3 /* WEP_##id */ SHOTGUN,
4 /* function */ W_Shotgun,
5 /* ammotype */ ammo_shells,
7 /* flags */ WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating */ BOT_PICKUP_RATING_LOW,
9 /* color */ '0.5 0.25 0',
10 /* modelname */ "shotgun",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairshotgun 0.65",
13 /* wepimg */ "weaponshotgun",
14 /* refname */ "shotgun",
15 /* wepname */ _("Shotgun")
18 #define SHOTGUN_SETTINGS(w_cvar,w_prop) SHOTGUN_SETTINGS_LIST(w_cvar, w_prop, SHOTGUN, shotgun)
19 #define SHOTGUN_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, PRI, ammo) \
21 w_cvar(id, sn, BOTH, animtime) \
22 w_cvar(id, sn, BOTH, refire) \
23 w_cvar(id, sn, PRI, bullets) \
24 w_cvar(id, sn, BOTH, damage) \
25 w_cvar(id, sn, BOTH, force) \
26 w_cvar(id, sn, PRI, solidpenetration) \
27 w_cvar(id, sn, PRI, spread) \
28 w_cvar(id, sn, NONE, secondary) \
29 w_cvar(id, sn, SEC, melee_time) \
30 w_cvar(id, sn, SEC, melee_no_doubleslap) \
31 w_cvar(id, sn, SEC, melee_traces) \
32 w_cvar(id, sn, SEC, melee_swing_up) \
33 w_cvar(id, sn, SEC, melee_swing_side) \
34 w_cvar(id, sn, SEC, melee_nonplayerdamage) \
35 w_cvar(id, sn, SEC, melee_multihit) \
36 w_cvar(id, sn, SEC, melee_delay) \
37 w_cvar(id, sn, SEC, melee_range) \
38 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
39 w_prop(id, sn, float, reloading_time, reload_time) \
40 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
41 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
42 w_prop(id, sn, string, weaponreplace, weaponreplace) \
43 w_prop(id, sn, float, weaponstart, weaponstart) \
44 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
45 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
48 SHOTGUN_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
52 void spawnfunc_weapon_shotgun(void) { weapon_defaultspawnfunc(WEP_SHOTGUN); }
54 void W_Shotgun_Attack(void)
59 W_DecreaseAmmo(WEP_CVAR_PRI(shotgun, ammo));
61 W_SetupShot(self, TRUE, 5, "weapons/shotgun_fire.wav", CH_WEAPON_A, WEP_CVAR_PRI(shotgun, damage) * WEP_CVAR_PRI(shotgun, bullets));
62 for(sc = 0;sc < WEP_CVAR_PRI(shotgun, bullets);sc = sc + 1)
63 fireBullet(w_shotorg, w_shotdir, WEP_CVAR_PRI(shotgun, spread), WEP_CVAR_PRI(shotgun, solidpenetration), WEP_CVAR_PRI(shotgun, damage), WEP_CVAR_PRI(shotgun, force), WEP_SHOTGUN, 0);
65 pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, WEP_CVAR_PRI(shotgun, ammo));
68 if(autocvar_g_casings >= 1)
69 for(sc = 0;sc < WEP_CVAR_PRI(shotgun, ammo);sc = sc + 1)
70 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);
72 // muzzle flash for 1st person view
74 setmodel(flash, "models/uziflash.md3"); // precision set below
75 flash.think = SUB_Remove;
76 flash.nextthink = time + 0.06;
77 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
78 W_AttachToShotorg(flash, '5 0 0');
82 .entity swing_alreadyhit;
83 void W_Shotgun_Melee_Think(void)
86 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
90 if(!self.cnt) // set start time of melee
93 W_PlayStrengthSound(self.realowner);
96 makevectors(self.realowner.v_angle); // update values for v_* vectors
98 // calculate swing percentage based on time
99 meleetime = WEP_CVAR_SEC(shotgun, melee_time) * W_WeaponRateFactor();
100 swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
101 f = ((1 - swing) * WEP_CVAR_SEC(shotgun, melee_traces));
103 // check to see if we can still continue, otherwise give up now
104 if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR_SEC(shotgun, melee_no_doubleslap))
110 // if okay, perform the traces needed for this frame
111 for(i=self.swing_prev; i < f; ++i)
113 swing_factor = ((1 - (i / WEP_CVAR_SEC(shotgun, melee_traces))) * 2 - 1);
115 targpos = (self.realowner.origin + self.realowner.view_ofs
116 + (v_forward * WEP_CVAR_SEC(shotgun, melee_range))
117 + (v_up * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_up))
118 + (v_right * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_side)));
120 WarpZone_traceline_antilag(self, self.realowner.origin + self.realowner.view_ofs, targpos, FALSE, self, ANTILAG_LATENCY(self.realowner));
122 // draw lightning beams for debugging
123 //te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
124 //te_customflash(targpos, 40, 2, '1 1 1');
126 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER));
128 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
129 && (trace_ent.takedamage == DAMAGE_AIM)
130 && (trace_ent != self.swing_alreadyhit)
131 && (is_player || WEP_CVAR_SEC(shotgun, melee_nonplayerdamage)))
133 target_victim = trace_ent; // so it persists through other calls
135 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
136 swing_damage = (WEP_CVAR_SEC(shotgun, damage) * min(1, swing_factor + 1));
138 swing_damage = (WEP_CVAR_SEC(shotgun, melee_nonplayerdamage) * min(1, swing_factor + 1));
140 //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
142 Damage(target_victim, self.realowner, self.realowner,
143 swing_damage, WEP_SHOTGUN | HITTYPE_SECONDARY,
144 self.realowner.origin + self.realowner.view_ofs,
145 v_forward * WEP_CVAR_SEC(shotgun, force));
147 if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOTGUN, 0, swing_damage); }
149 // draw large red flash for debugging
150 //te_customflash(targpos, 200, 2, '15 0 0');
152 if(WEP_CVAR_SEC(shotgun, melee_multihit)) // allow multiple hits with one swing, but not against the same player twice.
154 self.swing_alreadyhit = target_victim;
155 continue; // move along to next trace
165 if(time >= self.cnt + meleetime)
175 self.nextthink = time;
179 void W_Shotgun_Attack2(void)
181 sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTEN_NORM);
182 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(shotgun, animtime), w_ready);
186 meleetemp.realowner = self;
187 meleetemp.think = W_Shotgun_Melee_Think;
188 meleetemp.nextthink = time + WEP_CVAR_SEC(shotgun, melee_delay) * W_WeaponRateFactor();
189 W_SetupShot_Range(self, TRUE, 0, "", 0, WEP_CVAR_SEC(shotgun, damage), WEP_CVAR_SEC(shotgun, melee_range));
192 .float shotgun_primarytime;
194 float W_Shotgun(float req)
200 if(vlen(self.origin-self.enemy.origin) <= WEP_CVAR_SEC(shotgun, melee_range))
201 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
203 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
209 if(WEP_CVAR(shotgun, reload_ammo) && self.clip_load < WEP_CVAR_PRI(shotgun, ammo)) // forced reload
211 // don't force reload an empty shotgun if its melee attack is active
212 if(!WEP_CVAR(shotgun, secondary))
213 WEP_ACTION(self.weapon, WR_RELOAD);
219 if(time >= self.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
221 if(weapon_prepareattack(0, WEP_CVAR_PRI(shotgun, animtime)))
224 self.shotgun_primarytime = time + WEP_CVAR_PRI(shotgun, refire) * W_WeaponRateFactor();
225 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(shotgun, animtime), w_ready);
230 if(self.clip_load >= 0) // we are not currently reloading
231 if(!self.crouch) // no crouchmelee please
232 if(self.BUTTON_ATCK2 && WEP_CVAR(shotgun, secondary))
233 if(weapon_prepareattack(1, WEP_CVAR_SEC(shotgun, refire)))
235 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
236 weapon_thinkf(WFRAME_FIRE1, 0, W_Shotgun_Attack2);
243 precache_model("models/uziflash.md3");
244 precache_model("models/weapons/g_shotgun.md3");
245 precache_model("models/weapons/v_shotgun.md3");
246 precache_model("models/weapons/h_shotgun.iqm");
247 precache_sound("misc/itempickup.wav");
248 precache_sound("weapons/shotgun_fire.wav");
249 precache_sound("weapons/shotgun_melee.wav");
250 SHOTGUN_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
255 self.ammo_field = ammo_none;
261 // shotgun has infinite ammo
266 SHOTGUN_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
271 W_Reload(WEP_CVAR_PRI(shotgun, ammo), "weapons/reload.wav"); // WEAPONTODO
274 case WR_SUICIDEMESSAGE:
276 return WEAPON_THINKING_WITH_PORTALS;
280 if(w_deathtype & HITTYPE_SECONDARY)
281 return WEAPON_SHOTGUN_MURDER_SLAP;
283 return WEAPON_SHOTGUN_MURDER;
291 float W_Shotgun(float req)
295 case WR_IMPACTEFFECT:
298 org2 = w_org + w_backoff * 2;
299 pointparticles(particleeffectnum("shotgun_impact"), org2, w_backoff * 1000, 1);
300 if(!w_issilent && time - self.prevric > 0.25)
302 if(w_random < 0.0165)
303 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
304 else if(w_random < 0.033)
305 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
306 else if(w_random < 0.05)
307 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
315 precache_sound("weapons/ric1.wav");
316 precache_sound("weapons/ric2.wav");
317 precache_sound("weapons/ric3.wav");
322 // no weapon specific image for this weapon