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