1 #ifndef MUTATORS_BASE_H
2 #define MUTATORS_BASE_H
3 const float CBC_ORDER_EXCLUSIVE = 3;
4 const float CBC_ORDER_FIRST = 1;
5 const float CBC_ORDER_LAST = 2;
6 const float CBC_ORDER_ANY = 4;
8 float CallbackChain_ReturnValue; // read-only field of the current return value
10 entity CallbackChain_New(string name);
11 float CallbackChain_Add(entity cb, float() func, float order);
12 float CallbackChain_Remove(entity cb, float() func);
13 // a callback function is like this:
14 // float mycallback(entity me)
19 float CallbackChain_Call(entity cb);
21 const float MUTATOR_REMOVING = 0;
22 const float MUTATOR_ADDING = 1;
23 const float MUTATOR_ROLLING_BACK = 2;
24 typedef float(float) mutatorfunc_t;
25 float Mutator_Add(mutatorfunc_t func, string name);
26 void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
28 #define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name, #name)
29 #define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name, #name)
30 #define MUTATOR_DEFINITION(name) float MUTATOR_##name(float mode)
31 #define MUTATOR_DECLARATION(name) float MUTATOR_##name(float mode)
32 #define MUTATOR_HOOKFUNCTION(name) float HOOKFUNCTION_##name()
33 #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)
34 #define MUTATOR_ONADD if(mode == MUTATOR_ADDING)
35 #define MUTATOR_ONREMOVE if(mode == MUTATOR_REMOVING)
36 #define MUTATOR_ONROLLBACK_OR_REMOVE if(mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
38 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
39 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
41 #define MUTATOR_RETURNVALUE CallbackChain_ReturnValue
46 // register all possible hooks here
47 // some parameters are commented to avoid duplicate declarations
49 MUTATOR_HOOKABLE(MakePlayerObserver);
50 // called when a player becomes observer, after shared setup
52 MUTATOR_HOOKABLE(PutClientInServer);
53 // entity self; // client wanting to spawn
55 MUTATOR_HOOKABLE(PlayerSpawn);
56 entity spawn_spot; // spot that was used, or world
57 // called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here)
59 MUTATOR_HOOKABLE(reset_map_global);
60 // called in reset_map
62 MUTATOR_HOOKABLE(reset_map_players);
63 // called in reset_map
65 MUTATOR_HOOKABLE(ForbidPlayerScore_Clear);
66 // returns 1 if clearing player score shall not be allowed
68 MUTATOR_HOOKABLE(ClientDisconnect);
69 // called when a player disconnects
71 MUTATOR_HOOKABLE(PlayerDies);
72 // called when a player dies to e.g. remove stuff he was carrying.
74 entity frag_inflictor;
76 entity frag_target; // same as self
79 MUTATOR_HOOKABLE(PlayerJump);
80 // called when a player presses the jump key
82 float player_multijump;
83 float player_jumpheight;
85 MUTATOR_HOOKABLE(GiveFragsForKill);
86 // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
88 // entity frag_attacker; // same as self
89 // entity frag_target;
93 MUTATOR_HOOKABLE(MatchEnd);
94 // called when the match ends
96 MUTATOR_HOOKABLE(GetTeamCount);
97 // should adjust ret_float to contain the team count
101 MUTATOR_HOOKABLE(SpectateCopy);
102 // copies variables for spectating "other" to "self"
106 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
107 // returns 1 if throwing the current weapon shall not be allowed
109 MUTATOR_HOOKABLE(WeaponRateFactor);
110 // allows changing attack rate
114 MUTATOR_HOOKABLE(SetStartItems);
115 // adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}}
117 MUTATOR_HOOKABLE(BuildMutatorsString);
118 // appends ":mutatorname" to ret_string for logging
122 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
123 // appends ", Mutator name" to ret_string for display
125 // string ret_string;
127 MUTATOR_HOOKABLE(CustomizeWaypoint);
128 // called every frame
129 // customizes the waypoint for spectators
130 // INPUT: self = waypoint, other = player, other.enemy = spectator
132 MUTATOR_HOOKABLE(FilterItem);
133 // 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)
134 // return error to request removal
136 MUTATOR_HOOKABLE(TurretSpawn);
137 // return error to request removal
138 // INPUT: self - turret
140 MUTATOR_HOOKABLE(OnEntityPreSpawn);
141 // return error to prevent entity spawn, or modify the entity
143 MUTATOR_HOOKABLE(PlayerPreThink);
144 // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
146 MUTATOR_HOOKABLE(GetPressedKeys);
147 // TODO change this into a general PlayerPostThink hook?
149 MUTATOR_HOOKABLE(PlayerPhysics);
150 // called before any player physics, may adjust variables for movement,
151 // is run AFTER bot code and idle checking
153 MUTATOR_HOOKABLE(GetCvars);
154 // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
159 MUTATOR_HOOKABLE(EditProjectile);
160 // can edit any "just fired" projectile
165 MUTATOR_HOOKABLE(MonsterSpawn);
166 // called when a monster spawns
168 MUTATOR_HOOKABLE(MonsterDies);
169 // called when a monster dies
171 // entity frag_attacker;
173 MUTATOR_HOOKABLE(MonsterRespawn);
174 // called when a monster wants to respawn
178 MUTATOR_HOOKABLE(MonsterDropItem);
179 // called when a monster is dropping loot
181 .void() monster_loot;
184 MUTATOR_HOOKABLE(MonsterMove);
185 // called when a monster moves
186 // returning true makes the monster stop
188 float monster_speed_run;
189 float monster_speed_walk;
190 entity monster_target;
192 MUTATOR_HOOKABLE(MonsterFindTarget);
193 // called when a monster looks for another target
195 MUTATOR_HOOKABLE(MonsterCheckBossFlag);
196 // called to change a random monster to a miniboss
198 MUTATOR_HOOKABLE(AllowMobSpawning);
199 // called when a player tries to spawn a monster
200 // return 1 to prevent spawning
202 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
203 // called when a player gets damaged to e.g. remove stuff he was carrying.
205 // entity frag_inflictor;
206 // entity frag_attacker;
207 // entity frag_target; // same as self
208 vector damage_force; // NOTE: this force already HAS been applied
213 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
214 // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
215 // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
217 // entity frag_attacker;
218 // entity frag_target;
219 // float frag_deathtype;
222 float frag_mirrordamage;
225 MUTATOR_HOOKABLE(PlayerPowerups);
226 // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
229 float olditems; // also technically output, but since it is at the end of the function it's useless for that :P
231 MUTATOR_HOOKABLE(PlayerRegen);
232 // called every player think frame
233 // return 1 to disable regen
236 float regen_mod_regen;
238 float regen_mod_limit;
240 MUTATOR_HOOKABLE(PlayerUseKey);
241 // called when the use key is pressed
242 // if MUTATOR_RETURNVALUE is 1, don't do anything
243 // return 1 if the use key actually did something
245 MUTATOR_HOOKABLE(SV_ParseClientCommand);
246 // called when a client command is parsed
247 // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
248 // NOTE: return 1 if you handled the command, return 0 to continue handling
249 // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
251 string cmd_name; // command name
252 float cmd_argc; // also, argv() can be used
253 string cmd_string; // whole command, use only if you really have to
256 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
258 if(MUTATOR_RETURNVALUE) // command was already handled?
260 if(cmd_name == "echocvar" && cmd_argc >= 2)
262 print(cvar_string(argv(1)), "\n");
265 if(cmd_name == "echostring" && cmd_argc >= 2)
267 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
274 MUTATOR_HOOKABLE(Spawn_Score);
275 // called when a spawnpoint is being evaluated
276 // return 1 to make the spawnpoint unusable
278 // entity self; // player wanting to spawn
279 // entity spawn_spot; // spot to be evaluated
281 vector spawn_score; // _x is priority, _y is "distance"
283 MUTATOR_HOOKABLE(SV_StartFrame);
284 // runs globally each server frame
286 MUTATOR_HOOKABLE(SetModname);
288 // string modname; // name of the mutator/mod if it warrants showing as such in the server browser
290 MUTATOR_HOOKABLE(Item_Spawn);
291 // called for each item being spawned on a map, including dropped weapons
292 // return 1 to remove an item
294 // entity self; // the item
296 MUTATOR_HOOKABLE(SetWeaponreplace);
298 // entity self; // map entity
299 // entity other; // weapon info
301 // string ret_string;
303 MUTATOR_HOOKABLE(Item_RespawnCountdown);
304 // called when an item is about to respawn
309 MUTATOR_HOOKABLE(BotShouldAttack);
310 // called when a bot checks a target to attack
314 MUTATOR_HOOKABLE(PortalTeleport);
315 // called whenever a player goes through a portal gun teleport
316 // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
320 MUTATOR_HOOKABLE(HelpMePing);
321 // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
322 // normally help me ping uses self.waypointsprite_attachedforcarrier,
323 // but if your mutator uses something different then you can handle it
324 // in a special manner using this hook
326 // entity self; // the player who pressed impulse 33
328 MUTATOR_HOOKABLE(VehicleSpawn);
329 // called when a vehicle initializes
330 // return true to remove the vehicle
332 MUTATOR_HOOKABLE(VehicleEnter);
333 // called when a player enters a vehicle
334 // allows mutators to set special settings in this event
336 entity vh_player; // player
337 entity vh_vehicle; // vehicle
339 MUTATOR_HOOKABLE(VehicleTouch);
340 // called when a player touches a vehicle
341 // return true to stop player from entering the vehicle
343 // entity self; // vehicle
344 // entity other; // player
346 MUTATOR_HOOKABLE(VehicleExit);
347 // called when a player exits a vehicle
348 // allows mutators to set special settings in this event
350 // entity vh_player; // player
351 // entity vh_vehicle; // vehicle
353 MUTATOR_HOOKABLE(AbortSpeedrun);
354 // called when a speedrun is aborted and the player is teleported back to start position
356 // entity self; // player
358 MUTATOR_HOOKABLE(ItemTouch);
359 // called at when a item is touched. Called early, can edit item properties.
360 // entity self; // item
361 // entity other; // player
362 const float MUT_ITEMTOUCH_CONTINUE = 0; // return this flag to make the function continue as normal
363 const float MUT_ITEMTOUCH_RETURN = 1; // return this flag to make the function return (handled entirely by mutator)
364 const float MUT_ITEMTOUCH_PICKUP = 2; // return this flag to have the item "picked up" and taken even after mutator handled it
366 MUTATOR_HOOKABLE(ClientConnect);
367 // called at when a player connect
368 // entity self; // player
370 MUTATOR_HOOKABLE(HavocBot_ChooseRole);
373 MUTATOR_HOOKABLE(AccuracyTargetValid);
374 // called when a target is checked for accuracy
375 // entity frag_attacker; // attacker
376 // entity frag_target; // target
377 const float MUT_ACCADD_VALID = 0; // return this flag to make the function continue if target is a client
378 const float MUT_ACCADD_INVALID = 1; // return this flag to make the function always continue
379 const float MUT_ACCADD_INDIFFERENT = 2; // return this flag to make the function always return