[Fix] space.getSystem().

This commit is contained in:
Allanis 2013-08-26 14:56:28 +01:00
parent 800ac52895
commit 4fa786ce21
4 changed files with 28 additions and 17 deletions

View File

@ -33,7 +33,7 @@
<mission name="Empire Shipping"> <mission name="Empire Shipping">
<lua>es_cargo</lua> <lua>es_cargo</lua>
<avail> <avail>
<cond>var.peek("es_cargo") == true</cond> <cond>player.getFaction("Empire") &gt;=0 and var.peek("es_cargo") == true</cond>
<chance>350</chance> <chance>350</chance>
<location>Computer</location> <location>Computer</location>
<faction>Empire</faction> <faction>Empire</faction>

View File

@ -62,7 +62,7 @@ function create()
misn_time = time.get() + time.units(5) + misn_time = time.get() + time.units(5) +
rnd.int(time.units(5), time.units(8)) * misn_dist rnd.int(time.units(5), time.units(8)) * misn_dist
misn.setDesc(string.format( misn_desc, carg_mass, carg_type, 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()))) time.str(misn_time), time.str(misn_time-time.get())))
reward = misn_dist * carg_mass * (500+rnd.int(250)) + reward = misn_dist * carg_mass * (500+rnd.int(250)) +
carg_mass * (250+rnd.int(150)) + carg_mass * (250+rnd.int(150)) +

View File

@ -297,15 +297,20 @@ int lua_issystem(lua_State* L, int ind) {
static int systemL_get(lua_State* L) { static int systemL_get(lua_State* L) {
LLUA_MIN_ARGS(1); LLUA_MIN_ARGS(1);
LuaSystem sys; LuaSystem sys;
char* planetname, *sysname; LuaPlanet* p;
if(lua_isstring(L, 1)) planetname = (char*)lua_tostring(L, 1); /* Passing a string (systemname) */
else if(lua_isuserdata(L, 1)) {} 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(); else LLUA_INVALID_PARAMETER();
/* Return the system. */ /* Return the system. */
sysname = planet_getSystem(planetname);
sys.s = system_get(sysname);
lua_pushsystem(L, sys); lua_pushsystem(L, sys);
return 1; return 1;
} }

View File

@ -7,6 +7,7 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "llua.h" #include "llua.h"
#include "llua_space.h"
#include "lluadef.h" #include "lluadef.h"
#include "hook.h" #include "hook.h"
#include "mission.h" #include "mission.h"
@ -386,18 +387,23 @@ static int misn_setReward(lua_State* L) {
} }
static int misn_setMarker(lua_State* L) { static int misn_setMarker(lua_State* L) {
if(lua_isstring(L, 1)) { LuaSystem* sys;
if(cur_mission->sys_marker != NULL) /* Cleanup old markers. */
/* No parameter clears the marker. */
if(lua_gettop(L)==0) {
if(cur_mission->sys_marker != NULL)
free(cur_mission->sys_marker); free(cur_mission->sys_marker);
cur_mission->sys_marker = strdup((char*)lua_tostring(L, 1)); mission_sysMark(); /* Clear the marker. */
#ifdef DEBUG
if(system_get(cur_mission->sys_marker)==NULL)
LLUA_DEBUG("Marking unexistant system '%s'", cur_mission->sys_marker);
#endif
mission_sysMark();
} }
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; return 0;
} }