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 |