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