2019-08-31 19:18:15 -07:00
|
|
|
/*
|
2020-04-07 05:46:23 -07:00
|
|
|
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
2019-08-31 19:18:15 -07:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
2016-12-02 15:12:10 -08:00
|
|
|
|
2020-04-21 20:56:21 -07:00
|
|
|
#ifdef BULLETPENETRATION
|
2019-09-04 01:38:39 -07:00
|
|
|
var int iTotalPenetrations;
|
2019-03-26 06:37:34 -07:00
|
|
|
#endif
|
2017-01-07 12:18:15 -08:00
|
|
|
|
2019-09-04 01:38:39 -07:00
|
|
|
/* cast a single bullet shot */
|
|
|
|
void
|
2020-04-12 06:50:42 -07:00
|
|
|
TraceAttack_FireSingle(vector vecPos, vector vAngle, int iDamage, int iWeapon)
|
2019-02-27 23:18:01 -08:00
|
|
|
{
|
2019-09-04 01:38:39 -07:00
|
|
|
string tex;
|
|
|
|
vector range;
|
|
|
|
float surf;
|
|
|
|
|
|
|
|
range = (vAngle * 8196);
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
traceline(vecPos, vecPos + range, MOVE_LAGGED | MOVE_HITMODEL, self);
|
2019-09-04 01:38:39 -07:00
|
|
|
if (trace_fraction >= 1.0f) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-26 06:37:34 -07:00
|
|
|
|
2019-09-04 01:38:39 -07:00
|
|
|
if (trace_ent.takedamage == DAMAGE_YES) {
|
|
|
|
#ifdef CSTRIKE
|
|
|
|
/* modify the damage based on the location */
|
|
|
|
switch (trace_surface_id) {
|
|
|
|
case BODY_HEAD:
|
|
|
|
/* the helmet is one power house */
|
2020-04-12 06:50:42 -07:00
|
|
|
if (trace_ent.items & ITEM_HELMET) {
|
2019-09-04 01:38:39 -07:00
|
|
|
iDamage = 0;
|
|
|
|
sound(self, CHAN_ITEM, "weapons/ric_metal-2.wav", 1, ATTN_IDLE);
|
2020-04-12 06:50:42 -07:00
|
|
|
trace_ent.items &= ~ITEM_HELMET;
|
2019-09-04 01:38:39 -07:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
iDamage *= 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BODY_STOMACH:
|
|
|
|
iDamage *= 0.9;
|
|
|
|
break;
|
|
|
|
case BODY_LEGLEFT:
|
|
|
|
case BODY_LEGRIGHT:
|
|
|
|
iDamage *= 0.4;
|
|
|
|
break;
|
2017-01-07 12:18:15 -08:00
|
|
|
}
|
2019-09-04 01:38:39 -07:00
|
|
|
#else
|
|
|
|
/* only headshots count in HL */
|
|
|
|
if (trace_surface_id == BODY_HEAD) {
|
|
|
|
iDamage *= 3;
|
|
|
|
}
|
|
|
|
#endif
|
2019-09-28 16:54:29 -07:00
|
|
|
Damage_Apply(trace_ent, self, iDamage, iWeapon, DMG_BULLET);
|
2019-09-04 01:38:39 -07:00
|
|
|
}
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2019-09-04 01:38:39 -07:00
|
|
|
if (trace_ent.iBleeds == TRUE) {
|
2020-04-22 18:13:29 -07:00
|
|
|
FX_Blood(trace_endpos, [1,0,0]);
|
2019-09-04 01:38:39 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surf = getsurfacenearpoint(trace_ent, trace_endpos);
|
|
|
|
tex = getsurfacetexture(trace_ent, surf);
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2019-09-04 01:38:39 -07:00
|
|
|
/* our hashtable is the key to all this */
|
|
|
|
switch ((float)hash_get(hashMaterials, tex)) {
|
|
|
|
case 'G':
|
|
|
|
case 'V':
|
2020-04-22 18:13:29 -07:00
|
|
|
FX_Impact(IMPACT_METAL, trace_endpos, trace_plane_normal);
|
2019-09-04 01:38:39 -07:00
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
case 'P':
|
2020-04-22 18:13:29 -07:00
|
|
|
FX_Impact(IMPACT_METAL, trace_endpos, trace_plane_normal);
|
2019-09-04 01:38:39 -07:00
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
case 'W':
|
2020-04-22 18:13:29 -07:00
|
|
|
FX_Impact(IMPACT_WOOD, trace_endpos, trace_plane_normal);
|
2019-09-04 01:38:39 -07:00
|
|
|
break;
|
|
|
|
case 'Y':
|
2020-04-22 18:13:29 -07:00
|
|
|
FX_Impact(IMPACT_GLASS, trace_endpos, trace_plane_normal);
|
2019-09-04 01:38:39 -07:00
|
|
|
break;
|
|
|
|
case 'N':
|
2020-04-22 18:13:29 -07:00
|
|
|
FX_Impact(IMPACT_DEFAULT, trace_endpos, trace_plane_normal);
|
2019-09-04 01:38:39 -07:00
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
default:
|
2020-04-22 18:13:29 -07:00
|
|
|
FX_Impact(IMPACT_DEFAULT, trace_endpos, trace_plane_normal);
|
2019-09-04 01:38:39 -07:00
|
|
|
break;
|
|
|
|
}
|
2019-03-26 06:37:34 -07:00
|
|
|
|
2020-04-21 20:56:21 -07:00
|
|
|
#ifdef BULLETPENETRATION
|
2019-09-04 01:38:39 -07:00
|
|
|
if (iTotalPenetrations > 0) {
|
|
|
|
iTotalPenetrations -= 1;
|
2019-09-16 17:29:00 -07:00
|
|
|
TraceAttack_FireSingle(trace_endpos + (v_forward * 2), vAngle, iDamage, iWeapon);
|
2017-01-07 12:18:15 -08:00
|
|
|
}
|
2019-09-04 01:38:39 -07:00
|
|
|
#endif
|
2017-01-07 12:18:15 -08:00
|
|
|
}
|
2017-01-10 10:24:45 -08:00
|
|
|
|
2019-09-04 01:38:39 -07:00
|
|
|
/* fire a given amount of shots */
|
|
|
|
void
|
2020-04-12 06:50:42 -07:00
|
|
|
TraceAttack_FireBullets(int iShots, vector vecPos, int iDamage, vector vecSpread, int iWeapon)
|
2019-02-20 05:30:16 -08:00
|
|
|
{
|
2017-01-07 09:01:44 -08:00
|
|
|
vector vDir;
|
2016-12-02 15:12:10 -08:00
|
|
|
makevectors(self.v_angle);
|
2019-01-28 18:40:14 -08:00
|
|
|
|
2019-02-20 05:30:16 -08:00
|
|
|
while (iShots > 0) {
|
2020-04-21 20:56:21 -07:00
|
|
|
#ifdef BULLETPENETRATION
|
2020-04-14 07:19:25 -07:00
|
|
|
iTotalPenetrations = 2;
|
2019-03-26 06:37:34 -07:00
|
|
|
#endif
|
2019-09-04 01:38:39 -07:00
|
|
|
vDir = aim(self, 100000);
|
2020-04-12 06:50:42 -07:00
|
|
|
#ifndef CSTRIKE
|
|
|
|
vDir += random(-1,1) * vecSpread[0] * v_right;
|
|
|
|
vDir += random(-1,1) * vecSpread[1] * v_up;
|
|
|
|
#else
|
|
|
|
player pl = (player)self;
|
|
|
|
|
|
|
|
/* weapons have already applied their multiplier... so attempt this */
|
|
|
|
int multiplier = pl.cs_shotmultiplier - iShots;
|
|
|
|
float frand = (multiplier / 6);
|
|
|
|
|
|
|
|
/* shoddy attempt at spray patterns */
|
|
|
|
if (frand < 1)
|
|
|
|
frand = frand;
|
|
|
|
else if (frand <= 2)
|
|
|
|
frand = 2 - (frand * 1.5);
|
|
|
|
|
|
|
|
vDir += frand * vecSpread[0] * v_right;
|
|
|
|
vDir += (vecSpread[1] * v_up) * 2;
|
|
|
|
#endif
|
|
|
|
TraceAttack_FireSingle(vecPos, vDir, iDamage, iWeapon);
|
2016-12-02 15:12:10 -08:00
|
|
|
iShots--;
|
|
|
|
}
|
|
|
|
}
|