5 // enable to debug melee range
6 //#define SHOTGUN_MELEEDEBUG
8 void W_Shotgun_Attack(Weapon thiswep, entity actor, .entity weaponentity, float isprimary, float ammocount, float damage, float bullets, float spread, float solidpenetration, float force, entity bullet_trail_effect)
10 W_DecreaseAmmo(thiswep, actor, ammocount, weaponentity);
12 W_SetupShot(actor, weaponentity, true, 5, SND_SHOTGUN_FIRE, ((isprimary) ? CH_WEAPON_A : CH_WEAPON_SINGLE), damage * bullets, thiswep.m_id);
14 // TRICK: do the antilag outside the regular fireBullet function, so it isn't performed unnecessarily on every single bullet!
15 float lag = antilag_getlag(actor);
16 if(lag && bullets > 0)
17 antilag_takeback_all(actor, lag);
19 for(int sc = 0;sc < bullets;sc = sc + 1)
20 fireBullet_antilag(actor, weaponentity, w_shotorg, w_shotdir, spread, solidpenetration, damage, 0, force, thiswep.m_id, bullet_trail_effect, false);
22 if(lag && bullets > 0)
23 antilag_restore_all(actor);
25 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
28 if(autocvar_g_casings >= 1)
30 makevectors(actor.v_angle); // for some reason, this is lost
31 //for(int sc = 0;sc < WEP_CVAR_PRI(shotgun, ammo);sc = sc + 1)
32 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);
37 .entity swing_alreadyhit;
38 void W_Shotgun_Melee_Think(entity this)
41 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
45 if(!this.cnt) // set start time of melee
48 W_PlayStrengthSound(this.realowner);
51 makevectors(this.realowner.v_angle); // update values for v_* vectors
53 // calculate swing percentage based on time
54 meleetime = WEP_CVAR_SEC(shotgun, melee_time) * W_WeaponRateFactor(this.realowner);
55 swing = bound(0, (this.cnt + meleetime - time) / meleetime, 10);
56 f = ((1 - swing) * WEP_CVAR_SEC(shotgun, melee_traces));
58 // check to see if we can still continue, otherwise give up now
59 if(IS_DEAD(this.realowner) && WEP_CVAR_SEC(shotgun, melee_no_doubleslap))
65 // if okay, perform the traces needed for this frame
66 for(i=this.swing_prev; i < f; ++i)
68 swing_factor = ((1 - (i / WEP_CVAR_SEC(shotgun, melee_traces))) * 2 - 1);
70 targpos = (this.realowner.origin + this.realowner.view_ofs
71 + (v_forward * WEP_CVAR_SEC(shotgun, melee_range))
72 + (v_up * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_up))
73 + (v_right * swing_factor * WEP_CVAR_SEC(shotgun, melee_swing_side)));
75 WarpZone_traceline_antilag(this.realowner, this.realowner.origin + this.realowner.view_ofs, targpos, false, this.realowner, ((IS_CLIENT(this.realowner)) ? ANTILAG_LATENCY(this.realowner) : 0));
77 // draw lightning beams for debugging
78 #ifdef SHOTGUN_MELEEDEBUG
79 te_lightning2(NULL, targpos, this.realowner.origin + this.realowner.view_ofs + v_forward * 5 - v_up * 5);
80 te_customflash(targpos, 40, 2, '1 1 1');
83 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent));
85 if((trace_fraction < 1) // if trace is good, apply the damage and remove this
86 && (trace_ent.takedamage != DAMAGE_NO)
87 && (trace_ent != this.swing_alreadyhit)
88 && (is_player || WEP_CVAR_SEC(shotgun, melee_nonplayerdamage)))
90 target_victim = trace_ent; // so it persists through other calls
92 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
93 swing_damage = (WEP_CVAR_SEC(shotgun, damage) * min(1, swing_factor + 1));
95 swing_damage = (WEP_CVAR_SEC(shotgun, melee_nonplayerdamage) * min(1, swing_factor + 1));
97 //print(strcat(this.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
99 Damage(target_victim, this.realowner, this.realowner,
100 swing_damage, WEP_SHOTGUN.m_id | HITTYPE_SECONDARY, this.weaponentity_fld,
101 this.realowner.origin + this.realowner.view_ofs,
102 v_forward * WEP_CVAR_SEC(shotgun, force));
104 if(accuracy_isgooddamage(this.realowner, target_victim)) { accuracy_add(this.realowner, WEP_SHOTGUN, 0, swing_damage); }
106 // draw large red flash for debugging
107 #ifdef SHOTGUN_MELEEDEBUG
108 te_customflash(targpos, 200, 2, '15 0 0');
111 if(WEP_CVAR_SEC(shotgun, melee_multihit)) // allow multiple hits with one swing, but not against the same player twice.
113 this.swing_alreadyhit = target_victim;
114 continue; // move along to next trace
124 if(time >= this.cnt + meleetime)
134 this.nextthink = time;
138 void W_Shotgun_Attack2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
140 sound(actor, CH_WEAPON_A, SND_SHOTGUN_MELEE, VOL_BASE, ATTEN_NORM);
141 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(shotgun, animtime), w_ready);
143 entity meleetemp = new_pure(meleetemp);
144 meleetemp.realowner = actor;
145 setthink(meleetemp, W_Shotgun_Melee_Think);
146 meleetemp.nextthink = time + WEP_CVAR_SEC(shotgun, melee_delay) * W_WeaponRateFactor(actor);
147 meleetemp.weaponentity_fld = weaponentity;
148 W_SetupShot_Range(actor, weaponentity, true, 0, SND_Null, 0, WEP_CVAR_SEC(shotgun, damage), WEP_CVAR_SEC(shotgun, melee_range), WEP_SHOTGUN.m_id | HITTYPE_SECONDARY);
151 // alternate secondary weapon frames
152 void W_Shotgun_Attack3_Frame2(Weapon thiswep, entity actor, .entity weaponentity, int fire)
154 if (!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
155 if (!(actor.items & IT_UNLIMITED_AMMO))
157 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
158 w_ready(thiswep, actor, weaponentity, fire);
162 sound(actor, CH_WEAPON_SINGLE, SND_Null, VOL_BASE, ATTN_NORM); // kill previous sound
163 W_Shotgun_Attack(thiswep, actor, weaponentity, true,
164 WEP_CVAR_PRI(shotgun, ammo),
165 WEP_CVAR_PRI(shotgun, damage),
166 WEP_CVAR_PRI(shotgun, bullets),
167 WEP_CVAR_PRI(shotgun, spread),
168 WEP_CVAR_PRI(shotgun, solidpenetration),
169 WEP_CVAR_PRI(shotgun, force),
170 EFFECT_BULLET_WEAK); // actually is secondary, but we trick the last shot into playing full reload sound
171 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), w_ready);
173 void W_Shotgun_Attack3_Frame1(Weapon thiswep, entity actor, .entity weaponentity, int fire)
175 if (!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
176 if (!(actor.items & IT_UNLIMITED_AMMO))
178 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
179 w_ready(thiswep, actor, weaponentity, fire);
183 W_Shotgun_Attack(thiswep, actor, weaponentity, false,
184 WEP_CVAR_PRI(shotgun, ammo),
185 WEP_CVAR_PRI(shotgun, damage),
186 WEP_CVAR_PRI(shotgun, bullets),
187 WEP_CVAR_PRI(shotgun, spread),
188 WEP_CVAR_PRI(shotgun, solidpenetration),
189 WEP_CVAR_PRI(shotgun, force),
191 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame2);
194 .float shotgun_primarytime;
196 METHOD(Shotgun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
198 if(vdist(actor.origin - actor.enemy.origin, <=, WEP_CVAR_SEC(shotgun, melee_range)))
199 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
201 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false);
204 METHOD(Shotgun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
206 // force reload weapon when clip is empty or insufficent
207 if(WEP_CVAR(shotgun, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(shotgun, ammo))
209 if(actor.(weaponentity).clip_load >= 0 && GetResource(actor, thiswep.ammo_type) > 0)
211 thiswep.wr_reload(thiswep, actor, weaponentity);
216 if(actor.(weaponentity).clip_load >= 0) // we are not currently reloading
220 if(time >= actor.(weaponentity).shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
222 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(shotgun, animtime)))
224 W_Shotgun_Attack(thiswep, actor, weaponentity, true,
225 WEP_CVAR_PRI(shotgun, ammo),
226 WEP_CVAR_PRI(shotgun, damage),
227 WEP_CVAR_PRI(shotgun, bullets),
228 WEP_CVAR_PRI(shotgun, spread),
229 WEP_CVAR_PRI(shotgun, solidpenetration),
230 WEP_CVAR_PRI(shotgun, force),
232 actor.(weaponentity).shotgun_primarytime = time + WEP_CVAR_PRI(shotgun, refire) * W_WeaponRateFactor(actor);
233 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(shotgun, animtime), w_ready);
238 else if((fire & 2) && WEP_CVAR(shotgun, secondary) == 2)
240 if(time >= actor.(weaponentity).shotgun_primarytime) // handle refire separately so the secondary can be fired straight after a primary
242 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_SEC(shotgun, alt_animtime)))
244 W_Shotgun_Attack(thiswep, actor, weaponentity, false,
245 WEP_CVAR_PRI(shotgun, ammo),
246 WEP_CVAR_PRI(shotgun, damage),
247 WEP_CVAR_PRI(shotgun, bullets),
248 WEP_CVAR_PRI(shotgun, spread),
249 WEP_CVAR_PRI(shotgun, solidpenetration),
250 WEP_CVAR_PRI(shotgun, force),
252 actor.(weaponentity).shotgun_primarytime = time + WEP_CVAR_SEC(shotgun, alt_refire) * W_WeaponRateFactor(actor);
253 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_SEC(shotgun, alt_animtime), W_Shotgun_Attack3_Frame1);
260 if(actor.(weaponentity).clip_load >= 0) // we are not currently reloading
261 if(WEP_CVAR(shotgun, secondary) == 1)
262 if(((fire & 1) && !IS_BOT_CLIENT(actor) && GetResource(actor, thiswep.ammo_type) <= 0 && actor.(weaponentity).clip_load == 0 && !(actor.items & IT_UNLIMITED_AMMO)) || (fire & 2))
263 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(shotgun, refire)))
266 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
267 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shotgun_Attack2);
270 METHOD(Shotgun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
272 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(shotgun, ammo);
273 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(shotgun, ammo);
276 METHOD(Shotgun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
278 switch(WEP_CVAR(shotgun, secondary))
280 case 1: return true; // melee does not use ammo
281 case 2: // secondary triple shot
283 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(shotgun, ammo);
284 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(shotgun, ammo);
287 default: return false; // secondary unavailable
290 METHOD(Shotgun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
292 W_Reload(actor, weaponentity, WEP_CVAR_PRI(shotgun, ammo), SND_RELOAD); // WEAPONTODO
294 METHOD(Shotgun, wr_suicidemessage, Notification(entity thiswep))
296 return WEAPON_THINKING_WITH_PORTALS;
298 METHOD(Shotgun, wr_killmessage, Notification(entity thiswep))
300 if(w_deathtype & HITTYPE_SECONDARY)
301 return WEAPON_SHOTGUN_MURDER_SLAP;
303 return WEAPON_SHOTGUN_MURDER;
310 METHOD(Shotgun, wr_impacteffect, void(entity thiswep, entity actor))
312 vector org2 = w_org + w_backoff * 2;
313 pointparticles(EFFECT_SHOTGUN_IMPACT, org2, w_backoff * 1000, 1);
314 if(!w_issilent && time - actor.prevric > 0.25)
317 sound(actor, CH_SHOTS, SND_RIC_RANDOM(), VOL_BASE, ATTEN_NORM);
318 actor.prevric = time;