OpenTTD: src/company_base.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

company_base.h
Go to the documentation of this file.
1 /* $Id: company_base.h 26081 2013-11-24 09:52:35Z rubidium $ */
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, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
49 extern CompanyPool _company_pool;
50
51
53 struct CompanyProperties {
54 uint32 name_2;
55 uint16 name_1;
56 char *name;
57
58 uint16 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 */