[Add] Ability to figure out where a planet is located.

This commit is contained in:
Allanis 2013-04-09 21:11:12 +01:00
parent 0fbd239680
commit ae97cb398c
5 changed files with 59 additions and 5 deletions

View File

@ -2,7 +2,7 @@ lang = lephisto.lang()
if lang == "es" then
-- Not translated.
else -- Default English.
misn_desc = "%s needs a delivery of %d tons of %s."
misn_desc = "%s in the %s system needs a delivery of %d tons of %s."
misn_reward = "%d Scred."
title = {}
title[1] = "Cargo delivery to %s"
@ -34,6 +34,8 @@ function create()
misn.finish(false)
end
system = space.getSystem(planet)
-- Missions generic.
misn_type = "Cargo"
i = rnd.int(3)
@ -45,7 +47,7 @@ function create()
if i == 0 then carg_type = "Food"
elseif i == 1 then carg_type = "Ore"
end
misn.setDesc(string.format(misn_desc, planet, carg_mass, carg_type))
misn.setDesc(string.format(misn_desc, planet, system, carg_mass, carg_type))
reward = carg_mass * (750 + rnd.int(250)) + rnd.int(5000)
misn.setReward(string.format(misn_reward, reward))
end

View File

@ -11,10 +11,10 @@ else -- Default English.
title[3] = "Mission Accomplished"
text = {}
text[1] = [[As you enter the bar you can't help but notice that a fellow at a table has been looking at you since you came in. You tend to your business as if you hadn't noticed. A while later you feel a tap on your shoulder and see it's the same man.]]
text[2] = [["Hello, sorry to interupt you. I'm lieutenant Tamrit from the empire Armada. We're having another recruitment operation and would be interested in having another pilot among us. Would you be interested in working for the Empire?"]]
text[2] = [["Hello, sorry to interupt you. I'm lieutenant Tamrit from the empire Armada, shipping division. We're having another recruitment operation and would be interested in having another pilot among us. Would you be interested in working for the Empire?"]]
text[3] = [["Welcome aboard.", says Tamrit before giving you a firm handshake. "At first you'll be tested with cargo missions while we get data on your flying skills. Later you could get called for more important missions. Who knows? You could be the next Medek, greatest pilot we ever had on the Armada."
He hits a couple buttons on his wrist computer that springs into action.
"It looks like we already have a simple task for you. Deliver these parcels to %s. The best pilots started out delivering papers and ended up flying into combat against large warships."]]
"It looks like we already have a simple task for you. Deliver these parcels to %s. The best pilots started out delivering papers and ended up flying into combat against large warships in the interception division."]]
text[4] = [["You deliver the parcels to the Empire station at the %s spaceport. Afterwards they make you do some paperwork to formalize your participation with the Empire. You aren't too sure of your encounter with the Empire, only time will tell.]]
end

View File

@ -50,9 +50,11 @@ static const luaL_Reg misn_methods[] = {
// Space.
static int space_getPlanet(lua_State* L);
static int space_getSystem(lua_State* L);
static int space_landName(lua_State* L);
static const luaL_Reg space_methods[] = {
{ "getPlanet", space_getPlanet },
{ "getSystem", space_getSystem },
{ "landName", space_landName },
{ 0, 0 }
};
@ -286,6 +288,19 @@ static int space_getPlanet(lua_State* L) {
return 1;
}
static int space_getSystem(lua_State* L) {
char* planetname, *system;
MIN_ARGS(1);
if(lua_isstring(L, -1)) planetname = (char*) lua_tostring(L, -1);
else return 0;
system = planet_getSystem(planetname);
lua_pushstring(L, system);
return 1;
}
static int space_landName(lua_State* L) {
if(landed) {
lua_pushstring(L, land_planet->name);

View File

@ -39,6 +39,11 @@
#define FLAG_TECHSET (1<<5)
#define FLAG_FACTIONSET (1<<6)
// Planet <-> system name stack.
static char** planetname_stack = NULL;
static char** systemname_stack = NULL;
static int spacename_nstack = 0;
// Star system stack and co.
StarSystem* systems_stack = NULL; // Star system stack.
int systems_nstack = 0; // Number of star systems.
@ -254,6 +259,17 @@ char* space_getRndPlanet(void) {
return res;
}
// Get the name of a system from a planetname.
char* planet_getSystem(char* planetname) {
int i;
for(i = 0; i < spacename_nstack; i++)
if(strcmp(planetname_stack[i], planetname)==0)
return systemname_stack[i];
DEBUG("Planet '%s' not found in planetname stack", planetname);
return NULL;
}
// Basically used for spawning fleets.
void space_update(const double dt) {
unsigned int t;
@ -563,11 +579,21 @@ static StarSystem* system_parse(const xmlNodePtr parent) {
cur = node->children;
do {
if(xml_isNode(cur, "planet")) {
// Add planet to system.
nplanets++; // Increase planet counter.
planet = planet_get(xml_get(cur));
planet = planet_get((const char*)cur->children->content);
tmp->planets = realloc(tmp->planets, sizeof(Planet)*(++tmp->nplanets));
memcpy(tmp->planets+(tmp->nplanets-1), planet, sizeof(Planet));
// Add planet <-> star system to name stack.
spacename_nstack++;
planetname_stack = realloc(planetname_stack,
sizeof(char*)*spacename_nstack);
systemname_stack = realloc(systemname_stack,
sizeof(char*)*spacename_nstack);
planetname_stack[spacename_nstack-1] = planet->name;
systemname_stack[spacename_nstack-1] = tmp->name;
free(planet);
}
} while((cur = cur->next));
@ -777,6 +803,13 @@ void planets_render(void) {
// Clean up the system.
void space_exit(void) {
int i,j;
// Free the names.
if(planetname_stack) free(planetname_stack);
if(systemname_stack) free(systemname_stack);
spacename_nstack = 0;
// Free the systems.
for(i = 0; i < systems_nstack; i++) {
free(systems_stack[i].name);
if(systems_stack[i].fleets)
@ -784,6 +817,7 @@ void space_exit(void) {
if(systems_stack[i].jumps)
free(systems_stack[i].jumps);
// Free some planets.
for(j = 0; j < systems_stack[i].nplanets; j++) {
free(systems_stack[i].planets[j].name);
if(systems_stack[i].planets[j].description)
@ -806,8 +840,8 @@ void space_exit(void) {
systems_stack = NULL;
systems_nstack = 0;
// Stars must be set free too.
if(stars) free(stars);
stars = NULL;
nstars = 0;
}

View File

@ -98,6 +98,9 @@ void space_init(const char* sysname);
int space_load(void);
void space_exit(void);
// Planet stuff.
char* planet_getSystem(char* planetname);
// Render.
void space_render(double dt);
void planets_render(void);