Go to the documentation of this file.
1 /* $Id: company_base.h 27757 2017-02-26 19:41:14Z frosch $ */
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 <>.
8  */
12 #ifndef COMPANY_BASE_H
13 #define COMPANY_BASE_H
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"
29 };
32  uint32 road[ROADTYPE_END];
33  uint32 signal;
34  uint32 rail[RAILTYPE_END];
35  uint32 water;
36  uint32 station;
37  uint32 airport;
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 };
54  uint32 name_2;
56  char *name;
68  byte colour;
77  OwnerByte share_owners[4];
82  CompanyMask bankrupt_asked;
84  Money bankrupt_value;
86  uint32 terraform_limit;
87  uint32 clear_limit;
88  uint32 tree_limit;
94  bool is_ai;
96  Money yearly_expenses[3][EXPENSES_END];
101  CompanyProperties() : name(NULL), president_name(NULL) {}
104  {
105  free(this->name);
106  free(this->president_name);
107  }
108 };
111  Company(uint16 name_1 = 0, bool is_ai = false);
112  ~Company();
114  Livery livery[LS_END];
117  class AIInstance *ai_instance;
118  class AIInfo *ai_info;
132  static inline bool IsValidAiID(size_t index)
133  {
134  const Company *c = Company::GetIfValid(index);
135  return c != NULL && c->is_ai;
136  }
144  static inline bool IsValidHumanID(size_t index)
145  {
146  const Company *c = Company::GetIfValid(index);
147  return c != NULL && !c->is_ai;
148  }
157  static inline bool IsHumanID(size_t index)
158  {
159  return !Company::Get(index)->is_ai;
160  }
162  static void PostDestructor(size_t index);
163 };
165 #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
168 Money CalculateCompanyValue(const Company *c, bool including_loan = true);
170 extern uint _next_competitor_start;
171 extern uint _cur_company_tick_index;
173 #endif /* COMPANY_BASE_H */
Used for iterations.
Definition: rail_type.h:35
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
Enums and other types related to roads.
The different roadtypes we support, but then a bitmask of them.
Definition: rail_type.h:52
char * name
Name of the company if the user changed it.
Definition: company_base.h:56
Enumeration for all possible railtypes.
Definition: rail_type.h:29
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
byte money_fraction
Fraction of money of the company, too small to represent in money.
Definition: company_base.h:65
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:79
EngineRenewList engine_renew_list
Engine renewals of this company.
Definition: company_base.h:120
Base class for groups and group functions.
Last company-ownable type.
Definition: vehicle_type.h:29
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:72
CompanyMask bankrupt_asked
which companies were asked about buying it?
Definition: company_base.h:82
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:157
byte months_of_bankruptcy
Number of months that the company is unable to pay its debts.
Definition: company_base.h:81
char * president_name
Name of the president if the user changed it.
Definition: company_base.h:60
uint32 name_2
Parameter of name_1.
Definition: company_base.h:54
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:121
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
Definition: company_base.h:144
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:55
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:86
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:99
Statistics and caches on the vehicles in a group.
Definition: group.h:25
static bool IsValidAiID(size_t index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition: company_base.h:132
Statically loadable part of Company pool item.
Definition: company_base.h:53
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:66
Types related to global configuration settings.
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
Definition: company_base.h:74
uint32 clear_limit
Amount of tiles we can (still) clear (times 65536).
Definition: company_base.h:87
Information about a particular livery.
Definition: livery.h:76
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:94
Money money
Money owned by the company.
Definition: company_base.h:64
uint32 airport
Count of company owned airports.
Definition: company_base.h:37
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:62
Base class for all PoolItems.
Definition: pool_type.hpp:146
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
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
uint32 tree_limit
Amount of trees we can (still) plant (times 65536).
Definition: company_base.h:88
Base class for all pools.
Definition: pool_type.hpp:83
uint32 president_name_2
Parameter of president_name_1.
Definition: company_base.h:59
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:125
Functions/types related to livery colours.
Class for storing amounts of cargo.
Definition: cargo_type.h:74
static const uint MAX_HISTORY_QUARTERS
The maximum number of quarters kept as performance&#39;s history.
Definition: company_type.h:44
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
RailTypes avail_railtypes
Rail types available to the company.
Definition: company_base.h:70
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:55
byte colour
Company colour.
Definition: company_base.h:68
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:58
Struct to store engine replacements.
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:115
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition: company_base.h:75
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:114
Statistics about the economy.
Definition: company_base.h:23
Used for iterations.
Definition: rail_type.h:30
Number of expense types.
Definition: economy_type.h:164
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:97
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:35