2006-02-24 04:48:15 +00:00
|
|
|
#include "actor.h"
|
|
|
|
#include "info.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "s_sound.h"
|
2008-08-10 20:48:55 +00:00
|
|
|
#include "thingdef/thingdef.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
static FRandom pr_batspawn ("BatSpawn");
|
|
|
|
static FRandom pr_batmove ("BatMove");
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
// Bat Spawner Variables
|
|
|
|
// special1 frequency counter
|
|
|
|
// special2
|
|
|
|
// args[0] frequency of spawn (1=fastest, 10=slowest)
|
|
|
|
// args[1] spread angle (0..255)
|
|
|
|
// args[2]
|
|
|
|
// args[3] duration of bats (in octics)
|
|
|
|
// args[4] turn amount per move (in degrees)
|
|
|
|
//
|
|
|
|
// Bat Variables
|
|
|
|
// special2 lifetime counter
|
|
|
|
// args[4] turn amount per move (in degrees)
|
|
|
|
//===========================================================================
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_BatSpawnInit)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->special1 = 0; // Frequency count
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_BatSpawn)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AActor *mo;
|
|
|
|
int delta;
|
|
|
|
angle_t angle;
|
|
|
|
|
|
|
|
// Countdown until next spawn
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self->special1-- > 0) return;
|
|
|
|
self->special1 = self->args[0]; // Reset frequency count
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
delta = self->args[1];
|
2006-02-24 04:48:15 +00:00
|
|
|
if (delta==0) delta=1;
|
2008-08-10 20:48:55 +00:00
|
|
|
angle = self->angle + (((pr_batspawn()%delta)-(delta>>1))<<24);
|
|
|
|
mo = P_SpawnMissileAngle (self, PClass::FindClass ("Bat"), angle, 0);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (mo)
|
|
|
|
{
|
|
|
|
mo->args[0] = pr_batspawn()&63; // floatbob index
|
2008-08-10 20:48:55 +00:00
|
|
|
mo->args[4] = self->args[4]; // turn degrees
|
|
|
|
mo->special2 = self->args[3]<<3; // Set lifetime
|
|
|
|
mo->target = self;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_BatMove)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
angle_t newangle;
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self->special2 < 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->SetState (self->FindState(NAME_Death));
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-08-10 20:48:55 +00:00
|
|
|
self->special2 -= 2; // Called every 2 tics
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (pr_batmove()<128)
|
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
newangle = self->angle + ANGLE_1*self->args[4];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
newangle = self->angle - ANGLE_1*self->args[4];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust momentum vector to new direction
|
|
|
|
newangle >>= ANGLETOFINESHIFT;
|
2008-08-10 20:48:55 +00:00
|
|
|
self->momx = FixedMul (self->Speed, finecosine[newangle]);
|
|
|
|
self->momy = FixedMul (self->Speed, finesine[newangle]);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (pr_batmove()<15)
|
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
S_Sound (self, CHAN_VOICE, "BatScream", 1, ATTN_IDLE);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Z movement
|
2008-08-10 20:48:55 +00:00
|
|
|
self->z = self->target->z + 2*FloatBobOffsets[self->args[0]];
|
|
|
|
self->args[0] = (self->args[0]+3)&63;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|