naev 0.10.4
hook.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include "mission.h"
7#include "nlua_asteroid.h"
8#include "nlua_faction.h"
9#include "nlua_jump.h"
10#include "nlua_pilot.h"
11#include "nlua_spob.h"
12
13#define HOOK_MAX_PARAM 5
18typedef enum HookParamType_e {
19 HOOK_PARAM_NIL,
20 HOOK_PARAM_NUMBER,
21 HOOK_PARAM_STRING,
22 HOOK_PARAM_BOOL,
23 HOOK_PARAM_PILOT,
24 HOOK_PARAM_FACTION,
25 HOOK_PARAM_SPOB,
26 HOOK_PARAM_JUMP,
27 HOOK_PARAM_ASTEROID,
28 HOOK_PARAM_REF,
29 HOOK_PARAM_SENTINEL
30} HookParamType;
31
35typedef struct HookParam_s {
36 HookParamType type;
37 union {
38 double num;
39 const char *str;
40 int b;
41 LuaPilot lp;
42 LuaFaction lf;
43 LuaSpob la;
46 int ref;
47 } u;
48} HookParam;
49
50/*
51 * Exclusion.
52 */
53void hook_exclusionStart (void);
54void hook_exclusionEnd( double dt );
55
56/* add/run hooks */
57unsigned int hook_addMisn( unsigned int parent, const char *func, const char *stack );
58unsigned int hook_addEvent( unsigned int parent, const char *func, const char *stack );
59unsigned int hook_addFunc( int (*func)(void*), void *data, const char *stack );
60void hook_rm( unsigned int id );
61void hook_rmMisnParent( unsigned int parent );
62void hook_rmEventParent( unsigned int parent );
63int hook_hasMisnParent( unsigned int parent );
64int hook_hasEventParent( unsigned int parent );
65
66/* pilot hook. Weird dependencies don't let us put it into pilot_hook.h */
67int pilot_runHookParam( Pilot* p, int hook_type, const HookParam *param, int nparam );
68nlua_env hook_env( unsigned int hook );
69
70/*
71 * run hooks
72 *
73 * Currently used:
74 * - General
75 * - "safe" - Runs once each frame at a same time (last in the frame), good place to do breaking stuff.
76 * - "takeoff" - When taking off
77 * - "jumpin" - When player jumps (after changing system)
78 * - "jumpout" - When player jumps (before changing system)
79 * - "time" - When time is increment drastically (hyperspace and taking off)
80 * - "hail" - When any pilot is hailed
81 * - "board" - When any pilot is boarded
82 * - "input" - When an input command is pressed
83 * - "standing" - Whenever faction changes.
84 * - "load" - Run on load.
85 * - "discover" - When something is discovered.
86 * - "pay" - When player receives or loses money.
87 * - Landing
88 * - "land" - When landed
89 * - "outfits" - When visited outfitter
90 * - "shipyard" - When visited shipyard
91 * - "bar" - When visited bar
92 * - "mission" - When visited mission computer
93 * - "commodity" - When visited commodity exchange
94 * - "equipment" - When visiting equipment place < br/>
95 */
96int hooks_runParamDeferred( const char* stack, const HookParam *param );
97int hooks_runParam( const char* stack, const HookParam *param );
98int hooks_run( const char* stack );
99int hook_runIDparam( unsigned int id, const HookParam *param );
100int hook_runID( unsigned int id ); /* runs hook of specific id */
101
102/* Destroys hooks */
103void hook_cleanup (void);
104
105/* Timer hooks. */
106void hooks_update( double dt );
107unsigned int hook_addTimerMisn( unsigned int parent, const char *func, double ms );
108unsigned int hook_addTimerEvt( unsigned int parent, const char *func, double ms );
109
110/* Date hooks. */
111void hooks_updateDate( ntime_t change );
112unsigned int hook_addDateMisn( unsigned int parent, const char *func, ntime_t resolution );
113unsigned int hook_addDateEvt( unsigned int parent, const char *func, ntime_t resolution );
unsigned int hook_addTimerEvt(unsigned int parent, const char *func, double ms)
Adds a new event type hook timer.
Definition: hook.c:563
int hook_runIDparam(unsigned int id, const HookParam *param)
Runs a single hook by id.
Definition: hook.c:1041
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
Definition: hook.c:967
void hook_rmMisnParent(unsigned int parent)
Removes all hooks belonging to parent mission.
Definition: hook.c:809
void hooks_update(double dt)
Updates all the hook timer related stuff.
Definition: hook.c:726
int hook_runID(unsigned int id)
Runs a single hook by id.
Definition: hook.c:1066
int hook_hasEventParent(unsigned int parent)
Checks to see how many hooks there are with the same event parent.
Definition: hook.c:850
void hook_cleanup(void)
Gets rid of all current hooks.
Definition: hook.c:1104
int hooks_runParamDeferred(const char *stack, const HookParam *param)
Runs all the hooks of stack in the next frame. Does not trigger right away.
Definition: hook.c:935
nlua_env hook_env(unsigned int hook)
Gets the lua env for a hook.
Definition: hook.c:1007
void hooks_updateDate(ntime_t change)
Updates the time to see if it should be updated.
Definition: hook.c:635
unsigned int hook_addEvent(unsigned int parent, const char *func, const char *stack)
Adds a new event type hook.
Definition: hook.c:519
void hook_rm(unsigned int id)
Removes a hook.
Definition: hook.c:786
void hook_exclusionEnd(double dt)
Ends exclusion zone and runs all the queued hooks.
Definition: hook.c:195
int hooks_run(const char *stack)
Runs all the hooks of stack.
Definition: hook.c:987
void hook_rmEventParent(unsigned int parent)
Removes all hooks belonging to parent event.
Definition: hook.c:821
unsigned int hook_addFunc(int(*func)(void *), void *data, const char *stack)
Adds a function hook to be run.
Definition: hook.c:582
int hook_hasMisnParent(unsigned int parent)
Checks to see how many hooks there are with the same mission parent.
Definition: hook.c:834
void hook_exclusionStart(void)
Starts the hook exclusion zone, this makes hooks queue until exclusion is done.
Definition: hook.c:187
unsigned int hook_addTimerMisn(unsigned int parent, const char *func, double ms)
Adds a new mission type hook timer hook.
Definition: hook.c:539
unsigned int hook_addMisn(unsigned int parent, const char *func, const char *stack)
Adds a new mission type hook.
Definition: hook.c:499
int pilot_runHookParam(Pilot *p, int hook_type, const HookParam *param, int nparam)
Tries to run a pilot hook if he has it.
Definition: pilot_hook.c:37
The actual hook parameter.
Definition: hook.h:35
LuaPilot lp
Definition: hook.h:41
const char * str
Definition: hook.h:39
HookParamType type
Definition: hook.h:36
LuaSpob la
Definition: hook.h:43
LuaAsteroid_t ast
Definition: hook.h:45
int ref
Definition: hook.h:46
LuaJump lj
Definition: hook.h:44
double num
Definition: hook.h:38
LuaFaction lf
Definition: hook.h:42
int b
Definition: hook.h:40
Lua jump Wrapper.
Definition: nlua_jump.h:14
The representation of an in-game pilot.
Definition: pilot.h:210