From e04bd67aa331b48999f65bd66fa1f7f965c9b7b8 Mon Sep 17 00:00:00 2001 From: BjossiAlfreds Date: Wed, 1 Jan 2020 21:50:07 +0000 Subject: [PATCH] Parasite blocked attack bugfix and dead code elimination --- src/g_newai.c | 96 ----------------------------- src/header/local.h | 1 - src/monster/chick/chick.c | 5 -- src/monster/float/float.c | 10 --- src/monster/flyer/flyer.c | 4 -- src/monster/gladiator/gladiator.c | 5 -- src/monster/gunner/gunner.c | 5 -- src/monster/hover/hover.c | 10 --- src/monster/infantry/infantry.c | 5 -- src/monster/medic/medic.c | 5 -- src/monster/parasite/parasite.c | 33 +++++++++- src/monster/soldier/soldier.c | 5 -- src/monster/stalker/stalker.c | 11 +--- src/monster/supertank/supertank.c | 5 -- src/monster/tank/tank.c | 9 +-- src/monster/widow/widow.c | 5 -- src/savegame/tables/gamefunc_decs.h | 1 - src/savegame/tables/gamefunc_list.h | 1 - 18 files changed, 37 insertions(+), 179 deletions(-) diff --git a/src/g_newai.c b/src/g_newai.c index e8a5595..0cbe35d 100644 --- a/src/g_newai.c +++ b/src/g_newai.c @@ -24,104 +24,8 @@ int num_hint_paths; qboolean face_wall(edict_t *self); qboolean monsterlost_checkhint2(edict_t *self); -qboolean parasite_drain_attack_ok(vec3_t start, vec3_t end); void HuntTarget(edict_t *self); -qboolean -blocked_checkshot(edict_t *self, float shotChance) -{ - qboolean playerVisible; - - if (!self) - { - return false; - } - - if (!self->enemy) - { - return false; - } - - /* blocked checkshot is only against players. this will - filter out player sounds and other shit they should - not be firing at. */ - if (!(self->enemy->client)) - { - return false; - } - - if (random() < shotChance) - { - return false; - } - - if (!strcmp(self->classname, "monster_parasite")) - { - vec3_t f, r, offset, start, end; - trace_t tr; - AngleVectors(self->s.angles, f, r, NULL); - VectorSet(offset, 24, 0, 6); - G_ProjectSource(self->s.origin, offset, f, r, start); - - VectorCopy(self->enemy->s.origin, end); - - if (!parasite_drain_attack_ok(start, end)) - { - end[2] = self->enemy->s.origin[2] + self->enemy->maxs[2] - 8; - - if (!parasite_drain_attack_ok(start, end)) - { - end[2] = self->enemy->s.origin[2] + self->enemy->mins[2] + 8; - - if (!parasite_drain_attack_ok(start, end)) - { - return false; - } - } - } - - VectorCopy(self->enemy->s.origin, end); - - tr = gi.trace(start, NULL, NULL, end, self, MASK_SHOT); - - if (tr.ent != self->enemy) - { - self->monsterinfo.aiflags |= AI_BLOCKED; - - if (self->monsterinfo.attack) - { - self->monsterinfo.attack(self); - } - - self->monsterinfo.aiflags &= ~AI_BLOCKED; - return true; - } - } - - playerVisible = visible(self, self->enemy); - - /* always shoot at teslas */ - if (playerVisible) - { - if (!strcmp(self->enemy->classname, "tesla")) - { - /* turn on AI_BLOCKED to let the monster know the attack - is being called by the blocked functions... */ - self->monsterinfo.aiflags |= AI_BLOCKED; - - if (self->monsterinfo.attack) - { - self->monsterinfo.attack(self); - } - - self->monsterinfo.aiflags &= ~AI_BLOCKED; - return true; - } - } - - return false; -} - qboolean blocked_checkplat(edict_t *self, float dist) { diff --git a/src/header/local.h b/src/header/local.h index f48fff3..6c875c5 100644 --- a/src/header/local.h +++ b/src/header/local.h @@ -924,7 +924,6 @@ void fire_tracker(edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, edict_t *enemy); /* g_newai.c */ -qboolean blocked_checkshot(edict_t *self, float shotChance); qboolean blocked_checkplat(edict_t *self, float dist); qboolean blocked_checkjump(edict_t *self, float dist, float maxDown, float maxUp); qboolean blocked_checknewenemy(edict_t *self); diff --git a/src/monster/chick/chick.c b/src/monster/chick/chick.c index fd9e7ec..c8d5f9e 100644 --- a/src/monster/chick/chick.c +++ b/src/monster/chick/chick.c @@ -977,11 +977,6 @@ chick_blocked(edict_t *self, float dist) return false; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - if (blocked_checkplat(self, dist)) { return true; diff --git a/src/monster/float/float.c b/src/monster/float/float.c index e1bde30..5897ca8 100644 --- a/src/monster/float/float.c +++ b/src/monster/float/float.c @@ -804,16 +804,6 @@ floater_die(edict_t *self, edict_t *inflictor /* unused */, edict_t *attacker /* qboolean floater_blocked(edict_t *self, float dist) { - if (!self) - { - return false; - } - - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - return false; } diff --git a/src/monster/flyer/flyer.c b/src/monster/flyer/flyer.c index 07c0cac..ff61577 100644 --- a/src/monster/flyer/flyer.c +++ b/src/monster/flyer/flyer.c @@ -991,10 +991,6 @@ flyer_blocked(edict_t *self, float dist) } /* we're a normal flyer */ - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } return false; } diff --git a/src/monster/gladiator/gladiator.c b/src/monster/gladiator/gladiator.c index c0e9c15..a925a29 100644 --- a/src/monster/gladiator/gladiator.c +++ b/src/monster/gladiator/gladiator.c @@ -474,11 +474,6 @@ gladiator_blocked(edict_t *self, float dist) return false; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value) )) - { - return true; - } - if (blocked_checkplat(self, dist)) { return true; diff --git a/src/monster/gunner/gunner.c b/src/monster/gunner/gunner.c index c023512..317c51a 100644 --- a/src/monster/gunner/gunner.c +++ b/src/monster/gunner/gunner.c @@ -1101,11 +1101,6 @@ gunner_blocked(edict_t *self, float dist) return false; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - if (blocked_checkplat(self, dist)) { return true; diff --git a/src/monster/hover/hover.c b/src/monster/hover/hover.c index b23347b..9244741 100644 --- a/src/monster/hover/hover.c +++ b/src/monster/hover/hover.c @@ -760,16 +760,6 @@ hover_die(edict_t *self, edict_t *inflictor /* unused */, edict_t *attacker /* u qboolean hover_blocked(edict_t *self, float dist) { - if (!self) - { - return false; - } - - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - return false; } diff --git a/src/monster/infantry/infantry.c b/src/monster/infantry/infantry.c index b169250..54cb5fa 100644 --- a/src/monster/infantry/infantry.c +++ b/src/monster/infantry/infantry.c @@ -821,11 +821,6 @@ infantry_blocked(edict_t *self, float dist) return false; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - if (blocked_checkjump(self, dist, 192, 40)) { infantry_jump(self); diff --git a/src/monster/medic/medic.c b/src/monster/medic/medic.c index 44410bb..9e25995 100644 --- a/src/monster/medic/medic.c +++ b/src/monster/medic/medic.c @@ -1866,11 +1866,6 @@ medic_blocked(edict_t *self, float dist) return false; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - if (blocked_checkplat(self, dist)) { return true; diff --git a/src/monster/parasite/parasite.c b/src/monster/parasite/parasite.c index ffbdcf0..ea425bf 100644 --- a/src/monster/parasite/parasite.c +++ b/src/monster/parasite/parasite.c @@ -753,9 +753,38 @@ parasite_blocked(edict_t *self, float dist) return false; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) + if (self->enemy && self->enemy->client && random() >= (0.25 + (0.05 * skill->value))) { - return true; + vec3_t f, r, offset, start, end; + + AngleVectors(self->s.angles, f, r, NULL); + VectorSet(offset, 24, 0, 6); + G_ProjectSource(self->s.origin, offset, f, r, start); + + VectorCopy(self->enemy->s.origin, end); + + if (!parasite_drain_attack_ok(start, end)) + { + end[2] = self->enemy->s.origin[2] + self->enemy->maxs[2] - 8; + + if (!parasite_drain_attack_ok(start, end)) + { + end[2] = self->enemy->s.origin[2] + self->enemy->mins[2] + 8; + + if (!parasite_drain_attack_ok(start, end)) + { + return false; + } + } + } + + VectorCopy(self->enemy->s.origin, end); + + if (visible(self, self->enemy)) + { + parasite_attack(self); + return true; + } } if (blocked_checkjump(self, dist, 256, 68)) diff --git a/src/monster/soldier/soldier.c b/src/monster/soldier/soldier.c index 0065c48..594b9b9 100644 --- a/src/monster/soldier/soldier.c +++ b/src/monster/soldier/soldier.c @@ -1182,11 +1182,6 @@ soldier_blocked(edict_t *self, float dist) return false; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - if (blocked_checkplat(self, dist)) { return true; diff --git a/src/monster/stalker/stalker.c b/src/monster/stalker/stalker.c index 0084c7b..417320f 100644 --- a/src/monster/stalker/stalker.c +++ b/src/monster/stalker/stalker.c @@ -1303,11 +1303,6 @@ stalker_blocked(edict_t *self, float dist) if (!onCeiling) { - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - if (visible(self, self->enemy)) { stalker_do_pounce(self, self->enemy->s.origin); @@ -1327,11 +1322,7 @@ stalker_blocked(edict_t *self, float dist) } else { - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - else if (stalker_ok_to_transition(self)) + if (stalker_ok_to_transition(self)) { self->gravityVector[2] = -1; self->s.angles[2] += 180.0; diff --git a/src/monster/supertank/supertank.c b/src/monster/supertank/supertank.c index 5d44c28..a7782e7 100644 --- a/src/monster/supertank/supertank.c +++ b/src/monster/supertank/supertank.c @@ -834,11 +834,6 @@ supertank_blocked(edict_t *self, float dist) return false; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - if (blocked_checkplat(self, dist)) { return true; diff --git a/src/monster/tank/tank.c b/src/monster/tank/tank.c index d90836a..5215880 100644 --- a/src/monster/tank/tank.c +++ b/src/monster/tank/tank.c @@ -1178,14 +1178,15 @@ tank_die(edict_t *self, edict_t *inflictor /* unused */, edict_t *attacker /* un self->monsterinfo.currentmove = &tank_move_death; } -qboolean tank_blocked(edict_t *self, float dist) +qboolean +tank_blocked(edict_t *self, float dist) { - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value) )) + if (!self) { - return true; + return false; } - if(blocked_checkplat(self, dist)) + if (blocked_checkplat(self, dist)) { return true; } diff --git a/src/monster/widow/widow.c b/src/monster/widow/widow.c index d9b3999..621ddae 100644 --- a/src/monster/widow/widow.c +++ b/src/monster/widow/widow.c @@ -1765,11 +1765,6 @@ widow_blocked(edict_t *self, float dist) return true; } - if (blocked_checkshot(self, 0.25 + (0.05 * skill->value))) - { - return true; - } - return false; } diff --git a/src/savegame/tables/gamefunc_decs.h b/src/savegame/tables/gamefunc_decs.h index ae0511c..787bc1f 100644 --- a/src/savegame/tables/gamefunc_decs.h +++ b/src/savegame/tables/gamefunc_decs.h @@ -1105,7 +1105,6 @@ extern edict_t * hintpath_findstart ( edict_t * ent ) ; extern qboolean blocked_checknewenemy ( edict_t * self ) ; extern qboolean blocked_checkjump ( edict_t * self , float dist , float maxDown , float maxUp ) ; extern qboolean blocked_checkplat ( edict_t * self , float dist ) ; -extern qboolean blocked_checkshot ( edict_t * self , float shotChance ) ; extern void monster_done_dodge ( edict_t * self ) ; extern void stationarymonster_start ( edict_t * self ) ; extern void stationarymonster_start_go ( edict_t * self ) ; diff --git a/src/savegame/tables/gamefunc_list.h b/src/savegame/tables/gamefunc_list.h index eeff0dd..da457b5 100644 --- a/src/savegame/tables/gamefunc_list.h +++ b/src/savegame/tables/gamefunc_list.h @@ -1105,7 +1105,6 @@ {"blocked_checknewenemy", (byte *)blocked_checknewenemy}, {"blocked_checkjump", (byte *)blocked_checkjump}, {"blocked_checkplat", (byte *)blocked_checkplat}, -{"blocked_checkshot", (byte *)blocked_checkshot}, {"monster_done_dodge", (byte *)monster_done_dodge}, {"stationarymonster_start", (byte *)stationarymonster_start}, {"stationarymonster_start_go", (byte *)stationarymonster_start_go},