src/player_base.h
author rubidium
Sat, 02 Aug 2008 22:48:01 +0000
changeset 9787 cedb26977f52
parent 9661 7bfc9b673b17
child 9890 d78e15f4ac71
permissions -rw-r--r--
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
     1
/* $Id$ */
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
     2
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
     3
/** @file player_base.h Definition of stuff that is very close to a player, like the player struct itself. */
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
     4
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
     5
#ifndef PLAYER_BASE_H
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
     6
#define PLAYER_BASE_H
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
     7
9659
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
     8
#include "player_type.h"
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
     9
#include "oldpool.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    10
#include "road_type.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    11
#include "rail_type.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    12
#include "date_type.h"
8786
1823ff88a054 (svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents: 8515
diff changeset
    13
#include "engine_type.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    14
#include "livery.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    15
#include "autoreplace_type.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    16
#include "economy_type.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    17
#include "tile_type.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    18
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    19
struct PlayerEconomyEntry {
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    20
	Money income;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    21
	Money expenses;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    22
	int32 delivered_cargo;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    23
	int32 performance_history; ///< player score (scale 0-1000)
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    24
	Money company_value;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    25
};
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    26
9659
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    27
DECLARE_OLD_POOL(Player, Player, 1, MAX_PLAYERS)
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    28
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    29
struct Player : PoolItem<Player, PlayerByte, &_Player_pool> {
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    30
	Player(uint16 name_1 = 0, bool is_ai = false);
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    31
	~Player();
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    32
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    33
	uint32 name_2;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    34
	uint16 name_1;
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
    35
	char *name;
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    36
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    37
	uint16 president_name_1;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    38
	uint32 president_name_2;
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
    39
	char *president_name;
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    40
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    41
	PlayerFace face;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    42
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    43
	Money player_money;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    44
	Money current_loan;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    45
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    46
	byte player_color;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    47
	Livery livery[LS_END];
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    48
	byte player_money_fraction;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    49
	RailTypes avail_railtypes;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    50
	RoadTypes avail_roadtypes;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    51
	byte block_preview;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    52
9017
3d422fffe39c (svn r12816) -Fix: the cargo count in the performance rating window could be wrong.
rubidium
parents: 8786
diff changeset
    53
	uint32 cargo_types; ///< which cargo types were transported the last year
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    54
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    55
	TileIndex location_of_house;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    56
	TileIndex last_build_coordinate;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    57
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    58
	PlayerByte share_owners[4];
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    59
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    60
	Year inaugurated_year;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    61
	byte num_valid_stat_ent;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    62
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    63
	byte quarters_of_bankrupcy;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    64
	byte bankrupt_asked; ///< which players were asked about buying it?
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    65
	int16 bankrupt_timeout;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    66
	Money bankrupt_value;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    67
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    68
	bool is_ai;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    69
8515
20b5c6e8415e (svn r12090) -Codechange : removed a magic number and code style application on enum ExpensesType
belugas
parents: 8258
diff changeset
    70
	Money yearly_expenses[3][EXPENSES_END];
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    71
	PlayerEconomyEntry cur_economy;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    72
	PlayerEconomyEntry old_economy[24];
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    73
	EngineRenewList engine_renew_list; ///< Defined later
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    74
	bool engine_renew;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    75
	bool renew_keep_length;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    76
	int16 engine_renew_months;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    77
	uint32 engine_renew_money;
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 9061
diff changeset
    78
	uint16 *num_engines; ///< caches the number of engines of each type the player owns (no need to save this)
9659
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    79
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    80
	inline bool IsValid() const { return this->name_1 != 0; }
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    81
};
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
    82
9659
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    83
static inline bool IsValidPlayerID(PlayerID index)
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    84
{
9661
7bfc9b673b17 (svn r13733) -Fix (r13731): gcc2.95 compilation
smatz
parents: 9659
diff changeset
    85
	return (uint)index < GetPlayerPoolSize() && GetPlayer(index)->IsValid();
9659
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    86
}
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    87
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    88
#define FOR_ALL_PLAYERS_FROM(d, start) for (d = GetPlayer(start); d != NULL; d = (d->index + 1U < GetPlayerPoolSize()) ? GetPlayer(d->index + 1U) : NULL) if (d->IsValid())
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    89
#define FOR_ALL_PLAYERS(d) FOR_ALL_PLAYERS_FROM(d, 0)
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
    90
9061
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    91
struct PlayerMoneyBackup {
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    92
private:
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    93
	Money backup_yearly_expenses[EXPENSES_END];
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    94
	PlayerEconomyEntry backup_cur_economy;
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    95
	Player *p;
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    96
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    97
public:
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    98
	PlayerMoneyBackup(Player *player);
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
    99
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
   100
	void Restore();
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
   101
};
8ebd40e86171 (svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents: 9017
diff changeset
   102
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   103
static inline byte ActivePlayerCount()
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   104
{
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   105
	const Player *p;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   106
	byte count = 0;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   107
9659
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9070
diff changeset
   108
	FOR_ALL_PLAYERS(p) count++;
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   109
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   110
	return count;
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   111
}
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   112
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   113
Money CalculateCompanyValue(const Player *p);
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   114
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
diff changeset
   115
#endif /* PLAYER_BASE_H */