OpenTTD Source: src/company_cmd.cpp Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 "ai/ai_instance.hpp"
24#include "ai/ai_config.hpp"
25#include "company_manager_face.h"
26#include "window_func.h"
27#include "strings_func.h"
28#include "sound_func.h"
29#include "rail.h"
30#include "core/pool_func.hpp"
31#include "core/string_consumer.hpp"
32#include "settings_func.h"
33#include "vehicle_base.h"
34#include "vehicle_func.h"
35#include "smallmap_gui.h"
36#include "game/game.hpp"
37#include "goal_base.h"
38#include "story_base.h"
39#include "company_cmd.h"
40#include "timer/timer.h"
41#include "timer/timer_game_economy.h"
42#include "timer/timer_game_tick.h"
43#include "timer/timer_window.h"
44
45#include "widgets/statusbar_widget.h"
46
47#include "table/strings.h"
48#include "table/company_face.h"
49
50#include "safeguards.h"
51
52void ClearEnginesHiddenFlagOfCompany(CompanyID cid);
53void UpdateObjectColours(const Company *c);
54
55 CompanyID _local_company;
56 CompanyID _current_company;
57 TypedIndexContainer<std::array<Colours, MAX_COMPANIES>, CompanyID> _company_colours;
58std::string _company_manager_face;
59uint _cur_company_tick_index;
60
61 CompanyPool _company_pool("Company");
62 INSTANTIATE_POOL_METHODS(Company)
63
64
69 Company::Company(StringID name_1, bool is_ai)
70{
71 this->name_1 = name_1;
72 this->is_ai = is_ai;
73 this->terraform_limit = (uint32_t)_settings_game.construction.terraform_frame_burst << 16;
74 this->clear_limit = (uint32_t)_settings_game.construction.clear_frame_burst << 16;
75 this->tree_limit = (uint32_t)_settings_game.construction.tree_frame_burst << 16;
76 this->build_object_limit = (uint32_t)_settings_game.construction.build_object_frame_burst << 16;
77
78 InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, CompanyID::Invalid());
79}
80
82Company::~Company()
83{
84 if (CleaningPool()) return;
85
86 CloseCompanyWindows(this->index);
87}
88
93 void Company::PostDestructor(size_t index)
94{
95 InvalidateWindowData(WC_GRAPH_LEGEND, 0, (int)index);
96 InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, (int)index);
97 InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
98 InvalidateWindowData(WC_LINKGRAPH_LEGEND, 0);
99 /* If the currently shown error message has this company in it, then close it. */
100 InvalidateWindowData(WC_ERRMSG, 0);
101}
102
107 Money Company::GetMaxLoan() const
108{
109 if (this->max_loan == COMPANY_MAX_LOAN_DEFAULT) return _economy.max_loan;
110 return this->max_loan;
111}
112
119 void SetLocalCompany(CompanyID new_company)
120{
121 /* company could also be COMPANY_SPECTATOR or OWNER_NONE */
122 assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);
123
124 /* If actually changing to another company, several windows need closing */
125 bool switching_company = _local_company != new_company;
126
127 /* Delete the chat window, if you were team chatting. */
128 if (switching_company) InvalidateWindowData(WC_SEND_NETWORK_MSG, DESTTYPE_TEAM, _local_company);
129
130 assert(IsLocalCompany());
131
132 _current_company = _local_company = new_company;
133
134 if (switching_company) {
135 InvalidateWindowClassesData(WC_COMPANY);
136 /* Delete any construction windows... */
137 CloseConstructionWindows();
138 }
139
140 /* ... and redraw the whole screen. */
141 MarkWholeScreenDirty();
142 InvalidateWindowClassesData(WC_SIGN_LIST, -1);
143 InvalidateWindowClassesData(WC_GOALS_LIST);
144 InvalidateWindowClassesData(WC_COMPANY_COLOUR, -1);
145 ResetVehicleColourMap();
146}
147
153 TextColour GetDrawStringCompanyColour(CompanyID company)
154{
155 if (!Company::IsValidID(company)) return GetColourGradient(COLOUR_WHITE, SHADE_NORMAL).ToTextColour();
156 return GetColourGradient(_company_colours[company], SHADE_NORMAL).ToTextColour();
157}
158
164 PaletteID GetCompanyPalette(CompanyID company)
165{
166 return GetColourPalette(_company_colours[company]);
167}
168
175 void DrawCompanyIcon(CompanyID c, int x, int y)
176{
177 DrawSprite(SPR_COMPANY_ICON, GetCompanyPalette(c), x, y);
178}
179
186 static bool IsValidCompanyManagerFace(CompanyManagerFace cmf)
187{
188 if (cmf.style >= GetNumCompanyManagerFaceStyles()) return false;
189
190 /* Test if each enabled part is valid. */
191 FaceVars vars = GetCompanyManagerFaceVars(cmf.style);
192 for (uint var : SetBitIterator(GetActiveFaceVars(cmf, vars))) {
193 if (!vars[var].IsValid(cmf)) return false;
194 }
195
196 return true;
197}
198
199 static CompanyMask _dirty_company_finances{};
200
206 void InvalidateCompanyWindows(const Company *company)
207{
208 CompanyID cid = company->index;
209 _dirty_company_finances.Set(cid);
210}
211
215 static const IntervalTimer<TimerWindow> invalidate_company_windows_interval(std::chrono::milliseconds(1), [](auto) {
216 for (CompanyID cid : _dirty_company_finances) {
217 if (cid == _local_company) SetWindowWidgetDirty(WC_STATUS_BAR, 0, WID_S_RIGHT);
218 Window *w = FindWindowById(WC_FINANCES, cid);
219 if (w != nullptr) {
220 w->SetWidgetDirty(WID_CF_EXPS_PRICE3);
221 w->SetWidgetDirty(WID_CF_OWN_VALUE);
222 w->SetWidgetDirty(WID_CF_LOAN_VALUE);
223 w->SetWidgetDirty(WID_CF_BALANCE_VALUE);
224 w->SetWidgetDirty(WID_CF_MAXLOAN_VALUE);
225 }
226 SetWindowWidgetDirty(WC_COMPANY, cid, WID_C_DESC_COMPANY_VALUE);
227 }
228 _dirty_company_finances.Reset();
229});
230
238 Money GetAvailableMoney(CompanyID company)
239{
240 if (_settings_game.difficulty.infinite_money) return INT64_MAX;
241 if (!Company::IsValidID(company)) return INT64_MAX;
242 return Company::Get(company)->money;
243}
244
252 Money GetAvailableMoneyForCommand()
253{
254 return GetAvailableMoney(_current_company);
255}
256
263 bool CheckCompanyHasMoney(CommandCost &cost)
264{
265 if (cost.GetCost() <= 0) return true;
266 if (_settings_game.difficulty.infinite_money) return true;
267
268 const Company *c = Company::GetIfValid(_current_company);
269 if (c != nullptr && cost.GetCost() > c->money) {
270 cost.MakeError(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
271 if (IsLocalCompany()) {
272 cost.SetEncodedMessage(GetEncodedString(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY, cost.GetCost()));
273 }
274 return false;
275 }
276 return true;
277}
278
284 static void SubtractMoneyFromAnyCompany(Company *c, const CommandCost &cost)
285{
286 if (cost.GetCost() == 0) return;
287 assert(cost.GetExpensesType() != INVALID_EXPENSES);
288
289 c->money -= cost.GetCost();
290 c->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost();
291
292 if (HasBit(1 << EXPENSES_TRAIN_REVENUE |
293 1 << EXPENSES_ROADVEH_REVENUE |
294 1 << EXPENSES_AIRCRAFT_REVENUE |
295 1 << EXPENSES_SHIP_REVENUE, cost.GetExpensesType())) {
296 c->cur_economy.income -= cost.GetCost();
297 } else if (HasBit(1 << EXPENSES_TRAIN_RUN |
298 1 << EXPENSES_ROADVEH_RUN |
299 1 << EXPENSES_AIRCRAFT_RUN |
300 1 << EXPENSES_SHIP_RUN |
301 1 << EXPENSES_PROPERTY |
302 1 << EXPENSES_LOAN_INTEREST, cost.GetExpensesType())) {
303 c->cur_economy.expenses -= cost.GetCost();
304 }
305
306 InvalidateCompanyWindows(c);
307}
308
313 void SubtractMoneyFromCompany(const CommandCost &cost)
314{
315 Company *c = Company::GetIfValid(_current_company);
316 if (c != nullptr) SubtractMoneyFromAnyCompany(c, cost);
317}
318
324 void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
325{
326 Company *c = Company::Get(company);
327 uint8_t m = c->money_fraction;
328 Money cost = cst.GetCost();
329
330 c->money_fraction = m - (uint8_t)cost;
331 cost >>= 8;
332 if (c->money_fraction > m) cost++;
333 if (cost != 0) SubtractMoneyFromAnyCompany(c, CommandCost(cst.GetExpensesType(), cost));
334}
335
336static constexpr void UpdateLandscapingLimit(uint32_t &limit, uint64_t per_64k_frames, uint64_t burst)
337{
338 limit = static_cast<uint32_t>(std::min<uint64_t>(limit + per_64k_frames, burst << 16));
339}
340
342 void UpdateLandscapingLimits()
343{
344 for (Company *c : Company::Iterate()) {
345 UpdateLandscapingLimit(c->terraform_limit, _settings_game.construction.terraform_per_64k_frames, _settings_game.construction.terraform_frame_burst);
346 UpdateLandscapingLimit(c->clear_limit, _settings_game.construction.clear_per_64k_frames, _settings_game.construction.clear_frame_burst);
347 UpdateLandscapingLimit(c->tree_limit, _settings_game.construction.tree_per_64k_frames, _settings_game.construction.tree_frame_burst);
348 UpdateLandscapingLimit(c->build_object_limit, _settings_game.construction.build_object_per_64k_frames, _settings_game.construction.build_object_frame_burst);
349 }
350}
351
358std::array<StringParameter, 2> GetParamsForOwnedBy(Owner owner, TileIndex tile)
359{
360 if (owner == OWNER_TOWN) {
361 assert(tile != 0);
362 const Town *t = ClosestTownFromTile(tile, UINT_MAX);
363 return {STR_TOWN_NAME, t->index};
364 }
365
366 if (!Company::IsValidID(owner)) {
367 return {STR_COMPANY_SOMEONE, std::monostate{}};
368 }
369
370 return {STR_COMPANY_NAME, owner};
371}
372
381 CommandCost CheckOwnership(Owner owner, TileIndex tile)
382{
383 assert(owner < OWNER_END);
384 assert(owner != OWNER_TOWN || tile != 0);
385
386 if (owner == _current_company) return CommandCost();
387
388 CommandCost error{STR_ERROR_OWNED_BY};
389 if (IsLocalCompany()) {
390 auto params = GetParamsForOwnedBy(owner, tile);
391 error.SetEncodedMessage(GetEncodedStringWithArgs(STR_ERROR_OWNED_BY, params));
392 if (owner != OWNER_TOWN) error.SetErrorOwner(owner);
393 }
394 return error;
395}
396
404 CommandCost CheckTileOwnership(TileIndex tile)
405{
406 return CheckOwnership(GetTileOwner(tile), tile);
407}
408
413 static void GenerateCompanyName(Company *c)
414{
415 if (c->name_1 != STR_SV_UNNAMED) return;
416 if (c->last_build_coordinate == 0) return;
417
418 Town *t = ClosestTownFromTile(c->last_build_coordinate, UINT_MAX);
419
420 StringID str;
421 uint32_t strp;
422 std::string name;
423 if (t->name.empty() && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_END)) {
424 str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START;
425 strp = t->townnameparts;
426
427verify_name:;
428 /* No companies must have this name already */
429 for (const Company *cc : Company::Iterate()) {
430 if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name;
431 }
432
433 name = GetString(str, strp);
434 if (Utf8StringLength(name) >= MAX_LENGTH_COMPANY_NAME_CHARS) goto bad_town_name;
435
436set_name:;
437 c->name_1 = str;
438 c->name_2 = strp;
439
440 MarkWholeScreenDirty();
441 AI::BroadcastNewEvent(new ScriptEventCompanyRenamed(c->index, name));
442 Game::NewEvent(new ScriptEventCompanyRenamed(c->index, name));
443
444 if (c->is_ai) {
445 auto cni = std::make_unique<CompanyNewsInformation>(STR_NEWS_COMPANY_LAUNCH_TITLE, c);
446 EncodedString headline = GetEncodedString(STR_NEWS_COMPANY_LAUNCH_DESCRIPTION, cni->company_name, t->index);
447 AddNewsItem(std::move(headline),
448 NewsType::CompanyInfo, NewsStyle::Company, {}, c->last_build_coordinate, {}, std::move(cni));
449 }
450 return;
451 }
452bad_town_name:;
453
454 if (c->president_name_1 == SPECSTR_PRESIDENT_NAME) {
455 str = SPECSTR_ANDCO_NAME;
456 strp = c->president_name_2;
457 name = GetString(str, strp);
458 goto set_name;
459 } else {
460 str = SPECSTR_ANDCO_NAME;
461 strp = Random();
462 goto verify_name;
463 }
464}
465
467 static const uint8_t _colour_sort[COLOUR_END] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1};
469 static const Colours _similar_colour[COLOUR_END][2] = {
470 { COLOUR_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_DARK_BLUE
471 { COLOUR_GREEN, COLOUR_DARK_GREEN }, // COLOUR_PALE_GREEN
472 { INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_PINK
473 { COLOUR_ORANGE, INVALID_COLOUR }, // COLOUR_YELLOW
474 { INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_RED
475 { COLOUR_DARK_BLUE, COLOUR_BLUE }, // COLOUR_LIGHT_BLUE
476 { COLOUR_PALE_GREEN, COLOUR_DARK_GREEN }, // COLOUR_GREEN
477 { COLOUR_PALE_GREEN, COLOUR_GREEN }, // COLOUR_DARK_GREEN
478 { COLOUR_DARK_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_BLUE
479 { COLOUR_BROWN, COLOUR_ORANGE }, // COLOUR_CREAM
480 { COLOUR_PURPLE, INVALID_COLOUR }, // COLOUR_MAUVE
481 { COLOUR_MAUVE, INVALID_COLOUR }, // COLOUR_PURPLE
482 { COLOUR_YELLOW, COLOUR_CREAM }, // COLOUR_ORANGE
483 { COLOUR_CREAM, INVALID_COLOUR }, // COLOUR_BROWN
484 { COLOUR_WHITE, INVALID_COLOUR }, // COLOUR_GREY
485 { COLOUR_GREY, INVALID_COLOUR }, // COLOUR_WHITE
486};
487
492 static Colours GenerateCompanyColour()
493{
494 Colours colours[COLOUR_END];
495
496 /* Initialize array */
497 for (uint i = 0; i < COLOUR_END; i++) colours[i] = static_cast<Colours>(i);
498
499 /* And randomize it */
500 for (uint i = 0; i < 100; i++) {
501 uint r = Random();
502 std::swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]);
503 }
504
505 /* Bubble sort it according to the values in table 1 */
506 for (uint i = 0; i < COLOUR_END; i++) {
507 for (uint j = 1; j < COLOUR_END; j++) {
508 if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) {
509 std::swap(colours[j - 1], colours[j]);
510 }
511 }
512 }
513
514 /* Move the colours that look similar to each company's colour to the side */
515 for (const Company *c : Company::Iterate()) {
516 Colours pcolour = c->colour;
517
518 for (uint i = 0; i < COLOUR_END; i++) {
519 if (colours[i] == pcolour) {
520 colours[i] = INVALID_COLOUR;
521 break;
522 }
523 }
524
525 for (uint j = 0; j < 2; j++) {
526 Colours similar = _similar_colour[pcolour][j];
527 if (similar == INVALID_COLOUR) break;
528
529 for (uint i = 1; i < COLOUR_END; i++) {
530 if (colours[i - 1] == similar) std::swap(colours[i - 1], colours[i]);
531 }
532 }
533 }
534
535 /* Return the first available colour */
536 for (uint i = 0; i < COLOUR_END; i++) {
537 if (colours[i] != INVALID_COLOUR) return colours[i];
538 }
539
540 NOT_REACHED();
541}
542
547 static void GeneratePresidentName(Company *c)
548{
549 for (;;) {
550restart:;
551 c->president_name_2 = Random();
552 c->president_name_1 = SPECSTR_PRESIDENT_NAME;
553
554 /* Reserve space for extra unicode character. We need to do this to be able
555 * to detect too long president name. */
556 std::string name = GetString(STR_PRESIDENT_NAME, c->index);
557 if (Utf8StringLength(name) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue;
558
559 for (const Company *cc : Company::Iterate()) {
560 if (c != cc) {
561 std::string other_name = GetString(STR_PRESIDENT_NAME, cc->index);
562 if (name == other_name) goto restart;
563 }
564 }
565 return;
566 }
567}
568
574 void ResetCompanyLivery(Company *c)
575{
576 for (LiveryScheme scheme = LS_BEGIN; scheme < LS_END; scheme++) {
577 c->livery[scheme].in_use.Reset();
578 c->livery[scheme].colour1 = c->colour;
579 c->livery[scheme].colour2 = c->colour;
580 }
581
582 for (Group *g : Group::Iterate()) {
583 if (g->owner == c->index) {
584 g->livery.in_use.Reset();
585 g->livery.colour1 = c->colour;
586 g->livery.colour2 = c->colour;
587 }
588 }
589}
590
598 Company *DoStartupNewCompany(bool is_ai, CompanyID company = CompanyID::Invalid())
599{
600 if (!Company::CanAllocateItem()) return nullptr;
601
602 /* we have to generate colour before this company is valid */
603 Colours colour = GenerateCompanyColour();
604
605 Company *c;
606 if (company == CompanyID::Invalid()) {
607 c = new Company(STR_SV_UNNAMED, is_ai);
608 } else {
609 if (Company::IsValidID(company)) return nullptr;
610 c = new (company) Company(STR_SV_UNNAMED, is_ai);
611 }
612
613 c->colour = colour;
614
615 ResetCompanyLivery(c);
616 _company_colours[c->index] = c->colour;
617
618 /* Scale the initial loan based on the inflation rounded down to the loan interval. The maximum loan has already been inflation adjusted. */
619 c->money = c->current_loan = std::min<int64_t>((INITIAL_LOAN * _economy.inflation_prices >> 16) / LOAN_INTERVAL * LOAN_INTERVAL, _economy.max_loan);
620
621 c->avail_railtypes = GetCompanyRailTypes(c->index);
622 c->avail_roadtypes = GetCompanyRoadTypes(c->index);
623 c->inaugurated_year = TimerGameEconomy::year;
624 c->inaugurated_year_calendar = TimerGameCalendar::year;
625
626 /* If starting a player company in singleplayer and a favourite company manager face is selected, choose it. Otherwise, use a random face.
627 * In a network game, we'll choose the favourite face later in CmdCompanyCtrl to sync it to all clients. */
628 bool randomise_face = true;
629 if (!_company_manager_face.empty() && !is_ai && !_networking) {
630 auto cmf = ParseCompanyManagerFaceCode(_company_manager_face);
631 if (cmf.has_value()) {
632 randomise_face = false;
633 c->face = std::move(*cmf);
634 }
635 }
636 if (randomise_face) RandomiseCompanyManagerFace(c->face, _random);
637
638 SetDefaultCompanySettings(c->index);
639 ClearEnginesHiddenFlagOfCompany(c->index);
640
641 GeneratePresidentName(c);
642
643 SetWindowDirty(WC_GRAPH_LEGEND, 0);
644 InvalidateWindowData(WC_CLIENT_LIST, 0);
645 InvalidateWindowData(WC_LINKGRAPH_LEGEND, 0);
646 BuildOwnerLegend();
647 InvalidateWindowData(WC_SMALLMAP, 0, 1);
648
649 if (is_ai && (!_networking || _network_server)) AI::StartNew(c->index);
650
651 AI::BroadcastNewEvent(new ScriptEventCompanyNew(c->index), c->index);
652 Game::NewEvent(new ScriptEventCompanyNew(c->index));
653
654 return c;
655}
656
658 TimeoutTimer<TimerGameTick> _new_competitor_timeout({ TimerGameTick::Priority::COMPETITOR_TIMEOUT, 0 }, []() {
659 if (_game_mode == GM_MENU || !AI::CanStartNew()) return;
660 if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return;
661 if (_settings_game.difficulty.competitors_interval == 0) return;
662
663 /* count number of competitors */
664 uint8_t n = 0;
665 for (const Company *c : Company::Iterate()) {
666 if (c->is_ai) n++;
667 }
668
669 if (n >= _settings_game.difficulty.max_no_competitors) return;
670
671 /* Send a command to all clients to start up a new AI.
672 * Works fine for Multiplayer and Singleplayer */
673 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID);
674});
675
677 void StartupCompanies()
678{
679 /* Ensure the timeout is aborted, so it doesn't fire based on information of the last game. */
680 _new_competitor_timeout.Abort();
681}
682
684 void InitializeCompanies()
685{
686 _cur_company_tick_index = 0;
687}
688
695 bool CheckTakeoverVehicleLimit(CompanyID cbig, CompanyID csmall)
696{
697 const Company *c1 = Company::Get(cbig);
698 const Company *c2 = Company::Get(csmall);
699
700 /* Do the combined vehicle counts stay within the limits? */
701 return c1->group_all[VEH_TRAIN].num_vehicle + c2->group_all[VEH_TRAIN].num_vehicle <= _settings_game.vehicle.max_trains &&
702 c1->group_all[VEH_ROAD].num_vehicle + c2->group_all[VEH_ROAD].num_vehicle <= _settings_game.vehicle.max_roadveh &&
703 c1->group_all[VEH_SHIP].num_vehicle + c2->group_all[VEH_SHIP].num_vehicle <= _settings_game.vehicle.max_ships &&
704 c1->group_all[VEH_AIRCRAFT].num_vehicle + c2->group_all[VEH_AIRCRAFT].num_vehicle <= _settings_game.vehicle.max_aircraft;
705}
706
716 static void HandleBankruptcyTakeover(Company *c)
717{
718 /* Amount of time out for each company to take over a company;
719 * Timeout is a quarter (3 months of 30 days) divided over the
720 * number of companies. The minimum number of days in a quarter
721 * is 90: 31 in January, 28 in February and 31 in March.
722 * Note that the company going bankrupt can't buy itself. */
723 static const int TAKE_OVER_TIMEOUT = 3 * 30 * Ticks::DAY_TICKS / (MAX_COMPANIES - 1);
724
725 assert(c->bankrupt_asked.Any());
726
727 /* We're currently asking some company to buy 'us' */
728 if (c->bankrupt_timeout != 0) {
729 c->bankrupt_timeout -= MAX_COMPANIES;
730 if (c->bankrupt_timeout > 0) return;
731 c->bankrupt_timeout = 0;
732
733 return;
734 }
735
736 /* Did we ask everyone for bankruptcy? If so, bail out. */
737 if (c->bankrupt_asked.All()) return;
738
739 Company *best = nullptr;
740 int32_t best_performance = -1;
741
742 /* Ask the company with the highest performance history first */
743 for (Company *c2 : Company::Iterate()) {
744 if (c2->bankrupt_asked.None() && // Don't ask companies going bankrupt themselves
745 !c->bankrupt_asked.Test(c2->index) &&
746 best_performance < c2->old_economy[1].performance_history &&
747 CheckTakeoverVehicleLimit(c2->index, c->index)) {
748 best_performance = c2->old_economy[1].performance_history;
749 best = c2;
750 }
751 }
752
753 /* Asked all companies? */
754 if (best_performance == -1) {
755 c->bankrupt_asked.Set();
756 return;
757 }
758
759 c->bankrupt_asked.Set(best->index);
760
761 c->bankrupt_timeout = TAKE_OVER_TIMEOUT;
762
763 AI::NewEvent(best->index, new ScriptEventCompanyAskMerger(c->index, c->bankrupt_value));
764 if (IsInteractiveCompany(best->index)) {
765 ShowBuyCompanyDialog(c->index, false);
766 }
767}
768
770 void OnTick_Companies()
771{
772 if (_game_mode == GM_EDITOR) return;
773
774 Company *c = Company::GetIfValid(_cur_company_tick_index);
775 if (c != nullptr) {
776 if (c->name_1 != 0) GenerateCompanyName(c);
777 if (c->bankrupt_asked.Any()) HandleBankruptcyTakeover(c);
778 }
779
780 if (_new_competitor_timeout.HasFired() && _game_mode != GM_MENU && AI::CanStartNew()) {
781 int32_t timeout = _settings_game.difficulty.competitors_interval * 60 * Ticks::TICKS_PER_SECOND;
782 /* If the interval is zero, start as many competitors as needed then check every ~10 minutes if a company went bankrupt and needs replacing. */
783 if (timeout == 0) {
784 /* count number of competitors */
785 uint8_t num_ais = 0;
786 for (const Company *cc : Company::Iterate()) {
787 if (cc->is_ai) num_ais++;
788 }
789
790 size_t num_companies = Company::GetNumItems();
791 for (auto i = 0; i < _settings_game.difficulty.max_no_competitors; i++) {
792 if (_networking && num_companies++ >= _settings_client.network.max_companies) break;
793 if (num_ais++ >= _settings_game.difficulty.max_no_competitors) break;
794 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID);
795 }
796 timeout = 10 * 60 * Ticks::TICKS_PER_SECOND;
797 }
798 /* Randomize a bit when the AI is actually going to start; ranges from 87.5% .. 112.5% of indicated value. */
799 timeout += ScriptObject::GetRandomizer(OWNER_NONE).Next(timeout / 4) - timeout / 8;
800
801 _new_competitor_timeout.Reset({ TimerGameTick::Priority::COMPETITOR_TIMEOUT, static_cast<uint>(std::max(1, timeout)) });
802 }
803
804 _cur_company_tick_index = (_cur_company_tick_index + 1) % MAX_COMPANIES;
805}
806
811 static const IntervalTimer<TimerGameEconomy> _economy_companies_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::COMPANY}, [](auto)
812{
813 /* Copy statistics */
814 for (Company *c : Company::Iterate()) {
815 /* Move expenses to previous years. */
816 std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses));
817 c->yearly_expenses[0].fill(0);
818 InvalidateWindowData(WC_FINANCES, c->index);
819 }
820
821 if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
822 ShowCompanyFinances(_local_company);
823 Company *c = Company::Get(_local_company);
824 if (c->num_valid_stat_ent > 5 && c->old_economy[0].performance_history < c->old_economy[4].performance_history) {
825 if (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);
826 } else {
827 if (_settings_client.sound.new_year) SndPlayFx(SND_00_GOOD_YEAR);
828 }
829 }
830});
831
837CompanyNewsInformation::CompanyNewsInformation(StringID title, const Company *c, const Company *other)
838{
839 this->company_name = GetString(STR_COMPANY_NAME, c->index);
840
841 if (other != nullptr) {
842 this->other_company_name = GetString(STR_COMPANY_NAME, other->index);
843 c = other;
844 }
845
846 this->president_name = GetString(STR_PRESIDENT_NAME_MANAGER, c->index);
847
848 this->title = title;
849 this->colour = c->colour;
850 this->face = c->face;
851
852}
853
858 void CompanyAdminUpdate(const Company *company)
859{
860 if (_network_server) NetworkAdminCompanyUpdate(company);
861}
862
868 void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
869{
870 if (_network_server) NetworkAdminCompanyRemove(company_id, (AdminCompanyRemoveReason)reason);
871}
872
881 CommandCost CmdCompanyCtrl(DoCommandFlags flags, CompanyCtrlAction cca, CompanyID company_id, CompanyRemoveReason reason, ClientID client_id)
882{
883 InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
884
885 switch (cca) {
886 case CCA_NEW: { // Create a new company
887 /* This command is only executed in a multiplayer game */
888 if (!_networking) return CMD_ERROR;
889
890 /* Has the network client a correct ClientID? */
891 if (!flags.Test(DoCommandFlag::Execute)) return CommandCost();
892
893 NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
894
895 /* Delete multiplayer progress bar */
896 CloseWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
897
898 Company *c = DoStartupNewCompany(false);
899
900 /* A new company could not be created, revert to being a spectator */
901 if (c == nullptr) {
902 /* We check for "ci != nullptr" as a client could have left by
903 * the time we execute this command. */
904 if (_network_server && ci != nullptr) {
905 ci->client_playas = COMPANY_SPECTATOR;
906 NetworkUpdateClientInfo(ci->client_id);
907 }
908 break;
909 }
910
911 NetworkAdminCompanyNew(c);
912 NetworkServerNewCompany(c, ci);
913
914 /* This is the client (or non-dedicated server) who wants a new company */
915 if (client_id == _network_own_client_id) {
916 assert(_local_company == COMPANY_SPECTATOR);
917 SetLocalCompany(c->index);
918
919 /*
920 * If a favourite company manager face is selected, choose it. Otherwise, use a random face.
921 * Because this needs to be synchronised over the network, only the client knows
922 * its configuration and we are currently in the execution of a command, we have
923 * to circumvent the normal ::Post logic for commands and just send the command.
924 */
925 if (!_company_manager_face.empty()) {
926 auto cmf = ParseCompanyManagerFaceCode(_company_manager_face);
927 if (cmf.has_value()) {
928 Command<CMD_SET_COMPANY_MANAGER_FACE>::SendNet(STR_NULL, c->index, cmf->style, cmf->bits);
929 }
930 }
931
932 /* Now that we have a new company, broadcast our company settings to
933 * all clients so everything is in sync */
934 SyncCompanySettings();
935
936 MarkWholeScreenDirty();
937 }
938 break;
939 }
940
941 case CCA_NEW_AI: { // Make a new AI company
942 if (company_id != CompanyID::Invalid() && company_id >= MAX_COMPANIES) return CMD_ERROR;
943
944 /* For network games, company deletion is delayed. */
945 if (!_networking && company_id != CompanyID::Invalid() && Company::IsValidID(company_id)) return CMD_ERROR;
946
947 if (!flags.Test(DoCommandFlag::Execute)) return CommandCost();
948
949 /* For network game, just assume deletion happened. */
950 assert(company_id == CompanyID::Invalid() || !Company::IsValidID(company_id));
951
952 Company *c = DoStartupNewCompany(true, company_id);
953 if (c != nullptr) {
954 NetworkAdminCompanyNew(c);
955 NetworkServerNewCompany(c, nullptr);
956 }
957 break;
958 }
959
960 case CCA_DELETE: { // Delete a company
961 if (reason >= CRR_END) return CMD_ERROR;
962
963 /* We can't delete the last existing company in singleplayer mode. */
964 if (!_networking && Company::GetNumItems() == 1) return CMD_ERROR;
965
966 Company *c = Company::GetIfValid(company_id);
967 if (c == nullptr) return CMD_ERROR;
968
969 if (!flags.Test(DoCommandFlag::Execute)) return CommandCost();
970
971 /* Show the bankrupt news */
972 auto cni = std::make_unique<CompanyNewsInformation>(STR_NEWS_COMPANY_BANKRUPT_TITLE, c);
973 EncodedString headline = GetEncodedString(STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION, cni->company_name);
974 AddCompanyNewsItem(std::move(headline), std::move(cni));
975
976 /* Remove the company */
977 ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
978 if (c->is_ai) AI::Stop(c->index);
979
980 CompanyID c_index = c->index;
981 delete c;
982 AI::BroadcastNewEvent(new ScriptEventCompanyBankrupt(c_index));
983 Game::NewEvent(new ScriptEventCompanyBankrupt(c_index));
984 CompanyAdminRemove(c_index, (CompanyRemoveReason)reason);
985
986 if (StoryPage::GetNumItems() == 0 || Goal::GetNumItems() == 0) InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
987 InvalidateWindowData(WC_CLIENT_LIST, 0);
988
989 break;
990 }
991
992 default: return CMD_ERROR;
993 }
994
995 InvalidateWindowClassesData(WC_GAME_OPTIONS);
996 InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
997 InvalidateWindowClassesData(WC_SCRIPT_LIST);
998
999 return CommandCost();
1000}
1001
1002static bool ExecuteAllowListCtrlAction(CompanyAllowListCtrlAction action, Company *c, const std::string &public_key)
1003{
1004 switch (action) {
1005 case CALCA_ADD:
1006 return c->allow_list.Add(public_key);
1007
1008 case CALCA_REMOVE:
1009 return c->allow_list.Remove(public_key);
1010
1011 default:
1012 NOT_REACHED();
1013 }
1014}
1015
1023 CommandCost CmdCompanyAllowListCtrl(DoCommandFlags flags, CompanyAllowListCtrlAction action, const std::string &public_key)
1024{
1025 Company *c = Company::GetIfValid(_current_company);
1026 if (c == nullptr) return CMD_ERROR;
1027
1028 /* The public key length includes the '\0'. */
1029 if (public_key.size() != NETWORK_PUBLIC_KEY_LENGTH - 1) return CMD_ERROR;
1030
1031 switch (action) {
1032 case CALCA_ADD:
1033 case CALCA_REMOVE:
1034 break;
1035
1036 default:
1037 return CMD_ERROR;
1038 }
1039
1040 if (flags.Test(DoCommandFlag::Execute)) {
1041 if (ExecuteAllowListCtrlAction(action, c, public_key)) {
1042 InvalidateWindowData(WC_CLIENT_LIST, 0);
1043 SetWindowDirty(WC_COMPANY, _current_company);
1044 }
1045 }
1046
1047 return CommandCost();
1048}
1049
1057 CommandCost CmdSetCompanyManagerFace(DoCommandFlags flags, uint style, uint32_t bits)
1058{
1059 CompanyManagerFace tmp_face{style, bits, {}};
1060 if (!IsValidCompanyManagerFace(tmp_face)) return CMD_ERROR;
1061
1062 if (flags.Test(DoCommandFlag::Execute)) {
1063 CompanyManagerFace &cmf = Company::Get(_current_company)->face;
1064 SetCompanyManagerFaceStyle(cmf, style);
1065 cmf.bits = tmp_face.bits;
1066
1067 MarkWholeScreenDirty();
1068 }
1069 return CommandCost();
1070}
1071
1077 void UpdateCompanyLiveries(Company *c)
1078{
1079 for (int i = 1; i < LS_END; i++) {
1080 if (!c->livery[i].in_use.Test(Livery::Flag::Primary)) c->livery[i].colour1 = c->livery[LS_DEFAULT].colour1;
1081 if (!c->livery[i].in_use.Test(Livery::Flag::Secondary)) c->livery[i].colour2 = c->livery[LS_DEFAULT].colour2;
1082 }
1083 UpdateCompanyGroupLiveries(c);
1084}
1085
1094 CommandCost CmdSetCompanyColour(DoCommandFlags flags, LiveryScheme scheme, bool primary, Colours colour)
1095{
1096 if (scheme >= LS_END || (colour >= COLOUR_END && colour != INVALID_COLOUR)) return CMD_ERROR;
1097
1098 /* Default scheme can't be reset to invalid. */
1099 if (scheme == LS_DEFAULT && colour == INVALID_COLOUR) return CMD_ERROR;
1100
1101 Company *c = Company::Get(_current_company);
1102
1103 /* Ensure no two companies have the same primary colour */
1104 if (scheme == LS_DEFAULT && primary) {
1105 for (const Company *cc : Company::Iterate()) {
1106 if (cc != c && cc->colour == colour) return CMD_ERROR;
1107 }
1108 }
1109
1110 if (flags.Test(DoCommandFlag::Execute)) {
1111 if (primary) {
1112 if (scheme != LS_DEFAULT) c->livery[scheme].in_use.Set(Livery::Flag::Primary, colour != INVALID_COLOUR);
1113 if (colour == INVALID_COLOUR) colour = c->livery[LS_DEFAULT].colour1;
1114 c->livery[scheme].colour1 = colour;
1115
1116 /* If setting the first colour of the default scheme, adjust the
1117 * original and cached company colours too. */
1118 if (scheme == LS_DEFAULT) {
1119 UpdateCompanyLiveries(c);
1120 _company_colours[_current_company] = colour;
1121 c->colour = colour;
1122 CompanyAdminUpdate(c);
1123 }
1124 } else {
1125 if (scheme != LS_DEFAULT) c->livery[scheme].in_use.Set(Livery::Flag::Secondary, colour != INVALID_COLOUR);
1126 if (colour == INVALID_COLOUR) colour = c->livery[LS_DEFAULT].colour2;
1127 c->livery[scheme].colour2 = colour;
1128
1129 if (scheme == LS_DEFAULT) {
1130 UpdateCompanyLiveries(c);
1131 }
1132 }
1133
1134 if (c->livery[scheme].in_use.Any({Livery::Flag::Primary, Livery::Flag::Secondary})) {
1135 /* If enabling a scheme, set the default scheme to be in use too */
1136 c->livery[LS_DEFAULT].in_use.Set(Livery::Flag::Primary);
1137 } else {
1138 /* Else loop through all schemes to see if any are left enabled.
1139 * If not, disable the default scheme too. */
1140 c->livery[LS_DEFAULT].in_use.Reset({Livery::Flag::Primary, Livery::Flag::Secondary});
1141 for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1142 if (c->livery[scheme].in_use.Any({Livery::Flag::Primary, Livery::Flag::Secondary})) {
1143 c->livery[LS_DEFAULT].in_use.Set(Livery::Flag::Primary);
1144 break;
1145 }
1146 }
1147 }
1148
1149 ResetVehicleColourMap();
1150 MarkWholeScreenDirty();
1151
1152 /* All graph related to companies use the company colour. */
1153 InvalidateWindowData(WC_INCOME_GRAPH, 0);
1154 InvalidateWindowData(WC_OPERATING_PROFIT, 0);
1155 InvalidateWindowData(WC_DELIVERED_CARGO, 0);
1156 InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0);
1157 InvalidateWindowData(WC_COMPANY_VALUE, 0);
1158 InvalidateWindowData(WC_LINKGRAPH_LEGEND, 0);
1159 /* The smallmap owner view also stores the company colours. */
1160 BuildOwnerLegend();
1161 InvalidateWindowData(WC_SMALLMAP, 0, 1);
1162
1163 /* Company colour data is indirectly cached. */
1164 for (Vehicle *v : Vehicle::Iterate()) {
1165 if (v->owner == _current_company) v->InvalidateNewGRFCache();
1166 }
1167
1168 UpdateObjectColours(c);
1169 }
1170 return CommandCost();
1171}
1172
1178 static bool IsUniqueCompanyName(const std::string &name)
1179{
1180 for (const Company *c : Company::Iterate()) {
1181 if (!c->name.empty() && c->name == name) return false;
1182 }
1183
1184 return true;
1185}
1186
1193 CommandCost CmdRenameCompany(DoCommandFlags flags, const std::string &text)
1194{
1195 bool reset = text.empty();
1196
1197 if (!reset) {
1198 if (Utf8StringLength(text) >= MAX_LENGTH_COMPANY_NAME_CHARS) return CMD_ERROR;
1199 if (!IsUniqueCompanyName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE);
1200 }
1201
1202 if (flags.Test(DoCommandFlag::Execute)) {
1203 Company *c = Company::Get(_current_company);
1204 if (reset) {
1205 c->name.clear();
1206 } else {
1207 c->name = text;
1208 }
1209 MarkWholeScreenDirty();
1210 CompanyAdminUpdate(c);
1211
1212 std::string new_name = GetString(STR_COMPANY_NAME, c->index);
1213 AI::BroadcastNewEvent(new ScriptEventCompanyRenamed(c->index, new_name));
1214 Game::NewEvent(new ScriptEventCompanyRenamed(c->index, new_name));
1215 }
1216
1217 return CommandCost();
1218}
1219
1225 static bool IsUniquePresidentName(const std::string &name)
1226{
1227 for (const Company *c : Company::Iterate()) {
1228 if (!c->president_name.empty() && c->president_name == name) return false;
1229 }
1230
1231 return true;
1232}
1233
1240 CommandCost CmdRenamePresident(DoCommandFlags flags, const std::string &text)
1241{
1242 bool reset = text.empty();
1243
1244 if (!reset) {
1245 if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR;
1246 if (!IsUniquePresidentName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE);
1247 }
1248
1249 if (flags.Test(DoCommandFlag::Execute)) {
1250 Company *c = Company::Get(_current_company);
1251
1252 if (reset) {
1253 c->president_name.clear();
1254 } else {
1255 c->president_name = text;
1256
1257 if (c->name_1 == STR_SV_UNNAMED && c->name.empty()) {
1258 Command<CMD_RENAME_COMPANY>::Do(DoCommandFlag::Execute, text + " Transport");
1259 }
1260 }
1261
1262 InvalidateWindowClassesData(WC_COMPANY, 1);
1263 MarkWholeScreenDirty();
1264 CompanyAdminUpdate(c);
1265
1266 std::string new_name = GetString(STR_PRESIDENT_NAME, c->index);
1267 AI::BroadcastNewEvent(new ScriptEventPresidentRenamed(c->index, new_name));
1268 Game::NewEvent(new ScriptEventPresidentRenamed(c->index, new_name));
1269 }
1270
1271 return CommandCost();
1272}
1273
1280 int CompanyServiceInterval(const Company *c, VehicleType type)
1281{
1282 const VehicleDefaultSettings *vds = (c == nullptr) ? &_settings_client.company.vehicle : &c->settings.vehicle;
1283 switch (type) {
1284 default: NOT_REACHED();
1285 case VEH_TRAIN: return vds->servint_trains;
1286 case VEH_ROAD: return vds->servint_roadveh;
1287 case VEH_AIRCRAFT: return vds->servint_aircraft;
1288 case VEH_SHIP: return vds->servint_ships;
1289 }
1290}
1291
1297uint32_t CompanyInfrastructure::GetRoadTramTotal(RoadTramType rtt) const
1298{
1299 uint32_t total = 0;
1300 for (RoadType rt : GetMaskForRoadTramType(rtt)) {
1301 total += this->road[rt];
1302 }
1303 return total;
1304}
1305
1316 CommandCost CmdGiveMoney(DoCommandFlags flags, Money money, CompanyID dest_company)
1317{
1318 if (!_settings_game.economy.give_money) return CMD_ERROR;
1319
1320 const Company *c = Company::Get(_current_company);
1321 CommandCost amount(EXPENSES_OTHER, std::min<Money>(money, 20000000LL));
1322
1323 /* You can only transfer funds that is in excess of your loan */
1324 if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return CommandCost(STR_ERROR_INSUFFICIENT_FUNDS);
1325 if (!Company::IsValidID(dest_company)) return CMD_ERROR;
1326
1327 if (flags.Test(DoCommandFlag::Execute)) {
1328 /* Add money to company */
1329 Backup<CompanyID> cur_company(_current_company, dest_company);
1330 SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
1331 cur_company.Restore();
1332
1333 if (_networking) {
1334 std::string dest_company_name = GetString(STR_COMPANY_NAME, dest_company);
1335 std::string from_company_name = GetString(STR_COMPANY_NAME, _current_company);
1336
1337 NetworkTextMessage(NETWORK_ACTION_GIVE_MONEY, GetDrawStringCompanyColour(_current_company), false, from_company_name, dest_company_name, amount.GetCost());
1338 }
1339 }
1340
1341 /* Subtract money from local-company */
1342 return amount;
1343}
1344
1354 CompanyID GetFirstPlayableCompanyID()
1355{
1356 for (Company *c : Company::Iterate()) {
1357 if (Company::IsHumanID(c->index)) {
1358 return c->index;
1359 }
1360 }
1361
1362 if (Company::CanAllocateItem()) {
1363 for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) {
1364 if (!Company::IsValidID(c)) {
1365 return c;
1366 }
1367 }
1368 }
1369
1370 return CompanyID::Begin();
1371}
1372
1373 static std::vector<FaceSpec> _faces;
1374
1378 void ResetFaces()
1379{
1380 _faces.clear();
1381 _faces.assign(std::begin(_original_faces), std::end(_original_faces));
1382}
1383
1388uint GetNumCompanyManagerFaceStyles()
1389{
1390 return static_cast<uint>(std::size(_faces));
1391}
1392
1398 const FaceSpec *GetCompanyManagerFaceSpec(uint style_index)
1399{
1400 if (style_index < GetNumCompanyManagerFaceStyles()) return &_faces[style_index];
1401 return nullptr;
1402}
1403
1409std::optional<uint> FindCompanyManagerFaceLabel(std::string_view label)
1410{
1411 auto it = std::ranges::find(_faces, label, &FaceSpec::label);
1412 if (it == std::end(_faces)) return std::nullopt;
1413
1414 return static_cast<uint>(std::distance(std::begin(_faces), it));
1415}
1416
1422FaceVars GetCompanyManagerFaceVars(uint style)
1423{
1424 const FaceSpec *spec = GetCompanyManagerFaceSpec(style);
1425 if (spec == nullptr) return {};
1426 return spec->GetFaceVars();
1427}
1428
1435 void SetCompanyManagerFaceStyle(CompanyManagerFace &cmf, uint style)
1436{
1437 const FaceSpec *spec = GetCompanyManagerFaceSpec(style);
1438 assert(spec != nullptr);
1439
1440 cmf.style = style;
1441 cmf.style_label = spec->label;
1442}
1443
1450 void RandomiseCompanyManagerFace(CompanyManagerFace &cmf, Randomizer &randomizer)
1451{
1452 SetCompanyManagerFaceStyle(cmf, randomizer.Next(GetNumCompanyManagerFaceStyles()));
1453 RandomiseCompanyManagerFaceBits(cmf, GetCompanyManagerFaceVars(cmf.style), randomizer);
1454}
1455
1463uint32_t MaskCompanyManagerFaceBits(const CompanyManagerFace &cmf, FaceVars vars)
1464{
1465 CompanyManagerFace face{};
1466
1467 for (auto var : SetBitIterator(GetActiveFaceVars(cmf, vars))) {
1468 vars[var].SetBits(face, vars[var].GetBits(cmf));
1469 }
1470
1471 return face.bits;
1472}
1473
1479std::string FormatCompanyManagerFaceCode(const CompanyManagerFace &cmf)
1480{
1481 uint32_t masked_face_bits = MaskCompanyManagerFaceBits(cmf, GetCompanyManagerFaceVars(cmf.style));
1482 return fmt::format("{}:{}", cmf.style_label, masked_face_bits);
1483}
1484
1490std::optional<CompanyManagerFace> ParseCompanyManagerFaceCode(std::string_view str)
1491{
1492 if (str.empty()) return std::nullopt;
1493
1494 CompanyManagerFace cmf;
1495 StringConsumer consumer{str};
1496 if (consumer.FindChar(':') != StringConsumer::npos) {
1497 auto label = consumer.ReadUntilChar(':', StringConsumer::SKIP_ONE_SEPARATOR);
1498
1499 /* Read numeric part and ensure it's valid. */
1500 auto bits = consumer.TryReadIntegerBase<uint32_t>(10, true);
1501 if (!bits.has_value() || consumer.AnyBytesLeft()) return std::nullopt;
1502
1503 /* Ensure style label is valid. */
1504 auto style = FindCompanyManagerFaceLabel(label);
1505 if (!style.has_value()) return std::nullopt;
1506
1507 SetCompanyManagerFaceStyle(cmf, *style);
1508 cmf.bits = *bits;
1509 } else {
1510 /* No ':' included, treat as numeric-only. This allows old-style codes to be entered. */
1511 auto bits = ParseInteger(str, 10, true);
1512 if (!bits.has_value()) return std::nullopt;
1513
1514 /* Old codes use bits 0..1 to represent face style. These map directly to the default face styles. */
1515 SetCompanyManagerFaceStyle(cmf, GB(*bits, 0, 2));
1516 cmf.bits = *bits;
1517 }
1518
1519 /* Force the face bits to be valid. */
1520 FaceVars vars = GetCompanyManagerFaceVars(cmf.style);
1521 ScaleAllCompanyManagerFaceBits(cmf, vars);
1522 cmf.bits = MaskCompanyManagerFaceBits(cmf, vars);
1523
1524 return cmf;
1525}
ai.hpp
Base functions for all AIs.
ai_config.hpp
AIConfig stores the configuration settings of every AI.
ai_instance.hpp
The AIInstance tracks an AI.
backup_type.hpp
Class for backupping variables and making sure they are restored later.
GB
static constexpr 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
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
AI::BroadcastNewEvent
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=CompanyID::Invalid())
Broadcast a new event to all active AIs.
Definition ai_core.cpp:255
AI::CanStartNew
static bool CanStartNew()
Is it possible to start a new AI company?
Definition ai_core.cpp:30
AI::StartNew
static void StartNew(CompanyID company)
Start a new AI company.
Definition ai_core.cpp:36
AI::Stop
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition ai_core.cpp:107
AI::NewEvent
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition ai_core.cpp:235
BaseBitSet::All
constexpr bool All(const Timpl &other) const
Test if all of the values are set.
Definition base_bitset_type.hpp:151
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
BaseBitSet::Any
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Definition base_bitset_type.hpp:170
CommandCost
Common return value for all commands.
Definition command_type.h:24
CommandCost::GetExpensesType
ExpensesType GetExpensesType() const
The expense type of the cost.
Definition command_type.h:127
CommandCost::MakeError
void MakeError(StringID message)
Makes this CommandCost behave like an error command.
Definition command_type.h:136
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition command_type.h:118
CommandCost::SetEncodedMessage
void SetEncodedMessage(EncodedString &&message)
Set the encoded message string.
Definition command_type.h:72
CompanyMask
Definition company_type.h:43
EncodedString
Container for an encoded string, created by GetEncodedString.
Definition strings_type.h:98
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
Game::NewEvent
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition game_core.cpp:136
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
NetworkAuthorizedKeys::Add
bool Add(std::string_view key)
Add the given key to the authorized keys, when it is not already contained.
Definition network.cpp:190
NetworkAuthorizedKeys::Remove
bool Remove(std::string_view key)
Remove the given key from the authorized keys, when it is exists.
Definition network.cpp:206
OverflowSafeInt< int64_t >
StringConsumer
Parse data from a string / buffer.
Definition string_consumer.hpp:27
StringConsumer::ReadUntilChar
std::string_view ReadUntilChar(char c, SeparatorUsage sep)
Read data until the first occurrence of 8-bit char 'c', and advance reader.
Definition string_consumer.hpp:765
StringConsumer::SKIP_ONE_SEPARATOR
@ SKIP_ONE_SEPARATOR
Read and discard one separator, do not include it in the result.
Definition string_consumer.hpp:696
StringConsumer::npos
static constexpr size_type npos
Special value for "end of data".
Definition string_consumer.hpp:34
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:75
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:76
TimeoutTimer
A timeout timer will fire once after the interval.
Definition timer.h:116
TimeoutTimer::Abort
void Abort()
Abort the timer so it doesn't fire if it hasn't yet.
Definition timer.h:161
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition timer_game_calendar.h:31
TimerGameEconomy::year
static Year year
Current year, starting at 0.
Definition timer_game_economy.h:36
TypedIndexContainer
A sort-of mixin that implements 'at(pos)' and 'operator[](pos)' only for a specific type.
Definition convertible_through_base.hpp:38
command_func.h
Functions related to commands.
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition command_func.h:28
DoCommandFlag::Execute
@ Execute
execute the given command
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
ClearEnginesHiddenFlagOfCompany
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
Clear the 'hidden' flag for all engines of a new company.
Definition engine.cpp:1004
UpdateObjectColours
void UpdateObjectColours(const Company *c)
Updates the colour of the object whenever a company changes.
Definition object_cmd.cpp:184
_new_competitor_timeout
TimeoutTimer< TimerGameTick > _new_competitor_timeout({ TimerGameTick::Priority::COMPETITOR_TIMEOUT, 0 }, []() { if(_game_mode==GM_MENU||!AI::CanStartNew()) return;if(_networking &&Company::GetNumItems() >=_settings_client.network.max_companies) return;if(_settings_game.difficulty.competitors_interval==0) 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, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID);})
Start a new competitor company if possible.
ParseCompanyManagerFaceCode
std::optional< CompanyManagerFace > ParseCompanyManagerFaceCode(std::string_view str)
Parse a face code into a company manager face.
Definition company_cmd.cpp:1490
GenerateCompanyName
static void GenerateCompanyName(Company *c)
Generate the name of a company from the last build coordinate.
Definition company_cmd.cpp:413
IsValidCompanyManagerFace
static bool IsValidCompanyManagerFace(CompanyManagerFace cmf)
Checks whether a company manager's face is a valid encoding.
Definition company_cmd.cpp:186
GetCompanyManagerFaceSpec
const FaceSpec * GetCompanyManagerFaceSpec(uint style_index)
Get the definition of a company manager face style.
Definition company_cmd.cpp:1398
OnTick_Companies
void OnTick_Companies()
Called every tick for updating some company info.
Definition company_cmd.cpp:770
SubtractMoneyFromAnyCompany
static void SubtractMoneyFromAnyCompany(Company *c, const CommandCost &cost)
Deduct costs of a command from the money of a company.
Definition company_cmd.cpp:284
GetParamsForOwnedBy
std::array< StringParameter, 2 > GetParamsForOwnedBy(Owner owner, TileIndex tile)
Set the right DParams for STR_ERROR_OWNED_BY.
Definition company_cmd.cpp:358
GetCompanyManagerFaceVars
FaceVars GetCompanyManagerFaceVars(uint style)
Get the face variables for a face style.
Definition company_cmd.cpp:1422
CmdCompanyAllowListCtrl
CommandCost CmdCompanyAllowListCtrl(DoCommandFlags flags, CompanyAllowListCtrlAction action, const std::string &public_key)
Add or remove the given public key to the allow list of this company.
Definition company_cmd.cpp:1023
RandomiseCompanyManagerFace
void RandomiseCompanyManagerFace(CompanyManagerFace &cmf, Randomizer &randomizer)
Completely randomise a company manager face, including style.
Definition company_cmd.cpp:1450
ResetFaces
void ResetFaces()
Reset company manager face styles to default.
Definition company_cmd.cpp:1378
DoStartupNewCompany
Company * DoStartupNewCompany(bool is_ai, CompanyID company=CompanyID::Invalid())
Create a new company and sets all company variables default values.
Definition company_cmd.cpp:598
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition company_cmd.cpp:175
MaskCompanyManagerFaceBits
uint32_t MaskCompanyManagerFaceBits(const CompanyManagerFace &cmf, FaceVars vars)
Mask company manager face bits to ensure they are all within range.
Definition company_cmd.cpp:1463
_company_manager_face
std::string _company_manager_face
for company manager face storage in openttd.cfg
Definition company_cmd.cpp:58
GenerateCompanyColour
static Colours GenerateCompanyColour()
Generate a company colour.
Definition company_cmd.cpp:492
GeneratePresidentName
static void GeneratePresidentName(Company *c)
Generate a random president name of a company.
Definition company_cmd.cpp:547
_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:469
_company_colours
TypedIndexContainer< std::array< Colours, MAX_COMPANIES >, CompanyID > _company_colours
NOSAVE: can be determined from company structs.
Definition company_cmd.cpp:57
ResetCompanyLivery
void ResetCompanyLivery(Company *c)
Reset the livery schemes to the company's primary colour.
Definition company_cmd.cpp:574
UpdateCompanyLiveries
void UpdateCompanyLiveries(Company *c)
Update liveries for a company.
Definition company_cmd.cpp:1077
CheckTileOwnership
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Definition company_cmd.cpp:404
CmdSetCompanyColour
CommandCost CmdSetCompanyColour(DoCommandFlags flags, LiveryScheme scheme, bool primary, Colours colour)
Change the company's company-colour.
Definition company_cmd.cpp:1094
CmdCompanyCtrl
CommandCost CmdCompanyCtrl(DoCommandFlags flags, CompanyCtrlAction cca, CompanyID company_id, CompanyRemoveReason reason, ClientID client_id)
Control the companies: add, delete, etc.
Definition company_cmd.cpp:881
_faces
static std::vector< FaceSpec > _faces
All company manager face styles.
Definition company_cmd.cpp:1373
InvalidateCompanyWindows
void InvalidateCompanyWindows(const Company *company)
Mark all finance windows owned by a company as needing a refresh.
Definition company_cmd.cpp:206
CompanyServiceInterval
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
Definition company_cmd.cpp:1280
GetCompanyPalette
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
Definition company_cmd.cpp:164
SetCompanyManagerFaceStyle
void SetCompanyManagerFaceStyle(CompanyManagerFace &cmf, uint style)
Set a company face style.
Definition company_cmd.cpp:1435
CheckCompanyHasMoney
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
Definition company_cmd.cpp:263
GetFirstPlayableCompanyID
CompanyID GetFirstPlayableCompanyID()
Get the index of the first available company.
Definition company_cmd.cpp:1354
_dirty_company_finances
static CompanyMask _dirty_company_finances
Bitmask of company finances that should be marked dirty.
Definition company_cmd.cpp:199
GetDrawStringCompanyColour
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
Definition company_cmd.cpp:153
CmdSetCompanyManagerFace
CommandCost CmdSetCompanyManagerFace(DoCommandFlags flags, uint style, uint32_t bits)
Change the company manager's face.
Definition company_cmd.cpp:1057
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
This functions returns the money which can be used to execute a command.
Definition company_cmd.cpp:252
CompanyAdminUpdate
void CompanyAdminUpdate(const Company *company)
Called whenever company related information changes in order to notify admins.
Definition company_cmd.cpp:858
FindCompanyManagerFaceLabel
std::optional< uint > FindCompanyManagerFaceLabel(std::string_view label)
Find a company manager face style by label.
Definition company_cmd.cpp:1409
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition company_cmd.cpp:381
CompanyAdminRemove
void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
Called whenever a company is removed in order to notify admins.
Definition company_cmd.cpp:868
CmdRenamePresident
CommandCost CmdRenamePresident(DoCommandFlags flags, const std::string &text)
Change the name of the president.
Definition company_cmd.cpp:1240
SubtractMoneyFromCompany
void SubtractMoneyFromCompany(const CommandCost &cost)
Subtract money from the _current_company, if the company is valid.
Definition company_cmd.cpp:313
_company_pool
CompanyPool _company_pool("Company")
Pool of companies.
_economy_companies_yearly
static const 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].fill(0);InvalidateWindowData(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...
GetNumCompanyManagerFaceStyles
uint GetNumCompanyManagerFaceStyles()
Get the number of company manager face styles.
Definition company_cmd.cpp:1388
FormatCompanyManagerFaceCode
std::string FormatCompanyManagerFaceCode(const CompanyManagerFace &cmf)
Get a face code representation of a company manager face.
Definition company_cmd.cpp:1479
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:238
UpdateLandscapingLimits
void UpdateLandscapingLimits()
Update the landscaping limits per company.
Definition company_cmd.cpp:342
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
InitializeCompanies
void InitializeCompanies()
Initialize the pool of companies.
Definition company_cmd.cpp:684
_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:59
StartupCompanies
void StartupCompanies()
Start of a new game.
Definition company_cmd.cpp:677
CheckTakeoverVehicleLimit
bool CheckTakeoverVehicleLimit(CompanyID cbig, CompanyID csmall)
Can company cbig buy company csmall without exceeding vehicle limits?
Definition company_cmd.cpp:695
IsUniqueCompanyName
static bool IsUniqueCompanyName(const std::string &name)
Is the given name in use as name of a company?
Definition company_cmd.cpp:1178
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:119
IsUniquePresidentName
static bool IsUniquePresidentName(const std::string &name)
Is the given name in use as president name of a company?
Definition company_cmd.cpp:1225
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
CmdGiveMoney
CommandCost CmdGiveMoney(DoCommandFlags flags, Money money, CompanyID dest_company)
Transfer funds (money) from one company to another.
Definition company_cmd.cpp:1316
HandleBankruptcyTakeover
static void HandleBankruptcyTakeover(Company *c)
Handle the bankruptcy take over of a company.
Definition company_cmd.cpp:716
CmdRenameCompany
CommandCost CmdRenameCompany(DoCommandFlags flags, const std::string &text)
Change the name of the company.
Definition company_cmd.cpp:1193
SubtractMoneyFromCompanyFract
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
Subtract money from a company, including the money fraction.
Definition company_cmd.cpp:324
invalidate_company_windows_interval
static const IntervalTimer< TimerWindow > invalidate_company_windows_interval(std::chrono::milliseconds(1), [](auto) { for(CompanyID cid :_dirty_company_finances) { if(cid==_local_company) SetWindowWidgetDirty(WC_STATUS_BAR, 0, WID_S_RIGHT);Window *w=FindWindowById(WC_FINANCES, cid);if(w !=nullptr) { w->SetWidgetDirty(WID_CF_EXPS_PRICE3);w->SetWidgetDirty(WID_CF_OWN_VALUE);w->SetWidgetDirty(WID_CF_LOAN_VALUE);w->SetWidgetDirty(WID_CF_BALANCE_VALUE);w->SetWidgetDirty(WID_CF_MAXLOAN_VALUE);} SetWindowWidgetDirty(WC_COMPANY, cid, WID_C_DESC_COMPANY_VALUE);} _dirty_company_finances.Reset();})
Refresh all company finance windows previously marked dirty.
_colour_sort
static const uint8_t _colour_sort[COLOUR_END]
Sorting weights for the company colours.
Definition company_cmd.cpp:467
company_cmd.h
Command definitions related to companies.
company_face.h
This file contains all definitions for default company faces.
_original_faces
static FaceSpec _original_faces[]
Original face styles.
Definition company_face.h:91
company_func.h
Functions related to companies.
IsInteractiveCompany
bool IsInteractiveCompany(CompanyID company)
Is the user representing company?
Definition company_func.h:57
ChangeOwnershipOfCompanyItems
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
Change the ownership of all the items of a company.
Definition economy.cpp:322
ShowBuyCompanyDialog
void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
Show the query to buy another company.
Definition company_gui.cpp:2439
IsLocalCompany
bool IsLocalCompany()
Is the current company the local company?
Definition company_func.h:47
ShowCompanyFinances
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
Definition company_gui.cpp:569
company_gui.h
GUI Functions related to companies.
CloseCompanyWindows
void CloseCompanyWindows(CompanyID company)
Close all windows of a company.
Definition window.cpp:1223
company_manager_face.h
Functionality related to the company manager's face.
RandomiseCompanyManagerFaceBits
void RandomiseCompanyManagerFaceBits(CompanyManagerFace &cmf, FaceVars vars, Randomizer &randomizer)
Make a random new face without changing the face style.
Definition company_manager_face.h:171
GetActiveFaceVars
uint64_t GetActiveFaceVars(const CompanyManagerFace &cmf, FaceVars vars)
Get a bitmask of currently active face variables.
Definition company_manager_face.h:140
ScaleAllCompanyManagerFaceBits
void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf, FaceVars vars)
Scales all company manager's face bits to the correct scope.
Definition company_manager_face.h:158
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:33
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:34
CompanyCtrlAction
CompanyCtrlAction
The action to do with CMD_COMPANY_CTRL.
Definition company_type.h:71
CCA_NEW_AI
@ CCA_NEW_AI
Create a new AI company.
Definition company_type.h:73
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition company_type.h:74
CCA_NEW
@ CCA_NEW
Create a new company.
Definition company_type.h:72
COMPANY_SPECTATOR
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
Definition company_type.h:21
OWNER_END
static constexpr Owner OWNER_END
Last + 1 owner.
Definition company_type.h:29
CompanyAllowListCtrlAction
CompanyAllowListCtrlAction
The action to do with CMD_COMPANY_ALLOW_LIST_CTRL.
Definition company_type.h:80
CALCA_REMOVE
@ CALCA_REMOVE
Remove a public key.
Definition company_type.h:82
CALCA_ADD
@ CALCA_ADD
Create a public key.
Definition company_type.h:81
OWNER_TOWN
static constexpr Owner OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition company_type.h:25
OWNER_NONE
static constexpr Owner OWNER_NONE
The tile has no ownership.
Definition company_type.h:26
INVALID_OWNER
static constexpr Owner INVALID_OWNER
An invalid owner.
Definition company_type.h:30
CompanyRemoveReason
CompanyRemoveReason
The reason why the company was removed.
Definition company_type.h:60
CRR_END
@ CRR_END
Sentinel for end.
Definition company_type.h:65
CRR_NONE
@ CRR_NONE
Dummy reason for actions that don't need one.
Definition company_type.h:67
WID_CF_OWN_VALUE
@ WID_CF_OWN_VALUE
Own funds, not including loan.
Definition company_widget.h:68
WID_CF_LOAN_VALUE
@ WID_CF_LOAN_VALUE
Loan.
Definition company_widget.h:66
WID_CF_BALANCE_VALUE
@ WID_CF_BALANCE_VALUE
Bank balance value.
Definition company_widget.h:65
WID_CF_EXPS_PRICE3
@ WID_CF_EXPS_PRICE3
Column for year Y expenses.
Definition company_widget.h:62
WID_CF_MAXLOAN_VALUE
@ WID_CF_MAXLOAN_VALUE
Max loan widget.
Definition company_widget.h:70
WID_C_DESC_COMPANY_VALUE
@ WID_C_DESC_COMPANY_VALUE
Company value.
Definition company_widget.h:25
NETWORK_PUBLIC_KEY_LENGTH
static const uint NETWORK_PUBLIC_KEY_LENGTH
The maximum length of the hexadecimal encoded public keys, in bytes including '\0'.
Definition config.h:101
EXPENSES_ROADVEH_RUN
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
Definition economy_type.h:182
EXPENSES_TRAIN_RUN
@ EXPENSES_TRAIN_RUN
Running costs trains.
Definition economy_type.h:181
EXPENSES_AIRCRAFT_REVENUE
@ EXPENSES_AIRCRAFT_REVENUE
Revenue from aircraft.
Definition economy_type.h:188
EXPENSES_AIRCRAFT_RUN
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
Definition economy_type.h:183
EXPENSES_ROADVEH_REVENUE
@ EXPENSES_ROADVEH_REVENUE
Revenue from road vehicles.
Definition economy_type.h:187
EXPENSES_PROPERTY
@ EXPENSES_PROPERTY
Property costs.
Definition economy_type.h:185
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition economy_type.h:191
EXPENSES_SHIP_REVENUE
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition economy_type.h:189
EXPENSES_LOAN_INTEREST
@ EXPENSES_LOAN_INTEREST
Interest payments over the loan.
Definition economy_type.h:190
EXPENSES_TRAIN_REVENUE
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
Definition economy_type.h:186
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition economy_type.h:184
INVALID_EXPENSES
@ INVALID_EXPENSES
Invalid expense type.
Definition economy_type.h:193
LOAN_INTERVAL
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
Definition economy_type.h:211
INITIAL_LOAN
static const int64_t INITIAL_LOAN
The size of loan for a new company, in British Pounds!
Definition economy_type.h:213
game.hpp
Base functions for all Games.
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:1034
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
goal_base.h
Goal base class.
UpdateCompanyGroupLiveries
void UpdateCompanyGroupLiveries(const Company *c)
Update group liveries for a company.
Definition group_cmd.cpp:329
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1549
BorderFlag::Random
@ Random
Randomise borders.
LiveryScheme
LiveryScheme
List of different livery schemes.
Definition livery.h:22
IsInsideMM
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:267
_networking
bool _networking
are we in networking mode?
Definition network.cpp:67
_network_server
bool _network_server
network-server is active
Definition network.cpp:68
_network_own_client_id
ClientID _network_own_client_id
Our client identifier.
Definition network.cpp:72
network.h
Basic functions/variables used all over the place.
NetworkAdminCompanyUpdate
void NetworkAdminCompanyUpdate(const Company *company)
Notify the admin network of company updates.
Definition network_admin.cpp:955
NetworkAdminCompanyNew
void NetworkAdminCompanyNew(const Company *company)
Notify the admin network of a new company.
Definition network_admin.cpp:936
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:971
network_admin.h
Server part of the admin network protocol.
network_base.h
Base core network types and some helper functions to access them.
network_func.h
Network functions used by other parts of OpenTTD.
NetworkServerNewCompany
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci)
Perform all the server specific administration of a new company.
Definition network_server.cpp:2150
NetworkUpdateClientInfo
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
Definition network_server.cpp:1529
DESTTYPE_TEAM
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition network_type.h:70
ClientID
ClientID
'Unique' identifier to be given to clients
Definition network_type.h:43
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition network_type.h:44
news_func.h
Functions related to news.
AddNewsItem
void AddNewsItem(EncodedString &&headline, NewsType type, NewsStyle style, NewsFlags flags, NewsReference ref1={}, NewsReference ref2={}, std::unique_ptr< NewsAllocatedData > &&data=nullptr, AdviceType advice_type=AdviceType::Invalid)
Add a new newsitem to be shown.
Definition news_gui.cpp:900
NewsType::CompanyInfo
@ CompanyInfo
Company info (new companies, bankruptcy messages)
NewsStyle::Company
@ Company
Company news item. (Newspaper with face)
GetColourGradient
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:388
pool_func.hpp
Some methods of Pool are placed here in order to reduce compilation time and binary size.
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition pool_func.hpp:210
GetCompanyRailTypes
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition rail.cpp:135
rail.h
Rail specific functions.
_random
Randomizer _random
Random used in the game state calculations.
Definition random_func.cpp:36
GetCompanyRoadTypes
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition road.cpp:210
GetMaskForRoadTramType
RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
Get the mask for road types of the given RoadTramType.
Definition road.h:183
RoadTramType
RoadTramType
The different types of road type.
Definition road_type.h:37
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
safeguards.h
A number of safeguards to prevent using unsafe methods.
SyncCompanySettings
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
Definition settings.cpp:1870
SetDefaultCompanySettings
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Definition settings.cpp:1857
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
settings_func.h
Functions related to setting/changing the settings.
BuildOwnerLegend
void BuildOwnerLegend()
Completes the array for the owned property legend.
Definition smallmap_gui.cpp:341
smallmap_gui.h
Smallmap GUI functions.
sound_func.h
Functions related to sound.
SND_01_BAD_YEAR
@ SND_01_BAD_YEAR
40 == 0x28 New year: performance declined
Definition sound_type.h:87
SND_00_GOOD_YEAR
@ SND_00_GOOD_YEAR
39 == 0x27 New year: performance improved
Definition sound_type.h:86
GetColourPalette
static PaletteID GetColourPalette(Colours colour)
Get recolour palette for a colour.
Definition sprite.h:188
statusbar_widget.h
Types related to the statusbar widgets.
WID_S_RIGHT
@ WID_S_RIGHT
Right part; bank balance.
Definition statusbar_widget.h:17
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
story_base.h
StoryPage base class.
Utf8StringLength
size_t Utf8StringLength(std::string_view str)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
Definition string.cpp:349
string_consumer.hpp
Parse strings.
ParseInteger
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
Definition string_consumer.hpp:917
GetEncodedStringWithArgs
EncodedString GetEncodedStringWithArgs(StringID str, std::span< const StringParameter > params)
Encode a string with its parameters into an encoded string.
Definition strings.cpp:102
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
SPECSTR_COMPANY_NAME_START
static constexpr StringID SPECSTR_COMPANY_NAME_START
Special strings for company names on the form "TownName transport".
Definition strings_type.h:68
SPECSTR_ANDCO_NAME
static constexpr StringID SPECSTR_ANDCO_NAME
Special string for Surname & Co company names.
Definition strings_type.h:72
SPECSTR_PRESIDENT_NAME
static constexpr StringID SPECSTR_PRESIDENT_NAME
Special string for the president's name.
Definition strings_type.h:73
SPECSTR_TOWNNAME_START
static constexpr StringID SPECSTR_TOWNNAME_START
Special strings for town names.
Definition strings_type.h:64
Backup
Class to backup a specific variable and restore it later.
Definition backup_type.hpp:21
Backup::Restore
void Restore()
Restore the variable.
Definition backup_type.hpp:110
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition settings_type.h:652
ClientSettings::network
NetworkSettings network
settings related to the network
Definition settings_type.h:651
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition settings_type.h:653
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
CommandHelper
Definition command_func.h:84
CompanyEconomyEntry::income
Money income
The amount of income.
Definition company_base.h:25
CompanyEconomyEntry::expenses
Money expenses
The amount of expenses.
Definition company_base.h:26
CompanyInfrastructure::GetRoadTramTotal
uint32_t GetRoadTramTotal(RoadTramType rtt) const
Get total sum of all owned road bits.
Definition company_cmd.cpp:1297
CompanyInfrastructure::road
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
Definition company_base.h:34
CompanyManagerFace
Definition company_type.h:53
CompanyManagerFace::bits
uint32_t bits
Company manager face bits, meaning is dependent on style.
Definition company_type.h:55
CompanyManagerFace::style
uint style
Company manager face style.
Definition company_type.h:54
CompanyManagerFace::style_label
std::string style_label
Face style label.
Definition company_type.h:56
CompanyNewsInformation::face
CompanyManagerFace face
The face of the president.
Definition news_type.h:168
CompanyNewsInformation::colour
Colours colour
The colour related to the company.
Definition news_type.h:169
CompanyNewsInformation::CompanyNewsInformation
CompanyNewsInformation(StringID title, const struct Company *c, const struct Company *other=nullptr)
Fill the CompanyNewsInformation struct with the required data.
Definition company_cmd.cpp:837
CompanyNewsInformation::president_name
std::string president_name
The name of the president.
Definition news_type.h:164
CompanyNewsInformation::company_name
std::string company_name
The name of the company.
Definition news_type.h:163
CompanyNewsInformation::other_company_name
std::string other_company_name
The name of the company taking over this one.
Definition news_type.h:165
CompanyProperties::bankrupt_asked
CompanyMask bankrupt_asked
which companies were asked about buying it?
Definition company_base.h:101
CompanyProperties::president_name
std::string president_name
Name of the president if the user changed it.
Definition company_base.h:78
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:102
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition company_base.h:124
CompanyProperties::allow_list
NetworkAuthorizedKeys allow_list
Public keys of clients that are allowed to join this company.
Definition company_base.h:80
CompanyProperties::name_2
uint32_t name_2
Parameter of name_1.
Definition company_base.h:72
CompanyProperties::money_fraction
uint8_t money_fraction
Fraction of money of the company, too small to represent in money.
Definition company_base.h:85
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition company_base.h:114
CompanyProperties::president_name_2
uint32_t president_name_2
Parameter of president_name_1.
Definition company_base.h:77
CompanyProperties::name_1
StringID name_1
Name of the company if the user did not change it.
Definition company_base.h:73
CompanyProperties::current_loan
Money current_loan
Amount of money borrowed from the bank.
Definition company_base.h:86
CompanyProperties::inaugurated_year_calendar
TimerGameCalendar::Year inaugurated_year_calendar
Calendar year of starting the company. Used to display proper Inauguration year while in wallclock mo...
Definition company_base.h:97
CompanyProperties::inaugurated_year
TimerGameEconomy::Year inaugurated_year
Economy year of starting the company.
Definition company_base.h:96
CompanyProperties::cur_economy
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition company_base.h:117
CompanyProperties::colour
Colours colour
Company colour.
Definition company_base.h:89
CompanyProperties::old_economy
std::array< CompanyEconomyEntry, MAX_HISTORY_QUARTERS > old_economy
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition company_base.h:118
CompanyProperties::face
CompanyManagerFace face
Face description of the president.
Definition company_base.h:82
CompanyProperties::max_loan
Money max_loan
Max allowed amount of the loan or COMPANY_MAX_LOAN_DEFAULT.
Definition company_base.h:87
CompanyProperties::yearly_expenses
std::array< Expenses, 3 > yearly_expenses
Expenses of the company for the last three years.
Definition company_base.h:116
CompanyProperties::last_build_coordinate
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition company_base.h:94
CompanyProperties::president_name_1
StringID president_name_1
Name of the president if the user did not change it.
Definition company_base.h:76
CompanyProperties::name
std::string name
Name of the company if the user changed it.
Definition company_base.h:74
CompanyProperties::money
Money money
Money owned by the company.
Definition company_base.h:84
CompanyProperties::num_valid_stat_ent
uint8_t num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition company_base.h:119
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition settings_type.h:615
Company
Definition company_base.h:127
Company::GetMaxLoan
Money GetMaxLoan() const
Calculate the max allowed loan for this company.
Definition company_cmd.cpp:107
Company::IsHumanID
static bool IsHumanID(auto index)
Is this company a company not controlled by a NoAI program?
Definition company_base.h:178
Company::group_all
std::array< GroupStatistics, VEH_COMPANY_END > group_all
NOSAVE: Statistics for the ALL_GROUP group.
Definition company_base.h:138
Company::avail_roadtypes
RoadTypes avail_roadtypes
Road types available to this company.
Definition company_base.h:132
Company::~Company
~Company()
Destructor.
Definition company_cmd.cpp:82
Company::avail_railtypes
RailTypes avail_railtypes
Rail types available to this company.
Definition company_base.h:131
Company::PostDestructor
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
Definition company_cmd.cpp:93
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:429
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:431
ConstructionSettings::terraform_frame_burst
uint16_t terraform_frame_burst
how many tile heights may, over a short period, be terraformed?
Definition settings_type.h:428
ConstructionSettings::tree_frame_burst
uint16_t tree_frame_burst
how many trees may, over a short period, be planted?
Definition settings_type.h:432
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:434
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:433
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:427
ConstructionSettings::clear_frame_burst
uint16_t clear_frame_burst
how many tiles may, over a short period, be cleared?
Definition settings_type.h:430
DifficultySettings::max_no_competitors
uint8_t max_no_competitors
the number of competitors (AIs)
Definition settings_type.h:125
DifficultySettings::infinite_money
bool infinite_money
whether spending money despite negative balance is allowed
Definition settings_type.h:143
DifficultySettings::competitors_interval
uint16_t competitors_interval
the interval (in minutes) between adding competitors
Definition settings_type.h:126
EconomySettings::give_money
bool give_money
allow giving other companies money
Definition settings_type.h:549
Economy::inflation_prices
uint64_t inflation_prices
Cumulated inflation of prices since game start; 16 bit fractional part.
Definition economy_type.h:52
Economy::max_loan
Money max_loan
NOSAVE: Maximum possible loan.
Definition economy_type.h:45
FaceSpec
Definition company_manager_face.h:113
GUISettings::show_finances
bool show_finances
show finances at end of year
Definition settings_type.h:169
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition settings_type.h:642
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition settings_type.h:635
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition settings_type.h:633
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition settings_type.h:641
Group
Group data.
Definition group.h:73
Livery::Flag::Primary
@ Primary
Primary colour is set.
Livery::Flag::Secondary
@ Secondary
Secondary colour is set.
NetworkClientInfo
Container for all information known about a client.
Definition network_base.h:24
NetworkClientInfo::GetByClientID
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Definition network.cpp:118
NetworkClientInfo::client_playas
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition network_base.h:28
NetworkClientInfo::client_id
ClientID client_id
Client identifier (same as ClientState->client_id)
Definition network_base.h:25
NetworkSettings::max_companies
uint8_t max_companies
maximum amount of companies
Definition settings_type.h:364
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
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:436
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_company_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition pool_type.hpp:417
Pool::PoolItem<&_company_pool >::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
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:357
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
Pool::PoolItem<&_company_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition pool_type.hpp:366
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(auto index)
Returns Titem with given index.
Definition pool_type.hpp:398
Pool
Base class for all pools.
Definition pool_type.hpp:133
Randomizer
Structure to encapsulate the pseudo random number generators.
Definition random_func.hpp:27
Randomizer::Next
uint32_t Next()
Generate the next pseudo random number.
Definition random_func.cpp:42
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition bitmath_func.hpp:277
SoundSettings::new_year
bool new_year
Play sound on new year, summarising the performance during the last year.
Definition settings_type.h:274
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Town
Town data structure.
Definition town.h:63
Town::name
std::string name
Custom town name. If empty, the town was not renamed and uses the generated name.
Definition town.h:72
VehicleDefaultSettings
Default settings for vehicles.
Definition settings_type.h:601
VehicleDefaultSettings::servint_aircraft
uint16_t servint_aircraft
service interval for aircraft
Definition settings_type.h:605
VehicleDefaultSettings::servint_roadveh
uint16_t servint_roadveh
service interval for road vehicles
Definition settings_type.h:604
VehicleDefaultSettings::servint_ships
uint16_t servint_ships
service interval for ships
Definition settings_type.h:606
VehicleDefaultSettings::servint_trains
uint16_t servint_trains
service interval for trains
Definition settings_type.h:603
VehicleSettings::max_ships
UnitID max_ships
max ships in game per company
Definition settings_type.h:529
VehicleSettings::max_trains
UnitID max_trains
max trains in game per company
Definition settings_type.h:526
VehicleSettings::max_aircraft
UnitID max_aircraft
max planes in game per company
Definition settings_type.h:528
VehicleSettings::max_roadveh
UnitID max_roadveh
max trucks in game per company
Definition settings_type.h:527
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:558
AdminCompanyRemoveReason
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
Definition tcp_admin.h:107
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
timer.h
Definition of Interval and OneShot timers.
timer_game_economy.h
Definition of the game-economy-timer.
timer_game_tick.h
Definition of the tick-based game-timer.
timer_window.h
Definition of the Window system.
town.h
Base of the town class.
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:3961
vehicle_base.h
Base class for all vehicles.
vehicle_func.h
Functions related to vehicles.
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:28
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:27
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
CloseConstructionWindows
void CloseConstructionWindows()
Close all windows that are used for construction of vehicle etc.
Definition window.cpp:3383
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:1195
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:3297
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1153
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:3192
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3179
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:3314
window_func.h
Window functions not directly related to making/drawing windows.
WN_NETWORK_STATUS_WINDOW_JOIN
@ WN_NETWORK_STATUS_WINDOW_JOIN
Network join status.
Definition window_type.h:44
WC_PERFORMANCE_HISTORY
@ WC_PERFORMANCE_HISTORY
Performance history graph; Window numbers:
Definition window_type.h:556
WC_COMPANY_LEAGUE
@ WC_COMPANY_LEAGUE
Company league window; Window numbers:
Definition window_type.h:568
WC_SIGN_LIST
@ WC_SIGN_LIST
Sign list; Window numbers:
Definition window_type.h:283
WC_PERFORMANCE_DETAIL
@ WC_PERFORMANCE_DETAIL
Performance detail window; Window numbers:
Definition window_type.h:580
WC_COMPANY_COLOUR
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
Definition window_type.h:235
WC_GRAPH_LEGEND
@ WC_GRAPH_LEGEND
Legend for graphs; Window numbers:
Definition window_type.h:526
WC_LINKGRAPH_LEGEND
@ WC_LINKGRAPH_LEGEND
Linkgraph legend; Window numbers:
Definition window_type.h:703
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition window_type.h:69
WC_SEND_NETWORK_MSG
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
Definition window_type.h:514
WC_ERRMSG
@ WC_ERRMSG
Error message; Window numbers:
Definition window_type.h:115
WC_SCRIPT_SETTINGS
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
Definition window_type.h:180
WC_SCRIPT_LIST
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
Definition window_type.h:289
WC_GOALS_LIST
@ WC_GOALS_LIST
Goals list; Window numbers:
Definition window_type.h:295
WC_OPERATING_PROFIT
@ WC_OPERATING_PROFIT
Operating profit graph; Window numbers:
Definition window_type.h:544
WC_CLIENT_LIST
@ WC_CLIENT_LIST
Client list; Window numbers:
Definition window_type.h:489
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition window_type.h:635
WC_FINANCES
@ WC_FINANCES
Finances of a company; Window numbers:
Definition window_type.h:532
WC_INCOME_GRAPH
@ WC_INCOME_GRAPH
Income graph; Window numbers:
Definition window_type.h:538
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition window_type.h:109
WC_DELIVERED_CARGO
@ WC_DELIVERED_CARGO
Delivered cargo graph; Window numbers:
Definition window_type.h:550
WC_COMPANY_VALUE
@ WC_COMPANY_VALUE
Company value graph; Window numbers:
Definition window_type.h:562
WC_MAIN_TOOLBAR
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition window_type.h:63
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition window_type.h:374
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition window_type.h:496