MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdDoTownAction

Function CmdDoTownAction

src/town_cmd.cpp:3728–3745  ·  view source on GitHub ↗

* Do a town action. * This performs an action such as advertising, building a statue, funding buildings, * but also bribing the town-council * @param flags type of operation * @param town_id town to do the action at * @param action action to perform, @see _town_action_proc for the list of available actions * @return the cost of this operation or an error */

Source from the content-addressed store, hash-verified

3726 * @return the cost of this operation or an error
3727 */
3728CommandCost CmdDoTownAction(DoCommandFlags flags, TownID town_id, TownAction action)
3729{
3730 Town *t = Town::GetIfValid(town_id);
3731 if (t == nullptr || to_underlying(action) >= std::size(_town_action_proc)) return CMD_ERROR;
3732
3733 if (!GetMaskOfTownActions(_current_company, t).Test(action)) return CMD_ERROR;
3734
3735 CommandCost cost(EXPENSES_OTHER, _price[PR_TOWN_ACTION] * GetTownActionCost(action) >> 8);
3736
3737 CommandCost ret = _town_action_proc[to_underlying(action)](t, flags);
3738 if (ret.Failed()) return ret;
3739
3740 if (flags.Test(DoCommandFlag::Execute)) {
3741 SetWindowDirty(WC_TOWN_AUTHORITY, town_id);
3742 }
3743
3744 return cost;
3745}
3746
3747template <typename Func>
3748static void ForAllStationsNearTown(Town *t, Func func)

Callers

nothing calls this directly

Calls 7

to_underlyingFunction · 0.85
GetMaskOfTownActionsFunction · 0.85
GetTownActionCostFunction · 0.85
SetWindowDirtyFunction · 0.85
TestMethod · 0.80
FailedMethod · 0.80
sizeFunction · 0.50

Tested by

no test coverage detected