Skip to content

Commit e434faa

Browse files
authored
Merge pull request #1575 from OutpostUniverse/splitStructureImplementationToSource
Split `Structure` implementations to source files
2 parents 5f1c5dd + 5501359 commit e434faa

33 files changed

+824
-520
lines changed

appOPHD/MapObjects/Structure.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
#include "../StructureCatalogue.h"
66
#include "../Constants/Strings.h"
77

8+
#include "../UI/StringTable.h"
9+
810
#include <libOPHD/RandomNumberGenerator.h>
911

12+
#include <NAS2D/Dictionary.h>
13+
1014
#include <algorithm>
1115

1216

@@ -443,6 +447,12 @@ void Structure::integrity(int integrity)
443447
}
444448

445449

450+
StringTable Structure::createInspectorViewTable()
451+
{
452+
return StringTable(0, 0);
453+
}
454+
455+
446456
NAS2D::Dictionary Structure::getDataDict() const
447457
{
448458
NAS2D::Dictionary dictionary =

appOPHD/MapObjects/Structure.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
#include "MapObject.h"
44

55
#include "../StorableResources.h"
6-
#include "../UI/StringTable.h"
76

87
#include <libOPHD/EnumConnectorDir.h>
98
#include <libOPHD/EnumDisabledReason.h>
109
#include <libOPHD/EnumIdleReason.h>
1110
#include <libOPHD/EnumStructureID.h>
1211
#include <libOPHD/Population/PopulationPool.h>
1312

14-
#include <NAS2D/Dictionary.h>
13+
14+
namespace NAS2D
15+
{
16+
class Dictionary;
17+
}
1518

1619

1720
struct StructureType;
21+
class StringTable;
1822

1923

2024
/**
@@ -172,7 +176,7 @@ class Structure : public MapObject
172176
/**
173177
* Pass limited structure specific details for drawing. Use a custom UI window if needed.
174178
*/
175-
virtual StringTable createInspectorViewTable() { return StringTable(0, 0); }
179+
virtual StringTable createInspectorViewTable();
176180

177181
virtual NAS2D::Dictionary getDataDict() const;
178182

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "Agridome.h"
2+
3+
4+
#include "../../Constants/Strings.h"
5+
6+
#include <algorithm>
7+
8+
9+
const int AGRIDOME_CAPACITY = 1000;
10+
const int AGRIDOME_BASE_PRODUCUCTION = 10;
11+
12+
13+
Agridome::Agridome() : FoodProduction(StructureClass::FoodProduction, StructureID::SID_AGRIDOME)
14+
{
15+
}
16+
17+
18+
void Agridome::think()
19+
{
20+
if (isIdle()) { return; }
21+
22+
mFoodLevel = std::clamp(mFoodLevel + calculateProduction(), 0, AGRIDOME_CAPACITY);
23+
24+
if (isStorageFull())
25+
{
26+
idle(IdleReason::InternalStorageFull);
27+
}
28+
}
29+
30+
31+
void Agridome::disabledStateSet()
32+
{
33+
mFoodLevel = 0;
34+
}
35+
36+
37+
int Agridome::foodCapacity()
38+
{
39+
return AGRIDOME_CAPACITY;
40+
}
41+
42+
43+
int Agridome::calculateProduction()
44+
{
45+
if (!operational())
46+
{
47+
return 0;
48+
}
49+
50+
return std::min(AGRIDOME_BASE_PRODUCUCTION, AGRIDOME_CAPACITY - mFoodLevel);
51+
}
52+
53+
54+
bool Agridome::isStorageFull()
55+
{
56+
return mFoodLevel >= AGRIDOME_CAPACITY;
57+
}

appOPHD/MapObjects/Structures/Agridome.h

+7-43
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,21 @@
22

33
#include "FoodProduction.h"
44

5-
#include "../../Constants/Strings.h"
6-
7-
#include <algorithm>
8-
9-
10-
const int AGRIDOME_CAPACITY = 1000;
11-
const int AGRIDOME_BASE_PRODUCUCTION = 10;
125

136
class Agridome : public FoodProduction
147
{
158
public:
16-
Agridome() : FoodProduction(StructureClass::FoodProduction, StructureID::SID_AGRIDOME)
17-
{
18-
}
9+
Agridome();
1910

2011
protected:
21-
void think() override
22-
{
23-
if (isIdle()) { return; }
12+
void think() override;
2413

25-
mFoodLevel = std::clamp(mFoodLevel + calculateProduction(), 0, AGRIDOME_CAPACITY);
14+
void disabledStateSet() override;
2615

27-
if (isStorageFull())
28-
{
29-
idle(IdleReason::InternalStorageFull);
30-
}
31-
}
32-
33-
void disabledStateSet() override
34-
{
35-
mFoodLevel = 0;
36-
}
37-
38-
virtual int foodCapacity() override
39-
{
40-
return AGRIDOME_CAPACITY;
41-
}
16+
virtual int foodCapacity() override;
4217

4318
private:
44-
virtual int calculateProduction() override
45-
{
46-
if (!operational())
47-
{
48-
return 0;
49-
}
50-
51-
return std::min(AGRIDOME_BASE_PRODUCUCTION, AGRIDOME_CAPACITY - mFoodLevel);
52-
}
53-
54-
bool isStorageFull()
55-
{
56-
return mFoodLevel >= AGRIDOME_CAPACITY;
57-
}
19+
virtual int calculateProduction() override;
20+
21+
bool isStorageFull();
5822
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "CommTower.h"
2+
3+
4+
#include "../../Constants/Strings.h"
5+
#include "../../Constants/UiConstants.h"
6+
7+
#include "../../UI/StringTable.h"
8+
9+
10+
namespace
11+
{
12+
const int BaseRange = 10;
13+
}
14+
15+
16+
CommTower::CommTower() : Structure(
17+
StructureClass::Communication,
18+
StructureID::SID_COMM_TOWER)
19+
{
20+
}
21+
22+
23+
int CommTower::getRange() const
24+
{
25+
return operational() ? BaseRange : 0;
26+
}
27+
28+
29+
StringTable CommTower::createInspectorViewTable()
30+
{
31+
StringTable stringTable(2, 1);
32+
33+
stringTable[{0, 0}].text = "Communication Range:";
34+
35+
auto communicationRange = getRange();
36+
stringTable[{1, 0}].text = std::to_string(communicationRange);
37+
38+
if (communicationRange == 0)
39+
{
40+
stringTable[{1, 0}].textColor = constants::WarningTextColor;
41+
}
42+
43+
return stringTable;
44+
}

appOPHD/MapObjects/Structures/CommTower.h

+3-33
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,13 @@
22

33
#include "../Structure.h"
44

5-
#include "../../Constants/Strings.h"
6-
#include "../../Constants/UiConstants.h"
7-
85

96
class CommTower : public Structure
107
{
11-
private:
12-
const int BaseRange = 10;
13-
148
public:
15-
CommTower() : Structure(
16-
StructureClass::Communication,
17-
StructureID::SID_COMM_TOWER)
18-
{
19-
}
20-
21-
22-
int getRange() const
23-
{
24-
return operational() ? BaseRange : 0;
25-
}
26-
27-
28-
StringTable createInspectorViewTable() override
29-
{
30-
StringTable stringTable(2, 1);
31-
32-
stringTable[{0, 0}].text = "Communication Range:";
33-
34-
auto communicationRange = getRange();
35-
stringTable[{1, 0}].text = std::to_string(communicationRange);
9+
CommTower();
3610

37-
if (communicationRange == 0)
38-
{
39-
stringTable[{1, 0}].textColor = constants::WarningTextColor;
40-
}
11+
int getRange() const;
4112

42-
return stringTable;
43-
}
13+
StringTable createInspectorViewTable() override;
4414
};

appOPHD/MapObjects/Structures/Factory.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "../../ProductionCost.h"
44
#include "../../States/MapViewStateHelper.h" // yuck
55

6+
#include <NAS2D/Dictionary.h>
7+
68
#include <algorithm>
79

810

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "FoodProduction.h"
2+
3+
#include "../../UI/StringTable.h"
4+
5+
6+
FoodProduction::FoodProduction(StructureClass structureClass, StructureID id) :
7+
Structure(structureClass, id)
8+
{
9+
}
10+
11+
12+
StringTable FoodProduction::createInspectorViewTable()
13+
{
14+
StringTable stringTable(2, 2);
15+
16+
stringTable[{0, 0}].text = "Food Stored:";
17+
stringTable[{1, 0}].text = std::to_string(mFoodLevel) + " / " + std::to_string(foodCapacity());
18+
19+
stringTable[{0, 1}].text = "Production Rate:";
20+
stringTable[{1, 1}].text = std::to_string(calculateProduction());
21+
22+
return stringTable;
23+
}
24+
25+
26+
int FoodProduction::foodLevel() const
27+
{
28+
return mFoodLevel;
29+
}
30+
31+
32+
void FoodProduction::foodLevel(int level)
33+
{
34+
mFoodLevel = std::clamp(level, 0, foodCapacity());
35+
}

appOPHD/MapObjects/Structures/FoodProduction.h

+5-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "../Structure.h"
44

5+
56
/**
67
* Virtual class for structures whose primary purpose is agricultural production
78
*
@@ -10,24 +11,12 @@
1011
class FoodProduction : public Structure
1112
{
1213
public:
13-
FoodProduction(StructureClass structureClass, StructureID id) :
14-
Structure(structureClass, id) {}
15-
16-
StringTable createInspectorViewTable() override
17-
{
18-
StringTable stringTable(2, 2);
19-
20-
stringTable[{0, 0}].text = "Food Stored:";
21-
stringTable[{1, 0}].text = std::to_string(mFoodLevel) + " / " + std::to_string(foodCapacity());
22-
23-
stringTable[{0, 1}].text = "Production Rate:";
24-
stringTable[{1, 1}].text = std::to_string(calculateProduction());
14+
FoodProduction(StructureClass structureClass, StructureID id);
2515

26-
return stringTable;
27-
}
16+
StringTable createInspectorViewTable() override;
2817

29-
int foodLevel() const { return mFoodLevel; }
30-
void foodLevel(int level) { mFoodLevel = std::clamp(level, 0, foodCapacity()); }
18+
int foodLevel() const;
19+
void foodLevel(int level);
3120

3221
virtual int foodCapacity() = 0;
3322

0 commit comments

Comments
 (0)