gzdoom/src/g_hexen/a_hexenspecialdecs.cpp
Christoph Oelckers 1983b5c586 - Changed action function definition so that they have to be defined with a
DEFINE_ACTION_FUNCTION macro. This should make it easier to improve the
  whole system.


SVN r1148 (trunk)
2008-08-10 20:48:55 +00:00

350 lines
9.1 KiB
C++

/*
** Decorations that do special things
*/
#include "actor.h"
#include "info.h"
#include "a_action.h"
#include "p_enemy.h"
#include "m_random.h"
#include "s_sound.h"
#include "p_local.h"
#include "p_lnspec.h"
#include "a_hexenglobal.h"
#include "thingdef/thingdef.h"
static FRandom pr_pottery ("PotteryExplode");
static FRandom pr_bit ("PotteryChooseBit");
static FRandom pr_drip ("CorpseBloodDrip");
static FRandom pr_foo ("CorpseExplode");
static FRandom pr_leaf ("LeafSpawn");
static FRandom pr_leafthrust ("LeafThrust");
static FRandom pr_leafcheck ("LeafCheck");
static FRandom pr_shroom ("PoisonShroom");
static FRandom pr_soaexplode ("SoAExplode");
// Pottery1 ------------------------------------------------------------------
void A_PotteryExplode (AActor *);
void A_PotteryChooseBit (AActor *);
void A_PotteryCheck (AActor *);
class APottery1 : public AActor
{
DECLARE_CLASS (APottery1, AActor)
public:
void HitFloor ();
};
IMPLEMENT_CLASS (APottery1)
void APottery1::HitFloor ()
{
Super::HitFloor ();
P_DamageMobj (this, NULL, NULL, 25, NAME_None);
}
//============================================================================
//
// A_PotteryExplode
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_PotteryExplode)
{
AActor *mo = NULL;
int i;
for(i = (pr_pottery()&3)+3; i; i--)
{
mo = Spawn ("PotteryBit", self->x, self->y, self->z, ALLOW_REPLACE);
mo->SetState (mo->SpawnState + (pr_pottery()%5));
if (mo)
{
mo->momz = ((pr_pottery()&7)+5)*(3*FRACUNIT/4);
mo->momx = (pr_pottery.Random2())<<(FRACBITS-6);
mo->momy = (pr_pottery.Random2())<<(FRACBITS-6);
}
}
S_Sound (mo, CHAN_BODY, "PotteryExplode", 1, ATTN_NORM);
if (self->args[0]>=0 && self->args[0]<=255 && SpawnableThings[self->args[0]])
{ // Spawn an item
if (!((level.flags & LEVEL_NOMONSTERS) || (dmflags & DF_NO_MONSTERS))
|| !(GetDefaultByType (SpawnableThings[self->args[0]])->flags3 & MF3_ISMONSTER))
{ // Only spawn monsters if not -nomonsters
Spawn (SpawnableThings[self->args[0]],
self->x, self->y, self->z, ALLOW_REPLACE);
}
}
}
//============================================================================
//
// A_PotteryChooseBit
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_PotteryChooseBit)
{
self->SetState (self->FindState(NAME_Death) + 1 + 2*(pr_bit()%5));
self->tics = 256+(pr_bit()<<1);
}
//============================================================================
//
// A_PotteryCheck
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_PotteryCheck)
{
int i;
for(i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i])
{
AActor *pmo = players[i].mo;
if (P_CheckSight (self, pmo) && (abs (R_PointToAngle2 (pmo->x,
pmo->y, self->x, self->y) - pmo->angle) <= ANGLE_45))
{ // Previous state (pottery bit waiting state)
self->SetState (self->state - 1);
return;
}
}
}
}
// Lynched corpse (no heart) ------------------------------------------------
class AZCorpseLynchedNoHeart : public AActor
{
DECLARE_CLASS (AZCorpseLynchedNoHeart, AActor)
public:
void PostBeginPlay ();
};
IMPLEMENT_CLASS (AZCorpseLynchedNoHeart)
void AZCorpseLynchedNoHeart::PostBeginPlay ()
{
Super::PostBeginPlay ();
Spawn ("BloodPool", x, y, ONFLOORZ, ALLOW_REPLACE);
}
//============================================================================
//
// A_CorpseBloodDrip
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_CorpseBloodDrip)
{
if (pr_drip() <= 128)
{
Spawn ("CorpseBloodDrip", self->x, self->y, self->z + self->height/2, ALLOW_REPLACE);
}
}
//============================================================================
//
// A_CorpseExplode
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_CorpseExplode)
{
AActor *mo;
int i;
for (i = (pr_foo()&3)+3; i; i--)
{
mo = Spawn ("CorpseBit", self->x, self->y, self->z, ALLOW_REPLACE);
mo->SetState (mo->SpawnState + (pr_foo()%3));
if (mo)
{
mo->momz = ((pr_foo()&7)+5)*(3*FRACUNIT/4);
mo->momx = pr_foo.Random2()<<(FRACBITS-6);
mo->momy = pr_foo.Random2()<<(FRACBITS-6);
}
}
// Spawn a skull
mo = Spawn ("CorpseBit", self->x, self->y, self->z, ALLOW_REPLACE);
mo->SetState (mo->SpawnState + 3);
if (mo)
{
mo->momz = ((pr_foo()&7)+5)*(3*FRACUNIT/4);
mo->momx = pr_foo.Random2()<<(FRACBITS-6);
mo->momy = pr_foo.Random2()<<(FRACBITS-6);
}
S_Sound (self, CHAN_BODY, self->DeathSound, 1, ATTN_IDLE);
self->Destroy ();
}
//============================================================================
//
// A_LeafSpawn
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_LeafSpawn)
{
AActor *mo;
int i;
for (i = (pr_leaf()&3)+1; i; i--)
{
mo = Spawn (pr_leaf()&1 ? PClass::FindClass ("Leaf1") : PClass::FindClass ("Leaf2"),
self->x + (pr_leaf.Random2()<<14),
self->y + (pr_leaf.Random2()<<14),
self->z + (pr_leaf()<<14), ALLOW_REPLACE);
if (mo)
{
P_ThrustMobj (mo, self->angle, (pr_leaf()<<9)+3*FRACUNIT);
mo->target = self;
mo->special1 = 0;
}
}
}
//============================================================================
//
// A_LeafThrust
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_LeafThrust)
{
if (pr_leafthrust() <= 96)
{
self->momz += (pr_leafthrust()<<9)+FRACUNIT;
}
}
//============================================================================
//
// A_LeafCheck
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_LeafCheck)
{
self->special1++;
if (self->special1 >= 20)
{
self->SetState (NULL);
return;
}
angle_t ang = self->target ? self->target->angle : self->angle;
if (pr_leafcheck() > 64)
{
if (!self->momx && !self->momy)
{
P_ThrustMobj (self, ang, (pr_leafcheck()<<9)+FRACUNIT);
}
return;
}
self->SetState (self->SpawnState + 7);
self->momz = (pr_leafcheck()<<9)+FRACUNIT;
P_ThrustMobj (self, ang, (pr_leafcheck()<<9)+2*FRACUNIT);
self->flags |= MF_MISSILE;
}
//===========================================================================
//
// A_PoisonShroom
//
//===========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_PoisonShroom)
{
self->tics = 128+(pr_shroom()<<1);
}
//===========================================================================
//
// A_SoAExplode - Suit of Armor Explode
//
//===========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_SoAExplode)
{
AActor *mo;
int i;
for (i = 0; i < 10; i++)
{
mo = Spawn ("ZArmorChunk", self->x+((pr_soaexplode()-128)<<12),
self->y+((pr_soaexplode()-128)<<12),
self->z+(pr_soaexplode()*self->height/256), ALLOW_REPLACE);
mo->SetState (mo->SpawnState + i);
if (mo)
{
mo->momz = ((pr_soaexplode()&7)+5)*FRACUNIT;
mo->momx = pr_soaexplode.Random2()<<(FRACBITS-6);
mo->momy = pr_soaexplode.Random2()<<(FRACBITS-6);
}
}
if (self->args[0]>=0 && self->args[0]<=255 && SpawnableThings[self->args[0]])
{ // Spawn an item
if (!((level.flags & LEVEL_NOMONSTERS) || (dmflags & DF_NO_MONSTERS))
|| !(GetDefaultByType (SpawnableThings[self->args[0]])->flags3 & MF3_ISMONSTER))
{ // Only spawn monsters if not -nomonsters
Spawn (SpawnableThings[self->args[0]],
self->x, self->y, self->z, ALLOW_REPLACE);
}
}
S_Sound (self, CHAN_BODY, self->DeathSound, 1, ATTN_NORM);
self->Destroy ();
}
// Bell ---------------------------------------------------------------------
class AZBell : public AActor
{
DECLARE_CLASS (AZBell, AActor)
public:
void Activate (AActor *activator);
};
IMPLEMENT_CLASS (AZBell)
void AZBell::Activate (AActor *activator)
{
if (health > 0)
{
P_DamageMobj (this, activator, activator, 10, NAME_Melee); // 'ring' the bell
}
}
//===========================================================================
//
// A_BellReset1
//
//===========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_BellReset1)
{
self->flags |= MF_NOGRAVITY;
self->height <<= 2;
if (self->special)
{ // Initiate death action
LineSpecials[self->special] (NULL, NULL, false, self->args[0],
self->args[1], self->args[2], self->args[3], self->args[4]);
self->special = 0;
}
}
//===========================================================================
//
// A_BellReset2
//
//===========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_BellReset2)
{
self->flags |= MF_SHOOTABLE;
self->flags &= ~MF_CORPSE;
self->health = 5;
}