player.h
author KUDr
Mon, 11 Sep 2006 17:28:27 +0000
changeset 4590 020290824b22
parent 4574 497540b4a75f
child 4603 3ccd4ee0a2e2
permissions -rw-r--r--
(svn r6440) -Fix: [YAPF] some YAPF settings were not saved (i misunderstood how save flags work). This probably caused some MP desyncs. Thanks Maedhros for noticing and peter1138 for this patch.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#ifndef PLAYER_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     4
#define PLAYER_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
     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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
typedef struct PlayerEconomyEntry {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
	int32 income;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
	int32 expenses;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
	int32 delivered_cargo;
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
} PlayerEconomyEntry;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
typedef struct AiBuildRec {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
	TileIndex spec_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
	TileIndex use_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
	byte rand_rng;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
	byte cur_building_rule;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
	byte unk6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	byte unk7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
	byte buildcmd_a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	byte buildcmd_b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	byte direction;
3344
d86c852715fa (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 2952
diff changeset
    29
	CargoID cargo;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
} AiBuildRec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
typedef struct PlayerAI {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	byte state;
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	uint16 timeout_counter;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	byte state_mode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	byte banned_tile_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	byte railtype_to_use;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
3344
d86c852715fa (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 2952
diff changeset
    42
	CargoID cargo_type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	byte num_wagons;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	byte build_kind;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	byte num_build_rec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	byte num_loco_to_build;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	byte num_want_fullload;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	byte route_type_mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	TileIndex start_tile_a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	TileIndex cur_tile_a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	byte cur_dir_a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	byte start_dir_a;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    55
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	TileIndex start_tile_b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	TileIndex cur_tile_b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	byte cur_dir_b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
	byte start_dir_b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	Vehicle *cur_veh; /* only used by some states */
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    62
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	AiBuildRec src, dst, mid1, mid2;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    64
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	VehicleID wagon_list[9];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	byte order_list_blocks[20];
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    67
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	TileIndex banned_tiles[16];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
	byte banned_val[16];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
} PlayerAI;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    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
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    75
	TileIndex end_tile_tl;   // tl = top-left
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    76
	TileIndex end_tile_br;   // br = bottom-right
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    77
	byte start_direction;    // 0 to 3 or AI_PATHFINDER_NO_DIRECTION
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    78
	byte end_direction;      // 0 to 3 or AI_PATHFINDER_NO_DIRECTION
84
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];
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    81
	byte route_extra[500];   // Some extra information about the route like bridge/tunnel
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
    82
	int route_length;
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    83
	int position;            // Current position in the build-path, needed to build the path
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    84
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
    85
	bool rail_or_road;       // true = rail, false = road
84
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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    88
// The amount of memory reserved for the AI-special-vehicles
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    89
#define AI_MAX_SPECIAL_VEHICLES 100
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    90
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    91
typedef struct Ai_SpecialVehicle {
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    92
	VehicleID veh_id;
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    93
	uint32 flag;
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    94
} Ai_SpecialVehicle;
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   100
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   101
	int temp;    // A value used in more than one function, but it just temporary
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   102
	             // The use is pretty simple: with this we can 'think' about stuff
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   103
	             //   in more than one tick, and more than one AI. A static will not
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   104
	             //   do, because they are not saved. This way, the AI is almost human ;)
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   105
	int counter; // For the same reason as temp, we have counter. It can count how
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   106
	             //  long we are trying something, and just abort if it takes too long
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   111
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   112
	// Route stuff
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   113
3344
d86c852715fa (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 2952
diff changeset
   114
	CargoID cargo;
84
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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   117
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   118
	byte action;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   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
4289
ff1b2b915cab (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4077
diff changeset
   121
	Date last_vehiclecheck_date; // Used in CheckVehicle
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   122
	Ai_SpecialVehicle special_vehicles[AI_MAX_SPECIAL_VEHICLES]; // Some vehicles have some special flags
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   135
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   136
	byte amount_veh;       // How many vehicles we are going to build in this route
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   137
	byte cur_veh;          // How many vehicles did we bought?
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   138
	VehicleID veh_id;      // Used when bought a vehicle
84
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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   140
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   141
	int from_ic;           // ic = industry/city. This is the ID of them
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   142
	byte from_type;        // AI_NO_TYPE/AI_CITY/AI_INDUSTRY
84
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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
typedef struct Player {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	uint32 name_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	uint16 name_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	uint16 president_name_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	uint32 president_name_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	uint32 face;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	int32 player_money;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	int32 current_loan;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	int64 money64; // internal 64-bit version of the money. the 32-bit field will be clamped to plus minus 2 billion
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	byte player_color;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	uint16 cargo_types; /* which cargo types were transported the last year */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	TileIndex location_of_house;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	TileIndex last_build_coordinate;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   175
4326
c2ae4dbc1074 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4289
diff changeset
   176
	Year inaugurated_year;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	byte num_valid_stat_ent;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   178
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	byte quarters_of_bankrupcy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	byte bankrupt_asked; // which players were asked about buying it?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	int16 bankrupt_timeout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	int32 bankrupt_value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	bool is_active;
3345
40dc834caa24 (svn r4129) - CodeChange: Add proper bool type for is_ai as well...it is a bool type.
Darkvater
parents: 3344
diff changeset
   185
	bool is_ai;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   188
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	int64 yearly_expenses[3][13];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
	PlayerEconomyEntry cur_economy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	PlayerEconomyEntry old_economy[24];
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   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;
4574
497540b4a75f (svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents: 4549
diff changeset
   197
	uint16 num_engines[TOTAL_NUM_ENGINES]; // caches the number of engines of each type the player owns (no need to save this)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
} Player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
4428
0b0ee542d5b6 (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
   200
uint16 GetDrawStringPlayerColor(PlayerID player);
0b0ee542d5b6 (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
   201
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
   202
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
   203
void GetNameOfOwner(PlayerID owner, TileIndex tile);
2475
8443e1eefe1b (svn r3001) s/Player*/const Player*/
tron
parents: 2447
diff changeset
   204
int64 CalculateCompanyValue(const Player* p);
8443e1eefe1b (svn r3001) s/Player*/const Player*/
tron
parents: 2447
diff changeset
   205
void InvalidatePlayerWindows(const Player* p);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
void UpdatePlayerMoney32(Player *p);
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   207
#define FOR_ALL_PLAYERS(p) for (p = _players; p != endof(_players); p++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
2425
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   209
VARDEF PlayerID _local_player;
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   210
VARDEF PlayerID _current_player;
2154
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   211
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
#define MAX_PLAYERS 8
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
VARDEF Player _players[MAX_PLAYERS];
2154
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   214
// NOSAVE: can be determined from player structs
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   215
VARDEF byte _player_colors[MAX_PLAYERS];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
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
   217
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
   218
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
   219
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
   220
{
2425
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   221
	assert(i < lengthof(_players));
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   222
	return &_players[i];
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
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   225
static inline bool IsLocalPlayer(void)
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   226
{
99e1e8430a28 (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   227
	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
   228
}
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
   229
2544
50cb52cdeb73 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2525
diff changeset
   230
void DeletePlayerWindows(PlayerID pi);
50cb52cdeb73 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2525
diff changeset
   231
byte GetPlayerRailtypes(PlayerID p);
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   232
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4428
diff changeset
   233
/** Finds out if a Player has a certain railtype available */
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
   234
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
   235
{
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   236
	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
   237
}
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   238
2154
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   239
/* Validate functions for rail building */
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   240
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
   241
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   242
/** Returns the "best" railtype a player can build.
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   243
 * As the AI doesn't know what the BEST one is, we have our own priority list
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   244
 * here. When adding new railtypes, modify this function
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   245
 * @param p the player "in action"
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   246
 * @return The "best" railtype a player has available
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   247
 */
2520
75eb66d6e371 (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2475
diff changeset
   248
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
   249
{
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   250
	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
   251
	if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
3355
a653b8e47f27 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3345
diff changeset
   252
	if (HasRailtypeAvail(p, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   253
	return RAILTYPE_RAIL;
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   254
}
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   255
2475
8443e1eefe1b (svn r3001) s/Player*/const Player*/
tron
parents: 2447
diff changeset
   256
#define IS_HUMAN_PLAYER(p) (!GetPlayer(p)->is_ai)
8443e1eefe1b (svn r3001) s/Player*/const Player*/
tron
parents: 2447
diff changeset
   257
#define IS_INTERACTIVE_PLAYER(p) ((p) == _local_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
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
   259
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
   260
	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
   261
	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
   262
	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
   263
} 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
   264
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
   265
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
   266
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
   267
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
   268
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
   269
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
   270
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   271
/* Engine Replacement Functions */
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   272
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   273
/**
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   274
 * Remove all engine replacement settings for the given player.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   275
 * @param p Player.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   276
 */
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   277
static inline void RemoveAllEngineReplacementForPlayer(Player *p) { RemoveAllEngineReplacement(&p->engine_renew_list); }
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   278
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   279
/**
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   280
 * Retrieve the engine replacement for the given player and original engine type.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   281
 * @param p Player.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   282
 * @param engine Engine type.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   283
 * @return The engine type to replace with, or INVALID_ENGINE if no
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   284
 * replacement is in the list.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   285
 */
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   286
static inline EngineID EngineReplacementForPlayer(const Player *p, EngineID engine) { return EngineReplacement(p->engine_renew_list, engine); }
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   287
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   288
/**
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   289
 * Check if a player has a replacement set up for the given engine.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   290
 * @param p Player.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   291
 * @param  engine Engine type to be replaced.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   292
 * @return true if a replacement was set up, false otherwise.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   293
 */
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   294
static inline bool EngineHasReplacementForPlayer(const Player *p, EngineID engine) { return EngineReplacementForPlayer(p, engine) != INVALID_ENGINE; }
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   295
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   296
/**
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   297
 * Add an engine replacement for the player.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   298
 * @param p Player.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   299
 * @param old_engine The original engine type.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   300
 * @param new_engine The replacement engine type.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   301
 * @param flags The calling command flags.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   302
 * @return 0 on success, CMD_ERROR on failure.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   303
 */
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   304
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); }
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   305
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   306
/**
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   307
 * Remove an engine replacement for the player.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   308
 * @param p Player.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   309
 * @param engine The original engine type.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   310
 * @param flags The calling command flags.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   311
 * @return 0 on success, CMD_ERROR on failure.
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   312
 */
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   313
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
   314
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
#endif /* PLAYER_H */