SBSPSS/source/hazard/hazard.cpp

561 lines
11 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-18 14:55:34 +02:00
#ifndef __HAZARD_HFIREBAL_H__
#include "hazard\hfirebal.h"
#endif
2001-05-22 21:59:56 +02:00
#ifndef __HAZARD_HRROCK_H__
#include "hazard\hrrock.h"
#endif
2001-05-23 00:01:43 +02:00
#ifndef __HAZARD_HFLYTRAP_H__
#include "hazard\hflytrap.h"
#endif
2001-05-23 20:45:27 +02:00
#ifndef __HAZARD_HRWEIGHT_H__
#include "hazard\hrweight.h"
#endif
#ifndef __HAZARD_HRWHEEL_H__
#include "hazard\hrwheel.h"
#endif
2001-05-24 01:16:43 +02:00
#ifndef __HAZARD_HPSWITCH_H__
#include "hazard\hpswitch.h"
#endif
2001-05-24 17:18:25 +02:00
#ifndef __HAZARD_HRCKSHRD_H__
#include "hazard\hrckshrd.h"
#endif
2001-05-31 17:43:13 +02:00
#ifndef __HAZARD_HINERT_H__
#include "hazard\hinert.h"
#endif
2001-06-04 21:01:17 +02:00
#ifndef __HAZARD_HCSWITCH_H__
#include "hazard\hcswitch.h"
#endif
2001-06-05 18:01:22 +02:00
#ifndef __HAZARD_HBROCK_H__
#include "hazard\hbrock.h"
#endif
2001-06-14 23:27:25 +02:00
#ifndef __HAZARD_HSRDFISH_H__
#include "hazard\hsrdfish.h"
#endif
#ifndef __HAZARD_HLOG_H__
#include "hazard\hlog.h"
#endif
2001-07-17 22:15:28 +02:00
#ifndef __HAZARD_HCHECK_H__
#include "hazard\hcheck.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-18 14:55:34 +02:00
NPC_FIREBALL_HAZARD,
2001-05-22 21:59:56 +02:00
NPC_ROLLING_ROCK_HAZARD,
2001-05-23 00:01:43 +02:00
NPC_FLY_TRAP_HAZARD,
2001-05-23 20:45:27 +02:00
NPC_RISING_WEIGHT_HAZARD,
NPC_RISING_WEIGHT_WHEEL_HAZARD,
2001-05-24 01:16:43 +02:00
NPC_PRESSURE_SWITCH_HAZARD,
2001-05-24 17:18:25 +02:00
NPC_ROCKSHARD_HAZARD,
2001-05-31 17:43:13 +02:00
NPC_INERT_HAZARD,
2001-06-04 21:01:17 +02:00
NPC_CONVEYOR_SWITCH_HAZARD,
2001-06-05 18:01:22 +02:00
NPC_BOUNCING_ROCK_HAZARD,
2001-06-14 23:27:25 +02:00
NPC_SWORDFISH_HAZARD,
NPC_LOG_HAZARD,
2001-07-17 22:15:28 +02:00
NPC_CHECKPOINT_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-29 21:19:14 +02:00
CNpcHazard *CNpcHazard::Create(int Type)
2001-05-01 15:28:11 +02:00
{
2001-05-29 21:19:14 +02:00
CNpcHazard *hazard;
2001-05-01 15:28:11 +02:00
2001-05-25 20:43:47 +02:00
hazard = (CNpcHazard*)CThingManager::GetThing(CThing::TYPE_HAZARD,Type);
if (!hazard)
switch( Type )
2001-05-01 15:28:11 +02:00
{
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-18 14:55:34 +02:00
case NPC_FIREBALL_HAZARD:
{
hazard = new ("fireball hazard") CNpcFireballHazard;
break;
}
2001-05-22 21:59:56 +02:00
case NPC_ROLLING_ROCK_HAZARD:
{
hazard = new ("rolling rock hazard") CNpcRollingRockHazard;
break;
}
2001-05-23 00:01:43 +02:00
case NPC_FLY_TRAP_HAZARD:
{
hazard = new ("fly trap hazard") CNpcFlyTrapHazard;
break;
}
2001-05-23 20:45:27 +02:00
case NPC_RISING_WEIGHT_HAZARD:
{
hazard = new ("rising weight hazard") CNpcRisingWeightHazard;
break;
}
case NPC_RISING_WEIGHT_WHEEL_HAZARD:
{
hazard = new ("rising weight wheel hazard") CNpcRisingWeightWheelHazard;
break;
}
2001-05-24 01:16:43 +02:00
case NPC_PRESSURE_SWITCH_HAZARD:
{
hazard = new ("pressure switch hazard") CNpcPressureSwitchHazard;
break;
}
2001-05-24 17:18:25 +02:00
case NPC_ROCKSHARD_HAZARD:
{
hazard = new ("rock shard hazard") CNpcRockShardHazard;
break;
}
2001-05-31 17:43:13 +02:00
case NPC_INERT_HAZARD:
{
hazard = new ("inert hazard") CNpcInertHazard;
break;
}
2001-06-04 21:01:17 +02:00
case NPC_CONVEYOR_SWITCH_HAZARD:
{
hazard = new ("conveyor switch hazard") CNpcConveyorSwitchHazard;
break;
}
2001-06-05 18:01:22 +02:00
case NPC_BOUNCING_ROCK_HAZARD:
{
hazard = new ("bouncing rock hazard") CNpcBouncingRockHazard;
break;
}
2001-06-14 23:27:25 +02:00
case NPC_SWORDFISH_HAZARD:
{
hazard = new ("swordfish hazard") CNpcSwordfishHazard;
break;
}
case NPC_LOG_HAZARD:
{
hazard = new ("log hazard") CNpcLogHazard;
break;
}
2001-07-17 22:15:28 +02:00
case NPC_CHECKPOINT_HAZARD:
{
hazard = new ("checkpoint hazard") CNpcCheckpointHazard;
break;
}
2001-05-01 15:28:11 +02:00
default:
{
hazard = NULL;
break;
}
}
ASSERT( hazard );
2001-05-25 20:43:47 +02:00
hazard->setThingSubType(Type);
2001-05-01 15:28:11 +02:00
hazard->init();
2001-05-29 21:19:14 +02:00
return( hazard );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CNpcHazard *CNpcHazard::Create(sThingHazard *ThisHazard)
{
NPC_HAZARD_UNIT_TYPE Type = getTypeFromMapEdit( ThisHazard->Type );
CNpcHazard *hazard=Create(ThisHazard->Type);
2001-05-01 15:28:11 +02:00
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-30 00:07:28 +02:00
m_npcPath.setWaypointCount( ThisHazard->PointCount - 1 );
2001-05-01 15:28:11 +02:00
newXPos = (u16) *PntList;
2001-05-30 00:07:28 +02:00
setWaypointPtr( PntList );
2001-05-01 15:28:11 +02:00
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
2001-05-31 18:24:48 +02:00
startPos.vx = ( newXPos << 4 ) + 8;
startPos.vy = ( newYPos << 4 ) + 16;
2001-05-01 15:28:11 +02:00
Pos = startPos;
2001-04-24 17:01:42 +02:00
m_base = Pos;
2001-06-19 22:07:57 +02:00
s32 minX, maxX, minY, maxY;
m_npcPath.getPathXExtents( &minX, &maxX );
m_npcPath.getPathYExtents( &minY, &maxY );
m_thinkArea.x1 = minX;
m_thinkArea.x2 = maxX;
m_thinkArea.y1 = minY;
m_thinkArea.y2 = maxY;
2001-05-01 15:28:11 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CNpcHazard::NPC_HAZARD_UNIT_TYPE CNpcHazard::getTypeFromMapEdit( u16 newType )
{
return( mapEditConvertTable[newType] );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcHazard::init()
{
CHazardThing::init();
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
2001-06-18 21:06:43 +02:00
m_soundId = (int) NOT_PLAYING;
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-06-18 21:06:43 +02:00
if ( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
2001-05-01 15:28:11 +02:00
delete m_modelGfx;
2001-04-24 15:24:26 +02:00
2001-05-01 15:28:11 +02:00
//if (m_actorGfx) delete m_actorGfx;
2001-04-24 15:24:26 +02:00
CHazardThing::shutdown();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-06-18 21:06:43 +02:00
void CNpcHazard::leftThinkZone(int _frames)
{
if ( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
m_soundId = NOT_PLAYING;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 15:24:26 +02:00
void CNpcHazard::think(int _frames)
{
2001-06-18 21:06:43 +02:00
if ( m_soundId != NOT_PLAYING )
{
if( !CSoundMediator::isSfxStillPlaying( (xmPlayingId) m_soundId ) )
{
// unlock sound if it has finished
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
m_soundId = NOT_PLAYING;
}
}
2001-04-24 15:24:26 +02:00
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();
2001-05-14 23:08:03 +02:00
if (canRender())
2001-04-24 15:24:26 +02:00
{
2001-05-14 23:08:03 +02:00
DVECTOR &renderPos=getRenderPos();
m_modelGfx->Render(renderPos);
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:
break;
}
}
}