implement waves
This commit is contained in:
@@ -718,3 +718,90 @@ void BuildingSystem::healBuilding(EntityId id, float amount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BuildingSystem::damageBuilding(EntityId id, float amount)
|
||||
{
|
||||
for (Building& b : m_buildings)
|
||||
{
|
||||
if (b.id == id)
|
||||
{
|
||||
b.hp -= amount;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EntityId BuildingSystem::placeImmediate(BuildingType type,
|
||||
const std::vector<std::string>& surfaceMask,
|
||||
QPoint anchor, Rotation rotation,
|
||||
float hp, float maxHp)
|
||||
{
|
||||
const EntityId id = m_allocateId();
|
||||
const ParsedSurfaceMask mask = parseSurfaceMask(surfaceMask, rotation);
|
||||
|
||||
Building building;
|
||||
building.id = id;
|
||||
building.anchor = anchor;
|
||||
building.footprint = mask.footprint;
|
||||
building.rotation = rotation;
|
||||
building.type = type;
|
||||
building.hp = hp;
|
||||
building.maxHp = maxHp;
|
||||
|
||||
for (const QPoint& cell : mask.bodyCells)
|
||||
{
|
||||
const QPoint absCell = anchor + cell;
|
||||
building.bodyCells.push_back(absCell);
|
||||
m_tileOccupancy[{absCell.x(), absCell.y()}] = id;
|
||||
}
|
||||
for (const Port& port : mask.outputPorts)
|
||||
{
|
||||
Port absPort;
|
||||
absPort.tile = anchor + port.tile;
|
||||
absPort.direction = port.direction;
|
||||
building.outputPorts.push_back(absPort);
|
||||
}
|
||||
building.inputPorts = computeInputPorts(building);
|
||||
|
||||
m_buildings.push_back(std::move(building));
|
||||
return id;
|
||||
}
|
||||
|
||||
bool BuildingSystem::removeBuilding(EntityId id)
|
||||
{
|
||||
for (std::vector<Building>::iterator it = m_buildings.begin();
|
||||
it != m_buildings.end();
|
||||
++it)
|
||||
{
|
||||
if (it->id == id)
|
||||
{
|
||||
for (const QPoint& cell : it->bodyCells)
|
||||
{
|
||||
m_tileOccupancy.erase({cell.x(), cell.y()});
|
||||
}
|
||||
m_buildings.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void BuildingSystem::initStationWeapon(EntityId id, const StationWeapon& weapon)
|
||||
{
|
||||
for (Building& b : m_buildings)
|
||||
{
|
||||
if (b.id == id)
|
||||
{
|
||||
b.weapon = weapon;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BuildingSystem::forEachBuilding(std::function<void(Building&)> fn)
|
||||
{
|
||||
for (Building& b : m_buildings)
|
||||
{
|
||||
fn(b);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user