Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce special casing in StructureCatalogue::get #1665

Open
DanRStevens opened this issue Mar 8, 2025 · 0 comments
Open

Reduce special casing in StructureCatalogue::get #1665

DanRStevens opened this issue Mar 8, 2025 · 0 comments

Comments

@DanRStevens
Copy link
Member

There are currently a few special cases in StructureCatalogue::get that can probably be removed:


There is some inconsistency with setting the lander tile for the SeedLander:

case StructureID::SID_CARGO_LANDER: // only here for loading games
	structure = new CargoLander(tile);
// ...
case StructureID::SID_COLONIST_LANDER: // only here for loading games
	structure = new ColonistLander(tile);
// ...
case StructureID::SID_SEED_LANDER: // only here for loading games
	structure = new SeedLander({0, 0});

The MineFacility is constructed with a nullptr for the Mine*:

case StructureID::SID_MINE_FACILITY: // only here for loading games
	structure = new MineFacility(nullptr);

Potentially the tile could be used to find the Mine*, which could be set using the MineFacility constructor. It may be possible to remove the MineFacility::mine setter function. This would need some coordination with MapViewState::readStructures, which also uses the mine setter function. Though earlier there is a call to StructureCatalogue::get which could have set the Mine*:

auto& structure = *StructureCatalogue::get(structureId, &tile);
// ...
if (structureId == StructureID::SID_MINE_FACILITY)
{
	auto* mine = mTileMap->getTile({mapCoordinate.xy, 0}).mine();
	if (mine == nullptr)
	{
		throw std::runtime_error("Mine Facility is located on a Tile with no Mine.");
	}

	auto& mineFacility = *static_cast<MineFacility*>(&structure);
	mineFacility.mine(mine);
	// ...

There is a comment on MineShaft that indicates a special case:

case StructureID::SID_MINE_SHAFT: // only here for loading games
	structure = new MineShaft();

Looking into this, it seems that structure is specially created with direct uses of new in Robominer::buildMine and MapViewState::onMineFacilityExtend. Perhaps these methods should be updated to use StructureCatalogue::get for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant