1 /*
2  * See Licensing and Copyright notice in naev.h
3  */
4 
5 
6 #ifndef HOOK_H
7 #  define HOOK_H
8 
9 
10 #include "mission.h"
11 
12 #include "nlua_pilot.h"
13 #include "nlua_faction.h"
14 #include "nlua_planet.h"
15 #include "nlua_jump.h"
16 
17 
18 #define HOOK_MAX_PARAM  3 /**< Maximum hook params, to avoid dynamic allocation. */
19 
20 
21 /**
22  * @Brief The hook parameter types.
23  */
24 typedef enum HookParamType_e {
25    HOOK_PARAM_NIL, /**< No hook parameter. */
26    HOOK_PARAM_NUMBER, /**< Number parameter. */
27    HOOK_PARAM_STRING, /**< String parameter. */
28    HOOK_PARAM_BOOL, /**< Boolean parameter. */
29    HOOK_PARAM_PILOT, /**< Pilot hook parameter. */
30    HOOK_PARAM_FACTION, /**< Faction hook parameter. */
31    HOOK_PARAM_ASSET, /**< Asset hook parameter. */
32    HOOK_PARAM_JUMP, /**< Jump point hook parameter. */
33    HOOK_PARAM_SENTINEL /**< Enum sentinel. */
34 } HookParamType;
35 
36 /**
37  * @brief The actual hook parameter.
38  */
39 typedef struct HookParam_s {
40    HookParamType type; /**< Type of parameter. */
41    union {
42       double num; /**< Number parameter. */
43       const char *str; /**< String parameter. */
44       int b; /**< Boolean parameter. */
45       LuaPilot lp; /**< Hook parameter pilot data. */
46       LuaFaction lf; /**< Hook parameter faction data. */
47       LuaPlanet la; /**< Hook parameter planet data. */
48       LuaJump lj; /**< Hook parameter jump data. */
49    } u; /**< Hook parameter data. */
50 } HookParam;
51 
52 /*
53  * Exclusion.
54  */
55 void hook_exclusionStart (void);
56 void hook_exclusionEnd( double dt );
57 
58 /* add/run hooks */
59 unsigned int hook_addMisn( unsigned int parent, const char *func, const char *stack );
60 unsigned int hook_addEvent( unsigned int parent, const char *func, const char *stack );
61 unsigned int hook_addFunc( int (*func)(void*), void* data, const char *stack );
62 void hook_rm( unsigned int id );
63 void hook_rmMisnParent( unsigned int parent );
64 void hook_rmEventParent( unsigned int parent );
65 int hook_hasMisnParent( unsigned int parent );
66 int hook_hasEventParent( unsigned int parent );
67 
68 /* pilot hook. */
69 int pilot_runHookParam( Pilot* p, int hook_type, HookParam *param, int nparam );
70 
71 nlua_env hook_env( unsigned int hook );
72 
73 /*
74  * run hooks
75  *
76  * Currently used:
77  *  - General
78  *    - "safe" - Runs once each frame at a same time (last in the frame), good place to do breaking stuff.
79  *    - "takeoff" - When taking off
80  *    - "jumpin" - When player jumps (after changing system)
81  *    - "jumpout" - When player jumps (before changing system)
82  *    - "time" - When time is increment drastically (hyperspace and taking off)
83  *    - "hail" - When any pilot is hailed
84  *    - "board" - When any pilot is boarded
85  *    - "input" - When an input command is pressed
86  *    - "standing" - Whenever faction changes.
87  *    - "load" - Run on load.
88  *    - "discover" - When something is discovered.
89  *  - Landing
90  *    - "land" - When landed
91  *    - "outfits" - When visited outfitter
92  *    - "shipyard" - When visited shipyard
93  *    - "bar" - When visited bar
94  *    - "mission" - When visited mission computer
95  *    - "commodity" - When visited commodity exchange
96  *    - "equipment" - When visiting equipment place < br/>
97  */
98 int hooks_runParam( const char* stack, HookParam *param );
99 int hooks_run( const char* stack );
100 int hook_runIDparam( unsigned int id, HookParam *param );
101 int hook_runID( unsigned int id ); /* runs hook of specific id */
102 
103 /* destroys hooks */
104 void hook_cleanup (void);
105 
106 /* Timer hooks. */
107 void hooks_update( double dt );
108 unsigned int hook_addTimerMisn( unsigned int parent, const char *func, double ms );
109 unsigned int hook_addTimerEvt( unsigned int parent, const char *func, double ms );
110 
111 /* Date hooks. */
112 void hooks_updateDate( ntime_t change );
113 unsigned int hook_addDateMisn( unsigned int parent, const char *func, ntime_t resolution );
114 unsigned int hook_addDateEvt( unsigned int parent, const char *func, ntime_t resolution );
115 
116 
117 #endif /* HOOK_H */
118 
119