Skip to content
Snippets Groups Projects
Commit a7dc2126 authored by Max Cherris's avatar Max Cherris
Browse files

Add building capture feature

parent 71bdbd13
Branches
No related tags found
2 merge requests!34Building features,!29Merge main into box2d to implement physics
......@@ -596,7 +596,21 @@ void Level::handleSelectingEvents(Engine& engine, SDL_Event& event)
}
}
m_contextMenu.setOptions({"Move", "Attack", "Info", "Wait"});
Unit& u = m_units.at(m_selectedUnit);
if(u.hasMoved()) {
m_contextMenu.setOptions({"Attack", "Info", "Wait"});
} else {
for(auto& [id, building] : m_buildings) {
if(building.m_x == u.m_x && building.m_y == u.m_y) {
m_contextMenu.setOptions({"Capture", "Move", "Attack","Info", "Wait"});
m_captureBuilding = id;
break;
}
}
}
}
else
{
......@@ -703,6 +717,14 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
m_recruitingMenu.setOptions(m_buildings.at(m_selectedBuilding).recruitableUnits());
std::cout << "no training here" << std::endl;
}
if(cmd == "Capture") {
Building& b = m_buildings.at(m_captureBuilding);
UnitFaction u_f = m_units.at(m_selectedUnit).getFaction();
BuildingFaction b_f = static_cast <BuildingFaction> (static_cast<int> (u_f));
b.switch_faction(b_f);
}
}
break;
......
......@@ -133,6 +133,7 @@ class Level : public Scene
int m_selectedUnit;
int m_selectedBuilding;
int m_captureBuilding;
ContextMenu m_contextMenu;
RecruitingMenu m_recruitingMenu;
int m_id;
......
......@@ -324,4 +324,12 @@ void Unit::setState(UnitState state)
this->m_state = state;
}
bool Unit::hasAttacked() {
return this->m_hasAttacked;
}
bool Unit::hasMoved() {
return this->m_hasMoved;
}
} // namespace advanced_wars
\ No newline at end of file
......@@ -135,6 +135,9 @@ class Unit
*/
std::vector<Unit*> getUnitsInRangeWithDamagePotential(const std::vector<Unit*>& allUnits);
bool hasMoved();
bool hasAttacked();
private:
UnitFaction m_faction; // The faction to which this unit belongs.
UnitId m_id; // The identifier for the unit type.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment