src/player.h
changeset 8732 b18f578f7c16
parent 8725 b769d0a63f06
child 8733 9e2d2a2619ff
equal deleted inserted replaced
8731:a2cab8a23491 8732:b18f578f7c16
     3 /** @file player.h */
     3 /** @file player.h */
     4 
     4 
     5 #ifndef PLAYER_H
     5 #ifndef PLAYER_H
     6 #define PLAYER_H
     6 #define PLAYER_H
     7 
     7 
     8 #include "road_func.h"
     8 #include "road_type.h"
       
     9 #include "rail_type.h"
     9 #include "date_type.h"
    10 #include "date_type.h"
    10 #include "engine.h"
    11 #include "engine.h"
    11 #include "livery.h"
    12 #include "livery.h"
    12 #include "genworld.h"
       
    13 #include "autoreplace_type.h"
    13 #include "autoreplace_type.h"
    14 
    14 
    15 struct PlayerEconomyEntry {
    15 struct PlayerEconomyEntry {
    16 	Money income;
    16 	Money income;
    17 	Money expenses;
    17 	Money expenses;
    39 	Money current_loan;
    39 	Money current_loan;
    40 
    40 
    41 	byte player_color;
    41 	byte player_color;
    42 	Livery livery[LS_END];
    42 	Livery livery[LS_END];
    43 	byte player_money_fraction;
    43 	byte player_money_fraction;
    44 	byte avail_railtypes;
    44 	RailTypes avail_railtypes;
    45 	byte avail_roadtypes;
    45 	RoadTypes avail_roadtypes;
    46 	byte block_preview;
    46 	byte block_preview;
    47 	PlayerByte index;
    47 	PlayerByte index;
    48 
    48 
    49 	uint16 cargo_types; ///< which cargo types were transported the last year
    49 	uint16 cargo_types; ///< which cargo types were transported the last year
    50 
    50 
   117 static inline bool IsValidPlayer(PlayerID pi)
   117 static inline bool IsValidPlayer(PlayerID pi)
   118 {
   118 {
   119 	return IsInsideBS(pi, PLAYER_FIRST, MAX_PLAYERS);
   119 	return IsInsideBS(pi, PLAYER_FIRST, MAX_PLAYERS);
   120 }
   120 }
   121 
   121 
   122 byte GetPlayerRailtypes(PlayerID p);
       
   123 byte GetPlayerRoadtypes(PlayerID p);
       
   124 
       
   125 /** Finds out if a Player has a certain railtype available
       
   126  * @param p Player in question
       
   127  * @param Railtype requested RailType
       
   128  * @return true if player has requested RailType available
       
   129  */
       
   130 static inline bool HasRailtypeAvail(const Player *p, const RailType Railtype)
       
   131 {
       
   132 	return HasBit(p->avail_railtypes, Railtype);
       
   133 }
       
   134 
       
   135 /** Finds out, whether given player has all given RoadTypes available
       
   136  * @param PlayerID ID of player
       
   137  * @param rts RoadTypes to test
       
   138  * @return true if player has all requested RoadTypes available
       
   139  */
       
   140 static inline bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts)
       
   141 {
       
   142 	RoadTypes avail_roadtypes;
       
   143 
       
   144 	if (p == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
       
   145 		avail_roadtypes = ROADTYPES_ROAD;
       
   146 	} else {
       
   147 		if (!IsValidPlayer(p)) return false;
       
   148 		avail_roadtypes = (RoadTypes)GetPlayer(p)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
       
   149 	}
       
   150 	return (rts & ~avail_roadtypes) == 0;
       
   151 }
       
   152 
       
   153 static inline bool IsHumanPlayer(PlayerID pi)
   122 static inline bool IsHumanPlayer(PlayerID pi)
   154 {
   123 {
   155 	return !GetPlayer(pi)->is_ai;
   124 	return !GetPlayer(pi)->is_ai;
   156 }
   125 }
   157 
   126 
   159 {
   128 {
   160 	return pi == _local_player;
   129 	return pi == _local_player;
   161 }
   130 }
   162 
   131 
   163 void DrawPlayerIcon(PlayerID p, int x, int y);
   132 void DrawPlayerIcon(PlayerID p, int x, int y);
   164 
       
   165 /* Validate functions for rail building */
       
   166 static inline bool ValParamRailtype(const uint32 rail) { return HasBit(GetPlayer(_current_player)->avail_railtypes, rail);}
       
   167 
       
   168 /* Validate functions for road building */
       
   169 static inline bool ValParamRoadType(const RoadType rt) { return HasRoadTypesAvail(_current_player, RoadTypeToRoadTypes(rt));}
       
   170 
       
   171 /** Returns the "best" railtype a player can build.
       
   172  * As the AI doesn't know what the BEST one is, we have our own priority list
       
   173  * here. When adding new railtypes, modify this function
       
   174  * @param p the player "in action"
       
   175  * @return The "best" railtype a player has available
       
   176  */
       
   177 static inline RailType GetBestRailtype(const Player *p)
       
   178 {
       
   179 	if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
       
   180 	if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
       
   181 	if (HasRailtypeAvail(p, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
       
   182 	return RAILTYPE_RAIL;
       
   183 }
       
   184 
   133 
   185 struct HighScore {
   134 struct HighScore {
   186 	char company[100];
   135 	char company[100];
   187 	StringID title; ///< NO_SAVE, has troubles with changing string-numbers.
   136 	StringID title; ///< NO_SAVE, has troubles with changing string-numbers.
   188 	uint16 score;   ///< do NOT change type, will break hs.dat
   137 	uint16 score;   ///< do NOT change type, will break hs.dat