author | darkvater |
Wed, 01 Sep 2004 21:54:12 +0000 | |
changeset 147 | d0c8100d18cf |
parent 145 | 6e5468217504 |
child 200 | 03b8104d1479 |
permissions | -rw-r--r-- |
0 | 1 |
#ifndef PLAYER_H |
2 |
#define PLAYER_H |
|
3 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
4 |
#include "aystar.h" |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
5 |
|
0 | 6 |
typedef struct PlayerEconomyEntry { |
7 |
int32 income; |
|
8 |
int32 expenses; |
|
9 |
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
|
10 |
int32 performance_history; // player score (scale 0-1000) |
0 | 11 |
int32 company_value; |
12 |
} PlayerEconomyEntry; |
|
13 |
||
14 |
typedef struct AiBuildRec { |
|
15 |
TileIndex spec_tile; |
|
16 |
TileIndex use_tile; |
|
17 |
byte rand_rng; |
|
18 |
byte cur_building_rule; |
|
19 |
byte unk6; |
|
20 |
byte unk7; |
|
21 |
byte buildcmd_a; |
|
22 |
byte buildcmd_b; |
|
23 |
byte direction; |
|
24 |
byte cargo; |
|
25 |
} AiBuildRec; |
|
26 |
||
27 |
typedef struct PlayerAI { |
|
28 |
byte state; |
|
29 |
byte tick; // Used to determine how often to move |
|
30 |
uint16 state_counter; |
|
31 |
uint16 timeout_counter; |
|
32 |
||
33 |
byte state_mode; |
|
34 |
byte banned_tile_count; |
|
35 |
byte railtype_to_use; |
|
36 |
||
37 |
byte cargo_type; |
|
38 |
byte num_wagons; |
|
39 |
byte build_kind; |
|
40 |
byte num_build_rec; |
|
41 |
byte num_loco_to_build; |
|
42 |
byte num_want_fullload; |
|
43 |
||
44 |
byte route_type_mask; |
|
45 |
||
46 |
TileIndex start_tile_a; |
|
47 |
TileIndex cur_tile_a; |
|
48 |
byte cur_dir_a; |
|
49 |
byte start_dir_a; |
|
145 | 50 |
|
0 | 51 |
TileIndex start_tile_b; |
52 |
TileIndex cur_tile_b; |
|
53 |
byte cur_dir_b; |
|
54 |
byte start_dir_b; |
|
55 |
||
56 |
Vehicle *cur_veh; /* only used by some states */ |
|
145 | 57 |
|
0 | 58 |
AiBuildRec src, dst, mid1, mid2; |
145 | 59 |
|
0 | 60 |
VehicleID wagon_list[9]; |
61 |
byte order_list_blocks[20]; |
|
145 | 62 |
|
0 | 63 |
TileIndex banned_tiles[16]; |
64 |
byte banned_val[16]; |
|
65 |
} PlayerAI; |
|
66 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
67 |
typedef struct Ai_PathFinderInfo { |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
|
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
75 |
TileIndex route[500]; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
76 |
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
|
77 |
int route_length; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
78 |
int position; // Current position in the build-path, needed to build the path |
145 | 79 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
80 |
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
|
81 |
} Ai_PathFinderInfo; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
82 |
|
145 | 83 |
// The amount of memory reserved for the AI-special-vehicles |
84 |
#define AI_MAX_SPECIAL_VEHICLES 100 |
|
85 |
||
86 |
typedef struct Ai_SpecialVehicle { |
|
87 |
VehicleID veh_id; |
|
88 |
uint32 flag; |
|
89 |
} Ai_SpecialVehicle; |
|
90 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
91 |
typedef struct PlayerAiNew { |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
92 |
uint8 state; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
93 |
uint tick; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
94 |
uint idle; |
145 | 95 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
96 |
int temp; // A value used in more then one function, but it just temporary |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
97 |
// The use is pretty simple: with this we can 'think' about stuff |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
98 |
// in more then one tick, and more then one AI. A static will not |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
99 |
// 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
|
100 |
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
|
101 |
// long we are trying something, and just abort if it takes too long |
145 | 102 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
103 |
// Pathfinder stuff |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
104 |
Ai_PathFinderInfo path_info; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
105 |
AyStar *pathfinder; |
145 | 106 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
107 |
// Route stuff |
145 | 108 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
109 |
byte cargo; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
110 |
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
|
111 |
int new_cost; |
145 | 112 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
113 |
byte action; |
145 | 114 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
115 |
uint last_id; // here is stored the last id of the searched city/industry |
145 | 116 |
uint last_vehiclecheck_date; // Used in CheckVehicle |
117 |
Ai_SpecialVehicle special_vehicles[AI_MAX_SPECIAL_VEHICLES]; // Some vehicles have some special flags |
|
118 |
||
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
119 |
TileIndex from_tile; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
120 |
TileIndex to_tile; |
145 | 121 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
122 |
byte from_direction; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
123 |
byte to_direction; |
145 | 124 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
125 |
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
|
126 |
bool to_deliver; |
145 | 127 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
128 |
TileIndex depot_tile; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
129 |
byte depot_direction; |
145 | 130 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
VehicleID veh_main_id; // The ID of the first vehicle, for shared copy |
145 | 135 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
int to_ic; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
139 |
byte to_type; |
145 | 140 |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
141 |
} PlayerAiNew; |
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
142 |
|
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
143 |
|
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
144 |
|
0 | 145 |
typedef struct Player { |
146 |
uint32 name_2; |
|
147 |
uint16 name_1; |
|
148 |
||
149 |
uint16 president_name_1; |
|
150 |
uint32 president_name_2; |
|
151 |
||
152 |
uint32 face; |
|
153 |
||
154 |
int32 player_money; |
|
155 |
int32 current_loan; |
|
156 |
int64 money64; // internal 64-bit version of the money. the 32-bit field will be clamped to plus minus 2 billion |
|
157 |
||
158 |
byte player_color; |
|
159 |
byte player_money_fraction; |
|
160 |
byte max_railtype; |
|
161 |
byte block_preview; |
|
162 |
byte index; |
|
163 |
||
164 |
uint16 cargo_types; /* which cargo types were transported the last year */ |
|
165 |
||
166 |
TileIndex location_of_house; |
|
167 |
TileIndex last_build_coordinate; |
|
145 | 168 |
|
0 | 169 |
byte share_owners[4]; |
145 | 170 |
|
0 | 171 |
byte inaugurated_year; |
172 |
byte num_valid_stat_ent; |
|
145 | 173 |
|
0 | 174 |
byte quarters_of_bankrupcy; |
175 |
byte bankrupt_asked; // which players were asked about buying it? |
|
176 |
int16 bankrupt_timeout; |
|
177 |
int32 bankrupt_value; |
|
178 |
||
179 |
bool is_active; |
|
180 |
byte is_ai; |
|
181 |
PlayerAI ai; |
|
84
1e0721c29bad
(svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
0
diff
changeset
|
182 |
PlayerAiNew ainew; |
145 | 183 |
|
0 | 184 |
int64 yearly_expenses[3][13]; |
185 |
PlayerEconomyEntry cur_economy; |
|
186 |
PlayerEconomyEntry old_economy[24]; |
|
187 |
} Player; |
|
188 |
||
189 |
void ChangeOwnershipOfPlayerItems(byte old_player, byte new_player); |
|
190 |
void GetNameOfOwner(byte owner, uint tile); |
|
191 |
uint32 CalculateCompanyValue(Player *p); |
|
192 |
void InvalidatePlayerWindows(Player *p); |
|
193 |
void AiDoGameLoop(Player *p); |
|
194 |
void UpdatePlayerMoney32(Player *p); |
|
195 |
#define DEREF_PLAYER(i) (&_players[i]) |
|
196 |
#define FOR_ALL_PLAYERS(p) for(p=_players; p != endof(_players); p++) |
|
197 |
||
198 |
#define MAX_PLAYERS 8 |
|
199 |
VARDEF Player _players[MAX_PLAYERS]; |
|
200 |
||
201 |
#define IS_HUMAN_PLAYER(p) (!DEREF_PLAYER((byte)(p))->is_ai) |
|
202 |
#define IS_INTERACTIVE_PLAYER(p) (((byte)p) == _local_player) |
|
203 |
||
204 |
#endif /* PLAYER_H */ |