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



Rojikku98's avatar
Rojikku98 committed
ReplayUnit::ReplayUnit(const sc2::Unit * unit, IDAReplayObserver & replayObserver)
Rojikku98's avatar
Rojikku98 committed
	: m_replayObserver(&replayObserver), Unit(unit)
{
	
}

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

Rojikku98's avatar
Rojikku98 committed
 std::string ReplayUnit::getTypeName() const
 {
	 return sc2::UnitTypeToName(m_unit->unit_type);
 }

Rojikku98's avatar
Rojikku98 committed
bool ReplayUnit::hasTarget() const
Rojikku98's avatar
Rojikku98 committed
{
	BOT_ASSERT(isValid(), "Unit is not valid");
	if (getUnitPtr()->orders.size() > 0) {
		if (getUnitPtr()->orders[0].target_unit_tag != NULL) {
			CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
Edvin Bergström's avatar
Edvin Bergström committed
			// IDAReplayObserver checks if the unit with this tag still exists
			if (m_replayObserver->UnitExists(t_id)){
				// IDAReplayObserver finds the unit with this tag, and returns true if valid
				return m_replayObserver->GetUnit(t_id).isValid();
Rojikku98's avatar
Rojikku98 committed
ReplayUnit ReplayUnit::getTarget() const
Rojikku98's avatar
Rojikku98 committed
{
	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;
Edvin Bergström's avatar
Edvin Bergström committed
		// Checks if the tag is a null tag or the unit have been removed
		if (t_id != sc2::NullTag && m_replayObserver->UnitExists(t_id)){
			// IDAReplayObserver finds the unit with this tag
			return m_replayObserver->GetUnit(t_id);
Rojikku98's avatar
Rojikku98 committed
	ReplayUnit this_unit = ReplayUnit(m_unit, *m_replayObserver);
Rojikku98's avatar
Rojikku98 committed
	return this_unit;
}

Rojikku98's avatar
Rojikku98 committed