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

Function GetMaskOfTownActions

src/town_cmd.cpp:3672–3717  ·  view source on GitHub ↗

* Get a list of available town authority actions. * @param cid The company that is querying the town. * @param t The town that is queried. * @return The bitmasked value of enabled actions. */

Source from the content-addressed store, hash-verified

3670 * @return The bitmasked value of enabled actions.
3671 */
3672TownActions GetMaskOfTownActions(CompanyID cid, const Town *t)
3673{
3674 TownActions buttons{};
3675
3676 /* Spectators and unwanted have no options */
3677 if (cid != COMPANY_SPECTATOR && !(_settings_game.economy.bribe && t->unwanted[cid])) {
3678
3679 /* Actions worth more than this are not able to be performed */
3680 Money avail = GetAvailableMoney(cid);
3681
3682 /* Check the action bits for validity and
3683 * if they are valid add them */
3684 for (TownAction cur = {}; cur != TownAction::End; ++cur) {
3685
3686 /* Is the company prohibited from bribing ? */
3687 if (cur == TownAction::Bribe) {
3688 /* Company can't bribe if setting is disabled */
3689 if (!_settings_game.economy.bribe) continue;
3690 /* Company can bribe if another company has exclusive transport rights,
3691 * or its standing with the town is less than outstanding. */
3692 if (t->ratings[cid] >= RATING_BRIBE_MAXIMUM) {
3693 if (t->exclusivity == _current_company) continue;
3694 if (t->exclusive_counter == 0) continue;
3695 }
3696 }
3697
3698 /* Is the company not able to buy exclusive rights ? */
3699 if (cur == TownAction::BuyRights && (!_settings_game.economy.exclusive_rights || t->exclusive_counter != 0)) continue;
3700
3701 /* Is the company not able to fund buildings ? */
3702 if (cur == TownAction::FundBuildings && !_settings_game.economy.fund_buildings) continue;
3703
3704 /* Is the company not able to fund local road reconstruction? */
3705 if (cur == TownAction::RoadRebuild && !_settings_game.economy.fund_roads) continue;
3706
3707 /* Is the company not able to build a statue ? */
3708 if (cur == TownAction::BuildStatue && t->statues.Test(cid)) continue;
3709
3710 if (avail >= GetTownActionCost(cur) * _price[PR_TOWN_ACTION] >> 8) {
3711 buttons.Set(cur);
3712 }
3713 }
3714 }
3715
3716 return buttons;
3717}
3718
3719/**
3720 * Do a town action.

Callers 3

OnPaintMethod · 0.85
CmdDoTownActionFunction · 0.85
IsActionAvailableMethod · 0.85

Calls 4

GetAvailableMoneyFunction · 0.85
GetTownActionCostFunction · 0.85
TestMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected