OpenTTD

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