OK weapons: Removed unused stuff from shotgun and machinegun.
[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_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
17 {
18         float okmachinegun_spread;
19
20         if(!(fire & 1))
21         {
22                 w_ready(thiswep, actor, weaponentity, fire);
23                 return;
24         }
25
26         if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
27         if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
28         {
29                 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
30                 w_ready(thiswep, actor, weaponentity, fire);
31                 return;
32         }
33
34         W_DecreaseAmmo(WEP_OVERKILL_MACHINEGUN, actor, WEP_CVAR_PRI(okmachinegun, ammo), weaponentity);
35
36         W_SetupShot(actor, weaponentity, true, 0, SND_UZI_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(okmachinegun, damage));
37         if(!autocvar_g_norecoil)
38         {
39                 actor.punchangle_x = random() - 0.5;
40                 actor.punchangle_y = random() - 0.5;
41         }
42
43         okmachinegun_spread = bound(WEP_CVAR_PRI(okmachinegun, spread_min), WEP_CVAR_PRI(okmachinegun, spread_min) + (WEP_CVAR_PRI(okmachinegun, spread_add) * actor.(weaponentity).misc_bulletcounter), WEP_CVAR_PRI(okmachinegun, spread_max));
44         fireBullet(actor, weaponentity, w_shotorg, w_shotdir, okmachinegun_spread, WEP_CVAR_PRI(okmachinegun, solidpenetration), WEP_CVAR_PRI(okmachinegun, damage), WEP_CVAR_PRI(okmachinegun, force), WEP_OVERKILL_MACHINEGUN.m_id, 0);
45
46         actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
47
48         Send_Effect(EFFECT_MACHINEGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
49
50         W_MachineGun_MuzzleFlash(actor, weaponentity);
51         W_AttachToShotorg(actor, weaponentity, actor.(weaponentity).muzzle_flash, '5 0 0');
52
53         if(autocvar_g_casings >= 2) // casing code
54         {
55                 makevectors(actor.v_angle); // for some reason, this is lost
56                 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);
57         }
58
59         int slot = weaponslot(weaponentity);
60         ATTACK_FINISHED(actor, slot) = time + WEP_CVAR_PRI(okmachinegun, refire) * W_WeaponRateFactor(actor);
61         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(okmachinegun, refire), W_OverkillMachineGun_Attack_Auto);
62 }
63
64 METHOD(OverkillMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
65 {
66         if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
67                 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
68         else
69                 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
70 }
71
72 METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
73 {
74         if ((WEP_CVAR_SEC(okmachinegun, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
75         {
76                 // Secondary uses it's own refire timer if refire_type is 1.
77                 actor.jump_interval = time + WEP_CVAR_SEC(okmachinegun, refire) * W_WeaponRateFactor(actor);
78                 // Ugly hack to reuse the fire mode of the blaster.
79                 makevectors(actor.v_angle);
80                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
81                 actor.(weaponentity).m_weapon = WEP_BLASTER;
82                 W_Blaster_Attack(
83                         actor,
84                         weaponentity,
85                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
86                         WEP_CVAR_SEC(okmachinegun, shotangle),
87                         WEP_CVAR_SEC(okmachinegun, damage),
88                         WEP_CVAR_SEC(okmachinegun, edgedamage),
89                         WEP_CVAR_SEC(okmachinegun, radius),
90                         WEP_CVAR_SEC(okmachinegun, force),
91                         WEP_CVAR_SEC(okmachinegun, speed),
92                         WEP_CVAR_SEC(okmachinegun, spread),
93                         WEP_CVAR_SEC(okmachinegun, delay),
94                         WEP_CVAR_SEC(okmachinegun, lifetime)
95                 );
96                 actor.(weaponentity).m_weapon = oldwep;
97                 if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
98                         (actor.(weaponentity).wframe == WFRAME_FIRE2))
99                 {
100                         // Set secondary fire animation.
101                         vector a = '0 0 0';
102                         actor.(weaponentity).wframe = WFRAME_FIRE2;
103                         a = actor.(weaponentity).anim_fire2;
104                         a.z *= g_weaponratefactor;
105                         FOREACH_CLIENT(true, LAMBDA(
106                                 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
107                                 {
108                                         wframe_send(it, actor.(weaponentity), a, true);
109                                 }
110                         ));
111                         animdecide_setaction(actor, ANIMACTION_SHOOT, true);
112                 }
113         }
114         if (WEP_CVAR(okmachinegun, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(okmachinegun, ammo))
115         {
116                 // Forced reload
117                 thiswep.wr_reload(thiswep, actor, weaponentity);
118                 return;
119         }
120         if (fire & 1) // Primary attack
121         {
122                 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
123                 {
124                         return;
125                 }
126                 actor.(weaponentity).misc_bulletcounter = 0;
127                 W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
128                 return;
129         }
130         if ((fire & 2) && (WEP_CVAR_SEC(okmachinegun, refire_type) == 0)) // Secondary attack
131         {
132                 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(okmachinegun, refire)))
133                 {
134                         return;
135                 }
136                 // Ugly hack to reuse the fire mode of the blaster.
137                 makevectors(actor.v_angle);
138                 Weapon oldwep = actor.(weaponentity).m_weapon; // we can't avoid this hack
139                 actor.(weaponentity).m_weapon = WEP_BLASTER;
140                 W_Blaster_Attack(
141                         actor,
142                         weaponentity,
143                         WEP_BLASTER.m_id | HITTYPE_SECONDARY,
144                         WEP_CVAR_SEC(okmachinegun, shotangle),
145                         WEP_CVAR_SEC(okmachinegun, damage),
146                         WEP_CVAR_SEC(okmachinegun, edgedamage),
147                         WEP_CVAR_SEC(okmachinegun, radius),
148                         WEP_CVAR_SEC(okmachinegun, force),
149                         WEP_CVAR_SEC(okmachinegun, speed),
150                         WEP_CVAR_SEC(okmachinegun, spread),
151                         WEP_CVAR_SEC(okmachinegun, delay),
152                         WEP_CVAR_SEC(okmachinegun, lifetime)
153                 );
154                 actor.(weaponentity).m_weapon = oldwep;
155                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(okmachinegun, animtime), w_ready);
156         }
157 }
158
159 METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
160 {
161         float ammo_amount;
162         ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(okmachinegun, ammo);
163         if (WEP_CVAR(okmachinegun, reload_ammo))
164         {
165                 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR_PRI(okmachinegun, ammo);
166         }
167         return ammo_amount;
168 }
169
170 METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
171 {
172         return true; // Blaster secondary is unlimited.
173 }
174
175 METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
176 {
177         W_Reload(actor, weaponentity, WEP_CVAR_PRI(okmachinegun, ammo), SND_RELOAD);
178 }
179
180 METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
181 {
182         return WEAPON_THINKING_WITH_PORTALS;
183 }
184
185 METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
186 {
187         if(w_deathtype & HITTYPE_SECONDARY)
188                 return WEAPON_MACHINEGUN_MURDER_SNIPE;
189         else
190                 return WEAPON_MACHINEGUN_MURDER_SPRAY;
191 }
192
193 #endif
194 #ifdef CSQC
195
196 METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
197 {
198         vector org2;
199         org2 = w_org + w_backoff * 2;
200         pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
201         if(!w_issilent)
202                 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTN_NORM);
203 }
204
205 #endif
206