src/player.h
branchcpp_gui
changeset 6303 84c215fc8eb8
parent 6298 c30fe89622df
child 9911 0b8b245a2391
equal deleted inserted replaced
6302:bd80897189ba 6303:84c215fc8eb8
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file player.h */
     2 
     4 
     3 #ifndef PLAYER_H
     5 #ifndef PLAYER_H
     4 #define PLAYER_H
     6 #define PLAYER_H
     5 
     7 
     6 #include "oldpool.h"
     8 #include "oldpool.h"
    11 
    13 
    12 struct PlayerEconomyEntry {
    14 struct PlayerEconomyEntry {
    13 	int32 income;
    15 	int32 income;
    14 	int32 expenses;
    16 	int32 expenses;
    15 	int32 delivered_cargo;
    17 	int32 delivered_cargo;
    16 	int32 performance_history; // player score (scale 0-1000)
    18 	int32 performance_history; ///< player score (scale 0-1000)
    17 	int64 company_value;
    19 	int64 company_value;
    18 };
    20 };
    19 
    21 
    20 struct AiBuildRec {
    22 struct AiBuildRec {
    21 	TileIndex spec_tile;
    23 	TileIndex spec_tile;
    30 	CargoID cargo;
    32 	CargoID cargo;
    31 };
    33 };
    32 
    34 
    33 struct PlayerAI {
    35 struct PlayerAI {
    34 	byte state;
    36 	byte state;
    35 	byte tick;            // Used to determine how often to move
    37 	byte tick;            ///< Used to determine how often to move
    36 	uint32 state_counter; // Can hold tile index!
    38 	uint32 state_counter; ///< Can hold tile index!
    37 	uint16 timeout_counter;
    39 	uint16 timeout_counter;
    38 
    40 
    39 	byte state_mode;
    41 	byte state_mode;
    40 	byte banned_tile_count;
    42 	byte banned_tile_count;
    41 	RailTypeByte railtype_to_use;
    43 	RailTypeByte railtype_to_use;
    57 	TileIndex start_tile_b;
    59 	TileIndex start_tile_b;
    58 	TileIndex cur_tile_b;
    60 	TileIndex cur_tile_b;
    59 	byte cur_dir_b;
    61 	byte cur_dir_b;
    60 	byte start_dir_b;
    62 	byte start_dir_b;
    61 
    63 
    62 	Vehicle *cur_veh; /* only used by some states */
    64 	Vehicle *cur_veh; ///< only used by some states
    63 
    65 
    64 	AiBuildRec src, dst, mid1, mid2;
    66 	AiBuildRec src, dst, mid1, mid2;
    65 
    67 
    66 	VehicleID wagon_list[9];
    68 	VehicleID wagon_list[9];
    67 	byte order_list_blocks[20];
    69 	byte order_list_blocks[20];
    69 	TileIndex banned_tiles[16];
    71 	TileIndex banned_tiles[16];
    70 	byte banned_val[16];
    72 	byte banned_val[16];
    71 };
    73 };
    72 
    74 
    73 struct Ai_PathFinderInfo {
    75 struct Ai_PathFinderInfo {
    74 	TileIndex start_tile_tl; // tl = top-left
    76 	TileIndex start_tile_tl; ///< tl = top-left
    75 	TileIndex start_tile_br; // br = bottom-right
    77 	TileIndex start_tile_br; ///< br = bottom-right
    76 	TileIndex end_tile_tl;   // tl = top-left
    78 	TileIndex end_tile_tl;   ///< tl = top-left
    77 	TileIndex end_tile_br;   // br = bottom-right
    79 	TileIndex end_tile_br;   ///< br = bottom-right
    78 	byte start_direction;    // 0 to 3 or AI_PATHFINDER_NO_DIRECTION
    80 	byte start_direction;    ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
    79 	byte end_direction;      // 0 to 3 or AI_PATHFINDER_NO_DIRECTION
    81 	byte end_direction;      ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
    80 
    82 
    81 	TileIndex route[500];
    83 	TileIndex route[500];
    82 	byte route_extra[500];   // Some extra information about the route like bridge/tunnel
    84 	byte route_extra[500];   ///< Some extra information about the route like bridge/tunnel
    83 	int route_length;
    85 	int route_length;
    84 	int position;            // Current position in the build-path, needed to build the path
    86 	int position;            ///< Current position in the build-path, needed to build the path
    85 
    87 
    86 	bool rail_or_road;       // true = rail, false = road
    88 	bool rail_or_road;       ///< true = rail, false = road
    87 };
    89 };
    88 
    90 
    89 // The amount of memory reserved for the AI-special-vehicles
    91 /* The amount of memory reserved for the AI-special-vehicles */
    90 #define AI_MAX_SPECIAL_VEHICLES 100
    92 #define AI_MAX_SPECIAL_VEHICLES 100
    91 
    93 
    92 struct Ai_SpecialVehicle {
    94 struct Ai_SpecialVehicle {
    93 	VehicleID veh_id;
    95 	VehicleID veh_id;
    94 	uint32 flag;
    96 	uint32 flag;
    97 struct PlayerAiNew {
    99 struct PlayerAiNew {
    98 	uint8 state;
   100 	uint8 state;
    99 	uint tick;
   101 	uint tick;
   100 	uint idle;
   102 	uint idle;
   101 
   103 
   102 	int temp;    // A value used in more than one function, but it just temporary
   104 	int temp;    ///< A value used in more than one function, but it just temporary
   103 	             // The use is pretty simple: with this we can 'think' about stuff
   105 	             ///< The use is pretty simple: with this we can 'think' about stuff
   104 	             //   in more than one tick, and more than one AI. A static will not
   106 	             ///<   in more than one tick, and more than one AI. A static will not
   105 	             //   do, because they are not saved. This way, the AI is almost human ;)
   107 	             ///<   do, because they are not saved. This way, the AI is almost human ;)
   106 	int counter; // For the same reason as temp, we have counter. It can count how
   108 	int counter; ///< For the same reason as temp, we have counter. It can count how
   107 	             //  long we are trying something, and just abort if it takes too long
   109 	             ///<  long we are trying something, and just abort if it takes too long
   108 
   110 
   109 	// Pathfinder stuff
   111 	/* Pathfinder stuff */
   110 	Ai_PathFinderInfo path_info;
   112 	Ai_PathFinderInfo path_info;
   111 	AyStar *pathfinder;
   113 	AyStar *pathfinder;
   112 
   114 
   113 	// Route stuff
   115 	/* Route stuff */
   114 
   116 
   115 	CargoID cargo;
   117 	CargoID cargo;
   116 	byte tbt; // train/bus/truck 0/1/2 AI_TRAIN/AI_BUS/AI_TRUCK
   118 	byte tbt;    ///< train/bus/truck 0/1/2 AI_TRAIN/AI_BUS/AI_TRUCK
   117 	int new_cost;
   119 	int new_cost;
   118 
   120 
   119 	byte action;
   121 	byte action;
   120 
   122 
   121 	int last_id; // here is stored the last id of the searched city/industry
   123 	int last_id; ///< here is stored the last id of the searched city/industry
   122 	Date last_vehiclecheck_date; // Used in CheckVehicle
   124 	Date last_vehiclecheck_date; // Used in CheckVehicle
   123 	Ai_SpecialVehicle special_vehicles[AI_MAX_SPECIAL_VEHICLES]; // Some vehicles have some special flags
   125 	Ai_SpecialVehicle special_vehicles[AI_MAX_SPECIAL_VEHICLES]; ///< Some vehicles have some special flags
   124 
   126 
   125 	TileIndex from_tile;
   127 	TileIndex from_tile;
   126 	TileIndex to_tile;
   128 	TileIndex to_tile;
   127 
   129 
   128 	byte from_direction;
   130 	byte from_direction;
   129 	byte to_direction;
   131 	byte to_direction;
   130 
   132 
   131 	bool from_deliver; // True if this is the station that GIVES cargo
   133 	bool from_deliver; ///< True if this is the station that GIVES cargo
   132 	bool to_deliver;
   134 	bool to_deliver;
   133 
   135 
   134 	TileIndex depot_tile;
   136 	TileIndex depot_tile;
   135 	DiagDirectionByte depot_direction;
   137 	DiagDirectionByte depot_direction;
   136 
   138 
   137 	byte amount_veh;       // How many vehicles we are going to build in this route
   139 	byte amount_veh;       ///< How many vehicles we are going to build in this route
   138 	byte cur_veh;          // How many vehicles did we bought?
   140 	byte cur_veh;          ///< How many vehicles did we bought?
   139 	VehicleID veh_id;      // Used when bought a vehicle
   141 	VehicleID veh_id;      ///< Used when bought a vehicle
   140 	VehicleID veh_main_id; // The ID of the first vehicle, for shared copy
   142 	VehicleID veh_main_id; ///< The ID of the first vehicle, for shared copy
   141 
   143 
   142 	int from_ic;           // ic = industry/city. This is the ID of them
   144 	int from_ic;           ///< ic = industry/city. This is the ID of them
   143 	byte from_type;        // AI_NO_TYPE/AI_CITY/AI_INDUSTRY
   145 	byte from_type;        ///< AI_NO_TYPE/AI_CITY/AI_INDUSTRY
   144 	int to_ic;
   146 	int to_ic;
   145 	byte to_type;
   147 	byte to_type;
   146 
   148 
   147 };
   149 };
   148 
   150 
   158 
   160 
   159 	PlayerFace face;
   161 	PlayerFace face;
   160 
   162 
   161 	int32 player_money;
   163 	int32 player_money;
   162 	int32 current_loan;
   164 	int32 current_loan;
   163 	int64 money64; // internal 64-bit version of the money. the 32-bit field will be clamped to plus minus 2 billion
   165 	int64 money64; ///< internal 64-bit version of the money. the 32-bit field will be clamped to plus minus 2 billion
   164 
   166 
   165 	byte player_color;
   167 	byte player_color;
   166 	Livery livery[LS_END];
   168 	Livery livery[LS_END];
   167 	byte player_money_fraction;
   169 	byte player_money_fraction;
   168 	byte avail_railtypes;
   170 	byte avail_railtypes;
   169 	byte block_preview;
   171 	byte block_preview;
   170 	PlayerByte index;
   172 	PlayerByte index;
   171 
   173 
   172 	uint16 cargo_types; /* which cargo types were transported the last year */
   174 	uint16 cargo_types; ///< which cargo types were transported the last year
   173 
   175 
   174 	TileIndex location_of_house;
   176 	TileIndex location_of_house;
   175 	TileIndex last_build_coordinate;
   177 	TileIndex last_build_coordinate;
   176 
   178 
   177 	PlayerByte share_owners[4];
   179 	PlayerByte share_owners[4];
   178 
   180 
   179 	Year inaugurated_year;
   181 	Year inaugurated_year;
   180 	byte num_valid_stat_ent;
   182 	byte num_valid_stat_ent;
   181 
   183 
   182 	byte quarters_of_bankrupcy;
   184 	byte quarters_of_bankrupcy;
   183 	byte bankrupt_asked; // which players were asked about buying it?
   185 	byte bankrupt_asked; ///< which players were asked about buying it?
   184 	int16 bankrupt_timeout;
   186 	int16 bankrupt_timeout;
   185 	int32 bankrupt_value;
   187 	int32 bankrupt_value;
   186 
   188 
   187 	bool is_active;
   189 	bool is_active;
   188 	bool is_ai;
   190 	bool is_ai;
   190 	PlayerAiNew ainew;
   192 	PlayerAiNew ainew;
   191 
   193 
   192 	int64 yearly_expenses[3][13];
   194 	int64 yearly_expenses[3][13];
   193 	PlayerEconomyEntry cur_economy;
   195 	PlayerEconomyEntry cur_economy;
   194 	PlayerEconomyEntry old_economy[24];
   196 	PlayerEconomyEntry old_economy[24];
   195 	EngineRenewList engine_renew_list; // Defined later
   197 	EngineRenewList engine_renew_list; ///< Defined later
   196 	bool engine_renew;
   198 	bool engine_renew;
   197 	bool renew_keep_length;
   199 	bool renew_keep_length;
   198 	int16 engine_renew_months;
   200 	int16 engine_renew_months;
   199 	uint32 engine_renew_money;
   201 	uint32 engine_renew_money;
   200 	uint16 num_engines[TOTAL_NUM_ENGINES]; // caches the number of engines of each type the player owns (no need to save this)
   202 	uint16 num_engines[TOTAL_NUM_ENGINES]; ///< caches the number of engines of each type the player owns (no need to save this)
   201 };
   203 };
   202 
   204 
   203 uint16 GetDrawStringPlayerColor(PlayerID player);
   205 uint16 GetDrawStringPlayerColor(PlayerID player);
   204 
   206 
   205 void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player);
   207 void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player);
   212 
   214 
   213 VARDEF PlayerID _local_player;
   215 VARDEF PlayerID _local_player;
   214 VARDEF PlayerID _current_player;
   216 VARDEF PlayerID _current_player;
   215 
   217 
   216 VARDEF Player _players[MAX_PLAYERS];
   218 VARDEF Player _players[MAX_PLAYERS];
   217 // NOSAVE: can be determined from player structs
   219 /* NOSAVE: can be determined from player structs */
   218 VARDEF byte _player_colors[MAX_PLAYERS];
   220 VARDEF byte _player_colors[MAX_PLAYERS];
   219 
   221 
   220 static inline byte ActivePlayerCount()
   222 static inline byte ActivePlayerCount()
   221 {
   223 {
   222 	const Player *p;
   224 	const Player *p;
   282 	return RAILTYPE_RAIL;
   284 	return RAILTYPE_RAIL;
   283 }
   285 }
   284 
   286 
   285 struct HighScore {
   287 struct HighScore {
   286 	char company[100];
   288 	char company[100];
   287 	StringID title; // NO_SAVE, has troubles with changing string-numbers.
   289 	StringID title; ///< NO_SAVE, has troubles with changing string-numbers.
   288 	uint16 score;   // do NOT change type, will break hs.dat
   290 	uint16 score;   ///< do NOT change type, will break hs.dat
   289 };
   291 };
   290 
   292 
   291 VARDEF HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
   293 VARDEF HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
   292 void SaveToHighScore();
   294 void SaveToHighScore();
   293 void LoadFromHighScore();
   295 void LoadFromHighScore();