naev 0.12.5
hook.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include "nlua_asteroid.h"
7#include "nlua_faction.h"
8#include "nlua_jump.h"
9#include "nlua_pilot.h"
10#include "nlua_spob.h"
11#include "nlua_system.h"
12
13#define HOOK_MAX_PARAM \
14 7
15
19typedef enum HookParamType_e {
20 HOOK_PARAM_NIL,
21 HOOK_PARAM_NUMBER,
22 HOOK_PARAM_STRING,
23 HOOK_PARAM_BOOL,
24 HOOK_PARAM_PILOT,
25 HOOK_PARAM_SHIP,
26 HOOK_PARAM_OUTFIT,
27 HOOK_PARAM_COMMODITY,
28 HOOK_PARAM_FACTION,
29 HOOK_PARAM_SSYS,
30 HOOK_PARAM_SPOB,
31 HOOK_PARAM_JUMP,
32 HOOK_PARAM_ASTEROID,
33 HOOK_PARAM_REF,
34 HOOK_PARAM_SENTINEL
35} HookParamType;
36
40typedef struct HookParam_s {
41 HookParamType type;
42 union {
43 double num;
44 const char *str;
45 int b;
46 LuaPilot lp;
47 const Ship *ship;
48 const Outfit *outfit;
50 LuaFaction lf;
51 LuaSystem ls;
52 LuaSpob la;
55 int ref;
56 } u;
57} HookParam;
58
59/*
60 * Exclusion.
61 */
62void hook_exclusionStart( void );
63void hook_exclusionEnd( double dt );
64
65/* add/run hooks */
66unsigned int hook_addMisn( unsigned int parent, const char *func,
67 const char *stack );
68unsigned int hook_addEvent( unsigned int parent, const char *func,
69 const char *stack );
70unsigned int hook_addFunc( int ( *func )( void * ), void *data,
71 const char *stack );
72void hook_rm( unsigned int id );
73void hook_rmMisnParent( unsigned int parent );
74void hook_rmEventParent( unsigned int parent );
75int hook_hasMisnParent( unsigned int parent );
76int hook_hasEventParent( unsigned int parent );
77
78/* pilot hook. Weird dependencies don't let us put it into pilot_hook.h */
79int pilot_runHookParam( Pilot *p, int hook_type, const HookParam *param,
80 int nparam );
81nlua_env hook_env( unsigned int hook );
82
83/*
84 * run hooks
85 *
86 * Currently used:
87 * - General
88 * - "safe" - Runs once each frame at a same time (last in the frame), good
89 * place to do breaking stuff.
90 * - "takeoff" - When taking off
91 * - "jumpin" - When player jumps (after changing system)
92 * - "jumpout" - When player jumps (before changing system)
93 * - "time" - When time is increment drastically (hyperspace and taking off)
94 * - "hail" - When any pilot is hailed
95 * - "hail_spob" - When any spob is hailed
96 * - "board" - When any pilot is boarded
97 * - "input" - When an input command is pressed
98 * - "standing" - Whenever faction changes.
99 * - "load" - Run on load.
100 * - "discover" - When something is discovered.
101 * - "pay" - When player receives or loses money.
102 * - Landing
103 * - "land" - When landed
104 * - "outfits" - When visited outfitter
105 * - "shipyard" - When visited shipyard
106 * - "bar" - When visited bar
107 * - "mission" - When visited mission computer
108 * - "commodity" - When visited commodity exchange
109 * - "equipment" - When visiting equipment place < br/>
110 */
111int hooks_runParamDeferred( const char *stack, const HookParam *param );
112int hooks_runParam( const char *stack, const HookParam *param );
113int hooks_run( const char *stack );
114int hook_runIDparam( unsigned int id, const HookParam *param );
115int hook_runID( unsigned int id ); /* runs hook of specific id */
116
117/* Destroys hooks */
118void hook_cleanup( void ); /* Frees memory. */
119void hook_clear( void );
120void hook_clearMissionTimers( unsigned int parent );
121void hook_clearEventTimers( unsigned int parent );
122
123/* Timer hooks. */
124void hooks_update( double dt );
125unsigned int hook_addTimerMisn( unsigned int parent, const char *func,
126 double ms );
127unsigned int hook_addTimerEvt( unsigned int parent, const char *func,
128 double ms );
129unsigned int hook_addTimerFunc( int ( *func )( void * ), void *data,
130 double ms );
131
132/* Date hooks. */
133void hooks_updateDate( ntime_t change );
134unsigned int hook_addDateMisn( unsigned int parent, const char *func,
135 ntime_t resolution );
136unsigned int hook_addDateEvt( unsigned int parent, const char *func,
137 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:596
int hook_runIDparam(unsigned int id, const HookParam *param)
Runs a single hook by id.
Definition hook.c:1103
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
Definition hook.c:1029
void hook_rmMisnParent(unsigned int parent)
Removes all hooks belonging to parent mission.
Definition hook.c:869
void hooks_update(double dt)
Updates all the hook timer related stuff.
Definition hook.c:785
int hook_runID(unsigned int id)
Runs a single hook by id.
Definition hook.c:1129
unsigned int hook_addTimerFunc(int(*func)(void *), void *data, double ms)
Adds a function hook to be run.
Definition hook.c:616
int hook_hasEventParent(unsigned int parent)
Checks to see how many hooks there are with the same event parent.
Definition hook.c:910
void hook_clear(void)
Clears the hooks.
Definition hook.c:1187
void hook_cleanup(void)
Gets rid of all current hooks.
Definition hook.c:1167
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:996
nlua_env hook_env(unsigned int hook)
Gets the lua env for a hook.
Definition hook.c:1069
void hooks_updateDate(ntime_t change)
Updates the time to see if it should be updated.
Definition hook.c:688
unsigned int hook_addEvent(unsigned int parent, const char *func, const char *stack)
Adds a new event type hook.
Definition hook.c:550
void hook_rm(unsigned int id)
Removes a hook.
Definition hook.c:846
void hook_clearEventTimers(unsigned int parent)
Clears the timer hooks for an event.
Definition hook.c:1212
void hook_exclusionEnd(double dt)
Ends exclusion zone and runs all the queued hooks.
Definition hook.c:199
int hooks_run(const char *stack)
Runs all the hooks of stack.
Definition hook.c:1049
void hook_rmEventParent(unsigned int parent)
Removes all hooks belonging to parent event.
Definition hook.c:881
unsigned int hook_addFunc(int(*func)(void *), void *data, const char *stack)
Adds a function hook to be run.
Definition hook.c:634
int hook_hasMisnParent(unsigned int parent)
Checks to see how many hooks there are with the same mission parent.
Definition hook.c:894
void hook_exclusionStart(void)
Starts the hook exclusion zone, this makes hooks queue until exclusion is done.
Definition hook.c:191
unsigned int hook_addTimerMisn(unsigned int parent, const char *func, double ms)
Adds a new mission type hook timer hook.
Definition hook.c:571
unsigned int hook_addMisn(unsigned int parent, const char *func, const char *stack)
Adds a new mission type hook.
Definition hook.c:529
void hook_clearMissionTimers(unsigned int parent)
Clears the timer hooks for a mission.
Definition hook.c:1199
Represents a commodity.
Definition commodity.h:57
The actual hook parameter.
Definition hook.h:40
LuaPilot lp
Definition hook.h:46
const char * str
Definition hook.h:44
LuaSystem ls
Definition hook.h:51
HookParamType type
Definition hook.h:41
Commodity * commodity
Definition hook.h:49
LuaSpob la
Definition hook.h:52
LuaAsteroid_t ast
Definition hook.h:54
const Outfit * outfit
Definition hook.h:48
int ref
Definition hook.h:55
LuaJump lj
Definition hook.h:53
double num
Definition hook.h:43
const Ship * ship
Definition hook.h:47
LuaFaction lf
Definition hook.h:50
int b
Definition hook.h:45
Lua jump Wrapper.
Definition nlua_jump.h:14
A ship outfit, depends radically on the type.
Definition outfit.h:372
The representation of an in-game pilot.
Definition pilot.h:263
Represents a space ship.
Definition ship.h:97