/** * @brief You can use the '=' operator within Lua to compare planets with this. * * @usage if p.__eq( planet.get( "Anecu" ) ) then -- Do something * @usage if p == planet.get( "Anecu" ) then -- Do something * @luaparam p Planet comparing. * @luaparam comp planet to compare against. * @luareturn true if both planets are the same. * @luafunc __eq( p, comp ) */ static int planetL_eq( lua_State *L ) { LuaPlanet *a, *b; a = luaL_checkplanet(L,1); b = luaL_checkplanet(L,2); lua_pushboolean(L,(a->p == b->p)); return 1; }
/** * @brief Checks if a planet has shipyard services. * * @usage if p:hasShipyard() then -- Planet has shipyard service * @luaparam p Planet to get the services of. * @luareturn True f the planets has shipyard services. * @luafunc hasShipyard( p ) */ static int planetL_hasShipyard( lua_State *L ) { LuaPlanet *p; p = luaL_checkplanet(L,1); lua_pushboolean(L, (p->p->services & PLANET_SERVICE_SHIPYARD)); return 1; }
/** * @brief Checks if a planet has outfit services. * * @usage if p:hasOutfits() then -- Planet has outfit services * @luaparam p Planet to get the services of. * @luareturn True f the planets has outfitting services. * @luafunc hasOutfits( p ) */ static int planetL_hasOutfits( lua_State *L ) { LuaPlanet *p; p = luaL_checkplanet(L,1); lua_pushboolean(L, (p->p->services & PLANET_SERVICE_OUTFITS)); return 1; }
/** * @brief Checks if a planet has commodities exchange service. * * @usage if p:hasCommodities() then -- Planet has commodity exchange services * @luaparam p Planet to get the services of. * @luareturn True f the planets has commodity exchange service. * @luafunc hasCommodities( p ) */ static int planetL_hasCommodities( lua_State *L ) { LuaPlanet *p; p = luaL_checkplanet(L,1); lua_pushboolean(L, (p->p->services & PLANET_SERVICE_COMMODITY)); return 1; }
/** * @brief Checks if a planet has basic services (spaceport bar, mission computer). * * @usage if p:hasBasic() then -- Planet has basic service * @luaparam p Planet to get the services of. * @luareturn True f the planets has basic services. * @luafunc hasBasic( p ) */ static int planetL_hasBasic( lua_State *L ) { LuaPlanet *p; p = luaL_checkplanet(L,1); lua_pushboolean(L, (p->p->services & PLANET_SERVICE_BASIC)); return 1; }
/** * @brief Checks if a planet has services (any flag besides SERVICE_LAND). * * @usage if p:hasServices() then -- Planet has services * @luaparam p Planet to get the services of. * @luareturn True f the planets has services. * @luafunc hasServices( p ) */ static int planetL_hasServices( lua_State *L ) { LuaPlanet *p; p = luaL_checkplanet(L,1); lua_pushboolean(L, (p->p->services & (~PLANET_SERVICE_LAND))); return 1; }
/** * @brief Gets the planet's name. * * @usage name = p:name() * @luaparam p Planet to get the name of. * @luareturn The name of the planet. * @luafunc name( p ) */ static int planetL_name( lua_State *L ) { LuaPlanet *p; p = luaL_checkplanet(L,1); lua_pushstring(L,p->p->name); return 1; }
/** * @brief Gets the position of the planet in the system. * * @usage v = p:pos() * @luaparam p Planet to get the position of. * @luareturn The position of the planet in the system as a vec2. * @luafunc pos( p ) */ static int planetL_position( lua_State *L ) { LuaPlanet *p; LuaVector v; p = luaL_checkplanet(L,1); vectcpy(&v.vec, &p->p->pos); lua_pushvector(L, v); return 1; }
/** * @brief Gets the planet's class. * * Usually classes are characters for planets (see space.h) and numbers * for stations. * * @usage c = p:class() * @luaparam p Planet to get the class of. * @luareturn The class of the planet in a one char identifier. * @luafunc class( p ) */ static int planetL_class(lua_State *L ) { char buf[2]; LuaPlanet *p; p = luaL_checkplanet(L,1); buf[0] = planet_getClass(p->p); buf[1] = '\0'; lua_pushstring(L,buf); return 1; }
/** * @brief Gets the planet's faction. * * @usage f = p:faction() * @luaparam p Planet to get the faction of. * @luareturn The planet's faction. * @luafunc faction( p ) */ static int planetL_faction( lua_State *L ) { LuaPlanet *p; LuaFaction f; p = luaL_checkplanet(L,1); if (p->p->faction < 0) return 0; f.f = p->p->faction; lua_pushfaction(L, f); return 1; }
/** * @brief Gets a planet directly. * * @param L Lua state to get planet from. * @param ind Index position to find the planet. * @return Planet found at the index in the state. */ Planet* luaL_validplanet( lua_State *L, int ind ) { LuaPlanet *lp; Planet *p; lp = luaL_checkplanet( L, ind ); p = planet_getIndex( lp->id ); if (p == NULL) { NLUA_ERROR( L, "Planet is invalid" ); return NULL; } return p; }
/** * @brief Checks for planet services. * * Possible services are:<br /> * - "land"<br /> * - "inhabited"<br /> * - "refuel"<br /> * - "bar"<br /> * - "missions"<br /> * - "commodity"<br /> * - "outfits"<br /> * - "shipyard"<br /> * * @usage if #p:services() > 0 then -- Planet has services * @usage if p:serivces()["refuel"] then -- PLanet has refuel service. * #usage if p:services()["shipyard"] then -- Planet has shipyard service. * @luaparam p Planet to get the services of. * @luareturn Table containing all the services. * @luafunc services( p ) */ static int planetL_services( lua_State *L ) { LuaPlanet *lp; Planet *p; lp = luaL_checkplanet(L,1); p = lp->p; /* Return result in table */ lua_newtable(L); /* allows syntax foo = space.faction("foo"); if foo["bar"] then ... end */ if (planet_hasService(p, PLANET_SERVICE_LAND)) { lua_pushboolean(L,1); /* value */ lua_setfield(L,-2,"land"); /* key */ } if (planet_hasService(p, PLANET_SERVICE_INHABITED)) { lua_pushboolean(L,1); /* value */ lua_setfield(L,-2,"inhabited"); /* key */ } if (planet_hasService(p, PLANET_SERVICE_REFUEL)) { lua_pushboolean(L,1); /* value */ lua_setfield(L,-2,"refuel"); /* key */ } if (planet_hasService(p, PLANET_SERVICE_BAR)) { lua_pushboolean(L,1); /* value */ lua_setfield(L,-2,"bar"); /* key */ } if (planet_hasService(p, PLANET_SERVICE_MISSIONS)) { lua_pushboolean(L,1); /* value */ lua_setfield(L,-2,"missions"); /* key */ } if (planet_hasService(p, PLANET_SERVICE_COMMODITY)) { lua_pushboolean(L,1); /* value */ lua_setfield(L,-2,"commodity"); /* key */ } if (planet_hasService(p, PLANET_SERVICE_OUTFITS)) { lua_pushboolean(L,1); /* value */ lua_setfield(L,-2,"outfits"); /* key */ } if (planet_hasService(p, PLANET_SERVICE_SHIPYARD)) { lua_pushboolean(L,1); /* value */ lua_setfield(L,-2,"shipyard"); /* key */ } return 1; }
/** * @brief Gets a planet directly. * * @param L Lua state to get planet from. * @param ind Index position to find the planet. * @return Planet found at the index in the state. */ Planet* luaL_validplanet( lua_State *L, int ind ) { LuaPlanet *lp; Planet *p; if (lua_isplanet(L, ind)) { lp = luaL_checkplanet(L, ind); p = planet_getIndex(*lp); } else if (lua_isstring(L, ind)) p = planet_get( lua_tostring(L, ind) ); else { luaL_typerror(L, ind, PLANET_METATABLE); return NULL; } if (p == NULL) NLUA_ERROR(L, _("Planet is invalid")); return p; }