3 /* WEP_##id */ SHOTGUN,
4 /* function */ w_shotgun,
5 /* ammotype */ IT_SHELLS,
7 /* flags */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating */ BOT_PICKUP_RATING_LOW,
10 /* shortname */ "shotgun",
11 /* fullname */ _("Shotgun")
16 void W_Shotgun_Attack (void)
24 float solidpenetration;
27 ammoamount = autocvar_g_balance_shotgun_primary_ammo;
28 bullets = autocvar_g_balance_shotgun_primary_bullets;
29 d = autocvar_g_balance_shotgun_primary_damage;
30 f = autocvar_g_balance_shotgun_primary_force;
31 spread = autocvar_g_balance_shotgun_primary_spread;
32 solidpenetration = autocvar_g_balance_shotgun_primary_solidpenetration;
34 W_DecreaseAmmo(ammo_shells, ammoamount, autocvar_g_balance_shotgun_reload_ammo);
36 W_SetupShot (self, TRUE, 5, "weapons/shotgun_fire.wav", CH_WEAPON_A, d * bullets);
37 for (sc = 0;sc < bullets;sc = sc + 1)
38 fireBullet(w_shotorg, w_shotdir, spread, solidpenetration, d, f, WEP_SHOTGUN, 0);
40 pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, autocvar_g_balance_shotgun_primary_ammo);
43 if (autocvar_g_casings >= 1)
44 for (sc = 0;sc < ammoamount;sc = sc + 1)
45 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);
47 // muzzle flash for 1st person view
49 setmodel(flash, "models/uziflash.md3"); // precision set below
50 flash.think = SUB_Remove;
51 flash.nextthink = time + 0.06;
52 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
53 W_AttachToShotorg(flash, '5 0 0');
57 .entity swing_alreadyhit;
58 void shotgun_meleethink (void)
61 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
65 if(!self.cnt) // set start time of melee
68 W_PlayStrengthSound(self.realowner);
71 makevectors(self.realowner.v_angle); // update values for v_* vectors
73 // calculate swing percentage based on time
74 meleetime = autocvar_g_balance_shotgun_secondary_melee_time * W_WeaponRateFactor();
75 swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
76 f = ((1 - swing) * autocvar_g_balance_shotgun_secondary_melee_traces);
78 // check to see if we can still continue, otherwise give up now
79 if((self.realowner.deadflag != DEAD_NO) && autocvar_g_balance_shotgun_secondary_melee_no_doubleslap)
85 // if okay, perform the traces needed for this frame
86 for(i=self.swing_prev; i < f; ++i)
88 swing_factor = ((1 - (i / autocvar_g_balance_shotgun_secondary_melee_traces)) * 2 - 1);
90 targpos = (self.realowner.origin + self.realowner.view_ofs
91 + (v_forward * autocvar_g_balance_shotgun_secondary_melee_range)
92 + (v_up * swing_factor * autocvar_g_balance_shotgun_secondary_melee_swing_up)
93 + (v_right * swing_factor * autocvar_g_balance_shotgun_secondary_melee_swing_side));
95 WarpZone_traceline_antilag(self, self.realowner.origin + self.realowner.view_ofs, targpos, FALSE, self, ANTILAG_LATENCY(self.realowner));
97 // draw lightning beams for debugging
98 //te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
99 //te_customflash(targpos, 40, 2, '1 1 1');
101 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body");
103 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
104 && (trace_ent.takedamage == DAMAGE_AIM)
105 && (trace_ent != self.swing_alreadyhit)
106 && (is_player || autocvar_g_balance_shotgun_secondary_melee_nonplayerdamage))
108 target_victim = trace_ent; // so it persists through other calls
110 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
111 swing_damage = (autocvar_g_balance_shotgun_secondary_damage * min(1, swing_factor + 1));
113 swing_damage = (autocvar_g_balance_shotgun_secondary_melee_nonplayerdamage * min(1, swing_factor + 1));
115 //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
117 Damage(target_victim, self.realowner, self.realowner,
118 swing_damage, WEP_SHOTGUN | HITTYPE_SECONDARY,
119 self.realowner.origin + self.realowner.view_ofs,
120 v_forward * autocvar_g_balance_shotgun_secondary_force);
122 if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOTGUN, 0, swing_damage); }
124 // draw large red flash for debugging
125 //te_customflash(targpos, 200, 2, '15 0 0');
127 if(autocvar_g_balance_shotgun_secondary_melee_multihit) // allow multiple hits with one swing, but not against the same player twice.
129 self.swing_alreadyhit = target_victim;
130 continue; // move along to next trace
140 if(time >= self.cnt + meleetime)
150 self.nextthink = time;
154 void W_Shotgun_Attack2 (void)
156 sound (self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTEN_NORM);
157 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_shotgun_secondary_animtime, w_ready);
161 meleetemp.realowner = self;
162 meleetemp.think = shotgun_meleethink;
163 meleetemp.nextthink = time + autocvar_g_balance_shotgun_secondary_melee_delay * W_WeaponRateFactor();
164 W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_shotgun_secondary_damage, autocvar_g_balance_shotgun_secondary_melee_range);
167 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
169 .float shotgun_primarytime;
171 float w_shotgun(float req)
175 if(vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_shotgun_secondary_melee_range)
176 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
178 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
180 else if (req == WR_THINK)
182 if(autocvar_g_balance_shotgun_reload_ammo && self.clip_load < autocvar_g_balance_shotgun_primary_ammo) // forced reload
184 // don't force reload an empty shotgun if its melee attack is active
185 if (!(autocvar_g_balance_shotgun_secondary && self.ammo_shells < autocvar_g_balance_shotgun_primary_ammo))
186 weapon_action(self.weapon, WR_RELOAD);
190 if (self.BUTTON_ATCK)
192 if (time >= self.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
194 if(weapon_prepareattack(0, autocvar_g_balance_shotgun_primary_animtime))
197 self.shotgun_primarytime = time + autocvar_g_balance_shotgun_primary_refire * W_WeaponRateFactor();
198 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shotgun_primary_animtime, w_ready);
203 if (self.clip_load >= 0) // we are not currently reloading
204 if (!self.crouch) // no crouchmelee please
205 if (self.BUTTON_ATCK2 && autocvar_g_balance_shotgun_secondary)
206 if (weapon_prepareattack(1, autocvar_g_balance_shotgun_secondary_refire))
208 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
209 weapon_thinkf(WFRAME_FIRE1, 0, W_Shotgun_Attack2);
212 else if (req == WR_PRECACHE)
214 precache_model ("models/uziflash.md3");
215 precache_model ("models/weapons/g_shotgun.md3");
216 precache_model ("models/weapons/v_shotgun.md3");
217 precache_model ("models/weapons/h_shotgun.iqm");
218 precache_sound ("misc/itempickup.wav");
219 precache_sound ("weapons/shotgun_fire.wav");
220 precache_sound ("weapons/shotgun_melee.wav");
221 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
223 else if (req == WR_SETUP)
225 weapon_setup(WEP_SHOTGUN);
226 self.current_ammo = ammo_shells;
228 else if (req == WR_CHECKAMMO1)
230 ammo_amount = self.ammo_shells >= autocvar_g_balance_shotgun_primary_ammo;
231 ammo_amount += self.(weapon_load[WEP_SHOTGUN]) >= autocvar_g_balance_shotgun_primary_ammo;
234 else if (req == WR_CHECKAMMO2)
236 // melee attack is always available
239 else if (req == WR_RELOAD)
241 W_Reload(autocvar_g_balance_shotgun_primary_ammo, autocvar_g_balance_shotgun_reload_ammo, autocvar_g_balance_shotgun_reload_time, "weapons/reload.wav");
243 else if (req == WR_SUICIDEMESSAGE)
245 return WEAPON_THINKING_WITH_PORTALS;
247 else if (req == WR_KILLMESSAGE)
249 if(w_deathtype & HITTYPE_SECONDARY)
250 return WEAPON_SHOTGUN_MURDER_SLAP;
252 return WEAPON_SHOTGUN_MURDER;
259 float w_shotgun(float req)
261 if(req == WR_IMPACTEFFECT)
264 org2 = w_org + w_backoff * 2;
265 pointparticles(particleeffectnum("shotgun_impact"), org2, w_backoff * 1000, 1);
266 if(!w_issilent && time - self.prevric > 0.25)
268 if(w_random < 0.0165)
269 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
270 else if(w_random < 0.033)
271 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
272 else if(w_random < 0.05)
273 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
277 else if(req == WR_PRECACHE)
279 precache_sound("weapons/ric1.wav");
280 precache_sound("weapons/ric2.wav");
281 precache_sound("weapons/ric3.wav");