[Scummvm-cvs-logs] scummvm master -> 6e14e9767062a35a39dc216d92e3cbf0ece69902

wjp wjp at usecode.org
Tue Sep 4 22:26:23 CEST 2012


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b4090ead4d WINTERMUTE: Convert CRLF to LF
6e14e97670 BADA: Convert CRLF to LF


Commit: b4090ead4d4334e08725323ff72fd355c93b63d5
    https://github.com/scummvm/scummvm/commit/b4090ead4d4334e08725323ff72fd355c93b63d5
Author: Willem Jan Palenstijn (wjp at usecode.org)
Date: 2012-09-04T13:17:23-07:00

Commit Message:
WINTERMUTE: Convert CRLF to LF

Changed paths:
    engines/wintermute/ad/ad_actor.cpp
    engines/wintermute/ad/ad_actor.h
    engines/wintermute/ad/ad_entity.cpp
    engines/wintermute/ad/ad_entity.h
    engines/wintermute/ad/ad_game.cpp
    engines/wintermute/ad/ad_game.h
    engines/wintermute/ad/ad_inventory.cpp
    engines/wintermute/ad/ad_inventory.h
    engines/wintermute/ad/ad_inventory_box.cpp
    engines/wintermute/ad/ad_inventory_box.h
    engines/wintermute/ad/ad_item.cpp
    engines/wintermute/ad/ad_item.h
    engines/wintermute/ad/ad_layer.cpp
    engines/wintermute/ad/ad_layer.h
    engines/wintermute/ad/ad_node_state.cpp
    engines/wintermute/ad/ad_node_state.h
    engines/wintermute/ad/ad_object.cpp
    engines/wintermute/ad/ad_object.h
    engines/wintermute/ad/ad_path.cpp
    engines/wintermute/ad/ad_path.h
    engines/wintermute/ad/ad_path_point.cpp
    engines/wintermute/ad/ad_path_point.h
    engines/wintermute/ad/ad_region.cpp
    engines/wintermute/ad/ad_region.h
    engines/wintermute/ad/ad_response.cpp
    engines/wintermute/ad/ad_response.h
    engines/wintermute/ad/ad_response_box.cpp
    engines/wintermute/ad/ad_response_box.h
    engines/wintermute/ad/ad_response_context.cpp
    engines/wintermute/ad/ad_response_context.h
    engines/wintermute/ad/ad_rot_level.cpp
    engines/wintermute/ad/ad_rot_level.h
    engines/wintermute/ad/ad_scale_level.cpp
    engines/wintermute/ad/ad_scale_level.h
    engines/wintermute/ad/ad_scene.cpp
    engines/wintermute/ad/ad_scene.h
    engines/wintermute/ad/ad_scene_node.cpp
    engines/wintermute/ad/ad_scene_node.h
    engines/wintermute/ad/ad_scene_state.cpp
    engines/wintermute/ad/ad_scene_state.h
    engines/wintermute/ad/ad_sentence.cpp
    engines/wintermute/ad/ad_sentence.h
    engines/wintermute/ad/ad_sprite_set.cpp
    engines/wintermute/ad/ad_sprite_set.h
    engines/wintermute/ad/ad_talk_def.cpp
    engines/wintermute/ad/ad_talk_def.h
    engines/wintermute/ad/ad_talk_holder.cpp
    engines/wintermute/ad/ad_talk_holder.h
    engines/wintermute/ad/ad_talk_node.cpp
    engines/wintermute/ad/ad_talk_node.h
    engines/wintermute/ad/ad_types.h
    engines/wintermute/ad/ad_waypoint_group.cpp
    engines/wintermute/ad/ad_waypoint_group.h
    engines/wintermute/base/base.cpp
    engines/wintermute/base/base.h
    engines/wintermute/base/base_active_rect.cpp
    engines/wintermute/base/base_active_rect.h
    engines/wintermute/base/base_dynamic_buffer.cpp
    engines/wintermute/base/base_dynamic_buffer.h
    engines/wintermute/base/base_fader.cpp
    engines/wintermute/base/base_fader.h
    engines/wintermute/base/base_file_manager.cpp
    engines/wintermute/base/base_file_manager.h
    engines/wintermute/base/base_frame.cpp
    engines/wintermute/base/base_frame.h
    engines/wintermute/base/base_game.cpp
    engines/wintermute/base/base_game.h
    engines/wintermute/base/base_keyboard_state.cpp
    engines/wintermute/base/base_keyboard_state.h
    engines/wintermute/base/base_named_object.cpp
    engines/wintermute/base/base_named_object.h
    engines/wintermute/base/base_object.cpp
    engines/wintermute/base/base_object.h
    engines/wintermute/base/base_parser.cpp
    engines/wintermute/base/base_parser.h
    engines/wintermute/base/base_persistence_manager.cpp
    engines/wintermute/base/base_persistence_manager.h
    engines/wintermute/base/base_point.cpp
    engines/wintermute/base/base_point.h
    engines/wintermute/base/base_quick_msg.cpp
    engines/wintermute/base/base_quick_msg.h
    engines/wintermute/base/base_region.cpp
    engines/wintermute/base/base_region.h
    engines/wintermute/base/base_save_thumb_helper.cpp
    engines/wintermute/base/base_save_thumb_helper.h
    engines/wintermute/base/base_script_holder.cpp
    engines/wintermute/base/base_script_holder.h
    engines/wintermute/base/base_scriptable.cpp
    engines/wintermute/base/base_scriptable.h
    engines/wintermute/base/base_sprite.cpp
    engines/wintermute/base/base_sprite.h
    engines/wintermute/base/base_string_table.cpp
    engines/wintermute/base/base_string_table.h
    engines/wintermute/base/base_sub_frame.cpp
    engines/wintermute/base/base_sub_frame.h
    engines/wintermute/base/base_surface_storage.cpp
    engines/wintermute/base/base_surface_storage.h
    engines/wintermute/base/base_transition_manager.cpp
    engines/wintermute/base/base_transition_manager.h
    engines/wintermute/base/base_viewport.cpp
    engines/wintermute/base/base_viewport.h
    engines/wintermute/base/file/base_disk_file.cpp
    engines/wintermute/base/file/base_disk_file.h
    engines/wintermute/base/file/base_file.cpp
    engines/wintermute/base/file/base_file.h
    engines/wintermute/base/file/base_file_entry.cpp
    engines/wintermute/base/file/base_file_entry.h
    engines/wintermute/base/file/base_package.cpp
    engines/wintermute/base/file/base_package.h
    engines/wintermute/base/file/base_resources.cpp
    engines/wintermute/base/file/base_resources.h
    engines/wintermute/base/file/base_save_thumb_file.cpp
    engines/wintermute/base/file/base_save_thumb_file.h
    engines/wintermute/base/file/dcpackage.h
    engines/wintermute/base/font/base_font.cpp
    engines/wintermute/base/font/base_font.h
    engines/wintermute/base/font/base_font_bitmap.cpp
    engines/wintermute/base/font/base_font_bitmap.h
    engines/wintermute/base/font/base_font_storage.cpp
    engines/wintermute/base/font/base_font_storage.h
    engines/wintermute/base/font/base_font_truetype.cpp
    engines/wintermute/base/font/base_font_truetype.h
    engines/wintermute/base/gfx/base_image.cpp
    engines/wintermute/base/gfx/base_image.h
    engines/wintermute/base/gfx/base_renderer.cpp
    engines/wintermute/base/gfx/base_renderer.h
    engines/wintermute/base/gfx/base_surface.cpp
    engines/wintermute/base/gfx/base_surface.h
    engines/wintermute/base/gfx/osystem/base_render_osystem.cpp
    engines/wintermute/base/gfx/osystem/base_render_osystem.h
    engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
    engines/wintermute/base/gfx/osystem/base_surface_osystem.h
    engines/wintermute/base/particles/part_emitter.cpp
    engines/wintermute/base/particles/part_emitter.h
    engines/wintermute/base/particles/part_force.cpp
    engines/wintermute/base/particles/part_force.h
    engines/wintermute/base/particles/part_particle.cpp
    engines/wintermute/base/particles/part_particle.h
    engines/wintermute/base/scriptables/dcscript.h
    engines/wintermute/base/scriptables/script.cpp
    engines/wintermute/base/scriptables/script.h
    engines/wintermute/base/scriptables/script_engine.cpp
    engines/wintermute/base/scriptables/script_engine.h
    engines/wintermute/base/scriptables/script_ext_array.cpp
    engines/wintermute/base/scriptables/script_ext_array.h
    engines/wintermute/base/scriptables/script_ext_date.cpp
    engines/wintermute/base/scriptables/script_ext_date.h
    engines/wintermute/base/scriptables/script_ext_file.cpp
    engines/wintermute/base/scriptables/script_ext_file.h
    engines/wintermute/base/scriptables/script_ext_math.cpp
    engines/wintermute/base/scriptables/script_ext_math.h
    engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp
    engines/wintermute/base/scriptables/script_ext_mem_buffer.h
    engines/wintermute/base/scriptables/script_ext_object.cpp
    engines/wintermute/base/scriptables/script_ext_object.h
    engines/wintermute/base/scriptables/script_ext_string.cpp
    engines/wintermute/base/scriptables/script_ext_string.h
    engines/wintermute/base/scriptables/script_stack.cpp
    engines/wintermute/base/scriptables/script_stack.h
    engines/wintermute/base/scriptables/script_value.cpp
    engines/wintermute/base/scriptables/script_value.h
    engines/wintermute/base/sound/base_sound.cpp
    engines/wintermute/base/sound/base_sound.h
    engines/wintermute/base/sound/base_sound_buffer.cpp
    engines/wintermute/base/sound/base_sound_buffer.h
    engines/wintermute/base/sound/base_sound_manager.cpp
    engines/wintermute/base/sound/base_sound_manager.h
    engines/wintermute/coll_templ.h
    engines/wintermute/dcgf.h
    engines/wintermute/dctypes.h
    engines/wintermute/math/math_util.cpp
    engines/wintermute/math/math_util.h
    engines/wintermute/math/matrix4.cpp
    engines/wintermute/math/matrix4.h
    engines/wintermute/math/vector2.cpp
    engines/wintermute/math/vector2.h
    engines/wintermute/platform_osystem.cpp
    engines/wintermute/platform_osystem.h
    engines/wintermute/system/sys_class.cpp
    engines/wintermute/system/sys_class.h
    engines/wintermute/system/sys_class_registry.cpp
    engines/wintermute/system/sys_class_registry.h
    engines/wintermute/system/sys_instance.cpp
    engines/wintermute/system/sys_instance.h
    engines/wintermute/ui/ui_button.cpp
    engines/wintermute/ui/ui_button.h
    engines/wintermute/ui/ui_edit.cpp
    engines/wintermute/ui/ui_edit.h
    engines/wintermute/ui/ui_entity.cpp
    engines/wintermute/ui/ui_entity.h
    engines/wintermute/ui/ui_object.cpp
    engines/wintermute/ui/ui_object.h
    engines/wintermute/ui/ui_text.cpp
    engines/wintermute/ui/ui_text.h
    engines/wintermute/ui/ui_tiled_image.cpp
    engines/wintermute/ui/ui_tiled_image.h
    engines/wintermute/ui/ui_window.cpp
    engines/wintermute/ui/ui_window.h
    engines/wintermute/utils/crc.cpp
    engines/wintermute/utils/crc.h
    engines/wintermute/utils/path_util.cpp
    engines/wintermute/utils/path_util.h
    engines/wintermute/utils/string_util.cpp
    engines/wintermute/utils/string_util.h
    engines/wintermute/utils/utils.cpp
    engines/wintermute/utils/utils.h
    engines/wintermute/wintypes.h



diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp
index 63b1532..9087d66 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 **)&params) != 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 **)&params)) > 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<AdSpriteSet *> 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 **)&params)) > 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 **)&params) != 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 **)&params)) > 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<AdSpriteSet *> 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 **)&params)) > 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 370a91c..271e57c 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<AdSpriteSet *> _talkSprites;

-	BaseArray<AdSpriteSet *> _talkSpritesEx;

-	TDirection _dir;

-	// new anim system

-	Common::String _talkAnimName;

-	Common::String _idleAnimName;

-	Common::String _walkAnimName;

-	Common::String _turnLeftAnimName;

-	Common::String _turnRightAnimName;

-	BaseArray<AdSpriteSet *> _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<AdSpriteSet *> _talkSprites;
+	BaseArray<AdSpriteSet *> _talkSpritesEx;
+	TDirection _dir;
+	// new anim system
+	Common::String _talkAnimName;
+	Common::String _idleAnimName;
+	Common::String _walkAnimName;
+	Common::String _turnLeftAnimName;
+	Common::String _turnRightAnimName;
+	BaseArray<AdSpriteSet *> _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 67a919d..234af1f 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 **)&params) != 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 **)&params)) > 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 **)&params) != 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 **)&params)) > 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 2178563..39dc133 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 f5d865d..fe8a599 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 **)&params)) > 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 **)&params, commands, (char **)&params2)) > 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 **)&params)) > 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 **)&params)) > 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 **)&params, commands, (char **)&params2)) > 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 **)&params)) > 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");
+		}
+	}


Commit: 6e14e9767062a35a39dc216d92e3cbf0ece69902
    https://github.com/scummvm/scummvm/commit/6e14e9767062a35a39dc216d92e3cbf0ece69902
Author: Willem Jan Palenstijn (wjp at usecode.org)
Date: 2012-09-04T13:25:28-07:00

Commit Message:
BADA: Convert CRLF to LF

Changed paths:
    backends/timer/bada/timer.cpp
    backends/timer/bada/timer.h



diff --git a/backends/timer/bada/timer.cpp b/backends/timer/bada/timer.cpp
index f030e06..b7daf02 100644
--- a/backends/timer/bada/timer.cpp
+++ b/backends/timer/bada/timer.cpp
@@ -1,115 +1,115 @@
-/* ScummVM - Graphic Adventure Engine

- *

- * ScummVM is the legal property of its developers, whose names

- * are too numerous to list here. Please refer to the COPYRIGHT

- * file distributed with this source distribution.

- *

- * This program is free software; you can redistribute it and/or

- * modify it under the terms of the GNU General Public License

- * as published by the Free Software Foundation; either version 2

- * of the License, or (at your option) any later version.

- *

- * This program is distributed in the hope that it will be useful,

- * but WITHOUT ANY WARRANTY; without even the implied warranty of

- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the

- * GNU General Public License for more details.

- *

- * You should have received a copy of the GNU General Public License

- * along with this program; if not, write to the Free Software

- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

- *

- */

-

-#if defined(BADA)

-

-#include "backends/timer/bada/timer.h"

-

-//

-// TimerSlot

-//

-TimerSlot::TimerSlot(Common::TimerManager::TimerProc callback,

-										 uint32 interval, void *refCon) :

-	_timer(0),

-	_callback(callback),

-	_interval(interval),

-	_refCon(refCon) {

-}

-

-TimerSlot::~TimerSlot() {

-}

-

-bool TimerSlot::OnStart() {

-	_timer = new Osp::Base::Runtime::Timer();

-	if (!_timer || IsFailed(_timer->Construct(*this))) {

-		AppLog("Failed to create timer");

-		return false;

-	}

-

-	if (IsFailed(_timer->Start(_interval))) {

-		AppLog("failed to start timer");

-		return false;

-	}

-	

-	AppLog("started timer %d", _interval);

-	return true;

-}

-

-void TimerSlot::OnStop() {

-	AppLog("timer stopped");

-	if (_timer) {

-		_timer->Cancel();		 

-		delete _timer;

-		_timer = NULL;

-	}

-}

-

-void TimerSlot::OnTimerExpired(Timer &timer) {

-	_callback(_refCon);

-	timer.Start(_interval);

-}

-

-//

-// BadaTimerManager

-//

-BadaTimerManager::BadaTimerManager() {

-}

-

-BadaTimerManager::~BadaTimerManager() {

-	for (Common::List<TimerSlot>::iterator slot = _timers.begin();

-			 slot != _timers.end(); ) {

-		slot->Stop();

-		slot = _timers.erase(slot);

-	}

-}

-

-bool BadaTimerManager::installTimerProc(TimerProc proc, int32 interval, void *refCon,

-																				const Common::String &id) {

-	TimerSlot *slot = new TimerSlot(proc, interval / 1000, refCon);

-

-	if (IsFailed(slot->Construct(THREAD_TYPE_EVENT_DRIVEN))) {

-		AppLog("Failed to create timer thread");

-		delete slot;

-		return false;

-	}

-

-	if (IsFailed(slot->Start())) {

-		delete slot;

-		AppLog("Failed to start timer thread");

-		return false;

-	}

-

-	_timers.push_back(*slot);

-	return true;

-}

-

-void BadaTimerManager::removeTimerProc(TimerProc proc) {

-	for (Common::List<TimerSlot>::iterator slot = _timers.begin();

-			 slot != _timers.end(); ++slot) {

-		if (slot->_callback == proc) {

-			slot->Stop();

-			slot = _timers.erase(slot);

-		}

-	}

-}

-

-#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.
+ *
+ */
+
+#if defined(BADA)
+
+#include "backends/timer/bada/timer.h"
+
+//
+// TimerSlot
+//
+TimerSlot::TimerSlot(Common::TimerManager::TimerProc callback,
+										 uint32 interval, void *refCon) :
+	_timer(0),
+	_callback(callback),
+	_interval(interval),
+	_refCon(refCon) {
+}
+
+TimerSlot::~TimerSlot() {
+}
+
+bool TimerSlot::OnStart() {
+	_timer = new Osp::Base::Runtime::Timer();
+	if (!_timer || IsFailed(_timer->Construct(*this))) {
+		AppLog("Failed to create timer");
+		return false;
+	}
+
+	if (IsFailed(_timer->Start(_interval))) {
+		AppLog("failed to start timer");
+		return false;
+	}
+	
+	AppLog("started timer %d", _interval);
+	return true;
+}
+
+void TimerSlot::OnStop() {
+	AppLog("timer stopped");
+	if (_timer) {
+		_timer->Cancel();		 
+		delete _timer;
+		_timer = NULL;
+	}
+}
+
+void TimerSlot::OnTimerExpired(Timer &timer) {
+	_callback(_refCon);
+	timer.Start(_interval);
+}
+
+//
+// BadaTimerManager
+//
+BadaTimerManager::BadaTimerManager() {
+}
+
+BadaTimerManager::~BadaTimerManager() {
+	for (Common::List<TimerSlot>::iterator slot = _timers.begin();
+			 slot != _timers.end(); ) {
+		slot->Stop();
+		slot = _timers.erase(slot);
+	}
+}
+
+bool BadaTimerManager::installTimerProc(TimerProc proc, int32 interval, void *refCon,
+																				const Common::String &id) {
+	TimerSlot *slot = new TimerSlot(proc, interval / 1000, refCon);
+
+	if (IsFailed(slot->Construct(THREAD_TYPE_EVENT_DRIVEN))) {
+		AppLog("Failed to create timer thread");
+		delete slot;
+		return false;
+	}
+
+	if (IsFailed(slot->Start())) {
+		delete slot;
+		AppLog("Failed to start timer thread");
+		return false;
+	}
+
+	_timers.push_back(*slot);
+	return true;
+}
+
+void BadaTimerManager::removeTimerProc(TimerProc proc) {
+	for (Common::List<TimerSlot>::iterator slot = _timers.begin();
+			 slot != _timers.end(); ++slot) {
+		if (slot->_callback == proc) {
+			slot->Stop();
+			slot = _timers.erase(slot);
+		}
+	}
+}
+
+#endif
diff --git a/backends/timer/bada/timer.h b/backends/timer/bada/timer.h
index 04ca771..f6ae451 100644
--- a/backends/timer/bada/timer.h
+++ b/backends/timer/bada/timer.h
@@ -1,62 +1,62 @@
-/* ScummVM - Graphic Adventure Engine

- *

- * ScummVM is the legal property of its developers, whose names

- * are too numerous to list here. Please refer to the COPYRIGHT

- * file distributed with this source distribution.

- *

- * This program is free software; you can redistribute it and/or

- * modify it under the terms of the GNU General Public License

- * as published by the Free Software Foundation; either version 2

- * of the License, or (at your option) any later version.

- *

- * This program is distributed in the hope that it will be useful,

- * but WITHOUT ANY WARRANTY; without even the implied warranty of

- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the

- * GNU General Public License for more details.

- *

- * You should have received a copy of the GNU General Public License

- * along with this program; if not, write to the Free Software

- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

- *

- */

-

-#ifndef BADA_TIMER_H

-#define BADA_TIMER_H

-

-#include <FBase.h>

-

-#include "common/timer.h"

-#include "common/list.h"

-

-using namespace Osp::Base::Runtime;

-

-struct TimerSlot: public ITimerEventListener, public Thread {

-	TimerSlot(Common::TimerManager::TimerProc callback,

-						uint32 interval,

-						void *refCon);

-	~TimerSlot();

-

-	bool OnStart(void);

-	void OnStop(void);

-	void OnTimerExpired(Timer &timer);

-

-	Timer *_timer;

-	Common::TimerManager::TimerProc _callback;

-	uint32 _interval;	// in microseconds

-	void *_refCon;

-};

-

-class BadaTimerManager : public Common::TimerManager {

-public:

-	BadaTimerManager();

-	~BadaTimerManager();

-

-	bool installTimerProc(TimerProc proc, int32 interval, void *refCon, 

-												const Common::String &id);

-	void removeTimerProc(TimerProc proc);

-

-private:

-	Common::List<TimerSlot> _timers;

-};

-

-#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.
+ *
+ */
+
+#ifndef BADA_TIMER_H
+#define BADA_TIMER_H
+
+#include <FBase.h>
+
+#include "common/timer.h"
+#include "common/list.h"
+
+using namespace Osp::Base::Runtime;
+
+struct TimerSlot: public ITimerEventListener, public Thread {
+	TimerSlot(Common::TimerManager::TimerProc callback,
+						uint32 interval,
+						void *refCon);
+	~TimerSlot();
+
+	bool OnStart(void);
+	void OnStop(void);
+	void OnTimerExpired(Timer &timer);
+
+	Timer *_timer;
+	Common::TimerManager::TimerProc _callback;
+	uint32 _interval;	// in microseconds
+	void *_refCon;
+};
+
+class BadaTimerManager : public Common::TimerManager {
+public:
+	BadaTimerManager();
+	~BadaTimerManager();
+
+	bool installTimerProc(TimerProc proc, int32 interval, void *refCon, 
+												const Common::String &id);
+	void removeTimerProc(TimerProc proc);
+
+private:
+	Common::List<TimerSlot> _timers;
+};
+
+#endif






More information about the Scummvm-git-logs mailing list