MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / removeTree

Function removeTree

src/OpenLoco/src/GameCommands/Terraform/RemoveTree.cpp:32–79  ·  view source on GitHub ↗

* 0x004BB392 * Remove tree * * This is called when you activate the Plant Trees from the construction (first) menu and you move the cursor over the terrain. * * @param pos_x @ * @param pos_y @ * @param pos_z @ * World::kSmallZStep * @param type @ * @param elementType @ * @param flags @ * @return @ - returns the rem

Source from the content-addressed store, hash-verified

30 * @return @<ebx> - returns the remove cost if successful; otherwise GameCommands::kFailure (in the assembly code we never get into failure path)
31 */
32 static uint32_t removeTree(const World::Pos3& pos, const uint8_t type, const uint8_t elementType, const uint8_t flags)
33 {
34 GameCommands::setExpenditureType(ExpenditureType::Construction);
35
36 auto tileHeight = World::TileManager::getHeight(pos);
37 GameCommands::setPosition(World::Pos3(pos.x + World::kTileSize / 2, pos.y + World::kTileSize / 2, tileHeight.landHeight));
38
39 auto tile = World::TileManager::get(pos);
40 for (auto& element : tile)
41 {
42 // TODO: refactor! Figure out what info it actually needs.
43 if (element.rawData()[0] != elementType)
44 {
45 continue;
46 }
47
48 if (element.baseHeight() != pos.z)
49 {
50 continue;
51 }
52
53 auto* treeElement = element.as<World::TreeElement>();
54 if (treeElement == nullptr)
55 {
56 continue;
57 }
58
59 if (treeElement->treeObjectId() != type)
60 {
61 continue;
62 }
63
64 auto treeObj = ObjectManager::get<TreeObject>(treeElement->treeObjectId());
65 currency32_t removalCost = Economy::getInflationAdjustedCost(treeObj->clearCostFactor, treeObj->costIndex, 12);
66
67 if (flags & Flags::apply)
68 {
69 World::TileManager::removeTree(*treeElement, flags, pos);
70 }
71
72 auto& options = Scenario::getOptions();
73 options.madeAnyChanges = 1;
74
75 return removalCost;
76 }
77
78 return kFailure;
79 }
80
81 void removeTree(registers& regs)
82 {

Callers

nothing calls this directly

Calls 8

setExpenditureTypeFunction · 0.85
getHeightFunction · 0.85
setPositionFunction · 0.85
getInflationAdjustedCostFunction · 0.85
rawDataMethod · 0.80
baseHeightMethod · 0.80
treeObjectIdMethod · 0.80
getFunction · 0.50

Tested by

no test coverage detected