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