2 REGISTER_WEAPON(SHOTGUN, w_shotgun, IT_SHELLS, 2, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_LOW, "shotgun", "shotgun", _("Shotgun"))
6 void W_Shotgun_DoReload()
9 if(W_SniperRifle_Reload(self.ammo_shells))
13 void W_Shotgun_Attack (void)
25 if(self.sniperrifle_bulletcounter <= 0)
27 if(self.sniperrifle_bulletcounter < 0)
28 return; // reloading, so we are done
30 ammoamount = autocvar_g_balance_shotgun_primary_ammo;
31 bullets = autocvar_g_balance_shotgun_primary_bullets;
32 d = autocvar_g_balance_shotgun_primary_damage;
33 f = autocvar_g_balance_shotgun_primary_force;
34 spread = autocvar_g_balance_shotgun_primary_spread;
35 bulletspeed = autocvar_g_balance_shotgun_primary_speed;
36 bulletconstant = autocvar_g_balance_shotgun_primary_bulletconstant;
38 W_SetupShot (self, autocvar_g_antilag_bullets && bulletspeed >= autocvar_g_antilag_bullets, 5, "weapons/shotgun_fire.wav", CHAN_WEAPON, d * bullets);
39 for (sc = 0;sc < bullets;sc = sc + 1)
40 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN, 0, 1, bulletconstant);
41 endFireBallisticBullet();
42 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
43 self.ammo_shells = self.ammo_shells - ammoamount;
45 pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, autocvar_g_balance_shotgun_primary_ammo);
48 if (autocvar_g_casings >= 1)
49 for (sc = 0;sc < ammoamount;sc = sc + 1)
50 SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, self);
52 // muzzle flash for 1st person view
54 setmodel(flash, "models/uziflash.md3"); // precision set below
55 flash.think = SUB_Remove;
56 flash.nextthink = time + 0.06;
57 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
58 W_AttachToShotorg(flash, '5 0 0');
60 self.sniperrifle_bulletcounter = self.sniperrifle_bulletcounter - 1;
63 void shotgun_meleethink (void)
65 // store time when we started swinging down inside self.cnt
69 makevectors(self.owner.v_angle);
74 meleetime = autocvar_g_balance_shotgun_secondary_melee_time * W_WeaponRateFactor();
78 f = (self.cnt + meleetime - time) / meleetime * 2 - 1;
80 targpos = self.owner.origin + self.owner.view_ofs + angle * autocvar_g_balance_shotgun_secondary_melee_range + v_right * f * autocvar_g_balance_shotgun_secondary_melee_swing + v_up * f * autocvar_g_balance_shotgun_secondary_melee_swing;
82 WarpZone_traceline_antilag(self.owner, self.owner.origin + self.owner.view_ofs, targpos, FALSE, self.owner, ANTILAG_LATENCY(self.owner));
84 // apply the damage, also remove self
85 if(trace_fraction < 1 && trace_ent.takedamage == DAMAGE_AIM && (trace_ent.classname == "player" || trace_ent.classname == "body"))
88 force = angle * autocvar_g_balance_shotgun_secondary_force;
89 if(accuracy_isgooddamage(self.owner, trace_ent))
90 accuracy_add(self.owner, WEP_SHOTGUN, 0, autocvar_g_balance_shotgun_secondary_damage * min(1, f + 1));
91 Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_shotgun_secondary_damage * min(1, f + 1), WEP_SHOTGUN | HITTYPE_SECONDARY , self.owner.origin + self.owner.view_ofs, force);
94 else if(time >= self.cnt + meleetime) // missed, remove ent
96 else // continue swinging the weapon in hope of hitting someone :)
97 self.nextthink = time;
100 void W_Shotgun_Attack2 (void)
102 sound (self, CHAN_PROJECTILE, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
103 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_shotgun_secondary_animtime, w_ready);
107 meleetemp.owner = self;
108 meleetemp.think = shotgun_meleethink;
109 meleetemp.nextthink = time + autocvar_g_balance_shotgun_secondary_melee_delay;
110 W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_shotgun_secondary_damage, autocvar_g_balance_shotgun_secondary_melee_range);
113 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
115 .float shotgun_primarytime;
117 float w_shotgun(float req)
120 if(vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_shotgun_secondary_melee_range)
121 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
123 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
124 else if (req == WR_THINK)
126 if(self.sniperrifle_bulletcounter < 0) // forced reload (e.g. because interrupted)
127 self.wish_reload = 1;
130 if (self.BUTTON_ATCK)
132 if (time >= self.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
134 if(weapon_prepareattack(0, autocvar_g_balance_shotgun_primary_animtime))
137 self.shotgun_primarytime = time + autocvar_g_balance_shotgun_primary_refire;
138 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shotgun_primary_animtime, w_ready);
142 if (self.BUTTON_ATCK2 && autocvar_g_balance_shotgun_secondary)
143 if (weapon_prepareattack(1, autocvar_g_balance_shotgun_secondary_refire))
145 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
146 weapon_thinkf(WFRAME_FIRE1, 0, W_Shotgun_Attack2);
151 if(self.switchweapon == self.weapon)
153 if(self.weaponentity.state == WS_READY)
155 self.wish_reload = 0;
156 W_SniperRifle_Reload(self.ammo_shells);
161 else if (req == WR_PRECACHE)
163 precache_model ("models/uziflash.md3");
164 precache_model ("models/weapons/g_shotgun.md3");
165 precache_model ("models/weapons/v_shotgun.md3");
166 precache_model ("models/weapons/h_shotgun.iqm");
167 precache_sound ("misc/itempickup.wav");
168 precache_sound ("weapons/shotgun_fire.wav");
169 precache_sound ("weapons/shotgun_melee.wav");
171 else if (req == WR_SETUP)
172 weapon_setup(WEP_SHOTGUN);
173 else if (req == WR_CHECKAMMO1)
174 return self.ammo_shells >= autocvar_g_balance_shotgun_primary_ammo;
175 else if (req == WR_CHECKAMMO2)
184 float w_shotgun(float req)
186 if(req == WR_IMPACTEFFECT)
189 org2 = w_org + w_backoff * 2;
190 pointparticles(particleeffectnum("shotgun_impact"), org2, w_backoff * 1000, 1);
191 if(!w_issilent && time - self.prevric > 0.25)
193 if(w_random < 0.0165)
194 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
195 else if(w_random < 0.033)
196 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
197 else if(w_random < 0.05)
198 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
202 else if(req == WR_PRECACHE)
204 precache_sound("weapons/ric1.wav");
205 precache_sound("weapons/ric2.wav");
206 precache_sound("weapons/ric3.wav");
208 else if (req == WR_SUICIDEMESSAGE)
209 w_deathtypestring = "%s did the impossible";
210 else if (req == WR_KILLMESSAGE)
212 if(w_deathtype & HITTYPE_SECONDARY)
213 w_deathtypestring = "%2$s ^7slapped %1$s ^7around a bit with a large ^2shotgun";
215 w_deathtypestring = "%s was gunned by %s";