#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 = "";
	this->isScout = false;
	this->lastSeen = TilePosition(0, 0);
	this->miningBase = -1;
	this->squadIndex = -1;
	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;
}

bool CUnit::isMining()
{
	return (this->action == "minerals" || this->action == "gas");
}

void CUnit::mine(std::string action, int baseIndex)
{
	this->action = action;
	this->miningBase = baseIndex;
}

void CUnit::unsetTargetUnit()
{
	int queueIndex = Util::getQueueIndex(this->targetUnit);
	if(queueIndex > -1)
		Macro::queue.at(queueIndex).inProgress = 0;
	this->targetUnit = UnitTypes::None;
}