2012-03-06 03:34:46 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2012-05-11 14:03:59 +00:00
|
|
|
|
2012-03-06 03:34:46 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-05-11 14:03:59 +00:00
|
|
|
|
2012-03-06 03:34:46 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is based on WME Lite.
|
|
|
|
* http://dead-code.org/redir.php?target=wmelite
|
|
|
|
* Copyright (c) 2011 Jan Nedoma
|
|
|
|
*/
|
|
|
|
|
2012-03-06 16:29:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "engines/wintermute/dcgf.h"
|
2012-06-01 23:17:46 +00:00
|
|
|
#include "engines/wintermute/Ad/AdEntity.h"
|
2012-06-02 00:05:11 +00:00
|
|
|
#include "engines/wintermute/Base/BParser.h"
|
|
|
|
#include "engines/wintermute/Base/BDynBuffer.h"
|
|
|
|
#include "engines/wintermute/Base/BActiveRect.h"
|
|
|
|
#include "engines/wintermute/Base/BSurfaceStorage.h"
|
|
|
|
#include "engines/wintermute/Base/BGame.h"
|
2012-06-01 23:17:46 +00:00
|
|
|
#include "engines/wintermute/Ad/AdGame.h"
|
|
|
|
#include "engines/wintermute/Ad/AdScene.h"
|
2012-06-02 00:05:11 +00:00
|
|
|
#include "engines/wintermute/Base/BSound.h"
|
2012-06-01 23:17:46 +00:00
|
|
|
#include "engines/wintermute/Ad/AdWaypointGroup.h"
|
2012-06-02 00:05:11 +00:00
|
|
|
#include "engines/wintermute/Base/BFontStorage.h"
|
|
|
|
#include "engines/wintermute/Base/BFont.h"
|
2012-06-01 23:17:46 +00:00
|
|
|
#include "engines/wintermute/Ad/AdSentence.h"
|
2012-06-02 00:05:11 +00:00
|
|
|
#include "engines/wintermute/Base/BRegion.h"
|
|
|
|
#include "engines/wintermute/Base/BSprite.h"
|
|
|
|
#include "engines/wintermute/Base/BFileManager.h"
|
2012-03-06 16:29:40 +00:00
|
|
|
#include "engines/wintermute/PlatformSDL.h"
|
2012-06-02 00:31:59 +00:00
|
|
|
#include "engines/wintermute/utils/utils.h"
|
2012-06-02 00:05:11 +00:00
|
|
|
#include "engines/wintermute/Base/scriptables/ScValue.h"
|
|
|
|
#include "engines/wintermute/Base/scriptables/ScScript.h"
|
|
|
|
#include "engines/wintermute/Base/scriptables/ScStack.h"
|
2012-03-06 03:34:46 +00:00
|
|
|
#include "common/str.h"
|
|
|
|
|
|
|
|
namespace WinterMute {
|
|
|
|
|
|
|
|
IMPLEMENT_PERSISTENT(CAdEntity, false)
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
CAdEntity::CAdEntity(CBGame *inGame): CAdTalkHolder(inGame) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_type = OBJECT_ENTITY;
|
|
|
|
_subtype = ENTITY_NORMAL;
|
|
|
|
_region = NULL;
|
|
|
|
_item = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_walkToX = _walkToY = 0;
|
|
|
|
_walkToDir = DI_NONE;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
CAdEntity::~CAdEntity() {
|
2012-04-27 22:00:14 +00:00
|
|
|
Game->UnregisterObject(_region);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
delete[] _item;
|
|
|
|
_item = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-05-11 12:16:50 +00:00
|
|
|
HRESULT CAdEntity::LoadFile(const char *Filename) {
|
2012-04-27 22:00:14 +00:00
|
|
|
byte *Buffer = Game->_fileManager->ReadWholeFile(Filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
if (Buffer == NULL) {
|
|
|
|
Game->LOG(0, "CAdEntity::LoadFile failed for file '%s'", Filename);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT ret;
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
_filename = new char [strlen(Filename) + 1];
|
|
|
|
strcpy(_filename, Filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
if (FAILED(ret = LoadBuffer(Buffer, true))) Game->LOG(0, "Error parsing ENTITY file '%s'", Filename);
|
|
|
|
|
|
|
|
|
|
|
|
delete [] Buffer;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TOKEN_DEF_START
|
|
|
|
TOKEN_DEF(ENTITY)
|
|
|
|
TOKEN_DEF(SPRITE)
|
|
|
|
TOKEN_DEF(X)
|
|
|
|
TOKEN_DEF(Y)
|
|
|
|
TOKEN_DEF(TEMPLATE)
|
|
|
|
TOKEN_DEF(NAME)
|
|
|
|
TOKEN_DEF(SCALABLE)
|
|
|
|
TOKEN_DEF(REGISTRABLE)
|
|
|
|
TOKEN_DEF(INTERACTIVE)
|
|
|
|
TOKEN_DEF(SHADOWABLE)
|
|
|
|
TOKEN_DEF(COLORABLE)
|
|
|
|
TOKEN_DEF(ACTIVE)
|
|
|
|
TOKEN_DEF(EVENTS)
|
|
|
|
TOKEN_DEF(FONT)
|
|
|
|
TOKEN_DEF(TALK_SPECIAL)
|
|
|
|
TOKEN_DEF(TALK)
|
|
|
|
TOKEN_DEF(CURSOR)
|
|
|
|
TOKEN_DEF(REGION)
|
|
|
|
TOKEN_DEF(BLOCKED_REGION)
|
|
|
|
TOKEN_DEF(EDITOR_SELECTED)
|
|
|
|
TOKEN_DEF(SCRIPT)
|
|
|
|
TOKEN_DEF(SOUND_START_TIME)
|
|
|
|
TOKEN_DEF(SOUND_VOLUME)
|
|
|
|
TOKEN_DEF(SOUND_PANNING)
|
|
|
|
TOKEN_DEF(SOUND)
|
|
|
|
TOKEN_DEF(SUBTYPE)
|
|
|
|
TOKEN_DEF(CAPTION)
|
|
|
|
TOKEN_DEF(PROPERTY)
|
|
|
|
TOKEN_DEF(WAYPOINTS)
|
|
|
|
TOKEN_DEF(IGNORE_ITEMS)
|
|
|
|
TOKEN_DEF(ROTABLE)
|
|
|
|
TOKEN_DEF(ROTATABLE)
|
|
|
|
TOKEN_DEF(ALPHA_COLOR)
|
|
|
|
TOKEN_DEF(SCALE)
|
|
|
|
TOKEN_DEF(RELATIVE_SCALE)
|
|
|
|
TOKEN_DEF(ALPHA)
|
|
|
|
TOKEN_DEF(EDITOR_PROPERTY)
|
|
|
|
TOKEN_DEF(ITEM)
|
|
|
|
TOKEN_DEF(WALK_TO_X)
|
|
|
|
TOKEN_DEF(WALK_TO_Y)
|
|
|
|
TOKEN_DEF(WALK_TO_DIR)
|
|
|
|
TOKEN_DEF(SAVE_STATE)
|
|
|
|
TOKEN_DEF_END
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
HRESULT CAdEntity::LoadBuffer(byte *Buffer, bool Complete) {
|
|
|
|
TOKEN_TABLE_START(commands)
|
|
|
|
TOKEN_TABLE(ENTITY)
|
|
|
|
TOKEN_TABLE(SPRITE)
|
|
|
|
TOKEN_TABLE(X)
|
|
|
|
TOKEN_TABLE(Y)
|
|
|
|
TOKEN_TABLE(TEMPLATE)
|
|
|
|
TOKEN_TABLE(NAME)
|
|
|
|
TOKEN_TABLE(SCALABLE)
|
|
|
|
TOKEN_TABLE(REGISTRABLE)
|
|
|
|
TOKEN_TABLE(INTERACTIVE)
|
|
|
|
TOKEN_TABLE(SHADOWABLE)
|
|
|
|
TOKEN_TABLE(COLORABLE)
|
|
|
|
TOKEN_TABLE(ACTIVE)
|
|
|
|
TOKEN_TABLE(EVENTS)
|
|
|
|
TOKEN_TABLE(FONT)
|
|
|
|
TOKEN_TABLE(TALK_SPECIAL)
|
|
|
|
TOKEN_TABLE(TALK)
|
|
|
|
TOKEN_TABLE(CURSOR)
|
|
|
|
TOKEN_TABLE(REGION)
|
|
|
|
TOKEN_TABLE(BLOCKED_REGION)
|
|
|
|
TOKEN_TABLE(EDITOR_SELECTED)
|
|
|
|
TOKEN_TABLE(SCRIPT)
|
|
|
|
TOKEN_TABLE(SOUND_START_TIME)
|
|
|
|
TOKEN_TABLE(SOUND_VOLUME)
|
|
|
|
TOKEN_TABLE(SOUND_PANNING)
|
|
|
|
TOKEN_TABLE(SOUND)
|
|
|
|
TOKEN_TABLE(SUBTYPE)
|
|
|
|
TOKEN_TABLE(CAPTION)
|
|
|
|
TOKEN_TABLE(PROPERTY)
|
|
|
|
TOKEN_TABLE(WAYPOINTS)
|
|
|
|
TOKEN_TABLE(IGNORE_ITEMS)
|
|
|
|
TOKEN_TABLE(ROTABLE)
|
|
|
|
TOKEN_TABLE(ROTATABLE)
|
|
|
|
TOKEN_TABLE(ALPHA_COLOR)
|
|
|
|
TOKEN_TABLE(SCALE)
|
|
|
|
TOKEN_TABLE(RELATIVE_SCALE)
|
|
|
|
TOKEN_TABLE(ALPHA)
|
|
|
|
TOKEN_TABLE(EDITOR_PROPERTY)
|
|
|
|
TOKEN_TABLE(ITEM)
|
|
|
|
TOKEN_TABLE(WALK_TO_X)
|
|
|
|
TOKEN_TABLE(WALK_TO_Y)
|
|
|
|
TOKEN_TABLE(WALK_TO_DIR)
|
|
|
|
TOKEN_TABLE(SAVE_STATE)
|
|
|
|
TOKEN_TABLE_END
|
|
|
|
|
|
|
|
byte *params;
|
|
|
|
int cmd;
|
|
|
|
CBParser parser(Game);
|
|
|
|
|
|
|
|
if (Complete) {
|
|
|
|
if (parser.GetCommand((char **)&Buffer, commands, (char **)¶ms) != TOKEN_ENTITY) {
|
|
|
|
Game->LOG(0, "'ENTITY' keyword expected.");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
Buffer = params;
|
|
|
|
}
|
|
|
|
|
|
|
|
CAdGame *AdGame = (CAdGame *)Game;
|
|
|
|
CBSprite *spr = NULL;
|
|
|
|
int ar = 0, ag = 0, ab = 0, alpha = 0;
|
|
|
|
while ((cmd = parser.GetCommand((char **)&Buffer, commands, (char **)¶ms)) > 0) {
|
|
|
|
switch (cmd) {
|
|
|
|
case TOKEN_TEMPLATE:
|
|
|
|
if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_X:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%d", &_posX);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_Y:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%d", &_posY);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SPRITE: {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _sprite;
|
|
|
|
_sprite = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
spr = new CBSprite(Game, this);
|
|
|
|
if (!spr || FAILED(spr->LoadFile((char *)params))) cmd = PARSERR_GENERIC;
|
2012-04-27 22:00:14 +00:00
|
|
|
else _sprite = spr;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_TALK: {
|
|
|
|
spr = new CBSprite(Game, this);
|
2012-04-27 22:00:14 +00:00
|
|
|
if (!spr || FAILED(spr->LoadFile((char *)params, AdGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC;
|
|
|
|
else _talkSprites.Add(spr);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_TALK_SPECIAL: {
|
|
|
|
spr = new CBSprite(Game, this);
|
2012-04-27 22:00:14 +00:00
|
|
|
if (!spr || FAILED(spr->LoadFile((char *)params, AdGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC;
|
|
|
|
else _talkSpritesEx.Add(spr);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_NAME:
|
|
|
|
SetName((char *)params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_ITEM:
|
|
|
|
SetItem((char *)params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_CAPTION:
|
|
|
|
SetCaption((char *)params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_FONT:
|
|
|
|
SetFont((char *)params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SCALABLE:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_zoomable);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SCALE: {
|
|
|
|
int s;
|
|
|
|
parser.ScanStr((char *)params, "%d", &s);
|
2012-04-27 22:00:14 +00:00
|
|
|
_scale = (float)s;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_RELATIVE_SCALE: {
|
|
|
|
int s;
|
|
|
|
parser.ScanStr((char *)params, "%d", &s);
|
2012-04-27 22:00:14 +00:00
|
|
|
_relativeScale = (float)s;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_ROTABLE:
|
|
|
|
case TOKEN_ROTATABLE:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_rotatable);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_REGISTRABLE:
|
|
|
|
case TOKEN_INTERACTIVE:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_registrable);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SHADOWABLE:
|
|
|
|
case TOKEN_COLORABLE:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_shadowable);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_ACTIVE:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_active);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_CURSOR:
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _cursor;
|
2012-04-27 22:00:14 +00:00
|
|
|
_cursor = new CBSprite(Game);
|
|
|
|
if (!_cursor || FAILED(_cursor->LoadFile((char *)params))) {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _cursor;
|
|
|
|
_cursor = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_SELECTED:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_editorSelected);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_REGION: {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region) Game->UnregisterObject(_region);
|
|
|
|
_region = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
CBRegion *rgn = new CBRegion(Game);
|
|
|
|
if (!rgn || FAILED(rgn->LoadBuffer(params, false))) cmd = PARSERR_GENERIC;
|
|
|
|
else {
|
2012-04-27 22:00:14 +00:00
|
|
|
_region = rgn;
|
|
|
|
Game->RegisterObject(_region);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_BLOCKED_REGION: {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _blockRegion;
|
|
|
|
_blockRegion = NULL;
|
|
|
|
delete _currentBlockRegion;
|
|
|
|
_currentBlockRegion = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
CBRegion *rgn = new CBRegion(Game);
|
|
|
|
CBRegion *crgn = new CBRegion(Game);
|
|
|
|
if (!rgn || !crgn || FAILED(rgn->LoadBuffer(params, false))) {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _blockRegion;
|
|
|
|
_blockRegion = NULL;
|
|
|
|
delete _currentBlockRegion;
|
|
|
|
_currentBlockRegion = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
} else {
|
2012-04-27 22:00:14 +00:00
|
|
|
_blockRegion = rgn;
|
|
|
|
_currentBlockRegion = crgn;
|
|
|
|
_currentBlockRegion->Mimic(_blockRegion);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_WAYPOINTS: {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _wptGroup;
|
|
|
|
_wptGroup = NULL;
|
|
|
|
delete _currentWptGroup;
|
|
|
|
_currentWptGroup = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
CAdWaypointGroup *wpt = new CAdWaypointGroup(Game);
|
|
|
|
CAdWaypointGroup *cwpt = new CAdWaypointGroup(Game);
|
|
|
|
if (!wpt || !cwpt || FAILED(wpt->LoadBuffer(params, false))) {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _wptGroup;
|
|
|
|
_wptGroup = NULL;
|
|
|
|
delete _currentWptGroup;
|
|
|
|
_currentWptGroup = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
cmd = PARSERR_GENERIC;
|
|
|
|
} else {
|
2012-04-27 22:00:14 +00:00
|
|
|
_wptGroup = wpt;
|
|
|
|
_currentWptGroup = cwpt;
|
|
|
|
_currentWptGroup->Mimic(_wptGroup);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SCRIPT:
|
|
|
|
AddScript((char *)params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SUBTYPE: {
|
|
|
|
if (scumm_stricmp((char *)params, "sound") == 0) {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _sprite;
|
|
|
|
_sprite = NULL;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (Game->_editorMode) {
|
2012-03-06 03:34:46 +00:00
|
|
|
spr = new CBSprite(Game, this);
|
|
|
|
if (!spr || FAILED(spr->LoadFile("entity_sound.sprite"))) cmd = PARSERR_GENERIC;
|
2012-04-27 22:00:14 +00:00
|
|
|
else _sprite = spr;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
if (Game->_editorMode) _editorOnly = true;
|
|
|
|
_zoomable = false;
|
|
|
|
_rotatable = false;
|
|
|
|
_registrable = Game->_editorMode;
|
|
|
|
_shadowable = false;
|
|
|
|
_subtype = ENTITY_SOUND;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SOUND:
|
|
|
|
PlaySFX((char *)params, false, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SOUND_START_TIME:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%d", &_sFXStart);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SOUND_VOLUME:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%d", &_sFXVolume);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SOUND_PANNING:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_autoSoundPanning);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_SAVE_STATE:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_saveState);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_PROPERTY:
|
|
|
|
ParseProperty(params, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_IGNORE_ITEMS:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%b", &_ignoreItems);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_ALPHA_COLOR:
|
|
|
|
parser.ScanStr((char *)params, "%d,%d,%d", &ar, &ag, &ab);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_ALPHA:
|
|
|
|
parser.ScanStr((char *)params, "%d", &alpha);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_EDITOR_PROPERTY:
|
|
|
|
ParseEditorProperty(params, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_WALK_TO_X:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%d", &_walkToX);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_WALK_TO_Y:
|
2012-04-27 22:00:14 +00:00
|
|
|
parser.ScanStr((char *)params, "%d", &_walkToY);
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TOKEN_WALK_TO_DIR: {
|
|
|
|
int i;
|
|
|
|
parser.ScanStr((char *)params, "%d", &i);
|
|
|
|
if (i < 0) i = 0;
|
|
|
|
if (i >= NUM_DIRECTIONS) i = DI_NONE;
|
2012-04-27 22:00:14 +00:00
|
|
|
_walkToDir = (TDirection)i;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cmd == PARSERR_TOKENNOTFOUND) {
|
|
|
|
Game->LOG(0, "Syntax error in ENTITY definition");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
if (cmd == PARSERR_GENERIC) {
|
|
|
|
Game->LOG(0, "Error loading ENTITY definition");
|
|
|
|
if (spr) delete spr;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region && _sprite) {
|
|
|
|
Game->LOG(0, "Warning: Entity '%s' has both sprite and region.", _name);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdatePosition();
|
|
|
|
|
|
|
|
if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) {
|
|
|
|
ar = ag = ab = 255;
|
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
_alphaColor = DRGBA(ar, ag, ab, alpha);
|
|
|
|
_state = STATE_READY;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_item && ((CAdGame *)Game)->IsItemTaken(_item)) _active = false;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
HRESULT CAdEntity::Display() {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_active) {
|
2012-03-06 03:34:46 +00:00
|
|
|
UpdateSounds();
|
|
|
|
|
|
|
|
uint32 Alpha;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_alphaColor != 0) Alpha = _alphaColor;
|
|
|
|
else Alpha = _shadowable ? ((CAdGame *)Game)->_scene->GetAlphaAt(_posX, _posY) : 0xFFFFFFFF;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
float ScaleX, ScaleY;
|
|
|
|
GetScale(&ScaleX, &ScaleY);
|
|
|
|
|
|
|
|
float Rotate;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_rotatable) {
|
|
|
|
if (_rotateValid) Rotate = _rotate;
|
|
|
|
else Rotate = ((CAdGame *)Game)->_scene->GetRotationAt(_posX, _posY) + _relativeRotate;
|
2012-03-06 03:34:46 +00:00
|
|
|
} else Rotate = 0.0f;
|
|
|
|
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
bool Reg = _registrable;
|
|
|
|
if (_ignoreItems && ((CAdGame *)Game)->_selectedItem) Reg = false;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region && (Reg || _editorAlwaysRegister)) {
|
|
|
|
Game->_renderer->_rectList.Add(new CBActiveRect(Game, _registerAlias, _region, Game->_offsetX, Game->_offsetY));
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DisplaySpriteAttachments(true);
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_currentSprite) {
|
|
|
|
_currentSprite->Display(_posX,
|
2012-05-11 14:03:59 +00:00
|
|
|
_posY,
|
|
|
|
(Reg || _editorAlwaysRegister) ? _registerAlias : NULL,
|
|
|
|
ScaleX,
|
|
|
|
ScaleY,
|
|
|
|
Alpha,
|
|
|
|
Rotate,
|
|
|
|
_blendMode);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
DisplaySpriteAttachments(false);
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_partEmitter) _partEmitter->Display(_region);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
HRESULT CAdEntity::Update() {
|
2012-04-27 22:00:14 +00:00
|
|
|
_currentSprite = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_state == STATE_READY && _animSprite) {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _animSprite;
|
|
|
|
_animSprite = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// finished playing animation?
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) {
|
|
|
|
_state = STATE_READY;
|
|
|
|
_currentSprite = _animSprite;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_sentence && _state != STATE_TALKING) _sentence->Finish();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
// default: stand animation
|
2012-04-27 22:00:14 +00:00
|
|
|
if (!_currentSprite) _currentSprite = _sprite;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
switch (_state) {
|
2012-03-06 03:34:46 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
case STATE_PLAYING_ANIM:
|
2012-04-27 22:00:14 +00:00
|
|
|
_currentSprite = _animSprite;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
case STATE_READY:
|
2012-04-27 22:00:14 +00:00
|
|
|
if (!_animSprite)
|
|
|
|
_currentSprite = _sprite;
|
2012-03-06 03:34:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
case STATE_TALKING: {
|
2012-04-27 22:00:14 +00:00
|
|
|
_sentence->Update();
|
|
|
|
if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite;
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->IsPlaying() && !_sentence->_sound->IsPaused())) || (!_sentence->_sound && _sentence->_duration <= Game->_timer - _sentence->_startTime);
|
|
|
|
if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) {
|
2012-03-06 03:34:46 +00:00
|
|
|
if (TimeIsUp) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_sentence->Finish();
|
|
|
|
_tempSprite2 = NULL;
|
|
|
|
_state = STATE_READY;
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-04-27 22:00:14 +00:00
|
|
|
_tempSprite2 = GetTalkStance(_sentence->GetNextStance());
|
|
|
|
if (_tempSprite2) {
|
|
|
|
_tempSprite2->Reset();
|
|
|
|
_currentSprite = _tempSprite2;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
((CAdGame *)Game)->AddSentence(_sentence);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-04-27 22:00:14 +00:00
|
|
|
_currentSprite = _tempSprite2;
|
|
|
|
((CAdGame *)Game)->AddSentence(_sentence);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-05-31 22:51:58 +00:00
|
|
|
default:
|
|
|
|
error("AdEntity::Update - Unhandled enum");
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_currentSprite) {
|
|
|
|
_currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)Game)->_scene->GetZoomAt(_posX, _posY) : 100);
|
|
|
|
if (_currentSprite->_changed) {
|
|
|
|
_posX += _currentSprite->_moveX;
|
|
|
|
_posY += _currentSprite->_moveY;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateBlockRegion();
|
2012-04-27 22:00:14 +00:00
|
|
|
_ready = (_state == STATE_READY);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
UpdatePartEmitter();
|
|
|
|
UpdateSpriteAttachments();
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// high level scripting interface
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-05-11 13:24:49 +00:00
|
|
|
HRESULT CAdEntity::ScCallMethod(CScScript *Script, CScStack *Stack, CScStack *ThisStack, const char *Name) {
|
2012-03-06 03:34:46 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// StopSound
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-04-27 22:00:14 +00:00
|
|
|
if (strcmp(Name, "StopSound") == 0 && _subtype == ENTITY_SOUND) {
|
2012-03-06 03:34:46 +00:00
|
|
|
Stack->CorrectParams(0);
|
|
|
|
|
|
|
|
if (FAILED(StopSFX(false))) Stack->PushBool(false);
|
|
|
|
else Stack->PushBool(true);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlayTheora
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "PlayTheora") == 0) {
|
|
|
|
Stack->CorrectParams(0);
|
|
|
|
Stack->PushBool(false);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// StopTheora
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "StopTheora") == 0) {
|
|
|
|
Stack->CorrectParams(0);
|
|
|
|
Stack->PushBool(false);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTheoraPlaying
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "IsTheoraPlaying") == 0) {
|
|
|
|
Stack->CorrectParams(0);
|
|
|
|
Stack->PushBool(false);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// PauseTheora
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "PauseTheora") == 0) {
|
|
|
|
Stack->CorrectParams(0);
|
|
|
|
Stack->PushBool(false);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// ResumeTheora
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "ResumeTheora") == 0) {
|
|
|
|
Stack->CorrectParams(0);
|
|
|
|
Stack->PushBool(false);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTheoraPaused
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "IsTheoraPaused") == 0) {
|
|
|
|
Stack->CorrectParams(0);
|
|
|
|
Stack->PushBool(false);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// CreateRegion
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "CreateRegion") == 0) {
|
|
|
|
Stack->CorrectParams(0);
|
2012-04-27 22:00:14 +00:00
|
|
|
if (!_region) {
|
|
|
|
_region = new CBRegion(Game);
|
|
|
|
Game->RegisterObject(_region);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region) Stack->PushNative(_region, true);
|
2012-03-06 03:34:46 +00:00
|
|
|
else Stack->PushNULL();
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// DeleteRegion
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "DeleteRegion") == 0) {
|
|
|
|
Stack->CorrectParams(0);
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region) {
|
|
|
|
Game->UnregisterObject(_region);
|
|
|
|
_region = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
Stack->PushBool(true);
|
|
|
|
} else Stack->PushBool(false);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
else return CAdTalkHolder::ScCallMethod(Script, Stack, ThisStack, Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-05-11 13:24:49 +00:00
|
|
|
CScValue *CAdEntity::ScGetProperty(const char *Name) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_scValue->SetNULL();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Type (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
if (strcmp(Name, "Type") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_scValue->SetString("entity");
|
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Item
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "Item") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_item) _scValue->SetString(_item);
|
|
|
|
else _scValue->SetNULL();
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Subtype (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "Subtype") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_subtype == ENTITY_SOUND)
|
|
|
|
_scValue->SetString("sound");
|
2012-03-06 03:34:46 +00:00
|
|
|
else
|
2012-04-27 22:00:14 +00:00
|
|
|
_scValue->SetString("normal");
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// WalkToX
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "WalkToX") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_scValue->SetInt(_walkToX);
|
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// WalkToY
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "WalkToY") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_scValue->SetInt(_walkToY);
|
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// WalkToDirection
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "WalkToDirection") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_scValue->SetInt((int)_walkToDir);
|
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Region (RO)
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "Region") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region) _scValue->SetNative(_region, true);
|
|
|
|
else _scValue->SetNULL();
|
|
|
|
return _scValue;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else return CAdTalkHolder::ScGetProperty(Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-05-11 13:24:49 +00:00
|
|
|
HRESULT CAdEntity::ScSetProperty(const char *Name, CScValue *Value) {
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Item
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
if (strcmp(Name, "Item") == 0) {
|
|
|
|
SetItem(Value->GetString());
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// WalkToX
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "WalkToX") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_walkToX = Value->GetInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// WalkToY
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "WalkToY") == 0) {
|
2012-04-27 22:00:14 +00:00
|
|
|
_walkToY = Value->GetInt();
|
2012-03-06 03:34:46 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// WalkToDirection
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
else if (strcmp(Name, "WalkToDirection") == 0) {
|
|
|
|
int Dir = Value->GetInt();
|
2012-04-27 22:00:14 +00:00
|
|
|
if (Dir >= 0 && Dir < NUM_DIRECTIONS) _walkToDir = (TDirection)Dir;
|
2012-03-06 03:34:46 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else return CAdTalkHolder::ScSetProperty(Name, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-05-12 04:49:10 +00:00
|
|
|
const char *CAdEntity::ScToString() {
|
2012-03-06 03:34:46 +00:00
|
|
|
return "[entity object]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
HRESULT CAdEntity::SaveAsText(CBDynBuffer *Buffer, int Indent) {
|
|
|
|
Buffer->PutTextIndent(Indent, "ENTITY {\n");
|
2012-04-27 22:00:14 +00:00
|
|
|
Buffer->PutTextIndent(Indent + 2, "NAME=\"%s\"\n", _name);
|
|
|
|
if (_subtype == ENTITY_SOUND)
|
2012-03-06 03:34:46 +00:00
|
|
|
Buffer->PutTextIndent(Indent + 2, "SUBTYPE=\"SOUND\"\n");
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "CAPTION=\"%s\"\n", GetCaption());
|
2012-04-27 22:00:14 +00:00
|
|
|
Buffer->PutTextIndent(Indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE");
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "X=%d\n", _posX);
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "Y=%d\n", _posY);
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SCALABLE=%s\n", _zoomable ? "TRUE" : "FALSE");
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "INTERACTIVE=%s\n", _registrable ? "TRUE" : "FALSE");
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "COLORABLE=%s\n", _shadowable ? "TRUE" : "FALSE");
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE");
|
|
|
|
if (_ignoreItems)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "IGNORE_ITEMS=%s\n", _ignoreItems ? "TRUE" : "FALSE");
|
|
|
|
if (_rotatable)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "ROTATABLE=%s\n", _rotatable ? "TRUE" : "FALSE");
|
|
|
|
|
|
|
|
if (!_autoSoundPanning)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SOUND_PANNING=%s\n", _autoSoundPanning ? "TRUE" : "FALSE");
|
|
|
|
|
|
|
|
if (!_saveState)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SAVE_STATE=%s\n", _saveState ? "TRUE" : "FALSE");
|
|
|
|
|
|
|
|
if (_item && _item[0] != '\0') Buffer->PutTextIndent(Indent + 2, "ITEM=\"%s\"\n", _item);
|
|
|
|
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "WALK_TO_X=%d\n", _walkToX);
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "WALK_TO_Y=%d\n", _walkToY);
|
|
|
|
if (_walkToDir != DI_NONE)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "WALK_TO_DIR=%d\n", (int)_walkToDir);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
for (i = 0; i < _scripts.GetSize(); i++) {
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_subtype == ENTITY_NORMAL && _sprite && _sprite->_filename)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SPRITE=\"%s\"\n", _sprite->_filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_subtype == ENTITY_SOUND && _sFX && _sFX->_soundFilename) {
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SOUND=\"%s\"\n", _sFX->_soundFilename);
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SOUND_START_TIME=%d\n", _sFXStart);
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SOUND_VOLUME=%d\n", _sFXVolume);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (D3DCOLGetR(_alphaColor) != 0 || D3DCOLGetG(_alphaColor) != 0 || D3DCOLGetB(_alphaColor) != 0)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", D3DCOLGetR(_alphaColor), D3DCOLGetG(_alphaColor), D3DCOLGetB(_alphaColor));
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (D3DCOLGetA(_alphaColor) != 0)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "ALPHA = %d\n", D3DCOLGetA(_alphaColor));
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_scale >= 0)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "SCALE = %d\n", (int)_scale);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_relativeScale != 0)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_font && _font->_filename)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "FONT=\"%s\"\n", _font->_filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_cursor && _cursor->_filename)
|
|
|
|
Buffer->PutTextIndent(Indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
CAdTalkHolder::SaveAsText(Buffer, Indent + 2);
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region) _region->SaveAsText(Buffer, Indent + 2);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_scProp) _scProp->SaveAsText(Buffer, Indent + 2);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
CAdObject::SaveAsText(Buffer, Indent + 2);
|
|
|
|
|
|
|
|
Buffer->PutTextIndent(Indent, "}\n\n");
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
int CAdEntity::GetHeight() {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region && !_sprite) {
|
|
|
|
return _region->_rect.bottom - _region->_rect.top;
|
2012-03-06 03:34:46 +00:00
|
|
|
} else {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_currentSprite == NULL) _currentSprite = _sprite;
|
2012-03-06 03:34:46 +00:00
|
|
|
return CAdObject::GetHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void CAdEntity::UpdatePosition() {
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_region && !_sprite) {
|
|
|
|
_posX = _region->_rect.left + (_region->_rect.right - _region->_rect.left) / 2;
|
|
|
|
_posY = _region->_rect.bottom;
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
HRESULT CAdEntity::Persist(CBPersistMgr *PersistMgr) {
|
|
|
|
CAdTalkHolder::Persist(PersistMgr);
|
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
PersistMgr->Transfer(TMEMBER(_item));
|
|
|
|
PersistMgr->Transfer(TMEMBER(_region));
|
|
|
|
//PersistMgr->Transfer(TMEMBER(_sprite));
|
|
|
|
PersistMgr->Transfer(TMEMBER_INT(_subtype));
|
|
|
|
_talkSprites.Persist(PersistMgr);
|
|
|
|
_talkSpritesEx.Persist(PersistMgr);
|
2012-03-06 03:34:46 +00:00
|
|
|
|
2012-04-27 22:00:14 +00:00
|
|
|
PersistMgr->Transfer(TMEMBER(_walkToX));
|
|
|
|
PersistMgr->Transfer(TMEMBER(_walkToY));
|
|
|
|
PersistMgr->Transfer(TMEMBER_INT(_walkToDir));
|
2012-03-06 03:34:46 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-05-11 12:16:50 +00:00
|
|
|
void CAdEntity::SetItem(const char *ItemName) {
|
2012-04-27 22:00:14 +00:00
|
|
|
CBUtils::SetString(&_item, ItemName);
|
2012-03-06 03:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-05-11 12:16:50 +00:00
|
|
|
HRESULT CAdEntity::SetSprite(const char *Filename) {
|
2012-03-06 03:34:46 +00:00
|
|
|
bool SetCurrent = false;
|
2012-04-27 22:00:14 +00:00
|
|
|
if (_currentSprite == _sprite) {
|
|
|
|
_currentSprite = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
SetCurrent = true;
|
|
|
|
}
|
|
|
|
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _sprite;
|
|
|
|
_sprite = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
CBSprite *spr = new CBSprite(Game, this);
|
|
|
|
if (!spr || FAILED(spr->LoadFile(Filename))) {
|
2012-05-12 05:36:24 +00:00
|
|
|
delete _sprite;
|
|
|
|
_sprite = NULL;
|
2012-03-06 03:34:46 +00:00
|
|
|
return E_FAIL;
|
|
|
|
} else {
|
2012-04-27 22:00:14 +00:00
|
|
|
_sprite = spr;
|
|
|
|
_currentSprite = _sprite;
|
2012-03-06 03:34:46 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace WinterMute
|