SBSPSS/source/enemy/nclam.cpp

389 lines
8.3 KiB
C++
Raw Normal View History

2001-01-18 22:18:53 +01:00
/*=========================================================================
nclam.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
2001-04-20 16:48:15 +02:00
#ifndef __ENEMY_NCLAM_H__
#include "enemy\nclam.h"
#endif
2001-05-15 18:31:29 +02:00
#ifndef __PLATFORM_PLATFORM_H__
#include "platform\platform.h"
#endif
2001-07-23 16:16:26 +02:00
#ifndef __PLATFORM_PCLAM_H__
#include "platform\pclam.h"
#endif
2001-01-18 22:18:53 +01:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-04-20 16:48:15 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-02-28 22:05:39 +01:00
#ifndef __ANIM_CLAM_HEADER__
#include <ACTOR_CLAM_ANIM.h>
#endif
2001-01-18 22:18:53 +01:00
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-24 21:03:06 +02:00
void CNpcClamEnemy::processEnemyCollision( CThing *thisThing )
{
// do nothing
}
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-14 17:19:07 +02:00
void CNpcClamEnemy::processUserCollision( CThing *thisThing )
{
// do nothing
}
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 16:48:15 +02:00
bool CNpcClamEnemy::processSensor()
{
switch( m_sensorFunc )
{
case NPC_SENSOR_NONE:
return( false );
default:
{
2001-07-17 16:44:00 +02:00
if ( playerXDistSqr + playerYDistSqr < 40000 )
2001-04-20 16:48:15 +02:00
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_extendDir = EXTEND_UP;
m_extension = 0;
2001-06-18 21:06:43 +02:00
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_MOVE, true );
}
2001-05-21 23:16:42 +02:00
2001-04-20 16:48:15 +02:00
return( true );
}
else
{
return( false );
}
}
}
}
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-26 17:20:21 +02:00
void CNpcJumpingClamEnemy::postInit()
{
CNpcClamEnemy::postInit();
2001-06-07 16:39:53 +02:00
m_drawRotation = ( m_heading + 1024 ) & 4095;
2001-04-26 17:20:21 +02:00
}
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-22 17:55:04 +02:00
void CNpcJumpingClamEnemy::setupWaypoints( sThingActor *ThisActor )
{
u16 *PntList=(u16*)MakePtr(ThisActor,sizeof(sThingActor));
u16 newXPos, newYPos;
u16 startXPos, startYPos, endXPos, endYPos;
2001-05-30 00:07:28 +02:00
m_npcPath.setWaypointCount( ThisActor->PointCount - 1 );
2001-05-22 17:55:04 +02:00
startXPos = newXPos = (u16) *PntList;
2001-05-30 00:07:28 +02:00
setWaypointPtr( PntList );
2001-05-22 17:55:04 +02:00
PntList++;
startYPos = newYPos = (u16) *PntList;
PntList++;
setStartPos( newXPos, newYPos );
m_maxExtension = 10;
if ( ThisActor->PointCount > 1 )
{
2001-05-30 00:07:28 +02:00
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
2001-05-22 17:55:04 +02:00
2001-05-30 00:07:28 +02:00
endXPos = newXPos;
endYPos = newYPos;
2001-05-22 17:55:04 +02:00
2001-07-27 15:31:52 +02:00
setHeading( newXPos, newYPos, startXPos, startYPos );
2001-05-22 17:55:04 +02:00
2001-05-30 00:07:28 +02:00
s32 xDist = ( endXPos - startXPos ) << 4;
s32 yDist = ( endYPos - startYPos ) << 4;
2001-05-22 17:55:04 +02:00
2001-05-30 00:07:28 +02:00
m_maxExtension = isqrt2( ( xDist * xDist ) + ( yDist * yDist ) );
2001-05-22 17:55:04 +02:00
}
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-22 17:55:04 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 16:48:15 +02:00
void CNpcJumpingClamEnemy::processClose( int _frames )
2001-01-18 22:18:53 +01:00
{
s32 velocity;
2001-01-19 22:46:30 +01:00
if ( m_extendDir == EXTEND_UP )
2001-05-22 17:55:04 +02:00
{
velocity = m_speed * _frames;
m_extension += velocity;
if ( m_extension > m_maxExtension )
{
m_extension = m_maxExtension;
m_extendDir = EXTEND_DOWN;
}
Pos = m_base;
Pos.vx += ( m_extension * rcos( m_heading ) ) >> 12;
Pos.vy += ( m_extension * rsin( m_heading ) ) >> 12;
if ( !m_animPlaying )
{
m_animPlaying = true;
2001-06-07 16:39:53 +02:00
m_animNo = ANIM_CLAM_SNAPUP;
2001-05-22 17:55:04 +02:00
m_frame = 0;
}
}
else if ( m_extendDir == EXTEND_DOWN )
{
velocity = -_frames;
m_extension += velocity;
if ( m_extension < 0 )
{
m_extension = 0;
if ( !m_animPlaying )
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
}
}
Pos = m_base;
Pos.vx += ( m_extension * rcos( m_heading ) ) >> 12;
Pos.vy += ( m_extension * rsin( m_heading ) ) >> 12;
}
2001-02-06 22:25:25 +01:00
}
2001-03-01 17:48:45 +01:00
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-25 17:10:26 +02:00
void CNpcStaticClamEnemy::postInit()
{
CNpcClamEnemy::postInit();
2001-05-22 20:11:57 +02:00
m_isStunned = 0;
2001-05-15 21:08:14 +02:00
// create platform in same place
2001-06-14 18:07:48 +02:00
CNpcPlatform *platform;
platform = CNpcPlatform::Create( CNpcPlatform::NPC_CLAM_PLATFORM );
2001-05-15 21:08:14 +02:00
2001-06-14 18:07:48 +02:00
platform->setThingSubType(CNpcPlatform::NPC_CLAM_PLATFORM);
2001-05-15 21:08:14 +02:00
platform->setGraphic( (u8) 0 );
platform->init( Pos );
platform->setTiltable( false );
2001-05-21 17:30:48 +02:00
platform->postInit();
2001-05-21 23:16:42 +02:00
2001-07-23 16:16:26 +02:00
CNpcClamPlatform *clamPlatform;
clamPlatform = (CNpcClamPlatform *) platform;
clamPlatform->setClam( this );
2001-05-21 23:16:42 +02:00
m_animPlaying = false;
2001-04-25 17:10:26 +02:00
}
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-07-23 16:16:26 +02:00
void CNpcStaticClamEnemy::stoodOn()
2001-03-01 17:48:45 +01:00
{
2001-07-23 16:16:26 +02:00
if ( m_frame < ( 5 << 8 ) )
2001-03-01 17:48:45 +01:00
{
2001-07-23 16:16:26 +02:00
if ( m_frame != 0 )
{
m_frame = 0;
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_ATTACK, true );
}
}
2001-05-21 23:16:42 +02:00
2001-07-23 16:16:26 +02:00
m_isStunned = 2 * GameState::getOneSecondInFrames();
m_animPlaying = false;
2001-05-21 23:16:42 +02:00
}
2001-07-23 16:16:26 +02:00
else
{
m_oldControlFunc = m_controlFunc;
m_controlFunc = NPC_CONTROL_COLLISION;
}
}
2001-05-15 21:08:14 +02:00
2001-07-23 16:16:26 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcStaticClamEnemy::think( int _frames )
{
2001-05-21 21:18:35 +02:00
if ( m_isStunned )
{
2001-05-22 20:11:57 +02:00
m_isStunned -= _frames;
if ( m_isStunned < 0 )
{
m_isStunned = 0;
2001-07-23 16:16:26 +02:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_movementTimer = GameState::getOneSecondInFrames();
2001-05-22 20:11:57 +02:00
}
}
2001-07-23 16:16:26 +02:00
CNpcEnemy::think( _frames );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcStaticClamEnemy::processMovement( int _frames )
{
if ( !m_animPlaying && m_isStunned == 0 )
2001-05-22 20:11:57 +02:00
{
2001-07-23 16:16:26 +02:00
if ( m_movementTimer > 0 )
{
m_movementTimer -= _frames;
}
else
{
m_animPlaying = true;
m_animNo = ANIM_CLAM_SIDESNAP;
m_movementTimer = GameState::getOneSecondInFrames();
}
2001-05-21 21:18:35 +02:00
}
2001-04-25 17:10:26 +02:00
}
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-25 17:10:26 +02:00
void CNpcStaticClamEnemy::collidedWith( CThing *_thisThing )
{
2001-05-15 21:08:14 +02:00
if ( m_isActive && !m_isCaught && !m_isDying )
2001-04-25 17:10:26 +02:00
{
2001-05-15 21:08:14 +02:00
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
2001-07-23 16:16:26 +02:00
CPlayer *player = (CPlayer *) _thisThing;
if ( m_isStunned <= 0 )
2001-05-21 21:18:35 +02:00
{
2001-07-23 16:16:26 +02:00
if ( !player->isRecoveringFromHit() )
2001-05-21 23:16:42 +02:00
{
2001-07-25 17:13:10 +02:00
if ( m_frame >= ( 5 << 8 ) )
2001-06-18 21:06:43 +02:00
{
2001-07-31 21:20:19 +02:00
if ( m_controlFunc != NPC_CONTROL_COLLISION )
{
m_oldControlFunc = m_controlFunc;
m_controlFunc = NPC_CONTROL_COLLISION;
}
2001-06-18 21:06:43 +02:00
}
2001-05-21 23:16:42 +02:00
}
2001-05-21 21:18:35 +02:00
}
2001-05-15 21:08:14 +02:00
break;
}
default:
break;
}
2001-04-25 17:10:26 +02:00
}
}
2001-05-21 21:18:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcStaticClamEnemy::processCollision()
{
CPlayer *player = GameScene.getPlayer();
player->takeDamage( m_data[m_type].damageToUserType,REACT__GET_DIRECTION_FROM_THING,(CThing*)this );
processUserCollision( (CThing *) player );
m_controlFunc = m_oldControlFunc;
2001-05-22 20:11:57 +02:00
if ( !m_animPlaying && m_isStunned == 0 )
2001-05-21 21:18:35 +02:00
{
m_animPlaying = true;
m_animNo = ANIM_CLAM_SIDESNAP;
m_frame = 0;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
s32 CNpcStaticClamEnemy::getFrameShift( int _frames )
{
return( ( _frames << 8 ) >> 2 );
}
2001-05-21 23:16:42 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcStaticClamEnemy::processAnimFrames( int _frames )
{
2001-06-01 21:53:49 +02:00
if ( m_animPlaying && ( ( m_isDying && m_data[m_type].playDeathAnim ) || !m_isDying ) )
2001-05-21 23:16:42 +02:00
{
s32 frameCount;
frameCount = getFrameCount();
s32 frameShift = getFrameShift( _frames );
if ( ( frameCount << 8 ) - m_frame > frameShift )
{
m_frame += frameShift;
}
else
{
m_frame = 0;
m_animPlaying = false;
2001-06-18 21:06:43 +02:00
if ( m_soundId == NOT_PLAYING )
{
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_CLAM_ATTACK, true );
}
2001-05-21 23:16:42 +02:00
}
}
}