OpenTTD Source: src/company_cmd.cpp Source File

OpenTTD Source 14.0-beta1

company_cmd.cpp
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 #include "stdafx.h"
11 #include "company_base.h"
12 #include "company_func.h"
13 #include "company_gui.h"
14 #include "core/backup_type.hpp"
15 #include "town.h"
16 #include "news_func.h"
17 #include "command_func.h"
18 #include "network/network.h"
19 #include "network/network_func.h"
20 #include "network/network_base.h"
21 #include "network/network_admin.h"
22 #include "ai/ai.hpp"
23 #include "company_manager_face.h"
24 #include "window_func.h"
25 #include "strings_func.h"
26 #include "sound_func.h"
27 #include "rail.h"
28 #include "core/pool_func.hpp"
29 #include "settings_func.h"
30 #include "vehicle_base.h"
31 #include "vehicle_func.h"
32 #include "smallmap_gui.h"
33 #include "game/game.hpp"
34 #include "goal_base.h"
35 #include "story_base.h"
36 #include "widgets/statusbar_widget.h"
37 #include "company_cmd.h"
38 #include "timer/timer.h"
39 #include "timer/timer_game_economy.h"
40 #include "timer/timer_game_tick.h"
41
42 #include "table/strings.h"
43
44 #include "safeguards.h"
45
46 void ClearEnginesHiddenFlagOfCompany(CompanyID cid);
47 void UpdateObjectColours(const Company *c);
48
49 CompanyID _local_company;
50 CompanyID _current_company;
51 Colours _company_colours[MAX_COMPANIES];
52 CompanyManagerFace _company_manager_face;
53 uint _cur_company_tick_index;
54
55 CompanyPool _company_pool("Company");
56 INSTANTIATE_POOL_METHODS(Company)
57
58
63 Company::Company(uint16_t name_1, bool is_ai)
64 {
65 this->name_1 = name_1;
66 this->location_of_HQ = INVALID_TILE;
67 this->is_ai = is_ai;
68 this->terraform_limit = (uint32_t)_settings_game.construction.terraform_frame_burst << 16;
69 this->clear_limit = (uint32_t)_settings_game.construction.clear_frame_burst << 16;
70 this->tree_limit = (uint32_t)_settings_game.construction.tree_frame_burst << 16;
71 this->build_object_limit = (uint32_t)_settings_game.construction.build_object_frame_burst << 16;
72
73 InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, INVALID_COMPANY);
74 }
75
77 Company::~Company()
78 {
79 if (CleaningPool()) return;
80
81 CloseCompanyWindows(this->index);
82 }
83
88 void Company::PostDestructor(size_t index)
89 {
90 InvalidateWindowData(WC_GRAPH_LEGEND, 0, (int)index);
91 InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, (int)index);
92 InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
93 InvalidateWindowData(WC_LINKGRAPH_LEGEND, 0);
94 /* If the currently shown error message has this company in it, then close it. */
95 InvalidateWindowData(WC_ERRMSG, 0);
96 }
97
102 Money Company::GetMaxLoan() const
103 {
104 if (this->max_loan == COMPANY_MAX_LOAN_DEFAULT) return _economy.max_loan;
105 return this->max_loan;
106 }
107
114 void SetLocalCompany(CompanyID new_company)
115 {
116 /* company could also be COMPANY_SPECTATOR or OWNER_NONE */
117 assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);
118
119 /* If actually changing to another company, several windows need closing */
120 bool switching_company = _local_company != new_company;
121
122 /* Delete the chat window, if you were team chatting. */
123 if (switching_company) InvalidateWindowData(WC_SEND_NETWORK_MSG, DESTTYPE_TEAM, _local_company);
124
125 assert(IsLocalCompany());
126
127 _current_company = _local_company = new_company;
128
129 if (switching_company) {
130 InvalidateWindowClassesData(WC_COMPANY);
131 /* Delete any construction windows... */
132 CloseConstructionWindows();
133 }
134
135 /* ... and redraw the whole screen. */
136 MarkWholeScreenDirty();
137 InvalidateWindowClassesData(WC_SIGN_LIST, -1);
138 InvalidateWindowClassesData(WC_GOALS_LIST);
139 }
140
146 TextColour GetDrawStringCompanyColour(CompanyID company)
147 {
148 if (!Company::IsValidID(company)) return (TextColour)_colour_gradient[COLOUR_WHITE][4] | TC_IS_PALETTE_COLOUR;
149 return (TextColour)_colour_gradient[_company_colours[company]][4] | TC_IS_PALETTE_COLOUR;
150 }
151
158 void DrawCompanyIcon(CompanyID c, int x, int y)
159 {
160 DrawSprite(SPR_COMPANY_ICON, COMPANY_SPRITE_COLOUR(c), x, y);
161 }
162
169 static bool IsValidCompanyManagerFace(CompanyManagerFace cmf)
170 {
171 if (!AreCompanyManagerFaceBitsValid(cmf, CMFV_GEN_ETHN, GE_WM)) return false;
172
173 GenderEthnicity ge = (GenderEthnicity)GetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, GE_WM);
174 bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0;
175 bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge) != 0;
176 bool has_glasses = GetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge) != 0;
177
178 if (!AreCompanyManagerFaceBitsValid(cmf, CMFV_EYE_COLOUR, ge)) return false;
179 for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) {
180 switch (cmfv) {
181 case CMFV_MOUSTACHE: if (!has_moustache) continue; break;
182 case CMFV_LIPS:
183 case CMFV_NOSE: if (has_moustache) continue; break;
184 case CMFV_TIE_EARRING: if (!has_tie_earring) continue; break;
185 case CMFV_GLASSES: if (!has_glasses) continue; break;
186 default: break;
187 }
188 if (!AreCompanyManagerFaceBitsValid(cmf, cmfv, ge)) return false;
189 }
190
191 return true;
192 }
193
198 void InvalidateCompanyWindows(const Company *company)
199 {
200 CompanyID cid = company->index;
201
202 if (cid == _local_company) SetWindowWidgetDirty(WC_STATUS_BAR, 0, WID_S_RIGHT);
203 SetWindowDirty(WC_FINANCES, cid);
204 }
205
213 Money GetAvailableMoney(CompanyID company)
214 {
215 if (_settings_game.difficulty.infinite_money) return INT64_MAX;
216 if (!Company::IsValidID(company)) return INT64_MAX;
217 return Company::Get(company)->money;
218 }
219
227 Money GetAvailableMoneyForCommand()
228 {
229 return GetAvailableMoney(_current_company);
230 }
231
238 bool CheckCompanyHasMoney(CommandCost &cost)
239 {
240 if (cost.GetCost() <= 0) return true;
241 if (_settings_game.difficulty.infinite_money) return true;
242
243 const Company *c = Company::GetIfValid(_current_company);
244 if (c != nullptr && cost.GetCost() > c->money) {
245 SetDParam(0, cost.GetCost());
246 cost.MakeError(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
247 return false;
248 }
249 return true;
250 }
251
257 static void SubtractMoneyFromAnyCompany(Company *c, const CommandCost &cost)
258 {
259 if (cost.GetCost() == 0) return;
260 assert(cost.GetExpensesType() != INVALID_EXPENSES);
261
262 c->money -= cost.GetCost();
263 c->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost();
264
265 if (HasBit(1 << EXPENSES_TRAIN_REVENUE |
266 1 << EXPENSES_ROADVEH_REVENUE |
267 1 << EXPENSES_AIRCRAFT_REVENUE |
268 1 << EXPENSES_SHIP_REVENUE, cost.GetExpensesType())) {
269 c->cur_economy.income -= cost.GetCost();
270 } else if (HasBit(1 << EXPENSES_TRAIN_RUN |
271 1 << EXPENSES_ROADVEH_RUN |
272 1 << EXPENSES_AIRCRAFT_RUN |
273 1 << EXPENSES_SHIP_RUN |
274 1 << EXPENSES_PROPERTY |
275 1 << EXPENSES_LOAN_INTEREST, cost.GetExpensesType())) {
276 c->cur_economy.expenses -= cost.GetCost();
277 }
278
279 InvalidateCompanyWindows(c);
280 }
281
286 void SubtractMoneyFromCompany(const CommandCost &cost)
287 {
288 Company *c = Company::GetIfValid(_current_company);
289 if (c != nullptr) SubtractMoneyFromAnyCompany(c, cost);
290 }
291
297 void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
298 {
299 Company *c = Company::Get(company);
300 byte m = c->money_fraction;
301 Money cost = cst.GetCost();
302
303 c->money_fraction = m - (byte)cost;
304 cost >>= 8;
305 if (c->money_fraction > m) cost++;
306 if (cost != 0) SubtractMoneyFromAnyCompany(c, CommandCost(cst.GetExpensesType(), cost));
307 }
308
309 static constexpr void UpdateLandscapingLimit(uint32_t &limit, uint64_t per_64k_frames, uint64_t burst)
310 {
311 limit = static_cast<uint32_t>(std::min<uint64_t>(limit + per_64k_frames, burst << 16));
312 }
313
315 void UpdateLandscapingLimits()
316 {
317 for (Company *c : Company::Iterate()) {
318 UpdateLandscapingLimit(c->terraform_limit, _settings_game.construction.terraform_per_64k_frames, _settings_game.construction.terraform_frame_burst);
319 UpdateLandscapingLimit(c->clear_limit, _settings_game.construction.clear_per_64k_frames, _settings_game.construction.clear_frame_burst);
320 UpdateLandscapingLimit(c->tree_limit, _settings_game.construction.tree_per_64k_frames, _settings_game.construction.tree_frame_burst);
321 UpdateLandscapingLimit(c->build_object_limit, _settings_game.construction.build_object_per_64k_frames, _settings_game.construction.build_object_frame_burst);
322 }
323 }
324
331 void SetDParamsForOwnedBy(Owner owner, TileIndex tile)
332 {
333 SetDParam(OWNED_BY_OWNER_IN_PARAMETERS_OFFSET, owner);
334
335 if (owner != OWNER_TOWN) {
336 if (!Company::IsValidID(owner)) {
337 SetDParam(0, STR_COMPANY_SOMEONE);
338 } else {
339 SetDParam(0, STR_COMPANY_NAME);
340 SetDParam(1, owner);
341 }
342 } else {
343 assert(tile != 0);
344 const Town *t = ClosestTownFromTile(tile, UINT_MAX);
345
346 SetDParam(0, STR_TOWN_NAME);
347 SetDParam(1, t->index);
348 }
349 }
350
351
360 CommandCost CheckOwnership(Owner owner, TileIndex tile)
361 {
362 assert(owner < OWNER_END);
363 assert(owner != OWNER_TOWN || tile != 0);
364
365 if (owner == _current_company) return CommandCost();
366
367 SetDParamsForOwnedBy(owner, tile);
368 return_cmd_error(STR_ERROR_OWNED_BY);
369 }
370
378 CommandCost CheckTileOwnership(TileIndex tile)
379 {
380 Owner owner = GetTileOwner(tile);
381
382 assert(owner < OWNER_END);
383
384 if (owner == _current_company) return CommandCost();
385
386 /* no need to get the name of the owner unless we're the local company (saves some time) */
387 if (IsLocalCompany()) SetDParamsForOwnedBy(owner, tile);
388 return_cmd_error(STR_ERROR_OWNED_BY);
389 }
390
395 static void GenerateCompanyName(Company *c)
396 {
397 if (c->name_1 != STR_SV_UNNAMED) return;
398 if (c->last_build_coordinate == 0) return;
399
400 Town *t = ClosestTownFromTile(c->last_build_coordinate, UINT_MAX);
401
402 StringID str;
403 uint32_t strp;
404 std::string name;
405 if (t->name.empty() && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
406 str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START;
407 strp = t->townnameparts;
408
409 verify_name:;
410 /* No companies must have this name already */
411 for (const Company *cc : Company::Iterate()) {
412 if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name;
413 }
414
415 SetDParam(0, strp);
416 name = GetString(str);
417 if (Utf8StringLength(name) >= MAX_LENGTH_COMPANY_NAME_CHARS) goto bad_town_name;
418
419 set_name:;
420 c->name_1 = str;
421 c->name_2 = strp;
422
423 MarkWholeScreenDirty();
424
425 if (c->is_ai) {
426 CompanyNewsInformation *cni = new CompanyNewsInformation(c);
427 SetDParam(0, STR_NEWS_COMPANY_LAUNCH_TITLE);
428 SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION);
429 SetDParamStr(2, cni->company_name);
430 SetDParam(3, t->index);
431 AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate.base(), NR_NONE, UINT32_MAX, cni);
432 }
433 return;
434 }
435 bad_town_name:;
436
437 if (c->president_name_1 == SPECSTR_PRESIDENT_NAME) {
438 str = SPECSTR_ANDCO_NAME;
439 strp = c->president_name_2;
440 goto set_name;
441 } else {
442 str = SPECSTR_ANDCO_NAME;
443 strp = Random();
444 goto verify_name;
445 }
446 }
447
449 static const byte _colour_sort[COLOUR_END] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1};
451 static const Colours _similar_colour[COLOUR_END][2] = {
452 { COLOUR_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_DARK_BLUE
453 { COLOUR_GREEN, COLOUR_DARK_GREEN }, // COLOUR_PALE_GREEN
454 { INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_PINK
455 { COLOUR_ORANGE, INVALID_COLOUR }, // COLOUR_YELLOW
456 { INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_RED
457 { COLOUR_DARK_BLUE, COLOUR_BLUE }, // COLOUR_LIGHT_BLUE
458 { COLOUR_PALE_GREEN, COLOUR_DARK_GREEN }, // COLOUR_GREEN
459 { COLOUR_PALE_GREEN, COLOUR_GREEN }, // COLOUR_DARK_GREEN
460 { COLOUR_DARK_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_BLUE
461 { COLOUR_BROWN, COLOUR_ORANGE }, // COLOUR_CREAM
462 { COLOUR_PURPLE, INVALID_COLOUR }, // COLOUR_MAUVE
463 { COLOUR_MAUVE, INVALID_COLOUR }, // COLOUR_PURPLE
464 { COLOUR_YELLOW, COLOUR_CREAM }, // COLOUR_ORANGE
465 { COLOUR_CREAM, INVALID_COLOUR }, // COLOUR_BROWN
466 { COLOUR_WHITE, INVALID_COLOUR }, // COLOUR_GREY
467 { COLOUR_GREY, INVALID_COLOUR }, // COLOUR_WHITE
468 };
469
474 static Colours GenerateCompanyColour()
475 {
476 Colours colours[COLOUR_END];
477
478 /* Initialize array */
479 for (uint i = 0; i < COLOUR_END; i++) colours[i] = (Colours)i;
480
481 /* And randomize it */
482 for (uint i = 0; i < 100; i++) {
483 uint r = Random();
484 Swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]);
485 }
486
487 /* Bubble sort it according to the values in table 1 */
488 for (uint i = 0; i < COLOUR_END; i++) {
489 for (uint j = 1; j < COLOUR_END; j++) {
490 if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) {
491 Swap(colours[j - 1], colours[j]);
492 }
493 }
494 }
495
496 /* Move the colours that look similar to each company's colour to the side */
497 for (const Company *c : Company::Iterate()) {
498 Colours pcolour = c->colour;
499
500 for (uint i = 0; i < COLOUR_END; i++) {
501 if (colours[i] == pcolour) {
502 colours[i] = INVALID_COLOUR;
503 break;
504 }
505 }
506
507 for (uint j = 0; j < 2; j++) {
508 Colours similar = _similar_colour[pcolour][j];
509 if (similar == INVALID_COLOUR) break;
510
511 for (uint i = 1; i < COLOUR_END; i++) {
512 if (colours[i - 1] == similar) Swap(colours[i - 1], colours[i]);
513 }
514 }
515 }
516
517 /* Return the first available colour */
518 for (uint i = 0; i < COLOUR_END; i++) {
519 if (colours[i] != INVALID_COLOUR) return colours[i];
520 }
521
522 NOT_REACHED();
523 }
524
529 static void GeneratePresidentName(Company *c)
530 {
531 for (;;) {
532 restart:;
533 c->president_name_2 = Random();
534 c->president_name_1 = SPECSTR_PRESIDENT_NAME;
535
536 /* Reserve space for extra unicode character. We need to do this to be able
537 * to detect too long president name. */
538 SetDParam(0, c->index);
539 std::string name = GetString(STR_PRESIDENT_NAME);
540 if (Utf8StringLength(name) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue;
541
542 for (const Company *cc : Company::Iterate()) {
543 if (c != cc) {
544 SetDParam(0, cc->index);
545 std::string other_name = GetString(STR_PRESIDENT_NAME);
546 if (name == other_name) goto restart;
547 }
548 }
549 return;
550 }
551 }
552
558 void ResetCompanyLivery(Company *c)
559 {
560 for (LiveryScheme scheme = LS_BEGIN; scheme < LS_END; scheme++) {
561 c->livery[scheme].in_use = 0;
562 c->livery[scheme].colour1 = c->colour;
563 c->livery[scheme].colour2 = c->colour;
564 }
565
566 for (Group *g : Group::Iterate()) {
567 if (g->owner == c->index) {
568 g->livery.in_use = 0;
569 g->livery.colour1 = c->colour;
570 g->livery.colour2 = c->colour;
571 }
572 }
573 }
574
582 Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
583 {
584 if (!Company::CanAllocateItem()) return nullptr;
585
586 /* we have to generate colour before this company is valid */
587 Colours colour = GenerateCompanyColour();
588
589 Company *c;
590 if (company == INVALID_COMPANY) {
591 c = new Company(STR_SV_UNNAMED, is_ai);
592 } else {
593 if (Company::IsValidID(company)) return nullptr;
594 c = new (company) Company(STR_SV_UNNAMED, is_ai);
595 }
596
597 c->colour = colour;
598
599 ResetCompanyLivery(c);
600 _company_colours[c->index] = c->colour;
601
602 /* Scale the initial loan based on the inflation rounded down to the loan interval. The maximum loan has already been inflation adjusted. */
603 c->money = c->current_loan = std::min<int64_t>((INITIAL_LOAN * _economy.inflation_prices >> 16) / LOAN_INTERVAL * LOAN_INTERVAL, _economy.max_loan);
604
605 c->avail_railtypes = GetCompanyRailTypes(c->index);
606 c->avail_roadtypes = GetCompanyRoadTypes(c->index);
607 c->inaugurated_year = TimerGameEconomy::year;
608
609 /* If starting a player company in singleplayer and a favorite company manager face is selected, choose it. Otherwise, use a random face.
610 * In a network game, we'll choose the favorite face later in CmdCompanyCtrl to sync it to all clients. */
611 if (_company_manager_face != 0 && !is_ai && !_networking) {
612 c->face = _company_manager_face;
613 } else {
614 RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false, _random);
615 }
616
617 SetDefaultCompanySettings(c->index);
618 ClearEnginesHiddenFlagOfCompany(c->index);
619
620 GeneratePresidentName(c);
621
622 SetWindowDirty(WC_GRAPH_LEGEND, 0);
623 InvalidateWindowData(WC_CLIENT_LIST, 0);
624 InvalidateWindowData(WC_LINKGRAPH_LEGEND, 0);
625 BuildOwnerLegend();
626 InvalidateWindowData(WC_SMALLMAP, 0, 1);
627
628 if (is_ai && (!_networking || _network_server)) AI::StartNew(c->index);
629
630 AI::BroadcastNewEvent(new ScriptEventCompanyNew(c->index), c->index);
631 Game::NewEvent(new ScriptEventCompanyNew(c->index));
632
633 return c;
634 }
635
637 TimeoutTimer<TimerGameTick> _new_competitor_timeout(0, []() {
638 if (_game_mode == GM_MENU || !AI::CanStartNew()) return;
639 if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return;
640
641 /* count number of competitors */
642 uint8_t n = 0;
643 for (const Company *c : Company::Iterate()) {
644 if (c->is_ai) n++;
645 }
646
647 if (n >= _settings_game.difficulty.max_no_competitors) return;
648
649 /* Send a command to all clients to start up a new AI.
650 * Works fine for Multiplayer and Singleplayer */
651 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID);
652 });
653
655 void StartupCompanies()
656 {
657 /* Ensure the timeout is aborted, so it doesn't fire based on information of the last game. */
658 _new_competitor_timeout.Abort();
659 }
660
662 void InitializeCompanies()
663 {
664 _cur_company_tick_index = 0;
665 }
666
673 bool MayCompanyTakeOver(CompanyID cbig, CompanyID csmall)
674 {
675 const Company *c1 = Company::Get(cbig);
676 const Company *c2 = Company::Get(csmall);
677
678 /* Do the combined vehicle counts stay within the limits? */
679 return c1->group_all[VEH_TRAIN].num_vehicle + c2->group_all[VEH_TRAIN].num_vehicle <= _settings_game.vehicle.max_trains &&
680 c1->group_all[VEH_ROAD].num_vehicle + c2->group_all[VEH_ROAD].num_vehicle <= _settings_game.vehicle.max_roadveh &&
681 c1->group_all[VEH_SHIP].num_vehicle + c2->group_all[VEH_SHIP].num_vehicle <= _settings_game.vehicle.max_ships &&
682 c1->group_all[VEH_AIRCRAFT].num_vehicle + c2->group_all[VEH_AIRCRAFT].num_vehicle <= _settings_game.vehicle.max_aircraft;
683 }
684
694 static void HandleBankruptcyTakeover(Company *c)
695 {
696 /* Amount of time out for each company to take over a company;
697 * Timeout is a quarter (3 months of 30 days) divided over the
698 * number of companies. The minimum number of days in a quarter
699 * is 90: 31 in January, 28 in February and 31 in March.
700 * Note that the company going bankrupt can't buy itself. */
701 static const int TAKE_OVER_TIMEOUT = 3 * 30 * Ticks::DAY_TICKS / (MAX_COMPANIES - 1);
702
703 assert(c->bankrupt_asked != 0);
704
705 /* We're currently asking some company to buy 'us' */
706 if (c->bankrupt_timeout != 0) {
707 c->bankrupt_timeout -= MAX_COMPANIES;
708 if (c->bankrupt_timeout > 0) return;
709 c->bankrupt_timeout = 0;
710
711 return;
712 }
713
714 /* Did we ask everyone for bankruptcy? If so, bail out. */
715 if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return;
716
717 Company *best = nullptr;
718 int32_t best_performance = -1;
719
720 /* Ask the company with the highest performance history first */
721 for (Company *c2 : Company::Iterate()) {
722 if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves
723 !HasBit(c->bankrupt_asked, c2->index) &&
724 best_performance < c2->old_economy[1].performance_history &&
725 MayCompanyTakeOver(c2->index, c->index)) {
726 best_performance = c2->old_economy[1].performance_history;
727 best = c2;
728 }
729 }
730
731 /* Asked all companies? */
732 if (best_performance == -1) {
733 c->bankrupt_asked = MAX_UVALUE(CompanyMask);
734 return;
735 }
736
737 SetBit(c->bankrupt_asked, best->index);
738
739 c->bankrupt_timeout = TAKE_OVER_TIMEOUT;
740
741 AI::NewEvent(best->index, new ScriptEventCompanyAskMerger(c->index, c->bankrupt_value));
742 if (IsInteractiveCompany(best->index)) {
743 ShowBuyCompanyDialog(c->index, false);
744 }
745 }
746
748 void OnTick_Companies()
749 {
750 if (_game_mode == GM_EDITOR) return;
751
752 Company *c = Company::GetIfValid(_cur_company_tick_index);
753 if (c != nullptr) {
754 if (c->name_1 != 0) GenerateCompanyName(c);
755 if (c->bankrupt_asked != 0) HandleBankruptcyTakeover(c);
756 }
757
758 if (_new_competitor_timeout.HasFired() && _game_mode != GM_MENU && AI::CanStartNew()) {
759 int32_t timeout = _settings_game.difficulty.competitors_interval * 60 * Ticks::TICKS_PER_SECOND;
760 /* If the interval is zero, start as many competitors as needed then check every ~10 minutes if a company went bankrupt and needs replacing. */
761 if (timeout == 0) {
762 /* count number of competitors */
763 uint8_t n = 0;
764 for (const Company *cc : Company::Iterate()) {
765 if (cc->is_ai) n++;
766 }
767
768 for (auto i = 0; i < _settings_game.difficulty.max_no_competitors; i++) {
769 if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) break;
770 if (n++ >= _settings_game.difficulty.max_no_competitors) break;
771 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID);
772 }
773 timeout = 10 * 60 * Ticks::TICKS_PER_SECOND;
774 }
775 /* Randomize a bit when the AI is actually going to start; ranges from 87.5% .. 112.5% of indicated value. */
776 timeout += ScriptObject::GetRandomizer(OWNER_NONE).Next(timeout / 4) - timeout / 8;
777
778 _new_competitor_timeout.Reset(std::max(1, timeout));
779 }
780
781 _cur_company_tick_index = (_cur_company_tick_index + 1) % MAX_COMPANIES;
782 }
783
788 static IntervalTimer<TimerGameEconomy> _economy_companies_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::COMPANY}, [](auto)
789 {
790 /* Copy statistics */
791 for (Company *c : Company::Iterate()) {
792 /* Move expenses to previous years. */
793 std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses));
794 c->yearly_expenses[0] = {};
795 SetWindowDirty(WC_FINANCES, c->index);
796 }
797
798 if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
799 ShowCompanyFinances(_local_company);
800 Company *c = Company::Get(_local_company);
801 if (c->num_valid_stat_ent > 5 && c->old_economy[0].performance_history < c->old_economy[4].performance_history) {
802 if (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);
803 } else {
804 if (_settings_client.sound.new_year) SndPlayFx(SND_00_GOOD_YEAR);
805 }
806 }
807 });
808
814 CompanyNewsInformation::CompanyNewsInformation(const Company *c, const Company *other)
815 {
816 SetDParam(0, c->index);
817 this->company_name = GetString(STR_COMPANY_NAME);
818
819 if (other != nullptr) {
820 SetDParam(0, other->index);
821 this->other_company_name = GetString(STR_COMPANY_NAME);
822 c = other;
823 }
824
825 SetDParam(0, c->index);
826 this->president_name = GetString(STR_PRESIDENT_NAME_MANAGER);
827
828 this->colour = c->colour;
829 this->face = c->face;
830
831 }
832
837 void CompanyAdminUpdate(const Company *company)
838 {
839 if (_network_server) NetworkAdminCompanyUpdate(company);
840 }
841
847 void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
848 {
849 if (_network_server) NetworkAdminCompanyRemove(company_id, (AdminCompanyRemoveReason)reason);
850 }
851
860 CommandCost CmdCompanyCtrl(DoCommandFlag flags, CompanyCtrlAction cca, CompanyID company_id, CompanyRemoveReason reason, ClientID client_id)
861 {
862 InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
863
864 switch (cca) {
865 case CCA_NEW: { // Create a new company
866 /* This command is only executed in a multiplayer game */
867 if (!_networking) return CMD_ERROR;
868
869 /* Has the network client a correct ClientIndex? */
870 if (!(flags & DC_EXEC)) return CommandCost();
871
872 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
873
874 /* Delete multiplayer progress bar */
875 CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
876
877 Company *c = DoStartupNewCompany(false);
878
879 /* A new company could not be created, revert to being a spectator */
880 if (c == nullptr) {
881 /* We check for "ci != nullptr" as a client could have left by
882 * the time we execute this command. */
883 if (_network_server && ci != nullptr) {
884 ci->client_playas = COMPANY_SPECTATOR;
885 NetworkUpdateClientInfo(ci->client_id);
886 }
887 break;
888 }
889
890 /* This is the client (or non-dedicated server) who wants a new company */
891 if (client_id == _network_own_client_id) {
892 assert(_local_company == COMPANY_SPECTATOR);
893 SetLocalCompany(c->index);
894 if (!_settings_client.network.default_company_pass.empty()) {
895 NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass);
896 }
897
898 /* In network games, we need to try setting the company manager face here to sync it to all clients.
899 * If a favorite company manager face is selected, choose it. Otherwise, use a random face. */
900 if (_company_manager_face != 0) Command<CMD_SET_COMPANY_MANAGER_FACE>::SendNet(STR_NULL, c->index, _company_manager_face);
901
902 /* Now that we have a new company, broadcast our company settings to
903 * all clients so everything is in sync */
904 SyncCompanySettings();
905
906 MarkWholeScreenDirty();
907 }
908
909 NetworkServerNewCompany(c, ci);
910 break;
911 }
912
913 case CCA_NEW_AI: { // Make a new AI company
914 if (company_id != INVALID_COMPANY && company_id >= MAX_COMPANIES) return CMD_ERROR;
915
916 /* For network games, company deletion is delayed. */
917 if (!_networking && company_id != INVALID_COMPANY && Company::IsValidID(company_id)) return CMD_ERROR;
918
919 if (!(flags & DC_EXEC)) return CommandCost();
920
921 /* For network game, just assume deletion happened. */
922 assert(company_id == INVALID_COMPANY || !Company::IsValidID(company_id));
923
924 Company *c = DoStartupNewCompany(true, company_id);
925 if (c != nullptr) NetworkServerNewCompany(c, nullptr);
926 break;
927 }
928
929 case CCA_DELETE: { // Delete a company
930 if (reason >= CRR_END) return CMD_ERROR;
931
932 /* We can't delete the last existing company in singleplayer mode. */
933 if (!_networking && Company::GetNumItems() == 1) return CMD_ERROR;
934
935 Company *c = Company::GetIfValid(company_id);
936 if (c == nullptr) return CMD_ERROR;
937
938 if (!(flags & DC_EXEC)) return CommandCost();
939
940 CompanyNewsInformation *cni = new CompanyNewsInformation(c);
941
942 /* Show the bankrupt news */
943 SetDParam(0, STR_NEWS_COMPANY_BANKRUPT_TITLE);
944 SetDParam(1, STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION);
945 SetDParamStr(2, cni->company_name);
946 AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, cni);
947
948 /* Remove the company */
949 ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
950 if (c->is_ai) AI::Stop(c->index);
951
952 CompanyID c_index = c->index;
953 delete c;
954 AI::BroadcastNewEvent(new ScriptEventCompanyBankrupt(c_index));
955 Game::NewEvent(new ScriptEventCompanyBankrupt(c_index));
956 CompanyAdminRemove(c_index, (CompanyRemoveReason)reason);
957
958 if (StoryPage::GetNumItems() == 0 || Goal::GetNumItems() == 0) InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
959 InvalidateWindowData(WC_CLIENT_LIST, 0);
960
961 break;
962 }
963
964 default: return CMD_ERROR;
965 }
966
967 InvalidateWindowClassesData(WC_GAME_OPTIONS);
968 InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
969 InvalidateWindowClassesData(WC_SCRIPT_LIST);
970
971 return CommandCost();
972 }
973
980 CommandCost CmdSetCompanyManagerFace(DoCommandFlag flags, CompanyManagerFace cmf)
981 {
982 if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR;
983
984 if (flags & DC_EXEC) {
985 Company::Get(_current_company)->face = cmf;
986 MarkWholeScreenDirty();
987 }
988 return CommandCost();
989 }
990
996 void UpdateCompanyLiveries(Company *c)
997 {
998 for (int i = 1; i < LS_END; i++) {
999 if (!HasBit(c->livery[i].in_use, 0)) c->livery[i].colour1 = c->livery[LS_DEFAULT].colour1;
1000 if (!HasBit(c->livery[i].in_use, 1)) c->livery[i].colour2 = c->livery[LS_DEFAULT].colour2;
1001 }
1002 UpdateCompanyGroupLiveries(c);
1003 }
1004
1013 CommandCost CmdSetCompanyColour(DoCommandFlag flags, LiveryScheme scheme, bool primary, Colours colour)
1014 {
1015 if (scheme >= LS_END || (colour >= COLOUR_END && colour != INVALID_COLOUR)) return CMD_ERROR;
1016
1017 /* Default scheme can't be reset to invalid. */
1018 if (scheme == LS_DEFAULT && colour == INVALID_COLOUR) return CMD_ERROR;
1019
1020 Company *c = Company::Get(_current_company);
1021
1022 /* Ensure no two companies have the same primary colour */
1023 if (scheme == LS_DEFAULT && primary) {
1024 for (const Company *cc : Company::Iterate()) {
1025 if (cc != c && cc->colour == colour) return CMD_ERROR;
1026 }
1027 }
1028
1029 if (flags & DC_EXEC) {
1030 if (primary) {
1031 if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 0, 1, colour != INVALID_COLOUR);
1032 if (colour == INVALID_COLOUR) colour = c->livery[LS_DEFAULT].colour1;
1033 c->livery[scheme].colour1 = colour;
1034
1035 /* If setting the first colour of the default scheme, adjust the
1036 * original and cached company colours too. */
1037 if (scheme == LS_DEFAULT) {
1038 UpdateCompanyLiveries(c);
1039 _company_colours[_current_company] = colour;
1040 c->colour = colour;
1041 CompanyAdminUpdate(c);
1042 }
1043 } else {
1044 if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 1, 1, colour != INVALID_COLOUR);
1045 if (colour == INVALID_COLOUR) colour = c->livery[LS_DEFAULT].colour2;
1046 c->livery[scheme].colour2 = colour;
1047
1048 if (scheme == LS_DEFAULT) {
1049 UpdateCompanyGroupLiveries(c);
1050 }
1051 }
1052
1053 if (c->livery[scheme].in_use != 0) {
1054 /* If enabling a scheme, set the default scheme to be in use too */
1055 c->livery[LS_DEFAULT].in_use = 1;
1056 } else {
1057 /* Else loop through all schemes to see if any are left enabled.
1058 * If not, disable the default scheme too. */
1059 c->livery[LS_DEFAULT].in_use = 0;
1060 for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1061 if (c->livery[scheme].in_use != 0) {
1062 c->livery[LS_DEFAULT].in_use = 1;
1063 break;
1064 }
1065 }
1066 }
1067
1068 ResetVehicleColourMap();
1069 MarkWholeScreenDirty();
1070
1071 /* All graph related to companies use the company colour. */
1072 InvalidateWindowData(WC_INCOME_GRAPH, 0);
1073 InvalidateWindowData(WC_OPERATING_PROFIT, 0);
1074 InvalidateWindowData(WC_DELIVERED_CARGO, 0);
1075 InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0);
1076 InvalidateWindowData(WC_COMPANY_VALUE, 0);
1077 InvalidateWindowData(WC_LINKGRAPH_LEGEND, 0);
1078 /* The smallmap owner view also stores the company colours. */
1079 BuildOwnerLegend();
1080 InvalidateWindowData(WC_SMALLMAP, 0, 1);
1081
1082 /* Company colour data is indirectly cached. */
1083 for (Vehicle *v : Vehicle::Iterate()) {
1084 if (v->owner == _current_company) v->InvalidateNewGRFCache();
1085 }
1086
1087 UpdateObjectColours(c);
1088 }
1089 return CommandCost();
1090 }
1091
1097 static bool IsUniqueCompanyName(const std::string &name)
1098 {
1099 for (const Company *c : Company::Iterate()) {
1100 if (!c->name.empty() && c->name == name) return false;
1101 }
1102
1103 return true;
1104 }
1105
1112 CommandCost CmdRenameCompany(DoCommandFlag flags, const std::string &text)
1113 {
1114 bool reset = text.empty();
1115
1116 if (!reset) {
1117 if (Utf8StringLength(text) >= MAX_LENGTH_COMPANY_NAME_CHARS) return CMD_ERROR;
1118 if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1119 }
1120
1121 if (flags & DC_EXEC) {
1122 Company *c = Company::Get(_current_company);
1123 if (reset) {
1124 c->name.clear();
1125 } else {
1126 c->name = text;
1127 }
1128 MarkWholeScreenDirty();
1129 CompanyAdminUpdate(c);
1130 }
1131
1132 return CommandCost();
1133 }
1134
1140 static bool IsUniquePresidentName(const std::string &name)
1141 {
1142 for (const Company *c : Company::Iterate()) {
1143 if (!c->president_name.empty() && c->president_name == name) return false;
1144 }
1145
1146 return true;
1147 }
1148
1155 CommandCost CmdRenamePresident(DoCommandFlag flags, const std::string &text)
1156 {
1157 bool reset = text.empty();
1158
1159 if (!reset) {
1160 if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR;
1161 if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1162 }
1163
1164 if (flags & DC_EXEC) {
1165 Company *c = Company::Get(_current_company);
1166
1167 if (reset) {
1168 c->president_name.clear();
1169 } else {
1170 c->president_name = text;
1171
1172 if (c->name_1 == STR_SV_UNNAMED && c->name.empty()) {
1173 Command<CMD_RENAME_COMPANY>::Do(DC_EXEC, text + " Transport");
1174 }
1175 }
1176
1177 MarkWholeScreenDirty();
1178 CompanyAdminUpdate(c);
1179 }
1180
1181 return CommandCost();
1182 }
1183
1190 int CompanyServiceInterval(const Company *c, VehicleType type)
1191 {
1192 const VehicleDefaultSettings *vds = (c == nullptr) ? &_settings_client.company.vehicle : &c->settings.vehicle;
1193 switch (type) {
1194 default: NOT_REACHED();
1195 case VEH_TRAIN: return vds->servint_trains;
1196 case VEH_ROAD: return vds->servint_roadveh;
1197 case VEH_AIRCRAFT: return vds->servint_aircraft;
1198 case VEH_SHIP: return vds->servint_ships;
1199 }
1200 }
1201
1206 uint32_t CompanyInfrastructure::GetRoadTotal() const
1207 {
1208 uint32_t total = 0;
1209 for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
1210 if (RoadTypeIsRoad(rt)) total += this->road[rt];
1211 }
1212 return total;
1213 }
1214
1219 uint32_t CompanyInfrastructure::GetTramTotal() const
1220 {
1221 uint32_t total = 0;
1222 for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
1223 if (RoadTypeIsTram(rt)) total += this->road[rt];
1224 }
1225 return total;
1226 }
1227
1238 CommandCost CmdGiveMoney(DoCommandFlag flags, Money money, CompanyID dest_company)
1239 {
1240 if (!_settings_game.economy.give_money) return CMD_ERROR;
1241
1242 const Company *c = Company::Get(_current_company);
1243 CommandCost amount(EXPENSES_OTHER, std::min<Money>(money, 20000000LL));
1244
1245 /* You can only transfer funds that is in excess of your loan */
1246 if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return_cmd_error(STR_ERROR_INSUFFICIENT_FUNDS);
1247 if (!Company::IsValidID(dest_company)) return CMD_ERROR;
1248
1249 if (flags & DC_EXEC) {
1250 /* Add money to company */
1251 Backup<CompanyID> cur_company(_current_company, dest_company, FILE_LINE);
1252 SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
1253 cur_company.Restore();
1254
1255 if (_networking) {
1256 SetDParam(0, dest_company);
1257 std::string dest_company_name = GetString(STR_COMPANY_NAME);
1258
1259 SetDParam(0, _current_company);
1260 std::string from_company_name = GetString(STR_COMPANY_NAME);
1261
1262 NetworkTextMessage(NETWORK_ACTION_GIVE_MONEY, GetDrawStringCompanyColour(_current_company), false, from_company_name, dest_company_name, amount.GetCost());
1263 }
1264 }
1265
1266 /* Subtract money from local-company */
1267 return amount;
1268 }
1269
1279 CompanyID GetFirstPlayableCompanyID()
1280 {
1281 for (Company *c : Company::Iterate()) {
1282 if (Company::IsHumanID(c->index)) {
1283 return c->index;
1284 }
1285 }
1286
1287 if (Company::CanAllocateItem()) {
1288 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
1289 if (!Company::IsValidID(c)) {
1290 return c;
1291 }
1292 }
1293 }
1294
1295 return COMPANY_FIRST;
1296 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
EconomySettings::give_money
bool give_money
allow giving other companies money
Definition: settings_type.h:547
game.hpp
HandleBankruptcyTakeover
static void HandleBankruptcyTakeover(Company *c)
Handle the bankruptcy take over of a company.
Definition: company_cmd.cpp:694
BuildOwnerLegend
void BuildOwnerLegend()
Completes the array for the owned property legend.
Definition: smallmap_gui.cpp:343
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:95
VehicleSettings::max_aircraft
UnitID max_aircraft
max planes in game per company
Definition: settings_type.h:526
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3200
sound_func.h
EXPENSES_ROADVEH_RUN
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
Definition: economy_type.h:176
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:29
INVALID_EXPENSES
@ INVALID_EXPENSES
Invalid expense type.
Definition: economy_type.h:187
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3082
NR_TILE
@ NR_TILE
Reference tile. Scroll to tile when clicking on the news.
Definition: news_type.h:54
Company::group_all
GroupStatistics group_all[VEH_COMPANY_END]
NOSAVE: Statistics for the ALL_GROUP group.
Definition: company_base.h:126
CompanyAdminUpdate
void CompanyAdminUpdate(const Company *company)
Called whenever company related information changes in order to notify admins.
Definition: company_cmd.cpp:837
command_func.h
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
ConstructionSettings::tree_per_64k_frames
uint32_t tree_per_64k_frames
how many trees may, over a long period, be planted per 65536 frames?
Definition: settings_type.h:391
Swap
constexpr void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:283
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
statusbar_widget.h
Company::avail_railtypes
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:120
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition: town_cmd.cpp:3744
smallmap_gui.h
GenerateCompanyName
static void GenerateCompanyName(Company *c)
Generate the name of a company from the last build coordinate.
Definition: company_cmd.cpp:395
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
SetDefaultCompanySettings
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Definition: settings.cpp:1786
Company::avail_roadtypes
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:121
_similar_colour
static const Colours _similar_colour[COLOUR_END][2]
Similar colours, so we can try to prevent same coloured companies.
Definition: company_cmd.cpp:451
UpdateObjectColours
void UpdateObjectColours(const Company *c)
Updates the colour of the object whenever a company changes.
Definition: object_cmd.cpp:181
company_base.h
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition: economy_type.h:185
CompanyNewsInformation::president_name
std::string president_name
The name of the president.
Definition: news_type.h:163
NetworkClientInfo::client_playas
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:27
LOAN_INTERVAL
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
Definition: economy_type.h:215
company_gui.h
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NetworkSettings::default_company_pass
std::string default_company_pass
default password for new companies in encrypted form
Definition: settings_type.h:319
ConstructionSettings::tree_frame_burst
uint16_t tree_frame_burst
how many trees may, over a short period, be planted?
Definition: settings_type.h:392
_network_server
bool _network_server
network-server is active
Definition: network.cpp:60
EXPENSES_TRAIN_REVENUE
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
Definition: economy_type.h:180
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
GetCompanyManagerFaceBits
uint GetCompanyManagerFaceBits(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, [[maybe_unused]] GenderEthnicity ge)
Make sure the table's size is right.
Definition: company_manager_face.h:96
WC_CLIENT_LIST
@ WC_CLIENT_LIST
Client list; Window numbers:
Definition: window_type.h:478
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition: timer.h:76
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
company_manager_face.h
GenderEthnicity
GenderEthnicity
The gender/race combinations that we have faces for.
Definition: company_manager_face.h:19
Pool::PoolItem<&_company_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
CompanyProperties::money_fraction
byte money_fraction
Fraction of money of the company, too small to represent in money.
Definition: company_base.h:68
NetworkUpdateClientInfo
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
Definition: network_server.cpp:1569
Company::PostDestructor
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
Definition: company_cmd.cpp:88
CompanyNewsInformation::colour
Colours colour
The colour related to the company.
Definition: news_type.h:167
WC_PERFORMANCE_HISTORY
@ WC_PERFORMANCE_HISTORY
Performance history graph; Window numbers:
Definition: window_type.h:552
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:618
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
WC_SIGN_LIST
@ WC_SIGN_LIST
Sign list; Window numbers:
Definition: window_type.h:278
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:613
SetLocalCompany
void SetLocalCompany(CompanyID new_company)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
Definition: company_cmd.cpp:114
AI::CanStartNew
static bool CanStartNew()
Is it possible to start a new AI company?
Definition: ai_core.cpp:30
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
vehicle_base.h
CompanyProperties::bankrupt_timeout
int16_t 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
EXPENSES_AIRCRAFT_RUN
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
Definition: economy_type.h:177
CmdCompanyCtrl
CommandCost CmdCompanyCtrl(DoCommandFlag flags, CompanyCtrlAction cca, CompanyID company_id, CompanyRemoveReason reason, ClientID client_id)
Control the companies: add, delete, etc.
Definition: company_cmd.cpp:860
CompanyProperties::name
std::string name
Name of the company if the user changed it.
Definition: company_base.h:59
_random
Randomizer _random
Random used in the game state calculations.
Definition: random_func.cpp:37
goal_base.h
Economy::max_loan
Money max_loan
NOSAVE: Maximum possible loan.
Definition: economy_type.h:44
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
LiveryScheme
LiveryScheme
List of different livery schemes.
Definition: livery.h:21
GetCompanyRoadTypes
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition: road.cpp:199
town.h
CloseCompanyWindows
void CloseCompanyWindows(CompanyID company)
Close all windows of a company.
Definition: window.cpp:1169
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition: window_type.h:369
CompanyInfrastructure::road
uint32_t road[ROADTYPE_END]
Count of company owned track bits for each road type.
Definition: company_base.h:33
SoundSettings::new_year
bool new_year
Play sound on new year, summarising the performance during the last year.
Definition: settings_type.h:239
CompanyProperties::last_build_coordinate
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition: company_base.h:77
CompanyProperties::face
CompanyManagerFace face
Face description of the president.
Definition: company_base.h:65
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
WC_GOALS_LIST
@ WC_GOALS_LIST
Goals list; Window numbers:
Definition: window_type.h:290
CompanyProperties::president_name_2
uint32_t president_name_2
Parameter of president_name_1.
Definition: company_base.h:62
ConstructionSettings::build_object_per_64k_frames
uint32_t build_object_per_64k_frames
how many tiles may, over a long period, be purchased or have objects built on them per 65536 frames?
Definition: settings_type.h:393
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
CmdSetCompanyColour
CommandCost CmdSetCompanyColour(DoCommandFlag flags, LiveryScheme scheme, bool primary, Colours colour)
Change the company's company-colour.
Definition: company_cmd.cpp:1013
WC_COMPANY_LEAGUE
@ WC_COMPANY_LEAGUE
Company league window; Window numbers:
Definition: window_type.h:564
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
CompanyProperties::current_loan
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:69
_cur_company_tick_index
uint _cur_company_tick_index
used to generate a name for one company that doesn't have a name yet per tick
Definition: company_cmd.cpp:53
InitializeCompanies
void InitializeCompanies()
Initialize the pool of companies.
Definition: company_cmd.cpp:662
ClearEnginesHiddenFlagOfCompany
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
Clear the 'hidden' flag for all engines of a new company.
Definition: engine.cpp:967
MayCompanyTakeOver
bool MayCompanyTakeOver(CompanyID cbig, CompanyID csmall)
May company cbig buy company csmall?
Definition: company_cmd.cpp:673
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
network_base.h
MAX_LENGTH_COMPANY_NAME_CHARS
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including '\0'.
Definition: company_type.h:41
CmdSetCompanyManagerFace
CommandCost CmdSetCompanyManagerFace(DoCommandFlag flags, CompanyManagerFace cmf)
Change the company manager's face.
Definition: company_cmd.cpp:980
ai.hpp
NR_NONE
@ NR_NONE
Empty reference.
Definition: news_type.h:53
GENDER_FEMALE
@ GENDER_FEMALE
This bit set means a female, otherwise male.
Definition: company_manager_face.h:20
NetworkChangeCompanyPassword
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password)
Change the company password of a given company.
Definition: network.cpp:157
WC_DELIVERED_CARGO
@ WC_DELIVERED_CARGO
Delivered cargo graph; Window numbers:
Definition: window_type.h:546
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
Group
Group data.
Definition: group.h:72
WC_GRAPH_LEGEND
@ WC_GRAPH_LEGEND
Legend for graphs; Window numbers:
Definition: window_type.h:522
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition: network.cpp:114
company_cmd.h
CompanyNewsInformation::other_company_name
std::string other_company_name
The name of the company taking over this one.
Definition: news_type.h:164
Utf8StringLength
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
Definition: string.cpp:378
ShowCompanyFinances
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
Definition: company_gui.cpp:544
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:51
CompanyNewsInformation::company_name
std::string company_name
The name of the company.
Definition: news_type.h:162
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:360
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
StartupCompanies
void StartupCompanies()
Start of a new game.
Definition: company_cmd.cpp:655
CmdGiveMoney
CommandCost CmdGiveMoney(DoCommandFlag flags, Money money, CompanyID dest_company)
Transfer funds (money) from one company to another.
Definition: company_cmd.cpp:1238
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
This functions returns the money which can be used to execute a command.
Definition: company_cmd.cpp:227
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:235
CommandCost
Common return value for all commands.
Definition: command_type.h:23
MAX_LENGTH_PRESIDENT_NAME_CHARS
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS
The maximum length of a president name in characters including '\0'.
Definition: company_type.h:40
settings_func.h
CompanyProperties::num_valid_stat_ent
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:100
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:639
CommandCost::GetExpensesType
ExpensesType GetExpensesType() const
The expense type of the cost.
Definition: command_type.h:92
AreCompanyManagerFaceBitsValid
bool AreCompanyManagerFaceBitsValid(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
Checks whether the company manager's face bits have a valid range.
Definition: company_manager_face.h:151
DifficultySettings::competitors_interval
uint16_t competitors_interval
the interval (in minutes) between adding competitors
Definition: settings_type.h:100
CCA_NEW_AI
@ CCA_NEW_AI
Create a new AI company.
Definition: company_type.h:69
VehicleSettings::max_ships
UnitID max_ships
max ships in game per company
Definition: settings_type.h:527
SubtractMoneyFromCompanyFract
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
Subtract money from a company, including the money fraction.
Definition: company_cmd.cpp:297
GeneratePresidentName
static void GeneratePresidentName(Company *c)
Generate a random president name of a company.
Definition: company_cmd.cpp:529
ConstructionSettings::clear_frame_burst
uint16_t clear_frame_burst
how many tiles may, over a short period, be cleared?
Definition: settings_type.h:390
CommandCost::MakeError
void MakeError(StringID message, StringID extra_message=INVALID_STRING_ID)
Makes this CommandCost behave like an error command.
Definition: command_type.h:101
CompanyProperties::colour
Colours colour
Company colour.
Definition: company_base.h:72
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
CompanyProperties::money
Money money
Money owned by the company.
Definition: company_base.h:67
InvalidateCompanyWindows
void InvalidateCompanyWindows(const Company *company)
Refresh all windows owned by a company.
Definition: company_cmd.cpp:198
AI::StartNew
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
Definition: ai_core.cpp:36
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
TC_IS_PALETTE_COLOUR
@ TC_IS_PALETTE_COLOUR
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:276
Livery::in_use
byte in_use
Bit 0 set if this livery should override the default livery first colour, Bit 1 for the second colour...
Definition: livery.h:79
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:105
timer_game_tick.h
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:147
CompanyProperties::name_2
uint32_t name_2
Parameter of name_1.
Definition: company_base.h:57
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:628
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
SyncCompanySettings
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
Definition: settings.cpp:1798
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:260
safeguards.h
WID_S_RIGHT
@ WID_S_RIGHT
Right part; bank balance.
Definition: statusbar_widget.h:17
timer.h
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
CompanyManagerFace
uint32_t CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition: company_type.h:52
VehicleDefaultSettings::servint_aircraft
uint16_t servint_aircraft
service interval for aircraft
Definition: settings_type.h:603
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:59
rail.h
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1007
CompanyProperties::president_name
std::string president_name
Name of the president if the user changed it.
Definition: company_base.h:63
SetDParamsForOwnedBy
void SetDParamsForOwnedBy(Owner owner, TileIndex tile)
Set the right DParams for STR_ERROR_OWNED_BY.
Definition: company_cmd.cpp:331
IsValidCompanyManagerFace
static bool IsValidCompanyManagerFace(CompanyManagerFace cmf)
Checks whether a company manager's face is a valid encoding.
Definition: company_cmd.cpp:169
VehicleDefaultSettings
Default settings for vehicles.
Definition: settings_type.h:599
AdminCompanyRemoveReason
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
Definition: tcp_admin.h:103
Company::GetMaxLoan
Money GetMaxLoan() const
Calculate the max allowed loan for this company.
Definition: company_cmd.cpp:102
ShowBuyCompanyDialog
void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
Show the query to buy another company.
Definition: company_gui.cpp:2775
WC_INCOME_GRAPH
@ WC_INCOME_GRAPH
Income graph; Window numbers:
Definition: window_type.h:534
stdafx.h
Company::IsHumanID
static bool IsHumanID(size_t index)
Is this company a company not controlled by a NoAI program?
Definition: company_base.h:163
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
NetworkAdminCompanyRemove
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Notify the admin network of a company to be removed (including the reason why).
Definition: network_admin.cpp:897
GroupStatistics::num_vehicle
uint16_t num_vehicle
Number of vehicles.
Definition: group.h:28
WC_LINKGRAPH_LEGEND
@ WC_LINKGRAPH_LEGEND
Linkgraph legend; Window numbers:
Definition: window_type.h:687
CheckCompanyHasMoney
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
Definition: company_cmd.cpp:238
CompanyAdminRemove
void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
Called whenever a company is removed in order to notify admins.
Definition: company_cmd.cpp:847
CompanyProperties::bankrupt_asked
CompanyMask bankrupt_asked
which companies were asked about buying it?
Definition: company_base.h:82
NetworkClientInfo::client_id
ClientID client_id
Client identifier (same as ClientState->client_id)
Definition: network_base.h:25
DESTTYPE_TEAM
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition: network_type.h:93
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:158
_economy_companies_yearly
static IntervalTimer< TimerGameEconomy > _economy_companies_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::COMPANY}, [](auto) { for(Company *c :Company::Iterate()) { std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses)+1, std::rend(c->yearly_expenses));c->yearly_expenses[0]={};SetWindowDirty(WC_FINANCES, c->index);} if(_settings_client.gui.show_finances &&_local_company !=COMPANY_SPECTATOR) { ShowCompanyFinances(_local_company);Company *c=Company::Get(_local_company);if(c->num_valid_stat_ent > 5 &&c->old_economy[0].performance_history< c->old_economy[4].performance_history) { if(_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);} else { if(_settings_client.sound.new_year) SndPlayFx(SND_00_GOOD_YEAR);} } })
A year has passed, update the economic data of all companies, and perhaps show the financial overview...
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:65
_colour_sort
static const byte _colour_sort[COLOUR_END]
Sorting weights for the company colours.
Definition: company_cmd.cpp:449
NetworkAdminCompanyUpdate
void NetworkAdminCompanyUpdate(const Company *company)
Notify the admin network of company updates.
Definition: network_admin.cpp:881
_company_pool
CompanyPool _company_pool("Company")
Pool of companies.
WC_COMPANY_VALUE
@ WC_COMPANY_VALUE
Company value graph; Window numbers:
Definition: window_type.h:558
IsUniqueCompanyName
static bool IsUniqueCompanyName(const std::string &name)
Is the given name in use as name of a company?
Definition: company_cmd.cpp:1097
CCA_NEW
@ CCA_NEW
Create a new company.
Definition: company_type.h:68
CompanyEconomyEntry::expenses
Money expenses
The amount of expenses.
Definition: company_base.h:26
CompanyProperties::inaugurated_year
TimerGameEconomy::Year inaugurated_year
Economy year of starting the company.
Definition: company_base.h:79
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
vehicle_func.h
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:619
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:384
TimeoutTimer
A timeout timer will fire once after the interval.
Definition: timer.h:116
CompanyNewsInformation
Data that needs to be stored for company news messages.
Definition: news_type.h:161
strings_func.h
CompanyEconomyEntry::performance_history
int32_t performance_history
Company score (scale 0-1000)
Definition: company_base.h:28
TimerGameEconomy::year
static Year year
Current year, starting at 0.
Definition: timer_game_economy.h:35
Pool
Base class for all pools.
Definition: pool_type.hpp:80
CompanyInfrastructure::GetTramTotal
uint32_t GetTramTotal() const
Get total sum of all owned tram bits.
Definition: company_cmd.cpp:1219
CompanyProperties::cur_economy
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition: company_base.h:98
ClientID
ClientID
'Unique' identifier to be given to clients
Definition: network_type.h:49
WC_PERFORMANCE_DETAIL
@ WC_PERFORMANCE_DETAIL
Performance detail window; Window numbers:
Definition: window_type.h:576
VehicleSettings::max_trains
UnitID max_trains
max trains in game per company
Definition: settings_type.h:524
Pool::PoolItem<&_company_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:365
GetCompanyRailTypes
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition: rail.cpp:251
Economy::inflation_prices
uint64_t inflation_prices
Cumulated inflation of prices since game start; 16 bit fractional part.
Definition: economy_type.h:51
DifficultySettings::infinite_money
bool infinite_money
whether spending money despite negative balance is allowed
Definition: settings_type.h:117
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
CompanyProperties::yearly_expenses
std::array< Expenses, 3 > yearly_expenses
Expenses of the company for the last three years.
Definition: company_base.h:97
GUISettings::show_finances
bool show_finances
show finances at end of year
Definition: settings_type.h:135
GetDrawStringCompanyColour
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
Definition: company_cmd.cpp:146
_company_manager_face
CompanyManagerFace _company_manager_face
for company manager face storage in openttd.cfg
Definition: company_cmd.cpp:52
CRR_NONE
@ CRR_NONE
Dummy reason for actions that don't need one.
Definition: company_type.h:63
NF_COMPANY
@ NF_COMPANY
Company news item. (Newspaper with face)
Definition: news_type.h:83
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition: company_cmd.cpp:1190
NetworkServerNewCompany
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci)
Perform all the server specific administration of a new company.
Definition: network_server.cpp:2223
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3217
CompanyNewsInformation::face
uint32_t face
The face of the president.
Definition: news_type.h:166
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition: window_type.h:485
Livery::colour1
Colours colour1
First colour, for all vehicles.
Definition: livery.h:80
Pool::PoolItem<&_company_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:314
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
AddNewsItem
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32_t ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32_t ref2=UINT32_MAX, const NewsAllocatedData *data=nullptr)
Add a new newsitem to be shown.
Definition: news_gui.cpp:827
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
CompanyInfrastructure::GetRoadTotal
uint32_t GetRoadTotal() const
Get total sum of all owned road bits.
Definition: company_cmd.cpp:1206
NetworkSettings::max_companies
uint8_t max_companies
maximum amount of companies
Definition: settings_type.h:326
Pool::PoolItem<&_company_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:305
ScriptInfo::name
std::string name
Full name of the script.
Definition: script_info.hpp:147
GetFirstPlayableCompanyID
CompanyID GetFirstPlayableCompanyID()
Get the index of the first available company.
Definition: company_cmd.cpp:1279
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:388
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:25
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
CompanyCtrlAction
CompanyCtrlAction
The action to do with CMD_COMPANY_CTRL.
Definition: company_type.h:67
SubtractMoneyFromAnyCompany
static void SubtractMoneyFromAnyCompany(Company *c, const CommandCost &cost)
Deduct costs of a command from the money of a company.
Definition: company_cmd.cpp:257
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:50
EXPENSES_PROPERTY
@ EXPENSES_PROPERTY
Property costs.
Definition: economy_type.h:179
DoStartupNewCompany
Company * DoStartupNewCompany(bool is_ai, CompanyID company=INVALID_COMPANY)
Create a new company and sets all company variables default values.
Definition: company_cmd.cpp:582
DifficultySettings::max_no_competitors
byte max_no_competitors
the number of competitors (AIs)
Definition: settings_type.h:99
ConstructionSettings::build_object_frame_burst
uint16_t build_object_frame_burst
how many tiles may, over a short period, be purchased or have objects built on them?
Definition: settings_type.h:394
VehicleDefaultSettings::servint_trains
uint16_t servint_trains
service interval for trains
Definition: settings_type.h:601
company_func.h
VehicleSettings::max_roadveh
UnitID max_roadveh
max trucks in game per company
Definition: settings_type.h:525
CompanyNewsInformation::CompanyNewsInformation
CompanyNewsInformation(const struct Company *c, const struct Company *other=nullptr)
Fill the CompanyNewsInformation struct with the required data.
Definition: company_cmd.cpp:814
ConstructionSettings::clear_per_64k_frames
uint32_t clear_per_64k_frames
how many tiles may, over a long period, be cleared per 65536 frames?
Definition: settings_type.h:389
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:225
Ticks::TICKS_PER_SECOND
static constexpr TimerGameTick::Ticks TICKS_PER_SECOND
Estimation of how many ticks fit in a single second.
Definition: timer_game_tick.h:49
CompanyEconomyEntry::income
Money income
The amount of income.
Definition: company_base.h:25
network.h
CompanyProperties::president_name_1
StringID president_name_1
Name of the president if the user did not change it.
Definition: company_base.h:61
VehicleDefaultSettings::servint_ships
uint16_t servint_ships
service interval for ships
Definition: settings_type.h:604
CheckTileOwnership
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Definition: company_cmd.cpp:378
CommandHelper
Definition: command_func.h:93
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition: window_type.h:503
Company::~Company
~Company()
Destructor.
Definition: company_cmd.cpp:77
SND_01_BAD_YEAR
@ SND_01_BAD_YEAR
40 == 0x28 New year: performance declined
Definition: sound_type.h:79
window_func.h
Town
Town data structure.
Definition: town.h:50
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1552
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:637
EXPENSES_TRAIN_RUN
@ EXPENSES_TRAIN_RUN
Running costs trains.
Definition: economy_type.h:175
OverflowSafeInt< int64_t >
UpdateCompanyLiveries
void UpdateCompanyLiveries(Company *c)
Update liveries for a company.
Definition: company_cmd.cpp:996
CRR_END
@ CRR_END
Sentinel for end.
Definition: company_type.h:61
IsInteractiveCompany
bool IsInteractiveCompany(CompanyID company)
Is the user representing company?
Definition: company_func.h:57
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
SND_00_GOOD_YEAR
@ SND_00_GOOD_YEAR
39 == 0x27 New year: performance improved
Definition: sound_type.h:78
INITIAL_LOAN
static const int64_t INITIAL_LOAN
The size of loan for a new company, in British Pounds!
Definition: economy_type.h:217
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:58
OWNER_END
@ OWNER_END
Last + 1 owner.
Definition: company_type.h:28
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition: settings_type.h:638
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:620
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:627
IsUniquePresidentName
static bool IsUniquePresidentName(const std::string &name)
Is the given name in use as president name of a company?
Definition: company_cmd.cpp:1140
Ticks::DAY_TICKS
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Definition: timer_game_tick.h:48
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
GetAvailableMoney
Money GetAvailableMoney(CompanyID company)
Get the amount of money that a company has available, or INT64_MAX if there is no such valid company.
Definition: company_cmd.cpp:213
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:324
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:64
ConstructionSettings::terraform_frame_burst
uint16_t terraform_frame_burst
how many tile heights may, over a short period, be terraformed?
Definition: settings_type.h:388
GE_WM
@ GE_WM
A male of Caucasian origin (white)
Definition: company_manager_face.h:23
SubtractMoneyFromCompany
void SubtractMoneyFromCompany(const CommandCost &cost)
Subtract money from the _current_company, if the company is valid.
Definition: company_cmd.cpp:286
CloseConstructionWindows
void CloseConstructionWindows()
Close all windows that are used for construction of vehicle etc.
Definition: window.cpp:3286
AI::Stop
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition: ai_core.cpp:103
WC_FINANCES
@ WC_FINANCES
Finances of a company; Window numbers:
Definition: window_type.h:528
network_admin.h
OnTick_Companies
void OnTick_Companies()
Called every tick for updating some company info.
Definition: company_cmd.cpp:748
WN_NETWORK_STATUS_WINDOW_JOIN
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
Definition: window_type.h:39
pool_func.hpp
GenerateCompanyColour
static Colours GenerateCompanyColour()
Generate a company colour.
Definition: company_cmd.cpp:474
WC_ERRMSG
@ WC_ERRMSG
Error message; Window numbers:
Definition: window_type.h:110
WC_OPERATING_PROFIT
@ WC_OPERATING_PROFIT
Operating profit graph; Window numbers:
Definition: window_type.h:540
WC_SCRIPT_SETTINGS
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
Definition: window_type.h:175
story_base.h
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition: company_type.h:70
WC_SCRIPT_LIST
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
Definition: window_type.h:284
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Company
Definition: company_base.h:116
IsLocalCompany
bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:47
ChangeOwnershipOfCompanyItems
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
Change the ownership of all the items of a company.
Definition: economy.cpp:334
Town::name
std::string name
Custom town name. If empty, the town was not renamed and uses the generated name.
Definition: town.h:59
Livery::colour2
Colours colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:81
RandomCompanyManagerFaceBits
void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv, Randomizer &randomizer)
Make a random new face.
Definition: company_manager_face.h:206
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:58
CompanyProperties::old_economy
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition: company_base.h:99
SetWindowWidgetDirty
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Definition: window.cpp:3095
OWNED_BY_OWNER_IN_PARAMETERS_OFFSET
static const int OWNED_BY_OWNER_IN_PARAMETERS_OFFSET
The index in the parameters for the owner information.
Definition: company_func.h:20
EXPENSES_ROADVEH_REVENUE
@ EXPENSES_ROADVEH_REVENUE
Revenue from road vehicles.
Definition: economy_type.h:181
ROADTYPE_BEGIN
@ ROADTYPE_BEGIN
Used for iterations.
Definition: road_type.h:26
NT_COMPANY_INFO
@ NT_COMPANY_INFO
Company info (new companies, bankruptcy messages)
Definition: news_type.h:28
VehicleDefaultSettings::servint_roadveh
uint16_t servint_roadveh
service interval for road vehicles
Definition: settings_type.h:602
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition: window_type.h:104
UpdateLandscapingLimits
void UpdateLandscapingLimits()
Update the landscaping limits per company.
Definition: company_cmd.cpp:315
EXPENSES_AIRCRAFT_REVENUE
@ EXPENSES_AIRCRAFT_REVENUE
Revenue from aircraft.
Definition: economy_type.h:182
network_func.h
UpdateCompanyGroupLiveries
void UpdateCompanyGroupLiveries(const Company *c)
Update group liveries for a company.
Definition: group_cmd.cpp:311
NetworkClientInfo
Container for all information known about a client.
Definition: network_base.h:24
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:178
EXPENSES_LOAN_INTEREST
@ EXPENSES_LOAN_INTEREST
Interest payments over the loan.
Definition: economy_type.h:184
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
_new_competitor_timeout
TimeoutTimer< TimerGameTick > _new_competitor_timeout(0, []() { if(_game_mode==GM_MENU||!AI::CanStartNew()) return;if(_networking &&Company::GetNumItems() >=_settings_client.network.max_companies) return;uint8_t n=0;for(const Company *c :Company::Iterate()) { if(c->is_ai) n++;} if(n >=_settings_game.difficulty.max_no_competitors) return;Command< CMD_COMPANY_CTRL >::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID);})
Start a new competitor company if possible.
CompanyRemoveReason
CompanyRemoveReason
The reason why the company was removed.
Definition: company_type.h:56
timer_game_economy.h
ResetCompanyLivery
void ResetCompanyLivery(Company *c)
Reset the livery schemes to the company's primary colour.
Definition: company_cmd.cpp:558
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
CmdRenameCompany
CommandCost CmdRenameCompany(DoCommandFlag flags, const std::string &text)
Change the name of the company.
Definition: company_cmd.cpp:1112
CompanyProperties::name_1
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:58
EXPENSES_SHIP_REVENUE
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition: economy_type.h:183
news_func.h
CompanyProperties::max_loan
Money max_loan
Max allowed amount of the loan or COMPANY_MAX_LOAN_DEFAULT.
Definition: company_base.h:70
CmdRenamePresident
CommandCost CmdRenamePresident(DoCommandFlag flags, const std::string &text)
Change the name of the president.
Definition: company_cmd.cpp:1155
ConstructionSettings::terraform_per_64k_frames
uint32_t terraform_per_64k_frames
how many tile heights may, over a long period, be terraformed per 65536 frames?
Definition: settings_type.h:387
backup_type.hpp
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103