author | matthijs |
Wed, 22 Mar 2006 22:26:16 +0000 | |
branch | 0.4.5 |
changeset 9958 | bed516c67d61 |
parent 2944 | 7c392e7b51c6 |
child 2952 | 6a26eeda9679 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#ifndef PLAYER_H |
4 |
#define PLAYER_H |
|
5 |
||
2848 | 6 |
#include "pool.h" |
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
7 |
#include "aystar.h" |
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
8 |
#include "rail.h" |
2573
1950c5c3aab5
(svn r3110) Replace another 256 with TOTAL_NUM_ENGINES.
peter1138
parents:
2544
diff
changeset
|
9 |
#include "engine.h" |
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
10 |
|
0 | 11 |
typedef struct PlayerEconomyEntry { |
12 |
int32 income; |
|
13 |
int32 expenses; |
|
14 |
int32 delivered_cargo; |
|
147
d0c8100d18cf
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
darkvater
parents:
145
diff
changeset
|
15 |
int32 performance_history; // player score (scale 0-1000) |
200
03b8104d1479
(svn r201) -Fix: [1025836] Company values bigger dan int32 were put to negative
truelight
parents:
147
diff
changeset
|
16 |
int64 company_value; |
0 | 17 |
} PlayerEconomyEntry; |
18 |
||
19 |
typedef struct AiBuildRec { |
|
20 |
TileIndex spec_tile; |
|
21 |
TileIndex use_tile; |
|
22 |
byte rand_rng; |
|
23 |
byte cur_building_rule; |
|
24 |
byte unk6; |
|
25 |
byte unk7; |
|
26 |
byte buildcmd_a; |
|
27 |
byte buildcmd_b; |
|
28 |
byte direction; |
|
29 |
byte cargo; |
|
30 |
} AiBuildRec; |
|
31 |
||
32 |
typedef struct PlayerAI { |
|
33 |
byte state; |
|
34 |
byte tick; // Used to determine how often to move |
|
1576
a066e33fa297
(svn r2080) - Fix: [OldAI] p->ai.state_counter was uint16 but could hold a tile index, therefore overflowing - changed that to uint32 and bumped the savegame revision to 32. It *MIGHT* close bug 1151374 - it certainly caused AI to stop building anything sometimes.
pasky
parents:
998
diff
changeset
|
35 |
uint32 state_counter; // Can hold tile index! |
0 | 36 |
uint16 timeout_counter; |
37 |
||
38 |
byte state_mode; |
|
39 |
byte banned_tile_count; |
|
40 |
byte railtype_to_use; |
|
41 |
||
42 |
byte cargo_type; |
|
43 |
byte num_wagons; |
|
44 |
byte build_kind; |
|
45 |
byte num_build_rec; |
|
46 |
byte num_loco_to_build; |
|
47 |
byte num_want_fullload; |
|
48 |
||
49 |
byte route_type_mask; |
|
50 |
||
51 |
TileIndex start_tile_a; |
|
52 |
TileIndex cur_tile_a; |
|
53 |
byte cur_dir_a; |
|
54 |
byte start_dir_a; |
|
145 | 55 |
|
0 | 56 |
TileIndex start_tile_b; |
57 |
TileIndex cur_tile_b; |
|
58 |
byte cur_dir_b; |
|
59 |
byte start_dir_b; |
|
60 |
||
61 |
Vehicle *cur_veh; /* only used by some states */ |
|
145 | 62 |
|
0 | 63 |
AiBuildRec src, dst, mid1, mid2; |
145 | 64 |
|
0 | 65 |
VehicleID wagon_list[9]; |
66 |
byte order_list_blocks[20]; |
|
145 | 67 |
|
0 | 68 |
TileIndex banned_tiles[16]; |
69 |
byte banned_val[16]; |
|
70 |
} PlayerAI; |
|
71 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
72 |
typedef struct Ai_PathFinderInfo { |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
73 |
TileIndex start_tile_tl; // tl = top-left |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
74 |
TileIndex start_tile_br; // br = bottom-right |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
75 |
TileIndex end_tile_tl; // tl = top-left |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
76 |
TileIndex end_tile_br; // br = bottom-right |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
77 |
byte start_direction; // 0 to 3 or AI_PATHFINDER_NO_DIRECTION |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
78 |
byte end_direction; // 0 to 3 or AI_PATHFINDER_NO_DIRECTION |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
79 |
|
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
80 |
TileIndex route[500]; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
81 |
byte route_extra[500]; // Some extra information about the route like bridge/tunnel |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
82 |
int route_length; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
83 |
int position; // Current position in the build-path, needed to build the path |
145 | 84 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
85 |
bool rail_or_road; // true = rail, false = road |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
86 |
} Ai_PathFinderInfo; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
87 |
|
145 | 88 |
// The amount of memory reserved for the AI-special-vehicles |
89 |
#define AI_MAX_SPECIAL_VEHICLES 100 |
|
90 |
||
91 |
typedef struct Ai_SpecialVehicle { |
|
92 |
VehicleID veh_id; |
|
93 |
uint32 flag; |
|
94 |
} Ai_SpecialVehicle; |
|
95 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
96 |
typedef struct PlayerAiNew { |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
97 |
uint8 state; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
98 |
uint tick; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
99 |
uint idle; |
145 | 100 |
|
826 | 101 |
int temp; // A value used in more than one function, but it just temporary |
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
102 |
// The use is pretty simple: with this we can 'think' about stuff |
826 | 103 |
// in more than one tick, and more than one AI. A static will not |
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
104 |
// do, because they are not saved. This way, the AI is almost human ;) |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
105 |
int counter; // For the same reason as temp, we have counter. It can count how |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
106 |
// long we are trying something, and just abort if it takes too long |
145 | 107 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
108 |
// Pathfinder stuff |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
109 |
Ai_PathFinderInfo path_info; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
110 |
AyStar *pathfinder; |
145 | 111 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
112 |
// Route stuff |
145 | 113 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
114 |
byte cargo; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
115 |
byte tbt; // train/bus/truck 0/1/2 AI_TRAIN/AI_BUS/AI_TRUCK |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
116 |
int new_cost; |
145 | 117 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
118 |
byte action; |
145 | 119 |
|
990
5cbf62b64f36
(svn r1488) -Fix: fixed some spelling mistakes (tnx to Tron)
truelight
parents:
983
diff
changeset
|
120 |
int last_id; // here is stored the last id of the searched city/industry |
145 | 121 |
uint last_vehiclecheck_date; // Used in CheckVehicle |
122 |
Ai_SpecialVehicle special_vehicles[AI_MAX_SPECIAL_VEHICLES]; // Some vehicles have some special flags |
|
123 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
124 |
TileIndex from_tile; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
125 |
TileIndex to_tile; |
145 | 126 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
127 |
byte from_direction; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
128 |
byte to_direction; |
145 | 129 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
130 |
bool from_deliver; // True if this is the station that GIVES cargo |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
131 |
bool to_deliver; |
145 | 132 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
133 |
TileIndex depot_tile; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
134 |
byte depot_direction; |
145 | 135 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
136 |
byte amount_veh; // How many vehicles we are going to build in this route |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
137 |
byte cur_veh; // How many vehicles did we bought? |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
138 |
VehicleID veh_id; // Used when bought a vehicle |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
139 |
VehicleID veh_main_id; // The ID of the first vehicle, for shared copy |
145 | 140 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
141 |
int from_ic; // ic = industry/city. This is the ID of them |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
142 |
byte from_type; // AI_NO_TYPE/AI_CITY/AI_INDUSTRY |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
143 |
int to_ic; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
144 |
byte to_type; |
145 | 145 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
146 |
} PlayerAiNew; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
147 |
|
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
148 |
|
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
149 |
|
0 | 150 |
typedef struct Player { |
151 |
uint32 name_2; |
|
152 |
uint16 name_1; |
|
153 |
||
154 |
uint16 president_name_1; |
|
155 |
uint32 president_name_2; |
|
156 |
||
157 |
uint32 face; |
|
158 |
||
159 |
int32 player_money; |
|
160 |
int32 current_loan; |
|
161 |
int64 money64; // internal 64-bit version of the money. the 32-bit field will be clamped to plus minus 2 billion |
|
162 |
||
163 |
byte player_color; |
|
164 |
byte player_money_fraction; |
|
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
165 |
byte avail_railtypes; |
0 | 166 |
byte block_preview; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
167 |
PlayerID index; |
0 | 168 |
|
169 |
uint16 cargo_types; /* which cargo types were transported the last year */ |
|
170 |
||
171 |
TileIndex location_of_house; |
|
172 |
TileIndex last_build_coordinate; |
|
145 | 173 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
174 |
PlayerID share_owners[4]; |
145 | 175 |
|
0 | 176 |
byte inaugurated_year; |
177 |
byte num_valid_stat_ent; |
|
145 | 178 |
|
0 | 179 |
byte quarters_of_bankrupcy; |
180 |
byte bankrupt_asked; // which players were asked about buying it? |
|
181 |
int16 bankrupt_timeout; |
|
182 |
int32 bankrupt_value; |
|
183 |
||
184 |
bool is_active; |
|
185 |
byte is_ai; |
|
186 |
PlayerAI ai; |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
187 |
PlayerAiNew ainew; |
145 | 188 |
|
0 | 189 |
int64 yearly_expenses[3][13]; |
190 |
PlayerEconomyEntry cur_economy; |
|
191 |
PlayerEconomyEntry old_economy[24]; |
|
2848 | 192 |
EngineRenewList engine_renew_list; // Defined later |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2186
diff
changeset
|
193 |
bool engine_renew; |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2613
diff
changeset
|
194 |
bool renew_keep_length; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2186
diff
changeset
|
195 |
int16 engine_renew_months; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2186
diff
changeset
|
196 |
uint32 engine_renew_money; |
0 | 197 |
} Player; |
198 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
199 |
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player); |
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
200 |
void GetNameOfOwner(PlayerID owner, TileIndex tile); |
2475 | 201 |
int64 CalculateCompanyValue(const Player* p); |
202 |
void InvalidatePlayerWindows(const Player* p); |
|
0 | 203 |
void UpdatePlayerMoney32(Player *p); |
204 |
#define FOR_ALL_PLAYERS(p) for(p=_players; p != endof(_players); p++) |
|
205 |
||
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
206 |
VARDEF PlayerID _local_player; |
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
207 |
VARDEF PlayerID _current_player; |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2147
diff
changeset
|
208 |
|
0 | 209 |
#define MAX_PLAYERS 8 |
210 |
VARDEF Player _players[MAX_PLAYERS]; |
|
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2147
diff
changeset
|
211 |
// NOSAVE: can be determined from player structs |
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2147
diff
changeset
|
212 |
VARDEF byte _player_colors[MAX_PLAYERS]; |
0 | 213 |
|
2944
7c392e7b51c6
(svn r3500) - Workaround the inaccurate count of spectators/companies that can happen in certain border-cases. For now just dynamically get this value when requested so it is always right. To do properly all player/client creation/destruction needs a hook for networking.
Darkvater
parents:
2848
diff
changeset
|
214 |
byte ActivePlayerCount(void); |
7c392e7b51c6
(svn r3500) - Workaround the inaccurate count of spectators/companies that can happen in certain border-cases. For now just dynamically get this value when requested so it is always right. To do properly all player/client creation/destruction needs a hook for networking.
Darkvater
parents:
2848
diff
changeset
|
215 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
216 |
static inline Player* GetPlayer(PlayerID i) |
1767
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1576
diff
changeset
|
217 |
{ |
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
218 |
assert(i < lengthof(_players)); |
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
219 |
return &_players[i]; |
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
220 |
} |
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
221 |
|
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
222 |
static inline bool IsLocalPlayer(void) |
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
223 |
{ |
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2293
diff
changeset
|
224 |
return _local_player == _current_player; |
1767
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1576
diff
changeset
|
225 |
} |
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1576
diff
changeset
|
226 |
|
2544 | 227 |
void DeletePlayerWindows(PlayerID pi); |
228 |
byte GetPlayerRailtypes(PlayerID p); |
|
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
229 |
|
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
230 |
/** Finds out if a Player has a certain railtype available |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
231 |
*/ |
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
232 |
static inline bool HasRailtypeAvail(const Player *p, RailType Railtype) |
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
233 |
{ |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
234 |
return HASBIT(p->avail_railtypes, Railtype); |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
235 |
} |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
236 |
|
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2147
diff
changeset
|
237 |
/* Validate functions for rail building */ |
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2147
diff
changeset
|
238 |
static inline bool ValParamRailtype(uint32 rail) { return HASBIT(GetPlayer(_current_player)->avail_railtypes, rail);} |
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2147
diff
changeset
|
239 |
|
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
240 |
/** Returns the "best" railtype a player can build. |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
241 |
* As the AI doesn't know what the BEST one is, we |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
242 |
* have our own priority list here. When adding |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
243 |
* new railtypes, modify this function |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
244 |
* @param p the player "in action" |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
245 |
* @return The "best" railtype a player has available |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
246 |
*/ |
2520
75eb66d6e371
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2475
diff
changeset
|
247 |
static inline RailType GetBestRailtype(const Player* p) |
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
248 |
{ |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
249 |
if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV; |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
250 |
if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO; |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
251 |
return RAILTYPE_RAIL; |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
252 |
} |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
1977
diff
changeset
|
253 |
|
2475 | 254 |
#define IS_HUMAN_PLAYER(p) (!GetPlayer(p)->is_ai) |
255 |
#define IS_INTERACTIVE_PLAYER(p) ((p) == _local_player) |
|
0 | 256 |
|
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
826
diff
changeset
|
257 |
typedef struct HighScore { |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
826
diff
changeset
|
258 |
char company[100]; |
2613
b008d366ed8a
(svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents:
2573
diff
changeset
|
259 |
StringID title; // NO_SAVE, has troubles with changing string-numbers. |
b008d366ed8a
(svn r3151) - Fix: showing the highscore might crash the game with an invalid string message in the case when a highscore file was used before certain strings were added.
Darkvater
parents:
2573
diff
changeset
|
260 |
uint16 score; // do NOT change type, will break hs.dat |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
826
diff
changeset
|
261 |
} HighScore; |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
826
diff
changeset
|
262 |
|
998
d9dc257b8949
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
990
diff
changeset
|
263 |
VARDEF HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5 |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
826
diff
changeset
|
264 |
void SaveToHighScore(void); |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
826
diff
changeset
|
265 |
void LoadFromHighScore(void); |
998
d9dc257b8949
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
990
diff
changeset
|
266 |
int8 SaveHighScoreValue(const Player *p); |
d9dc257b8949
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
990
diff
changeset
|
267 |
int8 SaveHighScoreValueNetwork(void); |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
826
diff
changeset
|
268 |
|
2848 | 269 |
/* Engine Replacement Functions */ |
270 |
||
271 |
/** |
|
272 |
* Remove all engine replacement settings for the given player. |
|
273 |
* @param p Player. |
|
274 |
*/ |
|
275 |
static inline void RemoveAllEngineReplacementForPlayer(Player *p) { RemoveAllEngineReplacement(&p->engine_renew_list); } |
|
276 |
||
277 |
/** |
|
278 |
* Retrieve the engine replacement for the given player and original engine type. |
|
279 |
* @param p Player. |
|
280 |
* @param engine Engine type. |
|
281 |
* @return The engine type to replace with, or INVALID_ENGINE if no |
|
282 |
* replacement is in the list. |
|
283 |
*/ |
|
284 |
static inline EngineID EngineReplacementForPlayer(const Player *p, EngineID engine) { return EngineReplacement(p->engine_renew_list, engine); } |
|
285 |
||
286 |
/** |
|
287 |
* Check if a player has a replacement set up for the given engine. |
|
288 |
* @param p Player. |
|
289 |
* @param engine Engine type to be replaced. |
|
290 |
* @return true if a replacement was set up, false otherwise. |
|
291 |
*/ |
|
292 |
static inline bool EngineHasReplacementForPlayer(const Player *p, EngineID engine) { return EngineReplacementForPlayer(p, engine) != INVALID_ENGINE; } |
|
293 |
||
294 |
/** |
|
295 |
* Add an engine replacement for the player. |
|
296 |
* @param p Player. |
|
297 |
* @param old_engine The original engine type. |
|
298 |
* @param new_engine The replacement engine type. |
|
299 |
* @param flags The calling command flags. |
|
300 |
* @return 0 on success, CMD_ERROR on failure. |
|
301 |
*/ |
|
302 |
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); } |
|
303 |
||
304 |
/** |
|
305 |
* Remove an engine replacement for the player. |
|
306 |
* @param p Player. |
|
307 |
* @param engine The original engine type. |
|
308 |
* @param flags The calling command flags. |
|
309 |
* @return 0 on success, CMD_ERROR on failure. |
|
310 |
*/ |
|
311 |
static inline int32 RemoveEngineReplacementForPlayer(Player *p, EngineID engine, uint32 flags) {return RemoveEngineReplacement(&p->engine_renew_list, engine, flags); } |
|
2697
c7b1a950c4cf
(svn r3239) - Codechange: Introduce and use helper functions for engine replacement code.
peter1138
parents:
2617
diff
changeset
|
312 |
|
0 | 313 |
#endif /* PLAYER_H */ |