diff options
-rw-r--r-- | ai/default/default.c | 2 | ||||
-rw-r--r-- | command.c | 6 | ||||
-rw-r--r-- | economy.c | 3 | ||||
-rw-r--r-- | player.h | 12 | ||||
-rw-r--r-- | players.c | 13 | ||||
-rw-r--r-- | rail_cmd.c | 2 | ||||
-rw-r--r-- | road_cmd.c | 2 | ||||
-rw-r--r-- | station_cmd.c | 5 | ||||
-rw-r--r-- | town_cmd.c | 3 | ||||
-rw-r--r-- | train_cmd.c | 2 | ||||
-rw-r--r-- | variables.h | 1 | ||||
-rw-r--r-- | vehicle.c | 3 |
12 files changed, 26 insertions, 28 deletions
diff --git a/ai/default/default.c b/ai/default/default.c index 44fb1572d..0fb4a3817 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -3831,7 +3831,7 @@ static void AiHandleTakeover(Player *p) return; p->bankrupt_timeout = 0; DeleteWindowById(WC_BUY_COMPANY, _current_player); - if (_current_player == _local_player) { + if (IsLocalPlayer()) { AskExitToGameMenu(); return; } @@ -460,7 +460,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, _docommand_recursive = 1; // cost estimation only? - if (_shift_pressed && _current_player == _local_player && !(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR))) { + if (_shift_pressed && IsLocalPlayer() && !(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR))) { // estimate the cost. res = proc(x, y, flags, p1, p2); if (CmdFailed(res)) { @@ -525,7 +525,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, SubtractMoneyFromPlayer(res2); - if (_current_player == _local_player && _game_mode != GM_EDITOR) { + if (IsLocalPlayer() && _game_mode != GM_EDITOR) { if (res2 != 0) ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2); if (_additional_cash_required) { @@ -543,7 +543,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, show_error: // show error message if the command fails? - if (_current_player == _local_player && _error_message_2 != 0) + if (IsLocalPlayer() && _error_message_2 != 0) ShowErrorMessage(_error_message, _error_message_2, x,y); callb_err: @@ -1472,8 +1472,7 @@ int LoadUnloadVehicle(Vehicle *v) v->profit_this_year += profit; SubtractMoneyFromPlayer(-profit); - if (_current_player == _local_player) - SndPlayVehicleFx(SND_14_CASHTILL, v); + if (IsLocalPlayer()) SndPlayVehicleFx(SND_14_CASHTILL, v); ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, -profit); } @@ -201,7 +201,8 @@ void AiDoGameLoop(Player *p); void UpdatePlayerMoney32(Player *p); #define FOR_ALL_PLAYERS(p) for(p=_players; p != endof(_players); p++) -extern PlayerID _current_player; +VARDEF PlayerID _local_player; +VARDEF PlayerID _current_player; #define MAX_PLAYERS 8 VARDEF Player _players[MAX_PLAYERS]; @@ -210,8 +211,13 @@ VARDEF byte _player_colors[MAX_PLAYERS]; static inline Player* GetPlayer(uint i) { - assert(i < lengthof(_players)); - return &_players[i]; + assert(i < lengthof(_players)); + return &_players[i]; +} + +static inline bool IsLocalPlayer(void) +{ + return _local_player == _current_player; } /** Returns the number of rail types the player can build @@ -25,8 +25,6 @@ #include "variables.h" #include "ai/ai.h" -PlayerID _current_player; - static const SpriteID cheeks_table[4] = { 0x325, 0x326, 0x390, 0x3B0, @@ -295,8 +293,7 @@ bool CheckTileOwnership(TileIndex tile) _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 (_current_player == _local_player) - GetNameOfOwner(owner, tile); + if (IsLocalPlayer()) GetNameOfOwner(owner, tile); return false; } @@ -690,7 +687,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (flags & DC_EXEC) { p->engine_renew = (bool)GB(p2, 0, 1); - if (_current_player == _local_player) { + if (IsLocalPlayer()) { _patches.autorenew = p->engine_renew; InvalidateWindow(WC_GAME_OPTIONS, 0); } @@ -702,7 +699,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (flags & DC_EXEC) { p->engine_renew_months = (int16)p2; - if (_current_player == _local_player) { + if (IsLocalPlayer()) { _patches.autorenew_months = p->engine_renew_months; InvalidateWindow(WC_GAME_OPTIONS, 0); } @@ -714,7 +711,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (flags & DC_EXEC) { p->engine_renew_money = (uint32)p2; - if (_current_player == _local_player) { + if (IsLocalPlayer()) { _patches.autorenew_money = p->engine_renew_money; InvalidateWindow(WC_GAME_OPTIONS, 0); } @@ -753,7 +750,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) p->engine_renew_months = (int16)GB(p1, 16, 16); p->engine_renew_money = (uint32)p2; - if (_current_player == _local_player) { + if (IsLocalPlayer()) { _patches.autorenew = p->engine_renew; _patches.autorenew_months = p->engine_renew_months; _patches.autorenew_money = p->engine_renew_money; diff --git a/rail_cmd.c b/rail_cmd.c index a9178c680..bf1a7d705 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -696,7 +696,7 @@ int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) return CMD_ERROR; if (flags & DC_EXEC) { - if (_current_player == _local_player) _last_built_train_depot_tile = tile; + if (IsLocalPlayer()) _last_built_train_depot_tile = tile; ModifyTile(tile, MP_SETTYPE(MP_RAILWAY) | diff --git a/road_cmd.c b/road_cmd.c index 3b6eff3c1..17aac26d6 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -662,7 +662,7 @@ int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) return CMD_ERROR; if (flags & DC_EXEC) { - if (_current_player == _local_player) _last_built_road_depot_tile = tile; + if (IsLocalPlayer()) _last_built_road_depot_tile = tile; dep->xy = tile; dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index; diff --git a/station_cmd.c b/station_cmd.c index 17c8162dd..6bf8a66e8 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -1782,9 +1782,8 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2) const AirportFTAClass *afc = GetAirport(p1); st->owner = _current_player; - if (_current_player == _local_player && afc->nof_depots != 0) { - _last_built_aircraft_depot_tile = tile + ToTileIndexDiff(afc->airport_depots[0]); - } + if (IsLocalPlayer() && afc->nof_depots != 0) + _last_built_aircraft_depot_tile = tile + ToTileIndexDiff(afc->airport_depots[0]); st->airport_tile = tile; if (!st->facilities) st->xy = tile; diff --git a/town_cmd.c b/town_cmd.c index c493fd2b6..2ba9e5fa0 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -1670,8 +1670,7 @@ static void TownActionBribe(Town *t, int action) // only show errormessage to the executing player. All errors are handled command.c // but this is special, because it can only 'fail' on a DC_EXEC - if (!_networking || (_current_player == _local_player)) - ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0); + if (IsLocalPlayer()) ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0); /* decrease by a lot! * ChangeTownRating is only for stuff in demolishing. Bribe failure should diff --git a/train_cmd.c b/train_cmd.c index 2e339020a..c37d5d221 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -1043,7 +1043,7 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2) new_f->orders = first->orders; new_f->num_orders = first->num_orders; first->orders = NULL; // XXX - to not to delete the orders */ - ShowTrainViewWindow(new_f); + if (IsLocalPlayer()) ShowTrainViewWindow(new_f); } } } diff --git a/variables.h b/variables.h index 328991781..ec6cb8bfc 100644 --- a/variables.h +++ b/variables.h @@ -257,7 +257,6 @@ VARDEF bool _is_old_ai_player; // current player is an oldAI player? (enables a VARDEF bool _do_autosave; VARDEF int _autosave_ctr; -VARDEF PlayerID _local_player; VARDEF byte _display_opt; VARDEF byte _pause; VARDEF int _caret_timer; @@ -1613,8 +1613,7 @@ int32 ReplaceVehicle(Vehicle *v) //needs to be down here because refitting will change SET_EXPENSES_TYPE if called SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); SubtractMoneyFromPlayer(cost); - if (_current_player == _local_player) - ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost); + if (IsLocalPlayer()) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost); return cost; } |