]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/base.qh
Merge branch 'master' into terencehill/weapon_panel_fix
[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(SetStartItems);
115         // adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}}
116
117 MUTATOR_HOOKABLE(BuildMutatorsString);
118         // appends ":mutatorname" to ret_string for logging
119         // INPUT, OUTPUT:
120                 string ret_string;
121
122 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
123         // appends ", Mutator name" to ret_string for display
124         // INPUT, OUTPUT:
125 //              string ret_string;
126
127 MUTATOR_HOOKABLE(CustomizeWaypoint);
128         // called every frame
129         // customizes the waypoint for spectators
130         // INPUT: self = waypoint, other = player, other.enemy = spectator
131
132 MUTATOR_HOOKABLE(FilterItem);
133         // 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)
134         // return error to request removal
135
136 MUTATOR_HOOKABLE(TurretSpawn);
137         // return error to request removal
138         // INPUT: self - turret
139
140 MUTATOR_HOOKABLE(OnEntityPreSpawn);
141         // return error to prevent entity spawn, or modify the entity
142
143 MUTATOR_HOOKABLE(PlayerPreThink);
144         // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
145
146 MUTATOR_HOOKABLE(GetPressedKeys);
147         // TODO change this into a general PlayerPostThink hook?
148
149 MUTATOR_HOOKABLE(PlayerPhysics);
150         // called before any player physics, may adjust variables for movement,
151         // is run AFTER bot code and idle checking
152
153 MUTATOR_HOOKABLE(GetCvars);
154         // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
155         // INPUT:
156                 float get_cvars_f;
157                 string get_cvars_s;
158
159 MUTATOR_HOOKABLE(EditProjectile);
160         // can edit any "just fired" projectile
161         // INPUT:
162 //              entity self;
163 //              entity other;
164
165 MUTATOR_HOOKABLE(MonsterSpawn);
166         // called when a monster spawns
167
168 MUTATOR_HOOKABLE(MonsterDies);
169         // called when a monster dies
170         // INPUT:
171 //              entity frag_attacker;
172
173 MUTATOR_HOOKABLE(MonsterRespawn);
174         // called when a monster wants to respawn
175         // INPUT:
176 //              entity other;
177
178 MUTATOR_HOOKABLE(MonsterDropItem);
179         // called when a monster is dropping loot
180         // INPUT, OUTPUT:
181                 .void() monster_loot;
182 //              entity other;
183
184 MUTATOR_HOOKABLE(MonsterMove);
185         // called when a monster moves
186         // returning true makes the monster stop
187         // INPUT:
188                 float monster_speed_run;
189                 float monster_speed_walk;
190                 entity monster_target;
191
192 MUTATOR_HOOKABLE(MonsterFindTarget);
193         // called when a monster looks for another target
194
195 MUTATOR_HOOKABLE(MonsterCheckBossFlag);
196     // called to change a random monster to a miniboss
197
198 MUTATOR_HOOKABLE(AllowMobSpawning);
199         // called when a player tries to spawn a monster
200         // return 1 to prevent spawning
201
202 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
203         // called when a player gets damaged to e.g. remove stuff he was carrying.
204         // INPUT:
205 //              entity frag_inflictor;
206 //              entity frag_attacker;
207 //              entity frag_target; // same as self
208                 vector damage_force; // NOTE: this force already HAS been applied
209         // INPUT, OUTPUT:
210                 float damage_take;
211                 float damage_save;
212
213 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
214         // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
215         // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
216         // INPUT:
217 //              entity frag_attacker;
218 //              entity frag_target;
219 //              float frag_deathtype;
220         // INPUT, OUTPUT:
221                 float frag_damage;
222                 float frag_mirrordamage;
223                 vector frag_force;
224
225 MUTATOR_HOOKABLE(PlayerPowerups);
226         // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
227         // INPUT
228 //      entity self;
229         float olditems; // also technically output, but since it is at the end of the function it's useless for that :P
230
231 MUTATOR_HOOKABLE(PlayerRegen);
232         // called every player think frame
233         // return 1 to disable regen
234         // INPUT, OUTPUT:
235                 float regen_mod_max;
236                 float regen_mod_regen;
237                 float regen_mod_rot;
238                 float regen_mod_limit;
239
240 MUTATOR_HOOKABLE(PlayerUseKey);
241         // called when the use key is pressed
242         // if MUTATOR_RETURNVALUE is 1, don't do anything
243         // return 1 if the use key actually did something
244
245 MUTATOR_HOOKABLE(SV_ParseClientCommand);
246         // called when a client command is parsed
247         // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
248         // NOTE: return 1 if you handled the command, return 0 to continue handling
249         // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
250         // INPUT
251         string cmd_name; // command name
252         float cmd_argc; // also, argv() can be used
253         string cmd_string; // whole command, use only if you really have to
254         /*
255                 // example:
256                 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
257                 {
258                         if(MUTATOR_RETURNVALUE) // command was already handled?
259                                 return 0;
260                         if(cmd_name == "echocvar" && cmd_argc >= 2)
261                         {
262                                 print(cvar_string(argv(1)), "\n");
263                                 return 1;
264                         }
265                         if(cmd_name == "echostring" && cmd_argc >= 2)
266                         {
267                                 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
268                                 return 1;
269                         }
270                         return 0;
271                 }
272         */
273
274 MUTATOR_HOOKABLE(Spawn_Score);
275         // called when a spawnpoint is being evaluated
276         // return 1 to make the spawnpoint unusable
277         // INPUT
278 //      entity self; // player wanting to spawn
279 //      entity spawn_spot; // spot to be evaluated
280         // IN+OUT
281         vector spawn_score; // _x is priority, _y is "distance"
282
283 MUTATOR_HOOKABLE(SV_StartFrame);
284         // runs globally each server frame
285
286 MUTATOR_HOOKABLE(SetModname);
287         // OUT
288 //      string modname; // name of the mutator/mod if it warrants showing as such in the server browser
289
290 MUTATOR_HOOKABLE(Item_Spawn);
291         // called for each item being spawned on a map, including dropped weapons
292         // return 1 to remove an item
293         // INPUT
294 //      entity self; // the item
295
296 MUTATOR_HOOKABLE(SetWeaponreplace);
297         // IN
298 //              entity self; // map entity
299 //              entity other; // weapon info
300         // IN+OUT
301 //              string ret_string;
302
303 MUTATOR_HOOKABLE(Item_RespawnCountdown);
304         // called when an item is about to respawn
305         // INPUT+OUTPUT:
306         string item_name;
307         vector item_color;
308
309 MUTATOR_HOOKABLE(BotShouldAttack);
310         // called when a bot checks a target to attack
311         // INPUT
312         entity checkentity;
313
314 MUTATOR_HOOKABLE(PortalTeleport);
315         // called whenever a player goes through a portal gun teleport
316         // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
317         // INPUT
318 //      entity self;
319
320 MUTATOR_HOOKABLE(HelpMePing);
321         // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
322         // normally help me ping uses self.waypointsprite_attachedforcarrier,
323         // but if your mutator uses something different then you can handle it
324         // in a special manner using this hook
325         // INPUT
326 //      entity self; // the player who pressed impulse 33
327
328 MUTATOR_HOOKABLE(VehicleSpawn);
329         // called when a vehicle initializes
330         // return true to remove the vehicle
331
332 MUTATOR_HOOKABLE(VehicleEnter);
333         // called when a player enters a vehicle
334         // allows mutators to set special settings in this event
335         // INPUT
336         entity vh_player; // player
337         entity vh_vehicle; // vehicle
338
339 MUTATOR_HOOKABLE(VehicleTouch);
340         // called when a player touches a vehicle
341         // return true to stop player from entering the vehicle
342         // INPUT
343 //      entity self; // vehicle
344 //      entity other; // player
345
346 MUTATOR_HOOKABLE(VehicleExit);
347         // called when a player exits a vehicle
348         // allows mutators to set special settings in this event
349         // INPUT
350 //      entity vh_player; // player
351 //      entity vh_vehicle; // vehicle
352
353 MUTATOR_HOOKABLE(AbortSpeedrun);
354         // called when a speedrun is aborted and the player is teleported back to start position
355         // INPUT
356 //      entity self; // player
357
358 MUTATOR_HOOKABLE(ItemTouch);
359         // called at when a item is touched. Called early, can edit item properties.
360 //      entity self;    // item
361 //      entity other;   // player
362         const float MUT_ITEMTOUCH_CONTINUE = 0; // return this flag to make the function continue as normal
363         const float MUT_ITEMTOUCH_RETURN = 1; // return this flag to make the function return (handled entirely by mutator)
364         const float MUT_ITEMTOUCH_PICKUP = 2; // return this flag to have the item "picked up" and taken even after mutator handled it
365
366 MUTATOR_HOOKABLE(ClientConnect);
367         // called at when a player connect
368 //      entity self;    // player
369
370 MUTATOR_HOOKABLE(HavocBot_ChooseRole);
371 //      entity self;
372
373 MUTATOR_HOOKABLE(AccuracyTargetValid);
374         // called when a target is checked for accuracy
375 //      entity frag_attacker; // attacker
376 //      entity frag_target; // target
377         const float MUT_ACCADD_VALID = 0; // return this flag to make the function continue if target is a client
378         const float MUT_ACCADD_INVALID = 1; // return this flag to make the function always continue
379         const float MUT_ACCADD_INDIFFERENT = 2; // return this flag to make the function always return
380 #endif