diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 34083d457c..1d85b790dd 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,6 +1,8 @@ October 26, 2009 - Changes to both A_MonsterRail() and A_CustomRailgun(): Save actor's pitch, - use a larger aiming range, and ignore non-targets in P_AimLineAttack(). + use a larger aiming range, ignore non-targets in P_AimLineAttack(), and + aim at the target anyway even if P_AimLineAttack() decides it has no + chance of hitting. - Added another parameter to P_AimLineAttack(): A target to be aimed at. If this is non-NULL, then all actors between the shooter and the target will be ignored. diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index 08bd6af838..980025d96d 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -2704,6 +2704,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_MonsterRail) return; fixed_t saved_pitch = self->pitch; + AActor *linetarget; // [RH] Andy Baker's stealth monsters if (self->flags & MF_STEALTH) @@ -2718,7 +2719,15 @@ DEFINE_ACTION_FUNCTION(AActor, A_MonsterRail) self->target->x, self->target->y); - self->pitch = P_AimLineAttack (self, self->angle, MISSILERANGE, NULL, ANGLE_1*60, false, false, false, self->target); + self->pitch = P_AimLineAttack (self, self->angle, MISSILERANGE, &linetarget, ANGLE_1*60, false, false, false, self->target); + if (linetarget == NULL) + { + // We probably won't hit the target, but aim at it anyway so we don't look stupid. + FVector2 xydiff(self->target->x - self->x, self->target->y - self->y); + double zdiff = (self->target->z + (self->target->height>>1)) - + (self->z + (self->height>>1) - self->floorclip); + self->pitch = int(atan2(zdiff, xydiff.Length()) * ANGLE_180 / -M_PI); + } // Let the aim trail behind the player self->angle = R_PointToAngle2 (self->x, diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 34ef234860..d1c9f40836 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -1179,6 +1179,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomRailgun) ACTION_PARAM_FLOAT(MaxDiff, 6); ACTION_PARAM_CLASS(PuffType, 7); + AActor *linetarget; + fixed_t saved_x = self->x; fixed_t saved_y = self->y; angle_t saved_angle = self->angle; @@ -1204,8 +1206,15 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomRailgun) self->target->x, self->target->y); } - self->pitch = P_AimLineAttack (self, self->angle, MISSILERANGE, NULL, ANGLE_1*60, false, false, false, self->target); - + self->pitch = P_AimLineAttack (self, self->angle, MISSILERANGE, &linetarget, ANGLE_1*60, false, false, false, aim ? self->target : NULL); + if (linetarget == NULL && aim) + { + // We probably won't hit the target, but aim at it anyway so we don't look stupid. + FVector2 xydiff(self->target->x - self->x, self->target->y - self->y); + double zdiff = (self->target->z + (self->target->height>>1)) - + (self->z + (self->height>>1) - self->floorclip); + self->pitch = int(atan2(zdiff, xydiff.Length()) * ANGLE_180 / -M_PI); + } // Let the aim trail behind the player if (aim) {