2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef PLAYER_H
|
|
|
|
#define PLAYER_H
|
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
#include "aystar.h"
|
2005-07-20 22:02:58 +00:00
|
|
|
#include "rail.h"
|
2004-08-20 09:32:32 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef struct PlayerEconomyEntry {
|
|
|
|
int32 income;
|
|
|
|
int32 expenses;
|
|
|
|
int32 delivered_cargo;
|
2004-09-01 21:54:12 +00:00
|
|
|
int32 performance_history; // player score (scale 0-1000)
|
2004-09-11 09:40:19 +00:00
|
|
|
int64 company_value;
|
2004-08-09 17:04:08 +00:00
|
|
|
} PlayerEconomyEntry;
|
|
|
|
|
|
|
|
typedef struct AiBuildRec {
|
|
|
|
TileIndex spec_tile;
|
|
|
|
TileIndex use_tile;
|
|
|
|
byte rand_rng;
|
|
|
|
byte cur_building_rule;
|
|
|
|
byte unk6;
|
|
|
|
byte unk7;
|
|
|
|
byte buildcmd_a;
|
|
|
|
byte buildcmd_b;
|
|
|
|
byte direction;
|
|
|
|
byte cargo;
|
|
|
|
} AiBuildRec;
|
|
|
|
|
|
|
|
typedef struct PlayerAI {
|
|
|
|
byte state;
|
|
|
|
byte tick; // Used to determine how often to move
|
2005-03-27 00:28:14 +00:00
|
|
|
uint32 state_counter; // Can hold tile index!
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 timeout_counter;
|
|
|
|
|
|
|
|
byte state_mode;
|
|
|
|
byte banned_tile_count;
|
|
|
|
byte railtype_to_use;
|
|
|
|
|
|
|
|
byte cargo_type;
|
|
|
|
byte num_wagons;
|
|
|
|
byte build_kind;
|
|
|
|
byte num_build_rec;
|
|
|
|
byte num_loco_to_build;
|
|
|
|
byte num_want_fullload;
|
|
|
|
|
|
|
|
byte route_type_mask;
|
|
|
|
|
|
|
|
TileIndex start_tile_a;
|
|
|
|
TileIndex cur_tile_a;
|
|
|
|
byte cur_dir_a;
|
|
|
|
byte start_dir_a;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex start_tile_b;
|
|
|
|
TileIndex cur_tile_b;
|
|
|
|
byte cur_dir_b;
|
|
|
|
byte start_dir_b;
|
|
|
|
|
|
|
|
Vehicle *cur_veh; /* only used by some states */
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
AiBuildRec src, dst, mid1, mid2;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
VehicleID wagon_list[9];
|
|
|
|
byte order_list_blocks[20];
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex banned_tiles[16];
|
|
|
|
byte banned_val[16];
|
|
|
|
} PlayerAI;
|
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
typedef struct Ai_PathFinderInfo {
|
|
|
|
TileIndex start_tile_tl; // tl = top-left
|
|
|
|
TileIndex start_tile_br; // br = bottom-right
|
|
|
|
TileIndex end_tile_tl; // tl = top-left
|
|
|
|
TileIndex end_tile_br; // br = bottom-right
|
|
|
|
byte start_direction; // 0 to 3 or AI_PATHFINDER_NO_DIRECTION
|
|
|
|
byte end_direction; // 0 to 3 or AI_PATHFINDER_NO_DIRECTION
|
|
|
|
|
|
|
|
TileIndex route[500];
|
|
|
|
byte route_extra[500]; // Some extra information about the route like bridge/tunnel
|
|
|
|
int route_length;
|
|
|
|
int position; // Current position in the build-path, needed to build the path
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
bool rail_or_road; // true = rail, false = road
|
|
|
|
} Ai_PathFinderInfo;
|
|
|
|
|
2004-08-31 16:12:52 +00:00
|
|
|
// The amount of memory reserved for the AI-special-vehicles
|
|
|
|
#define AI_MAX_SPECIAL_VEHICLES 100
|
|
|
|
|
|
|
|
typedef struct Ai_SpecialVehicle {
|
|
|
|
VehicleID veh_id;
|
|
|
|
uint32 flag;
|
|
|
|
} Ai_SpecialVehicle;
|
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
typedef struct PlayerAiNew {
|
|
|
|
uint8 state;
|
|
|
|
uint tick;
|
|
|
|
uint idle;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-12-29 13:13:29 +00:00
|
|
|
int temp; // A value used in more than one function, but it just temporary
|
2004-08-20 09:32:32 +00:00
|
|
|
// The use is pretty simple: with this we can 'think' about stuff
|
2004-12-29 13:13:29 +00:00
|
|
|
// in more than one tick, and more than one AI. A static will not
|
2004-08-20 09:32:32 +00:00
|
|
|
// do, because they are not saved. This way, the AI is almost human ;)
|
|
|
|
int counter; // For the same reason as temp, we have counter. It can count how
|
|
|
|
// long we are trying something, and just abort if it takes too long
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
// Pathfinder stuff
|
|
|
|
Ai_PathFinderInfo path_info;
|
|
|
|
AyStar *pathfinder;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
// Route stuff
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
byte cargo;
|
|
|
|
byte tbt; // train/bus/truck 0/1/2 AI_TRAIN/AI_BUS/AI_TRUCK
|
|
|
|
int new_cost;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
byte action;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2005-01-12 11:54:51 +00:00
|
|
|
int last_id; // here is stored the last id of the searched city/industry
|
2004-08-31 16:12:52 +00:00
|
|
|
uint last_vehiclecheck_date; // Used in CheckVehicle
|
|
|
|
Ai_SpecialVehicle special_vehicles[AI_MAX_SPECIAL_VEHICLES]; // Some vehicles have some special flags
|
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
TileIndex from_tile;
|
|
|
|
TileIndex to_tile;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
byte from_direction;
|
|
|
|
byte to_direction;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
bool from_deliver; // True if this is the station that GIVES cargo
|
|
|
|
bool to_deliver;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
TileIndex depot_tile;
|
|
|
|
byte depot_direction;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
byte amount_veh; // How many vehicles we are going to build in this route
|
|
|
|
byte cur_veh; // How many vehicles did we bought?
|
|
|
|
VehicleID veh_id; // Used when bought a vehicle
|
|
|
|
VehicleID veh_main_id; // The ID of the first vehicle, for shared copy
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
int from_ic; // ic = industry/city. This is the ID of them
|
|
|
|
byte from_type; // AI_NO_TYPE/AI_CITY/AI_INDUSTRY
|
|
|
|
int to_ic;
|
|
|
|
byte to_type;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-20 09:32:32 +00:00
|
|
|
} PlayerAiNew;
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
typedef struct Player {
|
|
|
|
uint32 name_2;
|
|
|
|
uint16 name_1;
|
|
|
|
|
|
|
|
uint16 president_name_1;
|
|
|
|
uint32 president_name_2;
|
|
|
|
|
|
|
|
uint32 face;
|
|
|
|
|
|
|
|
int32 player_money;
|
|
|
|
int32 current_loan;
|
|
|
|
int64 money64; // internal 64-bit version of the money. the 32-bit field will be clamped to plus minus 2 billion
|
|
|
|
|
|
|
|
byte player_color;
|
|
|
|
byte player_money_fraction;
|
2005-07-20 22:02:58 +00:00
|
|
|
byte avail_railtypes;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte block_preview;
|
2005-05-11 00:00:27 +00:00
|
|
|
PlayerID index;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
uint16 cargo_types; /* which cargo types were transported the last year */
|
|
|
|
|
|
|
|
TileIndex location_of_house;
|
|
|
|
TileIndex last_build_coordinate;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
byte share_owners[4];
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
byte inaugurated_year;
|
|
|
|
byte num_valid_stat_ent;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
byte quarters_of_bankrupcy;
|
|
|
|
byte bankrupt_asked; // which players were asked about buying it?
|
|
|
|
int16 bankrupt_timeout;
|
|
|
|
int32 bankrupt_value;
|
|
|
|
|
|
|
|
bool is_active;
|
|
|
|
byte is_ai;
|
|
|
|
PlayerAI ai;
|
2004-08-20 09:32:32 +00:00
|
|
|
PlayerAiNew ainew;
|
2004-08-31 16:12:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
int64 yearly_expenses[3][13];
|
|
|
|
PlayerEconomyEntry cur_economy;
|
|
|
|
PlayerEconomyEntry old_economy[24];
|
|
|
|
} Player;
|
|
|
|
|
|
|
|
void ChangeOwnershipOfPlayerItems(byte old_player, byte new_player);
|
2005-06-24 12:38:35 +00:00
|
|
|
void GetNameOfOwner(byte owner, TileIndex tile);
|
2004-09-11 09:40:19 +00:00
|
|
|
int64 CalculateCompanyValue(Player *p);
|
2004-08-09 17:04:08 +00:00
|
|
|
void InvalidatePlayerWindows(Player *p);
|
|
|
|
void AiDoGameLoop(Player *p);
|
|
|
|
void UpdatePlayerMoney32(Player *p);
|
|
|
|
#define FOR_ALL_PLAYERS(p) for(p=_players; p != endof(_players); p++)
|
|
|
|
|
2005-07-21 19:36:43 +00:00
|
|
|
extern PlayerID _current_player;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#define MAX_PLAYERS 8
|
|
|
|
VARDEF Player _players[MAX_PLAYERS];
|
2005-07-21 19:36:43 +00:00
|
|
|
// NOSAVE: can be determined from player structs
|
|
|
|
VARDEF byte _player_colors[MAX_PLAYERS];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-06 06:56:30 +00:00
|
|
|
static inline Player* GetPlayer(uint i)
|
|
|
|
{
|
|
|
|
assert(i < lengthof(_players));
|
|
|
|
return &_players[i];
|
|
|
|
}
|
|
|
|
|
2005-07-20 22:02:58 +00:00
|
|
|
/** Returns the number of rail types the player can build
|
|
|
|
* @param *p Player in question
|
|
|
|
*/
|
|
|
|
static inline int GetNumRailtypes(Player *p)
|
|
|
|
{
|
|
|
|
int num = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < (int)sizeof(p->avail_railtypes) * 8; i++)
|
|
|
|
if (HASBIT(p->avail_railtypes, i)) num++;
|
|
|
|
|
|
|
|
assert(num <= RAILTYPE_END);
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte GetPlayerRailtypes(int p);
|
|
|
|
|
|
|
|
/** Finds out if a Player has a certain railtype available
|
|
|
|
*/
|
|
|
|
static inline bool HasRailtypeAvail(Player *p, RailType Railtype)
|
|
|
|
{
|
|
|
|
return HASBIT(p->avail_railtypes, Railtype);
|
|
|
|
}
|
|
|
|
|
2005-07-21 19:36:43 +00:00
|
|
|
/* Validate functions for rail building */
|
|
|
|
static inline bool ValParamRailtype(uint32 rail) { return HASBIT(GetPlayer(_current_player)->avail_railtypes, rail);}
|
|
|
|
|
2005-07-20 22:02:58 +00:00
|
|
|
/** Returns the "best" railtype a player can build.
|
|
|
|
* As the AI doesn't know what the BEST one is, we
|
|
|
|
* have our own priority list here. When adding
|
|
|
|
* new railtypes, modify this function
|
|
|
|
* @param p the player "in action"
|
|
|
|
* @return The "best" railtype a player has available
|
|
|
|
*/
|
|
|
|
static inline byte GetBestRailtype(Player *p)
|
|
|
|
{
|
|
|
|
if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
|
|
|
|
if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
|
|
|
|
return RAILTYPE_RAIL;
|
|
|
|
}
|
|
|
|
|
2005-06-21 16:28:17 +00:00
|
|
|
#define IS_HUMAN_PLAYER(p) (!GetPlayer((byte)(p))->is_ai)
|
2004-08-09 17:04:08 +00:00
|
|
|
#define IS_INTERACTIVE_PLAYER(p) (((byte)p) == _local_player)
|
|
|
|
|
2005-01-11 00:54:06 +00:00
|
|
|
typedef struct HighScore {
|
|
|
|
char company[100];
|
|
|
|
StringID title;
|
|
|
|
uint16 score;
|
|
|
|
} HighScore;
|
|
|
|
|
2005-01-13 16:28:47 +00:00
|
|
|
VARDEF HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
|
2005-01-11 00:54:06 +00:00
|
|
|
void SaveToHighScore(void);
|
|
|
|
void LoadFromHighScore(void);
|
2005-01-13 16:28:47 +00:00
|
|
|
int8 SaveHighScoreValue(const Player *p);
|
|
|
|
int8 SaveHighScoreValueNetwork(void);
|
2005-01-11 00:54:06 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif /* PLAYER_H */
|