/** * @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 Saves a planet. * * @param writer Write to use for saving the star planet. * @param p Planet to save. * @return 0 on success. */ static int dpl_savePlanet( xmlTextWriterPtr writer, const Planet *p ) { int i; xmlw_startElem( writer, "asset" ); /* Attributes. */ xmlw_attr( writer, "name", "%s", p->name ); /* Explicit virtualness. */ if (p->real == ASSET_VIRTUAL) xmlw_elemEmpty( writer, "virtual" ); /* Position. */ if (p->real == ASSET_REAL) { xmlw_startElem( writer, "pos" ); xmlw_elem( writer, "x", "%f", p->pos.x ); xmlw_elem( writer, "y", "%f", p->pos.y ); xmlw_endElem( writer ); /* "pos" */ } /* GFX. */ if (p->real == ASSET_REAL) { xmlw_startElem( writer, "GFX" ); xmlw_elem( writer, "space", "%s", p->gfx_spacePath ); xmlw_elem( writer, "exterior", "%s", p->gfx_exteriorPath ); xmlw_endElem( writer ); /* "GFX" */ } /* Presence. */ if (p->faction >= 0) { xmlw_startElem( writer, "presence" ); xmlw_elem( writer, "faction", "%s", faction_name( p->faction ) ); xmlw_elem( writer, "value", "%f", p->presenceAmount ); xmlw_elem( writer, "range", "%d", p->presenceRange ); xmlw_endElem( writer ); } /* General. */ if (p->real == ASSET_REAL) { xmlw_startElem( writer, "general" ); xmlw_elem( writer, "class", "%c", planet_getClass( p ) ); xmlw_elem( writer, "population", "%"PRIu64, p->population ); xmlw_startElem( writer, "services" ); if (planet_hasService( p, PLANET_SERVICE_LAND )) { if (p->land_func == NULL) xmlw_elemEmpty( writer, "land" ); else xmlw_elem( writer, "land", "%s", p->land_func ); } if (planet_hasService( p, PLANET_SERVICE_REFUEL )) xmlw_elemEmpty( writer, "refuel" ); if (planet_hasService( p, PLANET_SERVICE_BAR )) xmlw_elemEmpty( writer, "bar" ); if (planet_hasService( p, PLANET_SERVICE_MISSIONS )) xmlw_elemEmpty( writer, "missions" ); if (planet_hasService( p, PLANET_SERVICE_COMMODITY )) xmlw_elemEmpty( writer, "commodity" ); if (planet_hasService( p, PLANET_SERVICE_OUTFITS )) xmlw_elemEmpty( writer, "outfits" ); if (planet_hasService( p, PLANET_SERVICE_SHIPYARD )) xmlw_elemEmpty( writer, "shipyard" ); xmlw_endElem( writer ); /* "services" */ if (planet_hasService( p, PLANET_SERVICE_LAND )) { xmlw_startElem( writer, "commodities" ); for (i=0; i<p->ncommodities; i++) xmlw_elem( writer, "commodity", "%s", p->commodities[i]->name ); xmlw_endElem( writer ); /* "commodities" */ xmlw_elem( writer, "description", "%s", p->description ); if (planet_hasService( p, PLANET_SERVICE_BAR )) xmlw_elem( writer, "bar", "%s", p->bar_description ); } xmlw_endElem( writer ); /* "general" */ } /* Tech. */ if (planet_hasService( p, PLANET_SERVICE_LAND )) tech_groupWrite( writer, p->tech ); xmlw_endElem( writer ); /** "planet" */ return 0; }