company_base.h
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
00024 struct CompanyEconomyEntry {
00025 Money income;
00026 Money expenses;
00027 int32 delivered_cargo;
00028 int32 performance_history;
00029 Money company_value;
00030 };
00031
00032 typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
00033 extern CompanyPool _company_pool;
00034
00035
00037 struct CompanyProperties {
00038 uint32 name_2;
00039 uint16 name_1;
00040 char *name;
00041
00042 uint16 president_name_1;
00043 uint32 president_name_2;
00044 char *president_name;
00045
00046 CompanyManagerFace face;
00047
00048 Money money;
00049 byte money_fraction;
00050 Money current_loan;
00051
00052 byte colour;
00053
00054 RailTypes avail_railtypes;
00055
00056 byte block_preview;
00057
00058 uint32 cargo_types;
00059
00060 TileIndex location_of_HQ;
00061 TileIndex last_build_coordinate;
00062
00063 OwnerByte share_owners[4];
00064
00065 Year inaugurated_year;
00066
00067 byte quarters_of_bankruptcy;
00068 CompanyMask bankrupt_asked;
00069 int16 bankrupt_timeout;
00070 Money bankrupt_value;
00071
00076 bool is_ai;
00077
00078 Money yearly_expenses[3][EXPENSES_END];
00079 CompanyEconomyEntry cur_economy;
00080 CompanyEconomyEntry old_economy[MAX_HISTORY_MONTHS];
00081 byte num_valid_stat_ent;
00082
00083 CompanyProperties() : name(NULL), president_name(NULL) {}
00084
00085 ~CompanyProperties()
00086 {
00087 free(this->name);
00088 free(this->president_name);
00089 }
00090 };
00091
00092 struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
00093 Company(uint16 name_1 = 0, bool is_ai = false);
00094 ~Company();
00095
00096 Livery livery[LS_END];
00097 RoadTypes avail_roadtypes;
00098
00099 class AIInstance *ai_instance;
00100 class AIInfo *ai_info;
00101
00102 EngineRenewList engine_renew_list;
00103 CompanySettings settings;
00104 uint16 *num_engines;
00105
00111 static FORCEINLINE bool IsValidAiID(size_t index)
00112 {
00113 const Company *c = Company::GetIfValid(index);
00114 return c != NULL && c->is_ai;
00115 }
00116
00123 static FORCEINLINE bool IsValidHumanID(size_t index)
00124 {
00125 const Company *c = Company::GetIfValid(index);
00126 return c != NULL && !c->is_ai;
00127 }
00128
00136 static FORCEINLINE bool IsHumanID(size_t index)
00137 {
00138 return !Company::Get(index)->is_ai;
00139 }
00140
00141 static void PostDestructor(size_t index);
00142 };
00143
00144 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
00145 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
00146
00147 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
00148
00149 extern uint _next_competitor_start;
00150 extern uint _cur_company_tick_index;
00151
00152 #endif