Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef COMPANY_BASE_H
00013 #define COMPANY_BASE_H
00014
00015 #include "road_type.h"
00016 #include "livery.h"
00017 #include "autoreplace_type.h"
00018 #include "tile_type.h"
00019 #include "settings_type.h"
00020 #include "group.h"
00021
00023 struct CompanyEconomyEntry {
00024 Money income;
00025 Money expenses;
00026 CargoArray delivered_cargo;
00027 int32 performance_history;
00028 Money company_value;
00029 };
00030
00031 struct CompanyInfrastructure {
00032 uint32 road[ROADTYPE_END];
00033 uint32 signal;
00034 uint32 rail[RAILTYPE_END];
00035 uint32 water;
00036 uint32 station;
00037 uint32 airport;
00038
00040 uint32 GetRailTotal() const
00041 {
00042 uint32 total = 0;
00043 for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) total += this->rail[rt];
00044 return total;
00045 }
00046 };
00047
00048 typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
00049 extern CompanyPool _company_pool;
00050
00051
00053 struct CompanyProperties {
00054 uint32 name_2;
00055 uint16 name_1;
00056 char *name;
00057
00058 uint16 president_name_1;
00059 uint32 president_name_2;
00060 char *president_name;
00061
00062 CompanyManagerFace face;
00063
00064 Money money;
00065 byte money_fraction;
00066 Money current_loan;
00067
00068 byte colour;
00069
00070 RailTypes avail_railtypes;
00071
00072 byte block_preview;
00073
00074 TileIndex location_of_HQ;
00075 TileIndex last_build_coordinate;
00076
00077 OwnerByte share_owners[4];
00078
00079 Year inaugurated_year;
00080
00081 byte quarters_of_bankruptcy;
00082 CompanyMask bankrupt_asked;
00083 int16 bankrupt_timeout;
00084 Money bankrupt_value;
00085
00086 uint32 terraform_limit;
00087 uint32 clear_limit;
00088 uint32 tree_limit;
00089
00094 bool is_ai;
00095
00096 Money yearly_expenses[3][EXPENSES_END];
00097 CompanyEconomyEntry cur_economy;
00098 CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS];
00099 byte num_valid_stat_ent;
00100
00101 CompanyProperties() : name(NULL), president_name(NULL) {}
00102
00103 ~CompanyProperties()
00104 {
00105 free(this->name);
00106 free(this->president_name);
00107 }
00108 };
00109
00110 struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
00111 Company(uint16 name_1 = 0, bool is_ai = false);
00112 ~Company();
00113
00114 Livery livery[LS_END];
00115 RoadTypes avail_roadtypes;
00116
00117 class AIInstance *ai_instance;
00118 class AIInfo *ai_info;
00119
00120 EngineRenewList engine_renew_list;
00121 CompanySettings settings;
00122 GroupStatistics group_all[VEH_COMPANY_END];
00123 GroupStatistics group_default[VEH_COMPANY_END];
00124
00125 CompanyInfrastructure infrastructure;
00126
00132 static inline bool IsValidAiID(size_t index)
00133 {
00134 const Company *c = Company::GetIfValid(index);
00135 return c != NULL && c->is_ai;
00136 }
00137
00144 static inline bool IsValidHumanID(size_t index)
00145 {
00146 const Company *c = Company::GetIfValid(index);
00147 return c != NULL && !c->is_ai;
00148 }
00149
00157 static inline bool IsHumanID(size_t index)
00158 {
00159 return !Company::Get(index)->is_ai;
00160 }
00161
00162 static void PostDestructor(size_t index);
00163 };
00164
00165 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
00166 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
00167
00168 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
00169
00170 extern uint _next_competitor_start;
00171 extern uint _cur_company_tick_index;
00172
00173 #endif