4 /* ammotype */ ATTRIB(Shotgun, ammo_field, .int, ammo_shells);
5 /* impulse */ ATTRIB(Shotgun, impulse, int, 2);
6 /* flags */ ATTRIB(Shotgun, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_TYPE_MELEE_SEC);
7 /* rating */ ATTRIB(Shotgun, bot_pickupbasevalue, float, BOT_PICKUP_RATING_LOW);
8 /* color */ ATTRIB(Shotgun, wpcolor, vector, '0.5 0.25 0');
9 /* modelname */ ATTRIB(Shotgun, mdl, string, "shotgun");
11 /* model */ ATTRIB(Shotgun, m_model, Model, MDL_SHOTGUN_ITEM);
13 /* crosshair */ ATTRIB(Shotgun, w_crosshair, string, "gfx/crosshairshotgun");
14 /* crosshair */ ATTRIB(Shotgun, w_crosshair_size, float, 0.65);
15 /* wepimg */ ATTRIB(Shotgun, model2, string, "weaponshotgun");
16 /* refname */ ATTRIB(Shotgun, netname, string, "shotgun");
17 /* wepname */ ATTRIB(Shotgun, m_name, string, _("Shotgun"));
19 #define X(BEGIN, P, END, class, prefix) \
21 P(class, prefix, alt_animtime, float, SEC) \
22 P(class, prefix, alt_refire, float, SEC) \
23 P(class, prefix, ammo, float, PRI) \
24 P(class, prefix, animtime, float, BOTH) \
25 P(class, prefix, bullets, float, PRI) \
26 P(class, prefix, damage, float, BOTH) \
27 P(class, prefix, force, float, BOTH) \
28 P(class, prefix, melee_delay, float, SEC) \
29 P(class, prefix, melee_multihit, float, SEC) \
30 P(class, prefix, melee_nonplayerdamage, float, SEC) \
31 P(class, prefix, melee_no_doubleslap, float, SEC) \
32 P(class, prefix, melee_range, float, SEC) \
33 P(class, prefix, melee_swing_side, float, SEC) \
34 P(class, prefix, melee_swing_up, float, SEC) \
35 P(class, prefix, melee_time, float, SEC) \
36 P(class, prefix, melee_traces, float, SEC) \
37 P(class, prefix, refire, float, BOTH) \
38 P(class, prefix, reload_ammo, float, NONE) \
39 P(class, prefix, reload_time, float, NONE) \
40 P(class, prefix, secondary, float, NONE) \
41 P(class, prefix, solidpenetration, float, PRI) \
42 P(class, prefix, spread, float, PRI) \
43 P(class, prefix, switchdelay_drop, float, NONE) \
44 P(class, prefix, switchdelay_raise, float, NONE) \
45 P(class, prefix, weaponreplace, string,NONE) \
46 P(class, prefix, weaponstartoverride, float, NONE) \
47 P(class, prefix, weaponstart, float, NONE) \
48 P(class, prefix, weaponthrowable, float, NONE) \
50 W_PROPS(X, Shotgun, shotgun)
54 REGISTER_WEAPON(SHOTGUN, shotgun, NEW(Shotgun));
60 spawnfunc(weapon_shotgun) { weapon_defaultspawnfunc(this, WEP_SHOTGUN); }
62 void W_Shotgun_Attack(Weapon thiswep, entity actor, .entity weaponentity, float isprimary)
64 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(shotgun, ammo), weaponentity);
66 W_SetupShot(actor, weaponentity, true, 5, SND_SHOTGUN_FIRE, ((isprimary) ? CH_WEAPON_A : CH_WEAPON_SINGLE), WEP_CVAR_PRI(shotgun, damage) * WEP_CVAR_PRI(shotgun, bullets));
67 for(int sc = 0;sc < WEP_CVAR_PRI(shotgun, bullets);sc = sc + 1)
68 fireBullet(actor, weaponentity, 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);
70 Send_Effect(EFFECT_SHOTGUN_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, WEP_CVAR_PRI(shotgun, ammo));
73 if(autocvar_g_casings >= 1)
75 makevectors(actor.v_angle); // for some reason, this is lost
76 //for(int 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, actor, weaponentity);
80 // muzzle flash for 1st person view
81 entity flash = spawn();
82 setmodel(flash, MDL_SHOTGUN_MUZZLEFLASH); // precision set below
83 setthink(flash, SUB_Remove);
84 flash.nextthink = time + 0.06;
85 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
86 W_AttachToShotorg(actor, weaponentity, flash, '5 0 0');
90 .entity swing_alreadyhit;
91 void W_Shotgun_Melee_Think(entity this)
94 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
98 if(!this.cnt) // set start time of melee
101 W_PlayStrengthSound(this.realowner);
104 makevectors(this.realowner.v_angle); // update values for v_* vectors
106 // calculate swing percentage based on time
107 meleetime = WEP_CVAR_SEC(shotgun, melee_time) * W_WeaponRateFactor(this.realowner);
108 swing = bound(0, (this.cnt + meleetime - time) / meleetime, 10);
109 f = ((1 - swing) * WEP_CVAR_SEC(shotgun, melee_traces));
111 // check to see if we can still continue, otherwise give up now
112 if(IS_DEAD(this.realowner) && WEP_CVAR_SEC(shotgun, melee_no_doubleslap))
118 // if okay, perform the traces needed for this frame
119 for(i=this.swing_prev; i < f; ++i)
121 swing_factor = ((1 - (i / WEP_CVAR_SEC(shotgun, melee_traces))) * 2 - 1);
123 targpos = (this.realowner.origin + this.realowner.view_ofs
124 + (v_forward * WEP_CVAR_SEC(shotgun, melee_range))
125 + (v_up * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_up))
126 + (v_right * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_side)));
128 WarpZone_traceline_antilag(this, this.realowner.origin + this.realowner.view_ofs, targpos, false, this.realowner, ANTILAG_LATENCY(this.realowner));
130 // draw lightning beams for debugging
131 //te_lightning2(NULL, targpos, this.realowner.origin + this.realowner.view_ofs + v_forward * 5 - v_up * 5);
132 //te_customflash(targpos, 40, 2, '1 1 1');
134 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent));
136 if((trace_fraction < 1) // if trace is good, apply the damage and remove this
137 && (trace_ent.takedamage == DAMAGE_AIM)
138 && (trace_ent != this.swing_alreadyhit)
139 && (is_player || WEP_CVAR_SEC(shotgun, melee_nonplayerdamage)))
141 target_victim = trace_ent; // so it persists through other calls
143 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
144 swing_damage = (WEP_CVAR_SEC(shotgun, damage) * min(1, swing_factor + 1));
146 swing_damage = (WEP_CVAR_SEC(shotgun, melee_nonplayerdamage) * min(1, swing_factor + 1));
148 //print(strcat(this.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
150 Damage(target_victim, this.realowner, this.realowner,
151 swing_damage, WEP_SHOTGUN.m_id | HITTYPE_SECONDARY,
152 this.realowner.origin + this.realowner.view_ofs,
153 v_forward * WEP_CVAR_SEC(shotgun, force));
155 if(accuracy_isgooddamage(this.realowner, target_victim)) { accuracy_add(this.realowner, WEP_SHOTGUN.m_id, 0, swing_damage); }
157 // draw large red flash for debugging
158 //te_customflash(targpos, 200, 2, '15 0 0');
160 if(WEP_CVAR_SEC(shotgun, melee_multihit)) // allow multiple hits with one swing, but not against the same player twice.
162 this.swing_alreadyhit = target_victim;
163 continue; // move along to next trace
173 if(time >= this.cnt + meleetime)
183 this.nextthink = time;
187 void W_Shotgun_Attack2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
189 sound(actor, CH_WEAPON_A, SND_SHOTGUN_MELEE, VOL_BASE, ATTEN_NORM);
190 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(shotgun, animtime), w_ready);
192 entity meleetemp = new_pure(meleetemp);
193 meleetemp.realowner = actor;
194 setthink(meleetemp, W_Shotgun_Melee_Think);
195 meleetemp.nextthink = time + WEP_CVAR_SEC(shotgun, melee_delay) * W_WeaponRateFactor(actor);
196 W_SetupShot_Range(actor, weaponentity, true, 0, SND_Null, 0, WEP_CVAR_SEC(shotgun, damage), WEP_CVAR_SEC(shotgun, melee_range));
199 // alternate secondary weapon frames
200 void W_Shotgun_Attack3_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
202 if (!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
203 if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
205 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
206 w_ready(thiswep, actor, weaponentity, fire);
210 sound(actor, CH_WEAPON_SINGLE, SND_Null, VOL_BASE, ATTN_NORM); // kill previous sound
211 W_Shotgun_Attack(WEP_SHOTGUN, actor, weaponentity, true); // actually is secondary, but we trick the last shot into playing full reload sound
212 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), w_ready);
214 void W_Shotgun_Attack3_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
216 if (!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
217 if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
219 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
220 w_ready(thiswep, actor, weaponentity, fire);
224 W_Shotgun_Attack(WEP_SHOTGUN, actor, weaponentity, false);
225 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame2);
228 .float shotgun_primarytime[MAX_WEAPONSLOTS];
230 METHOD(Shotgun, wr_aim, void(entity thiswep, entity actor))
232 if(vdist(actor.origin - actor.enemy.origin, <=, WEP_CVAR_SEC(shotgun, melee_range)))
233 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, 1000000, 0, 0.001, false);
235 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, 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.(weaponentity).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 int slot = weaponslot(weaponentity);
251 if(time >= actor.shotgun_primarytime[slot]) // handle refire separately so the secondary can be fired straight after a primary
253 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(shotgun, animtime)))
255 W_Shotgun_Attack(thiswep, actor, weaponentity, true);
256 actor.shotgun_primarytime[slot] = time + WEP_CVAR_PRI(shotgun, refire) * W_WeaponRateFactor(actor);
257 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(shotgun, animtime), w_ready);
261 else if((fire & 2) && WEP_CVAR(shotgun, secondary) == 2)
263 int slot = weaponslot(weaponentity);
264 if(time >= actor.shotgun_primarytime[slot]) // handle refire separately so the secondary can be fired straight after a primary
266 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(shotgun, alt_animtime)))
268 W_Shotgun_Attack(thiswep, actor, weaponentity, false);
269 actor.shotgun_primarytime[slot] = time + WEP_CVAR_SEC(shotgun, alt_refire) * W_WeaponRateFactor(actor);
270 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame1);
275 if(actor.(weaponentity).clip_load >= 0) // we are not currently reloading
276 if(WEP_CVAR(shotgun, secondary) == 1)
277 if(((fire & 1) && actor.(thiswep.ammo_field) <= 0 && !(actor.items & IT_UNLIMITED_WEAPON_AMMO)) || (fire & 2))
278 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(shotgun, refire)))
280 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
281 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shotgun_Attack2);
284 METHOD(Shotgun, wr_setup, void(entity thiswep, entity actor))
286 actor.ammo_field = ammo_none;
288 METHOD(Shotgun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
290 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(shotgun, ammo);
291 ammo_amount += actor.(weapon_load[WEP_SHOTGUN.m_id]) >= WEP_CVAR_PRI(shotgun, ammo);
294 METHOD(Shotgun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
296 if(IS_BOT_CLIENT(actor))
297 if(vdist(actor.origin - actor.enemy.origin, >, WEP_CVAR_SEC(shotgun, melee_range)))
298 return false; // bots cannot use secondary out of range (fixes constant melee when out of ammo)
299 switch(WEP_CVAR(shotgun, secondary))
301 case 1: return true; // melee does not use ammo
302 case 2: // secondary triple shot
304 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(shotgun, ammo);
305 ammo_amount += actor.(weapon_load[WEP_SHOTGUN.m_id]) >= WEP_CVAR_PRI(shotgun, ammo);
308 default: return false; // secondary unavailable
311 METHOD(Shotgun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
313 W_Reload(actor, weaponentity, WEP_CVAR_PRI(shotgun, ammo), SND_RELOAD); // WEAPONTODO
315 METHOD(Shotgun, wr_suicidemessage, Notification(entity thiswep))
317 return WEAPON_THINKING_WITH_PORTALS;
319 METHOD(Shotgun, wr_killmessage, Notification(entity thiswep))
321 if(w_deathtype & HITTYPE_SECONDARY)
322 return WEAPON_SHOTGUN_MURDER_SLAP;
324 return WEAPON_SHOTGUN_MURDER;
331 METHOD(Shotgun, wr_impacteffect, void(entity thiswep, entity actor))
333 vector org2 = w_org + w_backoff * 2;
334 pointparticles(EFFECT_SHOTGUN_IMPACT, org2, w_backoff * 1000, 1);
335 if(!w_issilent && time - actor.prevric > 0.25)
338 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
339 actor.prevric = time;