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