2001-05-23 20:43:44 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
hrweight.cpp
|
|
|
|
|
|
|
|
Author: CRB
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
#ifndef __HAZARD_HRWEIGHT_H__
|
|
|
|
#include "hazard\hrweight.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-31 19:58:55 +02:00
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
|
|
|
#endif
|
|
|
|
|
2001-07-09 21:38:58 +02:00
|
|
|
#ifndef __FRIEND_FRIEND_H__
|
|
|
|
#include "friend\friend.h"
|
|
|
|
#endif
|
|
|
|
|
2001-07-26 21:12:49 +02:00
|
|
|
#ifndef __GFX_OTPOS_H__
|
|
|
|
#include "gfx\otpos.h"
|
|
|
|
#endif
|
2001-05-23 20:43:44 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightHazard::init()
|
|
|
|
{
|
|
|
|
CNpcHazard::init();
|
|
|
|
|
|
|
|
m_triggered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightHazard::setWaypoints( sThingHazard *ThisHazard )
|
|
|
|
{
|
2001-06-01 16:30:03 +02:00
|
|
|
ASSERT( ThisHazard->PointCount >= 3 );
|
2001-05-23 20:43:44 +02:00
|
|
|
|
|
|
|
u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard));
|
|
|
|
|
|
|
|
u16 newXPos, newYPos;
|
|
|
|
|
|
|
|
// get master hazard init pos
|
|
|
|
|
|
|
|
newXPos = (u16) *PntList;
|
|
|
|
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-23 20:43:44 +02:00
|
|
|
|
|
|
|
Pos = startPos;
|
|
|
|
m_base = Pos;
|
|
|
|
|
|
|
|
// get master hazard max vertical extension
|
|
|
|
|
|
|
|
newXPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
newYPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
|
2001-05-31 18:24:48 +02:00
|
|
|
m_maxExtension = abs( ( ( newYPos << 4 ) + 16 ) - startPos.vy ) << 8;
|
2001-05-23 20:43:44 +02:00
|
|
|
|
|
|
|
// get slave trigger position
|
|
|
|
|
|
|
|
newXPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
newYPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
|
|
|
|
m_wheelPos.vx = newXPos;
|
|
|
|
m_wheelPos.vy = newYPos;
|
2001-06-01 16:30:03 +02:00
|
|
|
|
|
|
|
if ( ThisHazard->PointCount > 3 )
|
|
|
|
{
|
|
|
|
newXPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
newYPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
|
|
|
|
m_pulleyPos.vx = ( newXPos << 4 ) + 8;
|
|
|
|
m_pulleyPos.vy = ( newYPos << 4 ) + 16;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pulleyPos.vx = startPos.vx;
|
|
|
|
m_pulleyPos.vy = startPos.vy - ( m_maxExtension >> 8 );
|
|
|
|
}
|
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-23 20:43:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightHazard::processMovement( int _frames )
|
|
|
|
{
|
|
|
|
if ( m_triggered )
|
|
|
|
{
|
|
|
|
m_triggered = false;
|
2001-08-08 17:43:07 +02:00
|
|
|
m_extension += ( 16 * _frames ) << 8;
|
2001-05-23 20:43:44 +02:00
|
|
|
if ( m_extension > m_maxExtension )
|
|
|
|
{
|
|
|
|
m_extension = m_maxExtension;
|
|
|
|
}
|
2001-07-24 22:35:40 +02:00
|
|
|
else
|
|
|
|
{
|
2001-07-26 17:45:30 +02:00
|
|
|
if ( canRender() && m_soundId == NOT_PLAYING )
|
2001-07-24 22:35:40 +02:00
|
|
|
{
|
|
|
|
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_PULLEY, true, true );
|
|
|
|
}
|
|
|
|
}
|
2001-05-23 20:43:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_extension -= 64 * _frames;
|
|
|
|
|
|
|
|
if ( m_extension < 0 )
|
|
|
|
{
|
|
|
|
m_extension = 0;
|
|
|
|
}
|
2001-07-24 22:35:40 +02:00
|
|
|
else
|
|
|
|
{
|
2001-07-26 17:45:30 +02:00
|
|
|
if ( canRender() && m_soundId == NOT_PLAYING )
|
2001-07-24 22:35:40 +02:00
|
|
|
{
|
|
|
|
m_soundId = (int) CSoundMediator::playSfx( CSoundMediator::SFX_PULLEY, true, true );
|
|
|
|
}
|
2001-08-08 17:43:07 +02:00
|
|
|
|
|
|
|
m_wheel->weightDrop();
|
2001-07-24 22:35:40 +02:00
|
|
|
}
|
2001-05-23 20:43:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Pos.vy = m_base.vy - ( m_extension >> 8 );
|
|
|
|
}
|
2001-05-31 19:58:55 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightHazard::render()
|
|
|
|
{
|
|
|
|
int x1,y1,x2,y2;
|
2001-06-01 16:30:03 +02:00
|
|
|
int minX, maxX, minY, maxY;
|
2001-05-31 19:58:55 +02:00
|
|
|
|
2001-07-23 21:26:37 +02:00
|
|
|
DVECTOR const &offset = CLevel::getCameraPos();
|
2001-05-31 19:58:55 +02:00
|
|
|
|
|
|
|
if ( m_isActive )
|
|
|
|
{
|
|
|
|
CHazardThing::render();
|
|
|
|
|
|
|
|
if (canRender())
|
|
|
|
{
|
|
|
|
DVECTOR &renderPos=getRenderPos();
|
|
|
|
|
|
|
|
m_modelGfx->Render(renderPos);
|
|
|
|
}
|
|
|
|
|
2001-06-01 16:30:03 +02:00
|
|
|
x1 = m_base.vx - offset.vx;
|
|
|
|
x2 = m_pulleyPos.vx - offset.vx;
|
|
|
|
y1 = m_pulleyPos.vy - offset.vy;
|
2001-05-31 19:58:55 +02:00
|
|
|
y2 = Pos.vy - offset.vy;
|
|
|
|
|
2001-06-01 16:30:03 +02:00
|
|
|
minX = x1;
|
|
|
|
maxX = x2;
|
|
|
|
|
|
|
|
if ( minX > maxX )
|
|
|
|
{
|
|
|
|
minX = x2;
|
|
|
|
maxX = x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
minY = y1;
|
|
|
|
maxY = y2;
|
|
|
|
|
|
|
|
if ( minY > maxY )
|
2001-05-31 19:58:55 +02:00
|
|
|
{
|
2001-06-01 16:30:03 +02:00
|
|
|
minY = y2;
|
|
|
|
maxY = y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( maxX >= 0 && minX <= VidGetScrW() )
|
|
|
|
{
|
|
|
|
if ( maxY >= 0 && minY <= VidGetScrH() )
|
2001-05-31 19:58:55 +02:00
|
|
|
{
|
2001-07-26 21:12:49 +02:00
|
|
|
DrawLine( x1, y1, x2, y2, 0, 0, 0, OTPOS__ACTOR_POS+1 );
|
2001-05-31 19:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x1 = ( m_wheelPos.vx << 4 ) + 8 - offset.vx;
|
2001-06-01 16:30:03 +02:00
|
|
|
x2 = m_pulleyPos.vx - offset.vx;
|
2001-05-31 19:58:55 +02:00
|
|
|
y1 = ( m_wheelPos.vy << 4 ) + 16 - offset.vy;
|
2001-06-01 16:30:03 +02:00
|
|
|
y2 = m_pulleyPos.vy - offset.vy;
|
|
|
|
|
|
|
|
minX = x1;
|
|
|
|
maxX = x2;
|
|
|
|
|
|
|
|
if ( minX > maxX )
|
|
|
|
{
|
|
|
|
minX = x2;
|
|
|
|
maxX = x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
minY = y1;
|
|
|
|
maxY = y2;
|
|
|
|
|
|
|
|
if ( minY > maxY )
|
|
|
|
{
|
|
|
|
minY = y2;
|
|
|
|
maxY = y1;
|
|
|
|
}
|
2001-05-31 19:58:55 +02:00
|
|
|
|
2001-06-01 16:30:03 +02:00
|
|
|
if ( maxX >= 0 && minX <= VidGetScrW() )
|
2001-05-31 19:58:55 +02:00
|
|
|
{
|
2001-06-01 16:30:03 +02:00
|
|
|
if ( maxY >= 0 && minY <= VidGetScrH() )
|
2001-05-31 19:58:55 +02:00
|
|
|
{
|
2001-07-26 21:12:49 +02:00
|
|
|
DrawLine( x1, y1, x2, y2, 0, 0, 0, OTPOS__ACTOR_POS+1 );
|
2001-05-31 19:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-07-09 21:38:58 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightHazard::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_NPC:
|
|
|
|
{
|
|
|
|
CNpcFriend *npcFriend = (CNpcFriend *) _thisThing;
|
|
|
|
|
|
|
|
npcFriend->setObstructed();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-08-08 17:43:07 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightWheelHazard::init()
|
|
|
|
{
|
|
|
|
CNpcHazard::init();
|
|
|
|
|
|
|
|
m_rotation = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightWheelHazard::setWaypoints( sThingHazard *ThisHazard )
|
|
|
|
{
|
|
|
|
u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard));
|
|
|
|
|
|
|
|
u16 newXPos, newYPos;
|
|
|
|
|
|
|
|
// get init pos
|
|
|
|
|
|
|
|
newXPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
newYPos = (u16) *PntList;
|
|
|
|
PntList++;
|
|
|
|
|
|
|
|
DVECTOR startPos;
|
|
|
|
startPos.vx = ( newXPos << 4 ) + 8;
|
|
|
|
startPos.vy = ( newYPos << 4 ) + 16;
|
|
|
|
|
|
|
|
Pos = startPos;
|
|
|
|
m_base = Pos;
|
|
|
|
|
|
|
|
m_wheelPos.vx = newXPos;
|
|
|
|
m_wheelPos.vy = newYPos;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightWheelHazard::collidedWith( CThing *_thisThing )
|
|
|
|
{
|
|
|
|
if ( m_isActive )
|
|
|
|
{
|
|
|
|
switch(_thisThing->getThingType())
|
|
|
|
{
|
|
|
|
case TYPE_PLAYER:
|
|
|
|
{
|
|
|
|
CPlayer *player = (CPlayer *) _thisThing;
|
|
|
|
|
|
|
|
ATTACK_STATE playerState = player->getAttackState();
|
|
|
|
|
|
|
|
if ( playerState == ATTACK_STATE__BUTT_BOUNCE )
|
|
|
|
{
|
|
|
|
m_weight->setTriggered();
|
|
|
|
|
|
|
|
m_rotation += 256;
|
|
|
|
m_rotation &= 4095;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_PLAYERPROJECTILE:
|
|
|
|
{
|
|
|
|
m_weight->setTriggered();
|
|
|
|
|
|
|
|
m_rotation += 256;
|
|
|
|
m_rotation &= 4095;
|
|
|
|
|
|
|
|
_thisThing->setToShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightWheelHazard::weightDrop()
|
|
|
|
{
|
|
|
|
m_rotation -= 128;
|
|
|
|
m_rotation &= 4095;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CNpcRisingWeightWheelHazard::render()
|
|
|
|
{
|
|
|
|
CHazardThing::render();
|
|
|
|
|
|
|
|
if (canRender())
|
|
|
|
{
|
|
|
|
DVECTOR &renderPos=getRenderPos();
|
|
|
|
|
|
|
|
SVECTOR rotation;
|
|
|
|
rotation.vx = 0;
|
|
|
|
rotation.vy = 0;
|
|
|
|
rotation.vz = m_rotation;
|
|
|
|
|
|
|
|
VECTOR scale;
|
|
|
|
scale.vx = ONE;
|
|
|
|
scale.vy = ONE;
|
|
|
|
scale.vz = ONE;
|
|
|
|
|
|
|
|
m_modelGfx->Render(renderPos,&rotation,&scale);
|
|
|
|
}
|
|
|
|
}
|