From 4fa786ce213bb59ad4b02803e32f7446217edd3e Mon Sep 17 00:00:00 2001 From: Allanis Date: Mon, 26 Aug 2013 14:56:28 +0100 Subject: [PATCH] [Fix] space.getSystem(). --- dat/mission.xml | 2 +- dat/missions/es_cargo.lua | 2 +- src/llua_space.c | 15 ++++++++++----- src/misn_lua.c | 26 ++++++++++++++++---------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/dat/mission.xml b/dat/mission.xml index d9ac6fc..dd6ee66 100644 --- a/dat/mission.xml +++ b/dat/mission.xml @@ -33,7 +33,7 @@ es_cargo - var.peek("es_cargo") == true + player.getFaction("Empire") >=0 and var.peek("es_cargo") == true 350 Computer Empire diff --git a/dat/missions/es_cargo.lua b/dat/missions/es_cargo.lua index eb264a6..4934d0c 100644 --- a/dat/missions/es_cargo.lua +++ b/dat/missions/es_cargo.lua @@ -62,7 +62,7 @@ function create() misn_time = time.get() + time.units(5) + rnd.int(time.units(5), time.units(8)) * misn_dist misn.setDesc(string.format( misn_desc, carg_mass, carg_type, - planet:name(),, system:name(), + planet:name(), system:name(), time.str(misn_time), time.str(misn_time-time.get()))) reward = misn_dist * carg_mass * (500+rnd.int(250)) + carg_mass * (250+rnd.int(150)) + diff --git a/src/llua_space.c b/src/llua_space.c index cf06c47..e0a4471 100644 --- a/src/llua_space.c +++ b/src/llua_space.c @@ -297,15 +297,20 @@ int lua_issystem(lua_State* L, int ind) { static int systemL_get(lua_State* L) { LLUA_MIN_ARGS(1); LuaSystem sys; - char* planetname, *sysname; + LuaPlanet* p; - if(lua_isstring(L, 1)) planetname = (char*)lua_tostring(L, 1); - else if(lua_isuserdata(L, 1)) {} + /* Passing a string (systemname) */ + if(lua_isstring(L, 1)) { + sys.s = system_get((char*)lua_tostring(L, 1)); + } + /* Passing a planet */ + else if(lua_isplanet(L, 1)) { + p = lua_toplanet(L, 1); + sys.s = system_get(planet_getSystem(p->p->name)); + } else LLUA_INVALID_PARAMETER(); /* Return the system. */ - sysname = planet_getSystem(planetname); - sys.s = system_get(sysname); lua_pushsystem(L, sys); return 1; } diff --git a/src/misn_lua.c b/src/misn_lua.c index ab3f58d..cd1fd7d 100644 --- a/src/misn_lua.c +++ b/src/misn_lua.c @@ -7,6 +7,7 @@ #include "lauxlib.h" #include "llua.h" +#include "llua_space.h" #include "lluadef.h" #include "hook.h" #include "mission.h" @@ -386,18 +387,23 @@ static int misn_setReward(lua_State* L) { } static int misn_setMarker(lua_State* L) { - if(lua_isstring(L, 1)) { - if(cur_mission->sys_marker != NULL) /* Cleanup old markers. */ + LuaSystem* sys; + + /* No parameter clears the marker. */ + if(lua_gettop(L)==0) { + if(cur_mission->sys_marker != NULL) free(cur_mission->sys_marker); - cur_mission->sys_marker = strdup((char*)lua_tostring(L, 1)); -#ifdef DEBUG - if(system_get(cur_mission->sys_marker)==NULL) - LLUA_DEBUG("Marking unexistant system '%s'", cur_mission->sys_marker); -#endif - mission_sysMark(); + mission_sysMark(); /* Clear the marker. */ } - else if(cur_mission->sys_marker != NULL) /* No parameter nullifies. */ - free(cur_mission->sys_marker); + + /* Passing in a Star System. */ + if(lua_issystem(L, 1)) { + sys = lua_tosystem(L, 1); + cur_mission->sys_marker = strdup(sys->s->name); + mission_sysMark(); /* Mark the system. */ + } + else LLUA_INVALID_PARAMETER(); + return 0; }