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