2008-09-15 14:11:05 +00:00
|
|
|
/*
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "actor.h"
|
|
|
|
#include "info.h"
|
|
|
|
#include "p_enemy.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "a_action.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "s_sound.h"
|
2008-08-10 20:48:55 +00:00
|
|
|
#include "thingdef/thingdef.h"
|
2008-09-15 14:11:05 +00:00
|
|
|
*/
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
static FRandom pr_dragonseek ("DragonSeek");
|
|
|
|
static FRandom pr_dragonflight ("DragonFlight");
|
|
|
|
static FRandom pr_dragonflap ("DragonFlap");
|
|
|
|
static FRandom pr_dragonfx2 ("DragonFX2");
|
|
|
|
|
2008-08-10 22:48:37 +00:00
|
|
|
DECLARE_ACTION(A_DragonFlight)
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// DragonSeek
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
static void DragonSeek (AActor *actor, angle_t thresh, angle_t turnMax)
|
|
|
|
{
|
|
|
|
int dir;
|
|
|
|
int dist;
|
|
|
|
angle_t delta;
|
|
|
|
angle_t angle;
|
|
|
|
AActor *target;
|
|
|
|
int i;
|
|
|
|
angle_t bestAngle;
|
|
|
|
angle_t angleToSpot, angleToTarget;
|
|
|
|
AActor *mo;
|
|
|
|
|
|
|
|
target = actor->tracer;
|
|
|
|
if(target == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dir = P_FaceMobj (actor, target, &delta);
|
|
|
|
if (delta > thresh)
|
|
|
|
{
|
|
|
|
delta >>= 1;
|
|
|
|
if (delta > turnMax)
|
|
|
|
{
|
|
|
|
delta = turnMax;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dir)
|
|
|
|
{ // Turn clockwise
|
|
|
|
actor->angle += delta;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Turn counter clockwise
|
|
|
|
actor->angle -= delta;
|
|
|
|
}
|
|
|
|
angle = actor->angle>>ANGLETOFINESHIFT;
|
2009-06-30 20:57:51 +00:00
|
|
|
actor->velx = FixedMul (actor->Speed, finecosine[angle]);
|
|
|
|
actor->vely = FixedMul (actor->Speed, finesine[angle]);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (actor->z+actor->height < target->z ||
|
|
|
|
target->z+target->height < actor->z)
|
|
|
|
{
|
|
|
|
dist = P_AproxDistance(target->x-actor->x, target->y-actor->y);
|
|
|
|
dist = dist/actor->Speed;
|
|
|
|
if (dist < 1)
|
|
|
|
{
|
|
|
|
dist = 1;
|
|
|
|
}
|
2009-06-30 20:57:51 +00:00
|
|
|
actor->velz = (target->z - actor->z)/dist;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dist = P_AproxDistance (target->x-actor->x, target->y-actor->y);
|
|
|
|
dist = dist/actor->Speed;
|
|
|
|
}
|
|
|
|
if (target->flags&MF_SHOOTABLE && pr_dragonseek() < 64)
|
|
|
|
{ // attack the destination mobj if it's attackable
|
|
|
|
AActor *oldTarget;
|
|
|
|
|
|
|
|
if (abs(actor->angle-R_PointToAngle2(actor->x, actor->y,
|
|
|
|
target->x, target->y)) < ANGLE_45/2)
|
|
|
|
{
|
|
|
|
oldTarget = actor->target;
|
|
|
|
actor->target = target;
|
|
|
|
if (actor->CheckMeleeRange ())
|
|
|
|
{
|
|
|
|
int damage = pr_dragonseek.HitDice (10);
|
2013-01-02 04:39:59 +00:00
|
|
|
int newdam = P_DamageMobj (actor->target, actor, actor, damage, NAME_Melee);
|
|
|
|
P_TraceBleed (newdam > 0 ? newdam : damage, actor->target, actor);
|
2008-06-15 02:25:09 +00:00
|
|
|
S_Sound (actor, CHAN_WEAPON, actor->AttackSound, 1, ATTN_NORM);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else if (pr_dragonseek() < 128 && P_CheckMissileRange(actor))
|
|
|
|
{
|
2008-08-08 15:18:23 +00:00
|
|
|
P_SpawnMissile(actor, target, PClass::FindClass ("DragonFireball"));
|
2008-06-15 02:25:09 +00:00
|
|
|
S_Sound (actor, CHAN_WEAPON, actor->AttackSound, 1, ATTN_NORM);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
actor->target = oldTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dist < 4)
|
|
|
|
{ // Hit the target thing
|
|
|
|
if (actor->target && pr_dragonseek() < 200)
|
|
|
|
{
|
|
|
|
AActor *bestActor = NULL;
|
|
|
|
bestAngle = ANGLE_MAX;
|
|
|
|
angleToTarget = R_PointToAngle2(actor->x, actor->y,
|
|
|
|
actor->target->x, actor->target->y);
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
if (!target->args[i])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
FActorIterator iterator (target->args[i]);
|
|
|
|
mo = iterator.Next ();
|
|
|
|
if (mo == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
angleToSpot = R_PointToAngle2(actor->x, actor->y,
|
|
|
|
mo->x, mo->y);
|
|
|
|
if ((angle_t)abs(angleToSpot-angleToTarget) < bestAngle)
|
|
|
|
{
|
|
|
|
bestAngle = abs(angleToSpot-angleToTarget);
|
|
|
|
bestActor = mo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bestActor != NULL)
|
|
|
|
{
|
|
|
|
actor->tracer = bestActor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// [RH] Don't lock up if the dragon doesn't have any
|
|
|
|
// targets defined
|
|
|
|
for (i = 0; i < 5; ++i)
|
|
|
|
{
|
|
|
|
if (target->args[i] != 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i < 5)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
i = (pr_dragonseek()>>2)%5;
|
|
|
|
} while(!target->args[i]);
|
|
|
|
FActorIterator iterator (target->args[i]);
|
|
|
|
actor->tracer = iterator.Next ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// A_DragonInitFlight
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_DragonInitFlight)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
FActorIterator iterator (self->tid);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{ // find the first tid identical to the dragon's tid
|
2008-08-10 20:48:55 +00:00
|
|
|
self->tracer = iterator.Next ();
|
|
|
|
if (self->tracer == NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->SetState (self->SpawnState);
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-08-10 20:48:55 +00:00
|
|
|
} while (self->tracer == self);
|
|
|
|
self->RemoveFromHash ();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// A_DragonFlight
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_DragonFlight)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
angle_t angle;
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DragonSeek (self, 4*ANGLE_1, 8*ANGLE_1);
|
|
|
|
if (self->target)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
if(!(self->target->flags&MF_SHOOTABLE))
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // target died
|
2008-08-10 20:48:55 +00:00
|
|
|
self->target = NULL;
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-08-10 20:48:55 +00:00
|
|
|
angle = R_PointToAngle2(self->x, self->y, self->target->x,
|
|
|
|
self->target->y);
|
|
|
|
if (abs(self->angle-angle) < ANGLE_45/2 && self->CheckMeleeRange())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int damage = pr_dragonflight.HitDice (8);
|
2013-01-02 04:39:59 +00:00
|
|
|
int newdam = P_DamageMobj (self->target, self, self, damage, NAME_Melee);
|
|
|
|
P_TraceBleed (newdam > 0 ? newdam : damage, self->target, self);
|
2008-08-10 20:48:55 +00:00
|
|
|
S_Sound (self, CHAN_WEAPON, self->AttackSound, 1, ATTN_NORM);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-08-10 20:48:55 +00:00
|
|
|
else if (abs(self->angle-angle) <= ANGLE_1*20)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->SetState (self->MissileState);
|
|
|
|
S_Sound (self, CHAN_WEAPON, self->AttackSound, 1, ATTN_NORM);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-16 15:54:04 +00:00
|
|
|
P_LookForPlayers (self, true, NULL);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// A_DragonFlap
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_DragonFlap)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 22:48:37 +00:00
|
|
|
CALL_ACTION(A_DragonFlight, self);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (pr_dragonflap() < 240)
|
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
S_Sound (self, CHAN_BODY, "DragonWingflap", 1, ATTN_NORM);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->PlayActiveSound ();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// A_DragonAttack
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_DragonAttack)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
P_SpawnMissile (self, self->target, PClass::FindClass ("DragonFireball"));
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// A_DragonFX2
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_DragonFX2)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AActor *mo;
|
|
|
|
int i;
|
|
|
|
int delay;
|
|
|
|
|
|
|
|
delay = 16+(pr_dragonfx2()>>3);
|
|
|
|
for (i = 1+(pr_dragonfx2()&3); i; i--)
|
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
fixed_t x = self->x+((pr_dragonfx2()-128)<<14);
|
|
|
|
fixed_t y = self->y+((pr_dragonfx2()-128)<<14);
|
|
|
|
fixed_t z = self->z+((pr_dragonfx2()-128)<<12);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-08-08 15:18:23 +00:00
|
|
|
mo = Spawn ("DragonExplosion", x, y, z, ALLOW_REPLACE);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (mo)
|
|
|
|
{
|
|
|
|
mo->tics = delay+(pr_dragonfx2()&3)*i*2;
|
2008-08-10 20:48:55 +00:00
|
|
|
mo->target = self->target;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// A_DragonPain
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_DragonPain)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 22:48:37 +00:00
|
|
|
CALL_ACTION(A_Pain, self);
|
2008-08-10 20:48:55 +00:00
|
|
|
if (!self->tracer)
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // no destination spot yet
|
2008-08-10 20:48:55 +00:00
|
|
|
self->SetState (self->SeeState);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// A_DragonCheckCrash
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_DragonCheckCrash)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self->z <= self->floorz)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->SetState (self->FindState ("Crash"));
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|