From 01243e12e31a78b583633d76feb9c9d33071864e Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Tue, 26 Nov 2013 15:07:41 +0000
Subject: [PATCH] [Add] Lua logic for traders.

---
 dat/fleet.xml         |  2 +-
 scripts/ai/trader.lua | 30 ++++++++++++++++++++++++++++++
 src/explosion.c       |  2 +-
 3 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 scripts/ai/trader.lua

diff --git a/dat/fleet.xml b/dat/fleet.xml
index c53636f..26e8fa8 100644
--- a/dat/fleet.xml
+++ b/dat/fleet.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Fleets>
  <fleet name="Goddard Goddard">
-  <ai>militia</ai>
+  <ai>goddard</ai>
   <faction>Goddard</faction>
   <pilots>
    <pilot chance="100">Goddard</pilot>
diff --git a/scripts/ai/trader.lua b/scripts/ai/trader.lua
new file mode 100644
index 0000000..db7f7a1
--- /dev/null
+++ b/scripts/ai/trader.lua
@@ -0,0 +1,30 @@
+include("../scripts/ai/merchant.lua")
+
+function sos()
+  msg = {
+    "Mayday! We are under attack!",
+    "Requesting assistance. We are under attack!",
+    "Merchant vessle here under attack! HELP!"
+  }
+  ai.broadcast(msg[rnd.int(1, #msg)])
+end
+
+function create()
+  ai.setcredits(rnd.int(100, ai.shipprice()/50))
+
+  -- Some stuff has more than others.
+  num = rnd.int(12)
+  if num < 5 then
+    cargo = "Food"
+  elseif num < 8 then
+    cargo = "Ore"
+  elseif num < 10 then
+    cargo = "Industrial Goods"
+  elseif num < 12 then
+    cargo = "Luxury Goods"
+  else
+    cargo = "Medicine"
+  end
+  ai.setcargo(cargo, rnd.int(0, ai.cargofree()))
+end
+
diff --git a/src/explosion.c b/src/explosion.c
index d4050fa..978628a 100644
--- a/src/explosion.c
+++ b/src/explosion.c
@@ -31,7 +31,7 @@ void expl_explode(double x, double y, double vx, double vy,
   /* Standard stuff. */
   exp_s = spfx_get("ExpS");
   exp_m = spfx_get("ExpM");
-  exp_s = spfx_get("ExpL");
+  exp_l = spfx_get("ExpL");
   layer = SPFX_LAYER_FRONT;
 
   /* Number of explosions. */