Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / sv_overkill.qc
1 #include "sv_overkill.qh"
2
3 #include "hmg.qh"
4 #include "rpc.qh"
5
6 bool autocvar_g_overkill_powerups_replace;
7 bool autocvar_g_overkill_ammo_charge;
8 float autocvar_g_overkill_ammo_charge_notice;
9 float autocvar_g_overkill_ammo_charge_limit;
10
11 bool autocvar_g_overkill_filter_healthmega;
12 bool autocvar_g_overkill_filter_armormedium;
13 bool autocvar_g_overkill_filter_armorbig;
14 bool autocvar_g_overkill_filter_armorlarge;
15
16 .float ok_item;
17
18 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
19
20 void ok_Initialize();
21
22 REGISTER_MUTATOR(ok, cvar("g_overkill") && !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill")
23 {
24         MUTATOR_ONADD
25         {
26                 ok_Initialize();
27         }
28
29         MUTATOR_ONREMOVE
30         {
31                 WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
32                 WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
33         }
34 }
35
36 void W_Blaster_Attack(entity, .entity, float, float, float, float, float, float, float, float, float, float);
37 spawnfunc(weapon_hmg);
38 spawnfunc(weapon_rpc);
39
40 MUTATOR_HOOKFUNCTION(ok, PlayerDamage_Calculate, CBC_ORDER_LAST)
41 {
42         entity frag_attacker = M_ARGV(1, entity);
43         entity frag_target = M_ARGV(2, entity);
44         float frag_deathtype = M_ARGV(3, float);
45
46         if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target))
47         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
48         {
49                 if(frag_attacker != frag_target)
50                 if(frag_target.health > 0)
51                 if(STAT(FROZEN, frag_target) == 0)
52                 if(!IS_DEAD(frag_target))
53                 {
54                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
55                         M_ARGV(6, vector) = '0 0 0'; // force
56                 }
57
58                 M_ARGV(4, float) = 0; // damage
59         }
60 }
61
62 void ok_DropItem(entity this, entity targ)
63 {
64         entity e = new(droppedweapon); // hax
65         e.ok_item = true;
66         e.noalign = true;
67         e.pickup_anyway = true;
68         e.spawnfunc_checked = true;
69         spawnfunc_item_armor_small(e);
70         if (!wasfreed(e)) { // might have been blocked by a mutator
71         set_movetype(e, MOVETYPE_TOSS);
72         e.gravity = 1;
73         e.reset = SUB_Remove;
74         setorigin(e, this.origin + '0 0 32');
75         e.velocity = '0 0 200' + normalize(targ.origin - this.origin) * 500;
76         SUB_SetFade(e, time + 5, 1);
77         }
78 }
79
80 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
81 {
82         entity frag_attacker = M_ARGV(1, entity);
83         entity frag_target = M_ARGV(2, entity);
84
85         entity targ = ((frag_attacker) ? frag_attacker : frag_target);
86
87         ok_DropItem(frag_target, targ);
88
89         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
90         {
91                 .entity weaponentity = weaponentities[slot];
92
93                 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
94         }
95 }
96
97 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
98 {
99         entity mon = M_ARGV(0, entity);
100         entity olditem = M_ARGV(1, entity);
101         entity frag_attacker = M_ARGV(2, entity);
102
103         delete(olditem);
104
105         M_ARGV(1, entity) = NULL;
106
107         ok_DropItem(mon, frag_attacker);
108 }
109
110 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
111 {
112         return true;
113 }
114
115 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
116 {
117         if(intermission_running || gameover)
118                 return;
119
120         entity player = M_ARGV(0, entity);
121
122         if(IS_DEAD(player) || !IS_PLAYER(player) || STAT(FROZEN, player))
123                 return;
124
125         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
126         {
127                 .entity weaponentity = weaponentities[slot];
128                 entity thiswep = player.(weaponentity);
129
130                 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
131                 {
132                         Weapon newwep = player.ok_lastwep[slot];
133                         if(player.ok_lastwep[slot] == WEP_HMG)
134                                 newwep = WEP_MACHINEGUN;
135                         if(player.ok_lastwep[slot] == WEP_RPC)
136                                 newwep = WEP_VORTEX;
137                         thiswep.m_switchweapon = newwep;
138                         player.ok_lastwep[slot] = WEP_Null;
139                 }
140         }
141
142         if(PHYS_INPUT_BUTTON_ATCK2(player))
143         if( !forbidWeaponUse(player) || player.weapon_blocked // allow if weapon is blocked
144                 || (round_handler_IsActive() && !round_handler_IsRoundStarted()) )
145         if(time >= player.jump_interval)
146         {
147                 player.jump_interval = time + WEP_CVAR_PRI(blaster, refire) * W_WeaponRateFactor(player);
148                 makevectors(player.v_angle);
149
150                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
151                 {
152                         .entity weaponentity = weaponentities[slot];
153
154                         if(player.(weaponentity).m_weapon == WEP_Null && slot != 0)
155                                 continue;
156
157                         Weapon oldwep = player.(weaponentity).m_weapon;
158                         player.(weaponentity).m_weapon = WEP_BLASTER;
159                         W_Blaster_Attack(
160                                 player,
161                                 weaponentity,
162                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
163                                 WEP_CVAR_SEC(vaporizer, shotangle),
164                                 WEP_CVAR_SEC(vaporizer, damage),
165                                 WEP_CVAR_SEC(vaporizer, edgedamage),
166                                 WEP_CVAR_SEC(vaporizer, radius),
167                                 WEP_CVAR_SEC(vaporizer, force),
168                                 WEP_CVAR_SEC(vaporizer, speed),
169                                 WEP_CVAR_SEC(vaporizer, spread),
170                                 WEP_CVAR_SEC(vaporizer, delay),
171                                 WEP_CVAR_SEC(vaporizer, lifetime)
172                         );
173                         player.(weaponentity).m_weapon = oldwep;
174                 }
175         }
176
177         PHYS_INPUT_BUTTON_ATCK2(player) = false;
178 }
179
180 MUTATOR_HOOKFUNCTION(ok, PlayerSpawn)
181 {
182         entity player = M_ARGV(0, entity);
183
184         // if player changed their weapon while dead, don't switch to their death weapon
185         if(player.impulse)
186         {
187                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
188                 {
189                         player.ok_lastwep[slot] = WEP_Null;
190                 }
191         }
192 }
193
194 void self_spawnfunc_weapon_hmg(entity this) { spawnfunc_weapon_hmg(this); }
195 void self_spawnfunc_weapon_rpc(entity this) { spawnfunc_weapon_rpc(this); }
196
197 MUTATOR_HOOKFUNCTION(ok, OnEntityPreSpawn)
198 {
199         entity ent = M_ARGV(0, entity);
200
201         if(autocvar_g_powerups)
202         if(autocvar_g_overkill_powerups_replace)
203         {
204                 if(ent.classname == "item_strength")
205                 {
206                         entity wep = new(weapon_hmg);
207                         setorigin(wep, ent.origin);
208                         setmodel(wep, MDL_OK_HMG);
209                         wep.ok_item = true;
210                         wep.noalign = ent.noalign;
211                         wep.cnt = ent.cnt;
212                         wep.team = ent.team;
213                         wep.respawntime = g_pickup_respawntime_superweapon;
214                         wep.pickup_anyway = true;
215                         wep.spawnfunc_checked = true;
216                         setthink(wep, self_spawnfunc_weapon_hmg);
217                         wep.nextthink = time + 0.1;
218                         return true;
219                 }
220
221                 if(ent.classname == "item_invincible")
222                 {
223                         entity wep = new(weapon_rpc);
224                         setorigin(wep, ent.origin);
225                         setmodel(wep, MDL_OK_RPC);
226                         wep.ok_item = true;
227                         wep.noalign = ent.noalign;
228                         wep.cnt = ent.cnt;
229                         wep.team = ent.team;
230                         wep.respawntime = g_pickup_respawntime_superweapon;
231                         wep.pickup_anyway = true;
232                         wep.spawnfunc_checked = true;
233                         setthink(wep, self_spawnfunc_weapon_rpc);
234                         wep.nextthink = time + 0.1;
235                         return true;
236                 }
237         }
238 }
239
240 MUTATOR_HOOKFUNCTION(ok, FilterItem)
241 {
242         entity item = M_ARGV(0, entity);
243
244         if(item.ok_item)
245                 return false;
246
247         switch(item.itemdef)
248         {
249                 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
250                 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
251                 // WARNING: next two statements look wrong because of inconsistency between cvar names and code
252                 // armor cvars need renaming to be consistent with their health counterparts
253                 case ITEM_ArmorLarge: return autocvar_g_overkill_filter_armorbig;
254                 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armorlarge;
255         }
256
257         return true;
258 }
259
260 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
261 {
262         WepSet ok_start_items = (WEPSET(MACHINEGUN) | WEPSET(VORTEX) | WEPSET(SHOTGUN));
263
264         if(WEP_RPC.weaponstart > 0) { ok_start_items |= WEPSET(RPC); }
265         if(WEP_HMG.weaponstart > 0) { ok_start_items |= WEPSET(HMG); }
266
267         start_items |= IT_UNLIMITED_WEAPON_AMMO;
268         start_weapons = warmup_start_weapons = ok_start_items;
269 }
270
271 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
272 {
273         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
274 }
275
276 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
277 {
278         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
279 }
280
281 MUTATOR_HOOKFUNCTION(ok, SetModname)
282 {
283         M_ARGV(0, string) = "Overkill";
284         return true;
285 }
286
287 void ok_SetCvars()
288 {
289         // hack to force overkill playermodels
290         cvar_settemp("sv_defaultcharacter", "1");
291         cvar_settemp("sv_defaultplayermodel", "models/ok_player/okrobot1.dpm models/ok_player/okrobot2.dpm models/ok_player/okrobot3.dpm models/ok_player/okrobot4.dpm models/ok_player/okmale1.dpm models/ok_player/okmale2.dpm models/ok_player/okmale3.dpm models/ok_player/okmale4.dpm");
292         cvar_settemp("sv_defaultplayermodel_red", "models/ok_player/okrobot1.dpm models/ok_player/okrobot2.dpm models/ok_player/okrobot3.dpm models/ok_player/okrobot4.dpm");
293         cvar_settemp("sv_defaultplayermodel_blue", "models/ok_player/okmale1.dpm models/ok_player/okmale2.dpm models/ok_player/okmale3.dpm models/ok_player/okmale4.dpm");
294 }
295
296 void ok_Initialize()
297 {
298         ok_SetCvars();
299
300         precache_all_playermodels("models/ok_player/*.dpm");
301
302         WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
303         WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
304
305         WEP_SHOTGUN.mdl = "ok_shotgun";
306         WEP_MACHINEGUN.mdl = "ok_mg";
307         WEP_VORTEX.mdl = "ok_sniper";
308 }