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