OpenTTD: src/company_func.h File Reference

OpenTTD

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

- File List
- Globals

Functions | Variables
company_func.h File Reference

Functions related to companies. More...

`#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?
void | ChangeOwnershipOfCompanyItems (Owner old_owner, Owner new_owner)
| Change the ownership of all the items of a company.
void | GetNameOfOwner (Owner owner, TileIndex tile)
| Set the right DParams to get the name of an owner.
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.
void | ShowBuyCompanyDialog (CompanyID company)
| Show the query to buy another company.
void | CompanyAdminUpdate (const Company *company)
| Called whenever company related information changes in order to notify admins.
void | CompanyAdminBankrupt (CompanyID company_id)
void | UpdateLandscapingLimits ()
| Update the landscaping limits per company.
bool | CheckCompanyHasMoney (CommandCost &cost)
| Verify whether the company can pay the bill.
void | SubtractMoneyFromCompany (CommandCost cost)
| Subtract money from the _current_company, if the company is valid.
void | SubtractMoneyFromCompanyFract (CompanyID company, CommandCost cost)
| Subtract money from a company, including the money fraction.
CommandCost | CheckOwnership (Owner owner, TileIndex tile=0)
| Check whether the current owner owns something.
CommandCost | CheckTileOwnership (TileIndex tile)
| Check whether the current owner owns the stuff on the given tile.
static bool | IsLocalCompany ()
| Is the current company the local company?
static bool | IsInteractiveCompany (CompanyID company)
| Is the user representing company?
int | CompanyServiceInterval (const Company *c, VehicleType type)
| Get the service interval for the given company and vehicle type.

## Variables
CompanyByte | _local_company
| Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyByte | _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

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 289 of file economy.cpp.

References _current_company, _local_company, _networking, AddTrackToSignalBuffer(), Subsidy::awarded, Vehicle::cargo_payment, Backup< T >::Change(), ChangeTileOwner(), ChangeWindowOwner(), ClearCargoDeliveryMonitoring(), ClearCargoPickupMonitoring(), ClrBit(), CMD_SELL_SHARE_IN_COMPANY, Vehicle::colourmap, Goal::company, StoryPage::company, GroupStatistics::CountEngine(), GroupStatistics::CountVehicle(), DC_BANKRUPT, DC_EXEC, DoCommand(), Town::exclusive_counter, Town::exclusivity, FOR_ALL_VEHICLES, FOR_ALL_WAYPOINTS, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GetTrackBits(), HasBit(), HasSignalOnTrack(), HasSignals(), Town::have_ratings, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_COMPANY, INVALID_OWNER, Vehicle::InvalidateNewGRFCache(), IsCompanyBuildableVehicleType(), Vehicle::IsEngineCountable(), IsLevelCrossingTile(), Vehicle::IsPrimaryVehicle(), IsTileOwner(), IsTileType(), MapSize(), MarkWholeScreenDirty(), max(), MP_RAILWAY, NetworkClientsToSpectators(), FreeUnitIDGenerator::NextID(), CargoPayment::owner, BaseStation::owner, Group::owner, Vehicle::owner, OWNER_NONE, Vehicle::Previous(), RATING_INITIAL, Town::ratings, RebuildSubsidisedSourceAndDestinationCache(), RemoveAllEngineReplacementForCompany(), RemoveFirstTrack(), Backup< T >::Restore(), SetBit(), SetLocalCompany(), CompanyProperties::share_owners, SubtractMoneyFromCompany(), TRACK_BIT_NONE, BaseVehicle::type, Vehicle::unitnumber, GroupStatistics::UpdateAutoreplace(), UpdateLevelCrossing(), UpdateSignalsInBuffer(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by CmdCompanyCtrl(), and ResetLandscapeConfirmationCallback().

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

Verify whether the company can pay the bill.

Parameters

  cost | [inout] 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, else it returns `false`.

Definition at line 194 of file company_cmd.cpp.

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

Referenced by CmdCloneVehicle(), DoCommand(), and DoCommandPInternal().

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 310 of file company_cmd.cpp.

References GetNameOfOwner(), OWNER_END, OWNER_TOWN, and return_cmd_error.

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

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 328 of file company_cmd.cpp.

References GetNameOfOwner(), GetTileOwner(), IsLocalCompany(), OWNER_END, and return_cmd_error.

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

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 774 of file company_cmd.cpp.

References _network_server, and NetworkAdminCompanyUpdate().

Referenced by CmdBuyShareInCompany(), CmdRenameCompany(), CmdRenamePresident(), CmdSellShareInCompany(), and CmdSetCompanyColour().

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

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

Parameters

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

Returns
  The service interval.

Definition at line 1154 of file company_cmd.cpp.

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

Referenced by AfterLoadVehicles(), and CmdChangeServiceInt().

void GetNameOfOwner | ( | Owner | owner,
|  | TileIndex | tile
| ) |  |

Set the right DParams to get the name of an owner.

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 281 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(), OWNER_TOWN, and SetDParam().

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

static bool IsInteractiveCompany | ( | CompanyID | company | ) |
| inlinestatic

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 55 of file company_func.h.

References _local_company.

Referenced by EnginesDailyLoop(), and HandleBankruptcyTakeover().

static bool IsLocalCompany | ( |  | ) |
| inlinestatic

Is the current company the local company?

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

Definition at line 45 of file company_func.h.

References _current_company.

Referenced by CheckTileOwnership(), CmdBuildVehicle(), CmdSetAutoReplace(), DoCommandP(), HandleKeypress(), HandleMouseEvents(), InputLoop(), NetworkExecuteLocalCommandQueue(), SetLocalCompany(), and StateGameLoop().

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 622 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(), CmdBuyShareInCompany(), and HandleBankruptcyTakeover().

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 102 of file company_cmd.cpp.

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

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

void ShowBuyCompanyDialog | ( | CompanyID | company | ) |

Show the query to buy another company.

Parameters

  company | The company to buy.

Definition at line 2570 of file company_gui.cpp.

Referenced by HandleBankruptcyTakeover().

void SubtractMoneyFromCompany | ( | CommandCost | cost | ) |

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

Parameters

  cost | Money to pay.

Definition at line 241 of file company_cmd.cpp.

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

Referenced by ChangeOwnershipOfCompanyItems(), CmdChangeBankBalance(), CmdGiveMoney(), CompaniesGenStatistics(), CompaniesPayInterest(), DoCommand(), and DoCommandPInternal().

void SubtractMoneyFromCompanyFract | ( | CompanyID | company,
|  | 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 252 of file company_cmd.cpp.

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

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

void UpdateLandscapingLimits | ( |  | ) |

Update the landscaping limits per company.

Definition at line 265 of file company_cmd.cpp.

References _settings_game, ConstructionSettings::clear_frame_burst, CompanyProperties::clear_limit, ConstructionSettings::clear_per_64k_frames, GameSettings::construction, min(), ConstructionSettings::terraform_frame_burst, CompanyProperties::terraform_limit, ConstructionSettings::terraform_per_64k_frames, ConstructionSettings::tree_frame_burst, CompanyProperties::tree_limit, and ConstructionSettings::tree_per_64k_frames.

Referenced by StateGameLoop().