80 lines
1.7 KiB
C++
80 lines
1.7 KiB
C++
#include "Squad.h"
|
|
|
|
Squad::Squad()
|
|
{
|
|
this->action = "";
|
|
this->center = TilePosition(0, 0);
|
|
}
|
|
|
|
void Squad::addUnit(CUnit unit)
|
|
{
|
|
this->units.push_back(unit);
|
|
this->airDamage += unit.unitType.airWeapon().damageAmount();
|
|
this->groundDamage += unit.unitType.groundWeapon().damageAmount();
|
|
}
|
|
|
|
void Squad::attack(std::pair<TilePosition, int> baseToAttack)
|
|
{
|
|
this->action = "attack";
|
|
Position attackLocation = Position(baseToAttack.first);
|
|
this->target = TilePosition(attackLocation);
|
|
for (auto u : this->units)
|
|
{
|
|
u.unit->attack(attackLocation);
|
|
if (u.unit->getType() == UnitTypes::Zerg_Overlord)
|
|
{
|
|
u.unit->move(this->units.at(rand() % this->units.size()).unit->getPosition());
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO rename
|
|
void Squad::checkCenter()
|
|
{
|
|
int averageX = 0;
|
|
int averageY = 0;
|
|
int size = this->units.size();
|
|
if (size == 0) size = 1;
|
|
|
|
for (auto u : this->units)
|
|
{
|
|
averageX += u.unit->getTilePosition().x;
|
|
averageY += u.unit->getTilePosition().y;
|
|
}
|
|
|
|
this->center = TilePosition((averageX / size), (averageY / size));
|
|
}
|
|
|
|
//TODO rename
|
|
void Squad::checkDamage()
|
|
{
|
|
int ground = 0;
|
|
int air = 0;
|
|
for (auto u : this->units)
|
|
{
|
|
ground += u.unitType.groundWeapon().damageAmount();
|
|
air += u.unitType.airWeapon().damageAmount();
|
|
}
|
|
this->groundDamage = ground;
|
|
this->airDamage = air;
|
|
}
|
|
|
|
bool Squad::contains(CUnit unit)
|
|
{
|
|
for (size_t i = 0; i < this->units.size(); i++)
|
|
{
|
|
if (this->units.at(i).unit->getID() == unit.unit->getID()) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool Squad::containsType(UnitType ut)
|
|
{
|
|
for (size_t i = 0; i < this->units.size(); i++)
|
|
{
|
|
if (this->units.at(i).unit->getType() == ut) return true;
|
|
}
|
|
|
|
return false;
|
|
} |