OpenTTD
company_base.h
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef COMPANY_BASE_H
13 #define COMPANY_BASE_H
14 
15 #include "road_type.h"
16 #include "livery.h"
17 #include "autoreplace_type.h"
18 #include "tile_type.h"
19 #include "settings_type.h"
20 #include "group.h"
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  char *name;
60 
64 
66 
70 
71  byte colour;
72 
74 
77 
78  Owner share_owners[4];
79 
81 
83  CompanyMask bankrupt_asked;
85  Money bankrupt_value;
86 
87  uint32 terraform_limit;
88  uint32 clear_limit;
89  uint32 tree_limit;
90 
95  bool is_ai;
96 
97  Money yearly_expenses[3][EXPENSES_END];
101 
102  // TODO: Change some of these member variables to use relevant INVALID_xxx constants
104  : name_2(0), name_1(0), name(nullptr), president_name_1(0), president_name_2(0), president_name(nullptr),
105  face(0), money(0), money_fraction(0), current_loan(0), colour(0), block_preview(0),
106  location_of_HQ(0), last_build_coordinate(0), share_owners(), inaugurated_year(0),
107  months_of_bankruptcy(0), bankrupt_asked(0), bankrupt_timeout(0), bankrupt_value(0),
108  terraform_limit(0), clear_limit(0), tree_limit(0), is_ai(false) {}
109 
111  {
112  free(this->name);
113  free(this->president_name);
114  }
115 };
116 
118  Company(uint16 name_1 = 0, bool is_ai = false);
119  ~Company();
120 
121  Livery livery[LS_END];
124 
125  class AIInstance *ai_instance;
126  class AIInfo *ai_info;
127 
132 
134 
140  static inline bool IsValidAiID(size_t index)
141  {
142  const Company *c = Company::GetIfValid(index);
143  return c != nullptr && c->is_ai;
144  }
145 
152  static inline bool IsValidHumanID(size_t index)
153  {
154  const Company *c = Company::GetIfValid(index);
155  return c != nullptr && !c->is_ai;
156  }
157 
165  static inline bool IsHumanID(size_t index)
166  {
167  return !Company::Get(index)->is_ai;
168  }
169 
170  static void PostDestructor(size_t index);
171 };
172 
173 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
174 #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
175 
176 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
177 
178 extern uint _next_competitor_start;
179 extern uint _cur_company_tick_index;
180 
181 #endif /* COMPANY_BASE_H */
Last company-ownable type.
Definition: vehicle_type.h:31
Owner
Enum for all companies/owners.
Definition: company_type.h:20
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
Enums and other types related to roads.
char * name
Name of the company if the user changed it.
Definition: company_base.h:59
Runtime information about an AI like a pointer to the squirrel vm and the current state...
Definition: ai_instance.hpp:18
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
int32 performance_history
Company score (scale 0-1000)
Definition: company_base.h:27
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:41
byte money_fraction
Fraction of money of the company, too small to represent in money.
Definition: company_base.h:68
uint32 GetRailTotal() const
Get total sum of all owned track bits.
Definition: company_base.h:40
Year inaugurated_year
Year of starting the company.
Definition: company_base.h:80
EngineRenewList engine_renew_list
Engine renewals of this company.
Definition: company_base.h:128
Base class for groups and group functions.
Used for iterations.
Definition: road_type.h:31
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
CompanyMask bankrupt_asked
which companies were asked about buying it?
Definition: company_base.h:83
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:165
byte months_of_bankruptcy
Number of months that the company is unable to pay its debts.
Definition: company_base.h:82
char * president_name
Name of the president if the user changed it.
Definition: company_base.h:63
uint32 name_2
Parameter of name_1.
Definition: company_base.h:57
uint32 station
Count of company owned station tiles.
Definition: company_base.h:36
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
CompanySettings settings
settings specific for each company
Definition: company_base.h:129
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:152
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:51
Money expenses
The amount of expenses.
Definition: company_base.h:25
uint32 CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition: company_type.h:53
uint32 signal
Count of company owned signals.
Definition: company_base.h:33
uint32 terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
Definition: company_base.h:87
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:100
Statistics and caches on the vehicles in a group.
Definition: group.h:26
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition: company_base.h:140
Statically loadable part of Company pool item.
Definition: company_base.h:56
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:69
Types related to global configuration settings.
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
Definition: company_base.h:75
uint32 clear_limit
Amount of tiles we can (still) clear (times 65536).
Definition: company_base.h:88
Information about a particular livery.
Definition: livery.h:80
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition: economy.cpp:113
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:95
Money money
Money owned by the company.
Definition: company_base.h:67
uint32 airport
Count of company owned airports.
Definition: company_base.h:37
RailTypes
The different railtypes we support, but then a bitmask of them.
Definition: rail_type.h:52
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
CompanyManagerFace face
Face description of the president.
Definition: company_base.h:65
Base class for all PoolItems.
Definition: pool_type.hpp:146
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
uint32 tree_limit
Amount of trees we can (still) plant (times 65536).
Definition: company_base.h:89
Base class for all pools.
Definition: pool_type.hpp:83
uint32 president_name_2
Parameter of president_name_1.
Definition: company_base.h:62
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:133
Functions/types related to livery colours.
Class for storing amounts of cargo.
Definition: cargo_type.h:83
static const uint MAX_HISTORY_QUARTERS
The maximum number of quarters kept as performance&#39;s history.
Definition: company_type.h:44
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
Types related to autoreplacing.
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:18
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:58
byte colour
Company colour.
Definition: company_base.h:71
CargoArray delivered_cargo
The amount of delivered cargo.
Definition: company_base.h:26
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:61
Struct to store engine replacements.
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:123
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition: company_base.h:76
uint _next_competitor_start
the number of ticks before the next AI is started
Definition: company_cmd.cpp:50
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:131
Statistics about the economy.
Definition: company_base.h:23
Used for iterations.
Definition: rail_type.h:35
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:122
Money income
The amount of income.
Definition: company_base.h:24
Money company_value
The value of the company.
Definition: company_base.h:28
Types related to tiles.
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition: company_base.h:98
Number of expense types.
Definition: economy_type.h:164
Used for iterations.
Definition: rail_type.h:30
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:35