]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/base.qh
04b725fad6a94952bef23167f86cf612041e50e8
[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 typedef float(float) mutatorfunc_t;
22 float Mutator_Add(mutatorfunc_t func, string name);
23 void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
24
25 #define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name, #name)
26 #define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name, #name)
27 #define MUTATOR_DEFINITION(name) float MUTATOR_##name(float mode)
28 #define MUTATOR_DECLARATION(name) float MUTATOR_##name(float mode)
29 #define MUTATOR_HOOKFUNCTION(name) float HOOKFUNCTION_##name()
30 #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) { if(HOOK_##cb) CallbackChain_Remove(HOOK_##cb,HOOKFUNCTION_##func); } } while(0)
31 #define MUTATOR_ONADD if(mode == MUTATOR_ADDING)
32 #define MUTATOR_ONREMOVE if(mode == MUTATOR_REMOVING)
33
34 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
35 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
36
37 #define MUTATOR_RETURNVALUE CallbackChain_ReturnValue
38
39
40
41
42 // register all possible hooks here
43
44 MUTATOR_HOOKABLE(MakePlayerObserver);
45         // called when a player becomes observer, after shared setup
46
47 MUTATOR_HOOKABLE(PutClientInServer);
48         entity self; // client wanting to spawn
49
50 MUTATOR_HOOKABLE(PlayerSpawn);
51         entity spawn_spot; // spot that was used, or world
52         // called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here)
53
54 MUTATOR_HOOKABLE(reset_map_global);
55         // called in reset_map
56
57 MUTATOR_HOOKABLE(reset_map_players);
58         // called in reset_map
59
60 MUTATOR_HOOKABLE(ForbidPlayerScore_Clear);
61         // returns 1 if clearing player score shall not be allowed
62
63 MUTATOR_HOOKABLE(ClientDisconnect);
64         // called when a player disconnects
65
66 MUTATOR_HOOKABLE(PlayerDies);
67         // called when a player dies to e.g. remove stuff he was carrying.
68         // INPUT:
69                 entity frag_inflictor;
70                 entity frag_attacker;
71                 entity frag_target; // same as self
72                 float frag_deathtype;
73
74 MUTATOR_HOOKABLE(GiveFragsForKill);
75         // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
76         // INPUT:
77                 entity frag_attacker; // same as self
78                 entity frag_target;
79         // INPUT, OUTPUT:
80                 float frag_score;
81
82 MUTATOR_HOOKABLE(MatchEnd);
83         // called when the match ends
84
85 MUTATOR_HOOKABLE(GetTeamCount);
86         // should adjust ret_float to contain the team count
87         // INPUT, OUTPUT:
88                 float ret_float;
89
90 MUTATOR_HOOKABLE(SpectateCopy);
91         // copies variables for spectating "other" to "self"
92         // INPUT:
93                 entity other;
94
95 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
96         // returns 1 if throwing the current weapon shall not be allowed
97
98 MUTATOR_HOOKABLE(SetStartItems);
99         // adjusts {warmup_}start_{items,weapons,ammo_{cells,rockets,nails,shells,fuel}}
100
101 MUTATOR_HOOKABLE(BuildMutatorsString);
102         // appends ":mutatorname" to ret_string for logging
103         // INPUT, OUTPUT:
104                 string ret_string;
105
106 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
107         // appends ", Mutator name" to ret_string for display
108         // INPUT, OUTPUT:
109                 string ret_string;
110
111 MUTATOR_HOOKABLE(FilterItem);
112         // 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)
113         // return error to request removal
114
115 MUTATOR_HOOKABLE(TurretSpawn);
116         // return error to request removal
117         // INPUT: self - turret
118         
119 MUTATOR_HOOKABLE(OnEntityPreSpawn);
120         // return error to prevent entity spawn, or modify the entity
121
122 MUTATOR_HOOKABLE(PlayerPreThink);
123         // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
124
125 MUTATOR_HOOKABLE(GetPressedKeys);
126         // TODO change this into a general PlayerPostThink hook?
127
128 MUTATOR_HOOKABLE(PlayerPhysics);
129         // called before any player physics, may adjust variables for movement,
130         // is run AFTER bot code and idle checking
131
132 MUTATOR_HOOKABLE(GetCvars);
133         // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
134         // INPUT:
135                 float get_cvars_f;
136                 string get_cvars_s;
137
138 MUTATOR_HOOKABLE(EditProjectile);
139         // can edit any "just fired" projectile
140         // INPUT:
141                 entity self;
142                 entity other;
143
144 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
145         // called when a player gets damaged to e.g. remove stuff he was carrying.
146         // INPUT:
147                 entity frag_inflictor;
148                 entity frag_attacker;
149                 entity frag_target; // same as self
150                 vector damage_force; // NOTE: this force already HAS been applied
151         // INPUT, OUTPUT:
152                 float damage_take;
153                 float damage_save;
154                 
155 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
156         // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier or runematch runes
157         // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
158         // INPUT:
159                 entity frag_attacker;
160                 entity frag_target;
161                 float frag_deathtype;
162         // INPUT, OUTPUT:
163                 float frag_damage;
164                 vector frag_force;
165
166 MUTATOR_HOOKABLE(PlayerPowerups);
167         // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
168         // INPUT
169         entity self;
170         float olditems; // also technically output, but since it is at the end of the function it's useless for that :P 
171
172 MUTATOR_HOOKABLE(PlayerUseKey);
173         // called when the use key is pressed
174         // if MUTATOR_RETURNVALUE is 1, don't do anything
175         // return 1 if the use key actually did something
176
177 MUTATOR_HOOKABLE(SV_ParseClientCommand);
178         // called when a client command is parsed
179         // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
180         // NOTE: return 1 if you handled the command, return 0 to continue handling
181         // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
182         // INPUT
183         string cmd_name; // command name
184         float cmd_argc; // also, argv() can be used
185         string cmd_string; // whole command, use only if you really have to
186         /*
187                 // example:
188                 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
189                 {
190                         if(MUTATOR_RETURNVALUE) // command was already handled?
191                                 return 0;
192                         if(cmd_name == "echocvar" && cmd_argc >= 2)
193                         {
194                                 print(cvar_string(argv(1)), "\n");
195                                 return 1;
196                         }
197                         if(cmd_name == "echostring" && cmd_argc >= 2)
198                         {
199                                 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
200                                 return 1;
201                         }
202                         return 0;
203                 }
204         */
205
206 MUTATOR_HOOKABLE(Spawn_Score);
207         // called when a spawnpoint is being evaluated
208         // return 1 to make the spawnpoint unusable
209         // INPUT
210         entity self; // player wanting to spawn
211         entity spawn_spot; // spot to be evaluated
212         // IN+OUT
213         vector spawn_score; // _x is priority, _y is "distance"
214
215 MUTATOR_HOOKABLE(SV_StartFrame);
216         // runs globally each server frame
217
218 MUTATOR_HOOKABLE(SetModname);
219         // OUT
220         string modname; // name of the mutator/mod if it warrants showing as such in the server browser
221
222 MUTATOR_HOOKABLE(SetWeaponreplace);
223         // IN
224                 entity self; // map entity
225                 entity other; // weapon info
226         // IN+OUT
227                 string ret_string;
228
229 MUTATOR_HOOKABLE(PortalTeleport);
230         // called whenever a player goes through a portal gun teleport
231         // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
232         // INPUT
233         entity self;
234         
235 MUTATOR_HOOKABLE(HelpMePing);
236         // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
237         // normally help me ping uses self.waypointsprite_attachedforcarrier,
238         // but if your mutator uses something different then you can handle it
239         // in a special manner using this hook
240         // INPUT
241         entity self; // the player who pressed impulse 33
242         
243 MUTATOR_HOOKABLE(VehicleEnter);
244         // called when a player enters a vehicle
245         // allows mutators to set special settings in this event
246         // INPUT
247         entity vh_player; // player
248         entity vh_vehicle; // vehicle
249         
250 MUTATOR_HOOKABLE(VehicleExit);
251         // called when a player exits a vehicle
252         // allows mutators to set special settings in this event
253         // INPUT
254         entity vh_player; // player
255         entity vh_vehicle; // vehicle
256         
257 MUTATOR_HOOKABLE(AbortSpeedrun);
258         // called when a speedrun is aborted and the player is teleported back to start position
259         // INPUT
260         entity self; // player
261
262 MUTATOR_HOOKABLE(ItemTouch);
263         // called at when a item is touched. Called early, can edit item properties.
264         entity self;    // item
265         entity other;   // player
266
267 MUTATOR_HOOKABLE(ClientConnect);
268         // called at when a player connect
269         entity self;    // player
270
271 MUTATOR_HOOKABLE(HavocBot_ChooseRule);
272         entity self;