2005-07-24 16:12:37 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-21 18:42:43 +01:00
|
|
|
/** @file player.h */
|
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
#ifndef PLAYER_H
|
|
|
|
#define PLAYER_H
|
|
|
|
|
2007-12-18 21:38:16 +01:00
|
|
|
#include "road_func.h"
|
2007-12-26 14:50:40 +01:00
|
|
|
#include "date_type.h"
|
2005-10-31 13:01:41 +01:00
|
|
|
#include "engine.h"
|
2006-09-15 14:27:00 +02:00
|
|
|
#include "livery.h"
|
2007-11-11 13:34:44 +01:00
|
|
|
#include "genworld.h"
|
2008-01-07 10:19:53 +01:00
|
|
|
#include "autoreplace_type.h"
|
2004-08-20 11:32:32 +02:00
|
|
|
|
2007-03-07 13:11:48 +01:00
|
|
|
struct PlayerEconomyEntry {
|
2007-06-18 23:44:47 +02:00
|
|
|
Money income;
|
|
|
|
Money expenses;
|
2004-08-09 19:04:08 +02:00
|
|
|
int32 delivered_cargo;
|
2007-03-21 18:42:43 +01:00
|
|
|
int32 performance_history; ///< player score (scale 0-1000)
|
2007-06-19 00:49:55 +02:00
|
|
|
Money company_value;
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2007-06-14 17:24:34 +02:00
|
|
|
/* The "steps" in loan size, in British Pounds! */
|
|
|
|
enum {
|
|
|
|
LOAN_INTERVAL = 10000,
|
|
|
|
LOAN_INTERVAL_OLD_AI = 50000,
|
|
|
|
};
|
|
|
|
|
2007-03-07 13:11:48 +01:00
|
|
|
struct Player {
|
2004-08-09 19:04:08 +02:00
|
|
|
uint32 name_2;
|
|
|
|
uint16 name_1;
|
|
|
|
|
|
|
|
uint16 president_name_1;
|
|
|
|
uint32 president_name_2;
|
|
|
|
|
2007-03-02 02:17:11 +01:00
|
|
|
PlayerFace face;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2007-06-19 00:49:55 +02:00
|
|
|
Money player_money;
|
2007-06-18 23:44:47 +02:00
|
|
|
Money current_loan;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
byte player_color;
|
2006-09-15 14:27:00 +02:00
|
|
|
Livery livery[LS_END];
|
2004-08-09 19:04:08 +02:00
|
|
|
byte player_money_fraction;
|
2005-07-21 00:02:58 +02:00
|
|
|
byte avail_railtypes;
|
2007-05-25 10:13:01 +02:00
|
|
|
byte avail_roadtypes;
|
2004-08-09 19:04:08 +02:00
|
|
|
byte block_preview;
|
2007-01-10 19:56:51 +01:00
|
|
|
PlayerByte index;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2007-03-21 18:42:43 +01:00
|
|
|
uint16 cargo_types; ///< which cargo types were transported the last year
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
TileIndex location_of_house;
|
|
|
|
TileIndex last_build_coordinate;
|
2004-08-31 18:12:52 +02:00
|
|
|
|
2007-01-10 19:56:51 +01:00
|
|
|
PlayerByte share_owners[4];
|
2004-08-31 18:12:52 +02:00
|
|
|
|
2006-08-20 20:40:57 +02:00
|
|
|
Year inaugurated_year;
|
2004-08-09 19:04:08 +02:00
|
|
|
byte num_valid_stat_ent;
|
2004-08-31 18:12:52 +02:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
byte quarters_of_bankrupcy;
|
2007-03-21 18:42:43 +01:00
|
|
|
byte bankrupt_asked; ///< which players were asked about buying it?
|
2004-08-09 19:04:08 +02:00
|
|
|
int16 bankrupt_timeout;
|
2007-06-18 23:44:47 +02:00
|
|
|
Money bankrupt_value;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
|
|
|
bool is_active;
|
2006-03-27 00:25:29 +02:00
|
|
|
bool is_ai;
|
2004-08-31 18:12:52 +02:00
|
|
|
|
2007-06-19 00:49:55 +02:00
|
|
|
Money yearly_expenses[3][13];
|
2004-08-09 19:04:08 +02:00
|
|
|
PlayerEconomyEntry cur_economy;
|
|
|
|
PlayerEconomyEntry old_economy[24];
|
2007-03-21 18:42:43 +01:00
|
|
|
EngineRenewList engine_renew_list; ///< Defined later
|
2005-08-06 18:07:22 +02:00
|
|
|
bool engine_renew;
|
2005-11-08 00:20:47 +01:00
|
|
|
bool renew_keep_length;
|
2005-08-06 18:07:22 +02:00
|
|
|
int16 engine_renew_months;
|
|
|
|
uint32 engine_renew_money;
|
2007-03-21 18:42:43 +01:00
|
|
|
uint16 num_engines[TOTAL_NUM_ENGINES]; ///< caches the number of engines of each type the player owns (no need to save this)
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2006-08-28 08:21:48 +02:00
|
|
|
uint16 GetDrawStringPlayerColor(PlayerID player);
|
|
|
|
|
2005-09-18 22:56:44 +02:00
|
|
|
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player);
|
2006-10-15 00:22:48 +02:00
|
|
|
void GetNameOfOwner(Owner owner, TileIndex tile);
|
2007-07-24 19:01:23 +02:00
|
|
|
Money CalculateCompanyValue(const Player *p);
|
|
|
|
void InvalidatePlayerWindows(const Player *p);
|
2006-12-26 13:56:48 +01:00
|
|
|
void SetLocalPlayer(PlayerID new_player);
|
2006-02-01 08:36:15 +01:00
|
|
|
#define FOR_ALL_PLAYERS(p) for (p = _players; p != endof(_players); p++)
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2007-08-31 21:49:31 +02:00
|
|
|
VARDEF PlayerByte _local_player;
|
|
|
|
VARDEF PlayerByte _current_player;
|
2005-07-21 21:36:43 +02:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
VARDEF Player _players[MAX_PLAYERS];
|
2007-03-21 18:42:43 +01:00
|
|
|
/* NOSAVE: can be determined from player structs */
|
2005-07-21 21:36:43 +02:00
|
|
|
VARDEF byte _player_colors[MAX_PLAYERS];
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
static inline byte ActivePlayerCount()
|
2006-10-12 13:42:57 +02:00
|
|
|
{
|
|
|
|
const Player *p;
|
|
|
|
byte count = 0;
|
|
|
|
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
|
if (p->is_active) count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2006-01-31 23:16:15 +01:00
|
|
|
|
2007-07-24 19:01:23 +02:00
|
|
|
static inline Player *GetPlayer(PlayerID i)
|
2005-05-06 08:56:30 +02:00
|
|
|
{
|
2007-11-24 11:38:43 +01:00
|
|
|
assert(IsInsideBS(i, PLAYER_FIRST, lengthof(_players)));
|
2005-09-14 20:03:38 +02:00
|
|
|
return &_players[i];
|
|
|
|
}
|
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
static inline bool IsLocalPlayer()
|
2005-09-14 20:03:38 +02:00
|
|
|
{
|
|
|
|
return _local_player == _current_player;
|
2005-05-06 08:56:30 +02:00
|
|
|
}
|
|
|
|
|
2006-10-15 00:31:18 +02:00
|
|
|
static inline bool IsValidPlayer(PlayerID pi)
|
|
|
|
{
|
2007-11-24 11:38:43 +01:00
|
|
|
return IsInsideBS(pi, PLAYER_FIRST, MAX_PLAYERS);
|
2006-10-15 00:31:18 +02:00
|
|
|
}
|
|
|
|
|
2005-10-20 19:43:13 +02:00
|
|
|
byte GetPlayerRailtypes(PlayerID p);
|
2007-05-25 10:13:01 +02:00
|
|
|
byte GetPlayerRoadtypes(PlayerID p);
|
2005-07-21 00:02:58 +02:00
|
|
|
|
2007-11-11 13:34:44 +01:00
|
|
|
/** Finds out if a Player has a certain railtype available
|
|
|
|
* @param p Player in question
|
|
|
|
* @param Railtype requested RailType
|
|
|
|
* @return true if player has requested RailType available
|
|
|
|
*/
|
|
|
|
static inline bool HasRailtypeAvail(const Player *p, const RailType Railtype)
|
2005-07-21 00:02:58 +02:00
|
|
|
{
|
2007-11-19 22:02:30 +01:00
|
|
|
return HasBit(p->avail_railtypes, Railtype);
|
2005-07-21 00:02:58 +02:00
|
|
|
}
|
|
|
|
|
2007-11-11 13:34:44 +01:00
|
|
|
/** Finds out, whether given player has all given RoadTypes available
|
|
|
|
* @param PlayerID ID of player
|
|
|
|
* @param rts RoadTypes to test
|
|
|
|
* @return true if player has all requested RoadTypes available
|
|
|
|
*/
|
|
|
|
static inline bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts)
|
|
|
|
{
|
|
|
|
RoadTypes avail_roadtypes;
|
|
|
|
|
|
|
|
if (p == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
|
|
|
|
avail_roadtypes = ROADTYPES_ROAD;
|
|
|
|
} else {
|
|
|
|
if (!IsValidPlayer(p)) return false;
|
|
|
|
avail_roadtypes = (RoadTypes)GetPlayer(p)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
|
|
|
|
}
|
|
|
|
return (rts & ~avail_roadtypes) == 0;
|
|
|
|
}
|
|
|
|
|
2006-10-14 17:15:56 +02:00
|
|
|
static inline bool IsHumanPlayer(PlayerID pi)
|
|
|
|
{
|
|
|
|
return !GetPlayer(pi)->is_ai;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsInteractivePlayer(PlayerID pi)
|
|
|
|
{
|
|
|
|
return pi == _local_player;
|
|
|
|
}
|
|
|
|
|
2007-01-21 12:49:18 +01:00
|
|
|
void DrawPlayerIcon(PlayerID p, int x, int y);
|
|
|
|
|
2005-07-21 21:36:43 +02:00
|
|
|
/* Validate functions for rail building */
|
2007-11-19 22:02:30 +01:00
|
|
|
static inline bool ValParamRailtype(const uint32 rail) { return HasBit(GetPlayer(_current_player)->avail_railtypes, rail);}
|
2007-11-11 13:34:44 +01:00
|
|
|
|
|
|
|
/* Validate functions for road building */
|
|
|
|
static inline bool ValParamRoadType(const RoadType rt) { return HasRoadTypesAvail(_current_player, RoadTypeToRoadTypes(rt));}
|
2005-07-21 21:36:43 +02:00
|
|
|
|
2005-07-21 00:02:58 +02:00
|
|
|
/** Returns the "best" railtype a player can build.
|
2006-06-27 23:25:53 +02:00
|
|
|
* 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
|
|
|
|
*/
|
2007-07-24 19:01:23 +02:00
|
|
|
static inline RailType GetBestRailtype(const Player *p)
|
2005-07-21 00:02:58 +02:00
|
|
|
{
|
|
|
|
if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
|
|
|
|
if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
|
2006-03-29 18:30:26 +02:00
|
|
|
if (HasRailtypeAvail(p, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
|
2005-07-21 00:02:58 +02:00
|
|
|
return RAILTYPE_RAIL;
|
|
|
|
}
|
|
|
|
|
2007-03-07 13:11:48 +01:00
|
|
|
struct HighScore {
|
2005-01-11 01:54:06 +01:00
|
|
|
char company[100];
|
2007-03-21 18:42:43 +01:00
|
|
|
StringID title; ///< NO_SAVE, has troubles with changing string-numbers.
|
|
|
|
uint16 score; ///< do NOT change type, will break hs.dat
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2005-01-11 01:54:06 +01:00
|
|
|
|
2005-01-13 17:28:47 +01:00
|
|
|
VARDEF HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
|
2007-03-07 12:47:46 +01:00
|
|
|
void SaveToHighScore();
|
|
|
|
void LoadFromHighScore();
|
2005-01-13 17:28:47 +01:00
|
|
|
int8 SaveHighScoreValue(const Player *p);
|
2007-03-07 12:47:46 +01:00
|
|
|
int8 SaveHighScoreValueNetwork();
|
2005-01-11 01:54:06 +01:00
|
|
|
|
2006-09-15 14:27:00 +02:00
|
|
|
/**
|
|
|
|
* Reset the livery schemes to the player's primary colour.
|
|
|
|
* This is used on loading games without livery information and on new player start up.
|
|
|
|
* @param p Player to reset.
|
|
|
|
*/
|
|
|
|
void ResetPlayerLivery(Player *p);
|
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
#endif /* PLAYER_H */
|