Changeset - r4849:41dc3967353a
[Not reviewed]
master
0 8 0
Darkvater - 18 years ago 2006-10-14 22:22:48
darkvater@openttd.org
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
these are used intermixed often.
8 files changed with 15 insertions and 16 deletions:
0 comments (0 inline, 0 general)
functions.h
Show inline comments
 
@@ -43,25 +43,25 @@ void DrawHillyLandTile(const TileInfo *t
 
void DrawClearLandTile(const TileInfo *ti, byte set);
 
void DrawClearLandFence(const TileInfo *ti);
 
void TileLoopClearHelper(TileIndex tile);
 

	
 
/* water_land.c */
 
void DrawShipDepotSprite(int x, int y, int image);
 
void TileLoop_Water(TileIndex tile);
 

	
 
/* players.c */
 
bool CheckPlayerHasMoney(int32 cost);
 
void SubtractMoneyFromPlayer(int32 cost);
 
void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost);
 
bool CheckOwnership(PlayerID owner);
 
bool CheckOwnership(Owner owner);
 
bool CheckTileOwnership(TileIndex tile);
 
StringID GetPlayerNameString(PlayerID player, uint index);
 

	
 
/* standard */
 
void ShowInfo(const char *str);
 
void CDECL ShowInfoF(const char *str, ...);
 
void NORETURN CDECL error(const char *str, ...);
 

	
 
/* openttd.c */
 

	
 
/**************
 
 * Warning: DO NOT enable this unless you understand what it does
map.h
Show inline comments
 
@@ -58,30 +58,31 @@ static inline TileIndexDiff TileDiffXY(i
 
	// Multiplication gives much better optimization on MSVC than shifting.
 
	// 0 << shift isn't optimized to 0 properly.
 
	// Typically x and y are constants, and then this doesn't result
 
	// in any actual multiplication in the assembly code..
 
	return (y * MapSizeX()) + x;
 
}
 

	
 
static inline TileIndex TileVirtXY(uint x, uint y)
 
{
 
	return (y >> 4 << MapLogX()) + (x >> 4);
 
}
 

	
 
typedef enum Owner {
 
typedef byte Owner;
 
enum Owners {
 
	OWNER_TOWN      = 0x0F, // a town owns the tile
 
	OWNER_NONE      = 0x10, // nobody owns the tile
 
	OWNER_WATER     = 0x11, // "water" owns the tile
 
	OWNER_END       = 0x12,
 
} Owner;
 
};
 

	
 
enum {
 
	INVALID_TILE = (TileIndex)-1
 
};
 

	
 
enum {
 
	TILE_SIZE   = 16,   /* Tiles are 16x16 "units" in size */
 
	TILE_PIXELS = 32,   /* a tile is 32x32 pixels */
 
	TILE_HEIGHT =  8,   /* The standard height-difference between tiles on two levels is 8 (z-diff 8) */
 
};
 

	
 

	
openttd.h
Show inline comments
 
@@ -283,25 +283,25 @@ enum {
 
	CT_FIZZY_DRINKS = 11,
 

	
 
	NUM_CARGO       = 12,
 

	
 
	CT_NO_REFIT     = 0xFE,
 
	CT_INVALID      = 0xFF
 
};
 

	
 
typedef uint AcceptedCargo[NUM_CARGO];
 

	
 
typedef struct TileDesc {
 
	StringID str;
 
	byte owner;
 
	Owner owner;
 
	Date build_date;
 
	uint32 dparam[2];
 
} TileDesc;
 

	
 
typedef struct {
 
	int32 left;
 
	int32 top;
 
	byte width_1, width_2;
 
} ViewportSign;
 

	
 

	
 
typedef void DrawTileProc(TileInfo *ti);
player.h
Show inline comments
 
@@ -193,25 +193,25 @@ typedef struct Player {
 
	PlayerEconomyEntry old_economy[24];
 
	EngineRenewList engine_renew_list; // Defined later
 
	bool engine_renew;
 
	bool renew_keep_length;
 
	int16 engine_renew_months;
 
	uint32 engine_renew_money;
 
	uint16 num_engines[TOTAL_NUM_ENGINES]; // caches the number of engines of each type the player owns (no need to save this)
 
} Player;
 

	
 
uint16 GetDrawStringPlayerColor(PlayerID player);
 

	
 
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player);
 
void GetNameOfOwner(PlayerID owner, TileIndex tile);
 
void GetNameOfOwner(Owner owner, TileIndex tile);
 
int64 CalculateCompanyValue(const Player* p);
 
void InvalidatePlayerWindows(const Player* p);
 
void UpdatePlayerMoney32(Player *p);
 
#define FOR_ALL_PLAYERS(p) for (p = _players; p != endof(_players); p++)
 

	
 
VARDEF PlayerID _local_player;
 
VARDEF PlayerID _current_player;
 

	
 
/* Player identifiers All players below MAX_PLAYERS are playable
 
 * players, above, they are special, computer controlled players */
 
enum {
 
	PLAYER_SPECTATOR   = 255, ///< Spectator in Multiplayer or the player in the scenario editor
players.c
Show inline comments
 
@@ -250,61 +250,61 @@ void SubtractMoneyFromPlayerFract(Player
 
// the player_money field is kept as it is, but money64 contains the actual amount of money.
 
void UpdatePlayerMoney32(Player *p)
 
{
 
	if (p->money64 < -2000000000) {
 
		p->player_money = -2000000000;
 
	} else if (p->money64 > 2000000000) {
 
		p->player_money = 2000000000;
 
	} else {
 
		p->player_money = (int32)p->money64;
 
	}
 
}
 

	
 
void GetNameOfOwner(PlayerID owner, TileIndex tile)
 
void GetNameOfOwner(Owner owner, TileIndex tile)
 
{
 
	SetDParam(2, owner);
 

	
 
	if (owner != OWNER_TOWN) {
 
		if (owner >= MAX_PLAYERS) {
 
			SetDParam(0, STR_0150_SOMEONE);
 
		} else {
 
			const Player* p = GetPlayer(owner);
 

	
 
			SetDParam(0, p->name_1);
 
			SetDParam(1, p->name_2);
 
		}
 
	} else {
 
		const Town* t = ClosestTownFromTile(tile, (uint)-1);
 

	
 
		SetDParam(0, STR_TOWN);
 
		SetDParam(1, t->index);
 
	}
 
}
 

	
 

	
 
bool CheckOwnership(PlayerID owner)
 
{
 
	assert(owner <= OWNER_WATER);
 
	assert(owner < OWNER_END);
 

	
 
	if (owner == _current_player) return true;
 
	_error_message = STR_013B_OWNED_BY;
 
	GetNameOfOwner(owner, 0);
 
	return false;
 
}
 

	
 
bool CheckTileOwnership(TileIndex tile)
 
{
 
	PlayerID owner = GetTileOwner(tile);
 
	Owner owner = GetTileOwner(tile);
 

	
 
	assert(owner <= OWNER_WATER);
 
	assert(owner < OWNER_END);
 

	
 
	if (owner == _current_player) return true;
 
	_error_message = STR_013B_OWNED_BY;
 

	
 
	// no need to get the name of the owner unless we're the local player (saves some time)
 
	if (IsLocalPlayer()) GetNameOfOwner(owner, tile);
 
	return false;
 
}
 

	
 
static void GenerateCompanyName(Player *p)
 
{
 
	TileIndex tile;
road_cmd.c
Show inline comments
 
@@ -30,39 +30,37 @@ static uint CountRoadBits(RoadBits r)
 
	if (r & ROAD_NW) ++count;
 
	if (r & ROAD_SW) ++count;
 
	if (r & ROAD_SE) ++count;
 
	if (r & ROAD_NE) ++count;
 
	return count;
 
}
 

	
 

	
 
static bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, bool* edge_road)
 
{
 
	RoadBits present;
 
	RoadBits n;
 
	byte owner;
 
	Owner owner;
 
	*edge_road = true;
 

	
 
	if (_game_mode == GM_EDITOR) return true;
 

	
 
	// Only do the special processing for actual players.
 
	if (_current_player >= MAX_PLAYERS) return true;
 

	
 
	owner = IsLevelCrossingTile(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile);
 

	
 
	// Only do the special processing if the road is owned
 
	// by a town
 
	if (owner != OWNER_TOWN) {
 
		return owner == OWNER_NONE || CheckOwnership(owner);
 
	}
 
	if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner);
 

	
 
	if (_cheats.magic_bulldozer.value) return true;
 

	
 
	// Get a bitmask of which neighbouring roads has a tile
 
	n = 0;
 
	present = GetAnyRoadBits(tile);
 
	if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile,-1, 0)) & ROAD_SW) n |= ROAD_NE;
 
	if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile, 0, 1)) & ROAD_NW) n |= ROAD_SE;
 
	if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile, 1, 0)) & ROAD_NE) n |= ROAD_SW;
 
	if (present & ROAD_NW && GetAnyRoadBits(TILE_ADDXY(tile, 0,-1)) & ROAD_SE) n |= ROAD_NW;
 

	
 
	// If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
 
@@ -85,25 +83,25 @@ static bool CheckAllowRemoveRoad(TileInd
 

	
 

	
 
/** Delete a piece of road.
 
 * @param tile tile where to remove road from
 
 * @param p1 road piece flags
 
 * @param p2 unused
 
 */
 
int32 CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	// cost for removing inner/edge -roads
 
	static const uint16 road_remove_cost[2] = {50, 18};
 

	
 
	PlayerID owner;
 
	Owner owner;
 
	Town *t;
 
	/* true if the roadpiece was always removeable,
 
	 * false if it was a center piece. Affects town ratings drop */
 
	bool edge_road;
 
	RoadBits pieces;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) */
 
	if (p1 >> 4) return CMD_ERROR;
 
	pieces = p1;
 

	
road_map.h
Show inline comments
 
@@ -169,25 +169,25 @@ static inline DiagDirection GetRoadDepot
 
 * Special behavior:
 
 * - road depots: entrance is treated as road piece
 
 * - road tunnels: entrance is treated as road piece
 
 * - bridge ramps: start of the ramp is treated as road piece
 
 * - bridge middle parts: bridge itself is ignored
 
 */
 
RoadBits GetAnyRoadBits(TileIndex);
 

	
 

	
 
TrackBits GetAnyRoadTrackBits(TileIndex tile);
 

	
 

	
 
static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, uint town)
 
static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, TownID town)
 
{
 
	SetTileType(t, MP_STREET);
 
	SetTileOwner(t, owner);
 
	_m[t].m2 = town;
 
	_m[t].m3 = 0;
 
	_m[t].m4 = 0 << 7 | 0 << 4 | 0;
 
	_m[t].m5 = ROAD_TILE_NORMAL << 4 | bits;
 
}
 

	
 

	
 
static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner rail, Axis roaddir, RailType rt, uint town)
 
{
tunnelbridge_cmd.c
Show inline comments
 
@@ -699,25 +699,25 @@ static int32 DoClearBridge(TileIndex til
 
		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
 
		// you have a "Poor" (0) town rating
 
		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
 
			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
 

	
 
		DoClearSquare(tile);
 
		DoClearSquare(endtile);
 
		for (c = tile + delta; c != endtile; c += delta) {
 
			if (IsTransportUnderBridge(c)) {
 
				if (GetTransportTypeUnderBridge(c) == TRANSPORT_RAIL) {
 
					MakeRailNormal(c, GetTileOwner(c), GetRailBitsUnderBridge(c), GetRailType(c));
 
				} else {
 
					uint town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0;
 
					TownID town = IsTileOwner(c, OWNER_TOWN) ? ClosestTownFromTile(c, (uint)-1)->index : 0;
 
					MakeRoadNormal(c, GetTileOwner(c), GetRoadBitsUnderBridge(c), town);
 
				}
 
				MarkTileDirtyByTile(c);
 
			} else {
 
				if (IsClearUnderBridge(c)) {
 
					DoClearSquare(c);
 
				} else {
 
					if (GetTileSlope(c, NULL) == SLOPE_FLAT) {
 
						if (IsTileOwner(c, OWNER_WATER)) {
 
							MakeWater(c);
 
						} else {
 
							MakeCanal(c, GetTileOwner(c));
0 comments (0 inline, 0 general)