(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
rubidium 16 years ago
parent c2d2f817de
commit d06529ef4d

@ -212,7 +212,7 @@ void AI_RunGameLoop()
*/
void AI_StartNewAI(PlayerID player)
{
assert(IsValidPlayer(player));
assert(IsValidPlayerID(player));
/* Called if a new AI is booted */
_ai_player[player].active = true;

@ -145,7 +145,7 @@ static const WindowDesc _air_toolbar_desc = {
void ShowBuildAirToolbar()
{
if (!IsValidPlayer(_current_player)) return;
if (!IsValidPlayerID(_current_player)) return;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);

@ -39,7 +39,7 @@ static inline bool AutoslopeCheckForEntranceEdge(TileIndex tile, uint z_new, Slo
static inline bool AutoslopeEnabled()
{
return (_settings_game.construction.autoslope &&
((IsValidPlayer(_current_player) && !_is_old_ai_player) ||
((IsValidPlayerID(_current_player) && !_is_old_ai_player) ||
(_current_player == OWNER_NONE && _game_mode == GM_EDITOR)));
}

@ -44,7 +44,7 @@ static int32 ClickMoneyCheat(int32 p1, int32 p2)
*/
static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
{
while (IsValidPlayer((PlayerID)p1)) {
while (IsValidPlayerID((PlayerID)p1)) {
if (_players[p1].is_active) {
SetLocalPlayer((PlayerID)p1);

@ -448,7 +448,7 @@ error:
if (--_docommand_recursive == 0 && !(flags & DC_BANKRUPT)) {
SubtractMoneyFromPlayer(res);
/* XXX - Old AI hack which doesn't use DoCommandDP; update last build coord of player */
if (tile != 0 && IsValidPlayer(_current_player)) {
if (tile != 0 && IsValidPlayerID(_current_player)) {
GetPlayer(_current_player)->last_build_coordinate = tile;
}
}
@ -467,7 +467,7 @@ error:
Money GetAvailableMoneyForCommand()
{
PlayerID pid = _current_player;
if (!IsValidPlayer(pid)) return INT64_MAX;
if (!IsValidPlayerID(pid)) return INT64_MAX;
return GetPlayer(pid)->player_money;
}
@ -608,7 +608,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)_current_player, tile, p1, p2, cmd, _cmd_text);
/* update last build coordinate of player. */
if (tile != 0 && IsValidPlayer(_current_player)) {
if (tile != 0 && IsValidPlayerID(_current_player)) {
GetPlayer(_current_player)->last_build_coordinate = tile;
}

@ -608,7 +608,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
index = (PlayerID)(atoi(argv[1]) - 1);
/* Check valid range */
if (!IsValidPlayer(index)) {
if (!IsValidPlayerID(index)) {
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_PLAYERS);
return true;
}
@ -654,7 +654,7 @@ DEF_CONSOLE_CMD(ConNetworkClients)
FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d IP: %s",
ci->client_index, ci->client_name,
ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
ci->client_playas + (IsValidPlayerID(ci->client_playas) ? 1 : 0),
GetPlayerIP(ci));
}
@ -694,7 +694,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
* players are offset by one to ease up on users (eg players 1-8 not 0-7) */
if (_network_playas != PLAYER_SPECTATOR) {
_network_playas--;
if (!IsValidPlayer(_network_playas)) return false;
if (!IsValidPlayerID(_network_playas)) return false;
}
}
if (port != NULL) {
@ -1185,7 +1185,7 @@ DEF_CONSOLE_CMD(ConSayPlayer)
if (argc != 3) return false;
PlayerID player_id = (PlayerID)(atoi(argv[1]) - 1);
if (!IsValidPlayer(player_id) || !GetPlayer(player_id)->is_active) {
if (!IsValidPlayerID(player_id) || !GetPlayer(player_id)->is_active) {
IConsolePrintF(CC_DEFAULT, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS);
return true;
}
@ -1224,12 +1224,12 @@ extern void HashCurrentCompanyPassword();
bool NetworkChangeCompanyPassword(byte argc, char *argv[])
{
if (argc == 0) {
if (!IsValidPlayer(_local_player)) return true; // dedicated server
if (!IsValidPlayerID(_local_player)) return true; // dedicated server
IConsolePrintF(CC_WARNING, "Current value for 'company_pw': %s", _network_player_info[_local_player].password);
return true;
}
if (!IsValidPlayer(_local_player)) {
if (!IsValidPlayerID(_local_player)) {
IConsoleError("You have to own a company to make use of this command.");
return false;
}

@ -277,7 +277,7 @@ static const WindowDesc _build_docks_toolbar_desc = {
void ShowBuildDocksToolbar()
{
if (!IsValidPlayer(_current_player)) return;
if (!IsValidPlayerID(_current_player)) return;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);

@ -1784,7 +1784,7 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32
/* Check if buying shares is allowed (protection against modified clients) */
/* Cannot buy own shares */
if (!IsValidPlayer((PlayerID)p1) || !_settings_game.economy.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR;
if (!IsValidPlayerID((PlayerID)p1) || !_settings_game.economy.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR;
p = GetPlayer((PlayerID)p1);
@ -1833,7 +1833,7 @@ CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint3
/* Check if selling shares is allowed (protection against modified clients) */
/* Cannot sell own shares */
if (!IsValidPlayer((PlayerID)p1) || !_settings_game.economy.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR;
if (!IsValidPlayerID((PlayerID)p1) || !_settings_game.economy.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR;
p = GetPlayer((PlayerID)p1);
@ -1871,7 +1871,7 @@ CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
PlayerID pid = (PlayerID)p1;
/* Disable takeovers in multiplayer games */
if (!IsValidPlayer(pid) || _networking) return CMD_ERROR;
if (!IsValidPlayerID(pid) || _networking) return CMD_ERROR;
/* Do not allow players to take over themselves */
if (pid == _current_player) return CMD_ERROR;

@ -732,7 +732,7 @@ static const WindowDesc _group_desc = {
void ShowPlayerGroup(PlayerID player, VehicleType vehicle_type)
{
if (!IsValidPlayer(player)) return;
if (!IsValidPlayerID(player)) return;
WindowClass wc;

@ -419,7 +419,7 @@ public:
void ShowBuildIndustryWindow()
{
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
if (_game_mode != GM_EDITOR && !IsValidPlayerID(_current_player)) return;
if (BringWindowToFrontById(WC_BUILD_INDUSTRY, 0)) return;
new BuildIndustryWindow();
}

@ -342,7 +342,7 @@ struct MainWindow : Window
if (cio == NULL) break;
/* Only players actually playing can speak to team. Eg spectators cannot */
if (_settings_client.gui.prefer_teamchat && IsValidPlayer(cio->client_playas)) {
if (_settings_client.gui.prefer_teamchat && IsValidPlayerID(cio->client_playas)) {
const NetworkClientInfo *ci;
FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
if (ci->client_playas == cio->client_playas && ci != cio) {

@ -35,7 +35,7 @@ CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
PlayerFace pf = (PlayerFace)p2;
if (!IsValidPlayerFace(pf)) return CMD_ERROR;
if (!IsValidPlayerIDFace(pf)) return CMD_ERROR;
if (flags & DC_EXEC) {
GetPlayer(_current_player)->face = pf;
@ -366,7 +366,7 @@ CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* You can only transfer funds that is in excess of your loan */
if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
if (!_networking || !IsValidPlayerID((PlayerID)p2)) return CMD_ERROR;
if (flags & DC_EXEC) {
/* Add money to player */

@ -103,7 +103,7 @@ public:
}
LandInfoWindow(TileIndex tile) : Window(&_land_info_desc) {
Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
Player *p = GetPlayer(IsValidPlayerID(_local_player) ? _local_player : PLAYER_FIRST);
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
Money old_money = p->player_money;
@ -1364,7 +1364,7 @@ struct SaveLoadWindow : public QueryStringBaseWindow {
{
/* Check if we are not a spectator who wants to generate a name..
Let's use the name of player #0 for now. */
const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
const Player *p = GetPlayer(IsValidPlayerID(_local_player) ? _local_player : PLAYER_FIRST);
SetDParam(0, p->index);
SetDParam(1, _date);

@ -341,7 +341,7 @@ static uint NetworkCountPlayers()
FOR_ALL_CLIENTS(cs) {
const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
if (IsValidPlayer(ci->client_playas)) count++;
if (IsValidPlayerID(ci->client_playas)) count++;
}
return count;

@ -367,7 +367,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY;
current = (Owner)p->Recv_uint8();
if (!IsValidPlayer(current)) return NETWORK_RECV_STATUS_CLOSE_QUERY;
if (!IsValidPlayerID(current)) return NETWORK_RECV_STATUS_CLOSE_QUERY;
p->Recv_string(_network_player_info[current].company_name, sizeof(_network_player_info[current].company_name));
_network_player_info[current].inaugurated_year = p->Recv_uint32();
@ -624,7 +624,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
/* New company/spectator (invalid player) or company we want to join is not active
* Switch local player to spectator and await the server's judgement */
if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayer(_network_playas) ||
if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayerID(_network_playas) ||
!GetPlayer(_network_playas)->is_active) {
SetLocalPlayer(PLAYER_SPECTATOR);
@ -737,10 +737,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
/* For speaking to company or giving money, we need the player-name */
case NETWORK_ACTION_GIVE_MONEY:
if (!IsValidPlayer(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
if (!IsValidPlayerID(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
/* fallthrough */
case NETWORK_ACTION_CHAT_COMPANY: {
StringID str = IsValidPlayer(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
StringID str = IsValidPlayerID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
SetDParam(0, ci_to->client_playas);
GetString(name, str, lastof(name));

@ -1296,7 +1296,7 @@ struct NetworkClientListPopupWindow : Window {
this->proc[i++] = &ClientList_SpeakToClient;
}
if (IsValidPlayer(ci->client_playas) || ci->client_playas == PLAYER_SPECTATOR) {
if (IsValidPlayerID(ci->client_playas) || ci->client_playas == PLAYER_SPECTATOR) {
GetString(this->action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, lastof(this->action[i]));
this->proc[i++] = &ClientList_SpeakToCompany;
}
@ -1305,7 +1305,7 @@ struct NetworkClientListPopupWindow : Window {
if (_network_own_client_index != ci->client_index) {
/* We are no spectator and the player we want to give money to is no spectator and money gifts are allowed */
if (IsValidPlayer(_network_playas) && IsValidPlayer(ci->client_playas) && _settings_game.economy.give_money) {
if (IsValidPlayerID(_network_playas) && IsValidPlayerID(ci->client_playas) && _settings_game.economy.give_money) {
GetString(this->action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(this->action[i]));
this->proc[i++] = &ClientList_GiveMoney;
}
@ -1494,7 +1494,7 @@ struct NetworkClientListWindow : Window
}
/* Filter out spectators */
if (IsValidPlayer(ci->client_playas)) DrawPlayerIcon(ci->client_playas, 64, y + 1);
if (IsValidPlayerID(ci->client_playas)) DrawPlayerIcon(ci->client_playas, 64, y + 1);
DoDrawString(ci->client_name, 81, y, colour);

@ -621,7 +621,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)
if (!StrEmpty(_settings_client.network.server_password)) {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_GAME_PASSWORD);
} else {
if (IsValidPlayer(ci->client_playas) && _network_player_info[ci->client_playas].password[0] != '\0') {
if (IsValidPlayerID(ci->client_playas) && _network_player_info[ci->client_playas].password[0] != '\0') {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
} else {
SEND_COMMAND(PACKET_SERVER_WELCOME)(cs);
@ -677,7 +677,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
}
break;
default: /* Join another company (companies 1-8 (index 0-7)) */
if (!IsValidPlayer(playas)) {
if (!IsValidPlayerID(playas)) {
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
return;
}
@ -701,7 +701,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
ci->client_lang = client_lang;
/* Make sure companies to which people try to join are not autocleaned */
if (IsValidPlayer(playas)) _network_player_info[playas].months_empty = 0;
if (IsValidPlayerID(playas)) _network_player_info[playas].months_empty = 0;
if (_grfconfig == NULL) {
RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)(cs, NULL);
@ -729,7 +729,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
ci = DEREF_CLIENT_INFO(cs);
if (IsValidPlayer(ci->client_playas) && _network_player_info[ci->client_playas].password[0] != '\0') {
if (IsValidPlayerID(ci->client_playas) && _network_player_info[ci->client_playas].password[0] != '\0') {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
return;
}
@ -841,7 +841,7 @@ static bool CheckCommandFlags(const CommandPacket *cp, const NetworkClientInfo *
return false;
}
if (cp->cmd != CMD_PLAYER_CTRL && !IsValidPlayer(cp->player) && ci->client_index != NETWORK_SERVER_INDEX) {
if (cp->cmd != CMD_PLAYER_CTRL && !IsValidPlayerID(cp->player) && ci->client_index != NETWORK_SERVER_INDEX) {
IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
return false;
}
@ -1125,7 +1125,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
if (ci != NULL && show_local) {
if (from_index == NETWORK_SERVER_INDEX) {
char name[NETWORK_NAME_LENGTH];
StringID str = IsValidPlayer(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
StringID str = IsValidPlayerID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
SetDParam(0, ci_to->client_playas);
GetString(name, str, lastof(name));
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
@ -1185,7 +1185,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD)
p->Recv_string(password, sizeof(password));
ci = DEREF_CLIENT_INFO(cs);
if (IsValidPlayer(ci->client_playas)) {
if (IsValidPlayerID(ci->client_playas)) {
ttd_strlcpy(_network_player_info[ci->client_playas].password, password, sizeof(_network_player_info[0].password));
}
}
@ -1337,7 +1337,7 @@ void NetworkPopulateCompanyInfo()
// Go through all vehicles and count the type of vehicles
FOR_ALL_VEHICLES(v) {
if (!IsValidPlayer(v->owner) || !v->IsPrimaryVehicle()) continue;
if (!IsValidPlayerID(v->owner) || !v->IsPrimaryVehicle()) continue;
byte type = 0;
switch (v->type) {
case VEH_TRAIN: type = 0; break;
@ -1351,7 +1351,7 @@ void NetworkPopulateCompanyInfo()
// Go through all stations and count the types of stations
FOR_ALL_STATIONS(s) {
if (IsValidPlayer(s->owner)) {
if (IsValidPlayerID(s->owner)) {
NetworkPlayerInfo *npi = &_network_player_info[s->owner];
if (s->facilities & FACIL_TRAIN) npi->num_station[0]++;
@ -1364,7 +1364,7 @@ void NetworkPopulateCompanyInfo()
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
// Register local player (if not dedicated)
if (ci != NULL && IsValidPlayer(ci->client_playas))
if (ci != NULL && IsValidPlayerID(ci->client_playas))
ttd_strlcpy(_network_player_info[ci->client_playas].players, ci->client_name, sizeof(_network_player_info[0].players));
FOR_ALL_CLIENTS(cs) {
@ -1373,7 +1373,7 @@ void NetworkPopulateCompanyInfo()
NetworkGetClientName(client_name, sizeof(client_name), cs);
ci = DEREF_CLIENT_INFO(cs);
if (ci != NULL && IsValidPlayer(ci->client_playas)) {
if (ci != NULL && IsValidPlayerID(ci->client_playas)) {
if (!StrEmpty(_network_player_info[ci->client_playas].players)) {
ttd_strlcat(_network_player_info[ci->client_playas].players, ", ", lengthof(_network_player_info[0].players));
}
@ -1425,12 +1425,12 @@ static void NetworkAutoCleanCompanies()
/* Detect the active companies */
FOR_ALL_CLIENTS(cs) {
ci = DEREF_CLIENT_INFO(cs);
if (IsValidPlayer(ci->client_playas)) clients_in_company[ci->client_playas] = true;
if (IsValidPlayerID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
}
if (!_network_dedicated) {
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
if (IsValidPlayer(ci->client_playas)) clients_in_company[ci->client_playas] = true;
if (IsValidPlayerID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
}
/* Go through all the comapnies */
@ -1669,7 +1669,7 @@ void NetworkServerShowStatusToConsole()
status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s unique-id: '%s'",
cs->index, ci->client_name, status, lag,
ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
ci->client_playas + (IsValidPlayerID(ci->client_playas) ? 1 : 0),
GetPlayerIP(ci), ci->unique_id);
}
}

@ -454,7 +454,7 @@ static uint8 LiveryHelper(EngineID engine, const Vehicle *v)
const Livery *l;
if (v == NULL) {
if (!IsValidPlayer(_current_player)) return 0;
if (!IsValidPlayerID(_current_player)) return 0;
l = GetEngineLivery(engine, _current_player, INVALID_ENGINE, NULL);
} else if (v->type == VEH_TRAIN) {
l = GetEngineLivery((v->u.rail.first_engine != INVALID_ENGINE && (IsArticulatedPart(v) || UsesWagonOverride(v))) ? v->u.rail.first_engine : v->engine_type, v->owner, v->u.rail.first_engine, v);

@ -591,7 +591,7 @@ bool CanDeleteHouse(TileIndex tile)
/* Human players are always allowed to remove buildings, as is water and
* anyone using the scenario editor. */
if ((IsValidPlayer(_current_player) && IsHumanPlayer(_current_player))
if ((IsValidPlayerID(_current_player) && IsHumanPlayer(_current_player))
|| _current_player == OWNER_WATER || _current_player == OWNER_NONE) return true;
if (HasBit(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {

@ -252,7 +252,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
byte colours;
bool is_ai = false;
if (IsValidPlayer(industry->founder)) {
if (IsValidPlayerID(industry->founder)) {
const Player *p = GetPlayer(industry->founder);
const Livery *l = &p->livery[LS_DEFAULT];

@ -630,7 +630,7 @@ int ttd_main(int argc, char *argv[])
if (_network_playas != PLAYER_SPECTATOR) {
_network_playas--;
if (!IsValidPlayer(_network_playas)) return false;
if (!IsValidPlayerID(_network_playas)) return false;
}
}
if (port != NULL) rport = atoi(port);
@ -1573,7 +1573,7 @@ bool AfterLoadGame()
* becomes player 0, unless we are in the scenario editor where all the
* players are 'invalid'.
*/
if (!_network_dedicated && IsValidPlayer(PLAYER_FIRST)) {
if (!_network_dedicated && IsValidPlayerID(PLAYER_FIRST)) {
p = GetPlayer(PLAYER_FIRST);
p->engine_renew = _settings_client.gui.autorenew;
p->engine_renew_months = _settings_client.gui.autorenew_months;
@ -2322,7 +2322,7 @@ bool AfterLoadGame()
for (uint i = 0; i < 4; i++) {
PlayerID o = p->share_owners[i];
if (o == PLAYER_SPECTATOR) continue;
if (!IsValidPlayer(o) || o == p->index || !GetPlayer(o)->is_active) p->share_owners[i] = PLAYER_SPECTATOR;
if (!IsValidPlayerID(o) || o == p->index || !GetPlayer(o)->is_active) p->share_owners[i] = PLAYER_SPECTATOR;
}
}
}
@ -2374,7 +2374,7 @@ bool AfterLoadGame()
if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
Owner o = GetTileOwner(t);
if (IsValidPlayer(o) && !GetPlayer(o)->is_active) {
if (IsValidPlayerID(o) && !GetPlayer(o)->is_active) {
_current_player = o;
ChangeTileOwner(t, o, PLAYER_SPECTATOR);
}
@ -2388,7 +2388,7 @@ bool AfterLoadGame()
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
/* update even non-existing road types to update tile owner too */
Owner o = GetRoadOwner(t, rt);
if (IsValidPlayer(o) && !GetPlayer(o)->is_active) SetRoadOwner(t, rt, OWNER_NONE);
if (IsValidPlayerID(o) && !GetPlayer(o)->is_active) SetRoadOwner(t, rt, OWNER_NONE);
}
if (IsLevelCrossing(t)) {
Owner o = GetTileOwner(t);

@ -229,6 +229,6 @@ static inline SpriteID GetPlayerFaceSprite(PlayerFace pf, PlayerFaceVariable pfv
void DrawPlayerFace(PlayerFace face, int color, int x, int y);
PlayerFace ConvertFromOldPlayerFace(uint32 face);
bool IsValidPlayerFace(PlayerFace pf);
bool IsValidPlayerIDFace(PlayerFace pf);
#endif /* PLAYER_FACE_H */

@ -27,7 +27,7 @@ static inline bool IsLocalPlayer()
return _local_player == _current_player;
}
static inline bool IsValidPlayer(PlayerID pi)
static inline bool IsValidPlayerID(PlayerID pi)
{
return IsInsideBS(pi, PLAYER_FIRST, MAX_PLAYERS);
}

@ -252,7 +252,7 @@ static const WindowDesc _player_finances_small_desc = {
*/
static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied, int top, int left)
{
if (!IsValidPlayer(player)) return;
if (!IsValidPlayerID(player)) return;
if (BringWindowToFrontById(WC_FINANCES, player)) return;
new PlayerFinancesWindow(show_small ? &_player_finances_small_desc : &_player_finances_desc, player, show_small, show_stickied, top, left);
@ -1030,7 +1030,7 @@ static const WindowDesc _select_player_face_adv_desc = {
*/
static void DoSelectPlayerFace(Window *parent, bool adv, int top, int left)
{
if (!IsValidPlayer((PlayerID)parent->window_number)) return;
if (!IsValidPlayerID((PlayerID)parent->window_number)) return;
if (BringWindowToFrontById(WC_PLAYER_FACE, parent->window_number)) return;
new SelectPlayerFaceWindow(adv ? &_select_player_face_adv_desc : &_select_player_face_desc, parent, adv, top, left); // simple or advanced window
@ -1349,7 +1349,7 @@ static const WindowDesc _player_company_desc = {
void ShowPlayerCompany(PlayerID player)
{
if (!IsValidPlayer(player)) return;
if (!IsValidPlayerID(player)) return;
AllocateWindowDescFront<PlayerCompanyWindow>(&_player_company_desc, player);
}
@ -1495,7 +1495,7 @@ struct EndGameWindow : EndGameHighScoreBaseWindow {
this->SetupHighScoreEndWindow(&x, &y);
if (!IsValidPlayer(_local_player)) return;
if (!IsValidPlayerID(_local_player)) return;
p = GetPlayer(_local_player);
/* We need to get performance from last year because the image is shown

@ -54,17 +54,17 @@ HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
* Sets the local player and updates the patch settings that are set on a
* per-company (player) basis to reflect the core's state in the GUI.
* @param new_player the new player
* @pre IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE
* @pre IsValidPlayerID(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE
*/
void SetLocalPlayer(PlayerID new_player)
{
/* Player could also be PLAYER_SPECTATOR or OWNER_NONE */
assert(IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE);
assert(IsValidPlayerID(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE);
_local_player = new_player;
/* Do not update the patches if we are in the intro GUI */
if (IsValidPlayer(new_player) && _game_mode != GM_MENU) {
if (IsValidPlayerID(new_player) && _game_mode != GM_MENU) {
const Player *p = GetPlayer(new_player);
_settings_client.gui.autorenew = p->engine_renew;
_settings_client.gui.autorenew_months = p->engine_renew_months;
@ -83,7 +83,7 @@ uint16 GetDrawStringPlayerColor(PlayerID player)
{
/* Get the color for DrawString-subroutines which matches the color
* of the player */
if (!IsValidPlayer(player)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOR;
if (!IsValidPlayerID(player)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOR;
return (_colour_gradient[_player_colors[player]][4]) | IS_PALETTE_COLOR;
}
@ -166,7 +166,7 @@ PlayerFace ConvertFromOldPlayerFace(uint32 face)
* @param pf the fact to check
* @return true if and only if the face is valid
*/
bool IsValidPlayerFace(PlayerFace pf)
bool IsValidPlayerIDFace(PlayerFace pf)
{
if (!ArePlayerFaceBitsValid(pf, PFV_GEN_ETHN, GE_WM)) return false;
@ -203,7 +203,7 @@ bool CheckPlayerHasMoney(CommandCost cost)
{
if (cost.GetCost() > 0) {
PlayerID pid = _current_player;
if (IsValidPlayer(pid) && cost.GetCost() > GetPlayer(pid)->player_money) {
if (IsValidPlayerID(pid) && cost.GetCost() > GetPlayer(pid)->player_money) {
SetDParam(0, cost.GetCost());
_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES;
return false;
@ -259,7 +259,7 @@ void SubtractMoneyFromPlayer(CommandCost cost)
{
PlayerID pid = _current_player;
if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
if (IsValidPlayerID(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
}
void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst)
@ -279,7 +279,7 @@ void GetNameOfOwner(Owner owner, TileIndex tile)
SetDParam(2, owner);
if (owner != OWNER_TOWN) {
if (!IsValidPlayer(owner)) {
if (!IsValidPlayerID(owner)) {
SetDParam(0, STR_0150_SOMEONE);
} else {
const Player* p = GetPlayer(owner);
@ -686,7 +686,7 @@ static void DeletePlayerStuff(PlayerID pi)
*/
CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
if (!IsValidPlayer(_current_player)) return CMD_ERROR;
if (!IsValidPlayerID(_current_player)) return CMD_ERROR;
Player *p = GetPlayer(_current_player);
switch (GB(p1, 0, 3)) {
@ -889,7 +889,7 @@ CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
ci->client_playas = p->index;
NetworkUpdateClientInfo(ci->client_index);
if (IsValidPlayer(ci->client_playas)) {
if (IsValidPlayerID(ci->client_playas)) {
PlayerID player_backup = _local_player;
_network_player_info[p->index].months_empty = 0;
@ -922,7 +922,7 @@ CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
case 2: { /* Delete a player */
Player *p;
if (!IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
if (!IsValidPlayerID((PlayerID)p2)) return CMD_ERROR;
if (!(flags & DC_EXEC)) return CommandCost();
@ -949,7 +949,7 @@ CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
PlayerID pid_old = (PlayerID)GB(p2, 0, 16);
PlayerID pid_new = (PlayerID)GB(p2, 16, 16);
if (!IsValidPlayer(pid_old) || !IsValidPlayer(pid_new)) return CMD_ERROR;
if (!IsValidPlayerID(pid_old) || !IsValidPlayerID(pid_new)) return CMD_ERROR;
if (!(flags & DC_EXEC)) return CMD_ERROR;

@ -514,7 +514,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32
if (flags & DC_EXEC) {
/* if we got that far, 'owner' variable is set correctly */
assert(IsValidPlayer(owner));
assert(IsValidPlayerID(owner));
MarkTileDirtyByTile(tile);
if (crossing) {

@ -839,7 +839,7 @@ void ShowBuildRailToolbar(RailType railtype, int button)
{
BuildRailToolbarWindow *w;
if (!IsValidPlayer(_current_player)) return;
if (!IsValidPlayerID(_current_player)) return;
if (!ValParamRailtype(railtype)) return;
// don't recreate the window if we're clicking on a button and the window exists.
@ -1698,7 +1698,7 @@ void ReinitGuiAfterToggleElrail(bool disable)
/** Set the initial (default) railtype to use */
static void SetDefaultRailGui()
{
if (_local_player == PLAYER_SPECTATOR || !IsValidPlayer(_local_player)) return;
if (_local_player == PLAYER_SPECTATOR || !IsValidPlayerID(_local_player)) return;
extern RailType _last_built_railtype;
RailType rt = (RailType)_settings_client.gui.default_rail_type;

@ -84,7 +84,7 @@ bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts)
if (p == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
avail_roadtypes = ROADTYPES_ROAD;
} else {
if (!IsValidPlayer(p)) return false;
if (!IsValidPlayerID(p)) return false;
avail_roadtypes = (RoadTypes)GetPlayer(p)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
}
return (rts & ~avail_roadtypes) == 0;

@ -152,7 +152,7 @@ bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType
* Towns are not be allowed to remove non "normal" road pieces, like tram
* tracks as that would result in trams that cannot turn. */
if (_current_player == OWNER_WATER ||
(rt == ROADTYPE_ROAD && !IsValidPlayer(_current_player))) return true;
(rt == ROADTYPE_ROAD && !IsValidPlayerID(_current_player))) return true;
/* Only do the special processing if the road is owned
* by a town */
@ -471,7 +471,7 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
* if a non-player is building the road */
if ((IsValidPlayer(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
if ((IsValidPlayerID(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
RoadBits pieces = Extract<RoadBits, 0>(p1);

@ -675,7 +675,7 @@ static const WindowDesc _build_tramway_desc = {
void ShowBuildRoadToolbar(RoadType roadtype)
{
if (!IsValidPlayer(_current_player)) return;
if (!IsValidPlayerID(_current_player)) return;
_cur_roadtype = roadtype;
DeleteWindowByClass(WC_BUILD_TOOLBAR);

@ -467,11 +467,11 @@ static inline void ResetSets()
*
* @param owner player whose signals we are updating
* @return state of the first block from _globset
* @pre IsValidPlayer(owner)
* @pre IsValidPlayerID(owner)
*/
static SigSegState UpdateSignalsInBuffer(Owner owner)
{
assert(IsValidPlayer(owner));
assert(IsValidPlayerID(owner));
bool first = true; // first block?
SigSegState state = SIGSEG_FREE; // value to return

@ -956,7 +956,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1,
st->town = ClosestTownFromTile(tile_org, UINT_MAX);
st->string_id = GenerateStationName(st, tile_org, STATIONNAMING_RAIL);
if (IsValidPlayer(_current_player)) {
if (IsValidPlayerID(_current_player)) {
SetBit(st->town->have_ratings, _current_player);
}
}
@ -1382,7 +1382,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st->town = ClosestTownFromTile(tile, UINT_MAX);
st->string_id = GenerateStationName(st, tile, STATIONNAMING_ROAD);
if (IsValidPlayer(_current_player)) {
if (IsValidPlayerID(_current_player)) {
SetBit(st->town->have_ratings, _current_player);
}
st->sign.width_1 = 0;
@ -1778,7 +1778,7 @@ CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st->town = t;
st->string_id = GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT);
if (IsValidPlayer(_current_player)) {
if (IsValidPlayerID(_current_player)) {
SetBit(st->town->have_ratings, _current_player);
}
st->sign.width_1 = 0;
@ -1911,7 +1911,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st->town = ClosestTownFromTile(tile, UINT_MAX);
st->string_id = GenerateStationName(st, tile, STATIONNAMING_BUOY);
if (IsValidPlayer(_current_player)) {
if (IsValidPlayerID(_current_player)) {
SetBit(st->town->have_ratings, _current_player);
}
st->sign.width_1 = 0;
@ -1960,7 +1960,7 @@ bool HasStationInUse(StationID station, PlayerID player)
static CommandCost RemoveBuoy(Station *st, uint32 flags)
{
/* XXX: strange stuff */
if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID);
if (!IsValidPlayerID(_current_player)) return_cmd_error(INVALID_STRING_ID);
TileIndex tile = st->dock_tile;
@ -2070,7 +2070,7 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st->town = ClosestTownFromTile(tile, UINT_MAX);
st->string_id = GenerateStationName(st, tile, STATIONNAMING_DOCK);
if (IsValidPlayer(_current_player)) {
if (IsValidPlayerID(_current_player)) {
SetBit(st->town->have_ratings, _current_player);
}
}
@ -2153,7 +2153,7 @@ static void DrawTile_Station(TileInfo *ti)
PlayerID owner = GetTileOwner(ti->tile);
SpriteID palette;
if (IsValidPlayer(owner)) {
if (IsValidPlayerID(owner)) {
palette = PLAYER_SPRITE_COLOR(owner);
} else {
/* Some stations are not owner by a player, namely oil rigs */
@ -2573,7 +2573,7 @@ static void UpdateStationRating(Station *st)
(rating += 13, true);
}
if (IsValidPlayer(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26;
if (IsValidPlayerID(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26;
{
byte days = ge->days_since_pickup;

@ -601,7 +601,7 @@ static const WindowDesc _player_stations_desc = {
*/
void ShowPlayerStations(PlayerID player)
{
if (!IsValidPlayer(player)) return;
if (!IsValidPlayerID(player)) return;
AllocateWindowDescFront<PlayerStationsWindow>(&_player_stations_desc, player);
}

@ -959,7 +959,7 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
PlayerID player = (PlayerID)GetInt32(&argv);
/* Nothing is added for AI or inactive players */
if (IsHumanPlayer(player) && IsValidPlayer(player)) {
if (IsHumanPlayer(player) && IsValidPlayerID(player)) {
int64 args[1];
args[0] = player + 1;
buff = GetStringWithArgs(buff, STR_7002_PLAYER, args, last);

@ -327,7 +327,7 @@ static const WindowDesc _terraform_desc = {
void ShowTerraformToolbar(Window *link)
{
if (!IsValidPlayer(_current_player)) return;
if (!IsValidPlayerID(_current_player)) return;
Window *w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
if (w != NULL && link != NULL) {
/* Align the terraform toolbar under the main toolbar and put the linked
@ -574,7 +574,7 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
/* Delete all stations owned by a player */
Station *st;
FOR_ALL_STATIONS(st) {
if (IsValidPlayer(st->owner)) delete st;
if (IsValidPlayerID(st->owner)) delete st;
}
}
}

@ -529,7 +529,7 @@ static CommandCost ClearTile_Town(TileIndex tile, byte flags)
_cleared_town_rating += rating;
Town *t = _cleared_town = GetTownByTile(tile);
if (IsValidPlayer(_current_player)) {
if (IsValidPlayerID(_current_player)) {
if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
SetDParam(0, t->index);
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
@ -2314,12 +2314,12 @@ static void UpdateTownGrowRate(Town *t)
if (DistanceSquare(st->xy, t->xy) <= t->squared_town_zone_radius[0]) {
if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
n++;
if (IsValidPlayer(st->owner)) {
if (IsValidPlayerID(st->owner)) {
int new_rating = t->ratings[st->owner] + RATING_STATION_UP_STEP;
t->ratings[st->owner] = min(new_rating, INT16_MAX); // do not let it overflow
}
} else {
if (IsValidPlayer(st->owner)) {
if (IsValidPlayerID(st->owner)) {
int new_rating = t->ratings[st->owner] + RATING_STATION_DOWN_STEP;
t->ratings[st->owner] = max(new_rating, INT16_MIN);
}
@ -2405,7 +2405,7 @@ static void UpdateTownUnwanted(Town *t)
bool CheckIfAuthorityAllows(TileIndex tile)
{
if (!IsValidPlayer(_current_player)) return true;
if (!IsValidPlayerID(_current_player)) return true;
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (t == NULL) return true;
@ -2482,7 +2482,7 @@ void ChangeTownRating(Town *t, int add, int max)
{
/* if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff */
if (t == NULL ||
!IsValidPlayer(_current_player) ||
!IsValidPlayerID(_current_player) ||
(_cheats.magic_bulldozer.value && add < 0)) {
return;
}
@ -2520,7 +2520,7 @@ static const int _default_rating_settings [3][3] = {
bool CheckforTownRating(uint32 flags, Town *t, byte type)
{
/* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */
if (t == NULL || !IsValidPlayer(_current_player) || _cheats.magic_bulldozer.value)
if (t == NULL || !IsValidPlayerID(_current_player) || _cheats.magic_bulldozer.value)
return true;
/* check if you're allowed to remove the street/bridge/tunnel/industry

@ -781,7 +781,7 @@ static const WindowDesc _scen_edit_town_gen_desc = {
void ShowBuildTownWindow()
{
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
if (_game_mode != GM_EDITOR && !IsValidPlayerID(_current_player)) return;
AllocateWindowDescFront<ScenarioEditorTownGenerationWindow>(&_scen_edit_town_gen_desc, 0);
}

@ -389,7 +389,7 @@ CommandCost CmdPlantTree(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
}
if (_game_mode != GM_EDITOR && IsValidPlayer(_current_player)) {
if (_game_mode != GM_EDITOR && IsValidPlayerID(_current_player)) {
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM);
}
@ -532,7 +532,7 @@ static CommandCost ClearTile_Trees(TileIndex tile, byte flags)
{
uint num;
if (IsValidPlayer(_current_player)) {
if (IsValidPlayerID(_current_player)) {
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM);
}

@ -179,6 +179,6 @@ static const WindowDesc _build_trees_desc = {
void ShowBuildTreesToolbar()
{
if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
if (_game_mode != GM_EDITOR && !IsValidPlayerID(_current_player)) return;
AllocateWindowDescFront<BuildTreesWindow>(&_build_trees_desc, 0);
}

@ -452,10 +452,10 @@ not_valid_below:;
* It's unnecessary to execute this command every time for every bridge. So it is done only
* and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
*/
if (!(flags & DC_QUERY_COST) || (IsValidPlayer(_current_player) && GetPlayer(_current_player)->is_ai)) {
if (!(flags & DC_QUERY_COST) || (IsValidPlayerID(_current_player) && GetPlayer(_current_player)->is_ai)) {
bridge_len += 2; // begin and end tiles/ramps
if (IsValidPlayer(_current_player) && !_is_old_ai_player)
if (IsValidPlayerID(_current_player) && !_is_old_ai_player)
bridge_len = CalcBridgeLenCostFactor(bridge_len);
cost.AddCost((int64)bridge_len * _price.build_bridge * GetBridgeSpec(bridge_type)->price >> 8);

@ -1750,7 +1750,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type)
{
assert(IsPlayerBuildableVehicleType(type));
if (!IsValidPlayer(_current_player)) return false;
if (!IsValidPlayerID(_current_player)) return false;
if (_settings_client.gui.always_build_infrastructure) return true;
UnitID max;

@ -1122,7 +1122,7 @@ static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, Vehicle
VehicleListWindow *w;
WindowNumber num;
if (!IsValidPlayer(player)) return;
if (!IsValidPlayerID(player)) return;
num = (unique_number << 16) | (vehicle_type << 11) | VLW_flag | player;

Loading…
Cancel
Save