From 5d2f6047039c9015c6d9cad6c1e84345a1362403 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Sun, 17 Mar 2013 13:49:25 +0000
Subject: [PATCH] [Add] ai.cargofree() to lua API.

---
 scripts/ai/API | 3 +++
 src/ai.c       | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/scripts/ai/API b/scripts/ai/API
index 8dbc70e..e4ae57c 100644
--- a/scripts/ai/API
+++ b/scripts/ai/API
@@ -67,6 +67,9 @@ pshield()
   -- Returns the percentage of shield remaining.
     -- pilot - Optional pilot id, if not the current pilot is used.
 
+cargofree()
+	-- Return amount of free space the pilot has.
+
 // ================
 // BOOLEAN!
 // ================
diff --git a/src/ai.c b/src/ai.c
index a013c82..ab0b4f1 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -107,6 +107,7 @@ static int ai_pshield(lua_State* L);            // pshield()
 static int ai_getdistance(lua_State* L);        // Number getdist(Vec2)
 static int ai_getpos(lua_State* L);             // getpos(number)
 static int ai_minbrakedist(lua_State* L);       // Number minbrakedist()
+static int ai_cargofree(lua_State* L);					// Number cargofree().
 // Boolean expressions.
 static int ai_exists(lua_State* L);             // boolean exists
 static int ai_ismaxvel(lua_State* L);           // Boolean ismaxvel()
@@ -166,6 +167,7 @@ static const luaL_Reg ai_methods[] = {
 	{ "dist",									ai_getdistance			},
 	{ "pos",									ai_getpos						},
 	{ "minbrakedist",					ai_minbrakedist			},
+	{ "cargofree",						ai_cargofree				},
 	{ "nearestplanet",				ai_getnearestplanet	},
 	{ "rndplanet",						ai_getrndplanet			},
 	// Movement.
@@ -566,6 +568,11 @@ static int ai_minbrakedist(lua_State* L) {
   return 1;
 }
 
+static int ai_cargofree(lua_State* L) {
+	lua_pushnumber(L, cur_pilot->cargo_free);
+	return 1;
+}
+
 static int ai_exists(lua_State* L) {
   MIN_ARGS(1);