]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/base.qh
Merge remote branch 'origin/master' into samual/mutator_ctf
[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(ClientDisconnect);
52         // called when a player disconnects
53
54 MUTATOR_HOOKABLE(PlayerDies);
55         // called when a player dies to e.g. remove stuff he was carrying.
56         // INPUT:
57                 entity frag_inflictor;
58                 entity frag_attacker;
59                 entity frag_target; // same as self
60
61 MUTATOR_HOOKABLE(GiveFragsForKill);
62         // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
63         // INPUT:
64                 entity frag_attacker; // same as self
65                 entity frag_target;
66         // INPUT, OUTPUT:
67                 float frag_score;
68
69 MUTATOR_HOOKABLE(MatchEnd);
70         // called when the match ends
71
72 MUTATOR_HOOKABLE(GetTeamCount);
73         // should adjust ret_float to contain the team count
74         // INPUT, OUTPUT:
75                 float ret_float;
76
77 MUTATOR_HOOKABLE(SpectateCopy);
78         // copies variables for spectating "other" to "self"
79         // INPUT:
80                 entity other;
81
82 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
83         // returns 1 if throwing the current weapon shall not be allowed
84
85 MUTATOR_HOOKABLE(SetStartItems);
86         // adjusts {warmup_}start_{items,weapons,ammo_{cells,rockets,nails,shells,fuel}}
87
88 MUTATOR_HOOKABLE(BuildMutatorsString);
89         // appends ":mutatorname" to ret_string for logging
90         // INPUT, OUTPUT:
91                 string ret_string;
92
93 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
94         // appends ", Mutator name" to ret_string for display
95         // INPUT, OUTPUT:
96                 string ret_string;
97
98 MUTATOR_HOOKABLE(FilterItem);
99         // 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)
100         // return error to request removal
101
102 MUTATOR_HOOKABLE(TurretSpawn);
103         // return error to request removal
104         // INPUT: self - turret
105         
106 MUTATOR_HOOKABLE(OnEntityPreSpawn);
107         // return error to prevent entity spawn, or modify the entity
108
109 MUTATOR_HOOKABLE(PlayerPreThink);
110         // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
111
112 MUTATOR_HOOKABLE(GetPressedKeys);
113         // TODO change this into a general PlayerPostThink hook?
114
115 MUTATOR_HOOKABLE(PlayerPhysics);
116         // called before any player physics, may adjust variables for movement,
117         // is run AFTER bot code and idle checking
118
119 MUTATOR_HOOKABLE(GetCvars);
120         // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
121         // INPUT:
122                 float get_cvars_f;
123                 string get_cvars_s;
124
125 MUTATOR_HOOKABLE(EditProjectile);
126         // can edit any "just fired" projectile
127         // INPUT:
128                 entity self;
129                 entity other;
130
131 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
132         // called when a player gets damaged to e.g. remove stuff he was carrying.
133         // INPUT:
134                 entity frag_inflictor;
135                 entity frag_attacker;
136                 entity frag_target; // same as self
137                 vector damage_force; // NOTE: this force already HAS been applied
138         // INPUT, OUTPUT:
139                 float damage_take;
140                 float damage_save;
141                 
142 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
143         // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier or runematch runes
144         // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
145         // INPUT:
146                 entity frag_attacker;
147                 entity frag_target;
148                 float frag_deathtype;
149         // INPUT, OUTPUT:
150                 float frag_damage;
151                 vector frag_force;
152
153 MUTATOR_HOOKABLE(PlayerPowerups);
154         // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
155         // INPUT
156         entity self;
157         float olditems; // also technically output, but since it is at the end of the function it's useless for that :P 
158
159 MUTATOR_HOOKABLE(PlayerUseKey);
160         // called when the use key is pressed
161         // if MUTATOR_RETURNVALUE is 1, don't do anything
162         // return 1 if the use key actually did something
163
164 MUTATOR_HOOKABLE(SV_ParseClientCommand);
165         // called when a client command is parsed
166         // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
167         // NOTE: return 1 if you handled the command, return 0 to continue handling
168         // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
169         // INPUT
170         string cmd_name; // command name
171         float cmd_argc; // also, argv() can be used
172         string cmd_string; // whole command, use only if you really have to
173         /*
174                 // example:
175                 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
176                 {
177                         if(MUTATOR_RETURNVALUE) // command was already handled?
178                                 return 0;
179                         if(cmd_name == "echocvar" && cmd_argc >= 2)
180                         {
181                                 print(cvar_string(argv(1)), "\n");
182                                 return 1;
183                         }
184                         if(cmd_name == "echostring" && cmd_argc >= 2)
185                         {
186                                 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
187                                 return 1;
188                         }
189                         return 0;
190                 }
191         */
192
193 MUTATOR_HOOKABLE(Spawn_Score);
194         // called when a spawnpoint is being evaluated
195         // return 1 to make the spawnpoint unusable
196         // INPUT
197         entity self; // player wanting to spawn
198         entity spawn_spot; // spot to be evaluated
199         // IN+OUT
200         vector spawn_score; // _x is priority, _y is "distance"
201
202 MUTATOR_HOOKABLE(SV_StartFrame);
203         // runs globally each server frame
204
205 MUTATOR_HOOKABLE(SetModname);
206         // OUT
207         string modname; // name of the mutator/mod if it warrants showing as such in the server browser