[Change] Minor misn_lua cleanup and added pilot.rename().
This commit is contained in:
parent
75954df719
commit
049b52fc79
@ -15,8 +15,13 @@
|
|||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
#include "misn_lua.h"
|
#include "misn_lua.h"
|
||||||
|
|
||||||
#define MISN_DEBUG(str, args...) (fprintf(stdout, "Mission '%s': "str"\n", \
|
#define MISN_DEBUG(str, args...) \
|
||||||
cur_mission->data->name, ## args))
|
(fprintf(stdout, "Mission '%s': "str"\n", cur_mission->data->name, ## args))
|
||||||
|
|
||||||
|
#define MISN_INVALID_PARAMETER() { \
|
||||||
|
MISN_DEBUG("Invalid parameter."); \
|
||||||
|
return 0; \
|
||||||
|
}
|
||||||
|
|
||||||
#define MIN_ARGS(n) \
|
#define MIN_ARGS(n) \
|
||||||
if(lua_gettop(L) < n) { \
|
if(lua_gettop(L) < n) { \
|
||||||
@ -169,8 +174,10 @@ static const luaL_reg hook_methods[] = {
|
|||||||
|
|
||||||
// Pilots.
|
// Pilots.
|
||||||
static int pilot_addFleet(lua_State* L);
|
static int pilot_addFleet(lua_State* L);
|
||||||
|
static int pilot_rename(lua_State* L);
|
||||||
static const luaL_reg pilot_methods[] = {
|
static const luaL_reg pilot_methods[] = {
|
||||||
{ "add", pilot_addFleet },
|
{ "add", pilot_addFleet },
|
||||||
|
{ "rename", pilot_rename },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -647,10 +654,7 @@ static int space_jumpDist(lua_State* L) {
|
|||||||
|
|
||||||
if(lua_isstring(L, -1))
|
if(lua_isstring(L, -1))
|
||||||
start = (char*)lua_tostring(L, -1);
|
start = (char*)lua_tostring(L, -1);
|
||||||
else {
|
else MISN_INVALID_PARAMETER();
|
||||||
MISN_DEBUG("invalid parameter 1");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((lua_gettop(L) > 1) && lua_isstring(L, -2))
|
if((lua_gettop(L) > 1) && lua_isstring(L, -2))
|
||||||
goal = (char*) lua_tostring(L, -2);
|
goal = (char*) lua_tostring(L, -2);
|
||||||
@ -889,10 +893,7 @@ static int hook_pilotDeath(lua_State* L) {
|
|||||||
unsigned int p;
|
unsigned int p;
|
||||||
|
|
||||||
if(lua_isnumber(L, -2)) p = (unsigned int) lua_tonumber(L, -2);
|
if(lua_isnumber(L, -2)) p = (unsigned int) lua_tonumber(L, -2);
|
||||||
else {
|
else MISN_INVALID_PARAMETER();
|
||||||
MISN_DEBUG("Invalid first param");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
h = hook_generic(L, "death"); // We won't actually call the death stack directly.
|
h = hook_generic(L, "death"); // We won't actually call the death stack directly.
|
||||||
pilot_addHook(pilot_get(p), PILOT_HOOK_DEATH, h);
|
pilot_addHook(pilot_get(p), PILOT_HOOK_DEATH, h);
|
||||||
@ -911,10 +912,7 @@ static int pilot_addFleet(lua_State* L) {
|
|||||||
Vec2 vv, vp, vn;
|
Vec2 vv, vp, vn;
|
||||||
|
|
||||||
if(lua_isstring(L, -1)) fltname = (char*) lua_tostring(L, -1);
|
if(lua_isstring(L, -1)) fltname = (char*) lua_tostring(L, -1);
|
||||||
else {
|
else MISN_INVALID_PARAMETER();
|
||||||
MISN_DEBUG("Invalid parameter");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pull the fleet.
|
// Pull the fleet.
|
||||||
flt = fleet_get(fltname);
|
flt = fleet_get(fltname);
|
||||||
@ -956,3 +954,20 @@ static int pilot_addFleet(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pilot_rename(lua_State* L) {
|
||||||
|
MIN_ARGS(2);
|
||||||
|
char* name;
|
||||||
|
unsigned int id;
|
||||||
|
Pilot* p;
|
||||||
|
|
||||||
|
if(lua_isnumber(L, -2)) id = (unsigned int) lua_tonumber(L, -2);
|
||||||
|
else MISN_INVALID_PARAMETER();
|
||||||
|
if(lua_isstring(L, -1)) name = (char*) lua_tostring(L, -1);
|
||||||
|
else MISN_INVALID_PARAMETER();
|
||||||
|
|
||||||
|
p = pilot_get(id);
|
||||||
|
free(p->name);
|
||||||
|
p->name = strdup(name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user