OpenTTD Source: src/company_func.h File Reference

OpenTTD Source 14.0-beta3

Functions | Variables
company_func.h File Reference
`#include "command_type.h"`
`#include "company_type.h"`
`#include "gfx_type.h"`
`#include "vehicle_type.h"`

Go to the source code of this file.

## Functions
bool | MayCompanyTakeOver (CompanyID cbig, CompanyID small)
| May company cbig buy company csmall? More...
void | ChangeOwnershipOfCompanyItems (Owner old_owner, Owner new_owner)
| Change the ownership of all the items of a company. More...
void | SetDParamsForOwnedBy (Owner owner, TileIndex tile)
| Set the right DParams for STR_ERROR_OWNED_BY. More...
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. More...
void | ShowBuyCompanyDialog (CompanyID company, bool hostile_takeover)
| Show the query to buy another company. More...
void | CompanyAdminUpdate (const Company *company)
| Called whenever company related information changes in order to notify admins. More...
void | CompanyAdminBankrupt (CompanyID company_id)
void | UpdateLandscapingLimits ()
| Update the landscaping limits per company.
void | UpdateCompanyLiveries (Company *c)
| Update liveries for a company. More...
Money | GetAvailableMoney (CompanyID company)
| Get the amount of money that a company has available, or INT64_MAX if there is no such valid company. More...
Money | GetAvailableMoneyForCommand ()
| This functions returns the money which can be used to execute a command. More...
bool | CheckCompanyHasMoney (CommandCost &cost)
| Verify whether the company can pay the bill. More...
void | SubtractMoneyFromCompany (const CommandCost &cost)
| Subtract money from the _current_company, if the company is valid. More...
void | SubtractMoneyFromCompanyFract (CompanyID company, const CommandCost &cost)
| Subtract money from a company, including the money fraction. More...
CommandCost | CheckOwnership (Owner owner, TileIndex tile=0U)
| Check whether the current owner owns something. More...
CommandCost | CheckTileOwnership (TileIndex tile)
| Check whether the current owner owns the stuff on the given tile. More...
bool | IsLocalCompany ()
| Is the current company the local company? More...
bool | IsInteractiveCompany (CompanyID company)
| Is the user representing company? More...
int | CompanyServiceInterval (const Company *c, VehicleType type)
| Get the service interval for the given company and vehicle type. More...
CompanyID | GetFirstPlayableCompanyID ()
| Get the index of the first available company. More...

## Variables
static const int | OWNED_BY_OWNER_IN_PARAMETERS_OFFSET = 2
| The index in the parameters for the owner information.
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.
Colours | _company_colours [MAX_COMPANIES]
| NOSAVE: can be determined from company structs.
CompanyManagerFace | _company_manager_face
| for company manager face storage in openttd.cfg

## Detailed Description

Functions related to companies.

Definition in file company_func.h.

## Function Documentation

## ◆ ChangeOwnershipOfCompanyItems()

void ChangeOwnershipOfCompanyItems | ( | Owner | old_owner,
|  | Owner | new_owner
| ) |  |

Change the ownership of all the items of a company.

Parameters

  old_owner | The company that gets removed.
  new_owner | The company to merge to, or INVALID_OWNER to remove the company.

Definition at line 334 of file economy.cpp.

References _current_company.

## ◆ 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 238 of file company_cmd.cpp.

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

Referenced by 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 360 of file company_cmd.cpp.

References _current_company, OWNER_END, OWNER_TOWN, return_cmd_error, and SetDParamsForOwnedBy().

Referenced by CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdCloneOrder(), CmdCloneVehicle(), CmdDeleteOrder(), CmdForceTrainProceed(), CmdInsertOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOpenCloseAirport(), CmdOrderRefit(), CmdRefitVehicle(), CmdRenameStation(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdReverseTrainDirection(), CmdSellVehicle(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdTurnRoadVeh(), RemoveAirport(), RemoveDock(), RemoveRoadStop(), and Vehicle::SendToDepot().

## ◆ 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 378 of file company_cmd.cpp.

References _current_company, GetTileOwner(), IsLocalCompany(), OWNER_END, return_cmd_error, and SetDParamsForOwnedBy().

Referenced by CmdConvertRail(), CmdRenameDepot(), and RemoveLock().

## ◆ 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 837 of file company_cmd.cpp.

References _network_server, and NetworkAdminCompanyUpdate().

Referenced by CmdRenameCompany(), CmdRenamePresident(), 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 1190 of file company_cmd.cpp.

References _settings_client, ClientSettings::company, CompanyProperties::settings, and CompanySettings::vehicle.

## ◆ 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 213 of file company_cmd.cpp.

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

Referenced by 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 227 of file company_cmd.cpp.

References _current_company, and GetAvailableMoney().

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

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

Returns
  the index of the first available company.

Definition at line 1279 of file company_cmd.cpp.

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

Referenced by OnStartGame().

## ◆ IsInteractiveCompany()

bool IsInteractiveCompany | ( | CompanyID | company | ) |
| inline

Is the user representing company?

Parameters

  company | Company where interaction is needed with.

Returns
  Gives `true` if the user can answer questions interactively as representative of company, else `false`

Definition at line 57 of file company_func.h.

References _local_company.

Referenced by HandleBankruptcyTakeover().

## ◆ IsLocalCompany()

bool IsLocalCompany | ( |  | ) |
| inline

Is the current company the local company?

Returns
  `true` of the current company is the local company, `false` otherwise.

Definition at line 47 of file company_func.h.

References _current_company, and _local_company.

Referenced by BuildReplacementVehicle(), CheckTileOwnership(), HandleKeypress(), HandleMouseEvents(), HandleToolbarHotkey(), InputLoop(), CommandHelperBase::InternalPostBefore(), NetworkExecuteLocalCommandQueue(), SetLocalCompany(), and TownActionBribe().

## ◆ MayCompanyTakeOver()

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

May company cbig buy company csmall?

Parameters

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

Returns
  Return `true` if it is allowed.

Definition at line 673 of file company_cmd.cpp.

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

Referenced by CmdBuyCompany(), and HandleBankruptcyTakeover().

## ◆ SetDParamsForOwnedBy()

void SetDParamsForOwnedBy | ( | 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 331 of file company_cmd.cpp.

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

Referenced by CheckOwnership(), and CheckTileOwnership().

## ◆ 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 114 of file company_cmd.cpp.

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

Referenced by ClickChangeCompanyCheat(), CmdCompanyCtrl(), GenerateWorld(), NetworkServerDoMove(), and OnStartGame().

## ◆ ShowBuyCompanyDialog()

void ShowBuyCompanyDialog | ( | CompanyID | company,
|  | bool | hostile_takeover
| ) |  |

Show the query to buy another company.

Parameters

  company | The company to buy.
  hostile_takeover | Whether this is a hostile takeover.

Definition at line 2775 of file company_gui.cpp.

References BringWindowToFrontById(), and WC_BUY_COMPANY.

Referenced by HandleBankruptcyTakeover().

## ◆ 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 286 of file company_cmd.cpp.

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

Referenced by 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 297 of file company_cmd.cpp.

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

## ◆ 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 996 of file company_cmd.cpp.