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