diff --git a/scripts/ai/empire.lua b/scripts/ai/empire.lua
index a0a41bf..90331be 100644
--- a/scripts/ai/empire.lua
+++ b/scripts/ai/empire.lua
@@ -84,10 +84,3 @@ function land()
  end
 end
 
-function hyperspace()
- dir = ai.face(-1) -- Face away from (0,0)
- if(dir < 10) then
-  ai.accel()
- end
-end
-
diff --git a/scripts/ai/include/basic.lua b/scripts/ai/include/basic.lua
index a98822a..a09704b 100644
--- a/scripts/ai/include/basic.lua
+++ b/scripts/ai/include/basic.lua
@@ -59,3 +59,20 @@ function runaway()
   end
 end
 
+--[[
+-- Start heading away to try to hyperspace.
+--
+-- Will need the following in control() to work:
+--
+-- task = ai.taskname()
+-- if task == "hyperspace" then
+--   ai.hyperspace() -- Try to hyperspace.
+-- end
+--]]
+function hyperspace()
+  dir = ai.facr(-1) -- Face away from (0,0).
+  if(dir < 10) then
+    ai.accel()
+  end
+end
+
diff --git a/scripts/ai/merchant.lua b/scripts/ai/merchant.lua
index 73fb294..7bceae5 100644
--- a/scripts/ai/merchant.lua
+++ b/scripts/ai/merchant.lua
@@ -94,11 +94,3 @@ function land()
   end
 end
 
--- Go to hyperspace YEAAAHHH!!
-function hyperspace()
- dir = ai.face(-1) -- Face away from (0,0)
- if(dir < 10) then 
-  ai.accel()
- end
-end
-
diff --git a/scripts/ai/pirate.lua b/scripts/ai/pirate.lua
index 04893df..35114c8 100644
--- a/scripts/ai/pirate.lua
+++ b/scripts/ai/pirate.lua
@@ -7,13 +7,22 @@ control_rate = 2
 function control()
   task = ai.taskname()
 
+  if task == "hyperspace" then
+    ai.hyperspace() -- Try to hyperspace.
+
   -- Running pilot has healed up some.
-  if task == "runaway" then
+  elseif task == "runaway" then
     if ai.parmour() == 100 then
       -- "attack" should be called after "runaway".
       ai.poptask()
   elseif ai.dist(ai.pos(ai.targetid())) > 300 then
    ai.hyperspace()
+  end
+
+  -- Hurt pilot wants to run away.
+  elseif task == "attack" then
+    if ai.parmour() < 80 then
+      ai.pushtask(0, "runaway", ai.targetid())
     end
 
     -- Nothing to do.
@@ -22,7 +31,7 @@ function control()
     enemy = ai.getenemy()
     if ai.parmour() == 100 and enemy ~= 0 then
       -- Taunts.
-      num = rnd.int(0,4)
+      num = rnd.int(0,5)
       if num == 0 then msg = "Prepare to be boarded!"
       elseif num == 1 then msg = "Whoa! Lookie what we found here!"
       elseif num == 2 then msg = "What's a ship like you doing in a place like this?"
@@ -37,7 +46,7 @@ function control()
       ai.pushtask(0, "attack", enemy) -- Begin the attack.
     -- Nothing to attack.
     else
-      ai.pushtask(0, "fly")
+      ai.pushtask(0, "hyperspace")
     end
   end
 end