2023-04-10 23:31:02 +00:00
|
|
|
#include "CUnit.h"
|
|
|
|
|
|
|
|
CUnit::CUnit()
|
|
|
|
{
|
|
|
|
this->initialize();
|
|
|
|
this->id = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CUnit::CUnit(BWAPI::Unit unit)
|
|
|
|
{
|
|
|
|
this->initialize();
|
|
|
|
this->id = unit->getID();
|
|
|
|
this->tilePosition = unit->getTilePosition();
|
|
|
|
this->unit = unit;
|
|
|
|
this->unitType = unit->getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CUnit::initialize()
|
|
|
|
{
|
|
|
|
this->action = "";
|
2023-04-11 17:56:09 +00:00
|
|
|
this->isScout = false;
|
2023-04-10 23:31:02 +00:00
|
|
|
this->lastSeen = TilePosition(0, 0);
|
|
|
|
this->miningBase = -1;
|
2023-04-12 04:30:14 +00:00
|
|
|
this->squadIndex = -1;
|
2023-04-10 23:31:02 +00:00
|
|
|
this->target = TilePosition(-1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CUnit::isIdle()
|
|
|
|
{
|
|
|
|
bool status = false;
|
|
|
|
if (this->unit->getOrder() == Orders::PlayerGuard
|
|
|
|
&& this->action != "expand"
|
|
|
|
&& this->action != "build"
|
|
|
|
&& this->action != "minerals")
|
|
|
|
status = true;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CUnit::isInSquad()
|
|
|
|
{
|
|
|
|
for (auto s : Macro::squads)
|
|
|
|
{
|
|
|
|
if (s.contains(this->unit)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-04-11 17:56:09 +00:00
|
|
|
bool CUnit::isMining()
|
|
|
|
{
|
|
|
|
return (this->action == "minerals" || this->action == "gas");
|
|
|
|
}
|
|
|
|
|
2023-04-10 23:31:02 +00:00
|
|
|
void CUnit::mine(std::string action, int baseIndex)
|
|
|
|
{
|
|
|
|
this->action = action;
|
|
|
|
this->miningBase = baseIndex;
|
2023-04-12 04:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CUnit::unsetTargetUnit()
|
|
|
|
{
|
2023-04-13 17:49:07 +00:00
|
|
|
int queueIndex = Util::getQueueIndex(this->targetUnit);
|
|
|
|
if(queueIndex > -1)
|
|
|
|
Macro::queue.at(queueIndex).inProgress = 0;
|
2023-04-12 04:30:14 +00:00
|
|
|
this->targetUnit = UnitTypes::None;
|
2023-04-10 23:31:02 +00:00
|
|
|
}
|