src/player.h
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6868 7eb395287b3d
equal deleted inserted replaced
6870:ca3fd1fbe311 6871:5a9dc001e1ad
     6 #define PLAYER_H
     6 #define PLAYER_H
     7 
     7 
     8 #include "oldpool.h"
     8 #include "oldpool.h"
     9 #include "aystar.h"
     9 #include "aystar.h"
    10 #include "rail.h"
    10 #include "rail.h"
       
    11 #include "road.h"
    11 #include "engine.h"
    12 #include "engine.h"
    12 #include "livery.h"
    13 #include "livery.h"
       
    14 #include "genworld.h"
       
    15 #include "gfx.h"
    13 
    16 
    14 struct PlayerEconomyEntry {
    17 struct PlayerEconomyEntry {
    15 	Money income;
    18 	Money income;
    16 	Money expenses;
    19 	Money expenses;
    17 	int32 delivered_cargo;
    20 	int32 delivered_cargo;
   153 enum {
   156 enum {
   154 	LOAN_INTERVAL        = 10000,
   157 	LOAN_INTERVAL        = 10000,
   155 	LOAN_INTERVAL_OLD_AI = 50000,
   158 	LOAN_INTERVAL_OLD_AI = 50000,
   156 };
   159 };
   157 
   160 
   158 typedef uint32 PlayerFace;
       
   159 
       
   160 struct Player {
   161 struct Player {
   161 	uint32 name_2;
   162 	uint32 name_2;
   162 	uint16 name_1;
   163 	uint16 name_1;
   163 
   164 
   164 	uint16 president_name_1;
   165 	uint16 president_name_1;
   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"