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
00022 struct CompanyEconomyEntry {
00023 Money income;
00024 Money expenses;
00025 int32 delivered_cargo;
00026 int32 performance_history;
00027 Money company_value;
00028 };
00029
00030 struct CompanyInfrastructure {
00031 uint32 road[ROADTYPE_END];
00032 uint32 signal;
00033 uint32 rail[RAILTYPE_END];
00034 uint32 water;
00035 uint32 station;
00036 uint32 airport;
00037 };
00038
00039 typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
00040 extern CompanyPool _company_pool;
00041
00042
00044 struct CompanyProperties {
00045 uint32 name_2;
00046 uint16 name_1;
00047 char *name;
00048
00049 uint16 president_name_1;
00050 uint32 president_name_2;
00051 char *president_name;
00052
00053 CompanyManagerFace face;
00054
00055 Money money;
00056 byte money_fraction;
00057 Money current_loan;
00058
00059 byte colour;
00060
00061 RailTypes avail_railtypes;
00062
00063 byte block_preview;
00064
00065 uint32 cargo_types;
00066
00067 TileIndex location_of_HQ;
00068 TileIndex last_build_coordinate;
00069
00070 OwnerByte share_owners[4];
00071
00072 Year inaugurated_year;
00073
00074 byte quarters_of_bankruptcy;
00075 CompanyMask bankrupt_asked;
00076 int16 bankrupt_timeout;
00077 Money bankrupt_value;
00078
00079 uint32 terraform_limit;
00080 uint32 clear_limit;
00081
00086 bool is_ai;
00087
00088 Money yearly_expenses[3][EXPENSES_END];
00089 CompanyEconomyEntry cur_economy;
00090 CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS];
00091 byte num_valid_stat_ent;
00092
00093 CompanyProperties() : name(NULL), president_name(NULL) {}
00094
00095 ~CompanyProperties()
00096 {
00097 free(this->name);
00098 free(this->president_name);
00099 }
00100 };
00101
00102 struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
00103 Company(uint16 name_1 = 0, bool is_ai = false);
00104 ~Company();
00105
00106 Livery livery[LS_END];
00107 RoadTypes avail_roadtypes;
00108
00109 class AIInstance *ai_instance;
00110 class AIInfo *ai_info;
00111
00112 EngineRenewList engine_renew_list;
00113 CompanySettings settings;
00114 GroupStatistics group_all[VEH_COMPANY_END];
00115 GroupStatistics group_default[VEH_COMPANY_END];
00116
00117 CompanyInfrastructure infrastructure;
00118
00124 static inline bool IsValidAiID(size_t index)
00125 {
00126 const Company *c = Company::GetIfValid(index);
00127 return c != NULL && c->is_ai;
00128 }
00129
00136 static inline bool IsValidHumanID(size_t index)
00137 {
00138 const Company *c = Company::GetIfValid(index);
00139 return c != NULL && !c->is_ai;
00140 }
00141
00149 static inline bool IsHumanID(size_t index)
00150 {
00151 return !Company::Get(index)->is_ai;
00152 }
00153
00154 static void PostDestructor(size_t index);
00155 };
00156
00157 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
00158 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
00159
00160 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
00161
00162 extern uint _next_competitor_start;
00163 extern uint _cur_company_tick_index;
00164
00165 #endif