SBSPSS/source/friend/friend.cpp

287 lines
5.9 KiB
C++
Raw Normal View History

2001-04-27 16:39:10 +02:00
/*=========================================================================
friend.cpp
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
#ifndef __FRIEND_FRIEND_H__
#include "friend\friend.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-04-27 21:20:49 +02:00
#ifndef __FRIEND_FBBOY_H__
#include "friend\fbboy.h"
#endif
#ifndef __FRIEND_FGARY_H__
#include "friend\fgary.h"
#endif
#ifndef __FRIEND_FKRUSTY_H__
#include "friend\fkrusty.h"
#endif
#ifndef __FRIEND_FMMAN_H__
#include "friend\fmman.h"
#endif
#ifndef __FRIEND_FPATRICK_H__
#include "friend\fpatrick.h"
#endif
#ifndef __FRIEND_FSANDY_H__
#include "friend\fsandy.h"
#endif
2001-04-27 17:09:10 +02:00
#ifndef __FRIEND_FSQUID_H__
#include "friend\fsquid.h"
#endif
2001-05-03 15:11:45 +02:00
#ifndef __FRIEND_FPLNKTON_H__
#include "friend\fplnkton.h"
#endif
2001-04-27 16:39:10 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Friend NPCs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CNpcFriend *CNpcFriend::Create(sThingActor *ThisActor)
{
CNpcFriend *friendNpc;
NPC_FRIEND_UNIT_TYPE friendType = CNpcFriend::getTypeFromMapEdit( ThisActor->Type );
switch( friendType )
{
2001-04-27 21:20:49 +02:00
case CNpcFriend::NPC_FRIEND_BARNACLE_BOY:
{
friendNpc = new ("barnacle boy") CNpcBarnacleBoyFriend;
break;
}
case CNpcFriend::NPC_FRIEND_GARY:
{
friendNpc = new ("gary") CNpcGaryFriend;
break;
}
case CNpcFriend::NPC_FRIEND_KRUSTY:
{
friendNpc = new ("krusty") CNpcKrustyFriend;
break;
}
case CNpcFriend::NPC_FRIEND_MERMAID_MAN:
{
friendNpc = new ("mermaid man") CNpcMermaidManFriend;
break;
}
case CNpcFriend::NPC_FRIEND_PATRICK:
{
friendNpc = new ("patrick") CNpcPatrickFriend;
break;
}
case CNpcFriend::NPC_FRIEND_SANDY_CHEEKS:
{
friendNpc = new ("sandy cheeks") CNpcSandyFriend;
break;
}
2001-04-27 16:39:10 +02:00
case CNpcFriend::NPC_FRIEND_SQUIDWARD:
{
2001-04-27 17:09:10 +02:00
friendNpc = new ("squidward") CNpcSquidwardFriend;
2001-04-27 16:39:10 +02:00
break;
}
2001-05-03 15:11:45 +02:00
case CNpcFriend::NPC_FRIEND_PLANKTON:
{
friendNpc = new ("plankton") CNpcPlanktonFriend;
break;
}
2001-04-27 16:39:10 +02:00
default:
{
printf("UNKNOWN %i\n",friendType);
friendNpc = NULL;
ASSERT(0);
break;
}
}
ASSERT( friendNpc );
friendNpc->setType( friendType );
u16 *PntList=(u16*)MakePtr(ThisActor,sizeof(sThingActor));
u16 newXPos, newYPos;
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
DVECTOR startPos;
startPos.vx = newXPos << 4;
2001-04-27 21:54:38 +02:00
startPos.vy = ( newYPos + 1 ) << 4;
2001-04-27 16:39:10 +02:00
friendNpc->init( startPos );
return( friendNpc );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CNpcFriend::NPC_FRIEND_UNIT_TYPE CNpcFriend::getTypeFromMapEdit( u16 newType )
{
return( mapEditConvertTable[newType - NPC_FRIEND_MAPEDIT_OFFSET] );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::init()
{
CNpcThing::init();
m_extension = EXTEND_RIGHT;
m_actorGfx = CActorPool::GetActor( (FileEquate) m_data[m_type].skelType );
2001-04-27 17:09:10 +02:00
m_animPlaying = true;
m_animNo = m_data[m_type].idleAnim;
2001-04-27 16:39:10 +02:00
m_frame = 0;
m_reversed = false;
DVECTOR ofs = getCollisionSize();
m_drawOffset.vx = 0;
m_drawOffset.vy = -( ofs.vy >> 1 );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::init( DVECTOR initPos )
{
init();
Pos = initPos;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-03 00:49:59 +02:00
void CNpcFriend::postInit()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-27 16:39:10 +02:00
void CNpcFriend::shutdown()
{
//m_spriteBank->dump(); delete m_spriteBank;
delete m_actorGfx;
CNpcThing::shutdown();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::think(int _frames)
{
CNpcThing::think(_frames);
2001-04-27 17:09:10 +02:00
if ( m_animPlaying )
2001-04-27 16:39:10 +02:00
{
2001-04-27 17:09:10 +02:00
s32 frameCount;
2001-04-27 16:39:10 +02:00
2001-04-27 17:09:10 +02:00
frameCount = m_actorGfx->getFrameCount( m_animNo );
2001-04-27 16:39:10 +02:00
2001-04-27 17:09:10 +02:00
s32 frameShift = ( _frames << 8 ) >> 1;
if ( ( frameCount << 8 ) - m_frame > frameShift )
{
m_frame += frameShift;
}
else
{
m_frame = ( frameCount - 1 ) << 8;
m_animPlaying = false;
}
}
else
{
2001-04-27 21:54:38 +02:00
m_animNo = m_data[m_type].idleAnim;
m_animPlaying = true;
m_frame = 0;
2001-04-27 16:39:10 +02:00
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcFriend::render()
{
CNpcThing::render();
2001-05-10 18:16:57 +02:00
// Render
2001-04-27 16:39:10 +02:00
2001-05-10 18:16:57 +02:00
if (canRender())
2001-04-27 16:39:10 +02:00
{
2001-05-10 18:16:57 +02:00
DVECTOR &renderPos=getRenderPos();
2001-04-27 20:30:19 +02:00
2001-05-10 18:16:57 +02:00
m_actorGfx->Render(renderPos,m_animNo,(m_frame>>8),m_reversed);
sBBox boundingBox = m_actorGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
2001-04-27 16:39:10 +02:00
}
2001-05-10 18:16:57 +02:00
2001-04-27 16:39:10 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-02 00:06:59 +02:00
void CNpcFriend::collidedWith( CThing *_thisThing )
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
CPlayer *player = (CPlayer *) _thisThing;
if ( player->isTryingToConversateWithFriend() )
{
startConderversation();
}
break;
}
default:
ASSERT(0);
break;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-01 23:05:14 +02:00
void CNpcFriend::startConderversation()
2001-04-27 16:39:10 +02:00
{
2001-05-01 23:05:14 +02:00
// I am 'avin a fayg
}