236 return count; |
237 return count; |
237 } |
238 } |
238 |
239 |
239 static inline Player *GetPlayer(PlayerID i) |
240 static inline Player *GetPlayer(PlayerID i) |
240 { |
241 { |
241 assert(IS_INSIDE_1D(i, PLAYER_FIRST, lengthof(_players))); |
242 assert(IsInsideBS(i, PLAYER_FIRST, lengthof(_players))); |
242 return &_players[i]; |
243 return &_players[i]; |
243 } |
244 } |
244 |
245 |
245 static inline bool IsLocalPlayer() |
246 static inline bool IsLocalPlayer() |
246 { |
247 { |
247 return _local_player == _current_player; |
248 return _local_player == _current_player; |
248 } |
249 } |
249 |
250 |
250 static inline bool IsValidPlayer(PlayerID pi) |
251 static inline bool IsValidPlayer(PlayerID pi) |
251 { |
252 { |
252 return IS_INSIDE_1D(pi, PLAYER_FIRST, MAX_PLAYERS); |
253 return IsInsideBS(pi, PLAYER_FIRST, MAX_PLAYERS); |
253 } |
254 } |
254 |
255 |
255 byte GetPlayerRailtypes(PlayerID p); |
256 byte GetPlayerRailtypes(PlayerID p); |
256 byte GetPlayerRoadtypes(PlayerID p); |
257 byte GetPlayerRoadtypes(PlayerID p); |
257 |
258 |
258 /** Finds out if a Player has a certain railtype available */ |
259 /** Finds out if a Player has a certain railtype available |
259 static inline bool HasRailtypeAvail(const Player *p, RailType Railtype) |
260 * @param p Player in question |
260 { |
261 * @param Railtype requested RailType |
261 return HASBIT(p->avail_railtypes, Railtype); |
262 * @return true if player has requested RailType available |
|
263 */ |
|
264 static inline bool HasRailtypeAvail(const Player *p, const RailType Railtype) |
|
265 { |
|
266 return HasBit(p->avail_railtypes, Railtype); |
|
267 } |
|
268 |
|
269 /** Finds out, whether given player has all given RoadTypes available |
|
270 * @param PlayerID ID of player |
|
271 * @param rts RoadTypes to test |
|
272 * @return true if player has all requested RoadTypes available |
|
273 */ |
|
274 static inline bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts) |
|
275 { |
|
276 RoadTypes avail_roadtypes; |
|
277 |
|
278 if (p == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) { |
|
279 avail_roadtypes = ROADTYPES_ROAD; |
|
280 } else { |
|
281 if (!IsValidPlayer(p)) return false; |
|
282 avail_roadtypes = (RoadTypes)GetPlayer(p)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody |
|
283 } |
|
284 return (rts & ~avail_roadtypes) == 0; |
262 } |
285 } |
263 |
286 |
264 static inline bool IsHumanPlayer(PlayerID pi) |
287 static inline bool IsHumanPlayer(PlayerID pi) |
265 { |
288 { |
266 return !GetPlayer(pi)->is_ai; |
289 return !GetPlayer(pi)->is_ai; |
272 } |
295 } |
273 |
296 |
274 void DrawPlayerIcon(PlayerID p, int x, int y); |
297 void DrawPlayerIcon(PlayerID p, int x, int y); |
275 |
298 |
276 /* Validate functions for rail building */ |
299 /* Validate functions for rail building */ |
277 static inline bool ValParamRailtype(uint32 rail) { return HASBIT(GetPlayer(_current_player)->avail_railtypes, rail);} |
300 static inline bool ValParamRailtype(const uint32 rail) { return HasBit(GetPlayer(_current_player)->avail_railtypes, rail);} |
|
301 |
|
302 /* Validate functions for road building */ |
|
303 static inline bool ValParamRoadType(const RoadType rt) { return HasRoadTypesAvail(_current_player, RoadTypeToRoadTypes(rt));} |
278 |
304 |
279 /** Returns the "best" railtype a player can build. |
305 /** Returns the "best" railtype a player can build. |
280 * As the AI doesn't know what the BEST one is, we have our own priority list |
306 * As the AI doesn't know what the BEST one is, we have our own priority list |
281 * here. When adding new railtypes, modify this function |
307 * here. When adding new railtypes, modify this function |
282 * @param p the player "in action" |
308 * @param p the player "in action" |