]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/base.qh
Merge branch 'maint' of https://gitlab.com/xonotic/xonotic-data.pk3dir into maint
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / base.qh
1 #ifndef MUTATORS_BASE_H
2 #define MUTATORS_BASE_H
3 const float CBC_ORDER_EXCLUSIVE = 3;
4 const float CBC_ORDER_FIRST = 1;
5 const float CBC_ORDER_LAST = 2;
6 const float CBC_ORDER_ANY = 4;
7
8 float CallbackChain_ReturnValue; // read-only field of the current return value
9
10 entity CallbackChain_New(string name);
11 float CallbackChain_Add(entity cb, float() func, float order);
12 float CallbackChain_Remove(entity cb, float() func);
13 // a callback function is like this:
14 // float mycallback(entity me)
15 // {
16 //   do something
17 //   return r;
18 // }
19 float CallbackChain_Call(entity cb);
20
21 const float MUTATOR_REMOVING = 0;
22 const float MUTATOR_ADDING = 1;
23 const float MUTATOR_ROLLING_BACK = 2;
24 typedef float(float) mutatorfunc_t;
25 float Mutator_Add(mutatorfunc_t func, string name);
26 void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
27
28 #define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name, #name)
29 #define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name, #name)
30 #define MUTATOR_DEFINITION(name) float MUTATOR_##name(float mode)
31 #define MUTATOR_DECLARATION(name) float MUTATOR_##name(float mode)
32 #define MUTATOR_HOOKFUNCTION(name) float HOOKFUNCTION_##name()
33 #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 || mode == MUTATOR_ROLLING_BACK) { if(HOOK_##cb) CallbackChain_Remove(HOOK_##cb,HOOKFUNCTION_##func); } } while(0)
34 #define MUTATOR_ONADD if(mode == MUTATOR_ADDING)
35 #define MUTATOR_ONREMOVE if(mode == MUTATOR_REMOVING)
36 #define MUTATOR_ONROLLBACK_OR_REMOVE if(mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
37
38 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
39 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
40
41 #define MUTATOR_RETURNVALUE CallbackChain_ReturnValue
42
43
44
45
46 // register all possible hooks here
47 // some parameters are commented to avoid duplicate declarations
48
49 MUTATOR_HOOKABLE(MakePlayerObserver);
50         // called when a player becomes observer, after shared setup
51
52 MUTATOR_HOOKABLE(PutClientInServer);
53 //      entity self; // client wanting to spawn
54
55 MUTATOR_HOOKABLE(PlayerSpawn);
56         entity spawn_spot; // spot that was used, or world
57         // called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here)
58
59 MUTATOR_HOOKABLE(reset_map_global);
60         // called in reset_map
61
62 MUTATOR_HOOKABLE(reset_map_players);
63         // called in reset_map
64
65 MUTATOR_HOOKABLE(ForbidPlayerScore_Clear);
66         // returns 1 if clearing player score shall not be allowed
67
68 MUTATOR_HOOKABLE(ClientDisconnect);
69         // called when a player disconnects
70
71 MUTATOR_HOOKABLE(PlayerDies);
72         // called when a player dies to e.g. remove stuff he was carrying.
73         // INPUT:
74                 entity frag_inflictor;
75                 entity frag_attacker;
76                 entity frag_target; // same as self
77                 float frag_deathtype;
78
79 MUTATOR_HOOKABLE(PlayerJump);
80         // called when a player presses the jump key
81         // INPUT, OUTPUT:
82                 float player_multijump;
83                 float player_jumpheight;
84
85 MUTATOR_HOOKABLE(GiveFragsForKill);
86         // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
87         // INPUT:
88 //              entity frag_attacker; // same as self
89 //              entity frag_target;
90         // INPUT, OUTPUT:
91                 float frag_score;
92
93 MUTATOR_HOOKABLE(MatchEnd);
94         // called when the match ends
95
96 MUTATOR_HOOKABLE(GetTeamCount);
97         // should adjust ret_float to contain the team count
98         // INPUT, OUTPUT:
99                 float ret_float;
100
101 MUTATOR_HOOKABLE(SpectateCopy);
102         // copies variables for spectating "other" to "self"
103         // INPUT:
104 //              entity other;
105
106 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
107         // returns 1 if throwing the current weapon shall not be allowed
108
109 MUTATOR_HOOKABLE(WeaponRateFactor);
110         // allows changing attack rate
111         // INPUT, OUTPUT:
112                 float weapon_rate;
113
114 MUTATOR_HOOKABLE(WeaponSpeedFactor);
115         // allows changing weapon speed (projectiles mostly)
116         // INPUT, OUTPUT:
117                 //float ret_float;
118
119 MUTATOR_HOOKABLE(SetStartItems);
120         // adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}}
121
122 MUTATOR_HOOKABLE(BuildMutatorsString);
123         // appends ":mutatorname" to ret_string for logging
124         // INPUT, OUTPUT:
125                 string ret_string;
126
127 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
128         // appends ", Mutator name" to ret_string for display
129         // INPUT, OUTPUT:
130 //              string ret_string;
131
132 MUTATOR_HOOKABLE(CustomizeWaypoint);
133         // called every frame
134         // customizes the waypoint for spectators
135         // INPUT: self = waypoint, other = player, other.enemy = spectator
136
137 MUTATOR_HOOKABLE(FilterItem);
138         // 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)
139         // return error to request removal
140
141 MUTATOR_HOOKABLE(TurretSpawn);
142         // return error to request removal
143         // INPUT: self - turret
144
145 MUTATOR_HOOKABLE(OnEntityPreSpawn);
146         // return error to prevent entity spawn, or modify the entity
147
148 MUTATOR_HOOKABLE(PlayerPreThink);
149         // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
150
151 MUTATOR_HOOKABLE(GetPressedKeys);
152         // TODO change this into a general PlayerPostThink hook?
153
154 MUTATOR_HOOKABLE(PlayerPhysics);
155         // called before any player physics, may adjust variables for movement,
156         // is run AFTER bot code and idle checking
157
158 MUTATOR_HOOKABLE(GetCvars);
159         // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
160         // INPUT:
161                 float get_cvars_f;
162                 string get_cvars_s;
163
164 MUTATOR_HOOKABLE(EditProjectile);
165         // can edit any "just fired" projectile
166         // INPUT:
167 //              entity self;
168 //              entity other;
169
170 MUTATOR_HOOKABLE(MonsterSpawn);
171         // called when a monster spawns
172
173 MUTATOR_HOOKABLE(MonsterDies);
174         // called when a monster dies
175         // INPUT:
176 //              entity frag_attacker;
177
178 MUTATOR_HOOKABLE(MonsterRespawn);
179         // called when a monster wants to respawn
180         // INPUT:
181 //              entity other;
182
183 MUTATOR_HOOKABLE(MonsterDropItem);
184         // called when a monster is dropping loot
185         // INPUT, OUTPUT:
186                 .void() monster_loot;
187 //              entity other;
188
189 MUTATOR_HOOKABLE(MonsterMove);
190         // called when a monster moves
191         // returning true makes the monster stop
192         // INPUT:
193                 float monster_speed_run;
194                 float monster_speed_walk;
195                 entity monster_target;
196
197 MUTATOR_HOOKABLE(MonsterFindTarget);
198         // called when a monster looks for another target
199
200 MUTATOR_HOOKABLE(MonsterCheckBossFlag);
201     // called to change a random monster to a miniboss
202
203 MUTATOR_HOOKABLE(AllowMobSpawning);
204         // called when a player tries to spawn a monster
205         // return 1 to prevent spawning
206
207 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
208         // called when a player gets damaged to e.g. remove stuff he was carrying.
209         // INPUT:
210 //              entity frag_inflictor;
211 //              entity frag_attacker;
212 //              entity frag_target; // same as self
213                 vector damage_force; // NOTE: this force already HAS been applied
214         // INPUT, OUTPUT:
215                 float damage_take;
216                 float damage_save;
217
218 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
219         // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
220         // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
221         // INPUT:
222 //              entity frag_attacker;
223 //              entity frag_target;
224 //              float frag_deathtype;
225         // INPUT, OUTPUT:
226                 float frag_damage;
227                 float frag_mirrordamage;
228                 vector frag_force;
229
230 MUTATOR_HOOKABLE(PlayerPowerups);
231         // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
232         // INPUT
233 //      entity self;
234         float olditems; // also technically output, but since it is at the end of the function it's useless for that :P
235
236 MUTATOR_HOOKABLE(PlayerRegen);
237         // called every player think frame
238         // return 1 to disable regen
239         // INPUT, OUTPUT:
240                 float regen_mod_max;
241                 float regen_mod_regen;
242                 float regen_mod_rot;
243                 float regen_mod_limit;
244
245 MUTATOR_HOOKABLE(PlayerUseKey);
246         // called when the use key is pressed
247         // if MUTATOR_RETURNVALUE is 1, don't do anything
248         // return 1 if the use key actually did something
249
250 MUTATOR_HOOKABLE(SV_ParseClientCommand);
251         // called when a client command is parsed
252         // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
253         // NOTE: return 1 if you handled the command, return 0 to continue handling
254         // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
255         // INPUT
256         string cmd_name; // command name
257         float cmd_argc; // also, argv() can be used
258         string cmd_string; // whole command, use only if you really have to
259         /*
260                 // example:
261                 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
262                 {
263                         if(MUTATOR_RETURNVALUE) // command was already handled?
264                                 return 0;
265                         if(cmd_name == "echocvar" && cmd_argc >= 2)
266                         {
267                                 print(cvar_string(argv(1)), "\n");
268                                 return 1;
269                         }
270                         if(cmd_name == "echostring" && cmd_argc >= 2)
271                         {
272                                 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
273                                 return 1;
274                         }
275                         return 0;
276                 }
277         */
278
279 MUTATOR_HOOKABLE(Spawn_Score);
280         // called when a spawnpoint is being evaluated
281         // return 1 to make the spawnpoint unusable
282         // INPUT
283 //      entity self; // player wanting to spawn
284 //      entity spawn_spot; // spot to be evaluated
285         // IN+OUT
286         vector spawn_score; // _x is priority, _y is "distance"
287
288 MUTATOR_HOOKABLE(SV_StartFrame);
289         // runs globally each server frame
290
291 MUTATOR_HOOKABLE(SetModname);
292         // OUT
293 //      string modname; // name of the mutator/mod if it warrants showing as such in the server browser
294
295 MUTATOR_HOOKABLE(Item_Spawn);
296         // called for each item being spawned on a map, including dropped weapons
297         // return 1 to remove an item
298         // INPUT
299 //      entity self; // the item
300
301 MUTATOR_HOOKABLE(SetWeaponreplace);
302         // IN
303 //              entity self; // map entity
304 //              entity other; // weapon info
305         // IN+OUT
306 //              string ret_string;
307
308 MUTATOR_HOOKABLE(Item_RespawnCountdown);
309         // called when an item is about to respawn
310         // INPUT+OUTPUT:
311         string item_name;
312         vector item_color;
313
314 MUTATOR_HOOKABLE(BotShouldAttack);
315         // called when a bot checks a target to attack
316         // INPUT
317         entity checkentity;
318
319 MUTATOR_HOOKABLE(PortalTeleport);
320         // called whenever a player goes through a portal gun teleport
321         // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
322         // INPUT
323 //      entity self;
324
325 MUTATOR_HOOKABLE(HelpMePing);
326         // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
327         // normally help me ping uses self.waypointsprite_attachedforcarrier,
328         // but if your mutator uses something different then you can handle it
329         // in a special manner using this hook
330         // INPUT
331 //      entity self; // the player who pressed impulse 33
332
333 MUTATOR_HOOKABLE(VehicleSpawn);
334         // called when a vehicle initializes
335         // return true to remove the vehicle
336
337 MUTATOR_HOOKABLE(VehicleEnter);
338         // called when a player enters a vehicle
339         // allows mutators to set special settings in this event
340         // INPUT
341         entity vh_player; // player
342         entity vh_vehicle; // vehicle
343
344 MUTATOR_HOOKABLE(VehicleTouch);
345         // called when a player touches a vehicle
346         // return true to stop player from entering the vehicle
347         // INPUT
348 //      entity self; // vehicle
349 //      entity other; // player
350
351 MUTATOR_HOOKABLE(VehicleExit);
352         // called when a player exits a vehicle
353         // allows mutators to set special settings in this event
354         // INPUT
355 //      entity vh_player; // player
356 //      entity vh_vehicle; // vehicle
357
358 MUTATOR_HOOKABLE(AbortSpeedrun);
359         // called when a speedrun is aborted and the player is teleported back to start position
360         // INPUT
361 //      entity self; // player
362
363 MUTATOR_HOOKABLE(ItemTouch);
364         // called at when a item is touched. Called early, can edit item properties.
365 //      entity self;    // item
366 //      entity other;   // player
367         const float MUT_ITEMTOUCH_CONTINUE = 0; // return this flag to make the function continue as normal
368         const float MUT_ITEMTOUCH_RETURN = 1; // return this flag to make the function return (handled entirely by mutator)
369         const float MUT_ITEMTOUCH_PICKUP = 2; // return this flag to have the item "picked up" and taken even after mutator handled it
370
371 MUTATOR_HOOKABLE(ClientConnect);
372         // called at when a player connect
373 //      entity self;    // player
374
375 MUTATOR_HOOKABLE(HavocBot_ChooseRole);
376 //      entity self;
377
378 MUTATOR_HOOKABLE(AccuracyTargetValid);
379         // called when a target is checked for accuracy
380 //      entity frag_attacker; // attacker
381 //      entity frag_target; // target
382         const float MUT_ACCADD_VALID = 0; // return this flag to make the function continue if target is a client
383         const float MUT_ACCADD_INVALID = 1; // return this flag to make the function always continue
384         const float MUT_ACCADD_INDIFFERENT = 2; // return this flag to make the function always return
385 #endif