Skip to content

Commit

Permalink
Changed PopulationPool methods to const versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar139 committed Feb 24, 2024
1 parent 6b08cda commit 6611252
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 36 deletions.
1 change: 1 addition & 0 deletions OPHD/States/MapViewState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ MapViewState::MapViewState(MainReportsUiState& mainReportsState, const Planet::A
mStructures{"ui/structures.png", 46, constants::MarginTight},
mRobots{"ui/robots.png", 46, constants::MarginTight},
mConnections{"ui/structures.png", 46, constants::MarginTight},
mPopulationPanel{mPopulation, mPopulationPool},
mResourceInfoBar{mResourcesCount, mPopulation, mCurrentMorale, mPreviousMorale, mFood},
mRobotDeploymentSummary{mRobotPool},
mMiniMap{std::make_unique<MiniMap>(*mMapView, mTileMap, mRobotList, planetAttributes.mapImagePath)},
Expand Down
2 changes: 0 additions & 2 deletions OPHD/States/MapViewStateUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ void MapViewState::initUi()
mFileIoDialog.hide();

mPopulationPanel.position({675, constants::ResourceIconSize + 4 + constants::MarginTight});
mPopulationPanel.population(&mPopulation);
mPopulationPanel.populationPool(&mPopulationPool);

mResourceBreakdownPanel.position({0, 22});
mResourceBreakdownPanel.playerResources(&mResourcesCount);
Expand Down
22 changes: 6 additions & 16 deletions OPHD/UI/PopulationPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ static const std::array moraleStringColor
Color{0, 185, 0}
};

PopulationPanel::PopulationPanel() : PopulationPanel::PopulationPanel(Population(), PopulationPool()){};

PopulationPanel::PopulationPanel() :
PopulationPanel::PopulationPanel(const Population& pop, const PopulationPool& popPool) :
mFont{fontCache.load(constants::FONT_PRIMARY, constants::FontPrimaryNormal)},
mFontBold{fontCache.load(constants::FONT_PRIMARY_BOLD, constants::FontPrimaryNormal)},
mIcons{imageCache.load("ui/icons.png")},
mSkin
{
mSkin{
imageCache.load("ui/skin/window_top_left.png"),
imageCache.load("ui/skin/window_top_middle.png"),
imageCache.load("ui/skin/window_top_right.png"),
Expand All @@ -63,9 +63,10 @@ PopulationPanel::PopulationPanel() :
imageCache.load("ui/skin/window_middle_right.png"),
imageCache.load("ui/skin/window_bottom_left.png"),
imageCache.load("ui/skin/window_bottom_middle.png"),
imageCache.load("ui/skin/window_bottom_right.png")
}
imageCache.load("ui/skin/window_bottom_right.png")}
{
mPopulation = &pop;
mPopulationPool = &popPool;
constexpr int linesOfText = 16;
constexpr int edgeBuffer = constants::Margin * 2;
const int windowHeight = mFontBold.height() + (mFont.height() * linesOfText) + (edgeBuffer * 2 /* Times two to account for both the edge and the divider line. */);
Expand All @@ -89,23 +90,12 @@ PopulationPanel::PopulationPanel() :
size({windowWidth, windowHeight});
}

void PopulationPanel::population(Population* pop)
{
mPopulation = pop;
}

void PopulationPanel::populationPool(PopulationPool* popPool)
{
mPopulationPool = popPool;
}

void PopulationPanel::addMoraleReason(const std::string& str, int val)
{
if (val == 0) { return; }
mMoraleChangeReasons.push_back(std::make_pair(str, val));
}


void PopulationPanel::update()
{
auto& renderer = Utility<Renderer>::get();
Expand Down
9 changes: 4 additions & 5 deletions OPHD/UI/PopulationPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class PopulationPanel : public Control
{
public:
PopulationPanel();

void population(Population* pop);
void populationPool(PopulationPool* popPool);
PopulationPanel(const Population& pop, const PopulationPool& popPool);

void morale(int val) { mMorale = val; }
void old_morale(int val) { mPreviousMorale = val; }
Expand All @@ -50,12 +48,13 @@ class PopulationPanel : public Control

std::vector<std::pair<std::string,int>> mMoraleChangeReasons;

Population* mPopulation = nullptr;
PopulationPool* mPopulationPool = nullptr;
const Population* mPopulation;
const PopulationPool* mPopulationPool;

int mMorale{0};
int mPreviousMorale{0};
int mResidentialCapacity{0};
int mCrimeRate{0};
int mPopulationPanelWidth{0};

};
14 changes: 7 additions & 7 deletions libOPHD/Population/PopulationPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Sets a pointer to a Population object.
*
*
* \note PopulationPool expects a valid object and does no checking
* for invalid states.
*/
Expand All @@ -19,13 +19,13 @@ void PopulationPool::population(Population* pop)
}


int PopulationPool::availableWorkers()
int PopulationPool::availableWorkers() const
{
return mPopulation->getPopulations().worker - workersEmployed();
}


int PopulationPool::availableScientists()
int PopulationPool::availableScientists() const
{
return mPopulation->getPopulations().scientist - scientistsEmployed();
}
Expand Down Expand Up @@ -67,7 +67,7 @@ void PopulationPool::clear()
/**
* Amount of Scientists employed as Workers.
*/
int PopulationPool::scientistsAsWorkers()
int PopulationPool::scientistsAsWorkers() const
{
return mScientistsAsWorkers;
}
Expand All @@ -76,7 +76,7 @@ int PopulationPool::scientistsAsWorkers()
/**
* Amount of Scientists currently employed.
*/
int PopulationPool::scientistsEmployed()
int PopulationPool::scientistsEmployed() const
{
return mScientistsUsed;
}
Expand All @@ -85,7 +85,7 @@ int PopulationPool::scientistsEmployed()
/**
* Amount of Workers currently employed.
*/
int PopulationPool::workersEmployed()
int PopulationPool::workersEmployed() const
{
return mWorkersUsed;
}
Expand All @@ -94,7 +94,7 @@ int PopulationPool::workersEmployed()
/**
* Amount of population currently employed.
*/
int PopulationPool::populationEmployed()
int PopulationPool::populationEmployed() const
{
return scientistsEmployed() + scientistsAsWorkers() + workersEmployed();
}
Expand Down
12 changes: 6 additions & 6 deletions libOPHD/Population/PopulationPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class PopulationPool
public:
void population(Population* pop);

int availableWorkers();
int availableScientists();
int availableWorkers() const;
int availableScientists() const;

bool usePopulation(PopulationRequirements populationRequirements);

void clear();

int scientistsAsWorkers();
int scientistsEmployed();
int workersEmployed();
int populationEmployed();
int scientistsAsWorkers() const;
int scientistsEmployed() const;
int workersEmployed() const;
int populationEmployed() const;

int size() const;

Expand Down

0 comments on commit 6611252

Please sign in to comment.