diff options
author | tron <tron@openttd.org> | 2005-10-20 17:43:13 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-10-20 17:43:13 +0000 |
commit | 2b91f55b320256a9653920f0b395879c1012d158 (patch) | |
tree | 904818203b322c8fca47da358ab42c2f254d2280 | |
parent | 6a5c0fabddadee4a95b075a21856eb8afbf93c57 (diff) | |
download | openttd-2b91f55b320256a9653920f0b395879c1012d158.tar.xz |
(svn r3073) int/byte -> EngineID/PlayerID/VehicleID
0/-1 -> INVALID_ENGINE
0x10 -> OWNER_NONE
-rw-r--r-- | ai/default/default.c | 72 | ||||
-rw-r--r-- | economy.c | 2 | ||||
-rw-r--r-- | player.h | 3 | ||||
-rw-r--r-- | players.c | 16 | ||||
-rw-r--r-- | rail_cmd.c | 3 | ||||
-rw-r--r-- | road_cmd.c | 2 | ||||
-rw-r--r-- | station_gui.c | 6 |
7 files changed, 51 insertions, 53 deletions
diff --git a/ai/default/default.c b/ai/default/default.c index 59227e32a..f154aec8a 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -122,12 +122,12 @@ static void AiStateVehLoop(Player *p) 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 @@ static int AiChooseTrainToBuild(byte railtype, int32 money, byte flag, TileIndex 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 @@ static int AiChooseRoadVehToBuild(byte cargo, int32 money, TileIndex tile) 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 @@ static int32 AiGetBasePrice(Player *p) } #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 @@ static int AiChooseTrainToReplaceWith(Player *p, Vehicle *v) 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 @@ static void AiHandleReplaceTrain(Player *p) { 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 @@ static void AiHandleReplaceTrain(Player *p) } veh = AiChooseTrainToReplaceWith(p, v); - if (veh != -1) { + if (veh != INVALID_ENGINE) { TileIndex tile; BackupVehicleOrders(v, orderbak); @@ -306,7 +306,7 @@ static void AiHandleReplaceTrain(Player *p) 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 @@ static void AiHandleReplaceRoadVeh(Player *p) { 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 @@ static void AiHandleReplaceRoadVeh(Player *p) } veh = AiChooseRoadVehToReplaceWith(p, v); - if (veh != -1) { + if (veh != INVALID_ENGINE) { TileIndex tile; BackupVehicleOrders(v, orderbak); @@ -335,7 +335,7 @@ static void AiHandleReplaceRoadVeh(Player *p) 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 AiHandleReplaceRoadVeh(Player *p) 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 @@ static void AiHandleReplaceAircraft(Player *p) } veh = AiChooseAircraftToReplaceWith(p, v); - if (veh != -1) { + if (veh != INVALID_ENGINE) { TileIndex tile; BackupVehicleOrders(v, orderbak); @@ -364,7 +364,7 @@ static void AiHandleReplaceAircraft(Player *p) 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 @@ static void AiHandleReplaceShip(Player *p) 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 @@ static void AiStateCheckReplaceVehicle(Player *p) { 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 const byte _terraform_down_flags[] = { 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 @@ static void AiStateBuildRailVeh(Player *p) { const AiDefaultBlockData *ptr; TileIndex tile; - int i, veh; + EngineID veh; + int i; int cargo; int32 cost; Vehicle *v; @@ -2406,7 +2410,7 @@ static void AiStateBuildRailVeh(Player *p) // 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 @@ static void AiStateBuildAircraftVehicles(Player *p) { const AiDefaultBlockData *ptr; TileIndex tile; - int veh; + EngineID veh; int i; uint loco_id; @@ -3507,7 +3511,7 @@ static void AiStateBuildAircraftVehicles(Player *p) 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 */ @@ -391,8 +391,6 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player) MarkWholeScreenDirty(); } -extern void DeletePlayerWindows(int pi); - static void PlayersCheckBankrupt(Player *p) { PlayerID owner; @@ -219,7 +219,8 @@ static inline bool IsLocalPlayer(void) 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 */ @@ -603,21 +603,19 @@ void PlayersYearlyLoop(void) } } -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 @@ byte GetPlayerRailtypes(int p) return rt; } -static void DeletePlayerStuff(int pi) +static void DeletePlayerStuff(PlayerID pi) { Player *p; diff --git a/rail_cmd.c b/rail_cmd.c index 47f70c66f..6e46999e3 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -1997,7 +1997,6 @@ static void TileLoop_Track(TileIndex tile) byte a2; byte rail; uint16 m2; - byte owner; m2 = GB(_m[tile].m2, 0, 4); @@ -2037,7 +2036,7 @@ static void TileLoop_Track(TileIndex tile) } 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) || diff --git a/road_cmd.c b/road_cmd.c index 21bbad190..3137e2fd0 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -879,7 +879,7 @@ static void DrawTile_Road(TileInfo *ti) } else { uint32 ormod; - int player; + PlayerID player; const DrawRoadSeqStruct *drss; if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); } diff --git a/station_gui.c b/station_gui.c index dc8a95dc1..91b706411 100644 --- a/station_gui.c +++ b/station_gui.c @@ -533,13 +533,11 @@ static const WindowDesc _station_view_desc = { 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; } } |