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

Function TownActionBuyRights

src/town_cmd.cpp:3585–3608  ·  view source on GitHub ↗

* Perform the "buy exclusive transport rights" town action. * @param t The town to buy exclusivity in. * @param flags Type of operation. * @return An empty cost. */

Source from the content-addressed store, hash-verified

3583 * @return An empty cost.
3584 */
3585static CommandCost TownActionBuyRights(Town *t, DoCommandFlags flags)
3586{
3587 /* Check if it's allowed to buy the rights */
3588 if (!_settings_game.economy.exclusive_rights) return CMD_ERROR;
3589 if (t->exclusivity != CompanyID::Invalid()) return CMD_ERROR;
3590
3591 if (flags.Test(DoCommandFlag::Execute)) {
3592 t->exclusive_counter = 12;
3593 t->exclusivity = _current_company;
3594
3595 ModifyStationRatingAround(t->xy, _current_company, 130, 17);
3596
3597 SetWindowClassesDirty(WC_STATION_VIEW);
3598
3599 /* Spawn news message */
3600 auto cni = std::make_unique<CompanyNewsInformation>(STR_NEWS_EXCLUSIVE_RIGHTS_TITLE, Company::Get(_current_company));
3601 EncodedString message = GetEncodedString(TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MINUTES : STR_NEWS_EXCLUSIVE_RIGHTS_DESCRIPTION_MONTHS, t->index, cni->company_name);
3602 AddNewsItem(std::move(message),
3603 NewsType::General, NewsStyle::Company, {}, t->index, {}, std::move(cni));
3604 AI::BroadcastNewEvent(new ScriptEventExclusiveTransportRights(_current_company, t->index));
3605 Game::NewEvent(new ScriptEventExclusiveTransportRights(_current_company, t->index));
3606 }
3607 return CommandCost();
3608}
3609
3610/**
3611 * Perform the "bribe" town action.

Callers

nothing calls this directly

Calls 7

InvalidFunction · 0.85
SetWindowClassesDirtyFunction · 0.85
AddNewsItemFunction · 0.85
CommandCostClass · 0.85
TestMethod · 0.80
GetEncodedStringFunction · 0.70

Tested by

no test coverage detected