[Add] Two new hooks: Board and disable. Also made lua debug more verbose.
This commit is contained in:
parent
6099849f4f
commit
dcf093b13e
@ -63,7 +63,7 @@ function enter()
|
|||||||
elseif sys == misn_target then
|
elseif sys == misn_target then
|
||||||
p = pilot.add("Collective Drone", "scout")
|
p = pilot.add("Collective Drone", "scout")
|
||||||
for k,v in pairs(p) do
|
for k,v in pairs(p) do
|
||||||
hook.pilotDeath(v, "kill")
|
hook.pilot(v, "death", "kill")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "space.h"
|
#include "space.h"
|
||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
|
#include "hook.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
#define BOARDING_WIDTH 300
|
#define BOARDING_WIDTH 300
|
||||||
@ -77,6 +78,10 @@ void player_board(void) {
|
|||||||
"Leave", board_exit);
|
"Leave", board_exit);
|
||||||
|
|
||||||
board_update();
|
board_update();
|
||||||
|
|
||||||
|
/* Run hook if needed. */
|
||||||
|
if(p->hook_type == PILOT_HOOK_BOARD)
|
||||||
|
hook_runID(p->hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void board_exit(char* str) {
|
static void board_exit(char* str) {
|
||||||
|
@ -174,7 +174,9 @@ void hook_cleanup(void) {
|
|||||||
/* Save the hooks. */
|
/* Save the hooks. */
|
||||||
static int hook_needSave(Hook* h) {
|
static int hook_needSave(Hook* h) {
|
||||||
int i;
|
int i;
|
||||||
char* nosave[] = { "death", "end" };
|
char* nosave[] = {
|
||||||
|
"death", "board", "disable", /* Pilot hooks. */
|
||||||
|
"end" };
|
||||||
|
|
||||||
for(i = 0; strcmp(nosave[i], "end") != 0; i++)
|
for(i = 0; strcmp(nosave[i], "end") != 0; i++)
|
||||||
if(strcmp(nosave[i], h->stack)==0) return 0;
|
if(strcmp(nosave[i], h->stack)==0) return 0;
|
||||||
|
@ -5,19 +5,24 @@
|
|||||||
#include "lualib.h"
|
#include "lualib.h"
|
||||||
|
|
||||||
/* Debug stuff. */
|
/* Debug stuff. */
|
||||||
|
#ifdef DEBUG
|
||||||
#define LLUA_DEBUG(str, args...) \
|
#define LLUA_DEBUG(str, args...) \
|
||||||
(fprintf(stdout, "Lua: "str"\n", ## args))
|
(fprintf(stdout, "Lua: "str"\n", ## args))
|
||||||
|
|
||||||
#define LLUA_INVALID_PARAMETER() { \
|
#define LLUA_INVALID_PARAMETER() { \
|
||||||
LLUA_DEBUG("[%s] Invalid parameter", __func__); \
|
LLUA_DEBUG("[%s] Invalid parameter (%s:%d)", __func__, __FILE__, __LINE__); \
|
||||||
return 0; \
|
return 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LLUA_MIN_ARGS(n) \
|
#define LLUA_MIN_ARGS(n) \
|
||||||
if(lua_gettop(L) < n) { \
|
if(lua_gettop(L) < n) { \
|
||||||
LLUA_DEBUG("[%s] Too few arguments", __func__); \
|
LLUA_DEBUG("[%s] Too few arguments (%s:%d)", __func__, __FILE__, __LINE__); \
|
||||||
return 0; \
|
return 0; \
|
||||||
}
|
}
|
||||||
|
#else /* DEBUG. */
|
||||||
|
#define LLUA_DEBUG(str, args...) do {;} while(0)
|
||||||
|
#define LLUA_MIN_ARGS(n) do {;} while(0)
|
||||||
|
#endif /* DEBUG. */
|
||||||
|
|
||||||
/* Comfortability macros. */
|
/* Comfortability macros. */
|
||||||
#define luaL_dobuffer(L, b, n, s) \
|
#define luaL_dobuffer(L, b, n, s) \
|
||||||
|
@ -123,13 +123,13 @@ static int hook_land(lua_State* L);
|
|||||||
static int hook_takeoff(lua_State* L);
|
static int hook_takeoff(lua_State* L);
|
||||||
static int hook_time(lua_State* L);
|
static int hook_time(lua_State* L);
|
||||||
static int hook_enter(lua_State* L);
|
static int hook_enter(lua_State* L);
|
||||||
static int hook_pilotDeath(lua_State* L);
|
static int hook_pilot(lua_State* L);
|
||||||
static const luaL_reg hook_methods[] = {
|
static const luaL_reg hook_methods[] = {
|
||||||
{ "land", hook_land },
|
{ "land", hook_land },
|
||||||
{ "takeoff", hook_takeoff },
|
{ "takeoff", hook_takeoff },
|
||||||
{ "time", hook_time },
|
{ "time", hook_time },
|
||||||
{ "enter", hook_enter },
|
{ "enter", hook_enter },
|
||||||
{ "pilotDeath", hook_pilotDeath },
|
{ "pilot", hook_pilot },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -682,6 +682,10 @@ static unsigned int hook_generic(lua_State* L, char* stack) {
|
|||||||
char* func;
|
char* func;
|
||||||
|
|
||||||
LLUA_MIN_ARGS(1);
|
LLUA_MIN_ARGS(1);
|
||||||
|
|
||||||
|
/* Last parameter must be function to hook. */
|
||||||
|
if(lua_isstring(L, -1)) func = (char*)lua_tostring(L, -1);
|
||||||
|
else LLUA_INVALID_PARAMETER();
|
||||||
|
|
||||||
/* Make sure mission is a player mission. */
|
/* Make sure mission is a player mission. */
|
||||||
for(i = 0; i < MISSION_MAX; i++)
|
for(i = 0; i < MISSION_MAX; i++)
|
||||||
@ -692,12 +696,6 @@ static unsigned int hook_generic(lua_State* L, char* stack) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lua_isstring(L, -1)) func = (char*)lua_tostring(L, -1);
|
|
||||||
else {
|
|
||||||
WARN("Mission '%s': trying to push non-valid function hook",
|
|
||||||
cur_mission->data->name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return hook_add(cur_mission->id, func, stack);
|
return hook_add(cur_mission->id, func, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -721,15 +719,33 @@ static int hook_enter(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hook_pilotDeath(lua_State* L) {
|
static int hook_pilot(lua_State* L) {
|
||||||
LLUA_MIN_ARGS(2);
|
LLUA_MIN_ARGS(2);
|
||||||
unsigned int h, p;
|
unsigned int h, p;
|
||||||
|
int type;
|
||||||
|
char* hook_type;
|
||||||
|
|
||||||
if(lua_isnumber(L, -2)) p = (unsigned int) lua_tonumber(L, -2);
|
/* First parameter - pilot to hook. */
|
||||||
|
if(lua_isnumber(L, 1)) p = (unsigned int)lua_tonumber(L, 1);
|
||||||
else LLUA_INVALID_PARAMETER();
|
else LLUA_INVALID_PARAMETER();
|
||||||
|
|
||||||
h = hook_generic(L, "death"); /* We won't actually call the death stack directly. */
|
/* Second parameer - Hook name. */
|
||||||
pilot_addHook(pilot_get(p), PILOT_HOOK_DEATH, h);
|
if(lua_isstring(L, 2)) hook_type = (char*) lua_tostring(L, 2);
|
||||||
|
else LLUA_INVALID_PARAMETER();
|
||||||
|
|
||||||
|
/* Check to see if hook_type is valid. */
|
||||||
|
if(strcmp(hook_type, "death")==0) type = PILOT_HOOK_DEATH;
|
||||||
|
else if(strcmp(hook_type, "board")==0) type = PILOT_HOOK_BOARD;
|
||||||
|
else if(strcmp(hook_type, "disable")==0) type = PILOT_HOOK_DISABLE;
|
||||||
|
else { /* Hook type not valid. */
|
||||||
|
LLUA_DEBUG("Invalid pilot hook type: '%s'", hook_type);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Actually add the hook. */
|
||||||
|
h = hook_generic(L, hook_type);
|
||||||
|
pilot_addHook(pilot_get(p), type, h);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
15
src/pilot.c
15
src/pilot.c
@ -424,10 +424,17 @@ static void pilot_update(Pilot* pilot, const double dt) {
|
|||||||
else if(pilot->armour <= 0.) /* PWNED! */
|
else if(pilot->armour <= 0.) /* PWNED! */
|
||||||
pilot_dead(pilot); /* Start death stuff. */
|
pilot_dead(pilot); /* Start death stuff. */
|
||||||
|
|
||||||
/* Pupose fallthrough to get the movement similar to disabled. */
|
/* Purpose fallthrough to get the movement similar to disabled. */
|
||||||
if(pilot != player && pilot->armour < PILOT_DISABLED_ARMOUR * pilot->armour_max) {
|
if((pilot != player) &&
|
||||||
/* We are disabled. */
|
(pilot->armour < PILOT_DISABLED_ARMOUR*pilot->armour_max)) { /* Disabled. */
|
||||||
pilot_setFlag(pilot, PILOT_DISABLED);
|
/* First time pilot is disabled. */
|
||||||
|
if(!pilot_isFlag(pilot, PILOT_DISABLED)) {
|
||||||
|
pilot_setFlag(pilot, PILOT_DISABLED); /* Set as disabled. */
|
||||||
|
/* Run hook. */
|
||||||
|
if(pilot->hook_type == PILOT_HOOK_DISABLE)
|
||||||
|
hook_runID(pilot->hook);
|
||||||
|
}
|
||||||
|
|
||||||
/* Come to a halt slowly. */
|
/* Come to a halt slowly. */
|
||||||
vect_pset(&pilot->solid->vel,
|
vect_pset(&pilot->solid->vel,
|
||||||
VMOD(pilot->solid->vel) * (1. - dt*0.10), VANGLE(pilot->solid->vel));
|
VMOD(pilot->solid->vel) * (1. - dt*0.10), VANGLE(pilot->solid->vel));
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
/* Hooks. */
|
/* Hooks. */
|
||||||
#define PILOT_HOOK_NONE 0 /* No hook. */
|
#define PILOT_HOOK_NONE 0 /* No hook. */
|
||||||
#define PILOT_HOOK_DEATH 1 /* Pilot died. */
|
#define PILOT_HOOK_DEATH 1 /* Pilot died. */
|
||||||
|
#define PILOT_HOOK_BOARD 2 /* Pilot got boarded. */
|
||||||
|
#define PILOT_HOOK_DISABLE 3 /* Pilot got disabled. */
|
||||||
|
|
||||||
/* Flags. */
|
/* Flags. */
|
||||||
#define pilot_isFlag(p,f) (p->flags & (f))
|
#define pilot_isFlag(p,f) (p->flags & (f))
|
||||||
|
Loading…
Reference in New Issue
Block a user