Skip to content
Snippets Groups Projects
UnitInformation.cpp 2 KiB
Newer Older
Rojikku98's avatar
Rojikku98 committed
#include "UnitInformation.h"



UnitInformation::UnitInformation(const sc2::Unit * unit, IDAReplayObserver & replayObserver)
	: m_replayObserver(&replayObserver), Unit(unit)
{
	
}

Rojikku98's avatar
Rojikku98 committed
 std::string UnitInformation::getType() const
{
	 return m_unit->unit_type.to_string();
		
}

 std::string UnitInformation::getTypeName() const
 {
	 return sc2::UnitTypeToName(m_unit->unit_type);
 }

Rojikku98's avatar
Rojikku98 committed
bool UnitInformation::hasTarget() const
{
	BOT_ASSERT(isValid(), "Unit is not valid");
	std::cout << "HAS TARGET" << std::endl;
Rojikku98's avatar
Rojikku98 committed
	if (getUnitPtr()->orders.size() > 0) {
		if (getUnitPtr()->orders[0].target_unit_tag != NULL) {
			CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
			//The tag is for somereason a null tag
			if (t_id == sc2::NullTag) {
				return false;
			}
			std::cout << "1MID HAS TARGET" << std::endl;
			std::cout << "2MID HAS TARGET" << std::endl;
			std::cout << "valid" << m_replayObserver->GetUnit(t_id).getType() << std::endl;
			std::cout << "AFTER" << std::endl;
Rojikku98's avatar
Rojikku98 committed
			// IDABot finds the unit with this tag, and returns true if valid
			return m_replayObserver->GetUnit(t_id).isValid();
		}
	}
	std::cout << "END HAS TARGET" << std::endl;
Rojikku98's avatar
Rojikku98 committed

	return false;
}

UnitInformation UnitInformation::getTarget() const
{
	BOT_ASSERT(isValid(), "Unit is not valid");

Rojikku98's avatar
Rojikku98 committed
	// if unit has order, check tag of target of first order
	if (getUnitPtr()->orders.size() > 0) {
		// t_id is set to the unit tag of the target
		CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
		//The tag is for somereason a null tag
		if (t_id == sc2::NullTag) {
			
			std::cout << "nullTAG" << std::endl;
			std::cout << "type " << sc2::UnitTypeToName(m_unit->unit_type) <<"pos " << getPosition().x << " x y "<< getPosition().y << ", id " << getID() << "player " << getPlayer() << std::endl;
			std::cout << getUnitPtr()->orders.size() << std::endl;
Rojikku98's avatar
Rojikku98 committed
			return *this;
		}
		// IDAReplayObserver finds the unit with this tag
		return m_replayObserver->GetUnit(t_id);
	}

	UnitInformation this_unit = UnitInformation(m_unit, *m_replayObserver);
	return this_unit;
}

Rojikku98's avatar
Rojikku98 committed