2006-02-24 04:48:15 +00:00
|
|
|
|
#include "actor.h"
|
|
|
|
|
#include "info.h"
|
|
|
|
|
#include "gi.h"
|
|
|
|
|
#include "m_random.h"
|
2008-08-02 16:17:19 +00:00
|
|
|
|
#include "thingdef/thingdef.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
|
|
static FRandom pr_orbit ("Orbit");
|
|
|
|
|
|
|
|
|
|
|
2008-08-02 16:17:19 +00:00
|
|
|
|
// Custom bridge --------------------------------------------------------
|
|
|
|
|
/*
|
|
|
|
|
args[0]: Bridge radius, in mapunits
|
|
|
|
|
args[1]: Bridge height, in mapunits
|
|
|
|
|
args[2]: Amount of bridge balls (if 0: Doom bridge)
|
|
|
|
|
args[3]: Rotation speed of bridge balls, in byte angle per seconds, sorta:
|
|
|
|
|
Since an arg is only a byte, it can only go from 0 to 255, while ZDoom's
|
|
|
|
|
BAM go from 0 to 65535. Plus, it needs to be able to go either way. So,
|
|
|
|
|
up to 128, it goes counterclockwise; 129-255 is clockwise, substracting
|
|
|
|
|
256 from it to get the angle. A few example values:
|
|
|
|
|
0: Hexen default
|
|
|
|
|
11: 15<EFBFBD> / seconds
|
|
|
|
|
21: 30<EFBFBD> / seconds
|
|
|
|
|
32: 45<EFBFBD> / seconds
|
|
|
|
|
64: 90<EFBFBD> / seconds
|
|
|
|
|
128: 180<EFBFBD> / seconds
|
|
|
|
|
192: -90<EFBFBD> / seconds
|
|
|
|
|
223: -45<EFBFBD> / seconds
|
|
|
|
|
233: -30<EFBFBD> / seconds
|
|
|
|
|
244: -15<EFBFBD> / seconds
|
|
|
|
|
This value only matters if args[2] is not zero.
|
|
|
|
|
args[4]: Rotation radius of bridge balls, in bridge radius %.
|
|
|
|
|
If 0, use Hexen default: ORBIT_RADIUS, regardless of bridge radius.
|
|
|
|
|
This value only matters if args[2] is not zero.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-08-03 12:00:36 +00:00
|
|
|
|
class ACustomBridge : public AActor
|
2008-08-02 16:17:19 +00:00
|
|
|
|
{
|
2008-08-03 12:00:36 +00:00
|
|
|
|
DECLARE_CLASS (ACustomBridge, AActor)
|
2008-08-02 16:17:19 +00:00
|
|
|
|
public:
|
|
|
|
|
void BeginPlay ();
|
|
|
|
|
};
|
|
|
|
|
|
2008-08-03 12:00:36 +00:00
|
|
|
|
IMPLEMENT_CLASS(ACustomBridge)
|
2008-08-02 16:17:19 +00:00
|
|
|
|
|
|
|
|
|
void ACustomBridge::BeginPlay ()
|
|
|
|
|
{
|
|
|
|
|
if (args[2]) // Hexen bridge if there are balls
|
|
|
|
|
{
|
2008-08-03 12:00:36 +00:00
|
|
|
|
SetState(SeeState);
|
2008-08-02 16:17:19 +00:00
|
|
|
|
radius = args[0] ? args[0] << FRACBITS : 32 * FRACUNIT;
|
|
|
|
|
height = args[1] ? args[1] << FRACBITS : 2 * FRACUNIT;
|
|
|
|
|
}
|
|
|
|
|
else // No balls? Then a Doom bridge.
|
|
|
|
|
{
|
|
|
|
|
radius = args[0] ? args[0] << FRACBITS : 36 * FRACUNIT;
|
|
|
|
|
height = args[1] ? args[1] << FRACBITS : 4 * FRACUNIT;
|
|
|
|
|
RenderStyle = STYLE_Normal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
|
// Action functions for the non-Doom bridge --------------------------------
|
|
|
|
|
|
|
|
|
|
#define ORBIT_RADIUS 15
|
|
|
|
|
|
|
|
|
|
// New bridge stuff
|
|
|
|
|
// Parent
|
|
|
|
|
// special1 true == removing from world
|
|
|
|
|
//
|
|
|
|
|
// Child
|
|
|
|
|
// target pointer to center mobj
|
|
|
|
|
// angle angle of ball
|
|
|
|
|
|
|
|
|
|
void A_BridgeOrbit (AActor *self)
|
|
|
|
|
{
|
|
|
|
|
if (self->target == NULL)
|
|
|
|
|
{ // Don't crash if somebody spawned this into the world
|
|
|
|
|
// independantly of a Bridge actor.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-08-02 16:17:19 +00:00
|
|
|
|
// Set default values
|
|
|
|
|
// Every five tics, Hexen moved the ball 3/256th of a revolution.
|
|
|
|
|
int rotationspeed = ANGLE_45/32*3/5;
|
|
|
|
|
int rotationradius = ORBIT_RADIUS;
|
|
|
|
|
// If the bridge is custom, set non-default values if any.
|
2008-08-03 12:00:36 +00:00
|
|
|
|
|
|
|
|
|
// Set angular speed; 1--128: counterclockwise rotation ~=1--180<38>; 129--255: clockwise rotation ~= 180--1<>
|
|
|
|
|
if (self->target->args[3] > 128) rotationspeed = ANGLE_45/32 * (self->target->args[3]-256) / TICRATE;
|
|
|
|
|
else if (self->target->args[3] > 0) rotationspeed = ANGLE_45/32 * (self->target->args[3]) / TICRATE;
|
|
|
|
|
// Set rotation radius
|
|
|
|
|
if (self->target->args[4]) rotationradius = ((self->target->args[4] * self->target->radius) / (100 * FRACUNIT));
|
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
|
if (self->target->special1)
|
|
|
|
|
{
|
|
|
|
|
self->SetState (NULL);
|
|
|
|
|
}
|
2008-08-02 16:17:19 +00:00
|
|
|
|
self->angle += rotationspeed;
|
|
|
|
|
self->x = self->target->x + rotationradius * finecosine[self->angle >> ANGLETOFINESHIFT];
|
|
|
|
|
self->y = self->target->y + rotationradius * finesine[self->angle >> ANGLETOFINESHIFT];
|
2006-02-24 04:48:15 +00:00
|
|
|
|
self->z = self->target->z;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-02 16:17:19 +00:00
|
|
|
|
|
|
|
|
|
static const PClass *GetBallType()
|
|
|
|
|
{
|
|
|
|
|
const PClass *balltype = NULL;
|
|
|
|
|
int index=CheckIndex(1, NULL);
|
|
|
|
|
if (index>=0)
|
|
|
|
|
{
|
|
|
|
|
balltype = PClass::FindClass((ENamedName)StateParameters[index]);
|
|
|
|
|
}
|
|
|
|
|
if (balltype == NULL) balltype = PClass::FindClass("BridgeBall");
|
|
|
|
|
return balltype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
|
void A_BridgeInit (AActor *self)
|
|
|
|
|
{
|
|
|
|
|
angle_t startangle;
|
2008-08-02 16:17:19 +00:00
|
|
|
|
AActor *ball;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
fixed_t cx, cy, cz;
|
|
|
|
|
|
|
|
|
|
cx = self->x;
|
|
|
|
|
cy = self->y;
|
|
|
|
|
cz = self->z;
|
|
|
|
|
startangle = pr_orbit() << 24;
|
|
|
|
|
self->special1 = 0;
|
|
|
|
|
|
2008-08-02 16:17:19 +00:00
|
|
|
|
// Spawn triad into world -- may be more than a triad now.
|
2008-08-03 12:00:36 +00:00
|
|
|
|
int ballcount = self->args[2]==0 ? 3 : self->args[2];
|
2008-08-02 16:17:19 +00:00
|
|
|
|
const PClass *balltype = GetBallType();
|
|
|
|
|
for (int i = 0; i < ballcount; i++)
|
|
|
|
|
{
|
|
|
|
|
ball = Spawn(balltype, cx, cy, cz, ALLOW_REPLACE);
|
|
|
|
|
ball->angle = startangle + (ANGLE_45/32) * (256/ballcount) * i;
|
|
|
|
|
ball->target = self;
|
|
|
|
|
A_BridgeOrbit(ball);
|
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-03 12:00:36 +00:00
|
|
|
|
/* never used
|
2006-02-24 04:48:15 +00:00
|
|
|
|
void A_BridgeRemove (AActor *self)
|
|
|
|
|
{
|
|
|
|
|
self->special1 = true; // Removing the bridge
|
|
|
|
|
self->flags &= ~MF_SOLID;
|
|
|
|
|
self->SetState (&ABridge::States[S_FREE_BRIDGE]);
|
|
|
|
|
}
|
2008-08-03 12:00:36 +00:00
|
|
|
|
*/
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
|
|
// Invisible bridge --------------------------------------------------------
|
|
|
|
|
|
2008-08-03 12:00:36 +00:00
|
|
|
|
class AInvisibleBridge : public AActor
|
2006-02-24 04:48:15 +00:00
|
|
|
|
{
|
2008-08-03 12:00:36 +00:00
|
|
|
|
DECLARE_CLASS (AInvisibleBridge, AActor)
|
2006-02-24 04:48:15 +00:00
|
|
|
|
public:
|
|
|
|
|
void BeginPlay ();
|
|
|
|
|
};
|
|
|
|
|
|
2008-08-03 12:00:36 +00:00
|
|
|
|
IMPLEMENT_CLASS(AInvisibleBridge)
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
|
|
void AInvisibleBridge::BeginPlay ()
|
|
|
|
|
{
|
|
|
|
|
Super::BeginPlay ();
|
|
|
|
|
if (args[0])
|
|
|
|
|
radius = args[0] << FRACBITS;
|
|
|
|
|
if (args[1])
|
|
|
|
|
height = args[1] << FRACBITS;
|
|
|
|
|
}
|
|
|
|
|
|