From 113961fd2a2203434b03766d722a0f8c0854bfd0 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 19 Jul 2012 19:29:15 +0200 Subject: WINTERMUTE: Change all folder-names to lowercase. --- engines/wintermute/ad/AdActor.cpp | 1316 +++++++++++++ engines/wintermute/ad/AdActor.h | 107 ++ engines/wintermute/ad/AdEntity.cpp | 1027 ++++++++++ engines/wintermute/ad/AdEntity.h | 68 + engines/wintermute/ad/AdGame.cpp | 2061 ++++++++++++++++++++ engines/wintermute/ad/AdGame.h | 161 ++ engines/wintermute/ad/AdInventory.cpp | 119 ++ engines/wintermute/ad/AdInventory.h | 52 + engines/wintermute/ad/AdInventoryBox.cpp | 372 ++++ engines/wintermute/ad/AdInventoryBox.h | 64 + engines/wintermute/ad/AdItem.cpp | 760 ++++++++ engines/wintermute/ad/AdItem.h | 70 + engines/wintermute/ad/AdLayer.cpp | 537 ++++++ engines/wintermute/ad/AdLayer.h | 58 + engines/wintermute/ad/AdNodeState.cpp | 169 ++ engines/wintermute/ad/AdNodeState.h | 58 + engines/wintermute/ad/AdObject.cpp | 1203 ++++++++++++ engines/wintermute/ad/AdObject.h | 123 ++ engines/wintermute/ad/AdPath.cpp | 112 ++ engines/wintermute/ad/AdPath.h | 56 + engines/wintermute/ad/AdPathPoint.cpp | 75 + engines/wintermute/ad/AdPathPoint.h | 50 + engines/wintermute/ad/AdRegion.cpp | 392 ++++ engines/wintermute/ad/AdRegion.h | 58 + engines/wintermute/ad/AdResponse.cpp | 143 ++ engines/wintermute/ad/AdResponse.h | 61 + engines/wintermute/ad/AdResponseBox.cpp | 647 +++++++ engines/wintermute/ad/AdResponseBox.h | 87 + engines/wintermute/ad/AdResponseContext.cpp | 70 + engines/wintermute/ad/AdResponseContext.h | 50 + engines/wintermute/ad/AdRotLevel.cpp | 159 ++ engines/wintermute/ad/AdRotLevel.h | 49 + engines/wintermute/ad/AdScaleLevel.cpp | 157 ++ engines/wintermute/ad/AdScaleLevel.h | 50 + engines/wintermute/ad/AdScene.cpp | 2752 +++++++++++++++++++++++++++ engines/wintermute/ad/AdScene.h | 181 ++ engines/wintermute/ad/AdSceneNode.cpp | 83 + engines/wintermute/ad/AdSceneNode.h | 54 + engines/wintermute/ad/AdSceneState.cpp | 88 + engines/wintermute/ad/AdSceneState.h | 51 + engines/wintermute/ad/AdSentence.cpp | 317 +++ engines/wintermute/ad/AdSentence.h | 85 + engines/wintermute/ad/AdSpriteSet.cpp | 312 +++ engines/wintermute/ad/AdSpriteSet.h | 54 + engines/wintermute/ad/AdTalkDef.cpp | 260 +++ engines/wintermute/ad/AdTalkDef.h | 58 + engines/wintermute/ad/AdTalkHolder.cpp | 366 ++++ engines/wintermute/ad/AdTalkHolder.h | 57 + engines/wintermute/ad/AdTalkNode.cpp | 266 +++ engines/wintermute/ad/AdTalkNode.h | 63 + engines/wintermute/ad/AdTypes.h | 107 ++ engines/wintermute/ad/AdWaypointGroup.cpp | 261 +++ engines/wintermute/ad/AdWaypointGroup.h | 58 + 53 files changed, 16014 insertions(+) create mode 100644 engines/wintermute/ad/AdActor.cpp create mode 100644 engines/wintermute/ad/AdActor.h create mode 100644 engines/wintermute/ad/AdEntity.cpp create mode 100644 engines/wintermute/ad/AdEntity.h create mode 100644 engines/wintermute/ad/AdGame.cpp create mode 100644 engines/wintermute/ad/AdGame.h create mode 100644 engines/wintermute/ad/AdInventory.cpp create mode 100644 engines/wintermute/ad/AdInventory.h create mode 100644 engines/wintermute/ad/AdInventoryBox.cpp create mode 100644 engines/wintermute/ad/AdInventoryBox.h create mode 100644 engines/wintermute/ad/AdItem.cpp create mode 100644 engines/wintermute/ad/AdItem.h create mode 100644 engines/wintermute/ad/AdLayer.cpp create mode 100644 engines/wintermute/ad/AdLayer.h create mode 100644 engines/wintermute/ad/AdNodeState.cpp create mode 100644 engines/wintermute/ad/AdNodeState.h create mode 100644 engines/wintermute/ad/AdObject.cpp create mode 100644 engines/wintermute/ad/AdObject.h create mode 100644 engines/wintermute/ad/AdPath.cpp create mode 100644 engines/wintermute/ad/AdPath.h create mode 100644 engines/wintermute/ad/AdPathPoint.cpp create mode 100644 engines/wintermute/ad/AdPathPoint.h create mode 100644 engines/wintermute/ad/AdRegion.cpp create mode 100644 engines/wintermute/ad/AdRegion.h create mode 100644 engines/wintermute/ad/AdResponse.cpp create mode 100644 engines/wintermute/ad/AdResponse.h create mode 100644 engines/wintermute/ad/AdResponseBox.cpp create mode 100644 engines/wintermute/ad/AdResponseBox.h create mode 100644 engines/wintermute/ad/AdResponseContext.cpp create mode 100644 engines/wintermute/ad/AdResponseContext.h create mode 100644 engines/wintermute/ad/AdRotLevel.cpp create mode 100644 engines/wintermute/ad/AdRotLevel.h create mode 100644 engines/wintermute/ad/AdScaleLevel.cpp create mode 100644 engines/wintermute/ad/AdScaleLevel.h create mode 100644 engines/wintermute/ad/AdScene.cpp create mode 100644 engines/wintermute/ad/AdScene.h create mode 100644 engines/wintermute/ad/AdSceneNode.cpp create mode 100644 engines/wintermute/ad/AdSceneNode.h create mode 100644 engines/wintermute/ad/AdSceneState.cpp create mode 100644 engines/wintermute/ad/AdSceneState.h create mode 100644 engines/wintermute/ad/AdSentence.cpp create mode 100644 engines/wintermute/ad/AdSentence.h create mode 100644 engines/wintermute/ad/AdSpriteSet.cpp create mode 100644 engines/wintermute/ad/AdSpriteSet.h create mode 100644 engines/wintermute/ad/AdTalkDef.cpp create mode 100644 engines/wintermute/ad/AdTalkDef.h create mode 100644 engines/wintermute/ad/AdTalkHolder.cpp create mode 100644 engines/wintermute/ad/AdTalkHolder.h create mode 100644 engines/wintermute/ad/AdTalkNode.cpp create mode 100644 engines/wintermute/ad/AdTalkNode.h create mode 100644 engines/wintermute/ad/AdTypes.h create mode 100644 engines/wintermute/ad/AdWaypointGroup.cpp create mode 100644 engines/wintermute/ad/AdWaypointGroup.h (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/AdActor.cpp b/engines/wintermute/ad/AdActor.cpp new file mode 100644 index 0000000000..480851d21f --- /dev/null +++ b/engines/wintermute/ad/AdActor.cpp @@ -0,0 +1,1316 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/dctypes.h" +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/BObject.h" +#include "engines/wintermute/ad/AdActor.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdScene.h" +#include "engines/wintermute/ad/AdEntity.h" +#include "engines/wintermute/ad/AdSpriteSet.h" +#include "engines/wintermute/ad/AdWaypointGroup.h" +#include "engines/wintermute/ad/AdPath.h" +#include "engines/wintermute/ad/AdSentence.h" +#include "engines/wintermute/base/BObject.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BSound.h" +#include "engines/wintermute/base/BRegion.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/wintermute.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdActor, false) + + +////////////////////////////////////////////////////////////////////////// +CAdActor::CAdActor(CBGame *inGame): CAdTalkHolder(inGame) { + _path = new CAdPath(_gameRef); + + _type = OBJECT_ACTOR; + _dir = DI_LEFT; + + _walkSprite = NULL; + _standSprite = NULL; + _turnLeftSprite = NULL; + _turnRightSprite = NULL; + + _targetPoint = new CBPoint; + _afterWalkDir = DI_NONE; + + _animSprite2 = NULL; + + setDefaultAnimNames(); +} + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::setDefaultAnimNames() { + _talkAnimName = "talk"; + _idleAnimName = "idle"; + _walkAnimName = "walk"; + _turnLeftAnimName = "turnleft"; + _turnRightAnimName = "turnright"; + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +CAdActor::~CAdActor() { + delete _path; + delete _targetPoint; + _path = NULL; + _targetPoint = NULL; + + delete _walkSprite; + delete _standSprite; + delete _turnLeftSprite; + delete _turnRightSprite; + _walkSprite = NULL; + _standSprite = NULL; + _turnLeftSprite = NULL; + _turnRightSprite = NULL; + + _animSprite2 = NULL; // ref only + + for (int i = 0; i < _talkSprites.getSize(); i++) { + delete _talkSprites[i]; + } + _talkSprites.removeAll(); + + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + delete _talkSpritesEx[i]; + } + _talkSpritesEx.removeAll(); + + for (int i = 0; i < _anims.getSize(); i++) { + delete _anims[i]; + _anims[i] = NULL; + } + _anims.removeAll(); + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdActor::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ACTOR) +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(WALK) +TOKEN_DEF(STAND) +TOKEN_DEF(TALK_SPECIAL) +TOKEN_DEF(TALK) +TOKEN_DEF(TURN_LEFT) +TOKEN_DEF(TURN_RIGHT) +TOKEN_DEF(EVENTS) +TOKEN_DEF(FONT) +TOKEN_DEF(CURSOR) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(SOUND_VOLUME) +TOKEN_DEF(SOUND_PANNING) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(BLOCKED_REGION) +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(ANIMATION) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdActor::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ACTOR) + 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(WALK) + TOKEN_TABLE(STAND) + TOKEN_TABLE(TALK_SPECIAL) + TOKEN_TABLE(TALK) + TOKEN_TABLE(TURN_LEFT) + TOKEN_TABLE(TURN_RIGHT) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(FONT) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(SOUND_VOLUME) + TOKEN_TABLE(SOUND_PANNING) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(BLOCKED_REGION) + 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(ANIMATION) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTOR) { + _gameRef->LOG(0, "'ACTOR' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + CAdGame *adGame = (CAdGame *)_gameRef; + CAdSpriteSet *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 (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_FONT: + SetFont((char *)params); + break; + + case TOKEN_SCALABLE: + parser.scanStr((char *)params, "%b", &_zoomable); + break; + + case TOKEN_ROTABLE: + case TOKEN_ROTATABLE: + parser.scanStr((char *)params, "%b", &_rotatable); + break; + + case TOKEN_REGISTRABLE: + case TOKEN_INTERACTIVE: + parser.scanStr((char *)params, "%b", &_registrable); + break; + + case TOKEN_SHADOWABLE: + case TOKEN_COLORABLE: + parser.scanStr((char *)params, "%b", &_shadowable); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_WALK: + delete _walkSprite; + _walkSprite = NULL; + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC; + else _walkSprite = spr; + break; + + case TOKEN_TALK: + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSprites.add(spr); + break; + + case TOKEN_TALK_SPECIAL: + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSpritesEx.add(spr); + break; + + case TOKEN_STAND: + delete _standSprite; + _standSprite = NULL; + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) cmd = PARSERR_GENERIC; + else _standSprite = spr; + break; + + case TOKEN_TURN_LEFT: + delete _turnLeftSprite; + _turnLeftSprite = NULL; + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; + else _turnLeftSprite = spr; + break; + + case TOKEN_TURN_RIGHT: + delete _turnRightSprite; + _turnRightSprite = NULL; + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; + else _turnRightSprite = spr; + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new CBSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_SOUND_VOLUME: + parser.scanStr((char *)params, "%d", &_sFXVolume); + break; + + case TOKEN_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _scale = (float)s; + + } + break; + + case TOKEN_RELATIVE_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _relativeScale = (float)s; + + } + break; + + case TOKEN_SOUND_PANNING: + parser.scanStr((char *)params, "%b", &_autoSoundPanning); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_BLOCKED_REGION: { + delete _blockRegion; + delete _currentBlockRegion; + _blockRegion = NULL; + _currentBlockRegion = NULL; + CBRegion *rgn = new CBRegion(_gameRef); + CBRegion *crgn = new CBRegion(_gameRef); + if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { + delete _blockRegion; + delete _currentBlockRegion; + _blockRegion = NULL; + _currentBlockRegion = NULL; + cmd = PARSERR_GENERIC; + } else { + _blockRegion = rgn; + _currentBlockRegion = crgn; + _currentBlockRegion->mimic(_blockRegion); + } + } + break; + + case TOKEN_WAYPOINTS: { + delete _wptGroup; + delete _currentWptGroup; + _wptGroup = NULL; + _currentWptGroup = NULL; + CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); + CAdWaypointGroup *cwpt = new CAdWaypointGroup(_gameRef); + if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { + delete _wptGroup; + delete _currentWptGroup; + _wptGroup = NULL; + _currentWptGroup = NULL; + cmd = PARSERR_GENERIC; + } else { + _wptGroup = wpt; + _currentWptGroup = cwpt; + _currentWptGroup->mimic(_wptGroup); + } + } + break; + + case TOKEN_IGNORE_ITEMS: + parser.scanStr((char *)params, "%b", &_ignoreItems); + 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_ANIMATION: { + CAdSpriteSet *Anim = new CAdSpriteSet(_gameRef, this); + if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) cmd = PARSERR_GENERIC; + else _anims.add(Anim); + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ACTOR definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + if (spr) delete spr; + _gameRef->LOG(0, "Error loading ACTOR definition"); + return STATUS_FAILED; + } + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + _state = _nextState = STATE_READY; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::turnTo(TDirection dir) { + int delta1, delta2, delta3, delta; + + delta1 = dir - _dir; + delta2 = dir + NUM_DIRECTIONS - _dir; + delta3 = dir - NUM_DIRECTIONS - _dir; + + delta1 = (abs(delta1) <= abs(delta2)) ? delta1 : delta2; + delta = (abs(delta1) <= abs(delta3)) ? delta1 : delta3; + + // already there? + if (abs(delta) < 2) { + _dir = dir; + _state = _nextState; + _nextState = STATE_READY; + return; + } + + _targetDir = dir; + _state = delta < 0 ? STATE_TURNING_LEFT : STATE_TURNING_RIGHT; + + _tempSprite2 = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::goTo(int x, int y, TDirection afterWalkDir) { + _afterWalkDir = afterWalkDir; + if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) return; + + _path->reset(); + _path->setReady(false); + + _targetPoint->x = x; + _targetPoint->y = y; + + ((CAdGame *)_gameRef)->_scene->correctTargetPoint(_posX, _posY, &_targetPoint->x, &_targetPoint->y, true, this); + + _state = STATE_SEARCHING_PATH; + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::display() { + if (_active) updateSounds(); + + uint32 alpha; + if (_alphaColor != 0) alpha = _alphaColor; + else alpha = _shadowable ? ((CAdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; + + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + + float rotate; + if (_rotatable) { + if (_rotateValid) rotate = _rotate; + else rotate = ((CAdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } else rotate = 0.0f; + + if (_active) displaySpriteAttachments(true); + + if (_currentSprite && _active) { + bool reg = _registrable; + if (_ignoreItems && ((CAdGame *)_gameRef)->_selectedItem) reg = false; + + _currentSprite->display(_posX, + _posY, + reg ? _registerAlias : NULL, + scaleX, + scaleY, + alpha, + rotate, + _blendMode); + + } + + if (_active) displaySpriteAttachments(false); + if (_active && _partEmitter) _partEmitter->display(); + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::update() { + _currentSprite = NULL; + + if (_state == STATE_READY) { + if (_animSprite) { + delete _animSprite; + _animSprite = NULL; + } + if (_animSprite2) { + _animSprite2 = NULL; + } + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = _nextState; + _nextState = STATE_READY; + _currentSprite = _animSprite; + } + + if (_state == STATE_PLAYING_ANIM_SET && _animSprite2 != NULL && _animSprite2->_finished) { + _state = _nextState; + _nextState = STATE_READY; + _currentSprite = _animSprite2; + } + + if (_sentence && _state != STATE_TALKING) _sentence->finish(); + + // default: stand animation + if (!_currentSprite) { + if (_sprite) _currentSprite = _sprite; + else { + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + if (Anim) _currentSprite = Anim->getSprite(_dir); + } + } + } + + bool already_moved = false; + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM_SET: + _currentSprite = _animSprite2; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TURNING_LEFT: + if (_tempSprite2 == NULL || _tempSprite2->_finished) { + if (_dir > 0) _dir = (TDirection)(_dir - 1); + else _dir = (TDirection)(NUM_DIRECTIONS - 1); + + if (_dir == _targetDir) { + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + if (_turnLeftSprite) { + _tempSprite2 = _turnLeftSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_turnLeftAnimName); + if (Anim) _tempSprite2 = Anim->getSprite(_dir); + } + + if (_tempSprite2) { + _tempSprite2->reset(); + if (_tempSprite2->_looping) _tempSprite2->_looping = false; + } + _currentSprite = _tempSprite2; + } + } else _currentSprite = _tempSprite2; + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_TURNING_RIGHT: + if (_tempSprite2 == NULL || _tempSprite2->_finished) { + _dir = (TDirection)(_dir + 1); + + if ((int)_dir >= (int)NUM_DIRECTIONS) _dir = (TDirection)(0); + + if (_dir == _targetDir) { + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + if (_turnRightSprite) { + _tempSprite2 = _turnRightSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_turnRightAnimName); + if (Anim) _tempSprite2 = Anim->getSprite(_dir); + } + + if (_tempSprite2) { + _tempSprite2->reset(); + if (_tempSprite2->_looping) _tempSprite2->_looping = false; + } + _currentSprite = _tempSprite2; + } + } else _currentSprite = _tempSprite2; + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_SEARCHING_PATH: + // keep asking scene for the path + if (((CAdGame *)_gameRef)->_scene->getPath(CBPoint(_posX, _posY), *_targetPoint, _path, this)) + _state = STATE_WAITING_PATH; + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_WAITING_PATH: + // wait until the scene finished the path + if (_path->_ready) followPath(); + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_FOLLOWING_PATH: + getNextStep(); + already_moved = true; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(_dir); + if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + + bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { + if (TimeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } + } else { + _currentSprite = _tempSprite2; + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite && !_animSprite2) { + if (_sprite) _currentSprite = _sprite; + else { + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + if (Anim) _currentSprite = Anim->getSprite(_dir); + } + } + } + break; + default: + error("AdActor::Update - Unhandled enum"); + } + + + if (_currentSprite && !already_moved) { + _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (_currentSprite->_changed) { + _posX += _currentSprite->_moveX; + _posY += _currentSprite->_moveY; + afterMove(); + } + } + + //_gameRef->QuickMessageForm("%s", _currentSprite->_filename); + + updateBlockRegion(); + _ready = (_state == STATE_READY); + + updatePartEmitter(); + updateSpriteAttachments(); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::followPath() { + // skip current position + _path->getFirst(); + while (_path->getCurrent() != NULL) { + if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) break; + _path->getNext(); + } + + // are there points to follow? + if (_path->getCurrent() != NULL) { + _state = STATE_FOLLOWING_PATH;; + initLine(CBPoint(_posX, _posY), *_path->getCurrent()); + } else { + if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); + else _state = STATE_READY; + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::getNextStep() { + if (_walkSprite) { + _currentSprite = _walkSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_walkAnimName); + if (Anim) _currentSprite = Anim->getSprite(_dir); + } + + if (!_currentSprite) return; + + _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (!_currentSprite->_changed) return; + + + int maxStepX, maxStepY; + maxStepX = abs(_currentSprite->_moveX); + maxStepY = abs(_currentSprite->_moveY); + + maxStepX = MAX(maxStepX, maxStepY); + maxStepX = MAX(maxStepX, 1); + + while (_pFCount > 0 && maxStepX >= 0) { + _pFX += _pFStepX; + _pFY += _pFStepY; + + _pFCount--; + maxStepX--; + } + + if (((CAdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX,(int) _pFY, true, this)) { + if (_pFCount == 0) { + _state = _nextState; + _nextState = STATE_READY; + return; + } + goTo(_targetPoint->x, _targetPoint->y); + return; + } + + + _posX = (int)_pFX; + _posY = (int)_pFY; + + afterMove(); + + + if (_pFCount == 0) { + if (_path->getNext() == NULL) { + _posX = _targetPoint->x; + _posY = _targetPoint->y; + + _path->reset(); + if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); + else { + _state = _nextState; + _nextState = STATE_READY; + } + } else initLine(CBPoint(_posX, _posY), *_path->getCurrent()); + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::initLine(CBPoint startPt, CBPoint endPt) { + _pFCount = MAX((abs(endPt.x - startPt.x)) , (abs(endPt.y - startPt.y))); + + _pFStepX = (double)(endPt.x - startPt.x) / _pFCount; + _pFStepY = (double)(endPt.y - startPt.y) / _pFCount; + + _pFX = startPt.x; + _pFY = startPt.y; + + int angle = (int)(atan2((double)(endPt.y - startPt.y), (double)(endPt.x - startPt.x)) * (180 / 3.14)); + + _nextState = STATE_FOLLOWING_PATH; + + turnTo(angleToDirection(angle)); +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdActor::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // GoTo / GoToAsync + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "GoTo") == 0 || strcmp(name, "GoToAsync") == 0) { + stack->correctParams(2); + int X = stack->pop()->getInt(); + int Y = stack->pop()->getInt(); + goTo(X, Y); + if (strcmp(name, "GoToAsync") != 0) script->waitForExclusive(this); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GoToObject / GoToObjectAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GoToObject") == 0 || strcmp(name, "GoToObjectAsync") == 0) { + stack->correctParams(1); + CScValue *Val = stack->pop(); + if (!Val->isNative()) { + script->runtimeError("actor.%s method accepts an entity refrence only", name); + stack->pushNULL(); + return STATUS_OK; + } + CAdObject *Obj = (CAdObject *)Val->getNative(); + if (!Obj || Obj->_type != OBJECT_ENTITY) { + script->runtimeError("actor.%s method accepts an entity refrence only", name); + stack->pushNULL(); + return STATUS_OK; + } + CAdEntity *Ent = (CAdEntity *)Obj; + if (Ent->_walkToX == 0 && Ent->_walkToY == 0) goTo(Ent->_posX, Ent->_posY); + else goTo(Ent->_walkToX, Ent->_walkToY, Ent->_walkToDir); + if (strcmp(name, "GoToObjectAsync") != 0) script->waitForExclusive(this); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnTo / TurnToAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnTo") == 0 || strcmp(name, "TurnToAsync") == 0) { + stack->correctParams(1); + int dir; + CScValue *val = stack->pop(); + + // turn to object? + if (val->isNative() && _gameRef->validObject((CBObject *)val->getNative())) { + CBObject *obj = (CBObject *)val->getNative(); + int angle = (int)(atan2((double)(obj->_posY - _posY), (double)(obj->_posX - _posX)) * (180 / 3.14)); + dir = (int)angleToDirection(angle); + } + // otherwise turn to direction + else dir = val->getInt(); + + if (dir >= 0 && dir < NUM_DIRECTIONS) { + turnTo((TDirection)dir); + if (strcmp(name, "TurnToAsync") != 0) script->waitForExclusive(this); + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsWalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsWalking") == 0) { + stack->correctParams(0); + stack->pushBool(_state == STATE_FOLLOWING_PATH); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // MergeAnims + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MergeAnims") == 0) { + stack->correctParams(1); + stack->pushBool(DID_SUCCEED(mergeAnims(stack->pop()->getString()))); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadAnim") == 0) { + stack->correctParams(1); + const char *AnimName = stack->pop()->getString(); + + bool Found = false; + for (int i = 0; i < _anims.getSize(); i++) { + if (scumm_stricmp(_anims[i]->_name, AnimName) == 0) { + // invalidate sprites in use + if (_anims[i]->containsSprite(_tempSprite2)) _tempSprite2 = NULL; + if (_anims[i]->containsSprite(_currentSprite)) _currentSprite = NULL; + if (_anims[i]->containsSprite(_animSprite2)) _animSprite2 = NULL; + + delete _anims[i]; + _anims[i] = NULL; + _anims.removeAt(i); + i--; + Found = true; + } + } + stack->pushBool(Found); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // HasAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasAnim") == 0) { + stack->correctParams(1); + const char *AnimName = stack->pop()->getString(); + stack->pushBool(getAnimByName(AnimName) != NULL); + return STATUS_OK; + } + + else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdActor::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Direction + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Direction") == 0) { + _scValue->setInt(_dir); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Type") == 0) { + _scValue->setString("actor"); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // TalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkAnimName") == 0) { + _scValue->setString(_talkAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkAnimName") == 0) { + _scValue->setString(_walkAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // IdleAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IdleAnimName") == 0) { + _scValue->setString(_idleAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnLeftAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnLeftAnimName") == 0) { + _scValue->setString(_turnLeftAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnRightAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnRightAnimName") == 0) { + _scValue->setString(_turnRightAnimName); + return _scValue; + } + + else return CAdTalkHolder::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Direction + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Direction") == 0) { + int dir = value->getInt(); + if (dir >= 0 && dir < NUM_DIRECTIONS) _dir = (TDirection)dir; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkAnimName") == 0) { + if (value->isNULL()) _talkAnimName = "talk"; + else _talkAnimName = value->getString(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkAnimName") == 0) { + if (value->isNULL()) _walkAnimName = "walk"; + else _walkAnimName = value->getString(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IdleAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IdleAnimName") == 0) { + if (value->isNULL()) _idleAnimName = "idle"; + else _idleAnimName = value->getString(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnLeftAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnLeftAnimName") == 0) { + if (value->isNULL()) _turnLeftAnimName = "turnleft"; + else _turnLeftAnimName = value->getString(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnRightAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnRightAnimName") == 0) { + if (value->isNULL()) _turnRightAnimName = "turnright"; + else _turnRightAnimName = value->getString(); + return STATUS_OK; + } + + else return CAdTalkHolder::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdActor::scToString() { + return "[actor object]"; +} + + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdActor::getTalkStance(const char *stance) { + // forced stance? + if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { + _forcedTalkAnimUsed = true; + delete _animSprite; + _animSprite = new CBSprite(_gameRef, this); + if (_animSprite) { + bool res = _animSprite->loadFile(_forcedTalkAnimName); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "CAdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); + delete _animSprite; + _animSprite = NULL; + } else return _animSprite; + } + } + + // old way + if (_talkSprites.getSize() > 0 || _talkSpritesEx.getSize() > 0) + return getTalkStanceOld(stance); + + // new way + CBSprite *ret = NULL; + + // do we have an animation with this name? + CAdSpriteSet *Anim = getAnimByName(stance); + if (Anim) ret = Anim->getSprite(_dir); + + // not - get a random talk + if (!ret) { + CBArray TalkAnims; + for (int i = 0; i < _anims.getSize(); i++) { + if (_talkAnimName.compareToIgnoreCase(_anims[i]->_name) == 0) + TalkAnims.add(_anims[i]); + } + + if (TalkAnims.getSize() > 0) { + int rnd = g_wintermute->randInt(0, TalkAnims.getSize() - 1); + ret = TalkAnims[rnd]->getSprite(_dir); + } else { + if (_standSprite) ret = _standSprite->getSprite(_dir); + else { + Anim = getAnimByName(_idleAnimName); + if (Anim) ret = Anim->getSprite(_dir); + } + } + } + return ret; +} + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdActor::getTalkStanceOld(const char *stance) { + CBSprite *ret = NULL; + + if (stance != NULL) { + // search special stances + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->_name, stance) == 0) { + ret = _talkSpritesEx[i]->getSprite(_dir); + break; + } + } + if (ret == NULL) { + // search generic stances + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (scumm_stricmp(_talkSprites[i]->_name, stance) == 0) { + ret = _talkSprites[i]->getSprite(_dir); + break; + } + } + } + } + + // not a valid stance? get a random one + if (ret == NULL) { + if (_talkSprites.getSize() < 1) ret = _standSprite->getSprite(_dir); + else { + // TODO: remember last + int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); + ret = _talkSprites[rnd]->getSprite(_dir); + } + } + + return ret; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::persist(CBPersistMgr *persistMgr) { + CAdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER_INT(_dir)); + persistMgr->transfer(TMEMBER(_path)); + persistMgr->transfer(TMEMBER(_pFCount)); + persistMgr->transfer(TMEMBER(_pFStepX)); + persistMgr->transfer(TMEMBER(_pFStepY)); + persistMgr->transfer(TMEMBER(_pFX)); + persistMgr->transfer(TMEMBER(_pFY)); + persistMgr->transfer(TMEMBER(_standSprite)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + persistMgr->transfer(TMEMBER_INT(_targetDir)); + persistMgr->transfer(TMEMBER_INT(_afterWalkDir)); + persistMgr->transfer(TMEMBER(_targetPoint)); + persistMgr->transfer(TMEMBER(_turnLeftSprite)); + persistMgr->transfer(TMEMBER(_turnRightSprite)); + persistMgr->transfer(TMEMBER(_walkSprite)); + + persistMgr->transfer(TMEMBER(_animSprite2)); + persistMgr->transfer(TMEMBER(_talkAnimName)); + persistMgr->transfer(TMEMBER(_idleAnimName)); + persistMgr->transfer(TMEMBER(_walkAnimName)); + persistMgr->transfer(TMEMBER(_turnLeftAnimName)); + persistMgr->transfer(TMEMBER(_turnRightAnimName)); + + _anims.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +TDirection CAdActor::angleToDirection(int angle) { + TDirection ret = DI_DOWN;; + + if (angle > -112 && angle <= -67) ret = DI_UP; + else if (angle > -67 && angle <= -22) ret = DI_UPRIGHT; + else if (angle > -22 && angle <= 22) ret = DI_RIGHT; + else if (angle > 22 && angle <= 67) ret = DI_DOWNRIGHT; + else if (angle > 67 && angle <= 112) ret = DI_DOWN; + else if (angle > 112 && angle <= 157) ret = DI_DOWNLEFT; + else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) ret = DI_LEFT; + else if (angle > -157 && angle <= -112) ret = DI_UPLEFT; + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdActor::getHeight() { + // if no current sprite is set, set some + if (_currentSprite == NULL) { + if (_standSprite) _currentSprite = _standSprite->getSprite(_dir); + else { + CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + if (Anim) _currentSprite = Anim->getSprite(_dir); + } + } + // and get height + return CAdTalkHolder::getHeight(); +} + + +////////////////////////////////////////////////////////////////////////// +CAdSpriteSet *CAdActor::getAnimByName(const Common::String &animName) { + for (int i = 0; i < _anims.getSize(); i++) { + if (animName.compareToIgnoreCase(_anims[i]->_name) == 0) + return _anims[i]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::mergeAnims(const char *animsFilename) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ANIMATION) + TOKEN_TABLE_END + + + byte *fileBuffer = _gameRef->_fileManager->readWholeFile(animsFilename); + if (fileBuffer == NULL) { + _gameRef->LOG(0, "CAdActor::MergeAnims failed for file '%s'", animsFilename); + return STATUS_FAILED; + } + + byte *buffer = fileBuffer; + byte *params; + int cmd; + CBParser parser(_gameRef); + + bool Ret = STATUS_OK; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_ANIMATION: { + CAdSpriteSet *Anim = new CAdSpriteSet(_gameRef, this); + if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + Ret = STATUS_FAILED; + } else _anims.add(Anim); + } + break; + } + } + delete [] fileBuffer; + return Ret; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::playAnim(const char *filename) { + // if we have an anim with this name, use it + CAdSpriteSet *Anim = getAnimByName(filename); + if (Anim) { + _animSprite2 = Anim->getSprite(_dir); + if (_animSprite2) { + _animSprite2->reset(); + _state = STATE_PLAYING_ANIM_SET; + return STATUS_OK; + } + } + // otherwise call the standard handler + return CAdTalkHolder::playAnim(filename); +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdActor.h b/engines/wintermute/ad/AdActor.h new file mode 100644 index 0000000000..1be8b8131d --- /dev/null +++ b/engines/wintermute/ad/AdActor.h @@ -0,0 +1,107 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADACTOR_H +#define WINTERMUTE_ADACTOR_H + + +#include "engines/wintermute/dctypes.h" // Added by ClassView +#include "engines/wintermute/ad/AdTypes.h" // Added by ClassView +#include "engines/wintermute/ad/AdTalkHolder.h" +#include "engines/wintermute/base/BPoint.h" // Added by ClassView +#include "engines/wintermute/persistent.h" +#include "common/str.h" + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +namespace WinterMute { +class CAdSpriteSet; +class CAdPath; +class CAdActor : public CAdTalkHolder { +public: + TDirection angleToDirection(int angle); + DECLARE_PERSISTENT(CAdActor, CAdTalkHolder) + virtual int getHeight(); + CBSprite *getTalkStance(const char *stance); + virtual void goTo(int x, int y, TDirection afterWalkDir = DI_NONE); + CBPoint *_targetPoint; + virtual bool update(); + virtual bool display(); + TDirection _targetDir; + TDirection _afterWalkDir; + virtual void turnTo(TDirection dir); + CAdPath *_path; + CAdSpriteSet *_walkSprite; + CAdSpriteSet *_standSprite; + CAdSpriteSet *_turnLeftSprite; + CAdSpriteSet *_turnRightSprite; + CBArray _talkSprites; + CBArray _talkSpritesEx; + TDirection _dir; + CAdActor(CBGame *inGame/*=NULL*/); + virtual ~CAdActor(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + + // new anim system + Common::String _talkAnimName; + Common::String _idleAnimName; + Common::String _walkAnimName; + Common::String _turnLeftAnimName; + Common::String _turnRightAnimName; + CBArray _anims; + virtual bool playAnim(const char *filename); + CAdSpriteSet *getAnimByName(const Common::String &animName); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + +private: + bool setDefaultAnimNames(); + CBSprite *getTalkStanceOld(const char *stance); + bool mergeAnims(const char *animsFilename); + CBSprite *_animSprite2; + + void initLine(CBPoint startPt, CBPoint endPt); + void getNextStep(); + void followPath(); + double _pFStepX; + double _pFStepY; + double _pFX; + double _pFY; + int _pFCount; +}; + +} // end of namespace WinterMute + +#endif // WINTERMUTE_ADACTOR_H diff --git a/engines/wintermute/ad/AdEntity.cpp b/engines/wintermute/ad/AdEntity.cpp new file mode 100644 index 0000000000..c559e99abb --- /dev/null +++ b/engines/wintermute/ad/AdEntity.cpp @@ -0,0 +1,1027 @@ +/* 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. + + * 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. + + * 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 + */ + + + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdEntity.h" +#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" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdScene.h" +#include "engines/wintermute/base/BSound.h" +#include "engines/wintermute/ad/AdWaypointGroup.h" +#include "engines/wintermute/base/font/BFontStorage.h" +#include "engines/wintermute/base/font/BFont.h" +#include "engines/wintermute/ad/AdSentence.h" +#include "engines/wintermute/base/BRegion.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/video/VidTheoraPlayer.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdEntity, false) + +////////////////////////////////////////////////////////////////////////// +CAdEntity::CAdEntity(CBGame *inGame): CAdTalkHolder(inGame) { + _type = OBJECT_ENTITY; + _subtype = ENTITY_NORMAL; + _region = NULL; + _item = NULL; + + _walkToX = _walkToY = 0; + _walkToDir = DI_NONE; + + _theora = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdEntity::~CAdEntity() { + _gameRef->unregisterObject(_region); + + delete _theora; + _theora = NULL; + + delete[] _item; + _item = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdEntity::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->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 +////////////////////////////////////////////////////////////////////////// +bool 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(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY) { + _gameRef->LOG(0, "'ENTITY' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + CAdGame *adGame = (CAdGame *)_gameRef; + 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 (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_SPRITE: { + delete _sprite; + _sprite = NULL; + spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params))) cmd = PARSERR_GENERIC; + else _sprite = spr; + } + break; + + case TOKEN_TALK: { + spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSprites.add(spr); + } + break; + + case TOKEN_TALK_SPECIAL: { + spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSpritesEx.add(spr); + } + 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: + parser.scanStr((char *)params, "%b", &_zoomable); + break; + + case TOKEN_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _scale = (float)s; + + } + break; + + case TOKEN_RELATIVE_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _relativeScale = (float)s; + + } + break; + + case TOKEN_ROTABLE: + case TOKEN_ROTATABLE: + parser.scanStr((char *)params, "%b", &_rotatable); + break; + + case TOKEN_REGISTRABLE: + case TOKEN_INTERACTIVE: + parser.scanStr((char *)params, "%b", &_registrable); + break; + + case TOKEN_SHADOWABLE: + case TOKEN_COLORABLE: + parser.scanStr((char *)params, "%b", &_shadowable); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new CBSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_REGION: { + if (_region) _gameRef->unregisterObject(_region); + _region = NULL; + CBRegion *rgn = new CBRegion(_gameRef); + if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) cmd = PARSERR_GENERIC; + else { + _region = rgn; + _gameRef->registerObject(_region); + } + } + break; + + case TOKEN_BLOCKED_REGION: { + delete _blockRegion; + _blockRegion = NULL; + delete _currentBlockRegion; + _currentBlockRegion = NULL; + CBRegion *rgn = new CBRegion(_gameRef); + CBRegion *crgn = new CBRegion(_gameRef); + if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { + delete _blockRegion; + _blockRegion = NULL; + delete _currentBlockRegion; + _currentBlockRegion = NULL; + cmd = PARSERR_GENERIC; + } else { + _blockRegion = rgn; + _currentBlockRegion = crgn; + _currentBlockRegion->mimic(_blockRegion); + } + } + break; + + case TOKEN_WAYPOINTS: { + delete _wptGroup; + _wptGroup = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); + CAdWaypointGroup *cwpt = new CAdWaypointGroup(_gameRef); + if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { + delete _wptGroup; + _wptGroup = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + cmd = PARSERR_GENERIC; + } else { + _wptGroup = wpt; + _currentWptGroup = cwpt; + _currentWptGroup->mimic(_wptGroup); + } + } + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_SUBTYPE: { + if (scumm_stricmp((char *)params, "sound") == 0) { + delete _sprite; + _sprite = NULL; + if (_gameRef->_editorMode) { + spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) cmd = PARSERR_GENERIC; + else _sprite = spr; + } + if (_gameRef->_editorMode) _editorOnly = true; + _zoomable = false; + _rotatable = false; + _registrable = _gameRef->_editorMode; + _shadowable = false; + _subtype = ENTITY_SOUND; + } + } + break; + + case TOKEN_SOUND: + playSFX((char *)params, false, false); + break; + + case TOKEN_SOUND_START_TIME: + parser.scanStr((char *)params, "%d", &_sFXStart); + break; + + case TOKEN_SOUND_VOLUME: + parser.scanStr((char *)params, "%d", &_sFXVolume); + break; + + case TOKEN_SOUND_PANNING: + parser.scanStr((char *)params, "%b", &_autoSoundPanning); + break; + + case TOKEN_SAVE_STATE: + parser.scanStr((char *)params, "%b", &_saveState); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_IGNORE_ITEMS: + parser.scanStr((char *)params, "%b", &_ignoreItems); + 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: + parser.scanStr((char *)params, "%d", &_walkToX); + break; + + case TOKEN_WALK_TO_Y: + parser.scanStr((char *)params, "%d", &_walkToY); + 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; + _walkToDir = (TDirection)i; + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ENTITY definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ENTITY definition"); + if (spr) delete spr; + return STATUS_FAILED; + } + + if (_region && _sprite) { + _gameRef->LOG(0, "Warning: Entity '%s' has both sprite and region.", _name); + } + + updatePosition(); + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + _state = STATE_READY; + + if (_item && ((CAdGame *)_gameRef)->isItemTaken(_item)) _active = false; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::display() { + if (_active) { + updateSounds(); + + uint32 Alpha; + if (_alphaColor != 0) Alpha = _alphaColor; + else Alpha = _shadowable ? ((CAdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; + + float ScaleX, ScaleY; + getScale(&ScaleX, &ScaleY); + + float Rotate; + if (_rotatable) { + if (_rotateValid) Rotate = _rotate; + else Rotate = ((CAdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } else Rotate = 0.0f; + + + bool Reg = _registrable; + if (_ignoreItems && ((CAdGame *)_gameRef)->_selectedItem) Reg = false; + + if (_region && (Reg || _editorAlwaysRegister)) { + _gameRef->_renderer->_rectList.add(new CBActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); + } + + displaySpriteAttachments(true); + if (_theora && (_theora->isPlaying() || _theora->isPaused())) { + _theora->display(Alpha); + } else if (_currentSprite) { + _currentSprite->display(_posX, + _posY, + (Reg || _editorAlwaysRegister) ? _registerAlias : NULL, + ScaleX, + ScaleY, + Alpha, + Rotate, + _blendMode); + } + displaySpriteAttachments(false); + + if (_partEmitter) _partEmitter->display(_region); + + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::update() { + _currentSprite = NULL; + + if (_state == STATE_READY && _animSprite) { + delete _animSprite; + _animSprite = NULL; + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = STATE_READY; + _currentSprite = _animSprite; + } + + if (_sentence && _state != STATE_TALKING) _sentence->finish(); + + // default: stand animation + if (!_currentSprite) _currentSprite = _sprite; + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite) + _currentSprite = _sprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(); + if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + + bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { + if (TimeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + } + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } else { + _currentSprite = _tempSprite2; + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } + break; + default: // Silence unhandled enum-warning + break; + } + + + if (_currentSprite) { + _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (_currentSprite->_changed) { + _posX += _currentSprite->_moveX; + _posY += _currentSprite->_moveY; + } + } + + updateBlockRegion(); + _ready = (_state == STATE_READY); + + if (_theora) { + int OffsetX, OffsetY; + _gameRef->getOffset(&OffsetX, &OffsetY); + _theora->_posX = _posX - OffsetX; + _theora->_posY = _posY - OffsetY; + + _theora->update(); + if (_theora->isFinished()) { + _theora->stop(); + delete _theora; + _theora = NULL; + } + } + + updatePartEmitter(); + updateSpriteAttachments(); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // StopSound + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "StopSound") == 0 && _subtype == ENTITY_SOUND) { + stack->correctParams(0); + + if (DID_FAIL(stopSFX(false))) stack->pushBool(false); + else stack->pushBool(true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PlayTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PlayTheora") == 0) { + stack->correctParams(4); + const char *filename = stack->pop()->getString(); + bool looping = stack->pop()->getBool(false); + CScValue *valAlpha = stack->pop(); + int startTime = stack->pop()->getInt(); + + delete _theora; + _theora = new CVidTheoraPlayer(_gameRef); + if (_theora && DID_SUCCEED(_theora->initialize(filename))) { + if (!valAlpha->isNULL()) _theora->setAlphaImage(valAlpha->getString()); + _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); + //if(m_Scale>=0) m_Theora->m_PlayZoom = m_Scale; + stack->pushBool(true); + } else { + script->runtimeError("Entity.PlayTheora - error playing video '%s'", filename); + stack->pushBool(false); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StopTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StopTheora") == 0) { + stack->correctParams(0); + if (_theora) { + _theora->stop(); + delete _theora; + _theora = NULL; + stack->pushBool(true); + } else stack->pushBool(false); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTheoraPlaying + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTheoraPlaying") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPlaying()) stack->pushBool(true); + else stack->pushBool(false); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PauseTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PauseTheora") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPlaying()) { + _theora->pause(); + stack->pushBool(true); + } else stack->pushBool(false); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ResumeTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResumeTheora") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPaused()) { + _theora->resume(); + stack->pushBool(true); + } else stack->pushBool(false); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTheoraPaused + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTheoraPaused") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPaused()) stack->pushBool(true); + else stack->pushBool(false); + + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // CreateRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateRegion") == 0) { + stack->correctParams(0); + if (!_region) { + _region = new CBRegion(_gameRef); + _gameRef->registerObject(_region); + } + if (_region) stack->pushNative(_region, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteRegion") == 0) { + stack->correctParams(0); + if (_region) { + _gameRef->unregisterObject(_region); + _region = NULL; + stack->pushBool(true); + } else stack->pushBool(false); + + return STATUS_OK; + } + + else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdEntity::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type (RO) + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("entity"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Item") == 0) { + if (_item) _scValue->setString(_item); + else _scValue->setNULL(); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Subtype (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Subtype") == 0) { + if (_subtype == ENTITY_SOUND) + _scValue->setString("sound"); + else + _scValue->setString("normal"); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToX") == 0) { + _scValue->setInt(_walkToX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToY") == 0) { + _scValue->setInt(_walkToY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToDirection + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToDirection") == 0) { + _scValue->setInt((int)_walkToDir); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Region (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Region") == 0) { + if (_region) _scValue->setNative(_region, true); + else _scValue->setNULL(); + return _scValue; + } + + else return CAdTalkHolder::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::scSetProperty(const char *name, CScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Item") == 0) { + setItem(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToX") == 0) { + _walkToX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToY") == 0) { + _walkToY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToDirection + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToDirection") == 0) { + int dir = value->getInt(); + if (dir >= 0 && dir < NUM_DIRECTIONS) _walkToDir = (TDirection)dir; + return STATUS_OK; + } + + else return CAdTalkHolder::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdEntity::scToString() { + return "[entity object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ENTITY {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + if (_subtype == ENTITY_SOUND) + buffer->putTextIndent(indent + 2, "SUBTYPE=\"SOUND\"\n"); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + 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); + + int i; + + for (i = 0; i < _scripts.getSize(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_subtype == ENTITY_NORMAL && _sprite && _sprite->_filename) + buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->_filename); + + 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); + } + + + if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) + buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alphaColor), RGBCOLGetG(_alphaColor), RGBCOLGetB(_alphaColor)); + + if (RGBCOLGetA(_alphaColor) != 0) + buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alphaColor)); + + if (_scale >= 0) + buffer->putTextIndent(indent + 2, "SCALE = %d\n", (int)_scale); + + if (_relativeScale != 0) + buffer->putTextIndent(indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale); + + if (_font && _font->_filename) + buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->_filename); + + if (_cursor && _cursor->_filename) + buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); + + CAdTalkHolder::saveAsText(buffer, indent + 2); + + if (_region) _region->saveAsText(buffer, indent + 2); + + if (_scProp) _scProp->saveAsText(buffer, indent + 2); + + CAdObject::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdEntity::getHeight() { + if (_region && !_sprite) { + return _region->_rect.bottom - _region->_rect.top; + } else { + if (_currentSprite == NULL) _currentSprite = _sprite; + return CAdObject::getHeight(); + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdEntity::updatePosition() { + if (_region && !_sprite) { + _posX = _region->_rect.left + (_region->_rect.right - _region->_rect.left) / 2; + _posY = _region->_rect.bottom; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::persist(CBPersistMgr *persistMgr) { + CAdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_item)); + persistMgr->transfer(TMEMBER(_region)); + //persistMgr->transfer(TMEMBER(_sprite)); + persistMgr->transfer(TMEMBER_INT(_subtype)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_walkToX)); + persistMgr->transfer(TMEMBER(_walkToY)); + persistMgr->transfer(TMEMBER_INT(_walkToDir)); + + persistMgr->transfer(TMEMBER(_theora)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdEntity::setItem(const char *itemName) { + CBUtils::setString(&_item, itemName); +} + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::setSprite(const char *filename) { + bool setCurrent = false; + if (_currentSprite == _sprite) { + _currentSprite = NULL; + setCurrent = true; + } + + delete _sprite; + _sprite = NULL; + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + delete _sprite; + _sprite = NULL; + return STATUS_FAILED; + } else { + _sprite = spr; + _currentSprite = _sprite; + return STATUS_OK; + } +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdEntity.h b/engines/wintermute/ad/AdEntity.h new file mode 100644 index 0000000000..a260ca3329 --- /dev/null +++ b/engines/wintermute/ad/AdEntity.h @@ -0,0 +1,68 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADENTITY_H +#define WINTERMUTE_ADENTITY_H + +#include "engines/wintermute/ad/AdTalkHolder.h" + +namespace WinterMute { +class CVidTheoraPlayer; +class CAdEntity : public CAdTalkHolder { +public: + CVidTheoraPlayer *_theora; + bool setSprite(const char *filename); + int _walkToX; + int _walkToY; + TDirection _walkToDir; + void setItem(const char *itemName); + char *_item; + DECLARE_PERSISTENT(CAdEntity, CAdTalkHolder) + void updatePosition(); + virtual int getHeight(); + CBRegion *_region; + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + virtual bool update(); + virtual bool display(); + CAdEntity(CBGame *inGame); + virtual ~CAdEntity(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + TEntityType _subtype; + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdGame.cpp b/engines/wintermute/ad/AdGame.cpp new file mode 100644 index 0000000000..87e3fe14d9 --- /dev/null +++ b/engines/wintermute/ad/AdGame.cpp @@ -0,0 +1,2061 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdActor.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdEntity.h" +#include "engines/wintermute/ad/AdInventory.h" +#include "engines/wintermute/ad/AdInventoryBox.h" +#include "engines/wintermute/ad/AdItem.h" +#include "engines/wintermute/ad/AdResponse.h" +#include "engines/wintermute/ad/AdResponseBox.h" +#include "engines/wintermute/ad/AdResponseContext.h" +#include "engines/wintermute/ad/AdScene.h" +#include "engines/wintermute/ad/AdSceneState.h" +#include "engines/wintermute/ad/AdSentence.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/base/font/BFont.h" +#include "engines/wintermute/base/BObject.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BSound.h" +#include "engines/wintermute/base/BStringTable.h" +#include "engines/wintermute/base/BSurfaceStorage.h" +#include "engines/wintermute/base/BTransitionMgr.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/base/BViewport.h" +#include "engines/wintermute/base/particles/PartEmitter.h" +#include "engines/wintermute/base/scriptables/ScEngine.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "engines/wintermute/ui/UIEntity.h" +#include "engines/wintermute/ui/UIWindow.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/video/VidPlayer.h" +#include "engines/wintermute/video/VidTheoraPlayer.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdGame, true) + +////////////////////////////////////////////////////////////////////////// +CAdGame::CAdGame(): CBGame() { + _responseBox = NULL; + _inventoryBox = NULL; + + _scene = new CAdScene(_gameRef); + _scene->setName(""); + registerObject(_scene); + + _prevSceneName = NULL; + _prevSceneFilename = NULL; + _scheduledScene = NULL; + _scheduledFadeIn = false; + + + _stateEx = GAME_NORMAL; + + _selectedItem = NULL; + + + _texItemLifeTime = 10000; + _texWalkLifeTime = 10000; + _texStandLifeTime = 10000; + _texTalkLifeTime = 10000; + + _talkSkipButton = TALK_SKIP_LEFT; + + _sceneViewport = NULL; + + _initialScene = true; + _debugStartupScene = NULL; + _startupScene = NULL; + + _invObject = new CAdObject(this); + _inventoryOwner = _invObject; + + _tempDisableSaveState = false; + _itemsFile = NULL; + + _smartItemCursor = false; + + addSpeechDir("speech"); +} + + +////////////////////////////////////////////////////////////////////////// +CAdGame::~CAdGame() { + cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::cleanup() { + int i; + + for (i = 0; i < _objects.getSize(); i++) { + unregisterObject(_objects[i]); + _objects[i] = NULL; + } + _objects.removeAll(); + + + for (i = 0; i < _dlgPendingBranches.getSize(); i++) { + delete [] _dlgPendingBranches[i]; + } + _dlgPendingBranches.removeAll(); + + for (i = 0; i < _speechDirs.getSize(); i++) { + delete [] _speechDirs[i]; + } + _speechDirs.removeAll(); + + + unregisterObject(_scene); + _scene = NULL; + + // remove items + for (i = 0; i < _items.getSize(); i++) _gameRef->unregisterObject(_items[i]); + _items.removeAll(); + + + // clear remaining inventories + delete _invObject; + _invObject = NULL; + + for (i = 0; i < _inventories.getSize(); i++) { + delete _inventories[i]; + } + _inventories.removeAll(); + + + if (_responseBox) { + _gameRef->unregisterObject(_responseBox); + _responseBox = NULL; + } + + if (_inventoryBox) { + _gameRef->unregisterObject(_inventoryBox); + _inventoryBox = NULL; + } + + delete[] _prevSceneName; + delete[] _prevSceneFilename; + delete[] _scheduledScene; + delete[] _debugStartupScene; + delete[] _itemsFile; + _prevSceneName = NULL; + _prevSceneFilename = NULL; + _scheduledScene = NULL; + _debugStartupScene = NULL; + _startupScene = NULL; + _itemsFile = NULL; + + delete _sceneViewport; + _sceneViewport = NULL; + + for (i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; + _sceneStates.removeAll(); + + for (i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + _responsesBranch.removeAll(); + + for (i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; + _responsesGame.removeAll(); + + return CBGame::cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::initLoop() { + if (_scheduledScene && _transMgr->isReady()) { + changeScene(_scheduledScene, _scheduledFadeIn); + delete[] _scheduledScene; + _scheduledScene = NULL; + + _gameRef->_activeObject = NULL; + } + + + bool res; + res = CBGame::initLoop(); + if (DID_FAIL(res)) return res; + + if (_scene) res = _scene->initLoop(); + + _sentences.removeAll(); + + return res; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addObject(CAdObject *object) { + _objects.add(object); + return registerObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::removeObject(CAdObject *object) { + // in case the user called Scene.CreateXXX() and Game.DeleteXXX() + if (_scene) { + bool Res = _scene->removeObject(object); + if (DID_SUCCEED(Res)) return Res; + } + + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i] == object) { + _objects.removeAt(i); + break; + } + } + return unregisterObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::changeScene(const char *filename, bool fadeIn) { + if (_scene == NULL) { + _scene = new CAdScene(_gameRef); + registerObject(_scene); + } else { + _scene->applyEvent("SceneShutdown", true); + + setPrevSceneName(_scene->_name); + setPrevSceneFilename(_scene->_filename); + + if (!_tempDisableSaveState) _scene->saveState(); + _tempDisableSaveState = false; + } + + if (_scene) { + // reset objects + for (int i = 0; i < _objects.getSize(); i++) _objects[i]->reset(); + + // reset scene properties + _scene->_sFXVolume = 100; + if (_scene->_scProp) _scene->_scProp->cleanup(); + + bool ret; + if (_initialScene && _debugDebugMode && _debugStartupScene) { + _initialScene = false; + ret = _scene->loadFile(_debugStartupScene); + } else ret = _scene->loadFile(filename); + + if (DID_SUCCEED(ret)) { + // invalidate references to the original scene + for (int i = 0; i < _objects.getSize(); i++) { + _objects[i]->invalidateCurrRegions(); + _objects[i]->_stickRegion = NULL; + } + + _scene->loadState(); + } + if (fadeIn) _gameRef->_transMgr->start(TRANSITION_FADE_IN); + return ret; + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdGame::addSentence(CAdSentence *sentence) { + _sentences.add(sentence); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::displaySentences(bool frozen) { + for (int i = 0; i < _sentences.getSize(); i++) { + if (frozen && _sentences[i]->_freezable) continue; + else _sentences[i]->display(); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdGame::finishSentences() { + for (int i = 0; i < _sentences.getSize(); i++) { + if (_sentences[i]->CanSkip()) { + _sentences[i]->_duration = 0; + if (_sentences[i]->_sound) _sentences[i]->_sound->stop(); + } + } +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // ChangeScene + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "ChangeScene") == 0) { + stack->correctParams(3); + const char *filename = stack->pop()->getString(); + CScValue *valFadeOut = stack->pop(); + CScValue *valFadeIn = stack->pop(); + + bool transOut = valFadeOut->isNULL() ? true : valFadeOut->getBool(); + bool transIn = valFadeIn->isNULL() ? true : valFadeIn->getBool(); + + scheduleChangeScene(filename, transIn); + if (transOut) _transMgr->start(TRANSITION_FADE_OUT, true); + stack->pushNULL(); + + + //bool ret = ChangeScene(stack->pop()->getString()); + //if(DID_FAIL(ret)) stack->pushBool(false); + //else stack->pushBool(true); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadActor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadActor") == 0) { + stack->correctParams(1); + CAdActor *act = new CAdActor(_gameRef); + if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { + addObject(act); + stack->pushNative(act, true); + } else { + delete act; + act = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadEntity") == 0) { + stack->correctParams(1); + CAdEntity *ent = new CAdEntity(_gameRef); + if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { + addObject(ent); + stack->pushNative(ent, true); + } else { + delete ent; + ent = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadObject / UnloadActor / UnloadEntity / DeleteEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "DeleteEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + CAdObject *obj = (CAdObject *)val->getNative(); + removeObject(obj); + if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdEntity *ent = new CAdEntity(_gameRef); + addObject(ent); + if (!val->isNULL()) ent->setName(val->getString()); + stack->pushNative(ent, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateItem") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdItem *item = new CAdItem(_gameRef); + addItem(item); + if (!val->isNULL()) item->setName(val->getString()); + stack->pushNative(item, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteItem") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdItem *item = NULL; + if (val->isNative()) item = (CAdItem *)val->getNative(); + else item = getItemByName(val->getString()); + + if (item) { + deleteItem(item); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // QueryItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "QueryItem") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdItem *item = NULL; + if (val->isInt()) { + int index = val->getInt(); + if (index >= 0 && index < _items.getSize()) item = _items[index]; + } else { + item = getItemByName(val->getString()); + } + + if (item) stack->pushNative(item, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // AddResponse/AddResponseOnce/AddResponseOnceGame + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddResponse") == 0 || strcmp(name, "AddResponseOnce") == 0 || strcmp(name, "AddResponseOnceGame") == 0) { + stack->correctParams(6); + int id = stack->pop()->getInt(); + const char *text = stack->pop()->getString(); + CScValue *val1 = stack->pop(); + CScValue *val2 = stack->pop(); + CScValue *val3 = stack->pop(); + CScValue *val4 = stack->pop(); + + if (_responseBox) { + CAdResponse *res = new CAdResponse(_gameRef); + if (res) { + res->_iD = id; + res->setText(text); + _stringTable->expand(&res->_text); + if (!val1->isNULL()) res->setIcon(val1->getString()); + if (!val2->isNULL()) res->setIconHover(val2->getString()); + if (!val3->isNULL()) res->setIconPressed(val3->getString()); + if (!val4->isNULL()) res->setFont(val4->getString()); + + if (strcmp(name, "AddResponseOnce") == 0) res->_responseType = RESPONSE_ONCE; + else if (strcmp(name, "AddResponseOnceGame") == 0) res->_responseType = RESPONSE_ONCE_GAME; + + _responseBox->_responses.add(res); + } + } else { + script->runtimeError("Game.AddResponse: response box is not defined"); + } + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ResetResponse + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResetResponse") == 0) { + stack->correctParams(1); + int ID = stack->pop()->getInt(-1); + resetResponse(ID); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ClearResponses + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ClearResponses") == 0) { + stack->correctParams(0); + _responseBox->clearResponses(); + _responseBox->clearButtons(); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetResponse + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetResponse") == 0) { + stack->correctParams(1); + bool autoSelectLast = stack->pop()->getBool(); + + if (_responseBox) { + _responseBox->weedResponses(); + + if (_responseBox->_responses.getSize() == 0) { + stack->pushNULL(); + return STATUS_OK; + } + + + if (_responseBox->_responses.getSize() == 1 && autoSelectLast) { + stack->pushInt(_responseBox->_responses[0]->_iD); + _responseBox->handleResponse(_responseBox->_responses[0]); + _responseBox->clearResponses(); + return STATUS_OK; + } + + _responseBox->createButtons(); + _responseBox->_waitingScript = script; + script->waitForExclusive(_responseBox); + _state = GAME_SEMI_FROZEN; + _stateEx = GAME_WAITING_RESPONSE; + } else { + script->runtimeError("Game.GetResponse: response box is not defined"); + stack->pushNULL(); + } + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // GetNumResponses + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNumResponses") == 0) { + stack->correctParams(0); + if (_responseBox) { + _responseBox->weedResponses(); + stack->pushInt(_responseBox->_responses.getSize()); + } else { + script->runtimeError("Game.GetNumResponses: response box is not defined"); + stack->pushNULL(); + } + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // StartDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartDlgBranch") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + Common::String branchName; + if (val->isNULL()) { + branchName.format("line%d", script->_currentLine); + } else branchName = val->getString(); + + startDlgBranch(branchName.c_str(), script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // EndDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "EndDlgBranch") == 0) { + stack->correctParams(1); + + const char *branchName = NULL; + CScValue *val = stack->pop(); + if (!val->isNULL()) branchName = val->getString(); + endDlgBranch(branchName, script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); + + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetCurrentDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetCurrentDlgBranch") == 0) { + stack->correctParams(0); + + if (_dlgPendingBranches.getSize() > 0) { + stack->pushString(_dlgPendingBranches[_dlgPendingBranches.getSize() - 1]); + } else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TakeItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TakeItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // DropItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DropItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // GetItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // HasItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // IsItemTaken + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsItemTaken") == 0) { + stack->correctParams(1); + + CScValue *val = stack->pop(); + if (!val->isNULL()) { + for (int i = 0; i < _inventories.getSize(); i++) { + CAdInventory *Inv = _inventories[i]; + + for (int j = 0; j < Inv->_takenItems.getSize(); j++) { + if (val->getNative() == Inv->_takenItems[j]) { + stack->pushBool(true); + return STATUS_OK; + } else if (scumm_stricmp(val->getString(), Inv->_takenItems[j]->_name) == 0) { + stack->pushBool(true); + return STATUS_OK; + } + } + } + } else script->runtimeError("Game.IsItemTaken: item name expected"); + + stack->pushBool(false); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetInventoryWindow + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetInventoryWindow") == 0) { + stack->correctParams(0); + if (_inventoryBox && _inventoryBox->_window) + stack->pushNative(_inventoryBox->_window, true); + else + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetResponsesWindow + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetResponsesWindow") == 0 || strcmp(name, "GetResponseWindow") == 0) { + stack->correctParams(0); + if (_responseBox && _responseBox->_window) + stack->pushNative(_responseBox->_window, true); + else + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadResponseBox + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadResponseBox") == 0) { + stack->correctParams(1); + const char *filename = stack->pop()->getString(); + + _gameRef->unregisterObject(_responseBox); + _responseBox = new CAdResponseBox(_gameRef); + if (_responseBox && !DID_FAIL(_responseBox->loadFile(filename))) { + registerObject(_responseBox); + stack->pushBool(true); + } else { + delete _responseBox; + _responseBox = NULL; + stack->pushBool(false); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadInventoryBox + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadInventoryBox") == 0) { + stack->correctParams(1); + const char *filename = stack->pop()->getString(); + + _gameRef->unregisterObject(_inventoryBox); + _inventoryBox = new CAdInventoryBox(_gameRef); + if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile(filename))) { + registerObject(_inventoryBox); + stack->pushBool(true); + } else { + delete _inventoryBox; + _inventoryBox = NULL; + stack->pushBool(false); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadItems") == 0) { + stack->correctParams(2); + const char *filename = stack->pop()->getString(); + bool merge = stack->pop()->getBool(false); + + bool ret = loadItemsFile(filename, merge); + stack->pushBool(DID_SUCCEED(ret)); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddSpeechDir + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddSpeechDir") == 0) { + stack->correctParams(1); + const char *dir = stack->pop()->getString(); + stack->pushBool(DID_SUCCEED(addSpeechDir(dir))); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveSpeechDir + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveSpeechDir") == 0) { + stack->correctParams(1); + const char *dir = stack->pop()->getString(); + stack->pushBool(DID_SUCCEED(removeSpeechDir(dir))); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetSceneViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetSceneViewport") == 0) { + stack->correctParams(4); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + int width = stack->pop()->getInt(); + int height = stack->pop()->getInt(); + + if (width <= 0) width = _renderer->_width; + if (height <= 0) height = _renderer->_height; + + if (!_sceneViewport) _sceneViewport = new CBViewport(_gameRef); + if (_sceneViewport) _sceneViewport->setRect(x, y, x + width, y + height); + + stack->pushBool(true); + + return STATUS_OK; + } + + + else return CBGame::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdGame::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("game"); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // Scene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scene") == 0) { + if (_scene) _scValue->setNative(_scene, true); + else _scValue->setNULL(); + + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // SelectedItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SelectedItem") == 0) { + //if(_selectedItem) _scValue->setString(_selectedItem->_name); + if (_selectedItem) _scValue->setNative(_selectedItem, true); + else _scValue->setNULL(); + + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // NumItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumItems") == 0) { + return _invObject->scGetProperty(name); + } + + ////////////////////////////////////////////////////////////////////////// + // SmartItemCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SmartItemCursor") == 0) { + _scValue->setBool(_smartItemCursor); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryVisible + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryVisible") == 0) { + _scValue->setBool(_inventoryBox && _inventoryBox->_visible); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryScrollOffset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryScrollOffset") == 0) { + if (_inventoryBox) _scValue->setInt(_inventoryBox->_scrollOffset); + else _scValue->setInt(0); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ResponsesVisible (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResponsesVisible") == 0) { + _scValue->setBool(_stateEx == GAME_WAITING_RESPONSE); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PrevScene / PreviousScene (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PrevScene") == 0 || strcmp(name, "PreviousScene") == 0) { + if (!_prevSceneName) _scValue->setString(""); + else _scValue->setString(_prevSceneName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PrevSceneFilename / PreviousSceneFilename (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PrevSceneFilename") == 0 || strcmp(name, "PreviousSceneFilename") == 0) { + if (!_prevSceneFilename) _scValue->setString(""); + else _scValue->setString(_prevSceneFilename); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // LastResponse (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LastResponse") == 0) { + if (!_responseBox || !_responseBox->_lastResponseText) _scValue->setString(""); + else _scValue->setString(_responseBox->_lastResponseText); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // LastResponseOrig (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LastResponseOrig") == 0) { + if (!_responseBox || !_responseBox->_lastResponseTextOrig) _scValue->setString(""); + else _scValue->setString(_responseBox->_lastResponseTextOrig); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryObject") == 0) { + if (_inventoryOwner == _invObject) _scValue->setNative(this, true); + else _scValue->setNative(_inventoryOwner, true); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TotalNumItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TotalNumItems") == 0) { + _scValue->setInt(_items.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkSkipButton + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkSkipButton") == 0) { + _scValue->setInt(_talkSkipButton); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ChangingScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ChangingScene") == 0) { + _scValue->setBool(_scheduledScene != NULL); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // StartupScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartupScene") == 0) { + if (!_startupScene) _scValue->setNULL(); + else _scValue->setString(_startupScene); + return _scValue; + } + + else return CBGame::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::scSetProperty(const char *name, CScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // SelectedItem + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SelectedItem") == 0) { + if (value->isNULL()) _selectedItem = NULL; + else { + if (value->isNative()) { + _selectedItem = NULL; + for (int i = 0; i < _items.getSize(); i++) { + if (_items[i] == value->getNative()) { + _selectedItem = (CAdItem *)value->getNative(); + break; + } + } + } else { + // try to get by name + _selectedItem = getItemByName(value->getString()); + } + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SmartItemCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SmartItemCursor") == 0) { + _smartItemCursor = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryVisible + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryVisible") == 0) { + if (_inventoryBox) _inventoryBox->_visible = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryObject") == 0) { + if (_inventoryOwner && _inventoryBox) _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; + + if (value->isNULL()) _inventoryOwner = _invObject; + else { + CBObject *Obj = (CBObject *)value->getNative(); + if (Obj == this) _inventoryOwner = _invObject; + else if (_gameRef->validObject(Obj)) _inventoryOwner = (CAdObject *)Obj; + } + + if (_inventoryOwner && _inventoryBox) _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryScrollOffset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryScrollOffset") == 0) { + if (_inventoryBox) _inventoryBox->_scrollOffset = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkSkipButton + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkSkipButton") == 0) { + int Val = value->getInt(); + if (Val < 0) Val = 0; + if (Val > TALK_SKIP_NONE) Val = TALK_SKIP_NONE; + _talkSkipButton = (TTalkSkipButton)Val; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StartupScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartupScene") == 0) { + if (value == NULL) { + delete[] _startupScene; + _startupScene = NULL; + } else CBUtils::setString(&_startupScene, value->getString()); + + return STATUS_OK; + } + + else return CBGame::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name) { + CScValue *this_obj; + + ////////////////////////////////////////////////////////////////////////// + // Actor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Actor") == 0) { + stack->correctParams(0); + this_obj = thisStack->getTop(); + + this_obj->setNative(new CAdActor(_gameRef)); + stack->pushNULL(); + } + + ////////////////////////////////////////////////////////////////////////// + // Entity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Entity") == 0) { + stack->correctParams(0); + this_obj = thisStack->getTop(); + + this_obj->setNative(new CAdEntity(_gameRef)); + stack->pushNULL(); + } + + + ////////////////////////////////////////////////////////////////////////// + // call parent + else return CBGame::ExternalCall(script, stack, thisStack, name); + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::showCursor() { + if (_cursorHidden) return STATUS_OK; + + if (_selectedItem && _gameRef->_state == GAME_RUNNING && _stateEx == GAME_NORMAL && _interactive) { + if (_selectedItem->_cursorCombined) { + CBSprite *origLastCursor = _lastCursor; + CBGame::showCursor(); + _lastCursor = origLastCursor; + } + if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { + if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->_name)) + return drawCursor(_selectedItem->_cursorHover); + else + return drawCursor(_selectedItem->_cursorNormal); + } else return drawCursor(_selectedItem->_cursorNormal); + } else return CBGame::showCursor(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadFile(const char *filename) { + byte *buffer = _fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdGame::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(GAME) +TOKEN_DEF(AD_GAME) +TOKEN_DEF(RESPONSE_BOX) +TOKEN_DEF(INVENTORY_BOX) +TOKEN_DEF(ITEMS) +TOKEN_DEF(ITEM) +TOKEN_DEF(TALK_SKIP_BUTTON) +TOKEN_DEF(SCENE_VIEWPORT) +TOKEN_DEF(ENTITY_CONTAINER) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF(STARTUP_SCENE) +TOKEN_DEF(DEBUG_STARTUP_SCENE) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(GAME) + TOKEN_TABLE(AD_GAME) + TOKEN_TABLE(RESPONSE_BOX) + TOKEN_TABLE(INVENTORY_BOX) + TOKEN_TABLE(ITEMS) + TOKEN_TABLE(TALK_SKIP_BUTTON) + TOKEN_TABLE(SCENE_VIEWPORT) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE(STARTUP_SCENE) + TOKEN_TABLE(DEBUG_STARTUP_SCENE) + TOKEN_TABLE_END + + byte *params; + byte *params2; + int cmd = 1; + CBParser parser(_gameRef); + + bool itemFound = false, itemsFound = false; + + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_GAME: + if (DID_FAIL(CBGame::loadBuffer(params, false))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_AD_GAME: + while (cmd > 0 && (cmd = parser.getCommand((char **)¶ms, commands, (char **)¶ms2)) > 0) { + switch (cmd) { + case TOKEN_RESPONSE_BOX: + delete _responseBox; + _responseBox = new CAdResponseBox(_gameRef); + if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) + registerObject(_responseBox); + else { + delete _responseBox; + _responseBox = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_INVENTORY_BOX: + delete _inventoryBox; + _inventoryBox = new CAdInventoryBox(_gameRef); + if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) + registerObject(_inventoryBox); + else { + delete _inventoryBox; + _inventoryBox = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_ITEMS: + itemsFound = true; + CBUtils::setString(&_itemsFile, (char *)params2); + if (DID_FAIL(loadItemsFile(_itemsFile))) { + delete[] _itemsFile; + _itemsFile = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_TALK_SKIP_BUTTON: + if (scumm_stricmp((char *)params2, "right") == 0) _talkSkipButton = TALK_SKIP_RIGHT; + else if (scumm_stricmp((char *)params2, "both") == 0) _talkSkipButton = TALK_SKIP_BOTH; + else _talkSkipButton = TALK_SKIP_LEFT; + break; + + case TOKEN_SCENE_VIEWPORT: { + Rect32 rc; + parser.scanStr((char *)params2, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); + if (!_sceneViewport) _sceneViewport = new CBViewport(_gameRef); + if (_sceneViewport) _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params2, false); + break; + + case TOKEN_STARTUP_SCENE: + CBUtils::setString(&_startupScene, (char *)params2); + break; + + case TOKEN_DEBUG_STARTUP_SCENE: + CBUtils::setString(&_debugStartupScene, (char *)params2); + break; + } + } + break; + } + } + + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in GAME definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading GAME definition"); + return STATUS_FAILED; + } + + if (itemFound && !itemsFound) { + _gameRef->LOG(0, "**Warning** Please put the items definition to a separate file."); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::persist(CBPersistMgr *persistMgr) { + if (!persistMgr->_saving) cleanup(); + CBGame::persist(persistMgr); + + _dlgPendingBranches.persist(persistMgr); + + _inventories.persist(persistMgr); + persistMgr->transfer(TMEMBER(_inventoryBox)); + + _objects.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_prevSceneName)); + persistMgr->transfer(TMEMBER(_prevSceneFilename)); + + persistMgr->transfer(TMEMBER(_responseBox)); + _responsesBranch.persist(persistMgr); + _responsesGame.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scene)); + _sceneStates.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scheduledFadeIn)); + persistMgr->transfer(TMEMBER(_scheduledScene)); + persistMgr->transfer(TMEMBER(_selectedItem)); + persistMgr->transfer(TMEMBER_INT(_talkSkipButton)); + + _sentences.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_sceneViewport)); + persistMgr->transfer(TMEMBER_INT(_stateEx)); + persistMgr->transfer(TMEMBER(_initialScene)); + persistMgr->transfer(TMEMBER(_debugStartupScene)); + + persistMgr->transfer(TMEMBER(_invObject)); + persistMgr->transfer(TMEMBER(_inventoryOwner)); + persistMgr->transfer(TMEMBER(_tempDisableSaveState)); + _items.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_itemsFile)); + + _speechDirs.persist(persistMgr); + persistMgr->transfer(TMEMBER(_smartItemCursor)); + + if (!persistMgr->_saving) _initialScene = false; + + persistMgr->transfer(TMEMBER(_startupScene)); + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadGame(const char *filename) { + bool ret = CBGame::loadGame(filename); + if (DID_SUCCEED(ret)) CSysClassRegistry::getInstance()->enumInstances(afterLoadRegion, "CAdRegion", NULL); + return ret; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::initAfterLoad() { + CBGame::initAfterLoad(); + CSysClassRegistry::getInstance()->enumInstances(afterLoadScene, "CAdScene", NULL); + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +void CAdGame::afterLoadScene(void *scene, void *data) { + ((CAdScene *)scene)->afterLoad(); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdGame::setPrevSceneName(const char *name) { + delete[] _prevSceneName; + _prevSceneName = NULL; + if (name) { + _prevSceneName = new char[strlen(name) + 1]; + if (_prevSceneName) strcpy(_prevSceneName, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdGame::setPrevSceneFilename(const char *name) { + delete[] _prevSceneFilename; + _prevSceneFilename = NULL; + if (name) { + _prevSceneFilename = new char[strlen(name) + 1]; + if (_prevSceneFilename) strcpy(_prevSceneFilename, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::scheduleChangeScene(const char *filename, bool fadeIn) { + delete[] _scheduledScene; + _scheduledScene = NULL; + + if (_scene && !_scene->_initialized) return changeScene(filename, fadeIn); + else { + _scheduledScene = new char [strlen(filename) + 1]; + strcpy(_scheduledScene, filename); + + _scheduledFadeIn = fadeIn; + + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { + CBGame::getVersion(verMajor, verMinor, NULL, NULL); + + if (extMajor) *extMajor = 0; + if (extMinor) *extMinor = 0; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadItemsFile(const char *filename, bool merge) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdGame::LoadItemsFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + //_filename = new char [strlen(filename)+1]; + //strcpy(_filename, filename); + + if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadItemsBuffer(byte *buffer, bool merge) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ITEM) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (!merge) { + while (_items.getSize() > 0) deleteItem(_items[0]); + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_ITEM: { + CAdItem *item = new CAdItem(_gameRef); + if (item && !DID_FAIL(item->loadBuffer(params, false))) { + // delete item with the same name, if exists + if (merge) { + CAdItem *PrevItem = getItemByName(item->_name); + if (PrevItem) deleteItem(PrevItem); + } + addItem(item); + } else { + delete item; + item = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + } + } + + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ITEMS definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ITEMS definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSceneState *CAdGame::getSceneState(const char *filename, bool saving) { + char *filenameCor = new char[strlen(filename) + 1]; + strcpy(filenameCor, filename); + for (uint32 i = 0; i < strlen(filenameCor); i++) { + if (filenameCor[i] == '/') filenameCor[i] = '\\'; + } + + for (int i = 0; i < _sceneStates.getSize(); i++) { + if (scumm_stricmp(_sceneStates[i]->_filename, filenameCor) == 0) { + delete [] filenameCor; + return _sceneStates[i]; + } + } + + if (saving) { + CAdSceneState *ret = new CAdSceneState(_gameRef); + ret->setFilename(filenameCor); + + _sceneStates.add(ret); + + delete [] filenameCor; + return ret; + } else { + delete [] filenameCor; + return NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::windowLoadHook(CUIWindow *win, char **buffer, char **params) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ENTITY_CONTAINER) + TOKEN_TABLE_END + + int cmd = PARSERR_GENERIC; + CBParser parser(_gameRef); + + cmd = parser.getCommand(buffer, commands, params); + switch (cmd) { + case TOKEN_ENTITY_CONTAINER: { + CUIEntity *ent = new CUIEntity(_gameRef); + if (!ent || DID_FAIL(ent->loadBuffer((byte *)*params, false))) { + delete ent; + ent = NULL; + cmd = PARSERR_GENERIC; + } else { + ent->_parent = win; + win->_widgets.add(ent); + } + } + break; + } + + if (cmd == PARSERR_TOKENNOTFOUND || cmd == PARSERR_GENERIC) { + return STATUS_FAILED; + } + + return STATUS_OK; + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name) { + if (strcmp(name, "CreateEntityContainer") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CUIEntity *ent = new CUIEntity(_gameRef); + if (!val->isNULL()) ent->setName(val->getString()); + stack->pushNative(ent, true); + + ent->_parent = win; + win->_widgets.add(ent); + + return STATUS_OK; + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::startDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { + char *name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; + if (name) { + sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); + _dlgPendingBranches.add(name); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::endDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { + char *name = NULL; + bool deleteName = false; + if (branchName == NULL && _dlgPendingBranches.getSize() > 0) { + name = _dlgPendingBranches[_dlgPendingBranches.getSize() - 1]; + } else { + if (branchName != NULL) { + name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; + if (name) { + sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); + deleteName = true; + } + } + } + + if (name == NULL) return STATUS_OK; + + + int startIndex = -1; + for (int i = _dlgPendingBranches.getSize() - 1; i >= 0; i--) { + if (scumm_stricmp(name, _dlgPendingBranches[i]) == 0) { + startIndex = i; + break; + } + } + if (startIndex >= 0) { + for (int i = startIndex; i < _dlgPendingBranches.getSize(); i++) { + //ClearBranchResponses(_dlgPendingBranches[i]); + delete [] _dlgPendingBranches[i]; + _dlgPendingBranches[i] = NULL; + } + _dlgPendingBranches.removeAt(startIndex, _dlgPendingBranches.getSize() - startIndex); + } + + // dialogue is over, forget selected responses + if (_dlgPendingBranches.getSize() == 0) { + for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + _responsesBranch.removeAll(); + } + + if (deleteName) delete [] name; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::clearBranchResponses(char *name) { + for (int i = 0; i < _responsesBranch.getSize(); i++) { + if (scumm_stricmp(name, _responsesBranch[i]->_context) == 0) { + delete _responsesBranch[i]; + _responsesBranch.removeAt(i); + i--; + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addBranchResponse(int ID) { + if (branchResponseUsed(ID)) return STATUS_OK; + CAdResponseContext *r = new CAdResponseContext(_gameRef); + r->_iD = ID; + r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); + _responsesBranch.add(r); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::branchResponseUsed(int ID) { + char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; + for (int i = 0; i < _responsesBranch.getSize(); i++) { + if (_responsesBranch[i]->_iD == ID) { + if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) return true; + } + } + return false; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addGameResponse(int ID) { + if (gameResponseUsed(ID)) return STATUS_OK; + CAdResponseContext *r = new CAdResponseContext(_gameRef); + r->_iD = ID; + r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); + _responsesGame.add(r); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::gameResponseUsed(int ID) { + char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; + for (int i = 0; i < _responsesGame.getSize(); i++) { + CAdResponseContext *RespContext = _responsesGame[i]; + if (RespContext->_iD == ID) { + if ((Context == NULL && RespContext->_context == NULL) || ((Context != NULL && RespContext->_context != NULL) && scumm_stricmp(Context, RespContext->_context) == 0)) return true; + } + } + return false; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::resetResponse(int ID) { + char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; + + int i; + + for (i = 0; i < _responsesGame.getSize(); i++) { + if (_responsesGame[i]->_iD == ID) { + if ((Context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(Context, _responsesGame[i]->_context) == 0) { + delete _responsesGame[i]; + _responsesGame.removeAt(i); + break; + } + } + } + + for (i = 0; i < _responsesBranch.getSize(); i++) { + if (_responsesBranch[i]->_iD == ID) { + if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) { + delete _responsesBranch[i]; + _responsesBranch.removeAt(i); + break; + } + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::displayContent(bool doUpdate, bool displayAll) { + // init + if (doUpdate) initLoop(); + + // fill black + _renderer->fill(0, 0, 0); + if (!_editorMode) _renderer->setScreenViewport(); + + // playing exclusive video? + if (_videoPlayer->isPlaying()) { + if (doUpdate) _videoPlayer->update(); + _videoPlayer->display(); + } else if (_theoraPlayer) { + if (_theoraPlayer->isPlaying()) { + if (doUpdate) _theoraPlayer->update(); + _theoraPlayer->display(); + } + if (_theoraPlayer->isFinished()) { + delete _theoraPlayer; + _theoraPlayer = NULL; + } + } else { + + // process scripts + if (doUpdate) _scEngine->tick(); + + Point32 p; + getMousePos(&p); + + _scene->update(); + _scene->display(); + + + // display in-game windows + displayWindows(true); + if (_inventoryBox) _inventoryBox->display(); + if (_stateEx == GAME_WAITING_RESPONSE) _responseBox->display(); + if (_indicatorDisplay) displayIndicator(); + + + if (doUpdate || displayAll) { + // display normal windows + displayWindows(false); + + setActiveObject(_gameRef->_renderer->getObjectAt(p.x, p.y)); + + // textual info + displaySentences(_state == GAME_FROZEN); + + showCursor(); + + if (_fader) _fader->display(); + _transMgr->update(); + } + + } + if (_loadingIcon) { + _loadingIcon->display(_loadingIconX, _loadingIconY); + if (!_loadingIconPersistent) { + delete _loadingIcon; + _loadingIcon = NULL; + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::registerInventory(CAdInventory *inv) { + for (int i = 0; i < _inventories.getSize(); i++) { + if (_inventories[i] == inv) return STATUS_OK; + } + registerObject(inv); + _inventories.add(inv); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::unregisterInventory(CAdInventory *inv) { + for (int i = 0; i < _inventories.getSize(); i++) { + if (_inventories[i] == inv) { + unregisterObject(_inventories[i]); + _inventories.removeAt(i); + return STATUS_OK; + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::isItemTaken(char *itemName) { + for (int i = 0; i < _inventories.getSize(); i++) { + CAdInventory *Inv = _inventories[i]; + + for (int j = 0; j < Inv->_takenItems.getSize(); j++) { + if (scumm_stricmp(itemName, Inv->_takenItems[j]->_name) == 0) { + return true; + } + } + } + return false; +} + +////////////////////////////////////////////////////////////////////////// +CAdItem *CAdGame::getItemByName(const char *name) { + for (int i = 0; i < _items.getSize(); i++) { + if (scumm_stricmp(_items[i]->_name, name) == 0) return _items[i]; + } + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addItem(CAdItem *item) { + _items.add(item); + return _gameRef->registerObject(item); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::resetContent() { + // clear pending dialogs + for (int i = 0; i < _dlgPendingBranches.getSize(); i++) { + delete [] _dlgPendingBranches[i]; + } + _dlgPendingBranches.removeAll(); + + + // clear inventories + for (int i = 0; i < _inventories.getSize(); i++) { + _inventories[i]->_takenItems.removeAll(); + } + + // clear scene states + for (int i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; + _sceneStates.removeAll(); + + // clear once responses + for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + _responsesBranch.removeAll(); + + // clear once game responses + for (int i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; + _responsesGame.removeAll(); + + // reload inventory items + if (_itemsFile) loadItemsFile(_itemsFile); + + _tempDisableSaveState = true; + + return CBGame::resetContent(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::deleteItem(CAdItem *item) { + if (!item) return STATUS_FAILED; + + if (_selectedItem == item) _selectedItem = NULL; + _scene->handleItemAssociations(item->_name, false); + + // remove from all inventories + for (int i = 0; i < _inventories.getSize(); i++) { + _inventories[i]->removeItem(item); + } + + // remove object + for (int i = 0; i < _items.getSize(); i++) { + if (_items[i] == item) { + unregisterObject(_items[i]); + _items.removeAt(i); + break; + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addSpeechDir(const char *dir) { + if (!dir || dir[0] == '\0') return STATUS_FAILED; + + char *temp = new char[strlen(dir) + 2]; + strcpy(temp, dir); + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') + strcat(temp, "\\"); + + for (int i = 0; i < _speechDirs.getSize(); i++) { + if (scumm_stricmp(_speechDirs[i], temp) == 0) { + delete [] temp; + return STATUS_OK; + } + } + _speechDirs.add(temp); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::removeSpeechDir(const char *dir) { + if (!dir || dir[0] == '\0') return STATUS_FAILED; + + char *temp = new char[strlen(dir) + 2]; + strcpy(temp, dir); + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') + strcat(temp, "\\"); + + bool Found = false; + for (int i = 0; i < _speechDirs.getSize(); i++) { + if (scumm_stricmp(_speechDirs[i], temp) == 0) { + delete [] _speechDirs[i]; + _speechDirs.removeAt(i); + Found = true; + break; + } + } + delete [] temp; + + if (Found) return STATUS_OK; + else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdGame::findSpeechFile(char *stringID) { + char *ret = new char[MAX_PATH_LENGTH]; + + for (int i = 0; i < _speechDirs.getSize(); i++) { + sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); + Common::SeekableReadStream *file = _fileManager->openFile(ret); // TODO: Replace with hasFile + if (file) { + _fileManager->closeFile(file); + return ret; + } + + sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); + file = _fileManager->openFile(ret); + if (file) { + _fileManager->closeFile(file); + return ret; + } + } + delete [] ret; + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::validMouse() { + Point32 pos; + CBPlatform::getCursorPos(&pos); + + return _renderer->pointInViewport(&pos); +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseLeftDown() { + if (!validMouse()) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + if (_talkSkipButton == TALK_SKIP_LEFT || _talkSkipButton == TALK_SKIP_BOTH) { + finishSentences(); + } + return STATUS_OK; + } + + if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftClick"); + } + } + + if (_activeObject != NULL) _gameRef->_capturedObject = _gameRef->_activeObject; + _mouseLeftDown = true; + CBPlatform::setCapture(/*_renderer->_window*/); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseLeftUp() { + if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + + CBPlatform::releaseCapture(); + _capturedObject = NULL; + _mouseLeftDown = false; + + bool handled = /*_state==GAME_RUNNING &&*/ DID_SUCCEED(applyEvent("LeftRelease")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftRelease"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftRelease"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseLeftDblClick() { + if (!validMouse()) return STATUS_OK; + + if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; + + if (_activeObject) _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftDoubleClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftDoubleClick"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseRightDown() { + if (!validMouse()) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + if (_talkSkipButton == TALK_SKIP_RIGHT || _talkSkipButton == TALK_SKIP_BOTH) { + finishSentences(); + } + return STATUS_OK; + } + + if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) return STATUS_OK; + + if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("RightClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("RightClick"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseRightUp() { + if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("RightRelease"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("RightRelease"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::displayDebugInfo() { + char str[100]; + if (_gameRef->_debugDebugMode) { + sprintf(str, "Mouse: %d, %d (scene: %d, %d)", _mousePos.x, _mousePos.y, _mousePos.x + _scene->getOffsetLeft(), _mousePos.y + _scene->getOffsetTop()); + _systemFont->drawText((byte *)str, 0, 90, _renderer->_width, TAL_RIGHT); + + sprintf(str, "Scene: %s (prev: %s)", (_scene && _scene->_name) ? _scene->_name : "???", _prevSceneName ? _prevSceneName : "???"); + _systemFont->drawText((byte *)str, 0, 110, _renderer->_width, TAL_RIGHT); + } + return CBGame::displayDebugInfo(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onScriptShutdown(CScScript *script) { + if (_responseBox && _responseBox->_waitingScript == script) + _responseBox->_waitingScript = NULL; + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdGame.h b/engines/wintermute/ad/AdGame.h new file mode 100644 index 0000000000..4a89fa97d2 --- /dev/null +++ b/engines/wintermute/ad/AdGame.h @@ -0,0 +1,161 @@ +/* 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. + + * 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. + + * 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 + */ +#ifndef WINTERMUTE_ADGAME_H +#define WINTERMUTE_ADGAME_H + +#include "engines/wintermute/ad/AdTypes.h" +#include "engines/wintermute/base/BGame.h" + +namespace WinterMute { +class CAdItem; +class CAdInventory; +class CAdSceneState; +class CAdScene; +class CAdItem; +class CAdObject; +class CAdSentence; +class CAdInventoryBox; +class CAdResponseContext; +class CAdResponseBox; +class CAdGame : public CBGame { +public: + virtual bool onScriptShutdown(CScScript *script); + + virtual bool onMouseLeftDown(); + virtual bool onMouseLeftUp(); + virtual bool onMouseLeftDblClick(); + virtual bool onMouseRightDown(); + virtual bool onMouseRightUp(); + + virtual bool displayDebugInfo(); + + + virtual bool initAfterLoad(); + static void afterLoadScene(void *scene, void *data); + + bool _smartItemCursor; + + CBArray _speechDirs; + bool addSpeechDir(const char *dir); + bool removeSpeechDir(const char *dir); + char *findSpeechFile(char *StringID); + + bool deleteItem(CAdItem *Item); + char *_itemsFile; + bool _tempDisableSaveState; + virtual bool resetContent(); + bool addItem(CAdItem *item); + CAdItem *getItemByName(const char *name); + CBArray _items; + CAdObject *_inventoryOwner; + bool isItemTaken(char *itemName); + bool registerInventory(CAdInventory *inv); + bool unregisterInventory(CAdInventory *inv); + + CAdObject *_invObject; + CBArray _inventories; + virtual bool displayContent(bool update = true, bool displayAll = false); + char *_debugStartupScene; + char *_startupScene; + bool _initialScene; + bool gameResponseUsed(int ID); + bool addGameResponse(int ID); + bool resetResponse(int ID); + + bool branchResponseUsed(int ID); + bool addBranchResponse(int ID); + bool clearBranchResponses(char *name); + bool startDlgBranch(const char *branchName, const char *scriptName, const char *eventName); + bool endDlgBranch(const char *branchName, const char *scriptName, const char *eventName); + virtual bool windowLoadHook(CUIWindow *win, char **buf, char **params); + virtual bool windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name); + + CAdSceneState *getSceneState(const char *filename, bool saving); + CBViewport *_sceneViewport; + int _texItemLifeTime; + int _texWalkLifeTime; + int _texStandLifeTime; + int _texTalkLifeTime; + + TTalkSkipButton _talkSkipButton; + + virtual bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor); + bool scheduleChangeScene(const char *filename, bool fadeIn); + char *_scheduledScene; + bool _scheduledFadeIn; + void setPrevSceneName(const char *name); + void setPrevSceneFilename(const char *name); + char *_prevSceneName; + char *_prevSceneFilename; + virtual bool loadGame(const char *filename); + CAdItem *_selectedItem; + bool cleanup(); + DECLARE_PERSISTENT(CAdGame, CBGame) + + void finishSentences(); + bool showCursor(); + TGameStateEx _stateEx; + CAdResponseBox *_responseBox; + CAdInventoryBox *_inventoryBox; + bool displaySentences(bool frozen); + void addSentence(CAdSentence *sentence); + bool changeScene(const char *filename, bool fadeIn); + bool removeObject(CAdObject *object); + bool addObject(CAdObject *object); + CAdScene *_scene; + bool initLoop(); + CAdGame(); + virtual ~CAdGame(); + CBArray _objects; + CBArray _sentences; + + CBArray _sceneStates; + CBArray _dlgPendingBranches; + + CBArray _responsesBranch; + CBArray _responsesGame; + + virtual bool loadFile(const char *filename); + virtual bool loadBuffer(byte *buffer, bool complete = true); + + bool loadItemsFile(const char *filename, bool merge = false); + bool loadItemsBuffer(byte *buffer, bool merge = false); + + + virtual bool ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + bool validMouse(); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdInventory.cpp b/engines/wintermute/ad/AdInventory.cpp new file mode 100644 index 0000000000..54195cc68a --- /dev/null +++ b/engines/wintermute/ad/AdInventory.cpp @@ -0,0 +1,119 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/AdInventory.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdItem.h" +#include "engines/wintermute/PlatformSDL.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdInventory, false) + +////////////////////////////////////////////////////////////////////////// +CAdInventory::CAdInventory(CBGame *inGame): CBObject(inGame) { + _scrollOffset = 0; +} + + +////////////////////////////////////////////////////////////////////////// +CAdInventory::~CAdInventory() { + _takenItems.removeAll(); // ref only +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventory::insertItem(const char *name, const char *insertAfter) { + if (name == NULL) return STATUS_FAILED; + + CAdItem *item = ((CAdGame *)_gameRef)->getItemByName(name); + if (item == NULL) return STATUS_FAILED; + + int insertIndex = -1; + for (int i = 0; i < _takenItems.getSize(); i++) { + if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { + _takenItems.removeAt(i); + i--; + continue; + } + if (insertAfter && scumm_stricmp(_takenItems[i]->_name, insertAfter) == 0) insertIndex = i + 1; + } + + + if (insertIndex == -1) _takenItems.add(item); + else _takenItems.insertAt(insertIndex, item); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventory::removeItem(const char *name) { + if (name == NULL) return STATUS_FAILED; + + for (int i = 0; i < _takenItems.getSize(); i++) { + if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { + if (((CAdGame *)_gameRef)->_selectedItem == _takenItems[i])((CAdGame *)_gameRef)->_selectedItem = NULL; + _takenItems.removeAt(i); + return STATUS_OK; + } + } + + return STATUS_FAILED; +} + + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventory::removeItem(CAdItem *item) { + if (item == NULL) return STATUS_FAILED; + + for (int i = 0; i < _takenItems.getSize(); i++) { + if (_takenItems[i] == item) { + if (((CAdGame *)_gameRef)->_selectedItem == _takenItems[i])((CAdGame *)_gameRef)->_selectedItem = NULL; + _takenItems.removeAt(i); + return STATUS_OK; + } + } + + return STATUS_FAILED; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdInventory::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + _takenItems.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollOffset)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdInventory.h b/engines/wintermute/ad/AdInventory.h new file mode 100644 index 0000000000..cec76c03a0 --- /dev/null +++ b/engines/wintermute/ad/AdInventory.h @@ -0,0 +1,52 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADINVENTORY_H +#define WINTERMUTE_ADINVENTORY_H + +#include "engines/wintermute/base/BObject.h" + +namespace WinterMute { + +class CAdItem; + +class CAdInventory : public CBObject { +public: + DECLARE_PERSISTENT(CAdInventory, CBObject) + bool removeItem(const char *name); + bool removeItem(CAdItem *Item); + bool insertItem(const char *name, const char *insertAfter = NULL); + CAdInventory(CBGame *inGame); + virtual ~CAdInventory(); + CBArray _takenItems; + int _scrollOffset; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdInventoryBox.cpp b/engines/wintermute/ad/AdInventoryBox.cpp new file mode 100644 index 0000000000..c5c9c3be67 --- /dev/null +++ b/engines/wintermute/ad/AdInventoryBox.cpp @@ -0,0 +1,372 @@ +/* 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. + + * 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. + + * 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 + */ +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdInventoryBox.h" +#include "engines/wintermute/ad/AdInventory.h" +#include "engines/wintermute/ad/AdItem.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/base/BViewport.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/ui/UIButton.h" +#include "engines/wintermute/ui/UIWindow.h" +#include "engines/wintermute/PlatformSDL.h" +#include "common/str.h" +#include "common/rect.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdInventoryBox, false) + +////////////////////////////////////////////////////////////////////////// +CAdInventoryBox::CAdInventoryBox(CBGame *inGame): CBObject(inGame) { + _itemsArea.setEmpty(); + _scrollOffset = 0; + _spacing = 0; + _itemWidth = _itemHeight = 50; + _scrollBy = 1; + + _window = NULL; + _closeButton = NULL; + + _hideSelected = false; + + _visible = false; + _exclusive = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdInventoryBox::~CAdInventoryBox() { + _gameRef->unregisterObject(_window); + _window = NULL; + + delete _closeButton; + _closeButton = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::listen(CBScriptHolder *param1, uint32 param2) { + CUIObject *obj = (CUIObject *)param1; + + switch (obj->_type) { + case UI_BUTTON: + if (scumm_stricmp(obj->_name, "close") == 0) { + _visible = false; + } else if (scumm_stricmp(obj->_name, "prev") == 0) { + _scrollOffset -= _scrollBy; + _scrollOffset = MAX(_scrollOffset, 0); + } else if (scumm_stricmp(obj->_name, "next") == 0) { + _scrollOffset += _scrollBy; + } else return CBObject::listen(param1, param2); + break; + default: + error("CAdInventoryBox::Listen - Unhandled enum"); + break; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::display() { + CAdGame *adGame = (CAdGame *)_gameRef; + + if (!_visible) return STATUS_OK; + + int itemsX, itemsY; + itemsX = (int)floor((float)((_itemsArea.right - _itemsArea.left + _spacing) / (_itemWidth + _spacing))); + itemsY = (int)floor((float)((_itemsArea.bottom - _itemsArea.top + _spacing) / (_itemHeight + _spacing))); + + if (_window) { + _window->enableWidget("prev", _scrollOffset > 0); + _window->enableWidget("next", _scrollOffset + itemsX * itemsY < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()); + } + + + if (_closeButton) { + _closeButton->_posX = _closeButton->_posY = 0; + _closeButton->_width = _gameRef->_renderer->_width; + _closeButton->_height = _gameRef->_renderer->_height; + + _closeButton->display(); + } + + + // display window + Rect32 rect = _itemsArea; + if (_window) { + rect.offsetRect(_window->_posX, _window->_posY); + _window->display(); + } + + // display items + if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; + int yyy = rect.top; + for (int j = 0; j < itemsY; j++) { + int xxx = rect.left; + for (int i = 0; i < itemsX; i++) { + int itemIndex = _scrollOffset + j * itemsX + i; + if (itemIndex >= 0 && itemIndex < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()) { + CAdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex]; + if (item != ((CAdGame *)_gameRef)->_selectedItem || !_hideSelected) { + item->update(); + item->display(xxx, yyy); + } + } + + xxx += (_itemWidth + _spacing); + } + yyy += (_itemHeight + _spacing); + } + if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = 0; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdInventoryBox::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(INVENTORY_BOX) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(WINDOW) +TOKEN_DEF(EXCLUSIVE) +TOKEN_DEF(ALWAYS_VISIBLE) +TOKEN_DEF(AREA) +TOKEN_DEF(SPACING) +TOKEN_DEF(ITEM_WIDTH) +TOKEN_DEF(ITEM_HEIGHT) +TOKEN_DEF(SCROLL_BY) +TOKEN_DEF(NAME) +TOKEN_DEF(CAPTION) +TOKEN_DEF(HIDE_SELECTED) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(INVENTORY_BOX) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(WINDOW) + TOKEN_TABLE(EXCLUSIVE) + TOKEN_TABLE(ALWAYS_VISIBLE) + TOKEN_TABLE(AREA) + TOKEN_TABLE(SPACING) + TOKEN_TABLE(ITEM_WIDTH) + TOKEN_TABLE(ITEM_HEIGHT) + TOKEN_TABLE(SCROLL_BY) + TOKEN_TABLE(NAME) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(HIDE_SELECTED) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd = 2; + CBParser parser(_gameRef); + bool always_visible = false; + + _exclusive = false; + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_INVENTORY_BOX) { + _gameRef->LOG(0, "'INVENTORY_BOX' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_WINDOW: + delete _window; + _window = new CUIWindow(_gameRef); + if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { + delete _window; + _window = NULL; + cmd = PARSERR_GENERIC; + } else _gameRef->registerObject(_window); + break; + + case TOKEN_AREA: + parser.scanStr((char *)params, "%d,%d,%d,%d", &_itemsArea.left, &_itemsArea.top, &_itemsArea.right, &_itemsArea.bottom); + break; + + case TOKEN_EXCLUSIVE: + parser.scanStr((char *)params, "%b", &_exclusive); + break; + + case TOKEN_HIDE_SELECTED: + parser.scanStr((char *)params, "%b", &_hideSelected); + break; + + case TOKEN_ALWAYS_VISIBLE: + parser.scanStr((char *)params, "%b", &always_visible); + break; + + case TOKEN_SPACING: + parser.scanStr((char *)params, "%d", &_spacing); + break; + + case TOKEN_ITEM_WIDTH: + parser.scanStr((char *)params, "%d", &_itemWidth); + break; + + case TOKEN_ITEM_HEIGHT: + parser.scanStr((char *)params, "%d", &_itemHeight); + break; + + case TOKEN_SCROLL_BY: + parser.scanStr((char *)params, "%d", &_scrollBy); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in INVENTORY_BOX definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading INVENTORY_BOX definition"); + return STATUS_FAILED; + } + + if (_exclusive) { + delete _closeButton; + _closeButton = new CUIButton(_gameRef); + if (_closeButton) { + _closeButton->setName("close"); + _closeButton->setListener(this, _closeButton, 0); + _closeButton->_parent = _window; + } + } + + _visible = always_visible; + + if (_window) { + for (int i = 0; i < _window->_widgets.getSize(); i++) { + if (!_window->_widgets[i]->_listenerObject) + _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "INVENTORY_BOX\n"); + buffer->putTextIndent(indent, "{\n"); + + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + + buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _itemsArea.left, _itemsArea.top, _itemsArea.right, _itemsArea.bottom); + + buffer->putTextIndent(indent + 2, "EXCLUSIVE=%s\n", _exclusive ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "HIDE_SELECTED=%s\n", _hideSelected ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "ALWAYS_VISIBLE=%s\n", _visible ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); + buffer->putTextIndent(indent + 2, "ITEM_WIDTH=%d\n", _itemWidth); + buffer->putTextIndent(indent + 2, "ITEM_HEIGHT=%d\n", _itemHeight); + buffer->putTextIndent(indent + 2, "SCROLL_BY=%d\n", _scrollBy); + + buffer->putTextIndent(indent + 2, "\n"); + + // window + if (_window) _window->saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent + 2, "\n"); + + // editor properties + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::persist(CBPersistMgr *persistMgr) { + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_closeButton)); + persistMgr->transfer(TMEMBER(_hideSelected)); + persistMgr->transfer(TMEMBER(_itemHeight)); + persistMgr->transfer(TMEMBER(_itemsArea)); + persistMgr->transfer(TMEMBER(_itemWidth)); + persistMgr->transfer(TMEMBER(_scrollBy)); + persistMgr->transfer(TMEMBER(_scrollOffset)); + persistMgr->transfer(TMEMBER(_spacing)); + persistMgr->transfer(TMEMBER(_visible)); + persistMgr->transfer(TMEMBER(_window)); + persistMgr->transfer(TMEMBER(_exclusive)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdInventoryBox.h b/engines/wintermute/ad/AdInventoryBox.h new file mode 100644 index 0000000000..cfd8d74021 --- /dev/null +++ b/engines/wintermute/ad/AdInventoryBox.h @@ -0,0 +1,64 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADINVENTORYBOX_H +#define WINTERMUTE_ADINVENTORYBOX_H + +#include "engines/wintermute/base/BObject.h" +#include "common/rect.h" + +namespace WinterMute { +class CUIButton; +class CUIWindow; + +class CAdInventoryBox : public CBObject { +public: + bool _hideSelected; + DECLARE_PERSISTENT(CAdInventoryBox, CBObject) + bool _exclusive; + int _scrollBy; + int _itemHeight; + int _itemWidth; + bool _visible; + virtual bool display(); + CUIButton *_closeButton; + int _spacing; + int _scrollOffset; + Rect32 _itemsArea; + bool listen(CBScriptHolder *param1, uint32 param2); + CUIWindow *_window; + CAdInventoryBox(CBGame *inGame); + virtual ~CAdInventoryBox(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdItem.cpp b/engines/wintermute/ad/AdItem.cpp new file mode 100644 index 0000000000..5678f6cfa6 --- /dev/null +++ b/engines/wintermute/ad/AdItem.cpp @@ -0,0 +1,760 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdItem.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdSentence.h" +#include "engines/wintermute/base/font/BFontStorage.h" +#include "engines/wintermute/base/font/BFont.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BSound.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdItem, false) + +////////////////////////////////////////////////////////////////////////// +CAdItem::CAdItem(CBGame *inGame): CAdTalkHolder(inGame) { + _spriteHover = NULL; + _cursorNormal = _cursorHover = NULL; + + _cursorCombined = true; + _inInventory = false; + + _displayAmount = false; + _amount = 0; + _amountOffsetX = 0; + _amountOffsetY = 0; + _amountAlign = TAL_RIGHT; + _amountString = NULL; + + _state = STATE_READY; + + _movable = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdItem::~CAdItem() { + delete _spriteHover; + delete _cursorNormal; + delete _cursorHover; + _spriteHover = NULL; + _cursorNormal = NULL; + _cursorHover = NULL; + + delete[] _amountString; + _amountString = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdItem::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ITEM) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(CURSOR_HOVER) +TOKEN_DEF(CURSOR_COMBINED) +TOKEN_DEF(CURSOR) +TOKEN_DEF(NAME) +TOKEN_DEF(IMAGE_HOVER) +TOKEN_DEF(IMAGE) +TOKEN_DEF(EVENTS) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF(FONT) +TOKEN_DEF(ALPHA_COLOR) +TOKEN_DEF(ALPHA) +TOKEN_DEF(TALK_SPECIAL) +TOKEN_DEF(TALK) +TOKEN_DEF(SPRITE_HOVER) +TOKEN_DEF(SPRITE) +TOKEN_DEF(DISPLAY_AMOUNT) +TOKEN_DEF(AMOUNT_OFFSET_X) +TOKEN_DEF(AMOUNT_OFFSET_Y) +TOKEN_DEF(AMOUNT_ALIGN) +TOKEN_DEF(AMOUNT_STRING) +TOKEN_DEF(AMOUNT) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdItem::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ITEM) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(CURSOR_HOVER) + TOKEN_TABLE(CURSOR_COMBINED) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(NAME) + TOKEN_TABLE(IMAGE_HOVER) + TOKEN_TABLE(IMAGE) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE(FONT) + TOKEN_TABLE(ALPHA_COLOR) + TOKEN_TABLE(ALPHA) + TOKEN_TABLE(TALK_SPECIAL) + TOKEN_TABLE(TALK) + TOKEN_TABLE(SPRITE_HOVER) + TOKEN_TABLE(SPRITE) + TOKEN_TABLE(DISPLAY_AMOUNT) + TOKEN_TABLE(AMOUNT_OFFSET_X) + TOKEN_TABLE(AMOUNT_OFFSET_Y) + TOKEN_TABLE(AMOUNT_ALIGN) + TOKEN_TABLE(AMOUNT_STRING) + TOKEN_TABLE(AMOUNT) + TOKEN_TABLE_END + + byte *params; + int cmd = 2; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ITEM) { + _gameRef->LOG(0, "'ITEM' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + int ar = 0, ag = 0, ab = 0, alpha = 255; + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_FONT: + SetFont((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_IMAGE: + case TOKEN_SPRITE: + delete _sprite; + _sprite = new CBSprite(_gameRef, this); + if (!_sprite || DID_FAIL(_sprite->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + delete _sprite; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_IMAGE_HOVER: + case TOKEN_SPRITE_HOVER: + delete _spriteHover; + _spriteHover = new CBSprite(_gameRef, this); + if (!_spriteHover || DID_FAIL(_spriteHover->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + delete _spriteHover; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_AMOUNT: + parser.scanStr((char *)params, "%d", &_amount); + break; + + case TOKEN_DISPLAY_AMOUNT: + parser.scanStr((char *)params, "%b", &_displayAmount); + break; + + case TOKEN_AMOUNT_OFFSET_X: + parser.scanStr((char *)params, "%d", &_amountOffsetX); + break; + + case TOKEN_AMOUNT_OFFSET_Y: + parser.scanStr((char *)params, "%d", &_amountOffsetY); + break; + + case TOKEN_AMOUNT_ALIGN: + if (scumm_stricmp((char *)params, "left") == 0) _amountAlign = TAL_LEFT; + else if (scumm_stricmp((char *)params, "right") == 0) _amountAlign = TAL_RIGHT; + else _amountAlign = TAL_CENTER; + break; + + case TOKEN_AMOUNT_STRING: + CBUtils::setString(&_amountString, (char *)params); + break; + + case TOKEN_TALK: { + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((CAdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSprites.add(spr); + } + break; + + case TOKEN_TALK_SPECIAL: { + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((CAdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSpritesEx.add(spr); + } + break; + + case TOKEN_CURSOR: + delete _cursorNormal; + _cursorNormal = new CBSprite(_gameRef); + if (!_cursorNormal || DID_FAIL(_cursorNormal->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + delete _cursorNormal; + _cursorNormal = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CURSOR_HOVER: + delete _cursorHover; + _cursorHover = new CBSprite(_gameRef); + if (!_cursorHover || DID_FAIL(_cursorHover->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + delete _cursorHover; + _cursorHover = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CURSOR_COMBINED: + parser.scanStr((char *)params, "%b", &_cursorCombined); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + 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; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ITEM definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ITEM definition"); + return STATUS_FAILED; + } + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::update() { + _currentSprite = NULL; + + if (_state == STATE_READY && _animSprite) { + delete _animSprite; + _animSprite = NULL; + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = STATE_READY; + _currentSprite = _animSprite; + } + + if (_sentence && _state != STATE_TALKING) _sentence->finish(); + + // default: stand animation + if (!_currentSprite) _currentSprite = _sprite; + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite) { + if (_gameRef->_activeObject == this && _spriteHover) _currentSprite = _spriteHover; + else _currentSprite = _sprite; + } + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(); + if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + + bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { + if (TimeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + } + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } else { + _currentSprite = _tempSprite2; + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } + default: + break; + } + _ready = (_state == STATE_READY); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::display(int x, int y) { + int width = 0; + if (_currentSprite) { + Rect32 rc; + _currentSprite->getBoundingRect(&rc, 0, 0); + width = rc.width(); + } + + _posX = x + width / 2; + _posY = y; + + bool ret; + if (_currentSprite) + ret = _currentSprite->draw(x, y, this, 100, 100, _alphaColor); + else ret = STATUS_OK; + + if (_displayAmount) { + int amountX = x; + int amountY = y + _amountOffsetY; + + if (_amountAlign == TAL_RIGHT) { + width -= _amountOffsetX; + amountX -= _amountOffsetX; + } + amountX += _amountOffsetX; + + CBFont *font = _font ? _font : _gameRef->_systemFont; + if (font) { + if (_amountString) font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); + else { + char Str[256]; + sprintf(Str, "%d", _amount); + font->drawText((byte *)Str, amountX, amountY, width, _amountAlign); + } + } + } + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdItem::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // SetHoverSprite + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetHoverSprite") == 0) { + stack->correctParams(1); + + bool setCurrent = false; + if (_currentSprite && _currentSprite == _spriteHover) setCurrent = true; + + const char *filename = stack->pop()->getString(); + + delete _spriteHover; + _spriteHover = NULL; + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetHoverSprite failed for file '%s'", filename); + } else { + _spriteHover = spr; + if (setCurrent) _currentSprite = _spriteHover; + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverSprite") == 0) { + stack->correctParams(0); + + if (!_spriteHover || !_spriteHover->_filename) stack->pushNULL(); + else stack->pushString(_spriteHover->_filename); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverSpriteObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverSpriteObject") == 0) { + stack->correctParams(0); + if (!_spriteHover) stack->pushNULL(); + else stack->pushNative(_spriteHover, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetNormalCursor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetNormalCursor") == 0) { + stack->correctParams(1); + + const char *filename = stack->pop()->getString(); + + delete _cursorNormal; + _cursorNormal = NULL; + CBSprite *spr = new CBSprite(_gameRef); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetNormalCursor failed for file '%s'", filename); + } else { + _cursorNormal = spr; + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNormalCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNormalCursor") == 0) { + stack->correctParams(0); + + if (!_cursorNormal || !_cursorNormal->_filename) stack->pushNULL(); + else stack->pushString(_cursorNormal->_filename); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNormalCursorObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNormalCursorObject") == 0) { + stack->correctParams(0); + + if (!_cursorNormal) stack->pushNULL(); + else stack->pushNative(_cursorNormal, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetHoverCursor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetHoverCursor") == 0) { + stack->correctParams(1); + + const char *filename = stack->pop()->getString(); + + delete _cursorHover; + _cursorHover = NULL; + CBSprite *spr = new CBSprite(_gameRef); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetHoverCursor failed for file '%s'", filename); + } else { + _cursorHover = spr; + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverCursor") == 0) { + stack->correctParams(0); + + if (!_cursorHover || !_cursorHover->_filename) stack->pushNULL(); + else stack->pushString(_cursorHover->_filename); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverCursorObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverCursorObject") == 0) { + stack->correctParams(0); + + if (!_cursorHover) stack->pushNULL(); + else stack->pushNative(_cursorHover, true); + return STATUS_OK; + } + + else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdItem::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("item"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Name") == 0) { + _scValue->setString(_name); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // DisplayAmount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DisplayAmount") == 0) { + _scValue->setBool(_displayAmount); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Amount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Amount") == 0) { + _scValue->setInt(_amount); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetX") == 0) { + _scValue->setInt(_amountOffsetX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetY") == 0) { + _scValue->setInt(_amountOffsetY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountAlign + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountAlign") == 0) { + _scValue->setInt(_amountAlign); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountString + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountString") == 0) { + if (!_amountString) _scValue->setNULL(); + else _scValue->setString(_amountString); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // CursorCombined + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CursorCombined") == 0) { + _scValue->setBool(_cursorCombined); + return _scValue; + } + + else return CAdTalkHolder::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DisplayAmount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DisplayAmount") == 0) { + _displayAmount = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Amount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Amount") == 0) { + _amount = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetX") == 0) { + _amountOffsetX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetY") == 0) { + _amountOffsetY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountAlign + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountAlign") == 0) { + _amountAlign = (TTextAlign)value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountString + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountString") == 0) { + if (value->isNULL()) { + delete[] _amountString; + _amountString = NULL; + } else { + CBUtils::setString(&_amountString, value->getString()); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CursorCombined + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CursorCombined") == 0) { + _cursorCombined = value->getBool(); + return STATUS_OK; + } + + else return CAdTalkHolder::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdItem::scToString() { + return "[item]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::persist(CBPersistMgr *persistMgr) { + + CAdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_cursorCombined)); + persistMgr->transfer(TMEMBER(_cursorHover)); + persistMgr->transfer(TMEMBER(_cursorNormal)); + persistMgr->transfer(TMEMBER(_spriteHover)); + persistMgr->transfer(TMEMBER(_inInventory)); + persistMgr->transfer(TMEMBER(_displayAmount)); + persistMgr->transfer(TMEMBER(_amount)); + persistMgr->transfer(TMEMBER(_amountOffsetX)); + persistMgr->transfer(TMEMBER(_amountOffsetY)); + persistMgr->transfer(TMEMBER_INT(_amountAlign)); + persistMgr->transfer(TMEMBER(_amountString)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::getExtendedFlag(const char *flagName) { + if (!flagName) return false; + else if (strcmp(flagName, "usable") == 0) return true; + else return CAdObject::getExtendedFlag(flagName); +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdItem.h b/engines/wintermute/ad/AdItem.h new file mode 100644 index 0000000000..d45f9cc614 --- /dev/null +++ b/engines/wintermute/ad/AdItem.h @@ -0,0 +1,70 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADITEM_H +#define WINTERMUTE_ADITEM_H + + +#include "engines/wintermute/ad/AdTalkHolder.h" + +namespace WinterMute { + +class CAdItem : public CAdTalkHolder { +public: + bool _displayAmount; + int _amount; + int _amountOffsetX; + int _amountOffsetY; + TTextAlign _amountAlign; + char *_amountString; + + + bool update(); + DECLARE_PERSISTENT(CAdItem, CAdTalkHolder) + bool display(int x, int y); + bool getExtendedFlag(const char *flagName); + bool _inInventory; + bool _cursorCombined; + CBSprite *_spriteHover; + CBSprite *_cursorNormal; + CBSprite *_cursorHover; + CAdItem(CBGame *inGame); + virtual ~CAdItem(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdLayer.cpp b/engines/wintermute/ad/AdLayer.cpp new file mode 100644 index 0000000000..d797172338 --- /dev/null +++ b/engines/wintermute/ad/AdLayer.cpp @@ -0,0 +1,537 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/ad/AdLayer.h" +#include "engines/wintermute/ad/AdSceneNode.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/PlatformSDL.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdLayer, false) + +////////////////////////////////////////////////////////////////////////// +CAdLayer::CAdLayer(CBGame *inGame): CBObject(inGame) { + _main = false; + _width = _height = 0; + _active = true; + _closeUp = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdLayer::~CAdLayer() { + for (int i = 0; i < _nodes.getSize(); i++) + delete _nodes[i]; + _nodes.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdLayer::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(LAYER) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(WIDTH) +TOKEN_DEF(HEIGHT) +TOKEN_DEF(MAIN) +TOKEN_DEF(ENTITY) +TOKEN_DEF(REGION) +TOKEN_DEF(ACTIVE) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(CLOSE_UP) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(LAYER) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(WIDTH) + TOKEN_TABLE(HEIGHT) + TOKEN_TABLE(MAIN) + TOKEN_TABLE(ENTITY) + TOKEN_TABLE(REGION) + TOKEN_TABLE(ACTIVE) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(CLOSE_UP) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_LAYER) { + _gameRef->LOG(0, "'LAYER' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_MAIN: + parser.scanStr((char *)params, "%b", &_main); + break; + + case TOKEN_CLOSE_UP: + parser.scanStr((char *)params, "%b", &_closeUp); + break; + + case TOKEN_WIDTH: + parser.scanStr((char *)params, "%d", &_width); + break; + + case TOKEN_HEIGHT: + parser.scanStr((char *)params, "%d", &_height); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_REGION: { + CAdRegion *region = new CAdRegion(_gameRef); + CAdSceneNode *node = new CAdSceneNode(_gameRef); + if (!region || !node || DID_FAIL(region->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete region; + delete node; + region = NULL; + node = NULL; + } else { + node->setRegion(region); + _nodes.add(node); + } + } + break; + + case TOKEN_ENTITY: { + CAdEntity *entity = new CAdEntity(_gameRef); + CAdSceneNode *node = new CAdSceneNode(_gameRef); + if (entity) entity->_zoomable = false; // scene entites default to NOT zoom + if (!entity || !node || DID_FAIL(entity->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete entity; + delete node; + entity = NULL; + node = NULL; + } else { + node->setEntity(entity); + _nodes.add(node); + } + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in LAYER definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // GetNode + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "GetNode") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + int node = -1; + + if (val->_type == VAL_INT) node = val->getInt(); + else { // get by name + for (int i = 0; i < _nodes.getSize(); i++) { + if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->_name, val->getString()) == 0) || + (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->_name, val->getString()) == 0)) { + node = i; + break; + } + } + } + + if (node < 0 || node >= _nodes.getSize()) stack->pushNULL(); + else { + switch (_nodes[node]->_type) { + case OBJECT_ENTITY: + stack->pushNative(_nodes[node]->_entity, true); + break; + case OBJECT_REGION: + stack->pushNative(_nodes[node]->_region, true); + break; + default: + stack->pushNULL(); + } + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddRegion / AddEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddRegion") == 0 || strcmp(name, "AddEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdSceneNode *node = new CAdSceneNode(_gameRef); + if (strcmp(name, "AddRegion") == 0) { + CAdRegion *region = new CAdRegion(_gameRef); + if (!val->isNULL()) region->setName(val->getString()); + node->setRegion(region); + stack->pushNative(region, true); + } else { + CAdEntity *entity = new CAdEntity(_gameRef); + if (!val->isNULL()) entity->setName(val->getString()); + node->setEntity(entity); + stack->pushNative(entity, true); + } + _nodes.add(node); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InsertRegion / InsertEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InsertRegion") == 0 || strcmp(name, "InsertEntity") == 0) { + stack->correctParams(2); + int index = stack->pop()->getInt(); + CScValue *val = stack->pop(); + + CAdSceneNode *node = new CAdSceneNode(_gameRef); + if (strcmp(name, "InsertRegion") == 0) { + CAdRegion *region = new CAdRegion(_gameRef); + if (!val->isNULL()) region->setName(val->getString()); + node->setRegion(region); + stack->pushNative(region, true); + } else { + CAdEntity *entity = new CAdEntity(_gameRef); + if (!val->isNULL()) entity->setName(val->getString()); + node->setEntity(entity); + stack->pushNative(entity, true); + } + if (index < 0) index = 0; + if (index <= _nodes.getSize() - 1) _nodes.insertAt(index, node); + else _nodes.add(node); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteNode") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdSceneNode *toDelete = NULL; + if (val->isNative()) { + CBScriptable *temp = val->getNative(); + for (int i = 0; i < _nodes.getSize(); i++) { + if (_nodes[i]->_region == temp || _nodes[i]->_entity == temp) { + toDelete = _nodes[i]; + break; + } + } + } else { + int index = val->getInt(); + if (index >= 0 && index < _nodes.getSize()) { + toDelete = _nodes[index]; + } + } + if (toDelete == NULL) { + stack->pushBool(false); + return STATUS_OK; + } + + for (int i = 0; i < _nodes.getSize(); i++) { + if (_nodes[i] == toDelete) { + delete _nodes[i]; + _nodes[i] = NULL; + _nodes.removeAt(i); + break; + } + } + stack->pushBool(true); + return STATUS_OK; + } + + else return CBObject::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdLayer::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("layer"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumNodes (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumNodes") == 0) { + _scValue->setInt(_nodes.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Width + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + _scValue->setInt(_width); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Height + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + _scValue->setInt(_height); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Main (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Main") == 0) { + _scValue->setBool(_main); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // CloseUp + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CloseUp") == 0) { + _scValue->setBool(_closeUp); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } + + else return CBObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CloseUp + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CloseUp") == 0) { + _closeUp = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Width + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + _width = value->getInt(); + if (_width < 0) _width = 0; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Height + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + _height = value->getInt(); + if (_height < 0) _height = 0; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + bool b = value->getBool(); + if (b == false && _main) { + _gameRef->LOG(0, "Warning: cannot deactivate scene's main layer"); + } else _active = b; + return STATUS_OK; + } + + else return CBObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdLayer::scToString() { + return "[layer]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "LAYER {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + buffer->putTextIndent(indent + 2, "MAIN=%s\n", _main ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "WIDTH=%d\n", _width); + buffer->putTextIndent(indent + 2, "HEIGHT=%d\n", _height); + buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + if (_closeUp) + buffer->putTextIndent(indent + 2, "CLOSE_UP=%s\n", _closeUp ? "TRUE" : "FALSE"); + + int i; + + for (i = 0; i < _scripts.getSize(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_scProp) _scProp->saveAsText(buffer, indent + 2); + + for (i = 0; i < _nodes.getSize(); i++) { + switch (_nodes[i]->_type) { + case OBJECT_ENTITY: + _nodes[i]->_entity->saveAsText(buffer, indent + 2); + break; + case OBJECT_REGION: + _nodes[i]->_region->saveAsText(buffer, indent + 2); + break; + default: + error("CAdLayer::SaveAsText - Unhandled enum"); + break; + } + } + + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_closeUp)); + persistMgr->transfer(TMEMBER(_height)); + persistMgr->transfer(TMEMBER(_main)); + _nodes.persist(persistMgr); + persistMgr->transfer(TMEMBER(_width)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdLayer.h b/engines/wintermute/ad/AdLayer.h new file mode 100644 index 0000000000..0ccdb13ae7 --- /dev/null +++ b/engines/wintermute/ad/AdLayer.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADLAYER_H +#define WINTERMUTE_ADLAYER_H + +namespace WinterMute { +class CAdSceneNode; +class CAdLayer : public CBObject { +public: + bool _closeUp; + DECLARE_PERSISTENT(CAdLayer, CBObject) + bool _active; + int _height; + int _width; + bool _main; + CAdLayer(CBGame *inGame); + virtual ~CAdLayer(); + CBArray _nodes; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdNodeState.cpp b/engines/wintermute/ad/AdNodeState.cpp new file mode 100644 index 0000000000..8e9894b5f5 --- /dev/null +++ b/engines/wintermute/ad/AdNodeState.cpp @@ -0,0 +1,169 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/ad/AdNodeState.h" +#include "engines/wintermute/ad/AdEntity.h" +#include "engines/wintermute/base/BStringTable.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/PlatformSDL.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdNodeState, false) + + +////////////////////////////////////////////////////////////////////////// +CAdNodeState::CAdNodeState(CBGame *inGame): CBBase(inGame) { + _name = NULL; + _active = false; + for (int i = 0; i < 7; i++) _caption[i] = NULL; + _alphaColor = 0; + _filename = NULL; + _cursor = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdNodeState::~CAdNodeState() { + delete[] _name; + delete[] _filename; + delete[] _cursor; + _name = NULL; + _filename = NULL; + _cursor = NULL; + for (int i = 0; i < 7; i++) { + delete[] _caption[i]; + _caption[i] = NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdNodeState::setName(const char *name) { + delete[] _name; + _name = NULL; + CBUtils::setString(&_name, name); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdNodeState::setFilename(const char *filename) { + delete[] _filename; + _filename = NULL; + CBUtils::setString(&_filename, filename); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdNodeState::setCursor(const char *filename) { + delete[] _cursor; + _cursor = NULL; + CBUtils::setString(&_cursor, filename); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdNodeState::persist(CBPersistMgr *persistMgr) { + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_name)); + persistMgr->transfer(TMEMBER(_filename)); + persistMgr->transfer(TMEMBER(_cursor)); + persistMgr->transfer(TMEMBER(_alphaColor)); + for (int i = 0; i < 7; i++) persistMgr->transfer(TMEMBER(_caption[i])); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdNodeState::setCaption(const char *caption, int caseVal) { + if (caseVal== 0) caseVal= 1; + if (caseVal< 1 || caseVal> 7) return; + + delete[] _caption[caseVal- 1]; + _caption[caseVal- 1] = new char[strlen(caption) + 1]; + if (_caption[caseVal- 1]) { + strcpy(_caption[caseVal- 1], caption); + _gameRef->_stringTable->expand(&_caption[caseVal- 1]); + } +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdNodeState::getCaption(int caseVal) { + if (caseVal== 0) caseVal= 1; + if (caseVal< 1 || caseVal> 7 || _caption[caseVal- 1] == NULL) return ""; + else return _caption[caseVal- 1]; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdNodeState::transferEntity(CAdEntity *entity, bool includingSprites, bool saving) { + if (!entity) return STATUS_FAILED; + + // hack! + if (this->_gameRef != entity->_gameRef) this->_gameRef = entity->_gameRef; + + if (saving) { + for (int i = 0; i < 7; i++) { + if (entity->_caption[i]) setCaption(entity->_caption[i], i); + } + if (!entity->_region && entity->_sprite && entity->_sprite->_filename) { + if (includingSprites) setFilename(entity->_sprite->_filename); + else setFilename(""); + } + if (entity->_cursor && entity->_cursor->_filename) setCursor(entity->_cursor->_filename); + _alphaColor = entity->_alphaColor; + _active = entity->_active; + } else { + for (int i = 0; i < 7; i++) { + if (_caption[i]) entity->setCaption(_caption[i], i); + } + if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) { + if (!entity->_sprite || !entity->_sprite->_filename || scumm_stricmp(entity->_sprite->_filename, _filename) != 0) + entity->setSprite(_filename); + } + if (_cursor) { + if (!entity->_cursor || !entity->_cursor->_filename || scumm_stricmp(entity->_cursor->_filename, _cursor) != 0) + entity->setCursor(_cursor); + } + + entity->_active = _active; + entity->_alphaColor = _alphaColor; + } + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdNodeState.h b/engines/wintermute/ad/AdNodeState.h new file mode 100644 index 0000000000..186f2ebbb2 --- /dev/null +++ b/engines/wintermute/ad/AdNodeState.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADNODESTATE_H +#define WINTERMUTE_ADNODESTATE_H + +namespace WinterMute { + +class CAdEntity; + +class CAdNodeState : public CBBase { +public: + bool transferEntity(CAdEntity *entity, bool includingSprites, bool saving); + void setName(const char *name); + void setFilename(const char *filename); + void setCursor(const char *filename); + DECLARE_PERSISTENT(CAdNodeState, CBBase) + CAdNodeState(CBGame *inGame); + virtual ~CAdNodeState(); + char *_name; + bool _active; + char *_caption[7]; + void setCaption(const char *caption, int caseVal); + char *getCaption(int caseVal); + uint32 _alphaColor; + char *_filename; + char *_cursor; + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdObject.cpp b/engines/wintermute/ad/AdObject.cpp new file mode 100644 index 0000000000..c74c8cf6b3 --- /dev/null +++ b/engines/wintermute/ad/AdObject.cpp @@ -0,0 +1,1203 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdItem.h" +#include "engines/wintermute/ad/AdObject.h" +#include "engines/wintermute/ad/AdInventory.h" +#include "engines/wintermute/ad/AdLayer.h" +#include "engines/wintermute/ad/AdScene.h" +#include "engines/wintermute/ad/AdSceneNode.h" +#include "engines/wintermute/ad/AdSentence.h" +#include "engines/wintermute/ad/AdWaypointGroup.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BFrame.h" +#include "engines/wintermute/base/BSound.h" +#include "engines/wintermute/base/BSurfaceStorage.h" +#include "engines/wintermute/base/BSubFrame.h" +#include "engines/wintermute/base/font/BFont.h" +#include "engines/wintermute/base/font/BFontStorage.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/base/BStringTable.h" +#include "engines/wintermute/base/scriptables/ScEngine.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "common/str.h" +#include "common/util.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdObject, false) + +////////////////////////////////////////////////////////////////////////// +CAdObject::CAdObject(CBGame *inGame): CBObject(inGame) { + _type = OBJECT_NONE; + _state = _nextState = STATE_NONE; + + _active = true; + _drawn = false; + + _currentSprite = NULL; + _animSprite = NULL; + _tempSprite2 = NULL; + + _font = NULL; + + _sentence = NULL; + + _forcedTalkAnimName = NULL; + _forcedTalkAnimUsed = false; + + _blockRegion = NULL; + _wptGroup = NULL; + + _currentBlockRegion = NULL; + _currentWptGroup = NULL; + + _ignoreItems = false; + _sceneIndependent = false; + + _stickRegion = NULL; + + _subtitlesModRelative = true; + _subtitlesModX = 0; + _subtitlesModY = 0; + _subtitlesWidth = 0; + _subtitlesModXCenter = true; + + _inventory = NULL; + + for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; + + _partEmitter = NULL; + _partFollowParent = false; + _partOffsetX = _partOffsetY = 0; + + _registerAlias = this; +} + + +////////////////////////////////////////////////////////////////////////// +CAdObject::~CAdObject() { + _currentSprite = NULL; // reference only, don't delete + delete _animSprite; + _animSprite = NULL; + delete _sentence; + _sentence = NULL; + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = NULL; + + delete _blockRegion; + _blockRegion = NULL; + delete _wptGroup; + _wptGroup = NULL; + + delete _currentBlockRegion; + _currentBlockRegion = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + + _tempSprite2 = NULL; // reference only + _stickRegion = NULL; + + if (_font) _gameRef->_fontStorage->removeFont(_font); + + if (_inventory) { + ((CAdGame *)_gameRef)->unregisterInventory(_inventory); + _inventory = NULL; + } + + if (_partEmitter) + _gameRef->unregisterObject(_partEmitter); + + + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + _gameRef->unregisterObject(_attachmentsPre[i]); + } + _attachmentsPre.removeAll(); + + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + _gameRef->unregisterObject(_attachmentsPost[i]); + } + _attachmentsPost.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::playAnim(const char *filename) { + delete _animSprite; + _animSprite = NULL; + _animSprite = new CBSprite(_gameRef, this); + if (!_animSprite) { + _gameRef->LOG(0, "CAdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); + return STATUS_FAILED; + } + bool res = _animSprite->loadFile(filename); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "CAdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); + delete _animSprite; + _animSprite = NULL; + return res; + } + _state = STATE_PLAYING_ANIM; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::display() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::update() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + + ////////////////////////////////////////////////////////////////////////// + // PlayAnim / PlayAnimAsync + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "PlayAnim") == 0 || strcmp(name, "PlayAnimAsync") == 0) { + stack->correctParams(1); + if (DID_FAIL(playAnim(stack->pop()->getString()))) stack->pushBool(false); + else { + if (strcmp(name, "PlayAnimAsync") != 0) script->waitFor(this); + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Reset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Reset") == 0) { + stack->correctParams(0); + reset(); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTalking") == 0) { + stack->correctParams(0); + stack->pushBool(_state == STATE_TALKING); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StopTalk / StopTalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StopTalk") == 0 || strcmp(name, "StopTalking") == 0) { + stack->correctParams(0); + if (_sentence) _sentence->finish(); + if (_state == STATE_TALKING) { + _state = _nextState; + _nextState = STATE_READY; + stack->pushBool(true); + } else stack->pushBool(false); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ForceTalkAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ForceTalkAnim") == 0) { + stack->correctParams(1); + const char *animName = stack->pop()->getString(); + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = new char[strlen(animName) + 1]; + strcpy(_forcedTalkAnimName, animName); + _forcedTalkAnimUsed = false; + stack->pushBool(true); + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // Talk / TalkAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Talk") == 0 || strcmp(name, "TalkAsync") == 0) { + stack->correctParams(5); + + const char *text = stack->pop()->getString(); + CScValue *soundVal = stack->pop(); + int duration = stack->pop()->getInt(); + CScValue *valStances = stack->pop(); + + const char *stances = valStances->isNULL() ? NULL : valStances->getString(); + + int align = 0; + CScValue *val = stack->pop(); + if (val->isNULL()) align = TAL_CENTER; + else align = val->getInt(); + + align = MIN(MAX(0, align), NUM_TEXT_ALIGN - 1); + + const char *sound = soundVal->isNULL() ? NULL : soundVal->getString(); + + talk(text, sound, duration, stances, (TTextAlign)align); + if (strcmp(name, "TalkAsync") != 0) script->waitForExclusive(this); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StickToRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StickToRegion") == 0) { + stack->correctParams(1); + + CAdLayer *main = ((CAdGame *)_gameRef)->_scene->_mainLayer; + bool regFound = false; + + int i; + CScValue *val = stack->pop(); + if (val->isNULL() || !main) { + _stickRegion = NULL; + regFound = true; + } else if (val->isString()) { + const char *regionName = val->getString(); + for (i = 0; i < main->_nodes.getSize(); i++) { + if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region->_name && scumm_stricmp(main->_nodes[i]->_region->_name, regionName) == 0) { + _stickRegion = main->_nodes[i]->_region; + regFound = true; + break; + } + } + } else if (val->isNative()) { + CBScriptable *obj = val->getNative(); + + for (i = 0; i < main->_nodes.getSize(); i++) { + if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region == obj) { + _stickRegion = main->_nodes[i]->_region; + regFound = true; + break; + } + } + + } + + if (!regFound) _stickRegion = NULL; + stack->pushBool(regFound); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetFont + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetFont") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + if (val->isNULL()) SetFont(NULL); + else SetFont(val->getString()); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFont + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFont") == 0) { + stack->correctParams(0); + if (_font && _font->_filename) stack->pushString(_font->_filename); + else stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TakeItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TakeItem") == 0) { + stack->correctParams(2); + + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + + CScValue *val = stack->pop(); + if (!val->isNULL()) { + const char *itemName = val->getString(); + val = stack->pop(); + const char *insertAfter = val->isNULL() ? NULL : val->getString(); + if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) script->runtimeError("Cannot add item '%s' to inventory", itemName); + else { + // hide associated entities + ((CAdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); + } + + } else script->runtimeError("TakeItem: item name expected"); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DropItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DropItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + + CScValue *val = stack->pop(); + if (!val->isNULL()) { + if (DID_FAIL(_inventory->removeItem(val->getString()))) script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); + else { + // show associated entities + ((CAdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); + } + } else script->runtimeError("DropItem: item name expected"); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + + CScValue *val = stack->pop(); + if (val->_type == VAL_STRING) { + CAdItem *item = ((CAdGame *)_gameRef)->getItemByName(val->getString()); + if (item) stack->pushNative(item, true); + else stack->pushNULL(); + } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) + stack->pushNULL(); + else + stack->pushNative(_inventory->_takenItems[val->getInt()], true); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // HasItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + + CScValue *val = stack->pop(); + if (!val->isNULL()) { + for (int i = 0; i < _inventory->_takenItems.getSize(); i++) { + if (val->getNative() == _inventory->_takenItems[i]) { + stack->pushBool(true); + return STATUS_OK; + } else if (scumm_stricmp(val->getString(), _inventory->_takenItems[i]->_name) == 0) { + stack->pushBool(true); + return STATUS_OK; + } + } + } else script->runtimeError("HasItem: item name expected"); + + stack->pushBool(false); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateParticleEmitter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateParticleEmitter") == 0) { + stack->correctParams(3); + bool followParent = stack->pop()->getBool(); + int offsetX = stack->pop()->getInt(); + int offsetY = stack->pop()->getInt(); + + CPartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); + if (emitter) stack->pushNative(_partEmitter, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteParticleEmitter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteParticleEmitter") == 0) { + stack->correctParams(0); + if (_partEmitter) { + _gameRef->unregisterObject(_partEmitter); + _partEmitter = NULL; + } + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddAttachment") == 0) { + stack->correctParams(4); + const char *filename = stack->pop()->getString(); + bool preDisplay = stack->pop()->getBool(true); + int offsetX = stack->pop()->getInt(); + int offsetY = stack->pop()->getInt(); + + bool res; + CAdEntity *ent = new CAdEntity(_gameRef); + if (DID_FAIL(res = ent->loadFile(filename))) { + delete ent; + ent = NULL; + script->runtimeError("AddAttachment() failed loading entity '%s'", filename); + stack->pushBool(false); + } else { + _gameRef->registerObject(ent); + + ent->_posX = offsetX; + ent->_posY = offsetY; + ent->_active = true; + + if (preDisplay) _attachmentsPre.add(ent); + else _attachmentsPost.add(ent); + + stack->pushBool(true); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveAttachment") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + bool found = false; + if (val->isNative()) { + CBScriptable *obj = val->getNative(); + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + if (_attachmentsPre[i] == obj) { + found = true; + _gameRef->unregisterObject(_attachmentsPre[i]); + _attachmentsPre.removeAt(i); + i--; + } + } + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + if (_attachmentsPost[i] == obj) { + found = true; + _gameRef->unregisterObject(_attachmentsPost[i]); + _attachmentsPost.removeAt(i); + i--; + } + } + } else { + const char *attachmentName = val->getString(); + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + if (_attachmentsPre[i]->_name && scumm_stricmp(_attachmentsPre[i]->_name, attachmentName) == 0) { + found = true; + _gameRef->unregisterObject(_attachmentsPre[i]); + _attachmentsPre.removeAt(i); + i--; + } + } + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + if (_attachmentsPost[i]->_name && scumm_stricmp(_attachmentsPost[i]->_name, attachmentName) == 0) { + found = true; + _gameRef->unregisterObject(_attachmentsPost[i]); + _attachmentsPost.removeAt(i); + i--; + } + } + } + stack->pushBool(found); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetAttachment") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdObject *ret = NULL; + if (val->isInt()) { + int index = val->getInt(); + int currIndex = 0; + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + if (currIndex == index) ret = _attachmentsPre[i]; + currIndex++; + } + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + if (currIndex == index) ret = _attachmentsPost[i]; + currIndex++; + } + } else { + const char *attachmentName = val->getString(); + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + if (_attachmentsPre[i]->_name && scumm_stricmp(_attachmentsPre[i]->_name, attachmentName) == 0) { + ret = _attachmentsPre[i]; + break; + } + } + if (!ret) { + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + if (_attachmentsPost[i]->_name && scumm_stricmp(_attachmentsPost[i]->_name, attachmentName) == 0) { + ret = _attachmentsPre[i]; + break; + } + } + } + } + + if (ret != NULL) stack->pushNative(ret, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + else return CBObject::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdObject::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("object"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // IgnoreItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IgnoreItems") == 0) { + _scValue->setBool(_ignoreItems); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SceneIndependent + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SceneIndependent") == 0) { + _scValue->setBool(_sceneIndependent); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesWidth + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesWidth") == 0) { + _scValue->setInt(_subtitlesWidth); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosRelative + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosRelative") == 0) { + _scValue->setBool(_subtitlesModRelative); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosX") == 0) { + _scValue->setInt(_subtitlesModX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosY") == 0) { + _scValue->setInt(_subtitlesModY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosXCenter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosXCenter") == 0) { + _scValue->setBool(_subtitlesModXCenter); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumItems (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumItems") == 0) { + _scValue->setInt(getInventory()->_takenItems.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ParticleEmitter (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ParticleEmitter") == 0) { + if (_partEmitter) _scValue->setNative(_partEmitter, true); + else _scValue->setNULL(); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumAttachments (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumAttachments") == 0) { + _scValue->setInt(_attachmentsPre.getSize() + _attachmentsPost.getSize()); + return _scValue; + } + + + else return CBObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::scSetProperty(const char *name, CScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Active") == 0) { + _active = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IgnoreItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IgnoreItems") == 0) { + _ignoreItems = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SceneIndependent + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SceneIndependent") == 0) { + _sceneIndependent = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesWidth + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesWidth") == 0) { + _subtitlesWidth = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosRelative + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosRelative") == 0) { + _subtitlesModRelative = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosX") == 0) { + _subtitlesModX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosY") == 0) { + _subtitlesModY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosXCenter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosXCenter") == 0) { + _subtitlesModXCenter = value->getBool(); + return STATUS_OK; + } + + else return CBObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdObject::scToString() { + return "[ad object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::SetFont(const char *filename) { + if (_font) _gameRef->_fontStorage->removeFont(_font); + if (filename) { + _font = _gameRef->_fontStorage->addFont(filename); + return _font == NULL ? STATUS_FAILED : STATUS_OK; + } else { + _font = NULL; + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +int CAdObject::getHeight() { + if (!_currentSprite) return 0; + else { + CBFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; + int ret = 0; + for (int i = 0; i < frame->_subframes.getSize(); i++) { + ret = MAX(ret, frame->_subframes[i]->_hotspotY); + } + + if (_zoomable) { + float zoom = ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY); + ret = (int)(ret * zoom / 100); + } + return ret; + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { + if (!_sentence) _sentence = new CAdSentence(_gameRef); + if (!_sentence) return; + + if (_forcedTalkAnimName && _forcedTalkAnimUsed) { + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = NULL; + _forcedTalkAnimUsed = false; + } + + delete(_sentence->_sound); + _sentence->_sound = NULL; + + _sentence->setText(text); + _gameRef->_stringTable->expand(&_sentence->_text); + _sentence->setStances(stances); + _sentence->_duration = duration; + _sentence->_align = Align; + _sentence->_startTime = _gameRef->_timer; + _sentence->_currentStance = -1; + _sentence->_font = _font == NULL ? _gameRef->_systemFont : _font; + _sentence->_freezable = _freezable; + + // try to locate speech file automatically + bool deleteSound = false; + if (!sound) { + char *key = _gameRef->_stringTable->getKey(text); + if (key) { + sound = ((CAdGame *)_gameRef)->findSpeechFile(key); + delete [] key; + + if (sound) deleteSound = true; + } + } + + // load sound and set duration appropriately + if (sound) { + CBSound *snd = new CBSound(_gameRef); + if (snd && DID_SUCCEED(snd->setSound(sound, Audio::Mixer::kSpeechSoundType, true))) { + _sentence->setSound(snd); + if (_sentence->_duration <= 0) { + uint32 Length = snd->getLength(); + if (Length != 0) _sentence->_duration = Length; + } + } else delete snd; + } + + // set duration by text length + if (_sentence->_duration <= 0) {// TODO: Avoid longs. + _sentence->_duration = MAX((size_t)1000, _gameRef->_subtitlesSpeed * strlen(_sentence->_text)); + } + + + int x, y, width, height; + + x = _posX; + y = _posY; + + if (!_sceneIndependent && _subtitlesModRelative) { + x -= ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); + y -= ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + } + + + if (_subtitlesWidth > 0) width = _subtitlesWidth; + else { + if ((x < _gameRef->_renderer->_width / 4 || x > _gameRef->_renderer->_width * 0.75) && !_gameRef->_touchInterface) { + width = MAX(_gameRef->_renderer->_width / 4, MIN(x * 2, (_gameRef->_renderer->_width - x) * 2)); + } else width = _gameRef->_renderer->_width / 2; + } + + height = _sentence->_font->getTextHeight((byte *)_sentence->_text, width); + + y = y - height - getHeight() - 5; + if (_subtitlesModRelative) { + x += _subtitlesModX; + y += _subtitlesModY; + } else { + x = _subtitlesModX; + y = _subtitlesModY; + } + if (_subtitlesModXCenter) + x = x - width / 2; + + + x = MIN(MAX(0, x), _gameRef->_renderer->_width - width); + y = MIN(MAX(0, y), _gameRef->_renderer->_height - height); + + _sentence->_width = width; + + + _sentence->_pos.x = x; + _sentence->_pos.y = y; + + + if (_subtitlesModRelative) { + _sentence->_pos.x += ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); + _sentence->_pos.y += ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + } + + _sentence->_fixedPos = !_subtitlesModRelative; + + + _sentence->setupTalkFile(sound); + + _state = STATE_TALKING; + + if (deleteSound) delete [] sound; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::reset() { + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL) { + delete _animSprite; + _animSprite = NULL; + } else if (_state == STATE_TALKING && _sentence) { + _sentence->finish(); + } + + _state = _nextState = STATE_READY; + + _gameRef->_scEngine->resetObject(this); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::persist(CBPersistMgr *persistMgr) { + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_blockRegion)); + persistMgr->transfer(TMEMBER(_currentBlockRegion)); + persistMgr->transfer(TMEMBER(_currentWptGroup)); + persistMgr->transfer(TMEMBER(_currentSprite)); + persistMgr->transfer(TMEMBER(_drawn)); + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_ignoreItems)); + persistMgr->transfer(TMEMBER_INT(_nextState)); + persistMgr->transfer(TMEMBER(_sentence)); + persistMgr->transfer(TMEMBER_INT(_state)); + persistMgr->transfer(TMEMBER(_animSprite)); + persistMgr->transfer(TMEMBER(_sceneIndependent)); + persistMgr->transfer(TMEMBER(_forcedTalkAnimName)); + persistMgr->transfer(TMEMBER(_forcedTalkAnimUsed)); + persistMgr->transfer(TMEMBER(_tempSprite2)); + persistMgr->transfer(TMEMBER_INT(_type)); + persistMgr->transfer(TMEMBER(_wptGroup)); + persistMgr->transfer(TMEMBER(_stickRegion)); + persistMgr->transfer(TMEMBER(_subtitlesModRelative)); + persistMgr->transfer(TMEMBER(_subtitlesModX)); + persistMgr->transfer(TMEMBER(_subtitlesModY)); + persistMgr->transfer(TMEMBER(_subtitlesModXCenter)); + persistMgr->transfer(TMEMBER(_subtitlesWidth)); + persistMgr->transfer(TMEMBER(_inventory)); + persistMgr->transfer(TMEMBER(_partEmitter)); + + for (int i = 0; i < MAX_NUM_REGIONS; i++) persistMgr->transfer(TMEMBER(_currentRegions[i])); + + _attachmentsPre.persist(persistMgr); + _attachmentsPost.persist(persistMgr); + persistMgr->transfer(TMEMBER(_registerAlias)); + + persistMgr->transfer(TMEMBER(_partFollowParent)); + persistMgr->transfer(TMEMBER(_partOffsetX)); + persistMgr->transfer(TMEMBER(_partOffsetY)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::updateSounds() { + if (_sentence && _sentence->_sound) + updateOneSound(_sentence->_sound); + + return CBObject::updateSounds(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::resetSoundPan() { + if (_sentence && _sentence->_sound) { + _sentence->_sound->setPan(0.0f); + } + return CBObject::resetSoundPan(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::getExtendedFlag(const char *flagName) { + if (!flagName) return false; + else if (strcmp(flagName, "usable") == 0) return true; + + else return CBObject::getExtendedFlag(flagName); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::saveAsText(CBDynBuffer *buffer, int indent) { + if (_blockRegion) _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); + if (_wptGroup) _wptGroup->saveAsText(buffer, indent + 2); + + CBBase::saveAsText(buffer, indent + 2); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::updateBlockRegion() { + CAdGame *adGame = (CAdGame *)_gameRef; + if (adGame->_scene) { + if (_blockRegion && _currentBlockRegion) + _currentBlockRegion->mimic(_blockRegion, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + + if (_wptGroup && _currentWptGroup) + _currentWptGroup->mimic(_wptGroup, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +CAdInventory *CAdObject::getInventory() { + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + return _inventory; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::afterMove() { + CAdRegion *newRegions[MAX_NUM_REGIONS]; + + ((CAdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + if (!newRegions[i]) break; + bool regFound = false; + for (int j = 0; j < MAX_NUM_REGIONS; j++) { + if (_currentRegions[j] == newRegions[i]) { + _currentRegions[j] = NULL; + regFound = true; + break; + } + } + if (!regFound) newRegions[i]->applyEvent("ActorEntry"); + } + + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + if (_currentRegions[i] && _gameRef->validObject(_currentRegions[i])) { + _currentRegions[i]->applyEvent("ActorLeave"); + } + _currentRegions[i] = newRegions[i]; + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::invalidateCurrRegions() { + for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::getScale(float *scaleX, float *scaleY) { + if (_zoomable) { + if (_scaleX >= 0 || _scaleY >= 0) { + *scaleX = _scaleX < 0 ? 100 : _scaleX; + *scaleY = _scaleY < 0 ? 100 : _scaleY; + } else if (_scale >= 0) *scaleX = *scaleY = _scale; + else *scaleX = *scaleY = ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; + } else { + *scaleX = *scaleY = 100; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::updateSpriteAttachments() { + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + _attachmentsPre[i]->update(); + } + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + _attachmentsPost[i]->update(); + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::displaySpriteAttachments(bool preDisplay) { + if (preDisplay) { + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + displaySpriteAttachment(_attachmentsPre[i]); + } + } else { + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + displaySpriteAttachment(_attachmentsPost[i]); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::displaySpriteAttachment(CAdObject *attachment) { + if (!attachment->_active) return STATUS_OK; + + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + int origX = attachment->_posX; + int origY = attachment->_posY; + + // inherit position from owner + attachment->_posX = (int)(this->_posX + attachment->_posX * scaleX / 100.0f); + attachment->_posY = (int)(this->_posY + attachment->_posY * scaleY / 100.0f); + + // inherit other props + attachment->_alphaColor = this->_alphaColor; + attachment->_blendMode = this->_blendMode; + + attachment->_scale = this->_scale; + attachment->_relativeScale = this->_relativeScale; + attachment->_scaleX = this->_scaleX; + attachment->_scaleY = this->_scaleY; + + attachment->_rotate = this->_rotate; + attachment->_relativeRotate = this->_relativeRotate; + attachment->_rotateValid = this->_rotateValid; + + attachment->_registerAlias = this; + attachment->_registrable = this->_registrable; + + bool ret = attachment->display(); + + attachment->_posX = origX; + attachment->_posY = origY; + + return ret; +} + +////////////////////////////////////////////////////////////////////////// +CPartEmitter *CAdObject::createParticleEmitter(bool followParent, int offsetX, int offsetY) { + _partFollowParent = followParent; + _partOffsetX = offsetX; + _partOffsetY = offsetY; + + if (!_partEmitter) { + _partEmitter = new CPartEmitter(_gameRef, this); + if (_partEmitter) { + _gameRef->registerObject(_partEmitter); + } + } + updatePartEmitter(); + return _partEmitter; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::updatePartEmitter() { + if (!_partEmitter) return STATUS_FAILED; + + if (_partFollowParent) { + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + _partEmitter->_posX = (int)(_posX + (scaleX / 100.0f) * _partOffsetX); + _partEmitter->_posY = (int)(_posY + (scaleY / 100.0f) * _partOffsetY); + } + return _partEmitter->update(); +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdObject.h b/engines/wintermute/ad/AdObject.h new file mode 100644 index 0000000000..d662e84729 --- /dev/null +++ b/engines/wintermute/ad/AdObject.h @@ -0,0 +1,123 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADOBJECT_H +#define WINTERMUTE_ADOBJECT_H + +#include "engines/wintermute/ad/AdTypes.h" +#include "engines/wintermute/base/particles/PartEmitter.h" + +namespace WinterMute { + +class CAdWaypointGroup; +class CAdRegion; +class CAdSentence; +class CBFont; +class CBRegion; +class CAdInventory; + +#define MAX_NUM_REGIONS 10 + +class CAdObject : public CBObject { +public: + CPartEmitter *_partEmitter; + virtual CPartEmitter *createParticleEmitter(bool followParent = false, int offsetX = 0, int offsetY = 0); + virtual bool updatePartEmitter(); + bool _partFollowParent; + int _partOffsetX; + int _partOffsetY; + + bool invalidateCurrRegions(); + bool _subtitlesModRelative; + bool _subtitlesModXCenter; + int _subtitlesModX; + int _subtitlesModY; + int _subtitlesWidth; + CAdRegion *_stickRegion; + bool _sceneIndependent; + bool _ignoreItems; + bool updateBlockRegion(); + bool _forcedTalkAnimUsed; + char *_forcedTalkAnimName; + virtual bool getExtendedFlag(const char *flagName); + virtual bool resetSoundPan(); + virtual bool updateSounds(); + bool reset(); + DECLARE_PERSISTENT(CAdObject, CBObject) + virtual void talk(const char *text, const char *sound = NULL, uint32 duration = 0, const char *stances = NULL, TTextAlign align = TAL_CENTER); + virtual int getHeight(); + CAdSentence *_sentence; + bool SetFont(const char *filename); + virtual bool update(); + virtual bool display(); + bool _drawn; + bool _active; + virtual bool playAnim(const char *filename); + CBSprite *_animSprite; + CBSprite *_currentSprite; + TObjectState _state; + TObjectState _nextState; + TObjectType _type; + CAdObject(CBGame *inGame); + virtual ~CAdObject(); + CBFont *_font; + CBSprite *_tempSprite2; + CBRegion *_blockRegion; + CAdWaypointGroup *_wptGroup; + CBRegion *_currentBlockRegion; + CAdWaypointGroup *_currentWptGroup; + CAdInventory *getInventory(); + + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + + virtual bool afterMove(); + CAdRegion *_currentRegions[MAX_NUM_REGIONS]; + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + + CBArray _attachmentsPre; + CBArray _attachmentsPost; + + bool updateSpriteAttachments(); + bool displaySpriteAttachments(bool preDisplay); + CAdObject *_registerAlias; +private: + bool displaySpriteAttachment(CAdObject *attachment); + CAdInventory *_inventory; + +protected: + bool getScale(float *scaleX, float *scaleY); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdPath.cpp b/engines/wintermute/ad/AdPath.cpp new file mode 100644 index 0000000000..d1b9d87063 --- /dev/null +++ b/engines/wintermute/ad/AdPath.cpp @@ -0,0 +1,112 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdPath.h" +#include "engines/wintermute/base/BPoint.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdPath, false) + +////////////////////////////////////////////////////////////////////////// +CAdPath::CAdPath(CBGame *inGame): CBBase(inGame) { + _currIndex = -1; + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdPath::~CAdPath() { + reset(); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdPath::reset() { + for (int i = 0; i < _points.getSize(); i++) + delete _points[i]; + + _points.removeAll(); + _currIndex = -1; + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +CBPoint *CAdPath::getFirst() { + if (_points.getSize() > 0) { + _currIndex = 0; + return _points[_currIndex]; + } else return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CBPoint *CAdPath::getNext() { + _currIndex++; + if (_currIndex < _points.getSize()) return _points[_currIndex]; + else return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CBPoint *CAdPath::getCurrent() { + if (_currIndex >= 0 && _currIndex < _points.getSize()) return _points[_currIndex]; + else return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdPath::addPoint(CBPoint *point) { + _points.add(point); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdPath::setReady(bool ready) { + bool orig = _ready; + _ready = ready; + + return orig; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdPath::persist(CBPersistMgr *persistMgr) { + + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER(_currIndex)); + _points.persist(persistMgr); + persistMgr->transfer(TMEMBER(_ready)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdPath.h b/engines/wintermute/ad/AdPath.h new file mode 100644 index 0000000000..fdc2980042 --- /dev/null +++ b/engines/wintermute/ad/AdPath.h @@ -0,0 +1,56 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADPATH_H +#define WINTERMUTE_ADPATH_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/coll_templ.h" +#include "engines/wintermute/base/BBase.h" + +namespace WinterMute { +class CBPoint; +class CAdPath : public CBBase { +public: + DECLARE_PERSISTENT(CAdPath, CBBase) + CBPoint *getCurrent(); + bool setReady(bool ready = true); + void addPoint(CBPoint *point); + CBPoint *getNext(); + CBPoint *getFirst(); + void reset(); + CAdPath(CBGame *inGame); + virtual ~CAdPath(); + CBArray _points; + int _currIndex; + bool _ready; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdPathPoint.cpp b/engines/wintermute/ad/AdPathPoint.cpp new file mode 100644 index 0000000000..184ad8559a --- /dev/null +++ b/engines/wintermute/ad/AdPathPoint.cpp @@ -0,0 +1,75 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/AdPathPoint.h" +#include "engines/wintermute/base/BPersistMgr.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdPathPoint, false) + +////////////////////////////////////////////////////////////////////////// +CAdPathPoint::CAdPathPoint() { + x = y = 0; + _distance = 0; + + _marked = false; + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdPathPoint::CAdPathPoint(int initX, int initY, int initDistance) { + x = initX; + y = initY; + _distance = initDistance; + + _marked = false; + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdPathPoint::~CAdPathPoint() { + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdPathPoint::persist(CBPersistMgr *persistMgr) { + + CBPoint::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_distance)); + persistMgr->transfer(TMEMBER(_marked)); + persistMgr->transfer(TMEMBER(_origin)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdPathPoint.h b/engines/wintermute/ad/AdPathPoint.h new file mode 100644 index 0000000000..f58df765b1 --- /dev/null +++ b/engines/wintermute/ad/AdPathPoint.h @@ -0,0 +1,50 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADPATHPOINT_H +#define WINTERMUTE_ADPATHPOINT_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/BPoint.h" + +namespace WinterMute { + +class CAdPathPoint : public CBPoint { +public: + DECLARE_PERSISTENT(CAdPathPoint, CBPoint) + CAdPathPoint(int initX, int initY, int initDistance); + CAdPathPoint(); + virtual ~CAdPathPoint(); + CAdPathPoint *_origin; + bool _marked; + int _distance; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdRegion.cpp b/engines/wintermute/ad/AdRegion.cpp new file mode 100644 index 0000000000..a1864de1ac --- /dev/null +++ b/engines/wintermute/ad/AdRegion.cpp @@ -0,0 +1,392 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdRegion.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BFileManager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdRegion, false) + +////////////////////////////////////////////////////////////////////////// +CAdRegion::CAdRegion(CBGame *inGame): CBRegion(inGame) { + _blocked = false; + _decoration = false; + _zoom = 0; + _alpha = 0xFFFFFFFF; +} + + +////////////////////////////////////////////////////////////////////////// +CAdRegion::~CAdRegion() { +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdRegion::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(REGION) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(ACTIVE) +TOKEN_DEF(ZOOM) +TOKEN_DEF(SCALE) +TOKEN_DEF(BLOCKED) +TOKEN_DEF(DECORATION) +TOKEN_DEF(POINT) +TOKEN_DEF(ALPHA_COLOR) +TOKEN_DEF(ALPHA) +TOKEN_DEF(EDITOR_SELECTED_POINT) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(REGION) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(ACTIVE) + TOKEN_TABLE(ZOOM) + TOKEN_TABLE(SCALE) + TOKEN_TABLE(BLOCKED) + TOKEN_TABLE(DECORATION) + TOKEN_TABLE(POINT) + TOKEN_TABLE(ALPHA_COLOR) + TOKEN_TABLE(ALPHA) + TOKEN_TABLE(EDITOR_SELECTED_POINT) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { + _gameRef->LOG(0, "'REGION' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + for (int i = 0; i < _points.getSize(); i++) delete _points[i]; + _points.removeAll(); + + int ar = 255, ag = 255, ab = 255, alpha = 255; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_BLOCKED: + parser.scanStr((char *)params, "%b", &_blocked); + break; + + case TOKEN_DECORATION: + parser.scanStr((char *)params, "%b", &_decoration); + break; + + case TOKEN_ZOOM: + case TOKEN_SCALE: { + int j; + parser.scanStr((char *)params, "%d", &j); + _zoom = (float)j; + } + break; + + case TOKEN_POINT: { + int x, y; + parser.scanStr((char *)params, "%d,%d", &x, &y); + _points.add(new CBPoint(x, y)); + } + 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_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_EDITOR_SELECTED_POINT: + parser.scanStr((char *)params, "%d", &_editorSelectedPoint); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in REGION definition"); + return STATUS_FAILED; + } + + createRegion(); + + _alpha = BYTETORGBA(ar, ag, ab, alpha); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + /* + ////////////////////////////////////////////////////////////////////////// + // SkipTo + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SkipTo")==0) { + stack->correctParams(2); + _posX = stack->pop()->getInt(); + _posY = stack->pop()->getInt(); + stack->pushNULL(); + + return STATUS_OK; + } + + else*/ return CBRegion::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdRegion::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("ad region"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Name") == 0) { + _scValue->setString(_name); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Blocked + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Blocked") == 0) { + _scValue->setBool(_blocked); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Decoration + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Decoration") == 0) { + _scValue->setBool(_decoration); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Scale + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scale") == 0) { + _scValue->setFloat(_zoom); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AlphaColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AlphaColor") == 0) { + _scValue->setInt((int)_alpha); + return _scValue; + } + + else return CBRegion::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Blocked + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Blocked") == 0) { + _blocked = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Decoration + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Decoration") == 0) { + _decoration = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Scale + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scale") == 0) { + _zoom = value->getFloat(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AlphaColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AlphaColor") == 0) { + _alpha = (uint32)value->getInt(); + return STATUS_OK; + } + + else return CBRegion::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdRegion::scToString() { + return "[ad region]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "REGION {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + buffer->putTextIndent(indent + 2, "BLOCKED=%s\n", _blocked ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "DECORATION=%s\n", _decoration ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_zoom); + buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alpha), RGBCOLGetG(_alpha), RGBCOLGetB(_alpha)); + buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alpha)); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + + int i; + for (i = 0; i < _scripts.getSize(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_scProp) _scProp->saveAsText(buffer, indent + 2); + + for (i = 0; i < _points.getSize(); i++) { + buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); + } + + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::persist(CBPersistMgr *persistMgr) { + CBRegion::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_alpha)); + persistMgr->transfer(TMEMBER(_blocked)); + persistMgr->transfer(TMEMBER(_decoration)); + persistMgr->transfer(TMEMBER(_zoom)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdRegion.h b/engines/wintermute/ad/AdRegion.h new file mode 100644 index 0000000000..c91feb4012 --- /dev/null +++ b/engines/wintermute/ad/AdRegion.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADREGION_H +#define WINTERMUTE_ADREGION_H + +#include "engines/wintermute/base/BRegion.h" + +namespace WinterMute { + +class CAdRegion : public CBRegion { +public: + DECLARE_PERSISTENT(CAdRegion, CBRegion) + uint32 _alpha; + float _zoom; + bool _blocked; + bool _decoration; + CAdRegion(CBGame *inGame); + virtual ~CAdRegion(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdResponse.cpp b/engines/wintermute/ad/AdResponse.cpp new file mode 100644 index 0000000000..20617f9573 --- /dev/null +++ b/engines/wintermute/ad/AdResponse.cpp @@ -0,0 +1,143 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdResponse.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/font/BFontStorage.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/utils/utils.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdResponse, false) + +////////////////////////////////////////////////////////////////////////// +CAdResponse::CAdResponse(CBGame *inGame): CBObject(inGame) { + _text = NULL; + _textOrig = NULL; + _icon = _iconHover = _iconPressed = NULL; + _font = NULL; + _iD = 0; + _responseType = RESPONSE_ALWAYS; +} + + +////////////////////////////////////////////////////////////////////////// +CAdResponse::~CAdResponse() { + delete[] _text; + delete[] _textOrig; + delete _icon; + delete _iconHover; + delete _iconPressed; + _text = NULL; + _textOrig = NULL; + _icon = NULL; + _iconHover = NULL; + _iconPressed = NULL; + if (_font) _gameRef->_fontStorage->removeFont(_font); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdResponse::setText(const char *text) { + CBUtils::setString(&_text, text); + CBUtils::setString(&_textOrig, text); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::setIcon(const char *filename) { + delete _icon; + _icon = new CBSprite(_gameRef); + if (!_icon || DID_FAIL(_icon->loadFile(filename))) { + _gameRef->LOG(0, "CAdResponse::setIcon failed for file '%s'", filename); + delete _icon; + _icon = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::setFont(const char *filename) { + if (_font) _gameRef->_fontStorage->removeFont(_font); + _font = _gameRef->_fontStorage->addFont(filename); + if (!_font) { + _gameRef->LOG(0, "CAdResponse::setFont failed for file '%s'", filename); + return STATUS_FAILED; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::setIconHover(const char *filename) { + delete _iconHover; + _iconHover = new CBSprite(_gameRef); + if (!_iconHover || DID_FAIL(_iconHover->loadFile(filename))) { + _gameRef->LOG(0, "CAdResponse::setIconHover failed for file '%s'", filename); + delete _iconHover; + _iconHover = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::setIconPressed(const char *filename) { + delete _iconPressed; + _iconPressed = new CBSprite(_gameRef); + if (!_iconPressed || DID_FAIL(_iconPressed->loadFile(filename))) { + _gameRef->LOG(0, "CAdResponse::setIconPressed failed for file '%s'", filename); + delete _iconPressed; + _iconPressed = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_icon)); + persistMgr->transfer(TMEMBER(_iconHover)); + persistMgr->transfer(TMEMBER(_iconPressed)); + persistMgr->transfer(TMEMBER(_iD)); + persistMgr->transfer(TMEMBER(_text)); + persistMgr->transfer(TMEMBER(_textOrig)); + persistMgr->transfer(TMEMBER_INT(_responseType)); + persistMgr->transfer(TMEMBER(_font)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdResponse.h b/engines/wintermute/ad/AdResponse.h new file mode 100644 index 0000000000..646d781b89 --- /dev/null +++ b/engines/wintermute/ad/AdResponse.h @@ -0,0 +1,61 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSE_H +#define WINTERMUTE_ADRESPONSE_H + + +#include "engines/wintermute/base/BObject.h" +#include "engines/wintermute/ad/AdTypes.h" + +namespace WinterMute { +class CBFont; +class CAdResponse : public CBObject { +public: + DECLARE_PERSISTENT(CAdResponse, CBObject) + bool setIcon(const char *filename); + bool setFont(const char *filename); + bool setIconHover(const char *filename); + bool setIconPressed(const char *filename); + void setText(const char *text); + int _iD; + CBSprite *_icon; + CBSprite *_iconHover; + CBSprite *_iconPressed; + CBFont *_font; + char *_text; + char *_textOrig; + CAdResponse(CBGame *inGame); + virtual ~CAdResponse(); + TResponseType _responseType; + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdResponseBox.cpp b/engines/wintermute/ad/AdResponseBox.cpp new file mode 100644 index 0000000000..1a1732edd0 --- /dev/null +++ b/engines/wintermute/ad/AdResponseBox.cpp @@ -0,0 +1,647 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdResponseBox.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BSurfaceStorage.h" +#include "engines/wintermute/ui/UIButton.h" +#include "engines/wintermute/ui/UIWindow.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/font/BFontStorage.h" +#include "engines/wintermute/base/font/BFont.h" +#include "engines/wintermute/ad/AdResponse.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/PlatformSDL.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdResponseBox, false) + +////////////////////////////////////////////////////////////////////////// +CAdResponseBox::CAdResponseBox(CBGame *inGame): CBObject(inGame) { + _font = _fontHover = NULL; + + _window = NULL; + _shieldWindow = new CUIWindow(_gameRef); + + _horizontal = false; + CBPlatform::setRectEmpty(&_responseArea); + _scrollOffset = 0; + _spacing = 0; + + _waitingScript = NULL; + _lastResponseText = NULL; + _lastResponseTextOrig = NULL; + + _verticalAlign = VAL_BOTTOM; + _align = TAL_LEFT; +} + + +////////////////////////////////////////////////////////////////////////// +CAdResponseBox::~CAdResponseBox() { + + delete _window; + _window = NULL; + delete _shieldWindow; + _shieldWindow = NULL; + delete[] _lastResponseText; + _lastResponseText = NULL; + delete[] _lastResponseTextOrig; + _lastResponseTextOrig = NULL; + + if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + + clearResponses(); + clearButtons(); + + _waitingScript = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdResponseBox::clearResponses() { + for (int i = 0; i < _responses.getSize(); i++) { + delete _responses[i]; + } + _responses.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdResponseBox::clearButtons() { + for (int i = 0; i < _respButtons.getSize(); i++) { + delete _respButtons[i]; + } + _respButtons.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::invalidateButtons() { + for (int i = 0; i < _respButtons.getSize(); i++) { + _respButtons[i]->_image = NULL; + _respButtons[i]->_cursor = NULL; + _respButtons[i]->_font = NULL; + _respButtons[i]->_fontHover = NULL; + _respButtons[i]->_fontPress = NULL; + _respButtons[i]->setText(""); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::createButtons() { + clearButtons(); + + _scrollOffset = 0; + for (int i = 0; i < _responses.getSize(); i++) { + CUIButton *btn = new CUIButton(_gameRef); + if (btn) { + btn->_parent = _window; + btn->_sharedFonts = btn->_sharedImages = true; + btn->_sharedCursors = true; + // iconic + if (_responses[i]->_icon) { + btn->_image = _responses[i]->_icon; + if (_responses[i]->_iconHover) btn->_imageHover = _responses[i]->_iconHover; + if (_responses[i]->_iconPressed) btn->_imagePress = _responses[i]->_iconPressed; + + btn->setCaption(_responses[i]->_text); + if (_cursor) btn->_cursor = _cursor; + else if (_gameRef->_activeCursor) btn->_cursor = _gameRef->_activeCursor; + } + // textual + else { + btn->setText(_responses[i]->_text); + btn->_font = (_font == NULL) ? _gameRef->_systemFont : _font; + btn->_fontHover = (_fontHover == NULL) ? _gameRef->_systemFont : _fontHover; + btn->_fontPress = btn->_fontHover; + btn->_align = _align; + + if (_gameRef->_touchInterface) + btn->_fontHover = btn->_font; + + + if (_responses[i]->_font) btn->_font = _responses[i]->_font; + + btn->_width = _responseArea.right - _responseArea.left; + if (btn->_width <= 0) btn->_width = _gameRef->_renderer->_width; + } + btn->setName("response"); + btn->correctSize(); + + // make the responses touchable + if (_gameRef->_touchInterface) + btn->_height = MAX(btn->_height, 50); + + //btn->SetListener(this, btn, _responses[i]->_iD); + btn->setListener(this, btn, i); + btn->_visible = false; + _respButtons.add(btn); + + if (_responseArea.bottom - _responseArea.top < btn->_height) { + _gameRef->LOG(0, "Warning: Response '%s' is too high to be displayed within response box. Correcting.", _responses[i]->_text); + _responseArea.bottom += (btn->_height - (_responseArea.bottom - _responseArea.top)); + } + } + } + _ready = false; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdResponseBox::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(RESPONSE_BOX) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(FONT_HOVER) +TOKEN_DEF(FONT) +TOKEN_DEF(AREA) +TOKEN_DEF(HORIZONTAL) +TOKEN_DEF(SPACING) +TOKEN_DEF(WINDOW) +TOKEN_DEF(CURSOR) +TOKEN_DEF(TEXT_ALIGN) +TOKEN_DEF(VERTICAL_ALIGN) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(RESPONSE_BOX) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(FONT_HOVER) + TOKEN_TABLE(FONT) + TOKEN_TABLE(AREA) + TOKEN_TABLE(HORIZONTAL) + TOKEN_TABLE(SPACING) + TOKEN_TABLE(WINDOW) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(TEXT_ALIGN) + TOKEN_TABLE(VERTICAL_ALIGN) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_RESPONSE_BOX) { + _gameRef->LOG(0, "'RESPONSE_BOX' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_WINDOW: + delete _window; + _window = new CUIWindow(_gameRef); + if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { + delete _window; + _window = NULL; + cmd = PARSERR_GENERIC; + } else if (_shieldWindow) _shieldWindow->_parent = _window; + break; + + case TOKEN_FONT: + if (_font) _gameRef->_fontStorage->removeFont(_font); + _font = _gameRef->_fontStorage->addFont((char *)params); + if (!_font) cmd = PARSERR_GENERIC; + break; + + case TOKEN_FONT_HOVER: + if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + _fontHover = _gameRef->_fontStorage->addFont((char *)params); + if (!_fontHover) cmd = PARSERR_GENERIC; + break; + + case TOKEN_AREA: + parser.scanStr((char *)params, "%d,%d,%d,%d", &_responseArea.left, &_responseArea.top, &_responseArea.right, &_responseArea.bottom); + break; + + case TOKEN_HORIZONTAL: + parser.scanStr((char *)params, "%b", &_horizontal); + break; + + case TOKEN_TEXT_ALIGN: + if (scumm_stricmp((char *)params, "center") == 0) _align = TAL_CENTER; + else if (scumm_stricmp((char *)params, "right") == 0) _align = TAL_RIGHT; + else _align = TAL_LEFT; + break; + + case TOKEN_VERTICAL_ALIGN: + if (scumm_stricmp((char *)params, "top") == 0) _verticalAlign = VAL_TOP; + else if (scumm_stricmp((char *)params, "center") == 0) _verticalAlign = VAL_CENTER; + else _verticalAlign = VAL_BOTTOM; + break; + + case TOKEN_SPACING: + parser.scanStr((char *)params, "%d", &_spacing); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new CBSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in RESPONSE_BOX definition"); + return STATUS_FAILED; + } + + if (_window) { + for (int i = 0; i < _window->_widgets.getSize(); i++) { + if (!_window->_widgets[i]->_listenerObject) + _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "RESPONSE_BOX\n"); + buffer->putTextIndent(indent, "{\n"); + + buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _responseArea.left, _responseArea.top, _responseArea.right, _responseArea.bottom); + + if (_font && _font->_filename) + buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->_filename); + if (_fontHover && _fontHover->_filename) + buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->_filename); + + if (_cursor && _cursor->_filename) + buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); + + buffer->putTextIndent(indent + 2, "HORIZONTAL=%s\n", _horizontal ? "TRUE" : "FALSE"); + + switch (_align) { + case TAL_LEFT: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "left"); + break; + case TAL_RIGHT: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "right"); + break; + case TAL_CENTER: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "center"); + break; + default: + error("CAdResponseBox::SaveAsText - Unhandled enum"); + break; + } + + switch (_verticalAlign) { + case VAL_TOP: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "top"); + break; + case VAL_BOTTOM: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "bottom"); + break; + case VAL_CENTER: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "center"); + break; + } + + buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); + + buffer->putTextIndent(indent + 2, "\n"); + + // window + if (_window) _window->saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent + 2, "\n"); + + // editor properties + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::display() { + Rect32 rect = _responseArea; + if (_window) { + CBPlatform::offsetRect(&rect, _window->_posX, _window->_posY); + //_window->display(); + } + + int xxx, yyy, i; + + xxx = rect.left; + yyy = rect.top; + + // shift down if needed + if (!_horizontal) { + int total_height = 0; + for (i = 0; i < _respButtons.getSize(); i++) total_height += (_respButtons[i]->_height + _spacing); + total_height -= _spacing; + + switch (_verticalAlign) { + case VAL_BOTTOM: + if (yyy + total_height < rect.bottom) + yyy = rect.bottom - total_height; + break; + + case VAL_CENTER: + if (yyy + total_height < rect.bottom) + yyy += ((rect.bottom - rect.top) - total_height) / 2; + break; + + case VAL_TOP: + // do nothing + break; + } + } + + // prepare response buttons + bool scrollNeeded = false; + for (i = _scrollOffset; i < _respButtons.getSize(); i++) { + if ((_horizontal && xxx + _respButtons[i]->_width > rect.right) + || (!_horizontal && yyy + _respButtons[i]->_height > rect.bottom)) { + + scrollNeeded = true; + _respButtons[i]->_visible = false; + break; + } + + _respButtons[i]->_visible = true; + _respButtons[i]->_posX = xxx; + _respButtons[i]->_posY = yyy; + + if (_horizontal) { + xxx += (_respButtons[i]->_width + _spacing); + } else { + yyy += (_respButtons[i]->_height + _spacing); + } + } + + // show appropriate scroll buttons + if (_window) { + _window->showWidget("prev", _scrollOffset > 0); + _window->showWidget("next", scrollNeeded); + } + + // go exclusive + if (_shieldWindow) { + _shieldWindow->_posX = _shieldWindow->_posY = 0; + _shieldWindow->_width = _gameRef->_renderer->_width; + _shieldWindow->_height = _gameRef->_renderer->_height; + + _shieldWindow->display(); + } + + // display window + if (_window) _window->display(); + + + // display response buttons + for (i = _scrollOffset; i < _respButtons.getSize(); i++) { + _respButtons[i]->display(); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::listen(CBScriptHolder *param1, uint32 param2) { + CUIObject *obj = (CUIObject *)param1; + + switch (obj->_type) { + case UI_BUTTON: + if (scumm_stricmp(obj->_name, "prev") == 0) { + _scrollOffset--; + } else if (scumm_stricmp(obj->_name, "next") == 0) { + _scrollOffset++; + } else if (scumm_stricmp(obj->_name, "response") == 0) { + if (_waitingScript) _waitingScript->_stack->pushInt(_responses[param2]->_iD); + handleResponse(_responses[param2]); + _waitingScript = NULL; + _gameRef->_state = GAME_RUNNING; + ((CAdGame *)_gameRef)->_stateEx = GAME_NORMAL; + _ready = true; + invalidateButtons(); + clearResponses(); + } else return CBObject::listen(param1, param2); + break; + default: + error("AdResponseBox::Listen - Unhandled enum"); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::persist(CBPersistMgr *persistMgr) { + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_fontHover)); + persistMgr->transfer(TMEMBER(_horizontal)); + persistMgr->transfer(TMEMBER(_lastResponseText)); + persistMgr->transfer(TMEMBER(_lastResponseTextOrig)); + _respButtons.persist(persistMgr); + persistMgr->transfer(TMEMBER(_responseArea)); + _responses.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollOffset)); + persistMgr->transfer(TMEMBER(_shieldWindow)); + persistMgr->transfer(TMEMBER(_spacing)); + persistMgr->transfer(TMEMBER(_waitingScript)); + persistMgr->transfer(TMEMBER(_window)); + + persistMgr->transfer(TMEMBER_INT(_verticalAlign)); + persistMgr->transfer(TMEMBER_INT(_align)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::weedResponses() { + CAdGame *adGame = (CAdGame *)_gameRef; + + for (int i = 0; i < _responses.getSize(); i++) { + switch (_responses[i]->_responseType) { + case RESPONSE_ONCE: + if (adGame->branchResponseUsed(_responses[i]->_iD)) { + delete _responses[i]; + _responses.removeAt(i); + i--; + } + break; + + case RESPONSE_ONCE_GAME: + if (adGame->gameResponseUsed(_responses[i]->_iD)) { + delete _responses[i]; + _responses.removeAt(i); + i--; + } + break; + default: + warning("CAdResponseBox::WeedResponses - Unhandled enum"); + break; + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdResponseBox::setLastResponseText(const char *text, const char *textOrig) { + CBUtils::setString(&_lastResponseText, text); + CBUtils::setString(&_lastResponseTextOrig, textOrig); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::handleResponse(CAdResponse *response) { + setLastResponseText(response->_text, response->_textOrig); + + CAdGame *adGame = (CAdGame *)_gameRef; + + switch (response->_responseType) { + case RESPONSE_ONCE: + adGame->addBranchResponse(response->_iD); + break; + + case RESPONSE_ONCE_GAME: + adGame->addGameResponse(response->_iD); + break; + default: + warning("CAdResponseBox::HandleResponse - Unhandled enum"); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdResponseBox::getNextAccessObject(CBObject *currObject) { + CBArray objects; + getObjects(objects, true); + + if (objects.getSize() == 0) return NULL; + else { + if (currObject != NULL) { + for (int i = 0; i < objects.getSize(); i++) { + if (objects[i] == currObject) { + if (i < objects.getSize() - 1) return objects[i + 1]; + else break; + } + } + } + return objects[0]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdResponseBox::getPrevAccessObject(CBObject *currObject) { + CBArray objects; + getObjects(objects, true); + + if (objects.getSize() == 0) return NULL; + else { + if (currObject != NULL) { + for (int i = objects.getSize() - 1; i >= 0; i--) { + if (objects[i] == currObject) { + if (i > 0) return objects[i - 1]; + else break; + } + } + } + return objects[objects.getSize() - 1]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::getObjects(CBArray &objects, bool interactiveOnly) { + for (int i = 0; i < _respButtons.getSize(); i++) { + objects.add(_respButtons[i]); + } + if (_window) _window->getWindowObjects(objects, interactiveOnly); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdResponseBox.h b/engines/wintermute/ad/AdResponseBox.h new file mode 100644 index 0000000000..93b677bd4a --- /dev/null +++ b/engines/wintermute/ad/AdResponseBox.h @@ -0,0 +1,87 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSEBOX_H +#define WINTERMUTE_ADRESPONSEBOX_H + + +#include "engines/wintermute/base/BObject.h" + +namespace WinterMute { + +class CUIButton; +class CUIWindow; +class CUIObject; +class CAdResponse; +class CAdResponseBox : public CBObject { +public: + CBObject *getNextAccessObject(CBObject *CurrObject); + CBObject *getPrevAccessObject(CBObject *CurrObject); + bool getObjects(CBArray &objects, bool interactiveOnly); + + bool handleResponse(CAdResponse *response); + void setLastResponseText(const char *text, const char *textOrig); + char *_lastResponseText; + char *_lastResponseTextOrig; + DECLARE_PERSISTENT(CAdResponseBox, CBObject) + CScScript *_waitingScript; + virtual bool listen(CBScriptHolder *param1, uint32 param2); + typedef enum { + EVENT_PREV, + EVENT_NEXT, + EVENT_RESPONSE + } TResponseEvent; + + bool weedResponses(); + bool display(); + int _spacing; + int _scrollOffset; + CBFont *_fontHover; + CBFont *_font; + bool createButtons(); + bool invalidateButtons(); + void clearButtons(); + void clearResponses(); + CAdResponseBox(CBGame *inGame); + virtual ~CAdResponseBox(); + CBArray _responses; + CBArray _respButtons; + CUIWindow *_window; + CUIWindow *_shieldWindow; + bool _horizontal; + Rect32 _responseArea; + int _verticalAlign; + TTextAlign _align; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdResponseContext.cpp b/engines/wintermute/ad/AdResponseContext.cpp new file mode 100644 index 0000000000..8573e58b95 --- /dev/null +++ b/engines/wintermute/ad/AdResponseContext.cpp @@ -0,0 +1,70 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdResponseContext.h" +#include "engines/wintermute/base/BPersistMgr.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdResponseContext, false) + +////////////////////////////////////////////////////////////////////////// +CAdResponseContext::CAdResponseContext(CBGame *inGame): CBBase(inGame) { + _iD = 0; + _context = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdResponseContext::~CAdResponseContext() { + delete[] _context; + _context = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseContext::persist(CBPersistMgr *persistMgr) { + persistMgr->transfer(TMEMBER(_gameRef)); + persistMgr->transfer(TMEMBER(_context)); + persistMgr->transfer(TMEMBER(_iD)); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +void CAdResponseContext::setContext(const char *context) { + delete[] _context; + _context = NULL; + if (context) { + _context = new char [strlen(context) + 1]; + if (_context) strcpy(_context, context); + } +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdResponseContext.h b/engines/wintermute/ad/AdResponseContext.h new file mode 100644 index 0000000000..74506405de --- /dev/null +++ b/engines/wintermute/ad/AdResponseContext.h @@ -0,0 +1,50 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSECONTEXT_H +#define WINTERMUTE_ADRESPONSECONTEXT_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/BBase.h" + +namespace WinterMute { + +class CAdResponseContext : public CBBase { +public: + void setContext(const char *context); + int _iD; + char *_context; + DECLARE_PERSISTENT(CAdResponseContext, CBBase) + CAdResponseContext(CBGame *inGame); + virtual ~CAdResponseContext(); + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdRotLevel.cpp b/engines/wintermute/ad/AdRotLevel.cpp new file mode 100644 index 0000000000..671d003f35 --- /dev/null +++ b/engines/wintermute/ad/AdRotLevel.cpp @@ -0,0 +1,159 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdRotLevel.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/base/BFileManager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdRotLevel, false) + + +////////////////////////////////////////////////////////////////////////// +CAdRotLevel::CAdRotLevel(CBGame *inGame): CBObject(inGame) { + _posX = 0; + _rotation = 0.0f; +} + + +////////////////////////////////////////////////////////////////////////// +CAdRotLevel::~CAdRotLevel() { + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRotLevel::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdRotLevel::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ROTATION_LEVEL) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(X) +TOKEN_DEF(ROTATION) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdRotLevel::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ROTATION_LEVEL) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(X) + TOKEN_TABLE(ROTATION) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ROTATION_LEVEL) { + _gameRef->LOG(0, "'ROTATION_LEVEL' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_ROTATION: { + int i; + parser.scanStr((char *)params, "%d", &i); + _rotation = (float)i; + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ROTATION_LEVEL definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRotLevel::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ROTATION_LEVEL {\n"); + buffer->putTextIndent(indent + 2, "X=%d\n", _posX); + buffer->putTextIndent(indent + 2, "ROTATION=%d\n", (int)_rotation); + CBBase::saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRotLevel::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_rotation)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdRotLevel.h b/engines/wintermute/ad/AdRotLevel.h new file mode 100644 index 0000000000..9e536a8d8f --- /dev/null +++ b/engines/wintermute/ad/AdRotLevel.h @@ -0,0 +1,49 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADROTLEVEL_H +#define WINTERMUTE_ADROTLEVEL_H + +#include "engines/wintermute/base/BObject.h" + +namespace WinterMute { + +class CAdRotLevel : public CBObject { +public: + DECLARE_PERSISTENT(CAdRotLevel, CBObject) + CAdRotLevel(CBGame *inGame); + virtual ~CAdRotLevel(); + float _rotation; + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdScaleLevel.cpp b/engines/wintermute/ad/AdScaleLevel.cpp new file mode 100644 index 0000000000..1ac2f7ba6c --- /dev/null +++ b/engines/wintermute/ad/AdScaleLevel.cpp @@ -0,0 +1,157 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdScaleLevel.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BFileManager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdScaleLevel, false) + +////////////////////////////////////////////////////////////////////////// +CAdScaleLevel::CAdScaleLevel(CBGame *inGame): CBObject(inGame) { + _posY = 0; + _scale = 100; +} + + +////////////////////////////////////////////////////////////////////////// +CAdScaleLevel::~CAdScaleLevel() { + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScaleLevel::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdScaleLevel::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SCALE_LEVEL) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(Y) +TOKEN_DEF(SCALE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdScaleLevel::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SCALE_LEVEL) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(Y) + TOKEN_TABLE(SCALE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCALE_LEVEL) { + _gameRef->LOG(0, "'SCALE_LEVEL' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_SCALE: { + int i; + parser.scanStr((char *)params, "%d", &i); + _scale = (float)i; + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SCALE_LEVEL definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScaleLevel::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "SCALE_LEVEL {\n"); + buffer->putTextIndent(indent + 2, "Y=%d\n", _posY); + buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_scale); + CBBase::saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScaleLevel::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_scale)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdScaleLevel.h b/engines/wintermute/ad/AdScaleLevel.h new file mode 100644 index 0000000000..c360ec4eff --- /dev/null +++ b/engines/wintermute/ad/AdScaleLevel.h @@ -0,0 +1,50 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCALELEVEL_H +#define WINTERMUTE_ADSCALELEVEL_H + + +#include "engines/wintermute/base/BObject.h" + +namespace WinterMute { + +class CAdScaleLevel : public CBObject { +public: + DECLARE_PERSISTENT(CAdScaleLevel, CBObject) + float _scale; + CAdScaleLevel(CBGame *inGame); + virtual ~CAdScaleLevel(); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdScene.cpp b/engines/wintermute/ad/AdScene.cpp new file mode 100644 index 0000000000..022ec4a8a5 --- /dev/null +++ b/engines/wintermute/ad/AdScene.cpp @@ -0,0 +1,2752 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/AdScene.h" +#include "engines/wintermute/ad/AdActor.h" +#include "engines/wintermute/ad/AdEntity.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/ad/AdLayer.h" +#include "engines/wintermute/ad/AdNodeState.h" +#include "engines/wintermute/ad/AdObject.h" +#include "engines/wintermute/ad/AdPath.h" +#include "engines/wintermute/ad/AdPathPoint.h" +#include "engines/wintermute/ad/AdRotLevel.h" +#include "engines/wintermute/ad/AdScaleLevel.h" +#include "engines/wintermute/ad/AdSceneNode.h" +#include "engines/wintermute/ad/AdSceneState.h" +#include "engines/wintermute/ad/AdSentence.h" +#include "engines/wintermute/ad/AdWaypointGroup.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/base/font/BFont.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BObject.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BPoint.h" +#include "engines/wintermute/base/BRegion.h" +#include "engines/wintermute/base/BScriptable.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/base/BViewport.h" +#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/ui/UIWindow.h" +#include "engines/wintermute/utils/utils.h" +#include + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdScene, false) + +////////////////////////////////////////////////////////////////////////// +CAdScene::CAdScene(CBGame *inGame): CBObject(inGame) { + _pfTarget = new CBPoint; + setDefaults(); +} + + +////////////////////////////////////////////////////////////////////////// +CAdScene::~CAdScene() { + cleanup(); + _gameRef->unregisterObject(_fader); + delete _pfTarget; + _pfTarget = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::setDefaults() { + _initialized = false; + _pfReady = true; + _pfTargetPath = NULL; + _pfRequester = NULL; + _mainLayer = NULL; + + _pfPointsNum = 0; + _persistentState = false; + _persistentStateSprites = true; + + _autoScroll = true; + _offsetLeft = _offsetTop = 0; + _targetOffsetLeft = _targetOffsetTop = 0; + + _lastTimeH = _lastTimeV = 0; + _scrollTimeH = _scrollTimeV = 10; + _scrollPixelsH = _scrollPixelsV = 1; + + _pfMaxTime = 15; + + _paralaxScrolling = true; + + // editor settings + _editorMarginH = _editorMarginV = 100; + + _editorColFrame = 0xE0888888; + _editorColEntity = 0xFF008000; + _editorColRegion = 0xFF0000FF; + _editorColBlocked = 0xFF800080; + _editorColWaypoints = 0xFF0000FF; + _editorColEntitySel = 0xFFFF0000; + _editorColRegionSel = 0xFFFF0000; + _editorColBlockedSel = 0xFFFF0000; + _editorColWaypointsSel = 0xFFFF0000; + _editorColScale = 0xFF00FF00; + _editorColDecor = 0xFF00FFFF; + _editorColDecorSel = 0xFFFF0000; + + _editorShowRegions = true; + _editorShowBlocked = true; + _editorShowDecor = true; + _editorShowEntities = true; + _editorShowScale = true; + + _shieldWindow = NULL; + + _fader = new CBFader(_gameRef); + _gameRef->registerObject(_fader); + + _viewport = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::cleanup() { + CBObject::cleanup(); + + _mainLayer = NULL; // reference only + + int i; + + delete _shieldWindow; + _shieldWindow = NULL; + + _gameRef->unregisterObject(_fader); + _fader = NULL; + + for (i = 0; i < _layers.getSize(); i++) + _gameRef->unregisterObject(_layers[i]); + _layers.removeAll(); + + + for (i = 0; i < _waypointGroups.getSize(); i++) + _gameRef->unregisterObject(_waypointGroups[i]); + _waypointGroups.removeAll(); + + for (i = 0; i < _scaleLevels.getSize(); i++) + _gameRef->unregisterObject(_scaleLevels[i]); + _scaleLevels.removeAll(); + + for (i = 0; i < _rotLevels.getSize(); i++) + _gameRef->unregisterObject(_rotLevels[i]); + _rotLevels.removeAll(); + + + for (i = 0; i < _pfPath.getSize(); i++) + delete _pfPath[i]; + _pfPath.removeAll(); + _pfPointsNum = 0; + + for (i = 0; i < _objects.getSize(); i++) + _gameRef->unregisterObject(_objects[i]); + _objects.removeAll(); + + delete _viewport; + _viewport = NULL; + + setDefaults(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject *requester) { + if (!_pfReady) return false; + else { + _pfReady = false; + *_pfTarget = target; + _pfTargetPath = path; + _pfRequester = requester; + + _pfTargetPath->reset(); + _pfTargetPath->setReady(false); + + // prepare working path + int i; + pfPointsStart(); + + // first point + //_pfPath.add(new CAdPathPoint(source.x, source.y, 0)); + + // if we're one pixel stuck, get unstuck + int startX = source.x; + int startY = source.y; + int bestDistance = 1000; + if (isBlockedAt(startX, startY, true, requester)) { + int tolerance = 2; + for (int xxx = startX - tolerance; xxx <= startX + tolerance; xxx++) { + for (int yyy = startY - tolerance; yyy <= startY + tolerance; yyy++) { + if (isWalkableAt(xxx, yyy, true, requester)) { + int distance = abs(xxx - source.x) + abs(yyy - source.y); + if (distance < bestDistance) { + startX = xxx; + startY = yyy; + + bestDistance = distance; + } + } + } + } + } + + pfPointsAdd(startX, startY, 0); + + //CorrectTargetPoint(&target.x, &target.y); + + // last point + //_pfPath.add(new CAdPathPoint(target.x, target.y, INT_MAX)); + pfPointsAdd(target.x, target.y, INT_MAX); + + // active waypoints + for (i = 0; i < _waypointGroups.getSize(); i++) { + if (_waypointGroups[i]->_active) { + pfAddWaypointGroup(_waypointGroups[i], requester); + } + } + + + // free waypoints + for (i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentWptGroup) { + pfAddWaypointGroup(_objects[i]->_currentWptGroup, requester); + } + } + CAdGame *adGame = (CAdGame *)_gameRef; + for (i = 0; i < adGame->_objects.getSize(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentWptGroup) { + pfAddWaypointGroup(adGame->_objects[i]->_currentWptGroup, requester); + } + } + + return true; + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::pfAddWaypointGroup(CAdWaypointGroup *wpt, CBObject *requester) { + if (!wpt->_active) return; + + for (int i = 0; i < wpt->_points.getSize(); i++) { + if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) continue; + + //_pfPath.add(new CAdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); + pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX); + } +} + + +////////////////////////////////////////////////////////////////////////// +float CAdScene::getZoomAt(int x, int y) { + float ret = 100; + + bool found = false; + if (_mainLayer) { + for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_blocked && node->_region->pointInRegion(x, y)) { + if (node->_region->_zoom != 0) { + ret = node->_region->_zoom; + found = true; + break; + } + } + } + } + if (!found) ret = getScaleAt(y); + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +uint32 CAdScene::getAlphaAt(int x, int y, bool colorCheck) { + if (!_gameRef->_debugDebugMode) colorCheck = false; + + uint32 ret; + if (colorCheck) ret = 0xFFFF0000; + else ret = 0xFFFFFFFF; + + if (_mainLayer) { + for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { + if (!node->_region->_blocked) ret = node->_region->_alpha; + break; + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::isBlockedAt(int x, int y, bool checkFreeObjects, CBObject *requester) { + bool ret = true; + + + if (checkFreeObjects) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; + } + } + CAdGame *adGame = (CAdGame *)_gameRef; + for (int i = 0; i < adGame->_objects.getSize(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; + } + } + } + + + if (_mainLayer) { + for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + /* + if (Node->_type == OBJECT_REGION && Node->_region->_active && Node->_region->_blocked && Node->_region->PointInRegion(X, Y)) + { + ret = true; + break; + } + */ + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { + if (node->_region->_blocked) { + ret = true; + break; + } else ret = false; + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::isWalkableAt(int x, int y, bool checkFreeObjects, CBObject *requester) { + bool ret = false; + + if (checkFreeObjects) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; + } + } + CAdGame *adGame = (CAdGame *)_gameRef; + for (int i = 0; i < adGame->_objects.getSize(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; + } + } + } + + + if (_mainLayer) { + for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { + if (node->_region->_blocked) { + ret = false; + break; + } else ret = true; + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdScene::getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester) { + double xStep, yStep, x, y; + int xLength, yLength, xCount, yCount; + int x1, y1, x2, y2; + + x1 = p1.x; + y1 = p1.y; + x2 = p2.x; + y2 = p2.y; + + xLength = abs(x2 - x1); + yLength = abs(y2 - y1); + + if (xLength > yLength) { + if (x1 > x2) { + CBUtils::swap(&x1, &x2); + CBUtils::swap(&y1, &y2); + } + + yStep = (double)(y2 - y1) / (double)(x2 - x1); + y = y1; + + for (xCount = x1; xCount < x2; xCount++) { + if (isBlockedAt(xCount, (int)y, true, requester)) return -1; + y += yStep; + } + } else { + if (y1 > y2) { + CBUtils::swap(&x1, &x2); + CBUtils::swap(&y1, &y2); + } + + xStep = (double)(x2 - x1) / (double)(y2 - y1); + x = x1; + + for (yCount = y1; yCount < y2; yCount++) { + if (isBlockedAt((int)x, yCount, true, requester)) return -1; + x += xStep; + } + } + return MAX(xLength, yLength); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::pathFinderStep() { + int i; + // get lowest unmarked + int lowestDist = INT_MAX; + CAdPathPoint *lowestPt = NULL; + + for (i = 0; i < _pfPointsNum; i++) + if (!_pfPath[i]->_marked && _pfPath[i]->_distance < lowestDist) { + lowestDist = _pfPath[i]->_distance; + lowestPt = _pfPath[i]; + } + + if (lowestPt == NULL) { // no path -> terminate PathFinder + _pfReady = true; + _pfTargetPath->setReady(true); + return; + } + + lowestPt->_marked = true; + + // target point marked, generate path and terminate + if (lowestPt->x == _pfTarget->x && lowestPt->y == _pfTarget->y) { + while (lowestPt != NULL) { + _pfTargetPath->_points.insertAt(0, new CBPoint(lowestPt->x, lowestPt->y)); + lowestPt = lowestPt->_origin; + } + + _pfReady = true; + _pfTargetPath->setReady(true); + return; + } + + // otherwise keep on searching + for (i = 0; i < _pfPointsNum; i++) + if (!_pfPath[i]->_marked) { + int j = getPointsDist(*lowestPt, *_pfPath[i], _pfRequester); + if (j != -1 && lowestPt->_distance + j < _pfPath[i]->_distance) { + _pfPath[i]->_distance = lowestPt->_distance + j; + _pfPath[i]->_origin = lowestPt; + } + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::initLoop() { +#ifdef _DEBUGxxxx + int nu_steps = 0; + uint32 start = _gameRef->_currentTime; + while (!_pfReady && CBPlatform::getTime() - start <= _pfMaxTime) { + PathFinderStep(); + nu_steps++; + } + if (nu_steps > 0) _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); +#else + uint32 start = _gameRef->_currentTime; + while (!_pfReady && CBPlatform::getTime() - start <= _pfMaxTime) pathFinderStep(); +#endif + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdScene::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + delete[] _filename; + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SCENE) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(LAYER) +TOKEN_DEF(WAYPOINTS) +TOKEN_DEF(EVENTS) +TOKEN_DEF(CURSOR) +TOKEN_DEF(CAMERA) +TOKEN_DEF(ENTITY) +TOKEN_DEF(SCALE_LEVEL) +TOKEN_DEF(ROTATION_LEVEL) +TOKEN_DEF(EDITOR_MARGIN_H) +TOKEN_DEF(EDITOR_MARGIN_V) +TOKEN_DEF(EDITOR_COLOR_FRAME) +TOKEN_DEF(EDITOR_COLOR_ENTITY_SEL) +TOKEN_DEF(EDITOR_COLOR_REGION_SEL) +TOKEN_DEF(EDITOR_COLOR_DECORATION_SEL) +TOKEN_DEF(EDITOR_COLOR_BLOCKED_SEL) +TOKEN_DEF(EDITOR_COLOR_WAYPOINTS_SEL) +TOKEN_DEF(EDITOR_COLOR_REGION) +TOKEN_DEF(EDITOR_COLOR_DECORATION) +TOKEN_DEF(EDITOR_COLOR_BLOCKED) +TOKEN_DEF(EDITOR_COLOR_ENTITY) +TOKEN_DEF(EDITOR_COLOR_WAYPOINTS) +TOKEN_DEF(EDITOR_COLOR_SCALE) +TOKEN_DEF(EDITOR_SHOW_REGIONS) +TOKEN_DEF(EDITOR_SHOW_BLOCKED) +TOKEN_DEF(EDITOR_SHOW_DECORATION) +TOKEN_DEF(EDITOR_SHOW_ENTITIES) +TOKEN_DEF(EDITOR_SHOW_SCALE) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(VIEWPORT) +TOKEN_DEF(PERSISTENT_STATE_SPRITES) +TOKEN_DEF(PERSISTENT_STATE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdScene::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SCENE) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(LAYER) + TOKEN_TABLE(WAYPOINTS) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(CAMERA) + TOKEN_TABLE(ENTITY) + TOKEN_TABLE(SCALE_LEVEL) + TOKEN_TABLE(ROTATION_LEVEL) + TOKEN_TABLE(EDITOR_MARGIN_H) + TOKEN_TABLE(EDITOR_MARGIN_V) + TOKEN_TABLE(EDITOR_COLOR_FRAME) + TOKEN_TABLE(EDITOR_COLOR_ENTITY_SEL) + TOKEN_TABLE(EDITOR_COLOR_REGION_SEL) + TOKEN_TABLE(EDITOR_COLOR_DECORATION_SEL) + TOKEN_TABLE(EDITOR_COLOR_BLOCKED_SEL) + TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS_SEL) + TOKEN_TABLE(EDITOR_COLOR_REGION) + TOKEN_TABLE(EDITOR_COLOR_DECORATION) + TOKEN_TABLE(EDITOR_COLOR_BLOCKED) + TOKEN_TABLE(EDITOR_COLOR_ENTITY) + TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS) + TOKEN_TABLE(EDITOR_COLOR_SCALE) + TOKEN_TABLE(EDITOR_SHOW_REGIONS) + TOKEN_TABLE(EDITOR_SHOW_DECORATION) + TOKEN_TABLE(EDITOR_SHOW_BLOCKED) + TOKEN_TABLE(EDITOR_SHOW_ENTITIES) + TOKEN_TABLE(EDITOR_SHOW_SCALE) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(VIEWPORT) + TOKEN_TABLE(PERSISTENT_STATE_SPRITES) + TOKEN_TABLE(PERSISTENT_STATE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + cleanup(); + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCENE) { + _gameRef->LOG(0, "'SCENE' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + int ar, ag, ab, aa; + char camera[MAX_PATH_LENGTH] = ""; + /* float WaypointHeight = -1.0f; */ + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_LAYER: { + CAdLayer *layer = new CAdLayer(_gameRef); + if (!layer || DID_FAIL(layer->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete layer; + layer = NULL; + } else { + _gameRef->registerObject(layer); + _layers.add(layer); + if (layer->_main) { + _mainLayer = layer; + _width = layer->_width; + _height = layer->_height; + } + } + } + break; + + case TOKEN_WAYPOINTS: { + CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); + if (!wpt || DID_FAIL(wpt->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete wpt; + wpt = NULL; + } else { + _gameRef->registerObject(wpt); + _waypointGroups.add(wpt); + } + } + break; + + case TOKEN_SCALE_LEVEL: { + CAdScaleLevel *sl = new CAdScaleLevel(_gameRef); + if (!sl || DID_FAIL(sl->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete sl; + sl = NULL; + } else { + _gameRef->registerObject(sl); + _scaleLevels.add(sl); + } + } + break; + + case TOKEN_ROTATION_LEVEL: { + CAdRotLevel *rl = new CAdRotLevel(_gameRef); + if (!rl || DID_FAIL(rl->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete rl; + rl = NULL; + } else { + _gameRef->registerObject(rl); + _rotLevels.add(rl); + } + } + break; + + case TOKEN_ENTITY: { + CAdEntity *entity = new CAdEntity(_gameRef); + if (!entity || DID_FAIL(entity->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete entity; + entity = NULL; + } else { + addObject(entity); + } + } + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new CBSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CAMERA: + strcpy(camera, (char *)params); + break; + + case TOKEN_EDITOR_MARGIN_H: + parser.scanStr((char *)params, "%d", &_editorMarginH); + break; + + case TOKEN_EDITOR_MARGIN_V: + parser.scanStr((char *)params, "%d", &_editorMarginV); + break; + + case TOKEN_EDITOR_COLOR_FRAME: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColFrame = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_ENTITY: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColEntity = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_ENTITY_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColEntitySel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_REGION_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColRegionSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_DECORATION_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColDecorSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_BLOCKED_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColBlockedSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_WAYPOINTS_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColWaypointsSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_REGION: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColRegion = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_DECORATION: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColDecor = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_BLOCKED: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColBlocked = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_WAYPOINTS: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColWaypoints = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_SCALE: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColScale = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_SHOW_REGIONS: + parser.scanStr((char *)params, "%b", &_editorShowRegions); + break; + + case TOKEN_EDITOR_SHOW_BLOCKED: + parser.scanStr((char *)params, "%b", &_editorShowBlocked); + break; + + case TOKEN_EDITOR_SHOW_DECORATION: + parser.scanStr((char *)params, "%b", &_editorShowDecor); + break; + + case TOKEN_EDITOR_SHOW_ENTITIES: + parser.scanStr((char *)params, "%b", &_editorShowEntities); + break; + + case TOKEN_EDITOR_SHOW_SCALE: + parser.scanStr((char *)params, "%b", &_editorShowScale); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_VIEWPORT: { + Rect32 rc; + parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); + if (!_viewport) _viewport = new CBViewport(_gameRef); + if (_viewport) _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); + } + + case TOKEN_PERSISTENT_STATE: + parser.scanStr((char *)params, "%b", &_persistentState); + break; + + case TOKEN_PERSISTENT_STATE_SPRITES: + parser.scanStr((char *)params, "%b", &_persistentStateSprites); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SCENE definition"); + return STATUS_FAILED; + } + + if (_mainLayer == NULL) _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", _filename); + + + sortScaleLevels(); + sortRotLevels(); + + _initialized = true; + + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::traverseNodes(bool doUpdate) { + if (!_initialized) return STATUS_OK; + + int j, k; + CAdGame *adGame = (CAdGame *)_gameRef; + + + ////////////////////////////////////////////////////////////////////////// + // prepare viewport + bool PopViewport = false; + if (_viewport && !_gameRef->_editorMode) { + _gameRef->pushViewport(_viewport); + PopViewport = true; + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + _gameRef->pushViewport(adGame->_sceneViewport); + PopViewport = true; + } + + + ////////////////////////////////////////////////////////////////////////// + // *** adjust scroll offset + if (doUpdate) { + /* + if (_autoScroll && _gameRef->_mainObject != NULL) + { + ScrollToObject(_gameRef->_mainObject); + } + */ + + if (_autoScroll) { + // adjust horizontal scroll + if (_gameRef->_timer - _lastTimeH >= _scrollTimeH) { + _lastTimeH = _gameRef->_timer; + if (_offsetLeft < _targetOffsetLeft) { + _offsetLeft += _scrollPixelsH; + _offsetLeft = MIN(_offsetLeft, _targetOffsetLeft); + } else if (_offsetLeft > _targetOffsetLeft) { + _offsetLeft -= _scrollPixelsH; + _offsetLeft = MAX(_offsetLeft, _targetOffsetLeft); + } + } + + // adjust vertical scroll + if (_gameRef->_timer - _lastTimeV >= _scrollTimeV) { + _lastTimeV = _gameRef->_timer; + if (_offsetTop < _targetOffsetTop) { + _offsetTop += _scrollPixelsV; + _offsetTop = MIN(_offsetTop, _targetOffsetTop); + } else if (_offsetTop > _targetOffsetTop) { + _offsetTop -= _scrollPixelsV; + _offsetTop = MAX(_offsetTop, _targetOffsetTop); + } + } + + if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) _ready = true; + } else _ready = true; // not scrolling, i.e. always ready + } + + + + + ////////////////////////////////////////////////////////////////////////// + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + int viewportX, viewportY; + getViewportOffset(&viewportX, &viewportY); + + int scrollableX = _width - viewportWidth; + int scrollableY = _height - viewportHeight; + + double widthRatio = scrollableX <= 0 ? 0 : ((double)(_offsetLeft) / (double)scrollableX); + double heightRatio = scrollableY <= 0 ? 0 : ((double)(_offsetTop) / (double)scrollableY); + + int origX, origY; + _gameRef->getOffset(&origX, &origY); + + + + ////////////////////////////////////////////////////////////////////////// + // *** display/update everything + _gameRef->_renderer->setup2D(); + + // for each layer + /* int MainOffsetX = 0; */ + /* int MainOffsetY = 0; */ + + for (j = 0; j < _layers.getSize(); j++) { + if (!_layers[j]->_active) continue; + + // make layer exclusive + if (!doUpdate) { + if (_layers[j]->_closeUp && !_gameRef->_editorMode) { + if (!_shieldWindow) _shieldWindow = new CUIWindow(_gameRef); + if (_shieldWindow) { + _shieldWindow->_posX = _shieldWindow->_posY = 0; + _shieldWindow->_width = _gameRef->_renderer->_width; + _shieldWindow->_height = _gameRef->_renderer->_height; + _shieldWindow->display(); + } + } + } + + if (_paralaxScrolling) { + int offsetX = (int)(widthRatio * (_layers[j]->_width - viewportWidth) - viewportX); + int offsetY = (int)(heightRatio * (_layers[j]->_height - viewportHeight) - viewportY); + _gameRef->setOffset(offsetX, offsetY); + + _gameRef->_offsetPercentX = (float)offsetX / ((float)_layers[j]->_width - viewportWidth) * 100.0f; + _gameRef->_offsetPercentY = (float)offsetY / ((float)_layers[j]->_height - viewportHeight) * 100.0f; + + //_gameRef->QuickMessageForm("%d %f", OffsetX+ViewportX, _gameRef->_offsetPercentX); + } else { + _gameRef->setOffset(_offsetLeft - viewportX, _offsetTop - viewportY); + + _gameRef->_offsetPercentX = (float)(_offsetLeft - viewportX) / ((float)_layers[j]->_width - viewportWidth) * 100.0f; + _gameRef->_offsetPercentY = (float)(_offsetTop - viewportY) / ((float)_layers[j]->_height - viewportHeight) * 100.0f; + } + + + // for each node + for (k = 0; k < _layers[j]->_nodes.getSize(); k++) { + CAdSceneNode *node = _layers[j]->_nodes[k]; + switch (node->_type) { + case OBJECT_ENTITY: + if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) { + _gameRef->_renderer->setup2D(); + + if (doUpdate) node->_entity->update(); + else node->_entity->display(); + } + break; + + case OBJECT_REGION: { + if (node->_region->_blocked) break; + if (node->_region->_decoration) break; + + if (!doUpdate) displayRegionContent(node->_region); + } + break; + default: + error("AdScene::TraverseNodes - Unhandled enum"); + break; + } // switch + } // each node + + // display/update all objects which are off-regions + if (_layers[j]->_main) { + if (doUpdate) { + updateFreeObjects(); + } else { + displayRegionContent(NULL); + } + } + } // each layer + + + // restore state + _gameRef->setOffset(origX, origY); + _gameRef->_renderer->setup2D(); + + // display/update fader + if (_fader) { + if (doUpdate) _fader->update(); + else _fader->display(); + } + + if (PopViewport) _gameRef->popViewport(); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::display() { + return traverseNodes(false); +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::updateFreeObjects() { + CAdGame *adGame = (CAdGame *)_gameRef; + bool is3DSet; + + // *** update all active objects + is3DSet = false; + for (int i = 0; i < adGame->_objects.getSize(); i++) { + if (!adGame->_objects[i]->_active) continue; + + adGame->_objects[i]->update(); + adGame->_objects[i]->_drawn = false; + } + + + for (int i = 0; i < _objects.getSize(); i++) { + if (!_objects[i]->_active) continue; + + _objects[i]->update(); + _objects[i]->_drawn = false; + } + + + if (_autoScroll && _gameRef->_mainObject != NULL) { + scrollToObject(_gameRef->_mainObject); + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::displayRegionContent(CAdRegion *region, bool display3DOnly) { + CAdGame *adGame = (CAdGame *)_gameRef; + CBArray objects; + CAdObject *obj; + + // global objects + for (int i = 0; i < adGame->_objects.getSize(); i++) { + obj = adGame->_objects[i]; + if (obj->_active && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + objects.add(obj); + } + } + + // scene objects + for (int i = 0; i < _objects.getSize(); i++) { + obj = _objects[i]; + if (obj->_active && !obj->_editorOnly && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + objects.add(obj); + } + } + + // sort by _posY + qsort(objects.getData(), objects.getSize(), sizeof(CAdObject *), CAdScene::compareObjs); + + // display them + for (int i = 0; i < objects.getSize(); i++) { + obj = objects[i]; + + if (display3DOnly && !obj->_is3D) continue; + + _gameRef->_renderer->setup2D(); + + if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); + obj->_drawn = true; + } + + + // display design only objects + if (!display3DOnly) { + if (_gameRef->_editorMode && region == NULL) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i]->_editorOnly) { + _objects[i]->display(); + _objects[i]->_drawn = true; + } + } + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +int CAdScene::compareObjs(const void *obj1, const void *obj2) { + CAdObject *object1 = *(CAdObject **)obj1; + CAdObject *object2 = *(CAdObject **)obj2; + + if (object1->_posY < object2->_posY) return -1; + else if (object1->_posY > object2->_posY) return 1; + else return 0; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::displayRegionContentOld(CAdRegion *region) { + CAdGame *adGame = (CAdGame *)_gameRef; + CAdObject *obj; + + // display all objects in region sorted by _posY + do { + obj = NULL; + int minY = INT_MAX; + + // global objects + for (int i = 0; i < adGame->_objects.getSize(); i++) { + if (adGame->_objects[i]->_active && !adGame->_objects[i]->_drawn && adGame->_objects[i]->_posY < minY && (adGame->_objects[i]->_stickRegion == region || region == NULL || (adGame->_objects[i]->_stickRegion == NULL && region->pointInRegion(adGame->_objects[i]->_posX, adGame->_objects[i]->_posY)))) { + obj = adGame->_objects[i]; + minY = adGame->_objects[i]->_posY; + } + } + + // scene objects + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && !_objects[i]->_editorOnly && !_objects[i]->_drawn && _objects[i]->_posY < minY && (_objects[i]->_stickRegion == region || region == NULL || (_objects[i]->_stickRegion == NULL && region->pointInRegion(_objects[i]->_posX, _objects[i]->_posY)))) { + obj = _objects[i]; + minY = _objects[i]->_posY; + } + } + + + if (obj != NULL) { + _gameRef->_renderer->setup2D(); + + if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); + obj->_drawn = true; + } + } while (obj != NULL); + + + // design only objects + if (_gameRef->_editorMode && region == NULL) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i]->_editorOnly) { + _objects[i]->display(); + _objects[i]->_drawn = true; + } + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::update() { + return traverseNodes(true); +} + +////////////////////////////////////////////////////////////////////////// +void CAdScene::scrollTo(int offsetX, int offsetY) { + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + int origOffsetLeft = _targetOffsetLeft; + int origOffsetTop = _targetOffsetTop; + + _targetOffsetLeft = MAX(0, offsetX - viewportWidth / 2); + _targetOffsetLeft = MIN(_targetOffsetLeft, _width - viewportWidth); + + _targetOffsetTop = MAX(0, offsetY - viewportHeight / 2); + _targetOffsetTop = MIN(_targetOffsetTop, _height - viewportHeight); + + + if (_gameRef->_mainObject && _gameRef->_mainObject->_is3D) { + if (abs(origOffsetLeft - _targetOffsetLeft) < 5) _targetOffsetLeft = origOffsetLeft; + if (abs(origOffsetTop - _targetOffsetTop) < 5) _targetOffsetTop = origOffsetTop; + //_targetOffsetTop = 0; + } + + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::scrollToObject(CBObject *object) { + if (object) scrollTo(object->_posX, object->_posY - object->getHeight() / 2); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::skipToObject(CBObject *object) { + if (object) skipTo(object->_posX, object->_posY - object->getHeight() / 2); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::skipTo(int offsetX, int offsetY) { + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetLeft = MAX(0, offsetX - viewportWidth / 2); + _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); + + _offsetTop = MAX(0, offsetY - viewportHeight / 2); + _offsetTop = MIN(_offsetTop, _height - viewportHeight); + + _targetOffsetLeft = _offsetLeft; + _targetOffsetTop = _offsetTop; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // LoadActor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "LoadActor") == 0) { + stack->correctParams(1); + CAdActor *act = new CAdActor(_gameRef); + if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { + addObject(act); + stack->pushNative(act, true); + } else { + delete act; + act = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadEntity") == 0) { + stack->correctParams(1); + CAdEntity *ent = new CAdEntity(_gameRef); + if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { + addObject(ent); + stack->pushNative(ent, true); + } else { + delete ent; + ent = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdEntity *ent = new CAdEntity(_gameRef); + addObject(ent); + if (!val->isNULL()) ent->setName(val->getString()); + stack->pushNative(ent, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadObject / UnloadActor / UnloadEntity / UnloadActor3D / DeleteEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "UnloadActor3D") == 0 || strcmp(name, "DeleteEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + CAdObject *obj = (CAdObject *)val->getNative(); + removeObject(obj); + if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SkipTo + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SkipTo") == 0) { + stack->correctParams(2); + CScValue *val1 = stack->pop(); + CScValue *val2 = stack->pop(); + if (val1->isNative()) { + skipToObject((CBObject *)val1->getNative()); + } else { + skipTo(val1->getInt(), val2->getInt()); + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollTo / ScrollToAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollTo") == 0 || strcmp(name, "ScrollToAsync") == 0) { + stack->correctParams(2); + CScValue *val1 = stack->pop(); + CScValue *val2 = stack->pop(); + if (val1->isNative()) { + scrollToObject((CBObject *)val1->getNative()); + } else { + scrollTo(val1->getInt(), val2->getInt()); + } + if (strcmp(name, "ScrollTo") == 0) script->waitForExclusive(this); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetLayer") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + if (val->isInt()) { + int layer = val->getInt(); + if (layer < 0 || layer >= _layers.getSize()) stack->pushNULL(); + else stack->pushNative(_layers[layer], true); + } else { + const char *LayerName = val->getString(); + bool LayerFound = false; + for (int i = 0; i < _layers.getSize(); i++) { + if (scumm_stricmp(LayerName, _layers[i]->_name) == 0) { + stack->pushNative(_layers[i], true); + LayerFound = true; + break; + } + } + if (!LayerFound) stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetWaypointGroup + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetWaypointGroup") == 0) { + stack->correctParams(1); + int group = stack->pop()->getInt(); + if (group < 0 || group >= _waypointGroups.getSize()) stack->pushNULL(); + else stack->pushNative(_waypointGroups[group], true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNode") == 0) { + stack->correctParams(1); + const char *nodeName = stack->pop()->getString(); + + CBObject *node = getNodeByName(nodeName); + if (node) stack->pushNative((CBScriptable *)node, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFreeNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFreeNode") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdObject *ret = NULL; + if (val->isInt()) { + int index = val->getInt(); + if (index >= 0 && index < _objects.getSize()) ret = _objects[index]; + } else { + const char *nodeName = val->getString(); + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i] && _objects[i]->_name && scumm_stricmp(_objects[i]->_name, nodeName) == 0) { + ret = _objects[i]; + break; + } + } + } + if (ret) stack->pushNative(ret, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetRegionAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetRegionAt") == 0) { + stack->correctParams(3); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + CScValue *val = stack->pop(); + + bool includeDecors = false; + if (!val->isNULL()) includeDecors = val->getBool(); + + if (_mainLayer) { + for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { + if (node->_region->_decoration && !includeDecors) continue; + + stack->pushNative(node->_region, true); + return STATUS_OK; + } + } + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsBlockedAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsBlockedAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushBool(isBlockedAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsWalkableAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsWalkableAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushBool(isWalkableAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetScaleAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetScaleAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushFloat(getZoomAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetRotationAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetRotationAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushFloat(getRotationAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsScrolling + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsScrolling") == 0) { + stack->correctParams(0); + bool ret = false; + if (_autoScroll) { + if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) ret = true; + } + + stack->pushBool(ret); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // FadeOut / FadeOutAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "FadeOut") == 0 || strcmp(name, "FadeOutAsync") == 0) { + stack->correctParams(5); + uint32 duration = stack->pop()->getInt(500); + byte red = stack->pop()->getInt(0); + byte green = stack->pop()->getInt(0); + byte blue = stack->pop()->getInt(0); + byte alpha = stack->pop()->getInt(0xFF); + + _fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration); + if (strcmp(name, "FadeOutAsync") != 0) script->waitFor(_fader); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // FadeIn / FadeInAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "FadeIn") == 0 || strcmp(name, "FadeInAsync") == 0) { + stack->correctParams(5); + uint32 duration = stack->pop()->getInt(500); + byte red = stack->pop()->getInt(0); + byte green = stack->pop()->getInt(0); + byte blue = stack->pop()->getInt(0); + byte alpha = stack->pop()->getInt(0xFF); + + _fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration); + if (strcmp(name, "FadeInAsync") != 0) script->waitFor(_fader); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFadeColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFadeColor") == 0) { + stack->correctParams(0); + stack->pushInt(_fader->getCurrentColor()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsPointInViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsPointInViewport") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + stack->pushBool(pointInViewport(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetViewport") == 0) { + stack->correctParams(4); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + int width = stack->pop()->getInt(); + int height = stack->pop()->getInt(); + + if (width <= 0) width = _gameRef->_renderer->_width; + if (height <= 0) height = _gameRef->_renderer->_height; + + if (!_viewport) _viewport = new CBViewport(_gameRef); + if (_viewport) _viewport->setRect(x, y, x + width, y + height); + + stack->pushBool(true); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddLayer") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdLayer *layer = new CAdLayer(_gameRef); + if (!val->isNULL()) layer->setName(val->getString()); + if (_mainLayer) { + layer->_width = _mainLayer->_width; + layer->_height = _mainLayer->_height; + } + _layers.add(layer); + _gameRef->registerObject(layer); + + stack->pushNative(layer, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InsertLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InsertLayer") == 0) { + stack->correctParams(2); + int index = stack->pop()->getInt(); + CScValue *val = stack->pop(); + + CAdLayer *layer = new CAdLayer(_gameRef); + if (!val->isNULL()) layer->setName(val->getString()); + if (_mainLayer) { + layer->_width = _mainLayer->_width; + layer->_height = _mainLayer->_height; + } + if (index < 0) index = 0; + if (index <= _layers.getSize() - 1) _layers.insertAt(index, layer); + else _layers.add(layer); + + _gameRef->registerObject(layer); + + stack->pushNative(layer, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteLayer") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdLayer *toDelete = NULL; + if (val->isNative()) { + CBScriptable *temp = val->getNative(); + for (int i = 0; i < _layers.getSize(); i++) { + if (_layers[i] == temp) { + toDelete = _layers[i]; + break; + } + } + } else { + int index = val->getInt(); + if (index >= 0 && index < _layers.getSize()) { + toDelete = _layers[index]; + } + } + if (toDelete == NULL) { + stack->pushBool(false); + return STATUS_OK; + } + + if (toDelete->_main) { + script->runtimeError("Scene.DeleteLayer - cannot delete main scene layer"); + stack->pushBool(false); + return STATUS_OK; + } + + for (int i = 0; i < _layers.getSize(); i++) { + if (_layers[i] == toDelete) { + _layers.removeAt(i); + _gameRef->unregisterObject(toDelete); + break; + } + } + stack->pushBool(true); + return STATUS_OK; + } + + else return CBObject::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdScene::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("scene"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumLayers (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumLayers") == 0) { + _scValue->setInt(_layers.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumWaypointGroups (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumWaypointGroups") == 0) { + _scValue->setInt(_waypointGroups.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MainLayer (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MainLayer") == 0) { + if (_mainLayer) _scValue->setNative(_mainLayer, true); + else _scValue->setNULL(); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumFreeNodes (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumFreeNodes") == 0) { + _scValue->setInt(_objects.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MouseX (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MouseX") == 0) { + int viewportX; + getViewportOffset(&viewportX); + + _scValue->setInt(_gameRef->_mousePos.x + _offsetLeft - viewportX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MouseY (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MouseY") == 0) { + int viewportY; + getViewportOffset(NULL, &viewportY); + + _scValue->setInt(_gameRef->_mousePos.y + _offsetTop - viewportY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AutoScroll + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AutoScroll") == 0) { + _scValue->setBool(_autoScroll); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentState + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentState") == 0) { + _scValue->setBool(_persistentState); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentStateSprites + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentStateSprites") == 0) { + _scValue->setBool(_persistentStateSprites); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsX") == 0) { + _scValue->setInt(_scrollPixelsH); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsY") == 0) { + _scValue->setInt(_scrollPixelsV); + return _scValue; + } + + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedX") == 0) { + _scValue->setInt(_scrollTimeH); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedY") == 0) { + _scValue->setInt(_scrollTimeV); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetX") == 0) { + _scValue->setInt(_offsetLeft); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetY") == 0) { + _scValue->setInt(_offsetTop); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Width (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + if (_mainLayer) _scValue->setInt(_mainLayer->_width); + else _scValue->setInt(0); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Height (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + if (_mainLayer) _scValue->setInt(_mainLayer->_height); + else _scValue->setInt(0); + return _scValue; + } + + else return CBObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AutoScroll + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AutoScroll") == 0) { + _autoScroll = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentState + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentState") == 0) { + _persistentState = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentStateSprites + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentStateSprites") == 0) { + _persistentStateSprites = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsX") == 0) { + _scrollPixelsH = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsY") == 0) { + _scrollPixelsV = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedX") == 0) { + _scrollTimeH = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedY") == 0) { + _scrollTimeV = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetX") == 0) { + _offsetLeft = value->getInt(); + + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetLeft = MAX(0, _offsetLeft - viewportWidth / 2); + _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); + _targetOffsetLeft = _offsetLeft; + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetY") == 0) { + _offsetTop = value->getInt(); + + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetTop = MAX(0, _offsetTop - viewportHeight / 2); + _offsetTop = MIN(_offsetTop, _height - viewportHeight); + _targetOffsetTop = _offsetTop; + + return STATUS_OK; + } + + else return CBObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdScene::scToString() { + return "[scene object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::addObject(CAdObject *object) { + _objects.add(object); + return _gameRef->registerObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::removeObject(CAdObject *object) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i] == object) { + _objects.removeAt(i); + return _gameRef->unregisterObject(object); + } + } + return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::saveAsText(CBDynBuffer *buffer, int indent) { + int i; + + buffer->putTextIndent(indent, "SCENE {\n"); + + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + + if (_persistentState) + buffer->putTextIndent(indent + 2, "PERSISTENT_STATE=%s\n", _persistentState ? "TRUE" : "FALSE"); + + if (!_persistentStateSprites) + buffer->putTextIndent(indent + 2, "PERSISTENT_STATE_SPRITES=%s\n", _persistentStateSprites ? "TRUE" : "FALSE"); + + + // scripts + for (i = 0; i < _scripts.getSize(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + buffer->putTextIndent(indent + 2, "\n"); + + // properties + if (_scProp) _scProp->saveAsText(buffer, indent + 2); + + // viewport + if (_viewport) { + Rect32 *rc = _viewport->getRect(); + buffer->putTextIndent(indent + 2, "VIEWPORT { %d, %d, %d, %d }\n", rc->left, rc->top, rc->right, rc->bottom); + } + + + + // editor settings + buffer->putTextIndent(indent + 2, "; ----- editor settings\n"); + buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_H=%d\n", _editorMarginH); + buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_V=%d\n", _editorMarginV); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_FRAME { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColFrame), RGBCOLGetG(_editorColFrame), RGBCOLGetB(_editorColFrame), RGBCOLGetA(_editorColFrame)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntitySel), RGBCOLGetG(_editorColEntitySel), RGBCOLGetB(_editorColEntitySel), RGBCOLGetA(_editorColEntitySel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegionSel), RGBCOLGetG(_editorColRegionSel), RGBCOLGetB(_editorColRegionSel), RGBCOLGetA(_editorColRegionSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlockedSel), RGBCOLGetG(_editorColBlockedSel), RGBCOLGetB(_editorColBlockedSel), RGBCOLGetA(_editorColBlockedSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecorSel), RGBCOLGetG(_editorColDecorSel), RGBCOLGetB(_editorColDecorSel), RGBCOLGetA(_editorColDecorSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypointsSel), RGBCOLGetG(_editorColWaypointsSel), RGBCOLGetB(_editorColWaypointsSel), RGBCOLGetA(_editorColWaypointsSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntity), RGBCOLGetG(_editorColEntity), RGBCOLGetB(_editorColEntity), RGBCOLGetA(_editorColEntity)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegion), RGBCOLGetG(_editorColRegion), RGBCOLGetB(_editorColRegion), RGBCOLGetA(_editorColRegion)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecor), RGBCOLGetG(_editorColDecor), RGBCOLGetB(_editorColDecor), RGBCOLGetA(_editorColDecor)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlocked), RGBCOLGetG(_editorColBlocked), RGBCOLGetB(_editorColBlocked), RGBCOLGetA(_editorColBlocked)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypoints), RGBCOLGetG(_editorColWaypoints), RGBCOLGetB(_editorColWaypoints), RGBCOLGetA(_editorColWaypoints)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_SCALE { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColScale), RGBCOLGetG(_editorColScale), RGBCOLGetB(_editorColScale), RGBCOLGetA(_editorColScale)); + + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_REGIONS=%s\n", _editorShowRegions ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_BLOCKED=%s\n", _editorShowBlocked ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_DECORATION=%s\n", _editorShowDecor ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_ENTITIES=%s\n", _editorShowEntities ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_SCALE=%s\n", _editorShowScale ? "TRUE" : "FALSE"); + + buffer->putTextIndent(indent + 2, "\n"); + + CBBase::saveAsText(buffer, indent + 2); + + // waypoints + buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); + for (i = 0; i < _waypointGroups.getSize(); i++) _waypointGroups[i]->saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent + 2, "\n"); + + // layers + buffer->putTextIndent(indent + 2, "; ----- layers\n"); + for (i = 0; i < _layers.getSize(); i++) _layers[i]->saveAsText(buffer, indent + 2); + + // scale levels + buffer->putTextIndent(indent + 2, "; ----- scale levels\n"); + for (i = 0; i < _scaleLevels.getSize(); i++) _scaleLevels[i]->saveAsText(buffer, indent + 2); + + // rotation levels + buffer->putTextIndent(indent + 2, "; ----- rotation levels\n"); + for (i = 0; i < _rotLevels.getSize(); i++) _rotLevels[i]->saveAsText(buffer, indent + 2); + + + buffer->putTextIndent(indent + 2, "\n"); + + // free entities + buffer->putTextIndent(indent + 2, "; ----- free entities\n"); + for (i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY) { + _objects[i]->saveAsText(buffer, indent + 2); + + } + } + + + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::sortScaleLevels() { + bool changed; + do { + changed = false; + for (int i = 0; i < _scaleLevels.getSize() - 1; i++) { + if (_scaleLevels[i]->_posY > _scaleLevels[i + 1]->_posY) { + CAdScaleLevel *sl = _scaleLevels[i]; + _scaleLevels[i] = _scaleLevels[i + 1]; + _scaleLevels[i + 1] = sl; + + changed = true; + } + } + + } while (changed); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::sortRotLevels() { + bool changed; + do { + changed = false; + for (int i = 0; i < _rotLevels.getSize() - 1; i++) { + if (_rotLevels[i]->_posX > _rotLevels[i + 1]->_posX) { + CAdRotLevel *rl = _rotLevels[i]; + _rotLevels[i] = _rotLevels[i + 1]; + _rotLevels[i + 1] = rl; + + changed = true; + } + } + + } while (changed); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +float CAdScene::getScaleAt(int Y) { + CAdScaleLevel *prev = NULL; + CAdScaleLevel *next = NULL; + + for (int i = 0; i < _scaleLevels.getSize(); i++) { + /* CAdScaleLevel *xxx = _scaleLevels[i];*/ + /* int j = _scaleLevels.getSize(); */ + if (_scaleLevels[i]->_posY < Y) prev = _scaleLevels[i]; + else { + next = _scaleLevels[i]; + break; + } + } + + if (prev == NULL || next == NULL) return 100; + + int delta_y = next->_posY - prev->_posY; + float delta_scale = next->_scale - prev->_scale; + Y -= prev->_posY; + + float percent = (float)Y / ((float)delta_y / 100.0f); + return prev->_scale + delta_scale / 100 * percent; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::persist(CBPersistMgr *persistMgr) { + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_autoScroll)); + persistMgr->transfer(TMEMBER(_editorColBlocked)); + persistMgr->transfer(TMEMBER(_editorColBlockedSel)); + persistMgr->transfer(TMEMBER(_editorColDecor)); + persistMgr->transfer(TMEMBER(_editorColDecorSel)); + persistMgr->transfer(TMEMBER(_editorColEntity)); + persistMgr->transfer(TMEMBER(_editorColEntitySel)); + persistMgr->transfer(TMEMBER(_editorColFrame)); + persistMgr->transfer(TMEMBER(_editorColRegion)); + persistMgr->transfer(TMEMBER(_editorColRegionSel)); + persistMgr->transfer(TMEMBER(_editorColScale)); + persistMgr->transfer(TMEMBER(_editorColWaypoints)); + persistMgr->transfer(TMEMBER(_editorColWaypointsSel)); + persistMgr->transfer(TMEMBER(_editorMarginH)); + persistMgr->transfer(TMEMBER(_editorMarginV)); + persistMgr->transfer(TMEMBER(_editorShowBlocked)); + persistMgr->transfer(TMEMBER(_editorShowDecor)); + persistMgr->transfer(TMEMBER(_editorShowEntities)); + persistMgr->transfer(TMEMBER(_editorShowRegions)); + persistMgr->transfer(TMEMBER(_editorShowScale)); + persistMgr->transfer(TMEMBER(_fader)); + persistMgr->transfer(TMEMBER(_height)); + persistMgr->transfer(TMEMBER(_initialized)); + persistMgr->transfer(TMEMBER(_lastTimeH)); + persistMgr->transfer(TMEMBER(_lastTimeV)); + _layers.persist(persistMgr); + persistMgr->transfer(TMEMBER(_mainLayer)); + _objects.persist(persistMgr); + persistMgr->transfer(TMEMBER(_offsetLeft)); + persistMgr->transfer(TMEMBER(_offsetTop)); + persistMgr->transfer(TMEMBER(_paralaxScrolling)); + persistMgr->transfer(TMEMBER(_persistentState)); + persistMgr->transfer(TMEMBER(_persistentStateSprites)); + persistMgr->transfer(TMEMBER(_pfMaxTime)); + _pfPath.persist(persistMgr); + persistMgr->transfer(TMEMBER(_pfPointsNum)); + persistMgr->transfer(TMEMBER(_pfReady)); + persistMgr->transfer(TMEMBER(_pfRequester)); + persistMgr->transfer(TMEMBER(_pfTarget)); + persistMgr->transfer(TMEMBER(_pfTargetPath)); + _rotLevels.persist(persistMgr); + _scaleLevels.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollPixelsH)); + persistMgr->transfer(TMEMBER(_scrollPixelsV)); + persistMgr->transfer(TMEMBER(_scrollTimeH)); + persistMgr->transfer(TMEMBER(_scrollTimeV)); + persistMgr->transfer(TMEMBER(_shieldWindow)); + persistMgr->transfer(TMEMBER(_targetOffsetLeft)); + persistMgr->transfer(TMEMBER(_targetOffsetTop)); + _waypointGroups.persist(persistMgr); + persistMgr->transfer(TMEMBER(_viewport)); + persistMgr->transfer(TMEMBER(_width)); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::afterLoad() { + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, CBObject *requester) { + double xStep, yStep, x, y; + int xLength, yLength, xCount, yCount; + int x1, y1, x2, y2; + + x1 = *targetX; + y1 = *targetY; + x2 = startX; + y2 = startY; + + + xLength = abs(x2 - x1); + yLength = abs(y2 - y1); + + if (xLength > yLength) { + /* + if (X1 > X2) + { + Swap(&X1, &X2); + Swap(&Y1, &Y2); + } + */ + + yStep = fabs((double)(y2 - y1) / (double)(x2 - x1)); + y = y1; + + for (xCount = x1; xCount < x2; xCount++) { + if (isWalkableAt(xCount, (int)y, checkFreeObjects, requester)) { + *targetX = xCount; + *targetY = (int)y; + return STATUS_OK; + } + y += yStep; + } + } else { + /* + if (Y1 > Y2) { + Swap(&X1, &X2); + Swap(&Y1, &Y2); + } + */ + + xStep = fabs((double)(x2 - x1) / (double)(y2 - y1)); + x = x1; + + for (yCount = y1; yCount < y2; yCount++) { + if (isWalkableAt((int)x, yCount, checkFreeObjects, requester)) { + *targetX = (int)x; + *targetY = yCount; + return STATUS_OK; + } + x += xStep; + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, bool checkFreeObjects, CBObject *requester) { + int x = *argX; + int y = *argY; + + if (isWalkableAt(x, y, checkFreeObjects, requester) || !_mainLayer) { + return STATUS_OK; + } + + // right + int length_right = 0; + bool found_right = false; + for (x = *argX, y = *argY; x < _mainLayer->_width; x++, length_right++) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x - 5, y, checkFreeObjects, requester)) { + found_right = true; + break; + } + } + + // left + int length_left = 0; + bool found_left = false; + for (x = *argX, y = *argY; x >= 0; x--, length_left--) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x + 5, y, checkFreeObjects, requester)) { + found_left = true; + break; + } + } + + // up + int length_up = 0; + bool found_up = false; + for (x = *argX, y = *argY; y >= 0; y--, length_up--) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y + 5, checkFreeObjects, requester)) { + found_up = true; + break; + } + } + + // down + int length_down = 0; + bool found_down = false; + for (x = *argX, y = *argY; y < _mainLayer->_height; y++, length_down++) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y - 5, checkFreeObjects, requester)) { + found_down = true; + break; + } + } + + if (!found_left && !found_right && !found_up && !found_down) { + return STATUS_OK; + } + + int OffsetX = INT_MAX, OffsetY = INT_MAX; + + if (found_left && found_right) { + if (abs(length_left) < abs(length_right)) OffsetX = length_left; + else OffsetX = length_right; + } else if (found_left) OffsetX = length_left; + else if (found_right) OffsetX = length_right; + + if (found_up && found_down) { + if (abs(length_up) < abs(length_down)) OffsetY = length_up; + else OffsetY = length_down; + } else if (found_up) OffsetY = length_up; + else if (found_down) OffsetY = length_down; + + if (abs(OffsetX) < abs(OffsetY)) + *argX = *argX + OffsetX; + else + *argY = *argY + OffsetY; + + if (!isWalkableAt(*argX, *argY)) return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); + else return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::pfPointsStart() { + _pfPointsNum = 0; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::pfPointsAdd(int x, int y, int distance) { + if (_pfPointsNum >= _pfPath.getSize()) { + _pfPath.add(new CAdPathPoint(x, y, distance)); + } else { + _pfPath[_pfPointsNum]->x = x; + _pfPath[_pfPointsNum]->y = y; + _pfPath[_pfPointsNum]->_distance = distance; + _pfPath[_pfPointsNum]->_marked = false; + _pfPath[_pfPointsNum]->_origin = NULL; + } + + _pfPointsNum++; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getViewportOffset(int *offsetX, int *offsetY) { + CAdGame *adGame = (CAdGame *)_gameRef; + if (_viewport && !_gameRef->_editorMode) { + if (offsetX) *offsetX = _viewport->_offsetX; + if (offsetY) *offsetY = _viewport->_offsetY; + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + if (offsetX) *offsetX = adGame->_sceneViewport->_offsetX; + if (offsetY) *offsetY = adGame->_sceneViewport->_offsetY; + } else { + if (offsetX) *offsetX = 0; + if (offsetY) *offsetY = 0; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getViewportSize(int *width, int *height) { + CAdGame *adGame = (CAdGame *)_gameRef; + if (_viewport && !_gameRef->_editorMode) { + if (width) *width = _viewport->getWidth(); + if (height) *height = _viewport->getHeight(); + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + if (width) *width = adGame->_sceneViewport->getWidth(); + if (height) *height = adGame->_sceneViewport->getHeight(); + } else { + if (width) *width = _gameRef->_renderer->_width; + if (height) *height = _gameRef->_renderer->_height; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdScene::getOffsetLeft() { + int viewportX; + getViewportOffset(&viewportX); + + return _offsetLeft - viewportX; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdScene::getOffsetTop() { + int viewportY; + getViewportOffset(NULL, &viewportY); + + return _offsetTop - viewportY; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::pointInViewport(int x, int y) { + int left, top, width, height; + + getViewportOffset(&left, &top); + getViewportSize(&width, &height); + + return x >= left && x <= left + width && y >= top && y <= top + height; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::setOffset(int offsetLeft, int offsetTop) { + _offsetLeft = offsetLeft; + _offsetTop = offsetTop; +} + + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdScene::getNodeByName(const char *name) { + CBObject *ret = NULL; + + // dependent objects + for (int i = 0; i < _layers.getSize(); i++) { + CAdLayer *layer = _layers[i]; + for (int j = 0; j < layer->_nodes.getSize(); j++) { + CAdSceneNode *node = layer->_nodes[j]; + if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->_name)) || + (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->_name))) { + switch (node->_type) { + case OBJECT_ENTITY: + ret = node->_entity; + break; + case OBJECT_REGION: + ret = node->_region; + break; + default: + ret = NULL; + } + return ret; + } + } + } + + // free entities + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->_name)) { + return _objects[i]; + } + } + + // waypoint groups + for (int i = 0; i < _waypointGroups.getSize(); i++) { + if (!scumm_stricmp(name, _waypointGroups[i]->_name)) { + return _waypointGroups[i]; + } + } + + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::saveState() { + return persistState(true); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::loadState() { + return persistState(false); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::persistState(bool saving) { + if (!_persistentState) return STATUS_OK; + + CAdGame *adGame = (CAdGame *)_gameRef; + CAdSceneState *state = adGame->getSceneState(_filename, saving); + if (!state) return STATUS_OK; + + CAdNodeState *nodeState; + + // dependent objects + for (int i = 0; i < _layers.getSize(); i++) { + CAdLayer *layer = _layers[i]; + for (int j = 0; j < layer->_nodes.getSize(); j++) { + CAdSceneNode *node = layer->_nodes[j]; + switch (node->_type) { + case OBJECT_ENTITY: + if (!node->_entity->_saveState) continue; + nodeState = state->getNodeState(node->_entity->_name, saving); + if (nodeState) { + nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); + //if(Saving) NodeState->_active = node->_entity->_active; + //else node->_entity->_active = NodeState->_active; + } + break; + case OBJECT_REGION: + if (!node->_region->_saveState) continue; + nodeState = state->getNodeState(node->_region->_name, saving); + if (nodeState) { + if (saving) nodeState->_active = node->_region->_active; + else node->_region->_active = nodeState->_active; + } + break; + default: + warning("CAdScene::PersistState - unhandled enum"); + break; + } + } + } + + // free entities + for (int i = 0; i < _objects.getSize(); i++) { + if (!_objects[i]->_saveState) continue; + if (_objects[i]->_type == OBJECT_ENTITY) { + nodeState = state->getNodeState(_objects[i]->_name, saving); + if (nodeState) { + nodeState->transferEntity((CAdEntity *)_objects[i], _persistentStateSprites, saving); + //if(Saving) NodeState->_active = _objects[i]->_active; + //else _objects[i]->_active = NodeState->_active; + } + } + } + + // waypoint groups + for (int i = 0; i < _waypointGroups.getSize(); i++) { + nodeState = state->getNodeState(_waypointGroups[i]->_name, saving); + if (nodeState) { + if (saving) nodeState->_active = _waypointGroups[i]->_active; + else _waypointGroups[i]->_active = nodeState->_active; + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +float CAdScene::getRotationAt(int x, int y) { + CAdRotLevel *prev = NULL; + CAdRotLevel *next = NULL; + + for (int i = 0; i < _rotLevels.getSize(); i++) { + /* CAdRotLevel *xxx = _rotLevels[i]; + int j = _rotLevels.getSize();*/ + if (_rotLevels[i]->_posX < x) prev = _rotLevels[i]; + else { + next = _rotLevels[i]; + break; + } + } + + if (prev == NULL || next == NULL) return 0; + + int delta_x = next->_posX - prev->_posX; + float delta_rot = next->_rotation - prev->_rotation; + x -= prev->_posX; + + float percent = (float)x / ((float)delta_x / 100.0f); + return prev->_rotation + delta_rot / 100 * percent; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::handleItemAssociations(const char *itemName, bool show) { + for (int i = 0; i < _layers.getSize(); i++) { + CAdLayer *layer = _layers[i]; + for (int j = 0; j < layer->_nodes.getSize(); j++) { + if (layer->_nodes[j]->_type == OBJECT_ENTITY) { + CAdEntity *ent = layer->_nodes[j]->_entity; + + if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; + } + } + } + + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY) { + CAdEntity *ent = (CAdEntity *)_objects[i]; + if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getRegionsAt(int x, int y, CAdRegion **regionList, int numRegions) { + int numUsed = 0; + if (_mainLayer) { + for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { + if (numUsed < numRegions - 1) { + regionList[numUsed] = node->_region; + numUsed++; + } else break; + } + } + } + for (int i = numUsed; i < numRegions; i++) { + regionList[i] = NULL; + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::restoreDeviceObjects() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdScene::getNextAccessObject(CBObject *currObject) { + CBArray objects; + getSceneObjects(objects, true); + + if (objects.getSize() == 0) return NULL; + else { + if (currObject != NULL) { + for (int i = 0; i < objects.getSize(); i++) { + if (objects[i] == currObject) { + if (i < objects.getSize() - 1) return objects[i + 1]; + else break; + } + } + } + return objects[0]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdScene::getPrevAccessObject(CBObject *currObject) { + CBArray objects; + getSceneObjects(objects, true); + + if (objects.getSize() == 0) return NULL; + else { + if (currObject != NULL) { + for (int i = objects.getSize() - 1; i >= 0; i--) { + if (objects[i] == currObject) { + if (i > 0) return objects[i - 1]; + else break; + } + } + } + return objects[objects.getSize() - 1]; + } + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getSceneObjects(CBArray &objects, bool interactiveOnly) { + for (int i = 0; i < _layers.getSize(); i++) { + // close-up layer -> remove everything below it + if (interactiveOnly && _layers[i]->_closeUp) objects.removeAll(); + + + for (int j = 0; j < _layers[i]->_nodes.getSize(); j++) { + CAdSceneNode *node = _layers[i]->_nodes[j]; + switch (node->_type) { + case OBJECT_ENTITY: { + CAdEntity *ent = node->_entity; + if (ent->_active && (ent->_registrable || !interactiveOnly)) + objects.add(ent); + } + break; + + case OBJECT_REGION: { + CBArray regionObj; + getRegionObjects(node->_region, regionObj, interactiveOnly); + for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { + bool found = false; + for (int old = 0; old < objects.getSize(); old++) { + if (objects[old] == regionObj[newIndex]) { + found = true; + break; + } + } + if (!found) objects.add(regionObj[newIndex]); + } + //if(RegionObj.getSize() > 0) Objects.Append(RegionObj); + } + break; + default: + warning("CAdScene::GetSceneObjects - Unhandled enum"); + break; + } + } + } + + // objects outside any region + CBArray regionObj; + getRegionObjects(NULL, regionObj, interactiveOnly); + for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { + bool found = false; + for (int old = 0; old < objects.getSize(); old++) { + if (objects[old] == regionObj[newIndex]) { + found = true; + break; + } + } + if (!found) objects.add(regionObj[newIndex]); + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getRegionObjects(CAdRegion *region, CBArray &objects, bool interactiveOnly) { + CAdGame *adGame = (CAdGame *)_gameRef; + CAdObject *obj; + + // global objects + for (int i = 0; i < adGame->_objects.getSize(); i++) { + obj = adGame->_objects[i]; + if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + if (interactiveOnly && !obj->_registrable) continue; + + objects.add(obj); + } + } + + // scene objects + for (int i = 0; i < _objects.getSize(); i++) { + obj = _objects[i]; + if (obj->_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + if (interactiveOnly && !obj->_registrable) continue; + + objects.add(obj); + } + } + + // sort by _posY + qsort(objects.getData(), objects.getSize(), sizeof(CAdObject *), CAdScene::compareObjs); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdScene.h b/engines/wintermute/ad/AdScene.h new file mode 100644 index 0000000000..f77c64aa9b --- /dev/null +++ b/engines/wintermute/ad/AdScene.h @@ -0,0 +1,181 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENE_H +#define WINTERMUTE_ADSCENE_H + +#include "engines/wintermute/base/BFader.h" + +namespace WinterMute { + +class CUIWindow; +class CAdObject; +class CAdRegion; +class CBViewport; +class CAdLayer; +class CBPoint; +class CAdWaypointGroup; +class CAdPath; +class CAdScaleLevel; +class CAdRotLevel; +class CAdPathPoint; +class CAdScene : public CBObject { +public: + + CBObject *getNextAccessObject(CBObject *CurrObject); + CBObject *getPrevAccessObject(CBObject *CurrObject); + bool getSceneObjects(CBArray &Objects, bool InteractiveOnly); + bool getRegionObjects(CAdRegion *Region, CBArray &Objects, bool InteractiveOnly); + + bool afterLoad(); + + bool getRegionsAt(int X, int Y, CAdRegion **RegionList, int NumRegions); + bool handleItemAssociations(const char *ItemName, bool Show); + CUIWindow *_shieldWindow; + float getRotationAt(int X, int Y); + bool loadState(); + bool saveState(); + bool _persistentState; + bool _persistentStateSprites; + CBObject *getNodeByName(const char *name); + void setOffset(int OffsetLeft, int OffsetTop); + bool pointInViewport(int X, int Y); + int getOffsetTop(); + int getOffsetLeft(); + bool getViewportSize(int *Width = NULL, int *Height = NULL); + bool getViewportOffset(int *OffsetX = NULL, int *OffsetY = NULL); + CBViewport *_viewport; + CBFader *_fader; + int _pfPointsNum; + void pfPointsAdd(int X, int Y, int Distance); + void pfPointsStart(); + bool _initialized; + bool correctTargetPoint(int StartX, int StartY, int *X, int *Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); + bool correctTargetPoint2(int StartX, int StartY, int *TargetX, int *TargetY, bool CheckFreeObjects, CBObject *Requester); + DECLARE_PERSISTENT(CAdScene, CBObject) + bool displayRegionContent(CAdRegion *Region = NULL, bool Display3DOnly = false); + bool displayRegionContentOld(CAdRegion *Region = NULL); + static int compareObjs(const void *Obj1, const void *Obj2); + + bool updateFreeObjects(); + bool traverseNodes(bool Update = false); + float getScaleAt(int Y); + bool sortScaleLevels(); + bool sortRotLevels(); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + uint32 getAlphaAt(int X, int Y, bool ColorCheck = false); + bool _paralaxScrolling; + void skipTo(int OffsetX, int OffsetY); + void setDefaults(); + void cleanup(); + void skipToObject(CBObject *Object); + void scrollToObject(CBObject *Object); + void scrollTo(int OffsetX, int OffsetY); + virtual bool update(); + bool _autoScroll; + int _targetOffsetTop; + int _targetOffsetLeft; + + int _scrollPixelsV; + uint32 _scrollTimeV; + uint32 _lastTimeV; + + int _scrollPixelsH; + uint32 _scrollTimeH; + uint32 _lastTimeH; + + virtual bool display(); + uint32 _pfMaxTime; + bool initLoop(); + void pathFinderStep(); + bool isBlockedAt(int X, int Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); + bool isWalkableAt(int X, int Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); + CAdLayer *_mainLayer; + float getZoomAt(int X, int Y); + bool getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject *requester = NULL); + CAdScene(CBGame *inGame); + virtual ~CAdScene(); + CBArray _layers; + CBArray _objects; + CBArray _waypointGroups; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + int _width; + int _height; + bool addObject(CAdObject *Object); + bool removeObject(CAdObject *Object); + int _editorMarginH; + int _editorMarginV; + uint32 _editorColFrame; + uint32 _editorColEntity; + uint32 _editorColRegion; + uint32 _editorColBlocked; + uint32 _editorColWaypoints; + uint32 _editorColEntitySel; + uint32 _editorColRegionSel; + uint32 _editorColBlockedSel; + uint32 _editorColWaypointsSel; + uint32 _editorColScale; + uint32 _editorColDecor; + uint32 _editorColDecorSel; + + bool _editorShowRegions; + bool _editorShowBlocked; + bool _editorShowDecor; + bool _editorShowEntities; + bool _editorShowScale; + CBArray _scaleLevels; + CBArray _rotLevels; + + virtual bool restoreDeviceObjects(); + int getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester = NULL); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + + +private: + bool persistState(bool Saving = true); + void pfAddWaypointGroup(CAdWaypointGroup *Wpt, CBObject *Requester = NULL); + bool _pfReady; + CBPoint *_pfTarget; + CAdPath *_pfTargetPath; + CBObject *_pfRequester; + CBArray _pfPath; + + int _offsetTop; + int _offsetLeft; + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdSceneNode.cpp b/engines/wintermute/ad/AdSceneNode.cpp new file mode 100644 index 0000000000..5f518e5442 --- /dev/null +++ b/engines/wintermute/ad/AdSceneNode.cpp @@ -0,0 +1,83 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdSceneNode.h" +#include "engines/wintermute/base/BGame.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdSceneNode, false) + +////////////////////////////////////////////////////////////////////////// +CAdSceneNode::CAdSceneNode(CBGame *inGame): CBObject(inGame) { + _type = OBJECT_NONE; + _region = NULL; + _entity = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSceneNode::~CAdSceneNode() { + _gameRef->unregisterObject(_region); + _region = NULL; + + _gameRef->unregisterObject(_entity); + _entity = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSceneNode::setEntity(CAdEntity *entity) { + _type = OBJECT_ENTITY; + _entity = entity; + return _gameRef->registerObject(entity); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSceneNode::setRegion(CAdRegion *region) { + _type = OBJECT_REGION; + _region = region; + return _gameRef->registerObject(region); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSceneNode::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_entity)); + persistMgr->transfer(TMEMBER(_region)); + persistMgr->transfer(TMEMBER_INT(_type)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdSceneNode.h b/engines/wintermute/ad/AdSceneNode.h new file mode 100644 index 0000000000..d081959934 --- /dev/null +++ b/engines/wintermute/ad/AdSceneNode.h @@ -0,0 +1,54 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENENODE_H +#define WINTERMUTE_ADSCENENODE_H + + +#include "engines/wintermute/ad/AdTypes.h" // Added by ClassView +#include "engines/wintermute/ad/AdRegion.h" // Added by ClassView +#include "engines/wintermute/ad/AdEntity.h" + +namespace WinterMute { + +class CAdSceneNode : public CBObject { +public: + DECLARE_PERSISTENT(CAdSceneNode, CBObject) + bool setRegion(CAdRegion *region); + bool setEntity(CAdEntity *entity); + CAdEntity *_entity; + CAdRegion *_region; + TObjectType _type; + CAdSceneNode(CBGame *inGame); + virtual ~CAdSceneNode(); + +}; + +} + +#endif diff --git a/engines/wintermute/ad/AdSceneState.cpp b/engines/wintermute/ad/AdSceneState.cpp new file mode 100644 index 0000000000..2192bc13fe --- /dev/null +++ b/engines/wintermute/ad/AdSceneState.cpp @@ -0,0 +1,88 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/ad/AdSceneState.h" +#include "engines/wintermute/ad/AdNodeState.h" +#include "engines/wintermute/PlatformSDL.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdSceneState, false) + +////////////////////////////////////////////////////////////////////////// +CAdSceneState::CAdSceneState(CBGame *inGame): CBBase(inGame) { + _filename = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSceneState::~CAdSceneState() { + delete[] _filename; + _filename = NULL; + + for (int i = 0; i < _nodeStates.getSize(); i++) delete _nodeStates[i]; + _nodeStates.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSceneState::persist(CBPersistMgr *persistMgr) { + persistMgr->transfer(TMEMBER(_filename)); + _nodeStates.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdSceneState::setFilename(const char *filename) { + delete[] _filename; + _filename = new char [strlen(filename) + 1]; + if (_filename) strcpy(_filename, filename); +} + + +////////////////////////////////////////////////////////////////////////// +CAdNodeState *CAdSceneState::getNodeState(char *name, bool saving) { + for (int i = 0; i < _nodeStates.getSize(); i++) { + if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) return _nodeStates[i]; + } + + if (saving) { + CAdNodeState *ret = new CAdNodeState(_gameRef); + ret->setName(name); + _nodeStates.add(ret); + + return ret; + } else return NULL; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdSceneState.h b/engines/wintermute/ad/AdSceneState.h new file mode 100644 index 0000000000..82207f383c --- /dev/null +++ b/engines/wintermute/ad/AdSceneState.h @@ -0,0 +1,51 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENESTATE_H +#define WINTERMUTE_ADSCENESTATE_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/BBase.h" +#include "engines/wintermute/coll_templ.h" + +namespace WinterMute { +class CAdNodeState; +class CAdSceneState : public CBBase { +public: + CAdNodeState *getNodeState(char *name, bool saving); + void setFilename(const char *filename); + DECLARE_PERSISTENT(CAdSceneState, CBBase) + CAdSceneState(CBGame *inGame); + virtual ~CAdSceneState(); + char *_filename; + CBArray _nodeStates; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdSentence.cpp b/engines/wintermute/ad/AdSentence.cpp new file mode 100644 index 0000000000..98926caac6 --- /dev/null +++ b/engines/wintermute/ad/AdSentence.cpp @@ -0,0 +1,317 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdSentence.h" +#include "engines/wintermute/ad/AdTalkDef.h" +#include "engines/wintermute/ad/AdTalkNode.h" +#include "engines/wintermute/ad/AdGame.h" +#include "engines/wintermute/utils/PathUtil.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BSound.h" +#include "engines/wintermute/ad/AdScene.h" +#include "engines/wintermute/base/font/BFont.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/base/BFileManager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdSentence, false) + +////////////////////////////////////////////////////////////////////////// +CAdSentence::CAdSentence(CBGame *inGame): CBBase(inGame) { + _text = NULL; + _stances = NULL; + _tempStance = NULL; + + _duration = 0; + _startTime = 0; + _currentStance = 0; + + _font = NULL; + + _pos.x = _pos.y = 0; + _width = _gameRef->_renderer->_width; + + _align = (TTextAlign)TAL_CENTER; + + _sound = NULL; + _soundStarted = false; + + _talkDef = NULL; + _currentSprite = NULL; + _currentSkelAnim = NULL; + _fixedPos = false; + _freezable = true; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSentence::~CAdSentence() { + delete _sound; + delete[] _text; + delete[] _stances; + delete[] _tempStance; + delete _talkDef; + _sound = NULL; + _text = NULL; + _stances = NULL; + _tempStance = NULL; + _talkDef = NULL; + + _currentSprite = NULL; // ref only + _currentSkelAnim = NULL; + _font = NULL; // ref only +} + + +////////////////////////////////////////////////////////////////////////// +void CAdSentence::setText(const char *text) { + if (_text) delete [] _text; + _text = new char[strlen(text) + 1]; + if (_text) strcpy(_text, text); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdSentence::setStances(const char *stances) { + if (_stances) delete [] _stances; + if (stances) { + _stances = new char[strlen(stances) + 1]; + if (_stances) strcpy(_stances, stances); + } else _stances = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdSentence::getCurrentStance() { + return getStance(_currentStance); +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdSentence::getNextStance() { + _currentStance++; + return getStance(_currentStance); +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdSentence::getStance(int stance) { + if (_stances == NULL) return NULL; + + if (_tempStance) delete [] _tempStance; + _tempStance = NULL; + + char *start; + char *curr; + int pos; + + if (stance == 0) start = _stances; + else { + pos = 0; + start = NULL; + curr = _stances; + while (pos < stance) { + if (*curr == '\0') break; + if (*curr == ',') pos++; + curr++; + } + if (pos == stance) start = curr; + } + + if (start == NULL) return NULL; + + while (*start == ' ' && *start != ',' && *start != '\0') start++; + + curr = start; + while (*curr != '\0' && *curr != ',') curr++; + + while (curr > start && *(curr - 1) == ' ') curr--; + + _tempStance = new char [curr - start + 1]; + if (_tempStance) { + _tempStance[curr - start] = '\0'; + strncpy(_tempStance, start, curr - start); + } + + return _tempStance; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::display() { + if (!_font || !_text) return STATUS_FAILED; + + if (_sound && !_soundStarted) { + _sound->play(); + _soundStarted = true; + } + + if (_gameRef->_subtitles) { + int x = _pos.x; + int y = _pos.y; + + if (!_fixedPos) { + x = x - ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); + y = y - ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + } + + + x = MAX(x, 0); + x = MIN(x, _gameRef->_renderer->_width - _width); + y = MAX(y, 0); + + _font->drawText((byte *)_text, x, y, _width, _align); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdSentence::setSound(CBSound *sound) { + if (!sound) return; + delete _sound; + _sound = sound; + _soundStarted = false; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::finish() { + if (_sound) _sound->stop(); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::persist(CBPersistMgr *persistMgr) { + + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER_INT(_align)); + persistMgr->transfer(TMEMBER(_currentStance)); + persistMgr->transfer(TMEMBER(_currentSprite)); + persistMgr->transfer(TMEMBER(_currentSkelAnim)); + persistMgr->transfer(TMEMBER(_duration)); + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_pos)); + persistMgr->transfer(TMEMBER(_sound)); + persistMgr->transfer(TMEMBER(_soundStarted)); + persistMgr->transfer(TMEMBER(_stances)); + persistMgr->transfer(TMEMBER(_startTime)); + persistMgr->transfer(TMEMBER(_talkDef)); + persistMgr->transfer(TMEMBER(_tempStance)); + persistMgr->transfer(TMEMBER(_text)); + persistMgr->transfer(TMEMBER(_width)); + persistMgr->transfer(TMEMBER(_fixedPos)); + persistMgr->transfer(TMEMBER(_freezable)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::setupTalkFile(const char *soundFilename) { + delete _talkDef; + _talkDef = NULL; + _currentSprite = NULL; + + if (!soundFilename) return STATUS_OK; + + + AnsiString path = PathUtil::getDirectoryName(soundFilename); + AnsiString name = PathUtil::getFileNameWithoutExtension(soundFilename); + + AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); + + Common::SeekableReadStream *file = _gameRef->_fileManager->openFile(talkDefFileName.c_str()); + if (file) { + _gameRef->_fileManager->closeFile(file); + } else return STATUS_OK; // no talk def file found + + + _talkDef = new CAdTalkDef(_gameRef); + if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { + delete _talkDef; + _talkDef = NULL; + return STATUS_FAILED; + } + //_gameRef->LOG(0, "Using .talk file: %s", TalkDefFile); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::update(TDirection dir) { + if (!_talkDef) return STATUS_OK; + + uint32 currentTime; + // if sound is available, synchronize with sound, otherwise use timer + + /* + if (_sound) CurrentTime = _sound->GetPositionTime(); + else CurrentTime = _gameRef->_timer - _startTime; + */ + currentTime = _gameRef->_timer - _startTime; + + bool talkNodeFound = false; + for (int i = 0; i < _talkDef->_nodes.getSize(); i++) { + if (_talkDef->_nodes[i]->isInTimeInterval(currentTime, dir)) { + talkNodeFound = true; + + CBSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); + if (newSprite != _currentSprite) newSprite->reset(); + _currentSprite = newSprite; + + if (!_talkDef->_nodes[i]->_playToEnd) break; + } + } + + + // no talk node, try to use default sprite instead (if any) + if (!talkNodeFound) { + CBSprite *newSprite = _talkDef->getDefaultSprite(dir); + if (newSprite) { + if (newSprite != _currentSprite) newSprite->reset(); + _currentSprite = newSprite; + } else _currentSprite = NULL; + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::CanSkip() { + // prevent accidental sentence skipping (TODO make configurable) + return (_gameRef->_timer - _startTime) > 300; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdSentence.h b/engines/wintermute/ad/AdSentence.h new file mode 100644 index 0000000000..954568878e --- /dev/null +++ b/engines/wintermute/ad/AdSentence.h @@ -0,0 +1,85 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSENTENCE_H +#define WINTERMUTE_ADSENTENCE_H + + +#include "engines/wintermute/base/BBase.h" +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/math/Rect32.h" +#include "engines/wintermute/dctypes.h" // Added by ClassView +#include "common/rect.h" + +namespace WinterMute { +class CAdTalkDef; +class CBFont; +class CBSprite; +class CBSound; +class CAdSentence : public CBBase { +public: + bool _freezable; + bool _fixedPos; + CBSprite *_currentSprite; + char *_currentSkelAnim; + bool update(TDirection dir = DI_DOWN); + bool setupTalkFile(const char *soundFilename); + DECLARE_PERSISTENT(CAdSentence, CBBase) + bool finish(); + void setSound(CBSound *Sound); + bool _soundStarted; + CBSound *_sound; + TTextAlign _align; + bool display(); + int _width; + Point32 _pos; + CBFont *_font; + char *getNextStance(); + char *getCurrentStance(); + void setStances(const char *stances); + void setText(const char *text); + int _currentStance; + uint32 _startTime; + char *_stances; + char *_text; + uint32 _duration; + CAdSentence(CBGame *inGame); + virtual ~CAdSentence(); + CAdTalkDef *_talkDef; + + bool CanSkip(); + +private: + char *_tempStance; + char *getStance(int stance); + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdSpriteSet.cpp b/engines/wintermute/ad/AdSpriteSet.cpp new file mode 100644 index 0000000000..127d42d02b --- /dev/null +++ b/engines/wintermute/ad/AdSpriteSet.cpp @@ -0,0 +1,312 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdSpriteSet.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BFileManager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdSpriteSet, false) + +////////////////////////////////////////////////////////////////////////// +CAdSpriteSet::CAdSpriteSet(CBGame *inGame, CBObject *owner): CBObject(inGame) { + _owner = owner; + + for (int i = 0; i < NUM_DIRECTIONS; i++) + _sprites[i] = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSpriteSet::~CAdSpriteSet() { + for (int i = 0; i < NUM_DIRECTIONS; i++) { + delete _sprites[i]; + _sprites[i] = NULL; + } + + _owner = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdSpriteSet::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SPRITESET) +TOKEN_DEF(NAME) +TOKEN_DEF(UP_LEFT) +TOKEN_DEF(DOWN_LEFT) +TOKEN_DEF(LEFT) +TOKEN_DEF(UP_RIGHT) +TOKEN_DEF(DOWN_RIGHT) +TOKEN_DEF(RIGHT) +TOKEN_DEF(UP) +TOKEN_DEF(DOWN) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType CacheType) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SPRITESET) + TOKEN_TABLE(NAME) + TOKEN_TABLE(UP_LEFT) + TOKEN_TABLE(DOWN_LEFT) + TOKEN_TABLE(LEFT) + TOKEN_TABLE(UP_RIGHT) + TOKEN_TABLE(DOWN_RIGHT) + TOKEN_TABLE(RIGHT) + TOKEN_TABLE(UP) + TOKEN_TABLE(DOWN) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SPRITESET) { + _gameRef->LOG(0, "'SPRITESET' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + CBSprite *spr = NULL; + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_LEFT: + delete _sprites[DI_LEFT]; + _sprites[DI_LEFT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_LEFT] = spr; + break; + + case TOKEN_RIGHT: + delete _sprites[DI_RIGHT]; + _sprites[DI_RIGHT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_RIGHT] = spr; + break; + + case TOKEN_UP: + delete _sprites[DI_UP]; + _sprites[DI_UP] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_UP] = spr; + break; + + case TOKEN_DOWN: + delete _sprites[DI_DOWN]; + _sprites[DI_DOWN] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_DOWN] = spr; + break; + + case TOKEN_UP_LEFT: + delete _sprites[DI_UPLEFT]; + _sprites[DI_UPLEFT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_UPLEFT] = spr; + break; + + case TOKEN_UP_RIGHT: + delete _sprites[DI_UPRIGHT]; + _sprites[DI_UPRIGHT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_UPRIGHT] = spr; + break; + + case TOKEN_DOWN_LEFT: + delete _sprites[DI_DOWNLEFT]; + _sprites[DI_DOWNLEFT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_DOWNLEFT] = spr; + break; + + case TOKEN_DOWN_RIGHT: + delete _sprites[DI_DOWNRIGHT]; + _sprites[DI_DOWNRIGHT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_DOWNRIGHT] = spr; + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SPRITESET definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading SPRITESET definition"); + if (spr) delete spr; + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_owner)); + for (int i = 0; i < NUM_DIRECTIONS; i++) { + persistMgr->transfer("", &_sprites[i]); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdSpriteSet::getSprite(TDirection direction) { + int dir = (int)direction; + if (dir < 0) dir = 0; + if (dir >= NUM_DIRECTIONS) dir = NUM_DIRECTIONS - 1; + + CBSprite *ret = NULL; + + // find nearest set sprite + int numSteps = 0; + for (int i = dir; i >= 0; i--) { + if (_sprites[i] != NULL) { + ret = _sprites[i]; + numSteps = dir - i; + break; + } + } + + for (int i = dir; i < NUM_DIRECTIONS; i++) { + if (_sprites[i] != NULL) { + if (ret == NULL || numSteps > i - dir) return _sprites[i]; + else return ret; + } + } + + return ret; +} + + + +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "SPRITESET {\n"); + if (_name) buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + for (int i = 0; i < NUM_DIRECTIONS; i++) { + if (_sprites[i]) { + switch (i) { + case DI_UP: + buffer->putTextIndent(indent + 2, "UP=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_UPRIGHT: + buffer->putTextIndent(indent + 2, "UP_RIGHT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_RIGHT: + buffer->putTextIndent(indent + 2, "RIGHT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_DOWNRIGHT: + buffer->putTextIndent(indent + 2, "DOWN_RIGHT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_DOWN: + buffer->putTextIndent(indent + 2, "DOWN=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_DOWNLEFT: + buffer->putTextIndent(indent + 2, "DOWN_LEFT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_LEFT: + buffer->putTextIndent(indent + 2, "LEFT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_UPLEFT: + buffer->putTextIndent(indent + 2, "UP_LEFT=\"%s\"\n", _sprites[i]->_filename); + break; + } + } + } + + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::containsSprite(CBSprite *sprite) { + if (!sprite) return false; + + for (int i = 0; i < NUM_DIRECTIONS; i++) { + if (_sprites[i] == sprite) return true; + } + return false; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdSpriteSet.h b/engines/wintermute/ad/AdSpriteSet.h new file mode 100644 index 0000000000..ba5c6fb75b --- /dev/null +++ b/engines/wintermute/ad/AdSpriteSet.h @@ -0,0 +1,54 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSPRITESET_H +#define WINTERMUTE_ADSPRITESET_H + + +#include "engines/wintermute/base/BObject.h" +#include "engines/wintermute/base/BSprite.h" // Added by ClassView + +namespace WinterMute { + +class CAdSpriteSet : public CBObject { +public: + bool containsSprite(CBSprite *sprite); + virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); + CBSprite *getSprite(TDirection direction); + DECLARE_PERSISTENT(CAdSpriteSet, CBObject) + CBObject *_owner; + CAdSpriteSet(CBGame *inGame, CBObject *owner = NULL); + virtual ~CAdSpriteSet(); + bool loadFile(const char *filename, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); + bool loadBuffer(byte *buffer, bool complete = true, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); + CBSprite *_sprites[NUM_DIRECTIONS]; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdTalkDef.cpp b/engines/wintermute/ad/AdTalkDef.cpp new file mode 100644 index 0000000000..b598226413 --- /dev/null +++ b/engines/wintermute/ad/AdTalkDef.cpp @@ -0,0 +1,260 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdTalkDef.h" +#include "engines/wintermute/ad/AdTalkNode.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/ad/AdSpriteSet.h" +#include "engines/wintermute/base/BFileManager.h" +#include "engines/wintermute/utils/utils.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdTalkDef, false) + +////////////////////////////////////////////////////////////////////////// +CAdTalkDef::CAdTalkDef(CBGame *inGame): CBObject(inGame) { + _defaultSpriteFilename = NULL; + _defaultSprite = NULL; + + _defaultSpriteSetFilename = NULL; + _defaultSpriteSet = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdTalkDef::~CAdTalkDef() { + for (int i = 0; i < _nodes.getSize(); i++) delete _nodes[i]; + _nodes.removeAll(); + + delete[] _defaultSpriteFilename; + delete _defaultSprite; + _defaultSpriteFilename = NULL; + _defaultSprite = NULL; + + delete[] _defaultSpriteSetFilename; + delete _defaultSpriteSet; + _defaultSpriteSetFilename = NULL; + _defaultSpriteSet = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdTalkDef::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + CBUtils::setString(&_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(TALK) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(ACTION) +TOKEN_DEF(DEFAULT_SPRITESET_FILE) +TOKEN_DEF(DEFAULT_SPRITESET) +TOKEN_DEF(DEFAULT_SPRITE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(TALK) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(ACTION) + TOKEN_TABLE(DEFAULT_SPRITESET_FILE) + TOKEN_TABLE(DEFAULT_SPRITESET) + TOKEN_TABLE(DEFAULT_SPRITE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_TALK) { + _gameRef->LOG(0, "'TALK' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_ACTION: { + CAdTalkNode *Node = new CAdTalkNode(_gameRef); + if (Node && DID_SUCCEED(Node->loadBuffer(params, false))) _nodes.add(Node); + else { + delete Node; + Node = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + case TOKEN_DEFAULT_SPRITE: + CBUtils::setString(&_defaultSpriteFilename, (char *)params); + break; + + case TOKEN_DEFAULT_SPRITESET_FILE: + CBUtils::setString(&_defaultSpriteSetFilename, (char *)params); + break; + + case TOKEN_DEFAULT_SPRITESET: { + delete _defaultSpriteSet; + _defaultSpriteSet = new CAdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadBuffer(params, false))) { + delete _defaultSpriteSet; + _defaultSpriteSet = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in TALK definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading TALK definition"); + return STATUS_FAILED; + } + + delete _defaultSprite; + delete _defaultSpriteSet; + _defaultSprite = NULL; + _defaultSpriteSet = NULL; + + if (_defaultSpriteFilename) { + _defaultSprite = new CBSprite(_gameRef); + if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) return STATUS_FAILED; + } + + if (_defaultSpriteSetFilename) { + _defaultSpriteSet = new CAdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) return STATUS_FAILED; + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_defaultSprite)); + persistMgr->transfer(TMEMBER(_defaultSpriteFilename)); + persistMgr->transfer(TMEMBER(_defaultSpriteSet)); + persistMgr->transfer(TMEMBER(_defaultSpriteSetFilename)); + + _nodes.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "TALK {\n"); + if (_defaultSpriteFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); + + if (_defaultSpriteSetFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); + else if (_defaultSpriteSet) _defaultSpriteSet->saveAsText(buffer, indent + 2); + + for (int i = 0; i < _nodes.getSize(); i++) { + _nodes[i]->saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "\n"); + } + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::loadDefaultSprite() { + if (_defaultSpriteFilename && !_defaultSprite) { + _defaultSprite = new CBSprite(_gameRef); + if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { + delete _defaultSprite; + _defaultSprite = NULL; + return STATUS_FAILED; + } else return STATUS_OK; + } else if (_defaultSpriteSetFilename && !_defaultSpriteSet) { + _defaultSpriteSet = new CAdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { + delete _defaultSpriteSet; + _defaultSpriteSet = NULL; + return STATUS_FAILED; + } else return STATUS_OK; + } else return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdTalkDef::getDefaultSprite(TDirection dir) { + loadDefaultSprite(); + if (_defaultSprite) return _defaultSprite; + else if (_defaultSpriteSet) return _defaultSpriteSet->getSprite(dir); + else return NULL; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdTalkDef.h b/engines/wintermute/ad/AdTalkDef.h new file mode 100644 index 0000000000..81d6475013 --- /dev/null +++ b/engines/wintermute/ad/AdTalkDef.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKDEF_H +#define WINTERMUTE_ADTALKDEF_H + +#include "engines/wintermute/coll_templ.h" +#include "engines/wintermute/base/BObject.h" + +namespace WinterMute { +class CAdTalkNode; +class CAdSpriteSet; +class CAdTalkDef : public CBObject { +public: + char *_defaultSpriteSetFilename; + CAdSpriteSet *_defaultSpriteSet; + CBSprite *getDefaultSprite(TDirection Dir); + bool loadDefaultSprite(); + DECLARE_PERSISTENT(CAdTalkDef, CBObject) + + CAdTalkDef(CBGame *inGame); + virtual ~CAdTalkDef(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + CBArray _nodes; + char *_defaultSpriteFilename; + CBSprite *_defaultSprite; + virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdTalkHolder.cpp b/engines/wintermute/ad/AdTalkHolder.cpp new file mode 100644 index 0000000000..4c627ca9ad --- /dev/null +++ b/engines/wintermute/ad/AdTalkHolder.cpp @@ -0,0 +1,366 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdTalkHolder.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "engines/wintermute/base/scriptables/ScScript.h" +#include "engines/wintermute/base/scriptables/ScStack.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/wintermute.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdTalkHolder, false) + +////////////////////////////////////////////////////////////////////////// +CAdTalkHolder::CAdTalkHolder(CBGame *inGame): CAdObject(inGame) { + _sprite = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdTalkHolder::~CAdTalkHolder() { + delete _sprite; + _sprite = NULL; + + for (int i = 0; i < _talkSprites.getSize(); i++) + delete _talkSprites[i]; + _talkSprites.removeAll(); + + for (int i = 0; i < _talkSpritesEx.getSize(); i++) + delete _talkSpritesEx[i]; + _talkSpritesEx.removeAll(); +} + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdTalkHolder::getTalkStance(const char *stance) { + CBSprite *ret = NULL; + + + // forced stance? + if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { + _forcedTalkAnimUsed = true; + delete _animSprite; + _animSprite = new CBSprite(_gameRef, this); + if (_animSprite) { + bool res = _animSprite->loadFile(_forcedTalkAnimName); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "CAdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); + delete _animSprite; + _animSprite = NULL; + } else return _animSprite; + } + } + + + if (stance != NULL) { + // search special talk stances + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->_name, stance) == 0) { + ret = _talkSpritesEx[i]; + break; + } + } + if (ret == NULL) { + // serach generic talk stances + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (scumm_stricmp(_talkSprites[i]->_name, stance) == 0) { + ret = _talkSprites[i]; + break; + } + } + } + } + + // not a valid stance? get a random one + if (ret == NULL) { + if (_talkSprites.getSize() < 1) ret = _sprite; + else { + // TODO: remember last + int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); + ret = _talkSprites[rnd]; + } + } + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdTalkHolder::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // SetSprite + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetSprite") == 0) { + stack->correctParams(1); + + CScValue *val = stack->pop(); + + bool setCurrent = false; + if (_currentSprite && _currentSprite == _sprite) setCurrent = true; + + delete _sprite; + _sprite = NULL; + + if (val->isNULL()) { + _sprite = NULL; + if (setCurrent) _currentSprite = NULL; + stack->pushBool(true); + } else { + const char *filename = val->getString(); + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + script->runtimeError("SetSprite method failed for file '%s'", filename); + stack->pushBool(false); + } else { + _sprite = spr; + if (setCurrent) _currentSprite = _sprite; + stack->pushBool(true); + } + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetSprite") == 0) { + stack->correctParams(0); + + if (!_sprite || !_sprite->_filename) stack->pushNULL(); + else stack->pushString(_sprite->_filename); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetSpriteObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetSpriteObject") == 0) { + stack->correctParams(0); + + if (!_sprite) stack->pushNULL(); + else stack->pushNative(_sprite, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool Ex = stack->pop()->getBool(); + + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("AddTalkSprite method failed for file '%s'", filename); + } else { + if (Ex) _talkSpritesEx.add(spr); + else _talkSprites.add(spr); + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool ex = stack->pop()->getBool(); + + bool setCurrent = false; + bool setTemp2 = false; + + if (ex) { + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->_filename, filename) == 0) { + if (_currentSprite == _talkSpritesEx[i]) + setCurrent = true; + if (_tempSprite2 == _talkSpritesEx[i]) + setTemp2 = true; + delete _talkSpritesEx[i]; + _talkSpritesEx.removeAt(i); + break; + } + } + } else { + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (scumm_stricmp(_talkSprites[i]->_filename, filename) == 0) { + if (_currentSprite == _talkSprites[i]) + setCurrent = true; + if (_tempSprite2 == _talkSprites[i]) + setTemp2 = true; + delete _talkSprites[i]; + _talkSprites.removeAt(i); + break; + } + } + + } + + stack->pushBool(true); + if (setCurrent) + _currentSprite = _sprite; + if (setTemp2) + _tempSprite2 = _sprite; + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool ex = stack->pop()->getBool(); + bool setCurrent = false; + bool setTemp2 = false; + + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("SetTalkSprite method failed for file '%s'", filename); + } else { + + // delete current + if (ex) { + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (_talkSpritesEx[i] == _currentSprite) + setCurrent = true; + if (_talkSpritesEx[i] == _tempSprite2) + setTemp2 = true; + delete _talkSpritesEx[i]; + } + _talkSpritesEx.removeAll(); + } else { + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (_talkSprites[i] == _currentSprite) setCurrent = true; + if (_talkSprites[i] == _tempSprite2) setTemp2 = true; + delete _talkSprites[i]; + } + _talkSprites.removeAll(); + } + + // set new + if (ex) + _talkSpritesEx.add(spr); + else + _talkSprites.add(spr); + stack->pushBool(true); + + if (setCurrent) + _currentSprite = spr; + if (setTemp2) + _tempSprite2 = spr; + } + return STATUS_OK; + } + + else return CAdObject::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdTalkHolder::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type (RO) + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("talk-holder"); + return _scValue; + } + + else return CAdObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkHolder::scSetProperty(const char *name, CScValue *value) { + /* + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + if(strcmp(name, "Item")==0){ + SetItem(value->getString()); + return STATUS_OK; + } + + else*/ return CAdObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdTalkHolder::scToString() { + return "[talk-holder object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkHolder::saveAsText(CBDynBuffer *buffer, int indent) { + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (_talkSprites[i]->_filename) + buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->_filename); + } + + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (_talkSpritesEx[i]->_filename) + buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->_filename); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkHolder::persist(CBPersistMgr *persistMgr) { + CAdObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_sprite)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdTalkHolder.h b/engines/wintermute/ad/AdTalkHolder.h new file mode 100644 index 0000000000..9e6c3bbd63 --- /dev/null +++ b/engines/wintermute/ad/AdTalkHolder.h @@ -0,0 +1,57 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKHOLDER_H +#define WINTERMUTE_ADTALKHOLDER_H + +#include "engines/wintermute/ad/AdObject.h" + +namespace WinterMute { + +class CAdTalkHolder : public CAdObject { +public: + DECLARE_PERSISTENT(CAdTalkHolder, CAdObject) + virtual CBSprite *getTalkStance(const char *stance); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + CBSprite *_sprite; + CBArray _talkSprites; + CBArray _talkSpritesEx; + CAdTalkHolder(CBGame *inGame); + virtual ~CAdTalkHolder(); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdTalkNode.cpp b/engines/wintermute/ad/AdTalkNode.cpp new file mode 100644 index 0000000000..da2195be33 --- /dev/null +++ b/engines/wintermute/ad/AdTalkNode.cpp @@ -0,0 +1,266 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/AdTalkNode.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BSprite.h" +#include "engines/wintermute/ad/AdSpriteSet.h" +#include "engines/wintermute/utils/utils.h" +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdTalkNode, false) + +////////////////////////////////////////////////////////////////////////// +CAdTalkNode::CAdTalkNode(CBGame *inGame): CBBase(inGame) { + _sprite = NULL; + _spriteFilename = NULL; + _spriteSet = NULL; + _spriteSetFilename = NULL; + _comment = NULL; + + _startTime = _endTime = 0; + _playToEnd = false; + _preCache = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdTalkNode::~CAdTalkNode() { + delete[] _spriteFilename; + delete _sprite; + delete[] _spriteSetFilename; + delete _spriteSet; + delete _comment; + _spriteFilename = NULL; + _sprite = NULL; + _spriteSetFilename = NULL; + _spriteSet = NULL; + _comment = NULL; +} + + + +TOKEN_DEF_START +TOKEN_DEF(ACTION) +TOKEN_DEF(SPRITESET_FILE) +TOKEN_DEF(SPRITESET) +TOKEN_DEF(SPRITE) +TOKEN_DEF(START_TIME) +TOKEN_DEF(END_TIME) +TOKEN_DEF(COMMENT) +TOKEN_DEF(PRECACHE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ACTION) + TOKEN_TABLE(SPRITESET_FILE) + TOKEN_TABLE(SPRITESET) + TOKEN_TABLE(SPRITE) + TOKEN_TABLE(START_TIME) + TOKEN_TABLE(END_TIME) + TOKEN_TABLE(COMMENT) + TOKEN_TABLE(PRECACHE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTION) { + _gameRef->LOG(0, "'ACTION' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + _endTime = 0; + _playToEnd = false; + _preCache = false; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_SPRITE: + CBUtils::setString(&_spriteFilename, (char *)params); + break; + + case TOKEN_SPRITESET_FILE: + CBUtils::setString(&_spriteSetFilename, (char *)params); + break; + + case TOKEN_SPRITESET: { + delete _spriteSet; + _spriteSet = new CAdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadBuffer(params, false))) { + delete _spriteSet; + _spriteSet = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + case TOKEN_START_TIME: + parser.scanStr((char *)params, "%d", &_startTime); + break; + + case TOKEN_END_TIME: + parser.scanStr((char *)params, "%d", &_endTime); + break; + + case TOKEN_PRECACHE: + parser.scanStr((char *)params, "%b", &_preCache); + break; + + case TOKEN_COMMENT: + if (_gameRef->_editorMode) CBUtils::setString(&_comment, (char *)params); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ACTION definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ACTION definition"); + return STATUS_FAILED; + } + + if (_endTime == 0) + _playToEnd = true; + else + _playToEnd = false; + + if (_preCache && _spriteFilename) { + delete _sprite; + _sprite = new CBSprite(_gameRef); + if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) + return STATUS_FAILED; + } + + if (_preCache && _spriteSetFilename) { + delete _spriteSet; + _spriteSet = new CAdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) + return STATUS_FAILED; + } + + return STATUS_OK; +} + + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::persist(CBPersistMgr *persistMgr) { + persistMgr->transfer(TMEMBER(_comment)); + persistMgr->transfer(TMEMBER(_startTime)); + persistMgr->transfer(TMEMBER(_endTime)); + persistMgr->transfer(TMEMBER(_playToEnd)); + persistMgr->transfer(TMEMBER(_sprite)); + persistMgr->transfer(TMEMBER(_spriteFilename)); + persistMgr->transfer(TMEMBER(_spriteSet)); + persistMgr->transfer(TMEMBER(_spriteSetFilename)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ACTION {\n"); + if (_comment) buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); + buffer->putTextIndent(indent + 2, "START_TIME=%d\n", _startTime); + if (!_playToEnd) buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); + if (_spriteFilename) buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); + if (_spriteSetFilename) buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); + else if (_spriteSet) _spriteSet->saveAsText(buffer, indent + 2); + if (_preCache) buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); + + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::loadSprite() { + if (_spriteFilename && !_sprite) { + _sprite = new CBSprite(_gameRef); + if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { + delete _sprite; + _sprite = NULL; + return STATUS_FAILED; + } else return STATUS_OK; + } + + else if (_spriteSetFilename && !_spriteSet) { + _spriteSet = new CAdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { + delete _spriteSet; + _spriteSet = NULL; + return STATUS_FAILED; + } else return STATUS_OK; + } + + else return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { + if (time >= _startTime) { + if (_playToEnd) { + if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) return true; + else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) return true; + else return false; + } else return _endTime >= time; + } else return false; +} + + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdTalkNode::getSprite(TDirection dir) { + loadSprite(); + if (_sprite) return _sprite; + else if (_spriteSet) return _spriteSet->getSprite(dir); + else return NULL; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdTalkNode.h b/engines/wintermute/ad/AdTalkNode.h new file mode 100644 index 0000000000..11bbb353c1 --- /dev/null +++ b/engines/wintermute/ad/AdTalkNode.h @@ -0,0 +1,63 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKNODE_H +#define WINTERMUTE_ADTALKNODE_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/BBase.h" + +namespace WinterMute { +class CAdSpriteSet; +class CBSprite; +class CAdTalkNode : public CBBase { +public: + char *_spriteSetFilename; + CAdSpriteSet *_spriteSet; + CBSprite *getSprite(TDirection dir); + bool isInTimeInterval(uint32 time, TDirection dir); + bool loadSprite(); + DECLARE_PERSISTENT(CAdTalkNode, CBBase) + + CAdTalkNode(CBGame *inGame); + virtual ~CAdTalkNode(); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); + char *_spriteFilename; + CBSprite *_sprite; + uint32 _startTime; + uint32 _endTime; + bool _playToEnd; + bool _preCache; + char *_comment; + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/AdTypes.h b/engines/wintermute/ad/AdTypes.h new file mode 100644 index 0000000000..b88d6fe259 --- /dev/null +++ b/engines/wintermute/ad/AdTypes.h @@ -0,0 +1,107 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTYPES_H +#define WINTERMUTE_ADTYPES_H + +namespace WinterMute { + +typedef enum { + GAME_NORMAL, + GAME_WAITING_RESPONSE +} TGameStateEx; + +typedef enum { + OBJECT_ENTITY, + OBJECT_REGION, + OBJECT_ACTOR, + OBJECT_NONE +} TObjectType; + +typedef enum { + ENTITY_NORMAL, + ENTITY_SOUND +} TEntityType; + +typedef enum { + STATE_NONE, + STATE_IDLE, + STATE_PLAYING_ANIM, + STATE_READY, + STATE_FOLLOWING_PATH, + STATE_SEARCHING_PATH, + STATE_WAITING_PATH, + STATE_TURNING_LEFT, + STATE_TURNING_RIGHT, + STATE_TURNING, + STATE_TALKING, + STATE_DIRECT_CONTROL, + STATE_PLAYING_ANIM_SET +} TObjectState; + +typedef enum { + DIRECT_WALK_NONE, + DIRECT_WALK_FW, + DIRECT_WALK_BK +} TDirectWalkMode; + +typedef enum { + DIRECT_TURN_NONE, + DIRECT_TURN_CW, + DIRECT_TURN_CCW +} TDirectTurnMode; + +typedef enum { + RESPONSE_TEXT, + RESPONSE_ICON +} TResponseStyle; + +typedef enum { + RESPONSE_ALWAYS, + RESPONSE_ONCE, + RESPONSE_ONCE_GAME +} TResponseType; + + +typedef enum { + TALK_SKIP_LEFT = 0, + TALK_SKIP_RIGHT = 1, + TALK_SKIP_BOTH = 2, + TALK_SKIP_NONE = 3 +} TTalkSkipButton; + +typedef enum { + GEOM_WAYPOINT, + GEOM_WALKPLANE, + GEOM_BLOCKED, + GEOM_GENERIC +} TGeomNodeType; + +} // end of namespace WinterMute + +#endif // WINTERMUTE_ADTYPES_H diff --git a/engines/wintermute/ad/AdWaypointGroup.cpp b/engines/wintermute/ad/AdWaypointGroup.cpp new file mode 100644 index 0000000000..3080b34c09 --- /dev/null +++ b/engines/wintermute/ad/AdWaypointGroup.cpp @@ -0,0 +1,261 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/AdWaypointGroup.h" +#include "engines/wintermute/base/BParser.h" +#include "engines/wintermute/base/BDynBuffer.h" +#include "engines/wintermute/base/scriptables/ScValue.h" +#include "engines/wintermute/base/BGame.h" +#include "engines/wintermute/base/BRegion.h" +#include "engines/wintermute/base/BFileManager.h" +#include + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdWaypointGroup, false) + +////////////////////////////////////////////////////////////////////////// +CAdWaypointGroup::CAdWaypointGroup(CBGame *inGame): CBObject(inGame) { + _active = true; + _editorSelectedPoint = -1; + _lastMimicScale = -1; + _lastMimicX = _lastMimicY = INT_MIN; +} + + +////////////////////////////////////////////////////////////////////////// +CAdWaypointGroup::~CAdWaypointGroup() { + cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdWaypointGroup::cleanup() { + for (int i = 0; i < _points.getSize(); i++) + delete _points[i]; + _points.removeAll(); + _editorSelectedPoint = -1; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdWaypointGroup::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(WAYPOINTS) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(POINT) +TOKEN_DEF(EDITOR_SELECTED_POINT) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(WAYPOINTS) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(POINT) + TOKEN_TABLE(EDITOR_SELECTED_POINT) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_WAYPOINTS) { + _gameRef->LOG(0, "'WAYPOINTS' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_POINT: { + int x, y; + parser.scanStr((char *)params, "%d,%d", &x, &y); + _points.add(new CBPoint(x, y)); + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_EDITOR_SELECTED_POINT: + parser.scanStr((char *)params, "%d", &_editorSelectedPoint); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in WAYPOINTS definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "WAYPOINTS {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED_POINT=%d\n", _editorSelectedPoint); + + if (_scProp) + _scProp->saveAsText(buffer, indent + 2); + CBBase::saveAsText(buffer, indent + 2); + + for (int i = 0; i < _points.getSize(); i++) { + buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); + } + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_editorSelectedPoint)); + persistMgr->transfer(TMEMBER(_lastMimicScale)); + persistMgr->transfer(TMEMBER(_lastMimicX)); + persistMgr->transfer(TMEMBER(_lastMimicY)); + _points.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdWaypointGroup::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("waypoint-group"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } + + else return CBObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Active") == 0) { + _active = value->getBool(); + return STATUS_OK; + } + + else return CBObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::mimic(CAdWaypointGroup *wpt, float scale, int argX, int argY) { + if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) return STATUS_OK; + + cleanup(); + + for (int i = 0; i < wpt->_points.getSize(); i++) { + int x = (int)((float)wpt->_points[i]->x * scale / 100.0f); + int y = (int)((float)wpt->_points[i]->y * scale / 100.0f); + + _points.add(new CBPoint(x + argX, y + argY)); + } + + _lastMimicScale = scale; + _lastMimicX = argX; + _lastMimicY = argY; + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdWaypointGroup.h b/engines/wintermute/ad/AdWaypointGroup.h new file mode 100644 index 0000000000..f7c9e4c361 --- /dev/null +++ b/engines/wintermute/ad/AdWaypointGroup.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADWAYPOINTGROUP_H +#define WINTERMUTE_ADWAYPOINTGROUP_H + +#include "engines/wintermute/base/BObject.h" + +namespace WinterMute { +class CBPoint; +class CAdWaypointGroup : public CBObject { +public: + float _lastMimicScale; + int _lastMimicX; + int _lastMimicY; + void cleanup(); + bool mimic(CAdWaypointGroup *wpt, float scale = 100.0f, int x = 0, int y = 0); + DECLARE_PERSISTENT(CAdWaypointGroup, CBObject) + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + bool _active; + CAdWaypointGroup(CBGame *inGame); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual ~CAdWaypointGroup(); + CBArray _points; + int _editorSelectedPoint; + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); +}; + +} // end of namespace WinterMute + +#endif -- cgit v1.2.3 From 3ad839b32c5e432e93058218db9139dfbe8b8c84 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 20 Jul 2012 00:45:20 +0200 Subject: WINTERMUTE: Rename PlatformSDL->platform_osystem --- engines/wintermute/ad/AdActor.cpp | 2 +- engines/wintermute/ad/AdEntity.cpp | 2 +- engines/wintermute/ad/AdInventory.cpp | 2 +- engines/wintermute/ad/AdInventoryBox.cpp | 2 +- engines/wintermute/ad/AdItem.cpp | 2 +- engines/wintermute/ad/AdLayer.cpp | 2 +- engines/wintermute/ad/AdNodeState.cpp | 2 +- engines/wintermute/ad/AdResponseBox.cpp | 2 +- engines/wintermute/ad/AdScene.cpp | 2 +- engines/wintermute/ad/AdSceneState.cpp | 2 +- engines/wintermute/ad/AdTalkHolder.cpp | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/AdActor.cpp b/engines/wintermute/ad/AdActor.cpp index 480851d21f..050a419e53 100644 --- a/engines/wintermute/ad/AdActor.cpp +++ b/engines/wintermute/ad/AdActor.cpp @@ -47,7 +47,7 @@ #include "engines/wintermute/base/scriptables/ScValue.h" #include "engines/wintermute/base/scriptables/ScStack.h" #include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/wintermute.h" namespace WinterMute { diff --git a/engines/wintermute/ad/AdEntity.cpp b/engines/wintermute/ad/AdEntity.cpp index c559e99abb..49c723f66a 100644 --- a/engines/wintermute/ad/AdEntity.cpp +++ b/engines/wintermute/ad/AdEntity.cpp @@ -45,7 +45,7 @@ #include "engines/wintermute/base/BRegion.h" #include "engines/wintermute/base/BSprite.h" #include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/utils/utils.h" #include "engines/wintermute/base/scriptables/ScValue.h" #include "engines/wintermute/base/scriptables/ScScript.h" diff --git a/engines/wintermute/ad/AdInventory.cpp b/engines/wintermute/ad/AdInventory.cpp index 54195cc68a..f913108404 100644 --- a/engines/wintermute/ad/AdInventory.cpp +++ b/engines/wintermute/ad/AdInventory.cpp @@ -29,7 +29,7 @@ #include "engines/wintermute/ad/AdInventory.h" #include "engines/wintermute/ad/AdGame.h" #include "engines/wintermute/ad/AdItem.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" namespace WinterMute { diff --git a/engines/wintermute/ad/AdInventoryBox.cpp b/engines/wintermute/ad/AdInventoryBox.cpp index c5c9c3be67..9509bf9b10 100644 --- a/engines/wintermute/ad/AdInventoryBox.cpp +++ b/engines/wintermute/ad/AdInventoryBox.cpp @@ -37,7 +37,7 @@ #include "engines/wintermute/base/BDynBuffer.h" #include "engines/wintermute/ui/UIButton.h" #include "engines/wintermute/ui/UIWindow.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" #include "common/rect.h" diff --git a/engines/wintermute/ad/AdItem.cpp b/engines/wintermute/ad/AdItem.cpp index 5678f6cfa6..0e443d5c3e 100644 --- a/engines/wintermute/ad/AdItem.cpp +++ b/engines/wintermute/ad/AdItem.cpp @@ -38,7 +38,7 @@ #include "engines/wintermute/base/BSound.h" #include "engines/wintermute/base/BSprite.h" #include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/base/scriptables/ScScript.h" #include "engines/wintermute/base/scriptables/ScStack.h" #include "engines/wintermute/base/scriptables/ScValue.h" diff --git a/engines/wintermute/ad/AdLayer.cpp b/engines/wintermute/ad/AdLayer.cpp index d797172338..4549ba4af7 100644 --- a/engines/wintermute/ad/AdLayer.cpp +++ b/engines/wintermute/ad/AdLayer.cpp @@ -36,7 +36,7 @@ #include "engines/wintermute/base/scriptables/ScScript.h" #include "engines/wintermute/base/scriptables/ScStack.h" #include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" namespace WinterMute { diff --git a/engines/wintermute/ad/AdNodeState.cpp b/engines/wintermute/ad/AdNodeState.cpp index 8e9894b5f5..fd72a356c5 100644 --- a/engines/wintermute/ad/AdNodeState.cpp +++ b/engines/wintermute/ad/AdNodeState.cpp @@ -33,7 +33,7 @@ #include "engines/wintermute/base/BStringTable.h" #include "engines/wintermute/base/BSprite.h" #include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" namespace WinterMute { diff --git a/engines/wintermute/ad/AdResponseBox.cpp b/engines/wintermute/ad/AdResponseBox.cpp index 1a1732edd0..829d58f2ee 100644 --- a/engines/wintermute/ad/AdResponseBox.cpp +++ b/engines/wintermute/ad/AdResponseBox.cpp @@ -42,7 +42,7 @@ #include "engines/wintermute/base/BSprite.h" #include "engines/wintermute/base/BFileManager.h" #include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" namespace WinterMute { diff --git a/engines/wintermute/ad/AdScene.cpp b/engines/wintermute/ad/AdScene.cpp index 022ec4a8a5..b284543a08 100644 --- a/engines/wintermute/ad/AdScene.cpp +++ b/engines/wintermute/ad/AdScene.cpp @@ -52,7 +52,7 @@ #include "engines/wintermute/base/BScriptable.h" #include "engines/wintermute/base/BSprite.h" #include "engines/wintermute/base/BViewport.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/base/scriptables/ScStack.h" #include "engines/wintermute/base/scriptables/ScValue.h" #include "engines/wintermute/base/scriptables/ScScript.h" diff --git a/engines/wintermute/ad/AdSceneState.cpp b/engines/wintermute/ad/AdSceneState.cpp index 2192bc13fe..5dfb8c537e 100644 --- a/engines/wintermute/ad/AdSceneState.cpp +++ b/engines/wintermute/ad/AdSceneState.cpp @@ -30,7 +30,7 @@ #include "engines/wintermute/persistent.h" #include "engines/wintermute/ad/AdSceneState.h" #include "engines/wintermute/ad/AdNodeState.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" namespace WinterMute { diff --git a/engines/wintermute/ad/AdTalkHolder.cpp b/engines/wintermute/ad/AdTalkHolder.cpp index 4c627ca9ad..e1a91792ce 100644 --- a/engines/wintermute/ad/AdTalkHolder.cpp +++ b/engines/wintermute/ad/AdTalkHolder.cpp @@ -34,7 +34,7 @@ #include "engines/wintermute/base/scriptables/ScStack.h" #include "engines/wintermute/base/BGame.h" #include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/PlatformSDL.h" +#include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/wintermute.h" #include "common/str.h" -- cgit v1.2.3 From 5683f076331d2831eb4720b65bb53e8d01ca33ee Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 21 Jul 2012 18:19:07 +0200 Subject: WINTERMUTE: Rename CamelCased filenames to prefixed_under_score-filenames This is mostly a lead-up to namespacing the Ad/Base folders, and then possibly removing the prefixes from the files, it also has the added benefit of getting rid of the odd case-typos that makes for issues on platforms that don't ignore case. --- engines/wintermute/ad/AdActor.cpp | 1316 ------------ engines/wintermute/ad/AdActor.h | 107 - engines/wintermute/ad/AdEntity.cpp | 1027 --------- engines/wintermute/ad/AdEntity.h | 68 - engines/wintermute/ad/AdGame.cpp | 2061 ------------------ engines/wintermute/ad/AdGame.h | 161 -- engines/wintermute/ad/AdInventory.cpp | 119 -- engines/wintermute/ad/AdInventory.h | 52 - engines/wintermute/ad/AdInventoryBox.cpp | 372 ---- engines/wintermute/ad/AdInventoryBox.h | 64 - engines/wintermute/ad/AdItem.cpp | 760 ------- engines/wintermute/ad/AdItem.h | 70 - engines/wintermute/ad/AdLayer.cpp | 537 ----- engines/wintermute/ad/AdLayer.h | 58 - engines/wintermute/ad/AdNodeState.cpp | 169 -- engines/wintermute/ad/AdNodeState.h | 58 - engines/wintermute/ad/AdObject.cpp | 1203 ----------- engines/wintermute/ad/AdObject.h | 123 -- engines/wintermute/ad/AdPath.cpp | 112 - engines/wintermute/ad/AdPath.h | 56 - engines/wintermute/ad/AdPathPoint.cpp | 75 - engines/wintermute/ad/AdPathPoint.h | 50 - engines/wintermute/ad/AdRegion.cpp | 392 ---- engines/wintermute/ad/AdRegion.h | 58 - engines/wintermute/ad/AdResponse.cpp | 143 -- engines/wintermute/ad/AdResponse.h | 61 - engines/wintermute/ad/AdResponseBox.cpp | 647 ------ engines/wintermute/ad/AdResponseBox.h | 87 - engines/wintermute/ad/AdResponseContext.cpp | 70 - engines/wintermute/ad/AdResponseContext.h | 50 - engines/wintermute/ad/AdRotLevel.cpp | 159 -- engines/wintermute/ad/AdRotLevel.h | 49 - engines/wintermute/ad/AdScaleLevel.cpp | 157 -- engines/wintermute/ad/AdScaleLevel.h | 50 - engines/wintermute/ad/AdScene.cpp | 2752 ------------------------- engines/wintermute/ad/AdScene.h | 181 -- engines/wintermute/ad/AdSceneNode.cpp | 83 - engines/wintermute/ad/AdSceneNode.h | 54 - engines/wintermute/ad/AdSceneState.cpp | 88 - engines/wintermute/ad/AdSceneState.h | 51 - engines/wintermute/ad/AdSentence.cpp | 317 --- engines/wintermute/ad/AdSentence.h | 85 - engines/wintermute/ad/AdSpriteSet.cpp | 312 --- engines/wintermute/ad/AdSpriteSet.h | 54 - engines/wintermute/ad/AdTalkDef.cpp | 260 --- engines/wintermute/ad/AdTalkDef.h | 58 - engines/wintermute/ad/AdTalkHolder.cpp | 366 ---- engines/wintermute/ad/AdTalkHolder.h | 57 - engines/wintermute/ad/AdTalkNode.cpp | 266 --- engines/wintermute/ad/AdTalkNode.h | 63 - engines/wintermute/ad/AdTypes.h | 107 - engines/wintermute/ad/AdWaypointGroup.cpp | 261 --- engines/wintermute/ad/AdWaypointGroup.h | 58 - engines/wintermute/ad/ad_actor.cpp | 1316 ++++++++++++ engines/wintermute/ad/ad_actor.h | 107 + engines/wintermute/ad/ad_entity.cpp | 1027 +++++++++ engines/wintermute/ad/ad_entity.h | 68 + engines/wintermute/ad/ad_game.cpp | 2061 ++++++++++++++++++ engines/wintermute/ad/ad_game.h | 161 ++ engines/wintermute/ad/ad_inventory.cpp | 119 ++ engines/wintermute/ad/ad_inventory.h | 52 + engines/wintermute/ad/ad_inventory_box.cpp | 372 ++++ engines/wintermute/ad/ad_inventory_box.h | 64 + engines/wintermute/ad/ad_item.cpp | 760 +++++++ engines/wintermute/ad/ad_item.h | 70 + engines/wintermute/ad/ad_layer.cpp | 537 +++++ engines/wintermute/ad/ad_layer.h | 58 + engines/wintermute/ad/ad_node_state.cpp | 169 ++ engines/wintermute/ad/ad_node_state.h | 58 + engines/wintermute/ad/ad_object.cpp | 1203 +++++++++++ engines/wintermute/ad/ad_object.h | 123 ++ engines/wintermute/ad/ad_path.cpp | 112 + engines/wintermute/ad/ad_path.h | 56 + engines/wintermute/ad/ad_path_point.cpp | 75 + engines/wintermute/ad/ad_path_point.h | 50 + engines/wintermute/ad/ad_region.cpp | 392 ++++ engines/wintermute/ad/ad_region.h | 58 + engines/wintermute/ad/ad_response.cpp | 143 ++ engines/wintermute/ad/ad_response.h | 61 + engines/wintermute/ad/ad_response_box.cpp | 647 ++++++ engines/wintermute/ad/ad_response_box.h | 87 + engines/wintermute/ad/ad_response_context.cpp | 70 + engines/wintermute/ad/ad_response_context.h | 50 + engines/wintermute/ad/ad_rot_level.cpp | 159 ++ engines/wintermute/ad/ad_rot_level.h | 49 + engines/wintermute/ad/ad_scale_level.cpp | 157 ++ engines/wintermute/ad/ad_scale_level.h | 50 + engines/wintermute/ad/ad_scene.cpp | 2752 +++++++++++++++++++++++++ engines/wintermute/ad/ad_scene.h | 181 ++ engines/wintermute/ad/ad_scene_node.cpp | 83 + engines/wintermute/ad/ad_scene_node.h | 54 + engines/wintermute/ad/ad_scene_state.cpp | 88 + engines/wintermute/ad/ad_scene_state.h | 51 + engines/wintermute/ad/ad_sentence.cpp | 317 +++ engines/wintermute/ad/ad_sentence.h | 85 + engines/wintermute/ad/ad_sprite_set.cpp | 312 +++ engines/wintermute/ad/ad_sprite_set.h | 54 + engines/wintermute/ad/ad_talk_def.cpp | 260 +++ engines/wintermute/ad/ad_talk_def.h | 58 + engines/wintermute/ad/ad_talk_holder.cpp | 366 ++++ engines/wintermute/ad/ad_talk_holder.h | 57 + engines/wintermute/ad/ad_talk_node.cpp | 266 +++ engines/wintermute/ad/ad_talk_node.h | 63 + engines/wintermute/ad/ad_types.h | 107 + engines/wintermute/ad/ad_waypoint_group.cpp | 261 +++ engines/wintermute/ad/ad_waypoint_group.h | 58 + 106 files changed, 16014 insertions(+), 16014 deletions(-) delete mode 100644 engines/wintermute/ad/AdActor.cpp delete mode 100644 engines/wintermute/ad/AdActor.h delete mode 100644 engines/wintermute/ad/AdEntity.cpp delete mode 100644 engines/wintermute/ad/AdEntity.h delete mode 100644 engines/wintermute/ad/AdGame.cpp delete mode 100644 engines/wintermute/ad/AdGame.h delete mode 100644 engines/wintermute/ad/AdInventory.cpp delete mode 100644 engines/wintermute/ad/AdInventory.h delete mode 100644 engines/wintermute/ad/AdInventoryBox.cpp delete mode 100644 engines/wintermute/ad/AdInventoryBox.h delete mode 100644 engines/wintermute/ad/AdItem.cpp delete mode 100644 engines/wintermute/ad/AdItem.h delete mode 100644 engines/wintermute/ad/AdLayer.cpp delete mode 100644 engines/wintermute/ad/AdLayer.h delete mode 100644 engines/wintermute/ad/AdNodeState.cpp delete mode 100644 engines/wintermute/ad/AdNodeState.h delete mode 100644 engines/wintermute/ad/AdObject.cpp delete mode 100644 engines/wintermute/ad/AdObject.h delete mode 100644 engines/wintermute/ad/AdPath.cpp delete mode 100644 engines/wintermute/ad/AdPath.h delete mode 100644 engines/wintermute/ad/AdPathPoint.cpp delete mode 100644 engines/wintermute/ad/AdPathPoint.h delete mode 100644 engines/wintermute/ad/AdRegion.cpp delete mode 100644 engines/wintermute/ad/AdRegion.h delete mode 100644 engines/wintermute/ad/AdResponse.cpp delete mode 100644 engines/wintermute/ad/AdResponse.h delete mode 100644 engines/wintermute/ad/AdResponseBox.cpp delete mode 100644 engines/wintermute/ad/AdResponseBox.h delete mode 100644 engines/wintermute/ad/AdResponseContext.cpp delete mode 100644 engines/wintermute/ad/AdResponseContext.h delete mode 100644 engines/wintermute/ad/AdRotLevel.cpp delete mode 100644 engines/wintermute/ad/AdRotLevel.h delete mode 100644 engines/wintermute/ad/AdScaleLevel.cpp delete mode 100644 engines/wintermute/ad/AdScaleLevel.h delete mode 100644 engines/wintermute/ad/AdScene.cpp delete mode 100644 engines/wintermute/ad/AdScene.h delete mode 100644 engines/wintermute/ad/AdSceneNode.cpp delete mode 100644 engines/wintermute/ad/AdSceneNode.h delete mode 100644 engines/wintermute/ad/AdSceneState.cpp delete mode 100644 engines/wintermute/ad/AdSceneState.h delete mode 100644 engines/wintermute/ad/AdSentence.cpp delete mode 100644 engines/wintermute/ad/AdSentence.h delete mode 100644 engines/wintermute/ad/AdSpriteSet.cpp delete mode 100644 engines/wintermute/ad/AdSpriteSet.h delete mode 100644 engines/wintermute/ad/AdTalkDef.cpp delete mode 100644 engines/wintermute/ad/AdTalkDef.h delete mode 100644 engines/wintermute/ad/AdTalkHolder.cpp delete mode 100644 engines/wintermute/ad/AdTalkHolder.h delete mode 100644 engines/wintermute/ad/AdTalkNode.cpp delete mode 100644 engines/wintermute/ad/AdTalkNode.h delete mode 100644 engines/wintermute/ad/AdTypes.h delete mode 100644 engines/wintermute/ad/AdWaypointGroup.cpp delete mode 100644 engines/wintermute/ad/AdWaypointGroup.h create mode 100644 engines/wintermute/ad/ad_actor.cpp create mode 100644 engines/wintermute/ad/ad_actor.h create mode 100644 engines/wintermute/ad/ad_entity.cpp create mode 100644 engines/wintermute/ad/ad_entity.h create mode 100644 engines/wintermute/ad/ad_game.cpp create mode 100644 engines/wintermute/ad/ad_game.h create mode 100644 engines/wintermute/ad/ad_inventory.cpp create mode 100644 engines/wintermute/ad/ad_inventory.h create mode 100644 engines/wintermute/ad/ad_inventory_box.cpp create mode 100644 engines/wintermute/ad/ad_inventory_box.h create mode 100644 engines/wintermute/ad/ad_item.cpp create mode 100644 engines/wintermute/ad/ad_item.h create mode 100644 engines/wintermute/ad/ad_layer.cpp create mode 100644 engines/wintermute/ad/ad_layer.h create mode 100644 engines/wintermute/ad/ad_node_state.cpp create mode 100644 engines/wintermute/ad/ad_node_state.h create mode 100644 engines/wintermute/ad/ad_object.cpp create mode 100644 engines/wintermute/ad/ad_object.h create mode 100644 engines/wintermute/ad/ad_path.cpp create mode 100644 engines/wintermute/ad/ad_path.h create mode 100644 engines/wintermute/ad/ad_path_point.cpp create mode 100644 engines/wintermute/ad/ad_path_point.h create mode 100644 engines/wintermute/ad/ad_region.cpp create mode 100644 engines/wintermute/ad/ad_region.h create mode 100644 engines/wintermute/ad/ad_response.cpp create mode 100644 engines/wintermute/ad/ad_response.h create mode 100644 engines/wintermute/ad/ad_response_box.cpp create mode 100644 engines/wintermute/ad/ad_response_box.h create mode 100644 engines/wintermute/ad/ad_response_context.cpp create mode 100644 engines/wintermute/ad/ad_response_context.h create mode 100644 engines/wintermute/ad/ad_rot_level.cpp create mode 100644 engines/wintermute/ad/ad_rot_level.h create mode 100644 engines/wintermute/ad/ad_scale_level.cpp create mode 100644 engines/wintermute/ad/ad_scale_level.h create mode 100644 engines/wintermute/ad/ad_scene.cpp create mode 100644 engines/wintermute/ad/ad_scene.h create mode 100644 engines/wintermute/ad/ad_scene_node.cpp create mode 100644 engines/wintermute/ad/ad_scene_node.h create mode 100644 engines/wintermute/ad/ad_scene_state.cpp create mode 100644 engines/wintermute/ad/ad_scene_state.h create mode 100644 engines/wintermute/ad/ad_sentence.cpp create mode 100644 engines/wintermute/ad/ad_sentence.h create mode 100644 engines/wintermute/ad/ad_sprite_set.cpp create mode 100644 engines/wintermute/ad/ad_sprite_set.h create mode 100644 engines/wintermute/ad/ad_talk_def.cpp create mode 100644 engines/wintermute/ad/ad_talk_def.h create mode 100644 engines/wintermute/ad/ad_talk_holder.cpp create mode 100644 engines/wintermute/ad/ad_talk_holder.h create mode 100644 engines/wintermute/ad/ad_talk_node.cpp create mode 100644 engines/wintermute/ad/ad_talk_node.h create mode 100644 engines/wintermute/ad/ad_types.h create mode 100644 engines/wintermute/ad/ad_waypoint_group.cpp create mode 100644 engines/wintermute/ad/ad_waypoint_group.h (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/AdActor.cpp b/engines/wintermute/ad/AdActor.cpp deleted file mode 100644 index 050a419e53..0000000000 --- a/engines/wintermute/ad/AdActor.cpp +++ /dev/null @@ -1,1316 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/dctypes.h" -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/BObject.h" -#include "engines/wintermute/ad/AdActor.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdScene.h" -#include "engines/wintermute/ad/AdEntity.h" -#include "engines/wintermute/ad/AdSpriteSet.h" -#include "engines/wintermute/ad/AdWaypointGroup.h" -#include "engines/wintermute/ad/AdPath.h" -#include "engines/wintermute/ad/AdSentence.h" -#include "engines/wintermute/base/BObject.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BSound.h" -#include "engines/wintermute/base/BRegion.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/wintermute.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdActor, false) - - -////////////////////////////////////////////////////////////////////////// -CAdActor::CAdActor(CBGame *inGame): CAdTalkHolder(inGame) { - _path = new CAdPath(_gameRef); - - _type = OBJECT_ACTOR; - _dir = DI_LEFT; - - _walkSprite = NULL; - _standSprite = NULL; - _turnLeftSprite = NULL; - _turnRightSprite = NULL; - - _targetPoint = new CBPoint; - _afterWalkDir = DI_NONE; - - _animSprite2 = NULL; - - setDefaultAnimNames(); -} - -////////////////////////////////////////////////////////////////////////// -bool CAdActor::setDefaultAnimNames() { - _talkAnimName = "talk"; - _idleAnimName = "idle"; - _walkAnimName = "walk"; - _turnLeftAnimName = "turnleft"; - _turnRightAnimName = "turnright"; - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -CAdActor::~CAdActor() { - delete _path; - delete _targetPoint; - _path = NULL; - _targetPoint = NULL; - - delete _walkSprite; - delete _standSprite; - delete _turnLeftSprite; - delete _turnRightSprite; - _walkSprite = NULL; - _standSprite = NULL; - _turnLeftSprite = NULL; - _turnRightSprite = NULL; - - _animSprite2 = NULL; // ref only - - for (int i = 0; i < _talkSprites.getSize(); i++) { - delete _talkSprites[i]; - } - _talkSprites.removeAll(); - - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - delete _talkSpritesEx[i]; - } - _talkSpritesEx.removeAll(); - - for (int i = 0; i < _anims.getSize(); i++) { - delete _anims[i]; - _anims[i] = NULL; - } - _anims.removeAll(); - -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdActor::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdActor::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(ACTOR) -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(WALK) -TOKEN_DEF(STAND) -TOKEN_DEF(TALK_SPECIAL) -TOKEN_DEF(TALK) -TOKEN_DEF(TURN_LEFT) -TOKEN_DEF(TURN_RIGHT) -TOKEN_DEF(EVENTS) -TOKEN_DEF(FONT) -TOKEN_DEF(CURSOR) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(SOUND_VOLUME) -TOKEN_DEF(SOUND_PANNING) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(BLOCKED_REGION) -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(ANIMATION) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdActor::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ACTOR) - 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(WALK) - TOKEN_TABLE(STAND) - TOKEN_TABLE(TALK_SPECIAL) - TOKEN_TABLE(TALK) - TOKEN_TABLE(TURN_LEFT) - TOKEN_TABLE(TURN_RIGHT) - TOKEN_TABLE(EVENTS) - TOKEN_TABLE(FONT) - TOKEN_TABLE(CURSOR) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(SOUND_VOLUME) - TOKEN_TABLE(SOUND_PANNING) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(BLOCKED_REGION) - 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(ANIMATION) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTOR) { - _gameRef->LOG(0, "'ACTOR' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - CAdGame *adGame = (CAdGame *)_gameRef; - CAdSpriteSet *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 (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_X: - parser.scanStr((char *)params, "%d", &_posX); - break; - - case TOKEN_Y: - parser.scanStr((char *)params, "%d", &_posY); - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_FONT: - SetFont((char *)params); - break; - - case TOKEN_SCALABLE: - parser.scanStr((char *)params, "%b", &_zoomable); - break; - - case TOKEN_ROTABLE: - case TOKEN_ROTATABLE: - parser.scanStr((char *)params, "%b", &_rotatable); - break; - - case TOKEN_REGISTRABLE: - case TOKEN_INTERACTIVE: - parser.scanStr((char *)params, "%b", &_registrable); - break; - - case TOKEN_SHADOWABLE: - case TOKEN_COLORABLE: - parser.scanStr((char *)params, "%b", &_shadowable); - break; - - case TOKEN_ACTIVE: - parser.scanStr((char *)params, "%b", &_active); - break; - - case TOKEN_WALK: - delete _walkSprite; - _walkSprite = NULL; - spr = new CAdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC; - else _walkSprite = spr; - break; - - case TOKEN_TALK: - spr = new CAdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); - break; - - case TOKEN_TALK_SPECIAL: - spr = new CAdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); - break; - - case TOKEN_STAND: - delete _standSprite; - _standSprite = NULL; - spr = new CAdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) cmd = PARSERR_GENERIC; - else _standSprite = spr; - break; - - case TOKEN_TURN_LEFT: - delete _turnLeftSprite; - _turnLeftSprite = NULL; - spr = new CAdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; - else _turnLeftSprite = spr; - break; - - case TOKEN_TURN_RIGHT: - delete _turnRightSprite; - _turnRightSprite = NULL; - spr = new CAdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; - else _turnRightSprite = spr; - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_CURSOR: - delete _cursor; - _cursor = new CBSprite(_gameRef); - if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { - delete _cursor; - _cursor = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_SOUND_VOLUME: - parser.scanStr((char *)params, "%d", &_sFXVolume); - break; - - case TOKEN_SCALE: { - int s; - parser.scanStr((char *)params, "%d", &s); - _scale = (float)s; - - } - break; - - case TOKEN_RELATIVE_SCALE: { - int s; - parser.scanStr((char *)params, "%d", &s); - _relativeScale = (float)s; - - } - break; - - case TOKEN_SOUND_PANNING: - parser.scanStr((char *)params, "%b", &_autoSoundPanning); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_BLOCKED_REGION: { - delete _blockRegion; - delete _currentBlockRegion; - _blockRegion = NULL; - _currentBlockRegion = NULL; - CBRegion *rgn = new CBRegion(_gameRef); - CBRegion *crgn = new CBRegion(_gameRef); - if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { - delete _blockRegion; - delete _currentBlockRegion; - _blockRegion = NULL; - _currentBlockRegion = NULL; - cmd = PARSERR_GENERIC; - } else { - _blockRegion = rgn; - _currentBlockRegion = crgn; - _currentBlockRegion->mimic(_blockRegion); - } - } - break; - - case TOKEN_WAYPOINTS: { - delete _wptGroup; - delete _currentWptGroup; - _wptGroup = NULL; - _currentWptGroup = NULL; - CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); - CAdWaypointGroup *cwpt = new CAdWaypointGroup(_gameRef); - if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { - delete _wptGroup; - delete _currentWptGroup; - _wptGroup = NULL; - _currentWptGroup = NULL; - cmd = PARSERR_GENERIC; - } else { - _wptGroup = wpt; - _currentWptGroup = cwpt; - _currentWptGroup->mimic(_wptGroup); - } - } - break; - - case TOKEN_IGNORE_ITEMS: - parser.scanStr((char *)params, "%b", &_ignoreItems); - 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_ANIMATION: { - CAdSpriteSet *Anim = new CAdSpriteSet(_gameRef, this); - if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) cmd = PARSERR_GENERIC; - else _anims.add(Anim); - } - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ACTOR definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - if (spr) delete spr; - _gameRef->LOG(0, "Error loading ACTOR definition"); - return STATUS_FAILED; - } - - if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { - ar = ag = ab = 255; - } - _alphaColor = BYTETORGBA(ar, ag, ab, alpha); - _state = _nextState = STATE_READY; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdActor::turnTo(TDirection dir) { - int delta1, delta2, delta3, delta; - - delta1 = dir - _dir; - delta2 = dir + NUM_DIRECTIONS - _dir; - delta3 = dir - NUM_DIRECTIONS - _dir; - - delta1 = (abs(delta1) <= abs(delta2)) ? delta1 : delta2; - delta = (abs(delta1) <= abs(delta3)) ? delta1 : delta3; - - // already there? - if (abs(delta) < 2) { - _dir = dir; - _state = _nextState; - _nextState = STATE_READY; - return; - } - - _targetDir = dir; - _state = delta < 0 ? STATE_TURNING_LEFT : STATE_TURNING_RIGHT; - - _tempSprite2 = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdActor::goTo(int x, int y, TDirection afterWalkDir) { - _afterWalkDir = afterWalkDir; - if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) return; - - _path->reset(); - _path->setReady(false); - - _targetPoint->x = x; - _targetPoint->y = y; - - ((CAdGame *)_gameRef)->_scene->correctTargetPoint(_posX, _posY, &_targetPoint->x, &_targetPoint->y, true, this); - - _state = STATE_SEARCHING_PATH; - -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdActor::display() { - if (_active) updateSounds(); - - uint32 alpha; - if (_alphaColor != 0) alpha = _alphaColor; - else alpha = _shadowable ? ((CAdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; - - float scaleX, scaleY; - getScale(&scaleX, &scaleY); - - - float rotate; - if (_rotatable) { - if (_rotateValid) rotate = _rotate; - else rotate = ((CAdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; - } else rotate = 0.0f; - - if (_active) displaySpriteAttachments(true); - - if (_currentSprite && _active) { - bool reg = _registrable; - if (_ignoreItems && ((CAdGame *)_gameRef)->_selectedItem) reg = false; - - _currentSprite->display(_posX, - _posY, - reg ? _registerAlias : NULL, - scaleX, - scaleY, - alpha, - rotate, - _blendMode); - - } - - if (_active) displaySpriteAttachments(false); - if (_active && _partEmitter) _partEmitter->display(); - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdActor::update() { - _currentSprite = NULL; - - if (_state == STATE_READY) { - if (_animSprite) { - delete _animSprite; - _animSprite = NULL; - } - if (_animSprite2) { - _animSprite2 = NULL; - } - } - - // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { - _state = _nextState; - _nextState = STATE_READY; - _currentSprite = _animSprite; - } - - if (_state == STATE_PLAYING_ANIM_SET && _animSprite2 != NULL && _animSprite2->_finished) { - _state = _nextState; - _nextState = STATE_READY; - _currentSprite = _animSprite2; - } - - if (_sentence && _state != STATE_TALKING) _sentence->finish(); - - // default: stand animation - if (!_currentSprite) { - if (_sprite) _currentSprite = _sprite; - else { - if (_standSprite) { - _currentSprite = _standSprite->getSprite(_dir); - } else { - CAdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); - } - } - } - - bool already_moved = false; - - switch (_state) { - ////////////////////////////////////////////////////////////////////////// - case STATE_PLAYING_ANIM: - _currentSprite = _animSprite; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_PLAYING_ANIM_SET: - _currentSprite = _animSprite2; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_TURNING_LEFT: - if (_tempSprite2 == NULL || _tempSprite2->_finished) { - if (_dir > 0) _dir = (TDirection)(_dir - 1); - else _dir = (TDirection)(NUM_DIRECTIONS - 1); - - if (_dir == _targetDir) { - _tempSprite2 = NULL; - _state = _nextState; - _nextState = STATE_READY; - } else { - if (_turnLeftSprite) { - _tempSprite2 = _turnLeftSprite->getSprite(_dir); - } else { - CAdSpriteSet *Anim = getAnimByName(_turnLeftAnimName); - if (Anim) _tempSprite2 = Anim->getSprite(_dir); - } - - if (_tempSprite2) { - _tempSprite2->reset(); - if (_tempSprite2->_looping) _tempSprite2->_looping = false; - } - _currentSprite = _tempSprite2; - } - } else _currentSprite = _tempSprite2; - break; - - - ////////////////////////////////////////////////////////////////////////// - case STATE_TURNING_RIGHT: - if (_tempSprite2 == NULL || _tempSprite2->_finished) { - _dir = (TDirection)(_dir + 1); - - if ((int)_dir >= (int)NUM_DIRECTIONS) _dir = (TDirection)(0); - - if (_dir == _targetDir) { - _tempSprite2 = NULL; - _state = _nextState; - _nextState = STATE_READY; - } else { - if (_turnRightSprite) { - _tempSprite2 = _turnRightSprite->getSprite(_dir); - } else { - CAdSpriteSet *Anim = getAnimByName(_turnRightAnimName); - if (Anim) _tempSprite2 = Anim->getSprite(_dir); - } - - if (_tempSprite2) { - _tempSprite2->reset(); - if (_tempSprite2->_looping) _tempSprite2->_looping = false; - } - _currentSprite = _tempSprite2; - } - } else _currentSprite = _tempSprite2; - break; - - - ////////////////////////////////////////////////////////////////////////// - case STATE_SEARCHING_PATH: - // keep asking scene for the path - if (((CAdGame *)_gameRef)->_scene->getPath(CBPoint(_posX, _posY), *_targetPoint, _path, this)) - _state = STATE_WAITING_PATH; - break; - - - ////////////////////////////////////////////////////////////////////////// - case STATE_WAITING_PATH: - // wait until the scene finished the path - if (_path->_ready) followPath(); - break; - - - ////////////////////////////////////////////////////////////////////////// - case STATE_FOLLOWING_PATH: - getNextStep(); - already_moved = true; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_TALKING: { - _sentence->update(_dir); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; - - bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { - if (TimeIsUp) { - _sentence->finish(); - _tempSprite2 = NULL; - _state = _nextState; - _nextState = STATE_READY; - } else { - _tempSprite2 = getTalkStance(_sentence->getNextStance()); - if (_tempSprite2) { - _tempSprite2->reset(); - _currentSprite = _tempSprite2; - ((CAdGame *)_gameRef)->addSentence(_sentence); - } - } - } else { - _currentSprite = _tempSprite2; - ((CAdGame *)_gameRef)->addSentence(_sentence); - } - } - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_READY: - if (!_animSprite && !_animSprite2) { - if (_sprite) _currentSprite = _sprite; - else { - if (_standSprite) { - _currentSprite = _standSprite->getSprite(_dir); - } else { - CAdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); - } - } - } - break; - default: - error("AdActor::Update - Unhandled enum"); - } - - - if (_currentSprite && !already_moved) { - _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (_currentSprite->_changed) { - _posX += _currentSprite->_moveX; - _posY += _currentSprite->_moveY; - afterMove(); - } - } - - //_gameRef->QuickMessageForm("%s", _currentSprite->_filename); - - updateBlockRegion(); - _ready = (_state == STATE_READY); - - updatePartEmitter(); - updateSpriteAttachments(); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdActor::followPath() { - // skip current position - _path->getFirst(); - while (_path->getCurrent() != NULL) { - if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) break; - _path->getNext(); - } - - // are there points to follow? - if (_path->getCurrent() != NULL) { - _state = STATE_FOLLOWING_PATH;; - initLine(CBPoint(_posX, _posY), *_path->getCurrent()); - } else { - if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); - else _state = STATE_READY; - } -} - - -////////////////////////////////////////////////////////////////////////// -void CAdActor::getNextStep() { - if (_walkSprite) { - _currentSprite = _walkSprite->getSprite(_dir); - } else { - CAdSpriteSet *Anim = getAnimByName(_walkAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); - } - - if (!_currentSprite) return; - - _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (!_currentSprite->_changed) return; - - - int maxStepX, maxStepY; - maxStepX = abs(_currentSprite->_moveX); - maxStepY = abs(_currentSprite->_moveY); - - maxStepX = MAX(maxStepX, maxStepY); - maxStepX = MAX(maxStepX, 1); - - while (_pFCount > 0 && maxStepX >= 0) { - _pFX += _pFStepX; - _pFY += _pFStepY; - - _pFCount--; - maxStepX--; - } - - if (((CAdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX,(int) _pFY, true, this)) { - if (_pFCount == 0) { - _state = _nextState; - _nextState = STATE_READY; - return; - } - goTo(_targetPoint->x, _targetPoint->y); - return; - } - - - _posX = (int)_pFX; - _posY = (int)_pFY; - - afterMove(); - - - if (_pFCount == 0) { - if (_path->getNext() == NULL) { - _posX = _targetPoint->x; - _posY = _targetPoint->y; - - _path->reset(); - if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); - else { - _state = _nextState; - _nextState = STATE_READY; - } - } else initLine(CBPoint(_posX, _posY), *_path->getCurrent()); - } -} - - -////////////////////////////////////////////////////////////////////////// -void CAdActor::initLine(CBPoint startPt, CBPoint endPt) { - _pFCount = MAX((abs(endPt.x - startPt.x)) , (abs(endPt.y - startPt.y))); - - _pFStepX = (double)(endPt.x - startPt.x) / _pFCount; - _pFStepY = (double)(endPt.y - startPt.y) / _pFCount; - - _pFX = startPt.x; - _pFY = startPt.y; - - int angle = (int)(atan2((double)(endPt.y - startPt.y), (double)(endPt.x - startPt.x)) * (180 / 3.14)); - - _nextState = STATE_FOLLOWING_PATH; - - turnTo(angleToDirection(angle)); -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdActor::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // GoTo / GoToAsync - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "GoTo") == 0 || strcmp(name, "GoToAsync") == 0) { - stack->correctParams(2); - int X = stack->pop()->getInt(); - int Y = stack->pop()->getInt(); - goTo(X, Y); - if (strcmp(name, "GoToAsync") != 0) script->waitForExclusive(this); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GoToObject / GoToObjectAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GoToObject") == 0 || strcmp(name, "GoToObjectAsync") == 0) { - stack->correctParams(1); - CScValue *Val = stack->pop(); - if (!Val->isNative()) { - script->runtimeError("actor.%s method accepts an entity refrence only", name); - stack->pushNULL(); - return STATUS_OK; - } - CAdObject *Obj = (CAdObject *)Val->getNative(); - if (!Obj || Obj->_type != OBJECT_ENTITY) { - script->runtimeError("actor.%s method accepts an entity refrence only", name); - stack->pushNULL(); - return STATUS_OK; - } - CAdEntity *Ent = (CAdEntity *)Obj; - if (Ent->_walkToX == 0 && Ent->_walkToY == 0) goTo(Ent->_posX, Ent->_posY); - else goTo(Ent->_walkToX, Ent->_walkToY, Ent->_walkToDir); - if (strcmp(name, "GoToObjectAsync") != 0) script->waitForExclusive(this); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnTo / TurnToAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnTo") == 0 || strcmp(name, "TurnToAsync") == 0) { - stack->correctParams(1); - int dir; - CScValue *val = stack->pop(); - - // turn to object? - if (val->isNative() && _gameRef->validObject((CBObject *)val->getNative())) { - CBObject *obj = (CBObject *)val->getNative(); - int angle = (int)(atan2((double)(obj->_posY - _posY), (double)(obj->_posX - _posX)) * (180 / 3.14)); - dir = (int)angleToDirection(angle); - } - // otherwise turn to direction - else dir = val->getInt(); - - if (dir >= 0 && dir < NUM_DIRECTIONS) { - turnTo((TDirection)dir); - if (strcmp(name, "TurnToAsync") != 0) script->waitForExclusive(this); - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsWalking - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsWalking") == 0) { - stack->correctParams(0); - stack->pushBool(_state == STATE_FOLLOWING_PATH); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // MergeAnims - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MergeAnims") == 0) { - stack->correctParams(1); - stack->pushBool(DID_SUCCEED(mergeAnims(stack->pop()->getString()))); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // UnloadAnim - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "UnloadAnim") == 0) { - stack->correctParams(1); - const char *AnimName = stack->pop()->getString(); - - bool Found = false; - for (int i = 0; i < _anims.getSize(); i++) { - if (scumm_stricmp(_anims[i]->_name, AnimName) == 0) { - // invalidate sprites in use - if (_anims[i]->containsSprite(_tempSprite2)) _tempSprite2 = NULL; - if (_anims[i]->containsSprite(_currentSprite)) _currentSprite = NULL; - if (_anims[i]->containsSprite(_animSprite2)) _animSprite2 = NULL; - - delete _anims[i]; - _anims[i] = NULL; - _anims.removeAt(i); - i--; - Found = true; - } - } - stack->pushBool(Found); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // HasAnim - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "HasAnim") == 0) { - stack->correctParams(1); - const char *AnimName = stack->pop()->getString(); - stack->pushBool(getAnimByName(AnimName) != NULL); - return STATUS_OK; - } - - else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdActor::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Direction - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Direction") == 0) { - _scValue->setInt(_dir); - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Type") == 0) { - _scValue->setString("actor"); - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // TalkAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkAnimName") == 0) { - _scValue->setString(_talkAnimName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkAnimName") == 0) { - _scValue->setString(_walkAnimName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // IdleAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IdleAnimName") == 0) { - _scValue->setString(_idleAnimName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnLeftAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnLeftAnimName") == 0) { - _scValue->setString(_turnLeftAnimName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnRightAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnRightAnimName") == 0) { - _scValue->setString(_turnRightAnimName); - return _scValue; - } - - else return CAdTalkHolder::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdActor::scSetProperty(const char *name, CScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Direction - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Direction") == 0) { - int dir = value->getInt(); - if (dir >= 0 && dir < NUM_DIRECTIONS) _dir = (TDirection)dir; - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TalkAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkAnimName") == 0) { - if (value->isNULL()) _talkAnimName = "talk"; - else _talkAnimName = value->getString(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkAnimName") == 0) { - if (value->isNULL()) _walkAnimName = "walk"; - else _walkAnimName = value->getString(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IdleAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IdleAnimName") == 0) { - if (value->isNULL()) _idleAnimName = "idle"; - else _idleAnimName = value->getString(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnLeftAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnLeftAnimName") == 0) { - if (value->isNULL()) _turnLeftAnimName = "turnleft"; - else _turnLeftAnimName = value->getString(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnRightAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnRightAnimName") == 0) { - if (value->isNULL()) _turnRightAnimName = "turnright"; - else _turnRightAnimName = value->getString(); - return STATUS_OK; - } - - else return CAdTalkHolder::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *CAdActor::scToString() { - return "[actor object]"; -} - - -////////////////////////////////////////////////////////////////////////// -CBSprite *CAdActor::getTalkStance(const char *stance) { - // forced stance? - if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { - _forcedTalkAnimUsed = true; - delete _animSprite; - _animSprite = new CBSprite(_gameRef, this); - if (_animSprite) { - bool res = _animSprite->loadFile(_forcedTalkAnimName); - if (DID_FAIL(res)) { - _gameRef->LOG(res, "CAdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); - delete _animSprite; - _animSprite = NULL; - } else return _animSprite; - } - } - - // old way - if (_talkSprites.getSize() > 0 || _talkSpritesEx.getSize() > 0) - return getTalkStanceOld(stance); - - // new way - CBSprite *ret = NULL; - - // do we have an animation with this name? - CAdSpriteSet *Anim = getAnimByName(stance); - if (Anim) ret = Anim->getSprite(_dir); - - // not - get a random talk - if (!ret) { - CBArray TalkAnims; - for (int i = 0; i < _anims.getSize(); i++) { - if (_talkAnimName.compareToIgnoreCase(_anims[i]->_name) == 0) - TalkAnims.add(_anims[i]); - } - - if (TalkAnims.getSize() > 0) { - int rnd = g_wintermute->randInt(0, TalkAnims.getSize() - 1); - ret = TalkAnims[rnd]->getSprite(_dir); - } else { - if (_standSprite) ret = _standSprite->getSprite(_dir); - else { - Anim = getAnimByName(_idleAnimName); - if (Anim) ret = Anim->getSprite(_dir); - } - } - } - return ret; -} - -////////////////////////////////////////////////////////////////////////// -CBSprite *CAdActor::getTalkStanceOld(const char *stance) { - CBSprite *ret = NULL; - - if (stance != NULL) { - // search special stances - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->_name, stance) == 0) { - ret = _talkSpritesEx[i]->getSprite(_dir); - break; - } - } - if (ret == NULL) { - // search generic stances - for (int i = 0; i < _talkSprites.getSize(); i++) { - if (scumm_stricmp(_talkSprites[i]->_name, stance) == 0) { - ret = _talkSprites[i]->getSprite(_dir); - break; - } - } - } - } - - // not a valid stance? get a random one - if (ret == NULL) { - if (_talkSprites.getSize() < 1) ret = _standSprite->getSprite(_dir); - else { - // TODO: remember last - int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); - ret = _talkSprites[rnd]->getSprite(_dir); - } - } - - return ret; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdActor::persist(CBPersistMgr *persistMgr) { - CAdTalkHolder::persist(persistMgr); - - persistMgr->transfer(TMEMBER_INT(_dir)); - persistMgr->transfer(TMEMBER(_path)); - persistMgr->transfer(TMEMBER(_pFCount)); - persistMgr->transfer(TMEMBER(_pFStepX)); - persistMgr->transfer(TMEMBER(_pFStepY)); - persistMgr->transfer(TMEMBER(_pFX)); - persistMgr->transfer(TMEMBER(_pFY)); - persistMgr->transfer(TMEMBER(_standSprite)); - _talkSprites.persist(persistMgr); - _talkSpritesEx.persist(persistMgr); - persistMgr->transfer(TMEMBER_INT(_targetDir)); - persistMgr->transfer(TMEMBER_INT(_afterWalkDir)); - persistMgr->transfer(TMEMBER(_targetPoint)); - persistMgr->transfer(TMEMBER(_turnLeftSprite)); - persistMgr->transfer(TMEMBER(_turnRightSprite)); - persistMgr->transfer(TMEMBER(_walkSprite)); - - persistMgr->transfer(TMEMBER(_animSprite2)); - persistMgr->transfer(TMEMBER(_talkAnimName)); - persistMgr->transfer(TMEMBER(_idleAnimName)); - persistMgr->transfer(TMEMBER(_walkAnimName)); - persistMgr->transfer(TMEMBER(_turnLeftAnimName)); - persistMgr->transfer(TMEMBER(_turnRightAnimName)); - - _anims.persist(persistMgr); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -TDirection CAdActor::angleToDirection(int angle) { - TDirection ret = DI_DOWN;; - - if (angle > -112 && angle <= -67) ret = DI_UP; - else if (angle > -67 && angle <= -22) ret = DI_UPRIGHT; - else if (angle > -22 && angle <= 22) ret = DI_RIGHT; - else if (angle > 22 && angle <= 67) ret = DI_DOWNRIGHT; - else if (angle > 67 && angle <= 112) ret = DI_DOWN; - else if (angle > 112 && angle <= 157) ret = DI_DOWNLEFT; - else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) ret = DI_LEFT; - else if (angle > -157 && angle <= -112) ret = DI_UPLEFT; - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -int CAdActor::getHeight() { - // if no current sprite is set, set some - if (_currentSprite == NULL) { - if (_standSprite) _currentSprite = _standSprite->getSprite(_dir); - else { - CAdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); - } - } - // and get height - return CAdTalkHolder::getHeight(); -} - - -////////////////////////////////////////////////////////////////////////// -CAdSpriteSet *CAdActor::getAnimByName(const Common::String &animName) { - for (int i = 0; i < _anims.getSize(); i++) { - if (animName.compareToIgnoreCase(_anims[i]->_name) == 0) - return _anims[i]; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdActor::mergeAnims(const char *animsFilename) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ANIMATION) - TOKEN_TABLE_END - - - byte *fileBuffer = _gameRef->_fileManager->readWholeFile(animsFilename); - if (fileBuffer == NULL) { - _gameRef->LOG(0, "CAdActor::MergeAnims failed for file '%s'", animsFilename); - return STATUS_FAILED; - } - - byte *buffer = fileBuffer; - byte *params; - int cmd; - CBParser parser(_gameRef); - - bool Ret = STATUS_OK; - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_ANIMATION: { - CAdSpriteSet *Anim = new CAdSpriteSet(_gameRef, this); - if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - Ret = STATUS_FAILED; - } else _anims.add(Anim); - } - break; - } - } - delete [] fileBuffer; - return Ret; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdActor::playAnim(const char *filename) { - // if we have an anim with this name, use it - CAdSpriteSet *Anim = getAnimByName(filename); - if (Anim) { - _animSprite2 = Anim->getSprite(_dir); - if (_animSprite2) { - _animSprite2->reset(); - _state = STATE_PLAYING_ANIM_SET; - return STATUS_OK; - } - } - // otherwise call the standard handler - return CAdTalkHolder::playAnim(filename); -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdActor.h b/engines/wintermute/ad/AdActor.h deleted file mode 100644 index 1be8b8131d..0000000000 --- a/engines/wintermute/ad/AdActor.h +++ /dev/null @@ -1,107 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADACTOR_H -#define WINTERMUTE_ADACTOR_H - - -#include "engines/wintermute/dctypes.h" // Added by ClassView -#include "engines/wintermute/ad/AdTypes.h" // Added by ClassView -#include "engines/wintermute/ad/AdTalkHolder.h" -#include "engines/wintermute/base/BPoint.h" // Added by ClassView -#include "engines/wintermute/persistent.h" -#include "common/str.h" - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -namespace WinterMute { -class CAdSpriteSet; -class CAdPath; -class CAdActor : public CAdTalkHolder { -public: - TDirection angleToDirection(int angle); - DECLARE_PERSISTENT(CAdActor, CAdTalkHolder) - virtual int getHeight(); - CBSprite *getTalkStance(const char *stance); - virtual void goTo(int x, int y, TDirection afterWalkDir = DI_NONE); - CBPoint *_targetPoint; - virtual bool update(); - virtual bool display(); - TDirection _targetDir; - TDirection _afterWalkDir; - virtual void turnTo(TDirection dir); - CAdPath *_path; - CAdSpriteSet *_walkSprite; - CAdSpriteSet *_standSprite; - CAdSpriteSet *_turnLeftSprite; - CAdSpriteSet *_turnRightSprite; - CBArray _talkSprites; - CBArray _talkSpritesEx; - TDirection _dir; - CAdActor(CBGame *inGame/*=NULL*/); - virtual ~CAdActor(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - - // new anim system - Common::String _talkAnimName; - Common::String _idleAnimName; - Common::String _walkAnimName; - Common::String _turnLeftAnimName; - Common::String _turnRightAnimName; - CBArray _anims; - virtual bool playAnim(const char *filename); - CAdSpriteSet *getAnimByName(const Common::String &animName); - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - virtual const char *scToString(); - -private: - bool setDefaultAnimNames(); - CBSprite *getTalkStanceOld(const char *stance); - bool mergeAnims(const char *animsFilename); - CBSprite *_animSprite2; - - void initLine(CBPoint startPt, CBPoint endPt); - void getNextStep(); - void followPath(); - double _pFStepX; - double _pFStepY; - double _pFX; - double _pFY; - int _pFCount; -}; - -} // end of namespace WinterMute - -#endif // WINTERMUTE_ADACTOR_H diff --git a/engines/wintermute/ad/AdEntity.cpp b/engines/wintermute/ad/AdEntity.cpp deleted file mode 100644 index 49c723f66a..0000000000 --- a/engines/wintermute/ad/AdEntity.cpp +++ /dev/null @@ -1,1027 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - - - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdEntity.h" -#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" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdScene.h" -#include "engines/wintermute/base/BSound.h" -#include "engines/wintermute/ad/AdWaypointGroup.h" -#include "engines/wintermute/base/font/BFontStorage.h" -#include "engines/wintermute/base/font/BFont.h" -#include "engines/wintermute/ad/AdSentence.h" -#include "engines/wintermute/base/BRegion.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/video/VidTheoraPlayer.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdEntity, false) - -////////////////////////////////////////////////////////////////////////// -CAdEntity::CAdEntity(CBGame *inGame): CAdTalkHolder(inGame) { - _type = OBJECT_ENTITY; - _subtype = ENTITY_NORMAL; - _region = NULL; - _item = NULL; - - _walkToX = _walkToY = 0; - _walkToDir = DI_NONE; - - _theora = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdEntity::~CAdEntity() { - _gameRef->unregisterObject(_region); - - delete _theora; - _theora = NULL; - - delete[] _item; - _item = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdEntity::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdEntity::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->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 -////////////////////////////////////////////////////////////////////////// -bool 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(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY) { - _gameRef->LOG(0, "'ENTITY' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - CAdGame *adGame = (CAdGame *)_gameRef; - 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 (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_X: - parser.scanStr((char *)params, "%d", &_posX); - break; - - case TOKEN_Y: - parser.scanStr((char *)params, "%d", &_posY); - break; - - case TOKEN_SPRITE: { - delete _sprite; - _sprite = NULL; - spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params))) cmd = PARSERR_GENERIC; - else _sprite = spr; - } - break; - - case TOKEN_TALK: { - spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); - } - break; - - case TOKEN_TALK_SPECIAL: { - spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); - } - 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: - parser.scanStr((char *)params, "%b", &_zoomable); - break; - - case TOKEN_SCALE: { - int s; - parser.scanStr((char *)params, "%d", &s); - _scale = (float)s; - - } - break; - - case TOKEN_RELATIVE_SCALE: { - int s; - parser.scanStr((char *)params, "%d", &s); - _relativeScale = (float)s; - - } - break; - - case TOKEN_ROTABLE: - case TOKEN_ROTATABLE: - parser.scanStr((char *)params, "%b", &_rotatable); - break; - - case TOKEN_REGISTRABLE: - case TOKEN_INTERACTIVE: - parser.scanStr((char *)params, "%b", &_registrable); - break; - - case TOKEN_SHADOWABLE: - case TOKEN_COLORABLE: - parser.scanStr((char *)params, "%b", &_shadowable); - break; - - case TOKEN_ACTIVE: - parser.scanStr((char *)params, "%b", &_active); - break; - - case TOKEN_CURSOR: - delete _cursor; - _cursor = new CBSprite(_gameRef); - if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { - delete _cursor; - _cursor = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_EDITOR_SELECTED: - parser.scanStr((char *)params, "%b", &_editorSelected); - break; - - case TOKEN_REGION: { - if (_region) _gameRef->unregisterObject(_region); - _region = NULL; - CBRegion *rgn = new CBRegion(_gameRef); - if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) cmd = PARSERR_GENERIC; - else { - _region = rgn; - _gameRef->registerObject(_region); - } - } - break; - - case TOKEN_BLOCKED_REGION: { - delete _blockRegion; - _blockRegion = NULL; - delete _currentBlockRegion; - _currentBlockRegion = NULL; - CBRegion *rgn = new CBRegion(_gameRef); - CBRegion *crgn = new CBRegion(_gameRef); - if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { - delete _blockRegion; - _blockRegion = NULL; - delete _currentBlockRegion; - _currentBlockRegion = NULL; - cmd = PARSERR_GENERIC; - } else { - _blockRegion = rgn; - _currentBlockRegion = crgn; - _currentBlockRegion->mimic(_blockRegion); - } - } - break; - - case TOKEN_WAYPOINTS: { - delete _wptGroup; - _wptGroup = NULL; - delete _currentWptGroup; - _currentWptGroup = NULL; - CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); - CAdWaypointGroup *cwpt = new CAdWaypointGroup(_gameRef); - if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { - delete _wptGroup; - _wptGroup = NULL; - delete _currentWptGroup; - _currentWptGroup = NULL; - cmd = PARSERR_GENERIC; - } else { - _wptGroup = wpt; - _currentWptGroup = cwpt; - _currentWptGroup->mimic(_wptGroup); - } - } - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_SUBTYPE: { - if (scumm_stricmp((char *)params, "sound") == 0) { - delete _sprite; - _sprite = NULL; - if (_gameRef->_editorMode) { - spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) cmd = PARSERR_GENERIC; - else _sprite = spr; - } - if (_gameRef->_editorMode) _editorOnly = true; - _zoomable = false; - _rotatable = false; - _registrable = _gameRef->_editorMode; - _shadowable = false; - _subtype = ENTITY_SOUND; - } - } - break; - - case TOKEN_SOUND: - playSFX((char *)params, false, false); - break; - - case TOKEN_SOUND_START_TIME: - parser.scanStr((char *)params, "%d", &_sFXStart); - break; - - case TOKEN_SOUND_VOLUME: - parser.scanStr((char *)params, "%d", &_sFXVolume); - break; - - case TOKEN_SOUND_PANNING: - parser.scanStr((char *)params, "%b", &_autoSoundPanning); - break; - - case TOKEN_SAVE_STATE: - parser.scanStr((char *)params, "%b", &_saveState); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_IGNORE_ITEMS: - parser.scanStr((char *)params, "%b", &_ignoreItems); - 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: - parser.scanStr((char *)params, "%d", &_walkToX); - break; - - case TOKEN_WALK_TO_Y: - parser.scanStr((char *)params, "%d", &_walkToY); - 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; - _walkToDir = (TDirection)i; - } - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ENTITY definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading ENTITY definition"); - if (spr) delete spr; - return STATUS_FAILED; - } - - if (_region && _sprite) { - _gameRef->LOG(0, "Warning: Entity '%s' has both sprite and region.", _name); - } - - updatePosition(); - - if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { - ar = ag = ab = 255; - } - _alphaColor = BYTETORGBA(ar, ag, ab, alpha); - _state = STATE_READY; - - if (_item && ((CAdGame *)_gameRef)->isItemTaken(_item)) _active = false; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdEntity::display() { - if (_active) { - updateSounds(); - - uint32 Alpha; - if (_alphaColor != 0) Alpha = _alphaColor; - else Alpha = _shadowable ? ((CAdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; - - float ScaleX, ScaleY; - getScale(&ScaleX, &ScaleY); - - float Rotate; - if (_rotatable) { - if (_rotateValid) Rotate = _rotate; - else Rotate = ((CAdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; - } else Rotate = 0.0f; - - - bool Reg = _registrable; - if (_ignoreItems && ((CAdGame *)_gameRef)->_selectedItem) Reg = false; - - if (_region && (Reg || _editorAlwaysRegister)) { - _gameRef->_renderer->_rectList.add(new CBActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); - } - - displaySpriteAttachments(true); - if (_theora && (_theora->isPlaying() || _theora->isPaused())) { - _theora->display(Alpha); - } else if (_currentSprite) { - _currentSprite->display(_posX, - _posY, - (Reg || _editorAlwaysRegister) ? _registerAlias : NULL, - ScaleX, - ScaleY, - Alpha, - Rotate, - _blendMode); - } - displaySpriteAttachments(false); - - if (_partEmitter) _partEmitter->display(_region); - - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdEntity::update() { - _currentSprite = NULL; - - if (_state == STATE_READY && _animSprite) { - delete _animSprite; - _animSprite = NULL; - } - - // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { - _state = STATE_READY; - _currentSprite = _animSprite; - } - - if (_sentence && _state != STATE_TALKING) _sentence->finish(); - - // default: stand animation - if (!_currentSprite) _currentSprite = _sprite; - - switch (_state) { - ////////////////////////////////////////////////////////////////////////// - case STATE_PLAYING_ANIM: - _currentSprite = _animSprite; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_READY: - if (!_animSprite) - _currentSprite = _sprite; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_TALKING: { - _sentence->update(); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; - - bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { - if (TimeIsUp) { - _sentence->finish(); - _tempSprite2 = NULL; - _state = STATE_READY; - } else { - _tempSprite2 = getTalkStance(_sentence->getNextStance()); - if (_tempSprite2) { - _tempSprite2->reset(); - _currentSprite = _tempSprite2; - } - ((CAdGame *)_gameRef)->addSentence(_sentence); - } - } else { - _currentSprite = _tempSprite2; - ((CAdGame *)_gameRef)->addSentence(_sentence); - } - } - break; - default: // Silence unhandled enum-warning - break; - } - - - if (_currentSprite) { - _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (_currentSprite->_changed) { - _posX += _currentSprite->_moveX; - _posY += _currentSprite->_moveY; - } - } - - updateBlockRegion(); - _ready = (_state == STATE_READY); - - if (_theora) { - int OffsetX, OffsetY; - _gameRef->getOffset(&OffsetX, &OffsetY); - _theora->_posX = _posX - OffsetX; - _theora->_posY = _posY - OffsetY; - - _theora->update(); - if (_theora->isFinished()) { - _theora->stop(); - delete _theora; - _theora = NULL; - } - } - - updatePartEmitter(); - updateSpriteAttachments(); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdEntity::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // StopSound - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "StopSound") == 0 && _subtype == ENTITY_SOUND) { - stack->correctParams(0); - - if (DID_FAIL(stopSFX(false))) stack->pushBool(false); - else stack->pushBool(true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // PlayTheora - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PlayTheora") == 0) { - stack->correctParams(4); - const char *filename = stack->pop()->getString(); - bool looping = stack->pop()->getBool(false); - CScValue *valAlpha = stack->pop(); - int startTime = stack->pop()->getInt(); - - delete _theora; - _theora = new CVidTheoraPlayer(_gameRef); - if (_theora && DID_SUCCEED(_theora->initialize(filename))) { - if (!valAlpha->isNULL()) _theora->setAlphaImage(valAlpha->getString()); - _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); - //if(m_Scale>=0) m_Theora->m_PlayZoom = m_Scale; - stack->pushBool(true); - } else { - script->runtimeError("Entity.PlayTheora - error playing video '%s'", filename); - stack->pushBool(false); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // StopTheora - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StopTheora") == 0) { - stack->correctParams(0); - if (_theora) { - _theora->stop(); - delete _theora; - _theora = NULL; - stack->pushBool(true); - } else stack->pushBool(false); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsTheoraPlaying - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsTheoraPlaying") == 0) { - stack->correctParams(0); - if (_theora && _theora->isPlaying()) stack->pushBool(true); - else stack->pushBool(false); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // PauseTheora - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PauseTheora") == 0) { - stack->correctParams(0); - if (_theora && _theora->isPlaying()) { - _theora->pause(); - stack->pushBool(true); - } else stack->pushBool(false); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ResumeTheora - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ResumeTheora") == 0) { - stack->correctParams(0); - if (_theora && _theora->isPaused()) { - _theora->resume(); - stack->pushBool(true); - } else stack->pushBool(false); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsTheoraPaused - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsTheoraPaused") == 0) { - stack->correctParams(0); - if (_theora && _theora->isPaused()) stack->pushBool(true); - else stack->pushBool(false); - - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // CreateRegion - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateRegion") == 0) { - stack->correctParams(0); - if (!_region) { - _region = new CBRegion(_gameRef); - _gameRef->registerObject(_region); - } - if (_region) stack->pushNative(_region, true); - else stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteRegion - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteRegion") == 0) { - stack->correctParams(0); - if (_region) { - _gameRef->unregisterObject(_region); - _region = NULL; - stack->pushBool(true); - } else stack->pushBool(false); - - return STATUS_OK; - } - - else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdEntity::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type (RO) - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("entity"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Item - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Item") == 0) { - if (_item) _scValue->setString(_item); - else _scValue->setNULL(); - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Subtype (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Subtype") == 0) { - if (_subtype == ENTITY_SOUND) - _scValue->setString("sound"); - else - _scValue->setString("normal"); - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToX") == 0) { - _scValue->setInt(_walkToX); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToY") == 0) { - _scValue->setInt(_walkToY); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToDirection - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToDirection") == 0) { - _scValue->setInt((int)_walkToDir); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Region (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Region") == 0) { - if (_region) _scValue->setNative(_region, true); - else _scValue->setNULL(); - return _scValue; - } - - else return CAdTalkHolder::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdEntity::scSetProperty(const char *name, CScValue *value) { - - ////////////////////////////////////////////////////////////////////////// - // Item - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Item") == 0) { - setItem(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToX") == 0) { - _walkToX = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToY") == 0) { - _walkToY = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToDirection - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToDirection") == 0) { - int dir = value->getInt(); - if (dir >= 0 && dir < NUM_DIRECTIONS) _walkToDir = (TDirection)dir; - return STATUS_OK; - } - - else return CAdTalkHolder::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *CAdEntity::scToString() { - return "[entity object]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdEntity::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "ENTITY {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); - if (_subtype == ENTITY_SOUND) - buffer->putTextIndent(indent + 2, "SUBTYPE=\"SOUND\"\n"); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - 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); - - int i; - - for (i = 0; i < _scripts.getSize(); i++) { - buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); - } - - if (_subtype == ENTITY_NORMAL && _sprite && _sprite->_filename) - buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->_filename); - - 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); - } - - - if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) - buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alphaColor), RGBCOLGetG(_alphaColor), RGBCOLGetB(_alphaColor)); - - if (RGBCOLGetA(_alphaColor) != 0) - buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alphaColor)); - - if (_scale >= 0) - buffer->putTextIndent(indent + 2, "SCALE = %d\n", (int)_scale); - - if (_relativeScale != 0) - buffer->putTextIndent(indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale); - - if (_font && _font->_filename) - buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->_filename); - - if (_cursor && _cursor->_filename) - buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); - - CAdTalkHolder::saveAsText(buffer, indent + 2); - - if (_region) _region->saveAsText(buffer, indent + 2); - - if (_scProp) _scProp->saveAsText(buffer, indent + 2); - - CAdObject::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -int CAdEntity::getHeight() { - if (_region && !_sprite) { - return _region->_rect.bottom - _region->_rect.top; - } else { - if (_currentSprite == NULL) _currentSprite = _sprite; - return CAdObject::getHeight(); - } -} - - -////////////////////////////////////////////////////////////////////////// -void CAdEntity::updatePosition() { - if (_region && !_sprite) { - _posX = _region->_rect.left + (_region->_rect.right - _region->_rect.left) / 2; - _posY = _region->_rect.bottom; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdEntity::persist(CBPersistMgr *persistMgr) { - CAdTalkHolder::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_item)); - persistMgr->transfer(TMEMBER(_region)); - //persistMgr->transfer(TMEMBER(_sprite)); - persistMgr->transfer(TMEMBER_INT(_subtype)); - _talkSprites.persist(persistMgr); - _talkSpritesEx.persist(persistMgr); - - persistMgr->transfer(TMEMBER(_walkToX)); - persistMgr->transfer(TMEMBER(_walkToY)); - persistMgr->transfer(TMEMBER_INT(_walkToDir)); - - persistMgr->transfer(TMEMBER(_theora)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdEntity::setItem(const char *itemName) { - CBUtils::setString(&_item, itemName); -} - -////////////////////////////////////////////////////////////////////////// -bool CAdEntity::setSprite(const char *filename) { - bool setCurrent = false; - if (_currentSprite == _sprite) { - _currentSprite = NULL; - setCurrent = true; - } - - delete _sprite; - _sprite = NULL; - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - delete _sprite; - _sprite = NULL; - return STATUS_FAILED; - } else { - _sprite = spr; - _currentSprite = _sprite; - return STATUS_OK; - } -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdEntity.h b/engines/wintermute/ad/AdEntity.h deleted file mode 100644 index a260ca3329..0000000000 --- a/engines/wintermute/ad/AdEntity.h +++ /dev/null @@ -1,68 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADENTITY_H -#define WINTERMUTE_ADENTITY_H - -#include "engines/wintermute/ad/AdTalkHolder.h" - -namespace WinterMute { -class CVidTheoraPlayer; -class CAdEntity : public CAdTalkHolder { -public: - CVidTheoraPlayer *_theora; - bool setSprite(const char *filename); - int _walkToX; - int _walkToY; - TDirection _walkToDir; - void setItem(const char *itemName); - char *_item; - DECLARE_PERSISTENT(CAdEntity, CAdTalkHolder) - void updatePosition(); - virtual int getHeight(); - CBRegion *_region; - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - virtual bool update(); - virtual bool display(); - CAdEntity(CBGame *inGame); - virtual ~CAdEntity(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - TEntityType _subtype; - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - virtual const char *scToString(); - -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdGame.cpp b/engines/wintermute/ad/AdGame.cpp deleted file mode 100644 index 87e3fe14d9..0000000000 --- a/engines/wintermute/ad/AdGame.cpp +++ /dev/null @@ -1,2061 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdActor.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdEntity.h" -#include "engines/wintermute/ad/AdInventory.h" -#include "engines/wintermute/ad/AdInventoryBox.h" -#include "engines/wintermute/ad/AdItem.h" -#include "engines/wintermute/ad/AdResponse.h" -#include "engines/wintermute/ad/AdResponseBox.h" -#include "engines/wintermute/ad/AdResponseContext.h" -#include "engines/wintermute/ad/AdScene.h" -#include "engines/wintermute/ad/AdSceneState.h" -#include "engines/wintermute/ad/AdSentence.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/base/font/BFont.h" -#include "engines/wintermute/base/BObject.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BSound.h" -#include "engines/wintermute/base/BStringTable.h" -#include "engines/wintermute/base/BSurfaceStorage.h" -#include "engines/wintermute/base/BTransitionMgr.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/base/BViewport.h" -#include "engines/wintermute/base/particles/PartEmitter.h" -#include "engines/wintermute/base/scriptables/ScEngine.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "engines/wintermute/ui/UIEntity.h" -#include "engines/wintermute/ui/UIWindow.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/video/VidPlayer.h" -#include "engines/wintermute/video/VidTheoraPlayer.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdGame, true) - -////////////////////////////////////////////////////////////////////////// -CAdGame::CAdGame(): CBGame() { - _responseBox = NULL; - _inventoryBox = NULL; - - _scene = new CAdScene(_gameRef); - _scene->setName(""); - registerObject(_scene); - - _prevSceneName = NULL; - _prevSceneFilename = NULL; - _scheduledScene = NULL; - _scheduledFadeIn = false; - - - _stateEx = GAME_NORMAL; - - _selectedItem = NULL; - - - _texItemLifeTime = 10000; - _texWalkLifeTime = 10000; - _texStandLifeTime = 10000; - _texTalkLifeTime = 10000; - - _talkSkipButton = TALK_SKIP_LEFT; - - _sceneViewport = NULL; - - _initialScene = true; - _debugStartupScene = NULL; - _startupScene = NULL; - - _invObject = new CAdObject(this); - _inventoryOwner = _invObject; - - _tempDisableSaveState = false; - _itemsFile = NULL; - - _smartItemCursor = false; - - addSpeechDir("speech"); -} - - -////////////////////////////////////////////////////////////////////////// -CAdGame::~CAdGame() { - cleanup(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::cleanup() { - int i; - - for (i = 0; i < _objects.getSize(); i++) { - unregisterObject(_objects[i]); - _objects[i] = NULL; - } - _objects.removeAll(); - - - for (i = 0; i < _dlgPendingBranches.getSize(); i++) { - delete [] _dlgPendingBranches[i]; - } - _dlgPendingBranches.removeAll(); - - for (i = 0; i < _speechDirs.getSize(); i++) { - delete [] _speechDirs[i]; - } - _speechDirs.removeAll(); - - - unregisterObject(_scene); - _scene = NULL; - - // remove items - for (i = 0; i < _items.getSize(); i++) _gameRef->unregisterObject(_items[i]); - _items.removeAll(); - - - // clear remaining inventories - delete _invObject; - _invObject = NULL; - - for (i = 0; i < _inventories.getSize(); i++) { - delete _inventories[i]; - } - _inventories.removeAll(); - - - if (_responseBox) { - _gameRef->unregisterObject(_responseBox); - _responseBox = NULL; - } - - if (_inventoryBox) { - _gameRef->unregisterObject(_inventoryBox); - _inventoryBox = NULL; - } - - delete[] _prevSceneName; - delete[] _prevSceneFilename; - delete[] _scheduledScene; - delete[] _debugStartupScene; - delete[] _itemsFile; - _prevSceneName = NULL; - _prevSceneFilename = NULL; - _scheduledScene = NULL; - _debugStartupScene = NULL; - _startupScene = NULL; - _itemsFile = NULL; - - delete _sceneViewport; - _sceneViewport = NULL; - - for (i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; - _sceneStates.removeAll(); - - for (i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; - _responsesBranch.removeAll(); - - for (i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; - _responsesGame.removeAll(); - - return CBGame::cleanup(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::initLoop() { - if (_scheduledScene && _transMgr->isReady()) { - changeScene(_scheduledScene, _scheduledFadeIn); - delete[] _scheduledScene; - _scheduledScene = NULL; - - _gameRef->_activeObject = NULL; - } - - - bool res; - res = CBGame::initLoop(); - if (DID_FAIL(res)) return res; - - if (_scene) res = _scene->initLoop(); - - _sentences.removeAll(); - - return res; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::addObject(CAdObject *object) { - _objects.add(object); - return registerObject(object); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::removeObject(CAdObject *object) { - // in case the user called Scene.CreateXXX() and Game.DeleteXXX() - if (_scene) { - bool Res = _scene->removeObject(object); - if (DID_SUCCEED(Res)) return Res; - } - - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i] == object) { - _objects.removeAt(i); - break; - } - } - return unregisterObject(object); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::changeScene(const char *filename, bool fadeIn) { - if (_scene == NULL) { - _scene = new CAdScene(_gameRef); - registerObject(_scene); - } else { - _scene->applyEvent("SceneShutdown", true); - - setPrevSceneName(_scene->_name); - setPrevSceneFilename(_scene->_filename); - - if (!_tempDisableSaveState) _scene->saveState(); - _tempDisableSaveState = false; - } - - if (_scene) { - // reset objects - for (int i = 0; i < _objects.getSize(); i++) _objects[i]->reset(); - - // reset scene properties - _scene->_sFXVolume = 100; - if (_scene->_scProp) _scene->_scProp->cleanup(); - - bool ret; - if (_initialScene && _debugDebugMode && _debugStartupScene) { - _initialScene = false; - ret = _scene->loadFile(_debugStartupScene); - } else ret = _scene->loadFile(filename); - - if (DID_SUCCEED(ret)) { - // invalidate references to the original scene - for (int i = 0; i < _objects.getSize(); i++) { - _objects[i]->invalidateCurrRegions(); - _objects[i]->_stickRegion = NULL; - } - - _scene->loadState(); - } - if (fadeIn) _gameRef->_transMgr->start(TRANSITION_FADE_IN); - return ret; - } else return STATUS_FAILED; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdGame::addSentence(CAdSentence *sentence) { - _sentences.add(sentence); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::displaySentences(bool frozen) { - for (int i = 0; i < _sentences.getSize(); i++) { - if (frozen && _sentences[i]->_freezable) continue; - else _sentences[i]->display(); - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdGame::finishSentences() { - for (int i = 0; i < _sentences.getSize(); i++) { - if (_sentences[i]->CanSkip()) { - _sentences[i]->_duration = 0; - if (_sentences[i]->_sound) _sentences[i]->_sound->stop(); - } - } -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // ChangeScene - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "ChangeScene") == 0) { - stack->correctParams(3); - const char *filename = stack->pop()->getString(); - CScValue *valFadeOut = stack->pop(); - CScValue *valFadeIn = stack->pop(); - - bool transOut = valFadeOut->isNULL() ? true : valFadeOut->getBool(); - bool transIn = valFadeIn->isNULL() ? true : valFadeIn->getBool(); - - scheduleChangeScene(filename, transIn); - if (transOut) _transMgr->start(TRANSITION_FADE_OUT, true); - stack->pushNULL(); - - - //bool ret = ChangeScene(stack->pop()->getString()); - //if(DID_FAIL(ret)) stack->pushBool(false); - //else stack->pushBool(true); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadActor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadActor") == 0) { - stack->correctParams(1); - CAdActor *act = new CAdActor(_gameRef); - if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { - addObject(act); - stack->pushNative(act, true); - } else { - delete act; - act = NULL; - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadEntity") == 0) { - stack->correctParams(1); - CAdEntity *ent = new CAdEntity(_gameRef); - if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { - addObject(ent); - stack->pushNative(ent, true); - } else { - delete ent; - ent = NULL; - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // UnloadObject / UnloadActor / UnloadEntity / DeleteEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "DeleteEntity") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - CAdObject *obj = (CAdObject *)val->getNative(); - removeObject(obj); - if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CreateEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateEntity") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdEntity *ent = new CAdEntity(_gameRef); - addObject(ent); - if (!val->isNULL()) ent->setName(val->getString()); - stack->pushNative(ent, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CreateItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateItem") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdItem *item = new CAdItem(_gameRef); - addItem(item); - if (!val->isNULL()) item->setName(val->getString()); - stack->pushNative(item, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteItem") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdItem *item = NULL; - if (val->isNative()) item = (CAdItem *)val->getNative(); - else item = getItemByName(val->getString()); - - if (item) { - deleteItem(item); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // QueryItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "QueryItem") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdItem *item = NULL; - if (val->isInt()) { - int index = val->getInt(); - if (index >= 0 && index < _items.getSize()) item = _items[index]; - } else { - item = getItemByName(val->getString()); - } - - if (item) stack->pushNative(item, true); - else stack->pushNULL(); - - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // AddResponse/AddResponseOnce/AddResponseOnceGame - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddResponse") == 0 || strcmp(name, "AddResponseOnce") == 0 || strcmp(name, "AddResponseOnceGame") == 0) { - stack->correctParams(6); - int id = stack->pop()->getInt(); - const char *text = stack->pop()->getString(); - CScValue *val1 = stack->pop(); - CScValue *val2 = stack->pop(); - CScValue *val3 = stack->pop(); - CScValue *val4 = stack->pop(); - - if (_responseBox) { - CAdResponse *res = new CAdResponse(_gameRef); - if (res) { - res->_iD = id; - res->setText(text); - _stringTable->expand(&res->_text); - if (!val1->isNULL()) res->setIcon(val1->getString()); - if (!val2->isNULL()) res->setIconHover(val2->getString()); - if (!val3->isNULL()) res->setIconPressed(val3->getString()); - if (!val4->isNULL()) res->setFont(val4->getString()); - - if (strcmp(name, "AddResponseOnce") == 0) res->_responseType = RESPONSE_ONCE; - else if (strcmp(name, "AddResponseOnceGame") == 0) res->_responseType = RESPONSE_ONCE_GAME; - - _responseBox->_responses.add(res); - } - } else { - script->runtimeError("Game.AddResponse: response box is not defined"); - } - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ResetResponse - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ResetResponse") == 0) { - stack->correctParams(1); - int ID = stack->pop()->getInt(-1); - resetResponse(ID); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ClearResponses - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ClearResponses") == 0) { - stack->correctParams(0); - _responseBox->clearResponses(); - _responseBox->clearButtons(); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetResponse - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetResponse") == 0) { - stack->correctParams(1); - bool autoSelectLast = stack->pop()->getBool(); - - if (_responseBox) { - _responseBox->weedResponses(); - - if (_responseBox->_responses.getSize() == 0) { - stack->pushNULL(); - return STATUS_OK; - } - - - if (_responseBox->_responses.getSize() == 1 && autoSelectLast) { - stack->pushInt(_responseBox->_responses[0]->_iD); - _responseBox->handleResponse(_responseBox->_responses[0]); - _responseBox->clearResponses(); - return STATUS_OK; - } - - _responseBox->createButtons(); - _responseBox->_waitingScript = script; - script->waitForExclusive(_responseBox); - _state = GAME_SEMI_FROZEN; - _stateEx = GAME_WAITING_RESPONSE; - } else { - script->runtimeError("Game.GetResponse: response box is not defined"); - stack->pushNULL(); - } - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // GetNumResponses - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetNumResponses") == 0) { - stack->correctParams(0); - if (_responseBox) { - _responseBox->weedResponses(); - stack->pushInt(_responseBox->_responses.getSize()); - } else { - script->runtimeError("Game.GetNumResponses: response box is not defined"); - stack->pushNULL(); - } - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // StartDlgBranch - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StartDlgBranch") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - Common::String branchName; - if (val->isNULL()) { - branchName.format("line%d", script->_currentLine); - } else branchName = val->getString(); - - startDlgBranch(branchName.c_str(), script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // EndDlgBranch - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "EndDlgBranch") == 0) { - stack->correctParams(1); - - const char *branchName = NULL; - CScValue *val = stack->pop(); - if (!val->isNULL()) branchName = val->getString(); - endDlgBranch(branchName, script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); - - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetCurrentDlgBranch - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetCurrentDlgBranch") == 0) { - stack->correctParams(0); - - if (_dlgPendingBranches.getSize() > 0) { - stack->pushString(_dlgPendingBranches[_dlgPendingBranches.getSize() - 1]); - } else stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TakeItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TakeItem") == 0) { - return _invObject->scCallMethod(script, stack, thisStack, name); - } - - ////////////////////////////////////////////////////////////////////////// - // DropItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DropItem") == 0) { - return _invObject->scCallMethod(script, stack, thisStack, name); - } - - ////////////////////////////////////////////////////////////////////////// - // GetItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetItem") == 0) { - return _invObject->scCallMethod(script, stack, thisStack, name); - } - - ////////////////////////////////////////////////////////////////////////// - // HasItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "HasItem") == 0) { - return _invObject->scCallMethod(script, stack, thisStack, name); - } - - ////////////////////////////////////////////////////////////////////////// - // IsItemTaken - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsItemTaken") == 0) { - stack->correctParams(1); - - CScValue *val = stack->pop(); - if (!val->isNULL()) { - for (int i = 0; i < _inventories.getSize(); i++) { - CAdInventory *Inv = _inventories[i]; - - for (int j = 0; j < Inv->_takenItems.getSize(); j++) { - if (val->getNative() == Inv->_takenItems[j]) { - stack->pushBool(true); - return STATUS_OK; - } else if (scumm_stricmp(val->getString(), Inv->_takenItems[j]->_name) == 0) { - stack->pushBool(true); - return STATUS_OK; - } - } - } - } else script->runtimeError("Game.IsItemTaken: item name expected"); - - stack->pushBool(false); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetInventoryWindow - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetInventoryWindow") == 0) { - stack->correctParams(0); - if (_inventoryBox && _inventoryBox->_window) - stack->pushNative(_inventoryBox->_window, true); - else - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetResponsesWindow - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetResponsesWindow") == 0 || strcmp(name, "GetResponseWindow") == 0) { - stack->correctParams(0); - if (_responseBox && _responseBox->_window) - stack->pushNative(_responseBox->_window, true); - else - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadResponseBox - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadResponseBox") == 0) { - stack->correctParams(1); - const char *filename = stack->pop()->getString(); - - _gameRef->unregisterObject(_responseBox); - _responseBox = new CAdResponseBox(_gameRef); - if (_responseBox && !DID_FAIL(_responseBox->loadFile(filename))) { - registerObject(_responseBox); - stack->pushBool(true); - } else { - delete _responseBox; - _responseBox = NULL; - stack->pushBool(false); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadInventoryBox - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadInventoryBox") == 0) { - stack->correctParams(1); - const char *filename = stack->pop()->getString(); - - _gameRef->unregisterObject(_inventoryBox); - _inventoryBox = new CAdInventoryBox(_gameRef); - if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile(filename))) { - registerObject(_inventoryBox); - stack->pushBool(true); - } else { - delete _inventoryBox; - _inventoryBox = NULL; - stack->pushBool(false); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadItems") == 0) { - stack->correctParams(2); - const char *filename = stack->pop()->getString(); - bool merge = stack->pop()->getBool(false); - - bool ret = loadItemsFile(filename, merge); - stack->pushBool(DID_SUCCEED(ret)); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddSpeechDir - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddSpeechDir") == 0) { - stack->correctParams(1); - const char *dir = stack->pop()->getString(); - stack->pushBool(DID_SUCCEED(addSpeechDir(dir))); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // RemoveSpeechDir - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "RemoveSpeechDir") == 0) { - stack->correctParams(1); - const char *dir = stack->pop()->getString(); - stack->pushBool(DID_SUCCEED(removeSpeechDir(dir))); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetSceneViewport - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SetSceneViewport") == 0) { - stack->correctParams(4); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - int width = stack->pop()->getInt(); - int height = stack->pop()->getInt(); - - if (width <= 0) width = _renderer->_width; - if (height <= 0) height = _renderer->_height; - - if (!_sceneViewport) _sceneViewport = new CBViewport(_gameRef); - if (_sceneViewport) _sceneViewport->setRect(x, y, x + width, y + height); - - stack->pushBool(true); - - return STATUS_OK; - } - - - else return CBGame::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdGame::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("game"); - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // Scene - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Scene") == 0) { - if (_scene) _scValue->setNative(_scene, true); - else _scValue->setNULL(); - - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // SelectedItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SelectedItem") == 0) { - //if(_selectedItem) _scValue->setString(_selectedItem->_name); - if (_selectedItem) _scValue->setNative(_selectedItem, true); - else _scValue->setNULL(); - - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // NumItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumItems") == 0) { - return _invObject->scGetProperty(name); - } - - ////////////////////////////////////////////////////////////////////////// - // SmartItemCursor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SmartItemCursor") == 0) { - _scValue->setBool(_smartItemCursor); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryVisible - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryVisible") == 0) { - _scValue->setBool(_inventoryBox && _inventoryBox->_visible); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryScrollOffset - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryScrollOffset") == 0) { - if (_inventoryBox) _scValue->setInt(_inventoryBox->_scrollOffset); - else _scValue->setInt(0); - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ResponsesVisible (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ResponsesVisible") == 0) { - _scValue->setBool(_stateEx == GAME_WAITING_RESPONSE); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // PrevScene / PreviousScene (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PrevScene") == 0 || strcmp(name, "PreviousScene") == 0) { - if (!_prevSceneName) _scValue->setString(""); - else _scValue->setString(_prevSceneName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // PrevSceneFilename / PreviousSceneFilename (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PrevSceneFilename") == 0 || strcmp(name, "PreviousSceneFilename") == 0) { - if (!_prevSceneFilename) _scValue->setString(""); - else _scValue->setString(_prevSceneFilename); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // LastResponse (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LastResponse") == 0) { - if (!_responseBox || !_responseBox->_lastResponseText) _scValue->setString(""); - else _scValue->setString(_responseBox->_lastResponseText); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // LastResponseOrig (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LastResponseOrig") == 0) { - if (!_responseBox || !_responseBox->_lastResponseTextOrig) _scValue->setString(""); - else _scValue->setString(_responseBox->_lastResponseTextOrig); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryObject") == 0) { - if (_inventoryOwner == _invObject) _scValue->setNative(this, true); - else _scValue->setNative(_inventoryOwner, true); - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // TotalNumItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TotalNumItems") == 0) { - _scValue->setInt(_items.getSize()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // TalkSkipButton - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkSkipButton") == 0) { - _scValue->setInt(_talkSkipButton); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ChangingScene - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ChangingScene") == 0) { - _scValue->setBool(_scheduledScene != NULL); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // StartupScene - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StartupScene") == 0) { - if (!_startupScene) _scValue->setNULL(); - else _scValue->setString(_startupScene); - return _scValue; - } - - else return CBGame::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::scSetProperty(const char *name, CScValue *value) { - - ////////////////////////////////////////////////////////////////////////// - // SelectedItem - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SelectedItem") == 0) { - if (value->isNULL()) _selectedItem = NULL; - else { - if (value->isNative()) { - _selectedItem = NULL; - for (int i = 0; i < _items.getSize(); i++) { - if (_items[i] == value->getNative()) { - _selectedItem = (CAdItem *)value->getNative(); - break; - } - } - } else { - // try to get by name - _selectedItem = getItemByName(value->getString()); - } - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SmartItemCursor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SmartItemCursor") == 0) { - _smartItemCursor = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryVisible - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryVisible") == 0) { - if (_inventoryBox) _inventoryBox->_visible = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryObject") == 0) { - if (_inventoryOwner && _inventoryBox) _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; - - if (value->isNULL()) _inventoryOwner = _invObject; - else { - CBObject *Obj = (CBObject *)value->getNative(); - if (Obj == this) _inventoryOwner = _invObject; - else if (_gameRef->validObject(Obj)) _inventoryOwner = (CAdObject *)Obj; - } - - if (_inventoryOwner && _inventoryBox) _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryScrollOffset - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryScrollOffset") == 0) { - if (_inventoryBox) _inventoryBox->_scrollOffset = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TalkSkipButton - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkSkipButton") == 0) { - int Val = value->getInt(); - if (Val < 0) Val = 0; - if (Val > TALK_SKIP_NONE) Val = TALK_SKIP_NONE; - _talkSkipButton = (TTalkSkipButton)Val; - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // StartupScene - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StartupScene") == 0) { - if (value == NULL) { - delete[] _startupScene; - _startupScene = NULL; - } else CBUtils::setString(&_startupScene, value->getString()); - - return STATUS_OK; - } - - else return CBGame::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name) { - CScValue *this_obj; - - ////////////////////////////////////////////////////////////////////////// - // Actor - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Actor") == 0) { - stack->correctParams(0); - this_obj = thisStack->getTop(); - - this_obj->setNative(new CAdActor(_gameRef)); - stack->pushNULL(); - } - - ////////////////////////////////////////////////////////////////////////// - // Entity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Entity") == 0) { - stack->correctParams(0); - this_obj = thisStack->getTop(); - - this_obj->setNative(new CAdEntity(_gameRef)); - stack->pushNULL(); - } - - - ////////////////////////////////////////////////////////////////////////// - // call parent - else return CBGame::ExternalCall(script, stack, thisStack, name); - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::showCursor() { - if (_cursorHidden) return STATUS_OK; - - if (_selectedItem && _gameRef->_state == GAME_RUNNING && _stateEx == GAME_NORMAL && _interactive) { - if (_selectedItem->_cursorCombined) { - CBSprite *origLastCursor = _lastCursor; - CBGame::showCursor(); - _lastCursor = origLastCursor; - } - if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { - if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->_name)) - return drawCursor(_selectedItem->_cursorHover); - else - return drawCursor(_selectedItem->_cursorNormal); - } else return drawCursor(_selectedItem->_cursorNormal); - } else return CBGame::showCursor(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadFile(const char *filename) { - byte *buffer = _fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdGame::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(GAME) -TOKEN_DEF(AD_GAME) -TOKEN_DEF(RESPONSE_BOX) -TOKEN_DEF(INVENTORY_BOX) -TOKEN_DEF(ITEMS) -TOKEN_DEF(ITEM) -TOKEN_DEF(TALK_SKIP_BUTTON) -TOKEN_DEF(SCENE_VIEWPORT) -TOKEN_DEF(ENTITY_CONTAINER) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF(STARTUP_SCENE) -TOKEN_DEF(DEBUG_STARTUP_SCENE) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(GAME) - TOKEN_TABLE(AD_GAME) - TOKEN_TABLE(RESPONSE_BOX) - TOKEN_TABLE(INVENTORY_BOX) - TOKEN_TABLE(ITEMS) - TOKEN_TABLE(TALK_SKIP_BUTTON) - TOKEN_TABLE(SCENE_VIEWPORT) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE(STARTUP_SCENE) - TOKEN_TABLE(DEBUG_STARTUP_SCENE) - TOKEN_TABLE_END - - byte *params; - byte *params2; - int cmd = 1; - CBParser parser(_gameRef); - - bool itemFound = false, itemsFound = false; - - while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_GAME: - if (DID_FAIL(CBGame::loadBuffer(params, false))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_AD_GAME: - while (cmd > 0 && (cmd = parser.getCommand((char **)¶ms, commands, (char **)¶ms2)) > 0) { - switch (cmd) { - case TOKEN_RESPONSE_BOX: - delete _responseBox; - _responseBox = new CAdResponseBox(_gameRef); - if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) - registerObject(_responseBox); - else { - delete _responseBox; - _responseBox = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_INVENTORY_BOX: - delete _inventoryBox; - _inventoryBox = new CAdInventoryBox(_gameRef); - if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) - registerObject(_inventoryBox); - else { - delete _inventoryBox; - _inventoryBox = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_ITEMS: - itemsFound = true; - CBUtils::setString(&_itemsFile, (char *)params2); - if (DID_FAIL(loadItemsFile(_itemsFile))) { - delete[] _itemsFile; - _itemsFile = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_TALK_SKIP_BUTTON: - if (scumm_stricmp((char *)params2, "right") == 0) _talkSkipButton = TALK_SKIP_RIGHT; - else if (scumm_stricmp((char *)params2, "both") == 0) _talkSkipButton = TALK_SKIP_BOTH; - else _talkSkipButton = TALK_SKIP_LEFT; - break; - - case TOKEN_SCENE_VIEWPORT: { - Rect32 rc; - parser.scanStr((char *)params2, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_sceneViewport) _sceneViewport = new CBViewport(_gameRef); - if (_sceneViewport) _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); - } - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params2, false); - break; - - case TOKEN_STARTUP_SCENE: - CBUtils::setString(&_startupScene, (char *)params2); - break; - - case TOKEN_DEBUG_STARTUP_SCENE: - CBUtils::setString(&_debugStartupScene, (char *)params2); - break; - } - } - break; - } - } - - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in GAME definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading GAME definition"); - return STATUS_FAILED; - } - - if (itemFound && !itemsFound) { - _gameRef->LOG(0, "**Warning** Please put the items definition to a separate file."); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::persist(CBPersistMgr *persistMgr) { - if (!persistMgr->_saving) cleanup(); - CBGame::persist(persistMgr); - - _dlgPendingBranches.persist(persistMgr); - - _inventories.persist(persistMgr); - persistMgr->transfer(TMEMBER(_inventoryBox)); - - _objects.persist(persistMgr); - - persistMgr->transfer(TMEMBER(_prevSceneName)); - persistMgr->transfer(TMEMBER(_prevSceneFilename)); - - persistMgr->transfer(TMEMBER(_responseBox)); - _responsesBranch.persist(persistMgr); - _responsesGame.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scene)); - _sceneStates.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scheduledFadeIn)); - persistMgr->transfer(TMEMBER(_scheduledScene)); - persistMgr->transfer(TMEMBER(_selectedItem)); - persistMgr->transfer(TMEMBER_INT(_talkSkipButton)); - - _sentences.persist(persistMgr); - - persistMgr->transfer(TMEMBER(_sceneViewport)); - persistMgr->transfer(TMEMBER_INT(_stateEx)); - persistMgr->transfer(TMEMBER(_initialScene)); - persistMgr->transfer(TMEMBER(_debugStartupScene)); - - persistMgr->transfer(TMEMBER(_invObject)); - persistMgr->transfer(TMEMBER(_inventoryOwner)); - persistMgr->transfer(TMEMBER(_tempDisableSaveState)); - _items.persist(persistMgr); - - persistMgr->transfer(TMEMBER(_itemsFile)); - - _speechDirs.persist(persistMgr); - persistMgr->transfer(TMEMBER(_smartItemCursor)); - - if (!persistMgr->_saving) _initialScene = false; - - persistMgr->transfer(TMEMBER(_startupScene)); - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadGame(const char *filename) { - bool ret = CBGame::loadGame(filename); - if (DID_SUCCEED(ret)) CSysClassRegistry::getInstance()->enumInstances(afterLoadRegion, "CAdRegion", NULL); - return ret; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::initAfterLoad() { - CBGame::initAfterLoad(); - CSysClassRegistry::getInstance()->enumInstances(afterLoadScene, "CAdScene", NULL); - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -void CAdGame::afterLoadScene(void *scene, void *data) { - ((CAdScene *)scene)->afterLoad(); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdGame::setPrevSceneName(const char *name) { - delete[] _prevSceneName; - _prevSceneName = NULL; - if (name) { - _prevSceneName = new char[strlen(name) + 1]; - if (_prevSceneName) strcpy(_prevSceneName, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -void CAdGame::setPrevSceneFilename(const char *name) { - delete[] _prevSceneFilename; - _prevSceneFilename = NULL; - if (name) { - _prevSceneFilename = new char[strlen(name) + 1]; - if (_prevSceneFilename) strcpy(_prevSceneFilename, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::scheduleChangeScene(const char *filename, bool fadeIn) { - delete[] _scheduledScene; - _scheduledScene = NULL; - - if (_scene && !_scene->_initialized) return changeScene(filename, fadeIn); - else { - _scheduledScene = new char [strlen(filename) + 1]; - strcpy(_scheduledScene, filename); - - _scheduledFadeIn = fadeIn; - - return STATUS_OK; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { - CBGame::getVersion(verMajor, verMinor, NULL, NULL); - - if (extMajor) *extMajor = 0; - if (extMinor) *extMinor = 0; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadItemsFile(const char *filename, bool merge) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdGame::LoadItemsFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - //_filename = new char [strlen(filename)+1]; - //strcpy(_filename, filename); - - if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadItemsBuffer(byte *buffer, bool merge) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ITEM) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (!merge) { - while (_items.getSize() > 0) deleteItem(_items[0]); - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_ITEM: { - CAdItem *item = new CAdItem(_gameRef); - if (item && !DID_FAIL(item->loadBuffer(params, false))) { - // delete item with the same name, if exists - if (merge) { - CAdItem *PrevItem = getItemByName(item->_name); - if (PrevItem) deleteItem(PrevItem); - } - addItem(item); - } else { - delete item; - item = NULL; - cmd = PARSERR_GENERIC; - } - } - break; - } - } - - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ITEMS definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading ITEMS definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -CAdSceneState *CAdGame::getSceneState(const char *filename, bool saving) { - char *filenameCor = new char[strlen(filename) + 1]; - strcpy(filenameCor, filename); - for (uint32 i = 0; i < strlen(filenameCor); i++) { - if (filenameCor[i] == '/') filenameCor[i] = '\\'; - } - - for (int i = 0; i < _sceneStates.getSize(); i++) { - if (scumm_stricmp(_sceneStates[i]->_filename, filenameCor) == 0) { - delete [] filenameCor; - return _sceneStates[i]; - } - } - - if (saving) { - CAdSceneState *ret = new CAdSceneState(_gameRef); - ret->setFilename(filenameCor); - - _sceneStates.add(ret); - - delete [] filenameCor; - return ret; - } else { - delete [] filenameCor; - return NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::windowLoadHook(CUIWindow *win, char **buffer, char **params) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ENTITY_CONTAINER) - TOKEN_TABLE_END - - int cmd = PARSERR_GENERIC; - CBParser parser(_gameRef); - - cmd = parser.getCommand(buffer, commands, params); - switch (cmd) { - case TOKEN_ENTITY_CONTAINER: { - CUIEntity *ent = new CUIEntity(_gameRef); - if (!ent || DID_FAIL(ent->loadBuffer((byte *)*params, false))) { - delete ent; - ent = NULL; - cmd = PARSERR_GENERIC; - } else { - ent->_parent = win; - win->_widgets.add(ent); - } - } - break; - } - - if (cmd == PARSERR_TOKENNOTFOUND || cmd == PARSERR_GENERIC) { - return STATUS_FAILED; - } - - return STATUS_OK; - -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name) { - if (strcmp(name, "CreateEntityContainer") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CUIEntity *ent = new CUIEntity(_gameRef); - if (!val->isNULL()) ent->setName(val->getString()); - stack->pushNative(ent, true); - - ent->_parent = win; - win->_widgets.add(ent); - - return STATUS_OK; - } else return STATUS_FAILED; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::startDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { - char *name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; - if (name) { - sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); - _dlgPendingBranches.add(name); - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::endDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { - char *name = NULL; - bool deleteName = false; - if (branchName == NULL && _dlgPendingBranches.getSize() > 0) { - name = _dlgPendingBranches[_dlgPendingBranches.getSize() - 1]; - } else { - if (branchName != NULL) { - name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; - if (name) { - sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); - deleteName = true; - } - } - } - - if (name == NULL) return STATUS_OK; - - - int startIndex = -1; - for (int i = _dlgPendingBranches.getSize() - 1; i >= 0; i--) { - if (scumm_stricmp(name, _dlgPendingBranches[i]) == 0) { - startIndex = i; - break; - } - } - if (startIndex >= 0) { - for (int i = startIndex; i < _dlgPendingBranches.getSize(); i++) { - //ClearBranchResponses(_dlgPendingBranches[i]); - delete [] _dlgPendingBranches[i]; - _dlgPendingBranches[i] = NULL; - } - _dlgPendingBranches.removeAt(startIndex, _dlgPendingBranches.getSize() - startIndex); - } - - // dialogue is over, forget selected responses - if (_dlgPendingBranches.getSize() == 0) { - for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; - _responsesBranch.removeAll(); - } - - if (deleteName) delete [] name; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::clearBranchResponses(char *name) { - for (int i = 0; i < _responsesBranch.getSize(); i++) { - if (scumm_stricmp(name, _responsesBranch[i]->_context) == 0) { - delete _responsesBranch[i]; - _responsesBranch.removeAt(i); - i--; - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::addBranchResponse(int ID) { - if (branchResponseUsed(ID)) return STATUS_OK; - CAdResponseContext *r = new CAdResponseContext(_gameRef); - r->_iD = ID; - r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); - _responsesBranch.add(r); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::branchResponseUsed(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - for (int i = 0; i < _responsesBranch.getSize(); i++) { - if (_responsesBranch[i]->_iD == ID) { - if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) return true; - } - } - return false; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::addGameResponse(int ID) { - if (gameResponseUsed(ID)) return STATUS_OK; - CAdResponseContext *r = new CAdResponseContext(_gameRef); - r->_iD = ID; - r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); - _responsesGame.add(r); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::gameResponseUsed(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - for (int i = 0; i < _responsesGame.getSize(); i++) { - CAdResponseContext *RespContext = _responsesGame[i]; - if (RespContext->_iD == ID) { - if ((Context == NULL && RespContext->_context == NULL) || ((Context != NULL && RespContext->_context != NULL) && scumm_stricmp(Context, RespContext->_context) == 0)) return true; - } - } - return false; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::resetResponse(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - - int i; - - for (i = 0; i < _responsesGame.getSize(); i++) { - if (_responsesGame[i]->_iD == ID) { - if ((Context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(Context, _responsesGame[i]->_context) == 0) { - delete _responsesGame[i]; - _responsesGame.removeAt(i); - break; - } - } - } - - for (i = 0; i < _responsesBranch.getSize(); i++) { - if (_responsesBranch[i]->_iD == ID) { - if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) { - delete _responsesBranch[i]; - _responsesBranch.removeAt(i); - break; - } - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::displayContent(bool doUpdate, bool displayAll) { - // init - if (doUpdate) initLoop(); - - // fill black - _renderer->fill(0, 0, 0); - if (!_editorMode) _renderer->setScreenViewport(); - - // playing exclusive video? - if (_videoPlayer->isPlaying()) { - if (doUpdate) _videoPlayer->update(); - _videoPlayer->display(); - } else if (_theoraPlayer) { - if (_theoraPlayer->isPlaying()) { - if (doUpdate) _theoraPlayer->update(); - _theoraPlayer->display(); - } - if (_theoraPlayer->isFinished()) { - delete _theoraPlayer; - _theoraPlayer = NULL; - } - } else { - - // process scripts - if (doUpdate) _scEngine->tick(); - - Point32 p; - getMousePos(&p); - - _scene->update(); - _scene->display(); - - - // display in-game windows - displayWindows(true); - if (_inventoryBox) _inventoryBox->display(); - if (_stateEx == GAME_WAITING_RESPONSE) _responseBox->display(); - if (_indicatorDisplay) displayIndicator(); - - - if (doUpdate || displayAll) { - // display normal windows - displayWindows(false); - - setActiveObject(_gameRef->_renderer->getObjectAt(p.x, p.y)); - - // textual info - displaySentences(_state == GAME_FROZEN); - - showCursor(); - - if (_fader) _fader->display(); - _transMgr->update(); - } - - } - if (_loadingIcon) { - _loadingIcon->display(_loadingIconX, _loadingIconY); - if (!_loadingIconPersistent) { - delete _loadingIcon; - _loadingIcon = NULL; - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::registerInventory(CAdInventory *inv) { - for (int i = 0; i < _inventories.getSize(); i++) { - if (_inventories[i] == inv) return STATUS_OK; - } - registerObject(inv); - _inventories.add(inv); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::unregisterInventory(CAdInventory *inv) { - for (int i = 0; i < _inventories.getSize(); i++) { - if (_inventories[i] == inv) { - unregisterObject(_inventories[i]); - _inventories.removeAt(i); - return STATUS_OK; - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::isItemTaken(char *itemName) { - for (int i = 0; i < _inventories.getSize(); i++) { - CAdInventory *Inv = _inventories[i]; - - for (int j = 0; j < Inv->_takenItems.getSize(); j++) { - if (scumm_stricmp(itemName, Inv->_takenItems[j]->_name) == 0) { - return true; - } - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -CAdItem *CAdGame::getItemByName(const char *name) { - for (int i = 0; i < _items.getSize(); i++) { - if (scumm_stricmp(_items[i]->_name, name) == 0) return _items[i]; - } - return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::addItem(CAdItem *item) { - _items.add(item); - return _gameRef->registerObject(item); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::resetContent() { - // clear pending dialogs - for (int i = 0; i < _dlgPendingBranches.getSize(); i++) { - delete [] _dlgPendingBranches[i]; - } - _dlgPendingBranches.removeAll(); - - - // clear inventories - for (int i = 0; i < _inventories.getSize(); i++) { - _inventories[i]->_takenItems.removeAll(); - } - - // clear scene states - for (int i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; - _sceneStates.removeAll(); - - // clear once responses - for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; - _responsesBranch.removeAll(); - - // clear once game responses - for (int i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; - _responsesGame.removeAll(); - - // reload inventory items - if (_itemsFile) loadItemsFile(_itemsFile); - - _tempDisableSaveState = true; - - return CBGame::resetContent(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::deleteItem(CAdItem *item) { - if (!item) return STATUS_FAILED; - - if (_selectedItem == item) _selectedItem = NULL; - _scene->handleItemAssociations(item->_name, false); - - // remove from all inventories - for (int i = 0; i < _inventories.getSize(); i++) { - _inventories[i]->removeItem(item); - } - - // remove object - for (int i = 0; i < _items.getSize(); i++) { - if (_items[i] == item) { - unregisterObject(_items[i]); - _items.removeAt(i); - break; - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::addSpeechDir(const char *dir) { - if (!dir || dir[0] == '\0') return STATUS_FAILED; - - char *temp = new char[strlen(dir) + 2]; - strcpy(temp, dir); - if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') - strcat(temp, "\\"); - - for (int i = 0; i < _speechDirs.getSize(); i++) { - if (scumm_stricmp(_speechDirs[i], temp) == 0) { - delete [] temp; - return STATUS_OK; - } - } - _speechDirs.add(temp); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::removeSpeechDir(const char *dir) { - if (!dir || dir[0] == '\0') return STATUS_FAILED; - - char *temp = new char[strlen(dir) + 2]; - strcpy(temp, dir); - if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') - strcat(temp, "\\"); - - bool Found = false; - for (int i = 0; i < _speechDirs.getSize(); i++) { - if (scumm_stricmp(_speechDirs[i], temp) == 0) { - delete [] _speechDirs[i]; - _speechDirs.removeAt(i); - Found = true; - break; - } - } - delete [] temp; - - if (Found) return STATUS_OK; - else return STATUS_FAILED; -} - - -////////////////////////////////////////////////////////////////////////// -char *CAdGame::findSpeechFile(char *stringID) { - char *ret = new char[MAX_PATH_LENGTH]; - - for (int i = 0; i < _speechDirs.getSize(); i++) { - sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); - Common::SeekableReadStream *file = _fileManager->openFile(ret); // TODO: Replace with hasFile - if (file) { - _fileManager->closeFile(file); - return ret; - } - - sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); - file = _fileManager->openFile(ret); - if (file) { - _fileManager->closeFile(file); - return ret; - } - } - delete [] ret; - return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::validMouse() { - Point32 pos; - CBPlatform::getCursorPos(&pos); - - return _renderer->pointInViewport(&pos); -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseLeftDown() { - if (!validMouse()) return STATUS_OK; - if (_state == GAME_RUNNING && !_interactive) { - if (_talkSkipButton == TALK_SKIP_LEFT || _talkSkipButton == TALK_SKIP_BOTH) { - finishSentences(); - } - return STATUS_OK; - } - - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); - - bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("LeftClick"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("LeftClick"); - } - } - - if (_activeObject != NULL) _gameRef->_capturedObject = _gameRef->_activeObject; - _mouseLeftDown = true; - CBPlatform::setCapture(/*_renderer->_window*/); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseLeftUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); - - CBPlatform::releaseCapture(); - _capturedObject = NULL; - _mouseLeftDown = false; - - bool handled = /*_state==GAME_RUNNING &&*/ DID_SUCCEED(applyEvent("LeftRelease")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("LeftRelease"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("LeftRelease"); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseLeftDblClick() { - if (!validMouse()) return STATUS_OK; - - if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; - - if (_activeObject) _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); - - bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("LeftDoubleClick"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("LeftDoubleClick"); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseRightDown() { - if (!validMouse()) return STATUS_OK; - if (_state == GAME_RUNNING && !_interactive) { - if (_talkSkipButton == TALK_SKIP_RIGHT || _talkSkipButton == TALK_SKIP_BOTH) { - finishSentences(); - } - return STATUS_OK; - } - - if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) return STATUS_OK; - - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); - - bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("RightClick"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("RightClick"); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseRightUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); - - bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("RightRelease"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("RightRelease"); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::displayDebugInfo() { - char str[100]; - if (_gameRef->_debugDebugMode) { - sprintf(str, "Mouse: %d, %d (scene: %d, %d)", _mousePos.x, _mousePos.y, _mousePos.x + _scene->getOffsetLeft(), _mousePos.y + _scene->getOffsetTop()); - _systemFont->drawText((byte *)str, 0, 90, _renderer->_width, TAL_RIGHT); - - sprintf(str, "Scene: %s (prev: %s)", (_scene && _scene->_name) ? _scene->_name : "???", _prevSceneName ? _prevSceneName : "???"); - _systemFont->drawText((byte *)str, 0, 110, _renderer->_width, TAL_RIGHT); - } - return CBGame::displayDebugInfo(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdGame::onScriptShutdown(CScScript *script) { - if (_responseBox && _responseBox->_waitingScript == script) - _responseBox->_waitingScript = NULL; - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdGame.h b/engines/wintermute/ad/AdGame.h deleted file mode 100644 index 4a89fa97d2..0000000000 --- a/engines/wintermute/ad/AdGame.h +++ /dev/null @@ -1,161 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ -#ifndef WINTERMUTE_ADGAME_H -#define WINTERMUTE_ADGAME_H - -#include "engines/wintermute/ad/AdTypes.h" -#include "engines/wintermute/base/BGame.h" - -namespace WinterMute { -class CAdItem; -class CAdInventory; -class CAdSceneState; -class CAdScene; -class CAdItem; -class CAdObject; -class CAdSentence; -class CAdInventoryBox; -class CAdResponseContext; -class CAdResponseBox; -class CAdGame : public CBGame { -public: - virtual bool onScriptShutdown(CScScript *script); - - virtual bool onMouseLeftDown(); - virtual bool onMouseLeftUp(); - virtual bool onMouseLeftDblClick(); - virtual bool onMouseRightDown(); - virtual bool onMouseRightUp(); - - virtual bool displayDebugInfo(); - - - virtual bool initAfterLoad(); - static void afterLoadScene(void *scene, void *data); - - bool _smartItemCursor; - - CBArray _speechDirs; - bool addSpeechDir(const char *dir); - bool removeSpeechDir(const char *dir); - char *findSpeechFile(char *StringID); - - bool deleteItem(CAdItem *Item); - char *_itemsFile; - bool _tempDisableSaveState; - virtual bool resetContent(); - bool addItem(CAdItem *item); - CAdItem *getItemByName(const char *name); - CBArray _items; - CAdObject *_inventoryOwner; - bool isItemTaken(char *itemName); - bool registerInventory(CAdInventory *inv); - bool unregisterInventory(CAdInventory *inv); - - CAdObject *_invObject; - CBArray _inventories; - virtual bool displayContent(bool update = true, bool displayAll = false); - char *_debugStartupScene; - char *_startupScene; - bool _initialScene; - bool gameResponseUsed(int ID); - bool addGameResponse(int ID); - bool resetResponse(int ID); - - bool branchResponseUsed(int ID); - bool addBranchResponse(int ID); - bool clearBranchResponses(char *name); - bool startDlgBranch(const char *branchName, const char *scriptName, const char *eventName); - bool endDlgBranch(const char *branchName, const char *scriptName, const char *eventName); - virtual bool windowLoadHook(CUIWindow *win, char **buf, char **params); - virtual bool windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name); - - CAdSceneState *getSceneState(const char *filename, bool saving); - CBViewport *_sceneViewport; - int _texItemLifeTime; - int _texWalkLifeTime; - int _texStandLifeTime; - int _texTalkLifeTime; - - TTalkSkipButton _talkSkipButton; - - virtual bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor); - bool scheduleChangeScene(const char *filename, bool fadeIn); - char *_scheduledScene; - bool _scheduledFadeIn; - void setPrevSceneName(const char *name); - void setPrevSceneFilename(const char *name); - char *_prevSceneName; - char *_prevSceneFilename; - virtual bool loadGame(const char *filename); - CAdItem *_selectedItem; - bool cleanup(); - DECLARE_PERSISTENT(CAdGame, CBGame) - - void finishSentences(); - bool showCursor(); - TGameStateEx _stateEx; - CAdResponseBox *_responseBox; - CAdInventoryBox *_inventoryBox; - bool displaySentences(bool frozen); - void addSentence(CAdSentence *sentence); - bool changeScene(const char *filename, bool fadeIn); - bool removeObject(CAdObject *object); - bool addObject(CAdObject *object); - CAdScene *_scene; - bool initLoop(); - CAdGame(); - virtual ~CAdGame(); - CBArray _objects; - CBArray _sentences; - - CBArray _sceneStates; - CBArray _dlgPendingBranches; - - CBArray _responsesBranch; - CBArray _responsesGame; - - virtual bool loadFile(const char *filename); - virtual bool loadBuffer(byte *buffer, bool complete = true); - - bool loadItemsFile(const char *filename, bool merge = false); - bool loadItemsBuffer(byte *buffer, bool merge = false); - - - virtual bool ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name); - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - bool validMouse(); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdInventory.cpp b/engines/wintermute/ad/AdInventory.cpp deleted file mode 100644 index f913108404..0000000000 --- a/engines/wintermute/ad/AdInventory.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/AdInventory.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdItem.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdInventory, false) - -////////////////////////////////////////////////////////////////////////// -CAdInventory::CAdInventory(CBGame *inGame): CBObject(inGame) { - _scrollOffset = 0; -} - - -////////////////////////////////////////////////////////////////////////// -CAdInventory::~CAdInventory() { - _takenItems.removeAll(); // ref only -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdInventory::insertItem(const char *name, const char *insertAfter) { - if (name == NULL) return STATUS_FAILED; - - CAdItem *item = ((CAdGame *)_gameRef)->getItemByName(name); - if (item == NULL) return STATUS_FAILED; - - int insertIndex = -1; - for (int i = 0; i < _takenItems.getSize(); i++) { - if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { - _takenItems.removeAt(i); - i--; - continue; - } - if (insertAfter && scumm_stricmp(_takenItems[i]->_name, insertAfter) == 0) insertIndex = i + 1; - } - - - if (insertIndex == -1) _takenItems.add(item); - else _takenItems.insertAt(insertIndex, item); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdInventory::removeItem(const char *name) { - if (name == NULL) return STATUS_FAILED; - - for (int i = 0; i < _takenItems.getSize(); i++) { - if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { - if (((CAdGame *)_gameRef)->_selectedItem == _takenItems[i])((CAdGame *)_gameRef)->_selectedItem = NULL; - _takenItems.removeAt(i); - return STATUS_OK; - } - } - - return STATUS_FAILED; -} - - - -////////////////////////////////////////////////////////////////////////// -bool CAdInventory::removeItem(CAdItem *item) { - if (item == NULL) return STATUS_FAILED; - - for (int i = 0; i < _takenItems.getSize(); i++) { - if (_takenItems[i] == item) { - if (((CAdGame *)_gameRef)->_selectedItem == _takenItems[i])((CAdGame *)_gameRef)->_selectedItem = NULL; - _takenItems.removeAt(i); - return STATUS_OK; - } - } - - return STATUS_FAILED; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdInventory::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - _takenItems.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scrollOffset)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdInventory.h b/engines/wintermute/ad/AdInventory.h deleted file mode 100644 index cec76c03a0..0000000000 --- a/engines/wintermute/ad/AdInventory.h +++ /dev/null @@ -1,52 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADINVENTORY_H -#define WINTERMUTE_ADINVENTORY_H - -#include "engines/wintermute/base/BObject.h" - -namespace WinterMute { - -class CAdItem; - -class CAdInventory : public CBObject { -public: - DECLARE_PERSISTENT(CAdInventory, CBObject) - bool removeItem(const char *name); - bool removeItem(CAdItem *Item); - bool insertItem(const char *name, const char *insertAfter = NULL); - CAdInventory(CBGame *inGame); - virtual ~CAdInventory(); - CBArray _takenItems; - int _scrollOffset; -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdInventoryBox.cpp b/engines/wintermute/ad/AdInventoryBox.cpp deleted file mode 100644 index 9509bf9b10..0000000000 --- a/engines/wintermute/ad/AdInventoryBox.cpp +++ /dev/null @@ -1,372 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdInventoryBox.h" -#include "engines/wintermute/ad/AdInventory.h" -#include "engines/wintermute/ad/AdItem.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/base/BViewport.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/ui/UIButton.h" -#include "engines/wintermute/ui/UIWindow.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" -#include "common/rect.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdInventoryBox, false) - -////////////////////////////////////////////////////////////////////////// -CAdInventoryBox::CAdInventoryBox(CBGame *inGame): CBObject(inGame) { - _itemsArea.setEmpty(); - _scrollOffset = 0; - _spacing = 0; - _itemWidth = _itemHeight = 50; - _scrollBy = 1; - - _window = NULL; - _closeButton = NULL; - - _hideSelected = false; - - _visible = false; - _exclusive = false; -} - - -////////////////////////////////////////////////////////////////////////// -CAdInventoryBox::~CAdInventoryBox() { - _gameRef->unregisterObject(_window); - _window = NULL; - - delete _closeButton; - _closeButton = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::listen(CBScriptHolder *param1, uint32 param2) { - CUIObject *obj = (CUIObject *)param1; - - switch (obj->_type) { - case UI_BUTTON: - if (scumm_stricmp(obj->_name, "close") == 0) { - _visible = false; - } else if (scumm_stricmp(obj->_name, "prev") == 0) { - _scrollOffset -= _scrollBy; - _scrollOffset = MAX(_scrollOffset, 0); - } else if (scumm_stricmp(obj->_name, "next") == 0) { - _scrollOffset += _scrollBy; - } else return CBObject::listen(param1, param2); - break; - default: - error("CAdInventoryBox::Listen - Unhandled enum"); - break; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::display() { - CAdGame *adGame = (CAdGame *)_gameRef; - - if (!_visible) return STATUS_OK; - - int itemsX, itemsY; - itemsX = (int)floor((float)((_itemsArea.right - _itemsArea.left + _spacing) / (_itemWidth + _spacing))); - itemsY = (int)floor((float)((_itemsArea.bottom - _itemsArea.top + _spacing) / (_itemHeight + _spacing))); - - if (_window) { - _window->enableWidget("prev", _scrollOffset > 0); - _window->enableWidget("next", _scrollOffset + itemsX * itemsY < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()); - } - - - if (_closeButton) { - _closeButton->_posX = _closeButton->_posY = 0; - _closeButton->_width = _gameRef->_renderer->_width; - _closeButton->_height = _gameRef->_renderer->_height; - - _closeButton->display(); - } - - - // display window - Rect32 rect = _itemsArea; - if (_window) { - rect.offsetRect(_window->_posX, _window->_posY); - _window->display(); - } - - // display items - if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; - int yyy = rect.top; - for (int j = 0; j < itemsY; j++) { - int xxx = rect.left; - for (int i = 0; i < itemsX; i++) { - int itemIndex = _scrollOffset + j * itemsX + i; - if (itemIndex >= 0 && itemIndex < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()) { - CAdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex]; - if (item != ((CAdGame *)_gameRef)->_selectedItem || !_hideSelected) { - item->update(); - item->display(xxx, yyy); - } - } - - xxx += (_itemWidth + _spacing); - } - yyy += (_itemHeight + _spacing); - } - if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = 0; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdInventoryBox::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(INVENTORY_BOX) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(WINDOW) -TOKEN_DEF(EXCLUSIVE) -TOKEN_DEF(ALWAYS_VISIBLE) -TOKEN_DEF(AREA) -TOKEN_DEF(SPACING) -TOKEN_DEF(ITEM_WIDTH) -TOKEN_DEF(ITEM_HEIGHT) -TOKEN_DEF(SCROLL_BY) -TOKEN_DEF(NAME) -TOKEN_DEF(CAPTION) -TOKEN_DEF(HIDE_SELECTED) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(INVENTORY_BOX) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(WINDOW) - TOKEN_TABLE(EXCLUSIVE) - TOKEN_TABLE(ALWAYS_VISIBLE) - TOKEN_TABLE(AREA) - TOKEN_TABLE(SPACING) - TOKEN_TABLE(ITEM_WIDTH) - TOKEN_TABLE(ITEM_HEIGHT) - TOKEN_TABLE(SCROLL_BY) - TOKEN_TABLE(NAME) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(HIDE_SELECTED) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd = 2; - CBParser parser(_gameRef); - bool always_visible = false; - - _exclusive = false; - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_INVENTORY_BOX) { - _gameRef->LOG(0, "'INVENTORY_BOX' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_WINDOW: - delete _window; - _window = new CUIWindow(_gameRef); - if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { - delete _window; - _window = NULL; - cmd = PARSERR_GENERIC; - } else _gameRef->registerObject(_window); - break; - - case TOKEN_AREA: - parser.scanStr((char *)params, "%d,%d,%d,%d", &_itemsArea.left, &_itemsArea.top, &_itemsArea.right, &_itemsArea.bottom); - break; - - case TOKEN_EXCLUSIVE: - parser.scanStr((char *)params, "%b", &_exclusive); - break; - - case TOKEN_HIDE_SELECTED: - parser.scanStr((char *)params, "%b", &_hideSelected); - break; - - case TOKEN_ALWAYS_VISIBLE: - parser.scanStr((char *)params, "%b", &always_visible); - break; - - case TOKEN_SPACING: - parser.scanStr((char *)params, "%d", &_spacing); - break; - - case TOKEN_ITEM_WIDTH: - parser.scanStr((char *)params, "%d", &_itemWidth); - break; - - case TOKEN_ITEM_HEIGHT: - parser.scanStr((char *)params, "%d", &_itemHeight); - break; - - case TOKEN_SCROLL_BY: - parser.scanStr((char *)params, "%d", &_scrollBy); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in INVENTORY_BOX definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading INVENTORY_BOX definition"); - return STATUS_FAILED; - } - - if (_exclusive) { - delete _closeButton; - _closeButton = new CUIButton(_gameRef); - if (_closeButton) { - _closeButton->setName("close"); - _closeButton->setListener(this, _closeButton, 0); - _closeButton->_parent = _window; - } - } - - _visible = always_visible; - - if (_window) { - for (int i = 0; i < _window->_widgets.getSize(); i++) { - if (!_window->_widgets[i]->_listenerObject) - _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "INVENTORY_BOX\n"); - buffer->putTextIndent(indent, "{\n"); - - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - - buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _itemsArea.left, _itemsArea.top, _itemsArea.right, _itemsArea.bottom); - - buffer->putTextIndent(indent + 2, "EXCLUSIVE=%s\n", _exclusive ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "HIDE_SELECTED=%s\n", _hideSelected ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "ALWAYS_VISIBLE=%s\n", _visible ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); - buffer->putTextIndent(indent + 2, "ITEM_WIDTH=%d\n", _itemWidth); - buffer->putTextIndent(indent + 2, "ITEM_HEIGHT=%d\n", _itemHeight); - buffer->putTextIndent(indent + 2, "SCROLL_BY=%d\n", _scrollBy); - - buffer->putTextIndent(indent + 2, "\n"); - - // window - if (_window) _window->saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent + 2, "\n"); - - // editor properties - CBBase::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::persist(CBPersistMgr *persistMgr) { - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_closeButton)); - persistMgr->transfer(TMEMBER(_hideSelected)); - persistMgr->transfer(TMEMBER(_itemHeight)); - persistMgr->transfer(TMEMBER(_itemsArea)); - persistMgr->transfer(TMEMBER(_itemWidth)); - persistMgr->transfer(TMEMBER(_scrollBy)); - persistMgr->transfer(TMEMBER(_scrollOffset)); - persistMgr->transfer(TMEMBER(_spacing)); - persistMgr->transfer(TMEMBER(_visible)); - persistMgr->transfer(TMEMBER(_window)); - persistMgr->transfer(TMEMBER(_exclusive)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdInventoryBox.h b/engines/wintermute/ad/AdInventoryBox.h deleted file mode 100644 index cfd8d74021..0000000000 --- a/engines/wintermute/ad/AdInventoryBox.h +++ /dev/null @@ -1,64 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADINVENTORYBOX_H -#define WINTERMUTE_ADINVENTORYBOX_H - -#include "engines/wintermute/base/BObject.h" -#include "common/rect.h" - -namespace WinterMute { -class CUIButton; -class CUIWindow; - -class CAdInventoryBox : public CBObject { -public: - bool _hideSelected; - DECLARE_PERSISTENT(CAdInventoryBox, CBObject) - bool _exclusive; - int _scrollBy; - int _itemHeight; - int _itemWidth; - bool _visible; - virtual bool display(); - CUIButton *_closeButton; - int _spacing; - int _scrollOffset; - Rect32 _itemsArea; - bool listen(CBScriptHolder *param1, uint32 param2); - CUIWindow *_window; - CAdInventoryBox(CBGame *inGame); - virtual ~CAdInventoryBox(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdItem.cpp b/engines/wintermute/ad/AdItem.cpp deleted file mode 100644 index 0e443d5c3e..0000000000 --- a/engines/wintermute/ad/AdItem.cpp +++ /dev/null @@ -1,760 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdItem.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdSentence.h" -#include "engines/wintermute/base/font/BFontStorage.h" -#include "engines/wintermute/base/font/BFont.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BSound.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdItem, false) - -////////////////////////////////////////////////////////////////////////// -CAdItem::CAdItem(CBGame *inGame): CAdTalkHolder(inGame) { - _spriteHover = NULL; - _cursorNormal = _cursorHover = NULL; - - _cursorCombined = true; - _inInventory = false; - - _displayAmount = false; - _amount = 0; - _amountOffsetX = 0; - _amountOffsetY = 0; - _amountAlign = TAL_RIGHT; - _amountString = NULL; - - _state = STATE_READY; - - _movable = false; -} - - -////////////////////////////////////////////////////////////////////////// -CAdItem::~CAdItem() { - delete _spriteHover; - delete _cursorNormal; - delete _cursorHover; - _spriteHover = NULL; - _cursorNormal = NULL; - _cursorHover = NULL; - - delete[] _amountString; - _amountString = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdItem::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdItem::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(ITEM) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(CURSOR_HOVER) -TOKEN_DEF(CURSOR_COMBINED) -TOKEN_DEF(CURSOR) -TOKEN_DEF(NAME) -TOKEN_DEF(IMAGE_HOVER) -TOKEN_DEF(IMAGE) -TOKEN_DEF(EVENTS) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF(FONT) -TOKEN_DEF(ALPHA_COLOR) -TOKEN_DEF(ALPHA) -TOKEN_DEF(TALK_SPECIAL) -TOKEN_DEF(TALK) -TOKEN_DEF(SPRITE_HOVER) -TOKEN_DEF(SPRITE) -TOKEN_DEF(DISPLAY_AMOUNT) -TOKEN_DEF(AMOUNT_OFFSET_X) -TOKEN_DEF(AMOUNT_OFFSET_Y) -TOKEN_DEF(AMOUNT_ALIGN) -TOKEN_DEF(AMOUNT_STRING) -TOKEN_DEF(AMOUNT) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdItem::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ITEM) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(CURSOR_HOVER) - TOKEN_TABLE(CURSOR_COMBINED) - TOKEN_TABLE(CURSOR) - TOKEN_TABLE(NAME) - TOKEN_TABLE(IMAGE_HOVER) - TOKEN_TABLE(IMAGE) - TOKEN_TABLE(EVENTS) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE(FONT) - TOKEN_TABLE(ALPHA_COLOR) - TOKEN_TABLE(ALPHA) - TOKEN_TABLE(TALK_SPECIAL) - TOKEN_TABLE(TALK) - TOKEN_TABLE(SPRITE_HOVER) - TOKEN_TABLE(SPRITE) - TOKEN_TABLE(DISPLAY_AMOUNT) - TOKEN_TABLE(AMOUNT_OFFSET_X) - TOKEN_TABLE(AMOUNT_OFFSET_Y) - TOKEN_TABLE(AMOUNT_ALIGN) - TOKEN_TABLE(AMOUNT_STRING) - TOKEN_TABLE(AMOUNT) - TOKEN_TABLE_END - - byte *params; - int cmd = 2; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ITEM) { - _gameRef->LOG(0, "'ITEM' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - int ar = 0, ag = 0, ab = 0, alpha = 255; - while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_FONT: - SetFont((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_IMAGE: - case TOKEN_SPRITE: - delete _sprite; - _sprite = new CBSprite(_gameRef, this); - if (!_sprite || DID_FAIL(_sprite->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { - delete _sprite; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_IMAGE_HOVER: - case TOKEN_SPRITE_HOVER: - delete _spriteHover; - _spriteHover = new CBSprite(_gameRef, this); - if (!_spriteHover || DID_FAIL(_spriteHover->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { - delete _spriteHover; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_AMOUNT: - parser.scanStr((char *)params, "%d", &_amount); - break; - - case TOKEN_DISPLAY_AMOUNT: - parser.scanStr((char *)params, "%b", &_displayAmount); - break; - - case TOKEN_AMOUNT_OFFSET_X: - parser.scanStr((char *)params, "%d", &_amountOffsetX); - break; - - case TOKEN_AMOUNT_OFFSET_Y: - parser.scanStr((char *)params, "%d", &_amountOffsetY); - break; - - case TOKEN_AMOUNT_ALIGN: - if (scumm_stricmp((char *)params, "left") == 0) _amountAlign = TAL_LEFT; - else if (scumm_stricmp((char *)params, "right") == 0) _amountAlign = TAL_RIGHT; - else _amountAlign = TAL_CENTER; - break; - - case TOKEN_AMOUNT_STRING: - CBUtils::setString(&_amountString, (char *)params); - break; - - case TOKEN_TALK: { - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((CAdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); - } - break; - - case TOKEN_TALK_SPECIAL: { - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((CAdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); - } - break; - - case TOKEN_CURSOR: - delete _cursorNormal; - _cursorNormal = new CBSprite(_gameRef); - if (!_cursorNormal || DID_FAIL(_cursorNormal->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { - delete _cursorNormal; - _cursorNormal = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_CURSOR_HOVER: - delete _cursorHover; - _cursorHover = new CBSprite(_gameRef); - if (!_cursorHover || DID_FAIL(_cursorHover->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { - delete _cursorHover; - _cursorHover = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_CURSOR_COMBINED: - parser.scanStr((char *)params, "%b", &_cursorCombined); - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - 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; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ITEM definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading ITEM definition"); - return STATUS_FAILED; - } - - if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { - ar = ag = ab = 255; - } - _alphaColor = BYTETORGBA(ar, ag, ab, alpha); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdItem::update() { - _currentSprite = NULL; - - if (_state == STATE_READY && _animSprite) { - delete _animSprite; - _animSprite = NULL; - } - - // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { - _state = STATE_READY; - _currentSprite = _animSprite; - } - - if (_sentence && _state != STATE_TALKING) _sentence->finish(); - - // default: stand animation - if (!_currentSprite) _currentSprite = _sprite; - - switch (_state) { - ////////////////////////////////////////////////////////////////////////// - case STATE_PLAYING_ANIM: - _currentSprite = _animSprite; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_READY: - if (!_animSprite) { - if (_gameRef->_activeObject == this && _spriteHover) _currentSprite = _spriteHover; - else _currentSprite = _sprite; - } - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_TALKING: { - _sentence->update(); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; - - bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { - if (TimeIsUp) { - _sentence->finish(); - _tempSprite2 = NULL; - _state = STATE_READY; - } else { - _tempSprite2 = getTalkStance(_sentence->getNextStance()); - if (_tempSprite2) { - _tempSprite2->reset(); - _currentSprite = _tempSprite2; - } - ((CAdGame *)_gameRef)->addSentence(_sentence); - } - } else { - _currentSprite = _tempSprite2; - ((CAdGame *)_gameRef)->addSentence(_sentence); - } - } - default: - break; - } - _ready = (_state == STATE_READY); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdItem::display(int x, int y) { - int width = 0; - if (_currentSprite) { - Rect32 rc; - _currentSprite->getBoundingRect(&rc, 0, 0); - width = rc.width(); - } - - _posX = x + width / 2; - _posY = y; - - bool ret; - if (_currentSprite) - ret = _currentSprite->draw(x, y, this, 100, 100, _alphaColor); - else ret = STATUS_OK; - - if (_displayAmount) { - int amountX = x; - int amountY = y + _amountOffsetY; - - if (_amountAlign == TAL_RIGHT) { - width -= _amountOffsetX; - amountX -= _amountOffsetX; - } - amountX += _amountOffsetX; - - CBFont *font = _font ? _font : _gameRef->_systemFont; - if (font) { - if (_amountString) font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); - else { - char Str[256]; - sprintf(Str, "%d", _amount); - font->drawText((byte *)Str, amountX, amountY, width, _amountAlign); - } - } - } - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdItem::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // SetHoverSprite - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SetHoverSprite") == 0) { - stack->correctParams(1); - - bool setCurrent = false; - if (_currentSprite && _currentSprite == _spriteHover) setCurrent = true; - - const char *filename = stack->pop()->getString(); - - delete _spriteHover; - _spriteHover = NULL; - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("Item.SetHoverSprite failed for file '%s'", filename); - } else { - _spriteHover = spr; - if (setCurrent) _currentSprite = _spriteHover; - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetHoverSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetHoverSprite") == 0) { - stack->correctParams(0); - - if (!_spriteHover || !_spriteHover->_filename) stack->pushNULL(); - else stack->pushString(_spriteHover->_filename); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetHoverSpriteObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetHoverSpriteObject") == 0) { - stack->correctParams(0); - if (!_spriteHover) stack->pushNULL(); - else stack->pushNative(_spriteHover, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetNormalCursor - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SetNormalCursor") == 0) { - stack->correctParams(1); - - const char *filename = stack->pop()->getString(); - - delete _cursorNormal; - _cursorNormal = NULL; - CBSprite *spr = new CBSprite(_gameRef); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("Item.SetNormalCursor failed for file '%s'", filename); - } else { - _cursorNormal = spr; - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetNormalCursor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetNormalCursor") == 0) { - stack->correctParams(0); - - if (!_cursorNormal || !_cursorNormal->_filename) stack->pushNULL(); - else stack->pushString(_cursorNormal->_filename); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetNormalCursorObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetNormalCursorObject") == 0) { - stack->correctParams(0); - - if (!_cursorNormal) stack->pushNULL(); - else stack->pushNative(_cursorNormal, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetHoverCursor - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SetHoverCursor") == 0) { - stack->correctParams(1); - - const char *filename = stack->pop()->getString(); - - delete _cursorHover; - _cursorHover = NULL; - CBSprite *spr = new CBSprite(_gameRef); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("Item.SetHoverCursor failed for file '%s'", filename); - } else { - _cursorHover = spr; - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetHoverCursor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetHoverCursor") == 0) { - stack->correctParams(0); - - if (!_cursorHover || !_cursorHover->_filename) stack->pushNULL(); - else stack->pushString(_cursorHover->_filename); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetHoverCursorObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetHoverCursorObject") == 0) { - stack->correctParams(0); - - if (!_cursorHover) stack->pushNULL(); - else stack->pushNative(_cursorHover, true); - return STATUS_OK; - } - - else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdItem::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("item"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Name") == 0) { - _scValue->setString(_name); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // DisplayAmount - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DisplayAmount") == 0) { - _scValue->setBool(_displayAmount); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Amount - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Amount") == 0) { - _scValue->setInt(_amount); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountOffsetX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetX") == 0) { - _scValue->setInt(_amountOffsetX); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountOffsetY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetY") == 0) { - _scValue->setInt(_amountOffsetY); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountAlign - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountAlign") == 0) { - _scValue->setInt(_amountAlign); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountString - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountString") == 0) { - if (!_amountString) _scValue->setNULL(); - else _scValue->setString(_amountString); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // CursorCombined - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CursorCombined") == 0) { - _scValue->setBool(_cursorCombined); - return _scValue; - } - - else return CAdTalkHolder::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdItem::scSetProperty(const char *name, CScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Name") == 0) { - setName(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DisplayAmount - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DisplayAmount") == 0) { - _displayAmount = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Amount - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Amount") == 0) { - _amount = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountOffsetX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetX") == 0) { - _amountOffsetX = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountOffsetY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetY") == 0) { - _amountOffsetY = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountAlign - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountAlign") == 0) { - _amountAlign = (TTextAlign)value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountString - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountString") == 0) { - if (value->isNULL()) { - delete[] _amountString; - _amountString = NULL; - } else { - CBUtils::setString(&_amountString, value->getString()); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CursorCombined - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CursorCombined") == 0) { - _cursorCombined = value->getBool(); - return STATUS_OK; - } - - else return CAdTalkHolder::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *CAdItem::scToString() { - return "[item]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdItem::persist(CBPersistMgr *persistMgr) { - - CAdTalkHolder::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_cursorCombined)); - persistMgr->transfer(TMEMBER(_cursorHover)); - persistMgr->transfer(TMEMBER(_cursorNormal)); - persistMgr->transfer(TMEMBER(_spriteHover)); - persistMgr->transfer(TMEMBER(_inInventory)); - persistMgr->transfer(TMEMBER(_displayAmount)); - persistMgr->transfer(TMEMBER(_amount)); - persistMgr->transfer(TMEMBER(_amountOffsetX)); - persistMgr->transfer(TMEMBER(_amountOffsetY)); - persistMgr->transfer(TMEMBER_INT(_amountAlign)); - persistMgr->transfer(TMEMBER(_amountString)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdItem::getExtendedFlag(const char *flagName) { - if (!flagName) return false; - else if (strcmp(flagName, "usable") == 0) return true; - else return CAdObject::getExtendedFlag(flagName); -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdItem.h b/engines/wintermute/ad/AdItem.h deleted file mode 100644 index d45f9cc614..0000000000 --- a/engines/wintermute/ad/AdItem.h +++ /dev/null @@ -1,70 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADITEM_H -#define WINTERMUTE_ADITEM_H - - -#include "engines/wintermute/ad/AdTalkHolder.h" - -namespace WinterMute { - -class CAdItem : public CAdTalkHolder { -public: - bool _displayAmount; - int _amount; - int _amountOffsetX; - int _amountOffsetY; - TTextAlign _amountAlign; - char *_amountString; - - - bool update(); - DECLARE_PERSISTENT(CAdItem, CAdTalkHolder) - bool display(int x, int y); - bool getExtendedFlag(const char *flagName); - bool _inInventory; - bool _cursorCombined; - CBSprite *_spriteHover; - CBSprite *_cursorNormal; - CBSprite *_cursorHover; - CAdItem(CBGame *inGame); - virtual ~CAdItem(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - virtual const char *scToString(); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdLayer.cpp b/engines/wintermute/ad/AdLayer.cpp deleted file mode 100644 index 4549ba4af7..0000000000 --- a/engines/wintermute/ad/AdLayer.cpp +++ /dev/null @@ -1,537 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/ad/AdLayer.h" -#include "engines/wintermute/ad/AdSceneNode.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdLayer, false) - -////////////////////////////////////////////////////////////////////////// -CAdLayer::CAdLayer(CBGame *inGame): CBObject(inGame) { - _main = false; - _width = _height = 0; - _active = true; - _closeUp = false; -} - - -////////////////////////////////////////////////////////////////////////// -CAdLayer::~CAdLayer() { - for (int i = 0; i < _nodes.getSize(); i++) - delete _nodes[i]; - _nodes.removeAll(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdLayer::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdLayer::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(LAYER) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(NAME) -TOKEN_DEF(WIDTH) -TOKEN_DEF(HEIGHT) -TOKEN_DEF(MAIN) -TOKEN_DEF(ENTITY) -TOKEN_DEF(REGION) -TOKEN_DEF(ACTIVE) -TOKEN_DEF(EDITOR_SELECTED) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(CLOSE_UP) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdLayer::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(LAYER) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(NAME) - TOKEN_TABLE(WIDTH) - TOKEN_TABLE(HEIGHT) - TOKEN_TABLE(MAIN) - TOKEN_TABLE(ENTITY) - TOKEN_TABLE(REGION) - TOKEN_TABLE(ACTIVE) - TOKEN_TABLE(EDITOR_SELECTED) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(CLOSE_UP) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_LAYER) { - _gameRef->LOG(0, "'LAYER' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_MAIN: - parser.scanStr((char *)params, "%b", &_main); - break; - - case TOKEN_CLOSE_UP: - parser.scanStr((char *)params, "%b", &_closeUp); - break; - - case TOKEN_WIDTH: - parser.scanStr((char *)params, "%d", &_width); - break; - - case TOKEN_HEIGHT: - parser.scanStr((char *)params, "%d", &_height); - break; - - case TOKEN_ACTIVE: - parser.scanStr((char *)params, "%b", &_active); - break; - - case TOKEN_REGION: { - CAdRegion *region = new CAdRegion(_gameRef); - CAdSceneNode *node = new CAdSceneNode(_gameRef); - if (!region || !node || DID_FAIL(region->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete region; - delete node; - region = NULL; - node = NULL; - } else { - node->setRegion(region); - _nodes.add(node); - } - } - break; - - case TOKEN_ENTITY: { - CAdEntity *entity = new CAdEntity(_gameRef); - CAdSceneNode *node = new CAdSceneNode(_gameRef); - if (entity) entity->_zoomable = false; // scene entites default to NOT zoom - if (!entity || !node || DID_FAIL(entity->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete entity; - delete node; - entity = NULL; - node = NULL; - } else { - node->setEntity(entity); - _nodes.add(node); - } - } - break; - - case TOKEN_EDITOR_SELECTED: - parser.scanStr((char *)params, "%b", &_editorSelected); - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in LAYER definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdLayer::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // GetNode - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "GetNode") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - int node = -1; - - if (val->_type == VAL_INT) node = val->getInt(); - else { // get by name - for (int i = 0; i < _nodes.getSize(); i++) { - if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->_name, val->getString()) == 0) || - (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->_name, val->getString()) == 0)) { - node = i; - break; - } - } - } - - if (node < 0 || node >= _nodes.getSize()) stack->pushNULL(); - else { - switch (_nodes[node]->_type) { - case OBJECT_ENTITY: - stack->pushNative(_nodes[node]->_entity, true); - break; - case OBJECT_REGION: - stack->pushNative(_nodes[node]->_region, true); - break; - default: - stack->pushNULL(); - } - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddRegion / AddEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddRegion") == 0 || strcmp(name, "AddEntity") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdSceneNode *node = new CAdSceneNode(_gameRef); - if (strcmp(name, "AddRegion") == 0) { - CAdRegion *region = new CAdRegion(_gameRef); - if (!val->isNULL()) region->setName(val->getString()); - node->setRegion(region); - stack->pushNative(region, true); - } else { - CAdEntity *entity = new CAdEntity(_gameRef); - if (!val->isNULL()) entity->setName(val->getString()); - node->setEntity(entity); - stack->pushNative(entity, true); - } - _nodes.add(node); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InsertRegion / InsertEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InsertRegion") == 0 || strcmp(name, "InsertEntity") == 0) { - stack->correctParams(2); - int index = stack->pop()->getInt(); - CScValue *val = stack->pop(); - - CAdSceneNode *node = new CAdSceneNode(_gameRef); - if (strcmp(name, "InsertRegion") == 0) { - CAdRegion *region = new CAdRegion(_gameRef); - if (!val->isNULL()) region->setName(val->getString()); - node->setRegion(region); - stack->pushNative(region, true); - } else { - CAdEntity *entity = new CAdEntity(_gameRef); - if (!val->isNULL()) entity->setName(val->getString()); - node->setEntity(entity); - stack->pushNative(entity, true); - } - if (index < 0) index = 0; - if (index <= _nodes.getSize() - 1) _nodes.insertAt(index, node); - else _nodes.add(node); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteNode - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteNode") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdSceneNode *toDelete = NULL; - if (val->isNative()) { - CBScriptable *temp = val->getNative(); - for (int i = 0; i < _nodes.getSize(); i++) { - if (_nodes[i]->_region == temp || _nodes[i]->_entity == temp) { - toDelete = _nodes[i]; - break; - } - } - } else { - int index = val->getInt(); - if (index >= 0 && index < _nodes.getSize()) { - toDelete = _nodes[index]; - } - } - if (toDelete == NULL) { - stack->pushBool(false); - return STATUS_OK; - } - - for (int i = 0; i < _nodes.getSize(); i++) { - if (_nodes[i] == toDelete) { - delete _nodes[i]; - _nodes[i] = NULL; - _nodes.removeAt(i); - break; - } - } - stack->pushBool(true); - return STATUS_OK; - } - - else return CBObject::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdLayer::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("layer"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumNodes (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumNodes") == 0) { - _scValue->setInt(_nodes.getSize()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Width - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Width") == 0) { - _scValue->setInt(_width); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Height - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Height") == 0) { - _scValue->setInt(_height); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Main (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Main") == 0) { - _scValue->setBool(_main); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // CloseUp - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CloseUp") == 0) { - _scValue->setBool(_closeUp); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { - _scValue->setBool(_active); - return _scValue; - } - - else return CBObject::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdLayer::scSetProperty(const char *name, CScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Name") == 0) { - setName(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CloseUp - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CloseUp") == 0) { - _closeUp = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Width - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Width") == 0) { - _width = value->getInt(); - if (_width < 0) _width = 0; - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Height - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Height") == 0) { - _height = value->getInt(); - if (_height < 0) _height = 0; - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { - bool b = value->getBool(); - if (b == false && _main) { - _gameRef->LOG(0, "Warning: cannot deactivate scene's main layer"); - } else _active = b; - return STATUS_OK; - } - - else return CBObject::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *CAdLayer::scToString() { - return "[layer]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdLayer::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "LAYER {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - buffer->putTextIndent(indent + 2, "MAIN=%s\n", _main ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "WIDTH=%d\n", _width); - buffer->putTextIndent(indent + 2, "HEIGHT=%d\n", _height); - buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - if (_closeUp) - buffer->putTextIndent(indent + 2, "CLOSE_UP=%s\n", _closeUp ? "TRUE" : "FALSE"); - - int i; - - for (i = 0; i < _scripts.getSize(); i++) { - buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); - } - - if (_scProp) _scProp->saveAsText(buffer, indent + 2); - - for (i = 0; i < _nodes.getSize(); i++) { - switch (_nodes[i]->_type) { - case OBJECT_ENTITY: - _nodes[i]->_entity->saveAsText(buffer, indent + 2); - break; - case OBJECT_REGION: - _nodes[i]->_region->saveAsText(buffer, indent + 2); - break; - default: - error("CAdLayer::SaveAsText - Unhandled enum"); - break; - } - } - - CBBase::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdLayer::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_active)); - persistMgr->transfer(TMEMBER(_closeUp)); - persistMgr->transfer(TMEMBER(_height)); - persistMgr->transfer(TMEMBER(_main)); - _nodes.persist(persistMgr); - persistMgr->transfer(TMEMBER(_width)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdLayer.h b/engines/wintermute/ad/AdLayer.h deleted file mode 100644 index 0ccdb13ae7..0000000000 --- a/engines/wintermute/ad/AdLayer.h +++ /dev/null @@ -1,58 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADLAYER_H -#define WINTERMUTE_ADLAYER_H - -namespace WinterMute { -class CAdSceneNode; -class CAdLayer : public CBObject { -public: - bool _closeUp; - DECLARE_PERSISTENT(CAdLayer, CBObject) - bool _active; - int _height; - int _width; - bool _main; - CAdLayer(CBGame *inGame); - virtual ~CAdLayer(); - CBArray _nodes; - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - virtual const char *scToString(); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdNodeState.cpp b/engines/wintermute/ad/AdNodeState.cpp deleted file mode 100644 index fd72a356c5..0000000000 --- a/engines/wintermute/ad/AdNodeState.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/ad/AdNodeState.h" -#include "engines/wintermute/ad/AdEntity.h" -#include "engines/wintermute/base/BStringTable.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdNodeState, false) - - -////////////////////////////////////////////////////////////////////////// -CAdNodeState::CAdNodeState(CBGame *inGame): CBBase(inGame) { - _name = NULL; - _active = false; - for (int i = 0; i < 7; i++) _caption[i] = NULL; - _alphaColor = 0; - _filename = NULL; - _cursor = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdNodeState::~CAdNodeState() { - delete[] _name; - delete[] _filename; - delete[] _cursor; - _name = NULL; - _filename = NULL; - _cursor = NULL; - for (int i = 0; i < 7; i++) { - delete[] _caption[i]; - _caption[i] = NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -void CAdNodeState::setName(const char *name) { - delete[] _name; - _name = NULL; - CBUtils::setString(&_name, name); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdNodeState::setFilename(const char *filename) { - delete[] _filename; - _filename = NULL; - CBUtils::setString(&_filename, filename); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdNodeState::setCursor(const char *filename) { - delete[] _cursor; - _cursor = NULL; - CBUtils::setString(&_cursor, filename); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdNodeState::persist(CBPersistMgr *persistMgr) { - persistMgr->transfer(TMEMBER(_gameRef)); - - persistMgr->transfer(TMEMBER(_active)); - persistMgr->transfer(TMEMBER(_name)); - persistMgr->transfer(TMEMBER(_filename)); - persistMgr->transfer(TMEMBER(_cursor)); - persistMgr->transfer(TMEMBER(_alphaColor)); - for (int i = 0; i < 7; i++) persistMgr->transfer(TMEMBER(_caption[i])); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdNodeState::setCaption(const char *caption, int caseVal) { - if (caseVal== 0) caseVal= 1; - if (caseVal< 1 || caseVal> 7) return; - - delete[] _caption[caseVal- 1]; - _caption[caseVal- 1] = new char[strlen(caption) + 1]; - if (_caption[caseVal- 1]) { - strcpy(_caption[caseVal- 1], caption); - _gameRef->_stringTable->expand(&_caption[caseVal- 1]); - } -} - - -////////////////////////////////////////////////////////////////////////// -char *CAdNodeState::getCaption(int caseVal) { - if (caseVal== 0) caseVal= 1; - if (caseVal< 1 || caseVal> 7 || _caption[caseVal- 1] == NULL) return ""; - else return _caption[caseVal- 1]; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdNodeState::transferEntity(CAdEntity *entity, bool includingSprites, bool saving) { - if (!entity) return STATUS_FAILED; - - // hack! - if (this->_gameRef != entity->_gameRef) this->_gameRef = entity->_gameRef; - - if (saving) { - for (int i = 0; i < 7; i++) { - if (entity->_caption[i]) setCaption(entity->_caption[i], i); - } - if (!entity->_region && entity->_sprite && entity->_sprite->_filename) { - if (includingSprites) setFilename(entity->_sprite->_filename); - else setFilename(""); - } - if (entity->_cursor && entity->_cursor->_filename) setCursor(entity->_cursor->_filename); - _alphaColor = entity->_alphaColor; - _active = entity->_active; - } else { - for (int i = 0; i < 7; i++) { - if (_caption[i]) entity->setCaption(_caption[i], i); - } - if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) { - if (!entity->_sprite || !entity->_sprite->_filename || scumm_stricmp(entity->_sprite->_filename, _filename) != 0) - entity->setSprite(_filename); - } - if (_cursor) { - if (!entity->_cursor || !entity->_cursor->_filename || scumm_stricmp(entity->_cursor->_filename, _cursor) != 0) - entity->setCursor(_cursor); - } - - entity->_active = _active; - entity->_alphaColor = _alphaColor; - } - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdNodeState.h b/engines/wintermute/ad/AdNodeState.h deleted file mode 100644 index 186f2ebbb2..0000000000 --- a/engines/wintermute/ad/AdNodeState.h +++ /dev/null @@ -1,58 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADNODESTATE_H -#define WINTERMUTE_ADNODESTATE_H - -namespace WinterMute { - -class CAdEntity; - -class CAdNodeState : public CBBase { -public: - bool transferEntity(CAdEntity *entity, bool includingSprites, bool saving); - void setName(const char *name); - void setFilename(const char *filename); - void setCursor(const char *filename); - DECLARE_PERSISTENT(CAdNodeState, CBBase) - CAdNodeState(CBGame *inGame); - virtual ~CAdNodeState(); - char *_name; - bool _active; - char *_caption[7]; - void setCaption(const char *caption, int caseVal); - char *getCaption(int caseVal); - uint32 _alphaColor; - char *_filename; - char *_cursor; - -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdObject.cpp b/engines/wintermute/ad/AdObject.cpp deleted file mode 100644 index c74c8cf6b3..0000000000 --- a/engines/wintermute/ad/AdObject.cpp +++ /dev/null @@ -1,1203 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdItem.h" -#include "engines/wintermute/ad/AdObject.h" -#include "engines/wintermute/ad/AdInventory.h" -#include "engines/wintermute/ad/AdLayer.h" -#include "engines/wintermute/ad/AdScene.h" -#include "engines/wintermute/ad/AdSceneNode.h" -#include "engines/wintermute/ad/AdSentence.h" -#include "engines/wintermute/ad/AdWaypointGroup.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BFrame.h" -#include "engines/wintermute/base/BSound.h" -#include "engines/wintermute/base/BSurfaceStorage.h" -#include "engines/wintermute/base/BSubFrame.h" -#include "engines/wintermute/base/font/BFont.h" -#include "engines/wintermute/base/font/BFontStorage.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/base/BStringTable.h" -#include "engines/wintermute/base/scriptables/ScEngine.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "common/str.h" -#include "common/util.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdObject, false) - -////////////////////////////////////////////////////////////////////////// -CAdObject::CAdObject(CBGame *inGame): CBObject(inGame) { - _type = OBJECT_NONE; - _state = _nextState = STATE_NONE; - - _active = true; - _drawn = false; - - _currentSprite = NULL; - _animSprite = NULL; - _tempSprite2 = NULL; - - _font = NULL; - - _sentence = NULL; - - _forcedTalkAnimName = NULL; - _forcedTalkAnimUsed = false; - - _blockRegion = NULL; - _wptGroup = NULL; - - _currentBlockRegion = NULL; - _currentWptGroup = NULL; - - _ignoreItems = false; - _sceneIndependent = false; - - _stickRegion = NULL; - - _subtitlesModRelative = true; - _subtitlesModX = 0; - _subtitlesModY = 0; - _subtitlesWidth = 0; - _subtitlesModXCenter = true; - - _inventory = NULL; - - for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; - - _partEmitter = NULL; - _partFollowParent = false; - _partOffsetX = _partOffsetY = 0; - - _registerAlias = this; -} - - -////////////////////////////////////////////////////////////////////////// -CAdObject::~CAdObject() { - _currentSprite = NULL; // reference only, don't delete - delete _animSprite; - _animSprite = NULL; - delete _sentence; - _sentence = NULL; - delete[] _forcedTalkAnimName; - _forcedTalkAnimName = NULL; - - delete _blockRegion; - _blockRegion = NULL; - delete _wptGroup; - _wptGroup = NULL; - - delete _currentBlockRegion; - _currentBlockRegion = NULL; - delete _currentWptGroup; - _currentWptGroup = NULL; - - _tempSprite2 = NULL; // reference only - _stickRegion = NULL; - - if (_font) _gameRef->_fontStorage->removeFont(_font); - - if (_inventory) { - ((CAdGame *)_gameRef)->unregisterInventory(_inventory); - _inventory = NULL; - } - - if (_partEmitter) - _gameRef->unregisterObject(_partEmitter); - - - for (int i = 0; i < _attachmentsPre.getSize(); i++) { - _gameRef->unregisterObject(_attachmentsPre[i]); - } - _attachmentsPre.removeAll(); - - for (int i = 0; i < _attachmentsPost.getSize(); i++) { - _gameRef->unregisterObject(_attachmentsPost[i]); - } - _attachmentsPost.removeAll(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::playAnim(const char *filename) { - delete _animSprite; - _animSprite = NULL; - _animSprite = new CBSprite(_gameRef, this); - if (!_animSprite) { - _gameRef->LOG(0, "CAdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); - return STATUS_FAILED; - } - bool res = _animSprite->loadFile(filename); - if (DID_FAIL(res)) { - _gameRef->LOG(res, "CAdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); - delete _animSprite; - _animSprite = NULL; - return res; - } - _state = STATE_PLAYING_ANIM; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::display() { - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::update() { - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - - ////////////////////////////////////////////////////////////////////////// - // PlayAnim / PlayAnimAsync - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "PlayAnim") == 0 || strcmp(name, "PlayAnimAsync") == 0) { - stack->correctParams(1); - if (DID_FAIL(playAnim(stack->pop()->getString()))) stack->pushBool(false); - else { - if (strcmp(name, "PlayAnimAsync") != 0) script->waitFor(this); - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Reset - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Reset") == 0) { - stack->correctParams(0); - reset(); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsTalking - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsTalking") == 0) { - stack->correctParams(0); - stack->pushBool(_state == STATE_TALKING); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // StopTalk / StopTalking - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StopTalk") == 0 || strcmp(name, "StopTalking") == 0) { - stack->correctParams(0); - if (_sentence) _sentence->finish(); - if (_state == STATE_TALKING) { - _state = _nextState; - _nextState = STATE_READY; - stack->pushBool(true); - } else stack->pushBool(false); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ForceTalkAnim - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ForceTalkAnim") == 0) { - stack->correctParams(1); - const char *animName = stack->pop()->getString(); - delete[] _forcedTalkAnimName; - _forcedTalkAnimName = new char[strlen(animName) + 1]; - strcpy(_forcedTalkAnimName, animName); - _forcedTalkAnimUsed = false; - stack->pushBool(true); - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // Talk / TalkAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Talk") == 0 || strcmp(name, "TalkAsync") == 0) { - stack->correctParams(5); - - const char *text = stack->pop()->getString(); - CScValue *soundVal = stack->pop(); - int duration = stack->pop()->getInt(); - CScValue *valStances = stack->pop(); - - const char *stances = valStances->isNULL() ? NULL : valStances->getString(); - - int align = 0; - CScValue *val = stack->pop(); - if (val->isNULL()) align = TAL_CENTER; - else align = val->getInt(); - - align = MIN(MAX(0, align), NUM_TEXT_ALIGN - 1); - - const char *sound = soundVal->isNULL() ? NULL : soundVal->getString(); - - talk(text, sound, duration, stances, (TTextAlign)align); - if (strcmp(name, "TalkAsync") != 0) script->waitForExclusive(this); - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // StickToRegion - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StickToRegion") == 0) { - stack->correctParams(1); - - CAdLayer *main = ((CAdGame *)_gameRef)->_scene->_mainLayer; - bool regFound = false; - - int i; - CScValue *val = stack->pop(); - if (val->isNULL() || !main) { - _stickRegion = NULL; - regFound = true; - } else if (val->isString()) { - const char *regionName = val->getString(); - for (i = 0; i < main->_nodes.getSize(); i++) { - if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region->_name && scumm_stricmp(main->_nodes[i]->_region->_name, regionName) == 0) { - _stickRegion = main->_nodes[i]->_region; - regFound = true; - break; - } - } - } else if (val->isNative()) { - CBScriptable *obj = val->getNative(); - - for (i = 0; i < main->_nodes.getSize(); i++) { - if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region == obj) { - _stickRegion = main->_nodes[i]->_region; - regFound = true; - break; - } - } - - } - - if (!regFound) _stickRegion = NULL; - stack->pushBool(regFound); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetFont - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SetFont") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - if (val->isNULL()) SetFont(NULL); - else SetFont(val->getString()); - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetFont - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetFont") == 0) { - stack->correctParams(0); - if (_font && _font->_filename) stack->pushString(_font->_filename); - else stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TakeItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TakeItem") == 0) { - stack->correctParams(2); - - if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); - } - - CScValue *val = stack->pop(); - if (!val->isNULL()) { - const char *itemName = val->getString(); - val = stack->pop(); - const char *insertAfter = val->isNULL() ? NULL : val->getString(); - if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) script->runtimeError("Cannot add item '%s' to inventory", itemName); - else { - // hide associated entities - ((CAdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); - } - - } else script->runtimeError("TakeItem: item name expected"); - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DropItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DropItem") == 0) { - stack->correctParams(1); - - if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); - } - - CScValue *val = stack->pop(); - if (!val->isNULL()) { - if (DID_FAIL(_inventory->removeItem(val->getString()))) script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); - else { - // show associated entities - ((CAdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); - } - } else script->runtimeError("DropItem: item name expected"); - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetItem") == 0) { - stack->correctParams(1); - - if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); - } - - CScValue *val = stack->pop(); - if (val->_type == VAL_STRING) { - CAdItem *item = ((CAdGame *)_gameRef)->getItemByName(val->getString()); - if (item) stack->pushNative(item, true); - else stack->pushNULL(); - } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) - stack->pushNULL(); - else - stack->pushNative(_inventory->_takenItems[val->getInt()], true); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // HasItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "HasItem") == 0) { - stack->correctParams(1); - - if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); - } - - CScValue *val = stack->pop(); - if (!val->isNULL()) { - for (int i = 0; i < _inventory->_takenItems.getSize(); i++) { - if (val->getNative() == _inventory->_takenItems[i]) { - stack->pushBool(true); - return STATUS_OK; - } else if (scumm_stricmp(val->getString(), _inventory->_takenItems[i]->_name) == 0) { - stack->pushBool(true); - return STATUS_OK; - } - } - } else script->runtimeError("HasItem: item name expected"); - - stack->pushBool(false); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CreateParticleEmitter - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateParticleEmitter") == 0) { - stack->correctParams(3); - bool followParent = stack->pop()->getBool(); - int offsetX = stack->pop()->getInt(); - int offsetY = stack->pop()->getInt(); - - CPartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); - if (emitter) stack->pushNative(_partEmitter, true); - else stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteParticleEmitter - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteParticleEmitter") == 0) { - stack->correctParams(0); - if (_partEmitter) { - _gameRef->unregisterObject(_partEmitter); - _partEmitter = NULL; - } - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddAttachment - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddAttachment") == 0) { - stack->correctParams(4); - const char *filename = stack->pop()->getString(); - bool preDisplay = stack->pop()->getBool(true); - int offsetX = stack->pop()->getInt(); - int offsetY = stack->pop()->getInt(); - - bool res; - CAdEntity *ent = new CAdEntity(_gameRef); - if (DID_FAIL(res = ent->loadFile(filename))) { - delete ent; - ent = NULL; - script->runtimeError("AddAttachment() failed loading entity '%s'", filename); - stack->pushBool(false); - } else { - _gameRef->registerObject(ent); - - ent->_posX = offsetX; - ent->_posY = offsetY; - ent->_active = true; - - if (preDisplay) _attachmentsPre.add(ent); - else _attachmentsPost.add(ent); - - stack->pushBool(true); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // RemoveAttachment - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "RemoveAttachment") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - bool found = false; - if (val->isNative()) { - CBScriptable *obj = val->getNative(); - for (int i = 0; i < _attachmentsPre.getSize(); i++) { - if (_attachmentsPre[i] == obj) { - found = true; - _gameRef->unregisterObject(_attachmentsPre[i]); - _attachmentsPre.removeAt(i); - i--; - } - } - for (int i = 0; i < _attachmentsPost.getSize(); i++) { - if (_attachmentsPost[i] == obj) { - found = true; - _gameRef->unregisterObject(_attachmentsPost[i]); - _attachmentsPost.removeAt(i); - i--; - } - } - } else { - const char *attachmentName = val->getString(); - for (int i = 0; i < _attachmentsPre.getSize(); i++) { - if (_attachmentsPre[i]->_name && scumm_stricmp(_attachmentsPre[i]->_name, attachmentName) == 0) { - found = true; - _gameRef->unregisterObject(_attachmentsPre[i]); - _attachmentsPre.removeAt(i); - i--; - } - } - for (int i = 0; i < _attachmentsPost.getSize(); i++) { - if (_attachmentsPost[i]->_name && scumm_stricmp(_attachmentsPost[i]->_name, attachmentName) == 0) { - found = true; - _gameRef->unregisterObject(_attachmentsPost[i]); - _attachmentsPost.removeAt(i); - i--; - } - } - } - stack->pushBool(found); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetAttachment - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetAttachment") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdObject *ret = NULL; - if (val->isInt()) { - int index = val->getInt(); - int currIndex = 0; - for (int i = 0; i < _attachmentsPre.getSize(); i++) { - if (currIndex == index) ret = _attachmentsPre[i]; - currIndex++; - } - for (int i = 0; i < _attachmentsPost.getSize(); i++) { - if (currIndex == index) ret = _attachmentsPost[i]; - currIndex++; - } - } else { - const char *attachmentName = val->getString(); - for (int i = 0; i < _attachmentsPre.getSize(); i++) { - if (_attachmentsPre[i]->_name && scumm_stricmp(_attachmentsPre[i]->_name, attachmentName) == 0) { - ret = _attachmentsPre[i]; - break; - } - } - if (!ret) { - for (int i = 0; i < _attachmentsPost.getSize(); i++) { - if (_attachmentsPost[i]->_name && scumm_stricmp(_attachmentsPost[i]->_name, attachmentName) == 0) { - ret = _attachmentsPre[i]; - break; - } - } - } - } - - if (ret != NULL) stack->pushNative(ret, true); - else stack->pushNULL(); - - return STATUS_OK; - } - - else return CBObject::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdObject::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("object"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { - _scValue->setBool(_active); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // IgnoreItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IgnoreItems") == 0) { - _scValue->setBool(_ignoreItems); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SceneIndependent - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SceneIndependent") == 0) { - _scValue->setBool(_sceneIndependent); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesWidth - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesWidth") == 0) { - _scValue->setInt(_subtitlesWidth); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosRelative - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosRelative") == 0) { - _scValue->setBool(_subtitlesModRelative); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosX") == 0) { - _scValue->setInt(_subtitlesModX); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosY") == 0) { - _scValue->setInt(_subtitlesModY); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosXCenter - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosXCenter") == 0) { - _scValue->setBool(_subtitlesModXCenter); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumItems (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumItems") == 0) { - _scValue->setInt(getInventory()->_takenItems.getSize()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ParticleEmitter (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ParticleEmitter") == 0) { - if (_partEmitter) _scValue->setNative(_partEmitter, true); - else _scValue->setNULL(); - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumAttachments (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumAttachments") == 0) { - _scValue->setInt(_attachmentsPre.getSize() + _attachmentsPost.getSize()); - return _scValue; - } - - - else return CBObject::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::scSetProperty(const char *name, CScValue *value) { - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Active") == 0) { - _active = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IgnoreItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IgnoreItems") == 0) { - _ignoreItems = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SceneIndependent - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SceneIndependent") == 0) { - _sceneIndependent = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesWidth - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesWidth") == 0) { - _subtitlesWidth = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosRelative - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosRelative") == 0) { - _subtitlesModRelative = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosX") == 0) { - _subtitlesModX = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosY") == 0) { - _subtitlesModY = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosXCenter - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosXCenter") == 0) { - _subtitlesModXCenter = value->getBool(); - return STATUS_OK; - } - - else return CBObject::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *CAdObject::scToString() { - return "[ad object]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::SetFont(const char *filename) { - if (_font) _gameRef->_fontStorage->removeFont(_font); - if (filename) { - _font = _gameRef->_fontStorage->addFont(filename); - return _font == NULL ? STATUS_FAILED : STATUS_OK; - } else { - _font = NULL; - return STATUS_OK; - } -} - - -////////////////////////////////////////////////////////////////////////// -int CAdObject::getHeight() { - if (!_currentSprite) return 0; - else { - CBFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; - int ret = 0; - for (int i = 0; i < frame->_subframes.getSize(); i++) { - ret = MAX(ret, frame->_subframes[i]->_hotspotY); - } - - if (_zoomable) { - float zoom = ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY); - ret = (int)(ret * zoom / 100); - } - return ret; - } -} - - -////////////////////////////////////////////////////////////////////////// -void CAdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { - if (!_sentence) _sentence = new CAdSentence(_gameRef); - if (!_sentence) return; - - if (_forcedTalkAnimName && _forcedTalkAnimUsed) { - delete[] _forcedTalkAnimName; - _forcedTalkAnimName = NULL; - _forcedTalkAnimUsed = false; - } - - delete(_sentence->_sound); - _sentence->_sound = NULL; - - _sentence->setText(text); - _gameRef->_stringTable->expand(&_sentence->_text); - _sentence->setStances(stances); - _sentence->_duration = duration; - _sentence->_align = Align; - _sentence->_startTime = _gameRef->_timer; - _sentence->_currentStance = -1; - _sentence->_font = _font == NULL ? _gameRef->_systemFont : _font; - _sentence->_freezable = _freezable; - - // try to locate speech file automatically - bool deleteSound = false; - if (!sound) { - char *key = _gameRef->_stringTable->getKey(text); - if (key) { - sound = ((CAdGame *)_gameRef)->findSpeechFile(key); - delete [] key; - - if (sound) deleteSound = true; - } - } - - // load sound and set duration appropriately - if (sound) { - CBSound *snd = new CBSound(_gameRef); - if (snd && DID_SUCCEED(snd->setSound(sound, Audio::Mixer::kSpeechSoundType, true))) { - _sentence->setSound(snd); - if (_sentence->_duration <= 0) { - uint32 Length = snd->getLength(); - if (Length != 0) _sentence->_duration = Length; - } - } else delete snd; - } - - // set duration by text length - if (_sentence->_duration <= 0) {// TODO: Avoid longs. - _sentence->_duration = MAX((size_t)1000, _gameRef->_subtitlesSpeed * strlen(_sentence->_text)); - } - - - int x, y, width, height; - - x = _posX; - y = _posY; - - if (!_sceneIndependent && _subtitlesModRelative) { - x -= ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); - y -= ((CAdGame *)_gameRef)->_scene->getOffsetTop(); - } - - - if (_subtitlesWidth > 0) width = _subtitlesWidth; - else { - if ((x < _gameRef->_renderer->_width / 4 || x > _gameRef->_renderer->_width * 0.75) && !_gameRef->_touchInterface) { - width = MAX(_gameRef->_renderer->_width / 4, MIN(x * 2, (_gameRef->_renderer->_width - x) * 2)); - } else width = _gameRef->_renderer->_width / 2; - } - - height = _sentence->_font->getTextHeight((byte *)_sentence->_text, width); - - y = y - height - getHeight() - 5; - if (_subtitlesModRelative) { - x += _subtitlesModX; - y += _subtitlesModY; - } else { - x = _subtitlesModX; - y = _subtitlesModY; - } - if (_subtitlesModXCenter) - x = x - width / 2; - - - x = MIN(MAX(0, x), _gameRef->_renderer->_width - width); - y = MIN(MAX(0, y), _gameRef->_renderer->_height - height); - - _sentence->_width = width; - - - _sentence->_pos.x = x; - _sentence->_pos.y = y; - - - if (_subtitlesModRelative) { - _sentence->_pos.x += ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); - _sentence->_pos.y += ((CAdGame *)_gameRef)->_scene->getOffsetTop(); - } - - _sentence->_fixedPos = !_subtitlesModRelative; - - - _sentence->setupTalkFile(sound); - - _state = STATE_TALKING; - - if (deleteSound) delete [] sound; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::reset() { - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL) { - delete _animSprite; - _animSprite = NULL; - } else if (_state == STATE_TALKING && _sentence) { - _sentence->finish(); - } - - _state = _nextState = STATE_READY; - - _gameRef->_scEngine->resetObject(this); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::persist(CBPersistMgr *persistMgr) { - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_active)); - persistMgr->transfer(TMEMBER(_blockRegion)); - persistMgr->transfer(TMEMBER(_currentBlockRegion)); - persistMgr->transfer(TMEMBER(_currentWptGroup)); - persistMgr->transfer(TMEMBER(_currentSprite)); - persistMgr->transfer(TMEMBER(_drawn)); - persistMgr->transfer(TMEMBER(_font)); - persistMgr->transfer(TMEMBER(_ignoreItems)); - persistMgr->transfer(TMEMBER_INT(_nextState)); - persistMgr->transfer(TMEMBER(_sentence)); - persistMgr->transfer(TMEMBER_INT(_state)); - persistMgr->transfer(TMEMBER(_animSprite)); - persistMgr->transfer(TMEMBER(_sceneIndependent)); - persistMgr->transfer(TMEMBER(_forcedTalkAnimName)); - persistMgr->transfer(TMEMBER(_forcedTalkAnimUsed)); - persistMgr->transfer(TMEMBER(_tempSprite2)); - persistMgr->transfer(TMEMBER_INT(_type)); - persistMgr->transfer(TMEMBER(_wptGroup)); - persistMgr->transfer(TMEMBER(_stickRegion)); - persistMgr->transfer(TMEMBER(_subtitlesModRelative)); - persistMgr->transfer(TMEMBER(_subtitlesModX)); - persistMgr->transfer(TMEMBER(_subtitlesModY)); - persistMgr->transfer(TMEMBER(_subtitlesModXCenter)); - persistMgr->transfer(TMEMBER(_subtitlesWidth)); - persistMgr->transfer(TMEMBER(_inventory)); - persistMgr->transfer(TMEMBER(_partEmitter)); - - for (int i = 0; i < MAX_NUM_REGIONS; i++) persistMgr->transfer(TMEMBER(_currentRegions[i])); - - _attachmentsPre.persist(persistMgr); - _attachmentsPost.persist(persistMgr); - persistMgr->transfer(TMEMBER(_registerAlias)); - - persistMgr->transfer(TMEMBER(_partFollowParent)); - persistMgr->transfer(TMEMBER(_partOffsetX)); - persistMgr->transfer(TMEMBER(_partOffsetY)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::updateSounds() { - if (_sentence && _sentence->_sound) - updateOneSound(_sentence->_sound); - - return CBObject::updateSounds(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::resetSoundPan() { - if (_sentence && _sentence->_sound) { - _sentence->_sound->setPan(0.0f); - } - return CBObject::resetSoundPan(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::getExtendedFlag(const char *flagName) { - if (!flagName) return false; - else if (strcmp(flagName, "usable") == 0) return true; - - else return CBObject::getExtendedFlag(flagName); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::saveAsText(CBDynBuffer *buffer, int indent) { - if (_blockRegion) _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); - if (_wptGroup) _wptGroup->saveAsText(buffer, indent + 2); - - CBBase::saveAsText(buffer, indent + 2); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::updateBlockRegion() { - CAdGame *adGame = (CAdGame *)_gameRef; - if (adGame->_scene) { - if (_blockRegion && _currentBlockRegion) - _currentBlockRegion->mimic(_blockRegion, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); - - if (_wptGroup && _currentWptGroup) - _currentWptGroup->mimic(_wptGroup, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -CAdInventory *CAdObject::getInventory() { - if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); - } - return _inventory; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::afterMove() { - CAdRegion *newRegions[MAX_NUM_REGIONS]; - - ((CAdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); - for (int i = 0; i < MAX_NUM_REGIONS; i++) { - if (!newRegions[i]) break; - bool regFound = false; - for (int j = 0; j < MAX_NUM_REGIONS; j++) { - if (_currentRegions[j] == newRegions[i]) { - _currentRegions[j] = NULL; - regFound = true; - break; - } - } - if (!regFound) newRegions[i]->applyEvent("ActorEntry"); - } - - for (int i = 0; i < MAX_NUM_REGIONS; i++) { - if (_currentRegions[i] && _gameRef->validObject(_currentRegions[i])) { - _currentRegions[i]->applyEvent("ActorLeave"); - } - _currentRegions[i] = newRegions[i]; - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::invalidateCurrRegions() { - for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::getScale(float *scaleX, float *scaleY) { - if (_zoomable) { - if (_scaleX >= 0 || _scaleY >= 0) { - *scaleX = _scaleX < 0 ? 100 : _scaleX; - *scaleY = _scaleY < 0 ? 100 : _scaleY; - } else if (_scale >= 0) *scaleX = *scaleY = _scale; - else *scaleX = *scaleY = ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; - } else { - *scaleX = *scaleY = 100; - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::updateSpriteAttachments() { - for (int i = 0; i < _attachmentsPre.getSize(); i++) { - _attachmentsPre[i]->update(); - } - for (int i = 0; i < _attachmentsPost.getSize(); i++) { - _attachmentsPost[i]->update(); - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::displaySpriteAttachments(bool preDisplay) { - if (preDisplay) { - for (int i = 0; i < _attachmentsPre.getSize(); i++) { - displaySpriteAttachment(_attachmentsPre[i]); - } - } else { - for (int i = 0; i < _attachmentsPost.getSize(); i++) { - displaySpriteAttachment(_attachmentsPost[i]); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::displaySpriteAttachment(CAdObject *attachment) { - if (!attachment->_active) return STATUS_OK; - - float scaleX, scaleY; - getScale(&scaleX, &scaleY); - - int origX = attachment->_posX; - int origY = attachment->_posY; - - // inherit position from owner - attachment->_posX = (int)(this->_posX + attachment->_posX * scaleX / 100.0f); - attachment->_posY = (int)(this->_posY + attachment->_posY * scaleY / 100.0f); - - // inherit other props - attachment->_alphaColor = this->_alphaColor; - attachment->_blendMode = this->_blendMode; - - attachment->_scale = this->_scale; - attachment->_relativeScale = this->_relativeScale; - attachment->_scaleX = this->_scaleX; - attachment->_scaleY = this->_scaleY; - - attachment->_rotate = this->_rotate; - attachment->_relativeRotate = this->_relativeRotate; - attachment->_rotateValid = this->_rotateValid; - - attachment->_registerAlias = this; - attachment->_registrable = this->_registrable; - - bool ret = attachment->display(); - - attachment->_posX = origX; - attachment->_posY = origY; - - return ret; -} - -////////////////////////////////////////////////////////////////////////// -CPartEmitter *CAdObject::createParticleEmitter(bool followParent, int offsetX, int offsetY) { - _partFollowParent = followParent; - _partOffsetX = offsetX; - _partOffsetY = offsetY; - - if (!_partEmitter) { - _partEmitter = new CPartEmitter(_gameRef, this); - if (_partEmitter) { - _gameRef->registerObject(_partEmitter); - } - } - updatePartEmitter(); - return _partEmitter; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdObject::updatePartEmitter() { - if (!_partEmitter) return STATUS_FAILED; - - if (_partFollowParent) { - float scaleX, scaleY; - getScale(&scaleX, &scaleY); - - _partEmitter->_posX = (int)(_posX + (scaleX / 100.0f) * _partOffsetX); - _partEmitter->_posY = (int)(_posY + (scaleY / 100.0f) * _partOffsetY); - } - return _partEmitter->update(); -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdObject.h b/engines/wintermute/ad/AdObject.h deleted file mode 100644 index d662e84729..0000000000 --- a/engines/wintermute/ad/AdObject.h +++ /dev/null @@ -1,123 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADOBJECT_H -#define WINTERMUTE_ADOBJECT_H - -#include "engines/wintermute/ad/AdTypes.h" -#include "engines/wintermute/base/particles/PartEmitter.h" - -namespace WinterMute { - -class CAdWaypointGroup; -class CAdRegion; -class CAdSentence; -class CBFont; -class CBRegion; -class CAdInventory; - -#define MAX_NUM_REGIONS 10 - -class CAdObject : public CBObject { -public: - CPartEmitter *_partEmitter; - virtual CPartEmitter *createParticleEmitter(bool followParent = false, int offsetX = 0, int offsetY = 0); - virtual bool updatePartEmitter(); - bool _partFollowParent; - int _partOffsetX; - int _partOffsetY; - - bool invalidateCurrRegions(); - bool _subtitlesModRelative; - bool _subtitlesModXCenter; - int _subtitlesModX; - int _subtitlesModY; - int _subtitlesWidth; - CAdRegion *_stickRegion; - bool _sceneIndependent; - bool _ignoreItems; - bool updateBlockRegion(); - bool _forcedTalkAnimUsed; - char *_forcedTalkAnimName; - virtual bool getExtendedFlag(const char *flagName); - virtual bool resetSoundPan(); - virtual bool updateSounds(); - bool reset(); - DECLARE_PERSISTENT(CAdObject, CBObject) - virtual void talk(const char *text, const char *sound = NULL, uint32 duration = 0, const char *stances = NULL, TTextAlign align = TAL_CENTER); - virtual int getHeight(); - CAdSentence *_sentence; - bool SetFont(const char *filename); - virtual bool update(); - virtual bool display(); - bool _drawn; - bool _active; - virtual bool playAnim(const char *filename); - CBSprite *_animSprite; - CBSprite *_currentSprite; - TObjectState _state; - TObjectState _nextState; - TObjectType _type; - CAdObject(CBGame *inGame); - virtual ~CAdObject(); - CBFont *_font; - CBSprite *_tempSprite2; - CBRegion *_blockRegion; - CAdWaypointGroup *_wptGroup; - CBRegion *_currentBlockRegion; - CAdWaypointGroup *_currentWptGroup; - CAdInventory *getInventory(); - - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - - virtual bool afterMove(); - CAdRegion *_currentRegions[MAX_NUM_REGIONS]; - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - virtual const char *scToString(); - - CBArray _attachmentsPre; - CBArray _attachmentsPost; - - bool updateSpriteAttachments(); - bool displaySpriteAttachments(bool preDisplay); - CAdObject *_registerAlias; -private: - bool displaySpriteAttachment(CAdObject *attachment); - CAdInventory *_inventory; - -protected: - bool getScale(float *scaleX, float *scaleY); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdPath.cpp b/engines/wintermute/ad/AdPath.cpp deleted file mode 100644 index d1b9d87063..0000000000 --- a/engines/wintermute/ad/AdPath.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdPath.h" -#include "engines/wintermute/base/BPoint.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdPath, false) - -////////////////////////////////////////////////////////////////////////// -CAdPath::CAdPath(CBGame *inGame): CBBase(inGame) { - _currIndex = -1; - _ready = false; -} - - -////////////////////////////////////////////////////////////////////////// -CAdPath::~CAdPath() { - reset(); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdPath::reset() { - for (int i = 0; i < _points.getSize(); i++) - delete _points[i]; - - _points.removeAll(); - _currIndex = -1; - _ready = false; -} - - -////////////////////////////////////////////////////////////////////////// -CBPoint *CAdPath::getFirst() { - if (_points.getSize() > 0) { - _currIndex = 0; - return _points[_currIndex]; - } else return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CBPoint *CAdPath::getNext() { - _currIndex++; - if (_currIndex < _points.getSize()) return _points[_currIndex]; - else return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CBPoint *CAdPath::getCurrent() { - if (_currIndex >= 0 && _currIndex < _points.getSize()) return _points[_currIndex]; - else return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdPath::addPoint(CBPoint *point) { - _points.add(point); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdPath::setReady(bool ready) { - bool orig = _ready; - _ready = ready; - - return orig; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdPath::persist(CBPersistMgr *persistMgr) { - - persistMgr->transfer(TMEMBER(_gameRef)); - - persistMgr->transfer(TMEMBER(_currIndex)); - _points.persist(persistMgr); - persistMgr->transfer(TMEMBER(_ready)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdPath.h b/engines/wintermute/ad/AdPath.h deleted file mode 100644 index fdc2980042..0000000000 --- a/engines/wintermute/ad/AdPath.h +++ /dev/null @@ -1,56 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADPATH_H -#define WINTERMUTE_ADPATH_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/coll_templ.h" -#include "engines/wintermute/base/BBase.h" - -namespace WinterMute { -class CBPoint; -class CAdPath : public CBBase { -public: - DECLARE_PERSISTENT(CAdPath, CBBase) - CBPoint *getCurrent(); - bool setReady(bool ready = true); - void addPoint(CBPoint *point); - CBPoint *getNext(); - CBPoint *getFirst(); - void reset(); - CAdPath(CBGame *inGame); - virtual ~CAdPath(); - CBArray _points; - int _currIndex; - bool _ready; -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdPathPoint.cpp b/engines/wintermute/ad/AdPathPoint.cpp deleted file mode 100644 index 184ad8559a..0000000000 --- a/engines/wintermute/ad/AdPathPoint.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/AdPathPoint.h" -#include "engines/wintermute/base/BPersistMgr.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdPathPoint, false) - -////////////////////////////////////////////////////////////////////////// -CAdPathPoint::CAdPathPoint() { - x = y = 0; - _distance = 0; - - _marked = false; - _origin = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdPathPoint::CAdPathPoint(int initX, int initY, int initDistance) { - x = initX; - y = initY; - _distance = initDistance; - - _marked = false; - _origin = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdPathPoint::~CAdPathPoint() { - _origin = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdPathPoint::persist(CBPersistMgr *persistMgr) { - - CBPoint::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_distance)); - persistMgr->transfer(TMEMBER(_marked)); - persistMgr->transfer(TMEMBER(_origin)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdPathPoint.h b/engines/wintermute/ad/AdPathPoint.h deleted file mode 100644 index f58df765b1..0000000000 --- a/engines/wintermute/ad/AdPathPoint.h +++ /dev/null @@ -1,50 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADPATHPOINT_H -#define WINTERMUTE_ADPATHPOINT_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/BPoint.h" - -namespace WinterMute { - -class CAdPathPoint : public CBPoint { -public: - DECLARE_PERSISTENT(CAdPathPoint, CBPoint) - CAdPathPoint(int initX, int initY, int initDistance); - CAdPathPoint(); - virtual ~CAdPathPoint(); - CAdPathPoint *_origin; - bool _marked; - int _distance; -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdRegion.cpp b/engines/wintermute/ad/AdRegion.cpp deleted file mode 100644 index a1864de1ac..0000000000 --- a/engines/wintermute/ad/AdRegion.cpp +++ /dev/null @@ -1,392 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdRegion.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BFileManager.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdRegion, false) - -////////////////////////////////////////////////////////////////////////// -CAdRegion::CAdRegion(CBGame *inGame): CBRegion(inGame) { - _blocked = false; - _decoration = false; - _zoom = 0; - _alpha = 0xFFFFFFFF; -} - - -////////////////////////////////////////////////////////////////////////// -CAdRegion::~CAdRegion() { -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdRegion::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdRegion::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(REGION) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(NAME) -TOKEN_DEF(ACTIVE) -TOKEN_DEF(ZOOM) -TOKEN_DEF(SCALE) -TOKEN_DEF(BLOCKED) -TOKEN_DEF(DECORATION) -TOKEN_DEF(POINT) -TOKEN_DEF(ALPHA_COLOR) -TOKEN_DEF(ALPHA) -TOKEN_DEF(EDITOR_SELECTED_POINT) -TOKEN_DEF(EDITOR_SELECTED) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdRegion::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(REGION) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(NAME) - TOKEN_TABLE(ACTIVE) - TOKEN_TABLE(ZOOM) - TOKEN_TABLE(SCALE) - TOKEN_TABLE(BLOCKED) - TOKEN_TABLE(DECORATION) - TOKEN_TABLE(POINT) - TOKEN_TABLE(ALPHA_COLOR) - TOKEN_TABLE(ALPHA) - TOKEN_TABLE(EDITOR_SELECTED_POINT) - TOKEN_TABLE(EDITOR_SELECTED) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { - _gameRef->LOG(0, "'REGION' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - for (int i = 0; i < _points.getSize(); i++) delete _points[i]; - _points.removeAll(); - - int ar = 255, ag = 255, ab = 255, alpha = 255; - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_ACTIVE: - parser.scanStr((char *)params, "%b", &_active); - break; - - case TOKEN_BLOCKED: - parser.scanStr((char *)params, "%b", &_blocked); - break; - - case TOKEN_DECORATION: - parser.scanStr((char *)params, "%b", &_decoration); - break; - - case TOKEN_ZOOM: - case TOKEN_SCALE: { - int j; - parser.scanStr((char *)params, "%d", &j); - _zoom = (float)j; - } - break; - - case TOKEN_POINT: { - int x, y; - parser.scanStr((char *)params, "%d,%d", &x, &y); - _points.add(new CBPoint(x, y)); - } - 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_SELECTED: - parser.scanStr((char *)params, "%b", &_editorSelected); - break; - - case TOKEN_EDITOR_SELECTED_POINT: - parser.scanStr((char *)params, "%d", &_editorSelectedPoint); - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in REGION definition"); - return STATUS_FAILED; - } - - createRegion(); - - _alpha = BYTETORGBA(ar, ag, ab, alpha); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdRegion::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - /* - ////////////////////////////////////////////////////////////////////////// - // SkipTo - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SkipTo")==0) { - stack->correctParams(2); - _posX = stack->pop()->getInt(); - _posY = stack->pop()->getInt(); - stack->pushNULL(); - - return STATUS_OK; - } - - else*/ return CBRegion::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdRegion::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("ad region"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Name") == 0) { - _scValue->setString(_name); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Blocked - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Blocked") == 0) { - _scValue->setBool(_blocked); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Decoration - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Decoration") == 0) { - _scValue->setBool(_decoration); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Scale - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Scale") == 0) { - _scValue->setFloat(_zoom); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AlphaColor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AlphaColor") == 0) { - _scValue->setInt((int)_alpha); - return _scValue; - } - - else return CBRegion::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdRegion::scSetProperty(const char *name, CScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Name") == 0) { - setName(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Blocked - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Blocked") == 0) { - _blocked = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Decoration - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Decoration") == 0) { - _decoration = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Scale - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Scale") == 0) { - _zoom = value->getFloat(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AlphaColor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AlphaColor") == 0) { - _alpha = (uint32)value->getInt(); - return STATUS_OK; - } - - else return CBRegion::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *CAdRegion::scToString() { - return "[ad region]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdRegion::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "REGION {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - buffer->putTextIndent(indent + 2, "BLOCKED=%s\n", _blocked ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "DECORATION=%s\n", _decoration ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_zoom); - buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alpha), RGBCOLGetG(_alpha), RGBCOLGetB(_alpha)); - buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alpha)); - buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - - int i; - for (i = 0; i < _scripts.getSize(); i++) { - buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); - } - - if (_scProp) _scProp->saveAsText(buffer, indent + 2); - - for (i = 0; i < _points.getSize(); i++) { - buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); - } - - CBBase::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdRegion::persist(CBPersistMgr *persistMgr) { - CBRegion::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_alpha)); - persistMgr->transfer(TMEMBER(_blocked)); - persistMgr->transfer(TMEMBER(_decoration)); - persistMgr->transfer(TMEMBER(_zoom)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdRegion.h b/engines/wintermute/ad/AdRegion.h deleted file mode 100644 index c91feb4012..0000000000 --- a/engines/wintermute/ad/AdRegion.h +++ /dev/null @@ -1,58 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADREGION_H -#define WINTERMUTE_ADREGION_H - -#include "engines/wintermute/base/BRegion.h" - -namespace WinterMute { - -class CAdRegion : public CBRegion { -public: - DECLARE_PERSISTENT(CAdRegion, CBRegion) - uint32 _alpha; - float _zoom; - bool _blocked; - bool _decoration; - CAdRegion(CBGame *inGame); - virtual ~CAdRegion(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - virtual const char *scToString(); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdResponse.cpp b/engines/wintermute/ad/AdResponse.cpp deleted file mode 100644 index 20617f9573..0000000000 --- a/engines/wintermute/ad/AdResponse.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdResponse.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/font/BFontStorage.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/utils/utils.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdResponse, false) - -////////////////////////////////////////////////////////////////////////// -CAdResponse::CAdResponse(CBGame *inGame): CBObject(inGame) { - _text = NULL; - _textOrig = NULL; - _icon = _iconHover = _iconPressed = NULL; - _font = NULL; - _iD = 0; - _responseType = RESPONSE_ALWAYS; -} - - -////////////////////////////////////////////////////////////////////////// -CAdResponse::~CAdResponse() { - delete[] _text; - delete[] _textOrig; - delete _icon; - delete _iconHover; - delete _iconPressed; - _text = NULL; - _textOrig = NULL; - _icon = NULL; - _iconHover = NULL; - _iconPressed = NULL; - if (_font) _gameRef->_fontStorage->removeFont(_font); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdResponse::setText(const char *text) { - CBUtils::setString(&_text, text); - CBUtils::setString(&_textOrig, text); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponse::setIcon(const char *filename) { - delete _icon; - _icon = new CBSprite(_gameRef); - if (!_icon || DID_FAIL(_icon->loadFile(filename))) { - _gameRef->LOG(0, "CAdResponse::setIcon failed for file '%s'", filename); - delete _icon; - _icon = NULL; - return STATUS_FAILED; - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdResponse::setFont(const char *filename) { - if (_font) _gameRef->_fontStorage->removeFont(_font); - _font = _gameRef->_fontStorage->addFont(filename); - if (!_font) { - _gameRef->LOG(0, "CAdResponse::setFont failed for file '%s'", filename); - return STATUS_FAILED; - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdResponse::setIconHover(const char *filename) { - delete _iconHover; - _iconHover = new CBSprite(_gameRef); - if (!_iconHover || DID_FAIL(_iconHover->loadFile(filename))) { - _gameRef->LOG(0, "CAdResponse::setIconHover failed for file '%s'", filename); - delete _iconHover; - _iconHover = NULL; - return STATUS_FAILED; - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponse::setIconPressed(const char *filename) { - delete _iconPressed; - _iconPressed = new CBSprite(_gameRef); - if (!_iconPressed || DID_FAIL(_iconPressed->loadFile(filename))) { - _gameRef->LOG(0, "CAdResponse::setIconPressed failed for file '%s'", filename); - delete _iconPressed; - _iconPressed = NULL; - return STATUS_FAILED; - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponse::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_icon)); - persistMgr->transfer(TMEMBER(_iconHover)); - persistMgr->transfer(TMEMBER(_iconPressed)); - persistMgr->transfer(TMEMBER(_iD)); - persistMgr->transfer(TMEMBER(_text)); - persistMgr->transfer(TMEMBER(_textOrig)); - persistMgr->transfer(TMEMBER_INT(_responseType)); - persistMgr->transfer(TMEMBER(_font)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdResponse.h b/engines/wintermute/ad/AdResponse.h deleted file mode 100644 index 646d781b89..0000000000 --- a/engines/wintermute/ad/AdResponse.h +++ /dev/null @@ -1,61 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADRESPONSE_H -#define WINTERMUTE_ADRESPONSE_H - - -#include "engines/wintermute/base/BObject.h" -#include "engines/wintermute/ad/AdTypes.h" - -namespace WinterMute { -class CBFont; -class CAdResponse : public CBObject { -public: - DECLARE_PERSISTENT(CAdResponse, CBObject) - bool setIcon(const char *filename); - bool setFont(const char *filename); - bool setIconHover(const char *filename); - bool setIconPressed(const char *filename); - void setText(const char *text); - int _iD; - CBSprite *_icon; - CBSprite *_iconHover; - CBSprite *_iconPressed; - CBFont *_font; - char *_text; - char *_textOrig; - CAdResponse(CBGame *inGame); - virtual ~CAdResponse(); - TResponseType _responseType; - -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdResponseBox.cpp b/engines/wintermute/ad/AdResponseBox.cpp deleted file mode 100644 index 829d58f2ee..0000000000 --- a/engines/wintermute/ad/AdResponseBox.cpp +++ /dev/null @@ -1,647 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdResponseBox.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BSurfaceStorage.h" -#include "engines/wintermute/ui/UIButton.h" -#include "engines/wintermute/ui/UIWindow.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/font/BFontStorage.h" -#include "engines/wintermute/base/font/BFont.h" -#include "engines/wintermute/ad/AdResponse.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdResponseBox, false) - -////////////////////////////////////////////////////////////////////////// -CAdResponseBox::CAdResponseBox(CBGame *inGame): CBObject(inGame) { - _font = _fontHover = NULL; - - _window = NULL; - _shieldWindow = new CUIWindow(_gameRef); - - _horizontal = false; - CBPlatform::setRectEmpty(&_responseArea); - _scrollOffset = 0; - _spacing = 0; - - _waitingScript = NULL; - _lastResponseText = NULL; - _lastResponseTextOrig = NULL; - - _verticalAlign = VAL_BOTTOM; - _align = TAL_LEFT; -} - - -////////////////////////////////////////////////////////////////////////// -CAdResponseBox::~CAdResponseBox() { - - delete _window; - _window = NULL; - delete _shieldWindow; - _shieldWindow = NULL; - delete[] _lastResponseText; - _lastResponseText = NULL; - delete[] _lastResponseTextOrig; - _lastResponseTextOrig = NULL; - - if (_font) _gameRef->_fontStorage->removeFont(_font); - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); - - clearResponses(); - clearButtons(); - - _waitingScript = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdResponseBox::clearResponses() { - for (int i = 0; i < _responses.getSize(); i++) { - delete _responses[i]; - } - _responses.removeAll(); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdResponseBox::clearButtons() { - for (int i = 0; i < _respButtons.getSize(); i++) { - delete _respButtons[i]; - } - _respButtons.removeAll(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::invalidateButtons() { - for (int i = 0; i < _respButtons.getSize(); i++) { - _respButtons[i]->_image = NULL; - _respButtons[i]->_cursor = NULL; - _respButtons[i]->_font = NULL; - _respButtons[i]->_fontHover = NULL; - _respButtons[i]->_fontPress = NULL; - _respButtons[i]->setText(""); - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::createButtons() { - clearButtons(); - - _scrollOffset = 0; - for (int i = 0; i < _responses.getSize(); i++) { - CUIButton *btn = new CUIButton(_gameRef); - if (btn) { - btn->_parent = _window; - btn->_sharedFonts = btn->_sharedImages = true; - btn->_sharedCursors = true; - // iconic - if (_responses[i]->_icon) { - btn->_image = _responses[i]->_icon; - if (_responses[i]->_iconHover) btn->_imageHover = _responses[i]->_iconHover; - if (_responses[i]->_iconPressed) btn->_imagePress = _responses[i]->_iconPressed; - - btn->setCaption(_responses[i]->_text); - if (_cursor) btn->_cursor = _cursor; - else if (_gameRef->_activeCursor) btn->_cursor = _gameRef->_activeCursor; - } - // textual - else { - btn->setText(_responses[i]->_text); - btn->_font = (_font == NULL) ? _gameRef->_systemFont : _font; - btn->_fontHover = (_fontHover == NULL) ? _gameRef->_systemFont : _fontHover; - btn->_fontPress = btn->_fontHover; - btn->_align = _align; - - if (_gameRef->_touchInterface) - btn->_fontHover = btn->_font; - - - if (_responses[i]->_font) btn->_font = _responses[i]->_font; - - btn->_width = _responseArea.right - _responseArea.left; - if (btn->_width <= 0) btn->_width = _gameRef->_renderer->_width; - } - btn->setName("response"); - btn->correctSize(); - - // make the responses touchable - if (_gameRef->_touchInterface) - btn->_height = MAX(btn->_height, 50); - - //btn->SetListener(this, btn, _responses[i]->_iD); - btn->setListener(this, btn, i); - btn->_visible = false; - _respButtons.add(btn); - - if (_responseArea.bottom - _responseArea.top < btn->_height) { - _gameRef->LOG(0, "Warning: Response '%s' is too high to be displayed within response box. Correcting.", _responses[i]->_text); - _responseArea.bottom += (btn->_height - (_responseArea.bottom - _responseArea.top)); - } - } - } - _ready = false; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdResponseBox::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(RESPONSE_BOX) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(FONT_HOVER) -TOKEN_DEF(FONT) -TOKEN_DEF(AREA) -TOKEN_DEF(HORIZONTAL) -TOKEN_DEF(SPACING) -TOKEN_DEF(WINDOW) -TOKEN_DEF(CURSOR) -TOKEN_DEF(TEXT_ALIGN) -TOKEN_DEF(VERTICAL_ALIGN) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(RESPONSE_BOX) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(FONT_HOVER) - TOKEN_TABLE(FONT) - TOKEN_TABLE(AREA) - TOKEN_TABLE(HORIZONTAL) - TOKEN_TABLE(SPACING) - TOKEN_TABLE(WINDOW) - TOKEN_TABLE(CURSOR) - TOKEN_TABLE(TEXT_ALIGN) - TOKEN_TABLE(VERTICAL_ALIGN) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_RESPONSE_BOX) { - _gameRef->LOG(0, "'RESPONSE_BOX' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_WINDOW: - delete _window; - _window = new CUIWindow(_gameRef); - if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { - delete _window; - _window = NULL; - cmd = PARSERR_GENERIC; - } else if (_shieldWindow) _shieldWindow->_parent = _window; - break; - - case TOKEN_FONT: - if (_font) _gameRef->_fontStorage->removeFont(_font); - _font = _gameRef->_fontStorage->addFont((char *)params); - if (!_font) cmd = PARSERR_GENERIC; - break; - - case TOKEN_FONT_HOVER: - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); - _fontHover = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontHover) cmd = PARSERR_GENERIC; - break; - - case TOKEN_AREA: - parser.scanStr((char *)params, "%d,%d,%d,%d", &_responseArea.left, &_responseArea.top, &_responseArea.right, &_responseArea.bottom); - break; - - case TOKEN_HORIZONTAL: - parser.scanStr((char *)params, "%b", &_horizontal); - break; - - case TOKEN_TEXT_ALIGN: - if (scumm_stricmp((char *)params, "center") == 0) _align = TAL_CENTER; - else if (scumm_stricmp((char *)params, "right") == 0) _align = TAL_RIGHT; - else _align = TAL_LEFT; - break; - - case TOKEN_VERTICAL_ALIGN: - if (scumm_stricmp((char *)params, "top") == 0) _verticalAlign = VAL_TOP; - else if (scumm_stricmp((char *)params, "center") == 0) _verticalAlign = VAL_CENTER; - else _verticalAlign = VAL_BOTTOM; - break; - - case TOKEN_SPACING: - parser.scanStr((char *)params, "%d", &_spacing); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - - case TOKEN_CURSOR: - delete _cursor; - _cursor = new CBSprite(_gameRef); - if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { - delete _cursor; - _cursor = NULL; - cmd = PARSERR_GENERIC; - } - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in RESPONSE_BOX definition"); - return STATUS_FAILED; - } - - if (_window) { - for (int i = 0; i < _window->_widgets.getSize(); i++) { - if (!_window->_widgets[i]->_listenerObject) - _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "RESPONSE_BOX\n"); - buffer->putTextIndent(indent, "{\n"); - - buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _responseArea.left, _responseArea.top, _responseArea.right, _responseArea.bottom); - - if (_font && _font->_filename) - buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->_filename); - if (_fontHover && _fontHover->_filename) - buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->_filename); - - if (_cursor && _cursor->_filename) - buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); - - buffer->putTextIndent(indent + 2, "HORIZONTAL=%s\n", _horizontal ? "TRUE" : "FALSE"); - - switch (_align) { - case TAL_LEFT: - buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "left"); - break; - case TAL_RIGHT: - buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "right"); - break; - case TAL_CENTER: - buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "center"); - break; - default: - error("CAdResponseBox::SaveAsText - Unhandled enum"); - break; - } - - switch (_verticalAlign) { - case VAL_TOP: - buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "top"); - break; - case VAL_BOTTOM: - buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "bottom"); - break; - case VAL_CENTER: - buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "center"); - break; - } - - buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); - - buffer->putTextIndent(indent + 2, "\n"); - - // window - if (_window) _window->saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent + 2, "\n"); - - // editor properties - CBBase::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::display() { - Rect32 rect = _responseArea; - if (_window) { - CBPlatform::offsetRect(&rect, _window->_posX, _window->_posY); - //_window->display(); - } - - int xxx, yyy, i; - - xxx = rect.left; - yyy = rect.top; - - // shift down if needed - if (!_horizontal) { - int total_height = 0; - for (i = 0; i < _respButtons.getSize(); i++) total_height += (_respButtons[i]->_height + _spacing); - total_height -= _spacing; - - switch (_verticalAlign) { - case VAL_BOTTOM: - if (yyy + total_height < rect.bottom) - yyy = rect.bottom - total_height; - break; - - case VAL_CENTER: - if (yyy + total_height < rect.bottom) - yyy += ((rect.bottom - rect.top) - total_height) / 2; - break; - - case VAL_TOP: - // do nothing - break; - } - } - - // prepare response buttons - bool scrollNeeded = false; - for (i = _scrollOffset; i < _respButtons.getSize(); i++) { - if ((_horizontal && xxx + _respButtons[i]->_width > rect.right) - || (!_horizontal && yyy + _respButtons[i]->_height > rect.bottom)) { - - scrollNeeded = true; - _respButtons[i]->_visible = false; - break; - } - - _respButtons[i]->_visible = true; - _respButtons[i]->_posX = xxx; - _respButtons[i]->_posY = yyy; - - if (_horizontal) { - xxx += (_respButtons[i]->_width + _spacing); - } else { - yyy += (_respButtons[i]->_height + _spacing); - } - } - - // show appropriate scroll buttons - if (_window) { - _window->showWidget("prev", _scrollOffset > 0); - _window->showWidget("next", scrollNeeded); - } - - // go exclusive - if (_shieldWindow) { - _shieldWindow->_posX = _shieldWindow->_posY = 0; - _shieldWindow->_width = _gameRef->_renderer->_width; - _shieldWindow->_height = _gameRef->_renderer->_height; - - _shieldWindow->display(); - } - - // display window - if (_window) _window->display(); - - - // display response buttons - for (i = _scrollOffset; i < _respButtons.getSize(); i++) { - _respButtons[i]->display(); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::listen(CBScriptHolder *param1, uint32 param2) { - CUIObject *obj = (CUIObject *)param1; - - switch (obj->_type) { - case UI_BUTTON: - if (scumm_stricmp(obj->_name, "prev") == 0) { - _scrollOffset--; - } else if (scumm_stricmp(obj->_name, "next") == 0) { - _scrollOffset++; - } else if (scumm_stricmp(obj->_name, "response") == 0) { - if (_waitingScript) _waitingScript->_stack->pushInt(_responses[param2]->_iD); - handleResponse(_responses[param2]); - _waitingScript = NULL; - _gameRef->_state = GAME_RUNNING; - ((CAdGame *)_gameRef)->_stateEx = GAME_NORMAL; - _ready = true; - invalidateButtons(); - clearResponses(); - } else return CBObject::listen(param1, param2); - break; - default: - error("AdResponseBox::Listen - Unhandled enum"); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::persist(CBPersistMgr *persistMgr) { - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_font)); - persistMgr->transfer(TMEMBER(_fontHover)); - persistMgr->transfer(TMEMBER(_horizontal)); - persistMgr->transfer(TMEMBER(_lastResponseText)); - persistMgr->transfer(TMEMBER(_lastResponseTextOrig)); - _respButtons.persist(persistMgr); - persistMgr->transfer(TMEMBER(_responseArea)); - _responses.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scrollOffset)); - persistMgr->transfer(TMEMBER(_shieldWindow)); - persistMgr->transfer(TMEMBER(_spacing)); - persistMgr->transfer(TMEMBER(_waitingScript)); - persistMgr->transfer(TMEMBER(_window)); - - persistMgr->transfer(TMEMBER_INT(_verticalAlign)); - persistMgr->transfer(TMEMBER_INT(_align)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::weedResponses() { - CAdGame *adGame = (CAdGame *)_gameRef; - - for (int i = 0; i < _responses.getSize(); i++) { - switch (_responses[i]->_responseType) { - case RESPONSE_ONCE: - if (adGame->branchResponseUsed(_responses[i]->_iD)) { - delete _responses[i]; - _responses.removeAt(i); - i--; - } - break; - - case RESPONSE_ONCE_GAME: - if (adGame->gameResponseUsed(_responses[i]->_iD)) { - delete _responses[i]; - _responses.removeAt(i); - i--; - } - break; - default: - warning("CAdResponseBox::WeedResponses - Unhandled enum"); - break; - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdResponseBox::setLastResponseText(const char *text, const char *textOrig) { - CBUtils::setString(&_lastResponseText, text); - CBUtils::setString(&_lastResponseTextOrig, textOrig); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::handleResponse(CAdResponse *response) { - setLastResponseText(response->_text, response->_textOrig); - - CAdGame *adGame = (CAdGame *)_gameRef; - - switch (response->_responseType) { - case RESPONSE_ONCE: - adGame->addBranchResponse(response->_iD); - break; - - case RESPONSE_ONCE_GAME: - adGame->addGameResponse(response->_iD); - break; - default: - warning("CAdResponseBox::HandleResponse - Unhandled enum"); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -CBObject *CAdResponseBox::getNextAccessObject(CBObject *currObject) { - CBArray objects; - getObjects(objects, true); - - if (objects.getSize() == 0) return NULL; - else { - if (currObject != NULL) { - for (int i = 0; i < objects.getSize(); i++) { - if (objects[i] == currObject) { - if (i < objects.getSize() - 1) return objects[i + 1]; - else break; - } - } - } - return objects[0]; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -CBObject *CAdResponseBox::getPrevAccessObject(CBObject *currObject) { - CBArray objects; - getObjects(objects, true); - - if (objects.getSize() == 0) return NULL; - else { - if (currObject != NULL) { - for (int i = objects.getSize() - 1; i >= 0; i--) { - if (objects[i] == currObject) { - if (i > 0) return objects[i - 1]; - else break; - } - } - } - return objects[objects.getSize() - 1]; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::getObjects(CBArray &objects, bool interactiveOnly) { - for (int i = 0; i < _respButtons.getSize(); i++) { - objects.add(_respButtons[i]); - } - if (_window) _window->getWindowObjects(objects, interactiveOnly); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdResponseBox.h b/engines/wintermute/ad/AdResponseBox.h deleted file mode 100644 index 93b677bd4a..0000000000 --- a/engines/wintermute/ad/AdResponseBox.h +++ /dev/null @@ -1,87 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADRESPONSEBOX_H -#define WINTERMUTE_ADRESPONSEBOX_H - - -#include "engines/wintermute/base/BObject.h" - -namespace WinterMute { - -class CUIButton; -class CUIWindow; -class CUIObject; -class CAdResponse; -class CAdResponseBox : public CBObject { -public: - CBObject *getNextAccessObject(CBObject *CurrObject); - CBObject *getPrevAccessObject(CBObject *CurrObject); - bool getObjects(CBArray &objects, bool interactiveOnly); - - bool handleResponse(CAdResponse *response); - void setLastResponseText(const char *text, const char *textOrig); - char *_lastResponseText; - char *_lastResponseTextOrig; - DECLARE_PERSISTENT(CAdResponseBox, CBObject) - CScScript *_waitingScript; - virtual bool listen(CBScriptHolder *param1, uint32 param2); - typedef enum { - EVENT_PREV, - EVENT_NEXT, - EVENT_RESPONSE - } TResponseEvent; - - bool weedResponses(); - bool display(); - int _spacing; - int _scrollOffset; - CBFont *_fontHover; - CBFont *_font; - bool createButtons(); - bool invalidateButtons(); - void clearButtons(); - void clearResponses(); - CAdResponseBox(CBGame *inGame); - virtual ~CAdResponseBox(); - CBArray _responses; - CBArray _respButtons; - CUIWindow *_window; - CUIWindow *_shieldWindow; - bool _horizontal; - Rect32 _responseArea; - int _verticalAlign; - TTextAlign _align; - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdResponseContext.cpp b/engines/wintermute/ad/AdResponseContext.cpp deleted file mode 100644 index 8573e58b95..0000000000 --- a/engines/wintermute/ad/AdResponseContext.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdResponseContext.h" -#include "engines/wintermute/base/BPersistMgr.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdResponseContext, false) - -////////////////////////////////////////////////////////////////////////// -CAdResponseContext::CAdResponseContext(CBGame *inGame): CBBase(inGame) { - _iD = 0; - _context = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdResponseContext::~CAdResponseContext() { - delete[] _context; - _context = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdResponseContext::persist(CBPersistMgr *persistMgr) { - persistMgr->transfer(TMEMBER(_gameRef)); - persistMgr->transfer(TMEMBER(_context)); - persistMgr->transfer(TMEMBER(_iD)); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -void CAdResponseContext::setContext(const char *context) { - delete[] _context; - _context = NULL; - if (context) { - _context = new char [strlen(context) + 1]; - if (_context) strcpy(_context, context); - } -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdResponseContext.h b/engines/wintermute/ad/AdResponseContext.h deleted file mode 100644 index 74506405de..0000000000 --- a/engines/wintermute/ad/AdResponseContext.h +++ /dev/null @@ -1,50 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADRESPONSECONTEXT_H -#define WINTERMUTE_ADRESPONSECONTEXT_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/BBase.h" - -namespace WinterMute { - -class CAdResponseContext : public CBBase { -public: - void setContext(const char *context); - int _iD; - char *_context; - DECLARE_PERSISTENT(CAdResponseContext, CBBase) - CAdResponseContext(CBGame *inGame); - virtual ~CAdResponseContext(); - -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdRotLevel.cpp b/engines/wintermute/ad/AdRotLevel.cpp deleted file mode 100644 index 671d003f35..0000000000 --- a/engines/wintermute/ad/AdRotLevel.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdRotLevel.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/base/BFileManager.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdRotLevel, false) - - -////////////////////////////////////////////////////////////////////////// -CAdRotLevel::CAdRotLevel(CBGame *inGame): CBObject(inGame) { - _posX = 0; - _rotation = 0.0f; -} - - -////////////////////////////////////////////////////////////////////////// -CAdRotLevel::~CAdRotLevel() { - -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdRotLevel::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdRotLevel::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(ROTATION_LEVEL) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(X) -TOKEN_DEF(ROTATION) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdRotLevel::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ROTATION_LEVEL) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(X) - TOKEN_TABLE(ROTATION) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ROTATION_LEVEL) { - _gameRef->LOG(0, "'ROTATION_LEVEL' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_X: - parser.scanStr((char *)params, "%d", &_posX); - break; - - case TOKEN_ROTATION: { - int i; - parser.scanStr((char *)params, "%d", &i); - _rotation = (float)i; - } - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ROTATION_LEVEL definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdRotLevel::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "ROTATION_LEVEL {\n"); - buffer->putTextIndent(indent + 2, "X=%d\n", _posX); - buffer->putTextIndent(indent + 2, "ROTATION=%d\n", (int)_rotation); - CBBase::saveAsText(buffer, indent + 2); - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdRotLevel::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_rotation)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdRotLevel.h b/engines/wintermute/ad/AdRotLevel.h deleted file mode 100644 index 9e536a8d8f..0000000000 --- a/engines/wintermute/ad/AdRotLevel.h +++ /dev/null @@ -1,49 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADROTLEVEL_H -#define WINTERMUTE_ADROTLEVEL_H - -#include "engines/wintermute/base/BObject.h" - -namespace WinterMute { - -class CAdRotLevel : public CBObject { -public: - DECLARE_PERSISTENT(CAdRotLevel, CBObject) - CAdRotLevel(CBGame *inGame); - virtual ~CAdRotLevel(); - float _rotation; - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdScaleLevel.cpp b/engines/wintermute/ad/AdScaleLevel.cpp deleted file mode 100644 index 1ac2f7ba6c..0000000000 --- a/engines/wintermute/ad/AdScaleLevel.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdScaleLevel.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BFileManager.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdScaleLevel, false) - -////////////////////////////////////////////////////////////////////////// -CAdScaleLevel::CAdScaleLevel(CBGame *inGame): CBObject(inGame) { - _posY = 0; - _scale = 100; -} - - -////////////////////////////////////////////////////////////////////////// -CAdScaleLevel::~CAdScaleLevel() { - -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScaleLevel::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdScaleLevel::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(SCALE_LEVEL) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(Y) -TOKEN_DEF(SCALE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdScaleLevel::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(SCALE_LEVEL) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(Y) - TOKEN_TABLE(SCALE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCALE_LEVEL) { - _gameRef->LOG(0, "'SCALE_LEVEL' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_Y: - parser.scanStr((char *)params, "%d", &_posY); - break; - - case TOKEN_SCALE: { - int i; - parser.scanStr((char *)params, "%d", &i); - _scale = (float)i; - } - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in SCALE_LEVEL definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScaleLevel::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "SCALE_LEVEL {\n"); - buffer->putTextIndent(indent + 2, "Y=%d\n", _posY); - buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_scale); - CBBase::saveAsText(buffer, indent + 2); - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScaleLevel::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_scale)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdScaleLevel.h b/engines/wintermute/ad/AdScaleLevel.h deleted file mode 100644 index c360ec4eff..0000000000 --- a/engines/wintermute/ad/AdScaleLevel.h +++ /dev/null @@ -1,50 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSCALELEVEL_H -#define WINTERMUTE_ADSCALELEVEL_H - - -#include "engines/wintermute/base/BObject.h" - -namespace WinterMute { - -class CAdScaleLevel : public CBObject { -public: - DECLARE_PERSISTENT(CAdScaleLevel, CBObject) - float _scale; - CAdScaleLevel(CBGame *inGame); - virtual ~CAdScaleLevel(); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdScene.cpp b/engines/wintermute/ad/AdScene.cpp deleted file mode 100644 index b284543a08..0000000000 --- a/engines/wintermute/ad/AdScene.cpp +++ /dev/null @@ -1,2752 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/AdScene.h" -#include "engines/wintermute/ad/AdActor.h" -#include "engines/wintermute/ad/AdEntity.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/ad/AdLayer.h" -#include "engines/wintermute/ad/AdNodeState.h" -#include "engines/wintermute/ad/AdObject.h" -#include "engines/wintermute/ad/AdPath.h" -#include "engines/wintermute/ad/AdPathPoint.h" -#include "engines/wintermute/ad/AdRotLevel.h" -#include "engines/wintermute/ad/AdScaleLevel.h" -#include "engines/wintermute/ad/AdSceneNode.h" -#include "engines/wintermute/ad/AdSceneState.h" -#include "engines/wintermute/ad/AdSentence.h" -#include "engines/wintermute/ad/AdWaypointGroup.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/base/font/BFont.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BObject.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BPoint.h" -#include "engines/wintermute/base/BRegion.h" -#include "engines/wintermute/base/BScriptable.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/base/BViewport.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/ui/UIWindow.h" -#include "engines/wintermute/utils/utils.h" -#include - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdScene, false) - -////////////////////////////////////////////////////////////////////////// -CAdScene::CAdScene(CBGame *inGame): CBObject(inGame) { - _pfTarget = new CBPoint; - setDefaults(); -} - - -////////////////////////////////////////////////////////////////////////// -CAdScene::~CAdScene() { - cleanup(); - _gameRef->unregisterObject(_fader); - delete _pfTarget; - _pfTarget = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::setDefaults() { - _initialized = false; - _pfReady = true; - _pfTargetPath = NULL; - _pfRequester = NULL; - _mainLayer = NULL; - - _pfPointsNum = 0; - _persistentState = false; - _persistentStateSprites = true; - - _autoScroll = true; - _offsetLeft = _offsetTop = 0; - _targetOffsetLeft = _targetOffsetTop = 0; - - _lastTimeH = _lastTimeV = 0; - _scrollTimeH = _scrollTimeV = 10; - _scrollPixelsH = _scrollPixelsV = 1; - - _pfMaxTime = 15; - - _paralaxScrolling = true; - - // editor settings - _editorMarginH = _editorMarginV = 100; - - _editorColFrame = 0xE0888888; - _editorColEntity = 0xFF008000; - _editorColRegion = 0xFF0000FF; - _editorColBlocked = 0xFF800080; - _editorColWaypoints = 0xFF0000FF; - _editorColEntitySel = 0xFFFF0000; - _editorColRegionSel = 0xFFFF0000; - _editorColBlockedSel = 0xFFFF0000; - _editorColWaypointsSel = 0xFFFF0000; - _editorColScale = 0xFF00FF00; - _editorColDecor = 0xFF00FFFF; - _editorColDecorSel = 0xFFFF0000; - - _editorShowRegions = true; - _editorShowBlocked = true; - _editorShowDecor = true; - _editorShowEntities = true; - _editorShowScale = true; - - _shieldWindow = NULL; - - _fader = new CBFader(_gameRef); - _gameRef->registerObject(_fader); - - _viewport = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::cleanup() { - CBObject::cleanup(); - - _mainLayer = NULL; // reference only - - int i; - - delete _shieldWindow; - _shieldWindow = NULL; - - _gameRef->unregisterObject(_fader); - _fader = NULL; - - for (i = 0; i < _layers.getSize(); i++) - _gameRef->unregisterObject(_layers[i]); - _layers.removeAll(); - - - for (i = 0; i < _waypointGroups.getSize(); i++) - _gameRef->unregisterObject(_waypointGroups[i]); - _waypointGroups.removeAll(); - - for (i = 0; i < _scaleLevels.getSize(); i++) - _gameRef->unregisterObject(_scaleLevels[i]); - _scaleLevels.removeAll(); - - for (i = 0; i < _rotLevels.getSize(); i++) - _gameRef->unregisterObject(_rotLevels[i]); - _rotLevels.removeAll(); - - - for (i = 0; i < _pfPath.getSize(); i++) - delete _pfPath[i]; - _pfPath.removeAll(); - _pfPointsNum = 0; - - for (i = 0; i < _objects.getSize(); i++) - _gameRef->unregisterObject(_objects[i]); - _objects.removeAll(); - - delete _viewport; - _viewport = NULL; - - setDefaults(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject *requester) { - if (!_pfReady) return false; - else { - _pfReady = false; - *_pfTarget = target; - _pfTargetPath = path; - _pfRequester = requester; - - _pfTargetPath->reset(); - _pfTargetPath->setReady(false); - - // prepare working path - int i; - pfPointsStart(); - - // first point - //_pfPath.add(new CAdPathPoint(source.x, source.y, 0)); - - // if we're one pixel stuck, get unstuck - int startX = source.x; - int startY = source.y; - int bestDistance = 1000; - if (isBlockedAt(startX, startY, true, requester)) { - int tolerance = 2; - for (int xxx = startX - tolerance; xxx <= startX + tolerance; xxx++) { - for (int yyy = startY - tolerance; yyy <= startY + tolerance; yyy++) { - if (isWalkableAt(xxx, yyy, true, requester)) { - int distance = abs(xxx - source.x) + abs(yyy - source.y); - if (distance < bestDistance) { - startX = xxx; - startY = yyy; - - bestDistance = distance; - } - } - } - } - } - - pfPointsAdd(startX, startY, 0); - - //CorrectTargetPoint(&target.x, &target.y); - - // last point - //_pfPath.add(new CAdPathPoint(target.x, target.y, INT_MAX)); - pfPointsAdd(target.x, target.y, INT_MAX); - - // active waypoints - for (i = 0; i < _waypointGroups.getSize(); i++) { - if (_waypointGroups[i]->_active) { - pfAddWaypointGroup(_waypointGroups[i], requester); - } - } - - - // free waypoints - for (i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentWptGroup) { - pfAddWaypointGroup(_objects[i]->_currentWptGroup, requester); - } - } - CAdGame *adGame = (CAdGame *)_gameRef; - for (i = 0; i < adGame->_objects.getSize(); i++) { - if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentWptGroup) { - pfAddWaypointGroup(adGame->_objects[i]->_currentWptGroup, requester); - } - } - - return true; - } -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::pfAddWaypointGroup(CAdWaypointGroup *wpt, CBObject *requester) { - if (!wpt->_active) return; - - for (int i = 0; i < wpt->_points.getSize(); i++) { - if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) continue; - - //_pfPath.add(new CAdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); - pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX); - } -} - - -////////////////////////////////////////////////////////////////////////// -float CAdScene::getZoomAt(int x, int y) { - float ret = 100; - - bool found = false; - if (_mainLayer) { - for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { - CAdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_blocked && node->_region->pointInRegion(x, y)) { - if (node->_region->_zoom != 0) { - ret = node->_region->_zoom; - found = true; - break; - } - } - } - } - if (!found) ret = getScaleAt(y); - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -uint32 CAdScene::getAlphaAt(int x, int y, bool colorCheck) { - if (!_gameRef->_debugDebugMode) colorCheck = false; - - uint32 ret; - if (colorCheck) ret = 0xFFFF0000; - else ret = 0xFFFFFFFF; - - if (_mainLayer) { - for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { - CAdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { - if (!node->_region->_blocked) ret = node->_region->_alpha; - break; - } - } - } - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::isBlockedAt(int x, int y, bool checkFreeObjects, CBObject *requester) { - bool ret = true; - - - if (checkFreeObjects) { - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { - if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; - } - } - CAdGame *adGame = (CAdGame *)_gameRef; - for (int i = 0; i < adGame->_objects.getSize(); i++) { - if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { - if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; - } - } - } - - - if (_mainLayer) { - for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { - CAdSceneNode *node = _mainLayer->_nodes[i]; - /* - if (Node->_type == OBJECT_REGION && Node->_region->_active && Node->_region->_blocked && Node->_region->PointInRegion(X, Y)) - { - ret = true; - break; - } - */ - if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { - if (node->_region->_blocked) { - ret = true; - break; - } else ret = false; - } - } - } - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::isWalkableAt(int x, int y, bool checkFreeObjects, CBObject *requester) { - bool ret = false; - - if (checkFreeObjects) { - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { - if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; - } - } - CAdGame *adGame = (CAdGame *)_gameRef; - for (int i = 0; i < adGame->_objects.getSize(); i++) { - if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { - if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; - } - } - } - - - if (_mainLayer) { - for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { - CAdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { - if (node->_region->_blocked) { - ret = false; - break; - } else ret = true; - } - } - } - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -int CAdScene::getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester) { - double xStep, yStep, x, y; - int xLength, yLength, xCount, yCount; - int x1, y1, x2, y2; - - x1 = p1.x; - y1 = p1.y; - x2 = p2.x; - y2 = p2.y; - - xLength = abs(x2 - x1); - yLength = abs(y2 - y1); - - if (xLength > yLength) { - if (x1 > x2) { - CBUtils::swap(&x1, &x2); - CBUtils::swap(&y1, &y2); - } - - yStep = (double)(y2 - y1) / (double)(x2 - x1); - y = y1; - - for (xCount = x1; xCount < x2; xCount++) { - if (isBlockedAt(xCount, (int)y, true, requester)) return -1; - y += yStep; - } - } else { - if (y1 > y2) { - CBUtils::swap(&x1, &x2); - CBUtils::swap(&y1, &y2); - } - - xStep = (double)(x2 - x1) / (double)(y2 - y1); - x = x1; - - for (yCount = y1; yCount < y2; yCount++) { - if (isBlockedAt((int)x, yCount, true, requester)) return -1; - x += xStep; - } - } - return MAX(xLength, yLength); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::pathFinderStep() { - int i; - // get lowest unmarked - int lowestDist = INT_MAX; - CAdPathPoint *lowestPt = NULL; - - for (i = 0; i < _pfPointsNum; i++) - if (!_pfPath[i]->_marked && _pfPath[i]->_distance < lowestDist) { - lowestDist = _pfPath[i]->_distance; - lowestPt = _pfPath[i]; - } - - if (lowestPt == NULL) { // no path -> terminate PathFinder - _pfReady = true; - _pfTargetPath->setReady(true); - return; - } - - lowestPt->_marked = true; - - // target point marked, generate path and terminate - if (lowestPt->x == _pfTarget->x && lowestPt->y == _pfTarget->y) { - while (lowestPt != NULL) { - _pfTargetPath->_points.insertAt(0, new CBPoint(lowestPt->x, lowestPt->y)); - lowestPt = lowestPt->_origin; - } - - _pfReady = true; - _pfTargetPath->setReady(true); - return; - } - - // otherwise keep on searching - for (i = 0; i < _pfPointsNum; i++) - if (!_pfPath[i]->_marked) { - int j = getPointsDist(*lowestPt, *_pfPath[i], _pfRequester); - if (j != -1 && lowestPt->_distance + j < _pfPath[i]->_distance) { - _pfPath[i]->_distance = lowestPt->_distance + j; - _pfPath[i]->_origin = lowestPt; - } - } -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::initLoop() { -#ifdef _DEBUGxxxx - int nu_steps = 0; - uint32 start = _gameRef->_currentTime; - while (!_pfReady && CBPlatform::getTime() - start <= _pfMaxTime) { - PathFinderStep(); - nu_steps++; - } - if (nu_steps > 0) _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); -#else - uint32 start = _gameRef->_currentTime; - while (!_pfReady && CBPlatform::getTime() - start <= _pfMaxTime) pathFinderStep(); -#endif - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdScene::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - delete[] _filename; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(SCENE) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(NAME) -TOKEN_DEF(LAYER) -TOKEN_DEF(WAYPOINTS) -TOKEN_DEF(EVENTS) -TOKEN_DEF(CURSOR) -TOKEN_DEF(CAMERA) -TOKEN_DEF(ENTITY) -TOKEN_DEF(SCALE_LEVEL) -TOKEN_DEF(ROTATION_LEVEL) -TOKEN_DEF(EDITOR_MARGIN_H) -TOKEN_DEF(EDITOR_MARGIN_V) -TOKEN_DEF(EDITOR_COLOR_FRAME) -TOKEN_DEF(EDITOR_COLOR_ENTITY_SEL) -TOKEN_DEF(EDITOR_COLOR_REGION_SEL) -TOKEN_DEF(EDITOR_COLOR_DECORATION_SEL) -TOKEN_DEF(EDITOR_COLOR_BLOCKED_SEL) -TOKEN_DEF(EDITOR_COLOR_WAYPOINTS_SEL) -TOKEN_DEF(EDITOR_COLOR_REGION) -TOKEN_DEF(EDITOR_COLOR_DECORATION) -TOKEN_DEF(EDITOR_COLOR_BLOCKED) -TOKEN_DEF(EDITOR_COLOR_ENTITY) -TOKEN_DEF(EDITOR_COLOR_WAYPOINTS) -TOKEN_DEF(EDITOR_COLOR_SCALE) -TOKEN_DEF(EDITOR_SHOW_REGIONS) -TOKEN_DEF(EDITOR_SHOW_BLOCKED) -TOKEN_DEF(EDITOR_SHOW_DECORATION) -TOKEN_DEF(EDITOR_SHOW_ENTITIES) -TOKEN_DEF(EDITOR_SHOW_SCALE) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(VIEWPORT) -TOKEN_DEF(PERSISTENT_STATE_SPRITES) -TOKEN_DEF(PERSISTENT_STATE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdScene::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(SCENE) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(NAME) - TOKEN_TABLE(LAYER) - TOKEN_TABLE(WAYPOINTS) - TOKEN_TABLE(EVENTS) - TOKEN_TABLE(CURSOR) - TOKEN_TABLE(CAMERA) - TOKEN_TABLE(ENTITY) - TOKEN_TABLE(SCALE_LEVEL) - TOKEN_TABLE(ROTATION_LEVEL) - TOKEN_TABLE(EDITOR_MARGIN_H) - TOKEN_TABLE(EDITOR_MARGIN_V) - TOKEN_TABLE(EDITOR_COLOR_FRAME) - TOKEN_TABLE(EDITOR_COLOR_ENTITY_SEL) - TOKEN_TABLE(EDITOR_COLOR_REGION_SEL) - TOKEN_TABLE(EDITOR_COLOR_DECORATION_SEL) - TOKEN_TABLE(EDITOR_COLOR_BLOCKED_SEL) - TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS_SEL) - TOKEN_TABLE(EDITOR_COLOR_REGION) - TOKEN_TABLE(EDITOR_COLOR_DECORATION) - TOKEN_TABLE(EDITOR_COLOR_BLOCKED) - TOKEN_TABLE(EDITOR_COLOR_ENTITY) - TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS) - TOKEN_TABLE(EDITOR_COLOR_SCALE) - TOKEN_TABLE(EDITOR_SHOW_REGIONS) - TOKEN_TABLE(EDITOR_SHOW_DECORATION) - TOKEN_TABLE(EDITOR_SHOW_BLOCKED) - TOKEN_TABLE(EDITOR_SHOW_ENTITIES) - TOKEN_TABLE(EDITOR_SHOW_SCALE) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(VIEWPORT) - TOKEN_TABLE(PERSISTENT_STATE_SPRITES) - TOKEN_TABLE(PERSISTENT_STATE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - cleanup(); - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCENE) { - _gameRef->LOG(0, "'SCENE' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - int ar, ag, ab, aa; - char camera[MAX_PATH_LENGTH] = ""; - /* float WaypointHeight = -1.0f; */ - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_LAYER: { - CAdLayer *layer = new CAdLayer(_gameRef); - if (!layer || DID_FAIL(layer->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete layer; - layer = NULL; - } else { - _gameRef->registerObject(layer); - _layers.add(layer); - if (layer->_main) { - _mainLayer = layer; - _width = layer->_width; - _height = layer->_height; - } - } - } - break; - - case TOKEN_WAYPOINTS: { - CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); - if (!wpt || DID_FAIL(wpt->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete wpt; - wpt = NULL; - } else { - _gameRef->registerObject(wpt); - _waypointGroups.add(wpt); - } - } - break; - - case TOKEN_SCALE_LEVEL: { - CAdScaleLevel *sl = new CAdScaleLevel(_gameRef); - if (!sl || DID_FAIL(sl->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete sl; - sl = NULL; - } else { - _gameRef->registerObject(sl); - _scaleLevels.add(sl); - } - } - break; - - case TOKEN_ROTATION_LEVEL: { - CAdRotLevel *rl = new CAdRotLevel(_gameRef); - if (!rl || DID_FAIL(rl->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete rl; - rl = NULL; - } else { - _gameRef->registerObject(rl); - _rotLevels.add(rl); - } - } - break; - - case TOKEN_ENTITY: { - CAdEntity *entity = new CAdEntity(_gameRef); - if (!entity || DID_FAIL(entity->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete entity; - entity = NULL; - } else { - addObject(entity); - } - } - break; - - case TOKEN_CURSOR: - delete _cursor; - _cursor = new CBSprite(_gameRef); - if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { - delete _cursor; - _cursor = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_CAMERA: - strcpy(camera, (char *)params); - break; - - case TOKEN_EDITOR_MARGIN_H: - parser.scanStr((char *)params, "%d", &_editorMarginH); - break; - - case TOKEN_EDITOR_MARGIN_V: - parser.scanStr((char *)params, "%d", &_editorMarginV); - break; - - case TOKEN_EDITOR_COLOR_FRAME: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColFrame = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_ENTITY: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColEntity = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_ENTITY_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColEntitySel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_REGION_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColRegionSel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_DECORATION_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColDecorSel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_BLOCKED_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColBlockedSel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_WAYPOINTS_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColWaypointsSel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_REGION: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColRegion = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_DECORATION: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColDecor = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_BLOCKED: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColBlocked = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_WAYPOINTS: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColWaypoints = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_SCALE: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColScale = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_SHOW_REGIONS: - parser.scanStr((char *)params, "%b", &_editorShowRegions); - break; - - case TOKEN_EDITOR_SHOW_BLOCKED: - parser.scanStr((char *)params, "%b", &_editorShowBlocked); - break; - - case TOKEN_EDITOR_SHOW_DECORATION: - parser.scanStr((char *)params, "%b", &_editorShowDecor); - break; - - case TOKEN_EDITOR_SHOW_ENTITIES: - parser.scanStr((char *)params, "%b", &_editorShowEntities); - break; - - case TOKEN_EDITOR_SHOW_SCALE: - parser.scanStr((char *)params, "%b", &_editorShowScale); - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_VIEWPORT: { - Rect32 rc; - parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_viewport) _viewport = new CBViewport(_gameRef); - if (_viewport) _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); - } - - case TOKEN_PERSISTENT_STATE: - parser.scanStr((char *)params, "%b", &_persistentState); - break; - - case TOKEN_PERSISTENT_STATE_SPRITES: - parser.scanStr((char *)params, "%b", &_persistentStateSprites); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in SCENE definition"); - return STATUS_FAILED; - } - - if (_mainLayer == NULL) _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", _filename); - - - sortScaleLevels(); - sortRotLevels(); - - _initialized = true; - - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::traverseNodes(bool doUpdate) { - if (!_initialized) return STATUS_OK; - - int j, k; - CAdGame *adGame = (CAdGame *)_gameRef; - - - ////////////////////////////////////////////////////////////////////////// - // prepare viewport - bool PopViewport = false; - if (_viewport && !_gameRef->_editorMode) { - _gameRef->pushViewport(_viewport); - PopViewport = true; - } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - _gameRef->pushViewport(adGame->_sceneViewport); - PopViewport = true; - } - - - ////////////////////////////////////////////////////////////////////////// - // *** adjust scroll offset - if (doUpdate) { - /* - if (_autoScroll && _gameRef->_mainObject != NULL) - { - ScrollToObject(_gameRef->_mainObject); - } - */ - - if (_autoScroll) { - // adjust horizontal scroll - if (_gameRef->_timer - _lastTimeH >= _scrollTimeH) { - _lastTimeH = _gameRef->_timer; - if (_offsetLeft < _targetOffsetLeft) { - _offsetLeft += _scrollPixelsH; - _offsetLeft = MIN(_offsetLeft, _targetOffsetLeft); - } else if (_offsetLeft > _targetOffsetLeft) { - _offsetLeft -= _scrollPixelsH; - _offsetLeft = MAX(_offsetLeft, _targetOffsetLeft); - } - } - - // adjust vertical scroll - if (_gameRef->_timer - _lastTimeV >= _scrollTimeV) { - _lastTimeV = _gameRef->_timer; - if (_offsetTop < _targetOffsetTop) { - _offsetTop += _scrollPixelsV; - _offsetTop = MIN(_offsetTop, _targetOffsetTop); - } else if (_offsetTop > _targetOffsetTop) { - _offsetTop -= _scrollPixelsV; - _offsetTop = MAX(_offsetTop, _targetOffsetTop); - } - } - - if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) _ready = true; - } else _ready = true; // not scrolling, i.e. always ready - } - - - - - ////////////////////////////////////////////////////////////////////////// - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - int viewportX, viewportY; - getViewportOffset(&viewportX, &viewportY); - - int scrollableX = _width - viewportWidth; - int scrollableY = _height - viewportHeight; - - double widthRatio = scrollableX <= 0 ? 0 : ((double)(_offsetLeft) / (double)scrollableX); - double heightRatio = scrollableY <= 0 ? 0 : ((double)(_offsetTop) / (double)scrollableY); - - int origX, origY; - _gameRef->getOffset(&origX, &origY); - - - - ////////////////////////////////////////////////////////////////////////// - // *** display/update everything - _gameRef->_renderer->setup2D(); - - // for each layer - /* int MainOffsetX = 0; */ - /* int MainOffsetY = 0; */ - - for (j = 0; j < _layers.getSize(); j++) { - if (!_layers[j]->_active) continue; - - // make layer exclusive - if (!doUpdate) { - if (_layers[j]->_closeUp && !_gameRef->_editorMode) { - if (!_shieldWindow) _shieldWindow = new CUIWindow(_gameRef); - if (_shieldWindow) { - _shieldWindow->_posX = _shieldWindow->_posY = 0; - _shieldWindow->_width = _gameRef->_renderer->_width; - _shieldWindow->_height = _gameRef->_renderer->_height; - _shieldWindow->display(); - } - } - } - - if (_paralaxScrolling) { - int offsetX = (int)(widthRatio * (_layers[j]->_width - viewportWidth) - viewportX); - int offsetY = (int)(heightRatio * (_layers[j]->_height - viewportHeight) - viewportY); - _gameRef->setOffset(offsetX, offsetY); - - _gameRef->_offsetPercentX = (float)offsetX / ((float)_layers[j]->_width - viewportWidth) * 100.0f; - _gameRef->_offsetPercentY = (float)offsetY / ((float)_layers[j]->_height - viewportHeight) * 100.0f; - - //_gameRef->QuickMessageForm("%d %f", OffsetX+ViewportX, _gameRef->_offsetPercentX); - } else { - _gameRef->setOffset(_offsetLeft - viewportX, _offsetTop - viewportY); - - _gameRef->_offsetPercentX = (float)(_offsetLeft - viewportX) / ((float)_layers[j]->_width - viewportWidth) * 100.0f; - _gameRef->_offsetPercentY = (float)(_offsetTop - viewportY) / ((float)_layers[j]->_height - viewportHeight) * 100.0f; - } - - - // for each node - for (k = 0; k < _layers[j]->_nodes.getSize(); k++) { - CAdSceneNode *node = _layers[j]->_nodes[k]; - switch (node->_type) { - case OBJECT_ENTITY: - if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) { - _gameRef->_renderer->setup2D(); - - if (doUpdate) node->_entity->update(); - else node->_entity->display(); - } - break; - - case OBJECT_REGION: { - if (node->_region->_blocked) break; - if (node->_region->_decoration) break; - - if (!doUpdate) displayRegionContent(node->_region); - } - break; - default: - error("AdScene::TraverseNodes - Unhandled enum"); - break; - } // switch - } // each node - - // display/update all objects which are off-regions - if (_layers[j]->_main) { - if (doUpdate) { - updateFreeObjects(); - } else { - displayRegionContent(NULL); - } - } - } // each layer - - - // restore state - _gameRef->setOffset(origX, origY); - _gameRef->_renderer->setup2D(); - - // display/update fader - if (_fader) { - if (doUpdate) _fader->update(); - else _fader->display(); - } - - if (PopViewport) _gameRef->popViewport(); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::display() { - return traverseNodes(false); -} - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::updateFreeObjects() { - CAdGame *adGame = (CAdGame *)_gameRef; - bool is3DSet; - - // *** update all active objects - is3DSet = false; - for (int i = 0; i < adGame->_objects.getSize(); i++) { - if (!adGame->_objects[i]->_active) continue; - - adGame->_objects[i]->update(); - adGame->_objects[i]->_drawn = false; - } - - - for (int i = 0; i < _objects.getSize(); i++) { - if (!_objects[i]->_active) continue; - - _objects[i]->update(); - _objects[i]->_drawn = false; - } - - - if (_autoScroll && _gameRef->_mainObject != NULL) { - scrollToObject(_gameRef->_mainObject); - } - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::displayRegionContent(CAdRegion *region, bool display3DOnly) { - CAdGame *adGame = (CAdGame *)_gameRef; - CBArray objects; - CAdObject *obj; - - // global objects - for (int i = 0; i < adGame->_objects.getSize(); i++) { - obj = adGame->_objects[i]; - if (obj->_active && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - objects.add(obj); - } - } - - // scene objects - for (int i = 0; i < _objects.getSize(); i++) { - obj = _objects[i]; - if (obj->_active && !obj->_editorOnly && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - objects.add(obj); - } - } - - // sort by _posY - qsort(objects.getData(), objects.getSize(), sizeof(CAdObject *), CAdScene::compareObjs); - - // display them - for (int i = 0; i < objects.getSize(); i++) { - obj = objects[i]; - - if (display3DOnly && !obj->_is3D) continue; - - _gameRef->_renderer->setup2D(); - - if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); - obj->_drawn = true; - } - - - // display design only objects - if (!display3DOnly) { - if (_gameRef->_editorMode && region == NULL) { - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_active && _objects[i]->_editorOnly) { - _objects[i]->display(); - _objects[i]->_drawn = true; - } - } - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -int CAdScene::compareObjs(const void *obj1, const void *obj2) { - CAdObject *object1 = *(CAdObject **)obj1; - CAdObject *object2 = *(CAdObject **)obj2; - - if (object1->_posY < object2->_posY) return -1; - else if (object1->_posY > object2->_posY) return 1; - else return 0; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::displayRegionContentOld(CAdRegion *region) { - CAdGame *adGame = (CAdGame *)_gameRef; - CAdObject *obj; - - // display all objects in region sorted by _posY - do { - obj = NULL; - int minY = INT_MAX; - - // global objects - for (int i = 0; i < adGame->_objects.getSize(); i++) { - if (adGame->_objects[i]->_active && !adGame->_objects[i]->_drawn && adGame->_objects[i]->_posY < minY && (adGame->_objects[i]->_stickRegion == region || region == NULL || (adGame->_objects[i]->_stickRegion == NULL && region->pointInRegion(adGame->_objects[i]->_posX, adGame->_objects[i]->_posY)))) { - obj = adGame->_objects[i]; - minY = adGame->_objects[i]->_posY; - } - } - - // scene objects - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_active && !_objects[i]->_editorOnly && !_objects[i]->_drawn && _objects[i]->_posY < minY && (_objects[i]->_stickRegion == region || region == NULL || (_objects[i]->_stickRegion == NULL && region->pointInRegion(_objects[i]->_posX, _objects[i]->_posY)))) { - obj = _objects[i]; - minY = _objects[i]->_posY; - } - } - - - if (obj != NULL) { - _gameRef->_renderer->setup2D(); - - if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); - obj->_drawn = true; - } - } while (obj != NULL); - - - // design only objects - if (_gameRef->_editorMode && region == NULL) { - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_active && _objects[i]->_editorOnly) { - _objects[i]->display(); - _objects[i]->_drawn = true; - } - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::update() { - return traverseNodes(true); -} - -////////////////////////////////////////////////////////////////////////// -void CAdScene::scrollTo(int offsetX, int offsetY) { - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - int origOffsetLeft = _targetOffsetLeft; - int origOffsetTop = _targetOffsetTop; - - _targetOffsetLeft = MAX(0, offsetX - viewportWidth / 2); - _targetOffsetLeft = MIN(_targetOffsetLeft, _width - viewportWidth); - - _targetOffsetTop = MAX(0, offsetY - viewportHeight / 2); - _targetOffsetTop = MIN(_targetOffsetTop, _height - viewportHeight); - - - if (_gameRef->_mainObject && _gameRef->_mainObject->_is3D) { - if (abs(origOffsetLeft - _targetOffsetLeft) < 5) _targetOffsetLeft = origOffsetLeft; - if (abs(origOffsetTop - _targetOffsetTop) < 5) _targetOffsetTop = origOffsetTop; - //_targetOffsetTop = 0; - } - - _ready = false; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::scrollToObject(CBObject *object) { - if (object) scrollTo(object->_posX, object->_posY - object->getHeight() / 2); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::skipToObject(CBObject *object) { - if (object) skipTo(object->_posX, object->_posY - object->getHeight() / 2); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::skipTo(int offsetX, int offsetY) { - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - _offsetLeft = MAX(0, offsetX - viewportWidth / 2); - _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); - - _offsetTop = MAX(0, offsetY - viewportHeight / 2); - _offsetTop = MIN(_offsetTop, _height - viewportHeight); - - _targetOffsetLeft = _offsetLeft; - _targetOffsetTop = _offsetTop; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // LoadActor - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "LoadActor") == 0) { - stack->correctParams(1); - CAdActor *act = new CAdActor(_gameRef); - if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { - addObject(act); - stack->pushNative(act, true); - } else { - delete act; - act = NULL; - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadEntity") == 0) { - stack->correctParams(1); - CAdEntity *ent = new CAdEntity(_gameRef); - if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { - addObject(ent); - stack->pushNative(ent, true); - } else { - delete ent; - ent = NULL; - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CreateEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateEntity") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdEntity *ent = new CAdEntity(_gameRef); - addObject(ent); - if (!val->isNULL()) ent->setName(val->getString()); - stack->pushNative(ent, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // UnloadObject / UnloadActor / UnloadEntity / UnloadActor3D / DeleteEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "UnloadActor3D") == 0 || strcmp(name, "DeleteEntity") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - CAdObject *obj = (CAdObject *)val->getNative(); - removeObject(obj); - if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SkipTo - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SkipTo") == 0) { - stack->correctParams(2); - CScValue *val1 = stack->pop(); - CScValue *val2 = stack->pop(); - if (val1->isNative()) { - skipToObject((CBObject *)val1->getNative()); - } else { - skipTo(val1->getInt(), val2->getInt()); - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollTo / ScrollToAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollTo") == 0 || strcmp(name, "ScrollToAsync") == 0) { - stack->correctParams(2); - CScValue *val1 = stack->pop(); - CScValue *val2 = stack->pop(); - if (val1->isNative()) { - scrollToObject((CBObject *)val1->getNative()); - } else { - scrollTo(val1->getInt(), val2->getInt()); - } - if (strcmp(name, "ScrollTo") == 0) script->waitForExclusive(this); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetLayer - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetLayer") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - if (val->isInt()) { - int layer = val->getInt(); - if (layer < 0 || layer >= _layers.getSize()) stack->pushNULL(); - else stack->pushNative(_layers[layer], true); - } else { - const char *LayerName = val->getString(); - bool LayerFound = false; - for (int i = 0; i < _layers.getSize(); i++) { - if (scumm_stricmp(LayerName, _layers[i]->_name) == 0) { - stack->pushNative(_layers[i], true); - LayerFound = true; - break; - } - } - if (!LayerFound) stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetWaypointGroup - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetWaypointGroup") == 0) { - stack->correctParams(1); - int group = stack->pop()->getInt(); - if (group < 0 || group >= _waypointGroups.getSize()) stack->pushNULL(); - else stack->pushNative(_waypointGroups[group], true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetNode - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetNode") == 0) { - stack->correctParams(1); - const char *nodeName = stack->pop()->getString(); - - CBObject *node = getNodeByName(nodeName); - if (node) stack->pushNative((CBScriptable *)node, true); - else stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetFreeNode - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetFreeNode") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdObject *ret = NULL; - if (val->isInt()) { - int index = val->getInt(); - if (index >= 0 && index < _objects.getSize()) ret = _objects[index]; - } else { - const char *nodeName = val->getString(); - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i] && _objects[i]->_name && scumm_stricmp(_objects[i]->_name, nodeName) == 0) { - ret = _objects[i]; - break; - } - } - } - if (ret) stack->pushNative(ret, true); - else stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetRegionAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetRegionAt") == 0) { - stack->correctParams(3); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - CScValue *val = stack->pop(); - - bool includeDecors = false; - if (!val->isNULL()) includeDecors = val->getBool(); - - if (_mainLayer) { - for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { - CAdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { - if (node->_region->_decoration && !includeDecors) continue; - - stack->pushNative(node->_region, true); - return STATUS_OK; - } - } - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsBlockedAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsBlockedAt") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - - stack->pushBool(isBlockedAt(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsWalkableAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsWalkableAt") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - - stack->pushBool(isWalkableAt(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetScaleAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetScaleAt") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - - stack->pushFloat(getZoomAt(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetRotationAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetRotationAt") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - - stack->pushFloat(getRotationAt(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsScrolling - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsScrolling") == 0) { - stack->correctParams(0); - bool ret = false; - if (_autoScroll) { - if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) ret = true; - } - - stack->pushBool(ret); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // FadeOut / FadeOutAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "FadeOut") == 0 || strcmp(name, "FadeOutAsync") == 0) { - stack->correctParams(5); - uint32 duration = stack->pop()->getInt(500); - byte red = stack->pop()->getInt(0); - byte green = stack->pop()->getInt(0); - byte blue = stack->pop()->getInt(0); - byte alpha = stack->pop()->getInt(0xFF); - - _fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration); - if (strcmp(name, "FadeOutAsync") != 0) script->waitFor(_fader); - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // FadeIn / FadeInAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "FadeIn") == 0 || strcmp(name, "FadeInAsync") == 0) { - stack->correctParams(5); - uint32 duration = stack->pop()->getInt(500); - byte red = stack->pop()->getInt(0); - byte green = stack->pop()->getInt(0); - byte blue = stack->pop()->getInt(0); - byte alpha = stack->pop()->getInt(0xFF); - - _fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration); - if (strcmp(name, "FadeInAsync") != 0) script->waitFor(_fader); - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetFadeColor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetFadeColor") == 0) { - stack->correctParams(0); - stack->pushInt(_fader->getCurrentColor()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsPointInViewport - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsPointInViewport") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - stack->pushBool(pointInViewport(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetViewport - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SetViewport") == 0) { - stack->correctParams(4); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - int width = stack->pop()->getInt(); - int height = stack->pop()->getInt(); - - if (width <= 0) width = _gameRef->_renderer->_width; - if (height <= 0) height = _gameRef->_renderer->_height; - - if (!_viewport) _viewport = new CBViewport(_gameRef); - if (_viewport) _viewport->setRect(x, y, x + width, y + height); - - stack->pushBool(true); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddLayer - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddLayer") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdLayer *layer = new CAdLayer(_gameRef); - if (!val->isNULL()) layer->setName(val->getString()); - if (_mainLayer) { - layer->_width = _mainLayer->_width; - layer->_height = _mainLayer->_height; - } - _layers.add(layer); - _gameRef->registerObject(layer); - - stack->pushNative(layer, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InsertLayer - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InsertLayer") == 0) { - stack->correctParams(2); - int index = stack->pop()->getInt(); - CScValue *val = stack->pop(); - - CAdLayer *layer = new CAdLayer(_gameRef); - if (!val->isNULL()) layer->setName(val->getString()); - if (_mainLayer) { - layer->_width = _mainLayer->_width; - layer->_height = _mainLayer->_height; - } - if (index < 0) index = 0; - if (index <= _layers.getSize() - 1) _layers.insertAt(index, layer); - else _layers.add(layer); - - _gameRef->registerObject(layer); - - stack->pushNative(layer, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteLayer - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteLayer") == 0) { - stack->correctParams(1); - CScValue *val = stack->pop(); - - CAdLayer *toDelete = NULL; - if (val->isNative()) { - CBScriptable *temp = val->getNative(); - for (int i = 0; i < _layers.getSize(); i++) { - if (_layers[i] == temp) { - toDelete = _layers[i]; - break; - } - } - } else { - int index = val->getInt(); - if (index >= 0 && index < _layers.getSize()) { - toDelete = _layers[index]; - } - } - if (toDelete == NULL) { - stack->pushBool(false); - return STATUS_OK; - } - - if (toDelete->_main) { - script->runtimeError("Scene.DeleteLayer - cannot delete main scene layer"); - stack->pushBool(false); - return STATUS_OK; - } - - for (int i = 0; i < _layers.getSize(); i++) { - if (_layers[i] == toDelete) { - _layers.removeAt(i); - _gameRef->unregisterObject(toDelete); - break; - } - } - stack->pushBool(true); - return STATUS_OK; - } - - else return CBObject::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdScene::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("scene"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumLayers (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumLayers") == 0) { - _scValue->setInt(_layers.getSize()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumWaypointGroups (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumWaypointGroups") == 0) { - _scValue->setInt(_waypointGroups.getSize()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // MainLayer (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MainLayer") == 0) { - if (_mainLayer) _scValue->setNative(_mainLayer, true); - else _scValue->setNULL(); - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumFreeNodes (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumFreeNodes") == 0) { - _scValue->setInt(_objects.getSize()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // MouseX (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MouseX") == 0) { - int viewportX; - getViewportOffset(&viewportX); - - _scValue->setInt(_gameRef->_mousePos.x + _offsetLeft - viewportX); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // MouseY (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MouseY") == 0) { - int viewportY; - getViewportOffset(NULL, &viewportY); - - _scValue->setInt(_gameRef->_mousePos.y + _offsetTop - viewportY); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AutoScroll - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AutoScroll") == 0) { - _scValue->setBool(_autoScroll); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // PersistentState - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentState") == 0) { - _scValue->setBool(_persistentState); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // PersistentStateSprites - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentStateSprites") == 0) { - _scValue->setBool(_persistentStateSprites); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollPixelsX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsX") == 0) { - _scValue->setInt(_scrollPixelsH); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollPixelsY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsY") == 0) { - _scValue->setInt(_scrollPixelsV); - return _scValue; - } - - - ////////////////////////////////////////////////////////////////////////// - // ScrollSpeedX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedX") == 0) { - _scValue->setInt(_scrollTimeH); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollSpeedY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedY") == 0) { - _scValue->setInt(_scrollTimeV); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // OffsetX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetX") == 0) { - _scValue->setInt(_offsetLeft); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // OffsetY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetY") == 0) { - _scValue->setInt(_offsetTop); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Width (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Width") == 0) { - if (_mainLayer) _scValue->setInt(_mainLayer->_width); - else _scValue->setInt(0); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Height (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Height") == 0) { - if (_mainLayer) _scValue->setInt(_mainLayer->_height); - else _scValue->setInt(0); - return _scValue; - } - - else return CBObject::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::scSetProperty(const char *name, CScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Name") == 0) { - setName(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AutoScroll - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AutoScroll") == 0) { - _autoScroll = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // PersistentState - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentState") == 0) { - _persistentState = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // PersistentStateSprites - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentStateSprites") == 0) { - _persistentStateSprites = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollPixelsX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsX") == 0) { - _scrollPixelsH = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollPixelsY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsY") == 0) { - _scrollPixelsV = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollSpeedX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedX") == 0) { - _scrollTimeH = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollSpeedY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedY") == 0) { - _scrollTimeV = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // OffsetX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetX") == 0) { - _offsetLeft = value->getInt(); - - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - _offsetLeft = MAX(0, _offsetLeft - viewportWidth / 2); - _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); - _targetOffsetLeft = _offsetLeft; - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // OffsetY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetY") == 0) { - _offsetTop = value->getInt(); - - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - _offsetTop = MAX(0, _offsetTop - viewportHeight / 2); - _offsetTop = MIN(_offsetTop, _height - viewportHeight); - _targetOffsetTop = _offsetTop; - - return STATUS_OK; - } - - else return CBObject::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *CAdScene::scToString() { - return "[scene object]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::addObject(CAdObject *object) { - _objects.add(object); - return _gameRef->registerObject(object); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::removeObject(CAdObject *object) { - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i] == object) { - _objects.removeAt(i); - return _gameRef->unregisterObject(object); - } - } - return STATUS_FAILED; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::saveAsText(CBDynBuffer *buffer, int indent) { - int i; - - buffer->putTextIndent(indent, "SCENE {\n"); - - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - - if (_persistentState) - buffer->putTextIndent(indent + 2, "PERSISTENT_STATE=%s\n", _persistentState ? "TRUE" : "FALSE"); - - if (!_persistentStateSprites) - buffer->putTextIndent(indent + 2, "PERSISTENT_STATE_SPRITES=%s\n", _persistentStateSprites ? "TRUE" : "FALSE"); - - - // scripts - for (i = 0; i < _scripts.getSize(); i++) { - buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); - } - - buffer->putTextIndent(indent + 2, "\n"); - - // properties - if (_scProp) _scProp->saveAsText(buffer, indent + 2); - - // viewport - if (_viewport) { - Rect32 *rc = _viewport->getRect(); - buffer->putTextIndent(indent + 2, "VIEWPORT { %d, %d, %d, %d }\n", rc->left, rc->top, rc->right, rc->bottom); - } - - - - // editor settings - buffer->putTextIndent(indent + 2, "; ----- editor settings\n"); - buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_H=%d\n", _editorMarginH); - buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_V=%d\n", _editorMarginV); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_FRAME { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColFrame), RGBCOLGetG(_editorColFrame), RGBCOLGetB(_editorColFrame), RGBCOLGetA(_editorColFrame)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntitySel), RGBCOLGetG(_editorColEntitySel), RGBCOLGetB(_editorColEntitySel), RGBCOLGetA(_editorColEntitySel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegionSel), RGBCOLGetG(_editorColRegionSel), RGBCOLGetB(_editorColRegionSel), RGBCOLGetA(_editorColRegionSel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlockedSel), RGBCOLGetG(_editorColBlockedSel), RGBCOLGetB(_editorColBlockedSel), RGBCOLGetA(_editorColBlockedSel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecorSel), RGBCOLGetG(_editorColDecorSel), RGBCOLGetB(_editorColDecorSel), RGBCOLGetA(_editorColDecorSel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypointsSel), RGBCOLGetG(_editorColWaypointsSel), RGBCOLGetB(_editorColWaypointsSel), RGBCOLGetA(_editorColWaypointsSel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntity), RGBCOLGetG(_editorColEntity), RGBCOLGetB(_editorColEntity), RGBCOLGetA(_editorColEntity)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegion), RGBCOLGetG(_editorColRegion), RGBCOLGetB(_editorColRegion), RGBCOLGetA(_editorColRegion)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecor), RGBCOLGetG(_editorColDecor), RGBCOLGetB(_editorColDecor), RGBCOLGetA(_editorColDecor)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlocked), RGBCOLGetG(_editorColBlocked), RGBCOLGetB(_editorColBlocked), RGBCOLGetA(_editorColBlocked)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypoints), RGBCOLGetG(_editorColWaypoints), RGBCOLGetB(_editorColWaypoints), RGBCOLGetA(_editorColWaypoints)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_SCALE { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColScale), RGBCOLGetG(_editorColScale), RGBCOLGetB(_editorColScale), RGBCOLGetA(_editorColScale)); - - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_REGIONS=%s\n", _editorShowRegions ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_BLOCKED=%s\n", _editorShowBlocked ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_DECORATION=%s\n", _editorShowDecor ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_ENTITIES=%s\n", _editorShowEntities ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_SCALE=%s\n", _editorShowScale ? "TRUE" : "FALSE"); - - buffer->putTextIndent(indent + 2, "\n"); - - CBBase::saveAsText(buffer, indent + 2); - - // waypoints - buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); - for (i = 0; i < _waypointGroups.getSize(); i++) _waypointGroups[i]->saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent + 2, "\n"); - - // layers - buffer->putTextIndent(indent + 2, "; ----- layers\n"); - for (i = 0; i < _layers.getSize(); i++) _layers[i]->saveAsText(buffer, indent + 2); - - // scale levels - buffer->putTextIndent(indent + 2, "; ----- scale levels\n"); - for (i = 0; i < _scaleLevels.getSize(); i++) _scaleLevels[i]->saveAsText(buffer, indent + 2); - - // rotation levels - buffer->putTextIndent(indent + 2, "; ----- rotation levels\n"); - for (i = 0; i < _rotLevels.getSize(); i++) _rotLevels[i]->saveAsText(buffer, indent + 2); - - - buffer->putTextIndent(indent + 2, "\n"); - - // free entities - buffer->putTextIndent(indent + 2, "; ----- free entities\n"); - for (i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_type == OBJECT_ENTITY) { - _objects[i]->saveAsText(buffer, indent + 2); - - } - } - - - - buffer->putTextIndent(indent, "}\n"); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::sortScaleLevels() { - bool changed; - do { - changed = false; - for (int i = 0; i < _scaleLevels.getSize() - 1; i++) { - if (_scaleLevels[i]->_posY > _scaleLevels[i + 1]->_posY) { - CAdScaleLevel *sl = _scaleLevels[i]; - _scaleLevels[i] = _scaleLevels[i + 1]; - _scaleLevels[i + 1] = sl; - - changed = true; - } - } - - } while (changed); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::sortRotLevels() { - bool changed; - do { - changed = false; - for (int i = 0; i < _rotLevels.getSize() - 1; i++) { - if (_rotLevels[i]->_posX > _rotLevels[i + 1]->_posX) { - CAdRotLevel *rl = _rotLevels[i]; - _rotLevels[i] = _rotLevels[i + 1]; - _rotLevels[i + 1] = rl; - - changed = true; - } - } - - } while (changed); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -float CAdScene::getScaleAt(int Y) { - CAdScaleLevel *prev = NULL; - CAdScaleLevel *next = NULL; - - for (int i = 0; i < _scaleLevels.getSize(); i++) { - /* CAdScaleLevel *xxx = _scaleLevels[i];*/ - /* int j = _scaleLevels.getSize(); */ - if (_scaleLevels[i]->_posY < Y) prev = _scaleLevels[i]; - else { - next = _scaleLevels[i]; - break; - } - } - - if (prev == NULL || next == NULL) return 100; - - int delta_y = next->_posY - prev->_posY; - float delta_scale = next->_scale - prev->_scale; - Y -= prev->_posY; - - float percent = (float)Y / ((float)delta_y / 100.0f); - return prev->_scale + delta_scale / 100 * percent; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::persist(CBPersistMgr *persistMgr) { - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_autoScroll)); - persistMgr->transfer(TMEMBER(_editorColBlocked)); - persistMgr->transfer(TMEMBER(_editorColBlockedSel)); - persistMgr->transfer(TMEMBER(_editorColDecor)); - persistMgr->transfer(TMEMBER(_editorColDecorSel)); - persistMgr->transfer(TMEMBER(_editorColEntity)); - persistMgr->transfer(TMEMBER(_editorColEntitySel)); - persistMgr->transfer(TMEMBER(_editorColFrame)); - persistMgr->transfer(TMEMBER(_editorColRegion)); - persistMgr->transfer(TMEMBER(_editorColRegionSel)); - persistMgr->transfer(TMEMBER(_editorColScale)); - persistMgr->transfer(TMEMBER(_editorColWaypoints)); - persistMgr->transfer(TMEMBER(_editorColWaypointsSel)); - persistMgr->transfer(TMEMBER(_editorMarginH)); - persistMgr->transfer(TMEMBER(_editorMarginV)); - persistMgr->transfer(TMEMBER(_editorShowBlocked)); - persistMgr->transfer(TMEMBER(_editorShowDecor)); - persistMgr->transfer(TMEMBER(_editorShowEntities)); - persistMgr->transfer(TMEMBER(_editorShowRegions)); - persistMgr->transfer(TMEMBER(_editorShowScale)); - persistMgr->transfer(TMEMBER(_fader)); - persistMgr->transfer(TMEMBER(_height)); - persistMgr->transfer(TMEMBER(_initialized)); - persistMgr->transfer(TMEMBER(_lastTimeH)); - persistMgr->transfer(TMEMBER(_lastTimeV)); - _layers.persist(persistMgr); - persistMgr->transfer(TMEMBER(_mainLayer)); - _objects.persist(persistMgr); - persistMgr->transfer(TMEMBER(_offsetLeft)); - persistMgr->transfer(TMEMBER(_offsetTop)); - persistMgr->transfer(TMEMBER(_paralaxScrolling)); - persistMgr->transfer(TMEMBER(_persistentState)); - persistMgr->transfer(TMEMBER(_persistentStateSprites)); - persistMgr->transfer(TMEMBER(_pfMaxTime)); - _pfPath.persist(persistMgr); - persistMgr->transfer(TMEMBER(_pfPointsNum)); - persistMgr->transfer(TMEMBER(_pfReady)); - persistMgr->transfer(TMEMBER(_pfRequester)); - persistMgr->transfer(TMEMBER(_pfTarget)); - persistMgr->transfer(TMEMBER(_pfTargetPath)); - _rotLevels.persist(persistMgr); - _scaleLevels.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scrollPixelsH)); - persistMgr->transfer(TMEMBER(_scrollPixelsV)); - persistMgr->transfer(TMEMBER(_scrollTimeH)); - persistMgr->transfer(TMEMBER(_scrollTimeV)); - persistMgr->transfer(TMEMBER(_shieldWindow)); - persistMgr->transfer(TMEMBER(_targetOffsetLeft)); - persistMgr->transfer(TMEMBER(_targetOffsetTop)); - _waypointGroups.persist(persistMgr); - persistMgr->transfer(TMEMBER(_viewport)); - persistMgr->transfer(TMEMBER(_width)); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::afterLoad() { - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, CBObject *requester) { - double xStep, yStep, x, y; - int xLength, yLength, xCount, yCount; - int x1, y1, x2, y2; - - x1 = *targetX; - y1 = *targetY; - x2 = startX; - y2 = startY; - - - xLength = abs(x2 - x1); - yLength = abs(y2 - y1); - - if (xLength > yLength) { - /* - if (X1 > X2) - { - Swap(&X1, &X2); - Swap(&Y1, &Y2); - } - */ - - yStep = fabs((double)(y2 - y1) / (double)(x2 - x1)); - y = y1; - - for (xCount = x1; xCount < x2; xCount++) { - if (isWalkableAt(xCount, (int)y, checkFreeObjects, requester)) { - *targetX = xCount; - *targetY = (int)y; - return STATUS_OK; - } - y += yStep; - } - } else { - /* - if (Y1 > Y2) { - Swap(&X1, &X2); - Swap(&Y1, &Y2); - } - */ - - xStep = fabs((double)(x2 - x1) / (double)(y2 - y1)); - x = x1; - - for (yCount = y1; yCount < y2; yCount++) { - if (isWalkableAt((int)x, yCount, checkFreeObjects, requester)) { - *targetX = (int)x; - *targetY = yCount; - return STATUS_OK; - } - x += xStep; - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, bool checkFreeObjects, CBObject *requester) { - int x = *argX; - int y = *argY; - - if (isWalkableAt(x, y, checkFreeObjects, requester) || !_mainLayer) { - return STATUS_OK; - } - - // right - int length_right = 0; - bool found_right = false; - for (x = *argX, y = *argY; x < _mainLayer->_width; x++, length_right++) { - if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x - 5, y, checkFreeObjects, requester)) { - found_right = true; - break; - } - } - - // left - int length_left = 0; - bool found_left = false; - for (x = *argX, y = *argY; x >= 0; x--, length_left--) { - if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x + 5, y, checkFreeObjects, requester)) { - found_left = true; - break; - } - } - - // up - int length_up = 0; - bool found_up = false; - for (x = *argX, y = *argY; y >= 0; y--, length_up--) { - if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y + 5, checkFreeObjects, requester)) { - found_up = true; - break; - } - } - - // down - int length_down = 0; - bool found_down = false; - for (x = *argX, y = *argY; y < _mainLayer->_height; y++, length_down++) { - if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y - 5, checkFreeObjects, requester)) { - found_down = true; - break; - } - } - - if (!found_left && !found_right && !found_up && !found_down) { - return STATUS_OK; - } - - int OffsetX = INT_MAX, OffsetY = INT_MAX; - - if (found_left && found_right) { - if (abs(length_left) < abs(length_right)) OffsetX = length_left; - else OffsetX = length_right; - } else if (found_left) OffsetX = length_left; - else if (found_right) OffsetX = length_right; - - if (found_up && found_down) { - if (abs(length_up) < abs(length_down)) OffsetY = length_up; - else OffsetY = length_down; - } else if (found_up) OffsetY = length_up; - else if (found_down) OffsetY = length_down; - - if (abs(OffsetX) < abs(OffsetY)) - *argX = *argX + OffsetX; - else - *argY = *argY + OffsetY; - - if (!isWalkableAt(*argX, *argY)) return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); - else return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::pfPointsStart() { - _pfPointsNum = 0; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::pfPointsAdd(int x, int y, int distance) { - if (_pfPointsNum >= _pfPath.getSize()) { - _pfPath.add(new CAdPathPoint(x, y, distance)); - } else { - _pfPath[_pfPointsNum]->x = x; - _pfPath[_pfPointsNum]->y = y; - _pfPath[_pfPointsNum]->_distance = distance; - _pfPath[_pfPointsNum]->_marked = false; - _pfPath[_pfPointsNum]->_origin = NULL; - } - - _pfPointsNum++; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::getViewportOffset(int *offsetX, int *offsetY) { - CAdGame *adGame = (CAdGame *)_gameRef; - if (_viewport && !_gameRef->_editorMode) { - if (offsetX) *offsetX = _viewport->_offsetX; - if (offsetY) *offsetY = _viewport->_offsetY; - } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - if (offsetX) *offsetX = adGame->_sceneViewport->_offsetX; - if (offsetY) *offsetY = adGame->_sceneViewport->_offsetY; - } else { - if (offsetX) *offsetX = 0; - if (offsetY) *offsetY = 0; - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::getViewportSize(int *width, int *height) { - CAdGame *adGame = (CAdGame *)_gameRef; - if (_viewport && !_gameRef->_editorMode) { - if (width) *width = _viewport->getWidth(); - if (height) *height = _viewport->getHeight(); - } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - if (width) *width = adGame->_sceneViewport->getWidth(); - if (height) *height = adGame->_sceneViewport->getHeight(); - } else { - if (width) *width = _gameRef->_renderer->_width; - if (height) *height = _gameRef->_renderer->_height; - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -int CAdScene::getOffsetLeft() { - int viewportX; - getViewportOffset(&viewportX); - - return _offsetLeft - viewportX; -} - - -////////////////////////////////////////////////////////////////////////// -int CAdScene::getOffsetTop() { - int viewportY; - getViewportOffset(NULL, &viewportY); - - return _offsetTop - viewportY; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::pointInViewport(int x, int y) { - int left, top, width, height; - - getViewportOffset(&left, &top); - getViewportSize(&width, &height); - - return x >= left && x <= left + width && y >= top && y <= top + height; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdScene::setOffset(int offsetLeft, int offsetTop) { - _offsetLeft = offsetLeft; - _offsetTop = offsetTop; -} - - -////////////////////////////////////////////////////////////////////////// -CBObject *CAdScene::getNodeByName(const char *name) { - CBObject *ret = NULL; - - // dependent objects - for (int i = 0; i < _layers.getSize(); i++) { - CAdLayer *layer = _layers[i]; - for (int j = 0; j < layer->_nodes.getSize(); j++) { - CAdSceneNode *node = layer->_nodes[j]; - if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->_name)) || - (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->_name))) { - switch (node->_type) { - case OBJECT_ENTITY: - ret = node->_entity; - break; - case OBJECT_REGION: - ret = node->_region; - break; - default: - ret = NULL; - } - return ret; - } - } - } - - // free entities - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->_name)) { - return _objects[i]; - } - } - - // waypoint groups - for (int i = 0; i < _waypointGroups.getSize(); i++) { - if (!scumm_stricmp(name, _waypointGroups[i]->_name)) { - return _waypointGroups[i]; - } - } - - return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::saveState() { - return persistState(true); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::loadState() { - return persistState(false); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::persistState(bool saving) { - if (!_persistentState) return STATUS_OK; - - CAdGame *adGame = (CAdGame *)_gameRef; - CAdSceneState *state = adGame->getSceneState(_filename, saving); - if (!state) return STATUS_OK; - - CAdNodeState *nodeState; - - // dependent objects - for (int i = 0; i < _layers.getSize(); i++) { - CAdLayer *layer = _layers[i]; - for (int j = 0; j < layer->_nodes.getSize(); j++) { - CAdSceneNode *node = layer->_nodes[j]; - switch (node->_type) { - case OBJECT_ENTITY: - if (!node->_entity->_saveState) continue; - nodeState = state->getNodeState(node->_entity->_name, saving); - if (nodeState) { - nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); - //if(Saving) NodeState->_active = node->_entity->_active; - //else node->_entity->_active = NodeState->_active; - } - break; - case OBJECT_REGION: - if (!node->_region->_saveState) continue; - nodeState = state->getNodeState(node->_region->_name, saving); - if (nodeState) { - if (saving) nodeState->_active = node->_region->_active; - else node->_region->_active = nodeState->_active; - } - break; - default: - warning("CAdScene::PersistState - unhandled enum"); - break; - } - } - } - - // free entities - for (int i = 0; i < _objects.getSize(); i++) { - if (!_objects[i]->_saveState) continue; - if (_objects[i]->_type == OBJECT_ENTITY) { - nodeState = state->getNodeState(_objects[i]->_name, saving); - if (nodeState) { - nodeState->transferEntity((CAdEntity *)_objects[i], _persistentStateSprites, saving); - //if(Saving) NodeState->_active = _objects[i]->_active; - //else _objects[i]->_active = NodeState->_active; - } - } - } - - // waypoint groups - for (int i = 0; i < _waypointGroups.getSize(); i++) { - nodeState = state->getNodeState(_waypointGroups[i]->_name, saving); - if (nodeState) { - if (saving) nodeState->_active = _waypointGroups[i]->_active; - else _waypointGroups[i]->_active = nodeState->_active; - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -float CAdScene::getRotationAt(int x, int y) { - CAdRotLevel *prev = NULL; - CAdRotLevel *next = NULL; - - for (int i = 0; i < _rotLevels.getSize(); i++) { - /* CAdRotLevel *xxx = _rotLevels[i]; - int j = _rotLevels.getSize();*/ - if (_rotLevels[i]->_posX < x) prev = _rotLevels[i]; - else { - next = _rotLevels[i]; - break; - } - } - - if (prev == NULL || next == NULL) return 0; - - int delta_x = next->_posX - prev->_posX; - float delta_rot = next->_rotation - prev->_rotation; - x -= prev->_posX; - - float percent = (float)x / ((float)delta_x / 100.0f); - return prev->_rotation + delta_rot / 100 * percent; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::handleItemAssociations(const char *itemName, bool show) { - for (int i = 0; i < _layers.getSize(); i++) { - CAdLayer *layer = _layers[i]; - for (int j = 0; j < layer->_nodes.getSize(); j++) { - if (layer->_nodes[j]->_type == OBJECT_ENTITY) { - CAdEntity *ent = layer->_nodes[j]->_entity; - - if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; - } - } - } - - for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_type == OBJECT_ENTITY) { - CAdEntity *ent = (CAdEntity *)_objects[i]; - if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::getRegionsAt(int x, int y, CAdRegion **regionList, int numRegions) { - int numUsed = 0; - if (_mainLayer) { - for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { - CAdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { - if (numUsed < numRegions - 1) { - regionList[numUsed] = node->_region; - numUsed++; - } else break; - } - } - } - for (int i = numUsed; i < numRegions; i++) { - regionList[i] = NULL; - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::restoreDeviceObjects() { - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -CBObject *CAdScene::getNextAccessObject(CBObject *currObject) { - CBArray objects; - getSceneObjects(objects, true); - - if (objects.getSize() == 0) return NULL; - else { - if (currObject != NULL) { - for (int i = 0; i < objects.getSize(); i++) { - if (objects[i] == currObject) { - if (i < objects.getSize() - 1) return objects[i + 1]; - else break; - } - } - } - return objects[0]; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -CBObject *CAdScene::getPrevAccessObject(CBObject *currObject) { - CBArray objects; - getSceneObjects(objects, true); - - if (objects.getSize() == 0) return NULL; - else { - if (currObject != NULL) { - for (int i = objects.getSize() - 1; i >= 0; i--) { - if (objects[i] == currObject) { - if (i > 0) return objects[i - 1]; - else break; - } - } - } - return objects[objects.getSize() - 1]; - } - return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::getSceneObjects(CBArray &objects, bool interactiveOnly) { - for (int i = 0; i < _layers.getSize(); i++) { - // close-up layer -> remove everything below it - if (interactiveOnly && _layers[i]->_closeUp) objects.removeAll(); - - - for (int j = 0; j < _layers[i]->_nodes.getSize(); j++) { - CAdSceneNode *node = _layers[i]->_nodes[j]; - switch (node->_type) { - case OBJECT_ENTITY: { - CAdEntity *ent = node->_entity; - if (ent->_active && (ent->_registrable || !interactiveOnly)) - objects.add(ent); - } - break; - - case OBJECT_REGION: { - CBArray regionObj; - getRegionObjects(node->_region, regionObj, interactiveOnly); - for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { - bool found = false; - for (int old = 0; old < objects.getSize(); old++) { - if (objects[old] == regionObj[newIndex]) { - found = true; - break; - } - } - if (!found) objects.add(regionObj[newIndex]); - } - //if(RegionObj.getSize() > 0) Objects.Append(RegionObj); - } - break; - default: - warning("CAdScene::GetSceneObjects - Unhandled enum"); - break; - } - } - } - - // objects outside any region - CBArray regionObj; - getRegionObjects(NULL, regionObj, interactiveOnly); - for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { - bool found = false; - for (int old = 0; old < objects.getSize(); old++) { - if (objects[old] == regionObj[newIndex]) { - found = true; - break; - } - } - if (!found) objects.add(regionObj[newIndex]); - } - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdScene::getRegionObjects(CAdRegion *region, CBArray &objects, bool interactiveOnly) { - CAdGame *adGame = (CAdGame *)_gameRef; - CAdObject *obj; - - // global objects - for (int i = 0; i < adGame->_objects.getSize(); i++) { - obj = adGame->_objects[i]; - if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - if (interactiveOnly && !obj->_registrable) continue; - - objects.add(obj); - } - } - - // scene objects - for (int i = 0; i < _objects.getSize(); i++) { - obj = _objects[i]; - if (obj->_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - if (interactiveOnly && !obj->_registrable) continue; - - objects.add(obj); - } - } - - // sort by _posY - qsort(objects.getData(), objects.getSize(), sizeof(CAdObject *), CAdScene::compareObjs); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdScene.h b/engines/wintermute/ad/AdScene.h deleted file mode 100644 index f77c64aa9b..0000000000 --- a/engines/wintermute/ad/AdScene.h +++ /dev/null @@ -1,181 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSCENE_H -#define WINTERMUTE_ADSCENE_H - -#include "engines/wintermute/base/BFader.h" - -namespace WinterMute { - -class CUIWindow; -class CAdObject; -class CAdRegion; -class CBViewport; -class CAdLayer; -class CBPoint; -class CAdWaypointGroup; -class CAdPath; -class CAdScaleLevel; -class CAdRotLevel; -class CAdPathPoint; -class CAdScene : public CBObject { -public: - - CBObject *getNextAccessObject(CBObject *CurrObject); - CBObject *getPrevAccessObject(CBObject *CurrObject); - bool getSceneObjects(CBArray &Objects, bool InteractiveOnly); - bool getRegionObjects(CAdRegion *Region, CBArray &Objects, bool InteractiveOnly); - - bool afterLoad(); - - bool getRegionsAt(int X, int Y, CAdRegion **RegionList, int NumRegions); - bool handleItemAssociations(const char *ItemName, bool Show); - CUIWindow *_shieldWindow; - float getRotationAt(int X, int Y); - bool loadState(); - bool saveState(); - bool _persistentState; - bool _persistentStateSprites; - CBObject *getNodeByName(const char *name); - void setOffset(int OffsetLeft, int OffsetTop); - bool pointInViewport(int X, int Y); - int getOffsetTop(); - int getOffsetLeft(); - bool getViewportSize(int *Width = NULL, int *Height = NULL); - bool getViewportOffset(int *OffsetX = NULL, int *OffsetY = NULL); - CBViewport *_viewport; - CBFader *_fader; - int _pfPointsNum; - void pfPointsAdd(int X, int Y, int Distance); - void pfPointsStart(); - bool _initialized; - bool correctTargetPoint(int StartX, int StartY, int *X, int *Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); - bool correctTargetPoint2(int StartX, int StartY, int *TargetX, int *TargetY, bool CheckFreeObjects, CBObject *Requester); - DECLARE_PERSISTENT(CAdScene, CBObject) - bool displayRegionContent(CAdRegion *Region = NULL, bool Display3DOnly = false); - bool displayRegionContentOld(CAdRegion *Region = NULL); - static int compareObjs(const void *Obj1, const void *Obj2); - - bool updateFreeObjects(); - bool traverseNodes(bool Update = false); - float getScaleAt(int Y); - bool sortScaleLevels(); - bool sortRotLevels(); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - uint32 getAlphaAt(int X, int Y, bool ColorCheck = false); - bool _paralaxScrolling; - void skipTo(int OffsetX, int OffsetY); - void setDefaults(); - void cleanup(); - void skipToObject(CBObject *Object); - void scrollToObject(CBObject *Object); - void scrollTo(int OffsetX, int OffsetY); - virtual bool update(); - bool _autoScroll; - int _targetOffsetTop; - int _targetOffsetLeft; - - int _scrollPixelsV; - uint32 _scrollTimeV; - uint32 _lastTimeV; - - int _scrollPixelsH; - uint32 _scrollTimeH; - uint32 _lastTimeH; - - virtual bool display(); - uint32 _pfMaxTime; - bool initLoop(); - void pathFinderStep(); - bool isBlockedAt(int X, int Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); - bool isWalkableAt(int X, int Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); - CAdLayer *_mainLayer; - float getZoomAt(int X, int Y); - bool getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject *requester = NULL); - CAdScene(CBGame *inGame); - virtual ~CAdScene(); - CBArray _layers; - CBArray _objects; - CBArray _waypointGroups; - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - int _width; - int _height; - bool addObject(CAdObject *Object); - bool removeObject(CAdObject *Object); - int _editorMarginH; - int _editorMarginV; - uint32 _editorColFrame; - uint32 _editorColEntity; - uint32 _editorColRegion; - uint32 _editorColBlocked; - uint32 _editorColWaypoints; - uint32 _editorColEntitySel; - uint32 _editorColRegionSel; - uint32 _editorColBlockedSel; - uint32 _editorColWaypointsSel; - uint32 _editorColScale; - uint32 _editorColDecor; - uint32 _editorColDecorSel; - - bool _editorShowRegions; - bool _editorShowBlocked; - bool _editorShowDecor; - bool _editorShowEntities; - bool _editorShowScale; - CBArray _scaleLevels; - CBArray _rotLevels; - - virtual bool restoreDeviceObjects(); - int getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester = NULL); - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - virtual const char *scToString(); - - -private: - bool persistState(bool Saving = true); - void pfAddWaypointGroup(CAdWaypointGroup *Wpt, CBObject *Requester = NULL); - bool _pfReady; - CBPoint *_pfTarget; - CAdPath *_pfTargetPath; - CBObject *_pfRequester; - CBArray _pfPath; - - int _offsetTop; - int _offsetLeft; - -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdSceneNode.cpp b/engines/wintermute/ad/AdSceneNode.cpp deleted file mode 100644 index 5f518e5442..0000000000 --- a/engines/wintermute/ad/AdSceneNode.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdSceneNode.h" -#include "engines/wintermute/base/BGame.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdSceneNode, false) - -////////////////////////////////////////////////////////////////////////// -CAdSceneNode::CAdSceneNode(CBGame *inGame): CBObject(inGame) { - _type = OBJECT_NONE; - _region = NULL; - _entity = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdSceneNode::~CAdSceneNode() { - _gameRef->unregisterObject(_region); - _region = NULL; - - _gameRef->unregisterObject(_entity); - _entity = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSceneNode::setEntity(CAdEntity *entity) { - _type = OBJECT_ENTITY; - _entity = entity; - return _gameRef->registerObject(entity); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSceneNode::setRegion(CAdRegion *region) { - _type = OBJECT_REGION; - _region = region; - return _gameRef->registerObject(region); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSceneNode::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_entity)); - persistMgr->transfer(TMEMBER(_region)); - persistMgr->transfer(TMEMBER_INT(_type)); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdSceneNode.h b/engines/wintermute/ad/AdSceneNode.h deleted file mode 100644 index d081959934..0000000000 --- a/engines/wintermute/ad/AdSceneNode.h +++ /dev/null @@ -1,54 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSCENENODE_H -#define WINTERMUTE_ADSCENENODE_H - - -#include "engines/wintermute/ad/AdTypes.h" // Added by ClassView -#include "engines/wintermute/ad/AdRegion.h" // Added by ClassView -#include "engines/wintermute/ad/AdEntity.h" - -namespace WinterMute { - -class CAdSceneNode : public CBObject { -public: - DECLARE_PERSISTENT(CAdSceneNode, CBObject) - bool setRegion(CAdRegion *region); - bool setEntity(CAdEntity *entity); - CAdEntity *_entity; - CAdRegion *_region; - TObjectType _type; - CAdSceneNode(CBGame *inGame); - virtual ~CAdSceneNode(); - -}; - -} - -#endif diff --git a/engines/wintermute/ad/AdSceneState.cpp b/engines/wintermute/ad/AdSceneState.cpp deleted file mode 100644 index 5dfb8c537e..0000000000 --- a/engines/wintermute/ad/AdSceneState.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/ad/AdSceneState.h" -#include "engines/wintermute/ad/AdNodeState.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdSceneState, false) - -////////////////////////////////////////////////////////////////////////// -CAdSceneState::CAdSceneState(CBGame *inGame): CBBase(inGame) { - _filename = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdSceneState::~CAdSceneState() { - delete[] _filename; - _filename = NULL; - - for (int i = 0; i < _nodeStates.getSize(); i++) delete _nodeStates[i]; - _nodeStates.removeAll(); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSceneState::persist(CBPersistMgr *persistMgr) { - persistMgr->transfer(TMEMBER(_filename)); - _nodeStates.persist(persistMgr); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdSceneState::setFilename(const char *filename) { - delete[] _filename; - _filename = new char [strlen(filename) + 1]; - if (_filename) strcpy(_filename, filename); -} - - -////////////////////////////////////////////////////////////////////////// -CAdNodeState *CAdSceneState::getNodeState(char *name, bool saving) { - for (int i = 0; i < _nodeStates.getSize(); i++) { - if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) return _nodeStates[i]; - } - - if (saving) { - CAdNodeState *ret = new CAdNodeState(_gameRef); - ret->setName(name); - _nodeStates.add(ret); - - return ret; - } else return NULL; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdSceneState.h b/engines/wintermute/ad/AdSceneState.h deleted file mode 100644 index 82207f383c..0000000000 --- a/engines/wintermute/ad/AdSceneState.h +++ /dev/null @@ -1,51 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSCENESTATE_H -#define WINTERMUTE_ADSCENESTATE_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/BBase.h" -#include "engines/wintermute/coll_templ.h" - -namespace WinterMute { -class CAdNodeState; -class CAdSceneState : public CBBase { -public: - CAdNodeState *getNodeState(char *name, bool saving); - void setFilename(const char *filename); - DECLARE_PERSISTENT(CAdSceneState, CBBase) - CAdSceneState(CBGame *inGame); - virtual ~CAdSceneState(); - char *_filename; - CBArray _nodeStates; -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdSentence.cpp b/engines/wintermute/ad/AdSentence.cpp deleted file mode 100644 index 98926caac6..0000000000 --- a/engines/wintermute/ad/AdSentence.cpp +++ /dev/null @@ -1,317 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdSentence.h" -#include "engines/wintermute/ad/AdTalkDef.h" -#include "engines/wintermute/ad/AdTalkNode.h" -#include "engines/wintermute/ad/AdGame.h" -#include "engines/wintermute/utils/PathUtil.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BSound.h" -#include "engines/wintermute/ad/AdScene.h" -#include "engines/wintermute/base/font/BFont.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/base/BFileManager.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdSentence, false) - -////////////////////////////////////////////////////////////////////////// -CAdSentence::CAdSentence(CBGame *inGame): CBBase(inGame) { - _text = NULL; - _stances = NULL; - _tempStance = NULL; - - _duration = 0; - _startTime = 0; - _currentStance = 0; - - _font = NULL; - - _pos.x = _pos.y = 0; - _width = _gameRef->_renderer->_width; - - _align = (TTextAlign)TAL_CENTER; - - _sound = NULL; - _soundStarted = false; - - _talkDef = NULL; - _currentSprite = NULL; - _currentSkelAnim = NULL; - _fixedPos = false; - _freezable = true; -} - - -////////////////////////////////////////////////////////////////////////// -CAdSentence::~CAdSentence() { - delete _sound; - delete[] _text; - delete[] _stances; - delete[] _tempStance; - delete _talkDef; - _sound = NULL; - _text = NULL; - _stances = NULL; - _tempStance = NULL; - _talkDef = NULL; - - _currentSprite = NULL; // ref only - _currentSkelAnim = NULL; - _font = NULL; // ref only -} - - -////////////////////////////////////////////////////////////////////////// -void CAdSentence::setText(const char *text) { - if (_text) delete [] _text; - _text = new char[strlen(text) + 1]; - if (_text) strcpy(_text, text); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdSentence::setStances(const char *stances) { - if (_stances) delete [] _stances; - if (stances) { - _stances = new char[strlen(stances) + 1]; - if (_stances) strcpy(_stances, stances); - } else _stances = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -char *CAdSentence::getCurrentStance() { - return getStance(_currentStance); -} - - -////////////////////////////////////////////////////////////////////////// -char *CAdSentence::getNextStance() { - _currentStance++; - return getStance(_currentStance); -} - - -////////////////////////////////////////////////////////////////////////// -char *CAdSentence::getStance(int stance) { - if (_stances == NULL) return NULL; - - if (_tempStance) delete [] _tempStance; - _tempStance = NULL; - - char *start; - char *curr; - int pos; - - if (stance == 0) start = _stances; - else { - pos = 0; - start = NULL; - curr = _stances; - while (pos < stance) { - if (*curr == '\0') break; - if (*curr == ',') pos++; - curr++; - } - if (pos == stance) start = curr; - } - - if (start == NULL) return NULL; - - while (*start == ' ' && *start != ',' && *start != '\0') start++; - - curr = start; - while (*curr != '\0' && *curr != ',') curr++; - - while (curr > start && *(curr - 1) == ' ') curr--; - - _tempStance = new char [curr - start + 1]; - if (_tempStance) { - _tempStance[curr - start] = '\0'; - strncpy(_tempStance, start, curr - start); - } - - return _tempStance; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSentence::display() { - if (!_font || !_text) return STATUS_FAILED; - - if (_sound && !_soundStarted) { - _sound->play(); - _soundStarted = true; - } - - if (_gameRef->_subtitles) { - int x = _pos.x; - int y = _pos.y; - - if (!_fixedPos) { - x = x - ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); - y = y - ((CAdGame *)_gameRef)->_scene->getOffsetTop(); - } - - - x = MAX(x, 0); - x = MIN(x, _gameRef->_renderer->_width - _width); - y = MAX(y, 0); - - _font->drawText((byte *)_text, x, y, _width, _align); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void CAdSentence::setSound(CBSound *sound) { - if (!sound) return; - delete _sound; - _sound = sound; - _soundStarted = false; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSentence::finish() { - if (_sound) _sound->stop(); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSentence::persist(CBPersistMgr *persistMgr) { - - persistMgr->transfer(TMEMBER(_gameRef)); - - persistMgr->transfer(TMEMBER_INT(_align)); - persistMgr->transfer(TMEMBER(_currentStance)); - persistMgr->transfer(TMEMBER(_currentSprite)); - persistMgr->transfer(TMEMBER(_currentSkelAnim)); - persistMgr->transfer(TMEMBER(_duration)); - persistMgr->transfer(TMEMBER(_font)); - persistMgr->transfer(TMEMBER(_pos)); - persistMgr->transfer(TMEMBER(_sound)); - persistMgr->transfer(TMEMBER(_soundStarted)); - persistMgr->transfer(TMEMBER(_stances)); - persistMgr->transfer(TMEMBER(_startTime)); - persistMgr->transfer(TMEMBER(_talkDef)); - persistMgr->transfer(TMEMBER(_tempStance)); - persistMgr->transfer(TMEMBER(_text)); - persistMgr->transfer(TMEMBER(_width)); - persistMgr->transfer(TMEMBER(_fixedPos)); - persistMgr->transfer(TMEMBER(_freezable)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSentence::setupTalkFile(const char *soundFilename) { - delete _talkDef; - _talkDef = NULL; - _currentSprite = NULL; - - if (!soundFilename) return STATUS_OK; - - - AnsiString path = PathUtil::getDirectoryName(soundFilename); - AnsiString name = PathUtil::getFileNameWithoutExtension(soundFilename); - - AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); - - Common::SeekableReadStream *file = _gameRef->_fileManager->openFile(talkDefFileName.c_str()); - if (file) { - _gameRef->_fileManager->closeFile(file); - } else return STATUS_OK; // no talk def file found - - - _talkDef = new CAdTalkDef(_gameRef); - if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { - delete _talkDef; - _talkDef = NULL; - return STATUS_FAILED; - } - //_gameRef->LOG(0, "Using .talk file: %s", TalkDefFile); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSentence::update(TDirection dir) { - if (!_talkDef) return STATUS_OK; - - uint32 currentTime; - // if sound is available, synchronize with sound, otherwise use timer - - /* - if (_sound) CurrentTime = _sound->GetPositionTime(); - else CurrentTime = _gameRef->_timer - _startTime; - */ - currentTime = _gameRef->_timer - _startTime; - - bool talkNodeFound = false; - for (int i = 0; i < _talkDef->_nodes.getSize(); i++) { - if (_talkDef->_nodes[i]->isInTimeInterval(currentTime, dir)) { - talkNodeFound = true; - - CBSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); - if (newSprite != _currentSprite) newSprite->reset(); - _currentSprite = newSprite; - - if (!_talkDef->_nodes[i]->_playToEnd) break; - } - } - - - // no talk node, try to use default sprite instead (if any) - if (!talkNodeFound) { - CBSprite *newSprite = _talkDef->getDefaultSprite(dir); - if (newSprite) { - if (newSprite != _currentSprite) newSprite->reset(); - _currentSprite = newSprite; - } else _currentSprite = NULL; - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdSentence::CanSkip() { - // prevent accidental sentence skipping (TODO make configurable) - return (_gameRef->_timer - _startTime) > 300; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdSentence.h b/engines/wintermute/ad/AdSentence.h deleted file mode 100644 index 954568878e..0000000000 --- a/engines/wintermute/ad/AdSentence.h +++ /dev/null @@ -1,85 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSENTENCE_H -#define WINTERMUTE_ADSENTENCE_H - - -#include "engines/wintermute/base/BBase.h" -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/math/Rect32.h" -#include "engines/wintermute/dctypes.h" // Added by ClassView -#include "common/rect.h" - -namespace WinterMute { -class CAdTalkDef; -class CBFont; -class CBSprite; -class CBSound; -class CAdSentence : public CBBase { -public: - bool _freezable; - bool _fixedPos; - CBSprite *_currentSprite; - char *_currentSkelAnim; - bool update(TDirection dir = DI_DOWN); - bool setupTalkFile(const char *soundFilename); - DECLARE_PERSISTENT(CAdSentence, CBBase) - bool finish(); - void setSound(CBSound *Sound); - bool _soundStarted; - CBSound *_sound; - TTextAlign _align; - bool display(); - int _width; - Point32 _pos; - CBFont *_font; - char *getNextStance(); - char *getCurrentStance(); - void setStances(const char *stances); - void setText(const char *text); - int _currentStance; - uint32 _startTime; - char *_stances; - char *_text; - uint32 _duration; - CAdSentence(CBGame *inGame); - virtual ~CAdSentence(); - CAdTalkDef *_talkDef; - - bool CanSkip(); - -private: - char *_tempStance; - char *getStance(int stance); - -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdSpriteSet.cpp b/engines/wintermute/ad/AdSpriteSet.cpp deleted file mode 100644 index 127d42d02b..0000000000 --- a/engines/wintermute/ad/AdSpriteSet.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdSpriteSet.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BFileManager.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdSpriteSet, false) - -////////////////////////////////////////////////////////////////////////// -CAdSpriteSet::CAdSpriteSet(CBGame *inGame, CBObject *owner): CBObject(inGame) { - _owner = owner; - - for (int i = 0; i < NUM_DIRECTIONS; i++) - _sprites[i] = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdSpriteSet::~CAdSpriteSet() { - for (int i = 0; i < NUM_DIRECTIONS; i++) { - delete _sprites[i]; - _sprites[i] = NULL; - } - - _owner = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdSpriteSet::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(SPRITESET) -TOKEN_DEF(NAME) -TOKEN_DEF(UP_LEFT) -TOKEN_DEF(DOWN_LEFT) -TOKEN_DEF(LEFT) -TOKEN_DEF(UP_RIGHT) -TOKEN_DEF(DOWN_RIGHT) -TOKEN_DEF(RIGHT) -TOKEN_DEF(UP) -TOKEN_DEF(DOWN) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType CacheType) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(SPRITESET) - TOKEN_TABLE(NAME) - TOKEN_TABLE(UP_LEFT) - TOKEN_TABLE(DOWN_LEFT) - TOKEN_TABLE(LEFT) - TOKEN_TABLE(UP_RIGHT) - TOKEN_TABLE(DOWN_RIGHT) - TOKEN_TABLE(RIGHT) - TOKEN_TABLE(UP) - TOKEN_TABLE(DOWN) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SPRITESET) { - _gameRef->LOG(0, "'SPRITESET' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - CBSprite *spr = NULL; - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_LEFT: - delete _sprites[DI_LEFT]; - _sprites[DI_LEFT] = NULL; - spr = new CBSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_LEFT] = spr; - break; - - case TOKEN_RIGHT: - delete _sprites[DI_RIGHT]; - _sprites[DI_RIGHT] = NULL; - spr = new CBSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_RIGHT] = spr; - break; - - case TOKEN_UP: - delete _sprites[DI_UP]; - _sprites[DI_UP] = NULL; - spr = new CBSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UP] = spr; - break; - - case TOKEN_DOWN: - delete _sprites[DI_DOWN]; - _sprites[DI_DOWN] = NULL; - spr = new CBSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWN] = spr; - break; - - case TOKEN_UP_LEFT: - delete _sprites[DI_UPLEFT]; - _sprites[DI_UPLEFT] = NULL; - spr = new CBSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UPLEFT] = spr; - break; - - case TOKEN_UP_RIGHT: - delete _sprites[DI_UPRIGHT]; - _sprites[DI_UPRIGHT] = NULL; - spr = new CBSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UPRIGHT] = spr; - break; - - case TOKEN_DOWN_LEFT: - delete _sprites[DI_DOWNLEFT]; - _sprites[DI_DOWNLEFT] = NULL; - spr = new CBSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWNLEFT] = spr; - break; - - case TOKEN_DOWN_RIGHT: - delete _sprites[DI_DOWNRIGHT]; - _sprites[DI_DOWNRIGHT] = NULL; - spr = new CBSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWNRIGHT] = spr; - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in SPRITESET definition"); - return STATUS_FAILED; - } - - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading SPRITESET definition"); - if (spr) delete spr; - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_owner)); - for (int i = 0; i < NUM_DIRECTIONS; i++) { - persistMgr->transfer("", &_sprites[i]); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -CBSprite *CAdSpriteSet::getSprite(TDirection direction) { - int dir = (int)direction; - if (dir < 0) dir = 0; - if (dir >= NUM_DIRECTIONS) dir = NUM_DIRECTIONS - 1; - - CBSprite *ret = NULL; - - // find nearest set sprite - int numSteps = 0; - for (int i = dir; i >= 0; i--) { - if (_sprites[i] != NULL) { - ret = _sprites[i]; - numSteps = dir - i; - break; - } - } - - for (int i = dir; i < NUM_DIRECTIONS; i++) { - if (_sprites[i] != NULL) { - if (ret == NULL || numSteps > i - dir) return _sprites[i]; - else return ret; - } - } - - return ret; -} - - - -////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "SPRITESET {\n"); - if (_name) buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); - for (int i = 0; i < NUM_DIRECTIONS; i++) { - if (_sprites[i]) { - switch (i) { - case DI_UP: - buffer->putTextIndent(indent + 2, "UP=\"%s\"\n", _sprites[i]->_filename); - break; - case DI_UPRIGHT: - buffer->putTextIndent(indent + 2, "UP_RIGHT=\"%s\"\n", _sprites[i]->_filename); - break; - case DI_RIGHT: - buffer->putTextIndent(indent + 2, "RIGHT=\"%s\"\n", _sprites[i]->_filename); - break; - case DI_DOWNRIGHT: - buffer->putTextIndent(indent + 2, "DOWN_RIGHT=\"%s\"\n", _sprites[i]->_filename); - break; - case DI_DOWN: - buffer->putTextIndent(indent + 2, "DOWN=\"%s\"\n", _sprites[i]->_filename); - break; - case DI_DOWNLEFT: - buffer->putTextIndent(indent + 2, "DOWN_LEFT=\"%s\"\n", _sprites[i]->_filename); - break; - case DI_LEFT: - buffer->putTextIndent(indent + 2, "LEFT=\"%s\"\n", _sprites[i]->_filename); - break; - case DI_UPLEFT: - buffer->putTextIndent(indent + 2, "UP_LEFT=\"%s\"\n", _sprites[i]->_filename); - break; - } - } - } - - CBBase::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::containsSprite(CBSprite *sprite) { - if (!sprite) return false; - - for (int i = 0; i < NUM_DIRECTIONS; i++) { - if (_sprites[i] == sprite) return true; - } - return false; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdSpriteSet.h b/engines/wintermute/ad/AdSpriteSet.h deleted file mode 100644 index ba5c6fb75b..0000000000 --- a/engines/wintermute/ad/AdSpriteSet.h +++ /dev/null @@ -1,54 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSPRITESET_H -#define WINTERMUTE_ADSPRITESET_H - - -#include "engines/wintermute/base/BObject.h" -#include "engines/wintermute/base/BSprite.h" // Added by ClassView - -namespace WinterMute { - -class CAdSpriteSet : public CBObject { -public: - bool containsSprite(CBSprite *sprite); - virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); - CBSprite *getSprite(TDirection direction); - DECLARE_PERSISTENT(CAdSpriteSet, CBObject) - CBObject *_owner; - CAdSpriteSet(CBGame *inGame, CBObject *owner = NULL); - virtual ~CAdSpriteSet(); - bool loadFile(const char *filename, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); - bool loadBuffer(byte *buffer, bool complete = true, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); - CBSprite *_sprites[NUM_DIRECTIONS]; -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdTalkDef.cpp b/engines/wintermute/ad/AdTalkDef.cpp deleted file mode 100644 index b598226413..0000000000 --- a/engines/wintermute/ad/AdTalkDef.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdTalkDef.h" -#include "engines/wintermute/ad/AdTalkNode.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/ad/AdSpriteSet.h" -#include "engines/wintermute/base/BFileManager.h" -#include "engines/wintermute/utils/utils.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdTalkDef, false) - -////////////////////////////////////////////////////////////////////////// -CAdTalkDef::CAdTalkDef(CBGame *inGame): CBObject(inGame) { - _defaultSpriteFilename = NULL; - _defaultSprite = NULL; - - _defaultSpriteSetFilename = NULL; - _defaultSpriteSet = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdTalkDef::~CAdTalkDef() { - for (int i = 0; i < _nodes.getSize(); i++) delete _nodes[i]; - _nodes.removeAll(); - - delete[] _defaultSpriteFilename; - delete _defaultSprite; - _defaultSpriteFilename = NULL; - _defaultSprite = NULL; - - delete[] _defaultSpriteSetFilename; - delete _defaultSpriteSet; - _defaultSpriteSetFilename = NULL; - _defaultSpriteSet = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdTalkDef::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - CBUtils::setString(&_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(TALK) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(ACTION) -TOKEN_DEF(DEFAULT_SPRITESET_FILE) -TOKEN_DEF(DEFAULT_SPRITESET) -TOKEN_DEF(DEFAULT_SPRITE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(TALK) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(ACTION) - TOKEN_TABLE(DEFAULT_SPRITESET_FILE) - TOKEN_TABLE(DEFAULT_SPRITESET) - TOKEN_TABLE(DEFAULT_SPRITE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_TALK) { - _gameRef->LOG(0, "'TALK' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_ACTION: { - CAdTalkNode *Node = new CAdTalkNode(_gameRef); - if (Node && DID_SUCCEED(Node->loadBuffer(params, false))) _nodes.add(Node); - else { - delete Node; - Node = NULL; - cmd = PARSERR_GENERIC; - } - } - break; - - case TOKEN_DEFAULT_SPRITE: - CBUtils::setString(&_defaultSpriteFilename, (char *)params); - break; - - case TOKEN_DEFAULT_SPRITESET_FILE: - CBUtils::setString(&_defaultSpriteSetFilename, (char *)params); - break; - - case TOKEN_DEFAULT_SPRITESET: { - delete _defaultSpriteSet; - _defaultSpriteSet = new CAdSpriteSet(_gameRef); - if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadBuffer(params, false))) { - delete _defaultSpriteSet; - _defaultSpriteSet = NULL; - cmd = PARSERR_GENERIC; - } - } - break; - - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in TALK definition"); - return STATUS_FAILED; - } - - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading TALK definition"); - return STATUS_FAILED; - } - - delete _defaultSprite; - delete _defaultSpriteSet; - _defaultSprite = NULL; - _defaultSpriteSet = NULL; - - if (_defaultSpriteFilename) { - _defaultSprite = new CBSprite(_gameRef); - if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) return STATUS_FAILED; - } - - if (_defaultSpriteSetFilename) { - _defaultSpriteSet = new CAdSpriteSet(_gameRef); - if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) return STATUS_FAILED; - } - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_defaultSprite)); - persistMgr->transfer(TMEMBER(_defaultSpriteFilename)); - persistMgr->transfer(TMEMBER(_defaultSpriteSet)); - persistMgr->transfer(TMEMBER(_defaultSpriteSetFilename)); - - _nodes.persist(persistMgr); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "TALK {\n"); - if (_defaultSpriteFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); - - if (_defaultSpriteSetFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); - else if (_defaultSpriteSet) _defaultSpriteSet->saveAsText(buffer, indent + 2); - - for (int i = 0; i < _nodes.getSize(); i++) { - _nodes[i]->saveAsText(buffer, indent + 2); - buffer->putTextIndent(indent, "\n"); - } - CBBase::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::loadDefaultSprite() { - if (_defaultSpriteFilename && !_defaultSprite) { - _defaultSprite = new CBSprite(_gameRef); - if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { - delete _defaultSprite; - _defaultSprite = NULL; - return STATUS_FAILED; - } else return STATUS_OK; - } else if (_defaultSpriteSetFilename && !_defaultSpriteSet) { - _defaultSpriteSet = new CAdSpriteSet(_gameRef); - if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { - delete _defaultSpriteSet; - _defaultSpriteSet = NULL; - return STATUS_FAILED; - } else return STATUS_OK; - } else return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -CBSprite *CAdTalkDef::getDefaultSprite(TDirection dir) { - loadDefaultSprite(); - if (_defaultSprite) return _defaultSprite; - else if (_defaultSpriteSet) return _defaultSpriteSet->getSprite(dir); - else return NULL; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdTalkDef.h b/engines/wintermute/ad/AdTalkDef.h deleted file mode 100644 index 81d6475013..0000000000 --- a/engines/wintermute/ad/AdTalkDef.h +++ /dev/null @@ -1,58 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADTALKDEF_H -#define WINTERMUTE_ADTALKDEF_H - -#include "engines/wintermute/coll_templ.h" -#include "engines/wintermute/base/BObject.h" - -namespace WinterMute { -class CAdTalkNode; -class CAdSpriteSet; -class CAdTalkDef : public CBObject { -public: - char *_defaultSpriteSetFilename; - CAdSpriteSet *_defaultSpriteSet; - CBSprite *getDefaultSprite(TDirection Dir); - bool loadDefaultSprite(); - DECLARE_PERSISTENT(CAdTalkDef, CBObject) - - CAdTalkDef(CBGame *inGame); - virtual ~CAdTalkDef(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - CBArray _nodes; - char *_defaultSpriteFilename; - CBSprite *_defaultSprite; - virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdTalkHolder.cpp b/engines/wintermute/ad/AdTalkHolder.cpp deleted file mode 100644 index e1a91792ce..0000000000 --- a/engines/wintermute/ad/AdTalkHolder.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdTalkHolder.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "engines/wintermute/base/scriptables/ScScript.h" -#include "engines/wintermute/base/scriptables/ScStack.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/wintermute.h" -#include "common/str.h" - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdTalkHolder, false) - -////////////////////////////////////////////////////////////////////////// -CAdTalkHolder::CAdTalkHolder(CBGame *inGame): CAdObject(inGame) { - _sprite = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -CAdTalkHolder::~CAdTalkHolder() { - delete _sprite; - _sprite = NULL; - - for (int i = 0; i < _talkSprites.getSize(); i++) - delete _talkSprites[i]; - _talkSprites.removeAll(); - - for (int i = 0; i < _talkSpritesEx.getSize(); i++) - delete _talkSpritesEx[i]; - _talkSpritesEx.removeAll(); -} - -////////////////////////////////////////////////////////////////////////// -CBSprite *CAdTalkHolder::getTalkStance(const char *stance) { - CBSprite *ret = NULL; - - - // forced stance? - if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { - _forcedTalkAnimUsed = true; - delete _animSprite; - _animSprite = new CBSprite(_gameRef, this); - if (_animSprite) { - bool res = _animSprite->loadFile(_forcedTalkAnimName); - if (DID_FAIL(res)) { - _gameRef->LOG(res, "CAdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); - delete _animSprite; - _animSprite = NULL; - } else return _animSprite; - } - } - - - if (stance != NULL) { - // search special talk stances - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->_name, stance) == 0) { - ret = _talkSpritesEx[i]; - break; - } - } - if (ret == NULL) { - // serach generic talk stances - for (int i = 0; i < _talkSprites.getSize(); i++) { - if (scumm_stricmp(_talkSprites[i]->_name, stance) == 0) { - ret = _talkSprites[i]; - break; - } - } - } - } - - // not a valid stance? get a random one - if (ret == NULL) { - if (_talkSprites.getSize() < 1) ret = _sprite; - else { - // TODO: remember last - int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); - ret = _talkSprites[rnd]; - } - } - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool CAdTalkHolder::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // SetSprite - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SetSprite") == 0) { - stack->correctParams(1); - - CScValue *val = stack->pop(); - - bool setCurrent = false; - if (_currentSprite && _currentSprite == _sprite) setCurrent = true; - - delete _sprite; - _sprite = NULL; - - if (val->isNULL()) { - _sprite = NULL; - if (setCurrent) _currentSprite = NULL; - stack->pushBool(true); - } else { - const char *filename = val->getString(); - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - script->runtimeError("SetSprite method failed for file '%s'", filename); - stack->pushBool(false); - } else { - _sprite = spr; - if (setCurrent) _currentSprite = _sprite; - stack->pushBool(true); - } - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetSprite") == 0) { - stack->correctParams(0); - - if (!_sprite || !_sprite->_filename) stack->pushNULL(); - else stack->pushString(_sprite->_filename); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetSpriteObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetSpriteObject") == 0) { - stack->correctParams(0); - - if (!_sprite) stack->pushNULL(); - else stack->pushNative(_sprite, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddTalkSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddTalkSprite") == 0) { - stack->correctParams(2); - - const char *filename = stack->pop()->getString(); - bool Ex = stack->pop()->getBool(); - - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("AddTalkSprite method failed for file '%s'", filename); - } else { - if (Ex) _talkSpritesEx.add(spr); - else _talkSprites.add(spr); - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // RemoveTalkSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "RemoveTalkSprite") == 0) { - stack->correctParams(2); - - const char *filename = stack->pop()->getString(); - bool ex = stack->pop()->getBool(); - - bool setCurrent = false; - bool setTemp2 = false; - - if (ex) { - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->_filename, filename) == 0) { - if (_currentSprite == _talkSpritesEx[i]) - setCurrent = true; - if (_tempSprite2 == _talkSpritesEx[i]) - setTemp2 = true; - delete _talkSpritesEx[i]; - _talkSpritesEx.removeAt(i); - break; - } - } - } else { - for (int i = 0; i < _talkSprites.getSize(); i++) { - if (scumm_stricmp(_talkSprites[i]->_filename, filename) == 0) { - if (_currentSprite == _talkSprites[i]) - setCurrent = true; - if (_tempSprite2 == _talkSprites[i]) - setTemp2 = true; - delete _talkSprites[i]; - _talkSprites.removeAt(i); - break; - } - } - - } - - stack->pushBool(true); - if (setCurrent) - _currentSprite = _sprite; - if (setTemp2) - _tempSprite2 = _sprite; - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetTalkSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SetTalkSprite") == 0) { - stack->correctParams(2); - - const char *filename = stack->pop()->getString(); - bool ex = stack->pop()->getBool(); - bool setCurrent = false; - bool setTemp2 = false; - - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("SetTalkSprite method failed for file '%s'", filename); - } else { - - // delete current - if (ex) { - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (_talkSpritesEx[i] == _currentSprite) - setCurrent = true; - if (_talkSpritesEx[i] == _tempSprite2) - setTemp2 = true; - delete _talkSpritesEx[i]; - } - _talkSpritesEx.removeAll(); - } else { - for (int i = 0; i < _talkSprites.getSize(); i++) { - if (_talkSprites[i] == _currentSprite) setCurrent = true; - if (_talkSprites[i] == _tempSprite2) setTemp2 = true; - delete _talkSprites[i]; - } - _talkSprites.removeAll(); - } - - // set new - if (ex) - _talkSpritesEx.add(spr); - else - _talkSprites.add(spr); - stack->pushBool(true); - - if (setCurrent) - _currentSprite = spr; - if (setTemp2) - _tempSprite2 = spr; - } - return STATUS_OK; - } - - else return CAdObject::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdTalkHolder::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type (RO) - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("talk-holder"); - return _scValue; - } - - else return CAdObject::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkHolder::scSetProperty(const char *name, CScValue *value) { - /* - ////////////////////////////////////////////////////////////////////////// - // Item - ////////////////////////////////////////////////////////////////////////// - if(strcmp(name, "Item")==0){ - SetItem(value->getString()); - return STATUS_OK; - } - - else*/ return CAdObject::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *CAdTalkHolder::scToString() { - return "[talk-holder object]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkHolder::saveAsText(CBDynBuffer *buffer, int indent) { - for (int i = 0; i < _talkSprites.getSize(); i++) { - if (_talkSprites[i]->_filename) - buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->_filename); - } - - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (_talkSpritesEx[i]->_filename) - buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->_filename); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkHolder::persist(CBPersistMgr *persistMgr) { - CAdObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_sprite)); - _talkSprites.persist(persistMgr); - _talkSpritesEx.persist(persistMgr); - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdTalkHolder.h b/engines/wintermute/ad/AdTalkHolder.h deleted file mode 100644 index 9e6c3bbd63..0000000000 --- a/engines/wintermute/ad/AdTalkHolder.h +++ /dev/null @@ -1,57 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADTALKHOLDER_H -#define WINTERMUTE_ADTALKHOLDER_H - -#include "engines/wintermute/ad/AdObject.h" - -namespace WinterMute { - -class CAdTalkHolder : public CAdObject { -public: - DECLARE_PERSISTENT(CAdTalkHolder, CAdObject) - virtual CBSprite *getTalkStance(const char *stance); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - CBSprite *_sprite; - CBArray _talkSprites; - CBArray _talkSpritesEx; - CAdTalkHolder(CBGame *inGame); - virtual ~CAdTalkHolder(); - - // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); - virtual const char *scToString(); - -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdTalkNode.cpp b/engines/wintermute/ad/AdTalkNode.cpp deleted file mode 100644 index da2195be33..0000000000 --- a/engines/wintermute/ad/AdTalkNode.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/ad/AdTalkNode.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BSprite.h" -#include "engines/wintermute/ad/AdSpriteSet.h" -#include "engines/wintermute/utils/utils.h" -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdTalkNode, false) - -////////////////////////////////////////////////////////////////////////// -CAdTalkNode::CAdTalkNode(CBGame *inGame): CBBase(inGame) { - _sprite = NULL; - _spriteFilename = NULL; - _spriteSet = NULL; - _spriteSetFilename = NULL; - _comment = NULL; - - _startTime = _endTime = 0; - _playToEnd = false; - _preCache = false; -} - - -////////////////////////////////////////////////////////////////////////// -CAdTalkNode::~CAdTalkNode() { - delete[] _spriteFilename; - delete _sprite; - delete[] _spriteSetFilename; - delete _spriteSet; - delete _comment; - _spriteFilename = NULL; - _sprite = NULL; - _spriteSetFilename = NULL; - _spriteSet = NULL; - _comment = NULL; -} - - - -TOKEN_DEF_START -TOKEN_DEF(ACTION) -TOKEN_DEF(SPRITESET_FILE) -TOKEN_DEF(SPRITESET) -TOKEN_DEF(SPRITE) -TOKEN_DEF(START_TIME) -TOKEN_DEF(END_TIME) -TOKEN_DEF(COMMENT) -TOKEN_DEF(PRECACHE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ACTION) - TOKEN_TABLE(SPRITESET_FILE) - TOKEN_TABLE(SPRITESET) - TOKEN_TABLE(SPRITE) - TOKEN_TABLE(START_TIME) - TOKEN_TABLE(END_TIME) - TOKEN_TABLE(COMMENT) - TOKEN_TABLE(PRECACHE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTION) { - _gameRef->LOG(0, "'ACTION' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - _endTime = 0; - _playToEnd = false; - _preCache = false; - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_SPRITE: - CBUtils::setString(&_spriteFilename, (char *)params); - break; - - case TOKEN_SPRITESET_FILE: - CBUtils::setString(&_spriteSetFilename, (char *)params); - break; - - case TOKEN_SPRITESET: { - delete _spriteSet; - _spriteSet = new CAdSpriteSet(_gameRef); - if (!_spriteSet || DID_FAIL(_spriteSet->loadBuffer(params, false))) { - delete _spriteSet; - _spriteSet = NULL; - cmd = PARSERR_GENERIC; - } - } - break; - - case TOKEN_START_TIME: - parser.scanStr((char *)params, "%d", &_startTime); - break; - - case TOKEN_END_TIME: - parser.scanStr((char *)params, "%d", &_endTime); - break; - - case TOKEN_PRECACHE: - parser.scanStr((char *)params, "%b", &_preCache); - break; - - case TOKEN_COMMENT: - if (_gameRef->_editorMode) CBUtils::setString(&_comment, (char *)params); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ACTION definition"); - return STATUS_FAILED; - } - - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading ACTION definition"); - return STATUS_FAILED; - } - - if (_endTime == 0) - _playToEnd = true; - else - _playToEnd = false; - - if (_preCache && _spriteFilename) { - delete _sprite; - _sprite = new CBSprite(_gameRef); - if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) - return STATUS_FAILED; - } - - if (_preCache && _spriteSetFilename) { - delete _spriteSet; - _spriteSet = new CAdSpriteSet(_gameRef); - if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) - return STATUS_FAILED; - } - - return STATUS_OK; -} - - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::persist(CBPersistMgr *persistMgr) { - persistMgr->transfer(TMEMBER(_comment)); - persistMgr->transfer(TMEMBER(_startTime)); - persistMgr->transfer(TMEMBER(_endTime)); - persistMgr->transfer(TMEMBER(_playToEnd)); - persistMgr->transfer(TMEMBER(_sprite)); - persistMgr->transfer(TMEMBER(_spriteFilename)); - persistMgr->transfer(TMEMBER(_spriteSet)); - persistMgr->transfer(TMEMBER(_spriteSetFilename)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "ACTION {\n"); - if (_comment) buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); - buffer->putTextIndent(indent + 2, "START_TIME=%d\n", _startTime); - if (!_playToEnd) buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); - if (_spriteFilename) buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); - if (_spriteSetFilename) buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); - else if (_spriteSet) _spriteSet->saveAsText(buffer, indent + 2); - if (_preCache) buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); - - CBBase::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::loadSprite() { - if (_spriteFilename && !_sprite) { - _sprite = new CBSprite(_gameRef); - if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { - delete _sprite; - _sprite = NULL; - return STATUS_FAILED; - } else return STATUS_OK; - } - - else if (_spriteSetFilename && !_spriteSet) { - _spriteSet = new CAdSpriteSet(_gameRef); - if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { - delete _spriteSet; - _spriteSet = NULL; - return STATUS_FAILED; - } else return STATUS_OK; - } - - else return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { - if (time >= _startTime) { - if (_playToEnd) { - if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) return true; - else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) return true; - else return false; - } else return _endTime >= time; - } else return false; -} - - -////////////////////////////////////////////////////////////////////////// -CBSprite *CAdTalkNode::getSprite(TDirection dir) { - loadSprite(); - if (_sprite) return _sprite; - else if (_spriteSet) return _spriteSet->getSprite(dir); - else return NULL; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdTalkNode.h b/engines/wintermute/ad/AdTalkNode.h deleted file mode 100644 index 11bbb353c1..0000000000 --- a/engines/wintermute/ad/AdTalkNode.h +++ /dev/null @@ -1,63 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADTALKNODE_H -#define WINTERMUTE_ADTALKNODE_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/BBase.h" - -namespace WinterMute { -class CAdSpriteSet; -class CBSprite; -class CAdTalkNode : public CBBase { -public: - char *_spriteSetFilename; - CAdSpriteSet *_spriteSet; - CBSprite *getSprite(TDirection dir); - bool isInTimeInterval(uint32 time, TDirection dir); - bool loadSprite(); - DECLARE_PERSISTENT(CAdTalkNode, CBBase) - - CAdTalkNode(CBGame *inGame); - virtual ~CAdTalkNode(); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); - char *_spriteFilename; - CBSprite *_sprite; - uint32 _startTime; - uint32 _endTime; - bool _playToEnd; - bool _preCache; - char *_comment; - -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/AdTypes.h b/engines/wintermute/ad/AdTypes.h deleted file mode 100644 index b88d6fe259..0000000000 --- a/engines/wintermute/ad/AdTypes.h +++ /dev/null @@ -1,107 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADTYPES_H -#define WINTERMUTE_ADTYPES_H - -namespace WinterMute { - -typedef enum { - GAME_NORMAL, - GAME_WAITING_RESPONSE -} TGameStateEx; - -typedef enum { - OBJECT_ENTITY, - OBJECT_REGION, - OBJECT_ACTOR, - OBJECT_NONE -} TObjectType; - -typedef enum { - ENTITY_NORMAL, - ENTITY_SOUND -} TEntityType; - -typedef enum { - STATE_NONE, - STATE_IDLE, - STATE_PLAYING_ANIM, - STATE_READY, - STATE_FOLLOWING_PATH, - STATE_SEARCHING_PATH, - STATE_WAITING_PATH, - STATE_TURNING_LEFT, - STATE_TURNING_RIGHT, - STATE_TURNING, - STATE_TALKING, - STATE_DIRECT_CONTROL, - STATE_PLAYING_ANIM_SET -} TObjectState; - -typedef enum { - DIRECT_WALK_NONE, - DIRECT_WALK_FW, - DIRECT_WALK_BK -} TDirectWalkMode; - -typedef enum { - DIRECT_TURN_NONE, - DIRECT_TURN_CW, - DIRECT_TURN_CCW -} TDirectTurnMode; - -typedef enum { - RESPONSE_TEXT, - RESPONSE_ICON -} TResponseStyle; - -typedef enum { - RESPONSE_ALWAYS, - RESPONSE_ONCE, - RESPONSE_ONCE_GAME -} TResponseType; - - -typedef enum { - TALK_SKIP_LEFT = 0, - TALK_SKIP_RIGHT = 1, - TALK_SKIP_BOTH = 2, - TALK_SKIP_NONE = 3 -} TTalkSkipButton; - -typedef enum { - GEOM_WAYPOINT, - GEOM_WALKPLANE, - GEOM_BLOCKED, - GEOM_GENERIC -} TGeomNodeType; - -} // end of namespace WinterMute - -#endif // WINTERMUTE_ADTYPES_H diff --git a/engines/wintermute/ad/AdWaypointGroup.cpp b/engines/wintermute/ad/AdWaypointGroup.cpp deleted file mode 100644 index 3080b34c09..0000000000 --- a/engines/wintermute/ad/AdWaypointGroup.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/AdWaypointGroup.h" -#include "engines/wintermute/base/BParser.h" -#include "engines/wintermute/base/BDynBuffer.h" -#include "engines/wintermute/base/scriptables/ScValue.h" -#include "engines/wintermute/base/BGame.h" -#include "engines/wintermute/base/BRegion.h" -#include "engines/wintermute/base/BFileManager.h" -#include - -namespace WinterMute { - -IMPLEMENT_PERSISTENT(CAdWaypointGroup, false) - -////////////////////////////////////////////////////////////////////////// -CAdWaypointGroup::CAdWaypointGroup(CBGame *inGame): CBObject(inGame) { - _active = true; - _editorSelectedPoint = -1; - _lastMimicScale = -1; - _lastMimicX = _lastMimicY = INT_MIN; -} - - -////////////////////////////////////////////////////////////////////////// -CAdWaypointGroup::~CAdWaypointGroup() { - cleanup(); -} - - -////////////////////////////////////////////////////////////////////////// -void CAdWaypointGroup::cleanup() { - for (int i = 0; i < _points.getSize(); i++) - delete _points[i]; - _points.removeAll(); - _editorSelectedPoint = -1; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "CAdWaypointGroup::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); - - - delete [] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(WAYPOINTS) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(NAME) -TOKEN_DEF(POINT) -TOKEN_DEF(EDITOR_SELECTED_POINT) -TOKEN_DEF(EDITOR_SELECTED) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(WAYPOINTS) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(NAME) - TOKEN_TABLE(POINT) - TOKEN_TABLE(EDITOR_SELECTED_POINT) - TOKEN_TABLE(EDITOR_SELECTED) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - CBParser parser(_gameRef); - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_WAYPOINTS) { - _gameRef->LOG(0, "'WAYPOINTS' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_POINT: { - int x, y; - parser.scanStr((char *)params, "%d,%d", &x, &y); - _points.add(new CBPoint(x, y)); - } - break; - - case TOKEN_EDITOR_SELECTED: - parser.scanStr((char *)params, "%b", &_editorSelected); - break; - - case TOKEN_EDITOR_SELECTED_POINT: - parser.scanStr((char *)params, "%d", &_editorSelectedPoint); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in WAYPOINTS definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::saveAsText(CBDynBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "WAYPOINTS {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); - buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SELECTED_POINT=%d\n", _editorSelectedPoint); - - if (_scProp) - _scProp->saveAsText(buffer, indent + 2); - CBBase::saveAsText(buffer, indent + 2); - - for (int i = 0; i < _points.getSize(); i++) { - buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); - } - - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::persist(CBPersistMgr *persistMgr) { - - CBObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_active)); - persistMgr->transfer(TMEMBER(_editorSelectedPoint)); - persistMgr->transfer(TMEMBER(_lastMimicScale)); - persistMgr->transfer(TMEMBER(_lastMimicX)); - persistMgr->transfer(TMEMBER(_lastMimicY)); - _points.persist(persistMgr); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -CScValue *CAdWaypointGroup::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("waypoint-group"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { - _scValue->setBool(_active); - return _scValue; - } - - else return CBObject::scGetProperty(name); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::scSetProperty(const char *name, CScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Active") == 0) { - _active = value->getBool(); - return STATUS_OK; - } - - else return CBObject::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::mimic(CAdWaypointGroup *wpt, float scale, int argX, int argY) { - if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) return STATUS_OK; - - cleanup(); - - for (int i = 0; i < wpt->_points.getSize(); i++) { - int x = (int)((float)wpt->_points[i]->x * scale / 100.0f); - int y = (int)((float)wpt->_points[i]->y * scale / 100.0f); - - _points.add(new CBPoint(x + argX, y + argY)); - } - - _lastMimicScale = scale; - _lastMimicX = argX; - _lastMimicY = argY; - - return STATUS_OK; -} - -} // end of namespace WinterMute diff --git a/engines/wintermute/ad/AdWaypointGroup.h b/engines/wintermute/ad/AdWaypointGroup.h deleted file mode 100644 index f7c9e4c361..0000000000 --- a/engines/wintermute/ad/AdWaypointGroup.h +++ /dev/null @@ -1,58 +0,0 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADWAYPOINTGROUP_H -#define WINTERMUTE_ADWAYPOINTGROUP_H - -#include "engines/wintermute/base/BObject.h" - -namespace WinterMute { -class CBPoint; -class CAdWaypointGroup : public CBObject { -public: - float _lastMimicScale; - int _lastMimicX; - int _lastMimicY; - void cleanup(); - bool mimic(CAdWaypointGroup *wpt, float scale = 100.0f, int x = 0, int y = 0); - DECLARE_PERSISTENT(CAdWaypointGroup, CBObject) - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - bool _active; - CAdWaypointGroup(CBGame *inGame); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual ~CAdWaypointGroup(); - CBArray _points; - int _editorSelectedPoint; - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); -}; - -} // end of namespace WinterMute - -#endif diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp new file mode 100644 index 0000000000..36f1aa8286 --- /dev/null +++ b/engines/wintermute/ad/ad_actor.cpp @@ -0,0 +1,1316 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/dctypes.h" +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/ad/ad_actor.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/ad/ad_sprite_set.h" +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/ad/ad_path.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/wintermute.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdActor, false) + + +////////////////////////////////////////////////////////////////////////// +CAdActor::CAdActor(CBGame *inGame): CAdTalkHolder(inGame) { + _path = new CAdPath(_gameRef); + + _type = OBJECT_ACTOR; + _dir = DI_LEFT; + + _walkSprite = NULL; + _standSprite = NULL; + _turnLeftSprite = NULL; + _turnRightSprite = NULL; + + _targetPoint = new CBPoint; + _afterWalkDir = DI_NONE; + + _animSprite2 = NULL; + + setDefaultAnimNames(); +} + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::setDefaultAnimNames() { + _talkAnimName = "talk"; + _idleAnimName = "idle"; + _walkAnimName = "walk"; + _turnLeftAnimName = "turnleft"; + _turnRightAnimName = "turnright"; + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +CAdActor::~CAdActor() { + delete _path; + delete _targetPoint; + _path = NULL; + _targetPoint = NULL; + + delete _walkSprite; + delete _standSprite; + delete _turnLeftSprite; + delete _turnRightSprite; + _walkSprite = NULL; + _standSprite = NULL; + _turnLeftSprite = NULL; + _turnRightSprite = NULL; + + _animSprite2 = NULL; // ref only + + for (int i = 0; i < _talkSprites.getSize(); i++) { + delete _talkSprites[i]; + } + _talkSprites.removeAll(); + + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + delete _talkSpritesEx[i]; + } + _talkSpritesEx.removeAll(); + + for (int i = 0; i < _anims.getSize(); i++) { + delete _anims[i]; + _anims[i] = NULL; + } + _anims.removeAll(); + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdActor::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ACTOR) +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(WALK) +TOKEN_DEF(STAND) +TOKEN_DEF(TALK_SPECIAL) +TOKEN_DEF(TALK) +TOKEN_DEF(TURN_LEFT) +TOKEN_DEF(TURN_RIGHT) +TOKEN_DEF(EVENTS) +TOKEN_DEF(FONT) +TOKEN_DEF(CURSOR) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(SOUND_VOLUME) +TOKEN_DEF(SOUND_PANNING) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(BLOCKED_REGION) +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(ANIMATION) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdActor::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ACTOR) + 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(WALK) + TOKEN_TABLE(STAND) + TOKEN_TABLE(TALK_SPECIAL) + TOKEN_TABLE(TALK) + TOKEN_TABLE(TURN_LEFT) + TOKEN_TABLE(TURN_RIGHT) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(FONT) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(SOUND_VOLUME) + TOKEN_TABLE(SOUND_PANNING) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(BLOCKED_REGION) + 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(ANIMATION) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTOR) { + _gameRef->LOG(0, "'ACTOR' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + CAdGame *adGame = (CAdGame *)_gameRef; + CAdSpriteSet *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 (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_FONT: + SetFont((char *)params); + break; + + case TOKEN_SCALABLE: + parser.scanStr((char *)params, "%b", &_zoomable); + break; + + case TOKEN_ROTABLE: + case TOKEN_ROTATABLE: + parser.scanStr((char *)params, "%b", &_rotatable); + break; + + case TOKEN_REGISTRABLE: + case TOKEN_INTERACTIVE: + parser.scanStr((char *)params, "%b", &_registrable); + break; + + case TOKEN_SHADOWABLE: + case TOKEN_COLORABLE: + parser.scanStr((char *)params, "%b", &_shadowable); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_WALK: + delete _walkSprite; + _walkSprite = NULL; + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC; + else _walkSprite = spr; + break; + + case TOKEN_TALK: + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSprites.add(spr); + break; + + case TOKEN_TALK_SPECIAL: + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSpritesEx.add(spr); + break; + + case TOKEN_STAND: + delete _standSprite; + _standSprite = NULL; + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) cmd = PARSERR_GENERIC; + else _standSprite = spr; + break; + + case TOKEN_TURN_LEFT: + delete _turnLeftSprite; + _turnLeftSprite = NULL; + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; + else _turnLeftSprite = spr; + break; + + case TOKEN_TURN_RIGHT: + delete _turnRightSprite; + _turnRightSprite = NULL; + spr = new CAdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; + else _turnRightSprite = spr; + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new CBSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_SOUND_VOLUME: + parser.scanStr((char *)params, "%d", &_sFXVolume); + break; + + case TOKEN_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _scale = (float)s; + + } + break; + + case TOKEN_RELATIVE_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _relativeScale = (float)s; + + } + break; + + case TOKEN_SOUND_PANNING: + parser.scanStr((char *)params, "%b", &_autoSoundPanning); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_BLOCKED_REGION: { + delete _blockRegion; + delete _currentBlockRegion; + _blockRegion = NULL; + _currentBlockRegion = NULL; + CBRegion *rgn = new CBRegion(_gameRef); + CBRegion *crgn = new CBRegion(_gameRef); + if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { + delete _blockRegion; + delete _currentBlockRegion; + _blockRegion = NULL; + _currentBlockRegion = NULL; + cmd = PARSERR_GENERIC; + } else { + _blockRegion = rgn; + _currentBlockRegion = crgn; + _currentBlockRegion->mimic(_blockRegion); + } + } + break; + + case TOKEN_WAYPOINTS: { + delete _wptGroup; + delete _currentWptGroup; + _wptGroup = NULL; + _currentWptGroup = NULL; + CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); + CAdWaypointGroup *cwpt = new CAdWaypointGroup(_gameRef); + if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { + delete _wptGroup; + delete _currentWptGroup; + _wptGroup = NULL; + _currentWptGroup = NULL; + cmd = PARSERR_GENERIC; + } else { + _wptGroup = wpt; + _currentWptGroup = cwpt; + _currentWptGroup->mimic(_wptGroup); + } + } + break; + + case TOKEN_IGNORE_ITEMS: + parser.scanStr((char *)params, "%b", &_ignoreItems); + 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_ANIMATION: { + CAdSpriteSet *Anim = new CAdSpriteSet(_gameRef, this); + if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) cmd = PARSERR_GENERIC; + else _anims.add(Anim); + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ACTOR definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + if (spr) delete spr; + _gameRef->LOG(0, "Error loading ACTOR definition"); + return STATUS_FAILED; + } + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + _state = _nextState = STATE_READY; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::turnTo(TDirection dir) { + int delta1, delta2, delta3, delta; + + delta1 = dir - _dir; + delta2 = dir + NUM_DIRECTIONS - _dir; + delta3 = dir - NUM_DIRECTIONS - _dir; + + delta1 = (abs(delta1) <= abs(delta2)) ? delta1 : delta2; + delta = (abs(delta1) <= abs(delta3)) ? delta1 : delta3; + + // already there? + if (abs(delta) < 2) { + _dir = dir; + _state = _nextState; + _nextState = STATE_READY; + return; + } + + _targetDir = dir; + _state = delta < 0 ? STATE_TURNING_LEFT : STATE_TURNING_RIGHT; + + _tempSprite2 = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::goTo(int x, int y, TDirection afterWalkDir) { + _afterWalkDir = afterWalkDir; + if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) return; + + _path->reset(); + _path->setReady(false); + + _targetPoint->x = x; + _targetPoint->y = y; + + ((CAdGame *)_gameRef)->_scene->correctTargetPoint(_posX, _posY, &_targetPoint->x, &_targetPoint->y, true, this); + + _state = STATE_SEARCHING_PATH; + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::display() { + if (_active) updateSounds(); + + uint32 alpha; + if (_alphaColor != 0) alpha = _alphaColor; + else alpha = _shadowable ? ((CAdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; + + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + + float rotate; + if (_rotatable) { + if (_rotateValid) rotate = _rotate; + else rotate = ((CAdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } else rotate = 0.0f; + + if (_active) displaySpriteAttachments(true); + + if (_currentSprite && _active) { + bool reg = _registrable; + if (_ignoreItems && ((CAdGame *)_gameRef)->_selectedItem) reg = false; + + _currentSprite->display(_posX, + _posY, + reg ? _registerAlias : NULL, + scaleX, + scaleY, + alpha, + rotate, + _blendMode); + + } + + if (_active) displaySpriteAttachments(false); + if (_active && _partEmitter) _partEmitter->display(); + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::update() { + _currentSprite = NULL; + + if (_state == STATE_READY) { + if (_animSprite) { + delete _animSprite; + _animSprite = NULL; + } + if (_animSprite2) { + _animSprite2 = NULL; + } + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = _nextState; + _nextState = STATE_READY; + _currentSprite = _animSprite; + } + + if (_state == STATE_PLAYING_ANIM_SET && _animSprite2 != NULL && _animSprite2->_finished) { + _state = _nextState; + _nextState = STATE_READY; + _currentSprite = _animSprite2; + } + + if (_sentence && _state != STATE_TALKING) _sentence->finish(); + + // default: stand animation + if (!_currentSprite) { + if (_sprite) _currentSprite = _sprite; + else { + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + if (Anim) _currentSprite = Anim->getSprite(_dir); + } + } + } + + bool already_moved = false; + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM_SET: + _currentSprite = _animSprite2; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TURNING_LEFT: + if (_tempSprite2 == NULL || _tempSprite2->_finished) { + if (_dir > 0) _dir = (TDirection)(_dir - 1); + else _dir = (TDirection)(NUM_DIRECTIONS - 1); + + if (_dir == _targetDir) { + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + if (_turnLeftSprite) { + _tempSprite2 = _turnLeftSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_turnLeftAnimName); + if (Anim) _tempSprite2 = Anim->getSprite(_dir); + } + + if (_tempSprite2) { + _tempSprite2->reset(); + if (_tempSprite2->_looping) _tempSprite2->_looping = false; + } + _currentSprite = _tempSprite2; + } + } else _currentSprite = _tempSprite2; + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_TURNING_RIGHT: + if (_tempSprite2 == NULL || _tempSprite2->_finished) { + _dir = (TDirection)(_dir + 1); + + if ((int)_dir >= (int)NUM_DIRECTIONS) _dir = (TDirection)(0); + + if (_dir == _targetDir) { + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + if (_turnRightSprite) { + _tempSprite2 = _turnRightSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_turnRightAnimName); + if (Anim) _tempSprite2 = Anim->getSprite(_dir); + } + + if (_tempSprite2) { + _tempSprite2->reset(); + if (_tempSprite2->_looping) _tempSprite2->_looping = false; + } + _currentSprite = _tempSprite2; + } + } else _currentSprite = _tempSprite2; + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_SEARCHING_PATH: + // keep asking scene for the path + if (((CAdGame *)_gameRef)->_scene->getPath(CBPoint(_posX, _posY), *_targetPoint, _path, this)) + _state = STATE_WAITING_PATH; + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_WAITING_PATH: + // wait until the scene finished the path + if (_path->_ready) followPath(); + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_FOLLOWING_PATH: + getNextStep(); + already_moved = true; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(_dir); + if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + + bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { + if (TimeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } + } else { + _currentSprite = _tempSprite2; + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite && !_animSprite2) { + if (_sprite) _currentSprite = _sprite; + else { + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + if (Anim) _currentSprite = Anim->getSprite(_dir); + } + } + } + break; + default: + error("AdActor::Update - Unhandled enum"); + } + + + if (_currentSprite && !already_moved) { + _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (_currentSprite->_changed) { + _posX += _currentSprite->_moveX; + _posY += _currentSprite->_moveY; + afterMove(); + } + } + + //_gameRef->QuickMessageForm("%s", _currentSprite->_filename); + + updateBlockRegion(); + _ready = (_state == STATE_READY); + + updatePartEmitter(); + updateSpriteAttachments(); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::followPath() { + // skip current position + _path->getFirst(); + while (_path->getCurrent() != NULL) { + if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) break; + _path->getNext(); + } + + // are there points to follow? + if (_path->getCurrent() != NULL) { + _state = STATE_FOLLOWING_PATH;; + initLine(CBPoint(_posX, _posY), *_path->getCurrent()); + } else { + if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); + else _state = STATE_READY; + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::getNextStep() { + if (_walkSprite) { + _currentSprite = _walkSprite->getSprite(_dir); + } else { + CAdSpriteSet *Anim = getAnimByName(_walkAnimName); + if (Anim) _currentSprite = Anim->getSprite(_dir); + } + + if (!_currentSprite) return; + + _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (!_currentSprite->_changed) return; + + + int maxStepX, maxStepY; + maxStepX = abs(_currentSprite->_moveX); + maxStepY = abs(_currentSprite->_moveY); + + maxStepX = MAX(maxStepX, maxStepY); + maxStepX = MAX(maxStepX, 1); + + while (_pFCount > 0 && maxStepX >= 0) { + _pFX += _pFStepX; + _pFY += _pFStepY; + + _pFCount--; + maxStepX--; + } + + if (((CAdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX,(int) _pFY, true, this)) { + if (_pFCount == 0) { + _state = _nextState; + _nextState = STATE_READY; + return; + } + goTo(_targetPoint->x, _targetPoint->y); + return; + } + + + _posX = (int)_pFX; + _posY = (int)_pFY; + + afterMove(); + + + if (_pFCount == 0) { + if (_path->getNext() == NULL) { + _posX = _targetPoint->x; + _posY = _targetPoint->y; + + _path->reset(); + if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); + else { + _state = _nextState; + _nextState = STATE_READY; + } + } else initLine(CBPoint(_posX, _posY), *_path->getCurrent()); + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdActor::initLine(CBPoint startPt, CBPoint endPt) { + _pFCount = MAX((abs(endPt.x - startPt.x)) , (abs(endPt.y - startPt.y))); + + _pFStepX = (double)(endPt.x - startPt.x) / _pFCount; + _pFStepY = (double)(endPt.y - startPt.y) / _pFCount; + + _pFX = startPt.x; + _pFY = startPt.y; + + int angle = (int)(atan2((double)(endPt.y - startPt.y), (double)(endPt.x - startPt.x)) * (180 / 3.14)); + + _nextState = STATE_FOLLOWING_PATH; + + turnTo(angleToDirection(angle)); +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdActor::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // GoTo / GoToAsync + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "GoTo") == 0 || strcmp(name, "GoToAsync") == 0) { + stack->correctParams(2); + int X = stack->pop()->getInt(); + int Y = stack->pop()->getInt(); + goTo(X, Y); + if (strcmp(name, "GoToAsync") != 0) script->waitForExclusive(this); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GoToObject / GoToObjectAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GoToObject") == 0 || strcmp(name, "GoToObjectAsync") == 0) { + stack->correctParams(1); + CScValue *Val = stack->pop(); + if (!Val->isNative()) { + script->runtimeError("actor.%s method accepts an entity refrence only", name); + stack->pushNULL(); + return STATUS_OK; + } + CAdObject *Obj = (CAdObject *)Val->getNative(); + if (!Obj || Obj->_type != OBJECT_ENTITY) { + script->runtimeError("actor.%s method accepts an entity refrence only", name); + stack->pushNULL(); + return STATUS_OK; + } + CAdEntity *Ent = (CAdEntity *)Obj; + if (Ent->_walkToX == 0 && Ent->_walkToY == 0) goTo(Ent->_posX, Ent->_posY); + else goTo(Ent->_walkToX, Ent->_walkToY, Ent->_walkToDir); + if (strcmp(name, "GoToObjectAsync") != 0) script->waitForExclusive(this); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnTo / TurnToAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnTo") == 0 || strcmp(name, "TurnToAsync") == 0) { + stack->correctParams(1); + int dir; + CScValue *val = stack->pop(); + + // turn to object? + if (val->isNative() && _gameRef->validObject((CBObject *)val->getNative())) { + CBObject *obj = (CBObject *)val->getNative(); + int angle = (int)(atan2((double)(obj->_posY - _posY), (double)(obj->_posX - _posX)) * (180 / 3.14)); + dir = (int)angleToDirection(angle); + } + // otherwise turn to direction + else dir = val->getInt(); + + if (dir >= 0 && dir < NUM_DIRECTIONS) { + turnTo((TDirection)dir); + if (strcmp(name, "TurnToAsync") != 0) script->waitForExclusive(this); + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsWalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsWalking") == 0) { + stack->correctParams(0); + stack->pushBool(_state == STATE_FOLLOWING_PATH); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // MergeAnims + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MergeAnims") == 0) { + stack->correctParams(1); + stack->pushBool(DID_SUCCEED(mergeAnims(stack->pop()->getString()))); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadAnim") == 0) { + stack->correctParams(1); + const char *AnimName = stack->pop()->getString(); + + bool Found = false; + for (int i = 0; i < _anims.getSize(); i++) { + if (scumm_stricmp(_anims[i]->_name, AnimName) == 0) { + // invalidate sprites in use + if (_anims[i]->containsSprite(_tempSprite2)) _tempSprite2 = NULL; + if (_anims[i]->containsSprite(_currentSprite)) _currentSprite = NULL; + if (_anims[i]->containsSprite(_animSprite2)) _animSprite2 = NULL; + + delete _anims[i]; + _anims[i] = NULL; + _anims.removeAt(i); + i--; + Found = true; + } + } + stack->pushBool(Found); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // HasAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasAnim") == 0) { + stack->correctParams(1); + const char *AnimName = stack->pop()->getString(); + stack->pushBool(getAnimByName(AnimName) != NULL); + return STATUS_OK; + } + + else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdActor::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Direction + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Direction") == 0) { + _scValue->setInt(_dir); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Type") == 0) { + _scValue->setString("actor"); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // TalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkAnimName") == 0) { + _scValue->setString(_talkAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkAnimName") == 0) { + _scValue->setString(_walkAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // IdleAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IdleAnimName") == 0) { + _scValue->setString(_idleAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnLeftAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnLeftAnimName") == 0) { + _scValue->setString(_turnLeftAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnRightAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnRightAnimName") == 0) { + _scValue->setString(_turnRightAnimName); + return _scValue; + } + + else return CAdTalkHolder::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Direction + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Direction") == 0) { + int dir = value->getInt(); + if (dir >= 0 && dir < NUM_DIRECTIONS) _dir = (TDirection)dir; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkAnimName") == 0) { + if (value->isNULL()) _talkAnimName = "talk"; + else _talkAnimName = value->getString(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkAnimName") == 0) { + if (value->isNULL()) _walkAnimName = "walk"; + else _walkAnimName = value->getString(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IdleAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IdleAnimName") == 0) { + if (value->isNULL()) _idleAnimName = "idle"; + else _idleAnimName = value->getString(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnLeftAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnLeftAnimName") == 0) { + if (value->isNULL()) _turnLeftAnimName = "turnleft"; + else _turnLeftAnimName = value->getString(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnRightAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnRightAnimName") == 0) { + if (value->isNULL()) _turnRightAnimName = "turnright"; + else _turnRightAnimName = value->getString(); + return STATUS_OK; + } + + else return CAdTalkHolder::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdActor::scToString() { + return "[actor object]"; +} + + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdActor::getTalkStance(const char *stance) { + // forced stance? + if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { + _forcedTalkAnimUsed = true; + delete _animSprite; + _animSprite = new CBSprite(_gameRef, this); + if (_animSprite) { + bool res = _animSprite->loadFile(_forcedTalkAnimName); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "CAdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); + delete _animSprite; + _animSprite = NULL; + } else return _animSprite; + } + } + + // old way + if (_talkSprites.getSize() > 0 || _talkSpritesEx.getSize() > 0) + return getTalkStanceOld(stance); + + // new way + CBSprite *ret = NULL; + + // do we have an animation with this name? + CAdSpriteSet *Anim = getAnimByName(stance); + if (Anim) ret = Anim->getSprite(_dir); + + // not - get a random talk + if (!ret) { + CBArray TalkAnims; + for (int i = 0; i < _anims.getSize(); i++) { + if (_talkAnimName.compareToIgnoreCase(_anims[i]->_name) == 0) + TalkAnims.add(_anims[i]); + } + + if (TalkAnims.getSize() > 0) { + int rnd = g_wintermute->randInt(0, TalkAnims.getSize() - 1); + ret = TalkAnims[rnd]->getSprite(_dir); + } else { + if (_standSprite) ret = _standSprite->getSprite(_dir); + else { + Anim = getAnimByName(_idleAnimName); + if (Anim) ret = Anim->getSprite(_dir); + } + } + } + return ret; +} + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdActor::getTalkStanceOld(const char *stance) { + CBSprite *ret = NULL; + + if (stance != NULL) { + // search special stances + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->_name, stance) == 0) { + ret = _talkSpritesEx[i]->getSprite(_dir); + break; + } + } + if (ret == NULL) { + // search generic stances + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (scumm_stricmp(_talkSprites[i]->_name, stance) == 0) { + ret = _talkSprites[i]->getSprite(_dir); + break; + } + } + } + } + + // not a valid stance? get a random one + if (ret == NULL) { + if (_talkSprites.getSize() < 1) ret = _standSprite->getSprite(_dir); + else { + // TODO: remember last + int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); + ret = _talkSprites[rnd]->getSprite(_dir); + } + } + + return ret; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::persist(CBPersistMgr *persistMgr) { + CAdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER_INT(_dir)); + persistMgr->transfer(TMEMBER(_path)); + persistMgr->transfer(TMEMBER(_pFCount)); + persistMgr->transfer(TMEMBER(_pFStepX)); + persistMgr->transfer(TMEMBER(_pFStepY)); + persistMgr->transfer(TMEMBER(_pFX)); + persistMgr->transfer(TMEMBER(_pFY)); + persistMgr->transfer(TMEMBER(_standSprite)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + persistMgr->transfer(TMEMBER_INT(_targetDir)); + persistMgr->transfer(TMEMBER_INT(_afterWalkDir)); + persistMgr->transfer(TMEMBER(_targetPoint)); + persistMgr->transfer(TMEMBER(_turnLeftSprite)); + persistMgr->transfer(TMEMBER(_turnRightSprite)); + persistMgr->transfer(TMEMBER(_walkSprite)); + + persistMgr->transfer(TMEMBER(_animSprite2)); + persistMgr->transfer(TMEMBER(_talkAnimName)); + persistMgr->transfer(TMEMBER(_idleAnimName)); + persistMgr->transfer(TMEMBER(_walkAnimName)); + persistMgr->transfer(TMEMBER(_turnLeftAnimName)); + persistMgr->transfer(TMEMBER(_turnRightAnimName)); + + _anims.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +TDirection CAdActor::angleToDirection(int angle) { + TDirection ret = DI_DOWN;; + + if (angle > -112 && angle <= -67) ret = DI_UP; + else if (angle > -67 && angle <= -22) ret = DI_UPRIGHT; + else if (angle > -22 && angle <= 22) ret = DI_RIGHT; + else if (angle > 22 && angle <= 67) ret = DI_DOWNRIGHT; + else if (angle > 67 && angle <= 112) ret = DI_DOWN; + else if (angle > 112 && angle <= 157) ret = DI_DOWNLEFT; + else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) ret = DI_LEFT; + else if (angle > -157 && angle <= -112) ret = DI_UPLEFT; + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdActor::getHeight() { + // if no current sprite is set, set some + if (_currentSprite == NULL) { + if (_standSprite) _currentSprite = _standSprite->getSprite(_dir); + else { + CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + if (Anim) _currentSprite = Anim->getSprite(_dir); + } + } + // and get height + return CAdTalkHolder::getHeight(); +} + + +////////////////////////////////////////////////////////////////////////// +CAdSpriteSet *CAdActor::getAnimByName(const Common::String &animName) { + for (int i = 0; i < _anims.getSize(); i++) { + if (animName.compareToIgnoreCase(_anims[i]->_name) == 0) + return _anims[i]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::mergeAnims(const char *animsFilename) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ANIMATION) + TOKEN_TABLE_END + + + byte *fileBuffer = _gameRef->_fileManager->readWholeFile(animsFilename); + if (fileBuffer == NULL) { + _gameRef->LOG(0, "CAdActor::MergeAnims failed for file '%s'", animsFilename); + return STATUS_FAILED; + } + + byte *buffer = fileBuffer; + byte *params; + int cmd; + CBParser parser(_gameRef); + + bool Ret = STATUS_OK; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_ANIMATION: { + CAdSpriteSet *Anim = new CAdSpriteSet(_gameRef, this); + if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + Ret = STATUS_FAILED; + } else _anims.add(Anim); + } + break; + } + } + delete [] fileBuffer; + return Ret; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdActor::playAnim(const char *filename) { + // if we have an anim with this name, use it + CAdSpriteSet *Anim = getAnimByName(filename); + if (Anim) { + _animSprite2 = Anim->getSprite(_dir); + if (_animSprite2) { + _animSprite2->reset(); + _state = STATE_PLAYING_ANIM_SET; + return STATUS_OK; + } + } + // otherwise call the standard handler + return CAdTalkHolder::playAnim(filename); +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h new file mode 100644 index 0000000000..ca79f638d9 --- /dev/null +++ b/engines/wintermute/ad/ad_actor.h @@ -0,0 +1,107 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADACTOR_H +#define WINTERMUTE_ADACTOR_H + + +#include "engines/wintermute/dctypes.h" // Added by ClassView +#include "engines/wintermute/ad/ad_types.h" // Added by ClassView +#include "engines/wintermute/ad/ad_talk_holder.h" +#include "engines/wintermute/base/base_point.h" // Added by ClassView +#include "engines/wintermute/persistent.h" +#include "common/str.h" + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +namespace WinterMute { +class CAdSpriteSet; +class CAdPath; +class CAdActor : public CAdTalkHolder { +public: + TDirection angleToDirection(int angle); + DECLARE_PERSISTENT(CAdActor, CAdTalkHolder) + virtual int getHeight(); + CBSprite *getTalkStance(const char *stance); + virtual void goTo(int x, int y, TDirection afterWalkDir = DI_NONE); + CBPoint *_targetPoint; + virtual bool update(); + virtual bool display(); + TDirection _targetDir; + TDirection _afterWalkDir; + virtual void turnTo(TDirection dir); + CAdPath *_path; + CAdSpriteSet *_walkSprite; + CAdSpriteSet *_standSprite; + CAdSpriteSet *_turnLeftSprite; + CAdSpriteSet *_turnRightSprite; + CBArray _talkSprites; + CBArray _talkSpritesEx; + TDirection _dir; + CAdActor(CBGame *inGame/*=NULL*/); + virtual ~CAdActor(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + + // new anim system + Common::String _talkAnimName; + Common::String _idleAnimName; + Common::String _walkAnimName; + Common::String _turnLeftAnimName; + Common::String _turnRightAnimName; + CBArray _anims; + virtual bool playAnim(const char *filename); + CAdSpriteSet *getAnimByName(const Common::String &animName); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + +private: + bool setDefaultAnimNames(); + CBSprite *getTalkStanceOld(const char *stance); + bool mergeAnims(const char *animsFilename); + CBSprite *_animSprite2; + + void initLine(CBPoint startPt, CBPoint endPt); + void getNextStep(); + void followPath(); + double _pFStepX; + double _pFStepY; + double _pFX; + double _pFY; + int _pFCount; +}; + +} // end of namespace WinterMute + +#endif // WINTERMUTE_ADACTOR_H diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp new file mode 100644 index 0000000000..5f32017264 --- /dev/null +++ b/engines/wintermute/ad/ad_entity.cpp @@ -0,0 +1,1027 @@ +/* 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. + + * 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. + + * 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 + */ + + + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_active_rect.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/video/video_theora_player.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdEntity, false) + +////////////////////////////////////////////////////////////////////////// +CAdEntity::CAdEntity(CBGame *inGame): CAdTalkHolder(inGame) { + _type = OBJECT_ENTITY; + _subtype = ENTITY_NORMAL; + _region = NULL; + _item = NULL; + + _walkToX = _walkToY = 0; + _walkToDir = DI_NONE; + + _theora = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdEntity::~CAdEntity() { + _gameRef->unregisterObject(_region); + + delete _theora; + _theora = NULL; + + delete[] _item; + _item = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdEntity::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->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 +////////////////////////////////////////////////////////////////////////// +bool 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(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY) { + _gameRef->LOG(0, "'ENTITY' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + CAdGame *adGame = (CAdGame *)_gameRef; + 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 (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_SPRITE: { + delete _sprite; + _sprite = NULL; + spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params))) cmd = PARSERR_GENERIC; + else _sprite = spr; + } + break; + + case TOKEN_TALK: { + spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSprites.add(spr); + } + break; + + case TOKEN_TALK_SPECIAL: { + spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSpritesEx.add(spr); + } + 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: + parser.scanStr((char *)params, "%b", &_zoomable); + break; + + case TOKEN_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _scale = (float)s; + + } + break; + + case TOKEN_RELATIVE_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _relativeScale = (float)s; + + } + break; + + case TOKEN_ROTABLE: + case TOKEN_ROTATABLE: + parser.scanStr((char *)params, "%b", &_rotatable); + break; + + case TOKEN_REGISTRABLE: + case TOKEN_INTERACTIVE: + parser.scanStr((char *)params, "%b", &_registrable); + break; + + case TOKEN_SHADOWABLE: + case TOKEN_COLORABLE: + parser.scanStr((char *)params, "%b", &_shadowable); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new CBSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_REGION: { + if (_region) _gameRef->unregisterObject(_region); + _region = NULL; + CBRegion *rgn = new CBRegion(_gameRef); + if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) cmd = PARSERR_GENERIC; + else { + _region = rgn; + _gameRef->registerObject(_region); + } + } + break; + + case TOKEN_BLOCKED_REGION: { + delete _blockRegion; + _blockRegion = NULL; + delete _currentBlockRegion; + _currentBlockRegion = NULL; + CBRegion *rgn = new CBRegion(_gameRef); + CBRegion *crgn = new CBRegion(_gameRef); + if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { + delete _blockRegion; + _blockRegion = NULL; + delete _currentBlockRegion; + _currentBlockRegion = NULL; + cmd = PARSERR_GENERIC; + } else { + _blockRegion = rgn; + _currentBlockRegion = crgn; + _currentBlockRegion->mimic(_blockRegion); + } + } + break; + + case TOKEN_WAYPOINTS: { + delete _wptGroup; + _wptGroup = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); + CAdWaypointGroup *cwpt = new CAdWaypointGroup(_gameRef); + if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { + delete _wptGroup; + _wptGroup = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + cmd = PARSERR_GENERIC; + } else { + _wptGroup = wpt; + _currentWptGroup = cwpt; + _currentWptGroup->mimic(_wptGroup); + } + } + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_SUBTYPE: { + if (scumm_stricmp((char *)params, "sound") == 0) { + delete _sprite; + _sprite = NULL; + if (_gameRef->_editorMode) { + spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) cmd = PARSERR_GENERIC; + else _sprite = spr; + } + if (_gameRef->_editorMode) _editorOnly = true; + _zoomable = false; + _rotatable = false; + _registrable = _gameRef->_editorMode; + _shadowable = false; + _subtype = ENTITY_SOUND; + } + } + break; + + case TOKEN_SOUND: + playSFX((char *)params, false, false); + break; + + case TOKEN_SOUND_START_TIME: + parser.scanStr((char *)params, "%d", &_sFXStart); + break; + + case TOKEN_SOUND_VOLUME: + parser.scanStr((char *)params, "%d", &_sFXVolume); + break; + + case TOKEN_SOUND_PANNING: + parser.scanStr((char *)params, "%b", &_autoSoundPanning); + break; + + case TOKEN_SAVE_STATE: + parser.scanStr((char *)params, "%b", &_saveState); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_IGNORE_ITEMS: + parser.scanStr((char *)params, "%b", &_ignoreItems); + 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: + parser.scanStr((char *)params, "%d", &_walkToX); + break; + + case TOKEN_WALK_TO_Y: + parser.scanStr((char *)params, "%d", &_walkToY); + 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; + _walkToDir = (TDirection)i; + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ENTITY definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ENTITY definition"); + if (spr) delete spr; + return STATUS_FAILED; + } + + if (_region && _sprite) { + _gameRef->LOG(0, "Warning: Entity '%s' has both sprite and region.", _name); + } + + updatePosition(); + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + _state = STATE_READY; + + if (_item && ((CAdGame *)_gameRef)->isItemTaken(_item)) _active = false; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::display() { + if (_active) { + updateSounds(); + + uint32 Alpha; + if (_alphaColor != 0) Alpha = _alphaColor; + else Alpha = _shadowable ? ((CAdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; + + float ScaleX, ScaleY; + getScale(&ScaleX, &ScaleY); + + float Rotate; + if (_rotatable) { + if (_rotateValid) Rotate = _rotate; + else Rotate = ((CAdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } else Rotate = 0.0f; + + + bool Reg = _registrable; + if (_ignoreItems && ((CAdGame *)_gameRef)->_selectedItem) Reg = false; + + if (_region && (Reg || _editorAlwaysRegister)) { + _gameRef->_renderer->_rectList.add(new CBActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); + } + + displaySpriteAttachments(true); + if (_theora && (_theora->isPlaying() || _theora->isPaused())) { + _theora->display(Alpha); + } else if (_currentSprite) { + _currentSprite->display(_posX, + _posY, + (Reg || _editorAlwaysRegister) ? _registerAlias : NULL, + ScaleX, + ScaleY, + Alpha, + Rotate, + _blendMode); + } + displaySpriteAttachments(false); + + if (_partEmitter) _partEmitter->display(_region); + + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::update() { + _currentSprite = NULL; + + if (_state == STATE_READY && _animSprite) { + delete _animSprite; + _animSprite = NULL; + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = STATE_READY; + _currentSprite = _animSprite; + } + + if (_sentence && _state != STATE_TALKING) _sentence->finish(); + + // default: stand animation + if (!_currentSprite) _currentSprite = _sprite; + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite) + _currentSprite = _sprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(); + if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + + bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { + if (TimeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + } + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } else { + _currentSprite = _tempSprite2; + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } + break; + default: // Silence unhandled enum-warning + break; + } + + + if (_currentSprite) { + _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (_currentSprite->_changed) { + _posX += _currentSprite->_moveX; + _posY += _currentSprite->_moveY; + } + } + + updateBlockRegion(); + _ready = (_state == STATE_READY); + + if (_theora) { + int OffsetX, OffsetY; + _gameRef->getOffset(&OffsetX, &OffsetY); + _theora->_posX = _posX - OffsetX; + _theora->_posY = _posY - OffsetY; + + _theora->update(); + if (_theora->isFinished()) { + _theora->stop(); + delete _theora; + _theora = NULL; + } + } + + updatePartEmitter(); + updateSpriteAttachments(); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // StopSound + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "StopSound") == 0 && _subtype == ENTITY_SOUND) { + stack->correctParams(0); + + if (DID_FAIL(stopSFX(false))) stack->pushBool(false); + else stack->pushBool(true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PlayTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PlayTheora") == 0) { + stack->correctParams(4); + const char *filename = stack->pop()->getString(); + bool looping = stack->pop()->getBool(false); + CScValue *valAlpha = stack->pop(); + int startTime = stack->pop()->getInt(); + + delete _theora; + _theora = new CVidTheoraPlayer(_gameRef); + if (_theora && DID_SUCCEED(_theora->initialize(filename))) { + if (!valAlpha->isNULL()) _theora->setAlphaImage(valAlpha->getString()); + _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); + //if(m_Scale>=0) m_Theora->m_PlayZoom = m_Scale; + stack->pushBool(true); + } else { + script->runtimeError("Entity.PlayTheora - error playing video '%s'", filename); + stack->pushBool(false); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StopTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StopTheora") == 0) { + stack->correctParams(0); + if (_theora) { + _theora->stop(); + delete _theora; + _theora = NULL; + stack->pushBool(true); + } else stack->pushBool(false); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTheoraPlaying + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTheoraPlaying") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPlaying()) stack->pushBool(true); + else stack->pushBool(false); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PauseTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PauseTheora") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPlaying()) { + _theora->pause(); + stack->pushBool(true); + } else stack->pushBool(false); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ResumeTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResumeTheora") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPaused()) { + _theora->resume(); + stack->pushBool(true); + } else stack->pushBool(false); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTheoraPaused + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTheoraPaused") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPaused()) stack->pushBool(true); + else stack->pushBool(false); + + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // CreateRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateRegion") == 0) { + stack->correctParams(0); + if (!_region) { + _region = new CBRegion(_gameRef); + _gameRef->registerObject(_region); + } + if (_region) stack->pushNative(_region, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteRegion") == 0) { + stack->correctParams(0); + if (_region) { + _gameRef->unregisterObject(_region); + _region = NULL; + stack->pushBool(true); + } else stack->pushBool(false); + + return STATUS_OK; + } + + else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdEntity::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type (RO) + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("entity"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Item") == 0) { + if (_item) _scValue->setString(_item); + else _scValue->setNULL(); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Subtype (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Subtype") == 0) { + if (_subtype == ENTITY_SOUND) + _scValue->setString("sound"); + else + _scValue->setString("normal"); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToX") == 0) { + _scValue->setInt(_walkToX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToY") == 0) { + _scValue->setInt(_walkToY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToDirection + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToDirection") == 0) { + _scValue->setInt((int)_walkToDir); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Region (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Region") == 0) { + if (_region) _scValue->setNative(_region, true); + else _scValue->setNULL(); + return _scValue; + } + + else return CAdTalkHolder::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::scSetProperty(const char *name, CScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Item") == 0) { + setItem(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToX") == 0) { + _walkToX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToY") == 0) { + _walkToY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToDirection + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToDirection") == 0) { + int dir = value->getInt(); + if (dir >= 0 && dir < NUM_DIRECTIONS) _walkToDir = (TDirection)dir; + return STATUS_OK; + } + + else return CAdTalkHolder::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdEntity::scToString() { + return "[entity object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ENTITY {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + if (_subtype == ENTITY_SOUND) + buffer->putTextIndent(indent + 2, "SUBTYPE=\"SOUND\"\n"); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + 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); + + int i; + + for (i = 0; i < _scripts.getSize(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_subtype == ENTITY_NORMAL && _sprite && _sprite->_filename) + buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->_filename); + + 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); + } + + + if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) + buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alphaColor), RGBCOLGetG(_alphaColor), RGBCOLGetB(_alphaColor)); + + if (RGBCOLGetA(_alphaColor) != 0) + buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alphaColor)); + + if (_scale >= 0) + buffer->putTextIndent(indent + 2, "SCALE = %d\n", (int)_scale); + + if (_relativeScale != 0) + buffer->putTextIndent(indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale); + + if (_font && _font->_filename) + buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->_filename); + + if (_cursor && _cursor->_filename) + buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); + + CAdTalkHolder::saveAsText(buffer, indent + 2); + + if (_region) _region->saveAsText(buffer, indent + 2); + + if (_scProp) _scProp->saveAsText(buffer, indent + 2); + + CAdObject::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdEntity::getHeight() { + if (_region && !_sprite) { + return _region->_rect.bottom - _region->_rect.top; + } else { + if (_currentSprite == NULL) _currentSprite = _sprite; + return CAdObject::getHeight(); + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdEntity::updatePosition() { + if (_region && !_sprite) { + _posX = _region->_rect.left + (_region->_rect.right - _region->_rect.left) / 2; + _posY = _region->_rect.bottom; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::persist(CBPersistMgr *persistMgr) { + CAdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_item)); + persistMgr->transfer(TMEMBER(_region)); + //persistMgr->transfer(TMEMBER(_sprite)); + persistMgr->transfer(TMEMBER_INT(_subtype)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_walkToX)); + persistMgr->transfer(TMEMBER(_walkToY)); + persistMgr->transfer(TMEMBER_INT(_walkToDir)); + + persistMgr->transfer(TMEMBER(_theora)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdEntity::setItem(const char *itemName) { + CBUtils::setString(&_item, itemName); +} + +////////////////////////////////////////////////////////////////////////// +bool CAdEntity::setSprite(const char *filename) { + bool setCurrent = false; + if (_currentSprite == _sprite) { + _currentSprite = NULL; + setCurrent = true; + } + + delete _sprite; + _sprite = NULL; + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + delete _sprite; + _sprite = NULL; + return STATUS_FAILED; + } else { + _sprite = spr; + _currentSprite = _sprite; + return STATUS_OK; + } +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_entity.h b/engines/wintermute/ad/ad_entity.h new file mode 100644 index 0000000000..8b67d27c1f --- /dev/null +++ b/engines/wintermute/ad/ad_entity.h @@ -0,0 +1,68 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADENTITY_H +#define WINTERMUTE_ADENTITY_H + +#include "engines/wintermute/ad/ad_talk_holder.h" + +namespace WinterMute { +class CVidTheoraPlayer; +class CAdEntity : public CAdTalkHolder { +public: + CVidTheoraPlayer *_theora; + bool setSprite(const char *filename); + int _walkToX; + int _walkToY; + TDirection _walkToDir; + void setItem(const char *itemName); + char *_item; + DECLARE_PERSISTENT(CAdEntity, CAdTalkHolder) + void updatePosition(); + virtual int getHeight(); + CBRegion *_region; + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + virtual bool update(); + virtual bool display(); + CAdEntity(CBGame *inGame); + virtual ~CAdEntity(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + TEntityType _subtype; + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp new file mode 100644 index 0000000000..69cda25f29 --- /dev/null +++ b/engines/wintermute/ad/ad_game.cpp @@ -0,0 +1,2061 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_actor.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/ad/ad_inventory.h" +#include "engines/wintermute/ad/ad_inventory_box.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/ad/ad_response.h" +#include "engines/wintermute/ad/ad_response_box.h" +#include "engines/wintermute/ad/ad_response_context.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/ad/ad_scene_state.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/base/base_string_table.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/base/base_transition_manager.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_viewport.h" +#include "engines/wintermute/base/particles/part_emitter.h" +#include "engines/wintermute/base/scriptables/script_engine.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/ui/ui_entity.h" +#include "engines/wintermute/ui/ui_window.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/video/video_player.h" +#include "engines/wintermute/video/video_theora_player.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdGame, true) + +////////////////////////////////////////////////////////////////////////// +CAdGame::CAdGame(): CBGame() { + _responseBox = NULL; + _inventoryBox = NULL; + + _scene = new CAdScene(_gameRef); + _scene->setName(""); + registerObject(_scene); + + _prevSceneName = NULL; + _prevSceneFilename = NULL; + _scheduledScene = NULL; + _scheduledFadeIn = false; + + + _stateEx = GAME_NORMAL; + + _selectedItem = NULL; + + + _texItemLifeTime = 10000; + _texWalkLifeTime = 10000; + _texStandLifeTime = 10000; + _texTalkLifeTime = 10000; + + _talkSkipButton = TALK_SKIP_LEFT; + + _sceneViewport = NULL; + + _initialScene = true; + _debugStartupScene = NULL; + _startupScene = NULL; + + _invObject = new CAdObject(this); + _inventoryOwner = _invObject; + + _tempDisableSaveState = false; + _itemsFile = NULL; + + _smartItemCursor = false; + + addSpeechDir("speech"); +} + + +////////////////////////////////////////////////////////////////////////// +CAdGame::~CAdGame() { + cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::cleanup() { + int i; + + for (i = 0; i < _objects.getSize(); i++) { + unregisterObject(_objects[i]); + _objects[i] = NULL; + } + _objects.removeAll(); + + + for (i = 0; i < _dlgPendingBranches.getSize(); i++) { + delete [] _dlgPendingBranches[i]; + } + _dlgPendingBranches.removeAll(); + + for (i = 0; i < _speechDirs.getSize(); i++) { + delete [] _speechDirs[i]; + } + _speechDirs.removeAll(); + + + unregisterObject(_scene); + _scene = NULL; + + // remove items + for (i = 0; i < _items.getSize(); i++) _gameRef->unregisterObject(_items[i]); + _items.removeAll(); + + + // clear remaining inventories + delete _invObject; + _invObject = NULL; + + for (i = 0; i < _inventories.getSize(); i++) { + delete _inventories[i]; + } + _inventories.removeAll(); + + + if (_responseBox) { + _gameRef->unregisterObject(_responseBox); + _responseBox = NULL; + } + + if (_inventoryBox) { + _gameRef->unregisterObject(_inventoryBox); + _inventoryBox = NULL; + } + + delete[] _prevSceneName; + delete[] _prevSceneFilename; + delete[] _scheduledScene; + delete[] _debugStartupScene; + delete[] _itemsFile; + _prevSceneName = NULL; + _prevSceneFilename = NULL; + _scheduledScene = NULL; + _debugStartupScene = NULL; + _startupScene = NULL; + _itemsFile = NULL; + + delete _sceneViewport; + _sceneViewport = NULL; + + for (i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; + _sceneStates.removeAll(); + + for (i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + _responsesBranch.removeAll(); + + for (i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; + _responsesGame.removeAll(); + + return CBGame::cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::initLoop() { + if (_scheduledScene && _transMgr->isReady()) { + changeScene(_scheduledScene, _scheduledFadeIn); + delete[] _scheduledScene; + _scheduledScene = NULL; + + _gameRef->_activeObject = NULL; + } + + + bool res; + res = CBGame::initLoop(); + if (DID_FAIL(res)) return res; + + if (_scene) res = _scene->initLoop(); + + _sentences.removeAll(); + + return res; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addObject(CAdObject *object) { + _objects.add(object); + return registerObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::removeObject(CAdObject *object) { + // in case the user called Scene.CreateXXX() and Game.DeleteXXX() + if (_scene) { + bool Res = _scene->removeObject(object); + if (DID_SUCCEED(Res)) return Res; + } + + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i] == object) { + _objects.removeAt(i); + break; + } + } + return unregisterObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::changeScene(const char *filename, bool fadeIn) { + if (_scene == NULL) { + _scene = new CAdScene(_gameRef); + registerObject(_scene); + } else { + _scene->applyEvent("SceneShutdown", true); + + setPrevSceneName(_scene->_name); + setPrevSceneFilename(_scene->_filename); + + if (!_tempDisableSaveState) _scene->saveState(); + _tempDisableSaveState = false; + } + + if (_scene) { + // reset objects + for (int i = 0; i < _objects.getSize(); i++) _objects[i]->reset(); + + // reset scene properties + _scene->_sFXVolume = 100; + if (_scene->_scProp) _scene->_scProp->cleanup(); + + bool ret; + if (_initialScene && _debugDebugMode && _debugStartupScene) { + _initialScene = false; + ret = _scene->loadFile(_debugStartupScene); + } else ret = _scene->loadFile(filename); + + if (DID_SUCCEED(ret)) { + // invalidate references to the original scene + for (int i = 0; i < _objects.getSize(); i++) { + _objects[i]->invalidateCurrRegions(); + _objects[i]->_stickRegion = NULL; + } + + _scene->loadState(); + } + if (fadeIn) _gameRef->_transMgr->start(TRANSITION_FADE_IN); + return ret; + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdGame::addSentence(CAdSentence *sentence) { + _sentences.add(sentence); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::displaySentences(bool frozen) { + for (int i = 0; i < _sentences.getSize(); i++) { + if (frozen && _sentences[i]->_freezable) continue; + else _sentences[i]->display(); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdGame::finishSentences() { + for (int i = 0; i < _sentences.getSize(); i++) { + if (_sentences[i]->CanSkip()) { + _sentences[i]->_duration = 0; + if (_sentences[i]->_sound) _sentences[i]->_sound->stop(); + } + } +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // ChangeScene + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "ChangeScene") == 0) { + stack->correctParams(3); + const char *filename = stack->pop()->getString(); + CScValue *valFadeOut = stack->pop(); + CScValue *valFadeIn = stack->pop(); + + bool transOut = valFadeOut->isNULL() ? true : valFadeOut->getBool(); + bool transIn = valFadeIn->isNULL() ? true : valFadeIn->getBool(); + + scheduleChangeScene(filename, transIn); + if (transOut) _transMgr->start(TRANSITION_FADE_OUT, true); + stack->pushNULL(); + + + //bool ret = ChangeScene(stack->pop()->getString()); + //if(DID_FAIL(ret)) stack->pushBool(false); + //else stack->pushBool(true); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadActor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadActor") == 0) { + stack->correctParams(1); + CAdActor *act = new CAdActor(_gameRef); + if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { + addObject(act); + stack->pushNative(act, true); + } else { + delete act; + act = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadEntity") == 0) { + stack->correctParams(1); + CAdEntity *ent = new CAdEntity(_gameRef); + if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { + addObject(ent); + stack->pushNative(ent, true); + } else { + delete ent; + ent = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadObject / UnloadActor / UnloadEntity / DeleteEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "DeleteEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + CAdObject *obj = (CAdObject *)val->getNative(); + removeObject(obj); + if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdEntity *ent = new CAdEntity(_gameRef); + addObject(ent); + if (!val->isNULL()) ent->setName(val->getString()); + stack->pushNative(ent, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateItem") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdItem *item = new CAdItem(_gameRef); + addItem(item); + if (!val->isNULL()) item->setName(val->getString()); + stack->pushNative(item, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteItem") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdItem *item = NULL; + if (val->isNative()) item = (CAdItem *)val->getNative(); + else item = getItemByName(val->getString()); + + if (item) { + deleteItem(item); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // QueryItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "QueryItem") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdItem *item = NULL; + if (val->isInt()) { + int index = val->getInt(); + if (index >= 0 && index < _items.getSize()) item = _items[index]; + } else { + item = getItemByName(val->getString()); + } + + if (item) stack->pushNative(item, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // AddResponse/AddResponseOnce/AddResponseOnceGame + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddResponse") == 0 || strcmp(name, "AddResponseOnce") == 0 || strcmp(name, "AddResponseOnceGame") == 0) { + stack->correctParams(6); + int id = stack->pop()->getInt(); + const char *text = stack->pop()->getString(); + CScValue *val1 = stack->pop(); + CScValue *val2 = stack->pop(); + CScValue *val3 = stack->pop(); + CScValue *val4 = stack->pop(); + + if (_responseBox) { + CAdResponse *res = new CAdResponse(_gameRef); + if (res) { + res->_iD = id; + res->setText(text); + _stringTable->expand(&res->_text); + if (!val1->isNULL()) res->setIcon(val1->getString()); + if (!val2->isNULL()) res->setIconHover(val2->getString()); + if (!val3->isNULL()) res->setIconPressed(val3->getString()); + if (!val4->isNULL()) res->setFont(val4->getString()); + + if (strcmp(name, "AddResponseOnce") == 0) res->_responseType = RESPONSE_ONCE; + else if (strcmp(name, "AddResponseOnceGame") == 0) res->_responseType = RESPONSE_ONCE_GAME; + + _responseBox->_responses.add(res); + } + } else { + script->runtimeError("Game.AddResponse: response box is not defined"); + } + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ResetResponse + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResetResponse") == 0) { + stack->correctParams(1); + int ID = stack->pop()->getInt(-1); + resetResponse(ID); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ClearResponses + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ClearResponses") == 0) { + stack->correctParams(0); + _responseBox->clearResponses(); + _responseBox->clearButtons(); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetResponse + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetResponse") == 0) { + stack->correctParams(1); + bool autoSelectLast = stack->pop()->getBool(); + + if (_responseBox) { + _responseBox->weedResponses(); + + if (_responseBox->_responses.getSize() == 0) { + stack->pushNULL(); + return STATUS_OK; + } + + + if (_responseBox->_responses.getSize() == 1 && autoSelectLast) { + stack->pushInt(_responseBox->_responses[0]->_iD); + _responseBox->handleResponse(_responseBox->_responses[0]); + _responseBox->clearResponses(); + return STATUS_OK; + } + + _responseBox->createButtons(); + _responseBox->_waitingScript = script; + script->waitForExclusive(_responseBox); + _state = GAME_SEMI_FROZEN; + _stateEx = GAME_WAITING_RESPONSE; + } else { + script->runtimeError("Game.GetResponse: response box is not defined"); + stack->pushNULL(); + } + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // GetNumResponses + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNumResponses") == 0) { + stack->correctParams(0); + if (_responseBox) { + _responseBox->weedResponses(); + stack->pushInt(_responseBox->_responses.getSize()); + } else { + script->runtimeError("Game.GetNumResponses: response box is not defined"); + stack->pushNULL(); + } + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // StartDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartDlgBranch") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + Common::String branchName; + if (val->isNULL()) { + branchName.format("line%d", script->_currentLine); + } else branchName = val->getString(); + + startDlgBranch(branchName.c_str(), script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // EndDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "EndDlgBranch") == 0) { + stack->correctParams(1); + + const char *branchName = NULL; + CScValue *val = stack->pop(); + if (!val->isNULL()) branchName = val->getString(); + endDlgBranch(branchName, script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); + + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetCurrentDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetCurrentDlgBranch") == 0) { + stack->correctParams(0); + + if (_dlgPendingBranches.getSize() > 0) { + stack->pushString(_dlgPendingBranches[_dlgPendingBranches.getSize() - 1]); + } else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TakeItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TakeItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // DropItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DropItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // GetItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // HasItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // IsItemTaken + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsItemTaken") == 0) { + stack->correctParams(1); + + CScValue *val = stack->pop(); + if (!val->isNULL()) { + for (int i = 0; i < _inventories.getSize(); i++) { + CAdInventory *Inv = _inventories[i]; + + for (int j = 0; j < Inv->_takenItems.getSize(); j++) { + if (val->getNative() == Inv->_takenItems[j]) { + stack->pushBool(true); + return STATUS_OK; + } else if (scumm_stricmp(val->getString(), Inv->_takenItems[j]->_name) == 0) { + stack->pushBool(true); + return STATUS_OK; + } + } + } + } else script->runtimeError("Game.IsItemTaken: item name expected"); + + stack->pushBool(false); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetInventoryWindow + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetInventoryWindow") == 0) { + stack->correctParams(0); + if (_inventoryBox && _inventoryBox->_window) + stack->pushNative(_inventoryBox->_window, true); + else + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetResponsesWindow + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetResponsesWindow") == 0 || strcmp(name, "GetResponseWindow") == 0) { + stack->correctParams(0); + if (_responseBox && _responseBox->_window) + stack->pushNative(_responseBox->_window, true); + else + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadResponseBox + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadResponseBox") == 0) { + stack->correctParams(1); + const char *filename = stack->pop()->getString(); + + _gameRef->unregisterObject(_responseBox); + _responseBox = new CAdResponseBox(_gameRef); + if (_responseBox && !DID_FAIL(_responseBox->loadFile(filename))) { + registerObject(_responseBox); + stack->pushBool(true); + } else { + delete _responseBox; + _responseBox = NULL; + stack->pushBool(false); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadInventoryBox + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadInventoryBox") == 0) { + stack->correctParams(1); + const char *filename = stack->pop()->getString(); + + _gameRef->unregisterObject(_inventoryBox); + _inventoryBox = new CAdInventoryBox(_gameRef); + if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile(filename))) { + registerObject(_inventoryBox); + stack->pushBool(true); + } else { + delete _inventoryBox; + _inventoryBox = NULL; + stack->pushBool(false); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadItems") == 0) { + stack->correctParams(2); + const char *filename = stack->pop()->getString(); + bool merge = stack->pop()->getBool(false); + + bool ret = loadItemsFile(filename, merge); + stack->pushBool(DID_SUCCEED(ret)); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddSpeechDir + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddSpeechDir") == 0) { + stack->correctParams(1); + const char *dir = stack->pop()->getString(); + stack->pushBool(DID_SUCCEED(addSpeechDir(dir))); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveSpeechDir + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveSpeechDir") == 0) { + stack->correctParams(1); + const char *dir = stack->pop()->getString(); + stack->pushBool(DID_SUCCEED(removeSpeechDir(dir))); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetSceneViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetSceneViewport") == 0) { + stack->correctParams(4); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + int width = stack->pop()->getInt(); + int height = stack->pop()->getInt(); + + if (width <= 0) width = _renderer->_width; + if (height <= 0) height = _renderer->_height; + + if (!_sceneViewport) _sceneViewport = new CBViewport(_gameRef); + if (_sceneViewport) _sceneViewport->setRect(x, y, x + width, y + height); + + stack->pushBool(true); + + return STATUS_OK; + } + + + else return CBGame::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdGame::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("game"); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // Scene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scene") == 0) { + if (_scene) _scValue->setNative(_scene, true); + else _scValue->setNULL(); + + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // SelectedItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SelectedItem") == 0) { + //if(_selectedItem) _scValue->setString(_selectedItem->_name); + if (_selectedItem) _scValue->setNative(_selectedItem, true); + else _scValue->setNULL(); + + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // NumItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumItems") == 0) { + return _invObject->scGetProperty(name); + } + + ////////////////////////////////////////////////////////////////////////// + // SmartItemCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SmartItemCursor") == 0) { + _scValue->setBool(_smartItemCursor); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryVisible + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryVisible") == 0) { + _scValue->setBool(_inventoryBox && _inventoryBox->_visible); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryScrollOffset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryScrollOffset") == 0) { + if (_inventoryBox) _scValue->setInt(_inventoryBox->_scrollOffset); + else _scValue->setInt(0); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ResponsesVisible (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResponsesVisible") == 0) { + _scValue->setBool(_stateEx == GAME_WAITING_RESPONSE); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PrevScene / PreviousScene (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PrevScene") == 0 || strcmp(name, "PreviousScene") == 0) { + if (!_prevSceneName) _scValue->setString(""); + else _scValue->setString(_prevSceneName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PrevSceneFilename / PreviousSceneFilename (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PrevSceneFilename") == 0 || strcmp(name, "PreviousSceneFilename") == 0) { + if (!_prevSceneFilename) _scValue->setString(""); + else _scValue->setString(_prevSceneFilename); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // LastResponse (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LastResponse") == 0) { + if (!_responseBox || !_responseBox->_lastResponseText) _scValue->setString(""); + else _scValue->setString(_responseBox->_lastResponseText); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // LastResponseOrig (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LastResponseOrig") == 0) { + if (!_responseBox || !_responseBox->_lastResponseTextOrig) _scValue->setString(""); + else _scValue->setString(_responseBox->_lastResponseTextOrig); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryObject") == 0) { + if (_inventoryOwner == _invObject) _scValue->setNative(this, true); + else _scValue->setNative(_inventoryOwner, true); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TotalNumItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TotalNumItems") == 0) { + _scValue->setInt(_items.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkSkipButton + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkSkipButton") == 0) { + _scValue->setInt(_talkSkipButton); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ChangingScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ChangingScene") == 0) { + _scValue->setBool(_scheduledScene != NULL); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // StartupScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartupScene") == 0) { + if (!_startupScene) _scValue->setNULL(); + else _scValue->setString(_startupScene); + return _scValue; + } + + else return CBGame::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::scSetProperty(const char *name, CScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // SelectedItem + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SelectedItem") == 0) { + if (value->isNULL()) _selectedItem = NULL; + else { + if (value->isNative()) { + _selectedItem = NULL; + for (int i = 0; i < _items.getSize(); i++) { + if (_items[i] == value->getNative()) { + _selectedItem = (CAdItem *)value->getNative(); + break; + } + } + } else { + // try to get by name + _selectedItem = getItemByName(value->getString()); + } + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SmartItemCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SmartItemCursor") == 0) { + _smartItemCursor = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryVisible + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryVisible") == 0) { + if (_inventoryBox) _inventoryBox->_visible = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryObject") == 0) { + if (_inventoryOwner && _inventoryBox) _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; + + if (value->isNULL()) _inventoryOwner = _invObject; + else { + CBObject *Obj = (CBObject *)value->getNative(); + if (Obj == this) _inventoryOwner = _invObject; + else if (_gameRef->validObject(Obj)) _inventoryOwner = (CAdObject *)Obj; + } + + if (_inventoryOwner && _inventoryBox) _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryScrollOffset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryScrollOffset") == 0) { + if (_inventoryBox) _inventoryBox->_scrollOffset = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkSkipButton + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkSkipButton") == 0) { + int Val = value->getInt(); + if (Val < 0) Val = 0; + if (Val > TALK_SKIP_NONE) Val = TALK_SKIP_NONE; + _talkSkipButton = (TTalkSkipButton)Val; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StartupScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartupScene") == 0) { + if (value == NULL) { + delete[] _startupScene; + _startupScene = NULL; + } else CBUtils::setString(&_startupScene, value->getString()); + + return STATUS_OK; + } + + else return CBGame::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name) { + CScValue *this_obj; + + ////////////////////////////////////////////////////////////////////////// + // Actor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Actor") == 0) { + stack->correctParams(0); + this_obj = thisStack->getTop(); + + this_obj->setNative(new CAdActor(_gameRef)); + stack->pushNULL(); + } + + ////////////////////////////////////////////////////////////////////////// + // Entity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Entity") == 0) { + stack->correctParams(0); + this_obj = thisStack->getTop(); + + this_obj->setNative(new CAdEntity(_gameRef)); + stack->pushNULL(); + } + + + ////////////////////////////////////////////////////////////////////////// + // call parent + else return CBGame::ExternalCall(script, stack, thisStack, name); + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::showCursor() { + if (_cursorHidden) return STATUS_OK; + + if (_selectedItem && _gameRef->_state == GAME_RUNNING && _stateEx == GAME_NORMAL && _interactive) { + if (_selectedItem->_cursorCombined) { + CBSprite *origLastCursor = _lastCursor; + CBGame::showCursor(); + _lastCursor = origLastCursor; + } + if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { + if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->_name)) + return drawCursor(_selectedItem->_cursorHover); + else + return drawCursor(_selectedItem->_cursorNormal); + } else return drawCursor(_selectedItem->_cursorNormal); + } else return CBGame::showCursor(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadFile(const char *filename) { + byte *buffer = _fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdGame::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(GAME) +TOKEN_DEF(AD_GAME) +TOKEN_DEF(RESPONSE_BOX) +TOKEN_DEF(INVENTORY_BOX) +TOKEN_DEF(ITEMS) +TOKEN_DEF(ITEM) +TOKEN_DEF(TALK_SKIP_BUTTON) +TOKEN_DEF(SCENE_VIEWPORT) +TOKEN_DEF(ENTITY_CONTAINER) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF(STARTUP_SCENE) +TOKEN_DEF(DEBUG_STARTUP_SCENE) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(GAME) + TOKEN_TABLE(AD_GAME) + TOKEN_TABLE(RESPONSE_BOX) + TOKEN_TABLE(INVENTORY_BOX) + TOKEN_TABLE(ITEMS) + TOKEN_TABLE(TALK_SKIP_BUTTON) + TOKEN_TABLE(SCENE_VIEWPORT) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE(STARTUP_SCENE) + TOKEN_TABLE(DEBUG_STARTUP_SCENE) + TOKEN_TABLE_END + + byte *params; + byte *params2; + int cmd = 1; + CBParser parser(_gameRef); + + bool itemFound = false, itemsFound = false; + + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_GAME: + if (DID_FAIL(CBGame::loadBuffer(params, false))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_AD_GAME: + while (cmd > 0 && (cmd = parser.getCommand((char **)¶ms, commands, (char **)¶ms2)) > 0) { + switch (cmd) { + case TOKEN_RESPONSE_BOX: + delete _responseBox; + _responseBox = new CAdResponseBox(_gameRef); + if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) + registerObject(_responseBox); + else { + delete _responseBox; + _responseBox = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_INVENTORY_BOX: + delete _inventoryBox; + _inventoryBox = new CAdInventoryBox(_gameRef); + if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) + registerObject(_inventoryBox); + else { + delete _inventoryBox; + _inventoryBox = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_ITEMS: + itemsFound = true; + CBUtils::setString(&_itemsFile, (char *)params2); + if (DID_FAIL(loadItemsFile(_itemsFile))) { + delete[] _itemsFile; + _itemsFile = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_TALK_SKIP_BUTTON: + if (scumm_stricmp((char *)params2, "right") == 0) _talkSkipButton = TALK_SKIP_RIGHT; + else if (scumm_stricmp((char *)params2, "both") == 0) _talkSkipButton = TALK_SKIP_BOTH; + else _talkSkipButton = TALK_SKIP_LEFT; + break; + + case TOKEN_SCENE_VIEWPORT: { + Rect32 rc; + parser.scanStr((char *)params2, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); + if (!_sceneViewport) _sceneViewport = new CBViewport(_gameRef); + if (_sceneViewport) _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params2, false); + break; + + case TOKEN_STARTUP_SCENE: + CBUtils::setString(&_startupScene, (char *)params2); + break; + + case TOKEN_DEBUG_STARTUP_SCENE: + CBUtils::setString(&_debugStartupScene, (char *)params2); + break; + } + } + break; + } + } + + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in GAME definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading GAME definition"); + return STATUS_FAILED; + } + + if (itemFound && !itemsFound) { + _gameRef->LOG(0, "**Warning** Please put the items definition to a separate file."); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::persist(CBPersistMgr *persistMgr) { + if (!persistMgr->_saving) cleanup(); + CBGame::persist(persistMgr); + + _dlgPendingBranches.persist(persistMgr); + + _inventories.persist(persistMgr); + persistMgr->transfer(TMEMBER(_inventoryBox)); + + _objects.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_prevSceneName)); + persistMgr->transfer(TMEMBER(_prevSceneFilename)); + + persistMgr->transfer(TMEMBER(_responseBox)); + _responsesBranch.persist(persistMgr); + _responsesGame.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scene)); + _sceneStates.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scheduledFadeIn)); + persistMgr->transfer(TMEMBER(_scheduledScene)); + persistMgr->transfer(TMEMBER(_selectedItem)); + persistMgr->transfer(TMEMBER_INT(_talkSkipButton)); + + _sentences.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_sceneViewport)); + persistMgr->transfer(TMEMBER_INT(_stateEx)); + persistMgr->transfer(TMEMBER(_initialScene)); + persistMgr->transfer(TMEMBER(_debugStartupScene)); + + persistMgr->transfer(TMEMBER(_invObject)); + persistMgr->transfer(TMEMBER(_inventoryOwner)); + persistMgr->transfer(TMEMBER(_tempDisableSaveState)); + _items.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_itemsFile)); + + _speechDirs.persist(persistMgr); + persistMgr->transfer(TMEMBER(_smartItemCursor)); + + if (!persistMgr->_saving) _initialScene = false; + + persistMgr->transfer(TMEMBER(_startupScene)); + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadGame(const char *filename) { + bool ret = CBGame::loadGame(filename); + if (DID_SUCCEED(ret)) CSysClassRegistry::getInstance()->enumInstances(afterLoadRegion, "CAdRegion", NULL); + return ret; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::initAfterLoad() { + CBGame::initAfterLoad(); + CSysClassRegistry::getInstance()->enumInstances(afterLoadScene, "CAdScene", NULL); + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +void CAdGame::afterLoadScene(void *scene, void *data) { + ((CAdScene *)scene)->afterLoad(); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdGame::setPrevSceneName(const char *name) { + delete[] _prevSceneName; + _prevSceneName = NULL; + if (name) { + _prevSceneName = new char[strlen(name) + 1]; + if (_prevSceneName) strcpy(_prevSceneName, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdGame::setPrevSceneFilename(const char *name) { + delete[] _prevSceneFilename; + _prevSceneFilename = NULL; + if (name) { + _prevSceneFilename = new char[strlen(name) + 1]; + if (_prevSceneFilename) strcpy(_prevSceneFilename, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::scheduleChangeScene(const char *filename, bool fadeIn) { + delete[] _scheduledScene; + _scheduledScene = NULL; + + if (_scene && !_scene->_initialized) return changeScene(filename, fadeIn); + else { + _scheduledScene = new char [strlen(filename) + 1]; + strcpy(_scheduledScene, filename); + + _scheduledFadeIn = fadeIn; + + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { + CBGame::getVersion(verMajor, verMinor, NULL, NULL); + + if (extMajor) *extMajor = 0; + if (extMinor) *extMinor = 0; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadItemsFile(const char *filename, bool merge) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdGame::LoadItemsFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + //_filename = new char [strlen(filename)+1]; + //strcpy(_filename, filename); + + if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::loadItemsBuffer(byte *buffer, bool merge) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ITEM) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (!merge) { + while (_items.getSize() > 0) deleteItem(_items[0]); + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_ITEM: { + CAdItem *item = new CAdItem(_gameRef); + if (item && !DID_FAIL(item->loadBuffer(params, false))) { + // delete item with the same name, if exists + if (merge) { + CAdItem *PrevItem = getItemByName(item->_name); + if (PrevItem) deleteItem(PrevItem); + } + addItem(item); + } else { + delete item; + item = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + } + } + + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ITEMS definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ITEMS definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSceneState *CAdGame::getSceneState(const char *filename, bool saving) { + char *filenameCor = new char[strlen(filename) + 1]; + strcpy(filenameCor, filename); + for (uint32 i = 0; i < strlen(filenameCor); i++) { + if (filenameCor[i] == '/') filenameCor[i] = '\\'; + } + + for (int i = 0; i < _sceneStates.getSize(); i++) { + if (scumm_stricmp(_sceneStates[i]->_filename, filenameCor) == 0) { + delete [] filenameCor; + return _sceneStates[i]; + } + } + + if (saving) { + CAdSceneState *ret = new CAdSceneState(_gameRef); + ret->setFilename(filenameCor); + + _sceneStates.add(ret); + + delete [] filenameCor; + return ret; + } else { + delete [] filenameCor; + return NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::windowLoadHook(CUIWindow *win, char **buffer, char **params) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ENTITY_CONTAINER) + TOKEN_TABLE_END + + int cmd = PARSERR_GENERIC; + CBParser parser(_gameRef); + + cmd = parser.getCommand(buffer, commands, params); + switch (cmd) { + case TOKEN_ENTITY_CONTAINER: { + CUIEntity *ent = new CUIEntity(_gameRef); + if (!ent || DID_FAIL(ent->loadBuffer((byte *)*params, false))) { + delete ent; + ent = NULL; + cmd = PARSERR_GENERIC; + } else { + ent->_parent = win; + win->_widgets.add(ent); + } + } + break; + } + + if (cmd == PARSERR_TOKENNOTFOUND || cmd == PARSERR_GENERIC) { + return STATUS_FAILED; + } + + return STATUS_OK; + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name) { + if (strcmp(name, "CreateEntityContainer") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CUIEntity *ent = new CUIEntity(_gameRef); + if (!val->isNULL()) ent->setName(val->getString()); + stack->pushNative(ent, true); + + ent->_parent = win; + win->_widgets.add(ent); + + return STATUS_OK; + } else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::startDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { + char *name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; + if (name) { + sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); + _dlgPendingBranches.add(name); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::endDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { + char *name = NULL; + bool deleteName = false; + if (branchName == NULL && _dlgPendingBranches.getSize() > 0) { + name = _dlgPendingBranches[_dlgPendingBranches.getSize() - 1]; + } else { + if (branchName != NULL) { + name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; + if (name) { + sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); + deleteName = true; + } + } + } + + if (name == NULL) return STATUS_OK; + + + int startIndex = -1; + for (int i = _dlgPendingBranches.getSize() - 1; i >= 0; i--) { + if (scumm_stricmp(name, _dlgPendingBranches[i]) == 0) { + startIndex = i; + break; + } + } + if (startIndex >= 0) { + for (int i = startIndex; i < _dlgPendingBranches.getSize(); i++) { + //ClearBranchResponses(_dlgPendingBranches[i]); + delete [] _dlgPendingBranches[i]; + _dlgPendingBranches[i] = NULL; + } + _dlgPendingBranches.removeAt(startIndex, _dlgPendingBranches.getSize() - startIndex); + } + + // dialogue is over, forget selected responses + if (_dlgPendingBranches.getSize() == 0) { + for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + _responsesBranch.removeAll(); + } + + if (deleteName) delete [] name; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::clearBranchResponses(char *name) { + for (int i = 0; i < _responsesBranch.getSize(); i++) { + if (scumm_stricmp(name, _responsesBranch[i]->_context) == 0) { + delete _responsesBranch[i]; + _responsesBranch.removeAt(i); + i--; + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addBranchResponse(int ID) { + if (branchResponseUsed(ID)) return STATUS_OK; + CAdResponseContext *r = new CAdResponseContext(_gameRef); + r->_iD = ID; + r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); + _responsesBranch.add(r); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::branchResponseUsed(int ID) { + char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; + for (int i = 0; i < _responsesBranch.getSize(); i++) { + if (_responsesBranch[i]->_iD == ID) { + if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) return true; + } + } + return false; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addGameResponse(int ID) { + if (gameResponseUsed(ID)) return STATUS_OK; + CAdResponseContext *r = new CAdResponseContext(_gameRef); + r->_iD = ID; + r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); + _responsesGame.add(r); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::gameResponseUsed(int ID) { + char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; + for (int i = 0; i < _responsesGame.getSize(); i++) { + CAdResponseContext *RespContext = _responsesGame[i]; + if (RespContext->_iD == ID) { + if ((Context == NULL && RespContext->_context == NULL) || ((Context != NULL && RespContext->_context != NULL) && scumm_stricmp(Context, RespContext->_context) == 0)) return true; + } + } + return false; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::resetResponse(int ID) { + char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; + + int i; + + for (i = 0; i < _responsesGame.getSize(); i++) { + if (_responsesGame[i]->_iD == ID) { + if ((Context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(Context, _responsesGame[i]->_context) == 0) { + delete _responsesGame[i]; + _responsesGame.removeAt(i); + break; + } + } + } + + for (i = 0; i < _responsesBranch.getSize(); i++) { + if (_responsesBranch[i]->_iD == ID) { + if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) { + delete _responsesBranch[i]; + _responsesBranch.removeAt(i); + break; + } + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::displayContent(bool doUpdate, bool displayAll) { + // init + if (doUpdate) initLoop(); + + // fill black + _renderer->fill(0, 0, 0); + if (!_editorMode) _renderer->setScreenViewport(); + + // playing exclusive video? + if (_videoPlayer->isPlaying()) { + if (doUpdate) _videoPlayer->update(); + _videoPlayer->display(); + } else if (_theoraPlayer) { + if (_theoraPlayer->isPlaying()) { + if (doUpdate) _theoraPlayer->update(); + _theoraPlayer->display(); + } + if (_theoraPlayer->isFinished()) { + delete _theoraPlayer; + _theoraPlayer = NULL; + } + } else { + + // process scripts + if (doUpdate) _scEngine->tick(); + + Point32 p; + getMousePos(&p); + + _scene->update(); + _scene->display(); + + + // display in-game windows + displayWindows(true); + if (_inventoryBox) _inventoryBox->display(); + if (_stateEx == GAME_WAITING_RESPONSE) _responseBox->display(); + if (_indicatorDisplay) displayIndicator(); + + + if (doUpdate || displayAll) { + // display normal windows + displayWindows(false); + + setActiveObject(_gameRef->_renderer->getObjectAt(p.x, p.y)); + + // textual info + displaySentences(_state == GAME_FROZEN); + + showCursor(); + + if (_fader) _fader->display(); + _transMgr->update(); + } + + } + if (_loadingIcon) { + _loadingIcon->display(_loadingIconX, _loadingIconY); + if (!_loadingIconPersistent) { + delete _loadingIcon; + _loadingIcon = NULL; + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::registerInventory(CAdInventory *inv) { + for (int i = 0; i < _inventories.getSize(); i++) { + if (_inventories[i] == inv) return STATUS_OK; + } + registerObject(inv); + _inventories.add(inv); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::unregisterInventory(CAdInventory *inv) { + for (int i = 0; i < _inventories.getSize(); i++) { + if (_inventories[i] == inv) { + unregisterObject(_inventories[i]); + _inventories.removeAt(i); + return STATUS_OK; + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::isItemTaken(char *itemName) { + for (int i = 0; i < _inventories.getSize(); i++) { + CAdInventory *Inv = _inventories[i]; + + for (int j = 0; j < Inv->_takenItems.getSize(); j++) { + if (scumm_stricmp(itemName, Inv->_takenItems[j]->_name) == 0) { + return true; + } + } + } + return false; +} + +////////////////////////////////////////////////////////////////////////// +CAdItem *CAdGame::getItemByName(const char *name) { + for (int i = 0; i < _items.getSize(); i++) { + if (scumm_stricmp(_items[i]->_name, name) == 0) return _items[i]; + } + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addItem(CAdItem *item) { + _items.add(item); + return _gameRef->registerObject(item); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::resetContent() { + // clear pending dialogs + for (int i = 0; i < _dlgPendingBranches.getSize(); i++) { + delete [] _dlgPendingBranches[i]; + } + _dlgPendingBranches.removeAll(); + + + // clear inventories + for (int i = 0; i < _inventories.getSize(); i++) { + _inventories[i]->_takenItems.removeAll(); + } + + // clear scene states + for (int i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; + _sceneStates.removeAll(); + + // clear once responses + for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + _responsesBranch.removeAll(); + + // clear once game responses + for (int i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; + _responsesGame.removeAll(); + + // reload inventory items + if (_itemsFile) loadItemsFile(_itemsFile); + + _tempDisableSaveState = true; + + return CBGame::resetContent(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::deleteItem(CAdItem *item) { + if (!item) return STATUS_FAILED; + + if (_selectedItem == item) _selectedItem = NULL; + _scene->handleItemAssociations(item->_name, false); + + // remove from all inventories + for (int i = 0; i < _inventories.getSize(); i++) { + _inventories[i]->removeItem(item); + } + + // remove object + for (int i = 0; i < _items.getSize(); i++) { + if (_items[i] == item) { + unregisterObject(_items[i]); + _items.removeAt(i); + break; + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::addSpeechDir(const char *dir) { + if (!dir || dir[0] == '\0') return STATUS_FAILED; + + char *temp = new char[strlen(dir) + 2]; + strcpy(temp, dir); + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') + strcat(temp, "\\"); + + for (int i = 0; i < _speechDirs.getSize(); i++) { + if (scumm_stricmp(_speechDirs[i], temp) == 0) { + delete [] temp; + return STATUS_OK; + } + } + _speechDirs.add(temp); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::removeSpeechDir(const char *dir) { + if (!dir || dir[0] == '\0') return STATUS_FAILED; + + char *temp = new char[strlen(dir) + 2]; + strcpy(temp, dir); + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') + strcat(temp, "\\"); + + bool Found = false; + for (int i = 0; i < _speechDirs.getSize(); i++) { + if (scumm_stricmp(_speechDirs[i], temp) == 0) { + delete [] _speechDirs[i]; + _speechDirs.removeAt(i); + Found = true; + break; + } + } + delete [] temp; + + if (Found) return STATUS_OK; + else return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdGame::findSpeechFile(char *stringID) { + char *ret = new char[MAX_PATH_LENGTH]; + + for (int i = 0; i < _speechDirs.getSize(); i++) { + sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); + Common::SeekableReadStream *file = _fileManager->openFile(ret); // TODO: Replace with hasFile + if (file) { + _fileManager->closeFile(file); + return ret; + } + + sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); + file = _fileManager->openFile(ret); + if (file) { + _fileManager->closeFile(file); + return ret; + } + } + delete [] ret; + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::validMouse() { + Point32 pos; + CBPlatform::getCursorPos(&pos); + + return _renderer->pointInViewport(&pos); +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseLeftDown() { + if (!validMouse()) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + if (_talkSkipButton == TALK_SKIP_LEFT || _talkSkipButton == TALK_SKIP_BOTH) { + finishSentences(); + } + return STATUS_OK; + } + + if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftClick"); + } + } + + if (_activeObject != NULL) _gameRef->_capturedObject = _gameRef->_activeObject; + _mouseLeftDown = true; + CBPlatform::setCapture(/*_renderer->_window*/); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseLeftUp() { + if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + + CBPlatform::releaseCapture(); + _capturedObject = NULL; + _mouseLeftDown = false; + + bool handled = /*_state==GAME_RUNNING &&*/ DID_SUCCEED(applyEvent("LeftRelease")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftRelease"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftRelease"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseLeftDblClick() { + if (!validMouse()) return STATUS_OK; + + if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; + + if (_activeObject) _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftDoubleClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftDoubleClick"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseRightDown() { + if (!validMouse()) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + if (_talkSkipButton == TALK_SKIP_RIGHT || _talkSkipButton == TALK_SKIP_BOTH) { + finishSentences(); + } + return STATUS_OK; + } + + if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) return STATUS_OK; + + if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("RightClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("RightClick"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onMouseRightUp() { + if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("RightRelease"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("RightRelease"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::displayDebugInfo() { + char str[100]; + if (_gameRef->_debugDebugMode) { + sprintf(str, "Mouse: %d, %d (scene: %d, %d)", _mousePos.x, _mousePos.y, _mousePos.x + _scene->getOffsetLeft(), _mousePos.y + _scene->getOffsetTop()); + _systemFont->drawText((byte *)str, 0, 90, _renderer->_width, TAL_RIGHT); + + sprintf(str, "Scene: %s (prev: %s)", (_scene && _scene->_name) ? _scene->_name : "???", _prevSceneName ? _prevSceneName : "???"); + _systemFont->drawText((byte *)str, 0, 110, _renderer->_width, TAL_RIGHT); + } + return CBGame::displayDebugInfo(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdGame::onScriptShutdown(CScScript *script) { + if (_responseBox && _responseBox->_waitingScript == script) + _responseBox->_waitingScript = NULL; + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h new file mode 100644 index 0000000000..09b3e09df0 --- /dev/null +++ b/engines/wintermute/ad/ad_game.h @@ -0,0 +1,161 @@ +/* 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. + + * 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. + + * 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 + */ +#ifndef WINTERMUTE_ADGAME_H +#define WINTERMUTE_ADGAME_H + +#include "engines/wintermute/ad/ad_types.h" +#include "engines/wintermute/base/base_game.h" + +namespace WinterMute { +class CAdItem; +class CAdInventory; +class CAdSceneState; +class CAdScene; +class CAdItem; +class CAdObject; +class CAdSentence; +class CAdInventoryBox; +class CAdResponseContext; +class CAdResponseBox; +class CAdGame : public CBGame { +public: + virtual bool onScriptShutdown(CScScript *script); + + virtual bool onMouseLeftDown(); + virtual bool onMouseLeftUp(); + virtual bool onMouseLeftDblClick(); + virtual bool onMouseRightDown(); + virtual bool onMouseRightUp(); + + virtual bool displayDebugInfo(); + + + virtual bool initAfterLoad(); + static void afterLoadScene(void *scene, void *data); + + bool _smartItemCursor; + + CBArray _speechDirs; + bool addSpeechDir(const char *dir); + bool removeSpeechDir(const char *dir); + char *findSpeechFile(char *StringID); + + bool deleteItem(CAdItem *Item); + char *_itemsFile; + bool _tempDisableSaveState; + virtual bool resetContent(); + bool addItem(CAdItem *item); + CAdItem *getItemByName(const char *name); + CBArray _items; + CAdObject *_inventoryOwner; + bool isItemTaken(char *itemName); + bool registerInventory(CAdInventory *inv); + bool unregisterInventory(CAdInventory *inv); + + CAdObject *_invObject; + CBArray _inventories; + virtual bool displayContent(bool update = true, bool displayAll = false); + char *_debugStartupScene; + char *_startupScene; + bool _initialScene; + bool gameResponseUsed(int ID); + bool addGameResponse(int ID); + bool resetResponse(int ID); + + bool branchResponseUsed(int ID); + bool addBranchResponse(int ID); + bool clearBranchResponses(char *name); + bool startDlgBranch(const char *branchName, const char *scriptName, const char *eventName); + bool endDlgBranch(const char *branchName, const char *scriptName, const char *eventName); + virtual bool windowLoadHook(CUIWindow *win, char **buf, char **params); + virtual bool windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name); + + CAdSceneState *getSceneState(const char *filename, bool saving); + CBViewport *_sceneViewport; + int _texItemLifeTime; + int _texWalkLifeTime; + int _texStandLifeTime; + int _texTalkLifeTime; + + TTalkSkipButton _talkSkipButton; + + virtual bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor); + bool scheduleChangeScene(const char *filename, bool fadeIn); + char *_scheduledScene; + bool _scheduledFadeIn; + void setPrevSceneName(const char *name); + void setPrevSceneFilename(const char *name); + char *_prevSceneName; + char *_prevSceneFilename; + virtual bool loadGame(const char *filename); + CAdItem *_selectedItem; + bool cleanup(); + DECLARE_PERSISTENT(CAdGame, CBGame) + + void finishSentences(); + bool showCursor(); + TGameStateEx _stateEx; + CAdResponseBox *_responseBox; + CAdInventoryBox *_inventoryBox; + bool displaySentences(bool frozen); + void addSentence(CAdSentence *sentence); + bool changeScene(const char *filename, bool fadeIn); + bool removeObject(CAdObject *object); + bool addObject(CAdObject *object); + CAdScene *_scene; + bool initLoop(); + CAdGame(); + virtual ~CAdGame(); + CBArray _objects; + CBArray _sentences; + + CBArray _sceneStates; + CBArray _dlgPendingBranches; + + CBArray _responsesBranch; + CBArray _responsesGame; + + virtual bool loadFile(const char *filename); + virtual bool loadBuffer(byte *buffer, bool complete = true); + + bool loadItemsFile(const char *filename, bool merge = false); + bool loadItemsBuffer(byte *buffer, bool merge = false); + + + virtual bool ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + bool validMouse(); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp new file mode 100644 index 0000000000..cfbc9e5029 --- /dev/null +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -0,0 +1,119 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_inventory.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdInventory, false) + +////////////////////////////////////////////////////////////////////////// +CAdInventory::CAdInventory(CBGame *inGame): CBObject(inGame) { + _scrollOffset = 0; +} + + +////////////////////////////////////////////////////////////////////////// +CAdInventory::~CAdInventory() { + _takenItems.removeAll(); // ref only +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventory::insertItem(const char *name, const char *insertAfter) { + if (name == NULL) return STATUS_FAILED; + + CAdItem *item = ((CAdGame *)_gameRef)->getItemByName(name); + if (item == NULL) return STATUS_FAILED; + + int insertIndex = -1; + for (int i = 0; i < _takenItems.getSize(); i++) { + if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { + _takenItems.removeAt(i); + i--; + continue; + } + if (insertAfter && scumm_stricmp(_takenItems[i]->_name, insertAfter) == 0) insertIndex = i + 1; + } + + + if (insertIndex == -1) _takenItems.add(item); + else _takenItems.insertAt(insertIndex, item); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventory::removeItem(const char *name) { + if (name == NULL) return STATUS_FAILED; + + for (int i = 0; i < _takenItems.getSize(); i++) { + if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { + if (((CAdGame *)_gameRef)->_selectedItem == _takenItems[i])((CAdGame *)_gameRef)->_selectedItem = NULL; + _takenItems.removeAt(i); + return STATUS_OK; + } + } + + return STATUS_FAILED; +} + + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventory::removeItem(CAdItem *item) { + if (item == NULL) return STATUS_FAILED; + + for (int i = 0; i < _takenItems.getSize(); i++) { + if (_takenItems[i] == item) { + if (((CAdGame *)_gameRef)->_selectedItem == _takenItems[i])((CAdGame *)_gameRef)->_selectedItem = NULL; + _takenItems.removeAt(i); + return STATUS_OK; + } + } + + return STATUS_FAILED; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdInventory::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + _takenItems.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollOffset)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_inventory.h b/engines/wintermute/ad/ad_inventory.h new file mode 100644 index 0000000000..84d9308d5d --- /dev/null +++ b/engines/wintermute/ad/ad_inventory.h @@ -0,0 +1,52 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADINVENTORY_H +#define WINTERMUTE_ADINVENTORY_H + +#include "engines/wintermute/base/base_object.h" + +namespace WinterMute { + +class CAdItem; + +class CAdInventory : public CBObject { +public: + DECLARE_PERSISTENT(CAdInventory, CBObject) + bool removeItem(const char *name); + bool removeItem(CAdItem *Item); + bool insertItem(const char *name, const char *insertAfter = NULL); + CAdInventory(CBGame *inGame); + virtual ~CAdInventory(); + CBArray _takenItems; + int _scrollOffset; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp new file mode 100644 index 0000000000..abe8676376 --- /dev/null +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -0,0 +1,372 @@ +/* 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. + + * 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. + + * 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 + */ +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_inventory_box.h" +#include "engines/wintermute/ad/ad_inventory.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_viewport.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/ui/ui_button.h" +#include "engines/wintermute/ui/ui_window.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" +#include "common/rect.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdInventoryBox, false) + +////////////////////////////////////////////////////////////////////////// +CAdInventoryBox::CAdInventoryBox(CBGame *inGame): CBObject(inGame) { + _itemsArea.setEmpty(); + _scrollOffset = 0; + _spacing = 0; + _itemWidth = _itemHeight = 50; + _scrollBy = 1; + + _window = NULL; + _closeButton = NULL; + + _hideSelected = false; + + _visible = false; + _exclusive = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdInventoryBox::~CAdInventoryBox() { + _gameRef->unregisterObject(_window); + _window = NULL; + + delete _closeButton; + _closeButton = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::listen(CBScriptHolder *param1, uint32 param2) { + CUIObject *obj = (CUIObject *)param1; + + switch (obj->_type) { + case UI_BUTTON: + if (scumm_stricmp(obj->_name, "close") == 0) { + _visible = false; + } else if (scumm_stricmp(obj->_name, "prev") == 0) { + _scrollOffset -= _scrollBy; + _scrollOffset = MAX(_scrollOffset, 0); + } else if (scumm_stricmp(obj->_name, "next") == 0) { + _scrollOffset += _scrollBy; + } else return CBObject::listen(param1, param2); + break; + default: + error("CAdInventoryBox::Listen - Unhandled enum"); + break; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::display() { + CAdGame *adGame = (CAdGame *)_gameRef; + + if (!_visible) return STATUS_OK; + + int itemsX, itemsY; + itemsX = (int)floor((float)((_itemsArea.right - _itemsArea.left + _spacing) / (_itemWidth + _spacing))); + itemsY = (int)floor((float)((_itemsArea.bottom - _itemsArea.top + _spacing) / (_itemHeight + _spacing))); + + if (_window) { + _window->enableWidget("prev", _scrollOffset > 0); + _window->enableWidget("next", _scrollOffset + itemsX * itemsY < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()); + } + + + if (_closeButton) { + _closeButton->_posX = _closeButton->_posY = 0; + _closeButton->_width = _gameRef->_renderer->_width; + _closeButton->_height = _gameRef->_renderer->_height; + + _closeButton->display(); + } + + + // display window + Rect32 rect = _itemsArea; + if (_window) { + rect.offsetRect(_window->_posX, _window->_posY); + _window->display(); + } + + // display items + if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; + int yyy = rect.top; + for (int j = 0; j < itemsY; j++) { + int xxx = rect.left; + for (int i = 0; i < itemsX; i++) { + int itemIndex = _scrollOffset + j * itemsX + i; + if (itemIndex >= 0 && itemIndex < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()) { + CAdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex]; + if (item != ((CAdGame *)_gameRef)->_selectedItem || !_hideSelected) { + item->update(); + item->display(xxx, yyy); + } + } + + xxx += (_itemWidth + _spacing); + } + yyy += (_itemHeight + _spacing); + } + if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = 0; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdInventoryBox::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(INVENTORY_BOX) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(WINDOW) +TOKEN_DEF(EXCLUSIVE) +TOKEN_DEF(ALWAYS_VISIBLE) +TOKEN_DEF(AREA) +TOKEN_DEF(SPACING) +TOKEN_DEF(ITEM_WIDTH) +TOKEN_DEF(ITEM_HEIGHT) +TOKEN_DEF(SCROLL_BY) +TOKEN_DEF(NAME) +TOKEN_DEF(CAPTION) +TOKEN_DEF(HIDE_SELECTED) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(INVENTORY_BOX) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(WINDOW) + TOKEN_TABLE(EXCLUSIVE) + TOKEN_TABLE(ALWAYS_VISIBLE) + TOKEN_TABLE(AREA) + TOKEN_TABLE(SPACING) + TOKEN_TABLE(ITEM_WIDTH) + TOKEN_TABLE(ITEM_HEIGHT) + TOKEN_TABLE(SCROLL_BY) + TOKEN_TABLE(NAME) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(HIDE_SELECTED) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd = 2; + CBParser parser(_gameRef); + bool always_visible = false; + + _exclusive = false; + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_INVENTORY_BOX) { + _gameRef->LOG(0, "'INVENTORY_BOX' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_WINDOW: + delete _window; + _window = new CUIWindow(_gameRef); + if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { + delete _window; + _window = NULL; + cmd = PARSERR_GENERIC; + } else _gameRef->registerObject(_window); + break; + + case TOKEN_AREA: + parser.scanStr((char *)params, "%d,%d,%d,%d", &_itemsArea.left, &_itemsArea.top, &_itemsArea.right, &_itemsArea.bottom); + break; + + case TOKEN_EXCLUSIVE: + parser.scanStr((char *)params, "%b", &_exclusive); + break; + + case TOKEN_HIDE_SELECTED: + parser.scanStr((char *)params, "%b", &_hideSelected); + break; + + case TOKEN_ALWAYS_VISIBLE: + parser.scanStr((char *)params, "%b", &always_visible); + break; + + case TOKEN_SPACING: + parser.scanStr((char *)params, "%d", &_spacing); + break; + + case TOKEN_ITEM_WIDTH: + parser.scanStr((char *)params, "%d", &_itemWidth); + break; + + case TOKEN_ITEM_HEIGHT: + parser.scanStr((char *)params, "%d", &_itemHeight); + break; + + case TOKEN_SCROLL_BY: + parser.scanStr((char *)params, "%d", &_scrollBy); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in INVENTORY_BOX definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading INVENTORY_BOX definition"); + return STATUS_FAILED; + } + + if (_exclusive) { + delete _closeButton; + _closeButton = new CUIButton(_gameRef); + if (_closeButton) { + _closeButton->setName("close"); + _closeButton->setListener(this, _closeButton, 0); + _closeButton->_parent = _window; + } + } + + _visible = always_visible; + + if (_window) { + for (int i = 0; i < _window->_widgets.getSize(); i++) { + if (!_window->_widgets[i]->_listenerObject) + _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "INVENTORY_BOX\n"); + buffer->putTextIndent(indent, "{\n"); + + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + + buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _itemsArea.left, _itemsArea.top, _itemsArea.right, _itemsArea.bottom); + + buffer->putTextIndent(indent + 2, "EXCLUSIVE=%s\n", _exclusive ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "HIDE_SELECTED=%s\n", _hideSelected ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "ALWAYS_VISIBLE=%s\n", _visible ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); + buffer->putTextIndent(indent + 2, "ITEM_WIDTH=%d\n", _itemWidth); + buffer->putTextIndent(indent + 2, "ITEM_HEIGHT=%d\n", _itemHeight); + buffer->putTextIndent(indent + 2, "SCROLL_BY=%d\n", _scrollBy); + + buffer->putTextIndent(indent + 2, "\n"); + + // window + if (_window) _window->saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent + 2, "\n"); + + // editor properties + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdInventoryBox::persist(CBPersistMgr *persistMgr) { + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_closeButton)); + persistMgr->transfer(TMEMBER(_hideSelected)); + persistMgr->transfer(TMEMBER(_itemHeight)); + persistMgr->transfer(TMEMBER(_itemsArea)); + persistMgr->transfer(TMEMBER(_itemWidth)); + persistMgr->transfer(TMEMBER(_scrollBy)); + persistMgr->transfer(TMEMBER(_scrollOffset)); + persistMgr->transfer(TMEMBER(_spacing)); + persistMgr->transfer(TMEMBER(_visible)); + persistMgr->transfer(TMEMBER(_window)); + persistMgr->transfer(TMEMBER(_exclusive)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_inventory_box.h b/engines/wintermute/ad/ad_inventory_box.h new file mode 100644 index 0000000000..09d3ef409e --- /dev/null +++ b/engines/wintermute/ad/ad_inventory_box.h @@ -0,0 +1,64 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADINVENTORYBOX_H +#define WINTERMUTE_ADINVENTORYBOX_H + +#include "engines/wintermute/base/base_object.h" +#include "common/rect.h" + +namespace WinterMute { +class CUIButton; +class CUIWindow; + +class CAdInventoryBox : public CBObject { +public: + bool _hideSelected; + DECLARE_PERSISTENT(CAdInventoryBox, CBObject) + bool _exclusive; + int _scrollBy; + int _itemHeight; + int _itemWidth; + bool _visible; + virtual bool display(); + CUIButton *_closeButton; + int _spacing; + int _scrollOffset; + Rect32 _itemsArea; + bool listen(CBScriptHolder *param1, uint32 param2); + CUIWindow *_window; + CAdInventoryBox(CBGame *inGame); + virtual ~CAdInventoryBox(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp new file mode 100644 index 0000000000..9c49a86bcb --- /dev/null +++ b/engines/wintermute/ad/ad_item.cpp @@ -0,0 +1,760 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdItem, false) + +////////////////////////////////////////////////////////////////////////// +CAdItem::CAdItem(CBGame *inGame): CAdTalkHolder(inGame) { + _spriteHover = NULL; + _cursorNormal = _cursorHover = NULL; + + _cursorCombined = true; + _inInventory = false; + + _displayAmount = false; + _amount = 0; + _amountOffsetX = 0; + _amountOffsetY = 0; + _amountAlign = TAL_RIGHT; + _amountString = NULL; + + _state = STATE_READY; + + _movable = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdItem::~CAdItem() { + delete _spriteHover; + delete _cursorNormal; + delete _cursorHover; + _spriteHover = NULL; + _cursorNormal = NULL; + _cursorHover = NULL; + + delete[] _amountString; + _amountString = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdItem::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ITEM) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(CURSOR_HOVER) +TOKEN_DEF(CURSOR_COMBINED) +TOKEN_DEF(CURSOR) +TOKEN_DEF(NAME) +TOKEN_DEF(IMAGE_HOVER) +TOKEN_DEF(IMAGE) +TOKEN_DEF(EVENTS) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF(FONT) +TOKEN_DEF(ALPHA_COLOR) +TOKEN_DEF(ALPHA) +TOKEN_DEF(TALK_SPECIAL) +TOKEN_DEF(TALK) +TOKEN_DEF(SPRITE_HOVER) +TOKEN_DEF(SPRITE) +TOKEN_DEF(DISPLAY_AMOUNT) +TOKEN_DEF(AMOUNT_OFFSET_X) +TOKEN_DEF(AMOUNT_OFFSET_Y) +TOKEN_DEF(AMOUNT_ALIGN) +TOKEN_DEF(AMOUNT_STRING) +TOKEN_DEF(AMOUNT) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdItem::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ITEM) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(CURSOR_HOVER) + TOKEN_TABLE(CURSOR_COMBINED) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(NAME) + TOKEN_TABLE(IMAGE_HOVER) + TOKEN_TABLE(IMAGE) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE(FONT) + TOKEN_TABLE(ALPHA_COLOR) + TOKEN_TABLE(ALPHA) + TOKEN_TABLE(TALK_SPECIAL) + TOKEN_TABLE(TALK) + TOKEN_TABLE(SPRITE_HOVER) + TOKEN_TABLE(SPRITE) + TOKEN_TABLE(DISPLAY_AMOUNT) + TOKEN_TABLE(AMOUNT_OFFSET_X) + TOKEN_TABLE(AMOUNT_OFFSET_Y) + TOKEN_TABLE(AMOUNT_ALIGN) + TOKEN_TABLE(AMOUNT_STRING) + TOKEN_TABLE(AMOUNT) + TOKEN_TABLE_END + + byte *params; + int cmd = 2; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ITEM) { + _gameRef->LOG(0, "'ITEM' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + int ar = 0, ag = 0, ab = 0, alpha = 255; + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_FONT: + SetFont((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_IMAGE: + case TOKEN_SPRITE: + delete _sprite; + _sprite = new CBSprite(_gameRef, this); + if (!_sprite || DID_FAIL(_sprite->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + delete _sprite; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_IMAGE_HOVER: + case TOKEN_SPRITE_HOVER: + delete _spriteHover; + _spriteHover = new CBSprite(_gameRef, this); + if (!_spriteHover || DID_FAIL(_spriteHover->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + delete _spriteHover; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_AMOUNT: + parser.scanStr((char *)params, "%d", &_amount); + break; + + case TOKEN_DISPLAY_AMOUNT: + parser.scanStr((char *)params, "%b", &_displayAmount); + break; + + case TOKEN_AMOUNT_OFFSET_X: + parser.scanStr((char *)params, "%d", &_amountOffsetX); + break; + + case TOKEN_AMOUNT_OFFSET_Y: + parser.scanStr((char *)params, "%d", &_amountOffsetY); + break; + + case TOKEN_AMOUNT_ALIGN: + if (scumm_stricmp((char *)params, "left") == 0) _amountAlign = TAL_LEFT; + else if (scumm_stricmp((char *)params, "right") == 0) _amountAlign = TAL_RIGHT; + else _amountAlign = TAL_CENTER; + break; + + case TOKEN_AMOUNT_STRING: + CBUtils::setString(&_amountString, (char *)params); + break; + + case TOKEN_TALK: { + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((CAdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSprites.add(spr); + } + break; + + case TOKEN_TALK_SPECIAL: { + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((CAdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + else _talkSpritesEx.add(spr); + } + break; + + case TOKEN_CURSOR: + delete _cursorNormal; + _cursorNormal = new CBSprite(_gameRef); + if (!_cursorNormal || DID_FAIL(_cursorNormal->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + delete _cursorNormal; + _cursorNormal = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CURSOR_HOVER: + delete _cursorHover; + _cursorHover = new CBSprite(_gameRef); + if (!_cursorHover || DID_FAIL(_cursorHover->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + delete _cursorHover; + _cursorHover = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CURSOR_COMBINED: + parser.scanStr((char *)params, "%b", &_cursorCombined); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + 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; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ITEM definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ITEM definition"); + return STATUS_FAILED; + } + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::update() { + _currentSprite = NULL; + + if (_state == STATE_READY && _animSprite) { + delete _animSprite; + _animSprite = NULL; + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = STATE_READY; + _currentSprite = _animSprite; + } + + if (_sentence && _state != STATE_TALKING) _sentence->finish(); + + // default: stand animation + if (!_currentSprite) _currentSprite = _sprite; + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite) { + if (_gameRef->_activeObject == this && _spriteHover) _currentSprite = _spriteHover; + else _currentSprite = _sprite; + } + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(); + if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + + bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { + if (TimeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + } + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } else { + _currentSprite = _tempSprite2; + ((CAdGame *)_gameRef)->addSentence(_sentence); + } + } + default: + break; + } + _ready = (_state == STATE_READY); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::display(int x, int y) { + int width = 0; + if (_currentSprite) { + Rect32 rc; + _currentSprite->getBoundingRect(&rc, 0, 0); + width = rc.width(); + } + + _posX = x + width / 2; + _posY = y; + + bool ret; + if (_currentSprite) + ret = _currentSprite->draw(x, y, this, 100, 100, _alphaColor); + else ret = STATUS_OK; + + if (_displayAmount) { + int amountX = x; + int amountY = y + _amountOffsetY; + + if (_amountAlign == TAL_RIGHT) { + width -= _amountOffsetX; + amountX -= _amountOffsetX; + } + amountX += _amountOffsetX; + + CBFont *font = _font ? _font : _gameRef->_systemFont; + if (font) { + if (_amountString) font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); + else { + char Str[256]; + sprintf(Str, "%d", _amount); + font->drawText((byte *)Str, amountX, amountY, width, _amountAlign); + } + } + } + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdItem::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // SetHoverSprite + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetHoverSprite") == 0) { + stack->correctParams(1); + + bool setCurrent = false; + if (_currentSprite && _currentSprite == _spriteHover) setCurrent = true; + + const char *filename = stack->pop()->getString(); + + delete _spriteHover; + _spriteHover = NULL; + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetHoverSprite failed for file '%s'", filename); + } else { + _spriteHover = spr; + if (setCurrent) _currentSprite = _spriteHover; + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverSprite") == 0) { + stack->correctParams(0); + + if (!_spriteHover || !_spriteHover->_filename) stack->pushNULL(); + else stack->pushString(_spriteHover->_filename); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverSpriteObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverSpriteObject") == 0) { + stack->correctParams(0); + if (!_spriteHover) stack->pushNULL(); + else stack->pushNative(_spriteHover, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetNormalCursor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetNormalCursor") == 0) { + stack->correctParams(1); + + const char *filename = stack->pop()->getString(); + + delete _cursorNormal; + _cursorNormal = NULL; + CBSprite *spr = new CBSprite(_gameRef); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetNormalCursor failed for file '%s'", filename); + } else { + _cursorNormal = spr; + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNormalCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNormalCursor") == 0) { + stack->correctParams(0); + + if (!_cursorNormal || !_cursorNormal->_filename) stack->pushNULL(); + else stack->pushString(_cursorNormal->_filename); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNormalCursorObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNormalCursorObject") == 0) { + stack->correctParams(0); + + if (!_cursorNormal) stack->pushNULL(); + else stack->pushNative(_cursorNormal, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetHoverCursor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetHoverCursor") == 0) { + stack->correctParams(1); + + const char *filename = stack->pop()->getString(); + + delete _cursorHover; + _cursorHover = NULL; + CBSprite *spr = new CBSprite(_gameRef); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetHoverCursor failed for file '%s'", filename); + } else { + _cursorHover = spr; + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverCursor") == 0) { + stack->correctParams(0); + + if (!_cursorHover || !_cursorHover->_filename) stack->pushNULL(); + else stack->pushString(_cursorHover->_filename); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverCursorObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverCursorObject") == 0) { + stack->correctParams(0); + + if (!_cursorHover) stack->pushNULL(); + else stack->pushNative(_cursorHover, true); + return STATUS_OK; + } + + else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdItem::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("item"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Name") == 0) { + _scValue->setString(_name); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // DisplayAmount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DisplayAmount") == 0) { + _scValue->setBool(_displayAmount); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Amount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Amount") == 0) { + _scValue->setInt(_amount); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetX") == 0) { + _scValue->setInt(_amountOffsetX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetY") == 0) { + _scValue->setInt(_amountOffsetY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountAlign + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountAlign") == 0) { + _scValue->setInt(_amountAlign); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountString + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountString") == 0) { + if (!_amountString) _scValue->setNULL(); + else _scValue->setString(_amountString); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // CursorCombined + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CursorCombined") == 0) { + _scValue->setBool(_cursorCombined); + return _scValue; + } + + else return CAdTalkHolder::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DisplayAmount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DisplayAmount") == 0) { + _displayAmount = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Amount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Amount") == 0) { + _amount = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetX") == 0) { + _amountOffsetX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetY") == 0) { + _amountOffsetY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountAlign + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountAlign") == 0) { + _amountAlign = (TTextAlign)value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountString + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountString") == 0) { + if (value->isNULL()) { + delete[] _amountString; + _amountString = NULL; + } else { + CBUtils::setString(&_amountString, value->getString()); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CursorCombined + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CursorCombined") == 0) { + _cursorCombined = value->getBool(); + return STATUS_OK; + } + + else return CAdTalkHolder::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdItem::scToString() { + return "[item]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::persist(CBPersistMgr *persistMgr) { + + CAdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_cursorCombined)); + persistMgr->transfer(TMEMBER(_cursorHover)); + persistMgr->transfer(TMEMBER(_cursorNormal)); + persistMgr->transfer(TMEMBER(_spriteHover)); + persistMgr->transfer(TMEMBER(_inInventory)); + persistMgr->transfer(TMEMBER(_displayAmount)); + persistMgr->transfer(TMEMBER(_amount)); + persistMgr->transfer(TMEMBER(_amountOffsetX)); + persistMgr->transfer(TMEMBER(_amountOffsetY)); + persistMgr->transfer(TMEMBER_INT(_amountAlign)); + persistMgr->transfer(TMEMBER(_amountString)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdItem::getExtendedFlag(const char *flagName) { + if (!flagName) return false; + else if (strcmp(flagName, "usable") == 0) return true; + else return CAdObject::getExtendedFlag(flagName); +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_item.h b/engines/wintermute/ad/ad_item.h new file mode 100644 index 0000000000..34b19a830f --- /dev/null +++ b/engines/wintermute/ad/ad_item.h @@ -0,0 +1,70 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADITEM_H +#define WINTERMUTE_ADITEM_H + + +#include "engines/wintermute/ad/ad_talk_holder.h" + +namespace WinterMute { + +class CAdItem : public CAdTalkHolder { +public: + bool _displayAmount; + int _amount; + int _amountOffsetX; + int _amountOffsetY; + TTextAlign _amountAlign; + char *_amountString; + + + bool update(); + DECLARE_PERSISTENT(CAdItem, CAdTalkHolder) + bool display(int x, int y); + bool getExtendedFlag(const char *flagName); + bool _inInventory; + bool _cursorCombined; + CBSprite *_spriteHover; + CBSprite *_cursorNormal; + CBSprite *_cursorHover; + CAdItem(CBGame *inGame); + virtual ~CAdItem(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp new file mode 100644 index 0000000000..e23948ed87 --- /dev/null +++ b/engines/wintermute/ad/ad_layer.cpp @@ -0,0 +1,537 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/ad/ad_layer.h" +#include "engines/wintermute/ad/ad_scene_node.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdLayer, false) + +////////////////////////////////////////////////////////////////////////// +CAdLayer::CAdLayer(CBGame *inGame): CBObject(inGame) { + _main = false; + _width = _height = 0; + _active = true; + _closeUp = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdLayer::~CAdLayer() { + for (int i = 0; i < _nodes.getSize(); i++) + delete _nodes[i]; + _nodes.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdLayer::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(LAYER) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(WIDTH) +TOKEN_DEF(HEIGHT) +TOKEN_DEF(MAIN) +TOKEN_DEF(ENTITY) +TOKEN_DEF(REGION) +TOKEN_DEF(ACTIVE) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(CLOSE_UP) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(LAYER) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(WIDTH) + TOKEN_TABLE(HEIGHT) + TOKEN_TABLE(MAIN) + TOKEN_TABLE(ENTITY) + TOKEN_TABLE(REGION) + TOKEN_TABLE(ACTIVE) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(CLOSE_UP) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_LAYER) { + _gameRef->LOG(0, "'LAYER' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_MAIN: + parser.scanStr((char *)params, "%b", &_main); + break; + + case TOKEN_CLOSE_UP: + parser.scanStr((char *)params, "%b", &_closeUp); + break; + + case TOKEN_WIDTH: + parser.scanStr((char *)params, "%d", &_width); + break; + + case TOKEN_HEIGHT: + parser.scanStr((char *)params, "%d", &_height); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_REGION: { + CAdRegion *region = new CAdRegion(_gameRef); + CAdSceneNode *node = new CAdSceneNode(_gameRef); + if (!region || !node || DID_FAIL(region->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete region; + delete node; + region = NULL; + node = NULL; + } else { + node->setRegion(region); + _nodes.add(node); + } + } + break; + + case TOKEN_ENTITY: { + CAdEntity *entity = new CAdEntity(_gameRef); + CAdSceneNode *node = new CAdSceneNode(_gameRef); + if (entity) entity->_zoomable = false; // scene entites default to NOT zoom + if (!entity || !node || DID_FAIL(entity->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete entity; + delete node; + entity = NULL; + node = NULL; + } else { + node->setEntity(entity); + _nodes.add(node); + } + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in LAYER definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // GetNode + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "GetNode") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + int node = -1; + + if (val->_type == VAL_INT) node = val->getInt(); + else { // get by name + for (int i = 0; i < _nodes.getSize(); i++) { + if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->_name, val->getString()) == 0) || + (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->_name, val->getString()) == 0)) { + node = i; + break; + } + } + } + + if (node < 0 || node >= _nodes.getSize()) stack->pushNULL(); + else { + switch (_nodes[node]->_type) { + case OBJECT_ENTITY: + stack->pushNative(_nodes[node]->_entity, true); + break; + case OBJECT_REGION: + stack->pushNative(_nodes[node]->_region, true); + break; + default: + stack->pushNULL(); + } + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddRegion / AddEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddRegion") == 0 || strcmp(name, "AddEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdSceneNode *node = new CAdSceneNode(_gameRef); + if (strcmp(name, "AddRegion") == 0) { + CAdRegion *region = new CAdRegion(_gameRef); + if (!val->isNULL()) region->setName(val->getString()); + node->setRegion(region); + stack->pushNative(region, true); + } else { + CAdEntity *entity = new CAdEntity(_gameRef); + if (!val->isNULL()) entity->setName(val->getString()); + node->setEntity(entity); + stack->pushNative(entity, true); + } + _nodes.add(node); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InsertRegion / InsertEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InsertRegion") == 0 || strcmp(name, "InsertEntity") == 0) { + stack->correctParams(2); + int index = stack->pop()->getInt(); + CScValue *val = stack->pop(); + + CAdSceneNode *node = new CAdSceneNode(_gameRef); + if (strcmp(name, "InsertRegion") == 0) { + CAdRegion *region = new CAdRegion(_gameRef); + if (!val->isNULL()) region->setName(val->getString()); + node->setRegion(region); + stack->pushNative(region, true); + } else { + CAdEntity *entity = new CAdEntity(_gameRef); + if (!val->isNULL()) entity->setName(val->getString()); + node->setEntity(entity); + stack->pushNative(entity, true); + } + if (index < 0) index = 0; + if (index <= _nodes.getSize() - 1) _nodes.insertAt(index, node); + else _nodes.add(node); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteNode") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdSceneNode *toDelete = NULL; + if (val->isNative()) { + CBScriptable *temp = val->getNative(); + for (int i = 0; i < _nodes.getSize(); i++) { + if (_nodes[i]->_region == temp || _nodes[i]->_entity == temp) { + toDelete = _nodes[i]; + break; + } + } + } else { + int index = val->getInt(); + if (index >= 0 && index < _nodes.getSize()) { + toDelete = _nodes[index]; + } + } + if (toDelete == NULL) { + stack->pushBool(false); + return STATUS_OK; + } + + for (int i = 0; i < _nodes.getSize(); i++) { + if (_nodes[i] == toDelete) { + delete _nodes[i]; + _nodes[i] = NULL; + _nodes.removeAt(i); + break; + } + } + stack->pushBool(true); + return STATUS_OK; + } + + else return CBObject::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdLayer::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("layer"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumNodes (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumNodes") == 0) { + _scValue->setInt(_nodes.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Width + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + _scValue->setInt(_width); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Height + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + _scValue->setInt(_height); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Main (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Main") == 0) { + _scValue->setBool(_main); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // CloseUp + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CloseUp") == 0) { + _scValue->setBool(_closeUp); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } + + else return CBObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CloseUp + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CloseUp") == 0) { + _closeUp = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Width + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + _width = value->getInt(); + if (_width < 0) _width = 0; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Height + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + _height = value->getInt(); + if (_height < 0) _height = 0; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + bool b = value->getBool(); + if (b == false && _main) { + _gameRef->LOG(0, "Warning: cannot deactivate scene's main layer"); + } else _active = b; + return STATUS_OK; + } + + else return CBObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdLayer::scToString() { + return "[layer]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "LAYER {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + buffer->putTextIndent(indent + 2, "MAIN=%s\n", _main ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "WIDTH=%d\n", _width); + buffer->putTextIndent(indent + 2, "HEIGHT=%d\n", _height); + buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + if (_closeUp) + buffer->putTextIndent(indent + 2, "CLOSE_UP=%s\n", _closeUp ? "TRUE" : "FALSE"); + + int i; + + for (i = 0; i < _scripts.getSize(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_scProp) _scProp->saveAsText(buffer, indent + 2); + + for (i = 0; i < _nodes.getSize(); i++) { + switch (_nodes[i]->_type) { + case OBJECT_ENTITY: + _nodes[i]->_entity->saveAsText(buffer, indent + 2); + break; + case OBJECT_REGION: + _nodes[i]->_region->saveAsText(buffer, indent + 2); + break; + default: + error("CAdLayer::SaveAsText - Unhandled enum"); + break; + } + } + + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdLayer::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_closeUp)); + persistMgr->transfer(TMEMBER(_height)); + persistMgr->transfer(TMEMBER(_main)); + _nodes.persist(persistMgr); + persistMgr->transfer(TMEMBER(_width)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_layer.h b/engines/wintermute/ad/ad_layer.h new file mode 100644 index 0000000000..0ccdb13ae7 --- /dev/null +++ b/engines/wintermute/ad/ad_layer.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADLAYER_H +#define WINTERMUTE_ADLAYER_H + +namespace WinterMute { +class CAdSceneNode; +class CAdLayer : public CBObject { +public: + bool _closeUp; + DECLARE_PERSISTENT(CAdLayer, CBObject) + bool _active; + int _height; + int _width; + bool _main; + CAdLayer(CBGame *inGame); + virtual ~CAdLayer(); + CBArray _nodes; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp new file mode 100644 index 0000000000..06f9c4cf95 --- /dev/null +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -0,0 +1,169 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/ad/ad_node_state.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/base/base_string_table.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdNodeState, false) + + +////////////////////////////////////////////////////////////////////////// +CAdNodeState::CAdNodeState(CBGame *inGame): CBBase(inGame) { + _name = NULL; + _active = false; + for (int i = 0; i < 7; i++) _caption[i] = NULL; + _alphaColor = 0; + _filename = NULL; + _cursor = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdNodeState::~CAdNodeState() { + delete[] _name; + delete[] _filename; + delete[] _cursor; + _name = NULL; + _filename = NULL; + _cursor = NULL; + for (int i = 0; i < 7; i++) { + delete[] _caption[i]; + _caption[i] = NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdNodeState::setName(const char *name) { + delete[] _name; + _name = NULL; + CBUtils::setString(&_name, name); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdNodeState::setFilename(const char *filename) { + delete[] _filename; + _filename = NULL; + CBUtils::setString(&_filename, filename); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdNodeState::setCursor(const char *filename) { + delete[] _cursor; + _cursor = NULL; + CBUtils::setString(&_cursor, filename); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdNodeState::persist(CBPersistMgr *persistMgr) { + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_name)); + persistMgr->transfer(TMEMBER(_filename)); + persistMgr->transfer(TMEMBER(_cursor)); + persistMgr->transfer(TMEMBER(_alphaColor)); + for (int i = 0; i < 7; i++) persistMgr->transfer(TMEMBER(_caption[i])); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdNodeState::setCaption(const char *caption, int caseVal) { + if (caseVal== 0) caseVal= 1; + if (caseVal< 1 || caseVal> 7) return; + + delete[] _caption[caseVal- 1]; + _caption[caseVal- 1] = new char[strlen(caption) + 1]; + if (_caption[caseVal- 1]) { + strcpy(_caption[caseVal- 1], caption); + _gameRef->_stringTable->expand(&_caption[caseVal- 1]); + } +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdNodeState::getCaption(int caseVal) { + if (caseVal== 0) caseVal= 1; + if (caseVal< 1 || caseVal> 7 || _caption[caseVal- 1] == NULL) return ""; + else return _caption[caseVal- 1]; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdNodeState::transferEntity(CAdEntity *entity, bool includingSprites, bool saving) { + if (!entity) return STATUS_FAILED; + + // hack! + if (this->_gameRef != entity->_gameRef) this->_gameRef = entity->_gameRef; + + if (saving) { + for (int i = 0; i < 7; i++) { + if (entity->_caption[i]) setCaption(entity->_caption[i], i); + } + if (!entity->_region && entity->_sprite && entity->_sprite->_filename) { + if (includingSprites) setFilename(entity->_sprite->_filename); + else setFilename(""); + } + if (entity->_cursor && entity->_cursor->_filename) setCursor(entity->_cursor->_filename); + _alphaColor = entity->_alphaColor; + _active = entity->_active; + } else { + for (int i = 0; i < 7; i++) { + if (_caption[i]) entity->setCaption(_caption[i], i); + } + if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) { + if (!entity->_sprite || !entity->_sprite->_filename || scumm_stricmp(entity->_sprite->_filename, _filename) != 0) + entity->setSprite(_filename); + } + if (_cursor) { + if (!entity->_cursor || !entity->_cursor->_filename || scumm_stricmp(entity->_cursor->_filename, _cursor) != 0) + entity->setCursor(_cursor); + } + + entity->_active = _active; + entity->_alphaColor = _alphaColor; + } + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_node_state.h b/engines/wintermute/ad/ad_node_state.h new file mode 100644 index 0000000000..186f2ebbb2 --- /dev/null +++ b/engines/wintermute/ad/ad_node_state.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADNODESTATE_H +#define WINTERMUTE_ADNODESTATE_H + +namespace WinterMute { + +class CAdEntity; + +class CAdNodeState : public CBBase { +public: + bool transferEntity(CAdEntity *entity, bool includingSprites, bool saving); + void setName(const char *name); + void setFilename(const char *filename); + void setCursor(const char *filename); + DECLARE_PERSISTENT(CAdNodeState, CBBase) + CAdNodeState(CBGame *inGame); + virtual ~CAdNodeState(); + char *_name; + bool _active; + char *_caption[7]; + void setCaption(const char *caption, int caseVal); + char *getCaption(int caseVal); + uint32 _alphaColor; + char *_filename; + char *_cursor; + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp new file mode 100644 index 0000000000..46f2e590fd --- /dev/null +++ b/engines/wintermute/ad/ad_object.cpp @@ -0,0 +1,1203 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/ad/ad_object.h" +#include "engines/wintermute/ad/ad_inventory.h" +#include "engines/wintermute/ad/ad_layer.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/ad/ad_scene_node.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_frame.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/base/base_sub_frame.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_string_table.h" +#include "engines/wintermute/base/scriptables/script_engine.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "common/str.h" +#include "common/util.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdObject, false) + +////////////////////////////////////////////////////////////////////////// +CAdObject::CAdObject(CBGame *inGame): CBObject(inGame) { + _type = OBJECT_NONE; + _state = _nextState = STATE_NONE; + + _active = true; + _drawn = false; + + _currentSprite = NULL; + _animSprite = NULL; + _tempSprite2 = NULL; + + _font = NULL; + + _sentence = NULL; + + _forcedTalkAnimName = NULL; + _forcedTalkAnimUsed = false; + + _blockRegion = NULL; + _wptGroup = NULL; + + _currentBlockRegion = NULL; + _currentWptGroup = NULL; + + _ignoreItems = false; + _sceneIndependent = false; + + _stickRegion = NULL; + + _subtitlesModRelative = true; + _subtitlesModX = 0; + _subtitlesModY = 0; + _subtitlesWidth = 0; + _subtitlesModXCenter = true; + + _inventory = NULL; + + for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; + + _partEmitter = NULL; + _partFollowParent = false; + _partOffsetX = _partOffsetY = 0; + + _registerAlias = this; +} + + +////////////////////////////////////////////////////////////////////////// +CAdObject::~CAdObject() { + _currentSprite = NULL; // reference only, don't delete + delete _animSprite; + _animSprite = NULL; + delete _sentence; + _sentence = NULL; + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = NULL; + + delete _blockRegion; + _blockRegion = NULL; + delete _wptGroup; + _wptGroup = NULL; + + delete _currentBlockRegion; + _currentBlockRegion = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + + _tempSprite2 = NULL; // reference only + _stickRegion = NULL; + + if (_font) _gameRef->_fontStorage->removeFont(_font); + + if (_inventory) { + ((CAdGame *)_gameRef)->unregisterInventory(_inventory); + _inventory = NULL; + } + + if (_partEmitter) + _gameRef->unregisterObject(_partEmitter); + + + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + _gameRef->unregisterObject(_attachmentsPre[i]); + } + _attachmentsPre.removeAll(); + + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + _gameRef->unregisterObject(_attachmentsPost[i]); + } + _attachmentsPost.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::playAnim(const char *filename) { + delete _animSprite; + _animSprite = NULL; + _animSprite = new CBSprite(_gameRef, this); + if (!_animSprite) { + _gameRef->LOG(0, "CAdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); + return STATUS_FAILED; + } + bool res = _animSprite->loadFile(filename); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "CAdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); + delete _animSprite; + _animSprite = NULL; + return res; + } + _state = STATE_PLAYING_ANIM; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::display() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::update() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + + ////////////////////////////////////////////////////////////////////////// + // PlayAnim / PlayAnimAsync + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "PlayAnim") == 0 || strcmp(name, "PlayAnimAsync") == 0) { + stack->correctParams(1); + if (DID_FAIL(playAnim(stack->pop()->getString()))) stack->pushBool(false); + else { + if (strcmp(name, "PlayAnimAsync") != 0) script->waitFor(this); + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Reset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Reset") == 0) { + stack->correctParams(0); + reset(); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTalking") == 0) { + stack->correctParams(0); + stack->pushBool(_state == STATE_TALKING); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StopTalk / StopTalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StopTalk") == 0 || strcmp(name, "StopTalking") == 0) { + stack->correctParams(0); + if (_sentence) _sentence->finish(); + if (_state == STATE_TALKING) { + _state = _nextState; + _nextState = STATE_READY; + stack->pushBool(true); + } else stack->pushBool(false); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ForceTalkAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ForceTalkAnim") == 0) { + stack->correctParams(1); + const char *animName = stack->pop()->getString(); + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = new char[strlen(animName) + 1]; + strcpy(_forcedTalkAnimName, animName); + _forcedTalkAnimUsed = false; + stack->pushBool(true); + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // Talk / TalkAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Talk") == 0 || strcmp(name, "TalkAsync") == 0) { + stack->correctParams(5); + + const char *text = stack->pop()->getString(); + CScValue *soundVal = stack->pop(); + int duration = stack->pop()->getInt(); + CScValue *valStances = stack->pop(); + + const char *stances = valStances->isNULL() ? NULL : valStances->getString(); + + int align = 0; + CScValue *val = stack->pop(); + if (val->isNULL()) align = TAL_CENTER; + else align = val->getInt(); + + align = MIN(MAX(0, align), NUM_TEXT_ALIGN - 1); + + const char *sound = soundVal->isNULL() ? NULL : soundVal->getString(); + + talk(text, sound, duration, stances, (TTextAlign)align); + if (strcmp(name, "TalkAsync") != 0) script->waitForExclusive(this); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StickToRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StickToRegion") == 0) { + stack->correctParams(1); + + CAdLayer *main = ((CAdGame *)_gameRef)->_scene->_mainLayer; + bool regFound = false; + + int i; + CScValue *val = stack->pop(); + if (val->isNULL() || !main) { + _stickRegion = NULL; + regFound = true; + } else if (val->isString()) { + const char *regionName = val->getString(); + for (i = 0; i < main->_nodes.getSize(); i++) { + if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region->_name && scumm_stricmp(main->_nodes[i]->_region->_name, regionName) == 0) { + _stickRegion = main->_nodes[i]->_region; + regFound = true; + break; + } + } + } else if (val->isNative()) { + CBScriptable *obj = val->getNative(); + + for (i = 0; i < main->_nodes.getSize(); i++) { + if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region == obj) { + _stickRegion = main->_nodes[i]->_region; + regFound = true; + break; + } + } + + } + + if (!regFound) _stickRegion = NULL; + stack->pushBool(regFound); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetFont + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetFont") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + if (val->isNULL()) SetFont(NULL); + else SetFont(val->getString()); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFont + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFont") == 0) { + stack->correctParams(0); + if (_font && _font->_filename) stack->pushString(_font->_filename); + else stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TakeItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TakeItem") == 0) { + stack->correctParams(2); + + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + + CScValue *val = stack->pop(); + if (!val->isNULL()) { + const char *itemName = val->getString(); + val = stack->pop(); + const char *insertAfter = val->isNULL() ? NULL : val->getString(); + if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) script->runtimeError("Cannot add item '%s' to inventory", itemName); + else { + // hide associated entities + ((CAdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); + } + + } else script->runtimeError("TakeItem: item name expected"); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DropItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DropItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + + CScValue *val = stack->pop(); + if (!val->isNULL()) { + if (DID_FAIL(_inventory->removeItem(val->getString()))) script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); + else { + // show associated entities + ((CAdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); + } + } else script->runtimeError("DropItem: item name expected"); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + + CScValue *val = stack->pop(); + if (val->_type == VAL_STRING) { + CAdItem *item = ((CAdGame *)_gameRef)->getItemByName(val->getString()); + if (item) stack->pushNative(item, true); + else stack->pushNULL(); + } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) + stack->pushNULL(); + else + stack->pushNative(_inventory->_takenItems[val->getInt()], true); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // HasItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + + CScValue *val = stack->pop(); + if (!val->isNULL()) { + for (int i = 0; i < _inventory->_takenItems.getSize(); i++) { + if (val->getNative() == _inventory->_takenItems[i]) { + stack->pushBool(true); + return STATUS_OK; + } else if (scumm_stricmp(val->getString(), _inventory->_takenItems[i]->_name) == 0) { + stack->pushBool(true); + return STATUS_OK; + } + } + } else script->runtimeError("HasItem: item name expected"); + + stack->pushBool(false); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateParticleEmitter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateParticleEmitter") == 0) { + stack->correctParams(3); + bool followParent = stack->pop()->getBool(); + int offsetX = stack->pop()->getInt(); + int offsetY = stack->pop()->getInt(); + + CPartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); + if (emitter) stack->pushNative(_partEmitter, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteParticleEmitter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteParticleEmitter") == 0) { + stack->correctParams(0); + if (_partEmitter) { + _gameRef->unregisterObject(_partEmitter); + _partEmitter = NULL; + } + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddAttachment") == 0) { + stack->correctParams(4); + const char *filename = stack->pop()->getString(); + bool preDisplay = stack->pop()->getBool(true); + int offsetX = stack->pop()->getInt(); + int offsetY = stack->pop()->getInt(); + + bool res; + CAdEntity *ent = new CAdEntity(_gameRef); + if (DID_FAIL(res = ent->loadFile(filename))) { + delete ent; + ent = NULL; + script->runtimeError("AddAttachment() failed loading entity '%s'", filename); + stack->pushBool(false); + } else { + _gameRef->registerObject(ent); + + ent->_posX = offsetX; + ent->_posY = offsetY; + ent->_active = true; + + if (preDisplay) _attachmentsPre.add(ent); + else _attachmentsPost.add(ent); + + stack->pushBool(true); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveAttachment") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + bool found = false; + if (val->isNative()) { + CBScriptable *obj = val->getNative(); + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + if (_attachmentsPre[i] == obj) { + found = true; + _gameRef->unregisterObject(_attachmentsPre[i]); + _attachmentsPre.removeAt(i); + i--; + } + } + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + if (_attachmentsPost[i] == obj) { + found = true; + _gameRef->unregisterObject(_attachmentsPost[i]); + _attachmentsPost.removeAt(i); + i--; + } + } + } else { + const char *attachmentName = val->getString(); + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + if (_attachmentsPre[i]->_name && scumm_stricmp(_attachmentsPre[i]->_name, attachmentName) == 0) { + found = true; + _gameRef->unregisterObject(_attachmentsPre[i]); + _attachmentsPre.removeAt(i); + i--; + } + } + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + if (_attachmentsPost[i]->_name && scumm_stricmp(_attachmentsPost[i]->_name, attachmentName) == 0) { + found = true; + _gameRef->unregisterObject(_attachmentsPost[i]); + _attachmentsPost.removeAt(i); + i--; + } + } + } + stack->pushBool(found); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetAttachment") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdObject *ret = NULL; + if (val->isInt()) { + int index = val->getInt(); + int currIndex = 0; + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + if (currIndex == index) ret = _attachmentsPre[i]; + currIndex++; + } + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + if (currIndex == index) ret = _attachmentsPost[i]; + currIndex++; + } + } else { + const char *attachmentName = val->getString(); + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + if (_attachmentsPre[i]->_name && scumm_stricmp(_attachmentsPre[i]->_name, attachmentName) == 0) { + ret = _attachmentsPre[i]; + break; + } + } + if (!ret) { + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + if (_attachmentsPost[i]->_name && scumm_stricmp(_attachmentsPost[i]->_name, attachmentName) == 0) { + ret = _attachmentsPre[i]; + break; + } + } + } + } + + if (ret != NULL) stack->pushNative(ret, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + else return CBObject::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdObject::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("object"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // IgnoreItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IgnoreItems") == 0) { + _scValue->setBool(_ignoreItems); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SceneIndependent + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SceneIndependent") == 0) { + _scValue->setBool(_sceneIndependent); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesWidth + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesWidth") == 0) { + _scValue->setInt(_subtitlesWidth); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosRelative + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosRelative") == 0) { + _scValue->setBool(_subtitlesModRelative); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosX") == 0) { + _scValue->setInt(_subtitlesModX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosY") == 0) { + _scValue->setInt(_subtitlesModY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosXCenter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosXCenter") == 0) { + _scValue->setBool(_subtitlesModXCenter); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumItems (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumItems") == 0) { + _scValue->setInt(getInventory()->_takenItems.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ParticleEmitter (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ParticleEmitter") == 0) { + if (_partEmitter) _scValue->setNative(_partEmitter, true); + else _scValue->setNULL(); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumAttachments (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumAttachments") == 0) { + _scValue->setInt(_attachmentsPre.getSize() + _attachmentsPost.getSize()); + return _scValue; + } + + + else return CBObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::scSetProperty(const char *name, CScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Active") == 0) { + _active = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IgnoreItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IgnoreItems") == 0) { + _ignoreItems = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SceneIndependent + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SceneIndependent") == 0) { + _sceneIndependent = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesWidth + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesWidth") == 0) { + _subtitlesWidth = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosRelative + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosRelative") == 0) { + _subtitlesModRelative = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosX") == 0) { + _subtitlesModX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosY") == 0) { + _subtitlesModY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosXCenter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosXCenter") == 0) { + _subtitlesModXCenter = value->getBool(); + return STATUS_OK; + } + + else return CBObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdObject::scToString() { + return "[ad object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::SetFont(const char *filename) { + if (_font) _gameRef->_fontStorage->removeFont(_font); + if (filename) { + _font = _gameRef->_fontStorage->addFont(filename); + return _font == NULL ? STATUS_FAILED : STATUS_OK; + } else { + _font = NULL; + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +int CAdObject::getHeight() { + if (!_currentSprite) return 0; + else { + CBFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; + int ret = 0; + for (int i = 0; i < frame->_subframes.getSize(); i++) { + ret = MAX(ret, frame->_subframes[i]->_hotspotY); + } + + if (_zoomable) { + float zoom = ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY); + ret = (int)(ret * zoom / 100); + } + return ret; + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { + if (!_sentence) _sentence = new CAdSentence(_gameRef); + if (!_sentence) return; + + if (_forcedTalkAnimName && _forcedTalkAnimUsed) { + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = NULL; + _forcedTalkAnimUsed = false; + } + + delete(_sentence->_sound); + _sentence->_sound = NULL; + + _sentence->setText(text); + _gameRef->_stringTable->expand(&_sentence->_text); + _sentence->setStances(stances); + _sentence->_duration = duration; + _sentence->_align = Align; + _sentence->_startTime = _gameRef->_timer; + _sentence->_currentStance = -1; + _sentence->_font = _font == NULL ? _gameRef->_systemFont : _font; + _sentence->_freezable = _freezable; + + // try to locate speech file automatically + bool deleteSound = false; + if (!sound) { + char *key = _gameRef->_stringTable->getKey(text); + if (key) { + sound = ((CAdGame *)_gameRef)->findSpeechFile(key); + delete [] key; + + if (sound) deleteSound = true; + } + } + + // load sound and set duration appropriately + if (sound) { + CBSound *snd = new CBSound(_gameRef); + if (snd && DID_SUCCEED(snd->setSound(sound, Audio::Mixer::kSpeechSoundType, true))) { + _sentence->setSound(snd); + if (_sentence->_duration <= 0) { + uint32 Length = snd->getLength(); + if (Length != 0) _sentence->_duration = Length; + } + } else delete snd; + } + + // set duration by text length + if (_sentence->_duration <= 0) {// TODO: Avoid longs. + _sentence->_duration = MAX((size_t)1000, _gameRef->_subtitlesSpeed * strlen(_sentence->_text)); + } + + + int x, y, width, height; + + x = _posX; + y = _posY; + + if (!_sceneIndependent && _subtitlesModRelative) { + x -= ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); + y -= ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + } + + + if (_subtitlesWidth > 0) width = _subtitlesWidth; + else { + if ((x < _gameRef->_renderer->_width / 4 || x > _gameRef->_renderer->_width * 0.75) && !_gameRef->_touchInterface) { + width = MAX(_gameRef->_renderer->_width / 4, MIN(x * 2, (_gameRef->_renderer->_width - x) * 2)); + } else width = _gameRef->_renderer->_width / 2; + } + + height = _sentence->_font->getTextHeight((byte *)_sentence->_text, width); + + y = y - height - getHeight() - 5; + if (_subtitlesModRelative) { + x += _subtitlesModX; + y += _subtitlesModY; + } else { + x = _subtitlesModX; + y = _subtitlesModY; + } + if (_subtitlesModXCenter) + x = x - width / 2; + + + x = MIN(MAX(0, x), _gameRef->_renderer->_width - width); + y = MIN(MAX(0, y), _gameRef->_renderer->_height - height); + + _sentence->_width = width; + + + _sentence->_pos.x = x; + _sentence->_pos.y = y; + + + if (_subtitlesModRelative) { + _sentence->_pos.x += ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); + _sentence->_pos.y += ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + } + + _sentence->_fixedPos = !_subtitlesModRelative; + + + _sentence->setupTalkFile(sound); + + _state = STATE_TALKING; + + if (deleteSound) delete [] sound; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::reset() { + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL) { + delete _animSprite; + _animSprite = NULL; + } else if (_state == STATE_TALKING && _sentence) { + _sentence->finish(); + } + + _state = _nextState = STATE_READY; + + _gameRef->_scEngine->resetObject(this); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::persist(CBPersistMgr *persistMgr) { + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_blockRegion)); + persistMgr->transfer(TMEMBER(_currentBlockRegion)); + persistMgr->transfer(TMEMBER(_currentWptGroup)); + persistMgr->transfer(TMEMBER(_currentSprite)); + persistMgr->transfer(TMEMBER(_drawn)); + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_ignoreItems)); + persistMgr->transfer(TMEMBER_INT(_nextState)); + persistMgr->transfer(TMEMBER(_sentence)); + persistMgr->transfer(TMEMBER_INT(_state)); + persistMgr->transfer(TMEMBER(_animSprite)); + persistMgr->transfer(TMEMBER(_sceneIndependent)); + persistMgr->transfer(TMEMBER(_forcedTalkAnimName)); + persistMgr->transfer(TMEMBER(_forcedTalkAnimUsed)); + persistMgr->transfer(TMEMBER(_tempSprite2)); + persistMgr->transfer(TMEMBER_INT(_type)); + persistMgr->transfer(TMEMBER(_wptGroup)); + persistMgr->transfer(TMEMBER(_stickRegion)); + persistMgr->transfer(TMEMBER(_subtitlesModRelative)); + persistMgr->transfer(TMEMBER(_subtitlesModX)); + persistMgr->transfer(TMEMBER(_subtitlesModY)); + persistMgr->transfer(TMEMBER(_subtitlesModXCenter)); + persistMgr->transfer(TMEMBER(_subtitlesWidth)); + persistMgr->transfer(TMEMBER(_inventory)); + persistMgr->transfer(TMEMBER(_partEmitter)); + + for (int i = 0; i < MAX_NUM_REGIONS; i++) persistMgr->transfer(TMEMBER(_currentRegions[i])); + + _attachmentsPre.persist(persistMgr); + _attachmentsPost.persist(persistMgr); + persistMgr->transfer(TMEMBER(_registerAlias)); + + persistMgr->transfer(TMEMBER(_partFollowParent)); + persistMgr->transfer(TMEMBER(_partOffsetX)); + persistMgr->transfer(TMEMBER(_partOffsetY)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::updateSounds() { + if (_sentence && _sentence->_sound) + updateOneSound(_sentence->_sound); + + return CBObject::updateSounds(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::resetSoundPan() { + if (_sentence && _sentence->_sound) { + _sentence->_sound->setPan(0.0f); + } + return CBObject::resetSoundPan(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::getExtendedFlag(const char *flagName) { + if (!flagName) return false; + else if (strcmp(flagName, "usable") == 0) return true; + + else return CBObject::getExtendedFlag(flagName); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::saveAsText(CBDynBuffer *buffer, int indent) { + if (_blockRegion) _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); + if (_wptGroup) _wptGroup->saveAsText(buffer, indent + 2); + + CBBase::saveAsText(buffer, indent + 2); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::updateBlockRegion() { + CAdGame *adGame = (CAdGame *)_gameRef; + if (adGame->_scene) { + if (_blockRegion && _currentBlockRegion) + _currentBlockRegion->mimic(_blockRegion, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + + if (_wptGroup && _currentWptGroup) + _currentWptGroup->mimic(_wptGroup, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +CAdInventory *CAdObject::getInventory() { + if (!_inventory) { + _inventory = new CAdInventory(_gameRef); + ((CAdGame *)_gameRef)->registerInventory(_inventory); + } + return _inventory; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::afterMove() { + CAdRegion *newRegions[MAX_NUM_REGIONS]; + + ((CAdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + if (!newRegions[i]) break; + bool regFound = false; + for (int j = 0; j < MAX_NUM_REGIONS; j++) { + if (_currentRegions[j] == newRegions[i]) { + _currentRegions[j] = NULL; + regFound = true; + break; + } + } + if (!regFound) newRegions[i]->applyEvent("ActorEntry"); + } + + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + if (_currentRegions[i] && _gameRef->validObject(_currentRegions[i])) { + _currentRegions[i]->applyEvent("ActorLeave"); + } + _currentRegions[i] = newRegions[i]; + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::invalidateCurrRegions() { + for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::getScale(float *scaleX, float *scaleY) { + if (_zoomable) { + if (_scaleX >= 0 || _scaleY >= 0) { + *scaleX = _scaleX < 0 ? 100 : _scaleX; + *scaleY = _scaleY < 0 ? 100 : _scaleY; + } else if (_scale >= 0) *scaleX = *scaleY = _scale; + else *scaleX = *scaleY = ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; + } else { + *scaleX = *scaleY = 100; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::updateSpriteAttachments() { + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + _attachmentsPre[i]->update(); + } + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + _attachmentsPost[i]->update(); + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::displaySpriteAttachments(bool preDisplay) { + if (preDisplay) { + for (int i = 0; i < _attachmentsPre.getSize(); i++) { + displaySpriteAttachment(_attachmentsPre[i]); + } + } else { + for (int i = 0; i < _attachmentsPost.getSize(); i++) { + displaySpriteAttachment(_attachmentsPost[i]); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::displaySpriteAttachment(CAdObject *attachment) { + if (!attachment->_active) return STATUS_OK; + + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + int origX = attachment->_posX; + int origY = attachment->_posY; + + // inherit position from owner + attachment->_posX = (int)(this->_posX + attachment->_posX * scaleX / 100.0f); + attachment->_posY = (int)(this->_posY + attachment->_posY * scaleY / 100.0f); + + // inherit other props + attachment->_alphaColor = this->_alphaColor; + attachment->_blendMode = this->_blendMode; + + attachment->_scale = this->_scale; + attachment->_relativeScale = this->_relativeScale; + attachment->_scaleX = this->_scaleX; + attachment->_scaleY = this->_scaleY; + + attachment->_rotate = this->_rotate; + attachment->_relativeRotate = this->_relativeRotate; + attachment->_rotateValid = this->_rotateValid; + + attachment->_registerAlias = this; + attachment->_registrable = this->_registrable; + + bool ret = attachment->display(); + + attachment->_posX = origX; + attachment->_posY = origY; + + return ret; +} + +////////////////////////////////////////////////////////////////////////// +CPartEmitter *CAdObject::createParticleEmitter(bool followParent, int offsetX, int offsetY) { + _partFollowParent = followParent; + _partOffsetX = offsetX; + _partOffsetY = offsetY; + + if (!_partEmitter) { + _partEmitter = new CPartEmitter(_gameRef, this); + if (_partEmitter) { + _gameRef->registerObject(_partEmitter); + } + } + updatePartEmitter(); + return _partEmitter; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdObject::updatePartEmitter() { + if (!_partEmitter) return STATUS_FAILED; + + if (_partFollowParent) { + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + _partEmitter->_posX = (int)(_posX + (scaleX / 100.0f) * _partOffsetX); + _partEmitter->_posY = (int)(_posY + (scaleY / 100.0f) * _partOffsetY); + } + return _partEmitter->update(); +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h new file mode 100644 index 0000000000..dd123092a3 --- /dev/null +++ b/engines/wintermute/ad/ad_object.h @@ -0,0 +1,123 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADOBJECT_H +#define WINTERMUTE_ADOBJECT_H + +#include "engines/wintermute/ad/ad_types.h" +#include "engines/wintermute/base/particles/part_emitter.h" + +namespace WinterMute { + +class CAdWaypointGroup; +class CAdRegion; +class CAdSentence; +class CBFont; +class CBRegion; +class CAdInventory; + +#define MAX_NUM_REGIONS 10 + +class CAdObject : public CBObject { +public: + CPartEmitter *_partEmitter; + virtual CPartEmitter *createParticleEmitter(bool followParent = false, int offsetX = 0, int offsetY = 0); + virtual bool updatePartEmitter(); + bool _partFollowParent; + int _partOffsetX; + int _partOffsetY; + + bool invalidateCurrRegions(); + bool _subtitlesModRelative; + bool _subtitlesModXCenter; + int _subtitlesModX; + int _subtitlesModY; + int _subtitlesWidth; + CAdRegion *_stickRegion; + bool _sceneIndependent; + bool _ignoreItems; + bool updateBlockRegion(); + bool _forcedTalkAnimUsed; + char *_forcedTalkAnimName; + virtual bool getExtendedFlag(const char *flagName); + virtual bool resetSoundPan(); + virtual bool updateSounds(); + bool reset(); + DECLARE_PERSISTENT(CAdObject, CBObject) + virtual void talk(const char *text, const char *sound = NULL, uint32 duration = 0, const char *stances = NULL, TTextAlign align = TAL_CENTER); + virtual int getHeight(); + CAdSentence *_sentence; + bool SetFont(const char *filename); + virtual bool update(); + virtual bool display(); + bool _drawn; + bool _active; + virtual bool playAnim(const char *filename); + CBSprite *_animSprite; + CBSprite *_currentSprite; + TObjectState _state; + TObjectState _nextState; + TObjectType _type; + CAdObject(CBGame *inGame); + virtual ~CAdObject(); + CBFont *_font; + CBSprite *_tempSprite2; + CBRegion *_blockRegion; + CAdWaypointGroup *_wptGroup; + CBRegion *_currentBlockRegion; + CAdWaypointGroup *_currentWptGroup; + CAdInventory *getInventory(); + + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + + virtual bool afterMove(); + CAdRegion *_currentRegions[MAX_NUM_REGIONS]; + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + + CBArray _attachmentsPre; + CBArray _attachmentsPost; + + bool updateSpriteAttachments(); + bool displaySpriteAttachments(bool preDisplay); + CAdObject *_registerAlias; +private: + bool displaySpriteAttachment(CAdObject *attachment); + CAdInventory *_inventory; + +protected: + bool getScale(float *scaleX, float *scaleY); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp new file mode 100644 index 0000000000..780912ce08 --- /dev/null +++ b/engines/wintermute/ad/ad_path.cpp @@ -0,0 +1,112 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_path.h" +#include "engines/wintermute/base/base_point.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdPath, false) + +////////////////////////////////////////////////////////////////////////// +CAdPath::CAdPath(CBGame *inGame): CBBase(inGame) { + _currIndex = -1; + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdPath::~CAdPath() { + reset(); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdPath::reset() { + for (int i = 0; i < _points.getSize(); i++) + delete _points[i]; + + _points.removeAll(); + _currIndex = -1; + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +CBPoint *CAdPath::getFirst() { + if (_points.getSize() > 0) { + _currIndex = 0; + return _points[_currIndex]; + } else return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CBPoint *CAdPath::getNext() { + _currIndex++; + if (_currIndex < _points.getSize()) return _points[_currIndex]; + else return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CBPoint *CAdPath::getCurrent() { + if (_currIndex >= 0 && _currIndex < _points.getSize()) return _points[_currIndex]; + else return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdPath::addPoint(CBPoint *point) { + _points.add(point); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdPath::setReady(bool ready) { + bool orig = _ready; + _ready = ready; + + return orig; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdPath::persist(CBPersistMgr *persistMgr) { + + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER(_currIndex)); + _points.persist(persistMgr); + persistMgr->transfer(TMEMBER(_ready)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_path.h b/engines/wintermute/ad/ad_path.h new file mode 100644 index 0000000000..f27362bfd9 --- /dev/null +++ b/engines/wintermute/ad/ad_path.h @@ -0,0 +1,56 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADPATH_H +#define WINTERMUTE_ADPATH_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/coll_templ.h" +#include "engines/wintermute/base/base.h" + +namespace WinterMute { +class CBPoint; +class CAdPath : public CBBase { +public: + DECLARE_PERSISTENT(CAdPath, CBBase) + CBPoint *getCurrent(); + bool setReady(bool ready = true); + void addPoint(CBPoint *point); + CBPoint *getNext(); + CBPoint *getFirst(); + void reset(); + CAdPath(CBGame *inGame); + virtual ~CAdPath(); + CBArray _points; + int _currIndex; + bool _ready; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_path_point.cpp b/engines/wintermute/ad/ad_path_point.cpp new file mode 100644 index 0000000000..d4b910a30f --- /dev/null +++ b/engines/wintermute/ad/ad_path_point.cpp @@ -0,0 +1,75 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_path_point.h" +#include "engines/wintermute/base/base_persistence_manager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdPathPoint, false) + +////////////////////////////////////////////////////////////////////////// +CAdPathPoint::CAdPathPoint() { + x = y = 0; + _distance = 0; + + _marked = false; + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdPathPoint::CAdPathPoint(int initX, int initY, int initDistance) { + x = initX; + y = initY; + _distance = initDistance; + + _marked = false; + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdPathPoint::~CAdPathPoint() { + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdPathPoint::persist(CBPersistMgr *persistMgr) { + + CBPoint::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_distance)); + persistMgr->transfer(TMEMBER(_marked)); + persistMgr->transfer(TMEMBER(_origin)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_path_point.h b/engines/wintermute/ad/ad_path_point.h new file mode 100644 index 0000000000..2a58237bb9 --- /dev/null +++ b/engines/wintermute/ad/ad_path_point.h @@ -0,0 +1,50 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADPATHPOINT_H +#define WINTERMUTE_ADPATHPOINT_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base_point.h" + +namespace WinterMute { + +class CAdPathPoint : public CBPoint { +public: + DECLARE_PERSISTENT(CAdPathPoint, CBPoint) + CAdPathPoint(int initX, int initY, int initDistance); + CAdPathPoint(); + virtual ~CAdPathPoint(); + CAdPathPoint *_origin; + bool _marked; + int _distance; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp new file mode 100644 index 0000000000..ae65be5013 --- /dev/null +++ b/engines/wintermute/ad/ad_region.cpp @@ -0,0 +1,392 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_region.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdRegion, false) + +////////////////////////////////////////////////////////////////////////// +CAdRegion::CAdRegion(CBGame *inGame): CBRegion(inGame) { + _blocked = false; + _decoration = false; + _zoom = 0; + _alpha = 0xFFFFFFFF; +} + + +////////////////////////////////////////////////////////////////////////// +CAdRegion::~CAdRegion() { +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdRegion::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(REGION) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(ACTIVE) +TOKEN_DEF(ZOOM) +TOKEN_DEF(SCALE) +TOKEN_DEF(BLOCKED) +TOKEN_DEF(DECORATION) +TOKEN_DEF(POINT) +TOKEN_DEF(ALPHA_COLOR) +TOKEN_DEF(ALPHA) +TOKEN_DEF(EDITOR_SELECTED_POINT) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(REGION) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(ACTIVE) + TOKEN_TABLE(ZOOM) + TOKEN_TABLE(SCALE) + TOKEN_TABLE(BLOCKED) + TOKEN_TABLE(DECORATION) + TOKEN_TABLE(POINT) + TOKEN_TABLE(ALPHA_COLOR) + TOKEN_TABLE(ALPHA) + TOKEN_TABLE(EDITOR_SELECTED_POINT) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { + _gameRef->LOG(0, "'REGION' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + for (int i = 0; i < _points.getSize(); i++) delete _points[i]; + _points.removeAll(); + + int ar = 255, ag = 255, ab = 255, alpha = 255; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_BLOCKED: + parser.scanStr((char *)params, "%b", &_blocked); + break; + + case TOKEN_DECORATION: + parser.scanStr((char *)params, "%b", &_decoration); + break; + + case TOKEN_ZOOM: + case TOKEN_SCALE: { + int j; + parser.scanStr((char *)params, "%d", &j); + _zoom = (float)j; + } + break; + + case TOKEN_POINT: { + int x, y; + parser.scanStr((char *)params, "%d,%d", &x, &y); + _points.add(new CBPoint(x, y)); + } + 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_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_EDITOR_SELECTED_POINT: + parser.scanStr((char *)params, "%d", &_editorSelectedPoint); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in REGION definition"); + return STATUS_FAILED; + } + + createRegion(); + + _alpha = BYTETORGBA(ar, ag, ab, alpha); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + /* + ////////////////////////////////////////////////////////////////////////// + // SkipTo + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SkipTo")==0) { + stack->correctParams(2); + _posX = stack->pop()->getInt(); + _posY = stack->pop()->getInt(); + stack->pushNULL(); + + return STATUS_OK; + } + + else*/ return CBRegion::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdRegion::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("ad region"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Name") == 0) { + _scValue->setString(_name); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Blocked + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Blocked") == 0) { + _scValue->setBool(_blocked); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Decoration + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Decoration") == 0) { + _scValue->setBool(_decoration); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Scale + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scale") == 0) { + _scValue->setFloat(_zoom); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AlphaColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AlphaColor") == 0) { + _scValue->setInt((int)_alpha); + return _scValue; + } + + else return CBRegion::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Blocked + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Blocked") == 0) { + _blocked = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Decoration + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Decoration") == 0) { + _decoration = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Scale + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scale") == 0) { + _zoom = value->getFloat(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AlphaColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AlphaColor") == 0) { + _alpha = (uint32)value->getInt(); + return STATUS_OK; + } + + else return CBRegion::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdRegion::scToString() { + return "[ad region]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "REGION {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + buffer->putTextIndent(indent + 2, "BLOCKED=%s\n", _blocked ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "DECORATION=%s\n", _decoration ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_zoom); + buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alpha), RGBCOLGetG(_alpha), RGBCOLGetB(_alpha)); + buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alpha)); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + + int i; + for (i = 0; i < _scripts.getSize(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_scProp) _scProp->saveAsText(buffer, indent + 2); + + for (i = 0; i < _points.getSize(); i++) { + buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); + } + + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRegion::persist(CBPersistMgr *persistMgr) { + CBRegion::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_alpha)); + persistMgr->transfer(TMEMBER(_blocked)); + persistMgr->transfer(TMEMBER(_decoration)); + persistMgr->transfer(TMEMBER(_zoom)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_region.h b/engines/wintermute/ad/ad_region.h new file mode 100644 index 0000000000..62c5fd6ba3 --- /dev/null +++ b/engines/wintermute/ad/ad_region.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADREGION_H +#define WINTERMUTE_ADREGION_H + +#include "engines/wintermute/base/base_region.h" + +namespace WinterMute { + +class CAdRegion : public CBRegion { +public: + DECLARE_PERSISTENT(CAdRegion, CBRegion) + uint32 _alpha; + float _zoom; + bool _blocked; + bool _decoration; + CAdRegion(CBGame *inGame); + virtual ~CAdRegion(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp new file mode 100644 index 0000000000..b653fbd36a --- /dev/null +++ b/engines/wintermute/ad/ad_response.cpp @@ -0,0 +1,143 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_response.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/utils/utils.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdResponse, false) + +////////////////////////////////////////////////////////////////////////// +CAdResponse::CAdResponse(CBGame *inGame): CBObject(inGame) { + _text = NULL; + _textOrig = NULL; + _icon = _iconHover = _iconPressed = NULL; + _font = NULL; + _iD = 0; + _responseType = RESPONSE_ALWAYS; +} + + +////////////////////////////////////////////////////////////////////////// +CAdResponse::~CAdResponse() { + delete[] _text; + delete[] _textOrig; + delete _icon; + delete _iconHover; + delete _iconPressed; + _text = NULL; + _textOrig = NULL; + _icon = NULL; + _iconHover = NULL; + _iconPressed = NULL; + if (_font) _gameRef->_fontStorage->removeFont(_font); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdResponse::setText(const char *text) { + CBUtils::setString(&_text, text); + CBUtils::setString(&_textOrig, text); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::setIcon(const char *filename) { + delete _icon; + _icon = new CBSprite(_gameRef); + if (!_icon || DID_FAIL(_icon->loadFile(filename))) { + _gameRef->LOG(0, "CAdResponse::setIcon failed for file '%s'", filename); + delete _icon; + _icon = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::setFont(const char *filename) { + if (_font) _gameRef->_fontStorage->removeFont(_font); + _font = _gameRef->_fontStorage->addFont(filename); + if (!_font) { + _gameRef->LOG(0, "CAdResponse::setFont failed for file '%s'", filename); + return STATUS_FAILED; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::setIconHover(const char *filename) { + delete _iconHover; + _iconHover = new CBSprite(_gameRef); + if (!_iconHover || DID_FAIL(_iconHover->loadFile(filename))) { + _gameRef->LOG(0, "CAdResponse::setIconHover failed for file '%s'", filename); + delete _iconHover; + _iconHover = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::setIconPressed(const char *filename) { + delete _iconPressed; + _iconPressed = new CBSprite(_gameRef); + if (!_iconPressed || DID_FAIL(_iconPressed->loadFile(filename))) { + _gameRef->LOG(0, "CAdResponse::setIconPressed failed for file '%s'", filename); + delete _iconPressed; + _iconPressed = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponse::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_icon)); + persistMgr->transfer(TMEMBER(_iconHover)); + persistMgr->transfer(TMEMBER(_iconPressed)); + persistMgr->transfer(TMEMBER(_iD)); + persistMgr->transfer(TMEMBER(_text)); + persistMgr->transfer(TMEMBER(_textOrig)); + persistMgr->transfer(TMEMBER_INT(_responseType)); + persistMgr->transfer(TMEMBER(_font)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_response.h b/engines/wintermute/ad/ad_response.h new file mode 100644 index 0000000000..da450b2229 --- /dev/null +++ b/engines/wintermute/ad/ad_response.h @@ -0,0 +1,61 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSE_H +#define WINTERMUTE_ADRESPONSE_H + + +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/ad/ad_types.h" + +namespace WinterMute { +class CBFont; +class CAdResponse : public CBObject { +public: + DECLARE_PERSISTENT(CAdResponse, CBObject) + bool setIcon(const char *filename); + bool setFont(const char *filename); + bool setIconHover(const char *filename); + bool setIconPressed(const char *filename); + void setText(const char *text); + int _iD; + CBSprite *_icon; + CBSprite *_iconHover; + CBSprite *_iconPressed; + CBFont *_font; + char *_text; + char *_textOrig; + CAdResponse(CBGame *inGame); + virtual ~CAdResponse(); + TResponseType _responseType; + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp new file mode 100644 index 0000000000..2499c9a732 --- /dev/null +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -0,0 +1,647 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_response_box.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/ui/ui_button.h" +#include "engines/wintermute/ui/ui_window.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/ad/ad_response.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdResponseBox, false) + +////////////////////////////////////////////////////////////////////////// +CAdResponseBox::CAdResponseBox(CBGame *inGame): CBObject(inGame) { + _font = _fontHover = NULL; + + _window = NULL; + _shieldWindow = new CUIWindow(_gameRef); + + _horizontal = false; + CBPlatform::setRectEmpty(&_responseArea); + _scrollOffset = 0; + _spacing = 0; + + _waitingScript = NULL; + _lastResponseText = NULL; + _lastResponseTextOrig = NULL; + + _verticalAlign = VAL_BOTTOM; + _align = TAL_LEFT; +} + + +////////////////////////////////////////////////////////////////////////// +CAdResponseBox::~CAdResponseBox() { + + delete _window; + _window = NULL; + delete _shieldWindow; + _shieldWindow = NULL; + delete[] _lastResponseText; + _lastResponseText = NULL; + delete[] _lastResponseTextOrig; + _lastResponseTextOrig = NULL; + + if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + + clearResponses(); + clearButtons(); + + _waitingScript = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdResponseBox::clearResponses() { + for (int i = 0; i < _responses.getSize(); i++) { + delete _responses[i]; + } + _responses.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdResponseBox::clearButtons() { + for (int i = 0; i < _respButtons.getSize(); i++) { + delete _respButtons[i]; + } + _respButtons.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::invalidateButtons() { + for (int i = 0; i < _respButtons.getSize(); i++) { + _respButtons[i]->_image = NULL; + _respButtons[i]->_cursor = NULL; + _respButtons[i]->_font = NULL; + _respButtons[i]->_fontHover = NULL; + _respButtons[i]->_fontPress = NULL; + _respButtons[i]->setText(""); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::createButtons() { + clearButtons(); + + _scrollOffset = 0; + for (int i = 0; i < _responses.getSize(); i++) { + CUIButton *btn = new CUIButton(_gameRef); + if (btn) { + btn->_parent = _window; + btn->_sharedFonts = btn->_sharedImages = true; + btn->_sharedCursors = true; + // iconic + if (_responses[i]->_icon) { + btn->_image = _responses[i]->_icon; + if (_responses[i]->_iconHover) btn->_imageHover = _responses[i]->_iconHover; + if (_responses[i]->_iconPressed) btn->_imagePress = _responses[i]->_iconPressed; + + btn->setCaption(_responses[i]->_text); + if (_cursor) btn->_cursor = _cursor; + else if (_gameRef->_activeCursor) btn->_cursor = _gameRef->_activeCursor; + } + // textual + else { + btn->setText(_responses[i]->_text); + btn->_font = (_font == NULL) ? _gameRef->_systemFont : _font; + btn->_fontHover = (_fontHover == NULL) ? _gameRef->_systemFont : _fontHover; + btn->_fontPress = btn->_fontHover; + btn->_align = _align; + + if (_gameRef->_touchInterface) + btn->_fontHover = btn->_font; + + + if (_responses[i]->_font) btn->_font = _responses[i]->_font; + + btn->_width = _responseArea.right - _responseArea.left; + if (btn->_width <= 0) btn->_width = _gameRef->_renderer->_width; + } + btn->setName("response"); + btn->correctSize(); + + // make the responses touchable + if (_gameRef->_touchInterface) + btn->_height = MAX(btn->_height, 50); + + //btn->SetListener(this, btn, _responses[i]->_iD); + btn->setListener(this, btn, i); + btn->_visible = false; + _respButtons.add(btn); + + if (_responseArea.bottom - _responseArea.top < btn->_height) { + _gameRef->LOG(0, "Warning: Response '%s' is too high to be displayed within response box. Correcting.", _responses[i]->_text); + _responseArea.bottom += (btn->_height - (_responseArea.bottom - _responseArea.top)); + } + } + } + _ready = false; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdResponseBox::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(RESPONSE_BOX) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(FONT_HOVER) +TOKEN_DEF(FONT) +TOKEN_DEF(AREA) +TOKEN_DEF(HORIZONTAL) +TOKEN_DEF(SPACING) +TOKEN_DEF(WINDOW) +TOKEN_DEF(CURSOR) +TOKEN_DEF(TEXT_ALIGN) +TOKEN_DEF(VERTICAL_ALIGN) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(RESPONSE_BOX) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(FONT_HOVER) + TOKEN_TABLE(FONT) + TOKEN_TABLE(AREA) + TOKEN_TABLE(HORIZONTAL) + TOKEN_TABLE(SPACING) + TOKEN_TABLE(WINDOW) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(TEXT_ALIGN) + TOKEN_TABLE(VERTICAL_ALIGN) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_RESPONSE_BOX) { + _gameRef->LOG(0, "'RESPONSE_BOX' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_WINDOW: + delete _window; + _window = new CUIWindow(_gameRef); + if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { + delete _window; + _window = NULL; + cmd = PARSERR_GENERIC; + } else if (_shieldWindow) _shieldWindow->_parent = _window; + break; + + case TOKEN_FONT: + if (_font) _gameRef->_fontStorage->removeFont(_font); + _font = _gameRef->_fontStorage->addFont((char *)params); + if (!_font) cmd = PARSERR_GENERIC; + break; + + case TOKEN_FONT_HOVER: + if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + _fontHover = _gameRef->_fontStorage->addFont((char *)params); + if (!_fontHover) cmd = PARSERR_GENERIC; + break; + + case TOKEN_AREA: + parser.scanStr((char *)params, "%d,%d,%d,%d", &_responseArea.left, &_responseArea.top, &_responseArea.right, &_responseArea.bottom); + break; + + case TOKEN_HORIZONTAL: + parser.scanStr((char *)params, "%b", &_horizontal); + break; + + case TOKEN_TEXT_ALIGN: + if (scumm_stricmp((char *)params, "center") == 0) _align = TAL_CENTER; + else if (scumm_stricmp((char *)params, "right") == 0) _align = TAL_RIGHT; + else _align = TAL_LEFT; + break; + + case TOKEN_VERTICAL_ALIGN: + if (scumm_stricmp((char *)params, "top") == 0) _verticalAlign = VAL_TOP; + else if (scumm_stricmp((char *)params, "center") == 0) _verticalAlign = VAL_CENTER; + else _verticalAlign = VAL_BOTTOM; + break; + + case TOKEN_SPACING: + parser.scanStr((char *)params, "%d", &_spacing); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new CBSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in RESPONSE_BOX definition"); + return STATUS_FAILED; + } + + if (_window) { + for (int i = 0; i < _window->_widgets.getSize(); i++) { + if (!_window->_widgets[i]->_listenerObject) + _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "RESPONSE_BOX\n"); + buffer->putTextIndent(indent, "{\n"); + + buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _responseArea.left, _responseArea.top, _responseArea.right, _responseArea.bottom); + + if (_font && _font->_filename) + buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->_filename); + if (_fontHover && _fontHover->_filename) + buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->_filename); + + if (_cursor && _cursor->_filename) + buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); + + buffer->putTextIndent(indent + 2, "HORIZONTAL=%s\n", _horizontal ? "TRUE" : "FALSE"); + + switch (_align) { + case TAL_LEFT: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "left"); + break; + case TAL_RIGHT: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "right"); + break; + case TAL_CENTER: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "center"); + break; + default: + error("CAdResponseBox::SaveAsText - Unhandled enum"); + break; + } + + switch (_verticalAlign) { + case VAL_TOP: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "top"); + break; + case VAL_BOTTOM: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "bottom"); + break; + case VAL_CENTER: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "center"); + break; + } + + buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); + + buffer->putTextIndent(indent + 2, "\n"); + + // window + if (_window) _window->saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent + 2, "\n"); + + // editor properties + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::display() { + Rect32 rect = _responseArea; + if (_window) { + CBPlatform::offsetRect(&rect, _window->_posX, _window->_posY); + //_window->display(); + } + + int xxx, yyy, i; + + xxx = rect.left; + yyy = rect.top; + + // shift down if needed + if (!_horizontal) { + int total_height = 0; + for (i = 0; i < _respButtons.getSize(); i++) total_height += (_respButtons[i]->_height + _spacing); + total_height -= _spacing; + + switch (_verticalAlign) { + case VAL_BOTTOM: + if (yyy + total_height < rect.bottom) + yyy = rect.bottom - total_height; + break; + + case VAL_CENTER: + if (yyy + total_height < rect.bottom) + yyy += ((rect.bottom - rect.top) - total_height) / 2; + break; + + case VAL_TOP: + // do nothing + break; + } + } + + // prepare response buttons + bool scrollNeeded = false; + for (i = _scrollOffset; i < _respButtons.getSize(); i++) { + if ((_horizontal && xxx + _respButtons[i]->_width > rect.right) + || (!_horizontal && yyy + _respButtons[i]->_height > rect.bottom)) { + + scrollNeeded = true; + _respButtons[i]->_visible = false; + break; + } + + _respButtons[i]->_visible = true; + _respButtons[i]->_posX = xxx; + _respButtons[i]->_posY = yyy; + + if (_horizontal) { + xxx += (_respButtons[i]->_width + _spacing); + } else { + yyy += (_respButtons[i]->_height + _spacing); + } + } + + // show appropriate scroll buttons + if (_window) { + _window->showWidget("prev", _scrollOffset > 0); + _window->showWidget("next", scrollNeeded); + } + + // go exclusive + if (_shieldWindow) { + _shieldWindow->_posX = _shieldWindow->_posY = 0; + _shieldWindow->_width = _gameRef->_renderer->_width; + _shieldWindow->_height = _gameRef->_renderer->_height; + + _shieldWindow->display(); + } + + // display window + if (_window) _window->display(); + + + // display response buttons + for (i = _scrollOffset; i < _respButtons.getSize(); i++) { + _respButtons[i]->display(); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::listen(CBScriptHolder *param1, uint32 param2) { + CUIObject *obj = (CUIObject *)param1; + + switch (obj->_type) { + case UI_BUTTON: + if (scumm_stricmp(obj->_name, "prev") == 0) { + _scrollOffset--; + } else if (scumm_stricmp(obj->_name, "next") == 0) { + _scrollOffset++; + } else if (scumm_stricmp(obj->_name, "response") == 0) { + if (_waitingScript) _waitingScript->_stack->pushInt(_responses[param2]->_iD); + handleResponse(_responses[param2]); + _waitingScript = NULL; + _gameRef->_state = GAME_RUNNING; + ((CAdGame *)_gameRef)->_stateEx = GAME_NORMAL; + _ready = true; + invalidateButtons(); + clearResponses(); + } else return CBObject::listen(param1, param2); + break; + default: + error("AdResponseBox::Listen - Unhandled enum"); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::persist(CBPersistMgr *persistMgr) { + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_fontHover)); + persistMgr->transfer(TMEMBER(_horizontal)); + persistMgr->transfer(TMEMBER(_lastResponseText)); + persistMgr->transfer(TMEMBER(_lastResponseTextOrig)); + _respButtons.persist(persistMgr); + persistMgr->transfer(TMEMBER(_responseArea)); + _responses.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollOffset)); + persistMgr->transfer(TMEMBER(_shieldWindow)); + persistMgr->transfer(TMEMBER(_spacing)); + persistMgr->transfer(TMEMBER(_waitingScript)); + persistMgr->transfer(TMEMBER(_window)); + + persistMgr->transfer(TMEMBER_INT(_verticalAlign)); + persistMgr->transfer(TMEMBER_INT(_align)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::weedResponses() { + CAdGame *adGame = (CAdGame *)_gameRef; + + for (int i = 0; i < _responses.getSize(); i++) { + switch (_responses[i]->_responseType) { + case RESPONSE_ONCE: + if (adGame->branchResponseUsed(_responses[i]->_iD)) { + delete _responses[i]; + _responses.removeAt(i); + i--; + } + break; + + case RESPONSE_ONCE_GAME: + if (adGame->gameResponseUsed(_responses[i]->_iD)) { + delete _responses[i]; + _responses.removeAt(i); + i--; + } + break; + default: + warning("CAdResponseBox::WeedResponses - Unhandled enum"); + break; + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdResponseBox::setLastResponseText(const char *text, const char *textOrig) { + CBUtils::setString(&_lastResponseText, text); + CBUtils::setString(&_lastResponseTextOrig, textOrig); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::handleResponse(CAdResponse *response) { + setLastResponseText(response->_text, response->_textOrig); + + CAdGame *adGame = (CAdGame *)_gameRef; + + switch (response->_responseType) { + case RESPONSE_ONCE: + adGame->addBranchResponse(response->_iD); + break; + + case RESPONSE_ONCE_GAME: + adGame->addGameResponse(response->_iD); + break; + default: + warning("CAdResponseBox::HandleResponse - Unhandled enum"); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdResponseBox::getNextAccessObject(CBObject *currObject) { + CBArray objects; + getObjects(objects, true); + + if (objects.getSize() == 0) return NULL; + else { + if (currObject != NULL) { + for (int i = 0; i < objects.getSize(); i++) { + if (objects[i] == currObject) { + if (i < objects.getSize() - 1) return objects[i + 1]; + else break; + } + } + } + return objects[0]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdResponseBox::getPrevAccessObject(CBObject *currObject) { + CBArray objects; + getObjects(objects, true); + + if (objects.getSize() == 0) return NULL; + else { + if (currObject != NULL) { + for (int i = objects.getSize() - 1; i >= 0; i--) { + if (objects[i] == currObject) { + if (i > 0) return objects[i - 1]; + else break; + } + } + } + return objects[objects.getSize() - 1]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseBox::getObjects(CBArray &objects, bool interactiveOnly) { + for (int i = 0; i < _respButtons.getSize(); i++) { + objects.add(_respButtons[i]); + } + if (_window) _window->getWindowObjects(objects, interactiveOnly); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_response_box.h b/engines/wintermute/ad/ad_response_box.h new file mode 100644 index 0000000000..7c611ef2d6 --- /dev/null +++ b/engines/wintermute/ad/ad_response_box.h @@ -0,0 +1,87 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSEBOX_H +#define WINTERMUTE_ADRESPONSEBOX_H + + +#include "engines/wintermute/base/base_object.h" + +namespace WinterMute { + +class CUIButton; +class CUIWindow; +class CUIObject; +class CAdResponse; +class CAdResponseBox : public CBObject { +public: + CBObject *getNextAccessObject(CBObject *CurrObject); + CBObject *getPrevAccessObject(CBObject *CurrObject); + bool getObjects(CBArray &objects, bool interactiveOnly); + + bool handleResponse(CAdResponse *response); + void setLastResponseText(const char *text, const char *textOrig); + char *_lastResponseText; + char *_lastResponseTextOrig; + DECLARE_PERSISTENT(CAdResponseBox, CBObject) + CScScript *_waitingScript; + virtual bool listen(CBScriptHolder *param1, uint32 param2); + typedef enum { + EVENT_PREV, + EVENT_NEXT, + EVENT_RESPONSE + } TResponseEvent; + + bool weedResponses(); + bool display(); + int _spacing; + int _scrollOffset; + CBFont *_fontHover; + CBFont *_font; + bool createButtons(); + bool invalidateButtons(); + void clearButtons(); + void clearResponses(); + CAdResponseBox(CBGame *inGame); + virtual ~CAdResponseBox(); + CBArray _responses; + CBArray _respButtons; + CUIWindow *_window; + CUIWindow *_shieldWindow; + bool _horizontal; + Rect32 _responseArea; + int _verticalAlign; + TTextAlign _align; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_response_context.cpp b/engines/wintermute/ad/ad_response_context.cpp new file mode 100644 index 0000000000..02b819d6de --- /dev/null +++ b/engines/wintermute/ad/ad_response_context.cpp @@ -0,0 +1,70 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_response_context.h" +#include "engines/wintermute/base/base_persistence_manager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdResponseContext, false) + +////////////////////////////////////////////////////////////////////////// +CAdResponseContext::CAdResponseContext(CBGame *inGame): CBBase(inGame) { + _iD = 0; + _context = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdResponseContext::~CAdResponseContext() { + delete[] _context; + _context = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdResponseContext::persist(CBPersistMgr *persistMgr) { + persistMgr->transfer(TMEMBER(_gameRef)); + persistMgr->transfer(TMEMBER(_context)); + persistMgr->transfer(TMEMBER(_iD)); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +void CAdResponseContext::setContext(const char *context) { + delete[] _context; + _context = NULL; + if (context) { + _context = new char [strlen(context) + 1]; + if (_context) strcpy(_context, context); + } +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_response_context.h b/engines/wintermute/ad/ad_response_context.h new file mode 100644 index 0000000000..79eaa27640 --- /dev/null +++ b/engines/wintermute/ad/ad_response_context.h @@ -0,0 +1,50 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSECONTEXT_H +#define WINTERMUTE_ADRESPONSECONTEXT_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base.h" + +namespace WinterMute { + +class CAdResponseContext : public CBBase { +public: + void setContext(const char *context); + int _iD; + char *_context; + DECLARE_PERSISTENT(CAdResponseContext, CBBase) + CAdResponseContext(CBGame *inGame); + virtual ~CAdResponseContext(); + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp new file mode 100644 index 0000000000..0ffbaf6919 --- /dev/null +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -0,0 +1,159 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_rot_level.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdRotLevel, false) + + +////////////////////////////////////////////////////////////////////////// +CAdRotLevel::CAdRotLevel(CBGame *inGame): CBObject(inGame) { + _posX = 0; + _rotation = 0.0f; +} + + +////////////////////////////////////////////////////////////////////////// +CAdRotLevel::~CAdRotLevel() { + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRotLevel::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdRotLevel::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ROTATION_LEVEL) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(X) +TOKEN_DEF(ROTATION) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdRotLevel::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ROTATION_LEVEL) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(X) + TOKEN_TABLE(ROTATION) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ROTATION_LEVEL) { + _gameRef->LOG(0, "'ROTATION_LEVEL' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_ROTATION: { + int i; + parser.scanStr((char *)params, "%d", &i); + _rotation = (float)i; + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ROTATION_LEVEL definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRotLevel::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ROTATION_LEVEL {\n"); + buffer->putTextIndent(indent + 2, "X=%d\n", _posX); + buffer->putTextIndent(indent + 2, "ROTATION=%d\n", (int)_rotation); + CBBase::saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdRotLevel::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_rotation)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_rot_level.h b/engines/wintermute/ad/ad_rot_level.h new file mode 100644 index 0000000000..2bd9519d65 --- /dev/null +++ b/engines/wintermute/ad/ad_rot_level.h @@ -0,0 +1,49 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADROTLEVEL_H +#define WINTERMUTE_ADROTLEVEL_H + +#include "engines/wintermute/base/base_object.h" + +namespace WinterMute { + +class CAdRotLevel : public CBObject { +public: + DECLARE_PERSISTENT(CAdRotLevel, CBObject) + CAdRotLevel(CBGame *inGame); + virtual ~CAdRotLevel(); + float _rotation; + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp new file mode 100644 index 0000000000..220d3c4b39 --- /dev/null +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -0,0 +1,157 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_scale_level.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdScaleLevel, false) + +////////////////////////////////////////////////////////////////////////// +CAdScaleLevel::CAdScaleLevel(CBGame *inGame): CBObject(inGame) { + _posY = 0; + _scale = 100; +} + + +////////////////////////////////////////////////////////////////////////// +CAdScaleLevel::~CAdScaleLevel() { + +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScaleLevel::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdScaleLevel::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SCALE_LEVEL) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(Y) +TOKEN_DEF(SCALE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdScaleLevel::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SCALE_LEVEL) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(Y) + TOKEN_TABLE(SCALE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCALE_LEVEL) { + _gameRef->LOG(0, "'SCALE_LEVEL' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_SCALE: { + int i; + parser.scanStr((char *)params, "%d", &i); + _scale = (float)i; + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SCALE_LEVEL definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScaleLevel::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "SCALE_LEVEL {\n"); + buffer->putTextIndent(indent + 2, "Y=%d\n", _posY); + buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_scale); + CBBase::saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScaleLevel::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_scale)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_scale_level.h b/engines/wintermute/ad/ad_scale_level.h new file mode 100644 index 0000000000..4a81c00dda --- /dev/null +++ b/engines/wintermute/ad/ad_scale_level.h @@ -0,0 +1,50 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCALELEVEL_H +#define WINTERMUTE_ADSCALELEVEL_H + + +#include "engines/wintermute/base/base_object.h" + +namespace WinterMute { + +class CAdScaleLevel : public CBObject { +public: + DECLARE_PERSISTENT(CAdScaleLevel, CBObject) + float _scale; + CAdScaleLevel(CBGame *inGame); + virtual ~CAdScaleLevel(); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp new file mode 100644 index 0000000000..11030d6996 --- /dev/null +++ b/engines/wintermute/ad/ad_scene.cpp @@ -0,0 +1,2752 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/ad/ad_actor.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_layer.h" +#include "engines/wintermute/ad/ad_node_state.h" +#include "engines/wintermute/ad/ad_object.h" +#include "engines/wintermute/ad/ad_path.h" +#include "engines/wintermute/ad/ad_path_point.h" +#include "engines/wintermute/ad/ad_rot_level.h" +#include "engines/wintermute/ad/ad_scale_level.h" +#include "engines/wintermute/ad/ad_scene_node.h" +#include "engines/wintermute/ad/ad_scene_state.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_point.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/base_scriptable.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_viewport.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/ui/ui_window.h" +#include "engines/wintermute/utils/utils.h" +#include + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdScene, false) + +////////////////////////////////////////////////////////////////////////// +CAdScene::CAdScene(CBGame *inGame): CBObject(inGame) { + _pfTarget = new CBPoint; + setDefaults(); +} + + +////////////////////////////////////////////////////////////////////////// +CAdScene::~CAdScene() { + cleanup(); + _gameRef->unregisterObject(_fader); + delete _pfTarget; + _pfTarget = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::setDefaults() { + _initialized = false; + _pfReady = true; + _pfTargetPath = NULL; + _pfRequester = NULL; + _mainLayer = NULL; + + _pfPointsNum = 0; + _persistentState = false; + _persistentStateSprites = true; + + _autoScroll = true; + _offsetLeft = _offsetTop = 0; + _targetOffsetLeft = _targetOffsetTop = 0; + + _lastTimeH = _lastTimeV = 0; + _scrollTimeH = _scrollTimeV = 10; + _scrollPixelsH = _scrollPixelsV = 1; + + _pfMaxTime = 15; + + _paralaxScrolling = true; + + // editor settings + _editorMarginH = _editorMarginV = 100; + + _editorColFrame = 0xE0888888; + _editorColEntity = 0xFF008000; + _editorColRegion = 0xFF0000FF; + _editorColBlocked = 0xFF800080; + _editorColWaypoints = 0xFF0000FF; + _editorColEntitySel = 0xFFFF0000; + _editorColRegionSel = 0xFFFF0000; + _editorColBlockedSel = 0xFFFF0000; + _editorColWaypointsSel = 0xFFFF0000; + _editorColScale = 0xFF00FF00; + _editorColDecor = 0xFF00FFFF; + _editorColDecorSel = 0xFFFF0000; + + _editorShowRegions = true; + _editorShowBlocked = true; + _editorShowDecor = true; + _editorShowEntities = true; + _editorShowScale = true; + + _shieldWindow = NULL; + + _fader = new CBFader(_gameRef); + _gameRef->registerObject(_fader); + + _viewport = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::cleanup() { + CBObject::cleanup(); + + _mainLayer = NULL; // reference only + + int i; + + delete _shieldWindow; + _shieldWindow = NULL; + + _gameRef->unregisterObject(_fader); + _fader = NULL; + + for (i = 0; i < _layers.getSize(); i++) + _gameRef->unregisterObject(_layers[i]); + _layers.removeAll(); + + + for (i = 0; i < _waypointGroups.getSize(); i++) + _gameRef->unregisterObject(_waypointGroups[i]); + _waypointGroups.removeAll(); + + for (i = 0; i < _scaleLevels.getSize(); i++) + _gameRef->unregisterObject(_scaleLevels[i]); + _scaleLevels.removeAll(); + + for (i = 0; i < _rotLevels.getSize(); i++) + _gameRef->unregisterObject(_rotLevels[i]); + _rotLevels.removeAll(); + + + for (i = 0; i < _pfPath.getSize(); i++) + delete _pfPath[i]; + _pfPath.removeAll(); + _pfPointsNum = 0; + + for (i = 0; i < _objects.getSize(); i++) + _gameRef->unregisterObject(_objects[i]); + _objects.removeAll(); + + delete _viewport; + _viewport = NULL; + + setDefaults(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject *requester) { + if (!_pfReady) return false; + else { + _pfReady = false; + *_pfTarget = target; + _pfTargetPath = path; + _pfRequester = requester; + + _pfTargetPath->reset(); + _pfTargetPath->setReady(false); + + // prepare working path + int i; + pfPointsStart(); + + // first point + //_pfPath.add(new CAdPathPoint(source.x, source.y, 0)); + + // if we're one pixel stuck, get unstuck + int startX = source.x; + int startY = source.y; + int bestDistance = 1000; + if (isBlockedAt(startX, startY, true, requester)) { + int tolerance = 2; + for (int xxx = startX - tolerance; xxx <= startX + tolerance; xxx++) { + for (int yyy = startY - tolerance; yyy <= startY + tolerance; yyy++) { + if (isWalkableAt(xxx, yyy, true, requester)) { + int distance = abs(xxx - source.x) + abs(yyy - source.y); + if (distance < bestDistance) { + startX = xxx; + startY = yyy; + + bestDistance = distance; + } + } + } + } + } + + pfPointsAdd(startX, startY, 0); + + //CorrectTargetPoint(&target.x, &target.y); + + // last point + //_pfPath.add(new CAdPathPoint(target.x, target.y, INT_MAX)); + pfPointsAdd(target.x, target.y, INT_MAX); + + // active waypoints + for (i = 0; i < _waypointGroups.getSize(); i++) { + if (_waypointGroups[i]->_active) { + pfAddWaypointGroup(_waypointGroups[i], requester); + } + } + + + // free waypoints + for (i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentWptGroup) { + pfAddWaypointGroup(_objects[i]->_currentWptGroup, requester); + } + } + CAdGame *adGame = (CAdGame *)_gameRef; + for (i = 0; i < adGame->_objects.getSize(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentWptGroup) { + pfAddWaypointGroup(adGame->_objects[i]->_currentWptGroup, requester); + } + } + + return true; + } +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::pfAddWaypointGroup(CAdWaypointGroup *wpt, CBObject *requester) { + if (!wpt->_active) return; + + for (int i = 0; i < wpt->_points.getSize(); i++) { + if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) continue; + + //_pfPath.add(new CAdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); + pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX); + } +} + + +////////////////////////////////////////////////////////////////////////// +float CAdScene::getZoomAt(int x, int y) { + float ret = 100; + + bool found = false; + if (_mainLayer) { + for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_blocked && node->_region->pointInRegion(x, y)) { + if (node->_region->_zoom != 0) { + ret = node->_region->_zoom; + found = true; + break; + } + } + } + } + if (!found) ret = getScaleAt(y); + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +uint32 CAdScene::getAlphaAt(int x, int y, bool colorCheck) { + if (!_gameRef->_debugDebugMode) colorCheck = false; + + uint32 ret; + if (colorCheck) ret = 0xFFFF0000; + else ret = 0xFFFFFFFF; + + if (_mainLayer) { + for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { + if (!node->_region->_blocked) ret = node->_region->_alpha; + break; + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::isBlockedAt(int x, int y, bool checkFreeObjects, CBObject *requester) { + bool ret = true; + + + if (checkFreeObjects) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; + } + } + CAdGame *adGame = (CAdGame *)_gameRef; + for (int i = 0; i < adGame->_objects.getSize(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; + } + } + } + + + if (_mainLayer) { + for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + /* + if (Node->_type == OBJECT_REGION && Node->_region->_active && Node->_region->_blocked && Node->_region->PointInRegion(X, Y)) + { + ret = true; + break; + } + */ + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { + if (node->_region->_blocked) { + ret = true; + break; + } else ret = false; + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::isWalkableAt(int x, int y, bool checkFreeObjects, CBObject *requester) { + bool ret = false; + + if (checkFreeObjects) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; + } + } + CAdGame *adGame = (CAdGame *)_gameRef; + for (int i = 0; i < adGame->_objects.getSize(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; + } + } + } + + + if (_mainLayer) { + for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { + if (node->_region->_blocked) { + ret = false; + break; + } else ret = true; + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdScene::getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester) { + double xStep, yStep, x, y; + int xLength, yLength, xCount, yCount; + int x1, y1, x2, y2; + + x1 = p1.x; + y1 = p1.y; + x2 = p2.x; + y2 = p2.y; + + xLength = abs(x2 - x1); + yLength = abs(y2 - y1); + + if (xLength > yLength) { + if (x1 > x2) { + CBUtils::swap(&x1, &x2); + CBUtils::swap(&y1, &y2); + } + + yStep = (double)(y2 - y1) / (double)(x2 - x1); + y = y1; + + for (xCount = x1; xCount < x2; xCount++) { + if (isBlockedAt(xCount, (int)y, true, requester)) return -1; + y += yStep; + } + } else { + if (y1 > y2) { + CBUtils::swap(&x1, &x2); + CBUtils::swap(&y1, &y2); + } + + xStep = (double)(x2 - x1) / (double)(y2 - y1); + x = x1; + + for (yCount = y1; yCount < y2; yCount++) { + if (isBlockedAt((int)x, yCount, true, requester)) return -1; + x += xStep; + } + } + return MAX(xLength, yLength); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::pathFinderStep() { + int i; + // get lowest unmarked + int lowestDist = INT_MAX; + CAdPathPoint *lowestPt = NULL; + + for (i = 0; i < _pfPointsNum; i++) + if (!_pfPath[i]->_marked && _pfPath[i]->_distance < lowestDist) { + lowestDist = _pfPath[i]->_distance; + lowestPt = _pfPath[i]; + } + + if (lowestPt == NULL) { // no path -> terminate PathFinder + _pfReady = true; + _pfTargetPath->setReady(true); + return; + } + + lowestPt->_marked = true; + + // target point marked, generate path and terminate + if (lowestPt->x == _pfTarget->x && lowestPt->y == _pfTarget->y) { + while (lowestPt != NULL) { + _pfTargetPath->_points.insertAt(0, new CBPoint(lowestPt->x, lowestPt->y)); + lowestPt = lowestPt->_origin; + } + + _pfReady = true; + _pfTargetPath->setReady(true); + return; + } + + // otherwise keep on searching + for (i = 0; i < _pfPointsNum; i++) + if (!_pfPath[i]->_marked) { + int j = getPointsDist(*lowestPt, *_pfPath[i], _pfRequester); + if (j != -1 && lowestPt->_distance + j < _pfPath[i]->_distance) { + _pfPath[i]->_distance = lowestPt->_distance + j; + _pfPath[i]->_origin = lowestPt; + } + } +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::initLoop() { +#ifdef _DEBUGxxxx + int nu_steps = 0; + uint32 start = _gameRef->_currentTime; + while (!_pfReady && CBPlatform::getTime() - start <= _pfMaxTime) { + PathFinderStep(); + nu_steps++; + } + if (nu_steps > 0) _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); +#else + uint32 start = _gameRef->_currentTime; + while (!_pfReady && CBPlatform::getTime() - start <= _pfMaxTime) pathFinderStep(); +#endif + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdScene::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + delete[] _filename; + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SCENE) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(LAYER) +TOKEN_DEF(WAYPOINTS) +TOKEN_DEF(EVENTS) +TOKEN_DEF(CURSOR) +TOKEN_DEF(CAMERA) +TOKEN_DEF(ENTITY) +TOKEN_DEF(SCALE_LEVEL) +TOKEN_DEF(ROTATION_LEVEL) +TOKEN_DEF(EDITOR_MARGIN_H) +TOKEN_DEF(EDITOR_MARGIN_V) +TOKEN_DEF(EDITOR_COLOR_FRAME) +TOKEN_DEF(EDITOR_COLOR_ENTITY_SEL) +TOKEN_DEF(EDITOR_COLOR_REGION_SEL) +TOKEN_DEF(EDITOR_COLOR_DECORATION_SEL) +TOKEN_DEF(EDITOR_COLOR_BLOCKED_SEL) +TOKEN_DEF(EDITOR_COLOR_WAYPOINTS_SEL) +TOKEN_DEF(EDITOR_COLOR_REGION) +TOKEN_DEF(EDITOR_COLOR_DECORATION) +TOKEN_DEF(EDITOR_COLOR_BLOCKED) +TOKEN_DEF(EDITOR_COLOR_ENTITY) +TOKEN_DEF(EDITOR_COLOR_WAYPOINTS) +TOKEN_DEF(EDITOR_COLOR_SCALE) +TOKEN_DEF(EDITOR_SHOW_REGIONS) +TOKEN_DEF(EDITOR_SHOW_BLOCKED) +TOKEN_DEF(EDITOR_SHOW_DECORATION) +TOKEN_DEF(EDITOR_SHOW_ENTITIES) +TOKEN_DEF(EDITOR_SHOW_SCALE) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(VIEWPORT) +TOKEN_DEF(PERSISTENT_STATE_SPRITES) +TOKEN_DEF(PERSISTENT_STATE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdScene::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SCENE) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(LAYER) + TOKEN_TABLE(WAYPOINTS) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(CAMERA) + TOKEN_TABLE(ENTITY) + TOKEN_TABLE(SCALE_LEVEL) + TOKEN_TABLE(ROTATION_LEVEL) + TOKEN_TABLE(EDITOR_MARGIN_H) + TOKEN_TABLE(EDITOR_MARGIN_V) + TOKEN_TABLE(EDITOR_COLOR_FRAME) + TOKEN_TABLE(EDITOR_COLOR_ENTITY_SEL) + TOKEN_TABLE(EDITOR_COLOR_REGION_SEL) + TOKEN_TABLE(EDITOR_COLOR_DECORATION_SEL) + TOKEN_TABLE(EDITOR_COLOR_BLOCKED_SEL) + TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS_SEL) + TOKEN_TABLE(EDITOR_COLOR_REGION) + TOKEN_TABLE(EDITOR_COLOR_DECORATION) + TOKEN_TABLE(EDITOR_COLOR_BLOCKED) + TOKEN_TABLE(EDITOR_COLOR_ENTITY) + TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS) + TOKEN_TABLE(EDITOR_COLOR_SCALE) + TOKEN_TABLE(EDITOR_SHOW_REGIONS) + TOKEN_TABLE(EDITOR_SHOW_DECORATION) + TOKEN_TABLE(EDITOR_SHOW_BLOCKED) + TOKEN_TABLE(EDITOR_SHOW_ENTITIES) + TOKEN_TABLE(EDITOR_SHOW_SCALE) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(VIEWPORT) + TOKEN_TABLE(PERSISTENT_STATE_SPRITES) + TOKEN_TABLE(PERSISTENT_STATE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + cleanup(); + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCENE) { + _gameRef->LOG(0, "'SCENE' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + int ar, ag, ab, aa; + char camera[MAX_PATH_LENGTH] = ""; + /* float WaypointHeight = -1.0f; */ + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_LAYER: { + CAdLayer *layer = new CAdLayer(_gameRef); + if (!layer || DID_FAIL(layer->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete layer; + layer = NULL; + } else { + _gameRef->registerObject(layer); + _layers.add(layer); + if (layer->_main) { + _mainLayer = layer; + _width = layer->_width; + _height = layer->_height; + } + } + } + break; + + case TOKEN_WAYPOINTS: { + CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); + if (!wpt || DID_FAIL(wpt->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete wpt; + wpt = NULL; + } else { + _gameRef->registerObject(wpt); + _waypointGroups.add(wpt); + } + } + break; + + case TOKEN_SCALE_LEVEL: { + CAdScaleLevel *sl = new CAdScaleLevel(_gameRef); + if (!sl || DID_FAIL(sl->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete sl; + sl = NULL; + } else { + _gameRef->registerObject(sl); + _scaleLevels.add(sl); + } + } + break; + + case TOKEN_ROTATION_LEVEL: { + CAdRotLevel *rl = new CAdRotLevel(_gameRef); + if (!rl || DID_FAIL(rl->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete rl; + rl = NULL; + } else { + _gameRef->registerObject(rl); + _rotLevels.add(rl); + } + } + break; + + case TOKEN_ENTITY: { + CAdEntity *entity = new CAdEntity(_gameRef); + if (!entity || DID_FAIL(entity->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete entity; + entity = NULL; + } else { + addObject(entity); + } + } + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new CBSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CAMERA: + strcpy(camera, (char *)params); + break; + + case TOKEN_EDITOR_MARGIN_H: + parser.scanStr((char *)params, "%d", &_editorMarginH); + break; + + case TOKEN_EDITOR_MARGIN_V: + parser.scanStr((char *)params, "%d", &_editorMarginV); + break; + + case TOKEN_EDITOR_COLOR_FRAME: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColFrame = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_ENTITY: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColEntity = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_ENTITY_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColEntitySel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_REGION_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColRegionSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_DECORATION_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColDecorSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_BLOCKED_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColBlockedSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_WAYPOINTS_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColWaypointsSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_REGION: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColRegion = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_DECORATION: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColDecor = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_BLOCKED: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColBlocked = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_WAYPOINTS: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColWaypoints = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_SCALE: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColScale = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_SHOW_REGIONS: + parser.scanStr((char *)params, "%b", &_editorShowRegions); + break; + + case TOKEN_EDITOR_SHOW_BLOCKED: + parser.scanStr((char *)params, "%b", &_editorShowBlocked); + break; + + case TOKEN_EDITOR_SHOW_DECORATION: + parser.scanStr((char *)params, "%b", &_editorShowDecor); + break; + + case TOKEN_EDITOR_SHOW_ENTITIES: + parser.scanStr((char *)params, "%b", &_editorShowEntities); + break; + + case TOKEN_EDITOR_SHOW_SCALE: + parser.scanStr((char *)params, "%b", &_editorShowScale); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_VIEWPORT: { + Rect32 rc; + parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); + if (!_viewport) _viewport = new CBViewport(_gameRef); + if (_viewport) _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); + } + + case TOKEN_PERSISTENT_STATE: + parser.scanStr((char *)params, "%b", &_persistentState); + break; + + case TOKEN_PERSISTENT_STATE_SPRITES: + parser.scanStr((char *)params, "%b", &_persistentStateSprites); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SCENE definition"); + return STATUS_FAILED; + } + + if (_mainLayer == NULL) _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", _filename); + + + sortScaleLevels(); + sortRotLevels(); + + _initialized = true; + + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::traverseNodes(bool doUpdate) { + if (!_initialized) return STATUS_OK; + + int j, k; + CAdGame *adGame = (CAdGame *)_gameRef; + + + ////////////////////////////////////////////////////////////////////////// + // prepare viewport + bool PopViewport = false; + if (_viewport && !_gameRef->_editorMode) { + _gameRef->pushViewport(_viewport); + PopViewport = true; + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + _gameRef->pushViewport(adGame->_sceneViewport); + PopViewport = true; + } + + + ////////////////////////////////////////////////////////////////////////// + // *** adjust scroll offset + if (doUpdate) { + /* + if (_autoScroll && _gameRef->_mainObject != NULL) + { + ScrollToObject(_gameRef->_mainObject); + } + */ + + if (_autoScroll) { + // adjust horizontal scroll + if (_gameRef->_timer - _lastTimeH >= _scrollTimeH) { + _lastTimeH = _gameRef->_timer; + if (_offsetLeft < _targetOffsetLeft) { + _offsetLeft += _scrollPixelsH; + _offsetLeft = MIN(_offsetLeft, _targetOffsetLeft); + } else if (_offsetLeft > _targetOffsetLeft) { + _offsetLeft -= _scrollPixelsH; + _offsetLeft = MAX(_offsetLeft, _targetOffsetLeft); + } + } + + // adjust vertical scroll + if (_gameRef->_timer - _lastTimeV >= _scrollTimeV) { + _lastTimeV = _gameRef->_timer; + if (_offsetTop < _targetOffsetTop) { + _offsetTop += _scrollPixelsV; + _offsetTop = MIN(_offsetTop, _targetOffsetTop); + } else if (_offsetTop > _targetOffsetTop) { + _offsetTop -= _scrollPixelsV; + _offsetTop = MAX(_offsetTop, _targetOffsetTop); + } + } + + if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) _ready = true; + } else _ready = true; // not scrolling, i.e. always ready + } + + + + + ////////////////////////////////////////////////////////////////////////// + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + int viewportX, viewportY; + getViewportOffset(&viewportX, &viewportY); + + int scrollableX = _width - viewportWidth; + int scrollableY = _height - viewportHeight; + + double widthRatio = scrollableX <= 0 ? 0 : ((double)(_offsetLeft) / (double)scrollableX); + double heightRatio = scrollableY <= 0 ? 0 : ((double)(_offsetTop) / (double)scrollableY); + + int origX, origY; + _gameRef->getOffset(&origX, &origY); + + + + ////////////////////////////////////////////////////////////////////////// + // *** display/update everything + _gameRef->_renderer->setup2D(); + + // for each layer + /* int MainOffsetX = 0; */ + /* int MainOffsetY = 0; */ + + for (j = 0; j < _layers.getSize(); j++) { + if (!_layers[j]->_active) continue; + + // make layer exclusive + if (!doUpdate) { + if (_layers[j]->_closeUp && !_gameRef->_editorMode) { + if (!_shieldWindow) _shieldWindow = new CUIWindow(_gameRef); + if (_shieldWindow) { + _shieldWindow->_posX = _shieldWindow->_posY = 0; + _shieldWindow->_width = _gameRef->_renderer->_width; + _shieldWindow->_height = _gameRef->_renderer->_height; + _shieldWindow->display(); + } + } + } + + if (_paralaxScrolling) { + int offsetX = (int)(widthRatio * (_layers[j]->_width - viewportWidth) - viewportX); + int offsetY = (int)(heightRatio * (_layers[j]->_height - viewportHeight) - viewportY); + _gameRef->setOffset(offsetX, offsetY); + + _gameRef->_offsetPercentX = (float)offsetX / ((float)_layers[j]->_width - viewportWidth) * 100.0f; + _gameRef->_offsetPercentY = (float)offsetY / ((float)_layers[j]->_height - viewportHeight) * 100.0f; + + //_gameRef->QuickMessageForm("%d %f", OffsetX+ViewportX, _gameRef->_offsetPercentX); + } else { + _gameRef->setOffset(_offsetLeft - viewportX, _offsetTop - viewportY); + + _gameRef->_offsetPercentX = (float)(_offsetLeft - viewportX) / ((float)_layers[j]->_width - viewportWidth) * 100.0f; + _gameRef->_offsetPercentY = (float)(_offsetTop - viewportY) / ((float)_layers[j]->_height - viewportHeight) * 100.0f; + } + + + // for each node + for (k = 0; k < _layers[j]->_nodes.getSize(); k++) { + CAdSceneNode *node = _layers[j]->_nodes[k]; + switch (node->_type) { + case OBJECT_ENTITY: + if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) { + _gameRef->_renderer->setup2D(); + + if (doUpdate) node->_entity->update(); + else node->_entity->display(); + } + break; + + case OBJECT_REGION: { + if (node->_region->_blocked) break; + if (node->_region->_decoration) break; + + if (!doUpdate) displayRegionContent(node->_region); + } + break; + default: + error("AdScene::TraverseNodes - Unhandled enum"); + break; + } // switch + } // each node + + // display/update all objects which are off-regions + if (_layers[j]->_main) { + if (doUpdate) { + updateFreeObjects(); + } else { + displayRegionContent(NULL); + } + } + } // each layer + + + // restore state + _gameRef->setOffset(origX, origY); + _gameRef->_renderer->setup2D(); + + // display/update fader + if (_fader) { + if (doUpdate) _fader->update(); + else _fader->display(); + } + + if (PopViewport) _gameRef->popViewport(); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::display() { + return traverseNodes(false); +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::updateFreeObjects() { + CAdGame *adGame = (CAdGame *)_gameRef; + bool is3DSet; + + // *** update all active objects + is3DSet = false; + for (int i = 0; i < adGame->_objects.getSize(); i++) { + if (!adGame->_objects[i]->_active) continue; + + adGame->_objects[i]->update(); + adGame->_objects[i]->_drawn = false; + } + + + for (int i = 0; i < _objects.getSize(); i++) { + if (!_objects[i]->_active) continue; + + _objects[i]->update(); + _objects[i]->_drawn = false; + } + + + if (_autoScroll && _gameRef->_mainObject != NULL) { + scrollToObject(_gameRef->_mainObject); + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::displayRegionContent(CAdRegion *region, bool display3DOnly) { + CAdGame *adGame = (CAdGame *)_gameRef; + CBArray objects; + CAdObject *obj; + + // global objects + for (int i = 0; i < adGame->_objects.getSize(); i++) { + obj = adGame->_objects[i]; + if (obj->_active && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + objects.add(obj); + } + } + + // scene objects + for (int i = 0; i < _objects.getSize(); i++) { + obj = _objects[i]; + if (obj->_active && !obj->_editorOnly && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + objects.add(obj); + } + } + + // sort by _posY + qsort(objects.getData(), objects.getSize(), sizeof(CAdObject *), CAdScene::compareObjs); + + // display them + for (int i = 0; i < objects.getSize(); i++) { + obj = objects[i]; + + if (display3DOnly && !obj->_is3D) continue; + + _gameRef->_renderer->setup2D(); + + if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); + obj->_drawn = true; + } + + + // display design only objects + if (!display3DOnly) { + if (_gameRef->_editorMode && region == NULL) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i]->_editorOnly) { + _objects[i]->display(); + _objects[i]->_drawn = true; + } + } + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +int CAdScene::compareObjs(const void *obj1, const void *obj2) { + CAdObject *object1 = *(CAdObject **)obj1; + CAdObject *object2 = *(CAdObject **)obj2; + + if (object1->_posY < object2->_posY) return -1; + else if (object1->_posY > object2->_posY) return 1; + else return 0; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::displayRegionContentOld(CAdRegion *region) { + CAdGame *adGame = (CAdGame *)_gameRef; + CAdObject *obj; + + // display all objects in region sorted by _posY + do { + obj = NULL; + int minY = INT_MAX; + + // global objects + for (int i = 0; i < adGame->_objects.getSize(); i++) { + if (adGame->_objects[i]->_active && !adGame->_objects[i]->_drawn && adGame->_objects[i]->_posY < minY && (adGame->_objects[i]->_stickRegion == region || region == NULL || (adGame->_objects[i]->_stickRegion == NULL && region->pointInRegion(adGame->_objects[i]->_posX, adGame->_objects[i]->_posY)))) { + obj = adGame->_objects[i]; + minY = adGame->_objects[i]->_posY; + } + } + + // scene objects + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && !_objects[i]->_editorOnly && !_objects[i]->_drawn && _objects[i]->_posY < minY && (_objects[i]->_stickRegion == region || region == NULL || (_objects[i]->_stickRegion == NULL && region->pointInRegion(_objects[i]->_posX, _objects[i]->_posY)))) { + obj = _objects[i]; + minY = _objects[i]->_posY; + } + } + + + if (obj != NULL) { + _gameRef->_renderer->setup2D(); + + if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); + obj->_drawn = true; + } + } while (obj != NULL); + + + // design only objects + if (_gameRef->_editorMode && region == NULL) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_active && _objects[i]->_editorOnly) { + _objects[i]->display(); + _objects[i]->_drawn = true; + } + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::update() { + return traverseNodes(true); +} + +////////////////////////////////////////////////////////////////////////// +void CAdScene::scrollTo(int offsetX, int offsetY) { + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + int origOffsetLeft = _targetOffsetLeft; + int origOffsetTop = _targetOffsetTop; + + _targetOffsetLeft = MAX(0, offsetX - viewportWidth / 2); + _targetOffsetLeft = MIN(_targetOffsetLeft, _width - viewportWidth); + + _targetOffsetTop = MAX(0, offsetY - viewportHeight / 2); + _targetOffsetTop = MIN(_targetOffsetTop, _height - viewportHeight); + + + if (_gameRef->_mainObject && _gameRef->_mainObject->_is3D) { + if (abs(origOffsetLeft - _targetOffsetLeft) < 5) _targetOffsetLeft = origOffsetLeft; + if (abs(origOffsetTop - _targetOffsetTop) < 5) _targetOffsetTop = origOffsetTop; + //_targetOffsetTop = 0; + } + + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::scrollToObject(CBObject *object) { + if (object) scrollTo(object->_posX, object->_posY - object->getHeight() / 2); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::skipToObject(CBObject *object) { + if (object) skipTo(object->_posX, object->_posY - object->getHeight() / 2); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::skipTo(int offsetX, int offsetY) { + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetLeft = MAX(0, offsetX - viewportWidth / 2); + _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); + + _offsetTop = MAX(0, offsetY - viewportHeight / 2); + _offsetTop = MIN(_offsetTop, _height - viewportHeight); + + _targetOffsetLeft = _offsetLeft; + _targetOffsetTop = _offsetTop; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // LoadActor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "LoadActor") == 0) { + stack->correctParams(1); + CAdActor *act = new CAdActor(_gameRef); + if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { + addObject(act); + stack->pushNative(act, true); + } else { + delete act; + act = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadEntity") == 0) { + stack->correctParams(1); + CAdEntity *ent = new CAdEntity(_gameRef); + if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { + addObject(ent); + stack->pushNative(ent, true); + } else { + delete ent; + ent = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdEntity *ent = new CAdEntity(_gameRef); + addObject(ent); + if (!val->isNULL()) ent->setName(val->getString()); + stack->pushNative(ent, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadObject / UnloadActor / UnloadEntity / UnloadActor3D / DeleteEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "UnloadActor3D") == 0 || strcmp(name, "DeleteEntity") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + CAdObject *obj = (CAdObject *)val->getNative(); + removeObject(obj); + if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SkipTo + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SkipTo") == 0) { + stack->correctParams(2); + CScValue *val1 = stack->pop(); + CScValue *val2 = stack->pop(); + if (val1->isNative()) { + skipToObject((CBObject *)val1->getNative()); + } else { + skipTo(val1->getInt(), val2->getInt()); + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollTo / ScrollToAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollTo") == 0 || strcmp(name, "ScrollToAsync") == 0) { + stack->correctParams(2); + CScValue *val1 = stack->pop(); + CScValue *val2 = stack->pop(); + if (val1->isNative()) { + scrollToObject((CBObject *)val1->getNative()); + } else { + scrollTo(val1->getInt(), val2->getInt()); + } + if (strcmp(name, "ScrollTo") == 0) script->waitForExclusive(this); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetLayer") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + if (val->isInt()) { + int layer = val->getInt(); + if (layer < 0 || layer >= _layers.getSize()) stack->pushNULL(); + else stack->pushNative(_layers[layer], true); + } else { + const char *LayerName = val->getString(); + bool LayerFound = false; + for (int i = 0; i < _layers.getSize(); i++) { + if (scumm_stricmp(LayerName, _layers[i]->_name) == 0) { + stack->pushNative(_layers[i], true); + LayerFound = true; + break; + } + } + if (!LayerFound) stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetWaypointGroup + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetWaypointGroup") == 0) { + stack->correctParams(1); + int group = stack->pop()->getInt(); + if (group < 0 || group >= _waypointGroups.getSize()) stack->pushNULL(); + else stack->pushNative(_waypointGroups[group], true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNode") == 0) { + stack->correctParams(1); + const char *nodeName = stack->pop()->getString(); + + CBObject *node = getNodeByName(nodeName); + if (node) stack->pushNative((CBScriptable *)node, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFreeNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFreeNode") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdObject *ret = NULL; + if (val->isInt()) { + int index = val->getInt(); + if (index >= 0 && index < _objects.getSize()) ret = _objects[index]; + } else { + const char *nodeName = val->getString(); + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i] && _objects[i]->_name && scumm_stricmp(_objects[i]->_name, nodeName) == 0) { + ret = _objects[i]; + break; + } + } + } + if (ret) stack->pushNative(ret, true); + else stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetRegionAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetRegionAt") == 0) { + stack->correctParams(3); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + CScValue *val = stack->pop(); + + bool includeDecors = false; + if (!val->isNULL()) includeDecors = val->getBool(); + + if (_mainLayer) { + for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { + if (node->_region->_decoration && !includeDecors) continue; + + stack->pushNative(node->_region, true); + return STATUS_OK; + } + } + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsBlockedAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsBlockedAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushBool(isBlockedAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsWalkableAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsWalkableAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushBool(isWalkableAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetScaleAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetScaleAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushFloat(getZoomAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetRotationAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetRotationAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushFloat(getRotationAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsScrolling + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsScrolling") == 0) { + stack->correctParams(0); + bool ret = false; + if (_autoScroll) { + if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) ret = true; + } + + stack->pushBool(ret); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // FadeOut / FadeOutAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "FadeOut") == 0 || strcmp(name, "FadeOutAsync") == 0) { + stack->correctParams(5); + uint32 duration = stack->pop()->getInt(500); + byte red = stack->pop()->getInt(0); + byte green = stack->pop()->getInt(0); + byte blue = stack->pop()->getInt(0); + byte alpha = stack->pop()->getInt(0xFF); + + _fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration); + if (strcmp(name, "FadeOutAsync") != 0) script->waitFor(_fader); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // FadeIn / FadeInAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "FadeIn") == 0 || strcmp(name, "FadeInAsync") == 0) { + stack->correctParams(5); + uint32 duration = stack->pop()->getInt(500); + byte red = stack->pop()->getInt(0); + byte green = stack->pop()->getInt(0); + byte blue = stack->pop()->getInt(0); + byte alpha = stack->pop()->getInt(0xFF); + + _fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration); + if (strcmp(name, "FadeInAsync") != 0) script->waitFor(_fader); + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFadeColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFadeColor") == 0) { + stack->correctParams(0); + stack->pushInt(_fader->getCurrentColor()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsPointInViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsPointInViewport") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + stack->pushBool(pointInViewport(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetViewport") == 0) { + stack->correctParams(4); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + int width = stack->pop()->getInt(); + int height = stack->pop()->getInt(); + + if (width <= 0) width = _gameRef->_renderer->_width; + if (height <= 0) height = _gameRef->_renderer->_height; + + if (!_viewport) _viewport = new CBViewport(_gameRef); + if (_viewport) _viewport->setRect(x, y, x + width, y + height); + + stack->pushBool(true); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddLayer") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdLayer *layer = new CAdLayer(_gameRef); + if (!val->isNULL()) layer->setName(val->getString()); + if (_mainLayer) { + layer->_width = _mainLayer->_width; + layer->_height = _mainLayer->_height; + } + _layers.add(layer); + _gameRef->registerObject(layer); + + stack->pushNative(layer, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InsertLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InsertLayer") == 0) { + stack->correctParams(2); + int index = stack->pop()->getInt(); + CScValue *val = stack->pop(); + + CAdLayer *layer = new CAdLayer(_gameRef); + if (!val->isNULL()) layer->setName(val->getString()); + if (_mainLayer) { + layer->_width = _mainLayer->_width; + layer->_height = _mainLayer->_height; + } + if (index < 0) index = 0; + if (index <= _layers.getSize() - 1) _layers.insertAt(index, layer); + else _layers.add(layer); + + _gameRef->registerObject(layer); + + stack->pushNative(layer, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteLayer") == 0) { + stack->correctParams(1); + CScValue *val = stack->pop(); + + CAdLayer *toDelete = NULL; + if (val->isNative()) { + CBScriptable *temp = val->getNative(); + for (int i = 0; i < _layers.getSize(); i++) { + if (_layers[i] == temp) { + toDelete = _layers[i]; + break; + } + } + } else { + int index = val->getInt(); + if (index >= 0 && index < _layers.getSize()) { + toDelete = _layers[index]; + } + } + if (toDelete == NULL) { + stack->pushBool(false); + return STATUS_OK; + } + + if (toDelete->_main) { + script->runtimeError("Scene.DeleteLayer - cannot delete main scene layer"); + stack->pushBool(false); + return STATUS_OK; + } + + for (int i = 0; i < _layers.getSize(); i++) { + if (_layers[i] == toDelete) { + _layers.removeAt(i); + _gameRef->unregisterObject(toDelete); + break; + } + } + stack->pushBool(true); + return STATUS_OK; + } + + else return CBObject::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdScene::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("scene"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumLayers (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumLayers") == 0) { + _scValue->setInt(_layers.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumWaypointGroups (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumWaypointGroups") == 0) { + _scValue->setInt(_waypointGroups.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MainLayer (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MainLayer") == 0) { + if (_mainLayer) _scValue->setNative(_mainLayer, true); + else _scValue->setNULL(); + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumFreeNodes (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumFreeNodes") == 0) { + _scValue->setInt(_objects.getSize()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MouseX (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MouseX") == 0) { + int viewportX; + getViewportOffset(&viewportX); + + _scValue->setInt(_gameRef->_mousePos.x + _offsetLeft - viewportX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MouseY (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MouseY") == 0) { + int viewportY; + getViewportOffset(NULL, &viewportY); + + _scValue->setInt(_gameRef->_mousePos.y + _offsetTop - viewportY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AutoScroll + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AutoScroll") == 0) { + _scValue->setBool(_autoScroll); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentState + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentState") == 0) { + _scValue->setBool(_persistentState); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentStateSprites + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentStateSprites") == 0) { + _scValue->setBool(_persistentStateSprites); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsX") == 0) { + _scValue->setInt(_scrollPixelsH); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsY") == 0) { + _scValue->setInt(_scrollPixelsV); + return _scValue; + } + + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedX") == 0) { + _scValue->setInt(_scrollTimeH); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedY") == 0) { + _scValue->setInt(_scrollTimeV); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetX") == 0) { + _scValue->setInt(_offsetLeft); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetY") == 0) { + _scValue->setInt(_offsetTop); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Width (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + if (_mainLayer) _scValue->setInt(_mainLayer->_width); + else _scValue->setInt(0); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Height (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + if (_mainLayer) _scValue->setInt(_mainLayer->_height); + else _scValue->setInt(0); + return _scValue; + } + + else return CBObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AutoScroll + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AutoScroll") == 0) { + _autoScroll = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentState + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentState") == 0) { + _persistentState = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentStateSprites + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentStateSprites") == 0) { + _persistentStateSprites = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsX") == 0) { + _scrollPixelsH = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsY") == 0) { + _scrollPixelsV = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedX") == 0) { + _scrollTimeH = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedY") == 0) { + _scrollTimeV = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetX") == 0) { + _offsetLeft = value->getInt(); + + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetLeft = MAX(0, _offsetLeft - viewportWidth / 2); + _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); + _targetOffsetLeft = _offsetLeft; + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetY") == 0) { + _offsetTop = value->getInt(); + + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetTop = MAX(0, _offsetTop - viewportHeight / 2); + _offsetTop = MIN(_offsetTop, _height - viewportHeight); + _targetOffsetTop = _offsetTop; + + return STATUS_OK; + } + + else return CBObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdScene::scToString() { + return "[scene object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::addObject(CAdObject *object) { + _objects.add(object); + return _gameRef->registerObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::removeObject(CAdObject *object) { + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i] == object) { + _objects.removeAt(i); + return _gameRef->unregisterObject(object); + } + } + return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::saveAsText(CBDynBuffer *buffer, int indent) { + int i; + + buffer->putTextIndent(indent, "SCENE {\n"); + + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + + if (_persistentState) + buffer->putTextIndent(indent + 2, "PERSISTENT_STATE=%s\n", _persistentState ? "TRUE" : "FALSE"); + + if (!_persistentStateSprites) + buffer->putTextIndent(indent + 2, "PERSISTENT_STATE_SPRITES=%s\n", _persistentStateSprites ? "TRUE" : "FALSE"); + + + // scripts + for (i = 0; i < _scripts.getSize(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + buffer->putTextIndent(indent + 2, "\n"); + + // properties + if (_scProp) _scProp->saveAsText(buffer, indent + 2); + + // viewport + if (_viewport) { + Rect32 *rc = _viewport->getRect(); + buffer->putTextIndent(indent + 2, "VIEWPORT { %d, %d, %d, %d }\n", rc->left, rc->top, rc->right, rc->bottom); + } + + + + // editor settings + buffer->putTextIndent(indent + 2, "; ----- editor settings\n"); + buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_H=%d\n", _editorMarginH); + buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_V=%d\n", _editorMarginV); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_FRAME { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColFrame), RGBCOLGetG(_editorColFrame), RGBCOLGetB(_editorColFrame), RGBCOLGetA(_editorColFrame)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntitySel), RGBCOLGetG(_editorColEntitySel), RGBCOLGetB(_editorColEntitySel), RGBCOLGetA(_editorColEntitySel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegionSel), RGBCOLGetG(_editorColRegionSel), RGBCOLGetB(_editorColRegionSel), RGBCOLGetA(_editorColRegionSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlockedSel), RGBCOLGetG(_editorColBlockedSel), RGBCOLGetB(_editorColBlockedSel), RGBCOLGetA(_editorColBlockedSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecorSel), RGBCOLGetG(_editorColDecorSel), RGBCOLGetB(_editorColDecorSel), RGBCOLGetA(_editorColDecorSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypointsSel), RGBCOLGetG(_editorColWaypointsSel), RGBCOLGetB(_editorColWaypointsSel), RGBCOLGetA(_editorColWaypointsSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntity), RGBCOLGetG(_editorColEntity), RGBCOLGetB(_editorColEntity), RGBCOLGetA(_editorColEntity)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegion), RGBCOLGetG(_editorColRegion), RGBCOLGetB(_editorColRegion), RGBCOLGetA(_editorColRegion)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecor), RGBCOLGetG(_editorColDecor), RGBCOLGetB(_editorColDecor), RGBCOLGetA(_editorColDecor)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlocked), RGBCOLGetG(_editorColBlocked), RGBCOLGetB(_editorColBlocked), RGBCOLGetA(_editorColBlocked)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypoints), RGBCOLGetG(_editorColWaypoints), RGBCOLGetB(_editorColWaypoints), RGBCOLGetA(_editorColWaypoints)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_SCALE { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColScale), RGBCOLGetG(_editorColScale), RGBCOLGetB(_editorColScale), RGBCOLGetA(_editorColScale)); + + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_REGIONS=%s\n", _editorShowRegions ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_BLOCKED=%s\n", _editorShowBlocked ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_DECORATION=%s\n", _editorShowDecor ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_ENTITIES=%s\n", _editorShowEntities ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_SCALE=%s\n", _editorShowScale ? "TRUE" : "FALSE"); + + buffer->putTextIndent(indent + 2, "\n"); + + CBBase::saveAsText(buffer, indent + 2); + + // waypoints + buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); + for (i = 0; i < _waypointGroups.getSize(); i++) _waypointGroups[i]->saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent + 2, "\n"); + + // layers + buffer->putTextIndent(indent + 2, "; ----- layers\n"); + for (i = 0; i < _layers.getSize(); i++) _layers[i]->saveAsText(buffer, indent + 2); + + // scale levels + buffer->putTextIndent(indent + 2, "; ----- scale levels\n"); + for (i = 0; i < _scaleLevels.getSize(); i++) _scaleLevels[i]->saveAsText(buffer, indent + 2); + + // rotation levels + buffer->putTextIndent(indent + 2, "; ----- rotation levels\n"); + for (i = 0; i < _rotLevels.getSize(); i++) _rotLevels[i]->saveAsText(buffer, indent + 2); + + + buffer->putTextIndent(indent + 2, "\n"); + + // free entities + buffer->putTextIndent(indent + 2, "; ----- free entities\n"); + for (i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY) { + _objects[i]->saveAsText(buffer, indent + 2); + + } + } + + + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::sortScaleLevels() { + bool changed; + do { + changed = false; + for (int i = 0; i < _scaleLevels.getSize() - 1; i++) { + if (_scaleLevels[i]->_posY > _scaleLevels[i + 1]->_posY) { + CAdScaleLevel *sl = _scaleLevels[i]; + _scaleLevels[i] = _scaleLevels[i + 1]; + _scaleLevels[i + 1] = sl; + + changed = true; + } + } + + } while (changed); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::sortRotLevels() { + bool changed; + do { + changed = false; + for (int i = 0; i < _rotLevels.getSize() - 1; i++) { + if (_rotLevels[i]->_posX > _rotLevels[i + 1]->_posX) { + CAdRotLevel *rl = _rotLevels[i]; + _rotLevels[i] = _rotLevels[i + 1]; + _rotLevels[i + 1] = rl; + + changed = true; + } + } + + } while (changed); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +float CAdScene::getScaleAt(int Y) { + CAdScaleLevel *prev = NULL; + CAdScaleLevel *next = NULL; + + for (int i = 0; i < _scaleLevels.getSize(); i++) { + /* CAdScaleLevel *xxx = _scaleLevels[i];*/ + /* int j = _scaleLevels.getSize(); */ + if (_scaleLevels[i]->_posY < Y) prev = _scaleLevels[i]; + else { + next = _scaleLevels[i]; + break; + } + } + + if (prev == NULL || next == NULL) return 100; + + int delta_y = next->_posY - prev->_posY; + float delta_scale = next->_scale - prev->_scale; + Y -= prev->_posY; + + float percent = (float)Y / ((float)delta_y / 100.0f); + return prev->_scale + delta_scale / 100 * percent; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::persist(CBPersistMgr *persistMgr) { + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_autoScroll)); + persistMgr->transfer(TMEMBER(_editorColBlocked)); + persistMgr->transfer(TMEMBER(_editorColBlockedSel)); + persistMgr->transfer(TMEMBER(_editorColDecor)); + persistMgr->transfer(TMEMBER(_editorColDecorSel)); + persistMgr->transfer(TMEMBER(_editorColEntity)); + persistMgr->transfer(TMEMBER(_editorColEntitySel)); + persistMgr->transfer(TMEMBER(_editorColFrame)); + persistMgr->transfer(TMEMBER(_editorColRegion)); + persistMgr->transfer(TMEMBER(_editorColRegionSel)); + persistMgr->transfer(TMEMBER(_editorColScale)); + persistMgr->transfer(TMEMBER(_editorColWaypoints)); + persistMgr->transfer(TMEMBER(_editorColWaypointsSel)); + persistMgr->transfer(TMEMBER(_editorMarginH)); + persistMgr->transfer(TMEMBER(_editorMarginV)); + persistMgr->transfer(TMEMBER(_editorShowBlocked)); + persistMgr->transfer(TMEMBER(_editorShowDecor)); + persistMgr->transfer(TMEMBER(_editorShowEntities)); + persistMgr->transfer(TMEMBER(_editorShowRegions)); + persistMgr->transfer(TMEMBER(_editorShowScale)); + persistMgr->transfer(TMEMBER(_fader)); + persistMgr->transfer(TMEMBER(_height)); + persistMgr->transfer(TMEMBER(_initialized)); + persistMgr->transfer(TMEMBER(_lastTimeH)); + persistMgr->transfer(TMEMBER(_lastTimeV)); + _layers.persist(persistMgr); + persistMgr->transfer(TMEMBER(_mainLayer)); + _objects.persist(persistMgr); + persistMgr->transfer(TMEMBER(_offsetLeft)); + persistMgr->transfer(TMEMBER(_offsetTop)); + persistMgr->transfer(TMEMBER(_paralaxScrolling)); + persistMgr->transfer(TMEMBER(_persistentState)); + persistMgr->transfer(TMEMBER(_persistentStateSprites)); + persistMgr->transfer(TMEMBER(_pfMaxTime)); + _pfPath.persist(persistMgr); + persistMgr->transfer(TMEMBER(_pfPointsNum)); + persistMgr->transfer(TMEMBER(_pfReady)); + persistMgr->transfer(TMEMBER(_pfRequester)); + persistMgr->transfer(TMEMBER(_pfTarget)); + persistMgr->transfer(TMEMBER(_pfTargetPath)); + _rotLevels.persist(persistMgr); + _scaleLevels.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollPixelsH)); + persistMgr->transfer(TMEMBER(_scrollPixelsV)); + persistMgr->transfer(TMEMBER(_scrollTimeH)); + persistMgr->transfer(TMEMBER(_scrollTimeV)); + persistMgr->transfer(TMEMBER(_shieldWindow)); + persistMgr->transfer(TMEMBER(_targetOffsetLeft)); + persistMgr->transfer(TMEMBER(_targetOffsetTop)); + _waypointGroups.persist(persistMgr); + persistMgr->transfer(TMEMBER(_viewport)); + persistMgr->transfer(TMEMBER(_width)); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::afterLoad() { + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, CBObject *requester) { + double xStep, yStep, x, y; + int xLength, yLength, xCount, yCount; + int x1, y1, x2, y2; + + x1 = *targetX; + y1 = *targetY; + x2 = startX; + y2 = startY; + + + xLength = abs(x2 - x1); + yLength = abs(y2 - y1); + + if (xLength > yLength) { + /* + if (X1 > X2) + { + Swap(&X1, &X2); + Swap(&Y1, &Y2); + } + */ + + yStep = fabs((double)(y2 - y1) / (double)(x2 - x1)); + y = y1; + + for (xCount = x1; xCount < x2; xCount++) { + if (isWalkableAt(xCount, (int)y, checkFreeObjects, requester)) { + *targetX = xCount; + *targetY = (int)y; + return STATUS_OK; + } + y += yStep; + } + } else { + /* + if (Y1 > Y2) { + Swap(&X1, &X2); + Swap(&Y1, &Y2); + } + */ + + xStep = fabs((double)(x2 - x1) / (double)(y2 - y1)); + x = x1; + + for (yCount = y1; yCount < y2; yCount++) { + if (isWalkableAt((int)x, yCount, checkFreeObjects, requester)) { + *targetX = (int)x; + *targetY = yCount; + return STATUS_OK; + } + x += xStep; + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, bool checkFreeObjects, CBObject *requester) { + int x = *argX; + int y = *argY; + + if (isWalkableAt(x, y, checkFreeObjects, requester) || !_mainLayer) { + return STATUS_OK; + } + + // right + int length_right = 0; + bool found_right = false; + for (x = *argX, y = *argY; x < _mainLayer->_width; x++, length_right++) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x - 5, y, checkFreeObjects, requester)) { + found_right = true; + break; + } + } + + // left + int length_left = 0; + bool found_left = false; + for (x = *argX, y = *argY; x >= 0; x--, length_left--) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x + 5, y, checkFreeObjects, requester)) { + found_left = true; + break; + } + } + + // up + int length_up = 0; + bool found_up = false; + for (x = *argX, y = *argY; y >= 0; y--, length_up--) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y + 5, checkFreeObjects, requester)) { + found_up = true; + break; + } + } + + // down + int length_down = 0; + bool found_down = false; + for (x = *argX, y = *argY; y < _mainLayer->_height; y++, length_down++) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y - 5, checkFreeObjects, requester)) { + found_down = true; + break; + } + } + + if (!found_left && !found_right && !found_up && !found_down) { + return STATUS_OK; + } + + int OffsetX = INT_MAX, OffsetY = INT_MAX; + + if (found_left && found_right) { + if (abs(length_left) < abs(length_right)) OffsetX = length_left; + else OffsetX = length_right; + } else if (found_left) OffsetX = length_left; + else if (found_right) OffsetX = length_right; + + if (found_up && found_down) { + if (abs(length_up) < abs(length_down)) OffsetY = length_up; + else OffsetY = length_down; + } else if (found_up) OffsetY = length_up; + else if (found_down) OffsetY = length_down; + + if (abs(OffsetX) < abs(OffsetY)) + *argX = *argX + OffsetX; + else + *argY = *argY + OffsetY; + + if (!isWalkableAt(*argX, *argY)) return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); + else return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::pfPointsStart() { + _pfPointsNum = 0; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::pfPointsAdd(int x, int y, int distance) { + if (_pfPointsNum >= _pfPath.getSize()) { + _pfPath.add(new CAdPathPoint(x, y, distance)); + } else { + _pfPath[_pfPointsNum]->x = x; + _pfPath[_pfPointsNum]->y = y; + _pfPath[_pfPointsNum]->_distance = distance; + _pfPath[_pfPointsNum]->_marked = false; + _pfPath[_pfPointsNum]->_origin = NULL; + } + + _pfPointsNum++; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getViewportOffset(int *offsetX, int *offsetY) { + CAdGame *adGame = (CAdGame *)_gameRef; + if (_viewport && !_gameRef->_editorMode) { + if (offsetX) *offsetX = _viewport->_offsetX; + if (offsetY) *offsetY = _viewport->_offsetY; + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + if (offsetX) *offsetX = adGame->_sceneViewport->_offsetX; + if (offsetY) *offsetY = adGame->_sceneViewport->_offsetY; + } else { + if (offsetX) *offsetX = 0; + if (offsetY) *offsetY = 0; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getViewportSize(int *width, int *height) { + CAdGame *adGame = (CAdGame *)_gameRef; + if (_viewport && !_gameRef->_editorMode) { + if (width) *width = _viewport->getWidth(); + if (height) *height = _viewport->getHeight(); + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + if (width) *width = adGame->_sceneViewport->getWidth(); + if (height) *height = adGame->_sceneViewport->getHeight(); + } else { + if (width) *width = _gameRef->_renderer->_width; + if (height) *height = _gameRef->_renderer->_height; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdScene::getOffsetLeft() { + int viewportX; + getViewportOffset(&viewportX); + + return _offsetLeft - viewportX; +} + + +////////////////////////////////////////////////////////////////////////// +int CAdScene::getOffsetTop() { + int viewportY; + getViewportOffset(NULL, &viewportY); + + return _offsetTop - viewportY; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::pointInViewport(int x, int y) { + int left, top, width, height; + + getViewportOffset(&left, &top); + getViewportSize(&width, &height); + + return x >= left && x <= left + width && y >= top && y <= top + height; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdScene::setOffset(int offsetLeft, int offsetTop) { + _offsetLeft = offsetLeft; + _offsetTop = offsetTop; +} + + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdScene::getNodeByName(const char *name) { + CBObject *ret = NULL; + + // dependent objects + for (int i = 0; i < _layers.getSize(); i++) { + CAdLayer *layer = _layers[i]; + for (int j = 0; j < layer->_nodes.getSize(); j++) { + CAdSceneNode *node = layer->_nodes[j]; + if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->_name)) || + (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->_name))) { + switch (node->_type) { + case OBJECT_ENTITY: + ret = node->_entity; + break; + case OBJECT_REGION: + ret = node->_region; + break; + default: + ret = NULL; + } + return ret; + } + } + } + + // free entities + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->_name)) { + return _objects[i]; + } + } + + // waypoint groups + for (int i = 0; i < _waypointGroups.getSize(); i++) { + if (!scumm_stricmp(name, _waypointGroups[i]->_name)) { + return _waypointGroups[i]; + } + } + + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::saveState() { + return persistState(true); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::loadState() { + return persistState(false); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::persistState(bool saving) { + if (!_persistentState) return STATUS_OK; + + CAdGame *adGame = (CAdGame *)_gameRef; + CAdSceneState *state = adGame->getSceneState(_filename, saving); + if (!state) return STATUS_OK; + + CAdNodeState *nodeState; + + // dependent objects + for (int i = 0; i < _layers.getSize(); i++) { + CAdLayer *layer = _layers[i]; + for (int j = 0; j < layer->_nodes.getSize(); j++) { + CAdSceneNode *node = layer->_nodes[j]; + switch (node->_type) { + case OBJECT_ENTITY: + if (!node->_entity->_saveState) continue; + nodeState = state->getNodeState(node->_entity->_name, saving); + if (nodeState) { + nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); + //if(Saving) NodeState->_active = node->_entity->_active; + //else node->_entity->_active = NodeState->_active; + } + break; + case OBJECT_REGION: + if (!node->_region->_saveState) continue; + nodeState = state->getNodeState(node->_region->_name, saving); + if (nodeState) { + if (saving) nodeState->_active = node->_region->_active; + else node->_region->_active = nodeState->_active; + } + break; + default: + warning("CAdScene::PersistState - unhandled enum"); + break; + } + } + } + + // free entities + for (int i = 0; i < _objects.getSize(); i++) { + if (!_objects[i]->_saveState) continue; + if (_objects[i]->_type == OBJECT_ENTITY) { + nodeState = state->getNodeState(_objects[i]->_name, saving); + if (nodeState) { + nodeState->transferEntity((CAdEntity *)_objects[i], _persistentStateSprites, saving); + //if(Saving) NodeState->_active = _objects[i]->_active; + //else _objects[i]->_active = NodeState->_active; + } + } + } + + // waypoint groups + for (int i = 0; i < _waypointGroups.getSize(); i++) { + nodeState = state->getNodeState(_waypointGroups[i]->_name, saving); + if (nodeState) { + if (saving) nodeState->_active = _waypointGroups[i]->_active; + else _waypointGroups[i]->_active = nodeState->_active; + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +float CAdScene::getRotationAt(int x, int y) { + CAdRotLevel *prev = NULL; + CAdRotLevel *next = NULL; + + for (int i = 0; i < _rotLevels.getSize(); i++) { + /* CAdRotLevel *xxx = _rotLevels[i]; + int j = _rotLevels.getSize();*/ + if (_rotLevels[i]->_posX < x) prev = _rotLevels[i]; + else { + next = _rotLevels[i]; + break; + } + } + + if (prev == NULL || next == NULL) return 0; + + int delta_x = next->_posX - prev->_posX; + float delta_rot = next->_rotation - prev->_rotation; + x -= prev->_posX; + + float percent = (float)x / ((float)delta_x / 100.0f); + return prev->_rotation + delta_rot / 100 * percent; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::handleItemAssociations(const char *itemName, bool show) { + for (int i = 0; i < _layers.getSize(); i++) { + CAdLayer *layer = _layers[i]; + for (int j = 0; j < layer->_nodes.getSize(); j++) { + if (layer->_nodes[j]->_type == OBJECT_ENTITY) { + CAdEntity *ent = layer->_nodes[j]->_entity; + + if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; + } + } + } + + for (int i = 0; i < _objects.getSize(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY) { + CAdEntity *ent = (CAdEntity *)_objects[i]; + if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getRegionsAt(int x, int y, CAdRegion **regionList, int numRegions) { + int numUsed = 0; + if (_mainLayer) { + for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + CAdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { + if (numUsed < numRegions - 1) { + regionList[numUsed] = node->_region; + numUsed++; + } else break; + } + } + } + for (int i = numUsed; i < numRegions; i++) { + regionList[i] = NULL; + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::restoreDeviceObjects() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdScene::getNextAccessObject(CBObject *currObject) { + CBArray objects; + getSceneObjects(objects, true); + + if (objects.getSize() == 0) return NULL; + else { + if (currObject != NULL) { + for (int i = 0; i < objects.getSize(); i++) { + if (objects[i] == currObject) { + if (i < objects.getSize() - 1) return objects[i + 1]; + else break; + } + } + } + return objects[0]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +CBObject *CAdScene::getPrevAccessObject(CBObject *currObject) { + CBArray objects; + getSceneObjects(objects, true); + + if (objects.getSize() == 0) return NULL; + else { + if (currObject != NULL) { + for (int i = objects.getSize() - 1; i >= 0; i--) { + if (objects[i] == currObject) { + if (i > 0) return objects[i - 1]; + else break; + } + } + } + return objects[objects.getSize() - 1]; + } + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getSceneObjects(CBArray &objects, bool interactiveOnly) { + for (int i = 0; i < _layers.getSize(); i++) { + // close-up layer -> remove everything below it + if (interactiveOnly && _layers[i]->_closeUp) objects.removeAll(); + + + for (int j = 0; j < _layers[i]->_nodes.getSize(); j++) { + CAdSceneNode *node = _layers[i]->_nodes[j]; + switch (node->_type) { + case OBJECT_ENTITY: { + CAdEntity *ent = node->_entity; + if (ent->_active && (ent->_registrable || !interactiveOnly)) + objects.add(ent); + } + break; + + case OBJECT_REGION: { + CBArray regionObj; + getRegionObjects(node->_region, regionObj, interactiveOnly); + for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { + bool found = false; + for (int old = 0; old < objects.getSize(); old++) { + if (objects[old] == regionObj[newIndex]) { + found = true; + break; + } + } + if (!found) objects.add(regionObj[newIndex]); + } + //if(RegionObj.getSize() > 0) Objects.Append(RegionObj); + } + break; + default: + warning("CAdScene::GetSceneObjects - Unhandled enum"); + break; + } + } + } + + // objects outside any region + CBArray regionObj; + getRegionObjects(NULL, regionObj, interactiveOnly); + for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { + bool found = false; + for (int old = 0; old < objects.getSize(); old++) { + if (objects[old] == regionObj[newIndex]) { + found = true; + break; + } + } + if (!found) objects.add(regionObj[newIndex]); + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdScene::getRegionObjects(CAdRegion *region, CBArray &objects, bool interactiveOnly) { + CAdGame *adGame = (CAdGame *)_gameRef; + CAdObject *obj; + + // global objects + for (int i = 0; i < adGame->_objects.getSize(); i++) { + obj = adGame->_objects[i]; + if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + if (interactiveOnly && !obj->_registrable) continue; + + objects.add(obj); + } + } + + // scene objects + for (int i = 0; i < _objects.getSize(); i++) { + obj = _objects[i]; + if (obj->_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + if (interactiveOnly && !obj->_registrable) continue; + + objects.add(obj); + } + } + + // sort by _posY + qsort(objects.getData(), objects.getSize(), sizeof(CAdObject *), CAdScene::compareObjs); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_scene.h b/engines/wintermute/ad/ad_scene.h new file mode 100644 index 0000000000..ab62a4a7fc --- /dev/null +++ b/engines/wintermute/ad/ad_scene.h @@ -0,0 +1,181 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENE_H +#define WINTERMUTE_ADSCENE_H + +#include "engines/wintermute/base/base_fader.h" + +namespace WinterMute { + +class CUIWindow; +class CAdObject; +class CAdRegion; +class CBViewport; +class CAdLayer; +class CBPoint; +class CAdWaypointGroup; +class CAdPath; +class CAdScaleLevel; +class CAdRotLevel; +class CAdPathPoint; +class CAdScene : public CBObject { +public: + + CBObject *getNextAccessObject(CBObject *CurrObject); + CBObject *getPrevAccessObject(CBObject *CurrObject); + bool getSceneObjects(CBArray &Objects, bool InteractiveOnly); + bool getRegionObjects(CAdRegion *Region, CBArray &Objects, bool InteractiveOnly); + + bool afterLoad(); + + bool getRegionsAt(int X, int Y, CAdRegion **RegionList, int NumRegions); + bool handleItemAssociations(const char *ItemName, bool Show); + CUIWindow *_shieldWindow; + float getRotationAt(int X, int Y); + bool loadState(); + bool saveState(); + bool _persistentState; + bool _persistentStateSprites; + CBObject *getNodeByName(const char *name); + void setOffset(int OffsetLeft, int OffsetTop); + bool pointInViewport(int X, int Y); + int getOffsetTop(); + int getOffsetLeft(); + bool getViewportSize(int *Width = NULL, int *Height = NULL); + bool getViewportOffset(int *OffsetX = NULL, int *OffsetY = NULL); + CBViewport *_viewport; + CBFader *_fader; + int _pfPointsNum; + void pfPointsAdd(int X, int Y, int Distance); + void pfPointsStart(); + bool _initialized; + bool correctTargetPoint(int StartX, int StartY, int *X, int *Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); + bool correctTargetPoint2(int StartX, int StartY, int *TargetX, int *TargetY, bool CheckFreeObjects, CBObject *Requester); + DECLARE_PERSISTENT(CAdScene, CBObject) + bool displayRegionContent(CAdRegion *Region = NULL, bool Display3DOnly = false); + bool displayRegionContentOld(CAdRegion *Region = NULL); + static int compareObjs(const void *Obj1, const void *Obj2); + + bool updateFreeObjects(); + bool traverseNodes(bool Update = false); + float getScaleAt(int Y); + bool sortScaleLevels(); + bool sortRotLevels(); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + uint32 getAlphaAt(int X, int Y, bool ColorCheck = false); + bool _paralaxScrolling; + void skipTo(int OffsetX, int OffsetY); + void setDefaults(); + void cleanup(); + void skipToObject(CBObject *Object); + void scrollToObject(CBObject *Object); + void scrollTo(int OffsetX, int OffsetY); + virtual bool update(); + bool _autoScroll; + int _targetOffsetTop; + int _targetOffsetLeft; + + int _scrollPixelsV; + uint32 _scrollTimeV; + uint32 _lastTimeV; + + int _scrollPixelsH; + uint32 _scrollTimeH; + uint32 _lastTimeH; + + virtual bool display(); + uint32 _pfMaxTime; + bool initLoop(); + void pathFinderStep(); + bool isBlockedAt(int X, int Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); + bool isWalkableAt(int X, int Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); + CAdLayer *_mainLayer; + float getZoomAt(int X, int Y); + bool getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject *requester = NULL); + CAdScene(CBGame *inGame); + virtual ~CAdScene(); + CBArray _layers; + CBArray _objects; + CBArray _waypointGroups; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + int _width; + int _height; + bool addObject(CAdObject *Object); + bool removeObject(CAdObject *Object); + int _editorMarginH; + int _editorMarginV; + uint32 _editorColFrame; + uint32 _editorColEntity; + uint32 _editorColRegion; + uint32 _editorColBlocked; + uint32 _editorColWaypoints; + uint32 _editorColEntitySel; + uint32 _editorColRegionSel; + uint32 _editorColBlockedSel; + uint32 _editorColWaypointsSel; + uint32 _editorColScale; + uint32 _editorColDecor; + uint32 _editorColDecorSel; + + bool _editorShowRegions; + bool _editorShowBlocked; + bool _editorShowDecor; + bool _editorShowEntities; + bool _editorShowScale; + CBArray _scaleLevels; + CBArray _rotLevels; + + virtual bool restoreDeviceObjects(); + int getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester = NULL); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + + +private: + bool persistState(bool Saving = true); + void pfAddWaypointGroup(CAdWaypointGroup *Wpt, CBObject *Requester = NULL); + bool _pfReady; + CBPoint *_pfTarget; + CAdPath *_pfTargetPath; + CBObject *_pfRequester; + CBArray _pfPath; + + int _offsetTop; + int _offsetLeft; + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_scene_node.cpp b/engines/wintermute/ad/ad_scene_node.cpp new file mode 100644 index 0000000000..da7082105f --- /dev/null +++ b/engines/wintermute/ad/ad_scene_node.cpp @@ -0,0 +1,83 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_scene_node.h" +#include "engines/wintermute/base/base_game.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdSceneNode, false) + +////////////////////////////////////////////////////////////////////////// +CAdSceneNode::CAdSceneNode(CBGame *inGame): CBObject(inGame) { + _type = OBJECT_NONE; + _region = NULL; + _entity = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSceneNode::~CAdSceneNode() { + _gameRef->unregisterObject(_region); + _region = NULL; + + _gameRef->unregisterObject(_entity); + _entity = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSceneNode::setEntity(CAdEntity *entity) { + _type = OBJECT_ENTITY; + _entity = entity; + return _gameRef->registerObject(entity); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSceneNode::setRegion(CAdRegion *region) { + _type = OBJECT_REGION; + _region = region; + return _gameRef->registerObject(region); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSceneNode::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_entity)); + persistMgr->transfer(TMEMBER(_region)); + persistMgr->transfer(TMEMBER_INT(_type)); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_scene_node.h b/engines/wintermute/ad/ad_scene_node.h new file mode 100644 index 0000000000..1c25f91a2d --- /dev/null +++ b/engines/wintermute/ad/ad_scene_node.h @@ -0,0 +1,54 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENENODE_H +#define WINTERMUTE_ADSCENENODE_H + + +#include "engines/wintermute/ad/ad_types.h" // Added by ClassView +#include "engines/wintermute/ad/ad_region.h" // Added by ClassView +#include "engines/wintermute/ad/ad_entity.h" + +namespace WinterMute { + +class CAdSceneNode : public CBObject { +public: + DECLARE_PERSISTENT(CAdSceneNode, CBObject) + bool setRegion(CAdRegion *region); + bool setEntity(CAdEntity *entity); + CAdEntity *_entity; + CAdRegion *_region; + TObjectType _type; + CAdSceneNode(CBGame *inGame); + virtual ~CAdSceneNode(); + +}; + +} + +#endif diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp new file mode 100644 index 0000000000..2ac36054a5 --- /dev/null +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -0,0 +1,88 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/ad/ad_scene_state.h" +#include "engines/wintermute/ad/ad_node_state.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdSceneState, false) + +////////////////////////////////////////////////////////////////////////// +CAdSceneState::CAdSceneState(CBGame *inGame): CBBase(inGame) { + _filename = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSceneState::~CAdSceneState() { + delete[] _filename; + _filename = NULL; + + for (int i = 0; i < _nodeStates.getSize(); i++) delete _nodeStates[i]; + _nodeStates.removeAll(); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSceneState::persist(CBPersistMgr *persistMgr) { + persistMgr->transfer(TMEMBER(_filename)); + _nodeStates.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdSceneState::setFilename(const char *filename) { + delete[] _filename; + _filename = new char [strlen(filename) + 1]; + if (_filename) strcpy(_filename, filename); +} + + +////////////////////////////////////////////////////////////////////////// +CAdNodeState *CAdSceneState::getNodeState(char *name, bool saving) { + for (int i = 0; i < _nodeStates.getSize(); i++) { + if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) return _nodeStates[i]; + } + + if (saving) { + CAdNodeState *ret = new CAdNodeState(_gameRef); + ret->setName(name); + _nodeStates.add(ret); + + return ret; + } else return NULL; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_scene_state.h b/engines/wintermute/ad/ad_scene_state.h new file mode 100644 index 0000000000..6df20e0578 --- /dev/null +++ b/engines/wintermute/ad/ad_scene_state.h @@ -0,0 +1,51 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENESTATE_H +#define WINTERMUTE_ADSCENESTATE_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base.h" +#include "engines/wintermute/coll_templ.h" + +namespace WinterMute { +class CAdNodeState; +class CAdSceneState : public CBBase { +public: + CAdNodeState *getNodeState(char *name, bool saving); + void setFilename(const char *filename); + DECLARE_PERSISTENT(CAdSceneState, CBBase) + CAdSceneState(CBGame *inGame); + virtual ~CAdSceneState(); + char *_filename; + CBArray _nodeStates; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp new file mode 100644 index 0000000000..2607993aa0 --- /dev/null +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -0,0 +1,317 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/ad/ad_talk_def.h" +#include "engines/wintermute/ad/ad_talk_node.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/utils/path_util.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdSentence, false) + +////////////////////////////////////////////////////////////////////////// +CAdSentence::CAdSentence(CBGame *inGame): CBBase(inGame) { + _text = NULL; + _stances = NULL; + _tempStance = NULL; + + _duration = 0; + _startTime = 0; + _currentStance = 0; + + _font = NULL; + + _pos.x = _pos.y = 0; + _width = _gameRef->_renderer->_width; + + _align = (TTextAlign)TAL_CENTER; + + _sound = NULL; + _soundStarted = false; + + _talkDef = NULL; + _currentSprite = NULL; + _currentSkelAnim = NULL; + _fixedPos = false; + _freezable = true; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSentence::~CAdSentence() { + delete _sound; + delete[] _text; + delete[] _stances; + delete[] _tempStance; + delete _talkDef; + _sound = NULL; + _text = NULL; + _stances = NULL; + _tempStance = NULL; + _talkDef = NULL; + + _currentSprite = NULL; // ref only + _currentSkelAnim = NULL; + _font = NULL; // ref only +} + + +////////////////////////////////////////////////////////////////////////// +void CAdSentence::setText(const char *text) { + if (_text) delete [] _text; + _text = new char[strlen(text) + 1]; + if (_text) strcpy(_text, text); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdSentence::setStances(const char *stances) { + if (_stances) delete [] _stances; + if (stances) { + _stances = new char[strlen(stances) + 1]; + if (_stances) strcpy(_stances, stances); + } else _stances = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdSentence::getCurrentStance() { + return getStance(_currentStance); +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdSentence::getNextStance() { + _currentStance++; + return getStance(_currentStance); +} + + +////////////////////////////////////////////////////////////////////////// +char *CAdSentence::getStance(int stance) { + if (_stances == NULL) return NULL; + + if (_tempStance) delete [] _tempStance; + _tempStance = NULL; + + char *start; + char *curr; + int pos; + + if (stance == 0) start = _stances; + else { + pos = 0; + start = NULL; + curr = _stances; + while (pos < stance) { + if (*curr == '\0') break; + if (*curr == ',') pos++; + curr++; + } + if (pos == stance) start = curr; + } + + if (start == NULL) return NULL; + + while (*start == ' ' && *start != ',' && *start != '\0') start++; + + curr = start; + while (*curr != '\0' && *curr != ',') curr++; + + while (curr > start && *(curr - 1) == ' ') curr--; + + _tempStance = new char [curr - start + 1]; + if (_tempStance) { + _tempStance[curr - start] = '\0'; + strncpy(_tempStance, start, curr - start); + } + + return _tempStance; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::display() { + if (!_font || !_text) return STATUS_FAILED; + + if (_sound && !_soundStarted) { + _sound->play(); + _soundStarted = true; + } + + if (_gameRef->_subtitles) { + int x = _pos.x; + int y = _pos.y; + + if (!_fixedPos) { + x = x - ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); + y = y - ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + } + + + x = MAX(x, 0); + x = MIN(x, _gameRef->_renderer->_width - _width); + y = MAX(y, 0); + + _font->drawText((byte *)_text, x, y, _width, _align); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void CAdSentence::setSound(CBSound *sound) { + if (!sound) return; + delete _sound; + _sound = sound; + _soundStarted = false; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::finish() { + if (_sound) _sound->stop(); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::persist(CBPersistMgr *persistMgr) { + + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER_INT(_align)); + persistMgr->transfer(TMEMBER(_currentStance)); + persistMgr->transfer(TMEMBER(_currentSprite)); + persistMgr->transfer(TMEMBER(_currentSkelAnim)); + persistMgr->transfer(TMEMBER(_duration)); + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_pos)); + persistMgr->transfer(TMEMBER(_sound)); + persistMgr->transfer(TMEMBER(_soundStarted)); + persistMgr->transfer(TMEMBER(_stances)); + persistMgr->transfer(TMEMBER(_startTime)); + persistMgr->transfer(TMEMBER(_talkDef)); + persistMgr->transfer(TMEMBER(_tempStance)); + persistMgr->transfer(TMEMBER(_text)); + persistMgr->transfer(TMEMBER(_width)); + persistMgr->transfer(TMEMBER(_fixedPos)); + persistMgr->transfer(TMEMBER(_freezable)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::setupTalkFile(const char *soundFilename) { + delete _talkDef; + _talkDef = NULL; + _currentSprite = NULL; + + if (!soundFilename) return STATUS_OK; + + + AnsiString path = PathUtil::getDirectoryName(soundFilename); + AnsiString name = PathUtil::getFileNameWithoutExtension(soundFilename); + + AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); + + Common::SeekableReadStream *file = _gameRef->_fileManager->openFile(talkDefFileName.c_str()); + if (file) { + _gameRef->_fileManager->closeFile(file); + } else return STATUS_OK; // no talk def file found + + + _talkDef = new CAdTalkDef(_gameRef); + if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { + delete _talkDef; + _talkDef = NULL; + return STATUS_FAILED; + } + //_gameRef->LOG(0, "Using .talk file: %s", TalkDefFile); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::update(TDirection dir) { + if (!_talkDef) return STATUS_OK; + + uint32 currentTime; + // if sound is available, synchronize with sound, otherwise use timer + + /* + if (_sound) CurrentTime = _sound->GetPositionTime(); + else CurrentTime = _gameRef->_timer - _startTime; + */ + currentTime = _gameRef->_timer - _startTime; + + bool talkNodeFound = false; + for (int i = 0; i < _talkDef->_nodes.getSize(); i++) { + if (_talkDef->_nodes[i]->isInTimeInterval(currentTime, dir)) { + talkNodeFound = true; + + CBSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); + if (newSprite != _currentSprite) newSprite->reset(); + _currentSprite = newSprite; + + if (!_talkDef->_nodes[i]->_playToEnd) break; + } + } + + + // no talk node, try to use default sprite instead (if any) + if (!talkNodeFound) { + CBSprite *newSprite = _talkDef->getDefaultSprite(dir); + if (newSprite) { + if (newSprite != _currentSprite) newSprite->reset(); + _currentSprite = newSprite; + } else _currentSprite = NULL; + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdSentence::CanSkip() { + // prevent accidental sentence skipping (TODO make configurable) + return (_gameRef->_timer - _startTime) > 300; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_sentence.h b/engines/wintermute/ad/ad_sentence.h new file mode 100644 index 0000000000..40f99ea830 --- /dev/null +++ b/engines/wintermute/ad/ad_sentence.h @@ -0,0 +1,85 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSENTENCE_H +#define WINTERMUTE_ADSENTENCE_H + + +#include "engines/wintermute/base/base.h" +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/math/rect32.h" +#include "engines/wintermute/dctypes.h" // Added by ClassView +#include "common/rect.h" + +namespace WinterMute { +class CAdTalkDef; +class CBFont; +class CBSprite; +class CBSound; +class CAdSentence : public CBBase { +public: + bool _freezable; + bool _fixedPos; + CBSprite *_currentSprite; + char *_currentSkelAnim; + bool update(TDirection dir = DI_DOWN); + bool setupTalkFile(const char *soundFilename); + DECLARE_PERSISTENT(CAdSentence, CBBase) + bool finish(); + void setSound(CBSound *Sound); + bool _soundStarted; + CBSound *_sound; + TTextAlign _align; + bool display(); + int _width; + Point32 _pos; + CBFont *_font; + char *getNextStance(); + char *getCurrentStance(); + void setStances(const char *stances); + void setText(const char *text); + int _currentStance; + uint32 _startTime; + char *_stances; + char *_text; + uint32 _duration; + CAdSentence(CBGame *inGame); + virtual ~CAdSentence(); + CAdTalkDef *_talkDef; + + bool CanSkip(); + +private: + char *_tempStance; + char *getStance(int stance); + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp new file mode 100644 index 0000000000..f0925c6913 --- /dev/null +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -0,0 +1,312 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_sprite_set.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdSpriteSet, false) + +////////////////////////////////////////////////////////////////////////// +CAdSpriteSet::CAdSpriteSet(CBGame *inGame, CBObject *owner): CBObject(inGame) { + _owner = owner; + + for (int i = 0; i < NUM_DIRECTIONS; i++) + _sprites[i] = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdSpriteSet::~CAdSpriteSet() { + for (int i = 0; i < NUM_DIRECTIONS; i++) { + delete _sprites[i]; + _sprites[i] = NULL; + } + + _owner = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdSpriteSet::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SPRITESET) +TOKEN_DEF(NAME) +TOKEN_DEF(UP_LEFT) +TOKEN_DEF(DOWN_LEFT) +TOKEN_DEF(LEFT) +TOKEN_DEF(UP_RIGHT) +TOKEN_DEF(DOWN_RIGHT) +TOKEN_DEF(RIGHT) +TOKEN_DEF(UP) +TOKEN_DEF(DOWN) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType CacheType) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SPRITESET) + TOKEN_TABLE(NAME) + TOKEN_TABLE(UP_LEFT) + TOKEN_TABLE(DOWN_LEFT) + TOKEN_TABLE(LEFT) + TOKEN_TABLE(UP_RIGHT) + TOKEN_TABLE(DOWN_RIGHT) + TOKEN_TABLE(RIGHT) + TOKEN_TABLE(UP) + TOKEN_TABLE(DOWN) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SPRITESET) { + _gameRef->LOG(0, "'SPRITESET' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + CBSprite *spr = NULL; + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_LEFT: + delete _sprites[DI_LEFT]; + _sprites[DI_LEFT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_LEFT] = spr; + break; + + case TOKEN_RIGHT: + delete _sprites[DI_RIGHT]; + _sprites[DI_RIGHT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_RIGHT] = spr; + break; + + case TOKEN_UP: + delete _sprites[DI_UP]; + _sprites[DI_UP] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_UP] = spr; + break; + + case TOKEN_DOWN: + delete _sprites[DI_DOWN]; + _sprites[DI_DOWN] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_DOWN] = spr; + break; + + case TOKEN_UP_LEFT: + delete _sprites[DI_UPLEFT]; + _sprites[DI_UPLEFT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_UPLEFT] = spr; + break; + + case TOKEN_UP_RIGHT: + delete _sprites[DI_UPRIGHT]; + _sprites[DI_UPRIGHT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_UPRIGHT] = spr; + break; + + case TOKEN_DOWN_LEFT: + delete _sprites[DI_DOWNLEFT]; + _sprites[DI_DOWNLEFT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_DOWNLEFT] = spr; + break; + + case TOKEN_DOWN_RIGHT: + delete _sprites[DI_DOWNRIGHT]; + _sprites[DI_DOWNRIGHT] = NULL; + spr = new CBSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + else _sprites[DI_DOWNRIGHT] = spr; + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SPRITESET definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading SPRITESET definition"); + if (spr) delete spr; + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_owner)); + for (int i = 0; i < NUM_DIRECTIONS; i++) { + persistMgr->transfer("", &_sprites[i]); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdSpriteSet::getSprite(TDirection direction) { + int dir = (int)direction; + if (dir < 0) dir = 0; + if (dir >= NUM_DIRECTIONS) dir = NUM_DIRECTIONS - 1; + + CBSprite *ret = NULL; + + // find nearest set sprite + int numSteps = 0; + for (int i = dir; i >= 0; i--) { + if (_sprites[i] != NULL) { + ret = _sprites[i]; + numSteps = dir - i; + break; + } + } + + for (int i = dir; i < NUM_DIRECTIONS; i++) { + if (_sprites[i] != NULL) { + if (ret == NULL || numSteps > i - dir) return _sprites[i]; + else return ret; + } + } + + return ret; +} + + + +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "SPRITESET {\n"); + if (_name) buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + for (int i = 0; i < NUM_DIRECTIONS; i++) { + if (_sprites[i]) { + switch (i) { + case DI_UP: + buffer->putTextIndent(indent + 2, "UP=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_UPRIGHT: + buffer->putTextIndent(indent + 2, "UP_RIGHT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_RIGHT: + buffer->putTextIndent(indent + 2, "RIGHT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_DOWNRIGHT: + buffer->putTextIndent(indent + 2, "DOWN_RIGHT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_DOWN: + buffer->putTextIndent(indent + 2, "DOWN=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_DOWNLEFT: + buffer->putTextIndent(indent + 2, "DOWN_LEFT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_LEFT: + buffer->putTextIndent(indent + 2, "LEFT=\"%s\"\n", _sprites[i]->_filename); + break; + case DI_UPLEFT: + buffer->putTextIndent(indent + 2, "UP_LEFT=\"%s\"\n", _sprites[i]->_filename); + break; + } + } + } + + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool CAdSpriteSet::containsSprite(CBSprite *sprite) { + if (!sprite) return false; + + for (int i = 0; i < NUM_DIRECTIONS; i++) { + if (_sprites[i] == sprite) return true; + } + return false; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_sprite_set.h b/engines/wintermute/ad/ad_sprite_set.h new file mode 100644 index 0000000000..993832cfa3 --- /dev/null +++ b/engines/wintermute/ad/ad_sprite_set.h @@ -0,0 +1,54 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSPRITESET_H +#define WINTERMUTE_ADSPRITESET_H + + +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/base/base_sprite.h" // Added by ClassView + +namespace WinterMute { + +class CAdSpriteSet : public CBObject { +public: + bool containsSprite(CBSprite *sprite); + virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); + CBSprite *getSprite(TDirection direction); + DECLARE_PERSISTENT(CAdSpriteSet, CBObject) + CBObject *_owner; + CAdSpriteSet(CBGame *inGame, CBObject *owner = NULL); + virtual ~CAdSpriteSet(); + bool loadFile(const char *filename, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); + bool loadBuffer(byte *buffer, bool complete = true, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); + CBSprite *_sprites[NUM_DIRECTIONS]; +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp new file mode 100644 index 0000000000..0cd62df603 --- /dev/null +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -0,0 +1,260 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_talk_def.h" +#include "engines/wintermute/ad/ad_talk_node.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/ad/ad_sprite_set.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/utils/utils.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdTalkDef, false) + +////////////////////////////////////////////////////////////////////////// +CAdTalkDef::CAdTalkDef(CBGame *inGame): CBObject(inGame) { + _defaultSpriteFilename = NULL; + _defaultSprite = NULL; + + _defaultSpriteSetFilename = NULL; + _defaultSpriteSet = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdTalkDef::~CAdTalkDef() { + for (int i = 0; i < _nodes.getSize(); i++) delete _nodes[i]; + _nodes.removeAll(); + + delete[] _defaultSpriteFilename; + delete _defaultSprite; + _defaultSpriteFilename = NULL; + _defaultSprite = NULL; + + delete[] _defaultSpriteSetFilename; + delete _defaultSpriteSet; + _defaultSpriteSetFilename = NULL; + _defaultSpriteSet = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdTalkDef::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + CBUtils::setString(&_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(TALK) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(ACTION) +TOKEN_DEF(DEFAULT_SPRITESET_FILE) +TOKEN_DEF(DEFAULT_SPRITESET) +TOKEN_DEF(DEFAULT_SPRITE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(TALK) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(ACTION) + TOKEN_TABLE(DEFAULT_SPRITESET_FILE) + TOKEN_TABLE(DEFAULT_SPRITESET) + TOKEN_TABLE(DEFAULT_SPRITE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_TALK) { + _gameRef->LOG(0, "'TALK' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_ACTION: { + CAdTalkNode *Node = new CAdTalkNode(_gameRef); + if (Node && DID_SUCCEED(Node->loadBuffer(params, false))) _nodes.add(Node); + else { + delete Node; + Node = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + case TOKEN_DEFAULT_SPRITE: + CBUtils::setString(&_defaultSpriteFilename, (char *)params); + break; + + case TOKEN_DEFAULT_SPRITESET_FILE: + CBUtils::setString(&_defaultSpriteSetFilename, (char *)params); + break; + + case TOKEN_DEFAULT_SPRITESET: { + delete _defaultSpriteSet; + _defaultSpriteSet = new CAdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadBuffer(params, false))) { + delete _defaultSpriteSet; + _defaultSpriteSet = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in TALK definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading TALK definition"); + return STATUS_FAILED; + } + + delete _defaultSprite; + delete _defaultSpriteSet; + _defaultSprite = NULL; + _defaultSpriteSet = NULL; + + if (_defaultSpriteFilename) { + _defaultSprite = new CBSprite(_gameRef); + if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) return STATUS_FAILED; + } + + if (_defaultSpriteSetFilename) { + _defaultSpriteSet = new CAdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) return STATUS_FAILED; + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_defaultSprite)); + persistMgr->transfer(TMEMBER(_defaultSpriteFilename)); + persistMgr->transfer(TMEMBER(_defaultSpriteSet)); + persistMgr->transfer(TMEMBER(_defaultSpriteSetFilename)); + + _nodes.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "TALK {\n"); + if (_defaultSpriteFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); + + if (_defaultSpriteSetFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); + else if (_defaultSpriteSet) _defaultSpriteSet->saveAsText(buffer, indent + 2); + + for (int i = 0; i < _nodes.getSize(); i++) { + _nodes[i]->saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "\n"); + } + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkDef::loadDefaultSprite() { + if (_defaultSpriteFilename && !_defaultSprite) { + _defaultSprite = new CBSprite(_gameRef); + if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { + delete _defaultSprite; + _defaultSprite = NULL; + return STATUS_FAILED; + } else return STATUS_OK; + } else if (_defaultSpriteSetFilename && !_defaultSpriteSet) { + _defaultSpriteSet = new CAdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { + delete _defaultSpriteSet; + _defaultSpriteSet = NULL; + return STATUS_FAILED; + } else return STATUS_OK; + } else return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdTalkDef::getDefaultSprite(TDirection dir) { + loadDefaultSprite(); + if (_defaultSprite) return _defaultSprite; + else if (_defaultSpriteSet) return _defaultSpriteSet->getSprite(dir); + else return NULL; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_talk_def.h b/engines/wintermute/ad/ad_talk_def.h new file mode 100644 index 0000000000..0811f5b8f5 --- /dev/null +++ b/engines/wintermute/ad/ad_talk_def.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKDEF_H +#define WINTERMUTE_ADTALKDEF_H + +#include "engines/wintermute/coll_templ.h" +#include "engines/wintermute/base/base_object.h" + +namespace WinterMute { +class CAdTalkNode; +class CAdSpriteSet; +class CAdTalkDef : public CBObject { +public: + char *_defaultSpriteSetFilename; + CAdSpriteSet *_defaultSpriteSet; + CBSprite *getDefaultSprite(TDirection Dir); + bool loadDefaultSprite(); + DECLARE_PERSISTENT(CAdTalkDef, CBObject) + + CAdTalkDef(CBGame *inGame); + virtual ~CAdTalkDef(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + CBArray _nodes; + char *_defaultSpriteFilename; + CBSprite *_defaultSprite; + virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp new file mode 100644 index 0000000000..28e62798c2 --- /dev/null +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -0,0 +1,366 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_talk_holder.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/wintermute.h" +#include "common/str.h" + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdTalkHolder, false) + +////////////////////////////////////////////////////////////////////////// +CAdTalkHolder::CAdTalkHolder(CBGame *inGame): CAdObject(inGame) { + _sprite = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +CAdTalkHolder::~CAdTalkHolder() { + delete _sprite; + _sprite = NULL; + + for (int i = 0; i < _talkSprites.getSize(); i++) + delete _talkSprites[i]; + _talkSprites.removeAll(); + + for (int i = 0; i < _talkSpritesEx.getSize(); i++) + delete _talkSpritesEx[i]; + _talkSpritesEx.removeAll(); +} + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdTalkHolder::getTalkStance(const char *stance) { + CBSprite *ret = NULL; + + + // forced stance? + if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { + _forcedTalkAnimUsed = true; + delete _animSprite; + _animSprite = new CBSprite(_gameRef, this); + if (_animSprite) { + bool res = _animSprite->loadFile(_forcedTalkAnimName); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "CAdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); + delete _animSprite; + _animSprite = NULL; + } else return _animSprite; + } + } + + + if (stance != NULL) { + // search special talk stances + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->_name, stance) == 0) { + ret = _talkSpritesEx[i]; + break; + } + } + if (ret == NULL) { + // serach generic talk stances + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (scumm_stricmp(_talkSprites[i]->_name, stance) == 0) { + ret = _talkSprites[i]; + break; + } + } + } + } + + // not a valid stance? get a random one + if (ret == NULL) { + if (_talkSprites.getSize() < 1) ret = _sprite; + else { + // TODO: remember last + int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); + ret = _talkSprites[rnd]; + } + } + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool CAdTalkHolder::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // SetSprite + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetSprite") == 0) { + stack->correctParams(1); + + CScValue *val = stack->pop(); + + bool setCurrent = false; + if (_currentSprite && _currentSprite == _sprite) setCurrent = true; + + delete _sprite; + _sprite = NULL; + + if (val->isNULL()) { + _sprite = NULL; + if (setCurrent) _currentSprite = NULL; + stack->pushBool(true); + } else { + const char *filename = val->getString(); + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + script->runtimeError("SetSprite method failed for file '%s'", filename); + stack->pushBool(false); + } else { + _sprite = spr; + if (setCurrent) _currentSprite = _sprite; + stack->pushBool(true); + } + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetSprite") == 0) { + stack->correctParams(0); + + if (!_sprite || !_sprite->_filename) stack->pushNULL(); + else stack->pushString(_sprite->_filename); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetSpriteObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetSpriteObject") == 0) { + stack->correctParams(0); + + if (!_sprite) stack->pushNULL(); + else stack->pushNative(_sprite, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool Ex = stack->pop()->getBool(); + + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("AddTalkSprite method failed for file '%s'", filename); + } else { + if (Ex) _talkSpritesEx.add(spr); + else _talkSprites.add(spr); + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool ex = stack->pop()->getBool(); + + bool setCurrent = false; + bool setTemp2 = false; + + if (ex) { + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->_filename, filename) == 0) { + if (_currentSprite == _talkSpritesEx[i]) + setCurrent = true; + if (_tempSprite2 == _talkSpritesEx[i]) + setTemp2 = true; + delete _talkSpritesEx[i]; + _talkSpritesEx.removeAt(i); + break; + } + } + } else { + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (scumm_stricmp(_talkSprites[i]->_filename, filename) == 0) { + if (_currentSprite == _talkSprites[i]) + setCurrent = true; + if (_tempSprite2 == _talkSprites[i]) + setTemp2 = true; + delete _talkSprites[i]; + _talkSprites.removeAt(i); + break; + } + } + + } + + stack->pushBool(true); + if (setCurrent) + _currentSprite = _sprite; + if (setTemp2) + _tempSprite2 = _sprite; + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool ex = stack->pop()->getBool(); + bool setCurrent = false; + bool setTemp2 = false; + + CBSprite *spr = new CBSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("SetTalkSprite method failed for file '%s'", filename); + } else { + + // delete current + if (ex) { + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (_talkSpritesEx[i] == _currentSprite) + setCurrent = true; + if (_talkSpritesEx[i] == _tempSprite2) + setTemp2 = true; + delete _talkSpritesEx[i]; + } + _talkSpritesEx.removeAll(); + } else { + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (_talkSprites[i] == _currentSprite) setCurrent = true; + if (_talkSprites[i] == _tempSprite2) setTemp2 = true; + delete _talkSprites[i]; + } + _talkSprites.removeAll(); + } + + // set new + if (ex) + _talkSpritesEx.add(spr); + else + _talkSprites.add(spr); + stack->pushBool(true); + + if (setCurrent) + _currentSprite = spr; + if (setTemp2) + _tempSprite2 = spr; + } + return STATUS_OK; + } + + else return CAdObject::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdTalkHolder::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type (RO) + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("talk-holder"); + return _scValue; + } + + else return CAdObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkHolder::scSetProperty(const char *name, CScValue *value) { + /* + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + if(strcmp(name, "Item")==0){ + SetItem(value->getString()); + return STATUS_OK; + } + + else*/ return CAdObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *CAdTalkHolder::scToString() { + return "[talk-holder object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkHolder::saveAsText(CBDynBuffer *buffer, int indent) { + for (int i = 0; i < _talkSprites.getSize(); i++) { + if (_talkSprites[i]->_filename) + buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->_filename); + } + + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + if (_talkSpritesEx[i]->_filename) + buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->_filename); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkHolder::persist(CBPersistMgr *persistMgr) { + CAdObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_sprite)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_talk_holder.h b/engines/wintermute/ad/ad_talk_holder.h new file mode 100644 index 0000000000..50c2f3504b --- /dev/null +++ b/engines/wintermute/ad/ad_talk_holder.h @@ -0,0 +1,57 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKHOLDER_H +#define WINTERMUTE_ADTALKHOLDER_H + +#include "engines/wintermute/ad/ad_object.h" + +namespace WinterMute { + +class CAdTalkHolder : public CAdObject { +public: + DECLARE_PERSISTENT(CAdTalkHolder, CAdObject) + virtual CBSprite *getTalkStance(const char *stance); + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + CBSprite *_sprite; + CBArray _talkSprites; + CBArray _talkSpritesEx; + CAdTalkHolder(CBGame *inGame); + virtual ~CAdTalkHolder(); + + // scripting interface + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); + virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual const char *scToString(); + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp new file mode 100644 index 0000000000..3b82d731c9 --- /dev/null +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -0,0 +1,266 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/dcgf.h" +#include "engines/wintermute/ad/ad_talk_node.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/ad/ad_sprite_set.h" +#include "engines/wintermute/utils/utils.h" +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdTalkNode, false) + +////////////////////////////////////////////////////////////////////////// +CAdTalkNode::CAdTalkNode(CBGame *inGame): CBBase(inGame) { + _sprite = NULL; + _spriteFilename = NULL; + _spriteSet = NULL; + _spriteSetFilename = NULL; + _comment = NULL; + + _startTime = _endTime = 0; + _playToEnd = false; + _preCache = false; +} + + +////////////////////////////////////////////////////////////////////////// +CAdTalkNode::~CAdTalkNode() { + delete[] _spriteFilename; + delete _sprite; + delete[] _spriteSetFilename; + delete _spriteSet; + delete _comment; + _spriteFilename = NULL; + _sprite = NULL; + _spriteSetFilename = NULL; + _spriteSet = NULL; + _comment = NULL; +} + + + +TOKEN_DEF_START +TOKEN_DEF(ACTION) +TOKEN_DEF(SPRITESET_FILE) +TOKEN_DEF(SPRITESET) +TOKEN_DEF(SPRITE) +TOKEN_DEF(START_TIME) +TOKEN_DEF(END_TIME) +TOKEN_DEF(COMMENT) +TOKEN_DEF(PRECACHE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ACTION) + TOKEN_TABLE(SPRITESET_FILE) + TOKEN_TABLE(SPRITESET) + TOKEN_TABLE(SPRITE) + TOKEN_TABLE(START_TIME) + TOKEN_TABLE(END_TIME) + TOKEN_TABLE(COMMENT) + TOKEN_TABLE(PRECACHE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTION) { + _gameRef->LOG(0, "'ACTION' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + _endTime = 0; + _playToEnd = false; + _preCache = false; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_SPRITE: + CBUtils::setString(&_spriteFilename, (char *)params); + break; + + case TOKEN_SPRITESET_FILE: + CBUtils::setString(&_spriteSetFilename, (char *)params); + break; + + case TOKEN_SPRITESET: { + delete _spriteSet; + _spriteSet = new CAdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadBuffer(params, false))) { + delete _spriteSet; + _spriteSet = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + case TOKEN_START_TIME: + parser.scanStr((char *)params, "%d", &_startTime); + break; + + case TOKEN_END_TIME: + parser.scanStr((char *)params, "%d", &_endTime); + break; + + case TOKEN_PRECACHE: + parser.scanStr((char *)params, "%b", &_preCache); + break; + + case TOKEN_COMMENT: + if (_gameRef->_editorMode) CBUtils::setString(&_comment, (char *)params); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ACTION definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ACTION definition"); + return STATUS_FAILED; + } + + if (_endTime == 0) + _playToEnd = true; + else + _playToEnd = false; + + if (_preCache && _spriteFilename) { + delete _sprite; + _sprite = new CBSprite(_gameRef); + if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) + return STATUS_FAILED; + } + + if (_preCache && _spriteSetFilename) { + delete _spriteSet; + _spriteSet = new CAdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) + return STATUS_FAILED; + } + + return STATUS_OK; +} + + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::persist(CBPersistMgr *persistMgr) { + persistMgr->transfer(TMEMBER(_comment)); + persistMgr->transfer(TMEMBER(_startTime)); + persistMgr->transfer(TMEMBER(_endTime)); + persistMgr->transfer(TMEMBER(_playToEnd)); + persistMgr->transfer(TMEMBER(_sprite)); + persistMgr->transfer(TMEMBER(_spriteFilename)); + persistMgr->transfer(TMEMBER(_spriteSet)); + persistMgr->transfer(TMEMBER(_spriteSetFilename)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ACTION {\n"); + if (_comment) buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); + buffer->putTextIndent(indent + 2, "START_TIME=%d\n", _startTime); + if (!_playToEnd) buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); + if (_spriteFilename) buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); + if (_spriteSetFilename) buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); + else if (_spriteSet) _spriteSet->saveAsText(buffer, indent + 2); + if (_preCache) buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); + + CBBase::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::loadSprite() { + if (_spriteFilename && !_sprite) { + _sprite = new CBSprite(_gameRef); + if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { + delete _sprite; + _sprite = NULL; + return STATUS_FAILED; + } else return STATUS_OK; + } + + else if (_spriteSetFilename && !_spriteSet) { + _spriteSet = new CAdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { + delete _spriteSet; + _spriteSet = NULL; + return STATUS_FAILED; + } else return STATUS_OK; + } + + else return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { + if (time >= _startTime) { + if (_playToEnd) { + if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) return true; + else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) return true; + else return false; + } else return _endTime >= time; + } else return false; +} + + +////////////////////////////////////////////////////////////////////////// +CBSprite *CAdTalkNode::getSprite(TDirection dir) { + loadSprite(); + if (_sprite) return _sprite; + else if (_spriteSet) return _spriteSet->getSprite(dir); + else return NULL; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_talk_node.h b/engines/wintermute/ad/ad_talk_node.h new file mode 100644 index 0000000000..55adf88e83 --- /dev/null +++ b/engines/wintermute/ad/ad_talk_node.h @@ -0,0 +1,63 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKNODE_H +#define WINTERMUTE_ADTALKNODE_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base.h" + +namespace WinterMute { +class CAdSpriteSet; +class CBSprite; +class CAdTalkNode : public CBBase { +public: + char *_spriteSetFilename; + CAdSpriteSet *_spriteSet; + CBSprite *getSprite(TDirection dir); + bool isInTimeInterval(uint32 time, TDirection dir); + bool loadSprite(); + DECLARE_PERSISTENT(CAdTalkNode, CBBase) + + CAdTalkNode(CBGame *inGame); + virtual ~CAdTalkNode(); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); + char *_spriteFilename; + CBSprite *_sprite; + uint32 _startTime; + uint32 _endTime; + bool _playToEnd; + bool _preCache; + char *_comment; + +}; + +} // end of namespace WinterMute + +#endif diff --git a/engines/wintermute/ad/ad_types.h b/engines/wintermute/ad/ad_types.h new file mode 100644 index 0000000000..b88d6fe259 --- /dev/null +++ b/engines/wintermute/ad/ad_types.h @@ -0,0 +1,107 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTYPES_H +#define WINTERMUTE_ADTYPES_H + +namespace WinterMute { + +typedef enum { + GAME_NORMAL, + GAME_WAITING_RESPONSE +} TGameStateEx; + +typedef enum { + OBJECT_ENTITY, + OBJECT_REGION, + OBJECT_ACTOR, + OBJECT_NONE +} TObjectType; + +typedef enum { + ENTITY_NORMAL, + ENTITY_SOUND +} TEntityType; + +typedef enum { + STATE_NONE, + STATE_IDLE, + STATE_PLAYING_ANIM, + STATE_READY, + STATE_FOLLOWING_PATH, + STATE_SEARCHING_PATH, + STATE_WAITING_PATH, + STATE_TURNING_LEFT, + STATE_TURNING_RIGHT, + STATE_TURNING, + STATE_TALKING, + STATE_DIRECT_CONTROL, + STATE_PLAYING_ANIM_SET +} TObjectState; + +typedef enum { + DIRECT_WALK_NONE, + DIRECT_WALK_FW, + DIRECT_WALK_BK +} TDirectWalkMode; + +typedef enum { + DIRECT_TURN_NONE, + DIRECT_TURN_CW, + DIRECT_TURN_CCW +} TDirectTurnMode; + +typedef enum { + RESPONSE_TEXT, + RESPONSE_ICON +} TResponseStyle; + +typedef enum { + RESPONSE_ALWAYS, + RESPONSE_ONCE, + RESPONSE_ONCE_GAME +} TResponseType; + + +typedef enum { + TALK_SKIP_LEFT = 0, + TALK_SKIP_RIGHT = 1, + TALK_SKIP_BOTH = 2, + TALK_SKIP_NONE = 3 +} TTalkSkipButton; + +typedef enum { + GEOM_WAYPOINT, + GEOM_WALKPLANE, + GEOM_BLOCKED, + GEOM_GENERIC +} TGeomNodeType; + +} // end of namespace WinterMute + +#endif // WINTERMUTE_ADTYPES_H diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp new file mode 100644 index 0000000000..4a902266ac --- /dev/null +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -0,0 +1,261 @@ +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/base_file_manager.h" +#include + +namespace WinterMute { + +IMPLEMENT_PERSISTENT(CAdWaypointGroup, false) + +////////////////////////////////////////////////////////////////////////// +CAdWaypointGroup::CAdWaypointGroup(CBGame *inGame): CBObject(inGame) { + _active = true; + _editorSelectedPoint = -1; + _lastMimicScale = -1; + _lastMimicX = _lastMimicY = INT_MIN; +} + + +////////////////////////////////////////////////////////////////////////// +CAdWaypointGroup::~CAdWaypointGroup() { + cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +void CAdWaypointGroup::cleanup() { + for (int i = 0; i < _points.getSize(); i++) + delete _points[i]; + _points.removeAll(); + _editorSelectedPoint = -1; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::loadFile(const char *filename) { + byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "CAdWaypointGroup::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + _filename = new char [strlen(filename) + 1]; + strcpy(_filename, filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); + + + delete [] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(WAYPOINTS) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(POINT) +TOKEN_DEF(EDITOR_SELECTED_POINT) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(WAYPOINTS) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(POINT) + TOKEN_TABLE(EDITOR_SELECTED_POINT) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + CBParser parser(_gameRef); + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_WAYPOINTS) { + _gameRef->LOG(0, "'WAYPOINTS' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_POINT: { + int x, y; + parser.scanStr((char *)params, "%d,%d", &x, &y); + _points.add(new CBPoint(x, y)); + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_EDITOR_SELECTED_POINT: + parser.scanStr((char *)params, "%d", &_editorSelectedPoint); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in WAYPOINTS definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::saveAsText(CBDynBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "WAYPOINTS {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED_POINT=%d\n", _editorSelectedPoint); + + if (_scProp) + _scProp->saveAsText(buffer, indent + 2); + CBBase::saveAsText(buffer, indent + 2); + + for (int i = 0; i < _points.getSize(); i++) { + buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); + } + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::persist(CBPersistMgr *persistMgr) { + + CBObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_editorSelectedPoint)); + persistMgr->transfer(TMEMBER(_lastMimicScale)); + persistMgr->transfer(TMEMBER(_lastMimicX)); + persistMgr->transfer(TMEMBER(_lastMimicY)); + _points.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +CScValue *CAdWaypointGroup::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("waypoint-group"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } + + else return CBObject::scGetProperty(name); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::scSetProperty(const char *name, CScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Active") == 0) { + _active = value->getBool(); + return STATUS_OK; + } + + else return CBObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +bool CAdWaypointGroup::mimic(CAdWaypointGroup *wpt, float scale, int argX, int argY) { + if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) return STATUS_OK; + + cleanup(); + + for (int i = 0; i < wpt->_points.getSize(); i++) { + int x = (int)((float)wpt->_points[i]->x * scale / 100.0f); + int y = (int)((float)wpt->_points[i]->y * scale / 100.0f); + + _points.add(new CBPoint(x + argX, y + argY)); + } + + _lastMimicScale = scale; + _lastMimicX = argX; + _lastMimicY = argY; + + return STATUS_OK; +} + +} // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_waypoint_group.h b/engines/wintermute/ad/ad_waypoint_group.h new file mode 100644 index 0000000000..2cece9e88b --- /dev/null +++ b/engines/wintermute/ad/ad_waypoint_group.h @@ -0,0 +1,58 @@ +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADWAYPOINTGROUP_H +#define WINTERMUTE_ADWAYPOINTGROUP_H + +#include "engines/wintermute/base/base_object.h" + +namespace WinterMute { +class CBPoint; +class CAdWaypointGroup : public CBObject { +public: + float _lastMimicScale; + int _lastMimicX; + int _lastMimicY; + void cleanup(); + bool mimic(CAdWaypointGroup *wpt, float scale = 100.0f, int x = 0, int y = 0); + DECLARE_PERSISTENT(CAdWaypointGroup, CBObject) + virtual bool saveAsText(CBDynBuffer *buffer, int indent); + bool _active; + CAdWaypointGroup(CBGame *inGame); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual ~CAdWaypointGroup(); + CBArray _points; + int _editorSelectedPoint; + virtual CScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, CScValue *value); +}; + +} // end of namespace WinterMute + +#endif -- cgit v1.2.3 From 2e82471240804df65acdf51c43ea044cbb81ae68 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 21 Jul 2012 19:50:08 +0200 Subject: WINTERMUTE: Get rid of #pragma once. --- engines/wintermute/ad/ad_actor.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index ca79f638d9..67e0630f83 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -37,11 +37,8 @@ #include "engines/wintermute/persistent.h" #include "common/str.h" -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - namespace WinterMute { + class CAdSpriteSet; class CAdPath; class CAdActor : public CAdTalkHolder { -- cgit v1.2.3 From b5a07fef8ebf29f7f44b15d9b34799c7e115fdad Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 21 Jul 2012 21:01:47 +0200 Subject: WINTERMUTE: Get rid of the C-prefix for class-definitions. --- engines/wintermute/ad/ad_actor.cpp | 166 ++++++------- engines/wintermute/ad/ad_actor.h | 46 ++-- engines/wintermute/ad/ad_entity.cpp | 102 ++++---- engines/wintermute/ad/ad_entity.h | 22 +- engines/wintermute/ad/ad_game.cpp | 276 ++++++++++----------- engines/wintermute/ad/ad_game.h | 92 +++---- engines/wintermute/ad/ad_inventory.cpp | 22 +- engines/wintermute/ad/ad_inventory.h | 14 +- engines/wintermute/ad/ad_inventory_box.cpp | 42 ++-- engines/wintermute/ad/ad_inventory_box.h | 20 +- engines/wintermute/ad/ad_item.cpp | 80 +++--- engines/wintermute/ad/ad_item.h | 20 +- engines/wintermute/ad/ad_layer.cpp | 70 +++--- engines/wintermute/ad/ad_layer.h | 20 +- engines/wintermute/ad/ad_node_state.cpp | 26 +- engines/wintermute/ad/ad_node_state.h | 12 +- engines/wintermute/ad/ad_object.cpp | 170 ++++++------- engines/wintermute/ad/ad_object.h | 68 +++--- engines/wintermute/ad/ad_path.cpp | 20 +- engines/wintermute/ad/ad_path.h | 20 +- engines/wintermute/ad/ad_path_point.cpp | 12 +- engines/wintermute/ad/ad_path_point.h | 12 +- engines/wintermute/ad/ad_region.cpp | 38 +-- engines/wintermute/ad/ad_region.h | 16 +- engines/wintermute/ad/ad_response.cpp | 38 +-- engines/wintermute/ad/ad_response.h | 18 +- engines/wintermute/ad/ad_response_box.cpp | 82 +++---- engines/wintermute/ad/ad_response_box.h | 42 ++-- engines/wintermute/ad/ad_response_context.cpp | 10 +- engines/wintermute/ad/ad_response_context.h | 8 +- engines/wintermute/ad/ad_rot_level.cpp | 22 +- engines/wintermute/ad/ad_rot_level.h | 10 +- engines/wintermute/ad/ad_scale_level.cpp | 22 +- engines/wintermute/ad/ad_scale_level.h | 10 +- engines/wintermute/ad/ad_scene.cpp | 340 +++++++++++++------------- engines/wintermute/ad/ad_scene.h | 102 ++++---- engines/wintermute/ad/ad_scene_node.cpp | 14 +- engines/wintermute/ad/ad_scene_node.h | 16 +- engines/wintermute/ad/ad_scene_state.cpp | 14 +- engines/wintermute/ad/ad_scene_state.h | 14 +- engines/wintermute/ad/ad_sentence.cpp | 40 +-- engines/wintermute/ad/ad_sentence.h | 26 +- engines/wintermute/ad/ad_sprite_set.cpp | 46 ++-- engines/wintermute/ad/ad_sprite_set.h | 18 +- engines/wintermute/ad/ad_talk_def.cpp | 44 ++-- engines/wintermute/ad/ad_talk_def.h | 22 +- engines/wintermute/ad/ad_talk_holder.cpp | 42 ++-- engines/wintermute/ad/ad_talk_holder.h | 24 +- engines/wintermute/ad/ad_talk_node.cpp | 38 +-- engines/wintermute/ad/ad_talk_node.h | 20 +- engines/wintermute/ad/ad_waypoint_group.cpp | 38 +-- engines/wintermute/ad/ad_waypoint_group.h | 20 +- 52 files changed, 1263 insertions(+), 1263 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index 36f1aa8286..1da28cd93d 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -52,12 +52,12 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdActor, false) +IMPLEMENT_PERSISTENT(AdActor, false) ////////////////////////////////////////////////////////////////////////// -CAdActor::CAdActor(CBGame *inGame): CAdTalkHolder(inGame) { - _path = new CAdPath(_gameRef); +AdActor::AdActor(BaseGame *inGame): AdTalkHolder(inGame) { + _path = new AdPath(_gameRef); _type = OBJECT_ACTOR; _dir = DI_LEFT; @@ -67,7 +67,7 @@ CAdActor::CAdActor(CBGame *inGame): CAdTalkHolder(inGame) { _turnLeftSprite = NULL; _turnRightSprite = NULL; - _targetPoint = new CBPoint; + _targetPoint = new BasePoint; _afterWalkDir = DI_NONE; _animSprite2 = NULL; @@ -76,7 +76,7 @@ CAdActor::CAdActor(CBGame *inGame): CAdTalkHolder(inGame) { } ////////////////////////////////////////////////////////////////////////// -bool CAdActor::setDefaultAnimNames() { +bool AdActor::setDefaultAnimNames() { _talkAnimName = "talk"; _idleAnimName = "idle"; _walkAnimName = "walk"; @@ -86,7 +86,7 @@ bool CAdActor::setDefaultAnimNames() { } ////////////////////////////////////////////////////////////////////////// -CAdActor::~CAdActor() { +AdActor::~AdActor() { delete _path; delete _targetPoint; _path = NULL; @@ -123,10 +123,10 @@ CAdActor::~CAdActor() { ////////////////////////////////////////////////////////////////////////// -bool CAdActor::loadFile(const char *filename) { +bool AdActor::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdActor::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdActor::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -183,7 +183,7 @@ TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF(ANIMATION) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdActor::loadBuffer(byte *buffer, bool complete) { +bool AdActor::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ACTOR) TOKEN_TABLE(X) @@ -225,7 +225,7 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTOR) { @@ -235,8 +235,8 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { buffer = params; } - CAdGame *adGame = (CAdGame *)_gameRef; - CAdSpriteSet *spr = NULL; + AdGame *adGame = (AdGame *)_gameRef; + AdSpriteSet *spr = NULL; int ar = 0, ag = 0, ab = 0, alpha = 0; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { @@ -290,19 +290,19 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { case TOKEN_WALK: delete _walkSprite; _walkSprite = NULL; - spr = new CAdSpriteSet(_gameRef, this); + spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC; else _walkSprite = spr; break; case TOKEN_TALK: - spr = new CAdSpriteSet(_gameRef, this); + spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; else _talkSprites.add(spr); break; case TOKEN_TALK_SPECIAL: - spr = new CAdSpriteSet(_gameRef, this); + spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; else _talkSpritesEx.add(spr); break; @@ -310,7 +310,7 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { case TOKEN_STAND: delete _standSprite; _standSprite = NULL; - spr = new CAdSpriteSet(_gameRef, this); + spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) cmd = PARSERR_GENERIC; else _standSprite = spr; break; @@ -318,7 +318,7 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { case TOKEN_TURN_LEFT: delete _turnLeftSprite; _turnLeftSprite = NULL; - spr = new CAdSpriteSet(_gameRef, this); + spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; else _turnLeftSprite = spr; break; @@ -326,7 +326,7 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { case TOKEN_TURN_RIGHT: delete _turnRightSprite; _turnRightSprite = NULL; - spr = new CAdSpriteSet(_gameRef, this); + spr = new AdSpriteSet(_gameRef, this); if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; else _turnRightSprite = spr; break; @@ -337,7 +337,7 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { case TOKEN_CURSOR: delete _cursor; - _cursor = new CBSprite(_gameRef); + _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = NULL; @@ -378,8 +378,8 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { delete _currentBlockRegion; _blockRegion = NULL; _currentBlockRegion = NULL; - CBRegion *rgn = new CBRegion(_gameRef); - CBRegion *crgn = new CBRegion(_gameRef); + BaseRegion *rgn = new BaseRegion(_gameRef); + BaseRegion *crgn = new BaseRegion(_gameRef); if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { delete _blockRegion; delete _currentBlockRegion; @@ -399,8 +399,8 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { delete _currentWptGroup; _wptGroup = NULL; _currentWptGroup = NULL; - CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); - CAdWaypointGroup *cwpt = new CAdWaypointGroup(_gameRef); + AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); + AdWaypointGroup *cwpt = new AdWaypointGroup(_gameRef); if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { delete _wptGroup; delete _currentWptGroup; @@ -432,7 +432,7 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ANIMATION: { - CAdSpriteSet *Anim = new CAdSpriteSet(_gameRef, this); + AdSpriteSet *Anim = new AdSpriteSet(_gameRef, this); if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) cmd = PARSERR_GENERIC; else _anims.add(Anim); } @@ -460,7 +460,7 @@ bool CAdActor::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// -void CAdActor::turnTo(TDirection dir) { +void AdActor::turnTo(TDirection dir) { int delta1, delta2, delta3, delta; delta1 = dir - _dir; @@ -486,7 +486,7 @@ void CAdActor::turnTo(TDirection dir) { ////////////////////////////////////////////////////////////////////////// -void CAdActor::goTo(int x, int y, TDirection afterWalkDir) { +void AdActor::goTo(int x, int y, TDirection afterWalkDir) { _afterWalkDir = afterWalkDir; if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) return; @@ -496,7 +496,7 @@ void CAdActor::goTo(int x, int y, TDirection afterWalkDir) { _targetPoint->x = x; _targetPoint->y = y; - ((CAdGame *)_gameRef)->_scene->correctTargetPoint(_posX, _posY, &_targetPoint->x, &_targetPoint->y, true, this); + ((AdGame *)_gameRef)->_scene->correctTargetPoint(_posX, _posY, &_targetPoint->x, &_targetPoint->y, true, this); _state = STATE_SEARCHING_PATH; @@ -504,12 +504,12 @@ void CAdActor::goTo(int x, int y, TDirection afterWalkDir) { ////////////////////////////////////////////////////////////////////////// -bool CAdActor::display() { +bool AdActor::display() { if (_active) updateSounds(); uint32 alpha; if (_alphaColor != 0) alpha = _alphaColor; - else alpha = _shadowable ? ((CAdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; + else alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; float scaleX, scaleY; getScale(&scaleX, &scaleY); @@ -518,14 +518,14 @@ bool CAdActor::display() { float rotate; if (_rotatable) { if (_rotateValid) rotate = _rotate; - else rotate = ((CAdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + else rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; } else rotate = 0.0f; if (_active) displaySpriteAttachments(true); if (_currentSprite && _active) { bool reg = _registrable; - if (_ignoreItems && ((CAdGame *)_gameRef)->_selectedItem) reg = false; + if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) reg = false; _currentSprite->display(_posX, _posY, @@ -547,7 +547,7 @@ bool CAdActor::display() { ////////////////////////////////////////////////////////////////////////// -bool CAdActor::update() { +bool AdActor::update() { _currentSprite = NULL; if (_state == STATE_READY) { @@ -582,7 +582,7 @@ bool CAdActor::update() { if (_standSprite) { _currentSprite = _standSprite->getSprite(_dir); } else { - CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + AdSpriteSet *Anim = getAnimByName(_idleAnimName); if (Anim) _currentSprite = Anim->getSprite(_dir); } } @@ -615,7 +615,7 @@ bool CAdActor::update() { if (_turnLeftSprite) { _tempSprite2 = _turnLeftSprite->getSprite(_dir); } else { - CAdSpriteSet *Anim = getAnimByName(_turnLeftAnimName); + AdSpriteSet *Anim = getAnimByName(_turnLeftAnimName); if (Anim) _tempSprite2 = Anim->getSprite(_dir); } @@ -644,7 +644,7 @@ bool CAdActor::update() { if (_turnRightSprite) { _tempSprite2 = _turnRightSprite->getSprite(_dir); } else { - CAdSpriteSet *Anim = getAnimByName(_turnRightAnimName); + AdSpriteSet *Anim = getAnimByName(_turnRightAnimName); if (Anim) _tempSprite2 = Anim->getSprite(_dir); } @@ -661,7 +661,7 @@ bool CAdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_SEARCHING_PATH: // keep asking scene for the path - if (((CAdGame *)_gameRef)->_scene->getPath(CBPoint(_posX, _posY), *_targetPoint, _path, this)) + if (((AdGame *)_gameRef)->_scene->getPath(BasePoint(_posX, _posY), *_targetPoint, _path, this)) _state = STATE_WAITING_PATH; break; @@ -696,12 +696,12 @@ bool CAdActor::update() { if (_tempSprite2) { _tempSprite2->reset(); _currentSprite = _tempSprite2; - ((CAdGame *)_gameRef)->addSentence(_sentence); + ((AdGame *)_gameRef)->addSentence(_sentence); } } } else { _currentSprite = _tempSprite2; - ((CAdGame *)_gameRef)->addSentence(_sentence); + ((AdGame *)_gameRef)->addSentence(_sentence); } } break; @@ -714,7 +714,7 @@ bool CAdActor::update() { if (_standSprite) { _currentSprite = _standSprite->getSprite(_dir); } else { - CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + AdSpriteSet *Anim = getAnimByName(_idleAnimName); if (Anim) _currentSprite = Anim->getSprite(_dir); } } @@ -726,7 +726,7 @@ bool CAdActor::update() { if (_currentSprite && !already_moved) { - _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + _currentSprite->GetCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); if (_currentSprite->_changed) { _posX += _currentSprite->_moveX; _posY += _currentSprite->_moveY; @@ -747,7 +747,7 @@ bool CAdActor::update() { ////////////////////////////////////////////////////////////////////////// -void CAdActor::followPath() { +void AdActor::followPath() { // skip current position _path->getFirst(); while (_path->getCurrent() != NULL) { @@ -758,7 +758,7 @@ void CAdActor::followPath() { // are there points to follow? if (_path->getCurrent() != NULL) { _state = STATE_FOLLOWING_PATH;; - initLine(CBPoint(_posX, _posY), *_path->getCurrent()); + initLine(BasePoint(_posX, _posY), *_path->getCurrent()); } else { if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); else _state = STATE_READY; @@ -767,17 +767,17 @@ void CAdActor::followPath() { ////////////////////////////////////////////////////////////////////////// -void CAdActor::getNextStep() { +void AdActor::getNextStep() { if (_walkSprite) { _currentSprite = _walkSprite->getSprite(_dir); } else { - CAdSpriteSet *Anim = getAnimByName(_walkAnimName); + AdSpriteSet *Anim = getAnimByName(_walkAnimName); if (Anim) _currentSprite = Anim->getSprite(_dir); } if (!_currentSprite) return; - _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + _currentSprite->GetCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); if (!_currentSprite->_changed) return; @@ -796,7 +796,7 @@ void CAdActor::getNextStep() { maxStepX--; } - if (((CAdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX,(int) _pFY, true, this)) { + if (((AdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX,(int) _pFY, true, this)) { if (_pFCount == 0) { _state = _nextState; _nextState = STATE_READY; @@ -824,13 +824,13 @@ void CAdActor::getNextStep() { _state = _nextState; _nextState = STATE_READY; } - } else initLine(CBPoint(_posX, _posY), *_path->getCurrent()); + } else initLine(BasePoint(_posX, _posY), *_path->getCurrent()); } } ////////////////////////////////////////////////////////////////////////// -void CAdActor::initLine(CBPoint startPt, CBPoint endPt) { +void AdActor::initLine(BasePoint startPt, BasePoint endPt) { _pFCount = MAX((abs(endPt.x - startPt.x)) , (abs(endPt.y - startPt.y))); _pFStepX = (double)(endPt.x - startPt.x) / _pFCount; @@ -850,7 +850,7 @@ void CAdActor::initLine(CBPoint startPt, CBPoint endPt) { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdActor::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // GoTo / GoToAsync ////////////////////////////////////////////////////////////////////////// @@ -869,19 +869,19 @@ bool CAdActor::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GoToObject") == 0 || strcmp(name, "GoToObjectAsync") == 0) { stack->correctParams(1); - CScValue *Val = stack->pop(); + ScValue *Val = stack->pop(); if (!Val->isNative()) { script->runtimeError("actor.%s method accepts an entity refrence only", name); stack->pushNULL(); return STATUS_OK; } - CAdObject *Obj = (CAdObject *)Val->getNative(); + AdObject *Obj = (AdObject *)Val->getNative(); if (!Obj || Obj->_type != OBJECT_ENTITY) { script->runtimeError("actor.%s method accepts an entity refrence only", name); stack->pushNULL(); return STATUS_OK; } - CAdEntity *Ent = (CAdEntity *)Obj; + AdEntity *Ent = (AdEntity *)Obj; if (Ent->_walkToX == 0 && Ent->_walkToY == 0) goTo(Ent->_posX, Ent->_posY); else goTo(Ent->_walkToX, Ent->_walkToY, Ent->_walkToDir); if (strcmp(name, "GoToObjectAsync") != 0) script->waitForExclusive(this); @@ -895,11 +895,11 @@ bool CAdActor::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt else if (strcmp(name, "TurnTo") == 0 || strcmp(name, "TurnToAsync") == 0) { stack->correctParams(1); int dir; - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); // turn to object? - if (val->isNative() && _gameRef->validObject((CBObject *)val->getNative())) { - CBObject *obj = (CBObject *)val->getNative(); + if (val->isNative() && _gameRef->validObject((BaseObject *)val->getNative())) { + BaseObject *obj = (BaseObject *)val->getNative(); int angle = (int)(atan2((double)(obj->_posY - _posY), (double)(obj->_posX - _posX)) * (180 / 3.14)); dir = (int)angleToDirection(angle); } @@ -968,12 +968,12 @@ bool CAdActor::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt return STATUS_OK; } - else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); + else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdActor::scGetProperty(const char *name) { +ScValue *AdActor::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -1030,12 +1030,12 @@ CScValue *CAdActor::scGetProperty(const char *name) { return _scValue; } - else return CAdTalkHolder::scGetProperty(name); + else return AdTalkHolder::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdActor::scSetProperty(const char *name, CScValue *value) { +bool AdActor::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Direction ////////////////////////////////////////////////////////////////////////// @@ -1090,27 +1090,27 @@ bool CAdActor::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else return CAdTalkHolder::scSetProperty(name, value); + else return AdTalkHolder::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -const char *CAdActor::scToString() { +const char *AdActor::scToString() { return "[actor object]"; } ////////////////////////////////////////////////////////////////////////// -CBSprite *CAdActor::getTalkStance(const char *stance) { +BaseSprite *AdActor::getTalkStance(const char *stance) { // forced stance? if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { _forcedTalkAnimUsed = true; delete _animSprite; - _animSprite = new CBSprite(_gameRef, this); + _animSprite = new BaseSprite(_gameRef, this); if (_animSprite) { bool res = _animSprite->loadFile(_forcedTalkAnimName); if (DID_FAIL(res)) { - _gameRef->LOG(res, "CAdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); + _gameRef->LOG(res, "AdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); delete _animSprite; _animSprite = NULL; } else return _animSprite; @@ -1122,15 +1122,15 @@ CBSprite *CAdActor::getTalkStance(const char *stance) { return getTalkStanceOld(stance); // new way - CBSprite *ret = NULL; + BaseSprite *ret = NULL; // do we have an animation with this name? - CAdSpriteSet *Anim = getAnimByName(stance); + AdSpriteSet *Anim = getAnimByName(stance); if (Anim) ret = Anim->getSprite(_dir); // not - get a random talk if (!ret) { - CBArray TalkAnims; + BaseArray TalkAnims; for (int i = 0; i < _anims.getSize(); i++) { if (_talkAnimName.compareToIgnoreCase(_anims[i]->_name) == 0) TalkAnims.add(_anims[i]); @@ -1151,8 +1151,8 @@ CBSprite *CAdActor::getTalkStance(const char *stance) { } ////////////////////////////////////////////////////////////////////////// -CBSprite *CAdActor::getTalkStanceOld(const char *stance) { - CBSprite *ret = NULL; +BaseSprite *AdActor::getTalkStanceOld(const char *stance) { + BaseSprite *ret = NULL; if (stance != NULL) { // search special stances @@ -1187,8 +1187,8 @@ CBSprite *CAdActor::getTalkStanceOld(const char *stance) { } ////////////////////////////////////////////////////////////////////////// -bool CAdActor::persist(CBPersistMgr *persistMgr) { - CAdTalkHolder::persist(persistMgr); +bool AdActor::persist(BasePersistenceManager *persistMgr) { + AdTalkHolder::persist(persistMgr); persistMgr->transfer(TMEMBER_INT(_dir)); persistMgr->transfer(TMEMBER(_path)); @@ -1221,7 +1221,7 @@ bool CAdActor::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -TDirection CAdActor::angleToDirection(int angle) { +TDirection AdActor::angleToDirection(int angle) { TDirection ret = DI_DOWN;; if (angle > -112 && angle <= -67) ret = DI_UP; @@ -1238,22 +1238,22 @@ TDirection CAdActor::angleToDirection(int angle) { ////////////////////////////////////////////////////////////////////////// -int CAdActor::getHeight() { +int AdActor::getHeight() { // if no current sprite is set, set some if (_currentSprite == NULL) { if (_standSprite) _currentSprite = _standSprite->getSprite(_dir); else { - CAdSpriteSet *Anim = getAnimByName(_idleAnimName); + AdSpriteSet *Anim = getAnimByName(_idleAnimName); if (Anim) _currentSprite = Anim->getSprite(_dir); } } // and get height - return CAdTalkHolder::getHeight(); + return AdTalkHolder::getHeight(); } ////////////////////////////////////////////////////////////////////////// -CAdSpriteSet *CAdActor::getAnimByName(const Common::String &animName) { +AdSpriteSet *AdActor::getAnimByName(const Common::String &animName) { for (int i = 0; i < _anims.getSize(); i++) { if (animName.compareToIgnoreCase(_anims[i]->_name) == 0) return _anims[i]; @@ -1262,7 +1262,7 @@ CAdSpriteSet *CAdActor::getAnimByName(const Common::String &animName) { } ////////////////////////////////////////////////////////////////////////// -bool CAdActor::mergeAnims(const char *animsFilename) { +bool AdActor::mergeAnims(const char *animsFilename) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ANIMATION) TOKEN_TABLE_END @@ -1270,21 +1270,21 @@ bool CAdActor::mergeAnims(const char *animsFilename) { byte *fileBuffer = _gameRef->_fileManager->readWholeFile(animsFilename); if (fileBuffer == NULL) { - _gameRef->LOG(0, "CAdActor::MergeAnims failed for file '%s'", animsFilename); + _gameRef->LOG(0, "AdActor::MergeAnims failed for file '%s'", animsFilename); return STATUS_FAILED; } byte *buffer = fileBuffer; byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); bool Ret = STATUS_OK; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_ANIMATION: { - CAdSpriteSet *Anim = new CAdSpriteSet(_gameRef, this); + AdSpriteSet *Anim = new AdSpriteSet(_gameRef, this); if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; Ret = STATUS_FAILED; @@ -1298,9 +1298,9 @@ bool CAdActor::mergeAnims(const char *animsFilename) { } ////////////////////////////////////////////////////////////////////////// -bool CAdActor::playAnim(const char *filename) { +bool AdActor::playAnim(const char *filename) { // if we have an anim with this name, use it - CAdSpriteSet *Anim = getAnimByName(filename); + AdSpriteSet *Anim = getAnimByName(filename); if (Anim) { _animSprite2 = Anim->getSprite(_dir); if (_animSprite2) { @@ -1310,7 +1310,7 @@ bool CAdActor::playAnim(const char *filename) { } } // otherwise call the standard handler - return CAdTalkHolder::playAnim(filename); + return AdTalkHolder::playAnim(filename); } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index 67e0630f83..3cce827b17 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -39,31 +39,31 @@ namespace WinterMute { -class CAdSpriteSet; -class CAdPath; -class CAdActor : public CAdTalkHolder { +class AdSpriteSet; +class AdPath; +class AdActor : public AdTalkHolder { public: TDirection angleToDirection(int angle); - DECLARE_PERSISTENT(CAdActor, CAdTalkHolder) + DECLARE_PERSISTENT(AdActor, AdTalkHolder) virtual int getHeight(); - CBSprite *getTalkStance(const char *stance); + BaseSprite *getTalkStance(const char *stance); virtual void goTo(int x, int y, TDirection afterWalkDir = DI_NONE); - CBPoint *_targetPoint; + BasePoint *_targetPoint; virtual bool update(); virtual bool display(); TDirection _targetDir; TDirection _afterWalkDir; virtual void turnTo(TDirection dir); - CAdPath *_path; - CAdSpriteSet *_walkSprite; - CAdSpriteSet *_standSprite; - CAdSpriteSet *_turnLeftSprite; - CAdSpriteSet *_turnRightSprite; - CBArray _talkSprites; - CBArray _talkSpritesEx; + AdPath *_path; + AdSpriteSet *_walkSprite; + AdSpriteSet *_standSprite; + AdSpriteSet *_turnLeftSprite; + AdSpriteSet *_turnRightSprite; + BaseArray _talkSprites; + BaseArray _talkSpritesEx; TDirection _dir; - CAdActor(CBGame *inGame/*=NULL*/); - virtual ~CAdActor(); + AdActor(BaseGame *inGame/*=NULL*/); + virtual ~AdActor(); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); @@ -73,23 +73,23 @@ public: Common::String _walkAnimName; Common::String _turnLeftAnimName; Common::String _turnRightAnimName; - CBArray _anims; + BaseArray _anims; virtual bool playAnim(const char *filename); - CAdSpriteSet *getAnimByName(const Common::String &animName); + AdSpriteSet *getAnimByName(const Common::String &animName); // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); private: bool setDefaultAnimNames(); - CBSprite *getTalkStanceOld(const char *stance); + BaseSprite *getTalkStanceOld(const char *stance); bool mergeAnims(const char *animsFilename); - CBSprite *_animSprite2; + BaseSprite *_animSprite2; - void initLine(CBPoint startPt, CBPoint endPt); + void initLine(BasePoint startPt, BasePoint endPt); void getNextStep(); void followPath(); double _pFStepX; diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 5f32017264..06a551b252 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -55,10 +55,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdEntity, false) +IMPLEMENT_PERSISTENT(AdEntity, false) ////////////////////////////////////////////////////////////////////////// -CAdEntity::CAdEntity(CBGame *inGame): CAdTalkHolder(inGame) { +AdEntity::AdEntity(BaseGame *inGame): AdTalkHolder(inGame) { _type = OBJECT_ENTITY; _subtype = ENTITY_NORMAL; _region = NULL; @@ -72,7 +72,7 @@ CAdEntity::CAdEntity(CBGame *inGame): CAdTalkHolder(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdEntity::~CAdEntity() { +AdEntity::~AdEntity() { _gameRef->unregisterObject(_region); delete _theora; @@ -84,10 +84,10 @@ CAdEntity::~CAdEntity() { ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::loadFile(const char *filename) { +bool AdEntity::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdEntity::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdEntity::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -150,7 +150,7 @@ TOKEN_DEF(WALK_TO_DIR) TOKEN_DEF(SAVE_STATE) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::loadBuffer(byte *buffer, bool complete) { +bool AdEntity::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ENTITY) TOKEN_TABLE(SPRITE) @@ -198,7 +198,7 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY) { @@ -208,8 +208,8 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { buffer = params; } - CAdGame *adGame = (CAdGame *)_gameRef; - CBSprite *spr = NULL; + AdGame *adGame = (AdGame *)_gameRef; + BaseSprite *spr = NULL; int ar = 0, ag = 0, ab = 0, alpha = 0; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { @@ -228,21 +228,21 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { case TOKEN_SPRITE: { delete _sprite; _sprite = NULL; - spr = new CBSprite(_gameRef, this); + spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile((char *)params))) cmd = PARSERR_GENERIC; else _sprite = spr; } break; case TOKEN_TALK: { - spr = new CBSprite(_gameRef, this); + spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; else _talkSprites.add(spr); } break; case TOKEN_TALK_SPECIAL: { - spr = new CBSprite(_gameRef, this); + spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; else _talkSpritesEx.add(spr); } @@ -305,7 +305,7 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { case TOKEN_CURSOR: delete _cursor; - _cursor = new CBSprite(_gameRef); + _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = NULL; @@ -320,7 +320,7 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { case TOKEN_REGION: { if (_region) _gameRef->unregisterObject(_region); _region = NULL; - CBRegion *rgn = new CBRegion(_gameRef); + BaseRegion *rgn = new BaseRegion(_gameRef); if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) cmd = PARSERR_GENERIC; else { _region = rgn; @@ -334,8 +334,8 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { _blockRegion = NULL; delete _currentBlockRegion; _currentBlockRegion = NULL; - CBRegion *rgn = new CBRegion(_gameRef); - CBRegion *crgn = new CBRegion(_gameRef); + BaseRegion *rgn = new BaseRegion(_gameRef); + BaseRegion *crgn = new BaseRegion(_gameRef); if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { delete _blockRegion; _blockRegion = NULL; @@ -355,8 +355,8 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { _wptGroup = NULL; delete _currentWptGroup; _currentWptGroup = NULL; - CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); - CAdWaypointGroup *cwpt = new CAdWaypointGroup(_gameRef); + AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); + AdWaypointGroup *cwpt = new AdWaypointGroup(_gameRef); if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { delete _wptGroup; _wptGroup = NULL; @@ -380,7 +380,7 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { delete _sprite; _sprite = NULL; if (_gameRef->_editorMode) { - spr = new CBSprite(_gameRef, this); + spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) cmd = PARSERR_GENERIC; else _sprite = spr; } @@ -474,20 +474,20 @@ bool CAdEntity::loadBuffer(byte *buffer, bool complete) { _alphaColor = BYTETORGBA(ar, ag, ab, alpha); _state = STATE_READY; - if (_item && ((CAdGame *)_gameRef)->isItemTaken(_item)) _active = false; + if (_item && ((AdGame *)_gameRef)->isItemTaken(_item)) _active = false; return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::display() { +bool AdEntity::display() { if (_active) { updateSounds(); uint32 Alpha; if (_alphaColor != 0) Alpha = _alphaColor; - else Alpha = _shadowable ? ((CAdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; + else Alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; float ScaleX, ScaleY; getScale(&ScaleX, &ScaleY); @@ -495,15 +495,15 @@ bool CAdEntity::display() { float Rotate; if (_rotatable) { if (_rotateValid) Rotate = _rotate; - else Rotate = ((CAdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + else Rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; } else Rotate = 0.0f; bool Reg = _registrable; - if (_ignoreItems && ((CAdGame *)_gameRef)->_selectedItem) Reg = false; + if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) Reg = false; if (_region && (Reg || _editorAlwaysRegister)) { - _gameRef->_renderer->_rectList.add(new CBActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); + _gameRef->_renderer->_rectList.add(new BaseActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); } displaySpriteAttachments(true); @@ -529,7 +529,7 @@ bool CAdEntity::display() { ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::update() { +bool AdEntity::update() { _currentSprite = NULL; if (_state == STATE_READY && _animSprite) { @@ -577,11 +577,11 @@ bool CAdEntity::update() { _tempSprite2->reset(); _currentSprite = _tempSprite2; } - ((CAdGame *)_gameRef)->addSentence(_sentence); + ((AdGame *)_gameRef)->addSentence(_sentence); } } else { _currentSprite = _tempSprite2; - ((CAdGame *)_gameRef)->addSentence(_sentence); + ((AdGame *)_gameRef)->addSentence(_sentence); } } break; @@ -591,7 +591,7 @@ bool CAdEntity::update() { if (_currentSprite) { - _currentSprite->GetCurrentFrame(_zoomable ? ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + _currentSprite->GetCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); if (_currentSprite->_changed) { _posX += _currentSprite->_moveX; _posY += _currentSprite->_moveY; @@ -625,7 +625,7 @@ bool CAdEntity::update() { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // StopSound ////////////////////////////////////////////////////////////////////////// @@ -644,11 +644,11 @@ bool CAdEntity::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS stack->correctParams(4); const char *filename = stack->pop()->getString(); bool looping = stack->pop()->getBool(false); - CScValue *valAlpha = stack->pop(); + ScValue *valAlpha = stack->pop(); int startTime = stack->pop()->getInt(); delete _theora; - _theora = new CVidTheoraPlayer(_gameRef); + _theora = new VideoTheoraPlayer(_gameRef); if (_theora && DID_SUCCEED(_theora->initialize(filename))) { if (!valAlpha->isNULL()) _theora->setAlphaImage(valAlpha->getString()); _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); @@ -732,7 +732,7 @@ bool CAdEntity::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS else if (strcmp(name, "CreateRegion") == 0) { stack->correctParams(0); if (!_region) { - _region = new CBRegion(_gameRef); + _region = new BaseRegion(_gameRef); _gameRef->registerObject(_region); } if (_region) stack->pushNative(_region, true); @@ -755,12 +755,12 @@ bool CAdEntity::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS return STATUS_OK; } - else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); + else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdEntity::scGetProperty(const char *name) { +ScValue *AdEntity::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -826,12 +826,12 @@ CScValue *CAdEntity::scGetProperty(const char *name) { return _scValue; } - else return CAdTalkHolder::scGetProperty(name); + else return AdTalkHolder::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::scSetProperty(const char *name, CScValue *value) { +bool AdEntity::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Item @@ -866,18 +866,18 @@ bool CAdEntity::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else return CAdTalkHolder::scSetProperty(name, value); + else return AdTalkHolder::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -const char *CAdEntity::scToString() { +const char *AdEntity::scToString() { return "[entity object]"; } ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "ENTITY {\n"); buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); if (_subtype == ENTITY_SOUND) @@ -942,13 +942,13 @@ bool CAdEntity::saveAsText(CBDynBuffer *buffer, int indent) { if (_cursor && _cursor->_filename) buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); - CAdTalkHolder::saveAsText(buffer, indent + 2); + AdTalkHolder::saveAsText(buffer, indent + 2); if (_region) _region->saveAsText(buffer, indent + 2); if (_scProp) _scProp->saveAsText(buffer, indent + 2); - CAdObject::saveAsText(buffer, indent + 2); + AdObject::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n\n"); @@ -957,18 +957,18 @@ bool CAdEntity::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -int CAdEntity::getHeight() { +int AdEntity::getHeight() { if (_region && !_sprite) { return _region->_rect.bottom - _region->_rect.top; } else { if (_currentSprite == NULL) _currentSprite = _sprite; - return CAdObject::getHeight(); + return AdObject::getHeight(); } } ////////////////////////////////////////////////////////////////////////// -void CAdEntity::updatePosition() { +void AdEntity::updatePosition() { if (_region && !_sprite) { _posX = _region->_rect.left + (_region->_rect.right - _region->_rect.left) / 2; _posY = _region->_rect.bottom; @@ -977,8 +977,8 @@ void CAdEntity::updatePosition() { ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::persist(CBPersistMgr *persistMgr) { - CAdTalkHolder::persist(persistMgr); +bool AdEntity::persist(BasePersistenceManager *persistMgr) { + AdTalkHolder::persist(persistMgr); persistMgr->transfer(TMEMBER(_item)); persistMgr->transfer(TMEMBER(_region)); @@ -998,12 +998,12 @@ bool CAdEntity::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -void CAdEntity::setItem(const char *itemName) { - CBUtils::setString(&_item, itemName); +void AdEntity::setItem(const char *itemName) { + BaseUtils::setString(&_item, itemName); } ////////////////////////////////////////////////////////////////////////// -bool CAdEntity::setSprite(const char *filename) { +bool AdEntity::setSprite(const char *filename) { bool setCurrent = false; if (_currentSprite == _sprite) { _currentSprite = NULL; @@ -1012,7 +1012,7 @@ bool CAdEntity::setSprite(const char *filename) { delete _sprite; _sprite = NULL; - CBSprite *spr = new CBSprite(_gameRef, this); + BaseSprite *spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile(filename))) { delete _sprite; _sprite = NULL; diff --git a/engines/wintermute/ad/ad_entity.h b/engines/wintermute/ad/ad_entity.h index 8b67d27c1f..9931327916 100644 --- a/engines/wintermute/ad/ad_entity.h +++ b/engines/wintermute/ad/ad_entity.h @@ -32,33 +32,33 @@ #include "engines/wintermute/ad/ad_talk_holder.h" namespace WinterMute { -class CVidTheoraPlayer; -class CAdEntity : public CAdTalkHolder { +class VideoTheoraPlayer; +class AdEntity : public AdTalkHolder { public: - CVidTheoraPlayer *_theora; + VideoTheoraPlayer *_theora; bool setSprite(const char *filename); int _walkToX; int _walkToY; TDirection _walkToDir; void setItem(const char *itemName); char *_item; - DECLARE_PERSISTENT(CAdEntity, CAdTalkHolder) + DECLARE_PERSISTENT(AdEntity, AdTalkHolder) void updatePosition(); virtual int getHeight(); - CBRegion *_region; - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + BaseRegion *_region; + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); virtual bool update(); virtual bool display(); - CAdEntity(CBGame *inGame); - virtual ~CAdEntity(); + AdEntity(BaseGame *inGame); + virtual ~AdEntity(); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); TEntityType _subtype; // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); }; diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 69cda25f29..e10ec1bf6d 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -63,14 +63,14 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdGame, true) +IMPLEMENT_PERSISTENT(AdGame, true) ////////////////////////////////////////////////////////////////////////// -CAdGame::CAdGame(): CBGame() { +AdGame::AdGame(): BaseGame() { _responseBox = NULL; _inventoryBox = NULL; - _scene = new CAdScene(_gameRef); + _scene = new AdScene(_gameRef); _scene->setName(""); registerObject(_scene); @@ -98,7 +98,7 @@ CAdGame::CAdGame(): CBGame() { _debugStartupScene = NULL; _startupScene = NULL; - _invObject = new CAdObject(this); + _invObject = new AdObject(this); _inventoryOwner = _invObject; _tempDisableSaveState = false; @@ -111,13 +111,13 @@ CAdGame::CAdGame(): CBGame() { ////////////////////////////////////////////////////////////////////////// -CAdGame::~CAdGame() { +AdGame::~AdGame() { cleanup(); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::cleanup() { +bool AdGame::cleanup() { int i; for (i = 0; i < _objects.getSize(); i++) { @@ -190,12 +190,12 @@ bool CAdGame::cleanup() { for (i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; _responsesGame.removeAll(); - return CBGame::cleanup(); + return BaseGame::cleanup(); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::initLoop() { +bool AdGame::initLoop() { if (_scheduledScene && _transMgr->isReady()) { changeScene(_scheduledScene, _scheduledFadeIn); delete[] _scheduledScene; @@ -206,7 +206,7 @@ bool CAdGame::initLoop() { bool res; - res = CBGame::initLoop(); + res = BaseGame::initLoop(); if (DID_FAIL(res)) return res; if (_scene) res = _scene->initLoop(); @@ -218,14 +218,14 @@ bool CAdGame::initLoop() { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::addObject(CAdObject *object) { +bool AdGame::addObject(AdObject *object) { _objects.add(object); return registerObject(object); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::removeObject(CAdObject *object) { +bool AdGame::removeObject(AdObject *object) { // in case the user called Scene.CreateXXX() and Game.DeleteXXX() if (_scene) { bool Res = _scene->removeObject(object); @@ -243,9 +243,9 @@ bool CAdGame::removeObject(CAdObject *object) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::changeScene(const char *filename, bool fadeIn) { +bool AdGame::changeScene(const char *filename, bool fadeIn) { if (_scene == NULL) { - _scene = new CAdScene(_gameRef); + _scene = new AdScene(_gameRef); registerObject(_scene); } else { _scene->applyEvent("SceneShutdown", true); @@ -287,13 +287,13 @@ bool CAdGame::changeScene(const char *filename, bool fadeIn) { ////////////////////////////////////////////////////////////////////////// -void CAdGame::addSentence(CAdSentence *sentence) { +void AdGame::addSentence(AdSentence *sentence) { _sentences.add(sentence); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::displaySentences(bool frozen) { +bool AdGame::displaySentences(bool frozen) { for (int i = 0; i < _sentences.getSize(); i++) { if (frozen && _sentences[i]->_freezable) continue; else _sentences[i]->display(); @@ -303,7 +303,7 @@ bool CAdGame::displaySentences(bool frozen) { ////////////////////////////////////////////////////////////////////////// -void CAdGame::finishSentences() { +void AdGame::finishSentences() { for (int i = 0; i < _sentences.getSize(); i++) { if (_sentences[i]->CanSkip()) { _sentences[i]->_duration = 0; @@ -316,15 +316,15 @@ void CAdGame::finishSentences() { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // ChangeScene ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "ChangeScene") == 0) { stack->correctParams(3); const char *filename = stack->pop()->getString(); - CScValue *valFadeOut = stack->pop(); - CScValue *valFadeIn = stack->pop(); + ScValue *valFadeOut = stack->pop(); + ScValue *valFadeIn = stack->pop(); bool transOut = valFadeOut->isNULL() ? true : valFadeOut->getBool(); bool transIn = valFadeIn->isNULL() ? true : valFadeIn->getBool(); @@ -346,7 +346,7 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "LoadActor") == 0) { stack->correctParams(1); - CAdActor *act = new CAdActor(_gameRef); + AdActor *act = new AdActor(_gameRef); if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { addObject(act); stack->pushNative(act, true); @@ -363,7 +363,7 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "LoadEntity") == 0) { stack->correctParams(1); - CAdEntity *ent = new CAdEntity(_gameRef); + AdEntity *ent = new AdEntity(_gameRef); if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { addObject(ent); stack->pushNative(ent, true); @@ -380,8 +380,8 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "DeleteEntity") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); - CAdObject *obj = (CAdObject *)val->getNative(); + ScValue *val = stack->pop(); + AdObject *obj = (AdObject *)val->getNative(); removeObject(obj); if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); @@ -394,9 +394,9 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "CreateEntity") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdEntity *ent = new CAdEntity(_gameRef); + AdEntity *ent = new AdEntity(_gameRef); addObject(ent); if (!val->isNULL()) ent->setName(val->getString()); stack->pushNative(ent, true); @@ -408,9 +408,9 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "CreateItem") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdItem *item = new CAdItem(_gameRef); + AdItem *item = new AdItem(_gameRef); addItem(item); if (!val->isNULL()) item->setName(val->getString()); stack->pushNative(item, true); @@ -422,10 +422,10 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "DeleteItem") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdItem *item = NULL; - if (val->isNative()) item = (CAdItem *)val->getNative(); + AdItem *item = NULL; + if (val->isNative()) item = (AdItem *)val->getNative(); else item = getItemByName(val->getString()); if (item) { @@ -441,9 +441,9 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "QueryItem") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdItem *item = NULL; + AdItem *item = NULL; if (val->isInt()) { int index = val->getInt(); if (index >= 0 && index < _items.getSize()) item = _items[index]; @@ -465,13 +465,13 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta stack->correctParams(6); int id = stack->pop()->getInt(); const char *text = stack->pop()->getString(); - CScValue *val1 = stack->pop(); - CScValue *val2 = stack->pop(); - CScValue *val3 = stack->pop(); - CScValue *val4 = stack->pop(); + ScValue *val1 = stack->pop(); + ScValue *val2 = stack->pop(); + ScValue *val3 = stack->pop(); + ScValue *val4 = stack->pop(); if (_responseBox) { - CAdResponse *res = new CAdResponse(_gameRef); + AdResponse *res = new AdResponse(_gameRef); if (res) { res->_iD = id; res->setText(text); @@ -573,7 +573,7 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "StartDlgBranch") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); Common::String branchName; if (val->isNULL()) { branchName.format("line%d", script->_currentLine); @@ -592,7 +592,7 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta stack->correctParams(1); const char *branchName = NULL; - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (!val->isNULL()) branchName = val->getString(); endDlgBranch(branchName, script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); @@ -648,10 +648,10 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta else if (strcmp(name, "IsItemTaken") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (!val->isNULL()) { for (int i = 0; i < _inventories.getSize(); i++) { - CAdInventory *Inv = _inventories[i]; + AdInventory *Inv = _inventories[i]; for (int j = 0; j < Inv->_takenItems.getSize(); j++) { if (val->getNative() == Inv->_takenItems[j]) { @@ -703,7 +703,7 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta const char *filename = stack->pop()->getString(); _gameRef->unregisterObject(_responseBox); - _responseBox = new CAdResponseBox(_gameRef); + _responseBox = new AdResponseBox(_gameRef); if (_responseBox && !DID_FAIL(_responseBox->loadFile(filename))) { registerObject(_responseBox); stack->pushBool(true); @@ -723,7 +723,7 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta const char *filename = stack->pop()->getString(); _gameRef->unregisterObject(_inventoryBox); - _inventoryBox = new CAdInventoryBox(_gameRef); + _inventoryBox = new AdInventoryBox(_gameRef); if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile(filename))) { registerObject(_inventoryBox); stack->pushBool(true); @@ -784,7 +784,7 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta if (width <= 0) width = _renderer->_width; if (height <= 0) height = _renderer->_height; - if (!_sceneViewport) _sceneViewport = new CBViewport(_gameRef); + if (!_sceneViewport) _sceneViewport = new BaseViewport(_gameRef); if (_sceneViewport) _sceneViewport->setRect(x, y, x + width, y + height); stack->pushBool(true); @@ -793,12 +793,12 @@ bool CAdGame::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta } - else return CBGame::scCallMethod(script, stack, thisStack, name); + else return BaseGame::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdGame::scGetProperty(const char *name) { +ScValue *AdGame::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -947,12 +947,12 @@ CScValue *CAdGame::scGetProperty(const char *name) { return _scValue; } - else return CBGame::scGetProperty(name); + else return BaseGame::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::scSetProperty(const char *name, CScValue *value) { +bool AdGame::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // SelectedItem @@ -964,7 +964,7 @@ bool CAdGame::scSetProperty(const char *name, CScValue *value) { _selectedItem = NULL; for (int i = 0; i < _items.getSize(); i++) { if (_items[i] == value->getNative()) { - _selectedItem = (CAdItem *)value->getNative(); + _selectedItem = (AdItem *)value->getNative(); break; } } @@ -1001,9 +1001,9 @@ bool CAdGame::scSetProperty(const char *name, CScValue *value) { if (value->isNULL()) _inventoryOwner = _invObject; else { - CBObject *Obj = (CBObject *)value->getNative(); + BaseObject *Obj = (BaseObject *)value->getNative(); if (Obj == this) _inventoryOwner = _invObject; - else if (_gameRef->validObject(Obj)) _inventoryOwner = (CAdObject *)Obj; + else if (_gameRef->validObject(Obj)) _inventoryOwner = (AdObject *)Obj; } if (_inventoryOwner && _inventoryBox) _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; @@ -1037,18 +1037,18 @@ bool CAdGame::scSetProperty(const char *name, CScValue *value) { if (value == NULL) { delete[] _startupScene; _startupScene = NULL; - } else CBUtils::setString(&_startupScene, value->getString()); + } else BaseUtils::setString(&_startupScene, value->getString()); return STATUS_OK; } - else return CBGame::scSetProperty(name, value); + else return BaseGame::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name) { - CScValue *this_obj; +bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name) { + ScValue *this_obj; ////////////////////////////////////////////////////////////////////////// // Actor @@ -1057,7 +1057,7 @@ bool CAdGame::ExternalCall(CScScript *script, CScStack *stack, CScStack *thisSta stack->correctParams(0); this_obj = thisStack->getTop(); - this_obj->setNative(new CAdActor(_gameRef)); + this_obj->setNative(new AdActor(_gameRef)); stack->pushNULL(); } @@ -1068,14 +1068,14 @@ bool CAdGame::ExternalCall(CScScript *script, CScStack *stack, CScStack *thisSta stack->correctParams(0); this_obj = thisStack->getTop(); - this_obj->setNative(new CAdEntity(_gameRef)); + this_obj->setNative(new AdEntity(_gameRef)); stack->pushNULL(); } ////////////////////////////////////////////////////////////////////////// // call parent - else return CBGame::ExternalCall(script, stack, thisStack, name); + else return BaseGame::ExternalCall(script, stack, thisStack, name); return STATUS_OK; @@ -1083,13 +1083,13 @@ bool CAdGame::ExternalCall(CScScript *script, CScStack *stack, CScStack *thisSta ////////////////////////////////////////////////////////////////////////// -bool CAdGame::showCursor() { +bool AdGame::showCursor() { if (_cursorHidden) return STATUS_OK; if (_selectedItem && _gameRef->_state == GAME_RUNNING && _stateEx == GAME_NORMAL && _interactive) { if (_selectedItem->_cursorCombined) { - CBSprite *origLastCursor = _lastCursor; - CBGame::showCursor(); + BaseSprite *origLastCursor = _lastCursor; + BaseGame::showCursor(); _lastCursor = origLastCursor; } if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { @@ -1098,15 +1098,15 @@ bool CAdGame::showCursor() { else return drawCursor(_selectedItem->_cursorNormal); } else return drawCursor(_selectedItem->_cursorNormal); - } else return CBGame::showCursor(); + } else return BaseGame::showCursor(); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadFile(const char *filename) { +bool AdGame::loadFile(const char *filename) { byte *buffer = _fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdGame::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdGame::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -1139,7 +1139,7 @@ TOKEN_DEF(STARTUP_SCENE) TOKEN_DEF(DEBUG_STARTUP_SCENE) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadBuffer(byte *buffer, bool complete) { +bool AdGame::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(GAME) TOKEN_TABLE(AD_GAME) @@ -1156,14 +1156,14 @@ bool CAdGame::loadBuffer(byte *buffer, bool complete) { byte *params; byte *params2; int cmd = 1; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); bool itemFound = false, itemsFound = false; while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_GAME: - if (DID_FAIL(CBGame::loadBuffer(params, false))) cmd = PARSERR_GENERIC; + if (DID_FAIL(BaseGame::loadBuffer(params, false))) cmd = PARSERR_GENERIC; break; case TOKEN_AD_GAME: @@ -1171,7 +1171,7 @@ bool CAdGame::loadBuffer(byte *buffer, bool complete) { switch (cmd) { case TOKEN_RESPONSE_BOX: delete _responseBox; - _responseBox = new CAdResponseBox(_gameRef); + _responseBox = new AdResponseBox(_gameRef); if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) registerObject(_responseBox); else { @@ -1183,7 +1183,7 @@ bool CAdGame::loadBuffer(byte *buffer, bool complete) { case TOKEN_INVENTORY_BOX: delete _inventoryBox; - _inventoryBox = new CAdInventoryBox(_gameRef); + _inventoryBox = new AdInventoryBox(_gameRef); if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) registerObject(_inventoryBox); else { @@ -1195,7 +1195,7 @@ bool CAdGame::loadBuffer(byte *buffer, bool complete) { case TOKEN_ITEMS: itemsFound = true; - CBUtils::setString(&_itemsFile, (char *)params2); + BaseUtils::setString(&_itemsFile, (char *)params2); if (DID_FAIL(loadItemsFile(_itemsFile))) { delete[] _itemsFile; _itemsFile = NULL; @@ -1212,7 +1212,7 @@ bool CAdGame::loadBuffer(byte *buffer, bool complete) { case TOKEN_SCENE_VIEWPORT: { Rect32 rc; parser.scanStr((char *)params2, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_sceneViewport) _sceneViewport = new CBViewport(_gameRef); + if (!_sceneViewport) _sceneViewport = new BaseViewport(_gameRef); if (_sceneViewport) _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); } break; @@ -1222,11 +1222,11 @@ bool CAdGame::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_STARTUP_SCENE: - CBUtils::setString(&_startupScene, (char *)params2); + BaseUtils::setString(&_startupScene, (char *)params2); break; case TOKEN_DEBUG_STARTUP_SCENE: - CBUtils::setString(&_debugStartupScene, (char *)params2); + BaseUtils::setString(&_debugStartupScene, (char *)params2); break; } } @@ -1252,9 +1252,9 @@ bool CAdGame::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::persist(CBPersistMgr *persistMgr) { +bool AdGame::persist(BasePersistenceManager *persistMgr) { if (!persistMgr->_saving) cleanup(); - CBGame::persist(persistMgr); + BaseGame::persist(persistMgr); _dlgPendingBranches.persist(persistMgr); @@ -1303,27 +1303,27 @@ bool CAdGame::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadGame(const char *filename) { - bool ret = CBGame::loadGame(filename); - if (DID_SUCCEED(ret)) CSysClassRegistry::getInstance()->enumInstances(afterLoadRegion, "CAdRegion", NULL); +bool AdGame::loadGame(const char *filename) { + bool ret = BaseGame::loadGame(filename); + if (DID_SUCCEED(ret)) SystemClassRegistry::getInstance()->enumInstances(afterLoadRegion, "AdRegion", NULL); return ret; } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::initAfterLoad() { - CBGame::initAfterLoad(); - CSysClassRegistry::getInstance()->enumInstances(afterLoadScene, "CAdScene", NULL); +bool AdGame::initAfterLoad() { + BaseGame::initAfterLoad(); + SystemClassRegistry::getInstance()->enumInstances(afterLoadScene, "AdScene", NULL); return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -void CAdGame::afterLoadScene(void *scene, void *data) { - ((CAdScene *)scene)->afterLoad(); +void AdGame::afterLoadScene(void *scene, void *data) { + ((AdScene *)scene)->afterLoad(); } ////////////////////////////////////////////////////////////////////////// -void CAdGame::setPrevSceneName(const char *name) { +void AdGame::setPrevSceneName(const char *name) { delete[] _prevSceneName; _prevSceneName = NULL; if (name) { @@ -1334,7 +1334,7 @@ void CAdGame::setPrevSceneName(const char *name) { ////////////////////////////////////////////////////////////////////////// -void CAdGame::setPrevSceneFilename(const char *name) { +void AdGame::setPrevSceneFilename(const char *name) { delete[] _prevSceneFilename; _prevSceneFilename = NULL; if (name) { @@ -1345,7 +1345,7 @@ void CAdGame::setPrevSceneFilename(const char *name) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::scheduleChangeScene(const char *filename, bool fadeIn) { +bool AdGame::scheduleChangeScene(const char *filename, bool fadeIn) { delete[] _scheduledScene; _scheduledScene = NULL; @@ -1362,8 +1362,8 @@ bool CAdGame::scheduleChangeScene(const char *filename, bool fadeIn) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { - CBGame::getVersion(verMajor, verMinor, NULL, NULL); +bool AdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { + BaseGame::getVersion(verMajor, verMinor, NULL, NULL); if (extMajor) *extMajor = 0; if (extMinor) *extMinor = 0; @@ -1373,10 +1373,10 @@ bool CAdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *e ////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadItemsFile(const char *filename, bool merge) { +bool AdGame::loadItemsFile(const char *filename, bool merge) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdGame::LoadItemsFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdGame::LoadItemsFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -1395,14 +1395,14 @@ bool CAdGame::loadItemsFile(const char *filename, bool merge) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::loadItemsBuffer(byte *buffer, bool merge) { +bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ITEM) TOKEN_TABLE_END byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (!merge) { while (_items.getSize() > 0) deleteItem(_items[0]); @@ -1411,11 +1411,11 @@ bool CAdGame::loadItemsBuffer(byte *buffer, bool merge) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_ITEM: { - CAdItem *item = new CAdItem(_gameRef); + AdItem *item = new AdItem(_gameRef); if (item && !DID_FAIL(item->loadBuffer(params, false))) { // delete item with the same name, if exists if (merge) { - CAdItem *PrevItem = getItemByName(item->_name); + AdItem *PrevItem = getItemByName(item->_name); if (PrevItem) deleteItem(PrevItem); } addItem(item); @@ -1443,7 +1443,7 @@ bool CAdGame::loadItemsBuffer(byte *buffer, bool merge) { ////////////////////////////////////////////////////////////////////////// -CAdSceneState *CAdGame::getSceneState(const char *filename, bool saving) { +AdSceneState *AdGame::getSceneState(const char *filename, bool saving) { char *filenameCor = new char[strlen(filename) + 1]; strcpy(filenameCor, filename); for (uint32 i = 0; i < strlen(filenameCor); i++) { @@ -1458,7 +1458,7 @@ CAdSceneState *CAdGame::getSceneState(const char *filename, bool saving) { } if (saving) { - CAdSceneState *ret = new CAdSceneState(_gameRef); + AdSceneState *ret = new AdSceneState(_gameRef); ret->setFilename(filenameCor); _sceneStates.add(ret); @@ -1473,18 +1473,18 @@ CAdSceneState *CAdGame::getSceneState(const char *filename, bool saving) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::windowLoadHook(CUIWindow *win, char **buffer, char **params) { +bool AdGame::windowLoadHook(UIWindow *win, char **buffer, char **params) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ENTITY_CONTAINER) TOKEN_TABLE_END int cmd = PARSERR_GENERIC; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); cmd = parser.getCommand(buffer, commands, params); switch (cmd) { case TOKEN_ENTITY_CONTAINER: { - CUIEntity *ent = new CUIEntity(_gameRef); + UIEntity *ent = new UIEntity(_gameRef); if (!ent || DID_FAIL(ent->loadBuffer((byte *)*params, false))) { delete ent; ent = NULL; @@ -1507,12 +1507,12 @@ bool CAdGame::windowLoadHook(CUIWindow *win, char **buffer, char **params) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name) { +bool AdGame::windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *stack, const char *name) { if (strcmp(name, "CreateEntityContainer") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CUIEntity *ent = new CUIEntity(_gameRef); + UIEntity *ent = new UIEntity(_gameRef); if (!val->isNULL()) ent->setName(val->getString()); stack->pushNative(ent, true); @@ -1525,7 +1525,7 @@ bool CAdGame::windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack ////////////////////////////////////////////////////////////////////////// -bool CAdGame::startDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { +bool AdGame::startDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { char *name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; if (name) { sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); @@ -1536,7 +1536,7 @@ bool CAdGame::startDlgBranch(const char *branchName, const char *scriptName, con ////////////////////////////////////////////////////////////////////////// -bool CAdGame::endDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { +bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { char *name = NULL; bool deleteName = false; if (branchName == NULL && _dlgPendingBranches.getSize() > 0) { @@ -1583,7 +1583,7 @@ bool CAdGame::endDlgBranch(const char *branchName, const char *scriptName, const ////////////////////////////////////////////////////////////////////////// -bool CAdGame::clearBranchResponses(char *name) { +bool AdGame::clearBranchResponses(char *name) { for (int i = 0; i < _responsesBranch.getSize(); i++) { if (scumm_stricmp(name, _responsesBranch[i]->_context) == 0) { delete _responsesBranch[i]; @@ -1596,9 +1596,9 @@ bool CAdGame::clearBranchResponses(char *name) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::addBranchResponse(int ID) { +bool AdGame::addBranchResponse(int ID) { if (branchResponseUsed(ID)) return STATUS_OK; - CAdResponseContext *r = new CAdResponseContext(_gameRef); + AdResponseContext *r = new AdResponseContext(_gameRef); r->_iD = ID; r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); _responsesBranch.add(r); @@ -1607,7 +1607,7 @@ bool CAdGame::addBranchResponse(int ID) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::branchResponseUsed(int ID) { +bool AdGame::branchResponseUsed(int ID) { char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; for (int i = 0; i < _responsesBranch.getSize(); i++) { if (_responsesBranch[i]->_iD == ID) { @@ -1619,9 +1619,9 @@ bool CAdGame::branchResponseUsed(int ID) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::addGameResponse(int ID) { +bool AdGame::addGameResponse(int ID) { if (gameResponseUsed(ID)) return STATUS_OK; - CAdResponseContext *r = new CAdResponseContext(_gameRef); + AdResponseContext *r = new AdResponseContext(_gameRef); r->_iD = ID; r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); _responsesGame.add(r); @@ -1630,10 +1630,10 @@ bool CAdGame::addGameResponse(int ID) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::gameResponseUsed(int ID) { +bool AdGame::gameResponseUsed(int ID) { char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; for (int i = 0; i < _responsesGame.getSize(); i++) { - CAdResponseContext *RespContext = _responsesGame[i]; + AdResponseContext *RespContext = _responsesGame[i]; if (RespContext->_iD == ID) { if ((Context == NULL && RespContext->_context == NULL) || ((Context != NULL && RespContext->_context != NULL) && scumm_stricmp(Context, RespContext->_context) == 0)) return true; } @@ -1643,7 +1643,7 @@ bool CAdGame::gameResponseUsed(int ID) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::resetResponse(int ID) { +bool AdGame::resetResponse(int ID) { char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; int i; @@ -1672,7 +1672,7 @@ bool CAdGame::resetResponse(int ID) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::displayContent(bool doUpdate, bool displayAll) { +bool AdGame::displayContent(bool doUpdate, bool displayAll) { // init if (doUpdate) initLoop(); @@ -1740,7 +1740,7 @@ bool CAdGame::displayContent(bool doUpdate, bool displayAll) { } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::registerInventory(CAdInventory *inv) { +bool AdGame::registerInventory(AdInventory *inv) { for (int i = 0; i < _inventories.getSize(); i++) { if (_inventories[i] == inv) return STATUS_OK; } @@ -1751,7 +1751,7 @@ bool CAdGame::registerInventory(CAdInventory *inv) { } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::unregisterInventory(CAdInventory *inv) { +bool AdGame::unregisterInventory(AdInventory *inv) { for (int i = 0; i < _inventories.getSize(); i++) { if (_inventories[i] == inv) { unregisterObject(_inventories[i]); @@ -1763,9 +1763,9 @@ bool CAdGame::unregisterInventory(CAdInventory *inv) { } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::isItemTaken(char *itemName) { +bool AdGame::isItemTaken(char *itemName) { for (int i = 0; i < _inventories.getSize(); i++) { - CAdInventory *Inv = _inventories[i]; + AdInventory *Inv = _inventories[i]; for (int j = 0; j < Inv->_takenItems.getSize(); j++) { if (scumm_stricmp(itemName, Inv->_takenItems[j]->_name) == 0) { @@ -1777,7 +1777,7 @@ bool CAdGame::isItemTaken(char *itemName) { } ////////////////////////////////////////////////////////////////////////// -CAdItem *CAdGame::getItemByName(const char *name) { +AdItem *AdGame::getItemByName(const char *name) { for (int i = 0; i < _items.getSize(); i++) { if (scumm_stricmp(_items[i]->_name, name) == 0) return _items[i]; } @@ -1786,14 +1786,14 @@ CAdItem *CAdGame::getItemByName(const char *name) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::addItem(CAdItem *item) { +bool AdGame::addItem(AdItem *item) { _items.add(item); return _gameRef->registerObject(item); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::resetContent() { +bool AdGame::resetContent() { // clear pending dialogs for (int i = 0; i < _dlgPendingBranches.getSize(); i++) { delete [] _dlgPendingBranches[i]; @@ -1823,12 +1823,12 @@ bool CAdGame::resetContent() { _tempDisableSaveState = true; - return CBGame::resetContent(); + return BaseGame::resetContent(); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::deleteItem(CAdItem *item) { +bool AdGame::deleteItem(AdItem *item) { if (!item) return STATUS_FAILED; if (_selectedItem == item) _selectedItem = NULL; @@ -1853,7 +1853,7 @@ bool CAdGame::deleteItem(CAdItem *item) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::addSpeechDir(const char *dir) { +bool AdGame::addSpeechDir(const char *dir) { if (!dir || dir[0] == '\0') return STATUS_FAILED; char *temp = new char[strlen(dir) + 2]; @@ -1874,7 +1874,7 @@ bool CAdGame::addSpeechDir(const char *dir) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::removeSpeechDir(const char *dir) { +bool AdGame::removeSpeechDir(const char *dir) { if (!dir || dir[0] == '\0') return STATUS_FAILED; char *temp = new char[strlen(dir) + 2]; @@ -1899,7 +1899,7 @@ bool CAdGame::removeSpeechDir(const char *dir) { ////////////////////////////////////////////////////////////////////////// -char *CAdGame::findSpeechFile(char *stringID) { +char *AdGame::findSpeechFile(char *stringID) { char *ret = new char[MAX_PATH_LENGTH]; for (int i = 0; i < _speechDirs.getSize(); i++) { @@ -1923,15 +1923,15 @@ char *CAdGame::findSpeechFile(char *stringID) { ////////////////////////////////////////////////////////////////////////// -bool CAdGame::validMouse() { +bool AdGame::validMouse() { Point32 pos; - CBPlatform::getCursorPos(&pos); + BasePlatform::getCursorPos(&pos); return _renderer->pointInViewport(&pos); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseLeftDown() { +bool AdGame::onMouseLeftDown() { if (!validMouse()) return STATUS_OK; if (_state == GAME_RUNNING && !_interactive) { if (_talkSkipButton == TALK_SKIP_LEFT || _talkSkipButton == TALK_SKIP_BOTH) { @@ -1953,16 +1953,16 @@ bool CAdGame::onMouseLeftDown() { if (_activeObject != NULL) _gameRef->_capturedObject = _gameRef->_activeObject; _mouseLeftDown = true; - CBPlatform::setCapture(/*_renderer->_window*/); + BasePlatform::setCapture(/*_renderer->_window*/); return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseLeftUp() { +bool AdGame::onMouseLeftUp() { if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); - CBPlatform::releaseCapture(); + BasePlatform::releaseCapture(); _capturedObject = NULL; _mouseLeftDown = false; @@ -1978,7 +1978,7 @@ bool CAdGame::onMouseLeftUp() { } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseLeftDblClick() { +bool AdGame::onMouseLeftDblClick() { if (!validMouse()) return STATUS_OK; if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; @@ -1997,7 +1997,7 @@ bool CAdGame::onMouseLeftDblClick() { } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseRightDown() { +bool AdGame::onMouseRightDown() { if (!validMouse()) return STATUS_OK; if (_state == GAME_RUNNING && !_interactive) { if (_talkSkipButton == TALK_SKIP_RIGHT || _talkSkipButton == TALK_SKIP_BOTH) { @@ -2022,7 +2022,7 @@ bool CAdGame::onMouseRightDown() { } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::onMouseRightUp() { +bool AdGame::onMouseRightUp() { if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); @@ -2037,7 +2037,7 @@ bool CAdGame::onMouseRightUp() { } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::displayDebugInfo() { +bool AdGame::displayDebugInfo() { char str[100]; if (_gameRef->_debugDebugMode) { sprintf(str, "Mouse: %d, %d (scene: %d, %d)", _mousePos.x, _mousePos.y, _mousePos.x + _scene->getOffsetLeft(), _mousePos.y + _scene->getOffsetTop()); @@ -2046,12 +2046,12 @@ bool CAdGame::displayDebugInfo() { sprintf(str, "Scene: %s (prev: %s)", (_scene && _scene->_name) ? _scene->_name : "???", _prevSceneName ? _prevSceneName : "???"); _systemFont->drawText((byte *)str, 0, 110, _renderer->_width, TAL_RIGHT); } - return CBGame::displayDebugInfo(); + return BaseGame::displayDebugInfo(); } ////////////////////////////////////////////////////////////////////////// -bool CAdGame::onScriptShutdown(CScScript *script) { +bool AdGame::onScriptShutdown(ScScript *script) { if (_responseBox && _responseBox->_waitingScript == script) _responseBox->_waitingScript = NULL; diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index 09b3e09df0..b52fd2832f 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -32,19 +32,19 @@ #include "engines/wintermute/base/base_game.h" namespace WinterMute { -class CAdItem; -class CAdInventory; -class CAdSceneState; -class CAdScene; -class CAdItem; -class CAdObject; -class CAdSentence; -class CAdInventoryBox; -class CAdResponseContext; -class CAdResponseBox; -class CAdGame : public CBGame { +class AdItem; +class AdInventory; +class AdSceneState; +class AdScene; +class AdItem; +class AdObject; +class AdSentence; +class AdInventoryBox; +class AdResponseContext; +class AdResponseBox; +class AdGame : public BaseGame { public: - virtual bool onScriptShutdown(CScScript *script); + virtual bool onScriptShutdown(ScScript *script); virtual bool onMouseLeftDown(); virtual bool onMouseLeftUp(); @@ -60,25 +60,25 @@ public: bool _smartItemCursor; - CBArray _speechDirs; + BaseArray _speechDirs; bool addSpeechDir(const char *dir); bool removeSpeechDir(const char *dir); char *findSpeechFile(char *StringID); - bool deleteItem(CAdItem *Item); + bool deleteItem(AdItem *Item); char *_itemsFile; bool _tempDisableSaveState; virtual bool resetContent(); - bool addItem(CAdItem *item); - CAdItem *getItemByName(const char *name); - CBArray _items; - CAdObject *_inventoryOwner; + bool addItem(AdItem *item); + AdItem *getItemByName(const char *name); + BaseArray _items; + AdObject *_inventoryOwner; bool isItemTaken(char *itemName); - bool registerInventory(CAdInventory *inv); - bool unregisterInventory(CAdInventory *inv); + bool registerInventory(AdInventory *inv); + bool unregisterInventory(AdInventory *inv); - CAdObject *_invObject; - CBArray _inventories; + AdObject *_invObject; + BaseArray _inventories; virtual bool displayContent(bool update = true, bool displayAll = false); char *_debugStartupScene; char *_startupScene; @@ -92,11 +92,11 @@ public: bool clearBranchResponses(char *name); bool startDlgBranch(const char *branchName, const char *scriptName, const char *eventName); bool endDlgBranch(const char *branchName, const char *scriptName, const char *eventName); - virtual bool windowLoadHook(CUIWindow *win, char **buf, char **params); - virtual bool windowScriptMethodHook(CUIWindow *win, CScScript *script, CScStack *stack, const char *name); + virtual bool windowLoadHook(UIWindow *win, char **buf, char **params); + virtual bool windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *stack, const char *name); - CAdSceneState *getSceneState(const char *filename, bool saving); - CBViewport *_sceneViewport; + AdSceneState *getSceneState(const char *filename, bool saving); + BaseViewport *_sceneViewport; int _texItemLifeTime; int _texWalkLifeTime; int _texStandLifeTime; @@ -113,32 +113,32 @@ public: char *_prevSceneName; char *_prevSceneFilename; virtual bool loadGame(const char *filename); - CAdItem *_selectedItem; + AdItem *_selectedItem; bool cleanup(); - DECLARE_PERSISTENT(CAdGame, CBGame) + DECLARE_PERSISTENT(AdGame, BaseGame) void finishSentences(); bool showCursor(); TGameStateEx _stateEx; - CAdResponseBox *_responseBox; - CAdInventoryBox *_inventoryBox; + AdResponseBox *_responseBox; + AdInventoryBox *_inventoryBox; bool displaySentences(bool frozen); - void addSentence(CAdSentence *sentence); + void addSentence(AdSentence *sentence); bool changeScene(const char *filename, bool fadeIn); - bool removeObject(CAdObject *object); - bool addObject(CAdObject *object); - CAdScene *_scene; + bool removeObject(AdObject *object); + bool addObject(AdObject *object); + AdScene *_scene; bool initLoop(); - CAdGame(); - virtual ~CAdGame(); - CBArray _objects; - CBArray _sentences; + AdGame(); + virtual ~AdGame(); + BaseArray _objects; + BaseArray _sentences; - CBArray _sceneStates; - CBArray _dlgPendingBranches; + BaseArray _sceneStates; + BaseArray _dlgPendingBranches; - CBArray _responsesBranch; - CBArray _responsesGame; + BaseArray _responsesBranch; + BaseArray _responsesGame; virtual bool loadFile(const char *filename); virtual bool loadBuffer(byte *buffer, bool complete = true); @@ -147,12 +147,12 @@ public: bool loadItemsBuffer(byte *buffer, bool merge = false); - virtual bool ExternalCall(CScScript *script, CScStack *stack, CScStack *thisStack, char *name); + virtual bool ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name); // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); bool validMouse(); }; diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index cfbc9e5029..fd56eef419 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -34,25 +34,25 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdInventory, false) +IMPLEMENT_PERSISTENT(AdInventory, false) ////////////////////////////////////////////////////////////////////////// -CAdInventory::CAdInventory(CBGame *inGame): CBObject(inGame) { +AdInventory::AdInventory(BaseGame *inGame): BaseObject(inGame) { _scrollOffset = 0; } ////////////////////////////////////////////////////////////////////////// -CAdInventory::~CAdInventory() { +AdInventory::~AdInventory() { _takenItems.removeAll(); // ref only } ////////////////////////////////////////////////////////////////////////// -bool CAdInventory::insertItem(const char *name, const char *insertAfter) { +bool AdInventory::insertItem(const char *name, const char *insertAfter) { if (name == NULL) return STATUS_FAILED; - CAdItem *item = ((CAdGame *)_gameRef)->getItemByName(name); + AdItem *item = ((AdGame *)_gameRef)->getItemByName(name); if (item == NULL) return STATUS_FAILED; int insertIndex = -1; @@ -74,12 +74,12 @@ bool CAdInventory::insertItem(const char *name, const char *insertAfter) { ////////////////////////////////////////////////////////////////////////// -bool CAdInventory::removeItem(const char *name) { +bool AdInventory::removeItem(const char *name) { if (name == NULL) return STATUS_FAILED; for (int i = 0; i < _takenItems.getSize(); i++) { if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { - if (((CAdGame *)_gameRef)->_selectedItem == _takenItems[i])((CAdGame *)_gameRef)->_selectedItem = NULL; + if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i])((AdGame *)_gameRef)->_selectedItem = NULL; _takenItems.removeAt(i); return STATUS_OK; } @@ -91,12 +91,12 @@ bool CAdInventory::removeItem(const char *name) { ////////////////////////////////////////////////////////////////////////// -bool CAdInventory::removeItem(CAdItem *item) { +bool AdInventory::removeItem(AdItem *item) { if (item == NULL) return STATUS_FAILED; for (int i = 0; i < _takenItems.getSize(); i++) { if (_takenItems[i] == item) { - if (((CAdGame *)_gameRef)->_selectedItem == _takenItems[i])((CAdGame *)_gameRef)->_selectedItem = NULL; + if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i])((AdGame *)_gameRef)->_selectedItem = NULL; _takenItems.removeAt(i); return STATUS_OK; } @@ -106,9 +106,9 @@ bool CAdInventory::removeItem(CAdItem *item) { } ////////////////////////////////////////////////////////////////////////// -bool CAdInventory::persist(CBPersistMgr *persistMgr) { +bool AdInventory::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); _takenItems.persist(persistMgr); persistMgr->transfer(TMEMBER(_scrollOffset)); diff --git a/engines/wintermute/ad/ad_inventory.h b/engines/wintermute/ad/ad_inventory.h index 84d9308d5d..6f7537633d 100644 --- a/engines/wintermute/ad/ad_inventory.h +++ b/engines/wintermute/ad/ad_inventory.h @@ -33,17 +33,17 @@ namespace WinterMute { -class CAdItem; +class AdItem; -class CAdInventory : public CBObject { +class AdInventory : public BaseObject { public: - DECLARE_PERSISTENT(CAdInventory, CBObject) + DECLARE_PERSISTENT(AdInventory, BaseObject) bool removeItem(const char *name); - bool removeItem(CAdItem *Item); + bool removeItem(AdItem *Item); bool insertItem(const char *name, const char *insertAfter = NULL); - CAdInventory(CBGame *inGame); - virtual ~CAdInventory(); - CBArray _takenItems; + AdInventory(BaseGame *inGame); + virtual ~AdInventory(); + BaseArray _takenItems; int _scrollOffset; }; diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index abe8676376..f835dd22d4 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -43,10 +43,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdInventoryBox, false) +IMPLEMENT_PERSISTENT(AdInventoryBox, false) ////////////////////////////////////////////////////////////////////////// -CAdInventoryBox::CAdInventoryBox(CBGame *inGame): CBObject(inGame) { +AdInventoryBox::AdInventoryBox(BaseGame *inGame): BaseObject(inGame) { _itemsArea.setEmpty(); _scrollOffset = 0; _spacing = 0; @@ -64,7 +64,7 @@ CAdInventoryBox::CAdInventoryBox(CBGame *inGame): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdInventoryBox::~CAdInventoryBox() { +AdInventoryBox::~AdInventoryBox() { _gameRef->unregisterObject(_window); _window = NULL; @@ -74,8 +74,8 @@ CAdInventoryBox::~CAdInventoryBox() { ////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::listen(CBScriptHolder *param1, uint32 param2) { - CUIObject *obj = (CUIObject *)param1; +bool AdInventoryBox::listen(BaseScriptHolder *param1, uint32 param2) { + UIObject *obj = (UIObject *)param1; switch (obj->_type) { case UI_BUTTON: @@ -86,10 +86,10 @@ bool CAdInventoryBox::listen(CBScriptHolder *param1, uint32 param2) { _scrollOffset = MAX(_scrollOffset, 0); } else if (scumm_stricmp(obj->_name, "next") == 0) { _scrollOffset += _scrollBy; - } else return CBObject::listen(param1, param2); + } else return BaseObject::listen(param1, param2); break; default: - error("CAdInventoryBox::Listen - Unhandled enum"); + error("AdInventoryBox::Listen - Unhandled enum"); break; } @@ -98,8 +98,8 @@ bool CAdInventoryBox::listen(CBScriptHolder *param1, uint32 param2) { ////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::display() { - CAdGame *adGame = (CAdGame *)_gameRef; +bool AdInventoryBox::display() { + AdGame *adGame = (AdGame *)_gameRef; if (!_visible) return STATUS_OK; @@ -137,8 +137,8 @@ bool CAdInventoryBox::display() { for (int i = 0; i < itemsX; i++) { int itemIndex = _scrollOffset + j * itemsX + i; if (itemIndex >= 0 && itemIndex < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()) { - CAdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex]; - if (item != ((CAdGame *)_gameRef)->_selectedItem || !_hideSelected) { + AdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex]; + if (item != ((AdGame *)_gameRef)->_selectedItem || !_hideSelected) { item->update(); item->display(xxx, yyy); } @@ -155,10 +155,10 @@ bool CAdInventoryBox::display() { ////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::loadFile(const char *filename) { +bool AdInventoryBox::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdInventoryBox::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdInventoryBox::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -193,7 +193,7 @@ TOKEN_DEF(HIDE_SELECTED) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::loadBuffer(byte *buffer, bool complete) { +bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(INVENTORY_BOX) TOKEN_TABLE(TEMPLATE) @@ -213,7 +213,7 @@ bool CAdInventoryBox::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd = 2; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); bool always_visible = false; _exclusive = false; @@ -241,7 +241,7 @@ bool CAdInventoryBox::loadBuffer(byte *buffer, bool complete) { case TOKEN_WINDOW: delete _window; - _window = new CUIWindow(_gameRef); + _window = new UIWindow(_gameRef); if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { delete _window; _window = NULL; @@ -297,7 +297,7 @@ bool CAdInventoryBox::loadBuffer(byte *buffer, bool complete) { if (_exclusive) { delete _closeButton; - _closeButton = new CUIButton(_gameRef); + _closeButton = new UIButton(_gameRef); if (_closeButton) { _closeButton->setName("close"); _closeButton->setListener(this, _closeButton, 0); @@ -318,7 +318,7 @@ bool CAdInventoryBox::loadBuffer(byte *buffer, bool complete) { } ////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdInventoryBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "INVENTORY_BOX\n"); buffer->putTextIndent(indent, "{\n"); @@ -343,7 +343,7 @@ bool CAdInventoryBox::saveAsText(CBDynBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); // editor properties - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n"); return STATUS_OK; @@ -351,8 +351,8 @@ bool CAdInventoryBox::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdInventoryBox::persist(CBPersistMgr *persistMgr) { - CBObject::persist(persistMgr); +bool AdInventoryBox::persist(BasePersistenceManager *persistMgr) { + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_closeButton)); persistMgr->transfer(TMEMBER(_hideSelected)); diff --git a/engines/wintermute/ad/ad_inventory_box.h b/engines/wintermute/ad/ad_inventory_box.h index 09d3ef409e..dfbf62be9a 100644 --- a/engines/wintermute/ad/ad_inventory_box.h +++ b/engines/wintermute/ad/ad_inventory_box.h @@ -33,30 +33,30 @@ #include "common/rect.h" namespace WinterMute { -class CUIButton; -class CUIWindow; +class UIButton; +class UIWindow; -class CAdInventoryBox : public CBObject { +class AdInventoryBox : public BaseObject { public: bool _hideSelected; - DECLARE_PERSISTENT(CAdInventoryBox, CBObject) + DECLARE_PERSISTENT(AdInventoryBox, BaseObject) bool _exclusive; int _scrollBy; int _itemHeight; int _itemWidth; bool _visible; virtual bool display(); - CUIButton *_closeButton; + UIButton *_closeButton; int _spacing; int _scrollOffset; Rect32 _itemsArea; - bool listen(CBScriptHolder *param1, uint32 param2); - CUIWindow *_window; - CAdInventoryBox(CBGame *inGame); - virtual ~CAdInventoryBox(); + bool listen(BaseScriptHolder *param1, uint32 param2); + UIWindow *_window; + AdInventoryBox(BaseGame *inGame); + virtual ~AdInventoryBox(); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index 9c49a86bcb..781b924513 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -46,10 +46,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdItem, false) +IMPLEMENT_PERSISTENT(AdItem, false) ////////////////////////////////////////////////////////////////////////// -CAdItem::CAdItem(CBGame *inGame): CAdTalkHolder(inGame) { +AdItem::AdItem(BaseGame *inGame): AdTalkHolder(inGame) { _spriteHover = NULL; _cursorNormal = _cursorHover = NULL; @@ -70,7 +70,7 @@ CAdItem::CAdItem(CBGame *inGame): CAdTalkHolder(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdItem::~CAdItem() { +AdItem::~AdItem() { delete _spriteHover; delete _cursorNormal; delete _cursorHover; @@ -84,10 +84,10 @@ CAdItem::~CAdItem() { ////////////////////////////////////////////////////////////////////////// -bool CAdItem::loadFile(const char *filename) { +bool AdItem::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdItem::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdItem::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -134,7 +134,7 @@ TOKEN_DEF(AMOUNT_STRING) TOKEN_DEF(AMOUNT) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdItem::loadBuffer(byte *buffer, bool complete) { +bool AdItem::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ITEM) TOKEN_TABLE(TEMPLATE) @@ -166,7 +166,7 @@ bool CAdItem::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd = 2; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ITEM) { @@ -198,8 +198,8 @@ bool CAdItem::loadBuffer(byte *buffer, bool complete) { case TOKEN_IMAGE: case TOKEN_SPRITE: delete _sprite; - _sprite = new CBSprite(_gameRef, this); - if (!_sprite || DID_FAIL(_sprite->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + _sprite = new BaseSprite(_gameRef, this); + if (!_sprite || DID_FAIL(_sprite->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { delete _sprite; cmd = PARSERR_GENERIC; } @@ -208,8 +208,8 @@ bool CAdItem::loadBuffer(byte *buffer, bool complete) { case TOKEN_IMAGE_HOVER: case TOKEN_SPRITE_HOVER: delete _spriteHover; - _spriteHover = new CBSprite(_gameRef, this); - if (!_spriteHover || DID_FAIL(_spriteHover->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + _spriteHover = new BaseSprite(_gameRef, this); + if (!_spriteHover || DID_FAIL(_spriteHover->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { delete _spriteHover; cmd = PARSERR_GENERIC; } @@ -238,27 +238,27 @@ bool CAdItem::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_AMOUNT_STRING: - CBUtils::setString(&_amountString, (char *)params); + BaseUtils::setString(&_amountString, (char *)params); break; case TOKEN_TALK: { - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((CAdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; else _talkSprites.add(spr); } break; case TOKEN_TALK_SPECIAL: { - CBSprite *spr = new CBSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((CAdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; else _talkSpritesEx.add(spr); } break; case TOKEN_CURSOR: delete _cursorNormal; - _cursorNormal = new CBSprite(_gameRef); - if (!_cursorNormal || DID_FAIL(_cursorNormal->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + _cursorNormal = new BaseSprite(_gameRef); + if (!_cursorNormal || DID_FAIL(_cursorNormal->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { delete _cursorNormal; _cursorNormal = NULL; cmd = PARSERR_GENERIC; @@ -267,8 +267,8 @@ bool CAdItem::loadBuffer(byte *buffer, bool complete) { case TOKEN_CURSOR_HOVER: delete _cursorHover; - _cursorHover = new CBSprite(_gameRef); - if (!_cursorHover || DID_FAIL(_cursorHover->loadFile((char *)params, ((CAdGame *)_gameRef)->_texItemLifeTime))) { + _cursorHover = new BaseSprite(_gameRef); + if (!_cursorHover || DID_FAIL(_cursorHover->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { delete _cursorHover; _cursorHover = NULL; cmd = PARSERR_GENERIC; @@ -319,7 +319,7 @@ bool CAdItem::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// -bool CAdItem::update() { +bool AdItem::update() { _currentSprite = NULL; if (_state == STATE_READY && _animSprite) { @@ -369,11 +369,11 @@ bool CAdItem::update() { _tempSprite2->reset(); _currentSprite = _tempSprite2; } - ((CAdGame *)_gameRef)->addSentence(_sentence); + ((AdGame *)_gameRef)->addSentence(_sentence); } } else { _currentSprite = _tempSprite2; - ((CAdGame *)_gameRef)->addSentence(_sentence); + ((AdGame *)_gameRef)->addSentence(_sentence); } } default: @@ -386,7 +386,7 @@ bool CAdItem::update() { ////////////////////////////////////////////////////////////////////////// -bool CAdItem::display(int x, int y) { +bool AdItem::display(int x, int y) { int width = 0; if (_currentSprite) { Rect32 rc; @@ -412,7 +412,7 @@ bool CAdItem::display(int x, int y) { } amountX += _amountOffsetX; - CBFont *font = _font ? _font : _gameRef->_systemFont; + BaseFont *font = _font ? _font : _gameRef->_systemFont; if (font) { if (_amountString) font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); else { @@ -430,7 +430,7 @@ bool CAdItem::display(int x, int y) { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdItem::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // SetHoverSprite ////////////////////////////////////////////////////////////////////////// @@ -444,7 +444,7 @@ bool CAdItem::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta delete _spriteHover; _spriteHover = NULL; - CBSprite *spr = new CBSprite(_gameRef, this); + BaseSprite *spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile(filename))) { stack->pushBool(false); script->runtimeError("Item.SetHoverSprite failed for file '%s'", filename); @@ -487,7 +487,7 @@ bool CAdItem::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta delete _cursorNormal; _cursorNormal = NULL; - CBSprite *spr = new CBSprite(_gameRef); + BaseSprite *spr = new BaseSprite(_gameRef); if (!spr || DID_FAIL(spr->loadFile(filename))) { stack->pushBool(false); script->runtimeError("Item.SetNormalCursor failed for file '%s'", filename); @@ -530,7 +530,7 @@ bool CAdItem::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta delete _cursorHover; _cursorHover = NULL; - CBSprite *spr = new CBSprite(_gameRef); + BaseSprite *spr = new BaseSprite(_gameRef); if (!spr || DID_FAIL(spr->loadFile(filename))) { stack->pushBool(false); script->runtimeError("Item.SetHoverCursor failed for file '%s'", filename); @@ -563,12 +563,12 @@ bool CAdItem::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSta return STATUS_OK; } - else return CAdTalkHolder::scCallMethod(script, stack, thisStack, name); + else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdItem::scGetProperty(const char *name) { +ScValue *AdItem::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -644,12 +644,12 @@ CScValue *CAdItem::scGetProperty(const char *name) { return _scValue; } - else return CAdTalkHolder::scGetProperty(name); + else return AdTalkHolder::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdItem::scSetProperty(const char *name, CScValue *value) { +bool AdItem::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Name ////////////////////////////////////////////////////////////////////////// @@ -706,7 +706,7 @@ bool CAdItem::scSetProperty(const char *name, CScValue *value) { delete[] _amountString; _amountString = NULL; } else { - CBUtils::setString(&_amountString, value->getString()); + BaseUtils::setString(&_amountString, value->getString()); } return STATUS_OK; } @@ -719,20 +719,20 @@ bool CAdItem::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else return CAdTalkHolder::scSetProperty(name, value); + else return AdTalkHolder::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -const char *CAdItem::scToString() { +const char *AdItem::scToString() { return "[item]"; } ////////////////////////////////////////////////////////////////////////// -bool CAdItem::persist(CBPersistMgr *persistMgr) { +bool AdItem::persist(BasePersistenceManager *persistMgr) { - CAdTalkHolder::persist(persistMgr); + AdTalkHolder::persist(persistMgr); persistMgr->transfer(TMEMBER(_cursorCombined)); persistMgr->transfer(TMEMBER(_cursorHover)); @@ -751,10 +751,10 @@ bool CAdItem::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -bool CAdItem::getExtendedFlag(const char *flagName) { +bool AdItem::getExtendedFlag(const char *flagName) { if (!flagName) return false; else if (strcmp(flagName, "usable") == 0) return true; - else return CAdObject::getExtendedFlag(flagName); + else return AdObject::getExtendedFlag(flagName); } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_item.h b/engines/wintermute/ad/ad_item.h index 34b19a830f..11010c2a35 100644 --- a/engines/wintermute/ad/ad_item.h +++ b/engines/wintermute/ad/ad_item.h @@ -34,7 +34,7 @@ namespace WinterMute { -class CAdItem : public CAdTalkHolder { +class AdItem : public AdTalkHolder { public: bool _displayAmount; int _amount; @@ -45,23 +45,23 @@ public: bool update(); - DECLARE_PERSISTENT(CAdItem, CAdTalkHolder) + DECLARE_PERSISTENT(AdItem, AdTalkHolder) bool display(int x, int y); bool getExtendedFlag(const char *flagName); bool _inInventory; bool _cursorCombined; - CBSprite *_spriteHover; - CBSprite *_cursorNormal; - CBSprite *_cursorHover; - CAdItem(CBGame *inGame); - virtual ~CAdItem(); + BaseSprite *_spriteHover; + BaseSprite *_cursorNormal; + BaseSprite *_cursorHover; + AdItem(BaseGame *inGame); + virtual ~AdItem(); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); }; diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index e23948ed87..2cd7ac26ce 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -41,10 +41,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdLayer, false) +IMPLEMENT_PERSISTENT(AdLayer, false) ////////////////////////////////////////////////////////////////////////// -CAdLayer::CAdLayer(CBGame *inGame): CBObject(inGame) { +AdLayer::AdLayer(BaseGame *inGame): BaseObject(inGame) { _main = false; _width = _height = 0; _active = true; @@ -53,7 +53,7 @@ CAdLayer::CAdLayer(CBGame *inGame): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdLayer::~CAdLayer() { +AdLayer::~AdLayer() { for (int i = 0; i < _nodes.getSize(); i++) delete _nodes[i]; _nodes.removeAll(); @@ -61,10 +61,10 @@ CAdLayer::~CAdLayer() { ////////////////////////////////////////////////////////////////////////// -bool CAdLayer::loadFile(const char *filename) { +bool AdLayer::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdLayer::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdLayer::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -99,7 +99,7 @@ TOKEN_DEF(CLOSE_UP) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdLayer::loadBuffer(byte *buffer, bool complete) { +bool AdLayer::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(LAYER) TOKEN_TABLE(TEMPLATE) @@ -120,7 +120,7 @@ bool CAdLayer::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_LAYER) { @@ -165,8 +165,8 @@ bool CAdLayer::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_REGION: { - CAdRegion *region = new CAdRegion(_gameRef); - CAdSceneNode *node = new CAdSceneNode(_gameRef); + AdRegion *region = new AdRegion(_gameRef); + AdSceneNode *node = new AdSceneNode(_gameRef); if (!region || !node || DID_FAIL(region->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; delete region; @@ -181,8 +181,8 @@ bool CAdLayer::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ENTITY: { - CAdEntity *entity = new CAdEntity(_gameRef); - CAdSceneNode *node = new CAdSceneNode(_gameRef); + AdEntity *entity = new AdEntity(_gameRef); + AdSceneNode *node = new AdSceneNode(_gameRef); if (entity) entity->_zoomable = false; // scene entites default to NOT zoom if (!entity || !node || DID_FAIL(entity->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; @@ -226,13 +226,13 @@ bool CAdLayer::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdLayer::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // GetNode ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "GetNode") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); int node = -1; if (val->_type == VAL_INT) node = val->getInt(); @@ -267,16 +267,16 @@ bool CAdLayer::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "AddRegion") == 0 || strcmp(name, "AddEntity") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdSceneNode *node = new CAdSceneNode(_gameRef); + AdSceneNode *node = new AdSceneNode(_gameRef); if (strcmp(name, "AddRegion") == 0) { - CAdRegion *region = new CAdRegion(_gameRef); + AdRegion *region = new AdRegion(_gameRef); if (!val->isNULL()) region->setName(val->getString()); node->setRegion(region); stack->pushNative(region, true); } else { - CAdEntity *entity = new CAdEntity(_gameRef); + AdEntity *entity = new AdEntity(_gameRef); if (!val->isNULL()) entity->setName(val->getString()); node->setEntity(entity); stack->pushNative(entity, true); @@ -291,16 +291,16 @@ bool CAdLayer::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt else if (strcmp(name, "InsertRegion") == 0 || strcmp(name, "InsertEntity") == 0) { stack->correctParams(2); int index = stack->pop()->getInt(); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdSceneNode *node = new CAdSceneNode(_gameRef); + AdSceneNode *node = new AdSceneNode(_gameRef); if (strcmp(name, "InsertRegion") == 0) { - CAdRegion *region = new CAdRegion(_gameRef); + AdRegion *region = new AdRegion(_gameRef); if (!val->isNULL()) region->setName(val->getString()); node->setRegion(region); stack->pushNative(region, true); } else { - CAdEntity *entity = new CAdEntity(_gameRef); + AdEntity *entity = new AdEntity(_gameRef); if (!val->isNULL()) entity->setName(val->getString()); node->setEntity(entity); stack->pushNative(entity, true); @@ -317,11 +317,11 @@ bool CAdLayer::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "DeleteNode") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdSceneNode *toDelete = NULL; + AdSceneNode *toDelete = NULL; if (val->isNative()) { - CBScriptable *temp = val->getNative(); + BaseScriptable *temp = val->getNative(); for (int i = 0; i < _nodes.getSize(); i++) { if (_nodes[i]->_region == temp || _nodes[i]->_entity == temp) { toDelete = _nodes[i]; @@ -351,12 +351,12 @@ bool CAdLayer::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt return STATUS_OK; } - else return CBObject::scCallMethod(script, stack, thisStack, name); + else return BaseObject::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdLayer::scGetProperty(const char *name) { +ScValue *AdLayer::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -415,12 +415,12 @@ CScValue *CAdLayer::scGetProperty(const char *name) { return _scValue; } - else return CBObject::scGetProperty(name); + else return BaseObject::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdLayer::scSetProperty(const char *name, CScValue *value) { +bool AdLayer::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Name ////////////////////////////////////////////////////////////////////////// @@ -466,18 +466,18 @@ bool CAdLayer::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else return CBObject::scSetProperty(name, value); + else return BaseObject::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -const char *CAdLayer::scToString() { +const char *AdLayer::scToString() { return "[layer]"; } ////////////////////////////////////////////////////////////////////////// -bool CAdLayer::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "LAYER {\n"); buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); @@ -506,12 +506,12 @@ bool CAdLayer::saveAsText(CBDynBuffer *buffer, int indent) { _nodes[i]->_region->saveAsText(buffer, indent + 2); break; default: - error("CAdLayer::SaveAsText - Unhandled enum"); + error("AdLayer::SaveAsText - Unhandled enum"); break; } } - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n\n"); @@ -520,9 +520,9 @@ bool CAdLayer::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdLayer::persist(CBPersistMgr *persistMgr) { +bool AdLayer::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_active)); persistMgr->transfer(TMEMBER(_closeUp)); diff --git a/engines/wintermute/ad/ad_layer.h b/engines/wintermute/ad/ad_layer.h index 0ccdb13ae7..b76cbf1d99 100644 --- a/engines/wintermute/ad/ad_layer.h +++ b/engines/wintermute/ad/ad_layer.h @@ -30,26 +30,26 @@ #define WINTERMUTE_ADLAYER_H namespace WinterMute { -class CAdSceneNode; -class CAdLayer : public CBObject { +class AdSceneNode; +class AdLayer : public BaseObject { public: bool _closeUp; - DECLARE_PERSISTENT(CAdLayer, CBObject) + DECLARE_PERSISTENT(AdLayer, BaseObject) bool _active; int _height; int _width; bool _main; - CAdLayer(CBGame *inGame); - virtual ~CAdLayer(); - CBArray _nodes; + AdLayer(BaseGame *inGame); + virtual ~AdLayer(); + BaseArray _nodes; bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); }; diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index 06f9c4cf95..12bd275614 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -38,11 +38,11 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdNodeState, false) +IMPLEMENT_PERSISTENT(AdNodeState, false) ////////////////////////////////////////////////////////////////////////// -CAdNodeState::CAdNodeState(CBGame *inGame): CBBase(inGame) { +AdNodeState::AdNodeState(BaseGame *inGame): BaseClass(inGame) { _name = NULL; _active = false; for (int i = 0; i < 7; i++) _caption[i] = NULL; @@ -53,7 +53,7 @@ CAdNodeState::CAdNodeState(CBGame *inGame): CBBase(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdNodeState::~CAdNodeState() { +AdNodeState::~AdNodeState() { delete[] _name; delete[] _filename; delete[] _cursor; @@ -68,31 +68,31 @@ CAdNodeState::~CAdNodeState() { ////////////////////////////////////////////////////////////////////////// -void CAdNodeState::setName(const char *name) { +void AdNodeState::setName(const char *name) { delete[] _name; _name = NULL; - CBUtils::setString(&_name, name); + BaseUtils::setString(&_name, name); } ////////////////////////////////////////////////////////////////////////// -void CAdNodeState::setFilename(const char *filename) { +void AdNodeState::setFilename(const char *filename) { delete[] _filename; _filename = NULL; - CBUtils::setString(&_filename, filename); + BaseUtils::setString(&_filename, filename); } ////////////////////////////////////////////////////////////////////////// -void CAdNodeState::setCursor(const char *filename) { +void AdNodeState::setCursor(const char *filename) { delete[] _cursor; _cursor = NULL; - CBUtils::setString(&_cursor, filename); + BaseUtils::setString(&_cursor, filename); } ////////////////////////////////////////////////////////////////////////// -bool CAdNodeState::persist(CBPersistMgr *persistMgr) { +bool AdNodeState::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_gameRef)); persistMgr->transfer(TMEMBER(_active)); @@ -107,7 +107,7 @@ bool CAdNodeState::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -void CAdNodeState::setCaption(const char *caption, int caseVal) { +void AdNodeState::setCaption(const char *caption, int caseVal) { if (caseVal== 0) caseVal= 1; if (caseVal< 1 || caseVal> 7) return; @@ -121,7 +121,7 @@ void CAdNodeState::setCaption(const char *caption, int caseVal) { ////////////////////////////////////////////////////////////////////////// -char *CAdNodeState::getCaption(int caseVal) { +char *AdNodeState::getCaption(int caseVal) { if (caseVal== 0) caseVal= 1; if (caseVal< 1 || caseVal> 7 || _caption[caseVal- 1] == NULL) return ""; else return _caption[caseVal- 1]; @@ -129,7 +129,7 @@ char *CAdNodeState::getCaption(int caseVal) { ////////////////////////////////////////////////////////////////////////// -bool CAdNodeState::transferEntity(CAdEntity *entity, bool includingSprites, bool saving) { +bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool saving) { if (!entity) return STATUS_FAILED; // hack! diff --git a/engines/wintermute/ad/ad_node_state.h b/engines/wintermute/ad/ad_node_state.h index 186f2ebbb2..fc7692a1bf 100644 --- a/engines/wintermute/ad/ad_node_state.h +++ b/engines/wintermute/ad/ad_node_state.h @@ -31,17 +31,17 @@ namespace WinterMute { -class CAdEntity; +class AdEntity; -class CAdNodeState : public CBBase { +class AdNodeState : public BaseClass { public: - bool transferEntity(CAdEntity *entity, bool includingSprites, bool saving); + bool transferEntity(AdEntity *entity, bool includingSprites, bool saving); void setName(const char *name); void setFilename(const char *filename); void setCursor(const char *filename); - DECLARE_PERSISTENT(CAdNodeState, CBBase) - CAdNodeState(CBGame *inGame); - virtual ~CAdNodeState(); + DECLARE_PERSISTENT(AdNodeState, BaseClass) + AdNodeState(BaseGame *inGame); + virtual ~AdNodeState(); char *_name; bool _active; char *_caption[7]; diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index 46f2e590fd..39593c482c 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -54,10 +54,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdObject, false) +IMPLEMENT_PERSISTENT(AdObject, false) ////////////////////////////////////////////////////////////////////////// -CAdObject::CAdObject(CBGame *inGame): CBObject(inGame) { +AdObject::AdObject(BaseGame *inGame): BaseObject(inGame) { _type = OBJECT_NONE; _state = _nextState = STATE_NONE; @@ -105,7 +105,7 @@ CAdObject::CAdObject(CBGame *inGame): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdObject::~CAdObject() { +AdObject::~AdObject() { _currentSprite = NULL; // reference only, don't delete delete _animSprite; _animSprite = NULL; @@ -130,7 +130,7 @@ CAdObject::~CAdObject() { if (_font) _gameRef->_fontStorage->removeFont(_font); if (_inventory) { - ((CAdGame *)_gameRef)->unregisterInventory(_inventory); + ((AdGame *)_gameRef)->unregisterInventory(_inventory); _inventory = NULL; } @@ -151,17 +151,17 @@ CAdObject::~CAdObject() { ////////////////////////////////////////////////////////////////////////// -bool CAdObject::playAnim(const char *filename) { +bool AdObject::playAnim(const char *filename) { delete _animSprite; _animSprite = NULL; - _animSprite = new CBSprite(_gameRef, this); + _animSprite = new BaseSprite(_gameRef, this); if (!_animSprite) { - _gameRef->LOG(0, "CAdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); + _gameRef->LOG(0, "AdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); return STATUS_FAILED; } bool res = _animSprite->loadFile(filename); if (DID_FAIL(res)) { - _gameRef->LOG(res, "CAdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); + _gameRef->LOG(res, "AdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); delete _animSprite; _animSprite = NULL; return res; @@ -173,13 +173,13 @@ bool CAdObject::playAnim(const char *filename) { ////////////////////////////////////////////////////////////////////////// -bool CAdObject::display() { +bool AdObject::display() { return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::update() { +bool AdObject::update() { return STATUS_OK; } @@ -187,7 +187,7 @@ bool CAdObject::update() { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // PlayAnim / PlayAnimAsync @@ -257,14 +257,14 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS stack->correctParams(5); const char *text = stack->pop()->getString(); - CScValue *soundVal = stack->pop(); + ScValue *soundVal = stack->pop(); int duration = stack->pop()->getInt(); - CScValue *valStances = stack->pop(); + ScValue *valStances = stack->pop(); const char *stances = valStances->isNULL() ? NULL : valStances->getString(); int align = 0; - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (val->isNULL()) align = TAL_CENTER; else align = val->getInt(); @@ -285,11 +285,11 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS else if (strcmp(name, "StickToRegion") == 0) { stack->correctParams(1); - CAdLayer *main = ((CAdGame *)_gameRef)->_scene->_mainLayer; + AdLayer *main = ((AdGame *)_gameRef)->_scene->_mainLayer; bool regFound = false; int i; - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (val->isNULL() || !main) { _stickRegion = NULL; regFound = true; @@ -303,7 +303,7 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS } } } else if (val->isNative()) { - CBScriptable *obj = val->getNative(); + BaseScriptable *obj = val->getNative(); for (i = 0; i < main->_nodes.getSize(); i++) { if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region == obj) { @@ -325,7 +325,7 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetFont") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (val->isNULL()) SetFont(NULL); else SetFont(val->getString()); @@ -351,11 +351,11 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS stack->correctParams(2); if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); } - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (!val->isNULL()) { const char *itemName = val->getString(); val = stack->pop(); @@ -363,7 +363,7 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) script->runtimeError("Cannot add item '%s' to inventory", itemName); else { // hide associated entities - ((CAdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); + ((AdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); } } else script->runtimeError("TakeItem: item name expected"); @@ -379,16 +379,16 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS stack->correctParams(1); if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); } - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (!val->isNULL()) { if (DID_FAIL(_inventory->removeItem(val->getString()))) script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); else { // show associated entities - ((CAdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); + ((AdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); } } else script->runtimeError("DropItem: item name expected"); @@ -403,13 +403,13 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS stack->correctParams(1); if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); } - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (val->_type == VAL_STRING) { - CAdItem *item = ((CAdGame *)_gameRef)->getItemByName(val->getString()); + AdItem *item = ((AdGame *)_gameRef)->getItemByName(val->getString()); if (item) stack->pushNative(item, true); else stack->pushNULL(); } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) @@ -427,11 +427,11 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS stack->correctParams(1); if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); } - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (!val->isNULL()) { for (int i = 0; i < _inventory->_takenItems.getSize(); i++) { if (val->getNative() == _inventory->_takenItems[i]) { @@ -457,7 +457,7 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS int offsetX = stack->pop()->getInt(); int offsetY = stack->pop()->getInt(); - CPartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); + PartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); if (emitter) stack->pushNative(_partEmitter, true); else stack->pushNULL(); @@ -489,7 +489,7 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS int offsetY = stack->pop()->getInt(); bool res; - CAdEntity *ent = new CAdEntity(_gameRef); + AdEntity *ent = new AdEntity(_gameRef); if (DID_FAIL(res = ent->loadFile(filename))) { delete ent; ent = NULL; @@ -516,10 +516,10 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "RemoveAttachment") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); bool found = false; if (val->isNative()) { - CBScriptable *obj = val->getNative(); + BaseScriptable *obj = val->getNative(); for (int i = 0; i < _attachmentsPre.getSize(); i++) { if (_attachmentsPre[i] == obj) { found = true; @@ -565,9 +565,9 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetAttachment") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdObject *ret = NULL; + AdObject *ret = NULL; if (val->isInt()) { int index = val->getInt(); int currIndex = 0; @@ -603,12 +603,12 @@ bool CAdObject::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS return STATUS_OK; } - else return CBObject::scCallMethod(script, stack, thisStack, name); + else return BaseObject::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdObject::scGetProperty(const char *name) { +ScValue *AdObject::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -710,12 +710,12 @@ CScValue *CAdObject::scGetProperty(const char *name) { } - else return CBObject::scGetProperty(name); + else return BaseObject::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::scSetProperty(const char *name, CScValue *value) { +bool AdObject::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Active @@ -781,18 +781,18 @@ bool CAdObject::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else return CBObject::scSetProperty(name, value); + else return BaseObject::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -const char *CAdObject::scToString() { +const char *AdObject::scToString() { return "[ad object]"; } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::SetFont(const char *filename) { +bool AdObject::SetFont(const char *filename) { if (_font) _gameRef->_fontStorage->removeFont(_font); if (filename) { _font = _gameRef->_fontStorage->addFont(filename); @@ -805,17 +805,17 @@ bool CAdObject::SetFont(const char *filename) { ////////////////////////////////////////////////////////////////////////// -int CAdObject::getHeight() { +int AdObject::getHeight() { if (!_currentSprite) return 0; else { - CBFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; + BaseFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; int ret = 0; for (int i = 0; i < frame->_subframes.getSize(); i++) { ret = MAX(ret, frame->_subframes[i]->_hotspotY); } if (_zoomable) { - float zoom = ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY); + float zoom = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY); ret = (int)(ret * zoom / 100); } return ret; @@ -824,8 +824,8 @@ int CAdObject::getHeight() { ////////////////////////////////////////////////////////////////////////// -void CAdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { - if (!_sentence) _sentence = new CAdSentence(_gameRef); +void AdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { + if (!_sentence) _sentence = new AdSentence(_gameRef); if (!_sentence) return; if (_forcedTalkAnimName && _forcedTalkAnimUsed) { @@ -852,7 +852,7 @@ void CAdObject::talk(const char *text, const char *sound, uint32 duration, const if (!sound) { char *key = _gameRef->_stringTable->getKey(text); if (key) { - sound = ((CAdGame *)_gameRef)->findSpeechFile(key); + sound = ((AdGame *)_gameRef)->findSpeechFile(key); delete [] key; if (sound) deleteSound = true; @@ -861,7 +861,7 @@ void CAdObject::talk(const char *text, const char *sound, uint32 duration, const // load sound and set duration appropriately if (sound) { - CBSound *snd = new CBSound(_gameRef); + BaseSound *snd = new BaseSound(_gameRef); if (snd && DID_SUCCEED(snd->setSound(sound, Audio::Mixer::kSpeechSoundType, true))) { _sentence->setSound(snd); if (_sentence->_duration <= 0) { @@ -883,8 +883,8 @@ void CAdObject::talk(const char *text, const char *sound, uint32 duration, const y = _posY; if (!_sceneIndependent && _subtitlesModRelative) { - x -= ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); - y -= ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + x -= ((AdGame *)_gameRef)->_scene->getOffsetLeft(); + y -= ((AdGame *)_gameRef)->_scene->getOffsetTop(); } @@ -920,8 +920,8 @@ void CAdObject::talk(const char *text, const char *sound, uint32 duration, const if (_subtitlesModRelative) { - _sentence->_pos.x += ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); - _sentence->_pos.y += ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + _sentence->_pos.x += ((AdGame *)_gameRef)->_scene->getOffsetLeft(); + _sentence->_pos.y += ((AdGame *)_gameRef)->_scene->getOffsetTop(); } _sentence->_fixedPos = !_subtitlesModRelative; @@ -936,7 +936,7 @@ void CAdObject::talk(const char *text, const char *sound, uint32 duration, const ////////////////////////////////////////////////////////////////////////// -bool CAdObject::reset() { +bool AdObject::reset() { if (_state == STATE_PLAYING_ANIM && _animSprite != NULL) { delete _animSprite; _animSprite = NULL; @@ -953,8 +953,8 @@ bool CAdObject::reset() { ////////////////////////////////////////////////////////////////////////// -bool CAdObject::persist(CBPersistMgr *persistMgr) { - CBObject::persist(persistMgr); +bool AdObject::persist(BasePersistenceManager *persistMgr) { + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_active)); persistMgr->transfer(TMEMBER(_blockRegion)); @@ -998,46 +998,46 @@ bool CAdObject::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -bool CAdObject::updateSounds() { +bool AdObject::updateSounds() { if (_sentence && _sentence->_sound) updateOneSound(_sentence->_sound); - return CBObject::updateSounds(); + return BaseObject::updateSounds(); } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::resetSoundPan() { +bool AdObject::resetSoundPan() { if (_sentence && _sentence->_sound) { _sentence->_sound->setPan(0.0f); } - return CBObject::resetSoundPan(); + return BaseObject::resetSoundPan(); } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::getExtendedFlag(const char *flagName) { +bool AdObject::getExtendedFlag(const char *flagName) { if (!flagName) return false; else if (strcmp(flagName, "usable") == 0) return true; - else return CBObject::getExtendedFlag(flagName); + else return BaseObject::getExtendedFlag(flagName); } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdObject::saveAsText(BaseDynamicBuffer *buffer, int indent) { if (_blockRegion) _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); if (_wptGroup) _wptGroup->saveAsText(buffer, indent + 2); - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::updateBlockRegion() { - CAdGame *adGame = (CAdGame *)_gameRef; +bool AdObject::updateBlockRegion() { + AdGame *adGame = (AdGame *)_gameRef; if (adGame->_scene) { if (_blockRegion && _currentBlockRegion) _currentBlockRegion->mimic(_blockRegion, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); @@ -1049,20 +1049,20 @@ bool CAdObject::updateBlockRegion() { } ////////////////////////////////////////////////////////////////////////// -CAdInventory *CAdObject::getInventory() { +AdInventory *AdObject::getInventory() { if (!_inventory) { - _inventory = new CAdInventory(_gameRef); - ((CAdGame *)_gameRef)->registerInventory(_inventory); + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); } return _inventory; } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::afterMove() { - CAdRegion *newRegions[MAX_NUM_REGIONS]; +bool AdObject::afterMove() { + AdRegion *newRegions[MAX_NUM_REGIONS]; - ((CAdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); + ((AdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); for (int i = 0; i < MAX_NUM_REGIONS; i++) { if (!newRegions[i]) break; bool regFound = false; @@ -1087,20 +1087,20 @@ bool CAdObject::afterMove() { } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::invalidateCurrRegions() { +bool AdObject::invalidateCurrRegions() { for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::getScale(float *scaleX, float *scaleY) { +bool AdObject::getScale(float *scaleX, float *scaleY) { if (_zoomable) { if (_scaleX >= 0 || _scaleY >= 0) { *scaleX = _scaleX < 0 ? 100 : _scaleX; *scaleY = _scaleY < 0 ? 100 : _scaleY; } else if (_scale >= 0) *scaleX = *scaleY = _scale; - else *scaleX = *scaleY = ((CAdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; + else *scaleX = *scaleY = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; } else { *scaleX = *scaleY = 100; } @@ -1108,7 +1108,7 @@ bool CAdObject::getScale(float *scaleX, float *scaleY) { } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::updateSpriteAttachments() { +bool AdObject::updateSpriteAttachments() { for (int i = 0; i < _attachmentsPre.getSize(); i++) { _attachmentsPre[i]->update(); } @@ -1119,7 +1119,7 @@ bool CAdObject::updateSpriteAttachments() { } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::displaySpriteAttachments(bool preDisplay) { +bool AdObject::displaySpriteAttachments(bool preDisplay) { if (preDisplay) { for (int i = 0; i < _attachmentsPre.getSize(); i++) { displaySpriteAttachment(_attachmentsPre[i]); @@ -1133,7 +1133,7 @@ bool CAdObject::displaySpriteAttachments(bool preDisplay) { } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::displaySpriteAttachment(CAdObject *attachment) { +bool AdObject::displaySpriteAttachment(AdObject *attachment) { if (!attachment->_active) return STATUS_OK; float scaleX, scaleY; @@ -1171,13 +1171,13 @@ bool CAdObject::displaySpriteAttachment(CAdObject *attachment) { } ////////////////////////////////////////////////////////////////////////// -CPartEmitter *CAdObject::createParticleEmitter(bool followParent, int offsetX, int offsetY) { +PartEmitter *AdObject::createParticleEmitter(bool followParent, int offsetX, int offsetY) { _partFollowParent = followParent; _partOffsetX = offsetX; _partOffsetY = offsetY; if (!_partEmitter) { - _partEmitter = new CPartEmitter(_gameRef, this); + _partEmitter = new PartEmitter(_gameRef, this); if (_partEmitter) { _gameRef->registerObject(_partEmitter); } @@ -1187,7 +1187,7 @@ CPartEmitter *CAdObject::createParticleEmitter(bool followParent, int offsetX, i } ////////////////////////////////////////////////////////////////////////// -bool CAdObject::updatePartEmitter() { +bool AdObject::updatePartEmitter() { if (!_partEmitter) return STATUS_FAILED; if (_partFollowParent) { diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h index dd123092a3..a8da8bd820 100644 --- a/engines/wintermute/ad/ad_object.h +++ b/engines/wintermute/ad/ad_object.h @@ -34,19 +34,19 @@ namespace WinterMute { -class CAdWaypointGroup; -class CAdRegion; -class CAdSentence; -class CBFont; -class CBRegion; -class CAdInventory; +class AdWaypointGroup; +class AdRegion; +class AdSentence; +class BaseFont; +class BaseRegion; +class AdInventory; #define MAX_NUM_REGIONS 10 -class CAdObject : public CBObject { +class AdObject : public BaseObject { public: - CPartEmitter *_partEmitter; - virtual CPartEmitter *createParticleEmitter(bool followParent = false, int offsetX = 0, int offsetY = 0); + PartEmitter *_partEmitter; + virtual PartEmitter *createParticleEmitter(bool followParent = false, int offsetX = 0, int offsetY = 0); virtual bool updatePartEmitter(); bool _partFollowParent; int _partOffsetX; @@ -58,7 +58,7 @@ public: int _subtitlesModX; int _subtitlesModY; int _subtitlesWidth; - CAdRegion *_stickRegion; + AdRegion *_stickRegion; bool _sceneIndependent; bool _ignoreItems; bool updateBlockRegion(); @@ -68,51 +68,51 @@ public: virtual bool resetSoundPan(); virtual bool updateSounds(); bool reset(); - DECLARE_PERSISTENT(CAdObject, CBObject) + DECLARE_PERSISTENT(AdObject, BaseObject) virtual void talk(const char *text, const char *sound = NULL, uint32 duration = 0, const char *stances = NULL, TTextAlign align = TAL_CENTER); virtual int getHeight(); - CAdSentence *_sentence; + AdSentence *_sentence; bool SetFont(const char *filename); virtual bool update(); virtual bool display(); bool _drawn; bool _active; virtual bool playAnim(const char *filename); - CBSprite *_animSprite; - CBSprite *_currentSprite; + BaseSprite *_animSprite; + BaseSprite *_currentSprite; TObjectState _state; TObjectState _nextState; TObjectType _type; - CAdObject(CBGame *inGame); - virtual ~CAdObject(); - CBFont *_font; - CBSprite *_tempSprite2; - CBRegion *_blockRegion; - CAdWaypointGroup *_wptGroup; - CBRegion *_currentBlockRegion; - CAdWaypointGroup *_currentWptGroup; - CAdInventory *getInventory(); - - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + AdObject(BaseGame *inGame); + virtual ~AdObject(); + BaseFont *_font; + BaseSprite *_tempSprite2; + BaseRegion *_blockRegion; + AdWaypointGroup *_wptGroup; + BaseRegion *_currentBlockRegion; + AdWaypointGroup *_currentWptGroup; + AdInventory *getInventory(); + + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); virtual bool afterMove(); - CAdRegion *_currentRegions[MAX_NUM_REGIONS]; + AdRegion *_currentRegions[MAX_NUM_REGIONS]; // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); - CBArray _attachmentsPre; - CBArray _attachmentsPost; + BaseArray _attachmentsPre; + BaseArray _attachmentsPost; bool updateSpriteAttachments(); bool displaySpriteAttachments(bool preDisplay); - CAdObject *_registerAlias; + AdObject *_registerAlias; private: - bool displaySpriteAttachment(CAdObject *attachment); - CAdInventory *_inventory; + bool displaySpriteAttachment(AdObject *attachment); + AdInventory *_inventory; protected: bool getScale(float *scaleX, float *scaleY); diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index 780912ce08..cecfaa37d6 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -32,23 +32,23 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdPath, false) +IMPLEMENT_PERSISTENT(AdPath, false) ////////////////////////////////////////////////////////////////////////// -CAdPath::CAdPath(CBGame *inGame): CBBase(inGame) { +AdPath::AdPath(BaseGame *inGame): BaseClass(inGame) { _currIndex = -1; _ready = false; } ////////////////////////////////////////////////////////////////////////// -CAdPath::~CAdPath() { +AdPath::~AdPath() { reset(); } ////////////////////////////////////////////////////////////////////////// -void CAdPath::reset() { +void AdPath::reset() { for (int i = 0; i < _points.getSize(); i++) delete _points[i]; @@ -59,7 +59,7 @@ void CAdPath::reset() { ////////////////////////////////////////////////////////////////////////// -CBPoint *CAdPath::getFirst() { +BasePoint *AdPath::getFirst() { if (_points.getSize() > 0) { _currIndex = 0; return _points[_currIndex]; @@ -68,7 +68,7 @@ CBPoint *CAdPath::getFirst() { ////////////////////////////////////////////////////////////////////////// -CBPoint *CAdPath::getNext() { +BasePoint *AdPath::getNext() { _currIndex++; if (_currIndex < _points.getSize()) return _points[_currIndex]; else return NULL; @@ -76,20 +76,20 @@ CBPoint *CAdPath::getNext() { ////////////////////////////////////////////////////////////////////////// -CBPoint *CAdPath::getCurrent() { +BasePoint *AdPath::getCurrent() { if (_currIndex >= 0 && _currIndex < _points.getSize()) return _points[_currIndex]; else return NULL; } ////////////////////////////////////////////////////////////////////////// -void CAdPath::addPoint(CBPoint *point) { +void AdPath::addPoint(BasePoint *point) { _points.add(point); } ////////////////////////////////////////////////////////////////////////// -bool CAdPath::setReady(bool ready) { +bool AdPath::setReady(bool ready) { bool orig = _ready; _ready = ready; @@ -98,7 +98,7 @@ bool CAdPath::setReady(bool ready) { ////////////////////////////////////////////////////////////////////////// -bool CAdPath::persist(CBPersistMgr *persistMgr) { +bool AdPath::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_gameRef)); diff --git a/engines/wintermute/ad/ad_path.h b/engines/wintermute/ad/ad_path.h index f27362bfd9..958f52af03 100644 --- a/engines/wintermute/ad/ad_path.h +++ b/engines/wintermute/ad/ad_path.h @@ -34,19 +34,19 @@ #include "engines/wintermute/base/base.h" namespace WinterMute { -class CBPoint; -class CAdPath : public CBBase { +class BasePoint; +class AdPath : public BaseClass { public: - DECLARE_PERSISTENT(CAdPath, CBBase) - CBPoint *getCurrent(); + DECLARE_PERSISTENT(AdPath, BaseClass) + BasePoint *getCurrent(); bool setReady(bool ready = true); - void addPoint(CBPoint *point); - CBPoint *getNext(); - CBPoint *getFirst(); + void addPoint(BasePoint *point); + BasePoint *getNext(); + BasePoint *getFirst(); void reset(); - CAdPath(CBGame *inGame); - virtual ~CAdPath(); - CBArray _points; + AdPath(BaseGame *inGame); + virtual ~AdPath(); + BaseArray _points; int _currIndex; bool _ready; }; diff --git a/engines/wintermute/ad/ad_path_point.cpp b/engines/wintermute/ad/ad_path_point.cpp index d4b910a30f..d5d447eb9a 100644 --- a/engines/wintermute/ad/ad_path_point.cpp +++ b/engines/wintermute/ad/ad_path_point.cpp @@ -31,10 +31,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdPathPoint, false) +IMPLEMENT_PERSISTENT(AdPathPoint, false) ////////////////////////////////////////////////////////////////////////// -CAdPathPoint::CAdPathPoint() { +AdPathPoint::AdPathPoint() { x = y = 0; _distance = 0; @@ -44,7 +44,7 @@ CAdPathPoint::CAdPathPoint() { ////////////////////////////////////////////////////////////////////////// -CAdPathPoint::CAdPathPoint(int initX, int initY, int initDistance) { +AdPathPoint::AdPathPoint(int initX, int initY, int initDistance) { x = initX; y = initY; _distance = initDistance; @@ -55,15 +55,15 @@ CAdPathPoint::CAdPathPoint(int initX, int initY, int initDistance) { ////////////////////////////////////////////////////////////////////////// -CAdPathPoint::~CAdPathPoint() { +AdPathPoint::~AdPathPoint() { _origin = NULL; } ////////////////////////////////////////////////////////////////////////// -bool CAdPathPoint::persist(CBPersistMgr *persistMgr) { +bool AdPathPoint::persist(BasePersistenceManager *persistMgr) { - CBPoint::persist(persistMgr); + BasePoint::persist(persistMgr); persistMgr->transfer(TMEMBER(_distance)); persistMgr->transfer(TMEMBER(_marked)); diff --git a/engines/wintermute/ad/ad_path_point.h b/engines/wintermute/ad/ad_path_point.h index 2a58237bb9..ea0a5795d0 100644 --- a/engines/wintermute/ad/ad_path_point.h +++ b/engines/wintermute/ad/ad_path_point.h @@ -34,13 +34,13 @@ namespace WinterMute { -class CAdPathPoint : public CBPoint { +class AdPathPoint : public BasePoint { public: - DECLARE_PERSISTENT(CAdPathPoint, CBPoint) - CAdPathPoint(int initX, int initY, int initDistance); - CAdPathPoint(); - virtual ~CAdPathPoint(); - CAdPathPoint *_origin; + DECLARE_PERSISTENT(AdPathPoint, BasePoint) + AdPathPoint(int initX, int initY, int initDistance); + AdPathPoint(); + virtual ~AdPathPoint(); + AdPathPoint *_origin; bool _marked; int _distance; }; diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index ae65be5013..1bd6051bda 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -37,10 +37,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdRegion, false) +IMPLEMENT_PERSISTENT(AdRegion, false) ////////////////////////////////////////////////////////////////////////// -CAdRegion::CAdRegion(CBGame *inGame): CBRegion(inGame) { +AdRegion::AdRegion(BaseGame *inGame): BaseRegion(inGame) { _blocked = false; _decoration = false; _zoom = 0; @@ -49,15 +49,15 @@ CAdRegion::CAdRegion(CBGame *inGame): CBRegion(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdRegion::~CAdRegion() { +AdRegion::~AdRegion() { } ////////////////////////////////////////////////////////////////////////// -bool CAdRegion::loadFile(const char *filename) { +bool AdRegion::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdRegion::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdRegion::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -95,7 +95,7 @@ TOKEN_DEF(PROPERTY) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdRegion::loadBuffer(byte *buffer, bool complete) { +bool AdRegion::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(REGION) TOKEN_TABLE(TEMPLATE) @@ -118,7 +118,7 @@ bool CAdRegion::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { @@ -170,7 +170,7 @@ bool CAdRegion::loadBuffer(byte *buffer, bool complete) { case TOKEN_POINT: { int x, y; parser.scanStr((char *)params, "%d,%d", &x, &y); - _points.add(new CBPoint(x, y)); + _points.add(new BasePoint(x, y)); } break; @@ -219,7 +219,7 @@ bool CAdRegion::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdRegion::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { /* ////////////////////////////////////////////////////////////////////////// // SkipTo @@ -233,12 +233,12 @@ bool CAdRegion::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisS return STATUS_OK; } - else*/ return CBRegion::scCallMethod(script, stack, thisStack, name); + else*/ return BaseRegion::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdRegion::scGetProperty(const char *name) { +ScValue *AdRegion::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -289,12 +289,12 @@ CScValue *CAdRegion::scGetProperty(const char *name) { return _scValue; } - else return CBRegion::scGetProperty(name); + else return BaseRegion::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdRegion::scSetProperty(const char *name, CScValue *value) { +bool AdRegion::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Name ////////////////////////////////////////////////////////////////////////// @@ -335,18 +335,18 @@ bool CAdRegion::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else return CBRegion::scSetProperty(name, value); + else return BaseRegion::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -const char *CAdRegion::scToString() { +const char *AdRegion::scToString() { return "[ad region]"; } ////////////////////////////////////////////////////////////////////////// -bool CAdRegion::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdRegion::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "REGION {\n"); buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); @@ -369,7 +369,7 @@ bool CAdRegion::saveAsText(CBDynBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); } - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n\n"); @@ -378,8 +378,8 @@ bool CAdRegion::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdRegion::persist(CBPersistMgr *persistMgr) { - CBRegion::persist(persistMgr); +bool AdRegion::persist(BasePersistenceManager *persistMgr) { + BaseRegion::persist(persistMgr); persistMgr->transfer(TMEMBER(_alpha)); persistMgr->transfer(TMEMBER(_blocked)); diff --git a/engines/wintermute/ad/ad_region.h b/engines/wintermute/ad/ad_region.h index 62c5fd6ba3..7ee36dc970 100644 --- a/engines/wintermute/ad/ad_region.h +++ b/engines/wintermute/ad/ad_region.h @@ -33,23 +33,23 @@ namespace WinterMute { -class CAdRegion : public CBRegion { +class AdRegion : public BaseRegion { public: - DECLARE_PERSISTENT(CAdRegion, CBRegion) + DECLARE_PERSISTENT(AdRegion, BaseRegion) uint32 _alpha; float _zoom; bool _blocked; bool _decoration; - CAdRegion(CBGame *inGame); - virtual ~CAdRegion(); + AdRegion(BaseGame *inGame); + virtual ~AdRegion(); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); }; diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp index b653fbd36a..29398f547c 100644 --- a/engines/wintermute/ad/ad_response.cpp +++ b/engines/wintermute/ad/ad_response.cpp @@ -35,10 +35,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdResponse, false) +IMPLEMENT_PERSISTENT(AdResponse, false) ////////////////////////////////////////////////////////////////////////// -CAdResponse::CAdResponse(CBGame *inGame): CBObject(inGame) { +AdResponse::AdResponse(BaseGame *inGame): BaseObject(inGame) { _text = NULL; _textOrig = NULL; _icon = _iconHover = _iconPressed = NULL; @@ -49,7 +49,7 @@ CAdResponse::CAdResponse(CBGame *inGame): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdResponse::~CAdResponse() { +AdResponse::~AdResponse() { delete[] _text; delete[] _textOrig; delete _icon; @@ -65,18 +65,18 @@ CAdResponse::~CAdResponse() { ////////////////////////////////////////////////////////////////////////// -void CAdResponse::setText(const char *text) { - CBUtils::setString(&_text, text); - CBUtils::setString(&_textOrig, text); +void AdResponse::setText(const char *text) { + BaseUtils::setString(&_text, text); + BaseUtils::setString(&_textOrig, text); } ////////////////////////////////////////////////////////////////////////// -bool CAdResponse::setIcon(const char *filename) { +bool AdResponse::setIcon(const char *filename) { delete _icon; - _icon = new CBSprite(_gameRef); + _icon = new BaseSprite(_gameRef); if (!_icon || DID_FAIL(_icon->loadFile(filename))) { - _gameRef->LOG(0, "CAdResponse::setIcon failed for file '%s'", filename); + _gameRef->LOG(0, "AdResponse::setIcon failed for file '%s'", filename); delete _icon; _icon = NULL; return STATUS_FAILED; @@ -85,22 +85,22 @@ bool CAdResponse::setIcon(const char *filename) { } ////////////////////////////////////////////////////////////////////////// -bool CAdResponse::setFont(const char *filename) { +bool AdResponse::setFont(const char *filename) { if (_font) _gameRef->_fontStorage->removeFont(_font); _font = _gameRef->_fontStorage->addFont(filename); if (!_font) { - _gameRef->LOG(0, "CAdResponse::setFont failed for file '%s'", filename); + _gameRef->LOG(0, "AdResponse::setFont failed for file '%s'", filename); return STATUS_FAILED; } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool CAdResponse::setIconHover(const char *filename) { +bool AdResponse::setIconHover(const char *filename) { delete _iconHover; - _iconHover = new CBSprite(_gameRef); + _iconHover = new BaseSprite(_gameRef); if (!_iconHover || DID_FAIL(_iconHover->loadFile(filename))) { - _gameRef->LOG(0, "CAdResponse::setIconHover failed for file '%s'", filename); + _gameRef->LOG(0, "AdResponse::setIconHover failed for file '%s'", filename); delete _iconHover; _iconHover = NULL; return STATUS_FAILED; @@ -110,11 +110,11 @@ bool CAdResponse::setIconHover(const char *filename) { ////////////////////////////////////////////////////////////////////////// -bool CAdResponse::setIconPressed(const char *filename) { +bool AdResponse::setIconPressed(const char *filename) { delete _iconPressed; - _iconPressed = new CBSprite(_gameRef); + _iconPressed = new BaseSprite(_gameRef); if (!_iconPressed || DID_FAIL(_iconPressed->loadFile(filename))) { - _gameRef->LOG(0, "CAdResponse::setIconPressed failed for file '%s'", filename); + _gameRef->LOG(0, "AdResponse::setIconPressed failed for file '%s'", filename); delete _iconPressed; _iconPressed = NULL; return STATUS_FAILED; @@ -124,9 +124,9 @@ bool CAdResponse::setIconPressed(const char *filename) { ////////////////////////////////////////////////////////////////////////// -bool CAdResponse::persist(CBPersistMgr *persistMgr) { +bool AdResponse::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_icon)); persistMgr->transfer(TMEMBER(_iconHover)); diff --git a/engines/wintermute/ad/ad_response.h b/engines/wintermute/ad/ad_response.h index da450b2229..0cb8f6628b 100644 --- a/engines/wintermute/ad/ad_response.h +++ b/engines/wintermute/ad/ad_response.h @@ -34,24 +34,24 @@ #include "engines/wintermute/ad/ad_types.h" namespace WinterMute { -class CBFont; -class CAdResponse : public CBObject { +class BaseFont; +class AdResponse : public BaseObject { public: - DECLARE_PERSISTENT(CAdResponse, CBObject) + DECLARE_PERSISTENT(AdResponse, BaseObject) bool setIcon(const char *filename); bool setFont(const char *filename); bool setIconHover(const char *filename); bool setIconPressed(const char *filename); void setText(const char *text); int _iD; - CBSprite *_icon; - CBSprite *_iconHover; - CBSprite *_iconPressed; - CBFont *_font; + BaseSprite *_icon; + BaseSprite *_iconHover; + BaseSprite *_iconPressed; + BaseFont *_font; char *_text; char *_textOrig; - CAdResponse(CBGame *inGame); - virtual ~CAdResponse(); + AdResponse(BaseGame *inGame); + virtual ~AdResponse(); TResponseType _responseType; }; diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 2499c9a732..5b7e441abc 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -47,17 +47,17 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdResponseBox, false) +IMPLEMENT_PERSISTENT(AdResponseBox, false) ////////////////////////////////////////////////////////////////////////// -CAdResponseBox::CAdResponseBox(CBGame *inGame): CBObject(inGame) { +AdResponseBox::AdResponseBox(BaseGame *inGame): BaseObject(inGame) { _font = _fontHover = NULL; _window = NULL; - _shieldWindow = new CUIWindow(_gameRef); + _shieldWindow = new UIWindow(_gameRef); _horizontal = false; - CBPlatform::setRectEmpty(&_responseArea); + BasePlatform::setRectEmpty(&_responseArea); _scrollOffset = 0; _spacing = 0; @@ -71,7 +71,7 @@ CAdResponseBox::CAdResponseBox(CBGame *inGame): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdResponseBox::~CAdResponseBox() { +AdResponseBox::~AdResponseBox() { delete _window; _window = NULL; @@ -93,7 +93,7 @@ CAdResponseBox::~CAdResponseBox() { ////////////////////////////////////////////////////////////////////////// -void CAdResponseBox::clearResponses() { +void AdResponseBox::clearResponses() { for (int i = 0; i < _responses.getSize(); i++) { delete _responses[i]; } @@ -102,7 +102,7 @@ void CAdResponseBox::clearResponses() { ////////////////////////////////////////////////////////////////////////// -void CAdResponseBox::clearButtons() { +void AdResponseBox::clearButtons() { for (int i = 0; i < _respButtons.getSize(); i++) { delete _respButtons[i]; } @@ -111,7 +111,7 @@ void CAdResponseBox::clearButtons() { ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::invalidateButtons() { +bool AdResponseBox::invalidateButtons() { for (int i = 0; i < _respButtons.getSize(); i++) { _respButtons[i]->_image = NULL; _respButtons[i]->_cursor = NULL; @@ -125,12 +125,12 @@ bool CAdResponseBox::invalidateButtons() { ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::createButtons() { +bool AdResponseBox::createButtons() { clearButtons(); _scrollOffset = 0; for (int i = 0; i < _responses.getSize(); i++) { - CUIButton *btn = new CUIButton(_gameRef); + UIButton *btn = new UIButton(_gameRef); if (btn) { btn->_parent = _window; btn->_sharedFonts = btn->_sharedImages = true; @@ -187,10 +187,10 @@ bool CAdResponseBox::createButtons() { ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::loadFile(const char *filename) { +bool AdResponseBox::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdResponseBox::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdResponseBox::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -223,7 +223,7 @@ TOKEN_DEF(VERTICAL_ALIGN) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::loadBuffer(byte *buffer, bool complete) { +bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(RESPONSE_BOX) TOKEN_TABLE(TEMPLATE) @@ -242,7 +242,7 @@ bool CAdResponseBox::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_RESPONSE_BOX) { @@ -260,7 +260,7 @@ bool CAdResponseBox::loadBuffer(byte *buffer, bool complete) { case TOKEN_WINDOW: delete _window; - _window = new CUIWindow(_gameRef); + _window = new UIWindow(_gameRef); if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { delete _window; _window = NULL; @@ -310,7 +310,7 @@ bool CAdResponseBox::loadBuffer(byte *buffer, bool complete) { case TOKEN_CURSOR: delete _cursor; - _cursor = new CBSprite(_gameRef); + _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = NULL; @@ -335,7 +335,7 @@ bool CAdResponseBox::loadBuffer(byte *buffer, bool complete) { } ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "RESPONSE_BOX\n"); buffer->putTextIndent(indent, "{\n"); @@ -362,7 +362,7 @@ bool CAdResponseBox::saveAsText(CBDynBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "center"); break; default: - error("CAdResponseBox::SaveAsText - Unhandled enum"); + error("AdResponseBox::SaveAsText - Unhandled enum"); break; } @@ -388,7 +388,7 @@ bool CAdResponseBox::saveAsText(CBDynBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); // editor properties - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n"); return STATUS_OK; @@ -396,10 +396,10 @@ bool CAdResponseBox::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::display() { +bool AdResponseBox::display() { Rect32 rect = _responseArea; if (_window) { - CBPlatform::offsetRect(&rect, _window->_posX, _window->_posY); + BasePlatform::offsetRect(&rect, _window->_posX, _window->_posY); //_window->display(); } @@ -482,8 +482,8 @@ bool CAdResponseBox::display() { ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::listen(CBScriptHolder *param1, uint32 param2) { - CUIObject *obj = (CUIObject *)param1; +bool AdResponseBox::listen(BaseScriptHolder *param1, uint32 param2) { + UIObject *obj = (UIObject *)param1; switch (obj->_type) { case UI_BUTTON: @@ -496,11 +496,11 @@ bool CAdResponseBox::listen(CBScriptHolder *param1, uint32 param2) { handleResponse(_responses[param2]); _waitingScript = NULL; _gameRef->_state = GAME_RUNNING; - ((CAdGame *)_gameRef)->_stateEx = GAME_NORMAL; + ((AdGame *)_gameRef)->_stateEx = GAME_NORMAL; _ready = true; invalidateButtons(); clearResponses(); - } else return CBObject::listen(param1, param2); + } else return BaseObject::listen(param1, param2); break; default: error("AdResponseBox::Listen - Unhandled enum"); @@ -511,8 +511,8 @@ bool CAdResponseBox::listen(CBScriptHolder *param1, uint32 param2) { ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::persist(CBPersistMgr *persistMgr) { - CBObject::persist(persistMgr); +bool AdResponseBox::persist(BasePersistenceManager *persistMgr) { + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_font)); persistMgr->transfer(TMEMBER(_fontHover)); @@ -536,8 +536,8 @@ bool CAdResponseBox::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::weedResponses() { - CAdGame *adGame = (CAdGame *)_gameRef; +bool AdResponseBox::weedResponses() { + AdGame *adGame = (AdGame *)_gameRef; for (int i = 0; i < _responses.getSize(); i++) { switch (_responses[i]->_responseType) { @@ -557,7 +557,7 @@ bool CAdResponseBox::weedResponses() { } break; default: - warning("CAdResponseBox::WeedResponses - Unhandled enum"); + warning("AdResponseBox::WeedResponses - Unhandled enum"); break; } } @@ -566,17 +566,17 @@ bool CAdResponseBox::weedResponses() { ////////////////////////////////////////////////////////////////////////// -void CAdResponseBox::setLastResponseText(const char *text, const char *textOrig) { - CBUtils::setString(&_lastResponseText, text); - CBUtils::setString(&_lastResponseTextOrig, textOrig); +void AdResponseBox::setLastResponseText(const char *text, const char *textOrig) { + BaseUtils::setString(&_lastResponseText, text); + BaseUtils::setString(&_lastResponseTextOrig, textOrig); } ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::handleResponse(CAdResponse *response) { +bool AdResponseBox::handleResponse(AdResponse *response) { setLastResponseText(response->_text, response->_textOrig); - CAdGame *adGame = (CAdGame *)_gameRef; + AdGame *adGame = (AdGame *)_gameRef; switch (response->_responseType) { case RESPONSE_ONCE: @@ -587,7 +587,7 @@ bool CAdResponseBox::handleResponse(CAdResponse *response) { adGame->addGameResponse(response->_iD); break; default: - warning("CAdResponseBox::HandleResponse - Unhandled enum"); + warning("AdResponseBox::HandleResponse - Unhandled enum"); } return STATUS_OK; @@ -595,8 +595,8 @@ bool CAdResponseBox::handleResponse(CAdResponse *response) { ////////////////////////////////////////////////////////////////////////// -CBObject *CAdResponseBox::getNextAccessObject(CBObject *currObject) { - CBArray objects; +BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) { + BaseArray objects; getObjects(objects, true); if (objects.getSize() == 0) return NULL; @@ -615,8 +615,8 @@ CBObject *CAdResponseBox::getNextAccessObject(CBObject *currObject) { } ////////////////////////////////////////////////////////////////////////// -CBObject *CAdResponseBox::getPrevAccessObject(CBObject *currObject) { - CBArray objects; +BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { + BaseArray objects; getObjects(objects, true); if (objects.getSize() == 0) return NULL; @@ -635,7 +635,7 @@ CBObject *CAdResponseBox::getPrevAccessObject(CBObject *currObject) { } ////////////////////////////////////////////////////////////////////////// -bool CAdResponseBox::getObjects(CBArray &objects, bool interactiveOnly) { +bool AdResponseBox::getObjects(BaseArray &objects, bool interactiveOnly) { for (int i = 0; i < _respButtons.getSize(); i++) { objects.add(_respButtons[i]); } diff --git a/engines/wintermute/ad/ad_response_box.h b/engines/wintermute/ad/ad_response_box.h index 7c611ef2d6..f77ff3360c 100644 --- a/engines/wintermute/ad/ad_response_box.h +++ b/engines/wintermute/ad/ad_response_box.h @@ -34,23 +34,23 @@ namespace WinterMute { -class CUIButton; -class CUIWindow; -class CUIObject; -class CAdResponse; -class CAdResponseBox : public CBObject { +class UIButton; +class UIWindow; +class UIObject; +class AdResponse; +class AdResponseBox : public BaseObject { public: - CBObject *getNextAccessObject(CBObject *CurrObject); - CBObject *getPrevAccessObject(CBObject *CurrObject); - bool getObjects(CBArray &objects, bool interactiveOnly); + BaseObject *getNextAccessObject(BaseObject *CurrObject); + BaseObject *getPrevAccessObject(BaseObject *CurrObject); + bool getObjects(BaseArray &objects, bool interactiveOnly); - bool handleResponse(CAdResponse *response); + bool handleResponse(AdResponse *response); void setLastResponseText(const char *text, const char *textOrig); char *_lastResponseText; char *_lastResponseTextOrig; - DECLARE_PERSISTENT(CAdResponseBox, CBObject) - CScScript *_waitingScript; - virtual bool listen(CBScriptHolder *param1, uint32 param2); + DECLARE_PERSISTENT(AdResponseBox, BaseObject) + ScScript *_waitingScript; + virtual bool listen(BaseScriptHolder *param1, uint32 param2); typedef enum { EVENT_PREV, EVENT_NEXT, @@ -61,25 +61,25 @@ public: bool display(); int _spacing; int _scrollOffset; - CBFont *_fontHover; - CBFont *_font; + BaseFont *_fontHover; + BaseFont *_font; bool createButtons(); bool invalidateButtons(); void clearButtons(); void clearResponses(); - CAdResponseBox(CBGame *inGame); - virtual ~CAdResponseBox(); - CBArray _responses; - CBArray _respButtons; - CUIWindow *_window; - CUIWindow *_shieldWindow; + AdResponseBox(BaseGame *inGame); + virtual ~AdResponseBox(); + BaseArray _responses; + BaseArray _respButtons; + UIWindow *_window; + UIWindow *_shieldWindow; bool _horizontal; Rect32 _responseArea; int _verticalAlign; TTextAlign _align; bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_response_context.cpp b/engines/wintermute/ad/ad_response_context.cpp index 02b819d6de..32d9415fe9 100644 --- a/engines/wintermute/ad/ad_response_context.cpp +++ b/engines/wintermute/ad/ad_response_context.cpp @@ -32,24 +32,24 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdResponseContext, false) +IMPLEMENT_PERSISTENT(AdResponseContext, false) ////////////////////////////////////////////////////////////////////////// -CAdResponseContext::CAdResponseContext(CBGame *inGame): CBBase(inGame) { +AdResponseContext::AdResponseContext(BaseGame *inGame): BaseClass(inGame) { _iD = 0; _context = NULL; } ////////////////////////////////////////////////////////////////////////// -CAdResponseContext::~CAdResponseContext() { +AdResponseContext::~AdResponseContext() { delete[] _context; _context = NULL; } ////////////////////////////////////////////////////////////////////////// -bool CAdResponseContext::persist(CBPersistMgr *persistMgr) { +bool AdResponseContext::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_gameRef)); persistMgr->transfer(TMEMBER(_context)); persistMgr->transfer(TMEMBER(_iD)); @@ -58,7 +58,7 @@ bool CAdResponseContext::persist(CBPersistMgr *persistMgr) { } ////////////////////////////////////////////////////////////////////////// -void CAdResponseContext::setContext(const char *context) { +void AdResponseContext::setContext(const char *context) { delete[] _context; _context = NULL; if (context) { diff --git a/engines/wintermute/ad/ad_response_context.h b/engines/wintermute/ad/ad_response_context.h index 79eaa27640..d0dc1546b7 100644 --- a/engines/wintermute/ad/ad_response_context.h +++ b/engines/wintermute/ad/ad_response_context.h @@ -34,14 +34,14 @@ namespace WinterMute { -class CAdResponseContext : public CBBase { +class AdResponseContext : public BaseClass { public: void setContext(const char *context); int _iD; char *_context; - DECLARE_PERSISTENT(CAdResponseContext, CBBase) - CAdResponseContext(CBGame *inGame); - virtual ~CAdResponseContext(); + DECLARE_PERSISTENT(AdResponseContext, BaseClass) + AdResponseContext(BaseGame *inGame); + virtual ~AdResponseContext(); }; diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index 0ffbaf6919..e758eaa1f6 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -36,27 +36,27 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdRotLevel, false) +IMPLEMENT_PERSISTENT(AdRotLevel, false) ////////////////////////////////////////////////////////////////////////// -CAdRotLevel::CAdRotLevel(CBGame *inGame): CBObject(inGame) { +AdRotLevel::AdRotLevel(BaseGame *inGame): BaseObject(inGame) { _posX = 0; _rotation = 0.0f; } ////////////////////////////////////////////////////////////////////////// -CAdRotLevel::~CAdRotLevel() { +AdRotLevel::~AdRotLevel() { } ////////////////////////////////////////////////////////////////////////// -bool CAdRotLevel::loadFile(const char *filename) { +bool AdRotLevel::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdRotLevel::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdRotLevel::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -82,7 +82,7 @@ TOKEN_DEF(ROTATION) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdRotLevel::loadBuffer(byte *buffer, bool complete) { +bool AdRotLevel::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ROTATION_LEVEL) TOKEN_TABLE(TEMPLATE) @@ -93,7 +93,7 @@ bool CAdRotLevel::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ROTATION_LEVEL) { @@ -135,11 +135,11 @@ bool CAdRotLevel::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// -bool CAdRotLevel::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdRotLevel::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "ROTATION_LEVEL {\n"); buffer->putTextIndent(indent + 2, "X=%d\n", _posX); buffer->putTextIndent(indent + 2, "ROTATION=%d\n", (int)_rotation); - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n"); return STATUS_OK; @@ -147,9 +147,9 @@ bool CAdRotLevel::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdRotLevel::persist(CBPersistMgr *persistMgr) { +bool AdRotLevel::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_rotation)); diff --git a/engines/wintermute/ad/ad_rot_level.h b/engines/wintermute/ad/ad_rot_level.h index 2bd9519d65..4339a379a5 100644 --- a/engines/wintermute/ad/ad_rot_level.h +++ b/engines/wintermute/ad/ad_rot_level.h @@ -33,13 +33,13 @@ namespace WinterMute { -class CAdRotLevel : public CBObject { +class AdRotLevel : public BaseObject { public: - DECLARE_PERSISTENT(CAdRotLevel, CBObject) - CAdRotLevel(CBGame *inGame); - virtual ~CAdRotLevel(); + DECLARE_PERSISTENT(AdRotLevel, BaseObject) + AdRotLevel(BaseGame *inGame); + virtual ~AdRotLevel(); float _rotation; - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); }; diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index 220d3c4b39..65e0cc4663 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -35,26 +35,26 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdScaleLevel, false) +IMPLEMENT_PERSISTENT(AdScaleLevel, false) ////////////////////////////////////////////////////////////////////////// -CAdScaleLevel::CAdScaleLevel(CBGame *inGame): CBObject(inGame) { +AdScaleLevel::AdScaleLevel(BaseGame *inGame): BaseObject(inGame) { _posY = 0; _scale = 100; } ////////////////////////////////////////////////////////////////////////// -CAdScaleLevel::~CAdScaleLevel() { +AdScaleLevel::~AdScaleLevel() { } ////////////////////////////////////////////////////////////////////////// -bool CAdScaleLevel::loadFile(const char *filename) { +bool AdScaleLevel::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdScaleLevel::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdScaleLevel::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -80,7 +80,7 @@ TOKEN_DEF(SCALE) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdScaleLevel::loadBuffer(byte *buffer, bool complete) { +bool AdScaleLevel::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(SCALE_LEVEL) TOKEN_TABLE(TEMPLATE) @@ -91,7 +91,7 @@ bool CAdScaleLevel::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCALE_LEVEL) { @@ -133,11 +133,11 @@ bool CAdScaleLevel::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// -bool CAdScaleLevel::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdScaleLevel::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "SCALE_LEVEL {\n"); buffer->putTextIndent(indent + 2, "Y=%d\n", _posY); buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_scale); - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n"); return STATUS_OK; @@ -145,9 +145,9 @@ bool CAdScaleLevel::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdScaleLevel::persist(CBPersistMgr *persistMgr) { +bool AdScaleLevel::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_scale)); diff --git a/engines/wintermute/ad/ad_scale_level.h b/engines/wintermute/ad/ad_scale_level.h index 4a81c00dda..5e84f8c9ce 100644 --- a/engines/wintermute/ad/ad_scale_level.h +++ b/engines/wintermute/ad/ad_scale_level.h @@ -34,13 +34,13 @@ namespace WinterMute { -class CAdScaleLevel : public CBObject { +class AdScaleLevel : public BaseObject { public: - DECLARE_PERSISTENT(CAdScaleLevel, CBObject) + DECLARE_PERSISTENT(AdScaleLevel, BaseObject) float _scale; - CAdScaleLevel(CBGame *inGame); - virtual ~CAdScaleLevel(); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + AdScaleLevel(BaseGame *inGame); + virtual ~AdScaleLevel(); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); }; diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 11030d6996..104fe6dd4d 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -62,17 +62,17 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdScene, false) +IMPLEMENT_PERSISTENT(AdScene, false) ////////////////////////////////////////////////////////////////////////// -CAdScene::CAdScene(CBGame *inGame): CBObject(inGame) { - _pfTarget = new CBPoint; +AdScene::AdScene(BaseGame *inGame): BaseObject(inGame) { + _pfTarget = new BasePoint; setDefaults(); } ////////////////////////////////////////////////////////////////////////// -CAdScene::~CAdScene() { +AdScene::~AdScene() { cleanup(); _gameRef->unregisterObject(_fader); delete _pfTarget; @@ -81,7 +81,7 @@ CAdScene::~CAdScene() { ////////////////////////////////////////////////////////////////////////// -void CAdScene::setDefaults() { +void AdScene::setDefaults() { _initialized = false; _pfReady = true; _pfTargetPath = NULL; @@ -128,7 +128,7 @@ void CAdScene::setDefaults() { _shieldWindow = NULL; - _fader = new CBFader(_gameRef); + _fader = new BaseFader(_gameRef); _gameRef->registerObject(_fader); _viewport = NULL; @@ -136,8 +136,8 @@ void CAdScene::setDefaults() { ////////////////////////////////////////////////////////////////////////// -void CAdScene::cleanup() { - CBObject::cleanup(); +void AdScene::cleanup() { + BaseObject::cleanup(); _mainLayer = NULL; // reference only @@ -184,7 +184,7 @@ void CAdScene::cleanup() { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject *requester) { +bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester) { if (!_pfReady) return false; else { _pfReady = false; @@ -200,7 +200,7 @@ bool CAdScene::getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject * pfPointsStart(); // first point - //_pfPath.add(new CAdPathPoint(source.x, source.y, 0)); + //_pfPath.add(new AdPathPoint(source.x, source.y, 0)); // if we're one pixel stuck, get unstuck int startX = source.x; @@ -228,7 +228,7 @@ bool CAdScene::getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject * //CorrectTargetPoint(&target.x, &target.y); // last point - //_pfPath.add(new CAdPathPoint(target.x, target.y, INT_MAX)); + //_pfPath.add(new AdPathPoint(target.x, target.y, INT_MAX)); pfPointsAdd(target.x, target.y, INT_MAX); // active waypoints @@ -245,7 +245,7 @@ bool CAdScene::getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject * pfAddWaypointGroup(_objects[i]->_currentWptGroup, requester); } } - CAdGame *adGame = (CAdGame *)_gameRef; + AdGame *adGame = (AdGame *)_gameRef; for (i = 0; i < adGame->_objects.getSize(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentWptGroup) { pfAddWaypointGroup(adGame->_objects[i]->_currentWptGroup, requester); @@ -258,26 +258,26 @@ bool CAdScene::getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject * ////////////////////////////////////////////////////////////////////////// -void CAdScene::pfAddWaypointGroup(CAdWaypointGroup *wpt, CBObject *requester) { +void AdScene::pfAddWaypointGroup(AdWaypointGroup *wpt, BaseObject *requester) { if (!wpt->_active) return; for (int i = 0; i < wpt->_points.getSize(); i++) { if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) continue; - //_pfPath.add(new CAdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); + //_pfPath.add(new AdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX); } } ////////////////////////////////////////////////////////////////////////// -float CAdScene::getZoomAt(int x, int y) { +float AdScene::getZoomAt(int x, int y) { float ret = 100; bool found = false; if (_mainLayer) { for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { - CAdSceneNode *node = _mainLayer->_nodes[i]; + AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_blocked && node->_region->pointInRegion(x, y)) { if (node->_region->_zoom != 0) { ret = node->_region->_zoom; @@ -294,7 +294,7 @@ float CAdScene::getZoomAt(int x, int y) { ////////////////////////////////////////////////////////////////////////// -uint32 CAdScene::getAlphaAt(int x, int y, bool colorCheck) { +uint32 AdScene::getAlphaAt(int x, int y, bool colorCheck) { if (!_gameRef->_debugDebugMode) colorCheck = false; uint32 ret; @@ -303,7 +303,7 @@ uint32 CAdScene::getAlphaAt(int x, int y, bool colorCheck) { if (_mainLayer) { for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { - CAdSceneNode *node = _mainLayer->_nodes[i]; + AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { if (!node->_region->_blocked) ret = node->_region->_alpha; break; @@ -315,7 +315,7 @@ uint32 CAdScene::getAlphaAt(int x, int y, bool colorCheck) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::isBlockedAt(int x, int y, bool checkFreeObjects, CBObject *requester) { +bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *requester) { bool ret = true; @@ -325,7 +325,7 @@ bool CAdScene::isBlockedAt(int x, int y, bool checkFreeObjects, CBObject *reques if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; } } - CAdGame *adGame = (CAdGame *)_gameRef; + AdGame *adGame = (AdGame *)_gameRef; for (int i = 0; i < adGame->_objects.getSize(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; @@ -336,7 +336,7 @@ bool CAdScene::isBlockedAt(int x, int y, bool checkFreeObjects, CBObject *reques if (_mainLayer) { for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { - CAdSceneNode *node = _mainLayer->_nodes[i]; + AdSceneNode *node = _mainLayer->_nodes[i]; /* if (Node->_type == OBJECT_REGION && Node->_region->_active && Node->_region->_blocked && Node->_region->PointInRegion(X, Y)) { @@ -357,7 +357,7 @@ bool CAdScene::isBlockedAt(int x, int y, bool checkFreeObjects, CBObject *reques ////////////////////////////////////////////////////////////////////////// -bool CAdScene::isWalkableAt(int x, int y, bool checkFreeObjects, CBObject *requester) { +bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requester) { bool ret = false; if (checkFreeObjects) { @@ -366,7 +366,7 @@ bool CAdScene::isWalkableAt(int x, int y, bool checkFreeObjects, CBObject *reque if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; } } - CAdGame *adGame = (CAdGame *)_gameRef; + AdGame *adGame = (AdGame *)_gameRef; for (int i = 0; i < adGame->_objects.getSize(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; @@ -377,7 +377,7 @@ bool CAdScene::isWalkableAt(int x, int y, bool checkFreeObjects, CBObject *reque if (_mainLayer) { for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { - CAdSceneNode *node = _mainLayer->_nodes[i]; + AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { if (node->_region->_blocked) { ret = false; @@ -391,7 +391,7 @@ bool CAdScene::isWalkableAt(int x, int y, bool checkFreeObjects, CBObject *reque ////////////////////////////////////////////////////////////////////////// -int CAdScene::getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester) { +int AdScene::getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester) { double xStep, yStep, x, y; int xLength, yLength, xCount, yCount; int x1, y1, x2, y2; @@ -406,8 +406,8 @@ int CAdScene::getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester) { if (xLength > yLength) { if (x1 > x2) { - CBUtils::swap(&x1, &x2); - CBUtils::swap(&y1, &y2); + BaseUtils::swap(&x1, &x2); + BaseUtils::swap(&y1, &y2); } yStep = (double)(y2 - y1) / (double)(x2 - x1); @@ -419,8 +419,8 @@ int CAdScene::getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester) { } } else { if (y1 > y2) { - CBUtils::swap(&x1, &x2); - CBUtils::swap(&y1, &y2); + BaseUtils::swap(&x1, &x2); + BaseUtils::swap(&y1, &y2); } xStep = (double)(x2 - x1) / (double)(y2 - y1); @@ -436,11 +436,11 @@ int CAdScene::getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester) { ////////////////////////////////////////////////////////////////////////// -void CAdScene::pathFinderStep() { +void AdScene::pathFinderStep() { int i; // get lowest unmarked int lowestDist = INT_MAX; - CAdPathPoint *lowestPt = NULL; + AdPathPoint *lowestPt = NULL; for (i = 0; i < _pfPointsNum; i++) if (!_pfPath[i]->_marked && _pfPath[i]->_distance < lowestDist) { @@ -459,7 +459,7 @@ void CAdScene::pathFinderStep() { // target point marked, generate path and terminate if (lowestPt->x == _pfTarget->x && lowestPt->y == _pfTarget->y) { while (lowestPt != NULL) { - _pfTargetPath->_points.insertAt(0, new CBPoint(lowestPt->x, lowestPt->y)); + _pfTargetPath->_points.insertAt(0, new BasePoint(lowestPt->x, lowestPt->y)); lowestPt = lowestPt->_origin; } @@ -481,18 +481,18 @@ void CAdScene::pathFinderStep() { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::initLoop() { +bool AdScene::initLoop() { #ifdef _DEBUGxxxx int nu_steps = 0; uint32 start = _gameRef->_currentTime; - while (!_pfReady && CBPlatform::getTime() - start <= _pfMaxTime) { + while (!_pfReady && BasePlatform::getTime() - start <= _pfMaxTime) { PathFinderStep(); nu_steps++; } if (nu_steps > 0) _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); #else uint32 start = _gameRef->_currentTime; - while (!_pfReady && CBPlatform::getTime() - start <= _pfMaxTime) pathFinderStep(); + while (!_pfReady && BasePlatform::getTime() - start <= _pfMaxTime) pathFinderStep(); #endif return STATUS_OK; @@ -500,10 +500,10 @@ bool CAdScene::initLoop() { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::loadFile(const char *filename) { +bool AdScene::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdScene::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdScene::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -565,7 +565,7 @@ TOKEN_DEF(PERSISTENT_STATE) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdScene::loadBuffer(byte *buffer, bool complete) { +bool AdScene::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(SCENE) TOKEN_TABLE(TEMPLATE) @@ -610,7 +610,7 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCENE) { @@ -639,7 +639,7 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_LAYER: { - CAdLayer *layer = new CAdLayer(_gameRef); + AdLayer *layer = new AdLayer(_gameRef); if (!layer || DID_FAIL(layer->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; delete layer; @@ -657,7 +657,7 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_WAYPOINTS: { - CAdWaypointGroup *wpt = new CAdWaypointGroup(_gameRef); + AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); if (!wpt || DID_FAIL(wpt->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; delete wpt; @@ -670,7 +670,7 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_SCALE_LEVEL: { - CAdScaleLevel *sl = new CAdScaleLevel(_gameRef); + AdScaleLevel *sl = new AdScaleLevel(_gameRef); if (!sl || DID_FAIL(sl->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; delete sl; @@ -683,7 +683,7 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ROTATION_LEVEL: { - CAdRotLevel *rl = new CAdRotLevel(_gameRef); + AdRotLevel *rl = new AdRotLevel(_gameRef); if (!rl || DID_FAIL(rl->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; delete rl; @@ -696,7 +696,7 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ENTITY: { - CAdEntity *entity = new CAdEntity(_gameRef); + AdEntity *entity = new AdEntity(_gameRef); if (!entity || DID_FAIL(entity->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; delete entity; @@ -709,7 +709,7 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { case TOKEN_CURSOR: delete _cursor; - _cursor = new CBSprite(_gameRef); + _cursor = new BaseSprite(_gameRef); if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { delete _cursor; _cursor = NULL; @@ -820,7 +820,7 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { case TOKEN_VIEWPORT: { Rect32 rc; parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_viewport) _viewport = new CBViewport(_gameRef); + if (!_viewport) _viewport = new BaseViewport(_gameRef); if (_viewport) _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); } @@ -856,11 +856,11 @@ bool CAdScene::loadBuffer(byte *buffer, bool complete) { } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::traverseNodes(bool doUpdate) { +bool AdScene::traverseNodes(bool doUpdate) { if (!_initialized) return STATUS_OK; int j, k; - CAdGame *adGame = (CAdGame *)_gameRef; + AdGame *adGame = (AdGame *)_gameRef; ////////////////////////////////////////////////////////////////////////// @@ -949,7 +949,7 @@ bool CAdScene::traverseNodes(bool doUpdate) { // make layer exclusive if (!doUpdate) { if (_layers[j]->_closeUp && !_gameRef->_editorMode) { - if (!_shieldWindow) _shieldWindow = new CUIWindow(_gameRef); + if (!_shieldWindow) _shieldWindow = new UIWindow(_gameRef); if (_shieldWindow) { _shieldWindow->_posX = _shieldWindow->_posY = 0; _shieldWindow->_width = _gameRef->_renderer->_width; @@ -978,7 +978,7 @@ bool CAdScene::traverseNodes(bool doUpdate) { // for each node for (k = 0; k < _layers[j]->_nodes.getSize(); k++) { - CAdSceneNode *node = _layers[j]->_nodes[k]; + AdSceneNode *node = _layers[j]->_nodes[k]; switch (node->_type) { case OBJECT_ENTITY: if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) { @@ -1030,13 +1030,13 @@ bool CAdScene::traverseNodes(bool doUpdate) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::display() { +bool AdScene::display() { return traverseNodes(false); } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::updateFreeObjects() { - CAdGame *adGame = (CAdGame *)_gameRef; +bool AdScene::updateFreeObjects() { + AdGame *adGame = (AdGame *)_gameRef; bool is3DSet; // *** update all active objects @@ -1067,10 +1067,10 @@ bool CAdScene::updateFreeObjects() { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::displayRegionContent(CAdRegion *region, bool display3DOnly) { - CAdGame *adGame = (CAdGame *)_gameRef; - CBArray objects; - CAdObject *obj; +bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { + AdGame *adGame = (AdGame *)_gameRef; + BaseArray objects; + AdObject *obj; // global objects for (int i = 0; i < adGame->_objects.getSize(); i++) { @@ -1089,7 +1089,7 @@ bool CAdScene::displayRegionContent(CAdRegion *region, bool display3DOnly) { } // sort by _posY - qsort(objects.getData(), objects.getSize(), sizeof(CAdObject *), CAdScene::compareObjs); + qsort(objects.getData(), objects.getSize(), sizeof(AdObject *), AdScene::compareObjs); // display them for (int i = 0; i < objects.getSize(); i++) { @@ -1120,9 +1120,9 @@ bool CAdScene::displayRegionContent(CAdRegion *region, bool display3DOnly) { } ////////////////////////////////////////////////////////////////////////// -int CAdScene::compareObjs(const void *obj1, const void *obj2) { - CAdObject *object1 = *(CAdObject **)obj1; - CAdObject *object2 = *(CAdObject **)obj2; +int AdScene::compareObjs(const void *obj1, const void *obj2) { + AdObject *object1 = *(AdObject **)obj1; + AdObject *object2 = *(AdObject **)obj2; if (object1->_posY < object2->_posY) return -1; else if (object1->_posY > object2->_posY) return 1; @@ -1130,9 +1130,9 @@ int CAdScene::compareObjs(const void *obj1, const void *obj2) { } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::displayRegionContentOld(CAdRegion *region) { - CAdGame *adGame = (CAdGame *)_gameRef; - CAdObject *obj; +bool AdScene::displayRegionContentOld(AdRegion *region) { + AdGame *adGame = (AdGame *)_gameRef; + AdObject *obj; // display all objects in region sorted by _posY do { @@ -1180,12 +1180,12 @@ bool CAdScene::displayRegionContentOld(CAdRegion *region) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::update() { +bool AdScene::update() { return traverseNodes(true); } ////////////////////////////////////////////////////////////////////////// -void CAdScene::scrollTo(int offsetX, int offsetY) { +void AdScene::scrollTo(int offsetX, int offsetY) { int viewportWidth, viewportHeight; getViewportSize(&viewportWidth, &viewportHeight); @@ -1210,19 +1210,19 @@ void CAdScene::scrollTo(int offsetX, int offsetY) { ////////////////////////////////////////////////////////////////////////// -void CAdScene::scrollToObject(CBObject *object) { +void AdScene::scrollToObject(BaseObject *object) { if (object) scrollTo(object->_posX, object->_posY - object->getHeight() / 2); } ////////////////////////////////////////////////////////////////////////// -void CAdScene::skipToObject(CBObject *object) { +void AdScene::skipToObject(BaseObject *object) { if (object) skipTo(object->_posX, object->_posY - object->getHeight() / 2); } ////////////////////////////////////////////////////////////////////////// -void CAdScene::skipTo(int offsetX, int offsetY) { +void AdScene::skipTo(int offsetX, int offsetY) { int viewportWidth, viewportHeight; getViewportSize(&viewportWidth, &viewportHeight); @@ -1240,13 +1240,13 @@ void CAdScene::skipTo(int offsetX, int offsetY) { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // LoadActor ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "LoadActor") == 0) { stack->correctParams(1); - CAdActor *act = new CAdActor(_gameRef); + AdActor *act = new AdActor(_gameRef); if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { addObject(act); stack->pushNative(act, true); @@ -1263,7 +1263,7 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "LoadEntity") == 0) { stack->correctParams(1); - CAdEntity *ent = new CAdEntity(_gameRef); + AdEntity *ent = new AdEntity(_gameRef); if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { addObject(ent); stack->pushNative(ent, true); @@ -1280,9 +1280,9 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "CreateEntity") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdEntity *ent = new CAdEntity(_gameRef); + AdEntity *ent = new AdEntity(_gameRef); addObject(ent); if (!val->isNULL()) ent->setName(val->getString()); stack->pushNative(ent, true); @@ -1294,8 +1294,8 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "UnloadActor3D") == 0 || strcmp(name, "DeleteEntity") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); - CAdObject *obj = (CAdObject *)val->getNative(); + ScValue *val = stack->pop(); + AdObject *obj = (AdObject *)val->getNative(); removeObject(obj); if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); @@ -1308,10 +1308,10 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SkipTo") == 0) { stack->correctParams(2); - CScValue *val1 = stack->pop(); - CScValue *val2 = stack->pop(); + ScValue *val1 = stack->pop(); + ScValue *val2 = stack->pop(); if (val1->isNative()) { - skipToObject((CBObject *)val1->getNative()); + skipToObject((BaseObject *)val1->getNative()); } else { skipTo(val1->getInt(), val2->getInt()); } @@ -1324,10 +1324,10 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ScrollTo") == 0 || strcmp(name, "ScrollToAsync") == 0) { stack->correctParams(2); - CScValue *val1 = stack->pop(); - CScValue *val2 = stack->pop(); + ScValue *val1 = stack->pop(); + ScValue *val2 = stack->pop(); if (val1->isNative()) { - scrollToObject((CBObject *)val1->getNative()); + scrollToObject((BaseObject *)val1->getNative()); } else { scrollTo(val1->getInt(), val2->getInt()); } @@ -1341,7 +1341,7 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetLayer") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); if (val->isInt()) { int layer = val->getInt(); if (layer < 0 || layer >= _layers.getSize()) stack->pushNULL(); @@ -1379,8 +1379,8 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt stack->correctParams(1); const char *nodeName = stack->pop()->getString(); - CBObject *node = getNodeByName(nodeName); - if (node) stack->pushNative((CBScriptable *)node, true); + BaseObject *node = getNodeByName(nodeName); + if (node) stack->pushNative((BaseScriptable *)node, true); else stack->pushNULL(); return STATUS_OK; @@ -1391,9 +1391,9 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetFreeNode") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdObject *ret = NULL; + AdObject *ret = NULL; if (val->isInt()) { int index = val->getInt(); if (index >= 0 && index < _objects.getSize()) ret = _objects[index]; @@ -1419,14 +1419,14 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt stack->correctParams(3); int x = stack->pop()->getInt(); int y = stack->pop()->getInt(); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); bool includeDecors = false; if (!val->isNULL()) includeDecors = val->getBool(); if (_mainLayer) { for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { - CAdSceneNode *node = _mainLayer->_nodes[i]; + AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { if (node->_region->_decoration && !includeDecors) continue; @@ -1570,7 +1570,7 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt if (width <= 0) width = _gameRef->_renderer->_width; if (height <= 0) height = _gameRef->_renderer->_height; - if (!_viewport) _viewport = new CBViewport(_gameRef); + if (!_viewport) _viewport = new BaseViewport(_gameRef); if (_viewport) _viewport->setRect(x, y, x + width, y + height); stack->pushBool(true); @@ -1583,9 +1583,9 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "AddLayer") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdLayer *layer = new CAdLayer(_gameRef); + AdLayer *layer = new AdLayer(_gameRef); if (!val->isNULL()) layer->setName(val->getString()); if (_mainLayer) { layer->_width = _mainLayer->_width; @@ -1604,9 +1604,9 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt else if (strcmp(name, "InsertLayer") == 0) { stack->correctParams(2); int index = stack->pop()->getInt(); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdLayer *layer = new CAdLayer(_gameRef); + AdLayer *layer = new AdLayer(_gameRef); if (!val->isNULL()) layer->setName(val->getString()); if (_mainLayer) { layer->_width = _mainLayer->_width; @@ -1627,11 +1627,11 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "DeleteLayer") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); - CAdLayer *toDelete = NULL; + AdLayer *toDelete = NULL; if (val->isNative()) { - CBScriptable *temp = val->getNative(); + BaseScriptable *temp = val->getNative(); for (int i = 0; i < _layers.getSize(); i++) { if (_layers[i] == temp) { toDelete = _layers[i]; @@ -1666,12 +1666,12 @@ bool CAdScene::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisSt return STATUS_OK; } - else return CBObject::scCallMethod(script, stack, thisStack, name); + else return BaseObject::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdScene::scGetProperty(const char *name) { +ScValue *AdScene::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -1829,12 +1829,12 @@ CScValue *CAdScene::scGetProperty(const char *name) { return _scValue; } - else return CBObject::scGetProperty(name); + else return BaseObject::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::scSetProperty(const char *name, CScValue *value) { +bool AdScene::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Name ////////////////////////////////////////////////////////////////////////// @@ -1931,25 +1931,25 @@ bool CAdScene::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else return CBObject::scSetProperty(name, value); + else return BaseObject::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -const char *CAdScene::scToString() { +const char *AdScene::scToString() { return "[scene object]"; } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::addObject(CAdObject *object) { +bool AdScene::addObject(AdObject *object) { _objects.add(object); return _gameRef->registerObject(object); } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::removeObject(CAdObject *object) { +bool AdScene::removeObject(AdObject *object) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i] == object) { _objects.removeAt(i); @@ -1961,7 +1961,7 @@ bool CAdScene::removeObject(CAdObject *object) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { int i; buffer->putTextIndent(indent, "SCENE {\n"); @@ -2019,7 +2019,7 @@ bool CAdScene::saveAsText(CBDynBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); // waypoints buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); @@ -2059,13 +2059,13 @@ bool CAdScene::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::sortScaleLevels() { +bool AdScene::sortScaleLevels() { bool changed; do { changed = false; for (int i = 0; i < _scaleLevels.getSize() - 1; i++) { if (_scaleLevels[i]->_posY > _scaleLevels[i + 1]->_posY) { - CAdScaleLevel *sl = _scaleLevels[i]; + AdScaleLevel *sl = _scaleLevels[i]; _scaleLevels[i] = _scaleLevels[i + 1]; _scaleLevels[i + 1] = sl; @@ -2080,13 +2080,13 @@ bool CAdScene::sortScaleLevels() { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::sortRotLevels() { +bool AdScene::sortRotLevels() { bool changed; do { changed = false; for (int i = 0; i < _rotLevels.getSize() - 1; i++) { if (_rotLevels[i]->_posX > _rotLevels[i + 1]->_posX) { - CAdRotLevel *rl = _rotLevels[i]; + AdRotLevel *rl = _rotLevels[i]; _rotLevels[i] = _rotLevels[i + 1]; _rotLevels[i + 1] = rl; @@ -2101,12 +2101,12 @@ bool CAdScene::sortRotLevels() { ////////////////////////////////////////////////////////////////////////// -float CAdScene::getScaleAt(int Y) { - CAdScaleLevel *prev = NULL; - CAdScaleLevel *next = NULL; +float AdScene::getScaleAt(int Y) { + AdScaleLevel *prev = NULL; + AdScaleLevel *next = NULL; for (int i = 0; i < _scaleLevels.getSize(); i++) { - /* CAdScaleLevel *xxx = _scaleLevels[i];*/ + /* AdScaleLevel *xxx = _scaleLevels[i];*/ /* int j = _scaleLevels.getSize(); */ if (_scaleLevels[i]->_posY < Y) prev = _scaleLevels[i]; else { @@ -2127,8 +2127,8 @@ float CAdScene::getScaleAt(int Y) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::persist(CBPersistMgr *persistMgr) { - CBObject::persist(persistMgr); +bool AdScene::persist(BasePersistenceManager *persistMgr) { + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_autoScroll)); persistMgr->transfer(TMEMBER(_editorColBlocked)); @@ -2187,12 +2187,12 @@ bool CAdScene::persist(CBPersistMgr *persistMgr) { } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::afterLoad() { +bool AdScene::afterLoad() { return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, CBObject *requester) { +bool AdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, BaseObject *requester) { double xStep, yStep, x, y; int xLength, yLength, xCount, yCount; int x1, y1, x2, y2; @@ -2251,7 +2251,7 @@ bool CAdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *ta } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, bool checkFreeObjects, CBObject *requester) { +bool AdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, bool checkFreeObjects, BaseObject *requester) { int x = *argX; int y = *argY; @@ -2328,15 +2328,15 @@ bool CAdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, ////////////////////////////////////////////////////////////////////////// -void CAdScene::pfPointsStart() { +void AdScene::pfPointsStart() { _pfPointsNum = 0; } ////////////////////////////////////////////////////////////////////////// -void CAdScene::pfPointsAdd(int x, int y, int distance) { +void AdScene::pfPointsAdd(int x, int y, int distance) { if (_pfPointsNum >= _pfPath.getSize()) { - _pfPath.add(new CAdPathPoint(x, y, distance)); + _pfPath.add(new AdPathPoint(x, y, distance)); } else { _pfPath[_pfPointsNum]->x = x; _pfPath[_pfPointsNum]->y = y; @@ -2350,8 +2350,8 @@ void CAdScene::pfPointsAdd(int x, int y, int distance) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::getViewportOffset(int *offsetX, int *offsetY) { - CAdGame *adGame = (CAdGame *)_gameRef; +bool AdScene::getViewportOffset(int *offsetX, int *offsetY) { + AdGame *adGame = (AdGame *)_gameRef; if (_viewport && !_gameRef->_editorMode) { if (offsetX) *offsetX = _viewport->_offsetX; if (offsetY) *offsetY = _viewport->_offsetY; @@ -2367,8 +2367,8 @@ bool CAdScene::getViewportOffset(int *offsetX, int *offsetY) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::getViewportSize(int *width, int *height) { - CAdGame *adGame = (CAdGame *)_gameRef; +bool AdScene::getViewportSize(int *width, int *height) { + AdGame *adGame = (AdGame *)_gameRef; if (_viewport && !_gameRef->_editorMode) { if (width) *width = _viewport->getWidth(); if (height) *height = _viewport->getHeight(); @@ -2384,7 +2384,7 @@ bool CAdScene::getViewportSize(int *width, int *height) { ////////////////////////////////////////////////////////////////////////// -int CAdScene::getOffsetLeft() { +int AdScene::getOffsetLeft() { int viewportX; getViewportOffset(&viewportX); @@ -2393,7 +2393,7 @@ int CAdScene::getOffsetLeft() { ////////////////////////////////////////////////////////////////////////// -int CAdScene::getOffsetTop() { +int AdScene::getOffsetTop() { int viewportY; getViewportOffset(NULL, &viewportY); @@ -2402,7 +2402,7 @@ int CAdScene::getOffsetTop() { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::pointInViewport(int x, int y) { +bool AdScene::pointInViewport(int x, int y) { int left, top, width, height; getViewportOffset(&left, &top); @@ -2413,21 +2413,21 @@ bool CAdScene::pointInViewport(int x, int y) { ////////////////////////////////////////////////////////////////////////// -void CAdScene::setOffset(int offsetLeft, int offsetTop) { +void AdScene::setOffset(int offsetLeft, int offsetTop) { _offsetLeft = offsetLeft; _offsetTop = offsetTop; } ////////////////////////////////////////////////////////////////////////// -CBObject *CAdScene::getNodeByName(const char *name) { - CBObject *ret = NULL; +BaseObject *AdScene::getNodeByName(const char *name) { + BaseObject *ret = NULL; // dependent objects for (int i = 0; i < _layers.getSize(); i++) { - CAdLayer *layer = _layers[i]; + AdLayer *layer = _layers[i]; for (int j = 0; j < layer->_nodes.getSize(); j++) { - CAdSceneNode *node = layer->_nodes[j]; + AdSceneNode *node = layer->_nodes[j]; if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->_name)) || (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->_name))) { switch (node->_type) { @@ -2464,32 +2464,32 @@ CBObject *CAdScene::getNodeByName(const char *name) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::saveState() { +bool AdScene::saveState() { return persistState(true); } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::loadState() { +bool AdScene::loadState() { return persistState(false); } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::persistState(bool saving) { +bool AdScene::persistState(bool saving) { if (!_persistentState) return STATUS_OK; - CAdGame *adGame = (CAdGame *)_gameRef; - CAdSceneState *state = adGame->getSceneState(_filename, saving); + AdGame *adGame = (AdGame *)_gameRef; + AdSceneState *state = adGame->getSceneState(_filename, saving); if (!state) return STATUS_OK; - CAdNodeState *nodeState; + AdNodeState *nodeState; // dependent objects for (int i = 0; i < _layers.getSize(); i++) { - CAdLayer *layer = _layers[i]; + AdLayer *layer = _layers[i]; for (int j = 0; j < layer->_nodes.getSize(); j++) { - CAdSceneNode *node = layer->_nodes[j]; + AdSceneNode *node = layer->_nodes[j]; switch (node->_type) { case OBJECT_ENTITY: if (!node->_entity->_saveState) continue; @@ -2509,7 +2509,7 @@ bool CAdScene::persistState(bool saving) { } break; default: - warning("CAdScene::PersistState - unhandled enum"); + warning("AdScene::PersistState - unhandled enum"); break; } } @@ -2521,7 +2521,7 @@ bool CAdScene::persistState(bool saving) { if (_objects[i]->_type == OBJECT_ENTITY) { nodeState = state->getNodeState(_objects[i]->_name, saving); if (nodeState) { - nodeState->transferEntity((CAdEntity *)_objects[i], _persistentStateSprites, saving); + nodeState->transferEntity((AdEntity *)_objects[i], _persistentStateSprites, saving); //if(Saving) NodeState->_active = _objects[i]->_active; //else _objects[i]->_active = NodeState->_active; } @@ -2542,12 +2542,12 @@ bool CAdScene::persistState(bool saving) { ////////////////////////////////////////////////////////////////////////// -float CAdScene::getRotationAt(int x, int y) { - CAdRotLevel *prev = NULL; - CAdRotLevel *next = NULL; +float AdScene::getRotationAt(int x, int y) { + AdRotLevel *prev = NULL; + AdRotLevel *next = NULL; for (int i = 0; i < _rotLevels.getSize(); i++) { - /* CAdRotLevel *xxx = _rotLevels[i]; + /* AdRotLevel *xxx = _rotLevels[i]; int j = _rotLevels.getSize();*/ if (_rotLevels[i]->_posX < x) prev = _rotLevels[i]; else { @@ -2568,12 +2568,12 @@ float CAdScene::getRotationAt(int x, int y) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::handleItemAssociations(const char *itemName, bool show) { +bool AdScene::handleItemAssociations(const char *itemName, bool show) { for (int i = 0; i < _layers.getSize(); i++) { - CAdLayer *layer = _layers[i]; + AdLayer *layer = _layers[i]; for (int j = 0; j < layer->_nodes.getSize(); j++) { if (layer->_nodes[j]->_type == OBJECT_ENTITY) { - CAdEntity *ent = layer->_nodes[j]->_entity; + AdEntity *ent = layer->_nodes[j]->_entity; if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; } @@ -2582,7 +2582,7 @@ bool CAdScene::handleItemAssociations(const char *itemName, bool show) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i]->_type == OBJECT_ENTITY) { - CAdEntity *ent = (CAdEntity *)_objects[i]; + AdEntity *ent = (AdEntity *)_objects[i]; if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; } } @@ -2592,11 +2592,11 @@ bool CAdScene::handleItemAssociations(const char *itemName, bool show) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::getRegionsAt(int x, int y, CAdRegion **regionList, int numRegions) { +bool AdScene::getRegionsAt(int x, int y, AdRegion **regionList, int numRegions) { int numUsed = 0; if (_mainLayer) { for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { - CAdSceneNode *node = _mainLayer->_nodes[i]; + AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { if (numUsed < numRegions - 1) { regionList[numUsed] = node->_region; @@ -2613,14 +2613,14 @@ bool CAdScene::getRegionsAt(int x, int y, CAdRegion **regionList, int numRegions } ////////////////////////////////////////////////////////////////////////// -bool CAdScene::restoreDeviceObjects() { +bool AdScene::restoreDeviceObjects() { return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -CBObject *CAdScene::getNextAccessObject(CBObject *currObject) { - CBArray objects; +BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) { + BaseArray objects; getSceneObjects(objects, true); if (objects.getSize() == 0) return NULL; @@ -2639,8 +2639,8 @@ CBObject *CAdScene::getNextAccessObject(CBObject *currObject) { } ////////////////////////////////////////////////////////////////////////// -CBObject *CAdScene::getPrevAccessObject(CBObject *currObject) { - CBArray objects; +BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { + BaseArray objects; getSceneObjects(objects, true); if (objects.getSize() == 0) return NULL; @@ -2660,24 +2660,24 @@ CBObject *CAdScene::getPrevAccessObject(CBObject *currObject) { ////////////////////////////////////////////////////////////////////////// -bool CAdScene::getSceneObjects(CBArray &objects, bool interactiveOnly) { +bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOnly) { for (int i = 0; i < _layers.getSize(); i++) { // close-up layer -> remove everything below it if (interactiveOnly && _layers[i]->_closeUp) objects.removeAll(); for (int j = 0; j < _layers[i]->_nodes.getSize(); j++) { - CAdSceneNode *node = _layers[i]->_nodes[j]; + AdSceneNode *node = _layers[i]->_nodes[j]; switch (node->_type) { case OBJECT_ENTITY: { - CAdEntity *ent = node->_entity; + AdEntity *ent = node->_entity; if (ent->_active && (ent->_registrable || !interactiveOnly)) objects.add(ent); } break; case OBJECT_REGION: { - CBArray regionObj; + BaseArray regionObj; getRegionObjects(node->_region, regionObj, interactiveOnly); for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { bool found = false; @@ -2693,14 +2693,14 @@ bool CAdScene::getSceneObjects(CBArray &objects, bool } break; default: - warning("CAdScene::GetSceneObjects - Unhandled enum"); + warning("AdScene::GetSceneObjects - Unhandled enum"); break; } } } // objects outside any region - CBArray regionObj; + BaseArray regionObj; getRegionObjects(NULL, regionObj, interactiveOnly); for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { bool found = false; @@ -2719,9 +2719,9 @@ bool CAdScene::getSceneObjects(CBArray &objects, bool ////////////////////////////////////////////////////////////////////////// -bool CAdScene::getRegionObjects(CAdRegion *region, CBArray &objects, bool interactiveOnly) { - CAdGame *adGame = (CAdGame *)_gameRef; - CAdObject *obj; +bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, bool interactiveOnly) { + AdGame *adGame = (AdGame *)_gameRef; + AdObject *obj; // global objects for (int i = 0; i < adGame->_objects.getSize(); i++) { @@ -2744,7 +2744,7 @@ bool CAdScene::getRegionObjects(CAdRegion *region, CBArray &Objects, bool InteractiveOnly); - bool getRegionObjects(CAdRegion *Region, CBArray &Objects, bool InteractiveOnly); + BaseObject *getNextAccessObject(BaseObject *CurrObject); + BaseObject *getPrevAccessObject(BaseObject *CurrObject); + bool getSceneObjects(BaseArray &Objects, bool InteractiveOnly); + bool getRegionObjects(AdRegion *Region, BaseArray &Objects, bool InteractiveOnly); bool afterLoad(); - bool getRegionsAt(int X, int Y, CAdRegion **RegionList, int NumRegions); + bool getRegionsAt(int X, int Y, AdRegion **RegionList, int NumRegions); bool handleItemAssociations(const char *ItemName, bool Show); - CUIWindow *_shieldWindow; + UIWindow *_shieldWindow; float getRotationAt(int X, int Y); bool loadState(); bool saveState(); bool _persistentState; bool _persistentStateSprites; - CBObject *getNodeByName(const char *name); + BaseObject *getNodeByName(const char *name); void setOffset(int OffsetLeft, int OffsetTop); bool pointInViewport(int X, int Y); int getOffsetTop(); int getOffsetLeft(); bool getViewportSize(int *Width = NULL, int *Height = NULL); bool getViewportOffset(int *OffsetX = NULL, int *OffsetY = NULL); - CBViewport *_viewport; - CBFader *_fader; + BaseViewport *_viewport; + BaseFader *_fader; int _pfPointsNum; void pfPointsAdd(int X, int Y, int Distance); void pfPointsStart(); bool _initialized; - bool correctTargetPoint(int StartX, int StartY, int *X, int *Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); - bool correctTargetPoint2(int StartX, int StartY, int *TargetX, int *TargetY, bool CheckFreeObjects, CBObject *Requester); - DECLARE_PERSISTENT(CAdScene, CBObject) - bool displayRegionContent(CAdRegion *Region = NULL, bool Display3DOnly = false); - bool displayRegionContentOld(CAdRegion *Region = NULL); + bool correctTargetPoint(int StartX, int StartY, int *X, int *Y, bool CheckFreeObjects = false, BaseObject *Requester = NULL); + bool correctTargetPoint2(int StartX, int StartY, int *TargetX, int *TargetY, bool CheckFreeObjects, BaseObject *Requester); + DECLARE_PERSISTENT(AdScene, BaseObject) + bool displayRegionContent(AdRegion *Region = NULL, bool Display3DOnly = false); + bool displayRegionContentOld(AdRegion *Region = NULL); static int compareObjs(const void *Obj1, const void *Obj2); bool updateFreeObjects(); @@ -87,14 +87,14 @@ public: float getScaleAt(int Y); bool sortScaleLevels(); bool sortRotLevels(); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); uint32 getAlphaAt(int X, int Y, bool ColorCheck = false); bool _paralaxScrolling; void skipTo(int OffsetX, int OffsetY); void setDefaults(); void cleanup(); - void skipToObject(CBObject *Object); - void scrollToObject(CBObject *Object); + void skipToObject(BaseObject *Object); + void scrollToObject(BaseObject *Object); void scrollTo(int OffsetX, int OffsetY); virtual bool update(); bool _autoScroll; @@ -113,22 +113,22 @@ public: uint32 _pfMaxTime; bool initLoop(); void pathFinderStep(); - bool isBlockedAt(int X, int Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); - bool isWalkableAt(int X, int Y, bool CheckFreeObjects = false, CBObject *Requester = NULL); - CAdLayer *_mainLayer; + bool isBlockedAt(int X, int Y, bool CheckFreeObjects = false, BaseObject *Requester = NULL); + bool isWalkableAt(int X, int Y, bool CheckFreeObjects = false, BaseObject *Requester = NULL); + AdLayer *_mainLayer; float getZoomAt(int X, int Y); - bool getPath(CBPoint source, CBPoint target, CAdPath *path, CBObject *requester = NULL); - CAdScene(CBGame *inGame); - virtual ~CAdScene(); - CBArray _layers; - CBArray _objects; - CBArray _waypointGroups; + bool getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester = NULL); + AdScene(BaseGame *inGame); + virtual ~AdScene(); + BaseArray _layers; + BaseArray _objects; + BaseArray _waypointGroups; bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); int _width; int _height; - bool addObject(CAdObject *Object); - bool removeObject(CAdObject *Object); + bool addObject(AdObject *Object); + bool removeObject(AdObject *Object); int _editorMarginH; int _editorMarginV; uint32 _editorColFrame; @@ -149,27 +149,27 @@ public: bool _editorShowDecor; bool _editorShowEntities; bool _editorShowScale; - CBArray _scaleLevels; - CBArray _rotLevels; + BaseArray _scaleLevels; + BaseArray _rotLevels; virtual bool restoreDeviceObjects(); - int getPointsDist(CBPoint p1, CBPoint p2, CBObject *requester = NULL); + int getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester = NULL); // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); private: bool persistState(bool Saving = true); - void pfAddWaypointGroup(CAdWaypointGroup *Wpt, CBObject *Requester = NULL); + void pfAddWaypointGroup(AdWaypointGroup *Wpt, BaseObject *Requester = NULL); bool _pfReady; - CBPoint *_pfTarget; - CAdPath *_pfTargetPath; - CBObject *_pfRequester; - CBArray _pfPath; + BasePoint *_pfTarget; + AdPath *_pfTargetPath; + BaseObject *_pfRequester; + BaseArray _pfPath; int _offsetTop; int _offsetLeft; diff --git a/engines/wintermute/ad/ad_scene_node.cpp b/engines/wintermute/ad/ad_scene_node.cpp index da7082105f..dbf68ff0ca 100644 --- a/engines/wintermute/ad/ad_scene_node.cpp +++ b/engines/wintermute/ad/ad_scene_node.cpp @@ -32,10 +32,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdSceneNode, false) +IMPLEMENT_PERSISTENT(AdSceneNode, false) ////////////////////////////////////////////////////////////////////////// -CAdSceneNode::CAdSceneNode(CBGame *inGame): CBObject(inGame) { +AdSceneNode::AdSceneNode(BaseGame *inGame): BaseObject(inGame) { _type = OBJECT_NONE; _region = NULL; _entity = NULL; @@ -43,7 +43,7 @@ CAdSceneNode::CAdSceneNode(CBGame *inGame): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdSceneNode::~CAdSceneNode() { +AdSceneNode::~AdSceneNode() { _gameRef->unregisterObject(_region); _region = NULL; @@ -53,7 +53,7 @@ CAdSceneNode::~CAdSceneNode() { ////////////////////////////////////////////////////////////////////////// -bool CAdSceneNode::setEntity(CAdEntity *entity) { +bool AdSceneNode::setEntity(AdEntity *entity) { _type = OBJECT_ENTITY; _entity = entity; return _gameRef->registerObject(entity); @@ -61,7 +61,7 @@ bool CAdSceneNode::setEntity(CAdEntity *entity) { ////////////////////////////////////////////////////////////////////////// -bool CAdSceneNode::setRegion(CAdRegion *region) { +bool AdSceneNode::setRegion(AdRegion *region) { _type = OBJECT_REGION; _region = region; return _gameRef->registerObject(region); @@ -69,9 +69,9 @@ bool CAdSceneNode::setRegion(CAdRegion *region) { ////////////////////////////////////////////////////////////////////////// -bool CAdSceneNode::persist(CBPersistMgr *persistMgr) { +bool AdSceneNode::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_entity)); persistMgr->transfer(TMEMBER(_region)); diff --git a/engines/wintermute/ad/ad_scene_node.h b/engines/wintermute/ad/ad_scene_node.h index 1c25f91a2d..b56c351bc8 100644 --- a/engines/wintermute/ad/ad_scene_node.h +++ b/engines/wintermute/ad/ad_scene_node.h @@ -36,16 +36,16 @@ namespace WinterMute { -class CAdSceneNode : public CBObject { +class AdSceneNode : public BaseObject { public: - DECLARE_PERSISTENT(CAdSceneNode, CBObject) - bool setRegion(CAdRegion *region); - bool setEntity(CAdEntity *entity); - CAdEntity *_entity; - CAdRegion *_region; + DECLARE_PERSISTENT(AdSceneNode, BaseObject) + bool setRegion(AdRegion *region); + bool setEntity(AdEntity *entity); + AdEntity *_entity; + AdRegion *_region; TObjectType _type; - CAdSceneNode(CBGame *inGame); - virtual ~CAdSceneNode(); + AdSceneNode(BaseGame *inGame); + virtual ~AdSceneNode(); }; diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index 2ac36054a5..da7b417470 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -35,16 +35,16 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdSceneState, false) +IMPLEMENT_PERSISTENT(AdSceneState, false) ////////////////////////////////////////////////////////////////////////// -CAdSceneState::CAdSceneState(CBGame *inGame): CBBase(inGame) { +AdSceneState::AdSceneState(BaseGame *inGame): BaseClass(inGame) { _filename = NULL; } ////////////////////////////////////////////////////////////////////////// -CAdSceneState::~CAdSceneState() { +AdSceneState::~AdSceneState() { delete[] _filename; _filename = NULL; @@ -54,7 +54,7 @@ CAdSceneState::~CAdSceneState() { ////////////////////////////////////////////////////////////////////////// -bool CAdSceneState::persist(CBPersistMgr *persistMgr) { +bool AdSceneState::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_filename)); _nodeStates.persist(persistMgr); @@ -63,7 +63,7 @@ bool CAdSceneState::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -void CAdSceneState::setFilename(const char *filename) { +void AdSceneState::setFilename(const char *filename) { delete[] _filename; _filename = new char [strlen(filename) + 1]; if (_filename) strcpy(_filename, filename); @@ -71,13 +71,13 @@ void CAdSceneState::setFilename(const char *filename) { ////////////////////////////////////////////////////////////////////////// -CAdNodeState *CAdSceneState::getNodeState(char *name, bool saving) { +AdNodeState *AdSceneState::getNodeState(char *name, bool saving) { for (int i = 0; i < _nodeStates.getSize(); i++) { if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) return _nodeStates[i]; } if (saving) { - CAdNodeState *ret = new CAdNodeState(_gameRef); + AdNodeState *ret = new AdNodeState(_gameRef); ret->setName(name); _nodeStates.add(ret); diff --git a/engines/wintermute/ad/ad_scene_state.h b/engines/wintermute/ad/ad_scene_state.h index 6df20e0578..7231ba52db 100644 --- a/engines/wintermute/ad/ad_scene_state.h +++ b/engines/wintermute/ad/ad_scene_state.h @@ -34,16 +34,16 @@ #include "engines/wintermute/coll_templ.h" namespace WinterMute { -class CAdNodeState; -class CAdSceneState : public CBBase { +class AdNodeState; +class AdSceneState : public BaseClass { public: - CAdNodeState *getNodeState(char *name, bool saving); + AdNodeState *getNodeState(char *name, bool saving); void setFilename(const char *filename); - DECLARE_PERSISTENT(CAdSceneState, CBBase) - CAdSceneState(CBGame *inGame); - virtual ~CAdSceneState(); + DECLARE_PERSISTENT(AdSceneState, BaseClass) + AdSceneState(BaseGame *inGame); + virtual ~AdSceneState(); char *_filename; - CBArray _nodeStates; + BaseArray _nodeStates; }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index 2607993aa0..ba59f57451 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -41,10 +41,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdSentence, false) +IMPLEMENT_PERSISTENT(AdSentence, false) ////////////////////////////////////////////////////////////////////////// -CAdSentence::CAdSentence(CBGame *inGame): CBBase(inGame) { +AdSentence::AdSentence(BaseGame *inGame): BaseClass(inGame) { _text = NULL; _stances = NULL; _tempStance = NULL; @@ -72,7 +72,7 @@ CAdSentence::CAdSentence(CBGame *inGame): CBBase(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdSentence::~CAdSentence() { +AdSentence::~AdSentence() { delete _sound; delete[] _text; delete[] _stances; @@ -91,7 +91,7 @@ CAdSentence::~CAdSentence() { ////////////////////////////////////////////////////////////////////////// -void CAdSentence::setText(const char *text) { +void AdSentence::setText(const char *text) { if (_text) delete [] _text; _text = new char[strlen(text) + 1]; if (_text) strcpy(_text, text); @@ -99,7 +99,7 @@ void CAdSentence::setText(const char *text) { ////////////////////////////////////////////////////////////////////////// -void CAdSentence::setStances(const char *stances) { +void AdSentence::setStances(const char *stances) { if (_stances) delete [] _stances; if (stances) { _stances = new char[strlen(stances) + 1]; @@ -109,20 +109,20 @@ void CAdSentence::setStances(const char *stances) { ////////////////////////////////////////////////////////////////////////// -char *CAdSentence::getCurrentStance() { +char *AdSentence::getCurrentStance() { return getStance(_currentStance); } ////////////////////////////////////////////////////////////////////////// -char *CAdSentence::getNextStance() { +char *AdSentence::getNextStance() { _currentStance++; return getStance(_currentStance); } ////////////////////////////////////////////////////////////////////////// -char *CAdSentence::getStance(int stance) { +char *AdSentence::getStance(int stance) { if (_stances == NULL) return NULL; if (_tempStance) delete [] _tempStance; @@ -165,7 +165,7 @@ char *CAdSentence::getStance(int stance) { ////////////////////////////////////////////////////////////////////////// -bool CAdSentence::display() { +bool AdSentence::display() { if (!_font || !_text) return STATUS_FAILED; if (_sound && !_soundStarted) { @@ -178,8 +178,8 @@ bool CAdSentence::display() { int y = _pos.y; if (!_fixedPos) { - x = x - ((CAdGame *)_gameRef)->_scene->getOffsetLeft(); - y = y - ((CAdGame *)_gameRef)->_scene->getOffsetTop(); + x = x - ((AdGame *)_gameRef)->_scene->getOffsetLeft(); + y = y - ((AdGame *)_gameRef)->_scene->getOffsetTop(); } @@ -195,7 +195,7 @@ bool CAdSentence::display() { ////////////////////////////////////////////////////////////////////////// -void CAdSentence::setSound(CBSound *sound) { +void AdSentence::setSound(BaseSound *sound) { if (!sound) return; delete _sound; _sound = sound; @@ -204,14 +204,14 @@ void CAdSentence::setSound(CBSound *sound) { ////////////////////////////////////////////////////////////////////////// -bool CAdSentence::finish() { +bool AdSentence::finish() { if (_sound) _sound->stop(); return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool CAdSentence::persist(CBPersistMgr *persistMgr) { +bool AdSentence::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_gameRef)); @@ -238,7 +238,7 @@ bool CAdSentence::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -bool CAdSentence::setupTalkFile(const char *soundFilename) { +bool AdSentence::setupTalkFile(const char *soundFilename) { delete _talkDef; _talkDef = NULL; _currentSprite = NULL; @@ -257,7 +257,7 @@ bool CAdSentence::setupTalkFile(const char *soundFilename) { } else return STATUS_OK; // no talk def file found - _talkDef = new CAdTalkDef(_gameRef); + _talkDef = new AdTalkDef(_gameRef); if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { delete _talkDef; _talkDef = NULL; @@ -270,7 +270,7 @@ bool CAdSentence::setupTalkFile(const char *soundFilename) { ////////////////////////////////////////////////////////////////////////// -bool CAdSentence::update(TDirection dir) { +bool AdSentence::update(TDirection dir) { if (!_talkDef) return STATUS_OK; uint32 currentTime; @@ -287,7 +287,7 @@ bool CAdSentence::update(TDirection dir) { if (_talkDef->_nodes[i]->isInTimeInterval(currentTime, dir)) { talkNodeFound = true; - CBSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); + BaseSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); if (newSprite != _currentSprite) newSprite->reset(); _currentSprite = newSprite; @@ -298,7 +298,7 @@ bool CAdSentence::update(TDirection dir) { // no talk node, try to use default sprite instead (if any) if (!talkNodeFound) { - CBSprite *newSprite = _talkDef->getDefaultSprite(dir); + BaseSprite *newSprite = _talkDef->getDefaultSprite(dir); if (newSprite) { if (newSprite != _currentSprite) newSprite->reset(); _currentSprite = newSprite; @@ -309,7 +309,7 @@ bool CAdSentence::update(TDirection dir) { } ////////////////////////////////////////////////////////////////////////// -bool CAdSentence::CanSkip() { +bool AdSentence::CanSkip() { // prevent accidental sentence skipping (TODO make configurable) return (_gameRef->_timer - _startTime) > 300; } diff --git a/engines/wintermute/ad/ad_sentence.h b/engines/wintermute/ad/ad_sentence.h index 40f99ea830..6883bd8893 100644 --- a/engines/wintermute/ad/ad_sentence.h +++ b/engines/wintermute/ad/ad_sentence.h @@ -37,28 +37,28 @@ #include "common/rect.h" namespace WinterMute { -class CAdTalkDef; -class CBFont; -class CBSprite; -class CBSound; -class CAdSentence : public CBBase { +class AdTalkDef; +class BaseFont; +class BaseSprite; +class BaseSound; +class AdSentence : public BaseClass { public: bool _freezable; bool _fixedPos; - CBSprite *_currentSprite; + BaseSprite *_currentSprite; char *_currentSkelAnim; bool update(TDirection dir = DI_DOWN); bool setupTalkFile(const char *soundFilename); - DECLARE_PERSISTENT(CAdSentence, CBBase) + DECLARE_PERSISTENT(AdSentence, BaseClass) bool finish(); - void setSound(CBSound *Sound); + void setSound(BaseSound *Sound); bool _soundStarted; - CBSound *_sound; + BaseSound *_sound; TTextAlign _align; bool display(); int _width; Point32 _pos; - CBFont *_font; + BaseFont *_font; char *getNextStance(); char *getCurrentStance(); void setStances(const char *stances); @@ -68,9 +68,9 @@ public: char *_stances; char *_text; uint32 _duration; - CAdSentence(CBGame *inGame); - virtual ~CAdSentence(); - CAdTalkDef *_talkDef; + AdSentence(BaseGame *inGame); + virtual ~AdSentence(); + AdTalkDef *_talkDef; bool CanSkip(); diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index f0925c6913..b594bd0467 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -35,10 +35,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdSpriteSet, false) +IMPLEMENT_PERSISTENT(AdSpriteSet, false) ////////////////////////////////////////////////////////////////////////// -CAdSpriteSet::CAdSpriteSet(CBGame *inGame, CBObject *owner): CBObject(inGame) { +AdSpriteSet::AdSpriteSet(BaseGame *inGame, BaseObject *owner): BaseObject(inGame) { _owner = owner; for (int i = 0; i < NUM_DIRECTIONS; i++) @@ -47,7 +47,7 @@ CAdSpriteSet::CAdSpriteSet(CBGame *inGame, CBObject *owner): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdSpriteSet::~CAdSpriteSet() { +AdSpriteSet::~AdSpriteSet() { for (int i = 0; i < NUM_DIRECTIONS; i++) { delete _sprites[i]; _sprites[i] = NULL; @@ -58,10 +58,10 @@ CAdSpriteSet::~CAdSpriteSet() { ////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) { +bool AdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdSpriteSet::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdSpriteSet::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -90,7 +90,7 @@ TOKEN_DEF(TEMPLATE) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType CacheType) { +bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType CacheType) { TOKEN_TABLE_START(commands) TOKEN_TABLE(SPRITESET) TOKEN_TABLE(NAME) @@ -108,7 +108,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SPRITESET) { @@ -118,7 +118,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite buffer = params; } - CBSprite *spr = NULL; + BaseSprite *spr = NULL; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: @@ -132,7 +132,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite case TOKEN_LEFT: delete _sprites[DI_LEFT]; _sprites[DI_LEFT] = NULL; - spr = new CBSprite(_gameRef, _owner); + spr = new BaseSprite(_gameRef, _owner); if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; else _sprites[DI_LEFT] = spr; break; @@ -140,7 +140,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite case TOKEN_RIGHT: delete _sprites[DI_RIGHT]; _sprites[DI_RIGHT] = NULL; - spr = new CBSprite(_gameRef, _owner); + spr = new BaseSprite(_gameRef, _owner); if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; else _sprites[DI_RIGHT] = spr; break; @@ -148,7 +148,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite case TOKEN_UP: delete _sprites[DI_UP]; _sprites[DI_UP] = NULL; - spr = new CBSprite(_gameRef, _owner); + spr = new BaseSprite(_gameRef, _owner); if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; else _sprites[DI_UP] = spr; break; @@ -156,7 +156,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite case TOKEN_DOWN: delete _sprites[DI_DOWN]; _sprites[DI_DOWN] = NULL; - spr = new CBSprite(_gameRef, _owner); + spr = new BaseSprite(_gameRef, _owner); if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; else _sprites[DI_DOWN] = spr; break; @@ -164,7 +164,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite case TOKEN_UP_LEFT: delete _sprites[DI_UPLEFT]; _sprites[DI_UPLEFT] = NULL; - spr = new CBSprite(_gameRef, _owner); + spr = new BaseSprite(_gameRef, _owner); if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; else _sprites[DI_UPLEFT] = spr; break; @@ -172,7 +172,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite case TOKEN_UP_RIGHT: delete _sprites[DI_UPRIGHT]; _sprites[DI_UPRIGHT] = NULL; - spr = new CBSprite(_gameRef, _owner); + spr = new BaseSprite(_gameRef, _owner); if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; else _sprites[DI_UPRIGHT] = spr; break; @@ -180,7 +180,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite case TOKEN_DOWN_LEFT: delete _sprites[DI_DOWNLEFT]; _sprites[DI_DOWNLEFT] = NULL; - spr = new CBSprite(_gameRef, _owner); + spr = new BaseSprite(_gameRef, _owner); if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; else _sprites[DI_DOWNLEFT] = spr; break; @@ -188,7 +188,7 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite case TOKEN_DOWN_RIGHT: delete _sprites[DI_DOWNRIGHT]; _sprites[DI_DOWNRIGHT] = NULL; - spr = new CBSprite(_gameRef, _owner); + spr = new BaseSprite(_gameRef, _owner); if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; else _sprites[DI_DOWNRIGHT] = spr; break; @@ -214,9 +214,9 @@ bool CAdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSprite ////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::persist(CBPersistMgr *persistMgr) { +bool AdSpriteSet::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_owner)); for (int i = 0; i < NUM_DIRECTIONS; i++) { @@ -228,12 +228,12 @@ bool CAdSpriteSet::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -CBSprite *CAdSpriteSet::getSprite(TDirection direction) { +BaseSprite *AdSpriteSet::getSprite(TDirection direction) { int dir = (int)direction; if (dir < 0) dir = 0; if (dir >= NUM_DIRECTIONS) dir = NUM_DIRECTIONS - 1; - CBSprite *ret = NULL; + BaseSprite *ret = NULL; // find nearest set sprite int numSteps = 0; @@ -258,7 +258,7 @@ CBSprite *CAdSpriteSet::getSprite(TDirection direction) { ////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "SPRITESET {\n"); if (_name) buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); for (int i = 0; i < NUM_DIRECTIONS; i++) { @@ -292,7 +292,7 @@ bool CAdSpriteSet::saveAsText(CBDynBuffer *buffer, int indent) { } } - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n"); @@ -300,7 +300,7 @@ bool CAdSpriteSet::saveAsText(CBDynBuffer *buffer, int indent) { } ////////////////////////////////////////////////////////////////////////// -bool CAdSpriteSet::containsSprite(CBSprite *sprite) { +bool AdSpriteSet::containsSprite(BaseSprite *sprite) { if (!sprite) return false; for (int i = 0; i < NUM_DIRECTIONS; i++) { diff --git a/engines/wintermute/ad/ad_sprite_set.h b/engines/wintermute/ad/ad_sprite_set.h index 993832cfa3..196d8a8e3a 100644 --- a/engines/wintermute/ad/ad_sprite_set.h +++ b/engines/wintermute/ad/ad_sprite_set.h @@ -35,18 +35,18 @@ namespace WinterMute { -class CAdSpriteSet : public CBObject { +class AdSpriteSet : public BaseObject { public: - bool containsSprite(CBSprite *sprite); - virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); - CBSprite *getSprite(TDirection direction); - DECLARE_PERSISTENT(CAdSpriteSet, CBObject) - CBObject *_owner; - CAdSpriteSet(CBGame *inGame, CBObject *owner = NULL); - virtual ~CAdSpriteSet(); + bool containsSprite(BaseSprite *sprite); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); + BaseSprite *getSprite(TDirection direction); + DECLARE_PERSISTENT(AdSpriteSet, BaseObject) + BaseObject *_owner; + AdSpriteSet(BaseGame *inGame, BaseObject *owner = NULL); + virtual ~AdSpriteSet(); bool loadFile(const char *filename, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); bool loadBuffer(byte *buffer, bool complete = true, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); - CBSprite *_sprites[NUM_DIRECTIONS]; + BaseSprite *_sprites[NUM_DIRECTIONS]; }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 0cd62df603..979e8b2698 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -39,10 +39,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdTalkDef, false) +IMPLEMENT_PERSISTENT(AdTalkDef, false) ////////////////////////////////////////////////////////////////////////// -CAdTalkDef::CAdTalkDef(CBGame *inGame): CBObject(inGame) { +AdTalkDef::AdTalkDef(BaseGame *inGame): BaseObject(inGame) { _defaultSpriteFilename = NULL; _defaultSprite = NULL; @@ -52,7 +52,7 @@ CAdTalkDef::CAdTalkDef(CBGame *inGame): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdTalkDef::~CAdTalkDef() { +AdTalkDef::~AdTalkDef() { for (int i = 0; i < _nodes.getSize(); i++) delete _nodes[i]; _nodes.removeAll(); @@ -69,16 +69,16 @@ CAdTalkDef::~CAdTalkDef() { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::loadFile(const char *filename) { +bool AdTalkDef::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdTalkDef::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdTalkDef::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } bool ret; - CBUtils::setString(&_filename, filename); + BaseUtils::setString(&_filename, filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); @@ -98,7 +98,7 @@ TOKEN_DEF(DEFAULT_SPRITE) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { +bool AdTalkDef::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(TALK) TOKEN_TABLE(TEMPLATE) @@ -111,7 +111,7 @@ bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_TALK) { @@ -128,7 +128,7 @@ bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ACTION: { - CAdTalkNode *Node = new CAdTalkNode(_gameRef); + AdTalkNode *Node = new AdTalkNode(_gameRef); if (Node && DID_SUCCEED(Node->loadBuffer(params, false))) _nodes.add(Node); else { delete Node; @@ -139,16 +139,16 @@ bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_DEFAULT_SPRITE: - CBUtils::setString(&_defaultSpriteFilename, (char *)params); + BaseUtils::setString(&_defaultSpriteFilename, (char *)params); break; case TOKEN_DEFAULT_SPRITESET_FILE: - CBUtils::setString(&_defaultSpriteSetFilename, (char *)params); + BaseUtils::setString(&_defaultSpriteSetFilename, (char *)params); break; case TOKEN_DEFAULT_SPRITESET: { delete _defaultSpriteSet; - _defaultSpriteSet = new CAdSpriteSet(_gameRef); + _defaultSpriteSet = new AdSpriteSet(_gameRef); if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadBuffer(params, false))) { delete _defaultSpriteSet; _defaultSpriteSet = NULL; @@ -179,12 +179,12 @@ bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { _defaultSpriteSet = NULL; if (_defaultSpriteFilename) { - _defaultSprite = new CBSprite(_gameRef); + _defaultSprite = new BaseSprite(_gameRef); if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) return STATUS_FAILED; } if (_defaultSpriteSetFilename) { - _defaultSpriteSet = new CAdSpriteSet(_gameRef); + _defaultSpriteSet = new AdSpriteSet(_gameRef); if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) return STATUS_FAILED; } @@ -194,9 +194,9 @@ bool CAdTalkDef::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::persist(CBPersistMgr *persistMgr) { +bool AdTalkDef::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_defaultSprite)); persistMgr->transfer(TMEMBER(_defaultSpriteFilename)); @@ -210,7 +210,7 @@ bool CAdTalkDef::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdTalkDef::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "TALK {\n"); if (_defaultSpriteFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); @@ -221,7 +221,7 @@ bool CAdTalkDef::saveAsText(CBDynBuffer *buffer, int indent) { _nodes[i]->saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "\n"); } - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n"); @@ -230,16 +230,16 @@ bool CAdTalkDef::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkDef::loadDefaultSprite() { +bool AdTalkDef::loadDefaultSprite() { if (_defaultSpriteFilename && !_defaultSprite) { - _defaultSprite = new CBSprite(_gameRef); + _defaultSprite = new BaseSprite(_gameRef); if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { delete _defaultSprite; _defaultSprite = NULL; return STATUS_FAILED; } else return STATUS_OK; } else if (_defaultSpriteSetFilename && !_defaultSpriteSet) { - _defaultSpriteSet = new CAdSpriteSet(_gameRef); + _defaultSpriteSet = new AdSpriteSet(_gameRef); if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { delete _defaultSpriteSet; _defaultSpriteSet = NULL; @@ -250,7 +250,7 @@ bool CAdTalkDef::loadDefaultSprite() { ////////////////////////////////////////////////////////////////////////// -CBSprite *CAdTalkDef::getDefaultSprite(TDirection dir) { +BaseSprite *AdTalkDef::getDefaultSprite(TDirection dir) { loadDefaultSprite(); if (_defaultSprite) return _defaultSprite; else if (_defaultSpriteSet) return _defaultSpriteSet->getSprite(dir); diff --git a/engines/wintermute/ad/ad_talk_def.h b/engines/wintermute/ad/ad_talk_def.h index 0811f5b8f5..fa32a81041 100644 --- a/engines/wintermute/ad/ad_talk_def.h +++ b/engines/wintermute/ad/ad_talk_def.h @@ -33,24 +33,24 @@ #include "engines/wintermute/base/base_object.h" namespace WinterMute { -class CAdTalkNode; -class CAdSpriteSet; -class CAdTalkDef : public CBObject { +class AdTalkNode; +class AdSpriteSet; +class AdTalkDef : public BaseObject { public: char *_defaultSpriteSetFilename; - CAdSpriteSet *_defaultSpriteSet; - CBSprite *getDefaultSprite(TDirection Dir); + AdSpriteSet *_defaultSpriteSet; + BaseSprite *getDefaultSprite(TDirection Dir); bool loadDefaultSprite(); - DECLARE_PERSISTENT(CAdTalkDef, CBObject) + DECLARE_PERSISTENT(AdTalkDef, BaseObject) - CAdTalkDef(CBGame *inGame); - virtual ~CAdTalkDef(); + AdTalkDef(BaseGame *inGame); + virtual ~AdTalkDef(); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); - CBArray _nodes; + BaseArray _nodes; char *_defaultSpriteFilename; - CBSprite *_defaultSprite; - virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); + BaseSprite *_defaultSprite; + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 28e62798c2..bd48ac601c 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -40,16 +40,16 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdTalkHolder, false) +IMPLEMENT_PERSISTENT(AdTalkHolder, false) ////////////////////////////////////////////////////////////////////////// -CAdTalkHolder::CAdTalkHolder(CBGame *inGame): CAdObject(inGame) { +AdTalkHolder::AdTalkHolder(BaseGame *inGame): AdObject(inGame) { _sprite = NULL; } ////////////////////////////////////////////////////////////////////////// -CAdTalkHolder::~CAdTalkHolder() { +AdTalkHolder::~AdTalkHolder() { delete _sprite; _sprite = NULL; @@ -63,19 +63,19 @@ CAdTalkHolder::~CAdTalkHolder() { } ////////////////////////////////////////////////////////////////////////// -CBSprite *CAdTalkHolder::getTalkStance(const char *stance) { - CBSprite *ret = NULL; +BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { + BaseSprite *ret = NULL; // forced stance? if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { _forcedTalkAnimUsed = true; delete _animSprite; - _animSprite = new CBSprite(_gameRef, this); + _animSprite = new BaseSprite(_gameRef, this); if (_animSprite) { bool res = _animSprite->loadFile(_forcedTalkAnimName); if (DID_FAIL(res)) { - _gameRef->LOG(res, "CAdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); + _gameRef->LOG(res, "AdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); delete _animSprite; _animSprite = NULL; } else return _animSprite; @@ -119,14 +119,14 @@ CBSprite *CAdTalkHolder::getTalkStance(const char *stance) { ////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// -bool CAdTalkHolder::scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name) { +bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // SetSprite ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "SetSprite") == 0) { stack->correctParams(1); - CScValue *val = stack->pop(); + ScValue *val = stack->pop(); bool setCurrent = false; if (_currentSprite && _currentSprite == _sprite) setCurrent = true; @@ -140,7 +140,7 @@ bool CAdTalkHolder::scCallMethod(CScScript *script, CScStack *stack, CScStack *t stack->pushBool(true); } else { const char *filename = val->getString(); - CBSprite *spr = new CBSprite(_gameRef, this); + BaseSprite *spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile(filename))) { script->runtimeError("SetSprite method failed for file '%s'", filename); stack->pushBool(false); @@ -184,7 +184,7 @@ bool CAdTalkHolder::scCallMethod(CScScript *script, CScStack *stack, CScStack *t const char *filename = stack->pop()->getString(); bool Ex = stack->pop()->getBool(); - CBSprite *spr = new CBSprite(_gameRef, this); + BaseSprite *spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile(filename))) { stack->pushBool(false); script->runtimeError("AddTalkSprite method failed for file '%s'", filename); @@ -255,7 +255,7 @@ bool CAdTalkHolder::scCallMethod(CScScript *script, CScStack *stack, CScStack *t bool setCurrent = false; bool setTemp2 = false; - CBSprite *spr = new CBSprite(_gameRef, this); + BaseSprite *spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile(filename))) { stack->pushBool(false); script->runtimeError("SetTalkSprite method failed for file '%s'", filename); @@ -295,12 +295,12 @@ bool CAdTalkHolder::scCallMethod(CScScript *script, CScStack *stack, CScStack *t return STATUS_OK; } - else return CAdObject::scCallMethod(script, stack, thisStack, name); + else return AdObject::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// -CScValue *CAdTalkHolder::scGetProperty(const char *name) { +ScValue *AdTalkHolder::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -311,12 +311,12 @@ CScValue *CAdTalkHolder::scGetProperty(const char *name) { return _scValue; } - else return CAdObject::scGetProperty(name); + else return AdObject::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdTalkHolder::scSetProperty(const char *name, CScValue *value) { +bool AdTalkHolder::scSetProperty(const char *name, ScValue *value) { /* ////////////////////////////////////////////////////////////////////////// // Item @@ -326,18 +326,18 @@ bool CAdTalkHolder::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else*/ return CAdObject::scSetProperty(name, value); + else*/ return AdObject::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -const char *CAdTalkHolder::scToString() { +const char *AdTalkHolder::scToString() { return "[talk-holder object]"; } ////////////////////////////////////////////////////////////////////////// -bool CAdTalkHolder::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdTalkHolder::saveAsText(BaseDynamicBuffer *buffer, int indent) { for (int i = 0; i < _talkSprites.getSize(); i++) { if (_talkSprites[i]->_filename) buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->_filename); @@ -353,8 +353,8 @@ bool CAdTalkHolder::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkHolder::persist(CBPersistMgr *persistMgr) { - CAdObject::persist(persistMgr); +bool AdTalkHolder::persist(BasePersistenceManager *persistMgr) { + AdObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_sprite)); _talkSprites.persist(persistMgr); diff --git a/engines/wintermute/ad/ad_talk_holder.h b/engines/wintermute/ad/ad_talk_holder.h index 50c2f3504b..8ad8ae1e52 100644 --- a/engines/wintermute/ad/ad_talk_holder.h +++ b/engines/wintermute/ad/ad_talk_holder.h @@ -33,21 +33,21 @@ namespace WinterMute { -class CAdTalkHolder : public CAdObject { +class AdTalkHolder : public AdObject { public: - DECLARE_PERSISTENT(CAdTalkHolder, CAdObject) - virtual CBSprite *getTalkStance(const char *stance); - virtual bool saveAsText(CBDynBuffer *buffer, int indent); - CBSprite *_sprite; - CBArray _talkSprites; - CBArray _talkSpritesEx; - CAdTalkHolder(CBGame *inGame); - virtual ~CAdTalkHolder(); + DECLARE_PERSISTENT(AdTalkHolder, AdObject) + virtual BaseSprite *getTalkStance(const char *stance); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + BaseSprite *_sprite; + BaseArray _talkSprites; + BaseArray _talkSpritesEx; + AdTalkHolder(BaseGame *inGame); + virtual ~AdTalkHolder(); // scripting interface - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); - virtual bool scCallMethod(CScScript *script, CScStack *stack, CScStack *thisStack, const char *name); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); }; diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index 3b82d731c9..5325b1aeff 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -36,10 +36,10 @@ #include "engines/wintermute/utils/utils.h" namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdTalkNode, false) +IMPLEMENT_PERSISTENT(AdTalkNode, false) ////////////////////////////////////////////////////////////////////////// -CAdTalkNode::CAdTalkNode(CBGame *inGame): CBBase(inGame) { +AdTalkNode::AdTalkNode(BaseGame *inGame): BaseClass(inGame) { _sprite = NULL; _spriteFilename = NULL; _spriteSet = NULL; @@ -53,7 +53,7 @@ CAdTalkNode::CAdTalkNode(CBGame *inGame): CBBase(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdTalkNode::~CAdTalkNode() { +AdTalkNode::~AdTalkNode() { delete[] _spriteFilename; delete _sprite; delete[] _spriteSetFilename; @@ -80,7 +80,7 @@ TOKEN_DEF(PRECACHE) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { +bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(ACTION) TOKEN_TABLE(SPRITESET_FILE) @@ -95,7 +95,7 @@ bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTION) { @@ -112,16 +112,16 @@ bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_SPRITE: - CBUtils::setString(&_spriteFilename, (char *)params); + BaseUtils::setString(&_spriteFilename, (char *)params); break; case TOKEN_SPRITESET_FILE: - CBUtils::setString(&_spriteSetFilename, (char *)params); + BaseUtils::setString(&_spriteSetFilename, (char *)params); break; case TOKEN_SPRITESET: { delete _spriteSet; - _spriteSet = new CAdSpriteSet(_gameRef); + _spriteSet = new AdSpriteSet(_gameRef); if (!_spriteSet || DID_FAIL(_spriteSet->loadBuffer(params, false))) { delete _spriteSet; _spriteSet = NULL; @@ -143,7 +143,7 @@ bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_COMMENT: - if (_gameRef->_editorMode) CBUtils::setString(&_comment, (char *)params); + if (_gameRef->_editorMode) BaseUtils::setString(&_comment, (char *)params); break; case TOKEN_EDITOR_PROPERTY: @@ -168,14 +168,14 @@ bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { if (_preCache && _spriteFilename) { delete _sprite; - _sprite = new CBSprite(_gameRef); + _sprite = new BaseSprite(_gameRef); if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) return STATUS_FAILED; } if (_preCache && _spriteSetFilename) { delete _spriteSet; - _spriteSet = new CAdSpriteSet(_gameRef); + _spriteSet = new AdSpriteSet(_gameRef); if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) return STATUS_FAILED; } @@ -186,7 +186,7 @@ bool CAdTalkNode::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::persist(CBPersistMgr *persistMgr) { +bool AdTalkNode::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_comment)); persistMgr->transfer(TMEMBER(_startTime)); persistMgr->transfer(TMEMBER(_endTime)); @@ -201,7 +201,7 @@ bool CAdTalkNode::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdTalkNode::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "ACTION {\n"); if (_comment) buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); buffer->putTextIndent(indent + 2, "START_TIME=%d\n", _startTime); @@ -211,7 +211,7 @@ bool CAdTalkNode::saveAsText(CBDynBuffer *buffer, int indent) { else if (_spriteSet) _spriteSet->saveAsText(buffer, indent + 2); if (_preCache) buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "}\n"); @@ -220,9 +220,9 @@ bool CAdTalkNode::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::loadSprite() { +bool AdTalkNode::loadSprite() { if (_spriteFilename && !_sprite) { - _sprite = new CBSprite(_gameRef); + _sprite = new BaseSprite(_gameRef); if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { delete _sprite; _sprite = NULL; @@ -231,7 +231,7 @@ bool CAdTalkNode::loadSprite() { } else if (_spriteSetFilename && !_spriteSet) { - _spriteSet = new CAdSpriteSet(_gameRef); + _spriteSet = new AdSpriteSet(_gameRef); if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { delete _spriteSet; _spriteSet = NULL; @@ -244,7 +244,7 @@ bool CAdTalkNode::loadSprite() { ////////////////////////////////////////////////////////////////////////// -bool CAdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { +bool AdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { if (time >= _startTime) { if (_playToEnd) { if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) return true; @@ -256,7 +256,7 @@ bool CAdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { ////////////////////////////////////////////////////////////////////////// -CBSprite *CAdTalkNode::getSprite(TDirection dir) { +BaseSprite *AdTalkNode::getSprite(TDirection dir) { loadSprite(); if (_sprite) return _sprite; else if (_spriteSet) return _spriteSet->getSprite(dir); diff --git a/engines/wintermute/ad/ad_talk_node.h b/engines/wintermute/ad/ad_talk_node.h index 55adf88e83..9e599b6af2 100644 --- a/engines/wintermute/ad/ad_talk_node.h +++ b/engines/wintermute/ad/ad_talk_node.h @@ -33,23 +33,23 @@ #include "engines/wintermute/base/base.h" namespace WinterMute { -class CAdSpriteSet; -class CBSprite; -class CAdTalkNode : public CBBase { +class AdSpriteSet; +class BaseSprite; +class AdTalkNode : public BaseClass { public: char *_spriteSetFilename; - CAdSpriteSet *_spriteSet; - CBSprite *getSprite(TDirection dir); + AdSpriteSet *_spriteSet; + BaseSprite *getSprite(TDirection dir); bool isInTimeInterval(uint32 time, TDirection dir); bool loadSprite(); - DECLARE_PERSISTENT(CAdTalkNode, CBBase) + DECLARE_PERSISTENT(AdTalkNode, BaseClass) - CAdTalkNode(CBGame *inGame); - virtual ~CAdTalkNode(); + AdTalkNode(BaseGame *inGame); + virtual ~AdTalkNode(); bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(CBDynBuffer *buffer, int indent = 0); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); char *_spriteFilename; - CBSprite *_sprite; + BaseSprite *_sprite; uint32 _startTime; uint32 _endTime; bool _playToEnd; diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 4a902266ac..25e5345ee7 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -37,10 +37,10 @@ namespace WinterMute { -IMPLEMENT_PERSISTENT(CAdWaypointGroup, false) +IMPLEMENT_PERSISTENT(AdWaypointGroup, false) ////////////////////////////////////////////////////////////////////////// -CAdWaypointGroup::CAdWaypointGroup(CBGame *inGame): CBObject(inGame) { +AdWaypointGroup::AdWaypointGroup(BaseGame *inGame): BaseObject(inGame) { _active = true; _editorSelectedPoint = -1; _lastMimicScale = -1; @@ -49,13 +49,13 @@ CAdWaypointGroup::CAdWaypointGroup(CBGame *inGame): CBObject(inGame) { ////////////////////////////////////////////////////////////////////////// -CAdWaypointGroup::~CAdWaypointGroup() { +AdWaypointGroup::~AdWaypointGroup() { cleanup(); } ////////////////////////////////////////////////////////////////////////// -void CAdWaypointGroup::cleanup() { +void AdWaypointGroup::cleanup() { for (int i = 0; i < _points.getSize(); i++) delete _points[i]; _points.removeAll(); @@ -64,10 +64,10 @@ void CAdWaypointGroup::cleanup() { ////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::loadFile(const char *filename) { +bool AdWaypointGroup::loadFile(const char *filename) { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer == NULL) { - _gameRef->LOG(0, "CAdWaypointGroup::LoadFile failed for file '%s'", filename); + _gameRef->LOG(0, "AdWaypointGroup::LoadFile failed for file '%s'", filename); return STATUS_FAILED; } @@ -96,7 +96,7 @@ TOKEN_DEF(PROPERTY) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::loadBuffer(byte *buffer, bool complete) { +bool AdWaypointGroup::loadBuffer(byte *buffer, bool complete) { TOKEN_TABLE_START(commands) TOKEN_TABLE(WAYPOINTS) TOKEN_TABLE(TEMPLATE) @@ -110,7 +110,7 @@ bool CAdWaypointGroup::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - CBParser parser(_gameRef); + BaseParser parser(_gameRef); if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_WAYPOINTS) { @@ -133,7 +133,7 @@ bool CAdWaypointGroup::loadBuffer(byte *buffer, bool complete) { case TOKEN_POINT: { int x, y; parser.scanStr((char *)params, "%d,%d", &x, &y); - _points.add(new CBPoint(x, y)); + _points.add(new BasePoint(x, y)); } break; @@ -164,7 +164,7 @@ bool CAdWaypointGroup::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::saveAsText(CBDynBuffer *buffer, int indent) { +bool AdWaypointGroup::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "WAYPOINTS {\n"); buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); @@ -172,7 +172,7 @@ bool CAdWaypointGroup::saveAsText(CBDynBuffer *buffer, int indent) { if (_scProp) _scProp->saveAsText(buffer, indent + 2); - CBBase::saveAsText(buffer, indent + 2); + BaseClass::saveAsText(buffer, indent + 2); for (int i = 0; i < _points.getSize(); i++) { buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); @@ -185,9 +185,9 @@ bool CAdWaypointGroup::saveAsText(CBDynBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::persist(CBPersistMgr *persistMgr) { +bool AdWaypointGroup::persist(BasePersistenceManager *persistMgr) { - CBObject::persist(persistMgr); + BaseObject::persist(persistMgr); persistMgr->transfer(TMEMBER(_active)); persistMgr->transfer(TMEMBER(_editorSelectedPoint)); @@ -201,7 +201,7 @@ bool CAdWaypointGroup::persist(CBPersistMgr *persistMgr) { ////////////////////////////////////////////////////////////////////////// -CScValue *CAdWaypointGroup::scGetProperty(const char *name) { +ScValue *AdWaypointGroup::scGetProperty(const char *name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -220,12 +220,12 @@ CScValue *CAdWaypointGroup::scGetProperty(const char *name) { return _scValue; } - else return CBObject::scGetProperty(name); + else return BaseObject::scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::scSetProperty(const char *name, CScValue *value) { +bool AdWaypointGroup::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Active ////////////////////////////////////////////////////////////////////////// @@ -234,12 +234,12 @@ bool CAdWaypointGroup::scSetProperty(const char *name, CScValue *value) { return STATUS_OK; } - else return CBObject::scSetProperty(name, value); + else return BaseObject::scSetProperty(name, value); } ////////////////////////////////////////////////////////////////////////// -bool CAdWaypointGroup::mimic(CAdWaypointGroup *wpt, float scale, int argX, int argY) { +bool AdWaypointGroup::mimic(AdWaypointGroup *wpt, float scale, int argX, int argY) { if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) return STATUS_OK; cleanup(); @@ -248,7 +248,7 @@ bool CAdWaypointGroup::mimic(CAdWaypointGroup *wpt, float scale, int argX, int a int x = (int)((float)wpt->_points[i]->x * scale / 100.0f); int y = (int)((float)wpt->_points[i]->y * scale / 100.0f); - _points.add(new CBPoint(x + argX, y + argY)); + _points.add(new BasePoint(x + argX, y + argY)); } _lastMimicScale = scale; diff --git a/engines/wintermute/ad/ad_waypoint_group.h b/engines/wintermute/ad/ad_waypoint_group.h index 2cece9e88b..f23f7be859 100644 --- a/engines/wintermute/ad/ad_waypoint_group.h +++ b/engines/wintermute/ad/ad_waypoint_group.h @@ -32,25 +32,25 @@ #include "engines/wintermute/base/base_object.h" namespace WinterMute { -class CBPoint; -class CAdWaypointGroup : public CBObject { +class BasePoint; +class AdWaypointGroup : public BaseObject { public: float _lastMimicScale; int _lastMimicX; int _lastMimicY; void cleanup(); - bool mimic(CAdWaypointGroup *wpt, float scale = 100.0f, int x = 0, int y = 0); - DECLARE_PERSISTENT(CAdWaypointGroup, CBObject) - virtual bool saveAsText(CBDynBuffer *buffer, int indent); + bool mimic(AdWaypointGroup *wpt, float scale = 100.0f, int x = 0, int y = 0); + DECLARE_PERSISTENT(AdWaypointGroup, BaseObject) + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); bool _active; - CAdWaypointGroup(CBGame *inGame); + AdWaypointGroup(BaseGame *inGame); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); - virtual ~CAdWaypointGroup(); - CBArray _points; + virtual ~AdWaypointGroup(); + BaseArray _points; int _editorSelectedPoint; - virtual CScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, CScValue *value); + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); }; } // end of namespace WinterMute -- cgit v1.2.3 From 3bcbd1881c9a22a594707726154c568d187e313b Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 22 Jul 2012 22:27:07 +0200 Subject: WINTERMUTE: Avoid opening files when checking hasFile() --- engines/wintermute/ad/ad_game.cpp | 10 ++-------- engines/wintermute/ad/ad_sentence.cpp | 7 ++----- 2 files changed, 4 insertions(+), 13 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index e10ec1bf6d..aa350b0e4c 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -1904,18 +1904,12 @@ char *AdGame::findSpeechFile(char *stringID) { for (int i = 0; i < _speechDirs.getSize(); i++) { sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); - Common::SeekableReadStream *file = _fileManager->openFile(ret); // TODO: Replace with hasFile - if (file) { - _fileManager->closeFile(file); + if (_fileManager->hasFile(ret)) return ret; - } sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); - file = _fileManager->openFile(ret); - if (file) { - _fileManager->closeFile(file); + if (_fileManager->hasFile(ret)) return ret; - } } delete [] ret; return NULL; diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index ba59f57451..ad3a291e16 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -251,11 +251,8 @@ bool AdSentence::setupTalkFile(const char *soundFilename) { AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); - Common::SeekableReadStream *file = _gameRef->_fileManager->openFile(talkDefFileName.c_str()); - if (file) { - _gameRef->_fileManager->closeFile(file); - } else return STATUS_OK; // no talk def file found - + if (!_gameRef->_fileManager->hasFile(talkDefFileName)) + return STATUS_OK; // no talk def file found _talkDef = new AdTalkDef(_gameRef); if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { -- cgit v1.2.3 From f6a5a2a0d57d2e0829aa93ac0b30d3c0e1bf8838 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 22 Jul 2012 22:55:54 +0200 Subject: WINTERMUTE: Wrap away base_script_holder's _filename field in getters/setters, avoiding direct writes. --- engines/wintermute/ad/ad_actor.cpp | 3 +-- engines/wintermute/ad/ad_entity.cpp | 15 +++++++-------- engines/wintermute/ad/ad_game.cpp | 5 ++--- engines/wintermute/ad/ad_inventory_box.cpp | 3 +-- engines/wintermute/ad/ad_item.cpp | 15 +++++++-------- engines/wintermute/ad/ad_layer.cpp | 3 +-- engines/wintermute/ad/ad_node_state.cpp | 10 +++++----- engines/wintermute/ad/ad_object.cpp | 2 +- engines/wintermute/ad/ad_region.cpp | 3 +-- engines/wintermute/ad/ad_response_box.cpp | 15 +++++++-------- engines/wintermute/ad/ad_rot_level.cpp | 3 +-- engines/wintermute/ad/ad_scale_level.cpp | 3 +-- engines/wintermute/ad/ad_scene.cpp | 12 ++++-------- engines/wintermute/ad/ad_sprite_set.cpp | 16 ++++++++-------- engines/wintermute/ad/ad_talk_def.cpp | 2 +- engines/wintermute/ad/ad_talk_holder.cpp | 16 ++++++++-------- engines/wintermute/ad/ad_waypoint_group.cpp | 3 +-- 17 files changed, 57 insertions(+), 72 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index 1da28cd93d..c6a9b59420 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -132,8 +132,7 @@ bool AdActor::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 06a551b252..df469b4321 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -93,8 +93,7 @@ bool AdEntity::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ENTITY file '%s'", filename); @@ -914,8 +913,8 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } - if (_subtype == ENTITY_NORMAL && _sprite && _sprite->_filename) - buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->_filename); + if (_subtype == ENTITY_NORMAL && _sprite && _sprite->getFilename()) + buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->getFilename()); if (_subtype == ENTITY_SOUND && _sFX && _sFX->_soundFilename) { buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sFX->_soundFilename); @@ -936,11 +935,11 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { if (_relativeScale != 0) buffer->putTextIndent(indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale); - if (_font && _font->_filename) - buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->_filename); + if (_font && _font->getFilename()) + buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); - if (_cursor && _cursor->_filename) - buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); + if (_cursor && _cursor->getFilename()) + buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); AdTalkHolder::saveAsText(buffer, indent + 2); diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index aa350b0e4c..8010a37864 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -251,7 +251,7 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) { _scene->applyEvent("SceneShutdown", true); setPrevSceneName(_scene->_name); - setPrevSceneFilename(_scene->_filename); + setPrevSceneFilename(_scene->getFilename()); if (!_tempDisableSaveState) _scene->saveState(); _tempDisableSaveState = false; @@ -1112,8 +1112,7 @@ bool AdGame::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index f835dd22d4..d2bdcdde34 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -164,8 +164,7 @@ bool AdInventoryBox::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index 781b924513..0b85fdb9b3 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -93,8 +93,7 @@ bool AdItem::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); @@ -462,8 +461,8 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetHoverSprite") == 0) { stack->correctParams(0); - if (!_spriteHover || !_spriteHover->_filename) stack->pushNULL(); - else stack->pushString(_spriteHover->_filename); + if (!_spriteHover || !_spriteHover->getFilename()) stack->pushNULL(); + else stack->pushString(_spriteHover->getFilename()); return STATUS_OK; } @@ -504,8 +503,8 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetNormalCursor") == 0) { stack->correctParams(0); - if (!_cursorNormal || !_cursorNormal->_filename) stack->pushNULL(); - else stack->pushString(_cursorNormal->_filename); + if (!_cursorNormal || !_cursorNormal->getFilename()) stack->pushNULL(); + else stack->pushString(_cursorNormal->getFilename()); return STATUS_OK; } @@ -547,8 +546,8 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetHoverCursor") == 0) { stack->correctParams(0); - if (!_cursorHover || !_cursorHover->_filename) stack->pushNULL(); - else stack->pushString(_cursorHover->_filename); + if (!_cursorHover || !_cursorHover->getFilename()) stack->pushNULL(); + else stack->pushString(_cursorHover->getFilename()); return STATUS_OK; } diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 2cd7ac26ce..e59b5cde18 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -70,8 +70,7 @@ bool AdLayer::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index 12bd275614..fca2600884 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -139,11 +139,11 @@ bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool s for (int i = 0; i < 7; i++) { if (entity->_caption[i]) setCaption(entity->_caption[i], i); } - if (!entity->_region && entity->_sprite && entity->_sprite->_filename) { - if (includingSprites) setFilename(entity->_sprite->_filename); + if (!entity->_region && entity->_sprite && entity->_sprite->getFilename()) { + if (includingSprites) setFilename(entity->_sprite->getFilename()); else setFilename(""); } - if (entity->_cursor && entity->_cursor->_filename) setCursor(entity->_cursor->_filename); + if (entity->_cursor && entity->_cursor->getFilename()) setCursor(entity->_cursor->getFilename()); _alphaColor = entity->_alphaColor; _active = entity->_active; } else { @@ -151,11 +151,11 @@ bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool s if (_caption[i]) entity->setCaption(_caption[i], i); } if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) { - if (!entity->_sprite || !entity->_sprite->_filename || scumm_stricmp(entity->_sprite->_filename, _filename) != 0) + if (!entity->_sprite || !entity->_sprite->getFilename() || scumm_stricmp(entity->_sprite->getFilename(), _filename) != 0) entity->setSprite(_filename); } if (_cursor) { - if (!entity->_cursor || !entity->_cursor->_filename || scumm_stricmp(entity->_cursor->_filename, _cursor) != 0) + if (!entity->_cursor || !entity->_cursor->getFilename() || scumm_stricmp(entity->_cursor->getFilename(), _cursor) != 0) entity->setCursor(_cursor); } diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index 39593c482c..bac39f5ea6 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -339,7 +339,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetFont") == 0) { stack->correctParams(0); - if (_font && _font->_filename) stack->pushString(_font->_filename); + if (_font && _font->getFilename()) stack->pushString(_font->getFilename()); else stack->pushNULL(); return STATUS_OK; } diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 1bd6051bda..bac02f5dd6 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -63,8 +63,7 @@ bool AdRegion::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 5b7e441abc..212802ef3a 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -196,8 +196,7 @@ bool AdResponseBox::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); @@ -341,13 +340,13 @@ bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _responseArea.left, _responseArea.top, _responseArea.right, _responseArea.bottom); - if (_font && _font->_filename) - buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->_filename); - if (_fontHover && _fontHover->_filename) - buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->_filename); + if (_font && _font->getFilename()) + buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); + if (_fontHover && _fontHover->getFilename()) + buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->getFilename()); - if (_cursor && _cursor->_filename) - buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->_filename); + if (_cursor && _cursor->getFilename()) + buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); buffer->putTextIndent(indent + 2, "HORIZONTAL=%s\n", _horizontal ? "TRUE" : "FALSE"); diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index e758eaa1f6..b9949d9f9b 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -62,8 +62,7 @@ bool AdRotLevel::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index 65e0cc4663..539e9a8bb7 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -60,8 +60,7 @@ bool AdScaleLevel::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 104fe6dd4d..958bf64ae5 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -509,15 +509,11 @@ bool AdScene::loadFile(const char *filename) { bool ret; - delete[] _filename; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); - + setFilename(filename); delete [] buffer; @@ -843,7 +839,7 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { return STATUS_FAILED; } - if (_mainLayer == NULL) _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", _filename); + if (_mainLayer == NULL) _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", getFilename()); sortScaleLevels(); @@ -2480,7 +2476,7 @@ bool AdScene::persistState(bool saving) { if (!_persistentState) return STATUS_OK; AdGame *adGame = (AdGame *)_gameRef; - AdSceneState *state = adGame->getSceneState(_filename, saving); + AdSceneState *state = adGame->getSceneState(getFilename(), saving); if (!state) return STATUS_OK; AdNodeState *nodeState; diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index b594bd0467..34ea53481d 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -265,28 +265,28 @@ bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { if (_sprites[i]) { switch (i) { case DI_UP: - buffer->putTextIndent(indent + 2, "UP=\"%s\"\n", _sprites[i]->_filename); + buffer->putTextIndent(indent + 2, "UP=\"%s\"\n", _sprites[i]->getFilename()); break; case DI_UPRIGHT: - buffer->putTextIndent(indent + 2, "UP_RIGHT=\"%s\"\n", _sprites[i]->_filename); + buffer->putTextIndent(indent + 2, "UP_RIGHT=\"%s\"\n", _sprites[i]->getFilename()); break; case DI_RIGHT: - buffer->putTextIndent(indent + 2, "RIGHT=\"%s\"\n", _sprites[i]->_filename); + buffer->putTextIndent(indent + 2, "RIGHT=\"%s\"\n", _sprites[i]->getFilename()); break; case DI_DOWNRIGHT: - buffer->putTextIndent(indent + 2, "DOWN_RIGHT=\"%s\"\n", _sprites[i]->_filename); + buffer->putTextIndent(indent + 2, "DOWN_RIGHT=\"%s\"\n", _sprites[i]->getFilename()); break; case DI_DOWN: - buffer->putTextIndent(indent + 2, "DOWN=\"%s\"\n", _sprites[i]->_filename); + buffer->putTextIndent(indent + 2, "DOWN=\"%s\"\n", _sprites[i]->getFilename()); break; case DI_DOWNLEFT: - buffer->putTextIndent(indent + 2, "DOWN_LEFT=\"%s\"\n", _sprites[i]->_filename); + buffer->putTextIndent(indent + 2, "DOWN_LEFT=\"%s\"\n", _sprites[i]->getFilename()); break; case DI_LEFT: - buffer->putTextIndent(indent + 2, "LEFT=\"%s\"\n", _sprites[i]->_filename); + buffer->putTextIndent(indent + 2, "LEFT=\"%s\"\n", _sprites[i]->getFilename()); break; case DI_UPLEFT: - buffer->putTextIndent(indent + 2, "UP_LEFT=\"%s\"\n", _sprites[i]->_filename); + buffer->putTextIndent(indent + 2, "UP_LEFT=\"%s\"\n", _sprites[i]->getFilename()); break; } } diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 979e8b2698..2756b69467 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -78,7 +78,7 @@ bool AdTalkDef::loadFile(const char *filename) { bool ret; - BaseUtils::setString(&_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index bd48ac601c..17f7171cc3 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -159,8 +159,8 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS else if (strcmp(name, "GetSprite") == 0) { stack->correctParams(0); - if (!_sprite || !_sprite->_filename) stack->pushNULL(); - else stack->pushString(_sprite->_filename); + if (!_sprite || !_sprite->getFilename()) stack->pushNULL(); + else stack->pushString(_sprite->getFilename()); return STATUS_OK; } @@ -210,7 +210,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS if (ex) { for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->_filename, filename) == 0) { + if (scumm_stricmp(_talkSpritesEx[i]->getFilename(), filename) == 0) { if (_currentSprite == _talkSpritesEx[i]) setCurrent = true; if (_tempSprite2 == _talkSpritesEx[i]) @@ -222,7 +222,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } } else { for (int i = 0; i < _talkSprites.getSize(); i++) { - if (scumm_stricmp(_talkSprites[i]->_filename, filename) == 0) { + if (scumm_stricmp(_talkSprites[i]->getFilename(), filename) == 0) { if (_currentSprite == _talkSprites[i]) setCurrent = true; if (_tempSprite2 == _talkSprites[i]) @@ -339,13 +339,13 @@ const char *AdTalkHolder::scToString() { ////////////////////////////////////////////////////////////////////////// bool AdTalkHolder::saveAsText(BaseDynamicBuffer *buffer, int indent) { for (int i = 0; i < _talkSprites.getSize(); i++) { - if (_talkSprites[i]->_filename) - buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->_filename); + if (_talkSprites[i]->getFilename()) + buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->getFilename()); } for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (_talkSpritesEx[i]->_filename) - buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->_filename); + if (_talkSpritesEx[i]->getFilename()) + buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->getFilename()); } return STATUS_OK; diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 25e5345ee7..4a8ab966e8 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -73,8 +73,7 @@ bool AdWaypointGroup::loadFile(const char *filename) { bool ret; - _filename = new char [strlen(filename) + 1]; - strcpy(_filename, filename); + setFilename(filename); if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); -- cgit v1.2.3 From 8c378f794e0398e646eb3598c9e27c09b4d68dfc Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 22 Jul 2012 23:17:32 +0200 Subject: WINTERMUTE: Wrap _name in base_named_object in getters/setters. --- engines/wintermute/ad/ad_actor.cpp | 12 ++++++------ engines/wintermute/ad/ad_entity.cpp | 4 ++-- engines/wintermute/ad/ad_game.cpp | 16 ++++++++-------- engines/wintermute/ad/ad_inventory.cpp | 6 +++--- engines/wintermute/ad/ad_inventory_box.cpp | 8 ++++---- engines/wintermute/ad/ad_item.cpp | 2 +- engines/wintermute/ad/ad_layer.cpp | 6 +++--- engines/wintermute/ad/ad_object.cpp | 16 ++++++++-------- engines/wintermute/ad/ad_region.cpp | 4 ++-- engines/wintermute/ad/ad_response_box.cpp | 6 +++--- engines/wintermute/ad/ad_scene.cpp | 22 +++++++++++----------- engines/wintermute/ad/ad_scene_state.cpp | 2 +- engines/wintermute/ad/ad_scene_state.h | 2 +- engines/wintermute/ad/ad_sprite_set.cpp | 2 +- engines/wintermute/ad/ad_talk_holder.cpp | 6 +++--- engines/wintermute/ad/ad_waypoint_group.cpp | 2 +- 16 files changed, 58 insertions(+), 58 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index c6a9b59420..68059072d7 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -940,7 +940,7 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, bool Found = false; for (int i = 0; i < _anims.getSize(); i++) { - if (scumm_stricmp(_anims[i]->_name, AnimName) == 0) { + if (scumm_stricmp(_anims[i]->getName(), AnimName) == 0) { // invalidate sprites in use if (_anims[i]->containsSprite(_tempSprite2)) _tempSprite2 = NULL; if (_anims[i]->containsSprite(_currentSprite)) _currentSprite = NULL; @@ -1109,7 +1109,7 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { if (_animSprite) { bool res = _animSprite->loadFile(_forcedTalkAnimName); if (DID_FAIL(res)) { - _gameRef->LOG(res, "AdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); + _gameRef->LOG(res, "AdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); delete _animSprite; _animSprite = NULL; } else return _animSprite; @@ -1131,7 +1131,7 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { if (!ret) { BaseArray TalkAnims; for (int i = 0; i < _anims.getSize(); i++) { - if (_talkAnimName.compareToIgnoreCase(_anims[i]->_name) == 0) + if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) TalkAnims.add(_anims[i]); } @@ -1156,7 +1156,7 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { if (stance != NULL) { // search special stances for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->_name, stance) == 0) { + if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { ret = _talkSpritesEx[i]->getSprite(_dir); break; } @@ -1164,7 +1164,7 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { if (ret == NULL) { // search generic stances for (int i = 0; i < _talkSprites.getSize(); i++) { - if (scumm_stricmp(_talkSprites[i]->_name, stance) == 0) { + if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { ret = _talkSprites[i]->getSprite(_dir); break; } @@ -1254,7 +1254,7 @@ int AdActor::getHeight() { ////////////////////////////////////////////////////////////////////////// AdSpriteSet *AdActor::getAnimByName(const Common::String &animName) { for (int i = 0; i < _anims.getSize(); i++) { - if (animName.compareToIgnoreCase(_anims[i]->_name) == 0) + if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) return _anims[i]; } return NULL; diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index df469b4321..2a281d0fcb 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -462,7 +462,7 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { } if (_region && _sprite) { - _gameRef->LOG(0, "Warning: Entity '%s' has both sprite and region.", _name); + _gameRef->LOG(0, "Warning: Entity '%s' has both sprite and region.", getName()); } updatePosition(); @@ -878,7 +878,7 @@ const char *AdEntity::scToString() { ////////////////////////////////////////////////////////////////////////// bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "ENTITY {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); if (_subtype == ENTITY_SOUND) buffer->putTextIndent(indent + 2, "SUBTYPE=\"SOUND\"\n"); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 8010a37864..42a453d533 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -250,7 +250,7 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) { } else { _scene->applyEvent("SceneShutdown", true); - setPrevSceneName(_scene->_name); + setPrevSceneName(_scene->getName()); setPrevSceneFilename(_scene->getFilename()); if (!_tempDisableSaveState) _scene->saveState(); @@ -657,7 +657,7 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (val->getNative() == Inv->_takenItems[j]) { stack->pushBool(true); return STATUS_OK; - } else if (scumm_stricmp(val->getString(), Inv->_takenItems[j]->_name) == 0) { + } else if (scumm_stricmp(val->getString(), Inv->_takenItems[j]->getName()) == 0) { stack->pushBool(true); return STATUS_OK; } @@ -1093,7 +1093,7 @@ bool AdGame::showCursor() { _lastCursor = origLastCursor; } if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { - if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->_name)) + if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->getName())) return drawCursor(_selectedItem->_cursorHover); else return drawCursor(_selectedItem->_cursorNormal); @@ -1414,7 +1414,7 @@ bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { if (item && !DID_FAIL(item->loadBuffer(params, false))) { // delete item with the same name, if exists if (merge) { - AdItem *PrevItem = getItemByName(item->_name); + AdItem *PrevItem = getItemByName(item->getName()); if (PrevItem) deleteItem(PrevItem); } addItem(item); @@ -1767,7 +1767,7 @@ bool AdGame::isItemTaken(char *itemName) { AdInventory *Inv = _inventories[i]; for (int j = 0; j < Inv->_takenItems.getSize(); j++) { - if (scumm_stricmp(itemName, Inv->_takenItems[j]->_name) == 0) { + if (scumm_stricmp(itemName, Inv->_takenItems[j]->getName()) == 0) { return true; } } @@ -1778,7 +1778,7 @@ bool AdGame::isItemTaken(char *itemName) { ////////////////////////////////////////////////////////////////////////// AdItem *AdGame::getItemByName(const char *name) { for (int i = 0; i < _items.getSize(); i++) { - if (scumm_stricmp(_items[i]->_name, name) == 0) return _items[i]; + if (scumm_stricmp(_items[i]->getName(), name) == 0) return _items[i]; } return NULL; } @@ -1831,7 +1831,7 @@ bool AdGame::deleteItem(AdItem *item) { if (!item) return STATUS_FAILED; if (_selectedItem == item) _selectedItem = NULL; - _scene->handleItemAssociations(item->_name, false); + _scene->handleItemAssociations(item->getName(), false); // remove from all inventories for (int i = 0; i < _inventories.getSize(); i++) { @@ -2036,7 +2036,7 @@ bool AdGame::displayDebugInfo() { sprintf(str, "Mouse: %d, %d (scene: %d, %d)", _mousePos.x, _mousePos.y, _mousePos.x + _scene->getOffsetLeft(), _mousePos.y + _scene->getOffsetTop()); _systemFont->drawText((byte *)str, 0, 90, _renderer->_width, TAL_RIGHT); - sprintf(str, "Scene: %s (prev: %s)", (_scene && _scene->_name) ? _scene->_name : "???", _prevSceneName ? _prevSceneName : "???"); + sprintf(str, "Scene: %s (prev: %s)", (_scene && _scene->getName()) ? _scene->getName() : "???", _prevSceneName ? _prevSceneName : "???"); _systemFont->drawText((byte *)str, 0, 110, _renderer->_width, TAL_RIGHT); } return BaseGame::displayDebugInfo(); diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index fd56eef419..d79d171d02 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -57,12 +57,12 @@ bool AdInventory::insertItem(const char *name, const char *insertAfter) { int insertIndex = -1; for (int i = 0; i < _takenItems.getSize(); i++) { - if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { + if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { _takenItems.removeAt(i); i--; continue; } - if (insertAfter && scumm_stricmp(_takenItems[i]->_name, insertAfter) == 0) insertIndex = i + 1; + if (insertAfter && scumm_stricmp(_takenItems[i]->getName(), insertAfter) == 0) insertIndex = i + 1; } @@ -78,7 +78,7 @@ bool AdInventory::removeItem(const char *name) { if (name == NULL) return STATUS_FAILED; for (int i = 0; i < _takenItems.getSize(); i++) { - if (scumm_stricmp(_takenItems[i]->_name, name) == 0) { + if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i])((AdGame *)_gameRef)->_selectedItem = NULL; _takenItems.removeAt(i); return STATUS_OK; diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index d2bdcdde34..488cee77c8 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -79,12 +79,12 @@ bool AdInventoryBox::listen(BaseScriptHolder *param1, uint32 param2) { switch (obj->_type) { case UI_BUTTON: - if (scumm_stricmp(obj->_name, "close") == 0) { + if (scumm_stricmp(obj->getName(), "close") == 0) { _visible = false; - } else if (scumm_stricmp(obj->_name, "prev") == 0) { + } else if (scumm_stricmp(obj->getName(), "prev") == 0) { _scrollOffset -= _scrollBy; _scrollOffset = MAX(_scrollOffset, 0); - } else if (scumm_stricmp(obj->_name, "next") == 0) { + } else if (scumm_stricmp(obj->getName(), "next") == 0) { _scrollOffset += _scrollBy; } else return BaseObject::listen(param1, param2); break; @@ -321,7 +321,7 @@ bool AdInventoryBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "INVENTORY_BOX\n"); buffer->putTextIndent(indent, "{\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _itemsArea.left, _itemsArea.top, _itemsArea.right, _itemsArea.bottom); diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index 0b85fdb9b3..ba116b6569 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -582,7 +582,7 @@ ScValue *AdItem::scGetProperty(const char *name) { // Name ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Name") == 0) { - _scValue->setString(_name); + _scValue->setString(getName()); return _scValue; } diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index e59b5cde18..80fbc683ef 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -237,8 +237,8 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (val->_type == VAL_INT) node = val->getInt(); else { // get by name for (int i = 0; i < _nodes.getSize(); i++) { - if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->_name, val->getString()) == 0) || - (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->_name, val->getString()) == 0)) { + if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->getName(), val->getString()) == 0) || + (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->getName(), val->getString()) == 0)) { node = i; break; } @@ -478,7 +478,7 @@ const char *AdLayer::scToString() { ////////////////////////////////////////////////////////////////////////// bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "LAYER {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); buffer->putTextIndent(indent + 2, "MAIN=%s\n", _main ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "WIDTH=%d\n", _width); diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index bac39f5ea6..acca57393c 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -156,12 +156,12 @@ bool AdObject::playAnim(const char *filename) { _animSprite = NULL; _animSprite = new BaseSprite(_gameRef, this); if (!_animSprite) { - _gameRef->LOG(0, "AdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); + _gameRef->LOG(0, "AdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", getName(), filename); return STATUS_FAILED; } bool res = _animSprite->loadFile(filename); if (DID_FAIL(res)) { - _gameRef->LOG(res, "AdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", _name, filename); + _gameRef->LOG(res, "AdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", getName(), filename); delete _animSprite; _animSprite = NULL; return res; @@ -296,7 +296,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } else if (val->isString()) { const char *regionName = val->getString(); for (i = 0; i < main->_nodes.getSize(); i++) { - if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region->_name && scumm_stricmp(main->_nodes[i]->_region->_name, regionName) == 0) { + if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region->getName() && scumm_stricmp(main->_nodes[i]->_region->getName(), regionName) == 0) { _stickRegion = main->_nodes[i]->_region; regFound = true; break; @@ -437,7 +437,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (val->getNative() == _inventory->_takenItems[i]) { stack->pushBool(true); return STATUS_OK; - } else if (scumm_stricmp(val->getString(), _inventory->_takenItems[i]->_name) == 0) { + } else if (scumm_stricmp(val->getString(), _inventory->_takenItems[i]->getName()) == 0) { stack->pushBool(true); return STATUS_OK; } @@ -539,7 +539,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } else { const char *attachmentName = val->getString(); for (int i = 0; i < _attachmentsPre.getSize(); i++) { - if (_attachmentsPre[i]->_name && scumm_stricmp(_attachmentsPre[i]->_name, attachmentName) == 0) { + if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { found = true; _gameRef->unregisterObject(_attachmentsPre[i]); _attachmentsPre.removeAt(i); @@ -547,7 +547,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } } for (int i = 0; i < _attachmentsPost.getSize(); i++) { - if (_attachmentsPost[i]->_name && scumm_stricmp(_attachmentsPost[i]->_name, attachmentName) == 0) { + if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { found = true; _gameRef->unregisterObject(_attachmentsPost[i]); _attachmentsPost.removeAt(i); @@ -582,14 +582,14 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } else { const char *attachmentName = val->getString(); for (int i = 0; i < _attachmentsPre.getSize(); i++) { - if (_attachmentsPre[i]->_name && scumm_stricmp(_attachmentsPre[i]->_name, attachmentName) == 0) { + if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { ret = _attachmentsPre[i]; break; } } if (!ret) { for (int i = 0; i < _attachmentsPost.getSize(); i++) { - if (_attachmentsPost[i]->_name && scumm_stricmp(_attachmentsPost[i]->_name, attachmentName) == 0) { + if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { ret = _attachmentsPre[i]; break; } diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index bac02f5dd6..965f14d8a3 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -252,7 +252,7 @@ ScValue *AdRegion::scGetProperty(const char *name) { // Name ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Name") == 0) { - _scValue->setString(_name); + _scValue->setString(getName()); return _scValue; } @@ -347,7 +347,7 @@ const char *AdRegion::scToString() { ////////////////////////////////////////////////////////////////////////// bool AdRegion::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "REGION {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); buffer->putTextIndent(indent + 2, "BLOCKED=%s\n", _blocked ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "DECORATION=%s\n", _decoration ? "TRUE" : "FALSE"); diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 212802ef3a..38fbd6f95d 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -486,11 +486,11 @@ bool AdResponseBox::listen(BaseScriptHolder *param1, uint32 param2) { switch (obj->_type) { case UI_BUTTON: - if (scumm_stricmp(obj->_name, "prev") == 0) { + if (scumm_stricmp(obj->getName(), "prev") == 0) { _scrollOffset--; - } else if (scumm_stricmp(obj->_name, "next") == 0) { + } else if (scumm_stricmp(obj->getName(), "next") == 0) { _scrollOffset++; - } else if (scumm_stricmp(obj->_name, "response") == 0) { + } else if (scumm_stricmp(obj->getName(), "response") == 0) { if (_waitingScript) _waitingScript->_stack->pushInt(_responses[param2]->_iD); handleResponse(_responses[param2]); _waitingScript = NULL; diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 958bf64ae5..e76e61af79 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -1346,7 +1346,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *LayerName = val->getString(); bool LayerFound = false; for (int i = 0; i < _layers.getSize(); i++) { - if (scumm_stricmp(LayerName, _layers[i]->_name) == 0) { + if (scumm_stricmp(LayerName, _layers[i]->getName()) == 0) { stack->pushNative(_layers[i], true); LayerFound = true; break; @@ -1396,7 +1396,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } else { const char *nodeName = val->getString(); for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i] && _objects[i]->_name && scumm_stricmp(_objects[i]->_name, nodeName) == 0) { + if (_objects[i] && _objects[i]->getName() && scumm_stricmp(_objects[i]->getName(), nodeName) == 0) { ret = _objects[i]; break; } @@ -1962,7 +1962,7 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "SCENE {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); if (_persistentState) @@ -2424,8 +2424,8 @@ BaseObject *AdScene::getNodeByName(const char *name) { AdLayer *layer = _layers[i]; for (int j = 0; j < layer->_nodes.getSize(); j++) { AdSceneNode *node = layer->_nodes[j]; - if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->_name)) || - (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->_name))) { + if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->getName())) || + (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->getName()))) { switch (node->_type) { case OBJECT_ENTITY: ret = node->_entity; @@ -2443,14 +2443,14 @@ BaseObject *AdScene::getNodeByName(const char *name) { // free entities for (int i = 0; i < _objects.getSize(); i++) { - if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->_name)) { + if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->getName())) { return _objects[i]; } } // waypoint groups for (int i = 0; i < _waypointGroups.getSize(); i++) { - if (!scumm_stricmp(name, _waypointGroups[i]->_name)) { + if (!scumm_stricmp(name, _waypointGroups[i]->getName())) { return _waypointGroups[i]; } } @@ -2489,7 +2489,7 @@ bool AdScene::persistState(bool saving) { switch (node->_type) { case OBJECT_ENTITY: if (!node->_entity->_saveState) continue; - nodeState = state->getNodeState(node->_entity->_name, saving); + nodeState = state->getNodeState(node->_entity->getName(), saving); if (nodeState) { nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); //if(Saving) NodeState->_active = node->_entity->_active; @@ -2498,7 +2498,7 @@ bool AdScene::persistState(bool saving) { break; case OBJECT_REGION: if (!node->_region->_saveState) continue; - nodeState = state->getNodeState(node->_region->_name, saving); + nodeState = state->getNodeState(node->_region->getName(), saving); if (nodeState) { if (saving) nodeState->_active = node->_region->_active; else node->_region->_active = nodeState->_active; @@ -2515,7 +2515,7 @@ bool AdScene::persistState(bool saving) { for (int i = 0; i < _objects.getSize(); i++) { if (!_objects[i]->_saveState) continue; if (_objects[i]->_type == OBJECT_ENTITY) { - nodeState = state->getNodeState(_objects[i]->_name, saving); + nodeState = state->getNodeState(_objects[i]->getName(), saving); if (nodeState) { nodeState->transferEntity((AdEntity *)_objects[i], _persistentStateSprites, saving); //if(Saving) NodeState->_active = _objects[i]->_active; @@ -2526,7 +2526,7 @@ bool AdScene::persistState(bool saving) { // waypoint groups for (int i = 0; i < _waypointGroups.getSize(); i++) { - nodeState = state->getNodeState(_waypointGroups[i]->_name, saving); + nodeState = state->getNodeState(_waypointGroups[i]->getName(), saving); if (nodeState) { if (saving) nodeState->_active = _waypointGroups[i]->_active; else _waypointGroups[i]->_active = nodeState->_active; diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index da7b417470..173c1ef57b 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -71,7 +71,7 @@ void AdSceneState::setFilename(const char *filename) { ////////////////////////////////////////////////////////////////////////// -AdNodeState *AdSceneState::getNodeState(char *name, bool saving) { +AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { for (int i = 0; i < _nodeStates.getSize(); i++) { if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) return _nodeStates[i]; } diff --git a/engines/wintermute/ad/ad_scene_state.h b/engines/wintermute/ad/ad_scene_state.h index 7231ba52db..469f985639 100644 --- a/engines/wintermute/ad/ad_scene_state.h +++ b/engines/wintermute/ad/ad_scene_state.h @@ -37,7 +37,7 @@ namespace WinterMute { class AdNodeState; class AdSceneState : public BaseClass { public: - AdNodeState *getNodeState(char *name, bool saving); + AdNodeState *getNodeState(const char *name, bool saving); void setFilename(const char *filename); DECLARE_PERSISTENT(AdSceneState, BaseClass) AdSceneState(BaseGame *inGame); diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index 34ea53481d..4840951ab2 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -260,7 +260,7 @@ BaseSprite *AdSpriteSet::getSprite(TDirection direction) { ////////////////////////////////////////////////////////////////////////// bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "SPRITESET {\n"); - if (_name) buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + if (getName()) buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); for (int i = 0; i < NUM_DIRECTIONS; i++) { if (_sprites[i]) { switch (i) { diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 17f7171cc3..de19004584 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -75,7 +75,7 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { if (_animSprite) { bool res = _animSprite->loadFile(_forcedTalkAnimName); if (DID_FAIL(res)) { - _gameRef->LOG(res, "AdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", _name, _forcedTalkAnimName); + _gameRef->LOG(res, "AdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); delete _animSprite; _animSprite = NULL; } else return _animSprite; @@ -86,7 +86,7 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { if (stance != NULL) { // search special talk stances for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->_name, stance) == 0) { + if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { ret = _talkSpritesEx[i]; break; } @@ -94,7 +94,7 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { if (ret == NULL) { // serach generic talk stances for (int i = 0; i < _talkSprites.getSize(); i++) { - if (scumm_stricmp(_talkSprites[i]->_name, stance) == 0) { + if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { ret = _talkSprites[i]; break; } diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 4a8ab966e8..28ce2967dd 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -165,7 +165,7 @@ bool AdWaypointGroup::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// bool AdWaypointGroup::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "WAYPOINTS {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", _name); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED_POINT=%d\n", _editorSelectedPoint); -- cgit v1.2.3 From d1f7730ec25b409f3651167640dd48b7dd8046be Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 23 Jul 2012 01:28:42 +0200 Subject: WINTERMUTE: Encapsulate BaseRenderer::_rectList and replace it by Common::Array --- engines/wintermute/ad/ad_entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 2a281d0fcb..91ba066d6a 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -502,7 +502,7 @@ bool AdEntity::display() { if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) Reg = false; if (_region && (Reg || _editorAlwaysRegister)) { - _gameRef->_renderer->_rectList.add(new BaseActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); + _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); } displaySpriteAttachments(true); -- cgit v1.2.3 From aac94209b306466b49b0938e5f7aab5e280a6c78 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 23 Jul 2012 01:54:47 +0200 Subject: WINTERMUTE: Clean up a few includes. --- engines/wintermute/ad/ad_actor.cpp | 9 ++------- engines/wintermute/ad/ad_actor.h | 2 ++ engines/wintermute/ad/ad_entity.cpp | 1 + engines/wintermute/ad/ad_object.cpp | 2 +- engines/wintermute/ad/ad_object.h | 3 ++- engines/wintermute/ad/ad_sprite_set.cpp | 1 + engines/wintermute/ad/ad_sprite_set.h | 3 +-- 7 files changed, 10 insertions(+), 11 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index 68059072d7..bfc21c6ccc 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -26,10 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" -#include "engines/wintermute/dctypes.h" -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/base_object.h" #include "engines/wintermute/ad/ad_actor.h" #include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/ad/ad_scene.h" @@ -38,16 +34,15 @@ #include "engines/wintermute/ad/ad_waypoint_group.h" #include "engines/wintermute/ad/ad_path.h" #include "engines/wintermute/ad/ad_sentence.h" -#include "engines/wintermute/base/base_object.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/sound/base_sound.h" #include "engines/wintermute/base/base_region.h" #include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/base/particles/part_emitter.h" #include "engines/wintermute/wintermute.h" namespace WinterMute { diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index 3cce827b17..870b3e8418 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -33,6 +33,7 @@ #include "engines/wintermute/dctypes.h" // Added by ClassView #include "engines/wintermute/ad/ad_types.h" // Added by ClassView #include "engines/wintermute/ad/ad_talk_holder.h" +#include "engines/wintermute/coll_templ.h" #include "engines/wintermute/base/base_point.h" // Added by ClassView #include "engines/wintermute/persistent.h" #include "common/str.h" @@ -41,6 +42,7 @@ namespace WinterMute { class AdSpriteSet; class AdPath; +class BaseSprite; class AdActor : public AdTalkHolder { public: TDirection angleToDirection(int angle); diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 91ba066d6a..1ea2512df6 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -51,6 +51,7 @@ #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" #include "engines/wintermute/video/video_theora_player.h" +#include "engines/wintermute/base/particles/part_emitter.h" #include "common/str.h" namespace WinterMute { diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index acca57393c..84f13dc989 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/ad/ad_item.h" #include "engines/wintermute/ad/ad_object.h" @@ -49,6 +48,7 @@ #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" #include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/particles/part_emitter.h" #include "common/str.h" #include "common/util.h" diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h index a8da8bd820..f26a29c8b2 100644 --- a/engines/wintermute/ad/ad_object.h +++ b/engines/wintermute/ad/ad_object.h @@ -30,7 +30,7 @@ #define WINTERMUTE_ADOBJECT_H #include "engines/wintermute/ad/ad_types.h" -#include "engines/wintermute/base/particles/part_emitter.h" +#include "engines/wintermute/base/base_object.h" namespace WinterMute { @@ -40,6 +40,7 @@ class AdSentence; class BaseFont; class BaseRegion; class AdInventory; +class PartEmitter; #define MAX_NUM_REGIONS 10 diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index 4840951ab2..b2238b63ba 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -32,6 +32,7 @@ #include "engines/wintermute/base/base_dynamic_buffer.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_sprite.h" namespace WinterMute { diff --git a/engines/wintermute/ad/ad_sprite_set.h b/engines/wintermute/ad/ad_sprite_set.h index 196d8a8e3a..555ab914cf 100644 --- a/engines/wintermute/ad/ad_sprite_set.h +++ b/engines/wintermute/ad/ad_sprite_set.h @@ -31,10 +31,9 @@ #include "engines/wintermute/base/base_object.h" -#include "engines/wintermute/base/base_sprite.h" // Added by ClassView namespace WinterMute { - +class BaseSprite; class AdSpriteSet : public BaseObject { public: bool containsSprite(BaseSprite *sprite); -- cgit v1.2.3 From 448911930d8d6bf43a67769d50ee4048f296b7f4 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 23 Jul 2012 03:01:05 +0200 Subject: WINTERMUTE: Remove unused code from platform_osystem.h --- engines/wintermute/ad/ad_game.cpp | 1 + engines/wintermute/ad/ad_response_box.cpp | 2 +- engines/wintermute/ad/ad_scene.cpp | 5 ++--- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 42a453d533..977115ad76 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -59,6 +59,7 @@ #include "engines/wintermute/utils/utils.h" #include "engines/wintermute/video/video_player.h" #include "engines/wintermute/video/video_theora_player.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" namespace WinterMute { diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 38fbd6f95d..a800ae71b2 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -398,7 +398,7 @@ bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { bool AdResponseBox::display() { Rect32 rect = _responseArea; if (_window) { - BasePlatform::offsetRect(&rect, _window->_posX, _window->_posY); + rect.offsetRect(_window->_posX, _window->_posY); //_window->display(); } diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index e76e61af79..a802039550 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -52,7 +52,6 @@ #include "engines/wintermute/base/base_scriptable.h" #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_viewport.h" -#include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/base/scriptables/script_stack.h" #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script.h" @@ -485,14 +484,14 @@ bool AdScene::initLoop() { #ifdef _DEBUGxxxx int nu_steps = 0; uint32 start = _gameRef->_currentTime; - while (!_pfReady && BasePlatform::getTime() - start <= _pfMaxTime) { + while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) { PathFinderStep(); nu_steps++; } if (nu_steps > 0) _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); #else uint32 start = _gameRef->_currentTime; - while (!_pfReady && BasePlatform::getTime() - start <= _pfMaxTime) pathFinderStep(); + while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) pathFinderStep(); #endif return STATUS_OK; -- cgit v1.2.3 From aedb0aea505e764c4c7bab1f90520b380be4d688 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 23 Jul 2012 03:22:49 +0200 Subject: WINTERMUTE: Remove dcgf.h from almost all includes. --- engines/wintermute/ad/ad_entity.cpp | 2 -- engines/wintermute/ad/ad_game.cpp | 1 - engines/wintermute/ad/ad_inventory_box.cpp | 2 +- engines/wintermute/ad/ad_item.cpp | 1 - engines/wintermute/ad/ad_layer.cpp | 1 - engines/wintermute/ad/ad_node_state.cpp | 1 - engines/wintermute/ad/ad_path.cpp | 1 - engines/wintermute/ad/ad_region.cpp | 1 - engines/wintermute/ad/ad_response.cpp | 1 - engines/wintermute/ad/ad_response_box.cpp | 1 - engines/wintermute/ad/ad_response_context.cpp | 1 - engines/wintermute/ad/ad_rot_level.cpp | 1 - engines/wintermute/ad/ad_scale_level.cpp | 1 - engines/wintermute/ad/ad_scene_node.cpp | 1 - engines/wintermute/ad/ad_scene_state.cpp | 1 - engines/wintermute/ad/ad_sentence.cpp | 1 - engines/wintermute/ad/ad_sprite_set.cpp | 1 - engines/wintermute/ad/ad_talk_def.cpp | 1 - engines/wintermute/ad/ad_talk_holder.cpp | 1 - engines/wintermute/ad/ad_talk_node.cpp | 1 - 20 files changed, 1 insertion(+), 21 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 1ea2512df6..80c52de71a 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -27,8 +27,6 @@ */ - -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_entity.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 977115ad76..ef5461bb5e 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_actor.h" #include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/ad/ad_entity.h" diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index 488cee77c8..38e06535d9 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -25,7 +25,7 @@ * http://dead-code.org/redir.php?target=wmelite * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" + #include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/ad/ad_inventory_box.h" #include "engines/wintermute/ad/ad_inventory.h" diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index ba116b6569..ec9fa3c14c 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_item.h" #include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/ad/ad_sentence.h" diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 80fbc683ef..38894a0e88 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/ad/ad_layer.h" #include "engines/wintermute/ad/ad_scene_node.h" diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index fca2600884..f8196e96b7 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/ad/ad_node_state.h" #include "engines/wintermute/ad/ad_entity.h" diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index cecfaa37d6..f7832d621d 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_path.h" #include "engines/wintermute/base/base_point.h" diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 965f14d8a3..a23c000137 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_region.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp index 29398f547c..fbfe828330 100644 --- a/engines/wintermute/ad/ad_response.cpp +++ b/engines/wintermute/ad/ad_response.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_response.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/font/base_font_storage.h" diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index a800ae71b2..90582ce811 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/ad/ad_response_box.h" #include "engines/wintermute/base/base_parser.h" diff --git a/engines/wintermute/ad/ad_response_context.cpp b/engines/wintermute/ad/ad_response_context.cpp index 32d9415fe9..8d966e7a3e 100644 --- a/engines/wintermute/ad/ad_response_context.cpp +++ b/engines/wintermute/ad/ad_response_context.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_response_context.h" #include "engines/wintermute/base/base_persistence_manager.h" diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index b9949d9f9b..6f3ffdaeb5 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_rot_level.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index 539e9a8bb7..1adf4266b2 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_scale_level.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" diff --git a/engines/wintermute/ad/ad_scene_node.cpp b/engines/wintermute/ad/ad_scene_node.cpp index dbf68ff0ca..658e85340d 100644 --- a/engines/wintermute/ad/ad_scene_node.cpp +++ b/engines/wintermute/ad/ad_scene_node.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_scene_node.h" #include "engines/wintermute/base/base_game.h" diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index 173c1ef57b..617f247241 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/persistent.h" #include "engines/wintermute/ad/ad_scene_state.h" #include "engines/wintermute/ad/ad_node_state.h" diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index ad3a291e16..452c2587d4 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_sentence.h" #include "engines/wintermute/ad/ad_talk_def.h" #include "engines/wintermute/ad/ad_talk_node.h" diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index b2238b63ba..e158b6115a 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_sprite_set.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 2756b69467..cfbefd39d4 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_talk_def.h" #include "engines/wintermute/ad/ad_talk_node.h" #include "engines/wintermute/base/base_parser.h" diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index de19004584..db13e0a549 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_talk_holder.h" #include "engines/wintermute/base/base_dynamic_buffer.h" #include "engines/wintermute/base/scriptables/script_value.h" diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index 5325b1aeff..306825c439 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/dcgf.h" #include "engines/wintermute/ad/ad_talk_node.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" -- cgit v1.2.3 From c7eda9abc80d1912148cae4292b94620c67a9c19 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 23 Jul 2012 03:42:27 +0200 Subject: WINTERMUTE: Encapsulate and distance BasePersistenceManager from Base. --- engines/wintermute/ad/ad_game.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index ef5461bb5e..d75f41e38e 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -1252,7 +1252,7 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// bool AdGame::persist(BasePersistenceManager *persistMgr) { - if (!persistMgr->_saving) cleanup(); + if (!persistMgr->getIsSaving()) cleanup(); BaseGame::persist(persistMgr); _dlgPendingBranches.persist(persistMgr); @@ -1292,7 +1292,7 @@ bool AdGame::persist(BasePersistenceManager *persistMgr) { _speechDirs.persist(persistMgr); persistMgr->transfer(TMEMBER(_smartItemCursor)); - if (!persistMgr->_saving) _initialScene = false; + if (!persistMgr->getIsSaving()) _initialScene = false; persistMgr->transfer(TMEMBER(_startupScene)); -- cgit v1.2.3 From 45c5eb5cab069ea9ca4302a637f4621d460c790d Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Wed, 25 Jul 2012 05:08:13 +0200 Subject: WINTERMUTE: Privatize/Protect variables that don't need to be public. --- engines/wintermute/ad/ad_game.h | 60 ++++++++++++++++++--------------- engines/wintermute/ad/ad_node_state.cpp | 2 +- 2 files changed, 34 insertions(+), 28 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index b52fd2832f..5136ed09d3 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -54,13 +54,9 @@ public: virtual bool displayDebugInfo(); - virtual bool initAfterLoad(); static void afterLoadScene(void *scene, void *data); - bool _smartItemCursor; - - BaseArray _speechDirs; bool addSpeechDir(const char *dir); bool removeSpeechDir(const char *dir); char *findSpeechFile(char *StringID); @@ -71,18 +67,13 @@ public: virtual bool resetContent(); bool addItem(AdItem *item); AdItem *getItemByName(const char *name); - BaseArray _items; + AdObject *_inventoryOwner; bool isItemTaken(char *itemName); bool registerInventory(AdInventory *inv); bool unregisterInventory(AdInventory *inv); - - AdObject *_invObject; - BaseArray _inventories; virtual bool displayContent(bool update = true, bool displayAll = false); - char *_debugStartupScene; - char *_startupScene; - bool _initialScene; + bool gameResponseUsed(int ID); bool addGameResponse(int ID); bool resetResponse(int ID); @@ -97,6 +88,7 @@ public: AdSceneState *getSceneState(const char *filename, bool saving); BaseViewport *_sceneViewport; + int _texItemLifeTime; int _texWalkLifeTime; int _texStandLifeTime; @@ -106,12 +98,9 @@ public: virtual bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor); bool scheduleChangeScene(const char *filename, bool fadeIn); - char *_scheduledScene; - bool _scheduledFadeIn; void setPrevSceneName(const char *name); void setPrevSceneFilename(const char *name); - char *_prevSceneName; - char *_prevSceneFilename; + virtual bool loadGame(const char *filename); AdItem *_selectedItem; bool cleanup(); @@ -119,9 +108,9 @@ public: void finishSentences(); bool showCursor(); + TGameStateEx _stateEx; - AdResponseBox *_responseBox; - AdInventoryBox *_inventoryBox; + bool displaySentences(bool frozen); void addSentence(AdSentence *sentence); bool changeScene(const char *filename, bool fadeIn); @@ -131,14 +120,8 @@ public: bool initLoop(); AdGame(); virtual ~AdGame(); - BaseArray _objects; - BaseArray _sentences; - BaseArray _sceneStates; - BaseArray _dlgPendingBranches; - - BaseArray _responsesBranch; - BaseArray _responsesGame; + BaseArray _objects; virtual bool loadFile(const char *filename); virtual bool loadBuffer(byte *buffer, bool complete = true); @@ -146,14 +129,37 @@ public: bool loadItemsFile(const char *filename, bool merge = false); bool loadItemsBuffer(byte *buffer, bool merge = false); - - virtual bool ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name); - // scripting interface virtual ScValue *scGetProperty(const char *name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); bool validMouse(); +private: + virtual bool ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name); + + AdObject *_invObject; + BaseArray _inventories; + char *_scheduledScene; + bool _scheduledFadeIn; + char *_prevSceneName; + char *_prevSceneFilename; + char *_debugStartupScene; + char *_startupScene; + bool _initialScene; + bool _smartItemCursor; + BaseArray _speechDirs; + BaseArray _items; + + BaseArray _sentences; + + BaseArray _sceneStates; + BaseArray _dlgPendingBranches; + + BaseArray _responsesBranch; + BaseArray _responsesGame; + + AdResponseBox *_responseBox; + AdInventoryBox *_inventoryBox; }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index f8196e96b7..6212274d03 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -131,7 +131,7 @@ char *AdNodeState::getCaption(int caseVal) { bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool saving) { if (!entity) return STATUS_FAILED; - // hack! + // HACK! if (this->_gameRef != entity->_gameRef) this->_gameRef = entity->_gameRef; if (saving) { -- cgit v1.2.3 From fa96c9ea187cdb26e9f1ce048c9132f723e25df1 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Wed, 25 Jul 2012 21:05:03 +0200 Subject: WINTERMUTE: "delete []" -> "delete[]" --- engines/wintermute/ad/ad_actor.cpp | 4 ++-- engines/wintermute/ad/ad_entity.cpp | 2 +- engines/wintermute/ad/ad_game.cpp | 28 ++++++++++++++-------------- engines/wintermute/ad/ad_inventory_box.cpp | 2 +- engines/wintermute/ad/ad_item.cpp | 2 +- engines/wintermute/ad/ad_layer.cpp | 2 +- engines/wintermute/ad/ad_object.cpp | 4 ++-- engines/wintermute/ad/ad_region.cpp | 2 +- engines/wintermute/ad/ad_response_box.cpp | 2 +- engines/wintermute/ad/ad_rot_level.cpp | 2 +- engines/wintermute/ad/ad_scale_level.cpp | 2 +- engines/wintermute/ad/ad_scene.cpp | 2 +- engines/wintermute/ad/ad_sentence.cpp | 6 +++--- engines/wintermute/ad/ad_sprite_set.cpp | 2 +- engines/wintermute/ad/ad_talk_def.cpp | 2 +- engines/wintermute/ad/ad_waypoint_group.cpp | 2 +- 16 files changed, 33 insertions(+), 33 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index bfc21c6ccc..fc28293ac8 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -132,7 +132,7 @@ bool AdActor::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } @@ -1287,7 +1287,7 @@ bool AdActor::mergeAnims(const char *animsFilename) { break; } } - delete [] fileBuffer; + delete[] fileBuffer; return Ret; } diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 80c52de71a..a4b94d062f 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -97,7 +97,7 @@ bool AdEntity::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ENTITY file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index d75f41e38e..1df34e74bd 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -128,12 +128,12 @@ bool AdGame::cleanup() { for (i = 0; i < _dlgPendingBranches.getSize(); i++) { - delete [] _dlgPendingBranches[i]; + delete[] _dlgPendingBranches[i]; } _dlgPendingBranches.removeAll(); for (i = 0; i < _speechDirs.getSize(); i++) { - delete [] _speechDirs[i]; + delete[] _speechDirs[i]; } _speechDirs.removeAll(); @@ -1117,7 +1117,7 @@ bool AdGame::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } @@ -1387,7 +1387,7 @@ bool AdGame::loadItemsFile(const char *filename, bool merge) { if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } @@ -1451,7 +1451,7 @@ AdSceneState *AdGame::getSceneState(const char *filename, bool saving) { for (int i = 0; i < _sceneStates.getSize(); i++) { if (scumm_stricmp(_sceneStates[i]->_filename, filenameCor) == 0) { - delete [] filenameCor; + delete[] filenameCor; return _sceneStates[i]; } } @@ -1462,10 +1462,10 @@ AdSceneState *AdGame::getSceneState(const char *filename, bool saving) { _sceneStates.add(ret); - delete [] filenameCor; + delete[] filenameCor; return ret; } else { - delete [] filenameCor; + delete[] filenameCor; return NULL; } } @@ -1563,7 +1563,7 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const if (startIndex >= 0) { for (int i = startIndex; i < _dlgPendingBranches.getSize(); i++) { //ClearBranchResponses(_dlgPendingBranches[i]); - delete [] _dlgPendingBranches[i]; + delete[] _dlgPendingBranches[i]; _dlgPendingBranches[i] = NULL; } _dlgPendingBranches.removeAt(startIndex, _dlgPendingBranches.getSize() - startIndex); @@ -1575,7 +1575,7 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const _responsesBranch.removeAll(); } - if (deleteName) delete [] name; + if (deleteName) delete[] name; return STATUS_OK; } @@ -1795,7 +1795,7 @@ bool AdGame::addItem(AdItem *item) { bool AdGame::resetContent() { // clear pending dialogs for (int i = 0; i < _dlgPendingBranches.getSize(); i++) { - delete [] _dlgPendingBranches[i]; + delete[] _dlgPendingBranches[i]; } _dlgPendingBranches.removeAll(); @@ -1862,7 +1862,7 @@ bool AdGame::addSpeechDir(const char *dir) { for (int i = 0; i < _speechDirs.getSize(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { - delete [] temp; + delete[] temp; return STATUS_OK; } } @@ -1884,13 +1884,13 @@ bool AdGame::removeSpeechDir(const char *dir) { bool Found = false; for (int i = 0; i < _speechDirs.getSize(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { - delete [] _speechDirs[i]; + delete[] _speechDirs[i]; _speechDirs.removeAt(i); Found = true; break; } } - delete [] temp; + delete[] temp; if (Found) return STATUS_OK; else return STATUS_FAILED; @@ -1910,7 +1910,7 @@ char *AdGame::findSpeechFile(char *stringID) { if (_fileManager->hasFile(ret)) return ret; } - delete [] ret; + delete[] ret; return NULL; } diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index 38e06535d9..60607c71c6 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -169,7 +169,7 @@ bool AdInventoryBox::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index ec9fa3c14c..e9a1bb4353 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -97,7 +97,7 @@ bool AdItem::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 38894a0e88..0a93edfb35 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -73,7 +73,7 @@ bool AdLayer::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index 84f13dc989..fdbc987158 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -853,7 +853,7 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const char *key = _gameRef->_stringTable->getKey(text); if (key) { sound = ((AdGame *)_gameRef)->findSpeechFile(key); - delete [] key; + delete[] key; if (sound) deleteSound = true; } @@ -931,7 +931,7 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const _state = STATE_TALKING; - if (deleteSound) delete [] sound; + if (deleteSound) delete[] sound; } diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index a23c000137..eec25b2aaa 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -67,7 +67,7 @@ bool AdRegion::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 90582ce811..22b40f3ea4 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -200,7 +200,7 @@ bool AdResponseBox::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index 6f3ffdaeb5..72fcaeff28 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -66,7 +66,7 @@ bool AdRotLevel::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index 1adf4266b2..c390c6dc08 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -64,7 +64,7 @@ bool AdScaleLevel::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index a802039550..dd69db3d68 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -514,7 +514,7 @@ bool AdScene::loadFile(const char *filename) { setFilename(filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index 452c2587d4..a011db3f02 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -91,7 +91,7 @@ AdSentence::~AdSentence() { ////////////////////////////////////////////////////////////////////////// void AdSentence::setText(const char *text) { - if (_text) delete [] _text; + if (_text) delete[] _text; _text = new char[strlen(text) + 1]; if (_text) strcpy(_text, text); } @@ -99,7 +99,7 @@ void AdSentence::setText(const char *text) { ////////////////////////////////////////////////////////////////////////// void AdSentence::setStances(const char *stances) { - if (_stances) delete [] _stances; + if (_stances) delete[] _stances; if (stances) { _stances = new char[strlen(stances) + 1]; if (_stances) strcpy(_stances, stances); @@ -124,7 +124,7 @@ char *AdSentence::getNextStance() { char *AdSentence::getStance(int stance) { if (_stances == NULL) return NULL; - if (_tempStance) delete [] _tempStance; + if (_tempStance) delete[] _tempStance; _tempStance = NULL; char *start; diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index e158b6115a..fcbf9af4eb 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -69,7 +69,7 @@ bool AdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index cfbefd39d4..2b0c6c6c1b 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -81,7 +81,7 @@ bool AdTalkDef::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 28ce2967dd..7e5d8d29c6 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -78,7 +78,7 @@ bool AdWaypointGroup::loadFile(const char *filename) { if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); - delete [] buffer; + delete[] buffer; return ret; } -- cgit v1.2.3 From 1ad859a468415cc7fd93adaa84beba02aae29ad8 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Wed, 25 Jul 2012 21:21:55 +0200 Subject: WINTERMUTE: "if(" -> "if (" --- engines/wintermute/ad/ad_entity.cpp | 2 +- engines/wintermute/ad/ad_game.cpp | 4 ++-- engines/wintermute/ad/ad_scene.cpp | 6 +++--- engines/wintermute/ad/ad_talk_holder.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index a4b94d062f..98fb296bf5 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -650,7 +650,7 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_theora && DID_SUCCEED(_theora->initialize(filename))) { if (!valAlpha->isNULL()) _theora->setAlphaImage(valAlpha->getString()); _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); - //if(m_Scale>=0) m_Theora->m_PlayZoom = m_Scale; + //if (_scale>=0) _theora->_playZoom = _scale; stack->pushBool(true); } else { script->runtimeError("Entity.PlayTheora - error playing video '%s'", filename); diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 1df34e74bd..259fc175ae 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -335,7 +335,7 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, //bool ret = ChangeScene(stack->pop()->getString()); - //if(DID_FAIL(ret)) stack->pushBool(false); + //if (DID_FAIL(ret)) stack->pushBool(false); //else stack->pushBool(true); return STATUS_OK; @@ -821,7 +821,7 @@ ScValue *AdGame::scGetProperty(const char *name) { // SelectedItem ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SelectedItem") == 0) { - //if(_selectedItem) _scValue->setString(_selectedItem->_name); + //if (_selectedItem) _scValue->setString(_selectedItem->_name); if (_selectedItem) _scValue->setNative(_selectedItem, true); else _scValue->setNULL(); diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index dd69db3d68..85c2341268 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -2491,7 +2491,7 @@ bool AdScene::persistState(bool saving) { nodeState = state->getNodeState(node->_entity->getName(), saving); if (nodeState) { nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); - //if(Saving) NodeState->_active = node->_entity->_active; + //if (Saving) NodeState->_active = node->_entity->_active; //else node->_entity->_active = NodeState->_active; } break; @@ -2517,7 +2517,7 @@ bool AdScene::persistState(bool saving) { nodeState = state->getNodeState(_objects[i]->getName(), saving); if (nodeState) { nodeState->transferEntity((AdEntity *)_objects[i], _persistentStateSprites, saving); - //if(Saving) NodeState->_active = _objects[i]->_active; + //if (Saving) NodeState->_active = _objects[i]->_active; //else _objects[i]->_active = NodeState->_active; } } @@ -2684,7 +2684,7 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i } if (!found) objects.add(regionObj[newIndex]); } - //if(RegionObj.getSize() > 0) Objects.Append(RegionObj); + //if (RegionObj.getSize() > 0) Objects.Append(RegionObj); } break; default: diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index db13e0a549..359215ee8f 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -320,7 +320,7 @@ bool AdTalkHolder::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// // Item ////////////////////////////////////////////////////////////////////////// - if(strcmp(name, "Item")==0){ + if (strcmp(name, "Item")==0){ SetItem(value->getString()); return STATUS_OK; } -- cgit v1.2.3 From 38507fa9895620639d8733dbb4e085dfb2282a33 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 04:12:58 +0200 Subject: WINTERMUTE: AStyle-formatting. --- engines/wintermute/ad/ad_actor.cpp | 2 +- engines/wintermute/ad/ad_game.h | 4 ++-- engines/wintermute/ad/ad_item.cpp | 2 +- engines/wintermute/ad/ad_node_state.cpp | 35 ++++++++++++++++++------------- engines/wintermute/ad/ad_response_box.h | 6 +++--- engines/wintermute/ad/ad_talk_holder.cpp | 4 ++-- engines/wintermute/ad/ad_types.h | 36 ++++++++++++++++---------------- 7 files changed, 48 insertions(+), 41 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index fc28293ac8..fe1948d3a8 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -790,7 +790,7 @@ void AdActor::getNextStep() { maxStepX--; } - if (((AdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX,(int) _pFY, true, this)) { + if (((AdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX, (int) _pFY, true, this)) { if (_pFCount == 0) { _state = _nextState; _nextState = STATE_READY; diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index 5136ed09d3..49c48de0bb 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -151,10 +151,10 @@ private: BaseArray _items; BaseArray _sentences; - + BaseArray _sceneStates; BaseArray _dlgPendingBranches; - + BaseArray _responsesBranch; BaseArray _responsesGame; diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index e9a1bb4353..cae974e152 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -375,7 +375,7 @@ bool AdItem::update() { } } default: - break; + break; } _ready = (_state == STATE_READY); diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index 6212274d03..444373ea75 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -44,7 +44,8 @@ IMPLEMENT_PERSISTENT(AdNodeState, false) AdNodeState::AdNodeState(BaseGame *inGame): BaseClass(inGame) { _name = NULL; _active = false; - for (int i = 0; i < 7; i++) _caption[i] = NULL; + for (int i = 0; i < 7; i++) + _caption[i] = NULL; _alphaColor = 0; _filename = NULL; _cursor = NULL; @@ -99,7 +100,8 @@ bool AdNodeState::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_filename)); persistMgr->transfer(TMEMBER(_cursor)); persistMgr->transfer(TMEMBER(_alphaColor)); - for (int i = 0; i < 7; i++) persistMgr->transfer(TMEMBER(_caption[i])); + for (int i = 0; i < 7; i++) + persistMgr->transfer(TMEMBER(_caption[i])); return STATUS_OK; } @@ -107,23 +109,27 @@ bool AdNodeState::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// void AdNodeState::setCaption(const char *caption, int caseVal) { - if (caseVal== 0) caseVal= 1; - if (caseVal< 1 || caseVal> 7) return; - - delete[] _caption[caseVal- 1]; - _caption[caseVal- 1] = new char[strlen(caption) + 1]; - if (_caption[caseVal- 1]) { - strcpy(_caption[caseVal- 1], caption); - _gameRef->_stringTable->expand(&_caption[caseVal- 1]); + if (caseVal == 0) + caseVal = 1; + if (caseVal < 1 || caseVal > 7) + return; + + delete[] _caption[caseVal - 1]; + _caption[caseVal - 1] = new char[strlen(caption) + 1]; + if (_caption[caseVal - 1]) { + strcpy(_caption[caseVal - 1], caption); + _gameRef->_stringTable->expand(&_caption[caseVal - 1]); } } ////////////////////////////////////////////////////////////////////////// char *AdNodeState::getCaption(int caseVal) { - if (caseVal== 0) caseVal= 1; - if (caseVal< 1 || caseVal> 7 || _caption[caseVal- 1] == NULL) return ""; - else return _caption[caseVal- 1]; + if (caseVal == 0) caseVal = 1; + if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) + return ""; + else + return _caption[caseVal - 1]; } @@ -132,7 +138,8 @@ bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool s if (!entity) return STATUS_FAILED; // HACK! - if (this->_gameRef != entity->_gameRef) this->_gameRef = entity->_gameRef; + if (this->_gameRef != entity->_gameRef) + this->_gameRef = entity->_gameRef; if (saving) { for (int i = 0; i < 7; i++) { diff --git a/engines/wintermute/ad/ad_response_box.h b/engines/wintermute/ad/ad_response_box.h index f77ff3360c..5dc22cbebe 100644 --- a/engines/wintermute/ad/ad_response_box.h +++ b/engines/wintermute/ad/ad_response_box.h @@ -52,9 +52,9 @@ public: ScScript *_waitingScript; virtual bool listen(BaseScriptHolder *param1, uint32 param2); typedef enum { - EVENT_PREV, - EVENT_NEXT, - EVENT_RESPONSE + EVENT_PREV, + EVENT_NEXT, + EVENT_RESPONSE } TResponseEvent; bool weedResponses(); diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 359215ee8f..d47cbb446e 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -222,7 +222,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } else { for (int i = 0; i < _talkSprites.getSize(); i++) { if (scumm_stricmp(_talkSprites[i]->getFilename(), filename) == 0) { - if (_currentSprite == _talkSprites[i]) + if (_currentSprite == _talkSprites[i]) setCurrent = true; if (_tempSprite2 == _talkSprites[i]) setTemp2 = true; @@ -282,7 +282,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS // set new if (ex) _talkSpritesEx.add(spr); - else + else _talkSprites.add(spr); stack->pushBool(true); diff --git a/engines/wintermute/ad/ad_types.h b/engines/wintermute/ad/ad_types.h index b88d6fe259..18892919c6 100644 --- a/engines/wintermute/ad/ad_types.h +++ b/engines/wintermute/ad/ad_types.h @@ -33,19 +33,19 @@ namespace WinterMute { typedef enum { GAME_NORMAL, - GAME_WAITING_RESPONSE + GAME_WAITING_RESPONSE } TGameStateEx; typedef enum { OBJECT_ENTITY, - OBJECT_REGION, - OBJECT_ACTOR, - OBJECT_NONE + OBJECT_REGION, + OBJECT_ACTOR, + OBJECT_NONE } TObjectType; typedef enum { ENTITY_NORMAL, - ENTITY_SOUND + ENTITY_SOUND } TEntityType; typedef enum { @@ -66,40 +66,40 @@ typedef enum { typedef enum { DIRECT_WALK_NONE, - DIRECT_WALK_FW, - DIRECT_WALK_BK + DIRECT_WALK_FW, + DIRECT_WALK_BK } TDirectWalkMode; typedef enum { DIRECT_TURN_NONE, - DIRECT_TURN_CW, - DIRECT_TURN_CCW + DIRECT_TURN_CW, + DIRECT_TURN_CCW } TDirectTurnMode; typedef enum { RESPONSE_TEXT, - RESPONSE_ICON + RESPONSE_ICON } TResponseStyle; typedef enum { RESPONSE_ALWAYS, - RESPONSE_ONCE, - RESPONSE_ONCE_GAME + RESPONSE_ONCE, + RESPONSE_ONCE_GAME } TResponseType; typedef enum { TALK_SKIP_LEFT = 0, - TALK_SKIP_RIGHT = 1, - TALK_SKIP_BOTH = 2, - TALK_SKIP_NONE = 3 + TALK_SKIP_RIGHT = 1, + TALK_SKIP_BOTH = 2, + TALK_SKIP_NONE = 3 } TTalkSkipButton; typedef enum { GEOM_WAYPOINT, - GEOM_WALKPLANE, - GEOM_BLOCKED, - GEOM_GENERIC + GEOM_WALKPLANE, + GEOM_BLOCKED, + GEOM_GENERIC } TGeomNodeType; } // end of namespace WinterMute -- cgit v1.2.3 From ef11f9d0c53cbdd9d88a99143de6f43f34d7e24d Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 15:59:26 +0200 Subject: WINTERMUTE: Run Astyle with add-braces to break one-line statements into easier-to-read-code. --- engines/wintermute/ad/ad_actor.cpp | 408 +++++++++++------ engines/wintermute/ad/ad_entity.cpp | 270 +++++++---- engines/wintermute/ad/ad_game.cpp | 614 +++++++++++++++++-------- engines/wintermute/ad/ad_inventory.cpp | 35 +- engines/wintermute/ad/ad_inventory_box.cpp | 35 +- engines/wintermute/ad/ad_item.cpp | 143 ++++-- engines/wintermute/ad/ad_layer.cpp | 83 ++-- engines/wintermute/ad/ad_node_state.cpp | 53 ++- engines/wintermute/ad/ad_object.cpp | 248 ++++++---- engines/wintermute/ad/ad_object.h | 2 +- engines/wintermute/ad/ad_path.cpp | 21 +- engines/wintermute/ad/ad_region.cpp | 24 +- engines/wintermute/ad/ad_response.cpp | 8 +- engines/wintermute/ad/ad_response_box.cpp | 151 +++++-- engines/wintermute/ad/ad_response_context.cpp | 8 +- engines/wintermute/ad/ad_response_context.h | 2 +- engines/wintermute/ad/ad_rot_level.cpp | 8 +- engines/wintermute/ad/ad_scale_level.cpp | 8 +- engines/wintermute/ad/ad_scene.cpp | 625 ++++++++++++++++++-------- engines/wintermute/ad/ad_scene_state.cpp | 16 +- engines/wintermute/ad/ad_sentence.cpp | 102 +++-- engines/wintermute/ad/ad_sprite_set.cpp | 100 +++-- engines/wintermute/ad/ad_talk_def.cpp | 64 ++- engines/wintermute/ad/ad_talk_holder.cpp | 107 +++-- engines/wintermute/ad/ad_talk_node.cpp | 82 ++-- engines/wintermute/ad/ad_waypoint_group.cpp | 26 +- 26 files changed, 2267 insertions(+), 976 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index fe1948d3a8..d1e03eac3a 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -129,7 +129,9 @@ bool AdActor::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); + } delete[] buffer; @@ -235,7 +237,9 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_X: @@ -255,7 +259,7 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - SetFont((char *)params); + setFont((char *)params); break; case TOKEN_SCALABLE: @@ -285,44 +289,62 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { delete _walkSprite; _walkSprite = NULL; spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC; - else _walkSprite = spr; + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) { + cmd = PARSERR_GENERIC; + } else { + _walkSprite = spr; + } break; case TOKEN_TALK: spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } break; case TOKEN_TALK_SPECIAL: spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } break; case TOKEN_STAND: delete _standSprite; _standSprite = NULL; spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) cmd = PARSERR_GENERIC; - else _standSprite = spr; + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _standSprite = spr; + } break; case TOKEN_TURN_LEFT: delete _turnLeftSprite; _turnLeftSprite = NULL; spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; - else _turnLeftSprite = spr; + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { + cmd = PARSERR_GENERIC; + } else { + _turnLeftSprite = spr; + } break; case TOKEN_TURN_RIGHT: delete _turnRightSprite; _turnRightSprite = NULL; spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; - else _turnRightSprite = spr; + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { + cmd = PARSERR_GENERIC; + } else { + _turnRightSprite = spr; + } break; case TOKEN_SCRIPT: @@ -426,9 +448,12 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ANIMATION: { - AdSpriteSet *Anim = new AdSpriteSet(_gameRef, this); - if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) cmd = PARSERR_GENERIC; - else _anims.add(Anim); + AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); + if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } else { + _anims.add(anim); + } } break; } @@ -438,7 +463,9 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { - if (spr) delete spr; + if (spr) { + delete spr; + } _gameRef->LOG(0, "Error loading ACTOR definition"); return STATUS_FAILED; } @@ -482,7 +509,9 @@ void AdActor::turnTo(TDirection dir) { ////////////////////////////////////////////////////////////////////////// void AdActor::goTo(int x, int y, TDirection afterWalkDir) { _afterWalkDir = afterWalkDir; - if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) return; + if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) { + return; + } _path->reset(); _path->setReady(false); @@ -499,11 +528,16 @@ void AdActor::goTo(int x, int y, TDirection afterWalkDir) { ////////////////////////////////////////////////////////////////////////// bool AdActor::display() { - if (_active) updateSounds(); + if (_active) { + updateSounds(); + } uint32 alpha; - if (_alphaColor != 0) alpha = _alphaColor; - else alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; + if (_alphaColor != 0) { + alpha = _alphaColor; + } else { + alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; + } float scaleX, scaleY; getScale(&scaleX, &scaleY); @@ -511,15 +545,24 @@ bool AdActor::display() { float rotate; if (_rotatable) { - if (_rotateValid) rotate = _rotate; - else rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; - } else rotate = 0.0f; + if (_rotateValid) { + rotate = _rotate; + } else { + rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } + } else { + rotate = 0.0f; + } - if (_active) displaySpriteAttachments(true); + if (_active) { + displaySpriteAttachments(true); + } if (_currentSprite && _active) { bool reg = _registrable; - if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) reg = false; + if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) { + reg = false; + } _currentSprite->display(_posX, _posY, @@ -532,8 +575,12 @@ bool AdActor::display() { } - if (_active) displaySpriteAttachments(false); - if (_active && _partEmitter) _partEmitter->display(); + if (_active) { + displaySpriteAttachments(false); + } + if (_active && _partEmitter) { + _partEmitter->display(); + } return STATUS_OK; @@ -567,17 +614,22 @@ bool AdActor::update() { _currentSprite = _animSprite2; } - if (_sentence && _state != STATE_TALKING) _sentence->finish(); + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } // default: stand animation if (!_currentSprite) { - if (_sprite) _currentSprite = _sprite; - else { + if (_sprite) { + _currentSprite = _sprite; + } else { if (_standSprite) { _currentSprite = _standSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } } } } @@ -598,8 +650,11 @@ bool AdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_TURNING_LEFT: if (_tempSprite2 == NULL || _tempSprite2->_finished) { - if (_dir > 0) _dir = (TDirection)(_dir - 1); - else _dir = (TDirection)(NUM_DIRECTIONS - 1); + if (_dir > 0) { + _dir = (TDirection)(_dir - 1); + } else { + _dir = (TDirection)(NUM_DIRECTIONS - 1); + } if (_dir == _targetDir) { _tempSprite2 = NULL; @@ -609,17 +664,23 @@ bool AdActor::update() { if (_turnLeftSprite) { _tempSprite2 = _turnLeftSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_turnLeftAnimName); - if (Anim) _tempSprite2 = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_turnLeftAnimName); + if (anim) { + _tempSprite2 = anim->getSprite(_dir); + } } if (_tempSprite2) { _tempSprite2->reset(); - if (_tempSprite2->_looping) _tempSprite2->_looping = false; + if (_tempSprite2->_looping) { + _tempSprite2->_looping = false; + } } _currentSprite = _tempSprite2; } - } else _currentSprite = _tempSprite2; + } else { + _currentSprite = _tempSprite2; + } break; @@ -628,7 +689,9 @@ bool AdActor::update() { if (_tempSprite2 == NULL || _tempSprite2->_finished) { _dir = (TDirection)(_dir + 1); - if ((int)_dir >= (int)NUM_DIRECTIONS) _dir = (TDirection)(0); + if ((int)_dir >= (int)NUM_DIRECTIONS) { + _dir = (TDirection)(0); + } if (_dir == _targetDir) { _tempSprite2 = NULL; @@ -638,32 +701,41 @@ bool AdActor::update() { if (_turnRightSprite) { _tempSprite2 = _turnRightSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_turnRightAnimName); - if (Anim) _tempSprite2 = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_turnRightAnimName); + if (anim) { + _tempSprite2 = anim->getSprite(_dir); + } } if (_tempSprite2) { _tempSprite2->reset(); - if (_tempSprite2->_looping) _tempSprite2->_looping = false; + if (_tempSprite2->_looping) { + _tempSprite2->_looping = false; + } } _currentSprite = _tempSprite2; } - } else _currentSprite = _tempSprite2; + } else { + _currentSprite = _tempSprite2; + } break; ////////////////////////////////////////////////////////////////////////// case STATE_SEARCHING_PATH: // keep asking scene for the path - if (((AdGame *)_gameRef)->_scene->getPath(BasePoint(_posX, _posY), *_targetPoint, _path, this)) + if (((AdGame *)_gameRef)->_scene->getPath(BasePoint(_posX, _posY), *_targetPoint, _path, this)) { _state = STATE_WAITING_PATH; + } break; ////////////////////////////////////////////////////////////////////////// case STATE_WAITING_PATH: // wait until the scene finished the path - if (_path->_ready) followPath(); + if (_path->_ready) { + followPath(); + } break; @@ -676,7 +748,9 @@ bool AdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_TALKING: { _sentence->update(_dir); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { @@ -703,13 +777,16 @@ bool AdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_READY: if (!_animSprite && !_animSprite2) { - if (_sprite) _currentSprite = _sprite; - else { + if (_sprite) { + _currentSprite = _sprite; + } else { if (_standSprite) { _currentSprite = _standSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } } } } @@ -745,7 +822,9 @@ void AdActor::followPath() { // skip current position _path->getFirst(); while (_path->getCurrent() != NULL) { - if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) break; + if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) { + break; + } _path->getNext(); } @@ -754,8 +833,11 @@ void AdActor::followPath() { _state = STATE_FOLLOWING_PATH;; initLine(BasePoint(_posX, _posY), *_path->getCurrent()); } else { - if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); - else _state = STATE_READY; + if (_afterWalkDir != DI_NONE) { + turnTo(_afterWalkDir); + } else { + _state = STATE_READY; + } } } @@ -765,14 +847,20 @@ void AdActor::getNextStep() { if (_walkSprite) { _currentSprite = _walkSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_walkAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_walkAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } } - if (!_currentSprite) return; + if (!_currentSprite) { + return; + } _currentSprite->GetCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (!_currentSprite->_changed) return; + if (!_currentSprite->_changed) { + return; + } int maxStepX, maxStepY; @@ -813,12 +901,15 @@ void AdActor::getNextStep() { _posY = _targetPoint->y; _path->reset(); - if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); - else { + if (_afterWalkDir != DI_NONE) { + turnTo(_afterWalkDir); + } else { _state = _nextState; _nextState = STATE_READY; } - } else initLine(BasePoint(_posX, _posY), *_path->getCurrent()); + } else { + initLine(BasePoint(_posX, _posY), *_path->getCurrent()); + } } } @@ -853,7 +944,9 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, int X = stack->pop()->getInt(); int Y = stack->pop()->getInt(); goTo(X, Y); - if (strcmp(name, "GoToAsync") != 0) script->waitForExclusive(this); + if (strcmp(name, "GoToAsync") != 0) { + script->waitForExclusive(this); + } stack->pushNULL(); return STATUS_OK; } @@ -863,22 +956,27 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GoToObject") == 0 || strcmp(name, "GoToObjectAsync") == 0) { stack->correctParams(1); - ScValue *Val = stack->pop(); - if (!Val->isNative()) { + ScValue *val = stack->pop(); + if (!val->isNative()) { script->runtimeError("actor.%s method accepts an entity refrence only", name); stack->pushNULL(); return STATUS_OK; } - AdObject *Obj = (AdObject *)Val->getNative(); - if (!Obj || Obj->_type != OBJECT_ENTITY) { + AdObject *obj = (AdObject *)val->getNative(); + if (!obj || obj->_type != OBJECT_ENTITY) { script->runtimeError("actor.%s method accepts an entity refrence only", name); stack->pushNULL(); return STATUS_OK; } - AdEntity *Ent = (AdEntity *)Obj; - if (Ent->_walkToX == 0 && Ent->_walkToY == 0) goTo(Ent->_posX, Ent->_posY); - else goTo(Ent->_walkToX, Ent->_walkToY, Ent->_walkToDir); - if (strcmp(name, "GoToObjectAsync") != 0) script->waitForExclusive(this); + AdEntity *ent = (AdEntity *)obj; + if (ent->_walkToX == 0 && ent->_walkToY == 0) { + goTo(ent->_posX, ent->_posY); + } else { + goTo(ent->_walkToX, ent->_walkToY, ent->_walkToDir); + } + if (strcmp(name, "GoToObjectAsync") != 0) { + script->waitForExclusive(this); + } stack->pushNULL(); return STATUS_OK; } @@ -898,11 +996,15 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, dir = (int)angleToDirection(angle); } // otherwise turn to direction - else dir = val->getInt(); + else { + dir = val->getInt(); + } if (dir >= 0 && dir < NUM_DIRECTIONS) { turnTo((TDirection)dir); - if (strcmp(name, "TurnToAsync") != 0) script->waitForExclusive(this); + if (strcmp(name, "TurnToAsync") != 0) { + script->waitForExclusive(this); + } } stack->pushNULL(); return STATUS_OK; @@ -937,9 +1039,15 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, for (int i = 0; i < _anims.getSize(); i++) { if (scumm_stricmp(_anims[i]->getName(), AnimName) == 0) { // invalidate sprites in use - if (_anims[i]->containsSprite(_tempSprite2)) _tempSprite2 = NULL; - if (_anims[i]->containsSprite(_currentSprite)) _currentSprite = NULL; - if (_anims[i]->containsSprite(_animSprite2)) _animSprite2 = NULL; + if (_anims[i]->containsSprite(_tempSprite2)) { + _tempSprite2 = NULL; + } + if (_anims[i]->containsSprite(_currentSprite)) { + _currentSprite = NULL; + } + if (_anims[i]->containsSprite(_animSprite2)) { + _animSprite2 = NULL; + } delete _anims[i]; _anims[i] = NULL; @@ -960,9 +1068,9 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *AnimName = stack->pop()->getString(); stack->pushBool(getAnimByName(AnimName) != NULL); return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } - - else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } @@ -1022,9 +1130,9 @@ ScValue *AdActor::scGetProperty(const char *name) { else if (strcmp(name, "TurnRightAnimName") == 0) { _scValue->setString(_turnRightAnimName); return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); } - - else return AdTalkHolder::scGetProperty(name); } @@ -1035,7 +1143,9 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "Direction") == 0) { int dir = value->getInt(); - if (dir >= 0 && dir < NUM_DIRECTIONS) _dir = (TDirection)dir; + if (dir >= 0 && dir < NUM_DIRECTIONS) { + _dir = (TDirection)dir; + } return STATUS_OK; } @@ -1043,8 +1153,11 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // TalkAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TalkAnimName") == 0) { - if (value->isNULL()) _talkAnimName = "talk"; - else _talkAnimName = value->getString(); + if (value->isNULL()) { + _talkAnimName = "talk"; + } else { + _talkAnimName = value->getString(); + } return STATUS_OK; } @@ -1052,8 +1165,11 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // WalkAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "WalkAnimName") == 0) { - if (value->isNULL()) _walkAnimName = "walk"; - else _walkAnimName = value->getString(); + if (value->isNULL()) { + _walkAnimName = "walk"; + } else { + _walkAnimName = value->getString(); + } return STATUS_OK; } @@ -1061,8 +1177,11 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // IdleAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "IdleAnimName") == 0) { - if (value->isNULL()) _idleAnimName = "idle"; - else _idleAnimName = value->getString(); + if (value->isNULL()) { + _idleAnimName = "idle"; + } else { + _idleAnimName = value->getString(); + } return STATUS_OK; } @@ -1070,8 +1189,11 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // TurnLeftAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TurnLeftAnimName") == 0) { - if (value->isNULL()) _turnLeftAnimName = "turnleft"; - else _turnLeftAnimName = value->getString(); + if (value->isNULL()) { + _turnLeftAnimName = "turnleft"; + } else { + _turnLeftAnimName = value->getString(); + } return STATUS_OK; } @@ -1079,12 +1201,15 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // TurnRightAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TurnRightAnimName") == 0) { - if (value->isNULL()) _turnRightAnimName = "turnright"; - else _turnRightAnimName = value->getString(); + if (value->isNULL()) { + _turnRightAnimName = "turnright"; + } else { + _turnRightAnimName = value->getString(); + } return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); } - - else return AdTalkHolder::scSetProperty(name, value); } @@ -1107,37 +1232,46 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { _gameRef->LOG(res, "AdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); delete _animSprite; _animSprite = NULL; - } else return _animSprite; + } else { + return _animSprite; + } } } // old way - if (_talkSprites.getSize() > 0 || _talkSpritesEx.getSize() > 0) + if (_talkSprites.getSize() > 0 || _talkSpritesEx.getSize() > 0) { return getTalkStanceOld(stance); + } // new way BaseSprite *ret = NULL; // do we have an animation with this name? - AdSpriteSet *Anim = getAnimByName(stance); - if (Anim) ret = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(stance); + if (anim) { + ret = anim->getSprite(_dir); + } // not - get a random talk if (!ret) { - BaseArray TalkAnims; + BaseArray talkAnims; for (int i = 0; i < _anims.getSize(); i++) { - if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) - TalkAnims.add(_anims[i]); + if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) { + talkAnims.add(_anims[i]); + } } - if (TalkAnims.getSize() > 0) { - int rnd = g_wintermute->randInt(0, TalkAnims.getSize() - 1); - ret = TalkAnims[rnd]->getSprite(_dir); + if (talkAnims.getSize() > 0) { + int rnd = g_wintermute->randInt(0, talkAnims.getSize() - 1); + ret = talkAnims[rnd]->getSprite(_dir); } else { - if (_standSprite) ret = _standSprite->getSprite(_dir); - else { - Anim = getAnimByName(_idleAnimName); - if (Anim) ret = Anim->getSprite(_dir); + if (_standSprite) { + ret = _standSprite->getSprite(_dir); + } else { + anim = getAnimByName(_idleAnimName); + if (anim) { + ret = anim->getSprite(_dir); + } } } } @@ -1169,8 +1303,9 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { // not a valid stance? get a random one if (ret == NULL) { - if (_talkSprites.getSize() < 1) ret = _standSprite->getSprite(_dir); - else { + if (_talkSprites.getSize() < 1) { + ret = _standSprite->getSprite(_dir); + } else { // TODO: remember last int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); ret = _talkSprites[rnd]->getSprite(_dir); @@ -1218,14 +1353,23 @@ bool AdActor::persist(BasePersistenceManager *persistMgr) { TDirection AdActor::angleToDirection(int angle) { TDirection ret = DI_DOWN;; - if (angle > -112 && angle <= -67) ret = DI_UP; - else if (angle > -67 && angle <= -22) ret = DI_UPRIGHT; - else if (angle > -22 && angle <= 22) ret = DI_RIGHT; - else if (angle > 22 && angle <= 67) ret = DI_DOWNRIGHT; - else if (angle > 67 && angle <= 112) ret = DI_DOWN; - else if (angle > 112 && angle <= 157) ret = DI_DOWNLEFT; - else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) ret = DI_LEFT; - else if (angle > -157 && angle <= -112) ret = DI_UPLEFT; + if (angle > -112 && angle <= -67) { + ret = DI_UP; + } else if (angle > -67 && angle <= -22) { + ret = DI_UPRIGHT; + } else if (angle > -22 && angle <= 22) { + ret = DI_RIGHT; + } else if (angle > 22 && angle <= 67) { + ret = DI_DOWNRIGHT; + } else if (angle > 67 && angle <= 112) { + ret = DI_DOWN; + } else if (angle > 112 && angle <= 157) { + ret = DI_DOWNLEFT; + } else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) { + ret = DI_LEFT; + } else if (angle > -157 && angle <= -112) { + ret = DI_UPLEFT; + } return ret; } @@ -1235,10 +1379,13 @@ TDirection AdActor::angleToDirection(int angle) { int AdActor::getHeight() { // if no current sprite is set, set some if (_currentSprite == NULL) { - if (_standSprite) _currentSprite = _standSprite->getSprite(_dir); - else { - AdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } } } // and get height @@ -1249,8 +1396,9 @@ int AdActor::getHeight() { ////////////////////////////////////////////////////////////////////////// AdSpriteSet *AdActor::getAnimByName(const Common::String &animName) { for (int i = 0; i < _anims.getSize(); i++) { - if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) + if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) { return _anims[i]; + } } return NULL; } @@ -1278,11 +1426,13 @@ bool AdActor::mergeAnims(const char *animsFilename) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_ANIMATION: { - AdSpriteSet *Anim = new AdSpriteSet(_gameRef, this); - if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) { + AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); + if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; Ret = STATUS_FAILED; - } else _anims.add(Anim); + } else { + _anims.add(anim); + } } break; } @@ -1294,9 +1444,9 @@ bool AdActor::mergeAnims(const char *animsFilename) { ////////////////////////////////////////////////////////////////////////// bool AdActor::playAnim(const char *filename) { // if we have an anim with this name, use it - AdSpriteSet *Anim = getAnimByName(filename); - if (Anim) { - _animSprite2 = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(filename); + if (anim) { + _animSprite2 = anim->getSprite(_dir); if (_animSprite2) { _animSprite2->reset(); _state = STATE_PLAYING_ANIM_SET; diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 98fb296bf5..aa30a0096c 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -94,7 +94,9 @@ bool AdEntity::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ENTITY file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ENTITY file '%s'", filename); + } delete[] buffer; @@ -212,7 +214,9 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_X: @@ -227,22 +231,31 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { delete _sprite; _sprite = NULL; spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params))) cmd = PARSERR_GENERIC; - else _sprite = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } else { + _sprite = spr; + } } break; case TOKEN_TALK: { spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } } break; case TOKEN_TALK_SPECIAL: { spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } } break; @@ -259,7 +272,7 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - SetFont((char *)params); + setFont((char *)params); break; case TOKEN_SCALABLE: @@ -316,11 +329,14 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_REGION: { - if (_region) _gameRef->unregisterObject(_region); + if (_region) { + _gameRef->unregisterObject(_region); + } _region = NULL; BaseRegion *rgn = new BaseRegion(_gameRef); - if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) cmd = PARSERR_GENERIC; - else { + if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } else { _region = rgn; _gameRef->registerObject(_region); } @@ -379,10 +395,15 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { _sprite = NULL; if (_gameRef->_editorMode) { spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) cmd = PARSERR_GENERIC; - else _sprite = spr; + if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) { + cmd = PARSERR_GENERIC; + } else { + _sprite = spr; + } + } + if (_gameRef->_editorMode) { + _editorOnly = true; } - if (_gameRef->_editorMode) _editorOnly = true; _zoomable = false; _rotatable = false; _registrable = _gameRef->_editorMode; @@ -443,8 +464,12 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { 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; + if (i < 0) { + i = 0; + } + if (i >= NUM_DIRECTIONS) { + i = DI_NONE; + } _walkToDir = (TDirection)i; } break; @@ -456,7 +481,9 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading ENTITY definition"); - if (spr) delete spr; + if (spr) { + delete spr; + } return STATUS_FAILED; } @@ -472,7 +499,9 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { _alphaColor = BYTETORGBA(ar, ag, ab, alpha); _state = STATE_READY; - if (_item && ((AdGame *)_gameRef)->isItemTaken(_item)) _active = false; + if (_item && ((AdGame *)_gameRef)->isItemTaken(_item)) { + _active = false; + } return STATUS_OK; } @@ -483,43 +512,55 @@ bool AdEntity::display() { if (_active) { updateSounds(); - uint32 Alpha; - if (_alphaColor != 0) Alpha = _alphaColor; - else Alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; + uint32 alpha; + if (_alphaColor != 0) { + alpha = _alphaColor; + } else { + alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; + } - float ScaleX, ScaleY; - getScale(&ScaleX, &ScaleY); + float scaleX, scaleY; + getScale(&scaleX, &scaleY); - float Rotate; + float rotate; if (_rotatable) { - if (_rotateValid) Rotate = _rotate; - else Rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; - } else Rotate = 0.0f; + if (_rotateValid) { + rotate = _rotate; + } else { + rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } + } else { + rotate = 0.0f; + } - bool Reg = _registrable; - if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) Reg = false; + bool reg = _registrable; + if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) { + reg = false; + } - if (_region && (Reg || _editorAlwaysRegister)) { + if (_region && (reg || _editorAlwaysRegister)) { _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); } displaySpriteAttachments(true); if (_theora && (_theora->isPlaying() || _theora->isPaused())) { - _theora->display(Alpha); + _theora->display(alpha); } else if (_currentSprite) { _currentSprite->display(_posX, _posY, - (Reg || _editorAlwaysRegister) ? _registerAlias : NULL, - ScaleX, - ScaleY, - Alpha, - Rotate, + (reg || _editorAlwaysRegister) ? _registerAlias : NULL, + scaleX, + scaleY, + alpha, + rotate, _blendMode); } displaySpriteAttachments(false); - if (_partEmitter) _partEmitter->display(_region); + if (_partEmitter) { + _partEmitter->display(_region); + } } return STATUS_OK; @@ -541,10 +582,14 @@ bool AdEntity::update() { _currentSprite = _animSprite; } - if (_sentence && _state != STATE_TALKING) _sentence->finish(); + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } // default: stand animation - if (!_currentSprite) _currentSprite = _sprite; + if (!_currentSprite) { + _currentSprite = _sprite; + } switch (_state) { ////////////////////////////////////////////////////////////////////////// @@ -554,14 +599,17 @@ bool AdEntity::update() { ////////////////////////////////////////////////////////////////////////// case STATE_READY: - if (!_animSprite) + if (!_animSprite) { _currentSprite = _sprite; + } break; ////////////////////////////////////////////////////////////////////////// case STATE_TALKING: { _sentence->update(); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { @@ -630,8 +678,11 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (strcmp(name, "StopSound") == 0 && _subtype == ENTITY_SOUND) { stack->correctParams(0); - if (DID_FAIL(stopSFX(false))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(stopSFX(false))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -648,7 +699,9 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _theora; _theora = new VideoTheoraPlayer(_gameRef); if (_theora && DID_SUCCEED(_theora->initialize(filename))) { - if (!valAlpha->isNULL()) _theora->setAlphaImage(valAlpha->getString()); + if (!valAlpha->isNULL()) { + _theora->setAlphaImage(valAlpha->getString()); + } _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); //if (_scale>=0) _theora->_playZoom = _scale; stack->pushBool(true); @@ -670,7 +723,9 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _theora; _theora = NULL; stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -680,8 +735,11 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "IsTheoraPlaying") == 0) { stack->correctParams(0); - if (_theora && _theora->isPlaying()) stack->pushBool(true); - else stack->pushBool(false); + if (_theora && _theora->isPlaying()) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -694,7 +752,9 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_theora && _theora->isPlaying()) { _theora->pause(); stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -707,7 +767,9 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_theora && _theora->isPaused()) { _theora->resume(); stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -717,8 +779,11 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "IsTheoraPaused") == 0) { stack->correctParams(0); - if (_theora && _theora->isPaused()) stack->pushBool(true); - else stack->pushBool(false); + if (_theora && _theora->isPaused()) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -733,8 +798,11 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack _region = new BaseRegion(_gameRef); _gameRef->registerObject(_region); } - if (_region) stack->pushNative(_region, true); - else stack->pushNULL(); + if (_region) { + stack->pushNative(_region, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -748,12 +816,14 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack _gameRef->unregisterObject(_region); _region = NULL; stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } - - else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } @@ -773,8 +843,11 @@ ScValue *AdEntity::scGetProperty(const char *name) { // Item ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Item") == 0) { - if (_item) _scValue->setString(_item); - else _scValue->setNULL(); + if (_item) { + _scValue->setString(_item); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -783,10 +856,11 @@ ScValue *AdEntity::scGetProperty(const char *name) { // Subtype (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Subtype") == 0) { - if (_subtype == ENTITY_SOUND) + if (_subtype == ENTITY_SOUND) { _scValue->setString("sound"); - else + } else { _scValue->setString("normal"); + } return _scValue; } @@ -819,12 +893,15 @@ ScValue *AdEntity::scGetProperty(const char *name) { // Region (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Region") == 0) { - if (_region) _scValue->setNative(_region, true); - else _scValue->setNULL(); + if (_region) { + _scValue->setNative(_region, true); + } else { + _scValue->setNULL(); + } return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); } - - else return AdTalkHolder::scGetProperty(name); } @@ -860,11 +937,13 @@ bool AdEntity::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "WalkToDirection") == 0) { int dir = value->getInt(); - if (dir >= 0 && dir < NUM_DIRECTIONS) _walkToDir = (TDirection)dir; + if (dir >= 0 && dir < NUM_DIRECTIONS) { + _walkToDir = (TDirection)dir; + } return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); } - - else return AdTalkHolder::scSetProperty(name, value); } @@ -878,8 +957,9 @@ const char *AdEntity::scToString() { bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "ENTITY {\n"); buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - if (_subtype == ENTITY_SOUND) + if (_subtype == ENTITY_SOUND) { buffer->putTextIndent(indent + 2, "SUBTYPE=\"SOUND\"\n"); + } buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "X=%d\n", _posX); @@ -888,23 +968,30 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { 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) + if (_ignoreItems) { buffer->putTextIndent(indent + 2, "IGNORE_ITEMS=%s\n", _ignoreItems ? "TRUE" : "FALSE"); - if (_rotatable) + } + if (_rotatable) { buffer->putTextIndent(indent + 2, "ROTATABLE=%s\n", _rotatable ? "TRUE" : "FALSE"); + } - if (!_autoSoundPanning) + if (!_autoSoundPanning) { buffer->putTextIndent(indent + 2, "SOUND_PANNING=%s\n", _autoSoundPanning ? "TRUE" : "FALSE"); + } - if (!_saveState) + 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); + 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) + if (_walkToDir != DI_NONE) { buffer->putTextIndent(indent + 2, "WALK_TO_DIR=%d\n", (int)_walkToDir); + } int i; @@ -912,8 +999,9 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } - if (_subtype == ENTITY_NORMAL && _sprite && _sprite->getFilename()) + if (_subtype == ENTITY_NORMAL && _sprite && _sprite->getFilename()) { buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->getFilename()); + } if (_subtype == ENTITY_SOUND && _sFX && _sFX->_soundFilename) { buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sFX->_soundFilename); @@ -922,29 +1010,39 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { } - if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) + if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) { buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alphaColor), RGBCOLGetG(_alphaColor), RGBCOLGetB(_alphaColor)); + } - if (RGBCOLGetA(_alphaColor) != 0) + if (RGBCOLGetA(_alphaColor) != 0) { buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alphaColor)); + } - if (_scale >= 0) + if (_scale >= 0) { buffer->putTextIndent(indent + 2, "SCALE = %d\n", (int)_scale); + } - if (_relativeScale != 0) + if (_relativeScale != 0) { buffer->putTextIndent(indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale); + } - if (_font && _font->getFilename()) + if (_font && _font->getFilename()) { buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); + } - if (_cursor && _cursor->getFilename()) + if (_cursor && _cursor->getFilename()) { buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } AdTalkHolder::saveAsText(buffer, indent + 2); - if (_region) _region->saveAsText(buffer, indent + 2); + if (_region) { + _region->saveAsText(buffer, indent + 2); + } - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } AdObject::saveAsText(buffer, indent + 2); @@ -959,7 +1057,9 @@ int AdEntity::getHeight() { if (_region && !_sprite) { return _region->_rect.bottom - _region->_rect.top; } else { - if (_currentSprite == NULL) _currentSprite = _sprite; + if (_currentSprite == NULL) { + _currentSprite = _sprite; + } return AdObject::getHeight(); } } diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 259fc175ae..a6452e8837 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -142,7 +142,9 @@ bool AdGame::cleanup() { _scene = NULL; // remove items - for (i = 0; i < _items.getSize(); i++) _gameRef->unregisterObject(_items[i]); + for (i = 0; i < _items.getSize(); i++) { + _gameRef->unregisterObject(_items[i]); + } _items.removeAll(); @@ -181,13 +183,19 @@ bool AdGame::cleanup() { delete _sceneViewport; _sceneViewport = NULL; - for (i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; + for (i = 0; i < _sceneStates.getSize(); i++) { + delete _sceneStates[i]; + } _sceneStates.removeAll(); - for (i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + for (i = 0; i < _responsesBranch.getSize(); i++) { + delete _responsesBranch[i]; + } _responsesBranch.removeAll(); - for (i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; + for (i = 0; i < _responsesGame.getSize(); i++) { + delete _responsesGame[i]; + } _responsesGame.removeAll(); return BaseGame::cleanup(); @@ -207,9 +215,13 @@ bool AdGame::initLoop() { bool res; res = BaseGame::initLoop(); - if (DID_FAIL(res)) return res; + if (DID_FAIL(res)) { + return res; + } - if (_scene) res = _scene->initLoop(); + if (_scene) { + res = _scene->initLoop(); + } _sentences.removeAll(); @@ -228,8 +240,10 @@ bool AdGame::addObject(AdObject *object) { bool AdGame::removeObject(AdObject *object) { // in case the user called Scene.CreateXXX() and Game.DeleteXXX() if (_scene) { - bool Res = _scene->removeObject(object); - if (DID_SUCCEED(Res)) return Res; + bool res = _scene->removeObject(object); + if (DID_SUCCEED(res)) { + return res; + } } for (int i = 0; i < _objects.getSize(); i++) { @@ -253,23 +267,31 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) { setPrevSceneName(_scene->getName()); setPrevSceneFilename(_scene->getFilename()); - if (!_tempDisableSaveState) _scene->saveState(); + if (!_tempDisableSaveState) { + _scene->saveState(); + } _tempDisableSaveState = false; } if (_scene) { // reset objects - for (int i = 0; i < _objects.getSize(); i++) _objects[i]->reset(); + for (int i = 0; i < _objects.getSize(); i++) { + _objects[i]->reset(); + } // reset scene properties _scene->_sFXVolume = 100; - if (_scene->_scProp) _scene->_scProp->cleanup(); + if (_scene->_scProp) { + _scene->_scProp->cleanup(); + } bool ret; if (_initialScene && _debugDebugMode && _debugStartupScene) { _initialScene = false; ret = _scene->loadFile(_debugStartupScene); - } else ret = _scene->loadFile(filename); + } else { + ret = _scene->loadFile(filename); + } if (DID_SUCCEED(ret)) { // invalidate references to the original scene @@ -280,9 +302,13 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) { _scene->loadState(); } - if (fadeIn) _gameRef->_transMgr->start(TRANSITION_FADE_IN); + if (fadeIn) { + _gameRef->_transMgr->start(TRANSITION_FADE_IN); + } return ret; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -295,8 +321,11 @@ void AdGame::addSentence(AdSentence *sentence) { ////////////////////////////////////////////////////////////////////////// bool AdGame::displaySentences(bool frozen) { for (int i = 0; i < _sentences.getSize(); i++) { - if (frozen && _sentences[i]->_freezable) continue; - else _sentences[i]->display(); + if (frozen && _sentences[i]->_freezable) { + continue; + } else { + _sentences[i]->display(); + } } return STATUS_OK; } @@ -307,7 +336,9 @@ void AdGame::finishSentences() { for (int i = 0; i < _sentences.getSize(); i++) { if (_sentences[i]->CanSkip()) { _sentences[i]->_duration = 0; - if (_sentences[i]->_sound) _sentences[i]->_sound->stop(); + if (_sentences[i]->_sound) { + _sentences[i]->_sound->stop(); + } } } } @@ -330,7 +361,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, bool transIn = valFadeIn->isNULL() ? true : valFadeIn->getBool(); scheduleChangeScene(filename, transIn); - if (transOut) _transMgr->start(TRANSITION_FADE_OUT, true); + if (transOut) { + _transMgr->start(TRANSITION_FADE_OUT, true); + } stack->pushNULL(); @@ -383,7 +416,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdObject *obj = (AdObject *)val->getNative(); removeObject(obj); - if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + if (val->getType() == VAL_VARIABLE_REF) { + val->setNULL(); + } stack->pushNULL(); return STATUS_OK; @@ -398,7 +433,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdEntity *ent = new AdEntity(_gameRef); addObject(ent); - if (!val->isNULL()) ent->setName(val->getString()); + if (!val->isNULL()) { + ent->setName(val->getString()); + } stack->pushNative(ent, true); return STATUS_OK; } @@ -412,7 +449,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdItem *item = new AdItem(_gameRef); addItem(item); - if (!val->isNULL()) item->setName(val->getString()); + if (!val->isNULL()) { + item->setName(val->getString()); + } stack->pushNative(item, true); return STATUS_OK; } @@ -425,8 +464,11 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdItem *item = NULL; - if (val->isNative()) item = (AdItem *)val->getNative(); - else item = getItemByName(val->getString()); + if (val->isNative()) { + item = (AdItem *)val->getNative(); + } else { + item = getItemByName(val->getString()); + } if (item) { deleteItem(item); @@ -446,13 +488,18 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdItem *item = NULL; if (val->isInt()) { int index = val->getInt(); - if (index >= 0 && index < _items.getSize()) item = _items[index]; + if (index >= 0 && index < _items.getSize()) { + item = _items[index]; + } } else { item = getItemByName(val->getString()); } - if (item) stack->pushNative(item, true); - else stack->pushNULL(); + if (item) { + stack->pushNative(item, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -476,13 +523,24 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, res->_iD = id; res->setText(text); _stringTable->expand(&res->_text); - if (!val1->isNULL()) res->setIcon(val1->getString()); - if (!val2->isNULL()) res->setIconHover(val2->getString()); - if (!val3->isNULL()) res->setIconPressed(val3->getString()); - if (!val4->isNULL()) res->setFont(val4->getString()); + if (!val1->isNULL()) { + res->setIcon(val1->getString()); + } + if (!val2->isNULL()) { + res->setIconHover(val2->getString()); + } + if (!val3->isNULL()) { + res->setIconPressed(val3->getString()); + } + if (!val4->isNULL()) { + res->setFont(val4->getString()); + } - if (strcmp(name, "AddResponseOnce") == 0) res->_responseType = RESPONSE_ONCE; - else if (strcmp(name, "AddResponseOnceGame") == 0) res->_responseType = RESPONSE_ONCE_GAME; + if (strcmp(name, "AddResponseOnce") == 0) { + res->_responseType = RESPONSE_ONCE; + } else if (strcmp(name, "AddResponseOnceGame") == 0) { + res->_responseType = RESPONSE_ONCE_GAME; + } _responseBox->_responses.add(res); } @@ -577,7 +635,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, Common::String branchName; if (val->isNULL()) { branchName.format("line%d", script->_currentLine); - } else branchName = val->getString(); + } else { + branchName = val->getString(); + } startDlgBranch(branchName.c_str(), script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); stack->pushNULL(); @@ -593,7 +653,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *branchName = NULL; ScValue *val = stack->pop(); - if (!val->isNULL()) branchName = val->getString(); + if (!val->isNULL()) { + branchName = val->getString(); + } endDlgBranch(branchName, script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); stack->pushNULL(); @@ -609,7 +671,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (_dlgPendingBranches.getSize() > 0) { stack->pushString(_dlgPendingBranches[_dlgPendingBranches.getSize() - 1]); - } else stack->pushNULL(); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -663,7 +727,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } } - } else script->runtimeError("Game.IsItemTaken: item name expected"); + } else { + script->runtimeError("Game.IsItemTaken: item name expected"); + } stack->pushBool(false); return STATUS_OK; @@ -674,10 +740,11 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetInventoryWindow") == 0) { stack->correctParams(0); - if (_inventoryBox && _inventoryBox->_window) + if (_inventoryBox && _inventoryBox->_window) { stack->pushNative(_inventoryBox->_window, true); - else + } else { stack->pushNULL(); + } return STATUS_OK; } @@ -687,10 +754,11 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetResponsesWindow") == 0 || strcmp(name, "GetResponseWindow") == 0) { stack->correctParams(0); - if (_responseBox && _responseBox->_window) + if (_responseBox && _responseBox->_window) { stack->pushNative(_responseBox->_window, true); - else + } else { stack->pushNULL(); + } return STATUS_OK; } @@ -781,11 +849,19 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, int width = stack->pop()->getInt(); int height = stack->pop()->getInt(); - if (width <= 0) width = _renderer->_width; - if (height <= 0) height = _renderer->_height; + if (width <= 0) { + width = _renderer->_width; + } + if (height <= 0) { + height = _renderer->_height; + } - if (!_sceneViewport) _sceneViewport = new BaseViewport(_gameRef); - if (_sceneViewport) _sceneViewport->setRect(x, y, x + width, y + height); + if (!_sceneViewport) { + _sceneViewport = new BaseViewport(_gameRef); + } + if (_sceneViewport) { + _sceneViewport->setRect(x, y, x + width, y + height); + } stack->pushBool(true); @@ -793,7 +869,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } - else return BaseGame::scCallMethod(script, stack, thisStack, name); + else { + return BaseGame::scCallMethod(script, stack, thisStack, name); + } } @@ -812,8 +890,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // Scene ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Scene") == 0) { - if (_scene) _scValue->setNative(_scene, true); - else _scValue->setNULL(); + if (_scene) { + _scValue->setNative(_scene, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -822,8 +903,11 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SelectedItem") == 0) { //if (_selectedItem) _scValue->setString(_selectedItem->_name); - if (_selectedItem) _scValue->setNative(_selectedItem, true); - else _scValue->setNULL(); + if (_selectedItem) { + _scValue->setNative(_selectedItem, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -854,8 +938,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // InventoryScrollOffset ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryScrollOffset") == 0) { - if (_inventoryBox) _scValue->setInt(_inventoryBox->_scrollOffset); - else _scValue->setInt(0); + if (_inventoryBox) { + _scValue->setInt(_inventoryBox->_scrollOffset); + } else { + _scValue->setInt(0); + } return _scValue; } @@ -872,8 +959,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // PrevScene / PreviousScene (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "PrevScene") == 0 || strcmp(name, "PreviousScene") == 0) { - if (!_prevSceneName) _scValue->setString(""); - else _scValue->setString(_prevSceneName); + if (!_prevSceneName) { + _scValue->setString(""); + } else { + _scValue->setString(_prevSceneName); + } return _scValue; } @@ -881,8 +971,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // PrevSceneFilename / PreviousSceneFilename (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "PrevSceneFilename") == 0 || strcmp(name, "PreviousSceneFilename") == 0) { - if (!_prevSceneFilename) _scValue->setString(""); - else _scValue->setString(_prevSceneFilename); + if (!_prevSceneFilename) { + _scValue->setString(""); + } else { + _scValue->setString(_prevSceneFilename); + } return _scValue; } @@ -890,8 +983,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // LastResponse (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "LastResponse") == 0) { - if (!_responseBox || !_responseBox->_lastResponseText) _scValue->setString(""); - else _scValue->setString(_responseBox->_lastResponseText); + if (!_responseBox || !_responseBox->_lastResponseText) { + _scValue->setString(""); + } else { + _scValue->setString(_responseBox->_lastResponseText); + } return _scValue; } @@ -899,8 +995,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // LastResponseOrig (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "LastResponseOrig") == 0) { - if (!_responseBox || !_responseBox->_lastResponseTextOrig) _scValue->setString(""); - else _scValue->setString(_responseBox->_lastResponseTextOrig); + if (!_responseBox || !_responseBox->_lastResponseTextOrig) { + _scValue->setString(""); + } else { + _scValue->setString(_responseBox->_lastResponseTextOrig); + } return _scValue; } @@ -908,8 +1007,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // InventoryObject ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryObject") == 0) { - if (_inventoryOwner == _invObject) _scValue->setNative(this, true); - else _scValue->setNative(_inventoryOwner, true); + if (_inventoryOwner == _invObject) { + _scValue->setNative(this, true); + } else { + _scValue->setNative(_inventoryOwner, true); + } return _scValue; } @@ -942,12 +1044,17 @@ ScValue *AdGame::scGetProperty(const char *name) { // StartupScene ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "StartupScene") == 0) { - if (!_startupScene) _scValue->setNULL(); - else _scValue->setString(_startupScene); + if (!_startupScene) { + _scValue->setNULL(); + } else { + _scValue->setString(_startupScene); + } return _scValue; } - else return BaseGame::scGetProperty(name); + else { + return BaseGame::scGetProperty(name); + } } @@ -958,8 +1065,9 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // SelectedItem ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "SelectedItem") == 0) { - if (value->isNULL()) _selectedItem = NULL; - else { + if (value->isNULL()) { + _selectedItem = NULL; + } else { if (value->isNative()) { _selectedItem = NULL; for (int i = 0; i < _items.getSize(); i++) { @@ -989,7 +1097,9 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // InventoryVisible ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryVisible") == 0) { - if (_inventoryBox) _inventoryBox->_visible = value->getBool(); + if (_inventoryBox) { + _inventoryBox->_visible = value->getBool(); + } return STATUS_OK; } @@ -997,16 +1107,24 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // InventoryObject ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryObject") == 0) { - if (_inventoryOwner && _inventoryBox) _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; + if (_inventoryOwner && _inventoryBox) { + _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; + } - if (value->isNULL()) _inventoryOwner = _invObject; - else { - BaseObject *Obj = (BaseObject *)value->getNative(); - if (Obj == this) _inventoryOwner = _invObject; - else if (_gameRef->validObject(Obj)) _inventoryOwner = (AdObject *)Obj; + if (value->isNULL()) { + _inventoryOwner = _invObject; + } else { + BaseObject *obj = (BaseObject *)value->getNative(); + if (obj == this) { + _inventoryOwner = _invObject; + } else if (_gameRef->validObject(obj)) { + _inventoryOwner = (AdObject *)obj; + } } - if (_inventoryOwner && _inventoryBox) _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; + if (_inventoryOwner && _inventoryBox) { + _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; + } return STATUS_OK; } @@ -1015,7 +1133,9 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // InventoryScrollOffset ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryScrollOffset") == 0) { - if (_inventoryBox) _inventoryBox->_scrollOffset = value->getInt(); + if (_inventoryBox) { + _inventoryBox->_scrollOffset = value->getInt(); + } return STATUS_OK; } @@ -1023,10 +1143,14 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // TalkSkipButton ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TalkSkipButton") == 0) { - int Val = value->getInt(); - if (Val < 0) Val = 0; - if (Val > TALK_SKIP_NONE) Val = TALK_SKIP_NONE; - _talkSkipButton = (TTalkSkipButton)Val; + int val = value->getInt(); + if (val < 0) { + val = 0; + } + if (val > TALK_SKIP_NONE) { + val = TALK_SKIP_NONE; + } + _talkSkipButton = (TTalkSkipButton)val; return STATUS_OK; } @@ -1037,12 +1161,16 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { if (value == NULL) { delete[] _startupScene; _startupScene = NULL; - } else BaseUtils::setString(&_startupScene, value->getString()); + } else { + BaseUtils::setString(&_startupScene, value->getString()); + } return STATUS_OK; } - else return BaseGame::scSetProperty(name, value); + else { + return BaseGame::scSetProperty(name, value); + } } @@ -1075,7 +1203,9 @@ bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// // call parent - else return BaseGame::ExternalCall(script, stack, thisStack, name); + else { + return BaseGame::ExternalCall(script, stack, thisStack, name); + } return STATUS_OK; @@ -1084,7 +1214,9 @@ bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// bool AdGame::showCursor() { - if (_cursorHidden) return STATUS_OK; + if (_cursorHidden) { + return STATUS_OK; + } if (_selectedItem && _gameRef->_state == GAME_RUNNING && _stateEx == GAME_NORMAL && _interactive) { if (_selectedItem->_cursorCombined) { @@ -1093,12 +1225,17 @@ bool AdGame::showCursor() { _lastCursor = origLastCursor; } if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { - if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->getName())) + if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->getName())) { return drawCursor(_selectedItem->_cursorHover); - else + } else { return drawCursor(_selectedItem->_cursorNormal); - } else return drawCursor(_selectedItem->_cursorNormal); - } else return BaseGame::showCursor(); + } + } else { + return drawCursor(_selectedItem->_cursorNormal); + } + } else { + return BaseGame::showCursor(); + } } @@ -1114,7 +1251,9 @@ bool AdGame::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + } delete[] buffer; @@ -1162,7 +1301,9 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_GAME: - if (DID_FAIL(BaseGame::loadBuffer(params, false))) cmd = PARSERR_GENERIC; + if (DID_FAIL(BaseGame::loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_AD_GAME: @@ -1171,9 +1312,9 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { case TOKEN_RESPONSE_BOX: delete _responseBox; _responseBox = new AdResponseBox(_gameRef); - if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) + if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) { registerObject(_responseBox); - else { + } else { delete _responseBox; _responseBox = NULL; cmd = PARSERR_GENERIC; @@ -1183,9 +1324,9 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { case TOKEN_INVENTORY_BOX: delete _inventoryBox; _inventoryBox = new AdInventoryBox(_gameRef); - if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) + if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) { registerObject(_inventoryBox); - else { + } else { delete _inventoryBox; _inventoryBox = NULL; cmd = PARSERR_GENERIC; @@ -1203,16 +1344,24 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_TALK_SKIP_BUTTON: - if (scumm_stricmp((char *)params2, "right") == 0) _talkSkipButton = TALK_SKIP_RIGHT; - else if (scumm_stricmp((char *)params2, "both") == 0) _talkSkipButton = TALK_SKIP_BOTH; - else _talkSkipButton = TALK_SKIP_LEFT; + if (scumm_stricmp((char *)params2, "right") == 0) { + _talkSkipButton = TALK_SKIP_RIGHT; + } else if (scumm_stricmp((char *)params2, "both") == 0) { + _talkSkipButton = TALK_SKIP_BOTH; + } else { + _talkSkipButton = TALK_SKIP_LEFT; + } break; case TOKEN_SCENE_VIEWPORT: { Rect32 rc; parser.scanStr((char *)params2, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_sceneViewport) _sceneViewport = new BaseViewport(_gameRef); - if (_sceneViewport) _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); + if (!_sceneViewport) { + _sceneViewport = new BaseViewport(_gameRef); + } + if (_sceneViewport) { + _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); + } } break; @@ -1252,7 +1401,9 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// bool AdGame::persist(BasePersistenceManager *persistMgr) { - if (!persistMgr->getIsSaving()) cleanup(); + if (!persistMgr->getIsSaving()) { + cleanup(); + } BaseGame::persist(persistMgr); _dlgPendingBranches.persist(persistMgr); @@ -1292,7 +1443,9 @@ bool AdGame::persist(BasePersistenceManager *persistMgr) { _speechDirs.persist(persistMgr); persistMgr->transfer(TMEMBER(_smartItemCursor)); - if (!persistMgr->getIsSaving()) _initialScene = false; + if (!persistMgr->getIsSaving()) { + _initialScene = false; + } persistMgr->transfer(TMEMBER(_startupScene)); @@ -1304,7 +1457,9 @@ bool AdGame::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdGame::loadGame(const char *filename) { bool ret = BaseGame::loadGame(filename); - if (DID_SUCCEED(ret)) SystemClassRegistry::getInstance()->enumInstances(afterLoadRegion, "AdRegion", NULL); + if (DID_SUCCEED(ret)) { + SystemClassRegistry::getInstance()->enumInstances(afterLoadRegion, "AdRegion", NULL); + } return ret; } @@ -1327,7 +1482,9 @@ void AdGame::setPrevSceneName(const char *name) { _prevSceneName = NULL; if (name) { _prevSceneName = new char[strlen(name) + 1]; - if (_prevSceneName) strcpy(_prevSceneName, name); + if (_prevSceneName) { + strcpy(_prevSceneName, name); + } } } @@ -1338,7 +1495,9 @@ void AdGame::setPrevSceneFilename(const char *name) { _prevSceneFilename = NULL; if (name) { _prevSceneFilename = new char[strlen(name) + 1]; - if (_prevSceneFilename) strcpy(_prevSceneFilename, name); + if (_prevSceneFilename) { + strcpy(_prevSceneFilename, name); + } } } @@ -1348,8 +1507,9 @@ bool AdGame::scheduleChangeScene(const char *filename, bool fadeIn) { delete[] _scheduledScene; _scheduledScene = NULL; - if (_scene && !_scene->_initialized) return changeScene(filename, fadeIn); - else { + if (_scene && !_scene->_initialized) { + return changeScene(filename, fadeIn); + } else { _scheduledScene = new char [strlen(filename) + 1]; strcpy(_scheduledScene, filename); @@ -1364,8 +1524,12 @@ bool AdGame::scheduleChangeScene(const char *filename, bool fadeIn) { bool AdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { BaseGame::getVersion(verMajor, verMinor, NULL, NULL); - if (extMajor) *extMajor = 0; - if (extMinor) *extMinor = 0; + if (extMajor) { + *extMajor = 0; + } + if (extMinor) { + *extMinor = 0; + } return STATUS_OK; } @@ -1384,7 +1548,9 @@ bool AdGame::loadItemsFile(const char *filename, bool merge) { //_filename = new char [strlen(filename)+1]; //strcpy(_filename, filename); - if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); + if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) { + _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); + } delete[] buffer; @@ -1404,7 +1570,9 @@ bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { BaseParser parser(_gameRef); if (!merge) { - while (_items.getSize() > 0) deleteItem(_items[0]); + while (_items.getSize() > 0) { + deleteItem(_items[0]); + } } while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { @@ -1414,8 +1582,10 @@ bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { if (item && !DID_FAIL(item->loadBuffer(params, false))) { // delete item with the same name, if exists if (merge) { - AdItem *PrevItem = getItemByName(item->getName()); - if (PrevItem) deleteItem(PrevItem); + AdItem *prevItem = getItemByName(item->getName()); + if (prevItem) { + deleteItem(prevItem); + } } addItem(item); } else { @@ -1446,7 +1616,9 @@ AdSceneState *AdGame::getSceneState(const char *filename, bool saving) { char *filenameCor = new char[strlen(filename) + 1]; strcpy(filenameCor, filename); for (uint32 i = 0; i < strlen(filenameCor); i++) { - if (filenameCor[i] == '/') filenameCor[i] = '\\'; + if (filenameCor[i] == '/') { + filenameCor[i] = '\\'; + } } for (int i = 0; i < _sceneStates.getSize(); i++) { @@ -1512,14 +1684,18 @@ bool AdGame::windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *st ScValue *val = stack->pop(); UIEntity *ent = new UIEntity(_gameRef); - if (!val->isNULL()) ent->setName(val->getString()); + if (!val->isNULL()) { + ent->setName(val->getString()); + } stack->pushNative(ent, true); ent->_parent = win; win->_widgets.add(ent); return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -1550,7 +1726,9 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const } } - if (name == NULL) return STATUS_OK; + if (name == NULL) { + return STATUS_OK; + } int startIndex = -1; @@ -1571,11 +1749,15 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const // dialogue is over, forget selected responses if (_dlgPendingBranches.getSize() == 0) { - for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + for (int i = 0; i < _responsesBranch.getSize(); i++) { + delete _responsesBranch[i]; + } _responsesBranch.removeAll(); } - if (deleteName) delete[] name; + if (deleteName) { + delete[] name; + } return STATUS_OK; } @@ -1595,10 +1777,12 @@ bool AdGame::clearBranchResponses(char *name) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::addBranchResponse(int ID) { - if (branchResponseUsed(ID)) return STATUS_OK; +bool AdGame::addBranchResponse(int id) { + if (branchResponseUsed(id)) { + return STATUS_OK; + } AdResponseContext *r = new AdResponseContext(_gameRef); - r->_iD = ID; + r->_id = id; r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); _responsesBranch.add(r); return STATUS_OK; @@ -1606,11 +1790,13 @@ bool AdGame::addBranchResponse(int ID) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::branchResponseUsed(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; +bool AdGame::branchResponseUsed(int id) { + char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; for (int i = 0; i < _responsesBranch.getSize(); i++) { - if (_responsesBranch[i]->_iD == ID) { - if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) return true; + if (_responsesBranch[i]->_id == id) { + if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { + return true; + } } } return false; @@ -1618,10 +1804,12 @@ bool AdGame::branchResponseUsed(int ID) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::addGameResponse(int ID) { - if (gameResponseUsed(ID)) return STATUS_OK; +bool AdGame::addGameResponse(int id) { + if (gameResponseUsed(id)) { + return STATUS_OK; + } AdResponseContext *r = new AdResponseContext(_gameRef); - r->_iD = ID; + r->_id = id; r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); _responsesGame.add(r); return STATUS_OK; @@ -1629,12 +1817,14 @@ bool AdGame::addGameResponse(int ID) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::gameResponseUsed(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; +bool AdGame::gameResponseUsed(int id) { + char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; for (int i = 0; i < _responsesGame.getSize(); i++) { - AdResponseContext *RespContext = _responsesGame[i]; - if (RespContext->_iD == ID) { - if ((Context == NULL && RespContext->_context == NULL) || ((Context != NULL && RespContext->_context != NULL) && scumm_stricmp(Context, RespContext->_context) == 0)) return true; + AdResponseContext *respContext = _responsesGame[i]; + if (respContext->_id == id) { + if ((context == NULL && respContext->_context == NULL) || ((context != NULL && respContext->_context != NULL) && scumm_stricmp(context, respContext->_context) == 0)) { + return true; + } } } return false; @@ -1642,14 +1832,12 @@ bool AdGame::gameResponseUsed(int ID) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::resetResponse(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - - int i; +bool AdGame::resetResponse(int id) { + char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - for (i = 0; i < _responsesGame.getSize(); i++) { - if (_responsesGame[i]->_iD == ID) { - if ((Context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(Context, _responsesGame[i]->_context) == 0) { + for (int i = 0; i < _responsesGame.getSize(); i++) { + if (_responsesGame[i]->_id == id) { + if ((context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(context, _responsesGame[i]->_context) == 0) { delete _responsesGame[i]; _responsesGame.removeAt(i); break; @@ -1657,9 +1845,9 @@ bool AdGame::resetResponse(int ID) { } } - for (i = 0; i < _responsesBranch.getSize(); i++) { - if (_responsesBranch[i]->_iD == ID) { - if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) { + for (int i = 0; i < _responsesBranch.getSize(); i++) { + if (_responsesBranch[i]->_id == id) { + if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { delete _responsesBranch[i]; _responsesBranch.removeAt(i); break; @@ -1673,19 +1861,27 @@ bool AdGame::resetResponse(int ID) { ////////////////////////////////////////////////////////////////////////// bool AdGame::displayContent(bool doUpdate, bool displayAll) { // init - if (doUpdate) initLoop(); + if (doUpdate) { + initLoop(); + } // fill black _renderer->fill(0, 0, 0); - if (!_editorMode) _renderer->setScreenViewport(); + if (!_editorMode) { + _renderer->setScreenViewport(); + } // playing exclusive video? if (_videoPlayer->isPlaying()) { - if (doUpdate) _videoPlayer->update(); + if (doUpdate) { + _videoPlayer->update(); + } _videoPlayer->display(); } else if (_theoraPlayer) { if (_theoraPlayer->isPlaying()) { - if (doUpdate) _theoraPlayer->update(); + if (doUpdate) { + _theoraPlayer->update(); + } _theoraPlayer->display(); } if (_theoraPlayer->isFinished()) { @@ -1695,7 +1891,9 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { } else { // process scripts - if (doUpdate) _scEngine->tick(); + if (doUpdate) { + _scEngine->tick(); + } Point32 p; getMousePos(&p); @@ -1706,9 +1904,15 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { // display in-game windows displayWindows(true); - if (_inventoryBox) _inventoryBox->display(); - if (_stateEx == GAME_WAITING_RESPONSE) _responseBox->display(); - if (_indicatorDisplay) displayIndicator(); + if (_inventoryBox) { + _inventoryBox->display(); + } + if (_stateEx == GAME_WAITING_RESPONSE) { + _responseBox->display(); + } + if (_indicatorDisplay) { + displayIndicator(); + } if (doUpdate || displayAll) { @@ -1722,7 +1926,9 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { showCursor(); - if (_fader) _fader->display(); + if (_fader) { + _fader->display(); + } _transMgr->update(); } @@ -1741,7 +1947,9 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { ////////////////////////////////////////////////////////////////////////// bool AdGame::registerInventory(AdInventory *inv) { for (int i = 0; i < _inventories.getSize(); i++) { - if (_inventories[i] == inv) return STATUS_OK; + if (_inventories[i] == inv) { + return STATUS_OK; + } } registerObject(inv); _inventories.add(inv); @@ -1778,7 +1986,9 @@ bool AdGame::isItemTaken(char *itemName) { ////////////////////////////////////////////////////////////////////////// AdItem *AdGame::getItemByName(const char *name) { for (int i = 0; i < _items.getSize(); i++) { - if (scumm_stricmp(_items[i]->getName(), name) == 0) return _items[i]; + if (scumm_stricmp(_items[i]->getName(), name) == 0) { + return _items[i]; + } } return NULL; } @@ -1806,19 +2016,27 @@ bool AdGame::resetContent() { } // clear scene states - for (int i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; + for (int i = 0; i < _sceneStates.getSize(); i++) { + delete _sceneStates[i]; + } _sceneStates.removeAll(); // clear once responses - for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + for (int i = 0; i < _responsesBranch.getSize(); i++) { + delete _responsesBranch[i]; + } _responsesBranch.removeAll(); // clear once game responses - for (int i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; + for (int i = 0; i < _responsesGame.getSize(); i++) { + delete _responsesGame[i]; + } _responsesGame.removeAll(); // reload inventory items - if (_itemsFile) loadItemsFile(_itemsFile); + if (_itemsFile) { + loadItemsFile(_itemsFile); + } _tempDisableSaveState = true; @@ -1828,9 +2046,13 @@ bool AdGame::resetContent() { ////////////////////////////////////////////////////////////////////////// bool AdGame::deleteItem(AdItem *item) { - if (!item) return STATUS_FAILED; + if (!item) { + return STATUS_FAILED; + } - if (_selectedItem == item) _selectedItem = NULL; + if (_selectedItem == item) { + _selectedItem = NULL; + } _scene->handleItemAssociations(item->getName(), false); // remove from all inventories @@ -1853,12 +2075,15 @@ bool AdGame::deleteItem(AdItem *item) { ////////////////////////////////////////////////////////////////////////// bool AdGame::addSpeechDir(const char *dir) { - if (!dir || dir[0] == '\0') return STATUS_FAILED; + if (!dir || dir[0] == '\0') { + return STATUS_FAILED; + } char *temp = new char[strlen(dir) + 2]; strcpy(temp, dir); - if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') { strcat(temp, "\\"); + } for (int i = 0; i < _speechDirs.getSize(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { @@ -1874,26 +2099,28 @@ bool AdGame::addSpeechDir(const char *dir) { ////////////////////////////////////////////////////////////////////////// bool AdGame::removeSpeechDir(const char *dir) { - if (!dir || dir[0] == '\0') return STATUS_FAILED; + if (!dir || dir[0] == '\0') { + return STATUS_FAILED; + } char *temp = new char[strlen(dir) + 2]; strcpy(temp, dir); - if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') { strcat(temp, "\\"); + } - bool Found = false; + bool found = false; for (int i = 0; i < _speechDirs.getSize(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { delete[] _speechDirs[i]; _speechDirs.removeAt(i); - Found = true; + found = true; break; } } delete[] temp; - if (Found) return STATUS_OK; - else return STATUS_FAILED; + return found; } @@ -1903,12 +2130,14 @@ char *AdGame::findSpeechFile(char *stringID) { for (int i = 0; i < _speechDirs.getSize(); i++) { sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); - if (_fileManager->hasFile(ret)) + if (_fileManager->hasFile(ret)) { return ret; + } sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); - if (_fileManager->hasFile(ret)) + if (_fileManager->hasFile(ret)) { return ret; + } } delete[] ret; return NULL; @@ -1925,7 +2154,9 @@ bool AdGame::validMouse() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseLeftDown() { - if (!validMouse()) return STATUS_OK; + if (!validMouse()) { + return STATUS_OK; + } if (_state == GAME_RUNNING && !_interactive) { if (_talkSkipButton == TALK_SKIP_LEFT || _talkSkipButton == TALK_SKIP_BOTH) { finishSentences(); @@ -1933,7 +2164,9 @@ bool AdGame::onMouseLeftDown() { return STATUS_OK; } - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick")); if (!handled) { @@ -1944,7 +2177,9 @@ bool AdGame::onMouseLeftDown() { } } - if (_activeObject != NULL) _gameRef->_capturedObject = _gameRef->_activeObject; + if (_activeObject != NULL) { + _gameRef->_capturedObject = _gameRef->_activeObject; + } _mouseLeftDown = true; BasePlatform::setCapture(/*_renderer->_window*/); @@ -1953,7 +2188,9 @@ bool AdGame::onMouseLeftDown() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseLeftUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + } BasePlatform::releaseCapture(); _capturedObject = NULL; @@ -1972,11 +2209,17 @@ bool AdGame::onMouseLeftUp() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseLeftDblClick() { - if (!validMouse()) return STATUS_OK; + if (!validMouse()) { + return STATUS_OK; + } - if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + return STATUS_OK; + } - if (_activeObject) _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick")); if (!handled) { @@ -1991,7 +2234,9 @@ bool AdGame::onMouseLeftDblClick() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseRightDown() { - if (!validMouse()) return STATUS_OK; + if (!validMouse()) { + return STATUS_OK; + } if (_state == GAME_RUNNING && !_interactive) { if (_talkSkipButton == TALK_SKIP_RIGHT || _talkSkipButton == TALK_SKIP_BOTH) { finishSentences(); @@ -1999,9 +2244,13 @@ bool AdGame::onMouseRightDown() { return STATUS_OK; } - if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) return STATUS_OK; + if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) { + return STATUS_OK; + } - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick")); if (!handled) { @@ -2016,7 +2265,9 @@ bool AdGame::onMouseRightDown() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseRightUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); if (!handled) { @@ -2045,8 +2296,9 @@ bool AdGame::displayDebugInfo() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onScriptShutdown(ScScript *script) { - if (_responseBox && _responseBox->_waitingScript == script) + if (_responseBox && _responseBox->_waitingScript == script) { _responseBox->_waitingScript = NULL; + } return STATUS_OK; } diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index d79d171d02..aa6e0b6f0b 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -50,10 +50,14 @@ AdInventory::~AdInventory() { ////////////////////////////////////////////////////////////////////////// bool AdInventory::insertItem(const char *name, const char *insertAfter) { - if (name == NULL) return STATUS_FAILED; + if (name == NULL) { + return STATUS_FAILED; + } AdItem *item = ((AdGame *)_gameRef)->getItemByName(name); - if (item == NULL) return STATUS_FAILED; + if (item == NULL) { + return STATUS_FAILED; + } int insertIndex = -1; for (int i = 0; i < _takenItems.getSize(); i++) { @@ -62,12 +66,17 @@ bool AdInventory::insertItem(const char *name, const char *insertAfter) { i--; continue; } - if (insertAfter && scumm_stricmp(_takenItems[i]->getName(), insertAfter) == 0) insertIndex = i + 1; + if (insertAfter && scumm_stricmp(_takenItems[i]->getName(), insertAfter) == 0) { + insertIndex = i + 1; + } } - if (insertIndex == -1) _takenItems.add(item); - else _takenItems.insertAt(insertIndex, item); + if (insertIndex == -1) { + _takenItems.add(item); + } else { + _takenItems.insertAt(insertIndex, item); + } return STATUS_OK; } @@ -75,11 +84,15 @@ bool AdInventory::insertItem(const char *name, const char *insertAfter) { ////////////////////////////////////////////////////////////////////////// bool AdInventory::removeItem(const char *name) { - if (name == NULL) return STATUS_FAILED; + if (name == NULL) { + return STATUS_FAILED; + } for (int i = 0; i < _takenItems.getSize(); i++) { if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { - if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i])((AdGame *)_gameRef)->_selectedItem = NULL; + if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { + ((AdGame *)_gameRef)->_selectedItem = NULL; + } _takenItems.removeAt(i); return STATUS_OK; } @@ -92,11 +105,15 @@ bool AdInventory::removeItem(const char *name) { ////////////////////////////////////////////////////////////////////////// bool AdInventory::removeItem(AdItem *item) { - if (item == NULL) return STATUS_FAILED; + if (item == NULL) { + return STATUS_FAILED; + } for (int i = 0; i < _takenItems.getSize(); i++) { if (_takenItems[i] == item) { - if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i])((AdGame *)_gameRef)->_selectedItem = NULL; + if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { + ((AdGame *)_gameRef)->_selectedItem = NULL; + } _takenItems.removeAt(i); return STATUS_OK; } diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index 60607c71c6..b8a3f1da22 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -86,7 +86,9 @@ bool AdInventoryBox::listen(BaseScriptHolder *param1, uint32 param2) { _scrollOffset = MAX(_scrollOffset, 0); } else if (scumm_stricmp(obj->getName(), "next") == 0) { _scrollOffset += _scrollBy; - } else return BaseObject::listen(param1, param2); + } else { + return BaseObject::listen(param1, param2); + } break; default: error("AdInventoryBox::Listen - Unhandled enum"); @@ -101,7 +103,9 @@ bool AdInventoryBox::listen(BaseScriptHolder *param1, uint32 param2) { bool AdInventoryBox::display() { AdGame *adGame = (AdGame *)_gameRef; - if (!_visible) return STATUS_OK; + if (!_visible) { + return STATUS_OK; + } int itemsX, itemsY; itemsX = (int)floor((float)((_itemsArea.right - _itemsArea.left + _spacing) / (_itemWidth + _spacing))); @@ -130,7 +134,9 @@ bool AdInventoryBox::display() { } // display items - if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; + if (_window && _window->_alphaColor != 0) { + _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; + } int yyy = rect.top; for (int j = 0; j < itemsY; j++) { int xxx = rect.left; @@ -148,7 +154,9 @@ bool AdInventoryBox::display() { } yyy += (_itemHeight + _spacing); } - if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = 0; + if (_window && _window->_alphaColor != 0) { + _gameRef->_renderer->_forceAlphaColor = 0; + } return STATUS_OK; } @@ -166,7 +174,9 @@ bool AdInventoryBox::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); + } delete[] buffer; @@ -227,7 +237,9 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -245,7 +257,9 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { delete _window; _window = NULL; cmd = PARSERR_GENERIC; - } else _gameRef->registerObject(_window); + } else { + _gameRef->registerObject(_window); + } break; case TOKEN_AREA: @@ -308,8 +322,9 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { if (_window) { for (int i = 0; i < _window->_widgets.getSize(); i++) { - if (!_window->_widgets[i]->_listenerObject) + if (!_window->_widgets[i]->_listenerObject) { _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } } } @@ -337,7 +352,9 @@ bool AdInventoryBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); // window - if (_window) _window->saveAsText(buffer, indent + 2); + if (_window) { + _window->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent + 2, "\n"); diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index cae974e152..c9e0d56b24 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -94,7 +94,9 @@ bool AdItem::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); + } delete[] buffer; @@ -178,7 +180,9 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -186,7 +190,7 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - SetFont((char *)params); + setFont((char *)params); break; case TOKEN_CAPTION: @@ -230,9 +234,13 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_AMOUNT_ALIGN: - if (scumm_stricmp((char *)params, "left") == 0) _amountAlign = TAL_LEFT; - else if (scumm_stricmp((char *)params, "right") == 0) _amountAlign = TAL_RIGHT; - else _amountAlign = TAL_CENTER; + if (scumm_stricmp((char *)params, "left") == 0) { + _amountAlign = TAL_LEFT; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _amountAlign = TAL_RIGHT; + } else { + _amountAlign = TAL_CENTER; + } break; case TOKEN_AMOUNT_STRING: @@ -241,15 +249,21 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { case TOKEN_TALK: { BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } } break; case TOKEN_TALK_SPECIAL: { BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } } break; @@ -331,10 +345,14 @@ bool AdItem::update() { _currentSprite = _animSprite; } - if (_sentence && _state != STATE_TALKING) _sentence->finish(); + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } // default: stand animation - if (!_currentSprite) _currentSprite = _sprite; + if (!_currentSprite) { + _currentSprite = _sprite; + } switch (_state) { ////////////////////////////////////////////////////////////////////////// @@ -345,15 +363,20 @@ bool AdItem::update() { ////////////////////////////////////////////////////////////////////////// case STATE_READY: if (!_animSprite) { - if (_gameRef->_activeObject == this && _spriteHover) _currentSprite = _spriteHover; - else _currentSprite = _sprite; + if (_gameRef->_activeObject == this && _spriteHover) { + _currentSprite = _spriteHover; + } else { + _currentSprite = _sprite; + } } break; ////////////////////////////////////////////////////////////////////////// case STATE_TALKING: { _sentence->update(); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { @@ -396,9 +419,11 @@ bool AdItem::display(int x, int y) { _posY = y; bool ret; - if (_currentSprite) + if (_currentSprite) { ret = _currentSprite->draw(x, y, this, 100, 100, _alphaColor); - else ret = STATUS_OK; + } else { + ret = STATUS_OK; + } if (_displayAmount) { int amountX = x; @@ -412,8 +437,9 @@ bool AdItem::display(int x, int y) { BaseFont *font = _font ? _font : _gameRef->_systemFont; if (font) { - if (_amountString) font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); - else { + if (_amountString) { + font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); + } else { char Str[256]; sprintf(Str, "%d", _amount); font->drawText((byte *)Str, amountX, amountY, width, _amountAlign); @@ -436,7 +462,9 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->correctParams(1); bool setCurrent = false; - if (_currentSprite && _currentSprite == _spriteHover) setCurrent = true; + if (_currentSprite && _currentSprite == _spriteHover) { + setCurrent = true; + } const char *filename = stack->pop()->getString(); @@ -448,7 +476,9 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, script->runtimeError("Item.SetHoverSprite failed for file '%s'", filename); } else { _spriteHover = spr; - if (setCurrent) _currentSprite = _spriteHover; + if (setCurrent) { + _currentSprite = _spriteHover; + } stack->pushBool(true); } return STATUS_OK; @@ -460,8 +490,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetHoverSprite") == 0) { stack->correctParams(0); - if (!_spriteHover || !_spriteHover->getFilename()) stack->pushNULL(); - else stack->pushString(_spriteHover->getFilename()); + if (!_spriteHover || !_spriteHover->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_spriteHover->getFilename()); + } return STATUS_OK; } @@ -470,8 +503,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetHoverSpriteObject") == 0) { stack->correctParams(0); - if (!_spriteHover) stack->pushNULL(); - else stack->pushNative(_spriteHover, true); + if (!_spriteHover) { + stack->pushNULL(); + } else { + stack->pushNative(_spriteHover, true); + } return STATUS_OK; } @@ -502,8 +538,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetNormalCursor") == 0) { stack->correctParams(0); - if (!_cursorNormal || !_cursorNormal->getFilename()) stack->pushNULL(); - else stack->pushString(_cursorNormal->getFilename()); + if (!_cursorNormal || !_cursorNormal->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_cursorNormal->getFilename()); + } return STATUS_OK; } @@ -513,8 +552,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetNormalCursorObject") == 0) { stack->correctParams(0); - if (!_cursorNormal) stack->pushNULL(); - else stack->pushNative(_cursorNormal, true); + if (!_cursorNormal) { + stack->pushNULL(); + } else { + stack->pushNative(_cursorNormal, true); + } return STATUS_OK; } @@ -545,8 +587,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetHoverCursor") == 0) { stack->correctParams(0); - if (!_cursorHover || !_cursorHover->getFilename()) stack->pushNULL(); - else stack->pushString(_cursorHover->getFilename()); + if (!_cursorHover || !_cursorHover->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_cursorHover->getFilename()); + } return STATUS_OK; } @@ -556,12 +601,15 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetHoverCursorObject") == 0) { stack->correctParams(0); - if (!_cursorHover) stack->pushNULL(); - else stack->pushNative(_cursorHover, true); + if (!_cursorHover) { + stack->pushNULL(); + } else { + stack->pushNative(_cursorHover, true); + } return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } - - else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } @@ -629,8 +677,11 @@ ScValue *AdItem::scGetProperty(const char *name) { // AmountString ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "AmountString") == 0) { - if (!_amountString) _scValue->setNULL(); - else _scValue->setString(_amountString); + if (!_amountString) { + _scValue->setNULL(); + } else { + _scValue->setString(_amountString); + } return _scValue; } @@ -640,9 +691,9 @@ ScValue *AdItem::scGetProperty(const char *name) { else if (strcmp(name, "CursorCombined") == 0) { _scValue->setBool(_cursorCombined); return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); } - - else return AdTalkHolder::scGetProperty(name); } @@ -715,9 +766,9 @@ bool AdItem::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "CursorCombined") == 0) { _cursorCombined = value->getBool(); return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); } - - else return AdTalkHolder::scSetProperty(name, value); } @@ -750,9 +801,13 @@ bool AdItem::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdItem::getExtendedFlag(const char *flagName) { - if (!flagName) return false; - else if (strcmp(flagName, "usable") == 0) return true; - else return AdObject::getExtendedFlag(flagName); + if (!flagName) { + return false; + } else if (strcmp(flagName, "usable") == 0) { + return true; + } else { + return AdObject::getExtendedFlag(flagName); + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 0a93edfb35..6c9e6381b2 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -53,8 +53,9 @@ AdLayer::AdLayer(BaseGame *inGame): BaseObject(inGame) { ////////////////////////////////////////////////////////////////////////// AdLayer::~AdLayer() { - for (int i = 0; i < _nodes.getSize(); i++) + for (int i = 0; i < _nodes.getSize(); i++) { delete _nodes[i]; + } _nodes.removeAll(); } @@ -71,7 +72,9 @@ bool AdLayer::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); + } delete[] buffer; @@ -131,7 +134,9 @@ bool AdLayer::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -181,7 +186,9 @@ bool AdLayer::loadBuffer(byte *buffer, bool complete) { case TOKEN_ENTITY: { AdEntity *entity = new AdEntity(_gameRef); AdSceneNode *node = new AdSceneNode(_gameRef); - if (entity) entity->_zoomable = false; // scene entites default to NOT zoom + if (entity) { + entity->_zoomable = false; // scene entites default to NOT zoom + } if (!entity || !node || DID_FAIL(entity->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; delete entity; @@ -233,8 +240,9 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); int node = -1; - if (val->_type == VAL_INT) node = val->getInt(); - else { // get by name + if (val->_type == VAL_INT) { + node = val->getInt(); + } else { // get by name for (int i = 0; i < _nodes.getSize(); i++) { if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->getName(), val->getString()) == 0) || (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->getName(), val->getString()) == 0)) { @@ -244,8 +252,9 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } - if (node < 0 || node >= _nodes.getSize()) stack->pushNULL(); - else { + if (node < 0 || node >= _nodes.getSize()) { + stack->pushNULL(); + } else { switch (_nodes[node]->_type) { case OBJECT_ENTITY: stack->pushNative(_nodes[node]->_entity, true); @@ -270,12 +279,16 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdSceneNode *node = new AdSceneNode(_gameRef); if (strcmp(name, "AddRegion") == 0) { AdRegion *region = new AdRegion(_gameRef); - if (!val->isNULL()) region->setName(val->getString()); + if (!val->isNULL()) { + region->setName(val->getString()); + } node->setRegion(region); stack->pushNative(region, true); } else { AdEntity *entity = new AdEntity(_gameRef); - if (!val->isNULL()) entity->setName(val->getString()); + if (!val->isNULL()) { + entity->setName(val->getString()); + } node->setEntity(entity); stack->pushNative(entity, true); } @@ -294,18 +307,27 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdSceneNode *node = new AdSceneNode(_gameRef); if (strcmp(name, "InsertRegion") == 0) { AdRegion *region = new AdRegion(_gameRef); - if (!val->isNULL()) region->setName(val->getString()); + if (!val->isNULL()) { + region->setName(val->getString()); + } node->setRegion(region); stack->pushNative(region, true); } else { AdEntity *entity = new AdEntity(_gameRef); - if (!val->isNULL()) entity->setName(val->getString()); + if (!val->isNULL()) { + entity->setName(val->getString()); + } node->setEntity(entity); stack->pushNative(entity, true); } - if (index < 0) index = 0; - if (index <= _nodes.getSize() - 1) _nodes.insertAt(index, node); - else _nodes.add(node); + if (index < 0) { + index = 0; + } + if (index <= _nodes.getSize() - 1) { + _nodes.insertAt(index, node); + } else { + _nodes.add(node); + } return STATUS_OK; } @@ -347,9 +369,9 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } stack->pushBool(true); return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -411,9 +433,9 @@ ScValue *AdLayer::scGetProperty(const char *name) { else if (strcmp(name, "Active") == 0) { _scValue->setBool(_active); return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -440,7 +462,9 @@ bool AdLayer::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Width") == 0) { _width = value->getInt(); - if (_width < 0) _width = 0; + if (_width < 0) { + _width = 0; + } return STATUS_OK; } @@ -449,7 +473,9 @@ bool AdLayer::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Height") == 0) { _height = value->getInt(); - if (_height < 0) _height = 0; + if (_height < 0) { + _height = 0; + } return STATUS_OK; } @@ -460,11 +486,13 @@ bool AdLayer::scSetProperty(const char *name, ScValue *value) { bool b = value->getBool(); if (b == false && _main) { _gameRef->LOG(0, "Warning: cannot deactivate scene's main layer"); - } else _active = b; + } else { + _active = b; + } return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -484,8 +512,9 @@ bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "HEIGHT=%d\n", _height); buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - if (_closeUp) + if (_closeUp) { buffer->putTextIndent(indent + 2, "CLOSE_UP=%s\n", _closeUp ? "TRUE" : "FALSE"); + } int i; @@ -493,7 +522,9 @@ bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } for (i = 0; i < _nodes.getSize(); i++) { switch (_nodes[i]->_type) { diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index 444373ea75..5a58dba5b1 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -44,8 +44,9 @@ IMPLEMENT_PERSISTENT(AdNodeState, false) AdNodeState::AdNodeState(BaseGame *inGame): BaseClass(inGame) { _name = NULL; _active = false; - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { _caption[i] = NULL; + } _alphaColor = 0; _filename = NULL; _cursor = NULL; @@ -100,8 +101,9 @@ bool AdNodeState::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_filename)); persistMgr->transfer(TMEMBER(_cursor)); persistMgr->transfer(TMEMBER(_alphaColor)); - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { persistMgr->transfer(TMEMBER(_caption[i])); + } return STATUS_OK; } @@ -109,10 +111,12 @@ bool AdNodeState::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// void AdNodeState::setCaption(const char *caption, int caseVal) { - if (caseVal == 0) + if (caseVal == 0) { caseVal = 1; - if (caseVal < 1 || caseVal > 7) + } + if (caseVal < 1 || caseVal > 7) { return; + } delete[] _caption[caseVal - 1]; _caption[caseVal - 1] = new char[strlen(caption) + 1]; @@ -125,44 +129,61 @@ void AdNodeState::setCaption(const char *caption, int caseVal) { ////////////////////////////////////////////////////////////////////////// char *AdNodeState::getCaption(int caseVal) { - if (caseVal == 0) caseVal = 1; - if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) + if (caseVal == 0) { + caseVal = 1; + } + if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) { return ""; - else + } else { return _caption[caseVal - 1]; + } } ////////////////////////////////////////////////////////////////////////// bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool saving) { - if (!entity) return STATUS_FAILED; + if (!entity) { + return STATUS_FAILED; + } // HACK! - if (this->_gameRef != entity->_gameRef) + if (this->_gameRef != entity->_gameRef) { this->_gameRef = entity->_gameRef; + } if (saving) { for (int i = 0; i < 7; i++) { - if (entity->_caption[i]) setCaption(entity->_caption[i], i); + if (entity->_caption[i]) { + setCaption(entity->_caption[i], i); + } } if (!entity->_region && entity->_sprite && entity->_sprite->getFilename()) { - if (includingSprites) setFilename(entity->_sprite->getFilename()); - else setFilename(""); + if (includingSprites) { + setFilename(entity->_sprite->getFilename()); + } else { + setFilename(""); + } + } + if (entity->_cursor && entity->_cursor->getFilename()) { + setCursor(entity->_cursor->getFilename()); } - if (entity->_cursor && entity->_cursor->getFilename()) setCursor(entity->_cursor->getFilename()); _alphaColor = entity->_alphaColor; _active = entity->_active; } else { for (int i = 0; i < 7; i++) { - if (_caption[i]) entity->setCaption(_caption[i], i); + if (_caption[i]) { + entity->setCaption(_caption[i], i); + } } if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) { - if (!entity->_sprite || !entity->_sprite->getFilename() || scumm_stricmp(entity->_sprite->getFilename(), _filename) != 0) + if (!entity->_sprite || !entity->_sprite->getFilename() || scumm_stricmp(entity->_sprite->getFilename(), _filename) != 0) { entity->setSprite(_filename); + } } if (_cursor) { - if (!entity->_cursor || !entity->_cursor->getFilename() || scumm_stricmp(entity->_cursor->getFilename(), _cursor) != 0) + if (!entity->_cursor || !entity->_cursor->getFilename() || scumm_stricmp(entity->_cursor->getFilename(), _cursor) != 0) { entity->setCursor(_cursor); + } } entity->_active = _active; diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index fdbc987158..c6f0306cbb 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -94,7 +94,9 @@ AdObject::AdObject(BaseGame *inGame): BaseObject(inGame) { _inventory = NULL; - for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + _currentRegions[i] = NULL; + } _partEmitter = NULL; _partFollowParent = false; @@ -127,15 +129,18 @@ AdObject::~AdObject() { _tempSprite2 = NULL; // reference only _stickRegion = NULL; - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } if (_inventory) { ((AdGame *)_gameRef)->unregisterInventory(_inventory); _inventory = NULL; } - if (_partEmitter) + if (_partEmitter) { _gameRef->unregisterObject(_partEmitter); + } for (int i = 0; i < _attachmentsPre.getSize(); i++) { @@ -194,9 +199,12 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "PlayAnim") == 0 || strcmp(name, "PlayAnimAsync") == 0) { stack->correctParams(1); - if (DID_FAIL(playAnim(stack->pop()->getString()))) stack->pushBool(false); - else { - if (strcmp(name, "PlayAnimAsync") != 0) script->waitFor(this); + if (DID_FAIL(playAnim(stack->pop()->getString()))) { + stack->pushBool(false); + } else { + if (strcmp(name, "PlayAnimAsync") != 0) { + script->waitFor(this); + } stack->pushBool(true); } return STATUS_OK; @@ -226,12 +234,16 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "StopTalk") == 0 || strcmp(name, "StopTalking") == 0) { stack->correctParams(0); - if (_sentence) _sentence->finish(); + if (_sentence) { + _sentence->finish(); + } if (_state == STATE_TALKING) { _state = _nextState; _nextState = STATE_READY; stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -265,15 +277,20 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int align = 0; ScValue *val = stack->pop(); - if (val->isNULL()) align = TAL_CENTER; - else align = val->getInt(); + if (val->isNULL()) { + align = TAL_CENTER; + } else { + align = val->getInt(); + } align = MIN(MAX(0, align), NUM_TEXT_ALIGN - 1); const char *sound = soundVal->isNULL() ? NULL : soundVal->getString(); talk(text, sound, duration, stances, (TTextAlign)align); - if (strcmp(name, "TalkAsync") != 0) script->waitForExclusive(this); + if (strcmp(name, "TalkAsync") != 0) { + script->waitForExclusive(this); + } stack->pushNULL(); return STATUS_OK; @@ -315,7 +332,9 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } - if (!regFound) _stickRegion = NULL; + if (!regFound) { + _stickRegion = NULL; + } stack->pushBool(regFound); return STATUS_OK; } @@ -327,8 +346,11 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(1); ScValue *val = stack->pop(); - if (val->isNULL()) SetFont(NULL); - else SetFont(val->getString()); + if (val->isNULL()) { + setFont(NULL); + } else { + setFont(val->getString()); + } stack->pushNULL(); return STATUS_OK; @@ -339,8 +361,11 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetFont") == 0) { stack->correctParams(0); - if (_font && _font->getFilename()) stack->pushString(_font->getFilename()); - else stack->pushNULL(); + if (_font && _font->getFilename()) { + stack->pushString(_font->getFilename()); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -360,13 +385,16 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack const char *itemName = val->getString(); val = stack->pop(); const char *insertAfter = val->isNULL() ? NULL : val->getString(); - if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) script->runtimeError("Cannot add item '%s' to inventory", itemName); - else { + if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) { + script->runtimeError("Cannot add item '%s' to inventory", itemName); + } else { // hide associated entities ((AdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); } - } else script->runtimeError("TakeItem: item name expected"); + } else { + script->runtimeError("TakeItem: item name expected"); + } stack->pushNULL(); return STATUS_OK; @@ -385,12 +413,15 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); if (!val->isNULL()) { - if (DID_FAIL(_inventory->removeItem(val->getString()))) script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); - else { + if (DID_FAIL(_inventory->removeItem(val->getString()))) { + script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); + } else { // show associated entities ((AdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); } - } else script->runtimeError("DropItem: item name expected"); + } else { + script->runtimeError("DropItem: item name expected"); + } stack->pushNULL(); return STATUS_OK; @@ -410,12 +441,16 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); if (val->_type == VAL_STRING) { AdItem *item = ((AdGame *)_gameRef)->getItemByName(val->getString()); - if (item) stack->pushNative(item, true); - else stack->pushNULL(); - } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) + if (item) { + stack->pushNative(item, true); + } else { + stack->pushNULL(); + } + } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) { stack->pushNULL(); - else + } else { stack->pushNative(_inventory->_takenItems[val->getInt()], true); + } return STATUS_OK; } @@ -442,7 +477,9 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack return STATUS_OK; } } - } else script->runtimeError("HasItem: item name expected"); + } else { + script->runtimeError("HasItem: item name expected"); + } stack->pushBool(false); return STATUS_OK; @@ -458,8 +495,11 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int offsetY = stack->pop()->getInt(); PartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); - if (emitter) stack->pushNative(_partEmitter, true); - else stack->pushNULL(); + if (emitter) { + stack->pushNative(_partEmitter, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -502,8 +542,11 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ent->_posY = offsetY; ent->_active = true; - if (preDisplay) _attachmentsPre.add(ent); - else _attachmentsPost.add(ent); + if (preDisplay) { + _attachmentsPre.add(ent); + } else { + _attachmentsPost.add(ent); + } stack->pushBool(true); } @@ -572,11 +615,15 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int index = val->getInt(); int currIndex = 0; for (int i = 0; i < _attachmentsPre.getSize(); i++) { - if (currIndex == index) ret = _attachmentsPre[i]; + if (currIndex == index) { + ret = _attachmentsPre[i]; + } currIndex++; } for (int i = 0; i < _attachmentsPost.getSize(); i++) { - if (currIndex == index) ret = _attachmentsPost[i]; + if (currIndex == index) { + ret = _attachmentsPost[i]; + } currIndex++; } } else { @@ -597,13 +644,16 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } } - if (ret != NULL) stack->pushNative(ret, true); - else stack->pushNULL(); + if (ret != NULL) { + stack->pushNative(ret, true); + } else { + stack->pushNULL(); + } return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -695,8 +745,11 @@ ScValue *AdObject::scGetProperty(const char *name) { // ParticleEmitter (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ParticleEmitter") == 0) { - if (_partEmitter) _scValue->setNative(_partEmitter, true); - else _scValue->setNULL(); + if (_partEmitter) { + _scValue->setNative(_partEmitter, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -707,10 +760,9 @@ ScValue *AdObject::scGetProperty(const char *name) { else if (strcmp(name, "NumAttachments") == 0) { _scValue->setInt(_attachmentsPre.getSize() + _attachmentsPost.getSize()); return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - - else return BaseObject::scGetProperty(name); } @@ -779,9 +831,9 @@ bool AdObject::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "SubtitlesPosXCenter") == 0) { _subtitlesModXCenter = value->getBool(); return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -792,8 +844,10 @@ const char *AdObject::scToString() { ////////////////////////////////////////////////////////////////////////// -bool AdObject::SetFont(const char *filename) { - if (_font) _gameRef->_fontStorage->removeFont(_font); +bool AdObject::setFont(const char *filename) { + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } if (filename) { _font = _gameRef->_fontStorage->addFont(filename); return _font == NULL ? STATUS_FAILED : STATUS_OK; @@ -806,8 +860,9 @@ bool AdObject::SetFont(const char *filename) { ////////////////////////////////////////////////////////////////////////// int AdObject::getHeight() { - if (!_currentSprite) return 0; - else { + if (!_currentSprite) { + return 0; + } else { BaseFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; int ret = 0; for (int i = 0; i < frame->_subframes.getSize(); i++) { @@ -825,8 +880,12 @@ int AdObject::getHeight() { ////////////////////////////////////////////////////////////////////////// void AdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { - if (!_sentence) _sentence = new AdSentence(_gameRef); - if (!_sentence) return; + if (!_sentence) { + _sentence = new AdSentence(_gameRef); + } + if (!_sentence) { + return; + } if (_forcedTalkAnimName && _forcedTalkAnimUsed) { delete[] _forcedTalkAnimName; @@ -855,7 +914,9 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const sound = ((AdGame *)_gameRef)->findSpeechFile(key); delete[] key; - if (sound) deleteSound = true; + if (sound) { + deleteSound = true; + } } } @@ -865,10 +926,14 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const if (snd && DID_SUCCEED(snd->setSound(sound, Audio::Mixer::kSpeechSoundType, true))) { _sentence->setSound(snd); if (_sentence->_duration <= 0) { - uint32 Length = snd->getLength(); - if (Length != 0) _sentence->_duration = Length; + uint32 length = snd->getLength(); + if (length != 0) { + _sentence->_duration = length; + } } - } else delete snd; + } else { + delete snd; + } } // set duration by text length @@ -888,11 +953,14 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const } - if (_subtitlesWidth > 0) width = _subtitlesWidth; - else { + if (_subtitlesWidth > 0) { + width = _subtitlesWidth; + } else { if ((x < _gameRef->_renderer->_width / 4 || x > _gameRef->_renderer->_width * 0.75) && !_gameRef->_touchInterface) { width = MAX(_gameRef->_renderer->_width / 4, MIN(x * 2, (_gameRef->_renderer->_width - x) * 2)); - } else width = _gameRef->_renderer->_width / 2; + } else { + width = _gameRef->_renderer->_width / 2; + } } height = _sentence->_font->getTextHeight((byte *)_sentence->_text, width); @@ -905,8 +973,9 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const x = _subtitlesModX; y = _subtitlesModY; } - if (_subtitlesModXCenter) + if (_subtitlesModXCenter) { x = x - width / 2; + } x = MIN(MAX(0, x), _gameRef->_renderer->_width - width); @@ -931,7 +1000,9 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const _state = STATE_TALKING; - if (deleteSound) delete[] sound; + if (deleteSound) { + delete[] sound; + } } @@ -983,7 +1054,9 @@ bool AdObject::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_inventory)); persistMgr->transfer(TMEMBER(_partEmitter)); - for (int i = 0; i < MAX_NUM_REGIONS; i++) persistMgr->transfer(TMEMBER(_currentRegions[i])); + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + persistMgr->transfer(TMEMBER(_currentRegions[i])); + } _attachmentsPre.persist(persistMgr); _attachmentsPost.persist(persistMgr); @@ -999,8 +1072,9 @@ bool AdObject::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdObject::updateSounds() { - if (_sentence && _sentence->_sound) + if (_sentence && _sentence->_sound) { updateOneSound(_sentence->_sound); + } return BaseObject::updateSounds(); } @@ -1017,17 +1091,24 @@ bool AdObject::resetSoundPan() { ////////////////////////////////////////////////////////////////////////// bool AdObject::getExtendedFlag(const char *flagName) { - if (!flagName) return false; - else if (strcmp(flagName, "usable") == 0) return true; - - else return BaseObject::getExtendedFlag(flagName); + if (!flagName) { + return false; + } else if (strcmp(flagName, "usable") == 0) { + return true; + } else { + return BaseObject::getExtendedFlag(flagName); + } } ////////////////////////////////////////////////////////////////////////// bool AdObject::saveAsText(BaseDynamicBuffer *buffer, int indent) { - if (_blockRegion) _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); - if (_wptGroup) _wptGroup->saveAsText(buffer, indent + 2); + if (_blockRegion) { + _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); + } + if (_wptGroup) { + _wptGroup->saveAsText(buffer, indent + 2); + } BaseClass::saveAsText(buffer, indent + 2); @@ -1039,11 +1120,13 @@ bool AdObject::saveAsText(BaseDynamicBuffer *buffer, int indent) { bool AdObject::updateBlockRegion() { AdGame *adGame = (AdGame *)_gameRef; if (adGame->_scene) { - if (_blockRegion && _currentBlockRegion) + if (_blockRegion && _currentBlockRegion) { _currentBlockRegion->mimic(_blockRegion, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + } - if (_wptGroup && _currentWptGroup) + if (_wptGroup && _currentWptGroup) { _currentWptGroup->mimic(_wptGroup, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + } } return STATUS_OK; } @@ -1064,7 +1147,9 @@ bool AdObject::afterMove() { ((AdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); for (int i = 0; i < MAX_NUM_REGIONS; i++) { - if (!newRegions[i]) break; + if (!newRegions[i]) { + break; + } bool regFound = false; for (int j = 0; j < MAX_NUM_REGIONS; j++) { if (_currentRegions[j] == newRegions[i]) { @@ -1073,7 +1158,9 @@ bool AdObject::afterMove() { break; } } - if (!regFound) newRegions[i]->applyEvent("ActorEntry"); + if (!regFound) { + newRegions[i]->applyEvent("ActorEntry"); + } } for (int i = 0; i < MAX_NUM_REGIONS; i++) { @@ -1088,7 +1175,9 @@ bool AdObject::afterMove() { ////////////////////////////////////////////////////////////////////////// bool AdObject::invalidateCurrRegions() { - for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + _currentRegions[i] = NULL; + } return STATUS_OK; } @@ -1099,8 +1188,11 @@ bool AdObject::getScale(float *scaleX, float *scaleY) { if (_scaleX >= 0 || _scaleY >= 0) { *scaleX = _scaleX < 0 ? 100 : _scaleX; *scaleY = _scaleY < 0 ? 100 : _scaleY; - } else if (_scale >= 0) *scaleX = *scaleY = _scale; - else *scaleX = *scaleY = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; + } else if (_scale >= 0) { + *scaleX = *scaleY = _scale; + } else { + *scaleX = *scaleY = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; + } } else { *scaleX = *scaleY = 100; } @@ -1134,7 +1226,9 @@ bool AdObject::displaySpriteAttachments(bool preDisplay) { ////////////////////////////////////////////////////////////////////////// bool AdObject::displaySpriteAttachment(AdObject *attachment) { - if (!attachment->_active) return STATUS_OK; + if (!attachment->_active) { + return STATUS_OK; + } float scaleX, scaleY; getScale(&scaleX, &scaleY); @@ -1188,7 +1282,9 @@ PartEmitter *AdObject::createParticleEmitter(bool followParent, int offsetX, int ////////////////////////////////////////////////////////////////////////// bool AdObject::updatePartEmitter() { - if (!_partEmitter) return STATUS_FAILED; + if (!_partEmitter) { + return STATUS_FAILED; + } if (_partFollowParent) { float scaleX, scaleY; diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h index f26a29c8b2..58cb15fde3 100644 --- a/engines/wintermute/ad/ad_object.h +++ b/engines/wintermute/ad/ad_object.h @@ -73,7 +73,7 @@ public: virtual void talk(const char *text, const char *sound = NULL, uint32 duration = 0, const char *stances = NULL, TTextAlign align = TAL_CENTER); virtual int getHeight(); AdSentence *_sentence; - bool SetFont(const char *filename); + bool setFont(const char *filename); virtual bool update(); virtual bool display(); bool _drawn; diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index f7832d621d..89be10f0fb 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -48,8 +48,9 @@ AdPath::~AdPath() { ////////////////////////////////////////////////////////////////////////// void AdPath::reset() { - for (int i = 0; i < _points.getSize(); i++) + for (int i = 0; i < _points.getSize(); i++) { delete _points[i]; + } _points.removeAll(); _currIndex = -1; @@ -62,22 +63,30 @@ BasePoint *AdPath::getFirst() { if (_points.getSize() > 0) { _currIndex = 0; return _points[_currIndex]; - } else return NULL; + } else { + return NULL; + } } ////////////////////////////////////////////////////////////////////////// BasePoint *AdPath::getNext() { _currIndex++; - if (_currIndex < _points.getSize()) return _points[_currIndex]; - else return NULL; + if (_currIndex < _points.getSize()) { + return _points[_currIndex]; + } else { + return NULL; + } } ////////////////////////////////////////////////////////////////////////// BasePoint *AdPath::getCurrent() { - if (_currIndex >= 0 && _currIndex < _points.getSize()) return _points[_currIndex]; - else return NULL; + if (_currIndex >= 0 && _currIndex < _points.getSize()) { + return _points[_currIndex]; + } else { + return NULL; + } } diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index eec25b2aaa..6b104d51ad 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -64,7 +64,9 @@ bool AdRegion::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + } delete[] buffer; @@ -126,7 +128,9 @@ bool AdRegion::loadBuffer(byte *buffer, bool complete) { buffer = params; } - for (int i = 0; i < _points.getSize(); i++) delete _points[i]; + for (int i = 0; i < _points.getSize(); i++) { + delete _points[i]; + } _points.removeAll(); int ar = 255, ag = 255, ab = 255, alpha = 255; @@ -134,7 +138,9 @@ bool AdRegion::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -285,9 +291,9 @@ ScValue *AdRegion::scGetProperty(const char *name) { else if (strcmp(name, "AlphaColor") == 0) { _scValue->setInt((int)_alpha); return _scValue; + } else { + return BaseRegion::scGetProperty(name); } - - else return BaseRegion::scGetProperty(name); } @@ -331,9 +337,9 @@ bool AdRegion::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "AlphaColor") == 0) { _alpha = (uint32)value->getInt(); return STATUS_OK; + } else { + return BaseRegion::scSetProperty(name, value); } - - else return BaseRegion::scSetProperty(name, value); } @@ -361,7 +367,9 @@ bool AdRegion::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } for (i = 0; i < _points.getSize(); i++) { buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp index fbfe828330..e954b0d44d 100644 --- a/engines/wintermute/ad/ad_response.cpp +++ b/engines/wintermute/ad/ad_response.cpp @@ -59,7 +59,9 @@ AdResponse::~AdResponse() { _icon = NULL; _iconHover = NULL; _iconPressed = NULL; - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } } @@ -85,7 +87,9 @@ bool AdResponse::setIcon(const char *filename) { ////////////////////////////////////////////////////////////////////////// bool AdResponse::setFont(const char *filename) { - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } _font = _gameRef->_fontStorage->addFont(filename); if (!_font) { _gameRef->LOG(0, "AdResponse::setFont failed for file '%s'", filename); diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 22b40f3ea4..fe37002abb 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -81,8 +81,12 @@ AdResponseBox::~AdResponseBox() { delete[] _lastResponseTextOrig; _lastResponseTextOrig = NULL; - if (_font) _gameRef->_fontStorage->removeFont(_font); - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } clearResponses(); clearButtons(); @@ -137,12 +141,19 @@ bool AdResponseBox::createButtons() { // iconic if (_responses[i]->_icon) { btn->_image = _responses[i]->_icon; - if (_responses[i]->_iconHover) btn->_imageHover = _responses[i]->_iconHover; - if (_responses[i]->_iconPressed) btn->_imagePress = _responses[i]->_iconPressed; + if (_responses[i]->_iconHover) { + btn->_imageHover = _responses[i]->_iconHover; + } + if (_responses[i]->_iconPressed) { + btn->_imagePress = _responses[i]->_iconPressed; + } btn->setCaption(_responses[i]->_text); - if (_cursor) btn->_cursor = _cursor; - else if (_gameRef->_activeCursor) btn->_cursor = _gameRef->_activeCursor; + if (_cursor) { + btn->_cursor = _cursor; + } else if (_gameRef->_activeCursor) { + btn->_cursor = _gameRef->_activeCursor; + } } // textual else { @@ -152,21 +163,27 @@ bool AdResponseBox::createButtons() { btn->_fontPress = btn->_fontHover; btn->_align = _align; - if (_gameRef->_touchInterface) + if (_gameRef->_touchInterface) { btn->_fontHover = btn->_font; + } - if (_responses[i]->_font) btn->_font = _responses[i]->_font; + if (_responses[i]->_font) { + btn->_font = _responses[i]->_font; + } btn->_width = _responseArea.right - _responseArea.left; - if (btn->_width <= 0) btn->_width = _gameRef->_renderer->_width; + if (btn->_width <= 0) { + btn->_width = _gameRef->_renderer->_width; + } } btn->setName("response"); btn->correctSize(); // make the responses touchable - if (_gameRef->_touchInterface) + if (_gameRef->_touchInterface) { btn->_height = MAX(btn->_height, 50); + } //btn->SetListener(this, btn, _responses[i]->_iD); btn->setListener(this, btn, i); @@ -197,7 +214,9 @@ bool AdResponseBox::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); + } delete[] buffer; @@ -253,7 +272,9 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_WINDOW: @@ -263,19 +284,29 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { delete _window; _window = NULL; cmd = PARSERR_GENERIC; - } else if (_shieldWindow) _shieldWindow->_parent = _window; + } else if (_shieldWindow) { + _shieldWindow->_parent = _window; + } break; case TOKEN_FONT: - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } _font = _gameRef->_fontStorage->addFont((char *)params); - if (!_font) cmd = PARSERR_GENERIC; + if (!_font) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_FONT_HOVER: - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } _fontHover = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontHover) cmd = PARSERR_GENERIC; + if (!_fontHover) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_AREA: @@ -287,15 +318,23 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_TEXT_ALIGN: - if (scumm_stricmp((char *)params, "center") == 0) _align = TAL_CENTER; - else if (scumm_stricmp((char *)params, "right") == 0) _align = TAL_RIGHT; - else _align = TAL_LEFT; + if (scumm_stricmp((char *)params, "center") == 0) { + _align = TAL_CENTER; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _align = TAL_RIGHT; + } else { + _align = TAL_LEFT; + } break; case TOKEN_VERTICAL_ALIGN: - if (scumm_stricmp((char *)params, "top") == 0) _verticalAlign = VAL_TOP; - else if (scumm_stricmp((char *)params, "center") == 0) _verticalAlign = VAL_CENTER; - else _verticalAlign = VAL_BOTTOM; + if (scumm_stricmp((char *)params, "top") == 0) { + _verticalAlign = VAL_TOP; + } else if (scumm_stricmp((char *)params, "center") == 0) { + _verticalAlign = VAL_CENTER; + } else { + _verticalAlign = VAL_BOTTOM; + } break; case TOKEN_SPACING: @@ -324,8 +363,9 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { if (_window) { for (int i = 0; i < _window->_widgets.getSize(); i++) { - if (!_window->_widgets[i]->_listenerObject) + if (!_window->_widgets[i]->_listenerObject) { _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } } } @@ -339,13 +379,16 @@ bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _responseArea.left, _responseArea.top, _responseArea.right, _responseArea.bottom); - if (_font && _font->getFilename()) + if (_font && _font->getFilename()) { buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); - if (_fontHover && _fontHover->getFilename()) + } + if (_fontHover && _fontHover->getFilename()) { buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->getFilename()); + } - if (_cursor && _cursor->getFilename()) + if (_cursor && _cursor->getFilename()) { buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } buffer->putTextIndent(indent + 2, "HORIZONTAL=%s\n", _horizontal ? "TRUE" : "FALSE"); @@ -381,7 +424,9 @@ bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); // window - if (_window) _window->saveAsText(buffer, indent + 2); + if (_window) { + _window->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent + 2, "\n"); @@ -409,18 +454,22 @@ bool AdResponseBox::display() { // shift down if needed if (!_horizontal) { int total_height = 0; - for (i = 0; i < _respButtons.getSize(); i++) total_height += (_respButtons[i]->_height + _spacing); + for (i = 0; i < _respButtons.getSize(); i++) { + total_height += (_respButtons[i]->_height + _spacing); + } total_height -= _spacing; switch (_verticalAlign) { case VAL_BOTTOM: - if (yyy + total_height < rect.bottom) + if (yyy + total_height < rect.bottom) { yyy = rect.bottom - total_height; + } break; case VAL_CENTER: - if (yyy + total_height < rect.bottom) + if (yyy + total_height < rect.bottom) { yyy += ((rect.bottom - rect.top) - total_height) / 2; + } break; case VAL_TOP: @@ -467,7 +516,9 @@ bool AdResponseBox::display() { } // display window - if (_window) _window->display(); + if (_window) { + _window->display(); + } // display response buttons @@ -490,7 +541,9 @@ bool AdResponseBox::listen(BaseScriptHolder *param1, uint32 param2) { } else if (scumm_stricmp(obj->getName(), "next") == 0) { _scrollOffset++; } else if (scumm_stricmp(obj->getName(), "response") == 0) { - if (_waitingScript) _waitingScript->_stack->pushInt(_responses[param2]->_iD); + if (_waitingScript) { + _waitingScript->_stack->pushInt(_responses[param2]->_iD); + } handleResponse(_responses[param2]); _waitingScript = NULL; _gameRef->_state = GAME_RUNNING; @@ -498,7 +551,9 @@ bool AdResponseBox::listen(BaseScriptHolder *param1, uint32 param2) { _ready = true; invalidateButtons(); clearResponses(); - } else return BaseObject::listen(param1, param2); + } else { + return BaseObject::listen(param1, param2); + } break; default: error("AdResponseBox::Listen - Unhandled enum"); @@ -597,13 +652,17 @@ BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) { BaseArray objects; getObjects(objects, true); - if (objects.getSize() == 0) return NULL; - else { + if (objects.getSize() == 0) { + return NULL; + } else { if (currObject != NULL) { for (int i = 0; i < objects.getSize(); i++) { if (objects[i] == currObject) { - if (i < objects.getSize() - 1) return objects[i + 1]; - else break; + if (i < objects.getSize() - 1) { + return objects[i + 1]; + } else { + break; + } } } } @@ -617,13 +676,17 @@ BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { BaseArray objects; getObjects(objects, true); - if (objects.getSize() == 0) return NULL; - else { + if (objects.getSize() == 0) { + return NULL; + } else { if (currObject != NULL) { for (int i = objects.getSize() - 1; i >= 0; i--) { if (objects[i] == currObject) { - if (i > 0) return objects[i - 1]; - else break; + if (i > 0) { + return objects[i - 1]; + } else { + break; + } } } } @@ -637,7 +700,9 @@ bool AdResponseBox::getObjects(BaseArray &objects, bool for (int i = 0; i < _respButtons.getSize(); i++) { objects.add(_respButtons[i]); } - if (_window) _window->getWindowObjects(objects, interactiveOnly); + if (_window) { + _window->getWindowObjects(objects, interactiveOnly); + } return STATUS_OK; } diff --git a/engines/wintermute/ad/ad_response_context.cpp b/engines/wintermute/ad/ad_response_context.cpp index 8d966e7a3e..41359fc0f0 100644 --- a/engines/wintermute/ad/ad_response_context.cpp +++ b/engines/wintermute/ad/ad_response_context.cpp @@ -35,7 +35,7 @@ IMPLEMENT_PERSISTENT(AdResponseContext, false) ////////////////////////////////////////////////////////////////////////// AdResponseContext::AdResponseContext(BaseGame *inGame): BaseClass(inGame) { - _iD = 0; + _id = 0; _context = NULL; } @@ -51,7 +51,7 @@ AdResponseContext::~AdResponseContext() { bool AdResponseContext::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_gameRef)); persistMgr->transfer(TMEMBER(_context)); - persistMgr->transfer(TMEMBER(_iD)); + persistMgr->transfer(TMEMBER(_id)); return STATUS_OK; } @@ -62,7 +62,9 @@ void AdResponseContext::setContext(const char *context) { _context = NULL; if (context) { _context = new char [strlen(context) + 1]; - if (_context) strcpy(_context, context); + if (_context) { + strcpy(_context, context); + } } } diff --git a/engines/wintermute/ad/ad_response_context.h b/engines/wintermute/ad/ad_response_context.h index d0dc1546b7..d5c8bb3fa3 100644 --- a/engines/wintermute/ad/ad_response_context.h +++ b/engines/wintermute/ad/ad_response_context.h @@ -37,7 +37,7 @@ namespace WinterMute { class AdResponseContext : public BaseClass { public: void setContext(const char *context); - int _iD; + int _id; char *_context; DECLARE_PERSISTENT(AdResponseContext, BaseClass) AdResponseContext(BaseGame *inGame); diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index 72fcaeff28..f04d379e6b 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -63,7 +63,9 @@ bool AdRotLevel::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); + } delete[] buffer; @@ -104,7 +106,9 @@ bool AdRotLevel::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_X: diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index c390c6dc08..f9da6bba4a 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -61,7 +61,9 @@ bool AdScaleLevel::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); + } delete[] buffer; @@ -102,7 +104,9 @@ bool AdScaleLevel::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_Y: diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 85c2341268..21f28b6247 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -148,31 +148,37 @@ void AdScene::cleanup() { _gameRef->unregisterObject(_fader); _fader = NULL; - for (i = 0; i < _layers.getSize(); i++) + for (i = 0; i < _layers.getSize(); i++) { _gameRef->unregisterObject(_layers[i]); + } _layers.removeAll(); - for (i = 0; i < _waypointGroups.getSize(); i++) + for (i = 0; i < _waypointGroups.getSize(); i++) { _gameRef->unregisterObject(_waypointGroups[i]); + } _waypointGroups.removeAll(); - for (i = 0; i < _scaleLevels.getSize(); i++) + for (i = 0; i < _scaleLevels.getSize(); i++) { _gameRef->unregisterObject(_scaleLevels[i]); + } _scaleLevels.removeAll(); - for (i = 0; i < _rotLevels.getSize(); i++) + for (i = 0; i < _rotLevels.getSize(); i++) { _gameRef->unregisterObject(_rotLevels[i]); + } _rotLevels.removeAll(); - for (i = 0; i < _pfPath.getSize(); i++) + for (i = 0; i < _pfPath.getSize(); i++) { delete _pfPath[i]; + } _pfPath.removeAll(); _pfPointsNum = 0; - for (i = 0; i < _objects.getSize(); i++) + for (i = 0; i < _objects.getSize(); i++) { _gameRef->unregisterObject(_objects[i]); + } _objects.removeAll(); delete _viewport; @@ -184,8 +190,9 @@ void AdScene::cleanup() { ////////////////////////////////////////////////////////////////////////// bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester) { - if (!_pfReady) return false; - else { + if (!_pfReady) { + return false; + } else { _pfReady = false; *_pfTarget = target; _pfTargetPath = path; @@ -258,10 +265,14 @@ bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObje ////////////////////////////////////////////////////////////////////////// void AdScene::pfAddWaypointGroup(AdWaypointGroup *wpt, BaseObject *requester) { - if (!wpt->_active) return; + if (!wpt->_active) { + return; + } for (int i = 0; i < wpt->_points.getSize(); i++) { - if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) continue; + if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) { + continue; + } //_pfPath.add(new AdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX); @@ -286,7 +297,9 @@ float AdScene::getZoomAt(int x, int y) { } } } - if (!found) ret = getScaleAt(y); + if (!found) { + ret = getScaleAt(y); + } return ret; } @@ -294,17 +307,24 @@ float AdScene::getZoomAt(int x, int y) { ////////////////////////////////////////////////////////////////////////// uint32 AdScene::getAlphaAt(int x, int y, bool colorCheck) { - if (!_gameRef->_debugDebugMode) colorCheck = false; + if (!_gameRef->_debugDebugMode) { + colorCheck = false; + } uint32 ret; - if (colorCheck) ret = 0xFFFF0000; - else ret = 0xFFFFFFFF; + if (colorCheck) { + ret = 0xFFFF0000; + } else { + ret = 0xFFFFFFFF; + } if (_mainLayer) { for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { - if (!node->_region->_blocked) ret = node->_region->_alpha; + if (!node->_region->_blocked) { + ret = node->_region->_alpha; + } break; } } @@ -321,13 +341,17 @@ bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *reque if (checkFreeObjects) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { - if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return true; + } } } AdGame *adGame = (AdGame *)_gameRef; for (int i = 0; i < adGame->_objects.getSize(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { - if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return true; + } } } } @@ -347,7 +371,9 @@ bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *reque if (node->_region->_blocked) { ret = true; break; - } else ret = false; + } else { + ret = false; + } } } } @@ -362,13 +388,17 @@ bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requ if (checkFreeObjects) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { - if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return false; + } } } AdGame *adGame = (AdGame *)_gameRef; for (int i = 0; i < adGame->_objects.getSize(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { - if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return false; + } } } } @@ -381,7 +411,9 @@ bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requ if (node->_region->_blocked) { ret = false; break; - } else ret = true; + } else { + ret = true; + } } } } @@ -413,7 +445,9 @@ int AdScene::getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester) { y = y1; for (xCount = x1; xCount < x2; xCount++) { - if (isBlockedAt(xCount, (int)y, true, requester)) return -1; + if (isBlockedAt(xCount, (int)y, true, requester)) { + return -1; + } y += yStep; } } else { @@ -426,7 +460,9 @@ int AdScene::getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester) { x = x1; for (yCount = y1; yCount < y2; yCount++) { - if (isBlockedAt((int)x, yCount, true, requester)) return -1; + if (isBlockedAt((int)x, yCount, true, requester)) { + return -1; + } x += xStep; } } @@ -488,10 +524,14 @@ bool AdScene::initLoop() { PathFinderStep(); nu_steps++; } - if (nu_steps > 0) _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); + if (nu_steps > 0) { + _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); + } #else uint32 start = _gameRef->_currentTime; - while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) pathFinderStep(); + while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) { + pathFinderStep(); + } #endif return STATUS_OK; @@ -510,7 +550,9 @@ bool AdScene::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); + } setFilename(filename); @@ -622,7 +664,9 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -815,8 +859,12 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { case TOKEN_VIEWPORT: { Rect32 rc; parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_viewport) _viewport = new BaseViewport(_gameRef); - if (_viewport) _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); + if (!_viewport) { + _viewport = new BaseViewport(_gameRef); + } + if (_viewport) { + _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); + } } case TOKEN_PERSISTENT_STATE: @@ -838,7 +886,9 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { return STATUS_FAILED; } - if (_mainLayer == NULL) _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", getFilename()); + if (_mainLayer == NULL) { + _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", getFilename()); + } sortScaleLevels(); @@ -852,7 +902,9 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// bool AdScene::traverseNodes(bool doUpdate) { - if (!_initialized) return STATUS_OK; + if (!_initialized) { + return STATUS_OK; + } int j, k; AdGame *adGame = (AdGame *)_gameRef; @@ -860,13 +912,13 @@ bool AdScene::traverseNodes(bool doUpdate) { ////////////////////////////////////////////////////////////////////////// // prepare viewport - bool PopViewport = false; + bool popViewport = false; if (_viewport && !_gameRef->_editorMode) { _gameRef->pushViewport(_viewport); - PopViewport = true; + popViewport = true; } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { _gameRef->pushViewport(adGame->_sceneViewport); - PopViewport = true; + popViewport = true; } @@ -905,8 +957,12 @@ bool AdScene::traverseNodes(bool doUpdate) { } } - if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) _ready = true; - } else _ready = true; // not scrolling, i.e. always ready + if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) { + _ready = true; + } + } else { + _ready = true; // not scrolling, i.e. always ready + } } @@ -939,12 +995,16 @@ bool AdScene::traverseNodes(bool doUpdate) { /* int MainOffsetY = 0; */ for (j = 0; j < _layers.getSize(); j++) { - if (!_layers[j]->_active) continue; + if (!_layers[j]->_active) { + continue; + } // make layer exclusive if (!doUpdate) { if (_layers[j]->_closeUp && !_gameRef->_editorMode) { - if (!_shieldWindow) _shieldWindow = new UIWindow(_gameRef); + if (!_shieldWindow) { + _shieldWindow = new UIWindow(_gameRef); + } if (_shieldWindow) { _shieldWindow->_posX = _shieldWindow->_posY = 0; _shieldWindow->_width = _gameRef->_renderer->_width; @@ -979,16 +1039,25 @@ bool AdScene::traverseNodes(bool doUpdate) { if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) { _gameRef->_renderer->setup2D(); - if (doUpdate) node->_entity->update(); - else node->_entity->display(); + if (doUpdate) { + node->_entity->update(); + } else { + node->_entity->display(); + } } break; case OBJECT_REGION: { - if (node->_region->_blocked) break; - if (node->_region->_decoration) break; + if (node->_region->_blocked) { + break; + } + if (node->_region->_decoration) { + break; + } - if (!doUpdate) displayRegionContent(node->_region); + if (!doUpdate) { + displayRegionContent(node->_region); + } } break; default: @@ -1014,11 +1083,16 @@ bool AdScene::traverseNodes(bool doUpdate) { // display/update fader if (_fader) { - if (doUpdate) _fader->update(); - else _fader->display(); + if (doUpdate) { + _fader->update(); + } else { + _fader->display(); + } } - if (PopViewport) _gameRef->popViewport(); + if (popViewport) { + _gameRef->popViewport(); + } return STATUS_OK; } @@ -1037,7 +1111,9 @@ bool AdScene::updateFreeObjects() { // *** update all active objects is3DSet = false; for (int i = 0; i < adGame->_objects.getSize(); i++) { - if (!adGame->_objects[i]->_active) continue; + if (!adGame->_objects[i]->_active) { + continue; + } adGame->_objects[i]->update(); adGame->_objects[i]->_drawn = false; @@ -1045,7 +1121,9 @@ bool AdScene::updateFreeObjects() { for (int i = 0; i < _objects.getSize(); i++) { - if (!_objects[i]->_active) continue; + if (!_objects[i]->_active) { + continue; + } _objects[i]->update(); _objects[i]->_drawn = false; @@ -1090,11 +1168,15 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { for (int i = 0; i < objects.getSize(); i++) { obj = objects[i]; - if (display3DOnly && !obj->_is3D) continue; + if (display3DOnly && !obj->_is3D) { + continue; + } _gameRef->_renderer->setup2D(); - if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); + if (_gameRef->_editorMode || !obj->_editorOnly) { + obj->display(); + } obj->_drawn = true; } @@ -1119,9 +1201,13 @@ int AdScene::compareObjs(const void *obj1, const void *obj2) { AdObject *object1 = *(AdObject **)obj1; AdObject *object2 = *(AdObject **)obj2; - if (object1->_posY < object2->_posY) return -1; - else if (object1->_posY > object2->_posY) return 1; - else return 0; + if (object1->_posY < object2->_posY) { + return -1; + } else if (object1->_posY > object2->_posY) { + return 1; + } else { + return 0; + } } ////////////////////////////////////////////////////////////////////////// @@ -1154,7 +1240,9 @@ bool AdScene::displayRegionContentOld(AdRegion *region) { if (obj != NULL) { _gameRef->_renderer->setup2D(); - if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); + if (_gameRef->_editorMode || !obj->_editorOnly) { + obj->display(); + } obj->_drawn = true; } } while (obj != NULL); @@ -1195,8 +1283,12 @@ void AdScene::scrollTo(int offsetX, int offsetY) { if (_gameRef->_mainObject && _gameRef->_mainObject->_is3D) { - if (abs(origOffsetLeft - _targetOffsetLeft) < 5) _targetOffsetLeft = origOffsetLeft; - if (abs(origOffsetTop - _targetOffsetTop) < 5) _targetOffsetTop = origOffsetTop; + if (abs(origOffsetLeft - _targetOffsetLeft) < 5) { + _targetOffsetLeft = origOffsetLeft; + } + if (abs(origOffsetTop - _targetOffsetTop) < 5) { + _targetOffsetTop = origOffsetTop; + } //_targetOffsetTop = 0; } @@ -1206,13 +1298,17 @@ void AdScene::scrollTo(int offsetX, int offsetY) { ////////////////////////////////////////////////////////////////////////// void AdScene::scrollToObject(BaseObject *object) { - if (object) scrollTo(object->_posX, object->_posY - object->getHeight() / 2); + if (object) { + scrollTo(object->_posX, object->_posY - object->getHeight() / 2); + } } ////////////////////////////////////////////////////////////////////////// void AdScene::skipToObject(BaseObject *object) { - if (object) skipTo(object->_posX, object->_posY - object->getHeight() / 2); + if (object) { + skipTo(object->_posX, object->_posY - object->getHeight() / 2); + } } @@ -1279,7 +1375,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdEntity *ent = new AdEntity(_gameRef); addObject(ent); - if (!val->isNULL()) ent->setName(val->getString()); + if (!val->isNULL()) { + ent->setName(val->getString()); + } stack->pushNative(ent, true); return STATUS_OK; } @@ -1292,7 +1390,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdObject *obj = (AdObject *)val->getNative(); removeObject(obj); - if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + if (val->getType() == VAL_VARIABLE_REF) { + val->setNULL(); + } stack->pushNULL(); return STATUS_OK; @@ -1326,7 +1426,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } else { scrollTo(val1->getInt(), val2->getInt()); } - if (strcmp(name, "ScrollTo") == 0) script->waitForExclusive(this); + if (strcmp(name, "ScrollTo") == 0) { + script->waitForExclusive(this); + } stack->pushNULL(); return STATUS_OK; } @@ -1339,19 +1441,24 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); if (val->isInt()) { int layer = val->getInt(); - if (layer < 0 || layer >= _layers.getSize()) stack->pushNULL(); - else stack->pushNative(_layers[layer], true); + if (layer < 0 || layer >= _layers.getSize()) { + stack->pushNULL(); + } else { + stack->pushNative(_layers[layer], true); + } } else { - const char *LayerName = val->getString(); - bool LayerFound = false; + const char *layerName = val->getString(); + bool layerFound = false; for (int i = 0; i < _layers.getSize(); i++) { - if (scumm_stricmp(LayerName, _layers[i]->getName()) == 0) { + if (scumm_stricmp(layerName, _layers[i]->getName()) == 0) { stack->pushNative(_layers[i], true); - LayerFound = true; + layerFound = true; break; } } - if (!LayerFound) stack->pushNULL(); + if (!layerFound) { + stack->pushNULL(); + } } return STATUS_OK; } @@ -1362,8 +1469,11 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetWaypointGroup") == 0) { stack->correctParams(1); int group = stack->pop()->getInt(); - if (group < 0 || group >= _waypointGroups.getSize()) stack->pushNULL(); - else stack->pushNative(_waypointGroups[group], true); + if (group < 0 || group >= _waypointGroups.getSize()) { + stack->pushNULL(); + } else { + stack->pushNative(_waypointGroups[group], true); + } return STATUS_OK; } @@ -1375,8 +1485,11 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *nodeName = stack->pop()->getString(); BaseObject *node = getNodeByName(nodeName); - if (node) stack->pushNative((BaseScriptable *)node, true); - else stack->pushNULL(); + if (node) { + stack->pushNative((BaseScriptable *)node, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -1391,7 +1504,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdObject *ret = NULL; if (val->isInt()) { int index = val->getInt(); - if (index >= 0 && index < _objects.getSize()) ret = _objects[index]; + if (index >= 0 && index < _objects.getSize()) { + ret = _objects[index]; + } } else { const char *nodeName = val->getString(); for (int i = 0; i < _objects.getSize(); i++) { @@ -1401,8 +1516,11 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } } - if (ret) stack->pushNative(ret, true); - else stack->pushNULL(); + if (ret) { + stack->pushNative(ret, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -1417,13 +1535,17 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); bool includeDecors = false; - if (!val->isNULL()) includeDecors = val->getBool(); + if (!val->isNULL()) { + includeDecors = val->getBool(); + } if (_mainLayer) { for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { - if (node->_region->_decoration && !includeDecors) continue; + if (node->_region->_decoration && !includeDecors) { + continue; + } stack->pushNative(node->_region, true); return STATUS_OK; @@ -1489,7 +1611,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->correctParams(0); bool ret = false; if (_autoScroll) { - if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) ret = true; + if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) { + ret = true; + } } stack->pushBool(ret); @@ -1508,7 +1632,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, byte alpha = stack->pop()->getInt(0xFF); _fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration); - if (strcmp(name, "FadeOutAsync") != 0) script->waitFor(_fader); + if (strcmp(name, "FadeOutAsync") != 0) { + script->waitFor(_fader); + } stack->pushNULL(); return STATUS_OK; @@ -1526,7 +1652,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, byte alpha = stack->pop()->getInt(0xFF); _fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration); - if (strcmp(name, "FadeInAsync") != 0) script->waitFor(_fader); + if (strcmp(name, "FadeInAsync") != 0) { + script->waitFor(_fader); + } stack->pushNULL(); return STATUS_OK; @@ -1562,11 +1690,19 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, int width = stack->pop()->getInt(); int height = stack->pop()->getInt(); - if (width <= 0) width = _gameRef->_renderer->_width; - if (height <= 0) height = _gameRef->_renderer->_height; + if (width <= 0) { + width = _gameRef->_renderer->_width; + } + if (height <= 0) { + height = _gameRef->_renderer->_height; + } - if (!_viewport) _viewport = new BaseViewport(_gameRef); - if (_viewport) _viewport->setRect(x, y, x + width, y + height); + if (!_viewport) { + _viewport = new BaseViewport(_gameRef); + } + if (_viewport) { + _viewport->setRect(x, y, x + width, y + height); + } stack->pushBool(true); @@ -1581,7 +1717,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdLayer *layer = new AdLayer(_gameRef); - if (!val->isNULL()) layer->setName(val->getString()); + if (!val->isNULL()) { + layer->setName(val->getString()); + } if (_mainLayer) { layer->_width = _mainLayer->_width; layer->_height = _mainLayer->_height; @@ -1602,14 +1740,21 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdLayer *layer = new AdLayer(_gameRef); - if (!val->isNULL()) layer->setName(val->getString()); + if (!val->isNULL()) { + layer->setName(val->getString()); + } if (_mainLayer) { layer->_width = _mainLayer->_width; layer->_height = _mainLayer->_height; } - if (index < 0) index = 0; - if (index <= _layers.getSize() - 1) _layers.insertAt(index, layer); - else _layers.add(layer); + if (index < 0) { + index = 0; + } + if (index <= _layers.getSize() - 1) { + _layers.insertAt(index, layer); + } else { + _layers.add(layer); + } _gameRef->registerObject(layer); @@ -1659,9 +1804,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } stack->pushBool(true); return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -1697,8 +1842,11 @@ ScValue *AdScene::scGetProperty(const char *name) { // MainLayer (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "MainLayer") == 0) { - if (_mainLayer) _scValue->setNative(_mainLayer, true); - else _scValue->setNULL(); + if (_mainLayer) { + _scValue->setNative(_mainLayer, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -1810,8 +1958,11 @@ ScValue *AdScene::scGetProperty(const char *name) { // Width (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Width") == 0) { - if (_mainLayer) _scValue->setInt(_mainLayer->_width); - else _scValue->setInt(0); + if (_mainLayer) { + _scValue->setInt(_mainLayer->_width); + } else { + _scValue->setInt(0); + } return _scValue; } @@ -1819,12 +1970,15 @@ ScValue *AdScene::scGetProperty(const char *name) { // Height (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Height") == 0) { - if (_mainLayer) _scValue->setInt(_mainLayer->_height); - else _scValue->setInt(0); + if (_mainLayer) { + _scValue->setInt(_mainLayer->_height); + } else { + _scValue->setInt(0); + } return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -1924,9 +2078,9 @@ bool AdScene::scSetProperty(const char *name, ScValue *value) { _targetOffsetTop = _offsetTop; return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -1964,11 +2118,13 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - if (_persistentState) + if (_persistentState) { buffer->putTextIndent(indent + 2, "PERSISTENT_STATE=%s\n", _persistentState ? "TRUE" : "FALSE"); + } - if (!_persistentStateSprites) + if (!_persistentStateSprites) { buffer->putTextIndent(indent + 2, "PERSISTENT_STATE_SPRITES=%s\n", _persistentStateSprites ? "TRUE" : "FALSE"); + } // scripts @@ -1979,7 +2135,9 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); // properties - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } // viewport if (_viewport) { @@ -2018,21 +2176,29 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { // waypoints buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); - for (i = 0; i < _waypointGroups.getSize(); i++) _waypointGroups[i]->saveAsText(buffer, indent + 2); + for (i = 0; i < _waypointGroups.getSize(); i++) { + _waypointGroups[i]->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent + 2, "\n"); // layers buffer->putTextIndent(indent + 2, "; ----- layers\n"); - for (i = 0; i < _layers.getSize(); i++) _layers[i]->saveAsText(buffer, indent + 2); + for (i = 0; i < _layers.getSize(); i++) { + _layers[i]->saveAsText(buffer, indent + 2); + } // scale levels buffer->putTextIndent(indent + 2, "; ----- scale levels\n"); - for (i = 0; i < _scaleLevels.getSize(); i++) _scaleLevels[i]->saveAsText(buffer, indent + 2); + for (i = 0; i < _scaleLevels.getSize(); i++) { + _scaleLevels[i]->saveAsText(buffer, indent + 2); + } // rotation levels buffer->putTextIndent(indent + 2, "; ----- rotation levels\n"); - for (i = 0; i < _rotLevels.getSize(); i++) _rotLevels[i]->saveAsText(buffer, indent + 2); + for (i = 0; i < _rotLevels.getSize(); i++) { + _rotLevels[i]->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent + 2, "\n"); @@ -2103,14 +2269,17 @@ float AdScene::getScaleAt(int Y) { for (int i = 0; i < _scaleLevels.getSize(); i++) { /* AdScaleLevel *xxx = _scaleLevels[i];*/ /* int j = _scaleLevels.getSize(); */ - if (_scaleLevels[i]->_posY < Y) prev = _scaleLevels[i]; - else { + if (_scaleLevels[i]->_posY < Y) { + prev = _scaleLevels[i]; + } else { next = _scaleLevels[i]; break; } } - if (prev == NULL || next == NULL) return 100; + if (prev == NULL || next == NULL) { + return 100; + } int delta_y = next->_posY - prev->_posY; float delta_scale = next->_scale - prev->_scale; @@ -2255,70 +2424,86 @@ bool AdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, b } // right - int length_right = 0; - bool found_right = false; - for (x = *argX, y = *argY; x < _mainLayer->_width; x++, length_right++) { + int lengthRight = 0; + bool foundRight = false; + for (x = *argX, y = *argY; x < _mainLayer->_width; x++, lengthRight++) { if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x - 5, y, checkFreeObjects, requester)) { - found_right = true; + foundRight = true; break; } } // left - int length_left = 0; - bool found_left = false; - for (x = *argX, y = *argY; x >= 0; x--, length_left--) { + int lengthLeft = 0; + bool foundLeft = false; + for (x = *argX, y = *argY; x >= 0; x--, lengthLeft--) { if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x + 5, y, checkFreeObjects, requester)) { - found_left = true; + foundLeft = true; break; } } // up - int length_up = 0; - bool found_up = false; - for (x = *argX, y = *argY; y >= 0; y--, length_up--) { + int lengthUp = 0; + bool foundUp = false; + for (x = *argX, y = *argY; y >= 0; y--, lengthUp--) { if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y + 5, checkFreeObjects, requester)) { - found_up = true; + foundUp = true; break; } } // down - int length_down = 0; - bool found_down = false; - for (x = *argX, y = *argY; y < _mainLayer->_height; y++, length_down++) { + int lengthDown = 0; + bool foundDown = false; + for (x = *argX, y = *argY; y < _mainLayer->_height; y++, lengthDown++) { if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y - 5, checkFreeObjects, requester)) { - found_down = true; + foundDown = true; break; } } - if (!found_left && !found_right && !found_up && !found_down) { + if (!foundLeft && !foundRight && !foundUp && !foundDown) { return STATUS_OK; } - int OffsetX = INT_MAX, OffsetY = INT_MAX; + int offsetX = INT_MAX, offsetY = INT_MAX; - if (found_left && found_right) { - if (abs(length_left) < abs(length_right)) OffsetX = length_left; - else OffsetX = length_right; - } else if (found_left) OffsetX = length_left; - else if (found_right) OffsetX = length_right; + if (foundLeft && foundRight) { + if (abs(lengthLeft) < abs(lengthRight)) { + offsetX = lengthLeft; + } else { + offsetX = lengthRight; + } + } else if (foundLeft) { + offsetX = lengthLeft; + } else if (foundRight) { + offsetX = lengthRight; + } - if (found_up && found_down) { - if (abs(length_up) < abs(length_down)) OffsetY = length_up; - else OffsetY = length_down; - } else if (found_up) OffsetY = length_up; - else if (found_down) OffsetY = length_down; + if (foundUp && foundDown) { + if (abs(lengthUp) < abs(lengthDown)) { + offsetY = lengthUp; + } else { + offsetY = lengthDown; + } + } else if (foundUp) { + offsetY = lengthUp; + } else if (foundDown) { + offsetY = lengthDown; + } - if (abs(OffsetX) < abs(OffsetY)) - *argX = *argX + OffsetX; - else - *argY = *argY + OffsetY; + if (abs(offsetX) < abs(offsetY)) { + *argX = *argX + offsetX; + } else { + *argY = *argY + offsetY; + } - if (!isWalkableAt(*argX, *argY)) return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); - else return STATUS_OK; + if (!isWalkableAt(*argX, *argY)) { + return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); + } else { + return STATUS_OK; + } } @@ -2348,14 +2533,26 @@ void AdScene::pfPointsAdd(int x, int y, int distance) { bool AdScene::getViewportOffset(int *offsetX, int *offsetY) { AdGame *adGame = (AdGame *)_gameRef; if (_viewport && !_gameRef->_editorMode) { - if (offsetX) *offsetX = _viewport->_offsetX; - if (offsetY) *offsetY = _viewport->_offsetY; + if (offsetX) { + *offsetX = _viewport->_offsetX; + } + if (offsetY) { + *offsetY = _viewport->_offsetY; + } } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - if (offsetX) *offsetX = adGame->_sceneViewport->_offsetX; - if (offsetY) *offsetY = adGame->_sceneViewport->_offsetY; + if (offsetX) { + *offsetX = adGame->_sceneViewport->_offsetX; + } + if (offsetY) { + *offsetY = adGame->_sceneViewport->_offsetY; + } } else { - if (offsetX) *offsetX = 0; - if (offsetY) *offsetY = 0; + if (offsetX) { + *offsetX = 0; + } + if (offsetY) { + *offsetY = 0; + } } return STATUS_OK; } @@ -2365,14 +2562,26 @@ bool AdScene::getViewportOffset(int *offsetX, int *offsetY) { bool AdScene::getViewportSize(int *width, int *height) { AdGame *adGame = (AdGame *)_gameRef; if (_viewport && !_gameRef->_editorMode) { - if (width) *width = _viewport->getWidth(); - if (height) *height = _viewport->getHeight(); + if (width) { + *width = _viewport->getWidth(); + } + if (height) { + *height = _viewport->getHeight(); + } } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - if (width) *width = adGame->_sceneViewport->getWidth(); - if (height) *height = adGame->_sceneViewport->getHeight(); + if (width) { + *width = adGame->_sceneViewport->getWidth(); + } + if (height) { + *height = adGame->_sceneViewport->getHeight(); + } } else { - if (width) *width = _gameRef->_renderer->_width; - if (height) *height = _gameRef->_renderer->_height; + if (width) { + *width = _gameRef->_renderer->_width; + } + if (height) { + *height = _gameRef->_renderer->_height; + } } return STATUS_OK; } @@ -2472,11 +2681,15 @@ bool AdScene::loadState() { ////////////////////////////////////////////////////////////////////////// bool AdScene::persistState(bool saving) { - if (!_persistentState) return STATUS_OK; + if (!_persistentState) { + return STATUS_OK; + } AdGame *adGame = (AdGame *)_gameRef; AdSceneState *state = adGame->getSceneState(getFilename(), saving); - if (!state) return STATUS_OK; + if (!state) { + return STATUS_OK; + } AdNodeState *nodeState; @@ -2487,7 +2700,9 @@ bool AdScene::persistState(bool saving) { AdSceneNode *node = layer->_nodes[j]; switch (node->_type) { case OBJECT_ENTITY: - if (!node->_entity->_saveState) continue; + if (!node->_entity->_saveState) { + continue; + } nodeState = state->getNodeState(node->_entity->getName(), saving); if (nodeState) { nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); @@ -2496,11 +2711,16 @@ bool AdScene::persistState(bool saving) { } break; case OBJECT_REGION: - if (!node->_region->_saveState) continue; + if (!node->_region->_saveState) { + continue; + } nodeState = state->getNodeState(node->_region->getName(), saving); if (nodeState) { - if (saving) nodeState->_active = node->_region->_active; - else node->_region->_active = nodeState->_active; + if (saving) { + nodeState->_active = node->_region->_active; + } else { + node->_region->_active = nodeState->_active; + } } break; default: @@ -2512,7 +2732,9 @@ bool AdScene::persistState(bool saving) { // free entities for (int i = 0; i < _objects.getSize(); i++) { - if (!_objects[i]->_saveState) continue; + if (!_objects[i]->_saveState) { + continue; + } if (_objects[i]->_type == OBJECT_ENTITY) { nodeState = state->getNodeState(_objects[i]->getName(), saving); if (nodeState) { @@ -2527,8 +2749,11 @@ bool AdScene::persistState(bool saving) { for (int i = 0; i < _waypointGroups.getSize(); i++) { nodeState = state->getNodeState(_waypointGroups[i]->getName(), saving); if (nodeState) { - if (saving) nodeState->_active = _waypointGroups[i]->_active; - else _waypointGroups[i]->_active = nodeState->_active; + if (saving) { + nodeState->_active = _waypointGroups[i]->_active; + } else { + _waypointGroups[i]->_active = nodeState->_active; + } } } @@ -2544,14 +2769,17 @@ float AdScene::getRotationAt(int x, int y) { for (int i = 0; i < _rotLevels.getSize(); i++) { /* AdRotLevel *xxx = _rotLevels[i]; int j = _rotLevels.getSize();*/ - if (_rotLevels[i]->_posX < x) prev = _rotLevels[i]; - else { + if (_rotLevels[i]->_posX < x) { + prev = _rotLevels[i]; + } else { next = _rotLevels[i]; break; } } - if (prev == NULL || next == NULL) return 0; + if (prev == NULL || next == NULL) { + return 0; + } int delta_x = next->_posX - prev->_posX; float delta_rot = next->_rotation - prev->_rotation; @@ -2570,7 +2798,9 @@ bool AdScene::handleItemAssociations(const char *itemName, bool show) { if (layer->_nodes[j]->_type == OBJECT_ENTITY) { AdEntity *ent = layer->_nodes[j]->_entity; - if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; + if (ent->_item && strcmp(ent->_item, itemName) == 0) { + ent->_active = show; + } } } } @@ -2578,7 +2808,9 @@ bool AdScene::handleItemAssociations(const char *itemName, bool show) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i]->_type == OBJECT_ENTITY) { AdEntity *ent = (AdEntity *)_objects[i]; - if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; + if (ent->_item && strcmp(ent->_item, itemName) == 0) { + ent->_active = show; + } } } @@ -2596,7 +2828,9 @@ bool AdScene::getRegionsAt(int x, int y, AdRegion **regionList, int numRegions) if (numUsed < numRegions - 1) { regionList[numUsed] = node->_region; numUsed++; - } else break; + } else { + break; + } } } } @@ -2618,13 +2852,17 @@ BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) { BaseArray objects; getSceneObjects(objects, true); - if (objects.getSize() == 0) return NULL; - else { + if (objects.getSize() == 0) { + return NULL; + } else { if (currObject != NULL) { for (int i = 0; i < objects.getSize(); i++) { if (objects[i] == currObject) { - if (i < objects.getSize() - 1) return objects[i + 1]; - else break; + if (i < objects.getSize() - 1) { + return objects[i + 1]; + } else { + break; + } } } } @@ -2638,13 +2876,17 @@ BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { BaseArray objects; getSceneObjects(objects, true); - if (objects.getSize() == 0) return NULL; - else { + if (objects.getSize() == 0) { + return NULL; + } else { if (currObject != NULL) { for (int i = objects.getSize() - 1; i >= 0; i--) { if (objects[i] == currObject) { - if (i > 0) return objects[i - 1]; - else break; + if (i > 0) { + return objects[i - 1]; + } else { + break; + } } } } @@ -2658,7 +2900,9 @@ BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOnly) { for (int i = 0; i < _layers.getSize(); i++) { // close-up layer -> remove everything below it - if (interactiveOnly && _layers[i]->_closeUp) objects.removeAll(); + if (interactiveOnly && _layers[i]->_closeUp) { + objects.removeAll(); + } for (int j = 0; j < _layers[i]->_nodes.getSize(); j++) { @@ -2666,8 +2910,9 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i switch (node->_type) { case OBJECT_ENTITY: { AdEntity *ent = node->_entity; - if (ent->_active && (ent->_registrable || !interactiveOnly)) + if (ent->_active && (ent->_registrable || !interactiveOnly)) { objects.add(ent); + } } break; @@ -2682,7 +2927,9 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i break; } } - if (!found) objects.add(regionObj[newIndex]); + if (!found) { + objects.add(regionObj[newIndex]); + } } //if (RegionObj.getSize() > 0) Objects.Append(RegionObj); } @@ -2705,7 +2952,9 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i break; } } - if (!found) objects.add(regionObj[newIndex]); + if (!found) { + objects.add(regionObj[newIndex]); + } } @@ -2722,7 +2971,9 @@ bool AdScene::getRegionObjects(AdRegion *region, BaseArray_objects.getSize(); i++) { obj = adGame->_objects[i]; if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - if (interactiveOnly && !obj->_registrable) continue; + if (interactiveOnly && !obj->_registrable) { + continue; + } objects.add(obj); } @@ -2732,7 +2983,9 @@ bool AdScene::getRegionObjects(AdRegion *region, BaseArray_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - if (interactiveOnly && !obj->_registrable) continue; + if (interactiveOnly && !obj->_registrable) { + continue; + } objects.add(obj); } diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index 617f247241..8a223150f2 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -47,7 +47,9 @@ AdSceneState::~AdSceneState() { delete[] _filename; _filename = NULL; - for (int i = 0; i < _nodeStates.getSize(); i++) delete _nodeStates[i]; + for (int i = 0; i < _nodeStates.getSize(); i++) { + delete _nodeStates[i]; + } _nodeStates.removeAll(); } @@ -65,14 +67,18 @@ bool AdSceneState::persist(BasePersistenceManager *persistMgr) { void AdSceneState::setFilename(const char *filename) { delete[] _filename; _filename = new char [strlen(filename) + 1]; - if (_filename) strcpy(_filename, filename); + if (_filename) { + strcpy(_filename, filename); + } } ////////////////////////////////////////////////////////////////////////// AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { for (int i = 0; i < _nodeStates.getSize(); i++) { - if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) return _nodeStates[i]; + if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) { + return _nodeStates[i]; + } } if (saving) { @@ -81,7 +87,9 @@ AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { _nodeStates.add(ret); return ret; - } else return NULL; + } else { + return NULL; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index a011db3f02..d429c1fedf 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -91,19 +91,29 @@ AdSentence::~AdSentence() { ////////////////////////////////////////////////////////////////////////// void AdSentence::setText(const char *text) { - if (_text) delete[] _text; + if (_text) { + delete[] _text; + } _text = new char[strlen(text) + 1]; - if (_text) strcpy(_text, text); + if (_text) { + strcpy(_text, text); + } } ////////////////////////////////////////////////////////////////////////// void AdSentence::setStances(const char *stances) { - if (_stances) delete[] _stances; + if (_stances) { + delete[] _stances; + } if (stances) { _stances = new char[strlen(stances) + 1]; - if (_stances) strcpy(_stances, stances); - } else _stances = NULL; + if (_stances) { + strcpy(_stances, stances); + } + } else { + _stances = NULL; + } } @@ -122,36 +132,55 @@ char *AdSentence::getNextStance() { ////////////////////////////////////////////////////////////////////////// char *AdSentence::getStance(int stance) { - if (_stances == NULL) return NULL; + if (_stances == NULL) { + return NULL; + } - if (_tempStance) delete[] _tempStance; + if (_tempStance) { + delete[] _tempStance; + } _tempStance = NULL; char *start; char *curr; int pos; - if (stance == 0) start = _stances; - else { + if (stance == 0) { + start = _stances; + } else { pos = 0; start = NULL; curr = _stances; while (pos < stance) { - if (*curr == '\0') break; - if (*curr == ',') pos++; + if (*curr == '\0') { + break; + } + if (*curr == ',') { + pos++; + } curr++; } - if (pos == stance) start = curr; + if (pos == stance) { + start = curr; + } } - if (start == NULL) return NULL; + if (start == NULL) { + return NULL; + } - while (*start == ' ' && *start != ',' && *start != '\0') start++; + while (*start == ' ' && *start != ',' && *start != '\0') { + start++; + } curr = start; - while (*curr != '\0' && *curr != ',') curr++; + while (*curr != '\0' && *curr != ',') { + curr++; + } - while (curr > start && *(curr - 1) == ' ') curr--; + while (curr > start && *(curr - 1) == ' ') { + curr--; + } _tempStance = new char [curr - start + 1]; if (_tempStance) { @@ -165,7 +194,9 @@ char *AdSentence::getStance(int stance) { ////////////////////////////////////////////////////////////////////////// bool AdSentence::display() { - if (!_font || !_text) return STATUS_FAILED; + if (!_font || !_text) { + return STATUS_FAILED; + } if (_sound && !_soundStarted) { _sound->play(); @@ -195,7 +226,9 @@ bool AdSentence::display() { ////////////////////////////////////////////////////////////////////////// void AdSentence::setSound(BaseSound *sound) { - if (!sound) return; + if (!sound) { + return; + } delete _sound; _sound = sound; _soundStarted = false; @@ -204,7 +237,9 @@ void AdSentence::setSound(BaseSound *sound) { ////////////////////////////////////////////////////////////////////////// bool AdSentence::finish() { - if (_sound) _sound->stop(); + if (_sound) { + _sound->stop(); + } return STATUS_OK; } @@ -242,7 +277,9 @@ bool AdSentence::setupTalkFile(const char *soundFilename) { _talkDef = NULL; _currentSprite = NULL; - if (!soundFilename) return STATUS_OK; + if (!soundFilename) { + return STATUS_OK; + } AnsiString path = PathUtil::getDirectoryName(soundFilename); @@ -250,8 +287,9 @@ bool AdSentence::setupTalkFile(const char *soundFilename) { AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); - if (!_gameRef->_fileManager->hasFile(talkDefFileName)) - return STATUS_OK; // no talk def file found + if (!_gameRef->_fileManager->hasFile(talkDefFileName)) { + return STATUS_OK; // no talk def file found + } _talkDef = new AdTalkDef(_gameRef); if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { @@ -267,7 +305,9 @@ bool AdSentence::setupTalkFile(const char *soundFilename) { ////////////////////////////////////////////////////////////////////////// bool AdSentence::update(TDirection dir) { - if (!_talkDef) return STATUS_OK; + if (!_talkDef) { + return STATUS_OK; + } uint32 currentTime; // if sound is available, synchronize with sound, otherwise use timer @@ -284,10 +324,14 @@ bool AdSentence::update(TDirection dir) { talkNodeFound = true; BaseSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); - if (newSprite != _currentSprite) newSprite->reset(); + if (newSprite != _currentSprite) { + newSprite->reset(); + } _currentSprite = newSprite; - if (!_talkDef->_nodes[i]->_playToEnd) break; + if (!_talkDef->_nodes[i]->_playToEnd) { + break; + } } } @@ -296,9 +340,13 @@ bool AdSentence::update(TDirection dir) { if (!talkNodeFound) { BaseSprite *newSprite = _talkDef->getDefaultSprite(dir); if (newSprite) { - if (newSprite != _currentSprite) newSprite->reset(); + if (newSprite != _currentSprite) { + newSprite->reset(); + } _currentSprite = newSprite; - } else _currentSprite = NULL; + } else { + _currentSprite = NULL; + } } return STATUS_OK; diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index fcbf9af4eb..42409988a5 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -41,8 +41,9 @@ IMPLEMENT_PERSISTENT(AdSpriteSet, false) AdSpriteSet::AdSpriteSet(BaseGame *inGame, BaseObject *owner): BaseObject(inGame) { _owner = owner; - for (int i = 0; i < NUM_DIRECTIONS; i++) + for (int i = 0; i < NUM_DIRECTIONS; i++) { _sprites[i] = NULL; + } } @@ -67,7 +68,9 @@ bool AdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType bool ret; - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); + } delete[] buffer; @@ -90,7 +93,7 @@ TOKEN_DEF(TEMPLATE) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType CacheType) { +bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType cacheType) { TOKEN_TABLE_START(commands) TOKEN_TABLE(SPRITESET) TOKEN_TABLE(NAME) @@ -122,7 +125,9 @@ bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteC while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -133,64 +138,88 @@ bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteC delete _sprites[DI_LEFT]; _sprites[DI_LEFT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_LEFT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_LEFT] = spr; + } break; case TOKEN_RIGHT: delete _sprites[DI_RIGHT]; _sprites[DI_RIGHT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_RIGHT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_RIGHT] = spr; + } break; case TOKEN_UP: delete _sprites[DI_UP]; _sprites[DI_UP] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UP] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UP] = spr; + } break; case TOKEN_DOWN: delete _sprites[DI_DOWN]; _sprites[DI_DOWN] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWN] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWN] = spr; + } break; case TOKEN_UP_LEFT: delete _sprites[DI_UPLEFT]; _sprites[DI_UPLEFT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UPLEFT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UPLEFT] = spr; + } break; case TOKEN_UP_RIGHT: delete _sprites[DI_UPRIGHT]; _sprites[DI_UPRIGHT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UPRIGHT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UPRIGHT] = spr; + } break; case TOKEN_DOWN_LEFT: delete _sprites[DI_DOWNLEFT]; _sprites[DI_DOWNLEFT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWNLEFT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWNLEFT] = spr; + } break; case TOKEN_DOWN_RIGHT: delete _sprites[DI_DOWNRIGHT]; _sprites[DI_DOWNRIGHT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWNRIGHT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWNRIGHT] = spr; + } break; case TOKEN_EDITOR_PROPERTY: @@ -205,7 +234,9 @@ bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteC if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading SPRITESET definition"); - if (spr) delete spr; + if (spr) { + delete spr; + } return STATUS_FAILED; } @@ -230,8 +261,12 @@ bool AdSpriteSet::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// BaseSprite *AdSpriteSet::getSprite(TDirection direction) { int dir = (int)direction; - if (dir < 0) dir = 0; - if (dir >= NUM_DIRECTIONS) dir = NUM_DIRECTIONS - 1; + if (dir < 0) { + dir = 0; + } + if (dir >= NUM_DIRECTIONS) { + dir = NUM_DIRECTIONS - 1; + } BaseSprite *ret = NULL; @@ -247,8 +282,11 @@ BaseSprite *AdSpriteSet::getSprite(TDirection direction) { for (int i = dir; i < NUM_DIRECTIONS; i++) { if (_sprites[i] != NULL) { - if (ret == NULL || numSteps > i - dir) return _sprites[i]; - else return ret; + if (ret == NULL || numSteps > i - dir) { + return _sprites[i]; + } else { + return ret; + } } } @@ -260,7 +298,9 @@ BaseSprite *AdSpriteSet::getSprite(TDirection direction) { ////////////////////////////////////////////////////////////////////////// bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "SPRITESET {\n"); - if (getName()) buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + if (getName()) { + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + } for (int i = 0; i < NUM_DIRECTIONS; i++) { if (_sprites[i]) { switch (i) { @@ -301,10 +341,14 @@ bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// bool AdSpriteSet::containsSprite(BaseSprite *sprite) { - if (!sprite) return false; + if (!sprite) { + return false; + } for (int i = 0; i < NUM_DIRECTIONS; i++) { - if (_sprites[i] == sprite) return true; + if (_sprites[i] == sprite) { + return true; + } } return false; } diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 2b0c6c6c1b..fc057ba183 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -52,7 +52,9 @@ AdTalkDef::AdTalkDef(BaseGame *inGame): BaseObject(inGame) { ////////////////////////////////////////////////////////////////////////// AdTalkDef::~AdTalkDef() { - for (int i = 0; i < _nodes.getSize(); i++) delete _nodes[i]; + for (int i = 0; i < _nodes.getSize(); i++) { + delete _nodes[i]; + } _nodes.removeAll(); delete[] _defaultSpriteFilename; @@ -79,7 +81,9 @@ bool AdTalkDef::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); + } delete[] buffer; @@ -123,15 +127,18 @@ bool AdTalkDef::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_ACTION: { - AdTalkNode *Node = new AdTalkNode(_gameRef); - if (Node && DID_SUCCEED(Node->loadBuffer(params, false))) _nodes.add(Node); - else { - delete Node; - Node = NULL; + AdTalkNode *node = new AdTalkNode(_gameRef); + if (node && DID_SUCCEED(node->loadBuffer(params, false))) { + _nodes.add(node); + } else { + delete node; + node = NULL; cmd = PARSERR_GENERIC; } } @@ -179,12 +186,16 @@ bool AdTalkDef::loadBuffer(byte *buffer, bool complete) { if (_defaultSpriteFilename) { _defaultSprite = new BaseSprite(_gameRef); - if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) return STATUS_FAILED; + if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { + return STATUS_FAILED; + } } if (_defaultSpriteSetFilename) { _defaultSpriteSet = new AdSpriteSet(_gameRef); - if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) return STATUS_FAILED; + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { + return STATUS_FAILED; + } } @@ -211,10 +222,15 @@ bool AdTalkDef::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdTalkDef::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "TALK {\n"); - if (_defaultSpriteFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); + if (_defaultSpriteFilename) { + buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); + } - if (_defaultSpriteSetFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); - else if (_defaultSpriteSet) _defaultSpriteSet->saveAsText(buffer, indent + 2); + if (_defaultSpriteSetFilename) { + buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); + } else if (_defaultSpriteSet) { + _defaultSpriteSet->saveAsText(buffer, indent + 2); + } for (int i = 0; i < _nodes.getSize(); i++) { _nodes[i]->saveAsText(buffer, indent + 2); @@ -236,24 +252,34 @@ bool AdTalkDef::loadDefaultSprite() { delete _defaultSprite; _defaultSprite = NULL; return STATUS_FAILED; - } else return STATUS_OK; + } else { + return STATUS_OK; + } } else if (_defaultSpriteSetFilename && !_defaultSpriteSet) { _defaultSpriteSet = new AdSpriteSet(_gameRef); if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { delete _defaultSpriteSet; _defaultSpriteSet = NULL; return STATUS_FAILED; - } else return STATUS_OK; - } else return STATUS_OK; + } else { + return STATUS_OK; + } + } else { + return STATUS_OK; + } } ////////////////////////////////////////////////////////////////////////// BaseSprite *AdTalkDef::getDefaultSprite(TDirection dir) { loadDefaultSprite(); - if (_defaultSprite) return _defaultSprite; - else if (_defaultSpriteSet) return _defaultSpriteSet->getSprite(dir); - else return NULL; + if (_defaultSprite) { + return _defaultSprite; + } else if (_defaultSpriteSet) { + return _defaultSpriteSet->getSprite(dir); + } else { + return NULL; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index d47cbb446e..90435d7977 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -52,12 +52,14 @@ AdTalkHolder::~AdTalkHolder() { delete _sprite; _sprite = NULL; - for (int i = 0; i < _talkSprites.getSize(); i++) + for (int i = 0; i < _talkSprites.getSize(); i++) { delete _talkSprites[i]; + } _talkSprites.removeAll(); - for (int i = 0; i < _talkSpritesEx.getSize(); i++) + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { delete _talkSpritesEx[i]; + } _talkSpritesEx.removeAll(); } @@ -77,7 +79,9 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { _gameRef->LOG(res, "AdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); delete _animSprite; _animSprite = NULL; - } else return _animSprite; + } else { + return _animSprite; + } } } @@ -103,8 +107,9 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { // not a valid stance? get a random one if (ret == NULL) { - if (_talkSprites.getSize() < 1) ret = _sprite; - else { + if (_talkSprites.getSize() < 1) { + ret = _sprite; + } else { // TODO: remember last int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); ret = _talkSprites[rnd]; @@ -128,14 +133,18 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS ScValue *val = stack->pop(); bool setCurrent = false; - if (_currentSprite && _currentSprite == _sprite) setCurrent = true; + if (_currentSprite && _currentSprite == _sprite) { + setCurrent = true; + } delete _sprite; _sprite = NULL; if (val->isNULL()) { _sprite = NULL; - if (setCurrent) _currentSprite = NULL; + if (setCurrent) { + _currentSprite = NULL; + } stack->pushBool(true); } else { const char *filename = val->getString(); @@ -145,7 +154,9 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS stack->pushBool(false); } else { _sprite = spr; - if (setCurrent) _currentSprite = _sprite; + if (setCurrent) { + _currentSprite = _sprite; + } stack->pushBool(true); } } @@ -158,8 +169,11 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS else if (strcmp(name, "GetSprite") == 0) { stack->correctParams(0); - if (!_sprite || !_sprite->getFilename()) stack->pushNULL(); - else stack->pushString(_sprite->getFilename()); + if (!_sprite || !_sprite->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_sprite->getFilename()); + } return STATUS_OK; } @@ -169,8 +183,11 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS else if (strcmp(name, "GetSpriteObject") == 0) { stack->correctParams(0); - if (!_sprite) stack->pushNULL(); - else stack->pushNative(_sprite, true); + if (!_sprite) { + stack->pushNULL(); + } else { + stack->pushNative(_sprite, true); + } return STATUS_OK; } @@ -181,15 +198,18 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS stack->correctParams(2); const char *filename = stack->pop()->getString(); - bool Ex = stack->pop()->getBool(); + bool ex = stack->pop()->getBool(); BaseSprite *spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile(filename))) { stack->pushBool(false); script->runtimeError("AddTalkSprite method failed for file '%s'", filename); } else { - if (Ex) _talkSpritesEx.add(spr); - else _talkSprites.add(spr); + if (ex) { + _talkSpritesEx.add(spr); + } else { + _talkSprites.add(spr); + } stack->pushBool(true); } return STATUS_OK; @@ -210,10 +230,12 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS if (ex) { for (int i = 0; i < _talkSpritesEx.getSize(); i++) { if (scumm_stricmp(_talkSpritesEx[i]->getFilename(), filename) == 0) { - if (_currentSprite == _talkSpritesEx[i]) + if (_currentSprite == _talkSpritesEx[i]) { setCurrent = true; - if (_tempSprite2 == _talkSpritesEx[i]) + } + if (_tempSprite2 == _talkSpritesEx[i]) { setTemp2 = true; + } delete _talkSpritesEx[i]; _talkSpritesEx.removeAt(i); break; @@ -222,10 +244,12 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } else { for (int i = 0; i < _talkSprites.getSize(); i++) { if (scumm_stricmp(_talkSprites[i]->getFilename(), filename) == 0) { - if (_currentSprite == _talkSprites[i]) + if (_currentSprite == _talkSprites[i]) { setCurrent = true; - if (_tempSprite2 == _talkSprites[i]) + } + if (_tempSprite2 == _talkSprites[i]) { setTemp2 = true; + } delete _talkSprites[i]; _talkSprites.removeAt(i); break; @@ -235,10 +259,12 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } stack->pushBool(true); - if (setCurrent) + if (setCurrent) { _currentSprite = _sprite; - if (setTemp2) + } + if (setTemp2) { _tempSprite2 = _sprite; + } return STATUS_OK; } @@ -263,38 +289,47 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS // delete current if (ex) { for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (_talkSpritesEx[i] == _currentSprite) + if (_talkSpritesEx[i] == _currentSprite) { setCurrent = true; - if (_talkSpritesEx[i] == _tempSprite2) + } + if (_talkSpritesEx[i] == _tempSprite2) { setTemp2 = true; + } delete _talkSpritesEx[i]; } _talkSpritesEx.removeAll(); } else { for (int i = 0; i < _talkSprites.getSize(); i++) { - if (_talkSprites[i] == _currentSprite) setCurrent = true; - if (_talkSprites[i] == _tempSprite2) setTemp2 = true; + if (_talkSprites[i] == _currentSprite) { + setCurrent = true; + } + if (_talkSprites[i] == _tempSprite2) { + setTemp2 = true; + } delete _talkSprites[i]; } _talkSprites.removeAll(); } // set new - if (ex) + if (ex) { _talkSpritesEx.add(spr); - else + } else { _talkSprites.add(spr); + } stack->pushBool(true); - if (setCurrent) + if (setCurrent) { _currentSprite = spr; - if (setTemp2) + } + if (setTemp2) { _tempSprite2 = spr; + } } return STATUS_OK; + } else { + return AdObject::scCallMethod(script, stack, thisStack, name); } - - else return AdObject::scCallMethod(script, stack, thisStack, name); } @@ -308,9 +343,9 @@ ScValue *AdTalkHolder::scGetProperty(const char *name) { if (strcmp(name, "Type") == 0) { _scValue->setString("talk-holder"); return _scValue; + } else { + return AdObject::scGetProperty(name); } - - else return AdObject::scGetProperty(name); } @@ -338,13 +373,15 @@ const char *AdTalkHolder::scToString() { ////////////////////////////////////////////////////////////////////////// bool AdTalkHolder::saveAsText(BaseDynamicBuffer *buffer, int indent) { for (int i = 0; i < _talkSprites.getSize(); i++) { - if (_talkSprites[i]->getFilename()) + if (_talkSprites[i]->getFilename()) { buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->getFilename()); + } } for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (_talkSpritesEx[i]->getFilename()) + if (_talkSpritesEx[i]->getFilename()) { buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->getFilename()); + } } return STATUS_OK; diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index 306825c439..ef30290b8c 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -142,7 +142,9 @@ bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_COMMENT: - if (_gameRef->_editorMode) BaseUtils::setString(&_comment, (char *)params); + if (_gameRef->_editorMode) { + BaseUtils::setString(&_comment, (char *)params); + } break; case TOKEN_EDITOR_PROPERTY: @@ -160,23 +162,26 @@ bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { return STATUS_FAILED; } - if (_endTime == 0) + if (_endTime == 0) { _playToEnd = true; - else + } else { _playToEnd = false; + } if (_preCache && _spriteFilename) { delete _sprite; _sprite = new BaseSprite(_gameRef); - if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) + if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { return STATUS_FAILED; + } } if (_preCache && _spriteSetFilename) { delete _spriteSet; _spriteSet = new AdSpriteSet(_gameRef); - if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) + if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { return STATUS_FAILED; + } } return STATUS_OK; @@ -202,13 +207,24 @@ bool AdTalkNode::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdTalkNode::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "ACTION {\n"); - if (_comment) buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); + if (_comment) { + buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); + } buffer->putTextIndent(indent + 2, "START_TIME=%d\n", _startTime); - if (!_playToEnd) buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); - if (_spriteFilename) buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); - if (_spriteSetFilename) buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); - else if (_spriteSet) _spriteSet->saveAsText(buffer, indent + 2); - if (_preCache) buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); + if (!_playToEnd) { + buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); + } + if (_spriteFilename) { + buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); + } + if (_spriteSetFilename) { + buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); + } else if (_spriteSet) { + _spriteSet->saveAsText(buffer, indent + 2); + } + if (_preCache) { + buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); + } BaseClass::saveAsText(buffer, indent + 2); @@ -226,19 +242,21 @@ bool AdTalkNode::loadSprite() { delete _sprite; _sprite = NULL; return STATUS_FAILED; - } else return STATUS_OK; - } - - else if (_spriteSetFilename && !_spriteSet) { + } else { + return STATUS_OK; + } + } else if (_spriteSetFilename && !_spriteSet) { _spriteSet = new AdSpriteSet(_gameRef); if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { delete _spriteSet; _spriteSet = NULL; return STATUS_FAILED; - } else return STATUS_OK; + } else { + return STATUS_OK; + } + } else { + return STATUS_OK; } - - else return STATUS_OK; } @@ -246,20 +264,32 @@ bool AdTalkNode::loadSprite() { bool AdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { if (time >= _startTime) { if (_playToEnd) { - if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) return true; - else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) return true; - else return false; - } else return _endTime >= time; - } else return false; + if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) { + return true; + } else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) { + return true; + } else { + return false; + } + } else { + return _endTime >= time; + } + } else { + return false; + } } ////////////////////////////////////////////////////////////////////////// BaseSprite *AdTalkNode::getSprite(TDirection dir) { loadSprite(); - if (_sprite) return _sprite; - else if (_spriteSet) return _spriteSet->getSprite(dir); - else return NULL; + if (_sprite) { + return _sprite; + } else if (_spriteSet) { + return _spriteSet->getSprite(dir); + } else { + return NULL; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 7e5d8d29c6..bb1e9275f5 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -56,8 +56,9 @@ AdWaypointGroup::~AdWaypointGroup() { ////////////////////////////////////////////////////////////////////////// void AdWaypointGroup::cleanup() { - for (int i = 0; i < _points.getSize(); i++) + for (int i = 0; i < _points.getSize(); i++) { delete _points[i]; + } _points.removeAll(); _editorSelectedPoint = -1; } @@ -75,7 +76,9 @@ bool AdWaypointGroup::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); + } delete[] buffer; @@ -122,7 +125,9 @@ bool AdWaypointGroup::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -169,8 +174,9 @@ bool AdWaypointGroup::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED_POINT=%d\n", _editorSelectedPoint); - if (_scProp) + if (_scProp) { _scProp->saveAsText(buffer, indent + 2); + } BaseClass::saveAsText(buffer, indent + 2); for (int i = 0; i < _points.getSize(); i++) { @@ -217,9 +223,9 @@ ScValue *AdWaypointGroup::scGetProperty(const char *name) { else if (strcmp(name, "Active") == 0) { _scValue->setBool(_active); return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -233,13 +239,17 @@ bool AdWaypointGroup::scSetProperty(const char *name, ScValue *value) { return STATUS_OK; } - else return BaseObject::scSetProperty(name, value); + else { + return BaseObject::scSetProperty(name, value); + } } ////////////////////////////////////////////////////////////////////////// bool AdWaypointGroup::mimic(AdWaypointGroup *wpt, float scale, int argX, int argY) { - if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) return STATUS_OK; + if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) { + return STATUS_OK; + } cleanup(); -- cgit v1.2.3 From 5e325a5b285e03f9099fa6b81c2f6a85fabe4b06 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 18:47:31 +0200 Subject: WINTERMUTE: Privatize most fields in AdActor --- engines/wintermute/ad/ad_actor.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index 870b3e8418..5da014bcda 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -53,9 +53,17 @@ public: BasePoint *_targetPoint; virtual bool update(); virtual bool display(); + virtual void turnTo(TDirection dir); + AdActor(BaseGame *inGame/*=NULL*/); + virtual ~AdActor(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + + +private: TDirection _targetDir; TDirection _afterWalkDir; - virtual void turnTo(TDirection dir); + AdPath *_path; AdSpriteSet *_walkSprite; AdSpriteSet *_standSprite; @@ -64,11 +72,6 @@ public: BaseArray _talkSprites; BaseArray _talkSpritesEx; TDirection _dir; - AdActor(BaseGame *inGame/*=NULL*/); - virtual ~AdActor(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - // new anim system Common::String _talkAnimName; Common::String _idleAnimName; @@ -85,7 +88,6 @@ public: virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); -private: bool setDefaultAnimNames(); BaseSprite *getTalkStanceOld(const char *stance); bool mergeAnims(const char *animsFilename); -- cgit v1.2.3 From 4eda234611bd77f053defe9e61d592b308270eaa Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 19:41:18 +0200 Subject: WINTERMUTE: Replace BaseArray with a templated subclass of Common::Array. This needs additional cleanup, but compiles and runs at this point. --- engines/wintermute/ad/ad_actor.cpp | 10 +++---- engines/wintermute/ad/ad_actor.h | 6 ++-- engines/wintermute/ad/ad_game.cpp | 46 ++++++++++++++--------------- engines/wintermute/ad/ad_game.h | 18 +++++------ engines/wintermute/ad/ad_inventory.cpp | 10 +++---- engines/wintermute/ad/ad_inventory.h | 2 +- engines/wintermute/ad/ad_layer.cpp | 6 ++-- engines/wintermute/ad/ad_layer.h | 2 +- engines/wintermute/ad/ad_object.cpp | 12 ++++---- engines/wintermute/ad/ad_object.h | 4 +-- engines/wintermute/ad/ad_path.cpp | 2 +- engines/wintermute/ad/ad_path.h | 2 +- engines/wintermute/ad/ad_region.cpp | 2 +- engines/wintermute/ad/ad_response_box.cpp | 14 ++++----- engines/wintermute/ad/ad_response_box.h | 6 ++-- engines/wintermute/ad/ad_scene.cpp | 36 +++++++++++----------- engines/wintermute/ad/ad_scene.h | 16 +++++----- engines/wintermute/ad/ad_scene_state.cpp | 2 +- engines/wintermute/ad/ad_scene_state.h | 2 +- engines/wintermute/ad/ad_talk_def.cpp | 2 +- engines/wintermute/ad/ad_talk_def.h | 2 +- engines/wintermute/ad/ad_talk_holder.cpp | 12 ++++---- engines/wintermute/ad/ad_talk_holder.h | 4 +-- engines/wintermute/ad/ad_waypoint_group.cpp | 2 +- engines/wintermute/ad/ad_waypoint_group.h | 2 +- 25 files changed, 111 insertions(+), 111 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index d1e03eac3a..fb46cef9cf 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -101,18 +101,18 @@ AdActor::~AdActor() { for (int i = 0; i < _talkSprites.getSize(); i++) { delete _talkSprites[i]; } - _talkSprites.removeAll(); + _talkSprites.clear(); for (int i = 0; i < _talkSpritesEx.getSize(); i++) { delete _talkSpritesEx[i]; } - _talkSpritesEx.removeAll(); + _talkSpritesEx.clear(); for (int i = 0; i < _anims.getSize(); i++) { delete _anims[i]; _anims[i] = NULL; } - _anims.removeAll(); + _anims.clear(); } @@ -1051,7 +1051,7 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, delete _anims[i]; _anims[i] = NULL; - _anims.removeAt(i); + _anims.remove_at(i); i--; Found = true; } @@ -1254,7 +1254,7 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { // not - get a random talk if (!ret) { - BaseArray talkAnims; + BaseArray talkAnims; for (int i = 0; i < _anims.getSize(); i++) { if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) { talkAnims.add(_anims[i]); diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index 5da014bcda..0c6334ac9d 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -69,8 +69,8 @@ private: AdSpriteSet *_standSprite; AdSpriteSet *_turnLeftSprite; AdSpriteSet *_turnRightSprite; - BaseArray _talkSprites; - BaseArray _talkSpritesEx; + BaseArray _talkSprites; + BaseArray _talkSpritesEx; TDirection _dir; // new anim system Common::String _talkAnimName; @@ -78,7 +78,7 @@ private: Common::String _walkAnimName; Common::String _turnLeftAnimName; Common::String _turnRightAnimName; - BaseArray _anims; + BaseArray _anims; virtual bool playAnim(const char *filename); AdSpriteSet *getAnimByName(const Common::String &animName); diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index a6452e8837..4533496199 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -124,18 +124,18 @@ bool AdGame::cleanup() { unregisterObject(_objects[i]); _objects[i] = NULL; } - _objects.removeAll(); + _objects.clear(); for (i = 0; i < _dlgPendingBranches.getSize(); i++) { delete[] _dlgPendingBranches[i]; } - _dlgPendingBranches.removeAll(); + _dlgPendingBranches.clear(); for (i = 0; i < _speechDirs.getSize(); i++) { delete[] _speechDirs[i]; } - _speechDirs.removeAll(); + _speechDirs.clear(); unregisterObject(_scene); @@ -145,7 +145,7 @@ bool AdGame::cleanup() { for (i = 0; i < _items.getSize(); i++) { _gameRef->unregisterObject(_items[i]); } - _items.removeAll(); + _items.clear(); // clear remaining inventories @@ -155,7 +155,7 @@ bool AdGame::cleanup() { for (i = 0; i < _inventories.getSize(); i++) { delete _inventories[i]; } - _inventories.removeAll(); + _inventories.clear(); if (_responseBox) { @@ -186,17 +186,17 @@ bool AdGame::cleanup() { for (i = 0; i < _sceneStates.getSize(); i++) { delete _sceneStates[i]; } - _sceneStates.removeAll(); + _sceneStates.clear(); for (i = 0; i < _responsesBranch.getSize(); i++) { delete _responsesBranch[i]; } - _responsesBranch.removeAll(); + _responsesBranch.clear(); for (i = 0; i < _responsesGame.getSize(); i++) { delete _responsesGame[i]; } - _responsesGame.removeAll(); + _responsesGame.clear(); return BaseGame::cleanup(); } @@ -223,7 +223,7 @@ bool AdGame::initLoop() { res = _scene->initLoop(); } - _sentences.removeAll(); + _sentences.clear(); return res; } @@ -248,7 +248,7 @@ bool AdGame::removeObject(AdObject *object) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i] == object) { - _objects.removeAt(i); + _objects.remove_at(i); break; } } @@ -1744,7 +1744,7 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const delete[] _dlgPendingBranches[i]; _dlgPendingBranches[i] = NULL; } - _dlgPendingBranches.removeAt(startIndex, _dlgPendingBranches.getSize() - startIndex); + _dlgPendingBranches.remove_at(startIndex, _dlgPendingBranches.getSize() - startIndex); } // dialogue is over, forget selected responses @@ -1752,7 +1752,7 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const for (int i = 0; i < _responsesBranch.getSize(); i++) { delete _responsesBranch[i]; } - _responsesBranch.removeAll(); + _responsesBranch.clear(); } if (deleteName) { @@ -1768,7 +1768,7 @@ bool AdGame::clearBranchResponses(char *name) { for (int i = 0; i < _responsesBranch.getSize(); i++) { if (scumm_stricmp(name, _responsesBranch[i]->_context) == 0) { delete _responsesBranch[i]; - _responsesBranch.removeAt(i); + _responsesBranch.remove_at(i); i--; } } @@ -1839,7 +1839,7 @@ bool AdGame::resetResponse(int id) { if (_responsesGame[i]->_id == id) { if ((context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(context, _responsesGame[i]->_context) == 0) { delete _responsesGame[i]; - _responsesGame.removeAt(i); + _responsesGame.remove_at(i); break; } } @@ -1849,7 +1849,7 @@ bool AdGame::resetResponse(int id) { if (_responsesBranch[i]->_id == id) { if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { delete _responsesBranch[i]; - _responsesBranch.removeAt(i); + _responsesBranch.remove_at(i); break; } } @@ -1962,7 +1962,7 @@ bool AdGame::unregisterInventory(AdInventory *inv) { for (int i = 0; i < _inventories.getSize(); i++) { if (_inventories[i] == inv) { unregisterObject(_inventories[i]); - _inventories.removeAt(i); + _inventories.remove_at(i); return STATUS_OK; } } @@ -2007,31 +2007,31 @@ bool AdGame::resetContent() { for (int i = 0; i < _dlgPendingBranches.getSize(); i++) { delete[] _dlgPendingBranches[i]; } - _dlgPendingBranches.removeAll(); + _dlgPendingBranches.clear(); // clear inventories for (int i = 0; i < _inventories.getSize(); i++) { - _inventories[i]->_takenItems.removeAll(); + _inventories[i]->_takenItems.clear(); } // clear scene states for (int i = 0; i < _sceneStates.getSize(); i++) { delete _sceneStates[i]; } - _sceneStates.removeAll(); + _sceneStates.clear(); // clear once responses for (int i = 0; i < _responsesBranch.getSize(); i++) { delete _responsesBranch[i]; } - _responsesBranch.removeAll(); + _responsesBranch.clear(); // clear once game responses for (int i = 0; i < _responsesGame.getSize(); i++) { delete _responsesGame[i]; } - _responsesGame.removeAll(); + _responsesGame.clear(); // reload inventory items if (_itemsFile) { @@ -2064,7 +2064,7 @@ bool AdGame::deleteItem(AdItem *item) { for (int i = 0; i < _items.getSize(); i++) { if (_items[i] == item) { unregisterObject(_items[i]); - _items.removeAt(i); + _items.remove_at(i); break; } } @@ -2113,7 +2113,7 @@ bool AdGame::removeSpeechDir(const char *dir) { for (int i = 0; i < _speechDirs.getSize(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { delete[] _speechDirs[i]; - _speechDirs.removeAt(i); + _speechDirs.remove_at(i); found = true; break; } diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index 49c48de0bb..e0179d3e94 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -121,7 +121,7 @@ public: AdGame(); virtual ~AdGame(); - BaseArray _objects; + BaseArray _objects; virtual bool loadFile(const char *filename); virtual bool loadBuffer(byte *buffer, bool complete = true); @@ -138,7 +138,7 @@ private: virtual bool ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name); AdObject *_invObject; - BaseArray _inventories; + BaseArray _inventories; char *_scheduledScene; bool _scheduledFadeIn; char *_prevSceneName; @@ -147,16 +147,16 @@ private: char *_startupScene; bool _initialScene; bool _smartItemCursor; - BaseArray _speechDirs; - BaseArray _items; + BaseArray _speechDirs; + BaseArray _items; - BaseArray _sentences; + BaseArray _sentences; - BaseArray _sceneStates; - BaseArray _dlgPendingBranches; + BaseArray _sceneStates; + BaseArray _dlgPendingBranches; - BaseArray _responsesBranch; - BaseArray _responsesGame; + BaseArray _responsesBranch; + BaseArray _responsesGame; AdResponseBox *_responseBox; AdInventoryBox *_inventoryBox; diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index aa6e0b6f0b..6cc5ed879e 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -44,7 +44,7 @@ AdInventory::AdInventory(BaseGame *inGame): BaseObject(inGame) { ////////////////////////////////////////////////////////////////////////// AdInventory::~AdInventory() { - _takenItems.removeAll(); // ref only + _takenItems.clear(); // ref only } @@ -62,7 +62,7 @@ bool AdInventory::insertItem(const char *name, const char *insertAfter) { int insertIndex = -1; for (int i = 0; i < _takenItems.getSize(); i++) { if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { - _takenItems.removeAt(i); + _takenItems.remove_at(i); i--; continue; } @@ -75,7 +75,7 @@ bool AdInventory::insertItem(const char *name, const char *insertAfter) { if (insertIndex == -1) { _takenItems.add(item); } else { - _takenItems.insertAt(insertIndex, item); + _takenItems.insert_at(insertIndex, item); } return STATUS_OK; @@ -93,7 +93,7 @@ bool AdInventory::removeItem(const char *name) { if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { ((AdGame *)_gameRef)->_selectedItem = NULL; } - _takenItems.removeAt(i); + _takenItems.remove_at(i); return STATUS_OK; } } @@ -114,7 +114,7 @@ bool AdInventory::removeItem(AdItem *item) { if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { ((AdGame *)_gameRef)->_selectedItem = NULL; } - _takenItems.removeAt(i); + _takenItems.remove_at(i); return STATUS_OK; } } diff --git a/engines/wintermute/ad/ad_inventory.h b/engines/wintermute/ad/ad_inventory.h index 6f7537633d..9eff30454c 100644 --- a/engines/wintermute/ad/ad_inventory.h +++ b/engines/wintermute/ad/ad_inventory.h @@ -43,7 +43,7 @@ public: bool insertItem(const char *name, const char *insertAfter = NULL); AdInventory(BaseGame *inGame); virtual ~AdInventory(); - BaseArray _takenItems; + BaseArray _takenItems; int _scrollOffset; }; diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 6c9e6381b2..a60cd76209 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -56,7 +56,7 @@ AdLayer::~AdLayer() { for (int i = 0; i < _nodes.getSize(); i++) { delete _nodes[i]; } - _nodes.removeAll(); + _nodes.clear(); } @@ -324,7 +324,7 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, index = 0; } if (index <= _nodes.getSize() - 1) { - _nodes.insertAt(index, node); + _nodes.insert_at(index, node); } else { _nodes.add(node); } @@ -363,7 +363,7 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (_nodes[i] == toDelete) { delete _nodes[i]; _nodes[i] = NULL; - _nodes.removeAt(i); + _nodes.remove_at(i); break; } } diff --git a/engines/wintermute/ad/ad_layer.h b/engines/wintermute/ad/ad_layer.h index b76cbf1d99..6d1686e1a6 100644 --- a/engines/wintermute/ad/ad_layer.h +++ b/engines/wintermute/ad/ad_layer.h @@ -41,7 +41,7 @@ public: bool _main; AdLayer(BaseGame *inGame); virtual ~AdLayer(); - BaseArray _nodes; + BaseArray _nodes; bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index c6f0306cbb..cf60bedf2c 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -146,12 +146,12 @@ AdObject::~AdObject() { for (int i = 0; i < _attachmentsPre.getSize(); i++) { _gameRef->unregisterObject(_attachmentsPre[i]); } - _attachmentsPre.removeAll(); + _attachmentsPre.clear(); for (int i = 0; i < _attachmentsPost.getSize(); i++) { _gameRef->unregisterObject(_attachmentsPost[i]); } - _attachmentsPost.removeAll(); + _attachmentsPost.clear(); } @@ -567,7 +567,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_attachmentsPre[i] == obj) { found = true; _gameRef->unregisterObject(_attachmentsPre[i]); - _attachmentsPre.removeAt(i); + _attachmentsPre.remove_at(i); i--; } } @@ -575,7 +575,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_attachmentsPost[i] == obj) { found = true; _gameRef->unregisterObject(_attachmentsPost[i]); - _attachmentsPost.removeAt(i); + _attachmentsPost.remove_at(i); i--; } } @@ -585,7 +585,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { found = true; _gameRef->unregisterObject(_attachmentsPre[i]); - _attachmentsPre.removeAt(i); + _attachmentsPre.remove_at(i); i--; } } @@ -593,7 +593,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { found = true; _gameRef->unregisterObject(_attachmentsPost[i]); - _attachmentsPost.removeAt(i); + _attachmentsPost.remove_at(i); i--; } } diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h index 58cb15fde3..8e4cb80742 100644 --- a/engines/wintermute/ad/ad_object.h +++ b/engines/wintermute/ad/ad_object.h @@ -105,8 +105,8 @@ public: virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); - BaseArray _attachmentsPre; - BaseArray _attachmentsPost; + BaseArray _attachmentsPre; + BaseArray _attachmentsPost; bool updateSpriteAttachments(); bool displaySpriteAttachments(bool preDisplay); diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index 89be10f0fb..7734b4d9ba 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -52,7 +52,7 @@ void AdPath::reset() { delete _points[i]; } - _points.removeAll(); + _points.clear(); _currIndex = -1; _ready = false; } diff --git a/engines/wintermute/ad/ad_path.h b/engines/wintermute/ad/ad_path.h index 958f52af03..8622e6757c 100644 --- a/engines/wintermute/ad/ad_path.h +++ b/engines/wintermute/ad/ad_path.h @@ -46,7 +46,7 @@ public: void reset(); AdPath(BaseGame *inGame); virtual ~AdPath(); - BaseArray _points; + BaseArray _points; int _currIndex; bool _ready; }; diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 6b104d51ad..18b5731830 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -131,7 +131,7 @@ bool AdRegion::loadBuffer(byte *buffer, bool complete) { for (int i = 0; i < _points.getSize(); i++) { delete _points[i]; } - _points.removeAll(); + _points.clear(); int ar = 255, ag = 255, ab = 255, alpha = 255; diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index fe37002abb..c566120405 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -100,7 +100,7 @@ void AdResponseBox::clearResponses() { for (int i = 0; i < _responses.getSize(); i++) { delete _responses[i]; } - _responses.removeAll(); + _responses.clear(); } @@ -109,7 +109,7 @@ void AdResponseBox::clearButtons() { for (int i = 0; i < _respButtons.getSize(); i++) { delete _respButtons[i]; } - _respButtons.removeAll(); + _respButtons.clear(); } @@ -597,7 +597,7 @@ bool AdResponseBox::weedResponses() { case RESPONSE_ONCE: if (adGame->branchResponseUsed(_responses[i]->_iD)) { delete _responses[i]; - _responses.removeAt(i); + _responses.remove_at(i); i--; } break; @@ -605,7 +605,7 @@ bool AdResponseBox::weedResponses() { case RESPONSE_ONCE_GAME: if (adGame->gameResponseUsed(_responses[i]->_iD)) { delete _responses[i]; - _responses.removeAt(i); + _responses.remove_at(i); i--; } break; @@ -649,7 +649,7 @@ bool AdResponseBox::handleResponse(AdResponse *response) { ////////////////////////////////////////////////////////////////////////// BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) { - BaseArray objects; + BaseArray objects; getObjects(objects, true); if (objects.getSize() == 0) { @@ -673,7 +673,7 @@ BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) { ////////////////////////////////////////////////////////////////////////// BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { - BaseArray objects; + BaseArray objects; getObjects(objects, true); if (objects.getSize() == 0) { @@ -696,7 +696,7 @@ BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { } ////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::getObjects(BaseArray &objects, bool interactiveOnly) { +bool AdResponseBox::getObjects(BaseArray &objects, bool interactiveOnly) { for (int i = 0; i < _respButtons.getSize(); i++) { objects.add(_respButtons[i]); } diff --git a/engines/wintermute/ad/ad_response_box.h b/engines/wintermute/ad/ad_response_box.h index 5dc22cbebe..c1f60ba6ae 100644 --- a/engines/wintermute/ad/ad_response_box.h +++ b/engines/wintermute/ad/ad_response_box.h @@ -42,7 +42,7 @@ class AdResponseBox : public BaseObject { public: BaseObject *getNextAccessObject(BaseObject *CurrObject); BaseObject *getPrevAccessObject(BaseObject *CurrObject); - bool getObjects(BaseArray &objects, bool interactiveOnly); + bool getObjects(BaseArray &objects, bool interactiveOnly); bool handleResponse(AdResponse *response); void setLastResponseText(const char *text, const char *textOrig); @@ -69,8 +69,8 @@ public: void clearResponses(); AdResponseBox(BaseGame *inGame); virtual ~AdResponseBox(); - BaseArray _responses; - BaseArray _respButtons; + BaseArray _responses; + BaseArray _respButtons; UIWindow *_window; UIWindow *_shieldWindow; bool _horizontal; diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 21f28b6247..d863d21140 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -151,35 +151,35 @@ void AdScene::cleanup() { for (i = 0; i < _layers.getSize(); i++) { _gameRef->unregisterObject(_layers[i]); } - _layers.removeAll(); + _layers.clear(); for (i = 0; i < _waypointGroups.getSize(); i++) { _gameRef->unregisterObject(_waypointGroups[i]); } - _waypointGroups.removeAll(); + _waypointGroups.clear(); for (i = 0; i < _scaleLevels.getSize(); i++) { _gameRef->unregisterObject(_scaleLevels[i]); } - _scaleLevels.removeAll(); + _scaleLevels.clear(); for (i = 0; i < _rotLevels.getSize(); i++) { _gameRef->unregisterObject(_rotLevels[i]); } - _rotLevels.removeAll(); + _rotLevels.clear(); for (i = 0; i < _pfPath.getSize(); i++) { delete _pfPath[i]; } - _pfPath.removeAll(); + _pfPath.clear(); _pfPointsNum = 0; for (i = 0; i < _objects.getSize(); i++) { _gameRef->unregisterObject(_objects[i]); } - _objects.removeAll(); + _objects.clear(); delete _viewport; _viewport = NULL; @@ -494,7 +494,7 @@ void AdScene::pathFinderStep() { // target point marked, generate path and terminate if (lowestPt->x == _pfTarget->x && lowestPt->y == _pfTarget->y) { while (lowestPt != NULL) { - _pfTargetPath->_points.insertAt(0, new BasePoint(lowestPt->x, lowestPt->y)); + _pfTargetPath->_points.insert_at(0, new BasePoint(lowestPt->x, lowestPt->y)); lowestPt = lowestPt->_origin; } @@ -1142,7 +1142,7 @@ bool AdScene::updateFreeObjects() { ////////////////////////////////////////////////////////////////////////// bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { AdGame *adGame = (AdGame *)_gameRef; - BaseArray objects; + BaseArray objects; AdObject *obj; // global objects @@ -1751,7 +1751,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, index = 0; } if (index <= _layers.getSize() - 1) { - _layers.insertAt(index, layer); + _layers.insert_at(index, layer); } else { _layers.add(layer); } @@ -1797,7 +1797,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, for (int i = 0; i < _layers.getSize(); i++) { if (_layers[i] == toDelete) { - _layers.removeAt(i); + _layers.remove_at(i); _gameRef->unregisterObject(toDelete); break; } @@ -2101,7 +2101,7 @@ bool AdScene::addObject(AdObject *object) { bool AdScene::removeObject(AdObject *object) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i] == object) { - _objects.removeAt(i); + _objects.remove_at(i); return _gameRef->unregisterObject(object); } } @@ -2849,7 +2849,7 @@ bool AdScene::restoreDeviceObjects() { ////////////////////////////////////////////////////////////////////////// BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) { - BaseArray objects; + BaseArray objects; getSceneObjects(objects, true); if (objects.getSize() == 0) { @@ -2873,7 +2873,7 @@ BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) { ////////////////////////////////////////////////////////////////////////// BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { - BaseArray objects; + BaseArray objects; getSceneObjects(objects, true); if (objects.getSize() == 0) { @@ -2897,11 +2897,11 @@ BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { ////////////////////////////////////////////////////////////////////////// -bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOnly) { +bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOnly) { for (int i = 0; i < _layers.getSize(); i++) { // close-up layer -> remove everything below it if (interactiveOnly && _layers[i]->_closeUp) { - objects.removeAll(); + objects.clear(); } @@ -2917,7 +2917,7 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i break; case OBJECT_REGION: { - BaseArray regionObj; + BaseArray regionObj; getRegionObjects(node->_region, regionObj, interactiveOnly); for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { bool found = false; @@ -2942,7 +2942,7 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i } // objects outside any region - BaseArray regionObj; + BaseArray regionObj; getRegionObjects(NULL, regionObj, interactiveOnly); for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { bool found = false; @@ -2963,7 +2963,7 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i ////////////////////////////////////////////////////////////////////////// -bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, bool interactiveOnly) { +bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, bool interactiveOnly) { AdGame *adGame = (AdGame *)_gameRef; AdObject *obj; diff --git a/engines/wintermute/ad/ad_scene.h b/engines/wintermute/ad/ad_scene.h index b1420cc5c2..a4bf666aea 100644 --- a/engines/wintermute/ad/ad_scene.h +++ b/engines/wintermute/ad/ad_scene.h @@ -49,8 +49,8 @@ public: BaseObject *getNextAccessObject(BaseObject *CurrObject); BaseObject *getPrevAccessObject(BaseObject *CurrObject); - bool getSceneObjects(BaseArray &Objects, bool InteractiveOnly); - bool getRegionObjects(AdRegion *Region, BaseArray &Objects, bool InteractiveOnly); + bool getSceneObjects(BaseArray &Objects, bool InteractiveOnly); + bool getRegionObjects(AdRegion *Region, BaseArray &Objects, bool InteractiveOnly); bool afterLoad(); @@ -120,9 +120,9 @@ public: bool getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester = NULL); AdScene(BaseGame *inGame); virtual ~AdScene(); - BaseArray _layers; - BaseArray _objects; - BaseArray _waypointGroups; + BaseArray _layers; + BaseArray _objects; + BaseArray _waypointGroups; bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); int _width; @@ -149,8 +149,8 @@ public: bool _editorShowDecor; bool _editorShowEntities; bool _editorShowScale; - BaseArray _scaleLevels; - BaseArray _rotLevels; + BaseArray _scaleLevels; + BaseArray _rotLevels; virtual bool restoreDeviceObjects(); int getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester = NULL); @@ -169,7 +169,7 @@ private: BasePoint *_pfTarget; AdPath *_pfTargetPath; BaseObject *_pfRequester; - BaseArray _pfPath; + BaseArray _pfPath; int _offsetTop; int _offsetLeft; diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index 8a223150f2..673fb965e9 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -50,7 +50,7 @@ AdSceneState::~AdSceneState() { for (int i = 0; i < _nodeStates.getSize(); i++) { delete _nodeStates[i]; } - _nodeStates.removeAll(); + _nodeStates.clear(); } diff --git a/engines/wintermute/ad/ad_scene_state.h b/engines/wintermute/ad/ad_scene_state.h index 469f985639..8f1bdb8fd2 100644 --- a/engines/wintermute/ad/ad_scene_state.h +++ b/engines/wintermute/ad/ad_scene_state.h @@ -43,7 +43,7 @@ public: AdSceneState(BaseGame *inGame); virtual ~AdSceneState(); char *_filename; - BaseArray _nodeStates; + BaseArray _nodeStates; }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index fc057ba183..5b88887e0c 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -55,7 +55,7 @@ AdTalkDef::~AdTalkDef() { for (int i = 0; i < _nodes.getSize(); i++) { delete _nodes[i]; } - _nodes.removeAll(); + _nodes.clear(); delete[] _defaultSpriteFilename; delete _defaultSprite; diff --git a/engines/wintermute/ad/ad_talk_def.h b/engines/wintermute/ad/ad_talk_def.h index fa32a81041..4d28881e97 100644 --- a/engines/wintermute/ad/ad_talk_def.h +++ b/engines/wintermute/ad/ad_talk_def.h @@ -47,7 +47,7 @@ public: virtual ~AdTalkDef(); bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); - BaseArray _nodes; + BaseArray _nodes; char *_defaultSpriteFilename; BaseSprite *_defaultSprite; virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 90435d7977..6aca8e01a8 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -55,12 +55,12 @@ AdTalkHolder::~AdTalkHolder() { for (int i = 0; i < _talkSprites.getSize(); i++) { delete _talkSprites[i]; } - _talkSprites.removeAll(); + _talkSprites.clear(); for (int i = 0; i < _talkSpritesEx.getSize(); i++) { delete _talkSpritesEx[i]; } - _talkSpritesEx.removeAll(); + _talkSpritesEx.clear(); } ////////////////////////////////////////////////////////////////////////// @@ -237,7 +237,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS setTemp2 = true; } delete _talkSpritesEx[i]; - _talkSpritesEx.removeAt(i); + _talkSpritesEx.remove_at(i); break; } } @@ -251,7 +251,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS setTemp2 = true; } delete _talkSprites[i]; - _talkSprites.removeAt(i); + _talkSprites.remove_at(i); break; } } @@ -297,7 +297,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } delete _talkSpritesEx[i]; } - _talkSpritesEx.removeAll(); + _talkSpritesEx.clear(); } else { for (int i = 0; i < _talkSprites.getSize(); i++) { if (_talkSprites[i] == _currentSprite) { @@ -308,7 +308,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } delete _talkSprites[i]; } - _talkSprites.removeAll(); + _talkSprites.clear(); } // set new diff --git a/engines/wintermute/ad/ad_talk_holder.h b/engines/wintermute/ad/ad_talk_holder.h index 8ad8ae1e52..2607fdd9da 100644 --- a/engines/wintermute/ad/ad_talk_holder.h +++ b/engines/wintermute/ad/ad_talk_holder.h @@ -39,8 +39,8 @@ public: virtual BaseSprite *getTalkStance(const char *stance); virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); BaseSprite *_sprite; - BaseArray _talkSprites; - BaseArray _talkSpritesEx; + BaseArray _talkSprites; + BaseArray _talkSpritesEx; AdTalkHolder(BaseGame *inGame); virtual ~AdTalkHolder(); diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index bb1e9275f5..fac3bbe630 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -59,7 +59,7 @@ void AdWaypointGroup::cleanup() { for (int i = 0; i < _points.getSize(); i++) { delete _points[i]; } - _points.removeAll(); + _points.clear(); _editorSelectedPoint = -1; } diff --git a/engines/wintermute/ad/ad_waypoint_group.h b/engines/wintermute/ad/ad_waypoint_group.h index f23f7be859..7d69ab8237 100644 --- a/engines/wintermute/ad/ad_waypoint_group.h +++ b/engines/wintermute/ad/ad_waypoint_group.h @@ -47,7 +47,7 @@ public: bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); virtual ~AdWaypointGroup(); - BaseArray _points; + BaseArray _points; int _editorSelectedPoint; virtual ScValue *scGetProperty(const char *name); virtual bool scSetProperty(const char *name, ScValue *value); -- cgit v1.2.3 From 2c530bc6edc9ffd95fa86488a663e67d2735041f Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 20:49:59 +0200 Subject: WINTERMUTE: var_name -> varName --- engines/wintermute/ad/ad_game.cpp | 18 +++++++++--------- engines/wintermute/ad/ad_inventory_box.cpp | 6 +++--- engines/wintermute/ad/ad_response_box.cpp | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 4533496199..e7bc4483e6 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -715,13 +715,13 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); if (!val->isNULL()) { for (int i = 0; i < _inventories.getSize(); i++) { - AdInventory *Inv = _inventories[i]; + AdInventory *inv = _inventories[i]; - for (int j = 0; j < Inv->_takenItems.getSize(); j++) { - if (val->getNative() == Inv->_takenItems[j]) { + for (int j = 0; j < inv->_takenItems.getSize(); j++) { + if (val->getNative() == inv->_takenItems[j]) { stack->pushBool(true); return STATUS_OK; - } else if (scumm_stricmp(val->getString(), Inv->_takenItems[j]->getName()) == 0) { + } else if (scumm_stricmp(val->getString(), inv->_takenItems[j]->getName()) == 0) { stack->pushBool(true); return STATUS_OK; } @@ -1176,16 +1176,16 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name) { - ScValue *this_obj; + ScValue *thisObj; ////////////////////////////////////////////////////////////////////////// // Actor ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "Actor") == 0) { stack->correctParams(0); - this_obj = thisStack->getTop(); + thisObj = thisStack->getTop(); - this_obj->setNative(new AdActor(_gameRef)); + thisObj->setNative(new AdActor(_gameRef)); stack->pushNULL(); } @@ -1194,9 +1194,9 @@ bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Entity") == 0) { stack->correctParams(0); - this_obj = thisStack->getTop(); + thisObj = thisStack->getTop(); - this_obj->setNative(new AdEntity(_gameRef)); + thisObj->setNative(new AdEntity(_gameRef)); stack->pushNULL(); } diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index b8a3f1da22..80929bcb7b 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -223,7 +223,7 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd = 2; BaseParser parser(_gameRef); - bool always_visible = false; + bool alwaysVisible = false; _exclusive = false; if (complete) { @@ -275,7 +275,7 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ALWAYS_VISIBLE: - parser.scanStr((char *)params, "%b", &always_visible); + parser.scanStr((char *)params, "%b", &alwaysVisible); break; case TOKEN_SPACING: @@ -318,7 +318,7 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { } } - _visible = always_visible; + _visible = alwaysVisible; if (_window) { for (int i = 0; i < _window->_widgets.getSize(); i++) { diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index c566120405..07df0a88ee 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -453,22 +453,22 @@ bool AdResponseBox::display() { // shift down if needed if (!_horizontal) { - int total_height = 0; + int totalHeight = 0; for (i = 0; i < _respButtons.getSize(); i++) { - total_height += (_respButtons[i]->_height + _spacing); + totalHeight += (_respButtons[i]->_height + _spacing); } - total_height -= _spacing; + totalHeight -= _spacing; switch (_verticalAlign) { case VAL_BOTTOM: - if (yyy + total_height < rect.bottom) { - yyy = rect.bottom - total_height; + if (yyy + totalHeight < rect.bottom) { + yyy = rect.bottom - totalHeight; } break; case VAL_CENTER: - if (yyy + total_height < rect.bottom) { - yyy += ((rect.bottom - rect.top) - total_height) / 2; + if (yyy + totalHeight < rect.bottom) { + yyy += ((rect.bottom - rect.top) - totalHeight) / 2; } break; -- cgit v1.2.3 From 3a49f2bad407787ef65d04c5f9ae423485629b41 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 22:20:55 +0200 Subject: WINTERMUTE: More variable/function renaming VarName->varName --- engines/wintermute/ad/ad_actor.cpp | 36 ++++++++++---------- engines/wintermute/ad/ad_entity.cpp | 16 ++++----- engines/wintermute/ad/ad_game.cpp | 10 +++--- engines/wintermute/ad/ad_game.h | 2 +- engines/wintermute/ad/ad_inventory_box.h | 9 ++--- engines/wintermute/ad/ad_item.cpp | 12 +++---- engines/wintermute/ad/ad_item.h | 15 ++++----- engines/wintermute/ad/ad_node_state.h | 4 ++- engines/wintermute/ad/ad_scene.cpp | 6 ++-- engines/wintermute/ad/ad_scene.h | 58 ++++++++++++++++---------------- engines/wintermute/ad/ad_scene_state.cpp | 2 +- engines/wintermute/ad/ad_sentence.cpp | 2 +- engines/wintermute/ad/ad_sentence.h | 2 +- 13 files changed, 88 insertions(+), 86 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index fb46cef9cf..540b6b62c2 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -752,9 +752,9 @@ bool AdActor::update() { _tempSprite2 = _sentence->_currentSprite; } - bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { - if (TimeIsUp) { + bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (timeIsUp) { _sentence->finish(); _tempSprite2 = NULL; _state = _nextState; @@ -797,7 +797,7 @@ bool AdActor::update() { if (_currentSprite && !already_moved) { - _currentSprite->GetCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); if (_currentSprite->_changed) { _posX += _currentSprite->_moveX; _posY += _currentSprite->_moveY; @@ -857,7 +857,7 @@ void AdActor::getNextStep() { return; } - _currentSprite->GetCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); if (!_currentSprite->_changed) { return; } @@ -941,9 +941,9 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "GoTo") == 0 || strcmp(name, "GoToAsync") == 0) { stack->correctParams(2); - int X = stack->pop()->getInt(); - int Y = stack->pop()->getInt(); - goTo(X, Y); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + goTo(x, y); if (strcmp(name, "GoToAsync") != 0) { script->waitForExclusive(this); } @@ -1033,11 +1033,11 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "UnloadAnim") == 0) { stack->correctParams(1); - const char *AnimName = stack->pop()->getString(); + const char *animName = stack->pop()->getString(); - bool Found = false; + bool found = false; for (int i = 0; i < _anims.getSize(); i++) { - if (scumm_stricmp(_anims[i]->getName(), AnimName) == 0) { + if (scumm_stricmp(_anims[i]->getName(), animName) == 0) { // invalidate sprites in use if (_anims[i]->containsSprite(_tempSprite2)) { _tempSprite2 = NULL; @@ -1053,10 +1053,10 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, _anims[i] = NULL; _anims.remove_at(i); i--; - Found = true; + found = true; } } - stack->pushBool(Found); + stack->pushBool(found); return STATUS_OK; } @@ -1065,8 +1065,8 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "HasAnim") == 0) { stack->correctParams(1); - const char *AnimName = stack->pop()->getString(); - stack->pushBool(getAnimByName(AnimName) != NULL); + const char *animName = stack->pop()->getString(); + stack->pushBool(getAnimByName(animName) != NULL); return STATUS_OK; } else { return AdTalkHolder::scCallMethod(script, stack, thisStack, name); @@ -1421,7 +1421,7 @@ bool AdActor::mergeAnims(const char *animsFilename) { int cmd; BaseParser parser(_gameRef); - bool Ret = STATUS_OK; + bool ret = STATUS_OK; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { @@ -1429,7 +1429,7 @@ bool AdActor::mergeAnims(const char *animsFilename) { AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; - Ret = STATUS_FAILED; + ret = STATUS_FAILED; } else { _anims.add(anim); } @@ -1438,7 +1438,7 @@ bool AdActor::mergeAnims(const char *animsFilename) { } } delete[] fileBuffer; - return Ret; + return ret; } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index aa30a0096c..daa064f328 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -611,9 +611,9 @@ bool AdEntity::update() { _tempSprite2 = _sentence->_currentSprite; } - bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { - if (TimeIsUp) { + bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (timeIsUp) { _sentence->finish(); _tempSprite2 = NULL; _state = STATE_READY; @@ -637,7 +637,7 @@ bool AdEntity::update() { if (_currentSprite) { - _currentSprite->GetCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); if (_currentSprite->_changed) { _posX += _currentSprite->_moveX; _posY += _currentSprite->_moveY; @@ -648,10 +648,10 @@ bool AdEntity::update() { _ready = (_state == STATE_READY); if (_theora) { - int OffsetX, OffsetY; - _gameRef->getOffset(&OffsetX, &OffsetY); - _theora->_posX = _posX - OffsetX; - _theora->_posY = _posY - OffsetY; + int offsetX, offsetY; + _gameRef->getOffset(&offsetX, &offsetY); + _theora->_posX = _posX - offsetX; + _theora->_posY = _posY - offsetY; _theora->update(); if (_theora->isFinished()) { diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index e7bc4483e6..66ec582f21 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -334,7 +334,7 @@ bool AdGame::displaySentences(bool frozen) { ////////////////////////////////////////////////////////////////////////// void AdGame::finishSentences() { for (int i = 0; i < _sentences.getSize(); i++) { - if (_sentences[i]->CanSkip()) { + if (_sentences[i]->canSkip()) { _sentences[i]->_duration = 0; if (_sentences[i]->_sound) { _sentences[i]->_sound->stop(); @@ -557,8 +557,8 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ResetResponse") == 0) { stack->correctParams(1); - int ID = stack->pop()->getInt(-1); - resetResponse(ID); + int id = stack->pop()->getInt(-1); + resetResponse(id); stack->pushNULL(); return STATUS_OK; } @@ -1175,7 +1175,7 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name) { +bool AdGame::externalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name) { ScValue *thisObj; ////////////////////////////////////////////////////////////////////////// @@ -1204,7 +1204,7 @@ bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// // call parent else { - return BaseGame::ExternalCall(script, stack, thisStack, name); + return BaseGame::externalCall(script, stack, thisStack, name); } diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index e0179d3e94..ef671b0a64 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -135,7 +135,7 @@ public: virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); bool validMouse(); private: - virtual bool ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name); + virtual bool externalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name); AdObject *_invObject; BaseArray _inventories; diff --git a/engines/wintermute/ad/ad_inventory_box.h b/engines/wintermute/ad/ad_inventory_box.h index dfbf62be9a..1857cd8f19 100644 --- a/engines/wintermute/ad/ad_inventory_box.h +++ b/engines/wintermute/ad/ad_inventory_box.h @@ -40,10 +40,6 @@ class AdInventoryBox : public BaseObject { public: bool _hideSelected; DECLARE_PERSISTENT(AdInventoryBox, BaseObject) - bool _exclusive; - int _scrollBy; - int _itemHeight; - int _itemWidth; bool _visible; virtual bool display(); UIButton *_closeButton; @@ -57,6 +53,11 @@ public: bool loadFile(const char *filename); bool loadBuffer(byte *buffer, bool complete = true); virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); +private: + bool _exclusive; + int _scrollBy; + int _itemHeight; + int _itemWidth; }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index c9e0d56b24..70b8bba2a4 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -378,9 +378,9 @@ bool AdItem::update() { _tempSprite2 = _sentence->_currentSprite; } - bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { - if (TimeIsUp) { + bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (timeIsUp) { _sentence->finish(); _tempSprite2 = NULL; _state = STATE_READY; @@ -440,9 +440,9 @@ bool AdItem::display(int x, int y) { if (_amountString) { font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); } else { - char Str[256]; - sprintf(Str, "%d", _amount); - font->drawText((byte *)Str, amountX, amountY, width, _amountAlign); + char str[256]; + sprintf(str, "%d", _amount); + font->drawText((byte *)str, amountX, amountY, width, _amountAlign); } } } diff --git a/engines/wintermute/ad/ad_item.h b/engines/wintermute/ad/ad_item.h index 11010c2a35..eaa6844fcd 100644 --- a/engines/wintermute/ad/ad_item.h +++ b/engines/wintermute/ad/ad_item.h @@ -36,14 +36,6 @@ namespace WinterMute { class AdItem : public AdTalkHolder { public: - bool _displayAmount; - int _amount; - int _amountOffsetX; - int _amountOffsetY; - TTextAlign _amountAlign; - char *_amountString; - - bool update(); DECLARE_PERSISTENT(AdItem, AdTalkHolder) bool display(int x, int y); @@ -63,6 +55,13 @@ public: virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); +private: + bool _displayAmount; + int _amount; + int _amountOffsetX; + int _amountOffsetY; + TTextAlign _amountAlign; + char *_amountString; }; } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_node_state.h b/engines/wintermute/ad/ad_node_state.h index fc7692a1bf..64ecab6849 100644 --- a/engines/wintermute/ad/ad_node_state.h +++ b/engines/wintermute/ad/ad_node_state.h @@ -35,6 +35,7 @@ class AdEntity; class AdNodeState : public BaseClass { public: + bool _active; bool transferEntity(AdEntity *entity, bool includingSprites, bool saving); void setName(const char *name); void setFilename(const char *filename); @@ -42,8 +43,9 @@ public: DECLARE_PERSISTENT(AdNodeState, BaseClass) AdNodeState(BaseGame *inGame); virtual ~AdNodeState(); + const char *getName() const { return _name; } +private: char *_name; - bool _active; char *_caption[7]; void setCaption(const char *caption, int caseVal); char *getCaption(int caseVal); diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index d863d21140..e047373918 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -659,7 +659,7 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { int ar, ag, ab, aa; char camera[MAX_PATH_LENGTH] = ""; - /* float WaypointHeight = -1.0f; */ + /* float waypointHeight = -1.0f; */ while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { @@ -991,8 +991,8 @@ bool AdScene::traverseNodes(bool doUpdate) { _gameRef->_renderer->setup2D(); // for each layer - /* int MainOffsetX = 0; */ - /* int MainOffsetY = 0; */ + /* int mainOffsetX = 0; */ + /* int mainOffsetY = 0; */ for (j = 0; j < _layers.getSize(); j++) { if (!_layers[j]->_active) { diff --git a/engines/wintermute/ad/ad_scene.h b/engines/wintermute/ad/ad_scene.h index a4bf666aea..5c2f505001 100644 --- a/engines/wintermute/ad/ad_scene.h +++ b/engines/wintermute/ad/ad_scene.h @@ -47,55 +47,55 @@ class AdPathPoint; class AdScene : public BaseObject { public: - BaseObject *getNextAccessObject(BaseObject *CurrObject); - BaseObject *getPrevAccessObject(BaseObject *CurrObject); - bool getSceneObjects(BaseArray &Objects, bool InteractiveOnly); - bool getRegionObjects(AdRegion *Region, BaseArray &Objects, bool InteractiveOnly); + BaseObject *getNextAccessObject(BaseObject *currObject); + BaseObject *getPrevAccessObject(BaseObject *currObject); + bool getSceneObjects(BaseArray &objects, bool interactiveOnly); + bool getRegionObjects(AdRegion *region, BaseArray &objects, bool interactiveOnly); bool afterLoad(); - bool getRegionsAt(int X, int Y, AdRegion **RegionList, int NumRegions); - bool handleItemAssociations(const char *ItemName, bool Show); + bool getRegionsAt(int x, int y, AdRegion **regionList, int numRegions); + bool handleItemAssociations(const char *itemName, bool show); UIWindow *_shieldWindow; - float getRotationAt(int X, int Y); + float getRotationAt(int x, int y); bool loadState(); bool saveState(); bool _persistentState; bool _persistentStateSprites; BaseObject *getNodeByName(const char *name); - void setOffset(int OffsetLeft, int OffsetTop); - bool pointInViewport(int X, int Y); + void setOffset(int offsetLeft, int offsetTop); + bool pointInViewport(int x, int y); int getOffsetTop(); int getOffsetLeft(); - bool getViewportSize(int *Width = NULL, int *Height = NULL); - bool getViewportOffset(int *OffsetX = NULL, int *OffsetY = NULL); + bool getViewportSize(int *width = NULL, int *height = NULL); + bool getViewportOffset(int *offsetX = NULL, int *offsetY = NULL); BaseViewport *_viewport; BaseFader *_fader; int _pfPointsNum; - void pfPointsAdd(int X, int Y, int Distance); + void pfPointsAdd(int x, int y, int distance); void pfPointsStart(); bool _initialized; - bool correctTargetPoint(int StartX, int StartY, int *X, int *Y, bool CheckFreeObjects = false, BaseObject *Requester = NULL); - bool correctTargetPoint2(int StartX, int StartY, int *TargetX, int *TargetY, bool CheckFreeObjects, BaseObject *Requester); + bool correctTargetPoint(int startX, int startY, int *x, int *y, bool checkFreeObjects = false, BaseObject *requester = NULL); + bool correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, BaseObject *requester); DECLARE_PERSISTENT(AdScene, BaseObject) - bool displayRegionContent(AdRegion *Region = NULL, bool Display3DOnly = false); - bool displayRegionContentOld(AdRegion *Region = NULL); - static int compareObjs(const void *Obj1, const void *Obj2); + bool displayRegionContent(AdRegion *region = NULL, bool display3DOnly = false); + bool displayRegionContentOld(AdRegion *region = NULL); + static int compareObjs(const void *obj1, const void *obj2); bool updateFreeObjects(); - bool traverseNodes(bool Update = false); - float getScaleAt(int Y); + bool traverseNodes(bool update = false); + float getScaleAt(int y); bool sortScaleLevels(); bool sortRotLevels(); virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - uint32 getAlphaAt(int X, int Y, bool ColorCheck = false); + uint32 getAlphaAt(int x, int y, bool colorCheck = false); bool _paralaxScrolling; - void skipTo(int OffsetX, int OffsetY); + void skipTo(int offsetX, int offsetY); void setDefaults(); void cleanup(); - void skipToObject(BaseObject *Object); - void scrollToObject(BaseObject *Object); - void scrollTo(int OffsetX, int OffsetY); + void skipToObject(BaseObject *object); + void scrollToObject(BaseObject *object); + void scrollTo(int offsetX, int offsetY); virtual bool update(); bool _autoScroll; int _targetOffsetTop; @@ -113,10 +113,10 @@ public: uint32 _pfMaxTime; bool initLoop(); void pathFinderStep(); - bool isBlockedAt(int X, int Y, bool CheckFreeObjects = false, BaseObject *Requester = NULL); - bool isWalkableAt(int X, int Y, bool CheckFreeObjects = false, BaseObject *Requester = NULL); + bool isBlockedAt(int x, int y, bool checkFreeObjects = false, BaseObject *requester = NULL); + bool isWalkableAt(int x, int y, bool checkFreeObjects = false, BaseObject *requester = NULL); AdLayer *_mainLayer; - float getZoomAt(int X, int Y); + float getZoomAt(int x, int y); bool getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester = NULL); AdScene(BaseGame *inGame); virtual ~AdScene(); @@ -163,8 +163,8 @@ public: private: - bool persistState(bool Saving = true); - void pfAddWaypointGroup(AdWaypointGroup *Wpt, BaseObject *Requester = NULL); + bool persistState(bool saving = true); + void pfAddWaypointGroup(AdWaypointGroup *Wpt, BaseObject *requester = NULL); bool _pfReady; BasePoint *_pfTarget; AdPath *_pfTargetPath; diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index 673fb965e9..bbacf57707 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -76,7 +76,7 @@ void AdSceneState::setFilename(const char *filename) { ////////////////////////////////////////////////////////////////////////// AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { for (int i = 0; i < _nodeStates.getSize(); i++) { - if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) { + if (scumm_stricmp(_nodeStates[i]->getName(), name) == 0) { return _nodeStates[i]; } } diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index d429c1fedf..6bbcd590a8 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -353,7 +353,7 @@ bool AdSentence::update(TDirection dir) { } ////////////////////////////////////////////////////////////////////////// -bool AdSentence::CanSkip() { +bool AdSentence::canSkip() { // prevent accidental sentence skipping (TODO make configurable) return (_gameRef->_timer - _startTime) > 300; } diff --git a/engines/wintermute/ad/ad_sentence.h b/engines/wintermute/ad/ad_sentence.h index 6883bd8893..ae4ee793d5 100644 --- a/engines/wintermute/ad/ad_sentence.h +++ b/engines/wintermute/ad/ad_sentence.h @@ -72,7 +72,7 @@ public: virtual ~AdSentence(); AdTalkDef *_talkDef; - bool CanSkip(); + bool canSkip(); private: char *_tempStance; -- cgit v1.2.3 From f6ac34ab9a48b702e3c3678cfd208ebeb2517dc4 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 27 Jul 2012 18:13:42 +0200 Subject: WINTERMUTE: Get rid of almost all LLVM GCC 4.2 warnings. --- engines/wintermute/ad/ad_node_state.cpp | 2 +- engines/wintermute/ad/ad_node_state.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index 5a58dba5b1..270a114277 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -128,7 +128,7 @@ void AdNodeState::setCaption(const char *caption, int caseVal) { ////////////////////////////////////////////////////////////////////////// -char *AdNodeState::getCaption(int caseVal) { +const char *AdNodeState::getCaption(int caseVal) { if (caseVal == 0) { caseVal = 1; } diff --git a/engines/wintermute/ad/ad_node_state.h b/engines/wintermute/ad/ad_node_state.h index 64ecab6849..ce15bc893f 100644 --- a/engines/wintermute/ad/ad_node_state.h +++ b/engines/wintermute/ad/ad_node_state.h @@ -48,7 +48,7 @@ private: char *_name; char *_caption[7]; void setCaption(const char *caption, int caseVal); - char *getCaption(int caseVal); + const char *getCaption(int caseVal); uint32 _alphaColor; char *_filename; char *_cursor; -- cgit v1.2.3 From c7fa8e7d1024e4447a7396b5099870d01b775746 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 27 Jul 2012 19:35:20 +0200 Subject: WINTERMUTE: Move settings-files to save-dir (gzipped xml now) --- engines/wintermute/ad/ad_game.cpp | 2 +- engines/wintermute/ad/ad_game.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 66ec582f21..b922123e38 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -66,7 +66,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdGame, true) ////////////////////////////////////////////////////////////////////////// -AdGame::AdGame(): BaseGame() { +AdGame::AdGame(const Common::String &gameId): BaseGame(gameId) { _responseBox = NULL; _inventoryBox = NULL; diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index ef671b0a64..7f76b959d4 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -118,7 +118,7 @@ public: bool addObject(AdObject *object); AdScene *_scene; bool initLoop(); - AdGame(); + AdGame(const Common::String &gameId); virtual ~AdGame(); BaseArray _objects; -- cgit v1.2.3 From 8ed71a99f6aaee27a3187cb47fe0c3b30acf88a0 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 27 Jul 2012 19:37:00 +0200 Subject: WINTERMUTE: Constructor(args): SuperClass(args) -> Constructor(args) : SuperClass(args) --- engines/wintermute/ad/ad_actor.cpp | 2 +- engines/wintermute/ad/ad_entity.cpp | 2 +- engines/wintermute/ad/ad_game.cpp | 2 +- engines/wintermute/ad/ad_inventory.cpp | 2 +- engines/wintermute/ad/ad_inventory_box.cpp | 2 +- engines/wintermute/ad/ad_item.cpp | 2 +- engines/wintermute/ad/ad_layer.cpp | 2 +- engines/wintermute/ad/ad_node_state.cpp | 2 +- engines/wintermute/ad/ad_object.cpp | 2 +- engines/wintermute/ad/ad_path.cpp | 2 +- engines/wintermute/ad/ad_region.cpp | 2 +- engines/wintermute/ad/ad_response.cpp | 2 +- engines/wintermute/ad/ad_response_box.cpp | 2 +- engines/wintermute/ad/ad_response_context.cpp | 2 +- engines/wintermute/ad/ad_rot_level.cpp | 2 +- engines/wintermute/ad/ad_scale_level.cpp | 2 +- engines/wintermute/ad/ad_scene.cpp | 2 +- engines/wintermute/ad/ad_scene_node.cpp | 2 +- engines/wintermute/ad/ad_scene_state.cpp | 2 +- engines/wintermute/ad/ad_sentence.cpp | 2 +- engines/wintermute/ad/ad_sprite_set.cpp | 2 +- engines/wintermute/ad/ad_talk_def.cpp | 2 +- engines/wintermute/ad/ad_talk_holder.cpp | 2 +- engines/wintermute/ad/ad_talk_node.cpp | 2 +- engines/wintermute/ad/ad_waypoint_group.cpp | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index 540b6b62c2..caadab18aa 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -51,7 +51,7 @@ IMPLEMENT_PERSISTENT(AdActor, false) ////////////////////////////////////////////////////////////////////////// -AdActor::AdActor(BaseGame *inGame): AdTalkHolder(inGame) { +AdActor::AdActor(BaseGame *inGame) : AdTalkHolder(inGame) { _path = new AdPath(_gameRef); _type = OBJECT_ACTOR; diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index daa064f328..b6da77f971 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -57,7 +57,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdEntity, false) ////////////////////////////////////////////////////////////////////////// -AdEntity::AdEntity(BaseGame *inGame): AdTalkHolder(inGame) { +AdEntity::AdEntity(BaseGame *inGame) : AdTalkHolder(inGame) { _type = OBJECT_ENTITY; _subtype = ENTITY_NORMAL; _region = NULL; diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index b922123e38..260a3fc378 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -66,7 +66,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdGame, true) ////////////////////////////////////////////////////////////////////////// -AdGame::AdGame(const Common::String &gameId): BaseGame(gameId) { +AdGame::AdGame(const Common::String &gameId) : BaseGame(gameId) { _responseBox = NULL; _inventoryBox = NULL; diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index 6cc5ed879e..203a18ae32 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -37,7 +37,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdInventory, false) ////////////////////////////////////////////////////////////////////////// -AdInventory::AdInventory(BaseGame *inGame): BaseObject(inGame) { +AdInventory::AdInventory(BaseGame *inGame) : BaseObject(inGame) { _scrollOffset = 0; } diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index 80929bcb7b..bc773cbdaf 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -46,7 +46,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdInventoryBox, false) ////////////////////////////////////////////////////////////////////////// -AdInventoryBox::AdInventoryBox(BaseGame *inGame): BaseObject(inGame) { +AdInventoryBox::AdInventoryBox(BaseGame *inGame) : BaseObject(inGame) { _itemsArea.setEmpty(); _scrollOffset = 0; _spacing = 0; diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index 70b8bba2a4..8e93ef77d4 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -48,7 +48,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdItem, false) ////////////////////////////////////////////////////////////////////////// -AdItem::AdItem(BaseGame *inGame): AdTalkHolder(inGame) { +AdItem::AdItem(BaseGame *inGame) : AdTalkHolder(inGame) { _spriteHover = NULL; _cursorNormal = _cursorHover = NULL; diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index a60cd76209..c4be6c8dfc 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -43,7 +43,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdLayer, false) ////////////////////////////////////////////////////////////////////////// -AdLayer::AdLayer(BaseGame *inGame): BaseObject(inGame) { +AdLayer::AdLayer(BaseGame *inGame) : BaseObject(inGame) { _main = false; _width = _height = 0; _active = true; diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index 270a114277..4784d6d331 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -41,7 +41,7 @@ IMPLEMENT_PERSISTENT(AdNodeState, false) ////////////////////////////////////////////////////////////////////////// -AdNodeState::AdNodeState(BaseGame *inGame): BaseClass(inGame) { +AdNodeState::AdNodeState(BaseGame *inGame) : BaseClass(inGame) { _name = NULL; _active = false; for (int i = 0; i < 7; i++) { diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index cf60bedf2c..aaf4c6db4a 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -57,7 +57,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdObject, false) ////////////////////////////////////////////////////////////////////////// -AdObject::AdObject(BaseGame *inGame): BaseObject(inGame) { +AdObject::AdObject(BaseGame *inGame) : BaseObject(inGame) { _type = OBJECT_NONE; _state = _nextState = STATE_NONE; diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index 7734b4d9ba..89eb3f29fa 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -34,7 +34,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdPath, false) ////////////////////////////////////////////////////////////////////////// -AdPath::AdPath(BaseGame *inGame): BaseClass(inGame) { +AdPath::AdPath(BaseGame *inGame) : BaseClass(inGame) { _currIndex = -1; _ready = false; } diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 18b5731830..7d51cfce37 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -39,7 +39,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdRegion, false) ////////////////////////////////////////////////////////////////////////// -AdRegion::AdRegion(BaseGame *inGame): BaseRegion(inGame) { +AdRegion::AdRegion(BaseGame *inGame) : BaseRegion(inGame) { _blocked = false; _decoration = false; _zoom = 0; diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp index e954b0d44d..9cfa181b1c 100644 --- a/engines/wintermute/ad/ad_response.cpp +++ b/engines/wintermute/ad/ad_response.cpp @@ -37,7 +37,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdResponse, false) ////////////////////////////////////////////////////////////////////////// -AdResponse::AdResponse(BaseGame *inGame): BaseObject(inGame) { +AdResponse::AdResponse(BaseGame *inGame) : BaseObject(inGame) { _text = NULL; _textOrig = NULL; _icon = _iconHover = _iconPressed = NULL; diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 07df0a88ee..7f2fdc9b3e 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -49,7 +49,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdResponseBox, false) ////////////////////////////////////////////////////////////////////////// -AdResponseBox::AdResponseBox(BaseGame *inGame): BaseObject(inGame) { +AdResponseBox::AdResponseBox(BaseGame *inGame) : BaseObject(inGame) { _font = _fontHover = NULL; _window = NULL; diff --git a/engines/wintermute/ad/ad_response_context.cpp b/engines/wintermute/ad/ad_response_context.cpp index 41359fc0f0..175a7f8491 100644 --- a/engines/wintermute/ad/ad_response_context.cpp +++ b/engines/wintermute/ad/ad_response_context.cpp @@ -34,7 +34,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdResponseContext, false) ////////////////////////////////////////////////////////////////////////// -AdResponseContext::AdResponseContext(BaseGame *inGame): BaseClass(inGame) { +AdResponseContext::AdResponseContext(BaseGame *inGame) : BaseClass(inGame) { _id = 0; _context = NULL; } diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index f04d379e6b..753dd38190 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -39,7 +39,7 @@ IMPLEMENT_PERSISTENT(AdRotLevel, false) ////////////////////////////////////////////////////////////////////////// -AdRotLevel::AdRotLevel(BaseGame *inGame): BaseObject(inGame) { +AdRotLevel::AdRotLevel(BaseGame *inGame) : BaseObject(inGame) { _posX = 0; _rotation = 0.0f; } diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index f9da6bba4a..465e82cbde 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -37,7 +37,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdScaleLevel, false) ////////////////////////////////////////////////////////////////////////// -AdScaleLevel::AdScaleLevel(BaseGame *inGame): BaseObject(inGame) { +AdScaleLevel::AdScaleLevel(BaseGame *inGame) : BaseObject(inGame) { _posY = 0; _scale = 100; } diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index e047373918..859effd5c7 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -64,7 +64,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdScene, false) ////////////////////////////////////////////////////////////////////////// -AdScene::AdScene(BaseGame *inGame): BaseObject(inGame) { +AdScene::AdScene(BaseGame *inGame) : BaseObject(inGame) { _pfTarget = new BasePoint; setDefaults(); } diff --git a/engines/wintermute/ad/ad_scene_node.cpp b/engines/wintermute/ad/ad_scene_node.cpp index 658e85340d..87b2c25406 100644 --- a/engines/wintermute/ad/ad_scene_node.cpp +++ b/engines/wintermute/ad/ad_scene_node.cpp @@ -34,7 +34,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdSceneNode, false) ////////////////////////////////////////////////////////////////////////// -AdSceneNode::AdSceneNode(BaseGame *inGame): BaseObject(inGame) { +AdSceneNode::AdSceneNode(BaseGame *inGame) : BaseObject(inGame) { _type = OBJECT_NONE; _region = NULL; _entity = NULL; diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index bbacf57707..eafb1f96b6 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -37,7 +37,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdSceneState, false) ////////////////////////////////////////////////////////////////////////// -AdSceneState::AdSceneState(BaseGame *inGame): BaseClass(inGame) { +AdSceneState::AdSceneState(BaseGame *inGame) : BaseClass(inGame) { _filename = NULL; } diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index 6bbcd590a8..5126a51c80 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -43,7 +43,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdSentence, false) ////////////////////////////////////////////////////////////////////////// -AdSentence::AdSentence(BaseGame *inGame): BaseClass(inGame) { +AdSentence::AdSentence(BaseGame *inGame) : BaseClass(inGame) { _text = NULL; _stances = NULL; _tempStance = NULL; diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index 42409988a5..0a5949b2c0 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -38,7 +38,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdSpriteSet, false) ////////////////////////////////////////////////////////////////////////// -AdSpriteSet::AdSpriteSet(BaseGame *inGame, BaseObject *owner): BaseObject(inGame) { +AdSpriteSet::AdSpriteSet(BaseGame *inGame, BaseObject *owner) : BaseObject(inGame) { _owner = owner; for (int i = 0; i < NUM_DIRECTIONS; i++) { diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 5b88887e0c..b12a6af357 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -41,7 +41,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdTalkDef, false) ////////////////////////////////////////////////////////////////////////// -AdTalkDef::AdTalkDef(BaseGame *inGame): BaseObject(inGame) { +AdTalkDef::AdTalkDef(BaseGame *inGame) : BaseObject(inGame) { _defaultSpriteFilename = NULL; _defaultSprite = NULL; diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 6aca8e01a8..5a2b3df31b 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -42,7 +42,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdTalkHolder, false) ////////////////////////////////////////////////////////////////////////// -AdTalkHolder::AdTalkHolder(BaseGame *inGame): AdObject(inGame) { +AdTalkHolder::AdTalkHolder(BaseGame *inGame) : AdObject(inGame) { _sprite = NULL; } diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index ef30290b8c..ecaf098a40 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -38,7 +38,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdTalkNode, false) ////////////////////////////////////////////////////////////////////////// -AdTalkNode::AdTalkNode(BaseGame *inGame): BaseClass(inGame) { +AdTalkNode::AdTalkNode(BaseGame *inGame) : BaseClass(inGame) { _sprite = NULL; _spriteFilename = NULL; _spriteSet = NULL; diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index fac3bbe630..1188ec2fb1 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -40,7 +40,7 @@ namespace WinterMute { IMPLEMENT_PERSISTENT(AdWaypointGroup, false) ////////////////////////////////////////////////////////////////////////// -AdWaypointGroup::AdWaypointGroup(BaseGame *inGame): BaseObject(inGame) { +AdWaypointGroup::AdWaypointGroup(BaseGame *inGame) : BaseObject(inGame) { _active = true; _editorSelectedPoint = -1; _lastMimicScale = -1; -- cgit v1.2.3 From e841bf16d6b955f779e5e30535848bd650d22352 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 28 Jul 2012 23:10:33 +0200 Subject: WINTERMUTE: Fix a few warnings pointed out by fuzzie. --- engines/wintermute/ad/ad_entity.cpp | 2 -- engines/wintermute/ad/ad_scene.cpp | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index b6da77f971..6fea297018 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -1102,10 +1102,8 @@ void AdEntity::setItem(const char *itemName) { ////////////////////////////////////////////////////////////////////////// bool AdEntity::setSprite(const char *filename) { - bool setCurrent = false; if (_currentSprite == _sprite) { _currentSprite = NULL; - setCurrent = true; } delete _sprite; diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 859effd5c7..9a808bbb5f 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -1106,15 +1106,16 @@ bool AdScene::display() { ////////////////////////////////////////////////////////////////////////// bool AdScene::updateFreeObjects() { AdGame *adGame = (AdGame *)_gameRef; - bool is3DSet; + // 3D-code removed + // bool is3DSet; // *** update all active objects - is3DSet = false; + // is3DSet = false; for (int i = 0; i < adGame->_objects.getSize(); i++) { if (!adGame->_objects[i]->_active) { continue; } - + // 3D-code removed adGame->_objects[i]->update(); adGame->_objects[i]->_drawn = false; } -- cgit v1.2.3 From 6dc1e09da93c0ba0507fd0ceadbbb504469deccc Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 29 Jul 2012 00:27:50 +0200 Subject: WINTERMUTE: Replace const char* with const Common::String & in fonts, gfx, particles, sound and files. --- engines/wintermute/ad/ad_entity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 6fea297018..4d1641036a 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -1003,8 +1003,8 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->getFilename()); } - if (_subtype == ENTITY_SOUND && _sFX && _sFX->_soundFilename) { - buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sFX->_soundFilename); + if (_subtype == ENTITY_SOUND && _sFX && _sFX->getFilename()) { + buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sFX->getFilename()); buffer->putTextIndent(indent + 2, "SOUND_START_TIME=%d\n", _sFXStart); buffer->putTextIndent(indent + 2, "SOUND_VOLUME=%d\n", _sFXVolume); } -- cgit v1.2.3 From 9b5cf8f1bafd5aa0dba9194a8f04e58724652891 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 29 Jul 2012 02:30:26 +0200 Subject: WINTERMUTE: Introduce a Singleton-class for holding registry/filemanager. --- engines/wintermute/ad/ad_actor.cpp | 8 ++++---- engines/wintermute/ad/ad_entity.cpp | 4 ++-- engines/wintermute/ad/ad_game.cpp | 14 +++++++------- engines/wintermute/ad/ad_inventory_box.cpp | 4 ++-- engines/wintermute/ad/ad_item.cpp | 4 ++-- engines/wintermute/ad/ad_layer.cpp | 4 ++-- engines/wintermute/ad/ad_region.cpp | 4 ++-- engines/wintermute/ad/ad_response_box.cpp | 4 ++-- engines/wintermute/ad/ad_rot_level.cpp | 4 ++-- engines/wintermute/ad/ad_scale_level.cpp | 4 ++-- engines/wintermute/ad/ad_scene.cpp | 4 ++-- engines/wintermute/ad/ad_sentence.cpp | 2 +- engines/wintermute/ad/ad_sprite_set.cpp | 4 ++-- engines/wintermute/ad/ad_talk_def.cpp | 4 ++-- engines/wintermute/ad/ad_talk_node.cpp | 2 +- engines/wintermute/ad/ad_waypoint_group.cpp | 4 ++-- 16 files changed, 37 insertions(+), 37 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index caadab18aa..b4e9d80a02 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -119,7 +119,7 @@ AdActor::~AdActor() { ////////////////////////////////////////////////////////////////////////// bool AdActor::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdActor::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -221,7 +221,7 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTOR) { @@ -1410,7 +1410,7 @@ bool AdActor::mergeAnims(const char *animsFilename) { TOKEN_TABLE_END - byte *fileBuffer = _gameRef->_fileManager->readWholeFile(animsFilename); + byte *fileBuffer = BaseFileManager::getEngineInstance()->readWholeFile(animsFilename); if (fileBuffer == NULL) { _gameRef->LOG(0, "AdActor::MergeAnims failed for file '%s'", animsFilename); return STATUS_FAILED; @@ -1419,7 +1419,7 @@ bool AdActor::mergeAnims(const char *animsFilename) { byte *buffer = fileBuffer; byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; bool ret = STATUS_OK; diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 4d1641036a..e6fde43697 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -84,7 +84,7 @@ AdEntity::~AdEntity() { ////////////////////////////////////////////////////////////////////////// bool AdEntity::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdEntity::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -198,7 +198,7 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY) { diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 260a3fc378..e399ba5fcf 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -1241,7 +1241,7 @@ bool AdGame::showCursor() { ////////////////////////////////////////////////////////////////////////// bool AdGame::loadFile(const char *filename) { - byte *buffer = _fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdGame::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -1294,7 +1294,7 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { byte *params; byte *params2; int cmd = 1; - BaseParser parser(_gameRef); + BaseParser parser; bool itemFound = false, itemsFound = false; @@ -1537,7 +1537,7 @@ bool AdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *ex ////////////////////////////////////////////////////////////////////////// bool AdGame::loadItemsFile(const char *filename, bool merge) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdGame::LoadItemsFile failed for file '%s'", filename); return STATUS_FAILED; @@ -1567,7 +1567,7 @@ bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (!merge) { while (_items.getSize() > 0) { @@ -1650,7 +1650,7 @@ bool AdGame::windowLoadHook(UIWindow *win, char **buffer, char **params) { TOKEN_TABLE_END int cmd = PARSERR_GENERIC; - BaseParser parser(_gameRef); + BaseParser parser; cmd = parser.getCommand(buffer, commands, params); switch (cmd) { @@ -2130,12 +2130,12 @@ char *AdGame::findSpeechFile(char *stringID) { for (int i = 0; i < _speechDirs.getSize(); i++) { sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); - if (_fileManager->hasFile(ret)) { + if (BaseFileManager::getEngineInstance()->hasFile(ret)) { return ret; } sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); - if (_fileManager->hasFile(ret)) { + if (BaseFileManager::getEngineInstance()->hasFile(ret)) { return ret; } } diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index bc773cbdaf..555fa8e5c2 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -164,7 +164,7 @@ bool AdInventoryBox::display() { ////////////////////////////////////////////////////////////////////////// bool AdInventoryBox::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdInventoryBox::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -222,7 +222,7 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd = 2; - BaseParser parser(_gameRef); + BaseParser parser; bool alwaysVisible = false; _exclusive = false; diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index 8e93ef77d4..cacafa826b 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -84,7 +84,7 @@ AdItem::~AdItem() { ////////////////////////////////////////////////////////////////////////// bool AdItem::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdItem::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -166,7 +166,7 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd = 2; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ITEM) { diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index c4be6c8dfc..5742c9fc85 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -62,7 +62,7 @@ AdLayer::~AdLayer() { ////////////////////////////////////////////////////////////////////////// bool AdLayer::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdLayer::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -121,7 +121,7 @@ bool AdLayer::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_LAYER) { diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 7d51cfce37..5ecb24c5b7 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -54,7 +54,7 @@ AdRegion::~AdRegion() { ////////////////////////////////////////////////////////////////////////// bool AdRegion::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdRegion::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -118,7 +118,7 @@ bool AdRegion::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 7f2fdc9b3e..e321f1cd93 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -204,7 +204,7 @@ bool AdResponseBox::createButtons() { ////////////////////////////////////////////////////////////////////////// bool AdResponseBox::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdResponseBox::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -259,7 +259,7 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_RESPONSE_BOX) { diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index 753dd38190..28c37b5b81 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -53,7 +53,7 @@ AdRotLevel::~AdRotLevel() { ////////////////////////////////////////////////////////////////////////// bool AdRotLevel::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdRotLevel::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -93,7 +93,7 @@ bool AdRotLevel::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ROTATION_LEVEL) { diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index 465e82cbde..430be3559d 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -51,7 +51,7 @@ AdScaleLevel::~AdScaleLevel() { ////////////////////////////////////////////////////////////////////////// bool AdScaleLevel::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdScaleLevel::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -91,7 +91,7 @@ bool AdScaleLevel::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCALE_LEVEL) { diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 9a808bbb5f..b84c4c2dca 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -540,7 +540,7 @@ bool AdScene::initLoop() { ////////////////////////////////////////////////////////////////////////// bool AdScene::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdScene::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -647,7 +647,7 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCENE) { diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index 5126a51c80..d243aaf8e6 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -287,7 +287,7 @@ bool AdSentence::setupTalkFile(const char *soundFilename) { AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); - if (!_gameRef->_fileManager->hasFile(talkDefFileName)) { + if (!BaseFileManager::getEngineInstance()->hasFile(talkDefFileName)) { return STATUS_OK; // no talk def file found } diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index 0a5949b2c0..df10418d95 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -60,7 +60,7 @@ AdSpriteSet::~AdSpriteSet() { ////////////////////////////////////////////////////////////////////////// bool AdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdSpriteSet::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -111,7 +111,7 @@ bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteC byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SPRITESET) { diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index b12a6af357..71d8d6b1c3 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -71,7 +71,7 @@ AdTalkDef::~AdTalkDef() { ////////////////////////////////////////////////////////////////////////// bool AdTalkDef::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdTalkDef::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -114,7 +114,7 @@ bool AdTalkDef::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_TALK) { diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index ecaf098a40..14c1c3f459 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -94,7 +94,7 @@ bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTION) { diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 1188ec2fb1..0f83c2c50b 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -66,7 +66,7 @@ void AdWaypointGroup::cleanup() { ////////////////////////////////////////////////////////////////////////// bool AdWaypointGroup::loadFile(const char *filename) { - byte *buffer = _gameRef->_fileManager->readWholeFile(filename); + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); if (buffer == NULL) { _gameRef->LOG(0, "AdWaypointGroup::LoadFile failed for file '%s'", filename); return STATUS_FAILED; @@ -112,7 +112,7 @@ bool AdWaypointGroup::loadBuffer(byte *buffer, bool complete) { byte *params; int cmd; - BaseParser parser(_gameRef); + BaseParser parser; if (complete) { if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_WAYPOINTS) { -- cgit v1.2.3 From 85ce9340bcb425a6c5e8dbcacff5a7fa2fb4c817 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 29 Jul 2012 21:35:11 +0200 Subject: WINTERMUTE: Separate out SaveGame-code from BaseGame --- engines/wintermute/ad/ad_game.cpp | 28 ++-------------------------- engines/wintermute/ad/ad_game.h | 4 ---- 2 files changed, 2 insertions(+), 30 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index e399ba5fcf..3bda534a04 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -49,6 +49,7 @@ #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_viewport.h" #include "engines/wintermute/base/particles/part_emitter.h" +#include "engines/wintermute/base/saveload.h" #include "engines/wintermute/base/scriptables/script_engine.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" @@ -1453,29 +1454,6 @@ bool AdGame::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } - -////////////////////////////////////////////////////////////////////////// -bool AdGame::loadGame(const char *filename) { - bool ret = BaseGame::loadGame(filename); - if (DID_SUCCEED(ret)) { - SystemClassRegistry::getInstance()->enumInstances(afterLoadRegion, "AdRegion", NULL); - } - return ret; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::initAfterLoad() { - BaseGame::initAfterLoad(); - SystemClassRegistry::getInstance()->enumInstances(afterLoadScene, "AdScene", NULL); - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -void AdGame::afterLoadScene(void *scene, void *data) { - ((AdScene *)scene)->afterLoad(); -} - - ////////////////////////////////////////////////////////////////////////// void AdGame::setPrevSceneName(const char *name) { delete[] _prevSceneName; @@ -1910,9 +1888,7 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { if (_stateEx == GAME_WAITING_RESPONSE) { _responseBox->display(); } - if (_indicatorDisplay) { - displayIndicator(); - } + _renderer->displayIndicator(); if (doUpdate || displayAll) { diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index 7f76b959d4..080aea40aa 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -54,9 +54,6 @@ public: virtual bool displayDebugInfo(); - virtual bool initAfterLoad(); - static void afterLoadScene(void *scene, void *data); - bool addSpeechDir(const char *dir); bool removeSpeechDir(const char *dir); char *findSpeechFile(char *StringID); @@ -101,7 +98,6 @@ public: void setPrevSceneName(const char *name); void setPrevSceneFilename(const char *name); - virtual bool loadGame(const char *filename); AdItem *_selectedItem; bool cleanup(); DECLARE_PERSISTENT(AdGame, BaseGame) -- cgit v1.2.3 From e32b79bff1260f8d2853404f750acc22209a323b Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Tue, 7 Aug 2012 13:32:26 +0200 Subject: WINTERMUTE: Save the random-seed as well. --- engines/wintermute/ad/ad_actor.cpp | 6 +++--- engines/wintermute/ad/ad_talk_holder.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index b4e9d80a02..aa148c9c85 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -43,7 +43,7 @@ #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script_stack.h" #include "engines/wintermute/base/particles/part_emitter.h" -#include "engines/wintermute/wintermute.h" +#include "engines/wintermute/base/base_engine.h" namespace WinterMute { @@ -1262,7 +1262,7 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { } if (talkAnims.getSize() > 0) { - int rnd = g_wintermute->randInt(0, talkAnims.getSize() - 1); + int rnd = BaseEngine::instance().randInt(0, talkAnims.getSize() - 1); ret = talkAnims[rnd]->getSprite(_dir); } else { if (_standSprite) { @@ -1307,7 +1307,7 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { ret = _standSprite->getSprite(_dir); } else { // TODO: remember last - int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); + int rnd = BaseEngine::instance().randInt(0, _talkSprites.getSize() - 1); ret = _talkSprites[rnd]->getSprite(_dir); } } diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 5a2b3df31b..a5ab7f3a6d 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -34,7 +34,7 @@ #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/wintermute.h" +#include "engines/wintermute/base/base_engine.h" #include "common/str.h" namespace WinterMute { @@ -111,7 +111,7 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { ret = _sprite; } else { // TODO: remember last - int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); + int rnd = BaseEngine::instance().randInt(0, _talkSprites.getSize() - 1); ret = _talkSprites[rnd]; } } -- cgit v1.2.3 From c422ae9d8a90aeb63da3e3fdf521323fe6769828 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 11 Aug 2012 02:30:07 +0200 Subject: WINTERMUTE: Get rid of strncpy+manual termination. --- engines/wintermute/ad/ad_sentence.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index d243aaf8e6..60c4519823 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -184,8 +184,7 @@ char *AdSentence::getStance(int stance) { _tempStance = new char [curr - start + 1]; if (_tempStance) { - _tempStance[curr - start] = '\0'; - strncpy(_tempStance, start, curr - start); + Common::strlcpy(_tempStance, start, curr - start + 1); } return _tempStance; -- cgit v1.2.3 From 2c44f3f5fac5f5bbe5628cf3de61782f975174fd Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 13 Aug 2012 01:06:56 +0200 Subject: WINTERMUTE: Make a few noisy warnings into debug-calls. --- engines/wintermute/ad/ad_response_box.cpp | 5 +++-- engines/wintermute/ad/ad_scene.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index e321f1cd93..5f2a1dc825 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -42,6 +42,7 @@ #include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/utils/utils.h" #include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/wintermute.h" #include "common/str.h" namespace WinterMute { @@ -610,7 +611,7 @@ bool AdResponseBox::weedResponses() { } break; default: - warning("AdResponseBox::WeedResponses - Unhandled enum"); + debugC(kWinterMuteDebugGeneral, "AdResponseBox::WeedResponses - Unhandled enum"); break; } } @@ -640,7 +641,7 @@ bool AdResponseBox::handleResponse(AdResponse *response) { adGame->addGameResponse(response->_iD); break; default: - warning("AdResponseBox::HandleResponse - Unhandled enum"); + debugC(kWinterMuteDebugGeneral, "AdResponseBox::HandleResponse - Unhandled enum"); } return STATUS_OK; diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index b84c4c2dca..d99b6b7fb8 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -57,6 +57,7 @@ #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/ui/ui_window.h" #include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/wintermute.h" #include namespace WinterMute { @@ -2936,7 +2937,7 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOn } break; default: - warning("AdScene::GetSceneObjects - Unhandled enum"); + debugC(kWinterMuteDebugGeneral, "AdScene::GetSceneObjects - Unhandled enum"); break; } } -- cgit v1.2.3 From fed19cb66ae5b56dd7dc81b90edd5a0d15986678 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Mon, 13 Aug 2012 03:42:30 +0200 Subject: WINTERMUTE: WinterMute -> Wintermute --- engines/wintermute/ad/ad_actor.cpp | 4 ++-- engines/wintermute/ad/ad_actor.h | 4 ++-- engines/wintermute/ad/ad_entity.cpp | 4 ++-- engines/wintermute/ad/ad_entity.h | 4 ++-- engines/wintermute/ad/ad_game.cpp | 4 ++-- engines/wintermute/ad/ad_game.h | 4 ++-- engines/wintermute/ad/ad_inventory.cpp | 4 ++-- engines/wintermute/ad/ad_inventory.h | 4 ++-- engines/wintermute/ad/ad_inventory_box.cpp | 4 ++-- engines/wintermute/ad/ad_inventory_box.h | 4 ++-- engines/wintermute/ad/ad_item.cpp | 4 ++-- engines/wintermute/ad/ad_item.h | 4 ++-- engines/wintermute/ad/ad_layer.cpp | 4 ++-- engines/wintermute/ad/ad_layer.h | 4 ++-- engines/wintermute/ad/ad_node_state.cpp | 4 ++-- engines/wintermute/ad/ad_node_state.h | 4 ++-- engines/wintermute/ad/ad_object.cpp | 4 ++-- engines/wintermute/ad/ad_object.h | 4 ++-- engines/wintermute/ad/ad_path.cpp | 4 ++-- engines/wintermute/ad/ad_path.h | 4 ++-- engines/wintermute/ad/ad_path_point.cpp | 4 ++-- engines/wintermute/ad/ad_path_point.h | 4 ++-- engines/wintermute/ad/ad_region.cpp | 4 ++-- engines/wintermute/ad/ad_region.h | 4 ++-- engines/wintermute/ad/ad_response.cpp | 4 ++-- engines/wintermute/ad/ad_response.h | 4 ++-- engines/wintermute/ad/ad_response_box.cpp | 8 ++++---- engines/wintermute/ad/ad_response_box.h | 4 ++-- engines/wintermute/ad/ad_response_context.cpp | 4 ++-- engines/wintermute/ad/ad_response_context.h | 4 ++-- engines/wintermute/ad/ad_rot_level.cpp | 4 ++-- engines/wintermute/ad/ad_rot_level.h | 4 ++-- engines/wintermute/ad/ad_scale_level.cpp | 4 ++-- engines/wintermute/ad/ad_scale_level.h | 4 ++-- engines/wintermute/ad/ad_scene.cpp | 6 +++--- engines/wintermute/ad/ad_scene.h | 4 ++-- engines/wintermute/ad/ad_scene_node.cpp | 4 ++-- engines/wintermute/ad/ad_scene_node.h | 2 +- engines/wintermute/ad/ad_scene_state.cpp | 4 ++-- engines/wintermute/ad/ad_scene_state.h | 4 ++-- engines/wintermute/ad/ad_sentence.cpp | 4 ++-- engines/wintermute/ad/ad_sentence.h | 4 ++-- engines/wintermute/ad/ad_sprite_set.cpp | 4 ++-- engines/wintermute/ad/ad_sprite_set.h | 4 ++-- engines/wintermute/ad/ad_talk_def.cpp | 4 ++-- engines/wintermute/ad/ad_talk_def.h | 4 ++-- engines/wintermute/ad/ad_talk_holder.cpp | 4 ++-- engines/wintermute/ad/ad_talk_holder.h | 4 ++-- engines/wintermute/ad/ad_talk_node.cpp | 4 ++-- engines/wintermute/ad/ad_talk_node.h | 4 ++-- engines/wintermute/ad/ad_types.h | 4 ++-- engines/wintermute/ad/ad_waypoint_group.cpp | 4 ++-- engines/wintermute/ad/ad_waypoint_group.h | 4 ++-- 53 files changed, 108 insertions(+), 108 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index aa148c9c85..e180499ee0 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -45,7 +45,7 @@ #include "engines/wintermute/base/particles/part_emitter.h" #include "engines/wintermute/base/base_engine.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdActor, false) @@ -1457,4 +1457,4 @@ bool AdActor::playAnim(const char *filename) { return AdTalkHolder::playAnim(filename); } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index 0c6334ac9d..4bc1bae37f 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -38,7 +38,7 @@ #include "engines/wintermute/persistent.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { class AdSpriteSet; class AdPath; @@ -103,6 +103,6 @@ private: int _pFCount; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif // WINTERMUTE_ADACTOR_H diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index e6fde43697..5bf03d6062 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -52,7 +52,7 @@ #include "engines/wintermute/base/particles/part_emitter.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdEntity, false) @@ -1120,4 +1120,4 @@ bool AdEntity::setSprite(const char *filename) { } } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_entity.h b/engines/wintermute/ad/ad_entity.h index 9931327916..2178563534 100644 --- a/engines/wintermute/ad/ad_entity.h +++ b/engines/wintermute/ad/ad_entity.h @@ -31,7 +31,7 @@ #include "engines/wintermute/ad/ad_talk_holder.h" -namespace WinterMute { +namespace Wintermute { class VideoTheoraPlayer; class AdEntity : public AdTalkHolder { public: @@ -63,6 +63,6 @@ public: }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 3bda534a04..2971cdab00 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -62,7 +62,7 @@ #include "engines/wintermute/platform_osystem.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdGame, true) @@ -2279,4 +2279,4 @@ bool AdGame::onScriptShutdown(ScScript *script) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index 080aea40aa..5707ec48fd 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -31,7 +31,7 @@ #include "engines/wintermute/ad/ad_types.h" #include "engines/wintermute/base/base_game.h" -namespace WinterMute { +namespace Wintermute { class AdItem; class AdInventory; class AdSceneState; @@ -158,6 +158,6 @@ private: AdInventoryBox *_inventoryBox; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index 203a18ae32..282c37449b 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -32,7 +32,7 @@ #include "engines/wintermute/platform_osystem.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdInventory, false) @@ -133,4 +133,4 @@ bool AdInventory::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_inventory.h b/engines/wintermute/ad/ad_inventory.h index 9eff30454c..9a12eb1abe 100644 --- a/engines/wintermute/ad/ad_inventory.h +++ b/engines/wintermute/ad/ad_inventory.h @@ -31,7 +31,7 @@ #include "engines/wintermute/base/base_object.h" -namespace WinterMute { +namespace Wintermute { class AdItem; @@ -47,6 +47,6 @@ public: int _scrollOffset; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index 555fa8e5c2..fd49860a5c 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -41,7 +41,7 @@ #include "common/str.h" #include "common/rect.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdInventoryBox, false) @@ -385,4 +385,4 @@ bool AdInventoryBox::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_inventory_box.h b/engines/wintermute/ad/ad_inventory_box.h index 1857cd8f19..451ebf9635 100644 --- a/engines/wintermute/ad/ad_inventory_box.h +++ b/engines/wintermute/ad/ad_inventory_box.h @@ -32,7 +32,7 @@ #include "engines/wintermute/base/base_object.h" #include "common/rect.h" -namespace WinterMute { +namespace Wintermute { class UIButton; class UIWindow; @@ -60,6 +60,6 @@ private: int _itemWidth; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index cacafa826b..f5c8b16308 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -43,7 +43,7 @@ #include "engines/wintermute/base/scriptables/script_value.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdItem, false) @@ -810,4 +810,4 @@ bool AdItem::getExtendedFlag(const char *flagName) { } } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_item.h b/engines/wintermute/ad/ad_item.h index eaa6844fcd..e06266f8b7 100644 --- a/engines/wintermute/ad/ad_item.h +++ b/engines/wintermute/ad/ad_item.h @@ -32,7 +32,7 @@ #include "engines/wintermute/ad/ad_talk_holder.h" -namespace WinterMute { +namespace Wintermute { class AdItem : public AdTalkHolder { public: @@ -64,6 +64,6 @@ private: char *_amountString; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 5742c9fc85..2cec37bec1 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -38,7 +38,7 @@ #include "engines/wintermute/platform_osystem.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdLayer, false) @@ -563,4 +563,4 @@ bool AdLayer::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_layer.h b/engines/wintermute/ad/ad_layer.h index 6d1686e1a6..b01079c091 100644 --- a/engines/wintermute/ad/ad_layer.h +++ b/engines/wintermute/ad/ad_layer.h @@ -29,7 +29,7 @@ #ifndef WINTERMUTE_ADLAYER_H #define WINTERMUTE_ADLAYER_H -namespace WinterMute { +namespace Wintermute { class AdSceneNode; class AdLayer : public BaseObject { public: @@ -53,6 +53,6 @@ public: virtual const char *scToString(); }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index 4784d6d331..fb2dfed0f5 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -35,7 +35,7 @@ #include "engines/wintermute/platform_osystem.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdNodeState, false) @@ -193,4 +193,4 @@ bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool s return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_node_state.h b/engines/wintermute/ad/ad_node_state.h index ce15bc893f..0008d4b3ee 100644 --- a/engines/wintermute/ad/ad_node_state.h +++ b/engines/wintermute/ad/ad_node_state.h @@ -29,7 +29,7 @@ #ifndef WINTERMUTE_ADNODESTATE_H #define WINTERMUTE_ADNODESTATE_H -namespace WinterMute { +namespace Wintermute { class AdEntity; @@ -55,6 +55,6 @@ private: }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index aaf4c6db4a..59781087a3 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -52,7 +52,7 @@ #include "common/str.h" #include "common/util.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdObject, false) @@ -1296,4 +1296,4 @@ bool AdObject::updatePartEmitter() { return _partEmitter->update(); } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h index 8e4cb80742..9451707445 100644 --- a/engines/wintermute/ad/ad_object.h +++ b/engines/wintermute/ad/ad_object.h @@ -32,7 +32,7 @@ #include "engines/wintermute/ad/ad_types.h" #include "engines/wintermute/base/base_object.h" -namespace WinterMute { +namespace Wintermute { class AdWaypointGroup; class AdRegion; @@ -119,6 +119,6 @@ protected: bool getScale(float *scaleX, float *scaleY); }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index 89eb3f29fa..0c0ec63e0f 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -29,7 +29,7 @@ #include "engines/wintermute/ad/ad_path.h" #include "engines/wintermute/base/base_point.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdPath, false) @@ -117,4 +117,4 @@ bool AdPath::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_path.h b/engines/wintermute/ad/ad_path.h index 8622e6757c..b85e1fce7a 100644 --- a/engines/wintermute/ad/ad_path.h +++ b/engines/wintermute/ad/ad_path.h @@ -33,7 +33,7 @@ #include "engines/wintermute/coll_templ.h" #include "engines/wintermute/base/base.h" -namespace WinterMute { +namespace Wintermute { class BasePoint; class AdPath : public BaseClass { public: @@ -51,6 +51,6 @@ public: bool _ready; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_path_point.cpp b/engines/wintermute/ad/ad_path_point.cpp index d5d447eb9a..1fb954c668 100644 --- a/engines/wintermute/ad/ad_path_point.cpp +++ b/engines/wintermute/ad/ad_path_point.cpp @@ -29,7 +29,7 @@ #include "engines/wintermute/ad/ad_path_point.h" #include "engines/wintermute/base/base_persistence_manager.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdPathPoint, false) @@ -72,4 +72,4 @@ bool AdPathPoint::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_path_point.h b/engines/wintermute/ad/ad_path_point.h index ea0a5795d0..8201750cef 100644 --- a/engines/wintermute/ad/ad_path_point.h +++ b/engines/wintermute/ad/ad_path_point.h @@ -32,7 +32,7 @@ #include "engines/wintermute/persistent.h" #include "engines/wintermute/base/base_point.h" -namespace WinterMute { +namespace Wintermute { class AdPathPoint : public BasePoint { public: @@ -45,6 +45,6 @@ public: int _distance; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 5ecb24c5b7..3b9d4fadda 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -34,7 +34,7 @@ #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_file_manager.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdRegion, false) @@ -395,4 +395,4 @@ bool AdRegion::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_region.h b/engines/wintermute/ad/ad_region.h index 7ee36dc970..5c33291a88 100644 --- a/engines/wintermute/ad/ad_region.h +++ b/engines/wintermute/ad/ad_region.h @@ -31,7 +31,7 @@ #include "engines/wintermute/base/base_region.h" -namespace WinterMute { +namespace Wintermute { class AdRegion : public BaseRegion { public: @@ -53,6 +53,6 @@ public: virtual const char *scToString(); }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp index 9cfa181b1c..f7886bba5a 100644 --- a/engines/wintermute/ad/ad_response.cpp +++ b/engines/wintermute/ad/ad_response.cpp @@ -32,7 +32,7 @@ #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/utils/utils.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdResponse, false) @@ -143,4 +143,4 @@ bool AdResponse::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_response.h b/engines/wintermute/ad/ad_response.h index 0cb8f6628b..0678ef5a37 100644 --- a/engines/wintermute/ad/ad_response.h +++ b/engines/wintermute/ad/ad_response.h @@ -33,7 +33,7 @@ #include "engines/wintermute/base/base_object.h" #include "engines/wintermute/ad/ad_types.h" -namespace WinterMute { +namespace Wintermute { class BaseFont; class AdResponse : public BaseObject { public: @@ -56,6 +56,6 @@ public: }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 5f2a1dc825..d467509612 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -45,7 +45,7 @@ #include "engines/wintermute/wintermute.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdResponseBox, false) @@ -611,7 +611,7 @@ bool AdResponseBox::weedResponses() { } break; default: - debugC(kWinterMuteDebugGeneral, "AdResponseBox::WeedResponses - Unhandled enum"); + debugC(kWintermuteDebugGeneral, "AdResponseBox::WeedResponses - Unhandled enum"); break; } } @@ -641,7 +641,7 @@ bool AdResponseBox::handleResponse(AdResponse *response) { adGame->addGameResponse(response->_iD); break; default: - debugC(kWinterMuteDebugGeneral, "AdResponseBox::HandleResponse - Unhandled enum"); + debugC(kWintermuteDebugGeneral, "AdResponseBox::HandleResponse - Unhandled enum"); } return STATUS_OK; @@ -708,4 +708,4 @@ bool AdResponseBox::getObjects(BaseArray &objects, bool interactiveO return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_response_box.h b/engines/wintermute/ad/ad_response_box.h index c1f60ba6ae..99522f00f6 100644 --- a/engines/wintermute/ad/ad_response_box.h +++ b/engines/wintermute/ad/ad_response_box.h @@ -32,7 +32,7 @@ #include "engines/wintermute/base/base_object.h" -namespace WinterMute { +namespace Wintermute { class UIButton; class UIWindow; @@ -82,6 +82,6 @@ public: virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_response_context.cpp b/engines/wintermute/ad/ad_response_context.cpp index 175a7f8491..0a2eff842d 100644 --- a/engines/wintermute/ad/ad_response_context.cpp +++ b/engines/wintermute/ad/ad_response_context.cpp @@ -29,7 +29,7 @@ #include "engines/wintermute/ad/ad_response_context.h" #include "engines/wintermute/base/base_persistence_manager.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdResponseContext, false) @@ -68,4 +68,4 @@ void AdResponseContext::setContext(const char *context) { } } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_response_context.h b/engines/wintermute/ad/ad_response_context.h index d5c8bb3fa3..a630f975e4 100644 --- a/engines/wintermute/ad/ad_response_context.h +++ b/engines/wintermute/ad/ad_response_context.h @@ -32,7 +32,7 @@ #include "engines/wintermute/persistent.h" #include "engines/wintermute/base/base.h" -namespace WinterMute { +namespace Wintermute { class AdResponseContext : public BaseClass { public: @@ -45,6 +45,6 @@ public: }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index 28c37b5b81..487e1f7067 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -33,7 +33,7 @@ #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_file_manager.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdRotLevel, false) @@ -158,4 +158,4 @@ bool AdRotLevel::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_rot_level.h b/engines/wintermute/ad/ad_rot_level.h index 4339a379a5..7951c7562d 100644 --- a/engines/wintermute/ad/ad_rot_level.h +++ b/engines/wintermute/ad/ad_rot_level.h @@ -31,7 +31,7 @@ #include "engines/wintermute/base/base_object.h" -namespace WinterMute { +namespace Wintermute { class AdRotLevel : public BaseObject { public: @@ -44,6 +44,6 @@ public: bool loadBuffer(byte *buffer, bool complete = true); }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index 430be3559d..f3ec68dd64 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -32,7 +32,7 @@ #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_file_manager.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdScaleLevel, false) @@ -156,4 +156,4 @@ bool AdScaleLevel::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_scale_level.h b/engines/wintermute/ad/ad_scale_level.h index 5e84f8c9ce..41a2edf8c5 100644 --- a/engines/wintermute/ad/ad_scale_level.h +++ b/engines/wintermute/ad/ad_scale_level.h @@ -32,7 +32,7 @@ #include "engines/wintermute/base/base_object.h" -namespace WinterMute { +namespace Wintermute { class AdScaleLevel : public BaseObject { public: @@ -45,6 +45,6 @@ public: bool loadBuffer(byte *buffer, bool complete = true); }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index d99b6b7fb8..19968d41dc 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -60,7 +60,7 @@ #include "engines/wintermute/wintermute.h" #include -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdScene, false) @@ -2937,7 +2937,7 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOn } break; default: - debugC(kWinterMuteDebugGeneral, "AdScene::GetSceneObjects - Unhandled enum"); + debugC(kWintermuteDebugGeneral, "AdScene::GetSceneObjects - Unhandled enum"); break; } } @@ -2999,4 +2999,4 @@ bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_scene.h b/engines/wintermute/ad/ad_scene.h index 5c2f505001..20b3f5026d 100644 --- a/engines/wintermute/ad/ad_scene.h +++ b/engines/wintermute/ad/ad_scene.h @@ -31,7 +31,7 @@ #include "engines/wintermute/base/base_fader.h" -namespace WinterMute { +namespace Wintermute { class UIWindow; class AdObject; @@ -176,6 +176,6 @@ private: }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_scene_node.cpp b/engines/wintermute/ad/ad_scene_node.cpp index 87b2c25406..4f6acdbc95 100644 --- a/engines/wintermute/ad/ad_scene_node.cpp +++ b/engines/wintermute/ad/ad_scene_node.cpp @@ -29,7 +29,7 @@ #include "engines/wintermute/ad/ad_scene_node.h" #include "engines/wintermute/base/base_game.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdSceneNode, false) @@ -79,4 +79,4 @@ bool AdSceneNode::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_scene_node.h b/engines/wintermute/ad/ad_scene_node.h index b56c351bc8..8cc50b86c4 100644 --- a/engines/wintermute/ad/ad_scene_node.h +++ b/engines/wintermute/ad/ad_scene_node.h @@ -34,7 +34,7 @@ #include "engines/wintermute/ad/ad_region.h" // Added by ClassView #include "engines/wintermute/ad/ad_entity.h" -namespace WinterMute { +namespace Wintermute { class AdSceneNode : public BaseObject { public: diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index eafb1f96b6..4a85148540 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -32,7 +32,7 @@ #include "engines/wintermute/platform_osystem.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdSceneState, false) @@ -92,4 +92,4 @@ AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { } } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_scene_state.h b/engines/wintermute/ad/ad_scene_state.h index 8f1bdb8fd2..8298d23d76 100644 --- a/engines/wintermute/ad/ad_scene_state.h +++ b/engines/wintermute/ad/ad_scene_state.h @@ -33,7 +33,7 @@ #include "engines/wintermute/base/base.h" #include "engines/wintermute/coll_templ.h" -namespace WinterMute { +namespace Wintermute { class AdNodeState; class AdSceneState : public BaseClass { public: @@ -46,6 +46,6 @@ public: BaseArray _nodeStates; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index 60c4519823..0c3080c9cd 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -38,7 +38,7 @@ #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_file_manager.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdSentence, false) @@ -357,4 +357,4 @@ bool AdSentence::canSkip() { return (_gameRef->_timer - _startTime) > 300; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_sentence.h b/engines/wintermute/ad/ad_sentence.h index ae4ee793d5..85be09094c 100644 --- a/engines/wintermute/ad/ad_sentence.h +++ b/engines/wintermute/ad/ad_sentence.h @@ -36,7 +36,7 @@ #include "engines/wintermute/dctypes.h" // Added by ClassView #include "common/rect.h" -namespace WinterMute { +namespace Wintermute { class AdTalkDef; class BaseFont; class BaseSprite; @@ -80,6 +80,6 @@ private: }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index df10418d95..5b605d6e32 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -33,7 +33,7 @@ #include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/base/base_sprite.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdSpriteSet, false) @@ -353,4 +353,4 @@ bool AdSpriteSet::containsSprite(BaseSprite *sprite) { return false; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_sprite_set.h b/engines/wintermute/ad/ad_sprite_set.h index 555ab914cf..3855114850 100644 --- a/engines/wintermute/ad/ad_sprite_set.h +++ b/engines/wintermute/ad/ad_sprite_set.h @@ -32,7 +32,7 @@ #include "engines/wintermute/base/base_object.h" -namespace WinterMute { +namespace Wintermute { class BaseSprite; class AdSpriteSet : public BaseObject { public: @@ -48,6 +48,6 @@ public: BaseSprite *_sprites[NUM_DIRECTIONS]; }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 71d8d6b1c3..08136d787e 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -36,7 +36,7 @@ #include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/utils/utils.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdTalkDef, false) @@ -282,4 +282,4 @@ BaseSprite *AdTalkDef::getDefaultSprite(TDirection dir) { } } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_talk_def.h b/engines/wintermute/ad/ad_talk_def.h index 4d28881e97..f748aa4e7a 100644 --- a/engines/wintermute/ad/ad_talk_def.h +++ b/engines/wintermute/ad/ad_talk_def.h @@ -32,7 +32,7 @@ #include "engines/wintermute/coll_templ.h" #include "engines/wintermute/base/base_object.h" -namespace WinterMute { +namespace Wintermute { class AdTalkNode; class AdSpriteSet; class AdTalkDef : public BaseObject { @@ -53,6 +53,6 @@ public: virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index a5ab7f3a6d..165ee50270 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -37,7 +37,7 @@ #include "engines/wintermute/base/base_engine.h" #include "common/str.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdTalkHolder, false) @@ -399,4 +399,4 @@ bool AdTalkHolder::persist(BasePersistenceManager *persistMgr) { return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_talk_holder.h b/engines/wintermute/ad/ad_talk_holder.h index 2607fdd9da..906c469b32 100644 --- a/engines/wintermute/ad/ad_talk_holder.h +++ b/engines/wintermute/ad/ad_talk_holder.h @@ -31,7 +31,7 @@ #include "engines/wintermute/ad/ad_object.h" -namespace WinterMute { +namespace Wintermute { class AdTalkHolder : public AdObject { public: @@ -52,6 +52,6 @@ public: }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index 14c1c3f459..6d793f483c 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -33,7 +33,7 @@ #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/ad/ad_sprite_set.h" #include "engines/wintermute/utils/utils.h" -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdTalkNode, false) @@ -292,4 +292,4 @@ BaseSprite *AdTalkNode::getSprite(TDirection dir) { } } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_talk_node.h b/engines/wintermute/ad/ad_talk_node.h index 9e599b6af2..863f6d0a3b 100644 --- a/engines/wintermute/ad/ad_talk_node.h +++ b/engines/wintermute/ad/ad_talk_node.h @@ -32,7 +32,7 @@ #include "engines/wintermute/persistent.h" #include "engines/wintermute/base/base.h" -namespace WinterMute { +namespace Wintermute { class AdSpriteSet; class BaseSprite; class AdTalkNode : public BaseClass { @@ -58,6 +58,6 @@ public: }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif diff --git a/engines/wintermute/ad/ad_types.h b/engines/wintermute/ad/ad_types.h index 18892919c6..17152ca5e8 100644 --- a/engines/wintermute/ad/ad_types.h +++ b/engines/wintermute/ad/ad_types.h @@ -29,7 +29,7 @@ #ifndef WINTERMUTE_ADTYPES_H #define WINTERMUTE_ADTYPES_H -namespace WinterMute { +namespace Wintermute { typedef enum { GAME_NORMAL, @@ -102,6 +102,6 @@ typedef enum { GEOM_GENERIC } TGeomNodeType; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif // WINTERMUTE_ADTYPES_H diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 0f83c2c50b..1573f5914e 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -35,7 +35,7 @@ #include "engines/wintermute/base/base_file_manager.h" #include -namespace WinterMute { +namespace Wintermute { IMPLEMENT_PERSISTENT(AdWaypointGroup, false) @@ -267,4 +267,4 @@ bool AdWaypointGroup::mimic(AdWaypointGroup *wpt, float scale, int argX, int arg return STATUS_OK; } -} // end of namespace WinterMute +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_waypoint_group.h b/engines/wintermute/ad/ad_waypoint_group.h index 7d69ab8237..a83c942652 100644 --- a/engines/wintermute/ad/ad_waypoint_group.h +++ b/engines/wintermute/ad/ad_waypoint_group.h @@ -31,7 +31,7 @@ #include "engines/wintermute/base/base_object.h" -namespace WinterMute { +namespace Wintermute { class BasePoint; class AdWaypointGroup : public BaseObject { public: @@ -53,6 +53,6 @@ public: virtual bool scSetProperty(const char *name, ScValue *value); }; -} // end of namespace WinterMute +} // end of namespace Wintermute #endif -- cgit v1.2.3 From 2039ea6b8df36c960ff25ae56930357d40e95d1d Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 14:01:18 +0200 Subject: WINTERMUTE: Fix g++ warnings listed by LordHoto --- engines/wintermute/ad/ad_scene.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 19968d41dc..1e5754a778 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -1200,8 +1200,8 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { ////////////////////////////////////////////////////////////////////////// int AdScene::compareObjs(const void *obj1, const void *obj2) { - AdObject *object1 = *(AdObject **)obj1; - AdObject *object2 = *(AdObject **)obj2; + const AdObject *object1 = *(AdObject **)obj1; + const AdObject *object2 = *(AdObject **)obj2; if (object1->_posY < object2->_posY) { return -1; -- cgit v1.2.3 From 3dc5d32e8547c0bbccbb20d6a84ca5307d29ca5e Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 16:55:17 +0200 Subject: WINTERMUTE: Replace qsort with Common::sort --- engines/wintermute/ad/ad_scene.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 1e5754a778..b04f48f1fc 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -1164,7 +1164,7 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { } // sort by _posY - qsort(objects.getData(), objects.getSize(), sizeof(AdObject *), AdScene::compareObjs); + Common::sort(objects.begin(), objects.end(), AdScene::compareObjs); // display them for (int i = 0; i < objects.getSize(); i++) { @@ -2994,7 +2994,7 @@ bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, } // sort by _posY - qsort(objects.getData(), objects.getSize(), sizeof(AdObject *), AdScene::compareObjs); + Common::sort(objects.begin(), objects.end(), AdScene::compareObjs); return STATUS_OK; } -- cgit v1.2.3 From 2d70964e9ca159ffffcd71759d0fbdb2448d0c01 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 17:15:03 +0200 Subject: WINTERMUTE: Use tabs instead of spaces in ad_types.h --- engines/wintermute/ad/ad_types.h | 80 ++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_types.h b/engines/wintermute/ad/ad_types.h index 17152ca5e8..b8cae58c6d 100644 --- a/engines/wintermute/ad/ad_types.h +++ b/engines/wintermute/ad/ad_types.h @@ -32,74 +32,74 @@ namespace Wintermute { typedef enum { - GAME_NORMAL, - GAME_WAITING_RESPONSE + GAME_NORMAL, + GAME_WAITING_RESPONSE } TGameStateEx; typedef enum { - OBJECT_ENTITY, - OBJECT_REGION, - OBJECT_ACTOR, - OBJECT_NONE + OBJECT_ENTITY, + OBJECT_REGION, + OBJECT_ACTOR, + OBJECT_NONE } TObjectType; typedef enum { - ENTITY_NORMAL, - ENTITY_SOUND + ENTITY_NORMAL, + ENTITY_SOUND } TEntityType; typedef enum { - STATE_NONE, - STATE_IDLE, - STATE_PLAYING_ANIM, - STATE_READY, - STATE_FOLLOWING_PATH, - STATE_SEARCHING_PATH, - STATE_WAITING_PATH, - STATE_TURNING_LEFT, - STATE_TURNING_RIGHT, - STATE_TURNING, - STATE_TALKING, - STATE_DIRECT_CONTROL, - STATE_PLAYING_ANIM_SET + STATE_NONE, + STATE_IDLE, + STATE_PLAYING_ANIM, + STATE_READY, + STATE_FOLLOWING_PATH, + STATE_SEARCHING_PATH, + STATE_WAITING_PATH, + STATE_TURNING_LEFT, + STATE_TURNING_RIGHT, + STATE_TURNING, + STATE_TALKING, + STATE_DIRECT_CONTROL, + STATE_PLAYING_ANIM_SET } TObjectState; typedef enum { - DIRECT_WALK_NONE, - DIRECT_WALK_FW, - DIRECT_WALK_BK + DIRECT_WALK_NONE, + DIRECT_WALK_FW, + DIRECT_WALK_BK } TDirectWalkMode; typedef enum { - DIRECT_TURN_NONE, - DIRECT_TURN_CW, - DIRECT_TURN_CCW + DIRECT_TURN_NONE, + DIRECT_TURN_CW, + DIRECT_TURN_CCW } TDirectTurnMode; typedef enum { - RESPONSE_TEXT, - RESPONSE_ICON + RESPONSE_TEXT, + RESPONSE_ICON } TResponseStyle; typedef enum { - RESPONSE_ALWAYS, - RESPONSE_ONCE, - RESPONSE_ONCE_GAME + RESPONSE_ALWAYS, + RESPONSE_ONCE, + RESPONSE_ONCE_GAME } TResponseType; typedef enum { - TALK_SKIP_LEFT = 0, - TALK_SKIP_RIGHT = 1, - TALK_SKIP_BOTH = 2, - TALK_SKIP_NONE = 3 + TALK_SKIP_LEFT = 0, + TALK_SKIP_RIGHT = 1, + TALK_SKIP_BOTH = 2, + TALK_SKIP_NONE = 3 } TTalkSkipButton; typedef enum { - GEOM_WAYPOINT, - GEOM_WALKPLANE, - GEOM_BLOCKED, - GEOM_GENERIC + GEOM_WAYPOINT, + GEOM_WALKPLANE, + GEOM_BLOCKED, + GEOM_GENERIC } TGeomNodeType; } // end of namespace Wintermute -- cgit v1.2.3 From 2fd38f47e04430b8684502e625f87a04dd968def Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 18:25:24 +0200 Subject: WINTERMUTE: Replace col_templ's getSize with Common::Array::size() --- engines/wintermute/ad/ad_actor.cpp | 26 ++--- engines/wintermute/ad/ad_entity.cpp | 4 +- engines/wintermute/ad/ad_game.cpp | 120 ++++++++++--------- engines/wintermute/ad/ad_inventory.cpp | 6 +- engines/wintermute/ad/ad_inventory_box.cpp | 6 +- engines/wintermute/ad/ad_layer.cpp | 22 ++-- engines/wintermute/ad/ad_object.cpp | 44 +++---- engines/wintermute/ad/ad_path.cpp | 8 +- engines/wintermute/ad/ad_region.cpp | 7 +- engines/wintermute/ad/ad_response_box.cpp | 35 +++--- engines/wintermute/ad/ad_scene.cpp | 175 +++++++++++++--------------- engines/wintermute/ad/ad_scene_state.cpp | 4 +- engines/wintermute/ad/ad_sentence.cpp | 2 +- engines/wintermute/ad/ad_talk_def.cpp | 4 +- engines/wintermute/ad/ad_talk_holder.cpp | 24 ++-- engines/wintermute/ad/ad_waypoint_group.cpp | 6 +- 16 files changed, 239 insertions(+), 254 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index e180499ee0..dd50955b4c 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -98,17 +98,17 @@ AdActor::~AdActor() { _animSprite2 = NULL; // ref only - for (int i = 0; i < _talkSprites.getSize(); i++) { + for (uint32 i = 0; i < _talkSprites.size(); i++) { delete _talkSprites[i]; } _talkSprites.clear(); - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { delete _talkSpritesEx[i]; } _talkSpritesEx.clear(); - for (int i = 0; i < _anims.getSize(); i++) { + for (uint32 i = 0; i < _anims.size(); i++) { delete _anims[i]; _anims[i] = NULL; } @@ -1036,7 +1036,7 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *animName = stack->pop()->getString(); bool found = false; - for (int i = 0; i < _anims.getSize(); i++) { + for (int i = 0; i < _anims.size(); i++) { if (scumm_stricmp(_anims[i]->getName(), animName) == 0) { // invalidate sprites in use if (_anims[i]->containsSprite(_tempSprite2)) { @@ -1239,7 +1239,7 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { } // old way - if (_talkSprites.getSize() > 0 || _talkSpritesEx.getSize() > 0) { + if (_talkSprites.size() > 0 || _talkSpritesEx.size() > 0) { return getTalkStanceOld(stance); } @@ -1255,14 +1255,14 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { // not - get a random talk if (!ret) { BaseArray talkAnims; - for (int i = 0; i < _anims.getSize(); i++) { + for (int i = 0; i < _anims.size(); i++) { if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) { talkAnims.add(_anims[i]); } } - if (talkAnims.getSize() > 0) { - int rnd = BaseEngine::instance().randInt(0, talkAnims.getSize() - 1); + if (talkAnims.size() > 0) { + int rnd = BaseEngine::instance().randInt(0, talkAnims.size() - 1); ret = talkAnims[rnd]->getSprite(_dir); } else { if (_standSprite) { @@ -1284,7 +1284,7 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { if (stance != NULL) { // search special stances - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + for (int i = 0; i < _talkSpritesEx.size(); i++) { if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { ret = _talkSpritesEx[i]->getSprite(_dir); break; @@ -1292,7 +1292,7 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { } if (ret == NULL) { // search generic stances - for (int i = 0; i < _talkSprites.getSize(); i++) { + for (int i = 0; i < _talkSprites.size(); i++) { if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { ret = _talkSprites[i]->getSprite(_dir); break; @@ -1303,11 +1303,11 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { // not a valid stance? get a random one if (ret == NULL) { - if (_talkSprites.getSize() < 1) { + if (_talkSprites.size() < 1) { ret = _standSprite->getSprite(_dir); } else { // TODO: remember last - int rnd = BaseEngine::instance().randInt(0, _talkSprites.getSize() - 1); + int rnd = BaseEngine::instance().randInt(0, _talkSprites.size() - 1); ret = _talkSprites[rnd]->getSprite(_dir); } } @@ -1395,7 +1395,7 @@ int AdActor::getHeight() { ////////////////////////////////////////////////////////////////////////// AdSpriteSet *AdActor::getAnimByName(const Common::String &animName) { - for (int i = 0; i < _anims.getSize(); i++) { + for (int i = 0; i < _anims.size(); i++) { if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) { return _anims[i]; } diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 5bf03d6062..67a919dd6b 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -993,9 +993,7 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "WALK_TO_DIR=%d\n", (int)_walkToDir); } - int i; - - for (i = 0; i < _scripts.getSize(); i++) { + for (uint32 i = 0; i < _scripts.size(); i++) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 2971cdab00..f5d865d9f8 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -119,21 +119,19 @@ AdGame::~AdGame() { ////////////////////////////////////////////////////////////////////////// bool AdGame::cleanup() { - int i; - - for (i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { unregisterObject(_objects[i]); _objects[i] = NULL; } _objects.clear(); - for (i = 0; i < _dlgPendingBranches.getSize(); i++) { + for (uint32 i = 0; i < _dlgPendingBranches.size(); i++) { delete[] _dlgPendingBranches[i]; } _dlgPendingBranches.clear(); - for (i = 0; i < _speechDirs.getSize(); i++) { + for (uint32 i = 0; i < _speechDirs.size(); i++) { delete[] _speechDirs[i]; } _speechDirs.clear(); @@ -143,7 +141,7 @@ bool AdGame::cleanup() { _scene = NULL; // remove items - for (i = 0; i < _items.getSize(); i++) { + for (uint32 i = 0; i < _items.size(); i++) { _gameRef->unregisterObject(_items[i]); } _items.clear(); @@ -153,7 +151,7 @@ bool AdGame::cleanup() { delete _invObject; _invObject = NULL; - for (i = 0; i < _inventories.getSize(); i++) { + for (uint32 i = 0; i < _inventories.size(); i++) { delete _inventories[i]; } _inventories.clear(); @@ -184,17 +182,17 @@ bool AdGame::cleanup() { delete _sceneViewport; _sceneViewport = NULL; - for (i = 0; i < _sceneStates.getSize(); i++) { + for (uint32 i = 0; i < _sceneStates.size(); i++) { delete _sceneStates[i]; } _sceneStates.clear(); - for (i = 0; i < _responsesBranch.getSize(); i++) { + for (uint32 i = 0; i < _responsesBranch.size(); i++) { delete _responsesBranch[i]; } _responsesBranch.clear(); - for (i = 0; i < _responsesGame.getSize(); i++) { + for (uint32 i = 0; i < _responsesGame.size(); i++) { delete _responsesGame[i]; } _responsesGame.clear(); @@ -247,7 +245,7 @@ bool AdGame::removeObject(AdObject *object) { } } - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i] == object) { _objects.remove_at(i); break; @@ -276,7 +274,7 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) { if (_scene) { // reset objects - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { _objects[i]->reset(); } @@ -296,7 +294,7 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) { if (DID_SUCCEED(ret)) { // invalidate references to the original scene - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { _objects[i]->invalidateCurrRegions(); _objects[i]->_stickRegion = NULL; } @@ -321,7 +319,7 @@ void AdGame::addSentence(AdSentence *sentence) { ////////////////////////////////////////////////////////////////////////// bool AdGame::displaySentences(bool frozen) { - for (int i = 0; i < _sentences.getSize(); i++) { + for (uint32 i = 0; i < _sentences.size(); i++) { if (frozen && _sentences[i]->_freezable) { continue; } else { @@ -334,7 +332,7 @@ bool AdGame::displaySentences(bool frozen) { ////////////////////////////////////////////////////////////////////////// void AdGame::finishSentences() { - for (int i = 0; i < _sentences.getSize(); i++) { + for (uint32 i = 0; i < _sentences.size(); i++) { if (_sentences[i]->canSkip()) { _sentences[i]->_duration = 0; if (_sentences[i]->_sound) { @@ -489,7 +487,7 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdItem *item = NULL; if (val->isInt()) { int index = val->getInt(); - if (index >= 0 && index < _items.getSize()) { + if (index >= 0 && index < (int32)_items.size()) { item = _items[index]; } } else { @@ -585,13 +583,13 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (_responseBox) { _responseBox->weedResponses(); - if (_responseBox->_responses.getSize() == 0) { + if (_responseBox->_responses.size() == 0) { stack->pushNULL(); return STATUS_OK; } - if (_responseBox->_responses.getSize() == 1 && autoSelectLast) { + if (_responseBox->_responses.size() == 1 && autoSelectLast) { stack->pushInt(_responseBox->_responses[0]->_iD); _responseBox->handleResponse(_responseBox->_responses[0]); _responseBox->clearResponses(); @@ -618,7 +616,7 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->correctParams(0); if (_responseBox) { _responseBox->weedResponses(); - stack->pushInt(_responseBox->_responses.getSize()); + stack->pushInt(_responseBox->_responses.size()); } else { script->runtimeError("Game.GetNumResponses: response box is not defined"); stack->pushNULL(); @@ -670,8 +668,8 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetCurrentDlgBranch") == 0) { stack->correctParams(0); - if (_dlgPendingBranches.getSize() > 0) { - stack->pushString(_dlgPendingBranches[_dlgPendingBranches.getSize() - 1]); + if (_dlgPendingBranches.size() > 0) { + stack->pushString(_dlgPendingBranches[_dlgPendingBranches.size() - 1]); } else { stack->pushNULL(); } @@ -715,10 +713,10 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); if (!val->isNULL()) { - for (int i = 0; i < _inventories.getSize(); i++) { + for (uint32 i = 0; i < _inventories.size(); i++) { AdInventory *inv = _inventories[i]; - for (int j = 0; j < inv->_takenItems.getSize(); j++) { + for (uint32 j = 0; j < inv->_takenItems.size(); j++) { if (val->getNative() == inv->_takenItems[j]) { stack->pushBool(true); return STATUS_OK; @@ -1021,7 +1019,7 @@ ScValue *AdGame::scGetProperty(const char *name) { // TotalNumItems ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TotalNumItems") == 0) { - _scValue->setInt(_items.getSize()); + _scValue->setInt(_items.size()); return _scValue; } @@ -1071,7 +1069,7 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { } else { if (value->isNative()) { _selectedItem = NULL; - for (int i = 0; i < _items.getSize(); i++) { + for (uint32 i = 0; i < _items.size(); i++) { if (_items[i] == value->getNative()) { _selectedItem = (AdItem *)value->getNative(); break; @@ -1548,7 +1546,7 @@ bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { BaseParser parser; if (!merge) { - while (_items.getSize() > 0) { + while (_items.size() > 0) { deleteItem(_items[0]); } } @@ -1599,7 +1597,7 @@ AdSceneState *AdGame::getSceneState(const char *filename, bool saving) { } } - for (int i = 0; i < _sceneStates.getSize(); i++) { + for (uint32 i = 0; i < _sceneStates.size(); i++) { if (scumm_stricmp(_sceneStates[i]->_filename, filenameCor) == 0) { delete[] filenameCor; return _sceneStates[i]; @@ -1692,8 +1690,8 @@ bool AdGame::startDlgBranch(const char *branchName, const char *scriptName, cons bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { char *name = NULL; bool deleteName = false; - if (branchName == NULL && _dlgPendingBranches.getSize() > 0) { - name = _dlgPendingBranches[_dlgPendingBranches.getSize() - 1]; + if (branchName == NULL && _dlgPendingBranches.size() > 0) { + name = _dlgPendingBranches[_dlgPendingBranches.size() - 1]; } else { if (branchName != NULL) { name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; @@ -1710,24 +1708,24 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const int startIndex = -1; - for (int i = _dlgPendingBranches.getSize() - 1; i >= 0; i--) { + for (int i = _dlgPendingBranches.size() - 1; i >= 0; i--) { if (scumm_stricmp(name, _dlgPendingBranches[i]) == 0) { startIndex = i; break; } } if (startIndex >= 0) { - for (int i = startIndex; i < _dlgPendingBranches.getSize(); i++) { + for (uint32 i = startIndex; i < _dlgPendingBranches.size(); i++) { //ClearBranchResponses(_dlgPendingBranches[i]); delete[] _dlgPendingBranches[i]; _dlgPendingBranches[i] = NULL; } - _dlgPendingBranches.remove_at(startIndex, _dlgPendingBranches.getSize() - startIndex); + _dlgPendingBranches.remove_at(startIndex, _dlgPendingBranches.size() - startIndex); } // dialogue is over, forget selected responses - if (_dlgPendingBranches.getSize() == 0) { - for (int i = 0; i < _responsesBranch.getSize(); i++) { + if (_dlgPendingBranches.size() == 0) { + for (uint32 i = 0; i < _responsesBranch.size(); i++) { delete _responsesBranch[i]; } _responsesBranch.clear(); @@ -1743,7 +1741,7 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const ////////////////////////////////////////////////////////////////////////// bool AdGame::clearBranchResponses(char *name) { - for (int i = 0; i < _responsesBranch.getSize(); i++) { + for (uint32 i = 0; i < _responsesBranch.size(); i++) { if (scumm_stricmp(name, _responsesBranch[i]->_context) == 0) { delete _responsesBranch[i]; _responsesBranch.remove_at(i); @@ -1761,7 +1759,7 @@ bool AdGame::addBranchResponse(int id) { } AdResponseContext *r = new AdResponseContext(_gameRef); r->_id = id; - r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); + r->setContext(_dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL); _responsesBranch.add(r); return STATUS_OK; } @@ -1769,8 +1767,8 @@ bool AdGame::addBranchResponse(int id) { ////////////////////////////////////////////////////////////////////////// bool AdGame::branchResponseUsed(int id) { - char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - for (int i = 0; i < _responsesBranch.getSize(); i++) { + char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; + for (uint32 i = 0; i < _responsesBranch.size(); i++) { if (_responsesBranch[i]->_id == id) { if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { return true; @@ -1788,7 +1786,7 @@ bool AdGame::addGameResponse(int id) { } AdResponseContext *r = new AdResponseContext(_gameRef); r->_id = id; - r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); + r->setContext(_dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL); _responsesGame.add(r); return STATUS_OK; } @@ -1796,8 +1794,8 @@ bool AdGame::addGameResponse(int id) { ////////////////////////////////////////////////////////////////////////// bool AdGame::gameResponseUsed(int id) { - char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - for (int i = 0; i < _responsesGame.getSize(); i++) { + char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; + for (uint32 i = 0; i < _responsesGame.size(); i++) { AdResponseContext *respContext = _responsesGame[i]; if (respContext->_id == id) { if ((context == NULL && respContext->_context == NULL) || ((context != NULL && respContext->_context != NULL) && scumm_stricmp(context, respContext->_context) == 0)) { @@ -1811,9 +1809,9 @@ bool AdGame::gameResponseUsed(int id) { ////////////////////////////////////////////////////////////////////////// bool AdGame::resetResponse(int id) { - char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; + char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; - for (int i = 0; i < _responsesGame.getSize(); i++) { + for (uint32 i = 0; i < _responsesGame.size(); i++) { if (_responsesGame[i]->_id == id) { if ((context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(context, _responsesGame[i]->_context) == 0) { delete _responsesGame[i]; @@ -1823,7 +1821,7 @@ bool AdGame::resetResponse(int id) { } } - for (int i = 0; i < _responsesBranch.getSize(); i++) { + for (uint32 i = 0; i < _responsesBranch.size(); i++) { if (_responsesBranch[i]->_id == id) { if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { delete _responsesBranch[i]; @@ -1922,7 +1920,7 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { ////////////////////////////////////////////////////////////////////////// bool AdGame::registerInventory(AdInventory *inv) { - for (int i = 0; i < _inventories.getSize(); i++) { + for (uint32 i = 0; i < _inventories.size(); i++) { if (_inventories[i] == inv) { return STATUS_OK; } @@ -1935,7 +1933,7 @@ bool AdGame::registerInventory(AdInventory *inv) { ////////////////////////////////////////////////////////////////////////// bool AdGame::unregisterInventory(AdInventory *inv) { - for (int i = 0; i < _inventories.getSize(); i++) { + for (uint32 i = 0; i < _inventories.size(); i++) { if (_inventories[i] == inv) { unregisterObject(_inventories[i]); _inventories.remove_at(i); @@ -1947,11 +1945,11 @@ bool AdGame::unregisterInventory(AdInventory *inv) { ////////////////////////////////////////////////////////////////////////// bool AdGame::isItemTaken(char *itemName) { - for (int i = 0; i < _inventories.getSize(); i++) { - AdInventory *Inv = _inventories[i]; + for (uint32 i = 0; i < _inventories.size(); i++) { + AdInventory *inv = _inventories[i]; - for (int j = 0; j < Inv->_takenItems.getSize(); j++) { - if (scumm_stricmp(itemName, Inv->_takenItems[j]->getName()) == 0) { + for (uint32 j = 0; j < inv->_takenItems.size(); j++) { + if (scumm_stricmp(itemName, inv->_takenItems[j]->getName()) == 0) { return true; } } @@ -1961,7 +1959,7 @@ bool AdGame::isItemTaken(char *itemName) { ////////////////////////////////////////////////////////////////////////// AdItem *AdGame::getItemByName(const char *name) { - for (int i = 0; i < _items.getSize(); i++) { + for (uint32 i = 0; i < _items.size(); i++) { if (scumm_stricmp(_items[i]->getName(), name) == 0) { return _items[i]; } @@ -1980,31 +1978,31 @@ bool AdGame::addItem(AdItem *item) { ////////////////////////////////////////////////////////////////////////// bool AdGame::resetContent() { // clear pending dialogs - for (int i = 0; i < _dlgPendingBranches.getSize(); i++) { + for (uint32 i = 0; i < _dlgPendingBranches.size(); i++) { delete[] _dlgPendingBranches[i]; } _dlgPendingBranches.clear(); // clear inventories - for (int i = 0; i < _inventories.getSize(); i++) { + for (uint32 i = 0; i < _inventories.size(); i++) { _inventories[i]->_takenItems.clear(); } // clear scene states - for (int i = 0; i < _sceneStates.getSize(); i++) { + for (uint32 i = 0; i < _sceneStates.size(); i++) { delete _sceneStates[i]; } _sceneStates.clear(); // clear once responses - for (int i = 0; i < _responsesBranch.getSize(); i++) { + for (uint32 i = 0; i < _responsesBranch.size(); i++) { delete _responsesBranch[i]; } _responsesBranch.clear(); // clear once game responses - for (int i = 0; i < _responsesGame.getSize(); i++) { + for (uint32 i = 0; i < _responsesGame.size(); i++) { delete _responsesGame[i]; } _responsesGame.clear(); @@ -2032,12 +2030,12 @@ bool AdGame::deleteItem(AdItem *item) { _scene->handleItemAssociations(item->getName(), false); // remove from all inventories - for (int i = 0; i < _inventories.getSize(); i++) { + for (uint32 i = 0; i < _inventories.size(); i++) { _inventories[i]->removeItem(item); } // remove object - for (int i = 0; i < _items.getSize(); i++) { + for (uint32 i = 0; i < _items.size(); i++) { if (_items[i] == item) { unregisterObject(_items[i]); _items.remove_at(i); @@ -2061,7 +2059,7 @@ bool AdGame::addSpeechDir(const char *dir) { strcat(temp, "\\"); } - for (int i = 0; i < _speechDirs.getSize(); i++) { + for (uint32 i = 0; i < _speechDirs.size(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { delete[] temp; return STATUS_OK; @@ -2086,7 +2084,7 @@ bool AdGame::removeSpeechDir(const char *dir) { } bool found = false; - for (int i = 0; i < _speechDirs.getSize(); i++) { + for (uint32 i = 0; i < _speechDirs.size(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { delete[] _speechDirs[i]; _speechDirs.remove_at(i); @@ -2104,7 +2102,7 @@ bool AdGame::removeSpeechDir(const char *dir) { char *AdGame::findSpeechFile(char *stringID) { char *ret = new char[MAX_PATH_LENGTH]; - for (int i = 0; i < _speechDirs.getSize(); i++) { + for (uint32 i = 0; i < _speechDirs.size(); i++) { sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); if (BaseFileManager::getEngineInstance()->hasFile(ret)) { return ret; diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index 282c37449b..44b2dc0508 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -60,7 +60,7 @@ bool AdInventory::insertItem(const char *name, const char *insertAfter) { } int insertIndex = -1; - for (int i = 0; i < _takenItems.getSize(); i++) { + for (uint32 i = 0; i < _takenItems.size(); i++) { if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { _takenItems.remove_at(i); i--; @@ -88,7 +88,7 @@ bool AdInventory::removeItem(const char *name) { return STATUS_FAILED; } - for (int i = 0; i < _takenItems.getSize(); i++) { + for (uint32 i = 0; i < _takenItems.size(); i++) { if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { ((AdGame *)_gameRef)->_selectedItem = NULL; @@ -109,7 +109,7 @@ bool AdInventory::removeItem(AdItem *item) { return STATUS_FAILED; } - for (int i = 0; i < _takenItems.getSize(); i++) { + for (uint32 i = 0; i < _takenItems.size(); i++) { if (_takenItems[i] == item) { if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { ((AdGame *)_gameRef)->_selectedItem = NULL; diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index fd49860a5c..ad679007df 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -113,7 +113,7 @@ bool AdInventoryBox::display() { if (_window) { _window->enableWidget("prev", _scrollOffset > 0); - _window->enableWidget("next", _scrollOffset + itemsX * itemsY < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()); + _window->enableWidget("next", _scrollOffset + itemsX * itemsY < (int32)adGame->_inventoryOwner->getInventory()->_takenItems.size()); } @@ -142,7 +142,7 @@ bool AdInventoryBox::display() { int xxx = rect.left; for (int i = 0; i < itemsX; i++) { int itemIndex = _scrollOffset + j * itemsX + i; - if (itemIndex >= 0 && itemIndex < adGame->_inventoryOwner->getInventory()->_takenItems.getSize()) { + if (itemIndex >= 0 && itemIndex < (int32)adGame->_inventoryOwner->getInventory()->_takenItems.size()) { AdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex]; if (item != ((AdGame *)_gameRef)->_selectedItem || !_hideSelected) { item->update(); @@ -321,7 +321,7 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { _visible = alwaysVisible; if (_window) { - for (int i = 0; i < _window->_widgets.getSize(); i++) { + for (uint32 i = 0; i < _window->_widgets.size(); i++) { if (!_window->_widgets[i]->_listenerObject) { _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); } diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 2cec37bec1..709ab50b58 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -53,7 +53,7 @@ AdLayer::AdLayer(BaseGame *inGame) : BaseObject(inGame) { ////////////////////////////////////////////////////////////////////////// AdLayer::~AdLayer() { - for (int i = 0; i < _nodes.getSize(); i++) { + for (uint32 i = 0; i < _nodes.size(); i++) { delete _nodes[i]; } _nodes.clear(); @@ -243,7 +243,7 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (val->_type == VAL_INT) { node = val->getInt(); } else { // get by name - for (int i = 0; i < _nodes.getSize(); i++) { + for (uint32 i = 0; i < _nodes.size(); i++) { if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->getName(), val->getString()) == 0) || (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->getName(), val->getString()) == 0)) { node = i; @@ -252,7 +252,7 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } - if (node < 0 || node >= _nodes.getSize()) { + if (node < 0 || node >= (int32)_nodes.size()) { stack->pushNULL(); } else { switch (_nodes[node]->_type) { @@ -323,7 +323,7 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (index < 0) { index = 0; } - if (index <= _nodes.getSize() - 1) { + if (index <= (int32)_nodes.size() - 1) { _nodes.insert_at(index, node); } else { _nodes.add(node); @@ -342,7 +342,7 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdSceneNode *toDelete = NULL; if (val->isNative()) { BaseScriptable *temp = val->getNative(); - for (int i = 0; i < _nodes.getSize(); i++) { + for (uint32 i = 0; i < _nodes.size(); i++) { if (_nodes[i]->_region == temp || _nodes[i]->_entity == temp) { toDelete = _nodes[i]; break; @@ -350,7 +350,7 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } else { int index = val->getInt(); - if (index >= 0 && index < _nodes.getSize()) { + if (index >= 0 && index < (int32)_nodes.size()) { toDelete = _nodes[index]; } } @@ -359,7 +359,7 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, return STATUS_OK; } - for (int i = 0; i < _nodes.getSize(); i++) { + for (uint32 i = 0; i < _nodes.size(); i++) { if (_nodes[i] == toDelete) { delete _nodes[i]; _nodes[i] = NULL; @@ -391,7 +391,7 @@ ScValue *AdLayer::scGetProperty(const char *name) { // NumNodes (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "NumNodes") == 0) { - _scValue->setInt(_nodes.getSize()); + _scValue->setInt(_nodes.size()); return _scValue; } @@ -516,9 +516,7 @@ bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "CLOSE_UP=%s\n", _closeUp ? "TRUE" : "FALSE"); } - int i; - - for (i = 0; i < _scripts.getSize(); i++) { + for (uint32 i = 0; i < _scripts.size(); i++) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } @@ -526,7 +524,7 @@ bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { _scProp->saveAsText(buffer, indent + 2); } - for (i = 0; i < _nodes.getSize(); i++) { + for (uint32 i = 0; i < _nodes.size(); i++) { switch (_nodes[i]->_type) { case OBJECT_ENTITY: _nodes[i]->_entity->saveAsText(buffer, indent + 2); diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index 59781087a3..a02decebdb 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -143,12 +143,12 @@ AdObject::~AdObject() { } - for (int i = 0; i < _attachmentsPre.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { _gameRef->unregisterObject(_attachmentsPre[i]); } _attachmentsPre.clear(); - for (int i = 0; i < _attachmentsPost.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { _gameRef->unregisterObject(_attachmentsPost[i]); } _attachmentsPost.clear(); @@ -305,14 +305,14 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack AdLayer *main = ((AdGame *)_gameRef)->_scene->_mainLayer; bool regFound = false; - int i; + uint32 i; ScValue *val = stack->pop(); if (val->isNULL() || !main) { _stickRegion = NULL; regFound = true; } else if (val->isString()) { const char *regionName = val->getString(); - for (i = 0; i < main->_nodes.getSize(); i++) { + for (i = 0; i < main->_nodes.size(); i++) { if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region->getName() && scumm_stricmp(main->_nodes[i]->_region->getName(), regionName) == 0) { _stickRegion = main->_nodes[i]->_region; regFound = true; @@ -322,7 +322,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } else if (val->isNative()) { BaseScriptable *obj = val->getNative(); - for (i = 0; i < main->_nodes.getSize(); i++) { + for (i = 0; i < main->_nodes.size(); i++) { if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region == obj) { _stickRegion = main->_nodes[i]->_region; regFound = true; @@ -446,7 +446,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } else { stack->pushNULL(); } - } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) { + } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= (int32)_inventory->_takenItems.size()) { stack->pushNULL(); } else { stack->pushNative(_inventory->_takenItems[val->getInt()], true); @@ -468,7 +468,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); if (!val->isNULL()) { - for (int i = 0; i < _inventory->_takenItems.getSize(); i++) { + for (uint32 i = 0; i < _inventory->_takenItems.size(); i++) { if (val->getNative() == _inventory->_takenItems[i]) { stack->pushBool(true); return STATUS_OK; @@ -563,7 +563,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack bool found = false; if (val->isNative()) { BaseScriptable *obj = val->getNative(); - for (int i = 0; i < _attachmentsPre.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { if (_attachmentsPre[i] == obj) { found = true; _gameRef->unregisterObject(_attachmentsPre[i]); @@ -571,7 +571,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack i--; } } - for (int i = 0; i < _attachmentsPost.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { if (_attachmentsPost[i] == obj) { found = true; _gameRef->unregisterObject(_attachmentsPost[i]); @@ -581,7 +581,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } } else { const char *attachmentName = val->getString(); - for (int i = 0; i < _attachmentsPre.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { found = true; _gameRef->unregisterObject(_attachmentsPre[i]); @@ -589,7 +589,7 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack i--; } } - for (int i = 0; i < _attachmentsPost.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { found = true; _gameRef->unregisterObject(_attachmentsPost[i]); @@ -614,13 +614,13 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (val->isInt()) { int index = val->getInt(); int currIndex = 0; - for (int i = 0; i < _attachmentsPre.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { if (currIndex == index) { ret = _attachmentsPre[i]; } currIndex++; } - for (int i = 0; i < _attachmentsPost.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { if (currIndex == index) { ret = _attachmentsPost[i]; } @@ -628,14 +628,14 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } } else { const char *attachmentName = val->getString(); - for (int i = 0; i < _attachmentsPre.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { ret = _attachmentsPre[i]; break; } } if (!ret) { - for (int i = 0; i < _attachmentsPost.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { ret = _attachmentsPre[i]; break; @@ -737,7 +737,7 @@ ScValue *AdObject::scGetProperty(const char *name) { // NumItems (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "NumItems") == 0) { - _scValue->setInt(getInventory()->_takenItems.getSize()); + _scValue->setInt(getInventory()->_takenItems.size()); return _scValue; } @@ -758,7 +758,7 @@ ScValue *AdObject::scGetProperty(const char *name) { // NumAttachments (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "NumAttachments") == 0) { - _scValue->setInt(_attachmentsPre.getSize() + _attachmentsPost.getSize()); + _scValue->setInt(_attachmentsPre.size() + _attachmentsPost.size()); return _scValue; } else { return BaseObject::scGetProperty(name); @@ -865,7 +865,7 @@ int AdObject::getHeight() { } else { BaseFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; int ret = 0; - for (int i = 0; i < frame->_subframes.getSize(); i++) { + for (uint32 i = 0; i < frame->_subframes.size(); i++) { ret = MAX(ret, frame->_subframes[i]->_hotspotY); } @@ -1201,10 +1201,10 @@ bool AdObject::getScale(float *scaleX, float *scaleY) { ////////////////////////////////////////////////////////////////////////// bool AdObject::updateSpriteAttachments() { - for (int i = 0; i < _attachmentsPre.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { _attachmentsPre[i]->update(); } - for (int i = 0; i < _attachmentsPost.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { _attachmentsPost[i]->update(); } return STATUS_OK; @@ -1213,11 +1213,11 @@ bool AdObject::updateSpriteAttachments() { ////////////////////////////////////////////////////////////////////////// bool AdObject::displaySpriteAttachments(bool preDisplay) { if (preDisplay) { - for (int i = 0; i < _attachmentsPre.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { displaySpriteAttachment(_attachmentsPre[i]); } } else { - for (int i = 0; i < _attachmentsPost.getSize(); i++) { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { displaySpriteAttachment(_attachmentsPost[i]); } } diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index 0c0ec63e0f..21b68f4d48 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -48,7 +48,7 @@ AdPath::~AdPath() { ////////////////////////////////////////////////////////////////////////// void AdPath::reset() { - for (int i = 0; i < _points.getSize(); i++) { + for (uint32 i = 0; i < _points.size(); i++) { delete _points[i]; } @@ -60,7 +60,7 @@ void AdPath::reset() { ////////////////////////////////////////////////////////////////////////// BasePoint *AdPath::getFirst() { - if (_points.getSize() > 0) { + if (_points.size() > 0) { _currIndex = 0; return _points[_currIndex]; } else { @@ -72,7 +72,7 @@ BasePoint *AdPath::getFirst() { ////////////////////////////////////////////////////////////////////////// BasePoint *AdPath::getNext() { _currIndex++; - if (_currIndex < _points.getSize()) { + if (_currIndex < (int32)_points.size()) { return _points[_currIndex]; } else { return NULL; @@ -82,7 +82,7 @@ BasePoint *AdPath::getNext() { ////////////////////////////////////////////////////////////////////////// BasePoint *AdPath::getCurrent() { - if (_currIndex >= 0 && _currIndex < _points.getSize()) { + if (_currIndex >= 0 && _currIndex < (int32)_points.size()) { return _points[_currIndex]; } else { return NULL; diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 3b9d4fadda..3e5f91524d 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -128,7 +128,7 @@ bool AdRegion::loadBuffer(byte *buffer, bool complete) { buffer = params; } - for (int i = 0; i < _points.getSize(); i++) { + for (uint32 i = 0; i < _points.size(); i++) { delete _points[i]; } _points.clear(); @@ -362,8 +362,7 @@ bool AdRegion::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alpha)); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - int i; - for (i = 0; i < _scripts.getSize(); i++) { + for (uint32 i = 0; i < _scripts.size(); i++) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } @@ -371,7 +370,7 @@ bool AdRegion::saveAsText(BaseDynamicBuffer *buffer, int indent) { _scProp->saveAsText(buffer, indent + 2); } - for (i = 0; i < _points.getSize(); i++) { + for (uint32 i = 0; i < _points.size(); i++) { buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); } diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index d467509612..76510e2f3e 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -98,7 +98,7 @@ AdResponseBox::~AdResponseBox() { ////////////////////////////////////////////////////////////////////////// void AdResponseBox::clearResponses() { - for (int i = 0; i < _responses.getSize(); i++) { + for (uint32 i = 0; i < _responses.size(); i++) { delete _responses[i]; } _responses.clear(); @@ -107,7 +107,7 @@ void AdResponseBox::clearResponses() { ////////////////////////////////////////////////////////////////////////// void AdResponseBox::clearButtons() { - for (int i = 0; i < _respButtons.getSize(); i++) { + for (uint32 i = 0; i < _respButtons.size(); i++) { delete _respButtons[i]; } _respButtons.clear(); @@ -116,7 +116,7 @@ void AdResponseBox::clearButtons() { ////////////////////////////////////////////////////////////////////////// bool AdResponseBox::invalidateButtons() { - for (int i = 0; i < _respButtons.getSize(); i++) { + for (uint32 i = 0; i < _respButtons.size(); i++) { _respButtons[i]->_image = NULL; _respButtons[i]->_cursor = NULL; _respButtons[i]->_font = NULL; @@ -133,7 +133,7 @@ bool AdResponseBox::createButtons() { clearButtons(); _scrollOffset = 0; - for (int i = 0; i < _responses.getSize(); i++) { + for (uint32 i = 0; i < _responses.size(); i++) { UIButton *btn = new UIButton(_gameRef); if (btn) { btn->_parent = _window; @@ -363,7 +363,7 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { } if (_window) { - for (int i = 0; i < _window->_widgets.getSize(); i++) { + for (uint32 i = 0; i < _window->_widgets.size(); i++) { if (!_window->_widgets[i]->_listenerObject) { _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); } @@ -447,7 +447,8 @@ bool AdResponseBox::display() { //_window->display(); } - int xxx, yyy, i; + int xxx, yyy; + uint32 i; xxx = rect.left; yyy = rect.top; @@ -455,7 +456,7 @@ bool AdResponseBox::display() { // shift down if needed if (!_horizontal) { int totalHeight = 0; - for (i = 0; i < _respButtons.getSize(); i++) { + for (i = 0; i < _respButtons.size(); i++) { totalHeight += (_respButtons[i]->_height + _spacing); } totalHeight -= _spacing; @@ -481,7 +482,7 @@ bool AdResponseBox::display() { // prepare response buttons bool scrollNeeded = false; - for (i = _scrollOffset; i < _respButtons.getSize(); i++) { + for (i = _scrollOffset; i < _respButtons.size(); i++) { if ((_horizontal && xxx + _respButtons[i]->_width > rect.right) || (!_horizontal && yyy + _respButtons[i]->_height > rect.bottom)) { @@ -523,7 +524,7 @@ bool AdResponseBox::display() { // display response buttons - for (i = _scrollOffset; i < _respButtons.getSize(); i++) { + for (i = _scrollOffset; i < _respButtons.size(); i++) { _respButtons[i]->display(); } @@ -593,7 +594,7 @@ bool AdResponseBox::persist(BasePersistenceManager *persistMgr) { bool AdResponseBox::weedResponses() { AdGame *adGame = (AdGame *)_gameRef; - for (int i = 0; i < _responses.getSize(); i++) { + for (uint32 i = 0; i < _responses.size(); i++) { switch (_responses[i]->_responseType) { case RESPONSE_ONCE: if (adGame->branchResponseUsed(_responses[i]->_iD)) { @@ -653,13 +654,13 @@ BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) { BaseArray objects; getObjects(objects, true); - if (objects.getSize() == 0) { + if (objects.size() == 0) { return NULL; } else { if (currObject != NULL) { - for (int i = 0; i < objects.getSize(); i++) { + for (uint32 i = 0; i < objects.size(); i++) { if (objects[i] == currObject) { - if (i < objects.getSize() - 1) { + if (i < objects.size() - 1) { return objects[i + 1]; } else { break; @@ -677,11 +678,11 @@ BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { BaseArray objects; getObjects(objects, true); - if (objects.getSize() == 0) { + if (objects.size() == 0) { return NULL; } else { if (currObject != NULL) { - for (int i = objects.getSize() - 1; i >= 0; i--) { + for (int i = objects.size() - 1; i >= 0; i--) { if (objects[i] == currObject) { if (i > 0) { return objects[i - 1]; @@ -691,14 +692,14 @@ BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { } } } - return objects[objects.getSize() - 1]; + return objects[objects.size() - 1]; } return NULL; } ////////////////////////////////////////////////////////////////////////// bool AdResponseBox::getObjects(BaseArray &objects, bool interactiveOnly) { - for (int i = 0; i < _respButtons.getSize(); i++) { + for (uint32 i = 0; i < _respButtons.size(); i++) { objects.add(_respButtons[i]); } if (_window) { diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index b04f48f1fc..176604b75f 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -141,43 +141,41 @@ void AdScene::cleanup() { _mainLayer = NULL; // reference only - int i; - delete _shieldWindow; _shieldWindow = NULL; _gameRef->unregisterObject(_fader); _fader = NULL; - for (i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { _gameRef->unregisterObject(_layers[i]); } _layers.clear(); - for (i = 0; i < _waypointGroups.getSize(); i++) { + for (uint32 i = 0; i < _waypointGroups.size(); i++) { _gameRef->unregisterObject(_waypointGroups[i]); } _waypointGroups.clear(); - for (i = 0; i < _scaleLevels.getSize(); i++) { + for (uint32 i = 0; i < _scaleLevels.size(); i++) { _gameRef->unregisterObject(_scaleLevels[i]); } _scaleLevels.clear(); - for (i = 0; i < _rotLevels.getSize(); i++) { + for (uint32 i = 0; i < _rotLevels.size(); i++) { _gameRef->unregisterObject(_rotLevels[i]); } _rotLevels.clear(); - for (i = 0; i < _pfPath.getSize(); i++) { + for (uint32 i = 0; i < _pfPath.size(); i++) { delete _pfPath[i]; } _pfPath.clear(); _pfPointsNum = 0; - for (i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { _gameRef->unregisterObject(_objects[i]); } _objects.clear(); @@ -203,7 +201,6 @@ bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObje _pfTargetPath->setReady(false); // prepare working path - int i; pfPointsStart(); // first point @@ -239,7 +236,7 @@ bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObje pfPointsAdd(target.x, target.y, INT_MAX); // active waypoints - for (i = 0; i < _waypointGroups.getSize(); i++) { + for (uint32 i = 0; i < _waypointGroups.size(); i++) { if (_waypointGroups[i]->_active) { pfAddWaypointGroup(_waypointGroups[i], requester); } @@ -247,13 +244,13 @@ bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObje // free waypoints - for (i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentWptGroup) { pfAddWaypointGroup(_objects[i]->_currentWptGroup, requester); } } AdGame *adGame = (AdGame *)_gameRef; - for (i = 0; i < adGame->_objects.getSize(); i++) { + for (uint32 i = 0; i < adGame->_objects.size(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentWptGroup) { pfAddWaypointGroup(adGame->_objects[i]->_currentWptGroup, requester); } @@ -270,7 +267,7 @@ void AdScene::pfAddWaypointGroup(AdWaypointGroup *wpt, BaseObject *requester) { return; } - for (int i = 0; i < wpt->_points.getSize(); i++) { + for (uint32 i = 0; i < wpt->_points.size(); i++) { if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) { continue; } @@ -287,7 +284,7 @@ float AdScene::getZoomAt(int x, int y) { bool found = false; if (_mainLayer) { - for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_blocked && node->_region->pointInRegion(x, y)) { if (node->_region->_zoom != 0) { @@ -320,7 +317,7 @@ uint32 AdScene::getAlphaAt(int x, int y, bool colorCheck) { } if (_mainLayer) { - for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { if (!node->_region->_blocked) { @@ -338,9 +335,8 @@ uint32 AdScene::getAlphaAt(int x, int y, bool colorCheck) { bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *requester) { bool ret = true; - if (checkFreeObjects) { - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { return true; @@ -348,7 +344,7 @@ bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *reque } } AdGame *adGame = (AdGame *)_gameRef; - for (int i = 0; i < adGame->_objects.getSize(); i++) { + for (uint32 i = 0; i < adGame->_objects.size(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { return true; @@ -359,7 +355,7 @@ bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *reque if (_mainLayer) { - for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { + for (uint32 i = 0; i < _mainLayer->_nodes.size(); i++) { AdSceneNode *node = _mainLayer->_nodes[i]; /* if (Node->_type == OBJECT_REGION && Node->_region->_active && Node->_region->_blocked && Node->_region->PointInRegion(X, Y)) @@ -387,7 +383,7 @@ bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requ bool ret = false; if (checkFreeObjects) { - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { return false; @@ -395,7 +391,7 @@ bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requ } } AdGame *adGame = (AdGame *)_gameRef; - for (int i = 0; i < adGame->_objects.getSize(); i++) { + for (uint32 i = 0; i < adGame->_objects.size(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { return false; @@ -406,7 +402,7 @@ bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requ if (_mainLayer) { - for (int i = 0; i < _mainLayer->_nodes.getSize(); i++) { + for (uint32 i = 0; i < _mainLayer->_nodes.size(); i++) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { if (node->_region->_blocked) { @@ -907,7 +903,6 @@ bool AdScene::traverseNodes(bool doUpdate) { return STATUS_OK; } - int j, k; AdGame *adGame = (AdGame *)_gameRef; @@ -995,7 +990,7 @@ bool AdScene::traverseNodes(bool doUpdate) { /* int mainOffsetX = 0; */ /* int mainOffsetY = 0; */ - for (j = 0; j < _layers.getSize(); j++) { + for (uint32 j = 0; j < _layers.size(); j++) { if (!_layers[j]->_active) { continue; } @@ -1033,7 +1028,7 @@ bool AdScene::traverseNodes(bool doUpdate) { // for each node - for (k = 0; k < _layers[j]->_nodes.getSize(); k++) { + for (uint32 k = 0; k < _layers[j]->_nodes.size(); k++) { AdSceneNode *node = _layers[j]->_nodes[k]; switch (node->_type) { case OBJECT_ENTITY: @@ -1112,7 +1107,7 @@ bool AdScene::updateFreeObjects() { // *** update all active objects // is3DSet = false; - for (int i = 0; i < adGame->_objects.getSize(); i++) { + for (uint32 i = 0; i < adGame->_objects.size(); i++) { if (!adGame->_objects[i]->_active) { continue; } @@ -1122,7 +1117,7 @@ bool AdScene::updateFreeObjects() { } - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (!_objects[i]->_active) { continue; } @@ -1148,7 +1143,7 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { AdObject *obj; // global objects - for (int i = 0; i < adGame->_objects.getSize(); i++) { + for (uint32 i = 0; i < adGame->_objects.size(); i++) { obj = adGame->_objects[i]; if (obj->_active && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { objects.add(obj); @@ -1156,7 +1151,7 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { } // scene objects - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { obj = _objects[i]; if (obj->_active && !obj->_editorOnly && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { objects.add(obj); @@ -1167,7 +1162,7 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { Common::sort(objects.begin(), objects.end(), AdScene::compareObjs); // display them - for (int i = 0; i < objects.getSize(); i++) { + for (uint32 i = 0; i < objects.size(); i++) { obj = objects[i]; if (display3DOnly && !obj->_is3D) { @@ -1186,7 +1181,7 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { // display design only objects if (!display3DOnly) { if (_gameRef->_editorMode && region == NULL) { - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_active && _objects[i]->_editorOnly) { _objects[i]->display(); _objects[i]->_drawn = true; @@ -1223,7 +1218,7 @@ bool AdScene::displayRegionContentOld(AdRegion *region) { int minY = INT_MAX; // global objects - for (int i = 0; i < adGame->_objects.getSize(); i++) { + for (uint32 i = 0; i < adGame->_objects.size(); i++) { if (adGame->_objects[i]->_active && !adGame->_objects[i]->_drawn && adGame->_objects[i]->_posY < minY && (adGame->_objects[i]->_stickRegion == region || region == NULL || (adGame->_objects[i]->_stickRegion == NULL && region->pointInRegion(adGame->_objects[i]->_posX, adGame->_objects[i]->_posY)))) { obj = adGame->_objects[i]; minY = adGame->_objects[i]->_posY; @@ -1231,7 +1226,7 @@ bool AdScene::displayRegionContentOld(AdRegion *region) { } // scene objects - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_active && !_objects[i]->_editorOnly && !_objects[i]->_drawn && _objects[i]->_posY < minY && (_objects[i]->_stickRegion == region || region == NULL || (_objects[i]->_stickRegion == NULL && region->pointInRegion(_objects[i]->_posX, _objects[i]->_posY)))) { obj = _objects[i]; minY = _objects[i]->_posY; @@ -1252,7 +1247,7 @@ bool AdScene::displayRegionContentOld(AdRegion *region) { // design only objects if (_gameRef->_editorMode && region == NULL) { - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_active && _objects[i]->_editorOnly) { _objects[i]->display(); _objects[i]->_drawn = true; @@ -1443,7 +1438,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); if (val->isInt()) { int layer = val->getInt(); - if (layer < 0 || layer >= _layers.getSize()) { + if (layer < 0 || layer >= (int32)_layers.size()) { stack->pushNULL(); } else { stack->pushNative(_layers[layer], true); @@ -1451,7 +1446,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } else { const char *layerName = val->getString(); bool layerFound = false; - for (int i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { if (scumm_stricmp(layerName, _layers[i]->getName()) == 0) { stack->pushNative(_layers[i], true); layerFound = true; @@ -1471,7 +1466,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetWaypointGroup") == 0) { stack->correctParams(1); int group = stack->pop()->getInt(); - if (group < 0 || group >= _waypointGroups.getSize()) { + if (group < 0 || group >= (int32)_waypointGroups.size()) { stack->pushNULL(); } else { stack->pushNative(_waypointGroups[group], true); @@ -1506,12 +1501,12 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdObject *ret = NULL; if (val->isInt()) { int index = val->getInt(); - if (index >= 0 && index < _objects.getSize()) { + if (index >= 0 && index < (int32)_objects.size()) { ret = _objects[index]; } } else { const char *nodeName = val->getString(); - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i] && _objects[i]->getName() && scumm_stricmp(_objects[i]->getName(), nodeName) == 0) { ret = _objects[i]; break; @@ -1542,7 +1537,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } if (_mainLayer) { - for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { if (node->_region->_decoration && !includeDecors) { @@ -1752,7 +1747,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (index < 0) { index = 0; } - if (index <= _layers.getSize() - 1) { + if (index <= (int32)_layers.size() - 1) { _layers.insert_at(index, layer); } else { _layers.add(layer); @@ -1774,7 +1769,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdLayer *toDelete = NULL; if (val->isNative()) { BaseScriptable *temp = val->getNative(); - for (int i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { if (_layers[i] == temp) { toDelete = _layers[i]; break; @@ -1782,7 +1777,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } else { int index = val->getInt(); - if (index >= 0 && index < _layers.getSize()) { + if (index >= 0 && index < (int32)_layers.size()) { toDelete = _layers[index]; } } @@ -1797,7 +1792,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, return STATUS_OK; } - for (int i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { if (_layers[i] == toDelete) { _layers.remove_at(i); _gameRef->unregisterObject(toDelete); @@ -1828,7 +1823,7 @@ ScValue *AdScene::scGetProperty(const char *name) { // NumLayers (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "NumLayers") == 0) { - _scValue->setInt(_layers.getSize()); + _scValue->setInt(_layers.size()); return _scValue; } @@ -1836,7 +1831,7 @@ ScValue *AdScene::scGetProperty(const char *name) { // NumWaypointGroups (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "NumWaypointGroups") == 0) { - _scValue->setInt(_waypointGroups.getSize()); + _scValue->setInt(_waypointGroups.size()); return _scValue; } @@ -1857,7 +1852,7 @@ ScValue *AdScene::scGetProperty(const char *name) { // NumFreeNodes (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "NumFreeNodes") == 0) { - _scValue->setInt(_objects.getSize()); + _scValue->setInt(_objects.size()); return _scValue; } @@ -2101,7 +2096,7 @@ bool AdScene::addObject(AdObject *object) { ////////////////////////////////////////////////////////////////////////// bool AdScene::removeObject(AdObject *object) { - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i] == object) { _objects.remove_at(i); return _gameRef->unregisterObject(object); @@ -2113,8 +2108,6 @@ bool AdScene::removeObject(AdObject *object) { ////////////////////////////////////////////////////////////////////////// bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { - int i; - buffer->putTextIndent(indent, "SCENE {\n"); buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); @@ -2130,7 +2123,7 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { // scripts - for (i = 0; i < _scripts.getSize(); i++) { + for (uint32 i = 0; i < _scripts.size(); i++) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } @@ -2178,7 +2171,7 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { // waypoints buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); - for (i = 0; i < _waypointGroups.getSize(); i++) { + for (uint32 i = 0; i < _waypointGroups.size(); i++) { _waypointGroups[i]->saveAsText(buffer, indent + 2); } @@ -2186,19 +2179,19 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { // layers buffer->putTextIndent(indent + 2, "; ----- layers\n"); - for (i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { _layers[i]->saveAsText(buffer, indent + 2); } // scale levels buffer->putTextIndent(indent + 2, "; ----- scale levels\n"); - for (i = 0; i < _scaleLevels.getSize(); i++) { + for (uint32 i = 0; i < _scaleLevels.size(); i++) { _scaleLevels[i]->saveAsText(buffer, indent + 2); } // rotation levels buffer->putTextIndent(indent + 2, "; ----- rotation levels\n"); - for (i = 0; i < _rotLevels.getSize(); i++) { + for (uint32 i = 0; i < _rotLevels.size(); i++) { _rotLevels[i]->saveAsText(buffer, indent + 2); } @@ -2207,15 +2200,13 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { // free entities buffer->putTextIndent(indent + 2, "; ----- free entities\n"); - for (i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_type == OBJECT_ENTITY) { _objects[i]->saveAsText(buffer, indent + 2); } } - - buffer->putTextIndent(indent, "}\n"); return STATUS_OK; } @@ -2226,7 +2217,7 @@ bool AdScene::sortScaleLevels() { bool changed; do { changed = false; - for (int i = 0; i < _scaleLevels.getSize() - 1; i++) { + for (uint32 i = 0; i < _scaleLevels.size() - 1; i++) { if (_scaleLevels[i]->_posY > _scaleLevels[i + 1]->_posY) { AdScaleLevel *sl = _scaleLevels[i]; _scaleLevels[i] = _scaleLevels[i + 1]; @@ -2247,7 +2238,7 @@ bool AdScene::sortRotLevels() { bool changed; do { changed = false; - for (int i = 0; i < _rotLevels.getSize() - 1; i++) { + for (uint32 i = 0; i < _rotLevels.size() - 1; i++) { if (_rotLevels[i]->_posX > _rotLevels[i + 1]->_posX) { AdRotLevel *rl = _rotLevels[i]; _rotLevels[i] = _rotLevels[i + 1]; @@ -2268,9 +2259,9 @@ float AdScene::getScaleAt(int Y) { AdScaleLevel *prev = NULL; AdScaleLevel *next = NULL; - for (int i = 0; i < _scaleLevels.getSize(); i++) { + for (uint32 i = 0; i < _scaleLevels.size(); i++) { /* AdScaleLevel *xxx = _scaleLevels[i];*/ - /* int j = _scaleLevels.getSize(); */ + /* int j = _scaleLevels.size(); */ if (_scaleLevels[i]->_posY < Y) { prev = _scaleLevels[i]; } else { @@ -2517,7 +2508,7 @@ void AdScene::pfPointsStart() { ////////////////////////////////////////////////////////////////////////// void AdScene::pfPointsAdd(int x, int y, int distance) { - if (_pfPointsNum >= _pfPath.getSize()) { + if (_pfPointsNum >= (int32)_pfPath.size()) { _pfPath.add(new AdPathPoint(x, y, distance)); } else { _pfPath[_pfPointsNum]->x = x; @@ -2630,9 +2621,9 @@ BaseObject *AdScene::getNodeByName(const char *name) { BaseObject *ret = NULL; // dependent objects - for (int i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { AdLayer *layer = _layers[i]; - for (int j = 0; j < layer->_nodes.getSize(); j++) { + for (uint32 j = 0; j < layer->_nodes.size(); j++) { AdSceneNode *node = layer->_nodes[j]; if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->getName())) || (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->getName()))) { @@ -2652,14 +2643,14 @@ BaseObject *AdScene::getNodeByName(const char *name) { } // free entities - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->getName())) { return _objects[i]; } } // waypoint groups - for (int i = 0; i < _waypointGroups.getSize(); i++) { + for (uint32 i = 0; i < _waypointGroups.size(); i++) { if (!scumm_stricmp(name, _waypointGroups[i]->getName())) { return _waypointGroups[i]; } @@ -2696,9 +2687,9 @@ bool AdScene::persistState(bool saving) { AdNodeState *nodeState; // dependent objects - for (int i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { AdLayer *layer = _layers[i]; - for (int j = 0; j < layer->_nodes.getSize(); j++) { + for (uint32 j = 0; j < layer->_nodes.size(); j++) { AdSceneNode *node = layer->_nodes[j]; switch (node->_type) { case OBJECT_ENTITY: @@ -2733,7 +2724,7 @@ bool AdScene::persistState(bool saving) { } // free entities - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (!_objects[i]->_saveState) { continue; } @@ -2748,7 +2739,7 @@ bool AdScene::persistState(bool saving) { } // waypoint groups - for (int i = 0; i < _waypointGroups.getSize(); i++) { + for (uint32 i = 0; i < _waypointGroups.size(); i++) { nodeState = state->getNodeState(_waypointGroups[i]->getName(), saving); if (nodeState) { if (saving) { @@ -2768,9 +2759,9 @@ float AdScene::getRotationAt(int x, int y) { AdRotLevel *prev = NULL; AdRotLevel *next = NULL; - for (int i = 0; i < _rotLevels.getSize(); i++) { + for (uint32 i = 0; i < _rotLevels.size(); i++) { /* AdRotLevel *xxx = _rotLevels[i]; - int j = _rotLevels.getSize();*/ + int j = _rotLevels.size();*/ if (_rotLevels[i]->_posX < x) { prev = _rotLevels[i]; } else { @@ -2794,9 +2785,9 @@ float AdScene::getRotationAt(int x, int y) { ////////////////////////////////////////////////////////////////////////// bool AdScene::handleItemAssociations(const char *itemName, bool show) { - for (int i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { AdLayer *layer = _layers[i]; - for (int j = 0; j < layer->_nodes.getSize(); j++) { + for (uint32 j = 0; j < layer->_nodes.size(); j++) { if (layer->_nodes[j]->_type == OBJECT_ENTITY) { AdEntity *ent = layer->_nodes[j]->_entity; @@ -2807,7 +2798,7 @@ bool AdScene::handleItemAssociations(const char *itemName, bool show) { } } - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { if (_objects[i]->_type == OBJECT_ENTITY) { AdEntity *ent = (AdEntity *)_objects[i]; if (ent->_item && strcmp(ent->_item, itemName) == 0) { @@ -2824,7 +2815,7 @@ bool AdScene::handleItemAssociations(const char *itemName, bool show) { bool AdScene::getRegionsAt(int x, int y, AdRegion **regionList, int numRegions) { int numUsed = 0; if (_mainLayer) { - for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { + for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { if (numUsed < numRegions - 1) { @@ -2854,13 +2845,13 @@ BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) { BaseArray objects; getSceneObjects(objects, true); - if (objects.getSize() == 0) { + if (objects.size() == 0) { return NULL; } else { if (currObject != NULL) { - for (int i = 0; i < objects.getSize(); i++) { + for (uint32 i = 0; i < objects.size(); i++) { if (objects[i] == currObject) { - if (i < objects.getSize() - 1) { + if (i < objects.size() - 1) { return objects[i + 1]; } else { break; @@ -2878,11 +2869,11 @@ BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { BaseArray objects; getSceneObjects(objects, true); - if (objects.getSize() == 0) { + if (objects.size() == 0) { return NULL; } else { if (currObject != NULL) { - for (int i = objects.getSize() - 1; i >= 0; i--) { + for (int i = objects.size() - 1; i >= 0; i--) { if (objects[i] == currObject) { if (i > 0) { return objects[i - 1]; @@ -2892,7 +2883,7 @@ BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { } } } - return objects[objects.getSize() - 1]; + return objects[objects.size() - 1]; } return NULL; } @@ -2900,14 +2891,14 @@ BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { ////////////////////////////////////////////////////////////////////////// bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOnly) { - for (int i = 0; i < _layers.getSize(); i++) { + for (uint32 i = 0; i < _layers.size(); i++) { // close-up layer -> remove everything below it if (interactiveOnly && _layers[i]->_closeUp) { objects.clear(); } - for (int j = 0; j < _layers[i]->_nodes.getSize(); j++) { + for (uint32 j = 0; j < _layers[i]->_nodes.size(); j++) { AdSceneNode *node = _layers[i]->_nodes[j]; switch (node->_type) { case OBJECT_ENTITY: { @@ -2921,9 +2912,9 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOn case OBJECT_REGION: { BaseArray regionObj; getRegionObjects(node->_region, regionObj, interactiveOnly); - for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { + for (uint32 newIndex = 0; newIndex < regionObj.size(); newIndex++) { bool found = false; - for (int old = 0; old < objects.getSize(); old++) { + for (uint32 old = 0; old < objects.size(); old++) { if (objects[old] == regionObj[newIndex]) { found = true; break; @@ -2933,7 +2924,7 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOn objects.add(regionObj[newIndex]); } } - //if (RegionObj.getSize() > 0) Objects.Append(RegionObj); + //if (regionObj.size() > 0) Objects.Append(RegionObj); } break; default: @@ -2946,9 +2937,9 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOn // objects outside any region BaseArray regionObj; getRegionObjects(NULL, regionObj, interactiveOnly); - for (int newIndex = 0; newIndex < regionObj.getSize(); newIndex++) { + for (uint32 newIndex = 0; newIndex < regionObj.size(); newIndex++) { bool found = false; - for (int old = 0; old < objects.getSize(); old++) { + for (uint32 old = 0; old < objects.size(); old++) { if (objects[old] == regionObj[newIndex]) { found = true; break; @@ -2970,7 +2961,7 @@ bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, AdObject *obj; // global objects - for (int i = 0; i < adGame->_objects.getSize(); i++) { + for (uint32 i = 0; i < adGame->_objects.size(); i++) { obj = adGame->_objects[i]; if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { if (interactiveOnly && !obj->_registrable) { @@ -2982,7 +2973,7 @@ bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, } // scene objects - for (int i = 0; i < _objects.getSize(); i++) { + for (uint32 i = 0; i < _objects.size(); i++) { obj = _objects[i]; if (obj->_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { if (interactiveOnly && !obj->_registrable) { diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index 4a85148540..04fd52c382 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -47,7 +47,7 @@ AdSceneState::~AdSceneState() { delete[] _filename; _filename = NULL; - for (int i = 0; i < _nodeStates.getSize(); i++) { + for (uint32 i = 0; i < _nodeStates.size(); i++) { delete _nodeStates[i]; } _nodeStates.clear(); @@ -75,7 +75,7 @@ void AdSceneState::setFilename(const char *filename) { ////////////////////////////////////////////////////////////////////////// AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { - for (int i = 0; i < _nodeStates.getSize(); i++) { + for (uint32 i = 0; i < _nodeStates.size(); i++) { if (scumm_stricmp(_nodeStates[i]->getName(), name) == 0) { return _nodeStates[i]; } diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index 0c3080c9cd..51765e3fe9 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -318,7 +318,7 @@ bool AdSentence::update(TDirection dir) { currentTime = _gameRef->_timer - _startTime; bool talkNodeFound = false; - for (int i = 0; i < _talkDef->_nodes.getSize(); i++) { + for (uint32 i = 0; i < _talkDef->_nodes.size(); i++) { if (_talkDef->_nodes[i]->isInTimeInterval(currentTime, dir)) { talkNodeFound = true; diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 08136d787e..cd96345fc8 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -52,7 +52,7 @@ AdTalkDef::AdTalkDef(BaseGame *inGame) : BaseObject(inGame) { ////////////////////////////////////////////////////////////////////////// AdTalkDef::~AdTalkDef() { - for (int i = 0; i < _nodes.getSize(); i++) { + for (uint32 i = 0; i < _nodes.size(); i++) { delete _nodes[i]; } _nodes.clear(); @@ -232,7 +232,7 @@ bool AdTalkDef::saveAsText(BaseDynamicBuffer *buffer, int indent) { _defaultSpriteSet->saveAsText(buffer, indent + 2); } - for (int i = 0; i < _nodes.getSize(); i++) { + for (uint32 i = 0; i < _nodes.size(); i++) { _nodes[i]->saveAsText(buffer, indent + 2); buffer->putTextIndent(indent, "\n"); } diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 165ee50270..89d7bd8a46 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -52,12 +52,12 @@ AdTalkHolder::~AdTalkHolder() { delete _sprite; _sprite = NULL; - for (int i = 0; i < _talkSprites.getSize(); i++) { + for (uint32 i = 0; i < _talkSprites.size(); i++) { delete _talkSprites[i]; } _talkSprites.clear(); - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { delete _talkSpritesEx[i]; } _talkSpritesEx.clear(); @@ -88,7 +88,7 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { if (stance != NULL) { // search special talk stances - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { ret = _talkSpritesEx[i]; break; @@ -96,7 +96,7 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { } if (ret == NULL) { // serach generic talk stances - for (int i = 0; i < _talkSprites.getSize(); i++) { + for (uint32 i = 0; i < _talkSprites.size(); i++) { if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { ret = _talkSprites[i]; break; @@ -107,11 +107,11 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { // not a valid stance? get a random one if (ret == NULL) { - if (_talkSprites.getSize() < 1) { + if (_talkSprites.size() < 1) { ret = _sprite; } else { // TODO: remember last - int rnd = BaseEngine::instance().randInt(0, _talkSprites.getSize() - 1); + int rnd = BaseEngine::instance().randInt(0, _talkSprites.size() - 1); ret = _talkSprites[rnd]; } } @@ -228,7 +228,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS bool setTemp2 = false; if (ex) { - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { if (scumm_stricmp(_talkSpritesEx[i]->getFilename(), filename) == 0) { if (_currentSprite == _talkSpritesEx[i]) { setCurrent = true; @@ -242,7 +242,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } } } else { - for (int i = 0; i < _talkSprites.getSize(); i++) { + for (uint32 i = 0; i < _talkSprites.size(); i++) { if (scumm_stricmp(_talkSprites[i]->getFilename(), filename) == 0) { if (_currentSprite == _talkSprites[i]) { setCurrent = true; @@ -288,7 +288,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS // delete current if (ex) { - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { if (_talkSpritesEx[i] == _currentSprite) { setCurrent = true; } @@ -299,7 +299,7 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } _talkSpritesEx.clear(); } else { - for (int i = 0; i < _talkSprites.getSize(); i++) { + for (uint32 i = 0; i < _talkSprites.size(); i++) { if (_talkSprites[i] == _currentSprite) { setCurrent = true; } @@ -372,13 +372,13 @@ const char *AdTalkHolder::scToString() { ////////////////////////////////////////////////////////////////////////// bool AdTalkHolder::saveAsText(BaseDynamicBuffer *buffer, int indent) { - for (int i = 0; i < _talkSprites.getSize(); i++) { + for (uint32 i = 0; i < _talkSprites.size(); i++) { if (_talkSprites[i]->getFilename()) { buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->getFilename()); } } - for (int i = 0; i < _talkSpritesEx.getSize(); i++) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { if (_talkSpritesEx[i]->getFilename()) { buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->getFilename()); } diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 1573f5914e..8da62c9115 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -56,7 +56,7 @@ AdWaypointGroup::~AdWaypointGroup() { ////////////////////////////////////////////////////////////////////////// void AdWaypointGroup::cleanup() { - for (int i = 0; i < _points.getSize(); i++) { + for (uint32 i = 0; i < _points.size(); i++) { delete _points[i]; } _points.clear(); @@ -179,7 +179,7 @@ bool AdWaypointGroup::saveAsText(BaseDynamicBuffer *buffer, int indent) { } BaseClass::saveAsText(buffer, indent + 2); - for (int i = 0; i < _points.getSize(); i++) { + for (uint32 i = 0; i < _points.size(); i++) { buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); } @@ -253,7 +253,7 @@ bool AdWaypointGroup::mimic(AdWaypointGroup *wpt, float scale, int argX, int arg cleanup(); - for (int i = 0; i < wpt->_points.getSize(); i++) { + for (uint32 i = 0; i < wpt->_points.size(); i++) { int x = (int)((float)wpt->_points[i]->x * scale / 100.0f); int y = (int)((float)wpt->_points[i]->y * scale / 100.0f); -- cgit v1.2.3 From 07c27b775c8d3997bf40891c2772ae8859eb534d Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 19:35:49 +0200 Subject: WINTERMUTE: Cleanup the header-guards. --- engines/wintermute/ad/ad_actor.h | 2 +- engines/wintermute/ad/ad_types.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index 4bc1bae37f..370a91cc22 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -105,4 +105,4 @@ private: } // end of namespace Wintermute -#endif // WINTERMUTE_ADACTOR_H +#endif diff --git a/engines/wintermute/ad/ad_types.h b/engines/wintermute/ad/ad_types.h index b8cae58c6d..8db20bfc02 100644 --- a/engines/wintermute/ad/ad_types.h +++ b/engines/wintermute/ad/ad_types.h @@ -104,4 +104,4 @@ typedef enum { } // end of namespace Wintermute -#endif // WINTERMUTE_ADTYPES_H +#endif -- cgit v1.2.3 From 8cf7d765c05bd13fc381e94801b2bbd8c27e1c07 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 19:38:24 +0200 Subject: WINTERMUTE: General cleanup --- engines/wintermute/ad/ad_path.h | 2 +- engines/wintermute/ad/ad_scene.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_path.h b/engines/wintermute/ad/ad_path.h index b85e1fce7a..de115b261a 100644 --- a/engines/wintermute/ad/ad_path.h +++ b/engines/wintermute/ad/ad_path.h @@ -46,7 +46,7 @@ public: void reset(); AdPath(BaseGame *inGame); virtual ~AdPath(); - BaseArray _points; + BaseArray _points; int _currIndex; bool _ready; }; diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 176604b75f..5b96bc0c3a 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -267,7 +267,7 @@ void AdScene::pfAddWaypointGroup(AdWaypointGroup *wpt, BaseObject *requester) { return; } - for (uint32 i = 0; i < wpt->_points.size(); i++) { + for (uint32 i = 0; i < wpt->_points.size(); i++) { if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) { continue; } -- cgit v1.2.3 From 7027741de777f3d1f5e9e93f5a2dd8ade09b6599 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 19:51:07 +0200 Subject: WINTERMUTE: Fix warnings --- engines/wintermute/ad/ad_actor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index dd50955b4c..63b1532416 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -1036,7 +1036,7 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *animName = stack->pop()->getString(); bool found = false; - for (int i = 0; i < _anims.size(); i++) { + for (uint32 i = 0; i < _anims.size(); i++) { if (scumm_stricmp(_anims[i]->getName(), animName) == 0) { // invalidate sprites in use if (_anims[i]->containsSprite(_tempSprite2)) { @@ -1255,7 +1255,7 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { // not - get a random talk if (!ret) { BaseArray talkAnims; - for (int i = 0; i < _anims.size(); i++) { + for (uint32 i = 0; i < _anims.size(); i++) { if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) { talkAnims.add(_anims[i]); } @@ -1284,7 +1284,7 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { if (stance != NULL) { // search special stances - for (int i = 0; i < _talkSpritesEx.size(); i++) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { ret = _talkSpritesEx[i]->getSprite(_dir); break; @@ -1292,7 +1292,7 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { } if (ret == NULL) { // search generic stances - for (int i = 0; i < _talkSprites.size(); i++) { + for (uint32 i = 0; i < _talkSprites.size(); i++) { if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { ret = _talkSprites[i]->getSprite(_dir); break; @@ -1395,7 +1395,7 @@ int AdActor::getHeight() { ////////////////////////////////////////////////////////////////////////// AdSpriteSet *AdActor::getAnimByName(const Common::String &animName) { - for (int i = 0; i < _anims.size(); i++) { + for (uint32 i = 0; i < _anims.size(); i++) { if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) { return _anims[i]; } -- cgit v1.2.3 From 313376c32985c8ce23f148b8a70d0222e2310080 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 19:54:53 +0200 Subject: WINTERMUTE: Fix a warning I missed in the last commit. --- engines/wintermute/ad/ad_scene.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 5b96bc0c3a..ddaf4d0adb 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -1195,8 +1195,8 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { ////////////////////////////////////////////////////////////////////////// int AdScene::compareObjs(const void *obj1, const void *obj2) { - const AdObject *object1 = *(AdObject **)obj1; - const AdObject *object2 = *(AdObject **)obj2; + const AdObject *object1 = *(const AdObject *const *)obj1; + const AdObject *object2 = *(const AdObject *const *)obj2; if (object1->_posY < object2->_posY) { return -1; -- cgit v1.2.3 From e067520bb904615ed75217808ba27235eb244336 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 21:01:53 +0200 Subject: WINTERMUTE: Use tabs in enums --- engines/wintermute/ad/ad_response_box.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_response_box.h b/engines/wintermute/ad/ad_response_box.h index 99522f00f6..8c76b561c6 100644 --- a/engines/wintermute/ad/ad_response_box.h +++ b/engines/wintermute/ad/ad_response_box.h @@ -52,9 +52,9 @@ public: ScScript *_waitingScript; virtual bool listen(BaseScriptHolder *param1, uint32 param2); typedef enum { - EVENT_PREV, - EVENT_NEXT, - EVENT_RESPONSE + EVENT_PREV, + EVENT_NEXT, + EVENT_RESPONSE } TResponseEvent; bool weedResponses(); -- cgit v1.2.3 From 4a6c031e3197899d1bd2b745b9b6f3605a72cb65 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 31 Aug 2012 21:50:12 +0200 Subject: WINTERMUTE: Fix a regression from the getSize()->size() change. --- engines/wintermute/ad/ad_scene.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index ddaf4d0adb..76238c1850 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -2214,6 +2214,9 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// bool AdScene::sortScaleLevels() { + if (_scaleLevels.size() == 0) { + return STATUS_OK; + } bool changed; do { changed = false; @@ -2235,6 +2238,9 @@ bool AdScene::sortScaleLevels() { ////////////////////////////////////////////////////////////////////////// bool AdScene::sortRotLevels() { + if (_rotLevels.size() == 0) { + return STATUS_OK; + } bool changed; do { changed = false; -- cgit v1.2.3 From 7b17d8060d5600fe736d0b3af4e24da4e1776ddb Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 1 Sep 2012 14:04:23 +0200 Subject: WINTERMUTE: Fix various comments. --- engines/wintermute/ad/ad_scene.cpp | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 76238c1850..f67252350e 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -2370,13 +2370,6 @@ bool AdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *tar yLength = abs(y2 - y1); if (xLength > yLength) { - /* - if (X1 > X2) - { - Swap(&X1, &X2); - Swap(&Y1, &Y2); - } - */ yStep = fabs((double)(y2 - y1) / (double)(x2 - x1)); y = y1; @@ -2390,12 +2383,6 @@ bool AdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *tar y += yStep; } } else { - /* - if (Y1 > Y2) { - Swap(&X1, &X2); - Swap(&Y1, &Y2); - } - */ xStep = fabs((double)(x2 - x1) / (double)(y2 - y1)); x = x1; -- cgit v1.2.3 From b4090ead4d4334e08725323ff72fd355c93b63d5 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 4 Sep 2012 22:17:23 +0200 Subject: WINTERMUTE: Convert CRLF to LF --- engines/wintermute/ad/ad_actor.cpp | 2920 ++++++------ engines/wintermute/ad/ad_actor.h | 216 +- engines/wintermute/ad/ad_entity.cpp | 2242 +++++----- engines/wintermute/ad/ad_entity.h | 136 +- engines/wintermute/ad/ad_game.cpp | 4560 +++++++++---------- engines/wintermute/ad/ad_game.h | 326 +- engines/wintermute/ad/ad_inventory.cpp | 272 +- engines/wintermute/ad/ad_inventory.h | 104 +- engines/wintermute/ad/ad_inventory_box.cpp | 776 ++-- engines/wintermute/ad/ad_inventory_box.h | 130 +- engines/wintermute/ad/ad_item.cpp | 1626 +++---- engines/wintermute/ad/ad_item.h | 138 +- engines/wintermute/ad/ad_layer.cpp | 1128 ++--- engines/wintermute/ad/ad_layer.h | 116 +- engines/wintermute/ad/ad_node_state.cpp | 392 +- engines/wintermute/ad/ad_node_state.h | 120 +- engines/wintermute/ad/ad_object.cpp | 2598 +++++------ engines/wintermute/ad/ad_object.h | 248 +- engines/wintermute/ad/ad_path.cpp | 240 +- engines/wintermute/ad/ad_path.h | 112 +- engines/wintermute/ad/ad_path_point.cpp | 150 +- engines/wintermute/ad/ad_path_point.h | 100 +- engines/wintermute/ad/ad_region.cpp | 794 ++-- engines/wintermute/ad/ad_region.h | 116 +- engines/wintermute/ad/ad_response.cpp | 292 +- engines/wintermute/ad/ad_response.h | 122 +- engines/wintermute/ad/ad_response_box.cpp | 1424 +++--- engines/wintermute/ad/ad_response_box.h | 174 +- engines/wintermute/ad/ad_response_context.cpp | 142 +- engines/wintermute/ad/ad_response_context.h | 100 +- engines/wintermute/ad/ad_rot_level.cpp | 322 +- engines/wintermute/ad/ad_rot_level.h | 98 +- engines/wintermute/ad/ad_scale_level.cpp | 318 +- engines/wintermute/ad/ad_scale_level.h | 100 +- engines/wintermute/ad/ad_scene.cpp | 5972 ++++++++++++------------- engines/wintermute/ad/ad_scene.h | 362 +- engines/wintermute/ad/ad_scene_node.cpp | 164 +- engines/wintermute/ad/ad_scene_node.h | 108 +- engines/wintermute/ad/ad_scene_state.cpp | 190 +- engines/wintermute/ad/ad_scene_state.h | 102 +- engines/wintermute/ad/ad_sentence.cpp | 720 +-- engines/wintermute/ad/ad_sentence.h | 170 +- engines/wintermute/ad/ad_sprite_set.cpp | 712 +-- engines/wintermute/ad/ad_sprite_set.h | 106 +- engines/wintermute/ad/ad_talk_def.cpp | 570 +-- engines/wintermute/ad/ad_talk_def.h | 116 +- engines/wintermute/ad/ad_talk_holder.cpp | 804 ++-- engines/wintermute/ad/ad_talk_holder.h | 114 +- engines/wintermute/ad/ad_talk_node.cpp | 590 +-- engines/wintermute/ad/ad_talk_node.h | 126 +- engines/wintermute/ad/ad_types.h | 214 +- engines/wintermute/ad/ad_waypoint_group.cpp | 540 +-- engines/wintermute/ad/ad_waypoint_group.h | 116 +- 53 files changed, 17224 insertions(+), 17224 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index 63b1532416..9087d66844 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -1,1460 +1,1460 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_actor.h" -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_scene.h" -#include "engines/wintermute/ad/ad_entity.h" -#include "engines/wintermute/ad/ad_sprite_set.h" -#include "engines/wintermute/ad/ad_waypoint_group.h" -#include "engines/wintermute/ad/ad_path.h" -#include "engines/wintermute/ad/ad_sentence.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/sound/base_sound.h" -#include "engines/wintermute/base/base_region.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/particles/part_emitter.h" -#include "engines/wintermute/base/base_engine.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdActor, false) - - -////////////////////////////////////////////////////////////////////////// -AdActor::AdActor(BaseGame *inGame) : AdTalkHolder(inGame) { - _path = new AdPath(_gameRef); - - _type = OBJECT_ACTOR; - _dir = DI_LEFT; - - _walkSprite = NULL; - _standSprite = NULL; - _turnLeftSprite = NULL; - _turnRightSprite = NULL; - - _targetPoint = new BasePoint; - _afterWalkDir = DI_NONE; - - _animSprite2 = NULL; - - setDefaultAnimNames(); -} - -////////////////////////////////////////////////////////////////////////// -bool AdActor::setDefaultAnimNames() { - _talkAnimName = "talk"; - _idleAnimName = "idle"; - _walkAnimName = "walk"; - _turnLeftAnimName = "turnleft"; - _turnRightAnimName = "turnright"; - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -AdActor::~AdActor() { - delete _path; - delete _targetPoint; - _path = NULL; - _targetPoint = NULL; - - delete _walkSprite; - delete _standSprite; - delete _turnLeftSprite; - delete _turnRightSprite; - _walkSprite = NULL; - _standSprite = NULL; - _turnLeftSprite = NULL; - _turnRightSprite = NULL; - - _animSprite2 = NULL; // ref only - - for (uint32 i = 0; i < _talkSprites.size(); i++) { - delete _talkSprites[i]; - } - _talkSprites.clear(); - - for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { - delete _talkSpritesEx[i]; - } - _talkSpritesEx.clear(); - - for (uint32 i = 0; i < _anims.size(); i++) { - delete _anims[i]; - _anims[i] = NULL; - } - _anims.clear(); - -} - - -////////////////////////////////////////////////////////////////////////// -bool AdActor::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdActor::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(ACTOR) -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(WALK) -TOKEN_DEF(STAND) -TOKEN_DEF(TALK_SPECIAL) -TOKEN_DEF(TALK) -TOKEN_DEF(TURN_LEFT) -TOKEN_DEF(TURN_RIGHT) -TOKEN_DEF(EVENTS) -TOKEN_DEF(FONT) -TOKEN_DEF(CURSOR) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(SOUND_VOLUME) -TOKEN_DEF(SOUND_PANNING) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(BLOCKED_REGION) -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(ANIMATION) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdActor::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ACTOR) - 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(WALK) - TOKEN_TABLE(STAND) - TOKEN_TABLE(TALK_SPECIAL) - TOKEN_TABLE(TALK) - TOKEN_TABLE(TURN_LEFT) - TOKEN_TABLE(TURN_RIGHT) - TOKEN_TABLE(EVENTS) - TOKEN_TABLE(FONT) - TOKEN_TABLE(CURSOR) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(SOUND_VOLUME) - TOKEN_TABLE(SOUND_PANNING) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(BLOCKED_REGION) - 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(ANIMATION) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTOR) { - _gameRef->LOG(0, "'ACTOR' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - AdGame *adGame = (AdGame *)_gameRef; - AdSpriteSet *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 (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_X: - parser.scanStr((char *)params, "%d", &_posX); - break; - - case TOKEN_Y: - parser.scanStr((char *)params, "%d", &_posY); - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_FONT: - setFont((char *)params); - break; - - case TOKEN_SCALABLE: - parser.scanStr((char *)params, "%b", &_zoomable); - break; - - case TOKEN_ROTABLE: - case TOKEN_ROTATABLE: - parser.scanStr((char *)params, "%b", &_rotatable); - break; - - case TOKEN_REGISTRABLE: - case TOKEN_INTERACTIVE: - parser.scanStr((char *)params, "%b", &_registrable); - break; - - case TOKEN_SHADOWABLE: - case TOKEN_COLORABLE: - parser.scanStr((char *)params, "%b", &_shadowable); - break; - - case TOKEN_ACTIVE: - parser.scanStr((char *)params, "%b", &_active); - break; - - case TOKEN_WALK: - delete _walkSprite; - _walkSprite = NULL; - spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) { - cmd = PARSERR_GENERIC; - } else { - _walkSprite = spr; - } - break; - - case TOKEN_TALK: - spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { - cmd = PARSERR_GENERIC; - } else { - _talkSprites.add(spr); - } - break; - - case TOKEN_TALK_SPECIAL: - spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { - cmd = PARSERR_GENERIC; - } else { - _talkSpritesEx.add(spr); - } - break; - - case TOKEN_STAND: - delete _standSprite; - _standSprite = NULL; - spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) { - cmd = PARSERR_GENERIC; - } else { - _standSprite = spr; - } - break; - - case TOKEN_TURN_LEFT: - delete _turnLeftSprite; - _turnLeftSprite = NULL; - spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { - cmd = PARSERR_GENERIC; - } else { - _turnLeftSprite = spr; - } - break; - - case TOKEN_TURN_RIGHT: - delete _turnRightSprite; - _turnRightSprite = NULL; - spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { - cmd = PARSERR_GENERIC; - } else { - _turnRightSprite = spr; - } - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_CURSOR: - delete _cursor; - _cursor = new BaseSprite(_gameRef); - if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { - delete _cursor; - _cursor = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_SOUND_VOLUME: - parser.scanStr((char *)params, "%d", &_sFXVolume); - break; - - case TOKEN_SCALE: { - int s; - parser.scanStr((char *)params, "%d", &s); - _scale = (float)s; - - } - break; - - case TOKEN_RELATIVE_SCALE: { - int s; - parser.scanStr((char *)params, "%d", &s); - _relativeScale = (float)s; - - } - break; - - case TOKEN_SOUND_PANNING: - parser.scanStr((char *)params, "%b", &_autoSoundPanning); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_BLOCKED_REGION: { - delete _blockRegion; - delete _currentBlockRegion; - _blockRegion = NULL; - _currentBlockRegion = NULL; - BaseRegion *rgn = new BaseRegion(_gameRef); - BaseRegion *crgn = new BaseRegion(_gameRef); - if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { - delete _blockRegion; - delete _currentBlockRegion; - _blockRegion = NULL; - _currentBlockRegion = NULL; - cmd = PARSERR_GENERIC; - } else { - _blockRegion = rgn; - _currentBlockRegion = crgn; - _currentBlockRegion->mimic(_blockRegion); - } - } - break; - - case TOKEN_WAYPOINTS: { - delete _wptGroup; - delete _currentWptGroup; - _wptGroup = NULL; - _currentWptGroup = NULL; - AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); - AdWaypointGroup *cwpt = new AdWaypointGroup(_gameRef); - if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { - delete _wptGroup; - delete _currentWptGroup; - _wptGroup = NULL; - _currentWptGroup = NULL; - cmd = PARSERR_GENERIC; - } else { - _wptGroup = wpt; - _currentWptGroup = cwpt; - _currentWptGroup->mimic(_wptGroup); - } - } - break; - - case TOKEN_IGNORE_ITEMS: - parser.scanStr((char *)params, "%b", &_ignoreItems); - 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_ANIMATION: { - AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); - if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - } else { - _anims.add(anim); - } - } - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ACTOR definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - if (spr) { - delete spr; - } - _gameRef->LOG(0, "Error loading ACTOR definition"); - return STATUS_FAILED; - } - - if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { - ar = ag = ab = 255; - } - _alphaColor = BYTETORGBA(ar, ag, ab, alpha); - _state = _nextState = STATE_READY; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void AdActor::turnTo(TDirection dir) { - int delta1, delta2, delta3, delta; - - delta1 = dir - _dir; - delta2 = dir + NUM_DIRECTIONS - _dir; - delta3 = dir - NUM_DIRECTIONS - _dir; - - delta1 = (abs(delta1) <= abs(delta2)) ? delta1 : delta2; - delta = (abs(delta1) <= abs(delta3)) ? delta1 : delta3; - - // already there? - if (abs(delta) < 2) { - _dir = dir; - _state = _nextState; - _nextState = STATE_READY; - return; - } - - _targetDir = dir; - _state = delta < 0 ? STATE_TURNING_LEFT : STATE_TURNING_RIGHT; - - _tempSprite2 = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void AdActor::goTo(int x, int y, TDirection afterWalkDir) { - _afterWalkDir = afterWalkDir; - if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) { - return; - } - - _path->reset(); - _path->setReady(false); - - _targetPoint->x = x; - _targetPoint->y = y; - - ((AdGame *)_gameRef)->_scene->correctTargetPoint(_posX, _posY, &_targetPoint->x, &_targetPoint->y, true, this); - - _state = STATE_SEARCHING_PATH; - -} - - -////////////////////////////////////////////////////////////////////////// -bool AdActor::display() { - if (_active) { - updateSounds(); - } - - uint32 alpha; - if (_alphaColor != 0) { - alpha = _alphaColor; - } else { - alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; - } - - float scaleX, scaleY; - getScale(&scaleX, &scaleY); - - - float rotate; - if (_rotatable) { - if (_rotateValid) { - rotate = _rotate; - } else { - rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; - } - } else { - rotate = 0.0f; - } - - if (_active) { - displaySpriteAttachments(true); - } - - if (_currentSprite && _active) { - bool reg = _registrable; - if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) { - reg = false; - } - - _currentSprite->display(_posX, - _posY, - reg ? _registerAlias : NULL, - scaleX, - scaleY, - alpha, - rotate, - _blendMode); - - } - - if (_active) { - displaySpriteAttachments(false); - } - if (_active && _partEmitter) { - _partEmitter->display(); - } - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdActor::update() { - _currentSprite = NULL; - - if (_state == STATE_READY) { - if (_animSprite) { - delete _animSprite; - _animSprite = NULL; - } - if (_animSprite2) { - _animSprite2 = NULL; - } - } - - // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { - _state = _nextState; - _nextState = STATE_READY; - _currentSprite = _animSprite; - } - - if (_state == STATE_PLAYING_ANIM_SET && _animSprite2 != NULL && _animSprite2->_finished) { - _state = _nextState; - _nextState = STATE_READY; - _currentSprite = _animSprite2; - } - - if (_sentence && _state != STATE_TALKING) { - _sentence->finish(); - } - - // default: stand animation - if (!_currentSprite) { - if (_sprite) { - _currentSprite = _sprite; - } else { - if (_standSprite) { - _currentSprite = _standSprite->getSprite(_dir); - } else { - AdSpriteSet *anim = getAnimByName(_idleAnimName); - if (anim) { - _currentSprite = anim->getSprite(_dir); - } - } - } - } - - bool already_moved = false; - - switch (_state) { - ////////////////////////////////////////////////////////////////////////// - case STATE_PLAYING_ANIM: - _currentSprite = _animSprite; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_PLAYING_ANIM_SET: - _currentSprite = _animSprite2; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_TURNING_LEFT: - if (_tempSprite2 == NULL || _tempSprite2->_finished) { - if (_dir > 0) { - _dir = (TDirection)(_dir - 1); - } else { - _dir = (TDirection)(NUM_DIRECTIONS - 1); - } - - if (_dir == _targetDir) { - _tempSprite2 = NULL; - _state = _nextState; - _nextState = STATE_READY; - } else { - if (_turnLeftSprite) { - _tempSprite2 = _turnLeftSprite->getSprite(_dir); - } else { - AdSpriteSet *anim = getAnimByName(_turnLeftAnimName); - if (anim) { - _tempSprite2 = anim->getSprite(_dir); - } - } - - if (_tempSprite2) { - _tempSprite2->reset(); - if (_tempSprite2->_looping) { - _tempSprite2->_looping = false; - } - } - _currentSprite = _tempSprite2; - } - } else { - _currentSprite = _tempSprite2; - } - break; - - - ////////////////////////////////////////////////////////////////////////// - case STATE_TURNING_RIGHT: - if (_tempSprite2 == NULL || _tempSprite2->_finished) { - _dir = (TDirection)(_dir + 1); - - if ((int)_dir >= (int)NUM_DIRECTIONS) { - _dir = (TDirection)(0); - } - - if (_dir == _targetDir) { - _tempSprite2 = NULL; - _state = _nextState; - _nextState = STATE_READY; - } else { - if (_turnRightSprite) { - _tempSprite2 = _turnRightSprite->getSprite(_dir); - } else { - AdSpriteSet *anim = getAnimByName(_turnRightAnimName); - if (anim) { - _tempSprite2 = anim->getSprite(_dir); - } - } - - if (_tempSprite2) { - _tempSprite2->reset(); - if (_tempSprite2->_looping) { - _tempSprite2->_looping = false; - } - } - _currentSprite = _tempSprite2; - } - } else { - _currentSprite = _tempSprite2; - } - break; - - - ////////////////////////////////////////////////////////////////////////// - case STATE_SEARCHING_PATH: - // keep asking scene for the path - if (((AdGame *)_gameRef)->_scene->getPath(BasePoint(_posX, _posY), *_targetPoint, _path, this)) { - _state = STATE_WAITING_PATH; - } - break; - - - ////////////////////////////////////////////////////////////////////////// - case STATE_WAITING_PATH: - // wait until the scene finished the path - if (_path->_ready) { - followPath(); - } - break; - - - ////////////////////////////////////////////////////////////////////////// - case STATE_FOLLOWING_PATH: - getNextStep(); - already_moved = true; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_TALKING: { - _sentence->update(_dir); - if (_sentence->_currentSprite) { - _tempSprite2 = _sentence->_currentSprite; - } - - bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { - if (timeIsUp) { - _sentence->finish(); - _tempSprite2 = NULL; - _state = _nextState; - _nextState = STATE_READY; - } else { - _tempSprite2 = getTalkStance(_sentence->getNextStance()); - if (_tempSprite2) { - _tempSprite2->reset(); - _currentSprite = _tempSprite2; - ((AdGame *)_gameRef)->addSentence(_sentence); - } - } - } else { - _currentSprite = _tempSprite2; - ((AdGame *)_gameRef)->addSentence(_sentence); - } - } - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_READY: - if (!_animSprite && !_animSprite2) { - if (_sprite) { - _currentSprite = _sprite; - } else { - if (_standSprite) { - _currentSprite = _standSprite->getSprite(_dir); - } else { - AdSpriteSet *anim = getAnimByName(_idleAnimName); - if (anim) { - _currentSprite = anim->getSprite(_dir); - } - } - } - } - break; - default: - error("AdActor::Update - Unhandled enum"); - } - - - if (_currentSprite && !already_moved) { - _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (_currentSprite->_changed) { - _posX += _currentSprite->_moveX; - _posY += _currentSprite->_moveY; - afterMove(); - } - } - - //_gameRef->QuickMessageForm("%s", _currentSprite->_filename); - - updateBlockRegion(); - _ready = (_state == STATE_READY); - - updatePartEmitter(); - updateSpriteAttachments(); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void AdActor::followPath() { - // skip current position - _path->getFirst(); - while (_path->getCurrent() != NULL) { - if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) { - break; - } - _path->getNext(); - } - - // are there points to follow? - if (_path->getCurrent() != NULL) { - _state = STATE_FOLLOWING_PATH;; - initLine(BasePoint(_posX, _posY), *_path->getCurrent()); - } else { - if (_afterWalkDir != DI_NONE) { - turnTo(_afterWalkDir); - } else { - _state = STATE_READY; - } - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdActor::getNextStep() { - if (_walkSprite) { - _currentSprite = _walkSprite->getSprite(_dir); - } else { - AdSpriteSet *anim = getAnimByName(_walkAnimName); - if (anim) { - _currentSprite = anim->getSprite(_dir); - } - } - - if (!_currentSprite) { - return; - } - - _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (!_currentSprite->_changed) { - return; - } - - - int maxStepX, maxStepY; - maxStepX = abs(_currentSprite->_moveX); - maxStepY = abs(_currentSprite->_moveY); - - maxStepX = MAX(maxStepX, maxStepY); - maxStepX = MAX(maxStepX, 1); - - while (_pFCount > 0 && maxStepX >= 0) { - _pFX += _pFStepX; - _pFY += _pFStepY; - - _pFCount--; - maxStepX--; - } - - if (((AdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX, (int) _pFY, true, this)) { - if (_pFCount == 0) { - _state = _nextState; - _nextState = STATE_READY; - return; - } - goTo(_targetPoint->x, _targetPoint->y); - return; - } - - - _posX = (int)_pFX; - _posY = (int)_pFY; - - afterMove(); - - - if (_pFCount == 0) { - if (_path->getNext() == NULL) { - _posX = _targetPoint->x; - _posY = _targetPoint->y; - - _path->reset(); - if (_afterWalkDir != DI_NONE) { - turnTo(_afterWalkDir); - } else { - _state = _nextState; - _nextState = STATE_READY; - } - } else { - initLine(BasePoint(_posX, _posY), *_path->getCurrent()); - } - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdActor::initLine(BasePoint startPt, BasePoint endPt) { - _pFCount = MAX((abs(endPt.x - startPt.x)) , (abs(endPt.y - startPt.y))); - - _pFStepX = (double)(endPt.x - startPt.x) / _pFCount; - _pFStepY = (double)(endPt.y - startPt.y) / _pFCount; - - _pFX = startPt.x; - _pFY = startPt.y; - - int angle = (int)(atan2((double)(endPt.y - startPt.y), (double)(endPt.x - startPt.x)) * (180 / 3.14)); - - _nextState = STATE_FOLLOWING_PATH; - - turnTo(angleToDirection(angle)); -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // GoTo / GoToAsync - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "GoTo") == 0 || strcmp(name, "GoToAsync") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - goTo(x, y); - if (strcmp(name, "GoToAsync") != 0) { - script->waitForExclusive(this); - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GoToObject / GoToObjectAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GoToObject") == 0 || strcmp(name, "GoToObjectAsync") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - if (!val->isNative()) { - script->runtimeError("actor.%s method accepts an entity refrence only", name); - stack->pushNULL(); - return STATUS_OK; - } - AdObject *obj = (AdObject *)val->getNative(); - if (!obj || obj->_type != OBJECT_ENTITY) { - script->runtimeError("actor.%s method accepts an entity refrence only", name); - stack->pushNULL(); - return STATUS_OK; - } - AdEntity *ent = (AdEntity *)obj; - if (ent->_walkToX == 0 && ent->_walkToY == 0) { - goTo(ent->_posX, ent->_posY); - } else { - goTo(ent->_walkToX, ent->_walkToY, ent->_walkToDir); - } - if (strcmp(name, "GoToObjectAsync") != 0) { - script->waitForExclusive(this); - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnTo / TurnToAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnTo") == 0 || strcmp(name, "TurnToAsync") == 0) { - stack->correctParams(1); - int dir; - ScValue *val = stack->pop(); - - // turn to object? - if (val->isNative() && _gameRef->validObject((BaseObject *)val->getNative())) { - BaseObject *obj = (BaseObject *)val->getNative(); - int angle = (int)(atan2((double)(obj->_posY - _posY), (double)(obj->_posX - _posX)) * (180 / 3.14)); - dir = (int)angleToDirection(angle); - } - // otherwise turn to direction - else { - dir = val->getInt(); - } - - if (dir >= 0 && dir < NUM_DIRECTIONS) { - turnTo((TDirection)dir); - if (strcmp(name, "TurnToAsync") != 0) { - script->waitForExclusive(this); - } - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsWalking - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsWalking") == 0) { - stack->correctParams(0); - stack->pushBool(_state == STATE_FOLLOWING_PATH); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // MergeAnims - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MergeAnims") == 0) { - stack->correctParams(1); - stack->pushBool(DID_SUCCEED(mergeAnims(stack->pop()->getString()))); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // UnloadAnim - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "UnloadAnim") == 0) { - stack->correctParams(1); - const char *animName = stack->pop()->getString(); - - bool found = false; - for (uint32 i = 0; i < _anims.size(); i++) { - if (scumm_stricmp(_anims[i]->getName(), animName) == 0) { - // invalidate sprites in use - if (_anims[i]->containsSprite(_tempSprite2)) { - _tempSprite2 = NULL; - } - if (_anims[i]->containsSprite(_currentSprite)) { - _currentSprite = NULL; - } - if (_anims[i]->containsSprite(_animSprite2)) { - _animSprite2 = NULL; - } - - delete _anims[i]; - _anims[i] = NULL; - _anims.remove_at(i); - i--; - found = true; - } - } - stack->pushBool(found); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // HasAnim - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "HasAnim") == 0) { - stack->correctParams(1); - const char *animName = stack->pop()->getString(); - stack->pushBool(getAnimByName(animName) != NULL); - return STATUS_OK; - } else { - return AdTalkHolder::scCallMethod(script, stack, thisStack, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdActor::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Direction - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Direction") == 0) { - _scValue->setInt(_dir); - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Type") == 0) { - _scValue->setString("actor"); - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // TalkAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkAnimName") == 0) { - _scValue->setString(_talkAnimName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkAnimName") == 0) { - _scValue->setString(_walkAnimName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // IdleAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IdleAnimName") == 0) { - _scValue->setString(_idleAnimName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnLeftAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnLeftAnimName") == 0) { - _scValue->setString(_turnLeftAnimName); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnRightAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnRightAnimName") == 0) { - _scValue->setString(_turnRightAnimName); - return _scValue; - } else { - return AdTalkHolder::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdActor::scSetProperty(const char *name, ScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Direction - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Direction") == 0) { - int dir = value->getInt(); - if (dir >= 0 && dir < NUM_DIRECTIONS) { - _dir = (TDirection)dir; - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TalkAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkAnimName") == 0) { - if (value->isNULL()) { - _talkAnimName = "talk"; - } else { - _talkAnimName = value->getString(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkAnimName") == 0) { - if (value->isNULL()) { - _walkAnimName = "walk"; - } else { - _walkAnimName = value->getString(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IdleAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IdleAnimName") == 0) { - if (value->isNULL()) { - _idleAnimName = "idle"; - } else { - _idleAnimName = value->getString(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnLeftAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnLeftAnimName") == 0) { - if (value->isNULL()) { - _turnLeftAnimName = "turnleft"; - } else { - _turnLeftAnimName = value->getString(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TurnRightAnimName - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnRightAnimName") == 0) { - if (value->isNULL()) { - _turnRightAnimName = "turnright"; - } else { - _turnRightAnimName = value->getString(); - } - return STATUS_OK; - } else { - return AdTalkHolder::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdActor::scToString() { - return "[actor object]"; -} - - -////////////////////////////////////////////////////////////////////////// -BaseSprite *AdActor::getTalkStance(const char *stance) { - // forced stance? - if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { - _forcedTalkAnimUsed = true; - delete _animSprite; - _animSprite = new BaseSprite(_gameRef, this); - if (_animSprite) { - bool res = _animSprite->loadFile(_forcedTalkAnimName); - if (DID_FAIL(res)) { - _gameRef->LOG(res, "AdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); - delete _animSprite; - _animSprite = NULL; - } else { - return _animSprite; - } - } - } - - // old way - if (_talkSprites.size() > 0 || _talkSpritesEx.size() > 0) { - return getTalkStanceOld(stance); - } - - // new way - BaseSprite *ret = NULL; - - // do we have an animation with this name? - AdSpriteSet *anim = getAnimByName(stance); - if (anim) { - ret = anim->getSprite(_dir); - } - - // not - get a random talk - if (!ret) { - BaseArray talkAnims; - for (uint32 i = 0; i < _anims.size(); i++) { - if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) { - talkAnims.add(_anims[i]); - } - } - - if (talkAnims.size() > 0) { - int rnd = BaseEngine::instance().randInt(0, talkAnims.size() - 1); - ret = talkAnims[rnd]->getSprite(_dir); - } else { - if (_standSprite) { - ret = _standSprite->getSprite(_dir); - } else { - anim = getAnimByName(_idleAnimName); - if (anim) { - ret = anim->getSprite(_dir); - } - } - } - } - return ret; -} - -////////////////////////////////////////////////////////////////////////// -BaseSprite *AdActor::getTalkStanceOld(const char *stance) { - BaseSprite *ret = NULL; - - if (stance != NULL) { - // search special stances - for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { - ret = _talkSpritesEx[i]->getSprite(_dir); - break; - } - } - if (ret == NULL) { - // search generic stances - for (uint32 i = 0; i < _talkSprites.size(); i++) { - if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { - ret = _talkSprites[i]->getSprite(_dir); - break; - } - } - } - } - - // not a valid stance? get a random one - if (ret == NULL) { - if (_talkSprites.size() < 1) { - ret = _standSprite->getSprite(_dir); - } else { - // TODO: remember last - int rnd = BaseEngine::instance().randInt(0, _talkSprites.size() - 1); - ret = _talkSprites[rnd]->getSprite(_dir); - } - } - - return ret; -} - -////////////////////////////////////////////////////////////////////////// -bool AdActor::persist(BasePersistenceManager *persistMgr) { - AdTalkHolder::persist(persistMgr); - - persistMgr->transfer(TMEMBER_INT(_dir)); - persistMgr->transfer(TMEMBER(_path)); - persistMgr->transfer(TMEMBER(_pFCount)); - persistMgr->transfer(TMEMBER(_pFStepX)); - persistMgr->transfer(TMEMBER(_pFStepY)); - persistMgr->transfer(TMEMBER(_pFX)); - persistMgr->transfer(TMEMBER(_pFY)); - persistMgr->transfer(TMEMBER(_standSprite)); - _talkSprites.persist(persistMgr); - _talkSpritesEx.persist(persistMgr); - persistMgr->transfer(TMEMBER_INT(_targetDir)); - persistMgr->transfer(TMEMBER_INT(_afterWalkDir)); - persistMgr->transfer(TMEMBER(_targetPoint)); - persistMgr->transfer(TMEMBER(_turnLeftSprite)); - persistMgr->transfer(TMEMBER(_turnRightSprite)); - persistMgr->transfer(TMEMBER(_walkSprite)); - - persistMgr->transfer(TMEMBER(_animSprite2)); - persistMgr->transfer(TMEMBER(_talkAnimName)); - persistMgr->transfer(TMEMBER(_idleAnimName)); - persistMgr->transfer(TMEMBER(_walkAnimName)); - persistMgr->transfer(TMEMBER(_turnLeftAnimName)); - persistMgr->transfer(TMEMBER(_turnRightAnimName)); - - _anims.persist(persistMgr); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -TDirection AdActor::angleToDirection(int angle) { - TDirection ret = DI_DOWN;; - - if (angle > -112 && angle <= -67) { - ret = DI_UP; - } else if (angle > -67 && angle <= -22) { - ret = DI_UPRIGHT; - } else if (angle > -22 && angle <= 22) { - ret = DI_RIGHT; - } else if (angle > 22 && angle <= 67) { - ret = DI_DOWNRIGHT; - } else if (angle > 67 && angle <= 112) { - ret = DI_DOWN; - } else if (angle > 112 && angle <= 157) { - ret = DI_DOWNLEFT; - } else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) { - ret = DI_LEFT; - } else if (angle > -157 && angle <= -112) { - ret = DI_UPLEFT; - } - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -int AdActor::getHeight() { - // if no current sprite is set, set some - if (_currentSprite == NULL) { - if (_standSprite) { - _currentSprite = _standSprite->getSprite(_dir); - } else { - AdSpriteSet *anim = getAnimByName(_idleAnimName); - if (anim) { - _currentSprite = anim->getSprite(_dir); - } - } - } - // and get height - return AdTalkHolder::getHeight(); -} - - -////////////////////////////////////////////////////////////////////////// -AdSpriteSet *AdActor::getAnimByName(const Common::String &animName) { - for (uint32 i = 0; i < _anims.size(); i++) { - if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) { - return _anims[i]; - } - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -bool AdActor::mergeAnims(const char *animsFilename) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ANIMATION) - TOKEN_TABLE_END - - - byte *fileBuffer = BaseFileManager::getEngineInstance()->readWholeFile(animsFilename); - if (fileBuffer == NULL) { - _gameRef->LOG(0, "AdActor::MergeAnims failed for file '%s'", animsFilename); - return STATUS_FAILED; - } - - byte *buffer = fileBuffer; - byte *params; - int cmd; - BaseParser parser; - - bool ret = STATUS_OK; - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_ANIMATION: { - AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); - if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - ret = STATUS_FAILED; - } else { - _anims.add(anim); - } - } - break; - } - } - delete[] fileBuffer; - return ret; -} - -////////////////////////////////////////////////////////////////////////// -bool AdActor::playAnim(const char *filename) { - // if we have an anim with this name, use it - AdSpriteSet *anim = getAnimByName(filename); - if (anim) { - _animSprite2 = anim->getSprite(_dir); - if (_animSprite2) { - _animSprite2->reset(); - _state = STATE_PLAYING_ANIM_SET; - return STATUS_OK; - } - } - // otherwise call the standard handler - return AdTalkHolder::playAnim(filename); -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_actor.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/ad/ad_sprite_set.h" +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/ad/ad_path.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/particles/part_emitter.h" +#include "engines/wintermute/base/base_engine.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdActor, false) + + +////////////////////////////////////////////////////////////////////////// +AdActor::AdActor(BaseGame *inGame) : AdTalkHolder(inGame) { + _path = new AdPath(_gameRef); + + _type = OBJECT_ACTOR; + _dir = DI_LEFT; + + _walkSprite = NULL; + _standSprite = NULL; + _turnLeftSprite = NULL; + _turnRightSprite = NULL; + + _targetPoint = new BasePoint; + _afterWalkDir = DI_NONE; + + _animSprite2 = NULL; + + setDefaultAnimNames(); +} + +////////////////////////////////////////////////////////////////////////// +bool AdActor::setDefaultAnimNames() { + _talkAnimName = "talk"; + _idleAnimName = "idle"; + _walkAnimName = "walk"; + _turnLeftAnimName = "turnleft"; + _turnRightAnimName = "turnright"; + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +AdActor::~AdActor() { + delete _path; + delete _targetPoint; + _path = NULL; + _targetPoint = NULL; + + delete _walkSprite; + delete _standSprite; + delete _turnLeftSprite; + delete _turnRightSprite; + _walkSprite = NULL; + _standSprite = NULL; + _turnLeftSprite = NULL; + _turnRightSprite = NULL; + + _animSprite2 = NULL; // ref only + + for (uint32 i = 0; i < _talkSprites.size(); i++) { + delete _talkSprites[i]; + } + _talkSprites.clear(); + + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { + delete _talkSpritesEx[i]; + } + _talkSpritesEx.clear(); + + for (uint32 i = 0; i < _anims.size(); i++) { + delete _anims[i]; + _anims[i] = NULL; + } + _anims.clear(); + +} + + +////////////////////////////////////////////////////////////////////////// +bool AdActor::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdActor::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ACTOR) +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(WALK) +TOKEN_DEF(STAND) +TOKEN_DEF(TALK_SPECIAL) +TOKEN_DEF(TALK) +TOKEN_DEF(TURN_LEFT) +TOKEN_DEF(TURN_RIGHT) +TOKEN_DEF(EVENTS) +TOKEN_DEF(FONT) +TOKEN_DEF(CURSOR) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(SOUND_VOLUME) +TOKEN_DEF(SOUND_PANNING) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(BLOCKED_REGION) +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(ANIMATION) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdActor::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ACTOR) + 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(WALK) + TOKEN_TABLE(STAND) + TOKEN_TABLE(TALK_SPECIAL) + TOKEN_TABLE(TALK) + TOKEN_TABLE(TURN_LEFT) + TOKEN_TABLE(TURN_RIGHT) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(FONT) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(SOUND_VOLUME) + TOKEN_TABLE(SOUND_PANNING) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(BLOCKED_REGION) + 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(ANIMATION) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTOR) { + _gameRef->LOG(0, "'ACTOR' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + AdGame *adGame = (AdGame *)_gameRef; + AdSpriteSet *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 (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_FONT: + setFont((char *)params); + break; + + case TOKEN_SCALABLE: + parser.scanStr((char *)params, "%b", &_zoomable); + break; + + case TOKEN_ROTABLE: + case TOKEN_ROTATABLE: + parser.scanStr((char *)params, "%b", &_rotatable); + break; + + case TOKEN_REGISTRABLE: + case TOKEN_INTERACTIVE: + parser.scanStr((char *)params, "%b", &_registrable); + break; + + case TOKEN_SHADOWABLE: + case TOKEN_COLORABLE: + parser.scanStr((char *)params, "%b", &_shadowable); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_WALK: + delete _walkSprite; + _walkSprite = NULL; + spr = new AdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) { + cmd = PARSERR_GENERIC; + } else { + _walkSprite = spr; + } + break; + + case TOKEN_TALK: + spr = new AdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } + break; + + case TOKEN_TALK_SPECIAL: + spr = new AdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } + break; + + case TOKEN_STAND: + delete _standSprite; + _standSprite = NULL; + spr = new AdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _standSprite = spr; + } + break; + + case TOKEN_TURN_LEFT: + delete _turnLeftSprite; + _turnLeftSprite = NULL; + spr = new AdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { + cmd = PARSERR_GENERIC; + } else { + _turnLeftSprite = spr; + } + break; + + case TOKEN_TURN_RIGHT: + delete _turnRightSprite; + _turnRightSprite = NULL; + spr = new AdSpriteSet(_gameRef, this); + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { + cmd = PARSERR_GENERIC; + } else { + _turnRightSprite = spr; + } + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new BaseSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_SOUND_VOLUME: + parser.scanStr((char *)params, "%d", &_sFXVolume); + break; + + case TOKEN_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _scale = (float)s; + + } + break; + + case TOKEN_RELATIVE_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _relativeScale = (float)s; + + } + break; + + case TOKEN_SOUND_PANNING: + parser.scanStr((char *)params, "%b", &_autoSoundPanning); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_BLOCKED_REGION: { + delete _blockRegion; + delete _currentBlockRegion; + _blockRegion = NULL; + _currentBlockRegion = NULL; + BaseRegion *rgn = new BaseRegion(_gameRef); + BaseRegion *crgn = new BaseRegion(_gameRef); + if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { + delete _blockRegion; + delete _currentBlockRegion; + _blockRegion = NULL; + _currentBlockRegion = NULL; + cmd = PARSERR_GENERIC; + } else { + _blockRegion = rgn; + _currentBlockRegion = crgn; + _currentBlockRegion->mimic(_blockRegion); + } + } + break; + + case TOKEN_WAYPOINTS: { + delete _wptGroup; + delete _currentWptGroup; + _wptGroup = NULL; + _currentWptGroup = NULL; + AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); + AdWaypointGroup *cwpt = new AdWaypointGroup(_gameRef); + if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { + delete _wptGroup; + delete _currentWptGroup; + _wptGroup = NULL; + _currentWptGroup = NULL; + cmd = PARSERR_GENERIC; + } else { + _wptGroup = wpt; + _currentWptGroup = cwpt; + _currentWptGroup->mimic(_wptGroup); + } + } + break; + + case TOKEN_IGNORE_ITEMS: + parser.scanStr((char *)params, "%b", &_ignoreItems); + 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_ANIMATION: { + AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); + if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } else { + _anims.add(anim); + } + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ACTOR definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + if (spr) { + delete spr; + } + _gameRef->LOG(0, "Error loading ACTOR definition"); + return STATUS_FAILED; + } + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + _state = _nextState = STATE_READY; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void AdActor::turnTo(TDirection dir) { + int delta1, delta2, delta3, delta; + + delta1 = dir - _dir; + delta2 = dir + NUM_DIRECTIONS - _dir; + delta3 = dir - NUM_DIRECTIONS - _dir; + + delta1 = (abs(delta1) <= abs(delta2)) ? delta1 : delta2; + delta = (abs(delta1) <= abs(delta3)) ? delta1 : delta3; + + // already there? + if (abs(delta) < 2) { + _dir = dir; + _state = _nextState; + _nextState = STATE_READY; + return; + } + + _targetDir = dir; + _state = delta < 0 ? STATE_TURNING_LEFT : STATE_TURNING_RIGHT; + + _tempSprite2 = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void AdActor::goTo(int x, int y, TDirection afterWalkDir) { + _afterWalkDir = afterWalkDir; + if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) { + return; + } + + _path->reset(); + _path->setReady(false); + + _targetPoint->x = x; + _targetPoint->y = y; + + ((AdGame *)_gameRef)->_scene->correctTargetPoint(_posX, _posY, &_targetPoint->x, &_targetPoint->y, true, this); + + _state = STATE_SEARCHING_PATH; + +} + + +////////////////////////////////////////////////////////////////////////// +bool AdActor::display() { + if (_active) { + updateSounds(); + } + + uint32 alpha; + if (_alphaColor != 0) { + alpha = _alphaColor; + } else { + alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; + } + + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + + float rotate; + if (_rotatable) { + if (_rotateValid) { + rotate = _rotate; + } else { + rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } + } else { + rotate = 0.0f; + } + + if (_active) { + displaySpriteAttachments(true); + } + + if (_currentSprite && _active) { + bool reg = _registrable; + if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) { + reg = false; + } + + _currentSprite->display(_posX, + _posY, + reg ? _registerAlias : NULL, + scaleX, + scaleY, + alpha, + rotate, + _blendMode); + + } + + if (_active) { + displaySpriteAttachments(false); + } + if (_active && _partEmitter) { + _partEmitter->display(); + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdActor::update() { + _currentSprite = NULL; + + if (_state == STATE_READY) { + if (_animSprite) { + delete _animSprite; + _animSprite = NULL; + } + if (_animSprite2) { + _animSprite2 = NULL; + } + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = _nextState; + _nextState = STATE_READY; + _currentSprite = _animSprite; + } + + if (_state == STATE_PLAYING_ANIM_SET && _animSprite2 != NULL && _animSprite2->_finished) { + _state = _nextState; + _nextState = STATE_READY; + _currentSprite = _animSprite2; + } + + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } + + // default: stand animation + if (!_currentSprite) { + if (_sprite) { + _currentSprite = _sprite; + } else { + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } + } + } + } + + bool already_moved = false; + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM_SET: + _currentSprite = _animSprite2; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TURNING_LEFT: + if (_tempSprite2 == NULL || _tempSprite2->_finished) { + if (_dir > 0) { + _dir = (TDirection)(_dir - 1); + } else { + _dir = (TDirection)(NUM_DIRECTIONS - 1); + } + + if (_dir == _targetDir) { + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + if (_turnLeftSprite) { + _tempSprite2 = _turnLeftSprite->getSprite(_dir); + } else { + AdSpriteSet *anim = getAnimByName(_turnLeftAnimName); + if (anim) { + _tempSprite2 = anim->getSprite(_dir); + } + } + + if (_tempSprite2) { + _tempSprite2->reset(); + if (_tempSprite2->_looping) { + _tempSprite2->_looping = false; + } + } + _currentSprite = _tempSprite2; + } + } else { + _currentSprite = _tempSprite2; + } + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_TURNING_RIGHT: + if (_tempSprite2 == NULL || _tempSprite2->_finished) { + _dir = (TDirection)(_dir + 1); + + if ((int)_dir >= (int)NUM_DIRECTIONS) { + _dir = (TDirection)(0); + } + + if (_dir == _targetDir) { + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + if (_turnRightSprite) { + _tempSprite2 = _turnRightSprite->getSprite(_dir); + } else { + AdSpriteSet *anim = getAnimByName(_turnRightAnimName); + if (anim) { + _tempSprite2 = anim->getSprite(_dir); + } + } + + if (_tempSprite2) { + _tempSprite2->reset(); + if (_tempSprite2->_looping) { + _tempSprite2->_looping = false; + } + } + _currentSprite = _tempSprite2; + } + } else { + _currentSprite = _tempSprite2; + } + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_SEARCHING_PATH: + // keep asking scene for the path + if (((AdGame *)_gameRef)->_scene->getPath(BasePoint(_posX, _posY), *_targetPoint, _path, this)) { + _state = STATE_WAITING_PATH; + } + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_WAITING_PATH: + // wait until the scene finished the path + if (_path->_ready) { + followPath(); + } + break; + + + ////////////////////////////////////////////////////////////////////////// + case STATE_FOLLOWING_PATH: + getNextStep(); + already_moved = true; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(_dir); + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } + + bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (timeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = _nextState; + _nextState = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + ((AdGame *)_gameRef)->addSentence(_sentence); + } + } + } else { + _currentSprite = _tempSprite2; + ((AdGame *)_gameRef)->addSentence(_sentence); + } + } + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite && !_animSprite2) { + if (_sprite) { + _currentSprite = _sprite; + } else { + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } + } + } + } + break; + default: + error("AdActor::Update - Unhandled enum"); + } + + + if (_currentSprite && !already_moved) { + _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (_currentSprite->_changed) { + _posX += _currentSprite->_moveX; + _posY += _currentSprite->_moveY; + afterMove(); + } + } + + //_gameRef->QuickMessageForm("%s", _currentSprite->_filename); + + updateBlockRegion(); + _ready = (_state == STATE_READY); + + updatePartEmitter(); + updateSpriteAttachments(); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void AdActor::followPath() { + // skip current position + _path->getFirst(); + while (_path->getCurrent() != NULL) { + if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) { + break; + } + _path->getNext(); + } + + // are there points to follow? + if (_path->getCurrent() != NULL) { + _state = STATE_FOLLOWING_PATH;; + initLine(BasePoint(_posX, _posY), *_path->getCurrent()); + } else { + if (_afterWalkDir != DI_NONE) { + turnTo(_afterWalkDir); + } else { + _state = STATE_READY; + } + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdActor::getNextStep() { + if (_walkSprite) { + _currentSprite = _walkSprite->getSprite(_dir); + } else { + AdSpriteSet *anim = getAnimByName(_walkAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } + } + + if (!_currentSprite) { + return; + } + + _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (!_currentSprite->_changed) { + return; + } + + + int maxStepX, maxStepY; + maxStepX = abs(_currentSprite->_moveX); + maxStepY = abs(_currentSprite->_moveY); + + maxStepX = MAX(maxStepX, maxStepY); + maxStepX = MAX(maxStepX, 1); + + while (_pFCount > 0 && maxStepX >= 0) { + _pFX += _pFStepX; + _pFY += _pFStepY; + + _pFCount--; + maxStepX--; + } + + if (((AdGame *)_gameRef)->_scene->isBlockedAt((int)_pFX, (int) _pFY, true, this)) { + if (_pFCount == 0) { + _state = _nextState; + _nextState = STATE_READY; + return; + } + goTo(_targetPoint->x, _targetPoint->y); + return; + } + + + _posX = (int)_pFX; + _posY = (int)_pFY; + + afterMove(); + + + if (_pFCount == 0) { + if (_path->getNext() == NULL) { + _posX = _targetPoint->x; + _posY = _targetPoint->y; + + _path->reset(); + if (_afterWalkDir != DI_NONE) { + turnTo(_afterWalkDir); + } else { + _state = _nextState; + _nextState = STATE_READY; + } + } else { + initLine(BasePoint(_posX, _posY), *_path->getCurrent()); + } + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdActor::initLine(BasePoint startPt, BasePoint endPt) { + _pFCount = MAX((abs(endPt.x - startPt.x)) , (abs(endPt.y - startPt.y))); + + _pFStepX = (double)(endPt.x - startPt.x) / _pFCount; + _pFStepY = (double)(endPt.y - startPt.y) / _pFCount; + + _pFX = startPt.x; + _pFY = startPt.y; + + int angle = (int)(atan2((double)(endPt.y - startPt.y), (double)(endPt.x - startPt.x)) * (180 / 3.14)); + + _nextState = STATE_FOLLOWING_PATH; + + turnTo(angleToDirection(angle)); +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // GoTo / GoToAsync + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "GoTo") == 0 || strcmp(name, "GoToAsync") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + goTo(x, y); + if (strcmp(name, "GoToAsync") != 0) { + script->waitForExclusive(this); + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GoToObject / GoToObjectAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GoToObject") == 0 || strcmp(name, "GoToObjectAsync") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + if (!val->isNative()) { + script->runtimeError("actor.%s method accepts an entity refrence only", name); + stack->pushNULL(); + return STATUS_OK; + } + AdObject *obj = (AdObject *)val->getNative(); + if (!obj || obj->_type != OBJECT_ENTITY) { + script->runtimeError("actor.%s method accepts an entity refrence only", name); + stack->pushNULL(); + return STATUS_OK; + } + AdEntity *ent = (AdEntity *)obj; + if (ent->_walkToX == 0 && ent->_walkToY == 0) { + goTo(ent->_posX, ent->_posY); + } else { + goTo(ent->_walkToX, ent->_walkToY, ent->_walkToDir); + } + if (strcmp(name, "GoToObjectAsync") != 0) { + script->waitForExclusive(this); + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnTo / TurnToAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnTo") == 0 || strcmp(name, "TurnToAsync") == 0) { + stack->correctParams(1); + int dir; + ScValue *val = stack->pop(); + + // turn to object? + if (val->isNative() && _gameRef->validObject((BaseObject *)val->getNative())) { + BaseObject *obj = (BaseObject *)val->getNative(); + int angle = (int)(atan2((double)(obj->_posY - _posY), (double)(obj->_posX - _posX)) * (180 / 3.14)); + dir = (int)angleToDirection(angle); + } + // otherwise turn to direction + else { + dir = val->getInt(); + } + + if (dir >= 0 && dir < NUM_DIRECTIONS) { + turnTo((TDirection)dir); + if (strcmp(name, "TurnToAsync") != 0) { + script->waitForExclusive(this); + } + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsWalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsWalking") == 0) { + stack->correctParams(0); + stack->pushBool(_state == STATE_FOLLOWING_PATH); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // MergeAnims + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MergeAnims") == 0) { + stack->correctParams(1); + stack->pushBool(DID_SUCCEED(mergeAnims(stack->pop()->getString()))); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadAnim") == 0) { + stack->correctParams(1); + const char *animName = stack->pop()->getString(); + + bool found = false; + for (uint32 i = 0; i < _anims.size(); i++) { + if (scumm_stricmp(_anims[i]->getName(), animName) == 0) { + // invalidate sprites in use + if (_anims[i]->containsSprite(_tempSprite2)) { + _tempSprite2 = NULL; + } + if (_anims[i]->containsSprite(_currentSprite)) { + _currentSprite = NULL; + } + if (_anims[i]->containsSprite(_animSprite2)) { + _animSprite2 = NULL; + } + + delete _anims[i]; + _anims[i] = NULL; + _anims.remove_at(i); + i--; + found = true; + } + } + stack->pushBool(found); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // HasAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasAnim") == 0) { + stack->correctParams(1); + const char *animName = stack->pop()->getString(); + stack->pushBool(getAnimByName(animName) != NULL); + return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdActor::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Direction + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Direction") == 0) { + _scValue->setInt(_dir); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Type") == 0) { + _scValue->setString("actor"); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // TalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkAnimName") == 0) { + _scValue->setString(_talkAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkAnimName") == 0) { + _scValue->setString(_walkAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // IdleAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IdleAnimName") == 0) { + _scValue->setString(_idleAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnLeftAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnLeftAnimName") == 0) { + _scValue->setString(_turnLeftAnimName); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnRightAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnRightAnimName") == 0) { + _scValue->setString(_turnRightAnimName); + return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdActor::scSetProperty(const char *name, ScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Direction + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Direction") == 0) { + int dir = value->getInt(); + if (dir >= 0 && dir < NUM_DIRECTIONS) { + _dir = (TDirection)dir; + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkAnimName") == 0) { + if (value->isNULL()) { + _talkAnimName = "talk"; + } else { + _talkAnimName = value->getString(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkAnimName") == 0) { + if (value->isNULL()) { + _walkAnimName = "walk"; + } else { + _walkAnimName = value->getString(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IdleAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IdleAnimName") == 0) { + if (value->isNULL()) { + _idleAnimName = "idle"; + } else { + _idleAnimName = value->getString(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnLeftAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnLeftAnimName") == 0) { + if (value->isNULL()) { + _turnLeftAnimName = "turnleft"; + } else { + _turnLeftAnimName = value->getString(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TurnRightAnimName + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TurnRightAnimName") == 0) { + if (value->isNULL()) { + _turnRightAnimName = "turnright"; + } else { + _turnRightAnimName = value->getString(); + } + return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdActor::scToString() { + return "[actor object]"; +} + + +////////////////////////////////////////////////////////////////////////// +BaseSprite *AdActor::getTalkStance(const char *stance) { + // forced stance? + if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { + _forcedTalkAnimUsed = true; + delete _animSprite; + _animSprite = new BaseSprite(_gameRef, this); + if (_animSprite) { + bool res = _animSprite->loadFile(_forcedTalkAnimName); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "AdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); + delete _animSprite; + _animSprite = NULL; + } else { + return _animSprite; + } + } + } + + // old way + if (_talkSprites.size() > 0 || _talkSpritesEx.size() > 0) { + return getTalkStanceOld(stance); + } + + // new way + BaseSprite *ret = NULL; + + // do we have an animation with this name? + AdSpriteSet *anim = getAnimByName(stance); + if (anim) { + ret = anim->getSprite(_dir); + } + + // not - get a random talk + if (!ret) { + BaseArray talkAnims; + for (uint32 i = 0; i < _anims.size(); i++) { + if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) { + talkAnims.add(_anims[i]); + } + } + + if (talkAnims.size() > 0) { + int rnd = BaseEngine::instance().randInt(0, talkAnims.size() - 1); + ret = talkAnims[rnd]->getSprite(_dir); + } else { + if (_standSprite) { + ret = _standSprite->getSprite(_dir); + } else { + anim = getAnimByName(_idleAnimName); + if (anim) { + ret = anim->getSprite(_dir); + } + } + } + } + return ret; +} + +////////////////////////////////////////////////////////////////////////// +BaseSprite *AdActor::getTalkStanceOld(const char *stance) { + BaseSprite *ret = NULL; + + if (stance != NULL) { + // search special stances + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { + ret = _talkSpritesEx[i]->getSprite(_dir); + break; + } + } + if (ret == NULL) { + // search generic stances + for (uint32 i = 0; i < _talkSprites.size(); i++) { + if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { + ret = _talkSprites[i]->getSprite(_dir); + break; + } + } + } + } + + // not a valid stance? get a random one + if (ret == NULL) { + if (_talkSprites.size() < 1) { + ret = _standSprite->getSprite(_dir); + } else { + // TODO: remember last + int rnd = BaseEngine::instance().randInt(0, _talkSprites.size() - 1); + ret = _talkSprites[rnd]->getSprite(_dir); + } + } + + return ret; +} + +////////////////////////////////////////////////////////////////////////// +bool AdActor::persist(BasePersistenceManager *persistMgr) { + AdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER_INT(_dir)); + persistMgr->transfer(TMEMBER(_path)); + persistMgr->transfer(TMEMBER(_pFCount)); + persistMgr->transfer(TMEMBER(_pFStepX)); + persistMgr->transfer(TMEMBER(_pFStepY)); + persistMgr->transfer(TMEMBER(_pFX)); + persistMgr->transfer(TMEMBER(_pFY)); + persistMgr->transfer(TMEMBER(_standSprite)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + persistMgr->transfer(TMEMBER_INT(_targetDir)); + persistMgr->transfer(TMEMBER_INT(_afterWalkDir)); + persistMgr->transfer(TMEMBER(_targetPoint)); + persistMgr->transfer(TMEMBER(_turnLeftSprite)); + persistMgr->transfer(TMEMBER(_turnRightSprite)); + persistMgr->transfer(TMEMBER(_walkSprite)); + + persistMgr->transfer(TMEMBER(_animSprite2)); + persistMgr->transfer(TMEMBER(_talkAnimName)); + persistMgr->transfer(TMEMBER(_idleAnimName)); + persistMgr->transfer(TMEMBER(_walkAnimName)); + persistMgr->transfer(TMEMBER(_turnLeftAnimName)); + persistMgr->transfer(TMEMBER(_turnRightAnimName)); + + _anims.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +TDirection AdActor::angleToDirection(int angle) { + TDirection ret = DI_DOWN;; + + if (angle > -112 && angle <= -67) { + ret = DI_UP; + } else if (angle > -67 && angle <= -22) { + ret = DI_UPRIGHT; + } else if (angle > -22 && angle <= 22) { + ret = DI_RIGHT; + } else if (angle > 22 && angle <= 67) { + ret = DI_DOWNRIGHT; + } else if (angle > 67 && angle <= 112) { + ret = DI_DOWN; + } else if (angle > 112 && angle <= 157) { + ret = DI_DOWNLEFT; + } else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) { + ret = DI_LEFT; + } else if (angle > -157 && angle <= -112) { + ret = DI_UPLEFT; + } + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +int AdActor::getHeight() { + // if no current sprite is set, set some + if (_currentSprite == NULL) { + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } + } + } + // and get height + return AdTalkHolder::getHeight(); +} + + +////////////////////////////////////////////////////////////////////////// +AdSpriteSet *AdActor::getAnimByName(const Common::String &animName) { + for (uint32 i = 0; i < _anims.size(); i++) { + if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) { + return _anims[i]; + } + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +bool AdActor::mergeAnims(const char *animsFilename) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ANIMATION) + TOKEN_TABLE_END + + + byte *fileBuffer = BaseFileManager::getEngineInstance()->readWholeFile(animsFilename); + if (fileBuffer == NULL) { + _gameRef->LOG(0, "AdActor::MergeAnims failed for file '%s'", animsFilename); + return STATUS_FAILED; + } + + byte *buffer = fileBuffer; + byte *params; + int cmd; + BaseParser parser; + + bool ret = STATUS_OK; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_ANIMATION: { + AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); + if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + ret = STATUS_FAILED; + } else { + _anims.add(anim); + } + } + break; + } + } + delete[] fileBuffer; + return ret; +} + +////////////////////////////////////////////////////////////////////////// +bool AdActor::playAnim(const char *filename) { + // if we have an anim with this name, use it + AdSpriteSet *anim = getAnimByName(filename); + if (anim) { + _animSprite2 = anim->getSprite(_dir); + if (_animSprite2) { + _animSprite2->reset(); + _state = STATE_PLAYING_ANIM_SET; + return STATUS_OK; + } + } + // otherwise call the standard handler + return AdTalkHolder::playAnim(filename); +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index 370a91cc22..271e57cb85 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -1,108 +1,108 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADACTOR_H -#define WINTERMUTE_ADACTOR_H - - -#include "engines/wintermute/dctypes.h" // Added by ClassView -#include "engines/wintermute/ad/ad_types.h" // Added by ClassView -#include "engines/wintermute/ad/ad_talk_holder.h" -#include "engines/wintermute/coll_templ.h" -#include "engines/wintermute/base/base_point.h" // Added by ClassView -#include "engines/wintermute/persistent.h" -#include "common/str.h" - -namespace Wintermute { - -class AdSpriteSet; -class AdPath; -class BaseSprite; -class AdActor : public AdTalkHolder { -public: - TDirection angleToDirection(int angle); - DECLARE_PERSISTENT(AdActor, AdTalkHolder) - virtual int getHeight(); - BaseSprite *getTalkStance(const char *stance); - virtual void goTo(int x, int y, TDirection afterWalkDir = DI_NONE); - BasePoint *_targetPoint; - virtual bool update(); - virtual bool display(); - virtual void turnTo(TDirection dir); - AdActor(BaseGame *inGame/*=NULL*/); - virtual ~AdActor(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - - -private: - TDirection _targetDir; - TDirection _afterWalkDir; - - AdPath *_path; - AdSpriteSet *_walkSprite; - AdSpriteSet *_standSprite; - AdSpriteSet *_turnLeftSprite; - AdSpriteSet *_turnRightSprite; - BaseArray _talkSprites; - BaseArray _talkSpritesEx; - TDirection _dir; - // new anim system - Common::String _talkAnimName; - Common::String _idleAnimName; - Common::String _walkAnimName; - Common::String _turnLeftAnimName; - Common::String _turnRightAnimName; - BaseArray _anims; - virtual bool playAnim(const char *filename); - AdSpriteSet *getAnimByName(const Common::String &animName); - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - virtual const char *scToString(); - - bool setDefaultAnimNames(); - BaseSprite *getTalkStanceOld(const char *stance); - bool mergeAnims(const char *animsFilename); - BaseSprite *_animSprite2; - - void initLine(BasePoint startPt, BasePoint endPt); - void getNextStep(); - void followPath(); - double _pFStepX; - double _pFStepY; - double _pFX; - double _pFY; - int _pFCount; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADACTOR_H +#define WINTERMUTE_ADACTOR_H + + +#include "engines/wintermute/dctypes.h" // Added by ClassView +#include "engines/wintermute/ad/ad_types.h" // Added by ClassView +#include "engines/wintermute/ad/ad_talk_holder.h" +#include "engines/wintermute/coll_templ.h" +#include "engines/wintermute/base/base_point.h" // Added by ClassView +#include "engines/wintermute/persistent.h" +#include "common/str.h" + +namespace Wintermute { + +class AdSpriteSet; +class AdPath; +class BaseSprite; +class AdActor : public AdTalkHolder { +public: + TDirection angleToDirection(int angle); + DECLARE_PERSISTENT(AdActor, AdTalkHolder) + virtual int getHeight(); + BaseSprite *getTalkStance(const char *stance); + virtual void goTo(int x, int y, TDirection afterWalkDir = DI_NONE); + BasePoint *_targetPoint; + virtual bool update(); + virtual bool display(); + virtual void turnTo(TDirection dir); + AdActor(BaseGame *inGame/*=NULL*/); + virtual ~AdActor(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + + +private: + TDirection _targetDir; + TDirection _afterWalkDir; + + AdPath *_path; + AdSpriteSet *_walkSprite; + AdSpriteSet *_standSprite; + AdSpriteSet *_turnLeftSprite; + AdSpriteSet *_turnRightSprite; + BaseArray _talkSprites; + BaseArray _talkSpritesEx; + TDirection _dir; + // new anim system + Common::String _talkAnimName; + Common::String _idleAnimName; + Common::String _walkAnimName; + Common::String _turnLeftAnimName; + Common::String _turnRightAnimName; + BaseArray _anims; + virtual bool playAnim(const char *filename); + AdSpriteSet *getAnimByName(const Common::String &animName); + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + virtual const char *scToString(); + + bool setDefaultAnimNames(); + BaseSprite *getTalkStanceOld(const char *stance); + bool mergeAnims(const char *animsFilename); + BaseSprite *_animSprite2; + + void initLine(BasePoint startPt, BasePoint endPt); + void getNextStep(); + void followPath(); + double _pFStepX; + double _pFStepY; + double _pFX; + double _pFY; + int _pFCount; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 67a919dd6b..234af1fffa 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -1,1121 +1,1121 @@ -/* 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. - - * 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. - - * 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 - */ - - -#include "engines/wintermute/ad/ad_entity.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_active_rect.h" -#include "engines/wintermute/base/base_surface_storage.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_scene.h" -#include "engines/wintermute/base/sound/base_sound.h" -#include "engines/wintermute/ad/ad_waypoint_group.h" -#include "engines/wintermute/base/font/base_font_storage.h" -#include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/ad/ad_sentence.h" -#include "engines/wintermute/base/base_region.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/video/video_theora_player.h" -#include "engines/wintermute/base/particles/part_emitter.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdEntity, false) - -////////////////////////////////////////////////////////////////////////// -AdEntity::AdEntity(BaseGame *inGame) : AdTalkHolder(inGame) { - _type = OBJECT_ENTITY; - _subtype = ENTITY_NORMAL; - _region = NULL; - _item = NULL; - - _walkToX = _walkToY = 0; - _walkToDir = DI_NONE; - - _theora = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdEntity::~AdEntity() { - _gameRef->unregisterObject(_region); - - delete _theora; - _theora = NULL; - - delete[] _item; - _item = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdEntity::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdEntity::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->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 -////////////////////////////////////////////////////////////////////////// -bool AdEntity::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; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY) { - _gameRef->LOG(0, "'ENTITY' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - AdGame *adGame = (AdGame *)_gameRef; - BaseSprite *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 (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_X: - parser.scanStr((char *)params, "%d", &_posX); - break; - - case TOKEN_Y: - parser.scanStr((char *)params, "%d", &_posY); - break; - - case TOKEN_SPRITE: { - delete _sprite; - _sprite = NULL; - spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } else { - _sprite = spr; - } - } - break; - - case TOKEN_TALK: { - spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { - cmd = PARSERR_GENERIC; - } else { - _talkSprites.add(spr); - } - } - break; - - case TOKEN_TALK_SPECIAL: { - spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { - cmd = PARSERR_GENERIC; - } else { - _talkSpritesEx.add(spr); - } - } - 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: - parser.scanStr((char *)params, "%b", &_zoomable); - break; - - case TOKEN_SCALE: { - int s; - parser.scanStr((char *)params, "%d", &s); - _scale = (float)s; - - } - break; - - case TOKEN_RELATIVE_SCALE: { - int s; - parser.scanStr((char *)params, "%d", &s); - _relativeScale = (float)s; - - } - break; - - case TOKEN_ROTABLE: - case TOKEN_ROTATABLE: - parser.scanStr((char *)params, "%b", &_rotatable); - break; - - case TOKEN_REGISTRABLE: - case TOKEN_INTERACTIVE: - parser.scanStr((char *)params, "%b", &_registrable); - break; - - case TOKEN_SHADOWABLE: - case TOKEN_COLORABLE: - parser.scanStr((char *)params, "%b", &_shadowable); - break; - - case TOKEN_ACTIVE: - parser.scanStr((char *)params, "%b", &_active); - break; - - case TOKEN_CURSOR: - delete _cursor; - _cursor = new BaseSprite(_gameRef); - if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { - delete _cursor; - _cursor = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_EDITOR_SELECTED: - parser.scanStr((char *)params, "%b", &_editorSelected); - break; - - case TOKEN_REGION: { - if (_region) { - _gameRef->unregisterObject(_region); - } - _region = NULL; - BaseRegion *rgn = new BaseRegion(_gameRef); - if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - } else { - _region = rgn; - _gameRef->registerObject(_region); - } - } - break; - - case TOKEN_BLOCKED_REGION: { - delete _blockRegion; - _blockRegion = NULL; - delete _currentBlockRegion; - _currentBlockRegion = NULL; - BaseRegion *rgn = new BaseRegion(_gameRef); - BaseRegion *crgn = new BaseRegion(_gameRef); - if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { - delete _blockRegion; - _blockRegion = NULL; - delete _currentBlockRegion; - _currentBlockRegion = NULL; - cmd = PARSERR_GENERIC; - } else { - _blockRegion = rgn; - _currentBlockRegion = crgn; - _currentBlockRegion->mimic(_blockRegion); - } - } - break; - - case TOKEN_WAYPOINTS: { - delete _wptGroup; - _wptGroup = NULL; - delete _currentWptGroup; - _currentWptGroup = NULL; - AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); - AdWaypointGroup *cwpt = new AdWaypointGroup(_gameRef); - if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { - delete _wptGroup; - _wptGroup = NULL; - delete _currentWptGroup; - _currentWptGroup = NULL; - cmd = PARSERR_GENERIC; - } else { - _wptGroup = wpt; - _currentWptGroup = cwpt; - _currentWptGroup->mimic(_wptGroup); - } - } - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_SUBTYPE: { - if (scumm_stricmp((char *)params, "sound") == 0) { - delete _sprite; - _sprite = NULL; - if (_gameRef->_editorMode) { - spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) { - cmd = PARSERR_GENERIC; - } else { - _sprite = spr; - } - } - if (_gameRef->_editorMode) { - _editorOnly = true; - } - _zoomable = false; - _rotatable = false; - _registrable = _gameRef->_editorMode; - _shadowable = false; - _subtype = ENTITY_SOUND; - } - } - break; - - case TOKEN_SOUND: - playSFX((char *)params, false, false); - break; - - case TOKEN_SOUND_START_TIME: - parser.scanStr((char *)params, "%d", &_sFXStart); - break; - - case TOKEN_SOUND_VOLUME: - parser.scanStr((char *)params, "%d", &_sFXVolume); - break; - - case TOKEN_SOUND_PANNING: - parser.scanStr((char *)params, "%b", &_autoSoundPanning); - break; - - case TOKEN_SAVE_STATE: - parser.scanStr((char *)params, "%b", &_saveState); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_IGNORE_ITEMS: - parser.scanStr((char *)params, "%b", &_ignoreItems); - 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: - parser.scanStr((char *)params, "%d", &_walkToX); - break; - - case TOKEN_WALK_TO_Y: - parser.scanStr((char *)params, "%d", &_walkToY); - 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; - } - _walkToDir = (TDirection)i; - } - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ENTITY definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading ENTITY definition"); - if (spr) { - delete spr; - } - return STATUS_FAILED; - } - - if (_region && _sprite) { - _gameRef->LOG(0, "Warning: Entity '%s' has both sprite and region.", getName()); - } - - updatePosition(); - - if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { - ar = ag = ab = 255; - } - _alphaColor = BYTETORGBA(ar, ag, ab, alpha); - _state = STATE_READY; - - if (_item && ((AdGame *)_gameRef)->isItemTaken(_item)) { - _active = false; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdEntity::display() { - if (_active) { - updateSounds(); - - uint32 alpha; - if (_alphaColor != 0) { - alpha = _alphaColor; - } else { - alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; - } - - float scaleX, scaleY; - getScale(&scaleX, &scaleY); - - float rotate; - if (_rotatable) { - if (_rotateValid) { - rotate = _rotate; - } else { - rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; - } - } else { - rotate = 0.0f; - } - - - bool reg = _registrable; - if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) { - reg = false; - } - - if (_region && (reg || _editorAlwaysRegister)) { - _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); - } - - displaySpriteAttachments(true); - if (_theora && (_theora->isPlaying() || _theora->isPaused())) { - _theora->display(alpha); - } else if (_currentSprite) { - _currentSprite->display(_posX, - _posY, - (reg || _editorAlwaysRegister) ? _registerAlias : NULL, - scaleX, - scaleY, - alpha, - rotate, - _blendMode); - } - displaySpriteAttachments(false); - - if (_partEmitter) { - _partEmitter->display(_region); - } - - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdEntity::update() { - _currentSprite = NULL; - - if (_state == STATE_READY && _animSprite) { - delete _animSprite; - _animSprite = NULL; - } - - // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { - _state = STATE_READY; - _currentSprite = _animSprite; - } - - if (_sentence && _state != STATE_TALKING) { - _sentence->finish(); - } - - // default: stand animation - if (!_currentSprite) { - _currentSprite = _sprite; - } - - switch (_state) { - ////////////////////////////////////////////////////////////////////////// - case STATE_PLAYING_ANIM: - _currentSprite = _animSprite; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_READY: - if (!_animSprite) { - _currentSprite = _sprite; - } - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_TALKING: { - _sentence->update(); - if (_sentence->_currentSprite) { - _tempSprite2 = _sentence->_currentSprite; - } - - bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { - if (timeIsUp) { - _sentence->finish(); - _tempSprite2 = NULL; - _state = STATE_READY; - } else { - _tempSprite2 = getTalkStance(_sentence->getNextStance()); - if (_tempSprite2) { - _tempSprite2->reset(); - _currentSprite = _tempSprite2; - } - ((AdGame *)_gameRef)->addSentence(_sentence); - } - } else { - _currentSprite = _tempSprite2; - ((AdGame *)_gameRef)->addSentence(_sentence); - } - } - break; - default: // Silence unhandled enum-warning - break; - } - - - if (_currentSprite) { - _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (_currentSprite->_changed) { - _posX += _currentSprite->_moveX; - _posY += _currentSprite->_moveY; - } - } - - updateBlockRegion(); - _ready = (_state == STATE_READY); - - if (_theora) { - int offsetX, offsetY; - _gameRef->getOffset(&offsetX, &offsetY); - _theora->_posX = _posX - offsetX; - _theora->_posY = _posY - offsetY; - - _theora->update(); - if (_theora->isFinished()) { - _theora->stop(); - delete _theora; - _theora = NULL; - } - } - - updatePartEmitter(); - updateSpriteAttachments(); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // StopSound - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "StopSound") == 0 && _subtype == ENTITY_SOUND) { - stack->correctParams(0); - - if (DID_FAIL(stopSFX(false))) { - stack->pushBool(false); - } else { - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // PlayTheora - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PlayTheora") == 0) { - stack->correctParams(4); - const char *filename = stack->pop()->getString(); - bool looping = stack->pop()->getBool(false); - ScValue *valAlpha = stack->pop(); - int startTime = stack->pop()->getInt(); - - delete _theora; - _theora = new VideoTheoraPlayer(_gameRef); - if (_theora && DID_SUCCEED(_theora->initialize(filename))) { - if (!valAlpha->isNULL()) { - _theora->setAlphaImage(valAlpha->getString()); - } - _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); - //if (_scale>=0) _theora->_playZoom = _scale; - stack->pushBool(true); - } else { - script->runtimeError("Entity.PlayTheora - error playing video '%s'", filename); - stack->pushBool(false); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // StopTheora - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StopTheora") == 0) { - stack->correctParams(0); - if (_theora) { - _theora->stop(); - delete _theora; - _theora = NULL; - stack->pushBool(true); - } else { - stack->pushBool(false); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsTheoraPlaying - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsTheoraPlaying") == 0) { - stack->correctParams(0); - if (_theora && _theora->isPlaying()) { - stack->pushBool(true); - } else { - stack->pushBool(false); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // PauseTheora - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PauseTheora") == 0) { - stack->correctParams(0); - if (_theora && _theora->isPlaying()) { - _theora->pause(); - stack->pushBool(true); - } else { - stack->pushBool(false); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ResumeTheora - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ResumeTheora") == 0) { - stack->correctParams(0); - if (_theora && _theora->isPaused()) { - _theora->resume(); - stack->pushBool(true); - } else { - stack->pushBool(false); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsTheoraPaused - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsTheoraPaused") == 0) { - stack->correctParams(0); - if (_theora && _theora->isPaused()) { - stack->pushBool(true); - } else { - stack->pushBool(false); - } - - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // CreateRegion - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateRegion") == 0) { - stack->correctParams(0); - if (!_region) { - _region = new BaseRegion(_gameRef); - _gameRef->registerObject(_region); - } - if (_region) { - stack->pushNative(_region, true); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteRegion - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteRegion") == 0) { - stack->correctParams(0); - if (_region) { - _gameRef->unregisterObject(_region); - _region = NULL; - stack->pushBool(true); - } else { - stack->pushBool(false); - } - - return STATUS_OK; - } else { - return AdTalkHolder::scCallMethod(script, stack, thisStack, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdEntity::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type (RO) - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("entity"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Item - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Item") == 0) { - if (_item) { - _scValue->setString(_item); - } else { - _scValue->setNULL(); - } - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Subtype (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Subtype") == 0) { - if (_subtype == ENTITY_SOUND) { - _scValue->setString("sound"); - } else { - _scValue->setString("normal"); - } - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToX") == 0) { - _scValue->setInt(_walkToX); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToY") == 0) { - _scValue->setInt(_walkToY); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToDirection - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToDirection") == 0) { - _scValue->setInt((int)_walkToDir); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Region (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Region") == 0) { - if (_region) { - _scValue->setNative(_region, true); - } else { - _scValue->setNULL(); - } - return _scValue; - } else { - return AdTalkHolder::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdEntity::scSetProperty(const char *name, ScValue *value) { - - ////////////////////////////////////////////////////////////////////////// - // Item - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Item") == 0) { - setItem(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToX") == 0) { - _walkToX = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToY") == 0) { - _walkToY = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // WalkToDirection - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToDirection") == 0) { - int dir = value->getInt(); - if (dir >= 0 && dir < NUM_DIRECTIONS) { - _walkToDir = (TDirection)dir; - } - return STATUS_OK; - } else { - return AdTalkHolder::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdEntity::scToString() { - return "[entity object]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "ENTITY {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - if (_subtype == ENTITY_SOUND) { - buffer->putTextIndent(indent + 2, "SUBTYPE=\"SOUND\"\n"); - } - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - 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); - } - - for (uint32 i = 0; i < _scripts.size(); i++) { - buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); - } - - if (_subtype == ENTITY_NORMAL && _sprite && _sprite->getFilename()) { - buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->getFilename()); - } - - if (_subtype == ENTITY_SOUND && _sFX && _sFX->getFilename()) { - buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sFX->getFilename()); - buffer->putTextIndent(indent + 2, "SOUND_START_TIME=%d\n", _sFXStart); - buffer->putTextIndent(indent + 2, "SOUND_VOLUME=%d\n", _sFXVolume); - } - - - if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) { - buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alphaColor), RGBCOLGetG(_alphaColor), RGBCOLGetB(_alphaColor)); - } - - if (RGBCOLGetA(_alphaColor) != 0) { - buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alphaColor)); - } - - if (_scale >= 0) { - buffer->putTextIndent(indent + 2, "SCALE = %d\n", (int)_scale); - } - - if (_relativeScale != 0) { - buffer->putTextIndent(indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale); - } - - if (_font && _font->getFilename()) { - buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); - } - - if (_cursor && _cursor->getFilename()) { - buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); - } - - AdTalkHolder::saveAsText(buffer, indent + 2); - - if (_region) { - _region->saveAsText(buffer, indent + 2); - } - - if (_scProp) { - _scProp->saveAsText(buffer, indent + 2); - } - - AdObject::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -int AdEntity::getHeight() { - if (_region && !_sprite) { - return _region->_rect.bottom - _region->_rect.top; - } else { - if (_currentSprite == NULL) { - _currentSprite = _sprite; - } - return AdObject::getHeight(); - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdEntity::updatePosition() { - if (_region && !_sprite) { - _posX = _region->_rect.left + (_region->_rect.right - _region->_rect.left) / 2; - _posY = _region->_rect.bottom; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdEntity::persist(BasePersistenceManager *persistMgr) { - AdTalkHolder::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_item)); - persistMgr->transfer(TMEMBER(_region)); - //persistMgr->transfer(TMEMBER(_sprite)); - persistMgr->transfer(TMEMBER_INT(_subtype)); - _talkSprites.persist(persistMgr); - _talkSpritesEx.persist(persistMgr); - - persistMgr->transfer(TMEMBER(_walkToX)); - persistMgr->transfer(TMEMBER(_walkToY)); - persistMgr->transfer(TMEMBER_INT(_walkToDir)); - - persistMgr->transfer(TMEMBER(_theora)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void AdEntity::setItem(const char *itemName) { - BaseUtils::setString(&_item, itemName); -} - -////////////////////////////////////////////////////////////////////////// -bool AdEntity::setSprite(const char *filename) { - if (_currentSprite == _sprite) { - _currentSprite = NULL; - } - - delete _sprite; - _sprite = NULL; - BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - delete _sprite; - _sprite = NULL; - return STATUS_FAILED; - } else { - _sprite = spr; - _currentSprite = _sprite; - return STATUS_OK; - } -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + + +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_active_rect.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/video/video_theora_player.h" +#include "engines/wintermute/base/particles/part_emitter.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdEntity, false) + +////////////////////////////////////////////////////////////////////////// +AdEntity::AdEntity(BaseGame *inGame) : AdTalkHolder(inGame) { + _type = OBJECT_ENTITY; + _subtype = ENTITY_NORMAL; + _region = NULL; + _item = NULL; + + _walkToX = _walkToY = 0; + _walkToDir = DI_NONE; + + _theora = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdEntity::~AdEntity() { + _gameRef->unregisterObject(_region); + + delete _theora; + _theora = NULL; + + delete[] _item; + _item = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdEntity::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdEntity::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->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 +////////////////////////////////////////////////////////////////////////// +bool AdEntity::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; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ENTITY) { + _gameRef->LOG(0, "'ENTITY' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + AdGame *adGame = (AdGame *)_gameRef; + BaseSprite *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 (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_SPRITE: { + delete _sprite; + _sprite = NULL; + spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } else { + _sprite = spr; + } + } + break; + + case TOKEN_TALK: { + spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } + } + break; + + case TOKEN_TALK_SPECIAL: { + spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } + } + 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: + parser.scanStr((char *)params, "%b", &_zoomable); + break; + + case TOKEN_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _scale = (float)s; + + } + break; + + case TOKEN_RELATIVE_SCALE: { + int s; + parser.scanStr((char *)params, "%d", &s); + _relativeScale = (float)s; + + } + break; + + case TOKEN_ROTABLE: + case TOKEN_ROTATABLE: + parser.scanStr((char *)params, "%b", &_rotatable); + break; + + case TOKEN_REGISTRABLE: + case TOKEN_INTERACTIVE: + parser.scanStr((char *)params, "%b", &_registrable); + break; + + case TOKEN_SHADOWABLE: + case TOKEN_COLORABLE: + parser.scanStr((char *)params, "%b", &_shadowable); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new BaseSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_REGION: { + if (_region) { + _gameRef->unregisterObject(_region); + } + _region = NULL; + BaseRegion *rgn = new BaseRegion(_gameRef); + if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } else { + _region = rgn; + _gameRef->registerObject(_region); + } + } + break; + + case TOKEN_BLOCKED_REGION: { + delete _blockRegion; + _blockRegion = NULL; + delete _currentBlockRegion; + _currentBlockRegion = NULL; + BaseRegion *rgn = new BaseRegion(_gameRef); + BaseRegion *crgn = new BaseRegion(_gameRef); + if (!rgn || !crgn || DID_FAIL(rgn->loadBuffer(params, false))) { + delete _blockRegion; + _blockRegion = NULL; + delete _currentBlockRegion; + _currentBlockRegion = NULL; + cmd = PARSERR_GENERIC; + } else { + _blockRegion = rgn; + _currentBlockRegion = crgn; + _currentBlockRegion->mimic(_blockRegion); + } + } + break; + + case TOKEN_WAYPOINTS: { + delete _wptGroup; + _wptGroup = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); + AdWaypointGroup *cwpt = new AdWaypointGroup(_gameRef); + if (!wpt || !cwpt || DID_FAIL(wpt->loadBuffer(params, false))) { + delete _wptGroup; + _wptGroup = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + cmd = PARSERR_GENERIC; + } else { + _wptGroup = wpt; + _currentWptGroup = cwpt; + _currentWptGroup->mimic(_wptGroup); + } + } + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_SUBTYPE: { + if (scumm_stricmp((char *)params, "sound") == 0) { + delete _sprite; + _sprite = NULL; + if (_gameRef->_editorMode) { + spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) { + cmd = PARSERR_GENERIC; + } else { + _sprite = spr; + } + } + if (_gameRef->_editorMode) { + _editorOnly = true; + } + _zoomable = false; + _rotatable = false; + _registrable = _gameRef->_editorMode; + _shadowable = false; + _subtype = ENTITY_SOUND; + } + } + break; + + case TOKEN_SOUND: + playSFX((char *)params, false, false); + break; + + case TOKEN_SOUND_START_TIME: + parser.scanStr((char *)params, "%d", &_sFXStart); + break; + + case TOKEN_SOUND_VOLUME: + parser.scanStr((char *)params, "%d", &_sFXVolume); + break; + + case TOKEN_SOUND_PANNING: + parser.scanStr((char *)params, "%b", &_autoSoundPanning); + break; + + case TOKEN_SAVE_STATE: + parser.scanStr((char *)params, "%b", &_saveState); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_IGNORE_ITEMS: + parser.scanStr((char *)params, "%b", &_ignoreItems); + 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: + parser.scanStr((char *)params, "%d", &_walkToX); + break; + + case TOKEN_WALK_TO_Y: + parser.scanStr((char *)params, "%d", &_walkToY); + 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; + } + _walkToDir = (TDirection)i; + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ENTITY definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ENTITY definition"); + if (spr) { + delete spr; + } + return STATUS_FAILED; + } + + if (_region && _sprite) { + _gameRef->LOG(0, "Warning: Entity '%s' has both sprite and region.", getName()); + } + + updatePosition(); + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + _state = STATE_READY; + + if (_item && ((AdGame *)_gameRef)->isItemTaken(_item)) { + _active = false; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdEntity::display() { + if (_active) { + updateSounds(); + + uint32 alpha; + if (_alphaColor != 0) { + alpha = _alphaColor; + } else { + alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; + } + + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + float rotate; + if (_rotatable) { + if (_rotateValid) { + rotate = _rotate; + } else { + rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } + } else { + rotate = 0.0f; + } + + + bool reg = _registrable; + if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) { + reg = false; + } + + if (_region && (reg || _editorAlwaysRegister)) { + _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); + } + + displaySpriteAttachments(true); + if (_theora && (_theora->isPlaying() || _theora->isPaused())) { + _theora->display(alpha); + } else if (_currentSprite) { + _currentSprite->display(_posX, + _posY, + (reg || _editorAlwaysRegister) ? _registerAlias : NULL, + scaleX, + scaleY, + alpha, + rotate, + _blendMode); + } + displaySpriteAttachments(false); + + if (_partEmitter) { + _partEmitter->display(_region); + } + + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdEntity::update() { + _currentSprite = NULL; + + if (_state == STATE_READY && _animSprite) { + delete _animSprite; + _animSprite = NULL; + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = STATE_READY; + _currentSprite = _animSprite; + } + + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } + + // default: stand animation + if (!_currentSprite) { + _currentSprite = _sprite; + } + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite) { + _currentSprite = _sprite; + } + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(); + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } + + bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (timeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + } + ((AdGame *)_gameRef)->addSentence(_sentence); + } + } else { + _currentSprite = _tempSprite2; + ((AdGame *)_gameRef)->addSentence(_sentence); + } + } + break; + default: // Silence unhandled enum-warning + break; + } + + + if (_currentSprite) { + _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); + if (_currentSprite->_changed) { + _posX += _currentSprite->_moveX; + _posY += _currentSprite->_moveY; + } + } + + updateBlockRegion(); + _ready = (_state == STATE_READY); + + if (_theora) { + int offsetX, offsetY; + _gameRef->getOffset(&offsetX, &offsetY); + _theora->_posX = _posX - offsetX; + _theora->_posY = _posY - offsetY; + + _theora->update(); + if (_theora->isFinished()) { + _theora->stop(); + delete _theora; + _theora = NULL; + } + } + + updatePartEmitter(); + updateSpriteAttachments(); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // StopSound + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "StopSound") == 0 && _subtype == ENTITY_SOUND) { + stack->correctParams(0); + + if (DID_FAIL(stopSFX(false))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PlayTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PlayTheora") == 0) { + stack->correctParams(4); + const char *filename = stack->pop()->getString(); + bool looping = stack->pop()->getBool(false); + ScValue *valAlpha = stack->pop(); + int startTime = stack->pop()->getInt(); + + delete _theora; + _theora = new VideoTheoraPlayer(_gameRef); + if (_theora && DID_SUCCEED(_theora->initialize(filename))) { + if (!valAlpha->isNULL()) { + _theora->setAlphaImage(valAlpha->getString()); + } + _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); + //if (_scale>=0) _theora->_playZoom = _scale; + stack->pushBool(true); + } else { + script->runtimeError("Entity.PlayTheora - error playing video '%s'", filename); + stack->pushBool(false); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StopTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StopTheora") == 0) { + stack->correctParams(0); + if (_theora) { + _theora->stop(); + delete _theora; + _theora = NULL; + stack->pushBool(true); + } else { + stack->pushBool(false); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTheoraPlaying + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTheoraPlaying") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPlaying()) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PauseTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PauseTheora") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPlaying()) { + _theora->pause(); + stack->pushBool(true); + } else { + stack->pushBool(false); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ResumeTheora + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResumeTheora") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPaused()) { + _theora->resume(); + stack->pushBool(true); + } else { + stack->pushBool(false); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTheoraPaused + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTheoraPaused") == 0) { + stack->correctParams(0); + if (_theora && _theora->isPaused()) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } + + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // CreateRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateRegion") == 0) { + stack->correctParams(0); + if (!_region) { + _region = new BaseRegion(_gameRef); + _gameRef->registerObject(_region); + } + if (_region) { + stack->pushNative(_region, true); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteRegion") == 0) { + stack->correctParams(0); + if (_region) { + _gameRef->unregisterObject(_region); + _region = NULL; + stack->pushBool(true); + } else { + stack->pushBool(false); + } + + return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdEntity::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type (RO) + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("entity"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Item") == 0) { + if (_item) { + _scValue->setString(_item); + } else { + _scValue->setNULL(); + } + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Subtype (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Subtype") == 0) { + if (_subtype == ENTITY_SOUND) { + _scValue->setString("sound"); + } else { + _scValue->setString("normal"); + } + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToX") == 0) { + _scValue->setInt(_walkToX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToY") == 0) { + _scValue->setInt(_walkToY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToDirection + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToDirection") == 0) { + _scValue->setInt((int)_walkToDir); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Region (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Region") == 0) { + if (_region) { + _scValue->setNative(_region, true); + } else { + _scValue->setNULL(); + } + return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdEntity::scSetProperty(const char *name, ScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Item") == 0) { + setItem(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToX") == 0) { + _walkToX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToY") == 0) { + _walkToY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // WalkToDirection + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "WalkToDirection") == 0) { + int dir = value->getInt(); + if (dir >= 0 && dir < NUM_DIRECTIONS) { + _walkToDir = (TDirection)dir; + } + return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdEntity::scToString() { + return "[entity object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ENTITY {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + if (_subtype == ENTITY_SOUND) { + buffer->putTextIndent(indent + 2, "SUBTYPE=\"SOUND\"\n"); + } + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + 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); + } + + for (uint32 i = 0; i < _scripts.size(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_subtype == ENTITY_NORMAL && _sprite && _sprite->getFilename()) { + buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->getFilename()); + } + + if (_subtype == ENTITY_SOUND && _sFX && _sFX->getFilename()) { + buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sFX->getFilename()); + buffer->putTextIndent(indent + 2, "SOUND_START_TIME=%d\n", _sFXStart); + buffer->putTextIndent(indent + 2, "SOUND_VOLUME=%d\n", _sFXVolume); + } + + + if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) { + buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alphaColor), RGBCOLGetG(_alphaColor), RGBCOLGetB(_alphaColor)); + } + + if (RGBCOLGetA(_alphaColor) != 0) { + buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alphaColor)); + } + + if (_scale >= 0) { + buffer->putTextIndent(indent + 2, "SCALE = %d\n", (int)_scale); + } + + if (_relativeScale != 0) { + buffer->putTextIndent(indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale); + } + + if (_font && _font->getFilename()) { + buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); + } + + if (_cursor && _cursor->getFilename()) { + buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } + + AdTalkHolder::saveAsText(buffer, indent + 2); + + if (_region) { + _region->saveAsText(buffer, indent + 2); + } + + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } + + AdObject::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +int AdEntity::getHeight() { + if (_region && !_sprite) { + return _region->_rect.bottom - _region->_rect.top; + } else { + if (_currentSprite == NULL) { + _currentSprite = _sprite; + } + return AdObject::getHeight(); + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdEntity::updatePosition() { + if (_region && !_sprite) { + _posX = _region->_rect.left + (_region->_rect.right - _region->_rect.left) / 2; + _posY = _region->_rect.bottom; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdEntity::persist(BasePersistenceManager *persistMgr) { + AdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_item)); + persistMgr->transfer(TMEMBER(_region)); + //persistMgr->transfer(TMEMBER(_sprite)); + persistMgr->transfer(TMEMBER_INT(_subtype)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_walkToX)); + persistMgr->transfer(TMEMBER(_walkToY)); + persistMgr->transfer(TMEMBER_INT(_walkToDir)); + + persistMgr->transfer(TMEMBER(_theora)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void AdEntity::setItem(const char *itemName) { + BaseUtils::setString(&_item, itemName); +} + +////////////////////////////////////////////////////////////////////////// +bool AdEntity::setSprite(const char *filename) { + if (_currentSprite == _sprite) { + _currentSprite = NULL; + } + + delete _sprite; + _sprite = NULL; + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + delete _sprite; + _sprite = NULL; + return STATUS_FAILED; + } else { + _sprite = spr; + _currentSprite = _sprite; + return STATUS_OK; + } +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_entity.h b/engines/wintermute/ad/ad_entity.h index 2178563534..39dc133eef 100644 --- a/engines/wintermute/ad/ad_entity.h +++ b/engines/wintermute/ad/ad_entity.h @@ -1,68 +1,68 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADENTITY_H -#define WINTERMUTE_ADENTITY_H - -#include "engines/wintermute/ad/ad_talk_holder.h" - -namespace Wintermute { -class VideoTheoraPlayer; -class AdEntity : public AdTalkHolder { -public: - VideoTheoraPlayer *_theora; - bool setSprite(const char *filename); - int _walkToX; - int _walkToY; - TDirection _walkToDir; - void setItem(const char *itemName); - char *_item; - DECLARE_PERSISTENT(AdEntity, AdTalkHolder) - void updatePosition(); - virtual int getHeight(); - BaseRegion *_region; - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - virtual bool update(); - virtual bool display(); - AdEntity(BaseGame *inGame); - virtual ~AdEntity(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - TEntityType _subtype; - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - virtual const char *scToString(); - -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADENTITY_H +#define WINTERMUTE_ADENTITY_H + +#include "engines/wintermute/ad/ad_talk_holder.h" + +namespace Wintermute { +class VideoTheoraPlayer; +class AdEntity : public AdTalkHolder { +public: + VideoTheoraPlayer *_theora; + bool setSprite(const char *filename); + int _walkToX; + int _walkToY; + TDirection _walkToDir; + void setItem(const char *itemName); + char *_item; + DECLARE_PERSISTENT(AdEntity, AdTalkHolder) + void updatePosition(); + virtual int getHeight(); + BaseRegion *_region; + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + virtual bool update(); + virtual bool display(); + AdEntity(BaseGame *inGame); + virtual ~AdEntity(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + TEntityType _subtype; + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + virtual const char *scToString(); + +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index f5d865d9f8..fe8a5991e2 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -1,2280 +1,2280 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_actor.h" -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_entity.h" -#include "engines/wintermute/ad/ad_inventory.h" -#include "engines/wintermute/ad/ad_inventory_box.h" -#include "engines/wintermute/ad/ad_item.h" -#include "engines/wintermute/ad/ad_response.h" -#include "engines/wintermute/ad/ad_response_box.h" -#include "engines/wintermute/ad/ad_response_context.h" -#include "engines/wintermute/ad/ad_scene.h" -#include "engines/wintermute/ad/ad_scene_state.h" -#include "engines/wintermute/ad/ad_sentence.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/base/base_object.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/sound/base_sound.h" -#include "engines/wintermute/base/base_string_table.h" -#include "engines/wintermute/base/base_surface_storage.h" -#include "engines/wintermute/base/base_transition_manager.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_viewport.h" -#include "engines/wintermute/base/particles/part_emitter.h" -#include "engines/wintermute/base/saveload.h" -#include "engines/wintermute/base/scriptables/script_engine.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/ui/ui_entity.h" -#include "engines/wintermute/ui/ui_window.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/video/video_player.h" -#include "engines/wintermute/video/video_theora_player.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdGame, true) - -////////////////////////////////////////////////////////////////////////// -AdGame::AdGame(const Common::String &gameId) : BaseGame(gameId) { - _responseBox = NULL; - _inventoryBox = NULL; - - _scene = new AdScene(_gameRef); - _scene->setName(""); - registerObject(_scene); - - _prevSceneName = NULL; - _prevSceneFilename = NULL; - _scheduledScene = NULL; - _scheduledFadeIn = false; - - - _stateEx = GAME_NORMAL; - - _selectedItem = NULL; - - - _texItemLifeTime = 10000; - _texWalkLifeTime = 10000; - _texStandLifeTime = 10000; - _texTalkLifeTime = 10000; - - _talkSkipButton = TALK_SKIP_LEFT; - - _sceneViewport = NULL; - - _initialScene = true; - _debugStartupScene = NULL; - _startupScene = NULL; - - _invObject = new AdObject(this); - _inventoryOwner = _invObject; - - _tempDisableSaveState = false; - _itemsFile = NULL; - - _smartItemCursor = false; - - addSpeechDir("speech"); -} - - -////////////////////////////////////////////////////////////////////////// -AdGame::~AdGame() { - cleanup(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::cleanup() { - for (uint32 i = 0; i < _objects.size(); i++) { - unregisterObject(_objects[i]); - _objects[i] = NULL; - } - _objects.clear(); - - - for (uint32 i = 0; i < _dlgPendingBranches.size(); i++) { - delete[] _dlgPendingBranches[i]; - } - _dlgPendingBranches.clear(); - - for (uint32 i = 0; i < _speechDirs.size(); i++) { - delete[] _speechDirs[i]; - } - _speechDirs.clear(); - - - unregisterObject(_scene); - _scene = NULL; - - // remove items - for (uint32 i = 0; i < _items.size(); i++) { - _gameRef->unregisterObject(_items[i]); - } - _items.clear(); - - - // clear remaining inventories - delete _invObject; - _invObject = NULL; - - for (uint32 i = 0; i < _inventories.size(); i++) { - delete _inventories[i]; - } - _inventories.clear(); - - - if (_responseBox) { - _gameRef->unregisterObject(_responseBox); - _responseBox = NULL; - } - - if (_inventoryBox) { - _gameRef->unregisterObject(_inventoryBox); - _inventoryBox = NULL; - } - - delete[] _prevSceneName; - delete[] _prevSceneFilename; - delete[] _scheduledScene; - delete[] _debugStartupScene; - delete[] _itemsFile; - _prevSceneName = NULL; - _prevSceneFilename = NULL; - _scheduledScene = NULL; - _debugStartupScene = NULL; - _startupScene = NULL; - _itemsFile = NULL; - - delete _sceneViewport; - _sceneViewport = NULL; - - for (uint32 i = 0; i < _sceneStates.size(); i++) { - delete _sceneStates[i]; - } - _sceneStates.clear(); - - for (uint32 i = 0; i < _responsesBranch.size(); i++) { - delete _responsesBranch[i]; - } - _responsesBranch.clear(); - - for (uint32 i = 0; i < _responsesGame.size(); i++) { - delete _responsesGame[i]; - } - _responsesGame.clear(); - - return BaseGame::cleanup(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::initLoop() { - if (_scheduledScene && _transMgr->isReady()) { - changeScene(_scheduledScene, _scheduledFadeIn); - delete[] _scheduledScene; - _scheduledScene = NULL; - - _gameRef->_activeObject = NULL; - } - - - bool res; - res = BaseGame::initLoop(); - if (DID_FAIL(res)) { - return res; - } - - if (_scene) { - res = _scene->initLoop(); - } - - _sentences.clear(); - - return res; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::addObject(AdObject *object) { - _objects.add(object); - return registerObject(object); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::removeObject(AdObject *object) { - // in case the user called Scene.CreateXXX() and Game.DeleteXXX() - if (_scene) { - bool res = _scene->removeObject(object); - if (DID_SUCCEED(res)) { - return res; - } - } - - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i] == object) { - _objects.remove_at(i); - break; - } - } - return unregisterObject(object); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::changeScene(const char *filename, bool fadeIn) { - if (_scene == NULL) { - _scene = new AdScene(_gameRef); - registerObject(_scene); - } else { - _scene->applyEvent("SceneShutdown", true); - - setPrevSceneName(_scene->getName()); - setPrevSceneFilename(_scene->getFilename()); - - if (!_tempDisableSaveState) { - _scene->saveState(); - } - _tempDisableSaveState = false; - } - - if (_scene) { - // reset objects - for (uint32 i = 0; i < _objects.size(); i++) { - _objects[i]->reset(); - } - - // reset scene properties - _scene->_sFXVolume = 100; - if (_scene->_scProp) { - _scene->_scProp->cleanup(); - } - - bool ret; - if (_initialScene && _debugDebugMode && _debugStartupScene) { - _initialScene = false; - ret = _scene->loadFile(_debugStartupScene); - } else { - ret = _scene->loadFile(filename); - } - - if (DID_SUCCEED(ret)) { - // invalidate references to the original scene - for (uint32 i = 0; i < _objects.size(); i++) { - _objects[i]->invalidateCurrRegions(); - _objects[i]->_stickRegion = NULL; - } - - _scene->loadState(); - } - if (fadeIn) { - _gameRef->_transMgr->start(TRANSITION_FADE_IN); - } - return ret; - } else { - return STATUS_FAILED; - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdGame::addSentence(AdSentence *sentence) { - _sentences.add(sentence); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::displaySentences(bool frozen) { - for (uint32 i = 0; i < _sentences.size(); i++) { - if (frozen && _sentences[i]->_freezable) { - continue; - } else { - _sentences[i]->display(); - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void AdGame::finishSentences() { - for (uint32 i = 0; i < _sentences.size(); i++) { - if (_sentences[i]->canSkip()) { - _sentences[i]->_duration = 0; - if (_sentences[i]->_sound) { - _sentences[i]->_sound->stop(); - } - } - } -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // ChangeScene - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "ChangeScene") == 0) { - stack->correctParams(3); - const char *filename = stack->pop()->getString(); - ScValue *valFadeOut = stack->pop(); - ScValue *valFadeIn = stack->pop(); - - bool transOut = valFadeOut->isNULL() ? true : valFadeOut->getBool(); - bool transIn = valFadeIn->isNULL() ? true : valFadeIn->getBool(); - - scheduleChangeScene(filename, transIn); - if (transOut) { - _transMgr->start(TRANSITION_FADE_OUT, true); - } - stack->pushNULL(); - - - //bool ret = ChangeScene(stack->pop()->getString()); - //if (DID_FAIL(ret)) stack->pushBool(false); - //else stack->pushBool(true); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadActor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadActor") == 0) { - stack->correctParams(1); - AdActor *act = new AdActor(_gameRef); - if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { - addObject(act); - stack->pushNative(act, true); - } else { - delete act; - act = NULL; - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadEntity") == 0) { - stack->correctParams(1); - AdEntity *ent = new AdEntity(_gameRef); - if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { - addObject(ent); - stack->pushNative(ent, true); - } else { - delete ent; - ent = NULL; - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // UnloadObject / UnloadActor / UnloadEntity / DeleteEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "DeleteEntity") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - AdObject *obj = (AdObject *)val->getNative(); - removeObject(obj); - if (val->getType() == VAL_VARIABLE_REF) { - val->setNULL(); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CreateEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateEntity") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdEntity *ent = new AdEntity(_gameRef); - addObject(ent); - if (!val->isNULL()) { - ent->setName(val->getString()); - } - stack->pushNative(ent, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CreateItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateItem") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdItem *item = new AdItem(_gameRef); - addItem(item); - if (!val->isNULL()) { - item->setName(val->getString()); - } - stack->pushNative(item, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteItem") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdItem *item = NULL; - if (val->isNative()) { - item = (AdItem *)val->getNative(); - } else { - item = getItemByName(val->getString()); - } - - if (item) { - deleteItem(item); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // QueryItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "QueryItem") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdItem *item = NULL; - if (val->isInt()) { - int index = val->getInt(); - if (index >= 0 && index < (int32)_items.size()) { - item = _items[index]; - } - } else { - item = getItemByName(val->getString()); - } - - if (item) { - stack->pushNative(item, true); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // AddResponse/AddResponseOnce/AddResponseOnceGame - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddResponse") == 0 || strcmp(name, "AddResponseOnce") == 0 || strcmp(name, "AddResponseOnceGame") == 0) { - stack->correctParams(6); - int id = stack->pop()->getInt(); - const char *text = stack->pop()->getString(); - ScValue *val1 = stack->pop(); - ScValue *val2 = stack->pop(); - ScValue *val3 = stack->pop(); - ScValue *val4 = stack->pop(); - - if (_responseBox) { - AdResponse *res = new AdResponse(_gameRef); - if (res) { - res->_iD = id; - res->setText(text); - _stringTable->expand(&res->_text); - if (!val1->isNULL()) { - res->setIcon(val1->getString()); - } - if (!val2->isNULL()) { - res->setIconHover(val2->getString()); - } - if (!val3->isNULL()) { - res->setIconPressed(val3->getString()); - } - if (!val4->isNULL()) { - res->setFont(val4->getString()); - } - - if (strcmp(name, "AddResponseOnce") == 0) { - res->_responseType = RESPONSE_ONCE; - } else if (strcmp(name, "AddResponseOnceGame") == 0) { - res->_responseType = RESPONSE_ONCE_GAME; - } - - _responseBox->_responses.add(res); - } - } else { - script->runtimeError("Game.AddResponse: response box is not defined"); - } - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ResetResponse - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ResetResponse") == 0) { - stack->correctParams(1); - int id = stack->pop()->getInt(-1); - resetResponse(id); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ClearResponses - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ClearResponses") == 0) { - stack->correctParams(0); - _responseBox->clearResponses(); - _responseBox->clearButtons(); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetResponse - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetResponse") == 0) { - stack->correctParams(1); - bool autoSelectLast = stack->pop()->getBool(); - - if (_responseBox) { - _responseBox->weedResponses(); - - if (_responseBox->_responses.size() == 0) { - stack->pushNULL(); - return STATUS_OK; - } - - - if (_responseBox->_responses.size() == 1 && autoSelectLast) { - stack->pushInt(_responseBox->_responses[0]->_iD); - _responseBox->handleResponse(_responseBox->_responses[0]); - _responseBox->clearResponses(); - return STATUS_OK; - } - - _responseBox->createButtons(); - _responseBox->_waitingScript = script; - script->waitForExclusive(_responseBox); - _state = GAME_SEMI_FROZEN; - _stateEx = GAME_WAITING_RESPONSE; - } else { - script->runtimeError("Game.GetResponse: response box is not defined"); - stack->pushNULL(); - } - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // GetNumResponses - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetNumResponses") == 0) { - stack->correctParams(0); - if (_responseBox) { - _responseBox->weedResponses(); - stack->pushInt(_responseBox->_responses.size()); - } else { - script->runtimeError("Game.GetNumResponses: response box is not defined"); - stack->pushNULL(); - } - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // StartDlgBranch - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StartDlgBranch") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - Common::String branchName; - if (val->isNULL()) { - branchName.format("line%d", script->_currentLine); - } else { - branchName = val->getString(); - } - - startDlgBranch(branchName.c_str(), script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // EndDlgBranch - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "EndDlgBranch") == 0) { - stack->correctParams(1); - - const char *branchName = NULL; - ScValue *val = stack->pop(); - if (!val->isNULL()) { - branchName = val->getString(); - } - endDlgBranch(branchName, script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); - - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetCurrentDlgBranch - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetCurrentDlgBranch") == 0) { - stack->correctParams(0); - - if (_dlgPendingBranches.size() > 0) { - stack->pushString(_dlgPendingBranches[_dlgPendingBranches.size() - 1]); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TakeItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TakeItem") == 0) { - return _invObject->scCallMethod(script, stack, thisStack, name); - } - - ////////////////////////////////////////////////////////////////////////// - // DropItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DropItem") == 0) { - return _invObject->scCallMethod(script, stack, thisStack, name); - } - - ////////////////////////////////////////////////////////////////////////// - // GetItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetItem") == 0) { - return _invObject->scCallMethod(script, stack, thisStack, name); - } - - ////////////////////////////////////////////////////////////////////////// - // HasItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "HasItem") == 0) { - return _invObject->scCallMethod(script, stack, thisStack, name); - } - - ////////////////////////////////////////////////////////////////////////// - // IsItemTaken - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsItemTaken") == 0) { - stack->correctParams(1); - - ScValue *val = stack->pop(); - if (!val->isNULL()) { - for (uint32 i = 0; i < _inventories.size(); i++) { - AdInventory *inv = _inventories[i]; - - for (uint32 j = 0; j < inv->_takenItems.size(); j++) { - if (val->getNative() == inv->_takenItems[j]) { - stack->pushBool(true); - return STATUS_OK; - } else if (scumm_stricmp(val->getString(), inv->_takenItems[j]->getName()) == 0) { - stack->pushBool(true); - return STATUS_OK; - } - } - } - } else { - script->runtimeError("Game.IsItemTaken: item name expected"); - } - - stack->pushBool(false); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetInventoryWindow - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetInventoryWindow") == 0) { - stack->correctParams(0); - if (_inventoryBox && _inventoryBox->_window) { - stack->pushNative(_inventoryBox->_window, true); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetResponsesWindow - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetResponsesWindow") == 0 || strcmp(name, "GetResponseWindow") == 0) { - stack->correctParams(0); - if (_responseBox && _responseBox->_window) { - stack->pushNative(_responseBox->_window, true); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadResponseBox - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadResponseBox") == 0) { - stack->correctParams(1); - const char *filename = stack->pop()->getString(); - - _gameRef->unregisterObject(_responseBox); - _responseBox = new AdResponseBox(_gameRef); - if (_responseBox && !DID_FAIL(_responseBox->loadFile(filename))) { - registerObject(_responseBox); - stack->pushBool(true); - } else { - delete _responseBox; - _responseBox = NULL; - stack->pushBool(false); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadInventoryBox - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadInventoryBox") == 0) { - stack->correctParams(1); - const char *filename = stack->pop()->getString(); - - _gameRef->unregisterObject(_inventoryBox); - _inventoryBox = new AdInventoryBox(_gameRef); - if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile(filename))) { - registerObject(_inventoryBox); - stack->pushBool(true); - } else { - delete _inventoryBox; - _inventoryBox = NULL; - stack->pushBool(false); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadItems") == 0) { - stack->correctParams(2); - const char *filename = stack->pop()->getString(); - bool merge = stack->pop()->getBool(false); - - bool ret = loadItemsFile(filename, merge); - stack->pushBool(DID_SUCCEED(ret)); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddSpeechDir - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddSpeechDir") == 0) { - stack->correctParams(1); - const char *dir = stack->pop()->getString(); - stack->pushBool(DID_SUCCEED(addSpeechDir(dir))); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // RemoveSpeechDir - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "RemoveSpeechDir") == 0) { - stack->correctParams(1); - const char *dir = stack->pop()->getString(); - stack->pushBool(DID_SUCCEED(removeSpeechDir(dir))); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetSceneViewport - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SetSceneViewport") == 0) { - stack->correctParams(4); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - int width = stack->pop()->getInt(); - int height = stack->pop()->getInt(); - - if (width <= 0) { - width = _renderer->_width; - } - if (height <= 0) { - height = _renderer->_height; - } - - if (!_sceneViewport) { - _sceneViewport = new BaseViewport(_gameRef); - } - if (_sceneViewport) { - _sceneViewport->setRect(x, y, x + width, y + height); - } - - stack->pushBool(true); - - return STATUS_OK; - } - - - else { - return BaseGame::scCallMethod(script, stack, thisStack, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdGame::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("game"); - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // Scene - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Scene") == 0) { - if (_scene) { - _scValue->setNative(_scene, true); - } else { - _scValue->setNULL(); - } - - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // SelectedItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SelectedItem") == 0) { - //if (_selectedItem) _scValue->setString(_selectedItem->_name); - if (_selectedItem) { - _scValue->setNative(_selectedItem, true); - } else { - _scValue->setNULL(); - } - - return _scValue; - } - ////////////////////////////////////////////////////////////////////////// - // NumItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumItems") == 0) { - return _invObject->scGetProperty(name); - } - - ////////////////////////////////////////////////////////////////////////// - // SmartItemCursor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SmartItemCursor") == 0) { - _scValue->setBool(_smartItemCursor); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryVisible - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryVisible") == 0) { - _scValue->setBool(_inventoryBox && _inventoryBox->_visible); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryScrollOffset - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryScrollOffset") == 0) { - if (_inventoryBox) { - _scValue->setInt(_inventoryBox->_scrollOffset); - } else { - _scValue->setInt(0); - } - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ResponsesVisible (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ResponsesVisible") == 0) { - _scValue->setBool(_stateEx == GAME_WAITING_RESPONSE); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // PrevScene / PreviousScene (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PrevScene") == 0 || strcmp(name, "PreviousScene") == 0) { - if (!_prevSceneName) { - _scValue->setString(""); - } else { - _scValue->setString(_prevSceneName); - } - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // PrevSceneFilename / PreviousSceneFilename (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PrevSceneFilename") == 0 || strcmp(name, "PreviousSceneFilename") == 0) { - if (!_prevSceneFilename) { - _scValue->setString(""); - } else { - _scValue->setString(_prevSceneFilename); - } - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // LastResponse (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LastResponse") == 0) { - if (!_responseBox || !_responseBox->_lastResponseText) { - _scValue->setString(""); - } else { - _scValue->setString(_responseBox->_lastResponseText); - } - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // LastResponseOrig (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LastResponseOrig") == 0) { - if (!_responseBox || !_responseBox->_lastResponseTextOrig) { - _scValue->setString(""); - } else { - _scValue->setString(_responseBox->_lastResponseTextOrig); - } - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryObject") == 0) { - if (_inventoryOwner == _invObject) { - _scValue->setNative(this, true); - } else { - _scValue->setNative(_inventoryOwner, true); - } - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // TotalNumItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TotalNumItems") == 0) { - _scValue->setInt(_items.size()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // TalkSkipButton - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkSkipButton") == 0) { - _scValue->setInt(_talkSkipButton); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ChangingScene - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ChangingScene") == 0) { - _scValue->setBool(_scheduledScene != NULL); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // StartupScene - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StartupScene") == 0) { - if (!_startupScene) { - _scValue->setNULL(); - } else { - _scValue->setString(_startupScene); - } - return _scValue; - } - - else { - return BaseGame::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::scSetProperty(const char *name, ScValue *value) { - - ////////////////////////////////////////////////////////////////////////// - // SelectedItem - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SelectedItem") == 0) { - if (value->isNULL()) { - _selectedItem = NULL; - } else { - if (value->isNative()) { - _selectedItem = NULL; - for (uint32 i = 0; i < _items.size(); i++) { - if (_items[i] == value->getNative()) { - _selectedItem = (AdItem *)value->getNative(); - break; - } - } - } else { - // try to get by name - _selectedItem = getItemByName(value->getString()); - } - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SmartItemCursor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SmartItemCursor") == 0) { - _smartItemCursor = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryVisible - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryVisible") == 0) { - if (_inventoryBox) { - _inventoryBox->_visible = value->getBool(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryObject") == 0) { - if (_inventoryOwner && _inventoryBox) { - _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; - } - - if (value->isNULL()) { - _inventoryOwner = _invObject; - } else { - BaseObject *obj = (BaseObject *)value->getNative(); - if (obj == this) { - _inventoryOwner = _invObject; - } else if (_gameRef->validObject(obj)) { - _inventoryOwner = (AdObject *)obj; - } - } - - if (_inventoryOwner && _inventoryBox) { - _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InventoryScrollOffset - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryScrollOffset") == 0) { - if (_inventoryBox) { - _inventoryBox->_scrollOffset = value->getInt(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TalkSkipButton - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkSkipButton") == 0) { - int val = value->getInt(); - if (val < 0) { - val = 0; - } - if (val > TALK_SKIP_NONE) { - val = TALK_SKIP_NONE; - } - _talkSkipButton = (TTalkSkipButton)val; - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // StartupScene - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StartupScene") == 0) { - if (value == NULL) { - delete[] _startupScene; - _startupScene = NULL; - } else { - BaseUtils::setString(&_startupScene, value->getString()); - } - - return STATUS_OK; - } - - else { - return BaseGame::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::externalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name) { - ScValue *thisObj; - - ////////////////////////////////////////////////////////////////////////// - // Actor - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Actor") == 0) { - stack->correctParams(0); - thisObj = thisStack->getTop(); - - thisObj->setNative(new AdActor(_gameRef)); - stack->pushNULL(); - } - - ////////////////////////////////////////////////////////////////////////// - // Entity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Entity") == 0) { - stack->correctParams(0); - thisObj = thisStack->getTop(); - - thisObj->setNative(new AdEntity(_gameRef)); - stack->pushNULL(); - } - - - ////////////////////////////////////////////////////////////////////////// - // call parent - else { - return BaseGame::externalCall(script, stack, thisStack, name); - } - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::showCursor() { - if (_cursorHidden) { - return STATUS_OK; - } - - if (_selectedItem && _gameRef->_state == GAME_RUNNING && _stateEx == GAME_NORMAL && _interactive) { - if (_selectedItem->_cursorCombined) { - BaseSprite *origLastCursor = _lastCursor; - BaseGame::showCursor(); - _lastCursor = origLastCursor; - } - if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { - if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->getName())) { - return drawCursor(_selectedItem->_cursorHover); - } else { - return drawCursor(_selectedItem->_cursorNormal); - } - } else { - return drawCursor(_selectedItem->_cursorNormal); - } - } else { - return BaseGame::showCursor(); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdGame::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(GAME) -TOKEN_DEF(AD_GAME) -TOKEN_DEF(RESPONSE_BOX) -TOKEN_DEF(INVENTORY_BOX) -TOKEN_DEF(ITEMS) -TOKEN_DEF(ITEM) -TOKEN_DEF(TALK_SKIP_BUTTON) -TOKEN_DEF(SCENE_VIEWPORT) -TOKEN_DEF(ENTITY_CONTAINER) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF(STARTUP_SCENE) -TOKEN_DEF(DEBUG_STARTUP_SCENE) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdGame::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(GAME) - TOKEN_TABLE(AD_GAME) - TOKEN_TABLE(RESPONSE_BOX) - TOKEN_TABLE(INVENTORY_BOX) - TOKEN_TABLE(ITEMS) - TOKEN_TABLE(TALK_SKIP_BUTTON) - TOKEN_TABLE(SCENE_VIEWPORT) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE(STARTUP_SCENE) - TOKEN_TABLE(DEBUG_STARTUP_SCENE) - TOKEN_TABLE_END - - byte *params; - byte *params2; - int cmd = 1; - BaseParser parser; - - bool itemFound = false, itemsFound = false; - - while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_GAME: - if (DID_FAIL(BaseGame::loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_AD_GAME: - while (cmd > 0 && (cmd = parser.getCommand((char **)¶ms, commands, (char **)¶ms2)) > 0) { - switch (cmd) { - case TOKEN_RESPONSE_BOX: - delete _responseBox; - _responseBox = new AdResponseBox(_gameRef); - if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) { - registerObject(_responseBox); - } else { - delete _responseBox; - _responseBox = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_INVENTORY_BOX: - delete _inventoryBox; - _inventoryBox = new AdInventoryBox(_gameRef); - if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) { - registerObject(_inventoryBox); - } else { - delete _inventoryBox; - _inventoryBox = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_ITEMS: - itemsFound = true; - BaseUtils::setString(&_itemsFile, (char *)params2); - if (DID_FAIL(loadItemsFile(_itemsFile))) { - delete[] _itemsFile; - _itemsFile = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_TALK_SKIP_BUTTON: - if (scumm_stricmp((char *)params2, "right") == 0) { - _talkSkipButton = TALK_SKIP_RIGHT; - } else if (scumm_stricmp((char *)params2, "both") == 0) { - _talkSkipButton = TALK_SKIP_BOTH; - } else { - _talkSkipButton = TALK_SKIP_LEFT; - } - break; - - case TOKEN_SCENE_VIEWPORT: { - Rect32 rc; - parser.scanStr((char *)params2, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_sceneViewport) { - _sceneViewport = new BaseViewport(_gameRef); - } - if (_sceneViewport) { - _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); - } - } - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params2, false); - break; - - case TOKEN_STARTUP_SCENE: - BaseUtils::setString(&_startupScene, (char *)params2); - break; - - case TOKEN_DEBUG_STARTUP_SCENE: - BaseUtils::setString(&_debugStartupScene, (char *)params2); - break; - } - } - break; - } - } - - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in GAME definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading GAME definition"); - return STATUS_FAILED; - } - - if (itemFound && !itemsFound) { - _gameRef->LOG(0, "**Warning** Please put the items definition to a separate file."); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::persist(BasePersistenceManager *persistMgr) { - if (!persistMgr->getIsSaving()) { - cleanup(); - } - BaseGame::persist(persistMgr); - - _dlgPendingBranches.persist(persistMgr); - - _inventories.persist(persistMgr); - persistMgr->transfer(TMEMBER(_inventoryBox)); - - _objects.persist(persistMgr); - - persistMgr->transfer(TMEMBER(_prevSceneName)); - persistMgr->transfer(TMEMBER(_prevSceneFilename)); - - persistMgr->transfer(TMEMBER(_responseBox)); - _responsesBranch.persist(persistMgr); - _responsesGame.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scene)); - _sceneStates.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scheduledFadeIn)); - persistMgr->transfer(TMEMBER(_scheduledScene)); - persistMgr->transfer(TMEMBER(_selectedItem)); - persistMgr->transfer(TMEMBER_INT(_talkSkipButton)); - - _sentences.persist(persistMgr); - - persistMgr->transfer(TMEMBER(_sceneViewport)); - persistMgr->transfer(TMEMBER_INT(_stateEx)); - persistMgr->transfer(TMEMBER(_initialScene)); - persistMgr->transfer(TMEMBER(_debugStartupScene)); - - persistMgr->transfer(TMEMBER(_invObject)); - persistMgr->transfer(TMEMBER(_inventoryOwner)); - persistMgr->transfer(TMEMBER(_tempDisableSaveState)); - _items.persist(persistMgr); - - persistMgr->transfer(TMEMBER(_itemsFile)); - - _speechDirs.persist(persistMgr); - persistMgr->transfer(TMEMBER(_smartItemCursor)); - - if (!persistMgr->getIsSaving()) { - _initialScene = false; - } - - persistMgr->transfer(TMEMBER(_startupScene)); - - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -void AdGame::setPrevSceneName(const char *name) { - delete[] _prevSceneName; - _prevSceneName = NULL; - if (name) { - _prevSceneName = new char[strlen(name) + 1]; - if (_prevSceneName) { - strcpy(_prevSceneName, name); - } - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdGame::setPrevSceneFilename(const char *name) { - delete[] _prevSceneFilename; - _prevSceneFilename = NULL; - if (name) { - _prevSceneFilename = new char[strlen(name) + 1]; - if (_prevSceneFilename) { - strcpy(_prevSceneFilename, name); - } - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::scheduleChangeScene(const char *filename, bool fadeIn) { - delete[] _scheduledScene; - _scheduledScene = NULL; - - if (_scene && !_scene->_initialized) { - return changeScene(filename, fadeIn); - } else { - _scheduledScene = new char [strlen(filename) + 1]; - strcpy(_scheduledScene, filename); - - _scheduledFadeIn = fadeIn; - - return STATUS_OK; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { - BaseGame::getVersion(verMajor, verMinor, NULL, NULL); - - if (extMajor) { - *extMajor = 0; - } - if (extMinor) { - *extMinor = 0; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::loadItemsFile(const char *filename, bool merge) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdGame::LoadItemsFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - //_filename = new char [strlen(filename)+1]; - //strcpy(_filename, filename); - - if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) { - _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ITEM) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (!merge) { - while (_items.size() > 0) { - deleteItem(_items[0]); - } - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_ITEM: { - AdItem *item = new AdItem(_gameRef); - if (item && !DID_FAIL(item->loadBuffer(params, false))) { - // delete item with the same name, if exists - if (merge) { - AdItem *prevItem = getItemByName(item->getName()); - if (prevItem) { - deleteItem(prevItem); - } - } - addItem(item); - } else { - delete item; - item = NULL; - cmd = PARSERR_GENERIC; - } - } - break; - } - } - - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ITEMS definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading ITEMS definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -AdSceneState *AdGame::getSceneState(const char *filename, bool saving) { - char *filenameCor = new char[strlen(filename) + 1]; - strcpy(filenameCor, filename); - for (uint32 i = 0; i < strlen(filenameCor); i++) { - if (filenameCor[i] == '/') { - filenameCor[i] = '\\'; - } - } - - for (uint32 i = 0; i < _sceneStates.size(); i++) { - if (scumm_stricmp(_sceneStates[i]->_filename, filenameCor) == 0) { - delete[] filenameCor; - return _sceneStates[i]; - } - } - - if (saving) { - AdSceneState *ret = new AdSceneState(_gameRef); - ret->setFilename(filenameCor); - - _sceneStates.add(ret); - - delete[] filenameCor; - return ret; - } else { - delete[] filenameCor; - return NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::windowLoadHook(UIWindow *win, char **buffer, char **params) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ENTITY_CONTAINER) - TOKEN_TABLE_END - - int cmd = PARSERR_GENERIC; - BaseParser parser; - - cmd = parser.getCommand(buffer, commands, params); - switch (cmd) { - case TOKEN_ENTITY_CONTAINER: { - UIEntity *ent = new UIEntity(_gameRef); - if (!ent || DID_FAIL(ent->loadBuffer((byte *)*params, false))) { - delete ent; - ent = NULL; - cmd = PARSERR_GENERIC; - } else { - ent->_parent = win; - win->_widgets.add(ent); - } - } - break; - } - - if (cmd == PARSERR_TOKENNOTFOUND || cmd == PARSERR_GENERIC) { - return STATUS_FAILED; - } - - return STATUS_OK; - -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *stack, const char *name) { - if (strcmp(name, "CreateEntityContainer") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - UIEntity *ent = new UIEntity(_gameRef); - if (!val->isNULL()) { - ent->setName(val->getString()); - } - stack->pushNative(ent, true); - - ent->_parent = win; - win->_widgets.add(ent); - - return STATUS_OK; - } else { - return STATUS_FAILED; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::startDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { - char *name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; - if (name) { - sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); - _dlgPendingBranches.add(name); - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { - char *name = NULL; - bool deleteName = false; - if (branchName == NULL && _dlgPendingBranches.size() > 0) { - name = _dlgPendingBranches[_dlgPendingBranches.size() - 1]; - } else { - if (branchName != NULL) { - name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; - if (name) { - sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); - deleteName = true; - } - } - } - - if (name == NULL) { - return STATUS_OK; - } - - - int startIndex = -1; - for (int i = _dlgPendingBranches.size() - 1; i >= 0; i--) { - if (scumm_stricmp(name, _dlgPendingBranches[i]) == 0) { - startIndex = i; - break; - } - } - if (startIndex >= 0) { - for (uint32 i = startIndex; i < _dlgPendingBranches.size(); i++) { - //ClearBranchResponses(_dlgPendingBranches[i]); - delete[] _dlgPendingBranches[i]; - _dlgPendingBranches[i] = NULL; - } - _dlgPendingBranches.remove_at(startIndex, _dlgPendingBranches.size() - startIndex); - } - - // dialogue is over, forget selected responses - if (_dlgPendingBranches.size() == 0) { - for (uint32 i = 0; i < _responsesBranch.size(); i++) { - delete _responsesBranch[i]; - } - _responsesBranch.clear(); - } - - if (deleteName) { - delete[] name; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::clearBranchResponses(char *name) { - for (uint32 i = 0; i < _responsesBranch.size(); i++) { - if (scumm_stricmp(name, _responsesBranch[i]->_context) == 0) { - delete _responsesBranch[i]; - _responsesBranch.remove_at(i); - i--; - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::addBranchResponse(int id) { - if (branchResponseUsed(id)) { - return STATUS_OK; - } - AdResponseContext *r = new AdResponseContext(_gameRef); - r->_id = id; - r->setContext(_dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL); - _responsesBranch.add(r); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::branchResponseUsed(int id) { - char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; - for (uint32 i = 0; i < _responsesBranch.size(); i++) { - if (_responsesBranch[i]->_id == id) { - if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { - return true; - } - } - } - return false; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::addGameResponse(int id) { - if (gameResponseUsed(id)) { - return STATUS_OK; - } - AdResponseContext *r = new AdResponseContext(_gameRef); - r->_id = id; - r->setContext(_dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL); - _responsesGame.add(r); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::gameResponseUsed(int id) { - char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; - for (uint32 i = 0; i < _responsesGame.size(); i++) { - AdResponseContext *respContext = _responsesGame[i]; - if (respContext->_id == id) { - if ((context == NULL && respContext->_context == NULL) || ((context != NULL && respContext->_context != NULL) && scumm_stricmp(context, respContext->_context) == 0)) { - return true; - } - } - } - return false; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::resetResponse(int id) { - char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; - - for (uint32 i = 0; i < _responsesGame.size(); i++) { - if (_responsesGame[i]->_id == id) { - if ((context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(context, _responsesGame[i]->_context) == 0) { - delete _responsesGame[i]; - _responsesGame.remove_at(i); - break; - } - } - } - - for (uint32 i = 0; i < _responsesBranch.size(); i++) { - if (_responsesBranch[i]->_id == id) { - if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { - delete _responsesBranch[i]; - _responsesBranch.remove_at(i); - break; - } - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::displayContent(bool doUpdate, bool displayAll) { - // init - if (doUpdate) { - initLoop(); - } - - // fill black - _renderer->fill(0, 0, 0); - if (!_editorMode) { - _renderer->setScreenViewport(); - } - - // playing exclusive video? - if (_videoPlayer->isPlaying()) { - if (doUpdate) { - _videoPlayer->update(); - } - _videoPlayer->display(); - } else if (_theoraPlayer) { - if (_theoraPlayer->isPlaying()) { - if (doUpdate) { - _theoraPlayer->update(); - } - _theoraPlayer->display(); - } - if (_theoraPlayer->isFinished()) { - delete _theoraPlayer; - _theoraPlayer = NULL; - } - } else { - - // process scripts - if (doUpdate) { - _scEngine->tick(); - } - - Point32 p; - getMousePos(&p); - - _scene->update(); - _scene->display(); - - - // display in-game windows - displayWindows(true); - if (_inventoryBox) { - _inventoryBox->display(); - } - if (_stateEx == GAME_WAITING_RESPONSE) { - _responseBox->display(); - } - _renderer->displayIndicator(); - - - if (doUpdate || displayAll) { - // display normal windows - displayWindows(false); - - setActiveObject(_gameRef->_renderer->getObjectAt(p.x, p.y)); - - // textual info - displaySentences(_state == GAME_FROZEN); - - showCursor(); - - if (_fader) { - _fader->display(); - } - _transMgr->update(); - } - - } - if (_loadingIcon) { - _loadingIcon->display(_loadingIconX, _loadingIconY); - if (!_loadingIconPersistent) { - delete _loadingIcon; - _loadingIcon = NULL; - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::registerInventory(AdInventory *inv) { - for (uint32 i = 0; i < _inventories.size(); i++) { - if (_inventories[i] == inv) { - return STATUS_OK; - } - } - registerObject(inv); - _inventories.add(inv); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::unregisterInventory(AdInventory *inv) { - for (uint32 i = 0; i < _inventories.size(); i++) { - if (_inventories[i] == inv) { - unregisterObject(_inventories[i]); - _inventories.remove_at(i); - return STATUS_OK; - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::isItemTaken(char *itemName) { - for (uint32 i = 0; i < _inventories.size(); i++) { - AdInventory *inv = _inventories[i]; - - for (uint32 j = 0; j < inv->_takenItems.size(); j++) { - if (scumm_stricmp(itemName, inv->_takenItems[j]->getName()) == 0) { - return true; - } - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -AdItem *AdGame::getItemByName(const char *name) { - for (uint32 i = 0; i < _items.size(); i++) { - if (scumm_stricmp(_items[i]->getName(), name) == 0) { - return _items[i]; - } - } - return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::addItem(AdItem *item) { - _items.add(item); - return _gameRef->registerObject(item); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::resetContent() { - // clear pending dialogs - for (uint32 i = 0; i < _dlgPendingBranches.size(); i++) { - delete[] _dlgPendingBranches[i]; - } - _dlgPendingBranches.clear(); - - - // clear inventories - for (uint32 i = 0; i < _inventories.size(); i++) { - _inventories[i]->_takenItems.clear(); - } - - // clear scene states - for (uint32 i = 0; i < _sceneStates.size(); i++) { - delete _sceneStates[i]; - } - _sceneStates.clear(); - - // clear once responses - for (uint32 i = 0; i < _responsesBranch.size(); i++) { - delete _responsesBranch[i]; - } - _responsesBranch.clear(); - - // clear once game responses - for (uint32 i = 0; i < _responsesGame.size(); i++) { - delete _responsesGame[i]; - } - _responsesGame.clear(); - - // reload inventory items - if (_itemsFile) { - loadItemsFile(_itemsFile); - } - - _tempDisableSaveState = true; - - return BaseGame::resetContent(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::deleteItem(AdItem *item) { - if (!item) { - return STATUS_FAILED; - } - - if (_selectedItem == item) { - _selectedItem = NULL; - } - _scene->handleItemAssociations(item->getName(), false); - - // remove from all inventories - for (uint32 i = 0; i < _inventories.size(); i++) { - _inventories[i]->removeItem(item); - } - - // remove object - for (uint32 i = 0; i < _items.size(); i++) { - if (_items[i] == item) { - unregisterObject(_items[i]); - _items.remove_at(i); - break; - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::addSpeechDir(const char *dir) { - if (!dir || dir[0] == '\0') { - return STATUS_FAILED; - } - - char *temp = new char[strlen(dir) + 2]; - strcpy(temp, dir); - if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') { - strcat(temp, "\\"); - } - - for (uint32 i = 0; i < _speechDirs.size(); i++) { - if (scumm_stricmp(_speechDirs[i], temp) == 0) { - delete[] temp; - return STATUS_OK; - } - } - _speechDirs.add(temp); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::removeSpeechDir(const char *dir) { - if (!dir || dir[0] == '\0') { - return STATUS_FAILED; - } - - char *temp = new char[strlen(dir) + 2]; - strcpy(temp, dir); - if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') { - strcat(temp, "\\"); - } - - bool found = false; - for (uint32 i = 0; i < _speechDirs.size(); i++) { - if (scumm_stricmp(_speechDirs[i], temp) == 0) { - delete[] _speechDirs[i]; - _speechDirs.remove_at(i); - found = true; - break; - } - } - delete[] temp; - - return found; -} - - -////////////////////////////////////////////////////////////////////////// -char *AdGame::findSpeechFile(char *stringID) { - char *ret = new char[MAX_PATH_LENGTH]; - - for (uint32 i = 0; i < _speechDirs.size(); i++) { - sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); - if (BaseFileManager::getEngineInstance()->hasFile(ret)) { - return ret; - } - - sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); - if (BaseFileManager::getEngineInstance()->hasFile(ret)) { - return ret; - } - } - delete[] ret; - return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::validMouse() { - Point32 pos; - BasePlatform::getCursorPos(&pos); - - return _renderer->pointInViewport(&pos); -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::onMouseLeftDown() { - if (!validMouse()) { - return STATUS_OK; - } - if (_state == GAME_RUNNING && !_interactive) { - if (_talkSkipButton == TALK_SKIP_LEFT || _talkSkipButton == TALK_SKIP_BOTH) { - finishSentences(); - } - return STATUS_OK; - } - - if (_activeObject) { - _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); - } - - bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("LeftClick"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("LeftClick"); - } - } - - if (_activeObject != NULL) { - _gameRef->_capturedObject = _gameRef->_activeObject; - } - _mouseLeftDown = true; - BasePlatform::setCapture(/*_renderer->_window*/); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::onMouseLeftUp() { - if (_activeObject) { - _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); - } - - BasePlatform::releaseCapture(); - _capturedObject = NULL; - _mouseLeftDown = false; - - bool handled = /*_state==GAME_RUNNING &&*/ DID_SUCCEED(applyEvent("LeftRelease")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("LeftRelease"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("LeftRelease"); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::onMouseLeftDblClick() { - if (!validMouse()) { - return STATUS_OK; - } - - if (_state == GAME_RUNNING && !_interactive) { - return STATUS_OK; - } - - if (_activeObject) { - _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); - } - - bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("LeftDoubleClick"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("LeftDoubleClick"); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::onMouseRightDown() { - if (!validMouse()) { - return STATUS_OK; - } - if (_state == GAME_RUNNING && !_interactive) { - if (_talkSkipButton == TALK_SKIP_RIGHT || _talkSkipButton == TALK_SKIP_BOTH) { - finishSentences(); - } - return STATUS_OK; - } - - if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) { - return STATUS_OK; - } - - if (_activeObject) { - _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); - } - - bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("RightClick"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("RightClick"); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::onMouseRightUp() { - if (_activeObject) { - _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); - } - - bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); - if (!handled) { - if (_activeObject != NULL) { - _activeObject->applyEvent("RightRelease"); - } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { - _scene->applyEvent("RightRelease"); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdGame::displayDebugInfo() { - char str[100]; - if (_gameRef->_debugDebugMode) { - sprintf(str, "Mouse: %d, %d (scene: %d, %d)", _mousePos.x, _mousePos.y, _mousePos.x + _scene->getOffsetLeft(), _mousePos.y + _scene->getOffsetTop()); - _systemFont->drawText((byte *)str, 0, 90, _renderer->_width, TAL_RIGHT); - - sprintf(str, "Scene: %s (prev: %s)", (_scene && _scene->getName()) ? _scene->getName() : "???", _prevSceneName ? _prevSceneName : "???"); - _systemFont->drawText((byte *)str, 0, 110, _renderer->_width, TAL_RIGHT); - } - return BaseGame::displayDebugInfo(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdGame::onScriptShutdown(ScScript *script) { - if (_responseBox && _responseBox->_waitingScript == script) { - _responseBox->_waitingScript = NULL; - } - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_actor.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/ad/ad_inventory.h" +#include "engines/wintermute/ad/ad_inventory_box.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/ad/ad_response.h" +#include "engines/wintermute/ad/ad_response_box.h" +#include "engines/wintermute/ad/ad_response_context.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/ad/ad_scene_state.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/base/base_string_table.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/base/base_transition_manager.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_viewport.h" +#include "engines/wintermute/base/particles/part_emitter.h" +#include "engines/wintermute/base/saveload.h" +#include "engines/wintermute/base/scriptables/script_engine.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/ui/ui_entity.h" +#include "engines/wintermute/ui/ui_window.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/video/video_player.h" +#include "engines/wintermute/video/video_theora_player.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdGame, true) + +////////////////////////////////////////////////////////////////////////// +AdGame::AdGame(const Common::String &gameId) : BaseGame(gameId) { + _responseBox = NULL; + _inventoryBox = NULL; + + _scene = new AdScene(_gameRef); + _scene->setName(""); + registerObject(_scene); + + _prevSceneName = NULL; + _prevSceneFilename = NULL; + _scheduledScene = NULL; + _scheduledFadeIn = false; + + + _stateEx = GAME_NORMAL; + + _selectedItem = NULL; + + + _texItemLifeTime = 10000; + _texWalkLifeTime = 10000; + _texStandLifeTime = 10000; + _texTalkLifeTime = 10000; + + _talkSkipButton = TALK_SKIP_LEFT; + + _sceneViewport = NULL; + + _initialScene = true; + _debugStartupScene = NULL; + _startupScene = NULL; + + _invObject = new AdObject(this); + _inventoryOwner = _invObject; + + _tempDisableSaveState = false; + _itemsFile = NULL; + + _smartItemCursor = false; + + addSpeechDir("speech"); +} + + +////////////////////////////////////////////////////////////////////////// +AdGame::~AdGame() { + cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::cleanup() { + for (uint32 i = 0; i < _objects.size(); i++) { + unregisterObject(_objects[i]); + _objects[i] = NULL; + } + _objects.clear(); + + + for (uint32 i = 0; i < _dlgPendingBranches.size(); i++) { + delete[] _dlgPendingBranches[i]; + } + _dlgPendingBranches.clear(); + + for (uint32 i = 0; i < _speechDirs.size(); i++) { + delete[] _speechDirs[i]; + } + _speechDirs.clear(); + + + unregisterObject(_scene); + _scene = NULL; + + // remove items + for (uint32 i = 0; i < _items.size(); i++) { + _gameRef->unregisterObject(_items[i]); + } + _items.clear(); + + + // clear remaining inventories + delete _invObject; + _invObject = NULL; + + for (uint32 i = 0; i < _inventories.size(); i++) { + delete _inventories[i]; + } + _inventories.clear(); + + + if (_responseBox) { + _gameRef->unregisterObject(_responseBox); + _responseBox = NULL; + } + + if (_inventoryBox) { + _gameRef->unregisterObject(_inventoryBox); + _inventoryBox = NULL; + } + + delete[] _prevSceneName; + delete[] _prevSceneFilename; + delete[] _scheduledScene; + delete[] _debugStartupScene; + delete[] _itemsFile; + _prevSceneName = NULL; + _prevSceneFilename = NULL; + _scheduledScene = NULL; + _debugStartupScene = NULL; + _startupScene = NULL; + _itemsFile = NULL; + + delete _sceneViewport; + _sceneViewport = NULL; + + for (uint32 i = 0; i < _sceneStates.size(); i++) { + delete _sceneStates[i]; + } + _sceneStates.clear(); + + for (uint32 i = 0; i < _responsesBranch.size(); i++) { + delete _responsesBranch[i]; + } + _responsesBranch.clear(); + + for (uint32 i = 0; i < _responsesGame.size(); i++) { + delete _responsesGame[i]; + } + _responsesGame.clear(); + + return BaseGame::cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::initLoop() { + if (_scheduledScene && _transMgr->isReady()) { + changeScene(_scheduledScene, _scheduledFadeIn); + delete[] _scheduledScene; + _scheduledScene = NULL; + + _gameRef->_activeObject = NULL; + } + + + bool res; + res = BaseGame::initLoop(); + if (DID_FAIL(res)) { + return res; + } + + if (_scene) { + res = _scene->initLoop(); + } + + _sentences.clear(); + + return res; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::addObject(AdObject *object) { + _objects.add(object); + return registerObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::removeObject(AdObject *object) { + // in case the user called Scene.CreateXXX() and Game.DeleteXXX() + if (_scene) { + bool res = _scene->removeObject(object); + if (DID_SUCCEED(res)) { + return res; + } + } + + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i] == object) { + _objects.remove_at(i); + break; + } + } + return unregisterObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::changeScene(const char *filename, bool fadeIn) { + if (_scene == NULL) { + _scene = new AdScene(_gameRef); + registerObject(_scene); + } else { + _scene->applyEvent("SceneShutdown", true); + + setPrevSceneName(_scene->getName()); + setPrevSceneFilename(_scene->getFilename()); + + if (!_tempDisableSaveState) { + _scene->saveState(); + } + _tempDisableSaveState = false; + } + + if (_scene) { + // reset objects + for (uint32 i = 0; i < _objects.size(); i++) { + _objects[i]->reset(); + } + + // reset scene properties + _scene->_sFXVolume = 100; + if (_scene->_scProp) { + _scene->_scProp->cleanup(); + } + + bool ret; + if (_initialScene && _debugDebugMode && _debugStartupScene) { + _initialScene = false; + ret = _scene->loadFile(_debugStartupScene); + } else { + ret = _scene->loadFile(filename); + } + + if (DID_SUCCEED(ret)) { + // invalidate references to the original scene + for (uint32 i = 0; i < _objects.size(); i++) { + _objects[i]->invalidateCurrRegions(); + _objects[i]->_stickRegion = NULL; + } + + _scene->loadState(); + } + if (fadeIn) { + _gameRef->_transMgr->start(TRANSITION_FADE_IN); + } + return ret; + } else { + return STATUS_FAILED; + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdGame::addSentence(AdSentence *sentence) { + _sentences.add(sentence); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::displaySentences(bool frozen) { + for (uint32 i = 0; i < _sentences.size(); i++) { + if (frozen && _sentences[i]->_freezable) { + continue; + } else { + _sentences[i]->display(); + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void AdGame::finishSentences() { + for (uint32 i = 0; i < _sentences.size(); i++) { + if (_sentences[i]->canSkip()) { + _sentences[i]->_duration = 0; + if (_sentences[i]->_sound) { + _sentences[i]->_sound->stop(); + } + } + } +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // ChangeScene + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "ChangeScene") == 0) { + stack->correctParams(3); + const char *filename = stack->pop()->getString(); + ScValue *valFadeOut = stack->pop(); + ScValue *valFadeIn = stack->pop(); + + bool transOut = valFadeOut->isNULL() ? true : valFadeOut->getBool(); + bool transIn = valFadeIn->isNULL() ? true : valFadeIn->getBool(); + + scheduleChangeScene(filename, transIn); + if (transOut) { + _transMgr->start(TRANSITION_FADE_OUT, true); + } + stack->pushNULL(); + + + //bool ret = ChangeScene(stack->pop()->getString()); + //if (DID_FAIL(ret)) stack->pushBool(false); + //else stack->pushBool(true); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadActor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadActor") == 0) { + stack->correctParams(1); + AdActor *act = new AdActor(_gameRef); + if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { + addObject(act); + stack->pushNative(act, true); + } else { + delete act; + act = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadEntity") == 0) { + stack->correctParams(1); + AdEntity *ent = new AdEntity(_gameRef); + if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { + addObject(ent); + stack->pushNative(ent, true); + } else { + delete ent; + ent = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadObject / UnloadActor / UnloadEntity / DeleteEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "DeleteEntity") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + AdObject *obj = (AdObject *)val->getNative(); + removeObject(obj); + if (val->getType() == VAL_VARIABLE_REF) { + val->setNULL(); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateEntity") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdEntity *ent = new AdEntity(_gameRef); + addObject(ent); + if (!val->isNULL()) { + ent->setName(val->getString()); + } + stack->pushNative(ent, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateItem") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdItem *item = new AdItem(_gameRef); + addItem(item); + if (!val->isNULL()) { + item->setName(val->getString()); + } + stack->pushNative(item, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteItem") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdItem *item = NULL; + if (val->isNative()) { + item = (AdItem *)val->getNative(); + } else { + item = getItemByName(val->getString()); + } + + if (item) { + deleteItem(item); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // QueryItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "QueryItem") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdItem *item = NULL; + if (val->isInt()) { + int index = val->getInt(); + if (index >= 0 && index < (int32)_items.size()) { + item = _items[index]; + } + } else { + item = getItemByName(val->getString()); + } + + if (item) { + stack->pushNative(item, true); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // AddResponse/AddResponseOnce/AddResponseOnceGame + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddResponse") == 0 || strcmp(name, "AddResponseOnce") == 0 || strcmp(name, "AddResponseOnceGame") == 0) { + stack->correctParams(6); + int id = stack->pop()->getInt(); + const char *text = stack->pop()->getString(); + ScValue *val1 = stack->pop(); + ScValue *val2 = stack->pop(); + ScValue *val3 = stack->pop(); + ScValue *val4 = stack->pop(); + + if (_responseBox) { + AdResponse *res = new AdResponse(_gameRef); + if (res) { + res->_iD = id; + res->setText(text); + _stringTable->expand(&res->_text); + if (!val1->isNULL()) { + res->setIcon(val1->getString()); + } + if (!val2->isNULL()) { + res->setIconHover(val2->getString()); + } + if (!val3->isNULL()) { + res->setIconPressed(val3->getString()); + } + if (!val4->isNULL()) { + res->setFont(val4->getString()); + } + + if (strcmp(name, "AddResponseOnce") == 0) { + res->_responseType = RESPONSE_ONCE; + } else if (strcmp(name, "AddResponseOnceGame") == 0) { + res->_responseType = RESPONSE_ONCE_GAME; + } + + _responseBox->_responses.add(res); + } + } else { + script->runtimeError("Game.AddResponse: response box is not defined"); + } + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ResetResponse + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResetResponse") == 0) { + stack->correctParams(1); + int id = stack->pop()->getInt(-1); + resetResponse(id); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ClearResponses + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ClearResponses") == 0) { + stack->correctParams(0); + _responseBox->clearResponses(); + _responseBox->clearButtons(); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetResponse + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetResponse") == 0) { + stack->correctParams(1); + bool autoSelectLast = stack->pop()->getBool(); + + if (_responseBox) { + _responseBox->weedResponses(); + + if (_responseBox->_responses.size() == 0) { + stack->pushNULL(); + return STATUS_OK; + } + + + if (_responseBox->_responses.size() == 1 && autoSelectLast) { + stack->pushInt(_responseBox->_responses[0]->_iD); + _responseBox->handleResponse(_responseBox->_responses[0]); + _responseBox->clearResponses(); + return STATUS_OK; + } + + _responseBox->createButtons(); + _responseBox->_waitingScript = script; + script->waitForExclusive(_responseBox); + _state = GAME_SEMI_FROZEN; + _stateEx = GAME_WAITING_RESPONSE; + } else { + script->runtimeError("Game.GetResponse: response box is not defined"); + stack->pushNULL(); + } + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // GetNumResponses + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNumResponses") == 0) { + stack->correctParams(0); + if (_responseBox) { + _responseBox->weedResponses(); + stack->pushInt(_responseBox->_responses.size()); + } else { + script->runtimeError("Game.GetNumResponses: response box is not defined"); + stack->pushNULL(); + } + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // StartDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartDlgBranch") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + Common::String branchName; + if (val->isNULL()) { + branchName.format("line%d", script->_currentLine); + } else { + branchName = val->getString(); + } + + startDlgBranch(branchName.c_str(), script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // EndDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "EndDlgBranch") == 0) { + stack->correctParams(1); + + const char *branchName = NULL; + ScValue *val = stack->pop(); + if (!val->isNULL()) { + branchName = val->getString(); + } + endDlgBranch(branchName, script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); + + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetCurrentDlgBranch + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetCurrentDlgBranch") == 0) { + stack->correctParams(0); + + if (_dlgPendingBranches.size() > 0) { + stack->pushString(_dlgPendingBranches[_dlgPendingBranches.size() - 1]); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TakeItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TakeItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // DropItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DropItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // GetItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // HasItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasItem") == 0) { + return _invObject->scCallMethod(script, stack, thisStack, name); + } + + ////////////////////////////////////////////////////////////////////////// + // IsItemTaken + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsItemTaken") == 0) { + stack->correctParams(1); + + ScValue *val = stack->pop(); + if (!val->isNULL()) { + for (uint32 i = 0; i < _inventories.size(); i++) { + AdInventory *inv = _inventories[i]; + + for (uint32 j = 0; j < inv->_takenItems.size(); j++) { + if (val->getNative() == inv->_takenItems[j]) { + stack->pushBool(true); + return STATUS_OK; + } else if (scumm_stricmp(val->getString(), inv->_takenItems[j]->getName()) == 0) { + stack->pushBool(true); + return STATUS_OK; + } + } + } + } else { + script->runtimeError("Game.IsItemTaken: item name expected"); + } + + stack->pushBool(false); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetInventoryWindow + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetInventoryWindow") == 0) { + stack->correctParams(0); + if (_inventoryBox && _inventoryBox->_window) { + stack->pushNative(_inventoryBox->_window, true); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetResponsesWindow + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetResponsesWindow") == 0 || strcmp(name, "GetResponseWindow") == 0) { + stack->correctParams(0); + if (_responseBox && _responseBox->_window) { + stack->pushNative(_responseBox->_window, true); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadResponseBox + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadResponseBox") == 0) { + stack->correctParams(1); + const char *filename = stack->pop()->getString(); + + _gameRef->unregisterObject(_responseBox); + _responseBox = new AdResponseBox(_gameRef); + if (_responseBox && !DID_FAIL(_responseBox->loadFile(filename))) { + registerObject(_responseBox); + stack->pushBool(true); + } else { + delete _responseBox; + _responseBox = NULL; + stack->pushBool(false); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadInventoryBox + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadInventoryBox") == 0) { + stack->correctParams(1); + const char *filename = stack->pop()->getString(); + + _gameRef->unregisterObject(_inventoryBox); + _inventoryBox = new AdInventoryBox(_gameRef); + if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile(filename))) { + registerObject(_inventoryBox); + stack->pushBool(true); + } else { + delete _inventoryBox; + _inventoryBox = NULL; + stack->pushBool(false); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadItems") == 0) { + stack->correctParams(2); + const char *filename = stack->pop()->getString(); + bool merge = stack->pop()->getBool(false); + + bool ret = loadItemsFile(filename, merge); + stack->pushBool(DID_SUCCEED(ret)); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddSpeechDir + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddSpeechDir") == 0) { + stack->correctParams(1); + const char *dir = stack->pop()->getString(); + stack->pushBool(DID_SUCCEED(addSpeechDir(dir))); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveSpeechDir + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveSpeechDir") == 0) { + stack->correctParams(1); + const char *dir = stack->pop()->getString(); + stack->pushBool(DID_SUCCEED(removeSpeechDir(dir))); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetSceneViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetSceneViewport") == 0) { + stack->correctParams(4); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + int width = stack->pop()->getInt(); + int height = stack->pop()->getInt(); + + if (width <= 0) { + width = _renderer->_width; + } + if (height <= 0) { + height = _renderer->_height; + } + + if (!_sceneViewport) { + _sceneViewport = new BaseViewport(_gameRef); + } + if (_sceneViewport) { + _sceneViewport->setRect(x, y, x + width, y + height); + } + + stack->pushBool(true); + + return STATUS_OK; + } + + + else { + return BaseGame::scCallMethod(script, stack, thisStack, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdGame::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("game"); + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // Scene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scene") == 0) { + if (_scene) { + _scValue->setNative(_scene, true); + } else { + _scValue->setNULL(); + } + + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // SelectedItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SelectedItem") == 0) { + //if (_selectedItem) _scValue->setString(_selectedItem->_name); + if (_selectedItem) { + _scValue->setNative(_selectedItem, true); + } else { + _scValue->setNULL(); + } + + return _scValue; + } + ////////////////////////////////////////////////////////////////////////// + // NumItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumItems") == 0) { + return _invObject->scGetProperty(name); + } + + ////////////////////////////////////////////////////////////////////////// + // SmartItemCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SmartItemCursor") == 0) { + _scValue->setBool(_smartItemCursor); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryVisible + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryVisible") == 0) { + _scValue->setBool(_inventoryBox && _inventoryBox->_visible); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryScrollOffset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryScrollOffset") == 0) { + if (_inventoryBox) { + _scValue->setInt(_inventoryBox->_scrollOffset); + } else { + _scValue->setInt(0); + } + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ResponsesVisible (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ResponsesVisible") == 0) { + _scValue->setBool(_stateEx == GAME_WAITING_RESPONSE); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PrevScene / PreviousScene (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PrevScene") == 0 || strcmp(name, "PreviousScene") == 0) { + if (!_prevSceneName) { + _scValue->setString(""); + } else { + _scValue->setString(_prevSceneName); + } + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PrevSceneFilename / PreviousSceneFilename (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PrevSceneFilename") == 0 || strcmp(name, "PreviousSceneFilename") == 0) { + if (!_prevSceneFilename) { + _scValue->setString(""); + } else { + _scValue->setString(_prevSceneFilename); + } + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // LastResponse (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LastResponse") == 0) { + if (!_responseBox || !_responseBox->_lastResponseText) { + _scValue->setString(""); + } else { + _scValue->setString(_responseBox->_lastResponseText); + } + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // LastResponseOrig (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LastResponseOrig") == 0) { + if (!_responseBox || !_responseBox->_lastResponseTextOrig) { + _scValue->setString(""); + } else { + _scValue->setString(_responseBox->_lastResponseTextOrig); + } + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryObject") == 0) { + if (_inventoryOwner == _invObject) { + _scValue->setNative(this, true); + } else { + _scValue->setNative(_inventoryOwner, true); + } + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TotalNumItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TotalNumItems") == 0) { + _scValue->setInt(_items.size()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkSkipButton + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkSkipButton") == 0) { + _scValue->setInt(_talkSkipButton); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ChangingScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ChangingScene") == 0) { + _scValue->setBool(_scheduledScene != NULL); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // StartupScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartupScene") == 0) { + if (!_startupScene) { + _scValue->setNULL(); + } else { + _scValue->setString(_startupScene); + } + return _scValue; + } + + else { + return BaseGame::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::scSetProperty(const char *name, ScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // SelectedItem + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SelectedItem") == 0) { + if (value->isNULL()) { + _selectedItem = NULL; + } else { + if (value->isNative()) { + _selectedItem = NULL; + for (uint32 i = 0; i < _items.size(); i++) { + if (_items[i] == value->getNative()) { + _selectedItem = (AdItem *)value->getNative(); + break; + } + } + } else { + // try to get by name + _selectedItem = getItemByName(value->getString()); + } + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SmartItemCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SmartItemCursor") == 0) { + _smartItemCursor = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryVisible + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryVisible") == 0) { + if (_inventoryBox) { + _inventoryBox->_visible = value->getBool(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryObject") == 0) { + if (_inventoryOwner && _inventoryBox) { + _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; + } + + if (value->isNULL()) { + _inventoryOwner = _invObject; + } else { + BaseObject *obj = (BaseObject *)value->getNative(); + if (obj == this) { + _inventoryOwner = _invObject; + } else if (_gameRef->validObject(obj)) { + _inventoryOwner = (AdObject *)obj; + } + } + + if (_inventoryOwner && _inventoryBox) { + _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InventoryScrollOffset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InventoryScrollOffset") == 0) { + if (_inventoryBox) { + _inventoryBox->_scrollOffset = value->getInt(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TalkSkipButton + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TalkSkipButton") == 0) { + int val = value->getInt(); + if (val < 0) { + val = 0; + } + if (val > TALK_SKIP_NONE) { + val = TALK_SKIP_NONE; + } + _talkSkipButton = (TTalkSkipButton)val; + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StartupScene + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StartupScene") == 0) { + if (value == NULL) { + delete[] _startupScene; + _startupScene = NULL; + } else { + BaseUtils::setString(&_startupScene, value->getString()); + } + + return STATUS_OK; + } + + else { + return BaseGame::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::externalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name) { + ScValue *thisObj; + + ////////////////////////////////////////////////////////////////////////// + // Actor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Actor") == 0) { + stack->correctParams(0); + thisObj = thisStack->getTop(); + + thisObj->setNative(new AdActor(_gameRef)); + stack->pushNULL(); + } + + ////////////////////////////////////////////////////////////////////////// + // Entity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Entity") == 0) { + stack->correctParams(0); + thisObj = thisStack->getTop(); + + thisObj->setNative(new AdEntity(_gameRef)); + stack->pushNULL(); + } + + + ////////////////////////////////////////////////////////////////////////// + // call parent + else { + return BaseGame::externalCall(script, stack, thisStack, name); + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::showCursor() { + if (_cursorHidden) { + return STATUS_OK; + } + + if (_selectedItem && _gameRef->_state == GAME_RUNNING && _stateEx == GAME_NORMAL && _interactive) { + if (_selectedItem->_cursorCombined) { + BaseSprite *origLastCursor = _lastCursor; + BaseGame::showCursor(); + _lastCursor = origLastCursor; + } + if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { + if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->getName())) { + return drawCursor(_selectedItem->_cursorHover); + } else { + return drawCursor(_selectedItem->_cursorNormal); + } + } else { + return drawCursor(_selectedItem->_cursorNormal); + } + } else { + return BaseGame::showCursor(); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdGame::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(GAME) +TOKEN_DEF(AD_GAME) +TOKEN_DEF(RESPONSE_BOX) +TOKEN_DEF(INVENTORY_BOX) +TOKEN_DEF(ITEMS) +TOKEN_DEF(ITEM) +TOKEN_DEF(TALK_SKIP_BUTTON) +TOKEN_DEF(SCENE_VIEWPORT) +TOKEN_DEF(ENTITY_CONTAINER) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF(STARTUP_SCENE) +TOKEN_DEF(DEBUG_STARTUP_SCENE) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdGame::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(GAME) + TOKEN_TABLE(AD_GAME) + TOKEN_TABLE(RESPONSE_BOX) + TOKEN_TABLE(INVENTORY_BOX) + TOKEN_TABLE(ITEMS) + TOKEN_TABLE(TALK_SKIP_BUTTON) + TOKEN_TABLE(SCENE_VIEWPORT) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE(STARTUP_SCENE) + TOKEN_TABLE(DEBUG_STARTUP_SCENE) + TOKEN_TABLE_END + + byte *params; + byte *params2; + int cmd = 1; + BaseParser parser; + + bool itemFound = false, itemsFound = false; + + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_GAME: + if (DID_FAIL(BaseGame::loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_AD_GAME: + while (cmd > 0 && (cmd = parser.getCommand((char **)¶ms, commands, (char **)¶ms2)) > 0) { + switch (cmd) { + case TOKEN_RESPONSE_BOX: + delete _responseBox; + _responseBox = new AdResponseBox(_gameRef); + if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) { + registerObject(_responseBox); + } else { + delete _responseBox; + _responseBox = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_INVENTORY_BOX: + delete _inventoryBox; + _inventoryBox = new AdInventoryBox(_gameRef); + if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) { + registerObject(_inventoryBox); + } else { + delete _inventoryBox; + _inventoryBox = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_ITEMS: + itemsFound = true; + BaseUtils::setString(&_itemsFile, (char *)params2); + if (DID_FAIL(loadItemsFile(_itemsFile))) { + delete[] _itemsFile; + _itemsFile = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_TALK_SKIP_BUTTON: + if (scumm_stricmp((char *)params2, "right") == 0) { + _talkSkipButton = TALK_SKIP_RIGHT; + } else if (scumm_stricmp((char *)params2, "both") == 0) { + _talkSkipButton = TALK_SKIP_BOTH; + } else { + _talkSkipButton = TALK_SKIP_LEFT; + } + break; + + case TOKEN_SCENE_VIEWPORT: { + Rect32 rc; + parser.scanStr((char *)params2, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); + if (!_sceneViewport) { + _sceneViewport = new BaseViewport(_gameRef); + } + if (_sceneViewport) { + _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); + } + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params2, false); + break; + + case TOKEN_STARTUP_SCENE: + BaseUtils::setString(&_startupScene, (char *)params2); + break; + + case TOKEN_DEBUG_STARTUP_SCENE: + BaseUtils::setString(&_debugStartupScene, (char *)params2); + break; + } + } + break; + } + } + + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in GAME definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading GAME definition"); + return STATUS_FAILED; + } + + if (itemFound && !itemsFound) { + _gameRef->LOG(0, "**Warning** Please put the items definition to a separate file."); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::persist(BasePersistenceManager *persistMgr) { + if (!persistMgr->getIsSaving()) { + cleanup(); + } + BaseGame::persist(persistMgr); + + _dlgPendingBranches.persist(persistMgr); + + _inventories.persist(persistMgr); + persistMgr->transfer(TMEMBER(_inventoryBox)); + + _objects.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_prevSceneName)); + persistMgr->transfer(TMEMBER(_prevSceneFilename)); + + persistMgr->transfer(TMEMBER(_responseBox)); + _responsesBranch.persist(persistMgr); + _responsesGame.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scene)); + _sceneStates.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scheduledFadeIn)); + persistMgr->transfer(TMEMBER(_scheduledScene)); + persistMgr->transfer(TMEMBER(_selectedItem)); + persistMgr->transfer(TMEMBER_INT(_talkSkipButton)); + + _sentences.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_sceneViewport)); + persistMgr->transfer(TMEMBER_INT(_stateEx)); + persistMgr->transfer(TMEMBER(_initialScene)); + persistMgr->transfer(TMEMBER(_debugStartupScene)); + + persistMgr->transfer(TMEMBER(_invObject)); + persistMgr->transfer(TMEMBER(_inventoryOwner)); + persistMgr->transfer(TMEMBER(_tempDisableSaveState)); + _items.persist(persistMgr); + + persistMgr->transfer(TMEMBER(_itemsFile)); + + _speechDirs.persist(persistMgr); + persistMgr->transfer(TMEMBER(_smartItemCursor)); + + if (!persistMgr->getIsSaving()) { + _initialScene = false; + } + + persistMgr->transfer(TMEMBER(_startupScene)); + + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +void AdGame::setPrevSceneName(const char *name) { + delete[] _prevSceneName; + _prevSceneName = NULL; + if (name) { + _prevSceneName = new char[strlen(name) + 1]; + if (_prevSceneName) { + strcpy(_prevSceneName, name); + } + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdGame::setPrevSceneFilename(const char *name) { + delete[] _prevSceneFilename; + _prevSceneFilename = NULL; + if (name) { + _prevSceneFilename = new char[strlen(name) + 1]; + if (_prevSceneFilename) { + strcpy(_prevSceneFilename, name); + } + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::scheduleChangeScene(const char *filename, bool fadeIn) { + delete[] _scheduledScene; + _scheduledScene = NULL; + + if (_scene && !_scene->_initialized) { + return changeScene(filename, fadeIn); + } else { + _scheduledScene = new char [strlen(filename) + 1]; + strcpy(_scheduledScene, filename); + + _scheduledFadeIn = fadeIn; + + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { + BaseGame::getVersion(verMajor, verMinor, NULL, NULL); + + if (extMajor) { + *extMajor = 0; + } + if (extMinor) { + *extMinor = 0; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::loadItemsFile(const char *filename, bool merge) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdGame::LoadItemsFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + //_filename = new char [strlen(filename)+1]; + //strcpy(_filename, filename); + + if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) { + _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ITEM) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (!merge) { + while (_items.size() > 0) { + deleteItem(_items[0]); + } + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_ITEM: { + AdItem *item = new AdItem(_gameRef); + if (item && !DID_FAIL(item->loadBuffer(params, false))) { + // delete item with the same name, if exists + if (merge) { + AdItem *prevItem = getItemByName(item->getName()); + if (prevItem) { + deleteItem(prevItem); + } + } + addItem(item); + } else { + delete item; + item = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + } + } + + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ITEMS definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ITEMS definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +AdSceneState *AdGame::getSceneState(const char *filename, bool saving) { + char *filenameCor = new char[strlen(filename) + 1]; + strcpy(filenameCor, filename); + for (uint32 i = 0; i < strlen(filenameCor); i++) { + if (filenameCor[i] == '/') { + filenameCor[i] = '\\'; + } + } + + for (uint32 i = 0; i < _sceneStates.size(); i++) { + if (scumm_stricmp(_sceneStates[i]->_filename, filenameCor) == 0) { + delete[] filenameCor; + return _sceneStates[i]; + } + } + + if (saving) { + AdSceneState *ret = new AdSceneState(_gameRef); + ret->setFilename(filenameCor); + + _sceneStates.add(ret); + + delete[] filenameCor; + return ret; + } else { + delete[] filenameCor; + return NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::windowLoadHook(UIWindow *win, char **buffer, char **params) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ENTITY_CONTAINER) + TOKEN_TABLE_END + + int cmd = PARSERR_GENERIC; + BaseParser parser; + + cmd = parser.getCommand(buffer, commands, params); + switch (cmd) { + case TOKEN_ENTITY_CONTAINER: { + UIEntity *ent = new UIEntity(_gameRef); + if (!ent || DID_FAIL(ent->loadBuffer((byte *)*params, false))) { + delete ent; + ent = NULL; + cmd = PARSERR_GENERIC; + } else { + ent->_parent = win; + win->_widgets.add(ent); + } + } + break; + } + + if (cmd == PARSERR_TOKENNOTFOUND || cmd == PARSERR_GENERIC) { + return STATUS_FAILED; + } + + return STATUS_OK; + +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *stack, const char *name) { + if (strcmp(name, "CreateEntityContainer") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + UIEntity *ent = new UIEntity(_gameRef); + if (!val->isNULL()) { + ent->setName(val->getString()); + } + stack->pushNative(ent, true); + + ent->_parent = win; + win->_widgets.add(ent); + + return STATUS_OK; + } else { + return STATUS_FAILED; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::startDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { + char *name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; + if (name) { + sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); + _dlgPendingBranches.add(name); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const char *eventName) { + char *name = NULL; + bool deleteName = false; + if (branchName == NULL && _dlgPendingBranches.size() > 0) { + name = _dlgPendingBranches[_dlgPendingBranches.size() - 1]; + } else { + if (branchName != NULL) { + name = new char[strlen(branchName) + 1 + strlen(scriptName) + 1 + strlen(eventName) + 1]; + if (name) { + sprintf(name, "%s.%s.%s", branchName, scriptName, eventName); + deleteName = true; + } + } + } + + if (name == NULL) { + return STATUS_OK; + } + + + int startIndex = -1; + for (int i = _dlgPendingBranches.size() - 1; i >= 0; i--) { + if (scumm_stricmp(name, _dlgPendingBranches[i]) == 0) { + startIndex = i; + break; + } + } + if (startIndex >= 0) { + for (uint32 i = startIndex; i < _dlgPendingBranches.size(); i++) { + //ClearBranchResponses(_dlgPendingBranches[i]); + delete[] _dlgPendingBranches[i]; + _dlgPendingBranches[i] = NULL; + } + _dlgPendingBranches.remove_at(startIndex, _dlgPendingBranches.size() - startIndex); + } + + // dialogue is over, forget selected responses + if (_dlgPendingBranches.size() == 0) { + for (uint32 i = 0; i < _responsesBranch.size(); i++) { + delete _responsesBranch[i]; + } + _responsesBranch.clear(); + } + + if (deleteName) { + delete[] name; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::clearBranchResponses(char *name) { + for (uint32 i = 0; i < _responsesBranch.size(); i++) { + if (scumm_stricmp(name, _responsesBranch[i]->_context) == 0) { + delete _responsesBranch[i]; + _responsesBranch.remove_at(i); + i--; + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::addBranchResponse(int id) { + if (branchResponseUsed(id)) { + return STATUS_OK; + } + AdResponseContext *r = new AdResponseContext(_gameRef); + r->_id = id; + r->setContext(_dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL); + _responsesBranch.add(r); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::branchResponseUsed(int id) { + char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; + for (uint32 i = 0; i < _responsesBranch.size(); i++) { + if (_responsesBranch[i]->_id == id) { + if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { + return true; + } + } + } + return false; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::addGameResponse(int id) { + if (gameResponseUsed(id)) { + return STATUS_OK; + } + AdResponseContext *r = new AdResponseContext(_gameRef); + r->_id = id; + r->setContext(_dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL); + _responsesGame.add(r); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::gameResponseUsed(int id) { + char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; + for (uint32 i = 0; i < _responsesGame.size(); i++) { + AdResponseContext *respContext = _responsesGame[i]; + if (respContext->_id == id) { + if ((context == NULL && respContext->_context == NULL) || ((context != NULL && respContext->_context != NULL) && scumm_stricmp(context, respContext->_context) == 0)) { + return true; + } + } + } + return false; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::resetResponse(int id) { + char *context = _dlgPendingBranches.size() > 0 ? _dlgPendingBranches[_dlgPendingBranches.size() - 1] : NULL; + + for (uint32 i = 0; i < _responsesGame.size(); i++) { + if (_responsesGame[i]->_id == id) { + if ((context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(context, _responsesGame[i]->_context) == 0) { + delete _responsesGame[i]; + _responsesGame.remove_at(i); + break; + } + } + } + + for (uint32 i = 0; i < _responsesBranch.size(); i++) { + if (_responsesBranch[i]->_id == id) { + if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { + delete _responsesBranch[i]; + _responsesBranch.remove_at(i); + break; + } + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::displayContent(bool doUpdate, bool displayAll) { + // init + if (doUpdate) { + initLoop(); + } + + // fill black + _renderer->fill(0, 0, 0); + if (!_editorMode) { + _renderer->setScreenViewport(); + } + + // playing exclusive video? + if (_videoPlayer->isPlaying()) { + if (doUpdate) { + _videoPlayer->update(); + } + _videoPlayer->display(); + } else if (_theoraPlayer) { + if (_theoraPlayer->isPlaying()) { + if (doUpdate) { + _theoraPlayer->update(); + } + _theoraPlayer->display(); + } + if (_theoraPlayer->isFinished()) { + delete _theoraPlayer; + _theoraPlayer = NULL; + } + } else { + + // process scripts + if (doUpdate) { + _scEngine->tick(); + } + + Point32 p; + getMousePos(&p); + + _scene->update(); + _scene->display(); + + + // display in-game windows + displayWindows(true); + if (_inventoryBox) { + _inventoryBox->display(); + } + if (_stateEx == GAME_WAITING_RESPONSE) { + _responseBox->display(); + } + _renderer->displayIndicator(); + + + if (doUpdate || displayAll) { + // display normal windows + displayWindows(false); + + setActiveObject(_gameRef->_renderer->getObjectAt(p.x, p.y)); + + // textual info + displaySentences(_state == GAME_FROZEN); + + showCursor(); + + if (_fader) { + _fader->display(); + } + _transMgr->update(); + } + + } + if (_loadingIcon) { + _loadingIcon->display(_loadingIconX, _loadingIconY); + if (!_loadingIconPersistent) { + delete _loadingIcon; + _loadingIcon = NULL; + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::registerInventory(AdInventory *inv) { + for (uint32 i = 0; i < _inventories.size(); i++) { + if (_inventories[i] == inv) { + return STATUS_OK; + } + } + registerObject(inv); + _inventories.add(inv); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::unregisterInventory(AdInventory *inv) { + for (uint32 i = 0; i < _inventories.size(); i++) { + if (_inventories[i] == inv) { + unregisterObject(_inventories[i]); + _inventories.remove_at(i); + return STATUS_OK; + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::isItemTaken(char *itemName) { + for (uint32 i = 0; i < _inventories.size(); i++) { + AdInventory *inv = _inventories[i]; + + for (uint32 j = 0; j < inv->_takenItems.size(); j++) { + if (scumm_stricmp(itemName, inv->_takenItems[j]->getName()) == 0) { + return true; + } + } + } + return false; +} + +////////////////////////////////////////////////////////////////////////// +AdItem *AdGame::getItemByName(const char *name) { + for (uint32 i = 0; i < _items.size(); i++) { + if (scumm_stricmp(_items[i]->getName(), name) == 0) { + return _items[i]; + } + } + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::addItem(AdItem *item) { + _items.add(item); + return _gameRef->registerObject(item); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::resetContent() { + // clear pending dialogs + for (uint32 i = 0; i < _dlgPendingBranches.size(); i++) { + delete[] _dlgPendingBranches[i]; + } + _dlgPendingBranches.clear(); + + + // clear inventories + for (uint32 i = 0; i < _inventories.size(); i++) { + _inventories[i]->_takenItems.clear(); + } + + // clear scene states + for (uint32 i = 0; i < _sceneStates.size(); i++) { + delete _sceneStates[i]; + } + _sceneStates.clear(); + + // clear once responses + for (uint32 i = 0; i < _responsesBranch.size(); i++) { + delete _responsesBranch[i]; + } + _responsesBranch.clear(); + + // clear once game responses + for (uint32 i = 0; i < _responsesGame.size(); i++) { + delete _responsesGame[i]; + } + _responsesGame.clear(); + + // reload inventory items + if (_itemsFile) { + loadItemsFile(_itemsFile); + } + + _tempDisableSaveState = true; + + return BaseGame::resetContent(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::deleteItem(AdItem *item) { + if (!item) { + return STATUS_FAILED; + } + + if (_selectedItem == item) { + _selectedItem = NULL; + } + _scene->handleItemAssociations(item->getName(), false); + + // remove from all inventories + for (uint32 i = 0; i < _inventories.size(); i++) { + _inventories[i]->removeItem(item); + } + + // remove object + for (uint32 i = 0; i < _items.size(); i++) { + if (_items[i] == item) { + unregisterObject(_items[i]); + _items.remove_at(i); + break; + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::addSpeechDir(const char *dir) { + if (!dir || dir[0] == '\0') { + return STATUS_FAILED; + } + + char *temp = new char[strlen(dir) + 2]; + strcpy(temp, dir); + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') { + strcat(temp, "\\"); + } + + for (uint32 i = 0; i < _speechDirs.size(); i++) { + if (scumm_stricmp(_speechDirs[i], temp) == 0) { + delete[] temp; + return STATUS_OK; + } + } + _speechDirs.add(temp); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::removeSpeechDir(const char *dir) { + if (!dir || dir[0] == '\0') { + return STATUS_FAILED; + } + + char *temp = new char[strlen(dir) + 2]; + strcpy(temp, dir); + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') { + strcat(temp, "\\"); + } + + bool found = false; + for (uint32 i = 0; i < _speechDirs.size(); i++) { + if (scumm_stricmp(_speechDirs[i], temp) == 0) { + delete[] _speechDirs[i]; + _speechDirs.remove_at(i); + found = true; + break; + } + } + delete[] temp; + + return found; +} + + +////////////////////////////////////////////////////////////////////////// +char *AdGame::findSpeechFile(char *stringID) { + char *ret = new char[MAX_PATH_LENGTH]; + + for (uint32 i = 0; i < _speechDirs.size(); i++) { + sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); + if (BaseFileManager::getEngineInstance()->hasFile(ret)) { + return ret; + } + + sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); + if (BaseFileManager::getEngineInstance()->hasFile(ret)) { + return ret; + } + } + delete[] ret; + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::validMouse() { + Point32 pos; + BasePlatform::getCursorPos(&pos); + + return _renderer->pointInViewport(&pos); +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::onMouseLeftDown() { + if (!validMouse()) { + return STATUS_OK; + } + if (_state == GAME_RUNNING && !_interactive) { + if (_talkSkipButton == TALK_SKIP_LEFT || _talkSkipButton == TALK_SKIP_BOTH) { + finishSentences(); + } + return STATUS_OK; + } + + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + } + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftClick"); + } + } + + if (_activeObject != NULL) { + _gameRef->_capturedObject = _gameRef->_activeObject; + } + _mouseLeftDown = true; + BasePlatform::setCapture(/*_renderer->_window*/); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::onMouseLeftUp() { + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + } + + BasePlatform::releaseCapture(); + _capturedObject = NULL; + _mouseLeftDown = false; + + bool handled = /*_state==GAME_RUNNING &&*/ DID_SUCCEED(applyEvent("LeftRelease")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftRelease"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftRelease"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::onMouseLeftDblClick() { + if (!validMouse()) { + return STATUS_OK; + } + + if (_state == GAME_RUNNING && !_interactive) { + return STATUS_OK; + } + + if (_activeObject) { + _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + } + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("LeftDoubleClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("LeftDoubleClick"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::onMouseRightDown() { + if (!validMouse()) { + return STATUS_OK; + } + if (_state == GAME_RUNNING && !_interactive) { + if (_talkSkipButton == TALK_SKIP_RIGHT || _talkSkipButton == TALK_SKIP_BOTH) { + finishSentences(); + } + return STATUS_OK; + } + + if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) { + return STATUS_OK; + } + + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + } + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("RightClick"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("RightClick"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::onMouseRightUp() { + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + } + + bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); + if (!handled) { + if (_activeObject != NULL) { + _activeObject->applyEvent("RightRelease"); + } else if (_state == GAME_RUNNING && _scene && _scene->pointInViewport(_mousePos.x, _mousePos.y)) { + _scene->applyEvent("RightRelease"); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdGame::displayDebugInfo() { + char str[100]; + if (_gameRef->_debugDebugMode) { + sprintf(str, "Mouse: %d, %d (scene: %d, %d)", _mousePos.x, _mousePos.y, _mousePos.x + _scene->getOffsetLeft(), _mousePos.y + _scene->getOffsetTop()); + _systemFont->drawText((byte *)str, 0, 90, _renderer->_width, TAL_RIGHT); + + sprintf(str, "Scene: %s (prev: %s)", (_scene && _scene->getName()) ? _scene->getName() : "???", _prevSceneName ? _prevSceneName : "???"); + _systemFont->drawText((byte *)str, 0, 110, _renderer->_width, TAL_RIGHT); + } + return BaseGame::displayDebugInfo(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdGame::onScriptShutdown(ScScript *script) { + if (_responseBox && _responseBox->_waitingScript == script) { + _responseBox->_waitingScript = NULL; + } + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index 5707ec48fd..46427331bf 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -1,163 +1,163 @@ -/* 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. - - * 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. - - * 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 - */ -#ifndef WINTERMUTE_ADGAME_H -#define WINTERMUTE_ADGAME_H - -#include "engines/wintermute/ad/ad_types.h" -#include "engines/wintermute/base/base_game.h" - -namespace Wintermute { -class AdItem; -class AdInventory; -class AdSceneState; -class AdScene; -class AdItem; -class AdObject; -class AdSentence; -class AdInventoryBox; -class AdResponseContext; -class AdResponseBox; -class AdGame : public BaseGame { -public: - virtual bool onScriptShutdown(ScScript *script); - - virtual bool onMouseLeftDown(); - virtual bool onMouseLeftUp(); - virtual bool onMouseLeftDblClick(); - virtual bool onMouseRightDown(); - virtual bool onMouseRightUp(); - - virtual bool displayDebugInfo(); - - bool addSpeechDir(const char *dir); - bool removeSpeechDir(const char *dir); - char *findSpeechFile(char *StringID); - - bool deleteItem(AdItem *Item); - char *_itemsFile; - bool _tempDisableSaveState; - virtual bool resetContent(); - bool addItem(AdItem *item); - AdItem *getItemByName(const char *name); - - AdObject *_inventoryOwner; - bool isItemTaken(char *itemName); - bool registerInventory(AdInventory *inv); - bool unregisterInventory(AdInventory *inv); - virtual bool displayContent(bool update = true, bool displayAll = false); - - bool gameResponseUsed(int ID); - bool addGameResponse(int ID); - bool resetResponse(int ID); - - bool branchResponseUsed(int ID); - bool addBranchResponse(int ID); - bool clearBranchResponses(char *name); - bool startDlgBranch(const char *branchName, const char *scriptName, const char *eventName); - bool endDlgBranch(const char *branchName, const char *scriptName, const char *eventName); - virtual bool windowLoadHook(UIWindow *win, char **buf, char **params); - virtual bool windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *stack, const char *name); - - AdSceneState *getSceneState(const char *filename, bool saving); - BaseViewport *_sceneViewport; - - int _texItemLifeTime; - int _texWalkLifeTime; - int _texStandLifeTime; - int _texTalkLifeTime; - - TTalkSkipButton _talkSkipButton; - - virtual bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor); - bool scheduleChangeScene(const char *filename, bool fadeIn); - void setPrevSceneName(const char *name); - void setPrevSceneFilename(const char *name); - - AdItem *_selectedItem; - bool cleanup(); - DECLARE_PERSISTENT(AdGame, BaseGame) - - void finishSentences(); - bool showCursor(); - - TGameStateEx _stateEx; - - bool displaySentences(bool frozen); - void addSentence(AdSentence *sentence); - bool changeScene(const char *filename, bool fadeIn); - bool removeObject(AdObject *object); - bool addObject(AdObject *object); - AdScene *_scene; - bool initLoop(); - AdGame(const Common::String &gameId); - virtual ~AdGame(); - - BaseArray _objects; - - virtual bool loadFile(const char *filename); - virtual bool loadBuffer(byte *buffer, bool complete = true); - - bool loadItemsFile(const char *filename, bool merge = false); - bool loadItemsBuffer(byte *buffer, bool merge = false); - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - bool validMouse(); -private: - virtual bool externalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name); - - AdObject *_invObject; - BaseArray _inventories; - char *_scheduledScene; - bool _scheduledFadeIn; - char *_prevSceneName; - char *_prevSceneFilename; - char *_debugStartupScene; - char *_startupScene; - bool _initialScene; - bool _smartItemCursor; - BaseArray _speechDirs; - BaseArray _items; - - BaseArray _sentences; - - BaseArray _sceneStates; - BaseArray _dlgPendingBranches; - - BaseArray _responsesBranch; - BaseArray _responsesGame; - - AdResponseBox *_responseBox; - AdInventoryBox *_inventoryBox; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ +#ifndef WINTERMUTE_ADGAME_H +#define WINTERMUTE_ADGAME_H + +#include "engines/wintermute/ad/ad_types.h" +#include "engines/wintermute/base/base_game.h" + +namespace Wintermute { +class AdItem; +class AdInventory; +class AdSceneState; +class AdScene; +class AdItem; +class AdObject; +class AdSentence; +class AdInventoryBox; +class AdResponseContext; +class AdResponseBox; +class AdGame : public BaseGame { +public: + virtual bool onScriptShutdown(ScScript *script); + + virtual bool onMouseLeftDown(); + virtual bool onMouseLeftUp(); + virtual bool onMouseLeftDblClick(); + virtual bool onMouseRightDown(); + virtual bool onMouseRightUp(); + + virtual bool displayDebugInfo(); + + bool addSpeechDir(const char *dir); + bool removeSpeechDir(const char *dir); + char *findSpeechFile(char *StringID); + + bool deleteItem(AdItem *Item); + char *_itemsFile; + bool _tempDisableSaveState; + virtual bool resetContent(); + bool addItem(AdItem *item); + AdItem *getItemByName(const char *name); + + AdObject *_inventoryOwner; + bool isItemTaken(char *itemName); + bool registerInventory(AdInventory *inv); + bool unregisterInventory(AdInventory *inv); + virtual bool displayContent(bool update = true, bool displayAll = false); + + bool gameResponseUsed(int ID); + bool addGameResponse(int ID); + bool resetResponse(int ID); + + bool branchResponseUsed(int ID); + bool addBranchResponse(int ID); + bool clearBranchResponses(char *name); + bool startDlgBranch(const char *branchName, const char *scriptName, const char *eventName); + bool endDlgBranch(const char *branchName, const char *scriptName, const char *eventName); + virtual bool windowLoadHook(UIWindow *win, char **buf, char **params); + virtual bool windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *stack, const char *name); + + AdSceneState *getSceneState(const char *filename, bool saving); + BaseViewport *_sceneViewport; + + int _texItemLifeTime; + int _texWalkLifeTime; + int _texStandLifeTime; + int _texTalkLifeTime; + + TTalkSkipButton _talkSkipButton; + + virtual bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor); + bool scheduleChangeScene(const char *filename, bool fadeIn); + void setPrevSceneName(const char *name); + void setPrevSceneFilename(const char *name); + + AdItem *_selectedItem; + bool cleanup(); + DECLARE_PERSISTENT(AdGame, BaseGame) + + void finishSentences(); + bool showCursor(); + + TGameStateEx _stateEx; + + bool displaySentences(bool frozen); + void addSentence(AdSentence *sentence); + bool changeScene(const char *filename, bool fadeIn); + bool removeObject(AdObject *object); + bool addObject(AdObject *object); + AdScene *_scene; + bool initLoop(); + AdGame(const Common::String &gameId); + virtual ~AdGame(); + + BaseArray _objects; + + virtual bool loadFile(const char *filename); + virtual bool loadBuffer(byte *buffer, bool complete = true); + + bool loadItemsFile(const char *filename, bool merge = false); + bool loadItemsBuffer(byte *buffer, bool merge = false); + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + bool validMouse(); +private: + virtual bool externalCall(ScScript *script, ScStack *stack, ScStack *thisStack, char *name); + + AdObject *_invObject; + BaseArray _inventories; + char *_scheduledScene; + bool _scheduledFadeIn; + char *_prevSceneName; + char *_prevSceneFilename; + char *_debugStartupScene; + char *_startupScene; + bool _initialScene; + bool _smartItemCursor; + BaseArray _speechDirs; + BaseArray _items; + + BaseArray _sentences; + + BaseArray _sceneStates; + BaseArray _dlgPendingBranches; + + BaseArray _responsesBranch; + BaseArray _responsesGame; + + AdResponseBox *_responseBox; + AdInventoryBox *_inventoryBox; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index 44b2dc0508..72f8fa0fb4 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -1,136 +1,136 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_inventory.h" -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_item.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdInventory, false) - -////////////////////////////////////////////////////////////////////////// -AdInventory::AdInventory(BaseGame *inGame) : BaseObject(inGame) { - _scrollOffset = 0; -} - - -////////////////////////////////////////////////////////////////////////// -AdInventory::~AdInventory() { - _takenItems.clear(); // ref only -} - - -////////////////////////////////////////////////////////////////////////// -bool AdInventory::insertItem(const char *name, const char *insertAfter) { - if (name == NULL) { - return STATUS_FAILED; - } - - AdItem *item = ((AdGame *)_gameRef)->getItemByName(name); - if (item == NULL) { - return STATUS_FAILED; - } - - int insertIndex = -1; - for (uint32 i = 0; i < _takenItems.size(); i++) { - if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { - _takenItems.remove_at(i); - i--; - continue; - } - if (insertAfter && scumm_stricmp(_takenItems[i]->getName(), insertAfter) == 0) { - insertIndex = i + 1; - } - } - - - if (insertIndex == -1) { - _takenItems.add(item); - } else { - _takenItems.insert_at(insertIndex, item); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdInventory::removeItem(const char *name) { - if (name == NULL) { - return STATUS_FAILED; - } - - for (uint32 i = 0; i < _takenItems.size(); i++) { - if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { - if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { - ((AdGame *)_gameRef)->_selectedItem = NULL; - } - _takenItems.remove_at(i); - return STATUS_OK; - } - } - - return STATUS_FAILED; -} - - - -////////////////////////////////////////////////////////////////////////// -bool AdInventory::removeItem(AdItem *item) { - if (item == NULL) { - return STATUS_FAILED; - } - - for (uint32 i = 0; i < _takenItems.size(); i++) { - if (_takenItems[i] == item) { - if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { - ((AdGame *)_gameRef)->_selectedItem = NULL; - } - _takenItems.remove_at(i); - return STATUS_OK; - } - } - - return STATUS_FAILED; -} - -////////////////////////////////////////////////////////////////////////// -bool AdInventory::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - _takenItems.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scrollOffset)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_inventory.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdInventory, false) + +////////////////////////////////////////////////////////////////////////// +AdInventory::AdInventory(BaseGame *inGame) : BaseObject(inGame) { + _scrollOffset = 0; +} + + +////////////////////////////////////////////////////////////////////////// +AdInventory::~AdInventory() { + _takenItems.clear(); // ref only +} + + +////////////////////////////////////////////////////////////////////////// +bool AdInventory::insertItem(const char *name, const char *insertAfter) { + if (name == NULL) { + return STATUS_FAILED; + } + + AdItem *item = ((AdGame *)_gameRef)->getItemByName(name); + if (item == NULL) { + return STATUS_FAILED; + } + + int insertIndex = -1; + for (uint32 i = 0; i < _takenItems.size(); i++) { + if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { + _takenItems.remove_at(i); + i--; + continue; + } + if (insertAfter && scumm_stricmp(_takenItems[i]->getName(), insertAfter) == 0) { + insertIndex = i + 1; + } + } + + + if (insertIndex == -1) { + _takenItems.add(item); + } else { + _takenItems.insert_at(insertIndex, item); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdInventory::removeItem(const char *name) { + if (name == NULL) { + return STATUS_FAILED; + } + + for (uint32 i = 0; i < _takenItems.size(); i++) { + if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { + if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { + ((AdGame *)_gameRef)->_selectedItem = NULL; + } + _takenItems.remove_at(i); + return STATUS_OK; + } + } + + return STATUS_FAILED; +} + + + +////////////////////////////////////////////////////////////////////////// +bool AdInventory::removeItem(AdItem *item) { + if (item == NULL) { + return STATUS_FAILED; + } + + for (uint32 i = 0; i < _takenItems.size(); i++) { + if (_takenItems[i] == item) { + if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { + ((AdGame *)_gameRef)->_selectedItem = NULL; + } + _takenItems.remove_at(i); + return STATUS_OK; + } + } + + return STATUS_FAILED; +} + +////////////////////////////////////////////////////////////////////////// +bool AdInventory::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + _takenItems.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollOffset)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_inventory.h b/engines/wintermute/ad/ad_inventory.h index 9a12eb1abe..4017d914bc 100644 --- a/engines/wintermute/ad/ad_inventory.h +++ b/engines/wintermute/ad/ad_inventory.h @@ -1,52 +1,52 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADINVENTORY_H -#define WINTERMUTE_ADINVENTORY_H - -#include "engines/wintermute/base/base_object.h" - -namespace Wintermute { - -class AdItem; - -class AdInventory : public BaseObject { -public: - DECLARE_PERSISTENT(AdInventory, BaseObject) - bool removeItem(const char *name); - bool removeItem(AdItem *Item); - bool insertItem(const char *name, const char *insertAfter = NULL); - AdInventory(BaseGame *inGame); - virtual ~AdInventory(); - BaseArray _takenItems; - int _scrollOffset; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADINVENTORY_H +#define WINTERMUTE_ADINVENTORY_H + +#include "engines/wintermute/base/base_object.h" + +namespace Wintermute { + +class AdItem; + +class AdInventory : public BaseObject { +public: + DECLARE_PERSISTENT(AdInventory, BaseObject) + bool removeItem(const char *name); + bool removeItem(AdItem *Item); + bool insertItem(const char *name, const char *insertAfter = NULL); + AdInventory(BaseGame *inGame); + virtual ~AdInventory(); + BaseArray _takenItems; + int _scrollOffset; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index ad679007df..16b8e01ff3 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -1,388 +1,388 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_inventory_box.h" -#include "engines/wintermute/ad/ad_inventory.h" -#include "engines/wintermute/ad/ad_item.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/base/base_viewport.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/ui/ui_button.h" -#include "engines/wintermute/ui/ui_window.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" -#include "common/rect.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdInventoryBox, false) - -////////////////////////////////////////////////////////////////////////// -AdInventoryBox::AdInventoryBox(BaseGame *inGame) : BaseObject(inGame) { - _itemsArea.setEmpty(); - _scrollOffset = 0; - _spacing = 0; - _itemWidth = _itemHeight = 50; - _scrollBy = 1; - - _window = NULL; - _closeButton = NULL; - - _hideSelected = false; - - _visible = false; - _exclusive = false; -} - - -////////////////////////////////////////////////////////////////////////// -AdInventoryBox::~AdInventoryBox() { - _gameRef->unregisterObject(_window); - _window = NULL; - - delete _closeButton; - _closeButton = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdInventoryBox::listen(BaseScriptHolder *param1, uint32 param2) { - UIObject *obj = (UIObject *)param1; - - switch (obj->_type) { - case UI_BUTTON: - if (scumm_stricmp(obj->getName(), "close") == 0) { - _visible = false; - } else if (scumm_stricmp(obj->getName(), "prev") == 0) { - _scrollOffset -= _scrollBy; - _scrollOffset = MAX(_scrollOffset, 0); - } else if (scumm_stricmp(obj->getName(), "next") == 0) { - _scrollOffset += _scrollBy; - } else { - return BaseObject::listen(param1, param2); - } - break; - default: - error("AdInventoryBox::Listen - Unhandled enum"); - break; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdInventoryBox::display() { - AdGame *adGame = (AdGame *)_gameRef; - - if (!_visible) { - return STATUS_OK; - } - - int itemsX, itemsY; - itemsX = (int)floor((float)((_itemsArea.right - _itemsArea.left + _spacing) / (_itemWidth + _spacing))); - itemsY = (int)floor((float)((_itemsArea.bottom - _itemsArea.top + _spacing) / (_itemHeight + _spacing))); - - if (_window) { - _window->enableWidget("prev", _scrollOffset > 0); - _window->enableWidget("next", _scrollOffset + itemsX * itemsY < (int32)adGame->_inventoryOwner->getInventory()->_takenItems.size()); - } - - - if (_closeButton) { - _closeButton->_posX = _closeButton->_posY = 0; - _closeButton->_width = _gameRef->_renderer->_width; - _closeButton->_height = _gameRef->_renderer->_height; - - _closeButton->display(); - } - - - // display window - Rect32 rect = _itemsArea; - if (_window) { - rect.offsetRect(_window->_posX, _window->_posY); - _window->display(); - } - - // display items - if (_window && _window->_alphaColor != 0) { - _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; - } - int yyy = rect.top; - for (int j = 0; j < itemsY; j++) { - int xxx = rect.left; - for (int i = 0; i < itemsX; i++) { - int itemIndex = _scrollOffset + j * itemsX + i; - if (itemIndex >= 0 && itemIndex < (int32)adGame->_inventoryOwner->getInventory()->_takenItems.size()) { - AdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex]; - if (item != ((AdGame *)_gameRef)->_selectedItem || !_hideSelected) { - item->update(); - item->display(xxx, yyy); - } - } - - xxx += (_itemWidth + _spacing); - } - yyy += (_itemHeight + _spacing); - } - if (_window && _window->_alphaColor != 0) { - _gameRef->_renderer->_forceAlphaColor = 0; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdInventoryBox::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdInventoryBox::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(INVENTORY_BOX) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(WINDOW) -TOKEN_DEF(EXCLUSIVE) -TOKEN_DEF(ALWAYS_VISIBLE) -TOKEN_DEF(AREA) -TOKEN_DEF(SPACING) -TOKEN_DEF(ITEM_WIDTH) -TOKEN_DEF(ITEM_HEIGHT) -TOKEN_DEF(SCROLL_BY) -TOKEN_DEF(NAME) -TOKEN_DEF(CAPTION) -TOKEN_DEF(HIDE_SELECTED) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(INVENTORY_BOX) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(WINDOW) - TOKEN_TABLE(EXCLUSIVE) - TOKEN_TABLE(ALWAYS_VISIBLE) - TOKEN_TABLE(AREA) - TOKEN_TABLE(SPACING) - TOKEN_TABLE(ITEM_WIDTH) - TOKEN_TABLE(ITEM_HEIGHT) - TOKEN_TABLE(SCROLL_BY) - TOKEN_TABLE(NAME) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(HIDE_SELECTED) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd = 2; - BaseParser parser; - bool alwaysVisible = false; - - _exclusive = false; - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_INVENTORY_BOX) { - _gameRef->LOG(0, "'INVENTORY_BOX' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_WINDOW: - delete _window; - _window = new UIWindow(_gameRef); - if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { - delete _window; - _window = NULL; - cmd = PARSERR_GENERIC; - } else { - _gameRef->registerObject(_window); - } - break; - - case TOKEN_AREA: - parser.scanStr((char *)params, "%d,%d,%d,%d", &_itemsArea.left, &_itemsArea.top, &_itemsArea.right, &_itemsArea.bottom); - break; - - case TOKEN_EXCLUSIVE: - parser.scanStr((char *)params, "%b", &_exclusive); - break; - - case TOKEN_HIDE_SELECTED: - parser.scanStr((char *)params, "%b", &_hideSelected); - break; - - case TOKEN_ALWAYS_VISIBLE: - parser.scanStr((char *)params, "%b", &alwaysVisible); - break; - - case TOKEN_SPACING: - parser.scanStr((char *)params, "%d", &_spacing); - break; - - case TOKEN_ITEM_WIDTH: - parser.scanStr((char *)params, "%d", &_itemWidth); - break; - - case TOKEN_ITEM_HEIGHT: - parser.scanStr((char *)params, "%d", &_itemHeight); - break; - - case TOKEN_SCROLL_BY: - parser.scanStr((char *)params, "%d", &_scrollBy); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in INVENTORY_BOX definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading INVENTORY_BOX definition"); - return STATUS_FAILED; - } - - if (_exclusive) { - delete _closeButton; - _closeButton = new UIButton(_gameRef); - if (_closeButton) { - _closeButton->setName("close"); - _closeButton->setListener(this, _closeButton, 0); - _closeButton->_parent = _window; - } - } - - _visible = alwaysVisible; - - if (_window) { - for (uint32 i = 0; i < _window->_widgets.size(); i++) { - if (!_window->_widgets[i]->_listenerObject) { - _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); - } - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdInventoryBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "INVENTORY_BOX\n"); - buffer->putTextIndent(indent, "{\n"); - - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - - buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _itemsArea.left, _itemsArea.top, _itemsArea.right, _itemsArea.bottom); - - buffer->putTextIndent(indent + 2, "EXCLUSIVE=%s\n", _exclusive ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "HIDE_SELECTED=%s\n", _hideSelected ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "ALWAYS_VISIBLE=%s\n", _visible ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); - buffer->putTextIndent(indent + 2, "ITEM_WIDTH=%d\n", _itemWidth); - buffer->putTextIndent(indent + 2, "ITEM_HEIGHT=%d\n", _itemHeight); - buffer->putTextIndent(indent + 2, "SCROLL_BY=%d\n", _scrollBy); - - buffer->putTextIndent(indent + 2, "\n"); - - // window - if (_window) { - _window->saveAsText(buffer, indent + 2); - } - - buffer->putTextIndent(indent + 2, "\n"); - - // editor properties - BaseClass::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdInventoryBox::persist(BasePersistenceManager *persistMgr) { - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_closeButton)); - persistMgr->transfer(TMEMBER(_hideSelected)); - persistMgr->transfer(TMEMBER(_itemHeight)); - persistMgr->transfer(TMEMBER(_itemsArea)); - persistMgr->transfer(TMEMBER(_itemWidth)); - persistMgr->transfer(TMEMBER(_scrollBy)); - persistMgr->transfer(TMEMBER(_scrollOffset)); - persistMgr->transfer(TMEMBER(_spacing)); - persistMgr->transfer(TMEMBER(_visible)); - persistMgr->transfer(TMEMBER(_window)); - persistMgr->transfer(TMEMBER(_exclusive)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_inventory_box.h" +#include "engines/wintermute/ad/ad_inventory.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_viewport.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/ui/ui_button.h" +#include "engines/wintermute/ui/ui_window.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" +#include "common/rect.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdInventoryBox, false) + +////////////////////////////////////////////////////////////////////////// +AdInventoryBox::AdInventoryBox(BaseGame *inGame) : BaseObject(inGame) { + _itemsArea.setEmpty(); + _scrollOffset = 0; + _spacing = 0; + _itemWidth = _itemHeight = 50; + _scrollBy = 1; + + _window = NULL; + _closeButton = NULL; + + _hideSelected = false; + + _visible = false; + _exclusive = false; +} + + +////////////////////////////////////////////////////////////////////////// +AdInventoryBox::~AdInventoryBox() { + _gameRef->unregisterObject(_window); + _window = NULL; + + delete _closeButton; + _closeButton = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdInventoryBox::listen(BaseScriptHolder *param1, uint32 param2) { + UIObject *obj = (UIObject *)param1; + + switch (obj->_type) { + case UI_BUTTON: + if (scumm_stricmp(obj->getName(), "close") == 0) { + _visible = false; + } else if (scumm_stricmp(obj->getName(), "prev") == 0) { + _scrollOffset -= _scrollBy; + _scrollOffset = MAX(_scrollOffset, 0); + } else if (scumm_stricmp(obj->getName(), "next") == 0) { + _scrollOffset += _scrollBy; + } else { + return BaseObject::listen(param1, param2); + } + break; + default: + error("AdInventoryBox::Listen - Unhandled enum"); + break; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdInventoryBox::display() { + AdGame *adGame = (AdGame *)_gameRef; + + if (!_visible) { + return STATUS_OK; + } + + int itemsX, itemsY; + itemsX = (int)floor((float)((_itemsArea.right - _itemsArea.left + _spacing) / (_itemWidth + _spacing))); + itemsY = (int)floor((float)((_itemsArea.bottom - _itemsArea.top + _spacing) / (_itemHeight + _spacing))); + + if (_window) { + _window->enableWidget("prev", _scrollOffset > 0); + _window->enableWidget("next", _scrollOffset + itemsX * itemsY < (int32)adGame->_inventoryOwner->getInventory()->_takenItems.size()); + } + + + if (_closeButton) { + _closeButton->_posX = _closeButton->_posY = 0; + _closeButton->_width = _gameRef->_renderer->_width; + _closeButton->_height = _gameRef->_renderer->_height; + + _closeButton->display(); + } + + + // display window + Rect32 rect = _itemsArea; + if (_window) { + rect.offsetRect(_window->_posX, _window->_posY); + _window->display(); + } + + // display items + if (_window && _window->_alphaColor != 0) { + _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; + } + int yyy = rect.top; + for (int j = 0; j < itemsY; j++) { + int xxx = rect.left; + for (int i = 0; i < itemsX; i++) { + int itemIndex = _scrollOffset + j * itemsX + i; + if (itemIndex >= 0 && itemIndex < (int32)adGame->_inventoryOwner->getInventory()->_takenItems.size()) { + AdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex]; + if (item != ((AdGame *)_gameRef)->_selectedItem || !_hideSelected) { + item->update(); + item->display(xxx, yyy); + } + } + + xxx += (_itemWidth + _spacing); + } + yyy += (_itemHeight + _spacing); + } + if (_window && _window->_alphaColor != 0) { + _gameRef->_renderer->_forceAlphaColor = 0; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdInventoryBox::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdInventoryBox::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(INVENTORY_BOX) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(WINDOW) +TOKEN_DEF(EXCLUSIVE) +TOKEN_DEF(ALWAYS_VISIBLE) +TOKEN_DEF(AREA) +TOKEN_DEF(SPACING) +TOKEN_DEF(ITEM_WIDTH) +TOKEN_DEF(ITEM_HEIGHT) +TOKEN_DEF(SCROLL_BY) +TOKEN_DEF(NAME) +TOKEN_DEF(CAPTION) +TOKEN_DEF(HIDE_SELECTED) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(INVENTORY_BOX) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(WINDOW) + TOKEN_TABLE(EXCLUSIVE) + TOKEN_TABLE(ALWAYS_VISIBLE) + TOKEN_TABLE(AREA) + TOKEN_TABLE(SPACING) + TOKEN_TABLE(ITEM_WIDTH) + TOKEN_TABLE(ITEM_HEIGHT) + TOKEN_TABLE(SCROLL_BY) + TOKEN_TABLE(NAME) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(HIDE_SELECTED) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd = 2; + BaseParser parser; + bool alwaysVisible = false; + + _exclusive = false; + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_INVENTORY_BOX) { + _gameRef->LOG(0, "'INVENTORY_BOX' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_WINDOW: + delete _window; + _window = new UIWindow(_gameRef); + if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { + delete _window; + _window = NULL; + cmd = PARSERR_GENERIC; + } else { + _gameRef->registerObject(_window); + } + break; + + case TOKEN_AREA: + parser.scanStr((char *)params, "%d,%d,%d,%d", &_itemsArea.left, &_itemsArea.top, &_itemsArea.right, &_itemsArea.bottom); + break; + + case TOKEN_EXCLUSIVE: + parser.scanStr((char *)params, "%b", &_exclusive); + break; + + case TOKEN_HIDE_SELECTED: + parser.scanStr((char *)params, "%b", &_hideSelected); + break; + + case TOKEN_ALWAYS_VISIBLE: + parser.scanStr((char *)params, "%b", &alwaysVisible); + break; + + case TOKEN_SPACING: + parser.scanStr((char *)params, "%d", &_spacing); + break; + + case TOKEN_ITEM_WIDTH: + parser.scanStr((char *)params, "%d", &_itemWidth); + break; + + case TOKEN_ITEM_HEIGHT: + parser.scanStr((char *)params, "%d", &_itemHeight); + break; + + case TOKEN_SCROLL_BY: + parser.scanStr((char *)params, "%d", &_scrollBy); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in INVENTORY_BOX definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading INVENTORY_BOX definition"); + return STATUS_FAILED; + } + + if (_exclusive) { + delete _closeButton; + _closeButton = new UIButton(_gameRef); + if (_closeButton) { + _closeButton->setName("close"); + _closeButton->setListener(this, _closeButton, 0); + _closeButton->_parent = _window; + } + } + + _visible = alwaysVisible; + + if (_window) { + for (uint32 i = 0; i < _window->_widgets.size(); i++) { + if (!_window->_widgets[i]->_listenerObject) { + _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdInventoryBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "INVENTORY_BOX\n"); + buffer->putTextIndent(indent, "{\n"); + + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + + buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _itemsArea.left, _itemsArea.top, _itemsArea.right, _itemsArea.bottom); + + buffer->putTextIndent(indent + 2, "EXCLUSIVE=%s\n", _exclusive ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "HIDE_SELECTED=%s\n", _hideSelected ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "ALWAYS_VISIBLE=%s\n", _visible ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); + buffer->putTextIndent(indent + 2, "ITEM_WIDTH=%d\n", _itemWidth); + buffer->putTextIndent(indent + 2, "ITEM_HEIGHT=%d\n", _itemHeight); + buffer->putTextIndent(indent + 2, "SCROLL_BY=%d\n", _scrollBy); + + buffer->putTextIndent(indent + 2, "\n"); + + // window + if (_window) { + _window->saveAsText(buffer, indent + 2); + } + + buffer->putTextIndent(indent + 2, "\n"); + + // editor properties + BaseClass::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdInventoryBox::persist(BasePersistenceManager *persistMgr) { + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_closeButton)); + persistMgr->transfer(TMEMBER(_hideSelected)); + persistMgr->transfer(TMEMBER(_itemHeight)); + persistMgr->transfer(TMEMBER(_itemsArea)); + persistMgr->transfer(TMEMBER(_itemWidth)); + persistMgr->transfer(TMEMBER(_scrollBy)); + persistMgr->transfer(TMEMBER(_scrollOffset)); + persistMgr->transfer(TMEMBER(_spacing)); + persistMgr->transfer(TMEMBER(_visible)); + persistMgr->transfer(TMEMBER(_window)); + persistMgr->transfer(TMEMBER(_exclusive)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_inventory_box.h b/engines/wintermute/ad/ad_inventory_box.h index 451ebf9635..cb6d084562 100644 --- a/engines/wintermute/ad/ad_inventory_box.h +++ b/engines/wintermute/ad/ad_inventory_box.h @@ -1,65 +1,65 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADINVENTORYBOX_H -#define WINTERMUTE_ADINVENTORYBOX_H - -#include "engines/wintermute/base/base_object.h" -#include "common/rect.h" - -namespace Wintermute { -class UIButton; -class UIWindow; - -class AdInventoryBox : public BaseObject { -public: - bool _hideSelected; - DECLARE_PERSISTENT(AdInventoryBox, BaseObject) - bool _visible; - virtual bool display(); - UIButton *_closeButton; - int _spacing; - int _scrollOffset; - Rect32 _itemsArea; - bool listen(BaseScriptHolder *param1, uint32 param2); - UIWindow *_window; - AdInventoryBox(BaseGame *inGame); - virtual ~AdInventoryBox(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); -private: - bool _exclusive; - int _scrollBy; - int _itemHeight; - int _itemWidth; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADINVENTORYBOX_H +#define WINTERMUTE_ADINVENTORYBOX_H + +#include "engines/wintermute/base/base_object.h" +#include "common/rect.h" + +namespace Wintermute { +class UIButton; +class UIWindow; + +class AdInventoryBox : public BaseObject { +public: + bool _hideSelected; + DECLARE_PERSISTENT(AdInventoryBox, BaseObject) + bool _visible; + virtual bool display(); + UIButton *_closeButton; + int _spacing; + int _scrollOffset; + Rect32 _itemsArea; + bool listen(BaseScriptHolder *param1, uint32 param2); + UIWindow *_window; + AdInventoryBox(BaseGame *inGame); + virtual ~AdInventoryBox(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); +private: + bool _exclusive; + int _scrollBy; + int _itemHeight; + int _itemWidth; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index f5c8b16308..afd813933b 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -1,813 +1,813 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_item.h" -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_sentence.h" -#include "engines/wintermute/base/font/base_font_storage.h" -#include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/sound/base_sound.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdItem, false) - -////////////////////////////////////////////////////////////////////////// -AdItem::AdItem(BaseGame *inGame) : AdTalkHolder(inGame) { - _spriteHover = NULL; - _cursorNormal = _cursorHover = NULL; - - _cursorCombined = true; - _inInventory = false; - - _displayAmount = false; - _amount = 0; - _amountOffsetX = 0; - _amountOffsetY = 0; - _amountAlign = TAL_RIGHT; - _amountString = NULL; - - _state = STATE_READY; - - _movable = false; -} - - -////////////////////////////////////////////////////////////////////////// -AdItem::~AdItem() { - delete _spriteHover; - delete _cursorNormal; - delete _cursorHover; - _spriteHover = NULL; - _cursorNormal = NULL; - _cursorHover = NULL; - - delete[] _amountString; - _amountString = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdItem::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdItem::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(ITEM) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(CURSOR_HOVER) -TOKEN_DEF(CURSOR_COMBINED) -TOKEN_DEF(CURSOR) -TOKEN_DEF(NAME) -TOKEN_DEF(IMAGE_HOVER) -TOKEN_DEF(IMAGE) -TOKEN_DEF(EVENTS) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF(FONT) -TOKEN_DEF(ALPHA_COLOR) -TOKEN_DEF(ALPHA) -TOKEN_DEF(TALK_SPECIAL) -TOKEN_DEF(TALK) -TOKEN_DEF(SPRITE_HOVER) -TOKEN_DEF(SPRITE) -TOKEN_DEF(DISPLAY_AMOUNT) -TOKEN_DEF(AMOUNT_OFFSET_X) -TOKEN_DEF(AMOUNT_OFFSET_Y) -TOKEN_DEF(AMOUNT_ALIGN) -TOKEN_DEF(AMOUNT_STRING) -TOKEN_DEF(AMOUNT) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdItem::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ITEM) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(CURSOR_HOVER) - TOKEN_TABLE(CURSOR_COMBINED) - TOKEN_TABLE(CURSOR) - TOKEN_TABLE(NAME) - TOKEN_TABLE(IMAGE_HOVER) - TOKEN_TABLE(IMAGE) - TOKEN_TABLE(EVENTS) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE(FONT) - TOKEN_TABLE(ALPHA_COLOR) - TOKEN_TABLE(ALPHA) - TOKEN_TABLE(TALK_SPECIAL) - TOKEN_TABLE(TALK) - TOKEN_TABLE(SPRITE_HOVER) - TOKEN_TABLE(SPRITE) - TOKEN_TABLE(DISPLAY_AMOUNT) - TOKEN_TABLE(AMOUNT_OFFSET_X) - TOKEN_TABLE(AMOUNT_OFFSET_Y) - TOKEN_TABLE(AMOUNT_ALIGN) - TOKEN_TABLE(AMOUNT_STRING) - TOKEN_TABLE(AMOUNT) - TOKEN_TABLE_END - - byte *params; - int cmd = 2; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ITEM) { - _gameRef->LOG(0, "'ITEM' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - int ar = 0, ag = 0, ab = 0, alpha = 255; - while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_FONT: - setFont((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_IMAGE: - case TOKEN_SPRITE: - delete _sprite; - _sprite = new BaseSprite(_gameRef, this); - if (!_sprite || DID_FAIL(_sprite->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { - delete _sprite; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_IMAGE_HOVER: - case TOKEN_SPRITE_HOVER: - delete _spriteHover; - _spriteHover = new BaseSprite(_gameRef, this); - if (!_spriteHover || DID_FAIL(_spriteHover->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { - delete _spriteHover; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_AMOUNT: - parser.scanStr((char *)params, "%d", &_amount); - break; - - case TOKEN_DISPLAY_AMOUNT: - parser.scanStr((char *)params, "%b", &_displayAmount); - break; - - case TOKEN_AMOUNT_OFFSET_X: - parser.scanStr((char *)params, "%d", &_amountOffsetX); - break; - - case TOKEN_AMOUNT_OFFSET_Y: - parser.scanStr((char *)params, "%d", &_amountOffsetY); - break; - - case TOKEN_AMOUNT_ALIGN: - if (scumm_stricmp((char *)params, "left") == 0) { - _amountAlign = TAL_LEFT; - } else if (scumm_stricmp((char *)params, "right") == 0) { - _amountAlign = TAL_RIGHT; - } else { - _amountAlign = TAL_CENTER; - } - break; - - case TOKEN_AMOUNT_STRING: - BaseUtils::setString(&_amountString, (char *)params); - break; - - case TOKEN_TALK: { - BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) { - cmd = PARSERR_GENERIC; - } else { - _talkSprites.add(spr); - } - } - break; - - case TOKEN_TALK_SPECIAL: { - BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) { - cmd = PARSERR_GENERIC; - } else { - _talkSpritesEx.add(spr); - } - } - break; - - case TOKEN_CURSOR: - delete _cursorNormal; - _cursorNormal = new BaseSprite(_gameRef); - if (!_cursorNormal || DID_FAIL(_cursorNormal->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { - delete _cursorNormal; - _cursorNormal = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_CURSOR_HOVER: - delete _cursorHover; - _cursorHover = new BaseSprite(_gameRef); - if (!_cursorHover || DID_FAIL(_cursorHover->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { - delete _cursorHover; - _cursorHover = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_CURSOR_COMBINED: - parser.scanStr((char *)params, "%b", &_cursorCombined); - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - 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; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ITEM definition"); - return STATUS_FAILED; - } - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading ITEM definition"); - return STATUS_FAILED; - } - - if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { - ar = ag = ab = 255; - } - _alphaColor = BYTETORGBA(ar, ag, ab, alpha); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdItem::update() { - _currentSprite = NULL; - - if (_state == STATE_READY && _animSprite) { - delete _animSprite; - _animSprite = NULL; - } - - // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { - _state = STATE_READY; - _currentSprite = _animSprite; - } - - if (_sentence && _state != STATE_TALKING) { - _sentence->finish(); - } - - // default: stand animation - if (!_currentSprite) { - _currentSprite = _sprite; - } - - switch (_state) { - ////////////////////////////////////////////////////////////////////////// - case STATE_PLAYING_ANIM: - _currentSprite = _animSprite; - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_READY: - if (!_animSprite) { - if (_gameRef->_activeObject == this && _spriteHover) { - _currentSprite = _spriteHover; - } else { - _currentSprite = _sprite; - } - } - break; - - ////////////////////////////////////////////////////////////////////////// - case STATE_TALKING: { - _sentence->update(); - if (_sentence->_currentSprite) { - _tempSprite2 = _sentence->_currentSprite; - } - - bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { - if (timeIsUp) { - _sentence->finish(); - _tempSprite2 = NULL; - _state = STATE_READY; - } else { - _tempSprite2 = getTalkStance(_sentence->getNextStance()); - if (_tempSprite2) { - _tempSprite2->reset(); - _currentSprite = _tempSprite2; - } - ((AdGame *)_gameRef)->addSentence(_sentence); - } - } else { - _currentSprite = _tempSprite2; - ((AdGame *)_gameRef)->addSentence(_sentence); - } - } - default: - break; - } - _ready = (_state == STATE_READY); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdItem::display(int x, int y) { - int width = 0; - if (_currentSprite) { - Rect32 rc; - _currentSprite->getBoundingRect(&rc, 0, 0); - width = rc.width(); - } - - _posX = x + width / 2; - _posY = y; - - bool ret; - if (_currentSprite) { - ret = _currentSprite->draw(x, y, this, 100, 100, _alphaColor); - } else { - ret = STATUS_OK; - } - - if (_displayAmount) { - int amountX = x; - int amountY = y + _amountOffsetY; - - if (_amountAlign == TAL_RIGHT) { - width -= _amountOffsetX; - amountX -= _amountOffsetX; - } - amountX += _amountOffsetX; - - BaseFont *font = _font ? _font : _gameRef->_systemFont; - if (font) { - if (_amountString) { - font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); - } else { - char str[256]; - sprintf(str, "%d", _amount); - font->drawText((byte *)str, amountX, amountY, width, _amountAlign); - } - } - } - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // SetHoverSprite - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SetHoverSprite") == 0) { - stack->correctParams(1); - - bool setCurrent = false; - if (_currentSprite && _currentSprite == _spriteHover) { - setCurrent = true; - } - - const char *filename = stack->pop()->getString(); - - delete _spriteHover; - _spriteHover = NULL; - BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("Item.SetHoverSprite failed for file '%s'", filename); - } else { - _spriteHover = spr; - if (setCurrent) { - _currentSprite = _spriteHover; - } - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetHoverSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetHoverSprite") == 0) { - stack->correctParams(0); - - if (!_spriteHover || !_spriteHover->getFilename()) { - stack->pushNULL(); - } else { - stack->pushString(_spriteHover->getFilename()); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetHoverSpriteObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetHoverSpriteObject") == 0) { - stack->correctParams(0); - if (!_spriteHover) { - stack->pushNULL(); - } else { - stack->pushNative(_spriteHover, true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetNormalCursor - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SetNormalCursor") == 0) { - stack->correctParams(1); - - const char *filename = stack->pop()->getString(); - - delete _cursorNormal; - _cursorNormal = NULL; - BaseSprite *spr = new BaseSprite(_gameRef); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("Item.SetNormalCursor failed for file '%s'", filename); - } else { - _cursorNormal = spr; - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetNormalCursor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetNormalCursor") == 0) { - stack->correctParams(0); - - if (!_cursorNormal || !_cursorNormal->getFilename()) { - stack->pushNULL(); - } else { - stack->pushString(_cursorNormal->getFilename()); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetNormalCursorObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetNormalCursorObject") == 0) { - stack->correctParams(0); - - if (!_cursorNormal) { - stack->pushNULL(); - } else { - stack->pushNative(_cursorNormal, true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetHoverCursor - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SetHoverCursor") == 0) { - stack->correctParams(1); - - const char *filename = stack->pop()->getString(); - - delete _cursorHover; - _cursorHover = NULL; - BaseSprite *spr = new BaseSprite(_gameRef); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("Item.SetHoverCursor failed for file '%s'", filename); - } else { - _cursorHover = spr; - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetHoverCursor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetHoverCursor") == 0) { - stack->correctParams(0); - - if (!_cursorHover || !_cursorHover->getFilename()) { - stack->pushNULL(); - } else { - stack->pushString(_cursorHover->getFilename()); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetHoverCursorObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetHoverCursorObject") == 0) { - stack->correctParams(0); - - if (!_cursorHover) { - stack->pushNULL(); - } else { - stack->pushNative(_cursorHover, true); - } - return STATUS_OK; - } else { - return AdTalkHolder::scCallMethod(script, stack, thisStack, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdItem::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("item"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Name") == 0) { - _scValue->setString(getName()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // DisplayAmount - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DisplayAmount") == 0) { - _scValue->setBool(_displayAmount); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Amount - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Amount") == 0) { - _scValue->setInt(_amount); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountOffsetX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetX") == 0) { - _scValue->setInt(_amountOffsetX); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountOffsetY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetY") == 0) { - _scValue->setInt(_amountOffsetY); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountAlign - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountAlign") == 0) { - _scValue->setInt(_amountAlign); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountString - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountString") == 0) { - if (!_amountString) { - _scValue->setNULL(); - } else { - _scValue->setString(_amountString); - } - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // CursorCombined - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CursorCombined") == 0) { - _scValue->setBool(_cursorCombined); - return _scValue; - } else { - return AdTalkHolder::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdItem::scSetProperty(const char *name, ScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Name") == 0) { - setName(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DisplayAmount - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DisplayAmount") == 0) { - _displayAmount = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Amount - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Amount") == 0) { - _amount = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountOffsetX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetX") == 0) { - _amountOffsetX = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountOffsetY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetY") == 0) { - _amountOffsetY = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountAlign - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountAlign") == 0) { - _amountAlign = (TTextAlign)value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AmountString - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountString") == 0) { - if (value->isNULL()) { - delete[] _amountString; - _amountString = NULL; - } else { - BaseUtils::setString(&_amountString, value->getString()); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CursorCombined - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CursorCombined") == 0) { - _cursorCombined = value->getBool(); - return STATUS_OK; - } else { - return AdTalkHolder::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdItem::scToString() { - return "[item]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdItem::persist(BasePersistenceManager *persistMgr) { - - AdTalkHolder::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_cursorCombined)); - persistMgr->transfer(TMEMBER(_cursorHover)); - persistMgr->transfer(TMEMBER(_cursorNormal)); - persistMgr->transfer(TMEMBER(_spriteHover)); - persistMgr->transfer(TMEMBER(_inInventory)); - persistMgr->transfer(TMEMBER(_displayAmount)); - persistMgr->transfer(TMEMBER(_amount)); - persistMgr->transfer(TMEMBER(_amountOffsetX)); - persistMgr->transfer(TMEMBER(_amountOffsetY)); - persistMgr->transfer(TMEMBER_INT(_amountAlign)); - persistMgr->transfer(TMEMBER(_amountString)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdItem::getExtendedFlag(const char *flagName) { - if (!flagName) { - return false; - } else if (strcmp(flagName, "usable") == 0) { - return true; - } else { - return AdObject::getExtendedFlag(flagName); - } -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdItem, false) + +////////////////////////////////////////////////////////////////////////// +AdItem::AdItem(BaseGame *inGame) : AdTalkHolder(inGame) { + _spriteHover = NULL; + _cursorNormal = _cursorHover = NULL; + + _cursorCombined = true; + _inInventory = false; + + _displayAmount = false; + _amount = 0; + _amountOffsetX = 0; + _amountOffsetY = 0; + _amountAlign = TAL_RIGHT; + _amountString = NULL; + + _state = STATE_READY; + + _movable = false; +} + + +////////////////////////////////////////////////////////////////////////// +AdItem::~AdItem() { + delete _spriteHover; + delete _cursorNormal; + delete _cursorHover; + _spriteHover = NULL; + _cursorNormal = NULL; + _cursorHover = NULL; + + delete[] _amountString; + _amountString = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdItem::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdItem::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ITEM) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(CURSOR_HOVER) +TOKEN_DEF(CURSOR_COMBINED) +TOKEN_DEF(CURSOR) +TOKEN_DEF(NAME) +TOKEN_DEF(IMAGE_HOVER) +TOKEN_DEF(IMAGE) +TOKEN_DEF(EVENTS) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF(FONT) +TOKEN_DEF(ALPHA_COLOR) +TOKEN_DEF(ALPHA) +TOKEN_DEF(TALK_SPECIAL) +TOKEN_DEF(TALK) +TOKEN_DEF(SPRITE_HOVER) +TOKEN_DEF(SPRITE) +TOKEN_DEF(DISPLAY_AMOUNT) +TOKEN_DEF(AMOUNT_OFFSET_X) +TOKEN_DEF(AMOUNT_OFFSET_Y) +TOKEN_DEF(AMOUNT_ALIGN) +TOKEN_DEF(AMOUNT_STRING) +TOKEN_DEF(AMOUNT) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdItem::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ITEM) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(CURSOR_HOVER) + TOKEN_TABLE(CURSOR_COMBINED) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(NAME) + TOKEN_TABLE(IMAGE_HOVER) + TOKEN_TABLE(IMAGE) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE(FONT) + TOKEN_TABLE(ALPHA_COLOR) + TOKEN_TABLE(ALPHA) + TOKEN_TABLE(TALK_SPECIAL) + TOKEN_TABLE(TALK) + TOKEN_TABLE(SPRITE_HOVER) + TOKEN_TABLE(SPRITE) + TOKEN_TABLE(DISPLAY_AMOUNT) + TOKEN_TABLE(AMOUNT_OFFSET_X) + TOKEN_TABLE(AMOUNT_OFFSET_Y) + TOKEN_TABLE(AMOUNT_ALIGN) + TOKEN_TABLE(AMOUNT_STRING) + TOKEN_TABLE(AMOUNT) + TOKEN_TABLE_END + + byte *params; + int cmd = 2; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ITEM) { + _gameRef->LOG(0, "'ITEM' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + int ar = 0, ag = 0, ab = 0, alpha = 255; + while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_FONT: + setFont((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_IMAGE: + case TOKEN_SPRITE: + delete _sprite; + _sprite = new BaseSprite(_gameRef, this); + if (!_sprite || DID_FAIL(_sprite->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { + delete _sprite; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_IMAGE_HOVER: + case TOKEN_SPRITE_HOVER: + delete _spriteHover; + _spriteHover = new BaseSprite(_gameRef, this); + if (!_spriteHover || DID_FAIL(_spriteHover->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { + delete _spriteHover; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_AMOUNT: + parser.scanStr((char *)params, "%d", &_amount); + break; + + case TOKEN_DISPLAY_AMOUNT: + parser.scanStr((char *)params, "%b", &_displayAmount); + break; + + case TOKEN_AMOUNT_OFFSET_X: + parser.scanStr((char *)params, "%d", &_amountOffsetX); + break; + + case TOKEN_AMOUNT_OFFSET_Y: + parser.scanStr((char *)params, "%d", &_amountOffsetY); + break; + + case TOKEN_AMOUNT_ALIGN: + if (scumm_stricmp((char *)params, "left") == 0) { + _amountAlign = TAL_LEFT; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _amountAlign = TAL_RIGHT; + } else { + _amountAlign = TAL_CENTER; + } + break; + + case TOKEN_AMOUNT_STRING: + BaseUtils::setString(&_amountString, (char *)params); + break; + + case TOKEN_TALK: { + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } + } + break; + + case TOKEN_TALK_SPECIAL: { + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } + } + break; + + case TOKEN_CURSOR: + delete _cursorNormal; + _cursorNormal = new BaseSprite(_gameRef); + if (!_cursorNormal || DID_FAIL(_cursorNormal->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { + delete _cursorNormal; + _cursorNormal = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CURSOR_HOVER: + delete _cursorHover; + _cursorHover = new BaseSprite(_gameRef); + if (!_cursorHover || DID_FAIL(_cursorHover->loadFile((char *)params, ((AdGame *)_gameRef)->_texItemLifeTime))) { + delete _cursorHover; + _cursorHover = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CURSOR_COMBINED: + parser.scanStr((char *)params, "%b", &_cursorCombined); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + 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; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ITEM definition"); + return STATUS_FAILED; + } + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ITEM definition"); + return STATUS_FAILED; + } + + if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) { + ar = ag = ab = 255; + } + _alphaColor = BYTETORGBA(ar, ag, ab, alpha); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdItem::update() { + _currentSprite = NULL; + + if (_state == STATE_READY && _animSprite) { + delete _animSprite; + _animSprite = NULL; + } + + // finished playing animation? + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + _state = STATE_READY; + _currentSprite = _animSprite; + } + + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } + + // default: stand animation + if (!_currentSprite) { + _currentSprite = _sprite; + } + + switch (_state) { + ////////////////////////////////////////////////////////////////////////// + case STATE_PLAYING_ANIM: + _currentSprite = _animSprite; + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_READY: + if (!_animSprite) { + if (_gameRef->_activeObject == this && _spriteHover) { + _currentSprite = _spriteHover; + } else { + _currentSprite = _sprite; + } + } + break; + + ////////////////////////////////////////////////////////////////////////// + case STATE_TALKING: { + _sentence->update(); + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } + + bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); + if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (timeIsUp) { + _sentence->finish(); + _tempSprite2 = NULL; + _state = STATE_READY; + } else { + _tempSprite2 = getTalkStance(_sentence->getNextStance()); + if (_tempSprite2) { + _tempSprite2->reset(); + _currentSprite = _tempSprite2; + } + ((AdGame *)_gameRef)->addSentence(_sentence); + } + } else { + _currentSprite = _tempSprite2; + ((AdGame *)_gameRef)->addSentence(_sentence); + } + } + default: + break; + } + _ready = (_state == STATE_READY); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdItem::display(int x, int y) { + int width = 0; + if (_currentSprite) { + Rect32 rc; + _currentSprite->getBoundingRect(&rc, 0, 0); + width = rc.width(); + } + + _posX = x + width / 2; + _posY = y; + + bool ret; + if (_currentSprite) { + ret = _currentSprite->draw(x, y, this, 100, 100, _alphaColor); + } else { + ret = STATUS_OK; + } + + if (_displayAmount) { + int amountX = x; + int amountY = y + _amountOffsetY; + + if (_amountAlign == TAL_RIGHT) { + width -= _amountOffsetX; + amountX -= _amountOffsetX; + } + amountX += _amountOffsetX; + + BaseFont *font = _font ? _font : _gameRef->_systemFont; + if (font) { + if (_amountString) { + font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); + } else { + char str[256]; + sprintf(str, "%d", _amount); + font->drawText((byte *)str, amountX, amountY, width, _amountAlign); + } + } + } + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // SetHoverSprite + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetHoverSprite") == 0) { + stack->correctParams(1); + + bool setCurrent = false; + if (_currentSprite && _currentSprite == _spriteHover) { + setCurrent = true; + } + + const char *filename = stack->pop()->getString(); + + delete _spriteHover; + _spriteHover = NULL; + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetHoverSprite failed for file '%s'", filename); + } else { + _spriteHover = spr; + if (setCurrent) { + _currentSprite = _spriteHover; + } + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverSprite") == 0) { + stack->correctParams(0); + + if (!_spriteHover || !_spriteHover->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_spriteHover->getFilename()); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverSpriteObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverSpriteObject") == 0) { + stack->correctParams(0); + if (!_spriteHover) { + stack->pushNULL(); + } else { + stack->pushNative(_spriteHover, true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetNormalCursor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetNormalCursor") == 0) { + stack->correctParams(1); + + const char *filename = stack->pop()->getString(); + + delete _cursorNormal; + _cursorNormal = NULL; + BaseSprite *spr = new BaseSprite(_gameRef); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetNormalCursor failed for file '%s'", filename); + } else { + _cursorNormal = spr; + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNormalCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNormalCursor") == 0) { + stack->correctParams(0); + + if (!_cursorNormal || !_cursorNormal->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_cursorNormal->getFilename()); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNormalCursorObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNormalCursorObject") == 0) { + stack->correctParams(0); + + if (!_cursorNormal) { + stack->pushNULL(); + } else { + stack->pushNative(_cursorNormal, true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetHoverCursor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetHoverCursor") == 0) { + stack->correctParams(1); + + const char *filename = stack->pop()->getString(); + + delete _cursorHover; + _cursorHover = NULL; + BaseSprite *spr = new BaseSprite(_gameRef); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("Item.SetHoverCursor failed for file '%s'", filename); + } else { + _cursorHover = spr; + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverCursor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverCursor") == 0) { + stack->correctParams(0); + + if (!_cursorHover || !_cursorHover->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_cursorHover->getFilename()); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetHoverCursorObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetHoverCursorObject") == 0) { + stack->correctParams(0); + + if (!_cursorHover) { + stack->pushNULL(); + } else { + stack->pushNative(_cursorHover, true); + } + return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdItem::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("item"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Name") == 0) { + _scValue->setString(getName()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // DisplayAmount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DisplayAmount") == 0) { + _scValue->setBool(_displayAmount); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Amount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Amount") == 0) { + _scValue->setInt(_amount); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetX") == 0) { + _scValue->setInt(_amountOffsetX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetY") == 0) { + _scValue->setInt(_amountOffsetY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountAlign + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountAlign") == 0) { + _scValue->setInt(_amountAlign); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountString + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountString") == 0) { + if (!_amountString) { + _scValue->setNULL(); + } else { + _scValue->setString(_amountString); + } + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // CursorCombined + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CursorCombined") == 0) { + _scValue->setBool(_cursorCombined); + return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdItem::scSetProperty(const char *name, ScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DisplayAmount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DisplayAmount") == 0) { + _displayAmount = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Amount + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Amount") == 0) { + _amount = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetX") == 0) { + _amountOffsetX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountOffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountOffsetY") == 0) { + _amountOffsetY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountAlign + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountAlign") == 0) { + _amountAlign = (TTextAlign)value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AmountString + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AmountString") == 0) { + if (value->isNULL()) { + delete[] _amountString; + _amountString = NULL; + } else { + BaseUtils::setString(&_amountString, value->getString()); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CursorCombined + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CursorCombined") == 0) { + _cursorCombined = value->getBool(); + return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdItem::scToString() { + return "[item]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdItem::persist(BasePersistenceManager *persistMgr) { + + AdTalkHolder::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_cursorCombined)); + persistMgr->transfer(TMEMBER(_cursorHover)); + persistMgr->transfer(TMEMBER(_cursorNormal)); + persistMgr->transfer(TMEMBER(_spriteHover)); + persistMgr->transfer(TMEMBER(_inInventory)); + persistMgr->transfer(TMEMBER(_displayAmount)); + persistMgr->transfer(TMEMBER(_amount)); + persistMgr->transfer(TMEMBER(_amountOffsetX)); + persistMgr->transfer(TMEMBER(_amountOffsetY)); + persistMgr->transfer(TMEMBER_INT(_amountAlign)); + persistMgr->transfer(TMEMBER(_amountString)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdItem::getExtendedFlag(const char *flagName) { + if (!flagName) { + return false; + } else if (strcmp(flagName, "usable") == 0) { + return true; + } else { + return AdObject::getExtendedFlag(flagName); + } +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_item.h b/engines/wintermute/ad/ad_item.h index e06266f8b7..6047c542c1 100644 --- a/engines/wintermute/ad/ad_item.h +++ b/engines/wintermute/ad/ad_item.h @@ -1,69 +1,69 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADITEM_H -#define WINTERMUTE_ADITEM_H - - -#include "engines/wintermute/ad/ad_talk_holder.h" - -namespace Wintermute { - -class AdItem : public AdTalkHolder { -public: - bool update(); - DECLARE_PERSISTENT(AdItem, AdTalkHolder) - bool display(int x, int y); - bool getExtendedFlag(const char *flagName); - bool _inInventory; - bool _cursorCombined; - BaseSprite *_spriteHover; - BaseSprite *_cursorNormal; - BaseSprite *_cursorHover; - AdItem(BaseGame *inGame); - virtual ~AdItem(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - virtual const char *scToString(); -private: - bool _displayAmount; - int _amount; - int _amountOffsetX; - int _amountOffsetY; - TTextAlign _amountAlign; - char *_amountString; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADITEM_H +#define WINTERMUTE_ADITEM_H + + +#include "engines/wintermute/ad/ad_talk_holder.h" + +namespace Wintermute { + +class AdItem : public AdTalkHolder { +public: + bool update(); + DECLARE_PERSISTENT(AdItem, AdTalkHolder) + bool display(int x, int y); + bool getExtendedFlag(const char *flagName); + bool _inInventory; + bool _cursorCombined; + BaseSprite *_spriteHover; + BaseSprite *_cursorNormal; + BaseSprite *_cursorHover; + AdItem(BaseGame *inGame); + virtual ~AdItem(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + virtual const char *scToString(); +private: + bool _displayAmount; + int _amount; + int _amountOffsetX; + int _amountOffsetY; + TTextAlign _amountAlign; + char *_amountString; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 709ab50b58..46b75b8b21 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -1,564 +1,564 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/ad/ad_layer.h" -#include "engines/wintermute/ad/ad_scene_node.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdLayer, false) - -////////////////////////////////////////////////////////////////////////// -AdLayer::AdLayer(BaseGame *inGame) : BaseObject(inGame) { - _main = false; - _width = _height = 0; - _active = true; - _closeUp = false; -} - - -////////////////////////////////////////////////////////////////////////// -AdLayer::~AdLayer() { - for (uint32 i = 0; i < _nodes.size(); i++) { - delete _nodes[i]; - } - _nodes.clear(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdLayer::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdLayer::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); - } - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(LAYER) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(NAME) -TOKEN_DEF(WIDTH) -TOKEN_DEF(HEIGHT) -TOKEN_DEF(MAIN) -TOKEN_DEF(ENTITY) -TOKEN_DEF(REGION) -TOKEN_DEF(ACTIVE) -TOKEN_DEF(EDITOR_SELECTED) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(CLOSE_UP) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdLayer::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(LAYER) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(NAME) - TOKEN_TABLE(WIDTH) - TOKEN_TABLE(HEIGHT) - TOKEN_TABLE(MAIN) - TOKEN_TABLE(ENTITY) - TOKEN_TABLE(REGION) - TOKEN_TABLE(ACTIVE) - TOKEN_TABLE(EDITOR_SELECTED) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(CLOSE_UP) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_LAYER) { - _gameRef->LOG(0, "'LAYER' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_MAIN: - parser.scanStr((char *)params, "%b", &_main); - break; - - case TOKEN_CLOSE_UP: - parser.scanStr((char *)params, "%b", &_closeUp); - break; - - case TOKEN_WIDTH: - parser.scanStr((char *)params, "%d", &_width); - break; - - case TOKEN_HEIGHT: - parser.scanStr((char *)params, "%d", &_height); - break; - - case TOKEN_ACTIVE: - parser.scanStr((char *)params, "%b", &_active); - break; - - case TOKEN_REGION: { - AdRegion *region = new AdRegion(_gameRef); - AdSceneNode *node = new AdSceneNode(_gameRef); - if (!region || !node || DID_FAIL(region->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete region; - delete node; - region = NULL; - node = NULL; - } else { - node->setRegion(region); - _nodes.add(node); - } - } - break; - - case TOKEN_ENTITY: { - AdEntity *entity = new AdEntity(_gameRef); - AdSceneNode *node = new AdSceneNode(_gameRef); - if (entity) { - entity->_zoomable = false; // scene entites default to NOT zoom - } - if (!entity || !node || DID_FAIL(entity->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete entity; - delete node; - entity = NULL; - node = NULL; - } else { - node->setEntity(entity); - _nodes.add(node); - } - } - break; - - case TOKEN_EDITOR_SELECTED: - parser.scanStr((char *)params, "%b", &_editorSelected); - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in LAYER definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // GetNode - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "GetNode") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - int node = -1; - - if (val->_type == VAL_INT) { - node = val->getInt(); - } else { // get by name - for (uint32 i = 0; i < _nodes.size(); i++) { - if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->getName(), val->getString()) == 0) || - (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->getName(), val->getString()) == 0)) { - node = i; - break; - } - } - } - - if (node < 0 || node >= (int32)_nodes.size()) { - stack->pushNULL(); - } else { - switch (_nodes[node]->_type) { - case OBJECT_ENTITY: - stack->pushNative(_nodes[node]->_entity, true); - break; - case OBJECT_REGION: - stack->pushNative(_nodes[node]->_region, true); - break; - default: - stack->pushNULL(); - } - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddRegion / AddEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddRegion") == 0 || strcmp(name, "AddEntity") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdSceneNode *node = new AdSceneNode(_gameRef); - if (strcmp(name, "AddRegion") == 0) { - AdRegion *region = new AdRegion(_gameRef); - if (!val->isNULL()) { - region->setName(val->getString()); - } - node->setRegion(region); - stack->pushNative(region, true); - } else { - AdEntity *entity = new AdEntity(_gameRef); - if (!val->isNULL()) { - entity->setName(val->getString()); - } - node->setEntity(entity); - stack->pushNative(entity, true); - } - _nodes.add(node); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InsertRegion / InsertEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InsertRegion") == 0 || strcmp(name, "InsertEntity") == 0) { - stack->correctParams(2); - int index = stack->pop()->getInt(); - ScValue *val = stack->pop(); - - AdSceneNode *node = new AdSceneNode(_gameRef); - if (strcmp(name, "InsertRegion") == 0) { - AdRegion *region = new AdRegion(_gameRef); - if (!val->isNULL()) { - region->setName(val->getString()); - } - node->setRegion(region); - stack->pushNative(region, true); - } else { - AdEntity *entity = new AdEntity(_gameRef); - if (!val->isNULL()) { - entity->setName(val->getString()); - } - node->setEntity(entity); - stack->pushNative(entity, true); - } - if (index < 0) { - index = 0; - } - if (index <= (int32)_nodes.size() - 1) { - _nodes.insert_at(index, node); - } else { - _nodes.add(node); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteNode - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteNode") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdSceneNode *toDelete = NULL; - if (val->isNative()) { - BaseScriptable *temp = val->getNative(); - for (uint32 i = 0; i < _nodes.size(); i++) { - if (_nodes[i]->_region == temp || _nodes[i]->_entity == temp) { - toDelete = _nodes[i]; - break; - } - } - } else { - int index = val->getInt(); - if (index >= 0 && index < (int32)_nodes.size()) { - toDelete = _nodes[index]; - } - } - if (toDelete == NULL) { - stack->pushBool(false); - return STATUS_OK; - } - - for (uint32 i = 0; i < _nodes.size(); i++) { - if (_nodes[i] == toDelete) { - delete _nodes[i]; - _nodes[i] = NULL; - _nodes.remove_at(i); - break; - } - } - stack->pushBool(true); - return STATUS_OK; - } else { - return BaseObject::scCallMethod(script, stack, thisStack, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdLayer::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("layer"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumNodes (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumNodes") == 0) { - _scValue->setInt(_nodes.size()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Width - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Width") == 0) { - _scValue->setInt(_width); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Height - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Height") == 0) { - _scValue->setInt(_height); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Main (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Main") == 0) { - _scValue->setBool(_main); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // CloseUp - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CloseUp") == 0) { - _scValue->setBool(_closeUp); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { - _scValue->setBool(_active); - return _scValue; - } else { - return BaseObject::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdLayer::scSetProperty(const char *name, ScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Name") == 0) { - setName(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CloseUp - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CloseUp") == 0) { - _closeUp = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Width - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Width") == 0) { - _width = value->getInt(); - if (_width < 0) { - _width = 0; - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Height - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Height") == 0) { - _height = value->getInt(); - if (_height < 0) { - _height = 0; - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { - bool b = value->getBool(); - if (b == false && _main) { - _gameRef->LOG(0, "Warning: cannot deactivate scene's main layer"); - } else { - _active = b; - } - return STATUS_OK; - } else { - return BaseObject::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdLayer::scToString() { - return "[layer]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "LAYER {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - buffer->putTextIndent(indent + 2, "MAIN=%s\n", _main ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "WIDTH=%d\n", _width); - buffer->putTextIndent(indent + 2, "HEIGHT=%d\n", _height); - buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - if (_closeUp) { - buffer->putTextIndent(indent + 2, "CLOSE_UP=%s\n", _closeUp ? "TRUE" : "FALSE"); - } - - for (uint32 i = 0; i < _scripts.size(); i++) { - buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); - } - - if (_scProp) { - _scProp->saveAsText(buffer, indent + 2); - } - - for (uint32 i = 0; i < _nodes.size(); i++) { - switch (_nodes[i]->_type) { - case OBJECT_ENTITY: - _nodes[i]->_entity->saveAsText(buffer, indent + 2); - break; - case OBJECT_REGION: - _nodes[i]->_region->saveAsText(buffer, indent + 2); - break; - default: - error("AdLayer::SaveAsText - Unhandled enum"); - break; - } - } - - BaseClass::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdLayer::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_active)); - persistMgr->transfer(TMEMBER(_closeUp)); - persistMgr->transfer(TMEMBER(_height)); - persistMgr->transfer(TMEMBER(_main)); - _nodes.persist(persistMgr); - persistMgr->transfer(TMEMBER(_width)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/ad/ad_layer.h" +#include "engines/wintermute/ad/ad_scene_node.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdLayer, false) + +////////////////////////////////////////////////////////////////////////// +AdLayer::AdLayer(BaseGame *inGame) : BaseObject(inGame) { + _main = false; + _width = _height = 0; + _active = true; + _closeUp = false; +} + + +////////////////////////////////////////////////////////////////////////// +AdLayer::~AdLayer() { + for (uint32 i = 0; i < _nodes.size(); i++) { + delete _nodes[i]; + } + _nodes.clear(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdLayer::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdLayer::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); + } + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(LAYER) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(WIDTH) +TOKEN_DEF(HEIGHT) +TOKEN_DEF(MAIN) +TOKEN_DEF(ENTITY) +TOKEN_DEF(REGION) +TOKEN_DEF(ACTIVE) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(CLOSE_UP) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdLayer::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(LAYER) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(WIDTH) + TOKEN_TABLE(HEIGHT) + TOKEN_TABLE(MAIN) + TOKEN_TABLE(ENTITY) + TOKEN_TABLE(REGION) + TOKEN_TABLE(ACTIVE) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(CLOSE_UP) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_LAYER) { + _gameRef->LOG(0, "'LAYER' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_MAIN: + parser.scanStr((char *)params, "%b", &_main); + break; + + case TOKEN_CLOSE_UP: + parser.scanStr((char *)params, "%b", &_closeUp); + break; + + case TOKEN_WIDTH: + parser.scanStr((char *)params, "%d", &_width); + break; + + case TOKEN_HEIGHT: + parser.scanStr((char *)params, "%d", &_height); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_REGION: { + AdRegion *region = new AdRegion(_gameRef); + AdSceneNode *node = new AdSceneNode(_gameRef); + if (!region || !node || DID_FAIL(region->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete region; + delete node; + region = NULL; + node = NULL; + } else { + node->setRegion(region); + _nodes.add(node); + } + } + break; + + case TOKEN_ENTITY: { + AdEntity *entity = new AdEntity(_gameRef); + AdSceneNode *node = new AdSceneNode(_gameRef); + if (entity) { + entity->_zoomable = false; // scene entites default to NOT zoom + } + if (!entity || !node || DID_FAIL(entity->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete entity; + delete node; + entity = NULL; + node = NULL; + } else { + node->setEntity(entity); + _nodes.add(node); + } + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in LAYER definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // GetNode + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "GetNode") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + int node = -1; + + if (val->_type == VAL_INT) { + node = val->getInt(); + } else { // get by name + for (uint32 i = 0; i < _nodes.size(); i++) { + if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->getName(), val->getString()) == 0) || + (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->getName(), val->getString()) == 0)) { + node = i; + break; + } + } + } + + if (node < 0 || node >= (int32)_nodes.size()) { + stack->pushNULL(); + } else { + switch (_nodes[node]->_type) { + case OBJECT_ENTITY: + stack->pushNative(_nodes[node]->_entity, true); + break; + case OBJECT_REGION: + stack->pushNative(_nodes[node]->_region, true); + break; + default: + stack->pushNULL(); + } + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddRegion / AddEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddRegion") == 0 || strcmp(name, "AddEntity") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdSceneNode *node = new AdSceneNode(_gameRef); + if (strcmp(name, "AddRegion") == 0) { + AdRegion *region = new AdRegion(_gameRef); + if (!val->isNULL()) { + region->setName(val->getString()); + } + node->setRegion(region); + stack->pushNative(region, true); + } else { + AdEntity *entity = new AdEntity(_gameRef); + if (!val->isNULL()) { + entity->setName(val->getString()); + } + node->setEntity(entity); + stack->pushNative(entity, true); + } + _nodes.add(node); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InsertRegion / InsertEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InsertRegion") == 0 || strcmp(name, "InsertEntity") == 0) { + stack->correctParams(2); + int index = stack->pop()->getInt(); + ScValue *val = stack->pop(); + + AdSceneNode *node = new AdSceneNode(_gameRef); + if (strcmp(name, "InsertRegion") == 0) { + AdRegion *region = new AdRegion(_gameRef); + if (!val->isNULL()) { + region->setName(val->getString()); + } + node->setRegion(region); + stack->pushNative(region, true); + } else { + AdEntity *entity = new AdEntity(_gameRef); + if (!val->isNULL()) { + entity->setName(val->getString()); + } + node->setEntity(entity); + stack->pushNative(entity, true); + } + if (index < 0) { + index = 0; + } + if (index <= (int32)_nodes.size() - 1) { + _nodes.insert_at(index, node); + } else { + _nodes.add(node); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteNode") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdSceneNode *toDelete = NULL; + if (val->isNative()) { + BaseScriptable *temp = val->getNative(); + for (uint32 i = 0; i < _nodes.size(); i++) { + if (_nodes[i]->_region == temp || _nodes[i]->_entity == temp) { + toDelete = _nodes[i]; + break; + } + } + } else { + int index = val->getInt(); + if (index >= 0 && index < (int32)_nodes.size()) { + toDelete = _nodes[index]; + } + } + if (toDelete == NULL) { + stack->pushBool(false); + return STATUS_OK; + } + + for (uint32 i = 0; i < _nodes.size(); i++) { + if (_nodes[i] == toDelete) { + delete _nodes[i]; + _nodes[i] = NULL; + _nodes.remove_at(i); + break; + } + } + stack->pushBool(true); + return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdLayer::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("layer"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumNodes (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumNodes") == 0) { + _scValue->setInt(_nodes.size()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Width + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + _scValue->setInt(_width); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Height + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + _scValue->setInt(_height); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Main (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Main") == 0) { + _scValue->setBool(_main); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // CloseUp + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CloseUp") == 0) { + _scValue->setBool(_closeUp); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } else { + return BaseObject::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdLayer::scSetProperty(const char *name, ScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CloseUp + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CloseUp") == 0) { + _closeUp = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Width + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + _width = value->getInt(); + if (_width < 0) { + _width = 0; + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Height + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + _height = value->getInt(); + if (_height < 0) { + _height = 0; + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + bool b = value->getBool(); + if (b == false && _main) { + _gameRef->LOG(0, "Warning: cannot deactivate scene's main layer"); + } else { + _active = b; + } + return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdLayer::scToString() { + return "[layer]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "LAYER {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + buffer->putTextIndent(indent + 2, "MAIN=%s\n", _main ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "WIDTH=%d\n", _width); + buffer->putTextIndent(indent + 2, "HEIGHT=%d\n", _height); + buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + if (_closeUp) { + buffer->putTextIndent(indent + 2, "CLOSE_UP=%s\n", _closeUp ? "TRUE" : "FALSE"); + } + + for (uint32 i = 0; i < _scripts.size(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } + + for (uint32 i = 0; i < _nodes.size(); i++) { + switch (_nodes[i]->_type) { + case OBJECT_ENTITY: + _nodes[i]->_entity->saveAsText(buffer, indent + 2); + break; + case OBJECT_REGION: + _nodes[i]->_region->saveAsText(buffer, indent + 2); + break; + default: + error("AdLayer::SaveAsText - Unhandled enum"); + break; + } + } + + BaseClass::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdLayer::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_closeUp)); + persistMgr->transfer(TMEMBER(_height)); + persistMgr->transfer(TMEMBER(_main)); + _nodes.persist(persistMgr); + persistMgr->transfer(TMEMBER(_width)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_layer.h b/engines/wintermute/ad/ad_layer.h index b01079c091..bb5f73b13a 100644 --- a/engines/wintermute/ad/ad_layer.h +++ b/engines/wintermute/ad/ad_layer.h @@ -1,58 +1,58 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADLAYER_H -#define WINTERMUTE_ADLAYER_H - -namespace Wintermute { -class AdSceneNode; -class AdLayer : public BaseObject { -public: - bool _closeUp; - DECLARE_PERSISTENT(AdLayer, BaseObject) - bool _active; - int _height; - int _width; - bool _main; - AdLayer(BaseGame *inGame); - virtual ~AdLayer(); - BaseArray _nodes; - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - virtual const char *scToString(); -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADLAYER_H +#define WINTERMUTE_ADLAYER_H + +namespace Wintermute { +class AdSceneNode; +class AdLayer : public BaseObject { +public: + bool _closeUp; + DECLARE_PERSISTENT(AdLayer, BaseObject) + bool _active; + int _height; + int _width; + bool _main; + AdLayer(BaseGame *inGame); + virtual ~AdLayer(); + BaseArray _nodes; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + virtual const char *scToString(); +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index fb2dfed0f5..493156c750 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -1,196 +1,196 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/ad/ad_node_state.h" -#include "engines/wintermute/ad/ad_entity.h" -#include "engines/wintermute/base/base_string_table.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdNodeState, false) - - -////////////////////////////////////////////////////////////////////////// -AdNodeState::AdNodeState(BaseGame *inGame) : BaseClass(inGame) { - _name = NULL; - _active = false; - for (int i = 0; i < 7; i++) { - _caption[i] = NULL; - } - _alphaColor = 0; - _filename = NULL; - _cursor = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdNodeState::~AdNodeState() { - delete[] _name; - delete[] _filename; - delete[] _cursor; - _name = NULL; - _filename = NULL; - _cursor = NULL; - for (int i = 0; i < 7; i++) { - delete[] _caption[i]; - _caption[i] = NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdNodeState::setName(const char *name) { - delete[] _name; - _name = NULL; - BaseUtils::setString(&_name, name); -} - - -////////////////////////////////////////////////////////////////////////// -void AdNodeState::setFilename(const char *filename) { - delete[] _filename; - _filename = NULL; - BaseUtils::setString(&_filename, filename); -} - - -////////////////////////////////////////////////////////////////////////// -void AdNodeState::setCursor(const char *filename) { - delete[] _cursor; - _cursor = NULL; - BaseUtils::setString(&_cursor, filename); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdNodeState::persist(BasePersistenceManager *persistMgr) { - persistMgr->transfer(TMEMBER(_gameRef)); - - persistMgr->transfer(TMEMBER(_active)); - persistMgr->transfer(TMEMBER(_name)); - persistMgr->transfer(TMEMBER(_filename)); - persistMgr->transfer(TMEMBER(_cursor)); - persistMgr->transfer(TMEMBER(_alphaColor)); - for (int i = 0; i < 7; i++) { - persistMgr->transfer(TMEMBER(_caption[i])); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void AdNodeState::setCaption(const char *caption, int caseVal) { - if (caseVal == 0) { - caseVal = 1; - } - if (caseVal < 1 || caseVal > 7) { - return; - } - - delete[] _caption[caseVal - 1]; - _caption[caseVal - 1] = new char[strlen(caption) + 1]; - if (_caption[caseVal - 1]) { - strcpy(_caption[caseVal - 1], caption); - _gameRef->_stringTable->expand(&_caption[caseVal - 1]); - } -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdNodeState::getCaption(int caseVal) { - if (caseVal == 0) { - caseVal = 1; - } - if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) { - return ""; - } else { - return _caption[caseVal - 1]; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool saving) { - if (!entity) { - return STATUS_FAILED; - } - - // HACK! - if (this->_gameRef != entity->_gameRef) { - this->_gameRef = entity->_gameRef; - } - - if (saving) { - for (int i = 0; i < 7; i++) { - if (entity->_caption[i]) { - setCaption(entity->_caption[i], i); - } - } - if (!entity->_region && entity->_sprite && entity->_sprite->getFilename()) { - if (includingSprites) { - setFilename(entity->_sprite->getFilename()); - } else { - setFilename(""); - } - } - if (entity->_cursor && entity->_cursor->getFilename()) { - setCursor(entity->_cursor->getFilename()); - } - _alphaColor = entity->_alphaColor; - _active = entity->_active; - } else { - for (int i = 0; i < 7; i++) { - if (_caption[i]) { - entity->setCaption(_caption[i], i); - } - } - if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) { - if (!entity->_sprite || !entity->_sprite->getFilename() || scumm_stricmp(entity->_sprite->getFilename(), _filename) != 0) { - entity->setSprite(_filename); - } - } - if (_cursor) { - if (!entity->_cursor || !entity->_cursor->getFilename() || scumm_stricmp(entity->_cursor->getFilename(), _cursor) != 0) { - entity->setCursor(_cursor); - } - } - - entity->_active = _active; - entity->_alphaColor = _alphaColor; - } - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/ad/ad_node_state.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/base/base_string_table.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdNodeState, false) + + +////////////////////////////////////////////////////////////////////////// +AdNodeState::AdNodeState(BaseGame *inGame) : BaseClass(inGame) { + _name = NULL; + _active = false; + for (int i = 0; i < 7; i++) { + _caption[i] = NULL; + } + _alphaColor = 0; + _filename = NULL; + _cursor = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdNodeState::~AdNodeState() { + delete[] _name; + delete[] _filename; + delete[] _cursor; + _name = NULL; + _filename = NULL; + _cursor = NULL; + for (int i = 0; i < 7; i++) { + delete[] _caption[i]; + _caption[i] = NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdNodeState::setName(const char *name) { + delete[] _name; + _name = NULL; + BaseUtils::setString(&_name, name); +} + + +////////////////////////////////////////////////////////////////////////// +void AdNodeState::setFilename(const char *filename) { + delete[] _filename; + _filename = NULL; + BaseUtils::setString(&_filename, filename); +} + + +////////////////////////////////////////////////////////////////////////// +void AdNodeState::setCursor(const char *filename) { + delete[] _cursor; + _cursor = NULL; + BaseUtils::setString(&_cursor, filename); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdNodeState::persist(BasePersistenceManager *persistMgr) { + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_name)); + persistMgr->transfer(TMEMBER(_filename)); + persistMgr->transfer(TMEMBER(_cursor)); + persistMgr->transfer(TMEMBER(_alphaColor)); + for (int i = 0; i < 7; i++) { + persistMgr->transfer(TMEMBER(_caption[i])); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void AdNodeState::setCaption(const char *caption, int caseVal) { + if (caseVal == 0) { + caseVal = 1; + } + if (caseVal < 1 || caseVal > 7) { + return; + } + + delete[] _caption[caseVal - 1]; + _caption[caseVal - 1] = new char[strlen(caption) + 1]; + if (_caption[caseVal - 1]) { + strcpy(_caption[caseVal - 1], caption); + _gameRef->_stringTable->expand(&_caption[caseVal - 1]); + } +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdNodeState::getCaption(int caseVal) { + if (caseVal == 0) { + caseVal = 1; + } + if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) { + return ""; + } else { + return _caption[caseVal - 1]; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool saving) { + if (!entity) { + return STATUS_FAILED; + } + + // HACK! + if (this->_gameRef != entity->_gameRef) { + this->_gameRef = entity->_gameRef; + } + + if (saving) { + for (int i = 0; i < 7; i++) { + if (entity->_caption[i]) { + setCaption(entity->_caption[i], i); + } + } + if (!entity->_region && entity->_sprite && entity->_sprite->getFilename()) { + if (includingSprites) { + setFilename(entity->_sprite->getFilename()); + } else { + setFilename(""); + } + } + if (entity->_cursor && entity->_cursor->getFilename()) { + setCursor(entity->_cursor->getFilename()); + } + _alphaColor = entity->_alphaColor; + _active = entity->_active; + } else { + for (int i = 0; i < 7; i++) { + if (_caption[i]) { + entity->setCaption(_caption[i], i); + } + } + if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) { + if (!entity->_sprite || !entity->_sprite->getFilename() || scumm_stricmp(entity->_sprite->getFilename(), _filename) != 0) { + entity->setSprite(_filename); + } + } + if (_cursor) { + if (!entity->_cursor || !entity->_cursor->getFilename() || scumm_stricmp(entity->_cursor->getFilename(), _cursor) != 0) { + entity->setCursor(_cursor); + } + } + + entity->_active = _active; + entity->_alphaColor = _alphaColor; + } + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_node_state.h b/engines/wintermute/ad/ad_node_state.h index 0008d4b3ee..e2050815a7 100644 --- a/engines/wintermute/ad/ad_node_state.h +++ b/engines/wintermute/ad/ad_node_state.h @@ -1,60 +1,60 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADNODESTATE_H -#define WINTERMUTE_ADNODESTATE_H - -namespace Wintermute { - -class AdEntity; - -class AdNodeState : public BaseClass { -public: - bool _active; - bool transferEntity(AdEntity *entity, bool includingSprites, bool saving); - void setName(const char *name); - void setFilename(const char *filename); - void setCursor(const char *filename); - DECLARE_PERSISTENT(AdNodeState, BaseClass) - AdNodeState(BaseGame *inGame); - virtual ~AdNodeState(); - const char *getName() const { return _name; } -private: - char *_name; - char *_caption[7]; - void setCaption(const char *caption, int caseVal); - const char *getCaption(int caseVal); - uint32 _alphaColor; - char *_filename; - char *_cursor; - -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADNODESTATE_H +#define WINTERMUTE_ADNODESTATE_H + +namespace Wintermute { + +class AdEntity; + +class AdNodeState : public BaseClass { +public: + bool _active; + bool transferEntity(AdEntity *entity, bool includingSprites, bool saving); + void setName(const char *name); + void setFilename(const char *filename); + void setCursor(const char *filename); + DECLARE_PERSISTENT(AdNodeState, BaseClass) + AdNodeState(BaseGame *inGame); + virtual ~AdNodeState(); + const char *getName() const { return _name; } +private: + char *_name; + char *_caption[7]; + void setCaption(const char *caption, int caseVal); + const char *getCaption(int caseVal); + uint32 _alphaColor; + char *_filename; + char *_cursor; + +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index a02decebdb..6c77917979 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -1,1299 +1,1299 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_item.h" -#include "engines/wintermute/ad/ad_object.h" -#include "engines/wintermute/ad/ad_inventory.h" -#include "engines/wintermute/ad/ad_layer.h" -#include "engines/wintermute/ad/ad_scene.h" -#include "engines/wintermute/ad/ad_scene_node.h" -#include "engines/wintermute/ad/ad_sentence.h" -#include "engines/wintermute/ad/ad_waypoint_group.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_frame.h" -#include "engines/wintermute/base/sound/base_sound.h" -#include "engines/wintermute/base/base_surface_storage.h" -#include "engines/wintermute/base/base_sub_frame.h" -#include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/base/font/base_font_storage.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_string_table.h" -#include "engines/wintermute/base/scriptables/script_engine.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/particles/part_emitter.h" -#include "common/str.h" -#include "common/util.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdObject, false) - -////////////////////////////////////////////////////////////////////////// -AdObject::AdObject(BaseGame *inGame) : BaseObject(inGame) { - _type = OBJECT_NONE; - _state = _nextState = STATE_NONE; - - _active = true; - _drawn = false; - - _currentSprite = NULL; - _animSprite = NULL; - _tempSprite2 = NULL; - - _font = NULL; - - _sentence = NULL; - - _forcedTalkAnimName = NULL; - _forcedTalkAnimUsed = false; - - _blockRegion = NULL; - _wptGroup = NULL; - - _currentBlockRegion = NULL; - _currentWptGroup = NULL; - - _ignoreItems = false; - _sceneIndependent = false; - - _stickRegion = NULL; - - _subtitlesModRelative = true; - _subtitlesModX = 0; - _subtitlesModY = 0; - _subtitlesWidth = 0; - _subtitlesModXCenter = true; - - _inventory = NULL; - - for (int i = 0; i < MAX_NUM_REGIONS; i++) { - _currentRegions[i] = NULL; - } - - _partEmitter = NULL; - _partFollowParent = false; - _partOffsetX = _partOffsetY = 0; - - _registerAlias = this; -} - - -////////////////////////////////////////////////////////////////////////// -AdObject::~AdObject() { - _currentSprite = NULL; // reference only, don't delete - delete _animSprite; - _animSprite = NULL; - delete _sentence; - _sentence = NULL; - delete[] _forcedTalkAnimName; - _forcedTalkAnimName = NULL; - - delete _blockRegion; - _blockRegion = NULL; - delete _wptGroup; - _wptGroup = NULL; - - delete _currentBlockRegion; - _currentBlockRegion = NULL; - delete _currentWptGroup; - _currentWptGroup = NULL; - - _tempSprite2 = NULL; // reference only - _stickRegion = NULL; - - if (_font) { - _gameRef->_fontStorage->removeFont(_font); - } - - if (_inventory) { - ((AdGame *)_gameRef)->unregisterInventory(_inventory); - _inventory = NULL; - } - - if (_partEmitter) { - _gameRef->unregisterObject(_partEmitter); - } - - - for (uint32 i = 0; i < _attachmentsPre.size(); i++) { - _gameRef->unregisterObject(_attachmentsPre[i]); - } - _attachmentsPre.clear(); - - for (uint32 i = 0; i < _attachmentsPost.size(); i++) { - _gameRef->unregisterObject(_attachmentsPost[i]); - } - _attachmentsPost.clear(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::playAnim(const char *filename) { - delete _animSprite; - _animSprite = NULL; - _animSprite = new BaseSprite(_gameRef, this); - if (!_animSprite) { - _gameRef->LOG(0, "AdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", getName(), filename); - return STATUS_FAILED; - } - bool res = _animSprite->loadFile(filename); - if (DID_FAIL(res)) { - _gameRef->LOG(res, "AdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", getName(), filename); - delete _animSprite; - _animSprite = NULL; - return res; - } - _state = STATE_PLAYING_ANIM; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::display() { - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::update() { - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - - ////////////////////////////////////////////////////////////////////////// - // PlayAnim / PlayAnimAsync - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "PlayAnim") == 0 || strcmp(name, "PlayAnimAsync") == 0) { - stack->correctParams(1); - if (DID_FAIL(playAnim(stack->pop()->getString()))) { - stack->pushBool(false); - } else { - if (strcmp(name, "PlayAnimAsync") != 0) { - script->waitFor(this); - } - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Reset - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Reset") == 0) { - stack->correctParams(0); - reset(); - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsTalking - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsTalking") == 0) { - stack->correctParams(0); - stack->pushBool(_state == STATE_TALKING); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // StopTalk / StopTalking - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StopTalk") == 0 || strcmp(name, "StopTalking") == 0) { - stack->correctParams(0); - if (_sentence) { - _sentence->finish(); - } - if (_state == STATE_TALKING) { - _state = _nextState; - _nextState = STATE_READY; - stack->pushBool(true); - } else { - stack->pushBool(false); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ForceTalkAnim - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ForceTalkAnim") == 0) { - stack->correctParams(1); - const char *animName = stack->pop()->getString(); - delete[] _forcedTalkAnimName; - _forcedTalkAnimName = new char[strlen(animName) + 1]; - strcpy(_forcedTalkAnimName, animName); - _forcedTalkAnimUsed = false; - stack->pushBool(true); - return STATUS_OK; - } - - - ////////////////////////////////////////////////////////////////////////// - // Talk / TalkAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Talk") == 0 || strcmp(name, "TalkAsync") == 0) { - stack->correctParams(5); - - const char *text = stack->pop()->getString(); - ScValue *soundVal = stack->pop(); - int duration = stack->pop()->getInt(); - ScValue *valStances = stack->pop(); - - const char *stances = valStances->isNULL() ? NULL : valStances->getString(); - - int align = 0; - ScValue *val = stack->pop(); - if (val->isNULL()) { - align = TAL_CENTER; - } else { - align = val->getInt(); - } - - align = MIN(MAX(0, align), NUM_TEXT_ALIGN - 1); - - const char *sound = soundVal->isNULL() ? NULL : soundVal->getString(); - - talk(text, sound, duration, stances, (TTextAlign)align); - if (strcmp(name, "TalkAsync") != 0) { - script->waitForExclusive(this); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // StickToRegion - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StickToRegion") == 0) { - stack->correctParams(1); - - AdLayer *main = ((AdGame *)_gameRef)->_scene->_mainLayer; - bool regFound = false; - - uint32 i; - ScValue *val = stack->pop(); - if (val->isNULL() || !main) { - _stickRegion = NULL; - regFound = true; - } else if (val->isString()) { - const char *regionName = val->getString(); - for (i = 0; i < main->_nodes.size(); i++) { - if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region->getName() && scumm_stricmp(main->_nodes[i]->_region->getName(), regionName) == 0) { - _stickRegion = main->_nodes[i]->_region; - regFound = true; - break; - } - } - } else if (val->isNative()) { - BaseScriptable *obj = val->getNative(); - - for (i = 0; i < main->_nodes.size(); i++) { - if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region == obj) { - _stickRegion = main->_nodes[i]->_region; - regFound = true; - break; - } - } - - } - - if (!regFound) { - _stickRegion = NULL; - } - stack->pushBool(regFound); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetFont - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SetFont") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - if (val->isNULL()) { - setFont(NULL); - } else { - setFont(val->getString()); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetFont - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetFont") == 0) { - stack->correctParams(0); - if (_font && _font->getFilename()) { - stack->pushString(_font->getFilename()); - } else { - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // TakeItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TakeItem") == 0) { - stack->correctParams(2); - - if (!_inventory) { - _inventory = new AdInventory(_gameRef); - ((AdGame *)_gameRef)->registerInventory(_inventory); - } - - ScValue *val = stack->pop(); - if (!val->isNULL()) { - const char *itemName = val->getString(); - val = stack->pop(); - const char *insertAfter = val->isNULL() ? NULL : val->getString(); - if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) { - script->runtimeError("Cannot add item '%s' to inventory", itemName); - } else { - // hide associated entities - ((AdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); - } - - } else { - script->runtimeError("TakeItem: item name expected"); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DropItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DropItem") == 0) { - stack->correctParams(1); - - if (!_inventory) { - _inventory = new AdInventory(_gameRef); - ((AdGame *)_gameRef)->registerInventory(_inventory); - } - - ScValue *val = stack->pop(); - if (!val->isNULL()) { - if (DID_FAIL(_inventory->removeItem(val->getString()))) { - script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); - } else { - // show associated entities - ((AdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); - } - } else { - script->runtimeError("DropItem: item name expected"); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetItem") == 0) { - stack->correctParams(1); - - if (!_inventory) { - _inventory = new AdInventory(_gameRef); - ((AdGame *)_gameRef)->registerInventory(_inventory); - } - - ScValue *val = stack->pop(); - if (val->_type == VAL_STRING) { - AdItem *item = ((AdGame *)_gameRef)->getItemByName(val->getString()); - if (item) { - stack->pushNative(item, true); - } else { - stack->pushNULL(); - } - } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= (int32)_inventory->_takenItems.size()) { - stack->pushNULL(); - } else { - stack->pushNative(_inventory->_takenItems[val->getInt()], true); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // HasItem - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "HasItem") == 0) { - stack->correctParams(1); - - if (!_inventory) { - _inventory = new AdInventory(_gameRef); - ((AdGame *)_gameRef)->registerInventory(_inventory); - } - - ScValue *val = stack->pop(); - if (!val->isNULL()) { - for (uint32 i = 0; i < _inventory->_takenItems.size(); i++) { - if (val->getNative() == _inventory->_takenItems[i]) { - stack->pushBool(true); - return STATUS_OK; - } else if (scumm_stricmp(val->getString(), _inventory->_takenItems[i]->getName()) == 0) { - stack->pushBool(true); - return STATUS_OK; - } - } - } else { - script->runtimeError("HasItem: item name expected"); - } - - stack->pushBool(false); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CreateParticleEmitter - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateParticleEmitter") == 0) { - stack->correctParams(3); - bool followParent = stack->pop()->getBool(); - int offsetX = stack->pop()->getInt(); - int offsetY = stack->pop()->getInt(); - - PartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); - if (emitter) { - stack->pushNative(_partEmitter, true); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteParticleEmitter - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteParticleEmitter") == 0) { - stack->correctParams(0); - if (_partEmitter) { - _gameRef->unregisterObject(_partEmitter); - _partEmitter = NULL; - } - stack->pushNULL(); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddAttachment - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddAttachment") == 0) { - stack->correctParams(4); - const char *filename = stack->pop()->getString(); - bool preDisplay = stack->pop()->getBool(true); - int offsetX = stack->pop()->getInt(); - int offsetY = stack->pop()->getInt(); - - bool res; - AdEntity *ent = new AdEntity(_gameRef); - if (DID_FAIL(res = ent->loadFile(filename))) { - delete ent; - ent = NULL; - script->runtimeError("AddAttachment() failed loading entity '%s'", filename); - stack->pushBool(false); - } else { - _gameRef->registerObject(ent); - - ent->_posX = offsetX; - ent->_posY = offsetY; - ent->_active = true; - - if (preDisplay) { - _attachmentsPre.add(ent); - } else { - _attachmentsPost.add(ent); - } - - stack->pushBool(true); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // RemoveAttachment - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "RemoveAttachment") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - bool found = false; - if (val->isNative()) { - BaseScriptable *obj = val->getNative(); - for (uint32 i = 0; i < _attachmentsPre.size(); i++) { - if (_attachmentsPre[i] == obj) { - found = true; - _gameRef->unregisterObject(_attachmentsPre[i]); - _attachmentsPre.remove_at(i); - i--; - } - } - for (uint32 i = 0; i < _attachmentsPost.size(); i++) { - if (_attachmentsPost[i] == obj) { - found = true; - _gameRef->unregisterObject(_attachmentsPost[i]); - _attachmentsPost.remove_at(i); - i--; - } - } - } else { - const char *attachmentName = val->getString(); - for (uint32 i = 0; i < _attachmentsPre.size(); i++) { - if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { - found = true; - _gameRef->unregisterObject(_attachmentsPre[i]); - _attachmentsPre.remove_at(i); - i--; - } - } - for (uint32 i = 0; i < _attachmentsPost.size(); i++) { - if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { - found = true; - _gameRef->unregisterObject(_attachmentsPost[i]); - _attachmentsPost.remove_at(i); - i--; - } - } - } - stack->pushBool(found); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetAttachment - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetAttachment") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdObject *ret = NULL; - if (val->isInt()) { - int index = val->getInt(); - int currIndex = 0; - for (uint32 i = 0; i < _attachmentsPre.size(); i++) { - if (currIndex == index) { - ret = _attachmentsPre[i]; - } - currIndex++; - } - for (uint32 i = 0; i < _attachmentsPost.size(); i++) { - if (currIndex == index) { - ret = _attachmentsPost[i]; - } - currIndex++; - } - } else { - const char *attachmentName = val->getString(); - for (uint32 i = 0; i < _attachmentsPre.size(); i++) { - if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { - ret = _attachmentsPre[i]; - break; - } - } - if (!ret) { - for (uint32 i = 0; i < _attachmentsPost.size(); i++) { - if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { - ret = _attachmentsPre[i]; - break; - } - } - } - } - - if (ret != NULL) { - stack->pushNative(ret, true); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } else { - return BaseObject::scCallMethod(script, stack, thisStack, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdObject::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("object"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { - _scValue->setBool(_active); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // IgnoreItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IgnoreItems") == 0) { - _scValue->setBool(_ignoreItems); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SceneIndependent - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SceneIndependent") == 0) { - _scValue->setBool(_sceneIndependent); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesWidth - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesWidth") == 0) { - _scValue->setInt(_subtitlesWidth); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosRelative - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosRelative") == 0) { - _scValue->setBool(_subtitlesModRelative); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosX") == 0) { - _scValue->setInt(_subtitlesModX); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosY") == 0) { - _scValue->setInt(_subtitlesModY); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosXCenter - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosXCenter") == 0) { - _scValue->setBool(_subtitlesModXCenter); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumItems (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumItems") == 0) { - _scValue->setInt(getInventory()->_takenItems.size()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ParticleEmitter (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ParticleEmitter") == 0) { - if (_partEmitter) { - _scValue->setNative(_partEmitter, true); - } else { - _scValue->setNULL(); - } - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumAttachments (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumAttachments") == 0) { - _scValue->setInt(_attachmentsPre.size() + _attachmentsPost.size()); - return _scValue; - } else { - return BaseObject::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::scSetProperty(const char *name, ScValue *value) { - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Active") == 0) { - _active = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IgnoreItems - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IgnoreItems") == 0) { - _ignoreItems = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SceneIndependent - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SceneIndependent") == 0) { - _sceneIndependent = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesWidth - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesWidth") == 0) { - _subtitlesWidth = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosRelative - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosRelative") == 0) { - _subtitlesModRelative = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosX") == 0) { - _subtitlesModX = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosY") == 0) { - _subtitlesModY = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SubtitlesPosXCenter - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosXCenter") == 0) { - _subtitlesModXCenter = value->getBool(); - return STATUS_OK; - } else { - return BaseObject::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdObject::scToString() { - return "[ad object]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::setFont(const char *filename) { - if (_font) { - _gameRef->_fontStorage->removeFont(_font); - } - if (filename) { - _font = _gameRef->_fontStorage->addFont(filename); - return _font == NULL ? STATUS_FAILED : STATUS_OK; - } else { - _font = NULL; - return STATUS_OK; - } -} - - -////////////////////////////////////////////////////////////////////////// -int AdObject::getHeight() { - if (!_currentSprite) { - return 0; - } else { - BaseFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; - int ret = 0; - for (uint32 i = 0; i < frame->_subframes.size(); i++) { - ret = MAX(ret, frame->_subframes[i]->_hotspotY); - } - - if (_zoomable) { - float zoom = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY); - ret = (int)(ret * zoom / 100); - } - return ret; - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { - if (!_sentence) { - _sentence = new AdSentence(_gameRef); - } - if (!_sentence) { - return; - } - - if (_forcedTalkAnimName && _forcedTalkAnimUsed) { - delete[] _forcedTalkAnimName; - _forcedTalkAnimName = NULL; - _forcedTalkAnimUsed = false; - } - - delete(_sentence->_sound); - _sentence->_sound = NULL; - - _sentence->setText(text); - _gameRef->_stringTable->expand(&_sentence->_text); - _sentence->setStances(stances); - _sentence->_duration = duration; - _sentence->_align = Align; - _sentence->_startTime = _gameRef->_timer; - _sentence->_currentStance = -1; - _sentence->_font = _font == NULL ? _gameRef->_systemFont : _font; - _sentence->_freezable = _freezable; - - // try to locate speech file automatically - bool deleteSound = false; - if (!sound) { - char *key = _gameRef->_stringTable->getKey(text); - if (key) { - sound = ((AdGame *)_gameRef)->findSpeechFile(key); - delete[] key; - - if (sound) { - deleteSound = true; - } - } - } - - // load sound and set duration appropriately - if (sound) { - BaseSound *snd = new BaseSound(_gameRef); - if (snd && DID_SUCCEED(snd->setSound(sound, Audio::Mixer::kSpeechSoundType, true))) { - _sentence->setSound(snd); - if (_sentence->_duration <= 0) { - uint32 length = snd->getLength(); - if (length != 0) { - _sentence->_duration = length; - } - } - } else { - delete snd; - } - } - - // set duration by text length - if (_sentence->_duration <= 0) {// TODO: Avoid longs. - _sentence->_duration = MAX((size_t)1000, _gameRef->_subtitlesSpeed * strlen(_sentence->_text)); - } - - - int x, y, width, height; - - x = _posX; - y = _posY; - - if (!_sceneIndependent && _subtitlesModRelative) { - x -= ((AdGame *)_gameRef)->_scene->getOffsetLeft(); - y -= ((AdGame *)_gameRef)->_scene->getOffsetTop(); - } - - - if (_subtitlesWidth > 0) { - width = _subtitlesWidth; - } else { - if ((x < _gameRef->_renderer->_width / 4 || x > _gameRef->_renderer->_width * 0.75) && !_gameRef->_touchInterface) { - width = MAX(_gameRef->_renderer->_width / 4, MIN(x * 2, (_gameRef->_renderer->_width - x) * 2)); - } else { - width = _gameRef->_renderer->_width / 2; - } - } - - height = _sentence->_font->getTextHeight((byte *)_sentence->_text, width); - - y = y - height - getHeight() - 5; - if (_subtitlesModRelative) { - x += _subtitlesModX; - y += _subtitlesModY; - } else { - x = _subtitlesModX; - y = _subtitlesModY; - } - if (_subtitlesModXCenter) { - x = x - width / 2; - } - - - x = MIN(MAX(0, x), _gameRef->_renderer->_width - width); - y = MIN(MAX(0, y), _gameRef->_renderer->_height - height); - - _sentence->_width = width; - - - _sentence->_pos.x = x; - _sentence->_pos.y = y; - - - if (_subtitlesModRelative) { - _sentence->_pos.x += ((AdGame *)_gameRef)->_scene->getOffsetLeft(); - _sentence->_pos.y += ((AdGame *)_gameRef)->_scene->getOffsetTop(); - } - - _sentence->_fixedPos = !_subtitlesModRelative; - - - _sentence->setupTalkFile(sound); - - _state = STATE_TALKING; - - if (deleteSound) { - delete[] sound; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::reset() { - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL) { - delete _animSprite; - _animSprite = NULL; - } else if (_state == STATE_TALKING && _sentence) { - _sentence->finish(); - } - - _state = _nextState = STATE_READY; - - _gameRef->_scEngine->resetObject(this); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::persist(BasePersistenceManager *persistMgr) { - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_active)); - persistMgr->transfer(TMEMBER(_blockRegion)); - persistMgr->transfer(TMEMBER(_currentBlockRegion)); - persistMgr->transfer(TMEMBER(_currentWptGroup)); - persistMgr->transfer(TMEMBER(_currentSprite)); - persistMgr->transfer(TMEMBER(_drawn)); - persistMgr->transfer(TMEMBER(_font)); - persistMgr->transfer(TMEMBER(_ignoreItems)); - persistMgr->transfer(TMEMBER_INT(_nextState)); - persistMgr->transfer(TMEMBER(_sentence)); - persistMgr->transfer(TMEMBER_INT(_state)); - persistMgr->transfer(TMEMBER(_animSprite)); - persistMgr->transfer(TMEMBER(_sceneIndependent)); - persistMgr->transfer(TMEMBER(_forcedTalkAnimName)); - persistMgr->transfer(TMEMBER(_forcedTalkAnimUsed)); - persistMgr->transfer(TMEMBER(_tempSprite2)); - persistMgr->transfer(TMEMBER_INT(_type)); - persistMgr->transfer(TMEMBER(_wptGroup)); - persistMgr->transfer(TMEMBER(_stickRegion)); - persistMgr->transfer(TMEMBER(_subtitlesModRelative)); - persistMgr->transfer(TMEMBER(_subtitlesModX)); - persistMgr->transfer(TMEMBER(_subtitlesModY)); - persistMgr->transfer(TMEMBER(_subtitlesModXCenter)); - persistMgr->transfer(TMEMBER(_subtitlesWidth)); - persistMgr->transfer(TMEMBER(_inventory)); - persistMgr->transfer(TMEMBER(_partEmitter)); - - for (int i = 0; i < MAX_NUM_REGIONS; i++) { - persistMgr->transfer(TMEMBER(_currentRegions[i])); - } - - _attachmentsPre.persist(persistMgr); - _attachmentsPost.persist(persistMgr); - persistMgr->transfer(TMEMBER(_registerAlias)); - - persistMgr->transfer(TMEMBER(_partFollowParent)); - persistMgr->transfer(TMEMBER(_partOffsetX)); - persistMgr->transfer(TMEMBER(_partOffsetY)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::updateSounds() { - if (_sentence && _sentence->_sound) { - updateOneSound(_sentence->_sound); - } - - return BaseObject::updateSounds(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::resetSoundPan() { - if (_sentence && _sentence->_sound) { - _sentence->_sound->setPan(0.0f); - } - return BaseObject::resetSoundPan(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::getExtendedFlag(const char *flagName) { - if (!flagName) { - return false; - } else if (strcmp(flagName, "usable") == 0) { - return true; - } else { - return BaseObject::getExtendedFlag(flagName); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::saveAsText(BaseDynamicBuffer *buffer, int indent) { - if (_blockRegion) { - _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); - } - if (_wptGroup) { - _wptGroup->saveAsText(buffer, indent + 2); - } - - BaseClass::saveAsText(buffer, indent + 2); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::updateBlockRegion() { - AdGame *adGame = (AdGame *)_gameRef; - if (adGame->_scene) { - if (_blockRegion && _currentBlockRegion) { - _currentBlockRegion->mimic(_blockRegion, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); - } - - if (_wptGroup && _currentWptGroup) { - _currentWptGroup->mimic(_wptGroup, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -AdInventory *AdObject::getInventory() { - if (!_inventory) { - _inventory = new AdInventory(_gameRef); - ((AdGame *)_gameRef)->registerInventory(_inventory); - } - return _inventory; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::afterMove() { - AdRegion *newRegions[MAX_NUM_REGIONS]; - - ((AdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); - for (int i = 0; i < MAX_NUM_REGIONS; i++) { - if (!newRegions[i]) { - break; - } - bool regFound = false; - for (int j = 0; j < MAX_NUM_REGIONS; j++) { - if (_currentRegions[j] == newRegions[i]) { - _currentRegions[j] = NULL; - regFound = true; - break; - } - } - if (!regFound) { - newRegions[i]->applyEvent("ActorEntry"); - } - } - - for (int i = 0; i < MAX_NUM_REGIONS; i++) { - if (_currentRegions[i] && _gameRef->validObject(_currentRegions[i])) { - _currentRegions[i]->applyEvent("ActorLeave"); - } - _currentRegions[i] = newRegions[i]; - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdObject::invalidateCurrRegions() { - for (int i = 0; i < MAX_NUM_REGIONS; i++) { - _currentRegions[i] = NULL; - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdObject::getScale(float *scaleX, float *scaleY) { - if (_zoomable) { - if (_scaleX >= 0 || _scaleY >= 0) { - *scaleX = _scaleX < 0 ? 100 : _scaleX; - *scaleY = _scaleY < 0 ? 100 : _scaleY; - } else if (_scale >= 0) { - *scaleX = *scaleY = _scale; - } else { - *scaleX = *scaleY = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; - } - } else { - *scaleX = *scaleY = 100; - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdObject::updateSpriteAttachments() { - for (uint32 i = 0; i < _attachmentsPre.size(); i++) { - _attachmentsPre[i]->update(); - } - for (uint32 i = 0; i < _attachmentsPost.size(); i++) { - _attachmentsPost[i]->update(); - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdObject::displaySpriteAttachments(bool preDisplay) { - if (preDisplay) { - for (uint32 i = 0; i < _attachmentsPre.size(); i++) { - displaySpriteAttachment(_attachmentsPre[i]); - } - } else { - for (uint32 i = 0; i < _attachmentsPost.size(); i++) { - displaySpriteAttachment(_attachmentsPost[i]); - } - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdObject::displaySpriteAttachment(AdObject *attachment) { - if (!attachment->_active) { - return STATUS_OK; - } - - float scaleX, scaleY; - getScale(&scaleX, &scaleY); - - int origX = attachment->_posX; - int origY = attachment->_posY; - - // inherit position from owner - attachment->_posX = (int)(this->_posX + attachment->_posX * scaleX / 100.0f); - attachment->_posY = (int)(this->_posY + attachment->_posY * scaleY / 100.0f); - - // inherit other props - attachment->_alphaColor = this->_alphaColor; - attachment->_blendMode = this->_blendMode; - - attachment->_scale = this->_scale; - attachment->_relativeScale = this->_relativeScale; - attachment->_scaleX = this->_scaleX; - attachment->_scaleY = this->_scaleY; - - attachment->_rotate = this->_rotate; - attachment->_relativeRotate = this->_relativeRotate; - attachment->_rotateValid = this->_rotateValid; - - attachment->_registerAlias = this; - attachment->_registrable = this->_registrable; - - bool ret = attachment->display(); - - attachment->_posX = origX; - attachment->_posY = origY; - - return ret; -} - -////////////////////////////////////////////////////////////////////////// -PartEmitter *AdObject::createParticleEmitter(bool followParent, int offsetX, int offsetY) { - _partFollowParent = followParent; - _partOffsetX = offsetX; - _partOffsetY = offsetY; - - if (!_partEmitter) { - _partEmitter = new PartEmitter(_gameRef, this); - if (_partEmitter) { - _gameRef->registerObject(_partEmitter); - } - } - updatePartEmitter(); - return _partEmitter; -} - -////////////////////////////////////////////////////////////////////////// -bool AdObject::updatePartEmitter() { - if (!_partEmitter) { - return STATUS_FAILED; - } - - if (_partFollowParent) { - float scaleX, scaleY; - getScale(&scaleX, &scaleY); - - _partEmitter->_posX = (int)(_posX + (scaleX / 100.0f) * _partOffsetX); - _partEmitter->_posY = (int)(_posY + (scaleY / 100.0f) * _partOffsetY); - } - return _partEmitter->update(); -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_item.h" +#include "engines/wintermute/ad/ad_object.h" +#include "engines/wintermute/ad/ad_inventory.h" +#include "engines/wintermute/ad/ad_layer.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/ad/ad_scene_node.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_frame.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/base/base_sub_frame.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_string_table.h" +#include "engines/wintermute/base/scriptables/script_engine.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/particles/part_emitter.h" +#include "common/str.h" +#include "common/util.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdObject, false) + +////////////////////////////////////////////////////////////////////////// +AdObject::AdObject(BaseGame *inGame) : BaseObject(inGame) { + _type = OBJECT_NONE; + _state = _nextState = STATE_NONE; + + _active = true; + _drawn = false; + + _currentSprite = NULL; + _animSprite = NULL; + _tempSprite2 = NULL; + + _font = NULL; + + _sentence = NULL; + + _forcedTalkAnimName = NULL; + _forcedTalkAnimUsed = false; + + _blockRegion = NULL; + _wptGroup = NULL; + + _currentBlockRegion = NULL; + _currentWptGroup = NULL; + + _ignoreItems = false; + _sceneIndependent = false; + + _stickRegion = NULL; + + _subtitlesModRelative = true; + _subtitlesModX = 0; + _subtitlesModY = 0; + _subtitlesWidth = 0; + _subtitlesModXCenter = true; + + _inventory = NULL; + + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + _currentRegions[i] = NULL; + } + + _partEmitter = NULL; + _partFollowParent = false; + _partOffsetX = _partOffsetY = 0; + + _registerAlias = this; +} + + +////////////////////////////////////////////////////////////////////////// +AdObject::~AdObject() { + _currentSprite = NULL; // reference only, don't delete + delete _animSprite; + _animSprite = NULL; + delete _sentence; + _sentence = NULL; + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = NULL; + + delete _blockRegion; + _blockRegion = NULL; + delete _wptGroup; + _wptGroup = NULL; + + delete _currentBlockRegion; + _currentBlockRegion = NULL; + delete _currentWptGroup; + _currentWptGroup = NULL; + + _tempSprite2 = NULL; // reference only + _stickRegion = NULL; + + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } + + if (_inventory) { + ((AdGame *)_gameRef)->unregisterInventory(_inventory); + _inventory = NULL; + } + + if (_partEmitter) { + _gameRef->unregisterObject(_partEmitter); + } + + + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { + _gameRef->unregisterObject(_attachmentsPre[i]); + } + _attachmentsPre.clear(); + + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { + _gameRef->unregisterObject(_attachmentsPost[i]); + } + _attachmentsPost.clear(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::playAnim(const char *filename) { + delete _animSprite; + _animSprite = NULL; + _animSprite = new BaseSprite(_gameRef, this); + if (!_animSprite) { + _gameRef->LOG(0, "AdObject::PlayAnim: error creating temp sprite (object:\"%s\" sprite:\"%s\")", getName(), filename); + return STATUS_FAILED; + } + bool res = _animSprite->loadFile(filename); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "AdObject::PlayAnim: error loading temp sprite (object:\"%s\" sprite:\"%s\")", getName(), filename); + delete _animSprite; + _animSprite = NULL; + return res; + } + _state = STATE_PLAYING_ANIM; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::display() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::update() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + + ////////////////////////////////////////////////////////////////////////// + // PlayAnim / PlayAnimAsync + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "PlayAnim") == 0 || strcmp(name, "PlayAnimAsync") == 0) { + stack->correctParams(1); + if (DID_FAIL(playAnim(stack->pop()->getString()))) { + stack->pushBool(false); + } else { + if (strcmp(name, "PlayAnimAsync") != 0) { + script->waitFor(this); + } + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Reset + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Reset") == 0) { + stack->correctParams(0); + reset(); + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsTalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsTalking") == 0) { + stack->correctParams(0); + stack->pushBool(_state == STATE_TALKING); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StopTalk / StopTalking + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StopTalk") == 0 || strcmp(name, "StopTalking") == 0) { + stack->correctParams(0); + if (_sentence) { + _sentence->finish(); + } + if (_state == STATE_TALKING) { + _state = _nextState; + _nextState = STATE_READY; + stack->pushBool(true); + } else { + stack->pushBool(false); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ForceTalkAnim + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ForceTalkAnim") == 0) { + stack->correctParams(1); + const char *animName = stack->pop()->getString(); + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = new char[strlen(animName) + 1]; + strcpy(_forcedTalkAnimName, animName); + _forcedTalkAnimUsed = false; + stack->pushBool(true); + return STATUS_OK; + } + + + ////////////////////////////////////////////////////////////////////////// + // Talk / TalkAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Talk") == 0 || strcmp(name, "TalkAsync") == 0) { + stack->correctParams(5); + + const char *text = stack->pop()->getString(); + ScValue *soundVal = stack->pop(); + int duration = stack->pop()->getInt(); + ScValue *valStances = stack->pop(); + + const char *stances = valStances->isNULL() ? NULL : valStances->getString(); + + int align = 0; + ScValue *val = stack->pop(); + if (val->isNULL()) { + align = TAL_CENTER; + } else { + align = val->getInt(); + } + + align = MIN(MAX(0, align), NUM_TEXT_ALIGN - 1); + + const char *sound = soundVal->isNULL() ? NULL : soundVal->getString(); + + talk(text, sound, duration, stances, (TTextAlign)align); + if (strcmp(name, "TalkAsync") != 0) { + script->waitForExclusive(this); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // StickToRegion + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "StickToRegion") == 0) { + stack->correctParams(1); + + AdLayer *main = ((AdGame *)_gameRef)->_scene->_mainLayer; + bool regFound = false; + + uint32 i; + ScValue *val = stack->pop(); + if (val->isNULL() || !main) { + _stickRegion = NULL; + regFound = true; + } else if (val->isString()) { + const char *regionName = val->getString(); + for (i = 0; i < main->_nodes.size(); i++) { + if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region->getName() && scumm_stricmp(main->_nodes[i]->_region->getName(), regionName) == 0) { + _stickRegion = main->_nodes[i]->_region; + regFound = true; + break; + } + } + } else if (val->isNative()) { + BaseScriptable *obj = val->getNative(); + + for (i = 0; i < main->_nodes.size(); i++) { + if (main->_nodes[i]->_type == OBJECT_REGION && main->_nodes[i]->_region == obj) { + _stickRegion = main->_nodes[i]->_region; + regFound = true; + break; + } + } + + } + + if (!regFound) { + _stickRegion = NULL; + } + stack->pushBool(regFound); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetFont + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetFont") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + if (val->isNULL()) { + setFont(NULL); + } else { + setFont(val->getString()); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFont + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFont") == 0) { + stack->correctParams(0); + if (_font && _font->getFilename()) { + stack->pushString(_font->getFilename()); + } else { + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // TakeItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "TakeItem") == 0) { + stack->correctParams(2); + + if (!_inventory) { + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); + } + + ScValue *val = stack->pop(); + if (!val->isNULL()) { + const char *itemName = val->getString(); + val = stack->pop(); + const char *insertAfter = val->isNULL() ? NULL : val->getString(); + if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) { + script->runtimeError("Cannot add item '%s' to inventory", itemName); + } else { + // hide associated entities + ((AdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); + } + + } else { + script->runtimeError("TakeItem: item name expected"); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DropItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DropItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); + } + + ScValue *val = stack->pop(); + if (!val->isNULL()) { + if (DID_FAIL(_inventory->removeItem(val->getString()))) { + script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); + } else { + // show associated entities + ((AdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); + } + } else { + script->runtimeError("DropItem: item name expected"); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); + } + + ScValue *val = stack->pop(); + if (val->_type == VAL_STRING) { + AdItem *item = ((AdGame *)_gameRef)->getItemByName(val->getString()); + if (item) { + stack->pushNative(item, true); + } else { + stack->pushNULL(); + } + } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= (int32)_inventory->_takenItems.size()) { + stack->pushNULL(); + } else { + stack->pushNative(_inventory->_takenItems[val->getInt()], true); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // HasItem + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "HasItem") == 0) { + stack->correctParams(1); + + if (!_inventory) { + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); + } + + ScValue *val = stack->pop(); + if (!val->isNULL()) { + for (uint32 i = 0; i < _inventory->_takenItems.size(); i++) { + if (val->getNative() == _inventory->_takenItems[i]) { + stack->pushBool(true); + return STATUS_OK; + } else if (scumm_stricmp(val->getString(), _inventory->_takenItems[i]->getName()) == 0) { + stack->pushBool(true); + return STATUS_OK; + } + } + } else { + script->runtimeError("HasItem: item name expected"); + } + + stack->pushBool(false); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateParticleEmitter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateParticleEmitter") == 0) { + stack->correctParams(3); + bool followParent = stack->pop()->getBool(); + int offsetX = stack->pop()->getInt(); + int offsetY = stack->pop()->getInt(); + + PartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); + if (emitter) { + stack->pushNative(_partEmitter, true); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteParticleEmitter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteParticleEmitter") == 0) { + stack->correctParams(0); + if (_partEmitter) { + _gameRef->unregisterObject(_partEmitter); + _partEmitter = NULL; + } + stack->pushNULL(); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddAttachment") == 0) { + stack->correctParams(4); + const char *filename = stack->pop()->getString(); + bool preDisplay = stack->pop()->getBool(true); + int offsetX = stack->pop()->getInt(); + int offsetY = stack->pop()->getInt(); + + bool res; + AdEntity *ent = new AdEntity(_gameRef); + if (DID_FAIL(res = ent->loadFile(filename))) { + delete ent; + ent = NULL; + script->runtimeError("AddAttachment() failed loading entity '%s'", filename); + stack->pushBool(false); + } else { + _gameRef->registerObject(ent); + + ent->_posX = offsetX; + ent->_posY = offsetY; + ent->_active = true; + + if (preDisplay) { + _attachmentsPre.add(ent); + } else { + _attachmentsPost.add(ent); + } + + stack->pushBool(true); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveAttachment") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + bool found = false; + if (val->isNative()) { + BaseScriptable *obj = val->getNative(); + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { + if (_attachmentsPre[i] == obj) { + found = true; + _gameRef->unregisterObject(_attachmentsPre[i]); + _attachmentsPre.remove_at(i); + i--; + } + } + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { + if (_attachmentsPost[i] == obj) { + found = true; + _gameRef->unregisterObject(_attachmentsPost[i]); + _attachmentsPost.remove_at(i); + i--; + } + } + } else { + const char *attachmentName = val->getString(); + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { + if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { + found = true; + _gameRef->unregisterObject(_attachmentsPre[i]); + _attachmentsPre.remove_at(i); + i--; + } + } + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { + if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { + found = true; + _gameRef->unregisterObject(_attachmentsPost[i]); + _attachmentsPost.remove_at(i); + i--; + } + } + } + stack->pushBool(found); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetAttachment + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetAttachment") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdObject *ret = NULL; + if (val->isInt()) { + int index = val->getInt(); + int currIndex = 0; + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { + if (currIndex == index) { + ret = _attachmentsPre[i]; + } + currIndex++; + } + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { + if (currIndex == index) { + ret = _attachmentsPost[i]; + } + currIndex++; + } + } else { + const char *attachmentName = val->getString(); + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { + if (_attachmentsPre[i]->getName() && scumm_stricmp(_attachmentsPre[i]->getName(), attachmentName) == 0) { + ret = _attachmentsPre[i]; + break; + } + } + if (!ret) { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { + if (_attachmentsPost[i]->getName() && scumm_stricmp(_attachmentsPost[i]->getName(), attachmentName) == 0) { + ret = _attachmentsPre[i]; + break; + } + } + } + } + + if (ret != NULL) { + stack->pushNative(ret, true); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdObject::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("object"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // IgnoreItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IgnoreItems") == 0) { + _scValue->setBool(_ignoreItems); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SceneIndependent + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SceneIndependent") == 0) { + _scValue->setBool(_sceneIndependent); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesWidth + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesWidth") == 0) { + _scValue->setInt(_subtitlesWidth); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosRelative + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosRelative") == 0) { + _scValue->setBool(_subtitlesModRelative); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosX") == 0) { + _scValue->setInt(_subtitlesModX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosY") == 0) { + _scValue->setInt(_subtitlesModY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosXCenter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosXCenter") == 0) { + _scValue->setBool(_subtitlesModXCenter); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumItems (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumItems") == 0) { + _scValue->setInt(getInventory()->_takenItems.size()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ParticleEmitter (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ParticleEmitter") == 0) { + if (_partEmitter) { + _scValue->setNative(_partEmitter, true); + } else { + _scValue->setNULL(); + } + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumAttachments (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumAttachments") == 0) { + _scValue->setInt(_attachmentsPre.size() + _attachmentsPost.size()); + return _scValue; + } else { + return BaseObject::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::scSetProperty(const char *name, ScValue *value) { + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Active") == 0) { + _active = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IgnoreItems + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IgnoreItems") == 0) { + _ignoreItems = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SceneIndependent + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SceneIndependent") == 0) { + _sceneIndependent = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesWidth + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesWidth") == 0) { + _subtitlesWidth = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosRelative + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosRelative") == 0) { + _subtitlesModRelative = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosX") == 0) { + _subtitlesModX = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosY") == 0) { + _subtitlesModY = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SubtitlesPosXCenter + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SubtitlesPosXCenter") == 0) { + _subtitlesModXCenter = value->getBool(); + return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdObject::scToString() { + return "[ad object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::setFont(const char *filename) { + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } + if (filename) { + _font = _gameRef->_fontStorage->addFont(filename); + return _font == NULL ? STATUS_FAILED : STATUS_OK; + } else { + _font = NULL; + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +int AdObject::getHeight() { + if (!_currentSprite) { + return 0; + } else { + BaseFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; + int ret = 0; + for (uint32 i = 0; i < frame->_subframes.size(); i++) { + ret = MAX(ret, frame->_subframes[i]->_hotspotY); + } + + if (_zoomable) { + float zoom = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY); + ret = (int)(ret * zoom / 100); + } + return ret; + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { + if (!_sentence) { + _sentence = new AdSentence(_gameRef); + } + if (!_sentence) { + return; + } + + if (_forcedTalkAnimName && _forcedTalkAnimUsed) { + delete[] _forcedTalkAnimName; + _forcedTalkAnimName = NULL; + _forcedTalkAnimUsed = false; + } + + delete(_sentence->_sound); + _sentence->_sound = NULL; + + _sentence->setText(text); + _gameRef->_stringTable->expand(&_sentence->_text); + _sentence->setStances(stances); + _sentence->_duration = duration; + _sentence->_align = Align; + _sentence->_startTime = _gameRef->_timer; + _sentence->_currentStance = -1; + _sentence->_font = _font == NULL ? _gameRef->_systemFont : _font; + _sentence->_freezable = _freezable; + + // try to locate speech file automatically + bool deleteSound = false; + if (!sound) { + char *key = _gameRef->_stringTable->getKey(text); + if (key) { + sound = ((AdGame *)_gameRef)->findSpeechFile(key); + delete[] key; + + if (sound) { + deleteSound = true; + } + } + } + + // load sound and set duration appropriately + if (sound) { + BaseSound *snd = new BaseSound(_gameRef); + if (snd && DID_SUCCEED(snd->setSound(sound, Audio::Mixer::kSpeechSoundType, true))) { + _sentence->setSound(snd); + if (_sentence->_duration <= 0) { + uint32 length = snd->getLength(); + if (length != 0) { + _sentence->_duration = length; + } + } + } else { + delete snd; + } + } + + // set duration by text length + if (_sentence->_duration <= 0) {// TODO: Avoid longs. + _sentence->_duration = MAX((size_t)1000, _gameRef->_subtitlesSpeed * strlen(_sentence->_text)); + } + + + int x, y, width, height; + + x = _posX; + y = _posY; + + if (!_sceneIndependent && _subtitlesModRelative) { + x -= ((AdGame *)_gameRef)->_scene->getOffsetLeft(); + y -= ((AdGame *)_gameRef)->_scene->getOffsetTop(); + } + + + if (_subtitlesWidth > 0) { + width = _subtitlesWidth; + } else { + if ((x < _gameRef->_renderer->_width / 4 || x > _gameRef->_renderer->_width * 0.75) && !_gameRef->_touchInterface) { + width = MAX(_gameRef->_renderer->_width / 4, MIN(x * 2, (_gameRef->_renderer->_width - x) * 2)); + } else { + width = _gameRef->_renderer->_width / 2; + } + } + + height = _sentence->_font->getTextHeight((byte *)_sentence->_text, width); + + y = y - height - getHeight() - 5; + if (_subtitlesModRelative) { + x += _subtitlesModX; + y += _subtitlesModY; + } else { + x = _subtitlesModX; + y = _subtitlesModY; + } + if (_subtitlesModXCenter) { + x = x - width / 2; + } + + + x = MIN(MAX(0, x), _gameRef->_renderer->_width - width); + y = MIN(MAX(0, y), _gameRef->_renderer->_height - height); + + _sentence->_width = width; + + + _sentence->_pos.x = x; + _sentence->_pos.y = y; + + + if (_subtitlesModRelative) { + _sentence->_pos.x += ((AdGame *)_gameRef)->_scene->getOffsetLeft(); + _sentence->_pos.y += ((AdGame *)_gameRef)->_scene->getOffsetTop(); + } + + _sentence->_fixedPos = !_subtitlesModRelative; + + + _sentence->setupTalkFile(sound); + + _state = STATE_TALKING; + + if (deleteSound) { + delete[] sound; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::reset() { + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL) { + delete _animSprite; + _animSprite = NULL; + } else if (_state == STATE_TALKING && _sentence) { + _sentence->finish(); + } + + _state = _nextState = STATE_READY; + + _gameRef->_scEngine->resetObject(this); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::persist(BasePersistenceManager *persistMgr) { + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_blockRegion)); + persistMgr->transfer(TMEMBER(_currentBlockRegion)); + persistMgr->transfer(TMEMBER(_currentWptGroup)); + persistMgr->transfer(TMEMBER(_currentSprite)); + persistMgr->transfer(TMEMBER(_drawn)); + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_ignoreItems)); + persistMgr->transfer(TMEMBER_INT(_nextState)); + persistMgr->transfer(TMEMBER(_sentence)); + persistMgr->transfer(TMEMBER_INT(_state)); + persistMgr->transfer(TMEMBER(_animSprite)); + persistMgr->transfer(TMEMBER(_sceneIndependent)); + persistMgr->transfer(TMEMBER(_forcedTalkAnimName)); + persistMgr->transfer(TMEMBER(_forcedTalkAnimUsed)); + persistMgr->transfer(TMEMBER(_tempSprite2)); + persistMgr->transfer(TMEMBER_INT(_type)); + persistMgr->transfer(TMEMBER(_wptGroup)); + persistMgr->transfer(TMEMBER(_stickRegion)); + persistMgr->transfer(TMEMBER(_subtitlesModRelative)); + persistMgr->transfer(TMEMBER(_subtitlesModX)); + persistMgr->transfer(TMEMBER(_subtitlesModY)); + persistMgr->transfer(TMEMBER(_subtitlesModXCenter)); + persistMgr->transfer(TMEMBER(_subtitlesWidth)); + persistMgr->transfer(TMEMBER(_inventory)); + persistMgr->transfer(TMEMBER(_partEmitter)); + + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + persistMgr->transfer(TMEMBER(_currentRegions[i])); + } + + _attachmentsPre.persist(persistMgr); + _attachmentsPost.persist(persistMgr); + persistMgr->transfer(TMEMBER(_registerAlias)); + + persistMgr->transfer(TMEMBER(_partFollowParent)); + persistMgr->transfer(TMEMBER(_partOffsetX)); + persistMgr->transfer(TMEMBER(_partOffsetY)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::updateSounds() { + if (_sentence && _sentence->_sound) { + updateOneSound(_sentence->_sound); + } + + return BaseObject::updateSounds(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::resetSoundPan() { + if (_sentence && _sentence->_sound) { + _sentence->_sound->setPan(0.0f); + } + return BaseObject::resetSoundPan(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::getExtendedFlag(const char *flagName) { + if (!flagName) { + return false; + } else if (strcmp(flagName, "usable") == 0) { + return true; + } else { + return BaseObject::getExtendedFlag(flagName); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::saveAsText(BaseDynamicBuffer *buffer, int indent) { + if (_blockRegion) { + _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); + } + if (_wptGroup) { + _wptGroup->saveAsText(buffer, indent + 2); + } + + BaseClass::saveAsText(buffer, indent + 2); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::updateBlockRegion() { + AdGame *adGame = (AdGame *)_gameRef; + if (adGame->_scene) { + if (_blockRegion && _currentBlockRegion) { + _currentBlockRegion->mimic(_blockRegion, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + } + + if (_wptGroup && _currentWptGroup) { + _currentWptGroup->mimic(_wptGroup, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +AdInventory *AdObject::getInventory() { + if (!_inventory) { + _inventory = new AdInventory(_gameRef); + ((AdGame *)_gameRef)->registerInventory(_inventory); + } + return _inventory; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::afterMove() { + AdRegion *newRegions[MAX_NUM_REGIONS]; + + ((AdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + if (!newRegions[i]) { + break; + } + bool regFound = false; + for (int j = 0; j < MAX_NUM_REGIONS; j++) { + if (_currentRegions[j] == newRegions[i]) { + _currentRegions[j] = NULL; + regFound = true; + break; + } + } + if (!regFound) { + newRegions[i]->applyEvent("ActorEntry"); + } + } + + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + if (_currentRegions[i] && _gameRef->validObject(_currentRegions[i])) { + _currentRegions[i]->applyEvent("ActorLeave"); + } + _currentRegions[i] = newRegions[i]; + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdObject::invalidateCurrRegions() { + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + _currentRegions[i] = NULL; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdObject::getScale(float *scaleX, float *scaleY) { + if (_zoomable) { + if (_scaleX >= 0 || _scaleY >= 0) { + *scaleX = _scaleX < 0 ? 100 : _scaleX; + *scaleY = _scaleY < 0 ? 100 : _scaleY; + } else if (_scale >= 0) { + *scaleX = *scaleY = _scale; + } else { + *scaleX = *scaleY = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; + } + } else { + *scaleX = *scaleY = 100; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdObject::updateSpriteAttachments() { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { + _attachmentsPre[i]->update(); + } + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { + _attachmentsPost[i]->update(); + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdObject::displaySpriteAttachments(bool preDisplay) { + if (preDisplay) { + for (uint32 i = 0; i < _attachmentsPre.size(); i++) { + displaySpriteAttachment(_attachmentsPre[i]); + } + } else { + for (uint32 i = 0; i < _attachmentsPost.size(); i++) { + displaySpriteAttachment(_attachmentsPost[i]); + } + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdObject::displaySpriteAttachment(AdObject *attachment) { + if (!attachment->_active) { + return STATUS_OK; + } + + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + int origX = attachment->_posX; + int origY = attachment->_posY; + + // inherit position from owner + attachment->_posX = (int)(this->_posX + attachment->_posX * scaleX / 100.0f); + attachment->_posY = (int)(this->_posY + attachment->_posY * scaleY / 100.0f); + + // inherit other props + attachment->_alphaColor = this->_alphaColor; + attachment->_blendMode = this->_blendMode; + + attachment->_scale = this->_scale; + attachment->_relativeScale = this->_relativeScale; + attachment->_scaleX = this->_scaleX; + attachment->_scaleY = this->_scaleY; + + attachment->_rotate = this->_rotate; + attachment->_relativeRotate = this->_relativeRotate; + attachment->_rotateValid = this->_rotateValid; + + attachment->_registerAlias = this; + attachment->_registrable = this->_registrable; + + bool ret = attachment->display(); + + attachment->_posX = origX; + attachment->_posY = origY; + + return ret; +} + +////////////////////////////////////////////////////////////////////////// +PartEmitter *AdObject::createParticleEmitter(bool followParent, int offsetX, int offsetY) { + _partFollowParent = followParent; + _partOffsetX = offsetX; + _partOffsetY = offsetY; + + if (!_partEmitter) { + _partEmitter = new PartEmitter(_gameRef, this); + if (_partEmitter) { + _gameRef->registerObject(_partEmitter); + } + } + updatePartEmitter(); + return _partEmitter; +} + +////////////////////////////////////////////////////////////////////////// +bool AdObject::updatePartEmitter() { + if (!_partEmitter) { + return STATUS_FAILED; + } + + if (_partFollowParent) { + float scaleX, scaleY; + getScale(&scaleX, &scaleY); + + _partEmitter->_posX = (int)(_posX + (scaleX / 100.0f) * _partOffsetX); + _partEmitter->_posY = (int)(_posY + (scaleY / 100.0f) * _partOffsetY); + } + return _partEmitter->update(); +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h index 9451707445..8395f58cff 100644 --- a/engines/wintermute/ad/ad_object.h +++ b/engines/wintermute/ad/ad_object.h @@ -1,124 +1,124 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADOBJECT_H -#define WINTERMUTE_ADOBJECT_H - -#include "engines/wintermute/ad/ad_types.h" -#include "engines/wintermute/base/base_object.h" - -namespace Wintermute { - -class AdWaypointGroup; -class AdRegion; -class AdSentence; -class BaseFont; -class BaseRegion; -class AdInventory; -class PartEmitter; - -#define MAX_NUM_REGIONS 10 - -class AdObject : public BaseObject { -public: - PartEmitter *_partEmitter; - virtual PartEmitter *createParticleEmitter(bool followParent = false, int offsetX = 0, int offsetY = 0); - virtual bool updatePartEmitter(); - bool _partFollowParent; - int _partOffsetX; - int _partOffsetY; - - bool invalidateCurrRegions(); - bool _subtitlesModRelative; - bool _subtitlesModXCenter; - int _subtitlesModX; - int _subtitlesModY; - int _subtitlesWidth; - AdRegion *_stickRegion; - bool _sceneIndependent; - bool _ignoreItems; - bool updateBlockRegion(); - bool _forcedTalkAnimUsed; - char *_forcedTalkAnimName; - virtual bool getExtendedFlag(const char *flagName); - virtual bool resetSoundPan(); - virtual bool updateSounds(); - bool reset(); - DECLARE_PERSISTENT(AdObject, BaseObject) - virtual void talk(const char *text, const char *sound = NULL, uint32 duration = 0, const char *stances = NULL, TTextAlign align = TAL_CENTER); - virtual int getHeight(); - AdSentence *_sentence; - bool setFont(const char *filename); - virtual bool update(); - virtual bool display(); - bool _drawn; - bool _active; - virtual bool playAnim(const char *filename); - BaseSprite *_animSprite; - BaseSprite *_currentSprite; - TObjectState _state; - TObjectState _nextState; - TObjectType _type; - AdObject(BaseGame *inGame); - virtual ~AdObject(); - BaseFont *_font; - BaseSprite *_tempSprite2; - BaseRegion *_blockRegion; - AdWaypointGroup *_wptGroup; - BaseRegion *_currentBlockRegion; - AdWaypointGroup *_currentWptGroup; - AdInventory *getInventory(); - - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - - virtual bool afterMove(); - AdRegion *_currentRegions[MAX_NUM_REGIONS]; - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - virtual const char *scToString(); - - BaseArray _attachmentsPre; - BaseArray _attachmentsPost; - - bool updateSpriteAttachments(); - bool displaySpriteAttachments(bool preDisplay); - AdObject *_registerAlias; -private: - bool displaySpriteAttachment(AdObject *attachment); - AdInventory *_inventory; - -protected: - bool getScale(float *scaleX, float *scaleY); -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADOBJECT_H +#define WINTERMUTE_ADOBJECT_H + +#include "engines/wintermute/ad/ad_types.h" +#include "engines/wintermute/base/base_object.h" + +namespace Wintermute { + +class AdWaypointGroup; +class AdRegion; +class AdSentence; +class BaseFont; +class BaseRegion; +class AdInventory; +class PartEmitter; + +#define MAX_NUM_REGIONS 10 + +class AdObject : public BaseObject { +public: + PartEmitter *_partEmitter; + virtual PartEmitter *createParticleEmitter(bool followParent = false, int offsetX = 0, int offsetY = 0); + virtual bool updatePartEmitter(); + bool _partFollowParent; + int _partOffsetX; + int _partOffsetY; + + bool invalidateCurrRegions(); + bool _subtitlesModRelative; + bool _subtitlesModXCenter; + int _subtitlesModX; + int _subtitlesModY; + int _subtitlesWidth; + AdRegion *_stickRegion; + bool _sceneIndependent; + bool _ignoreItems; + bool updateBlockRegion(); + bool _forcedTalkAnimUsed; + char *_forcedTalkAnimName; + virtual bool getExtendedFlag(const char *flagName); + virtual bool resetSoundPan(); + virtual bool updateSounds(); + bool reset(); + DECLARE_PERSISTENT(AdObject, BaseObject) + virtual void talk(const char *text, const char *sound = NULL, uint32 duration = 0, const char *stances = NULL, TTextAlign align = TAL_CENTER); + virtual int getHeight(); + AdSentence *_sentence; + bool setFont(const char *filename); + virtual bool update(); + virtual bool display(); + bool _drawn; + bool _active; + virtual bool playAnim(const char *filename); + BaseSprite *_animSprite; + BaseSprite *_currentSprite; + TObjectState _state; + TObjectState _nextState; + TObjectType _type; + AdObject(BaseGame *inGame); + virtual ~AdObject(); + BaseFont *_font; + BaseSprite *_tempSprite2; + BaseRegion *_blockRegion; + AdWaypointGroup *_wptGroup; + BaseRegion *_currentBlockRegion; + AdWaypointGroup *_currentWptGroup; + AdInventory *getInventory(); + + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + + virtual bool afterMove(); + AdRegion *_currentRegions[MAX_NUM_REGIONS]; + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + virtual const char *scToString(); + + BaseArray _attachmentsPre; + BaseArray _attachmentsPost; + + bool updateSpriteAttachments(); + bool displaySpriteAttachments(bool preDisplay); + AdObject *_registerAlias; +private: + bool displaySpriteAttachment(AdObject *attachment); + AdInventory *_inventory; + +protected: + bool getScale(float *scaleX, float *scaleY); +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index 21b68f4d48..c931213456 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -1,120 +1,120 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_path.h" -#include "engines/wintermute/base/base_point.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdPath, false) - -////////////////////////////////////////////////////////////////////////// -AdPath::AdPath(BaseGame *inGame) : BaseClass(inGame) { - _currIndex = -1; - _ready = false; -} - - -////////////////////////////////////////////////////////////////////////// -AdPath::~AdPath() { - reset(); -} - - -////////////////////////////////////////////////////////////////////////// -void AdPath::reset() { - for (uint32 i = 0; i < _points.size(); i++) { - delete _points[i]; - } - - _points.clear(); - _currIndex = -1; - _ready = false; -} - - -////////////////////////////////////////////////////////////////////////// -BasePoint *AdPath::getFirst() { - if (_points.size() > 0) { - _currIndex = 0; - return _points[_currIndex]; - } else { - return NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -BasePoint *AdPath::getNext() { - _currIndex++; - if (_currIndex < (int32)_points.size()) { - return _points[_currIndex]; - } else { - return NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -BasePoint *AdPath::getCurrent() { - if (_currIndex >= 0 && _currIndex < (int32)_points.size()) { - return _points[_currIndex]; - } else { - return NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdPath::addPoint(BasePoint *point) { - _points.add(point); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdPath::setReady(bool ready) { - bool orig = _ready; - _ready = ready; - - return orig; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdPath::persist(BasePersistenceManager *persistMgr) { - - persistMgr->transfer(TMEMBER(_gameRef)); - - persistMgr->transfer(TMEMBER(_currIndex)); - _points.persist(persistMgr); - persistMgr->transfer(TMEMBER(_ready)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_path.h" +#include "engines/wintermute/base/base_point.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdPath, false) + +////////////////////////////////////////////////////////////////////////// +AdPath::AdPath(BaseGame *inGame) : BaseClass(inGame) { + _currIndex = -1; + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +AdPath::~AdPath() { + reset(); +} + + +////////////////////////////////////////////////////////////////////////// +void AdPath::reset() { + for (uint32 i = 0; i < _points.size(); i++) { + delete _points[i]; + } + + _points.clear(); + _currIndex = -1; + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +BasePoint *AdPath::getFirst() { + if (_points.size() > 0) { + _currIndex = 0; + return _points[_currIndex]; + } else { + return NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +BasePoint *AdPath::getNext() { + _currIndex++; + if (_currIndex < (int32)_points.size()) { + return _points[_currIndex]; + } else { + return NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +BasePoint *AdPath::getCurrent() { + if (_currIndex >= 0 && _currIndex < (int32)_points.size()) { + return _points[_currIndex]; + } else { + return NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdPath::addPoint(BasePoint *point) { + _points.add(point); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdPath::setReady(bool ready) { + bool orig = _ready; + _ready = ready; + + return orig; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdPath::persist(BasePersistenceManager *persistMgr) { + + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER(_currIndex)); + _points.persist(persistMgr); + persistMgr->transfer(TMEMBER(_ready)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_path.h b/engines/wintermute/ad/ad_path.h index de115b261a..6b043197aa 100644 --- a/engines/wintermute/ad/ad_path.h +++ b/engines/wintermute/ad/ad_path.h @@ -1,56 +1,56 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADPATH_H -#define WINTERMUTE_ADPATH_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/coll_templ.h" -#include "engines/wintermute/base/base.h" - -namespace Wintermute { -class BasePoint; -class AdPath : public BaseClass { -public: - DECLARE_PERSISTENT(AdPath, BaseClass) - BasePoint *getCurrent(); - bool setReady(bool ready = true); - void addPoint(BasePoint *point); - BasePoint *getNext(); - BasePoint *getFirst(); - void reset(); - AdPath(BaseGame *inGame); - virtual ~AdPath(); - BaseArray _points; - int _currIndex; - bool _ready; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADPATH_H +#define WINTERMUTE_ADPATH_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/coll_templ.h" +#include "engines/wintermute/base/base.h" + +namespace Wintermute { +class BasePoint; +class AdPath : public BaseClass { +public: + DECLARE_PERSISTENT(AdPath, BaseClass) + BasePoint *getCurrent(); + bool setReady(bool ready = true); + void addPoint(BasePoint *point); + BasePoint *getNext(); + BasePoint *getFirst(); + void reset(); + AdPath(BaseGame *inGame); + virtual ~AdPath(); + BaseArray _points; + int _currIndex; + bool _ready; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_path_point.cpp b/engines/wintermute/ad/ad_path_point.cpp index 1fb954c668..a36648eb69 100644 --- a/engines/wintermute/ad/ad_path_point.cpp +++ b/engines/wintermute/ad/ad_path_point.cpp @@ -1,75 +1,75 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_path_point.h" -#include "engines/wintermute/base/base_persistence_manager.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdPathPoint, false) - -////////////////////////////////////////////////////////////////////////// -AdPathPoint::AdPathPoint() { - x = y = 0; - _distance = 0; - - _marked = false; - _origin = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdPathPoint::AdPathPoint(int initX, int initY, int initDistance) { - x = initX; - y = initY; - _distance = initDistance; - - _marked = false; - _origin = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdPathPoint::~AdPathPoint() { - _origin = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdPathPoint::persist(BasePersistenceManager *persistMgr) { - - BasePoint::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_distance)); - persistMgr->transfer(TMEMBER(_marked)); - persistMgr->transfer(TMEMBER(_origin)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_path_point.h" +#include "engines/wintermute/base/base_persistence_manager.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdPathPoint, false) + +////////////////////////////////////////////////////////////////////////// +AdPathPoint::AdPathPoint() { + x = y = 0; + _distance = 0; + + _marked = false; + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdPathPoint::AdPathPoint(int initX, int initY, int initDistance) { + x = initX; + y = initY; + _distance = initDistance; + + _marked = false; + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdPathPoint::~AdPathPoint() { + _origin = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdPathPoint::persist(BasePersistenceManager *persistMgr) { + + BasePoint::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_distance)); + persistMgr->transfer(TMEMBER(_marked)); + persistMgr->transfer(TMEMBER(_origin)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_path_point.h b/engines/wintermute/ad/ad_path_point.h index 8201750cef..58457976c8 100644 --- a/engines/wintermute/ad/ad_path_point.h +++ b/engines/wintermute/ad/ad_path_point.h @@ -1,50 +1,50 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADPATHPOINT_H -#define WINTERMUTE_ADPATHPOINT_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/base_point.h" - -namespace Wintermute { - -class AdPathPoint : public BasePoint { -public: - DECLARE_PERSISTENT(AdPathPoint, BasePoint) - AdPathPoint(int initX, int initY, int initDistance); - AdPathPoint(); - virtual ~AdPathPoint(); - AdPathPoint *_origin; - bool _marked; - int _distance; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADPATHPOINT_H +#define WINTERMUTE_ADPATHPOINT_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base_point.h" + +namespace Wintermute { + +class AdPathPoint : public BasePoint { +public: + DECLARE_PERSISTENT(AdPathPoint, BasePoint) + AdPathPoint(int initX, int initY, int initDistance); + AdPathPoint(); + virtual ~AdPathPoint(); + AdPathPoint *_origin; + bool _marked; + int _distance; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 3e5f91524d..88bd8201a2 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -1,397 +1,397 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_region.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_file_manager.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdRegion, false) - -////////////////////////////////////////////////////////////////////////// -AdRegion::AdRegion(BaseGame *inGame) : BaseRegion(inGame) { - _blocked = false; - _decoration = false; - _zoom = 0; - _alpha = 0xFFFFFFFF; -} - - -////////////////////////////////////////////////////////////////////////// -AdRegion::~AdRegion() { -} - - -////////////////////////////////////////////////////////////////////////// -bool AdRegion::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdRegion::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(REGION) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(NAME) -TOKEN_DEF(ACTIVE) -TOKEN_DEF(ZOOM) -TOKEN_DEF(SCALE) -TOKEN_DEF(BLOCKED) -TOKEN_DEF(DECORATION) -TOKEN_DEF(POINT) -TOKEN_DEF(ALPHA_COLOR) -TOKEN_DEF(ALPHA) -TOKEN_DEF(EDITOR_SELECTED_POINT) -TOKEN_DEF(EDITOR_SELECTED) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdRegion::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(REGION) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(NAME) - TOKEN_TABLE(ACTIVE) - TOKEN_TABLE(ZOOM) - TOKEN_TABLE(SCALE) - TOKEN_TABLE(BLOCKED) - TOKEN_TABLE(DECORATION) - TOKEN_TABLE(POINT) - TOKEN_TABLE(ALPHA_COLOR) - TOKEN_TABLE(ALPHA) - TOKEN_TABLE(EDITOR_SELECTED_POINT) - TOKEN_TABLE(EDITOR_SELECTED) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { - _gameRef->LOG(0, "'REGION' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - for (uint32 i = 0; i < _points.size(); i++) { - delete _points[i]; - } - _points.clear(); - - int ar = 255, ag = 255, ab = 255, alpha = 255; - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_ACTIVE: - parser.scanStr((char *)params, "%b", &_active); - break; - - case TOKEN_BLOCKED: - parser.scanStr((char *)params, "%b", &_blocked); - break; - - case TOKEN_DECORATION: - parser.scanStr((char *)params, "%b", &_decoration); - break; - - case TOKEN_ZOOM: - case TOKEN_SCALE: { - int j; - parser.scanStr((char *)params, "%d", &j); - _zoom = (float)j; - } - break; - - case TOKEN_POINT: { - int x, y; - parser.scanStr((char *)params, "%d,%d", &x, &y); - _points.add(new BasePoint(x, y)); - } - 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_SELECTED: - parser.scanStr((char *)params, "%b", &_editorSelected); - break; - - case TOKEN_EDITOR_SELECTED_POINT: - parser.scanStr((char *)params, "%d", &_editorSelectedPoint); - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in REGION definition"); - return STATUS_FAILED; - } - - createRegion(); - - _alpha = BYTETORGBA(ar, ag, ab, alpha); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - /* - ////////////////////////////////////////////////////////////////////////// - // SkipTo - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SkipTo")==0) { - stack->correctParams(2); - _posX = stack->pop()->getInt(); - _posY = stack->pop()->getInt(); - stack->pushNULL(); - - return STATUS_OK; - } - - else*/ return BaseRegion::scCallMethod(script, stack, thisStack, name); -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdRegion::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("ad region"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Name") == 0) { - _scValue->setString(getName()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Blocked - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Blocked") == 0) { - _scValue->setBool(_blocked); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Decoration - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Decoration") == 0) { - _scValue->setBool(_decoration); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Scale - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Scale") == 0) { - _scValue->setFloat(_zoom); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AlphaColor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AlphaColor") == 0) { - _scValue->setInt((int)_alpha); - return _scValue; - } else { - return BaseRegion::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdRegion::scSetProperty(const char *name, ScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Name") == 0) { - setName(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Blocked - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Blocked") == 0) { - _blocked = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Decoration - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Decoration") == 0) { - _decoration = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // Scale - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Scale") == 0) { - _zoom = value->getFloat(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AlphaColor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AlphaColor") == 0) { - _alpha = (uint32)value->getInt(); - return STATUS_OK; - } else { - return BaseRegion::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdRegion::scToString() { - return "[ad region]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdRegion::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "REGION {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - buffer->putTextIndent(indent + 2, "BLOCKED=%s\n", _blocked ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "DECORATION=%s\n", _decoration ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_zoom); - buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alpha), RGBCOLGetG(_alpha), RGBCOLGetB(_alpha)); - buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alpha)); - buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - - for (uint32 i = 0; i < _scripts.size(); i++) { - buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); - } - - if (_scProp) { - _scProp->saveAsText(buffer, indent + 2); - } - - for (uint32 i = 0; i < _points.size(); i++) { - buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); - } - - BaseClass::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdRegion::persist(BasePersistenceManager *persistMgr) { - BaseRegion::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_alpha)); - persistMgr->transfer(TMEMBER(_blocked)); - persistMgr->transfer(TMEMBER(_decoration)); - persistMgr->transfer(TMEMBER(_zoom)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_region.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdRegion, false) + +////////////////////////////////////////////////////////////////////////// +AdRegion::AdRegion(BaseGame *inGame) : BaseRegion(inGame) { + _blocked = false; + _decoration = false; + _zoom = 0; + _alpha = 0xFFFFFFFF; +} + + +////////////////////////////////////////////////////////////////////////// +AdRegion::~AdRegion() { +} + + +////////////////////////////////////////////////////////////////////////// +bool AdRegion::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdRegion::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(REGION) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(ACTIVE) +TOKEN_DEF(ZOOM) +TOKEN_DEF(SCALE) +TOKEN_DEF(BLOCKED) +TOKEN_DEF(DECORATION) +TOKEN_DEF(POINT) +TOKEN_DEF(ALPHA_COLOR) +TOKEN_DEF(ALPHA) +TOKEN_DEF(EDITOR_SELECTED_POINT) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdRegion::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(REGION) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(ACTIVE) + TOKEN_TABLE(ZOOM) + TOKEN_TABLE(SCALE) + TOKEN_TABLE(BLOCKED) + TOKEN_TABLE(DECORATION) + TOKEN_TABLE(POINT) + TOKEN_TABLE(ALPHA_COLOR) + TOKEN_TABLE(ALPHA) + TOKEN_TABLE(EDITOR_SELECTED_POINT) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_REGION) { + _gameRef->LOG(0, "'REGION' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + for (uint32 i = 0; i < _points.size(); i++) { + delete _points[i]; + } + _points.clear(); + + int ar = 255, ag = 255, ab = 255, alpha = 255; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_ACTIVE: + parser.scanStr((char *)params, "%b", &_active); + break; + + case TOKEN_BLOCKED: + parser.scanStr((char *)params, "%b", &_blocked); + break; + + case TOKEN_DECORATION: + parser.scanStr((char *)params, "%b", &_decoration); + break; + + case TOKEN_ZOOM: + case TOKEN_SCALE: { + int j; + parser.scanStr((char *)params, "%d", &j); + _zoom = (float)j; + } + break; + + case TOKEN_POINT: { + int x, y; + parser.scanStr((char *)params, "%d,%d", &x, &y); + _points.add(new BasePoint(x, y)); + } + 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_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_EDITOR_SELECTED_POINT: + parser.scanStr((char *)params, "%d", &_editorSelectedPoint); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in REGION definition"); + return STATUS_FAILED; + } + + createRegion(); + + _alpha = BYTETORGBA(ar, ag, ab, alpha); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + /* + ////////////////////////////////////////////////////////////////////////// + // SkipTo + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SkipTo")==0) { + stack->correctParams(2); + _posX = stack->pop()->getInt(); + _posY = stack->pop()->getInt(); + stack->pushNULL(); + + return STATUS_OK; + } + + else*/ return BaseRegion::scCallMethod(script, stack, thisStack, name); +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdRegion::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("ad region"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Name") == 0) { + _scValue->setString(getName()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Blocked + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Blocked") == 0) { + _scValue->setBool(_blocked); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Decoration + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Decoration") == 0) { + _scValue->setBool(_decoration); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Scale + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scale") == 0) { + _scValue->setFloat(_zoom); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AlphaColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AlphaColor") == 0) { + _scValue->setInt((int)_alpha); + return _scValue; + } else { + return BaseRegion::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdRegion::scSetProperty(const char *name, ScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Blocked + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Blocked") == 0) { + _blocked = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Decoration + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Decoration") == 0) { + _decoration = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // Scale + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Scale") == 0) { + _zoom = value->getFloat(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AlphaColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AlphaColor") == 0) { + _alpha = (uint32)value->getInt(); + return STATUS_OK; + } else { + return BaseRegion::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdRegion::scToString() { + return "[ad region]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdRegion::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "REGION {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + buffer->putTextIndent(indent + 2, "BLOCKED=%s\n", _blocked ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "DECORATION=%s\n", _decoration ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_zoom); + buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alpha), RGBCOLGetG(_alpha), RGBCOLGetB(_alpha)); + buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alpha)); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + + for (uint32 i = 0; i < _scripts.size(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } + + for (uint32 i = 0; i < _points.size(); i++) { + buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); + } + + BaseClass::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdRegion::persist(BasePersistenceManager *persistMgr) { + BaseRegion::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_alpha)); + persistMgr->transfer(TMEMBER(_blocked)); + persistMgr->transfer(TMEMBER(_decoration)); + persistMgr->transfer(TMEMBER(_zoom)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_region.h b/engines/wintermute/ad/ad_region.h index 5c33291a88..a60cb9a3f2 100644 --- a/engines/wintermute/ad/ad_region.h +++ b/engines/wintermute/ad/ad_region.h @@ -1,58 +1,58 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADREGION_H -#define WINTERMUTE_ADREGION_H - -#include "engines/wintermute/base/base_region.h" - -namespace Wintermute { - -class AdRegion : public BaseRegion { -public: - DECLARE_PERSISTENT(AdRegion, BaseRegion) - uint32 _alpha; - float _zoom; - bool _blocked; - bool _decoration; - AdRegion(BaseGame *inGame); - virtual ~AdRegion(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - virtual const char *scToString(); -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADREGION_H +#define WINTERMUTE_ADREGION_H + +#include "engines/wintermute/base/base_region.h" + +namespace Wintermute { + +class AdRegion : public BaseRegion { +public: + DECLARE_PERSISTENT(AdRegion, BaseRegion) + uint32 _alpha; + float _zoom; + bool _blocked; + bool _decoration; + AdRegion(BaseGame *inGame); + virtual ~AdRegion(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + virtual const char *scToString(); +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp index f7886bba5a..37f46118bf 100644 --- a/engines/wintermute/ad/ad_response.cpp +++ b/engines/wintermute/ad/ad_response.cpp @@ -1,146 +1,146 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_response.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/font/base_font_storage.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/utils/utils.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdResponse, false) - -////////////////////////////////////////////////////////////////////////// -AdResponse::AdResponse(BaseGame *inGame) : BaseObject(inGame) { - _text = NULL; - _textOrig = NULL; - _icon = _iconHover = _iconPressed = NULL; - _font = NULL; - _iD = 0; - _responseType = RESPONSE_ALWAYS; -} - - -////////////////////////////////////////////////////////////////////////// -AdResponse::~AdResponse() { - delete[] _text; - delete[] _textOrig; - delete _icon; - delete _iconHover; - delete _iconPressed; - _text = NULL; - _textOrig = NULL; - _icon = NULL; - _iconHover = NULL; - _iconPressed = NULL; - if (_font) { - _gameRef->_fontStorage->removeFont(_font); - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdResponse::setText(const char *text) { - BaseUtils::setString(&_text, text); - BaseUtils::setString(&_textOrig, text); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponse::setIcon(const char *filename) { - delete _icon; - _icon = new BaseSprite(_gameRef); - if (!_icon || DID_FAIL(_icon->loadFile(filename))) { - _gameRef->LOG(0, "AdResponse::setIcon failed for file '%s'", filename); - delete _icon; - _icon = NULL; - return STATUS_FAILED; - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdResponse::setFont(const char *filename) { - if (_font) { - _gameRef->_fontStorage->removeFont(_font); - } - _font = _gameRef->_fontStorage->addFont(filename); - if (!_font) { - _gameRef->LOG(0, "AdResponse::setFont failed for file '%s'", filename); - return STATUS_FAILED; - } - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdResponse::setIconHover(const char *filename) { - delete _iconHover; - _iconHover = new BaseSprite(_gameRef); - if (!_iconHover || DID_FAIL(_iconHover->loadFile(filename))) { - _gameRef->LOG(0, "AdResponse::setIconHover failed for file '%s'", filename); - delete _iconHover; - _iconHover = NULL; - return STATUS_FAILED; - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponse::setIconPressed(const char *filename) { - delete _iconPressed; - _iconPressed = new BaseSprite(_gameRef); - if (!_iconPressed || DID_FAIL(_iconPressed->loadFile(filename))) { - _gameRef->LOG(0, "AdResponse::setIconPressed failed for file '%s'", filename); - delete _iconPressed; - _iconPressed = NULL; - return STATUS_FAILED; - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponse::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_icon)); - persistMgr->transfer(TMEMBER(_iconHover)); - persistMgr->transfer(TMEMBER(_iconPressed)); - persistMgr->transfer(TMEMBER(_iD)); - persistMgr->transfer(TMEMBER(_text)); - persistMgr->transfer(TMEMBER(_textOrig)); - persistMgr->transfer(TMEMBER_INT(_responseType)); - persistMgr->transfer(TMEMBER(_font)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_response.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/utils/utils.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdResponse, false) + +////////////////////////////////////////////////////////////////////////// +AdResponse::AdResponse(BaseGame *inGame) : BaseObject(inGame) { + _text = NULL; + _textOrig = NULL; + _icon = _iconHover = _iconPressed = NULL; + _font = NULL; + _iD = 0; + _responseType = RESPONSE_ALWAYS; +} + + +////////////////////////////////////////////////////////////////////////// +AdResponse::~AdResponse() { + delete[] _text; + delete[] _textOrig; + delete _icon; + delete _iconHover; + delete _iconPressed; + _text = NULL; + _textOrig = NULL; + _icon = NULL; + _iconHover = NULL; + _iconPressed = NULL; + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdResponse::setText(const char *text) { + BaseUtils::setString(&_text, text); + BaseUtils::setString(&_textOrig, text); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponse::setIcon(const char *filename) { + delete _icon; + _icon = new BaseSprite(_gameRef); + if (!_icon || DID_FAIL(_icon->loadFile(filename))) { + _gameRef->LOG(0, "AdResponse::setIcon failed for file '%s'", filename); + delete _icon; + _icon = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdResponse::setFont(const char *filename) { + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } + _font = _gameRef->_fontStorage->addFont(filename); + if (!_font) { + _gameRef->LOG(0, "AdResponse::setFont failed for file '%s'", filename); + return STATUS_FAILED; + } + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdResponse::setIconHover(const char *filename) { + delete _iconHover; + _iconHover = new BaseSprite(_gameRef); + if (!_iconHover || DID_FAIL(_iconHover->loadFile(filename))) { + _gameRef->LOG(0, "AdResponse::setIconHover failed for file '%s'", filename); + delete _iconHover; + _iconHover = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponse::setIconPressed(const char *filename) { + delete _iconPressed; + _iconPressed = new BaseSprite(_gameRef); + if (!_iconPressed || DID_FAIL(_iconPressed->loadFile(filename))) { + _gameRef->LOG(0, "AdResponse::setIconPressed failed for file '%s'", filename); + delete _iconPressed; + _iconPressed = NULL; + return STATUS_FAILED; + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponse::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_icon)); + persistMgr->transfer(TMEMBER(_iconHover)); + persistMgr->transfer(TMEMBER(_iconPressed)); + persistMgr->transfer(TMEMBER(_iD)); + persistMgr->transfer(TMEMBER(_text)); + persistMgr->transfer(TMEMBER(_textOrig)); + persistMgr->transfer(TMEMBER_INT(_responseType)); + persistMgr->transfer(TMEMBER(_font)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_response.h b/engines/wintermute/ad/ad_response.h index 0678ef5a37..0ba88cf2e8 100644 --- a/engines/wintermute/ad/ad_response.h +++ b/engines/wintermute/ad/ad_response.h @@ -1,61 +1,61 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADRESPONSE_H -#define WINTERMUTE_ADRESPONSE_H - - -#include "engines/wintermute/base/base_object.h" -#include "engines/wintermute/ad/ad_types.h" - -namespace Wintermute { -class BaseFont; -class AdResponse : public BaseObject { -public: - DECLARE_PERSISTENT(AdResponse, BaseObject) - bool setIcon(const char *filename); - bool setFont(const char *filename); - bool setIconHover(const char *filename); - bool setIconPressed(const char *filename); - void setText(const char *text); - int _iD; - BaseSprite *_icon; - BaseSprite *_iconHover; - BaseSprite *_iconPressed; - BaseFont *_font; - char *_text; - char *_textOrig; - AdResponse(BaseGame *inGame); - virtual ~AdResponse(); - TResponseType _responseType; - -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSE_H +#define WINTERMUTE_ADRESPONSE_H + + +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/ad/ad_types.h" + +namespace Wintermute { +class BaseFont; +class AdResponse : public BaseObject { +public: + DECLARE_PERSISTENT(AdResponse, BaseObject) + bool setIcon(const char *filename); + bool setFont(const char *filename); + bool setIconHover(const char *filename); + bool setIconPressed(const char *filename); + void setText(const char *text); + int _iD; + BaseSprite *_icon; + BaseSprite *_iconHover; + BaseSprite *_iconPressed; + BaseFont *_font; + char *_text; + char *_textOrig; + AdResponse(BaseGame *inGame); + virtual ~AdResponse(); + TResponseType _responseType; + +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 76510e2f3e..a27f1ca54b 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -1,712 +1,712 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_response_box.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_surface_storage.h" -#include "engines/wintermute/ui/ui_button.h" -#include "engines/wintermute/ui/ui_window.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/font/base_font_storage.h" -#include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/ad/ad_response.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/wintermute.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdResponseBox, false) - -////////////////////////////////////////////////////////////////////////// -AdResponseBox::AdResponseBox(BaseGame *inGame) : BaseObject(inGame) { - _font = _fontHover = NULL; - - _window = NULL; - _shieldWindow = new UIWindow(_gameRef); - - _horizontal = false; - BasePlatform::setRectEmpty(&_responseArea); - _scrollOffset = 0; - _spacing = 0; - - _waitingScript = NULL; - _lastResponseText = NULL; - _lastResponseTextOrig = NULL; - - _verticalAlign = VAL_BOTTOM; - _align = TAL_LEFT; -} - - -////////////////////////////////////////////////////////////////////////// -AdResponseBox::~AdResponseBox() { - - delete _window; - _window = NULL; - delete _shieldWindow; - _shieldWindow = NULL; - delete[] _lastResponseText; - _lastResponseText = NULL; - delete[] _lastResponseTextOrig; - _lastResponseTextOrig = NULL; - - if (_font) { - _gameRef->_fontStorage->removeFont(_font); - } - if (_fontHover) { - _gameRef->_fontStorage->removeFont(_fontHover); - } - - clearResponses(); - clearButtons(); - - _waitingScript = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void AdResponseBox::clearResponses() { - for (uint32 i = 0; i < _responses.size(); i++) { - delete _responses[i]; - } - _responses.clear(); -} - - -////////////////////////////////////////////////////////////////////////// -void AdResponseBox::clearButtons() { - for (uint32 i = 0; i < _respButtons.size(); i++) { - delete _respButtons[i]; - } - _respButtons.clear(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::invalidateButtons() { - for (uint32 i = 0; i < _respButtons.size(); i++) { - _respButtons[i]->_image = NULL; - _respButtons[i]->_cursor = NULL; - _respButtons[i]->_font = NULL; - _respButtons[i]->_fontHover = NULL; - _respButtons[i]->_fontPress = NULL; - _respButtons[i]->setText(""); - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::createButtons() { - clearButtons(); - - _scrollOffset = 0; - for (uint32 i = 0; i < _responses.size(); i++) { - UIButton *btn = new UIButton(_gameRef); - if (btn) { - btn->_parent = _window; - btn->_sharedFonts = btn->_sharedImages = true; - btn->_sharedCursors = true; - // iconic - if (_responses[i]->_icon) { - btn->_image = _responses[i]->_icon; - if (_responses[i]->_iconHover) { - btn->_imageHover = _responses[i]->_iconHover; - } - if (_responses[i]->_iconPressed) { - btn->_imagePress = _responses[i]->_iconPressed; - } - - btn->setCaption(_responses[i]->_text); - if (_cursor) { - btn->_cursor = _cursor; - } else if (_gameRef->_activeCursor) { - btn->_cursor = _gameRef->_activeCursor; - } - } - // textual - else { - btn->setText(_responses[i]->_text); - btn->_font = (_font == NULL) ? _gameRef->_systemFont : _font; - btn->_fontHover = (_fontHover == NULL) ? _gameRef->_systemFont : _fontHover; - btn->_fontPress = btn->_fontHover; - btn->_align = _align; - - if (_gameRef->_touchInterface) { - btn->_fontHover = btn->_font; - } - - - if (_responses[i]->_font) { - btn->_font = _responses[i]->_font; - } - - btn->_width = _responseArea.right - _responseArea.left; - if (btn->_width <= 0) { - btn->_width = _gameRef->_renderer->_width; - } - } - btn->setName("response"); - btn->correctSize(); - - // make the responses touchable - if (_gameRef->_touchInterface) { - btn->_height = MAX(btn->_height, 50); - } - - //btn->SetListener(this, btn, _responses[i]->_iD); - btn->setListener(this, btn, i); - btn->_visible = false; - _respButtons.add(btn); - - if (_responseArea.bottom - _responseArea.top < btn->_height) { - _gameRef->LOG(0, "Warning: Response '%s' is too high to be displayed within response box. Correcting.", _responses[i]->_text); - _responseArea.bottom += (btn->_height - (_responseArea.bottom - _responseArea.top)); - } - } - } - _ready = false; - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdResponseBox::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(RESPONSE_BOX) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(FONT_HOVER) -TOKEN_DEF(FONT) -TOKEN_DEF(AREA) -TOKEN_DEF(HORIZONTAL) -TOKEN_DEF(SPACING) -TOKEN_DEF(WINDOW) -TOKEN_DEF(CURSOR) -TOKEN_DEF(TEXT_ALIGN) -TOKEN_DEF(VERTICAL_ALIGN) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(RESPONSE_BOX) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(FONT_HOVER) - TOKEN_TABLE(FONT) - TOKEN_TABLE(AREA) - TOKEN_TABLE(HORIZONTAL) - TOKEN_TABLE(SPACING) - TOKEN_TABLE(WINDOW) - TOKEN_TABLE(CURSOR) - TOKEN_TABLE(TEXT_ALIGN) - TOKEN_TABLE(VERTICAL_ALIGN) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_RESPONSE_BOX) { - _gameRef->LOG(0, "'RESPONSE_BOX' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_WINDOW: - delete _window; - _window = new UIWindow(_gameRef); - if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { - delete _window; - _window = NULL; - cmd = PARSERR_GENERIC; - } else if (_shieldWindow) { - _shieldWindow->_parent = _window; - } - break; - - case TOKEN_FONT: - if (_font) { - _gameRef->_fontStorage->removeFont(_font); - } - _font = _gameRef->_fontStorage->addFont((char *)params); - if (!_font) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_FONT_HOVER: - if (_fontHover) { - _gameRef->_fontStorage->removeFont(_fontHover); - } - _fontHover = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontHover) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_AREA: - parser.scanStr((char *)params, "%d,%d,%d,%d", &_responseArea.left, &_responseArea.top, &_responseArea.right, &_responseArea.bottom); - break; - - case TOKEN_HORIZONTAL: - parser.scanStr((char *)params, "%b", &_horizontal); - break; - - case TOKEN_TEXT_ALIGN: - if (scumm_stricmp((char *)params, "center") == 0) { - _align = TAL_CENTER; - } else if (scumm_stricmp((char *)params, "right") == 0) { - _align = TAL_RIGHT; - } else { - _align = TAL_LEFT; - } - break; - - case TOKEN_VERTICAL_ALIGN: - if (scumm_stricmp((char *)params, "top") == 0) { - _verticalAlign = VAL_TOP; - } else if (scumm_stricmp((char *)params, "center") == 0) { - _verticalAlign = VAL_CENTER; - } else { - _verticalAlign = VAL_BOTTOM; - } - break; - - case TOKEN_SPACING: - parser.scanStr((char *)params, "%d", &_spacing); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - - case TOKEN_CURSOR: - delete _cursor; - _cursor = new BaseSprite(_gameRef); - if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { - delete _cursor; - _cursor = NULL; - cmd = PARSERR_GENERIC; - } - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in RESPONSE_BOX definition"); - return STATUS_FAILED; - } - - if (_window) { - for (uint32 i = 0; i < _window->_widgets.size(); i++) { - if (!_window->_widgets[i]->_listenerObject) { - _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); - } - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "RESPONSE_BOX\n"); - buffer->putTextIndent(indent, "{\n"); - - buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _responseArea.left, _responseArea.top, _responseArea.right, _responseArea.bottom); - - if (_font && _font->getFilename()) { - buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); - } - if (_fontHover && _fontHover->getFilename()) { - buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->getFilename()); - } - - if (_cursor && _cursor->getFilename()) { - buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); - } - - buffer->putTextIndent(indent + 2, "HORIZONTAL=%s\n", _horizontal ? "TRUE" : "FALSE"); - - switch (_align) { - case TAL_LEFT: - buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "left"); - break; - case TAL_RIGHT: - buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "right"); - break; - case TAL_CENTER: - buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "center"); - break; - default: - error("AdResponseBox::SaveAsText - Unhandled enum"); - break; - } - - switch (_verticalAlign) { - case VAL_TOP: - buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "top"); - break; - case VAL_BOTTOM: - buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "bottom"); - break; - case VAL_CENTER: - buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "center"); - break; - } - - buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); - - buffer->putTextIndent(indent + 2, "\n"); - - // window - if (_window) { - _window->saveAsText(buffer, indent + 2); - } - - buffer->putTextIndent(indent + 2, "\n"); - - // editor properties - BaseClass::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::display() { - Rect32 rect = _responseArea; - if (_window) { - rect.offsetRect(_window->_posX, _window->_posY); - //_window->display(); - } - - int xxx, yyy; - uint32 i; - - xxx = rect.left; - yyy = rect.top; - - // shift down if needed - if (!_horizontal) { - int totalHeight = 0; - for (i = 0; i < _respButtons.size(); i++) { - totalHeight += (_respButtons[i]->_height + _spacing); - } - totalHeight -= _spacing; - - switch (_verticalAlign) { - case VAL_BOTTOM: - if (yyy + totalHeight < rect.bottom) { - yyy = rect.bottom - totalHeight; - } - break; - - case VAL_CENTER: - if (yyy + totalHeight < rect.bottom) { - yyy += ((rect.bottom - rect.top) - totalHeight) / 2; - } - break; - - case VAL_TOP: - // do nothing - break; - } - } - - // prepare response buttons - bool scrollNeeded = false; - for (i = _scrollOffset; i < _respButtons.size(); i++) { - if ((_horizontal && xxx + _respButtons[i]->_width > rect.right) - || (!_horizontal && yyy + _respButtons[i]->_height > rect.bottom)) { - - scrollNeeded = true; - _respButtons[i]->_visible = false; - break; - } - - _respButtons[i]->_visible = true; - _respButtons[i]->_posX = xxx; - _respButtons[i]->_posY = yyy; - - if (_horizontal) { - xxx += (_respButtons[i]->_width + _spacing); - } else { - yyy += (_respButtons[i]->_height + _spacing); - } - } - - // show appropriate scroll buttons - if (_window) { - _window->showWidget("prev", _scrollOffset > 0); - _window->showWidget("next", scrollNeeded); - } - - // go exclusive - if (_shieldWindow) { - _shieldWindow->_posX = _shieldWindow->_posY = 0; - _shieldWindow->_width = _gameRef->_renderer->_width; - _shieldWindow->_height = _gameRef->_renderer->_height; - - _shieldWindow->display(); - } - - // display window - if (_window) { - _window->display(); - } - - - // display response buttons - for (i = _scrollOffset; i < _respButtons.size(); i++) { - _respButtons[i]->display(); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::listen(BaseScriptHolder *param1, uint32 param2) { - UIObject *obj = (UIObject *)param1; - - switch (obj->_type) { - case UI_BUTTON: - if (scumm_stricmp(obj->getName(), "prev") == 0) { - _scrollOffset--; - } else if (scumm_stricmp(obj->getName(), "next") == 0) { - _scrollOffset++; - } else if (scumm_stricmp(obj->getName(), "response") == 0) { - if (_waitingScript) { - _waitingScript->_stack->pushInt(_responses[param2]->_iD); - } - handleResponse(_responses[param2]); - _waitingScript = NULL; - _gameRef->_state = GAME_RUNNING; - ((AdGame *)_gameRef)->_stateEx = GAME_NORMAL; - _ready = true; - invalidateButtons(); - clearResponses(); - } else { - return BaseObject::listen(param1, param2); - } - break; - default: - error("AdResponseBox::Listen - Unhandled enum"); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::persist(BasePersistenceManager *persistMgr) { - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_font)); - persistMgr->transfer(TMEMBER(_fontHover)); - persistMgr->transfer(TMEMBER(_horizontal)); - persistMgr->transfer(TMEMBER(_lastResponseText)); - persistMgr->transfer(TMEMBER(_lastResponseTextOrig)); - _respButtons.persist(persistMgr); - persistMgr->transfer(TMEMBER(_responseArea)); - _responses.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scrollOffset)); - persistMgr->transfer(TMEMBER(_shieldWindow)); - persistMgr->transfer(TMEMBER(_spacing)); - persistMgr->transfer(TMEMBER(_waitingScript)); - persistMgr->transfer(TMEMBER(_window)); - - persistMgr->transfer(TMEMBER_INT(_verticalAlign)); - persistMgr->transfer(TMEMBER_INT(_align)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::weedResponses() { - AdGame *adGame = (AdGame *)_gameRef; - - for (uint32 i = 0; i < _responses.size(); i++) { - switch (_responses[i]->_responseType) { - case RESPONSE_ONCE: - if (adGame->branchResponseUsed(_responses[i]->_iD)) { - delete _responses[i]; - _responses.remove_at(i); - i--; - } - break; - - case RESPONSE_ONCE_GAME: - if (adGame->gameResponseUsed(_responses[i]->_iD)) { - delete _responses[i]; - _responses.remove_at(i); - i--; - } - break; - default: - debugC(kWintermuteDebugGeneral, "AdResponseBox::WeedResponses - Unhandled enum"); - break; - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void AdResponseBox::setLastResponseText(const char *text, const char *textOrig) { - BaseUtils::setString(&_lastResponseText, text); - BaseUtils::setString(&_lastResponseTextOrig, textOrig); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::handleResponse(AdResponse *response) { - setLastResponseText(response->_text, response->_textOrig); - - AdGame *adGame = (AdGame *)_gameRef; - - switch (response->_responseType) { - case RESPONSE_ONCE: - adGame->addBranchResponse(response->_iD); - break; - - case RESPONSE_ONCE_GAME: - adGame->addGameResponse(response->_iD); - break; - default: - debugC(kWintermuteDebugGeneral, "AdResponseBox::HandleResponse - Unhandled enum"); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) { - BaseArray objects; - getObjects(objects, true); - - if (objects.size() == 0) { - return NULL; - } else { - if (currObject != NULL) { - for (uint32 i = 0; i < objects.size(); i++) { - if (objects[i] == currObject) { - if (i < objects.size() - 1) { - return objects[i + 1]; - } else { - break; - } - } - } - } - return objects[0]; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { - BaseArray objects; - getObjects(objects, true); - - if (objects.size() == 0) { - return NULL; - } else { - if (currObject != NULL) { - for (int i = objects.size() - 1; i >= 0; i--) { - if (objects[i] == currObject) { - if (i > 0) { - return objects[i - 1]; - } else { - break; - } - } - } - } - return objects[objects.size() - 1]; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -bool AdResponseBox::getObjects(BaseArray &objects, bool interactiveOnly) { - for (uint32 i = 0; i < _respButtons.size(); i++) { - objects.add(_respButtons[i]); - } - if (_window) { - _window->getWindowObjects(objects, interactiveOnly); - } - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_response_box.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/ui/ui_button.h" +#include "engines/wintermute/ui/ui_window.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/ad/ad_response.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/wintermute.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdResponseBox, false) + +////////////////////////////////////////////////////////////////////////// +AdResponseBox::AdResponseBox(BaseGame *inGame) : BaseObject(inGame) { + _font = _fontHover = NULL; + + _window = NULL; + _shieldWindow = new UIWindow(_gameRef); + + _horizontal = false; + BasePlatform::setRectEmpty(&_responseArea); + _scrollOffset = 0; + _spacing = 0; + + _waitingScript = NULL; + _lastResponseText = NULL; + _lastResponseTextOrig = NULL; + + _verticalAlign = VAL_BOTTOM; + _align = TAL_LEFT; +} + + +////////////////////////////////////////////////////////////////////////// +AdResponseBox::~AdResponseBox() { + + delete _window; + _window = NULL; + delete _shieldWindow; + _shieldWindow = NULL; + delete[] _lastResponseText; + _lastResponseText = NULL; + delete[] _lastResponseTextOrig; + _lastResponseTextOrig = NULL; + + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } + + clearResponses(); + clearButtons(); + + _waitingScript = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void AdResponseBox::clearResponses() { + for (uint32 i = 0; i < _responses.size(); i++) { + delete _responses[i]; + } + _responses.clear(); +} + + +////////////////////////////////////////////////////////////////////////// +void AdResponseBox::clearButtons() { + for (uint32 i = 0; i < _respButtons.size(); i++) { + delete _respButtons[i]; + } + _respButtons.clear(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::invalidateButtons() { + for (uint32 i = 0; i < _respButtons.size(); i++) { + _respButtons[i]->_image = NULL; + _respButtons[i]->_cursor = NULL; + _respButtons[i]->_font = NULL; + _respButtons[i]->_fontHover = NULL; + _respButtons[i]->_fontPress = NULL; + _respButtons[i]->setText(""); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::createButtons() { + clearButtons(); + + _scrollOffset = 0; + for (uint32 i = 0; i < _responses.size(); i++) { + UIButton *btn = new UIButton(_gameRef); + if (btn) { + btn->_parent = _window; + btn->_sharedFonts = btn->_sharedImages = true; + btn->_sharedCursors = true; + // iconic + if (_responses[i]->_icon) { + btn->_image = _responses[i]->_icon; + if (_responses[i]->_iconHover) { + btn->_imageHover = _responses[i]->_iconHover; + } + if (_responses[i]->_iconPressed) { + btn->_imagePress = _responses[i]->_iconPressed; + } + + btn->setCaption(_responses[i]->_text); + if (_cursor) { + btn->_cursor = _cursor; + } else if (_gameRef->_activeCursor) { + btn->_cursor = _gameRef->_activeCursor; + } + } + // textual + else { + btn->setText(_responses[i]->_text); + btn->_font = (_font == NULL) ? _gameRef->_systemFont : _font; + btn->_fontHover = (_fontHover == NULL) ? _gameRef->_systemFont : _fontHover; + btn->_fontPress = btn->_fontHover; + btn->_align = _align; + + if (_gameRef->_touchInterface) { + btn->_fontHover = btn->_font; + } + + + if (_responses[i]->_font) { + btn->_font = _responses[i]->_font; + } + + btn->_width = _responseArea.right - _responseArea.left; + if (btn->_width <= 0) { + btn->_width = _gameRef->_renderer->_width; + } + } + btn->setName("response"); + btn->correctSize(); + + // make the responses touchable + if (_gameRef->_touchInterface) { + btn->_height = MAX(btn->_height, 50); + } + + //btn->SetListener(this, btn, _responses[i]->_iD); + btn->setListener(this, btn, i); + btn->_visible = false; + _respButtons.add(btn); + + if (_responseArea.bottom - _responseArea.top < btn->_height) { + _gameRef->LOG(0, "Warning: Response '%s' is too high to be displayed within response box. Correcting.", _responses[i]->_text); + _responseArea.bottom += (btn->_height - (_responseArea.bottom - _responseArea.top)); + } + } + } + _ready = false; + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdResponseBox::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(RESPONSE_BOX) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(FONT_HOVER) +TOKEN_DEF(FONT) +TOKEN_DEF(AREA) +TOKEN_DEF(HORIZONTAL) +TOKEN_DEF(SPACING) +TOKEN_DEF(WINDOW) +TOKEN_DEF(CURSOR) +TOKEN_DEF(TEXT_ALIGN) +TOKEN_DEF(VERTICAL_ALIGN) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(RESPONSE_BOX) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(FONT_HOVER) + TOKEN_TABLE(FONT) + TOKEN_TABLE(AREA) + TOKEN_TABLE(HORIZONTAL) + TOKEN_TABLE(SPACING) + TOKEN_TABLE(WINDOW) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(TEXT_ALIGN) + TOKEN_TABLE(VERTICAL_ALIGN) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_RESPONSE_BOX) { + _gameRef->LOG(0, "'RESPONSE_BOX' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_WINDOW: + delete _window; + _window = new UIWindow(_gameRef); + if (!_window || DID_FAIL(_window->loadBuffer(params, false))) { + delete _window; + _window = NULL; + cmd = PARSERR_GENERIC; + } else if (_shieldWindow) { + _shieldWindow->_parent = _window; + } + break; + + case TOKEN_FONT: + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } + _font = _gameRef->_fontStorage->addFont((char *)params); + if (!_font) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_FONT_HOVER: + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } + _fontHover = _gameRef->_fontStorage->addFont((char *)params); + if (!_fontHover) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_AREA: + parser.scanStr((char *)params, "%d,%d,%d,%d", &_responseArea.left, &_responseArea.top, &_responseArea.right, &_responseArea.bottom); + break; + + case TOKEN_HORIZONTAL: + parser.scanStr((char *)params, "%b", &_horizontal); + break; + + case TOKEN_TEXT_ALIGN: + if (scumm_stricmp((char *)params, "center") == 0) { + _align = TAL_CENTER; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _align = TAL_RIGHT; + } else { + _align = TAL_LEFT; + } + break; + + case TOKEN_VERTICAL_ALIGN: + if (scumm_stricmp((char *)params, "top") == 0) { + _verticalAlign = VAL_TOP; + } else if (scumm_stricmp((char *)params, "center") == 0) { + _verticalAlign = VAL_CENTER; + } else { + _verticalAlign = VAL_BOTTOM; + } + break; + + case TOKEN_SPACING: + parser.scanStr((char *)params, "%d", &_spacing); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new BaseSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in RESPONSE_BOX definition"); + return STATUS_FAILED; + } + + if (_window) { + for (uint32 i = 0; i < _window->_widgets.size(); i++) { + if (!_window->_widgets[i]->_listenerObject) { + _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "RESPONSE_BOX\n"); + buffer->putTextIndent(indent, "{\n"); + + buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _responseArea.left, _responseArea.top, _responseArea.right, _responseArea.bottom); + + if (_font && _font->getFilename()) { + buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); + } + if (_fontHover && _fontHover->getFilename()) { + buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->getFilename()); + } + + if (_cursor && _cursor->getFilename()) { + buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } + + buffer->putTextIndent(indent + 2, "HORIZONTAL=%s\n", _horizontal ? "TRUE" : "FALSE"); + + switch (_align) { + case TAL_LEFT: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "left"); + break; + case TAL_RIGHT: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "right"); + break; + case TAL_CENTER: + buffer->putTextIndent(indent + 2, "TEXT_ALIGN=\"%s\"\n", "center"); + break; + default: + error("AdResponseBox::SaveAsText - Unhandled enum"); + break; + } + + switch (_verticalAlign) { + case VAL_TOP: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "top"); + break; + case VAL_BOTTOM: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "bottom"); + break; + case VAL_CENTER: + buffer->putTextIndent(indent + 2, "VERTICAL_ALIGN=\"%s\"\n", "center"); + break; + } + + buffer->putTextIndent(indent + 2, "SPACING=%d\n", _spacing); + + buffer->putTextIndent(indent + 2, "\n"); + + // window + if (_window) { + _window->saveAsText(buffer, indent + 2); + } + + buffer->putTextIndent(indent + 2, "\n"); + + // editor properties + BaseClass::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::display() { + Rect32 rect = _responseArea; + if (_window) { + rect.offsetRect(_window->_posX, _window->_posY); + //_window->display(); + } + + int xxx, yyy; + uint32 i; + + xxx = rect.left; + yyy = rect.top; + + // shift down if needed + if (!_horizontal) { + int totalHeight = 0; + for (i = 0; i < _respButtons.size(); i++) { + totalHeight += (_respButtons[i]->_height + _spacing); + } + totalHeight -= _spacing; + + switch (_verticalAlign) { + case VAL_BOTTOM: + if (yyy + totalHeight < rect.bottom) { + yyy = rect.bottom - totalHeight; + } + break; + + case VAL_CENTER: + if (yyy + totalHeight < rect.bottom) { + yyy += ((rect.bottom - rect.top) - totalHeight) / 2; + } + break; + + case VAL_TOP: + // do nothing + break; + } + } + + // prepare response buttons + bool scrollNeeded = false; + for (i = _scrollOffset; i < _respButtons.size(); i++) { + if ((_horizontal && xxx + _respButtons[i]->_width > rect.right) + || (!_horizontal && yyy + _respButtons[i]->_height > rect.bottom)) { + + scrollNeeded = true; + _respButtons[i]->_visible = false; + break; + } + + _respButtons[i]->_visible = true; + _respButtons[i]->_posX = xxx; + _respButtons[i]->_posY = yyy; + + if (_horizontal) { + xxx += (_respButtons[i]->_width + _spacing); + } else { + yyy += (_respButtons[i]->_height + _spacing); + } + } + + // show appropriate scroll buttons + if (_window) { + _window->showWidget("prev", _scrollOffset > 0); + _window->showWidget("next", scrollNeeded); + } + + // go exclusive + if (_shieldWindow) { + _shieldWindow->_posX = _shieldWindow->_posY = 0; + _shieldWindow->_width = _gameRef->_renderer->_width; + _shieldWindow->_height = _gameRef->_renderer->_height; + + _shieldWindow->display(); + } + + // display window + if (_window) { + _window->display(); + } + + + // display response buttons + for (i = _scrollOffset; i < _respButtons.size(); i++) { + _respButtons[i]->display(); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::listen(BaseScriptHolder *param1, uint32 param2) { + UIObject *obj = (UIObject *)param1; + + switch (obj->_type) { + case UI_BUTTON: + if (scumm_stricmp(obj->getName(), "prev") == 0) { + _scrollOffset--; + } else if (scumm_stricmp(obj->getName(), "next") == 0) { + _scrollOffset++; + } else if (scumm_stricmp(obj->getName(), "response") == 0) { + if (_waitingScript) { + _waitingScript->_stack->pushInt(_responses[param2]->_iD); + } + handleResponse(_responses[param2]); + _waitingScript = NULL; + _gameRef->_state = GAME_RUNNING; + ((AdGame *)_gameRef)->_stateEx = GAME_NORMAL; + _ready = true; + invalidateButtons(); + clearResponses(); + } else { + return BaseObject::listen(param1, param2); + } + break; + default: + error("AdResponseBox::Listen - Unhandled enum"); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::persist(BasePersistenceManager *persistMgr) { + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_fontHover)); + persistMgr->transfer(TMEMBER(_horizontal)); + persistMgr->transfer(TMEMBER(_lastResponseText)); + persistMgr->transfer(TMEMBER(_lastResponseTextOrig)); + _respButtons.persist(persistMgr); + persistMgr->transfer(TMEMBER(_responseArea)); + _responses.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollOffset)); + persistMgr->transfer(TMEMBER(_shieldWindow)); + persistMgr->transfer(TMEMBER(_spacing)); + persistMgr->transfer(TMEMBER(_waitingScript)); + persistMgr->transfer(TMEMBER(_window)); + + persistMgr->transfer(TMEMBER_INT(_verticalAlign)); + persistMgr->transfer(TMEMBER_INT(_align)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::weedResponses() { + AdGame *adGame = (AdGame *)_gameRef; + + for (uint32 i = 0; i < _responses.size(); i++) { + switch (_responses[i]->_responseType) { + case RESPONSE_ONCE: + if (adGame->branchResponseUsed(_responses[i]->_iD)) { + delete _responses[i]; + _responses.remove_at(i); + i--; + } + break; + + case RESPONSE_ONCE_GAME: + if (adGame->gameResponseUsed(_responses[i]->_iD)) { + delete _responses[i]; + _responses.remove_at(i); + i--; + } + break; + default: + debugC(kWintermuteDebugGeneral, "AdResponseBox::WeedResponses - Unhandled enum"); + break; + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void AdResponseBox::setLastResponseText(const char *text, const char *textOrig) { + BaseUtils::setString(&_lastResponseText, text); + BaseUtils::setString(&_lastResponseTextOrig, textOrig); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::handleResponse(AdResponse *response) { + setLastResponseText(response->_text, response->_textOrig); + + AdGame *adGame = (AdGame *)_gameRef; + + switch (response->_responseType) { + case RESPONSE_ONCE: + adGame->addBranchResponse(response->_iD); + break; + + case RESPONSE_ONCE_GAME: + adGame->addGameResponse(response->_iD); + break; + default: + debugC(kWintermuteDebugGeneral, "AdResponseBox::HandleResponse - Unhandled enum"); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) { + BaseArray objects; + getObjects(objects, true); + + if (objects.size() == 0) { + return NULL; + } else { + if (currObject != NULL) { + for (uint32 i = 0; i < objects.size(); i++) { + if (objects[i] == currObject) { + if (i < objects.size() - 1) { + return objects[i + 1]; + } else { + break; + } + } + } + } + return objects[0]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { + BaseArray objects; + getObjects(objects, true); + + if (objects.size() == 0) { + return NULL; + } else { + if (currObject != NULL) { + for (int i = objects.size() - 1; i >= 0; i--) { + if (objects[i] == currObject) { + if (i > 0) { + return objects[i - 1]; + } else { + break; + } + } + } + } + return objects[objects.size() - 1]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +bool AdResponseBox::getObjects(BaseArray &objects, bool interactiveOnly) { + for (uint32 i = 0; i < _respButtons.size(); i++) { + objects.add(_respButtons[i]); + } + if (_window) { + _window->getWindowObjects(objects, interactiveOnly); + } + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_response_box.h b/engines/wintermute/ad/ad_response_box.h index 8c76b561c6..35f8cb6347 100644 --- a/engines/wintermute/ad/ad_response_box.h +++ b/engines/wintermute/ad/ad_response_box.h @@ -1,87 +1,87 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADRESPONSEBOX_H -#define WINTERMUTE_ADRESPONSEBOX_H - - -#include "engines/wintermute/base/base_object.h" - -namespace Wintermute { - -class UIButton; -class UIWindow; -class UIObject; -class AdResponse; -class AdResponseBox : public BaseObject { -public: - BaseObject *getNextAccessObject(BaseObject *CurrObject); - BaseObject *getPrevAccessObject(BaseObject *CurrObject); - bool getObjects(BaseArray &objects, bool interactiveOnly); - - bool handleResponse(AdResponse *response); - void setLastResponseText(const char *text, const char *textOrig); - char *_lastResponseText; - char *_lastResponseTextOrig; - DECLARE_PERSISTENT(AdResponseBox, BaseObject) - ScScript *_waitingScript; - virtual bool listen(BaseScriptHolder *param1, uint32 param2); - typedef enum { - EVENT_PREV, - EVENT_NEXT, - EVENT_RESPONSE - } TResponseEvent; - - bool weedResponses(); - bool display(); - int _spacing; - int _scrollOffset; - BaseFont *_fontHover; - BaseFont *_font; - bool createButtons(); - bool invalidateButtons(); - void clearButtons(); - void clearResponses(); - AdResponseBox(BaseGame *inGame); - virtual ~AdResponseBox(); - BaseArray _responses; - BaseArray _respButtons; - UIWindow *_window; - UIWindow *_shieldWindow; - bool _horizontal; - Rect32 _responseArea; - int _verticalAlign; - TTextAlign _align; - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSEBOX_H +#define WINTERMUTE_ADRESPONSEBOX_H + + +#include "engines/wintermute/base/base_object.h" + +namespace Wintermute { + +class UIButton; +class UIWindow; +class UIObject; +class AdResponse; +class AdResponseBox : public BaseObject { +public: + BaseObject *getNextAccessObject(BaseObject *CurrObject); + BaseObject *getPrevAccessObject(BaseObject *CurrObject); + bool getObjects(BaseArray &objects, bool interactiveOnly); + + bool handleResponse(AdResponse *response); + void setLastResponseText(const char *text, const char *textOrig); + char *_lastResponseText; + char *_lastResponseTextOrig; + DECLARE_PERSISTENT(AdResponseBox, BaseObject) + ScScript *_waitingScript; + virtual bool listen(BaseScriptHolder *param1, uint32 param2); + typedef enum { + EVENT_PREV, + EVENT_NEXT, + EVENT_RESPONSE + } TResponseEvent; + + bool weedResponses(); + bool display(); + int _spacing; + int _scrollOffset; + BaseFont *_fontHover; + BaseFont *_font; + bool createButtons(); + bool invalidateButtons(); + void clearButtons(); + void clearResponses(); + AdResponseBox(BaseGame *inGame); + virtual ~AdResponseBox(); + BaseArray _responses; + BaseArray _respButtons; + UIWindow *_window; + UIWindow *_shieldWindow; + bool _horizontal; + Rect32 _responseArea; + int _verticalAlign; + TTextAlign _align; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_response_context.cpp b/engines/wintermute/ad/ad_response_context.cpp index 0a2eff842d..ebfa03feea 100644 --- a/engines/wintermute/ad/ad_response_context.cpp +++ b/engines/wintermute/ad/ad_response_context.cpp @@ -1,71 +1,71 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_response_context.h" -#include "engines/wintermute/base/base_persistence_manager.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdResponseContext, false) - -////////////////////////////////////////////////////////////////////////// -AdResponseContext::AdResponseContext(BaseGame *inGame) : BaseClass(inGame) { - _id = 0; - _context = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdResponseContext::~AdResponseContext() { - delete[] _context; - _context = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdResponseContext::persist(BasePersistenceManager *persistMgr) { - persistMgr->transfer(TMEMBER(_gameRef)); - persistMgr->transfer(TMEMBER(_context)); - persistMgr->transfer(TMEMBER(_id)); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -void AdResponseContext::setContext(const char *context) { - delete[] _context; - _context = NULL; - if (context) { - _context = new char [strlen(context) + 1]; - if (_context) { - strcpy(_context, context); - } - } -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_response_context.h" +#include "engines/wintermute/base/base_persistence_manager.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdResponseContext, false) + +////////////////////////////////////////////////////////////////////////// +AdResponseContext::AdResponseContext(BaseGame *inGame) : BaseClass(inGame) { + _id = 0; + _context = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdResponseContext::~AdResponseContext() { + delete[] _context; + _context = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdResponseContext::persist(BasePersistenceManager *persistMgr) { + persistMgr->transfer(TMEMBER(_gameRef)); + persistMgr->transfer(TMEMBER(_context)); + persistMgr->transfer(TMEMBER(_id)); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +void AdResponseContext::setContext(const char *context) { + delete[] _context; + _context = NULL; + if (context) { + _context = new char [strlen(context) + 1]; + if (_context) { + strcpy(_context, context); + } + } +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_response_context.h b/engines/wintermute/ad/ad_response_context.h index a630f975e4..14bc1abd93 100644 --- a/engines/wintermute/ad/ad_response_context.h +++ b/engines/wintermute/ad/ad_response_context.h @@ -1,50 +1,50 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADRESPONSECONTEXT_H -#define WINTERMUTE_ADRESPONSECONTEXT_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/base.h" - -namespace Wintermute { - -class AdResponseContext : public BaseClass { -public: - void setContext(const char *context); - int _id; - char *_context; - DECLARE_PERSISTENT(AdResponseContext, BaseClass) - AdResponseContext(BaseGame *inGame); - virtual ~AdResponseContext(); - -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADRESPONSECONTEXT_H +#define WINTERMUTE_ADRESPONSECONTEXT_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base.h" + +namespace Wintermute { + +class AdResponseContext : public BaseClass { +public: + void setContext(const char *context); + int _id; + char *_context; + DECLARE_PERSISTENT(AdResponseContext, BaseClass) + AdResponseContext(BaseGame *inGame); + virtual ~AdResponseContext(); + +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index 487e1f7067..ca7ed693ad 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -1,161 +1,161 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_rot_level.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_file_manager.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdRotLevel, false) - - -////////////////////////////////////////////////////////////////////////// -AdRotLevel::AdRotLevel(BaseGame *inGame) : BaseObject(inGame) { - _posX = 0; - _rotation = 0.0f; -} - - -////////////////////////////////////////////////////////////////////////// -AdRotLevel::~AdRotLevel() { - -} - - -////////////////////////////////////////////////////////////////////////// -bool AdRotLevel::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdRotLevel::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(ROTATION_LEVEL) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(X) -TOKEN_DEF(ROTATION) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdRotLevel::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ROTATION_LEVEL) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(X) - TOKEN_TABLE(ROTATION) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ROTATION_LEVEL) { - _gameRef->LOG(0, "'ROTATION_LEVEL' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_X: - parser.scanStr((char *)params, "%d", &_posX); - break; - - case TOKEN_ROTATION: { - int i; - parser.scanStr((char *)params, "%d", &i); - _rotation = (float)i; - } - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ROTATION_LEVEL definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdRotLevel::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "ROTATION_LEVEL {\n"); - buffer->putTextIndent(indent + 2, "X=%d\n", _posX); - buffer->putTextIndent(indent + 2, "ROTATION=%d\n", (int)_rotation); - BaseClass::saveAsText(buffer, indent + 2); - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdRotLevel::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_rotation)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_rot_level.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdRotLevel, false) + + +////////////////////////////////////////////////////////////////////////// +AdRotLevel::AdRotLevel(BaseGame *inGame) : BaseObject(inGame) { + _posX = 0; + _rotation = 0.0f; +} + + +////////////////////////////////////////////////////////////////////////// +AdRotLevel::~AdRotLevel() { + +} + + +////////////////////////////////////////////////////////////////////////// +bool AdRotLevel::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdRotLevel::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(ROTATION_LEVEL) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(X) +TOKEN_DEF(ROTATION) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdRotLevel::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ROTATION_LEVEL) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(X) + TOKEN_TABLE(ROTATION) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ROTATION_LEVEL) { + _gameRef->LOG(0, "'ROTATION_LEVEL' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_X: + parser.scanStr((char *)params, "%d", &_posX); + break; + + case TOKEN_ROTATION: { + int i; + parser.scanStr((char *)params, "%d", &i); + _rotation = (float)i; + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ROTATION_LEVEL definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdRotLevel::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ROTATION_LEVEL {\n"); + buffer->putTextIndent(indent + 2, "X=%d\n", _posX); + buffer->putTextIndent(indent + 2, "ROTATION=%d\n", (int)_rotation); + BaseClass::saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdRotLevel::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_rotation)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_rot_level.h b/engines/wintermute/ad/ad_rot_level.h index 7951c7562d..d7f5f8edf0 100644 --- a/engines/wintermute/ad/ad_rot_level.h +++ b/engines/wintermute/ad/ad_rot_level.h @@ -1,49 +1,49 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADROTLEVEL_H -#define WINTERMUTE_ADROTLEVEL_H - -#include "engines/wintermute/base/base_object.h" - -namespace Wintermute { - -class AdRotLevel : public BaseObject { -public: - DECLARE_PERSISTENT(AdRotLevel, BaseObject) - AdRotLevel(BaseGame *inGame); - virtual ~AdRotLevel(); - float _rotation; - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADROTLEVEL_H +#define WINTERMUTE_ADROTLEVEL_H + +#include "engines/wintermute/base/base_object.h" + +namespace Wintermute { + +class AdRotLevel : public BaseObject { +public: + DECLARE_PERSISTENT(AdRotLevel, BaseObject) + AdRotLevel(BaseGame *inGame); + virtual ~AdRotLevel(); + float _rotation; + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index f3ec68dd64..8b68cc5d32 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -1,159 +1,159 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_scale_level.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_file_manager.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdScaleLevel, false) - -////////////////////////////////////////////////////////////////////////// -AdScaleLevel::AdScaleLevel(BaseGame *inGame) : BaseObject(inGame) { - _posY = 0; - _scale = 100; -} - - -////////////////////////////////////////////////////////////////////////// -AdScaleLevel::~AdScaleLevel() { - -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScaleLevel::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdScaleLevel::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(SCALE_LEVEL) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(Y) -TOKEN_DEF(SCALE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdScaleLevel::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(SCALE_LEVEL) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(Y) - TOKEN_TABLE(SCALE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCALE_LEVEL) { - _gameRef->LOG(0, "'SCALE_LEVEL' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_Y: - parser.scanStr((char *)params, "%d", &_posY); - break; - - case TOKEN_SCALE: { - int i; - parser.scanStr((char *)params, "%d", &i); - _scale = (float)i; - } - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in SCALE_LEVEL definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScaleLevel::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "SCALE_LEVEL {\n"); - buffer->putTextIndent(indent + 2, "Y=%d\n", _posY); - buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_scale); - BaseClass::saveAsText(buffer, indent + 2); - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScaleLevel::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_scale)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_scale_level.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdScaleLevel, false) + +////////////////////////////////////////////////////////////////////////// +AdScaleLevel::AdScaleLevel(BaseGame *inGame) : BaseObject(inGame) { + _posY = 0; + _scale = 100; +} + + +////////////////////////////////////////////////////////////////////////// +AdScaleLevel::~AdScaleLevel() { + +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScaleLevel::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdScaleLevel::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SCALE_LEVEL) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(Y) +TOKEN_DEF(SCALE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdScaleLevel::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SCALE_LEVEL) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(Y) + TOKEN_TABLE(SCALE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCALE_LEVEL) { + _gameRef->LOG(0, "'SCALE_LEVEL' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_Y: + parser.scanStr((char *)params, "%d", &_posY); + break; + + case TOKEN_SCALE: { + int i; + parser.scanStr((char *)params, "%d", &i); + _scale = (float)i; + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SCALE_LEVEL definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScaleLevel::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "SCALE_LEVEL {\n"); + buffer->putTextIndent(indent + 2, "Y=%d\n", _posY); + buffer->putTextIndent(indent + 2, "SCALE=%d\n", (int)_scale); + BaseClass::saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScaleLevel::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_scale)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_scale_level.h b/engines/wintermute/ad/ad_scale_level.h index 41a2edf8c5..628a385eb4 100644 --- a/engines/wintermute/ad/ad_scale_level.h +++ b/engines/wintermute/ad/ad_scale_level.h @@ -1,50 +1,50 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSCALELEVEL_H -#define WINTERMUTE_ADSCALELEVEL_H - - -#include "engines/wintermute/base/base_object.h" - -namespace Wintermute { - -class AdScaleLevel : public BaseObject { -public: - DECLARE_PERSISTENT(AdScaleLevel, BaseObject) - float _scale; - AdScaleLevel(BaseGame *inGame); - virtual ~AdScaleLevel(); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCALELEVEL_H +#define WINTERMUTE_ADSCALELEVEL_H + + +#include "engines/wintermute/base/base_object.h" + +namespace Wintermute { + +class AdScaleLevel : public BaseObject { +public: + DECLARE_PERSISTENT(AdScaleLevel, BaseObject) + float _scale; + AdScaleLevel(BaseGame *inGame); + virtual ~AdScaleLevel(); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index f67252350e..e47acc63c9 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -1,2986 +1,2986 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_scene.h" -#include "engines/wintermute/ad/ad_actor.h" -#include "engines/wintermute/ad/ad_entity.h" -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/ad/ad_layer.h" -#include "engines/wintermute/ad/ad_node_state.h" -#include "engines/wintermute/ad/ad_object.h" -#include "engines/wintermute/ad/ad_path.h" -#include "engines/wintermute/ad/ad_path_point.h" -#include "engines/wintermute/ad/ad_rot_level.h" -#include "engines/wintermute/ad/ad_scale_level.h" -#include "engines/wintermute/ad/ad_scene_node.h" -#include "engines/wintermute/ad/ad_scene_state.h" -#include "engines/wintermute/ad/ad_sentence.h" -#include "engines/wintermute/ad/ad_waypoint_group.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_object.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_point.h" -#include "engines/wintermute/base/base_region.h" -#include "engines/wintermute/base/base_scriptable.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_viewport.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/ui/ui_window.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/wintermute.h" -#include - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdScene, false) - -////////////////////////////////////////////////////////////////////////// -AdScene::AdScene(BaseGame *inGame) : BaseObject(inGame) { - _pfTarget = new BasePoint; - setDefaults(); -} - - -////////////////////////////////////////////////////////////////////////// -AdScene::~AdScene() { - cleanup(); - _gameRef->unregisterObject(_fader); - delete _pfTarget; - _pfTarget = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::setDefaults() { - _initialized = false; - _pfReady = true; - _pfTargetPath = NULL; - _pfRequester = NULL; - _mainLayer = NULL; - - _pfPointsNum = 0; - _persistentState = false; - _persistentStateSprites = true; - - _autoScroll = true; - _offsetLeft = _offsetTop = 0; - _targetOffsetLeft = _targetOffsetTop = 0; - - _lastTimeH = _lastTimeV = 0; - _scrollTimeH = _scrollTimeV = 10; - _scrollPixelsH = _scrollPixelsV = 1; - - _pfMaxTime = 15; - - _paralaxScrolling = true; - - // editor settings - _editorMarginH = _editorMarginV = 100; - - _editorColFrame = 0xE0888888; - _editorColEntity = 0xFF008000; - _editorColRegion = 0xFF0000FF; - _editorColBlocked = 0xFF800080; - _editorColWaypoints = 0xFF0000FF; - _editorColEntitySel = 0xFFFF0000; - _editorColRegionSel = 0xFFFF0000; - _editorColBlockedSel = 0xFFFF0000; - _editorColWaypointsSel = 0xFFFF0000; - _editorColScale = 0xFF00FF00; - _editorColDecor = 0xFF00FFFF; - _editorColDecorSel = 0xFFFF0000; - - _editorShowRegions = true; - _editorShowBlocked = true; - _editorShowDecor = true; - _editorShowEntities = true; - _editorShowScale = true; - - _shieldWindow = NULL; - - _fader = new BaseFader(_gameRef); - _gameRef->registerObject(_fader); - - _viewport = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::cleanup() { - BaseObject::cleanup(); - - _mainLayer = NULL; // reference only - - delete _shieldWindow; - _shieldWindow = NULL; - - _gameRef->unregisterObject(_fader); - _fader = NULL; - - for (uint32 i = 0; i < _layers.size(); i++) { - _gameRef->unregisterObject(_layers[i]); - } - _layers.clear(); - - - for (uint32 i = 0; i < _waypointGroups.size(); i++) { - _gameRef->unregisterObject(_waypointGroups[i]); - } - _waypointGroups.clear(); - - for (uint32 i = 0; i < _scaleLevels.size(); i++) { - _gameRef->unregisterObject(_scaleLevels[i]); - } - _scaleLevels.clear(); - - for (uint32 i = 0; i < _rotLevels.size(); i++) { - _gameRef->unregisterObject(_rotLevels[i]); - } - _rotLevels.clear(); - - - for (uint32 i = 0; i < _pfPath.size(); i++) { - delete _pfPath[i]; - } - _pfPath.clear(); - _pfPointsNum = 0; - - for (uint32 i = 0; i < _objects.size(); i++) { - _gameRef->unregisterObject(_objects[i]); - } - _objects.clear(); - - delete _viewport; - _viewport = NULL; - - setDefaults(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester) { - if (!_pfReady) { - return false; - } else { - _pfReady = false; - *_pfTarget = target; - _pfTargetPath = path; - _pfRequester = requester; - - _pfTargetPath->reset(); - _pfTargetPath->setReady(false); - - // prepare working path - pfPointsStart(); - - // first point - //_pfPath.add(new AdPathPoint(source.x, source.y, 0)); - - // if we're one pixel stuck, get unstuck - int startX = source.x; - int startY = source.y; - int bestDistance = 1000; - if (isBlockedAt(startX, startY, true, requester)) { - int tolerance = 2; - for (int xxx = startX - tolerance; xxx <= startX + tolerance; xxx++) { - for (int yyy = startY - tolerance; yyy <= startY + tolerance; yyy++) { - if (isWalkableAt(xxx, yyy, true, requester)) { - int distance = abs(xxx - source.x) + abs(yyy - source.y); - if (distance < bestDistance) { - startX = xxx; - startY = yyy; - - bestDistance = distance; - } - } - } - } - } - - pfPointsAdd(startX, startY, 0); - - //CorrectTargetPoint(&target.x, &target.y); - - // last point - //_pfPath.add(new AdPathPoint(target.x, target.y, INT_MAX)); - pfPointsAdd(target.x, target.y, INT_MAX); - - // active waypoints - for (uint32 i = 0; i < _waypointGroups.size(); i++) { - if (_waypointGroups[i]->_active) { - pfAddWaypointGroup(_waypointGroups[i], requester); - } - } - - - // free waypoints - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentWptGroup) { - pfAddWaypointGroup(_objects[i]->_currentWptGroup, requester); - } - } - AdGame *adGame = (AdGame *)_gameRef; - for (uint32 i = 0; i < adGame->_objects.size(); i++) { - if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentWptGroup) { - pfAddWaypointGroup(adGame->_objects[i]->_currentWptGroup, requester); - } - } - - return true; - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::pfAddWaypointGroup(AdWaypointGroup *wpt, BaseObject *requester) { - if (!wpt->_active) { - return; - } - - for (uint32 i = 0; i < wpt->_points.size(); i++) { - if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) { - continue; - } - - //_pfPath.add(new AdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); - pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX); - } -} - - -////////////////////////////////////////////////////////////////////////// -float AdScene::getZoomAt(int x, int y) { - float ret = 100; - - bool found = false; - if (_mainLayer) { - for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { - AdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_blocked && node->_region->pointInRegion(x, y)) { - if (node->_region->_zoom != 0) { - ret = node->_region->_zoom; - found = true; - break; - } - } - } - } - if (!found) { - ret = getScaleAt(y); - } - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -uint32 AdScene::getAlphaAt(int x, int y, bool colorCheck) { - if (!_gameRef->_debugDebugMode) { - colorCheck = false; - } - - uint32 ret; - if (colorCheck) { - ret = 0xFFFF0000; - } else { - ret = 0xFFFFFFFF; - } - - if (_mainLayer) { - for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { - AdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { - if (!node->_region->_blocked) { - ret = node->_region->_alpha; - } - break; - } - } - } - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *requester) { - bool ret = true; - - if (checkFreeObjects) { - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { - if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { - return true; - } - } - } - AdGame *adGame = (AdGame *)_gameRef; - for (uint32 i = 0; i < adGame->_objects.size(); i++) { - if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { - if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { - return true; - } - } - } - } - - - if (_mainLayer) { - for (uint32 i = 0; i < _mainLayer->_nodes.size(); i++) { - AdSceneNode *node = _mainLayer->_nodes[i]; - /* - if (Node->_type == OBJECT_REGION && Node->_region->_active && Node->_region->_blocked && Node->_region->PointInRegion(X, Y)) - { - ret = true; - break; - } - */ - if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { - if (node->_region->_blocked) { - ret = true; - break; - } else { - ret = false; - } - } - } - } - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requester) { - bool ret = false; - - if (checkFreeObjects) { - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { - if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { - return false; - } - } - } - AdGame *adGame = (AdGame *)_gameRef; - for (uint32 i = 0; i < adGame->_objects.size(); i++) { - if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { - if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { - return false; - } - } - } - } - - - if (_mainLayer) { - for (uint32 i = 0; i < _mainLayer->_nodes.size(); i++) { - AdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { - if (node->_region->_blocked) { - ret = false; - break; - } else { - ret = true; - } - } - } - } - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -int AdScene::getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester) { - double xStep, yStep, x, y; - int xLength, yLength, xCount, yCount; - int x1, y1, x2, y2; - - x1 = p1.x; - y1 = p1.y; - x2 = p2.x; - y2 = p2.y; - - xLength = abs(x2 - x1); - yLength = abs(y2 - y1); - - if (xLength > yLength) { - if (x1 > x2) { - BaseUtils::swap(&x1, &x2); - BaseUtils::swap(&y1, &y2); - } - - yStep = (double)(y2 - y1) / (double)(x2 - x1); - y = y1; - - for (xCount = x1; xCount < x2; xCount++) { - if (isBlockedAt(xCount, (int)y, true, requester)) { - return -1; - } - y += yStep; - } - } else { - if (y1 > y2) { - BaseUtils::swap(&x1, &x2); - BaseUtils::swap(&y1, &y2); - } - - xStep = (double)(x2 - x1) / (double)(y2 - y1); - x = x1; - - for (yCount = y1; yCount < y2; yCount++) { - if (isBlockedAt((int)x, yCount, true, requester)) { - return -1; - } - x += xStep; - } - } - return MAX(xLength, yLength); -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::pathFinderStep() { - int i; - // get lowest unmarked - int lowestDist = INT_MAX; - AdPathPoint *lowestPt = NULL; - - for (i = 0; i < _pfPointsNum; i++) - if (!_pfPath[i]->_marked && _pfPath[i]->_distance < lowestDist) { - lowestDist = _pfPath[i]->_distance; - lowestPt = _pfPath[i]; - } - - if (lowestPt == NULL) { // no path -> terminate PathFinder - _pfReady = true; - _pfTargetPath->setReady(true); - return; - } - - lowestPt->_marked = true; - - // target point marked, generate path and terminate - if (lowestPt->x == _pfTarget->x && lowestPt->y == _pfTarget->y) { - while (lowestPt != NULL) { - _pfTargetPath->_points.insert_at(0, new BasePoint(lowestPt->x, lowestPt->y)); - lowestPt = lowestPt->_origin; - } - - _pfReady = true; - _pfTargetPath->setReady(true); - return; - } - - // otherwise keep on searching - for (i = 0; i < _pfPointsNum; i++) - if (!_pfPath[i]->_marked) { - int j = getPointsDist(*lowestPt, *_pfPath[i], _pfRequester); - if (j != -1 && lowestPt->_distance + j < _pfPath[i]->_distance) { - _pfPath[i]->_distance = lowestPt->_distance + j; - _pfPath[i]->_origin = lowestPt; - } - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::initLoop() { -#ifdef _DEBUGxxxx - int nu_steps = 0; - uint32 start = _gameRef->_currentTime; - while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) { - PathFinderStep(); - nu_steps++; - } - if (nu_steps > 0) { - _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); - } -#else - uint32 start = _gameRef->_currentTime; - while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) { - pathFinderStep(); - } -#endif - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdScene::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); - } - - setFilename(filename); - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(SCENE) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(NAME) -TOKEN_DEF(LAYER) -TOKEN_DEF(WAYPOINTS) -TOKEN_DEF(EVENTS) -TOKEN_DEF(CURSOR) -TOKEN_DEF(CAMERA) -TOKEN_DEF(ENTITY) -TOKEN_DEF(SCALE_LEVEL) -TOKEN_DEF(ROTATION_LEVEL) -TOKEN_DEF(EDITOR_MARGIN_H) -TOKEN_DEF(EDITOR_MARGIN_V) -TOKEN_DEF(EDITOR_COLOR_FRAME) -TOKEN_DEF(EDITOR_COLOR_ENTITY_SEL) -TOKEN_DEF(EDITOR_COLOR_REGION_SEL) -TOKEN_DEF(EDITOR_COLOR_DECORATION_SEL) -TOKEN_DEF(EDITOR_COLOR_BLOCKED_SEL) -TOKEN_DEF(EDITOR_COLOR_WAYPOINTS_SEL) -TOKEN_DEF(EDITOR_COLOR_REGION) -TOKEN_DEF(EDITOR_COLOR_DECORATION) -TOKEN_DEF(EDITOR_COLOR_BLOCKED) -TOKEN_DEF(EDITOR_COLOR_ENTITY) -TOKEN_DEF(EDITOR_COLOR_WAYPOINTS) -TOKEN_DEF(EDITOR_COLOR_SCALE) -TOKEN_DEF(EDITOR_SHOW_REGIONS) -TOKEN_DEF(EDITOR_SHOW_BLOCKED) -TOKEN_DEF(EDITOR_SHOW_DECORATION) -TOKEN_DEF(EDITOR_SHOW_ENTITIES) -TOKEN_DEF(EDITOR_SHOW_SCALE) -TOKEN_DEF(SCRIPT) -TOKEN_DEF(CAPTION) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(VIEWPORT) -TOKEN_DEF(PERSISTENT_STATE_SPRITES) -TOKEN_DEF(PERSISTENT_STATE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdScene::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(SCENE) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(NAME) - TOKEN_TABLE(LAYER) - TOKEN_TABLE(WAYPOINTS) - TOKEN_TABLE(EVENTS) - TOKEN_TABLE(CURSOR) - TOKEN_TABLE(CAMERA) - TOKEN_TABLE(ENTITY) - TOKEN_TABLE(SCALE_LEVEL) - TOKEN_TABLE(ROTATION_LEVEL) - TOKEN_TABLE(EDITOR_MARGIN_H) - TOKEN_TABLE(EDITOR_MARGIN_V) - TOKEN_TABLE(EDITOR_COLOR_FRAME) - TOKEN_TABLE(EDITOR_COLOR_ENTITY_SEL) - TOKEN_TABLE(EDITOR_COLOR_REGION_SEL) - TOKEN_TABLE(EDITOR_COLOR_DECORATION_SEL) - TOKEN_TABLE(EDITOR_COLOR_BLOCKED_SEL) - TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS_SEL) - TOKEN_TABLE(EDITOR_COLOR_REGION) - TOKEN_TABLE(EDITOR_COLOR_DECORATION) - TOKEN_TABLE(EDITOR_COLOR_BLOCKED) - TOKEN_TABLE(EDITOR_COLOR_ENTITY) - TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS) - TOKEN_TABLE(EDITOR_COLOR_SCALE) - TOKEN_TABLE(EDITOR_SHOW_REGIONS) - TOKEN_TABLE(EDITOR_SHOW_DECORATION) - TOKEN_TABLE(EDITOR_SHOW_BLOCKED) - TOKEN_TABLE(EDITOR_SHOW_ENTITIES) - TOKEN_TABLE(EDITOR_SHOW_SCALE) - TOKEN_TABLE(SCRIPT) - TOKEN_TABLE(CAPTION) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(VIEWPORT) - TOKEN_TABLE(PERSISTENT_STATE_SPRITES) - TOKEN_TABLE(PERSISTENT_STATE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - cleanup(); - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCENE) { - _gameRef->LOG(0, "'SCENE' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - int ar, ag, ab, aa; - char camera[MAX_PATH_LENGTH] = ""; - /* float waypointHeight = -1.0f; */ - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_CAPTION: - setCaption((char *)params); - break; - - case TOKEN_LAYER: { - AdLayer *layer = new AdLayer(_gameRef); - if (!layer || DID_FAIL(layer->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete layer; - layer = NULL; - } else { - _gameRef->registerObject(layer); - _layers.add(layer); - if (layer->_main) { - _mainLayer = layer; - _width = layer->_width; - _height = layer->_height; - } - } - } - break; - - case TOKEN_WAYPOINTS: { - AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); - if (!wpt || DID_FAIL(wpt->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete wpt; - wpt = NULL; - } else { - _gameRef->registerObject(wpt); - _waypointGroups.add(wpt); - } - } - break; - - case TOKEN_SCALE_LEVEL: { - AdScaleLevel *sl = new AdScaleLevel(_gameRef); - if (!sl || DID_FAIL(sl->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete sl; - sl = NULL; - } else { - _gameRef->registerObject(sl); - _scaleLevels.add(sl); - } - } - break; - - case TOKEN_ROTATION_LEVEL: { - AdRotLevel *rl = new AdRotLevel(_gameRef); - if (!rl || DID_FAIL(rl->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete rl; - rl = NULL; - } else { - _gameRef->registerObject(rl); - _rotLevels.add(rl); - } - } - break; - - case TOKEN_ENTITY: { - AdEntity *entity = new AdEntity(_gameRef); - if (!entity || DID_FAIL(entity->loadBuffer(params, false))) { - cmd = PARSERR_GENERIC; - delete entity; - entity = NULL; - } else { - addObject(entity); - } - } - break; - - case TOKEN_CURSOR: - delete _cursor; - _cursor = new BaseSprite(_gameRef); - if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { - delete _cursor; - _cursor = NULL; - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_CAMERA: - strcpy(camera, (char *)params); - break; - - case TOKEN_EDITOR_MARGIN_H: - parser.scanStr((char *)params, "%d", &_editorMarginH); - break; - - case TOKEN_EDITOR_MARGIN_V: - parser.scanStr((char *)params, "%d", &_editorMarginV); - break; - - case TOKEN_EDITOR_COLOR_FRAME: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColFrame = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_ENTITY: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColEntity = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_ENTITY_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColEntitySel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_REGION_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColRegionSel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_DECORATION_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColDecorSel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_BLOCKED_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColBlockedSel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_WAYPOINTS_SEL: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColWaypointsSel = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_REGION: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColRegion = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_DECORATION: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColDecor = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_BLOCKED: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColBlocked = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_WAYPOINTS: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColWaypoints = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_COLOR_SCALE: - parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); - _editorColScale = BYTETORGBA(ar, ag, ab, aa); - break; - - case TOKEN_EDITOR_SHOW_REGIONS: - parser.scanStr((char *)params, "%b", &_editorShowRegions); - break; - - case TOKEN_EDITOR_SHOW_BLOCKED: - parser.scanStr((char *)params, "%b", &_editorShowBlocked); - break; - - case TOKEN_EDITOR_SHOW_DECORATION: - parser.scanStr((char *)params, "%b", &_editorShowDecor); - break; - - case TOKEN_EDITOR_SHOW_ENTITIES: - parser.scanStr((char *)params, "%b", &_editorShowEntities); - break; - - case TOKEN_EDITOR_SHOW_SCALE: - parser.scanStr((char *)params, "%b", &_editorShowScale); - break; - - case TOKEN_SCRIPT: - addScript((char *)params); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_VIEWPORT: { - Rect32 rc; - parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_viewport) { - _viewport = new BaseViewport(_gameRef); - } - if (_viewport) { - _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); - } - } - - case TOKEN_PERSISTENT_STATE: - parser.scanStr((char *)params, "%b", &_persistentState); - break; - - case TOKEN_PERSISTENT_STATE_SPRITES: - parser.scanStr((char *)params, "%b", &_persistentStateSprites); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in SCENE definition"); - return STATUS_FAILED; - } - - if (_mainLayer == NULL) { - _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", getFilename()); - } - - - sortScaleLevels(); - sortRotLevels(); - - _initialized = true; - - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdScene::traverseNodes(bool doUpdate) { - if (!_initialized) { - return STATUS_OK; - } - - AdGame *adGame = (AdGame *)_gameRef; - - - ////////////////////////////////////////////////////////////////////////// - // prepare viewport - bool popViewport = false; - if (_viewport && !_gameRef->_editorMode) { - _gameRef->pushViewport(_viewport); - popViewport = true; - } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - _gameRef->pushViewport(adGame->_sceneViewport); - popViewport = true; - } - - - ////////////////////////////////////////////////////////////////////////// - // *** adjust scroll offset - if (doUpdate) { - /* - if (_autoScroll && _gameRef->_mainObject != NULL) - { - ScrollToObject(_gameRef->_mainObject); - } - */ - - if (_autoScroll) { - // adjust horizontal scroll - if (_gameRef->_timer - _lastTimeH >= _scrollTimeH) { - _lastTimeH = _gameRef->_timer; - if (_offsetLeft < _targetOffsetLeft) { - _offsetLeft += _scrollPixelsH; - _offsetLeft = MIN(_offsetLeft, _targetOffsetLeft); - } else if (_offsetLeft > _targetOffsetLeft) { - _offsetLeft -= _scrollPixelsH; - _offsetLeft = MAX(_offsetLeft, _targetOffsetLeft); - } - } - - // adjust vertical scroll - if (_gameRef->_timer - _lastTimeV >= _scrollTimeV) { - _lastTimeV = _gameRef->_timer; - if (_offsetTop < _targetOffsetTop) { - _offsetTop += _scrollPixelsV; - _offsetTop = MIN(_offsetTop, _targetOffsetTop); - } else if (_offsetTop > _targetOffsetTop) { - _offsetTop -= _scrollPixelsV; - _offsetTop = MAX(_offsetTop, _targetOffsetTop); - } - } - - if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) { - _ready = true; - } - } else { - _ready = true; // not scrolling, i.e. always ready - } - } - - - - - ////////////////////////////////////////////////////////////////////////// - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - int viewportX, viewportY; - getViewportOffset(&viewportX, &viewportY); - - int scrollableX = _width - viewportWidth; - int scrollableY = _height - viewportHeight; - - double widthRatio = scrollableX <= 0 ? 0 : ((double)(_offsetLeft) / (double)scrollableX); - double heightRatio = scrollableY <= 0 ? 0 : ((double)(_offsetTop) / (double)scrollableY); - - int origX, origY; - _gameRef->getOffset(&origX, &origY); - - - - ////////////////////////////////////////////////////////////////////////// - // *** display/update everything - _gameRef->_renderer->setup2D(); - - // for each layer - /* int mainOffsetX = 0; */ - /* int mainOffsetY = 0; */ - - for (uint32 j = 0; j < _layers.size(); j++) { - if (!_layers[j]->_active) { - continue; - } - - // make layer exclusive - if (!doUpdate) { - if (_layers[j]->_closeUp && !_gameRef->_editorMode) { - if (!_shieldWindow) { - _shieldWindow = new UIWindow(_gameRef); - } - if (_shieldWindow) { - _shieldWindow->_posX = _shieldWindow->_posY = 0; - _shieldWindow->_width = _gameRef->_renderer->_width; - _shieldWindow->_height = _gameRef->_renderer->_height; - _shieldWindow->display(); - } - } - } - - if (_paralaxScrolling) { - int offsetX = (int)(widthRatio * (_layers[j]->_width - viewportWidth) - viewportX); - int offsetY = (int)(heightRatio * (_layers[j]->_height - viewportHeight) - viewportY); - _gameRef->setOffset(offsetX, offsetY); - - _gameRef->_offsetPercentX = (float)offsetX / ((float)_layers[j]->_width - viewportWidth) * 100.0f; - _gameRef->_offsetPercentY = (float)offsetY / ((float)_layers[j]->_height - viewportHeight) * 100.0f; - - //_gameRef->QuickMessageForm("%d %f", OffsetX+ViewportX, _gameRef->_offsetPercentX); - } else { - _gameRef->setOffset(_offsetLeft - viewportX, _offsetTop - viewportY); - - _gameRef->_offsetPercentX = (float)(_offsetLeft - viewportX) / ((float)_layers[j]->_width - viewportWidth) * 100.0f; - _gameRef->_offsetPercentY = (float)(_offsetTop - viewportY) / ((float)_layers[j]->_height - viewportHeight) * 100.0f; - } - - - // for each node - for (uint32 k = 0; k < _layers[j]->_nodes.size(); k++) { - AdSceneNode *node = _layers[j]->_nodes[k]; - switch (node->_type) { - case OBJECT_ENTITY: - if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) { - _gameRef->_renderer->setup2D(); - - if (doUpdate) { - node->_entity->update(); - } else { - node->_entity->display(); - } - } - break; - - case OBJECT_REGION: { - if (node->_region->_blocked) { - break; - } - if (node->_region->_decoration) { - break; - } - - if (!doUpdate) { - displayRegionContent(node->_region); - } - } - break; - default: - error("AdScene::TraverseNodes - Unhandled enum"); - break; - } // switch - } // each node - - // display/update all objects which are off-regions - if (_layers[j]->_main) { - if (doUpdate) { - updateFreeObjects(); - } else { - displayRegionContent(NULL); - } - } - } // each layer - - - // restore state - _gameRef->setOffset(origX, origY); - _gameRef->_renderer->setup2D(); - - // display/update fader - if (_fader) { - if (doUpdate) { - _fader->update(); - } else { - _fader->display(); - } - } - - if (popViewport) { - _gameRef->popViewport(); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::display() { - return traverseNodes(false); -} - -////////////////////////////////////////////////////////////////////////// -bool AdScene::updateFreeObjects() { - AdGame *adGame = (AdGame *)_gameRef; - // 3D-code removed - // bool is3DSet; - - // *** update all active objects - // is3DSet = false; - for (uint32 i = 0; i < adGame->_objects.size(); i++) { - if (!adGame->_objects[i]->_active) { - continue; - } - // 3D-code removed - adGame->_objects[i]->update(); - adGame->_objects[i]->_drawn = false; - } - - - for (uint32 i = 0; i < _objects.size(); i++) { - if (!_objects[i]->_active) { - continue; - } - - _objects[i]->update(); - _objects[i]->_drawn = false; - } - - - if (_autoScroll && _gameRef->_mainObject != NULL) { - scrollToObject(_gameRef->_mainObject); - } - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { - AdGame *adGame = (AdGame *)_gameRef; - BaseArray objects; - AdObject *obj; - - // global objects - for (uint32 i = 0; i < adGame->_objects.size(); i++) { - obj = adGame->_objects[i]; - if (obj->_active && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - objects.add(obj); - } - } - - // scene objects - for (uint32 i = 0; i < _objects.size(); i++) { - obj = _objects[i]; - if (obj->_active && !obj->_editorOnly && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - objects.add(obj); - } - } - - // sort by _posY - Common::sort(objects.begin(), objects.end(), AdScene::compareObjs); - - // display them - for (uint32 i = 0; i < objects.size(); i++) { - obj = objects[i]; - - if (display3DOnly && !obj->_is3D) { - continue; - } - - _gameRef->_renderer->setup2D(); - - if (_gameRef->_editorMode || !obj->_editorOnly) { - obj->display(); - } - obj->_drawn = true; - } - - - // display design only objects - if (!display3DOnly) { - if (_gameRef->_editorMode && region == NULL) { - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_active && _objects[i]->_editorOnly) { - _objects[i]->display(); - _objects[i]->_drawn = true; - } - } - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -int AdScene::compareObjs(const void *obj1, const void *obj2) { - const AdObject *object1 = *(const AdObject *const *)obj1; - const AdObject *object2 = *(const AdObject *const *)obj2; - - if (object1->_posY < object2->_posY) { - return -1; - } else if (object1->_posY > object2->_posY) { - return 1; - } else { - return 0; - } -} - -////////////////////////////////////////////////////////////////////////// -bool AdScene::displayRegionContentOld(AdRegion *region) { - AdGame *adGame = (AdGame *)_gameRef; - AdObject *obj; - - // display all objects in region sorted by _posY - do { - obj = NULL; - int minY = INT_MAX; - - // global objects - for (uint32 i = 0; i < adGame->_objects.size(); i++) { - if (adGame->_objects[i]->_active && !adGame->_objects[i]->_drawn && adGame->_objects[i]->_posY < minY && (adGame->_objects[i]->_stickRegion == region || region == NULL || (adGame->_objects[i]->_stickRegion == NULL && region->pointInRegion(adGame->_objects[i]->_posX, adGame->_objects[i]->_posY)))) { - obj = adGame->_objects[i]; - minY = adGame->_objects[i]->_posY; - } - } - - // scene objects - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_active && !_objects[i]->_editorOnly && !_objects[i]->_drawn && _objects[i]->_posY < minY && (_objects[i]->_stickRegion == region || region == NULL || (_objects[i]->_stickRegion == NULL && region->pointInRegion(_objects[i]->_posX, _objects[i]->_posY)))) { - obj = _objects[i]; - minY = _objects[i]->_posY; - } - } - - - if (obj != NULL) { - _gameRef->_renderer->setup2D(); - - if (_gameRef->_editorMode || !obj->_editorOnly) { - obj->display(); - } - obj->_drawn = true; - } - } while (obj != NULL); - - - // design only objects - if (_gameRef->_editorMode && region == NULL) { - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_active && _objects[i]->_editorOnly) { - _objects[i]->display(); - _objects[i]->_drawn = true; - } - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::update() { - return traverseNodes(true); -} - -////////////////////////////////////////////////////////////////////////// -void AdScene::scrollTo(int offsetX, int offsetY) { - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - int origOffsetLeft = _targetOffsetLeft; - int origOffsetTop = _targetOffsetTop; - - _targetOffsetLeft = MAX(0, offsetX - viewportWidth / 2); - _targetOffsetLeft = MIN(_targetOffsetLeft, _width - viewportWidth); - - _targetOffsetTop = MAX(0, offsetY - viewportHeight / 2); - _targetOffsetTop = MIN(_targetOffsetTop, _height - viewportHeight); - - - if (_gameRef->_mainObject && _gameRef->_mainObject->_is3D) { - if (abs(origOffsetLeft - _targetOffsetLeft) < 5) { - _targetOffsetLeft = origOffsetLeft; - } - if (abs(origOffsetTop - _targetOffsetTop) < 5) { - _targetOffsetTop = origOffsetTop; - } - //_targetOffsetTop = 0; - } - - _ready = false; -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::scrollToObject(BaseObject *object) { - if (object) { - scrollTo(object->_posX, object->_posY - object->getHeight() / 2); - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::skipToObject(BaseObject *object) { - if (object) { - skipTo(object->_posX, object->_posY - object->getHeight() / 2); - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::skipTo(int offsetX, int offsetY) { - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - _offsetLeft = MAX(0, offsetX - viewportWidth / 2); - _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); - - _offsetTop = MAX(0, offsetY - viewportHeight / 2); - _offsetTop = MIN(_offsetTop, _height - viewportHeight); - - _targetOffsetLeft = _offsetLeft; - _targetOffsetTop = _offsetTop; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // LoadActor - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "LoadActor") == 0) { - stack->correctParams(1); - AdActor *act = new AdActor(_gameRef); - if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { - addObject(act); - stack->pushNative(act, true); - } else { - delete act; - act = NULL; - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // LoadEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LoadEntity") == 0) { - stack->correctParams(1); - AdEntity *ent = new AdEntity(_gameRef); - if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { - addObject(ent); - stack->pushNative(ent, true); - } else { - delete ent; - ent = NULL; - stack->pushNULL(); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // CreateEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CreateEntity") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdEntity *ent = new AdEntity(_gameRef); - addObject(ent); - if (!val->isNULL()) { - ent->setName(val->getString()); - } - stack->pushNative(ent, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // UnloadObject / UnloadActor / UnloadEntity / UnloadActor3D / DeleteEntity - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "UnloadActor3D") == 0 || strcmp(name, "DeleteEntity") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - AdObject *obj = (AdObject *)val->getNative(); - removeObject(obj); - if (val->getType() == VAL_VARIABLE_REF) { - val->setNULL(); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SkipTo - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SkipTo") == 0) { - stack->correctParams(2); - ScValue *val1 = stack->pop(); - ScValue *val2 = stack->pop(); - if (val1->isNative()) { - skipToObject((BaseObject *)val1->getNative()); - } else { - skipTo(val1->getInt(), val2->getInt()); - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollTo / ScrollToAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollTo") == 0 || strcmp(name, "ScrollToAsync") == 0) { - stack->correctParams(2); - ScValue *val1 = stack->pop(); - ScValue *val2 = stack->pop(); - if (val1->isNative()) { - scrollToObject((BaseObject *)val1->getNative()); - } else { - scrollTo(val1->getInt(), val2->getInt()); - } - if (strcmp(name, "ScrollTo") == 0) { - script->waitForExclusive(this); - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetLayer - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetLayer") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - if (val->isInt()) { - int layer = val->getInt(); - if (layer < 0 || layer >= (int32)_layers.size()) { - stack->pushNULL(); - } else { - stack->pushNative(_layers[layer], true); - } - } else { - const char *layerName = val->getString(); - bool layerFound = false; - for (uint32 i = 0; i < _layers.size(); i++) { - if (scumm_stricmp(layerName, _layers[i]->getName()) == 0) { - stack->pushNative(_layers[i], true); - layerFound = true; - break; - } - } - if (!layerFound) { - stack->pushNULL(); - } - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetWaypointGroup - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetWaypointGroup") == 0) { - stack->correctParams(1); - int group = stack->pop()->getInt(); - if (group < 0 || group >= (int32)_waypointGroups.size()) { - stack->pushNULL(); - } else { - stack->pushNative(_waypointGroups[group], true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetNode - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetNode") == 0) { - stack->correctParams(1); - const char *nodeName = stack->pop()->getString(); - - BaseObject *node = getNodeByName(nodeName); - if (node) { - stack->pushNative((BaseScriptable *)node, true); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetFreeNode - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetFreeNode") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdObject *ret = NULL; - if (val->isInt()) { - int index = val->getInt(); - if (index >= 0 && index < (int32)_objects.size()) { - ret = _objects[index]; - } - } else { - const char *nodeName = val->getString(); - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i] && _objects[i]->getName() && scumm_stricmp(_objects[i]->getName(), nodeName) == 0) { - ret = _objects[i]; - break; - } - } - } - if (ret) { - stack->pushNative(ret, true); - } else { - stack->pushNULL(); - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetRegionAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetRegionAt") == 0) { - stack->correctParams(3); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - ScValue *val = stack->pop(); - - bool includeDecors = false; - if (!val->isNULL()) { - includeDecors = val->getBool(); - } - - if (_mainLayer) { - for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { - AdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { - if (node->_region->_decoration && !includeDecors) { - continue; - } - - stack->pushNative(node->_region, true); - return STATUS_OK; - } - } - } - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsBlockedAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsBlockedAt") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - - stack->pushBool(isBlockedAt(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsWalkableAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsWalkableAt") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - - stack->pushBool(isWalkableAt(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetScaleAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetScaleAt") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - - stack->pushFloat(getZoomAt(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetRotationAt - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetRotationAt") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - - stack->pushFloat(getRotationAt(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsScrolling - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsScrolling") == 0) { - stack->correctParams(0); - bool ret = false; - if (_autoScroll) { - if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) { - ret = true; - } - } - - stack->pushBool(ret); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // FadeOut / FadeOutAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "FadeOut") == 0 || strcmp(name, "FadeOutAsync") == 0) { - stack->correctParams(5); - uint32 duration = stack->pop()->getInt(500); - byte red = stack->pop()->getInt(0); - byte green = stack->pop()->getInt(0); - byte blue = stack->pop()->getInt(0); - byte alpha = stack->pop()->getInt(0xFF); - - _fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration); - if (strcmp(name, "FadeOutAsync") != 0) { - script->waitFor(_fader); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // FadeIn / FadeInAsync - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "FadeIn") == 0 || strcmp(name, "FadeInAsync") == 0) { - stack->correctParams(5); - uint32 duration = stack->pop()->getInt(500); - byte red = stack->pop()->getInt(0); - byte green = stack->pop()->getInt(0); - byte blue = stack->pop()->getInt(0); - byte alpha = stack->pop()->getInt(0xFF); - - _fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration); - if (strcmp(name, "FadeInAsync") != 0) { - script->waitFor(_fader); - } - - stack->pushNULL(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetFadeColor - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetFadeColor") == 0) { - stack->correctParams(0); - stack->pushInt(_fader->getCurrentColor()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // IsPointInViewport - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IsPointInViewport") == 0) { - stack->correctParams(2); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - stack->pushBool(pointInViewport(x, y)); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetViewport - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SetViewport") == 0) { - stack->correctParams(4); - int x = stack->pop()->getInt(); - int y = stack->pop()->getInt(); - int width = stack->pop()->getInt(); - int height = stack->pop()->getInt(); - - if (width <= 0) { - width = _gameRef->_renderer->_width; - } - if (height <= 0) { - height = _gameRef->_renderer->_height; - } - - if (!_viewport) { - _viewport = new BaseViewport(_gameRef); - } - if (_viewport) { - _viewport->setRect(x, y, x + width, y + height); - } - - stack->pushBool(true); - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddLayer - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddLayer") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdLayer *layer = new AdLayer(_gameRef); - if (!val->isNULL()) { - layer->setName(val->getString()); - } - if (_mainLayer) { - layer->_width = _mainLayer->_width; - layer->_height = _mainLayer->_height; - } - _layers.add(layer); - _gameRef->registerObject(layer); - - stack->pushNative(layer, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // InsertLayer - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InsertLayer") == 0) { - stack->correctParams(2); - int index = stack->pop()->getInt(); - ScValue *val = stack->pop(); - - AdLayer *layer = new AdLayer(_gameRef); - if (!val->isNULL()) { - layer->setName(val->getString()); - } - if (_mainLayer) { - layer->_width = _mainLayer->_width; - layer->_height = _mainLayer->_height; - } - if (index < 0) { - index = 0; - } - if (index <= (int32)_layers.size() - 1) { - _layers.insert_at(index, layer); - } else { - _layers.add(layer); - } - - _gameRef->registerObject(layer); - - stack->pushNative(layer, true); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // DeleteLayer - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DeleteLayer") == 0) { - stack->correctParams(1); - ScValue *val = stack->pop(); - - AdLayer *toDelete = NULL; - if (val->isNative()) { - BaseScriptable *temp = val->getNative(); - for (uint32 i = 0; i < _layers.size(); i++) { - if (_layers[i] == temp) { - toDelete = _layers[i]; - break; - } - } - } else { - int index = val->getInt(); - if (index >= 0 && index < (int32)_layers.size()) { - toDelete = _layers[index]; - } - } - if (toDelete == NULL) { - stack->pushBool(false); - return STATUS_OK; - } - - if (toDelete->_main) { - script->runtimeError("Scene.DeleteLayer - cannot delete main scene layer"); - stack->pushBool(false); - return STATUS_OK; - } - - for (uint32 i = 0; i < _layers.size(); i++) { - if (_layers[i] == toDelete) { - _layers.remove_at(i); - _gameRef->unregisterObject(toDelete); - break; - } - } - stack->pushBool(true); - return STATUS_OK; - } else { - return BaseObject::scCallMethod(script, stack, thisStack, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdScene::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("scene"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumLayers (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumLayers") == 0) { - _scValue->setInt(_layers.size()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumWaypointGroups (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumWaypointGroups") == 0) { - _scValue->setInt(_waypointGroups.size()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // MainLayer (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MainLayer") == 0) { - if (_mainLayer) { - _scValue->setNative(_mainLayer, true); - } else { - _scValue->setNULL(); - } - - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // NumFreeNodes (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumFreeNodes") == 0) { - _scValue->setInt(_objects.size()); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // MouseX (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MouseX") == 0) { - int viewportX; - getViewportOffset(&viewportX); - - _scValue->setInt(_gameRef->_mousePos.x + _offsetLeft - viewportX); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // MouseY (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MouseY") == 0) { - int viewportY; - getViewportOffset(NULL, &viewportY); - - _scValue->setInt(_gameRef->_mousePos.y + _offsetTop - viewportY); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // AutoScroll - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AutoScroll") == 0) { - _scValue->setBool(_autoScroll); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // PersistentState - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentState") == 0) { - _scValue->setBool(_persistentState); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // PersistentStateSprites - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentStateSprites") == 0) { - _scValue->setBool(_persistentStateSprites); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollPixelsX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsX") == 0) { - _scValue->setInt(_scrollPixelsH); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollPixelsY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsY") == 0) { - _scValue->setInt(_scrollPixelsV); - return _scValue; - } - - - ////////////////////////////////////////////////////////////////////////// - // ScrollSpeedX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedX") == 0) { - _scValue->setInt(_scrollTimeH); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollSpeedY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedY") == 0) { - _scValue->setInt(_scrollTimeV); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // OffsetX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetX") == 0) { - _scValue->setInt(_offsetLeft); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // OffsetY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetY") == 0) { - _scValue->setInt(_offsetTop); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Width (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Width") == 0) { - if (_mainLayer) { - _scValue->setInt(_mainLayer->_width); - } else { - _scValue->setInt(0); - } - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Height (RO) - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Height") == 0) { - if (_mainLayer) { - _scValue->setInt(_mainLayer->_height); - } else { - _scValue->setInt(0); - } - return _scValue; - } else { - return BaseObject::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::scSetProperty(const char *name, ScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Name - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Name") == 0) { - setName(value->getString()); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AutoScroll - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AutoScroll") == 0) { - _autoScroll = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // PersistentState - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentState") == 0) { - _persistentState = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // PersistentStateSprites - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentStateSprites") == 0) { - _persistentStateSprites = value->getBool(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollPixelsX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsX") == 0) { - _scrollPixelsH = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollPixelsY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsY") == 0) { - _scrollPixelsV = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollSpeedX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedX") == 0) { - _scrollTimeH = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // ScrollSpeedY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedY") == 0) { - _scrollTimeV = value->getInt(); - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // OffsetX - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetX") == 0) { - _offsetLeft = value->getInt(); - - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - _offsetLeft = MAX(0, _offsetLeft - viewportWidth / 2); - _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); - _targetOffsetLeft = _offsetLeft; - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // OffsetY - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetY") == 0) { - _offsetTop = value->getInt(); - - int viewportWidth, viewportHeight; - getViewportSize(&viewportWidth, &viewportHeight); - - _offsetTop = MAX(0, _offsetTop - viewportHeight / 2); - _offsetTop = MIN(_offsetTop, _height - viewportHeight); - _targetOffsetTop = _offsetTop; - - return STATUS_OK; - } else { - return BaseObject::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdScene::scToString() { - return "[scene object]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::addObject(AdObject *object) { - _objects.add(object); - return _gameRef->registerObject(object); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::removeObject(AdObject *object) { - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i] == object) { - _objects.remove_at(i); - return _gameRef->unregisterObject(object); - } - } - return STATUS_FAILED; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "SCENE {\n"); - - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - - if (_persistentState) { - buffer->putTextIndent(indent + 2, "PERSISTENT_STATE=%s\n", _persistentState ? "TRUE" : "FALSE"); - } - - if (!_persistentStateSprites) { - buffer->putTextIndent(indent + 2, "PERSISTENT_STATE_SPRITES=%s\n", _persistentStateSprites ? "TRUE" : "FALSE"); - } - - - // scripts - for (uint32 i = 0; i < _scripts.size(); i++) { - buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); - } - - buffer->putTextIndent(indent + 2, "\n"); - - // properties - if (_scProp) { - _scProp->saveAsText(buffer, indent + 2); - } - - // viewport - if (_viewport) { - Rect32 *rc = _viewport->getRect(); - buffer->putTextIndent(indent + 2, "VIEWPORT { %d, %d, %d, %d }\n", rc->left, rc->top, rc->right, rc->bottom); - } - - - - // editor settings - buffer->putTextIndent(indent + 2, "; ----- editor settings\n"); - buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_H=%d\n", _editorMarginH); - buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_V=%d\n", _editorMarginV); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_FRAME { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColFrame), RGBCOLGetG(_editorColFrame), RGBCOLGetB(_editorColFrame), RGBCOLGetA(_editorColFrame)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntitySel), RGBCOLGetG(_editorColEntitySel), RGBCOLGetB(_editorColEntitySel), RGBCOLGetA(_editorColEntitySel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegionSel), RGBCOLGetG(_editorColRegionSel), RGBCOLGetB(_editorColRegionSel), RGBCOLGetA(_editorColRegionSel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlockedSel), RGBCOLGetG(_editorColBlockedSel), RGBCOLGetB(_editorColBlockedSel), RGBCOLGetA(_editorColBlockedSel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecorSel), RGBCOLGetG(_editorColDecorSel), RGBCOLGetB(_editorColDecorSel), RGBCOLGetA(_editorColDecorSel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypointsSel), RGBCOLGetG(_editorColWaypointsSel), RGBCOLGetB(_editorColWaypointsSel), RGBCOLGetA(_editorColWaypointsSel)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntity), RGBCOLGetG(_editorColEntity), RGBCOLGetB(_editorColEntity), RGBCOLGetA(_editorColEntity)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegion), RGBCOLGetG(_editorColRegion), RGBCOLGetB(_editorColRegion), RGBCOLGetA(_editorColRegion)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecor), RGBCOLGetG(_editorColDecor), RGBCOLGetB(_editorColDecor), RGBCOLGetA(_editorColDecor)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlocked), RGBCOLGetG(_editorColBlocked), RGBCOLGetB(_editorColBlocked), RGBCOLGetA(_editorColBlocked)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypoints), RGBCOLGetG(_editorColWaypoints), RGBCOLGetB(_editorColWaypoints), RGBCOLGetA(_editorColWaypoints)); - buffer->putTextIndent(indent + 2, "EDITOR_COLOR_SCALE { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColScale), RGBCOLGetG(_editorColScale), RGBCOLGetB(_editorColScale), RGBCOLGetA(_editorColScale)); - - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_REGIONS=%s\n", _editorShowRegions ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_BLOCKED=%s\n", _editorShowBlocked ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_DECORATION=%s\n", _editorShowDecor ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_ENTITIES=%s\n", _editorShowEntities ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SHOW_SCALE=%s\n", _editorShowScale ? "TRUE" : "FALSE"); - - buffer->putTextIndent(indent + 2, "\n"); - - BaseClass::saveAsText(buffer, indent + 2); - - // waypoints - buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); - for (uint32 i = 0; i < _waypointGroups.size(); i++) { - _waypointGroups[i]->saveAsText(buffer, indent + 2); - } - - buffer->putTextIndent(indent + 2, "\n"); - - // layers - buffer->putTextIndent(indent + 2, "; ----- layers\n"); - for (uint32 i = 0; i < _layers.size(); i++) { - _layers[i]->saveAsText(buffer, indent + 2); - } - - // scale levels - buffer->putTextIndent(indent + 2, "; ----- scale levels\n"); - for (uint32 i = 0; i < _scaleLevels.size(); i++) { - _scaleLevels[i]->saveAsText(buffer, indent + 2); - } - - // rotation levels - buffer->putTextIndent(indent + 2, "; ----- rotation levels\n"); - for (uint32 i = 0; i < _rotLevels.size(); i++) { - _rotLevels[i]->saveAsText(buffer, indent + 2); - } - - - buffer->putTextIndent(indent + 2, "\n"); - - // free entities - buffer->putTextIndent(indent + 2, "; ----- free entities\n"); - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_type == OBJECT_ENTITY) { - _objects[i]->saveAsText(buffer, indent + 2); - - } - } - - buffer->putTextIndent(indent, "}\n"); - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::sortScaleLevels() { - if (_scaleLevels.size() == 0) { - return STATUS_OK; - } - bool changed; - do { - changed = false; - for (uint32 i = 0; i < _scaleLevels.size() - 1; i++) { - if (_scaleLevels[i]->_posY > _scaleLevels[i + 1]->_posY) { - AdScaleLevel *sl = _scaleLevels[i]; - _scaleLevels[i] = _scaleLevels[i + 1]; - _scaleLevels[i + 1] = sl; - - changed = true; - } - } - - } while (changed); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::sortRotLevels() { - if (_rotLevels.size() == 0) { - return STATUS_OK; - } - bool changed; - do { - changed = false; - for (uint32 i = 0; i < _rotLevels.size() - 1; i++) { - if (_rotLevels[i]->_posX > _rotLevels[i + 1]->_posX) { - AdRotLevel *rl = _rotLevels[i]; - _rotLevels[i] = _rotLevels[i + 1]; - _rotLevels[i + 1] = rl; - - changed = true; - } - } - - } while (changed); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -float AdScene::getScaleAt(int Y) { - AdScaleLevel *prev = NULL; - AdScaleLevel *next = NULL; - - for (uint32 i = 0; i < _scaleLevels.size(); i++) { - /* AdScaleLevel *xxx = _scaleLevels[i];*/ - /* int j = _scaleLevels.size(); */ - if (_scaleLevels[i]->_posY < Y) { - prev = _scaleLevels[i]; - } else { - next = _scaleLevels[i]; - break; - } - } - - if (prev == NULL || next == NULL) { - return 100; - } - - int delta_y = next->_posY - prev->_posY; - float delta_scale = next->_scale - prev->_scale; - Y -= prev->_posY; - - float percent = (float)Y / ((float)delta_y / 100.0f); - return prev->_scale + delta_scale / 100 * percent; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::persist(BasePersistenceManager *persistMgr) { - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_autoScroll)); - persistMgr->transfer(TMEMBER(_editorColBlocked)); - persistMgr->transfer(TMEMBER(_editorColBlockedSel)); - persistMgr->transfer(TMEMBER(_editorColDecor)); - persistMgr->transfer(TMEMBER(_editorColDecorSel)); - persistMgr->transfer(TMEMBER(_editorColEntity)); - persistMgr->transfer(TMEMBER(_editorColEntitySel)); - persistMgr->transfer(TMEMBER(_editorColFrame)); - persistMgr->transfer(TMEMBER(_editorColRegion)); - persistMgr->transfer(TMEMBER(_editorColRegionSel)); - persistMgr->transfer(TMEMBER(_editorColScale)); - persistMgr->transfer(TMEMBER(_editorColWaypoints)); - persistMgr->transfer(TMEMBER(_editorColWaypointsSel)); - persistMgr->transfer(TMEMBER(_editorMarginH)); - persistMgr->transfer(TMEMBER(_editorMarginV)); - persistMgr->transfer(TMEMBER(_editorShowBlocked)); - persistMgr->transfer(TMEMBER(_editorShowDecor)); - persistMgr->transfer(TMEMBER(_editorShowEntities)); - persistMgr->transfer(TMEMBER(_editorShowRegions)); - persistMgr->transfer(TMEMBER(_editorShowScale)); - persistMgr->transfer(TMEMBER(_fader)); - persistMgr->transfer(TMEMBER(_height)); - persistMgr->transfer(TMEMBER(_initialized)); - persistMgr->transfer(TMEMBER(_lastTimeH)); - persistMgr->transfer(TMEMBER(_lastTimeV)); - _layers.persist(persistMgr); - persistMgr->transfer(TMEMBER(_mainLayer)); - _objects.persist(persistMgr); - persistMgr->transfer(TMEMBER(_offsetLeft)); - persistMgr->transfer(TMEMBER(_offsetTop)); - persistMgr->transfer(TMEMBER(_paralaxScrolling)); - persistMgr->transfer(TMEMBER(_persistentState)); - persistMgr->transfer(TMEMBER(_persistentStateSprites)); - persistMgr->transfer(TMEMBER(_pfMaxTime)); - _pfPath.persist(persistMgr); - persistMgr->transfer(TMEMBER(_pfPointsNum)); - persistMgr->transfer(TMEMBER(_pfReady)); - persistMgr->transfer(TMEMBER(_pfRequester)); - persistMgr->transfer(TMEMBER(_pfTarget)); - persistMgr->transfer(TMEMBER(_pfTargetPath)); - _rotLevels.persist(persistMgr); - _scaleLevels.persist(persistMgr); - persistMgr->transfer(TMEMBER(_scrollPixelsH)); - persistMgr->transfer(TMEMBER(_scrollPixelsV)); - persistMgr->transfer(TMEMBER(_scrollTimeH)); - persistMgr->transfer(TMEMBER(_scrollTimeV)); - persistMgr->transfer(TMEMBER(_shieldWindow)); - persistMgr->transfer(TMEMBER(_targetOffsetLeft)); - persistMgr->transfer(TMEMBER(_targetOffsetTop)); - _waypointGroups.persist(persistMgr); - persistMgr->transfer(TMEMBER(_viewport)); - persistMgr->transfer(TMEMBER(_width)); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdScene::afterLoad() { - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, BaseObject *requester) { - double xStep, yStep, x, y; - int xLength, yLength, xCount, yCount; - int x1, y1, x2, y2; - - x1 = *targetX; - y1 = *targetY; - x2 = startX; - y2 = startY; - - - xLength = abs(x2 - x1); - yLength = abs(y2 - y1); - - if (xLength > yLength) { - - yStep = fabs((double)(y2 - y1) / (double)(x2 - x1)); - y = y1; - - for (xCount = x1; xCount < x2; xCount++) { - if (isWalkableAt(xCount, (int)y, checkFreeObjects, requester)) { - *targetX = xCount; - *targetY = (int)y; - return STATUS_OK; - } - y += yStep; - } - } else { - - xStep = fabs((double)(x2 - x1) / (double)(y2 - y1)); - x = x1; - - for (yCount = y1; yCount < y2; yCount++) { - if (isWalkableAt((int)x, yCount, checkFreeObjects, requester)) { - *targetX = (int)x; - *targetY = yCount; - return STATUS_OK; - } - x += xStep; - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, bool checkFreeObjects, BaseObject *requester) { - int x = *argX; - int y = *argY; - - if (isWalkableAt(x, y, checkFreeObjects, requester) || !_mainLayer) { - return STATUS_OK; - } - - // right - int lengthRight = 0; - bool foundRight = false; - for (x = *argX, y = *argY; x < _mainLayer->_width; x++, lengthRight++) { - if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x - 5, y, checkFreeObjects, requester)) { - foundRight = true; - break; - } - } - - // left - int lengthLeft = 0; - bool foundLeft = false; - for (x = *argX, y = *argY; x >= 0; x--, lengthLeft--) { - if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x + 5, y, checkFreeObjects, requester)) { - foundLeft = true; - break; - } - } - - // up - int lengthUp = 0; - bool foundUp = false; - for (x = *argX, y = *argY; y >= 0; y--, lengthUp--) { - if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y + 5, checkFreeObjects, requester)) { - foundUp = true; - break; - } - } - - // down - int lengthDown = 0; - bool foundDown = false; - for (x = *argX, y = *argY; y < _mainLayer->_height; y++, lengthDown++) { - if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y - 5, checkFreeObjects, requester)) { - foundDown = true; - break; - } - } - - if (!foundLeft && !foundRight && !foundUp && !foundDown) { - return STATUS_OK; - } - - int offsetX = INT_MAX, offsetY = INT_MAX; - - if (foundLeft && foundRight) { - if (abs(lengthLeft) < abs(lengthRight)) { - offsetX = lengthLeft; - } else { - offsetX = lengthRight; - } - } else if (foundLeft) { - offsetX = lengthLeft; - } else if (foundRight) { - offsetX = lengthRight; - } - - if (foundUp && foundDown) { - if (abs(lengthUp) < abs(lengthDown)) { - offsetY = lengthUp; - } else { - offsetY = lengthDown; - } - } else if (foundUp) { - offsetY = lengthUp; - } else if (foundDown) { - offsetY = lengthDown; - } - - if (abs(offsetX) < abs(offsetY)) { - *argX = *argX + offsetX; - } else { - *argY = *argY + offsetY; - } - - if (!isWalkableAt(*argX, *argY)) { - return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); - } else { - return STATUS_OK; - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::pfPointsStart() { - _pfPointsNum = 0; -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::pfPointsAdd(int x, int y, int distance) { - if (_pfPointsNum >= (int32)_pfPath.size()) { - _pfPath.add(new AdPathPoint(x, y, distance)); - } else { - _pfPath[_pfPointsNum]->x = x; - _pfPath[_pfPointsNum]->y = y; - _pfPath[_pfPointsNum]->_distance = distance; - _pfPath[_pfPointsNum]->_marked = false; - _pfPath[_pfPointsNum]->_origin = NULL; - } - - _pfPointsNum++; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::getViewportOffset(int *offsetX, int *offsetY) { - AdGame *adGame = (AdGame *)_gameRef; - if (_viewport && !_gameRef->_editorMode) { - if (offsetX) { - *offsetX = _viewport->_offsetX; - } - if (offsetY) { - *offsetY = _viewport->_offsetY; - } - } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - if (offsetX) { - *offsetX = adGame->_sceneViewport->_offsetX; - } - if (offsetY) { - *offsetY = adGame->_sceneViewport->_offsetY; - } - } else { - if (offsetX) { - *offsetX = 0; - } - if (offsetY) { - *offsetY = 0; - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::getViewportSize(int *width, int *height) { - AdGame *adGame = (AdGame *)_gameRef; - if (_viewport && !_gameRef->_editorMode) { - if (width) { - *width = _viewport->getWidth(); - } - if (height) { - *height = _viewport->getHeight(); - } - } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - if (width) { - *width = adGame->_sceneViewport->getWidth(); - } - if (height) { - *height = adGame->_sceneViewport->getHeight(); - } - } else { - if (width) { - *width = _gameRef->_renderer->_width; - } - if (height) { - *height = _gameRef->_renderer->_height; - } - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -int AdScene::getOffsetLeft() { - int viewportX; - getViewportOffset(&viewportX); - - return _offsetLeft - viewportX; -} - - -////////////////////////////////////////////////////////////////////////// -int AdScene::getOffsetTop() { - int viewportY; - getViewportOffset(NULL, &viewportY); - - return _offsetTop - viewportY; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::pointInViewport(int x, int y) { - int left, top, width, height; - - getViewportOffset(&left, &top); - getViewportSize(&width, &height); - - return x >= left && x <= left + width && y >= top && y <= top + height; -} - - -////////////////////////////////////////////////////////////////////////// -void AdScene::setOffset(int offsetLeft, int offsetTop) { - _offsetLeft = offsetLeft; - _offsetTop = offsetTop; -} - - -////////////////////////////////////////////////////////////////////////// -BaseObject *AdScene::getNodeByName(const char *name) { - BaseObject *ret = NULL; - - // dependent objects - for (uint32 i = 0; i < _layers.size(); i++) { - AdLayer *layer = _layers[i]; - for (uint32 j = 0; j < layer->_nodes.size(); j++) { - AdSceneNode *node = layer->_nodes[j]; - if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->getName())) || - (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->getName()))) { - switch (node->_type) { - case OBJECT_ENTITY: - ret = node->_entity; - break; - case OBJECT_REGION: - ret = node->_region; - break; - default: - ret = NULL; - } - return ret; - } - } - } - - // free entities - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->getName())) { - return _objects[i]; - } - } - - // waypoint groups - for (uint32 i = 0; i < _waypointGroups.size(); i++) { - if (!scumm_stricmp(name, _waypointGroups[i]->getName())) { - return _waypointGroups[i]; - } - } - - return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::saveState() { - return persistState(true); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::loadState() { - return persistState(false); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::persistState(bool saving) { - if (!_persistentState) { - return STATUS_OK; - } - - AdGame *adGame = (AdGame *)_gameRef; - AdSceneState *state = adGame->getSceneState(getFilename(), saving); - if (!state) { - return STATUS_OK; - } - - AdNodeState *nodeState; - - // dependent objects - for (uint32 i = 0; i < _layers.size(); i++) { - AdLayer *layer = _layers[i]; - for (uint32 j = 0; j < layer->_nodes.size(); j++) { - AdSceneNode *node = layer->_nodes[j]; - switch (node->_type) { - case OBJECT_ENTITY: - if (!node->_entity->_saveState) { - continue; - } - nodeState = state->getNodeState(node->_entity->getName(), saving); - if (nodeState) { - nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); - //if (Saving) NodeState->_active = node->_entity->_active; - //else node->_entity->_active = NodeState->_active; - } - break; - case OBJECT_REGION: - if (!node->_region->_saveState) { - continue; - } - nodeState = state->getNodeState(node->_region->getName(), saving); - if (nodeState) { - if (saving) { - nodeState->_active = node->_region->_active; - } else { - node->_region->_active = nodeState->_active; - } - } - break; - default: - warning("AdScene::PersistState - unhandled enum"); - break; - } - } - } - - // free entities - for (uint32 i = 0; i < _objects.size(); i++) { - if (!_objects[i]->_saveState) { - continue; - } - if (_objects[i]->_type == OBJECT_ENTITY) { - nodeState = state->getNodeState(_objects[i]->getName(), saving); - if (nodeState) { - nodeState->transferEntity((AdEntity *)_objects[i], _persistentStateSprites, saving); - //if (Saving) NodeState->_active = _objects[i]->_active; - //else _objects[i]->_active = NodeState->_active; - } - } - } - - // waypoint groups - for (uint32 i = 0; i < _waypointGroups.size(); i++) { - nodeState = state->getNodeState(_waypointGroups[i]->getName(), saving); - if (nodeState) { - if (saving) { - nodeState->_active = _waypointGroups[i]->_active; - } else { - _waypointGroups[i]->_active = nodeState->_active; - } - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -float AdScene::getRotationAt(int x, int y) { - AdRotLevel *prev = NULL; - AdRotLevel *next = NULL; - - for (uint32 i = 0; i < _rotLevels.size(); i++) { - /* AdRotLevel *xxx = _rotLevels[i]; - int j = _rotLevels.size();*/ - if (_rotLevels[i]->_posX < x) { - prev = _rotLevels[i]; - } else { - next = _rotLevels[i]; - break; - } - } - - if (prev == NULL || next == NULL) { - return 0; - } - - int delta_x = next->_posX - prev->_posX; - float delta_rot = next->_rotation - prev->_rotation; - x -= prev->_posX; - - float percent = (float)x / ((float)delta_x / 100.0f); - return prev->_rotation + delta_rot / 100 * percent; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::handleItemAssociations(const char *itemName, bool show) { - for (uint32 i = 0; i < _layers.size(); i++) { - AdLayer *layer = _layers[i]; - for (uint32 j = 0; j < layer->_nodes.size(); j++) { - if (layer->_nodes[j]->_type == OBJECT_ENTITY) { - AdEntity *ent = layer->_nodes[j]->_entity; - - if (ent->_item && strcmp(ent->_item, itemName) == 0) { - ent->_active = show; - } - } - } - } - - for (uint32 i = 0; i < _objects.size(); i++) { - if (_objects[i]->_type == OBJECT_ENTITY) { - AdEntity *ent = (AdEntity *)_objects[i]; - if (ent->_item && strcmp(ent->_item, itemName) == 0) { - ent->_active = show; - } - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::getRegionsAt(int x, int y, AdRegion **regionList, int numRegions) { - int numUsed = 0; - if (_mainLayer) { - for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { - AdSceneNode *node = _mainLayer->_nodes[i]; - if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { - if (numUsed < numRegions - 1) { - regionList[numUsed] = node->_region; - numUsed++; - } else { - break; - } - } - } - } - for (int i = numUsed; i < numRegions; i++) { - regionList[i] = NULL; - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdScene::restoreDeviceObjects() { - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) { - BaseArray objects; - getSceneObjects(objects, true); - - if (objects.size() == 0) { - return NULL; - } else { - if (currObject != NULL) { - for (uint32 i = 0; i < objects.size(); i++) { - if (objects[i] == currObject) { - if (i < objects.size() - 1) { - return objects[i + 1]; - } else { - break; - } - } - } - } - return objects[0]; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { - BaseArray objects; - getSceneObjects(objects, true); - - if (objects.size() == 0) { - return NULL; - } else { - if (currObject != NULL) { - for (int i = objects.size() - 1; i >= 0; i--) { - if (objects[i] == currObject) { - if (i > 0) { - return objects[i - 1]; - } else { - break; - } - } - } - } - return objects[objects.size() - 1]; - } - return NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOnly) { - for (uint32 i = 0; i < _layers.size(); i++) { - // close-up layer -> remove everything below it - if (interactiveOnly && _layers[i]->_closeUp) { - objects.clear(); - } - - - for (uint32 j = 0; j < _layers[i]->_nodes.size(); j++) { - AdSceneNode *node = _layers[i]->_nodes[j]; - switch (node->_type) { - case OBJECT_ENTITY: { - AdEntity *ent = node->_entity; - if (ent->_active && (ent->_registrable || !interactiveOnly)) { - objects.add(ent); - } - } - break; - - case OBJECT_REGION: { - BaseArray regionObj; - getRegionObjects(node->_region, regionObj, interactiveOnly); - for (uint32 newIndex = 0; newIndex < regionObj.size(); newIndex++) { - bool found = false; - for (uint32 old = 0; old < objects.size(); old++) { - if (objects[old] == regionObj[newIndex]) { - found = true; - break; - } - } - if (!found) { - objects.add(regionObj[newIndex]); - } - } - //if (regionObj.size() > 0) Objects.Append(RegionObj); - } - break; - default: - debugC(kWintermuteDebugGeneral, "AdScene::GetSceneObjects - Unhandled enum"); - break; - } - } - } - - // objects outside any region - BaseArray regionObj; - getRegionObjects(NULL, regionObj, interactiveOnly); - for (uint32 newIndex = 0; newIndex < regionObj.size(); newIndex++) { - bool found = false; - for (uint32 old = 0; old < objects.size(); old++) { - if (objects[old] == regionObj[newIndex]) { - found = true; - break; - } - } - if (!found) { - objects.add(regionObj[newIndex]); - } - } - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, bool interactiveOnly) { - AdGame *adGame = (AdGame *)_gameRef; - AdObject *obj; - - // global objects - for (uint32 i = 0; i < adGame->_objects.size(); i++) { - obj = adGame->_objects[i]; - if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - if (interactiveOnly && !obj->_registrable) { - continue; - } - - objects.add(obj); - } - } - - // scene objects - for (uint32 i = 0; i < _objects.size(); i++) { - obj = _objects[i]; - if (obj->_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - if (interactiveOnly && !obj->_registrable) { - continue; - } - - objects.add(obj); - } - } - - // sort by _posY - Common::sort(objects.begin(), objects.end(), AdScene::compareObjs); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/ad/ad_actor.h" +#include "engines/wintermute/ad/ad_entity.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_layer.h" +#include "engines/wintermute/ad/ad_node_state.h" +#include "engines/wintermute/ad/ad_object.h" +#include "engines/wintermute/ad/ad_path.h" +#include "engines/wintermute/ad/ad_path_point.h" +#include "engines/wintermute/ad/ad_rot_level.h" +#include "engines/wintermute/ad/ad_scale_level.h" +#include "engines/wintermute/ad/ad_scene_node.h" +#include "engines/wintermute/ad/ad_scene_state.h" +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_point.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/base_scriptable.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_viewport.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/ui/ui_window.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/wintermute.h" +#include + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdScene, false) + +////////////////////////////////////////////////////////////////////////// +AdScene::AdScene(BaseGame *inGame) : BaseObject(inGame) { + _pfTarget = new BasePoint; + setDefaults(); +} + + +////////////////////////////////////////////////////////////////////////// +AdScene::~AdScene() { + cleanup(); + _gameRef->unregisterObject(_fader); + delete _pfTarget; + _pfTarget = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::setDefaults() { + _initialized = false; + _pfReady = true; + _pfTargetPath = NULL; + _pfRequester = NULL; + _mainLayer = NULL; + + _pfPointsNum = 0; + _persistentState = false; + _persistentStateSprites = true; + + _autoScroll = true; + _offsetLeft = _offsetTop = 0; + _targetOffsetLeft = _targetOffsetTop = 0; + + _lastTimeH = _lastTimeV = 0; + _scrollTimeH = _scrollTimeV = 10; + _scrollPixelsH = _scrollPixelsV = 1; + + _pfMaxTime = 15; + + _paralaxScrolling = true; + + // editor settings + _editorMarginH = _editorMarginV = 100; + + _editorColFrame = 0xE0888888; + _editorColEntity = 0xFF008000; + _editorColRegion = 0xFF0000FF; + _editorColBlocked = 0xFF800080; + _editorColWaypoints = 0xFF0000FF; + _editorColEntitySel = 0xFFFF0000; + _editorColRegionSel = 0xFFFF0000; + _editorColBlockedSel = 0xFFFF0000; + _editorColWaypointsSel = 0xFFFF0000; + _editorColScale = 0xFF00FF00; + _editorColDecor = 0xFF00FFFF; + _editorColDecorSel = 0xFFFF0000; + + _editorShowRegions = true; + _editorShowBlocked = true; + _editorShowDecor = true; + _editorShowEntities = true; + _editorShowScale = true; + + _shieldWindow = NULL; + + _fader = new BaseFader(_gameRef); + _gameRef->registerObject(_fader); + + _viewport = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::cleanup() { + BaseObject::cleanup(); + + _mainLayer = NULL; // reference only + + delete _shieldWindow; + _shieldWindow = NULL; + + _gameRef->unregisterObject(_fader); + _fader = NULL; + + for (uint32 i = 0; i < _layers.size(); i++) { + _gameRef->unregisterObject(_layers[i]); + } + _layers.clear(); + + + for (uint32 i = 0; i < _waypointGroups.size(); i++) { + _gameRef->unregisterObject(_waypointGroups[i]); + } + _waypointGroups.clear(); + + for (uint32 i = 0; i < _scaleLevels.size(); i++) { + _gameRef->unregisterObject(_scaleLevels[i]); + } + _scaleLevels.clear(); + + for (uint32 i = 0; i < _rotLevels.size(); i++) { + _gameRef->unregisterObject(_rotLevels[i]); + } + _rotLevels.clear(); + + + for (uint32 i = 0; i < _pfPath.size(); i++) { + delete _pfPath[i]; + } + _pfPath.clear(); + _pfPointsNum = 0; + + for (uint32 i = 0; i < _objects.size(); i++) { + _gameRef->unregisterObject(_objects[i]); + } + _objects.clear(); + + delete _viewport; + _viewport = NULL; + + setDefaults(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester) { + if (!_pfReady) { + return false; + } else { + _pfReady = false; + *_pfTarget = target; + _pfTargetPath = path; + _pfRequester = requester; + + _pfTargetPath->reset(); + _pfTargetPath->setReady(false); + + // prepare working path + pfPointsStart(); + + // first point + //_pfPath.add(new AdPathPoint(source.x, source.y, 0)); + + // if we're one pixel stuck, get unstuck + int startX = source.x; + int startY = source.y; + int bestDistance = 1000; + if (isBlockedAt(startX, startY, true, requester)) { + int tolerance = 2; + for (int xxx = startX - tolerance; xxx <= startX + tolerance; xxx++) { + for (int yyy = startY - tolerance; yyy <= startY + tolerance; yyy++) { + if (isWalkableAt(xxx, yyy, true, requester)) { + int distance = abs(xxx - source.x) + abs(yyy - source.y); + if (distance < bestDistance) { + startX = xxx; + startY = yyy; + + bestDistance = distance; + } + } + } + } + } + + pfPointsAdd(startX, startY, 0); + + //CorrectTargetPoint(&target.x, &target.y); + + // last point + //_pfPath.add(new AdPathPoint(target.x, target.y, INT_MAX)); + pfPointsAdd(target.x, target.y, INT_MAX); + + // active waypoints + for (uint32 i = 0; i < _waypointGroups.size(); i++) { + if (_waypointGroups[i]->_active) { + pfAddWaypointGroup(_waypointGroups[i], requester); + } + } + + + // free waypoints + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentWptGroup) { + pfAddWaypointGroup(_objects[i]->_currentWptGroup, requester); + } + } + AdGame *adGame = (AdGame *)_gameRef; + for (uint32 i = 0; i < adGame->_objects.size(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentWptGroup) { + pfAddWaypointGroup(adGame->_objects[i]->_currentWptGroup, requester); + } + } + + return true; + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::pfAddWaypointGroup(AdWaypointGroup *wpt, BaseObject *requester) { + if (!wpt->_active) { + return; + } + + for (uint32 i = 0; i < wpt->_points.size(); i++) { + if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) { + continue; + } + + //_pfPath.add(new AdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); + pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX); + } +} + + +////////////////////////////////////////////////////////////////////////// +float AdScene::getZoomAt(int x, int y) { + float ret = 100; + + bool found = false; + if (_mainLayer) { + for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { + AdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_blocked && node->_region->pointInRegion(x, y)) { + if (node->_region->_zoom != 0) { + ret = node->_region->_zoom; + found = true; + break; + } + } + } + } + if (!found) { + ret = getScaleAt(y); + } + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +uint32 AdScene::getAlphaAt(int x, int y, bool colorCheck) { + if (!_gameRef->_debugDebugMode) { + colorCheck = false; + } + + uint32 ret; + if (colorCheck) { + ret = 0xFFFF0000; + } else { + ret = 0xFFFFFFFF; + } + + if (_mainLayer) { + for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { + AdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { + if (!node->_region->_blocked) { + ret = node->_region->_alpha; + } + break; + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *requester) { + bool ret = true; + + if (checkFreeObjects) { + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return true; + } + } + } + AdGame *adGame = (AdGame *)_gameRef; + for (uint32 i = 0; i < adGame->_objects.size(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return true; + } + } + } + } + + + if (_mainLayer) { + for (uint32 i = 0; i < _mainLayer->_nodes.size(); i++) { + AdSceneNode *node = _mainLayer->_nodes[i]; + /* + if (Node->_type == OBJECT_REGION && Node->_region->_active && Node->_region->_blocked && Node->_region->PointInRegion(X, Y)) + { + ret = true; + break; + } + */ + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { + if (node->_region->_blocked) { + ret = true; + break; + } else { + ret = false; + } + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requester) { + bool ret = false; + + if (checkFreeObjects) { + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return false; + } + } + } + AdGame *adGame = (AdGame *)_gameRef; + for (uint32 i = 0; i < adGame->_objects.size(); i++) { + if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return false; + } + } + } + } + + + if (_mainLayer) { + for (uint32 i = 0; i < _mainLayer->_nodes.size(); i++) { + AdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && !node->_region->_decoration && node->_region->pointInRegion(x, y)) { + if (node->_region->_blocked) { + ret = false; + break; + } else { + ret = true; + } + } + } + } + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +int AdScene::getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester) { + double xStep, yStep, x, y; + int xLength, yLength, xCount, yCount; + int x1, y1, x2, y2; + + x1 = p1.x; + y1 = p1.y; + x2 = p2.x; + y2 = p2.y; + + xLength = abs(x2 - x1); + yLength = abs(y2 - y1); + + if (xLength > yLength) { + if (x1 > x2) { + BaseUtils::swap(&x1, &x2); + BaseUtils::swap(&y1, &y2); + } + + yStep = (double)(y2 - y1) / (double)(x2 - x1); + y = y1; + + for (xCount = x1; xCount < x2; xCount++) { + if (isBlockedAt(xCount, (int)y, true, requester)) { + return -1; + } + y += yStep; + } + } else { + if (y1 > y2) { + BaseUtils::swap(&x1, &x2); + BaseUtils::swap(&y1, &y2); + } + + xStep = (double)(x2 - x1) / (double)(y2 - y1); + x = x1; + + for (yCount = y1; yCount < y2; yCount++) { + if (isBlockedAt((int)x, yCount, true, requester)) { + return -1; + } + x += xStep; + } + } + return MAX(xLength, yLength); +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::pathFinderStep() { + int i; + // get lowest unmarked + int lowestDist = INT_MAX; + AdPathPoint *lowestPt = NULL; + + for (i = 0; i < _pfPointsNum; i++) + if (!_pfPath[i]->_marked && _pfPath[i]->_distance < lowestDist) { + lowestDist = _pfPath[i]->_distance; + lowestPt = _pfPath[i]; + } + + if (lowestPt == NULL) { // no path -> terminate PathFinder + _pfReady = true; + _pfTargetPath->setReady(true); + return; + } + + lowestPt->_marked = true; + + // target point marked, generate path and terminate + if (lowestPt->x == _pfTarget->x && lowestPt->y == _pfTarget->y) { + while (lowestPt != NULL) { + _pfTargetPath->_points.insert_at(0, new BasePoint(lowestPt->x, lowestPt->y)); + lowestPt = lowestPt->_origin; + } + + _pfReady = true; + _pfTargetPath->setReady(true); + return; + } + + // otherwise keep on searching + for (i = 0; i < _pfPointsNum; i++) + if (!_pfPath[i]->_marked) { + int j = getPointsDist(*lowestPt, *_pfPath[i], _pfRequester); + if (j != -1 && lowestPt->_distance + j < _pfPath[i]->_distance) { + _pfPath[i]->_distance = lowestPt->_distance + j; + _pfPath[i]->_origin = lowestPt; + } + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::initLoop() { +#ifdef _DEBUGxxxx + int nu_steps = 0; + uint32 start = _gameRef->_currentTime; + while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) { + PathFinderStep(); + nu_steps++; + } + if (nu_steps > 0) { + _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); + } +#else + uint32 start = _gameRef->_currentTime; + while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) { + pathFinderStep(); + } +#endif + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdScene::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); + } + + setFilename(filename); + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SCENE) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(LAYER) +TOKEN_DEF(WAYPOINTS) +TOKEN_DEF(EVENTS) +TOKEN_DEF(CURSOR) +TOKEN_DEF(CAMERA) +TOKEN_DEF(ENTITY) +TOKEN_DEF(SCALE_LEVEL) +TOKEN_DEF(ROTATION_LEVEL) +TOKEN_DEF(EDITOR_MARGIN_H) +TOKEN_DEF(EDITOR_MARGIN_V) +TOKEN_DEF(EDITOR_COLOR_FRAME) +TOKEN_DEF(EDITOR_COLOR_ENTITY_SEL) +TOKEN_DEF(EDITOR_COLOR_REGION_SEL) +TOKEN_DEF(EDITOR_COLOR_DECORATION_SEL) +TOKEN_DEF(EDITOR_COLOR_BLOCKED_SEL) +TOKEN_DEF(EDITOR_COLOR_WAYPOINTS_SEL) +TOKEN_DEF(EDITOR_COLOR_REGION) +TOKEN_DEF(EDITOR_COLOR_DECORATION) +TOKEN_DEF(EDITOR_COLOR_BLOCKED) +TOKEN_DEF(EDITOR_COLOR_ENTITY) +TOKEN_DEF(EDITOR_COLOR_WAYPOINTS) +TOKEN_DEF(EDITOR_COLOR_SCALE) +TOKEN_DEF(EDITOR_SHOW_REGIONS) +TOKEN_DEF(EDITOR_SHOW_BLOCKED) +TOKEN_DEF(EDITOR_SHOW_DECORATION) +TOKEN_DEF(EDITOR_SHOW_ENTITIES) +TOKEN_DEF(EDITOR_SHOW_SCALE) +TOKEN_DEF(SCRIPT) +TOKEN_DEF(CAPTION) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(VIEWPORT) +TOKEN_DEF(PERSISTENT_STATE_SPRITES) +TOKEN_DEF(PERSISTENT_STATE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdScene::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SCENE) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(LAYER) + TOKEN_TABLE(WAYPOINTS) + TOKEN_TABLE(EVENTS) + TOKEN_TABLE(CURSOR) + TOKEN_TABLE(CAMERA) + TOKEN_TABLE(ENTITY) + TOKEN_TABLE(SCALE_LEVEL) + TOKEN_TABLE(ROTATION_LEVEL) + TOKEN_TABLE(EDITOR_MARGIN_H) + TOKEN_TABLE(EDITOR_MARGIN_V) + TOKEN_TABLE(EDITOR_COLOR_FRAME) + TOKEN_TABLE(EDITOR_COLOR_ENTITY_SEL) + TOKEN_TABLE(EDITOR_COLOR_REGION_SEL) + TOKEN_TABLE(EDITOR_COLOR_DECORATION_SEL) + TOKEN_TABLE(EDITOR_COLOR_BLOCKED_SEL) + TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS_SEL) + TOKEN_TABLE(EDITOR_COLOR_REGION) + TOKEN_TABLE(EDITOR_COLOR_DECORATION) + TOKEN_TABLE(EDITOR_COLOR_BLOCKED) + TOKEN_TABLE(EDITOR_COLOR_ENTITY) + TOKEN_TABLE(EDITOR_COLOR_WAYPOINTS) + TOKEN_TABLE(EDITOR_COLOR_SCALE) + TOKEN_TABLE(EDITOR_SHOW_REGIONS) + TOKEN_TABLE(EDITOR_SHOW_DECORATION) + TOKEN_TABLE(EDITOR_SHOW_BLOCKED) + TOKEN_TABLE(EDITOR_SHOW_ENTITIES) + TOKEN_TABLE(EDITOR_SHOW_SCALE) + TOKEN_TABLE(SCRIPT) + TOKEN_TABLE(CAPTION) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(VIEWPORT) + TOKEN_TABLE(PERSISTENT_STATE_SPRITES) + TOKEN_TABLE(PERSISTENT_STATE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + cleanup(); + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SCENE) { + _gameRef->LOG(0, "'SCENE' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + int ar, ag, ab, aa; + char camera[MAX_PATH_LENGTH] = ""; + /* float waypointHeight = -1.0f; */ + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_CAPTION: + setCaption((char *)params); + break; + + case TOKEN_LAYER: { + AdLayer *layer = new AdLayer(_gameRef); + if (!layer || DID_FAIL(layer->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete layer; + layer = NULL; + } else { + _gameRef->registerObject(layer); + _layers.add(layer); + if (layer->_main) { + _mainLayer = layer; + _width = layer->_width; + _height = layer->_height; + } + } + } + break; + + case TOKEN_WAYPOINTS: { + AdWaypointGroup *wpt = new AdWaypointGroup(_gameRef); + if (!wpt || DID_FAIL(wpt->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete wpt; + wpt = NULL; + } else { + _gameRef->registerObject(wpt); + _waypointGroups.add(wpt); + } + } + break; + + case TOKEN_SCALE_LEVEL: { + AdScaleLevel *sl = new AdScaleLevel(_gameRef); + if (!sl || DID_FAIL(sl->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete sl; + sl = NULL; + } else { + _gameRef->registerObject(sl); + _scaleLevels.add(sl); + } + } + break; + + case TOKEN_ROTATION_LEVEL: { + AdRotLevel *rl = new AdRotLevel(_gameRef); + if (!rl || DID_FAIL(rl->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete rl; + rl = NULL; + } else { + _gameRef->registerObject(rl); + _rotLevels.add(rl); + } + } + break; + + case TOKEN_ENTITY: { + AdEntity *entity = new AdEntity(_gameRef); + if (!entity || DID_FAIL(entity->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + delete entity; + entity = NULL; + } else { + addObject(entity); + } + } + break; + + case TOKEN_CURSOR: + delete _cursor; + _cursor = new BaseSprite(_gameRef); + if (!_cursor || DID_FAIL(_cursor->loadFile((char *)params))) { + delete _cursor; + _cursor = NULL; + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_CAMERA: + strcpy(camera, (char *)params); + break; + + case TOKEN_EDITOR_MARGIN_H: + parser.scanStr((char *)params, "%d", &_editorMarginH); + break; + + case TOKEN_EDITOR_MARGIN_V: + parser.scanStr((char *)params, "%d", &_editorMarginV); + break; + + case TOKEN_EDITOR_COLOR_FRAME: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColFrame = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_ENTITY: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColEntity = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_ENTITY_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColEntitySel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_REGION_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColRegionSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_DECORATION_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColDecorSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_BLOCKED_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColBlockedSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_WAYPOINTS_SEL: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColWaypointsSel = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_REGION: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColRegion = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_DECORATION: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColDecor = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_BLOCKED: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColBlocked = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_WAYPOINTS: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColWaypoints = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_COLOR_SCALE: + parser.scanStr((char *)params, "%d,%d,%d,%d", &ar, &ag, &ab, &aa); + _editorColScale = BYTETORGBA(ar, ag, ab, aa); + break; + + case TOKEN_EDITOR_SHOW_REGIONS: + parser.scanStr((char *)params, "%b", &_editorShowRegions); + break; + + case TOKEN_EDITOR_SHOW_BLOCKED: + parser.scanStr((char *)params, "%b", &_editorShowBlocked); + break; + + case TOKEN_EDITOR_SHOW_DECORATION: + parser.scanStr((char *)params, "%b", &_editorShowDecor); + break; + + case TOKEN_EDITOR_SHOW_ENTITIES: + parser.scanStr((char *)params, "%b", &_editorShowEntities); + break; + + case TOKEN_EDITOR_SHOW_SCALE: + parser.scanStr((char *)params, "%b", &_editorShowScale); + break; + + case TOKEN_SCRIPT: + addScript((char *)params); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_VIEWPORT: { + Rect32 rc; + parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); + if (!_viewport) { + _viewport = new BaseViewport(_gameRef); + } + if (_viewport) { + _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); + } + } + + case TOKEN_PERSISTENT_STATE: + parser.scanStr((char *)params, "%b", &_persistentState); + break; + + case TOKEN_PERSISTENT_STATE_SPRITES: + parser.scanStr((char *)params, "%b", &_persistentStateSprites); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SCENE definition"); + return STATUS_FAILED; + } + + if (_mainLayer == NULL) { + _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", getFilename()); + } + + + sortScaleLevels(); + sortRotLevels(); + + _initialized = true; + + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdScene::traverseNodes(bool doUpdate) { + if (!_initialized) { + return STATUS_OK; + } + + AdGame *adGame = (AdGame *)_gameRef; + + + ////////////////////////////////////////////////////////////////////////// + // prepare viewport + bool popViewport = false; + if (_viewport && !_gameRef->_editorMode) { + _gameRef->pushViewport(_viewport); + popViewport = true; + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + _gameRef->pushViewport(adGame->_sceneViewport); + popViewport = true; + } + + + ////////////////////////////////////////////////////////////////////////// + // *** adjust scroll offset + if (doUpdate) { + /* + if (_autoScroll && _gameRef->_mainObject != NULL) + { + ScrollToObject(_gameRef->_mainObject); + } + */ + + if (_autoScroll) { + // adjust horizontal scroll + if (_gameRef->_timer - _lastTimeH >= _scrollTimeH) { + _lastTimeH = _gameRef->_timer; + if (_offsetLeft < _targetOffsetLeft) { + _offsetLeft += _scrollPixelsH; + _offsetLeft = MIN(_offsetLeft, _targetOffsetLeft); + } else if (_offsetLeft > _targetOffsetLeft) { + _offsetLeft -= _scrollPixelsH; + _offsetLeft = MAX(_offsetLeft, _targetOffsetLeft); + } + } + + // adjust vertical scroll + if (_gameRef->_timer - _lastTimeV >= _scrollTimeV) { + _lastTimeV = _gameRef->_timer; + if (_offsetTop < _targetOffsetTop) { + _offsetTop += _scrollPixelsV; + _offsetTop = MIN(_offsetTop, _targetOffsetTop); + } else if (_offsetTop > _targetOffsetTop) { + _offsetTop -= _scrollPixelsV; + _offsetTop = MAX(_offsetTop, _targetOffsetTop); + } + } + + if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) { + _ready = true; + } + } else { + _ready = true; // not scrolling, i.e. always ready + } + } + + + + + ////////////////////////////////////////////////////////////////////////// + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + int viewportX, viewportY; + getViewportOffset(&viewportX, &viewportY); + + int scrollableX = _width - viewportWidth; + int scrollableY = _height - viewportHeight; + + double widthRatio = scrollableX <= 0 ? 0 : ((double)(_offsetLeft) / (double)scrollableX); + double heightRatio = scrollableY <= 0 ? 0 : ((double)(_offsetTop) / (double)scrollableY); + + int origX, origY; + _gameRef->getOffset(&origX, &origY); + + + + ////////////////////////////////////////////////////////////////////////// + // *** display/update everything + _gameRef->_renderer->setup2D(); + + // for each layer + /* int mainOffsetX = 0; */ + /* int mainOffsetY = 0; */ + + for (uint32 j = 0; j < _layers.size(); j++) { + if (!_layers[j]->_active) { + continue; + } + + // make layer exclusive + if (!doUpdate) { + if (_layers[j]->_closeUp && !_gameRef->_editorMode) { + if (!_shieldWindow) { + _shieldWindow = new UIWindow(_gameRef); + } + if (_shieldWindow) { + _shieldWindow->_posX = _shieldWindow->_posY = 0; + _shieldWindow->_width = _gameRef->_renderer->_width; + _shieldWindow->_height = _gameRef->_renderer->_height; + _shieldWindow->display(); + } + } + } + + if (_paralaxScrolling) { + int offsetX = (int)(widthRatio * (_layers[j]->_width - viewportWidth) - viewportX); + int offsetY = (int)(heightRatio * (_layers[j]->_height - viewportHeight) - viewportY); + _gameRef->setOffset(offsetX, offsetY); + + _gameRef->_offsetPercentX = (float)offsetX / ((float)_layers[j]->_width - viewportWidth) * 100.0f; + _gameRef->_offsetPercentY = (float)offsetY / ((float)_layers[j]->_height - viewportHeight) * 100.0f; + + //_gameRef->QuickMessageForm("%d %f", OffsetX+ViewportX, _gameRef->_offsetPercentX); + } else { + _gameRef->setOffset(_offsetLeft - viewportX, _offsetTop - viewportY); + + _gameRef->_offsetPercentX = (float)(_offsetLeft - viewportX) / ((float)_layers[j]->_width - viewportWidth) * 100.0f; + _gameRef->_offsetPercentY = (float)(_offsetTop - viewportY) / ((float)_layers[j]->_height - viewportHeight) * 100.0f; + } + + + // for each node + for (uint32 k = 0; k < _layers[j]->_nodes.size(); k++) { + AdSceneNode *node = _layers[j]->_nodes[k]; + switch (node->_type) { + case OBJECT_ENTITY: + if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) { + _gameRef->_renderer->setup2D(); + + if (doUpdate) { + node->_entity->update(); + } else { + node->_entity->display(); + } + } + break; + + case OBJECT_REGION: { + if (node->_region->_blocked) { + break; + } + if (node->_region->_decoration) { + break; + } + + if (!doUpdate) { + displayRegionContent(node->_region); + } + } + break; + default: + error("AdScene::TraverseNodes - Unhandled enum"); + break; + } // switch + } // each node + + // display/update all objects which are off-regions + if (_layers[j]->_main) { + if (doUpdate) { + updateFreeObjects(); + } else { + displayRegionContent(NULL); + } + } + } // each layer + + + // restore state + _gameRef->setOffset(origX, origY); + _gameRef->_renderer->setup2D(); + + // display/update fader + if (_fader) { + if (doUpdate) { + _fader->update(); + } else { + _fader->display(); + } + } + + if (popViewport) { + _gameRef->popViewport(); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::display() { + return traverseNodes(false); +} + +////////////////////////////////////////////////////////////////////////// +bool AdScene::updateFreeObjects() { + AdGame *adGame = (AdGame *)_gameRef; + // 3D-code removed + // bool is3DSet; + + // *** update all active objects + // is3DSet = false; + for (uint32 i = 0; i < adGame->_objects.size(); i++) { + if (!adGame->_objects[i]->_active) { + continue; + } + // 3D-code removed + adGame->_objects[i]->update(); + adGame->_objects[i]->_drawn = false; + } + + + for (uint32 i = 0; i < _objects.size(); i++) { + if (!_objects[i]->_active) { + continue; + } + + _objects[i]->update(); + _objects[i]->_drawn = false; + } + + + if (_autoScroll && _gameRef->_mainObject != NULL) { + scrollToObject(_gameRef->_mainObject); + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { + AdGame *adGame = (AdGame *)_gameRef; + BaseArray objects; + AdObject *obj; + + // global objects + for (uint32 i = 0; i < adGame->_objects.size(); i++) { + obj = adGame->_objects[i]; + if (obj->_active && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + objects.add(obj); + } + } + + // scene objects + for (uint32 i = 0; i < _objects.size(); i++) { + obj = _objects[i]; + if (obj->_active && !obj->_editorOnly && !obj->_drawn && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + objects.add(obj); + } + } + + // sort by _posY + Common::sort(objects.begin(), objects.end(), AdScene::compareObjs); + + // display them + for (uint32 i = 0; i < objects.size(); i++) { + obj = objects[i]; + + if (display3DOnly && !obj->_is3D) { + continue; + } + + _gameRef->_renderer->setup2D(); + + if (_gameRef->_editorMode || !obj->_editorOnly) { + obj->display(); + } + obj->_drawn = true; + } + + + // display design only objects + if (!display3DOnly) { + if (_gameRef->_editorMode && region == NULL) { + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_active && _objects[i]->_editorOnly) { + _objects[i]->display(); + _objects[i]->_drawn = true; + } + } + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +int AdScene::compareObjs(const void *obj1, const void *obj2) { + const AdObject *object1 = *(const AdObject *const *)obj1; + const AdObject *object2 = *(const AdObject *const *)obj2; + + if (object1->_posY < object2->_posY) { + return -1; + } else if (object1->_posY > object2->_posY) { + return 1; + } else { + return 0; + } +} + +////////////////////////////////////////////////////////////////////////// +bool AdScene::displayRegionContentOld(AdRegion *region) { + AdGame *adGame = (AdGame *)_gameRef; + AdObject *obj; + + // display all objects in region sorted by _posY + do { + obj = NULL; + int minY = INT_MAX; + + // global objects + for (uint32 i = 0; i < adGame->_objects.size(); i++) { + if (adGame->_objects[i]->_active && !adGame->_objects[i]->_drawn && adGame->_objects[i]->_posY < minY && (adGame->_objects[i]->_stickRegion == region || region == NULL || (adGame->_objects[i]->_stickRegion == NULL && region->pointInRegion(adGame->_objects[i]->_posX, adGame->_objects[i]->_posY)))) { + obj = adGame->_objects[i]; + minY = adGame->_objects[i]->_posY; + } + } + + // scene objects + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_active && !_objects[i]->_editorOnly && !_objects[i]->_drawn && _objects[i]->_posY < minY && (_objects[i]->_stickRegion == region || region == NULL || (_objects[i]->_stickRegion == NULL && region->pointInRegion(_objects[i]->_posX, _objects[i]->_posY)))) { + obj = _objects[i]; + minY = _objects[i]->_posY; + } + } + + + if (obj != NULL) { + _gameRef->_renderer->setup2D(); + + if (_gameRef->_editorMode || !obj->_editorOnly) { + obj->display(); + } + obj->_drawn = true; + } + } while (obj != NULL); + + + // design only objects + if (_gameRef->_editorMode && region == NULL) { + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_active && _objects[i]->_editorOnly) { + _objects[i]->display(); + _objects[i]->_drawn = true; + } + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::update() { + return traverseNodes(true); +} + +////////////////////////////////////////////////////////////////////////// +void AdScene::scrollTo(int offsetX, int offsetY) { + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + int origOffsetLeft = _targetOffsetLeft; + int origOffsetTop = _targetOffsetTop; + + _targetOffsetLeft = MAX(0, offsetX - viewportWidth / 2); + _targetOffsetLeft = MIN(_targetOffsetLeft, _width - viewportWidth); + + _targetOffsetTop = MAX(0, offsetY - viewportHeight / 2); + _targetOffsetTop = MIN(_targetOffsetTop, _height - viewportHeight); + + + if (_gameRef->_mainObject && _gameRef->_mainObject->_is3D) { + if (abs(origOffsetLeft - _targetOffsetLeft) < 5) { + _targetOffsetLeft = origOffsetLeft; + } + if (abs(origOffsetTop - _targetOffsetTop) < 5) { + _targetOffsetTop = origOffsetTop; + } + //_targetOffsetTop = 0; + } + + _ready = false; +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::scrollToObject(BaseObject *object) { + if (object) { + scrollTo(object->_posX, object->_posY - object->getHeight() / 2); + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::skipToObject(BaseObject *object) { + if (object) { + skipTo(object->_posX, object->_posY - object->getHeight() / 2); + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::skipTo(int offsetX, int offsetY) { + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetLeft = MAX(0, offsetX - viewportWidth / 2); + _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); + + _offsetTop = MAX(0, offsetY - viewportHeight / 2); + _offsetTop = MIN(_offsetTop, _height - viewportHeight); + + _targetOffsetLeft = _offsetLeft; + _targetOffsetTop = _offsetTop; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // LoadActor + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "LoadActor") == 0) { + stack->correctParams(1); + AdActor *act = new AdActor(_gameRef); + if (act && DID_SUCCEED(act->loadFile(stack->pop()->getString()))) { + addObject(act); + stack->pushNative(act, true); + } else { + delete act; + act = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // LoadEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "LoadEntity") == 0) { + stack->correctParams(1); + AdEntity *ent = new AdEntity(_gameRef); + if (ent && DID_SUCCEED(ent->loadFile(stack->pop()->getString()))) { + addObject(ent); + stack->pushNative(ent, true); + } else { + delete ent; + ent = NULL; + stack->pushNULL(); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // CreateEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "CreateEntity") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdEntity *ent = new AdEntity(_gameRef); + addObject(ent); + if (!val->isNULL()) { + ent->setName(val->getString()); + } + stack->pushNative(ent, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // UnloadObject / UnloadActor / UnloadEntity / UnloadActor3D / DeleteEntity + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "UnloadObject") == 0 || strcmp(name, "UnloadActor") == 0 || strcmp(name, "UnloadEntity") == 0 || strcmp(name, "UnloadActor3D") == 0 || strcmp(name, "DeleteEntity") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + AdObject *obj = (AdObject *)val->getNative(); + removeObject(obj); + if (val->getType() == VAL_VARIABLE_REF) { + val->setNULL(); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SkipTo + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SkipTo") == 0) { + stack->correctParams(2); + ScValue *val1 = stack->pop(); + ScValue *val2 = stack->pop(); + if (val1->isNative()) { + skipToObject((BaseObject *)val1->getNative()); + } else { + skipTo(val1->getInt(), val2->getInt()); + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollTo / ScrollToAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollTo") == 0 || strcmp(name, "ScrollToAsync") == 0) { + stack->correctParams(2); + ScValue *val1 = stack->pop(); + ScValue *val2 = stack->pop(); + if (val1->isNative()) { + scrollToObject((BaseObject *)val1->getNative()); + } else { + scrollTo(val1->getInt(), val2->getInt()); + } + if (strcmp(name, "ScrollTo") == 0) { + script->waitForExclusive(this); + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetLayer") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + if (val->isInt()) { + int layer = val->getInt(); + if (layer < 0 || layer >= (int32)_layers.size()) { + stack->pushNULL(); + } else { + stack->pushNative(_layers[layer], true); + } + } else { + const char *layerName = val->getString(); + bool layerFound = false; + for (uint32 i = 0; i < _layers.size(); i++) { + if (scumm_stricmp(layerName, _layers[i]->getName()) == 0) { + stack->pushNative(_layers[i], true); + layerFound = true; + break; + } + } + if (!layerFound) { + stack->pushNULL(); + } + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetWaypointGroup + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetWaypointGroup") == 0) { + stack->correctParams(1); + int group = stack->pop()->getInt(); + if (group < 0 || group >= (int32)_waypointGroups.size()) { + stack->pushNULL(); + } else { + stack->pushNative(_waypointGroups[group], true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetNode") == 0) { + stack->correctParams(1); + const char *nodeName = stack->pop()->getString(); + + BaseObject *node = getNodeByName(nodeName); + if (node) { + stack->pushNative((BaseScriptable *)node, true); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFreeNode + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFreeNode") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdObject *ret = NULL; + if (val->isInt()) { + int index = val->getInt(); + if (index >= 0 && index < (int32)_objects.size()) { + ret = _objects[index]; + } + } else { + const char *nodeName = val->getString(); + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i] && _objects[i]->getName() && scumm_stricmp(_objects[i]->getName(), nodeName) == 0) { + ret = _objects[i]; + break; + } + } + } + if (ret) { + stack->pushNative(ret, true); + } else { + stack->pushNULL(); + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetRegionAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetRegionAt") == 0) { + stack->correctParams(3); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + ScValue *val = stack->pop(); + + bool includeDecors = false; + if (!val->isNULL()) { + includeDecors = val->getBool(); + } + + if (_mainLayer) { + for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { + AdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { + if (node->_region->_decoration && !includeDecors) { + continue; + } + + stack->pushNative(node->_region, true); + return STATUS_OK; + } + } + } + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsBlockedAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsBlockedAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushBool(isBlockedAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsWalkableAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsWalkableAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushBool(isWalkableAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetScaleAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetScaleAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushFloat(getZoomAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetRotationAt + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetRotationAt") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + + stack->pushFloat(getRotationAt(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsScrolling + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsScrolling") == 0) { + stack->correctParams(0); + bool ret = false; + if (_autoScroll) { + if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) { + ret = true; + } + } + + stack->pushBool(ret); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // FadeOut / FadeOutAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "FadeOut") == 0 || strcmp(name, "FadeOutAsync") == 0) { + stack->correctParams(5); + uint32 duration = stack->pop()->getInt(500); + byte red = stack->pop()->getInt(0); + byte green = stack->pop()->getInt(0); + byte blue = stack->pop()->getInt(0); + byte alpha = stack->pop()->getInt(0xFF); + + _fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration); + if (strcmp(name, "FadeOutAsync") != 0) { + script->waitFor(_fader); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // FadeIn / FadeInAsync + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "FadeIn") == 0 || strcmp(name, "FadeInAsync") == 0) { + stack->correctParams(5); + uint32 duration = stack->pop()->getInt(500); + byte red = stack->pop()->getInt(0); + byte green = stack->pop()->getInt(0); + byte blue = stack->pop()->getInt(0); + byte alpha = stack->pop()->getInt(0xFF); + + _fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration); + if (strcmp(name, "FadeInAsync") != 0) { + script->waitFor(_fader); + } + + stack->pushNULL(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetFadeColor + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetFadeColor") == 0) { + stack->correctParams(0); + stack->pushInt(_fader->getCurrentColor()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // IsPointInViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "IsPointInViewport") == 0) { + stack->correctParams(2); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + stack->pushBool(pointInViewport(x, y)); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetViewport + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetViewport") == 0) { + stack->correctParams(4); + int x = stack->pop()->getInt(); + int y = stack->pop()->getInt(); + int width = stack->pop()->getInt(); + int height = stack->pop()->getInt(); + + if (width <= 0) { + width = _gameRef->_renderer->_width; + } + if (height <= 0) { + height = _gameRef->_renderer->_height; + } + + if (!_viewport) { + _viewport = new BaseViewport(_gameRef); + } + if (_viewport) { + _viewport->setRect(x, y, x + width, y + height); + } + + stack->pushBool(true); + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddLayer") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdLayer *layer = new AdLayer(_gameRef); + if (!val->isNULL()) { + layer->setName(val->getString()); + } + if (_mainLayer) { + layer->_width = _mainLayer->_width; + layer->_height = _mainLayer->_height; + } + _layers.add(layer); + _gameRef->registerObject(layer); + + stack->pushNative(layer, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // InsertLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "InsertLayer") == 0) { + stack->correctParams(2); + int index = stack->pop()->getInt(); + ScValue *val = stack->pop(); + + AdLayer *layer = new AdLayer(_gameRef); + if (!val->isNULL()) { + layer->setName(val->getString()); + } + if (_mainLayer) { + layer->_width = _mainLayer->_width; + layer->_height = _mainLayer->_height; + } + if (index < 0) { + index = 0; + } + if (index <= (int32)_layers.size() - 1) { + _layers.insert_at(index, layer); + } else { + _layers.add(layer); + } + + _gameRef->registerObject(layer); + + stack->pushNative(layer, true); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // DeleteLayer + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "DeleteLayer") == 0) { + stack->correctParams(1); + ScValue *val = stack->pop(); + + AdLayer *toDelete = NULL; + if (val->isNative()) { + BaseScriptable *temp = val->getNative(); + for (uint32 i = 0; i < _layers.size(); i++) { + if (_layers[i] == temp) { + toDelete = _layers[i]; + break; + } + } + } else { + int index = val->getInt(); + if (index >= 0 && index < (int32)_layers.size()) { + toDelete = _layers[index]; + } + } + if (toDelete == NULL) { + stack->pushBool(false); + return STATUS_OK; + } + + if (toDelete->_main) { + script->runtimeError("Scene.DeleteLayer - cannot delete main scene layer"); + stack->pushBool(false); + return STATUS_OK; + } + + for (uint32 i = 0; i < _layers.size(); i++) { + if (_layers[i] == toDelete) { + _layers.remove_at(i); + _gameRef->unregisterObject(toDelete); + break; + } + } + stack->pushBool(true); + return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdScene::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("scene"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumLayers (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumLayers") == 0) { + _scValue->setInt(_layers.size()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumWaypointGroups (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumWaypointGroups") == 0) { + _scValue->setInt(_waypointGroups.size()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MainLayer (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MainLayer") == 0) { + if (_mainLayer) { + _scValue->setNative(_mainLayer, true); + } else { + _scValue->setNULL(); + } + + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // NumFreeNodes (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "NumFreeNodes") == 0) { + _scValue->setInt(_objects.size()); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MouseX (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MouseX") == 0) { + int viewportX; + getViewportOffset(&viewportX); + + _scValue->setInt(_gameRef->_mousePos.x + _offsetLeft - viewportX); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // MouseY (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "MouseY") == 0) { + int viewportY; + getViewportOffset(NULL, &viewportY); + + _scValue->setInt(_gameRef->_mousePos.y + _offsetTop - viewportY); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // AutoScroll + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AutoScroll") == 0) { + _scValue->setBool(_autoScroll); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentState + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentState") == 0) { + _scValue->setBool(_persistentState); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentStateSprites + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentStateSprites") == 0) { + _scValue->setBool(_persistentStateSprites); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsX") == 0) { + _scValue->setInt(_scrollPixelsH); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsY") == 0) { + _scValue->setInt(_scrollPixelsV); + return _scValue; + } + + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedX") == 0) { + _scValue->setInt(_scrollTimeH); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedY") == 0) { + _scValue->setInt(_scrollTimeV); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetX") == 0) { + _scValue->setInt(_offsetLeft); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetY") == 0) { + _scValue->setInt(_offsetTop); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Width (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Width") == 0) { + if (_mainLayer) { + _scValue->setInt(_mainLayer->_width); + } else { + _scValue->setInt(0); + } + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Height (RO) + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Height") == 0) { + if (_mainLayer) { + _scValue->setInt(_mainLayer->_height); + } else { + _scValue->setInt(0); + } + return _scValue; + } else { + return BaseObject::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::scSetProperty(const char *name, ScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Name + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Name") == 0) { + setName(value->getString()); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AutoScroll + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AutoScroll") == 0) { + _autoScroll = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentState + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentState") == 0) { + _persistentState = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // PersistentStateSprites + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "PersistentStateSprites") == 0) { + _persistentStateSprites = value->getBool(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsX") == 0) { + _scrollPixelsH = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollPixelsY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollPixelsY") == 0) { + _scrollPixelsV = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedX") == 0) { + _scrollTimeH = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // ScrollSpeedY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "ScrollSpeedY") == 0) { + _scrollTimeV = value->getInt(); + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetX + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetX") == 0) { + _offsetLeft = value->getInt(); + + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetLeft = MAX(0, _offsetLeft - viewportWidth / 2); + _offsetLeft = MIN(_offsetLeft, _width - viewportWidth); + _targetOffsetLeft = _offsetLeft; + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // OffsetY + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "OffsetY") == 0) { + _offsetTop = value->getInt(); + + int viewportWidth, viewportHeight; + getViewportSize(&viewportWidth, &viewportHeight); + + _offsetTop = MAX(0, _offsetTop - viewportHeight / 2); + _offsetTop = MIN(_offsetTop, _height - viewportHeight); + _targetOffsetTop = _offsetTop; + + return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdScene::scToString() { + return "[scene object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::addObject(AdObject *object) { + _objects.add(object); + return _gameRef->registerObject(object); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::removeObject(AdObject *object) { + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i] == object) { + _objects.remove_at(i); + return _gameRef->unregisterObject(object); + } + } + return STATUS_FAILED; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "SCENE {\n"); + + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); + + if (_persistentState) { + buffer->putTextIndent(indent + 2, "PERSISTENT_STATE=%s\n", _persistentState ? "TRUE" : "FALSE"); + } + + if (!_persistentStateSprites) { + buffer->putTextIndent(indent + 2, "PERSISTENT_STATE_SPRITES=%s\n", _persistentStateSprites ? "TRUE" : "FALSE"); + } + + + // scripts + for (uint32 i = 0; i < _scripts.size(); i++) { + buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); + } + + buffer->putTextIndent(indent + 2, "\n"); + + // properties + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } + + // viewport + if (_viewport) { + Rect32 *rc = _viewport->getRect(); + buffer->putTextIndent(indent + 2, "VIEWPORT { %d, %d, %d, %d }\n", rc->left, rc->top, rc->right, rc->bottom); + } + + + + // editor settings + buffer->putTextIndent(indent + 2, "; ----- editor settings\n"); + buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_H=%d\n", _editorMarginH); + buffer->putTextIndent(indent + 2, "EDITOR_MARGIN_V=%d\n", _editorMarginV); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_FRAME { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColFrame), RGBCOLGetG(_editorColFrame), RGBCOLGetB(_editorColFrame), RGBCOLGetA(_editorColFrame)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntitySel), RGBCOLGetG(_editorColEntitySel), RGBCOLGetB(_editorColEntitySel), RGBCOLGetA(_editorColEntitySel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegionSel), RGBCOLGetG(_editorColRegionSel), RGBCOLGetB(_editorColRegionSel), RGBCOLGetA(_editorColRegionSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlockedSel), RGBCOLGetG(_editorColBlockedSel), RGBCOLGetB(_editorColBlockedSel), RGBCOLGetA(_editorColBlockedSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecorSel), RGBCOLGetG(_editorColDecorSel), RGBCOLGetB(_editorColDecorSel), RGBCOLGetA(_editorColDecorSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS_SEL { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypointsSel), RGBCOLGetG(_editorColWaypointsSel), RGBCOLGetB(_editorColWaypointsSel), RGBCOLGetA(_editorColWaypointsSel)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_ENTITY { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColEntity), RGBCOLGetG(_editorColEntity), RGBCOLGetB(_editorColEntity), RGBCOLGetA(_editorColEntity)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_REGION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColRegion), RGBCOLGetG(_editorColRegion), RGBCOLGetB(_editorColRegion), RGBCOLGetA(_editorColRegion)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_DECORATION { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColDecor), RGBCOLGetG(_editorColDecor), RGBCOLGetB(_editorColDecor), RGBCOLGetA(_editorColDecor)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_BLOCKED { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColBlocked), RGBCOLGetG(_editorColBlocked), RGBCOLGetB(_editorColBlocked), RGBCOLGetA(_editorColBlocked)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_WAYPOINTS { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColWaypoints), RGBCOLGetG(_editorColWaypoints), RGBCOLGetB(_editorColWaypoints), RGBCOLGetA(_editorColWaypoints)); + buffer->putTextIndent(indent + 2, "EDITOR_COLOR_SCALE { %d,%d,%d,%d }\n", RGBCOLGetR(_editorColScale), RGBCOLGetG(_editorColScale), RGBCOLGetB(_editorColScale), RGBCOLGetA(_editorColScale)); + + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_REGIONS=%s\n", _editorShowRegions ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_BLOCKED=%s\n", _editorShowBlocked ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_DECORATION=%s\n", _editorShowDecor ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_ENTITIES=%s\n", _editorShowEntities ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SHOW_SCALE=%s\n", _editorShowScale ? "TRUE" : "FALSE"); + + buffer->putTextIndent(indent + 2, "\n"); + + BaseClass::saveAsText(buffer, indent + 2); + + // waypoints + buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); + for (uint32 i = 0; i < _waypointGroups.size(); i++) { + _waypointGroups[i]->saveAsText(buffer, indent + 2); + } + + buffer->putTextIndent(indent + 2, "\n"); + + // layers + buffer->putTextIndent(indent + 2, "; ----- layers\n"); + for (uint32 i = 0; i < _layers.size(); i++) { + _layers[i]->saveAsText(buffer, indent + 2); + } + + // scale levels + buffer->putTextIndent(indent + 2, "; ----- scale levels\n"); + for (uint32 i = 0; i < _scaleLevels.size(); i++) { + _scaleLevels[i]->saveAsText(buffer, indent + 2); + } + + // rotation levels + buffer->putTextIndent(indent + 2, "; ----- rotation levels\n"); + for (uint32 i = 0; i < _rotLevels.size(); i++) { + _rotLevels[i]->saveAsText(buffer, indent + 2); + } + + + buffer->putTextIndent(indent + 2, "\n"); + + // free entities + buffer->putTextIndent(indent + 2, "; ----- free entities\n"); + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY) { + _objects[i]->saveAsText(buffer, indent + 2); + + } + } + + buffer->putTextIndent(indent, "}\n"); + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::sortScaleLevels() { + if (_scaleLevels.size() == 0) { + return STATUS_OK; + } + bool changed; + do { + changed = false; + for (uint32 i = 0; i < _scaleLevels.size() - 1; i++) { + if (_scaleLevels[i]->_posY > _scaleLevels[i + 1]->_posY) { + AdScaleLevel *sl = _scaleLevels[i]; + _scaleLevels[i] = _scaleLevels[i + 1]; + _scaleLevels[i + 1] = sl; + + changed = true; + } + } + + } while (changed); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::sortRotLevels() { + if (_rotLevels.size() == 0) { + return STATUS_OK; + } + bool changed; + do { + changed = false; + for (uint32 i = 0; i < _rotLevels.size() - 1; i++) { + if (_rotLevels[i]->_posX > _rotLevels[i + 1]->_posX) { + AdRotLevel *rl = _rotLevels[i]; + _rotLevels[i] = _rotLevels[i + 1]; + _rotLevels[i + 1] = rl; + + changed = true; + } + } + + } while (changed); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +float AdScene::getScaleAt(int Y) { + AdScaleLevel *prev = NULL; + AdScaleLevel *next = NULL; + + for (uint32 i = 0; i < _scaleLevels.size(); i++) { + /* AdScaleLevel *xxx = _scaleLevels[i];*/ + /* int j = _scaleLevels.size(); */ + if (_scaleLevels[i]->_posY < Y) { + prev = _scaleLevels[i]; + } else { + next = _scaleLevels[i]; + break; + } + } + + if (prev == NULL || next == NULL) { + return 100; + } + + int delta_y = next->_posY - prev->_posY; + float delta_scale = next->_scale - prev->_scale; + Y -= prev->_posY; + + float percent = (float)Y / ((float)delta_y / 100.0f); + return prev->_scale + delta_scale / 100 * percent; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::persist(BasePersistenceManager *persistMgr) { + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_autoScroll)); + persistMgr->transfer(TMEMBER(_editorColBlocked)); + persistMgr->transfer(TMEMBER(_editorColBlockedSel)); + persistMgr->transfer(TMEMBER(_editorColDecor)); + persistMgr->transfer(TMEMBER(_editorColDecorSel)); + persistMgr->transfer(TMEMBER(_editorColEntity)); + persistMgr->transfer(TMEMBER(_editorColEntitySel)); + persistMgr->transfer(TMEMBER(_editorColFrame)); + persistMgr->transfer(TMEMBER(_editorColRegion)); + persistMgr->transfer(TMEMBER(_editorColRegionSel)); + persistMgr->transfer(TMEMBER(_editorColScale)); + persistMgr->transfer(TMEMBER(_editorColWaypoints)); + persistMgr->transfer(TMEMBER(_editorColWaypointsSel)); + persistMgr->transfer(TMEMBER(_editorMarginH)); + persistMgr->transfer(TMEMBER(_editorMarginV)); + persistMgr->transfer(TMEMBER(_editorShowBlocked)); + persistMgr->transfer(TMEMBER(_editorShowDecor)); + persistMgr->transfer(TMEMBER(_editorShowEntities)); + persistMgr->transfer(TMEMBER(_editorShowRegions)); + persistMgr->transfer(TMEMBER(_editorShowScale)); + persistMgr->transfer(TMEMBER(_fader)); + persistMgr->transfer(TMEMBER(_height)); + persistMgr->transfer(TMEMBER(_initialized)); + persistMgr->transfer(TMEMBER(_lastTimeH)); + persistMgr->transfer(TMEMBER(_lastTimeV)); + _layers.persist(persistMgr); + persistMgr->transfer(TMEMBER(_mainLayer)); + _objects.persist(persistMgr); + persistMgr->transfer(TMEMBER(_offsetLeft)); + persistMgr->transfer(TMEMBER(_offsetTop)); + persistMgr->transfer(TMEMBER(_paralaxScrolling)); + persistMgr->transfer(TMEMBER(_persistentState)); + persistMgr->transfer(TMEMBER(_persistentStateSprites)); + persistMgr->transfer(TMEMBER(_pfMaxTime)); + _pfPath.persist(persistMgr); + persistMgr->transfer(TMEMBER(_pfPointsNum)); + persistMgr->transfer(TMEMBER(_pfReady)); + persistMgr->transfer(TMEMBER(_pfRequester)); + persistMgr->transfer(TMEMBER(_pfTarget)); + persistMgr->transfer(TMEMBER(_pfTargetPath)); + _rotLevels.persist(persistMgr); + _scaleLevels.persist(persistMgr); + persistMgr->transfer(TMEMBER(_scrollPixelsH)); + persistMgr->transfer(TMEMBER(_scrollPixelsV)); + persistMgr->transfer(TMEMBER(_scrollTimeH)); + persistMgr->transfer(TMEMBER(_scrollTimeV)); + persistMgr->transfer(TMEMBER(_shieldWindow)); + persistMgr->transfer(TMEMBER(_targetOffsetLeft)); + persistMgr->transfer(TMEMBER(_targetOffsetTop)); + _waypointGroups.persist(persistMgr); + persistMgr->transfer(TMEMBER(_viewport)); + persistMgr->transfer(TMEMBER(_width)); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdScene::afterLoad() { + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdScene::correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, BaseObject *requester) { + double xStep, yStep, x, y; + int xLength, yLength, xCount, yCount; + int x1, y1, x2, y2; + + x1 = *targetX; + y1 = *targetY; + x2 = startX; + y2 = startY; + + + xLength = abs(x2 - x1); + yLength = abs(y2 - y1); + + if (xLength > yLength) { + + yStep = fabs((double)(y2 - y1) / (double)(x2 - x1)); + y = y1; + + for (xCount = x1; xCount < x2; xCount++) { + if (isWalkableAt(xCount, (int)y, checkFreeObjects, requester)) { + *targetX = xCount; + *targetY = (int)y; + return STATUS_OK; + } + y += yStep; + } + } else { + + xStep = fabs((double)(x2 - x1) / (double)(y2 - y1)); + x = x1; + + for (yCount = y1; yCount < y2; yCount++) { + if (isWalkableAt((int)x, yCount, checkFreeObjects, requester)) { + *targetX = (int)x; + *targetY = yCount; + return STATUS_OK; + } + x += xStep; + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, bool checkFreeObjects, BaseObject *requester) { + int x = *argX; + int y = *argY; + + if (isWalkableAt(x, y, checkFreeObjects, requester) || !_mainLayer) { + return STATUS_OK; + } + + // right + int lengthRight = 0; + bool foundRight = false; + for (x = *argX, y = *argY; x < _mainLayer->_width; x++, lengthRight++) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x - 5, y, checkFreeObjects, requester)) { + foundRight = true; + break; + } + } + + // left + int lengthLeft = 0; + bool foundLeft = false; + for (x = *argX, y = *argY; x >= 0; x--, lengthLeft--) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x + 5, y, checkFreeObjects, requester)) { + foundLeft = true; + break; + } + } + + // up + int lengthUp = 0; + bool foundUp = false; + for (x = *argX, y = *argY; y >= 0; y--, lengthUp--) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y + 5, checkFreeObjects, requester)) { + foundUp = true; + break; + } + } + + // down + int lengthDown = 0; + bool foundDown = false; + for (x = *argX, y = *argY; y < _mainLayer->_height; y++, lengthDown++) { + if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y - 5, checkFreeObjects, requester)) { + foundDown = true; + break; + } + } + + if (!foundLeft && !foundRight && !foundUp && !foundDown) { + return STATUS_OK; + } + + int offsetX = INT_MAX, offsetY = INT_MAX; + + if (foundLeft && foundRight) { + if (abs(lengthLeft) < abs(lengthRight)) { + offsetX = lengthLeft; + } else { + offsetX = lengthRight; + } + } else if (foundLeft) { + offsetX = lengthLeft; + } else if (foundRight) { + offsetX = lengthRight; + } + + if (foundUp && foundDown) { + if (abs(lengthUp) < abs(lengthDown)) { + offsetY = lengthUp; + } else { + offsetY = lengthDown; + } + } else if (foundUp) { + offsetY = lengthUp; + } else if (foundDown) { + offsetY = lengthDown; + } + + if (abs(offsetX) < abs(offsetY)) { + *argX = *argX + offsetX; + } else { + *argY = *argY + offsetY; + } + + if (!isWalkableAt(*argX, *argY)) { + return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); + } else { + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::pfPointsStart() { + _pfPointsNum = 0; +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::pfPointsAdd(int x, int y, int distance) { + if (_pfPointsNum >= (int32)_pfPath.size()) { + _pfPath.add(new AdPathPoint(x, y, distance)); + } else { + _pfPath[_pfPointsNum]->x = x; + _pfPath[_pfPointsNum]->y = y; + _pfPath[_pfPointsNum]->_distance = distance; + _pfPath[_pfPointsNum]->_marked = false; + _pfPath[_pfPointsNum]->_origin = NULL; + } + + _pfPointsNum++; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::getViewportOffset(int *offsetX, int *offsetY) { + AdGame *adGame = (AdGame *)_gameRef; + if (_viewport && !_gameRef->_editorMode) { + if (offsetX) { + *offsetX = _viewport->_offsetX; + } + if (offsetY) { + *offsetY = _viewport->_offsetY; + } + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + if (offsetX) { + *offsetX = adGame->_sceneViewport->_offsetX; + } + if (offsetY) { + *offsetY = adGame->_sceneViewport->_offsetY; + } + } else { + if (offsetX) { + *offsetX = 0; + } + if (offsetY) { + *offsetY = 0; + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::getViewportSize(int *width, int *height) { + AdGame *adGame = (AdGame *)_gameRef; + if (_viewport && !_gameRef->_editorMode) { + if (width) { + *width = _viewport->getWidth(); + } + if (height) { + *height = _viewport->getHeight(); + } + } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { + if (width) { + *width = adGame->_sceneViewport->getWidth(); + } + if (height) { + *height = adGame->_sceneViewport->getHeight(); + } + } else { + if (width) { + *width = _gameRef->_renderer->_width; + } + if (height) { + *height = _gameRef->_renderer->_height; + } + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +int AdScene::getOffsetLeft() { + int viewportX; + getViewportOffset(&viewportX); + + return _offsetLeft - viewportX; +} + + +////////////////////////////////////////////////////////////////////////// +int AdScene::getOffsetTop() { + int viewportY; + getViewportOffset(NULL, &viewportY); + + return _offsetTop - viewportY; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::pointInViewport(int x, int y) { + int left, top, width, height; + + getViewportOffset(&left, &top); + getViewportSize(&width, &height); + + return x >= left && x <= left + width && y >= top && y <= top + height; +} + + +////////////////////////////////////////////////////////////////////////// +void AdScene::setOffset(int offsetLeft, int offsetTop) { + _offsetLeft = offsetLeft; + _offsetTop = offsetTop; +} + + +////////////////////////////////////////////////////////////////////////// +BaseObject *AdScene::getNodeByName(const char *name) { + BaseObject *ret = NULL; + + // dependent objects + for (uint32 i = 0; i < _layers.size(); i++) { + AdLayer *layer = _layers[i]; + for (uint32 j = 0; j < layer->_nodes.size(); j++) { + AdSceneNode *node = layer->_nodes[j]; + if ((node->_type == OBJECT_ENTITY && !scumm_stricmp(name, node->_entity->getName())) || + (node->_type == OBJECT_REGION && !scumm_stricmp(name, node->_region->getName()))) { + switch (node->_type) { + case OBJECT_ENTITY: + ret = node->_entity; + break; + case OBJECT_REGION: + ret = node->_region; + break; + default: + ret = NULL; + } + return ret; + } + } + } + + // free entities + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY && !scumm_stricmp(name, _objects[i]->getName())) { + return _objects[i]; + } + } + + // waypoint groups + for (uint32 i = 0; i < _waypointGroups.size(); i++) { + if (!scumm_stricmp(name, _waypointGroups[i]->getName())) { + return _waypointGroups[i]; + } + } + + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::saveState() { + return persistState(true); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::loadState() { + return persistState(false); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::persistState(bool saving) { + if (!_persistentState) { + return STATUS_OK; + } + + AdGame *adGame = (AdGame *)_gameRef; + AdSceneState *state = adGame->getSceneState(getFilename(), saving); + if (!state) { + return STATUS_OK; + } + + AdNodeState *nodeState; + + // dependent objects + for (uint32 i = 0; i < _layers.size(); i++) { + AdLayer *layer = _layers[i]; + for (uint32 j = 0; j < layer->_nodes.size(); j++) { + AdSceneNode *node = layer->_nodes[j]; + switch (node->_type) { + case OBJECT_ENTITY: + if (!node->_entity->_saveState) { + continue; + } + nodeState = state->getNodeState(node->_entity->getName(), saving); + if (nodeState) { + nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); + //if (Saving) NodeState->_active = node->_entity->_active; + //else node->_entity->_active = NodeState->_active; + } + break; + case OBJECT_REGION: + if (!node->_region->_saveState) { + continue; + } + nodeState = state->getNodeState(node->_region->getName(), saving); + if (nodeState) { + if (saving) { + nodeState->_active = node->_region->_active; + } else { + node->_region->_active = nodeState->_active; + } + } + break; + default: + warning("AdScene::PersistState - unhandled enum"); + break; + } + } + } + + // free entities + for (uint32 i = 0; i < _objects.size(); i++) { + if (!_objects[i]->_saveState) { + continue; + } + if (_objects[i]->_type == OBJECT_ENTITY) { + nodeState = state->getNodeState(_objects[i]->getName(), saving); + if (nodeState) { + nodeState->transferEntity((AdEntity *)_objects[i], _persistentStateSprites, saving); + //if (Saving) NodeState->_active = _objects[i]->_active; + //else _objects[i]->_active = NodeState->_active; + } + } + } + + // waypoint groups + for (uint32 i = 0; i < _waypointGroups.size(); i++) { + nodeState = state->getNodeState(_waypointGroups[i]->getName(), saving); + if (nodeState) { + if (saving) { + nodeState->_active = _waypointGroups[i]->_active; + } else { + _waypointGroups[i]->_active = nodeState->_active; + } + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +float AdScene::getRotationAt(int x, int y) { + AdRotLevel *prev = NULL; + AdRotLevel *next = NULL; + + for (uint32 i = 0; i < _rotLevels.size(); i++) { + /* AdRotLevel *xxx = _rotLevels[i]; + int j = _rotLevels.size();*/ + if (_rotLevels[i]->_posX < x) { + prev = _rotLevels[i]; + } else { + next = _rotLevels[i]; + break; + } + } + + if (prev == NULL || next == NULL) { + return 0; + } + + int delta_x = next->_posX - prev->_posX; + float delta_rot = next->_rotation - prev->_rotation; + x -= prev->_posX; + + float percent = (float)x / ((float)delta_x / 100.0f); + return prev->_rotation + delta_rot / 100 * percent; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::handleItemAssociations(const char *itemName, bool show) { + for (uint32 i = 0; i < _layers.size(); i++) { + AdLayer *layer = _layers[i]; + for (uint32 j = 0; j < layer->_nodes.size(); j++) { + if (layer->_nodes[j]->_type == OBJECT_ENTITY) { + AdEntity *ent = layer->_nodes[j]->_entity; + + if (ent->_item && strcmp(ent->_item, itemName) == 0) { + ent->_active = show; + } + } + } + } + + for (uint32 i = 0; i < _objects.size(); i++) { + if (_objects[i]->_type == OBJECT_ENTITY) { + AdEntity *ent = (AdEntity *)_objects[i]; + if (ent->_item && strcmp(ent->_item, itemName) == 0) { + ent->_active = show; + } + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::getRegionsAt(int x, int y, AdRegion **regionList, int numRegions) { + int numUsed = 0; + if (_mainLayer) { + for (int i = _mainLayer->_nodes.size() - 1; i >= 0; i--) { + AdSceneNode *node = _mainLayer->_nodes[i]; + if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { + if (numUsed < numRegions - 1) { + regionList[numUsed] = node->_region; + numUsed++; + } else { + break; + } + } + } + } + for (int i = numUsed; i < numRegions; i++) { + regionList[i] = NULL; + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdScene::restoreDeviceObjects() { + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) { + BaseArray objects; + getSceneObjects(objects, true); + + if (objects.size() == 0) { + return NULL; + } else { + if (currObject != NULL) { + for (uint32 i = 0; i < objects.size(); i++) { + if (objects[i] == currObject) { + if (i < objects.size() - 1) { + return objects[i + 1]; + } else { + break; + } + } + } + } + return objects[0]; + } + return NULL; +} + +////////////////////////////////////////////////////////////////////////// +BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { + BaseArray objects; + getSceneObjects(objects, true); + + if (objects.size() == 0) { + return NULL; + } else { + if (currObject != NULL) { + for (int i = objects.size() - 1; i >= 0; i--) { + if (objects[i] == currObject) { + if (i > 0) { + return objects[i - 1]; + } else { + break; + } + } + } + } + return objects[objects.size() - 1]; + } + return NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOnly) { + for (uint32 i = 0; i < _layers.size(); i++) { + // close-up layer -> remove everything below it + if (interactiveOnly && _layers[i]->_closeUp) { + objects.clear(); + } + + + for (uint32 j = 0; j < _layers[i]->_nodes.size(); j++) { + AdSceneNode *node = _layers[i]->_nodes[j]; + switch (node->_type) { + case OBJECT_ENTITY: { + AdEntity *ent = node->_entity; + if (ent->_active && (ent->_registrable || !interactiveOnly)) { + objects.add(ent); + } + } + break; + + case OBJECT_REGION: { + BaseArray regionObj; + getRegionObjects(node->_region, regionObj, interactiveOnly); + for (uint32 newIndex = 0; newIndex < regionObj.size(); newIndex++) { + bool found = false; + for (uint32 old = 0; old < objects.size(); old++) { + if (objects[old] == regionObj[newIndex]) { + found = true; + break; + } + } + if (!found) { + objects.add(regionObj[newIndex]); + } + } + //if (regionObj.size() > 0) Objects.Append(RegionObj); + } + break; + default: + debugC(kWintermuteDebugGeneral, "AdScene::GetSceneObjects - Unhandled enum"); + break; + } + } + } + + // objects outside any region + BaseArray regionObj; + getRegionObjects(NULL, regionObj, interactiveOnly); + for (uint32 newIndex = 0; newIndex < regionObj.size(); newIndex++) { + bool found = false; + for (uint32 old = 0; old < objects.size(); old++) { + if (objects[old] == regionObj[newIndex]) { + found = true; + break; + } + } + if (!found) { + objects.add(regionObj[newIndex]); + } + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdScene::getRegionObjects(AdRegion *region, BaseArray &objects, bool interactiveOnly) { + AdGame *adGame = (AdGame *)_gameRef; + AdObject *obj; + + // global objects + for (uint32 i = 0; i < adGame->_objects.size(); i++) { + obj = adGame->_objects[i]; + if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + if (interactiveOnly && !obj->_registrable) { + continue; + } + + objects.add(obj); + } + } + + // scene objects + for (uint32 i = 0; i < _objects.size(); i++) { + obj = _objects[i]; + if (obj->_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { + if (interactiveOnly && !obj->_registrable) { + continue; + } + + objects.add(obj); + } + } + + // sort by _posY + Common::sort(objects.begin(), objects.end(), AdScene::compareObjs); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_scene.h b/engines/wintermute/ad/ad_scene.h index 20b3f5026d..c9c0e413bf 100644 --- a/engines/wintermute/ad/ad_scene.h +++ b/engines/wintermute/ad/ad_scene.h @@ -1,181 +1,181 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSCENE_H -#define WINTERMUTE_ADSCENE_H - -#include "engines/wintermute/base/base_fader.h" - -namespace Wintermute { - -class UIWindow; -class AdObject; -class AdRegion; -class BaseViewport; -class AdLayer; -class BasePoint; -class AdWaypointGroup; -class AdPath; -class AdScaleLevel; -class AdRotLevel; -class AdPathPoint; -class AdScene : public BaseObject { -public: - - BaseObject *getNextAccessObject(BaseObject *currObject); - BaseObject *getPrevAccessObject(BaseObject *currObject); - bool getSceneObjects(BaseArray &objects, bool interactiveOnly); - bool getRegionObjects(AdRegion *region, BaseArray &objects, bool interactiveOnly); - - bool afterLoad(); - - bool getRegionsAt(int x, int y, AdRegion **regionList, int numRegions); - bool handleItemAssociations(const char *itemName, bool show); - UIWindow *_shieldWindow; - float getRotationAt(int x, int y); - bool loadState(); - bool saveState(); - bool _persistentState; - bool _persistentStateSprites; - BaseObject *getNodeByName(const char *name); - void setOffset(int offsetLeft, int offsetTop); - bool pointInViewport(int x, int y); - int getOffsetTop(); - int getOffsetLeft(); - bool getViewportSize(int *width = NULL, int *height = NULL); - bool getViewportOffset(int *offsetX = NULL, int *offsetY = NULL); - BaseViewport *_viewport; - BaseFader *_fader; - int _pfPointsNum; - void pfPointsAdd(int x, int y, int distance); - void pfPointsStart(); - bool _initialized; - bool correctTargetPoint(int startX, int startY, int *x, int *y, bool checkFreeObjects = false, BaseObject *requester = NULL); - bool correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, BaseObject *requester); - DECLARE_PERSISTENT(AdScene, BaseObject) - bool displayRegionContent(AdRegion *region = NULL, bool display3DOnly = false); - bool displayRegionContentOld(AdRegion *region = NULL); - static int compareObjs(const void *obj1, const void *obj2); - - bool updateFreeObjects(); - bool traverseNodes(bool update = false); - float getScaleAt(int y); - bool sortScaleLevels(); - bool sortRotLevels(); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - uint32 getAlphaAt(int x, int y, bool colorCheck = false); - bool _paralaxScrolling; - void skipTo(int offsetX, int offsetY); - void setDefaults(); - void cleanup(); - void skipToObject(BaseObject *object); - void scrollToObject(BaseObject *object); - void scrollTo(int offsetX, int offsetY); - virtual bool update(); - bool _autoScroll; - int _targetOffsetTop; - int _targetOffsetLeft; - - int _scrollPixelsV; - uint32 _scrollTimeV; - uint32 _lastTimeV; - - int _scrollPixelsH; - uint32 _scrollTimeH; - uint32 _lastTimeH; - - virtual bool display(); - uint32 _pfMaxTime; - bool initLoop(); - void pathFinderStep(); - bool isBlockedAt(int x, int y, bool checkFreeObjects = false, BaseObject *requester = NULL); - bool isWalkableAt(int x, int y, bool checkFreeObjects = false, BaseObject *requester = NULL); - AdLayer *_mainLayer; - float getZoomAt(int x, int y); - bool getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester = NULL); - AdScene(BaseGame *inGame); - virtual ~AdScene(); - BaseArray _layers; - BaseArray _objects; - BaseArray _waypointGroups; - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - int _width; - int _height; - bool addObject(AdObject *Object); - bool removeObject(AdObject *Object); - int _editorMarginH; - int _editorMarginV; - uint32 _editorColFrame; - uint32 _editorColEntity; - uint32 _editorColRegion; - uint32 _editorColBlocked; - uint32 _editorColWaypoints; - uint32 _editorColEntitySel; - uint32 _editorColRegionSel; - uint32 _editorColBlockedSel; - uint32 _editorColWaypointsSel; - uint32 _editorColScale; - uint32 _editorColDecor; - uint32 _editorColDecorSel; - - bool _editorShowRegions; - bool _editorShowBlocked; - bool _editorShowDecor; - bool _editorShowEntities; - bool _editorShowScale; - BaseArray _scaleLevels; - BaseArray _rotLevels; - - virtual bool restoreDeviceObjects(); - int getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester = NULL); - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - virtual const char *scToString(); - - -private: - bool persistState(bool saving = true); - void pfAddWaypointGroup(AdWaypointGroup *Wpt, BaseObject *requester = NULL); - bool _pfReady; - BasePoint *_pfTarget; - AdPath *_pfTargetPath; - BaseObject *_pfRequester; - BaseArray _pfPath; - - int _offsetTop; - int _offsetLeft; - -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENE_H +#define WINTERMUTE_ADSCENE_H + +#include "engines/wintermute/base/base_fader.h" + +namespace Wintermute { + +class UIWindow; +class AdObject; +class AdRegion; +class BaseViewport; +class AdLayer; +class BasePoint; +class AdWaypointGroup; +class AdPath; +class AdScaleLevel; +class AdRotLevel; +class AdPathPoint; +class AdScene : public BaseObject { +public: + + BaseObject *getNextAccessObject(BaseObject *currObject); + BaseObject *getPrevAccessObject(BaseObject *currObject); + bool getSceneObjects(BaseArray &objects, bool interactiveOnly); + bool getRegionObjects(AdRegion *region, BaseArray &objects, bool interactiveOnly); + + bool afterLoad(); + + bool getRegionsAt(int x, int y, AdRegion **regionList, int numRegions); + bool handleItemAssociations(const char *itemName, bool show); + UIWindow *_shieldWindow; + float getRotationAt(int x, int y); + bool loadState(); + bool saveState(); + bool _persistentState; + bool _persistentStateSprites; + BaseObject *getNodeByName(const char *name); + void setOffset(int offsetLeft, int offsetTop); + bool pointInViewport(int x, int y); + int getOffsetTop(); + int getOffsetLeft(); + bool getViewportSize(int *width = NULL, int *height = NULL); + bool getViewportOffset(int *offsetX = NULL, int *offsetY = NULL); + BaseViewport *_viewport; + BaseFader *_fader; + int _pfPointsNum; + void pfPointsAdd(int x, int y, int distance); + void pfPointsStart(); + bool _initialized; + bool correctTargetPoint(int startX, int startY, int *x, int *y, bool checkFreeObjects = false, BaseObject *requester = NULL); + bool correctTargetPoint2(int startX, int startY, int *targetX, int *targetY, bool checkFreeObjects, BaseObject *requester); + DECLARE_PERSISTENT(AdScene, BaseObject) + bool displayRegionContent(AdRegion *region = NULL, bool display3DOnly = false); + bool displayRegionContentOld(AdRegion *region = NULL); + static int compareObjs(const void *obj1, const void *obj2); + + bool updateFreeObjects(); + bool traverseNodes(bool update = false); + float getScaleAt(int y); + bool sortScaleLevels(); + bool sortRotLevels(); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + uint32 getAlphaAt(int x, int y, bool colorCheck = false); + bool _paralaxScrolling; + void skipTo(int offsetX, int offsetY); + void setDefaults(); + void cleanup(); + void skipToObject(BaseObject *object); + void scrollToObject(BaseObject *object); + void scrollTo(int offsetX, int offsetY); + virtual bool update(); + bool _autoScroll; + int _targetOffsetTop; + int _targetOffsetLeft; + + int _scrollPixelsV; + uint32 _scrollTimeV; + uint32 _lastTimeV; + + int _scrollPixelsH; + uint32 _scrollTimeH; + uint32 _lastTimeH; + + virtual bool display(); + uint32 _pfMaxTime; + bool initLoop(); + void pathFinderStep(); + bool isBlockedAt(int x, int y, bool checkFreeObjects = false, BaseObject *requester = NULL); + bool isWalkableAt(int x, int y, bool checkFreeObjects = false, BaseObject *requester = NULL); + AdLayer *_mainLayer; + float getZoomAt(int x, int y); + bool getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester = NULL); + AdScene(BaseGame *inGame); + virtual ~AdScene(); + BaseArray _layers; + BaseArray _objects; + BaseArray _waypointGroups; + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + int _width; + int _height; + bool addObject(AdObject *Object); + bool removeObject(AdObject *Object); + int _editorMarginH; + int _editorMarginV; + uint32 _editorColFrame; + uint32 _editorColEntity; + uint32 _editorColRegion; + uint32 _editorColBlocked; + uint32 _editorColWaypoints; + uint32 _editorColEntitySel; + uint32 _editorColRegionSel; + uint32 _editorColBlockedSel; + uint32 _editorColWaypointsSel; + uint32 _editorColScale; + uint32 _editorColDecor; + uint32 _editorColDecorSel; + + bool _editorShowRegions; + bool _editorShowBlocked; + bool _editorShowDecor; + bool _editorShowEntities; + bool _editorShowScale; + BaseArray _scaleLevels; + BaseArray _rotLevels; + + virtual bool restoreDeviceObjects(); + int getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester = NULL); + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + virtual const char *scToString(); + + +private: + bool persistState(bool saving = true); + void pfAddWaypointGroup(AdWaypointGroup *Wpt, BaseObject *requester = NULL); + bool _pfReady; + BasePoint *_pfTarget; + AdPath *_pfTargetPath; + BaseObject *_pfRequester; + BaseArray _pfPath; + + int _offsetTop; + int _offsetLeft; + +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_scene_node.cpp b/engines/wintermute/ad/ad_scene_node.cpp index 4f6acdbc95..d0202236fd 100644 --- a/engines/wintermute/ad/ad_scene_node.cpp +++ b/engines/wintermute/ad/ad_scene_node.cpp @@ -1,82 +1,82 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_scene_node.h" -#include "engines/wintermute/base/base_game.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdSceneNode, false) - -////////////////////////////////////////////////////////////////////////// -AdSceneNode::AdSceneNode(BaseGame *inGame) : BaseObject(inGame) { - _type = OBJECT_NONE; - _region = NULL; - _entity = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdSceneNode::~AdSceneNode() { - _gameRef->unregisterObject(_region); - _region = NULL; - - _gameRef->unregisterObject(_entity); - _entity = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSceneNode::setEntity(AdEntity *entity) { - _type = OBJECT_ENTITY; - _entity = entity; - return _gameRef->registerObject(entity); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSceneNode::setRegion(AdRegion *region) { - _type = OBJECT_REGION; - _region = region; - return _gameRef->registerObject(region); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSceneNode::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_entity)); - persistMgr->transfer(TMEMBER(_region)); - persistMgr->transfer(TMEMBER_INT(_type)); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_scene_node.h" +#include "engines/wintermute/base/base_game.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdSceneNode, false) + +////////////////////////////////////////////////////////////////////////// +AdSceneNode::AdSceneNode(BaseGame *inGame) : BaseObject(inGame) { + _type = OBJECT_NONE; + _region = NULL; + _entity = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdSceneNode::~AdSceneNode() { + _gameRef->unregisterObject(_region); + _region = NULL; + + _gameRef->unregisterObject(_entity); + _entity = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSceneNode::setEntity(AdEntity *entity) { + _type = OBJECT_ENTITY; + _entity = entity; + return _gameRef->registerObject(entity); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSceneNode::setRegion(AdRegion *region) { + _type = OBJECT_REGION; + _region = region; + return _gameRef->registerObject(region); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSceneNode::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_entity)); + persistMgr->transfer(TMEMBER(_region)); + persistMgr->transfer(TMEMBER_INT(_type)); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_scene_node.h b/engines/wintermute/ad/ad_scene_node.h index 8cc50b86c4..5bb1606d0e 100644 --- a/engines/wintermute/ad/ad_scene_node.h +++ b/engines/wintermute/ad/ad_scene_node.h @@ -1,54 +1,54 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSCENENODE_H -#define WINTERMUTE_ADSCENENODE_H - - -#include "engines/wintermute/ad/ad_types.h" // Added by ClassView -#include "engines/wintermute/ad/ad_region.h" // Added by ClassView -#include "engines/wintermute/ad/ad_entity.h" - -namespace Wintermute { - -class AdSceneNode : public BaseObject { -public: - DECLARE_PERSISTENT(AdSceneNode, BaseObject) - bool setRegion(AdRegion *region); - bool setEntity(AdEntity *entity); - AdEntity *_entity; - AdRegion *_region; - TObjectType _type; - AdSceneNode(BaseGame *inGame); - virtual ~AdSceneNode(); - -}; - -} - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENENODE_H +#define WINTERMUTE_ADSCENENODE_H + + +#include "engines/wintermute/ad/ad_types.h" // Added by ClassView +#include "engines/wintermute/ad/ad_region.h" // Added by ClassView +#include "engines/wintermute/ad/ad_entity.h" + +namespace Wintermute { + +class AdSceneNode : public BaseObject { +public: + DECLARE_PERSISTENT(AdSceneNode, BaseObject) + bool setRegion(AdRegion *region); + bool setEntity(AdEntity *entity); + AdEntity *_entity; + AdRegion *_region; + TObjectType _type; + AdSceneNode(BaseGame *inGame); + virtual ~AdSceneNode(); + +}; + +} + +#endif diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index 04fd52c382..c09e6a259c 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -1,95 +1,95 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/ad/ad_scene_state.h" -#include "engines/wintermute/ad/ad_node_state.h" -#include "engines/wintermute/platform_osystem.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdSceneState, false) - -////////////////////////////////////////////////////////////////////////// -AdSceneState::AdSceneState(BaseGame *inGame) : BaseClass(inGame) { - _filename = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdSceneState::~AdSceneState() { - delete[] _filename; - _filename = NULL; - - for (uint32 i = 0; i < _nodeStates.size(); i++) { - delete _nodeStates[i]; - } - _nodeStates.clear(); -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSceneState::persist(BasePersistenceManager *persistMgr) { - persistMgr->transfer(TMEMBER(_filename)); - _nodeStates.persist(persistMgr); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void AdSceneState::setFilename(const char *filename) { - delete[] _filename; - _filename = new char [strlen(filename) + 1]; - if (_filename) { - strcpy(_filename, filename); - } -} - - -////////////////////////////////////////////////////////////////////////// -AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { - for (uint32 i = 0; i < _nodeStates.size(); i++) { - if (scumm_stricmp(_nodeStates[i]->getName(), name) == 0) { - return _nodeStates[i]; - } - } - - if (saving) { - AdNodeState *ret = new AdNodeState(_gameRef); - ret->setName(name); - _nodeStates.add(ret); - - return ret; - } else { - return NULL; - } -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/ad/ad_scene_state.h" +#include "engines/wintermute/ad/ad_node_state.h" +#include "engines/wintermute/platform_osystem.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdSceneState, false) + +////////////////////////////////////////////////////////////////////////// +AdSceneState::AdSceneState(BaseGame *inGame) : BaseClass(inGame) { + _filename = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdSceneState::~AdSceneState() { + delete[] _filename; + _filename = NULL; + + for (uint32 i = 0; i < _nodeStates.size(); i++) { + delete _nodeStates[i]; + } + _nodeStates.clear(); +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSceneState::persist(BasePersistenceManager *persistMgr) { + persistMgr->transfer(TMEMBER(_filename)); + _nodeStates.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void AdSceneState::setFilename(const char *filename) { + delete[] _filename; + _filename = new char [strlen(filename) + 1]; + if (_filename) { + strcpy(_filename, filename); + } +} + + +////////////////////////////////////////////////////////////////////////// +AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { + for (uint32 i = 0; i < _nodeStates.size(); i++) { + if (scumm_stricmp(_nodeStates[i]->getName(), name) == 0) { + return _nodeStates[i]; + } + } + + if (saving) { + AdNodeState *ret = new AdNodeState(_gameRef); + ret->setName(name); + _nodeStates.add(ret); + + return ret; + } else { + return NULL; + } +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_scene_state.h b/engines/wintermute/ad/ad_scene_state.h index 8298d23d76..2b25393c5a 100644 --- a/engines/wintermute/ad/ad_scene_state.h +++ b/engines/wintermute/ad/ad_scene_state.h @@ -1,51 +1,51 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSCENESTATE_H -#define WINTERMUTE_ADSCENESTATE_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/base.h" -#include "engines/wintermute/coll_templ.h" - -namespace Wintermute { -class AdNodeState; -class AdSceneState : public BaseClass { -public: - AdNodeState *getNodeState(const char *name, bool saving); - void setFilename(const char *filename); - DECLARE_PERSISTENT(AdSceneState, BaseClass) - AdSceneState(BaseGame *inGame); - virtual ~AdSceneState(); - char *_filename; - BaseArray _nodeStates; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSCENESTATE_H +#define WINTERMUTE_ADSCENESTATE_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base.h" +#include "engines/wintermute/coll_templ.h" + +namespace Wintermute { +class AdNodeState; +class AdSceneState : public BaseClass { +public: + AdNodeState *getNodeState(const char *name, bool saving); + void setFilename(const char *filename); + DECLARE_PERSISTENT(AdSceneState, BaseClass) + AdSceneState(BaseGame *inGame); + virtual ~AdSceneState(); + char *_filename; + BaseArray _nodeStates; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index 51765e3fe9..1f09d3ae0f 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -1,360 +1,360 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_sentence.h" -#include "engines/wintermute/ad/ad_talk_def.h" -#include "engines/wintermute/ad/ad_talk_node.h" -#include "engines/wintermute/ad/ad_game.h" -#include "engines/wintermute/utils/path_util.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/sound/base_sound.h" -#include "engines/wintermute/ad/ad_scene.h" -#include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_file_manager.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdSentence, false) - -////////////////////////////////////////////////////////////////////////// -AdSentence::AdSentence(BaseGame *inGame) : BaseClass(inGame) { - _text = NULL; - _stances = NULL; - _tempStance = NULL; - - _duration = 0; - _startTime = 0; - _currentStance = 0; - - _font = NULL; - - _pos.x = _pos.y = 0; - _width = _gameRef->_renderer->_width; - - _align = (TTextAlign)TAL_CENTER; - - _sound = NULL; - _soundStarted = false; - - _talkDef = NULL; - _currentSprite = NULL; - _currentSkelAnim = NULL; - _fixedPos = false; - _freezable = true; -} - - -////////////////////////////////////////////////////////////////////////// -AdSentence::~AdSentence() { - delete _sound; - delete[] _text; - delete[] _stances; - delete[] _tempStance; - delete _talkDef; - _sound = NULL; - _text = NULL; - _stances = NULL; - _tempStance = NULL; - _talkDef = NULL; - - _currentSprite = NULL; // ref only - _currentSkelAnim = NULL; - _font = NULL; // ref only -} - - -////////////////////////////////////////////////////////////////////////// -void AdSentence::setText(const char *text) { - if (_text) { - delete[] _text; - } - _text = new char[strlen(text) + 1]; - if (_text) { - strcpy(_text, text); - } -} - - -////////////////////////////////////////////////////////////////////////// -void AdSentence::setStances(const char *stances) { - if (_stances) { - delete[] _stances; - } - if (stances) { - _stances = new char[strlen(stances) + 1]; - if (_stances) { - strcpy(_stances, stances); - } - } else { - _stances = NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -char *AdSentence::getCurrentStance() { - return getStance(_currentStance); -} - - -////////////////////////////////////////////////////////////////////////// -char *AdSentence::getNextStance() { - _currentStance++; - return getStance(_currentStance); -} - - -////////////////////////////////////////////////////////////////////////// -char *AdSentence::getStance(int stance) { - if (_stances == NULL) { - return NULL; - } - - if (_tempStance) { - delete[] _tempStance; - } - _tempStance = NULL; - - char *start; - char *curr; - int pos; - - if (stance == 0) { - start = _stances; - } else { - pos = 0; - start = NULL; - curr = _stances; - while (pos < stance) { - if (*curr == '\0') { - break; - } - if (*curr == ',') { - pos++; - } - curr++; - } - if (pos == stance) { - start = curr; - } - } - - if (start == NULL) { - return NULL; - } - - while (*start == ' ' && *start != ',' && *start != '\0') { - start++; - } - - curr = start; - while (*curr != '\0' && *curr != ',') { - curr++; - } - - while (curr > start && *(curr - 1) == ' ') { - curr--; - } - - _tempStance = new char [curr - start + 1]; - if (_tempStance) { - Common::strlcpy(_tempStance, start, curr - start + 1); - } - - return _tempStance; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSentence::display() { - if (!_font || !_text) { - return STATUS_FAILED; - } - - if (_sound && !_soundStarted) { - _sound->play(); - _soundStarted = true; - } - - if (_gameRef->_subtitles) { - int x = _pos.x; - int y = _pos.y; - - if (!_fixedPos) { - x = x - ((AdGame *)_gameRef)->_scene->getOffsetLeft(); - y = y - ((AdGame *)_gameRef)->_scene->getOffsetTop(); - } - - - x = MAX(x, 0); - x = MIN(x, _gameRef->_renderer->_width - _width); - y = MAX(y, 0); - - _font->drawText((byte *)_text, x, y, _width, _align); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -void AdSentence::setSound(BaseSound *sound) { - if (!sound) { - return; - } - delete _sound; - _sound = sound; - _soundStarted = false; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSentence::finish() { - if (_sound) { - _sound->stop(); - } - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSentence::persist(BasePersistenceManager *persistMgr) { - - persistMgr->transfer(TMEMBER(_gameRef)); - - persistMgr->transfer(TMEMBER_INT(_align)); - persistMgr->transfer(TMEMBER(_currentStance)); - persistMgr->transfer(TMEMBER(_currentSprite)); - persistMgr->transfer(TMEMBER(_currentSkelAnim)); - persistMgr->transfer(TMEMBER(_duration)); - persistMgr->transfer(TMEMBER(_font)); - persistMgr->transfer(TMEMBER(_pos)); - persistMgr->transfer(TMEMBER(_sound)); - persistMgr->transfer(TMEMBER(_soundStarted)); - persistMgr->transfer(TMEMBER(_stances)); - persistMgr->transfer(TMEMBER(_startTime)); - persistMgr->transfer(TMEMBER(_talkDef)); - persistMgr->transfer(TMEMBER(_tempStance)); - persistMgr->transfer(TMEMBER(_text)); - persistMgr->transfer(TMEMBER(_width)); - persistMgr->transfer(TMEMBER(_fixedPos)); - persistMgr->transfer(TMEMBER(_freezable)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSentence::setupTalkFile(const char *soundFilename) { - delete _talkDef; - _talkDef = NULL; - _currentSprite = NULL; - - if (!soundFilename) { - return STATUS_OK; - } - - - AnsiString path = PathUtil::getDirectoryName(soundFilename); - AnsiString name = PathUtil::getFileNameWithoutExtension(soundFilename); - - AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); - - if (!BaseFileManager::getEngineInstance()->hasFile(talkDefFileName)) { - return STATUS_OK; // no talk def file found - } - - _talkDef = new AdTalkDef(_gameRef); - if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { - delete _talkDef; - _talkDef = NULL; - return STATUS_FAILED; - } - //_gameRef->LOG(0, "Using .talk file: %s", TalkDefFile); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSentence::update(TDirection dir) { - if (!_talkDef) { - return STATUS_OK; - } - - uint32 currentTime; - // if sound is available, synchronize with sound, otherwise use timer - - /* - if (_sound) CurrentTime = _sound->GetPositionTime(); - else CurrentTime = _gameRef->_timer - _startTime; - */ - currentTime = _gameRef->_timer - _startTime; - - bool talkNodeFound = false; - for (uint32 i = 0; i < _talkDef->_nodes.size(); i++) { - if (_talkDef->_nodes[i]->isInTimeInterval(currentTime, dir)) { - talkNodeFound = true; - - BaseSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); - if (newSprite != _currentSprite) { - newSprite->reset(); - } - _currentSprite = newSprite; - - if (!_talkDef->_nodes[i]->_playToEnd) { - break; - } - } - } - - - // no talk node, try to use default sprite instead (if any) - if (!talkNodeFound) { - BaseSprite *newSprite = _talkDef->getDefaultSprite(dir); - if (newSprite) { - if (newSprite != _currentSprite) { - newSprite->reset(); - } - _currentSprite = newSprite; - } else { - _currentSprite = NULL; - } - } - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdSentence::canSkip() { - // prevent accidental sentence skipping (TODO make configurable) - return (_gameRef->_timer - _startTime) > 300; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/ad/ad_talk_def.h" +#include "engines/wintermute/ad/ad_talk_node.h" +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/utils/path_util.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/sound/base_sound.h" +#include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_file_manager.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdSentence, false) + +////////////////////////////////////////////////////////////////////////// +AdSentence::AdSentence(BaseGame *inGame) : BaseClass(inGame) { + _text = NULL; + _stances = NULL; + _tempStance = NULL; + + _duration = 0; + _startTime = 0; + _currentStance = 0; + + _font = NULL; + + _pos.x = _pos.y = 0; + _width = _gameRef->_renderer->_width; + + _align = (TTextAlign)TAL_CENTER; + + _sound = NULL; + _soundStarted = false; + + _talkDef = NULL; + _currentSprite = NULL; + _currentSkelAnim = NULL; + _fixedPos = false; + _freezable = true; +} + + +////////////////////////////////////////////////////////////////////////// +AdSentence::~AdSentence() { + delete _sound; + delete[] _text; + delete[] _stances; + delete[] _tempStance; + delete _talkDef; + _sound = NULL; + _text = NULL; + _stances = NULL; + _tempStance = NULL; + _talkDef = NULL; + + _currentSprite = NULL; // ref only + _currentSkelAnim = NULL; + _font = NULL; // ref only +} + + +////////////////////////////////////////////////////////////////////////// +void AdSentence::setText(const char *text) { + if (_text) { + delete[] _text; + } + _text = new char[strlen(text) + 1]; + if (_text) { + strcpy(_text, text); + } +} + + +////////////////////////////////////////////////////////////////////////// +void AdSentence::setStances(const char *stances) { + if (_stances) { + delete[] _stances; + } + if (stances) { + _stances = new char[strlen(stances) + 1]; + if (_stances) { + strcpy(_stances, stances); + } + } else { + _stances = NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +char *AdSentence::getCurrentStance() { + return getStance(_currentStance); +} + + +////////////////////////////////////////////////////////////////////////// +char *AdSentence::getNextStance() { + _currentStance++; + return getStance(_currentStance); +} + + +////////////////////////////////////////////////////////////////////////// +char *AdSentence::getStance(int stance) { + if (_stances == NULL) { + return NULL; + } + + if (_tempStance) { + delete[] _tempStance; + } + _tempStance = NULL; + + char *start; + char *curr; + int pos; + + if (stance == 0) { + start = _stances; + } else { + pos = 0; + start = NULL; + curr = _stances; + while (pos < stance) { + if (*curr == '\0') { + break; + } + if (*curr == ',') { + pos++; + } + curr++; + } + if (pos == stance) { + start = curr; + } + } + + if (start == NULL) { + return NULL; + } + + while (*start == ' ' && *start != ',' && *start != '\0') { + start++; + } + + curr = start; + while (*curr != '\0' && *curr != ',') { + curr++; + } + + while (curr > start && *(curr - 1) == ' ') { + curr--; + } + + _tempStance = new char [curr - start + 1]; + if (_tempStance) { + Common::strlcpy(_tempStance, start, curr - start + 1); + } + + return _tempStance; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSentence::display() { + if (!_font || !_text) { + return STATUS_FAILED; + } + + if (_sound && !_soundStarted) { + _sound->play(); + _soundStarted = true; + } + + if (_gameRef->_subtitles) { + int x = _pos.x; + int y = _pos.y; + + if (!_fixedPos) { + x = x - ((AdGame *)_gameRef)->_scene->getOffsetLeft(); + y = y - ((AdGame *)_gameRef)->_scene->getOffsetTop(); + } + + + x = MAX(x, 0); + x = MIN(x, _gameRef->_renderer->_width - _width); + y = MAX(y, 0); + + _font->drawText((byte *)_text, x, y, _width, _align); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +void AdSentence::setSound(BaseSound *sound) { + if (!sound) { + return; + } + delete _sound; + _sound = sound; + _soundStarted = false; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSentence::finish() { + if (_sound) { + _sound->stop(); + } + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSentence::persist(BasePersistenceManager *persistMgr) { + + persistMgr->transfer(TMEMBER(_gameRef)); + + persistMgr->transfer(TMEMBER_INT(_align)); + persistMgr->transfer(TMEMBER(_currentStance)); + persistMgr->transfer(TMEMBER(_currentSprite)); + persistMgr->transfer(TMEMBER(_currentSkelAnim)); + persistMgr->transfer(TMEMBER(_duration)); + persistMgr->transfer(TMEMBER(_font)); + persistMgr->transfer(TMEMBER(_pos)); + persistMgr->transfer(TMEMBER(_sound)); + persistMgr->transfer(TMEMBER(_soundStarted)); + persistMgr->transfer(TMEMBER(_stances)); + persistMgr->transfer(TMEMBER(_startTime)); + persistMgr->transfer(TMEMBER(_talkDef)); + persistMgr->transfer(TMEMBER(_tempStance)); + persistMgr->transfer(TMEMBER(_text)); + persistMgr->transfer(TMEMBER(_width)); + persistMgr->transfer(TMEMBER(_fixedPos)); + persistMgr->transfer(TMEMBER(_freezable)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSentence::setupTalkFile(const char *soundFilename) { + delete _talkDef; + _talkDef = NULL; + _currentSprite = NULL; + + if (!soundFilename) { + return STATUS_OK; + } + + + AnsiString path = PathUtil::getDirectoryName(soundFilename); + AnsiString name = PathUtil::getFileNameWithoutExtension(soundFilename); + + AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); + + if (!BaseFileManager::getEngineInstance()->hasFile(talkDefFileName)) { + return STATUS_OK; // no talk def file found + } + + _talkDef = new AdTalkDef(_gameRef); + if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { + delete _talkDef; + _talkDef = NULL; + return STATUS_FAILED; + } + //_gameRef->LOG(0, "Using .talk file: %s", TalkDefFile); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSentence::update(TDirection dir) { + if (!_talkDef) { + return STATUS_OK; + } + + uint32 currentTime; + // if sound is available, synchronize with sound, otherwise use timer + + /* + if (_sound) CurrentTime = _sound->GetPositionTime(); + else CurrentTime = _gameRef->_timer - _startTime; + */ + currentTime = _gameRef->_timer - _startTime; + + bool talkNodeFound = false; + for (uint32 i = 0; i < _talkDef->_nodes.size(); i++) { + if (_talkDef->_nodes[i]->isInTimeInterval(currentTime, dir)) { + talkNodeFound = true; + + BaseSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); + if (newSprite != _currentSprite) { + newSprite->reset(); + } + _currentSprite = newSprite; + + if (!_talkDef->_nodes[i]->_playToEnd) { + break; + } + } + } + + + // no talk node, try to use default sprite instead (if any) + if (!talkNodeFound) { + BaseSprite *newSprite = _talkDef->getDefaultSprite(dir); + if (newSprite) { + if (newSprite != _currentSprite) { + newSprite->reset(); + } + _currentSprite = newSprite; + } else { + _currentSprite = NULL; + } + } + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdSentence::canSkip() { + // prevent accidental sentence skipping (TODO make configurable) + return (_gameRef->_timer - _startTime) > 300; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_sentence.h b/engines/wintermute/ad/ad_sentence.h index 85be09094c..e7c94030b9 100644 --- a/engines/wintermute/ad/ad_sentence.h +++ b/engines/wintermute/ad/ad_sentence.h @@ -1,85 +1,85 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSENTENCE_H -#define WINTERMUTE_ADSENTENCE_H - - -#include "engines/wintermute/base/base.h" -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/math/rect32.h" -#include "engines/wintermute/dctypes.h" // Added by ClassView -#include "common/rect.h" - -namespace Wintermute { -class AdTalkDef; -class BaseFont; -class BaseSprite; -class BaseSound; -class AdSentence : public BaseClass { -public: - bool _freezable; - bool _fixedPos; - BaseSprite *_currentSprite; - char *_currentSkelAnim; - bool update(TDirection dir = DI_DOWN); - bool setupTalkFile(const char *soundFilename); - DECLARE_PERSISTENT(AdSentence, BaseClass) - bool finish(); - void setSound(BaseSound *Sound); - bool _soundStarted; - BaseSound *_sound; - TTextAlign _align; - bool display(); - int _width; - Point32 _pos; - BaseFont *_font; - char *getNextStance(); - char *getCurrentStance(); - void setStances(const char *stances); - void setText(const char *text); - int _currentStance; - uint32 _startTime; - char *_stances; - char *_text; - uint32 _duration; - AdSentence(BaseGame *inGame); - virtual ~AdSentence(); - AdTalkDef *_talkDef; - - bool canSkip(); - -private: - char *_tempStance; - char *getStance(int stance); - -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSENTENCE_H +#define WINTERMUTE_ADSENTENCE_H + + +#include "engines/wintermute/base/base.h" +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/math/rect32.h" +#include "engines/wintermute/dctypes.h" // Added by ClassView +#include "common/rect.h" + +namespace Wintermute { +class AdTalkDef; +class BaseFont; +class BaseSprite; +class BaseSound; +class AdSentence : public BaseClass { +public: + bool _freezable; + bool _fixedPos; + BaseSprite *_currentSprite; + char *_currentSkelAnim; + bool update(TDirection dir = DI_DOWN); + bool setupTalkFile(const char *soundFilename); + DECLARE_PERSISTENT(AdSentence, BaseClass) + bool finish(); + void setSound(BaseSound *Sound); + bool _soundStarted; + BaseSound *_sound; + TTextAlign _align; + bool display(); + int _width; + Point32 _pos; + BaseFont *_font; + char *getNextStance(); + char *getCurrentStance(); + void setStances(const char *stances); + void setText(const char *text); + int _currentStance; + uint32 _startTime; + char *_stances; + char *_text; + uint32 _duration; + AdSentence(BaseGame *inGame); + virtual ~AdSentence(); + AdTalkDef *_talkDef; + + bool canSkip(); + +private: + char *_tempStance; + char *getStance(int stance); + +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index 5b605d6e32..c8cdec03c3 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -1,356 +1,356 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_sprite_set.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/base/base_sprite.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdSpriteSet, false) - -////////////////////////////////////////////////////////////////////////// -AdSpriteSet::AdSpriteSet(BaseGame *inGame, BaseObject *owner) : BaseObject(inGame) { - _owner = owner; - - for (int i = 0; i < NUM_DIRECTIONS; i++) { - _sprites[i] = NULL; - } -} - - -////////////////////////////////////////////////////////////////////////// -AdSpriteSet::~AdSpriteSet() { - for (int i = 0; i < NUM_DIRECTIONS; i++) { - delete _sprites[i]; - _sprites[i] = NULL; - } - - _owner = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdSpriteSet::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); - } - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(SPRITESET) -TOKEN_DEF(NAME) -TOKEN_DEF(UP_LEFT) -TOKEN_DEF(DOWN_LEFT) -TOKEN_DEF(LEFT) -TOKEN_DEF(UP_RIGHT) -TOKEN_DEF(DOWN_RIGHT) -TOKEN_DEF(RIGHT) -TOKEN_DEF(UP) -TOKEN_DEF(DOWN) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType cacheType) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(SPRITESET) - TOKEN_TABLE(NAME) - TOKEN_TABLE(UP_LEFT) - TOKEN_TABLE(DOWN_LEFT) - TOKEN_TABLE(LEFT) - TOKEN_TABLE(UP_RIGHT) - TOKEN_TABLE(DOWN_RIGHT) - TOKEN_TABLE(RIGHT) - TOKEN_TABLE(UP) - TOKEN_TABLE(DOWN) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SPRITESET) { - _gameRef->LOG(0, "'SPRITESET' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - BaseSprite *spr = NULL; - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_LEFT: - delete _sprites[DI_LEFT]; - _sprites[DI_LEFT] = NULL; - spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } else { - _sprites[DI_LEFT] = spr; - } - break; - - case TOKEN_RIGHT: - delete _sprites[DI_RIGHT]; - _sprites[DI_RIGHT] = NULL; - spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } else { - _sprites[DI_RIGHT] = spr; - } - break; - - case TOKEN_UP: - delete _sprites[DI_UP]; - _sprites[DI_UP] = NULL; - spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } else { - _sprites[DI_UP] = spr; - } - break; - - case TOKEN_DOWN: - delete _sprites[DI_DOWN]; - _sprites[DI_DOWN] = NULL; - spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } else { - _sprites[DI_DOWN] = spr; - } - break; - - case TOKEN_UP_LEFT: - delete _sprites[DI_UPLEFT]; - _sprites[DI_UPLEFT] = NULL; - spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } else { - _sprites[DI_UPLEFT] = spr; - } - break; - - case TOKEN_UP_RIGHT: - delete _sprites[DI_UPRIGHT]; - _sprites[DI_UPRIGHT] = NULL; - spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } else { - _sprites[DI_UPRIGHT] = spr; - } - break; - - case TOKEN_DOWN_LEFT: - delete _sprites[DI_DOWNLEFT]; - _sprites[DI_DOWNLEFT] = NULL; - spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } else { - _sprites[DI_DOWNLEFT] = spr; - } - break; - - case TOKEN_DOWN_RIGHT: - delete _sprites[DI_DOWNRIGHT]; - _sprites[DI_DOWNRIGHT] = NULL; - spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { - cmd = PARSERR_GENERIC; - } else { - _sprites[DI_DOWNRIGHT] = spr; - } - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in SPRITESET definition"); - return STATUS_FAILED; - } - - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading SPRITESET definition"); - if (spr) { - delete spr; - } - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdSpriteSet::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_owner)); - for (int i = 0; i < NUM_DIRECTIONS; i++) { - persistMgr->transfer("", &_sprites[i]); - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -BaseSprite *AdSpriteSet::getSprite(TDirection direction) { - int dir = (int)direction; - if (dir < 0) { - dir = 0; - } - if (dir >= NUM_DIRECTIONS) { - dir = NUM_DIRECTIONS - 1; - } - - BaseSprite *ret = NULL; - - // find nearest set sprite - int numSteps = 0; - for (int i = dir; i >= 0; i--) { - if (_sprites[i] != NULL) { - ret = _sprites[i]; - numSteps = dir - i; - break; - } - } - - for (int i = dir; i < NUM_DIRECTIONS; i++) { - if (_sprites[i] != NULL) { - if (ret == NULL || numSteps > i - dir) { - return _sprites[i]; - } else { - return ret; - } - } - } - - return ret; -} - - - -////////////////////////////////////////////////////////////////////////// -bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "SPRITESET {\n"); - if (getName()) { - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - } - for (int i = 0; i < NUM_DIRECTIONS; i++) { - if (_sprites[i]) { - switch (i) { - case DI_UP: - buffer->putTextIndent(indent + 2, "UP=\"%s\"\n", _sprites[i]->getFilename()); - break; - case DI_UPRIGHT: - buffer->putTextIndent(indent + 2, "UP_RIGHT=\"%s\"\n", _sprites[i]->getFilename()); - break; - case DI_RIGHT: - buffer->putTextIndent(indent + 2, "RIGHT=\"%s\"\n", _sprites[i]->getFilename()); - break; - case DI_DOWNRIGHT: - buffer->putTextIndent(indent + 2, "DOWN_RIGHT=\"%s\"\n", _sprites[i]->getFilename()); - break; - case DI_DOWN: - buffer->putTextIndent(indent + 2, "DOWN=\"%s\"\n", _sprites[i]->getFilename()); - break; - case DI_DOWNLEFT: - buffer->putTextIndent(indent + 2, "DOWN_LEFT=\"%s\"\n", _sprites[i]->getFilename()); - break; - case DI_LEFT: - buffer->putTextIndent(indent + 2, "LEFT=\"%s\"\n", _sprites[i]->getFilename()); - break; - case DI_UPLEFT: - buffer->putTextIndent(indent + 2, "UP_LEFT=\"%s\"\n", _sprites[i]->getFilename()); - break; - } - } - } - - BaseClass::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - -////////////////////////////////////////////////////////////////////////// -bool AdSpriteSet::containsSprite(BaseSprite *sprite) { - if (!sprite) { - return false; - } - - for (int i = 0; i < NUM_DIRECTIONS; i++) { - if (_sprites[i] == sprite) { - return true; - } - } - return false; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_sprite_set.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_sprite.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdSpriteSet, false) + +////////////////////////////////////////////////////////////////////////// +AdSpriteSet::AdSpriteSet(BaseGame *inGame, BaseObject *owner) : BaseObject(inGame) { + _owner = owner; + + for (int i = 0; i < NUM_DIRECTIONS; i++) { + _sprites[i] = NULL; + } +} + + +////////////////////////////////////////////////////////////////////////// +AdSpriteSet::~AdSpriteSet() { + for (int i = 0; i < NUM_DIRECTIONS; i++) { + delete _sprites[i]; + _sprites[i] = NULL; + } + + _owner = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType cacheType) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdSpriteSet::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); + } + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(SPRITESET) +TOKEN_DEF(NAME) +TOKEN_DEF(UP_LEFT) +TOKEN_DEF(DOWN_LEFT) +TOKEN_DEF(LEFT) +TOKEN_DEF(UP_RIGHT) +TOKEN_DEF(DOWN_RIGHT) +TOKEN_DEF(RIGHT) +TOKEN_DEF(UP) +TOKEN_DEF(DOWN) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType cacheType) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(SPRITESET) + TOKEN_TABLE(NAME) + TOKEN_TABLE(UP_LEFT) + TOKEN_TABLE(DOWN_LEFT) + TOKEN_TABLE(LEFT) + TOKEN_TABLE(UP_RIGHT) + TOKEN_TABLE(DOWN_RIGHT) + TOKEN_TABLE(RIGHT) + TOKEN_TABLE(UP) + TOKEN_TABLE(DOWN) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_SPRITESET) { + _gameRef->LOG(0, "'SPRITESET' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + BaseSprite *spr = NULL; + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_LEFT: + delete _sprites[DI_LEFT]; + _sprites[DI_LEFT] = NULL; + spr = new BaseSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_LEFT] = spr; + } + break; + + case TOKEN_RIGHT: + delete _sprites[DI_RIGHT]; + _sprites[DI_RIGHT] = NULL; + spr = new BaseSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_RIGHT] = spr; + } + break; + + case TOKEN_UP: + delete _sprites[DI_UP]; + _sprites[DI_UP] = NULL; + spr = new BaseSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UP] = spr; + } + break; + + case TOKEN_DOWN: + delete _sprites[DI_DOWN]; + _sprites[DI_DOWN] = NULL; + spr = new BaseSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWN] = spr; + } + break; + + case TOKEN_UP_LEFT: + delete _sprites[DI_UPLEFT]; + _sprites[DI_UPLEFT] = NULL; + spr = new BaseSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UPLEFT] = spr; + } + break; + + case TOKEN_UP_RIGHT: + delete _sprites[DI_UPRIGHT]; + _sprites[DI_UPRIGHT] = NULL; + spr = new BaseSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UPRIGHT] = spr; + } + break; + + case TOKEN_DOWN_LEFT: + delete _sprites[DI_DOWNLEFT]; + _sprites[DI_DOWNLEFT] = NULL; + spr = new BaseSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWNLEFT] = spr; + } + break; + + case TOKEN_DOWN_RIGHT: + delete _sprites[DI_DOWNRIGHT]; + _sprites[DI_DOWNRIGHT] = NULL; + spr = new BaseSprite(_gameRef, _owner); + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWNRIGHT] = spr; + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in SPRITESET definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading SPRITESET definition"); + if (spr) { + delete spr; + } + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdSpriteSet::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_owner)); + for (int i = 0; i < NUM_DIRECTIONS; i++) { + persistMgr->transfer("", &_sprites[i]); + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +BaseSprite *AdSpriteSet::getSprite(TDirection direction) { + int dir = (int)direction; + if (dir < 0) { + dir = 0; + } + if (dir >= NUM_DIRECTIONS) { + dir = NUM_DIRECTIONS - 1; + } + + BaseSprite *ret = NULL; + + // find nearest set sprite + int numSteps = 0; + for (int i = dir; i >= 0; i--) { + if (_sprites[i] != NULL) { + ret = _sprites[i]; + numSteps = dir - i; + break; + } + } + + for (int i = dir; i < NUM_DIRECTIONS; i++) { + if (_sprites[i] != NULL) { + if (ret == NULL || numSteps > i - dir) { + return _sprites[i]; + } else { + return ret; + } + } + } + + return ret; +} + + + +////////////////////////////////////////////////////////////////////////// +bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "SPRITESET {\n"); + if (getName()) { + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + } + for (int i = 0; i < NUM_DIRECTIONS; i++) { + if (_sprites[i]) { + switch (i) { + case DI_UP: + buffer->putTextIndent(indent + 2, "UP=\"%s\"\n", _sprites[i]->getFilename()); + break; + case DI_UPRIGHT: + buffer->putTextIndent(indent + 2, "UP_RIGHT=\"%s\"\n", _sprites[i]->getFilename()); + break; + case DI_RIGHT: + buffer->putTextIndent(indent + 2, "RIGHT=\"%s\"\n", _sprites[i]->getFilename()); + break; + case DI_DOWNRIGHT: + buffer->putTextIndent(indent + 2, "DOWN_RIGHT=\"%s\"\n", _sprites[i]->getFilename()); + break; + case DI_DOWN: + buffer->putTextIndent(indent + 2, "DOWN=\"%s\"\n", _sprites[i]->getFilename()); + break; + case DI_DOWNLEFT: + buffer->putTextIndent(indent + 2, "DOWN_LEFT=\"%s\"\n", _sprites[i]->getFilename()); + break; + case DI_LEFT: + buffer->putTextIndent(indent + 2, "LEFT=\"%s\"\n", _sprites[i]->getFilename()); + break; + case DI_UPLEFT: + buffer->putTextIndent(indent + 2, "UP_LEFT=\"%s\"\n", _sprites[i]->getFilename()); + break; + } + } + } + + BaseClass::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + +////////////////////////////////////////////////////////////////////////// +bool AdSpriteSet::containsSprite(BaseSprite *sprite) { + if (!sprite) { + return false; + } + + for (int i = 0; i < NUM_DIRECTIONS; i++) { + if (_sprites[i] == sprite) { + return true; + } + } + return false; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_sprite_set.h b/engines/wintermute/ad/ad_sprite_set.h index 3855114850..ba5da0ff2e 100644 --- a/engines/wintermute/ad/ad_sprite_set.h +++ b/engines/wintermute/ad/ad_sprite_set.h @@ -1,53 +1,53 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADSPRITESET_H -#define WINTERMUTE_ADSPRITESET_H - - -#include "engines/wintermute/base/base_object.h" - -namespace Wintermute { -class BaseSprite; -class AdSpriteSet : public BaseObject { -public: - bool containsSprite(BaseSprite *sprite); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); - BaseSprite *getSprite(TDirection direction); - DECLARE_PERSISTENT(AdSpriteSet, BaseObject) - BaseObject *_owner; - AdSpriteSet(BaseGame *inGame, BaseObject *owner = NULL); - virtual ~AdSpriteSet(); - bool loadFile(const char *filename, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); - bool loadBuffer(byte *buffer, bool complete = true, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); - BaseSprite *_sprites[NUM_DIRECTIONS]; -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADSPRITESET_H +#define WINTERMUTE_ADSPRITESET_H + + +#include "engines/wintermute/base/base_object.h" + +namespace Wintermute { +class BaseSprite; +class AdSpriteSet : public BaseObject { +public: + bool containsSprite(BaseSprite *sprite); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); + BaseSprite *getSprite(TDirection direction); + DECLARE_PERSISTENT(AdSpriteSet, BaseObject) + BaseObject *_owner; + AdSpriteSet(BaseGame *inGame, BaseObject *owner = NULL); + virtual ~AdSpriteSet(); + bool loadFile(const char *filename, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); + bool loadBuffer(byte *buffer, bool complete = true, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); + BaseSprite *_sprites[NUM_DIRECTIONS]; +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index cd96345fc8..8cb489509b 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -1,285 +1,285 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_talk_def.h" -#include "engines/wintermute/ad/ad_talk_node.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/ad/ad_sprite_set.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/utils/utils.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdTalkDef, false) - -////////////////////////////////////////////////////////////////////////// -AdTalkDef::AdTalkDef(BaseGame *inGame) : BaseObject(inGame) { - _defaultSpriteFilename = NULL; - _defaultSprite = NULL; - - _defaultSpriteSetFilename = NULL; - _defaultSpriteSet = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdTalkDef::~AdTalkDef() { - for (uint32 i = 0; i < _nodes.size(); i++) { - delete _nodes[i]; - } - _nodes.clear(); - - delete[] _defaultSpriteFilename; - delete _defaultSprite; - _defaultSpriteFilename = NULL; - _defaultSprite = NULL; - - delete[] _defaultSpriteSetFilename; - delete _defaultSpriteSet; - _defaultSpriteSetFilename = NULL; - _defaultSpriteSet = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkDef::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdTalkDef::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); - } - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(TALK) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(ACTION) -TOKEN_DEF(DEFAULT_SPRITESET_FILE) -TOKEN_DEF(DEFAULT_SPRITESET) -TOKEN_DEF(DEFAULT_SPRITE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdTalkDef::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(TALK) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(ACTION) - TOKEN_TABLE(DEFAULT_SPRITESET_FILE) - TOKEN_TABLE(DEFAULT_SPRITESET) - TOKEN_TABLE(DEFAULT_SPRITE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_TALK) { - _gameRef->LOG(0, "'TALK' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_ACTION: { - AdTalkNode *node = new AdTalkNode(_gameRef); - if (node && DID_SUCCEED(node->loadBuffer(params, false))) { - _nodes.add(node); - } else { - delete node; - node = NULL; - cmd = PARSERR_GENERIC; - } - } - break; - - case TOKEN_DEFAULT_SPRITE: - BaseUtils::setString(&_defaultSpriteFilename, (char *)params); - break; - - case TOKEN_DEFAULT_SPRITESET_FILE: - BaseUtils::setString(&_defaultSpriteSetFilename, (char *)params); - break; - - case TOKEN_DEFAULT_SPRITESET: { - delete _defaultSpriteSet; - _defaultSpriteSet = new AdSpriteSet(_gameRef); - if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadBuffer(params, false))) { - delete _defaultSpriteSet; - _defaultSpriteSet = NULL; - cmd = PARSERR_GENERIC; - } - } - break; - - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in TALK definition"); - return STATUS_FAILED; - } - - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading TALK definition"); - return STATUS_FAILED; - } - - delete _defaultSprite; - delete _defaultSpriteSet; - _defaultSprite = NULL; - _defaultSpriteSet = NULL; - - if (_defaultSpriteFilename) { - _defaultSprite = new BaseSprite(_gameRef); - if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { - return STATUS_FAILED; - } - } - - if (_defaultSpriteSetFilename) { - _defaultSpriteSet = new AdSpriteSet(_gameRef); - if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { - return STATUS_FAILED; - } - } - - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkDef::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_defaultSprite)); - persistMgr->transfer(TMEMBER(_defaultSpriteFilename)); - persistMgr->transfer(TMEMBER(_defaultSpriteSet)); - persistMgr->transfer(TMEMBER(_defaultSpriteSetFilename)); - - _nodes.persist(persistMgr); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkDef::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "TALK {\n"); - if (_defaultSpriteFilename) { - buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); - } - - if (_defaultSpriteSetFilename) { - buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); - } else if (_defaultSpriteSet) { - _defaultSpriteSet->saveAsText(buffer, indent + 2); - } - - for (uint32 i = 0; i < _nodes.size(); i++) { - _nodes[i]->saveAsText(buffer, indent + 2); - buffer->putTextIndent(indent, "\n"); - } - BaseClass::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkDef::loadDefaultSprite() { - if (_defaultSpriteFilename && !_defaultSprite) { - _defaultSprite = new BaseSprite(_gameRef); - if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { - delete _defaultSprite; - _defaultSprite = NULL; - return STATUS_FAILED; - } else { - return STATUS_OK; - } - } else if (_defaultSpriteSetFilename && !_defaultSpriteSet) { - _defaultSpriteSet = new AdSpriteSet(_gameRef); - if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { - delete _defaultSpriteSet; - _defaultSpriteSet = NULL; - return STATUS_FAILED; - } else { - return STATUS_OK; - } - } else { - return STATUS_OK; - } -} - - -////////////////////////////////////////////////////////////////////////// -BaseSprite *AdTalkDef::getDefaultSprite(TDirection dir) { - loadDefaultSprite(); - if (_defaultSprite) { - return _defaultSprite; - } else if (_defaultSpriteSet) { - return _defaultSpriteSet->getSprite(dir); - } else { - return NULL; - } -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_talk_def.h" +#include "engines/wintermute/ad/ad_talk_node.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/ad/ad_sprite_set.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/utils/utils.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdTalkDef, false) + +////////////////////////////////////////////////////////////////////////// +AdTalkDef::AdTalkDef(BaseGame *inGame) : BaseObject(inGame) { + _defaultSpriteFilename = NULL; + _defaultSprite = NULL; + + _defaultSpriteSetFilename = NULL; + _defaultSpriteSet = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdTalkDef::~AdTalkDef() { + for (uint32 i = 0; i < _nodes.size(); i++) { + delete _nodes[i]; + } + _nodes.clear(); + + delete[] _defaultSpriteFilename; + delete _defaultSprite; + _defaultSpriteFilename = NULL; + _defaultSprite = NULL; + + delete[] _defaultSpriteSetFilename; + delete _defaultSpriteSet; + _defaultSpriteSetFilename = NULL; + _defaultSpriteSet = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkDef::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdTalkDef::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); + } + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(TALK) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(ACTION) +TOKEN_DEF(DEFAULT_SPRITESET_FILE) +TOKEN_DEF(DEFAULT_SPRITESET) +TOKEN_DEF(DEFAULT_SPRITE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdTalkDef::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(TALK) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(ACTION) + TOKEN_TABLE(DEFAULT_SPRITESET_FILE) + TOKEN_TABLE(DEFAULT_SPRITESET) + TOKEN_TABLE(DEFAULT_SPRITE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_TALK) { + _gameRef->LOG(0, "'TALK' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_ACTION: { + AdTalkNode *node = new AdTalkNode(_gameRef); + if (node && DID_SUCCEED(node->loadBuffer(params, false))) { + _nodes.add(node); + } else { + delete node; + node = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + case TOKEN_DEFAULT_SPRITE: + BaseUtils::setString(&_defaultSpriteFilename, (char *)params); + break; + + case TOKEN_DEFAULT_SPRITESET_FILE: + BaseUtils::setString(&_defaultSpriteSetFilename, (char *)params); + break; + + case TOKEN_DEFAULT_SPRITESET: { + delete _defaultSpriteSet; + _defaultSpriteSet = new AdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadBuffer(params, false))) { + delete _defaultSpriteSet; + _defaultSpriteSet = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in TALK definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading TALK definition"); + return STATUS_FAILED; + } + + delete _defaultSprite; + delete _defaultSpriteSet; + _defaultSprite = NULL; + _defaultSpriteSet = NULL; + + if (_defaultSpriteFilename) { + _defaultSprite = new BaseSprite(_gameRef); + if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { + return STATUS_FAILED; + } + } + + if (_defaultSpriteSetFilename) { + _defaultSpriteSet = new AdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { + return STATUS_FAILED; + } + } + + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkDef::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_defaultSprite)); + persistMgr->transfer(TMEMBER(_defaultSpriteFilename)); + persistMgr->transfer(TMEMBER(_defaultSpriteSet)); + persistMgr->transfer(TMEMBER(_defaultSpriteSetFilename)); + + _nodes.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkDef::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "TALK {\n"); + if (_defaultSpriteFilename) { + buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); + } + + if (_defaultSpriteSetFilename) { + buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); + } else if (_defaultSpriteSet) { + _defaultSpriteSet->saveAsText(buffer, indent + 2); + } + + for (uint32 i = 0; i < _nodes.size(); i++) { + _nodes[i]->saveAsText(buffer, indent + 2); + buffer->putTextIndent(indent, "\n"); + } + BaseClass::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkDef::loadDefaultSprite() { + if (_defaultSpriteFilename && !_defaultSprite) { + _defaultSprite = new BaseSprite(_gameRef); + if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { + delete _defaultSprite; + _defaultSprite = NULL; + return STATUS_FAILED; + } else { + return STATUS_OK; + } + } else if (_defaultSpriteSetFilename && !_defaultSpriteSet) { + _defaultSpriteSet = new AdSpriteSet(_gameRef); + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { + delete _defaultSpriteSet; + _defaultSpriteSet = NULL; + return STATUS_FAILED; + } else { + return STATUS_OK; + } + } else { + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +BaseSprite *AdTalkDef::getDefaultSprite(TDirection dir) { + loadDefaultSprite(); + if (_defaultSprite) { + return _defaultSprite; + } else if (_defaultSpriteSet) { + return _defaultSpriteSet->getSprite(dir); + } else { + return NULL; + } +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_talk_def.h b/engines/wintermute/ad/ad_talk_def.h index f748aa4e7a..d147212775 100644 --- a/engines/wintermute/ad/ad_talk_def.h +++ b/engines/wintermute/ad/ad_talk_def.h @@ -1,58 +1,58 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADTALKDEF_H -#define WINTERMUTE_ADTALKDEF_H - -#include "engines/wintermute/coll_templ.h" -#include "engines/wintermute/base/base_object.h" - -namespace Wintermute { -class AdTalkNode; -class AdSpriteSet; -class AdTalkDef : public BaseObject { -public: - char *_defaultSpriteSetFilename; - AdSpriteSet *_defaultSpriteSet; - BaseSprite *getDefaultSprite(TDirection Dir); - bool loadDefaultSprite(); - DECLARE_PERSISTENT(AdTalkDef, BaseObject) - - AdTalkDef(BaseGame *inGame); - virtual ~AdTalkDef(); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - BaseArray _nodes; - char *_defaultSpriteFilename; - BaseSprite *_defaultSprite; - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKDEF_H +#define WINTERMUTE_ADTALKDEF_H + +#include "engines/wintermute/coll_templ.h" +#include "engines/wintermute/base/base_object.h" + +namespace Wintermute { +class AdTalkNode; +class AdSpriteSet; +class AdTalkDef : public BaseObject { +public: + char *_defaultSpriteSetFilename; + AdSpriteSet *_defaultSpriteSet; + BaseSprite *getDefaultSprite(TDirection Dir); + bool loadDefaultSprite(); + DECLARE_PERSISTENT(AdTalkDef, BaseObject) + + AdTalkDef(BaseGame *inGame); + virtual ~AdTalkDef(); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + BaseArray _nodes; + char *_defaultSpriteFilename; + BaseSprite *_defaultSprite; + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 89d7bd8a46..1e4ec26459 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -1,402 +1,402 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_talk_holder.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/scriptables/script.h" -#include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/base/base_engine.h" -#include "common/str.h" - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdTalkHolder, false) - -////////////////////////////////////////////////////////////////////////// -AdTalkHolder::AdTalkHolder(BaseGame *inGame) : AdObject(inGame) { - _sprite = NULL; -} - - -////////////////////////////////////////////////////////////////////////// -AdTalkHolder::~AdTalkHolder() { - delete _sprite; - _sprite = NULL; - - for (uint32 i = 0; i < _talkSprites.size(); i++) { - delete _talkSprites[i]; - } - _talkSprites.clear(); - - for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { - delete _talkSpritesEx[i]; - } - _talkSpritesEx.clear(); -} - -////////////////////////////////////////////////////////////////////////// -BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { - BaseSprite *ret = NULL; - - - // forced stance? - if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { - _forcedTalkAnimUsed = true; - delete _animSprite; - _animSprite = new BaseSprite(_gameRef, this); - if (_animSprite) { - bool res = _animSprite->loadFile(_forcedTalkAnimName); - if (DID_FAIL(res)) { - _gameRef->LOG(res, "AdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); - delete _animSprite; - _animSprite = NULL; - } else { - return _animSprite; - } - } - } - - - if (stance != NULL) { - // search special talk stances - for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { - ret = _talkSpritesEx[i]; - break; - } - } - if (ret == NULL) { - // serach generic talk stances - for (uint32 i = 0; i < _talkSprites.size(); i++) { - if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { - ret = _talkSprites[i]; - break; - } - } - } - } - - // not a valid stance? get a random one - if (ret == NULL) { - if (_talkSprites.size() < 1) { - ret = _sprite; - } else { - // TODO: remember last - int rnd = BaseEngine::instance().randInt(0, _talkSprites.size() - 1); - ret = _talkSprites[rnd]; - } - } - - return ret; -} - - -////////////////////////////////////////////////////////////////////////// -// high level scripting interface -////////////////////////////////////////////////////////////////////////// -bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { - ////////////////////////////////////////////////////////////////////////// - // SetSprite - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "SetSprite") == 0) { - stack->correctParams(1); - - ScValue *val = stack->pop(); - - bool setCurrent = false; - if (_currentSprite && _currentSprite == _sprite) { - setCurrent = true; - } - - delete _sprite; - _sprite = NULL; - - if (val->isNULL()) { - _sprite = NULL; - if (setCurrent) { - _currentSprite = NULL; - } - stack->pushBool(true); - } else { - const char *filename = val->getString(); - BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - script->runtimeError("SetSprite method failed for file '%s'", filename); - stack->pushBool(false); - } else { - _sprite = spr; - if (setCurrent) { - _currentSprite = _sprite; - } - stack->pushBool(true); - } - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetSprite") == 0) { - stack->correctParams(0); - - if (!_sprite || !_sprite->getFilename()) { - stack->pushNULL(); - } else { - stack->pushString(_sprite->getFilename()); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // GetSpriteObject - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "GetSpriteObject") == 0) { - stack->correctParams(0); - - if (!_sprite) { - stack->pushNULL(); - } else { - stack->pushNative(_sprite, true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // AddTalkSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AddTalkSprite") == 0) { - stack->correctParams(2); - - const char *filename = stack->pop()->getString(); - bool ex = stack->pop()->getBool(); - - BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("AddTalkSprite method failed for file '%s'", filename); - } else { - if (ex) { - _talkSpritesEx.add(spr); - } else { - _talkSprites.add(spr); - } - stack->pushBool(true); - } - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // RemoveTalkSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "RemoveTalkSprite") == 0) { - stack->correctParams(2); - - const char *filename = stack->pop()->getString(); - bool ex = stack->pop()->getBool(); - - bool setCurrent = false; - bool setTemp2 = false; - - if (ex) { - for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { - if (scumm_stricmp(_talkSpritesEx[i]->getFilename(), filename) == 0) { - if (_currentSprite == _talkSpritesEx[i]) { - setCurrent = true; - } - if (_tempSprite2 == _talkSpritesEx[i]) { - setTemp2 = true; - } - delete _talkSpritesEx[i]; - _talkSpritesEx.remove_at(i); - break; - } - } - } else { - for (uint32 i = 0; i < _talkSprites.size(); i++) { - if (scumm_stricmp(_talkSprites[i]->getFilename(), filename) == 0) { - if (_currentSprite == _talkSprites[i]) { - setCurrent = true; - } - if (_tempSprite2 == _talkSprites[i]) { - setTemp2 = true; - } - delete _talkSprites[i]; - _talkSprites.remove_at(i); - break; - } - } - - } - - stack->pushBool(true); - if (setCurrent) { - _currentSprite = _sprite; - } - if (setTemp2) { - _tempSprite2 = _sprite; - } - - return STATUS_OK; - } - - ////////////////////////////////////////////////////////////////////////// - // SetTalkSprite - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SetTalkSprite") == 0) { - stack->correctParams(2); - - const char *filename = stack->pop()->getString(); - bool ex = stack->pop()->getBool(); - bool setCurrent = false; - bool setTemp2 = false; - - BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile(filename))) { - stack->pushBool(false); - script->runtimeError("SetTalkSprite method failed for file '%s'", filename); - } else { - - // delete current - if (ex) { - for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { - if (_talkSpritesEx[i] == _currentSprite) { - setCurrent = true; - } - if (_talkSpritesEx[i] == _tempSprite2) { - setTemp2 = true; - } - delete _talkSpritesEx[i]; - } - _talkSpritesEx.clear(); - } else { - for (uint32 i = 0; i < _talkSprites.size(); i++) { - if (_talkSprites[i] == _currentSprite) { - setCurrent = true; - } - if (_talkSprites[i] == _tempSprite2) { - setTemp2 = true; - } - delete _talkSprites[i]; - } - _talkSprites.clear(); - } - - // set new - if (ex) { - _talkSpritesEx.add(spr); - } else { - _talkSprites.add(spr); - } - stack->pushBool(true); - - if (setCurrent) { - _currentSprite = spr; - } - if (setTemp2) { - _tempSprite2 = spr; - } - } - return STATUS_OK; - } else { - return AdObject::scCallMethod(script, stack, thisStack, name); - } -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdTalkHolder::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type (RO) - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("talk-holder"); - return _scValue; - } else { - return AdObject::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkHolder::scSetProperty(const char *name, ScValue *value) { - /* - ////////////////////////////////////////////////////////////////////////// - // Item - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Item")==0){ - SetItem(value->getString()); - return STATUS_OK; - } - - else*/ return AdObject::scSetProperty(name, value); -} - - -////////////////////////////////////////////////////////////////////////// -const char *AdTalkHolder::scToString() { - return "[talk-holder object]"; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkHolder::saveAsText(BaseDynamicBuffer *buffer, int indent) { - for (uint32 i = 0; i < _talkSprites.size(); i++) { - if (_talkSprites[i]->getFilename()) { - buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->getFilename()); - } - } - - for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { - if (_talkSpritesEx[i]->getFilename()) { - buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->getFilename()); - } - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkHolder::persist(BasePersistenceManager *persistMgr) { - AdObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_sprite)); - _talkSprites.persist(persistMgr); - _talkSpritesEx.persist(persistMgr); - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_talk_holder.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" +#include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/platform_osystem.h" +#include "engines/wintermute/base/base_engine.h" +#include "common/str.h" + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdTalkHolder, false) + +////////////////////////////////////////////////////////////////////////// +AdTalkHolder::AdTalkHolder(BaseGame *inGame) : AdObject(inGame) { + _sprite = NULL; +} + + +////////////////////////////////////////////////////////////////////////// +AdTalkHolder::~AdTalkHolder() { + delete _sprite; + _sprite = NULL; + + for (uint32 i = 0; i < _talkSprites.size(); i++) { + delete _talkSprites[i]; + } + _talkSprites.clear(); + + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { + delete _talkSpritesEx[i]; + } + _talkSpritesEx.clear(); +} + +////////////////////////////////////////////////////////////////////////// +BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { + BaseSprite *ret = NULL; + + + // forced stance? + if (_forcedTalkAnimName && !_forcedTalkAnimUsed) { + _forcedTalkAnimUsed = true; + delete _animSprite; + _animSprite = new BaseSprite(_gameRef, this); + if (_animSprite) { + bool res = _animSprite->loadFile(_forcedTalkAnimName); + if (DID_FAIL(res)) { + _gameRef->LOG(res, "AdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); + delete _animSprite; + _animSprite = NULL; + } else { + return _animSprite; + } + } + } + + + if (stance != NULL) { + // search special talk stances + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->getName(), stance) == 0) { + ret = _talkSpritesEx[i]; + break; + } + } + if (ret == NULL) { + // serach generic talk stances + for (uint32 i = 0; i < _talkSprites.size(); i++) { + if (scumm_stricmp(_talkSprites[i]->getName(), stance) == 0) { + ret = _talkSprites[i]; + break; + } + } + } + } + + // not a valid stance? get a random one + if (ret == NULL) { + if (_talkSprites.size() < 1) { + ret = _sprite; + } else { + // TODO: remember last + int rnd = BaseEngine::instance().randInt(0, _talkSprites.size() - 1); + ret = _talkSprites[rnd]; + } + } + + return ret; +} + + +////////////////////////////////////////////////////////////////////////// +// high level scripting interface +////////////////////////////////////////////////////////////////////////// +bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { + ////////////////////////////////////////////////////////////////////////// + // SetSprite + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "SetSprite") == 0) { + stack->correctParams(1); + + ScValue *val = stack->pop(); + + bool setCurrent = false; + if (_currentSprite && _currentSprite == _sprite) { + setCurrent = true; + } + + delete _sprite; + _sprite = NULL; + + if (val->isNULL()) { + _sprite = NULL; + if (setCurrent) { + _currentSprite = NULL; + } + stack->pushBool(true); + } else { + const char *filename = val->getString(); + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + script->runtimeError("SetSprite method failed for file '%s'", filename); + stack->pushBool(false); + } else { + _sprite = spr; + if (setCurrent) { + _currentSprite = _sprite; + } + stack->pushBool(true); + } + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetSprite") == 0) { + stack->correctParams(0); + + if (!_sprite || !_sprite->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_sprite->getFilename()); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // GetSpriteObject + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "GetSpriteObject") == 0) { + stack->correctParams(0); + + if (!_sprite) { + stack->pushNULL(); + } else { + stack->pushNative(_sprite, true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // AddTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "AddTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool ex = stack->pop()->getBool(); + + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("AddTalkSprite method failed for file '%s'", filename); + } else { + if (ex) { + _talkSpritesEx.add(spr); + } else { + _talkSprites.add(spr); + } + stack->pushBool(true); + } + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // RemoveTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "RemoveTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool ex = stack->pop()->getBool(); + + bool setCurrent = false; + bool setTemp2 = false; + + if (ex) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { + if (scumm_stricmp(_talkSpritesEx[i]->getFilename(), filename) == 0) { + if (_currentSprite == _talkSpritesEx[i]) { + setCurrent = true; + } + if (_tempSprite2 == _talkSpritesEx[i]) { + setTemp2 = true; + } + delete _talkSpritesEx[i]; + _talkSpritesEx.remove_at(i); + break; + } + } + } else { + for (uint32 i = 0; i < _talkSprites.size(); i++) { + if (scumm_stricmp(_talkSprites[i]->getFilename(), filename) == 0) { + if (_currentSprite == _talkSprites[i]) { + setCurrent = true; + } + if (_tempSprite2 == _talkSprites[i]) { + setTemp2 = true; + } + delete _talkSprites[i]; + _talkSprites.remove_at(i); + break; + } + } + + } + + stack->pushBool(true); + if (setCurrent) { + _currentSprite = _sprite; + } + if (setTemp2) { + _tempSprite2 = _sprite; + } + + return STATUS_OK; + } + + ////////////////////////////////////////////////////////////////////////// + // SetTalkSprite + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "SetTalkSprite") == 0) { + stack->correctParams(2); + + const char *filename = stack->pop()->getString(); + bool ex = stack->pop()->getBool(); + bool setCurrent = false; + bool setTemp2 = false; + + BaseSprite *spr = new BaseSprite(_gameRef, this); + if (!spr || DID_FAIL(spr->loadFile(filename))) { + stack->pushBool(false); + script->runtimeError("SetTalkSprite method failed for file '%s'", filename); + } else { + + // delete current + if (ex) { + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { + if (_talkSpritesEx[i] == _currentSprite) { + setCurrent = true; + } + if (_talkSpritesEx[i] == _tempSprite2) { + setTemp2 = true; + } + delete _talkSpritesEx[i]; + } + _talkSpritesEx.clear(); + } else { + for (uint32 i = 0; i < _talkSprites.size(); i++) { + if (_talkSprites[i] == _currentSprite) { + setCurrent = true; + } + if (_talkSprites[i] == _tempSprite2) { + setTemp2 = true; + } + delete _talkSprites[i]; + } + _talkSprites.clear(); + } + + // set new + if (ex) { + _talkSpritesEx.add(spr); + } else { + _talkSprites.add(spr); + } + stack->pushBool(true); + + if (setCurrent) { + _currentSprite = spr; + } + if (setTemp2) { + _tempSprite2 = spr; + } + } + return STATUS_OK; + } else { + return AdObject::scCallMethod(script, stack, thisStack, name); + } +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdTalkHolder::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type (RO) + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("talk-holder"); + return _scValue; + } else { + return AdObject::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkHolder::scSetProperty(const char *name, ScValue *value) { + /* + ////////////////////////////////////////////////////////////////////////// + // Item + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Item")==0){ + SetItem(value->getString()); + return STATUS_OK; + } + + else*/ return AdObject::scSetProperty(name, value); +} + + +////////////////////////////////////////////////////////////////////////// +const char *AdTalkHolder::scToString() { + return "[talk-holder object]"; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkHolder::saveAsText(BaseDynamicBuffer *buffer, int indent) { + for (uint32 i = 0; i < _talkSprites.size(); i++) { + if (_talkSprites[i]->getFilename()) { + buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->getFilename()); + } + } + + for (uint32 i = 0; i < _talkSpritesEx.size(); i++) { + if (_talkSpritesEx[i]->getFilename()) { + buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->getFilename()); + } + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkHolder::persist(BasePersistenceManager *persistMgr) { + AdObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_sprite)); + _talkSprites.persist(persistMgr); + _talkSpritesEx.persist(persistMgr); + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_talk_holder.h b/engines/wintermute/ad/ad_talk_holder.h index 906c469b32..ce10364b3d 100644 --- a/engines/wintermute/ad/ad_talk_holder.h +++ b/engines/wintermute/ad/ad_talk_holder.h @@ -1,57 +1,57 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADTALKHOLDER_H -#define WINTERMUTE_ADTALKHOLDER_H - -#include "engines/wintermute/ad/ad_object.h" - -namespace Wintermute { - -class AdTalkHolder : public AdObject { -public: - DECLARE_PERSISTENT(AdTalkHolder, AdObject) - virtual BaseSprite *getTalkStance(const char *stance); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - BaseSprite *_sprite; - BaseArray _talkSprites; - BaseArray _talkSpritesEx; - AdTalkHolder(BaseGame *inGame); - virtual ~AdTalkHolder(); - - // scripting interface - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); - virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); - virtual const char *scToString(); - -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKHOLDER_H +#define WINTERMUTE_ADTALKHOLDER_H + +#include "engines/wintermute/ad/ad_object.h" + +namespace Wintermute { + +class AdTalkHolder : public AdObject { +public: + DECLARE_PERSISTENT(AdTalkHolder, AdObject) + virtual BaseSprite *getTalkStance(const char *stance); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + BaseSprite *_sprite; + BaseArray _talkSprites; + BaseArray _talkSpritesEx; + AdTalkHolder(BaseGame *inGame); + virtual ~AdTalkHolder(); + + // scripting interface + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); + virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); + virtual const char *scToString(); + +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index 6d793f483c..b43a2b288e 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -1,295 +1,295 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_talk_node.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/ad/ad_sprite_set.h" -#include "engines/wintermute/utils/utils.h" -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdTalkNode, false) - -////////////////////////////////////////////////////////////////////////// -AdTalkNode::AdTalkNode(BaseGame *inGame) : BaseClass(inGame) { - _sprite = NULL; - _spriteFilename = NULL; - _spriteSet = NULL; - _spriteSetFilename = NULL; - _comment = NULL; - - _startTime = _endTime = 0; - _playToEnd = false; - _preCache = false; -} - - -////////////////////////////////////////////////////////////////////////// -AdTalkNode::~AdTalkNode() { - delete[] _spriteFilename; - delete _sprite; - delete[] _spriteSetFilename; - delete _spriteSet; - delete _comment; - _spriteFilename = NULL; - _sprite = NULL; - _spriteSetFilename = NULL; - _spriteSet = NULL; - _comment = NULL; -} - - - -TOKEN_DEF_START -TOKEN_DEF(ACTION) -TOKEN_DEF(SPRITESET_FILE) -TOKEN_DEF(SPRITESET) -TOKEN_DEF(SPRITE) -TOKEN_DEF(START_TIME) -TOKEN_DEF(END_TIME) -TOKEN_DEF(COMMENT) -TOKEN_DEF(PRECACHE) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(ACTION) - TOKEN_TABLE(SPRITESET_FILE) - TOKEN_TABLE(SPRITESET) - TOKEN_TABLE(SPRITE) - TOKEN_TABLE(START_TIME) - TOKEN_TABLE(END_TIME) - TOKEN_TABLE(COMMENT) - TOKEN_TABLE(PRECACHE) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTION) { - _gameRef->LOG(0, "'ACTION' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - _endTime = 0; - _playToEnd = false; - _preCache = false; - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_SPRITE: - BaseUtils::setString(&_spriteFilename, (char *)params); - break; - - case TOKEN_SPRITESET_FILE: - BaseUtils::setString(&_spriteSetFilename, (char *)params); - break; - - case TOKEN_SPRITESET: { - delete _spriteSet; - _spriteSet = new AdSpriteSet(_gameRef); - if (!_spriteSet || DID_FAIL(_spriteSet->loadBuffer(params, false))) { - delete _spriteSet; - _spriteSet = NULL; - cmd = PARSERR_GENERIC; - } - } - break; - - case TOKEN_START_TIME: - parser.scanStr((char *)params, "%d", &_startTime); - break; - - case TOKEN_END_TIME: - parser.scanStr((char *)params, "%d", &_endTime); - break; - - case TOKEN_PRECACHE: - parser.scanStr((char *)params, "%b", &_preCache); - break; - - case TOKEN_COMMENT: - if (_gameRef->_editorMode) { - BaseUtils::setString(&_comment, (char *)params); - } - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in ACTION definition"); - return STATUS_FAILED; - } - - if (cmd == PARSERR_GENERIC) { - _gameRef->LOG(0, "Error loading ACTION definition"); - return STATUS_FAILED; - } - - if (_endTime == 0) { - _playToEnd = true; - } else { - _playToEnd = false; - } - - if (_preCache && _spriteFilename) { - delete _sprite; - _sprite = new BaseSprite(_gameRef); - if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { - return STATUS_FAILED; - } - } - - if (_preCache && _spriteSetFilename) { - delete _spriteSet; - _spriteSet = new AdSpriteSet(_gameRef); - if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { - return STATUS_FAILED; - } - } - - return STATUS_OK; -} - - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkNode::persist(BasePersistenceManager *persistMgr) { - persistMgr->transfer(TMEMBER(_comment)); - persistMgr->transfer(TMEMBER(_startTime)); - persistMgr->transfer(TMEMBER(_endTime)); - persistMgr->transfer(TMEMBER(_playToEnd)); - persistMgr->transfer(TMEMBER(_sprite)); - persistMgr->transfer(TMEMBER(_spriteFilename)); - persistMgr->transfer(TMEMBER(_spriteSet)); - persistMgr->transfer(TMEMBER(_spriteSetFilename)); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkNode::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "ACTION {\n"); - if (_comment) { - buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); - } - buffer->putTextIndent(indent + 2, "START_TIME=%d\n", _startTime); - if (!_playToEnd) { - buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); - } - if (_spriteFilename) { - buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); - } - if (_spriteSetFilename) { - buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); - } else if (_spriteSet) { - _spriteSet->saveAsText(buffer, indent + 2); - } - if (_preCache) { - buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); - } - - BaseClass::saveAsText(buffer, indent + 2); - - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkNode::loadSprite() { - if (_spriteFilename && !_sprite) { - _sprite = new BaseSprite(_gameRef); - if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { - delete _sprite; - _sprite = NULL; - return STATUS_FAILED; - } else { - return STATUS_OK; - } - } else if (_spriteSetFilename && !_spriteSet) { - _spriteSet = new AdSpriteSet(_gameRef); - if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { - delete _spriteSet; - _spriteSet = NULL; - return STATUS_FAILED; - } else { - return STATUS_OK; - } - } else { - return STATUS_OK; - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { - if (time >= _startTime) { - if (_playToEnd) { - if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) { - return true; - } else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) { - return true; - } else { - return false; - } - } else { - return _endTime >= time; - } - } else { - return false; - } -} - - -////////////////////////////////////////////////////////////////////////// -BaseSprite *AdTalkNode::getSprite(TDirection dir) { - loadSprite(); - if (_sprite) { - return _sprite; - } else if (_spriteSet) { - return _spriteSet->getSprite(dir); - } else { - return NULL; - } -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_talk_node.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/ad/ad_sprite_set.h" +#include "engines/wintermute/utils/utils.h" +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdTalkNode, false) + +////////////////////////////////////////////////////////////////////////// +AdTalkNode::AdTalkNode(BaseGame *inGame) : BaseClass(inGame) { + _sprite = NULL; + _spriteFilename = NULL; + _spriteSet = NULL; + _spriteSetFilename = NULL; + _comment = NULL; + + _startTime = _endTime = 0; + _playToEnd = false; + _preCache = false; +} + + +////////////////////////////////////////////////////////////////////////// +AdTalkNode::~AdTalkNode() { + delete[] _spriteFilename; + delete _sprite; + delete[] _spriteSetFilename; + delete _spriteSet; + delete _comment; + _spriteFilename = NULL; + _sprite = NULL; + _spriteSetFilename = NULL; + _spriteSet = NULL; + _comment = NULL; +} + + + +TOKEN_DEF_START +TOKEN_DEF(ACTION) +TOKEN_DEF(SPRITESET_FILE) +TOKEN_DEF(SPRITESET) +TOKEN_DEF(SPRITE) +TOKEN_DEF(START_TIME) +TOKEN_DEF(END_TIME) +TOKEN_DEF(COMMENT) +TOKEN_DEF(PRECACHE) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(ACTION) + TOKEN_TABLE(SPRITESET_FILE) + TOKEN_TABLE(SPRITESET) + TOKEN_TABLE(SPRITE) + TOKEN_TABLE(START_TIME) + TOKEN_TABLE(END_TIME) + TOKEN_TABLE(COMMENT) + TOKEN_TABLE(PRECACHE) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_ACTION) { + _gameRef->LOG(0, "'ACTION' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + _endTime = 0; + _playToEnd = false; + _preCache = false; + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_SPRITE: + BaseUtils::setString(&_spriteFilename, (char *)params); + break; + + case TOKEN_SPRITESET_FILE: + BaseUtils::setString(&_spriteSetFilename, (char *)params); + break; + + case TOKEN_SPRITESET: { + delete _spriteSet; + _spriteSet = new AdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadBuffer(params, false))) { + delete _spriteSet; + _spriteSet = NULL; + cmd = PARSERR_GENERIC; + } + } + break; + + case TOKEN_START_TIME: + parser.scanStr((char *)params, "%d", &_startTime); + break; + + case TOKEN_END_TIME: + parser.scanStr((char *)params, "%d", &_endTime); + break; + + case TOKEN_PRECACHE: + parser.scanStr((char *)params, "%b", &_preCache); + break; + + case TOKEN_COMMENT: + if (_gameRef->_editorMode) { + BaseUtils::setString(&_comment, (char *)params); + } + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in ACTION definition"); + return STATUS_FAILED; + } + + if (cmd == PARSERR_GENERIC) { + _gameRef->LOG(0, "Error loading ACTION definition"); + return STATUS_FAILED; + } + + if (_endTime == 0) { + _playToEnd = true; + } else { + _playToEnd = false; + } + + if (_preCache && _spriteFilename) { + delete _sprite; + _sprite = new BaseSprite(_gameRef); + if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { + return STATUS_FAILED; + } + } + + if (_preCache && _spriteSetFilename) { + delete _spriteSet; + _spriteSet = new AdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { + return STATUS_FAILED; + } + } + + return STATUS_OK; +} + + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkNode::persist(BasePersistenceManager *persistMgr) { + persistMgr->transfer(TMEMBER(_comment)); + persistMgr->transfer(TMEMBER(_startTime)); + persistMgr->transfer(TMEMBER(_endTime)); + persistMgr->transfer(TMEMBER(_playToEnd)); + persistMgr->transfer(TMEMBER(_sprite)); + persistMgr->transfer(TMEMBER(_spriteFilename)); + persistMgr->transfer(TMEMBER(_spriteSet)); + persistMgr->transfer(TMEMBER(_spriteSetFilename)); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkNode::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "ACTION {\n"); + if (_comment) { + buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); + } + buffer->putTextIndent(indent + 2, "START_TIME=%d\n", _startTime); + if (!_playToEnd) { + buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); + } + if (_spriteFilename) { + buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); + } + if (_spriteSetFilename) { + buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); + } else if (_spriteSet) { + _spriteSet->saveAsText(buffer, indent + 2); + } + if (_preCache) { + buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); + } + + BaseClass::saveAsText(buffer, indent + 2); + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkNode::loadSprite() { + if (_spriteFilename && !_sprite) { + _sprite = new BaseSprite(_gameRef); + if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { + delete _sprite; + _sprite = NULL; + return STATUS_FAILED; + } else { + return STATUS_OK; + } + } else if (_spriteSetFilename && !_spriteSet) { + _spriteSet = new AdSpriteSet(_gameRef); + if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { + delete _spriteSet; + _spriteSet = NULL; + return STATUS_FAILED; + } else { + return STATUS_OK; + } + } else { + return STATUS_OK; + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { + if (time >= _startTime) { + if (_playToEnd) { + if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) { + return true; + } else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) { + return true; + } else { + return false; + } + } else { + return _endTime >= time; + } + } else { + return false; + } +} + + +////////////////////////////////////////////////////////////////////////// +BaseSprite *AdTalkNode::getSprite(TDirection dir) { + loadSprite(); + if (_sprite) { + return _sprite; + } else if (_spriteSet) { + return _spriteSet->getSprite(dir); + } else { + return NULL; + } +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_talk_node.h b/engines/wintermute/ad/ad_talk_node.h index 863f6d0a3b..7dfd861f85 100644 --- a/engines/wintermute/ad/ad_talk_node.h +++ b/engines/wintermute/ad/ad_talk_node.h @@ -1,63 +1,63 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADTALKNODE_H -#define WINTERMUTE_ADTALKNODE_H - -#include "engines/wintermute/persistent.h" -#include "engines/wintermute/base/base.h" - -namespace Wintermute { -class AdSpriteSet; -class BaseSprite; -class AdTalkNode : public BaseClass { -public: - char *_spriteSetFilename; - AdSpriteSet *_spriteSet; - BaseSprite *getSprite(TDirection dir); - bool isInTimeInterval(uint32 time, TDirection dir); - bool loadSprite(); - DECLARE_PERSISTENT(AdTalkNode, BaseClass) - - AdTalkNode(BaseGame *inGame); - virtual ~AdTalkNode(); - bool loadBuffer(byte *buffer, bool complete = true); - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); - char *_spriteFilename; - BaseSprite *_sprite; - uint32 _startTime; - uint32 _endTime; - bool _playToEnd; - bool _preCache; - char *_comment; - -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTALKNODE_H +#define WINTERMUTE_ADTALKNODE_H + +#include "engines/wintermute/persistent.h" +#include "engines/wintermute/base/base.h" + +namespace Wintermute { +class AdSpriteSet; +class BaseSprite; +class AdTalkNode : public BaseClass { +public: + char *_spriteSetFilename; + AdSpriteSet *_spriteSet; + BaseSprite *getSprite(TDirection dir); + bool isInTimeInterval(uint32 time, TDirection dir); + bool loadSprite(); + DECLARE_PERSISTENT(AdTalkNode, BaseClass) + + AdTalkNode(BaseGame *inGame); + virtual ~AdTalkNode(); + bool loadBuffer(byte *buffer, bool complete = true); + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent = 0); + char *_spriteFilename; + BaseSprite *_sprite; + uint32 _startTime; + uint32 _endTime; + bool _playToEnd; + bool _preCache; + char *_comment; + +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_types.h b/engines/wintermute/ad/ad_types.h index 8db20bfc02..ae5882f4ee 100644 --- a/engines/wintermute/ad/ad_types.h +++ b/engines/wintermute/ad/ad_types.h @@ -1,107 +1,107 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADTYPES_H -#define WINTERMUTE_ADTYPES_H - -namespace Wintermute { - -typedef enum { - GAME_NORMAL, - GAME_WAITING_RESPONSE -} TGameStateEx; - -typedef enum { - OBJECT_ENTITY, - OBJECT_REGION, - OBJECT_ACTOR, - OBJECT_NONE -} TObjectType; - -typedef enum { - ENTITY_NORMAL, - ENTITY_SOUND -} TEntityType; - -typedef enum { - STATE_NONE, - STATE_IDLE, - STATE_PLAYING_ANIM, - STATE_READY, - STATE_FOLLOWING_PATH, - STATE_SEARCHING_PATH, - STATE_WAITING_PATH, - STATE_TURNING_LEFT, - STATE_TURNING_RIGHT, - STATE_TURNING, - STATE_TALKING, - STATE_DIRECT_CONTROL, - STATE_PLAYING_ANIM_SET -} TObjectState; - -typedef enum { - DIRECT_WALK_NONE, - DIRECT_WALK_FW, - DIRECT_WALK_BK -} TDirectWalkMode; - -typedef enum { - DIRECT_TURN_NONE, - DIRECT_TURN_CW, - DIRECT_TURN_CCW -} TDirectTurnMode; - -typedef enum { - RESPONSE_TEXT, - RESPONSE_ICON -} TResponseStyle; - -typedef enum { - RESPONSE_ALWAYS, - RESPONSE_ONCE, - RESPONSE_ONCE_GAME -} TResponseType; - - -typedef enum { - TALK_SKIP_LEFT = 0, - TALK_SKIP_RIGHT = 1, - TALK_SKIP_BOTH = 2, - TALK_SKIP_NONE = 3 -} TTalkSkipButton; - -typedef enum { - GEOM_WAYPOINT, - GEOM_WALKPLANE, - GEOM_BLOCKED, - GEOM_GENERIC -} TGeomNodeType; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADTYPES_H +#define WINTERMUTE_ADTYPES_H + +namespace Wintermute { + +typedef enum { + GAME_NORMAL, + GAME_WAITING_RESPONSE +} TGameStateEx; + +typedef enum { + OBJECT_ENTITY, + OBJECT_REGION, + OBJECT_ACTOR, + OBJECT_NONE +} TObjectType; + +typedef enum { + ENTITY_NORMAL, + ENTITY_SOUND +} TEntityType; + +typedef enum { + STATE_NONE, + STATE_IDLE, + STATE_PLAYING_ANIM, + STATE_READY, + STATE_FOLLOWING_PATH, + STATE_SEARCHING_PATH, + STATE_WAITING_PATH, + STATE_TURNING_LEFT, + STATE_TURNING_RIGHT, + STATE_TURNING, + STATE_TALKING, + STATE_DIRECT_CONTROL, + STATE_PLAYING_ANIM_SET +} TObjectState; + +typedef enum { + DIRECT_WALK_NONE, + DIRECT_WALK_FW, + DIRECT_WALK_BK +} TDirectWalkMode; + +typedef enum { + DIRECT_TURN_NONE, + DIRECT_TURN_CW, + DIRECT_TURN_CCW +} TDirectTurnMode; + +typedef enum { + RESPONSE_TEXT, + RESPONSE_ICON +} TResponseStyle; + +typedef enum { + RESPONSE_ALWAYS, + RESPONSE_ONCE, + RESPONSE_ONCE_GAME +} TResponseType; + + +typedef enum { + TALK_SKIP_LEFT = 0, + TALK_SKIP_RIGHT = 1, + TALK_SKIP_BOTH = 2, + TALK_SKIP_NONE = 3 +} TTalkSkipButton; + +typedef enum { + GEOM_WAYPOINT, + GEOM_WALKPLANE, + GEOM_BLOCKED, + GEOM_GENERIC +} TGeomNodeType; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 8da62c9115..984ed75aeb 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -1,270 +1,270 @@ -/* 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. - - * 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. - - * 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 - */ - -#include "engines/wintermute/ad/ad_waypoint_group.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_region.h" -#include "engines/wintermute/base/base_file_manager.h" -#include - -namespace Wintermute { - -IMPLEMENT_PERSISTENT(AdWaypointGroup, false) - -////////////////////////////////////////////////////////////////////////// -AdWaypointGroup::AdWaypointGroup(BaseGame *inGame) : BaseObject(inGame) { - _active = true; - _editorSelectedPoint = -1; - _lastMimicScale = -1; - _lastMimicX = _lastMimicY = INT_MIN; -} - - -////////////////////////////////////////////////////////////////////////// -AdWaypointGroup::~AdWaypointGroup() { - cleanup(); -} - - -////////////////////////////////////////////////////////////////////////// -void AdWaypointGroup::cleanup() { - for (uint32 i = 0; i < _points.size(); i++) { - delete _points[i]; - } - _points.clear(); - _editorSelectedPoint = -1; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdWaypointGroup::loadFile(const char *filename) { - byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); - if (buffer == NULL) { - _gameRef->LOG(0, "AdWaypointGroup::LoadFile failed for file '%s'", filename); - return STATUS_FAILED; - } - - bool ret; - - setFilename(filename); - - if (DID_FAIL(ret = loadBuffer(buffer, true))) { - _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); - } - - - delete[] buffer; - - return ret; -} - - -TOKEN_DEF_START -TOKEN_DEF(WAYPOINTS) -TOKEN_DEF(TEMPLATE) -TOKEN_DEF(NAME) -TOKEN_DEF(POINT) -TOKEN_DEF(EDITOR_SELECTED_POINT) -TOKEN_DEF(EDITOR_SELECTED) -TOKEN_DEF(PROPERTY) -TOKEN_DEF(EDITOR_PROPERTY) -TOKEN_DEF_END -////////////////////////////////////////////////////////////////////////// -bool AdWaypointGroup::loadBuffer(byte *buffer, bool complete) { - TOKEN_TABLE_START(commands) - TOKEN_TABLE(WAYPOINTS) - TOKEN_TABLE(TEMPLATE) - TOKEN_TABLE(NAME) - TOKEN_TABLE(POINT) - TOKEN_TABLE(EDITOR_SELECTED_POINT) - TOKEN_TABLE(EDITOR_SELECTED) - TOKEN_TABLE(PROPERTY) - TOKEN_TABLE(EDITOR_PROPERTY) - TOKEN_TABLE_END - - byte *params; - int cmd; - BaseParser parser; - - if (complete) { - if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_WAYPOINTS) { - _gameRef->LOG(0, "'WAYPOINTS' keyword expected."); - return STATUS_FAILED; - } - buffer = params; - } - - while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { - switch (cmd) { - case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) { - cmd = PARSERR_GENERIC; - } - break; - - case TOKEN_NAME: - setName((char *)params); - break; - - case TOKEN_POINT: { - int x, y; - parser.scanStr((char *)params, "%d,%d", &x, &y); - _points.add(new BasePoint(x, y)); - } - break; - - case TOKEN_EDITOR_SELECTED: - parser.scanStr((char *)params, "%b", &_editorSelected); - break; - - case TOKEN_EDITOR_SELECTED_POINT: - parser.scanStr((char *)params, "%d", &_editorSelectedPoint); - break; - - case TOKEN_PROPERTY: - parseProperty(params, false); - break; - - case TOKEN_EDITOR_PROPERTY: - parseEditorProperty(params, false); - break; - } - } - if (cmd == PARSERR_TOKENNOTFOUND) { - _gameRef->LOG(0, "Syntax error in WAYPOINTS definition"); - return STATUS_FAILED; - } - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdWaypointGroup::saveAsText(BaseDynamicBuffer *buffer, int indent) { - buffer->putTextIndent(indent, "WAYPOINTS {\n"); - buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - buffer->putTextIndent(indent + 2, "EDITOR_SELECTED_POINT=%d\n", _editorSelectedPoint); - - if (_scProp) { - _scProp->saveAsText(buffer, indent + 2); - } - BaseClass::saveAsText(buffer, indent + 2); - - for (uint32 i = 0; i < _points.size(); i++) { - buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); - } - - buffer->putTextIndent(indent, "}\n"); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -bool AdWaypointGroup::persist(BasePersistenceManager *persistMgr) { - - BaseObject::persist(persistMgr); - - persistMgr->transfer(TMEMBER(_active)); - persistMgr->transfer(TMEMBER(_editorSelectedPoint)); - persistMgr->transfer(TMEMBER(_lastMimicScale)); - persistMgr->transfer(TMEMBER(_lastMimicX)); - persistMgr->transfer(TMEMBER(_lastMimicY)); - _points.persist(persistMgr); - - return STATUS_OK; -} - - -////////////////////////////////////////////////////////////////////////// -ScValue *AdWaypointGroup::scGetProperty(const char *name) { - _scValue->setNULL(); - - ////////////////////////////////////////////////////////////////////////// - // Type - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { - _scValue->setString("waypoint-group"); - return _scValue; - } - - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { - _scValue->setBool(_active); - return _scValue; - } else { - return BaseObject::scGetProperty(name); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdWaypointGroup::scSetProperty(const char *name, ScValue *value) { - ////////////////////////////////////////////////////////////////////////// - // Active - ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Active") == 0) { - _active = value->getBool(); - return STATUS_OK; - } - - else { - return BaseObject::scSetProperty(name, value); - } -} - - -////////////////////////////////////////////////////////////////////////// -bool AdWaypointGroup::mimic(AdWaypointGroup *wpt, float scale, int argX, int argY) { - if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) { - return STATUS_OK; - } - - cleanup(); - - for (uint32 i = 0; i < wpt->_points.size(); i++) { - int x = (int)((float)wpt->_points[i]->x * scale / 100.0f); - int y = (int)((float)wpt->_points[i]->y * scale / 100.0f); - - _points.add(new BasePoint(x + argX, y + argY)); - } - - _lastMimicScale = scale; - _lastMimicX = argX; - _lastMimicY = argY; - - return STATUS_OK; -} - -} // end of namespace Wintermute +/* 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. + + * 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. + + * 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 + */ + +#include "engines/wintermute/ad/ad_waypoint_group.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/base_file_manager.h" +#include + +namespace Wintermute { + +IMPLEMENT_PERSISTENT(AdWaypointGroup, false) + +////////////////////////////////////////////////////////////////////////// +AdWaypointGroup::AdWaypointGroup(BaseGame *inGame) : BaseObject(inGame) { + _active = true; + _editorSelectedPoint = -1; + _lastMimicScale = -1; + _lastMimicX = _lastMimicY = INT_MIN; +} + + +////////////////////////////////////////////////////////////////////////// +AdWaypointGroup::~AdWaypointGroup() { + cleanup(); +} + + +////////////////////////////////////////////////////////////////////////// +void AdWaypointGroup::cleanup() { + for (uint32 i = 0; i < _points.size(); i++) { + delete _points[i]; + } + _points.clear(); + _editorSelectedPoint = -1; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdWaypointGroup::loadFile(const char *filename) { + byte *buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename); + if (buffer == NULL) { + _gameRef->LOG(0, "AdWaypointGroup::LoadFile failed for file '%s'", filename); + return STATUS_FAILED; + } + + bool ret; + + setFilename(filename); + + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); + } + + + delete[] buffer; + + return ret; +} + + +TOKEN_DEF_START +TOKEN_DEF(WAYPOINTS) +TOKEN_DEF(TEMPLATE) +TOKEN_DEF(NAME) +TOKEN_DEF(POINT) +TOKEN_DEF(EDITOR_SELECTED_POINT) +TOKEN_DEF(EDITOR_SELECTED) +TOKEN_DEF(PROPERTY) +TOKEN_DEF(EDITOR_PROPERTY) +TOKEN_DEF_END +////////////////////////////////////////////////////////////////////////// +bool AdWaypointGroup::loadBuffer(byte *buffer, bool complete) { + TOKEN_TABLE_START(commands) + TOKEN_TABLE(WAYPOINTS) + TOKEN_TABLE(TEMPLATE) + TOKEN_TABLE(NAME) + TOKEN_TABLE(POINT) + TOKEN_TABLE(EDITOR_SELECTED_POINT) + TOKEN_TABLE(EDITOR_SELECTED) + TOKEN_TABLE(PROPERTY) + TOKEN_TABLE(EDITOR_PROPERTY) + TOKEN_TABLE_END + + byte *params; + int cmd; + BaseParser parser; + + if (complete) { + if (parser.getCommand((char **)&buffer, commands, (char **)¶ms) != TOKEN_WAYPOINTS) { + _gameRef->LOG(0, "'WAYPOINTS' keyword expected."); + return STATUS_FAILED; + } + buffer = params; + } + + while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { + switch (cmd) { + case TOKEN_TEMPLATE: + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } + break; + + case TOKEN_NAME: + setName((char *)params); + break; + + case TOKEN_POINT: { + int x, y; + parser.scanStr((char *)params, "%d,%d", &x, &y); + _points.add(new BasePoint(x, y)); + } + break; + + case TOKEN_EDITOR_SELECTED: + parser.scanStr((char *)params, "%b", &_editorSelected); + break; + + case TOKEN_EDITOR_SELECTED_POINT: + parser.scanStr((char *)params, "%d", &_editorSelectedPoint); + break; + + case TOKEN_PROPERTY: + parseProperty(params, false); + break; + + case TOKEN_EDITOR_PROPERTY: + parseEditorProperty(params, false); + break; + } + } + if (cmd == PARSERR_TOKENNOTFOUND) { + _gameRef->LOG(0, "Syntax error in WAYPOINTS definition"); + return STATUS_FAILED; + } + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdWaypointGroup::saveAsText(BaseDynamicBuffer *buffer, int indent) { + buffer->putTextIndent(indent, "WAYPOINTS {\n"); + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + buffer->putTextIndent(indent + 2, "EDITOR_SELECTED_POINT=%d\n", _editorSelectedPoint); + + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } + BaseClass::saveAsText(buffer, indent + 2); + + for (uint32 i = 0; i < _points.size(); i++) { + buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); + } + + buffer->putTextIndent(indent, "}\n"); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +bool AdWaypointGroup::persist(BasePersistenceManager *persistMgr) { + + BaseObject::persist(persistMgr); + + persistMgr->transfer(TMEMBER(_active)); + persistMgr->transfer(TMEMBER(_editorSelectedPoint)); + persistMgr->transfer(TMEMBER(_lastMimicScale)); + persistMgr->transfer(TMEMBER(_lastMimicX)); + persistMgr->transfer(TMEMBER(_lastMimicY)); + _points.persist(persistMgr); + + return STATUS_OK; +} + + +////////////////////////////////////////////////////////////////////////// +ScValue *AdWaypointGroup::scGetProperty(const char *name) { + _scValue->setNULL(); + + ////////////////////////////////////////////////////////////////////////// + // Type + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Type") == 0) { + _scValue->setString("waypoint-group"); + return _scValue; + } + + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + else if (strcmp(name, "Active") == 0) { + _scValue->setBool(_active); + return _scValue; + } else { + return BaseObject::scGetProperty(name); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdWaypointGroup::scSetProperty(const char *name, ScValue *value) { + ////////////////////////////////////////////////////////////////////////// + // Active + ////////////////////////////////////////////////////////////////////////// + if (strcmp(name, "Active") == 0) { + _active = value->getBool(); + return STATUS_OK; + } + + else { + return BaseObject::scSetProperty(name, value); + } +} + + +////////////////////////////////////////////////////////////////////////// +bool AdWaypointGroup::mimic(AdWaypointGroup *wpt, float scale, int argX, int argY) { + if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) { + return STATUS_OK; + } + + cleanup(); + + for (uint32 i = 0; i < wpt->_points.size(); i++) { + int x = (int)((float)wpt->_points[i]->x * scale / 100.0f); + int y = (int)((float)wpt->_points[i]->y * scale / 100.0f); + + _points.add(new BasePoint(x + argX, y + argY)); + } + + _lastMimicScale = scale; + _lastMimicX = argX; + _lastMimicY = argY; + + return STATUS_OK; +} + +} // end of namespace Wintermute diff --git a/engines/wintermute/ad/ad_waypoint_group.h b/engines/wintermute/ad/ad_waypoint_group.h index a83c942652..5cf6da1d1a 100644 --- a/engines/wintermute/ad/ad_waypoint_group.h +++ b/engines/wintermute/ad/ad_waypoint_group.h @@ -1,58 +1,58 @@ -/* 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. - - * 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. - - * 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 - */ - -#ifndef WINTERMUTE_ADWAYPOINTGROUP_H -#define WINTERMUTE_ADWAYPOINTGROUP_H - -#include "engines/wintermute/base/base_object.h" - -namespace Wintermute { -class BasePoint; -class AdWaypointGroup : public BaseObject { -public: - float _lastMimicScale; - int _lastMimicX; - int _lastMimicY; - void cleanup(); - bool mimic(AdWaypointGroup *wpt, float scale = 100.0f, int x = 0, int y = 0); - DECLARE_PERSISTENT(AdWaypointGroup, BaseObject) - virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); - bool _active; - AdWaypointGroup(BaseGame *inGame); - bool loadFile(const char *filename); - bool loadBuffer(byte *buffer, bool complete = true); - virtual ~AdWaypointGroup(); - BaseArray _points; - int _editorSelectedPoint; - virtual ScValue *scGetProperty(const char *name); - virtual bool scSetProperty(const char *name, ScValue *value); -}; - -} // end of namespace Wintermute - -#endif +/* 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. + + * 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. + + * 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 + */ + +#ifndef WINTERMUTE_ADWAYPOINTGROUP_H +#define WINTERMUTE_ADWAYPOINTGROUP_H + +#include "engines/wintermute/base/base_object.h" + +namespace Wintermute { +class BasePoint; +class AdWaypointGroup : public BaseObject { +public: + float _lastMimicScale; + int _lastMimicX; + int _lastMimicY; + void cleanup(); + bool mimic(AdWaypointGroup *wpt, float scale = 100.0f, int x = 0, int y = 0); + DECLARE_PERSISTENT(AdWaypointGroup, BaseObject) + virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); + bool _active; + AdWaypointGroup(BaseGame *inGame); + bool loadFile(const char *filename); + bool loadBuffer(byte *buffer, bool complete = true); + virtual ~AdWaypointGroup(); + BaseArray _points; + int _editorSelectedPoint; + virtual ScValue *scGetProperty(const char *name); + virtual bool scSetProperty(const char *name, ScValue *value); +}; + +} // end of namespace Wintermute + +#endif -- cgit v1.2.3 From 2a6e55169530b46985d6d6af6ebcbb12e7c5a603 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Tue, 11 Sep 2012 02:51:33 +0200 Subject: WINTERMUTE: Only include base_renderer.h where needed --- engines/wintermute/ad/ad_entity.cpp | 1 + engines/wintermute/ad/ad_game.cpp | 1 + engines/wintermute/ad/ad_inventory_box.cpp | 1 + engines/wintermute/ad/ad_object.cpp | 1 + engines/wintermute/ad/ad_response_box.cpp | 1 + engines/wintermute/ad/ad_scene.cpp | 1 + engines/wintermute/ad/ad_sentence.cpp | 1 + 7 files changed, 7 insertions(+) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 234af1fffa..ad1d25fb8a 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -45,6 +45,7 @@ #include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index fe8a5991e2..ec6c5dca31 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -50,6 +50,7 @@ #include "engines/wintermute/base/base_viewport.h" #include "engines/wintermute/base/particles/part_emitter.h" #include "engines/wintermute/base/saveload.h" +#include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/scriptables/script_engine.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index 16b8e01ff3..7ae8ff8d69 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -35,6 +35,7 @@ #include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/base/base_viewport.h" #include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/ui/ui_button.h" #include "engines/wintermute/ui/ui_window.h" #include "engines/wintermute/platform_osystem.h" diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index 6c77917979..7364d0488e 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -42,6 +42,7 @@ #include "engines/wintermute/base/base_sub_frame.h" #include "engines/wintermute/base/font/base_font.h" #include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_string_table.h" #include "engines/wintermute/base/scriptables/script_engine.h" diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index a27f1ca54b..c89b4ed225 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -36,6 +36,7 @@ #include "engines/wintermute/base/font/base_font_storage.h" #include "engines/wintermute/base/font/base_font.h" #include "engines/wintermute/ad/ad_response.h" +#include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" #include "engines/wintermute/base/base_sprite.h" diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index e47acc63c9..8c4bff02ac 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -52,6 +52,7 @@ #include "engines/wintermute/base/base_scriptable.h" #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_viewport.h" +#include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/scriptables/script_stack.h" #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script.h" diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index 1f09d3ae0f..cb88fcd3eb 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -35,6 +35,7 @@ #include "engines/wintermute/base/sound/base_sound.h" #include "engines/wintermute/ad/ad_scene.h" #include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_file_manager.h" -- cgit v1.2.3 From ef021656b8a73165711c3cf02bf24f72ce32645c Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Tue, 11 Sep 2012 03:03:17 +0200 Subject: WINTERMUTE: Alphabetize the includes in Ad/ --- engines/wintermute/ad/ad_entity.cpp | 24 ++++++++++++------------ engines/wintermute/ad/ad_item.cpp | 4 ++-- engines/wintermute/ad/ad_layer.cpp | 4 ++-- engines/wintermute/ad/ad_object.cpp | 10 +++++----- engines/wintermute/ad/ad_region.cpp | 6 +++--- engines/wintermute/ad/ad_response.cpp | 2 +- engines/wintermute/ad/ad_response_box.cpp | 12 ++++++------ engines/wintermute/ad/ad_rot_level.cpp | 4 ++-- engines/wintermute/ad/ad_scale_level.cpp | 4 ++-- engines/wintermute/ad/ad_scene_state.cpp | 2 +- engines/wintermute/ad/ad_sentence.cpp | 10 +++++----- engines/wintermute/ad/ad_sprite_set.cpp | 2 +- engines/wintermute/ad/ad_talk_def.cpp | 2 +- engines/wintermute/ad/ad_talk_holder.cpp | 6 +++--- engines/wintermute/ad/ad_talk_node.cpp | 2 +- engines/wintermute/ad/ad_waypoint_group.cpp | 6 +++--- 16 files changed, 50 insertions(+), 50 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index ad1d25fb8a..00dbc0f3c2 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -28,29 +28,29 @@ #include "engines/wintermute/ad/ad_entity.h" -#include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_active_rect.h" -#include "engines/wintermute/base/base_surface_storage.h" -#include "engines/wintermute/base/base_game.h" #include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/ad/ad_scene.h" -#include "engines/wintermute/base/sound/base_sound.h" #include "engines/wintermute/ad/ad_waypoint_group.h" -#include "engines/wintermute/base/font/base_font_storage.h" -#include "engines/wintermute/base/font/base_font.h" #include "engines/wintermute/ad/ad_sentence.h" +#include "engines/wintermute/base/base_active_rect.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_region.h" #include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_file_manager.h" -#include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/base/font/base_font_storage.h" +#include "engines/wintermute/base/font/base_font.h" #include "engines/wintermute/base/gfx/base_renderer.h" +#include "engines/wintermute/base/particles/part_emitter.h" #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/base/sound/base_sound.h" #include "engines/wintermute/video/video_theora_player.h" -#include "engines/wintermute/base/particles/part_emitter.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index afd813933b..bad7223788 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -36,11 +36,11 @@ #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/sound/base_sound.h" #include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/utils/utils.h" -#include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" #include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/utils/utils.h" +#include "engines/wintermute/platform_osystem.h" #include "common/str.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 46b75b8b21..bc64b21208 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -29,12 +29,12 @@ #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/ad/ad_layer.h" #include "engines/wintermute/ad/ad_scene_node.h" -#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/platform_osystem.h" #include "common/str.h" diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index 7364d0488e..013ce498e0 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -37,19 +37,19 @@ #include "engines/wintermute/ad/ad_waypoint_group.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_frame.h" -#include "engines/wintermute/base/sound/base_sound.h" -#include "engines/wintermute/base/base_surface_storage.h" +#include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/base_string_table.h" #include "engines/wintermute/base/base_sub_frame.h" +#include "engines/wintermute/base/base_surface_storage.h" #include "engines/wintermute/base/font/base_font.h" #include "engines/wintermute/base/font/base_font_storage.h" #include "engines/wintermute/base/gfx/base_renderer.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_string_table.h" +#include "engines/wintermute/base/particles/part_emitter.h" #include "engines/wintermute/base/scriptables/script_engine.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" #include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/particles/part_emitter.h" +#include "engines/wintermute/base/sound/base_sound.h" #include "common/str.h" #include "common/util.h" diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 88bd8201a2..2b90b479bf 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -27,12 +27,12 @@ */ #include "engines/wintermute/ad/ad_region.h" -#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/scriptables/script_value.h" -#include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/scriptables/script_value.h" +#include "engines/wintermute/base/scriptables/script.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp index 37f46118bf..a2225f2632 100644 --- a/engines/wintermute/ad/ad_response.cpp +++ b/engines/wintermute/ad/ad_response.cpp @@ -28,8 +28,8 @@ #include "engines/wintermute/ad/ad_response.h" #include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/font/base_font_storage.h" #include "engines/wintermute/base/base_sprite.h" +#include "engines/wintermute/base/font/base_font_storage.h" #include "engines/wintermute/utils/utils.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index c89b4ed225..fb31aa0bb8 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -27,20 +27,20 @@ */ #include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_response.h" #include "engines/wintermute/ad/ad_response_box.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_surface_storage.h" -#include "engines/wintermute/ui/ui_button.h" -#include "engines/wintermute/ui/ui_window.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" #include "engines/wintermute/base/font/base_font_storage.h" #include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/ad/ad_response.h" #include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/ui/ui_button.h" +#include "engines/wintermute/ui/ui_window.h" #include "engines/wintermute/utils/utils.h" #include "engines/wintermute/platform_osystem.h" #include "engines/wintermute/wintermute.h" diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index ca7ed693ad..fb9a4a47b9 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -27,11 +27,11 @@ */ #include "engines/wintermute/ad/ad_rot_level.h" -#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/base/base_file_manager.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index 8b68cc5d32..4e9293d875 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -28,9 +28,9 @@ #include "engines/wintermute/ad/ad_scale_level.h" #include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_dynamic_buffer.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index c09e6a259c..6b34f1af53 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -26,9 +26,9 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/persistent.h" #include "engines/wintermute/ad/ad_scene_state.h" #include "engines/wintermute/ad/ad_node_state.h" +#include "engines/wintermute/persistent.h" #include "engines/wintermute/platform_osystem.h" #include "common/str.h" diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index cb88fcd3eb..cfe4191b07 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -26,18 +26,18 @@ * Copyright (c) 2011 Jan Nedoma */ +#include "engines/wintermute/ad/ad_game.h" +#include "engines/wintermute/ad/ad_scene.h" #include "engines/wintermute/ad/ad_sentence.h" #include "engines/wintermute/ad/ad_talk_def.h" #include "engines/wintermute/ad/ad_talk_node.h" -#include "engines/wintermute/ad/ad_game.h" #include "engines/wintermute/utils/path_util.h" #include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/sound/base_sound.h" -#include "engines/wintermute/ad/ad_scene.h" -#include "engines/wintermute/base/font/base_font.h" -#include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/font/base_font.h" +#include "engines/wintermute/base/gfx/base_renderer.h" +#include "engines/wintermute/base/sound/base_sound.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index c8cdec03c3..345b483a8f 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -27,10 +27,10 @@ */ #include "engines/wintermute/ad/ad_sprite_set.h" -#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_sprite.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 8cb489509b..a85cd7f986 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -26,13 +26,13 @@ * Copyright (c) 2011 Jan Nedoma */ +#include "engines/wintermute/ad/ad_sprite_set.h" #include "engines/wintermute/ad/ad_talk_def.h" #include "engines/wintermute/ad/ad_talk_node.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_dynamic_buffer.h" #include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/ad/ad_sprite_set.h" #include "engines/wintermute/base/base_file_manager.h" #include "engines/wintermute/utils/utils.h" diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 1e4ec26459..1422d8683c 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -28,13 +28,13 @@ #include "engines/wintermute/ad/ad_talk_holder.h" #include "engines/wintermute/base/base_dynamic_buffer.h" +#include "engines/wintermute/base/base_engine.h" +#include "engines/wintermute/base/base_game.h" +#include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script.h" #include "engines/wintermute/base/scriptables/script_stack.h" -#include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_sprite.h" #include "engines/wintermute/platform_osystem.h" -#include "engines/wintermute/base/base_engine.h" #include "common/str.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index b43a2b288e..b1bcf685f2 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -26,12 +26,12 @@ * Copyright (c) 2011 Jan Nedoma */ +#include "engines/wintermute/ad/ad_sprite_set.h" #include "engines/wintermute/ad/ad_talk_node.h" #include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" #include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_sprite.h" -#include "engines/wintermute/ad/ad_sprite_set.h" #include "engines/wintermute/utils/utils.h" namespace Wintermute { diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 984ed75aeb..f80fa7e45d 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -27,12 +27,12 @@ */ #include "engines/wintermute/ad/ad_waypoint_group.h" -#include "engines/wintermute/base/base_parser.h" #include "engines/wintermute/base/base_dynamic_buffer.h" -#include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/base_game.h" -#include "engines/wintermute/base/base_region.h" #include "engines/wintermute/base/base_file_manager.h" +#include "engines/wintermute/base/base_parser.h" +#include "engines/wintermute/base/base_region.h" +#include "engines/wintermute/base/scriptables/script_value.h" #include namespace Wintermute { -- cgit v1.2.3 From f437e1df32c1edfb1bf6a9770d4a2e2a38172e64 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Mon, 24 Sep 2012 00:11:49 +0200 Subject: WINTERMUTE: Remove unnecessary semicolons. --- engines/wintermute/ad/ad_actor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index 9087d66844..074d5afdbb 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -830,7 +830,7 @@ void AdActor::followPath() { // are there points to follow? if (_path->getCurrent() != NULL) { - _state = STATE_FOLLOWING_PATH;; + _state = STATE_FOLLOWING_PATH; initLine(BasePoint(_posX, _posY), *_path->getCurrent()); } else { if (_afterWalkDir != DI_NONE) { @@ -1351,7 +1351,7 @@ bool AdActor::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// TDirection AdActor::angleToDirection(int angle) { - TDirection ret = DI_DOWN;; + TDirection ret = DI_DOWN; if (angle > -112 && angle <= -67) { ret = DI_UP; -- cgit v1.2.3 From b31d6212ffc35b987cfb7ee35a5ae3f75bf34a60 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 28 Sep 2012 23:42:16 +0200 Subject: WINTERMUTE: Privatize variables in BaseFrame and BaseSprite --- engines/wintermute/ad/ad_actor.cpp | 14 +++++++------- engines/wintermute/ad/ad_entity.cpp | 6 +++--- engines/wintermute/ad/ad_item.cpp | 4 ++-- engines/wintermute/ad/ad_talk_node.cpp | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index 074d5afdbb..fa06bb12e8 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -602,13 +602,13 @@ bool AdActor::update() { } // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->isFinished()) { _state = _nextState; _nextState = STATE_READY; _currentSprite = _animSprite; } - if (_state == STATE_PLAYING_ANIM_SET && _animSprite2 != NULL && _animSprite2->_finished) { + if (_state == STATE_PLAYING_ANIM_SET && _animSprite2 != NULL && _animSprite2->isFinished()) { _state = _nextState; _nextState = STATE_READY; _currentSprite = _animSprite2; @@ -649,7 +649,7 @@ bool AdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_TURNING_LEFT: - if (_tempSprite2 == NULL || _tempSprite2->_finished) { + if (_tempSprite2 == NULL || _tempSprite2->isFinished()) { if (_dir > 0) { _dir = (TDirection)(_dir - 1); } else { @@ -686,7 +686,7 @@ bool AdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_TURNING_RIGHT: - if (_tempSprite2 == NULL || _tempSprite2->_finished) { + if (_tempSprite2 == NULL || _tempSprite2->isFinished()) { _dir = (TDirection)(_dir + 1); if ((int)_dir >= (int)NUM_DIRECTIONS) { @@ -753,7 +753,7 @@ bool AdActor::update() { } bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (_tempSprite2 == NULL || _tempSprite2->isFinished() || (/*_tempSprite2->_looping &&*/ timeIsUp)) { if (timeIsUp) { _sentence->finish(); _tempSprite2 = NULL; @@ -798,7 +798,7 @@ bool AdActor::update() { if (_currentSprite && !already_moved) { _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (_currentSprite->_changed) { + if (_currentSprite->isChanged()) { _posX += _currentSprite->_moveX; _posY += _currentSprite->_moveY; afterMove(); @@ -858,7 +858,7 @@ void AdActor::getNextStep() { } _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (!_currentSprite->_changed) { + if (!_currentSprite->isChanged()) { return; } diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 00dbc0f3c2..f97284ae1d 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -578,7 +578,7 @@ bool AdEntity::update() { } // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->isFinished()) { _state = STATE_READY; _currentSprite = _animSprite; } @@ -613,7 +613,7 @@ bool AdEntity::update() { } bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (_tempSprite2 == NULL || _tempSprite2->isFinished() || (/*_tempSprite2->_looping &&*/ timeIsUp)) { if (timeIsUp) { _sentence->finish(); _tempSprite2 = NULL; @@ -639,7 +639,7 @@ bool AdEntity::update() { if (_currentSprite) { _currentSprite->getCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (_currentSprite->_changed) { + if (_currentSprite->isChanged()) { _posX += _currentSprite->_moveX; _posY += _currentSprite->_moveY; } diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index bad7223788..55ccca8d0a 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -340,7 +340,7 @@ bool AdItem::update() { } // finished playing animation? - if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) { + if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->isFinished()) { _state = STATE_READY; _currentSprite = _animSprite; } @@ -379,7 +379,7 @@ bool AdItem::update() { } bool timeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); - if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ timeIsUp)) { + if (_tempSprite2 == NULL || _tempSprite2->isFinished() || (/*_tempSprite2->_looping &&*/ timeIsUp)) { if (timeIsUp) { _sentence->finish(); _tempSprite2 = NULL; diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index b1bcf685f2..c909ee27ff 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -264,9 +264,9 @@ bool AdTalkNode::loadSprite() { bool AdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { if (time >= _startTime) { if (_playToEnd) { - if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) { + if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->isFinished() == false)) { return true; - } else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) { + } else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->isFinished() == false)) { return true; } else { return false; -- cgit v1.2.3 From afc21941e37a7481f5fe050d220968bdce43c873 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sat, 29 Sep 2012 00:47:12 +0200 Subject: WINTERMUTE: Make scGetProperty use Common::String& instead of const char* --- engines/wintermute/ad/ad_actor.cpp | 16 ++++++------ engines/wintermute/ad/ad_actor.h | 2 +- engines/wintermute/ad/ad_entity.cpp | 16 ++++++------ engines/wintermute/ad/ad_entity.h | 2 +- engines/wintermute/ad/ad_game.cpp | 36 +++++++++++++-------------- engines/wintermute/ad/ad_game.h | 2 +- engines/wintermute/ad/ad_item.cpp | 20 +++++++-------- engines/wintermute/ad/ad_item.h | 2 +- engines/wintermute/ad/ad_layer.cpp | 16 ++++++------ engines/wintermute/ad/ad_layer.h | 2 +- engines/wintermute/ad/ad_object.cpp | 26 ++++++++++---------- engines/wintermute/ad/ad_object.h | 2 +- engines/wintermute/ad/ad_region.cpp | 14 +++++------ engines/wintermute/ad/ad_region.h | 2 +- engines/wintermute/ad/ad_scene.cpp | 38 ++++++++++++++--------------- engines/wintermute/ad/ad_scene.h | 2 +- engines/wintermute/ad/ad_talk_holder.cpp | 4 +-- engines/wintermute/ad/ad_talk_holder.h | 2 +- engines/wintermute/ad/ad_waypoint_group.cpp | 6 ++--- engines/wintermute/ad/ad_waypoint_group.h | 2 +- 20 files changed, 106 insertions(+), 106 deletions(-) (limited to 'engines/wintermute/ad') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index fa06bb12e8..d175855d1e 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -1075,27 +1075,27 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// -ScValue *AdActor::scGetProperty(const char *name) { +ScValue *AdActor::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Direction ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Direction") == 0) { + if (name == "Direction") { _scValue->setInt(_dir); return _scValue; } ////////////////////////////////////////////////////////////////////////// // Type ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Type") == 0) { + else if (name == "Type") { _scValue->setString("actor"); return _scValue; } ////////////////////////////////////////////////////////////////////////// // TalkAnimName ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkAnimName") == 0) { + else if (name == "TalkAnimName") { _scValue->setString(_talkAnimName); return _scValue; } @@ -1103,7 +1103,7 @@ ScValue *AdActor::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // WalkAnimName ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkAnimName") == 0) { + else if (name == "WalkAnimName") { _scValue->setString(_walkAnimName); return _scValue; } @@ -1111,7 +1111,7 @@ ScValue *AdActor::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // IdleAnimName ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IdleAnimName") == 0) { + else if (name == "IdleAnimName") { _scValue->setString(_idleAnimName); return _scValue; } @@ -1119,7 +1119,7 @@ ScValue *AdActor::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // TurnLeftAnimName ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnLeftAnimName") == 0) { + else if (name == "TurnLeftAnimName") { _scValue->setString(_turnLeftAnimName); return _scValue; } @@ -1127,7 +1127,7 @@ ScValue *AdActor::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // TurnRightAnimName ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TurnRightAnimName") == 0) { + else if (name == "TurnRightAnimName") { _scValue->setString(_turnRightAnimName); return _scValue; } else { diff --git a/engines/wintermute/ad/ad_actor.h b/engines/wintermute/ad/ad_actor.h index 271e57cb85..543c9d063a 100644 --- a/engines/wintermute/ad/ad_actor.h +++ b/engines/wintermute/ad/ad_actor.h @@ -83,7 +83,7 @@ private: AdSpriteSet *getAnimByName(const Common::String &animName); // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index f97284ae1d..9af7e034ca 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -829,13 +829,13 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// -ScValue *AdEntity::scGetProperty(const char *name) { +ScValue *AdEntity::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type (RO) ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("entity"); return _scValue; } @@ -843,7 +843,7 @@ ScValue *AdEntity::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Item ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Item") == 0) { + else if (name == "Item") { if (_item) { _scValue->setString(_item); } else { @@ -856,7 +856,7 @@ ScValue *AdEntity::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Subtype (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Subtype") == 0) { + else if (name == "Subtype") { if (_subtype == ENTITY_SOUND) { _scValue->setString("sound"); } else { @@ -869,7 +869,7 @@ ScValue *AdEntity::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // WalkToX ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToX") == 0) { + else if (name == "WalkToX") { _scValue->setInt(_walkToX); return _scValue; } @@ -877,7 +877,7 @@ ScValue *AdEntity::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // WalkToY ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToY") == 0) { + else if (name == "WalkToY") { _scValue->setInt(_walkToY); return _scValue; } @@ -885,7 +885,7 @@ ScValue *AdEntity::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // WalkToDirection ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "WalkToDirection") == 0) { + else if (name == "WalkToDirection") { _scValue->setInt((int)_walkToDir); return _scValue; } @@ -893,7 +893,7 @@ ScValue *AdEntity::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Region (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Region") == 0) { + else if (name == "Region") { if (_region) { _scValue->setNative(_region, true); } else { diff --git a/engines/wintermute/ad/ad_entity.h b/engines/wintermute/ad/ad_entity.h index 39dc133eef..415987e50a 100644 --- a/engines/wintermute/ad/ad_entity.h +++ b/engines/wintermute/ad/ad_entity.h @@ -56,7 +56,7 @@ public: TEntityType _subtype; // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index ec6c5dca31..4481b774c1 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -876,20 +876,20 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// -ScValue *AdGame::scGetProperty(const char *name) { +ScValue *AdGame::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("game"); return _scValue; } ////////////////////////////////////////////////////////////////////////// // Scene ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Scene") == 0) { + else if (name == "Scene") { if (_scene) { _scValue->setNative(_scene, true); } else { @@ -901,7 +901,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // SelectedItem ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SelectedItem") == 0) { + else if (name == "SelectedItem") { //if (_selectedItem) _scValue->setString(_selectedItem->_name); if (_selectedItem) { _scValue->setNative(_selectedItem, true); @@ -914,14 +914,14 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // NumItems ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumItems") == 0) { + else if (name == "NumItems") { return _invObject->scGetProperty(name); } ////////////////////////////////////////////////////////////////////////// // SmartItemCursor ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SmartItemCursor") == 0) { + else if (name == "SmartItemCursor") { _scValue->setBool(_smartItemCursor); return _scValue; } @@ -929,7 +929,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // InventoryVisible ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryVisible") == 0) { + else if (name == "InventoryVisible") { _scValue->setBool(_inventoryBox && _inventoryBox->_visible); return _scValue; } @@ -937,7 +937,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // InventoryScrollOffset ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryScrollOffset") == 0) { + else if (name == "InventoryScrollOffset") { if (_inventoryBox) { _scValue->setInt(_inventoryBox->_scrollOffset); } else { @@ -950,7 +950,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // ResponsesVisible (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ResponsesVisible") == 0) { + else if (name == "ResponsesVisible") { _scValue->setBool(_stateEx == GAME_WAITING_RESPONSE); return _scValue; } @@ -958,7 +958,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // PrevScene / PreviousScene (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PrevScene") == 0 || strcmp(name, "PreviousScene") == 0) { + else if (name == "PrevScene" || name == "PreviousScene") { if (!_prevSceneName) { _scValue->setString(""); } else { @@ -970,7 +970,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // PrevSceneFilename / PreviousSceneFilename (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PrevSceneFilename") == 0 || strcmp(name, "PreviousSceneFilename") == 0) { + else if (name == "PrevSceneFilename" || name == "PreviousSceneFilename") { if (!_prevSceneFilename) { _scValue->setString(""); } else { @@ -982,7 +982,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // LastResponse (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LastResponse") == 0) { + else if (name == "LastResponse") { if (!_responseBox || !_responseBox->_lastResponseText) { _scValue->setString(""); } else { @@ -994,7 +994,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // LastResponseOrig (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "LastResponseOrig") == 0) { + else if (name == "LastResponseOrig") { if (!_responseBox || !_responseBox->_lastResponseTextOrig) { _scValue->setString(""); } else { @@ -1006,7 +1006,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // InventoryObject ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "InventoryObject") == 0) { + else if (name == "InventoryObject") { if (_inventoryOwner == _invObject) { _scValue->setNative(this, true); } else { @@ -1019,7 +1019,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // TotalNumItems ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TotalNumItems") == 0) { + else if (name == "TotalNumItems") { _scValue->setInt(_items.size()); return _scValue; } @@ -1027,7 +1027,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // TalkSkipButton ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "TalkSkipButton") == 0) { + else if (name == "TalkSkipButton") { _scValue->setInt(_talkSkipButton); return _scValue; } @@ -1035,7 +1035,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // ChangingScene ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ChangingScene") == 0) { + else if (name == "ChangingScene") { _scValue->setBool(_scheduledScene != NULL); return _scValue; } @@ -1043,7 +1043,7 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // StartupScene ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "StartupScene") == 0) { + else if (name == "StartupScene") { if (!_startupScene) { _scValue->setNULL(); } else { diff --git a/engines/wintermute/ad/ad_game.h b/engines/wintermute/ad/ad_game.h index 46427331bf..81c79a3da8 100644 --- a/engines/wintermute/ad/ad_game.h +++ b/engines/wintermute/ad/ad_game.h @@ -126,7 +126,7 @@ public: bool loadItemsBuffer(byte *buffer, bool merge = false); // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); bool validMouse(); diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index 55ccca8d0a..427b1c7db4 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -614,13 +614,13 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// -ScValue *AdItem::scGetProperty(const char *name) { +ScValue *AdItem::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("item"); return _scValue; } @@ -628,7 +628,7 @@ ScValue *AdItem::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Name ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Name") == 0) { + else if (name == "Name") { _scValue->setString(getName()); return _scValue; } @@ -636,7 +636,7 @@ ScValue *AdItem::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // DisplayAmount ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "DisplayAmount") == 0) { + else if (name == "DisplayAmount") { _scValue->setBool(_displayAmount); return _scValue; } @@ -644,7 +644,7 @@ ScValue *AdItem::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Amount ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Amount") == 0) { + else if (name == "Amount") { _scValue->setInt(_amount); return _scValue; } @@ -652,7 +652,7 @@ ScValue *AdItem::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // AmountOffsetX ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetX") == 0) { + else if (name == "AmountOffsetX") { _scValue->setInt(_amountOffsetX); return _scValue; } @@ -660,7 +660,7 @@ ScValue *AdItem::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // AmountOffsetY ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountOffsetY") == 0) { + else if (name == "AmountOffsetY") { _scValue->setInt(_amountOffsetY); return _scValue; } @@ -668,7 +668,7 @@ ScValue *AdItem::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // AmountAlign ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountAlign") == 0) { + else if (name == "AmountAlign") { _scValue->setInt(_amountAlign); return _scValue; } @@ -676,7 +676,7 @@ ScValue *AdItem::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // AmountString ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AmountString") == 0) { + else if (name == "AmountString") { if (!_amountString) { _scValue->setNULL(); } else { @@ -688,7 +688,7 @@ ScValue *AdItem::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // CursorCombined ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CursorCombined") == 0) { + else if (name == "CursorCombined") { _scValue->setBool(_cursorCombined); return _scValue; } else { diff --git a/engines/wintermute/ad/ad_item.h b/engines/wintermute/ad/ad_item.h index 6047c542c1..79978f9f72 100644 --- a/engines/wintermute/ad/ad_item.h +++ b/engines/wintermute/ad/ad_item.h @@ -51,7 +51,7 @@ public: bool loadBuffer(byte *buffer, bool complete = true); // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index bc64b21208..209c12b7a2 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -376,13 +376,13 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// -ScValue *AdLayer::scGetProperty(const char *name) { +ScValue *AdLayer::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("layer"); return _scValue; } @@ -390,7 +390,7 @@ ScValue *AdLayer::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // NumNodes (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumNodes") == 0) { + else if (name == "NumNodes") { _scValue->setInt(_nodes.size()); return _scValue; } @@ -398,7 +398,7 @@ ScValue *AdLayer::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Width ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Width") == 0) { + else if (name == "Width") { _scValue->setInt(_width); return _scValue; } @@ -406,7 +406,7 @@ ScValue *AdLayer::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Height ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Height") == 0) { + else if (name == "Height") { _scValue->setInt(_height); return _scValue; } @@ -414,7 +414,7 @@ ScValue *AdLayer::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Main (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Main") == 0) { + else if (name == "Main") { _scValue->setBool(_main); return _scValue; } @@ -422,7 +422,7 @@ ScValue *AdLayer::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // CloseUp ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "CloseUp") == 0) { + else if (name == "CloseUp") { _scValue->setBool(_closeUp); return _scValue; } @@ -430,7 +430,7 @@ ScValue *AdLayer::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Active ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { + else if (name == "Active") { _scValue->setBool(_active); return _scValue; } else { diff --git a/engines/wintermute/ad/ad_layer.h b/engines/wintermute/ad/ad_layer.h index bb5f73b13a..de65e2822f 100644 --- a/engines/wintermute/ad/ad_layer.h +++ b/engines/wintermute/ad/ad_layer.h @@ -47,7 +47,7 @@ public: virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index 013ce498e0..7b91daab2e 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -659,13 +659,13 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// -ScValue *AdObject::scGetProperty(const char *name) { +ScValue *AdObject::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("object"); return _scValue; } @@ -673,7 +673,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Active ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { + else if (name == "Active") { _scValue->setBool(_active); return _scValue; } @@ -681,7 +681,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // IgnoreItems ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "IgnoreItems") == 0) { + else if (name == "IgnoreItems") { _scValue->setBool(_ignoreItems); return _scValue; } @@ -689,7 +689,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // SceneIndependent ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SceneIndependent") == 0) { + else if (name == "SceneIndependent") { _scValue->setBool(_sceneIndependent); return _scValue; } @@ -697,7 +697,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // SubtitlesWidth ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesWidth") == 0) { + else if (name == "SubtitlesWidth") { _scValue->setInt(_subtitlesWidth); return _scValue; } @@ -705,7 +705,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // SubtitlesPosRelative ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosRelative") == 0) { + else if (name == "SubtitlesPosRelative") { _scValue->setBool(_subtitlesModRelative); return _scValue; } @@ -713,7 +713,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // SubtitlesPosX ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosX") == 0) { + else if (name == "SubtitlesPosX") { _scValue->setInt(_subtitlesModX); return _scValue; } @@ -721,7 +721,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // SubtitlesPosY ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosY") == 0) { + else if (name == "SubtitlesPosY") { _scValue->setInt(_subtitlesModY); return _scValue; } @@ -729,7 +729,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // SubtitlesPosXCenter ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "SubtitlesPosXCenter") == 0) { + else if (name == "SubtitlesPosXCenter") { _scValue->setBool(_subtitlesModXCenter); return _scValue; } @@ -737,7 +737,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // NumItems (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumItems") == 0) { + else if (name == "NumItems") { _scValue->setInt(getInventory()->_takenItems.size()); return _scValue; } @@ -745,7 +745,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // ParticleEmitter (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ParticleEmitter") == 0) { + else if (name == "ParticleEmitter") { if (_partEmitter) { _scValue->setNative(_partEmitter, true); } else { @@ -758,7 +758,7 @@ ScValue *AdObject::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // NumAttachments (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumAttachments") == 0) { + else if (name == "NumAttachments") { _scValue->setInt(_attachmentsPre.size() + _attachmentsPost.size()); return _scValue; } else { diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h index 8395f58cff..d1a20908e1 100644 --- a/engines/wintermute/ad/ad_object.h +++ b/engines/wintermute/ad/ad_object.h @@ -100,7 +100,7 @@ public: AdRegion *_currentRegions[MAX_NUM_REGIONS]; // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index 2b90b479bf..c9f1553c9a 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -242,13 +242,13 @@ bool AdRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// -ScValue *AdRegion::scGetProperty(const char *name) { +ScValue *AdRegion::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("ad region"); return _scValue; } @@ -256,7 +256,7 @@ ScValue *AdRegion::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Name ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Name") == 0) { + else if (name == "Name") { _scValue->setString(getName()); return _scValue; } @@ -264,7 +264,7 @@ ScValue *AdRegion::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Blocked ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Blocked") == 0) { + else if (name == "Blocked") { _scValue->setBool(_blocked); return _scValue; } @@ -272,7 +272,7 @@ ScValue *AdRegion::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Decoration ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Decoration") == 0) { + else if (name == "Decoration") { _scValue->setBool(_decoration); return _scValue; } @@ -280,7 +280,7 @@ ScValue *AdRegion::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Scale ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Scale") == 0) { + else if (name == "Scale") { _scValue->setFloat(_zoom); return _scValue; } @@ -288,7 +288,7 @@ ScValue *AdRegion::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // AlphaColor ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AlphaColor") == 0) { + else if (name == "AlphaColor") { _scValue->setInt((int)_alpha); return _scValue; } else { diff --git a/engines/wintermute/ad/ad_region.h b/engines/wintermute/ad/ad_region.h index a60cb9a3f2..6112900361 100644 --- a/engines/wintermute/ad/ad_region.h +++ b/engines/wintermute/ad/ad_region.h @@ -47,7 +47,7 @@ public: virtual bool saveAsText(BaseDynamicBuffer *buffer, int indent); // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 8c4bff02ac..8e9beca0c0 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -1809,13 +1809,13 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// -ScValue *AdScene::scGetProperty(const char *name) { +ScValue *AdScene::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("scene"); return _scValue; } @@ -1823,7 +1823,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // NumLayers (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumLayers") == 0) { + else if (name == "NumLayers") { _scValue->setInt(_layers.size()); return _scValue; } @@ -1831,7 +1831,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // NumWaypointGroups (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumWaypointGroups") == 0) { + else if (name == "NumWaypointGroups") { _scValue->setInt(_waypointGroups.size()); return _scValue; } @@ -1839,7 +1839,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // MainLayer (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MainLayer") == 0) { + else if (name == "MainLayer") { if (_mainLayer) { _scValue->setNative(_mainLayer, true); } else { @@ -1852,7 +1852,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // NumFreeNodes (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "NumFreeNodes") == 0) { + else if (name == "NumFreeNodes") { _scValue->setInt(_objects.size()); return _scValue; } @@ -1860,7 +1860,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // MouseX (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MouseX") == 0) { + else if (name == "MouseX") { int viewportX; getViewportOffset(&viewportX); @@ -1871,7 +1871,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // MouseY (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "MouseY") == 0) { + else if (name == "MouseY") { int viewportY; getViewportOffset(NULL, &viewportY); @@ -1882,7 +1882,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // AutoScroll ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "AutoScroll") == 0) { + else if (name == "AutoScroll") { _scValue->setBool(_autoScroll); return _scValue; } @@ -1890,7 +1890,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // PersistentState ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentState") == 0) { + else if (name == "PersistentState") { _scValue->setBool(_persistentState); return _scValue; } @@ -1898,7 +1898,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // PersistentStateSprites ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "PersistentStateSprites") == 0) { + else if (name == "PersistentStateSprites") { _scValue->setBool(_persistentStateSprites); return _scValue; } @@ -1906,7 +1906,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // ScrollPixelsX ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsX") == 0) { + else if (name == "ScrollPixelsX") { _scValue->setInt(_scrollPixelsH); return _scValue; } @@ -1914,7 +1914,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // ScrollPixelsY ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollPixelsY") == 0) { + else if (name == "ScrollPixelsY") { _scValue->setInt(_scrollPixelsV); return _scValue; } @@ -1923,7 +1923,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // ScrollSpeedX ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedX") == 0) { + else if (name == "ScrollSpeedX") { _scValue->setInt(_scrollTimeH); return _scValue; } @@ -1931,7 +1931,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // ScrollSpeedY ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "ScrollSpeedY") == 0) { + else if (name == "ScrollSpeedY") { _scValue->setInt(_scrollTimeV); return _scValue; } @@ -1939,7 +1939,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // OffsetX ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetX") == 0) { + else if (name == "OffsetX") { _scValue->setInt(_offsetLeft); return _scValue; } @@ -1947,7 +1947,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // OffsetY ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "OffsetY") == 0) { + else if (name == "OffsetY") { _scValue->setInt(_offsetTop); return _scValue; } @@ -1955,7 +1955,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Width (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Width") == 0) { + else if (name == "Width") { if (_mainLayer) { _scValue->setInt(_mainLayer->_width); } else { @@ -1967,7 +1967,7 @@ ScValue *AdScene::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Height (RO) ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Height") == 0) { + else if (name == "Height") { if (_mainLayer) { _scValue->setInt(_mainLayer->_height); } else { diff --git a/engines/wintermute/ad/ad_scene.h b/engines/wintermute/ad/ad_scene.h index c9c0e413bf..3b482403b5 100644 --- a/engines/wintermute/ad/ad_scene.h +++ b/engines/wintermute/ad/ad_scene.h @@ -156,7 +156,7 @@ public: int getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester = NULL); // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 1422d8683c..cca4fdc2cb 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -334,13 +334,13 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS ////////////////////////////////////////////////////////////////////////// -ScValue *AdTalkHolder::scGetProperty(const char *name) { +ScValue *AdTalkHolder::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type (RO) ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("talk-holder"); return _scValue; } else { diff --git a/engines/wintermute/ad/ad_talk_holder.h b/engines/wintermute/ad/ad_talk_holder.h index ce10364b3d..d52ebf63c0 100644 --- a/engines/wintermute/ad/ad_talk_holder.h +++ b/engines/wintermute/ad/ad_talk_holder.h @@ -45,7 +45,7 @@ public: virtual ~AdTalkHolder(); // scripting interface - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); virtual bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name); virtual const char *scToString(); diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index f80fa7e45d..81493ce769 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -206,13 +206,13 @@ bool AdWaypointGroup::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// -ScValue *AdWaypointGroup::scGetProperty(const char *name) { +ScValue *AdWaypointGroup::scGetProperty(const Common::String &name) { _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// // Type ////////////////////////////////////////////////////////////////////////// - if (strcmp(name, "Type") == 0) { + if (name == "Type") { _scValue->setString("waypoint-group"); return _scValue; } @@ -220,7 +220,7 @@ ScValue *AdWaypointGroup::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// // Active ////////////////////////////////////////////////////////////////////////// - else if (strcmp(name, "Active") == 0) { + else if (name == "Active") { _scValue->setBool(_active); return _scValue; } else { diff --git a/engines/wintermute/ad/ad_waypoint_group.h b/engines/wintermute/ad/ad_waypoint_group.h index 5cf6da1d1a..13d6bbadd7 100644 --- a/engines/wintermute/ad/ad_waypoint_group.h +++ b/engines/wintermute/ad/ad_waypoint_group.h @@ -49,7 +49,7 @@ public: virtual ~AdWaypointGroup(); BaseArray _points; int _editorSelectedPoint; - virtual ScValue *scGetProperty(const char *name); + virtual ScValue *scGetProperty(const Common::String &name); virtual bool scSetProperty(const char *name, ScValue *value); }; -- cgit v1.2.3