[Add] space.faction to get the faction of a star system.

This commit is contained in:
Allanis 2013-07-27 18:02:14 +01:00
parent 10ea68c5c3
commit 9c6567195c

View File

@ -29,12 +29,14 @@ static int space_getSystem(lua_State* L);
static int space_landName(lua_State* L); static int space_landName(lua_State* L);
static int space_systemName(lua_State* L); static int space_systemName(lua_State* L);
static int space_jumpDist(lua_State* L); static int space_jumpDist(lua_State* L);
static int space_faction(lua_State* L);
static const luaL_reg space_methods[] = { static const luaL_reg space_methods[] = {
{ "getPlanet", space_getPlanet }, { "getPlanet", space_getPlanet },
{ "getSystem", space_getSystem }, { "getSystem", space_getSystem },
{ "landName", space_landName }, { "landName", space_landName },
{ "system", space_systemName }, { "system", space_systemName },
{ "jumpDist", space_jumpDist }, { "jumpDist", space_jumpDist },
{ "spaceFaction", space_faction },
{ 0, 0 } { 0, 0 }
}; };
@ -288,6 +290,31 @@ static int space_jumpDist(lua_State* L) {
return 1; return 1;
} }
static int space_faction(lua_State* L) {
int i;
StarSystem* s;
/* Get the system. */
if(lua_isstring(L, 2))
s = system_get(lua_tostring(L, 1));
else s = cur_system;
/* Check if valid. */
if(s == NULL) {
LLUA_DEBUG("Invalid system!");
return 0;
}
/* Return the result in table. */
lua_newtable(L);
for(i = 0; i < s->nplanets; i++) {
lua_pushnumber(L, i+1); /* Index. */
lua_pushstring(L, faction_name(s->planets[i].faction)); /* Value. */
lua_rawset(L, -3); /* Store in table. */
}
return 1;
}
/* -- Time. -- */ /* -- Time. -- */
static int time_get(lua_State* L) { static int time_get(lua_State* L) {
lua_pushnumber(L, ltime_get()); lua_pushnumber(L, ltime_get());