2006-02-24 04:48:15 +00:00
|
|
|
#include "templates.h"
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "actor.h"
|
|
|
|
#include "m_bbox.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "s_sound.h"
|
2006-07-01 00:21:36 +00:00
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "statnums.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
static FRandom pr_quake ("Quake");
|
|
|
|
|
|
|
|
IMPLEMENT_POINTY_CLASS (DEarthquake)
|
|
|
|
DECLARE_POINTER (m_Spot)
|
|
|
|
END_POINTERS
|
|
|
|
|
2006-07-01 00:21:36 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DEarthquake :: DEarthquake private constructor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
DEarthquake::DEarthquake()
|
|
|
|
: DThinker(STAT_EARTHQUAKE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DEarthquake :: DEarthquake public constructor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
DEarthquake::DEarthquake (AActor *center, int intensity, int duration,
|
|
|
|
int damrad, int tremrad)
|
|
|
|
: DThinker(STAT_EARTHQUAKE)
|
|
|
|
{
|
|
|
|
m_QuakeSFX = S_FindSound ("world/quake");
|
|
|
|
m_Spot = center;
|
|
|
|
// Radii are specified in tile units (64 pixels)
|
|
|
|
m_DamageRadius = damrad << (FRACBITS+6);
|
|
|
|
m_TremorRadius = tremrad << (FRACBITS+6);
|
|
|
|
m_Intensity = intensity;
|
|
|
|
m_Countdown = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DEarthquake :: Serialize
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
void DEarthquake::Serialize (FArchive &arc)
|
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
|
|
|
arc << m_Spot << m_Intensity << m_Countdown
|
|
|
|
<< m_TremorRadius << m_DamageRadius;
|
|
|
|
m_QuakeSFX = S_FindSound ("world/quake");
|
|
|
|
}
|
|
|
|
|
2006-07-01 00:21:36 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DEarthquake :: Tick
|
|
|
|
//
|
|
|
|
// Deals damage to any players near the earthquake and makes sure it's
|
|
|
|
// making noise.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
void DEarthquake::Tick ()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (m_Spot == NULL)
|
|
|
|
{
|
|
|
|
Destroy ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-12-24 23:08:49 +00:00
|
|
|
if (!S_IsActorPlayingSomething (m_Spot, CHAN_BODY, m_QuakeSFX))
|
2006-02-24 04:48:15 +00:00
|
|
|
S_SoundID (m_Spot, CHAN_BODY, m_QuakeSFX, 1, ATTN_NORM);
|
|
|
|
|
2006-07-01 00:21:36 +00:00
|
|
|
if (m_DamageRadius > 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-01 00:21:36 +00:00
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-01 00:21:36 +00:00
|
|
|
if (playeringame[i] && !(players[i].cheats & CF_NOCLIP))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-01 00:21:36 +00:00
|
|
|
AActor *victim = players[i].mo;
|
|
|
|
fixed_t dist;
|
|
|
|
|
|
|
|
dist = P_AproxDistance (victim->x - m_Spot->x, victim->y - m_Spot->y);
|
|
|
|
// Check if in damage radius
|
|
|
|
if (dist < m_DamageRadius && victim->z <= victim->floorz)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-01 00:21:36 +00:00
|
|
|
if (pr_quake() < 50)
|
|
|
|
{
|
2006-10-31 14:53:21 +00:00
|
|
|
P_DamageMobj (victim, NULL, NULL, pr_quake.HitDice (1), NAME_None);
|
2006-07-01 00:21:36 +00:00
|
|
|
}
|
|
|
|
// Thrust player around
|
|
|
|
angle_t an = victim->angle + ANGLE_1*pr_quake();
|
|
|
|
P_ThrustMobj (victim, an, m_Intensity << (FRACBITS-1));
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (--m_Countdown == 0)
|
|
|
|
{
|
|
|
|
Destroy ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-01 00:21:36 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DEarthquake::StaticGetQuakeIntensity
|
|
|
|
//
|
|
|
|
// Searches for all quakes near the victim and returns their combined
|
|
|
|
// intensity.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
int DEarthquake::StaticGetQuakeIntensity (AActor *victim)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-01 00:21:36 +00:00
|
|
|
int intensity = 0;
|
|
|
|
TThinkerIterator<DEarthquake> iterator (STAT_EARTHQUAKE);
|
|
|
|
DEarthquake *quake;
|
|
|
|
|
|
|
|
if (victim->player != NULL && (victim->player->cheats & CF_NOCLIP))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( (quake = iterator.Next()) != NULL)
|
|
|
|
{
|
2006-07-11 00:20:45 +00:00
|
|
|
if (quake->m_Spot != NULL)
|
2006-07-01 00:21:36 +00:00
|
|
|
{
|
2006-07-11 00:20:45 +00:00
|
|
|
fixed_t dist = P_AproxDistance (victim->x - quake->m_Spot->x,
|
|
|
|
victim->y - quake->m_Spot->y);
|
|
|
|
if (dist < quake->m_TremorRadius)
|
|
|
|
{
|
|
|
|
intensity += quake->m_Intensity;
|
|
|
|
}
|
2006-07-01 00:21:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return intensity;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 00:21:36 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// P_StartQuake
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-07-30 08:31:26 +00:00
|
|
|
bool P_StartQuake (AActor *activator, int tid, int intensity, int duration, int damrad, int tremrad)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AActor *center;
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
intensity = clamp (intensity, 1, 9);
|
|
|
|
|
2006-07-30 08:31:26 +00:00
|
|
|
if (tid == 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-30 08:31:26 +00:00
|
|
|
if (activator != NULL)
|
|
|
|
{
|
|
|
|
new DEarthquake(activator, intensity, duration, damrad, tremrad);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FActorIterator iterator (tid);
|
|
|
|
while ( (center = iterator.Next ()) )
|
|
|
|
{
|
|
|
|
res = true;
|
|
|
|
new DEarthquake (center, intensity, duration, damrad, tremrad);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|