]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/base.qh
Merge remote branch 'origin/fruitiex/fruitbalance' into divVerent/forced-teams-by...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / base.qh
1 #define CBC_ORDER_EXCLUSIVE 3
2 #define CBC_ORDER_FIRST 1
3 #define CBC_ORDER_LAST 2
4 #define CBC_ORDER_ANY 4
5
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)
11 // {
12 //   do something
13 //   return r;
14 // }
15 float CallbackChain_Call(entity cb);
16
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
21
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)
30
31 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
32 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
33
34
35
36
37
38 // register all possible hooks here
39
40 MUTATOR_HOOKABLE(MakePlayerObserver);
41         // called when a player becomes observer, after shared setup
42
43 MUTATOR_HOOKABLE(PlayerSpawn);
44         // called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here)
45
46 MUTATOR_HOOKABLE(ClientDisconnect);
47         // called when a player disconnects
48
49 MUTATOR_HOOKABLE(PlayerDies);
50         // called when a player dies to e.g. remove stuff he was carrying.
51         // INPUT:
52                 entity frag_inflictor;
53                 entity frag_attacker;
54                 entity frag_target; // same as self
55
56 MUTATOR_HOOKABLE(GiveFragsForKill);
57         // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
58         // INPUT:
59                 entity frag_attacker; // same as self
60                 entity frag_target;
61         // INPUT, OUTPUT:
62                 float frag_score;
63
64 MUTATOR_HOOKABLE(MatchEnd);
65         // called when the match ends
66
67 MUTATOR_HOOKABLE(GetTeamCount);
68         // should adjust ret_float to contain the team count
69         // INPUT, OUTPUT:
70                 float ret_float;
71
72 MUTATOR_HOOKABLE(SpectateCopy);
73         // copies variables for spectating "other" to "self"
74         // INPUT:
75                 entity other;
76
77 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
78         // returns 1 if throwing the current weapon shall not be allowed
79
80 MUTATOR_HOOKABLE(SetStartItems);
81         // adjusts {warmup_}start_{items,weapons,ammo_{cells,rockets,nails,shells,fuel}}
82
83 MUTATOR_HOOKABLE(BuildMutatorsString);
84         // appends ":mutatorname" to ret_string for logging
85         // INPUT, OUTPUT:
86                 string ret_string;
87
88 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
89         // appends ", Mutator name" to ret_string for display
90         // INPUT, OUTPUT:
91                 string ret_string;
92
93 MUTATOR_HOOKABLE(FilterItem);
94         // checks if the current item may be spawned (self.items and self.weapons may be read and written to, as well as the ammo_ fields)
95         // return error to request removal
96
97 MUTATOR_HOOKABLE(OnEntityPreSpawn);
98         // return error to prevent entity spawn, or modify the entity
99
100 MUTATOR_HOOKABLE(PlayerPreThink);
101         // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
102
103 MUTATOR_HOOKABLE(GetPressedKeys);
104         // TODO change this into a general PlayerPostThink hook?
105
106 MUTATOR_HOOKABLE(PlayerPhysics);
107         // called before any player physics, may adjust variables for movement,
108         // is run AFTER bot code and idle checking
109
110 MUTATOR_HOOKABLE(GetCvars);
111         // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
112         // INPUT:
113                 float get_cvars_f;
114                 string get_cvars_s;
115
116 MUTATOR_HOOKABLE(EditProjectile);
117         // can edit any "just fired" projectile
118         // INPUT:
119                 entity self;
120                 entity other;
121
122 MUTATOR_HOOKABLE(PlayerDamage);
123         // called when a player gets damaged to e.g. remove stuff he was carrying.
124         // INPUT:
125                 entity frag_inflictor;
126                 entity frag_attacker;
127                 entity frag_target; // same as self
128                 vector damage_force; // NOTE: this force already HAS been applied (create and use a Damage hook to change that one)
129         // INPUT, OUTPUT:
130                 float damage_take;
131                 float damage_save;