]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/overkill.qc
19e88cd6387ce6d863a160868a1b393e372714af
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / overkill.qc
1 #ifdef IMPLEMENTATION
2 bool autocvar_g_overkill_powerups_replace;
3 float autocvar_g_overkill_superguns_respawn_time;
4 bool autocvar_g_overkill_100h_anyway;
5 bool autocvar_g_overkill_100a_anyway;
6 bool autocvar_g_overkill_ammo_charge;
7 float autocvar_g_overkill_ammo_charge_notice;
8 float autocvar_g_overkill_ammo_charge_limit;
9
10 .vector ok_deathloc;
11 .float ok_spawnsys_timer;
12 .float ok_lastwep;
13 .float ok_item;
14
15 .float ok_notice_time;
16 .float ammo_charge[Weapons_MAX];
17 .float ok_use_ammocharge = _STAT(OK_AMMO_CHARGE);
18 .float ok_ammo_charge = _STAT(OK_AMMO_CHARGEPOOL);
19
20 .float ok_pauseregen_finished;
21
22 void(entity ent, float wep) ok_DecreaseCharge;
23
24 void ok_Initialize();
25
26 REGISTER_MUTATOR(ok, cvar("g_overkill") && !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill")
27 {
28         MUTATOR_ONADD
29         {
30                 ok_Initialize();
31         }
32
33         MUTATOR_ONREMOVE
34         {
35                 WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
36                 WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
37         }
38 }
39
40 MUTATOR_HOOKFUNCTION(ok, W_DecreaseAmmo)
41 {
42         entity actor = M_ARGV(0, entity);
43         if (actor.ok_use_ammocharge)
44         {
45                 ok_DecreaseCharge(actor, PS(actor).m_weapon.m_id);
46                 return true;
47         }
48 }
49
50 MUTATOR_HOOKFUNCTION(ok, W_Reload)
51 {
52         entity actor = M_ARGV(0, entity);
53         return actor.ok_use_ammocharge;
54 }
55
56 void W_Blaster_Attack(entity, float, float, float, float, float, float, float, float, float, float);
57 spawnfunc(weapon_hmg);
58 spawnfunc(weapon_rpc);
59
60 void ok_DecreaseCharge(entity ent, int wep)
61 {
62         if(!ent.ok_use_ammocharge) return;
63
64         entity wepent = Weapons_from(wep);
65
66         if (wepent == WEP_Null) return;  // dummy
67
68         ent.ammo_charge[wep] -= max(0, cvar(sprintf("g_overkill_ammo_decharge_%s", wepent.netname)));
69 }
70
71 void ok_IncreaseCharge(entity ent, int wep)
72 {
73         entity wepent = Weapons_from(wep);
74
75         if (wepent == WEP_Null) return;  // dummy
76
77         if(ent.ok_use_ammocharge)
78         if(!PHYS_INPUT_BUTTON_ATCK(ent)) // not while attacking?
79                 ent.ammo_charge[wep] = min(autocvar_g_overkill_ammo_charge_limit, ent.ammo_charge[wep] + cvar(sprintf("g_overkill_ammo_charge_rate_%s", wepent.netname)) * frametime / W_TICSPERFRAME);
80 }
81
82 float ok_CheckWeaponCharge(entity ent, int wep)
83 {
84         if(!ent.ok_use_ammocharge) return true;
85
86         entity wepent = Weapons_from(wep);
87
88         if(wepent == WEP_Null) return false;  // dummy
89
90         return (ent.ammo_charge[wep] >= cvar(sprintf("g_overkill_ammo_decharge_%s", wepent.netname)));
91 }
92
93 MUTATOR_HOOKFUNCTION(ok, PlayerDamage_Calculate, CBC_ORDER_LAST)
94 {
95         entity frag_attacker = M_ARGV(1, entity);
96         entity frag_target = M_ARGV(2, entity);
97         float frag_deathtype = M_ARGV(3, float);
98
99         if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target))
100         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
101         {
102                 if(frag_attacker != frag_target)
103                 if(frag_target.health > 0)
104                 if(STAT(FROZEN, frag_target) == 0)
105                 if(!IS_DEAD(frag_target))
106                 {
107                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
108                         M_ARGV(6, vector) = '0 0 0';
109                 }
110
111                 M_ARGV(4, float) = 0;
112         }
113 }
114
115 MUTATOR_HOOKFUNCTION(ok, PlayerDamage_SplitHealthArmor)
116 {
117         entity frag_target = M_ARGV(2, entity);
118         float damage_take = M_ARGV(4, float);
119
120         if(damage_take)
121                 frag_target.ok_pauseregen_finished = max(frag_target.ok_pauseregen_finished, time + 2);
122 }
123
124 void ok_DropItem(entity this, entity targ)
125 {
126         entity e = new(droppedweapon); // hax
127         e.ok_item = true;
128         e.noalign = true;
129         e.pickup_anyway = true;
130         e.spawnfunc_checked = true;
131         WITHSELF(e, spawnfunc_item_armor_small(e));
132         if (!wasfreed(e)) { // might have been blocked by a mutator
133         e.movetype = MOVETYPE_TOSS;
134         e.gravity = 1;
135         e.reset = SUB_Remove;
136         setorigin(e, this.origin + '0 0 32');
137         e.velocity = '0 0 200' + normalize(targ.origin - this.origin) * 500;
138         SUB_SetFade(e, time + 5, 1);
139         }
140 }
141
142 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
143 {
144         entity frag_attacker = M_ARGV(1, entity);
145         entity frag_target = M_ARGV(2, entity);
146
147         entity targ = ((frag_attacker) ? frag_attacker : frag_target);
148
149         ok_DropItem(frag_target, targ);
150
151         frag_target.ok_lastwep = PS(frag_target).m_switchweapon.m_id;
152 }
153
154 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
155 {
156         entity mon = M_ARGV(0, entity);
157         entity olditem = M_ARGV(1, entity);
158         entity frag_attacker = M_ARGV(2, entity);
159
160         remove(olditem);
161
162         M_ARGV(1, entity) = NULL;
163
164         ok_DropItem(mon, frag_attacker);
165 }
166
167 MUTATOR_HOOKFUNCTION(ok, PlayerRegen)
168 {SELFPARAM();
169         // overkill's values are different, so use custom regen
170         if(!STAT(FROZEN, self))
171         {
172                 self.armorvalue = CalcRotRegen(self.armorvalue, autocvar_g_balance_armor_regenstable, autocvar_g_balance_armor_regen, autocvar_g_balance_armor_regenlinear, 1 * frametime * (time > self.ok_pauseregen_finished), 0, 0, 1, 1 * frametime * (time > self.pauserotarmor_finished), autocvar_g_balance_armor_limit);
173                 self.health = CalcRotRegen(self.health, autocvar_g_balance_health_regenstable, 0, 100, 1 * frametime * (time > self.ok_pauseregen_finished), 200, 0, autocvar_g_balance_health_rotlinear, 1 * frametime * (time > self.pauserothealth_finished), autocvar_g_balance_health_limit);
174
175                 float minf, maxf, limitf;
176
177                 maxf = autocvar_g_balance_fuel_rotstable;
178                 minf = autocvar_g_balance_fuel_regenstable;
179                 limitf = autocvar_g_balance_fuel_limit;
180
181                 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, frametime * (time > self.pauseregen_finished) * ((self.items & ITEM_JetpackRegen.m_itemid) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > self.pauserotfuel_finished), limitf);
182         }
183         return true; // return true anyway, as frozen uses no regen
184 }
185
186 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
187 {
188         return true;
189 }
190
191 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
192 {
193         if(intermission_running || gameover)
194                 return;
195
196         entity player = M_ARGV(0, entity);
197
198         if(IS_DEAD(player) || !IS_PLAYER(player) || STAT(FROZEN, player))
199                 return;
200
201         if(player.ok_lastwep)
202         {
203                 Weapon newwep = Weapons_from(player.ok_lastwep);
204                 if(player.ok_lastwep == WEP_HMG.m_id)
205                         newwep = WEP_MACHINEGUN;
206                 if(player.ok_lastwep == WEP_RPC.m_id)
207                         newwep = WEP_VORTEX;
208                 PS(player).m_switchweapon = newwep;
209                 player.ok_lastwep = 0;
210         }
211
212         ok_IncreaseCharge(player, PS(player).m_weapon.m_id);
213
214         if(PHYS_INPUT_BUTTON_ATCK2(player))
215         if(!forbidWeaponUse(player) || player.weapon_blocked) // allow if weapon is blocked
216         if(time >= player.jump_interval)
217         {
218                 player.jump_interval = time + WEP_CVAR_PRI(blaster, refire) * W_WeaponRateFactor(player);
219                 makevectors(player.v_angle);
220
221                 Weapon oldwep = PS(player).m_weapon;
222                 PS(player).m_weapon = WEP_BLASTER;
223                 W_Blaster_Attack(
224                         player,
225                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
226                         WEP_CVAR_SEC(vaporizer, shotangle),
227                         WEP_CVAR_SEC(vaporizer, damage),
228                         WEP_CVAR_SEC(vaporizer, edgedamage),
229                         WEP_CVAR_SEC(vaporizer, radius),
230                         WEP_CVAR_SEC(vaporizer, force),
231                         WEP_CVAR_SEC(vaporizer, speed),
232                         WEP_CVAR_SEC(vaporizer, spread),
233                         WEP_CVAR_SEC(vaporizer, delay),
234                         WEP_CVAR_SEC(vaporizer, lifetime)
235                 );
236                 PS(player).m_weapon = oldwep;
237         }
238
239         player.weapon_blocked = false;
240
241         player.ok_ammo_charge = player.ammo_charge[PS(player).m_weapon.m_id];
242
243         if(player.ok_use_ammocharge)
244         if(!ok_CheckWeaponCharge(player, PS(player).m_weapon.m_id))
245         {
246                 if(autocvar_g_overkill_ammo_charge_notice && time > player.ok_notice_time && PHYS_INPUT_BUTTON_ATCK(player) && IS_REAL_CLIENT(player) && PS(player).m_weapon == PS(player).m_switchweapon)
247                 {
248                         //Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERKILL_CHARGE);
249                         player.ok_notice_time = time + 2;
250                         play2(player, SND(DRYFIRE));
251                 }
252                 Weapon wpn = PS(player).m_weapon;
253                 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
254                 if(player.(weaponentity).state != WS_CLEAR)
255                         w_ready(wpn, player, weaponentity, PHYS_INPUT_BUTTON_ATCK(player) | (PHYS_INPUT_BUTTON_ATCK2(player) << 1));
256
257                 player.weapon_blocked = true;
258         }
259
260         PHYS_INPUT_BUTTON_ATCK2(player) = false;
261 }
262
263 MUTATOR_HOOKFUNCTION(ok, PlayerSpawn)
264 {
265         entity player = M_ARGV(0, entity);
266
267         if(autocvar_g_overkill_ammo_charge)
268         {
269                 FOREACH(Weapons, it != WEP_Null, LAMBDA(player.ammo_charge[it.m_id] = autocvar_g_overkill_ammo_charge_limit));
270
271                 player.ok_use_ammocharge = 1;
272                 player.ok_notice_time = time;
273         }
274         else
275                 player.ok_use_ammocharge = 0;
276
277         // if player changed their weapon while dead, don't switch to their death weapon
278         if(player.impulse)
279                 player.ok_lastwep = 0;
280
281         player.ok_pauseregen_finished = time + 2;
282 }
283
284 void self_spawnfunc_weapon_hmg(entity this) { spawnfunc_weapon_hmg(this); }
285 void self_spawnfunc_weapon_rpc(entity this) { spawnfunc_weapon_rpc(this); }
286
287 MUTATOR_HOOKFUNCTION(ok, OnEntityPreSpawn)
288 {
289         entity ent = M_ARGV(0, entity);
290
291         if(autocvar_g_powerups)
292         if(autocvar_g_overkill_powerups_replace)
293         {
294                 if(ent.classname == "item_strength")
295                 {
296                         entity wep = new(weapon_hmg);
297                         setorigin(wep, ent.origin);
298                         setmodel(wep, MDL_OK_HMG);
299                         wep.ok_item = true;
300                         wep.noalign = ent.noalign;
301                         wep.cnt = ent.cnt;
302                         wep.team = ent.team;
303                         wep.respawntime = autocvar_g_overkill_superguns_respawn_time;
304                         wep.pickup_anyway = true;
305                         wep.spawnfunc_checked = true;
306                         setthink(wep, self_spawnfunc_weapon_hmg);
307                         wep.nextthink = time + 0.1;
308                         return true;
309                 }
310
311                 if(ent.classname == "item_invincible")
312                 {
313                         entity wep = new(weapon_rpc);
314                         setorigin(wep, ent.origin);
315                         setmodel(wep, MDL_OK_RPC);
316                         wep.ok_item = true;
317                         wep.noalign = ent.noalign;
318                         wep.cnt = ent.cnt;
319                         wep.team = ent.team;
320                         wep.respawntime = autocvar_g_overkill_superguns_respawn_time;
321                         wep.pickup_anyway = true;
322                         wep.spawnfunc_checked = true;
323                         setthink(wep, self_spawnfunc_weapon_rpc);
324                         wep.nextthink = time + 0.1;
325                         return true;
326                 }
327         }
328 }
329
330 MUTATOR_HOOKFUNCTION(ok, FilterItem)
331 {
332         entity item = M_ARGV(0, entity);
333
334         if(item.ok_item)
335                 return;
336
337         switch(item.items)
338         {
339                 case ITEM_HealthMega.m_itemid: return !(autocvar_g_overkill_100h_anyway);
340                 case ITEM_ArmorMega.m_itemid: return !(autocvar_g_overkill_100a_anyway);
341         }
342
343         return true;
344 }
345
346 MUTATOR_HOOKFUNCTION(ok, SpectateCopy)
347 {
348         entity spectatee = M_ARGV(0, entity);
349         entity client = M_ARGV(1, entity);
350
351         client.ammo_charge[PS(client).m_weapon.m_id] = spectatee.ammo_charge[PS(spectatee).m_weapon.m_id];
352         client.ok_use_ammocharge = spectatee.ok_use_ammocharge;
353 }
354
355 MUTATOR_HOOKFUNCTION(ok, SetStartItems)
356 {
357         WepSet ok_start_items = (WEPSET(MACHINEGUN) | WEPSET(VORTEX) | WEPSET(SHOTGUN));
358
359         if(WEP_RPC.weaponstart > 0) { ok_start_items |= WEPSET(RPC); }
360         if(WEP_HMG.weaponstart > 0) { ok_start_items |= WEPSET(HMG); }
361
362         start_items |= IT_UNLIMITED_WEAPON_AMMO;
363         start_weapons = warmup_start_weapons = ok_start_items;
364 }
365
366 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
367 {
368         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
369 }
370
371 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
372 {
373         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
374 }
375
376 MUTATOR_HOOKFUNCTION(ok, SetModname)
377 {
378         M_ARGV(0, string) = "Overkill";
379         return true;
380 }
381
382 void ok_SetCvars()
383 {
384         // hack to force overkill playermodels
385         cvar_settemp("sv_defaultcharacter", "1");
386         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");
387         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");
388         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");
389 }
390
391 void ok_Initialize()
392 {
393         ok_SetCvars();
394
395         precache_all_playermodels("models/ok_player/*.dpm");
396
397         WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
398         WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
399
400         WEP_SHOTGUN.mdl = "ok_shotgun";
401         WEP_MACHINEGUN.mdl = "ok_mg";
402         WEP_VORTEX.mdl = "ok_sniper";
403 }
404 #endif