MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // 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 |
| 26 | |
| 27 | // the possible consumer types |
| 28 | #define H_HOOK_SURVEYOR 0 |
| 29 | #define H_HOOK_MODIFICATOR 1 |
| 30 | #define H_DATA_MODIFICATOR 2 |
| 31 | #define H_LISTENER 3 |
| 32 | #define H_CONSUMERCHECK(x) ((intp(x)&& x>=0 && x<=H_LISTENER)?x:-1) |
| 33 | #define H_CONSUMERNAMES ({"surveyors","hmods","dmods","listeners"}) |
| 34 | |
| 35 | // priorities |
| 36 | #define H_HOOK_PRIORITYRANGE 3 |
| 37 | #define H_HOOK_LIBBASEPRIO 0 |
| 38 | #define H_HOOK_GUILDBASEPRIO (H_HOOK_LIBBASEPRIO+H_HOOK_PRIORITYRANGE) |
| 39 | #define H_HOOK_OTHERBASEPRIO (H_HOOK_GUILDBASEPRIO+H_HOOK_PRIORITYRANGE) |
| 40 | #define H_HOOK_PRIOCHECK(x) ((intp(x) && x>=0 && x<H_HOOK_PRIORITYRANGE)?x:-1) |
| 41 | #define H_HOOK_LIBPRIO(x) ((H_HOOK_PRIOCHECK(x)!=-1)?(H_HOOK_LIBBASEPRIO+x):-1) |
| 42 | #define H_HOOK_GUILDPRIO(x) ((H_HOOK_PRIOCHECK(x)!=-1)?(H_HOOK_GUILDBASEPRIO+x):-1) |
| 43 | #define H_HOOK_OTHERPRIO(x) ((H_HOOK_PRIOCHECK(x)!=-1)?(H_HOOK_OTHERBASEPRIO+x):-1) |
| 44 | #define H_HOOK_VALIDPRIO(x) ((intp(x) && x>=0 && x<(H_HOOK_OTHERBASEPRIO+H_HOOK_PRIORITYRANGE))?x:-1) |
| 45 | |
| 46 | // maximum consumer per type |
| 47 | #define MAX_SURVEYOR 1 |
| 48 | #define MAX_HOOK_MODIFICATOR 2 |
| 49 | #define MAX_DATA_MODIFICATOR 3 |
| 50 | #define MAX_LISTENER 5 |
| 51 | #define MAX_HOOK_COUNTS ({MAX_SURVEYOR, MAX_HOOK_MODIFICATOR, \ |
| 52 | MAX_DATA_MODIFICATOR, MAX_LISTENER, \ |
| 53 | }) |
| 54 | |
| 55 | // data indices for return value of HookCallback() & Co. |
| 56 | #define H_RETCODE 0 |
| 57 | #define H_RETDATA 1 |
| 58 | |
| 59 | // return codes for HookFlow & Co. |
| 60 | #define H_NO_MOD 0 |
| 61 | #define H_CANCELLED 1 |
| 62 | #define H_ALTERED 2 |
| 63 | |
| 64 | // debugging |
| 65 | #define H_DMSG(x) (h_dbg() && (find_player("zesstra")) ? \ |
| 66 | tell_object(find_player("zesstra"),x):0) |
| 67 | |
| 68 | #endif //_HOOKS_H_ |
| 69 | |
| 70 | // prototypes |
| 71 | #ifdef NEED_PROTOTYPES |
| 72 | // provider |
| 73 | #ifndef __HOOK_PROVIDER_PROTO |
| 74 | #define __HOOK_PROVIDER_PROTO |
| 75 | |
| 76 | // list of offered hooks |
| 77 | int* HListHooks(); |
| 78 | |
| 79 | // register to hook |
| 80 | int HRegisterToHook(int hookid, mixed consumer, int hookprio, |
| 81 | int consumertype, int timeInSeconds); |
| 82 | |
| 83 | // unregister from hook |
| 84 | int HUnregisterFromHook(int hookid, mixed consumer); |
| 85 | |
| 86 | // check wether object is a consumer for a given hook |
| 87 | int HIsHookConsumer(int hookid, mixed consumer); |
| 88 | |
| 89 | // offer a hook or stop offering it |
| 90 | protected void offerHook(int hookid, int offerstate); |
| 91 | |
| 92 | // trigger a hook |
| 93 | protected mixed HookFlow(int hookid, mixed hookdata); |
| 94 | |
| 95 | #endif // __HOOK_PROVIDER_PROTO |
| 96 | #endif // NEED_PROTOTYPES |