File diff r4844:dcf812ad20ab → r4845:2200ed004c20
player.h
Show inline comments
 
@@ -203,116 +203,123 @@ uint16 GetDrawStringPlayerColor(PlayerID
 

	
 
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player);
 
void GetNameOfOwner(PlayerID owner, TileIndex tile);
 
int64 CalculateCompanyValue(const Player* p);
 
void InvalidatePlayerWindows(const Player* p);
 
void UpdatePlayerMoney32(Player *p);
 
#define FOR_ALL_PLAYERS(p) for (p = _players; p != endof(_players); p++)
 

	
 
VARDEF PlayerID _local_player;
 
VARDEF PlayerID _current_player;
 

	
 
#define MAX_PLAYERS 8
 
VARDEF Player _players[MAX_PLAYERS];
 
// NOSAVE: can be determined from player structs
 
VARDEF byte _player_colors[MAX_PLAYERS];
 

	
 
static inline byte ActivePlayerCount(void)
 
{
 
	const Player *p;
 
	byte count = 0;
 

	
 
	FOR_ALL_PLAYERS(p) {
 
		if (p->is_active) count++;
 
	}
 

	
 
	return count;
 
}
 

	
 
static inline Player* GetPlayer(PlayerID i)
 
{
 
	assert(i < lengthof(_players));
 
	return &_players[i];
 
}
 

	
 
static inline bool IsLocalPlayer(void)
 
{
 
	return _local_player == _current_player;
 
}
 

	
 
void DeletePlayerWindows(PlayerID pi);
 
byte GetPlayerRailtypes(PlayerID p);
 

	
 
/** Finds out if a Player has a certain railtype available */
 
static inline bool HasRailtypeAvail(const Player *p, RailType Railtype)
 
{
 
	return HASBIT(p->avail_railtypes, Railtype);
 
}
 

	
 
static inline bool IsHumanPlayer(PlayerID pi)
 
{
 
	return !GetPlayer(pi)->is_ai;
 
}
 

	
 
static inline bool IsInteractivePlayer(PlayerID pi)
 
{
 
	return pi == _local_player;
 
}
 

	
 
/* Validate functions for rail building */
 
static inline bool ValParamRailtype(uint32 rail) { return HASBIT(GetPlayer(_current_player)->avail_railtypes, rail);}
 

	
 
/** Returns the "best" railtype a player can build.
 
 * As the AI doesn't know what the BEST one is, we have our own priority list
 
 * here. When adding new railtypes, modify this function
 
 * @param p the player "in action"
 
 * @return The "best" railtype a player has available
 
 */
 
static inline RailType GetBestRailtype(const Player* p)
 
{
 
	if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
 
	if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
 
	if (HasRailtypeAvail(p, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
 
	return RAILTYPE_RAIL;
 
}
 

	
 
#define IS_HUMAN_PLAYER(p) (!GetPlayer(p)->is_ai)
 
#define IS_INTERACTIVE_PLAYER(p) ((p) == _local_player)
 

	
 
typedef struct HighScore {
 
	char company[100];
 
	StringID title; // NO_SAVE, has troubles with changing string-numbers.
 
	uint16 score;   // do NOT change type, will break hs.dat
 
} HighScore;
 

	
 
VARDEF HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
 
void SaveToHighScore(void);
 
void LoadFromHighScore(void);
 
int8 SaveHighScoreValue(const Player *p);
 
int8 SaveHighScoreValueNetwork(void);
 

	
 
/* Engine Replacement Functions */
 

	
 
/**
 
 * Remove all engine replacement settings for the given player.
 
 * @param p Player.
 
 */
 
static inline void RemoveAllEngineReplacementForPlayer(Player *p) { RemoveAllEngineReplacement(&p->engine_renew_list); }
 

	
 
/**
 
 * Retrieve the engine replacement for the given player and original engine type.
 
 * @param p Player.
 
 * @param engine Engine type.
 
 * @return The engine type to replace with, or INVALID_ENGINE if no
 
 * replacement is in the list.
 
 */
 
static inline EngineID EngineReplacementForPlayer(const Player *p, EngineID engine) { return EngineReplacement(p->engine_renew_list, engine); }
 

	
 
/**
 
 * Check if a player has a replacement set up for the given engine.
 
 * @param p Player.
 
 * @param  engine Engine type to be replaced.
 
 * @return true if a replacement was set up, false otherwise.
 
 */
 
static inline bool EngineHasReplacementForPlayer(const Player *p, EngineID engine) { return EngineReplacementForPlayer(p, engine) != INVALID_ENGINE; }
 

	
 
/**
 
 * Add an engine replacement for the player.
 
 * @param p Player.
 
 * @param old_engine The original engine type.
 
 * @param new_engine The replacement engine type.
 
 * @param flags The calling command flags.
 
 * @return 0 on success, CMD_ERROR on failure.
 
 */
 
static inline int32 AddEngineReplacementForPlayer(Player *p, EngineID old_engine, EngineID new_engine, uint32 flags) { return AddEngineReplacement(&p->engine_renew_list, old_engine, new_engine, flags); }
 

	
 
/**