void UnitClass::useTech(BWAPI::TechType tech, Unit target) { if(exists() && target) { if(!target->exists()) { move(target->getPosition()); return; } if(mUnit->getOrder() == tech.getOrder()) { if(mUnit->getOrderTarget() == target->mUnit) return; } if(mUnit->getLastCommand().getType() == BWAPI::UnitCommandTypes::Use_Tech_Unit && mUnit->getLastCommand().getTechType() == tech && mUnit->getLastCommand().getTarget() == target->mUnit) { if(mLastOrderExecuteTime >= BWAPI::Broodwar->getFrameCount()) return; } if(mUnit->useTech(tech, target->mUnit)) mLastOrderExecuteTime = BWAPI::Broodwar->getFrameCount() + BWAPI::Broodwar->getRemainingLatencyFrames(); } }
bool UnitWrap::UseTech(BWAPI::TechType tech, Unit pTarget, int targBit) { if ( !pTarget ) return false; if ( pUnit->getOrder() == tech.getOrder() && pUnit->getTarget() == pTarget ) // Already targetting it return false; int targFlags = UnitWrap(pTarget).GetTargetFlags(); if ( targFlags & targBit ) return false; if ( pUnit->useTech(tech, pTarget) ) // Use the tech! { UnitWrap(pTarget).SetTargetFlags(targFlags | targBit); SetVirtualUnitOrder( (Orders::Enum::Enum)tech.getOrder().getID() ); return true; } return false; // If the tech failed }