Skip to content

Commit c3b888c

Browse files
committed
Replaced MapViewState colony ship related member variable and logic with new ColonyShip Class
1 parent 7c92b08 commit c3b888c

5 files changed

+24
-48
lines changed

appOPHD/States/MapViewState.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "MapViewState.h"
2+
#include "ColonyShip.h"
23

34
#include "MapViewStateHelper.h"
45

@@ -224,7 +225,6 @@ MapViewState::MapViewState(GameState& gameState, const Planet::Attributes& plane
224225
mColonyShip{gameState.colonyShip()}
225226
{
226227
setMeanSolarDistance(mPlanetAttributes.meanSolarDistance);
227-
setPopulationLevel(PopulationLevel::Large);
228228
ccLocation() = CcNotPlaced;
229229
NAS2D::Utility<NAS2D::EventHandler>::get().windowResized().connect({this, &MapViewState::onWindowResized});
230230
}
@@ -250,13 +250,6 @@ MapViewState::~MapViewState()
250250
}
251251

252252

253-
void MapViewState::setPopulationLevel(PopulationLevel popLevel)
254-
{
255-
mLandersColonist = static_cast<int>(popLevel);
256-
mLandersCargo = 2; ///\todo This should be set based on difficulty level.
257-
}
258-
259-
260253
/**
261254
* Initialize values, the UI and set up event handling.
262255
*/
@@ -888,8 +881,8 @@ void MapViewState::placeStructure(Tile& tile)
888881
s.deploySignal().connect({this, &MapViewState::onDeployColonistLander});
889882
NAS2D::Utility<StructureManager>::get().addStructure(s, tile);
890883

891-
--mLandersColonist;
892-
if (mLandersColonist == 0)
884+
mColonyShip.onDeployColonistLander();
885+
if (!mColonyShip.colonistLanders())
893886
{
894887
clearMode();
895888
resetUi();
@@ -904,8 +897,8 @@ void MapViewState::placeStructure(Tile& tile)
904897
cargoLander.deploySignal().connect({this, &MapViewState::onDeployCargoLander});
905898
NAS2D::Utility<StructureManager>::get().addStructure(cargoLander, tile);
906899

907-
--mLandersCargo;
908-
if (mLandersCargo == 0)
900+
mColonyShip.onDeployCargoLander();
901+
if (!mColonyShip.cargoLanders())
909902
{
910903
clearMode();
911904
resetUi();

appOPHD/States/MapViewState.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ class MapViewState : public Wrapper
113113
MapViewState(GameState& gameState, const Planet::Attributes& planetAttributes, Difficulty selectedDifficulty);
114114
~MapViewState() override;
115115

116-
void setPopulationLevel(PopulationLevel popLevel);
117-
118116
ReportsUiSignal::Source& showReportsUi() { return mReportsUiSignal; }
119117
QuitSignal::Source& quit() { return mQuitSignal; }
120118
MapChangedSignal::Source& mapChanged() { return mMapChangedSignal; }
@@ -205,7 +203,7 @@ class MapViewState : public Wrapper
205203
void updateResearch();
206204

207205
// TURN LOGIC
208-
void checkColonyShip();
206+
void updateColonyShip();
209207
void checkWarehouseCapacity();
210208
void nextTurn();
211209
void updatePopulation();
@@ -312,9 +310,6 @@ class MapViewState : public Wrapper
312310

313311
Morale mMorale;
314312

315-
int mLandersColonist = 0;
316-
int mLandersCargo = 0;
317-
318313
int mResidentialCapacity = 0;
319314

320315
// POOLS

appOPHD/States/MapViewStateIO.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// ==================================================================================
66

77
#include "MapViewState.h"
8+
#include "ColonyShip.h"
89

910
#include "MapViewStateHelper.h"
1011

@@ -168,8 +169,8 @@ void MapViewState::save(const std::string& filePath)
168169
{{
169170
{"morale", mMorale.currentMorale()},
170171
{"prev_morale", mMorale.previousMorale()},
171-
{"colonist_landers", mLandersColonist},
172-
{"cargo_landers", mLandersCargo},
172+
{"colonist_landers", mColonyShip.colonistLanders()},
173+
{"cargo_landers", mColonyShip.cargoLanders()},
173174
{"turn_number_of_landing", mTurnNumberOfLanding},
174175
{"children", population.child},
175176
{"students", population.student},
@@ -572,9 +573,6 @@ void MapViewState::readPopulation(NAS2D::Xml::XmlElement* element)
572573

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

575-
mLandersColonist = dictionary.get<int>("colonist_landers");
576-
mLandersCargo = dictionary.get<int>("cargo_landers");
577-
578576
mMorale = Morale(dictionary.get<int>("morale"), dictionary.get<int>("prev_morale"));
579577

580578
mTurnNumberOfLanding = dictionary.get<int>("turn_number_of_landing", constants::ColonyShipOrbitTime);

appOPHD/States/MapViewStateTurn.cpp

+12-23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// ==================================================================================
44

55
#include "MapViewState.h"
6+
#include "ColonyShip.h"
7+
68
#include "MapViewStateHelper.h"
79

810
#include "Route.h"
@@ -418,29 +420,16 @@ void MapViewState::updateResources()
418420
* Check for colony ship deorbiting; if any colonists are remaining, kill
419421
* them and reduce morale by an appropriate amount.
420422
*/
421-
void MapViewState::checkColonyShip()
423+
void MapViewState::updateColonyShip()
422424
{
423-
if (mTurnCount == constants::ColonyShipOrbitTime)
425+
ColonyShip::ColonyShipUpdate update = mColonyShip.updateColonyShip(mDifficulty);
426+
if (update)
424427
{
425-
if (mLandersColonist > 0 || mLandersCargo > 0)
426-
{
427-
mMorale.journalMoraleChange({"Deorbit Disaster!", -(mLandersColonist * 50) * ColonyShipDeorbitMoraleLossMultiplier.at(mDifficulty)});
428-
429-
mLandersColonist = 0;
430-
mLandersCargo = 0;
431-
432-
populateStructureMenu();
433-
434-
mWindowStack.bringToFront(&mAnnouncement);
435-
mAnnouncement.announcement(MajorEventAnnouncement::AnnouncementType::ColonyShipCrashWithColonists);
436-
mAnnouncement.show();
437-
}
438-
else
439-
{
440-
mWindowStack.bringToFront(&mAnnouncement);
441-
mAnnouncement.announcement(MajorEventAnnouncement::AnnouncementType::ColonyShipCrash);
442-
mAnnouncement.show();
443-
}
428+
ColonyShip::ColonyShipCrashEffects crashEffects = update.value();
429+
mMorale.journalMoraleChanges(crashEffects.moraleChangeEntries);
430+
mWindowStack.bringToFront(&mAnnouncement);
431+
mAnnouncement.announcement(crashEffects.announcementType);
432+
mAnnouncement.show();
444433
}
445434
}
446435

@@ -783,13 +772,13 @@ void MapViewState::nextTurn()
783772
populateRobotMenu();
784773
populateStructureMenu();
785774

786-
checkColonyShip();
775+
updateColonyShip();
787776
checkWarehouseCapacity();
788777

789778
mMineOperationsWindow.updateTruckAvailability();
790779

791780
// Check for Game Over conditions
792-
if (mPopulation.getPopulations().size() <= 0 && mLandersColonist == 0)
781+
if (mPopulation.getPopulations().size() <= 0 && !mColonyShip.colonistLanders())
793782
{
794783
hideUi();
795784
mGameOverDialog.show();

appOPHD/States/MapViewStateUi.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// ==================================================================================
66

77
#include "MapViewState.h"
8+
#include "ColonyShip.h"
89
#include "MapViewStateHelper.h"
910

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

337338
// Special case code, not thrilled with this
338-
if (mLandersColonist > 0) { mStructures.addItem({constants::ColonistLander, 2, StructureID::SID_COLONIST_LANDER}); }
339-
if (mLandersCargo > 0) { mStructures.addItem({constants::CargoLander, 1, StructureID::SID_CARGO_LANDER}); }
339+
if (mColonyShip.colonistLanders()) { mStructures.addItem({constants::ColonistLander, 2, StructureID::SID_COLONIST_LANDER}); }
340+
if (mColonyShip.cargoLanders()) { mStructures.addItem({constants::CargoLander, 1, StructureID::SID_CARGO_LANDER}); }
340341
}
341342
else
342343
{

0 commit comments

Comments
 (0)