3 /* ammotype */ ATTRIB(Shotgun, ammo_field, .int, ammo_shells)
4 /* impulse */ ATTRIB(Shotgun, impulse, int, 2)
5 /* flags */ ATTRIB(Shotgun, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN);
6 /* rating */ ATTRIB(Shotgun, bot_pickupbasevalue, float, BOT_PICKUP_RATING_LOW);
7 /* color */ ATTRIB(Shotgun, wpcolor, vector, '0.5 0.25 0');
8 /* modelname */ ATTRIB(Shotgun, mdl, string, "shotgun");
10 /* model */ ATTRIB(Shotgun, m_model, Model, MDL_SHOTGUN_ITEM);
12 /* crosshair */ ATTRIB(Shotgun, w_crosshair, string, "gfx/crosshairshotgun");
13 /* crosshair */ ATTRIB(Shotgun, w_crosshair_size, float, 0.65);
14 /* wepimg */ ATTRIB(Shotgun, model2, string, "weaponshotgun");
15 /* refname */ ATTRIB(Shotgun, netname, string, "shotgun");
16 /* wepname */ ATTRIB(Shotgun, m_name, string, _("Shotgun"));
18 #define X(BEGIN, P, END, class, prefix) \
20 P(class, prefix, alt_animtime, float, SEC) \
21 P(class, prefix, alt_refire, float, SEC) \
22 P(class, prefix, ammo, float, PRI) \
23 P(class, prefix, animtime, float, BOTH) \
24 P(class, prefix, bullets, float, PRI) \
25 P(class, prefix, damage, float, BOTH) \
26 P(class, prefix, force, float, BOTH) \
27 P(class, prefix, melee_delay, float, SEC) \
28 P(class, prefix, melee_multihit, float, SEC) \
29 P(class, prefix, melee_nonplayerdamage, float, SEC) \
30 P(class, prefix, melee_no_doubleslap, float, SEC) \
31 P(class, prefix, melee_range, float, SEC) \
32 P(class, prefix, melee_swing_side, float, SEC) \
33 P(class, prefix, melee_swing_up, float, SEC) \
34 P(class, prefix, melee_time, float, SEC) \
35 P(class, prefix, melee_traces, float, SEC) \
36 P(class, prefix, refire, float, BOTH) \
37 P(class, prefix, reload_ammo, float, NONE) \
38 P(class, prefix, reload_time, float, NONE) \
39 P(class, prefix, secondary, float, NONE) \
40 P(class, prefix, solidpenetration, float, PRI) \
41 P(class, prefix, spread, float, PRI) \
42 P(class, prefix, switchdelay_drop, float, NONE) \
43 P(class, prefix, switchdelay_raise, float, NONE) \
44 P(class, prefix, weaponreplace, string,NONE) \
45 P(class, prefix, weaponstartoverride, float, NONE) \
46 P(class, prefix, weaponstart, float, NONE) \
47 P(class, prefix, weaponthrowable, float, NONE) \
49 W_PROPS(X, Shotgun, shotgun)
53 REGISTER_WEAPON(SHOTGUN, shotgun, NEW(Shotgun));
59 spawnfunc(weapon_shotgun) { weapon_defaultspawnfunc(this, WEP_SHOTGUN); }
61 void W_Shotgun_Attack(Weapon thiswep, float isprimary)
66 W_DecreaseAmmo(thiswep, self, WEP_CVAR_PRI(shotgun, ammo));
68 W_SetupShot(self, true, 5, SND_SHOTGUN_FIRE, ((isprimary) ? CH_WEAPON_A : CH_WEAPON_SINGLE), WEP_CVAR_PRI(shotgun, damage) * WEP_CVAR_PRI(shotgun, bullets));
69 for(sc = 0;sc < WEP_CVAR_PRI(shotgun, bullets);sc = sc + 1)
70 fireBullet(self, 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.m_id, 0);
72 Send_Effect(EFFECT_SHOTGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, WEP_CVAR_PRI(shotgun, ammo));
75 if(autocvar_g_casings >= 1)
76 for(sc = 0;sc < WEP_CVAR_PRI(shotgun, ammo);sc = sc + 1)
77 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);
79 // muzzle flash for 1st person view
81 setmodel(flash, MDL_SHOTGUN_MUZZLEFLASH); // precision set below
82 flash.think = SUB_Remove_self;
83 flash.nextthink = time + 0.06;
84 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
85 W_AttachToShotorg(self, flash, '5 0 0');
89 .entity swing_alreadyhit;
90 void W_Shotgun_Melee_Think()
93 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
97 if(!self.cnt) // set start time of melee
100 W_PlayStrengthSound(self.realowner);
103 makevectors(self.realowner.v_angle); // update values for v_* vectors
105 // calculate swing percentage based on time
106 meleetime = WEP_CVAR_SEC(shotgun, melee_time) * W_WeaponRateFactor();
107 swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
108 f = ((1 - swing) * WEP_CVAR_SEC(shotgun, melee_traces));
110 // check to see if we can still continue, otherwise give up now
111 if(IS_DEAD(self.realowner) && WEP_CVAR_SEC(shotgun, melee_no_doubleslap))
117 // if okay, perform the traces needed for this frame
118 for(i=self.swing_prev; i < f; ++i)
120 swing_factor = ((1 - (i / WEP_CVAR_SEC(shotgun, melee_traces))) * 2 - 1);
122 targpos = (self.realowner.origin + self.realowner.view_ofs
123 + (v_forward * WEP_CVAR_SEC(shotgun, melee_range))
124 + (v_up * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_up))
125 + (v_right * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_side)));
127 WarpZone_traceline_antilag(self, self.realowner.origin + self.realowner.view_ofs, targpos, false, self.realowner, ANTILAG_LATENCY(self.realowner));
129 // draw lightning beams for debugging
130 //te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
131 //te_customflash(targpos, 40, 2, '1 1 1');
133 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent));
135 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
136 && (trace_ent.takedamage == DAMAGE_AIM)
137 && (trace_ent != self.swing_alreadyhit)
138 && (is_player || WEP_CVAR_SEC(shotgun, melee_nonplayerdamage)))
140 target_victim = trace_ent; // so it persists through other calls
142 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
143 swing_damage = (WEP_CVAR_SEC(shotgun, damage) * min(1, swing_factor + 1));
145 swing_damage = (WEP_CVAR_SEC(shotgun, melee_nonplayerdamage) * min(1, swing_factor + 1));
147 //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
149 Damage(target_victim, self.realowner, self.realowner,
150 swing_damage, WEP_SHOTGUN.m_id | HITTYPE_SECONDARY,
151 self.realowner.origin + self.realowner.view_ofs,
152 v_forward * WEP_CVAR_SEC(shotgun, force));
154 if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOTGUN.m_id, 0, swing_damage); }
156 // draw large red flash for debugging
157 //te_customflash(targpos, 200, 2, '15 0 0');
159 if(WEP_CVAR_SEC(shotgun, melee_multihit)) // allow multiple hits with one swing, but not against the same player twice.
161 self.swing_alreadyhit = target_victim;
162 continue; // move along to next trace
172 if(time >= self.cnt + meleetime)
182 self.nextthink = time;
186 void W_Shotgun_Attack2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
188 sound(actor, CH_WEAPON_A, SND_SHOTGUN_MELEE, VOL_BASE, ATTEN_NORM);
189 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(shotgun, animtime), w_ready);
191 entity meleetemp = new_pure(meleetemp);
192 meleetemp.realowner = actor;
193 meleetemp.think = W_Shotgun_Melee_Think;
194 meleetemp.nextthink = time + WEP_CVAR_SEC(shotgun, melee_delay) * W_WeaponRateFactor();
195 W_SetupShot_Range(actor, true, 0, SND_Null, 0, WEP_CVAR_SEC(shotgun, damage), WEP_CVAR_SEC(shotgun, melee_range));
198 // alternate secondary weapon frames
199 void W_Shotgun_Attack3_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
201 if (!thiswep.wr_checkammo2(thiswep))
202 if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
204 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
205 w_ready(thiswep, actor, weaponentity, fire);
209 sound(actor, CH_WEAPON_SINGLE, SND_Null, VOL_BASE, ATTN_NORM); // kill previous sound
210 W_Shotgun_Attack(WEP_SHOTGUN, true); // actually is secondary, but we trick the last shot into playing full reload sound
211 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), w_ready);
213 void W_Shotgun_Attack3_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
215 if (!thiswep.wr_checkammo2(thiswep))
216 if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
218 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
219 w_ready(thiswep, actor, weaponentity, fire);
223 W_Shotgun_Attack(WEP_SHOTGUN, false);
224 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame2);
227 .float shotgun_primarytime;
229 METHOD(Shotgun, wr_aim, void(entity thiswep))
232 if(vdist(self.origin - self.enemy.origin, <=, WEP_CVAR_SEC(shotgun, melee_range)))
233 PHYS_INPUT_BUTTON_ATCK2(self) = bot_aim(self, 1000000, 0, 0.001, false);
235 PHYS_INPUT_BUTTON_ATCK(self) = bot_aim(self, 1000000, 0, 0.001, false);
237 METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
239 if(WEP_CVAR(shotgun, reload_ammo) && actor.clip_load < WEP_CVAR_PRI(shotgun, ammo)) // forced reload
241 // don't force reload an empty shotgun if its melee attack is active
242 if(WEP_CVAR(shotgun, secondary) < 2) {
243 thiswep.wr_reload(thiswep, actor, weaponentity);
250 if(time >= actor.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
252 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(shotgun, animtime)))
254 W_Shotgun_Attack(thiswep, true);
255 actor.shotgun_primarytime = time + WEP_CVAR_PRI(shotgun, refire) * W_WeaponRateFactor();
256 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(shotgun, animtime), w_ready);
260 else if((fire & 2) && WEP_CVAR(shotgun, secondary) == 2)
262 if(time >= actor.shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
264 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(shotgun, alt_animtime)))
266 W_Shotgun_Attack(thiswep, false);
267 actor.shotgun_primarytime = time + WEP_CVAR_SEC(shotgun, alt_refire) * W_WeaponRateFactor();
268 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame1);
273 if(actor.clip_load >= 0) // we are not currently reloading
274 if(!actor.crouch) // no crouchmelee please
275 if(WEP_CVAR(shotgun, secondary) == 1)
276 if(((fire & 1) && actor.(thiswep.ammo_field) <= 0 && !(actor.items & IT_UNLIMITED_WEAPON_AMMO)) || (fire & 2))
277 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(shotgun, refire)))
279 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
280 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shotgun_Attack2);
283 METHOD(Shotgun, wr_setup, void(entity thiswep))
286 self.ammo_field = ammo_none;
288 METHOD(Shotgun, wr_checkammo1, bool(entity thiswep))
291 float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR_PRI(shotgun, ammo);
292 ammo_amount += self.(weapon_load[WEP_SHOTGUN.m_id]) >= WEP_CVAR_PRI(shotgun, ammo);
295 METHOD(Shotgun, wr_checkammo2, bool(entity thiswep))
298 if(IS_BOT_CLIENT(self))
299 if(vdist(self.origin - self.enemy.origin, >, WEP_CVAR_SEC(shotgun, melee_range)))
300 return false; // bots cannot use secondary out of range (fixes constant melee when out of ammo)
301 switch(WEP_CVAR(shotgun, secondary))
303 case 1: return true; // melee does not use ammo
304 case 2: // secondary triple shot
306 float ammo_amount = self.(thiswep.ammo_field) >= WEP_CVAR_PRI(shotgun, ammo);
307 ammo_amount += self.(weapon_load[WEP_SHOTGUN.m_id]) >= WEP_CVAR_PRI(shotgun, ammo);
310 default: return false; // secondary unavailable
313 METHOD(Shotgun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
316 W_Reload(self, WEP_CVAR_PRI(shotgun, ammo), SND_RELOAD); // WEAPONTODO
318 METHOD(Shotgun, wr_suicidemessage, Notification(entity thiswep))
320 return WEAPON_THINKING_WITH_PORTALS;
322 METHOD(Shotgun, wr_killmessage, Notification(entity thiswep))
324 if(w_deathtype & HITTYPE_SECONDARY)
325 return WEAPON_SHOTGUN_MURDER_SLAP;
327 return WEAPON_SHOTGUN_MURDER;
334 METHOD(Shotgun, wr_impacteffect, void(entity thiswep))
337 vector org2 = w_org + w_backoff * 2;
338 pointparticles(EFFECT_SHOTGUN_IMPACT, org2, w_backoff * 1000, 1);
339 if(!w_issilent && time - self.prevric > 0.25)
342 sound(self, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);