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 "core/pool_type.hpp"
00016 #include "road_type.h"
00017 #include "rail_type.h"
00018 #include "livery.h"
00019 #include "autoreplace_type.h"
00020 #include "economy_type.h"
00021 #include "tile_type.h"
00022 #include "settings_type.h"
00023 #include "command_type.h"
00024 #include "table/strings.h"
00025
00026 struct CompanyEconomyEntry {
00027 Money income;
00028 Money expenses;
00029 int32 delivered_cargo;
00030 int32 performance_history;
00031 Money company_value;
00032 };
00033
00034 typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
00035 extern CompanyPool _company_pool;
00036
00037
00039 struct CompanyProperties {
00040 uint32 name_2;
00041 uint16 name_1;
00042 char *name;
00043
00044 uint16 president_name_1;
00045 uint32 president_name_2;
00046 char *president_name;
00047
00048 CompanyManagerFace face;
00049
00050 Money money;
00051 byte money_fraction;
00052 Money current_loan;
00053
00054 byte colour;
00055
00056 RailTypes avail_railtypes;
00057
00058 byte block_preview;
00059
00060 uint32 cargo_types;
00061
00062 TileIndex location_of_HQ;
00063 TileIndex last_build_coordinate;
00064
00065 OwnerByte share_owners[4];
00066
00067 Year inaugurated_year;
00068
00069 byte quarters_of_bankruptcy;
00070 CompanyMask bankrupt_asked;
00071 int16 bankrupt_timeout;
00072 Money bankrupt_value;
00073
00074 uint32 terraform_limit;
00075 uint32 clear_limit;
00076
00081 bool is_ai;
00082
00083 Money yearly_expenses[3][EXPENSES_END];
00084 CompanyEconomyEntry cur_economy;
00085 CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS];
00086 byte num_valid_stat_ent;
00087
00088 CompanyProperties() : name(NULL), president_name(NULL) {}
00089
00090 ~CompanyProperties()
00091 {
00092 free(this->name);
00093 free(this->president_name);
00094 }
00095 };
00096
00097 struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
00098 Company(uint16 name_1 = 0, bool is_ai = false);
00099 ~Company();
00100
00101 Livery livery[LS_END];
00102 RoadTypes avail_roadtypes;
00103
00104 class AIInstance *ai_instance;
00105 class AIInfo *ai_info;
00106
00107 EngineRenewList engine_renew_list;
00108 CompanySettings settings;
00109 uint16 *num_engines;
00110
00111 uint32 road_infrastructure[ROADTYPE_END];
00112 uint32 signal_infrastructure;
00113 uint32 rail_infrastructure[RAILTYPE_END];
00114 uint32 water_infrastructure;
00115 uint32 station_infrastructure;
00116 uint32 airport_infrastructure;
00117
00123 static FORCEINLINE bool IsValidAiID(size_t index)
00124 {
00125 const Company *c = Company::GetIfValid(index);
00126 return c != NULL && c->is_ai;
00127 }
00128
00135 static FORCEINLINE bool IsValidHumanID(size_t index)
00136 {
00137 const Company *c = Company::GetIfValid(index);
00138 return c != NULL && !c->is_ai;
00139 }
00140
00148 static FORCEINLINE bool IsHumanID(size_t index)
00149 {
00150 return !Company::Get(index)->is_ai;
00151 }
00152
00153 static void PostDestructor(size_t index);
00154 };
00155
00156 struct CompanyProfile {
00157 char president_name[MAX_LENGTH_PRESIDENT_NAME_CHARS];
00158 char company_name[MAX_LENGTH_COMPANY_NAME_CHARS];
00159 CompanyManagerFace face;
00160 Livery livery[LS_END];
00161
00162 StringID error_id;
00163
00164 CompanyProfile()
00165 {
00166 this->error_id = STR_NULL;
00167 }
00168
00169 CompanyProfile(StringID err)
00170 {
00171 this->error_id = err;
00172 }
00173 };
00174
00175 CompanyProfile GetCompanyProfile (const Company&);
00176 StringID SetCompanyProfile (const CompanyProfile&);
00177 StringID CompanyLoadProfile(CompanyProfile&);
00178 StringID CompanySaveProfile(const CompanyProfile&);
00179
00180 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
00181 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
00182
00183 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
00184
00185 extern uint _next_competitor_start;
00186 extern uint _cur_company_tick_index;
00187
00188 #endif