Skip to content

Commit

Permalink
Replaced MapViewState colony ship related member variable and logic w…
Browse files Browse the repository at this point in the history
…ith new ColonyShip Class
  • Loading branch information
oscar139 committed Mar 10, 2025
1 parent 1734e38 commit 0b9f00a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 28 deletions.
17 changes: 5 additions & 12 deletions appOPHD/States/MapViewState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "MainMenuState.h"
#include "MainReportsUiState.h"
#include "GameState.h"
#include "ColonyShip.h"
#include "Route.h"

#include "../Constants/Strings.h"
Expand Down Expand Up @@ -224,7 +225,6 @@ MapViewState::MapViewState(GameState& gameState, const Planet::Attributes& plane
mColonyShip{gameState.colonyShip()}
{
setMeanSolarDistance(mPlanetAttributes.meanSolarDistance);
setPopulationLevel(PopulationLevel::Large);
ccLocation() = CcNotPlaced;
NAS2D::Utility<NAS2D::EventHandler>::get().windowResized().connect({this, &MapViewState::onWindowResized});
}
Expand All @@ -250,13 +250,6 @@ MapViewState::~MapViewState()
}


void MapViewState::setPopulationLevel(PopulationLevel popLevel)
{
mLandersColonist = static_cast<int>(popLevel);
mLandersCargo = 2; ///\todo This should be set based on difficulty level.
}


/**
* Initialize values, the UI and set up event handling.
*/
Expand Down Expand Up @@ -888,8 +881,8 @@ void MapViewState::placeStructure(Tile& tile)
s.deploySignal().connect({this, &MapViewState::onDeployColonistLander});
NAS2D::Utility<StructureManager>::get().addStructure(s, tile);

--mLandersColonist;
if (mLandersColonist == 0)
mColonyShip.onDeployColonistLander();
if (mColonyShip.colonistLanders() == 0)
{
clearMode();
resetUi();
Expand All @@ -904,8 +897,8 @@ void MapViewState::placeStructure(Tile& tile)
cargoLander.deploySignal().connect({this, &MapViewState::onDeployCargoLander});
NAS2D::Utility<StructureManager>::get().addStructure(cargoLander, tile);

--mLandersCargo;
if (mLandersCargo == 0)
mColonyShip.onDeployCargoLander();
if (mColonyShip.cargoLanders() == 0)
{
clearMode();
resetUi();
Expand Down
5 changes: 0 additions & 5 deletions appOPHD/States/MapViewState.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ class MapViewState : public Wrapper
MapViewState(GameState& gameState, const Planet::Attributes& planetAttributes, Difficulty selectedDifficulty);
~MapViewState() override;

void setPopulationLevel(PopulationLevel popLevel);

ReportsUiSignal::Source& showReportsUi() { return mReportsUiSignal; }
QuitSignal::Source& quit() { return mQuitSignal; }
MapChangedSignal::Source& mapChanged() { return mMapChangedSignal; }
Expand Down Expand Up @@ -313,9 +311,6 @@ class MapViewState : public Wrapper

Morale mMorale;

int mLandersColonist = 0;
int mLandersCargo = 0;

int mResidentialCapacity = 0;

// POOLS
Expand Down
8 changes: 3 additions & 5 deletions appOPHD/States/MapViewStateIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ==================================================================================

#include "MapViewState.h"
#include "ColonyShip.h"

#include "MapViewStateHelper.h"

Expand Down Expand Up @@ -168,8 +169,8 @@ void MapViewState::save(const std::string& filePath)
{{
{"morale", mMorale.currentMorale()},
{"prev_morale", mMorale.previousMorale()},
{"colonist_landers", mLandersColonist},
{"cargo_landers", mLandersCargo},
{"colonist_landers", mColonyShip.colonistLanders()},
{"cargo_landers", mColonyShip.cargoLanders()},
{"turn_number_of_landing", mTurnNumberOfLanding},
{"children", population.child},
{"students", population.student},
Expand Down Expand Up @@ -572,9 +573,6 @@ void MapViewState::readPopulation(NAS2D::Xml::XmlElement* element)

const auto dictionary = NAS2D::attributesToDictionary(*element);

mLandersColonist = dictionary.get<int>("colonist_landers");
mLandersCargo = dictionary.get<int>("cargo_landers");

mMorale = Morale(dictionary.get<int>("morale"), dictionary.get<int>("prev_morale"));

mTurnNumberOfLanding = dictionary.get<int>("turn_number_of_landing", constants::ColonyShipOrbitTime);
Expand Down
7 changes: 3 additions & 4 deletions appOPHD/States/MapViewStateTurn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,6 @@ void MapViewState::nextTurn()

updateResearch();

populateRobotMenu();
populateStructureMenu();

if (!mColonyShip.crashed())
{
mColonyShip.onTurn();
Expand All @@ -794,12 +791,14 @@ void MapViewState::nextTurn()
mMineOperationsWindow.updateTruckAvailability();

// Check for Game Over conditions
if (mPopulation.getPopulations().size() <= 0 && mLandersColonist == 0)
if (mPopulation.getPopulations().size() <= 0 && mColonyShip.colonistLanders() == 0)
{
hideUi();
mGameOverDialog.show();
}

populateRobotMenu();
populateStructureMenu();

mMorale.commitMoraleChanges();

Expand Down
5 changes: 3 additions & 2 deletions appOPHD/States/MapViewStateUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ==================================================================================

#include "MapViewState.h"
#include "ColonyShip.h"
#include "MapViewStateHelper.h"

#include "MainMenuState.h"
Expand Down Expand Up @@ -335,8 +336,8 @@ void MapViewState::populateStructureMenu()
fillList(mConnections, mStructureTracker.surfaceTubes());

// Special case code, not thrilled with this
if (mLandersColonist > 0) { mStructures.addItem({constants::ColonistLander, 2, StructureID::SID_COLONIST_LANDER}); }
if (mLandersCargo > 0) { mStructures.addItem({constants::CargoLander, 1, StructureID::SID_CARGO_LANDER}); }
if (mColonyShip.colonistLanders() > 0) { mStructures.addItem({constants::ColonistLander, 2, StructureID::SID_COLONIST_LANDER}); }
if (mColonyShip.cargoLanders() > 0) { mStructures.addItem({constants::CargoLander, 1, StructureID::SID_CARGO_LANDER}); }
}
else
{
Expand Down

0 comments on commit 0b9f00a

Please sign in to comment.