[Add] New hard to kill ai who's primary objective is to survive.
This commit is contained in:
		
							parent
							
								
									a580cdeed3
								
							
						
					
					
						commit
						9dfd83abef
					
				
							
								
								
									
										90
									
								
								scripts/ai/scout.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								scripts/ai/scout.lua
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,90 @@
 | 
			
		||||
include("ai/include/basic.lua")
 | 
			
		||||
 | 
			
		||||
-- Some vars.
 | 
			
		||||
planet_dist = 1000  -- Distance to keep from planets.
 | 
			
		||||
enemy_dist  = 700   -- Distance to keep from enemies.
 | 
			
		||||
 | 
			
		||||
-- Required control rate.
 | 
			
		||||
control_rate = 2
 | 
			
		||||
-- Required "control" function.
 | 
			
		||||
function control()
 | 
			
		||||
  task = ai.taskname()
 | 
			
		||||
 | 
			
		||||
  if task == "none" or task == "idle" then
 | 
			
		||||
    enemy = ai.getenemy()
 | 
			
		||||
 | 
			
		||||
    -- There is an enemy.
 | 
			
		||||
    if enemy ~= 0 then
 | 
			
		||||
      -- Make hostile to the enemy (mainly for player).
 | 
			
		||||
      if ai.dist(enemy) < enemy_dist then
 | 
			
		||||
        ai.pushtask(0, "runaway", enemy)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      -- No enemy.
 | 
			
		||||
    else
 | 
			
		||||
      -- Nothing to do so check if we are too far from the planet.
 | 
			
		||||
      -- (If there is one).
 | 
			
		||||
      planet = ai.rndplanet()
 | 
			
		||||
 | 
			
		||||
      if planet ~= nil then
 | 
			
		||||
        if ai.dist(planet) > planet_dist then
 | 
			
		||||
          ai.pushtask(0, "approach", planet)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- Go idle if no task.
 | 
			
		||||
    if task == "none" then
 | 
			
		||||
      ai.pushtask(0, "idle")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- Check if we are near enough.
 | 
			
		||||
  elseif task == "approach" then
 | 
			
		||||
    planet = ai.target()
 | 
			
		||||
 | 
			
		||||
    if ai.dist(planet) < planet_dist then
 | 
			
		||||
      ai.poptask()
 | 
			
		||||
      ai.pushtask(0, "idle")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- Check if we need to run more.
 | 
			
		||||
  elseif task == "runaway" then
 | 
			
		||||
    enemy = ai.targetid()
 | 
			
		||||
 | 
			
		||||
    if ai.dist(enemy) > enemy_dist then
 | 
			
		||||
      ai.poptask()
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Required "attacked" function.
 | 
			
		||||
function attacked(attaker)
 | 
			
		||||
  task = ai.taskname()
 | 
			
		||||
  if task ~= "runaway" then
 | 
			
		||||
    ai.pushtask(0, "runaway", attacker)
 | 
			
		||||
  elseif task == "runaway" then
 | 
			
		||||
    if ai.targetid() ~= attacker then
 | 
			
		||||
      ai.pushtask(0, "runaway", attacker)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Required "create" function.
 | 
			
		||||
function create() 
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Effectively does nothing.
 | 
			
		||||
function idle()
 | 
			
		||||
  if ai.isstopped() == false then
 | 
			
		||||
    ai.brake()
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Approaches the target.
 | 
			
		||||
function approach()
 | 
			
		||||
  target = ai.target()
 | 
			
		||||
  dir = ai.face(target)
 | 
			
		||||
  ai.accel()
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user