]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/base.qh
Make player code more generic by detecting after the mutator hook PlayerDies if the...
[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 float CallbackChain_ReturnValue; // read-only field of the current return value
7
8 entity CallbackChain_New(string name);
9 float CallbackChain_Add(entity cb, float() func, float order)
10 float CallbackChain_Remove(entity cb, float() func);
11 // a callback function is like this:
12 // float mycallback(entity me)
13 // {
14 //   do something
15 //   return r;
16 // }
17 float CallbackChain_Call(entity cb);
18
19 #define MUTATOR_REMOVING 0
20 #define MUTATOR_ADDING 1
21 typedef float(float) mutatorfunc_t;
22 float Mutator_Add(mutatorfunc_t func, string name);
23 void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
24
25 #define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name, #name)
26 #define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name, #name)
27 #define MUTATOR_DEFINITION(name) float MUTATOR_##name(float mode)
28 #define MUTATOR_DECLARATION(name) float MUTATOR_##name(float mode)
29 #define MUTATOR_HOOKFUNCTION(name) float HOOKFUNCTION_##name()
30 #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)
31 #define MUTATOR_ONADD if(mode == MUTATOR_ADDING)
32 #define MUTATOR_ONREMOVE if(mode == MUTATOR_REMOVING)
33
34 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
35 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
36
37 #define MUTATOR_RETURNVALUE CallbackChain_ReturnValue
38
39
40
41
42 // register all possible hooks here
43
44 MUTATOR_HOOKABLE(MakePlayerObserver);
45         // called when a player becomes observer, after shared setup
46
47 MUTATOR_HOOKABLE(PlayerSpawn);
48         entity spawn_spot; // spot that was used, or world
49         // called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here)
50
51 MUTATOR_HOOKABLE(ClientDisconnect);
52         // called when a player disconnects
53
54 MUTATOR_HOOKABLE(PlayerDies);
55         // called when a player dies to e.g. remove stuff he was carrying.
56         // INPUT:
57                 entity frag_inflictor;
58                 entity frag_attacker;
59                 entity frag_target; // same as self
60                 float frag_deathtype;
61
62 MUTATOR_HOOKABLE(GiveFragsForKill);
63         // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
64         // INPUT:
65                 entity frag_attacker; // same as self
66                 entity frag_target;
67         // INPUT, OUTPUT:
68                 float frag_score;
69
70 MUTATOR_HOOKABLE(MatchEnd);
71         // called when the match ends
72
73 MUTATOR_HOOKABLE(GetTeamCount);
74         // should adjust ret_float to contain the team count
75         // INPUT, OUTPUT:
76                 float ret_float;
77
78 MUTATOR_HOOKABLE(SpectateCopy);
79         // copies variables for spectating "other" to "self"
80         // INPUT:
81                 entity other;
82
83 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
84         // returns 1 if throwing the current weapon shall not be allowed
85
86 MUTATOR_HOOKABLE(SetStartItems);
87         // adjusts {warmup_}start_{items,weapons,ammo_{cells,rockets,nails,shells,fuel}}
88
89 MUTATOR_HOOKABLE(BuildMutatorsString);
90         // appends ":mutatorname" to ret_string for logging
91         // INPUT, OUTPUT:
92                 string ret_string;
93
94 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
95         // appends ", Mutator name" to ret_string for display
96         // INPUT, OUTPUT:
97                 string ret_string;
98
99 MUTATOR_HOOKABLE(FilterItem);
100         // 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)
101         // return error to request removal
102
103 MUTATOR_HOOKABLE(TurretSpawn);
104         // return error to request removal
105         // INPUT: self - turret
106         
107 MUTATOR_HOOKABLE(OnEntityPreSpawn);
108         // return error to prevent entity spawn, or modify the entity
109
110 MUTATOR_HOOKABLE(PlayerPreThink);
111         // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
112
113 MUTATOR_HOOKABLE(GetPressedKeys);
114         // TODO change this into a general PlayerPostThink hook?
115
116 MUTATOR_HOOKABLE(PlayerPhysics);
117         // called before any player physics, may adjust variables for movement,
118         // is run AFTER bot code and idle checking
119
120 MUTATOR_HOOKABLE(GetCvars);
121         // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
122         // INPUT:
123                 float get_cvars_f;
124                 string get_cvars_s;
125
126 MUTATOR_HOOKABLE(EditProjectile);
127         // can edit any "just fired" projectile
128         // INPUT:
129                 entity self;
130                 entity other;
131
132 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
133         // called when a player gets damaged to e.g. remove stuff he was carrying.
134         // INPUT:
135                 entity frag_inflictor;
136                 entity frag_attacker;
137                 entity frag_target; // same as self
138                 vector damage_force; // NOTE: this force already HAS been applied
139         // INPUT, OUTPUT:
140                 float damage_take;
141                 float damage_save;
142                 
143 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
144         // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier or runematch runes
145         // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
146         // INPUT:
147                 entity frag_attacker;
148                 entity frag_target;
149                 float frag_deathtype;
150         // INPUT, OUTPUT:
151                 float frag_damage;
152                 vector frag_force;
153
154 MUTATOR_HOOKABLE(PlayerPowerups);
155         // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
156         // INPUT
157         entity self;
158         float olditems; // also technically output, but since it is at the end of the function it's useless for that :P 
159
160 MUTATOR_HOOKABLE(PlayerUseKey);
161         // called when the use key is pressed
162         // if MUTATOR_RETURNVALUE is 1, don't do anything
163         // return 1 if the use key actually did something
164
165 MUTATOR_HOOKABLE(SV_ParseClientCommand);
166         // called when a client command is parsed
167         // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
168         // NOTE: return 1 if you handled the command, return 0 to continue handling
169         // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
170         // INPUT
171         string cmd_name; // command name
172         float cmd_argc; // also, argv() can be used
173         string cmd_string; // whole command, use only if you really have to
174         /*
175                 // example:
176                 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
177                 {
178                         if(MUTATOR_RETURNVALUE) // command was already handled?
179                                 return 0;
180                         if(cmd_name == "echocvar" && cmd_argc >= 2)
181                         {
182                                 print(cvar_string(argv(1)), "\n");
183                                 return 1;
184                         }
185                         if(cmd_name == "echostring" && cmd_argc >= 2)
186                         {
187                                 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
188                                 return 1;
189                         }
190                         return 0;
191                 }
192         */
193
194 MUTATOR_HOOKABLE(Spawn_Score);
195         // called when a spawnpoint is being evaluated
196         // return 1 to make the spawnpoint unusable
197         // INPUT
198         entity self; // player wanting to spawn
199         entity spawn_spot; // spot to be evaluated
200         // IN+OUT
201         vector spawn_score; // _x is priority, _y is "distance"
202
203 MUTATOR_HOOKABLE(SV_StartFrame);
204         // runs globally each server frame
205
206 MUTATOR_HOOKABLE(SetModname);
207         // OUT
208         string modname; // name of the mutator/mod if it warrants showing as such in the server browser
209
210 MUTATOR_HOOKABLE(SetWeaponreplace);
211         // IN
212                 entity self; // map entity
213                 entity other; // weapon info
214         // IN+OUT
215                 string ret_string;
216
217 MUTATOR_HOOKABLE(PortalTeleport);
218         // called whenever a player goes through a portal gun teleport
219         // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
220         // INPUT
221         entity self;
222         
223 MUTATOR_HOOKABLE(HelpMePing);
224         // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
225         // normally help me ping uses self.waypointsprite_attachedforcarrier,
226         // but if your mutator uses something different then you can handle it
227         // in a special manner using this hook
228         // INPUT
229         entity self; // the player who pressed impulse 33
230         
231 MUTATOR_HOOKABLE(VehicleEnter);
232         // called when a player enters a vehicle
233         // allows mutators to set special settings in this event
234         // INPUT
235         entity vh_player; // player
236         entity vh_vehicle; // vehicle
237         
238 MUTATOR_HOOKABLE(VehicleExit);
239         // called when a player exits a vehicle
240         // allows mutators to set special settings in this event
241         // INPUT
242         entity vh_player; // player
243         entity vh_vehicle; // vehicle
244         
245 MUTATOR_HOOKABLE(AbortSpeedrun);
246         // called when a speedrun is aborted and the player is teleported back to start position
247         // INPUT
248         entity self; // player
249
250 MUTATOR_HOOKABLE(ItemTouch);
251         // called at when a item is touched. Called early, can edit item properties.
252         entity self;    // item
253         entity other;   // player
254
255 MUTATOR_HOOKABLE(ClientConnect);
256         // called at when a player connect
257         entity self;    // player
258
259 MUTATOR_HOOKABLE(HavocBot_ChooseRule);
260         entity self;