(svn r3073) int/byte -> EngineID/PlayerID/VehicleID
authortron
Thu, 20 Oct 2005 17:43:13 +0000
changeset 2544 50cb52cdeb73
parent 2543 a6344040f735
child 2545 d1965652e523
(svn r3073) int/byte -> EngineID/PlayerID/VehicleID
0/-1 -> INVALID_ENGINE
0x10 -> OWNER_NONE
ai/default/default.c
economy.c
player.h
players.c
rail_cmd.c
road_cmd.c
station_gui.c
--- a/ai/default/default.c	Thu Oct 20 17:23:33 2005 +0000
+++ b/ai/default/default.c	Thu Oct 20 17:43:13 2005 +0000
@@ -122,12 +122,12 @@
 	p->ai.state_counter = 0;
 }
 
-static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag, TileIndex tile)
+static EngineID AiChooseTrainToBuild(byte railtype, int32 money, byte flag, TileIndex tile)
 {
-	int best_veh_index = -1;
+	EngineID best_veh_index = INVALID_ENGINE;
 	byte best_veh_score = 0;
 	int32 ret;
-	int i;
+	EngineID i;
 
 	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
 		const RailVehicleInfo *rvi = RailVehInfo(i);
@@ -152,14 +152,14 @@
 	return best_veh_index;
 }
 
-static int AiChooseRoadVehToBuild(byte cargo, int32 money, TileIndex tile)
+static EngineID AiChooseRoadVehToBuild(byte cargo, int32 money, TileIndex tile)
 {
-	int best_veh_index = -1;
+	EngineID best_veh_index = INVALID_ENGINE;
 	int32 best_veh_cost = 0;
 	int32 ret;
 
-	int i = _cargoc.ai_roadveh_start[cargo];
-	int end = i + _cargoc.ai_roadveh_count[cargo];
+	EngineID i = _cargoc.ai_roadveh_start[cargo];
+	EngineID end = i + _cargoc.ai_roadveh_count[cargo];
 	const Engine* e = GetEngine(i);
 
 	do {
@@ -176,14 +176,14 @@
 	return best_veh_index;
 }
 
-static int AiChooseAircraftToBuild(int32 money, byte flag)
+static EngineID AiChooseAircraftToBuild(int32 money, byte flag)
 {
-	int best_veh_index = -1;
+	EngineID best_veh_index = INVALID_ENGINE;
 	int32 best_veh_cost = 0;
 	int32 ret;
 
-	int i = AIRCRAFT_ENGINES_INDEX;
-	int end = i + NUM_AIRCRAFT_ENGINES;
+	EngineID i = AIRCRAFT_ENGINES_INDEX;
+	EngineID end = i + NUM_AIRCRAFT_ENGINES;
 	const Engine* e = GetEngine(i);
 
 	do {
@@ -218,26 +218,26 @@
 }
 
 #if 0
-static int AiChooseShipToBuild(byte cargo, int32 money)
+static EngineID AiChooseShipToBuild(byte cargo, int32 money)
 {
 	// XXX: not done
-	return 0;
+	return INVALID_ENGINE;
 }
 #endif
 
-static int AiChooseRoadVehToReplaceWith(Player *p, Vehicle *v)
+static EngineID AiChooseRoadVehToReplaceWith(Player* p, Vehicle* v)
 {
 	int32 avail_money = p->player_money + v->value;
 	return AiChooseRoadVehToBuild(v->cargo_type, avail_money, v->tile);
 }
 
-static int AiChooseAircraftToReplaceWith(Player *p, Vehicle *v)
+static EngineID AiChooseAircraftToReplaceWith(Player* p, Vehicle* v)
 {
 	int32 avail_money = p->player_money + v->value;
 	return AiChooseAircraftToBuild(avail_money, v->engine_type>=253?1:0);
 }
 
-static int AiChooseTrainToReplaceWith(Player *p, Vehicle *v)
+static EngineID AiChooseTrainToReplaceWith(Player* p, Vehicle* v)
 {
 	int32 avail_money = p->player_money + v->value;
 	int num=0;
@@ -251,12 +251,12 @@
 	return AiChooseTrainToBuild(v->u.rail.railtype, avail_money, 0, v->tile);
 }
 
-static int AiChooseShipToReplaceWith(Player *p, Vehicle *v)
+static EngineID AiChooseShipToReplaceWith(Player* p, Vehicle* v)
 {
 	error("!AiChooseShipToReplaceWith");
 
 	/* maybe useless, but avoids compiler warning this way */
-	return 0;
+	return INVALID_ENGINE;
 }
 
 static void AiHandleGotoDepot(Player *p, int cmd)
@@ -289,7 +289,7 @@
 {
 	Vehicle *v = p->ai.cur_veh;
 	BackuppedOrders orderbak[1];
-	int veh;
+	EngineID veh;
 
 	// wait until the vehicle reaches the depot.
 	if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) {
@@ -298,7 +298,7 @@
 	}
 
 	veh = AiChooseTrainToReplaceWith(p, v);
-	if (veh != -1) {
+	if (veh != INVALID_ENGINE) {
 		TileIndex tile;
 
 		BackupVehicleOrders(v, orderbak);
@@ -306,7 +306,7 @@
 
 		if (!CmdFailed(DoCommandByTile(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON)) &&
 			  !CmdFailed(DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE)) ) {
-			veh = _new_train_id;
+			VehicleID veh = _new_train_id;
 			AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
 			DoCommandByTile(0, veh, 0, DC_EXEC, CMD_START_STOP_TRAIN);
 
@@ -319,7 +319,7 @@
 {
 	Vehicle *v = p->ai.cur_veh;
 	BackuppedOrders orderbak[1];
-	int veh;
+	EngineID veh;
 
 	if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED)) {
 		AiHandleGotoDepot(p, CMD_SEND_ROADVEH_TO_DEPOT);
@@ -327,7 +327,7 @@
 	}
 
 	veh = AiChooseRoadVehToReplaceWith(p, v);
-	if (veh != -1) {
+	if (veh != INVALID_ENGINE) {
 		TileIndex tile;
 
 		BackupVehicleOrders(v, orderbak);
@@ -335,7 +335,7 @@
 
 		if (!CmdFailed(DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH)) &&
 			  !CmdFailed(DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH)) ) {
-			veh = _new_roadveh_id;
+			VehicleID veh = _new_roadveh_id;
 			AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
 			DoCommandByTile(0, veh, 0, DC_EXEC, CMD_START_STOP_ROADVEH);
 
@@ -347,8 +347,8 @@
 static void AiHandleReplaceAircraft(Player *p)
 {
 	Vehicle *v = p->ai.cur_veh;
-	int veh;
 	BackuppedOrders orderbak[1];
+	EngineID veh;
 
 	if (!IsAircraftHangarTile(v->tile) && !(v->vehstatus&VS_STOPPED)) {
 		AiHandleGotoDepot(p, CMD_SEND_AIRCRAFT_TO_HANGAR);
@@ -356,7 +356,7 @@
 	}
 
 	veh = AiChooseAircraftToReplaceWith(p, v);
-	if (veh != -1) {
+	if (veh != INVALID_ENGINE) {
 		TileIndex tile;
 
 		BackupVehicleOrders(v, orderbak);
@@ -364,7 +364,7 @@
 
 		if (!CmdFailed(DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT)) &&
 			  !CmdFailed(DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT)) ) {
-			veh = _new_aircraft_id;
+			VehicleID veh = _new_aircraft_id;
 			AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
 			DoCommandByTile(0, veh, 0, DC_EXEC, CMD_START_STOP_AIRCRAFT);
 
@@ -378,7 +378,7 @@
 	error("!AiHandleReplaceShip");
 }
 
-typedef int CheckReplaceProc(Player *p, Vehicle *v);
+typedef EngineID CheckReplaceProc(Player* p, Vehicle* v);
 
 static CheckReplaceProc * const _veh_check_replace_proc[] = {
 	AiChooseTrainToReplaceWith,
@@ -399,7 +399,10 @@
 {
 	Vehicle *v = p->ai.cur_veh;
 
-	if (v->type == 0 || v->owner != _current_player || v->type > VEH_Ship || _veh_check_replace_proc[v->type - VEH_Train](p, v) == -1) {
+	if (v->type == 0 ||
+			v->owner != _current_player ||
+			v->type > VEH_Ship ||
+			_veh_check_replace_proc[v->type - VEH_Train](p, v) == INVALID_ENGINE) {
 		p->ai.state = AIS_VEH_LOOP;
 	} else {
 		p->ai.state_counter = 0;
@@ -1716,7 +1719,7 @@
 
 static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
 {
-	byte old_player;
+	PlayerID old_player;
 	uint32 r;
 	uint slope;
 	uint h;
@@ -2377,7 +2380,8 @@
 {
 	const AiDefaultBlockData *ptr;
 	TileIndex tile;
-	int i, veh;
+	EngineID veh;
+	int i;
 	int cargo;
 	int32 cost;
 	Vehicle *v;
@@ -2406,7 +2410,7 @@
 
 	// Which locomotive to build?
 	veh = AiChooseTrainToBuild(p->ai.railtype_to_use, p->player_money, (cargo!=CT_PASSENGERS)?1:0, tile);
-	if (veh == -1) {
+	if (veh == INVALID_ENGINE) {
 handle_nocash:
 		// after a while, if AI still doesn't have cash, get out of this block by selling the wagons.
 		if (++p->ai.state_counter == 1000) {
@@ -3497,7 +3501,7 @@
 {
 	const AiDefaultBlockData *ptr;
 	TileIndex tile;
-	int veh;
+	EngineID veh;
 	int i;
 	uint loco_id;
 
@@ -3507,7 +3511,7 @@
 	tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs));
 
 	veh = AiChooseAircraftToBuild(p->player_money, p->ai.build_kind!=0 ? 1 : 0);
-	if (veh == -1) return;
+	if (veh == INVALID_ENGINE) return;
 
 	/* XXX - Have the AI pick the hangar terminal in an airport. Eg get airport-type
 	 * and offset to the FIRST depot because the AI picks the st->xy tile */
--- a/economy.c	Thu Oct 20 17:23:33 2005 +0000
+++ b/economy.c	Thu Oct 20 17:43:13 2005 +0000
@@ -391,8 +391,6 @@
 	MarkWholeScreenDirty();
 }
 
-extern void DeletePlayerWindows(int pi);
-
 static void PlayersCheckBankrupt(Player *p)
 {
 	PlayerID owner;
--- a/player.h	Thu Oct 20 17:23:33 2005 +0000
+++ b/player.h	Thu Oct 20 17:43:13 2005 +0000
@@ -219,7 +219,8 @@
 	return _local_player == _current_player;
 }
 
-byte GetPlayerRailtypes(int p);
+void DeletePlayerWindows(PlayerID pi);
+byte GetPlayerRailtypes(PlayerID p);
 
 /** Finds out if a Player has a certain railtype available
   */
--- a/players.c	Thu Oct 20 17:23:33 2005 +0000
+++ b/players.c	Thu Oct 20 17:43:13 2005 +0000
@@ -603,21 +603,19 @@
 	}
 }
 
-void DeletePlayerWindows(int pi)
+void DeletePlayerWindows(PlayerID pi)
 {
 	DeleteWindowById(WC_COMPANY, pi);
 	DeleteWindowById(WC_FINANCES, pi);
 	DeleteWindowById(WC_STATION_LIST, pi);
-	/* The vehicle list windows also have station in the window_number
-	 * A stationindex of -1 means the global vehicle list */
-	DeleteWindowById(WC_TRAINS_LIST, (-1 << 16) | pi);
-	DeleteWindowById(WC_ROADVEH_LIST, (-1 << 16) | pi);
-	DeleteWindowById(WC_SHIPS_LIST, (-1 << 16) | pi);
-	DeleteWindowById(WC_AIRCRAFT_LIST, (-1 << 16) | pi);
+	DeleteWindowById(WC_TRAINS_LIST,   (INVALID_STATION << 16) | pi);
+	DeleteWindowById(WC_ROADVEH_LIST,  (INVALID_STATION << 16) | pi);
+	DeleteWindowById(WC_SHIPS_LIST,    (INVALID_STATION << 16) | pi);
+	DeleteWindowById(WC_AIRCRAFT_LIST, (INVALID_STATION << 16) | pi);
 	DeleteWindowById(WC_BUY_COMPANY, pi);
 }
 
-byte GetPlayerRailtypes(int p)
+byte GetPlayerRailtypes(PlayerID p)
 {
 	Engine *e;
 	int rt = 0;
@@ -638,7 +636,7 @@
 	return rt;
 }
 
-static void DeletePlayerStuff(int pi)
+static void DeletePlayerStuff(PlayerID pi)
 {
 	Player *p;
 
--- a/rail_cmd.c	Thu Oct 20 17:23:33 2005 +0000
+++ b/rail_cmd.c	Thu Oct 20 17:43:13 2005 +0000
@@ -1997,7 +1997,6 @@
 	byte a2;
 	byte rail;
 	uint16 m2;
-	byte owner;
 
 	m2 = GB(_m[tile].m2, 0, 4);
 
@@ -2037,7 +2036,7 @@
 		} else if (rail == TRACK_BIT_RIGHT) {
 			a2 = RAIL_GROUND_FENCE_VERT2;
 		} else {
-			owner = GetTileOwner(tile);
+			PlayerID owner = GetTileOwner(tile);
 
 			if ( (!(rail&(TRACK_BIT_DIAG2|TRACK_BIT_UPPER|TRACK_BIT_LEFT)) && (rail&TRACK_BIT_DIAG1)) || rail==(TRACK_BIT_LOWER|TRACK_BIT_RIGHT)) {
 				if (!IsTileType(tile + TileDiffXY(0, -1), MP_RAILWAY) ||
--- a/road_cmd.c	Thu Oct 20 17:23:33 2005 +0000
+++ b/road_cmd.c	Thu Oct 20 17:43:13 2005 +0000
@@ -879,7 +879,7 @@
 
 	} else {
 		uint32 ormod;
-		int player;
+		PlayerID player;
 		const DrawRoadSeqStruct *drss;
 
 		if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
--- a/station_gui.c	Thu Oct 20 17:23:33 2005 +0000
+++ b/station_gui.c	Thu Oct 20 17:43:13 2005 +0000
@@ -533,13 +533,11 @@
 void ShowStationViewWindow(StationID station)
 {
 	Window *w;
-	byte color;
 
 	w = AllocateWindowDescFront(&_station_view_desc, station);
 	if (w) {
-		color = GetStation(w->window_number)->owner;
-		if (color != 0x10)
-			w->caption_color = color;
+		PlayerID owner = GetStation(w->window_number)->owner;
+		if (owner != OWNER_NONE) w->caption_color = owner;
 		w->vscroll.cap = 5;
 	}
 }