blob: 928514e52b182c3c51287735a5a084f6a8ff6917 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// /sys/hooks.h - Hooksystem
4//
5// $Id: hook.h 9475 2016-02-19 21:16:17Z Zesstra $
6
7#ifndef _HOOKS_H_
8#define _HOOKS_H_
9
10// global hooks
11#define H_HOOK_MOVE 1
12#define H_HOOK_DIE 2
13#define H_HOOK_DEFEND 3
14#define H_HOOK_ATTACK 4
15#define H_HOOK_HP 5
16#define H_HOOK_SP 6
17#define H_HOOK_ATTACK_MOD 7
18#define H_HOOK_ALCOHOL 8
19#define H_HOOK_FOOD 9
20#define H_HOOK_DRINK 10
21#define H_HOOK_POISON 11
22#define H_HOOK_CONSUME 12
23#define H_HOOK_TEAMROWCHANGE 13
24#define H_HOOK_INSERT 14
25#define H_HOOK_EXIT_USE 15
Zesstra@Morgengrauen0f34a7e2016-10-30 22:33:25 +010026#define H_HOOK_INIT 16
MG Mud User88f12472016-06-24 23:31:02 +020027
28// the possible consumer types
29#define H_HOOK_SURVEYOR 0
30#define H_HOOK_MODIFICATOR 1
31#define H_DATA_MODIFICATOR 2
32#define H_LISTENER 3
33#define H_CONSUMERCHECK(x) ((intp(x)&& x>=0 && x<=H_LISTENER)?x:-1)
34#define H_CONSUMERNAMES ({"surveyors","hmods","dmods","listeners"})
35
36// priorities
37#define H_HOOK_PRIORITYRANGE 3
38#define H_HOOK_LIBBASEPRIO 0
39#define H_HOOK_GUILDBASEPRIO (H_HOOK_LIBBASEPRIO+H_HOOK_PRIORITYRANGE)
40#define H_HOOK_OTHERBASEPRIO (H_HOOK_GUILDBASEPRIO+H_HOOK_PRIORITYRANGE)
41#define H_HOOK_PRIOCHECK(x) ((intp(x) && x>=0 && x<H_HOOK_PRIORITYRANGE)?x:-1)
42#define H_HOOK_LIBPRIO(x) ((H_HOOK_PRIOCHECK(x)!=-1)?(H_HOOK_LIBBASEPRIO+x):-1)
43#define H_HOOK_GUILDPRIO(x) ((H_HOOK_PRIOCHECK(x)!=-1)?(H_HOOK_GUILDBASEPRIO+x):-1)
44#define H_HOOK_OTHERPRIO(x) ((H_HOOK_PRIOCHECK(x)!=-1)?(H_HOOK_OTHERBASEPRIO+x):-1)
45#define H_HOOK_VALIDPRIO(x) ((intp(x) && x>=0 && x<(H_HOOK_OTHERBASEPRIO+H_HOOK_PRIORITYRANGE))?x:-1)
46
47// maximum consumer per type
48#define MAX_SURVEYOR 1
49#define MAX_HOOK_MODIFICATOR 2
50#define MAX_DATA_MODIFICATOR 3
51#define MAX_LISTENER 5
52#define MAX_HOOK_COUNTS ({MAX_SURVEYOR, MAX_HOOK_MODIFICATOR, \
53 MAX_DATA_MODIFICATOR, MAX_LISTENER, \
54 })
55
56// data indices for return value of HookCallback() & Co.
57#define H_RETCODE 0
58#define H_RETDATA 1
59
60// return codes for HookFlow & Co.
61#define H_NO_MOD 0
62#define H_CANCELLED 1
63#define H_ALTERED 2
64
65// debugging
66#define H_DMSG(x) (h_dbg() && (find_player("zesstra")) ? \
67 tell_object(find_player("zesstra"),x):0)
68
69#endif //_HOOKS_H_
70
71// prototypes
72#ifdef NEED_PROTOTYPES
73// provider
74#ifndef __HOOK_PROVIDER_PROTO
75#define __HOOK_PROVIDER_PROTO
76
77// list of offered hooks
78int* HListHooks();
79
80// register to hook
Bugfix15229482022-10-06 11:41:13 +020081int HRegisterToHook(int hookid, object|closure consumer, int hookprio,
MG Mud User88f12472016-06-24 23:31:02 +020082 int consumertype, int timeInSeconds);
83
84// unregister from hook
Bugfix15229482022-10-06 11:41:13 +020085int HUnregisterFromHook(int hookid, object|closure consumer);
MG Mud User88f12472016-06-24 23:31:02 +020086
87// check wether object is a consumer for a given hook
Bugfix15229482022-10-06 11:41:13 +020088int HIsHookConsumer(int hookid, object|closure consumer);
MG Mud User88f12472016-06-24 23:31:02 +020089
90// offer a hook or stop offering it
91protected void offerHook(int hookid, int offerstate);
92
93// trigger a hook
94protected mixed HookFlow(int hookid, mixed hookdata);
95
96#endif // __HOOK_PROVIDER_PROTO
97#endif // NEED_PROTOTYPES