1 #define CBC_ORDER_EXCLUSIVE 3
2 #define CBC_ORDER_FIRST 1
3 #define CBC_ORDER_LAST 2
4 #define CBC_ORDER_ANY 4
6 entity CallbackChain_New(string name);
7 float CallbackChain_Add(entity cb, float() func, float order)
8 float CallbackChain_Remove(entity cb, float() func);
9 // a callback function is like this:
10 // float mycallback(entity me)
15 float CallbackChain_Call(entity cb);
17 #define MUTATOR_REMOVING 0
18 #define MUTATOR_ADDING 1
19 float Mutator_Add(float(float) func);
20 void Mutator_Remove(float(float) func); // calls error() on fail
22 #define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name)
23 #define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name)
24 #define MUTATOR_DEFINITION(name) float MUTATOR_##name(float mode)
25 #define MUTATOR_DECLARATION(name) float MUTATOR_##name(float mode)
26 #define MUTATOR_HOOKFUNCTION(name) float HOOKFUNCTION_##name()
27 #define MUTATOR_HOOK(cb,func,order) do { if(mode == MUTATOR_ADDING) { if(!HOOK_##cb) HOOK_##cb = CallbackChain_New(#cb); if(!CallbackChain_Add(HOOK_##cb,HOOKFUNCTION_##func,order)) { print("HOOK FAILED: ", #func, "\n"); return 1; } } else if(mode == MUTATOR_REMOVING) { if(HOOK_##cb) CallbackChain_Remove(HOOK_##cb,HOOKFUNCTION_##func); } } while(0)
28 #define MUTATOR_ONADD if(mode == MUTATOR_ADDING)
29 #define MUTATOR_ONREMOVE if(mode == MUTATOR_REMOVING)
31 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
32 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
38 // register all possible hooks here
39 MUTATOR_HOOKABLE(MakePlayerObserver);
40 MUTATOR_HOOKABLE(MakePlayerSpectator);
41 MUTATOR_HOOKABLE(PlayerSpawn);
42 MUTATOR_HOOKABLE(ClientDisconnect);
43 MUTATOR_HOOKABLE(PlayerDies); entity other; entity frag_attacker;
44 MUTATOR_HOOKABLE(GiveFragsForKill); entity frag_attacker, frag_target; float frag_score;
45 MUTATOR_HOOKABLE(MatchEnd);
46 MUTATOR_HOOKABLE(GetTeamCount); float ret_float;
47 MUTATOR_HOOKABLE(SpectateCopy); entity other;
48 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
49 MUTATOR_HOOKABLE(SetStartItems);
50 MUTATOR_HOOKABLE(BuildMutatorsString); string ret_string;
51 MUTATOR_HOOKABLE(BuildMutatorsPrettyString); string ret_string;
52 MUTATOR_HOOKABLE(FilterItem); // return error to request removal, or change self.items or self.weapons
53 MUTATOR_HOOKABLE(OnEntityPreSpawn); // return error to prevent entity spawn, or modify the entity
54 MUTATOR_HOOKABLE(PlayerPreThink);
55 MUTATOR_HOOKABLE(GetPressedKeys);
56 MUTATOR_HOOKABLE(PlayerPhysics);