Files @ r23483:3733e6b8ff17
Branch filter:

Location: cpp/openttd-patchpack/source/src/tile_map.cpp - annotation

Patric Stout
Remove: ENABLE_NETWORK switch

This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.

Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.

A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.

With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.

All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
r8108:1d5bdeea7e20
r8108:1d5bdeea7e20
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r9111:983de9c5a848
r8108:1d5bdeea7e20
r8108:1d5bdeea7e20
r8108:1d5bdeea7e20
r8108:1d5bdeea7e20
r21383:942c32fb8b0e
r21383:942c32fb8b0e
r10260:88d82a40120c
r21725:48a0e77ec34b
r23023:7b8669afd1db
r23023:7b8669afd1db
r23023:7b8669afd1db
r23023:7b8669afd1db
r23023:7b8669afd1db
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r10260:88d82a40120c
r10260:88d82a40120c
r15613:193c12018337
r15613:193c12018337
r18260:9616113792ef
r8108:1d5bdeea7e20
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r8108:1d5bdeea7e20
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r8108:1d5bdeea7e20
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r10268:59b64ee0ce54
r21725:48a0e77ec34b
r23201:f37d3515c110
r21725:48a0e77ec34b
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r10268:59b64ee0ce54
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r21725:48a0e77ec34b
r8108:1d5bdeea7e20
r8108:1d5bdeea7e20
r10260:88d82a40120c
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r20805:06eb3eae002c
r20805:06eb3eae002c
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r20805:06eb3eae002c
r10260:88d82a40120c
r10260:88d82a40120c
r15613:193c12018337
r15613:193c12018337
r18260:9616113792ef
r8108:1d5bdeea7e20
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r8108:1d5bdeea7e20
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r8108:1d5bdeea7e20
r18246:8bbceed09429
r8108:1d5bdeea7e20
r8108:1d5bdeea7e20
r10260:88d82a40120c
r21725:48a0e77ec34b
r13060:e57594b0ca84
r15613:193c12018337
r15613:193c12018337
r18260:9616113792ef
r8108:1d5bdeea7e20
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r8108:1d5bdeea7e20
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r23201:f37d3515c110
r8108:1d5bdeea7e20
r18246:8bbceed09429
r8108:1d5bdeea7e20
/* $Id$ */

/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file tile_map.cpp Global tile accessors. */

#include "stdafx.h"
#include "tile_map.h"

#include "safeguards.h"

/**
 * Get a tile's slope given the heigh of its four corners.
 * @param hnorth The height at the northern corner in the same unit as TileHeight.
 * @param hwest  The height at the western corner in the same unit as TileHeight.
 * @param heast  The height at the eastern corner in the same unit as TileHeight.
 * @param hsouth The height at the southern corner in the same unit as TileHeight.
 * @param[out] h The lowest height of the four corners.
 * @return The slope.
 */
static Slope GetTileSlopeGivenHeight(int hnorth, int hwest, int heast, int hsouth, int *h)
{
	/* Due to the fact that tiles must connect with each other without leaving gaps, the
	 * biggest difference in height between any corner and 'min' is between 0, 1, or 2.
	 *
	 * Also, there is at most 1 corner with height difference of 2.
	 */
	int hminnw = min(hnorth, hwest);
	int hmines = min(heast, hsouth);
	int hmin = min(hminnw, hmines);

	if (h != NULL) *h = hmin;

	int hmaxnw = max(hnorth, hwest);
	int hmaxes = max(heast, hsouth);
	int hmax = max(hmaxnw, hmaxes);

	Slope r = SLOPE_FLAT;

	if (hnorth != hmin) r |= SLOPE_N;
	if (hwest  != hmin) r |= SLOPE_W;
	if (heast  != hmin) r |= SLOPE_E;
	if (hsouth != hmin) r |= SLOPE_S;

	if (hmax - hmin == 2) r |= SLOPE_STEEP;

	return r;
}

/**
 * Return the slope of a given tile inside the map.
 * @param tile Tile to compute slope of
 * @param h    If not \c NULL, pointer to storage of z height
 * @return Slope of the tile, except for the HALFTILE part
 */
Slope GetTileSlope(TileIndex tile, int *h)
{
	uint x1 = TileX(tile);
	uint y1 = TileY(tile);
	uint x2 = min(x1 + 1, MapMaxX());
	uint y2 = min(y1 + 1, MapMaxY());

	int hnorth = TileHeight(tile);           // Height of the North corner.
	int hwest  = TileHeight(TileXY(x2, y1)); // Height of the West corner.
	int heast  = TileHeight(TileXY(x1, y2)); // Height of the East corner.
	int hsouth = TileHeight(TileXY(x2, y2)); // Height of the South corner.

	return GetTileSlopeGivenHeight(hnorth, hwest, heast, hsouth, h);
}

/**
 * Return the slope of a given tile, also for tiles outside the map (virtual "black" tiles).
 *
 * @param x X coordinate of the tile to compute slope of, may be ouside the map.
 * @param y Y coordinate of the tile to compute slope of, may be ouside the map.
 * @param h If not \c NULL, pointer to storage of z height.
 * @return Slope of the tile, except for the HALFTILE part.
 */
Slope GetTilePixelSlopeOutsideMap(int x, int y, int *h)
{
	int hnorth = TileHeightOutsideMap(x,     y);     // N corner.
	int hwest  = TileHeightOutsideMap(x + 1, y);     // W corner.
	int heast  = TileHeightOutsideMap(x,     y + 1); // E corner.
	int hsouth = TileHeightOutsideMap(x + 1, y + 1); // S corner.

	Slope s = GetTileSlopeGivenHeight(hnorth, hwest, heast, hsouth, h);
	if (h != NULL) *h *= TILE_HEIGHT;
	return s;
}

/**
 * Check if a given tile is flat
 * @param tile Tile to check
 * @param h If not \c NULL, pointer to storage of z height (only if tile is flat)
 * @return Whether the tile is flat
 */
bool IsTileFlat(TileIndex tile, int *h)
{
	uint x1 = TileX(tile);
	uint y1 = TileY(tile);
	uint x2 = min(x1 + 1, MapMaxX());
	uint y2 = min(y1 + 1, MapMaxY());

	uint z = TileHeight(tile);
	if (TileHeight(TileXY(x2, y1)) != z) return false;
	if (TileHeight(TileXY(x1, y2)) != z) return false;
	if (TileHeight(TileXY(x2, y2)) != z) return false;

	if (h != NULL) *h = z;
	return true;
}

/**
 * Get bottom height of the tile
 * @param tile Tile to compute height of
 * @return Minimum height of the tile
 */
int GetTileZ(TileIndex tile)
{
	uint x1 = TileX(tile);
	uint y1 = TileY(tile);
	uint x2 = min(x1 + 1, MapMaxX());
	uint y2 = min(y1 + 1, MapMaxY());

	int h =    TileHeight(tile);            // N corner
	h = min(h, TileHeight(TileXY(x2, y1))); // W corner
	h = min(h, TileHeight(TileXY(x1, y2))); // E corner
	h = min(h, TileHeight(TileXY(x2, y2))); // S corner

	return h;
}

/**
 * Get top height of the tile inside the map.
 * @param t Tile to compute height of
 * @return Maximum height of the tile
 */
int GetTileMaxZ(TileIndex t)
{
	uint x1 = TileX(t);
	uint y1 = TileY(t);
	uint x2 = min(x1 + 1, MapMaxX());
	uint y2 = min(y1 + 1, MapMaxY());

	int h =         TileHeight(t);               // N corner
	h = max<int>(h, TileHeight(TileXY(x2, y1))); // W corner
	h = max<int>(h, TileHeight(TileXY(x1, y2))); // E corner
	h = max<int>(h, TileHeight(TileXY(x2, y2))); // S corner

	return h;
}