]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/base.qh
Merge branch 'master' into terencehill/menu_tooltips_2
[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 entity CallbackChain_New(string name);
7 float CallbackChain_Add(entity cb, float() func, float order)
8 float CallbackChain_Remove(entity cb, float() func);
9 // a callback function is like this:
10 // float mycallback(entity me)
11 // {
12 //   do something
13 //   return r;
14 // }
15 float CallbackChain_Call(entity cb);
16
17 #define MUTATOR_REMOVING 0
18 #define MUTATOR_ADDING 1
19 typedef float(float) mutatorfunc_t;
20 float Mutator_Add(mutatorfunc_t func, string name);
21 void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
22
23 #define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name, #name)
24 #define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name, #name)
25 #define MUTATOR_DEFINITION(name) float MUTATOR_##name(float mode)
26 #define MUTATOR_DECLARATION(name) float MUTATOR_##name(float mode)
27 #define MUTATOR_HOOKFUNCTION(name) float HOOKFUNCTION_##name()
28 #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)
29 #define MUTATOR_ONADD if(mode == MUTATOR_ADDING)
30 #define MUTATOR_ONREMOVE if(mode == MUTATOR_REMOVING)
31
32 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
33 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
34
35
36
37
38
39 // register all possible hooks here
40
41 MUTATOR_HOOKABLE(MakePlayerObserver);
42         // called when a player becomes observer, after shared setup
43
44 MUTATOR_HOOKABLE(PlayerSpawn);
45         // called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here)
46
47 MUTATOR_HOOKABLE(ClientDisconnect);
48         // called when a player disconnects
49
50 MUTATOR_HOOKABLE(PlayerDies);
51         // called when a player dies to e.g. remove stuff he was carrying.
52         // INPUT:
53                 entity frag_inflictor;
54                 entity frag_attacker;
55                 entity frag_target; // same as self
56
57 MUTATOR_HOOKABLE(GiveFragsForKill);
58         // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
59         // INPUT:
60                 entity frag_attacker; // same as self
61                 entity frag_target;
62         // INPUT, OUTPUT:
63                 float frag_score;
64
65 MUTATOR_HOOKABLE(MatchEnd);
66         // called when the match ends
67
68 MUTATOR_HOOKABLE(GetTeamCount);
69         // should adjust ret_float to contain the team count
70         // INPUT, OUTPUT:
71                 float ret_float;
72
73 MUTATOR_HOOKABLE(SpectateCopy);
74         // copies variables for spectating "other" to "self"
75         // INPUT:
76                 entity other;
77
78 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
79         // returns 1 if throwing the current weapon shall not be allowed
80
81 MUTATOR_HOOKABLE(SetStartItems);
82         // adjusts {warmup_}start_{items,weapons,ammo_{cells,rockets,nails,shells,fuel}}
83
84 MUTATOR_HOOKABLE(BuildMutatorsString);
85         // appends ":mutatorname" to ret_string for logging
86         // INPUT, OUTPUT:
87                 string ret_string;
88
89 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
90         // appends ", Mutator name" to ret_string for display
91         // INPUT, OUTPUT:
92                 string ret_string;
93
94 MUTATOR_HOOKABLE(FilterItem);
95         // 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)
96         // return error to request removal
97
98 MUTATOR_HOOKABLE(TurretSpawn);
99         // return error to request removal
100         // INPUT: self - turret
101         
102 MUTATOR_HOOKABLE(OnEntityPreSpawn);
103         // return error to prevent entity spawn, or modify the entity
104
105 MUTATOR_HOOKABLE(PlayerPreThink);
106         // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
107
108 MUTATOR_HOOKABLE(GetPressedKeys);
109         // TODO change this into a general PlayerPostThink hook?
110
111 MUTATOR_HOOKABLE(PlayerPhysics);
112         // called before any player physics, may adjust variables for movement,
113         // is run AFTER bot code and idle checking
114
115 MUTATOR_HOOKABLE(GetCvars);
116         // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
117         // INPUT:
118                 float get_cvars_f;
119                 string get_cvars_s;
120
121 MUTATOR_HOOKABLE(EditProjectile);
122         // can edit any "just fired" projectile
123         // INPUT:
124                 entity self;
125                 entity other;
126
127 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
128         // called when a player gets damaged to e.g. remove stuff he was carrying.
129         // INPUT:
130                 entity frag_inflictor;
131                 entity frag_attacker;
132                 entity frag_target; // same as self
133                 vector damage_force; // NOTE: this force already HAS been applied
134         // INPUT, OUTPUT:
135                 float damage_take;
136                 float damage_save;
137                 
138 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
139         // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier or runematch runes
140         // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
141         // INPUT:
142                 entity frag_attacker;
143                 entity frag_target;
144                 float frag_deathtype;
145         // INPUT, OUTPUT:
146                 float frag_damage;
147                 vector frag_force;
148
149 MUTATOR_HOOKABLE(PlayerPowerups);
150         // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
151         // INPUT
152         entity self;
153         float olditems; // also technically output, but since it is at the end of the function it's useless for that :P