src/company_base.h
changeset 10208 72c00af5c95d
parent 10207 c291a21b304e
equal deleted inserted replaced
10207:c291a21b304e 10208:72c00af5c95d
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file company_base.h Definition of stuff that is very close to a company, like the company struct itself. */
       
     4 
       
     5 #ifndef COMPANY_BASE_H
       
     6 #define COMPANY_BASE_H
       
     7 
       
     8 #include "company_type.h"
       
     9 #include "oldpool.h"
       
    10 #include "road_type.h"
       
    11 #include "rail_type.h"
       
    12 #include "date_type.h"
       
    13 #include "engine_type.h"
       
    14 #include "livery.h"
       
    15 #include "autoreplace_type.h"
       
    16 #include "economy_type.h"
       
    17 #include "tile_type.h"
       
    18 
       
    19 struct CompanyEconomyEntry {
       
    20 	Money income;
       
    21 	Money expenses;
       
    22 	int32 delivered_cargo;
       
    23 	int32 performance_history; ///< company score (scale 0-1000)
       
    24 	Money company_value;
       
    25 };
       
    26 
       
    27 /* The third parameter and the number after >> MUST be the same,
       
    28  * otherwise more (or less) companies will be allowed to be
       
    29  * created than what MAX_COMPANIES specifies!
       
    30  */
       
    31 DECLARE_OLD_POOL(Company, Company, 1, MAX_COMPANIES >> 1)
       
    32 
       
    33 struct Company : PoolItem<Company, CompanyByte, &_Company_pool> {
       
    34 	Company(uint16 name_1 = 0, bool is_ai = false);
       
    35 	~Company();
       
    36 
       
    37 	uint32 name_2;
       
    38 	uint16 name_1;
       
    39 	char *name;
       
    40 
       
    41 	uint16 president_name_1;
       
    42 	uint32 president_name_2;
       
    43 	char *president_name;
       
    44 
       
    45 	CompanyManagerFace face;
       
    46 
       
    47 	Money money;
       
    48 	byte money_fraction;
       
    49 	Money current_loan;
       
    50 
       
    51 	byte colour;
       
    52 	Livery livery[LS_END];
       
    53 	RailTypes avail_railtypes;
       
    54 	RoadTypes avail_roadtypes;
       
    55 	byte block_preview;
       
    56 
       
    57 	uint32 cargo_types; ///< which cargo types were transported the last year
       
    58 
       
    59 	TileIndex location_of_HQ;
       
    60 	TileIndex last_build_coordinate;
       
    61 
       
    62 	OwnerByte share_owners[4];
       
    63 
       
    64 	Year inaugurated_year;
       
    65 	byte num_valid_stat_ent;
       
    66 
       
    67 	byte quarters_of_bankrupcy;
       
    68 	byte bankrupt_asked; ///< which companies were asked about buying it?
       
    69 	int16 bankrupt_timeout;
       
    70 	Money bankrupt_value;
       
    71 
       
    72 	bool is_ai;
       
    73 
       
    74 	Money yearly_expenses[3][EXPENSES_END];
       
    75 	CompanyEconomyEntry cur_economy;
       
    76 	CompanyEconomyEntry old_economy[24];
       
    77 	EngineRenewList engine_renew_list; ///< Defined later
       
    78 	bool engine_renew;
       
    79 	bool renew_keep_length;
       
    80 	int16 engine_renew_months;
       
    81 	uint32 engine_renew_money;
       
    82 	uint16 *num_engines; ///< caches the number of engines of each type the company owns (no need to save this)
       
    83 
       
    84 	inline bool IsValid() const { return this->name_1 != 0; }
       
    85 };
       
    86 
       
    87 static inline bool IsValidCompanyID(CompanyID company)
       
    88 {
       
    89 	return (uint)company < GetCompanyPoolSize() && GetCompany(company)->IsValid();
       
    90 }
       
    91 
       
    92 #define FOR_ALL_COMPANIES_FROM(d, start) for (d = GetCompany(start); d != NULL; d = (d->index + 1U < GetCompanyPoolSize()) ? GetCompany(d->index + 1U) : NULL) if (d->IsValid())
       
    93 #define FOR_ALL_COMPANIES(d) FOR_ALL_COMPANIES_FROM(d, 0)
       
    94 
       
    95 static inline byte ActiveCompanyCount()
       
    96 {
       
    97 	const Company *c;
       
    98 	byte count = 0;
       
    99 
       
   100 	FOR_ALL_COMPANIES(c) count++;
       
   101 
       
   102 	return count;
       
   103 }
       
   104 
       
   105 Money CalculateCompanyValue(const Company *c);
       
   106 
       
   107 #endif /* COMPANY_BASE_H */