[Add] Improved space.getPlanet() mission lua.
This commit is contained in:
parent
64f929c1d3
commit
7f973d7fe8
@ -209,10 +209,17 @@ static int space_getPlanet(lua_State* L) {
|
|||||||
|
|
||||||
if(lua_gettop(L) == 0) {
|
if(lua_gettop(L) == 0) {
|
||||||
// Get random planet.
|
// Get random planet.
|
||||||
|
lua_pushstring(L, space_getRndPlanet());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if(lua_isnumber(L, -1) || lua_istable(L, -1)) {
|
||||||
|
// Faction table or single.
|
||||||
|
if(lua_isnumber(L, -1)) {
|
||||||
|
// Faction is just a number.
|
||||||
|
i = lua_tonumber(L, -1);
|
||||||
|
planets = space_getFactionPlanet(&nplanets, &i, 1);
|
||||||
}
|
}
|
||||||
else if(lua_istable(L, -1)) {
|
else if(lua_istable(L, -1)) {
|
||||||
// Get planet of faction in table.
|
|
||||||
|
|
||||||
// Load up the table.
|
// Load up the table.
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
nfactions = (int) lua_gettop(L);
|
nfactions = (int) lua_gettop(L);
|
||||||
@ -226,7 +233,7 @@ static int space_getPlanet(lua_State* L) {
|
|||||||
// Get the planets.
|
// Get the planets.
|
||||||
planets = space_getFactionPlanet(&nplanets, factions, nfactions);
|
planets = space_getFactionPlanet(&nplanets, factions, nfactions);
|
||||||
free(factions);
|
free(factions);
|
||||||
|
}
|
||||||
// Choose random planet.
|
// Choose random planet.
|
||||||
if(nplanets == 0) {
|
if(nplanets == 0) {
|
||||||
// No suitable planets.
|
// No suitable planets.
|
||||||
|
28
src/space.c
28
src/space.c
@ -226,6 +226,34 @@ char** space_getFactionPlanet(int* nplanets, int* factions, int nfactions) {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the name of a random planet.
|
||||||
|
char* space_getRndPlanet(void) {
|
||||||
|
int i, j;
|
||||||
|
char** tmp;
|
||||||
|
int ntmp;
|
||||||
|
int mtmp;
|
||||||
|
char* res;
|
||||||
|
|
||||||
|
ntmp = 0;
|
||||||
|
mtmp = 25;
|
||||||
|
tmp = malloc(sizeof(char)*mtmp);
|
||||||
|
|
||||||
|
for(i = 0; i < systems_nstack; i++)
|
||||||
|
for(j = 0; j < systems_stack[i].nplanets; j++) {
|
||||||
|
ntmp++;
|
||||||
|
if(ntmp > mtmp) {
|
||||||
|
mtmp += 25;
|
||||||
|
tmp = realloc(tmp, sizeof(char*) * mtmp);
|
||||||
|
}
|
||||||
|
tmp[ntmp-1] = systems_stack[i].planets[j].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = tmp[RNG(0, ntmp-1)];
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
// Basically used for spawning fleets.
|
// Basically used for spawning fleets.
|
||||||
void space_update(const double dt) {
|
void space_update(const double dt) {
|
||||||
unsigned int t;
|
unsigned int t;
|
||||||
|
@ -109,5 +109,6 @@ void space_update(const double dt);
|
|||||||
int space_canHyperspace(Pilot* p);
|
int space_canHyperspace(Pilot* p);
|
||||||
int space_hyperspace(Pilot* p);
|
int space_hyperspace(Pilot* p);
|
||||||
char** space_getFactionPlanet(int* nplanets, int* factions, int nfactions);
|
char** space_getFactionPlanet(int* nplanets, int* factions, int nfactions);
|
||||||
|
char* space_getRndPlanet(void);
|
||||||
extern char* stardate;
|
extern char* stardate;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user