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
 
@@ -49,13 +49,13 @@ void DrawShipDepotSprite(int x, int y, i
 
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, ...);
map.h
Show inline comments
 
@@ -64,18 +64,19 @@ static inline TileIndexDiff TileDiffXY(i
 

	
 
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 {
openttd.h
Show inline comments
 
@@ -289,13 +289,13 @@ enum {
 
};
 

	
 
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;
player.h
Show inline comments
 
@@ -199,13 +199,13 @@ typedef struct Player {
 
	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;
players.c
Show inline comments
 
@@ -256,13 +256,13 @@ void UpdatePlayerMoney32(Player *p)
 
		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);
 
@@ -280,25 +280,25 @@ void GetNameOfOwner(PlayerID owner, Tile
 
	}
 
}
 

	
 

	
 
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);
road_cmd.c
Show inline comments
 
@@ -36,27 +36,25 @@ static uint CountRoadBits(RoadBits r)
 

	
 

	
 
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);
 
@@ -91,13 +89,13 @@ static bool CheckAllowRemoveRoad(TileInd
 
 */
 
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;
 

	
road_map.h
Show inline comments
 
@@ -175,13 +175,13 @@ static inline DiagDirection GetRoadDepot
 
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;
tunnelbridge_cmd.c
Show inline comments
 
@@ -705,13 +705,13 @@ static int32 DoClearBridge(TileIndex til
 
		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);
0 comments (0 inline, 0 general)