Skip to content
Snippets Groups Projects
Commit 16f9795d authored by Lorenz Martin Diel's avatar Lorenz Martin Diel
Browse files

UNAVAILABLE Units now can't move

parent ad8c46f8
Branches
No related tags found
2 merge requests!31Updated unit contextmenu,!29Merge main into box2d to implement physics
......@@ -593,7 +593,8 @@ void Level::handleSelectingEvents(Engine& engine, SDL_Event& event)
m_attackableUnitIds.clear();
// Set Fallback_position if movement will be canceled
unit_fallback_position = std::make_pair(m_units.at(m_selectedUnit).m_x, m_units.at(m_selectedUnit).m_y);
unit_fallback_position = std::make_pair(
m_units.at(m_selectedUnit).m_x, m_units.at(m_selectedUnit).m_y);
for (Unit* target : attackableTargets)
{
......@@ -613,13 +614,13 @@ void Level::handleSelectingEvents(Engine& engine, SDL_Event& event)
// Show according menu options if unit has same/different faction than current
// player
if (m_units.at(m_selectedUnit).getFaction() == m_turnQ.front().getFaction())
if (m_units.at(m_selectedUnit).getFaction() == m_turnQ.front().getFaction() && m_units.at(m_selectedUnit).getState()!= UnitState::UNAVAILABLE)
{
m_contextMenu.setOptions({"Move", "Attack", "Info", "Wait", "End Turn"});
}
else
{
m_contextMenu.setOptions({"Info", "Wait", "End Turn"});
m_contextMenu.setOptions({"Info", "End Turn"});
}
}
else
......@@ -629,11 +630,11 @@ void Level::handleSelectingEvents(Engine& engine, SDL_Event& event)
if (m_buildings.at(m_selectedBuilding).getFaction() ==
static_cast<BuildingFaction>(m_turnQ.front().getFaction()))
{
m_contextMenu.setOptions({"Train", "Info", "Wait", "End Turn"});
m_contextMenu.setOptions({"Train", "Info", "End Turn"});
}
else
{
m_contextMenu.setOptions({"Info", "Wait", "End Turn"});
m_contextMenu.setOptions({"Info", "End Turn"});
}
}
m_state = LevelState::MENUACTIVE_STATE;
......@@ -680,9 +681,12 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
{
if (m_selectedUnit > -1 && unit_fallback_position != std::make_pair(m_units.at(m_selectedUnit).m_x, m_units.at(m_selectedUnit).m_y))
if (m_selectedUnit > -1 &&
unit_fallback_position !=
std::make_pair(m_units.at(m_selectedUnit).m_x, m_units.at(m_selectedUnit).m_y))
{
m_units.at(m_selectedUnit).updatePosition(unit_fallback_position.first, unit_fallback_position.second);
m_units.at(m_selectedUnit)
.updatePosition(unit_fallback_position.first, unit_fallback_position.second);
}
m_selectedUnit = -1;
m_selectedBuilding = -1;
......@@ -705,6 +709,10 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
it->second.setState(UnitState::UNAVAILABLE);
std::cout << "Unit state set to UNAVAILABLE." << std::endl;
m_state = LevelState::SELECTING_STATE;
m_selectedUnit = -1;
m_selectedBuilding = -1;
m_showAttackableTiles = false;
m_showReachableTiles = false;
}
else
{
......
......@@ -125,6 +125,8 @@ class Unit
void setState(UnitState state);
inline UnitState getState() const { return m_state; }
/**
* Retrieves units within range that this unit can deal damage to.
* Considers all units provided in 'allUnits', excluding itself, and checks movement and
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment