SBSPSS/source/thing/thing.h

314 lines
7.6 KiB
C
Raw Normal View History

2001-02-26 21:27:20 +01:00
/*=========================================================================
thing.h
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __THING_THING_H__
#define __THING_THING_H__
/*----------------------------------------------------------------------
Includes
-------- */
#ifndef _GLOBAL_HEADER_
#include "system\global.h"
#endif
#ifndef __GAME_EVENT_H__
#include "game\event.h"
#endif
2001-05-10 18:16:57 +02:00
#include <dstructs.h>
2001-02-26 21:27:20 +01:00
/* Std Lib
------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
2001-04-06 23:25:18 +02:00
// Collision rectangle definition
2001-05-10 18:16:57 +02:00
struct CRECT
2001-04-06 23:25:18 +02:00
{
int x1,y1,x2,y2;
2001-05-10 18:16:57 +02:00
};
2001-04-06 23:25:18 +02:00
2001-05-10 18:16:57 +02:00
/*----------------------------------------------------------------------*/
2001-02-26 21:27:20 +01:00
// Thing manager class
2001-05-10 18:16:57 +02:00
class CThing;
class CThingManager
2001-02-26 21:27:20 +01:00
{
public:
2001-06-18 21:31:50 +02:00
static void init();
static void shutdown();
static void killAllThingsForRespawn();
2001-02-26 21:27:20 +01:00
2001-06-18 21:31:50 +02:00
static void initAllThings();
static void thinkAllThings(int _frames);
static void renderAllThings();
static void processEventAllThings(GAME_EVENT _event,CThing *_sourceThing);
2001-02-26 21:27:20 +01:00
2001-06-18 21:31:50 +02:00
static CThing *checkCollisionAreaAgainstThings(CRECT *_area,int _type,int _continue);
static void initCollision();
static void matchWheelsAndWeights();
static void matchPressureSwitches();
static void matchGaryTriggers();
2001-07-05 23:50:02 +02:00
static void shakePlatformLoose();
2001-05-10 18:16:57 +02:00
2001-06-18 21:31:50 +02:00
static sBBox &getRenderBBox() {return(m_RenderBBox);}
static sBBox &getThinkBBox() {return(m_ThinkBBox);}
2001-04-06 23:25:18 +02:00
2001-02-26 21:27:20 +01:00
protected:
2001-06-18 21:31:50 +02:00
static void initList(CThing **List);
static void addToThingList(CThing *_this);
static void removeFromThingList(CThing *_this);
2001-05-10 18:16:57 +02:00
2001-06-18 21:31:50 +02:00
static void addToCollisionList(CThing *_this);
2001-05-10 18:16:57 +02:00
2001-06-18 21:31:50 +02:00
friend class CThing;
2001-02-26 21:27:20 +01:00
private:
2001-06-18 21:31:50 +02:00
static CThing *s_thingLists[];
static int s_initialised;
2001-02-26 21:27:20 +01:00
2001-06-18 21:31:50 +02:00
static CThing *s_CollisionLists[];
static sBBox m_RenderBBox;
static sBBox m_ThinkBBox;
2001-05-25 20:43:47 +02:00
public:
// FreeList Stuff
2001-06-18 21:31:50 +02:00
static void initFreeList();
static void resetFreeList();
static void shutdownFreeList();
static CThing *GetThing(int Type,int SubType);
static void DeleteThing(CThing *Thing);
2001-05-21 17:19:18 +02:00
2001-05-25 20:43:47 +02:00
private:
2001-06-18 21:31:50 +02:00
static CThing **s_FreeList[];
2001-02-26 21:27:20 +01:00
};
2001-05-25 20:43:47 +02:00
2001-05-10 18:16:57 +02:00
/*----------------------------------------------------------------------*/
2001-02-26 21:27:20 +01:00
// Base thing class
class CThing
{
public:
2001-05-10 18:16:57 +02:00
enum TYPE
2001-02-26 21:27:20 +01:00
{
TYPE_PICKUP,
2001-03-08 21:12:47 +01:00
TYPE_PLATFORM,
2001-02-26 21:27:20 +01:00
TYPE_PLAYER,
2001-02-27 17:59:50 +01:00
TYPE_PLAYERPROJECTILE,
TYPE_NPC,
2001-02-26 21:27:20 +01:00
TYPE_ENEMY,
2001-02-27 17:59:50 +01:00
TYPE_ENEMYPROJECTILE,
TYPE_TRIGGER,
2001-04-24 17:01:42 +02:00
TYPE_HAZARD,
2001-05-04 20:47:12 +02:00
TYPE_FX,
2001-02-26 21:27:20 +01:00
MAX_TYPE,
2001-05-10 18:16:57 +02:00
};
// TYPE;
2001-05-25 20:43:47 +02:00
CThing()
{
initDef();
2001-07-04 20:19:13 +02:00
m_SubType=255;
2001-05-25 20:43:47 +02:00
}
2001-05-10 18:16:57 +02:00
virtual ~CThing() {;}
2001-02-26 21:27:20 +01:00
2001-07-04 20:19:13 +02:00
/*virtual*/ void initDef()
2001-05-25 20:43:47 +02:00
{
2001-05-30 17:04:41 +02:00
Pos.vx=0; Pos.vy=0;
PosDelta=Pos;
PosLast=Pos;
2001-05-25 20:43:47 +02:00
m_isShuttingDown=false;
NextFreeThing=0;
}
2001-07-04 20:19:13 +02:00
virtual TYPE getThingType()=0;
2001-02-26 21:27:20 +01:00
2001-07-04 20:19:13 +02:00
/*virtual */void setThingSubType(int T) {m_SubType=T;}
/*virtual */int getThingSubType() {return(m_SubType);}
2001-05-25 20:43:47 +02:00
2001-07-04 20:19:13 +02:00
//virtual void create() {;} // Once only init (for mem alloc)
virtual void init(); // re-usable init
virtual void shutdown(); // re-usable shutdown
//virtual void destroy() {;} // memory clean up when totally killing the poor things
2001-06-14 23:17:10 +02:00
2001-07-04 20:19:13 +02:00
virtual void think(int _frames);
virtual void render();
void setToShutdown(bool f=true) {m_isShuttingDown = f;}
u8 isSetToShutdown() {return( m_isShuttingDown);}
virtual int dontKillDuringLevelRespawn() {return false;}
void calcRenderPos(DVECTOR const &Pos,DVECTOR &renderPos);
2001-02-26 21:27:20 +01:00
// Linkage
2001-05-10 18:16:57 +02:00
void addChild(CThing *Child);
void removeChild(CThing *Child);
void removeAllChild();
void deleteAllChild();
2001-05-29 22:31:02 +02:00
int getNumChildren() {return( m_numChildren );}
2001-02-26 21:27:20 +01:00
2001-05-10 18:16:57 +02:00
DVECTOR const &getPos() {return Pos;}
void setPos(DVECTOR newPos) {Pos=newPos;}
DVECTOR getPosDelta() {return PosDelta;}
2001-05-21 17:19:18 +02:00
CThing *getParent() {return ParentThing;}
CThing *getNext() {return NextThing;}
2001-02-26 21:27:20 +01:00
2001-05-10 18:16:57 +02:00
virtual void processEvent(GAME_EVENT _event,CThing *_sourceThing);
2001-02-26 21:27:20 +01:00
protected:
2001-05-21 17:19:18 +02:00
// Pos
DVECTOR Pos, PosLast, PosDelta;
2001-02-26 21:27:20 +01:00
2001-05-10 18:16:57 +02:00
// Parent Child Linkage
2001-05-21 17:19:18 +02:00
CThing *ParentThing,*NextThing;
2001-07-04 20:19:13 +02:00
u8 m_numChildren;
2001-02-26 21:27:20 +01:00
public:
2001-05-21 17:19:18 +02:00
// Collision/List Link List
2001-05-10 18:16:57 +02:00
CThing *m_nextCollisionThing;
2001-05-21 17:19:18 +02:00
CThing *m_nextListThing;
public:
CThing *m_NextFreeThing;
2001-02-26 21:27:20 +01:00
2001-05-21 17:19:18 +02:00
// -- Collision --
2001-02-26 21:27:20 +01:00
public:
2001-05-14 18:33:39 +02:00
virtual CRECT const *getRenderBBox() {return &m_collisionArea;}
virtual CRECT const *getThinkBBox() {return &m_collisionArea;}
2001-05-15 00:12:09 +02:00
virtual bool alwaysThink() {return(false);}
2001-06-14 23:17:10 +02:00
virtual void leftThinkZone(int _frames) {}
2001-07-04 20:19:13 +02:00
//virtual void enterThinkZone(int _frames) {}
2001-05-14 18:33:39 +02:00
2001-05-10 18:16:57 +02:00
void ShowBBox();
DVECTOR const &getCollisionCentre() {return m_collisionCentre;}
DVECTOR const &getCollisionCentreOffset() {return m_collisionCentreOffset;}
int getCollisionRadius() {return m_collisionRadius;}
2001-07-04 20:19:13 +02:00
/*virtual */CRECT const &getCollisionArea() {return m_collisionArea;}
2001-05-10 18:16:57 +02:00
DVECTOR const &getCollisionSize() {return m_collisionSize;}
virtual int canCollide() {return true;}
virtual int checkCollisionAgainst(CThing *_thisThing, int _frames);
int checkCollisionAgainstArea(CRECT *_rect);
void updateCollisionArea();
virtual void collidedWith(CThing *_thisThing) {;}
2001-06-14 23:17:10 +02:00
//virtual s32 getNewYPos( CThing *_thisThing );
2001-05-21 17:19:18 +02:00
public:
// Thing states
2001-05-10 23:09:23 +02:00
void setRenderFlag(bool f) {m_renderFlag=f;}
void setThinkFlag(bool f) {m_thinkFlag=f;}
2001-05-29 18:38:09 +02:00
bool getThinkFlag() {return(m_thinkFlag);}
2001-05-10 18:16:57 +02:00
bool canRender() {return (m_renderFlag);}
DVECTOR &getRenderPos() {return(m_RenderPos);}
bool canThink() {return (m_thinkFlag);}
2001-06-14 23:17:10 +02:00
2001-05-21 17:19:18 +02:00
protected:
DVECTOR m_RenderPos;
2001-07-04 20:19:13 +02:00
u8 m_renderFlag,m_thinkFlag;
u8 m_isShuttingDown;
u8 m_SubType;
2001-04-06 23:25:18 +02:00
2001-02-26 21:27:20 +01:00
protected:
2001-07-04 20:19:13 +02:00
/*virtual */void setCollisionSize(int _w,int _h);
/*virtual */void setCollisionCentreOffset(int _x,int _y) {m_collisionCentreOffset.vx=_x;m_collisionCentreOffset.vy=_y;}
/*virtual */void setCollisionCentreOffset(DVECTOR xy) {m_collisionCentreOffset=xy;}
2001-05-29 18:38:09 +02:00
2001-02-26 21:27:20 +01:00
private:
2001-05-10 18:16:57 +02:00
DVECTOR m_collisionSize;
DVECTOR m_collisionCentreOffset;
2001-07-04 20:19:13 +02:00
s16 m_collisionRadius;
2001-05-10 18:16:57 +02:00
CRECT m_collisionArea;
DVECTOR m_collisionCentre;
2001-05-21 17:19:18 +02:00
// Free List Stuff
2001-05-25 20:43:47 +02:00
public:
CThing *NextFreeThing;
2001-02-26 21:27:20 +01:00
};
2001-05-10 18:16:57 +02:00
/*---------------------------------------------------------------------- */
2001-02-27 17:59:50 +01:00
/* These are the individual base classes for each of the seperate thing types */
class CPickupThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_PICKUP;}
2001-02-27 17:59:50 +01:00
};
2001-05-10 18:16:57 +02:00
2001-02-27 17:59:50 +01:00
class CPlayerThing : public CThing
{
public:
2001-05-25 20:43:47 +02:00
enum
{ // For Dynamic ThingCache
MAX_SUBTYPE =1,
};
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_PLAYER;}
2001-05-15 00:12:09 +02:00
virtual bool alwaysThink() {return(true);}
2001-02-27 17:59:50 +01:00
};
2001-05-10 18:16:57 +02:00
2001-02-27 17:59:50 +01:00
class CPlayerProjectileThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_PLAYERPROJECTILE;}
2001-02-27 17:59:50 +01:00
};
2001-05-10 18:16:57 +02:00
2001-02-27 17:59:50 +01:00
class CNpcThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_NPC;}
2001-02-27 17:59:50 +01:00
};
2001-05-10 18:16:57 +02:00
2001-02-27 17:59:50 +01:00
class CEnemyThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_ENEMY;}
2001-02-27 17:59:50 +01:00
};
2001-05-10 18:16:57 +02:00
2001-02-27 17:59:50 +01:00
class CEnemyProjectileThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_ENEMYPROJECTILE;}
2001-02-27 17:59:50 +01:00
};
2001-05-10 18:16:57 +02:00
2001-02-27 17:59:50 +01:00
class CPlatformThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_PLATFORM;}
2001-02-27 17:59:50 +01:00
};
2001-05-10 18:16:57 +02:00
2001-02-27 17:59:50 +01:00
class CTriggerThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_TRIGGER;}
2001-02-27 17:59:50 +01:00
};
2001-05-10 18:16:57 +02:00
2001-04-24 17:01:42 +02:00
class CHazardThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_HAZARD;}
2001-04-24 17:01:42 +02:00
};
2001-05-10 18:16:57 +02:00
2001-05-04 20:47:12 +02:00
class CFXThing : public CThing
{
public:
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType() {return TYPE_FX;}
2001-05-04 20:47:12 +02:00
};
2001-02-27 17:59:50 +01:00
2001-02-26 21:27:20 +01:00
#endif /* __THING_THING_H__ */
/*===========================================================================
end */