]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/events.qh
Fix auxiliary crosshairs
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / events.qh
1 #ifndef SERVER_MUTATORS_EVENTS_H
2 #define SERVER_MUTATORS_EVENTS_H
3
4 #include "../../common/mutators/base.qh"
5
6 // register all possible hooks here
7
8 /** called when a player becomes observer, after shared setup */
9 #define EV_MakePlayerObserver(i, o) \
10     /**/
11 MUTATOR_HOOKABLE(MakePlayerObserver, EV_MakePlayerObserver)
12
13 /** */
14 #define EV_PutClientInServer(i, o) \
15     /** client wanting to spawn */ i(entity, self) \
16     /**/
17 MUTATOR_HOOKABLE(PutClientInServer, EV_PutClientInServer);
18
19 /** called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here) */
20 #define EV_PlayerSpawn(i, o) \
21     /** spot that was used, or world */ i(entity, spawn_spot) \
22     /**/
23 entity spawn_spot;
24 MUTATOR_HOOKABLE(PlayerSpawn, EV_PlayerSpawn);
25
26 /** called in reset_map */
27 #define EV_reset_map_global(i, o) \
28     /**/
29 MUTATOR_HOOKABLE(reset_map_global, EV_reset_map_global);
30
31 /** called in reset_map */
32 #define EV_reset_map_players(i, o) \
33     /**/
34 MUTATOR_HOOKABLE(reset_map_players, EV_reset_map_players);
35
36 /** returns 1 if clearing player score shall not be allowed */
37 #define EV_ForbidPlayerScore_Clear(i, o) \
38     /**/
39 MUTATOR_HOOKABLE(ForbidPlayerScore_Clear, EV_ForbidPlayerScore_Clear);
40
41 /** called when a player disconnects */
42 #define EV_ClientDisconnect(i, o) \
43     /**/
44 MUTATOR_HOOKABLE(ClientDisconnect, EV_ClientDisconnect);
45
46 /** called when a player dies to e.g. remove stuff he was carrying. */
47 #define EV_PlayerDies(i, o) \
48     /**/ i(entity, frag_inflictor) \
49     /**/ i(entity, frag_attacker) \
50     /** same as self */ i(entity, frag_target) \
51     /**/ i(int, frag_deathtype) \
52     /**/
53 entity frag_inflictor;
54 entity frag_attacker;
55 entity frag_target;
56 int frag_deathtype;
57 MUTATOR_HOOKABLE(PlayerDies, EV_PlayerDies);
58
59 /** called when a player presses the jump key */
60 #define EV_PlayerJump(i, o) \
61     /**/ i(float, player_multijump) \
62     /**/ i(float, player_jumpheight) \
63     /**/ o(float, player_multijump) \
64     /**/ o(float, player_jumpheight) \
65     /**/
66 float player_multijump;
67 float player_jumpheight;
68 MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump);
69
70 /** called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill */
71 #define EV_GiveFragsForKill(i, o) \
72     /** same as self */ i(entity, frag_attacker) \
73     /**/ i(entity, frag_target) \
74     /**/ i(float, frag_score) \
75     /**/ o(float, frag_score) \
76     /**/
77 float frag_score;
78 MUTATOR_HOOKABLE(GiveFragsForKill, EV_GiveFragsForKill);
79
80 /** called when the match ends */
81 MUTATOR_HOOKABLE(MatchEnd, EV_NO_ARGS);
82
83 /** should adjust ret_float to contain the team count */
84 #define EV_GetTeamCount(i, o) \
85     /**/ i(float, ret_float) \
86     /**/ o(float, ret_float) \
87     /**/
88 float ret_float;
89 MUTATOR_HOOKABLE(GetTeamCount, EV_GetTeamCount);
90
91 /** copies variables for spectating "other" to "self" */
92 #define EV_SpectateCopy(i, o) \
93     /**/ i(entity, other) \
94     /**/ i(entity, self) \
95     /**/
96 MUTATOR_HOOKABLE(SpectateCopy, EV_SpectateCopy);
97
98 /** returns 1 if throwing the current weapon shall not be allowed */
99 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon, EV_NO_ARGS);
100
101 /** allows changing attack rate */
102 #define EV_WeaponRateFactor(i, o) \
103     /**/ i(float, weapon_rate) \
104     /**/ o(float, weapon_rate) \
105     /**/
106 float weapon_rate;
107 MUTATOR_HOOKABLE(WeaponRateFactor, EV_WeaponRateFactor);
108
109 /** allows changing weapon speed (projectiles mostly) */
110 #define EV_WeaponSpeedFactor(i, o) \
111     /**/ i(float, ret_float) \
112     /**/ o(float, ret_float) \
113     /**/
114 MUTATOR_HOOKABLE(WeaponSpeedFactor, EV_WeaponSpeedFactor);
115
116 /** adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}} */
117 MUTATOR_HOOKABLE(SetStartItems, EV_NO_ARGS);
118
119 /** called every frame. customizes the waypoint for spectators */
120 #define EV_CustomizeWaypoint(i, o) \
121     /** waypoint */ i(entity, self) \
122     /** player; other.enemy = spectator */ i(entity, other) \
123     /**/
124 MUTATOR_HOOKABLE(CustomizeWaypoint, EV_CustomizeWaypoint);
125
126 /**
127  * 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)
128  * return error to request removal
129  */
130 MUTATOR_HOOKABLE(FilterItem, EV_NO_ARGS);
131
132 /** return error to request removal */
133 #define EV_TurretSpawn(i, o) \
134     /** turret */ i(entity, self) \
135     /**/
136 MUTATOR_HOOKABLE(TurretSpawn, EV_TurretSpawn);
137
138 /** return error to prevent entity spawn, or modify the entity */
139 MUTATOR_HOOKABLE(OnEntityPreSpawn, EV_NO_ARGS);
140
141 /** runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators */
142 MUTATOR_HOOKABLE(PlayerPreThink, EV_NO_ARGS);
143
144 /** TODO change this into a general PlayerPostThink hook? */
145 MUTATOR_HOOKABLE(GetPressedKeys, EV_NO_ARGS);
146
147 /**
148  * called before any player physics, may adjust variables for movement,
149  * is run AFTER bot code and idle checking
150  */
151 MUTATOR_HOOKABLE(PlayerPhysics, EV_NO_ARGS);
152
153 /** is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client */
154 #define EV_GetCvars(i, o) \
155     /**/ i(float, get_cvars_f) \
156     /**/ i(string, get_cvars_s) \
157     /**/
158 float get_cvars_f;
159 string get_cvars_s;
160 MUTATOR_HOOKABLE(GetCvars, EV_NO_ARGS); // NOTE: Can't use EV_GetCvars because of `SZ_GetSpace: overflow`
161
162 /** can edit any "just fired" projectile */
163 #define EV_EditProjectile(i, o) \
164     /**/ i(entity, self) \
165     /**/ i(entity, other) \
166     /**/
167 MUTATOR_HOOKABLE(EditProjectile, EV_EditProjectile);
168
169 /** called when a monster spawns */
170 MUTATOR_HOOKABLE(MonsterSpawn, EV_NO_ARGS);
171
172 /** called when a monster dies */
173 #define EV_MonsterDies(i, o) \
174     /**/ i(entity, frag_attacker) \
175     /**/
176 MUTATOR_HOOKABLE(MonsterDies, EV_MonsterDies);
177
178 /** called when a monster wants to respawn */
179 #define EV_MonsterRespawn(i, o) \
180     /**/ i(entity, other) \
181     /**/
182 MUTATOR_HOOKABLE(MonsterRespawn, EV_MonsterRespawn);
183
184 /** called when a monster is dropping loot */
185 #define EV_MonsterDropItem(i, o) \
186     /**/ i(entity, other) \
187     /**/ o(entity, other) \
188     /**/
189 .void() monster_loot;
190 MUTATOR_HOOKABLE(MonsterDropItem, EV_MonsterDropItem);
191
192 /**
193  * called when a monster moves
194  * returning true makes the monster stop
195  */
196 #define EV_MonsterMove(i, o) \
197     /**/ i(float, monster_speed_run) \
198     /**/ o(float, monster_speed_run) \
199     /**/ i(float, monster_speed_walk) \
200     /**/ o(float, monster_speed_walk) \
201     /**/ i(entity, monster_target) \
202     /**/
203 float monster_speed_run;
204 float monster_speed_walk;
205 entity monster_target;
206 MUTATOR_HOOKABLE(MonsterMove, EV_MonsterMove);
207
208 /** called when a monster looks for another target */
209 MUTATOR_HOOKABLE(MonsterFindTarget, EV_NO_ARGS);
210
211 /** called to change a random monster to a miniboss */
212 MUTATOR_HOOKABLE(MonsterCheckBossFlag, EV_NO_ARGS);
213
214 /**
215  * called when a player tries to spawn a monster
216  * return 1 to prevent spawning
217  */
218 MUTATOR_HOOKABLE(AllowMobSpawning, EV_NO_ARGS);
219
220 /** called when a player gets damaged to e.g. remove stuff he was carrying. */
221 #define EV_PlayerDamage_SplitHealthArmor(i, o) \
222     /**/ i(entity, frag_inflictor) \
223     /**/ i(entity, frag_attacker) \
224     /** same as self */ i(entity, frag_target) \
225     /** NOTE: this force already HAS been applied */ i(vector, damage_force) \
226     /**/ i(float, damage_take) \
227     /**/ o(float, damage_take) \
228         /**/ i(float, damage_save) \
229     /**/ o(float, damage_save) \
230     /**/
231 vector damage_force;
232 float damage_take;
233 float damage_save;
234 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor, EV_PlayerDamage_SplitHealthArmor);
235
236 /**
237  * called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
238  * i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
239  */
240 #define EV_PlayerDamage_Calculate(i, o) \
241     /**/ i(entity, frag_attacker) \
242     /**/ i(entity, frag_target) \
243     /**/ i(float, frag_deathtype) \
244         /**/ i(float, frag_damage) \
245     /**/ o(float, frag_damage) \
246         /**/ i(float, frag_mirrordamage) \
247     /**/ o(float, frag_mirrordamage) \
248     /**/ i(vector, frag_force) \
249     /**/ o(vector, frag_force) \
250     /**/
251 float frag_damage;
252 float frag_mirrordamage;
253 vector frag_force;
254 MUTATOR_HOOKABLE(PlayerDamage_Calculate, EV_PlayerDamage_Calculate);
255
256 /** called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items. */
257 #define EV_PlayerPowerups(i, o) \
258     /**/ i(entity, self) \
259     /**/ i(int, olditems) \
260     /**/
261 int olditems;
262 MUTATOR_HOOKABLE(PlayerPowerups, EV_PlayerPowerups);
263
264 /**
265  * called every player think frame
266  * return 1 to disable regen
267  */
268 #define EV_PlayerRegen(i, o) \
269     /**/ i(float, regen_mod_max) \
270     /**/ o(float, regen_mod_max) \
271     /**/ i(float, regen_mod_regen) \
272     /**/ o(float, regen_mod_regen) \
273     /**/ i(float, regen_mod_rot) \
274     /**/ o(float, regen_mod_rot) \
275     /**/ i(float, regen_mod_limit) \
276     /**/ o(float, regen_mod_limit) \
277     /**/
278 float regen_mod_max;
279 float regen_mod_regen;
280 float regen_mod_rot;
281 float regen_mod_limit;
282 MUTATOR_HOOKABLE(PlayerRegen, EV_PlayerRegen);
283
284 /**
285  * called when the use key is pressed
286  * if MUTATOR_RETURNVALUE is 1, don't do anything
287  * return 1 if the use key actually did something
288  */
289 MUTATOR_HOOKABLE(PlayerUseKey, EV_NO_ARGS);
290
291 /**
292  * called when a client command is parsed
293  * NOTE: hooks MUST start with if (MUTATOR_RETURNVALUE) return false;
294  * NOTE: return true if you handled the command, return false to continue handling
295  * NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
296  * // example:
297  * MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
298  * {
299  *     if (MUTATOR_RETURNVALUE) // command was already handled?
300  *         return false;
301  *     if (cmd_name == "echocvar" && cmd_argc >= 2)
302  *     {
303  *         print(cvar_string(argv(1)), "\n");
304  *         return true;
305  *     }
306  *     if (cmd_name == "echostring" && cmd_argc >= 2)
307  *     {
308  *         print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
309  *         return true;
310  *     }
311  *     return false;
312  * }
313  */
314 #define EV_SV_ParseClientCommand(i, o) \
315     /** command name */ i(string, cmd_name) \
316     /** also, argv() can be used */ i(int, cmd_argc) \
317     /** whole command, use only if you really have to */ i(string, cmd_string) \
318     /**/
319 string cmd_name;
320 int cmd_argc;
321 string cmd_string;
322 MUTATOR_HOOKABLE(SV_ParseClientCommand, EV_SV_ParseClientCommand);
323
324 /**
325  * called when a spawnpoint is being evaluated
326  * return 1 to make the spawnpoint unusable
327  */
328 #define EV_Spawn_Score(i, o) \
329     /** player wanting to spawn */ i(entity, self) \
330     /** spot to be evaluated */ i(entity, spawn_spot) \
331     /** _x is priority, _y is "distance" */ i(vector, spawn_score) \
332     /**/ o(vector, spawn_score) \
333     /**/
334 vector spawn_score;
335 MUTATOR_HOOKABLE(Spawn_Score, EV_Spawn_Score);
336
337 /** runs globally each server frame */
338 MUTATOR_HOOKABLE(SV_StartFrame, EV_NO_ARGS);
339
340 #define EV_SetModname(i, o) \
341     /** name of the mutator/mod if it warrants showing as such in the server browser */ \
342     o(string, modname) \
343     /**/
344 MUTATOR_HOOKABLE(SetModname, EV_SetModname);
345
346 /**
347  * called for each item being spawned on a map, including dropped weapons
348  * return 1 to remove an item
349  */
350 #define EV_Item_Spawn(i, o) \
351     /** the item */ i(entity, self) \
352     /**/
353 MUTATOR_HOOKABLE(Item_Spawn, EV_Item_Spawn);
354
355 #define EV_SetWeaponreplace(i, o) \
356     /** map entity */ i(entity, self) \
357     /** weapon info */ i(entity, other) \
358     /**/ i(string, ret_string) \
359     /**/ o(string, ret_string) \
360     /**/
361 MUTATOR_HOOKABLE(SetWeaponreplace, EV_SetWeaponreplace);
362
363 /** called when an item is about to respawn */
364 #define EV_Item_RespawnCountdown(i, o) \
365     /**/ i(string, item_name) \
366     /**/ o(string, item_name) \
367     /**/ i(vector, item_color) \
368     /**/ o(vector, item_color) \
369     /**/
370 string item_name;
371 vector item_color;
372 MUTATOR_HOOKABLE(Item_RespawnCountdown, EV_Item_RespawnCountdown);
373
374 /** called when a bot checks a target to attack */
375 #define EV_BotShouldAttack(i, o) \
376     /**/ i(entity, checkentity) \
377     /**/
378 entity checkentity;
379 MUTATOR_HOOKABLE(BotShouldAttack, EV_BotShouldAttack);
380
381 /**
382  * called whenever a player goes through a portal gun teleport
383  * allows you to strip a player of an item if they go through the teleporter to help prevent cheating
384  */
385 #define EV_PortalTeleport(i, o) \
386     /**/ i(entity, self) \
387     /**/
388 MUTATOR_HOOKABLE(PortalTeleport, EV_PortalTeleport);
389
390 /**
391  * called whenever a player uses impulse 33 (help me) in cl_impulse.qc
392  * normally help me ping uses self.waypointsprite_attachedforcarrier,
393  * but if your mutator uses something different then you can handle it
394  * in a special manner using this hook
395  */
396 #define EV_HelpMePing(i, o) \
397     /** the player who pressed impulse 33 */ i(entity, self) \
398     /**/
399 MUTATOR_HOOKABLE(HelpMePing, EV_HelpMePing);
400
401 /**
402  * called when a vehicle initializes
403  * return true to remove the vehicle
404  */
405 MUTATOR_HOOKABLE(VehicleSpawn, EV_NO_ARGS);
406
407 /**
408  * called when a player enters a vehicle
409  * allows mutators to set special settings in this event
410  */
411 #define EV_VehicleEnter(i, o) \
412     /** player */ i(entity, vh_player) \
413     /** vehicle */ i(entity, vh_vehicle) \
414     /**/
415 entity vh_player;
416 entity vh_vehicle;
417 MUTATOR_HOOKABLE(VehicleEnter, EV_VehicleEnter);
418
419 /**
420  * called when a player touches a vehicle
421  * return true to stop player from entering the vehicle
422  */
423 #define EV_VehicleTouch(i, o) \
424     /** vehicle */ i(entity, self) \
425     /** player */ i(entity, other) \
426     /**/
427 MUTATOR_HOOKABLE(VehicleTouch, EV_VehicleTouch);
428
429 /**
430  * called when a player exits a vehicle
431  * allows mutators to set special settings in this event
432  */
433 #define EV_VehicleExit(i, o) \
434     /** player */ i(entity, vh_player) \
435     /** vehicle */ i(entity, vh_vehicle) \
436     /**/
437 MUTATOR_HOOKABLE(VehicleExit, EV_VehicleExit);
438
439 /** called when a speedrun is aborted and the player is teleported back to start position */
440 #define EV_AbortSpeedrun(i, o) \
441     /** player */ i(entity, self) \
442     /**/
443 MUTATOR_HOOKABLE(AbortSpeedrun, EV_AbortSpeedrun);
444
445 /** called at when a item is touched. Called early, can edit item properties. */
446 #define EV_ItemTouch(i, o) \
447     /** item */ i(entity, self) \
448     /** player */ i(entity, other) \
449     /**/
450 MUTATOR_HOOKABLE(ItemTouch, EV_ItemTouch);
451
452 enum {
453         MUT_ITEMTOUCH_CONTINUE, // return this flag to make the function continue as normal
454         MUT_ITEMTOUCH_RETURN, // return this flag to make the function return (handled entirely by mutator)
455         MUT_ITEMTOUCH_PICKUP // return this flag to have the item "picked up" and taken even after mutator handled it
456 };
457
458 /** called at when a player connect */
459 #define EV_ClientConnect(i, o) \
460     /** player */ i(entity, self) \
461     /**/
462 MUTATOR_HOOKABLE(ClientConnect, EV_ClientConnect);
463
464 #define EV_HavocBot_ChooseRole(i, o) \
465     /**/ i(entity, self) \
466     /**/
467 MUTATOR_HOOKABLE(HavocBot_ChooseRole, EV_HavocBot_ChooseRole);
468
469 /** called when a target is checked for accuracy */
470 #define EV_AccuracyTargetValid(i, o) \
471     /** attacker */ i(entity, frag_attacker) \
472     /** target */ i(entity, frag_target) \
473     /**/
474 MUTATOR_HOOKABLE(AccuracyTargetValid, EV_AccuracyTargetValid);
475 enum {
476         MUT_ACCADD_VALID, // return this flag to make the function continue if target is a client
477         MUT_ACCADD_INVALID, // return this flag to make the function always continue
478         MUT_ACCADD_INDIFFERENT // return this flag to make the function always return
479 };
480 #endif