SBSPSS/source/game/convo.cpp

431 lines
10 KiB
C++
Raw Normal View History

2001-01-05 22:43:21 +01:00
/*=========================================================================
convo.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "game\convo.h"
2001-01-10 18:27:12 +01:00
#ifndef __MEMORY_HEADER__
#include "mem\memory.h"
#endif
#ifndef __GUI_GFRAME_H__
#include "gui\gframe.h"
#endif
#ifndef __GUI_GSPRITE_H__
#include "gui\gsprite.h"
#endif
#ifndef __GUI_GTEXTBOX_H__
#include "gui\gtextbox.h"
#endif
#ifndef __GFX_SPRBANK_H__
#include "gfx\sprbank.h"
#endif
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
#ifndef __SCRIPT_SCRIPT_H__
#include "script\script.h"
#endif
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
2001-01-05 22:43:21 +01:00
/* Std Lib
------- */
/* Data
---- */
2001-04-20 16:53:35 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
2001-01-10 18:27:12 +01:00
#endif
#ifndef __STRING_ENUMS__
#include <trans.h>
#endif
2001-01-05 22:43:21 +01:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-01-10 18:27:12 +01:00
CConversation::CHAR_ICON_FRAMES CConversation::s_characterIconFrames[]=
{
2001-01-11 22:54:44 +01:00
{ FRM_SPONGEBOB, }, // CHAR_SPONGEBOB
{ FRM_SANDY }, // CHAR_SANDY
{ FRM_PATRICK }, // CHAR_PATRICK
{ FRM_SQUIDWARD }, // CHAR_SQUIDWARD
{ FRM_MR_KRABS }, // CHAR_KRABS
{ FRM_PLANKTON }, // CHAR_PLANKTON
{ FRM_MERMAIDMAN }, // CHAR_MERMAIDMAN,
{ FRM_BARNACLEBOY }, // CHAR_BARNACLEBOY,
{ FRM_JACK_CUSTARD }, // CHAR_JACKCUSTARD
2001-01-10 18:27:12 +01:00
};
class CGUIGroupFrame *CConversation::s_guiFrame=NULL;
class CGUISprite *CConversation::s_guiIcon=NULL;
class CGUITextBox *CConversation::s_guiText=NULL;
2001-01-22 21:57:39 +01:00
class FontBank *CConversation::s_fontBank=NULL;
2001-01-23 22:05:48 +01:00
class CScript *CConversation::s_registeredScripts[MAX_LOADED_SCRIPTS];
int CConversation::s_registeredScriptIds[MAX_LOADED_SCRIPTS];
int CConversation::s_numRegisteredScripts=0;
2001-01-22 21:57:39 +01:00
class CScript *CConversation::s_currentScript=NULL;
int CConversation::s_currentState=STATE_INACTIVE;
2001-01-10 18:27:12 +01:00
int CConversation::s_currentCharacterId=-1;
int CConversation::s_currentTextId=-1;
int CConversation::s_currentQuestion=QUESTION_NONE;
int CConversation::s_currentAnswer=ANSWER_NONE;
int CConversation::s_currentSelectedAnswer=0;
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::init()
{
2001-01-23 22:05:48 +01:00
ASSERT(s_numRegisteredScripts==0);
2001-01-10 18:27:12 +01:00
s_guiFrame=new ("Conversation GUI") CGUIGroupFrame();
s_guiFrame->init(0);
s_guiFrame->setObjectXYWH((512-FRAME_WIDTH)/2,256-FRAME_BOTTOM_OFFSET-FRAME_HEIGHT,FRAME_WIDTH,FRAME_HEIGHT);
s_guiFrame->setOt(OT_POS);
s_guiFrame->setFlags(CGUIObject::FLAG_DRAWBORDER);
s_guiIcon=new("Conversation Icon") CGUISprite();
s_guiIcon->init(s_guiFrame);
s_guiIcon->setObjectXYWH(0,0,FRAME_HEIGHT,FRAME_HEIGHT);
s_guiIcon->setOt(OT_POS);
2001-04-20 16:53:35 +02:00
s_guiIcon->setSpriteBank(SPRITES_SPRITES_SPR);
2001-01-10 18:27:12 +01:00
s_guiIcon->setFrame(0);
s_guiText=new("Conversation Text") CGUITextBox();
s_guiText->init(s_guiFrame);
s_guiText->setObjectXYWH(FRAME_HEIGHT,TEXT_BORDER,FRAME_WIDTH-FRAME_HEIGHT-TEXT_BORDER,FRAME_HEIGHT-(TEXT_BORDER*2));
s_guiText->setOt(OT_POS);
2001-01-22 21:57:39 +01:00
s_fontBank=new ("Conversation Font") FontBank();
s_fontBank->initialise(&standardFont);
s_fontBank->setOt(0);
2001-01-10 18:27:12 +01:00
2001-01-22 21:57:39 +01:00
s_currentState=STATE_INACTIVE;
2001-01-23 22:05:48 +01:00
s_currentScript=NULL;
2001-01-10 18:27:12 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::shutdown()
{
2001-02-09 18:31:20 +01:00
s_fontBank->dump(); delete s_fontBank;
2001-01-23 22:05:48 +01:00
dumpConversationScripts();
2001-02-09 18:31:20 +01:00
s_guiFrame->shutdown();
2001-01-10 18:27:12 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::think(int _frames)
{
if(isActive())
{
2001-01-23 22:05:48 +01:00
ASSERT(s_currentScript);
2001-01-22 21:57:39 +01:00
if(s_currentState==STATE_JUST_ACTIVATED)
2001-01-10 18:27:12 +01:00
{
2001-02-02 21:00:04 +01:00
// Need to make sure that the conversation box isn't rendered on the first frame
// ( ie: before it's had time to think ) or it will still be displaying old info
// from the last time it was up
2001-01-22 21:57:39 +01:00
s_currentState=STATE_ACTIVE;
2001-01-10 18:27:12 +01:00
}
s_guiFrame->think(_frames);
thinkQuestion();
2001-01-22 21:57:39 +01:00
s_currentScript->run();
if(s_currentScript->isFinished())
2001-01-10 18:27:12 +01:00
{
2001-01-23 22:05:48 +01:00
s_currentScript=NULL;
2001-01-22 21:57:39 +01:00
s_currentState=STATE_INACTIVE;
2001-01-10 18:27:12 +01:00
}
}
}
2001-01-05 22:43:21 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-10 18:27:12 +01:00
void CConversation::render()
2001-01-05 22:43:21 +01:00
{
2001-01-22 21:57:39 +01:00
if(s_currentState==STATE_ACTIVE)
2001-01-10 18:27:12 +01:00
{
renderQuestion();
s_guiFrame->render();
}
2001-01-05 22:43:21 +01:00
}
2001-01-10 18:27:12 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::registerConversationScript(FileEquate _feScript)
{
2001-01-23 22:05:48 +01:00
ASSERT(s_numRegisteredScripts<MAX_LOADED_SCRIPTS);
// Load in the script and register its id
s_registeredScripts[s_numRegisteredScripts]=new ("conversation script") CScript();
s_registeredScripts[s_numRegisteredScripts]->initialise(_feScript);
s_registeredScriptIds[s_numRegisteredScripts]=_feScript;
s_numRegisteredScripts++;
2001-01-10 18:27:12 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::trigger(FileEquate _feScript)
{
2001-01-23 22:05:48 +01:00
int i;
2001-01-10 18:27:12 +01:00
ASSERT(!isActive());
2001-01-23 22:05:48 +01:00
// Is this script already registered?
for(i=0;i<s_numRegisteredScripts;i++)
{
if(s_registeredScriptIds[i]==_feScript)
{
// Found it..
s_currentScript=s_registeredScripts[i];
s_currentState=STATE_JUST_ACTIVATED;
2001-02-02 21:00:04 +01:00
s_currentScript->reset();
2001-01-23 22:05:48 +01:00
return;
}
}
2001-01-10 18:27:12 +01:00
2001-01-23 22:05:48 +01:00
ASSERT(!"Script was not registered");
2001-01-10 18:27:12 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CConversation::isActive()
{
2001-01-22 21:57:39 +01:00
return s_currentState!=STATE_INACTIVE;
2001-01-10 18:27:12 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::setCharacterAndText(int _characterId,int _textId)
{
s_guiIcon->setFrame(s_characterIconFrames[_characterId].m_frame);
s_guiText->setText(_textId);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::setResponseOptions(int _responseOptions)
{
s_currentQuestion=_responseOptions;
s_currentAnswer=ANSWER_NONE;
s_currentSelectedAnswer=0;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CConversation::getResponse()
{
return s_currentAnswer;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::thinkQuestion()
{
if(s_currentQuestion!=QUESTION_NONE)
{
int pad=PadGetDown(0);
if(s_currentQuestion==QUESTION_YES_NO)
{
2001-02-02 18:48:40 +01:00
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_ACTION))
2001-01-10 18:27:12 +01:00
{
s_currentAnswer=s_currentSelectedAnswer==0?ANSWER_YES:ANSWER_NO;
s_currentQuestion=QUESTION_NONE;
}
2001-02-02 18:48:40 +01:00
else if(pad&(CPadConfig::getButton(CPadConfig::PAD_CFG_LEFT)|CPadConfig::getButton(CPadConfig::PAD_CFG_RIGHT)))
2001-01-10 18:27:12 +01:00
{
s_currentSelectedAnswer^=1;
}
}
else if(s_currentQuestion==QUESTION_OK)
{
2001-02-02 18:48:40 +01:00
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_ACTION))
2001-01-10 18:27:12 +01:00
{
s_currentAnswer=ANSWER_OK;
s_currentQuestion=QUESTION_NONE;
}
}
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::renderQuestion()
{
int xbase,y;
xbase=(512-FRAME_WIDTH)/2;
2001-01-22 21:57:39 +01:00
y=256-FRAME_BOTTOM_OFFSET-(TEXT_BORDER/2)-(s_fontBank->getCharHeight()/2);
2001-01-10 18:27:12 +01:00
switch(s_currentQuestion)
{
case QUESTION_OK:
{
2001-01-22 21:57:39 +01:00
s_fontBank->setColour(SELECT_TEXT_R,SELECT_TEXT_G,SELECT_TEXT_B);
s_fontBank->setJustification(FontBank::JUST_RIGHT);
s_fontBank->print(xbase+FRAME_WIDTH-TEXT_BORDER,y,STR__OK);
2001-01-10 18:27:12 +01:00
}
break;
case QUESTION_YES_NO:
{
if(s_currentSelectedAnswer==0)
{
2001-01-22 21:57:39 +01:00
s_fontBank->setColour(SELECT_TEXT_R,SELECT_TEXT_G,SELECT_TEXT_B);
2001-01-10 18:27:12 +01:00
}
else
{
2001-01-22 21:57:39 +01:00
s_fontBank->setColour(UNSELECT_TEXT_R,UNSELECT_TEXT_G,UNSELECT_TEXT_B);
2001-01-10 18:27:12 +01:00
}
2001-01-22 21:57:39 +01:00
s_fontBank->setJustification(FontBank::JUST_LEFT);
s_fontBank->print(xbase+FRAME_HEIGHT,y,STR__YES);
2001-01-10 18:27:12 +01:00
if(s_currentSelectedAnswer==1)
{
2001-01-22 21:57:39 +01:00
s_fontBank->setColour(SELECT_TEXT_R,SELECT_TEXT_G,SELECT_TEXT_B);
2001-01-10 18:27:12 +01:00
}
else
{
2001-01-22 21:57:39 +01:00
s_fontBank->setColour(UNSELECT_TEXT_R,UNSELECT_TEXT_G,UNSELECT_TEXT_B);
2001-01-10 18:27:12 +01:00
}
2001-01-22 21:57:39 +01:00
s_fontBank->setJustification(FontBank::JUST_RIGHT);
s_fontBank->print(xbase+FRAME_WIDTH-TEXT_BORDER,y,STR__NO);
2001-01-10 18:27:12 +01:00
}
break;
case QUESTION_NONE:
default:
break;
}
}
2001-01-23 22:05:48 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CConversation::dumpConversationScripts()
{
int i;
for(i=0;i<s_numRegisteredScripts;i++)
{
s_registeredScripts[i]->dump();
2001-02-09 18:31:20 +01:00
delete s_registeredScripts[i];
2001-01-23 22:05:48 +01:00
}
s_currentScript=NULL;
s_numRegisteredScripts=0;
}
2001-01-05 22:43:21 +01:00
/*===========================================================================
end */