13#include "pilot_hook.h"
37 HookParam hstaparam[5], *hdynparam, *hparam;
42 hstaparam[0].
type = HOOK_PARAM_PILOT;
43 hstaparam[0].
u.
lp = p->id;
45 memcpy( &hstaparam[n], param,
sizeof(
HookParam ) * nparam );
47 hstaparam[n].
type = HOOK_PARAM_SENTINEL;
51 hdynparam = malloc(
sizeof(
HookParam ) * ( nparam + 2 ) );
52 hdynparam[0].
type = HOOK_PARAM_PILOT;
53 hdynparam[0].
u.
lp = p->id;
54 memcpy( &hdynparam[1], param,
sizeof(
HookParam ) * nparam );
55 hdynparam[nparam + 1].
type = HOOK_PARAM_SENTINEL;
61 for (
int i = 0; i <
array_size( p->hooks ); i++ ) {
63 if ( p->hooks[i].type != hook_type )
68 WARN( _(
"Pilot '%s' failed to run hook type %d" ), p->name,
82 WARN( _(
"Pilot '%s' failed to run hook type %d" ), p->name,
121 if ( pilot == NULL ) {
122 WARN( _(
"Trying to set hook on NULL pilot!" ) );
127 if ( pilot->
hooks == NULL )
193 for (
int i = 0; i <
array_size( plist ); i++ ) {
196 for (
int j = 0; j <
array_size( p->hooks ); j++ ) {
198 if ( p->hooks[j].id != hook )
201 array_erase( &p->hooks, &p->hooks[j], &p->hooks[j + 1] );
216 for (
int i = 0; i <
array_size( p->hooks ); i++ )
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_end(array)
Returns a pointer to the end of the reserved memory space.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_begin(array)
Returns a pointer to the beginning of the reserved memory space.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void claim_activateAll(void)
Activates all the claims.
int hook_runIDparam(unsigned int id, const HookParam *param)
Runs a single hook by id.
void hook_rm(unsigned int id)
Removes a hook.
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
void pilots_clearGlobalHooks(void)
Removes all the pilot global hooks.
static PilotHook * pilot_globalHooks
void pilots_addGlobalHook(int type, unsigned int hook)
Adds a pilot global hook.
void pilots_rmHook(unsigned int hook)
Removes a hook from all the pilots.
static int pilot_hookCleanup
void pilot_clearHooks(Pilot *p)
Clears the pilots hooks.
int pilot_runHookParam(Pilot *p, int hook_type, const HookParam *param, int nparam)
Tries to run a pilot hook if he has it.
void pilot_freeGlobalHooks(void)
Clears global pilot hooks.
int pilot_runHook(Pilot *p, int hook_type)
Tries to run a pilot hook if he has it.
void pilot_addHook(Pilot *pilot, int type, unsigned int hook)
Adds a hook to the pilot.
void pilots_rmGlobalHook(unsigned int hook)
Removes a pilot global hook.
The actual hook parameter.
union HookParam::@065274143236224234262250043114351136253171035204 u
A wrapper for pilot hooks.
The representation of an in-game pilot.