]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_overkill.qc
Merge branch 'master' into Mario/vehicles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_overkill.qc
1 #include "mutator_overkill.qh"
2 #include "../_all.qh"
3
4 #include "mutator.qh"
5
6 void W_Blaster_Attack(float, float, float, float, float, float, float, float, float, float);
7 void spawnfunc_weapon_hmg();
8 void spawnfunc_weapon_rpc();
9
10 void ok_DecreaseCharge(entity ent, int wep)
11 {
12         if(!ent.ok_use_ammocharge) return;
13
14         entity wepent = get_weaponinfo(wep);
15
16         if(wepent.weapon == 0)
17                 return; // dummy
18
19         ent.ammo_charge[wep] -= max(0, cvar(sprintf("g_overkill_ammo_decharge_%s", wepent.netname)));
20 }
21
22 void ok_IncreaseCharge(entity ent, int wep)
23 {
24         entity wepent = get_weaponinfo(wep);
25
26         if(wepent.weapon == 0)
27                 return; // dummy
28
29         if(ent.ok_use_ammocharge)
30         if(!ent.BUTTON_ATCK) // not while attacking?
31                 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);
32 }
33
34 float ok_CheckWeaponCharge(entity ent, int wep)
35 {
36         if(!ent.ok_use_ammocharge) return true;
37
38         entity wepent = get_weaponinfo(wep);
39
40         if(wepent.weapon == 0)
41                 return 0; // dummy
42
43         return (ent.ammo_charge[wep] >= cvar(sprintf("g_overkill_ammo_decharge_%s", wepent.netname)));
44 }
45
46 MUTATOR_HOOKFUNCTION(ok_PlayerDamage_Calculate)
47 {
48         if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target))
49         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER.m_id))
50         {
51                 frag_damage = 0;
52
53                 if(frag_attacker != frag_target)
54                 if(frag_target.health > 0)
55                 if(frag_target.frozen == 0)
56                 if(frag_target.deadflag == DEAD_NO)
57                 {
58                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
59                         frag_force = '0 0 0';
60                 }
61         }
62
63         return false;
64 }
65
66 MUTATOR_HOOKFUNCTION(ok_PlayerDamage_SplitHealthArmor)
67 {
68         if(damage_take)
69                 self.ok_pauseregen_finished = max(self.ok_pauseregen_finished, time + 2);
70         return false;
71 }
72
73 MUTATOR_HOOKFUNCTION(ok_PlayerDies)
74 {
75         entity oldself = self;
76         entity targ = ((frag_attacker) ? frag_attacker : frag_target);
77
78         if(IS_MONSTER(self))
79         {
80                 remove(other); // remove default item
81                 other = world;
82         }
83
84         self = spawn();
85         self.ok_item = true;
86         self.noalign = true;
87         self.pickup_anyway = true;
88         spawnfunc_item_armor_small();
89         self.movetype = MOVETYPE_TOSS;
90         self.gravity = 1;
91         self.reset = SUB_Remove;
92         setorigin(self, frag_target.origin + '0 0 32');
93         self.velocity = '0 0 200' + normalize(targ.origin - self.origin) * 500;
94         self.classname = "droppedweapon"; // hax
95         SUB_SetFade(self, time + 5, 1);
96         self = oldself;
97
98         self.ok_lastwep = self.switchweapon;
99
100         return false;
101 }
102
103 MUTATOR_HOOKFUNCTION(ok_PlayerRegen)
104 {
105         // overkill's values are different, so use custom regen
106         if(!self.frozen)
107         {
108                 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);
109                 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);
110
111                 float minf, maxf, limitf;
112
113                 maxf = autocvar_g_balance_fuel_rotstable;
114                 minf = autocvar_g_balance_fuel_regenstable;
115                 limitf = autocvar_g_balance_fuel_limit;
116
117                 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);
118         }
119         return true; // return true anyway, as frozen uses no regen
120 }
121
122 MUTATOR_HOOKFUNCTION(ok_ForbidThrowCurrentWeapon)
123 {
124         return true;
125 }
126
127 MUTATOR_HOOKFUNCTION(ok_PlayerPreThink)
128 {
129         if(intermission_running || gameover)
130                 return false;
131
132         if(self.deadflag != DEAD_NO || !IS_PLAYER(self) || self.frozen)
133                 return false;
134
135         if(self.ok_lastwep)
136         {
137                 self.switchweapon = self.ok_lastwep;
138                 self.ok_lastwep = 0;
139         }
140
141         ok_IncreaseCharge(self, self.weapon);
142
143         if(self.BUTTON_ATCK2)
144         if(!forbidWeaponUse(self) || self.weapon_blocked) // allow if weapon is blocked
145         if(time >= self.jump_interval)
146         {
147                 self.jump_interval = time + WEP_CVAR_PRI(blaster, refire) * W_WeaponRateFactor();
148                 makevectors(self.v_angle);
149
150                 int oldwep = self.weapon;
151                 self.weapon = WEP_BLASTER.m_id;
152                 W_Blaster_Attack(
153                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
154                         WEP_CVAR_SEC(vaporizer, shotangle),
155                         WEP_CVAR_SEC(vaporizer, damage),
156                         WEP_CVAR_SEC(vaporizer, edgedamage),
157                         WEP_CVAR_SEC(vaporizer, radius),
158                         WEP_CVAR_SEC(vaporizer, force),
159                         WEP_CVAR_SEC(vaporizer, speed),
160                         WEP_CVAR_SEC(vaporizer, spread),
161                         WEP_CVAR_SEC(vaporizer, delay),
162                         WEP_CVAR_SEC(vaporizer, lifetime)
163                 );
164                 self.weapon = oldwep;
165         }
166
167         self.weapon_blocked = false;
168
169         self.ok_ammo_charge = self.ammo_charge[self.weapon];
170
171         if(self.ok_use_ammocharge)
172         if(!ok_CheckWeaponCharge(self, self.weapon))
173         {
174                 if(autocvar_g_overkill_ammo_charge_notice && time > self.ok_notice_time && self.BUTTON_ATCK && IS_REAL_CLIENT(self) && self.weapon == self.switchweapon)
175                 {
176                         //Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERKILL_CHARGE);
177                         self.ok_notice_time = time + 2;
178                         play2(self, "weapons/dryfire.wav");
179                 }
180                 if(self.weaponentity.state != WS_CLEAR)
181                         w_ready();
182
183                 self.weapon_blocked = true;
184         }
185
186         self.BUTTON_ATCK2 = 0;
187
188         return false;
189 }
190
191 MUTATOR_HOOKFUNCTION(ok_PlayerSpawn)
192 {
193         if(autocvar_g_overkill_ammo_charge)
194         {
195                 for(int i = WEP_FIRST; i <= WEP_LAST; ++i)
196                         self.ammo_charge[i] = autocvar_g_overkill_ammo_charge_limit;
197
198                 self.ok_use_ammocharge = 1;
199                 self.ok_notice_time = time;
200         }
201         else
202                 self.ok_use_ammocharge = 0;
203
204         self.ok_pauseregen_finished = time + 2;
205
206         return false;
207 }
208
209 MUTATOR_HOOKFUNCTION(ok_OnEntityPreSpawn)
210 {
211         if(autocvar_g_powerups)
212         if(autocvar_g_overkill_powerups_replace)
213         {
214                 if(self.classname == "item_strength")
215                 {
216                         entity wep = spawn();
217                         setorigin(wep, self.origin);
218                         setmodel(wep, "models/weapons/g_ok_hmg.md3");
219                         wep.classname = "weapon_hmg";
220                         wep.ok_item = true;
221                         wep.noalign = self.noalign;
222                         wep.cnt = self.cnt;
223                         wep.team = self.team;
224                         wep.respawntime = autocvar_g_overkill_superguns_respawn_time;
225                         wep.pickup_anyway = true;
226                         wep.think = spawnfunc_weapon_hmg;
227                         wep.nextthink = time + 0.1;
228                         return true;
229                 }
230
231                 if(self.classname == "item_invincible")
232                 {
233                         entity wep = spawn();
234                         setorigin(wep, self.origin);
235                         setmodel(wep, "models/weapons/g_ok_rl.md3");
236                         wep.classname = "weapon_rpc";
237                         wep.ok_item = true;
238                         wep.noalign = self.noalign;
239                         wep.cnt = self.cnt;
240                         wep.team = self.team;
241                         wep.respawntime = autocvar_g_overkill_superguns_respawn_time;
242                         wep.pickup_anyway = true;
243                         wep.think = spawnfunc_weapon_rpc;
244                         wep.nextthink = time + 0.1;
245                         return true;
246                 }
247         }
248
249         return false;
250 }
251
252 MUTATOR_HOOKFUNCTION(ok_ItemRemove)
253 {
254         if(self.ok_item)
255                 return false;
256
257         switch(self.items)
258         {
259                 case ITEM_HealthMega.m_itemid: return !(autocvar_g_overkill_100h_anyway);
260                 case ITEM_ArmorMega.m_itemid: return !(autocvar_g_overkill_100a_anyway);
261         }
262
263         return true;
264 }
265
266 MUTATOR_HOOKFUNCTION(ok_SpectateCopy)
267 {
268         self.ammo_charge[self.weapon] = other.ammo_charge[other.weapon];
269         self.ok_use_ammocharge = other.ok_use_ammocharge;
270
271         return false;
272 }
273
274 MUTATOR_HOOKFUNCTION(ok_StartItems)
275 {
276         WepSet ok_start_items = (WEPSET_MACHINEGUN | WEPSET_VORTEX | WEPSET_SHOTGUN);
277
278         if(WEP_RPC.weaponstart > 0) { ok_start_items |= WEPSET_RPC; }
279         if(WEP_HMG.weaponstart > 0) { ok_start_items |= WEPSET_HMG; }
280
281         start_items |= IT_UNLIMITED_WEAPON_AMMO;
282         start_weapons = warmup_start_weapons = ok_start_items;
283
284         return false;
285 }
286
287 MUTATOR_HOOKFUNCTION(ok_BuildMutatorsString)
288 {
289         ret_string = strcat(ret_string, ":OK");
290         return false;
291 }
292
293 MUTATOR_HOOKFUNCTION(ok_BuildMutatorsPrettyString)
294 {
295         ret_string = strcat(ret_string, ", Overkill");
296         return false;
297 }
298
299 MUTATOR_HOOKFUNCTION(ok_SetModname)
300 {
301         modname = "Overkill";
302         return true;
303 }
304
305 void ok_SetCvars()
306 {
307         // hack to force overkill playermodels
308         cvar_settemp("sv_defaultcharacter", "1");
309         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");
310         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");
311         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");
312 }
313
314 void ok_Initialize()
315 {
316         ok_SetCvars();
317
318         precache_all_playermodels("models/ok_player/*.dpm");
319
320         precache_model("models/weapons/h_ok_mg.iqm");
321         precache_model("models/weapons/v_ok_mg.md3");
322         precache_model("models/weapons/g_ok_mg.md3");
323
324         precache_model("models/weapons/h_ok_shotgun.iqm");
325         precache_model("models/weapons/v_ok_shotgun.md3");
326         precache_model("models/weapons/g_ok_shotgun.md3");
327
328         precache_model("models/weapons/h_ok_sniper.iqm");
329         precache_model("models/weapons/v_ok_sniper.md3");
330         precache_model("models/weapons/g_ok_sniper.md3");
331
332         precache_sound("weapons/dryfire.wav");
333
334         addstat(STAT_OK_AMMO_CHARGE, AS_FLOAT, ok_use_ammocharge);
335         addstat(STAT_OK_AMMO_CHARGEPOOL, AS_FLOAT, ok_ammo_charge);
336
337         WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
338         WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
339
340         WEP_SHOTGUN.mdl = "ok_shotgun";
341         WEP_MACHINEGUN.mdl = "ok_mg";
342         WEP_VORTEX.mdl = "ok_sniper";
343 }
344
345 MUTATOR_DEFINITION(mutator_overkill)
346 {
347         MUTATOR_HOOK(ForbidThrowCurrentWeapon, ok_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
348         MUTATOR_HOOK(PlayerPreThink, ok_PlayerPreThink, CBC_ORDER_LAST);
349         MUTATOR_HOOK(PlayerSpawn, ok_PlayerSpawn, CBC_ORDER_ANY);
350         MUTATOR_HOOK(PlayerDamage_Calculate, ok_PlayerDamage_Calculate, CBC_ORDER_LAST);
351         MUTATOR_HOOK(PlayerDamage_SplitHealthArmor, ok_PlayerDamage_SplitHealthArmor, CBC_ORDER_ANY);
352         MUTATOR_HOOK(PlayerDies, ok_PlayerDies, CBC_ORDER_ANY);
353         MUTATOR_HOOK(PlayerRegen, ok_PlayerRegen, CBC_ORDER_ANY);
354         MUTATOR_HOOK(OnEntityPreSpawn, ok_OnEntityPreSpawn, CBC_ORDER_ANY);
355         MUTATOR_HOOK(FilterItem, ok_ItemRemove, CBC_ORDER_ANY);
356         MUTATOR_HOOK(MonsterDropItem, ok_PlayerDies, CBC_ORDER_ANY);
357         MUTATOR_HOOK(SpectateCopy, ok_SpectateCopy, CBC_ORDER_ANY);
358         MUTATOR_HOOK(SetStartItems, ok_StartItems, CBC_ORDER_ANY);
359         MUTATOR_HOOK(BuildMutatorsString, ok_BuildMutatorsString, CBC_ORDER_ANY);
360         MUTATOR_HOOK(BuildMutatorsPrettyString, ok_BuildMutatorsPrettyString, CBC_ORDER_ANY);
361         MUTATOR_HOOK(SetModname, ok_SetModname, CBC_ORDER_ANY);
362
363         MUTATOR_ONADD
364         {
365                 ok_Initialize();
366         }
367
368         MUTATOR_ONREMOVE
369         {
370                 WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
371                 WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
372         }
373
374         return false;
375 }