SBSPSS/source/thing/thing.h

320 lines
8.1 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:
static void init();
static void shutdown();
2001-05-04 21:34:09 +02:00
static void killAllThingsForRespawn();
2001-02-26 21:27:20 +01:00
2001-05-11 01:51:14 +02:00
static void initAllThings();
2001-02-26 21:27:20 +01:00
static void thinkAllThings(int _frames);
static void renderAllThings();
2001-05-10 18:16:57 +02:00
static void processEventAllThings(GAME_EVENT _event,CThing *_sourceThing);
2001-02-26 21:27:20 +01:00
2001-04-06 23:25:18 +02:00
static CThing* checkCollisionAreaAgainstThings(CRECT *_area,int _type,int _continue);
2001-05-10 18:16:57 +02:00
static void initCollision();
2001-05-23 20:45:27 +02:00
static void matchWheelsAndWeights();
2001-05-24 01:16:43 +02:00
static void matchPressureSwitches();
2001-05-10 18:16:57 +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-05-10 18:16:57 +02:00
static void initList(CThing **List);
static void addToThingList(CThing *_this);
static void removeFromThingList(CThing *_this);
static void addToCollisionList(CThing *_this);
friend class CThing;
2001-02-26 21:27:20 +01:00
private:
2001-05-10 18:16:57 +02:00
static CThing *s_thingLists[];
static int s_initialised;
2001-02-26 21:27:20 +01:00
2001-05-10 18:16:57 +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
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:
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();
m_SubType=1234;
}
2001-05-10 18:16:57 +02:00
virtual ~CThing() {;}
2001-02-26 21:27:20 +01:00
2001-05-25 20:43:47 +02:00
virtual void initDef()
{
m_isShuttingDown=false;
NextFreeThing=0;
}
2001-05-10 18:16:57 +02:00
virtual TYPE getThingType()=0;
2001-02-26 21:27:20 +01:00
2001-05-25 20:43:47 +02:00
virtual void setThingSubType(int T) {m_SubType=T;}
virtual int getThingSubType() {return(m_SubType);}
2001-05-10 18:16:57 +02:00
virtual void init();
virtual void shutdown();
virtual void think(int _frames);
virtual void render();
2001-05-25 20:43:47 +02:00
void setToShutdown(bool f=true) {m_isShuttingDown = f;}
2001-05-16 22:46:54 +02:00
u8 isSetToShutdown() {return( m_isShuttingDown);}
2001-05-15 18:48:29 +02:00
virtual int dontKillDuringLevelRespawn() {return false;}
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();
bool hasChild(CThing *Child);
int getNumChildren();
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-05-10 18:16:57 +02:00
int 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-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-05-11 02:54:52 +02:00
virtual CRECT const &getCollisionArea() {return m_collisionArea;}
2001-05-25 20:43:47 +02:00
//!Dave! s16 getCollisionAngle() {return m_collisionAngle;} // pkg - move to CNpcPlatform?
//!Dave! DVECTOR const &getNewCollidedPos() {return m_newCollidedPos;} // pkg - to be removed?
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) {;}
virtual void setHasPlatformCollided( bool newVal ) {;}
virtual bool getHasPlatformCollided() {return false;}
virtual s32 getNewYPos( CThing *_thisThing );
2001-05-25 20:43:47 +02:00
//!Dave! void setNewCollidedPos(DVECTOR newPos) {m_newCollidedPos = newPos;} // pkg - to be removed?
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-10 18:16:57 +02:00
bool canRender() {return (m_renderFlag);}
DVECTOR &getRenderPos() {return(m_RenderPos);}
bool canThink() {return (m_thinkFlag);}
2001-05-21 17:19:18 +02:00
protected:
bool m_renderFlag,m_thinkFlag;
DVECTOR m_RenderPos;
bool m_isShuttingDown;
2001-05-25 20:43:47 +02:00
int m_SubType;
2001-04-06 23:25:18 +02:00
2001-02-26 21:27:20 +01:00
protected:
2001-05-10 18:16:57 +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-25 20:43:47 +02:00
//!Dave!virtual void setCollisionAngle(int newAngle) {m_collisionAngle = newAngle;} // pkg - move to CNpcPlatform?
2001-02-26 21:27:20 +01:00
private:
2001-05-10 18:16:57 +02:00
DVECTOR m_collisionSize;
DVECTOR m_collisionCentreOffset;
int m_collisionRadius;
CRECT m_collisionArea;
DVECTOR m_collisionCentre;
2001-05-25 20:43:47 +02:00
//!Dave! s16 m_collisionAngle; // pkg - move to CNpcPlatform?
//!Dave! DVECTOR m_newCollidedPos; // pkg - to be removed?
2001-05-10 18:16:57 +02:00
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-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_TRIGGER;}
virtual void setPositionAndSize(int _x,int _y,int _w,int _h); // Wonder if this might be better in CThing? (pkg)
virtual void setTargetBox(int _x,int _y,int _w,int _h); // Wonder if this might be better in CThing? (pkg)
2001-05-25 20:43:47 +02:00
2001-05-04 03:35:52 +02:00
protected:
2001-05-10 18:16:57 +02:00
int m_boxX1,m_boxY1,m_boxX2,m_boxY2;
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 */