OpenTTD Source: src/company_cmd.cpp File Reference

OpenTTD Source 15.3

Functions | Variables
company_cmd.cpp File Reference

Handling of companies. More...

`#include "stdafx.h"`
`#include "company_base.h"`
`#include "company_func.h"`
`#include "company_gui.h"`
`#include "core/backup_type.hpp"`
`#include "town.h"`
`#include "news_func.h"`
`#include "command_func.h"`
`#include "network/network.h"`
`#include "network/network_func.h"`
`#include "network/network_base.h"`
`#include "network/network_admin.h"`
`#include "ai/ai.hpp"`
`#include "ai/ai_instance.hpp"`
`#include "ai/ai_config.hpp"`
`#include "company_manager_face.h"`
`#include "window_func.h"`
`#include "strings_func.h"`
`#include "sound_func.h"`
`#include "rail.h"`
`#include "core/pool_func.hpp"`
`#include "core/string_consumer.hpp"`
`#include "settings_func.h"`
`#include "vehicle_base.h"`
`#include "vehicle_func.h"`
`#include "smallmap_gui.h"`
`#include "game/game.hpp"`
`#include "goal_base.h"`
`#include "story_base.h"`
`#include "company_cmd.h"`
`#include "timer/timer.h"`
`#include "timer/timer_game_economy.h"`
`#include "timer/timer_game_tick.h"`
`#include "timer/timer_window.h"`
`#include "widgets/statusbar_widget.h"`
`#include "table/strings.h"`
`#include "table/company_face.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
void | ClearEnginesHiddenFlagOfCompany (CompanyID cid)
| Clear the 'hidden' flag for all engines of a new company.
void | UpdateObjectColours (const Company *c)
| Updates the colour of the object whenever a company changes.
void | SetLocalCompany (CompanyID new_company)
| Sets the local company and updates the settings that are set on a per-company basis to reflect the core's state in the GUI.
TextColour | GetDrawStringCompanyColour (CompanyID company)
| Get the colour for DrawString-subroutines which matches the colour of the company.
PaletteID | GetCompanyPalette (CompanyID company)
| Get the palette for recolouring with a company colour.
void | DrawCompanyIcon (CompanyID c, int x, int y)
| Draw the icon of a company.
static bool | IsValidCompanyManagerFace (CompanyManagerFace cmf)
| Checks whether a company manager's face is a valid encoding.
void | InvalidateCompanyWindows (const Company *company)
| Mark all finance windows owned by a company as needing a refresh.
Money | GetAvailableMoney (CompanyID company)
| Get the amount of money that a company has available, or INT64_MAX if there is no such valid company.
Money | GetAvailableMoneyForCommand ()
| This functions returns the money which can be used to execute a command.
bool | CheckCompanyHasMoney (CommandCost &cost)
| Verify whether the company can pay the bill.
static void | SubtractMoneyFromAnyCompany (Company *c, const CommandCost &cost)
| Deduct costs of a command from the money of a company.
void | SubtractMoneyFromCompany (const CommandCost &cost)
| Subtract money from the _current_company, if the company is valid.
void | SubtractMoneyFromCompanyFract (CompanyID company, const CommandCost &cst)
| Subtract money from a company, including the money fraction.
static constexpr void | UpdateLandscapingLimit (uint32_t &limit, uint64_t per_64k_frames, uint64_t burst)
void | UpdateLandscapingLimits ()
| Update the landscaping limits per company.
std::array< StringParameter, 2 > | GetParamsForOwnedBy (Owner owner, TileIndex tile)
| Set the right DParams for STR_ERROR_OWNED_BY.
CommandCost | CheckOwnership (Owner owner, TileIndex tile)
| Check whether the current owner owns something.
CommandCost | CheckTileOwnership (TileIndex tile)
| Check whether the current owner owns the stuff on the given tile.
static void | GenerateCompanyName (Company *c)
| Generate the name of a company from the last build coordinate.
static Colours | GenerateCompanyColour ()
| Generate a company colour.
static void | GeneratePresidentName (Company *c)
| Generate a random president name of a company.
void | ResetCompanyLivery (Company *c)
| Reset the livery schemes to the company's primary colour.
Company * | DoStartupNewCompany (bool is_ai, CompanyID company=CompanyID::Invalid())
| Create a new company and sets all company variables default values.
void | StartupCompanies ()
| Start of a new game.
void | InitializeCompanies ()
| Initialize the pool of companies.
bool | CheckTakeoverVehicleLimit (CompanyID cbig, CompanyID csmall)
| Can company cbig buy company csmall without exceeding vehicle limits?
static void | HandleBankruptcyTakeover (Company *c)
| Handle the bankruptcy take over of a company.
void | OnTick_Companies ()
| Called every tick for updating some company info.
void | CompanyAdminUpdate (const Company *company)
| Called whenever company related information changes in order to notify admins.
void | CompanyAdminRemove (CompanyID company_id, CompanyRemoveReason reason)
| Called whenever a company is removed in order to notify admins.
CommandCost | CmdCompanyCtrl (DoCommandFlags flags, CompanyCtrlAction cca, CompanyID company_id, CompanyRemoveReason reason, ClientID client_id)
| Control the companies: add, delete, etc.
static bool | ExecuteAllowListCtrlAction (CompanyAllowListCtrlAction action, Company *c, const std::string &public_key)
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.
CommandCost | CmdSetCompanyManagerFace (DoCommandFlags flags, uint style, uint32_t bits)
| Change the company manager's face.
void | UpdateCompanyLiveries (Company *c)
| Update liveries for a company.
CommandCost | CmdSetCompanyColour (DoCommandFlags flags, LiveryScheme scheme, bool primary, Colours colour)
| Change the company's company-colour.
static bool | IsUniqueCompanyName (const std::string &name)
| Is the given name in use as name of a company?
CommandCost | CmdRenameCompany (DoCommandFlags flags, const std::string &text)
| Change the name of the company.
static bool | IsUniquePresidentName (const std::string &name)
| Is the given name in use as president name of a company?
CommandCost | CmdRenamePresident (DoCommandFlags flags, const std::string &text)
| Change the name of the president.
int | CompanyServiceInterval (const Company *c, VehicleType type)
| Get the service interval for the given company and vehicle type.
CommandCost | CmdGiveMoney (DoCommandFlags flags, Money money, CompanyID dest_company)
| Transfer funds (money) from one company to another.
CompanyID | GetFirstPlayableCompanyID ()
| Get the index of the first available company.
void | ResetFaces ()
| Reset company manager face styles to default.
uint | GetNumCompanyManagerFaceStyles ()
| Get the number of company manager face styles.
const FaceSpec * | GetCompanyManagerFaceSpec (uint style_index)
| Get the definition of a company manager face style.
std::optional< uint > | FindCompanyManagerFaceLabel (std::string_view label)
| Find a company manager face style by label.
FaceVars | GetCompanyManagerFaceVars (uint style)
| Get the face variables for a face style.
void | SetCompanyManagerFaceStyle (CompanyManagerFace &cmf, uint style)
| Set a company face style.
void | RandomiseCompanyManagerFace (CompanyManagerFace &cmf, Randomizer &randomizer)
| Completely randomise a company manager face, including style.
uint32_t | MaskCompanyManagerFaceBits (const CompanyManagerFace &cmf, FaceVars vars)
| Mask company manager face bits to ensure they are all within range.
std::string | FormatCompanyManagerFaceCode (const CompanyManagerFace &cmf)
| Get a face code representation of a company manager face.
std::optional< CompanyManagerFace > | ParseCompanyManagerFaceCode (std::string_view str)
| Parse a face code into a company manager face.

## Variables
CompanyID | _local_company
| Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID | _current_company
| Company currently doing an action.
TypedIndexContainer< std::array< Colours, MAX_COMPANIES >, CompanyID > | _company_colours
| NOSAVE: can be determined from company structs.
std::string | _company_manager_face
| for company manager face storage in openttd.cfg
uint | _cur_company_tick_index
| used to generate a name for one company that doesn't have a name yet per tick
CompanyPool | _company_pool ("Company")
| Pool of companies.
static CompanyMask | _dirty_company_finances {}
| Bitmask of company finances that should be marked dirty.
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.
static const uint8_t | _colour_sort [COLOUR_END] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1}
| Sorting weights for the company colours.
static const Colours | _similar_colour [COLOUR_END][2]
| Similar colours, so we can try to prevent same coloured companies.
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.
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 window of the local company.
static std::vector< FaceSpec > | _faces
| All company manager face styles.

## Detailed Description

Handling of companies.

Definition in file company_cmd.cpp.

## Function Documentation

## ◆ CheckCompanyHasMoney()

bool CheckCompanyHasMoney | ( | CommandCost & | cost | ) |

Verify whether the company can pay the bill.

Parameters

  [in,out] | cost | Money to pay, is changed to an error if the company does not have enough money.

Returns
  Function returns `true` if the company has enough money or infinite money is enabled, else it returns `false`.

Definition at line 263 of file company_cmd.cpp.

References _current_company, _settings_game, GameSettings::difficulty, CommandCost::GetCost(), GetEncodedString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), DifficultySettings::infinite_money, IsLocalCompany(), CommandCost::MakeError(), CompanyProperties::money, and CommandCost::SetEncodedMessage().

Referenced by CmdCloneVehicle(), CommandHelperBase::InternalDoAfter(), and CommandHelperBase::InternalExecuteValidateTestAndPrepExec().

## ◆ CheckOwnership()

CommandCost CheckOwnership | ( | Owner | owner,
|  | TileIndex | tile
| ) |  |

Check whether the current owner owns something.

If that isn't the case an appropriate error will be given.

Parameters

  owner | the owner of the thing to check.
  tile | optional tile to get the right town.

Precondition
  if tile == 0 then the owner can't be OWNER_TOWN.

Returns
  A succeeded command iff it's owned by the current company, else a failed command.

Definition at line 381 of file company_cmd.cpp.

References _current_company, GetEncodedStringWithArgs(), GetParamsForOwnedBy(), IsLocalCompany(), OWNER_END, and OWNER_TOWN.

Referenced by CanRemoveRoadWithStop(), CheckAllowRemoveRoad(), CheckAllowRemoveTunnelBridge(), CheckFlatLandRoadStop(), CheckTileOwnership(), CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdBuildObject(), CmdBuildRoad(), CmdBuildSingleRail(), CmdBulkChangeTimetable(), CmdChangeServiceInt(), CmdChangeTimetable(), CmdCloneOrder(), CmdCloneVehicle(), CmdConvertRoad(), CmdDeleteOrder(), CmdForceTrainProceed(), CmdInsertOrder(), CmdModifyOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdMoveStationName(), CmdMoveWaypointName(), CmdOpenCloseAirport(), CmdOrderRefit(), CmdRefitVehicle(), CmdRenameStation(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdReverseTrainDirection(), CmdSellVehicle(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdTurnRoadVeh(), IsValidTileForWaypoint(), RemoveAirport(), RemoveDock(), RemoveFromRailBaseStation(), RemoveRailStation(), RemoveRoadStop(), RemoveRoadWaypointStop(), and Vehicle::SendToDepot().

## ◆ CheckTakeoverVehicleLimit()

bool CheckTakeoverVehicleLimit | ( | CompanyID | cbig,
|  | CompanyID | csmall
| ) |  |

Can company cbig buy company csmall without exceeding vehicle limits?

Parameters

  cbig | Company buying csmall.
  csmall | Company getting bought.

Returns
  Return `true` if it is allowed.

Definition at line 695 of file company_cmd.cpp.

References _settings_game, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), Company::group_all, VehicleSettings::max_aircraft, VehicleSettings::max_roadveh, VehicleSettings::max_ships, VehicleSettings::max_trains, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and GameSettings::vehicle.

Referenced by CmdBuyCompany(), and HandleBankruptcyTakeover().

## ◆ CheckTileOwnership()

CommandCost CheckTileOwnership | ( | TileIndex | tile | ) |

Check whether the current owner owns the stuff on the given tile.

If that isn't the case an appropriate error will be given.

Parameters

  tile | the tile to check.

Returns
  A succeeded command iff it's owned by the current company, else a failed command.

Definition at line 404 of file company_cmd.cpp.

References CheckOwnership(), and GetTileOwner().

Referenced by CheckAllowRemoveTunnelBridge(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuildTrainDepot(), CmdConvertRail(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), CmdRenameDepot(), and RemoveLock().

## ◆ ClearEnginesHiddenFlagOfCompany()

void ClearEnginesHiddenFlagOfCompany | ( | CompanyID | cid | ) |

Clear the 'hidden' flag for all engines of a new company.

Parameters

  cid | Company being created.

Definition at line 1004 of file engine.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate().

Referenced by DoStartupNewCompany().

## ◆ 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.

Parameters

  flags | Operation to perform.
  action | The action to perform.
  public_key | The public key of the client to add or remove.

Returns
  The cost of this operation or an error.

Definition at line 1023 of file company_cmd.cpp.

References _current_company, CALCA_ADD, CALCA_REMOVE, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), InvalidateWindowData(), NETWORK_PUBLIC_KEY_LENGTH, SetWindowDirty(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), WC_CLIENT_LIST, and WC_COMPANY.

## ◆ CmdCompanyCtrl()

CommandCost CmdCompanyCtrl | ( | DoCommandFlags | flags,
|  | CompanyCtrlAction | cca,
|  | CompanyID | company_id,
|  | CompanyRemoveReason | reason,
|  | ClientID | client_id
| ) |  |

Control the companies: add, delete, etc.

Parameters

  flags | operation to perform
  cca | action to perform
  company_id | company to perform the action on
  client_id | ClientID

Returns
  the cost of this operation or an error

Definition at line 881 of file company_cmd.cpp.

References _company_manager_face, _local_company, _network_own_client_id, _network_server, _networking, AI::BroadcastNewEvent(), CCA_DELETE, CCA_NEW, CCA_NEW_AI, ChangeOwnershipOfCompanyItems(), NetworkClientInfo::client_id, NetworkClientInfo::client_playas, CloseWindowById(), CMD_ERROR, COMPANY_SPECTATOR, CompanyAdminRemove(), CRR_END, DoStartupNewCompany(), Execute, NetworkClientInfo::GetByClientID(), GetEncodedString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_goal_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_story_page_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, INVALID_OWNER, InvalidateWindowClassesData(), InvalidateWindowData(), CompanyProperties::is_ai, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), MarkWholeScreenDirty(), NetworkAdminCompanyNew(), NetworkServerNewCompany(), NetworkUpdateClientInfo(), Game::NewEvent(), ParseCompanyManagerFaceCode(), SetLocalCompany(), AI::Stop(), SyncCompanySettings(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), WC_CLIENT_LIST, WC_COMPANY_LEAGUE, WC_GAME_OPTIONS, WC_MAIN_TOOLBAR, WC_NETWORK_STATUS_WINDOW, WC_SCRIPT_LIST, WC_SCRIPT_SETTINGS, and WN_NETWORK_STATUS_WINDOW_JOIN.

## ◆ CmdGiveMoney()

CommandCost CmdGiveMoney | ( | DoCommandFlags | flags,
|  | Money | money,
|  | CompanyID | dest_company
| ) |  |

Transfer funds (money) from one company to another.

To prevent abuse in multiplayer games you can only send money to other companies if you have paid off your loan (either explicitly, or implicitly given the fact that you have more money than loan).

Parameters

  flags | operation to perform
  money | the amount of money to transfer; max 20.000.000
  dest_company | the company to transfer the money to

Returns
  the cost of this operation or an error

Definition at line 1316 of file company_cmd.cpp.

References _current_company, _networking, _settings_game, CMD_ERROR, CompanyProperties::current_loan, GameSettings::economy, Execute, EXPENSES_OTHER, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), CommandCost::GetCost(), GetDrawStringCompanyColour(), GetString(), EconomySettings::give_money, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), CompanyProperties::money, Backup< T >::Restore(), SubtractMoneyFromCompany(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

## ◆ CmdRenameCompany()

CommandCost CmdRenameCompany | ( | DoCommandFlags | flags,
|  | const std::string & | text
| ) |  |

Change the name of the company.

Parameters

  flags | operation to perform
  text | the new name or an empty string when resetting to the default

Returns
  the cost of this operation or an error

Definition at line 1193 of file company_cmd.cpp.

References _current_company, AI::BroadcastNewEvent(), CMD_ERROR, CompanyAdminUpdate(), Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsUniqueCompanyName(), MarkWholeScreenDirty(), MAX_LENGTH_COMPANY_NAME_CHARS, CompanyProperties::name, Game::NewEvent(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Utf8StringLength().

## ◆ CmdRenamePresident()

CommandCost CmdRenamePresident | ( | DoCommandFlags | flags,
|  | const std::string & | text
| ) |  |

Change the name of the president.

Parameters

  flags | operation to perform
  text | the new name or an empty string when resetting to the default

Returns
  the cost of this operation or an error

Definition at line 1240 of file company_cmd.cpp.

References _current_company, AI::BroadcastNewEvent(), CMD_ERROR, CompanyAdminUpdate(), Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, InvalidateWindowClassesData(), IsUniquePresidentName(), MarkWholeScreenDirty(), MAX_LENGTH_PRESIDENT_NAME_CHARS, CompanyProperties::name, CompanyProperties::name_1, Game::NewEvent(), CompanyProperties::president_name, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Utf8StringLength(), and WC_COMPANY.

## ◆ CmdSetCompanyColour()

CommandCost CmdSetCompanyColour | ( | DoCommandFlags | flags,
|  | LiveryScheme | scheme,
|  | bool | primary,
|  | Colours | colour
| ) |  |

Change the company's company-colour.

Parameters

  flags | operation to perform
  scheme | scheme to set
  primary | set first/second colour
  colour | new colour for vehicles, property, etc.

Returns
  the cost of this operation or an error

Definition at line 1094 of file company_cmd.cpp.

References _company_colours, _current_company, BuildOwnerLegend(), CMD_ERROR, CompanyProperties::colour, CompanyAdminUpdate(), Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), MarkWholeScreenDirty(), Livery::Primary, Livery::Secondary, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), UpdateCompanyLiveries(), UpdateObjectColours(), WC_COMPANY_VALUE, WC_DELIVERED_CARGO, WC_INCOME_GRAPH, WC_LINKGRAPH_LEGEND, WC_OPERATING_PROFIT, WC_PERFORMANCE_HISTORY, and WC_SMALLMAP.

## ◆ CmdSetCompanyManagerFace()

CommandCost CmdSetCompanyManagerFace | ( | DoCommandFlags | flags,
|  | uint | style,
|  | uint32_t | bits
| ) |  |

Change the company manager's face.

Parameters

  flags | operation to perform
  style | The style of the company manager face.
  bits | The bits of company manager face.

Returns
  the cost of this operation or an error

Definition at line 1057 of file company_cmd.cpp.

References _current_company, CompanyManagerFace::bits, CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), IsValidCompanyManagerFace(), MarkWholeScreenDirty(), SetCompanyManagerFaceStyle(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

## ◆ CompanyAdminRemove()

void CompanyAdminRemove | ( | CompanyID | company_id,
|  | CompanyRemoveReason | reason
| ) |  |

Called whenever a company is removed in order to notify admins.

Parameters

  company_id | The company that was removed.
  reason | The reason the company was removed.

Definition at line 868 of file company_cmd.cpp.

References _network_server, and NetworkAdminCompanyRemove().

Referenced by CmdCompanyCtrl().

## ◆ CompanyAdminUpdate()

void CompanyAdminUpdate | ( | const Company * | company | ) |

Called whenever company related information changes in order to notify admins.

Parameters

  company | The company data changed of.

Definition at line 858 of file company_cmd.cpp.

References _network_server, and NetworkAdminCompanyUpdate().

Referenced by CmdRenameCompany(), CmdRenamePresident(), CmdSetCompanyColour(), and CompanyCheckBankrupt().

## ◆ CompanyServiceInterval()

int CompanyServiceInterval | ( | const Company * | c,
|  | VehicleType | type
| ) |  |

Get the service interval for the given company and vehicle type.

Parameters

  c | The company, or nullptr for client-default settings.
  type | The vehicle type to get the interval for.

Returns
  The service interval.

Definition at line 1280 of file company_cmd.cpp.

References _settings_client, ClientSettings::company, VehicleDefaultSettings::servint_aircraft, VehicleDefaultSettings::servint_roadveh, VehicleDefaultSettings::servint_ships, VehicleDefaultSettings::servint_trains, CompanyProperties::settings, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and CompanySettings::vehicle.

Referenced by ChangeOwnershipOfCompanyItems(), CmdChangeServiceInt(), and UpdateAllServiceInterval().

## ◆ DoStartupNewCompany()

Company * DoStartupNewCompany | ( | bool | is_ai,
|  | CompanyID | company = `CompanyID::Invalid()`
| ) |  |

Create a new company and sets all company variables default values.

Parameters

  is_ai | is an AI company?
  company | CompanyID to use for the new company

Returns
  the company struct

Definition at line 598 of file company_cmd.cpp.

References _company_colours, _company_manager_face, _network_server, _networking, _random, Company::avail_railtypes, Company::avail_roadtypes, AI::BroadcastNewEvent(), BuildOwnerLegend(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::CanAllocateItem(), ClearEnginesHiddenFlagOfCompany(), CompanyProperties::colour, CompanyProperties::current_loan, CompanyProperties::face, GenerateCompanyColour(), GeneratePresidentName(), GetCompanyRailTypes(), GetCompanyRoadTypes(), CompanyProperties::inaugurated_year, CompanyProperties::inaugurated_year_calendar, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Economy::inflation_prices, INITIAL_LOAN, InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), LOAN_INTERVAL, Economy::max_loan, CompanyProperties::money, Game::NewEvent(), ParseCompanyManagerFaceCode(), RandomiseCompanyManagerFace(), ResetCompanyLivery(), SetDefaultCompanySettings(), SetWindowDirty(), AI::StartNew(), WC_CLIENT_LIST, WC_GRAPH_LEGEND, WC_LINKGRAPH_LEGEND, WC_SMALLMAP, TimerGameCalendar::year, and TimerGameEconomy::year.

Referenced by AfterLoadGame(), and CmdCompanyCtrl().

## ◆ DrawCompanyIcon()

void DrawCompanyIcon | ( | CompanyID | c,
|  | int | x,
|  | int | y
| ) |  |

Draw the icon of a company.

Parameters

  c | Company that needs its icon drawn.
  x | Horizontal coordinate of the icon.
  y | Vertical coordinate of the icon.

Definition at line 175 of file company_cmd.cpp.

References DrawSprite(), and GetCompanyPalette().

Referenced by TownAuthorityWindow::DrawRatings(), GraphLegendWindow::DrawWidget(), PerformanceRatingDetailWindow::DrawWidget(), PerformanceLeagueWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), LinkGraphLegendWindow::DrawWidget(), SignListWindow::DrawWidget(), and ScriptDebugWindow::DrawWidgetCompanyButton().

## ◆ ExecuteAllowListCtrlAction()

static bool ExecuteAllowListCtrlAction | ( | CompanyAllowListCtrlAction | action,
|  | Company * | c,
|  | const std::string & | public_key
| ) |  |
| static

Definition at line 1002 of file company_cmd.cpp.

## ◆ FindCompanyManagerFaceLabel()

std::optional< uint > FindCompanyManagerFaceLabel | ( | std::string_view | label | ) |

Find a company manager face style by label.

Parameters

  label | Label to find.

Returns
  Index of face style if label is found, otherwise std::nullopt.

Definition at line 1409 of file company_cmd.cpp.

References _faces.

Referenced by AfterLoadGame(), and ParseCompanyManagerFaceCode().

## ◆ FormatCompanyManagerFaceCode()

std::string FormatCompanyManagerFaceCode | ( | const CompanyManagerFace & | cmf | ) |

Get a face code representation of a company manager face.

Parameters

  cmf | The company manager face.

Returns
  String containing face code.

Definition at line 1479 of file company_cmd.cpp.

References GetCompanyManagerFaceVars(), MaskCompanyManagerFaceBits(), CompanyManagerFace::style, and CompanyManagerFace::style_label.

Referenced by SelectCompanyManagerFaceWindow::OnClick().

## ◆ GenerateCompanyColour()

static Colours GenerateCompanyColour | ( |  | ) |
| static

Generate a company colour.

Returns
  Generated company colour.

Definition at line 492 of file company_cmd.cpp.

References _colour_sort, _similar_colour, GB(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), and Random.

Referenced by DoStartupNewCompany().

## ◆ GenerateCompanyName()

static void GenerateCompanyName | ( | Company * | c | ) |
| static

Generate the name of a company from the last build coordinate.

Parameters

  c | Company to give a name.

Definition at line 413 of file company_cmd.cpp.

References AddNewsItem(), AI::BroadcastNewEvent(), ClosestTownFromTile(), Company, CompanyInfo, GetEncodedString(), GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, CompanyProperties::is_ai, IsInsideMM(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), CompanyProperties::last_build_coordinate, MarkWholeScreenDirty(), MAX_LENGTH_COMPANY_NAME_CHARS, Town::name, CompanyProperties::name_1, CompanyProperties::name_2, Game::NewEvent(), CompanyProperties::president_name_1, CompanyProperties::president_name_2, Random, SPECSTR_ANDCO_NAME, SPECSTR_COMPANY_NAME_START, SPECSTR_PRESIDENT_NAME, SPECSTR_TOWNNAME_START, and Utf8StringLength().

Referenced by OnTick_Companies().

## ◆ GeneratePresidentName()

static void GeneratePresidentName | ( | Company * | c | ) |
| static

Generate a random president name of a company.

Parameters

  c | Company that needs a new president name.

Definition at line 547 of file company_cmd.cpp.

References GetString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), MAX_LENGTH_PRESIDENT_NAME_CHARS, CompanyProperties::president_name_1, CompanyProperties::president_name_2, Random, SPECSTR_PRESIDENT_NAME, and Utf8StringLength().

Referenced by DoStartupNewCompany().

## ◆ 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.

Parameters

  company | Company to check

Returns
  The available money of the company or INT64_MAX

Definition at line 238 of file company_cmd.cpp.

References _settings_game, GameSettings::difficulty, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), DifficultySettings::infinite_money, and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID().

Referenced by CompaniesPayInterest(), TownAuthorityWindow::DrawWidget(), GetAvailableMoneyForCommand(), GetMaskOfTownActions(), and Vehicle::NeedsServicing().

## ◆ GetAvailableMoneyForCommand()

Money GetAvailableMoneyForCommand | ( |  | ) |

This functions returns the money which can be used to execute a command.

This is either the money of the current company, or INT64_MAX if infinite money is enabled or there is no such a company "at the moment" like the server itself.

Returns
  The available money of the current company or INT64_MAX

Definition at line 252 of file company_cmd.cpp.

References _current_company, and GetAvailableMoney().

Referenced by CmdBuildObjectArea(), CmdClearArea(), CmdDecreaseLoan(), CmdFoundTown(), CmdLevelLand(), and CmdRemoveLongRoad().

## ◆ GetCompanyManagerFaceSpec()

const FaceSpec * GetCompanyManagerFaceSpec | ( | uint | style_index | ) |

Get the definition of a company manager face style.

Parameters

  style_index | Face style to get.

Returns
  Definition of face style.

Definition at line 1398 of file company_cmd.cpp.

References _faces, and GetNumCompanyManagerFaceStyles().

Referenced by ConvertFromOldCompanyManagerFace(), GetCompanyManagerFaceVars(), and SetCompanyManagerFaceStyle().

## ◆ GetCompanyManagerFaceVars()

FaceVars GetCompanyManagerFaceVars | ( | uint | style | ) |

Get the face variables for a face style.

Parameters

  style_index | Face style to get variables for.

Returns
  Variables for the face style.

Definition at line 1422 of file company_cmd.cpp.

References GetCompanyManagerFaceSpec().

Referenced by DrawCompanyManagerFace(), SelectCompanyManagerFaceWindow::DrawWidget(), FormatCompanyManagerFaceCode(), IsValidCompanyManagerFace(), SelectCompanyManagerFaceWindow::OnClick(), ParseCompanyManagerFaceCode(), RandomiseCompanyManagerFace(), and SelectCompanyManagerFaceWindow::UpdateData().

## ◆ GetCompanyPalette()

PaletteID GetCompanyPalette | ( | CompanyID | company | ) |

Get the palette for recolouring with a company colour.

Parameters

  company | Company to get the colour of.

Returns
  Palette for recolouring.

Definition at line 164 of file company_cmd.cpp.

References _company_colours, and GetColourPalette().

Referenced by CompanyButtonLine::Draw(), DrawCompanyIcon(), DrawNewObjectTileInGUI(), TownAuthorityWindow::DrawRatings(), DrawRoadDepotSprite(), DrawRoadStopTile(), DrawRoadTypeCatenary(), DrawStationTile(), DrawTile_Road(), DrawWaterDepot(), BuildAirportWindow::DrawWidget(), CompanyWindow::DrawWidget(), PickerWindow::DrawWidget(), and PickerWindow::OnClick().

## ◆ GetDrawStringCompanyColour()

TextColour GetDrawStringCompanyColour | ( | CompanyID | company | ) |

Get the colour for DrawString-subroutines which matches the colour of the company.

Parameters

  company | Company to get the colour of.

Returns
  Colour of company.

Definition at line 153 of file company_cmd.cpp.

References _company_colours, GetColourGradient(), and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID().

Referenced by CmdGiveMoney(), NetworkServerSendChat(), and ClientNetworkGameSocketHandler::Receive_SERVER_CHAT().

## ◆ GetFirstPlayableCompanyID()

CompanyID GetFirstPlayableCompanyID | ( |  | ) |

Get the index of the first available company.

It attempts, from first to last, and as soon as the attempt succeeds, to get the index of the company: 1st - get the first existing human company. 2nd - get the first non-existing company. 3rd - get CompanyID::Begin().

Returns
  the index of the first available company.

Definition at line 1354 of file company_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Company::IsHumanID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate().

Referenced by AfterLoadGame(), NetworkOnGameStart(), and OnStartGame().

## ◆ GetNumCompanyManagerFaceStyles()

uint GetNumCompanyManagerFaceStyles | ( |  | ) |

Get the number of company manager face styles.

Returns
  Number of face styles.

Definition at line 1388 of file company_cmd.cpp.

References _faces.

Referenced by SelectCompanyManagerFaceWindow::DrawWidget(), GetCompanyManagerFaceSpec(), IsValidCompanyManagerFace(), SelectCompanyManagerFaceWindow::OnClick(), and RandomiseCompanyManagerFace().

## ◆ GetParamsForOwnedBy()

std::array< StringParameter, 2 > GetParamsForOwnedBy | ( | Owner | owner,
|  | TileIndex | tile
| ) |  |

Set the right DParams for STR_ERROR_OWNED_BY.

Parameters

  owner | the owner to get the name of.
  tile | optional tile to get the right town.

Precondition
  if tile == 0, then owner can't be OWNER_TOWN.

Definition at line 358 of file company_cmd.cpp.

References ClosestTownFromTile(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), and OWNER_TOWN.

Referenced by CheckOwnership(), CmdConvertRoad(), and LandInfoWindow::OnInit().

## ◆ HandleBankruptcyTakeover()

static void HandleBankruptcyTakeover | ( | Company * | c | ) |
| static

Handle the bankruptcy take over of a company.

Companies going bankrupt will ask the other companies in order of their performance rating, so better performing companies get the 'do you want to merge with Y' question earlier. The question will then stay till either the company has gone bankrupt or got merged with a company.

Parameters

  c | the company that is going bankrupt.

Definition at line 716 of file company_cmd.cpp.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::All(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), CompanyProperties::bankrupt_asked, CompanyProperties::bankrupt_timeout, CheckTakeoverVehicleLimit(), Ticks::DAY_TICKS, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsInteractiveCompany(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), AI::NewEvent(), CompanyProperties::old_economy, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), ShowBuyCompanyDialog(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by OnTick_Companies().

## ◆ InitializeCompanies()

void InitializeCompanies | ( |  | ) |

Initialize the pool of companies.

Definition at line 684 of file company_cmd.cpp.

References _cur_company_tick_index.

## ◆ InvalidateCompanyWindows()

void InvalidateCompanyWindows | ( | const Company * | company | ) |

Mark all finance windows owned by a company as needing a refresh.

The actual refresh is deferred until the end of the gameloop to reduce duplicated work.

Parameters

  company | Company that changed, and needs its windows refreshed.

Definition at line 206 of file company_cmd.cpp.

References _dirty_company_finances, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().

Referenced by CmdDecreaseLoan(), CmdIncreaseLoan(), CmdSetCompanyMaxLoan(), and SubtractMoneyFromAnyCompany().

## ◆ IsUniqueCompanyName()

static bool IsUniqueCompanyName | ( | const std::string & | name | ) |
| static

Is the given name in use as name of a company?

Parameters

  name | Name to search.

Returns
  `true` if the name us unique (that is, not in use), else `false`.

Definition at line 1178 of file company_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), and CompanyProperties::name.

Referenced by CmdRenameCompany().

## ◆ IsUniquePresidentName()

static bool IsUniquePresidentName | ( | const std::string & | name | ) |
| static

Is the given name in use as president name of a company?

Parameters

  name | Name to search.

Returns
  `true` if the name us unique (that is, not in use), else `false`.

Definition at line 1225 of file company_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), and CompanyProperties::president_name.

Referenced by CmdRenamePresident().

## ◆ IsValidCompanyManagerFace()

static bool IsValidCompanyManagerFace | ( | CompanyManagerFace | cmf | ) |
| static

Checks whether a company manager's face is a valid encoding.

Unused bits are not enforced to be 0.

Parameters

  cmf | the fact to check

Returns
  true if and only if the face is valid

Definition at line 186 of file company_cmd.cpp.

References GetActiveFaceVars(), GetCompanyManagerFaceVars(), GetNumCompanyManagerFaceStyles(), and CompanyManagerFace::style.

Referenced by CmdSetCompanyManagerFace().

## ◆ MaskCompanyManagerFaceBits()

uint32_t MaskCompanyManagerFaceBits | ( | const CompanyManagerFace & | cmf,
|  | FaceVars | vars
| ) |  |

Mask company manager face bits to ensure they are all within range.

Note
  Does not update the CompanyManagerFace itself. Unused bits are cleared.

Parameters

  cmf | The CompanyManagerFace.
  style | The face variables.

Returns
  The masked face bits.

Definition at line 1463 of file company_cmd.cpp.

References CompanyManagerFace::bits, and GetActiveFaceVars().

Referenced by FormatCompanyManagerFaceCode(), and ParseCompanyManagerFaceCode().

## ◆ OnTick_Companies()

void OnTick_Companies | ( |  | ) |

Called every tick for updating some company info.

Definition at line 770 of file company_cmd.cpp.

References _cur_company_tick_index, _networking, _new_competitor_timeout, _settings_client, _settings_game, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), CompanyProperties::bankrupt_asked, AI::CanStartNew(), CCA_NEW_AI, DifficultySettings::competitors_interval, CRR_NONE, GameSettings::difficulty, GenerateCompanyName(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetNumItems(), HandleBankruptcyTakeover(), INVALID_CLIENT_ID, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), NetworkSettings::max_companies, DifficultySettings::max_no_competitors, CompanyProperties::name_1, ClientSettings::network, OWNER_NONE, and Ticks::TICKS_PER_SECOND.

## ◆ ParseCompanyManagerFaceCode()

std::optional< CompanyManagerFace > ParseCompanyManagerFaceCode | ( | std::string_view | str | ) |

Parse a face code into a company manager face.

Parameters

  str | Face code to parse.

Returns
  Company manager face, or std::nullopt if it could not be parsed.

Definition at line 1490 of file company_cmd.cpp.

References CompanyManagerFace::bits, FindCompanyManagerFaceLabel(), GB(), GetCompanyManagerFaceVars(), MaskCompanyManagerFaceBits(), StringConsumer::npos, ParseInteger(), StringConsumer::ReadUntilChar(), ScaleAllCompanyManagerFaceBits(), SetCompanyManagerFaceStyle(), StringConsumer::SKIP_ONE_SEPARATOR, and CompanyManagerFace::style.

Referenced by CmdCompanyCtrl(), DoStartupNewCompany(), SelectCompanyManagerFaceWindow::OnClick(), and SelectCompanyManagerFaceWindow::OnQueryTextFinished().

## ◆ RandomiseCompanyManagerFace()

void RandomiseCompanyManagerFace | ( | CompanyManagerFace & | cmf,
|  | Randomizer & | randomizer
| ) |  |

Completely randomise a company manager face, including style.

Note
  randomizer should passed be appropriate for server-side or client-side usage.

Parameters

  cmf | The CompanyManagerFace to randomise.
  randomizer | The randomizer to use.

Definition at line 1450 of file company_cmd.cpp.

References GetCompanyManagerFaceVars(), GetNumCompanyManagerFaceStyles(), Randomizer::Next(), RandomiseCompanyManagerFaceBits(), SetCompanyManagerFaceStyle(), and CompanyManagerFace::style.

Referenced by AfterLoadGame(), DoStartupNewCompany(), and SelectCompanyManagerFaceWindow::OnClick().

## ◆ ResetCompanyLivery()

void ResetCompanyLivery | ( | Company * | c | ) |

Reset the livery schemes to the company's primary colour.

This is used on loading games without livery information and on new company start up.

Parameters

  c | Company to reset.

Definition at line 574 of file company_cmd.cpp.

References CompanyProperties::colour, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Iterate().

Referenced by AfterLoadGame(), and DoStartupNewCompany().

## ◆ ResetFaces()

void ResetFaces | ( |  | ) |

Reset company manager face styles to default.

Definition at line 1378 of file company_cmd.cpp.

References _faces, and _original_faces.

Referenced by ResetNewGRFData().

## ◆ SetCompanyManagerFaceStyle()

void SetCompanyManagerFaceStyle | ( | CompanyManagerFace & | cmf,
|  | uint | style
| ) |  |

Set a company face style.

Changes both the style index and the label.

Parameters

  cmf | The CompanyManagerFace to change.
  style | The style to set.

Definition at line 1435 of file company_cmd.cpp.

References GetCompanyManagerFaceSpec(), CompanyManagerFace::style, and CompanyManagerFace::style_label.

Referenced by AfterLoadGame(), CmdSetCompanyManagerFace(), SelectCompanyManagerFaceWindow::OnClick(), ParseCompanyManagerFaceCode(), and RandomiseCompanyManagerFace().

## ◆ 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 core's state in the GUI.

Parameters

  new_company | the new company

Precondition
  Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE

Definition at line 119 of file company_cmd.cpp.

References _current_company, _local_company, CloseConstructionWindows(), COMPANY_SPECTATOR, DESTTYPE_TEAM, InvalidateWindowClassesData(), InvalidateWindowData(), IsLocalCompany(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), MarkWholeScreenDirty(), OWNER_NONE, WC_COMPANY, WC_COMPANY_COLOUR, WC_GOALS_LIST, WC_SEND_NETWORK_MSG, and WC_SIGN_LIST.

Referenced by ChangeOwnershipOfCompanyItems(), ClickChangeCompanyCheat(), CmdCompanyCtrl(), GenerateWorld(), LoadIntroGame(), NetworkClientsToSpectators(), NetworkServerDoMove(), OnStartGame(), ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), and ClientNetworkGameSocketHandler::Receive_SERVER_MOVE().

## ◆ StartupCompanies()

void StartupCompanies | ( |  | ) |

Start of a new game.

Definition at line 677 of file company_cmd.cpp.

References _new_competitor_timeout, and TimeoutTimer< TTimerType >::Abort().

Referenced by _GenerateWorld().

## ◆ SubtractMoneyFromAnyCompany()

static void SubtractMoneyFromAnyCompany | ( | Company * | c,
|  | const CommandCost & | cost
| ) |  |
| static

Deduct costs of a command from the money of a company.

Parameters

  c | Company to pay the bill.
  cost | Money to pay.

Definition at line 284 of file company_cmd.cpp.

References CompanyProperties::cur_economy, CompanyEconomyEntry::expenses, EXPENSES_AIRCRAFT_REVENUE, EXPENSES_AIRCRAFT_RUN, EXPENSES_LOAN_INTEREST, EXPENSES_PROPERTY, EXPENSES_ROADVEH_REVENUE, EXPENSES_ROADVEH_RUN, EXPENSES_SHIP_REVENUE, EXPENSES_SHIP_RUN, EXPENSES_TRAIN_REVENUE, EXPENSES_TRAIN_RUN, CommandCost::GetCost(), CommandCost::GetExpensesType(), HasBit(), CompanyEconomyEntry::income, INVALID_EXPENSES, InvalidateCompanyWindows(), CompanyProperties::money, and CompanyProperties::yearly_expenses.

Referenced by SubtractMoneyFromCompany(), and SubtractMoneyFromCompanyFract().

## ◆ SubtractMoneyFromCompany()

void SubtractMoneyFromCompany | ( | const CommandCost & | cost | ) |

Subtract money from the _current_company, if the company is valid.

Parameters

  cost | Money to pay.

Definition at line 313 of file company_cmd.cpp.

References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), and SubtractMoneyFromAnyCompany().

Referenced by CmdChangeBankBalance(), CmdGiveMoney(), CompaniesGenStatistics(), CompaniesPayInterest(), CommandHelperBase::InternalDoAfter(), and CommandHelperBase::InternalExecuteProcessResult().

## ◆ SubtractMoneyFromCompanyFract()

void SubtractMoneyFromCompanyFract | ( | CompanyID | company,
|  | const CommandCost & | cst
| ) |  |

Subtract money from a company, including the money fraction.

Parameters

  company | Company paying the bill.
  cst | Cost of a command.

Definition at line 324 of file company_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), CommandCost::GetCost(), CommandCost::GetExpensesType(), CompanyProperties::money_fraction, and SubtractMoneyFromAnyCompany().

Referenced by Aircraft::OnNewEconomyDay(), RoadVehicle::OnNewEconomyDay(), Ship::OnNewEconomyDay(), and Train::OnNewEconomyDay().

## ◆ UpdateCompanyLiveries()

void UpdateCompanyLiveries | ( | Company * | c | ) |

Update liveries for a company.

This is called when the LS_DEFAULT scheme is changed, to update schemes with colours set to default.

Parameters

  c | Company to update.

Definition at line 1077 of file company_cmd.cpp.

References Livery::Primary, Livery::Secondary, and UpdateCompanyGroupLiveries().

Referenced by AfterLoadGame(), and CmdSetCompanyColour().

## ◆ UpdateLandscapingLimit()

static constexpr void UpdateLandscapingLimit | ( | uint32_t & | limit,
|  | uint64_t | per_64k_frames,
|  | uint64_t | burst
| ) |  |
| staticconstexpr

Definition at line 336 of file company_cmd.cpp.

## ◆ UpdateLandscapingLimits()

void UpdateLandscapingLimits | ( |  | ) |

Update the landscaping limits per company.

Definition at line 342 of file company_cmd.cpp.

References _settings_game, ConstructionSettings::build_object_frame_burst, ConstructionSettings::build_object_per_64k_frames, ConstructionSettings::clear_frame_burst, ConstructionSettings::clear_per_64k_frames, GameSettings::construction, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), ConstructionSettings::terraform_frame_burst, ConstructionSettings::terraform_per_64k_frames, ConstructionSettings::tree_frame_burst, and ConstructionSettings::tree_per_64k_frames.

Referenced by StateGameLoop().

## ◆ UpdateObjectColours()

void UpdateObjectColours | ( | const Company * | c | ) |

Updates the colour of the object whenever a company changes.

Parameters

  c | The company the company colour changed of.

Definition at line 184 of file object_cmd.cpp.

References ObjectSpec::callback_mask, Colour, ObjectSpec::flags, ObjectSpec::GetByTile(), Company::GetCompanyRecolourOffset(), GetTileOwner(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::Iterate(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Uses2CC.

Referenced by CmdSetCompanyColour().

## Variable Documentation

## ◆ _colour_sort

const uint8_t _colour_sort[COLOUR_END] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1}
| static

Sorting weights for the company colours.

Definition at line 467 of file company_cmd.cpp.

Referenced by GenerateCompanyColour().

## ◆ _company_colours

TypedIndexContainer<std::array<Colours, MAX_COMPANIES>, CompanyID> _company_colours

NOSAVE: can be determined from company structs.

Definition at line 57 of file company_cmd.cpp.

Referenced by CmdSetCompanyColour(), DoStartupNewCompany(), DrawCaption(), GetCompanyPalette(), GetDrawStringCompanyColour(), PLYRChunkHandler::Load(), ViewportAddSignStrings(), and ViewportAddStationStrings().

## ◆ _company_manager_face

std::string _company_manager_face

for company manager face storage in openttd.cfg

Definition at line 58 of file company_cmd.cpp.

Referenced by CmdCompanyCtrl(), DoStartupNewCompany(), and SelectCompanyManagerFaceWindow::OnClick().

## ◆ _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 at line 59 of file company_cmd.cpp.

Referenced by InitializeCompanies(), and OnTick_Companies().

## ◆ _current_company

CompanyID _current_company

Company currently doing an action.

Definition at line 56 of file company_cmd.cpp.

Referenced by _GenerateWorld(), Station::AddFacility(), AfterLoadGame(), AutoslopeEnabled(), BuildReplacementVehicle(), BuildStationPart(), CanBuildTramTrackOnTile(), CanRemoveRoadWithStop(), CcAI(), CcCreateGroup(), ChangeOwnershipOfCompanyItems(), ChangeTownRating(), CheckAllowRemoveRoad(), CheckAllowRemoveTunnelBridge(), CheckClearTile(), CheckCompanyHasMoney(), CheckforTownRating(), CheckIfAuthorityAllowsNewStation(), CheckIfCanLevelIndustryPlatform(), CheckIfIndustryTilesAreFree(), CheckOwnership(), ChopLumberMillTrees(), ClearTile_Town(), CmdAddSharedVehicleGroup(), CmdAddVehicleGroup(), CmdAlterGroup(), CmdAutoreplaceVehicle(), CmdBuildAircraft(), CmdBuildBridge(), CmdBuildCanal(), CmdBuildDock(), CmdBuildIndustry(), CmdBuildObject(), CmdBuildObjectArea(), CmdBuildRailStation(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildRoadVehicle(), CmdBuildRoadWaypoint(), CmdBuildShip(), CmdBuildShipDepot(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuildTrainDepot(), CmdBuildTunnel(), CmdBuildVehicle(), CmdBuyCompany(), CmdChangeBankBalance(), CmdChangeCompanySetting(), CmdClearArea(), CmdCompanyAllowListCtrl(), CmdConvertRoad(), CmdCreateGoal(), CmdCreateGroup(), CmdCreateLeagueTable(), CmdCreateLeagueTableElement(), CmdCreateStoryPage(), CmdCreateStoryPageElement(), CmdCreateSubsidy(), CmdCustomNewsItem(), CmdDecreaseLoan(), CmdDeleteGroup(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdDoTownAction(), CmdEngineCtrl(), CmdExpandTown(), CmdFoundTown(), CmdGiveMoney(), CmdGoalQuestion(), CmdGoalQuestionAnswer(), CmdIncreaseLoan(), CmdIndustrySetExclusivity(), CmdIndustrySetFlags(), CmdIndustrySetProduction(), CmdIndustrySetText(), CmdLandscapeClear(), CmdLevelLand(), CmdMassStartStopVehicle(), CmdMoveRailVehicle(), CmdMoveSign(), CmdPlaceSign(), CmdPlantTree(), CmdRemoveAllVehiclesGroup(), CmdRemoveGoal(), CmdRemoveLeagueTableElement(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), CmdRemoveStoryPage(), CmdRemoveStoryPageElement(), CmdRenameCompany(), CmdRenamePresident(), CmdRenameSign(), CmdScrollViewport(), CmdSetAutoReplace(), CmdSetCompanyColour(), CmdSetCompanyManagerFace(), CmdSetCompanyMaxLoan(), CmdSetGoalCompleted(), CmdSetGoalDestination(), CmdSetGoalProgress(), CmdSetGoalText(), CmdSetGroupFlag(), CmdSetGroupLivery(), CmdSetStoryPageDate(), CmdSetStoryPageTitle(), CmdSetVehicleVisibility(), CmdShowStoryPage(), CmdStoryPageButton(), CmdTerraformLand(), CmdTownCargoGoal(), CmdTownGrowthRate(), CmdTownRating(), CmdTownSetText(), CmdUpdateLeagueTableElementData(), CmdUpdateLeagueTableElementScore(), CmdUpdateStoryPageElement(), CmdWantEnginePreview(), CompaniesGenStatistics(), CompaniesPayInterest(), CompanyCanEditSign(), ConvertRoadTypeOwner(), CountArticulatedParts(), CreateRandomTown(), AIInstance::Died(), DoBuildLock(), DoDryUp(), DoFloodTile(), CrashLog::FillCrashLog(), ObjectPickerCallbacks::FillUsedItems(), FindJoiningBaseStation(), FloodHalftile(), AI::GameLoop(), Game::GameLoop(), ScriptInstance::GameLoop(), GetAvailableMoneyForCommand(), RefitWindow::GetCapacityString(), GetClosestDeletedStation(), GetDefaultServiceInterval(), GetFreeUnitNumber(), GetMaskOfTownActions(), GetNewEngineType(), GetRating(), AIInstance::GetSetting(), GetTileHighlightType(), VehicleScopeResolver::GetVariable(), ObjectScopeResolver::GetVariable(), RoadStopScopeResolver::GetVariable(), StationScopeResolver::GetVariable(), GrowTown(), HandleStationRefit(), AIInstance::Initialize(), CommandHelperBase::InternalExecutePrepTest(), CommandHelperBase::InternalExecuteProcessResult(), CommandHelperBase::InternalExecuteValidateTestAndPrepExec(), IsLocalCompany(), AI::IsPaused(), LiveryHelper(), CommandHelperBase::LogCommandExecution(), VideoDriver_Dedicated::MainLoop(), NetworkClientsToSpectators(), Game::NewEvent(), AI::NewEvent(), BuildVehicleWindow::OnClick(), LandInfoWindow::OnInit(), BuildIndustryWindow::OnPlaceObject(), AI::Pause(), PlaceInitialIndustry(), RemoveAirport(), RemoveBuoy(), RemoveFromRailBaseStation(), RemoveGenericRoadStop(), RemoveRailStation(), RemoveRailStation(), RemoveRailWaypoint(), RemoveRoad(), RemoveRoadStop(), RemoveRoadWaypointStop(), Game::Save(), AI::Save(), ServiceIntervalSettingsValueText(), SetDefaultCompanySettings(), SetLocalCompany(), Game::StartNew(), AI::StartNew(), StateGameLoop(), AI::Stop(), SubtractMoneyFromCompany(), SyncCompanySettings(), TileLoop_Town(), TownActionAdvertiseLarge(), TownActionAdvertiseMedium(), TownActionAdvertiseSmall(), TownActionBribe(), TownActionBuildStatue(), TownActionBuyRights(), TownActionRoadRebuild(), Game::Uninitialize(), AI::Unpause(), UpdateAllServiceInterval(), ValParamRailType(), ValParamRoadType(), and VehicleEnterDepot().

## ◆ _dirty_company_finances

CompanyMask _dirty_company_finances {}
| static

Bitmask of company finances that should be marked dirty.

Definition at line 199 of file company_cmd.cpp.

Referenced by InvalidateCompanyWindows().

## ◆ _faces

std::vector<FaceSpec> _faces
| static

All company manager face styles.

Definition at line 1373 of file company_cmd.cpp.

Referenced by FindCompanyManagerFaceLabel(), GetCompanyManagerFaceSpec(), GetNumCompanyManagerFaceStyles(), and ResetFaces().

## ◆ _local_company

CompanyID _local_company

Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.

Definition at line 55 of file company_cmd.cpp.

Referenced by _GenerateWorld(), AddNearbyStation(), AgeVehicle(), AircraftEntersTerminal(), AircraftHandleDestTooFar(), CanBuildVehicleInfrastructure(), CcStartStopVehicle(), ChangeOwnershipOfCompanyItems(), CheckOrders(), ClickChangeCompanyCheat(), CmdBuildBridge(), CmdBuyCompany(), CmdCompanyCtrl(), CmdCustomNewsItem(), CmdGoalQuestion(), CmdGoalQuestionAnswer(), CmdScrollViewport(), CmdShowStoryPage(), CompanyCheckBankrupt(), CrashAirplane(), DisableEngineForCompany(), DrawEngineList(), DrawNewObjectTileInGUI(), DrawRoadDepotSprite(), DrawRoadStopTile(), DrawStationTile(), BuildAirportWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), EnginePreviewWindow::DrawWidget(), NewsWindow::DrawWidget(), PickerWindow::DrawWidget(), StatusBarWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), EnableEngineForCompany(), CrashLog::FillCrashLog(), StationPickerCallbacks::FillUsedItems(), WaypointPickerCallbacks::FillUsedItems(), RoadStopPickerCallbacks< roadstoptype >::FillUsedItems(), RoadWaypointPickerCallbacks::FillUsedItems(), FindStationsAroundSelection(), FindStationsNearby(), GenerateDefaultSaveName(), ReplaceVehicleWindow::GenerateLists(), ReplaceVehicleWindow::GenerateReplaceVehList(), GenerateWorld(), RefitWindow::GetCapacityString(), GetEngineLivery(), GetOrderCmdFromTile(), SmallMapWindow::GetOverlayCompanyMask(), GetRailTypeDropDownList(), ReplaceVehicleWindow::GetWidgetString(), BuildVehicleWindow::GetWidgetString(), HandleClickOnSign(), Vehicle::HandlePathfindingResult(), CommandHelperBase::InternalExecuteProcessResult(), InvalidateAutoreplaceWindow(), IsInteractiveCompany(), IsLocalCompany(), VehicleDetailsWindow::IsVehicleServiceIntervalEnabled(), LoadUnloadVehicle(), VideoDriver_Dedicated::MainLoop(), MakeScreenshotName(), NetworkClientsToSpectators(), NetworkServerSendChat(), ReplaceVehicleWindow::OnClick(), BuildVehicleWindow::OnClick(), CompanyWindow::OnClick(), GoalListWindow::OnClick(), OrdersWindow::OnClick(), PickerWindow::OnClick(), StatusBarWindow::OnClick(), SelectCompanyLiveryWindow::OnDropdownSelect(), OrdersWindow::OnHotkey(), MainToolbarWindow::OnHotkey(), LandInfoWindow::OnInit(), SelectCompanyLiveryWindow::OnInvalidateData(), EnginePreviewWindow::OnInvalidateData(), GoalListWindow::OnInvalidateData(), ScriptDebugWindow::OnInvalidateData(), WaypointWindow::OnInvalidateData(), ReplaceVehicleWindow::OnPaint(), CompanyFinancesWindow::OnPaint(), SelectCompanyLiveryWindow::OnPaint(), CompanyWindow::OnPaint(), DepotWindow::OnPaint(), VehicleGroupWindow::OnPaint(), EndGameWindow::OnPaint(), OrdersWindow::OnPaint(), StationViewWindow::OnPaint(), TimetableWindow::OnPaint(), MainToolbarWindow::OnPaint(), TownAuthorityWindow::OnPaint(), VehicleListWindow::OnPaint(), VehicleDetailsWindow::OnPaint(), VehicleViewWindow::OnPaint(), SignList::OwnerVisibilityFilter(), Vehicle::PreDestructor(), RoadVehArrivesAt(), SaveHighScoreValueNetwork(), SetDefaultRailGui(), SetLocalCompany(), SetSettingValue(), CompanyFinancesWindow::SetupWidgets(), ShipArrivesAt(), ShowBuildAirToolbar(), ShowBuildDocksToolbar(), ShowBuildRailToolbar(), ShowBuildRoadToolbar(), ShowEndGameChart(), ShowTerraformToolbar(), SyncCompanySettings(), TownDirectoryWindow::TownRatingSorter(), TrainEnterStation(), UpdateStationAcceptance(), VehicleEnterDepot(), and WhoCanServiceIndustry().

## ◆ _similar_colour

const Colours _similar_colour[COLOUR_END][2]
| static

Initial value:
= {
{ COLOUR_BLUE, COLOUR_LIGHT_BLUE },
{ COLOUR_GREEN, COLOUR_DARK_GREEN },
{ INVALID_COLOUR, INVALID_COLOUR },
{ COLOUR_ORANGE, INVALID_COLOUR },
{ INVALID_COLOUR, INVALID_COLOUR },
{ COLOUR_DARK_BLUE, COLOUR_BLUE },
{ COLOUR_PALE_GREEN, COLOUR_DARK_GREEN },
{ COLOUR_PALE_GREEN, COLOUR_GREEN },
{ COLOUR_DARK_BLUE, COLOUR_LIGHT_BLUE },
{ COLOUR_BROWN, COLOUR_ORANGE },
{ COLOUR_PURPLE, INVALID_COLOUR },
{ COLOUR_MAUVE, INVALID_COLOUR },
{ COLOUR_YELLOW, COLOUR_CREAM },
{ COLOUR_CREAM, INVALID_COLOUR },
{ COLOUR_WHITE, INVALID_COLOUR },
{ COLOUR_GREY, INVALID_COLOUR },
}

Similar colours, so we can try to prevent same coloured companies.

Definition at line 469 of file company_cmd.cpp.

Referenced by GenerateCompanyColour().