OpenTTD Source  1.11.0-beta2
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 GetNameOfOwner (Owner owner, TileIndex tile)
 Set the right DParams to get the name of an owner. 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)
 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.
 
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=0)
 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...
 
static bool IsLocalCompany ()
 Is the current company the local company? More...
 
static 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...
 

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.
 
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_ownerThe company that gets removed.
new_ownerThe company to merge to, or INVALID_OWNER to remove the company.

Definition at line 282 of file economy.cpp.

References _current_company.

Referenced by ResetLandscapeConfirmationCallback().

◆ CheckCompanyHasMoney()

bool CheckCompanyHasMoney ( CommandCost cost)

Verify whether the company can pay the bill.

Parameters
[in,out]costMoney 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 195 of file company_cmd.cpp.

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

◆ 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
ownerthe owner of the thing to check.
tileoptional 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 _current_company, GetNameOfOwner(), OWNER_END, OWNER_TOWN, and return_cmd_error.

Referenced by CmdAutofillTimetable(), CmdAutoreplaceVehicle(), CmdChangeServiceInt(), CmdChangeTimetable(), 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
tilethe 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 _current_company, GetNameOfOwner(), GetTileOwner(), IsLocalCompany(), OWNER_END, and return_cmd_error.

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

◆ CompanyAdminUpdate()

void CompanyAdminUpdate ( const Company company)

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

Parameters
companyThe company data changed of.

Definition at line 783 of file company_cmd.cpp.

References _network_server, and NetworkAdminCompanyUpdate().

Referenced by CmdRenameCompany(), and CmdRenamePresident().

◆ CompanyServiceInterval()

int CompanyServiceInterval ( const Company c,
VehicleType  type 
)

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

Parameters
cThe company, or nullptr for client-default settings.
typeThe vehicle type to get the interval for.
Returns
The service interval.

Definition at line 1152 of file company_cmd.cpp.

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

Referenced by CmdChangeServiceInt().

◆ GetNameOfOwner()

void GetNameOfOwner ( Owner  owner,
TileIndex  tile 
)

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

Parameters
ownerthe owner to get the name of.
tileoptional 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(), and CheckTileOwnership().

◆ IsInteractiveCompany()

static bool IsInteractiveCompany ( CompanyID  company)
inlinestatic

Is the user representing company?

Parameters
companyCompany where interaction is needed with.
Returns
Gives true if the user can answer questions interactively as representative of company, else false

Definition at line 53 of file company_func.h.

References _local_company.

Referenced by HandleBankruptcyTakeover().

◆ IsLocalCompany()

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

References _current_company, and _local_company.

Referenced by BuildReplacementVehicle(), CheckTileOwnership(), DoCommandP(), HandleKeypress(), HandleMouseEvents(), InputLoop(), NetworkExecuteLocalCommandQueue(), and SetLocalCompany().

◆ MayCompanyTakeOver()

◆ 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_companythe 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 _current_company, _local_company, 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 ClickChangeCompanyCheat(), GenerateWorld(), and NetworkServerDoMove().

◆ ShowBuyCompanyDialog()

void ShowBuyCompanyDialog ( CompanyID  company)

Show the query to buy another company.

Parameters
companyThe company to buy.

Definition at line 2863 of file company_gui.cpp.

Referenced by HandleBankruptcyTakeover().

◆ SubtractMoneyFromCompany()

void SubtractMoneyFromCompany ( const CommandCost cost)

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

Parameters
costMoney to pay.

Definition at line 242 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().

◆ SubtractMoneyFromCompanyFract()

void SubtractMoneyFromCompanyFract ( CompanyID  company,
const CommandCost cst 
)

Subtract money from a company, including the money fraction.

Parameters
companyCompany paying the bill.
cstCost of a command.

Definition at line 253 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.