Skip to content

Commit

Permalink
Split Residence implementation to source file
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRStevens committed Feb 11, 2025
1 parent d9f29e5 commit f7ec864
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 80 deletions.
89 changes: 89 additions & 0 deletions appOPHD/MapObjects/Structures/Residence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "Residence.h"

#include "../../Constants/Strings.h"

#include <algorithm>


namespace
{
const int ResidentialWasteCapacityBase = 1000;
const int ResidentialColonistCapacityBase = 25;
}


Residence::Residence() : Structure(
StructureClass::Residence,
StructureID::SID_RESIDENCE)
{
}


int Residence::capacity() const { return ResidentialColonistCapacityBase; }

int Residence::wasteCapacity() const { return ResidentialWasteCapacityBase; }

int Residence::wasteAccumulated() const { return mWasteAccumulated; }
void Residence::wasteAccumulated(int amount) { mWasteAccumulated = amount; }

int Residence::wasteOverflow() const { return mWasteOverflow; }
void Residence::wasteOverflow(int amount) { mWasteOverflow = amount; }


int Residence::pullWaste(int amount)
{
const int pulledAmount = std::clamp(amount, 0, wasteAccumulated() + wasteOverflow());

const int pulledOverflow = std::clamp(pulledAmount, 0, wasteOverflow());
mWasteOverflow -= pulledOverflow;

if (pulledOverflow < amount)
{
mWasteAccumulated -= pulledAmount - pulledOverflow;
}

return pulledAmount;
}


void Residence::assignColonists(int amount)
{
mAssignedColonists = std::clamp(amount, 0, capacity());
}


int Residence::assignedColonists() const { return mAssignedColonists; }


StringTable Residence::createInspectorViewTable()
{
StringTable stringTable(2, 6);

stringTable[{0, 0}].text = "Colonist Capacity:";
stringTable[{1, 0}].text = std::to_string(capacity());

stringTable[{0, 1}].text = "Colonists Assigned:";
stringTable[{1, 1}].text = std::to_string(assignedColonists());

stringTable[{0, 3}].text = "Waste Capacity:";
stringTable[{1, 3}].text = std::to_string(wasteCapacity());

stringTable[{0, 4}].text = "Waste Accumulated:";
stringTable[{1, 4}].text = std::to_string(wasteAccumulated());

stringTable[{0, 5}].text = "Waste Overflow:";
stringTable[{1, 5}].text = std::to_string(wasteOverflow());

return stringTable;
}


void Residence::think()
{
mWasteAccumulated += mAssignedColonists;
if (mWasteAccumulated > wasteCapacity())
{
mWasteOverflow += mWasteAccumulated - wasteCapacity();
mWasteAccumulated = wasteCapacity();
}
}
92 changes: 12 additions & 80 deletions appOPHD/MapObjects/Structures/Residence.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

#include "../Structure.h"

#include "../../Constants/Strings.h"

#include <algorithm>


const int ResidentialWasteCapacityBase = 1000;
const int ResidentialColonistCapacityBase = 25;


/**
* Base Residential structure.
Expand All @@ -20,83 +12,23 @@ const int ResidentialColonistCapacityBase = 25;
class Residence : public Structure
{
public:
Residence() : Structure(
StructureClass::Residence,
StructureID::SID_RESIDENCE)
{
}


int capacity() const { return ResidentialColonistCapacityBase; }

int wasteCapacity() const { return ResidentialWasteCapacityBase; }

int wasteAccumulated() const { return mWasteAccumulated; }
void wasteAccumulated(int amount) { mWasteAccumulated = amount; }

int wasteOverflow() const { return mWasteOverflow; }
void wasteOverflow(int amount) { mWasteOverflow = amount; }


int pullWaste(int amount)
{
const int pulledAmount = std::clamp(amount, 0, wasteAccumulated() + wasteOverflow());

const int pulledOverflow = std::clamp(pulledAmount, 0, wasteOverflow());
mWasteOverflow -= pulledOverflow;

if (pulledOverflow < amount)
{
mWasteAccumulated -= pulledAmount - pulledOverflow;
}
Residence();

return pulledAmount;
}
int capacity() const;
int wasteCapacity() const;
int wasteAccumulated() const;
void wasteAccumulated(int amount);
int wasteOverflow() const;
void wasteOverflow(int amount);
int pullWaste(int amount);

void assignColonists(int amount);
int assignedColonists() const;

void assignColonists(int amount)
{
mAssignedColonists = std::clamp(amount, 0, capacity());
}


int assignedColonists() const { return mAssignedColonists; }


StringTable createInspectorViewTable() override
{
StringTable stringTable(2, 6);

stringTable[{0, 0}].text = "Colonist Capacity:";
stringTable[{1, 0}].text = std::to_string(capacity());

stringTable[{0, 1}].text = "Colonists Assigned:";
stringTable[{1, 1}].text = std::to_string(assignedColonists());

stringTable[{0, 3}].text = "Waste Capacity:";
stringTable[{1, 3}].text = std::to_string(wasteCapacity());

stringTable[{0, 4}].text = "Waste Accumulated:";
stringTable[{1, 4}].text = std::to_string(wasteAccumulated());

stringTable[{0, 5}].text = "Waste Overflow:";
stringTable[{1, 5}].text = std::to_string(wasteOverflow());

return stringTable;
}

StringTable createInspectorViewTable() override;

protected:
void think() override
{
mWasteAccumulated += mAssignedColonists;
if (mWasteAccumulated > wasteCapacity())
{
mWasteOverflow += mWasteAccumulated - wasteCapacity();
mWasteAccumulated = wasteCapacity();
}
}

void think() override;

protected:
int mWasteAccumulated = 0;
Expand Down
1 change: 1 addition & 0 deletions appOPHD/appOPHD.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<ClCompile Include="MapObjects\Structures\MineFacility.cpp" />
<ClCompile Include="MapObjects\Structures\OreRefining.cpp" />
<ClCompile Include="MapObjects\Structures\ResearchFacility.cpp" />
<ClCompile Include="MapObjects\Structures\Residence.cpp" />
<ClCompile Include="MapObjects\Structures\SolarPanelArray.cpp" />
<ClCompile Include="MapObjects\Structures\SolarPlant.cpp" />
<ClCompile Include="MapObjects\Structures\StorageTanks.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions appOPHD/appOPHD.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<ClCompile Include="MapObjects\Structures\ResearchFacility.cpp">
<Filter>Source Files\MapObjects\Structures</Filter>
</ClCompile>
<ClCompile Include="MapObjects\Structures\Residence.cpp">
<Filter>Source Files\MapObjects\Structures</Filter>
</ClCompile>
<ClCompile Include="MapObjects\Structures\SolarPanelArray.cpp">
<Filter>Source Files\MapObjects\Structures</Filter>
</ClCompile>
Expand Down

0 comments on commit f7ec864

Please sign in to comment.