]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_overkill.qc
Merge branch 'master' into TimePath/deathtypes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_overkill.qc
1 #include "mutator_overkill.qh"
2
3 #include "mutator.qh"
4
5 void W_Blaster_Attack(entity, float, float, float, float, float, float, float, float, float, float);
6 spawnfunc(weapon_hmg);
7 spawnfunc(weapon_rpc);
8
9 void ok_DecreaseCharge(entity ent, int wep)
10 {
11         if(!ent.ok_use_ammocharge) return;
12
13         entity wepent = get_weaponinfo(wep);
14
15         if(wepent.weapon == 0)
16                 return; // dummy
17
18         ent.ammo_charge[wep] -= max(0, cvar(sprintf("g_overkill_ammo_decharge_%s", wepent.netname)));
19 }
20
21 void ok_IncreaseCharge(entity ent, int wep)
22 {
23         entity wepent = get_weaponinfo(wep);
24
25         if(wepent.weapon == 0)
26                 return; // dummy
27
28         if(ent.ok_use_ammocharge)
29         if(!ent.BUTTON_ATCK) // not while attacking?
30                 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);
31 }
32
33 float ok_CheckWeaponCharge(entity ent, int wep)
34 {
35         if(!ent.ok_use_ammocharge) return true;
36
37         entity wepent = get_weaponinfo(wep);
38
39         if(wepent.weapon == 0)
40                 return 0; // dummy
41
42         return (ent.ammo_charge[wep] >= cvar(sprintf("g_overkill_ammo_decharge_%s", wepent.netname)));
43 }
44
45 MUTATOR_HOOKFUNCTION(ok_PlayerDamage_Calculate)
46 {
47         if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target))
48         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
49         {
50                 frag_damage = 0;
51
52                 if(frag_attacker != frag_target)
53                 if(frag_target.health > 0)
54                 if(frag_target.frozen == 0)
55                 if(frag_target.deadflag == DEAD_NO)
56                 {
57                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
58                         frag_force = '0 0 0';
59                 }
60         }
61
62         return false;
63 }
64
65 MUTATOR_HOOKFUNCTION(ok_PlayerDamage_SplitHealthArmor)
66 {SELFPARAM();
67         if(damage_take)
68                 self.ok_pauseregen_finished = max(self.ok_pauseregen_finished, time + 2);
69         return false;
70 }
71
72 MUTATOR_HOOKFUNCTION(ok_PlayerDies)
73 {SELFPARAM();
74         entity targ = ((frag_attacker) ? frag_attacker : frag_target);
75
76         if(IS_MONSTER(self))
77         {
78                 remove(other); // remove default item
79                 other = world;
80         }
81
82         setself(spawn());
83         self.ok_item = true;
84         self.noalign = true;
85         self.pickup_anyway = true;
86         spawnfunc_item_armor_small(this);
87         self.movetype = MOVETYPE_TOSS;
88         self.gravity = 1;
89         self.reset = SUB_Remove;
90         setorigin(self, frag_target.origin + '0 0 32');
91         self.velocity = '0 0 200' + normalize(targ.origin - self.origin) * 500;
92         self.classname = "droppedweapon"; // hax
93         SUB_SetFade(self, time + 5, 1);
94         setself(this);
95
96         self.ok_lastwep = self.switchweapon;
97
98         return false;
99 }
100
101 MUTATOR_HOOKFUNCTION(ok_PlayerRegen)
102 {SELFPARAM();
103         // overkill's values are different, so use custom regen
104         if(!self.frozen)
105         {
106                 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);
107                 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);
108
109                 float minf, maxf, limitf;
110
111                 maxf = autocvar_g_balance_fuel_rotstable;
112                 minf = autocvar_g_balance_fuel_regenstable;
113                 limitf = autocvar_g_balance_fuel_limit;
114
115                 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);
116         }
117         return true; // return true anyway, as frozen uses no regen
118 }
119
120 MUTATOR_HOOKFUNCTION(ok_ForbidThrowCurrentWeapon)
121 {
122         return true;
123 }
124
125 MUTATOR_HOOKFUNCTION(ok_PlayerPreThink)
126 {SELFPARAM();
127         if(intermission_running || gameover)
128                 return false;
129
130         if(self.deadflag != DEAD_NO || !IS_PLAYER(self) || self.frozen)
131                 return false;
132
133         if(self.ok_lastwep)
134         {
135                 self.switchweapon = self.ok_lastwep;
136                 self.ok_lastwep = 0;
137         }
138
139         ok_IncreaseCharge(self, self.weapon);
140
141         if(self.BUTTON_ATCK2)
142         if(!forbidWeaponUse(self) || self.weapon_blocked) // allow if weapon is blocked
143         if(time >= self.jump_interval)
144         {
145                 self.jump_interval = time + WEP_CVAR_PRI(blaster, refire) * W_WeaponRateFactor();
146                 makevectors(self.v_angle);
147
148                 int oldwep = self.weapon;
149                 self.weapon = WEP_BLASTER.m_id;
150                 W_Blaster_Attack(
151                         self,
152                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
153                         WEP_CVAR_SEC(vaporizer, shotangle),
154                         WEP_CVAR_SEC(vaporizer, damage),
155                         WEP_CVAR_SEC(vaporizer, edgedamage),
156                         WEP_CVAR_SEC(vaporizer, radius),
157                         WEP_CVAR_SEC(vaporizer, force),
158                         WEP_CVAR_SEC(vaporizer, speed),
159                         WEP_CVAR_SEC(vaporizer, spread),
160                         WEP_CVAR_SEC(vaporizer, delay),
161                         WEP_CVAR_SEC(vaporizer, lifetime)
162                 );
163                 self.weapon = oldwep;
164         }
165
166         self.weapon_blocked = false;
167
168         self.ok_ammo_charge = self.ammo_charge[self.weapon];
169
170         if(self.ok_use_ammocharge)
171         if(!ok_CheckWeaponCharge(self, self.weapon))
172         {
173                 if(autocvar_g_overkill_ammo_charge_notice && time > self.ok_notice_time && self.BUTTON_ATCK && IS_REAL_CLIENT(self) && self.weapon == self.switchweapon)
174                 {
175                         //Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERKILL_CHARGE);
176                         self.ok_notice_time = time + 2;
177                         play2(self, SND(DRYFIRE));
178                 }
179                 Weapon wpn = get_weaponinfo(self.weapon);
180                 if(self.weaponentity.state != WS_CLEAR)
181                         w_ready(wpn, self, self.BUTTON_ATCK, self.BUTTON_ATCK2);
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 {SELFPARAM();
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 void _spawnfunc_weapon_hmg() { SELFPARAM(); spawnfunc_weapon_hmg(this); }
210 void _spawnfunc_weapon_rpc() { SELFPARAM(); spawnfunc_weapon_rpc(this); }
211
212 MUTATOR_HOOKFUNCTION(ok_OnEntityPreSpawn)
213 {SELFPARAM();
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, MDL_OK_HMG);
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, MDL_OK_RPC);
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 {SELFPARAM();
257         if(self.ok_item)
258                 return false;
259
260         switch(self.items)
261         {
262                 case ITEM_HealthMega.m_itemid: return !(autocvar_g_overkill_100h_anyway);
263                 case ITEM_ArmorMega.m_itemid: return !(autocvar_g_overkill_100a_anyway);
264         }
265
266         return true;
267 }
268
269 MUTATOR_HOOKFUNCTION(ok_SpectateCopy)
270 {SELFPARAM();
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(WEP_RPC.weaponstart > 0) { ok_start_items |= WEPSET(RPC); }
282         if(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         return false;
288 }
289
290 MUTATOR_HOOKFUNCTION(ok_BuildMutatorsString)
291 {
292         ret_string = strcat(ret_string, ":OK");
293         return false;
294 }
295
296 MUTATOR_HOOKFUNCTION(ok_BuildMutatorsPrettyString)
297 {
298         ret_string = strcat(ret_string, ", Overkill");
299         return false;
300 }
301
302 MUTATOR_HOOKFUNCTION(ok_SetModname)
303 {
304         modname = "Overkill";
305         return true;
306 }
307
308 void ok_SetCvars()
309 {
310         // hack to force overkill playermodels
311         cvar_settemp("sv_defaultcharacter", "1");
312         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");
313         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");
314         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");
315 }
316
317 void ok_Initialize()
318 {
319         ok_SetCvars();
320
321         precache_all_playermodels("models/ok_player/*.dpm");
322
323         addstat(STAT_OK_AMMO_CHARGE, AS_FLOAT, ok_use_ammocharge);
324         addstat(STAT_OK_AMMO_CHARGEPOOL, AS_FLOAT, ok_ammo_charge);
325
326         WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
327         WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
328
329         WEP_SHOTGUN.mdl = "ok_shotgun";
330         WEP_MACHINEGUN.mdl = "ok_mg";
331         WEP_VORTEX.mdl = "ok_sniper";
332 }
333
334 MUTATOR_DEFINITION(mutator_overkill)
335 {
336         MUTATOR_HOOK(ForbidThrowCurrentWeapon, ok_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
337         MUTATOR_HOOK(PlayerPreThink, ok_PlayerPreThink, CBC_ORDER_LAST);
338         MUTATOR_HOOK(PlayerSpawn, ok_PlayerSpawn, CBC_ORDER_ANY);
339         MUTATOR_HOOK(PlayerDamage_Calculate, ok_PlayerDamage_Calculate, CBC_ORDER_LAST);
340         MUTATOR_HOOK(PlayerDamage_SplitHealthArmor, ok_PlayerDamage_SplitHealthArmor, CBC_ORDER_ANY);
341         MUTATOR_HOOK(PlayerDies, ok_PlayerDies, CBC_ORDER_ANY);
342         MUTATOR_HOOK(PlayerRegen, ok_PlayerRegen, CBC_ORDER_ANY);
343         MUTATOR_HOOK(OnEntityPreSpawn, ok_OnEntityPreSpawn, CBC_ORDER_ANY);
344         MUTATOR_HOOK(FilterItem, ok_ItemRemove, CBC_ORDER_ANY);
345         MUTATOR_HOOK(MonsterDropItem, ok_PlayerDies, CBC_ORDER_ANY);
346         MUTATOR_HOOK(SpectateCopy, ok_SpectateCopy, CBC_ORDER_ANY);
347         MUTATOR_HOOK(SetStartItems, ok_StartItems, CBC_ORDER_ANY);
348         MUTATOR_HOOK(BuildMutatorsString, ok_BuildMutatorsString, CBC_ORDER_ANY);
349         MUTATOR_HOOK(BuildMutatorsPrettyString, ok_BuildMutatorsPrettyString, CBC_ORDER_ANY);
350         MUTATOR_HOOK(SetModname, ok_SetModname, CBC_ORDER_ANY);
351
352         MUTATOR_ONADD
353         {
354                 ok_Initialize();
355         }
356
357         MUTATOR_ONREMOVE
358         {
359                 WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
360                 WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
361         }
362
363         return false;
364 }