Skip to content

Implement road removal game command#3052

Merged
duncanspumpkin merged 24 commits intoOpenLoco:masterfrom
AaronVanGeffen:gc/remove-road
Aug 24, 2025
Merged

Implement road removal game command#3052
duncanspumpkin merged 24 commits intoOpenLoco:masterfrom
AaronVanGeffen:gc/remove-road

Conversation

@AaronVanGeffen
Copy link
Copy Markdown
Member

@AaronVanGeffen AaronVanGeffen commented Mar 29, 2025

To do:

  • Finish implementation
  • Deduplicate tile element loops (getRoadEl?)
  • Fix bug with removing single-tile ghost pieces
  • Fix bug with removing multi-tile pieces
  • ...
  • Testing!

@github-project-automation github-project-automation bot moved this to In progress in GameCommands Mar 29, 2025
@AaronVanGeffen AaronVanGeffen marked this pull request as ready for review April 14, 2025 19:13
Comment on lines +135 to +158
/*
// This part was made redundant by a no-op write in Hooks.cpp:
// writeNop(0x004776DD, 6);
// TODO: turn this into a setting?
if (companyId != CompanyId::neutral && roadEl->hasUnk7_40() || roadEl->hasUnk7_80())
{
setErrorText(StringIds::empty);

auto nearest = TownManager::getClosestTownAndDensity(args.pos);
if (nearest.has_value())
{
auto* town = TownManager::get(nearest->first);
FormatArguments::common(town->name);
setErrorText(StringIds::stringid_local_authority_wont_allow_removal_in_use);
return FAILURE;
}
}
*/
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably turn this into a proper setting, rather than omitting it outright? Then again, it's been like this since 2018... @duncanspumpkin, any thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes should probably make it a setting but can look at it later.

// This part was made redundant by a no-op write in Hooks.cpp:
// writeNop(0x004776DD, 6);
// TODO: turn this into a setting?
if (companyId != CompanyId::neutral && roadEl->hasUnk7_40() || roadEl->hasUnk7_80())
Copy link
Copy Markdown
Member Author

@AaronVanGeffen AaronVanGeffen Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this on Discord, but for posterity: I think this is right for tram tracks, but the wrong check to use for other road types. For regular roads, unk4u (two bits) should probably be read instead? Consider:

const auto newUnk4u = _4F7358[trackAndDirection._data >> 2] >> 4;
if (setOccupied)
{
elRoad->setUnk4u(elRoad->unk4u() | newUnk4u);
}
else
{
elRoad->setUnk4u(elRoad->unk4u() & (~newUnk4u));
}

auto tile = World::TileManager::get(args.pos.x, args.pos.y);

if (auto* roadEl = getRoadElement(tile, args, args.sequenceIndex, flags); roadEl != nullptr)
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if roadElement is nullptr we should safely handle that and return FAILURE (this would be a change from vanilla)

duncanspumpkin added a commit to OpenLoco/TestData that referenced this pull request Aug 24, 2025
@duncanspumpkin duncanspumpkin enabled auto-merge (squash) August 24, 2025 08:36
@duncanspumpkin duncanspumpkin merged commit b1af623 into OpenLoco:master Aug 24, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in GameCommands Aug 24, 2025
@AaronVanGeffen AaronVanGeffen deleted the gc/remove-road branch August 24, 2025 09:16
Comment on lines +295 to +301
// Seems to have been forgotten in vanilla
if (removeRoadBridge)
{
const auto* bridgeObj = ObjectManager::get<BridgeObject>(roadBridgeId);
const auto bridgeBaseCost = Economy::getInflationAdjustedCost(bridgeObj->sellCostFactor, bridgeObj->costIndex, 10);
totalRemovalCost += (bridgeBaseCost * World::TrackData::getRoadMiscData(args.roadId).costFactor) / 256;
}
Copy link
Copy Markdown
Contributor

@LeeSpork LeeSpork Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vanilla change/fix that was omitted from the changelog?

Also #3268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done (PRs)

Development

Successfully merging this pull request may close these issues.

3 participants