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

Function ClearTile_Town

src/town_cmd.cpp:717–749  ·  view source on GitHub ↗

* Callback function to clear a house tile. * @param tile The tile to clear. * @param flags Type of operation. * @return The cost of this operation or an error. */

Source from the content-addressed store, hash-verified

715 * @return The cost of this operation or an error.
716 */
717static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlags flags)
718{
719 if (flags.Test(DoCommandFlag::Auto)) return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
720 if (!CanDeleteHouse(tile)) return CommandCost(STR_ERROR_BUILDING_IS_PROTECTED);
721
722 const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
723
724 CommandCost cost(EXPENSES_CONSTRUCTION);
725 cost.AddCost(hs->GetRemovalCost());
726
727 int rating = hs->remove_rating_decrease;
728 Town *t = Town::GetByTile(tile);
729
730 if (Company::IsValidID(_current_company)) {
731 if (!_cheats.magic_bulldozer.value && !flags.Test(DoCommandFlag::NoTestTownRating)) {
732 /* NewGRFs can add indestructible houses. */
733 if (rating > RATING_MAXIMUM) {
734 return CommandCost(STR_ERROR_BUILDING_IS_PROTECTED);
735 }
736 /* If town authority controls removal, check the company's rating. */
737 if (rating > t->ratings[_current_company] && _settings_game.difficulty.town_council_tolerance != TOWN_COUNCIL_PERMISSIVE) {
738 return CommandCostWithParam(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS, t->index);
739 }
740 }
741 }
742
743 ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM, flags);
744 if (flags.Test(DoCommandFlag::Execute)) {
745 ClearTownHouse(t, tile);
746 }
747
748 return cost;
749}
750
751static void AddProducedCargo_Town(TileIndex tile, CargoArray &produced)
752{

Callers

nothing calls this directly

Calls 9

CommandCostClass · 0.85
CanDeleteHouseFunction · 0.85
GetHouseTypeFunction · 0.85
ChangeTownRatingFunction · 0.85
ClearTownHouseFunction · 0.85
TestMethod · 0.80
CommandCostWithParamFunction · 0.70
AddCostMethod · 0.45
GetRemovalCostMethod · 0.45

Tested by

no test coverage detected