]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/okmachinegun.qc
Overkill weapons: better secondary refire.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / okmachinegun.qc
1 #include "okmachinegun.qh"
2
3 #ifdef SVQC
4
5 spawnfunc(weapon_okmachinegun)
6 {
7         if(autocvar_sv_q3acompat_machineshotgunswap)
8         if(this.classname != "droppedweapon")
9         {
10                 weapon_defaultspawnfunc(this, WEP_SHOCKWAVE);
11                 return;
12         }
13         weapon_defaultspawnfunc(this, WEP_OVERKILL_MACHINEGUN);
14 }
15
16 void W_OverkillMachineGun_Attack(Weapon thiswep, int deathtype, entity actor, .entity weaponentity)
17 {
18         W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, ((actor.(weaponentity).misc_bulletcounter == 1) ? WEP_CVAR(okmachinegun, first_damage) : WEP_CVAR(okmachinegun, sustained_damage)));
19         if(!autocvar_g_norecoil)
20         {
21                 actor.punchangle_x = random() - 0.5;
22                 actor.punchangle_y = random() - 0.5;
23         }
24         int slot = weaponslot(weaponentity);
25         // this attack_finished just enforces a cooldown at the end of a burst
26         ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(okmachinegun, first_refire) * W_WeaponRateFactor(actor);
27
28         if(actor.(weaponentity).misc_bulletcounter == 1)
29                 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(okmachinegun, first_spread), WEP_CVAR(okmachinegun, solidpenetration), WEP_CVAR(okmachinegun, first_damage), WEP_CVAR(okmachinegun, first_force), deathtype, 0);
30         else
31                 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, WEP_CVAR(okmachinegun, sustained_spread), WEP_CVAR(okmachinegun, solidpenetration), WEP_CVAR(okmachinegun, sustained_damage), WEP_CVAR(okmachinegun, sustained_force), deathtype, 0);
32
33         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
34
35         W_MachineGun_MuzzleFlash(actor, weaponentity);
36         W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
37
38         // casing code
39         if(autocvar_g_casings >= 2)
40         {
41                 makevectors(actor.v_angle); // for some reason, this is lost
42                 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
43         }
44
45         if(actor.(weaponentity).misc_bulletcounter == 1)
46                 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(okmachinegun, first_ammo), weaponentity);
47         else
48                 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(okmachinegun, sustained_ammo), weaponentity);
49 }
50
51 // weapon frames
52 void W_OverkillMachineGun_Attack_Frame(Weapon thiswep, entity actor, .entity weaponentity, int fire)
53 {
54         if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon) // abort immediately if switching
55         {
56                 w_ready(thiswep, actor, weaponentity, fire);
57                 return;
58         }
59         if(PHYS_INPUT_BUTTON_ATCK(actor))
60         {
61                 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
62                 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
63                 {
64                         W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
65                         w_ready(thiswep, actor, weaponentity, fire);
66                         return;
67                 }
68                 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
69                 W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity);
70                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
71         }
72         else
73                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), w_ready);
74 }
75
76 void W_OverkillMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
77 {
78         float okmachinegun_spread;
79
80         if(!(fire & 1))
81         {
82                 w_ready(thiswep, actor, weaponentity, fire);
83                 return;
84         }
85
86         if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
87         if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
88         {
89                 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
90                 w_ready(thiswep, actor, weaponentity, fire);
91                 return;
92         }
93
94         W_DecreaseAmmo(WEP_OVERKILL_MACHINEGUN, actor, WEP_CVAR(okmachinegun, sustained_ammo), weaponentity);
95
96         W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR(okmachinegun, sustained_damage));
97         if(!autocvar_g_norecoil)
98         {
99                 actor.punchangle_x = random() - 0.5;
100                 actor.punchangle_y = random() - 0.5;
101         }
102
103         okmachinegun_spread = bound(WEP_CVAR(okmachinegun, spread_min), WEP_CVAR(okmachinegun, spread_min) + (WEP_CVAR(okmachinegun, spread_add) * actor.(weaponentity).misc_bulletcounter), WEP_CVAR(okmachinegun, spread_max));
104         fireBullet(actor, weaponentity, w_shotorg, w_shotdir, okmachinegun_spread, WEP_CVAR(okmachinegun, solidpenetration), WEP_CVAR(okmachinegun, sustained_damage), WEP_CVAR(okmachinegun, sustained_force), WEP_OVERKILL_MACHINEGUN.m_id, 0);
105
106         actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
107
108         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
109
110         W_MachineGun_MuzzleFlash(actor, weaponentity);
111         W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
112
113         if(autocvar_g_casings >= 2) // casing code
114         {
115                 makevectors(actor.v_angle); // for some reason, this is lost
116                 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
117         }
118
119         int slot = weaponslot(weaponentity);
120         ATTACK_FINISHED(actor, slot) = time + WEP_CVAR(okmachinegun, first_refire) * W_WeaponRateFactor(actor);
121         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Auto);
122 }
123
124 METHOD(OverkillMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
125 {
126         if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
127                 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
128         else
129                 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
130 }
131
132 METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
133 {
134         if ((WEP_CVAR_SEC(okmachinegun, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
135         {
136                 // Secondary uses it's own refire timer if refire_type is 1.
137                 actor.jump_interval = time + WEP_CVAR_SEC(okmachinegun, refire) * W_WeaponRateFactor(actor);
138                 // Ugly hack to reuse the fire mode of the blaster.
139                 makevectors(actor.v_angle);
140                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
141                 actor.(weaponentity).m_weapon = WEP_BLASTER;
142                 W_Blaster_Attack(
143                         actor,
144                         weaponentity,
145                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
146                         WEP_CVAR_SEC(okmachinegun, shotangle),
147                         WEP_CVAR_SEC(okmachinegun, damage),
148                         WEP_CVAR_SEC(okmachinegun, edgedamage),
149                         WEP_CVAR_SEC(okmachinegun, radius),
150                         WEP_CVAR_SEC(okmachinegun, force),
151                         WEP_CVAR_SEC(okmachinegun, speed),
152                         WEP_CVAR_SEC(okmachinegun, spread),
153                         WEP_CVAR_SEC(okmachinegun, delay),
154                         WEP_CVAR_SEC(okmachinegun, lifetime)
155                 );
156                 actor.(weaponentity).m_weapon = oldwep;
157         }
158         if (WEP_CVAR(okmachinegun, reload_ammo) && actor.(weaponentity).clip_load < min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)))
159         {
160                 // Forced reload
161                 thiswep.wr_reload(thiswep, actor, weaponentity);
162                 return;
163         }
164         if (WEP_CVAR(okmachinegun, mode) == 1)
165         {
166                 if(fire & 1) // Primary attack
167                 {
168                         if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
169                         {
170                                 return;
171                         }
172                         actor.(weaponentity).misc_bulletcounter = 0;
173                         W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
174                         return;
175                 }
176                 if ((fire & 2) && (WEP_CVAR_SEC(okmachinegun, refire_type) == 0)) // Secondary attack
177                 {
178                         if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okmachinegun, refire)))
179                         {
180                                 return;
181                         }
182                         // ugly instagib hack to reuse the fire mode of the laser
183                         makevectors(actor.v_angle);
184                         Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
185                         actor.(weaponentity).m_weapon = WEP_BLASTER;
186                         W_Blaster_Attack(
187                                 actor,
188                                 weaponentity,
189                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
190                                 WEP_CVAR_SEC(okmachinegun, shotangle),
191                                 WEP_CVAR_SEC(okmachinegun, damage),
192                                 WEP_CVAR_SEC(okmachinegun, edgedamage),
193                                 WEP_CVAR_SEC(okmachinegun, radius),
194                                 WEP_CVAR_SEC(okmachinegun, force),
195                                 WEP_CVAR_SEC(okmachinegun, speed),
196                                 WEP_CVAR_SEC(okmachinegun, spread),
197                                 WEP_CVAR_SEC(okmachinegun, delay),
198                                 WEP_CVAR_SEC(okmachinegun, lifetime)
199                         );
200                         actor.(weaponentity).m_weapon = oldwep;
201                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
202                 }
203         }
204         else
205         {
206                 if (fire & 1) // Primary attack
207                 {
208                         if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
209                         {
210                                 return;
211                         }
212                         actor.(weaponentity).misc_bulletcounter = 1;
213                         W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity); // sets attack_finished
214                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
215                         return;
216                 }
217                 if ((fire & 2) && (WEP_CVAR_SEC(okmachinegun, refire_type) == 0)) // Secondary attack
218                 {
219                         if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okmachinegun, refire)))
220                         {
221                                 return;
222                         }
223                         // ugly instagib hack to reuse the fire mode of the laser
224                         makevectors(actor.v_angle);
225                         Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
226                         actor.(weaponentity).m_weapon = WEP_BLASTER;
227                         W_Blaster_Attack(
228                                 actor,
229                                 weaponentity,
230                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
231                                 WEP_CVAR_SEC(okmachinegun, shotangle),
232                                 WEP_CVAR_SEC(okmachinegun, damage),
233                                 WEP_CVAR_SEC(okmachinegun, edgedamage),
234                                 WEP_CVAR_SEC(okmachinegun, radius),
235                                 WEP_CVAR_SEC(okmachinegun, force),
236                                 WEP_CVAR_SEC(okmachinegun, speed),
237                                 WEP_CVAR_SEC(okmachinegun, spread),
238                                 WEP_CVAR_SEC(okmachinegun, delay),
239                                 WEP_CVAR_SEC(okmachinegun, lifetime)
240                         );
241                         actor.(weaponentity).m_weapon = oldwep;
242                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
243                 }
244         }
245 }
246
247 METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
248 {
249         float ammo_amount;
250         if(WEP_CVAR(okmachinegun, mode) == 1)
251                 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, sustained_ammo);
252         else
253                 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
254
255         if(WEP_CVAR(okmachinegun, reload_ammo))
256         {
257                 if(WEP_CVAR(okmachinegun, mode) == 1)
258                         ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, sustained_ammo);
259                 else
260                         ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
261         }
262         return ammo_amount;
263 }
264
265 METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
266 {
267         float ammo_amount;
268         if(WEP_CVAR(okmachinegun, mode) == 1)
269                 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, burst_ammo);
270         else
271                 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
272
273         if(WEP_CVAR(okmachinegun, reload_ammo))
274         {
275                 if(WEP_CVAR(okmachinegun, mode) == 1)
276                         ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, burst_ammo);
277                 else
278                         ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
279         }
280         return ammo_amount;
281 }
282
283 METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
284 {
285         W_Reload(actor, weaponentity, min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)), SND_RELOAD);
286 }
287
288 METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
289 {
290         return WEAPON_THINKING_WITH_PORTALS;
291 }
292
293 METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
294 {
295         if(w_deathtype & HITTYPE_SECONDARY)
296                 return WEAPON_MACHINEGUN_MURDER_SNIPE;
297         else
298                 return WEAPON_MACHINEGUN_MURDER_SPRAY;
299 }
300
301 #endif
302 #ifdef CSQC
303
304 METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
305 {
306         vector org2;
307         org2 = w_org + w_backoff * 2;
308         pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
309         if(!w_issilent)
310                 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);
311 }
312
313 #endif
314