diff --git a/dat/mission.xml b/dat/mission.xml
index 8cfc638..dcdec0a 100644
--- a/dat/mission.xml
+++ b/dat/mission.xml
@@ -149,4 +149,12 @@
Goddard
+ +
+ dvaered/dv_patrol
+
+ 366
+ Computer
+ Dvaered
+
+
diff --git a/dat/missions/dvaered/dv_patrol.lua b/dat/missions/dvaered/dv_patrol.lua
new file mode 100644
index 0000000..20a9944
--- /dev/null
+++ b/dat/missions/dvaered/dv_patrol.lua
@@ -0,0 +1,120 @@
+--[[
+-- Handles random Dvaered Patrol missions.
+--]]
+
+lang = lephisto.lang()
+if lang == "es" then
+ -- Not translated atm.
+else -- Default English.
+ misn_desc = {}
+ misn_desc[1] = "Patrol %d systems for hostiles: "
+ misn_desc[2] = "Travel to the %s system and check for hostiles."
+ misn_desc[3] = "Return to %s in the %s system for payment."
+ misn_reward = "%d credits"
+ title = {}
+ title[1] = "DV: Routine %d sector patrol"
+ title[2] = "DV: Patrol %d sectors"
+ title[3] = "DV: Scan of %d sectors"
+ accpet_title = "Mission Accepted"
+ msg_title = {}
+ msg_msg = {}
+ msg_title[1] = "Mission Success"
+ msg_msg[1] = "You are greeted by a Dvaered official and recieve your payment of %d credits for your contribution in keeping Dvaered systems clean."
+end
+
+-- Create the mission.
+function create()
+ -- Get systems to patrol.
+ num_systems = rnd.int(2, 4)
+ systems = {}
+ s = space.getSystem():adjacentSystems()
+ systems[1] = s[rnd.int(1, #s)]
+ for i = 2, num_systems do
+ s = systems[i-1]:adjacentSystems()
+ systems[i] = s[rnd.int(1, #s)]
+ end
+ system1, system2, system3, system4 = unpack(systems)
+ base, base_sys = space_getPlanet()
+ misn_setMarker(systems[1])
+
+ -- Create the description.
+ desc = string.format(misn_desc[1], num_systems) .. systems[1]:name()
+ for i = 2, num_systems-1 do
+ desc = desc ..", " .. systems[i]:name()
+ end
+ desc = desc .. " and " .. systems[num_systems]:name() .. "."
+
+ -- Set mission stage.
+ misn_stage = 1
+ visited = 0
+
+ -- Calculate reward.
+ reward = 10000
+ for i = 1, num_systems do
+ reward = reward + 15000 + 5000 * rnd.twosigma()
+ end
+
+ -- Set some details.
+ misn.setTitle(string.format(title[rnd.int(1, 3)], num_systems))
+ misn.setDesc(desc)
+ misn_setReward(string.format(misn_reward, reward))
+end
+
+-- Mission is accepted.
+function accept()
+ if misn.accept() then
+
+ -- Update the description.
+ misn.setDesc(string.format(misn_desc[2], systems[1]:name()))
+
+ -- Set the hooks.
+ hook.land("land")
+ hook.enter("jump")
+ end
+end
+
+-- Jump hook.
+function jump()
+ if misn_stage == 1 then
+ sys = space.getSystem()
+
+ -- Hack in case it wasn't saved.
+ if systems == nil then
+ systems = { system1, system2, system3, system4 }
+ end
+
+ -- Check to see if system is next.
+ if sys == systems[visited+1] then
+ visited = visited + 1
+
+ -- Finished visiting systems.
+ if visited >= #systems then
+ misn_stage = 2
+ misn.setDesc(string.format(misn_desc[3], base:name(), base_sys:name()))
+ misn.setMarker(base_sys)
+
+ -- Need to visit more systems.
+ else
+ misn.setDesc(string.format(misn_desc[2], systems[visited+1]:name()))
+ misn.setMarker(systems[visited+1])
+ end
+ end
+ end
+end
+
+-- land hook.
+function land()
+ landed = space.getPlanet()
+ if misn_stage == 2 and landed == base then
+ player.pay(reward)
+ tk.msg(msg_title[1], string.format(msg_msg[1], reward))
+
+ -- Modify the faction standing.
+ if player.getFaction("Dvaered") < 70 then
+ player.modFaction("Dvaered", rnd.rnd(1, num_systems/2));
+ end
+
+ misn.finish(true)
+ end
+end
+
diff --git a/src/llua.c b/src/llua.c
index b9d9e17..652dc68 100644
--- a/src/llua.c
+++ b/src/llua.c
@@ -48,8 +48,15 @@ static const luaL_reg time_methods[] = {
/* RND. */
static int rnd_int(lua_State*L);
+static int rnd_sigma(lua_State* L);
+static int rnd_twosigma(lua_State* L);
+static int rnd_threesigma(lua_State* L);
static const luaL_reg rnd_methods[] = {
- { "int", rnd_int },
+ { "int", rnd_int }, /* Obsolete, rnd.rnd is prefered. */
+ { "rnd", rnd_int },
+ { "sigma", rnd_sigma },
+ { "twosigma", rnd_twosigma },
+ { "threesigma", rnd_threesigma },
{ 0, 0 }
};
@@ -244,8 +251,41 @@ static int rnd_int(lua_State* L) {
return 1;
}
-/* -- Toolkit. -- */
+static int rnd_sigma(lua_State* L) {
+ lua_pushnumber(L, RNG_1SIGMA());
+ return 1;
+}
+static int rnd_twosigma(lua_State* L) {
+ lua_pushnumber(L, RNG_2SIGMA());
+ return 1;
+}
+
+static int rnd_threesigma(lua_State* L) {
+ lua_pushnumber(L, RNG_3SIGMA());
+ return 1;
+}
+
+/**
+ * @defgroup TOOLKIT Toolkit Lua Bindings.
+ *
+ * @brief Bindings for interacting with the toolkit.
+ *
+ * Functions should be called like:
+ *
+ * @code
+ * tk.function(parameters)
+ * @endcode
+ *
+ * @{
+ */
+/**
+ * @brief msg(string title, string message)
+ *
+ * Creates a window with an ok button.
+ * @param title Title of the window.
+ * @param message Message to display in the window.
+ */
static int tk_msg(lua_State* L) {
char* title, *str;
LLUA_MIN_ARGS(2);
diff --git a/src/llua_space.c b/src/llua_space.c
index 8d2c114..936328b 100644
--- a/src/llua_space.c
+++ b/src/llua_space.c
@@ -47,13 +47,15 @@ static int systemL_name(lua_State* L);
static int systemL_faction(lua_State* L);
static int systemL_nebulae(lua_State* L);
static int systemL_jumpdistance(lua_State* L);
+static int systemL_adjacent(lua_State* L);
static const luaL_reg system_methods[] = {
- { "__eq", systemL_eq },
- { "__tostring", systemL_name },
- { "name", systemL_name },
- { "faction", systemL_faction },
- { "nebulae", systemL_nebulae },
- { "jumpDist", systemL_jumpdistance },
+ { "__eq", systemL_eq },
+ { "__tostring", systemL_name },
+ { "name", systemL_name },
+ { "faction", systemL_faction },
+ { "nebulae", systemL_nebulae },
+ { "jumpDist", systemL_jumpdistance },
+ { "adjacentSystems", systemL_adjacent },
{ 0, 0 }
};
@@ -671,6 +673,27 @@ static int systemL_jumpdistance(lua_State* L) {
return 1;
}
+/**
+ * @ingroup META_SYSTEM
+ */
+static int systemL_adjacent(lua_State* L) {
+ int i;
+ LuaSystem* sys, sysp;
+
+ sys = lua_tosystem(L, 1);
+
+ /* Push all adjacent systems. */
+ lua_newtable(L);
+ for(i = 0; i < sys->s->njumps; i++) {
+ sysp.s = system_getIndex(sys->s->jumps[i]);
+ lua_pushnumber(L, i+1); /* Key. */
+ lua_pushsystem(L, sysp); /* Value. */
+ lua_rawset(L, -3);
+ }
+
+ return 1;
+}
+
/**
* @defgroup META_VECTOR Vector Metatable
*