mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 14:51:40 +00:00
Moved all the handling of MF_SHADOW for attacks into its' own file.
Also changed all the individual flag checks into one generic inline function.
This commit is contained in:
parent
a7f76fe8b9
commit
5b98eade91
4 changed files with 115 additions and 39 deletions
|
@ -70,20 +70,21 @@
|
||||||
#include "actorinlines.h"
|
#include "actorinlines.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
#include "shadowinlines.h"
|
||||||
|
|
||||||
static FRandom pr_camissile ("CustomActorfire");
|
static FRandom pr_camissile ("CustomActorfire");
|
||||||
static FRandom pr_cabullet ("CustomBullet");
|
static FRandom pr_cabullet ("CustomBullet");
|
||||||
static FRandom pr_cwjump ("CustomWpJump");
|
static FRandom pr_cwjump ("CustomWpJump");
|
||||||
static FRandom pr_cwpunch ("CustomWpPunch");
|
static FRandom pr_cwpunch ("CustomWpPunch");
|
||||||
static FRandom pr_grenade ("ThrowGrenade");
|
static FRandom pr_grenade ("ThrowGrenade");
|
||||||
static FRandom pr_crailgun ("CustomRailgun");
|
FRandom pr_crailgun ("CustomRailgun");
|
||||||
static FRandom pr_spawndebris ("SpawnDebris");
|
static FRandom pr_spawndebris ("SpawnDebris");
|
||||||
static FRandom pr_spawnitemex ("SpawnItemEx");
|
static FRandom pr_spawnitemex ("SpawnItemEx");
|
||||||
static FRandom pr_burst ("Burst");
|
static FRandom pr_burst ("Burst");
|
||||||
static FRandom pr_monsterrefire ("MonsterRefire");
|
static FRandom pr_monsterrefire ("MonsterRefire");
|
||||||
static FRandom pr_teleport("A_Teleport");
|
static FRandom pr_teleport("A_Teleport");
|
||||||
static FRandom pr_bfgselfdamage("BFGSelfDamage");
|
static FRandom pr_bfgselfdamage("BFGSelfDamage");
|
||||||
FRandom pr_cajump("CustomJump");
|
FRandom pr_cajump("CustomJump");
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -1226,11 +1227,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_CustomRailgun)
|
||||||
self->Angles.Yaw = self->AngleTo(self->target,- self->target->Vel.X * veleffect, -self->target->Vel.Y * veleffect);
|
self->Angles.Yaw = self->AngleTo(self->target,- self->target->Vel.X * veleffect, -self->target->Vel.Y * veleffect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->target->flags & MF_SHADOW)
|
A_CustomRailgun_ShadowHandling(self);
|
||||||
{
|
|
||||||
DAngle rnd = DAngle::fromDeg(pr_crailgun.Random2() * (45. / 256.));
|
|
||||||
self->Angles.Yaw += rnd;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(flags & CRF_EXPLICITANGLE))
|
if (!(flags & CRF_EXPLICITANGLE))
|
||||||
|
@ -3529,7 +3526,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_WolfAttack)
|
||||||
hitchance -= idist * (dodge ? 16 : 8);
|
hitchance -= idist * (dodge ? 16 : 8);
|
||||||
|
|
||||||
// While we're here, we may as well do something for this:
|
// While we're here, we may as well do something for this:
|
||||||
if (self->target->flags & MF_SHADOW)
|
if (A_WolfAttack_ShadowHandling(self))
|
||||||
{
|
{
|
||||||
hitchance >>= 2;
|
hitchance >>= 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
#include "actorinlines.h"
|
#include "actorinlines.h"
|
||||||
#include "a_ceiling.h"
|
#include "a_ceiling.h"
|
||||||
|
#include "shadowinlines.h"
|
||||||
|
|
||||||
#include "gi.h"
|
#include "gi.h"
|
||||||
|
|
||||||
|
@ -3021,12 +3022,7 @@ void A_Face(AActor *self, AActor *other, DAngle max_turn, DAngle max_pitch, DAng
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
A_Face_ShadowHandling(self,other,max_turn,other_angle);
|
||||||
// This will never work well if the turn angle is limited.
|
|
||||||
if (max_turn == nullAngle && (self->Angles.Yaw == other_angle) && other->flags & MF_SHADOW && !(self->flags6 & MF6_SEEINVISIBLE) )
|
|
||||||
{
|
|
||||||
self->Angles.Yaw += DAngle::fromDeg(pr_facetarget.Random2() * (45 / 256.));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void A_FaceTarget(AActor *self)
|
void A_FaceTarget(AActor *self)
|
||||||
|
@ -3073,10 +3069,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_MonsterRail)
|
||||||
// Let the aim trail behind the player
|
// Let the aim trail behind the player
|
||||||
self->Angles.Yaw = self->AngleTo(self->target, -self->target->Vel.X * 3, -self->target->Vel.Y * 3);
|
self->Angles.Yaw = self->AngleTo(self->target, -self->target->Vel.X * 3, -self->target->Vel.Y * 3);
|
||||||
|
|
||||||
if (self->target->flags & MF_SHADOW && !(self->flags6 & MF6_SEEINVISIBLE))
|
A_MonsterRail_ShadowHandling(self);
|
||||||
{
|
|
||||||
self->Angles.Yaw += DAngle::fromDeg(pr_railface.Random2() * 45./256);
|
|
||||||
}
|
|
||||||
|
|
||||||
FRailParams p;
|
FRailParams p;
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@
|
||||||
#include "actorinlines.h"
|
#include "actorinlines.h"
|
||||||
#include "a_dynlight.h"
|
#include "a_dynlight.h"
|
||||||
#include "fragglescript/t_fs.h"
|
#include "fragglescript/t_fs.h"
|
||||||
|
#include "shadowinlines.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -120,7 +121,6 @@ EXTERN_CVAR (Int, cl_rockettrails)
|
||||||
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
||||||
|
|
||||||
static FRandom pr_explodemissile ("ExplodeMissile");
|
static FRandom pr_explodemissile ("ExplodeMissile");
|
||||||
FRandom pr_bounce ("Bounce");
|
|
||||||
static FRandom pr_reflect ("Reflect");
|
static FRandom pr_reflect ("Reflect");
|
||||||
static FRandom pr_nightmarerespawn ("NightmareRespawn");
|
static FRandom pr_nightmarerespawn ("NightmareRespawn");
|
||||||
static FRandom pr_botspawnmobj ("BotSpawnActor");
|
static FRandom pr_botspawnmobj ("BotSpawnActor");
|
||||||
|
@ -133,7 +133,6 @@ static FRandom pr_splat ("FAxeSplatter");
|
||||||
static FRandom pr_ripperblood ("RipperBlood");
|
static FRandom pr_ripperblood ("RipperBlood");
|
||||||
static FRandom pr_chunk ("Chunk");
|
static FRandom pr_chunk ("Chunk");
|
||||||
static FRandom pr_checkmissilespawn ("CheckMissileSpawn");
|
static FRandom pr_checkmissilespawn ("CheckMissileSpawn");
|
||||||
static FRandom pr_spawnmissile ("SpawnMissile");
|
|
||||||
static FRandom pr_missiledamage ("MissileDamage");
|
static FRandom pr_missiledamage ("MissileDamage");
|
||||||
static FRandom pr_multiclasschoice ("MultiClassChoice");
|
static FRandom pr_multiclasschoice ("MultiClassChoice");
|
||||||
static FRandom pr_rockettrail("RocketTrail");
|
static FRandom pr_rockettrail("RocketTrail");
|
||||||
|
@ -142,6 +141,8 @@ static FRandom pr_uniquetid("UniqueTID");
|
||||||
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
||||||
|
|
||||||
FRandom pr_spawnmobj ("SpawnActor");
|
FRandom pr_spawnmobj ("SpawnActor");
|
||||||
|
FRandom pr_bounce("Bounce");
|
||||||
|
FRandom pr_spawnmissile("SpawnMissile");
|
||||||
|
|
||||||
CUSTOM_CVAR (Float, sv_gravity, 800.f, CVAR_SERVERINFO|CVAR_NOSAVE|CVAR_NOINITCALL)
|
CUSTOM_CVAR (Float, sv_gravity, 800.f, CVAR_SERVERINFO|CVAR_NOSAVE|CVAR_NOINITCALL)
|
||||||
{
|
{
|
||||||
|
@ -6704,21 +6705,8 @@ AActor *P_SpawnMissileXYZ (DVector3 pos, AActor *source, AActor *dest, PClassAct
|
||||||
}
|
}
|
||||||
th->Vel = velocity.Resized(speed);
|
th->Vel = velocity.Resized(speed);
|
||||||
|
|
||||||
// invisible target: rotate velocity vector in 2D
|
P_SpawnMissileXYZ_ShadowHandling(source,dest,th);
|
||||||
// [RC] Now monsters can aim at invisible player as if they were fully visible.
|
|
||||||
if (dest->flags & MF_SHADOW && !(source->flags6 & MF6_SEEINVISIBLE))
|
|
||||||
{
|
|
||||||
DAngle an = DAngle::fromDeg(pr_spawnmissile.Random2() * (22.5 / 256));
|
|
||||||
double c = an.Cos();
|
|
||||||
double s = an.Sin();
|
|
||||||
|
|
||||||
double newx = th->Vel.X * c - th->Vel.Y * s;
|
|
||||||
double newy = th->Vel.X * s + th->Vel.Y * c;
|
|
||||||
|
|
||||||
th->Vel.X = newx;
|
|
||||||
th->Vel.Y = newy;
|
|
||||||
}
|
|
||||||
|
|
||||||
th->AngleFromVel();
|
th->AngleFromVel();
|
||||||
|
|
||||||
if (th->flags4 & MF4_SPECTRAL)
|
if (th->flags4 & MF4_SPECTRAL)
|
||||||
|
@ -6839,10 +6827,8 @@ AActor *P_SpawnMissileZAimed (AActor *source, double z, AActor *dest, PClassActo
|
||||||
|
|
||||||
an = source->Angles.Yaw;
|
an = source->Angles.Yaw;
|
||||||
|
|
||||||
if (dest->flags & MF_SHADOW)
|
an += P_SpawnMissileZAimed_ShadowHandling(source,dest);
|
||||||
{
|
|
||||||
an += DAngle::fromDeg(pr_spawnmissile.Random2() * (16. / 360.));
|
|
||||||
}
|
|
||||||
dist = source->Distance2D (dest);
|
dist = source->Distance2D (dest);
|
||||||
speed = GetDefaultSpeed (type);
|
speed = GetDefaultSpeed (type);
|
||||||
dist /= speed;
|
dist /= speed;
|
||||||
|
|
100
src/playsim/shadowinlines.h
Normal file
100
src/playsim/shadowinlines.h
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "actor.h"
|
||||||
|
#include "r_defs.h"
|
||||||
|
#include "m_random.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// DESCRIPTION:
|
||||||
|
// Handling of MF_SHADOW related code for attack and aiming functions.
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// RNG VARIABLES ------------------------------------------------
|
||||||
|
extern FRandom pr_spawnmissile;
|
||||||
|
extern FRandom pr_facetarget;
|
||||||
|
extern FRandom pr_railface;
|
||||||
|
extern FRandom pr_crailgun;
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// Generic checks
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
inline bool CheckShadowFlags(AActor* self, AActor* other)
|
||||||
|
{
|
||||||
|
return (other->flags & MF_SHADOW && !(self->flags6 & MF6_SEEINVISIBLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// Function-specific inlines.
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
inline void P_SpawnMissileXYZ_ShadowHandling(AActor* source, AActor* target, AActor* missile)
|
||||||
|
{
|
||||||
|
// invisible target: rotate velocity vector in 2D
|
||||||
|
// [RC] Now monsters can aim at invisible player as if they were fully visible.
|
||||||
|
if (CheckShadowFlags(source,target))
|
||||||
|
{
|
||||||
|
DAngle an = DAngle::fromDeg(pr_spawnmissile.Random2() * (22.5 / 256));
|
||||||
|
double c = an.Cos();
|
||||||
|
double s = an.Sin();
|
||||||
|
|
||||||
|
double newx = missile->Vel.X * c - missile->Vel.Y * s;
|
||||||
|
double newy = missile->Vel.X * s + missile->Vel.Y * c;
|
||||||
|
|
||||||
|
missile->Vel.X = newx;
|
||||||
|
missile->Vel.Y = newy;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//P_SpawnMissileZAimed uses a local variable for the angle it passes on.
|
||||||
|
inline DAngle P_SpawnMissileZAimed_ShadowHandling(AActor* source, AActor* target)
|
||||||
|
{
|
||||||
|
if (CheckShadowFlags(source,target))
|
||||||
|
{
|
||||||
|
return DAngle::fromDeg(pr_spawnmissile.Random2() * (16. / 360.));
|
||||||
|
}
|
||||||
|
return nullAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void A_Face_ShadowHandling(AActor* self, AActor* other, DAngle max_turn, DAngle other_angle)
|
||||||
|
{
|
||||||
|
// This will never work well if the turn angle is limited.
|
||||||
|
if (max_turn == nullAngle && (self->Angles.Yaw == other_angle) && CheckShadowFlags(self, other))
|
||||||
|
{
|
||||||
|
self->Angles.Yaw += DAngle::fromDeg(pr_facetarget.Random2() * (45 / 256.));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void A_MonsterRail_ShadowHandling(AActor* self)
|
||||||
|
{
|
||||||
|
if (CheckShadowFlags(self, self->target))
|
||||||
|
{
|
||||||
|
self->Angles.Yaw += DAngle::fromDeg(pr_railface.Random2() * 45. / 256);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void A_CustomRailgun_ShadowHandling(AActor* self)
|
||||||
|
{
|
||||||
|
if (CheckShadowFlags(self, self->target))
|
||||||
|
{
|
||||||
|
DAngle rnd = DAngle::fromDeg(pr_crailgun.Random2() * (45. / 256.));
|
||||||
|
self->Angles.Yaw += rnd;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//A_WolfAttack directly harms the target instead of firing a hitscan or projectile. So it handles shadows by lowering the chance of harming the target.
|
||||||
|
inline bool A_WolfAttack_ShadowHandling(AActor* self)
|
||||||
|
{
|
||||||
|
return (CheckShadowFlags(self, self->target));
|
||||||
|
}
|
Loading…
Reference in a new issue