(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
authorDarkvater
Sat, 14 Oct 2006 22:22:48 +0000
changeset 4849 9a3c3ae7f62f
parent 4848 56549aa3e234
child 4850 b4e9be22945f
(svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
these are used intermixed often.
functions.h
map.h
openttd.h
player.h
players.c
road_cmd.c
road_map.h
tunnelbridge_cmd.c
--- a/functions.h	Sat Oct 14 15:49:43 2006 +0000
+++ b/functions.h	Sat Oct 14 22:22:48 2006 +0000
@@ -52,7 +52,7 @@
 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);
 
--- a/map.h	Sat Oct 14 15:49:43 2006 +0000
+++ b/map.h	Sat Oct 14 22:22:48 2006 +0000
@@ -67,12 +67,13 @@
 	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
--- a/openttd.h	Sat Oct 14 15:49:43 2006 +0000
+++ b/openttd.h	Sat Oct 14 22:22:48 2006 +0000
@@ -292,7 +292,7 @@
 
 typedef struct TileDesc {
 	StringID str;
-	byte owner;
+	Owner owner;
 	Date build_date;
 	uint32 dparam[2];
 } TileDesc;
--- a/player.h	Sat Oct 14 15:49:43 2006 +0000
+++ b/player.h	Sat Oct 14 22:22:48 2006 +0000
@@ -202,7 +202,7 @@
 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);
--- a/players.c	Sat Oct 14 15:49:43 2006 +0000
+++ b/players.c	Sat Oct 14 22:22:48 2006 +0000
@@ -259,7 +259,7 @@
 	}
 }
 
-void GetNameOfOwner(PlayerID owner, TileIndex tile)
+void GetNameOfOwner(Owner owner, TileIndex tile)
 {
 	SetDParam(2, owner);
 
@@ -283,7 +283,7 @@
 
 bool CheckOwnership(PlayerID owner)
 {
-	assert(owner <= OWNER_WATER);
+	assert(owner < OWNER_END);
 
 	if (owner == _current_player) return true;
 	_error_message = STR_013B_OWNED_BY;
@@ -293,9 +293,9 @@
 
 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;
--- a/road_cmd.c	Sat Oct 14 15:49:43 2006 +0000
+++ b/road_cmd.c	Sat Oct 14 22:22:48 2006 +0000
@@ -39,7 +39,7 @@
 {
 	RoadBits present;
 	RoadBits n;
-	byte owner;
+	Owner owner;
 	*edge_road = true;
 
 	if (_game_mode == GM_EDITOR) return true;
@@ -51,9 +51,7 @@
 
 	// 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;
 
@@ -94,7 +92,7 @@
 	// 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 */
--- a/road_map.h	Sat Oct 14 15:49:43 2006 +0000
+++ b/road_map.h	Sat Oct 14 22:22:48 2006 +0000
@@ -178,7 +178,7 @@
 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);
--- a/tunnelbridge_cmd.c	Sat Oct 14 15:49:43 2006 +0000
+++ b/tunnelbridge_cmd.c	Sat Oct 14 22:22:48 2006 +0000
@@ -708,7 +708,7 @@
 				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);