OpenTTD Source  13.2.1
company_base.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef COMPANY_BASE_H
11 #define COMPANY_BASE_H
12 
13 #include "road_type.h"
14 #include "livery.h"
15 #include "autoreplace_type.h"
16 #include "tile_type.h"
17 #include "settings_type.h"
18 #include "group.h"
19 #include <string>
20 #include <array>
21 
29 };
30 
32  uint32 road[ROADTYPE_END];
33  uint32 signal;
34  uint32 rail[RAILTYPE_END];
35  uint32 water;
36  uint32 station;
37  uint32 airport;
38 
40  uint32 GetRailTotal() const
41  {
42  uint32 total = 0;
43  for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) total += this->rail[rt];
44  return total;
45  }
46 
47  uint32 GetRoadTotal() const;
48  uint32 GetTramTotal() const;
49 };
50 
53 
54 
57  uint32 name_2;
59  std::string name;
60 
63  std::string president_name;
64 
66 
70 
71  byte colour;
72 
74 
77 
78  std::array<Owner, MAX_COMPANY_SHARE_OWNERS> share_owners;
79 
81 
83  CompanyMask bankrupt_asked;
85  Money bankrupt_value;
86 
87  uint32 terraform_limit;
88  uint32 clear_limit;
89  uint32 tree_limit;
91 
96  bool is_ai;
97 
102 
103  Livery livery[LS_END];
104 
107 
108  // TODO: Change some of these member variables to use relevant INVALID_xxx constants
111  face(0), money(0), money_fraction(0), current_loan(0), colour(0), block_preview(0),
113  months_of_bankruptcy(0), bankrupt_asked(0), bankrupt_timeout(0), bankrupt_value(0),
115 };
116 
118  Company(uint16 name_1 = 0, bool is_ai = false);
119  ~Company();
120 
123 
124  class AIInstance *ai_instance;
125  class AIInfo *ai_info;
126 
129 
131 
137  static inline bool IsValidAiID(size_t index)
138  {
139  const Company *c = Company::GetIfValid(index);
140  return c != nullptr && c->is_ai;
141  }
142 
149  static inline bool IsValidHumanID(size_t index)
150  {
151  const Company *c = Company::GetIfValid(index);
152  return c != nullptr && !c->is_ai;
153  }
154 
162  static inline bool IsHumanID(size_t index)
163  {
164  return !Company::Get(index)->is_ai;
165  }
166 
167  static void PostDestructor(size_t index);
168 };
169 
170 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
171 Money CalculateCompanyValueExcludingShares(const Company *c, bool including_loan = true);
172 
173 extern uint _next_competitor_start;
174 extern uint _cur_company_tick_index;
175 
176 #endif /* COMPANY_BASE_H */
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:96
_company_pool
CompanyPool _company_pool
Pool of companies.
CompanyEconomyEntry::company_value
Money company_value
The value of the company.
Definition: company_base.h:28
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:26
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
EXPENSES_END
@ EXPENSES_END
Number of expense types.
Definition: economy_type.h:171
Company::group_all
GroupStatistics group_all[VEH_COMPANY_END]
NOSAVE: Statistics for the ALL_GROUP group.
Definition: company_base.h:127
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
Company::avail_railtypes
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:121
CompanyManagerFace
uint32 CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition: company_type.h:52
Company::avail_roadtypes
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:122
CompanyProperties::inaugurated_year
Year inaugurated_year
Year of starting the company.
Definition: company_base.h:80
CompanyProperties::tree_limit
uint32 tree_limit
Amount of trees we can (still) plant (times 65536).
Definition: company_base.h:89
CompanyInfrastructure::water
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:35
Pool::PoolItem<&_company_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
CompanyProperties::money_fraction
byte money_fraction
Fraction of money of the company, too small to represent in money.
Definition: company_base.h:68
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
CompanyInfrastructure
Definition: company_base.h:31
Company::PostDestructor
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
Definition: company_cmd.cpp:87
CompanyInfrastructure::station
uint32 station
Count of company owned station tiles.
Definition: company_base.h:36
group.h
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
CompanyProperties::name
std::string name
Name of the company if the user changed it.
Definition: company_base.h:59
Company::IsValidHumanID
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:149
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:130
CompanyProperties::last_build_coordinate
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition: company_base.h:76
CompanyProperties::face
CompanyManagerFace face
Face description of the president.
Definition: company_base.h:65
CompanyProperties::block_preview
byte block_preview
Number of quarters that the company is not allowed to get new exclusive engine previews (see Companie...
Definition: company_base.h:73
CalculateCompanyValue
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition: economy.cpp:115
CompanyProperties::current_loan
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:69
CompanyEconomyEntry
Statistics about the economy.
Definition: company_base.h:23
CompanyProperties::build_object_limit
uint32 build_object_limit
Amount of tiles we can (still) build objects on (times 65536). Also applies to buying land.
Definition: company_base.h:90
CompanyInfrastructure::GetRoadTotal
uint32 GetRoadTotal() const
Get total sum of all owned road bits.
Definition: company_cmd.cpp:1153
CompanyProperties::name_2
uint32 name_2
Parameter of name_1.
Definition: company_base.h:57
CompanyProperties::clear_limit
uint32 clear_limit
Amount of tiles we can (still) clear (times 65536).
Definition: company_base.h:88
GroupStatistics
Statistics and caches on the vehicles in a group.
Definition: group.h:25
CompanyInfrastructure::GetTramTotal
uint32 GetTramTotal() const
Get total sum of all owned tram bits.
Definition: company_cmd.cpp:1166
Company::Company
Company(uint16 name_1=0, bool is_ai=false)
Constructor.
Definition: company_cmd.cpp:61
CompanyProperties::colour
byte colour
Company colour.
Definition: company_base.h:71
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
CompanyEconomyEntry::performance_history
int32 performance_history
Company score (scale 0-1000)
Definition: company_base.h:27
CompanyProperties::terraform_limit
uint32 terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
Definition: company_base.h:87
CompanyProperties::num_valid_stat_ent
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:101
VEH_COMPANY_END
@ VEH_COMPANY_END
Last company-ownable type.
Definition: vehicle_type.h:29
Company::group_default
GroupStatistics group_default[VEH_COMPANY_END]
NOSAVE: Statistics for the DEFAULT_GROUP group.
Definition: company_base.h:128
CompanyProperties::months_of_bankruptcy
byte months_of_bankruptcy
Number of months that the company is unable to pay its debts.
Definition: company_base.h:82
CompanyProperties::money
Money money
Money owned by the company.
Definition: company_base.h:67
RoadTypes
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:106
Company::IsValidAiID
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition: company_base.h:137
CompanyProperties::location_of_HQ
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
Definition: company_base.h:75
settings_type.h
CompanyProperties::president_name
std::string president_name
Name of the president if the user changed it.
Definition: company_base.h:63
MAX_HISTORY_QUARTERS
static const uint MAX_HISTORY_QUARTERS
The maximum number of quarters kept as performance's history.
Definition: company_type.h:42
CompanyInfrastructure::road
uint32 road[ROADTYPE_END]
Count of company owned track bits for each road type.
Definition: company_base.h:32
CompanyInfrastructure::signal
uint32 signal
Count of company owned signals.
Definition: company_base.h:33
CompanyProperties::yearly_expenses
Money yearly_expenses[3][EXPENSES_END]
Expenses of the company for the last three years, in every ExpensesType category.
Definition: company_base.h:98
livery.h
EngineRenew
Struct to store engine replacements.
Definition: autoreplace_base.h:33
Company::IsHumanID
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
Definition: company_base.h:162
_cur_company_tick_index
uint _cur_company_tick_index
used to generate a name for one company that doesn't have a name yet per tick
Definition: company_cmd.cpp:51
CompanyProperties::bankrupt_asked
CompanyMask bankrupt_asked
which companies were asked about buying it?
Definition: company_base.h:83
CompanyProperties::president_name_2
uint32 president_name_2
Parameter of president_name_1.
Definition: company_base.h:62
CompanyEconomyEntry::delivered_cargo
CargoArray delivered_cargo
The amount of delivered cargo.
Definition: company_base.h:26
_next_competitor_start
uint _next_competitor_start
the number of ticks before the next AI is started
Definition: company_cmd.cpp:50
CompanyEconomyEntry::expenses
Money expenses
The amount of expenses.
Definition: company_base.h:25
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CompanySettings
Settings that can be set per company.
Definition: settings_type.h:576
CompanyProperties::share_owners
std::array< Owner, MAX_COMPANY_SHARE_OWNERS > share_owners
Owners of the shares of the company. INVALID_OWNER if nobody has bought them yet.
Definition: company_base.h:78
Pool
Base class for all pools.
Definition: pool_type.hpp:81
CompanyProperties::cur_economy
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition: company_base.h:99
tile_type.h
RAILTYPE_END
@ RAILTYPE_END
Used for iterations.
Definition: rail_type.h:33
CompanyInfrastructure::rail
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
Definition: company_base.h:34
CompanyInfrastructure::airport
uint32 airport
Count of company owned airports.
Definition: company_base.h:37
CompanyEconomyEntry::income
Money income
The amount of income.
Definition: company_base.h:24
CompanyProperties::president_name_1
StringID president_name_1
Name of the president if the user did not change it.
Definition: company_base.h:61
Company::~Company
~Company()
Destructor.
Definition: company_cmd.cpp:76
road_type.h
AIInfo
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:16
OverflowSafeInt< int64 >
AIInstance
Runtime information about an AI like a pointer to the squirrel vm and the current state.
Definition: ai_instance.hpp:16
autoreplace_type.h
CompanyProperties::engine_renew_list
EngineRenewList engine_renew_list
Engine renewals of this company.
Definition: company_base.h:105
Company
Definition: company_base.h:117
RailTypes
RailTypes
The different railtypes we support, but then a bitmask of them.
Definition: rail_type.h:46
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:234
CompanyProperties::old_economy
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition: company_base.h:100
CompanyProperties::bankrupt_timeout
int16 bankrupt_timeout
If bigger than 0, amount of time to wait for an answer on an offer to buy this company.
Definition: company_base.h:84
Livery
Information about a particular livery.
Definition: livery.h:78
CompanyProperties
Statically loadable part of Company pool item.
Definition: company_base.h:56
CompanyInfrastructure::GetRailTotal
uint32 GetRailTotal() const
Get total sum of all owned track bits.
Definition: company_base.h:40
CompanyProperties::name_1
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:58
RAILTYPE_BEGIN
@ RAILTYPE_BEGIN
Used for iterations.
Definition: rail_type.h:28