void Donzo::AI(ACTORid enemy, EnemyTeam **team, int teamCount) { if(HP > 0) { detectEnemy(enemy); if(!attackAgent(enemy)) walkingAgent(enemy, team, teamCount); } }
void AI::path(Unit& unit){ float rad = unit.getR(); float theta = unit.getTheta(); float speed = unit.getSpeed(); float range = unit.getRange(); if(unit.attacking()) attack(unit); if(unit.pursuing()){ Unit *pursuing = unit.getPursuing(); CIwFVec2 pursuingPos = pursuing->getPosition(); CIwFVec2 pursuitVector = pursuingPos - unit.getPosition(); CIwSVec2 tempPos; if (pursuitVector.GetLength()<range) attack(unit); tempPos = (pursuitVector/speed)+unit.getPosition(); unit.setVelocity(tempPos-unit.getPosition()); std::list<Unit*> *tempArray = collisionDetection(unit, unit.getGame()->getUnits()); if (tempArray == NULL || !tempArray->empty()) unit.setVelocity(CIwFVec2::g_Zero); delete tempArray; } else { Unit *Enemy = detectEnemy(unit, unit.getGame()->getUnits()); float thetaChange = speed/rad; float tempTheta = thetaChange + theta; unit.setRTheta(rad, tempTheta); CIwFVec2 tempPos = unit.getPosition(); unit.setRTheta(rad, theta); unit.setVelocity(tempPos-unit.getPosition()); std::list<Unit*> *tempArray = collisionDetection(unit, unit.getGame()->getUnits()); if (tempArray == NULL || !tempArray->empty()) { unit.setVelocity(CIwFVec2::g_Zero); } delete tempArray; } }