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