diff --git a/OPHD/States/CrimeExecution.cpp b/OPHD/States/CrimeExecution.cpp index aa17f5148..35822673b 100644 --- a/OPHD/States/CrimeExecution.cpp +++ b/OPHD/States/CrimeExecution.cpp @@ -47,9 +47,8 @@ namespace } -CrimeExecution::CrimeExecution(NotificationArea& notificationArea, const Difficulty& difficulty) : - mDifficulty{difficulty}, - mNotificationArea{notificationArea} +CrimeExecution::CrimeExecution(const Difficulty& difficulty) : + mDifficulty{difficulty} { } @@ -88,13 +87,11 @@ void CrimeExecution::stealFood(FoodProduction& structure) int foodStolen = calcAmountForStealing(mDifficulty, 5, 15, structure.foodLevel()); structure.foodLevel(structure.foodLevel() - foodStolen); - const auto& structureTile = NAS2D::Utility::get().tileFromStructure(&structure); - - mNotificationArea.push({ + mCrimeEventSignal.emit( "Food Stolen", NAS2D::stringFrom(foodStolen) + " units of food was pilfered from a " + structure.name() + ". " + getReasonForStealing() + ".", - structureTile.xyz(), - NotificationArea::NotificationType::Warning}); + structure + ); } } @@ -125,13 +122,11 @@ void CrimeExecution::stealResources(Structure& structure, const std::array::get().tileFromStructure(&structure); - - mNotificationArea.push({ + mCrimeEventSignal.emit( "Resources Stolen", NAS2D::stringFrom(amountStolen) + " units of " + resourceNames[indexToStealFrom] + " were stolen from a " + structure.name() + ". " + getReasonForStealing() + ".", - structureTile.xyz(), - NotificationArea::NotificationType::Warning}); + structure + ); } @@ -139,11 +134,9 @@ void CrimeExecution::vandalize(Structure& structure) { mMoraleChanges.push_back(std::make_pair("Vandalism", -1)); - const auto& structureTile = NAS2D::Utility::get().tileFromStructure(&structure); - - mNotificationArea.push({ + mCrimeEventSignal.emit( "Vandalism", "A " + structure.name() + " was vandalized.", - structureTile.xyz(), - NotificationArea::NotificationType::Warning}); + structure + ); } diff --git a/OPHD/States/CrimeExecution.h b/OPHD/States/CrimeExecution.h index dce1ba4ef..ff5da9ac0 100644 --- a/OPHD/States/CrimeExecution.h +++ b/OPHD/States/CrimeExecution.h @@ -3,6 +3,8 @@ #include "../MapObjects/Structures/FoodProduction.h" #include "../Common.h" +#include + #include #include #include @@ -16,11 +18,13 @@ class NotificationArea; class CrimeExecution { public: - CrimeExecution(NotificationArea& notificationArea, const Difficulty& difficulty); + using Signal = NAS2D::Signal; - void executeCrimes(const std::vector& structuresCommittingCrime); + CrimeExecution(const Difficulty& difficulty); + void executeCrimes(const std::vector& structuresCommittingCrime); std::vector> moraleChanges() const { return mMoraleChanges; } + Signal::Source& crimeEventSignal() { return mCrimeEventSignal; } protected: void stealFood(FoodProduction& structure); @@ -31,6 +35,6 @@ class CrimeExecution private: const Difficulty& mDifficulty; - NotificationArea& mNotificationArea; std::vector> mMoraleChanges; + Signal mCrimeEventSignal; }; diff --git a/OPHD/States/MapViewState.cpp b/OPHD/States/MapViewState.cpp index 0cbef43fe..b19140b59 100644 --- a/OPHD/States/MapViewState.cpp +++ b/OPHD/States/MapViewState.cpp @@ -177,7 +177,7 @@ const std::map MapViewState::ColonyShipDeorbitMoraleLossMultipl MapViewState::MapViewState(MainReportsUiState& mainReportsState, const std::string& savegame) : mCrimeRateUpdate{mDifficulty}, - mCrimeExecution{mNotificationArea, mDifficulty}, + mCrimeExecution{mDifficulty}, mTechnologyReader{"tech0-1.xml"}, mLoadingExisting{true}, mExistingToLoad{savegame}, @@ -191,6 +191,7 @@ MapViewState::MapViewState(MainReportsUiState& mainReportsState, const std::stri { ccLocation() = CcNotPlaced; NAS2D::Utility::get().windowResized().connect({this, &MapViewState::onWindowResized}); + mCrimeExecution.crimeEventSignal().connect({this, &MapViewState::onCrimeEvent}); } @@ -198,7 +199,7 @@ MapViewState::MapViewState(MainReportsUiState& mainReportsState, const Planet::A mDifficulty{selectedDifficulty}, mTileMap{std::make_unique(planetAttributes.mapImagePath, planetAttributes.maxDepth, planetAttributes.maxMines, HostilityMineYields.at(planetAttributes.hostility))}, mCrimeRateUpdate{mDifficulty}, - mCrimeExecution{mNotificationArea, mDifficulty}, + mCrimeExecution{mDifficulty}, mTechnologyReader{"tech0-1.xml"}, mPlanetAttributes{planetAttributes}, mMainReportsState{mainReportsState}, @@ -217,6 +218,7 @@ MapViewState::MapViewState(MainReportsUiState& mainReportsState, const Planet::A setMeanSolarDistance(mPlanetAttributes.meanSolarDistance); ccLocation() = CcNotPlaced; NAS2D::Utility::get().windowResized().connect({this, &MapViewState::onWindowResized}); + mCrimeExecution.crimeEventSignal().connect({this, &MapViewState::onCrimeEvent}); } diff --git a/OPHD/States/MapViewState.h b/OPHD/States/MapViewState.h index c6c9956f4..5faf091c3 100644 --- a/OPHD/States/MapViewState.h +++ b/OPHD/States/MapViewState.h @@ -205,6 +205,8 @@ class MapViewState : public Wrapper void onMineFacilityExtend(MineFacility* mf); + void onCrimeEvent(std::string title, std::string text, const Structure& structure); + void updatePlayerResources(); void updateResearch(); diff --git a/OPHD/States/MapViewStateEvent.cpp b/OPHD/States/MapViewStateEvent.cpp index cb8b7f32b..c0aba85d5 100644 --- a/OPHD/States/MapViewStateEvent.cpp +++ b/OPHD/States/MapViewStateEvent.cpp @@ -251,3 +251,16 @@ void MapViewState::onMineFacilityExtend(MineFacility* mineFacility) mineDepthTile.index(TerrainType::Dozed); mineDepthTile.excavated(true); } + + +void MapViewState::onCrimeEvent(std::string title, std::string text, const Structure& structure) +{ + const auto& structureTile = NAS2D::Utility::get().tileFromStructure(&structure); + + mNotificationArea.push({ + std::move(title), + std::move(text), + structureTile.xyz(), + NotificationArea::NotificationType::Warning + }); +}