SBSPSS/source/hazard/hazard.cpp

414 lines
8.3 KiB
C++
Raw Normal View History

2001-04-24 15:24:26 +02:00
/*=========================================================================
hazard.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HAZARD_H__
#include "hazard\hazard.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-05-01 15:28:11 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-05-01 18:28:51 +02:00
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-05-01 15:28:11 +02:00
#ifndef __HAZARD_HFALLING_H__
#include "hazard\hfalling.h"
#endif
#ifndef __HAZARD_HPENDULM_H__
#include "hazard\hpendulm.h"
#endif
#ifndef __HAZARD_HBOAT_H__
#include "hazard\hboat.h"
#endif
2001-05-03 16:51:14 +02:00
#ifndef __HAZARD_HBARREL_H__
#include "hazard\hbarrel.h"
#endif
#ifndef __HAZARD_HSTATIC_H__
#include "hazard\hstatic.h"
#endif
#ifndef __HAZARD_HCSAW_H__
#include "hazard\hcsaw.h"
#endif
2001-05-04 23:25:33 +02:00
#ifndef __HAZARD_HMOWER_H__
#include "hazard\hmower.h"
#endif
#ifndef __HAZARD_HMASHER_H__
#include "hazard\hmasher.h"
#endif
#ifndef __HAZARD_HFAN_H__
#include "hazard\hfan.h"
#endif
#ifndef __HAZARD_HSPIKES_H__
#include "hazard\hspikes.h"
#endif
2001-05-05 15:54:34 +02:00
#ifndef __HAZARD_HBWHEEL_H__
#include "hazard\hbwheel.h"
#endif
2001-05-05 21:08:02 +02:00
#ifndef __HAZARD_HDBARREL_H__
#include "hazard\hdbarrel.h"
#endif
2001-05-05 23:04:00 +02:00
#ifndef __HAZARD_HBBARREL_H__
#include "hazard\hbbarrel.h"
#endif
2001-05-04 23:25:33 +02:00
2001-04-24 15:24:26 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-01 15:28:11 +02:00
CNpcHazard::NPC_HAZARD_UNIT_TYPE CNpcHazard::mapEditConvertTable[NPC_HAZARD_TYPE_MAX] =
2001-04-24 15:24:26 +02:00
{
2001-05-01 15:28:11 +02:00
NPC_FALLING_HAZARD,
NPC_PENDULUM_HAZARD,
NPC_BOAT_HAZARD,
2001-05-03 16:51:14 +02:00
NPC_BARREL_HAZARD,
NPC_STATIC_HAZARD,
NPC_CIRCULAR_SAW_HAZARD,
2001-05-04 23:25:33 +02:00
NPC_MOWER_HAZARD,
NPC_MASHER_HAZARD,
NPC_FAN_HAZARD,
NPC_SPIKES_HAZARD,
2001-05-05 15:54:34 +02:00
NPC_BIG_WHEEL_HAZARD,
2001-05-05 21:08:02 +02:00
NPC_DUAL_PLATFORM_BARREL_HAZARD,
2001-05-05 23:04:00 +02:00
NPC_BOUNCING_BARREL_HAZARD,
2001-05-01 15:28:11 +02:00
};
2001-04-24 15:24:26 +02:00
2001-05-01 15:28:11 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 15:24:26 +02:00
2001-05-01 15:28:11 +02:00
CNpcHazard *CNpcHazard::Create(sThingHazard *ThisHazard)
{
CNpcHazard *hazard;
NPC_HAZARD_UNIT_TYPE hazardType = getTypeFromMapEdit( ThisHazard->Type );
switch( hazardType )
{
case NPC_FALLING_HAZARD:
{
hazard = new ("falling hazard") CNpcFallingHazard;
break;
}
case NPC_PENDULUM_HAZARD:
{
hazard = new ("pendulum hazard") CNpcPendulumHazard;
break;
}
case NPC_BOAT_HAZARD:
{
hazard = new ("boat hazard") CNpcBoatHazard;
break;
}
2001-05-03 16:51:14 +02:00
case NPC_BARREL_HAZARD:
{
hazard = new ("barrel hazard") CNpcBarrelHazard;
break;
}
case NPC_STATIC_HAZARD:
{
hazard = new ("static hazard") CNpcStaticHazard;
break;
}
case NPC_CIRCULAR_SAW_HAZARD:
{
hazard = new ("circular saw hazard") CNpcCircularSawHazard;
break;
}
2001-05-04 23:25:33 +02:00
case NPC_MOWER_HAZARD:
{
hazard = new ("mower hazard") CNpcMowerHazard;
break;
}
case NPC_MASHER_HAZARD:
{
hazard = new ("masher hazard") CNpcMasherHazard;
break;
}
case NPC_FAN_HAZARD:
{
hazard = new ("fan hazard") CNpcFanHazard;
break;
}
case NPC_SPIKES_HAZARD:
{
hazard = new ("spikes hazard") CNpcSpikesHazard;
break;
}
2001-05-05 15:54:34 +02:00
case NPC_BIG_WHEEL_HAZARD:
{
hazard = new ("big wheel") CNpcBigWheelHazard;
break;
}
2001-05-05 21:08:02 +02:00
case NPC_DUAL_PLATFORM_BARREL_HAZARD:
{
hazard = new ("dual platform barrel hazard") CNpcDualPlatformBarrelHazard;
break;
}
2001-05-05 23:04:00 +02:00
case NPC_BOUNCING_BARREL_HAZARD:
{
hazard = new ("bouncing barrel hazard") CNpcBouncingBarrelHazard;
break;
}
2001-05-01 15:28:11 +02:00
default:
{
hazard = NULL;
break;
}
}
ASSERT( hazard );
hazard->init();
hazard->setWaypoints( ThisHazard );
hazard->setGraphic( ThisHazard );
return( hazard );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcHazard::setWaypoints( sThingHazard *ThisHazard )
{
int pointNum;
u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard));
2001-04-24 15:24:26 +02:00
2001-05-01 15:28:11 +02:00
u16 newXPos, newYPos;
2001-04-24 17:01:42 +02:00
2001-05-01 15:28:11 +02:00
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
startPos.vx = newXPos << 4;
startPos.vy = newYPos << 4;
Pos = startPos;
2001-04-24 17:01:42 +02:00
m_base = Pos;
2001-05-01 15:28:11 +02:00
addWaypoint( newXPos, newYPos );
if ( ThisHazard->PointCount > 1 )
{
for ( pointNum = 1 ; pointNum < ThisHazard->PointCount ; pointNum++ )
{
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
addWaypoint( newXPos, newYPos );
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcHazard::addWaypoint( s32 xPos, s32 yPos )
{
DVECTOR newPos;
newPos.vx = xPos << 4;
newPos.vy = yPos << 4;
m_npcPath.addWaypoint( newPos );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CNpcHazard::NPC_HAZARD_UNIT_TYPE CNpcHazard::getTypeFromMapEdit( u16 newType )
{
return( mapEditConvertTable[newType] );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcHazard::init()
{
CHazardThing::init();
//m_actorGfx=CActorPool::GetActor( (FileEquate) ACTORS_CLAM_SBK );
//m_spriteBank=0;
m_npcPath.initPath();
2001-04-24 17:01:42 +02:00
m_timer = 0;
m_timerActive = false;
m_isActive = true;
m_extension = 0;
m_extendDir = 0;
m_heading = 0;
2001-05-08 18:25:45 +02:00
clearPlatform();
2001-04-24 15:24:26 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-01 15:28:11 +02:00
void CNpcHazard::setGraphic( sThingHazard *ThisHazard )
{
m_modelGfx = new ("ModelGfx") CModelGfx;
m_modelGfx->SetModel( ThisHazard->Gfx );
2001-05-05 15:54:34 +02:00
sBBox boundingBox = m_modelGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
2001-05-01 15:28:11 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 15:24:26 +02:00
void CNpcHazard::shutdown()
{
2001-05-01 15:28:11 +02:00
delete m_modelGfx;
//if (m_spriteBank) m_spriteBank->dump(); delete m_spriteBank;
2001-04-24 15:24:26 +02:00
// remove waypoints
m_npcPath.removeAllWaypoints();
2001-05-01 15:28:11 +02:00
//if (m_actorGfx) delete m_actorGfx;
2001-04-24 15:24:26 +02:00
CHazardThing::shutdown();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcHazard::think(int _frames)
{
CHazardThing::think(_frames);
2001-04-24 17:01:42 +02:00
if ( m_isActive )
{
2001-04-25 17:48:31 +02:00
int moveFrames = _frames;
if ( moveFrames > 2 )
{
// make sure hazards don't go berserk if too many frames are dropped
moveFrames = 2;
}
processMovement( moveFrames );
2001-04-24 17:01:42 +02:00
}
if ( m_timerActive )
{
processTimer( _frames );
}
2001-05-08 18:25:45 +02:00
clearPlatform();
2001-04-24 15:24:26 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 17:01:42 +02:00
void CNpcHazard::processMovement( int _frames )
2001-04-24 15:24:26 +02:00
{
2001-04-24 17:01:42 +02:00
}
2001-04-24 15:24:26 +02:00
2001-04-24 17:01:42 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 15:24:26 +02:00
2001-04-24 17:01:42 +02:00
void CNpcHazard::processTimer( int _frames )
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 15:24:26 +02:00
2001-04-24 17:01:42 +02:00
void CNpcHazard::render()
{
if ( m_isActive )
2001-04-24 15:24:26 +02:00
{
2001-04-24 17:01:42 +02:00
CHazardThing::render();
// Render
DVECTOR renderPos;
DVECTOR offset = CLevel::getCameraPos();
renderPos.vx = Pos.vx - offset.vx;
renderPos.vy = Pos.vy - offset.vy;
2001-05-05 16:58:49 +02:00
CRECT collisionRect = getCollisionArea();
collisionRect.x1 -= Pos.vx;
collisionRect.x2 -= Pos.vx;
collisionRect.y1 -= Pos.vy;
collisionRect.y2 -= Pos.vy;
if ( renderPos.vx + collisionRect.x2 >= 0 && renderPos.vx + collisionRect.x1 <= VidGetScrW() )
2001-04-24 15:24:26 +02:00
{
2001-05-05 16:58:49 +02:00
if ( renderPos.vy + collisionRect.y2 >= 0 && renderPos.vy + collisionRect.y1 <= VidGetScrH() )
2001-04-24 17:01:42 +02:00
{
2001-05-01 15:28:11 +02:00
m_modelGfx->Render(renderPos);
//m_actorGfx->Render(renderPos,0,0,0);
2001-04-24 17:01:42 +02:00
}
2001-04-24 15:24:26 +02:00
}
}
}
2001-05-01 18:28:51 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcHazard::collidedWith( CThing *_thisThing )
{
if ( m_isActive )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
CPlayer *player = (CPlayer *) _thisThing;
if ( !player->isRecoveringFromHit() )
{
player->takeDamage( DAMAGE__HIT_ENEMY );
}
break;
}
default:
ASSERT(0);
break;
}
}
}