naev 0.11.5
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_SHIP,
25 HOOK_PARAM_OUTFIT,
26 HOOK_PARAM_COMMODITY,
27 HOOK_PARAM_FACTION,
28 HOOK_PARAM_SPOB,
29 HOOK_PARAM_JUMP,
30 HOOK_PARAM_ASTEROID,
31 HOOK_PARAM_REF,
32 HOOK_PARAM_SENTINEL
33} HookParamType;
34
38typedef struct HookParam_s {
39 HookParamType type;
40 union {
41 double num;
42 const char *str;
43 int b;
44 LuaPilot lp;
45 const Ship *ship;
46 const Outfit *outfit;
48 LuaFaction lf;
49 LuaSpob la;
52 int ref;
53 } u;
54} HookParam;
55
56/*
57 * Exclusion.
58 */
59void hook_exclusionStart (void);
60void hook_exclusionEnd( double dt );
61
62/* add/run hooks */
63unsigned int hook_addMisn( unsigned int parent, const char *func, const char *stack );
64unsigned int hook_addEvent( unsigned int parent, const char *func, const char *stack );
65unsigned int hook_addFunc( int (*func)(void*), void *data, const char *stack );
66void hook_rm( unsigned int id );
67void hook_rmMisnParent( unsigned int parent );
68void hook_rmEventParent( unsigned int parent );
69int hook_hasMisnParent( unsigned int parent );
70int hook_hasEventParent( unsigned int parent );
71
72/* pilot hook. Weird dependencies don't let us put it into pilot_hook.h */
73int pilot_runHookParam( Pilot* p, int hook_type, const HookParam *param, int nparam );
74nlua_env hook_env( unsigned int hook );
75
76/*
77 * run hooks
78 *
79 * Currently used:
80 * - General
81 * - "safe" - Runs once each frame at a same time (last in the frame), good place to do breaking stuff.
82 * - "takeoff" - When taking off
83 * - "jumpin" - When player jumps (after changing system)
84 * - "jumpout" - When player jumps (before changing system)
85 * - "time" - When time is increment drastically (hyperspace and taking off)
86 * - "hail" - When any pilot is hailed
87 * - "hail_spob" - When any spob is hailed
88 * - "board" - When any pilot is boarded
89 * - "input" - When an input command is pressed
90 * - "standing" - Whenever faction changes.
91 * - "load" - Run on load.
92 * - "discover" - When something is discovered.
93 * - "pay" - When player receives or loses money.
94 * - Landing
95 * - "land" - When landed
96 * - "outfits" - When visited outfitter
97 * - "shipyard" - When visited shipyard
98 * - "bar" - When visited bar
99 * - "mission" - When visited mission computer
100 * - "commodity" - When visited commodity exchange
101 * - "equipment" - When visiting equipment place < br/>
102 */
103int hooks_runParamDeferred( const char* stack, const HookParam *param );
104int hooks_runParam( const char* stack, const HookParam *param );
105int hooks_run( const char* stack );
106int hook_runIDparam( unsigned int id, const HookParam *param );
107int hook_runID( unsigned int id ); /* runs hook of specific id */
108
109/* Destroys hooks */
110void hook_cleanup (void); /* Frees memory. */
111void hook_clear (void);
112
113/* Timer hooks. */
114void hooks_update( double dt );
115unsigned int hook_addTimerMisn( unsigned int parent, const char *func, double ms );
116unsigned int hook_addTimerEvt( unsigned int parent, const char *func, double ms );
117
118/* Date hooks. */
119void hooks_updateDate( ntime_t change );
120unsigned int hook_addDateMisn( unsigned int parent, const char *func, ntime_t resolution );
121unsigned 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:575
int hook_runIDparam(unsigned int id, const HookParam *param)
Runs a single hook by id.
Definition hook.c:1053
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
Definition hook.c:979
void hook_rmMisnParent(unsigned int parent)
Removes all hooks belonging to parent mission.
Definition hook.c:821
void hooks_update(double dt)
Updates all the hook timer related stuff.
Definition hook.c:738
int hook_runID(unsigned int id)
Runs a single hook by id.
Definition hook.c:1078
int hook_hasEventParent(unsigned int parent)
Checks to see how many hooks there are with the same event parent.
Definition hook.c:862
void hook_clear(void)
Clears the hooks.
Definition hook.c:1136
void hook_cleanup(void)
Gets rid of all current hooks.
Definition hook.c:1116
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:947
nlua_env hook_env(unsigned int hook)
Gets the lua env for a hook.
Definition hook.c:1019
void hooks_updateDate(ntime_t change)
Updates the time to see if it should be updated.
Definition hook.c:647
unsigned int hook_addEvent(unsigned int parent, const char *func, const char *stack)
Adds a new event type hook.
Definition hook.c:531
void hook_rm(unsigned int id)
Removes a hook.
Definition hook.c:798
void hook_exclusionEnd(double dt)
Ends exclusion zone and runs all the queued hooks.
Definition hook.c:198
int hooks_run(const char *stack)
Runs all the hooks of stack.
Definition hook.c:999
void hook_rmEventParent(unsigned int parent)
Removes all hooks belonging to parent event.
Definition hook.c:833
unsigned int hook_addFunc(int(*func)(void *), void *data, const char *stack)
Adds a function hook to be run.
Definition hook.c:594
int hook_hasMisnParent(unsigned int parent)
Checks to see how many hooks there are with the same mission parent.
Definition hook.c:846
void hook_exclusionStart(void)
Starts the hook exclusion zone, this makes hooks queue until exclusion is done.
Definition hook.c:190
unsigned int hook_addTimerMisn(unsigned int parent, const char *func, double ms)
Adds a new mission type hook timer hook.
Definition hook.c:551
unsigned int hook_addMisn(unsigned int parent, const char *func, const char *stack)
Adds a new mission type hook.
Definition hook.c:511
Represents a commodity.
Definition commodity.h:43
The actual hook parameter.
Definition hook.h:38
LuaPilot lp
Definition hook.h:44
const char * str
Definition hook.h:42
HookParamType type
Definition hook.h:39
Commodity * commodity
Definition hook.h:47
LuaSpob la
Definition hook.h:49
LuaAsteroid_t ast
Definition hook.h:51
const Outfit * outfit
Definition hook.h:46
int ref
Definition hook.h:52
LuaJump lj
Definition hook.h:50
double num
Definition hook.h:41
const Ship * ship
Definition hook.h:45
LuaFaction lf
Definition hook.h:48
int b
Definition hook.h:43
Lua jump Wrapper.
Definition nlua_jump.h:14
A ship outfit, depends radically on the type.
Definition outfit.h:328
The representation of an in-game pilot.
Definition pilot.h:217
Represents a space ship.
Definition ship.h:94