src/player.h
author skidd13
Tue, 25 Dec 2007 13:59:21 +0000
changeset 8133 3ab8eaf85ca0
parent 8121 3bc6351e7369
child 8140 0d0d8c94f84b
permissions -rw-r--r--
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
-Codechange: Adapt the md5 algorithm to the OpenTTD source
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     2
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
     3
/** @file player.h */
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#ifndef PLAYER_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#define PLAYER_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 5077
diff changeset
     8
#include "oldpool.h"
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
     9
#include "aystar.h"
8103
cf92483a0abf (svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
rubidium
parents: 8102
diff changeset
    10
#include "rail_type.h"
8102
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 7954
diff changeset
    11
#include "road_func.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8103
diff changeset
    12
#include "cargo_type.h"
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8103
diff changeset
    13
#include "command_type.h"
2573
7a1e72905161 (svn r3110) Replace another 256 with TOTAL_NUM_ENGINES.
peter1138
parents: 2544
diff changeset
    14
#include "engine.h"
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
    15
#include "livery.h"
7857
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
    16
#include "genworld.h"
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
    17
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    18
struct PlayerEconomyEntry {
6953
230d1e3ac86c (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents: 6952
diff changeset
    19
	Money income;
230d1e3ac86c (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents: 6952
diff changeset
    20
	Money expenses;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
	int32 delivered_cargo;
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    22
	int32 performance_history; ///< player score (scale 0-1000)
6955
da3431cb25a9 (svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents: 6953
diff changeset
    23
	Money company_value;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    24
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    26
struct AiBuildRec {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	TileIndex spec_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	TileIndex use_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	byte rand_rng;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	byte cur_building_rule;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	byte unk6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	byte unk7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	byte buildcmd_a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	byte buildcmd_b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	byte direction;
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 2952
diff changeset
    36
	CargoID cargo;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    37
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    39
struct PlayerAI {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	byte state;
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    41
	byte tick;            ///< Used to determine how often to move
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    42
	uint32 state_counter; ///< Can hold tile index!
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	uint16 timeout_counter;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	byte state_mode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	byte banned_tile_count;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    47
	RailTypeByte railtype_to_use;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 2952
diff changeset
    49
	CargoID cargo_type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	byte num_wagons;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	byte build_kind;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	byte num_build_rec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	byte num_loco_to_build;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	byte num_want_fullload;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	byte route_type_mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	TileIndex start_tile_a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
	TileIndex cur_tile_a;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
    60
	DiagDirectionByte cur_dir_a;
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
    61
	DiagDirectionByte start_dir_a;
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
	TileIndex start_tile_b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	TileIndex cur_tile_b;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
    65
	DiagDirectionByte cur_dir_b;
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
    66
	DiagDirectionByte start_dir_b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    68
	Vehicle *cur_veh; ///< only used by some states
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    69
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	AiBuildRec src, dst, mid1, mid2;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    71
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	VehicleID wagon_list[9];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	byte order_list_blocks[20];
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    74
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	TileIndex banned_tiles[16];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
	byte banned_val[16];
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    77
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    79
struct Ai_PathFinderInfo {
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    80
	TileIndex start_tile_tl; ///< tl = top-left
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    81
	TileIndex start_tile_br; ///< br = bottom-right
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    82
	TileIndex end_tile_tl;   ///< tl = top-left
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    83
	TileIndex end_tile_br;   ///< br = bottom-right
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
    84
	DiagDirection start_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
    85
	DiagDirection 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
    86
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
    87
	TileIndex route[500];
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    88
	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
    89
	int route_length;
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    90
	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
    91
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    92
	bool rail_or_road;       ///< true = rail, false = road
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    93
};
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
    94
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
    95
/* The amount of memory reserved for the AI-special-vehicles */
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    96
#define AI_MAX_SPECIAL_VEHICLES 100
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    97
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    98
struct Ai_SpecialVehicle {
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
    99
	VehicleID veh_id;
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   100
	uint32 flag;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   101
};
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   102
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   103
struct PlayerAiNew {
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   104
	uint8 state;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   105
	uint tick;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   106
	uint idle;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   107
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   108
	int temp;    ///< A value used in more than one function, but it just temporary
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   109
	             ///< The use is pretty simple: with this we can 'think' about stuff
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   110
	             ///<   in more than one tick, and more than one AI. A static will not
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   111
	             ///<   do, because they are not saved. This way, the AI is almost human ;)
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   112
	int counter; ///< For the same reason as temp, we have counter. It can count how
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   113
	             ///<  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
   114
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   115
	/* Pathfinder stuff */
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   116
	Ai_PathFinderInfo path_info;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   117
	AyStar *pathfinder;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   118
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   119
	/* Route stuff */
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   120
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 2952
diff changeset
   121
	CargoID cargo;
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   122
	byte tbt;    ///< train/bus/truck 0/1/2 AI_TRAIN/AI_BUS/AI_TRUCK
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6955
diff changeset
   123
	Money new_cost;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   124
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   125
	byte action;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   126
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   127
	int last_id; ///< here is stored the last id of the searched city/industry
4289
8981ce44336d (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4077
diff changeset
   128
	Date last_vehiclecheck_date; // Used in CheckVehicle
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   129
	Ai_SpecialVehicle special_vehicles[AI_MAX_SPECIAL_VEHICLES]; ///< Some vehicles have some special flags
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   130
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   131
	TileIndex from_tile;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   132
	TileIndex to_tile;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   133
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
   134
	DiagDirectionByte from_direction;
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
   135
	DiagDirectionByte to_direction;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   136
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   137
	bool from_deliver; ///< True if this is the station that GIVES cargo
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   138
	bool to_deliver;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   139
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   140
	TileIndex depot_tile;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
   141
	DiagDirectionByte depot_direction;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   142
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   143
	byte amount_veh;       ///< How many vehicles we are going to build in this route
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   144
	byte cur_veh;          ///< How many vehicles did we bought?
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   145
	VehicleID veh_id;      ///< Used when bought a vehicle
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   146
	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
   147
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   148
	int from_ic;           ///< ic = industry/city. This is the ID of them
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   149
	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
   150
	int to_ic;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   151
	byte to_type;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   152
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   153
};
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   154
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   155
6909
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6685
diff changeset
   156
/* The "steps" in loan size, in British Pounds! */
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6685
diff changeset
   157
enum {
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6685
diff changeset
   158
	LOAN_INTERVAL        = 10000,
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6685
diff changeset
   159
	LOAN_INTERVAL_OLD_AI = 50000,
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6685
diff changeset
   160
};
5cb622b3d46a (svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents: 6685
diff changeset
   161
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   162
struct Player {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	uint32 name_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	uint16 name_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	uint16 president_name_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	uint32 president_name_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
6190
01a2b579b668 (svn r8969) -Codechange: rework of the player face bits.
rubidium
parents: 5750
diff changeset
   169
	PlayerFace face;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
6955
da3431cb25a9 (svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents: 6953
diff changeset
   171
	Money player_money;
6953
230d1e3ac86c (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents: 6952
diff changeset
   172
	Money current_loan;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	byte player_color;
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
   175
	Livery livery[LS_END];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
	byte player_money_fraction;
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   177
	byte avail_railtypes;
6685
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6643
diff changeset
   178
	byte avail_roadtypes;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	byte block_preview;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
   180
	PlayerByte index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   182
	uint16 cargo_types; ///< which cargo types were transported the last year
0
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
	TileIndex location_of_house;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
	TileIndex last_build_coordinate;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   186
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
   187
	PlayerByte share_owners[4];
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   188
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4289
diff changeset
   189
	Year inaugurated_year;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
	byte num_valid_stat_ent;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   191
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	byte quarters_of_bankrupcy;
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   193
	byte bankrupt_asked; ///< which players were asked about buying it?
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	int16 bankrupt_timeout;
6953
230d1e3ac86c (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents: 6952
diff changeset
   195
	Money bankrupt_value;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	bool is_active;
3345
0c5a7caf7f95 (svn r4129) - CodeChange: Add proper bool type for is_ai as well...it is a bool type.
Darkvater
parents: 3344
diff changeset
   198
	bool is_ai;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	PlayerAI ai;
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 0
diff changeset
   200
	PlayerAiNew ainew;
145
6e5468217504 (svn r146) -Fix [AI]: Tunnel/bridge bug
truelight
parents: 84
diff changeset
   201
6955
da3431cb25a9 (svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
rubidium
parents: 6953
diff changeset
   202
	Money yearly_expenses[3][13];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	PlayerEconomyEntry cur_economy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	PlayerEconomyEntry old_economy[24];
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   205
	EngineRenewList engine_renew_list; ///< Defined later
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2186
diff changeset
   206
	bool engine_renew;
2617
03120a0b1e39 (svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents: 2613
diff changeset
   207
	bool renew_keep_length;
2293
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2186
diff changeset
   208
	int16 engine_renew_months;
b48192aec903 (svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents: 2186
diff changeset
   209
	uint32 engine_renew_money;
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   210
	uint16 num_engines[TOTAL_NUM_ENGINES]; ///< caches the number of engines of each type the player owns (no need to save this)
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   211
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
4428
6d9fab57f2af (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
   213
uint16 GetDrawStringPlayerColor(PlayerID player);
6d9fab57f2af (svn r6183) Move GetDrawStringPlayerColor() out of gfx.[ch]
tron
parents: 4344
diff changeset
   214
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2425
diff changeset
   215
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player);
4849
1c6f21eb97f2 (svn r6775) -Codechange: Use some more proper types, especially Owner and PlayerID as
Darkvater
parents: 4848
diff changeset
   216
void GetNameOfOwner(Owner owner, TileIndex tile);
7318
632cd0497770 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 7317
diff changeset
   217
Money CalculateCompanyValue(const Player *p);
632cd0497770 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 7317
diff changeset
   218
void InvalidatePlayerWindows(const Player *p);
5376
204acb84473f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5216
diff changeset
   219
void SetLocalPlayer(PlayerID new_player);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2944
diff changeset
   220
#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
   221
7508
dc5d1757ba9f (svn r11023) -Fix [FS#1150]: Switching players (using the cheat) crashed on Big Endian machines.
rubidium
parents: 7318
diff changeset
   222
VARDEF PlayerByte _local_player;
dc5d1757ba9f (svn r11023) -Fix [FS#1150]: Switching players (using the cheat) crashed on Big Endian machines.
rubidium
parents: 7318
diff changeset
   223
VARDEF PlayerByte _current_player;
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   224
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
VARDEF Player _players[MAX_PLAYERS];
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   226
/* NOSAVE: can be determined from player structs */
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   227
VARDEF byte _player_colors[MAX_PLAYERS];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6190
diff changeset
   229
static inline byte ActivePlayerCount()
4824
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   230
{
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   231
	const Player *p;
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   232
	byte count = 0;
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   233
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   234
	FOR_ALL_PLAYERS(p) {
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   235
		if (p->is_active) count++;
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   236
	}
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   237
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   238
	return count;
c49e6ffcb89a (svn r6748) -Codechange: Use already existing function to count active players.
Darkvater
parents: 4603
diff changeset
   239
}
2944
2360b2da2bb0 (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
   240
7318
632cd0497770 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 7317
diff changeset
   241
static inline Player *GetPlayer(PlayerID i)
1767
cda2e9ac430a (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
   242
{
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
   243
	assert(IsInsideBS(i, PLAYER_FIRST, lengthof(_players)));
2425
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   244
	return &_players[i];
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   245
}
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   246
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6190
diff changeset
   247
static inline bool IsLocalPlayer()
2425
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   248
{
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2293
diff changeset
   249
	return _local_player == _current_player;
1767
cda2e9ac430a (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
   250
}
cda2e9ac430a (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
   251
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   252
static inline bool IsValidPlayer(PlayerID pi)
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   253
{
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
   254
	return IsInsideBS(pi, PLAYER_FIRST, MAX_PLAYERS);
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   255
}
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4849
diff changeset
   256
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2525
diff changeset
   257
byte GetPlayerRailtypes(PlayerID p);
6685
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6643
diff changeset
   258
byte GetPlayerRoadtypes(PlayerID p);
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   259
7857
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   260
/** Finds out if a Player has a certain railtype available
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   261
 * @param p Player in question
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   262
 * @param Railtype requested RailType
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   263
 * @return true if player has requested RailType available
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   264
 */
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   265
static inline bool HasRailtypeAvail(const Player *p, const RailType Railtype)
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   266
{
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   267
	return HasBit(p->avail_railtypes, Railtype);
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   268
}
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   269
7857
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   270
/** Finds out, whether given player has all given RoadTypes available
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   271
 * @param PlayerID ID of player
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   272
 * @param rts RoadTypes to test
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   273
 * @return true if player has all requested RoadTypes available
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   274
 */
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   275
static inline bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts)
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   276
{
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   277
	RoadTypes avail_roadtypes;
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   278
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   279
	if (p == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   280
		avail_roadtypes = ROADTYPES_ROAD;
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   281
	} else {
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   282
		if (!IsValidPlayer(p)) return false;
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   283
		avail_roadtypes = (RoadTypes)GetPlayer(p)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   284
	}
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   285
	return (rts & ~avail_roadtypes) == 0;
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   286
}
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   287
4845
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   288
static inline bool IsHumanPlayer(PlayerID pi)
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   289
{
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   290
	return !GetPlayer(pi)->is_ai;
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   291
}
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   292
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   293
static inline bool IsInteractivePlayer(PlayerID pi)
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   294
{
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   295
	return pi == _local_player;
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   296
}
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4824
diff changeset
   297
5750
5824ab1f36e2 (svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents: 5729
diff changeset
   298
void DrawPlayerIcon(PlayerID p, int x, int y);
5824ab1f36e2 (svn r8300) -Codechange: Add a prototype for DrawPlayerIcon to players.h and include that
maedhros
parents: 5729
diff changeset
   299
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   300
/* Validate functions for rail building */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7857
diff changeset
   301
static inline bool ValParamRailtype(const uint32 rail) { return HasBit(GetPlayer(_current_player)->avail_railtypes, rail);}
7857
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   302
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   303
/* Validate functions for road building */
6572278b5822 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 7734
diff changeset
   304
static inline bool ValParamRoadType(const RoadType rt) { return HasRoadTypesAvail(_current_player, RoadTypeToRoadTypes(rt));}
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2147
diff changeset
   305
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   306
/** Returns the "best" railtype a player can build.
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   307
 * As the AI doesn't know what the BEST one is, we have our own priority list
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   308
 * here. When adding new railtypes, modify this function
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   309
 * @param p the player "in action"
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   310
 * @return The "best" railtype a player has available
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3355
diff changeset
   311
 */
7318
632cd0497770 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 7317
diff changeset
   312
static inline RailType GetBestRailtype(const Player *p)
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   313
{
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   314
	if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   315
	if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
3355
e414a0b104a6 (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
   316
	if (HasRailtypeAvail(p, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   317
	return RAILTYPE_RAIL;
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   318
}
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 1977
diff changeset
   319
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   320
struct HighScore {
983
4765bf636f6b (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
   321
	char company[100];
6352
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   322
	StringID title; ///< NO_SAVE, has troubles with changing string-numbers.
938ab8f48e5d (svn r9391) -Documentation : correct Doxygen of comments and @file inclusion. Time for P and Q files
belugas
parents: 6248
diff changeset
   323
	uint16 score;   ///< do NOT change type, will break hs.dat
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   324
};
983
4765bf636f6b (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
   325
998
c90459c24842 (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
   326
VARDEF HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6190
diff changeset
   327
void SaveToHighScore();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6190
diff changeset
   328
void LoadFromHighScore();
998
c90459c24842 (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
   329
int8 SaveHighScoreValue(const Player *p);
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6190
diff changeset
   330
int8 SaveHighScoreValueNetwork();
983
4765bf636f6b (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
   331
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   332
/* Engine Replacement Functions */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   333
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   334
/**
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   335
 * Remove all engine replacement settings for the given player.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   336
 * @param p Player.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   337
 */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   338
static inline void RemoveAllEngineReplacementForPlayer(Player *p) { RemoveAllEngineReplacement(&p->engine_renew_list); }
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   339
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   340
/**
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   341
 * Retrieve the engine replacement for the given player and original engine type.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   342
 * @param p Player.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   343
 * @param engine Engine type.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   344
 * @return The engine type to replace with, or INVALID_ENGINE if no
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   345
 * replacement is in the list.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   346
 */
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6352
diff changeset
   347
static inline EngineID EngineReplacementForPlayer(const Player *p, EngineID engine, GroupID group) { return EngineReplacement(p->engine_renew_list, engine, group); }
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   348
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   349
/**
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   350
 * Check if a player has a replacement set up for the given engine.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   351
 * @param p Player.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   352
 * @param  engine Engine type to be replaced.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   353
 * @return true if a replacement was set up, false otherwise.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   354
 */
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6352
diff changeset
   355
static inline bool EngineHasReplacementForPlayer(const Player *p, EngineID engine, GroupID group) { return EngineReplacementForPlayer(p, engine, group) != INVALID_ENGINE; }
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   356
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   357
/**
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   358
 * Add an engine replacement for the player.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   359
 * @param p Player.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   360
 * @param old_engine The original engine type.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   361
 * @param new_engine The replacement engine type.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   362
 * @param flags The calling command flags.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   363
 * @return 0 on success, CMD_ERROR on failure.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   364
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   365
static inline CommandCost AddEngineReplacementForPlayer(Player *p, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags) { return AddEngineReplacement(&p->engine_renew_list, old_engine, new_engine, group, flags); }
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   366
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   367
/**
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   368
 * Remove an engine replacement for the player.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   369
 * @param p Player.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   370
 * @param engine The original engine type.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   371
 * @param flags The calling command flags.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   372
 * @return 0 on success, CMD_ERROR on failure.
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2817
diff changeset
   373
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6909
diff changeset
   374
static inline CommandCost RemoveEngineReplacementForPlayer(Player *p, EngineID engine, GroupID group, uint32 flags) {return RemoveEngineReplacement(&p->engine_renew_list, engine, group, flags); }
2697
97fc22baf3da (svn r3239) - Codechange: Introduce and use helper functions for engine replacement code.
peter1138
parents: 2617
diff changeset
   375
4603
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
   376
/**
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
   377
 * Reset the livery schemes to the player's primary colour.
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
   378
 * This is used on loading games without livery information and on new player start up.
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
   379
 * @param p Player to reset.
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
   380
 */
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
   381
void ResetPlayerLivery(Player *p);
20c816f664de (svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents: 4574
diff changeset
   382
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
#endif /* PLAYER_H */