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
00093 bool is_ai;
00094
00095 Money yearly_expenses[3][EXPENSES_END];
00096 CompanyEconomyEntry cur_economy;
00097 CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS];
00098 byte num_valid_stat_ent;
00099
00100 CompanyProperties() : name(NULL), president_name(NULL) {}
00101
00102 ~CompanyProperties()
00103 {
00104 free(this->name);
00105 free(this->president_name);
00106 }
00107 };
00108
00109 struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
00110 Company(uint16 name_1 = 0, bool is_ai = false);
00111 ~Company();
00112
00113 Livery livery[LS_END];
00114 RoadTypes avail_roadtypes;
00115
00116 class AIInstance *ai_instance;
00117 class AIInfo *ai_info;
00118
00119 EngineRenewList engine_renew_list;
00120 CompanySettings settings;
00121 GroupStatistics group_all[VEH_COMPANY_END];
00122 GroupStatistics group_default[VEH_COMPANY_END];
00123
00124 CompanyInfrastructure infrastructure;
00125
00131 static inline bool IsValidAiID(size_t index)
00132 {
00133 const Company *c = Company::GetIfValid(index);
00134 return c != NULL && c->is_ai;
00135 }
00136
00143 static inline bool IsValidHumanID(size_t index)
00144 {
00145 const Company *c = Company::GetIfValid(index);
00146 return c != NULL && !c->is_ai;
00147 }
00148
00156 static inline bool IsHumanID(size_t index)
00157 {
00158 return !Company::Get(index)->is_ai;
00159 }
00160
00161 static void PostDestructor(size_t index);
00162 };
00163
00164 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
00165 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
00166
00167 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
00168
00169 extern uint _next_competitor_start;
00170 extern uint _cur_company_tick_index;
00171
00172 #endif