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