* 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 */
| 3726 | * @return the cost of this operation or an error |
| 3727 | */ |
| 3728 | CommandCost 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 | |
| 3747 | template <typename Func> |
| 3748 | static void ForAllStationsNearTown(Town *t, Func func) |
nothing calls this directly
no test coverage detected