Implement removeTree game command (#1083)

This commit is contained in:
Aaron van Geffen 2021-08-05 23:44:18 +02:00 committed by GitHub
parent 4c54152737
commit a57af0e1f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 1 deletions

View File

@ -68,7 +68,7 @@ namespace OpenLoco::GameCommands
{ GameCommand::changeCompanyColourScheme, changeCompanyColour, 0x0043483D, false },
{ GameCommand::pauseGame, togglePause, 0x00431E32, false },
{ GameCommand::loadSaveQuitGame, loadSaveQuit, 0x0043BFCB, false },
{ GameCommand::removeTree, nullptr, 0x004BB392, true },
{ GameCommand::removeTree, removeTree, 0x004BB392, true },
{ GameCommand::createTree, nullptr, 0x004BB138, true },
{ GameCommand::changeLandMaterial, nullptr, 0x00468EDD, true },
{ GameCommand::raiseLand, nullptr, 0x00463702, true },

View File

@ -1238,6 +1238,9 @@ namespace OpenLoco::GameCommands
// Defined in GameCommands/LoadSaveQuit.cpp
void loadSaveQuit(registers& regs);
// Defined in GameCommands/RemoveTree.cpp
void removeTree(registers& regs);
// Defined in GameCommands/RenameIndustry.cpp
void renameIndustry(registers& regs);

View File

@ -0,0 +1,59 @@
#include "../Economy/Economy.h"
#include "../Economy/Expenditures.h"
#include "../Map/TileManager.h"
#include "../Objects/ObjectManager.h"
#include "../Objects/TreeObject.h"
#include "../OpenLoco.h"
#include "../S5/S5.h"
#include "GameCommands.h"
using namespace OpenLoco::Interop;
namespace OpenLoco::GameCommands
{
// 0x004BB392
static uint32_t removeTree(const Map::Pos3& pos, const uint8_t type, const uint8_t elementType, const uint8_t flags)
{
GameCommands::setExpenditureType(ExpenditureType::Construction);
auto tileHeight = Map::TileManager::getHeight(pos);
GameCommands::setPosition(Map::Pos3(pos.x + Map::tile_size / 2, pos.y + Map::tile_size / 2, tileHeight.landHeight));
auto tile = Map::TileManager::get(pos);
for (auto& element : tile)
{
// TODO: refactor! Figure out what info it actually needs.
if (element.rawData()[0] != elementType)
continue;
if (element.baseZ() * 4 != pos.z)
continue;
auto treeElement = element.asTree();
if (treeElement == nullptr)
continue;
if (treeElement->treeObjectId() != type)
continue;
auto treeObj = ObjectManager::get<TreeObject>(treeElement->treeObjectId());
currency32_t removalCost = Economy::getInflationAdjustedCost(treeObj->clear_cost_factor, treeObj->cost_index, 12);
if (flags & Flags::apply)
Map::TileManager::removeElement(element);
auto& options = S5::getOptions();
options.madeAnyChanges = 1;
return removalCost;
}
return FAILURE;
}
void removeTree(registers& regs)
{
TreeRemovalArgs args(regs);
regs.ebx = removeTree(args.pos, args.type, args.elementType, regs.bl);
}
}

View File

@ -86,6 +86,13 @@ namespace OpenLoco::Map::TileManager
TileManager::updateTilePointers();
}
void removeElement(TileElement& element)
{
registers regs;
regs.esi = X86Pointer(&element);
call(0x004BB432, regs);
}
TileElement** getElementIndex()
{
return _tiles.get();

View File

@ -17,6 +17,7 @@ namespace OpenLoco::Map::TileManager
Tile get(Pos2 pos);
Tile get(coord_t x, coord_t y);
void setElements(stdx::span<TileElement> elements);
void removeElement(TileElement& element);
TileHeight getHeight(const Pos2& pos);
void updateTilePointers();
void reorganise();

View File

@ -38,6 +38,7 @@
<ClCompile Include="GameCommands\ChangeCompanyColour.cpp" />
<ClCompile Include="GameCommands\GameCommands.cpp" />
<ClCompile Include="GameCommands\LoadSaveQuit.cpp" />
<ClCompile Include="GameCommands\RemoveTree.cpp" />
<ClCompile Include="GameCommands\RenameIndustry.cpp" />
<ClCompile Include="GameCommands\RenameStation.cpp" />
<ClCompile Include="GameCommands\RenameTown.cpp" />