]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/base.qh
Reintroduce the T-virus
[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(MonsterRemove);
179         // called when a monster is being removed
180         // returning true hides removal effect
181
182 MUTATOR_HOOKABLE(MonsterDropItem);
183         // called when a monster is dropping loot
184         // INPUT, OUTPUT:
185                 .void() monster_loot;
186 //              entity other;
187
188 MUTATOR_HOOKABLE(MonsterMove);
189         // called when a monster moves
190         // returning true makes the monster stop
191         // INPUT:
192                 float monster_speed_run;
193                 float monster_speed_walk;
194                 entity monster_target;
195
196 MUTATOR_HOOKABLE(MonsterFindTarget);
197         // called when a monster looks for another target
198
199 MUTATOR_HOOKABLE(MonsterCheckBossFlag);
200     // called to change a random monster to a miniboss
201
202 MUTATOR_HOOKABLE(AllowMobSpawning);
203         // called when a player tries to spawn a monster
204         // return 1 to prevent spawning
205
206 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
207         // called when a player gets damaged to e.g. remove stuff he was carrying.
208         // INPUT:
209 //              entity frag_inflictor;
210 //              entity frag_attacker;
211 //              entity frag_target; // same as self
212                 vector damage_force; // NOTE: this force already HAS been applied
213         // INPUT, OUTPUT:
214                 float damage_take;
215                 float damage_save;
216
217 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
218         // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
219         // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
220         // INPUT:
221 //              entity frag_attacker;
222 //              entity frag_target;
223 //              float frag_deathtype;
224         // INPUT, OUTPUT:
225                 float frag_damage;
226                 float frag_mirrordamage;
227                 vector frag_force;
228
229 MUTATOR_HOOKABLE(PlayerPowerups);
230         // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
231         // INPUT
232 //      entity self;
233         float olditems; // also technically output, but since it is at the end of the function it's useless for that :P
234
235 MUTATOR_HOOKABLE(PlayerRegen);
236         // called every player think frame
237         // return 1 to disable regen
238         // INPUT, OUTPUT:
239                 float regen_mod_max;
240                 float regen_mod_regen;
241                 float regen_mod_rot;
242                 float regen_mod_limit;
243
244 MUTATOR_HOOKABLE(PlayerUseKey);
245         // called when the use key is pressed
246         // if MUTATOR_RETURNVALUE is 1, don't do anything
247         // return 1 if the use key actually did something
248
249 MUTATOR_HOOKABLE(SV_ParseClientCommand);
250         // called when a client command is parsed
251         // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
252         // NOTE: return 1 if you handled the command, return 0 to continue handling
253         // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
254         // INPUT
255         string cmd_name; // command name
256         float cmd_argc; // also, argv() can be used
257         string cmd_string; // whole command, use only if you really have to
258         /*
259                 // example:
260                 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
261                 {
262                         if(MUTATOR_RETURNVALUE) // command was already handled?
263                                 return 0;
264                         if(cmd_name == "echocvar" && cmd_argc >= 2)
265                         {
266                                 print(cvar_string(argv(1)), "\n");
267                                 return 1;
268                         }
269                         if(cmd_name == "echostring" && cmd_argc >= 2)
270                         {
271                                 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
272                                 return 1;
273                         }
274                         return 0;
275                 }
276         */
277
278 MUTATOR_HOOKABLE(Spawn_Score);
279         // called when a spawnpoint is being evaluated
280         // return 1 to make the spawnpoint unusable
281         // INPUT
282 //      entity self; // player wanting to spawn
283 //      entity spawn_spot; // spot to be evaluated
284         // IN+OUT
285         vector spawn_score; // _x is priority, _y is "distance"
286
287 MUTATOR_HOOKABLE(SV_StartFrame);
288         // runs globally each server frame
289
290 MUTATOR_HOOKABLE(SetModname);
291         // OUT
292 //      string modname; // name of the mutator/mod if it warrants showing as such in the server browser
293
294 MUTATOR_HOOKABLE(Item_Spawn);
295         // called for each item being spawned on a map, including dropped weapons
296         // return 1 to remove an item
297         // INPUT
298 //      entity self; // the item
299
300 MUTATOR_HOOKABLE(SetWeaponreplace);
301         // IN
302 //              entity self; // map entity
303 //              entity other; // weapon info
304         // IN+OUT
305 //              string ret_string;
306
307 MUTATOR_HOOKABLE(Item_RespawnCountdown);
308         // called when an item is about to respawn
309         // INPUT+OUTPUT:
310         string item_name;
311         vector item_color;
312
313 MUTATOR_HOOKABLE(BotShouldAttack);
314         // called when a bot checks a target to attack
315         // INPUT
316         entity checkentity;
317
318 MUTATOR_HOOKABLE(PortalTeleport);
319         // called whenever a player goes through a portal gun teleport
320         // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
321         // INPUT
322 //      entity self;
323
324 MUTATOR_HOOKABLE(HelpMePing);
325         // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
326         // normally help me ping uses self.waypointsprite_attachedforcarrier,
327         // but if your mutator uses something different then you can handle it
328         // in a special manner using this hook
329         // INPUT
330 //      entity self; // the player who pressed impulse 33
331
332 MUTATOR_HOOKABLE(VehicleSpawn);
333         // called when a vehicle initializes
334         // return true to remove the vehicle
335
336 MUTATOR_HOOKABLE(VehicleEnter);
337         // called when a player enters a vehicle
338         // allows mutators to set special settings in this event
339         // INPUT
340         entity vh_player; // player
341         entity vh_vehicle; // vehicle
342
343 MUTATOR_HOOKABLE(VehicleTouch);
344         // called when a player touches a vehicle
345         // return true to stop player from entering the vehicle
346         // INPUT
347 //      entity self; // vehicle
348 //      entity other; // player
349
350 MUTATOR_HOOKABLE(VehicleExit);
351         // called when a player exits 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(AbortSpeedrun);
358         // called when a speedrun is aborted and the player is teleported back to start position
359         // INPUT
360 //      entity self; // player
361
362 MUTATOR_HOOKABLE(ItemTouch);
363         // called at when a item is touched. Called early, can edit item properties.
364 //      entity self;    // item
365 //      entity other;   // player
366         const float MUT_ITEMTOUCH_CONTINUE = 0; // return this flag to make the function continue as normal
367         const float MUT_ITEMTOUCH_RETURN = 1; // return this flag to make the function return (handled entirely by mutator)
368         const float MUT_ITEMTOUCH_PICKUP = 2; // return this flag to have the item "picked up" and taken even after mutator handled it
369
370 MUTATOR_HOOKABLE(ClientConnect);
371         // called at when a player connect
372 //      entity self;    // player
373
374 MUTATOR_HOOKABLE(HavocBot_ChooseRole);
375 //      entity self;
376
377 MUTATOR_HOOKABLE(AccuracyTargetValid);
378         // called when a target is checked for accuracy
379 //      entity frag_attacker; // attacker
380 //      entity frag_target; // target
381         const float MUT_ACCADD_VALID = 0; // return this flag to make the function continue if target is a client
382         const float MUT_ACCADD_INVALID = 1; // return this flag to make the function always continue
383         const float MUT_ACCADD_INDIFFERENT = 2; // return this flag to make the function always return
384 #endif