void CAttackTask::Execute(CCircuitUnit* unit, bool isUpdating) { Unit* u = unit->GetUnit(); CCircuitAI* circuit = manager->GetCircuit(); CTerrainManager* terrainManager = circuit->GetTerrainManager(); float minSqDist; CEnemyUnit* bestTarget = FindBestTarget(unit, minSqDist); if (bestTarget == nullptr) { if (!isUpdating) { float x = rand() % (terrainManager->GetTerrainWidth() + 1); float z = rand() % (terrainManager->GetTerrainHeight() + 1); position = AIFloat3(x, circuit->GetMap()->GetElevationAt(x, z), z); } } else { position = bestTarget->GetPos(); float range = u->GetMaxRange(); if (minSqDist < range * range) { u->Attack(bestTarget->GetUnit(), UNIT_COMMAND_OPTION_INTERNAL_ORDER, circuit->GetLastFrame() + FRAMES_PER_SEC * 300); return; } } u->Fight(position, UNIT_COMMAND_OPTION_INTERNAL_ORDER, circuit->GetLastFrame() + FRAMES_PER_SEC * 300); }
void CArtilleryTask::Execute(CCircuitUnit* unit, bool isUpdating) { IUnitAction* act = static_cast<IUnitAction*>(unit->End()); if (!act->IsAny(IUnitAction::Mask::MOVE | IUnitAction::Mask::FIGHT | IUnitAction::Mask::JUMP)) { return; } ITravelAction* travelAction = static_cast<ITravelAction*>(act); CCircuitAI* circuit = manager->GetCircuit(); int frame = circuit->GetLastFrame(); const AIFloat3& pos = unit->GetPos(frame); std::shared_ptr<F3Vec> pPath = std::make_shared<F3Vec>(); CEnemyUnit* bestTarget = FindTarget(unit, pos, *pPath); if (bestTarget != nullptr) { TRY_UNIT(circuit, unit, unit->GetUnit()->Attack(bestTarget->GetUnit(), UNIT_COMMAND_OPTION_RIGHT_MOUSE_KEY, frame + FRAMES_PER_SEC * 60); unit->GetUnit()->ExecuteCustomCommand(CMD_UNIT_SET_TARGET, {(float)bestTarget->GetId()}); )