]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/okmachinegun.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[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(okmachinegun, reload_ammo) && actor.(weaponentity).clip_load < min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)))
135         { // forced reload
136                 thiswep.wr_reload(thiswep, actor, weaponentity);
137         }
138         else if (WEP_CVAR(okmachinegun, mode) == 1)
139         {
140                 if(fire & 1) // Primary attack
141                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
142                 {
143                         actor.(weaponentity).misc_bulletcounter = 0;
144                         W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
145                 }
146
147                 if (fire & 2) // Secondary attack
148                 {
149                         if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okmachinegun, refire)))
150                         {
151                                 return;
152                         }
153                         // ugly instagib hack to reuse the fire mode of the laser
154                         makevectors(actor.v_angle);
155                         Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
156                         actor.(weaponentity).m_weapon = WEP_BLASTER;
157                         W_Blaster_Attack(
158                                 actor,
159                                 weaponentity,
160                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
161                                 WEP_CVAR_SEC(okmachinegun, shotangle),
162                                 WEP_CVAR_SEC(okmachinegun, damage),
163                                 WEP_CVAR_SEC(okmachinegun, edgedamage),
164                                 WEP_CVAR_SEC(okmachinegun, radius),
165                                 WEP_CVAR_SEC(okmachinegun, force),
166                                 WEP_CVAR_SEC(okmachinegun, speed),
167                                 WEP_CVAR_SEC(okmachinegun, spread),
168                                 WEP_CVAR_SEC(okmachinegun, delay),
169                                 WEP_CVAR_SEC(okmachinegun, lifetime)
170                         );
171                         actor.(weaponentity).m_weapon = oldwep;
172                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
173                 }
174         }
175         else
176         {
177                 if(fire & 1) // Primary attack
178                 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
179                 {
180                         actor.(weaponentity).misc_bulletcounter = 1;
181                         W_OverkillMachineGun_Attack(WEP_OVERKILL_MACHINEGUN, WEP_OVERKILL_MACHINEGUN.m_id, actor, weaponentity); // sets attack_finished
182                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(okmachinegun, sustained_refire), W_OverkillMachineGun_Attack_Frame);
183                 }
184
185                 if (fire & 2) // Secondary attack
186                 {
187                         if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(okmachinegun, refire)))
188                         {
189                                 return;
190                         }
191                         // ugly instagib hack to reuse the fire mode of the laser
192                         makevectors(actor.v_angle);
193                         Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
194                         actor.(weaponentity).m_weapon = WEP_BLASTER;
195                         W_Blaster_Attack(
196                                 actor,
197                                 weaponentity,
198                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
199                                 WEP_CVAR_SEC(okmachinegun, shotangle),
200                                 WEP_CVAR_SEC(okmachinegun, damage),
201                                 WEP_CVAR_SEC(okmachinegun, edgedamage),
202                                 WEP_CVAR_SEC(okmachinegun, radius),
203                                 WEP_CVAR_SEC(okmachinegun, force),
204                                 WEP_CVAR_SEC(okmachinegun, speed),
205                                 WEP_CVAR_SEC(okmachinegun, spread),
206                                 WEP_CVAR_SEC(okmachinegun, delay),
207                                 WEP_CVAR_SEC(okmachinegun, lifetime)
208                         );
209                         actor.(weaponentity).m_weapon = oldwep;
210                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
211                 }
212         }
213 }
214
215 METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
216 {
217         float ammo_amount;
218         if(WEP_CVAR(okmachinegun, mode) == 1)
219                 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, sustained_ammo);
220         else
221                 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
222
223         if(WEP_CVAR(okmachinegun, reload_ammo))
224         {
225                 if(WEP_CVAR(okmachinegun, mode) == 1)
226                         ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, sustained_ammo);
227                 else
228                         ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
229         }
230         return ammo_amount;
231 }
232
233 METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
234 {
235         float ammo_amount;
236         if(WEP_CVAR(okmachinegun, mode) == 1)
237                 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, burst_ammo);
238         else
239                 ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(okmachinegun, first_ammo);
240
241         if(WEP_CVAR(okmachinegun, reload_ammo))
242         {
243                 if(WEP_CVAR(okmachinegun, mode) == 1)
244                         ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, burst_ammo);
245                 else
246                         ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR(okmachinegun, first_ammo);
247         }
248         return ammo_amount;
249 }
250
251 METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
252 {
253         W_Reload(actor, weaponentity, min(max(WEP_CVAR(okmachinegun, sustained_ammo), WEP_CVAR(okmachinegun, first_ammo)), WEP_CVAR(okmachinegun, burst_ammo)), SND_RELOAD);
254 }
255
256 METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
257 {
258         return WEAPON_THINKING_WITH_PORTALS;
259 }
260
261 METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
262 {
263         if(w_deathtype & HITTYPE_SECONDARY)
264                 return WEAPON_MACHINEGUN_MURDER_SNIPE;
265         else
266                 return WEAPON_MACHINEGUN_MURDER_SPRAY;
267 }
268
269 #endif
270 #ifdef CSQC
271
272 METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
273 {
274         vector org2;
275         org2 = w_org + w_backoff * 2;
276         pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
277         if(!w_issilent)
278                 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);
279 }
280
281 #endif
282