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, is_monster;
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");
102 is_monster = (trace_ent.flags & FL_MONSTER);
104 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
105 && (trace_ent.takedamage == DAMAGE_AIM)
106 && (trace_ent != self.swing_alreadyhit)
107 && ((is_player || is_monster) || autocvar_g_balance_shotgun_secondary_melee_nonplayerdamage))
109 target_victim = trace_ent; // so it persists through other calls
111 if(is_player || is_monster) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
112 swing_damage = (autocvar_g_balance_shotgun_secondary_damage * min(1, swing_factor + 1));
114 swing_damage = (autocvar_g_balance_shotgun_secondary_melee_nonplayerdamage * min(1, swing_factor + 1));
116 //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
118 Damage(target_victim, self.realowner, self.realowner,
119 swing_damage, WEP_SHOTGUN | HITTYPE_SECONDARY,
120 self.realowner.origin + self.realowner.view_ofs,
121 v_forward * autocvar_g_balance_shotgun_secondary_force);
123 if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOTGUN, 0, swing_damage); }
125 // draw large red flash for debugging
126 //te_customflash(targpos, 200, 2, '15 0 0');
128 if(autocvar_g_balance_shotgun_secondary_melee_multihit) // allow multiple hits with one swing, but not against the same player twice.
130 self.swing_alreadyhit = target_victim;
131 continue; // move along to next trace
141 if(time >= self.cnt + meleetime)
151 self.nextthink = time;
155 void W_Shotgun_Attack2 (void)
157 sound (self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTEN_NORM);
158 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_shotgun_secondary_animtime, w_ready);
162 meleetemp.realowner = self;
163 meleetemp.think = shotgun_meleethink;
164 meleetemp.nextthink = time + autocvar_g_balance_shotgun_secondary_melee_delay * W_WeaponRateFactor();
165 W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_shotgun_secondary_damage, autocvar_g_balance_shotgun_secondary_melee_range);
168 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
170 .float shotgun_primarytime;
172 float w_shotgun(float req)
176 if(vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_shotgun_secondary_melee_range)
177 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
179 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
181 else if (req == WR_THINK)
183 if(autocvar_g_balance_shotgun_reload_ammo && self.clip_load < autocvar_g_balance_shotgun_primary_ammo) // forced reload
185 // don't force reload an empty shotgun if its melee attack is active
186 if (!(autocvar_g_balance_shotgun_secondary && self.ammo_shells < autocvar_g_balance_shotgun_primary_ammo))
187 weapon_action(self.weapon, WR_RELOAD);
191 if (self.BUTTON_ATCK)
193 if (time >= self.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
195 if(weapon_prepareattack(0, autocvar_g_balance_shotgun_primary_animtime))
198 self.shotgun_primarytime = time + autocvar_g_balance_shotgun_primary_refire * W_WeaponRateFactor();
199 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shotgun_primary_animtime, w_ready);
204 if (self.clip_load >= 0) // we are not currently reloading
205 if (!self.crouch) // no crouchmelee please
206 if (self.BUTTON_ATCK2 && autocvar_g_balance_shotgun_secondary)
207 if (weapon_prepareattack(1, autocvar_g_balance_shotgun_secondary_refire))
209 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
210 weapon_thinkf(WFRAME_FIRE1, 0, W_Shotgun_Attack2);
213 else if (req == WR_PRECACHE)
215 precache_model ("models/uziflash.md3");
216 precache_model ("models/weapons/g_shotgun.md3");
217 precache_model ("models/weapons/v_shotgun.md3");
218 precache_model ("models/weapons/h_shotgun.iqm");
219 precache_sound ("misc/itempickup.wav");
220 precache_sound ("weapons/shotgun_fire.wav");
221 precache_sound ("weapons/shotgun_melee.wav");
222 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
224 else if (req == WR_SETUP)
226 weapon_setup(WEP_SHOTGUN);
227 self.current_ammo = ammo_shells;
229 else if (req == WR_CHECKAMMO1)
231 ammo_amount = self.ammo_shells >= autocvar_g_balance_shotgun_primary_ammo;
232 ammo_amount += self.(weapon_load[WEP_SHOTGUN]) >= autocvar_g_balance_shotgun_primary_ammo;
235 else if (req == WR_CHECKAMMO2)
237 // melee attack is always available
240 else if (req == WR_RELOAD)
242 W_Reload(autocvar_g_balance_shotgun_primary_ammo, autocvar_g_balance_shotgun_reload_ammo, autocvar_g_balance_shotgun_reload_time, "weapons/reload.wav");
244 else if (req == WR_SUICIDEMESSAGE)
246 return WEAPON_THINKING_WITH_PORTALS;
248 else if (req == WR_KILLMESSAGE)
250 if(w_deathtype & HITTYPE_SECONDARY)
251 return WEAPON_SHOTGUN_MURDER_SLAP;
253 return WEAPON_SHOTGUN_MURDER;
260 float w_shotgun(float req)
262 if(req == WR_IMPACTEFFECT)
265 org2 = w_org + w_backoff * 2;
266 pointparticles(particleeffectnum("shotgun_impact"), org2, w_backoff * 1000, 1);
267 if(!w_issilent && time - self.prevric > 0.25)
269 if(w_random < 0.0165)
270 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
271 else if(w_random < 0.033)
272 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
273 else if(w_random < 0.05)
274 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
278 else if(req == WR_PRECACHE)
280 precache_sound("weapons/ric1.wav");
281 precache_sound("weapons/ric2.wav");
282 precache_sound("weapons/ric3.wav");