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(WeaponSpeedFactor);
115 // allows changing weapon speed (projectiles mostly)
119 MUTATOR_HOOKABLE(SetStartItems);
120 // adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}}
122 MUTATOR_HOOKABLE(BuildMutatorsString);
123 // appends ":mutatorname" to ret_string for logging
127 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
128 // appends ", Mutator name" to ret_string for display
130 // string ret_string;
132 MUTATOR_HOOKABLE(CustomizeWaypoint);
133 // called every frame
134 // customizes the waypoint for spectators
135 // INPUT: self = waypoint, other = player, other.enemy = spectator
137 MUTATOR_HOOKABLE(FilterItem);
138 // 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)
139 // return error to request removal
141 MUTATOR_HOOKABLE(TurretSpawn);
142 // return error to request removal
143 // INPUT: self - turret
145 MUTATOR_HOOKABLE(OnEntityPreSpawn);
146 // return error to prevent entity spawn, or modify the entity
148 MUTATOR_HOOKABLE(PlayerPreThink);
149 // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
151 MUTATOR_HOOKABLE(GetPressedKeys);
152 // TODO change this into a general PlayerPostThink hook?
154 MUTATOR_HOOKABLE(PlayerPhysics);
155 // called before any player physics, may adjust variables for movement,
156 // is run AFTER bot code and idle checking
158 MUTATOR_HOOKABLE(GetCvars);
159 // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
164 MUTATOR_HOOKABLE(EditProjectile);
165 // can edit any "just fired" projectile
170 MUTATOR_HOOKABLE(MonsterSpawn);
171 // called when a monster spawns
173 MUTATOR_HOOKABLE(MonsterDies);
174 // called when a monster dies
176 // entity frag_attacker;
178 MUTATOR_HOOKABLE(MonsterRemove);
179 // called when a monster is being removed
180 // returning true hides removal effect
182 MUTATOR_HOOKABLE(MonsterDropItem);
183 // called when a monster is dropping loot
185 .void() monster_loot;
188 MUTATOR_HOOKABLE(MonsterMove);
189 // called when a monster moves
190 // returning true makes the monster stop
192 float monster_speed_run;
193 float monster_speed_walk;
194 entity monster_target;
196 MUTATOR_HOOKABLE(MonsterFindTarget);
197 // called when a monster looks for another target
199 MUTATOR_HOOKABLE(MonsterCheckBossFlag);
200 // called to change a random monster to a miniboss
202 MUTATOR_HOOKABLE(AllowMobSpawning);
203 // called when a player tries to spawn a monster
204 // return 1 to prevent spawning
206 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
207 // called when a player gets damaged to e.g. remove stuff he was carrying.
209 // entity frag_inflictor;
210 // entity frag_attacker;
211 // entity frag_target; // same as self
212 vector damage_force; // NOTE: this force already HAS been applied
217 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
218 // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
219 // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
221 // entity frag_attacker;
222 // entity frag_target;
223 // float frag_deathtype;
226 float frag_mirrordamage;
229 MUTATOR_HOOKABLE(PlayerPowerups);
230 // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
233 float olditems; // also technically output, but since it is at the end of the function it's useless for that :P
235 MUTATOR_HOOKABLE(PlayerRegen);
236 // called every player think frame
237 // return 1 to disable regen
240 float regen_mod_regen;
242 float regen_mod_limit;
244 MUTATOR_HOOKABLE(PlayerUseKey);
245 // called when the use key is pressed
246 // if MUTATOR_RETURNVALUE is 1, don't do anything
247 // return 1 if the use key actually did something
249 MUTATOR_HOOKABLE(SV_ParseClientCommand);
250 // called when a client command is parsed
251 // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
252 // NOTE: return 1 if you handled the command, return 0 to continue handling
253 // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
255 string cmd_name; // command name
256 float cmd_argc; // also, argv() can be used
257 string cmd_string; // whole command, use only if you really have to
260 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
262 if(MUTATOR_RETURNVALUE) // command was already handled?
264 if(cmd_name == "echocvar" && cmd_argc >= 2)
266 print(cvar_string(argv(1)), "\n");
269 if(cmd_name == "echostring" && cmd_argc >= 2)
271 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
278 MUTATOR_HOOKABLE(Spawn_Score);
279 // called when a spawnpoint is being evaluated
280 // return 1 to make the spawnpoint unusable
282 // entity self; // player wanting to spawn
283 // entity spawn_spot; // spot to be evaluated
285 vector spawn_score; // _x is priority, _y is "distance"
287 MUTATOR_HOOKABLE(SV_StartFrame);
288 // runs globally each server frame
290 MUTATOR_HOOKABLE(SetModname);
292 // string modname; // name of the mutator/mod if it warrants showing as such in the server browser
294 MUTATOR_HOOKABLE(Item_Spawn);
295 // called for each item being spawned on a map, including dropped weapons
296 // return 1 to remove an item
298 // entity self; // the item
300 MUTATOR_HOOKABLE(SetWeaponreplace);
302 // entity self; // map entity
303 // entity other; // weapon info
305 // string ret_string;
307 MUTATOR_HOOKABLE(Item_RespawnCountdown);
308 // called when an item is about to respawn
313 MUTATOR_HOOKABLE(BotShouldAttack);
314 // called when a bot checks a target to attack
318 MUTATOR_HOOKABLE(PortalTeleport);
319 // called whenever a player goes through a portal gun teleport
320 // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
324 MUTATOR_HOOKABLE(HelpMePing);
325 // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
326 // normally help me ping uses self.waypointsprite_attachedforcarrier,
327 // but if your mutator uses something different then you can handle it
328 // in a special manner using this hook
330 // entity self; // the player who pressed impulse 33
332 MUTATOR_HOOKABLE(VehicleSpawn);
333 // called when a vehicle initializes
334 // return true to remove the vehicle
336 MUTATOR_HOOKABLE(VehicleEnter);
337 // called when a player enters a vehicle
338 // allows mutators to set special settings in this event
340 entity vh_player; // player
341 entity vh_vehicle; // vehicle
343 MUTATOR_HOOKABLE(VehicleTouch);
344 // called when a player touches a vehicle
345 // return true to stop player from entering the vehicle
347 // entity self; // vehicle
348 // entity other; // player
350 MUTATOR_HOOKABLE(VehicleExit);
351 // called when a player exits 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(AbortSpeedrun);
358 // called when a speedrun is aborted and the player is teleported back to start position
360 // entity self; // player
362 MUTATOR_HOOKABLE(ItemTouch);
363 // called at when a item is touched. Called early, can edit item properties.
364 // entity self; // item
365 // entity other; // player
366 const float MUT_ITEMTOUCH_CONTINUE = 0; // return this flag to make the function continue as normal
367 const float MUT_ITEMTOUCH_RETURN = 1; // return this flag to make the function return (handled entirely by mutator)
368 const float MUT_ITEMTOUCH_PICKUP = 2; // return this flag to have the item "picked up" and taken even after mutator handled it
370 MUTATOR_HOOKABLE(ClientConnect);
371 // called at when a player connect
372 // entity self; // player
374 MUTATOR_HOOKABLE(HavocBot_ChooseRole);
377 MUTATOR_HOOKABLE(AccuracyTargetValid);
378 // called when a target is checked for accuracy
379 // entity frag_attacker; // attacker
380 // entity frag_target; // target
381 const float MUT_ACCADD_VALID = 0; // return this flag to make the function continue if target is a client
382 const float MUT_ACCADD_INVALID = 1; // return this flag to make the function always continue
383 const float MUT_ACCADD_INDIFFERENT = 2; // return this flag to make the function always return