1 #ifndef MUTATORS_BASE_H
2 #define MUTATORS_BASE_H
3 const int CBC_ORDER_FIRST = 1;
4 const int CBC_ORDER_LAST = 2;
5 const int CBC_ORDER_EXCLUSIVE = 3;
6 const int CBC_ORDER_ANY = 4;
8 bool CallbackChain_ReturnValue; // read-only field of the current return value
10 entity CallbackChain_New(string name);
11 bool CallbackChain_Add(entity cb, bool() func, int order);
12 int CallbackChain_Remove(entity cb, bool() func);
13 // a callback function is like this:
14 // bool mycallback(entity me)
19 bool CallbackChain_Call(entity cb);
26 typedef bool(int) mutatorfunc_t;
27 bool Mutator_Add(mutatorfunc_t func, string name);
28 void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
30 #define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name, #name)
31 #define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name, #name)
32 #define MUTATOR_DEFINITION(name) bool MUTATOR_##name(int mode)
33 #define MUTATOR_DECLARATION(name) bool MUTATOR_##name(int mode)
34 #define MUTATOR_HOOKFUNCTION(name) bool HOOKFUNCTION_##name()
35 #define MUTATOR_HOOK(cb, func, order) do { \
37 if (!HOOK_##cb) HOOK_##cb = CallbackChain_New(#cb); \
38 if (!CallbackChain_Add(HOOK_##cb, HOOKFUNCTION_##func, order)) { \
39 print("HOOK FAILED: ", #func, "\n"); \
43 MUTATOR_ONROLLBACK_OR_REMOVE { \
44 if (HOOK_##cb) CallbackChain_Remove(HOOK_##cb, HOOKFUNCTION_##func); \
47 #define MUTATOR_ONADD if (mode == MUTATOR_ADDING)
48 #define MUTATOR_ONREMOVE if (mode == MUTATOR_REMOVING)
49 #define MUTATOR_ONROLLBACK_OR_REMOVE if (mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
51 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
52 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
54 #define MUTATOR_RETURNVALUE CallbackChain_ReturnValue
59 // register all possible hooks here
60 // some parameters are commented to avoid duplicate declarations
62 MUTATOR_HOOKABLE(MakePlayerObserver);
63 // called when a player becomes observer, after shared setup
65 MUTATOR_HOOKABLE(PutClientInServer);
66 // entity self; // client wanting to spawn
68 MUTATOR_HOOKABLE(PlayerSpawn);
69 entity spawn_spot; // spot that was used, or world
70 // called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here)
72 MUTATOR_HOOKABLE(reset_map_global);
73 // called in reset_map
75 MUTATOR_HOOKABLE(reset_map_players);
76 // called in reset_map
78 MUTATOR_HOOKABLE(ForbidPlayerScore_Clear);
79 // returns 1 if clearing player score shall not be allowed
81 MUTATOR_HOOKABLE(ClientDisconnect);
82 // called when a player disconnects
84 MUTATOR_HOOKABLE(PlayerDies);
85 // called when a player dies to e.g. remove stuff he was carrying.
87 entity frag_inflictor;
89 entity frag_target; // same as self
92 MUTATOR_HOOKABLE(PlayerJump);
93 // called when a player presses the jump key
95 float player_multijump;
96 float player_jumpheight;
98 MUTATOR_HOOKABLE(GiveFragsForKill);
99 // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
101 // entity frag_attacker; // same as self
102 // entity frag_target;
106 MUTATOR_HOOKABLE(MatchEnd);
107 // called when the match ends
109 MUTATOR_HOOKABLE(GetTeamCount);
110 // should adjust ret_float to contain the team count
114 MUTATOR_HOOKABLE(SpectateCopy);
115 // copies variables for spectating "other" to "self"
119 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
120 // returns 1 if throwing the current weapon shall not be allowed
122 MUTATOR_HOOKABLE(WeaponRateFactor);
123 // allows changing attack rate
127 MUTATOR_HOOKABLE(WeaponSpeedFactor);
128 // allows changing weapon speed (projectiles mostly)
132 MUTATOR_HOOKABLE(SetStartItems);
133 // adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}}
135 MUTATOR_HOOKABLE(BuildMutatorsString);
136 // appends ":mutatorname" to ret_string for logging
140 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
141 // appends ", Mutator name" to ret_string for display
143 // string ret_string;
145 MUTATOR_HOOKABLE(CustomizeWaypoint);
146 // called every frame
147 // customizes the waypoint for spectators
148 // INPUT: self = waypoint, other = player, other.enemy = spectator
150 MUTATOR_HOOKABLE(FilterItem);
151 // 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)
152 // return error to request removal
154 MUTATOR_HOOKABLE(TurretSpawn);
155 // return error to request removal
156 // INPUT: self - turret
158 MUTATOR_HOOKABLE(OnEntityPreSpawn);
159 // return error to prevent entity spawn, or modify the entity
161 MUTATOR_HOOKABLE(PlayerPreThink);
162 // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
164 MUTATOR_HOOKABLE(GetPressedKeys);
165 // TODO change this into a general PlayerPostThink hook?
167 MUTATOR_HOOKABLE(PlayerPhysics);
168 // called before any player physics, may adjust variables for movement,
169 // is run AFTER bot code and idle checking
171 MUTATOR_HOOKABLE(GetCvars);
172 // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
177 MUTATOR_HOOKABLE(EditProjectile);
178 // can edit any "just fired" projectile
183 MUTATOR_HOOKABLE(MonsterSpawn);
184 // called when a monster spawns
186 MUTATOR_HOOKABLE(MonsterDies);
187 // called when a monster dies
189 // entity frag_attacker;
191 MUTATOR_HOOKABLE(MonsterRespawn);
192 // called when a monster wants to respawn
196 MUTATOR_HOOKABLE(MonsterDropItem);
197 // called when a monster is dropping loot
199 .void() monster_loot;
202 MUTATOR_HOOKABLE(MonsterMove);
203 // called when a monster moves
204 // returning true makes the monster stop
206 float monster_speed_run;
207 float monster_speed_walk;
208 entity monster_target;
210 MUTATOR_HOOKABLE(MonsterFindTarget);
211 // called when a monster looks for another target
213 MUTATOR_HOOKABLE(MonsterCheckBossFlag);
214 // called to change a random monster to a miniboss
216 MUTATOR_HOOKABLE(AllowMobSpawning);
217 // called when a player tries to spawn a monster
218 // return 1 to prevent spawning
220 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
221 // called when a player gets damaged to e.g. remove stuff he was carrying.
223 // entity frag_inflictor;
224 // entity frag_attacker;
225 // entity frag_target; // same as self
226 vector damage_force; // NOTE: this force already HAS been applied
231 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
232 // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
233 // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
235 // entity frag_attacker;
236 // entity frag_target;
237 // float frag_deathtype;
240 float frag_mirrordamage;
243 MUTATOR_HOOKABLE(PlayerPowerups);
244 // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
247 int olditems; // also technically output, but since it is at the end of the function it's useless for that :P
249 MUTATOR_HOOKABLE(PlayerRegen);
250 // called every player think frame
251 // return 1 to disable regen
254 float regen_mod_regen;
256 float regen_mod_limit;
258 MUTATOR_HOOKABLE(PlayerUseKey);
259 // called when the use key is pressed
260 // if MUTATOR_RETURNVALUE is 1, don't do anything
261 // return 1 if the use key actually did something
263 MUTATOR_HOOKABLE(SV_ParseClientCommand);
264 // called when a client command is parsed
265 // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
266 // NOTE: return 1 if you handled the command, return 0 to continue handling
267 // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
269 string cmd_name; // command name
270 int cmd_argc; // also, argv() can be used
271 string cmd_string; // whole command, use only if you really have to
274 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
276 if(MUTATOR_RETURNVALUE) // command was already handled?
278 if(cmd_name == "echocvar" && cmd_argc >= 2)
280 print(cvar_string(argv(1)), "\n");
283 if(cmd_name == "echostring" && cmd_argc >= 2)
285 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
292 MUTATOR_HOOKABLE(Spawn_Score);
293 // called when a spawnpoint is being evaluated
294 // return 1 to make the spawnpoint unusable
296 // entity self; // player wanting to spawn
297 // entity spawn_spot; // spot to be evaluated
299 vector spawn_score; // _x is priority, _y is "distance"
301 MUTATOR_HOOKABLE(SV_StartFrame);
302 // runs globally each server frame
304 MUTATOR_HOOKABLE(SetModname);
306 // string modname; // name of the mutator/mod if it warrants showing as such in the server browser
308 MUTATOR_HOOKABLE(Item_Spawn);
309 // called for each item being spawned on a map, including dropped weapons
310 // return 1 to remove an item
312 // entity self; // the item
314 MUTATOR_HOOKABLE(SetWeaponreplace);
316 // entity self; // map entity
317 // entity other; // weapon info
319 // string ret_string;
321 MUTATOR_HOOKABLE(Item_RespawnCountdown);
322 // called when an item is about to respawn
327 MUTATOR_HOOKABLE(BotShouldAttack);
328 // called when a bot checks a target to attack
332 MUTATOR_HOOKABLE(PortalTeleport);
333 // called whenever a player goes through a portal gun teleport
334 // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
338 MUTATOR_HOOKABLE(HelpMePing);
339 // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
340 // normally help me ping uses self.waypointsprite_attachedforcarrier,
341 // but if your mutator uses something different then you can handle it
342 // in a special manner using this hook
344 // entity self; // the player who pressed impulse 33
346 MUTATOR_HOOKABLE(VehicleSpawn);
347 // called when a vehicle initializes
348 // return true to remove the vehicle
350 MUTATOR_HOOKABLE(VehicleEnter);
351 // called when a player enters a vehicle
352 // allows mutators to set special settings in this event
354 entity vh_player; // player
355 entity vh_vehicle; // vehicle
357 MUTATOR_HOOKABLE(VehicleTouch);
358 // called when a player touches a vehicle
359 // return true to stop player from entering the vehicle
361 // entity self; // vehicle
362 // entity other; // player
364 MUTATOR_HOOKABLE(VehicleExit);
365 // called when a player exits a vehicle
366 // allows mutators to set special settings in this event
368 // entity vh_player; // player
369 // entity vh_vehicle; // vehicle
371 MUTATOR_HOOKABLE(AbortSpeedrun);
372 // called when a speedrun is aborted and the player is teleported back to start position
374 // entity self; // player
376 MUTATOR_HOOKABLE(ItemTouch);
377 // called at when a item is touched. Called early, can edit item properties.
378 // entity self; // item
379 // entity other; // player
381 MUT_ITEMTOUCH_CONTINUE, // return this flag to make the function continue as normal
382 MUT_ITEMTOUCH_RETURN, // return this flag to make the function return (handled entirely by mutator)
383 MUT_ITEMTOUCH_PICKUP // return this flag to have the item "picked up" and taken even after mutator handled it
386 MUTATOR_HOOKABLE(ClientConnect);
387 // called at when a player connect
388 // entity self; // player
390 MUTATOR_HOOKABLE(HavocBot_ChooseRole);
393 MUTATOR_HOOKABLE(AccuracyTargetValid);
394 // called when a target is checked for accuracy
395 // entity frag_attacker; // attacker
396 // entity frag_target; // target
398 MUT_ACCADD_VALID, // return this flag to make the function continue if target is a client
399 MUT_ACCADD_INVALID, // return this flag to make the function always continue
400 MUT_ACCADD_INDIFFERENT // return this flag to make the function always return