Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope enum StructureState #566

Merged
merged 6 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions OPHD/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ Difficulty DifficultyFromString(std::string difficultyStr)
}


std::map<Structure::StructureState, Color> STRUCTURE_COLOR_TABLE
std::map<StructureState, Color> STRUCTURE_COLOR_TABLE
{
{ Structure::StructureState::UNDER_CONSTRUCTION, Color{150, 150, 150, 100} },
{ Structure::StructureState::OPERATIONAL, Color{0, 185, 0} },
{ Structure::StructureState::IDLE, Color{0, 185, 0, 100} },
{ Structure::StructureState::DISABLED, Color{220, 0, 0} },
{ Structure::StructureState::DESTROYED, Color{220, 0, 0} }
{ StructureState::UnderConstruction, Color{150, 150, 150, 100} },
{ StructureState::Operational, Color{0, 185, 0} },
{ StructureState::Idle, Color{0, 185, 0, 100} },
{ StructureState::Disabled, Color{220, 0, 0} },
{ StructureState::Destroyed, Color{220, 0, 0} }
};


std::map<Structure::StructureState, Color> STRUCTURE_TEXT_COLOR_TABLE
std::map<StructureState, Color> STRUCTURE_TEXT_COLOR_TABLE
{
{ Structure::StructureState::UNDER_CONSTRUCTION, Color{185, 185, 185, 100} },
{ Structure::StructureState::OPERATIONAL, Color{0, 185, 0} },
{ Structure::StructureState::IDLE, Color{0, 185, 0, 100} },
{ Structure::StructureState::DISABLED, Color{220, 0, 0} },
{ Structure::StructureState::DESTROYED, Color{220, 0, 0} }
{ StructureState::UnderConstruction, Color{185, 185, 185, 100} },
{ StructureState::Operational, Color{0, 185, 0} },
{ StructureState::Idle, Color{0, 185, 0, 100} },
{ StructureState::Disabled, Color{220, 0, 0} },
{ StructureState::Destroyed, Color{220, 0, 0} }
};


Expand Down Expand Up @@ -265,15 +265,15 @@ const std::string& idleReason(IdleReason _i)
}


Color& structureColorFromIndex(std::size_t index)
Color& structureColorFromIndex(StructureState structureState)
{
return STRUCTURE_COLOR_TABLE[static_cast<Structure::StructureState>(index)];
return STRUCTURE_COLOR_TABLE[structureState];
}


Color& structureTextColorFromIndex(std::size_t index)
Color& structureTextColorFromIndex(StructureState structureState)
{
return STRUCTURE_TEXT_COLOR_TABLE[static_cast<Structure::StructureState>(index)];
return STRUCTURE_TEXT_COLOR_TABLE[structureState];
}


Expand Down
16 changes: 14 additions & 2 deletions OPHD/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,19 @@ const std::string& idleReason(IdleReason);
*/
void drawBasicProgressBar(int x, int y, int width, int height, float percent, int padding = 4);

NAS2D::Color& structureColorFromIndex(std::size_t);
NAS2D::Color& structureTextColorFromIndex(std::size_t);
/**
* State of an individual Structure.
*/
enum class StructureState
{
UnderConstruction,
Operational,
Idle,
Disabled,
Destroyed
};

NAS2D::Color& structureColorFromIndex(StructureState structureState);
NAS2D::Color& structureTextColorFromIndex(StructureState structureState);

bool windowMaximized();
2 changes: 1 addition & 1 deletion OPHD/States/MapViewState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ void MapViewState::checkConnectedness()
throw std::runtime_error("CC coordinates do not actually point to a Command Center.");
}

if (cc->state() == Structure::StructureState::UNDER_CONSTRUCTION)
if (cc->state() == StructureState::UnderConstruction)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion OPHD/States/MapViewStateIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void MapViewState::readStructures(Xml::XmlElement* element)
}

st->age(age);
st->forced_state_change(static_cast<Structure::StructureState>(state), static_cast<DisabledReason>(disabled_reason), static_cast<IdleReason>(idle_reason));
st->forced_state_change(static_cast<StructureState>(state), static_cast<DisabledReason>(disabled_reason), static_cast<IdleReason>(idle_reason));
st->connectorDirection(static_cast<ConnectorDir>(direction));

if (forced_idle != 0) { st->forceIdle(forced_idle != 0); }
Expand Down
18 changes: 9 additions & 9 deletions OPHD/States/MapViewStateTurn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ void MapViewState::updatePopulation()
{
StructureManager& structureManager = NAS2D::Utility<StructureManager>::get();

int residences = structureManager.getCountInState(Structure::StructureClass::Residence, Structure::StructureState::OPERATIONAL);
int universities = structureManager.getCountInState(Structure::StructureClass::University, Structure::StructureState::OPERATIONAL);
int nurseries = structureManager.getCountInState(Structure::StructureClass::Nursery, Structure::StructureState::OPERATIONAL);
int hospitals = structureManager.getCountInState(Structure::StructureClass::MedicalCenter, Structure::StructureState::OPERATIONAL);
int residences = structureManager.getCountInState(Structure::StructureClass::Residence, StructureState::Operational);
int universities = structureManager.getCountInState(Structure::StructureClass::University, StructureState::Operational);
int nurseries = structureManager.getCountInState(Structure::StructureClass::Nursery, StructureState::Operational);
int hospitals = structureManager.getCountInState(Structure::StructureClass::MedicalCenter, StructureState::Operational);

// FOOD CONSUMPTION
int food_consumed = mPopulation.update(mCurrentMorale, foodInStorage(), residences, universities, nurseries, hospitals);
Expand Down Expand Up @@ -80,7 +80,7 @@ void MapViewState::updateCommercial()
// No need to do anything if there are no commercial structures.
if (_commercial.empty()) { return; }

int luxuryCount = structureManager.getCountInState(Structure::StructureClass::Commercial, Structure::StructureState::OPERATIONAL);
int luxuryCount = structureManager.getCountInState(Structure::StructureClass::Commercial, StructureState::Operational);
int commercialCount = luxuryCount;

for (auto warehouse : _warehouses)
Expand Down Expand Up @@ -137,13 +137,13 @@ void MapViewState::updateMorale()
// POSITIVE MORALE EFFECTS
// =========================================
mCurrentMorale += mPopulation.birthCount();
mCurrentMorale += structureManager.getCountInState(Structure::StructureClass::Park, Structure::StructureState::OPERATIONAL);
mCurrentMorale += structureManager.getCountInState(Structure::StructureClass::RecreationCenter, Structure::StructureState::OPERATIONAL);
mCurrentMorale += structureManager.getCountInState(Structure::StructureClass::Park, StructureState::Operational);
mCurrentMorale += structureManager.getCountInState(Structure::StructureClass::RecreationCenter, StructureState::Operational);

int food_production = structureManager.getCountInState(Structure::StructureClass::FoodProduction, Structure::StructureState::OPERATIONAL);
int food_production = structureManager.getCountInState(Structure::StructureClass::FoodProduction, StructureState::Operational);
mCurrentMorale += food_production > 0 ? food_production : -5;

mCurrentMorale += structureManager.getCountInState(Structure::StructureClass::Commercial, Structure::StructureState::OPERATIONAL);
mCurrentMorale += structureManager.getCountInState(Structure::StructureClass::Commercial, StructureState::Operational);

// NEGATIVE MORALE EFFECTS
// =========================================
Expand Down
8 changes: 4 additions & 4 deletions OPHD/StructureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ int StructureManager::count() const
/**
*
*/
int StructureManager::getCountInState(Structure::StructureClass st, Structure::StructureState state)
int StructureManager::getCountInState(Structure::StructureClass st, StructureState state)
{
int count = 0;
for (std::size_t i = 0; i < structureList(st).size(); ++i)
Expand All @@ -341,7 +341,7 @@ int StructureManager::disabled()
int count = 0;
for (auto it = mStructureLists.begin(); it != mStructureLists.end(); ++it)
{
count += getCountInState(it->first, Structure::StructureState::DISABLED);
count += getCountInState(it->first, StructureState::Disabled);
}

return count;
Expand All @@ -356,7 +356,7 @@ int StructureManager::destroyed()
int count = 0;
for (auto it = mStructureLists.begin(); it != mStructureLists.end(); ++it)
{
count += getCountInState(it->first, Structure::StructureState::DESTROYED);
count += getCountInState(it->first, StructureState::Destroyed);
}

return count;
Expand Down Expand Up @@ -411,7 +411,7 @@ void serializeStructure(XmlElement* _ti, Structure* structure, Tile* _t)
_ti->attribute("depth", _t->depth());

_ti->attribute("age", structure->age());
_ti->attribute("state", structure->state());
_ti->attribute("state", static_cast<int>(structure->state()));
_ti->attribute("forced_idle", structure->forceIdle());
_ti->attribute("disabled_reason", static_cast<int>(structure->disabledReason()));
_ti->attribute("idle_reason", static_cast<int>(structure->idleReason()));
Expand Down
2 changes: 1 addition & 1 deletion OPHD/StructureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StructureManager

int count() const;

int getCountInState(Structure::StructureClass st, Structure::StructureState state);
int getCountInState(Structure::StructureClass st, StructureState state);

int disabled();
int destroyed();
Expand Down
2 changes: 1 addition & 1 deletion OPHD/Things/Structures/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Factory::updateProduction()
* \fixme Most of these can be combined into a single
* compound conditional statement.
*/
if (state() != StructureState::OPERATIONAL)
if (state() != StructureState::Operational)
{
return;
}
Expand Down
32 changes: 16 additions & 16 deletions OPHD/Things/Structures/Structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
/**
* Translation table for Structure States.
*/
std::map<Structure::StructureState, std::string> STRUCTURE_STATE_TRANSLATION =
std::map<StructureState, std::string> STRUCTURE_STATE_TRANSLATION =
{
{ Structure::StructureState::UNDER_CONSTRUCTION, "Under Construction" },
{ Structure::StructureState::OPERATIONAL, "Operational" },
{ Structure::StructureState::IDLE, "Idle" },
{ Structure::StructureState::DISABLED, "Disabled" },
{ Structure::StructureState::DESTROYED, "Destroyed" },
{ StructureState::UnderConstruction, "Under Construction" },
{ StructureState::Operational, "Operational" },
{ StructureState::Idle, "Idle" },
{ StructureState::Disabled, "Disabled" },
{ StructureState::Destroyed, "Destroyed" },
};


Expand Down Expand Up @@ -48,7 +48,7 @@ std::map<Structure::StructureClass, std::string> STRUCTURE_CLASS_TRANSLATION =
};


const std::string& structureStateDescription(Structure::StructureState _state)
const std::string& structureStateDescription(StructureState _state)
{
return STRUCTURE_STATE_TRANSLATION[_state];
}
Expand Down Expand Up @@ -88,7 +88,7 @@ void Structure::disable(DisabledReason reason)
{
sprite().pause();
sprite().color(NAS2D::Color{255, 0, 0, 185});
state(StructureState::DISABLED);
state(StructureState::Disabled);
mDisabledReason = reason;
mIdleReason = IdleReason::None;
disabledStateSet();
Expand All @@ -108,7 +108,7 @@ void Structure::enable()

sprite().resume();
sprite().color(NAS2D::Color::White);
state(StructureState::OPERATIONAL);
state(StructureState::Operational);
mDisabledReason = DisabledReason::None;
mIdleReason = IdleReason::None;
}
Expand All @@ -128,7 +128,7 @@ void Structure::idle(IdleReason reason)
sprite().color(NAS2D::Color{255, 255, 255, 185});
mDisabledReason = DisabledReason::None;
mIdleReason = reason;
state(StructureState::IDLE);
state(StructureState::Idle);
}


Expand Down Expand Up @@ -213,7 +213,7 @@ void Structure::incrementAge()
void Structure::destroy()
{
sprite().play(constants::STRUCTURE_STATE_DESTROYED);
state(StructureState::DESTROYED);
state(StructureState::Destroyed);

// Destroyed buildings just need to be rebuilt right?
repairable(false);
Expand All @@ -234,11 +234,11 @@ void Structure::forced_state_change(StructureState structureState, DisabledReaso
//enable();
}

if (structureState == StructureState::OPERATIONAL) { enable(); }
else if (structureState == StructureState::IDLE) { idle(idleReason); }
else if (structureState == StructureState::DISABLED) { disable(disabledReason); }
else if (structureState == StructureState::DESTROYED) { destroy(); }
else if (structureState == StructureState::UNDER_CONSTRUCTION) { mStructureState = StructureState::UNDER_CONSTRUCTION; } // Kludge
if (structureState == StructureState::Operational) { enable(); }
else if (structureState == StructureState::Idle) { idle(idleReason); }
else if (structureState == StructureState::Disabled) { disable(disabledReason); }
else if (structureState == StructureState::Destroyed) { destroy(); }
else if (structureState == StructureState::UnderConstruction) { mStructureState = StructureState::UnderConstruction; } // Kludge
}


Expand Down
26 changes: 7 additions & 19 deletions OPHD/Things/Structures/Structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
class Structure: public Thing
{
public:
/**
* State of an individual Structure.
*/
enum StructureState
{
UNDER_CONSTRUCTION,
OPERATIONAL,
IDLE,
DISABLED,
DESTROYED
};

/**
* Class of a Structure.
*
Expand Down Expand Up @@ -69,21 +57,21 @@ class Structure: public Thing
// STATES & STATE MANAGEMENT
StructureState state() const { return mStructureState; }

bool disabled() const { return mStructureState == StructureState::DISABLED; }
bool disabled() const { return mStructureState == StructureState::Disabled; }
void disable(DisabledReason);
DisabledReason disabledReason() const { return mDisabledReason; }

bool operational() const { return mStructureState == StructureState::OPERATIONAL; }
bool operational() const { return mStructureState == StructureState::Operational; }
void enable();

bool isIdle() const { return mStructureState == StructureState::IDLE; }
bool isIdle() const { return mStructureState == StructureState::Idle; }
void idle(IdleReason);
IdleReason idleReason() const { return mIdleReason; }

bool destroyed() const { return mStructureState == StructureState::DESTROYED; }
bool destroyed() const { return mStructureState == StructureState::Destroyed; }
void destroy();

bool underConstruction() const { return mStructureState == StructureState::UNDER_CONSTRUCTION; }
bool underConstruction() const { return mStructureState == StructureState::UnderConstruction; }

void forceIdle(bool force);
bool forceIdle() const { return mForcedIdle; }
Expand Down Expand Up @@ -182,7 +170,7 @@ class Structure: public Thing
int mAge = 0; /**< Age of the Structure in turns. */
int mMaxAge = 0; /**< Maximum number of turns the Structure can remain in good repair. */

StructureState mStructureState = StructureState::UNDER_CONSTRUCTION; /**< State the structure is in. */
StructureState mStructureState = StructureState::UnderConstruction; /**< State the structure is in. */
StructureClass mStructureClass; /**< Indicates the Structure's Type. */
ConnectorDir mConnectorDirection = ConnectorDir::CONNECTOR_INTERSECTION; /**< Directions available for connections. */

Expand All @@ -207,5 +195,5 @@ class Structure: public Thing

using StructureList = std::vector<Structure*>;

const std::string& structureStateDescription(Structure::StructureState);
const std::string& structureStateDescription(StructureState);
const std::string& structureClassDescription(Structure::StructureClass);
2 changes: 1 addition & 1 deletion OPHD/UI/FactoryListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void FactoryListBox::addItem(Factory* factory)
else if (item->Text == constants::UNDERGROUND_FACTORY) { item->icon_slice = {138, 276}; }
else if (item->Text == constants::SEED_FACTORY) { item->icon_slice = {460, 368}; }

if (factory->state() == Structure::StructureState::DESTROYED) { item->icon_slice = {414, 368}; }
if (factory->state() == StructureState::Destroyed) { item->icon_slice = {414, 368}; }
_update_item_display();
}

Expand Down
Loading