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