OpenTTD
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 
27 };
28 
30  uint32 road[ROADTYPE_END];
31  uint32 signal;
32  uint32 rail[RAILTYPE_END];
33  uint32 water;
34  uint32 station;
35  uint32 airport;
36 
38  uint32 GetRailTotal() const
39  {
40  uint32 total = 0;
41  for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) total += this->rail[rt];
42  return total;
43  }
44 
45  uint32 GetRoadTotal() const;
46  uint32 GetTramTotal() const;
47 };
48 
51 
52 
55  uint32 name_2;
57  char *name;
58 
62 
64 
68 
69  byte colour;
70 
72 
75 
76  Owner share_owners[4];
77 
79 
81  CompanyMask bankrupt_asked;
83  Money bankrupt_value;
84 
85  uint32 terraform_limit;
86  uint32 clear_limit;
87  uint32 tree_limit;
88 
93  bool is_ai;
94 
95  Money yearly_expenses[3][EXPENSES_END];
99 
100  // TODO: Change some of these member variables to use relevant INVALID_xxx constants
102  : name_2(0), name_1(0), name(nullptr), president_name_1(0), president_name_2(0), president_name(nullptr),
103  face(0), money(0), money_fraction(0), current_loan(0), colour(0), block_preview(0),
104  location_of_HQ(0), last_build_coordinate(0), share_owners(), inaugurated_year(0),
105  months_of_bankruptcy(0), bankrupt_asked(0), bankrupt_timeout(0), bankrupt_value(0),
106  terraform_limit(0), clear_limit(0), tree_limit(0), is_ai(false) {}
107 
109  {
110  free(this->name);
111  free(this->president_name);
112  }
113 };
114 
116  Company(uint16 name_1 = 0, bool is_ai = false);
117  ~Company();
118 
119  Livery livery[LS_END];
122 
123  class AIInstance *ai_instance;
124  class AIInfo *ai_info;
125 
130 
132 
138  static inline bool IsValidAiID(size_t index)
139  {
140  const Company *c = Company::GetIfValid(index);
141  return c != nullptr && c->is_ai;
142  }
143 
150  static inline bool IsValidHumanID(size_t index)
151  {
152  const Company *c = Company::GetIfValid(index);
153  return c != nullptr && !c->is_ai;
154  }
155 
163  static inline bool IsHumanID(size_t index)
164  {
165  return !Company::Get(index)->is_ai;
166  }
167 
168  static void PostDestructor(size_t index);
169 };
170 
171 Money CalculateCompanyValue(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 */
Last company-ownable type.
Definition: vehicle_type.h:29
Owner
Enum for all companies/owners.
Definition: company_type.h:18
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:302
Enums and other types related to roads.
char * name
Name of the company if the user changed it.
Definition: company_base.h:57
Runtime information about an AI like a pointer to the squirrel vm and the current state...
Definition: ai_instance.hpp:16
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
int32 performance_history
Company score (scale 0-1000)
Definition: company_base.h:25
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
byte money_fraction
Fraction of money of the company, too small to represent in money.
Definition: company_base.h:66
uint32 GetRailTotal() const
Get total sum of all owned track bits.
Definition: company_base.h:38
Year inaugurated_year
Year of starting the company.
Definition: company_base.h:78
EngineRenewList engine_renew_list
Engine renewals of this company.
Definition: company_base.h:126
Base class for groups and group functions.
Used for iterations.
Definition: road_type.h:26
byte block_preview
Number of quarters that the company is not allowed to get new exclusive engine previews (see Companie...
Definition: company_base.h:71
CompanyMask bankrupt_asked
which companies were asked about buying it?
Definition: company_base.h:81
CompanyPool _company_pool
Pool of companies.
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
Definition: company_base.h:163
byte months_of_bankruptcy
Number of months that the company is unable to pay its debts.
Definition: company_base.h:80
char * president_name
Name of the president if the user changed it.
Definition: company_base.h:61
uint32 name_2
Parameter of name_1.
Definition: company_base.h:55
uint32 station
Count of company owned station tiles.
Definition: company_base.h:34
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
CompanySettings settings
settings specific for each company
Definition: company_base.h:127
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:150
uint _cur_company_tick_index
used to generate a name for one company that doesn&#39;t have a name yet per tick
Definition: company_cmd.cpp:49
Money expenses
The amount of expenses.
Definition: company_base.h:23
uint32 CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition: company_type.h:51
uint32 signal
Count of company owned signals.
Definition: company_base.h:31
uint32 terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
Definition: company_base.h:85
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:98
Statistics and caches on the vehicles in a group.
Definition: group.h:24
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition: company_base.h:138
Statically loadable part of Company pool item.
Definition: company_base.h:54
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:67
Types related to global configuration settings.
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
Definition: company_base.h:73
uint32 clear_limit
Amount of tiles we can (still) clear (times 65536).
Definition: company_base.h:86
Information about a particular livery.
Definition: livery.h:78
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition: economy.cpp:111
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:93
Money money
Money owned by the company.
Definition: company_base.h:65
uint32 airport
Count of company owned airports.
Definition: company_base.h:35
RailTypes
The different railtypes we support, but then a bitmask of them.
Definition: rail_type.h:46
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CompanyManagerFace face
Face description of the president.
Definition: company_base.h:63
Base class for all PoolItems.
Definition: pool_type.hpp:188
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:82
uint32 tree_limit
Amount of trees we can (still) plant (times 65536).
Definition: company_base.h:87
Base class for all pools.
Definition: pool_type.hpp:82
uint32 president_name_2
Parameter of president_name_1.
Definition: company_base.h:60
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:131
Functions/types related to livery colours.
Class for storing amounts of cargo.
Definition: cargo_type.h:81
static const uint MAX_HISTORY_QUARTERS
The maximum number of quarters kept as performance&#39;s history.
Definition: company_type.h:42
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
Types related to autoreplacing.
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:16
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:56
byte colour
Company colour.
Definition: company_base.h:69
CargoArray delivered_cargo
The amount of delivered cargo.
Definition: company_base.h:24
Settings that can be set per company.
StringID president_name_1
Name of the president if the user did not change it.
Definition: company_base.h:59
Struct to store engine replacements.
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:121
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition: company_base.h:74
uint _next_competitor_start
the number of ticks before the next AI is started
Definition: company_cmd.cpp:48
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
Statistics about the economy.
Definition: company_base.h:21
Used for iterations.
Definition: rail_type.h:33
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:120
Money income
The amount of income.
Definition: company_base.h:22
Money company_value
The value of the company.
Definition: company_base.h:26
Types related to tiles.
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition: company_base.h:96
Number of expense types.
Definition: economy_type.h:162
Used for iterations.
Definition: rail_type.h:28
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:33