52 |
52 |
53 /** |
53 /** |
54 * Sets the local player and updates the patch settings that are set on a |
54 * Sets the local player and updates the patch settings that are set on a |
55 * per-company (player) basis to reflect the core's state in the GUI. |
55 * per-company (player) basis to reflect the core's state in the GUI. |
56 * @param new_player the new player |
56 * @param new_player the new player |
57 * @pre IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE |
57 * @pre IsValidPlayerID(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE |
58 */ |
58 */ |
59 void SetLocalPlayer(PlayerID new_player) |
59 void SetLocalPlayer(PlayerID new_player) |
60 { |
60 { |
61 /* Player could also be PLAYER_SPECTATOR or OWNER_NONE */ |
61 /* Player could also be PLAYER_SPECTATOR or OWNER_NONE */ |
62 assert(IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE); |
62 assert(IsValidPlayerID(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE); |
63 |
63 |
64 _local_player = new_player; |
64 _local_player = new_player; |
65 |
65 |
66 /* Do not update the patches if we are in the intro GUI */ |
66 /* Do not update the patches if we are in the intro GUI */ |
67 if (IsValidPlayer(new_player) && _game_mode != GM_MENU) { |
67 if (IsValidPlayerID(new_player) && _game_mode != GM_MENU) { |
68 const Player *p = GetPlayer(new_player); |
68 const Player *p = GetPlayer(new_player); |
69 _settings_client.gui.autorenew = p->engine_renew; |
69 _settings_client.gui.autorenew = p->engine_renew; |
70 _settings_client.gui.autorenew_months = p->engine_renew_months; |
70 _settings_client.gui.autorenew_months = p->engine_renew_months; |
71 _settings_client.gui.autorenew_money = p->engine_renew_money; |
71 _settings_client.gui.autorenew_money = p->engine_renew_money; |
72 InvalidateWindow(WC_GAME_OPTIONS, 0); |
72 InvalidateWindow(WC_GAME_OPTIONS, 0); |
81 |
81 |
82 uint16 GetDrawStringPlayerColor(PlayerID player) |
82 uint16 GetDrawStringPlayerColor(PlayerID player) |
83 { |
83 { |
84 /* Get the color for DrawString-subroutines which matches the color |
84 /* Get the color for DrawString-subroutines which matches the color |
85 * of the player */ |
85 * of the player */ |
86 if (!IsValidPlayer(player)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOR; |
86 if (!IsValidPlayerID(player)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOR; |
87 return (_colour_gradient[_player_colors[player]][4]) | IS_PALETTE_COLOR; |
87 return (_colour_gradient[_player_colors[player]][4]) | IS_PALETTE_COLOR; |
88 } |
88 } |
89 |
89 |
90 void DrawPlayerIcon(PlayerID p, int x, int y) |
90 void DrawPlayerIcon(PlayerID p, int x, int y) |
91 { |
91 { |
164 * Checks whether a player's face is a valid encoding. |
164 * Checks whether a player's face is a valid encoding. |
165 * Unused bits are not enforced to be 0. |
165 * Unused bits are not enforced to be 0. |
166 * @param pf the fact to check |
166 * @param pf the fact to check |
167 * @return true if and only if the face is valid |
167 * @return true if and only if the face is valid |
168 */ |
168 */ |
169 bool IsValidPlayerFace(PlayerFace pf) |
169 bool IsValidPlayerIDFace(PlayerFace pf) |
170 { |
170 { |
171 if (!ArePlayerFaceBitsValid(pf, PFV_GEN_ETHN, GE_WM)) return false; |
171 if (!ArePlayerFaceBitsValid(pf, PFV_GEN_ETHN, GE_WM)) return false; |
172 |
172 |
173 GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM); |
173 GenderEthnicity ge = (GenderEthnicity)GetPlayerFaceBits(pf, PFV_GEN_ETHN, GE_WM); |
174 bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0; |
174 bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0; |
201 |
201 |
202 bool CheckPlayerHasMoney(CommandCost cost) |
202 bool CheckPlayerHasMoney(CommandCost cost) |
203 { |
203 { |
204 if (cost.GetCost() > 0) { |
204 if (cost.GetCost() > 0) { |
205 PlayerID pid = _current_player; |
205 PlayerID pid = _current_player; |
206 if (IsValidPlayer(pid) && cost.GetCost() > GetPlayer(pid)->player_money) { |
206 if (IsValidPlayerID(pid) && cost.GetCost() > GetPlayer(pid)->player_money) { |
207 SetDParam(0, cost.GetCost()); |
207 SetDParam(0, cost.GetCost()); |
208 _error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES; |
208 _error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES; |
209 return false; |
209 return false; |
210 } |
210 } |
211 } |
211 } |
257 |
257 |
258 void SubtractMoneyFromPlayer(CommandCost cost) |
258 void SubtractMoneyFromPlayer(CommandCost cost) |
259 { |
259 { |
260 PlayerID pid = _current_player; |
260 PlayerID pid = _current_player; |
261 |
261 |
262 if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost); |
262 if (IsValidPlayerID(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost); |
263 } |
263 } |
264 |
264 |
265 void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst) |
265 void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst) |
266 { |
266 { |
267 Player *p = GetPlayer(player); |
267 Player *p = GetPlayer(player); |
277 void GetNameOfOwner(Owner owner, TileIndex tile) |
277 void GetNameOfOwner(Owner owner, TileIndex tile) |
278 { |
278 { |
279 SetDParam(2, owner); |
279 SetDParam(2, owner); |
280 |
280 |
281 if (owner != OWNER_TOWN) { |
281 if (owner != OWNER_TOWN) { |
282 if (!IsValidPlayer(owner)) { |
282 if (!IsValidPlayerID(owner)) { |
283 SetDParam(0, STR_0150_SOMEONE); |
283 SetDParam(0, STR_0150_SOMEONE); |
284 } else { |
284 } else { |
285 const Player* p = GetPlayer(owner); |
285 const Player* p = GetPlayer(owner); |
286 |
286 |
287 SetDParam(0, STR_COMPANY_NAME); |
287 SetDParam(0, STR_COMPANY_NAME); |
684 * if p1 = 5, then |
684 * if p1 = 5, then |
685 * - p2 = enable renew_keep_length |
685 * - p2 = enable renew_keep_length |
686 */ |
686 */ |
687 CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
687 CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
688 { |
688 { |
689 if (!IsValidPlayer(_current_player)) return CMD_ERROR; |
689 if (!IsValidPlayerID(_current_player)) return CMD_ERROR; |
690 |
690 |
691 Player *p = GetPlayer(_current_player); |
691 Player *p = GetPlayer(_current_player); |
692 switch (GB(p1, 0, 3)) { |
692 switch (GB(p1, 0, 3)) { |
693 case 0: |
693 case 0: |
694 if (p->engine_renew == HasBit(p2, 0)) return CMD_ERROR; |
694 if (p->engine_renew == HasBit(p2, 0)) return CMD_ERROR; |
887 * DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */ |
887 * DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */ |
888 NetworkClientInfo *ci = &_network_client_info[cid]; |
888 NetworkClientInfo *ci = &_network_client_info[cid]; |
889 ci->client_playas = p->index; |
889 ci->client_playas = p->index; |
890 NetworkUpdateClientInfo(ci->client_index); |
890 NetworkUpdateClientInfo(ci->client_index); |
891 |
891 |
892 if (IsValidPlayer(ci->client_playas)) { |
892 if (IsValidPlayerID(ci->client_playas)) { |
893 PlayerID player_backup = _local_player; |
893 PlayerID player_backup = _local_player; |
894 _network_player_info[p->index].months_empty = 0; |
894 _network_player_info[p->index].months_empty = 0; |
895 |
895 |
896 /* XXX - When a client joins, we automatically set its name to the |
896 /* XXX - When a client joins, we automatically set its name to the |
897 * player's name (for some reason). As it stands now only the server |
897 * player's name (for some reason). As it stands now only the server |
947 |
947 |
948 case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */ |
948 case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */ |
949 PlayerID pid_old = (PlayerID)GB(p2, 0, 16); |
949 PlayerID pid_old = (PlayerID)GB(p2, 0, 16); |
950 PlayerID pid_new = (PlayerID)GB(p2, 16, 16); |
950 PlayerID pid_new = (PlayerID)GB(p2, 16, 16); |
951 |
951 |
952 if (!IsValidPlayer(pid_old) || !IsValidPlayer(pid_new)) return CMD_ERROR; |
952 if (!IsValidPlayerID(pid_old) || !IsValidPlayerID(pid_new)) return CMD_ERROR; |
953 |
953 |
954 if (!(flags & DC_EXEC)) return CMD_ERROR; |
954 if (!(flags & DC_EXEC)) return CMD_ERROR; |
955 |
955 |
956 ChangeOwnershipOfPlayerItems(pid_old, pid_new); |
956 ChangeOwnershipOfPlayerItems(pid_old, pid_new); |
957 DeletePlayerStuff(pid_old); |
957 DeletePlayerStuff(pid_old); |