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