[Scummvm-git-logs] scummvm master -> 0c12087ccca878281dccd1c6d760a615ddf2fc77

sev- sev at scummvm.org
Tue Feb 25 13:45:59 UTC 2020


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

Summary:
dd3f54cae8 DRAGONS: Initial commit
c846170787 DRAGONS: starting on bigfile.dat loader
4f77da673a DRAGONS: Work on loading scene gfx files.
09c507a9cd DRAGONS: Adding actor class
bbf08a389a DRAGONS: More work on actor loading
e7e8155baf DRAGONS: More work on actor loading
ac1f5a5984 DRAGONS: More work on actor sequences
012652068f DRAGONS: Work on executing actor sequences
774147099e DRAGONS: more work on actor update logic
df0298f8f4 DRAGONS: Added more sequence opCodes
c0f1d70393 DRAGOMS: Work on actor draw priorities
534fdd0640 DRAGONS: Started work on script logic
875d9f7bd7 DRAGONS: More work on script opCodes
a25ee6f255 DRAGONS: Add start of special opcode support
22d15cc7ca DRAGONS: Adding class for loading dragon.img file data
be017e1950 DRAGOMS: More work on scripts
5bab09d76e DRAGONS: More work on script logic
b4b5689af5 DRAGONS: More work on scripts
712071f256 DRAGONS: Work on actor pathfinding logic
fa842a0c7c DRAGONS: work on pathfinding
e74331f38d DRAGONS: pathfinding work
3cc1746bc3 DRAGONS: work on pathfinding
925b2292d6 DRAGONS: More work on actor pathfinding
b7a731b991 DRAGONS: Fixed pathfinder target adjustment logic
c4eac3b965 DRAGONS: pathfinding
080bffb34b DRAGONS: pathfinding
d9e341f0e1 DRAGONS: pathfinding
1ecd63ca02 DRAGONS: Start walking actors along path
eee3f64a88 DRAGONS: Add support for sprite flipping. More pathfinding logic
79bc1edb5c DRAGONS: fix sprite off screen with flipped sprite
f528cd2921 DRAGONS: more pathfinding
3210f936d0 DRAGONS: pathfinder
8a0dac1a11 DRAGONS: pathfinding
c7bdbf4a24 DRAGONS: finished main pathfinder funxction
7a596728de DRAGONS: work on tilemap overlays
69ec3ed7c8 DRAGONS: image overlays
ed56d587d5 DRAGONS: Show / Hide tile overlays. Work on inventory bag display
0a2a16c64f DRAGONS: added inventory to build system
b98d6f1200 DRAGONS: work on cursors
c1307c375f DRAGONS: moving cursor around
65700ca2a6 DRAGONS: work on cursor type changes
f71852707b DRAGONS: work on cursor animation
b4d6e1c520 DRAGONS: More cursor update logic
cbf85f6913 DRAGONS: Implementing more script opcodes
c287fa7106 DRAGONS: Started work on cursor cycling via right clicking
28a75525fd DRAGONS: Implementing opcode 14
deecd24582 DRAGONS: Implementing opcode 15
22ab216b78 DRAGONS: Adding game loop from original logic
2eac8db480 DRAGONS: Added original game loop logic
64ff1a2b46 DRAGONS: implement click action logic
22cec75350 DRAGONS: Pathfinding fixes
b339a9da7b DRAGONS: more pathfinder fixes
7a75ae2190 DRAGONS: More work on cursor action logic
6749657877 DRAGONS: More opcodes. Work on scene changing
963cd5441e DRAGONS: Work on scene change logic
a0ada3357c DRAGONS: Adding more scene loading logic
43498fda20 DRAGONS: update flicker coords when changing scenes
11483dfc73 DRAGONS: bug fixing pathfinder logic
7c10fe11d0 DRAGONS: Bug fixes for pathfinding
3f4ad5b2f2 DRAGONS: Update priority tilemap when adding/removing overlays
1746fefb0d DRAGONS: execute action after walking to location
98f935efb9 DRAGONS: update flicker after walking to destination
0acc07116f DRAGONS: Fix issue with cursor hover animations
2805bb4cab DRAGONS: show hide inventory bag
c2d584533b DRAGONS: bounce the inventory bag when drops in
c9204e3090 DRAGONS: Added items to inventory display
2e7b8b91b5 DRAGONS: Fixed inventory selection logic
c848548c02 DRAGONS: work on save/load
8c0fc756a1 DRAGONS: Add savelog to make file
799c33ccb2 DRAGONS: script bug fixes. Improving load game logic
10df96224e DRAGONS: Fix op14 if instruction
916d5da715 DRAGONS: allow load save game at start
f6b9ea6e41 DRAGONS: Added special op 0x53
d0d1f29722 DRAGONS: Added more script opcodes
ba284455b6 DRAGONS: work on talk sequences
5e3804e0e0 DRAGONS: work on flicker talk logic
e399d5b272 DRAGOMS: work on speech audio
7cf98ce5d3 DRAGONS: more dialog work
fe6600cc1f DRAGONS: Added Font class
a1a2b53248 DRAGONS: More work on font handling
f4b4156b51 DRAGONS: More work on talk dialog logic
118fa61835 DRAGONS: Pizza maker logic
a77889f85a DRAGONS: More script/special opcodes
8286a6de7a DRAGONS: Fixed bug with missing inventory items when loading from save game.
7392c4bc1f DRAGONS: Invention book display, work on intro sequence
0312e61345 DRAGONS: Work on intro sequences
627989e46f DRAGONS: fixed font mapping
7d7946e87a DRAGONS: More work on scene 1 logic
a65be38d90 DRAGONS: Improved camera logic in scene 1 cutscene
9aa66dd9ee DRAGONS: Fixed background display priority logic
efedc38511 DRAGONS: Add actor display order logic.
8612ccf5e0 DRAGONS: Improved scene 1 draw order
235c4464aa DRAGONS: Fixed background palette logic for cut scenes
015d68c114 DRAGONS: Added random function. Cleaned up method names
4bd381242a DRAGONS: Added default talk response ids
c20d288e22 DRAGONS: refactored inventory logic into inventory class
3f8c1596a4 DRAGONS: Fixed crash when moving items in inventory bag
c8ea9b2863 DRAGONS: Renamed inventory item table
d173ea7c5d DRAGONS: Removed some magic numbers
7b0c04eb3d DRAGONS: work on text formatting and dialog menu
f65a55783d DRAGONS: Fixed font colours. More work on talking to actors
52c0f285a0 DRAGONS: Fixed bug with sequence animations not reseting to the correct sequenceID. Fixed mem smashing bug with dialog m
59b26b78f5 DRAGONS: Fixed bug when attempting some actions. More work on special
8f37b37e24 DRAGONS: Work on table based scene update function
ec14cbe464 DRAGONS: Add spcUnk5d
a8f3cbe911 DRAGONS: Added place holder functions for screenshake and dragon on hill scene
81577ad2f0 DRAGONS: Started work on first minigame
c91c21bf89 DRAGONS: Fixes for the first mini game.
4a0a4ee1af DRAGONS: Fixed bugs in first mini game. It should be winable now
57cb891a55 DRAGONS: More special opcodes. Saved knights cutscene.
e774fe4201 DRAGONS: More work on dance battle mini game
a58a8d08c3 DRAGONS: Missing bag logic
6aaa143fe0 DRAGONS: added input handling for mini game 4
6c3596446c DRAGONS: added more special opcode stubs
f5c3790df4 DRAGONS: Added more specialOpcode logic
b1536f2360 DRAGONS: More special opcode stubs
d5aec116c1 DRAGONS: Added more special script logic.
77d0b6770e DRAGONS: work on mini game 3. Work on cutscenes.
c7b9b69035 DRAGONS: work on screen palette handling
16ae7e579e DRAGONS: Working on semi-transparent actors
939bd5dfd6 DRAGONS: Work on palette handling. Converted Actor back to 8bit surface.
d23849d95d DRAGONS: more palette fixes. Update scene palette with cursor palette
13a9ddaa79 DRAGONS: More work on font palette
a3458f4257 DRAGONS: Work on mini game 3
d510e2541f DRAGONS: Renamed magic variable
2e714a421e DRAGONS: work on minigame 3
3299c2136d DRAGONS: Fixed bug with performAction script
fcd92dc4c3 DRAGONS: handle negative offsets in background shift for minigame 3
c836646b69 DRAGONS: added ScriptOpCode constructor. Work on eyes bg layer in mini
88b0e2cff5 DRAGONS: Fixed bug while evaluating script expressions. expression
9dcc30945a DRAGONS: Started on mini game 2. Added vsync updater function logic
8df472f699 DRAGONS: Fixed random number generator. Fixed returning to dialog menu while talking
e51fe35e3a DRAGONS: Palette fixes
211377a5b3 DRAGONS: Work on mini game 2
71817f7b1e DRAGONS: Work on mini game 2
633bbeb89c DRAGONS: More work on mini game 2
e64a53a32b DRAGONS: Work on mini game 2 and mini game 5
7f0b7d2dc6 DRAGONS: More special opcodes for final scene logic
1db640963f DRAGONS: Started on credits logic
218bfd0bff DRAGONS: Work on end credits
8512c91c79 DRAGONS: Fixed talk script opcode
77ebe94f26 DRAGONS: sound plays (WIP, hack)
ddcec20428 DRAGONS: Merged two sound classes
f9db411416 DRAGONS: work on sfx
8d9dc0138e DRAGONS: Fixed timing on final backstage scene
aac561c124 DRAGONS: Hooked up correct sfx tone
bcdad1a606 DRAGONS: work on playing multiple sfx at once
2abd8b6f10 DRAGONS: Fixed bug when looking at objects. Stop sfx if already playing before starting it again.
ad2eebd348 DRAGONS: Fixed initial sfx load bug. Fixed sfx volume bug when stopping audio.
1023f3d8c2 DRAGONS: Clear old actor frame before recyling actor object
06ae3c43f3 DRAGONS: Some code cleanups
2d25f10ddd DRAGONS: Work on scaling. Added support for screen coords in cursor and
5e2a7a6882 DRAGONS: Added scaling to actor sprites
8c9a0cf1bb DRAGONS: Replaced max scale with define
d43bd21694 DRAGONS: Screen shake effects
f10347a5ca DRAGONS: variable naming cleanup
bb0fbec3bb DRAGONS: Replaced walk code with JohnDoe's walk logic. Cleaned up Actor variable names
31e314ef7e DRAGONS: Add textIds to spcZigmondFraudSceneLogic
af43722a35 DRAGONS: Add garden scene logic
1116df23c1 DRAGONS: Added table based scene updater logic
8a639a6eba DRAGONS: Added more scene update functions
f94d3e7671 DRAGONS: Fixed men in mine stop scene updater script function
56e0a2fa0a DRAGONS: Working on castle fog update logic
5cc1ff8dad DRAGONS: Add additive pixel blending for scene layers
894e0d99df DRAGONS: Added more missing specialOpcode logic
40a13a853e DRAGONS: Added palette cycling logic
780070f995 DRAGONS: Updated palette cycling script opcode
dc312c59f3 DRAGONS: Added lights to mini game 4
0036271c85 DRAGONS: More code cleanups
952442d56a DRAGONS: Code cleanup
77544a8b26 DRAGONS: Fixed naming on include define check
6dcb16fc11 DRAGONS: Added splashes to stilt walking sequence.
adba45ce33 DRAGONS: Compile fixes
837af740c5 DRAGONS: Removed uint32_t int32_t and ushort
b792c8bd13 DRAGONS: More compile fixes
8301d0dbb1 DRAGONS: Compile fixes + formatting
47f7d0aed5 DRAGONS: Add size to const array data
f32a199876 DRAGONS: Fixed formatting on includes
11eee8190f DRAGONS: Remove usages of auto keyword
559a96c1ca DRAGONS: Fixed platform specific issues in VabSound.
dfee40fd24 DRAGONS: More code formatting
08fb9da119 DRAGONS: Rename Actor class variables to conform our naming standards
2ca5dc3f11 DRAGONS: Whitespace fixes
1d783366c0 DRAGONS: Remove superfluous namespace references
7a912ee39f DRAGONS: More whitespace fixes
c28b2d2a07 DRAGONS: Fix warnings
039d8c0274 DRAGONS: Fix warnings
647f687830 DRAGONS: Whitespace fixes
89e9e76efa DRAGONS: More class variable renames
df7102298e DRAGONS: More renames for the class variables
36008ba9e9 DRAGONS: Whitespace fixes
9ea348117b DRAGONS: Fix incorrect assert() usage.
5d39aab174 DRAGONS: Whitespace fixes
853b703953 DRAGONS: Fix whitespaces
3d72a0a816 DRAGONS: Rename VabSound.* to vabsound.*
aae718b99d DRAGONS: Whitespace fixes
8ffb484c34 DRAGONS: Fix #include directive
79c7dbc8f6 DRAGONS: Whitespace fixes
6e86ab1d45 DRAGONS: Code clean. Added names to some script opcodes. Fixes for mini game 2
4790844720 DRAGONS: Started adding support for other game variants. EU and DE
f848b87572 DRAGONS: Fixed cutscene palettes in other variants. Started on FR support
bda2b9ae5a DRAGONS: Adding language support for flicker's default response text
ccea9afda3 DRAGONS: Renamed a bunch of script opcodes
ff519c1373 DRAGONS: Fixed flicker idle animation
bd39b6baae DRAGONS: Removed goto from game loop. renamed counter to flickerIdleCounter
21f61c26b9 DRAGONS: More gameLoop refactoring
a04d6206a0 DRAGONS: Game loop refactoring
fe1a4a705f DRAGONS: Cleaning up gameLoop. Removing goto logic
c9aad06192 DRAGONS: More code cleanup
723f082ea9 DRAGONS: Fixed flicker display bug when returning from invention book scene
72161554b2 DRAGONS: Refactoring inventory state code
832f38b3cd DRAGONS: More code cleanups. Added paning while walking on wide scenes
5c5eb3ad8b DRAGONS: More code cleanup. Stop audio on exit.
f10f1f5e6a DRAGONS: Improve method/variable names
ed2bf372d9 DRAGONS: Renaming variables
355d308757 DRAGONS: Improved FontManager logic. More var renaming
f7e7d5649e DRAGONS: Added dialog box borders
fad43ef8be DRAGONS: Changed engine methods from virtual to override
0c12087ccc DRAGONS: Removed temp ushort define


Commit: dd3f54cae82851a9a8977979c515fca9bcad3962
    https://github.com/scummvm/scummvm/commit/dd3f54cae82851a9a8977979c515fca9bcad3962
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Initial commit

Changed paths:
  A engines/dragons/configure.engine
  A engines/dragons/detection.cpp
  A engines/dragons/dragons.cpp
  A engines/dragons/dragons.h
  A engines/dragons/module.mk


diff --git a/engines/dragons/configure.engine b/engines/dragons/configure.engine
new file mode 100644
index 0000000000..4dccbdf866
--- /dev/null
+++ b/engines/dragons/configure.engine
@@ -0,0 +1,3 @@
+# This file is included from the main "configure" script
+# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps]
+add_engine dragons "Blazing Dragons" no
diff --git a/engines/dragons/detection.cpp b/engines/dragons/detection.cpp
new file mode 100644
index 0000000000..572fdf2e50
--- /dev/null
+++ b/engines/dragons/detection.cpp
@@ -0,0 +1,189 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "dragons/dragons.h"
+
+#include "common/config-manager.h"
+#include "engines/advancedDetector.h"
+#include "common/savefile.h"
+#include "common/system.h"
+#include "base/plugins.h"
+#include "graphics/thumbnail.h"
+
+static const PlainGameDescriptor dragonsGames[] = {
+		{ "dragons", "Blazing Dragons" },
+		{ 0, 0 }
+};
+
+namespace Dragons {
+
+static const Dragons::DragonsGameDescription gameDescriptions[] = {
+		{
+				{
+						"dragons",
+						0,
+						AD_ENTRY1s("bigfile.dat", "02c26712bee57266f28235fdc0207725", 44990464),
+						Common::EN_USA,
+						Common::kPlatformPSX,
+						ADGF_DROPPLATFORM,
+						GUIO0()
+				},
+				kGameIdDragons
+		},
+
+		{
+				{
+						"dragons",
+						0,
+						AD_ENTRY1s("bigfile.dat", "234234234234", 29779968),
+						Common::DE_DEU,
+						Common::kPlatformPSX,
+						ADGF_DROPPLATFORM,
+						GUIO0()
+				},
+				kGameIdDragons
+		},
+
+		{AD_TABLE_END_MARKER, 0}
+};
+
+} // End of namespace Dragons
+
+static const char * const directoryGlobs[] = {
+		"resource",
+		0
+};
+
+class DragonsMetaEngine : public AdvancedMetaEngine {
+public:
+	DragonsMetaEngine() : AdvancedMetaEngine(Dragons::gameDescriptions, sizeof(Dragons::DragonsGameDescription), dragonsGames) {
+		_maxScanDepth = 2;
+		_directoryGlobs = directoryGlobs;
+	}
+
+	const char *getEngineId() const {
+		return "dragons";
+	}
+
+	virtual const char *getName() const {
+		return "Blazing Dragons";
+	}
+
+	virtual const char *getOriginalCopyright() const {
+		return "(C) 1996 The Illusions Gaming Company";
+	}
+
+	virtual bool hasFeature(MetaEngineFeature f) const;
+	virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;
+	virtual int getMaximumSaveSlot() const;
+	virtual SaveStateList listSaves(const char *target) const;
+	SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
+	virtual void removeSaveState(const char *target, int slot) const;
+};
+
+bool DragonsMetaEngine::hasFeature(MetaEngineFeature f) const {
+	return
+			(f == kSupportsListSaves) ||
+			(f == kSupportsDeleteSave) ||
+			(f == kSupportsLoadingDuringStartup) ||
+			(f == kSavesSupportMetaInfo) ||
+			(f == kSavesSupportThumbnail) ||
+			(f == kSavesSupportCreationDate);
+}
+
+void DragonsMetaEngine::removeSaveState(const char *target, int slot) const {
+	Common::String fileName = Common::String::format("%s.%03d", target, slot);
+	g_system->getSavefileManager()->removeSavefile(fileName);
+}
+
+int DragonsMetaEngine::getMaximumSaveSlot() const {
+	return 999;
+}
+
+SaveStateList DragonsMetaEngine::listSaves(const char *target) const {
+	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+	Dragons::SaveHeader header;
+	Common::String pattern = target;
+	pattern += ".???";
+	Common::StringArray filenames;
+	filenames = saveFileMan->listSavefiles(pattern.c_str());
+	SaveStateList saveList;
+	for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
+		// Obtain the last 3 digits of the filename, since they correspond to the save slot
+		int slotNum = atoi(file->c_str() + file->size() - 3);
+		if (slotNum >= 0 && slotNum <= 999) {
+			Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str());
+			if (in) {
+				if (Dragons::DragonsEngine::readSaveHeader(in, header) == Dragons::kRSHENoError) {
+					saveList.push_back(SaveStateDescriptor(slotNum, header.description));
+				}
+				delete in;
+			}
+		}
+	}
+	Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
+	return saveList;
+}
+
+SaveStateDescriptor DragonsMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
+	Common::String filename = Dragons::DragonsEngine::getSavegameFilename(target, slot);
+	Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str());
+	if (in) {
+		Dragons::SaveHeader header;
+		Dragons::kReadSaveHeaderError error;
+		error = Dragons::DragonsEngine::readSaveHeader(in, header, false);
+		delete in;
+		if (error == Dragons::kRSHENoError) {
+			SaveStateDescriptor desc(slot, header.description);
+			// Slot 0 is used for the "Continue" save
+			desc.setDeletableFlag(slot != 0);
+			desc.setWriteProtectedFlag(slot == 0);
+			desc.setThumbnail(header.thumbnail);
+			desc.setSaveDate(header.saveDate & 0xFFFF, (header.saveDate >> 16) & 0xFF, (header.saveDate >> 24) & 0xFF);
+			desc.setSaveTime((header.saveTime >> 16) & 0xFF, (header.saveTime >> 8) & 0xFF);
+			desc.setPlayTime(header.playTime * 1000);
+			return desc;
+		}
+	}
+	return SaveStateDescriptor();
+}
+
+bool DragonsMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
+	const Dragons::DragonsGameDescription *gd = (const Dragons::DragonsGameDescription *)desc;
+	if (gd) {
+		switch (gd->gameId) {
+			case Dragons::kGameIdDragons:
+				*engine = new Dragons::DragonsEngine(syst);
+				break;
+			default:
+				error("Unknown game id");
+				break;
+		}
+	}
+	return desc != 0;
+}
+
+#if PLUGIN_ENABLED_DYNAMIC(DRAGONS)
+REGISTER_PLUGIN_DYNAMIC(ILLUSIONS, PLUGIN_TYPE_ENGINE, DragonsMetaEngine);
+#else
+REGISTER_PLUGIN_STATIC(DRAGONS, PLUGIN_TYPE_ENGINE, DragonsMetaEngine);
+#endif
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
new file mode 100644
index 0000000000..f7490ebae8
--- /dev/null
+++ b/engines/dragons/dragons.cpp
@@ -0,0 +1,82 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "engines/util.h"
+#include "graphics/thumbnail.h"
+#include "common/error.h"
+#include "dragons.h"
+
+namespace Dragons {
+
+DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
+
+}
+
+DragonsEngine::~DragonsEngine() {
+
+}
+
+Common::Error DragonsEngine::run() {
+	Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0);
+	initGraphics(320, 240, &pixelFormat16);
+	debug("Ok");
+	return Common::kNoError;
+}
+
+const char *DragonsEngine::getSavegameFilename(int num) {
+	static Common::String filename;
+	filename = getSavegameFilename(_targetName, num);
+	return filename.c_str();
+}
+
+Common::String DragonsEngine::getSavegameFilename(const Common::String &target, int num) {
+	assert(num >= 0 && num <= 999);
+	return Common::String::format("%s.%03d", target.c_str(), num);
+}
+
+#define DRAGONS_SAVEGAME_VERSION 0
+
+kReadSaveHeaderError DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
+
+	header.version = in->readUint32LE();
+	if (header.version > DRAGONS_SAVEGAME_VERSION)
+		return kRSHEInvalidVersion;
+
+	byte descriptionLen = in->readByte();
+	header.description = "";
+	while (descriptionLen--) {
+		header.description += (char)in->readByte();
+	}
+
+	if (!Graphics::loadThumbnail(*in, header.thumbnail, skipThumbnail)) {
+		return kRSHEIoError;
+	}
+
+	header.flags = in->readUint32LE();
+
+	header.saveDate = in->readUint32LE();
+	header.saveTime = in->readUint32LE();
+	header.playTime = in->readUint32LE();
+
+	return ((in->eos() || in->err()) ? kRSHEIoError : kRSHENoError);
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
new file mode 100644
index 0000000000..15ca6fa2ec
--- /dev/null
+++ b/engines/dragons/dragons.h
@@ -0,0 +1,70 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef SCUMMVM_DRAGONS_H
+#define SCUMMVM_DRAGONS_H
+
+#include "gui/EventRecorder.h"
+#include "engines/engine.h"
+
+namespace Dragons {
+
+enum {
+	kGameIdDragons = 1
+};
+
+struct DragonsGameDescription {
+	ADGameDescription desc;
+	int gameId;
+};
+
+struct SaveHeader {
+	Common::String description;
+	uint32 version;
+	uint32 flags;
+	uint32 saveDate;
+	uint32 saveTime;
+	uint32 playTime;
+	Graphics::Surface *thumbnail;
+};
+
+enum kReadSaveHeaderError {
+	kRSHENoError = 0,
+	kRSHEInvalidType = 1,
+	kRSHEInvalidVersion = 2,
+	kRSHEIoError = 3
+};
+
+class DragonsEngine : public Engine {
+public:
+	DragonsEngine(OSystem *syst);
+	~DragonsEngine();
+
+	virtual Common::Error run();
+
+	const char *getSavegameFilename(int num);
+	static Common::String getSavegameFilename(const Common::String &target, int num);
+	static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_DRAGONS_H
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
new file mode 100644
index 0000000000..1688743b93
--- /dev/null
+++ b/engines/dragons/module.mk
@@ -0,0 +1,16 @@
+MODULE := engines/dragons
+ 
+MODULE_OBJS := \
+	detection.o \
+	dragons.o
+ 
+MODULE_DIRS += \
+	engines/dragons
+ 
+# This module can be built as a plugin
+ifeq ($(ENABLE_QUUX), DYNAMIC_PLUGIN)
+PLUGIN := 1
+endif
+ 
+# Include common rules 
+include $(srcdir)/rules.mk


Commit: c8461707877960000b8012757715bb42a18572b7
    https://github.com/scummvm/scummvm/commit/c8461707877960000b8012757715bb42a18572b7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: starting on bigfile.dat loader

Changed paths:
  A engines/dragons/bigfile.cpp
  A engines/dragons/bigfile.h


diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
new file mode 100644
index 0000000000..45c2da26da
--- /dev/null
+++ b/engines/dragons/bigfile.cpp
@@ -0,0 +1,26 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "bigfile.h"
+
+namespace Illusions {
+
+} // End of namespace Illusions
diff --git a/engines/dragons/bigfile.h b/engines/dragons/bigfile.h
new file mode 100644
index 0000000000..afe4511072
--- /dev/null
+++ b/engines/dragons/bigfile.h
@@ -0,0 +1,33 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 SCUMMVM_BIGFILE_H
+#define SCUMMVM_BIGFILE_H
+
+namespace Dragons {
+
+class Bigfile {
+
+};
+
+} // End of namespace dragons
+
+#endif //SCUMMVM_BIGFILE_H


Commit: 4f77da673abb004cb159a4aef7477f402355b28e
    https://github.com/scummvm/scummvm/commit/4f77da673abb004cb159a4aef7477f402355b28e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on loading scene gfx files.

Changed paths:
  A engines/dragons/background.cpp
  A engines/dragons/background.h
  A engines/dragons/dragonini.cpp
  A engines/dragons/dragonini.h
  A engines/dragons/dragonrms.cpp
  A engines/dragons/dragonrms.h
  A engines/dragons/scene.cpp
  A engines/dragons/scene.h
  A engines/dragons/screen.cpp
  A engines/dragons/screen.h
    engines/dragons/bigfile.cpp
    engines/dragons/bigfile.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
new file mode 100644
index 0000000000..a91767f9cb
--- /dev/null
+++ b/engines/dragons/background.cpp
@@ -0,0 +1,171 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include <common/memstream.h>
+#include "graphics/screen.h"
+#include "common/endian.h"
+#include "background.h"
+
+namespace Dragons {
+
+#define TILE_WIDTH 32
+#define TILE_HEIGHT 8
+#define TILE_SIZE (TILE_WIDTH * TILE_HEIGHT * 2)
+
+struct TileMap {
+	uint16 w;
+	uint16 h;
+	uint32 size;
+	byte *map;
+	uint8 tileIndexOffset;
+};
+
+void Dragons::PriorityLayer::load(TileMap &tileMap, byte *tiles) {
+	_width = tileMap.w * TILE_WIDTH;
+	_height = tileMap.h * TILE_HEIGHT;
+	_mapWidth = tileMap.w;
+	_mapHeight = tileMap.h;
+	size_t tileSize = (size_t)tileMap.tileIndexOffset * TILE_SIZE;
+	_map = new byte[tileMap.size];
+	_values = new byte[tileSize];
+
+	memcpy(_map, tileMap.map, tileMap.size);
+	memcpy(_values, tiles, tileSize);
+}
+
+int PriorityLayer::getPriority(Common::Point pos) {
+	pos.x = CLIP<int16>(pos.x, 0, _width - 1);
+	pos.y = CLIP<int16>(pos.y, 0, _height - 1);
+	const int16 tx = pos.x / 32, sx = pos.x % 32;
+	const int16 ty = pos.y / 8, sy = pos.y % 8;
+	uint16 mapIndex = READ_LE_UINT16(_map + 2 * (tx + ty * _mapWidth)) - 1;
+	return _values[mapIndex * 32 * 8 + sx + sy * 32];
+
+}
+
+bool Background::load(byte *dataStart, Common::SeekableReadStream &stream) {
+	stream.read(_palette, 512);
+	_palette[0] = 0x80; //FIXME update palette
+	_palette[1] = 0x80;
+
+	_points1 = loadPoints(stream);
+	_points2 = loadPoints(stream);
+	stream.seek(0x305);
+	uint8 tileindexOffset = stream.readByte();
+	stream.seek(0x308);
+
+	uint32 tilemapOffset = 0x324;
+	TileMap tileMap[3];
+	for(int i=0;i< 3;i++) {
+		tileMap[i].w = stream.readUint16LE();
+		tileMap[i].h = stream.readUint16LE();
+		tileMap[i].size = stream.readUint32LE();
+		tileMap[i].map = dataStart + tilemapOffset;
+		tileMap[i].tileIndexOffset = tileindexOffset;
+		debug("Tilemap (%d,%d) map: %X", tileMap[i].w, tileMap[i].h, tilemapOffset);
+
+		tilemapOffset += tileMap[i].size;
+	}
+
+	uint32 finalSize = stream.readUint32LE();
+
+	_priorityLayer = new PriorityLayer();
+	_priorityLayer->load(tileMap[0], dataStart + tilemapOffset);
+
+	uint32 tilesOffset = tilemapOffset + finalSize;
+	debug("Tiles: %X", tilesOffset);
+	debug("tileIndexOffset: %d", tileMap[0].tileIndexOffset);
+	_bgLayer = loadGfxLayer(tileMap[0], dataStart + tilesOffset);
+	_mgLayer = loadGfxLayer(tileMap[1], dataStart + tilesOffset);
+	_fgLayer = loadGfxLayer(tileMap[2], dataStart + tilesOffset);
+	return false;
+}
+
+Common::Point *Background::loadPoints(Common::SeekableReadStream &stream) {
+	Common::Point *points = new Common::Point[0x20];
+
+	for (int i=0;i < 0x20;i++) {
+		points[i].x = stream.readUint16LE();
+		points[i].y = stream.readUint16LE();
+	}
+
+	return points;
+}
+
+Graphics::Surface *Background::loadGfxLayer(TileMap &tileMap, byte *tiles) {
+	Graphics::Surface *surface = new Graphics::Surface();
+	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
+	surface->create(tileMap.w * TILE_WIDTH, tileMap.h * TILE_HEIGHT, pixelFormat16);
+
+	for(int y = 0; y < tileMap.h; y++) {
+		for(int x = 0; x < tileMap.w; x++) {
+			uint16 idx = READ_LE_UINT16(&tileMap.map[(y * tileMap.w + x) * 2]) + tileMap.tileIndexOffset;
+			debug("tileIdx: %d", idx);
+			drawTileToSurface(surface, tiles + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
+		}
+	}
+	return surface;
+}
+
+void Background::drawTileToSurface(Graphics::Surface *surface, byte *tile, uint32 x, uint32 y) {
+	byte *pixels = (byte *)surface->getPixels();
+	for(int ty = 0; ty < TILE_HEIGHT; ty++) {
+		for(int tx = 0; tx < TILE_WIDTH; tx++) {
+			uint32 cidx = *tile;
+			uint32 offset = (y + ty) * surface->pitch + (x + tx) * 2;
+			pixels[offset] = _palette[cidx * 2];
+			pixels[offset + 1] = _palette[cidx * 2 + 1];
+			tile++;
+		}
+	}
+}
+
+Common::Point Background::getPoint2(uint32 pointIndex) {
+	assert (pointIndex < 0x20);
+	return _points2[pointIndex];
+}
+
+uint16 Background::getWidth() {
+	assert (_bgLayer);
+	return _bgLayer->w;
+}
+
+uint16 Background::getHeight() {
+	assert (_bgLayer);
+	return _bgLayer->h;
+}
+
+BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
+		bigFileArchive), _dragonRMS(dragonRMS) {}
+
+Background *BackgroundResourceLoader::load(uint32 sceneId) {
+	char filename[] = "nnnn.scr";
+	memcpy(filename, _dragonRMS->getSceneName(sceneId), 4);
+	debug("Loading %s", filename);
+	uint32 size;
+	byte *scrData = _bigFileArchive->load(filename, size);
+	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(scrData, size, DisposeAfterUse::YES);
+	Background *bg = new Background();
+	bg->load(scrData, *readStream);
+	return bg;
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
new file mode 100644
index 0000000000..f61c523f9b
--- /dev/null
+++ b/engines/dragons/background.h
@@ -0,0 +1,81 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 SCUMMVM_BACKGROUND_H
+#define SCUMMVM_BACKGROUND_H
+
+#include "common/rect.h"
+#include "common/system.h"
+#include "bigfile.h"
+#include "dragonrms.h"
+
+namespace Dragons {
+class PriorityLayer;
+class Background;
+
+struct TileMap;
+
+class BackgroundResourceLoader {
+private:
+	BigfileArchive *_bigFileArchive;
+	DragonRMS *_dragonRMS;
+public:
+	BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS);
+	Background *load(uint32 sceneId);
+};
+
+class Background {
+private:
+	PriorityLayer *_priorityLayer;
+	byte _palette[512];
+	Graphics::Surface *_bgLayer;
+	Graphics::Surface *_mgLayer;
+	Graphics::Surface *_fgLayer;
+	Common::Point *_points1;
+	Common::Point *_points2;
+public:
+	Background() : _priorityLayer(0), _points1(0), _points2(0), _bgLayer(0), _fgLayer(0) {}
+	bool load(byte *dataStart, Common::SeekableReadStream &stream);
+	uint16 getWidth();
+	uint16 getHeight();
+	Graphics::Surface *getBgLayer() { return _bgLayer; }
+	Graphics::Surface *getMgLayer() { return _mgLayer; }
+	Graphics::Surface *getFgLayer() { return _fgLayer; }
+	Common::Point getPoint2(uint32 pointIndex);
+private:
+	Common::Point *loadPoints(Common::SeekableReadStream &stream);
+	Graphics::Surface *loadGfxLayer(TileMap &tileMap, byte *tiles);
+	void drawTileToSurface(Graphics::Surface *surface, byte *tile, uint32 x, uint32 y);
+};
+
+class PriorityLayer {
+public:
+	void load(TileMap &tileMap, byte *tiles);
+	int getPriority(Common::Point pos);
+protected:
+	int16 _width, _height;
+	int16 _mapWidth, _mapHeight;
+	byte *_map, *_values;
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_BACKGROUND_H
diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
index 45c2da26da..723158d7b6 100644
--- a/engines/dragons/bigfile.cpp
+++ b/engines/dragons/bigfile.cpp
@@ -21,6 +21,631 @@
  */
 #include "bigfile.h"
 
-namespace Illusions {
+namespace Dragons {
+typedef struct FileInfo {
+	const char filename[16];
+	uint32 offset;
+	uint32 size;
+} FileInfo;
+
+#define TOTAL_FILES 576
+//TODO add support for other game types. get data directly from DRAGON.EXE
+FileInfo fileInfo[TOTAL_FILES] = {
+		{"loadpic.tim", 0x0, 0x1F414},
+		{"fntfiles.dat", 0x1F800, 0x6E44},
+		{"tfont.map", 0x26800, 0xC6A},
+		{"tfont.chr", 0x27800, 0x16C0},
+		{"tfont1.map", 0x29000, 0xC6A},
+		{"tfont1.chr", 0x2A000, 0x16C0},
+		{"sfont.map", 0x2B800, 0xC6A},
+		{"sfont.chr", 0x2C800, 0x16C0},
+		{"boxfont.chr", 0x2E000, 0x4C0},
+		{"bag.scr", 0x2E800, 0xA2E4},
+		{"igfiles.dat", 0x39000, 0x29208},
+		{"dragon.flg", 0x62800, 0x24},
+		{"dragon.var", 0x63000, 0x1E},
+		{"dragon.ini", 0x63800, 0x6028},
+		{"dragon.img", 0x6A000, 0x441C},
+		{"dragon.opt", 0x6E800, 0x16A0},
+		{"dragon.ipt", 0x70000, 0x5D8},
+		{"dragon.rms", 0x70800, 0x63C},
+		{"dragon.obd", 0x71000, 0x1C9DC},
+		{"dragon.txt", 0x8E000, 0x4E8A4},
+		{"dragon.spt", 0xDD000, 0xD0},
+		{"musx.vh", 0xDD800, 0x2E20},
+		{"musx.vb", 0xE0800, 0x402A0},
+		{"glob.vh", 0x121000, 0xC20},
+		{"glob.vb", 0x122000, 0xBB90},
+		{"glob.vab", 0x12E000, 0xC7B0},
+		{"cursor.act", 0x13A800, 0x1863C},
+		{"invenicn.act", 0x153000, 0x3D3C},
+		{"shadow.act", 0x157000, 0x508},
+		{"flicker.act", 0x157800, 0x3CDF0},
+		{"flickert.act", 0x194800, 0x1A4A0},
+		{"flkg.act", 0x1AF000, 0x4D298},
+		{"flkspec.act", 0x1FC800, 0xE008},
+		{"credits.txt", 0x20B000, 0x249A},
+		{"titles.act", 0x20D800, 0x15214},
+		{"drag0000.txt", 0x223000, 0x1000},
+		{"drag0001.txt", 0x224000, 0x1000},
+		{"drag0002.txt", 0x225000, 0x1000},
+		{"drag0003.txt", 0x226000, 0x1000},
+		{"drag0004.txt", 0x227000, 0x1000},
+		{"drag0005.txt", 0x228000, 0x1000},
+		{"drag0006.txt", 0x229000, 0x1000},
+		{"drag0007.txt", 0x22A000, 0x1000},
+		{"drag0008.txt", 0x22B000, 0x1000},
+		{"drag0009.txt", 0x22C000, 0x1000},
+		{"drag0010.txt", 0x22D000, 0x1000},
+		{"drag0011.txt", 0x22E000, 0x1000},
+		{"drag0012.txt", 0x22F000, 0x1000},
+		{"drag0013.txt", 0x230000, 0x1000},
+		{"drag0014.txt", 0x231000, 0x1000},
+		{"drag0015.txt", 0x232000, 0x1000},
+		{"drag0016.txt", 0x233000, 0x1000},
+		{"drag0017.txt", 0x234000, 0x1000},
+		{"drag0018.txt", 0x235000, 0x1000},
+		{"drag0019.txt", 0x236000, 0x1000},
+		{"drag0020.txt", 0x237000, 0x1000},
+		{"drag0021.txt", 0x238000, 0x1000},
+		{"drag0022.txt", 0x239000, 0x1000},
+		{"drag0023.txt", 0x23A000, 0x1000},
+		{"drag0024.txt", 0x23B000, 0x1000},
+		{"drag0025.txt", 0x23C000, 0x1000},
+		{"drag0026.txt", 0x23D000, 0x1000},
+		{"drag0027.txt", 0x23E000, 0x1000},
+		{"drag0028.txt", 0x23F000, 0x1000},
+		{"drag0029.txt", 0x240000, 0x1000},
+		{"drag0030.txt", 0x241000, 0x1000},
+		{"drag0031.txt", 0x242000, 0x1000},
+		{"drag0032.txt", 0x243000, 0x1000},
+		{"drag0033.txt", 0x244000, 0x1000},
+		{"drag0034.txt", 0x245000, 0x1000},
+		{"drag0035.txt", 0x246000, 0x1000},
+		{"drag0036.txt", 0x247000, 0x1000},
+		{"drag0037.txt", 0x248000, 0x1000},
+		{"drag0038.txt", 0x249000, 0x1000},
+		{"drag0039.txt", 0x24A000, 0x1000},
+		{"drag0040.txt", 0x24B000, 0x1000},
+		{"drag0041.txt", 0x24C000, 0x1000},
+		{"drag0042.txt", 0x24D000, 0x1000},
+		{"drag0043.txt", 0x24E000, 0x1000},
+		{"drag0044.txt", 0x24F000, 0x1000},
+		{"drag0045.txt", 0x250000, 0x1000},
+		{"drag0046.txt", 0x251000, 0x1000},
+		{"drag0047.txt", 0x252000, 0x1000},
+		{"drag0048.txt", 0x253000, 0x1000},
+		{"drag0049.txt", 0x254000, 0x1000},
+		{"drag0050.txt", 0x255000, 0x1000},
+		{"drag0051.txt", 0x256000, 0x1000},
+		{"drag0052.txt", 0x257000, 0x1000},
+		{"drag0053.txt", 0x258000, 0x1000},
+		{"drag0054.txt", 0x259000, 0x1000},
+		{"drag0055.txt", 0x25A000, 0x1000},
+		{"drag0056.txt", 0x25B000, 0x1000},
+		{"drag0057.txt", 0x25C000, 0x1000},
+		{"drag0058.txt", 0x25D000, 0x1000},
+		{"drag0059.txt", 0x25E000, 0x1000},
+		{"drag0060.txt", 0x25F000, 0x1000},
+		{"drag0061.txt", 0x260000, 0x1000},
+		{"drag0062.txt", 0x261000, 0x1000},
+		{"drag0063.txt", 0x262000, 0x1000},
+		{"drag0064.txt", 0x263000, 0x1000},
+		{"drag0065.txt", 0x264000, 0x1000},
+		{"drag0066.txt", 0x265000, 0x1000},
+		{"drag0067.txt", 0x266000, 0x1000},
+		{"drag0068.txt", 0x267000, 0x1000},
+		{"drag0069.txt", 0x268000, 0x1000},
+		{"drag0070.txt", 0x269000, 0x1000},
+		{"drag0071.txt", 0x26A000, 0x1000},
+		{"drag0072.txt", 0x26B000, 0x1000},
+		{"drag0073.txt", 0x26C000, 0x1000},
+		{"drag0074.txt", 0x26D000, 0x1000},
+		{"drag0075.txt", 0x26E000, 0x1000},
+		{"drag0076.txt", 0x26F000, 0x1000},
+		{"drag0077.txt", 0x270000, 0x1000},
+		{"drag0078.txt", 0x271000, 0x1000},
+		{"drag0079.txt", 0x272000, 0x1000},
+		{"drag0080.txt", 0x273000, 0x1000},
+		{"dem1.msf", 0x274000, 0x128C0},
+		{"dem1.scr", 0x287000, 0x1934C},
+		{"dem11.act", 0x2A0800, 0x573FC},
+		{"dem1z15.msq", 0x2F8000, 0x3A03},
+		{"dem2.msf", 0x2FC000, 0x23C50},
+		{"dem2.scr", 0x320000, 0x160F4},
+		{"dem2z10.msq", 0x336800, 0x192B},
+		{"dem2z13.msq", 0x338800, 0x3D20},
+		{"demoz00.msq", 0x33C800, 0x1D7A},
+		{"demoz01.msq", 0x33E800, 0x136D},
+		{"demoz02.msq", 0x340000, 0x2F1D},
+		{"demoz03.msq", 0x343000, 0x246A},
+		{"demoz04.msq", 0x345800, 0xFA1},
+		{"demoz05.msq", 0x346800, 0x61C},
+		{"demoz06.msq", 0x347000, 0x3A4B},
+		{"demoz07.msq", 0x34B000, 0x3909},
+		{"demoz08.msq", 0x34F000, 0x25B8},
+		{"demoz09.msq", 0x351800, 0x673F},
+		{"demoz10.msq", 0x358000, 0x192B},
+		{"demoz11.msq", 0x35A000, 0x2A5A},
+		{"demoz12.msq", 0x35D000, 0xE7B},
+		{"demoz13.msq", 0x35E000, 0x3D20},
+		{"demoz14.msq", 0x362000, 0x1B9B},
+		{"demoz15.msq", 0x364000, 0x3A03},
+		{"demoz16.msq", 0x368000, 0x2B6B},
+		{"demoz17.msq", 0x36B000, 0x1D7A},
+		{"demoz18.msq", 0x36D000, 0x33FE},
+		{"demoz19.msq", 0x370800, 0x20D7},
+		{"demoz20.msq", 0x373000, 0x673F},
+		{"demoz21.msq", 0x379800, 0x2EA7},
+		{"demoz22.msq", 0x37C800, 0x286C},
+		{"demoz23.msq", 0x37F800, 0x246A},
+		{"demoz24.msq", 0x382000, 0x2463},
+		{"demoz25.msq", 0x384800, 0x245B},
+		{"demoz26.msq", 0x387000, 0x2AE},
+		{"demoz27.msq", 0x387800, 0xB6E},
+		{"demoz99.msq", 0x388800, 0x2EA7},
+		{"s00b.msf", 0x38B800, 0x1CD0},
+		{"s00b.scr", 0x38D800, 0xEF4},
+		{"s00b1.act", 0x38E800, 0x3DE24},
+		{"s00bz00.msq", 0x3CC800, 0x1D7A},
+		{"s00f.msf", 0x3CE800, 0x158D0},
+		{"s00f.scr", 0x3E4800, 0x138F4},
+		{"s00f1.act", 0x3F8800, 0x2CBB0},
+		{"s00f2.act", 0x425800, 0x16738},
+		{"s00f3.act", 0x43C000, 0x32C78},
+		{"s00f4.act", 0x46F000, 0xB78},
+		{"s00fz01.msq", 0x470000, 0x136D},
+		{"s00g.msf", 0x471800, 0x3840},
+		{"s00g.scr", 0x475800, 0x106F4},
+		{"s00g1.act", 0x486000, 0xAA50},
+		{"s00g2.act", 0x491000, 0x4DDC},
+		{"s00g3.act", 0x496000, 0x1944},
+		{"s00gz00.msq", 0x498000, 0x1D7A},
+		{"s00h.msf", 0x49A000, 0x4FB0},
+		{"s00h.scr", 0x49F000, 0x17AF4},
+		{"s00h1.act", 0x4B7000, 0x34D94},
+		{"s00h2.act", 0x4EC000, 0x1BF4C},
+		{"s00h3.act", 0x508000, 0xA92C},
+		{"s00h4.act", 0x513000, 0x3F58},
+		{"s00h5.act", 0x517000, 0xC850},
+		{"s00h6.act", 0x524000, 0x32174},
+		{"s00h7.act", 0x556800, 0x3BC4},
+		{"s00h8.act", 0x55A800, 0x2D78},
+		{"s00h9.act", 0x55D800, 0x28B0},
+		{"s00ha.act", 0x560800, 0x6F0},
+		{"s00hz10.msq", 0x561000, 0x192B},
+		{"s00i.msf", 0x563000, 0x4A20},
+		{"s00i.scr", 0x568000, 0x61EA0},
+		{"s00i1.act", 0x5CA000, 0x4708},
+		{"s00i2.act", 0x5CE800, 0x32B4},
+		{"s00i3.act", 0x5D2000, 0x2530},
+		{"s00i4.act", 0x5D4800, 0x222C},
+		{"s00iz06.msq", 0x5D7000, 0x3A4B},
+		{"s00j.msf", 0x5DB000, 0x1D2A0},
+		{"s00j.scr", 0x5F8800, 0x1934C},
+		{"s00j1.act", 0x612000, 0x50914},
+		{"s00j2.act", 0x663000, 0x43FCC},
+		{"s00jz15.msq", 0x6A7000, 0x3A03},
+		{"s00k.msf", 0x6AB000, 0x144F0},
+		{"s00k.scr", 0x6BF800, 0x200F4},
+		{"s00kz21.msq", 0x6E0000, 0x2EA7},
+		{"s00l.scr", 0x6E3000, 0xBDF4},
+		{"s00lz16.msq", 0x6EF000, 0x2B6B},
+		{"s00lz21.msq", 0x6F2000, 0x2EA7},
+		{"s01a.msf", 0x6F5000, 0x10590},
+		{"s01a.scr", 0x705800, 0x1B0F4},
+		{"s01a1.act", 0x721000, 0xFBF0},
+		{"s01a2.act", 0x731000, 0x591C},
+		{"s01az00.msq", 0x737000, 0x1D7A},
+		{"s01az08.msq", 0x739000, 0x25B8},
+		{"s01az17.msq", 0x73B800, 0x1D7A},
+		{"s01b.msf", 0x73D800, 0xCDF0},
+		{"s01b.scr", 0x74A800, 0x1DAF4},
+		{"s01b1.act", 0x768800, 0xAF78},
+		{"s01b2.act", 0x773800, 0xAA8},
+		{"s01bz00.msq", 0x774800, 0x1D7A},
+		{"s01c.msf", 0x776800, 0x7D70},
+		{"s01c.scr", 0x77E800, 0x1CCF4},
+		{"s01c1.act", 0x79B800, 0x76CBC},
+		{"s01c2.act", 0x812800, 0x4D0},
+		{"s01c3.act", 0x813000, 0xEE4},
+		{"s01cz01.msq", 0x814000, 0x136D},
+		{"s01d.msf", 0x815800, 0xE740},
+		{"s01d.scr", 0x824000, 0x5E0AC},
+		{"s01d1.act", 0x882800, 0x90A2C},
+		{"s01d2.act", 0x913800, 0x11AB4},
+		{"s01d3.act", 0x925800, 0x20FD8},
+		{"s01d4.act", 0x946800, 0x17D2C},
+		{"s01d5.act", 0x95E800, 0x1BAF4},
+		{"s01d7.act", 0x97A800, 0x6A974},
+		{"s01d8.act", 0x9E5800, 0x2852C},
+		{"s01d9.act", 0xA0E000, 0x958C},
+		{"s01d20.act", 0xA17800, 0x1B9D8},
+		{"s01d21.act", 0xA33800, 0x1D460},
+		{"s01d22.act", 0xA51000, 0x287C8},
+		{"s01d23.act", 0xA79800, 0x16734},
+		{"s01d24.act", 0xA90000, 0x138A8},
+		{"s01d25.act", 0xAA4000, 0x1A290},
+		{"s01da.act", 0xABE800, 0x702C},
+		{"s01dz00.msq", 0xAC6000, 0x1D7A},
+		{"s01dz17.msq", 0xAC8000, 0x1D7A},
+		{"s01e.scr", 0xACA000, 0x189F4},
+		{"s01e1.act", 0xAE3000, 0x7004},
+		{"s01ez00.msq", 0xAEA800, 0x1D7A},
+		{"s01f.msf", 0xAEC800, 0x11210},
+		{"s01f.scr", 0xAFE000, 0x195F4},
+		{"s01f1.act", 0xB17800, 0x33868},
+		{"s01f2.act", 0xB4B800, 0x734C},
+		{"s01fz00.msq", 0xB53000, 0x1D7A},
+		{"s01fz03.msq", 0xB55000, 0x246A},
+		{"s01fz06.msq", 0xB57800, 0x3A4B},
+		{"s01fz23.msq", 0xB5B800, 0x246A},
+		{"s01g.msf", 0xB5E000, 0x1E010},
+		{"s01g.scr", 0xB7C800, 0x1BBF4},
+		{"s01g1.act", 0xB98800, 0xD30},
+		{"s01g2.act", 0xB99800, 0x18794},
+		{"s01g3.act", 0xBB2000, 0x38FC},
+		{"s01g4.act", 0xBB6000, 0x39784},
+		{"s01g5.act", 0xBEF800, 0x20694},
+		{"s01g6.act", 0xC10000, 0x10A18},
+		{"s01g7.act", 0xC21000, 0x13AD4},
+		{"s01g8.act", 0xC35000, 0x1A750},
+		{"s01g9.act", 0xC4F800, 0x12958},
+		{"s01gz00.msq", 0xC62800, 0x1D7A},
+		{"s01gz01.msq", 0xC64800, 0x136D},
+		{"s01gz08.msq", 0xC66000, 0x25B8},
+		{"s01h.msf", 0xC68800, 0xFBF0},
+		{"s01h.scr", 0xC78800, 0x10CF4},
+		{"s01h1.act", 0xC89800, 0x5E5A8},
+		{"s01h2.act", 0xCE8000, 0x52FC0},
+		{"s01h3.act", 0xD3B000, 0x2CC68},
+		{"s01h4.act", 0xD68000, 0xC3CC},
+		{"s01h5.act", 0xD74800, 0x8D8},
+		{"s01h6.act", 0xD75800, 0x1A044},
+		{"s01hz00.msq", 0xD90000, 0x1D7A},
+		{"s01hz01.msq", 0xD92000, 0x136D},
+		{"s01i.msf", 0xD93800, 0x3840},
+		{"s01i.scr", 0xD97800, 0x25FDC},
+		{"s01i1.act", 0xDBD800, 0x19CF0},
+		{"s01i2.act", 0xDD7800, 0x514},
+		{"s01i3.act", 0xDD8000, 0x3BC8},
+		{"s01iz00.msq", 0xDDC000, 0x1D7A},
+		{"s01j.msf", 0xDDE000, 0xBBA0},
+		{"s01j.scr", 0xDEA000, 0x15BF4},
+		{"s01j0.act", 0xE00000, 0x245B8},
+		{"s01j1.act", 0xE24800, 0x8A34},
+		{"s01j2.act", 0xE2D800, 0x3C0A0},
+		{"s01j3.act", 0xE6A000, 0x2944},
+		{"s01jz00.msq", 0xE6D000, 0x1D7A},
+		{"s01k.msf", 0xE6F000, 0x12FA0},
+		{"s01k.scr", 0xE82000, 0x189F4},
+		{"s01k1.act", 0xE9B000, 0x4394},
+		{"s01k2.act", 0xE9F800, 0x75068},
+		{"s01k3.act", 0xF15000, 0x9A0},
+		{"s01kz00.msq", 0xF16000, 0x1D7A},
+		{"s01l.msf", 0xF18000, 0x9A70},
+		{"s01l.scr", 0xF22000, 0x12BF4},
+		{"s01l1.act", 0xF35000, 0x1CDC},
+		{"s01lz00.msq", 0xF37000, 0x1D7A},
+		{"s02a.msf", 0xF39000, 0x11240},
+		{"s02a.scr", 0xF4A800, 0x197F4},
+		{"s02a1.act", 0xF64000, 0x17110},
+		{"s02a2.act", 0xF7B800, 0x13EB4},
+		{"s02a3.act", 0xF8F800, 0x8D20},
+		{"s02a4.act", 0xF98800, 0x36F8},
+		{"s02a5.act", 0xF9C000, 0x22F58},
+		{"s02a6.act", 0xFBF000, 0xE3C},
+		{"s02az02.msq", 0xFC0000, 0x2F1D},
+		{"s02az11.msq", 0xFC3000, 0x2A5A},
+		{"s02b.msf", 0xFC6000, 0x170D0},
+		{"s02b.scr", 0xFDD800, 0x14EF4},
+		{"s02b1.act", 0xFF2800, 0x49F08},
+		{"s02b2.act", 0x103C800, 0xDE78},
+		{"s02b3.act", 0x104A800, 0x3768},
+		{"s02bz02.msq", 0x104E000, 0x2F1D},
+		{"s02bz11.msq", 0x1051000, 0x2A5A},
+		{"s02bz13.msq", 0x1054000, 0x3D20},
+		{"s02bz20.msq", 0x1058000, 0x673F},
+		{"s02c.msf", 0x105E800, 0x20240},
+		{"s02c.scr", 0x107F000, 0x277F4},
+		{"s02c1.act", 0x10A6800, 0x30448},
+		{"s02c2.act", 0x10D7000, 0x15828},
+		{"s02c3.act", 0x10ED000, 0x1708C},
+		{"s02c4.act", 0x1104800, 0x12D1C},
+		{"s02c5.act", 0x1117800, 0x39970},
+		{"s02c6.act", 0x1151800, 0x1B114},
+		{"s02c7.act", 0x116D000, 0x5F7C},
+		{"s02c8.act", 0x1173000, 0x82368},
+		{"s02c9.act", 0x11F5800, 0x3D02C},
+		{"s02c11.act", 0x1233000, 0x2A934},
+		{"s02c51.act", 0x125E000, 0x3004},
+		{"s02ca.act", 0x1261800, 0x7F0D0},
+		{"s02cb.act", 0x12E1000, 0x125A8},
+		{"s02cc.act", 0x12F3800, 0x4150},
+		{"s02cz11.msq", 0x12F8000, 0x2A5A},
+		{"s02cz12.msq", 0x12FB000, 0xE7B},
+		{"s02cz13.msq", 0x12FC000, 0x3D20},
+		{"s02cz20.msq", 0x1300000, 0x673F},
+		{"s02d.msf", 0x1306800, 0x21940},
+		{"s02d.scr", 0x1328800, 0x160F4},
+		{"s02d1.act", 0x133F000, 0x2E09C},
+		{"s02d2.act", 0x136D800, 0x26D74},
+		{"s02d3.act", 0x1394800, 0x14EA0},
+		{"s02d4.act", 0x13A9800, 0x2294},
+		{"s02d5.act", 0x13AC000, 0x4A48},
+		{"s02dz10.msq", 0x13B1000, 0x192B},
+		{"s02dz13.msq", 0x13B3000, 0x3D20},
+		{"s02e.msf", 0x13B7000, 0x5EB0},
+		{"s02e.scr", 0x13BD000, 0x107F4},
+		{"s02e1.act", 0x13CD800, 0x62BC8},
+		{"s02ez18.msq", 0x1430800, 0x33FE},
+		{"s03a.msf", 0x1434000, 0x12070},
+		{"s03a.scr", 0x1446800, 0x18BF4},
+		{"s03a1.act", 0x145F800, 0x49E0},
+		{"s03a2.act", 0x1464800, 0x3DF4},
+		{"s03a3.act", 0x1468800, 0x45774},
+		{"s03a4.act", 0x14AE000, 0x23D4},
+		{"s03a5.act", 0x14B0800, 0x13E64},
+		{"s03a6.act", 0x14C4800, 0x46BC},
+		{"s03az03.msq", 0x14C9000, 0x246A},
+		{"s03az06.msq", 0x14CB800, 0x3A4B},
+		{"s03az23.msq", 0x14CF800, 0x246A},
+		{"s04a.msf", 0x14D2000, 0x11D60},
+		{"s04a.scr", 0x14E4000, 0x12AF4},
+		{"s04a1.act", 0x14F7000, 0x2AC40},
+		{"s04a2.act", 0x1522000, 0x6544},
+		{"s04a3.act", 0x1528800, 0x46C8},
+		{"s04a4.act", 0x152D000, 0x2240},
+		{"s04az03.msq", 0x152F800, 0x246A},
+		{"s04az10.msq", 0x1532000, 0x192B},
+		{"s04az24.msq", 0x1534000, 0x2463},
+		{"s05a.msf", 0x1536800, 0x5D60},
+		{"s05a.scr", 0x153C800, 0x127F4},
+		{"s05a1.act", 0x154F000, 0x3E1CC},
+		{"s05az04.msq", 0x158D800, 0xFA1},
+		{"s05b.msf", 0x158E800, 0x28640},
+		{"s05b.scr", 0x15B7000, 0x2C3C4},
+		{"s05b0.act", 0x15E3800, 0x16474},
+		{"s05b1.act", 0x15FA000, 0x1F2F4},
+		{"s05b2.act", 0x1619800, 0x113E8},
+		{"s05b3.act", 0x162B000, 0x1D424},
+		{"s05b4.act", 0x1648800, 0x501C4},
+		{"s05b5.act", 0x1699000, 0x1F510},
+		{"s05b6.act", 0x16B8800, 0x8860},
+		{"s05bz05.msq", 0x16C1800, 0x61C},
+		{"s05bz06.msq", 0x16C2000, 0x3A4B},
+		{"s05bz07.msq", 0x16C6000, 0x3909},
+		{"s06a.msf", 0x16CA000, 0x1C750},
+		{"s06a.scr", 0x16E6800, 0x151F4},
+		{"s06a1.act", 0x16FC000, 0x24654},
+		{"s06a2.act", 0x1720800, 0x25D0},
+		{"s06az19.msq", 0x1723000, 0x20D7},
+		{"s06b.msf", 0x1725800, 0x1BF60},
+		{"s06b.scr", 0x1741800, 0x182F4},
+		{"s06b1.act", 0x175A000, 0x6CE68},
+		{"s06bz19.msq", 0x17C7000, 0x20D7},
+		{"s07a.msf", 0x17C9800, 0x15240},
+		{"s07a.scr", 0x17DF000, 0x1ACF4},
+		{"s07a1.act", 0x17FA000, 0xE5A0},
+		{"s07a2.act", 0x1808800, 0x425D0},
+		{"s07a3.act", 0x184B000, 0x18810},
+		{"s07az03.msq", 0x1864000, 0x246A},
+		{"s07az08.msq", 0x1866800, 0x25B8},
+		{"s07az25.msq", 0x1869000, 0x245B},
+		{"s07b.msf", 0x186B800, 0x14960},
+		{"s07b.scr", 0x1880800, 0x15CF4},
+		{"s07b1.act", 0x1896800, 0x419C8},
+		{"s07b2.act", 0x18D8800, 0x1A560},
+		{"s07b3.act", 0x18F3000, 0x76F4},
+		{"s07b4.act", 0x18FA800, 0x76C8},
+		{"s07bz03.msq", 0x1902000, 0x246A},
+		{"s07bz08.msq", 0x1904800, 0x25B8},
+		{"s07bz25.msq", 0x1907000, 0x245B},
+		{"s07c.scr", 0x1909800, 0x143F4},
+		{"s07c1.act", 0x191E000, 0xA25C},
+		{"s08a.msf", 0x1928800, 0xB9E0},
+		{"s08a.scr", 0x1934800, 0x322F4},
+		{"s08a1.act", 0x1967000, 0xA668},
+		{"s08a2.act", 0x1971800, 0x2C828},
+		{"s08a3.act", 0x199E800, 0x6CF0},
+		{"s08az03.msq", 0x19A5800, 0x246A},
+		{"s08az06.msq", 0x19A8000, 0x3A4B},
+		{"s08az23.msq", 0x19AC000, 0x246A},
+		{"s08b.scr", 0x19AE800, 0x399F4},
+		{"s08b1.act", 0x19E8800, 0x1F0A0},
+		{"s08bz03.msq", 0x1A08000, 0x246A},
+		{"s08bz06.msq", 0x1A0A800, 0x3A4B},
+		{"s08bz23.msq", 0x1A0E800, 0x246A},
+		{"s09a.msf", 0x1A11000, 0x14190},
+		{"s09a.scr", 0x1A25800, 0x1B4F4},
+		{"s09a1.act", 0x1A41000, 0x634B8},
+		{"s09az14.msq", 0x1AA4800, 0x1B9B},
+		{"s09b.msf", 0x1AA6800, 0x1F2E0},
+		{"s09b.scr", 0x1AC6000, 0x1B4F4},
+		{"s09b1.act", 0x1AE1800, 0x71B8},
+		{"s09b2.act", 0x1AE9000, 0x2299C},
+		{"s09b3.act", 0x1B0C000, 0x1B360},
+		{"s09b4.act", 0x1B27800, 0x14B64},
+		{"s09b5.act", 0x1B3C800, 0x5E4},
+		{"s09b6.act", 0x1B3D000, 0xAA78},
+		{"s09b7.act", 0x1B48000, 0x9B24},
+		{"s09bz14.msq", 0x1B52000, 0x1B9B},
+		{"s09bz15.msq", 0x1B54000, 0x3A03},
+		{"s09c.msf", 0x1B58000, 0x2D640},
+		{"s09c.scr", 0x1B85800, 0x200F4},
+		{"s09c1.act", 0x1BA6000, 0x10F68},
+		{"s09c2.act", 0x1BB7000, 0x25B1C},
+		{"s09c3.act", 0x1BDD000, 0x15DF0},
+		{"s09c4.act", 0x1BF3000, 0x11310},
+		{"s09c5.act", 0x1C04800, 0x14F8C},
+		{"s09c6.act", 0x1C19800, 0x3810},
+		{"s09cz16.msq", 0x1C1D800, 0x2B6B},
+		{"s09d.msf", 0x1C20800, 0xF2F0},
+		{"s09d.scr", 0x1C30000, 0x1C0F4},
+		{"s09d1.act", 0x1C4C800, 0x2FE78},
+		{"s09dz16.msq", 0x1C7C800, 0x2B6B},
+		{"s09e.msf", 0x1C7F800, 0xCBD0},
+		{"s09e.scr", 0x1C8C800, 0x152F4},
+		{"s09e1.act", 0x1CA2000, 0x32538},
+		{"s09e2.act", 0x1CD4800, 0xADE4},
+		{"s09ez16.msq", 0x1CDF800, 0x2B6B},
+		{"s09f.msf", 0x1CE2800, 0x29380},
+		{"s09f.scr", 0x1D0C000, 0x177F4},
+		{"s09f1.act", 0x1D23800, 0x13B84},
+		{"s09f2.act", 0x1D37800, 0x5106C},
+		{"s09f3.act", 0x1D89000, 0xBDB4},
+		{"s09fz16.msq", 0x1D95000, 0x2B6B},
+		{"s09h.msf", 0x1D98000, 0x20F20},
+		{"s09h.scr", 0x1DB9000, 0x1EDF4},
+		{"s09h1.act", 0x1DD8000, 0x11A80},
+		{"s09h2.act", 0x1DEA000, 0x23FC0},
+		{"s09h3.act", 0x1E0E000, 0x2CC88},
+		{"s09h4.act", 0x1E3B000, 0x54534},
+		{"s09h5.act", 0x1E8F800, 0x2BFF4},
+		{"s09hz16.msq", 0x1EBB800, 0x2B6B},
+		{"s09i.msf", 0x1EBE800, 0x3840},
+		{"s09i.scr", 0x1EC2800, 0x229C4},
+		{"s09i1.act", 0x1EE5800, 0x2DD38},
+		{"s09i2.act", 0x1F13800, 0x11A24},
+		{"s09i3.act", 0x1F25800, 0x2CCA8},
+		{"s09i4.act", 0x1F52800, 0x343C},
+		{"s09iz16.msq", 0x1F56000, 0x2B6B},
+		{"s10a.msf", 0x1F59000, 0x270F0},
+		{"s10a.scr", 0x1F80800, 0x406F4},
+		{"s10a1.act", 0x1FC1000, 0x1F82C},
+		{"s10a2.act", 0x1FE1000, 0x5D690},
+		{"s10a3.act", 0x203E800, 0x5E800},
+		{"s10a4.act", 0x209D000, 0xBAF8},
+		{"s10a5.act", 0x20A9000, 0x181C},
+		{"s10a6.act", 0x20AB000, 0x36404},
+		{"s10a7.act", 0x20E1800, 0x51C44},
+		{"s10az17.msq", 0x2133800, 0x1D7A},
+		{"s10az18.msq", 0x2135800, 0x33FE},
+		{"s10b.msf", 0x2139000, 0xD5E0},
+		{"s10b.scr", 0x2146800, 0x14DF4},
+		{"s10b1.act", 0x215B800, 0x27B20},
+		{"s10b2.act", 0x2183800, 0x2B900},
+		{"s10b3.act", 0x21AF800, 0x8D78},
+		{"s10b4.act", 0x21B8800, 0x1A78},
+		{"s10bz17.msq", 0x21BA800, 0x1D7A},
+		{"s10bz18.msq", 0x21BC800, 0x33FE},
+		{"s10d.msf", 0x21C0000, 0x16D20},
+		{"s10d.scr", 0x21D7000, 0x220F4},
+		{"s10d1.act", 0x21F9800, 0x4DFB8},
+		{"s11a.msf", 0x2247800, 0xD650},
+		{"s11a.scr", 0x2255000, 0x16CF4},
+		{"s11a1.act", 0x226C000, 0x13BB4},
+		{"s11a2.act", 0x2280000, 0x4794},
+		{"s11a3.act", 0x2284800, 0x186E0},
+		{"s11az03.msq", 0x229D000, 0x246A},
+		{"s11az17.msq", 0x229F800, 0x1D7A},
+		{"s12a.msf", 0x22A1800, 0x22B60},
+		{"s12a.scr", 0x22C4800, 0x21AAA},
+		{"s12a1.act", 0x22E6800, 0xFE24},
+		{"s12a2.act", 0x22F6800, 0x123D4},
+		{"s12a3.act", 0x2309000, 0x39510},
+		{"s12a4.act", 0x2342800, 0x48474},
+		{"s12a5.act", 0x238B000, 0x35D24},
+		{"s12a6.act", 0x23C1000, 0x12850},
+		{"s12az04.msq", 0x23D4000, 0xFA1},
+		{"s12az26.msq", 0x23D5000, 0x2AE},
+		{"s12b.msf", 0x23D5800, 0xA720},
+		{"s12b.scr", 0x23E0000, 0x117F4},
+		{"s12b1.act", 0x23F1800, 0x50C0},
+		{"s12b2.act", 0x23F7000, 0xAE2C},
+		{"s12b3.act", 0x2402000, 0x6A4},
+		{"s12c.scr", 0x2402800, 0x106F4},
+		{"s12c1.act", 0x2413000, 0xA21B4},
+		{"s13a.msf", 0x24B5800, 0x251A0},
+		{"s13a.scr", 0x24DB000, 0x117F4},
+		{"s13a0.act", 0x24EC800, 0x74C},
+		{"s13a1.act", 0x24ED000, 0x7784},
+		{"s13a2.act", 0x24F4800, 0x923A8},
+		{"s13a3.act", 0x2587000, 0x381F4},
+		{"s13a4.act", 0x25BF800, 0x6E140},
+		{"s13a5.act", 0x262E000, 0x4B18},
+		{"s13az20.msq", 0x2633000, 0x673F},
+		{"s13b.msf", 0x2639800, 0xAB70},
+		{"s13b.scr", 0x2644800, 0xEF4},
+		{"s13b1.act", 0x2645800, 0x7784},
+		{"s13b2.act", 0x264D000, 0x4FAB0},
+		{"s13bz20.msq", 0x269D000, 0x673F},
+		{"s14a.msf", 0x26A3800, 0xF310},
+		{"s14a.scr", 0x26B3000, 0x30A94},
+		{"s14a0.act", 0x26E4000, 0xD320},
+		{"s14a1.act", 0x26F1800, 0x13FC8},
+		{"s14a2.act", 0x2705800, 0xD5E30},
+		{"s14a3.act", 0x27DB800, 0x13274},
+		{"s14a5.act", 0x27EF000, 0x5A6A4},
+		{"s14a15.act", 0x2849800, 0x6D50},
+		{"s14a25.act", 0x2850800, 0x7B564},
+		{"s14az21.msq", 0x28CC000, 0x2EA7},
+		{"s14b.msf", 0x28CF000, 0x187E0},
+		{"s14b.scr", 0x28E7800, 0x106F4},
+		{"s14bz21.msq", 0x28F8000, 0x2EA7},
+		{"s14d.msf", 0x28FB000, 0xC0E0},
+		{"s14d.scr", 0x2907800, 0x23E34},
+		{"s14d1.act", 0x292B800, 0x2D11C},
+		{"s14dz10.msq", 0x2959000, 0x192B},
+		{"s14dz11.msq", 0x295B000, 0x2A5A},
+		{"s14e.msf", 0x295E000, 0x8600},
+		{"s14e.scr", 0x2966800, 0x106F4},
+		{"s14e1.act", 0x2977000, 0xAA00},
+		{"s14e2.act", 0x2982000, 0x1F848},
+		{"s14ez03.msq", 0x29A2000, 0x246A},
+		{"s14ez20.msq", 0x29A4800, 0x673F},
+		{"s14ez22.msq", 0x29AB000, 0x286C},
+		{"s14f.scr", 0x29AE000, 0x106F4},
+		{"s14f1.act", 0x29BE800, 0x27A2C},
+		{"s14fz22.msq", 0x29E6800, 0x286C},
+		{"s14fz27.msq", 0x29E9800, 0xB6E},
+		{"s14g.msf", 0x29EA800, 0x2500},
+		{"s14g.scr", 0x29ED000, 0x1C3C4},
+		{"s14g1.act", 0x2A09800, 0x140FC},
+		{"s14g2.act", 0x2A1E000, 0x943F8},
+		{"s14g3.act", 0x2AB2800, 0x1E9A8},
+		{"s14gz22.msq", 0x2AD1800, 0x286C},
+		{"s14h.scr", 0x2AD4800, 0x106F4},
+		{"s14hz22.msq", 0x2AE5000, 0x286C}
+};
+
+uint32 getResourceId(const char *filename) {
+	for(uint32 i=0; i < TOTAL_FILES; i++) {
+		if (scumm_stricmp(fileInfo[i].filename, filename) == 0) {
+			return i;
+		}
+	}
+
+	return TOTAL_FILES;
+}
+
+BigfileArchive::BigfileArchive(const char *filename, Common::Language language) :_fd(0), _language(language) {
+	_fd = new Common::File();
+	if (!_fd->open(filename))
+		error("BigfileArchive::BigfileArchive() Could not open %s", filename);
+}
+
+BigfileArchive::~BigfileArchive() {
+	_fd->close();
+	delete _fd;
+}
+
+byte *BigfileArchive::load(const char *filename, uint32 &dataSize) {
+	uint32 id = getResourceId(filename);
+	if (id >= TOTAL_FILES) {
+		error("Invalid resourceID");
+	}
+
+	dataSize = fileInfo[id].size;
+	_fd->seek(fileInfo[id].offset);
+	byte *buf = (byte *)malloc(dataSize);
+	if (!buf) {
+		error("Failed to malloc %d bytes for '%s'", dataSize, filename);
+	}
+	_fd->read(buf, dataSize);
+	return buf;
+}
+
+
 
 } // End of namespace Illusions
diff --git a/engines/dragons/bigfile.h b/engines/dragons/bigfile.h
index afe4511072..6b3208c053 100644
--- a/engines/dragons/bigfile.h
+++ b/engines/dragons/bigfile.h
@@ -22,10 +22,20 @@
 #ifndef SCUMMVM_BIGFILE_H
 #define SCUMMVM_BIGFILE_H
 
+#include "common/file.h"
+#include "common/language.h"
+
 namespace Dragons {
 
-class Bigfile {
+class BigfileArchive {
+private:
+	Common::Language _language;
+	Common::File *_fd;
+public:
+	BigfileArchive(const char *filename, Common::Language language);
+	virtual ~BigfileArchive();
 
+	byte *load(const char *filename, uint32 &dataSize);
 };
 
 } // End of namespace dragons
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
new file mode 100644
index 0000000000..1c486b0d45
--- /dev/null
+++ b/engines/dragons/dragonini.cpp
@@ -0,0 +1,70 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "common/memstream.h"
+#include "dragonini.h"
+
+namespace Dragons {
+
+#define DRAGON_INI_STRUCT_SIZE 0x22
+DragonINIResource::DragonINIResource(BigfileArchive *bigfileArchive) {
+	uint32 fileSize;
+	byte *data = bigfileArchive->load("dragon.ini", fileSize);
+	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(data, fileSize, DisposeAfterUse::YES);
+
+	_count = fileSize / DRAGON_INI_STRUCT_SIZE;
+
+	_dragonINI = new DragonINI[_count];
+
+	for(int i=0; i < _count; i++) {
+		_dragonINI[i].iptIndex_maybe = readStream->readSint16LE();
+		_dragonINI[i].field_2 = readStream->readSint16LE();
+		_dragonINI[i].actorResourceId = readStream->readSint16LE();
+		_dragonINI[i].frameIndexId_maybe = readStream->readSint16LE();
+		_dragonINI[i].field_8 = readStream->readSint16LE();
+		_dragonINI[i].actorId = readStream->readUint16LE();
+		_dragonINI[i].sceneId = readStream->readUint16LE();
+		_dragonINI[i].field_e = readStream->readSint16LE();
+		_dragonINI[i].field_10 = readStream->readUint16LE();
+		_dragonINI[i].field_12 = readStream->readSint16LE();
+		_dragonINI[i].field_14 = readStream->readSint16LE();
+		_dragonINI[i].x = readStream->readSint16LE();
+		_dragonINI[i].y = readStream->readSint16LE();
+		_dragonINI[i].field_1a_flags_maybe = readStream->readUint16LE();
+		_dragonINI[i].field_1c = readStream->readSint16LE();
+		_dragonINI[i].field_1e = readStream->readSint16LE();
+		_dragonINI[i].field_20_actor_field_14 = readStream->readUint16LE();
+	}
+
+	_flickerINI = &_dragonINI[0];
+}
+
+DragonINI *DragonINIResource::getRecord(uint16 index) {
+	assert (index < _count);
+
+	return &_dragonINI[index];
+}
+
+void DragonINIResource::setFlickerRecord(DragonINI *dragonINI) {
+	_flickerINI = dragonINI;
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
new file mode 100644
index 0000000000..b58a34bdf1
--- /dev/null
+++ b/engines/dragons/dragonini.h
@@ -0,0 +1,68 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef SCUMMVM_DRAGONINI_H
+#define SCUMMVM_DRAGONINI_H
+
+#include "common/system.h"
+#include "bigfile.h"
+
+namespace Dragons {
+
+struct DragonINI
+	{
+		int16 iptIndex_maybe;
+		int16 field_2;
+		int16 actorResourceId;
+		int16 frameIndexId_maybe;
+		int16 field_8;
+		uint16 actorId;
+		uint16 sceneId;
+		int16 field_e;
+		uint16 field_10;
+		int16 field_12;
+		int16 field_14;
+		int16 x;
+		int16 y;
+		uint16 field_1a_flags_maybe;
+		int16 field_1c;
+		int16 field_1e;
+		uint16 field_20_actor_field_14;
+	};
+
+class DragonINIResource {
+private:
+	DragonINI *_dragonINI;
+	uint16 _count;
+	DragonINI *_flickerINI;
+public:
+	DragonINIResource(BigfileArchive *bigfileArchive);
+	uint16 totalRecords() { return _count; }
+	DragonINI *getRecord(uint16 index);
+	void setFlickerRecord(DragonINI *dragonINI);
+	DragonINI *getFlickerRecord() {
+		return _flickerINI;
+	}
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_DRAGONINI_H
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
new file mode 100644
index 0000000000..2e35cfa3cd
--- /dev/null
+++ b/engines/dragons/dragonrms.cpp
@@ -0,0 +1,57 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include <common/memstream.h>
+#include "dragonrms.h"
+#include "bigfile.h"
+
+namespace Dragons {
+
+#define DRAGON_RMS_STRUCT_SIZE 0x1c
+
+DragonRMS::DragonRMS(BigfileArchive *bigfileArchive) {
+	uint32 fileSize;
+	byte *data = bigfileArchive->load("dragon.rms", fileSize);
+	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(data, fileSize, DisposeAfterUse::YES);
+
+	_count = fileSize / DRAGON_RMS_STRUCT_SIZE;
+
+	_rmsObjects = new RMS[_count];
+
+	for(int i=0; i < _count; i++) {
+		_rmsObjects[i]._field0 = readStream->readSint32LE();
+		readStream->read(_rmsObjects[i]._sceneName, 4);
+		_rmsObjects[i]._obdOffset = readStream->readSint32LE();
+		_rmsObjects[i]._fieldC = readStream->readSint32LE();
+		_rmsObjects[i]._field10ObdOffset = readStream->readSint32LE();
+		_rmsObjects[i]._inventoryBagPosition = readStream->readSint16LE();
+		_rmsObjects[i]._field16 = readStream->readSint32LE();
+		_rmsObjects[i]._field1a = readStream->readSint16LE();
+	}
+}
+
+char *DragonRMS::getSceneName(uint32 sceneId) {
+	if(sceneId > 1 && sceneId - 2 < _count) {
+		return _rmsObjects[sceneId - 2]._sceneName;
+	}
+	return NULL;
+}
+} // End of namespace Dragons
diff --git a/engines/dragons/dragonrms.h b/engines/dragons/dragonrms.h
new file mode 100644
index 0000000000..6c6458da07
--- /dev/null
+++ b/engines/dragons/dragonrms.h
@@ -0,0 +1,53 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef SCUMMVM_DRAGONRMS_H
+#define SCUMMVM_DRAGONRMS_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+struct RMS {
+	int32 _field0;
+	char _sceneName[4];
+	int32 _obdOffset;
+	int32 _fieldC;
+	int32 _field10ObdOffset;
+	int16 _inventoryBagPosition;
+	int32 _field16;
+	int16 _field1a;
+};
+
+class BigfileArchive;
+
+class DragonRMS {
+private:
+	int16 _count;
+	RMS *_rmsObjects;
+public:
+	DragonRMS(BigfileArchive *bigfileArchive);
+	char *getSceneName(uint32 sceneId);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_DRAGONRMS_H
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index f7490ebae8..0a5e9d8227 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -21,22 +21,61 @@
  */
 #include "engines/util.h"
 #include "graphics/thumbnail.h"
+#include "graphics/surface.h"
 #include "common/error.h"
+#include "bigfile.h"
+#include "dragonrms.h"
+#include "dragonini.h"
 #include "dragons.h"
+#include "scene.h"
+#include "screen.h"
 
 namespace Dragons {
 
 DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
-
+	_bigfileArchive = NULL;
+	_dragonRMS = NULL;
+	_backgroundResourceLoader = NULL;
+	_screen = NULL;
 }
 
 DragonsEngine::~DragonsEngine() {
 
 }
 
+void DragonsEngine::updateEvents() {
+	Common::Event event;
+	while (_eventMan->pollEvent(event)) {
+//		_input->processEvent(event);
+		switch (event.type) {
+			case Common::EVENT_QUIT:
+				quitGame();
+				break;
+			default:
+				break;
+		}
+	}
+}
 Common::Error DragonsEngine::run() {
-	Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0);
-	initGraphics(320, 240, &pixelFormat16);
+	_screen = new Screen();
+	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
+	_dragonRMS = new DragonRMS(_bigfileArchive);
+	_dragonINIResource = new DragonINIResource(_bigfileArchive);
+	_scene = new Scene(_screen, _bigfileArchive, _dragonRMS, _dragonINIResource);
+
+	_scene->loadScene(0x12, 0x1e);
+
+	_scene->draw();
+	_screen->updateScreen();
+	while (!shouldQuit()) {
+		updateEvents();
+	}
+
+	delete _backgroundResourceLoader;
+	delete _dragonRMS;
+	delete _bigfileArchive;
+	delete _screen;
+
 	debug("Ok");
 	return Common::kNoError;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 15ca6fa2ec..ae33a2ad85 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -24,6 +24,7 @@
 
 #include "gui/EventRecorder.h"
 #include "engines/engine.h"
+#include "background.h"
 
 namespace Dragons {
 
@@ -52,12 +53,26 @@ enum kReadSaveHeaderError {
 	kRSHEInvalidVersion = 2,
 	kRSHEIoError = 3
 };
+class BigfileArchive;
+class DragonRMS;
+class DragonINIResource;
+class Scene;
+class Screen;
 
 class DragonsEngine : public Engine {
+private:
+	Screen *_screen;
+	BigfileArchive *_bigfileArchive;
+	DragonRMS *_dragonRMS;
+	DragonINIResource *_dragonINIResource;
+	BackgroundResourceLoader *_backgroundResourceLoader;
+	Scene *_scene;
+
 public:
 	DragonsEngine(OSystem *syst);
 	~DragonsEngine();
 
+	void updateEvents();
 	virtual Common::Error run();
 
 	const char *getSavegameFilename(int num);
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 1688743b93..0cfcf8ab61 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -1,8 +1,14 @@
 MODULE := engines/dragons
  
 MODULE_OBJS := \
+    background.o \
+    bigfile.o \
 	detection.o \
-	dragons.o
+    dragonini.o \
+    dragonrms.o \
+	dragons.o \
+	scene.o \
+	screen.o
  
 MODULE_DIRS += \
 	engines/dragons
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
new file mode 100644
index 0000000000..dd77b00ca4
--- /dev/null
+++ b/engines/dragons/scene.cpp
@@ -0,0 +1,80 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "scene.h"
+
+#include "background.h"
+#include "dragonini.h"
+#include "screen.h"
+
+namespace Dragons {
+
+Scene::Scene(Screen *screen, BigfileArchive *bigfileArchive, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
+		: _screen(screen), _stage(0), _bigfileArchive(bigfileArchive), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
+	_backgroundLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
+}
+
+void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
+	_stage = _backgroundLoader->load(sceneId);
+
+	_camera = _stage->getPoint2(cameraPointId);
+
+	debug("Flicker: (%X, %X)", _camera.x, _camera.y);
+
+	if (_camera.x > 160) {
+		_camera.x -= 160;
+	} else {
+		_camera.x = 0;
+	}
+
+	if (_camera.y > 100) {
+		_camera.y -= 100;
+	} else {
+		_camera.y = 0;
+	}
+
+	if (_camera.x + 320 >= _stage->getWidth()) {
+		_camera.x = _stage->getWidth() - 320;
+	}
+
+	if (_camera.y + 200 >= _stage->getHeight()) {
+		_camera.y = _stage->getHeight() - 200;
+	}
+
+	debug("Camera: (%d, %d)", _camera.x, _camera.y);
+
+	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
+		DragonINI *ini = _dragonINIResource->getRecord(i);
+		if (ini->sceneId == sceneId && (ini->field_1a_flags_maybe & 1)) {
+			debug("Actor %d %d (%d, %d)", ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
+		}
+	}
+
+}
+
+void Scene::draw() {
+	Common::Rect rect(_camera.x, _camera.y, 320, 200);
+	_screen->copyRectToSurface(*_stage->getBgLayer(), 0, 0, rect);
+	_screen->copyRectToSurface(*_stage->getMgLayer(), 0, 0, rect);
+	_screen->copyRectToSurface(*_stage->getFgLayer(), 0, 0, rect);
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
new file mode 100644
index 0000000000..bc76eb313f
--- /dev/null
+++ b/engines/dragons/scene.h
@@ -0,0 +1,59 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 SCUMMVM_SCENE_H
+#define SCUMMVM_SCENE_H
+
+#include "common/rect.h"
+#include "common/system.h"
+
+namespace Dragons {
+
+class Background;
+class DragonRMS;
+class BackgroundResourceLoader;
+class DragonINIResource;
+class BigfileArchive;
+class Screen;
+
+class Scene {
+private:
+	Screen *_screen;
+	Background *_stage;
+	BigfileArchive *_bigfileArchive;
+	DragonRMS *_dragonRMS;
+	DragonINIResource *_dragonINIResource;
+	BackgroundResourceLoader *_backgroundLoader;
+
+	uint16 _currentSceneId;
+	Common::Point _camera;
+
+public:
+	Scene(Screen *screen, BigfileArchive *bigfileArchive, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
+
+	void loadScene(uint32 sceneId, uint32 cameraPointId);
+
+	void draw();
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_SCENE_H
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
new file mode 100644
index 0000000000..cbee4a670c
--- /dev/null
+++ b/engines/dragons/screen.cpp
@@ -0,0 +1,78 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "common/system.h"
+#include "common/rect.h"
+#include "engines/util.h"
+#include "screen.h"
+
+namespace Dragons {
+
+Screen::Screen() {
+	_pixelFormat = Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15);
+	initGraphics(320, 200, &_pixelFormat);
+	_backSurface = new Graphics::Surface();
+	_backSurface->create(320, 200, _pixelFormat);
+}
+
+void Screen::updateScreen() {
+	g_system->copyRectToScreen((byte*)_backSurface->getBasePtr(0, 0), _backSurface->pitch, 0, 0, _backSurface->w, _backSurface->h);
+	g_system->updateScreen();
+}
+
+Screen::~Screen() {
+	_backSurface->free();
+	delete _backSurface;
+}
+
+void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY) {
+	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, destX, destY, srcSurface.w, srcSurface.h);
+}
+
+void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect) {
+	copyRectToSurface(srcSurface.getBasePtr(srcRect.left, srcRect.top), srcSurface.pitch, destX, destY, srcRect.width(), srcRect.height());
+}
+
+void Screen::copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height) {
+	assert(buffer);
+
+	assert(destX >= 0 && destX < _backSurface->w);
+	assert(destY >= 0 && destY < _backSurface->h);
+	assert(height > 0 && destY + height <= _backSurface->h);
+	assert(width > 0 && destX + width <= _backSurface->w);
+
+	// Copy buffer data to internal buffer
+	const byte *src = (const byte *)buffer;
+	byte *dst = (byte *)_backSurface->getBasePtr(destX, destY);
+	for (int i = 0; i < height; i++) {
+		for (int j = 0; j < width; j++) {
+			if ((src[j * 2 + 1] & 0x80) == 0) {
+				// only copy opaque pixels
+				dst[j * 2] = src[j * 2];
+				dst[j * 2 + 1] = src[j * 2 + 1];
+			}
+		}
+		src += srcPitch;
+		dst += _backSurface->pitch;
+	}
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
new file mode 100644
index 0000000000..e21efdd941
--- /dev/null
+++ b/engines/dragons/screen.h
@@ -0,0 +1,48 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 SCUMMVM_SCREEN_H
+#define SCUMMVM_SCREEN_H
+
+#include "graphics/surface.h"
+#include "graphics/pixelformat.h"
+
+namespace Dragons {
+
+class Screen {
+private:
+	Graphics::PixelFormat _pixelFormat;
+	Graphics::Surface *_backSurface;
+public:
+	virtual ~Screen();
+
+	Screen();
+
+	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
+	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
+	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect);
+	void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height);
+	void updateScreen();
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_SCREEN_H


Commit: 09c507a9cd3e474276a59f15a12d38272929a0e0
    https://github.com/scummvm/scummvm/commit/09c507a9cd3e474276a59f15a12d38272929a0e0
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Adding actor class

Changed paths:
  A engines/dragons/actor.cpp
  A engines/dragons/actor.h
  A engines/dragons/actorfiles.h
  A engines/dragons/actorresource.cpp
  A engines/dragons/actorresource.h
    engines/dragons/background.h
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/scene.cpp
    engines/dragons/scene.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
new file mode 100644
index 0000000000..f0742c94fb
--- /dev/null
+++ b/engines/dragons/actor.cpp
@@ -0,0 +1,53 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include <common/debug.h>
+#include "actorresource.h"
+#include "actor.h"
+
+namespace Dragons {
+
+ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorResourceLoader(actorResourceLoader) {}
+
+Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16) {
+	debug("Load actor: resourceId: %d, SequenceId: %d, position: (%d,%d) field16: %d", resourceId, sequenceId, x, y, field16);
+	//ActorResource *resource = _actorResourceLoader->load(resourceId);
+	return new Actor(_actorResourceLoader, resourceId, x, y, sequenceId);
+}
+
+Actor::Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16 x, int16 y, uint16 sequenceID): _actorResourceLoader(actorResourceLoader), resourceID(resourceID), x_pos(x), y_pos(y), _sequenceID(sequenceID) {
+	frameIndex_maybe = 0;
+}
+
+Graphics::Surface *Actor::getCurrentFrame() {
+	ActorResource *resource = _actorResourceLoader->load(resourceID);
+	frame_vram_x = resource->getFrameHeader(frameIndex_maybe)->field_0;
+	frame_vram_y = resource->getFrameHeader(frameIndex_maybe)->field_2;
+	return resource->loadFrame(frameIndex_maybe);
+}
+
+void Actor::updateSequence(uint16 newSequenceID) {
+	_sequenceID = newSequenceID;
+	field_18_flags_maybe &= 0xfbf1;
+	field_18_flags_maybe |= 1;
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
new file mode 100644
index 0000000000..fb314bf5d4
--- /dev/null
+++ b/engines/dragons/actor.h
@@ -0,0 +1,86 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 SCUMMVM_ACTOR_H
+#define SCUMMVM_ACTOR_H
+
+#include "common/system.h"
+
+namespace Dragons {
+class Actor;
+class ActorResourceLoader;
+class ActorResource;
+
+class ActorManager {
+private:
+	ActorResourceLoader *_actorResourceLoader;
+public:
+	ActorManager(ActorResourceLoader *actorResourceLoader);
+
+public:
+	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16);
+};
+
+class Actor {
+public:
+	ActorResourceLoader *_actorResourceLoader;
+	uint16 actorFileDictionaryIndex;
+	uint16 resourceID;
+	int16 _seqCodeIp;
+	void* frame_pointer_maybe;
+	uint16 field_c;
+	int16 var_e;
+	uint16 frameIndex_maybe;
+	uint16 _sequenceID;
+	uint16 _sequenceID2;
+	uint16 field16;
+	uint16 field_18_flags_maybe;
+	int16 x_pos;
+	int16 y_pos;
+	uint16 target_x_pos;
+	uint16 target_y_pos;
+	uint32 field_24;
+	uint32 field_28;
+	uint32 field_2c;
+	uint32 field_30;
+	uint16 field_34[32];
+	uint16 field_74;
+	uint16 field_76;
+	uint16 field_78;
+	uint16 field_7a;
+	uint32 field_7c;
+	uint16 field_80;
+	uint16 frame_vram_x;
+	uint16 frame_vram_y;
+	uint16 frame_width;
+	uint16 frame_height;
+	uint16 frame_flags;
+	uint16 clut;
+public:
+
+	Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16 x, int16 y, uint16 sequenceID);
+	Graphics::Surface *getCurrentFrame();
+	void updateSequence(uint16 newSequenceID);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_ACTOR_H
diff --git a/engines/dragons/actorfiles.h b/engines/dragons/actorfiles.h
new file mode 100644
index 0000000000..0eabf70bad
--- /dev/null
+++ b/engines/dragons/actorfiles.h
@@ -0,0 +1,229 @@
+
+
+#ifndef SCUMMVM_ACTORFILES_H
+#define SCUMMVM_ACTORFILES_H
+
+#define DRAGONS_NUM_ACTOR_FILES 219
+
+const char actorResourceFiles[DRAGONS_NUM_ACTOR_FILES][13] = {
+		"cursor.act",
+		"invenicn.act",
+		"s01b1.act",
+		"s00f1.act",
+		"s01h4.act",
+		"s07b2.act",
+		"s01g6.act",
+		"s02d1.act",
+		"s02d4.act",
+		"s00h6.act",
+		"s00h8.act",
+		"s00h3.act",
+		"s03a3.act",
+		"s00h2.act",
+		"flicker.act",
+		"s00h4.act",
+		"s00h5.act",
+		"s00h1.act",
+		"s00h7.act",
+		"s00h9.act",
+		"s03a6.act",
+		"s00i1.act",
+		"s00i4.act",
+		"s00j2.act",
+		"s00j1.act",
+		"s00i2.act",
+		"s01h1.act",
+		"flkspec.act",
+		"s03a2.act",
+		"s03a1.act",
+		"s12a2.act",
+		"s12a1.act",
+		"s12a4.act",
+		"s01f1.act",
+		"s01l1.act",
+		"s02c4.act",
+		"s03a4.act",
+		"s12a3.act",
+		"s02d3.act",
+		"s00ha.act",
+		"s01j2.act",
+		"s01j1.act",
+		"s01j0.act",
+		"s07a1.act",
+		"s07a2.act",
+		"s02b1.act",
+		"s02b2.act",
+		"s06a1.act",
+		"s06a2.act",
+		"s12c1.act",
+		"s12b2.act",
+		"s04a1.act",
+		"s00i3.act",
+		"s04a2.act",
+		"s02a2.act",
+		"s09i1.act",
+		"s02a3.act",
+		"s02a1.act",
+		"s02a4.act",
+		"s02d2.act",
+		"s05a1.act",
+		"s02c3.act",
+		"s02c1.act",
+		"s02c2.act",
+		"s02c5.act",
+		"s02c8.act",
+		"s02a5.act",
+		"s02c9.act",
+		"s02c6.act",
+		"s02c51.act",
+		"s09i2.act",
+		"s00f2.act",
+		"s02ca.act",
+		"s02c11.act",
+		"s02c7.act",
+		"s11a1.act",
+		"s09b2.act",
+		"s09b3.act",
+		"s09b6.act",
+		"s09b7.act",
+		"s09b1.act",
+		"s09b4.act",
+		"shadow.act",
+		"s09e1.act",
+		"flkg.act",
+		"s01g4.act",
+		"s01g3.act",
+		"s01g2.act",
+		"s00f3.act",
+		"s01g7.act",
+		"s09h4.act",
+		"s09c3.act",
+		"s09c2.act",
+		"s09c1.act",
+		"s09c4.act",
+		"s00b1.act",
+		"s09b5.act",
+		"s01k2.act",
+		"s01k1.act",
+		"s10b1.act",
+		"s01c1.act",
+		"s01h5.act",
+		"s09a1.act",
+		"s13a4.act",
+		"s09f1.act",
+		"s08a1.act",
+		"s09f3.act",
+		"s08b1.act",
+		"s07b1.act",
+		"s09f2.act",
+		"s00f4.act",
+		"s06b1.act",
+		"s05b1.act",
+		"s05b2.act",
+		"s05b3.act",
+		"s05b4.act",
+		"s05b5.act",
+		"s10a3.act",
+		"s10a6.act",
+		"s10a2.act",
+		"s10a1.act",
+		"s10a5.act",
+		"s10a7.act",
+		"s10a4.act",
+		"s01d1.act",
+		"s01d2.act",
+		"s01d3.act",
+		"s12b1.act",
+		"s12b3.act",
+		"s01d4.act",
+		"s01d5.act",
+		"s13a1.act",
+		"s13a2.act",
+		"s13a0.act",
+		"s04a3.act",
+		"s13a3.act",
+		"s13a5.act",
+		"flickert.act",
+		"s01a1.act",
+		"s01d7.act",
+		"s01d8.act",
+		"s14e1.act",
+		"s14e2.act",
+		"s01d9.act",
+		"s07c1.act",
+		"s10b2.act",
+		"s01g1.act",
+		"s01g5.act",
+		"s01h2.act",
+		"s01h3.act",
+		"s01i1.act",
+		"s02b3.act",
+		"s03a5.act",
+		"s09i4.act",
+		"s09i3.act",
+		"s14a1.act",
+		"s14a2.act",
+		"s01k3.act",
+		"s01i2.act",
+		"s01b2.act",
+		"s01c2.act",
+		"s14a3.act",
+		"s01j3.act",
+		"s01f2.act",
+		"s01c3.act",
+		"s01i3.act",
+		"s01e1.act",
+		"s01h6.act",
+		"s07b3.act",
+		"s01a2.act",
+		"s01da.act",
+		"s02a6.act",
+		"s02d5.act",
+		"s07a3.act",
+		"s07b4.act",
+		"s09e2.act",
+		"s10b3.act",
+		"s10b4.act",
+		"s09c5.act",
+		"s09h5.act",
+		"s14d1.act",
+		"s02e1.act",
+		"s09d1.act",
+		"s14f1.act",
+		"s14g1.act",
+		"s14g2.act",
+		"s14g3.act",
+		"s10d1.act",
+		"s08a2.act",
+		"s09c6.act",
+		"s00g1.act",
+		"s00g2.act",
+		"s00g3.act",
+		"s04a4.act",
+		"s08a3.act",
+		"s11a2.act",
+		"s02cb.act",
+		"s11a3.act",
+		"s05b0.act",
+		"s14a5.act",
+		"s14a25.act",
+		"s14a0.act",
+		"s14a15.act",
+		"s05b6.act",
+		"s12a5.act",
+		"s12a6.act",
+		"s13b1.act",
+		"s13b2.act",
+		"s01g8.act",
+		"s01g9.act",
+		"s02cc.act",
+		"s01d20.act",
+		"s01d21.act",
+		"s01d22.act",
+		"s01d23.act",
+		"s01d24.act",
+		"s01d25.act",
+		"titles.act",
+		"dem11.act"
+};
+#endif //SCUMMVM_ACTORFILES_H
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
new file mode 100644
index 0000000000..7a79994696
--- /dev/null
+++ b/engines/dragons/actorresource.cpp
@@ -0,0 +1,156 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "common/debug.h"
+#include "common/memstream.h"
+#include "graphics/surface.h"
+#include "actorfiles.h"
+#include "bigfile.h"
+#include "actorresource.h"
+
+namespace Dragons {
+
+
+ActorResourceLoader::ActorResourceLoader(BigfileArchive *bigFileArchive) : _bigFileArchive(bigFileArchive) {
+
+}
+
+ActorResource *ActorResourceLoader::load(uint32 resourceId) {
+	assert (resourceId < DRAGONS_NUM_ACTOR_FILES);
+	ActorResource *actorResource = new ActorResource();
+	const char *filename = actorResourceFiles[resourceId];
+	uint32 size;
+	byte *scrData = _bigFileArchive->load(filename, size);
+	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(scrData, size, DisposeAfterUse::NO);
+
+	debug("Loading '%s'", filename);
+	actorResource->load(scrData, *readStream);
+	return actorResource;
+}
+
+bool ActorResource::load(byte *dataStart, Common::SeekableReadStream &stream) {
+	stream.seek(0x6);
+	uint16 sequenceOffset = stream.readUint16LE();
+	uint16 frameOffset = stream.readUint16LE();
+	uint16 paletteOffset = stream.readUint16LE();
+
+	stream.seek(paletteOffset);
+	stream.read(_palette, 512);
+	_palette[1] = 0x80; // set alpha (bit 15) on first palette entry.
+
+	stream.seek(frameOffset);
+
+	_framesCount = (paletteOffset - stream.readUint16LE()) / 0xe;
+
+	debug("Frame Count: %d", _framesCount);
+
+	_frames = new ActorFrame[_framesCount];
+	for (int i=0; i < _framesCount; i++) {
+		stream.seek(frameOffset + i * 2);
+
+		uint16 offset = stream.readUint16LE();
+		stream.seek(offset);
+		_frames[i].field_0 = stream.readSint16LE();
+		_frames[i].field_2 = stream.readSint16LE();
+		_frames[i].width = stream.readByte() * 2; //FIXME the original checks actor->frame_flags bit 0 here at 0x80018438
+		_frames[i].height = stream.readByte();
+		uint32 frameDataOffset = stream.readUint32LE();
+		_frames[i].frameDataOffset = &dataStart[frameDataOffset];
+		_frames[i].flags = stream.readUint16LE();
+		_frames[i].field_c = stream.readUint16LE();
+		debug("Frame[%d] field_0: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
+				i, _frames[i].field_0, _frames[i].field_2, _frames[i].width, _frames[i].height, frameDataOffset, _frames[i].flags, _frames[i].field_c);
+	}
+
+	return false;
+}
+
+void ActorResource::writePixelBlock(byte *pixels, byte *data) {
+	pixels[0] = _palette[data[0] * 2];
+	pixels[1] = _palette[data[0] * 2 + 1];
+	pixels[2] = _palette[data[1] * 2];
+	pixels[3] = _palette[data[1] * 2 + 1];
+	pixels[4] = _palette[data[2] * 2];
+	pixels[5] = _palette[data[2] * 2 + 1];
+	pixels[6] = _palette[data[3] * 2];
+	pixels[7] = _palette[data[3] *2 + 1];
+}
+
+Graphics::Surface *ActorResource::loadFrame(uint16 frameNumber) {
+	assert (frameNumber < _framesCount);
+
+	Graphics::Surface *surface = new Graphics::Surface();
+	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
+	surface->create(_frames[frameNumber].width, _frames[frameNumber].height, pixelFormat16);
+
+	byte *pixels = (byte *)surface->getPixels();
+
+	int32 blockSize = ((_frames[frameNumber].width / 2) * _frames[frameNumber].height * 2) / 4;
+
+	debug("Frame blockSize: %d width: %d height: %d", blockSize, _frames[frameNumber].width, _frames[frameNumber].height);
+
+	byte *data = _frames[frameNumber].frameDataOffset;
+
+	while(blockSize > 0) {
+		int32 size = READ_BE_INT32(data);
+		data += 4;
+		if (size >= 0) {
+			if (blockSize < size) {
+				size = blockSize;
+			}
+			blockSize -= size;
+
+			if (size != 0) {
+				for(int32 i = size; i != 0; i--) {
+					//TODO clean up this copy.
+					writePixelBlock(pixels, data);
+
+					data += 4;
+					pixels += 8;
+				}
+			}
+		} else {
+			size = size & 0x7fffffff;
+			if (blockSize < size) {
+				size = blockSize;
+			}
+			blockSize -= size;
+			if (size != 0) {
+				for(int32 i = size; i != 0; i--) {
+					//TODO write bytes to pixel data.
+					writePixelBlock(pixels, data);
+					pixels += 8;
+				}
+				data += 4;
+			}
+		}
+	}
+
+	return surface;
+}
+
+ActorFrame *ActorResource::getFrameHeader(uint16 frameNumber) {
+	assert (frameNumber < _framesCount);
+
+	return &_frames[frameNumber];
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
new file mode 100644
index 0000000000..5f088aabf1
--- /dev/null
+++ b/engines/dragons/actorresource.h
@@ -0,0 +1,68 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef SCUMMVM_ACTORRESOURCE_H
+#define SCUMMVM_ACTORRESOURCE_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class BigfileArchive;
+class ActorResource;
+
+struct ActorFrame {
+	int16 field_0;
+	int16 field_2;
+	uint8 width;
+	uint8 height;
+	byte *frameDataOffset;
+	uint16 flags;
+	uint16 field_c;
+};
+
+class ActorResourceLoader {
+private:
+	BigfileArchive *_bigFileArchive;
+
+public:
+	ActorResourceLoader(BigfileArchive *bigFileArchive);
+	ActorResource *load(uint32 resourceId);
+};
+
+class ActorResource {
+private:
+	byte *data;
+	ActorFrame *_frames;
+	uint16 _framesCount;
+	byte _palette[512];
+
+public:
+	bool load(byte *dataStart, Common::SeekableReadStream &stream);
+	Graphics::Surface *loadFrame(uint16 frameNumber);
+	ActorFrame *getFrameHeader(uint16 frameNumber);
+private:
+	void writePixelBlock(byte *pixels, byte *data);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_ACTORRESOURCE_H
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index f61c523f9b..6929a8faf6 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -60,6 +60,8 @@ public:
 	Graphics::Surface *getMgLayer() { return _mgLayer; }
 	Graphics::Surface *getFgLayer() { return _fgLayer; }
 	Common::Point getPoint2(uint32 pointIndex);
+	byte *getPalette() { return _palette; }
+
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
 	Graphics::Surface *loadGfxLayer(TileMap &tileMap, byte *tiles);
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index b58a34bdf1..e2fdc2f4e7 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -31,8 +31,8 @@ struct DragonINI
 	{
 		int16 iptIndex_maybe;
 		int16 field_2;
-		int16 actorResourceId;
-		int16 frameIndexId_maybe;
+		uint16 actorResourceId;
+		uint16 frameIndexId_maybe;
 		int16 field_8;
 		uint16 actorId;
 		uint16 sceneId;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 0a5e9d8227..3dedf29502 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -23,6 +23,8 @@
 #include "graphics/thumbnail.h"
 #include "graphics/surface.h"
 #include "common/error.h"
+#include "actor.h"
+#include "actorresource.h"
 #include "bigfile.h"
 #include "dragonrms.h"
 #include "dragonini.h"
@@ -61,7 +63,9 @@ Common::Error DragonsEngine::run() {
 	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
 	_dragonRMS = new DragonRMS(_bigfileArchive);
 	_dragonINIResource = new DragonINIResource(_bigfileArchive);
-	_scene = new Scene(_screen, _bigfileArchive, _dragonRMS, _dragonINIResource);
+	ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
+	ActorManager *actorManager = new ActorManager(actorResourceLoader);
+	_scene = new Scene(_screen, _bigfileArchive, actorManager, _dragonRMS, _dragonINIResource);
 
 	_scene->loadScene(0x12, 0x1e);
 
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index dd77b00ca4..ef27306a47 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -21,14 +21,15 @@
  */
 #include "scene.h"
 
+#include "actor.h"
 #include "background.h"
 #include "dragonini.h"
 #include "screen.h"
 
 namespace Dragons {
 
-Scene::Scene(Screen *screen, BigfileArchive *bigfileArchive, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
-		: _screen(screen), _stage(0), _bigfileArchive(bigfileArchive), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
+Scene::Scene(Screen *screen, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
+		: _screen(screen), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
 	_backgroundLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 }
 
@@ -64,7 +65,16 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		if (ini->sceneId == sceneId && (ini->field_1a_flags_maybe & 1)) {
-			debug("Actor %d %d (%d, %d)", ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
+			Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->frameIndexId_maybe, ini->x, ini->y, 0);
+			Graphics::Surface *s = actor->getCurrentFrame();
+			int x = ini->x - actor->frame_vram_x;
+			int y = ini->y - actor->frame_vram_y;
+			if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
+				debug("Actor %d %d (%d, %d)", ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
+				_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w,s->h));
+			}
+			_stage->getFgLayer()->drawLine(ini->x, ini->y, ini->x + 8, ini->y + 8, 0x7c00);
+			//break;
 		}
 	}
 
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index bc76eb313f..c4d3f24a1c 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -27,6 +27,7 @@
 
 namespace Dragons {
 
+class ActorManager;
 class Background;
 class DragonRMS;
 class BackgroundResourceLoader;
@@ -37,6 +38,7 @@ class Screen;
 class Scene {
 private:
 	Screen *_screen;
+	ActorManager *_actorManager;
 	Background *_stage;
 	BigfileArchive *_bigfileArchive;
 	DragonRMS *_dragonRMS;
@@ -47,7 +49,7 @@ private:
 	Common::Point _camera;
 
 public:
-	Scene(Screen *screen, BigfileArchive *bigfileArchive, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
+	Scene(Screen *screen, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
 
 	void loadScene(uint32 sceneId, uint32 cameraPointId);
 


Commit: bbf08a389a93de987fedaf4bde0314d6195f6766
    https://github.com/scummvm/scummvm/commit/bbf08a389a93de987fedaf4bde0314d6195f6766
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on actor loading

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/module.mk
    engines/dragons/scene.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index f0742c94fb..1f2cf405d4 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -30,11 +30,23 @@ ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorRes
 Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16) {
 	debug("Load actor: resourceId: %d, SequenceId: %d, position: (%d,%d) field16: %d", resourceId, sequenceId, x, y, field16);
 	//ActorResource *resource = _actorResourceLoader->load(resourceId);
-	return new Actor(_actorResourceLoader, resourceId, x, y, sequenceId);
+	Actor *actor = new Actor(_actorResourceLoader, resourceId, x, y, sequenceId);
+	return actor;
 }
 
-Actor::Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16 x, int16 y, uint16 sequenceID): _actorResourceLoader(actorResourceLoader), resourceID(resourceID), x_pos(x), y_pos(y), _sequenceID(sequenceID) {
+Actor::Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16 x, int16 y, uint32 sequenceID): _actorResourceLoader(actorResourceLoader), resourceID(resourceID), x_pos(x), y_pos(y) {
 	frameIndex_maybe = 0;
+	target_x_pos = x;
+	target_y_pos = y;
+	var_e = 0x100;
+	_sequenceID2 = 0;
+	flags = (0x40 | 4);
+	frame_width = 0;
+	frame_height = 0;
+	frame_flags = 4;
+	//TODO sub_80017010();
+
+	updateSequence((uint16)sequenceID);
 }
 
 Graphics::Surface *Actor::getCurrentFrame() {
@@ -46,8 +58,8 @@ Graphics::Surface *Actor::getCurrentFrame() {
 
 void Actor::updateSequence(uint16 newSequenceID) {
 	_sequenceID = newSequenceID;
-	field_18_flags_maybe &= 0xfbf1;
-	field_18_flags_maybe |= 1;
+	flags &= 0xfbf1;
+	flags |= 1;
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index fb314bf5d4..32697802c4 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -52,11 +52,11 @@ public:
 	uint16 _sequenceID;
 	uint16 _sequenceID2;
 	uint16 field16;
-	uint16 field_18_flags_maybe;
+	uint16 flags;
 	int16 x_pos;
 	int16 y_pos;
-	uint16 target_x_pos;
-	uint16 target_y_pos;
+	int16 target_x_pos;
+	int16 target_y_pos;
 	uint32 field_24;
 	uint32 field_28;
 	uint32 field_2c;
@@ -76,7 +76,7 @@ public:
 	uint16 clut;
 public:
 
-	Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16 x, int16 y, uint16 sequenceID);
+	Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16 x, int16 y, uint32 sequenceID);
 	Graphics::Surface *getCurrentFrame();
 	void updateSequence(uint16 newSequenceID);
 };
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 0cfcf8ab61..9b971fc39a 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -1,6 +1,8 @@
 MODULE := engines/dragons
  
 MODULE_OBJS := \
+    actor.o \
+    actorresource.o \
     background.o \
     bigfile.o \
 	detection.o \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index ef27306a47..88947e5ac1 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -66,6 +66,43 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		if (ini->sceneId == sceneId && (ini->field_1a_flags_maybe & 1)) {
 			Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->frameIndexId_maybe, ini->x, ini->y, 0);
+
+			if (ini->frameIndexId_maybe & 0x1000) {
+				actor->frame_flags |= 0x10;
+			} else {
+				if (ini->field_1a_flags_maybe & 0x2000) {
+					actor->frame_flags |= 0x20;
+				} else {
+					actor->frame_flags &= 0xffef;
+				}
+			}
+
+			actor->_sequenceID2 = ini->field_20_actor_field_14;
+
+			if (ini->field_1a_flags_maybe & 2) {
+				actor->flags |= 0x80;
+			} else {
+				actor->flags &= 0xfeff;
+			}
+
+			if (ini->field_1a_flags_maybe & 0x20) {
+				actor->flags |= 0x100;
+			} else {
+				actor->flags &= 0xfeff;
+			}
+
+			if (ini->field_1a_flags_maybe & 4) {
+				actor->flags |= 0x8000;
+			} else {
+				actor->flags &= 0x7fff;
+			}
+
+			if (ini->field_1a_flags_maybe & 0x100) {
+				actor->flags |= 0x4000;
+			} else {
+				actor->flags &= 0xbfff;
+			}
+
 			Graphics::Surface *s = actor->getCurrentFrame();
 			int x = ini->x - actor->frame_vram_x;
 			int y = ini->y - actor->frame_vram_y;


Commit: e7e8155baf36febf747fdd0ecdf8e7d48b16459a
    https://github.com/scummvm/scummvm/commit/e7e8155baf36febf747fdd0ecdf8e7d48b16459a
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on actor loading

Changed paths:
  A engines/dragons/sequenceopcodes.cpp
  A engines/dragons/sequenceopcodes.h
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/actorresource.cpp
    engines/dragons/background.cpp
    engines/dragons/dragonini.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/scene.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 1f2cf405d4..2a4442e88c 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -25,22 +25,76 @@
 
 namespace Dragons {
 
-ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorResourceLoader(actorResourceLoader) {}
+ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorResourceLoader(actorResourceLoader) {
+	for (uint16 i = 0; i < 64; i++) {
+		_actors.push_back(Actor(i));
+	}
+}
+
 
 Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16) {
-	debug("Load actor: resourceId: %d, SequenceId: %d, position: (%d,%d) field16: %d", resourceId, sequenceId, x, y, field16);
-	//ActorResource *resource = _actorResourceLoader->load(resourceId);
-	Actor *actor = new Actor(_actorResourceLoader, resourceId, x, y, sequenceId);
+	Actor *actor = loadActor(resourceId, sequenceId, x, y);
+	if(actor) {
+		actor->field16 = field16;
+	}
+	return actor;
+}
+
+Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y) {
+	debug("Load actor: resourceId: %d, SequenceId: %d, position: (%d,%d)", resourceId, sequenceId, x, y);
+	ActorResource *resource = _actorResourceLoader->load(resourceId);
+	//Actor *actor = new Actor(_actorResourceLoader->load(resourceId), x, y, sequenceId);
+	Actor *actor = findFreeActor((int16)resourceId);
+	if (actor) {
+		actor->init(resource, x, y, sequenceId);
+	} else {
+		//TODO run find by resource and remove from mem logic here. @0x800358c8
+		debug("Unable to find free actor slot!!");
+	}
 	return actor;
 }
 
-Actor::Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16 x, int16 y, uint32 sequenceID): _actorResourceLoader(actorResourceLoader), resourceID(resourceID), x_pos(x), y_pos(y) {
+Actor *ActorManager::findFreeActor(int16 resourceId) {
+	int i = 0;
+	for (ActorsIterator it = _actors.begin(); it != _actors.end() && i < 23; ++it, i++) {
+		Actor *actor = it;
+		if (!(actor->flags & Dragons::ACTOR_FLAG_40)) {
+			actor->resourceID = resourceId;
+			actor->field_7c = 0x100000;
+			return actor;
+		}
+	}
+	return NULL;
+}
+
+Actor::Actor(uint16 id) : _actorID(id) {
+	_actorResource = NULL;
+	resourceID = -1;
+	_seqCodeIp = 0;
+	frame_pointer_maybe = NULL;
+	field16 = 3;
+	x_pos = 160;
+	y_pos = 110;
+	target_x_pos = 0;
+	target_y_pos = 0;
+	field_7c = 0;
+	flags = 0;
+	frame_width = 0;
+	frame_height = 0;
+	frame_flags = 0;
+	clut = 0;
+}
+
+void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
+	_actorResource = resource;
+	x_pos = x;
+	y_pos = y;
 	frameIndex_maybe = 0;
 	target_x_pos = x;
 	target_y_pos = y;
 	var_e = 0x100;
 	_sequenceID2 = 0;
-	flags = (0x40 | 4);
+	flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
 	frame_width = 0;
 	frame_height = 0;
 	frame_flags = 4;
@@ -50,16 +104,15 @@ Actor::Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16
 }
 
 Graphics::Surface *Actor::getCurrentFrame() {
-	ActorResource *resource = _actorResourceLoader->load(resourceID);
-	frame_vram_x = resource->getFrameHeader(frameIndex_maybe)->field_0;
-	frame_vram_y = resource->getFrameHeader(frameIndex_maybe)->field_2;
-	return resource->loadFrame(frameIndex_maybe);
+	frame_vram_x = _actorResource->getFrameHeader(frameIndex_maybe)->field_0;
+	frame_vram_y = _actorResource->getFrameHeader(frameIndex_maybe)->field_2;
+	return _actorResource->loadFrame(frameIndex_maybe);
 }
 
 void Actor::updateSequence(uint16 newSequenceID) {
 	_sequenceID = newSequenceID;
 	flags &= 0xfbf1;
-	flags |= 1;
+	flags |= Dragons::ACTOR_FLAG_1;
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 32697802c4..83619517f7 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -29,21 +29,50 @@ class Actor;
 class ActorResourceLoader;
 class ActorResource;
 
+enum ActorFlags {
+	ACTOR_FLAG_1 = 1,
+	ACTOR_FLAG_2 = 2,
+	ACTOR_FLAG_4 = 4,
+	ACTOR_FLAG_8 = 8,
+	ACTOR_FLAG_10 = 0x10,
+	ACTOR_FLAG_20 = 0x20,
+	ACTOR_FLAG_40 = 0x40,
+	ACTOR_FLAG_80 = 0x80,
+	ACTOR_FLAG_100 = 0x100,
+	ACTOR_FLAG_200 = 0x200,
+	ACTOR_FLAG_400 = 0x400,
+	ACTOR_FLAG_800 = 0x800,
+	ACTOR_FLAG_1000 = 0x1000,
+	ACTOR_FLAG_2000 = 0x2000,
+	ACTOR_FLAG_4000 = 0x4000,
+	ACTOR_FLAG_8000 = 0x8000
+};
+
 class ActorManager {
+public:
+	typedef Common::Array<Actor> Actors;
+	typedef Actors::iterator ActorsIterator;
+
 private:
 	ActorResourceLoader *_actorResourceLoader;
+	Actors _actors;
 public:
 	ActorManager(ActorResourceLoader *actorResourceLoader);
 
 public:
+	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y);
 	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16);
+
+private:
+	Actor *findFreeActor(int16 resourceID);
 };
 
 class Actor {
 public:
-	ActorResourceLoader *_actorResourceLoader;
+	uint16 _actorID;
+	ActorResource*_actorResource;
 	uint16 actorFileDictionaryIndex;
-	uint16 resourceID;
+	int16 resourceID;
 	int16 _seqCodeIp;
 	void* frame_pointer_maybe;
 	uint16 field_c;
@@ -76,7 +105,8 @@ public:
 	uint16 clut;
 public:
 
-	Actor(ActorResourceLoader *actorResourceLoader, uint32 resourceID, int16 x, int16 y, uint32 sequenceID);
+	Actor(uint16 id);
+	void init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID);
 	Graphics::Surface *getCurrentFrame();
 	void updateSequence(uint16 newSequenceID);
 };
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 7a79994696..9da45af0e7 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -76,8 +76,8 @@ bool ActorResource::load(byte *dataStart, Common::SeekableReadStream &stream) {
 		_frames[i].frameDataOffset = &dataStart[frameDataOffset];
 		_frames[i].flags = stream.readUint16LE();
 		_frames[i].field_c = stream.readUint16LE();
-		debug("Frame[%d] field_0: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
-				i, _frames[i].field_0, _frames[i].field_2, _frames[i].width, _frames[i].height, frameDataOffset, _frames[i].flags, _frames[i].field_c);
+//		debug("Frame[%d] field_0: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
+//				i, _frames[i].field_0, _frames[i].field_2, _frames[i].width, _frames[i].height, frameDataOffset, _frames[i].flags, _frames[i].field_c);
 	}
 
 	return false;
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index a91767f9cb..ab2b6ea177 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -118,7 +118,7 @@ Graphics::Surface *Background::loadGfxLayer(TileMap &tileMap, byte *tiles) {
 	for(int y = 0; y < tileMap.h; y++) {
 		for(int x = 0; x < tileMap.w; x++) {
 			uint16 idx = READ_LE_UINT16(&tileMap.map[(y * tileMap.w + x) * 2]) + tileMap.tileIndexOffset;
-			debug("tileIdx: %d", idx);
+			//debug("tileIdx: %d", idx);
 			drawTileToSurface(surface, tiles + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
 		}
 	}
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index 1c486b0d45..07a95db3e6 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
+#include <common/debug.h>
 #include "common/memstream.h"
 #include "dragonini.h"
 
@@ -40,7 +41,8 @@ DragonINIResource::DragonINIResource(BigfileArchive *bigfileArchive) {
 		_dragonINI[i].actorResourceId = readStream->readSint16LE();
 		_dragonINI[i].frameIndexId_maybe = readStream->readSint16LE();
 		_dragonINI[i].field_8 = readStream->readSint16LE();
-		_dragonINI[i].actorId = readStream->readUint16LE();
+		readStream->readUint16LE(); // actorId
+		_dragonINI[i].actor = NULL;
 		_dragonINI[i].sceneId = readStream->readUint16LE();
 		_dragonINI[i].field_e = readStream->readSint16LE();
 		_dragonINI[i].field_10 = readStream->readUint16LE();
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index e2fdc2f4e7..c9062bed8f 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -27,6 +27,8 @@
 
 namespace Dragons {
 
+class Actor;
+
 struct DragonINI
 	{
 		int16 iptIndex_maybe;
@@ -34,7 +36,7 @@ struct DragonINI
 		uint16 actorResourceId;
 		uint16 frameIndexId_maybe;
 		int16 field_8;
-		uint16 actorId;
+		Actor *actor;
 		uint16 sceneId;
 		int16 field_e;
 		uint16 field_10;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 3dedf29502..48712878f0 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -34,11 +34,15 @@
 
 namespace Dragons {
 
+#define DRAGONS_TICK_INTERVAL 17
+
 DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_bigfileArchive = NULL;
 	_dragonRMS = NULL;
 	_backgroundResourceLoader = NULL;
 	_screen = NULL;
+	_nextUpdatetime = 0;
+	_flags = 0;
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -71,9 +75,8 @@ Common::Error DragonsEngine::run() {
 
 	_scene->draw();
 	_screen->updateScreen();
-	while (!shouldQuit()) {
-		updateEvents();
-	}
+
+	gameLoop();
 
 	delete _backgroundResourceLoader;
 	delete _dragonRMS;
@@ -84,6 +87,17 @@ Common::Error DragonsEngine::run() {
 	return Common::kNoError;
 }
 
+void DragonsEngine::gameLoop() {
+	while (!shouldQuit()) {
+		updateEvents();
+		wait();
+	}
+}
+
+void DragonsEngine::updateHandler() {
+
+}
+
 const char *DragonsEngine::getSavegameFilename(int num) {
 	static Common::String filename;
 	filename = getSavegameFilename(_targetName, num);
@@ -122,4 +136,22 @@ kReadSaveHeaderError DragonsEngine::readSaveHeader(Common::SeekableReadStream *i
 	return ((in->eos() || in->err()) ? kRSHEIoError : kRSHENoError);
 }
 
+uint32 DragonsEngine::calulateTimeLeft() {
+	uint32 now;
+
+	now = _system->getMillis();
+
+	if ( _nextUpdatetime <= now ) {
+		_nextUpdatetime = now + DRAGONS_TICK_INTERVAL;
+		return(0);
+	}
+	uint32 delay = _nextUpdatetime - now;
+	_nextUpdatetime += DRAGONS_TICK_INTERVAL;
+	return(delay);
+}
+
+void DragonsEngine::wait() {
+	_system->delayMillis(calulateTimeLeft());
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index ae33a2ad85..6ff788eafc 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -67,6 +67,8 @@ private:
 	DragonINIResource *_dragonINIResource;
 	BackgroundResourceLoader *_backgroundResourceLoader;
 	Scene *_scene;
+	uint32 _nextUpdatetime;
+	uint32 _flags;
 
 public:
 	DragonsEngine(OSystem *syst);
@@ -78,6 +80,11 @@ public:
 	const char *getSavegameFilename(int num);
 	static Common::String getSavegameFilename(const Common::String &target, int num);
 	static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
+private:
+	void gameLoop();
+	void updateHandler();
+	uint32 calulateTimeLeft();
+	void wait();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 9b971fc39a..21d08f9ec8 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -10,8 +10,9 @@ MODULE_OBJS := \
     dragonrms.o \
 	dragons.o \
 	scene.o \
-	screen.o
- 
+	screen.o \
+	sequenceopcodes.o
+
 MODULE_DIRS += \
 	engines/dragons
  
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 88947e5ac1..9f5b2d6232 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -67,48 +67,51 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 		if (ini->sceneId == sceneId && (ini->field_1a_flags_maybe & 1)) {
 			Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->frameIndexId_maybe, ini->x, ini->y, 0);
 
-			if (ini->frameIndexId_maybe & 0x1000) {
-				actor->frame_flags |= 0x10;
-			} else {
-				if (ini->field_1a_flags_maybe & 0x2000) {
-					actor->frame_flags |= 0x20;
+			if (actor) {
+				ini->actor = actor;
+				if (ini->frameIndexId_maybe & 0x1000) {
+					actor->frame_flags |= 0x10;
 				} else {
-					actor->frame_flags &= 0xffef;
+					if (ini->field_1a_flags_maybe & 0x2000) {
+						actor->frame_flags |= 0x20;
+					} else {
+						actor->frame_flags &= 0xffef;
+					}
 				}
-			}
 
-			actor->_sequenceID2 = ini->field_20_actor_field_14;
+				actor->_sequenceID2 = ini->field_20_actor_field_14;
 
-			if (ini->field_1a_flags_maybe & 2) {
-				actor->flags |= 0x80;
-			} else {
-				actor->flags &= 0xfeff;
-			}
+				if (ini->field_1a_flags_maybe & 2) {
+					actor->flags |= Dragons::ACTOR_FLAG_80;
+				} else {
+					actor->flags &= 0xfeff;
+				}
 
-			if (ini->field_1a_flags_maybe & 0x20) {
-				actor->flags |= 0x100;
-			} else {
-				actor->flags &= 0xfeff;
-			}
+				if (ini->field_1a_flags_maybe & 0x20) {
+					actor->flags |= Dragons::ACTOR_FLAG_100;
+				} else {
+					actor->flags &= 0xfeff;
+				}
 
-			if (ini->field_1a_flags_maybe & 4) {
-				actor->flags |= 0x8000;
-			} else {
-				actor->flags &= 0x7fff;
-			}
+				if (ini->field_1a_flags_maybe & 4) {
+					actor->flags |= Dragons::ACTOR_FLAG_8000;
+				} else {
+					actor->flags &= 0x7fff;
+				}
 
-			if (ini->field_1a_flags_maybe & 0x100) {
-				actor->flags |= 0x4000;
-			} else {
-				actor->flags &= 0xbfff;
-			}
+				if (ini->field_1a_flags_maybe & 0x100) {
+					actor->flags |= Dragons::ACTOR_FLAG_4000;
+				} else {
+					actor->flags &= 0xbfff;
+				}
 
-			Graphics::Surface *s = actor->getCurrentFrame();
-			int x = ini->x - actor->frame_vram_x;
-			int y = ini->y - actor->frame_vram_y;
-			if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
-				debug("Actor %d %d (%d, %d)", ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
-				_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w,s->h));
+				Graphics::Surface *s = actor->getCurrentFrame();
+				int x = ini->x - actor->frame_vram_x;
+				int y = ini->y - actor->frame_vram_y;
+				if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
+					debug("Actor %d %d (%d, %d)", ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
+					_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
+				}
 			}
 			_stage->getFgLayer()->drawLine(ini->x, ini->y, ini->x + 8, ini->y + 8, 0x7c00);
 			//break;
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
new file mode 100644
index 0000000000..6c4d0818e4
--- /dev/null
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -0,0 +1,109 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "dragons/dragons.h"
+#include "dragons/sequenceopcodes.h"
+#include "dragons/actor.h"
+
+namespace Dragons {
+// OpCall
+
+void OpCall::skip(uint size) {
+	_code += size;
+}
+
+byte OpCall::readByte() {
+	return *_code++;
+}
+
+int16 OpCall::readSint16() {
+	int16 value = READ_LE_UINT16(_code);
+	_code += 2;
+	return value;
+}
+
+uint32 OpCall::readUint32() {
+	uint32 value = READ_LE_UINT32(_code);
+	_code += 4;
+	return value;
+}
+
+// SequenceOpcodes
+
+SequenceOpcodes::SequenceOpcodes(DragonsEngine *vm)
+	: _vm(vm) {
+	initOpcodes();
+}
+
+SequenceOpcodes::~SequenceOpcodes() {
+	freeOpcodes();
+}
+
+void SequenceOpcodes::execOpcode(Actor *control, OpCall &opCall) {
+	if (!_opcodes[opCall._op])
+		error("SequenceOpcodes::execOpcode() Unimplemented opcode %d", opCall._op);
+	debug(3, "execSequenceOpcode(%d) %s", opCall._op, _opcodeNames[opCall._op].c_str());
+	(*_opcodes[opCall._op])(control, opCall);
+}
+
+typedef Common::Functor2Mem<Actor*, OpCall&, void, SequenceOpcodes> SequenceOpcodeI;
+#define OPCODE(op, func) \
+	_opcodes[op] = new SequenceOpcodeI(this, &SequenceOpcodes::func); \
+	_opcodeNames[op] = #func;
+
+void SequenceOpcodes::initOpcodes() {
+	// First clear everything
+	for (uint i = 0; i < DRAGONS_NUM_SEQ_OPCODES; ++i) {
+		_opcodes[i] = 0;
+	}
+	// Register opcodes
+	OPCODE(1, opSetFramePointer);
+
+}
+
+#undef OPCODE
+
+void SequenceOpcodes::freeOpcodes() {
+	for (uint i = 0; i < DRAGONS_NUM_SEQ_OPCODES; ++i) {
+		delete _opcodes[i];
+	}
+}
+
+// Opcodes
+
+void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
+	ARG_INT16(framePointer);
+	//TODO update frame pointer
+	actor->flags |= Dragons::ACTOR_FLAG_2;
+	actor->frameIndex_maybe = actor->field_c;
+}
+
+//void SequenceOpcodes::opYield(Control *control, OpCall &opCall) {
+//	opCall._result = 2;
+//}
+//
+//void SequenceOpcodes::opStopSubSequence(Control *control, OpCall &opCall) {
+//	ARG_INT16(linkIndex);
+//	control->stopSubSequence(linkIndex);
+//}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/sequenceopcodes.h b/engines/dragons/sequenceopcodes.h
new file mode 100644
index 0000000000..ef3a4391eb
--- /dev/null
+++ b/engines/dragons/sequenceopcodes.h
@@ -0,0 +1,75 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef DRAGONS_SEQUENCEOPCODES_H
+#define DRAGONS_SEQUENCEOPCODES_H
+
+#include "common/func.h"
+#include "common/str.h"
+
+
+namespace Dragons {
+
+#define DRAGONS_NUM_SEQ_OPCODES 22
+class DragonsEngine;
+class Actor;
+
+struct OpCall {
+	byte _op;
+	byte _opSize;
+	int16 _deltaOfs;
+	byte *_code;
+	int _result;
+	void skip(uint size);
+	byte readByte();
+	int16 readSint16();
+	uint32 readUint32();
+};
+
+// Convenience macros
+#define ARG_SKIP(x) opCall.skip(x);
+#define ARG_BYTE(name) byte name = opCall.readByte(); debug(5, "ARG_BYTE(" #name " = %d)", name);
+#define ARG_INT16(name) int16 name = opCall.readSint16(); debug(5, "ARG_INT16(" #name " = %d)", name);
+#define ARG_UINT32(name) uint32 name = opCall.readUint32(); debug(5, "ARG_UINT32(" #name " = %08X)", name);
+
+typedef Common::Functor2<Actor*, OpCall&, void> SequenceOpcode;
+
+class SequenceOpcodes {
+public:
+	SequenceOpcodes(DragonsEngine *vm);
+	~SequenceOpcodes();
+	void execOpcode(Actor *actor, OpCall &opCall);
+protected:
+	DragonsEngine *_vm;
+	SequenceOpcode *_opcodes[DRAGONS_NUM_SEQ_OPCODES];
+	Common::String _opcodeNames[DRAGONS_NUM_SEQ_OPCODES];
+	void initOpcodes();
+	void freeOpcodes();
+
+	// Opcodes
+	void opSetFramePointer(Actor *actor, OpCall &opCall);
+
+};
+
+} // End of namespace Dragons
+
+#endif // DRAGONS_SEQUENCEOPCODES_H


Commit: ac1f5a5984bb9603dbf9bb75b2efd555b3c2499e
    https://github.com/scummvm/scummvm/commit/ac1f5a5984bb9603dbf9bb75b2efd555b3c2499e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on actor sequences

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 2a4442e88c..1768817c5a 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -67,6 +67,11 @@ Actor *ActorManager::findFreeActor(int16 resourceId) {
 	return NULL;
 }
 
+Actor *ActorManager::getActor(uint16 actorId) {
+	assert(actorId < 64);
+	return &_actors[actorId];
+}
+
 Actor::Actor(uint16 id) : _actorID(id) {
 	_actorResource = NULL;
 	resourceID = -1;
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 83619517f7..80066ce234 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -62,7 +62,7 @@ public:
 public:
 	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y);
 	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16);
-
+	Actor *getActor(uint16 actorId);
 private:
 	Actor *findFreeActor(int16 resourceID);
 };
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 48712878f0..f2071641ea 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -68,8 +68,9 @@ Common::Error DragonsEngine::run() {
 	_dragonRMS = new DragonRMS(_bigfileArchive);
 	_dragonINIResource = new DragonINIResource(_bigfileArchive);
 	ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
-	ActorManager *actorManager = new ActorManager(actorResourceLoader);
-	_scene = new Scene(_screen, _bigfileArchive, actorManager, _dragonRMS, _dragonINIResource);
+	_actorManager = new ActorManager(actorResourceLoader);
+	_scene = new Scene(_screen, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
+	_flags = 0x1046;
 
 	_scene->loadScene(0x12, 0x1e);
 
@@ -78,6 +79,8 @@ Common::Error DragonsEngine::run() {
 
 	gameLoop();
 
+	delete _scene;
+	delete _actorManager;
 	delete _backgroundResourceLoader;
 	delete _dragonRMS;
 	delete _bigfileArchive;
@@ -89,13 +92,14 @@ Common::Error DragonsEngine::run() {
 
 void DragonsEngine::gameLoop() {
 	while (!shouldQuit()) {
+		updateHandler();
 		updateEvents();
 		wait();
 	}
 }
 
 void DragonsEngine::updateHandler() {
-
+	updateActorSequences();
 }
 
 const char *DragonsEngine::getSavegameFilename(int num) {
@@ -154,4 +158,31 @@ void DragonsEngine::wait() {
 	_system->delayMillis(calulateTimeLeft());
 }
 
+void DragonsEngine::updateActorSequences() {
+	if (!(_flags & Dragons::ENGINE_FLAG_4)) {
+		return;
+	}
+
+	//TODO ResetRCnt(0xf2000001);
+
+	int16 actorId = _flags & Dragons::ENGINE_FLAG_80 ? (int16)64 : (int16)23;
+
+	while (actorId >= 0) {
+		actorId--;
+		Actor *actor = _actorManager->getActor((uint16)actorId);
+		if (actorId < 2 && _flags & Dragons::ENGINE_FLAG_40) {
+			continue;
+		}
+
+		if (actor->flags & Dragons::ACTOR_FLAG_40 &&
+				!(actor->flags & Dragons::ACTOR_FLAG_4) &&
+				!(actor->flags & Dragons::ACTOR_FLAG_400) &&
+				(actor->frameIndex_maybe == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
+			debug("Actor[%d] execute sequenceOp", actorId);
+			//TODO execute sequence Opcode here.
+			return;
+		}
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 6ff788eafc..0cf14f3f0e 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -53,11 +53,24 @@ enum kReadSaveHeaderError {
 	kRSHEInvalidVersion = 2,
 	kRSHEIoError = 3
 };
+
+enum Flags {
+	ENGINE_FLAG_1 = 1,
+	ENGINE_FLAG_2 = 2,
+	ENGINE_FLAG_4 = 4,
+	ENGINE_FLAG_8 = 8,
+	ENGINE_FLAG_10 = 10,
+	ENGINE_FLAG_20 = 20,
+	ENGINE_FLAG_40 = 40,
+	ENGINE_FLAG_80 = 80
+};
+
 class BigfileArchive;
 class DragonRMS;
 class DragonINIResource;
 class Scene;
 class Screen;
+class ActorManager;
 
 class DragonsEngine : public Engine {
 private:
@@ -66,6 +79,7 @@ private:
 	DragonRMS *_dragonRMS;
 	DragonINIResource *_dragonINIResource;
 	BackgroundResourceLoader *_backgroundResourceLoader;
+	ActorManager *_actorManager;
 	Scene *_scene;
 	uint32 _nextUpdatetime;
 	uint32 _flags;
@@ -80,6 +94,9 @@ public:
 	const char *getSavegameFilename(int num);
 	static Common::String getSavegameFilename(const Common::String &target, int num);
 	static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
+
+	void updateActorSequences();
+
 private:
 	void gameLoop();
 	void updateHandler();


Commit: 012652068fddb19f56f2d332b412d3205859355c
    https://github.com/scummvm/scummvm/commit/012652068fddb19f56f2d332b412d3205859355c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on executing actor sequences

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/actorresource.cpp
    engines/dragons/actorresource.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/sequenceopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 1768817c5a..9b4d7f4847 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -120,4 +120,8 @@ void Actor::updateSequence(uint16 newSequenceID) {
 	flags |= Dragons::ACTOR_FLAG_1;
 }
 
+void Actor::resetSequenceIP() {
+	_seqCodeIp = _actorResource->getSequenceData(_sequenceID);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 80066ce234..89cd1aeea9 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -73,7 +73,7 @@ public:
 	ActorResource*_actorResource;
 	uint16 actorFileDictionaryIndex;
 	int16 resourceID;
-	int16 _seqCodeIp;
+	byte *_seqCodeIp;
 	void* frame_pointer_maybe;
 	uint16 field_c;
 	int16 var_e;
@@ -109,6 +109,7 @@ public:
 	void init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID);
 	Graphics::Surface *getCurrentFrame();
 	void updateSequence(uint16 newSequenceID);
+	void resetSequenceIP();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 9da45af0e7..a2cb69c7e3 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -47,8 +47,9 @@ ActorResource *ActorResourceLoader::load(uint32 resourceId) {
 }
 
 bool ActorResource::load(byte *dataStart, Common::SeekableReadStream &stream) {
+	_data = dataStart;
 	stream.seek(0x6);
-	uint16 sequenceOffset = stream.readUint16LE();
+	_sequenceTableOffset = stream.readUint16LE();
 	uint16 frameOffset = stream.readUint16LE();
 	uint16 paletteOffset = stream.readUint16LE();
 
@@ -153,4 +154,10 @@ ActorFrame *ActorResource::getFrameHeader(uint16 frameNumber) {
 	return &_frames[frameNumber];
 }
 
+byte *ActorResource::getSequenceData(int16 sequenceId)
+{
+	uint16 offset = READ_LE_UINT16(_data + _sequenceTableOffset + (sequenceId * 2));
+	return &_data[offset];
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index 5f088aabf1..00d86b295f 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -50,15 +50,19 @@ public:
 
 class ActorResource {
 private:
-	byte *data;
+	byte *_data;
 	ActorFrame *_frames;
 	uint16 _framesCount;
 	byte _palette[512];
+	uint16 _sequenceTableOffset;
+	uint16 _sequenceCount;
 
 public:
 	bool load(byte *dataStart, Common::SeekableReadStream &stream);
 	Graphics::Surface *loadFrame(uint16 frameNumber);
 	ActorFrame *getFrameHeader(uint16 frameNumber);
+	byte *getSequenceData(int16 sequenceId);
+
 private:
 	void writePixelBlock(byte *pixels, byte *data);
 };
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index f2071641ea..36341f006f 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -31,6 +31,7 @@
 #include "dragons.h"
 #include "scene.h"
 #include "screen.h"
+#include "sequenceopcodes.h"
 
 namespace Dragons {
 
@@ -43,10 +44,11 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_screen = NULL;
 	_nextUpdatetime = 0;
 	_flags = 0;
+	_sequenceOpcodes = new SequenceOpcodes(this);
 }
 
 DragonsEngine::~DragonsEngine() {
-
+	delete _sequenceOpcodes;
 }
 
 void DragonsEngine::updateEvents() {
@@ -179,7 +181,19 @@ void DragonsEngine::updateActorSequences() {
 				!(actor->flags & Dragons::ACTOR_FLAG_400) &&
 				(actor->frameIndex_maybe == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
 			debug("Actor[%d] execute sequenceOp", actorId);
+
+			if (actor->flags & Dragons::ACTOR_FLAG_1) {
+				actor->resetSequenceIP();
+				actor->flags &= 0xeff6; //TODO rewrite using ACTOR_FLAG_nnn
+				actor->field_7a = 0;
+			}
 			//TODO execute sequence Opcode here.
+			OpCall opCall;
+			opCall._op = (byte)READ_LE_UINT16(actor->_seqCodeIp);
+			opCall._opSize = (byte)READ_LE_UINT16(actor->_seqCodeIp + 2);
+			opCall._code = actor->_seqCodeIp + 4;
+			opCall._deltaOfs = opCall._opSize;
+			_sequenceOpcodes->execOpcode(actor, opCall);
 			return;
 		}
 	}
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 0cf14f3f0e..696ea5bdd5 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -71,6 +71,7 @@ class DragonINIResource;
 class Scene;
 class Screen;
 class ActorManager;
+class SequenceOpcodes;
 
 class DragonsEngine : public Engine {
 private:
@@ -81,6 +82,7 @@ private:
 	BackgroundResourceLoader *_backgroundResourceLoader;
 	ActorManager *_actorManager;
 	Scene *_scene;
+	SequenceOpcodes *_sequenceOpcodes;
 	uint32 _nextUpdatetime;
 	uint32 _flags;
 
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 6c4d0818e4..afb5f75470 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -78,6 +78,9 @@ void SequenceOpcodes::initOpcodes() {
 	// Register opcodes
 	OPCODE(1, opSetFramePointer);
 
+
+	OPCODE(4, opSetFieldC);
+
 }
 
 #undef OPCODE
@@ -97,6 +100,11 @@ void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
 	actor->frameIndex_maybe = actor->field_c;
 }
 
+void SequenceOpcodes::opSetFieldC(Actor *actor, OpCall &opCall) {
+	ARG_INT16(newFieldC);
+	actor->field_c = (uint16)newFieldC;
+}
+
 //void SequenceOpcodes::opYield(Control *control, OpCall &opCall) {
 //	opCall._result = 2;
 //}
diff --git a/engines/dragons/sequenceopcodes.h b/engines/dragons/sequenceopcodes.h
index ef3a4391eb..7f1b3984b7 100644
--- a/engines/dragons/sequenceopcodes.h
+++ b/engines/dragons/sequenceopcodes.h
@@ -67,6 +67,7 @@ protected:
 
 	// Opcodes
 	void opSetFramePointer(Actor *actor, OpCall &opCall);
+	void opSetFieldC(Actor *actor, OpCall &opCall);
 
 };
 


Commit: 774147099e8a4d333b8ea63ba28d6d4e6421bcd2
    https://github.com/scummvm/scummvm/commit/774147099e8a4d333b8ea63ba28d6d4e6421bcd2
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: more work on actor update logic

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/actorresource.cpp
    engines/dragons/actorresource.h
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/dragonini.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/sequenceopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 9b4d7f4847..01ef0955dd 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -26,7 +26,7 @@
 namespace Dragons {
 
 ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorResourceLoader(actorResourceLoader) {
-	for (uint16 i = 0; i < 64; i++) {
+	for (uint16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
 		_actors.push_back(Actor(i));
 	}
 }
@@ -68,10 +68,17 @@ Actor *ActorManager::findFreeActor(int16 resourceId) {
 }
 
 Actor *ActorManager::getActor(uint16 actorId) {
-	assert(actorId < 64);
+	assert(actorId < DRAGONS_ENGINE_NUM_ACTORS);
 	return &_actors[actorId];
 }
 
+void ActorManager::clearActorFlags(uint16 startingActorId) {
+	assert(startingActorId < DRAGONS_ENGINE_NUM_ACTORS);
+	for(uint16 i = startingActorId; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
+		_actors[i].flags = 0;
+	}
+}
+
 Actor::Actor(uint16 id) : _actorID(id) {
 	_actorResource = NULL;
 	resourceID = -1;
@@ -88,13 +95,15 @@ Actor::Actor(uint16 id) : _actorID(id) {
 	frame_height = 0;
 	frame_flags = 0;
 	clut = 0;
+	frame = NULL;
+	surface = NULL;
 }
 
 void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	_actorResource = resource;
 	x_pos = x;
 	y_pos = y;
-	frameIndex_maybe = 0;
+	sequenceTimer = 0;
 	target_x_pos = x;
 	target_y_pos = y;
 	var_e = 0x100;
@@ -109,9 +118,9 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 }
 
 Graphics::Surface *Actor::getCurrentFrame() {
-	frame_vram_x = _actorResource->getFrameHeader(frameIndex_maybe)->field_0;
-	frame_vram_y = _actorResource->getFrameHeader(frameIndex_maybe)->field_2;
-	return _actorResource->loadFrame(frameIndex_maybe);
+	frame_vram_x = _actorResource->getFrameHeader(sequenceTimer)->xOffset;
+	frame_vram_y = _actorResource->getFrameHeader(sequenceTimer)->yOffset;
+	return _actorResource->loadFrame(sequenceTimer);
 }
 
 void Actor::updateSequence(uint16 newSequenceID) {
@@ -124,4 +133,19 @@ void Actor::resetSequenceIP() {
 	_seqCodeIp = _actorResource->getSequenceData(_sequenceID);
 }
 
+void Actor::loadFrame(uint16 frameOffset) {
+	if (frame) {
+		delete frame;
+	}
+	if (surface) {
+		delete surface;
+	}
+
+	frame = _actorResource->loadFrameHeader(frameOffset);
+	surface = _actorResource->loadFrame(*frame);
+
+	debug(3, "load frame header: (%d,%d)", frame->width, frame->height);
+
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 89cd1aeea9..dadc5f41a0 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -28,6 +28,9 @@ namespace Dragons {
 class Actor;
 class ActorResourceLoader;
 class ActorResource;
+struct ActorFrame;
+
+#define DRAGONS_ENGINE_NUM_ACTORS 64
 
 enum ActorFlags {
 	ACTOR_FLAG_1 = 1,
@@ -45,7 +48,7 @@ enum ActorFlags {
 	ACTOR_FLAG_1000 = 0x1000,
 	ACTOR_FLAG_2000 = 0x2000,
 	ACTOR_FLAG_4000 = 0x4000,
-	ACTOR_FLAG_8000 = 0x8000
+	ACTOR_FLAG_8000 = 0x8000  //Seems turn off semi trans mode when selected.
 };
 
 class ActorManager {
@@ -63,6 +66,8 @@ public:
 	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y);
 	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16);
 	Actor *getActor(uint16 actorId);
+	void clearActorFlags(uint16 startingActorId);
+
 private:
 	Actor *findFreeActor(int16 resourceID);
 };
@@ -75,12 +80,14 @@ public:
 	int16 resourceID;
 	byte *_seqCodeIp;
 	void* frame_pointer_maybe;
+	ActorFrame *frame;
+	Graphics::Surface *surface;
 	uint16 field_c;
 	int16 var_e;
-	uint16 frameIndex_maybe;
+	uint16 sequenceTimer;
 	uint16 _sequenceID;
 	uint16 _sequenceID2;
-	uint16 field16;
+	int16 field16;
 	uint16 flags;
 	int16 x_pos;
 	int16 y_pos;
@@ -110,6 +117,7 @@ public:
 	Graphics::Surface *getCurrentFrame();
 	void updateSequence(uint16 newSequenceID);
 	void resetSequenceIP();
+	void loadFrame(uint16 frameOffset);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index a2cb69c7e3..6e441d861c 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -42,11 +42,12 @@ ActorResource *ActorResourceLoader::load(uint32 resourceId) {
 	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(scrData, size, DisposeAfterUse::NO);
 
 	debug("Loading '%s'", filename);
-	actorResource->load(scrData, *readStream);
+	actorResource->load(resourceId, scrData, *readStream);
 	return actorResource;
 }
 
-bool ActorResource::load(byte *dataStart, Common::SeekableReadStream &stream) {
+bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream &stream) {
+	_id = id;
 	_data = dataStart;
 	stream.seek(0x6);
 	_sequenceTableOffset = stream.readUint16LE();
@@ -69,8 +70,8 @@ bool ActorResource::load(byte *dataStart, Common::SeekableReadStream &stream) {
 
 		uint16 offset = stream.readUint16LE();
 		stream.seek(offset);
-		_frames[i].field_0 = stream.readSint16LE();
-		_frames[i].field_2 = stream.readSint16LE();
+		_frames[i].xOffset = stream.readSint16LE();
+		_frames[i].yOffset = stream.readSint16LE();
 		_frames[i].width = stream.readByte() * 2; //FIXME the original checks actor->frame_flags bit 0 here at 0x80018438
 		_frames[i].height = stream.readByte();
 		uint32 frameDataOffset = stream.readUint32LE();
@@ -97,18 +98,22 @@ void ActorResource::writePixelBlock(byte *pixels, byte *data) {
 
 Graphics::Surface *ActorResource::loadFrame(uint16 frameNumber) {
 	assert (frameNumber < _framesCount);
+	return loadFrame(_frames[frameNumber]);
+}
+
+Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame) {
 
 	Graphics::Surface *surface = new Graphics::Surface();
 	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
-	surface->create(_frames[frameNumber].width, _frames[frameNumber].height, pixelFormat16);
+	surface->create(actorFrame.width, actorFrame.height, pixelFormat16);
 
 	byte *pixels = (byte *)surface->getPixels();
 
-	int32 blockSize = ((_frames[frameNumber].width / 2) * _frames[frameNumber].height * 2) / 4;
+	int32 blockSize = ((actorFrame.width / 2) * actorFrame.height * 2) / 4;
 
-	debug("Frame blockSize: %d width: %d height: %d", blockSize, _frames[frameNumber].width, _frames[frameNumber].height);
+	debug("Frame blockSize: %d width: %d height: %d", blockSize, actorFrame.width, actorFrame.height);
 
-	byte *data = _frames[frameNumber].frameDataOffset;
+	byte *data = actorFrame.frameDataOffset;
 
 	while(blockSize > 0) {
 		int32 size = READ_BE_INT32(data);
@@ -160,4 +165,25 @@ byte *ActorResource::getSequenceData(int16 sequenceId)
 	return &_data[offset];
 }
 
+ActorFrame *ActorResource::loadFrameHeader(uint16 frameOffset) {
+	Common::SeekableReadStream *stream = new Common::MemoryReadStream(_data + frameOffset, sizeof(ActorFrame), DisposeAfterUse::NO);
+
+	ActorFrame *frame = new ActorFrame;
+	frame->xOffset = stream->readSint16LE();
+	frame->yOffset = stream->readSint16LE();
+	frame->width = stream->readByte() * 2; //FIXME the original checks actor->frame_flags bit 0 here at 0x80018438
+	frame->height = stream->readByte();
+	uint32 frameDataOffset = stream->readUint32LE();
+	frame->frameDataOffset = &_data[frameDataOffset];
+	frame->flags = stream->readUint16LE();
+	frame->field_c = stream->readUint16LE();
+
+	delete stream;
+	return frame;
+}
+
+const char *ActorResource::getFilename() {
+	return actorResourceFiles[_id];
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index 00d86b295f..0bf924c96d 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -30,8 +30,8 @@ class BigfileArchive;
 class ActorResource;
 
 struct ActorFrame {
-	int16 field_0;
-	int16 field_2;
+	int16 xOffset;
+	int16 yOffset;
 	uint8 width;
 	uint8 height;
 	byte *frameDataOffset;
@@ -50,6 +50,7 @@ public:
 
 class ActorResource {
 private:
+	uint32 _id;
 	byte *_data;
 	ActorFrame *_frames;
 	uint16 _framesCount;
@@ -58,10 +59,14 @@ private:
 	uint16 _sequenceCount;
 
 public:
-	bool load(byte *dataStart, Common::SeekableReadStream &stream);
+	bool load(uint32 id, byte *dataStart, Common::SeekableReadStream &stream);
 	Graphics::Surface *loadFrame(uint16 frameNumber);
+	Graphics::Surface *loadFrame(ActorFrame &frameNumber);
+	ActorFrame *loadFrameHeader(uint16 frameOffset);
+
 	ActorFrame *getFrameHeader(uint16 frameNumber);
 	byte *getSequenceData(int16 sequenceId);
+	const char *getFilename();
 
 private:
 	void writePixelBlock(byte *pixels, byte *data);
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index ab2b6ea177..2e59720192 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -51,7 +51,7 @@ void Dragons::PriorityLayer::load(TileMap &tileMap, byte *tiles) {
 	memcpy(_values, tiles, tileSize);
 }
 
-int PriorityLayer::getPriority(Common::Point pos) {
+int16 PriorityLayer::getPriority(Common::Point pos) {
 	pos.x = CLIP<int16>(pos.x, 0, _width - 1);
 	pos.y = CLIP<int16>(pos.y, 0, _height - 1);
 	const int16 tx = pos.x / 32, sx = pos.x % 32;
@@ -153,6 +153,14 @@ uint16 Background::getHeight() {
 	return _bgLayer->h;
 }
 
+int16 Background::getPriorityAtPoint(Common::Point pos) {
+	if (pos.x < 0 || pos.x >= _bgLayer->w || pos.y < 0 || pos.y >= _bgLayer->h) {
+		return -1;
+	}
+	int16 priority = _priorityLayer->getPriority(pos);
+	return priority < 0x10 ? priority : 0;
+}
+
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
 		bigFileArchive), _dragonRMS(dragonRMS) {}
 
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 6929a8faf6..40aa00b398 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -59,6 +59,7 @@ public:
 	Graphics::Surface *getBgLayer() { return _bgLayer; }
 	Graphics::Surface *getMgLayer() { return _mgLayer; }
 	Graphics::Surface *getFgLayer() { return _fgLayer; }
+	int16 getPriorityAtPoint(Common::Point pos);
 	Common::Point getPoint2(uint32 pointIndex);
 	byte *getPalette() { return _palette; }
 
@@ -71,7 +72,7 @@ private:
 class PriorityLayer {
 public:
 	void load(TileMap &tileMap, byte *tiles);
-	int getPriority(Common::Point pos);
+	int16 getPriority(Common::Point pos);
 protected:
 	int16 _width, _height;
 	int16 _mapWidth, _mapHeight;
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index 07a95db3e6..b16562cf1c 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -45,7 +45,7 @@ DragonINIResource::DragonINIResource(BigfileArchive *bigfileArchive) {
 		_dragonINI[i].actor = NULL;
 		_dragonINI[i].sceneId = readStream->readUint16LE();
 		_dragonINI[i].field_e = readStream->readSint16LE();
-		_dragonINI[i].field_10 = readStream->readUint16LE();
+		_dragonINI[i].field_10 = readStream->readSint16LE();
 		_dragonINI[i].field_12 = readStream->readSint16LE();
 		_dragonINI[i].field_14 = readStream->readSint16LE();
 		_dragonINI[i].x = readStream->readSint16LE();
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index c9062bed8f..250634fd6a 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -29,6 +29,18 @@ namespace Dragons {
 
 class Actor;
 
+enum IniFlags {
+	INI_FLAG_1 = 1,
+	INI_FLAG_2 = 2,
+	INI_FLAG_4 = 4,
+	INI_FLAG_8 = 8,
+	INI_FLAG_10 = 10,
+	INI_FLAG_20 = 20,
+	INI_FLAG_40 = 40,
+	INI_FLAG_80 = 80
+};
+
+
 struct DragonINI
 	{
 		int16 iptIndex_maybe;
@@ -39,7 +51,7 @@ struct DragonINI
 		Actor *actor;
 		uint16 sceneId;
 		int16 field_e;
-		uint16 field_10;
+		int16 field_10;
 		int16 field_12;
 		int16 field_14;
 		int16 x;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 36341f006f..74383c290c 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -44,6 +44,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_screen = NULL;
 	_nextUpdatetime = 0;
 	_flags = 0;
+	_unkFlags1 = 0;
 	_sequenceOpcodes = new SequenceOpcodes(this);
 }
 
@@ -71,7 +72,7 @@ Common::Error DragonsEngine::run() {
 	_dragonINIResource = new DragonINIResource(_bigfileArchive);
 	ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
 	_actorManager = new ActorManager(actorResourceLoader);
-	_scene = new Scene(_screen, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
+	_scene = new Scene(this, _screen, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
 	_flags = 0x1046;
 
 	_scene->loadScene(0x12, 0x1e);
@@ -96,12 +97,55 @@ void DragonsEngine::gameLoop() {
 	while (!shouldQuit()) {
 		updateHandler();
 		updateEvents();
+		_scene->draw();
+		_screen->updateScreen();
 		wait();
 	}
 }
 
 void DragonsEngine::updateHandler() {
 	updateActorSequences();
+
+	//TODO logic here
+	for (uint16 i = 0; i < 0x17; i++) {
+		Actor *actor = _actorManager->getActor(i);
+		if (actor->flags & Dragons::ACTOR_FLAG_40) {
+			if (!(actor->flags & Dragons::ACTOR_FLAG_100)) {
+				int16 priority = _scene->getPriorityAtPosition(Common::Point(actor->x_pos, actor->y_pos));
+				DragonINI *flicker = _dragonINIResource->getFlickerRecord();
+				if (flicker && _scene->contains(flicker) && flicker->actor->_actorID == i) {
+					if (priority < 8 || priority == 0x10) {
+						actor->field16 = priority;
+					}
+				} else {
+					if (priority != -1) {
+						actor->field16 = priority;
+					}
+				}
+
+				if (actor->field16 >= 0x11) {
+					actor->field16 = 0;
+				}
+
+				if (actor->field16 >= 9) {
+					actor->field16 -= 8;
+				}
+			}
+
+			if (actor->sequenceTimer != 0) {
+				actor->sequenceTimer--;
+			}
+		}
+	}
+
+	if (_flags & Dragons::ENGINE_FLAG_80) {
+		for (uint16 i = 0x17; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
+			Actor *actor = _actorManager->getActor(i);
+			if (actor->sequenceTimer != 0) {
+				actor->sequenceTimer--;
+			}
+		}
+	}
 }
 
 const char *DragonsEngine::getSavegameFilename(int num) {
@@ -162,14 +206,14 @@ void DragonsEngine::wait() {
 
 void DragonsEngine::updateActorSequences() {
 	if (!(_flags & Dragons::ENGINE_FLAG_4)) {
-		return;
+//TODO 		return;
 	}
 
 	//TODO ResetRCnt(0xf2000001);
 
 	int16 actorId = _flags & Dragons::ENGINE_FLAG_80 ? (int16)64 : (int16)23;
 
-	while (actorId >= 0) {
+	while (actorId > 0) {
 		actorId--;
 		Actor *actor = _actorManager->getActor((uint16)actorId);
 		if (actorId < 2 && _flags & Dragons::ENGINE_FLAG_40) {
@@ -179,7 +223,7 @@ void DragonsEngine::updateActorSequences() {
 		if (actor->flags & Dragons::ACTOR_FLAG_40 &&
 				!(actor->flags & Dragons::ACTOR_FLAG_4) &&
 				!(actor->flags & Dragons::ACTOR_FLAG_400) &&
-				(actor->frameIndex_maybe == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
+				(actor->sequenceTimer == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
 			debug("Actor[%d] execute sequenceOp", actorId);
 
 			if (actor->flags & Dragons::ACTOR_FLAG_1) {
@@ -189,14 +233,31 @@ void DragonsEngine::updateActorSequences() {
 			}
 			//TODO execute sequence Opcode here.
 			OpCall opCall;
-			opCall._op = (byte)READ_LE_UINT16(actor->_seqCodeIp);
-			opCall._opSize = (byte)READ_LE_UINT16(actor->_seqCodeIp + 2);
-			opCall._code = actor->_seqCodeIp + 4;
-			opCall._deltaOfs = opCall._opSize;
-			_sequenceOpcodes->execOpcode(actor, opCall);
-			return;
+			opCall._result = 1;
+			while (opCall._result == 1) {
+				opCall._op = (byte) READ_LE_UINT16(actor->_seqCodeIp);
+				opCall._code = actor->_seqCodeIp + 2;
+				_sequenceOpcodes->execOpcode(actor, opCall);
+				actor->_seqCodeIp += opCall._deltaOfs;
+			}
 		}
 	}
 }
 
+void DragonsEngine::setFlags(uint32 flags) {
+	_flags |= flags;
+}
+
+void DragonsEngine::clearFlags(uint32 flags) {
+	_flags &= ~flags;
+}
+
+void DragonsEngine::setUnkFlags(uint32 flags) {
+	_unkFlags1 |= flags;
+}
+
+void DragonsEngine::clearUnkFlags(uint32 flags) {
+	_unkFlags1 &= ~flags;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 696ea5bdd5..0789b4c509 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -24,7 +24,6 @@
 
 #include "gui/EventRecorder.h"
 #include "engines/engine.h"
-#include "background.h"
 
 namespace Dragons {
 
@@ -65,7 +64,19 @@ enum Flags {
 	ENGINE_FLAG_80 = 80
 };
 
+enum UnkFlags {
+	ENGINE_UNK1_FLAG_1 = 1,
+	ENGINE_UNK1_FLAG_2 = 2,
+	ENGINE_UNK1_FLAG_4 = 4,
+	ENGINE_UNK1_FLAG_8 = 8,
+	ENGINE_UNK1_FLAG_10 = 10,
+	ENGINE_UNK1_FLAG_20 = 20,
+	ENGINE_UNK1_FLAG_40 = 40,
+	ENGINE_UNK1_FLAG_80 = 80
+};
+
 class BigfileArchive;
+class BackgroundResourceLoader;
 class DragonRMS;
 class DragonINIResource;
 class Scene;
@@ -85,6 +96,7 @@ private:
 	SequenceOpcodes *_sequenceOpcodes;
 	uint32 _nextUpdatetime;
 	uint32 _flags;
+	uint32 _unkFlags1;
 
 public:
 	DragonsEngine(OSystem *syst);
@@ -98,6 +110,11 @@ public:
 	static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
 
 	void updateActorSequences();
+	void setFlags(uint32 flags);
+	void clearFlags(uint32 flags);
+
+	void setUnkFlags(uint32 flags);
+	void clearUnkFlags(uint32 flags);
 
 private:
 	void gameLoop();
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 9f5b2d6232..fb113ca793 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -20,20 +20,42 @@
  *
  */
 #include "scene.h"
-
+#include "dragons.h"
 #include "actor.h"
 #include "background.h"
 #include "dragonini.h"
 #include "screen.h"
+#include "actorresource.h"
 
 namespace Dragons {
 
-Scene::Scene(Screen *screen, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
-		: _screen(screen), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
+
+Scene::Scene(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
+		: _vm(vm), _screen(screen), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
 	_backgroundLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 }
 
 void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
+	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_2 | Dragons::ENGINE_UNK1_FLAG_8);
+
+	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
+		DragonINI *ini = _dragonINIResource->getRecord(i);
+		ini->field_10 = -1;
+		ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
+	}
+
+	if (!(sceneId & 0x8000)) {
+		// TODO opcodes here.
+	}
+
+	_actorManager->clearActorFlags(2);
+	//TODO sub_8003fadc(); might be fade related
+
+	_vm->clearFlags(Dragons::ENGINE_FLAG_20);
+	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_10);
+
+	// TODO 0x8002f7bc call_fade_related_1f()
+
 	_stage = _backgroundLoader->load(sceneId);
 
 	_camera = _stage->getPoint2(cameraPointId);
@@ -104,18 +126,19 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 				} else {
 					actor->flags &= 0xbfff;
 				}
-
-				Graphics::Surface *s = actor->getCurrentFrame();
-				int x = ini->x - actor->frame_vram_x;
-				int y = ini->y - actor->frame_vram_y;
-				if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
-					debug("Actor %d %d (%d, %d)", ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
-					_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
-				}
+//
+//				Graphics::Surface *s = actor->getCurrentFrame();
+//				int x = ini->x - actor->frame_vram_x;
+//				int y = ini->y - actor->frame_vram_y;
+//				if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
+//					debug("Actor %d, %d %d (%d, %d)", actor->_actorID, ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
+//					_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
+//				}
 			}
-			_stage->getFgLayer()->drawLine(ini->x, ini->y, ini->x + 8, ini->y + 8, 0x7c00);
+			// _stage->getFgLayer()->drawLine(ini->x, ini->y, ini->x + 8, ini->y + 8, 0x7c00);
 			//break;
 		}
+		_currentSceneId = (uint16)(sceneId & 0x7fff);
 	}
 
 }
@@ -125,6 +148,37 @@ void Scene::draw() {
 	_screen->copyRectToSurface(*_stage->getBgLayer(), 0, 0, rect);
 	_screen->copyRectToSurface(*_stage->getMgLayer(), 0, 0, rect);
 	_screen->copyRectToSurface(*_stage->getFgLayer(), 0, 0, rect);
+	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
+		DragonINI *ini = _dragonINIResource->getRecord(i);
+		if (ini->sceneId == _currentSceneId && (ini->field_1a_flags_maybe & 1)) {
+			Actor *actor = ini->actor;
+			if (actor &&
+				actor->flags & Dragons::ACTOR_FLAG_40 &&
+				actor->surface) {
+				Graphics::Surface *s = actor->surface;
+				int x = ini->x - actor->frame->xOffset;
+				int y = ini->y - actor->frame->yOffset;
+				//int x = ini->x;// - actor->frame_vram_x;
+				//int y = ini->y;// - actor->frame_vram_y;
+				if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
+					debug("Actor %d %s (%d, %d)", actor->_actorID, actor->_actorResource->getFilename(), x, y);
+					_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
+				} else {
+					debug("Actor (not displayed) %d %s (%d, %d)", actor->_actorID, actor->_actorResource->getFilename(), x, y);
+					// _stage->getFgLayer()->copyRectToSurface(*s, 0, 0, Common::Rect(s->w, s->h));
+				}
+			}
+		}
+	}
+}
+
+int16 Scene::getPriorityAtPosition(Common::Point pos) {
+	return _stage->getPriorityAtPoint(pos);
+}
+
+bool Scene::contains(DragonINI *ini) {
+	assert(ini);
+	return ini->sceneId == _currentSceneId;
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index c4d3f24a1c..0adbdac56f 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -27,6 +27,7 @@
 
 namespace Dragons {
 
+class DragonsEngine;
 class ActorManager;
 class Background;
 class DragonRMS;
@@ -34,9 +35,11 @@ class BackgroundResourceLoader;
 class DragonINIResource;
 class BigfileArchive;
 class Screen;
+class DragonINI;
 
 class Scene {
 private:
+	DragonsEngine *_vm;
 	Screen *_screen;
 	ActorManager *_actorManager;
 	Background *_stage;
@@ -49,11 +52,12 @@ private:
 	Common::Point _camera;
 
 public:
-	Scene(Screen *screen, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
+	Scene(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
 
 	void loadScene(uint32 sceneId, uint32 cameraPointId);
-
+	int16 getPriorityAtPosition(Common::Point pos);
 	void draw();
+	bool contains(DragonINI *ini);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index afb5f75470..55b5a2f47c 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -23,6 +23,8 @@
 #include "dragons/dragons.h"
 #include "dragons/sequenceopcodes.h"
 #include "dragons/actor.h"
+#include "sequenceopcodes.h"
+
 
 namespace Dragons {
 // OpCall
@@ -77,10 +79,16 @@ void SequenceOpcodes::initOpcodes() {
 	}
 	// Register opcodes
 	OPCODE(1, opSetFramePointer);
+	OPCODE(2, opSetFramePointerAndStop);
 
 
 	OPCODE(4, opSetFieldC);
 
+	OPCODE(9, opSetActorFlag4AndStop);
+
+	OPCODE(11, opSetActorFlags404);
+	OPCODE(17, opPlaySound);
+
 }
 
 #undef OPCODE
@@ -91,20 +99,50 @@ void SequenceOpcodes::freeOpcodes() {
 	}
 }
 
+void SequenceOpcodes::updateReturn(OpCall &opCall, uint16 size) {
+	opCall._deltaOfs = size * 2 + 2;
+}
+
 // Opcodes
 
 void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
 	ARG_INT16(framePointer);
-	//TODO update frame pointer
+	debug(3, "set frame pointer %X", framePointer);
+	actor->loadFrame((uint16)framePointer);
 	actor->flags |= Dragons::ACTOR_FLAG_2;
-	actor->frameIndex_maybe = actor->field_c;
+	actor->sequenceTimer = actor->field_c;
+	updateReturn(opCall, 1);
+}
+
+void SequenceOpcodes::opSetFramePointerAndStop(Actor *actor, OpCall &opCall) {
+	opSetFramePointer(actor, opCall);
+	opCall._result = 0;
 }
 
 void SequenceOpcodes::opSetFieldC(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newFieldC);
 	actor->field_c = (uint16)newFieldC;
+	updateReturn(opCall, 1);
 }
 
+void SequenceOpcodes::opSetActorFlag4AndStop(Actor *actor, OpCall &opCall) {
+	actor->flags |= Dragons::ACTOR_FLAG_4;
+	opCall._deltaOfs = 0;
+	opCall._result = 0;
+	//updateReturn(opCall, 1);
+}
+
+void SequenceOpcodes::opSetActorFlags404(Actor *actor, OpCall &opCall) {
+	actor->flags |= (Dragons::ACTOR_FLAG_4 | Dragons::ACTOR_FLAG_400 );
+	updateReturn(opCall, 1);
+}
+void SequenceOpcodes::opPlaySound(Actor *actor, OpCall &opCall) {
+	ARG_INT16(soundId);
+	// TODO play sound here.
+	updateReturn(opCall, 1);
+}
+
+
 //void SequenceOpcodes::opYield(Control *control, OpCall &opCall) {
 //	opCall._result = 2;
 //}
diff --git a/engines/dragons/sequenceopcodes.h b/engines/dragons/sequenceopcodes.h
index 7f1b3984b7..56800ce254 100644
--- a/engines/dragons/sequenceopcodes.h
+++ b/engines/dragons/sequenceopcodes.h
@@ -64,10 +64,15 @@ protected:
 	Common::String _opcodeNames[DRAGONS_NUM_SEQ_OPCODES];
 	void initOpcodes();
 	void freeOpcodes();
+	void updateReturn(OpCall &opCall, uint16 size);
 
 	// Opcodes
 	void opSetFramePointer(Actor *actor, OpCall &opCall);
+	void opSetFramePointerAndStop(Actor *actor, OpCall &opCall);
 	void opSetFieldC(Actor *actor, OpCall &opCall);
+	void opSetActorFlag4AndStop(Actor *actor, OpCall &opCall);
+	void opSetActorFlags404(Actor *actor, OpCall &opCall);
+	void opPlaySound(Actor *actor, OpCall &opCall);
 
 };
 


Commit: df0298f8f48e08d153ccd4e5bdf5be1fe2a8b672
    https://github.com/scummvm/scummvm/commit/df0298f8f48e08d153ccd4e5bdf5be1fe2a8b672
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added more sequence opCodes

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/actorresource.cpp
    engines/dragons/actorresource.h
    engines/dragons/scene.cpp
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/sequenceopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 01ef0955dd..693f220fec 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -148,4 +148,8 @@ void Actor::loadFrame(uint16 frameOffset) {
 
 }
 
+byte *Actor::getSeqIpAtOffset(uint32 offset) {
+	return _actorResource->getSequenceDataAtOffset(offset);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index dadc5f41a0..26252366fc 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -117,6 +117,7 @@ public:
 	Graphics::Surface *getCurrentFrame();
 	void updateSequence(uint16 newSequenceID);
 	void resetSequenceIP();
+	byte *getSeqIpAtOffset(uint32 offset);
 	void loadFrame(uint16 frameOffset);
 };
 
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 6e441d861c..44f866a3dc 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -49,6 +49,7 @@ ActorResource *ActorResourceLoader::load(uint32 resourceId) {
 bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream &stream) {
 	_id = id;
 	_data = dataStart;
+	_fileSize = stream.size();
 	stream.seek(0x6);
 	_sequenceTableOffset = stream.readUint16LE();
 	uint16 frameOffset = stream.readUint16LE();
@@ -186,4 +187,9 @@ const char *ActorResource::getFilename() {
 	return actorResourceFiles[_id];
 }
 
+byte *ActorResource::getSequenceDataAtOffset(uint32 offset) {
+	assert(offset < _fileSize);
+	return &_data[offset];
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index 0bf924c96d..52bd9e8b7b 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -52,6 +52,7 @@ class ActorResource {
 private:
 	uint32 _id;
 	byte *_data;
+	int32 _fileSize;
 	ActorFrame *_frames;
 	uint16 _framesCount;
 	byte _palette[512];
@@ -66,6 +67,7 @@ public:
 
 	ActorFrame *getFrameHeader(uint16 frameNumber);
 	byte *getSequenceData(int16 sequenceId);
+	byte *getSequenceDataAtOffset(uint32 offset);
 	const char *getFilename();
 
 private:
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index fb113ca793..2f6190c244 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -156,15 +156,15 @@ void Scene::draw() {
 				actor->flags & Dragons::ACTOR_FLAG_40 &&
 				actor->surface) {
 				Graphics::Surface *s = actor->surface;
-				int x = ini->x - actor->frame->xOffset;
-				int y = ini->y - actor->frame->yOffset;
+				int x = actor->x_pos - actor->frame->xOffset;
+				int y = actor->y_pos - actor->frame->yOffset;
 				//int x = ini->x;// - actor->frame_vram_x;
 				//int y = ini->y;// - actor->frame_vram_y;
 				if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
-					debug("Actor %d %s (%d, %d)", actor->_actorID, actor->_actorResource->getFilename(), x, y);
-					_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
+					debug(4, "Actor %d %s (%d, %d) w:%d h:%d", actor->_actorID, actor->_actorResource->getFilename(), x, y, s->w, s->h);
+					_screen->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
 				} else {
-					debug("Actor (not displayed) %d %s (%d, %d)", actor->_actorID, actor->_actorResource->getFilename(), x, y);
+					debug(4, "Actor (not displayed) %d %s (%d, %d)", actor->_actorID, actor->_actorResource->getFilename(), x, y);
 					// _stage->getFgLayer()->copyRectToSurface(*s, 0, 0, Common::Rect(s->w, s->h));
 				}
 			}
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 55b5a2f47c..54329bb4b0 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -80,14 +80,23 @@ void SequenceOpcodes::initOpcodes() {
 	// Register opcodes
 	OPCODE(1, opSetFramePointer);
 	OPCODE(2, opSetFramePointerAndStop);
-
-
+	OPCODE(3, opJmp);
 	OPCODE(4, opSetFieldC);
-
+	OPCODE(5, opSetSequenceTimer);
+	OPCODE(6, opUpdateXYResetSeqTimer);
+	OPCODE(7, opUpdateXYResetSeqTimerAndStop);
+	// unused
 	OPCODE(9, opSetActorFlag4AndStop);
-
+	// unused
 	OPCODE(11, opSetActorFlags404);
+	OPCODE(12, opClearActorFlag400);
+	OPCODE(13, opChangeSequence);
+	// unused
+	OPCODE(15, opSetField7a);
+	OPCODE(16, opUpdateFlags);
 	OPCODE(17, opPlaySound);
+	OPCODE(18, opSetXY);
+	OPCODE(19, opSetXYAndStop);
 
 }
 
@@ -119,12 +128,49 @@ void SequenceOpcodes::opSetFramePointerAndStop(Actor *actor, OpCall &opCall) {
 	opCall._result = 0;
 }
 
+void SequenceOpcodes::opJmp(Actor *actor, OpCall &opCall) {
+	ARG_INT16(newIp);
+
+	if (!(actor->flags & Dragons::ACTOR_FLAG_1000)) {
+		byte *newOffset = actor->getSeqIpAtOffset((uint32)newIp);
+		opCall._deltaOfs = (int32)(newOffset - opCall._code);
+		debug(3, "opJump delta: %d", opCall._deltaOfs);
+	} else {
+		updateReturn(opCall, 1);
+	}
+}
+
 void SequenceOpcodes::opSetFieldC(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newFieldC);
 	actor->field_c = (uint16)newFieldC;
+	debug(3, "set fieldC: %d", newFieldC);
 	updateReturn(opCall, 1);
 }
 
+void SequenceOpcodes::opSetSequenceTimer(Actor *actor, OpCall &opCall) {
+	ARG_INT16(newSeqTimer);
+	actor->sequenceTimer = (uint16)newSeqTimer;
+	debug(3, "set sequenceTimer: %d", newSeqTimer);
+	updateReturn(opCall, 1);
+	opCall._result = 0;
+}
+
+void SequenceOpcodes::opUpdateXYResetSeqTimer(Actor *actor, OpCall &opCall) {
+	ARG_INT8(xOffset);
+	ARG_INT8(yOffset);
+	actor->x_pos += xOffset;
+	actor->y_pos += yOffset;
+	actor->sequenceTimer = actor->field_c;
+
+	debug(3, "update actor %d XY offset (%d,%d) new values (%d, %d) %d", actor->_actorID, xOffset, yOffset, actor->x_pos, actor->y_pos, actor->sequenceTimer);
+	updateReturn(opCall, 1);
+}
+
+void SequenceOpcodes::opUpdateXYResetSeqTimerAndStop(Actor *actor, OpCall &opCall) {
+	opUpdateXYResetSeqTimer(actor, opCall);
+	opCall._result = 0;
+}
+
 void SequenceOpcodes::opSetActorFlag4AndStop(Actor *actor, OpCall &opCall) {
 	actor->flags |= Dragons::ACTOR_FLAG_4;
 	opCall._deltaOfs = 0;
@@ -136,12 +182,55 @@ void SequenceOpcodes::opSetActorFlags404(Actor *actor, OpCall &opCall) {
 	actor->flags |= (Dragons::ACTOR_FLAG_4 | Dragons::ACTOR_FLAG_400 );
 	updateReturn(opCall, 1);
 }
+
+void SequenceOpcodes::opClearActorFlag400(Actor *actor, OpCall &opCall) {
+	actor->flags &= ~Dragons::ACTOR_FLAG_400;
+	updateReturn(opCall, 1);
+}
+
+void SequenceOpcodes::opChangeSequence(Actor *actor, OpCall &opCall) {
+	ARG_INT16(newValue);
+	actor->_sequenceID = (uint16)newValue;
+	updateReturn(opCall, 1);
+}
+
+void SequenceOpcodes::opSetField7a(Actor *actor, OpCall &opCall) {
+	ARG_INT16(newValue);
+	actor->field_7a = (uint16)newValue;
+	updateReturn(opCall, 1);
+}
+
+void SequenceOpcodes::opUpdateFlags(Actor *actor, OpCall &opCall) {
+	if (actor->flags & Dragons::ACTOR_FLAG_1000) {
+		actor->flags &= Dragons::ACTOR_FLAG_4;
+	}
+	updateReturn(opCall, 0);
+}
+
 void SequenceOpcodes::opPlaySound(Actor *actor, OpCall &opCall) {
 	ARG_INT16(soundId);
+	debug(3, "opPlaySound actorId: %d soundId: %d", actor->_actorID, soundId);
+
 	// TODO play sound here.
 	updateReturn(opCall, 1);
 }
 
+void SequenceOpcodes::opSetXY(Actor *actor, OpCall &opCall) {
+	ARG_INT16(x);
+	ARG_INT16(y);
+	actor->x_pos = x;
+	actor->y_pos = y;
+	updateReturn(opCall, 2);
+}
+
+void SequenceOpcodes::opSetXYAndStop(Actor *actor, OpCall &opCall) {
+	opSetXY(actor, opCall);
+	opCall._result = 0;
+}
+
+
+
+
 
 //void SequenceOpcodes::opYield(Control *control, OpCall &opCall) {
 //	opCall._result = 2;
diff --git a/engines/dragons/sequenceopcodes.h b/engines/dragons/sequenceopcodes.h
index 56800ce254..88b84c4ba1 100644
--- a/engines/dragons/sequenceopcodes.h
+++ b/engines/dragons/sequenceopcodes.h
@@ -36,7 +36,7 @@ class Actor;
 struct OpCall {
 	byte _op;
 	byte _opSize;
-	int16 _deltaOfs;
+	int32 _deltaOfs;
 	byte *_code;
 	int _result;
 	void skip(uint size);
@@ -48,6 +48,7 @@ struct OpCall {
 // Convenience macros
 #define ARG_SKIP(x) opCall.skip(x);
 #define ARG_BYTE(name) byte name = opCall.readByte(); debug(5, "ARG_BYTE(" #name " = %d)", name);
+#define ARG_INT8(name) int8 name = opCall.readByte(); debug(5, "ARG_INT8(" #name " = %d)", name);
 #define ARG_INT16(name) int16 name = opCall.readSint16(); debug(5, "ARG_INT16(" #name " = %d)", name);
 #define ARG_UINT32(name) uint32 name = opCall.readUint32(); debug(5, "ARG_UINT32(" #name " = %08X)", name);
 
@@ -69,10 +70,22 @@ protected:
 	// Opcodes
 	void opSetFramePointer(Actor *actor, OpCall &opCall);
 	void opSetFramePointerAndStop(Actor *actor, OpCall &opCall);
+	void opJmp(Actor *actor, OpCall &opCall);
 	void opSetFieldC(Actor *actor, OpCall &opCall);
+	void opSetSequenceTimer(Actor *actor, OpCall &opCall);
+	void opUpdateXYResetSeqTimer(Actor *actor, OpCall &opCall);
+	void opUpdateXYResetSeqTimerAndStop(Actor *actor, OpCall &opCall);
+
 	void opSetActorFlag4AndStop(Actor *actor, OpCall &opCall);
 	void opSetActorFlags404(Actor *actor, OpCall &opCall);
+	void opClearActorFlag400(Actor *actor, OpCall &opCall);
+	void opChangeSequence(Actor *actor, OpCall &opCall);
+
+	void opSetField7a(Actor *actor, OpCall &opCall);
+	void opUpdateFlags(Actor *actor, OpCall &opCall);
 	void opPlaySound(Actor *actor, OpCall &opCall);
+	void opSetXY(Actor *actor, OpCall &opCall);
+	void opSetXYAndStop(Actor *actor, OpCall &opCall);
 
 };
 


Commit: c0f1d703932a6f3fc910ecbf7c558789092d32c3
    https://github.com/scummvm/scummvm/commit/c0f1d703932a6f3fc910ecbf7c558789092d32c3
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGOMS: Work on actor draw priorities

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/actorresource.cpp
    engines/dragons/actorresource.h
    engines/dragons/background.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 693f220fec..b896cb4d53 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -20,6 +20,7 @@
  *
  */
 #include <common/debug.h>
+#include "dragons.h"
 #include "actorresource.h"
 #include "actor.h"
 
@@ -32,10 +33,10 @@ ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorRes
 }
 
 
-Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16) {
+Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 priorityLayer) {
 	Actor *actor = loadActor(resourceId, sequenceId, x, y);
 	if(actor) {
-		actor->field16 = field16;
+		actor->priorityLayer = priorityLayer;
 	}
 	return actor;
 }
@@ -79,12 +80,18 @@ void ActorManager::clearActorFlags(uint16 startingActorId) {
 	}
 }
 
+Actor *ActorManager::loadActor(uint32 resourceId, uint16 actorId) {
+	Actor *actor = getActor(actorId);
+	actor->_actorResource = _actorResourceLoader->load(resourceId);
+	return actor;
+}
+
 Actor::Actor(uint16 id) : _actorID(id) {
 	_actorResource = NULL;
 	resourceID = -1;
 	_seqCodeIp = 0;
 	frame_pointer_maybe = NULL;
-	field16 = 3;
+	priorityLayer = 3;
 	x_pos = 160;
 	y_pos = 110;
 	target_x_pos = 0;
@@ -100,13 +107,14 @@ Actor::Actor(uint16 id) : _actorID(id) {
 }
 
 void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
+	debug(3, "actor %d Init", _actorID);
 	_actorResource = resource;
 	x_pos = x;
 	y_pos = y;
 	sequenceTimer = 0;
 	target_x_pos = x;
 	target_y_pos = y;
-	var_e = 0x100;
+	field_e = 0x100;
 	_sequenceID2 = 0;
 	flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
 	frame_width = 0;
@@ -117,12 +125,6 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	updateSequence((uint16)sequenceID);
 }
 
-Graphics::Surface *Actor::getCurrentFrame() {
-	frame_vram_x = _actorResource->getFrameHeader(sequenceTimer)->xOffset;
-	frame_vram_y = _actorResource->getFrameHeader(sequenceTimer)->yOffset;
-	return _actorResource->loadFrame(sequenceTimer);
-}
-
 void Actor::updateSequence(uint16 newSequenceID) {
 	_sequenceID = newSequenceID;
 	flags &= 0xfbf1;
@@ -142,9 +144,18 @@ void Actor::loadFrame(uint16 frameOffset) {
 	}
 
 	frame = _actorResource->loadFrameHeader(frameOffset);
-	surface = _actorResource->loadFrame(*frame);
+	uint16 paletteId = 0;
+	if (flags & Dragons::ACTOR_FLAG_4000) {
+		paletteId = 0xf7;
+	} else if (flags & Dragons::ACTOR_FLAG_8000) {
+		paletteId = 0xf1;
+	} else {
+		paletteId = 0;
+	}
+
+	surface = _actorResource->loadFrame(*frame, NULL); // TODO paletteId == 0xf1 ? getEngine()->getBackgroundPalette() : NULL);
 
-	debug(3, "load frame header: (%d,%d)", frame->width, frame->height);
+	debug(3, "ActorId: %d load frame header: (%d,%d) palette: %X", _actorID, frame->width, frame->height, paletteId);
 
 }
 
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 26252366fc..a37552661c 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -64,7 +64,8 @@ public:
 
 public:
 	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y);
-	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 field16);
+	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 priorityLayer);
+	Actor *loadActor(uint32 resourceId, uint16 actorId);
 	Actor *getActor(uint16 actorId);
 	void clearActorFlags(uint16 startingActorId);
 
@@ -83,11 +84,11 @@ public:
 	ActorFrame *frame;
 	Graphics::Surface *surface;
 	uint16 field_c;
-	int16 var_e;
+	int16 field_e;
 	uint16 sequenceTimer;
 	uint16 _sequenceID;
 	uint16 _sequenceID2;
-	int16 field16;
+	int16 priorityLayer;
 	uint16 flags;
 	int16 x_pos;
 	int16 y_pos;
@@ -114,7 +115,6 @@ public:
 
 	Actor(uint16 id);
 	void init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID);
-	Graphics::Surface *getCurrentFrame();
 	void updateSequence(uint16 newSequenceID);
 	void resetSequenceIP();
 	byte *getSeqIpAtOffset(uint32 offset);
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 44f866a3dc..8efed4d706 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -79,30 +79,28 @@ bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream
 		_frames[i].frameDataOffset = &dataStart[frameDataOffset];
 		_frames[i].flags = stream.readUint16LE();
 		_frames[i].field_c = stream.readUint16LE();
-//		debug("Frame[%d] field_0: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
-//				i, _frames[i].field_0, _frames[i].field_2, _frames[i].width, _frames[i].height, frameDataOffset, _frames[i].flags, _frames[i].field_c);
+		debug("Frame[%d] @%X, xOffset: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
+				i, offset, _frames[i].xOffset, _frames[i].yOffset, _frames[i].width, _frames[i].height, frameDataOffset, _frames[i].flags, _frames[i].field_c);
 	}
 
 	return false;
 }
 
-void ActorResource::writePixelBlock(byte *pixels, byte *data) {
-	pixels[0] = _palette[data[0] * 2];
-	pixels[1] = _palette[data[0] * 2 + 1];
-	pixels[2] = _palette[data[1] * 2];
-	pixels[3] = _palette[data[1] * 2 + 1];
-	pixels[4] = _palette[data[2] * 2];
-	pixels[5] = _palette[data[2] * 2 + 1];
-	pixels[6] = _palette[data[3] * 2];
-	pixels[7] = _palette[data[3] *2 + 1];
+void ActorResource::writePixelBlock(byte *pixels, byte *data, byte *palette) {
+	pixels[0] = palette[data[0] * 2];
+	pixels[1] = palette[data[0] * 2 + 1];
+	pixels[2] = palette[data[1] * 2];
+	pixels[3] = palette[data[1] * 2 + 1];
+	pixels[4] = palette[data[2] * 2];
+	pixels[5] = palette[data[2] * 2 + 1];
+	pixels[6] = palette[data[3] * 2];
+	pixels[7] = palette[data[3] * 2 + 1];
 }
 
-Graphics::Surface *ActorResource::loadFrame(uint16 frameNumber) {
-	assert (frameNumber < _framesCount);
-	return loadFrame(_frames[frameNumber]);
-}
-
-Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame) {
+Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame, byte *palette) {
+	if (!palette) {
+		palette = _palette;
+	}
 
 	Graphics::Surface *surface = new Graphics::Surface();
 	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
@@ -128,7 +126,7 @@ Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame) {
 			if (size != 0) {
 				for(int32 i = size; i != 0; i--) {
 					//TODO clean up this copy.
-					writePixelBlock(pixels, data);
+					writePixelBlock(pixels, data, palette);
 
 					data += 4;
 					pixels += 8;
@@ -143,11 +141,11 @@ Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame) {
 			if (size != 0) {
 				for(int32 i = size; i != 0; i--) {
 					//TODO write bytes to pixel data.
-					writePixelBlock(pixels, data);
+					writePixelBlock(pixels, data, palette);
 					pixels += 8;
 				}
-				data += 4;
 			}
+			data += 4;
 		}
 	}
 
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index 52bd9e8b7b..d588a2644c 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -32,8 +32,8 @@ class ActorResource;
 struct ActorFrame {
 	int16 xOffset;
 	int16 yOffset;
-	uint8 width;
-	uint8 height;
+	uint16 width;
+	uint16 height;
 	byte *frameDataOffset;
 	uint16 flags;
 	uint16 field_c;
@@ -61,8 +61,7 @@ private:
 
 public:
 	bool load(uint32 id, byte *dataStart, Common::SeekableReadStream &stream);
-	Graphics::Surface *loadFrame(uint16 frameNumber);
-	Graphics::Surface *loadFrame(ActorFrame &frameNumber);
+	Graphics::Surface *loadFrame(ActorFrame &frameNumber, byte *palette);
 	ActorFrame *loadFrameHeader(uint16 frameOffset);
 
 	ActorFrame *getFrameHeader(uint16 frameNumber);
@@ -71,7 +70,7 @@ public:
 	const char *getFilename();
 
 private:
-	void writePixelBlock(byte *pixels, byte *data);
+	void writePixelBlock(byte *pixels, byte *data, byte *palette);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 2e59720192..291b824563 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -54,10 +54,10 @@ void Dragons::PriorityLayer::load(TileMap &tileMap, byte *tiles) {
 int16 PriorityLayer::getPriority(Common::Point pos) {
 	pos.x = CLIP<int16>(pos.x, 0, _width - 1);
 	pos.y = CLIP<int16>(pos.y, 0, _height - 1);
-	const int16 tx = pos.x / 32, sx = pos.x % 32;
-	const int16 ty = pos.y / 8, sy = pos.y % 8;
-	uint16 mapIndex = READ_LE_UINT16(_map + 2 * (tx + ty * _mapWidth)) - 1;
-	return _values[mapIndex * 32 * 8 + sx + sy * 32];
+	const int16 tx = pos.x / TILE_WIDTH, sx = pos.x % TILE_WIDTH;
+	const int16 ty = pos.y / TILE_HEIGHT, sy = pos.y % TILE_HEIGHT;
+	uint16 mapIndex = READ_LE_UINT16(_map + 2 * (tx + ty * _mapWidth));
+	return _values[mapIndex * 32 * 8 + sx + sy * 32] + 1;
 
 }
 
@@ -73,7 +73,7 @@ bool Background::load(byte *dataStart, Common::SeekableReadStream &stream) {
 	stream.seek(0x308);
 
 	uint32 tilemapOffset = 0x324;
-	TileMap tileMap[3];
+	TileMap tileMap[4];
 	for(int i=0;i< 3;i++) {
 		tileMap[i].w = stream.readUint16LE();
 		tileMap[i].h = stream.readUint16LE();
@@ -87,10 +87,17 @@ bool Background::load(byte *dataStart, Common::SeekableReadStream &stream) {
 
 	uint32 finalSize = stream.readUint32LE();
 
-	_priorityLayer = new PriorityLayer();
-	_priorityLayer->load(tileMap[0], dataStart + tilemapOffset);
+	tileMap[3].w = tileMap[0].w;
+	tileMap[3].h = tileMap[0].h;
+	tileMap[3].size = tileMap[0].size;
+	tileMap[3].map = dataStart + tilemapOffset;
+	tileMap[3].tileIndexOffset = tileindexOffset;
 
 	uint32 tilesOffset = tilemapOffset + finalSize;
+
+	_priorityLayer = new PriorityLayer();
+	_priorityLayer->load(tileMap[3], dataStart + tilesOffset);
+
 	debug("Tiles: %X", tilesOffset);
 	debug("tileIndexOffset: %d", tileMap[0].tileIndexOffset);
 	_bgLayer = loadGfxLayer(tileMap[0], dataStart + tilesOffset);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 74383c290c..a967c98983 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -25,6 +25,7 @@
 #include "common/error.h"
 #include "actor.h"
 #include "actorresource.h"
+#include "background.h"
 #include "bigfile.h"
 #include "dragonrms.h"
 #include "dragonini.h"
@@ -37,6 +38,12 @@ namespace Dragons {
 
 #define DRAGONS_TICK_INTERVAL 17
 
+static DragonsEngine *_engine = nullptr;
+
+DragonsEngine *getEngine() {
+	return _engine;
+}
+
 DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_bigfileArchive = NULL;
 	_dragonRMS = NULL;
@@ -46,6 +53,8 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_flags = 0;
 	_unkFlags1 = 0;
 	_sequenceOpcodes = new SequenceOpcodes(this);
+	_engine = this;
+	_cursorPosition = Common::Point();
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -75,6 +84,25 @@ Common::Error DragonsEngine::run() {
 	_scene = new Scene(this, _screen, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
 	_flags = 0x1046;
 
+	Actor *cursor = _actorManager->loadActor(0, 0); //Load cursor
+	cursor->x_pos = _cursorPosition.x = 160;
+	cursor->y_pos = _cursorPosition.y = 100;
+	cursor->priorityLayer = 6;
+	cursor->flags = 0;
+	cursor->field_e = 0x100;
+	cursor->updateSequence(0);
+	cursor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 | Dragons::ACTOR_FLAG_200);
+
+	Actor *inventory = _actorManager->loadActor(1, 1); //Load inventory
+	inventory->x_pos = 2;
+	inventory->y_pos = 0;
+	inventory->priorityLayer = 6;
+	inventory->flags = 0;
+	inventory->field_e = 0x100;
+	inventory->updateSequence(0);
+	inventory->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 | Dragons::ACTOR_FLAG_200);
+
+
 	_scene->loadScene(0x12, 0x1e);
 
 	_scene->draw();
@@ -115,20 +143,20 @@ void DragonsEngine::updateHandler() {
 				DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 				if (flicker && _scene->contains(flicker) && flicker->actor->_actorID == i) {
 					if (priority < 8 || priority == 0x10) {
-						actor->field16 = priority;
+						actor->priorityLayer = priority;
 					}
 				} else {
 					if (priority != -1) {
-						actor->field16 = priority;
+						actor->priorityLayer = priority;
 					}
 				}
 
-				if (actor->field16 >= 0x11) {
-					actor->field16 = 0;
+				if (actor->priorityLayer >= 0x11) {
+					actor->priorityLayer = 0;
 				}
 
-				if (actor->field16 >= 9) {
-					actor->field16 -= 8;
+				if (actor->priorityLayer >= 9) {
+					actor->priorityLayer -= 8;
 				}
 			}
 
@@ -260,4 +288,9 @@ void DragonsEngine::clearUnkFlags(uint32 flags) {
 	_unkFlags1 &= ~flags;
 }
 
+byte *DragonsEngine::getBackgroundPalette() {
+	assert(_scene);
+	return _scene->getPalette();
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 0789b4c509..99107459e5 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -97,6 +97,7 @@ private:
 	uint32 _nextUpdatetime;
 	uint32 _flags;
 	uint32 _unkFlags1;
+	Common::Point _cursorPosition;
 
 public:
 	DragonsEngine(OSystem *syst);
@@ -116,6 +117,8 @@ public:
 	void setUnkFlags(uint32 flags);
 	void clearUnkFlags(uint32 flags);
 
+	byte *getBackgroundPalette();
+
 private:
 	void gameLoop();
 	void updateHandler();
@@ -123,6 +126,8 @@ private:
 	void wait();
 };
 
+DragonsEngine *getEngine();
+
 } // End of namespace Dragons
 
 #endif //SCUMMVM_DRAGONS_H
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 2f6190c244..6efef8f722 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -145,27 +145,36 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 
 void Scene::draw() {
 	Common::Rect rect(_camera.x, _camera.y, 320, 200);
-	_screen->copyRectToSurface(*_stage->getBgLayer(), 0, 0, rect);
-	_screen->copyRectToSurface(*_stage->getMgLayer(), 0, 0, rect);
-	_screen->copyRectToSurface(*_stage->getFgLayer(), 0, 0, rect);
-	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
-		DragonINI *ini = _dragonINIResource->getRecord(i);
-		if (ini->sceneId == _currentSceneId && (ini->field_1a_flags_maybe & 1)) {
-			Actor *actor = ini->actor;
+
+	for(uint16 priority = 1; priority < 16; priority++) {
+		if (priority == 1) {
+			_screen->copyRectToSurface(*_stage->getBgLayer(), 0, 0, rect);
+		} else if (priority == 2) {
+			_screen->copyRectToSurface(*_stage->getMgLayer(), 0, 0, rect);
+		} else if (priority == 3) {
+			_screen->copyRectToSurface(*_stage->getFgLayer(), 0, 0, rect);
+		}
+
+		for (uint16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
+			Actor *actor = _actorManager->getActor(i);
 			if (actor &&
 				actor->flags & Dragons::ACTOR_FLAG_40 &&
 				actor->surface) {
 				Graphics::Surface *s = actor->surface;
+				//TODO fix for scenes that are larger than a screen.
 				int x = actor->x_pos - actor->frame->xOffset;
 				int y = actor->y_pos - actor->frame->yOffset;
 				//int x = ini->x;// - actor->frame_vram_x;
 				//int y = ini->y;// - actor->frame_vram_y;
-				if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
-					debug(4, "Actor %d %s (%d, %d) w:%d h:%d", actor->_actorID, actor->_actorResource->getFilename(), x, y, s->w, s->h);
+				if (actor->priorityLayer == priority) { //} && x + s->w < 320 && y + s->h < 200) {
+					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
+						  y,
+						  s->w, s->h, actor->priorityLayer);
 					_screen->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
 				} else {
-					debug(4, "Actor (not displayed) %d %s (%d, %d)", actor->_actorID, actor->_actorResource->getFilename(), x, y);
-					// _stage->getFgLayer()->copyRectToSurface(*s, 0, 0, Common::Rect(s->w, s->h));
+					debug(4, "Actor (not displayed) %d %s (%d, %d) Priority: %d", actor->_actorID,
+						  actor->_actorResource->getFilename(),
+						  x, y, actor->priorityLayer);
 				}
 			}
 		}
@@ -181,4 +190,9 @@ bool Scene::contains(DragonINI *ini) {
 	return ini->sceneId == _currentSceneId;
 }
 
+byte *Scene::getPalette() {
+	assert(_stage);
+	return _stage->getPalette();
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 0adbdac56f..a27aa3f057 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -35,7 +35,7 @@ class BackgroundResourceLoader;
 class DragonINIResource;
 class BigfileArchive;
 class Screen;
-class DragonINI;
+struct DragonINI;
 
 class Scene {
 private:
@@ -58,6 +58,7 @@ public:
 	int16 getPriorityAtPosition(Common::Point pos);
 	void draw();
 	bool contains(DragonINI *ini);
+	byte *getPalette();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index cbee4a670c..41e39645d8 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -48,7 +48,19 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
 }
 
 void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect) {
-	copyRectToSurface(srcSurface.getBasePtr(srcRect.left, srcRect.top), srcSurface.pitch, destX, destY, srcRect.width(), srcRect.height());
+	Common::Rect clipRect = clipRectToScreen( destX,  destY, srcRect);
+	if (clipRect.width() == 0 || clipRect.height() == 0) {
+		return;
+	}
+
+	if (destX < 0) {
+		destX = 0;
+	}
+	if (destY < 0) {
+		destY = 0;
+	}
+
+	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, destX, destY, clipRect.width(), clipRect.height());
 }
 
 void Screen::copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height) {
@@ -75,4 +87,39 @@ void Screen::copyRectToSurface(const void *buffer, int srcPitch, int destX, int
 	}
 }
 
+Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect rect) {
+	int16 x, y, w, h;
+	x = rect.left;
+	y = rect.top;
+	w = rect.width();
+	h = rect.height();
+
+	if (destX >= 320) {
+		w = 0;
+	}
+
+	if (destY >= 200) {
+		h = 0;
+	}
+
+	if (destX < 0) {
+		w += destX;
+		x += destX;
+	}
+
+	if (destY < 0) {
+		h += destY;
+		y += destY;
+	}
+
+	if (destX + w >= 320) {
+		w -= (destX + w) - 320;
+	}
+
+	if (destY + h >= 200) {
+		h -= (destY + h) - 200;
+	}
+	return Common::Rect(x, y, x + w, y + h);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index e21efdd941..43bbe96971 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -41,6 +41,8 @@ public:
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect);
 	void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height);
 	void updateScreen();
+private:
+	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
 };
 
 } // End of namespace Dragons


Commit: 534fdd0640f61276526416e8514dd361aa9a29ae
    https://github.com/scummvm/scummvm/commit/534fdd0640f61276526416e8514dd361aa9a29ae
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Started work on script logic

Changed paths:
  A engines/dragons/dragonobd.cpp
  A engines/dragons/dragonobd.h
  A engines/dragons/scriptopcodes.cpp
  A engines/dragons/scriptopcodes.h
    engines/dragons/dragonrms.cpp
    engines/dragons/dragonrms.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/scene.cpp
    engines/dragons/scene.h


diff --git a/engines/dragons/dragonobd.cpp b/engines/dragons/dragonobd.cpp
new file mode 100644
index 0000000000..8e53fba769
--- /dev/null
+++ b/engines/dragons/dragonobd.cpp
@@ -0,0 +1,43 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "dragonobd.h"
+#include "bigfile.h"
+
+namespace Dragons {
+
+DragonOBD::DragonOBD(BigfileArchive *bigfileArchive) {
+	_data = bigfileArchive->load("dragon.obd", _dataSize);
+}
+
+byte *DragonOBD::getObdAtOffset(uint32 offset) {
+	assert(_data);
+	assert(offset < _dataSize);
+	return &_data[offset];
+}
+
+DragonOBD::~DragonOBD() {
+	if (_data) {
+		delete _data;
+	}
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/dragonobd.h b/engines/dragons/dragonobd.h
new file mode 100644
index 0000000000..461653e61a
--- /dev/null
+++ b/engines/dragons/dragonobd.h
@@ -0,0 +1,44 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 SCUMMVM_DRAGONOBD_H
+#define SCUMMVM_DRAGONOBD_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class BigfileArchive;
+
+class DragonOBD {
+private:
+	byte *_data;
+	uint32_t _dataSize;
+public:
+	virtual ~DragonOBD();
+
+	DragonOBD(BigfileArchive *bigfileArchive);
+	byte *getObdAtOffset(uint32 offset);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_DRAGONOBD_H
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
index 2e35cfa3cd..3fb6d45920 100644
--- a/engines/dragons/dragonrms.cpp
+++ b/engines/dragons/dragonrms.cpp
@@ -21,13 +21,14 @@
  */
 #include <common/memstream.h>
 #include "dragonrms.h"
+#include "dragonobd.h"
 #include "bigfile.h"
 
 namespace Dragons {
 
 #define DRAGON_RMS_STRUCT_SIZE 0x1c
 
-DragonRMS::DragonRMS(BigfileArchive *bigfileArchive) {
+DragonRMS::DragonRMS(BigfileArchive *bigfileArchive, DragonOBD *dragonOBD) : _dragonOBD(dragonOBD) {
 	uint32 fileSize;
 	byte *data = bigfileArchive->load("dragon.rms", fileSize);
 	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(data, fileSize, DisposeAfterUse::YES);
@@ -49,9 +50,23 @@ DragonRMS::DragonRMS(BigfileArchive *bigfileArchive) {
 }
 
 char *DragonRMS::getSceneName(uint32 sceneId) {
-	if(sceneId > 1 && sceneId - 2 < _count) {
-		return _rmsObjects[sceneId - 2]._sceneName;
-	}
-	return NULL;
+	return getRMS(sceneId)->_sceneName;
+}
+
+byte *DragonRMS::getObdData(uint32 sceneId) {
+	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_obdOffset);
+}
+
+byte *DragonRMS::getObdDataField10(uint32 sceneId) {
+	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_field10ObdOffset);
 }
+
+RMS *DragonRMS::getRMS(uint32 sceneId) {
+	sceneId &= 0x7fff;
+	assert(sceneId > 1);
+	assert(sceneId - 2 < _count);
+	return &_rmsObjects[sceneId - 2];
+}
+
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonrms.h b/engines/dragons/dragonrms.h
index 6c6458da07..4b9f214997 100644
--- a/engines/dragons/dragonrms.h
+++ b/engines/dragons/dragonrms.h
@@ -29,23 +29,30 @@ namespace Dragons {
 struct RMS {
 	int32 _field0;
 	char _sceneName[4];
-	int32 _obdOffset;
+	uint32 _obdOffset;
 	int32 _fieldC;
-	int32 _field10ObdOffset;
+	uint32 _field10ObdOffset;
 	int16 _inventoryBagPosition;
 	int32 _field16;
 	int16 _field1a;
 };
 
 class BigfileArchive;
+class DragonOBD;
 
 class DragonRMS {
 private:
 	int16 _count;
 	RMS *_rmsObjects;
+	DragonOBD *_dragonOBD;
 public:
-	DragonRMS(BigfileArchive *bigfileArchive);
+	DragonRMS(BigfileArchive *bigfileArchive, DragonOBD *dragonOBD);
 	char *getSceneName(uint32 sceneId);
+	byte *getObdData(uint32 sceneId);
+	byte *getObdDataField10(uint32 sceneId);
+
+private:
+	RMS *getRMS(uint32 sceneId);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index a967c98983..692714fd95 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -27,12 +27,14 @@
 #include "actorresource.h"
 #include "background.h"
 #include "bigfile.h"
-#include "dragonrms.h"
 #include "dragonini.h"
+#include "dragonobd.h"
+#include "dragonrms.h"
 #include "dragons.h"
 #include "scene.h"
 #include "screen.h"
 #include "sequenceopcodes.h"
+#include "scriptopcodes.h"
 
 namespace Dragons {
 
@@ -53,12 +55,14 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_flags = 0;
 	_unkFlags1 = 0;
 	_sequenceOpcodes = new SequenceOpcodes(this);
+	_scriptOpcodes = new ScriptOpcodes(this);
 	_engine = this;
 	_cursorPosition = Common::Point();
 }
 
 DragonsEngine::~DragonsEngine() {
 	delete _sequenceOpcodes;
+	delete _scriptOpcodes;
 }
 
 void DragonsEngine::updateEvents() {
@@ -77,11 +81,12 @@ void DragonsEngine::updateEvents() {
 Common::Error DragonsEngine::run() {
 	_screen = new Screen();
 	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
-	_dragonRMS = new DragonRMS(_bigfileArchive);
+	_dragonOBD = new DragonOBD(_bigfileArchive);
+	_dragonRMS = new DragonRMS(_bigfileArchive, _dragonOBD);
 	_dragonINIResource = new DragonINIResource(_bigfileArchive);
 	ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
 	_actorManager = new ActorManager(actorResourceLoader);
-	_scene = new Scene(this, _screen, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
+	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
 	_flags = 0x1046;
 
 	Actor *cursor = _actorManager->loadActor(0, 0); //Load cursor
@@ -293,4 +298,8 @@ byte *DragonsEngine::getBackgroundPalette() {
 	return _scene->getPalette();
 }
 
+bool DragonsEngine::isFlagSet(uint32 flag) {
+	return (bool)(_flags & flag);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 99107459e5..6cf8ee35a9 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -58,10 +58,13 @@ enum Flags {
 	ENGINE_FLAG_2 = 2,
 	ENGINE_FLAG_4 = 4,
 	ENGINE_FLAG_8 = 8,
-	ENGINE_FLAG_10 = 10,
-	ENGINE_FLAG_20 = 20,
-	ENGINE_FLAG_40 = 40,
-	ENGINE_FLAG_80 = 80
+	ENGINE_FLAG_10 = 0x10,
+	ENGINE_FLAG_20 = 0x20,
+	ENGINE_FLAG_40 = 0x40,
+	ENGINE_FLAG_80 = 0x80,
+
+	ENGINE_FLAG_80000 =   0x80000,
+	ENGINE_FLAG_100000 = 0x100000
 };
 
 enum UnkFlags {
@@ -69,31 +72,35 @@ enum UnkFlags {
 	ENGINE_UNK1_FLAG_2 = 2,
 	ENGINE_UNK1_FLAG_4 = 4,
 	ENGINE_UNK1_FLAG_8 = 8,
-	ENGINE_UNK1_FLAG_10 = 10,
-	ENGINE_UNK1_FLAG_20 = 20,
-	ENGINE_UNK1_FLAG_40 = 40,
-	ENGINE_UNK1_FLAG_80 = 80
+	ENGINE_UNK1_FLAG_10 = 0x10,
+	ENGINE_UNK1_FLAG_20 = 0x20,
+	ENGINE_UNK1_FLAG_40 = 0x40,
+	ENGINE_UNK1_FLAG_80 = 0x80
 };
 
 class BigfileArchive;
 class BackgroundResourceLoader;
+class DragonOBD;
 class DragonRMS;
 class DragonINIResource;
 class Scene;
 class Screen;
 class ActorManager;
 class SequenceOpcodes;
+class ScriptOpcodes;
 
 class DragonsEngine : public Engine {
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
+	DragonOBD *_dragonOBD;
 	DragonRMS *_dragonRMS;
 	DragonINIResource *_dragonINIResource;
 	BackgroundResourceLoader *_backgroundResourceLoader;
 	ActorManager *_actorManager;
 	Scene *_scene;
 	SequenceOpcodes *_sequenceOpcodes;
+	ScriptOpcodes *_scriptOpcodes;
 	uint32 _nextUpdatetime;
 	uint32 _flags;
 	uint32 _unkFlags1;
@@ -113,6 +120,7 @@ public:
 	void updateActorSequences();
 	void setFlags(uint32 flags);
 	void clearFlags(uint32 flags);
+	bool isFlagSet(uint32 flag);
 
 	void setUnkFlags(uint32 flags);
 	void clearUnkFlags(uint32 flags);
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 21d08f9ec8..1146013b65 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -7,10 +7,12 @@ MODULE_OBJS := \
     bigfile.o \
 	detection.o \
     dragonini.o \
+    dragonobd.o \
     dragonrms.o \
 	dragons.o \
 	scene.o \
 	screen.o \
+	scriptopcodes.o
 	sequenceopcodes.o
 
 MODULE_DIRS += \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 6efef8f722..41fc927427 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -26,12 +26,13 @@
 #include "dragonini.h"
 #include "screen.h"
 #include "actorresource.h"
+#include "scriptopcodes.h"
 
 namespace Dragons {
 
 
-Scene::Scene(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
-		: _vm(vm), _screen(screen), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
+Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
+		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
 	_backgroundLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 }
 
@@ -45,7 +46,13 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 	}
 
 	if (!(sceneId & 0x8000)) {
-		// TODO opcodes here.
+		byte *obd = _dragonRMS->getObdDataField10(sceneId);
+		ScriptOpCall scriptOpCall;
+		scriptOpCall._code = obd + 4;
+		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		_currentSceneId = -1;
+		_scriptOpcodes->runScript(scriptOpCall);
+		_currentSceneId = (uint16)(sceneId & 0x7fff);
 	}
 
 	_actorManager->clearActorFlags(2);
@@ -141,6 +148,17 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 		_currentSceneId = (uint16)(sceneId & 0x7fff);
 	}
 
+	if (!(sceneId & 0x8000)) {
+		byte *obd = _dragonRMS->getObdData(sceneId);
+		ScriptOpCall scriptOpCall;
+		scriptOpCall._code = obd + 4;
+		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		_currentSceneId = -1;
+		_scriptOpcodes->runScript(scriptOpCall);
+		_currentSceneId = (uint16)(sceneId & 0x7fff);
+
+	}
+
 }
 
 void Scene::draw() {
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index a27aa3f057..927183e67e 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -35,6 +35,7 @@ class BackgroundResourceLoader;
 class DragonINIResource;
 class BigfileArchive;
 class Screen;
+class ScriptOpcodes;
 struct DragonINI;
 
 class Scene {
@@ -47,12 +48,13 @@ private:
 	DragonRMS *_dragonRMS;
 	DragonINIResource *_dragonINIResource;
 	BackgroundResourceLoader *_backgroundLoader;
+	ScriptOpcodes *_scriptOpcodes;
 
-	uint16 _currentSceneId;
+	int16 _currentSceneId;
 	Common::Point _camera;
 
 public:
-	Scene(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
+	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
 
 	void loadScene(uint32 sceneId, uint32 cameraPointId);
 	int16 getPriorityAtPosition(Common::Point pos);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
new file mode 100644
index 0000000000..7c572aa993
--- /dev/null
+++ b/engines/dragons/scriptopcodes.cpp
@@ -0,0 +1,177 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "dragons/dragons.h"
+#include "dragons/scriptopcodes.h"
+#include "dragons/actor.h"
+#include "scriptopcodes.h"
+
+
+namespace Dragons {
+// ScriptOpCall
+
+void ScriptOpCall::skip(uint size) {
+	_code += size;
+}
+
+byte ScriptOpCall::readByte() {
+	return *_code++;
+}
+
+int16 ScriptOpCall::readSint16() {
+	int16 value = READ_LE_UINT16(_code);
+	_code += 2;
+	return value;
+}
+
+uint32 ScriptOpCall::readUint32() {
+	uint32 value = READ_LE_UINT32(_code);
+	_code += 4;
+	return value;
+}
+
+// ScriptOpcodes
+
+ScriptOpcodes::ScriptOpcodes(DragonsEngine *vm)
+	: _vm(vm), _data_80071f5c(0) {
+	initOpcodes();
+}
+
+ScriptOpcodes::~ScriptOpcodes() {
+	freeOpcodes();
+}
+
+void ScriptOpcodes::execOpcode(ScriptOpCall &scriptOpCall) {
+	if (!_opcodes[scriptOpCall._op])
+		error("ScriptOpcodes::execOpcode() Unimplemented opcode %d (0x%X)", scriptOpCall._op, scriptOpCall._op);
+	debug(3, "execScriptOpcode(%d) %s", scriptOpCall._op, _opcodeNames[scriptOpCall._op].c_str());
+	(*_opcodes[scriptOpCall._op])(scriptOpCall);
+}
+
+typedef Common::Functor1Mem<ScriptOpCall&, void, ScriptOpcodes> ScriptOpcodeI;
+#define OPCODE(op, func) \
+	_opcodes[op] = new ScriptOpcodeI(this, &ScriptOpcodes::func); \
+	_opcodeNames[op] = #func;
+
+void ScriptOpcodes::initOpcodes() {
+	// First clear everything
+	for (uint i = 0; i < DRAGONS_NUM_SCRIPT_OPCODES; ++i) {
+		_opcodes[i] = 0;
+	}
+	// Register opcodes
+	OPCODE(1, opUnk1);
+	OPCODE(19, opUnk13PropertiesRelated);
+	OPCODE(31, opPlayMusic);
+
+}
+
+#undef OPCODE
+
+void ScriptOpcodes::freeOpcodes() {
+	for (uint i = 0; i < DRAGONS_NUM_SCRIPT_OPCODES; ++i) {
+		delete _opcodes[i];
+	}
+}
+
+void ScriptOpcodes::updateReturn(ScriptOpCall &scriptOpCall, uint16 size) {
+	// scriptOpCall._deltaOfs = size * 2 + 2;
+}
+
+
+void ScriptOpcodes::runScript(ScriptOpCall &scriptOpCall) {
+	scriptOpCall._field8 = 0;
+	scriptOpCall._result = 0;
+	_data_80071f5c = 0;
+	executeScriptLoop(scriptOpCall);
+}
+
+void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
+
+	if (scriptOpCall._code >= scriptOpCall._codeEnd || scriptOpCall._result & 1) {
+		return;
+	}
+
+	if (Dragons::getEngine()->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
+		return;
+	}
+
+	if (Dragons::getEngine()->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
+		//TODO
+//		if (IsPressedStart(0)) {
+//			Dragons::getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
+//		}
+	}
+
+	uint16 opcode = READ_LE_INT16(scriptOpCall._code);
+
+	scriptOpCall._op = (byte) opcode;
+	if (opcode < DRAGONS_NUM_SCRIPT_OPCODES) {
+		execOpcode(scriptOpCall);
+	}
+
+	while (scriptOpCall._code < scriptOpCall._codeEnd && !(scriptOpCall._result & 1) && _data_80071f5c == 0) {
+
+		if (Dragons::getEngine()->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
+			return;
+		}
+
+		if (Dragons::getEngine()->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
+			//TODO
+//		if (IsPressedStart(0)) {
+//			Dragons::getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
+//		}
+		}
+
+		uint16 opcode = READ_LE_INT16(scriptOpCall._code);
+
+		if (opcode >= DRAGONS_NUM_SCRIPT_OPCODES) {
+			return; //TODO should continue here.
+		}
+		scriptOpCall._op = (byte) opcode;
+		execOpcode(scriptOpCall);
+	}
+}
+
+// Opcodes
+
+void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
+//	ARG_INT16(framePointer);
+//	debug(3, "set frame pointer %X", framePointer);
+//	actor->loadFrame((uint16)framePointer);
+//	actor->flags |= Dragons::ACTOR_FLAG_2;
+//	actor->sequenceTimer = actor->field_c;
+//	updateReturn(scriptOpCall, 1);
+}
+
+void ScriptOpcodes::opPlayMusic(ScriptOpCall &scriptOpCall) {
+	byte *code = scriptOpCall._code;
+	scriptOpCall._code += 4;
+	if (scriptOpCall._field8 == 0) {
+		//TODO play music here.
+	}
+}
+
+void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
+	//TODO sub_8002f02c()
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
new file mode 100644
index 0000000000..1d397d2716
--- /dev/null
+++ b/engines/dragons/scriptopcodes.h
@@ -0,0 +1,84 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 DRAGONS_SCRIPTOPCODES_H
+#define DRAGONS_SCRIPTOPCODES_H
+
+#include "common/func.h"
+#include "common/str.h"
+
+
+namespace Dragons {
+
+#define DRAGONS_NUM_SCRIPT_OPCODES 0x22
+class DragonsEngine;
+
+struct ScriptOpCall {
+	byte _op;
+	byte *_code;
+	byte *_codeEnd;
+	int _field8;
+	int _result;
+	void skip(uint size);
+	byte readByte();
+	int16 readSint16();
+	uint32 readUint32();
+};
+
+// Convenience macros
+#define ARG_SKIP(x) opCall.skip(x);
+#define ARG_BYTE(name) byte name = scriptOpCall.readByte(); debug(5, "ARG_BYTE(" #name " = %d)", name);
+#define ARG_INT8(name) int8 name = scriptOpCall.readByte(); debug(5, "ARG_INT8(" #name " = %d)", name);
+#define ARG_INT16(name) int16 name = scriptOpCall.readSint16(); debug(5, "ARG_INT16(" #name " = %d)", name);
+#define ARG_UINT32(name) uint32 name = scriptOpCall.readUint32(); debug(5, "ARG_UINT32(" #name " = %08X)", name);
+
+typedef Common::Functor1<ScriptOpCall&, void> ScriptOpcode;
+
+class ScriptOpcodes {
+public:
+	ScriptOpcodes(DragonsEngine *vm);
+	~ScriptOpcodes();
+	void runScript(ScriptOpCall &scriptOpCall);
+	void execOpcode(ScriptOpCall &scriptOpCall);
+protected:
+	DragonsEngine *_vm;
+	ScriptOpcode *_opcodes[DRAGONS_NUM_SCRIPT_OPCODES];
+	Common::String _opcodeNames[DRAGONS_NUM_SCRIPT_OPCODES];
+	int16 _data_80071f5c;
+
+	void initOpcodes();
+	void freeOpcodes();
+	void updateReturn(ScriptOpCall &scriptOpCall, uint16 size);
+	void executeScriptLoop(ScriptOpCall &scriptOpCall);
+
+
+	// Opcodes
+	void opUnk1(ScriptOpCall &scriptOpCall);
+
+	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
+	void opPlayMusic(ScriptOpCall &scriptOpCall);
+
+};
+
+} // End of namespace Dragons
+
+#endif // DRAGONS_SCRIPTOPCODES_H


Commit: 875d9f7bd7f707f78272fbd40f4c75fa1dde59f0
    https://github.com/scummvm/scummvm/commit/875d9f7bd7f707f78272fbd40f4c75fa1dde59f0
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on script opCodes

Changed paths:
  A engines/dragons/dragonflg.cpp
  A engines/dragons/dragonflg.h
  A engines/dragons/dragonvar.cpp
  A engines/dragons/dragonvar.h
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index b896cb4d53..00df78502c 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -163,4 +163,9 @@ byte *Actor::getSeqIpAtOffset(uint32 offset) {
 	return _actorResource->getSequenceDataAtOffset(offset);
 }
 
+void Actor::reset_maybe() {
+	flags = 0;
+	//TODO actor_find_by_resourceId_and_remove_resource_from_mem_maybe(resourceID);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index a37552661c..1ec6c93e21 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -119,6 +119,8 @@ public:
 	void resetSequenceIP();
 	byte *getSeqIpAtOffset(uint32 offset);
 	void loadFrame(uint16 frameOffset);
+	void reset_maybe();
+
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
new file mode 100644
index 0000000000..e1d7bdc2e1
--- /dev/null
+++ b/engines/dragons/dragonflg.cpp
@@ -0,0 +1,93 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "dragonflg.h"
+#include "bigfile.h"
+
+
+namespace Dragons {
+
+// Properties
+
+Properties::Properties()
+		: _count(0), _properties(0) {
+}
+
+void Properties::init(uint count, byte *properties) {
+	_count = count;
+	_properties = properties;
+}
+
+void Properties::clear() {
+	uint32 size = getSize();
+	for (uint32 i = 0; i < size; ++i) {
+		_properties[i] = 0;
+	}
+}
+
+bool Properties::get(uint32 propertyId) {
+	uint index;
+	byte mask;
+	getProperyPos(propertyId, index, mask);
+	return (_properties[index] & mask) != 0;
+}
+
+void Properties::set(uint32 propertyId, bool value) {
+	uint index;
+	byte mask;
+	getProperyPos(propertyId, index, mask);
+	if (value)
+		_properties[index] |= mask;
+	else
+		_properties[index] &= ~mask;
+}
+
+uint32 Properties::getSize() {
+	return (_count >> 3) + 1;
+}
+
+void Properties::getProperyPos(uint32 propertyId, uint &index, byte &mask) {
+	assert(propertyId < _count);
+	propertyId &= 0xFFFF;
+	index = propertyId >> 3;
+	mask = 1 << (propertyId & 7);
+}
+
+DragonFLG::DragonFLG(BigfileArchive *bigfileArchive) {
+	_data = bigfileArchive->load("dragon.flg", _dataSize);
+	properties.init(288, _data);
+}
+
+DragonFLG::~DragonFLG() {
+	if (_data) {
+		delete _data;
+	}
+}
+
+bool DragonFLG::get(uint32 propertyId) {
+	return properties.get(propertyId);
+}
+
+void DragonFLG::set(uint32 propertyId, bool value) {
+	properties.set(propertyId, value);
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/dragonflg.h b/engines/dragons/dragonflg.h
new file mode 100644
index 0000000000..c2e3a873fd
--- /dev/null
+++ b/engines/dragons/dragonflg.h
@@ -0,0 +1,60 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef SCUMMVM_DRAGONFLG_H
+#define SCUMMVM_DRAGONFLG_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class BigfileArchive;
+
+class Properties {
+public:
+	Properties();
+	void init(uint count, byte *properties);
+	void clear();
+	bool get(uint32 propertyId);
+	void set(uint32 propertyId, bool value);
+private:
+	uint _count;
+	byte *_properties;
+	uint32 getSize();
+	void getProperyPos(uint32 propertyId, uint &index, byte &mask);
+};
+
+class DragonFLG {
+private:
+	byte *_data;
+	uint32_t _dataSize;
+	Properties properties;
+public:
+	virtual ~DragonFLG();
+
+	DragonFLG(BigfileArchive *bigfileArchive);
+	bool get(uint32 propertyId);
+	void set(uint32 propertyId, bool value);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_DRAGONFLG_H
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 250634fd6a..7776ae1028 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -53,7 +53,7 @@ struct DragonINI
 		int16 field_e;
 		int16 field_10;
 		int16 field_12;
-		int16 field_14;
+		uint16 field_14;
 		int16 x;
 		int16 y;
 		uint16 field_1a_flags_maybe;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 692714fd95..3c7feb8bb1 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -27,9 +27,11 @@
 #include "actorresource.h"
 #include "background.h"
 #include "bigfile.h"
+#include "dragonflg.h"
 #include "dragonini.h"
 #include "dragonobd.h"
 #include "dragonrms.h"
+#include "dragonvar.h"
 #include "dragons.h"
 #include "scene.h"
 #include "screen.h"
@@ -55,7 +57,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_flags = 0;
 	_unkFlags1 = 0;
 	_sequenceOpcodes = new SequenceOpcodes(this);
-	_scriptOpcodes = new ScriptOpcodes(this);
+	_scriptOpcodes = NULL;
 	_engine = this;
 	_cursorPosition = Common::Point();
 }
@@ -81,11 +83,14 @@ void DragonsEngine::updateEvents() {
 Common::Error DragonsEngine::run() {
 	_screen = new Screen();
 	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
+	_dragonFLG = new DragonFLG(_bigfileArchive);
 	_dragonOBD = new DragonOBD(_bigfileArchive);
 	_dragonRMS = new DragonRMS(_bigfileArchive, _dragonOBD);
+	_dragonVAR = new DragonVAR(_bigfileArchive);
 	_dragonINIResource = new DragonINIResource(_bigfileArchive);
 	ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
 	_actorManager = new ActorManager(actorResourceLoader);
+	_scriptOpcodes = new ScriptOpcodes(this, _dragonFLG);
 	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
 	_flags = 0x1046;
 
@@ -118,7 +123,9 @@ Common::Error DragonsEngine::run() {
 	delete _scene;
 	delete _actorManager;
 	delete _backgroundResourceLoader;
+	delete _dragonFLG;
 	delete _dragonRMS;
+	delete _dragonVAR;
 	delete _bigfileArchive;
 	delete _screen;
 
@@ -302,4 +309,20 @@ bool DragonsEngine::isFlagSet(uint32 flag) {
 	return (bool)(_flags & flag);
 }
 
+DragonINI *DragonsEngine::getINI(uint32 index) {
+	return _dragonINIResource->getRecord(index);
+}
+
+uint16 DragonsEngine::getVar(uint16 offset) {
+	return _dragonVAR->getVar(offset);
+}
+
+uint16 DragonsEngine::getCurrentSceneId() {
+	return _scene->getSceneId();
+}
+
+void DragonsEngine::setVar(uint16 offset, uint16 value) {
+	return _dragonVAR->setVar(offset, value);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 6cf8ee35a9..be720c947c 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -80,24 +80,30 @@ enum UnkFlags {
 
 class BigfileArchive;
 class BackgroundResourceLoader;
+class DragonFLG;
 class DragonOBD;
 class DragonRMS;
+class DragonVAR;
 class DragonINIResource;
 class Scene;
 class Screen;
 class ActorManager;
 class SequenceOpcodes;
 class ScriptOpcodes;
+struct DragonINI;
 
 class DragonsEngine : public Engine {
+public:
+	DragonOBD *_dragonOBD;
+	ActorManager *_actorManager;
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
-	DragonOBD *_dragonOBD;
+	DragonFLG *_dragonFLG;
 	DragonRMS *_dragonRMS;
+	DragonVAR *_dragonVAR;
 	DragonINIResource *_dragonINIResource;
 	BackgroundResourceLoader *_backgroundResourceLoader;
-	ActorManager *_actorManager;
 	Scene *_scene;
 	SequenceOpcodes *_sequenceOpcodes;
 	ScriptOpcodes *_scriptOpcodes;
@@ -126,6 +132,10 @@ public:
 	void clearUnkFlags(uint32 flags);
 
 	byte *getBackgroundPalette();
+	DragonINI *getINI(uint32 index);
+	uint16 getVar(uint16 offset);
+	void setVar(uint16 offset, uint16 value);
+	uint16 getCurrentSceneId();
 
 private:
 	void gameLoop();
diff --git a/engines/dragons/dragonvar.cpp b/engines/dragons/dragonvar.cpp
new file mode 100644
index 0000000000..18df773006
--- /dev/null
+++ b/engines/dragons/dragonvar.cpp
@@ -0,0 +1,51 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "dragonvar.h"
+#include "bigfile.h"
+
+namespace Dragons {
+
+DragonVAR::DragonVAR(BigfileArchive *bigfileArchive) {
+	uint32 size;
+	_data = bigfileArchive->load("dragon.var", size);
+	assert(size == 30);
+}
+
+DragonVAR::~DragonVAR() {
+	if (_data) {
+		delete _data;
+	}
+}
+
+uint16 DragonVAR::getVar(uint16 offset) {
+	assert(_data);
+	assert(offset < 15);
+	return READ_LE_UINT16(_data + offset * 2);
+}
+
+void DragonVAR::setVar(uint16 offset, uint16 value) {
+	assert(_data);
+	assert(offset < 15);
+	WRITE_LE_INT16(_data + offset * 2, value);
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/dragonvar.h b/engines/dragons/dragonvar.h
new file mode 100644
index 0000000000..46991c09c1
--- /dev/null
+++ b/engines/dragons/dragonvar.h
@@ -0,0 +1,44 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 SCUMMVM_DRAGONVAR_H
+#define SCUMMVM_DRAGONVAR_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class BigfileArchive;
+
+class DragonVAR {
+private:
+	byte *_data;
+public:
+	virtual ~DragonVAR();
+
+	DragonVAR(BigfileArchive *bigfileArchive);
+	uint16 getVar(uint16 offset);
+	void setVar(uint16 offset, uint16 value);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_DRAGONVAR_H
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 1146013b65..501e8dbe74 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -6,9 +6,11 @@ MODULE_OBJS := \
     background.o \
     bigfile.o \
 	detection.o \
+    dragonflg.o \
     dragonini.o \
     dragonobd.o \
     dragonrms.o \
+    dragonvar.o \
 	dragons.o \
 	scene.o \
 	screen.o \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 41fc927427..859f20b8e4 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -153,10 +153,7 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 		ScriptOpCall scriptOpCall;
 		scriptOpCall._code = obd + 4;
 		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
-		_currentSceneId = -1;
 		_scriptOpcodes->runScript(scriptOpCall);
-		_currentSceneId = (uint16)(sceneId & 0x7fff);
-
 	}
 
 }
@@ -213,4 +210,8 @@ byte *Scene::getPalette() {
 	return _stage->getPalette();
 }
 
+uint16 Scene::getSceneId() {
+	return (uint16)_currentSceneId;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 927183e67e..7bfd781bd0 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -61,6 +61,7 @@ public:
 	void draw();
 	bool contains(DragonINI *ini);
 	byte *getPalette();
+	uint16 getSceneId();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 7c572aa993..7ecd708b39 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -21,6 +21,9 @@
  */
 
 #include "dragons/dragons.h"
+#include "dragons/dragonflg.h"
+#include "dragons/dragonini.h"
+#include "dragons/dragonobd.h"
 #include "dragons/scriptopcodes.h"
 #include "dragons/actor.h"
 #include "scriptopcodes.h"
@@ -51,8 +54,8 @@ uint32 ScriptOpCall::readUint32() {
 
 // ScriptOpcodes
 
-ScriptOpcodes::ScriptOpcodes(DragonsEngine *vm)
-	: _vm(vm), _data_80071f5c(0) {
+ScriptOpcodes::ScriptOpcodes(DragonsEngine *vm, DragonFLG *dragonFLG)
+	: _vm(vm), _dragonFLG(dragonFLG), _data_80071f5c(0) {
 	initOpcodes();
 }
 
@@ -78,7 +81,16 @@ void ScriptOpcodes::initOpcodes() {
 		_opcodes[i] = 0;
 	}
 	// Register opcodes
-	OPCODE(1, opUnk1);
+	// OPCODE(1, opUnk1);
+
+	OPCODE(4,  opExecuteScript);
+
+	OPCODE(7,  opUnk7);
+
+	OPCODE(10, opUnkA);
+
+	OPCODE(15, opUnkF);
+
 	OPCODE(19, opUnk13PropertiesRelated);
 	OPCODE(31, opPlayMusic);
 
@@ -110,11 +122,11 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 		return;
 	}
 
-	if (Dragons::getEngine()->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
+	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
 		return;
 	}
 
-	if (Dragons::getEngine()->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
+	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
 		//TODO
 //		if (IsPressedStart(0)) {
 //			Dragons::getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
@@ -130,11 +142,11 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 
 	while (scriptOpCall._code < scriptOpCall._codeEnd && !(scriptOpCall._result & 1) && _data_80071f5c == 0) {
 
-		if (Dragons::getEngine()->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
+		if (_vm->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
 			return;
 		}
 
-		if (Dragons::getEngine()->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
+		if (_vm->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
 			//TODO
 //		if (IsPressedStart(0)) {
 //			Dragons::getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
@@ -162,6 +174,30 @@ void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
 //	updateReturn(scriptOpCall, 1);
 }
 
+void ScriptOpcodes::opExecuteScript(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_UINT32(obdOffset);
+	ScriptOpCall newScriptOpCall;
+	byte *data =_vm->_dragonOBD->getObdAtOffset(obdOffset);
+
+	newScriptOpCall._code = data + 4;
+	newScriptOpCall._codeEnd = newScriptOpCall._code + READ_LE_UINT32(data);
+	newScriptOpCall._field8 = scriptOpCall._field8;
+	newScriptOpCall._result = 0;
+
+	executeScriptLoop(newScriptOpCall);
+}
+
+void ScriptOpcodes::opUnk7(ScriptOpCall &scriptOpCall) {
+	if (scriptOpCall._field8 == 0) {
+		opCode_Unk7(scriptOpCall);
+	} else {
+		scriptOpCall._code += 6;
+	}
+
+}
+
+
 void ScriptOpcodes::opPlayMusic(ScriptOpCall &scriptOpCall) {
 	byte *code = scriptOpCall._code;
 	scriptOpCall._code += 4;
@@ -171,7 +207,296 @@ void ScriptOpcodes::opPlayMusic(ScriptOpCall &scriptOpCall) {
 }
 
 void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
-	//TODO sub_8002f02c()
+	if (checkPropertyFlag(scriptOpCall)) {
+		scriptOpCall._code += 4;
+	} else {
+		scriptOpCall._code += 4 + READ_LE_INT16(scriptOpCall._code);
+	}
+}
+
+bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {
+	byte *codePtrOffsetA = scriptOpCall._code + 0xA;
+	byte *codePtrOffset2 = scriptOpCall._code + 2;
+
+	uint16 status = 0;
+	uint16 result = 0;
+
+	uint16 t2 = 0;
+	uint16 t0 = 0;
+
+	for(;;) {
+		byte value = 0;
+		if (*codePtrOffsetA & 1) {
+			uint32 propId = READ_LE_UINT16(codePtrOffset2) * 8 + READ_LE_UINT16(codePtrOffsetA - 6);
+			value = _dragonFLG->get(propId) ? 1 : 0;
+		} else {
+			debug(3, "Op13 get here!!");
+			if (*codePtrOffsetA & 2) {
+				debug(3, "Op13 get here!! & 2");
+				t2 = _vm->getVar(READ_LE_UINT16(codePtrOffset2));
+			}
+
+			if (*codePtrOffsetA & 4) {
+				t2 = getINIField(READ_LE_INT16(codePtrOffsetA - 6) - 1, READ_LE_INT16(codePtrOffset2));
+				debug(3, "Op13 get here!! & 4 %d, %d", READ_LE_INT16(codePtrOffsetA - 6), t2);
+
+			}
+
+			if (!(*codePtrOffsetA & 7)) {
+				debug(3, "Op13 get here!! & 7");
+				t2 = READ_LE_UINT16(codePtrOffsetA - 6);
+			}
+
+			if (*codePtrOffsetA & 8) {
+				debug(3, "Op13 get here!! & 8");
+				t0 = _vm->getVar(READ_LE_UINT16(codePtrOffsetA - 4));
+			}
+
+			if (*codePtrOffsetA & 0x10) {
+				debug(3, "Op13 get here!! & 0x10");
+				t0 = getINIField(READ_LE_INT16(codePtrOffsetA - 2) - 1, READ_LE_INT16(codePtrOffsetA - 4));
+			}
+
+			if (!(*codePtrOffsetA & 0x18)) {
+				debug(3, "Op13 get here!! & 0x18");
+				t0 = READ_LE_UINT16(codePtrOffsetA - 2);
+			}
+
+			if (*(codePtrOffsetA + 1) == 0 && t0 == t2) {
+				value = 1;
+			}
+
+			if (*(codePtrOffsetA + 1) == 1 && t2 < t0) {
+				value = 1;
+			}
+
+			if (*(codePtrOffsetA + 1) == 2 && t0 < t2) {
+				value = 1;
+			}
+
+		}
+
+		if (*codePtrOffsetA & 0x20) {
+			value ^= 1;
+		}
+
+		if (!(status & 0xffff)) {
+			result |= value;
+		} else {
+			result &= value;
+		}
+
+		status = (*codePtrOffsetA >> 6) & 1;
+
+		if (!(*codePtrOffsetA & 0x80)) {
+			break;
+		}
+
+		codePtrOffset2 += 0xa;
+		codePtrOffsetA += 0xa;
+	}
+
+	scriptOpCall._code = codePtrOffset2 + 0xa;
+
+	return (result & 0xffff) != 0;
+}
+
+void ScriptOpcodes::opUnkA(ScriptOpCall &scriptOpCall) {
+	if (scriptOpCall._field8 == 0) {
+		opCode_UnkA_setsProperty(scriptOpCall);
+	} else {
+		scriptOpCall._code += 0xC;
+	}
+}
+
+void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
+	scriptOpCall._result = 1;
+}
+
+void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+	ARG_INT16(field8);
+	ARG_INT8(fieldA);
+	ARG_INT8(fieldB);
+
+	enum S2Type {
+		notSet,
+		var,
+		ini
+	};
+
+	S2Type s2Type = notSet;
+
+	int16 s1 = 0;
+	int16 s2 = 0;
+
+	if (fieldA & 8) {
+		// VAR
+		s1 = _vm->getVar(field6 / 2);
+	} else if (fieldA & 0x10) {
+		// INI
+		s1 = getINIField(field8 - 1, field6);
+	} else {
+		s1 = field8;
+	}
+
+	if (fieldA & 1) {
+		debug(3, "fieldA & 1");
+		bool flagValue = s1 != 0 ? true : false;
+		_dragonFLG->set(field2 * 8 + field4, flagValue);
+	}
+
+	if (fieldA & 2) {
+		debug(3, "fieldA & 2");
+		s2Type = var;
+		s2 = _vm->getVar(field2);
+	}
+
+	if (fieldA & 4) {
+		debug(3, "fieldA & 4");
+		s2Type = ini;
+		s2 = getINIField(field4 - 1, field2);
+		DragonINI *ini = _vm->getINI(field4 - 1);
+
+		if (field2 == 0x1a && ini->field_1a_flags_maybe & 1 && ini->sceneId == _vm->getCurrentSceneId()) {
+			if (s1 & 2) {
+				ini->actor->flags |= Dragons::ACTOR_FLAG_80;
+				ini->actor->field_e = 0x100;
+			} else {
+				ini->actor->flags &= ~Dragons::ACTOR_FLAG_80;
+			}
+
+			if (s1 & 4) {
+				ini->actor->flags |= Dragons::ACTOR_FLAG_8000;
+			} else {
+				ini->actor->flags &= ~Dragons::ACTOR_FLAG_8000;
+			}
+		}
+
+		if (fieldA & 4 && field2 == 0 && !(ini->field_1a_flags_maybe & 1) && ini->sceneId == _vm->getCurrentSceneId()) {
+			if (s1 == -1) {
+				if (ini->iptIndex_maybe != -1) {
+					// TODO ipt_img_file_related_3(ini->iptIndex_maybe);
+				}
+			} else {
+				// TODO ipt_img_file_related_2(s1);
+			}
+		}
+	}
+
+	if (s2Type != notSet) {
+		if (fieldB == 1) {
+			s2 += s1;
+		} else {
+			if (fieldB < 2) {
+				if (fieldB == 0) {
+					s2 = s1;
+				}
+			} else {
+				if (fieldB == 2) {
+					s2 -= s1;
+				} else {
+					if (fieldB == 3) {
+						//TODO s2 = sub_80023830(s1);
+					}
+				}
+			}
+		}
+
+		if (s2Type == ini) {
+			setINIField(field4 - 1, field2, s2);
+		} else  { //var type
+			_vm->setVar(field2, s2);
+		}
+	}
 }
 
+uint16 ScriptOpcodes::getINIField(uint32 iniIndex, uint16 fieldOffset) {
+	DragonINI *ini = _vm->getINI(iniIndex);
+
+	switch (fieldOffset) {
+		case 0x14 : return ini->field_14;
+		case 0x1A : return ini->field_1a_flags_maybe;
+		case 0x20 : return ini->field_20_actor_field_14;
+		default: error("Invalid fieldOffset %d", fieldOffset);
+	}
+}
+
+void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 value) {
+	DragonINI *ini = _vm->getINI(iniIndex);
+
+	switch (fieldOffset) {
+		case 0x14 : ini->field_14 = value; break;
+		case 0x1A : ini->field_1a_flags_maybe = value; break;
+		case 0x20 : ini->field_20_actor_field_14 = value; break;
+		default: error("Invalid fieldOffset %X", fieldOffset);
+	}
+
+}
+
+void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(sceneId); //sceneId
+
+	uint16 currentScene = _vm->getCurrentSceneId();
+	DragonINI *ini = _vm->getINI(field2 - 1);
+	if (!(field0 & 0x8000)) {
+
+		if (ini->field_1a_flags_maybe & 1) {
+			if (ini->sceneId == currentScene) {
+				assert(ini->actor);
+				ini->actor->reset_maybe();
+			}
+			if (sceneId == currentScene) {
+				ini->actor = _vm->_actorManager->loadActor(ini->actorResourceId, ini->frameIndexId_maybe, ini->x, ini->y, 0);
+				ini->actor->_sequenceID2 = ini->field_20_actor_field_14;
+				if (ini->field_1a_flags_maybe & 2) {
+					ini->actor->flags |= Dragons::ACTOR_FLAG_80;
+				} else {
+					ini->actor->flags &= ~Dragons::ACTOR_FLAG_80;
+				}
+
+				if (ini->field_1a_flags_maybe & 0x20) {
+					ini->actor->flags |= Dragons::ACTOR_FLAG_100;
+				} else {
+					ini->actor->flags &= ~Dragons::ACTOR_FLAG_100;
+				}
+
+				if (ini->field_1a_flags_maybe & 4) {
+					ini->actor->flags |= Dragons::ACTOR_FLAG_8000;
+				} else {
+					ini->actor->flags &= ~Dragons::ACTOR_FLAG_8000;
+				}
+
+				if (ini->field_1a_flags_maybe & 0x100) {
+					ini->actor->flags |= Dragons::ACTOR_FLAG_4000;
+				} else {
+					ini->actor->flags &= ~Dragons::ACTOR_FLAG_4000;
+				}
+			}
+		} else {
+			if (ini->sceneId == currentScene && ini->iptIndex_maybe != -1) {
+				//TODO ipt_img_file_related_3(ini->iptIndex_maybe);
+			}
+			if (sceneId == currentScene && ini->iptIndex_maybe != -1) {
+				// TODO ipt_img_file_related_2(ini->iptIndex_maybe);
+			}
+		}
+
+		if (ini->sceneId == 1) {
+			//TODO 0x8002d218
+		}
+
+		if (sceneId == 1) {
+			// TODO 0x8002d2f4
+		}
+	}
+	ini->sceneId = sceneId;
+}
+
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 1d397d2716..c3ea42632f 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -45,7 +45,7 @@ struct ScriptOpCall {
 };
 
 // Convenience macros
-#define ARG_SKIP(x) opCall.skip(x);
+#define ARG_SKIP(x) scriptOpCall.skip(x);
 #define ARG_BYTE(name) byte name = scriptOpCall.readByte(); debug(5, "ARG_BYTE(" #name " = %d)", name);
 #define ARG_INT8(name) int8 name = scriptOpCall.readByte(); debug(5, "ARG_INT8(" #name " = %d)", name);
 #define ARG_INT16(name) int16 name = scriptOpCall.readSint16(); debug(5, "ARG_INT16(" #name " = %d)", name);
@@ -53,14 +53,17 @@ struct ScriptOpCall {
 
 typedef Common::Functor1<ScriptOpCall&, void> ScriptOpcode;
 
+class DragonFLG;
+
 class ScriptOpcodes {
 public:
-	ScriptOpcodes(DragonsEngine *vm);
+	ScriptOpcodes(DragonsEngine *vm, DragonFLG *dragonFLG);
 	~ScriptOpcodes();
 	void runScript(ScriptOpCall &scriptOpCall);
 	void execOpcode(ScriptOpCall &scriptOpCall);
 protected:
 	DragonsEngine *_vm;
+	DragonFLG *_dragonFLG;
 	ScriptOpcode *_opcodes[DRAGONS_NUM_SCRIPT_OPCODES];
 	Common::String _opcodeNames[DRAGONS_NUM_SCRIPT_OPCODES];
 	int16 _data_80071f5c;
@@ -73,10 +76,24 @@ protected:
 
 	// Opcodes
 	void opUnk1(ScriptOpCall &scriptOpCall);
+	void opExecuteScript(ScriptOpCall &scriptOpCall); //op 4
+
+	void opUnk7(ScriptOpCall &scriptOpCall);
+
+	void opUnkA(ScriptOpCall &scriptOpCall);
+
+	void opUnkF(ScriptOpCall &scriptOpCall);
 
 	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
 
+	bool checkPropertyFlag(ScriptOpCall &scriptOpCall);
+	void opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall);
+	void opCode_Unk7(ScriptOpCall &scriptOpCall);
+
+	// misc
+	uint16 getINIField(uint32 iniIndex, uint16 fieldOffset);
+	void setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 value);
 };
 
 } // End of namespace Dragons


Commit: a25ee6f255a8613ae7d66c29a89eb38866eb9786
    https://github.com/scummvm/scummvm/commit/a25ee6f255a8613ae7d66c29a89eb38866eb9786
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add start of special opcode support

Changed paths:
  A engines/dragons/specialopcodes.cpp
  A engines/dragons/specialopcodes.h
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragonini.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 00df78502c..64a89827a5 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -168,4 +168,9 @@ void Actor::reset_maybe() {
 	//TODO actor_find_by_resourceId_and_remove_resource_from_mem_maybe(resourceID);
 }
 
+void Actor::pathfinding_maybe(int16 x, int16 y, int16 unk) {
+	//TODO implement me.
+	error("Implement pathfinding_maybe()");
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 1ec6c93e21..fb45e2bbed 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -103,7 +103,7 @@ public:
 	uint16 field_76;
 	uint16 field_78;
 	uint16 field_7a;
-	uint32 field_7c;
+	int32 field_7c;
 	uint16 field_80;
 	uint16 frame_vram_x;
 	uint16 frame_vram_y;
@@ -120,6 +120,7 @@ public:
 	byte *getSeqIpAtOffset(uint32 offset);
 	void loadFrame(uint16 frameOffset);
 	void reset_maybe();
+	void pathfinding_maybe(int16 x, int16 y, int16 unk);
 
 };
 
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index b16562cf1c..7b774f9bb0 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -36,12 +36,13 @@ DragonINIResource::DragonINIResource(BigfileArchive *bigfileArchive) {
 	_dragonINI = new DragonINI[_count];
 
 	for(int i=0; i < _count; i++) {
+		_dragonINI[i].id = (uint16)i;
 		_dragonINI[i].iptIndex_maybe = readStream->readSint16LE();
 		_dragonINI[i].field_2 = readStream->readSint16LE();
 		_dragonINI[i].actorResourceId = readStream->readSint16LE();
 		_dragonINI[i].frameIndexId_maybe = readStream->readSint16LE();
 		_dragonINI[i].field_8 = readStream->readSint16LE();
-		readStream->readUint16LE(); // actorId
+		assert(readStream->readUint16LE() == 0); // actorId
 		_dragonINI[i].actor = NULL;
 		_dragonINI[i].sceneId = readStream->readUint16LE();
 		_dragonINI[i].field_e = readStream->readSint16LE();
@@ -69,4 +70,9 @@ void DragonINIResource::setFlickerRecord(DragonINI *dragonINI) {
 	_flickerINI = dragonINI;
 }
 
+bool DragonINIResource::isFlicker(uint16 index) {
+	return _flickerINI && _flickerINI->id == index;
+}
+
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 7776ae1028..4fb0ca183c 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -43,6 +43,7 @@ enum IniFlags {
 
 struct DragonINI
 	{
+		uint16 id;
 		int16 iptIndex_maybe;
 		int16 field_2;
 		uint16 actorResourceId;
@@ -75,6 +76,11 @@ public:
 	DragonINI *getFlickerRecord() {
 		return _flickerINI;
 	}
+	bool isFlicker(uint16 index);
+	bool isFlicker(DragonINI *ini) {
+		return isFlicker(ini->id);
+	}
+
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 3c7feb8bb1..315204e4f2 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -103,6 +103,8 @@ Common::Error DragonsEngine::run() {
 	cursor->updateSequence(0);
 	cursor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 | Dragons::ACTOR_FLAG_200);
 
+	_dragonINIResource->getFlickerRecord()->actor = cursor; //TODO is this correct?
+
 	Actor *inventory = _actorManager->loadActor(1, 1); //Load inventory
 	inventory->x_pos = 2;
 	inventory->y_pos = 0;
@@ -112,7 +114,8 @@ Common::Error DragonsEngine::run() {
 	inventory->updateSequence(0);
 	inventory->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 | Dragons::ACTOR_FLAG_200);
 
-
+	_dragonINIResource->getFlickerRecord()->sceneId = 0x12; //TODO
+	_sceneId1 = 0x12;
 	_scene->loadScene(0x12, 0x1e);
 
 	_scene->draw();
@@ -134,9 +137,42 @@ Common::Error DragonsEngine::run() {
 }
 
 void DragonsEngine::gameLoop() {
+	_counter = 0;
+	bit_flags_8006fbd8 = 0;
 	while (!shouldQuit()) {
 		updateHandler();
 		updateEvents();
+
+		if (getCurrentSceneId() != 2) {
+			_sceneId1 = getCurrentSceneId();
+		}
+
+		_counter++;
+		DragonINI *flickerIni = _dragonINIResource->getFlickerRecord();
+		if (_counter >= 1200 && flickerIni->actor->resourceID == 0xe) { // 0xe == flicker.act
+			Actor *actor = flickerIni->actor;
+			actor->_sequenceID2 = 2;
+			flickerIni->field_20_actor_field_14 = 2;
+
+			actor->updateSequence(getINI(0xc2)->sceneId == 1 ? 0x30 : 2);
+			_counter = 0;
+			setFlags(Dragons::ENGINE_FLAG_80000000);
+		}
+
+		if (_flags & Dragons::ENGINE_FLAG_80000000) {
+			if (flickerIni->actor->flags & Dragons::ACTOR_FLAG_4) {
+				_counter = 0;
+				clearFlags(Dragons::ENGINE_FLAG_80000000);
+			}
+		}
+
+		if (bit_flags_8006fbd8 == 0) {
+			setFlags(Dragons::ENGINE_FLAG_8);
+		}
+
+		if (flickerIni->sceneId == getCurrentSceneId()) {
+			debug("get here");
+		}
 		_scene->draw();
 		_screen->updateScreen();
 		wait();
@@ -246,7 +282,7 @@ void DragonsEngine::wait() {
 
 void DragonsEngine::updateActorSequences() {
 	if (!(_flags & Dragons::ENGINE_FLAG_4)) {
-//TODO 		return;
+		return;
 	}
 
 	//TODO ResetRCnt(0xf2000001);
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index be720c947c..dd36234be5 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -64,7 +64,8 @@ enum Flags {
 	ENGINE_FLAG_80 = 0x80,
 
 	ENGINE_FLAG_80000 =   0x80000,
-	ENGINE_FLAG_100000 = 0x100000
+	ENGINE_FLAG_100000 = 0x100000,
+	ENGINE_FLAG_80000000 = 80000000
 };
 
 enum UnkFlags {
@@ -96,13 +97,13 @@ class DragonsEngine : public Engine {
 public:
 	DragonOBD *_dragonOBD;
 	ActorManager *_actorManager;
+	DragonINIResource *_dragonINIResource;
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
 	DragonFLG *_dragonFLG;
 	DragonRMS *_dragonRMS;
 	DragonVAR *_dragonVAR;
-	DragonINIResource *_dragonINIResource;
 	BackgroundResourceLoader *_backgroundResourceLoader;
 	Scene *_scene;
 	SequenceOpcodes *_sequenceOpcodes;
@@ -111,6 +112,9 @@ private:
 	uint32 _flags;
 	uint32 _unkFlags1;
 	Common::Point _cursorPosition;
+	uint16 _sceneId1;
+	uint32 _counter;
+	uint32 bit_flags_8006fbd8;
 
 public:
 	DragonsEngine(OSystem *syst);
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 501e8dbe74..8139ab4c1b 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -14,8 +14,9 @@ MODULE_OBJS := \
 	dragons.o \
 	scene.o \
 	screen.o \
-	scriptopcodes.o
-	sequenceopcodes.o
+	scriptopcodes.o \
+	sequenceopcodes.o \
+	specialopcodes.o
 
 MODULE_DIRS += \
 	engines/dragons
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 7ecd708b39..5d1f07c543 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -25,6 +25,7 @@
 #include "dragons/dragonini.h"
 #include "dragons/dragonobd.h"
 #include "dragons/scriptopcodes.h"
+#include "dragons/specialopcodes.h"
 #include "dragons/actor.h"
 #include "scriptopcodes.h"
 
@@ -56,11 +57,13 @@ uint32 ScriptOpCall::readUint32() {
 
 ScriptOpcodes::ScriptOpcodes(DragonsEngine *vm, DragonFLG *dragonFLG)
 	: _vm(vm), _dragonFLG(dragonFLG), _data_80071f5c(0) {
+	_specialOpCodes = new SpecialOpcodes(_vm);
 	initOpcodes();
 }
 
 ScriptOpcodes::~ScriptOpcodes() {
 	freeOpcodes();
+	delete _specialOpCodes;
 }
 
 void ScriptOpcodes::execOpcode(ScriptOpCall &scriptOpCall) {
@@ -88,6 +91,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(7,  opUnk7);
 
 	OPCODE(10, opUnkA);
+	OPCODE(11, opRunSpecialOpCode);
 
 	OPCODE(15, opUnkF);
 
@@ -309,8 +313,79 @@ void ScriptOpcodes::opUnkA(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opRunSpecialOpCode(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(specialOpCode);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	if (specialOpCode >= 140) {
+		error("Invalid Special OpCode %d", specialOpCode);
+	}
+
+	debug("Special opCode %X", specialOpCode);
+	_specialOpCodes->run(specialOpCode);
+}
+
 void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
-	scriptOpCall._result = 1;
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+	ARG_INT16(field8);
+	ARG_INT16(fieldA);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	int32 s3 = 0;
+	DragonINI *ini = _vm->getINI(field2 - 1);
+
+	if (field6 & 0x8000) {
+		s3 = 0 > (field6 ^ 0xffff) ? 1 : 0;
+	}
+
+	if (field4 != -1) {
+		if (field6 != -1) {
+			if (!(field0 & 0x8000)) {
+				assert(ini->actor);
+				ini->actor->flags |= Dragons::ACTOR_FLAG_800;
+				ini->actor->updateSequence(field6 & 0x7fff);
+			}
+			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 0x10 : (field4 & 0x7fff) << 7;
+
+			if (_vm->_dragonINIResource->isFlicker(ini)) {
+
+			}
+			bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
+			ini->actor->pathfinding_maybe(field8, fieldA, isFlicker ? 0 : 1);
+
+			if(s3 == 0) {
+				while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
+					//TODO
+					//wait a game tick
+					error("Wait a game tick here");
+				}
+			}
+			ini->x = field8;
+			ini->y = fieldA;
+			ini->actor->flags &= ~Dragons::ACTOR_FLAG_800;
+		}
+	} else {
+		assert(ini->actor);
+		ini->x = field8;
+		ini->actor->x_pos = field8;
+		ini->y = fieldA;
+		ini->actor->y_pos = fieldA;
+
+		if (field4 != field6) {
+			ini->actor->field_7c = field4;
+		}
+		ini->actor->updateSequence(field6 & 0x7fff);
+	}
 }
 
 void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
@@ -380,9 +455,11 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 			if (s1 == -1) {
 				if (ini->iptIndex_maybe != -1) {
 					// TODO ipt_img_file_related_3(ini->iptIndex_maybe);
+					error("TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
 				}
 			} else {
 				// TODO ipt_img_file_related_2(s1);
+				error("TODO ipt_img_file_related_2(s1);");
 			}
 		}
 	}
@@ -401,6 +478,7 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 				} else {
 					if (fieldB == 3) {
 						//TODO s2 = sub_80023830(s1);
+						error("TODO s2 = sub_80023830(s1);");
 					}
 				}
 			}
@@ -481,9 +559,11 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 		} else {
 			if (ini->sceneId == currentScene && ini->iptIndex_maybe != -1) {
 				//TODO ipt_img_file_related_3(ini->iptIndex_maybe);
+				error("//TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
 			}
 			if (sceneId == currentScene && ini->iptIndex_maybe != -1) {
 				// TODO ipt_img_file_related_2(ini->iptIndex_maybe);
+				error("// TODO ipt_img_file_related_2(ini->iptIndex_maybe);");
 			}
 		}
 
@@ -499,4 +579,5 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 }
 
 
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index c3ea42632f..090a57f6c8 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -54,6 +54,7 @@ struct ScriptOpCall {
 typedef Common::Functor1<ScriptOpCall&, void> ScriptOpcode;
 
 class DragonFLG;
+class SpecialOpcodes;
 
 class ScriptOpcodes {
 public:
@@ -64,6 +65,7 @@ public:
 protected:
 	DragonsEngine *_vm;
 	DragonFLG *_dragonFLG;
+	SpecialOpcodes *_specialOpCodes;
 	ScriptOpcode *_opcodes[DRAGONS_NUM_SCRIPT_OPCODES];
 	Common::String _opcodeNames[DRAGONS_NUM_SCRIPT_OPCODES];
 	int16 _data_80071f5c;
@@ -81,6 +83,7 @@ protected:
 	void opUnk7(ScriptOpCall &scriptOpCall);
 
 	void opUnkA(ScriptOpCall &scriptOpCall);
+	void opRunSpecialOpCode(ScriptOpCall &scriptOpCall); //op B
 
 	void opUnkF(ScriptOpCall &scriptOpCall);
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
new file mode 100644
index 0000000000..a944c254a9
--- /dev/null
+++ b/engines/dragons/specialopcodes.cpp
@@ -0,0 +1,98 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "dragons/dragons.h"
+#include "dragons/dragonflg.h"
+#include "dragons/dragonini.h"
+#include "dragons/dragonobd.h"
+#include "dragons/specialopcodes.h"
+#include "dragons/actor.h"
+#include "specialopcodes.h"
+
+
+namespace Dragons {
+
+// SpecialOpcodes
+
+SpecialOpcodes::SpecialOpcodes(DragonsEngine *vm)
+	: _vm(vm) {
+	initOpcodes();
+}
+
+SpecialOpcodes::~SpecialOpcodes() {
+	freeOpcodes();
+}
+
+void SpecialOpcodes::run(int16 op) {
+	if (!_opcodes[op])
+		error("SpecialOpcodes::execOpcode() Unimplemented opcode %d (0x%X)", op, op);
+	debug(3, "run(%d) %s", op, _opcodeNames[op].c_str());
+	(*_opcodes[op])();
+}
+
+typedef Common::Functor0Mem<void, SpecialOpcodes> SpecialOpcodeI;
+#define OPCODE(op, func) \
+	_opcodes[op] = new SpecialOpcodeI(this, &SpecialOpcodes::func); \
+	_opcodeNames[op] = #func;
+
+void SpecialOpcodes::initOpcodes() {
+	// First clear everything
+	for (uint i = 0; i < DRAGONS_NUM_SPECIAL_OPCODES; ++i) {
+		_opcodes[i] = 0;
+	}
+	// Register opcodes
+	// OPCODE(1, opUnk1);
+	OPCODE(3, spcClearEngineFlag10);
+	OPCODE(9, spcUnk9);
+	OPCODE(20, spcClearEngineFlag8);
+}
+
+#undef OPCODE
+
+void SpecialOpcodes::freeOpcodes() {
+	for (uint i = 0; i < DRAGONS_NUM_SPECIAL_OPCODES; ++i) {
+		delete _opcodes[i];
+	}
+}
+
+// Opcodes
+
+void SpecialOpcodes::spcClearEngineFlag10() {
+	_vm->clearFlags(Dragons::ENGINE_FLAG_10);
+}
+
+void SpecialOpcodes::spcUnk9() {
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+	assert(flicker);
+	flicker->field_1a_flags_maybe |= 0x20;
+	assert(flicker->actor);
+	flicker->actor->flags |= Dragons::ACTOR_FLAG_100;
+	flicker->actor->priorityLayer = 0;
+	_vm->getINI(1)->field_1a_flags_maybe |= 0x20;
+}
+
+void SpecialOpcodes::spcClearEngineFlag8() {
+	_vm->clearFlags(Dragons::ENGINE_FLAG_8);
+}
+
+
+} // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
new file mode 100644
index 0000000000..9be62953fd
--- /dev/null
+++ b/engines/dragons/specialopcodes.h
@@ -0,0 +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 DRAGONS_SPECIALOPCODES_H
+#define DRAGONS_SPECIALOPCODES_H
+
+#include "common/func.h"
+#include "common/str.h"
+
+
+namespace Dragons {
+
+#define DRAGONS_NUM_SPECIAL_OPCODES 0x8c
+
+class DragonsEngine;
+
+typedef Common::Functor0<void> SpecialOpcode;
+
+class SpecialOpcodes {
+public:
+	SpecialOpcodes(DragonsEngine *vm);
+	~SpecialOpcodes();
+	void run(int16 opcode);
+protected:
+	DragonsEngine *_vm;
+	SpecialOpcode *_opcodes[DRAGONS_NUM_SPECIAL_OPCODES];
+	Common::String _opcodeNames[DRAGONS_NUM_SPECIAL_OPCODES];
+
+	void initOpcodes();
+	void freeOpcodes();
+
+	// Opcodes
+	void spcClearEngineFlag10(); // 3
+
+	void spcUnk9();
+
+	void spcClearEngineFlag8(); // 0x14
+
+};
+
+} // End of namespace Dragons
+
+#endif // DRAGONS_SPECIALOPCODES_H


Commit: 22d15cc7ca4d3bab6a17c70b463de414e5f9b474
    https://github.com/scummvm/scummvm/commit/22d15cc7ca4d3bab6a17c70b463de414e5f9b474
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Adding class for loading dragon.img file data

Changed paths:
  A engines/dragons/dragonimg.cpp
  A engines/dragons/dragonimg.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk


diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
new file mode 100644
index 0000000000..ec53e3c434
--- /dev/null
+++ b/engines/dragons/dragonimg.cpp
@@ -0,0 +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.
+ *
+ */
+#include <common/memstream.h>
+#include "dragonimg.h"
+#include "bigfile.h"
+
+namespace Dragons {
+
+DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
+	uint32 fileSize;
+	byte *iptData = bigfileArchive->load("dragon.ipt", fileSize);
+	Common::SeekableReadStream *iptReadStream = new Common::MemoryReadStream(iptData, fileSize, DisposeAfterUse::YES);
+
+	_count = fileSize / 4;
+
+	byte *imgData = bigfileArchive->load("dragon.img", fileSize);
+	Common::SeekableReadStream *imgReadStream = new Common::MemoryReadStream(imgData, fileSize, DisposeAfterUse::YES);
+
+
+	_imgObjects = new IMG[_count];
+
+	for(int i=0; i < _count; i++) {
+		imgReadStream->seek(iptReadStream->readUint32LE());
+		_imgObjects[i].field_0 = imgReadStream->readUint16LE();
+		_imgObjects[i].field_2 = imgReadStream->readUint16LE();
+		_imgObjects[i].field_4 = imgReadStream->readUint16LE();
+		_imgObjects[i].field_6 = imgReadStream->readUint16LE();
+		_imgObjects[i].field_8 = imgReadStream->readUint16LE();
+		_imgObjects[i].field_a = imgReadStream->readUint16LE();
+		_imgObjects[i].field_c = imgReadStream->readUint16LE();
+		_imgObjects[i].field_e = imgReadStream->readUint16LE();
+	}
+}
+
+IMG *DragonIMG::getIMG(uint32 iptId) {
+	iptId &= 0xffff;
+	assert(iptId > 1);
+	assert(iptId < _count);
+	return &_imgObjects[iptId];
+}
+
+
+} // End of namespace Dragons
diff --git a/engines/dragons/dragonimg.h b/engines/dragons/dragonimg.h
new file mode 100644
index 0000000000..6d9109e150
--- /dev/null
+++ b/engines/dragons/dragonimg.h
@@ -0,0 +1,53 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef SCUMMVM_DRAGONIMG_H
+#define SCUMMVM_DRAGONIMG_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+struct IMG {
+	uint16 field_0;
+	uint16 field_2;
+	uint16 field_4;
+	uint16 field_6;
+	uint16 field_8;
+	uint16 field_a;
+	uint16 field_c;
+	uint16 field_e;
+};
+
+class BigfileArchive;
+
+class DragonIMG {
+private:
+	int16 _count;
+	IMG *_imgObjects;
+public:
+	DragonIMG(BigfileArchive *bigfileArchive);
+	IMG *getIMG(uint32 iptId);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_DRAGONIMG_H
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 315204e4f2..3bfd41c92e 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -28,6 +28,7 @@
 #include "background.h"
 #include "bigfile.h"
 #include "dragonflg.h"
+#include "dragonimg.h"
 #include "dragonini.h"
 #include "dragonobd.h"
 #include "dragonrms.h"
@@ -84,6 +85,7 @@ Common::Error DragonsEngine::run() {
 	_screen = new Screen();
 	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
 	_dragonFLG = new DragonFLG(_bigfileArchive);
+	_dragonIMG = new DragonIMG(_bigfileArchive);
 	_dragonOBD = new DragonOBD(_bigfileArchive);
 	_dragonRMS = new DragonRMS(_bigfileArchive, _dragonOBD);
 	_dragonVAR = new DragonVAR(_bigfileArchive);
@@ -127,6 +129,7 @@ Common::Error DragonsEngine::run() {
 	delete _actorManager;
 	delete _backgroundResourceLoader;
 	delete _dragonFLG;
+	delete _dragonIMG;
 	delete _dragonRMS;
 	delete _dragonVAR;
 	delete _bigfileArchive;
@@ -171,7 +174,10 @@ void DragonsEngine::gameLoop() {
 		}
 
 		if (flickerIni->sceneId == getCurrentSceneId()) {
-			debug("get here");
+			uint16 id = getIniFromImg();
+			if (id != 0) {
+				error("todo 0x80026cb0 run script");
+			}
 		}
 		_scene->draw();
 		_screen->updateScreen();
@@ -361,4 +367,28 @@ void DragonsEngine::setVar(uint16 offset, uint16 value) {
 	return _dragonVAR->setVar(offset, value);
 }
 
+uint16 DragonsEngine::getIniFromImg() {
+	DragonINI *flicker = _dragonINIResource->getFlickerRecord();
+
+	int16 x = flicker->actor->x_pos / 32;
+	int16 y = flicker->actor->y_pos / 8;
+
+	uint16 currentSceneId = _scene->getSceneId();
+
+	for(uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
+		DragonINI *ini = getINI(i);
+		if (ini->sceneId == currentSceneId && ini->field_1a_flags_maybe == 0) {
+			IMG *img = _dragonIMG->getIMG(ini->field_2);
+			if (x >= img->field_0 &&
+			img->field_0 + img->field_4 >= x &&
+			y >= img->field_2 &&
+			img->field_6 + img->field_2 >= y) {
+				return i + 1;
+			}
+		}
+
+	}
+	return 0;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index dd36234be5..18b1cfe050 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -82,6 +82,7 @@ enum UnkFlags {
 class BigfileArchive;
 class BackgroundResourceLoader;
 class DragonFLG;
+class DragonIMG;
 class DragonOBD;
 class DragonRMS;
 class DragonVAR;
@@ -96,6 +97,7 @@ struct DragonINI;
 class DragonsEngine : public Engine {
 public:
 	DragonOBD *_dragonOBD;
+	DragonIMG *_dragonIMG;
 	ActorManager *_actorManager;
 	DragonINIResource *_dragonINIResource;
 private:
@@ -146,6 +148,7 @@ private:
 	void updateHandler();
 	uint32 calulateTimeLeft();
 	void wait();
+	uint16 getIniFromImg();
 };
 
 DragonsEngine *getEngine();
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 8139ab4c1b..d41f15eace 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -7,6 +7,7 @@ MODULE_OBJS := \
     bigfile.o \
 	detection.o \
     dragonflg.o \
+    dragonimg.o \
     dragonini.o \
     dragonobd.o \
     dragonrms.o \


Commit: be017e1950ab9176a6ca52d80574054f6434d9d1
    https://github.com/scummvm/scummvm/commit/be017e1950ab9176a6ca52d80574054f6434d9d1
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGOMS: More work on scripts

Changed paths:
    engines/dragons/actorresource.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/screen.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index d588a2644c..572d691607 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -49,8 +49,9 @@ public:
 };
 
 class ActorResource {
-private:
+public:
 	uint32 _id;
+private:
 	byte *_data;
 	int32 _fileSize;
 	ActorFrame *_frames;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 3bfd41c92e..5774302afe 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -61,6 +61,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_scriptOpcodes = NULL;
 	_engine = this;
 	_cursorPosition = Common::Point();
+	_cursorSequenceID = 0;
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -96,13 +97,14 @@ Common::Error DragonsEngine::run() {
 	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
 	_flags = 0x1046;
 
+	_cursorSequenceID = 0;
 	Actor *cursor = _actorManager->loadActor(0, 0); //Load cursor
 	cursor->x_pos = _cursorPosition.x = 160;
 	cursor->y_pos = _cursorPosition.y = 100;
 	cursor->priorityLayer = 6;
 	cursor->flags = 0;
 	cursor->field_e = 0x100;
-	cursor->updateSequence(0);
+	cursor->updateSequence(_cursorSequenceID);
 	cursor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 | Dragons::ACTOR_FLAG_200);
 
 	_dragonINIResource->getFlickerRecord()->actor = cursor; //TODO is this correct?
@@ -115,10 +117,12 @@ Common::Error DragonsEngine::run() {
 	inventory->field_e = 0x100;
 	inventory->updateSequence(0);
 	inventory->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 | Dragons::ACTOR_FLAG_200);
+	inventorySequenceId = 0;
 
-	_dragonINIResource->getFlickerRecord()->sceneId = 0x12; //TODO
-	_sceneId1 = 0x12;
-	_scene->loadScene(0x12, 0x1e);
+	uint16 sceneId = 0x12;
+	_dragonINIResource->getFlickerRecord()->sceneId = sceneId; //TODO
+	_sceneId1 = sceneId;
+	_scene->loadScene(sceneId, 0x1e);
 
 	_scene->draw();
 	_screen->updateScreen();
@@ -391,4 +395,20 @@ uint16 DragonsEngine::getIniFromImg() {
 	return 0;
 }
 
+uint16 DragonsEngine::updateINIUnderCursor() {
+	int32 x = (_cursorPosition.x + _scene->_camera.x) / 32;
+	int32 y = (_cursorPosition.y + _scene->_camera.y) / 8;
+
+	if (_flags & Dragons::ENGINE_FLAG_10) {
+
+		if (inventorySequenceId == 0 || inventorySequenceId == 2) {
+//TODO
+		} else {
+
+		}
+	}
+
+	return 0;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 18b1cfe050..a8859bf350 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -63,9 +63,10 @@ enum Flags {
 	ENGINE_FLAG_40 = 0x40,
 	ENGINE_FLAG_80 = 0x80,
 
-	ENGINE_FLAG_80000 =   0x80000,
-	ENGINE_FLAG_100000 = 0x100000,
-	ENGINE_FLAG_80000000 = 80000000
+	ENGINE_FLAG_80000    =    0x80000,
+	ENGINE_FLAG_100000   =   0x100000,
+	ENGINE_FLAG_4000000  =  0x4000000,
+	ENGINE_FLAG_80000000 = 0x80000000
 };
 
 enum UnkFlags {
@@ -100,6 +101,7 @@ public:
 	DragonIMG *_dragonIMG;
 	ActorManager *_actorManager;
 	DragonINIResource *_dragonINIResource;
+	uint16 _cursorSequenceID;
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
@@ -118,6 +120,9 @@ private:
 	uint32 _counter;
 	uint32 bit_flags_8006fbd8;
 
+	//unk
+	uint32 inventorySequenceId;
+
 public:
 	DragonsEngine(OSystem *syst);
 	~DragonsEngine();
@@ -149,6 +154,7 @@ private:
 	uint32 calulateTimeLeft();
 	void wait();
 	uint16 getIniFromImg();
+	uint16 updateINIUnderCursor();
 };
 
 DragonsEngine *getEngine();
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 859f20b8e4..11c76bf065 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -172,13 +172,20 @@ void Scene::draw() {
 
 		for (uint16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
 			Actor *actor = _actorManager->getActor(i);
-			if (actor &&
-				actor->flags & Dragons::ACTOR_FLAG_40 &&
-				actor->surface) {
+			if (actor->x_pos == -100 && actor->y_pos == 100) {
+				actor->priorityLayer = 0;
+				continue;
+			}
+
+			if (actor->flags & Dragons::ACTOR_FLAG_40 &&
+				!(actor->flags & Dragons::ACTOR_FLAG_400) &&
+				actor->surface &&
+				actor->frame->width != 0 &&
+				actor->frame->height != 0
+				) {
 				Graphics::Surface *s = actor->surface;
-				//TODO fix for scenes that are larger than a screen.
-				int x = actor->x_pos - actor->frame->xOffset;
-				int y = actor->y_pos - actor->frame->yOffset;
+				int x = actor->x_pos - actor->frame->xOffset - _camera.x;
+				int y = actor->y_pos - actor->frame->yOffset - _camera.y;
 				//int x = ini->x;// - actor->frame_vram_x;
 				//int y = ini->y;// - actor->frame_vram_y;
 				if (actor->priorityLayer == priority) { //} && x + s->w < 320 && y + s->h < 200) {
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 7bfd781bd0..25c215fa6c 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -39,6 +39,8 @@ class ScriptOpcodes;
 struct DragonINI;
 
 class Scene {
+public:
+	Common::Point _camera;
 private:
 	DragonsEngine *_vm;
 	Screen *_screen;
@@ -51,7 +53,6 @@ private:
 	ScriptOpcodes *_scriptOpcodes;
 
 	int16 _currentSceneId;
-	Common::Point _camera;
 
 public:
 	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 41e39645d8..5ad6d76d1d 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -112,11 +112,11 @@ Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect r
 		y += destY;
 	}
 
-	if (destX + w >= 320) {
+	if (w > 0 && destX + w >= 320) {
 		w -= (destX + w) - 320;
 	}
 
-	if (destY + h >= 200) {
+	if (h > 0 && destY + h >= 200) {
 		h -= (destY + h) - 200;
 	}
 	return Common::Rect(x, y, x + w, y + h);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 5d1f07c543..effc546221 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -20,6 +20,7 @@
  *
  */
 
+#include "dragons/actorresource.h"
 #include "dragons/dragons.h"
 #include "dragons/dragonflg.h"
 #include "dragons/dragonini.h"
@@ -87,8 +88,10 @@ void ScriptOpcodes::initOpcodes() {
 	// OPCODE(1, opUnk1);
 
 	OPCODE(4,  opExecuteScript);
+	OPCODE(5,  opActorSetSequenceID2);
 
 	OPCODE(7,  opUnk7);
+	OPCODE(8,  opActorLoadSequence);
 
 	OPCODE(10, opUnkA);
 	OPCODE(11, opRunSpecialOpCode);
@@ -192,6 +195,18 @@ void ScriptOpcodes::opExecuteScript(ScriptOpCall &scriptOpCall) {
 	executeScriptLoop(newScriptOpCall);
 }
 
+void ScriptOpcodes::opActorSetSequenceID2(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(iniIndex);
+	ARG_SKIP(2);
+	ARG_INT16(sequenceId);
+
+	if (scriptOpCall._field8 == 0) {
+		_vm->getINI(iniIndex - 1)->actor->_sequenceID2 = sequenceId;
+	}
+}
+
+
 void ScriptOpcodes::opUnk7(ScriptOpCall &scriptOpCall) {
 	if (scriptOpCall._field8 == 0) {
 		opCode_Unk7(scriptOpCall);
@@ -201,6 +216,34 @@ void ScriptOpcodes::opUnk7(ScriptOpCall &scriptOpCall) {
 
 }
 
+void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(sequenceId);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	DragonINI *ini = _vm->getINI(field2 - 1);
+
+	bool isFlicker = _vm->_dragonINIResource->isFlicker(field2 - 1);
+	if (isFlicker) {
+		ini->actor->flags |= Dragons::ACTOR_FLAG_2000;
+	}
+
+	assert(ini->actor->_actorResource);
+	assert(ini->actor->_actorResource->_id == ini->actorResourceId); // TODO need to rework selecting resourceId for an actor.
+	ini->actor->updateSequence(sequenceId);
+
+	if (field0 & 0x8000) {
+		error("wait here.");
+	}
+
+	if (isFlicker) {
+		ini->actor->flags &= ~Dragons::ACTOR_FLAG_2000;
+	}
+}
 
 void ScriptOpcodes::opPlayMusic(ScriptOpCall &scriptOpCall) {
 	byte *code = scriptOpCall._code;
@@ -214,7 +257,7 @@ void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	if (checkPropertyFlag(scriptOpCall)) {
 		scriptOpCall._code += 4;
 	} else {
-		scriptOpCall._code += 4 + READ_LE_INT16(scriptOpCall._code);
+		scriptOpCall._code += 4 + READ_LE_UINT16(scriptOpCall._code);
 	}
 }
 
@@ -496,10 +539,13 @@ uint16 ScriptOpcodes::getINIField(uint32 iniIndex, uint16 fieldOffset) {
 	DragonINI *ini = _vm->getINI(iniIndex);
 
 	switch (fieldOffset) {
+		case 0 : return ini->iptIndex_maybe;
+		case 0xC  : return ini->sceneId;
+		case 0x12  : return ini->field_12;
 		case 0x14 : return ini->field_14;
 		case 0x1A : return ini->field_1a_flags_maybe;
 		case 0x20 : return ini->field_20_actor_field_14;
-		default: error("Invalid fieldOffset %d", fieldOffset);
+		default: error("getINIField() Invalid fieldOffset 0x%X", fieldOffset);
 	}
 }
 
@@ -507,14 +553,25 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 	DragonINI *ini = _vm->getINI(iniIndex);
 
 	switch (fieldOffset) {
+		case 0 : ini->iptIndex_maybe = value; break;
+		case 0xc  : ini->sceneId = value; break;
+		case 0x12 : ini->field_12 = value; break;
 		case 0x14 : ini->field_14 = value; break;
 		case 0x1A : ini->field_1a_flags_maybe = value; break;
 		case 0x20 : ini->field_20_actor_field_14 = value; break;
-		default: error("Invalid fieldOffset %X", fieldOffset);
+		default: error("setINIField() Invalid fieldOffset 0x%X", fieldOffset);
 	}
 
 }
 
+void ScriptOpcodes::opUnk14(ScriptOpCall &scriptOpCall) {
+
+}
+
+void ScriptOpcodes::opUnk15(ScriptOpCall &scriptOpCall) {
+
+}
+
 void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
@@ -578,6 +635,4 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 	ini->sceneId = sceneId;
 }
 
-
-
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 090a57f6c8..d714d108e5 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -79,8 +79,10 @@ protected:
 	// Opcodes
 	void opUnk1(ScriptOpCall &scriptOpCall);
 	void opExecuteScript(ScriptOpCall &scriptOpCall); //op 4
+	void opActorSetSequenceID2(ScriptOpCall &scriptOpCall); //op 5
 
 	void opUnk7(ScriptOpCall &scriptOpCall);
+	void opActorLoadSequence(ScriptOpCall &scriptOpCall);
 
 	void opUnkA(ScriptOpCall &scriptOpCall);
 	void opRunSpecialOpCode(ScriptOpCall &scriptOpCall); //op B
@@ -88,6 +90,8 @@ protected:
 	void opUnkF(ScriptOpCall &scriptOpCall);
 
 	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
+	void opUnk14(ScriptOpCall &scriptOpCall);
+	void opUnk15(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
 
 	bool checkPropertyFlag(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 54329bb4b0..795422b5d8 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -61,6 +61,7 @@ SequenceOpcodes::~SequenceOpcodes() {
 }
 
 void SequenceOpcodes::execOpcode(Actor *control, OpCall &opCall) {
+	assert(opCall._op < DRAGONS_NUM_SEQ_OPCODES);
 	if (!_opcodes[opCall._op])
 		error("SequenceOpcodes::execOpcode() Unimplemented opcode %d", opCall._op);
 	debug(3, "execSequenceOpcode(%d) %s", opCall._op, _opcodeNames[opCall._op].c_str());
@@ -133,7 +134,7 @@ void SequenceOpcodes::opJmp(Actor *actor, OpCall &opCall) {
 
 	if (!(actor->flags & Dragons::ACTOR_FLAG_1000)) {
 		byte *newOffset = actor->getSeqIpAtOffset((uint32)newIp);
-		opCall._deltaOfs = (int32)(newOffset - opCall._code);
+		opCall._deltaOfs = (int32)(newOffset - actor->_seqCodeIp); //opCall._code);
 		debug(3, "opJump delta: %d", opCall._deltaOfs);
 	} else {
 		updateReturn(opCall, 1);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index a944c254a9..fa4a727ddb 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -64,6 +64,9 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(3, spcClearEngineFlag10);
 	OPCODE(9, spcUnk9);
 	OPCODE(20, spcClearEngineFlag8);
+
+	OPCODE(0x54, spcSetEngineFlag0x4000000);
+	OPCODE(0x55, spcSetCursorSequenceIdToZero);
 }
 
 #undef OPCODE
@@ -94,5 +97,13 @@ void SpecialOpcodes::spcClearEngineFlag8() {
 	_vm->clearFlags(Dragons::ENGINE_FLAG_8);
 }
 
+void SpecialOpcodes::spcSetEngineFlag0x4000000() {
+	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
+}
+
+void SpecialOpcodes::spcSetCursorSequenceIdToZero() {
+	_vm->_cursorSequenceID = 0;
+}
+
 
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 9be62953fd..b7a1ca8090 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -55,6 +55,9 @@ protected:
 
 	void spcClearEngineFlag8(); // 0x14
 
+	void spcSetEngineFlag0x4000000(); // 0x54
+	void spcSetCursorSequenceIdToZero(); // 0x55
+
 };
 
 } // End of namespace Dragons


Commit: 5bab09d76eff1f6885d8a09a00978ded9b3a6641
    https://github.com/scummvm/scummvm/commit/5bab09d76eff1f6885d8a09a00978ded9b3a6641
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on script logic

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragonini.h
    engines/dragons/dragonobd.cpp
    engines/dragons/dragonobd.h
    engines/dragons/dragonrms.cpp
    engines/dragons/dragonrms.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 64a89827a5..5edba49a51 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -157,6 +157,8 @@ void Actor::loadFrame(uint16 frameOffset) {
 
 	debug(3, "ActorId: %d load frame header: (%d,%d) palette: %X", _actorID, frame->width, frame->height, paletteId);
 
+	flags |= Dragons::ACTOR_FLAG_8; //TODO check if this is the right spot. engine sets it at 0x800185b0
+
 }
 
 byte *Actor::getSeqIpAtOffset(uint32 offset) {
@@ -173,4 +175,26 @@ void Actor::pathfinding_maybe(int16 x, int16 y, int16 unk) {
 	error("Implement pathfinding_maybe()");
 }
 
+void Actor::waitUntilFlag8IsSet() {
+	if (flags & Dragons::ACTOR_FLAG_8) {
+		return;
+	}
+
+	while(!(flags & Dragons::ACTOR_FLAG_8)) {
+		getEngine()->waitForFrames(1);
+	}
+}
+
+void Actor::waitUntilFlag8And4AreSet() {
+	waitUntilFlag8IsSet();
+
+	if (flags & Dragons::ACTOR_FLAG_4) {
+		return;
+	}
+
+	while(!(flags & Dragons::ACTOR_FLAG_4)) {
+		getEngine()->waitForFrames(1);
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index fb45e2bbed..02d8caf282 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -121,6 +121,8 @@ public:
 	void loadFrame(uint16 frameOffset);
 	void reset_maybe();
 	void pathfinding_maybe(int16 x, int16 y, int16 unk);
+	void waitUntilFlag8IsSet();
+	void waitUntilFlag8And4AreSet();
 
 };
 
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 4fb0ca183c..af680eb882 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -30,14 +30,14 @@ namespace Dragons {
 class Actor;
 
 enum IniFlags {
-	INI_FLAG_1 = 1,
-	INI_FLAG_2 = 2,
-	INI_FLAG_4 = 4,
-	INI_FLAG_8 = 8,
-	INI_FLAG_10 = 10,
-	INI_FLAG_20 = 20,
-	INI_FLAG_40 = 40,
-	INI_FLAG_80 = 80
+	INI_FLAG_1 = 0x1,
+	INI_FLAG_2 = 0x2,
+	INI_FLAG_4 = 0x4,
+	INI_FLAG_8 = 0x8,
+	INI_FLAG_10 = 0x10,
+	INI_FLAG_20 = 0x20,
+	INI_FLAG_40 = 0x40,
+	INI_FLAG_80 = 0x80
 };
 
 
diff --git a/engines/dragons/dragonobd.cpp b/engines/dragons/dragonobd.cpp
index 8e53fba769..a1568f246c 100644
--- a/engines/dragons/dragonobd.cpp
+++ b/engines/dragons/dragonobd.cpp
@@ -19,12 +19,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
+#include "common/memstream.h"
 #include "dragonobd.h"
 #include "bigfile.h"
 
 namespace Dragons {
 
 DragonOBD::DragonOBD(BigfileArchive *bigfileArchive) {
+	uint32 size;
+	byte *optData = bigfileArchive->load("dragon.opt", size);
+	optReadStream = new Common::MemoryReadStream(optData, size, DisposeAfterUse::NO);
+
 	_data = bigfileArchive->load("dragon.obd", _dataSize);
 }
 
@@ -38,6 +43,12 @@ DragonOBD::~DragonOBD() {
 	if (_data) {
 		delete _data;
 	}
+	delete optReadStream;
+}
+
+byte *DragonOBD::getFromOpt(uint32 index) {
+	optReadStream->seek(index * 8);
+	return getObdAtOffset(optReadStream->readUint32LE());
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonobd.h b/engines/dragons/dragonobd.h
index 461653e61a..10ff63596f 100644
--- a/engines/dragons/dragonobd.h
+++ b/engines/dragons/dragonobd.h
@@ -32,11 +32,14 @@ class DragonOBD {
 private:
 	byte *_data;
 	uint32_t _dataSize;
+	Common::SeekableReadStream *optReadStream;
+
 public:
 	virtual ~DragonOBD();
 
 	DragonOBD(BigfileArchive *bigfileArchive);
 	byte *getObdAtOffset(uint32 offset);
+	byte *getFromOpt(uint32 index);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
index 3fb6d45920..039dc58471 100644
--- a/engines/dragons/dragonrms.cpp
+++ b/engines/dragons/dragonrms.cpp
@@ -60,6 +60,9 @@ byte *DragonRMS::getObdData(uint32 sceneId) {
 byte *DragonRMS::getObdDataField10(uint32 sceneId) {
 	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_field10ObdOffset);
 }
+byte *DragonRMS::getObdDataFieldC(uint32 sceneId) {
+	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_fieldC);
+}
 
 RMS *DragonRMS::getRMS(uint32 sceneId) {
 	sceneId &= 0x7fff;
diff --git a/engines/dragons/dragonrms.h b/engines/dragons/dragonrms.h
index 4b9f214997..8af329e3c9 100644
--- a/engines/dragons/dragonrms.h
+++ b/engines/dragons/dragonrms.h
@@ -50,6 +50,7 @@ public:
 	char *getSceneName(uint32 sceneId);
 	byte *getObdData(uint32 sceneId);
 	byte *getObdDataField10(uint32 sceneId);
+	byte *getObdDataFieldC(uint32 sceneId);
 
 private:
 	RMS *getRMS(uint32 sceneId);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 5774302afe..34daa4c3af 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -62,6 +62,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_engine = this;
 	_cursorPosition = Common::Point();
 	_cursorSequenceID = 0;
+	run_func_ptr_unk_countdown_timer = 0;
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -82,6 +83,7 @@ void DragonsEngine::updateEvents() {
 		}
 	}
 }
+
 Common::Error DragonsEngine::run() {
 	_screen = new Screen();
 	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
@@ -96,6 +98,8 @@ Common::Error DragonsEngine::run() {
 	_scriptOpcodes = new ScriptOpcodes(this, _dragonFLG);
 	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
 	_flags = 0x1046;
+	_flags &= 0x1c07040;
+	_flags |= 0x26;
 
 	_cursorSequenceID = 0;
 	Actor *cursor = _actorManager->loadActor(0, 0); //Load cursor
@@ -105,9 +109,11 @@ Common::Error DragonsEngine::run() {
 	cursor->flags = 0;
 	cursor->field_e = 0x100;
 	cursor->updateSequence(_cursorSequenceID);
-	cursor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 | Dragons::ACTOR_FLAG_200);
+	cursor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
+					  Dragons::ACTOR_FLAG_200);
 
 	_dragonINIResource->getFlickerRecord()->actor = cursor; //TODO is this correct?
+	_dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
 
 	Actor *inventory = _actorManager->loadActor(1, 1); //Load inventory
 	inventory->x_pos = 2;
@@ -116,8 +122,10 @@ Common::Error DragonsEngine::run() {
 	inventory->flags = 0;
 	inventory->field_e = 0x100;
 	inventory->updateSequence(0);
-	inventory->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 | Dragons::ACTOR_FLAG_200);
+	inventory->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
+						 Dragons::ACTOR_FLAG_200);
 	inventorySequenceId = 0;
+	inventoryIsShowingMaybe = 0;
 
 	uint16 sceneId = 0x12;
 	_dragonINIResource->getFlickerRecord()->sceneId = sceneId; //TODO
@@ -183,6 +191,9 @@ void DragonsEngine::gameLoop() {
 				error("todo 0x80026cb0 run script");
 			}
 		}
+
+		runINIScripts();
+
 		_scene->draw();
 		_screen->updateScreen();
 		wait();
@@ -232,6 +243,10 @@ void DragonsEngine::updateHandler() {
 			}
 		}
 	}
+
+	if (_flags & Dragons::ENGINE_FLAG_20) {
+		engineFlag0x20UpdateFunction();
+	}
 }
 
 const char *DragonsEngine::getSavegameFilename(int num) {
@@ -247,7 +262,8 @@ Common::String DragonsEngine::getSavegameFilename(const Common::String &target,
 
 #define DRAGONS_SAVEGAME_VERSION 0
 
-kReadSaveHeaderError DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
+kReadSaveHeaderError
+DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
 
 	header.version = in->readUint32LE();
 	if (header.version > DRAGONS_SAVEGAME_VERSION)
@@ -256,7 +272,7 @@ kReadSaveHeaderError DragonsEngine::readSaveHeader(Common::SeekableReadStream *i
 	byte descriptionLen = in->readByte();
 	header.description = "";
 	while (descriptionLen--) {
-		header.description += (char)in->readByte();
+		header.description += (char) in->readByte();
 	}
 
 	if (!Graphics::loadThumbnail(*in, header.thumbnail, skipThumbnail)) {
@@ -277,13 +293,13 @@ uint32 DragonsEngine::calulateTimeLeft() {
 
 	now = _system->getMillis();
 
-	if ( _nextUpdatetime <= now ) {
+	if (_nextUpdatetime <= now) {
 		_nextUpdatetime = now + DRAGONS_TICK_INTERVAL;
-		return(0);
+		return (0);
 	}
 	uint32 delay = _nextUpdatetime - now;
 	_nextUpdatetime += DRAGONS_TICK_INTERVAL;
-	return(delay);
+	return (delay);
 }
 
 void DragonsEngine::wait() {
@@ -297,19 +313,19 @@ void DragonsEngine::updateActorSequences() {
 
 	//TODO ResetRCnt(0xf2000001);
 
-	int16 actorId = _flags & Dragons::ENGINE_FLAG_80 ? (int16)64 : (int16)23;
+	int16 actorId = _flags & Dragons::ENGINE_FLAG_80 ? (int16) 64 : (int16) 23;
 
 	while (actorId > 0) {
 		actorId--;
-		Actor *actor = _actorManager->getActor((uint16)actorId);
+		Actor *actor = _actorManager->getActor((uint16) actorId);
 		if (actorId < 2 && _flags & Dragons::ENGINE_FLAG_40) {
 			continue;
 		}
 
 		if (actor->flags & Dragons::ACTOR_FLAG_40 &&
-				!(actor->flags & Dragons::ACTOR_FLAG_4) &&
-				!(actor->flags & Dragons::ACTOR_FLAG_400) &&
-				(actor->sequenceTimer == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
+			!(actor->flags & Dragons::ACTOR_FLAG_4) &&
+			!(actor->flags & Dragons::ACTOR_FLAG_400) &&
+			(actor->sequenceTimer == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
 			debug("Actor[%d] execute sequenceOp", actorId);
 
 			if (actor->flags & Dragons::ACTOR_FLAG_1) {
@@ -352,7 +368,7 @@ byte *DragonsEngine::getBackgroundPalette() {
 }
 
 bool DragonsEngine::isFlagSet(uint32 flag) {
-	return (bool)(_flags & flag);
+	return (bool) (_flags & flag);
 }
 
 DragonINI *DragonsEngine::getINI(uint32 index) {
@@ -379,14 +395,14 @@ uint16 DragonsEngine::getIniFromImg() {
 
 	uint16 currentSceneId = _scene->getSceneId();
 
-	for(uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
+	for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
 		if (ini->sceneId == currentSceneId && ini->field_1a_flags_maybe == 0) {
 			IMG *img = _dragonIMG->getIMG(ini->field_2);
 			if (x >= img->field_0 &&
-			img->field_0 + img->field_4 >= x &&
-			y >= img->field_2 &&
-			img->field_6 + img->field_2 >= y) {
+				img->field_0 + img->field_4 >= x &&
+				y >= img->field_2 &&
+				img->field_6 + img->field_2 >= y) {
 				return i + 1;
 			}
 		}
@@ -411,4 +427,55 @@ uint16 DragonsEngine::updateINIUnderCursor() {
 	return 0;
 }
 
+void DragonsEngine::runINIScripts() {
+	for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
+		DragonINI *ini = getINI(i);
+		if (ini->field_1a_flags_maybe & Dragons::INI_FLAG_10) {
+			ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
+			byte *data = _dragonOBD->getFromOpt(i);
+			ScriptOpCall scriptOpCall;
+			scriptOpCall._code = data + 8;
+			scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(data);
+			uint32 currentFlags = _flags;
+			clearFlags(Dragons::ENGINE_FLAG_8);
+			_scriptOpcodes->runScript3(scriptOpCall);
+			_flags = currentFlags;
+		}
+	}
+}
+
+void DragonsEngine::engineFlag0x20UpdateFunction() {
+	if (_flags & Dragons::ENGINE_FLAG_20) {
+		if ((_flags & (Dragons::ENGINE_FLAG_80000000 | Dragons::ENGINE_FLAG_8)) == 8) {
+			error("updateCursor();"); //TODO updateCursor();
+		}
+		//TODO
+		uint16 currentSceneId = _scene->getSceneId();
+
+		if (inventoryIsShowingMaybe == 0) {
+			for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
+				DragonINI *ini = getINI(i);
+				if (ini->field_10 >= 0 && ini->sceneId == currentSceneId) {
+					ini->field_10--;
+					if (ini->field_10 < 0) {
+						ini->field_1a_flags_maybe |= Dragons::INI_FLAG_10;
+					}
+				}
+			}
+		}
+	} else {
+		run_func_ptr_unk_countdown_timer = 1;
+	}
+}
+
+void DragonsEngine::waitForFrames(uint16 numFrames) {
+	for (uint16 i = 0; i < numFrames; i++) {
+		wait();
+		updateHandler();
+
+		_scene->draw();
+		_screen->updateScreen();
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index a8859bf350..4c46c6b9d4 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -122,6 +122,8 @@ private:
 
 	//unk
 	uint32 inventorySequenceId;
+	uint16 inventoryIsShowingMaybe;
+	uint16 run_func_ptr_unk_countdown_timer;
 
 public:
 	DragonsEngine(OSystem *syst);
@@ -148,6 +150,8 @@ public:
 	void setVar(uint16 offset, uint16 value);
 	uint16 getCurrentSceneId();
 
+	void waitForFrames(uint16 numFrames);
+
 private:
 	void gameLoop();
 	void updateHandler();
@@ -155,6 +159,8 @@ private:
 	void wait();
 	uint16 getIniFromImg();
 	uint16 updateINIUnderCursor();
+	void runINIScripts();
+	void engineFlag0x20UpdateFunction();
 };
 
 DragonsEngine *getEngine();
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 11c76bf065..67144cf094 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -35,8 +35,21 @@ Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, Bi
 		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
 	_backgroundLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 }
-
 void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
+	// TODO
+	loadSceneData(sceneId, cameraPointId);
+	//TODO
+	if (!(sceneId & 0x8000)) {
+		byte *obd = _dragonRMS->getObdDataFieldC(sceneId);
+		ScriptOpCall scriptOpCall;
+		scriptOpCall._code = obd + 4;
+		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		_currentSceneId = -1;
+		_scriptOpcodes->runScript(scriptOpCall);
+	}
+}
+
+void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_2 | Dragons::ENGINE_UNK1_FLAG_8);
 
 	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 25c215fa6c..ba8fb75a5b 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -63,6 +63,9 @@ public:
 	bool contains(DragonINI *ini);
 	byte *getPalette();
 	uint16 getSceneId();
+private:
+	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
+
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index effc546221..a72f70f057 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -96,6 +96,8 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(10, opUnkA);
 	OPCODE(11, opRunSpecialOpCode);
 
+	OPCODE(0xD, opDelay);
+
 	OPCODE(15, opUnkF);
 
 	OPCODE(19, opUnk13PropertiesRelated);
@@ -123,6 +125,14 @@ void ScriptOpcodes::runScript(ScriptOpCall &scriptOpCall) {
 	executeScriptLoop(scriptOpCall);
 }
 
+
+void ScriptOpcodes::runScript3(ScriptOpCall &scriptOpCall) {
+	scriptOpCall._field8 = 3;
+	scriptOpCall._result = 0;
+	_data_80071f5c = 0;
+	executeScriptLoop(scriptOpCall);
+}
+
 void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 
 	if (scriptOpCall._code >= scriptOpCall._codeEnd || scriptOpCall._result & 1) {
@@ -140,7 +150,7 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 //		}
 	}
 
-	uint16 opcode = READ_LE_INT16(scriptOpCall._code);
+	uint16 opcode = READ_LE_UINT16(scriptOpCall._code) & 0x7fff;
 
 	scriptOpCall._op = (byte) opcode;
 	if (opcode < DRAGONS_NUM_SCRIPT_OPCODES) {
@@ -160,7 +170,7 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 //		}
 		}
 
-		uint16 opcode = READ_LE_INT16(scriptOpCall._code);
+		opcode = READ_LE_UINT16(scriptOpCall._code) & 0x7fff;
 
 		if (opcode >= DRAGONS_NUM_SCRIPT_OPCODES) {
 			return; //TODO should continue here.
@@ -237,7 +247,7 @@ void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
 	ini->actor->updateSequence(sequenceId);
 
 	if (field0 & 0x8000) {
-		error("wait here.");
+		ini->actor->waitUntilFlag8And4AreSet();
 	}
 
 	if (isFlicker) {
@@ -372,6 +382,17 @@ void ScriptOpcodes::opRunSpecialOpCode(ScriptOpCall &scriptOpCall) {
 	_specialOpCodes->run(specialOpCode);
 }
 
+void ScriptOpcodes::opDelay(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(delay);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	_vm->waitForFrames((uint16)delay);
+}
+
 void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index d714d108e5..9b2591803c 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -29,7 +29,7 @@
 
 namespace Dragons {
 
-#define DRAGONS_NUM_SCRIPT_OPCODES 0x22
+#define DRAGONS_NUM_SCRIPT_OPCODES 0x23
 class DragonsEngine;
 
 struct ScriptOpCall {
@@ -61,6 +61,7 @@ public:
 	ScriptOpcodes(DragonsEngine *vm, DragonFLG *dragonFLG);
 	~ScriptOpcodes();
 	void runScript(ScriptOpCall &scriptOpCall);
+	void runScript3(ScriptOpCall &scriptOpCall);
 	void execOpcode(ScriptOpCall &scriptOpCall);
 protected:
 	DragonsEngine *_vm;
@@ -87,6 +88,8 @@ protected:
 	void opUnkA(ScriptOpCall &scriptOpCall);
 	void opRunSpecialOpCode(ScriptOpCall &scriptOpCall); //op B
 
+	void opDelay(ScriptOpCall &scriptOpCall); //op D
+
 	void opUnkF(ScriptOpCall &scriptOpCall);
 
 	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);


Commit: b4b5689af583535c45c87785ec976b3f95f5902b
    https://github.com/scummvm/scummvm/commit/b4b5689af583535c45c87785ec976b3f95f5902b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on scripts

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/dragonini.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 5edba49a51..2329d16420 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -172,7 +172,9 @@ void Actor::reset_maybe() {
 
 void Actor::pathfinding_maybe(int16 x, int16 y, int16 unk) {
 	//TODO implement me.
-	error("Implement pathfinding_maybe()");
+	 error("Implement pathfinding_maybe()");
+//	x_pos = x;
+//	y_pos = y;
 }
 
 void Actor::waitUntilFlag8IsSet() {
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index 7b774f9bb0..f3874003f8 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -40,7 +40,7 @@ DragonINIResource::DragonINIResource(BigfileArchive *bigfileArchive) {
 		_dragonINI[i].iptIndex_maybe = readStream->readSint16LE();
 		_dragonINI[i].field_2 = readStream->readSint16LE();
 		_dragonINI[i].actorResourceId = readStream->readSint16LE();
-		_dragonINI[i].frameIndexId_maybe = readStream->readSint16LE();
+		_dragonINI[i].sequenceId = readStream->readSint16LE();
 		_dragonINI[i].field_8 = readStream->readSint16LE();
 		assert(readStream->readUint16LE() == 0); // actorId
 		_dragonINI[i].actor = NULL;
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index af680eb882..251eeb68ab 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -47,7 +47,7 @@ struct DragonINI
 		int16 iptIndex_maybe;
 		int16 field_2;
 		uint16 actorResourceId;
-		uint16 frameIndexId_maybe;
+		uint16 sequenceId;
 		int16 field_8;
 		Actor *actor;
 		uint16 sceneId;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 34daa4c3af..bac9b592b3 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -478,4 +478,8 @@ void DragonsEngine::waitForFrames(uint16 numFrames) {
 	}
 }
 
+void DragonsEngine::playSound(uint16 soundId) {
+	debug(3, "TODO: play sound %d", soundId);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 4c46c6b9d4..378208cdbe 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -152,6 +152,8 @@ public:
 
 	void waitForFrames(uint16 numFrames);
 
+	void playSound(uint16 soundId);
+
 private:
 	void gameLoop();
 	void updateHandler();
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 67144cf094..bf5aa20b56 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -107,11 +107,11 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		if (ini->sceneId == sceneId && (ini->field_1a_flags_maybe & 1)) {
-			Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->frameIndexId_maybe, ini->x, ini->y, 0);
+			Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
 
 			if (actor) {
 				ini->actor = actor;
-				if (ini->frameIndexId_maybe & 0x1000) {
+				if (ini->sequenceId & 0x1000) {
 					actor->frame_flags |= 0x10;
 				} else {
 					if (ini->field_1a_flags_maybe & 0x2000) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index a72f70f057..36231b3726 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -93,16 +93,19 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(7,  opUnk7);
 	OPCODE(8,  opActorLoadSequence);
 
-	OPCODE(10, opUnkA);
-	OPCODE(11, opRunSpecialOpCode);
-
+	OPCODE(0xA, opUnkA);
+	OPCODE(0xB, opRunSpecialOpCode);
+	OPCODE(0xC, opUnkCSoundRelatedMaybe);
 	OPCODE(0xD, opDelay);
+	OPCODE(0xE, opUnkE);
+	OPCODE(0xF, opUnkF);
 
-	OPCODE(15, opUnkF);
+	OPCODE(0x11, opUnk11FlickerTalk);
 
-	OPCODE(19, opUnk13PropertiesRelated);
-	OPCODE(31, opPlayMusic);
+	OPCODE(0x13, opUnk13PropertiesRelated);
+	OPCODE(0x1F, opPlayMusic);
 
+	OPCODE(0x22, opCodeActorTalk);
 }
 
 #undef OPCODE
@@ -382,6 +385,15 @@ void ScriptOpcodes::opRunSpecialOpCode(ScriptOpCall &scriptOpCall) {
 	_specialOpCodes->run(specialOpCode);
 }
 
+void ScriptOpcodes::opUnkCSoundRelatedMaybe(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(soundId);
+
+	if (scriptOpCall._field8 == 0) {
+		_vm->playSound((uint16)soundId);
+	}
+}
+
 void ScriptOpcodes::opDelay(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(delay);
@@ -393,6 +405,31 @@ void ScriptOpcodes::opDelay(ScriptOpCall &scriptOpCall) {
 	_vm->waitForFrames((uint16)delay);
 }
 
+void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+	ARG_INT16(field8);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	int32 s3 = 0;
+	DragonINI *ini = _vm->getINI(field2 - 1);
+
+	if (field6 & 0x8000) {
+		s3 = 0 > (field6 ^ 0xffff) ? 1 : 0;
+	}
+
+	if (field4 != -1) {
+
+	} else {
+
+	}
+}
+
 void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
@@ -429,9 +466,7 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 
 			if(s3 == 0) {
 				while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
-					//TODO
-					//wait a game tick
-					error("Wait a game tick here");
+					_vm->waitForFrames(1);
 				}
 			}
 			ini->x = field8;
@@ -452,6 +487,24 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(8);
+	// TODO implement me!
+}
+
+void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(field2);
+	ARG_SKIP(6);
+	ARG_UINT32(fieldA);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	//TODO implement actor talk.
+}
+
 void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
@@ -561,9 +614,12 @@ uint16 ScriptOpcodes::getINIField(uint32 iniIndex, uint16 fieldOffset) {
 
 	switch (fieldOffset) {
 		case 0 : return ini->iptIndex_maybe;
+		case 6 : return ini->sequenceId;
 		case 0xC  : return ini->sceneId;
 		case 0x12  : return ini->field_12;
 		case 0x14 : return ini->field_14;
+		case 0x16 : return ini->x;
+		case 0x18 : return ini->y;
 		case 0x1A : return ini->field_1a_flags_maybe;
 		case 0x20 : return ini->field_20_actor_field_14;
 		default: error("getINIField() Invalid fieldOffset 0x%X", fieldOffset);
@@ -575,9 +631,12 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 
 	switch (fieldOffset) {
 		case 0 : ini->iptIndex_maybe = value; break;
+		case 6 : ini->sequenceId = value; break;
 		case 0xc  : ini->sceneId = value; break;
 		case 0x12 : ini->field_12 = value; break;
 		case 0x14 : ini->field_14 = value; break;
+		case 0x16 : ini->x = value; break;
+		case 0x18 : ini->y = value; break;
 		case 0x1A : ini->field_1a_flags_maybe = value; break;
 		case 0x20 : ini->field_20_actor_field_14 = value; break;
 		default: error("setINIField() Invalid fieldOffset 0x%X", fieldOffset);
@@ -608,7 +667,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 				ini->actor->reset_maybe();
 			}
 			if (sceneId == currentScene) {
-				ini->actor = _vm->_actorManager->loadActor(ini->actorResourceId, ini->frameIndexId_maybe, ini->x, ini->y, 0);
+				ini->actor = _vm->_actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
 				ini->actor->_sequenceID2 = ini->field_20_actor_field_14;
 				if (ini->field_1a_flags_maybe & 2) {
 					ini->actor->flags |= Dragons::ACTOR_FLAG_80;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 9b2591803c..0f0d0f1337 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -87,11 +87,13 @@ protected:
 
 	void opUnkA(ScriptOpCall &scriptOpCall);
 	void opRunSpecialOpCode(ScriptOpCall &scriptOpCall); //op B
-
+	void opUnkCSoundRelatedMaybe(ScriptOpCall &scriptOpCall);
 	void opDelay(ScriptOpCall &scriptOpCall); //op D
-
+	void opUnkE(ScriptOpCall &scriptOpCall);
 	void opUnkF(ScriptOpCall &scriptOpCall);
 
+	void opUnk11FlickerTalk(ScriptOpCall &scriptOpCall);
+
 	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opUnk14(ScriptOpCall &scriptOpCall);
 	void opUnk15(ScriptOpCall &scriptOpCall);
@@ -101,6 +103,8 @@ protected:
 	void opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall);
 	void opCode_Unk7(ScriptOpCall &scriptOpCall);
 
+	void opCodeActorTalk(ScriptOpCall &scriptOpCall); // 0x22
+
 	// misc
 	uint16 getINIField(uint32 iniIndex, uint16 fieldOffset);
 	void setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 value);
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 795422b5d8..542a4ecd8b 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -212,7 +212,7 @@ void SequenceOpcodes::opPlaySound(Actor *actor, OpCall &opCall) {
 	ARG_INT16(soundId);
 	debug(3, "opPlaySound actorId: %d soundId: %d", actor->_actorID, soundId);
 
-	// TODO play sound here.
+	_vm->playSound((uint16)soundId);
 	updateReturn(opCall, 1);
 }
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index fa4a727ddb..717713665e 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -62,8 +62,12 @@ void SpecialOpcodes::initOpcodes() {
 	// Register opcodes
 	// OPCODE(1, opUnk1);
 	OPCODE(3, spcClearEngineFlag10);
+	OPCODE(4, spcSetEngineFlag10);
+
 	OPCODE(9, spcUnk9);
-	OPCODE(20, spcClearEngineFlag8);
+	OPCODE(0xa, spcUnkA);
+	OPCODE(0x14, spcClearEngineFlag8);
+	OPCODE(0x15, spcSetEngineFlag8);
 
 	OPCODE(0x54, spcSetEngineFlag0x4000000);
 	OPCODE(0x55, spcSetCursorSequenceIdToZero);
@@ -83,20 +87,37 @@ void SpecialOpcodes::spcClearEngineFlag10() {
 	_vm->clearFlags(Dragons::ENGINE_FLAG_10);
 }
 
+void SpecialOpcodes::spcSetEngineFlag10() {
+	_vm->setFlags(Dragons::ENGINE_FLAG_10);
+}
+
 void SpecialOpcodes::spcUnk9() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	assert(flicker);
-	flicker->field_1a_flags_maybe |= 0x20;
+	flicker->field_1a_flags_maybe |= Dragons::INI_FLAG_20;
 	assert(flicker->actor);
 	flicker->actor->flags |= Dragons::ACTOR_FLAG_100;
 	flicker->actor->priorityLayer = 0;
-	_vm->getINI(1)->field_1a_flags_maybe |= 0x20;
+	_vm->getINI(1)->field_1a_flags_maybe |= Dragons::INI_FLAG_20;
 }
 
+
+void SpecialOpcodes::spcUnkA() {
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+	flicker->field_1a_flags_maybe &= ~Dragons::INI_FLAG_20;
+	flicker->actor->flags &= ~Dragons::ACTOR_FLAG_100;
+	_vm->getINI(1)->field_1a_flags_maybe &= ~Dragons::INI_FLAG_20;
+}
+
+
 void SpecialOpcodes::spcClearEngineFlag8() {
 	_vm->clearFlags(Dragons::ENGINE_FLAG_8);
 }
 
+void SpecialOpcodes::spcSetEngineFlag8() {
+	_vm->setFlags(Dragons::ENGINE_FLAG_8);
+}
+
 void SpecialOpcodes::spcSetEngineFlag0x4000000() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
 }
@@ -105,5 +126,4 @@ void SpecialOpcodes::spcSetCursorSequenceIdToZero() {
 	_vm->_cursorSequenceID = 0;
 }
 
-
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index b7a1ca8090..7611eb2f9e 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -50,10 +50,13 @@ protected:
 
 	// Opcodes
 	void spcClearEngineFlag10(); // 3
+	void spcSetEngineFlag10();   // 4
 
 	void spcUnk9();
+	void spcUnkA();
 
 	void spcClearEngineFlag8(); // 0x14
+	void spcSetEngineFlag8(); // 0x15
 
 	void spcSetEngineFlag0x4000000(); // 0x54
 	void spcSetCursorSequenceIdToZero(); // 0x55


Commit: 712071f256ada7925732229b62424ca332162f53
    https://github.com/scummvm/scummvm/commit/712071f256ada7925732229b62424ca332162f53
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on actor pathfinding logic

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/background.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/screen.cpp
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 2329d16420..10603dbcee 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -23,6 +23,7 @@
 #include "dragons.h"
 #include "actorresource.h"
 #include "actor.h"
+#include "scene.h"
 
 namespace Dragons {
 
@@ -170,11 +171,152 @@ void Actor::reset_maybe() {
 	//TODO actor_find_by_resourceId_and_remove_resource_from_mem_maybe(resourceID);
 }
 
-void Actor::pathfinding_maybe(int16 x, int16 y, int16 unk) {
+static const int32 pathfinderXYOffsetTbl[32] =
+		{
+				0x00000100,
+				0x000000fb,
+				0x000000ec,
+				0x000000d4,
+
+				0x000000b5,
+				0x0000008e,
+				0x00000061,
+				0x00000031,
+
+				-0x00000000,
+				-0x31,
+				-0x61,
+				-0x8e,
+
+				-0xb5,
+				-0xd4,
+				-0xec,
+				-0xfb,
+
+				-0xff,
+				-0xfb,
+				-0xec,
+				-0xd4,
+
+				-0xb5,
+				-0x8e,
+				-0x61,
+				-0x31,
+
+				0x00000000,
+				0x00000031,
+				0x00000061,
+				0x0000008e,
+
+				0x000000b5,
+				0x000000d4,
+				0x000000ec,
+				0x000000fb
+		};
+
+
+bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe) {
+	uint8 pathfinderData[32];
+
 	//TODO implement me.
-	 error("Implement pathfinding_maybe()");
-//	x_pos = x;
-//	y_pos = y;
+//	 error("Implement pathfinding_maybe()");
+	int16 priority = 0;
+	int16 var_90_1 = 0;
+	bool isFlag0x10Set = flags & Dragons::ACTOR_FLAG_10;
+	flags &= ~Dragons::ENGINE_FLAG_10;
+
+	if (x_pos == target_x && y_pos == target_y) {
+		if (isFlag0x10Set) {
+			pathfindingCleanup();
+		}
+		return true;
+	}
+
+	if (unkTypeMaybe < 2) {
+		priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x_pos, target_y_pos));
+		if (priority < 0) {
+			priority = 1;
+		}
+
+		if ((unkTypeMaybe != 0 || priority - 1 < 8) && (unkTypeMaybe != 1 || priority - 1 < 16)) {
+			var_90_1 = (unkTypeMaybe ^ 2) < 1 ? 1 : 0;
+		} else {
+			var_90_1 = 1;
+		}
+	}
+	int32 x_related_idx=1;
+	for(; x_related_idx < 320; x_related_idx++) {
+
+		int32 v0_18 = 0;
+		for (int32 s3_1 = 0;s3_1 < 0x20; s3_1++) {
+			int32 v0_19 = s3_1 + 8;
+			if (v0_19 <  0) {
+				v0_19 = s3_1 - 8;
+			}
+			int16 y_offset = (x_related_idx * pathfinderXYOffsetTbl[v0_19 & 0x1f]) / 16;
+			int16 x_offset = (x_related_idx * pathfinderXYOffsetTbl[s3_1 & 0x1f]) / 16;
+			if (target_x + x_offset >= 0 &&
+				 target_y + y_offset >= 0) {
+				priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x + x_offset, target_y + y_offset));
+
+				if ((unkTypeMaybe == 0 && priority - 1 < 8) || (unkTypeMaybe == 1 && priority -1 < 0x10)) {
+					target_x += x_offset;
+					target_y += y_offset;
+					x_related_idx = -1;
+					break;
+				}
+			}
+		}
+		if (x_related_idx == -1) {
+			break;
+		}
+	}
+
+	if (x_related_idx == 320) {
+		if (isFlag0x10Set) {
+			pathfindingCleanup();
+		}
+		return false;
+	}
+
+	if (x_pos == target_x && y_pos == target_y) {
+		if (isFlag0x10Set) {
+			pathfindingCleanup();
+		}
+		return true;
+	}
+
+	int16 var_c8_1 = 0;
+
+	int16 var_c0_1_target_x = target_x;
+	int16 var_b8_1_target_y = target_y;
+
+	memset(pathfinderData, 0, 32);
+
+	field_76 = target_x;
+	field_78 = target_y;
+
+	pathfindingUnk(x_pos, y_pos, target_x, target_y, unkTypeMaybe);
+
+	//FIXME
+	x_pos = target_x;
+	y_pos = target_y;
+
+	return false;
+}
+
+void Actor::pathfindingCleanup() {
+	clearFlag(Dragons::ACTOR_FLAG_10);
+	field_74 = 0;
+	target_x_pos = x_pos;
+	target_y_pos = y_pos;
+	field_76 = -1;
+	field_78 = -1;
+	setFlag(Dragons::ACTOR_FLAG_4);
+
+	if (flags & Dragons::ACTOR_FLAG_200) {
+		clearFlag(Dragons::ACTOR_FLAG_800);
+	}
 }
 
 void Actor::waitUntilFlag8IsSet() {
@@ -199,4 +341,82 @@ void Actor::waitUntilFlag8And4AreSet() {
 	}
 }
 
+void Actor::clearFlag(uint32 flag) {
+	flags &= ~flag;
+}
+
+void Actor::setFlag(uint32 flag) {
+	flags |= flag;
+}
+
+uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType) {
+	if (unkType == 2) {
+		return 1;
+	}
+	uint16 width = getEngine()->_scene->getStageWidth();
+	uint16 height = getEngine()->_scene->getStageHeight();
+
+	if (unkType & 0x8000
+	|| actor_x < 0
+	|| width - 1 < actor_x
+	|| actor_y < 0
+	|| height - 1 < actor_y
+	|| target_x < 0
+	|| width - 1 < target_x
+	|| target_y < 0
+	|| height - 1 < target_y) {
+		return 0;
+	}
+
+	int32 x_increment = 0;
+	int32 y_increment = 0;
+	if (target_y == actor_y && target_x == target_y) {
+		return 1;
+	}
+
+	if (target_y != actor_y && target_x == actor_x) {
+		y_increment = target_y - actor_y > 0 ? 1 : -1;
+	} else {
+		if (target_y == actor_y) {
+			if (target_x == actor_x) {
+				x_increment = 0;
+				y_increment = target_y - actor_y > 0 ? 1 : -1;
+			} else {
+				x_increment = target_x - actor_x > 0 ? 1 : -1;
+				y_increment = 0;
+			}
+		} else {
+			if (ABS(target_y - actor_y) < ABS(target_x - actor_x)) {
+				x_increment = target_x - actor_x > 0 ? 1 : -1;
+				y_increment = ((target_y - actor_y) << 0x10) / (target_x - actor_x);
+				if ((target_y - actor_y > 0 && y_increment < 0) || (target_y - actor_y < 0 && y_increment > 0)) {
+					y_increment = -y_increment;
+				}
+			} else {
+				y_increment = target_y - actor_y > 0 ? 1 : -1;
+				x_increment = ((target_x - actor_x) << 0x10) / (target_y - actor_y);
+				if ((target_x - actor_x > 0 && x_increment < 0) || (target_x - actor_x < 0 && x_increment > 0)) {
+					x_increment = -x_increment;
+				}
+			}
+		}
+	}
+
+	// 0x80034d28
+	int16 x = actor_x;
+	int16 y = actor_y;
+	for(;;) {
+		if (x+1 == target_x && y+1 == target_y) {
+			return 1;
+		}
+		int16 priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(x, y));
+		if ( priority < 0) {
+			priority = 1;
+		}
+		// 0x80034d70
+		break; //TODO FIX ME
+	}
+	return 0;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 02d8caf282..8f01f6c576 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -100,8 +100,8 @@ public:
 	uint32 field_30;
 	uint16 field_34[32];
 	uint16 field_74;
-	uint16 field_76;
-	uint16 field_78;
+	int16 field_76;
+	int16 field_78;
 	uint16 field_7a;
 	int32 field_7c;
 	uint16 field_80;
@@ -120,10 +120,15 @@ public:
 	byte *getSeqIpAtOffset(uint32 offset);
 	void loadFrame(uint16 frameOffset);
 	void reset_maybe();
-	void pathfinding_maybe(int16 x, int16 y, int16 unk);
+	bool pathfinding_maybe(int16 target_x, int16 target_y, int16 isNotFlicker);
 	void waitUntilFlag8IsSet();
 	void waitUntilFlag8And4AreSet();
 
+	void clearFlag(uint32 flag);
+	void setFlag(uint32 flag);
+private:
+	void pathfindingCleanup();
+	uint16 pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 291b824563..49b43cc661 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -66,8 +66,8 @@ bool Background::load(byte *dataStart, Common::SeekableReadStream &stream) {
 	_palette[0] = 0x80; //FIXME update palette
 	_palette[1] = 0x80;
 
-	_points1 = loadPoints(stream);
-	_points2 = loadPoints(stream);
+	_points1 = loadPoints(stream); // 0x200
+	_points2 = loadPoints(stream); // 0x280
 	stream.seek(0x305);
 	uint8 tileindexOffset = stream.readByte();
 	stream.seek(0x308);
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 378208cdbe..40096e0af3 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -102,6 +102,7 @@ public:
 	ActorManager *_actorManager;
 	DragonINIResource *_dragonINIResource;
 	uint16 _cursorSequenceID;
+	Scene *_scene;
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
@@ -109,7 +110,6 @@ private:
 	DragonRMS *_dragonRMS;
 	DragonVAR *_dragonVAR;
 	BackgroundResourceLoader *_backgroundResourceLoader;
-	Scene *_scene;
 	SequenceOpcodes *_sequenceOpcodes;
 	ScriptOpcodes *_scriptOpcodes;
 	uint32 _nextUpdatetime;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index bf5aa20b56..0d5857f37e 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -234,4 +234,16 @@ uint16 Scene::getSceneId() {
 	return (uint16)_currentSceneId;
 }
 
+Common::Point Scene::getPoint(uint32 pointIndex) {
+	return _stage->getPoint2(pointIndex);
+}
+
+uint16 Scene::getStageWidth() {
+	return _stage->getWidth();
+}
+
+uint16 Scene::getStageHeight() {
+	return _stage->getHeight();
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index ba8fb75a5b..cd8cd2294a 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -63,6 +63,9 @@ public:
 	bool contains(DragonINI *ini);
 	byte *getPalette();
 	uint16 getSceneId();
+	Common::Point getPoint(uint32 pointIndex);
+	uint16 getStageWidth();
+	uint16 getStageHeight();
 private:
 	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
 
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 5ad6d76d1d..3639fdb0f3 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -119,6 +119,15 @@ Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect r
 	if (h > 0 && destY + h >= 200) {
 		h -= (destY + h) - 200;
 	}
+
+	if (w < 0) {
+		w = 0;
+	}
+
+	if (h < 0) {
+		h = 0;
+	}
+
 	return Common::Rect(x, y, x + w, y + h);
 }
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 36231b3726..b06d31db45 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -25,6 +25,7 @@
 #include "dragons/dragonflg.h"
 #include "dragons/dragonini.h"
 #include "dragons/dragonobd.h"
+#include "dragons/scene.h"
 #include "dragons/scriptopcodes.h"
 #include "dragons/specialopcodes.h"
 #include "dragons/actor.h"
@@ -422,11 +423,40 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 	if (field6 & 0x8000) {
 		s3 = 0 > (field6 ^ 0xffff) ? 1 : 0;
 	}
+	Common::Point point = _vm->_scene->getPoint(field8);
 
 	if (field4 != -1) {
+		if (field6 != -1) {
+			if (!(field0 & 0x8000)) {
+				assert(ini->actor);
+				ini->actor->flags |= Dragons::ACTOR_FLAG_800;
+				ini->actor->updateSequence(field6 & 0x7fff);
+			}
+			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 0x10 : (field4 & 0x7fff) << 7;
+		}
+
+		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
+		ini->actor->pathfinding_maybe(point.x, point.y, isFlicker ? 0 : 1);
+
+		if(s3 == 0) {
+			while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
+				_vm->waitForFrames(1);
+			}
+		}
+		ini->x = point.x;
+		ini->y = point.y;
+		ini->actor->flags &= ~Dragons::ACTOR_FLAG_800;
 
 	} else {
+		ini->x = point.x;
+		ini->actor->x_pos = point.x;
+		ini->y = point.y;
+		ini->actor->y_pos = point.y;
 
+		if (field4 != field6) {
+			ini->actor->field_7c = field4;
+			ini->actor->updateSequence(field6 & 0x7fff);
+		}
 	}
 }
 
@@ -457,22 +487,19 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
 			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 0x10 : (field4 & 0x7fff) << 7;
+		}
+		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
+		ini->actor->pathfinding_maybe(field8, fieldA, isFlicker ? 0 : 1);
 
-			if (_vm->_dragonINIResource->isFlicker(ini)) {
-
-			}
-			bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
-			ini->actor->pathfinding_maybe(field8, fieldA, isFlicker ? 0 : 1);
-
-			if(s3 == 0) {
-				while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
-					_vm->waitForFrames(1);
-				}
+		if(s3 == 0) {
+			while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
+				_vm->waitForFrames(1);
 			}
-			ini->x = field8;
-			ini->y = fieldA;
-			ini->actor->flags &= ~Dragons::ACTOR_FLAG_800;
 		}
+		ini->x = field8;
+		ini->y = fieldA;
+		ini->actor->flags &= ~Dragons::ACTOR_FLAG_800;
+
 	} else {
 		assert(ini->actor);
 		ini->x = field8;


Commit: fa842a0c7ce697fe1bfd2c78ed7c3e7d01a4492f
    https://github.com/scummvm/scummvm/commit/fa842a0c7ce697fe1bfd2c78ed7c3e7d01a4492f
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on pathfinding

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 10603dbcee..2ce205343e 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -388,13 +388,13 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		} else {
 			if (ABS(target_y - actor_y) < ABS(target_x - actor_x)) {
 				x_increment = target_x - actor_x > 0 ? 1 : -1;
-				y_increment = ((target_y - actor_y) << 0x10) / (target_x - actor_x);
+				y_increment = ((target_y - actor_y) /*<< 0x10*/) / (target_x - actor_x);
 				if ((target_y - actor_y > 0 && y_increment < 0) || (target_y - actor_y < 0 && y_increment > 0)) {
 					y_increment = -y_increment;
 				}
 			} else {
 				y_increment = target_y - actor_y > 0 ? 1 : -1;
-				x_increment = ((target_x - actor_x) << 0x10) / (target_y - actor_y);
+				x_increment = ((target_x - actor_x) /*<< 0x10*/) / (target_y - actor_y);
 				if ((target_x - actor_x > 0 && x_increment < 0) || (target_x - actor_x < 0 && x_increment > 0)) {
 					x_increment = -x_increment;
 				}
@@ -413,10 +413,18 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		if ( priority < 0) {
 			priority = 1;
 		}
-		// 0x80034d70
-		break; //TODO FIX ME
+		if (!(unkType & 0x7fff) && (priority == 0 || priority >= 9)) {
+			return 0;
+		}
+
+		if ((unkType & 0x7fff) == 1) {
+			if (priority == 0 || priority >= 0x11) {
+				return 0;
+			}
+		}
+		x += x_increment;
+		y += y_increment;
 	}
-	return 0;
 }
 
 } // End of namespace Dragons


Commit: e74331f38dc9a649bea8ef9b544b84d699464387
    https://github.com/scummvm/scummvm/commit/e74331f38dc9a649bea8ef9b544b84d699464387
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: pathfinding work

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/background.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 2ce205343e..fb76b5941f 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -374,28 +374,31 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		return 1;
 	}
 
+	int16 diffX = target_x - actor_x;
+	int16 diffY = target_y - actor_y;
+
 	if (target_y != actor_y && target_x == actor_x) {
-		y_increment = target_y - actor_y > 0 ? 1 : -1;
+		y_increment = diffY > 0 ? 1 : -1;
 	} else {
 		if (target_y == actor_y) {
 			if (target_x == actor_x) {
 				x_increment = 0;
-				y_increment = target_y - actor_y > 0 ? 1 : -1;
+				y_increment = diffY > 0 ? 1 : -1;
 			} else {
-				x_increment = target_x - actor_x > 0 ? 1 : -1;
+				x_increment = diffX > 0 ? 1 : -1;
 				y_increment = 0;
 			}
 		} else {
-			if (ABS(target_y - actor_y) < ABS(target_x - actor_x)) {
-				x_increment = target_x - actor_x > 0 ? 1 : -1;
-				y_increment = ((target_y - actor_y) /*<< 0x10*/) / (target_x - actor_x);
-				if ((target_y - actor_y > 0 && y_increment < 0) || (target_y - actor_y < 0 && y_increment > 0)) {
+			if (ABS(diffY) < ABS(diffX)) {
+				x_increment = diffX > 0 ? 1 : -1;
+				y_increment = ((diffY) /*<< 0x10*/) / (diffX);
+				if ((diffY > 0 && y_increment < 0) || (diffY < 0 && y_increment > 0)) {
 					y_increment = -y_increment;
 				}
 			} else {
-				y_increment = target_y - actor_y > 0 ? 1 : -1;
-				x_increment = ((target_x - actor_x) /*<< 0x10*/) / (target_y - actor_y);
-				if ((target_x - actor_x > 0 && x_increment < 0) || (target_x - actor_x < 0 && x_increment > 0)) {
+				y_increment = diffY > 0 ? 1 : -1;
+				x_increment = ((diffX) /*<< 0x10*/) / (diffY);
+				if ((diffX > 0 && x_increment < 0) || (diffX < 0 && x_increment > 0)) {
 					x_increment = -x_increment;
 				}
 			}
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 49b43cc661..46acc39e15 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -57,7 +57,7 @@ int16 PriorityLayer::getPriority(Common::Point pos) {
 	const int16 tx = pos.x / TILE_WIDTH, sx = pos.x % TILE_WIDTH;
 	const int16 ty = pos.y / TILE_HEIGHT, sy = pos.y % TILE_HEIGHT;
 	uint16 mapIndex = READ_LE_UINT16(_map + 2 * (tx + ty * _mapWidth));
-	return _values[mapIndex * 32 * 8 + sx + sy * 32] + 1;
+	return _values[mapIndex * TILE_WIDTH * TILE_HEIGHT + sx + sy * TILE_WIDTH] + 1;
 
 }
 
@@ -165,7 +165,7 @@ int16 Background::getPriorityAtPoint(Common::Point pos) {
 		return -1;
 	}
 	int16 priority = _priorityLayer->getPriority(pos);
-	return priority < 0x10 ? priority : 0;
+	return priority < 0x11 ? priority : 0;
 }
 
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(


Commit: 3cc1746bc315521bebc081bbdaac6afd0b2aa954
    https://github.com/scummvm/scummvm/commit/3cc1746bc315521bebc081bbdaac6afd0b2aa954
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on pathfinding

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index fb76b5941f..25b5abe53a 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -260,8 +260,9 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 				priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x + x_offset, target_y + y_offset));
 
 				if ((unkTypeMaybe == 0 && priority - 1 < 8) || (unkTypeMaybe == 1 && priority -1 < 0x10)) {
-					target_x += x_offset;
-					target_y += y_offset;
+					//TODO FIXME
+//					target_x += x_offset;
+//					target_y += y_offset;
 					x_related_idx = -1;
 					break;
 				}
@@ -406,13 +407,13 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 	}
 
 	// 0x80034d28
-	int16 x = actor_x;
-	int16 y = actor_y;
+	int32 x = actor_x << 0x10;
+	int32 y = actor_y << 0x10;
 	for(;;) {
-		if (x+1 == target_x && y+1 == target_y) {
+		if ((x+0x8000) >> 0x10 == target_x && (y+0x8000) >> 0x10 == target_y) {
 			return 1;
 		}
-		int16 priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(x, y));
+		int16 priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(x>>0x10, y>>0x10));
 		if ( priority < 0) {
 			priority = 1;
 		}


Commit: 925b2292d607e5f9612b270c110ef8e4587af4e0
    https://github.com/scummvm/scummvm/commit/925b2292d607e5f9612b270c110ef8e4587af4e0
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on actor pathfinding

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 25b5abe53a..da401e80ea 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -217,7 +217,7 @@ static const int32 pathfinderXYOffsetTbl[32] =
 
 bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe) {
 	uint8 pathfinderData[32];
-
+	debug(1, "pathfinding. (%X,%X) -> (%X,%X)", x_pos, y_pos, target_x, target_y);
 	//TODO implement me.
 //	 error("Implement pathfinding_maybe()");
 	int16 priority = 0;
@@ -351,6 +351,8 @@ void Actor::setFlag(uint32 flag) {
 }
 
 uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType) {
+	debug(1, "pathfindingUnk. (%X,%X) -> (%X,%X) %d", x_pos, y_pos, target_x, target_y, unkType);
+
 	if (unkType == 2) {
 		return 1;
 	}
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 0d5857f37e..6d8ed84011 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -44,7 +44,6 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 		ScriptOpCall scriptOpCall;
 		scriptOpCall._code = obd + 4;
 		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
-		_currentSceneId = -1;
 		_scriptOpcodes->runScript(scriptOpCall);
 	}
 }
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index b06d31db45..a46d4eb6cd 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -599,11 +599,11 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 			if (s1 == -1) {
 				if (ini->iptIndex_maybe != -1) {
 					// TODO ipt_img_file_related_3(ini->iptIndex_maybe);
-					error("TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
+					//error("TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
 				}
 			} else {
 				// TODO ipt_img_file_related_2(s1);
-				error("TODO ipt_img_file_related_2(s1);");
+				//error("TODO ipt_img_file_related_2(s1);");
 			}
 		}
 	}


Commit: b7a731b991788f5d353e2fc08303be23dcd91779
    https://github.com/scummvm/scummvm/commit/b7a731b991788f5d353e2fc08303be23dcd91779
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed pathfinder target adjustment logic

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index da401e80ea..43a28246fb 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -237,47 +237,46 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		if (priority < 0) {
 			priority = 1;
 		}
-
-		if ((unkTypeMaybe != 0 || priority - 1 < 8) && (unkTypeMaybe != 1 || priority - 1 < 16)) {
-			var_90_1 = (unkTypeMaybe ^ 2) < 1 ? 1 : 0;
-		} else {
-			var_90_1 = 1;
-		}
 	}
-	int32 x_related_idx=1;
-	for(; x_related_idx < 320; x_related_idx++) {
-
-		int32 v0_18 = 0;
-		for (int32 s3_1 = 0;s3_1 < 0x20; s3_1++) {
-			int32 v0_19 = s3_1 + 8;
-			if (v0_19 <  0) {
-				v0_19 = s3_1 - 8;
-			}
-			int16 y_offset = (x_related_idx * pathfinderXYOffsetTbl[v0_19 & 0x1f]) / 16;
-			int16 x_offset = (x_related_idx * pathfinderXYOffsetTbl[s3_1 & 0x1f]) / 16;
-			if (target_x + x_offset >= 0 &&
-				 target_y + y_offset >= 0) {
-				priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x + x_offset, target_y + y_offset));
-
-				if ((unkTypeMaybe == 0 && priority - 1 < 8) || (unkTypeMaybe == 1 && priority -1 < 0x10)) {
-					//TODO FIXME
-//					target_x += x_offset;
-//					target_y += y_offset;
-					x_related_idx = -1;
-					break;
+	if ((unkTypeMaybe != 0 || priority - 1 < 8) && (unkTypeMaybe != 1 || priority - 1 < 16)) {
+		var_90_1 = (unkTypeMaybe ^ 2) < 1 ? 1 : 0;
+
+		int32 x_related_idx=1;
+		for(; x_related_idx < 320; x_related_idx++) {
+
+			int32 v0_18 = 0;
+			for (int32 s3_1 = 0;s3_1 < 0x20; s3_1++) {
+				int32 v0_19 = s3_1 + 8;
+				if (v0_19 <  0) {
+					v0_19 = s3_1 - 8;
+				}
+				int16 y_offset = (x_related_idx * pathfinderXYOffsetTbl[v0_19 & 0x1f]) / 16;
+				int16 x_offset = (x_related_idx * pathfinderXYOffsetTbl[s3_1 & 0x1f]) / 16;
+				if (target_x + x_offset >= 0 &&
+					target_y + y_offset >= 0) {
+					priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x + x_offset, target_y + y_offset));
+
+					if ((unkTypeMaybe == 0 && priority - 1 < 8) || (unkTypeMaybe == 1 && priority -1 < 0x10)) {
+						target_x += x_offset;
+						target_y += y_offset;
+						x_related_idx = -1;
+						break;
+					}
 				}
 			}
+			if (x_related_idx == -1) {
+				break;
+			}
 		}
-		if (x_related_idx == -1) {
-			break;
-		}
-	}
 
-	if (x_related_idx == 320) {
-		if (isFlag0x10Set) {
-			pathfindingCleanup();
+		if (x_related_idx == 320) {
+			if (isFlag0x10Set) {
+				pathfindingCleanup();
+			}
+			return false;
 		}
-		return false;
+	} else {
+		var_90_1 = 1;
 	}
 
 	if (x_pos == target_x && y_pos == target_y) {


Commit: c4eac3b965b146805c44463203637babb1b4d2ae
    https://github.com/scummvm/scummvm/commit/c4eac3b965b146805c44463203637babb1b4d2ae
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: pathfinding

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 43a28246fb..b7b173c714 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -222,6 +222,8 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 //	 error("Implement pathfinding_maybe()");
 	int16 priority = 0;
 	int16 var_90_1 = 0;
+	int16 var88 = 0;
+
 	bool isFlag0x10Set = flags & Dragons::ACTOR_FLAG_10;
 	flags &= ~Dragons::ENGINE_FLAG_10;
 
@@ -296,8 +298,27 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 	field_76 = target_x;
 	field_78 = target_y;
 
-	pathfindingUnk(x_pos, y_pos, target_x, target_y, unkTypeMaybe);
+	if(!pathfindingUnk(x_pos, y_pos, target_x, target_y, unkTypeMaybe)) {
+		// TODO 0x8003398c
+	}
+
+	if (var88 == 0) { //0x80033af0
+		int16 i=0;
+		for (;i < 0x20;i++) {
+			Common::Point point = getEngine()->_scene->getPoint(i);
+			if (point.x != -1) {
+				//TODO 0x80033b2c
+			}
+		}
 
+		if (i == 0x20) {
+			//TODO 0x80033b80
+		}
+
+		if (var88 == 0) {
+			//TODO 0x80033e48
+		}
+	}
 	//FIXME
 	x_pos = target_x;
 	y_pos = target_y;


Commit: 080bffb34bdb3ddb5410a20f762be6be4cd6a919
    https://github.com/scummvm/scummvm/commit/080bffb34bdb3ddb5410a20f762be6be4cd6a919
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: pathfinding

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index b7b173c714..15f34ee639 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -303,11 +303,13 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 	}
 
 	if (var88 == 0) { //0x80033af0
-		int16 i=0;
-		for (;i < 0x20;i++) {
+		int16 i;
+		for (i = 0; i < 0x20; i++) {
 			Common::Point point = getEngine()->_scene->getPoint(i);
 			if (point.x != -1) {
-				//TODO 0x80033b2c
+				if (pathfindingUnk(x_pos, x_pos, point.x, point.y, unkTypeMaybe)) {
+					break;
+				}
 			}
 		}
 
@@ -317,8 +319,32 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 
 		if (var88 == 0) {
 			//TODO 0x80033e48
+			for (i = 0; i < 0x20; i++) {
+				Common::Point point = getEngine()->_scene->getPoint(i);
+				if (point.x != -1) {
+					if (pathfindingUnk(x_pos, x_pos, point.x, point.y, unkTypeMaybe)) {
+						break;
+					}
+				}
+			}
+
+			if (i == 0x20) {
+				//TODO 0x80033ed0
+			}
 		}
 	}
+
+	if (pathfindingUnk(x_pos, x_pos, var_c0_1_target_x, var_b8_1_target_y, unkTypeMaybe)) {
+		//0x8003437c
+		if (var_90_1 == 0 /*TODO other expressions here */) {
+			//0x80034568
+		} else {
+
+		}
+	} else {
+		//TODO 0x800341f0
+	}
+
 	//FIXME
 	x_pos = target_x;
 	y_pos = target_y;


Commit: d9e341f0e16354ba249bf1f55be4925807340828
    https://github.com/scummvm/scummvm/commit/d9e341f0e16354ba249bf1f55be4925807340828
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: pathfinding

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 15f34ee639..c182d0ff85 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -290,8 +290,8 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 
 	int16 var_c8_1 = 0;
 
-	int16 var_c0_1_target_x = target_x;
-	int16 var_b8_1_target_y = target_y;
+	int16 newTargetX = target_x;
+	int16 newTargetY = target_y;
 
 	memset(pathfinderData, 0, 32);
 
@@ -334,15 +334,37 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		}
 	}
 
-	if (pathfindingUnk(x_pos, x_pos, var_c0_1_target_x, var_b8_1_target_y, unkTypeMaybe)) {
+	if (pathfindingUnk(x_pos, x_pos, newTargetX, newTargetY, unkTypeMaybe)) {
 		//0x8003437c
-		if (var_90_1 == 0 /*TODO other expressions here */) {
+		int16 origDistance = abs(target_x - x_pos) * abs(target_x - x_pos) + abs(target_y - y_pos) * abs(target_y - y_pos);
+		int16 newTargetDiffDistance = abs(newTargetX - target_x) * abs(newTargetX - target_x) + abs(newTargetY - target_y) * abs(newTargetY - target_y);
+
+		if (var_90_1 == 0
+		|| origDistance >= 625
+		|| ((target_x != x_pos || target_y != y_pos) && origDistance >= newTargetDiffDistance)) {
 			//0x80034568
+			debug(1, "0x80034568");
+			field_74 = var_c8_1 - 1;
+
+			if (var_c8_1 == 0) {
+				target_x = newTargetX;
+				target_y = newTargetY;
+				field_76 = -1;
+				field_78 = -1;
+			} else {
+				uint16 pointId = field_34[field_74];
+				Common::Point point = getEngine()->_scene->getPoint(pointId);
+				target_x = point.x;
+				target_y = point.y;
+			}
+			//TODO continue here
 		} else {
-
+			//0x80034470
+			debug(1, "0x80034470");
 		}
 	} else {
 		//TODO 0x800341f0
+		debug(1, "0x800341f0");
 	}
 
 	//FIXME
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 8f01f6c576..3b9c86e7d3 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -99,7 +99,7 @@ public:
 	uint32 field_2c;
 	uint32 field_30;
 	uint16 field_34[32];
-	uint16 field_74;
+	int16 field_74;
 	int16 field_76;
 	int16 field_78;
 	uint16 field_7a;


Commit: 1ecd63ca0257858a0a7db1ae3e359d0ae5b3de27
    https://github.com/scummvm/scummvm/commit/1ecd63ca0257858a0a7db1ae3e359d0ae5b3de27
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Start walking actors along path

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/screen.cpp
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index c182d0ff85..9a13251d61 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -21,6 +21,7 @@
  */
 #include <common/debug.h>
 #include "dragons.h"
+#include "dragonini.h"
 #include "actorresource.h"
 #include "actor.h"
 #include "scene.h"
@@ -344,7 +345,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		|| ((target_x != x_pos || target_y != y_pos) && origDistance >= newTargetDiffDistance)) {
 			//0x80034568
 			debug(1, "0x80034568");
-			field_74 = var_c8_1 - 1;
+			walkPointsIndex = var_c8_1 - 1;
 
 			if (var_c8_1 == 0) {
 				target_x = newTargetX;
@@ -352,12 +353,20 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 				field_76 = -1;
 				field_78 = -1;
 			} else {
-				uint16 pointId = field_34[field_74];
+				uint16 pointId = walkPointsTbl[walkPointsIndex];
 				Common::Point point = getEngine()->_scene->getPoint(pointId);
 				target_x = point.x;
 				target_y = point.y;
 			}
-			//TODO continue here
+			int16 newSeqId = pathfindingUpdateTarget(target_x, target_y);
+			if (newSeqId != -1 && !(flags & ACTOR_FLAG_800)) {
+				_sequenceID2 = newSeqId;
+			}
+			if (_sequenceID != _sequenceID2 + 8 && !(flags & ACTOR_FLAG_800)) {
+				updateSequence(_sequenceID2 + 8);
+			}
+			setFlag(ACTOR_FLAG_10);
+			return true;
 		} else {
 			//0x80034470
 			debug(1, "0x80034470");
@@ -367,16 +376,12 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		debug(1, "0x800341f0");
 	}
 
-	//FIXME
-	x_pos = target_x;
-	y_pos = target_y;
-
 	return false;
 }
 
 void Actor::pathfindingCleanup() {
 	clearFlag(Dragons::ACTOR_FLAG_10);
-	field_74 = 0;
+	walkPointsIndex = 0;
 	target_x_pos = x_pos;
 	target_y_pos = y_pos;
 	field_76 = -1;
@@ -418,6 +423,10 @@ void Actor::setFlag(uint32 flag) {
 	flags |= flag;
 }
 
+bool Actor::isFlagSet(uint32 flag) {
+	return (flags & flag) == flag;
+}
+
 uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType) {
 	debug(1, "pathfindingUnk. (%X,%X) -> (%X,%X) %d", x_pos, y_pos, target_x, target_y, unkType);
 
@@ -501,4 +510,102 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 	}
 }
 
+	int16 Actor::pathfindingUpdateTarget(int16 newTargetX, int16 newTargetY) {
+		field_24_x = x_pos << 0x10;
+		field_28_y = y_pos << 0x10;
+
+		int16 diffX = newTargetX - x_pos;
+		int16 diffY = newTargetY - y_pos;
+		int16 absDiffX = abs(diffX);
+		int16 absDiffY = abs(diffY) * 2;
+
+		int16 t2 = 0;
+		int16 newSequenceId = -1;
+
+		if (diffX == 0) {
+			if (diffY == 0) {
+				return -1;
+			}
+			field_2c = 0;
+			field_30 = 0x10000;
+		} else {
+			if (diffY == 0) {
+				field_2c = 0x10000;
+				field_30 = 0;
+			} else {
+				if (absDiffX >= absDiffY) {
+					field_2c = 0x10000;
+					field_30 = (absDiffY << 0x10) / absDiffX;
+				} else {
+					field_2c = (absDiffX << 0x10) / absDiffY;
+					field_30 = 0x10000;
+				}
+			}
+		}
+		field_30 = ((field_30 >> 5) * field_7c) >> 0xb;
+		field_2c = ((field_2c >> 5) * field_7c) >> 0xb;
+
+		if (diffX < 0) {
+			field_2c = -field_2c;
+			t2 = 2;
+		}
+
+		if (diffY < 0) {
+			field_30 = -field_30;
+			t2++;
+		}
+
+		switch (t2) {
+			case 0 :
+				newSequenceId = absDiffX < (absDiffY * 2) ? 2 : 0;
+				break;
+			case 1 :
+				error("TODO t2 == 1 0x80035138");
+			case 2 :
+				newSequenceId = absDiffX < (absDiffY * 2) ? 2 : 4;
+				break;
+			case 3 :
+				newSequenceId = absDiffX < (absDiffY * 2) ? 6 : 4;
+				break;
+			default :
+				break;
+		}
+
+		field_30 = field_30 / 2;
+
+		if (getEngine()->_dragonINIResource->isFlicker(_actorID)) {
+			// TODO 0x8003523c
+			error("FIXME 0x8003523c");
+		}
+
+		target_x_pos = newTargetX;
+		target_y_pos = newTargetY;
+
+		return newSequenceId;
+	}
+
+	void Actor::walkPath() {
+		if (isFlagClear(Dragons::ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
+			field_24_x += (((field_e * field_2c) / 256) * 5) / 4;
+			field_28_y += (((field_e * field_30) / 256) * 5) / 4;
+
+			if ( (field_2c >= 0 && target_x_pos < (field_24_x >> 0x10))
+			|| (field_2c < 0 && (field_24_x >> 0x10) < target_x_pos)) {
+				field_24_x = target_x_pos << 0x10;
+			}
+
+			if ( (field_30 >= 0 && target_y_pos < (field_28_y >> 0x10))
+				 || (field_30 < 0 && (field_28_y >> 0x10) < target_y_pos)) {
+				field_28_y = target_y_pos << 0x10;
+			}
+
+			x_pos = field_24_x >> 0x10;
+			y_pos = field_28_y >> 0x10;
+
+			if (x_pos == target_x_pos && y_pos == target_y_pos) { //TODO temp logic
+				clearFlag(ACTOR_FLAG_10);
+			}
+		}
+	}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 3b9c86e7d3..f6f6a03312 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -37,7 +37,7 @@ enum ActorFlags {
 	ACTOR_FLAG_2 = 2,
 	ACTOR_FLAG_4 = 4,
 	ACTOR_FLAG_8 = 8,
-	ACTOR_FLAG_10 = 0x10,
+	ACTOR_FLAG_10 = 0x10, //actor is walking a path
 	ACTOR_FLAG_20 = 0x20,
 	ACTOR_FLAG_40 = 0x40,
 	ACTOR_FLAG_80 = 0x80,
@@ -94,12 +94,12 @@ public:
 	int16 y_pos;
 	int16 target_x_pos;
 	int16 target_y_pos;
-	uint32 field_24;
-	uint32 field_28;
-	uint32 field_2c;
-	uint32 field_30;
-	uint16 field_34[32];
-	int16 field_74;
+	int32 field_24_x;
+	int32 field_28_y;
+	int32 field_2c;
+	int32 field_30;
+	uint16 walkPointsTbl[32];
+	int16 walkPointsIndex;
 	int16 field_76;
 	int16 field_78;
 	uint16 field_7a;
@@ -121,14 +121,19 @@ public:
 	void loadFrame(uint16 frameOffset);
 	void reset_maybe();
 	bool pathfinding_maybe(int16 target_x, int16 target_y, int16 isNotFlicker);
+	void walkPath();
 	void waitUntilFlag8IsSet();
 	void waitUntilFlag8And4AreSet();
 
 	void clearFlag(uint32 flag);
 	void setFlag(uint32 flag);
+	bool isFlagSet(uint32 flag);
+	bool isFlagClear(uint32 flag) { return !isFlagSet(flag); }
+
 private:
 	void pathfindingCleanup();
 	uint16 pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType);
+	int16 pathfindingUpdateTarget(int16 newTargetX, int16 newTargetY);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index bac9b592b3..929829d41d 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -247,6 +247,8 @@ void DragonsEngine::updateHandler() {
 	if (_flags & Dragons::ENGINE_FLAG_20) {
 		engineFlag0x20UpdateFunction();
 	}
+
+	updatePathfindingActors(); //TODO find exact location for this logic.
 }
 
 const char *DragonsEngine::getSavegameFilename(int num) {
@@ -475,6 +477,7 @@ void DragonsEngine::waitForFrames(uint16 numFrames) {
 
 		_scene->draw();
 		_screen->updateScreen();
+		updateEvents();
 	}
 }
 
@@ -482,4 +485,11 @@ void DragonsEngine::playSound(uint16 soundId) {
 	debug(3, "TODO: play sound %d", soundId);
 }
 
+void DragonsEngine::updatePathfindingActors() {
+	for (uint16 i = 0; i < 0x17; i++) {
+		Actor *actor = _actorManager->getActor(i);
+		actor->walkPath();
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 40096e0af3..edbb6b2711 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -157,6 +157,7 @@ public:
 private:
 	void gameLoop();
 	void updateHandler();
+	void updatePathfindingActors();
 	uint32 calulateTimeLeft();
 	void wait();
 	uint16 getIniFromImg();
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 3639fdb0f3..3e70fd6011 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -104,12 +104,12 @@ Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect r
 
 	if (destX < 0) {
 		w += destX;
-		x += destX;
+		x += -destX;
 	}
 
 	if (destY < 0) {
 		h += destY;
-		y += destY;
+		y += -destY;
 	}
 
 	if (w > 0 && destX + w >= 320) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index a46d4eb6cd..b49ffbf25e 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -432,7 +432,7 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 				ini->actor->flags |= Dragons::ACTOR_FLAG_800;
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
-			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 0x10 : (field4 & 0x7fff) << 7;
+			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
 		}
 
 		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
@@ -486,7 +486,7 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 				ini->actor->flags |= Dragons::ACTOR_FLAG_800;
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
-			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 0x10 : (field4 & 0x7fff) << 7;
+			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
 		}
 		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
 		ini->actor->pathfinding_maybe(field8, fieldA, isFlicker ? 0 : 1);


Commit: eee3f64a888cbcd577b727db4744a1481d9dcc40
    https://github.com/scummvm/scummvm/commit/eee3f64a888cbcd577b727db4744a1481d9dcc40
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add support for sprite flipping. More pathfinding logic

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/actorresource.h
    engines/dragons/dragons.cpp
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 9a13251d61..af04df350a 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -602,8 +602,37 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 			x_pos = field_24_x >> 0x10;
 			y_pos = field_28_y >> 0x10;
 
-			if (x_pos == target_x_pos && y_pos == target_y_pos) { //TODO temp logic
-				clearFlag(ACTOR_FLAG_10);
+			if (x_pos == target_x_pos && y_pos == target_y_pos) {
+				if (walkPointsIndex <= 0) {
+					if (field_76 < 0) {
+						clearFlag(ACTOR_FLAG_10);
+						if (isFlagClear(ACTOR_FLAG_200)) {
+							clearFlag(ACTOR_FLAG_800);
+						}
+						setFlag(ACTOR_FLAG_4);
+						clearFlag(ACTOR_FLAG_1);
+						return;
+					} else {
+						target_x_pos = field_76;
+						target_y_pos = field_78;
+						field_76 = -1;
+						field_78 = -1;
+					}
+				} else {
+					walkPointsIndex--;
+					Common::Point point = getEngine()->_scene->getPoint(walkPointsTbl[walkPointsIndex]);
+					target_x_pos = point.x;
+					target_y_pos = point.y;
+				}
+				// 0x8001bcc8
+				if(pathfindingUpdateTarget(target_x_pos, target_y_pos) == -1) {
+					_sequenceID2 = -1;
+				} else {
+					if (_sequenceID != _sequenceID2 + 8 && !(flags & ACTOR_FLAG_800)) {
+						updateSequence(_sequenceID2 + 8);
+					}
+				}
+				setFlag(ACTOR_FLAG_10);
 			}
 		}
 	}
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index f6f6a03312..5ae542b519 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -87,7 +87,7 @@ public:
 	int16 field_e;
 	uint16 sequenceTimer;
 	uint16 _sequenceID;
-	uint16 _sequenceID2;
+	int16 _sequenceID2;
 	int16 priorityLayer;
 	uint16 flags;
 	int16 x_pos;
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index 572d691607..f6ad943615 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -39,6 +39,10 @@ struct ActorFrame {
 	uint16 field_c;
 };
 
+enum FrameFlags {
+	FRAME_FLAG_FLIP_X = 0x800
+};
+
 class ActorResourceLoader {
 private:
 	BigfileArchive *_bigFileArchive;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 929829d41d..ff799d974a 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -201,6 +201,8 @@ void DragonsEngine::gameLoop() {
 }
 
 void DragonsEngine::updateHandler() {
+	//TODO logic here
+
 	updateActorSequences();
 
 	//TODO logic here
@@ -244,11 +246,24 @@ void DragonsEngine::updateHandler() {
 		}
 	}
 
-	if (_flags & Dragons::ENGINE_FLAG_20) {
+	if (isFlagSet(ENGINE_FLAG_4)) {
+		updatePathfindingActors();
+	}
+
+	// TODO 0x8001bed0
+
+	// 0x8001c294
+	if (!(_unkFlags1 & ENGINE_UNK1_FLAG_8)) {
+		//TODO ReadPad();
+	}
+
+	if (isFlagSet(ENGINE_FLAG_20)) {
 		engineFlag0x20UpdateFunction();
 	}
 
-	updatePathfindingActors(); //TODO find exact location for this logic.
+	//TODO vsync update function
+
+	// TODO data_8006a3a0 logic. @ 0x8001c2f4
 }
 
 const char *DragonsEngine::getSavegameFilename(int num) {
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 6d8ed84011..3421b8c067 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -38,6 +38,12 @@ Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, Bi
 void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 	// TODO
 	loadSceneData(sceneId, cameraPointId);
+
+	if (sceneId != 4) {
+		Actor *cursor = _actorManager->getActor(0);
+		//TODO update cursor.
+
+	}
 	//TODO
 	if (!(sceneId & 0x8000)) {
 		byte *obd = _dragonRMS->getObdDataFieldC(sceneId);
@@ -46,6 +52,8 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
 		_scriptOpcodes->runScript(scriptOpCall);
 	}
+	DragonINI *ini = _dragonINIResource->getRecord(0xc4);
+	ini->field_12 = 0;
 }
 
 void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
@@ -204,7 +212,7 @@ void Scene::draw() {
 					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
 						  s->w, s->h, actor->priorityLayer);
-					_screen->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
+					_screen->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X));
 				} else {
 					debug(4, "Actor (not displayed) %d %s (%d, %d) Priority: %d", actor->_actorID,
 						  actor->_actorResource->getFilename(),
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 3e70fd6011..dcef22ee9c 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -44,10 +44,10 @@ Screen::~Screen() {
 }
 
 void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY) {
-	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, destX, destY, srcSurface.w, srcSurface.h);
+	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, destX, destY, srcSurface.w, srcSurface.h, false);
 }
 
-void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect) {
+void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect, bool flipX) {
 	Common::Rect clipRect = clipRectToScreen( destX,  destY, srcRect);
 	if (clipRect.width() == 0 || clipRect.height() == 0) {
 		return;
@@ -60,10 +60,10 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
 		destY = 0;
 	}
 
-	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, destX, destY, clipRect.width(), clipRect.height());
+	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, destX, destY, clipRect.width(), clipRect.height(), flipX);
 }
 
-void Screen::copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height) {
+void Screen::copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height, bool flipX) {
 	assert(buffer);
 
 	assert(destX >= 0 && destX < _backSurface->w);
@@ -76,10 +76,11 @@ void Screen::copyRectToSurface(const void *buffer, int srcPitch, int destX, int
 	byte *dst = (byte *)_backSurface->getBasePtr(destX, destY);
 	for (int i = 0; i < height; i++) {
 		for (int j = 0; j < width; j++) {
-			if ((src[j * 2 + 1] & 0x80) == 0) {
+			uint32 srcIdx = flipX ? width - j - 1 : j;
+			if ((src[srcIdx * 2 + 1] & 0x80) == 0) {
 				// only copy opaque pixels
-				dst[j * 2] = src[j * 2];
-				dst[j * 2 + 1] = src[j * 2 + 1];
+				dst[j * 2] = src[srcIdx * 2];
+				dst[j * 2 + 1] = src[srcIdx * 2 + 1];
 			}
 		}
 		src += srcPitch;
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 43bbe96971..2bb74d358b 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -38,8 +38,8 @@ public:
 
 	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
-	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect);
-	void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height);
+	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false);
+	void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height, bool flipX);
 	void updateScreen();
 private:
 	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);


Commit: 79bc1edb5c8a92ddb193e8be2855d9d010608bba
    https://github.com/scummvm/scummvm/commit/79bc1edb5c8a92ddb193e8be2855d9d010608bba
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: fix sprite off screen with flipped sprite

Changed paths:
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index dcef22ee9c..9bd2098a96 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -44,7 +44,7 @@ Screen::~Screen() {
 }
 
 void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY) {
-	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, destX, destY, srcSurface.w, srcSurface.h, false);
+	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, srcSurface.w, 0, destX, destY, srcSurface.w, srcSurface.h, false);
 }
 
 void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect, bool flipX) {
@@ -60,10 +60,10 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
 		destY = 0;
 	}
 
-	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, destX, destY, clipRect.width(), clipRect.height(), flipX);
+	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, srcSurface.w, clipRect.left, destX, destY, clipRect.width(), clipRect.height(), flipX);
 }
 
-void Screen::copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height, bool flipX) {
+void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX) {
 	assert(buffer);
 
 	assert(destX >= 0 && destX < _backSurface->w);
@@ -76,7 +76,7 @@ void Screen::copyRectToSurface(const void *buffer, int srcPitch, int destX, int
 	byte *dst = (byte *)_backSurface->getBasePtr(destX, destY);
 	for (int i = 0; i < height; i++) {
 		for (int j = 0; j < width; j++) {
-			uint32 srcIdx = flipX ? width - j - 1 : j;
+			int32 srcIdx = flipX ? srcWidth - (srcXOffset * 2) - j - 1 : j;
 			if ((src[srcIdx * 2 + 1] & 0x80) == 0) {
 				// only copy opaque pixels
 				dst[j * 2] = src[srcIdx * 2];
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 2bb74d358b..8c3ee8a321 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -39,9 +39,9 @@ public:
 	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false);
-	void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height, bool flipX);
 	void updateScreen();
 private:
+	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX);
 	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
 };
 


Commit: f528cd29213d21a180dc2e69edcea5bed02fb03e
    https://github.com/scummvm/scummvm/commit/f528cd29213d21a180dc2e69edcea5bed02fb03e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: more pathfinding

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index af04df350a..593e43d319 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -219,8 +219,6 @@ static const int32 pathfinderXYOffsetTbl[32] =
 bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe) {
 	uint8 pathfinderData[32];
 	debug(1, "pathfinding. (%X,%X) -> (%X,%X)", x_pos, y_pos, target_x, target_y);
-	//TODO implement me.
-//	 error("Implement pathfinding_maybe()");
 	int16 priority = 0;
 	int16 var_90_1 = 0;
 	int16 var88 = 0;
@@ -293,6 +291,8 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 
 	int16 newTargetX = target_x;
 	int16 newTargetY = target_y;
+	int16 newX = x_pos;
+	int16 newY = y_pos;
 
 	memset(pathfinderData, 0, 32);
 
@@ -300,7 +300,39 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 	field_78 = target_y;
 
 	if(!pathfindingUnk(x_pos, y_pos, target_x, target_y, unkTypeMaybe)) {
-		// TODO 0x8003398c
+		//  0x8003398c
+		int16 xOffset = -1;
+		//TODO convert to for loops
+		do {
+			int16 yOffset = -1;
+			do {
+				int16 targetXOffset = -1;
+				do {
+					int16 targetYOffset = -1;
+					do {
+						if(pathfindingUnk(newX + xOffset, newY + yOffset, newTargetX + targetXOffset, newTargetY + targetYOffset, unkTypeMaybe | 0x8000)) {
+							targetXOffset = 2;
+							newX += xOffset;
+							newY += yOffset;
+							newTargetX += targetXOffset;
+							newTargetY += targetYOffset;
+							var_90_1 = 0;
+							var88 = 1;
+							x_pos += xOffset;
+							y_pos += yOffset;
+							xOffset = 2;
+							yOffset = 2;
+							targetYOffset = 3;
+						} else {
+							targetYOffset++;
+						}
+					} while(targetYOffset < 2);
+					targetXOffset++;
+				} while(targetXOffset < 2);
+				yOffset++;
+			} while(yOffset < 2);
+			xOffset++;
+		} while(xOffset < 2);
 	}
 
 	if (var88 == 0) { //0x80033af0


Commit: 3210f936d0e9910b685065f337a423ba2419649f
    https://github.com/scummvm/scummvm/commit/3210f936d0e9910b685065f337a423ba2419649f
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: pathfinder

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 593e43d319..d183a0b670 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -348,10 +348,59 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 
 		if (i == 0x20) {
 			//TODO 0x80033b80
+			int16 tempX = newX;
+			int16 tempY = newY;
+			for(int j = 0; j < 0x20; j++) {
+				Common::Point point = getEngine()->_scene->getPoint(i);
+				if (point.x == -1) {
+					continue;
+				}
+				if (pathfindingUnk(newX + 1, tempY, point.x, point.y, unkTypeMaybe)) {
+					newX++;
+					x_pos++;
+					break;
+				} else if (pathfindingUnk(newX - 1, tempY, point.x, point.y, unkTypeMaybe)) {
+					newX--;
+					x_pos--;
+					break;
+				} else if (pathfindingUnk(tempX, newY + 1, point.x, point.y, unkTypeMaybe)) {
+					newY++;
+					y_pos++;
+					break;
+				} else if (pathfindingUnk(tempX, newY - 1, point.x, point.y, unkTypeMaybe)) {
+					newY--;
+					y_pos--;
+					break;
+				} else if (pathfindingUnk(newX + 1, newY + 1, point.x, point.y, unkTypeMaybe)) {
+					newX++;
+					x_pos++;
+					newY++;
+					y_pos++;
+					break;
+				} else if (pathfindingUnk(newX - 1, newY + 1, point.x, point.y, unkTypeMaybe)) {
+					newX--;
+					x_pos--;
+					newY++;
+					y_pos++;
+					break;
+				} else if (pathfindingUnk(newX + 1, newY - 1, point.x, point.y, unkTypeMaybe)) {
+					newX++;
+					x_pos++;
+					newY--;
+					y_pos--;
+					break;
+				} else if (pathfindingUnk(newX - 1, newY - 1, point.x, point.y, unkTypeMaybe)) {
+					newX--;
+					x_pos--;
+					newY--;
+					y_pos--;
+					break;
+				}
+			}
 		}
 
 		if (var88 == 0) {
-			//TODO 0x80033e48
+			// 0x80033e48
 			for (i = 0; i < 0x20; i++) {
 				Common::Point point = getEngine()->_scene->getPoint(i);
 				if (point.x != -1) {
@@ -362,7 +411,42 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 			}
 
 			if (i == 0x20) {
-				//TODO 0x80033ed0
+				// 0x80033ed0
+				for(int j = 0; j < 0x20; j++) {
+					Common::Point point = getEngine()->_scene->getPoint(i);
+					if (point.x == -1) {
+						continue;
+					}
+					if (pathfindingUnk(target_x + 1, target_y, point.x, point.y, unkTypeMaybe)) {
+						target_x++;
+						break;
+					} else if (pathfindingUnk(target_x - 1, target_y, point.x, point.y, unkTypeMaybe)) {
+						target_x--;
+						break;
+					} else if (pathfindingUnk(target_x, target_y + 1, point.x, point.y, unkTypeMaybe)) {
+						target_y++;
+						break;
+					} else if (pathfindingUnk(target_x, target_y - 1, point.x, point.y, unkTypeMaybe)) {
+						target_y--;
+						break;
+					} else if (pathfindingUnk(target_x + 1, target_y + 1, point.x, point.y, unkTypeMaybe)) {
+						target_x++;
+						target_y++;
+						break;
+					} else if (pathfindingUnk(target_x - 1, target_y + 1, point.x, point.y, unkTypeMaybe)) {
+						target_x--;
+						target_y++;
+						break;
+					} else if (pathfindingUnk(target_x + 1, target_y - 1, point.x, point.y, unkTypeMaybe)) {
+						target_x++;
+						target_y--;
+						break;
+					} else if (pathfindingUnk(target_x - 1, target_y - 1, point.x, point.y, unkTypeMaybe)) {
+						target_x--;
+						target_y--;
+						break;
+					}
+				}
 			}
 		}
 	}


Commit: 8a0dac1a11eaf5def8d541188febac6b6484016c
    https://github.com/scummvm/scummvm/commit/8a0dac1a11eaf5def8d541188febac6b6484016c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: pathfinding

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index d183a0b670..68c6e45349 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -287,7 +287,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		return true;
 	}
 
-	int16 var_c8_1 = 0;
+	int16 numWalkPoints = 0;
 
 	int16 newTargetX = target_x;
 	int16 newTargetY = target_y;
@@ -347,7 +347,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		}
 
 		if (i == 0x20) {
-			//TODO 0x80033b80
+			// 0x80033b80
 			int16 tempX = newX;
 			int16 tempY = newY;
 			for(int j = 0; j < 0x20; j++) {
@@ -451,7 +451,30 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		}
 	}
 
-	if (pathfindingUnk(x_pos, x_pos, newTargetX, newTargetY, unkTypeMaybe)) {
+	for (; !pathfindingUnk(newX, newY, newTargetX, newTargetY, unkTypeMaybe); ) {
+		int16 pointId = pathfindingFindClosestPoint(newX, newY, newTargetX, newTargetX, unkTypeMaybe, pathfinderData);
+		if (pointId == -1) {
+			if (isFlag0x10Set) {
+				pathfindingCleanup();
+			}
+			return false;
+		}
+		pathfinderData[pointId] = 1;
+		Common::Point point = getEngine()->_scene->getPoint(pointId);
+		if (numWalkPoints < 2) {
+			if (numWalkPoints > 0 && pathfindingUnk(point.x, point.y, newTargetX, newTargetY, unkTypeMaybe)) {
+				numWalkPoints--;
+			}
+		} else {
+			Common::Point targetPoint = getEngine()->_scene->getPoint(walkPointsTbl[numWalkPoints - 2]);
+			if (pathfindingUnk(point.x, point.y, targetPoint.x, targetPoint.y, unkTypeMaybe)) {
+				numWalkPoints--;
+			}
+		}
+		walkPointsTbl[numWalkPoints] = (uint16)pointId;
+		numWalkPoints++;
+	}
+
 		//0x8003437c
 		int16 origDistance = abs(target_x - x_pos) * abs(target_x - x_pos) + abs(target_y - y_pos) * abs(target_y - y_pos);
 		int16 newTargetDiffDistance = abs(newTargetX - target_x) * abs(newTargetX - target_x) + abs(newTargetY - target_y) * abs(newTargetY - target_y);
@@ -461,18 +484,18 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		|| ((target_x != x_pos || target_y != y_pos) && origDistance >= newTargetDiffDistance)) {
 			//0x80034568
 			debug(1, "0x80034568");
-			walkPointsIndex = var_c8_1 - 1;
+			walkPointsIndex = numWalkPoints - 1;
 
-			if (var_c8_1 == 0) {
-				target_x = newTargetX;
-				target_y = newTargetY;
+			if (numWalkPoints == 0) {
+				target_x_pos = newTargetX;
+				target_y_pos = newTargetY;
 				field_76 = -1;
 				field_78 = -1;
 			} else {
 				uint16 pointId = walkPointsTbl[walkPointsIndex];
 				Common::Point point = getEngine()->_scene->getPoint(pointId);
-				target_x = point.x;
-				target_y = point.y;
+				target_x_pos = point.x;
+				target_y_pos = point.y;
 			}
 			int16 newSeqId = pathfindingUpdateTarget(target_x, target_y);
 			if (newSeqId != -1 && !(flags & ACTOR_FLAG_800)) {
@@ -487,10 +510,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 			//0x80034470
 			debug(1, "0x80034470");
 		}
-	} else {
-		//TODO 0x800341f0
-		debug(1, "0x800341f0");
-	}
+
 
 	return false;
 }
@@ -753,4 +773,24 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		}
 	}
 
+	int16 Actor::pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y,
+											 int16 unkType, uint8 *pointsInUseTbl) {
+		int16 pointId = -1;
+		uint32 minDist = 0xffffffff;
+
+		for (int i = 0; i < 0x22; i++) {
+			Common::Point point = getEngine()->_scene->getPoint(i);
+			if (point.x != -1 && pointsInUseTbl[i] == 0) {
+				if (pathfindingUnk(point.x, point.y, target_x, target_y, unkType)) {
+					uint32 dist = abs(point.x - actor_x) * abs(point.x - actor_x) + abs(point.y - actor_y) * abs(point.y - actor_y);
+					if ( dist < minDist) {
+						minDist = dist;
+						pointId = i;
+					}
+				}
+			}
+		}
+		return pointId;
+	}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 5ae542b519..7e598eb71c 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -134,6 +134,8 @@ private:
 	void pathfindingCleanup();
 	uint16 pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType);
 	int16 pathfindingUpdateTarget(int16 newTargetX, int16 newTargetY);
+	int16 pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType,
+									  uint8 *pointsInUseTbl);
 };
 
 } // End of namespace Dragons


Commit: c7bdbf4a24e16584035996a21087d9c52a9eb144
    https://github.com/scummvm/scummvm/commit/c7bdbf4a24e16584035996a21087d9c52a9eb144
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: finished main pathfinder funxction

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 68c6e45349..7a67e7a620 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -508,7 +508,25 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 			return true;
 		} else {
 			//0x80034470
-			debug(1, "0x80034470");
+			int16 diffX = target_x - newX;
+			int16 diffY = newY - target_y;
+			int16 newSeqId = 0;
+			if (diffX == 0) {
+				newSeqId = diffY <= 0 ? 2 : 6;
+			} else {
+				int16 div = diffY / diffX;
+				if (div == 0) {
+					newSeqId = diffX < 1 ? 4 : 0;
+				} else if (div <= 0) {
+					newSeqId = diffX <= 0 ? 5 : 1;
+				} else {
+					newSeqId = diffX <= 0 ? 3 : 7;
+				}
+			}
+			_sequenceID2 = newSeqId;
+			if (isFlag0x10Set) {
+				pathfindingCleanup();
+			}
 		}
 
 


Commit: 7a596728de0cf1d01de58c468bd688ff457fdcd6
    https://github.com/scummvm/scummvm/commit/7a596728de0cf1d01de58c468bd688ff457fdcd6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on tilemap overlays

Changed paths:
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 3421b8c067..3e245d1766 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -113,46 +113,47 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
-		if (ini->sceneId == sceneId && (ini->field_1a_flags_maybe & 1)) {
-			Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
-
-			if (actor) {
-				ini->actor = actor;
-				if (ini->sequenceId & 0x1000) {
-					actor->frame_flags |= 0x10;
-				} else {
-					if (ini->field_1a_flags_maybe & 0x2000) {
-						actor->frame_flags |= 0x20;
+		if (ini->sceneId == sceneId) {
+			if (ini->field_1a_flags_maybe & 1) {
+				Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
+
+				if (actor) {
+					ini->actor = actor;
+					if (ini->sequenceId & 0x1000) {
+						actor->frame_flags |= 0x10;
 					} else {
-						actor->frame_flags &= 0xffef;
+						if (ini->field_1a_flags_maybe & 0x2000) {
+							actor->frame_flags |= 0x20;
+						} else {
+							actor->frame_flags &= 0xffef;
+						}
 					}
-				}
 
-				actor->_sequenceID2 = ini->field_20_actor_field_14;
+					actor->_sequenceID2 = ini->field_20_actor_field_14;
 
-				if (ini->field_1a_flags_maybe & 2) {
-					actor->flags |= Dragons::ACTOR_FLAG_80;
-				} else {
-					actor->flags &= 0xfeff;
-				}
+					if (ini->field_1a_flags_maybe & 2) {
+						actor->flags |= Dragons::ACTOR_FLAG_80;
+					} else {
+						actor->flags &= 0xfeff;
+					}
 
-				if (ini->field_1a_flags_maybe & 0x20) {
-					actor->flags |= Dragons::ACTOR_FLAG_100;
-				} else {
-					actor->flags &= 0xfeff;
-				}
+					if (ini->field_1a_flags_maybe & 0x20) {
+						actor->flags |= Dragons::ACTOR_FLAG_100;
+					} else {
+						actor->flags &= 0xfeff;
+					}
 
-				if (ini->field_1a_flags_maybe & 4) {
-					actor->flags |= Dragons::ACTOR_FLAG_8000;
-				} else {
-					actor->flags &= 0x7fff;
-				}
+					if (ini->field_1a_flags_maybe & 4) {
+						actor->flags |= Dragons::ACTOR_FLAG_8000;
+					} else {
+						actor->flags &= 0x7fff;
+					}
 
-				if (ini->field_1a_flags_maybe & 0x100) {
-					actor->flags |= Dragons::ACTOR_FLAG_4000;
-				} else {
-					actor->flags &= 0xbfff;
-				}
+					if (ini->field_1a_flags_maybe & 0x100) {
+						actor->flags |= Dragons::ACTOR_FLAG_4000;
+					} else {
+						actor->flags &= 0xbfff;
+					}
 //
 //				Graphics::Surface *s = actor->getCurrentFrame();
 //				int x = ini->x - actor->frame_vram_x;
@@ -161,9 +162,14 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 //					debug("Actor %d, %d %d (%d, %d)", actor->_actorID, ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
 //					_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
 //				}
+				}
+				// _stage->getFgLayer()->drawLine(ini->x, ini->y, ini->x + 8, ini->y + 8, 0x7c00);
+				//break;
+			} else {
+				if (ini->iptIndex_maybe != -1) {
+					error("ipt_img_file_related_2()");
+				}
 			}
-			// _stage->getFgLayer()->drawLine(ini->x, ini->y, ini->x + 8, ini->y + 8, 0x7c00);
-			//break;
 		}
 		_currentSceneId = (uint16)(sceneId & 0x7fff);
 	}
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index b49ffbf25e..39805be78b 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -603,7 +603,7 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 				}
 			} else {
 				// TODO ipt_img_file_related_2(s1);
-				//error("TODO ipt_img_file_related_2(s1);");
+				error("TODO ipt_img_file_related_2(s1);");
 			}
 		}
 	}


Commit: 69ec3ed7c8cf235067422a6d8c87924347bd2b62
    https://github.com/scummvm/scummvm/commit/69ec3ed7c8cf235067422a6d8c87924347bd2b62
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: image overlays

Changed paths:
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/dragonimg.cpp
    engines/dragons/dragonimg.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 46acc39e15..cac7705a7c 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -30,13 +30,6 @@ namespace Dragons {
 #define TILE_HEIGHT 8
 #define TILE_SIZE (TILE_WIDTH * TILE_HEIGHT * 2)
 
-struct TileMap {
-	uint16 w;
-	uint16 h;
-	uint32 size;
-	byte *map;
-	uint8 tileIndexOffset;
-};
 
 void Dragons::PriorityLayer::load(TileMap &tileMap, byte *tiles) {
 	_width = tileMap.w * TILE_WIDTH;
@@ -61,7 +54,22 @@ int16 PriorityLayer::getPriority(Common::Point pos) {
 
 }
 
-bool Background::load(byte *dataStart, Common::SeekableReadStream &stream) {
+Background::Background() : _priorityLayer(0), _points1(0), _points2(0), _data(0) {
+	_layer[0] = NULL;
+	_layer[1] = NULL;
+	_layer[2] = NULL;
+}
+
+Background::~Background() {
+	if(_data) {
+		delete _data;
+	}
+}
+
+bool Background::load(byte *dataStart, uint32 size) {
+	Common::MemoryReadStream stream(dataStart, size, DisposeAfterUse::NO);
+	_data = dataStart;
+
 	stream.read(_palette, 512);
 	_palette[0] = 0x80; //FIXME update palette
 	_palette[1] = 0x80;
@@ -73,36 +81,41 @@ bool Background::load(byte *dataStart, Common::SeekableReadStream &stream) {
 	stream.seek(0x308);
 
 	uint32 tilemapOffset = 0x324;
-	TileMap tileMap[4];
 	for(int i=0;i< 3;i++) {
-		tileMap[i].w = stream.readUint16LE();
-		tileMap[i].h = stream.readUint16LE();
-		tileMap[i].size = stream.readUint32LE();
-		tileMap[i].map = dataStart + tilemapOffset;
-		tileMap[i].tileIndexOffset = tileindexOffset;
-		debug("Tilemap (%d,%d) map: %X", tileMap[i].w, tileMap[i].h, tilemapOffset);
-
-		tilemapOffset += tileMap[i].size;
+		_tileMap[i].w = stream.readUint16LE();
+		_tileMap[i].h = stream.readUint16LE();
+		_tileMap[i].size = stream.readUint32LE();
+		_tileMap[i].map = dataStart + tilemapOffset;
+		_tileMap[i].tileIndexOffset = tileindexOffset;
+		debug("Tilemap (%d,%d) map: %X", _tileMap[i].w, _tileMap[i].h, tilemapOffset);
+
+		tilemapOffset += _tileMap[i].size;
 	}
 
 	uint32 finalSize = stream.readUint32LE();
 
-	tileMap[3].w = tileMap[0].w;
-	tileMap[3].h = tileMap[0].h;
-	tileMap[3].size = tileMap[0].size;
-	tileMap[3].map = dataStart + tilemapOffset;
-	tileMap[3].tileIndexOffset = tileindexOffset;
+	TileMap priorityTilemap;
+
+	priorityTilemap.w = _tileMap[0].w;
+	priorityTilemap.h = _tileMap[0].h;
+	priorityTilemap.size = _tileMap[0].size;
+	priorityTilemap.map = dataStart + tilemapOffset;
+	priorityTilemap.tileIndexOffset = tileindexOffset;
 
 	uint32 tilesOffset = tilemapOffset + finalSize;
 
+	_tileDataOffset = _data + tilesOffset;
+
 	_priorityLayer = new PriorityLayer();
-	_priorityLayer->load(tileMap[3], dataStart + tilesOffset);
+	_priorityLayer->load(priorityTilemap, _tileDataOffset);
 
 	debug("Tiles: %X", tilesOffset);
-	debug("tileIndexOffset: %d", tileMap[0].tileIndexOffset);
-	_bgLayer = loadGfxLayer(tileMap[0], dataStart + tilesOffset);
-	_mgLayer = loadGfxLayer(tileMap[1], dataStart + tilesOffset);
-	_fgLayer = loadGfxLayer(tileMap[2], dataStart + tilesOffset);
+	debug("tileIndexOffset: %d", _tileMap[0].tileIndexOffset);
+
+	for(int i = 0; i < 3; i++) {
+		_layer[i] = loadGfxLayer(_tileMap[i], _tileDataOffset);
+	}
+
 	return false;
 }
 
@@ -151,23 +164,36 @@ Common::Point Background::getPoint2(uint32 pointIndex) {
 }
 
 uint16 Background::getWidth() {
-	assert (_bgLayer);
-	return _bgLayer->w;
+	assert (_layer[0]);
+	return _layer[0]->w;
 }
 
 uint16 Background::getHeight() {
-	assert (_bgLayer);
-	return _bgLayer->h;
+	assert (_layer[0]);
+	return _layer[0]->h;
 }
 
 int16 Background::getPriorityAtPoint(Common::Point pos) {
-	if (pos.x < 0 || pos.x >= _bgLayer->w || pos.y < 0 || pos.y >= _bgLayer->h) {
+	if (pos.x < 0 || pos.x >= getWidth() || pos.y < 0 || pos.y >= getHeight()) {
 		return -1;
 	}
 	int16 priority = _priorityLayer->getPriority(pos);
 	return priority < 0x11 ? priority : 0;
 }
 
+void Background::overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h) {
+	for(int i = 0; i < h; i++ ) {
+		for(int j = 0; j < w; j++ ) {
+			int16 idx = READ_LE_UINT16(data) + _tileMap[layerNum].tileIndexOffset;
+			drawTileToSurface(_layer[layerNum],
+					_tileDataOffset + idx * 0x100,
+					(j + x) * TILE_WIDTH,
+					(i + y) * TILE_HEIGHT);
+			data += 2;
+		}
+	}
+}
+
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
 		bigFileArchive), _dragonRMS(dragonRMS) {}
 
@@ -177,9 +203,8 @@ Background *BackgroundResourceLoader::load(uint32 sceneId) {
 	debug("Loading %s", filename);
 	uint32 size;
 	byte *scrData = _bigFileArchive->load(filename, size);
-	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(scrData, size, DisposeAfterUse::YES);
 	Background *bg = new Background();
-	bg->load(scrData, *readStream);
+	bg->load(scrData, size);
 	return bg;
 }
 
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 40aa00b398..02bec65416 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -31,8 +31,6 @@ namespace Dragons {
 class PriorityLayer;
 class Background;
 
-struct TileMap;
-
 class BackgroundResourceLoader {
 private:
 	BigfileArchive *_bigFileArchive;
@@ -42,27 +40,40 @@ public:
 	Background *load(uint32 sceneId);
 };
 
+struct TileMap {
+	uint16 w;
+	uint16 h;
+	uint32 size;
+	byte *map;
+	uint8 tileIndexOffset;
+};
+
 class Background {
 private:
+	byte *_data;
+	byte *_tileDataOffset;
+	TileMap _tileMap[4];
 	PriorityLayer *_priorityLayer;
 	byte _palette[512];
-	Graphics::Surface *_bgLayer;
-	Graphics::Surface *_mgLayer;
-	Graphics::Surface *_fgLayer;
+	Graphics::Surface *_layer[3];
 	Common::Point *_points1;
 	Common::Point *_points2;
 public:
-	Background() : _priorityLayer(0), _points1(0), _points2(0), _bgLayer(0), _fgLayer(0) {}
-	bool load(byte *dataStart, Common::SeekableReadStream &stream);
+	Background();
+	~Background();
+
+	bool load(byte *dataStart, uint32 size);
 	uint16 getWidth();
 	uint16 getHeight();
-	Graphics::Surface *getBgLayer() { return _bgLayer; }
-	Graphics::Surface *getMgLayer() { return _mgLayer; }
-	Graphics::Surface *getFgLayer() { return _fgLayer; }
+	Graphics::Surface *getBgLayer() { return _layer[0]; }
+	Graphics::Surface *getMgLayer() { return _layer[1]; }
+	Graphics::Surface *getFgLayer() { return _layer[2]; }
 	int16 getPriorityAtPoint(Common::Point pos);
 	Common::Point getPoint2(uint32 pointIndex);
 	byte *getPalette() { return _palette; }
 
+	void overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h);
+
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
 	Graphics::Surface *loadGfxLayer(TileMap &tileMap, byte *tiles);
diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
index ec53e3c434..a70ccb3e0e 100644
--- a/engines/dragons/dragonimg.cpp
+++ b/engines/dragons/dragonimg.cpp
@@ -32,8 +32,8 @@ DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
 
 	_count = fileSize / 4;
 
-	byte *imgData = bigfileArchive->load("dragon.img", fileSize);
-	Common::SeekableReadStream *imgReadStream = new Common::MemoryReadStream(imgData, fileSize, DisposeAfterUse::YES);
+	_imgData = bigfileArchive->load("dragon.img", fileSize);
+	Common::SeekableReadStream *imgReadStream = new Common::MemoryReadStream(_imgData, fileSize, DisposeAfterUse::NO);
 
 
 	_imgObjects = new IMG[_count];
@@ -48,7 +48,15 @@ DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
 		_imgObjects[i].field_a = imgReadStream->readUint16LE();
 		_imgObjects[i].field_c = imgReadStream->readUint16LE();
 		_imgObjects[i].field_e = imgReadStream->readUint16LE();
+		_imgObjects[i].data = _imgData + imgReadStream->pos();
 	}
+
+	delete iptReadStream;
+	delete imgReadStream;
+}
+
+DragonIMG::~DragonIMG() {
+	delete _imgData;
 }
 
 IMG *DragonIMG::getIMG(uint32 iptId) {
@@ -58,5 +66,4 @@ IMG *DragonIMG::getIMG(uint32 iptId) {
 	return &_imgObjects[iptId];
 }
 
-
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonimg.h b/engines/dragons/dragonimg.h
index 6d9109e150..848bdaece7 100644
--- a/engines/dragons/dragonimg.h
+++ b/engines/dragons/dragonimg.h
@@ -35,6 +35,7 @@ struct IMG {
 	uint16 field_a;
 	uint16 field_c;
 	uint16 field_e;
+	byte *data;
 };
 
 class BigfileArchive;
@@ -43,8 +44,10 @@ class DragonIMG {
 private:
 	int16 _count;
 	IMG *_imgObjects;
+	byte *_imgData;
 public:
 	DragonIMG(BigfileArchive *bigfileArchive);
+	~DragonIMG();
 	IMG *getIMG(uint32 iptId);
 };
 
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 3e245d1766..f62d388fec 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -24,6 +24,7 @@
 #include "actor.h"
 #include "background.h"
 #include "dragonini.h"
+#include "dragonimg.h"
 #include "screen.h"
 #include "actorresource.h"
 #include "scriptopcodes.h"
@@ -167,7 +168,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 				//break;
 			} else {
 				if (ini->iptIndex_maybe != -1) {
-					error("ipt_img_file_related_2()");
+					loadImageOverlay(ini->iptIndex_maybe);
 				}
 			}
 		}
@@ -259,4 +260,9 @@ uint16 Scene::getStageHeight() {
 	return _stage->getHeight();
 }
 
+void Scene::loadImageOverlay(uint16 iptId) {
+	IMG *img =_vm->_dragonIMG->getIMG(iptId);
+	_stage->overlayImage(2, img->data, img->field_0, img->field_2, img->field_4, img->field_6);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index cd8cd2294a..1f6c527d6f 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -66,6 +66,7 @@ public:
 	Common::Point getPoint(uint32 pointIndex);
 	uint16 getStageWidth();
 	uint16 getStageHeight();
+	void loadImageOverlay(uint16 iptId);
 private:
 	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 39805be78b..a42210ffa4 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -599,11 +599,12 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 			if (s1 == -1) {
 				if (ini->iptIndex_maybe != -1) {
 					// TODO ipt_img_file_related_3(ini->iptIndex_maybe);
-					//error("TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
+					error("TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
 				}
 			} else {
 				// TODO ipt_img_file_related_2(s1);
-				error("TODO ipt_img_file_related_2(s1);");
+				_vm->_scene->loadImageOverlay(s1);
+				//error("TODO ipt_img_file_related_2(s1);");
 			}
 		}
 	}
@@ -726,8 +727,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 				error("//TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
 			}
 			if (sceneId == currentScene && ini->iptIndex_maybe != -1) {
-				// TODO ipt_img_file_related_2(ini->iptIndex_maybe);
-				error("// TODO ipt_img_file_related_2(ini->iptIndex_maybe);");
+				_vm->_scene->loadImageOverlay(ini->iptIndex_maybe);
 			}
 		}
 


Commit: ed56d587d5ba9a17a353d8fbadbefbc10c2bb558
    https://github.com/scummvm/scummvm/commit/ed56d587d5ba9a17a353d8fbadbefbc10c2bb558
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Show / Hide tile overlays. Work on inventory bag display

Changed paths:
  A engines/dragons/inventory.cpp
  A engines/dragons/inventory.h
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/dragonimg.cpp
    engines/dragons/dragonimg.h
    engines/dragons/dragonrms.cpp
    engines/dragons/dragonrms.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index cac7705a7c..8c09dc9e0b 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -194,8 +194,20 @@ void Background::overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int
 	}
 }
 
+void Background::restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h) {
+	int16 tmw = x + w;
+	int16 tmh = y + h;
+	for(int y = 0; y < tmh; y++) {
+		for(int x = 0; x < tmw; x++) {
+			uint16 idx = READ_LE_UINT16(&_tileMap[layerNum].map[(y * _tileMap[layerNum].w + x) * 2]) + _tileMap[layerNum].tileIndexOffset;
+			//debug("tileIdx: %d", idx);
+			drawTileToSurface(_layer[layerNum], _tileDataOffset + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
+		}
+	}
+}
+
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
-		bigFileArchive), _dragonRMS(dragonRMS) {}
+	bigFileArchive), _dragonRMS(dragonRMS) {}
 
 Background *BackgroundResourceLoader::load(uint32 sceneId) {
 	char filename[] = "nnnn.scr";
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 02bec65416..f34aa07caf 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -73,6 +73,7 @@ public:
 	byte *getPalette() { return _palette; }
 
 	void overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h);
+	void restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h);
 
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
index a70ccb3e0e..0504e8454a 100644
--- a/engines/dragons/dragonimg.cpp
+++ b/engines/dragons/dragonimg.cpp
@@ -40,11 +40,11 @@ DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
 
 	for(int i=0; i < _count; i++) {
 		imgReadStream->seek(iptReadStream->readUint32LE());
-		_imgObjects[i].field_0 = imgReadStream->readUint16LE();
-		_imgObjects[i].field_2 = imgReadStream->readUint16LE();
-		_imgObjects[i].field_4 = imgReadStream->readUint16LE();
-		_imgObjects[i].field_6 = imgReadStream->readUint16LE();
-		_imgObjects[i].field_8 = imgReadStream->readUint16LE();
+		_imgObjects[i].x = imgReadStream->readUint16LE();
+		_imgObjects[i].y = imgReadStream->readUint16LE();
+		_imgObjects[i].w = imgReadStream->readUint16LE();
+		_imgObjects[i].h = imgReadStream->readUint16LE();
+		_imgObjects[i].layerNum = imgReadStream->readUint16LE();
 		_imgObjects[i].field_a = imgReadStream->readUint16LE();
 		_imgObjects[i].field_c = imgReadStream->readUint16LE();
 		_imgObjects[i].field_e = imgReadStream->readUint16LE();
diff --git a/engines/dragons/dragonimg.h b/engines/dragons/dragonimg.h
index 848bdaece7..0ad7420f18 100644
--- a/engines/dragons/dragonimg.h
+++ b/engines/dragons/dragonimg.h
@@ -27,11 +27,11 @@
 namespace Dragons {
 
 struct IMG {
-	uint16 field_0;
-	uint16 field_2;
-	uint16 field_4;
-	uint16 field_6;
-	uint16 field_8;
+	uint16 x;
+	uint16 y;
+	uint16 w;
+	uint16 h;
+	uint16 layerNum;
 	uint16 field_a;
 	uint16 field_c;
 	uint16 field_e;
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
index 039dc58471..f095935e9e 100644
--- a/engines/dragons/dragonrms.cpp
+++ b/engines/dragons/dragonrms.cpp
@@ -60,10 +60,15 @@ byte *DragonRMS::getObdData(uint32 sceneId) {
 byte *DragonRMS::getObdDataField10(uint32 sceneId) {
 	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_field10ObdOffset);
 }
+
 byte *DragonRMS::getObdDataFieldC(uint32 sceneId) {
 	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_fieldC);
 }
 
+int16 DragonRMS::getInventoryPosition(uint32 sceneId) {
+	return getRMS(sceneId)->_inventoryBagPosition;
+}
+
 RMS *DragonRMS::getRMS(uint32 sceneId) {
 	sceneId &= 0x7fff;
 	assert(sceneId > 1);
@@ -71,5 +76,4 @@ RMS *DragonRMS::getRMS(uint32 sceneId) {
 	return &_rmsObjects[sceneId - 2];
 }
 
-
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonrms.h b/engines/dragons/dragonrms.h
index 8af329e3c9..d22be5a53f 100644
--- a/engines/dragons/dragonrms.h
+++ b/engines/dragons/dragonrms.h
@@ -51,6 +51,7 @@ public:
 	byte *getObdData(uint32 sceneId);
 	byte *getObdDataField10(uint32 sceneId);
 	byte *getObdDataFieldC(uint32 sceneId);
+	int16 getInventoryPosition(uint32 sceneId);
 
 private:
 	RMS *getRMS(uint32 sceneId);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index ff799d974a..6017c8c22f 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -34,6 +34,7 @@
 #include "dragonrms.h"
 #include "dragonvar.h"
 #include "dragons.h"
+#include "inventory.h"
 #include "scene.h"
 #include "screen.h"
 #include "sequenceopcodes.h"
@@ -63,6 +64,9 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_cursorPosition = Common::Point();
 	_cursorSequenceID = 0;
 	run_func_ptr_unk_countdown_timer = 0;
+	data_8006a3a0_flag = 0;
+	data_800633fa = 0;
+	_inventory = new Inventory(this);
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -115,17 +119,7 @@ Common::Error DragonsEngine::run() {
 	_dragonINIResource->getFlickerRecord()->actor = cursor; //TODO is this correct?
 	_dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
 
-	Actor *inventory = _actorManager->loadActor(1, 1); //Load inventory
-	inventory->x_pos = 2;
-	inventory->y_pos = 0;
-	inventory->priorityLayer = 6;
-	inventory->flags = 0;
-	inventory->field_e = 0x100;
-	inventory->updateSequence(0);
-	inventory->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
-						 Dragons::ACTOR_FLAG_200);
-	inventorySequenceId = 0;
-	inventoryIsShowingMaybe = 0;
+	_inventory->init(_actorManager);
 
 	uint16 sceneId = 0x12;
 	_dragonINIResource->getFlickerRecord()->sceneId = sceneId; //TODO
@@ -201,6 +195,7 @@ void DragonsEngine::gameLoop() {
 }
 
 void DragonsEngine::updateHandler() {
+	data_8006a3a0_flag |= 0x40;
 	//TODO logic here
 
 	updateActorSequences();
@@ -264,6 +259,8 @@ void DragonsEngine::updateHandler() {
 	//TODO vsync update function
 
 	// TODO data_8006a3a0 logic. @ 0x8001c2f4
+
+	data_8006a3a0_flag &= ~0x40;
 }
 
 const char *DragonsEngine::getSavegameFilename(int num) {
@@ -388,6 +385,10 @@ bool DragonsEngine::isFlagSet(uint32 flag) {
 	return (bool) (_flags & flag);
 }
 
+bool DragonsEngine::isUnkFlagSet(uint32 flag) {
+	return (bool) (_unkFlags1 & flag);
+}
+
 DragonINI *DragonsEngine::getINI(uint32 index) {
 	return _dragonINIResource->getRecord(index);
 }
@@ -416,10 +417,10 @@ uint16 DragonsEngine::getIniFromImg() {
 		DragonINI *ini = getINI(i);
 		if (ini->sceneId == currentSceneId && ini->field_1a_flags_maybe == 0) {
 			IMG *img = _dragonIMG->getIMG(ini->field_2);
-			if (x >= img->field_0 &&
-				img->field_0 + img->field_4 >= x &&
-				y >= img->field_2 &&
-				img->field_6 + img->field_2 >= y) {
+			if (x >= img->x &&
+				img->x + img->w >= x &&
+				y >= img->y &&
+				img->h + img->y >= y) {
 				return i + 1;
 			}
 		}
@@ -434,7 +435,7 @@ uint16 DragonsEngine::updateINIUnderCursor() {
 
 	if (_flags & Dragons::ENGINE_FLAG_10) {
 
-		if (inventorySequenceId == 0 || inventorySequenceId == 2) {
+		if (_inventory->getSequenceId() == 0 || _inventory->getSequenceId() == 2) {
 //TODO
 		} else {
 
@@ -469,7 +470,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 		//TODO
 		uint16 currentSceneId = _scene->getSceneId();
 
-		if (inventoryIsShowingMaybe == 0) {
+		if (!_inventory->isVisible()) {
 			for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 				DragonINI *ini = getINI(i);
 				if (ini->field_10 >= 0 && ini->sceneId == currentSceneId) {
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index edbb6b2711..373c8fbc2a 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -62,9 +62,13 @@ enum Flags {
 	ENGINE_FLAG_20 = 0x20,
 	ENGINE_FLAG_40 = 0x40,
 	ENGINE_FLAG_80 = 0x80,
+	ENGINE_FLAG_100 = 0x100,
+	ENGINE_FLAG_200 = 0x200,
 
+	ENGINE_FLAG_10000    =    0x10000,
 	ENGINE_FLAG_80000    =    0x80000,
 	ENGINE_FLAG_100000   =   0x100000,
+	ENGINE_FLAG_400000   =   0x400000,
 	ENGINE_FLAG_4000000  =  0x4000000,
 	ENGINE_FLAG_80000000 = 0x80000000
 };
@@ -88,6 +92,7 @@ class DragonOBD;
 class DragonRMS;
 class DragonVAR;
 class DragonINIResource;
+class Inventory;
 class Scene;
 class Screen;
 class ActorManager;
@@ -99,15 +104,17 @@ class DragonsEngine : public Engine {
 public:
 	DragonOBD *_dragonOBD;
 	DragonIMG *_dragonIMG;
+	DragonRMS *_dragonRMS;
 	ActorManager *_actorManager;
 	DragonINIResource *_dragonINIResource;
 	uint16 _cursorSequenceID;
 	Scene *_scene;
+	uint16 data_800633fa;
+	Inventory *_inventory;
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
 	DragonFLG *_dragonFLG;
-	DragonRMS *_dragonRMS;
 	DragonVAR *_dragonVAR;
 	BackgroundResourceLoader *_backgroundResourceLoader;
 	SequenceOpcodes *_sequenceOpcodes;
@@ -119,10 +126,9 @@ private:
 	uint16 _sceneId1;
 	uint32 _counter;
 	uint32 bit_flags_8006fbd8;
-
+	uint16 data_8006a3a0_flag; // screen related flags?
 	//unk
-	uint32 inventorySequenceId;
-	uint16 inventoryIsShowingMaybe;
+
 	uint16 run_func_ptr_unk_countdown_timer;
 
 public:
@@ -140,6 +146,7 @@ public:
 	void setFlags(uint32 flags);
 	void clearFlags(uint32 flags);
 	bool isFlagSet(uint32 flag);
+	bool isUnkFlagSet(uint32 flag);
 
 	void setUnkFlags(uint32 flags);
 	void clearUnkFlags(uint32 flags);
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
new file mode 100644
index 0000000000..f4a1912cf3
--- /dev/null
+++ b/engines/dragons/inventory.cpp
@@ -0,0 +1,77 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "actor.h"
+#include "dragons.h"
+#include "dragonrms.h"
+#include "inventory.h"
+
+namespace Dragons {
+
+static const Common::Point positionTable[4] = {
+		{2,0},
+		{0xce,0},
+		{2,0x9e},
+		{0xce,0x9e}
+};
+
+Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
+	_isShowingMaybe = false;
+	_sequenceId = 0;
+	_screenPositionIndex = 0;
+}
+
+void Inventory::init(ActorManager *actorManager) {
+	_actor = actorManager->loadActor(1, 1); //Load inventory
+	_actor->x_pos = 2;
+	_actor->y_pos = 0;
+	_actor->priorityLayer = 6;
+	_actor->flags = 0;
+	_actor->field_e = 0x100;
+	_actor->updateSequence(0);
+	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
+						 Dragons::ACTOR_FLAG_200);
+	_sequenceId = 0;
+	_isShowingMaybe = false;
+}
+
+
+void Inventory::loadScene(uint32 sceneId) {
+	if (!_isShowingMaybe) {
+		_sequenceId = _vm->isFlagSet(Dragons::ENGINE_FLAG_400000) ? 1 : 0;
+	}
+	_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(sceneId);
+
+	if (_sequenceId == 0 && _vm->getVar(7) == 1) {
+		_actor->updateSequence(5);
+	} else {
+		_actor->updateSequence(_sequenceId);
+	}
+
+	_actor->x_pos = positionTable[_screenPositionIndex].x;
+	if ((_sequenceId == 0 || _sequenceId == 2) && (_screenPositionIndex == 1 || _screenPositionIndex == 3)) {
+		_actor->x_pos += 0x32;
+	}
+	_actor->y_pos = positionTable[_screenPositionIndex].y;
+}
+
+} // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
new file mode 100644
index 0000000000..0b242c01ee
--- /dev/null
+++ b/engines/dragons/inventory.h
@@ -0,0 +1,61 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SCUMMVM_INVENTORY_H
+#define SCUMMVM_INVENTORY_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class Actor;
+class ActorManager;
+
+class Inventory {
+private:
+	DragonsEngine *_vm;
+	int32 _sequenceId;
+	bool _isShowingMaybe;
+	int16 _screenPositionIndex;
+	Actor *_actor;
+
+public:
+	Inventory(DragonsEngine *vm);
+
+	void init(ActorManager *actorManager);
+	void loadScene(uint32 sceneId);
+
+	int32 getSequenceId() {
+		return _sequenceId;
+	}
+
+	bool isVisible() {
+		return _isShowingMaybe;
+	}
+
+	void hide() { _isShowingMaybe = false; }
+	void show() { _isShowingMaybe = true; }
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_INVENTORY_H
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index f62d388fec..05c9bdeabc 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -25,6 +25,7 @@
 #include "background.h"
 #include "dragonini.h"
 #include "dragonimg.h"
+#include "inventory.h"
 #include "screen.h"
 #include "actorresource.h"
 #include "scriptopcodes.h"
@@ -58,6 +59,8 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 }
 
 void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
+	bool isUnkFlag2Set = _vm->isUnkFlagSet(Dragons::ENGINE_UNK1_FLAG_2);
+
 	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_2 | Dragons::ENGINE_UNK1_FLAG_8);
 
 	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
@@ -112,6 +115,15 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	debug("Camera: (%d, %d)", _camera.x, _camera.y);
 
+	// 0x8002ff80
+	// TODO fade_related_calls_with_1f();
+	_vm->clearUnkFlags(Dragons::ENGINE_UNK1_FLAG_10);
+	_vm->setFlags(Dragons::ENGINE_FLAG_20);
+	// TODO reset vsync_updater_function
+	_vm->setFlags(Dragons::ENGINE_FLAG_200);
+	_actorManager->clearActorFlags(2);
+	// TODO 0x8002fff0
+
 	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		if (ini->sceneId == sceneId) {
@@ -172,7 +184,54 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 				}
 			}
 		}
-		_currentSceneId = (uint16)(sceneId & 0x7fff);
+	}
+	_currentSceneId = (uint16)(sceneId & 0x7fff); //TODO is this the right spot for this?
+
+	// 0x80030458
+	DragonINI *ini = _vm->getINI(1);
+	if (ini->actor && _vm->_dragonINIResource->getFlickerRecord() && _vm->_dragonINIResource->getFlickerRecord()->sceneId == _currentSceneId) {
+		ini->actor->setFlag(Dragons::ACTOR_FLAG_100);
+		ini->actor->priorityLayer = 0;
+	}
+
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+
+	if (flicker && flicker->sceneId != 0) {
+		flicker->field_20_actor_field_14 = _vm->data_800633fa;
+		if (flicker->actor) {
+			flicker->actor->_sequenceID2 = _vm->data_800633fa;
+			flicker->actor->setFlag(Dragons::ACTOR_FLAG_4);
+		}
+	}
+
+	// 0x800305bc
+	_vm->_inventory->loadScene(_currentSceneId);
+
+	// 0x8003070c
+	// TODO sub_80013b3c(); // palette related.
+
+	if (_vm->_inventory->isVisible()) {
+		_vm->_inventory->hide();
+	}
+
+	if (!_vm->isFlagSet(Dragons::ENGINE_FLAG_10000)) {
+		_vm->setFlags(Dragons::ENGINE_FLAG_10);
+	}
+
+	_vm->setFlags(Dragons::ENGINE_FLAG_1);
+	_vm->setFlags(Dragons::ENGINE_FLAG_200);
+	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
+
+	if (flicker && flicker->sceneId == _currentSceneId) {
+
+		flicker->actor->updateSequence((uint16)flicker->actor->_sequenceID2);
+	}
+
+	_vm->clearUnkFlags(Dragons::ENGINE_UNK1_FLAG_2);
+	_vm->clearUnkFlags(Dragons::ENGINE_UNK1_FLAG_8);
+
+	if (isUnkFlag2Set) {
+		_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_2);
 	}
 
 	if (!(sceneId & 0x8000)) {
@@ -262,7 +321,21 @@ uint16 Scene::getStageHeight() {
 
 void Scene::loadImageOverlay(uint16 iptId) {
 	IMG *img =_vm->_dragonIMG->getIMG(iptId);
-	_stage->overlayImage(2, img->data, img->field_0, img->field_2, img->field_4, img->field_6);
+	if (img->h != 0) {
+		if (img->field_e <= 2) {
+			_stage->overlayImage(img->layerNum - 1, img->data, img->x, img->y, img->w, img->h);
+		}
+
+		if (img->field_e == 2 || img->field_e == 0) {
+			// error("img->field_e == 2 || img->field_e == 0");
+			//TODO what does this do? Do we need it? 0x800177f8
+		}
+	}
+}
+
+void Scene::removeImageOverlay(uint16 iptId) {
+	IMG *img =_vm->_dragonIMG->getIMG(iptId);
+	_stage->restoreTiles(img->layerNum - 1, img->x, img->y, img->w, img->h);
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 1f6c527d6f..42bb82e32d 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -67,6 +67,7 @@ public:
 	uint16 getStageWidth();
 	uint16 getStageHeight();
 	void loadImageOverlay(uint16 iptId);
+	void removeImageOverlay(uint16 iptId);
 private:
 	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index a42210ffa4..bd9f27a103 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -102,8 +102,9 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0xF, opUnkF);
 
 	OPCODE(0x11, opUnk11FlickerTalk);
-
+	OPCODE(0x12, opUnk12LoadScene);
 	OPCODE(0x13, opUnk13PropertiesRelated);
+
 	OPCODE(0x1F, opPlayMusic);
 
 	OPCODE(0x22, opCodeActorTalk);
@@ -519,6 +520,29 @@ void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 	// TODO implement me!
 }
 
+void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	//TODO fade_related_calls_with_1f();
+	// func_ptr_unk = 0;
+	// PauseCDMusic();
+
+	if (field2 != 0) {
+		// load scene here.
+		//TODO
+		error("0x8002efe4");
+	} else {
+		_vm->setFlags(Dragons::ENGINE_FLAG_100000);
+	}
+}
+
 void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(field2);
@@ -598,13 +622,10 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 		if (fieldA & 4 && field2 == 0 && !(ini->field_1a_flags_maybe & 1) && ini->sceneId == _vm->getCurrentSceneId()) {
 			if (s1 == -1) {
 				if (ini->iptIndex_maybe != -1) {
-					// TODO ipt_img_file_related_3(ini->iptIndex_maybe);
-					error("TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
+					_vm->_scene->removeImageOverlay(ini->iptIndex_maybe);
 				}
 			} else {
-				// TODO ipt_img_file_related_2(s1);
 				_vm->_scene->loadImageOverlay(s1);
-				//error("TODO ipt_img_file_related_2(s1);");
 			}
 		}
 	}
@@ -723,8 +744,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 			}
 		} else {
 			if (ini->sceneId == currentScene && ini->iptIndex_maybe != -1) {
-				//TODO ipt_img_file_related_3(ini->iptIndex_maybe);
-				error("//TODO ipt_img_file_related_3(ini->iptIndex_maybe);");
+				_vm->_scene->removeImageOverlay(ini->iptIndex_maybe);
 			}
 			if (sceneId == currentScene && ini->iptIndex_maybe != -1) {
 				_vm->_scene->loadImageOverlay(ini->iptIndex_maybe);
@@ -733,10 +753,12 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 
 		if (ini->sceneId == 1) {
 			//TODO 0x8002d218
+			error("0x8002d218");
 		}
 
 		if (sceneId == 1) {
 			// TODO 0x8002d2f4
+			error("0x8002d2f4");
 		}
 	}
 	ini->sceneId = sceneId;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 0f0d0f1337..3c22f74c71 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -93,7 +93,7 @@ protected:
 	void opUnkF(ScriptOpCall &scriptOpCall);
 
 	void opUnk11FlickerTalk(ScriptOpCall &scriptOpCall);
-
+	void opUnk12LoadScene(ScriptOpCall &scriptOpCall);
 	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opUnk14(ScriptOpCall &scriptOpCall);
 	void opUnk15(ScriptOpCall &scriptOpCall);


Commit: 0a2a16c64f15ae5a491388c218b389b9dfb11b4c
    https://github.com/scummvm/scummvm/commit/0a2a16c64f15ae5a491388c218b389b9dfb11b4c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: added inventory to build system

Changed paths:
    engines/dragons/module.mk


diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index d41f15eace..b8f21aacd0 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -13,6 +13,7 @@ MODULE_OBJS := \
     dragonrms.o \
     dragonvar.o \
 	dragons.o \
+	inventory.o \
 	scene.o \
 	screen.o \
 	scriptopcodes.o \


Commit: b98d6f1200d8beb717162e8bc42d04343a6f9f0f
    https://github.com/scummvm/scummvm/commit/b98d6f1200d8beb717162e8bc42d04343a6f9f0f
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on cursors

Changed paths:
  A engines/dragons/cursor.cpp
  A engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
new file mode 100644
index 0000000000..e4526152bc
--- /dev/null
+++ b/engines/dragons/cursor.cpp
@@ -0,0 +1,75 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "cursor.h"
+#include "actor.h"
+#include "dragons.h"
+#include "dragonini.h"
+#include "inventory.h"
+
+namespace Dragons {
+
+Cursor::Cursor(DragonsEngine *vm): _vm(vm), _actor(0), _x(0), _y(0) {
+	_sequenceID = 0;
+}
+
+void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResource) {
+	_sequenceID = 0;
+	_actor = actorManager->loadActor(0, 0); //Load cursor
+	_actor->x_pos = _x = 160;
+	_actor->y_pos = _y = 100;
+	_actor->priorityLayer = 6;
+	_actor->flags = 0;
+	_actor->field_e = 0x100;
+	_actor->updateSequence(_sequenceID);
+	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
+					  Dragons::ACTOR_FLAG_200);
+
+	dragonINIResource->getFlickerRecord()->actor = _actor; //TODO is this correct?
+	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
+}
+
+void Cursor::update() {
+	if (!_vm->isFlagSet(Dragons::ENGINE_FLAG_8) || _vm->isFlagSet(Dragons::ENGINE_FLAG_100)) {
+		return;
+	}
+	// TODO update cursor from inputs here.
+
+	// 0x800280b8
+	if (_sequenceID == 0 && (_vm->_inventory->getType() == 1 || _vm->_inventory->getType() == 2)) {
+		_sequenceID = 1;
+	}
+
+	_actor->x_pos = _x;
+	_actor->y_pos = _y;
+
+	// 0x80028104
+}
+
+void Cursor::updateVisibility() {
+	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_8) && !_vm->isUnkFlagSet(Dragons::ENGINE_UNK1_FLAG_10)) {
+		_actor->priorityLayer = 9;
+	} else {
+		_actor->priorityLayer = 0;
+	}
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
new file mode 100644
index 0000000000..f0ef3c13c2
--- /dev/null
+++ b/engines/dragons/cursor.h
@@ -0,0 +1,51 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef DRAGONS_CURSOR_H
+#define DRAGONS_CURSOR_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class Actor;
+class ActorManager;
+class DragonsEngine;
+class DragonINIResource;
+
+class Cursor {
+private:
+	DragonsEngine *_vm;
+	int16 _x;
+	int16 _y;
+	Actor *_actor;
+	int32 _sequenceID;
+
+public:
+	Cursor(DragonsEngine *vm);
+	void init(ActorManager *actorManager, DragonINIResource *dragonINIResource);
+	void update();
+	void updateVisibility();
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_CURSOR_H
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 6017c8c22f..3a2c05e130 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -27,6 +27,7 @@
 #include "actorresource.h"
 #include "background.h"
 #include "bigfile.h"
+#include "cursor.h"
 #include "dragonflg.h"
 #include "dragonimg.h"
 #include "dragonini.h"
@@ -67,6 +68,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	data_8006a3a0_flag = 0;
 	data_800633fa = 0;
 	_inventory = new Inventory(this);
+	_cursor = new Cursor(this);
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -105,20 +107,7 @@ Common::Error DragonsEngine::run() {
 	_flags &= 0x1c07040;
 	_flags |= 0x26;
 
-	_cursorSequenceID = 0;
-	Actor *cursor = _actorManager->loadActor(0, 0); //Load cursor
-	cursor->x_pos = _cursorPosition.x = 160;
-	cursor->y_pos = _cursorPosition.y = 100;
-	cursor->priorityLayer = 6;
-	cursor->flags = 0;
-	cursor->field_e = 0x100;
-	cursor->updateSequence(_cursorSequenceID);
-	cursor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
-					  Dragons::ACTOR_FLAG_200);
-
-	_dragonINIResource->getFlickerRecord()->actor = cursor; //TODO is this correct?
-	_dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
-
+	_cursor->init(_actorManager, _dragonINIResource);
 	_inventory->init(_actorManager);
 
 	uint16 sceneId = 0x12;
@@ -200,6 +189,9 @@ void DragonsEngine::updateHandler() {
 
 	updateActorSequences();
 
+	_cursor->updateVisibility();
+	_inventory->updateVisibility();
+
 	//TODO logic here
 	for (uint16 i = 0; i < 0x17; i++) {
 		Actor *actor = _actorManager->getActor(i);
@@ -465,7 +457,7 @@ void DragonsEngine::runINIScripts() {
 void DragonsEngine::engineFlag0x20UpdateFunction() {
 	if (_flags & Dragons::ENGINE_FLAG_20) {
 		if ((_flags & (Dragons::ENGINE_FLAG_80000000 | Dragons::ENGINE_FLAG_8)) == 8) {
-			error("updateCursor();"); //TODO updateCursor();
+			_cursor->update();
 		}
 		//TODO
 		uint16 currentSceneId = _scene->getSceneId();
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 373c8fbc2a..96ce0a676b 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -86,6 +86,7 @@ enum UnkFlags {
 
 class BigfileArchive;
 class BackgroundResourceLoader;
+class Cursor;
 class DragonFLG;
 class DragonIMG;
 class DragonOBD;
@@ -111,6 +112,7 @@ public:
 	Scene *_scene;
 	uint16 data_800633fa;
 	Inventory *_inventory;
+	Cursor *_cursor;
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index f4a1912cf3..cbb204c63b 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -35,7 +35,7 @@ static const Common::Point positionTable[4] = {
 };
 
 Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
-	_isShowingMaybe = false;
+	_type = 0;
 	_sequenceId = 0;
 	_screenPositionIndex = 0;
 }
@@ -51,12 +51,12 @@ void Inventory::init(ActorManager *actorManager) {
 	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
 						 Dragons::ACTOR_FLAG_200);
 	_sequenceId = 0;
-	_isShowingMaybe = false;
+	_type = 0;
 }
 
 
 void Inventory::loadScene(uint32 sceneId) {
-	if (!_isShowingMaybe) {
+	if (!_type) {
 		_sequenceId = _vm->isFlagSet(Dragons::ENGINE_FLAG_400000) ? 1 : 0;
 	}
 	_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(sceneId);
@@ -74,4 +74,8 @@ void Inventory::loadScene(uint32 sceneId) {
 	_actor->y_pos = positionTable[_screenPositionIndex].y;
 }
 
+void Inventory::updateVisibility() {
+	_actor->priorityLayer = _vm->isFlagSet(Dragons::ENGINE_FLAG_10) ? (int16)6 : (int16)0;
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 0b242c01ee..6eef7edbd6 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -20,8 +20,8 @@
  *
  */
 
-#ifndef SCUMMVM_INVENTORY_H
-#define SCUMMVM_INVENTORY_H
+#ifndef DRAGONS_INVENTORY_H
+#define DRAGONS_INVENTORY_H
 
 #include "common/system.h"
 
@@ -34,9 +34,9 @@ class Inventory {
 private:
 	DragonsEngine *_vm;
 	int32 _sequenceId;
-	bool _isShowingMaybe;
 	int16 _screenPositionIndex;
 	Actor *_actor;
+	int16 _type;
 
 public:
 	Inventory(DragonsEngine *vm);
@@ -48,14 +48,20 @@ public:
 		return _sequenceId;
 	}
 
+	int16 getType() { return _type; }
+
 	bool isVisible() {
-		return _isShowingMaybe;
+		return _type != 0;
 	}
 
-	void hide() { _isShowingMaybe = false; }
-	void show() { _isShowingMaybe = true; }
+	void hide() { _type = 0; }
+	void show(int16 type) { _type = type; }
+
+	void updateVisibility();
+
+
 };
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_INVENTORY_H
+#endif //DRAGONS_INVENTORY_H


Commit: c1307c375f4762b9e4a11ad4b81c7385b1769cf7
    https://github.com/scummvm/scummvm/commit/c1307c375f4762b9e4a11ad4b81c7385b1769cf7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: moving cursor around

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/scene.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index e4526152bc..70436ce69c 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -72,4 +72,9 @@ void Cursor::updateVisibility() {
 	}
 }
 
+void Cursor::updatePosition(int16 x, int16 y) {
+	_x = x;
+	_y = y;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index f0ef3c13c2..4c29135386 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -44,6 +44,7 @@ public:
 	void init(ActorManager *actorManager, DragonINIResource *dragonINIResource);
 	void update();
 	void updateVisibility();
+	void updatePosition(int16 x, int16 y);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 3a2c05e130..89c3fb1d93 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -84,6 +84,9 @@ void DragonsEngine::updateEvents() {
 			case Common::EVENT_QUIT:
 				quitGame();
 				break;
+			case Common::EVENT_MOUSEMOVE:
+				_cursor->updatePosition(event.mouse.x, event.mouse.y);
+				break;
 			default:
 				break;
 		}
@@ -500,4 +503,18 @@ void DragonsEngine::updatePathfindingActors() {
 	}
 }
 
+void DragonsEngine::fade_related(uint32 flags) {
+	if (!isFlagSet(ENGINE_FLAG_40)) {
+		return;
+	}
+	setUnkFlags(ENGINE_UNK1_FLAG_2);
+	clearFlags(ENGINE_FLAG_40);
+
+	//TODO 0x80015a1c
+}
+
+void DragonsEngine::call_fade_related_1f() {
+	fade_related(0x1f);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 96ce0a676b..ce7ad277ab 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -163,6 +163,10 @@ public:
 
 	void playSound(uint16 soundId);
 
+	//TODO what are these functions really doing?
+	void call_fade_related_1f();
+	void fade_related(uint32 flags);
+
 private:
 	void gameLoop();
 	void updateHandler();
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index b8f21aacd0..a971380a3f 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -5,6 +5,7 @@ MODULE_OBJS := \
     actorresource.o \
     background.o \
     bigfile.o \
+    cursor.o \
 	detection.o \
     dragonflg.o \
     dragonimg.o \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 05c9bdeabc..a5fee252a5 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -85,7 +85,8 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_vm->clearFlags(Dragons::ENGINE_FLAG_20);
 	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_10);
 
-	// TODO 0x8002f7bc call_fade_related_1f()
+	_vm->call_fade_related_1f();
+	// TODO 0x8002f7c4
 
 	_stage = _backgroundLoader->load(sceneId);
 


Commit: 65700ca2a60b0d9ac8693083b0dbce5ead3fd4e2
    https://github.com/scummvm/scummvm/commit/65700ca2a60b0d9ac8693083b0dbce5ead3fd4e2
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on cursor type changes

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 70436ce69c..6d4164e578 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -24,6 +24,7 @@
 #include "dragons.h"
 #include "dragonini.h"
 #include "inventory.h"
+#include "scene.h"
 
 namespace Dragons {
 
@@ -45,6 +46,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 
 	dragonINIResource->getFlickerRecord()->actor = _actor; //TODO is this correct?
 	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
+	_iniUnderCursor = 0;
 }
 
 void Cursor::update() {
@@ -58,8 +60,8 @@ void Cursor::update() {
 		_sequenceID = 1;
 	}
 
-	_actor->x_pos = _x;
-	_actor->y_pos = _y;
+	_actor->x_pos = _x + _vm->_scene->_camera.x;
+	_actor->y_pos = _y + _vm->_scene->_camera.y;
 
 	// 0x80028104
 }
@@ -77,4 +79,37 @@ void Cursor::updatePosition(int16 x, int16 y) {
 	_y = y;
 }
 
+int16 Cursor::updateINIUnderCursor() {
+	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_10)) {
+		int16 xOffset = 0;
+		if (_vm->_inventory->getSequenceId() == 0 || _vm->_inventory->getSequenceId() == 2) {
+			if (_vm->_inventory->getPositionIndex() == 1 || _vm->_inventory->getPositionIndex() == 3) {
+				xOffset = 0x32;
+			}
+		}
+		Common::Point inventoryPosition = _vm->_inventory->getPosition();
+		if (_x >= inventoryPosition.x + 0xa + xOffset
+			&& _x < inventoryPosition.x + 0x35 + xOffset
+			&& _y >= inventoryPosition.y + 0xa
+			&& _y < inventoryPosition.y + 0x25) {
+			_iniUnderCursor = 0x8001;
+			return _iniUnderCursor;
+		}
+
+		if (_x >= inventoryPosition.x + 0x36
+			&& _x < inventoryPosition.x + 0x5f
+			&& _y >= inventoryPosition.y + 0xa
+			&& _y < inventoryPosition.y + 0x25
+			&& _vm->_inventory->getPositionIndex() != 0
+			&& _vm->_inventory->getPositionIndex() != 2) {
+			_iniUnderCursor = 0x8002;
+			return _iniUnderCursor;
+		}
+	}
+
+	// TODO 0x80028940
+
+	return 0;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 4c29135386..a9900cf630 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -38,6 +38,7 @@ private:
 	int16 _y;
 	Actor *_actor;
 	int32 _sequenceID;
+	uint16 _iniUnderCursor;
 
 public:
 	Cursor(DragonsEngine *vm);
@@ -45,6 +46,7 @@ public:
 	void update();
 	void updateVisibility();
 	void updatePosition(int16 x, int16 y);
+	int16 updateINIUnderCursor();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 89c3fb1d93..98a8d9cac2 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -174,10 +174,20 @@ void DragonsEngine::gameLoop() {
 		if (flickerIni->sceneId == getCurrentSceneId()) {
 			uint16 id = getIniFromImg();
 			if (id != 0) {
-				error("todo 0x80026cb0 run script");
+				// 0x80026cac
+				error("todo 0x80026cac run script");
+			} else {
+				// 0x80026d34
+				// $s4_1 = 0;
 			}
+		} else {
+			// 0x80026d34
+			// $s4_1 = 0;
 		}
 
+		// 0x80026d38
+		_cursor->updateINIUnderCursor();
+
 		runINIScripts();
 
 		_scene->draw();
@@ -462,9 +472,11 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 		if ((_flags & (Dragons::ENGINE_FLAG_80000000 | Dragons::ENGINE_FLAG_8)) == 8) {
 			_cursor->update();
 		}
-		//TODO
+		//TODO 0x80027be4
+
 		uint16 currentSceneId = _scene->getSceneId();
 
+		// 0x80027db8
 		if (!_inventory->isVisible()) {
 			for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 				DragonINI *ini = getINI(i);
@@ -476,6 +488,10 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 				}
 			}
 		}
+
+		if (run_func_ptr_unk_countdown_timer != 0) {
+			run_func_ptr_unk_countdown_timer--;
+		}
 	} else {
 		run_func_ptr_unk_countdown_timer = 1;
 	}
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index cbb204c63b..91e3ade824 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -78,4 +78,8 @@ void Inventory::updateVisibility() {
 	_actor->priorityLayer = _vm->isFlagSet(Dragons::ENGINE_FLAG_10) ? (int16)6 : (int16)0;
 }
 
+Common::Point Inventory::getPosition() {
+	return positionTable[_screenPositionIndex];
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 6eef7edbd6..92b17f5e24 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -49,6 +49,8 @@ public:
 	}
 
 	int16 getType() { return _type; }
+	int16 getPositionIndex() { return _screenPositionIndex; }
+	Common::Point getPosition();
 
 	bool isVisible() {
 		return _type != 0;


Commit: f71852707bb04e8950ed96e5b8dd9df2c143bfbc
    https://github.com/scummvm/scummvm/commit/f71852707bb04e8950ed96e5b8dd9df2c143bfbc
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on cursor animation

Changed paths:
    engines/dragons/cursor.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 6d4164e578..1821423e75 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -64,6 +64,16 @@ void Cursor::update() {
 	_actor->y_pos = _y + _vm->_scene->_camera.y;
 
 	// 0x80028104
+	if (_iniUnderCursor == 0
+	|| (!(_iniUnderCursor & 0x8000) && !(_vm->getINI(_iniUnderCursor - 1)->field_1a_flags_maybe & 0x80))
+	|| (_vm->_inventory->getType() != 1 && _vm->_inventory->getType() != 2)) {
+		//TODO 0x800281c4
+	} else {
+		// TODO 0x800281a4
+		if (_actor->_sequenceID != 0x84) {
+			_actor->updateSequence(0x84);
+		}
+	}
 }
 
 void Cursor::updateVisibility() {


Commit: b4d6e1c5207ad2356cc613c8c540f37ed7966424
    https://github.com/scummvm/scummvm/commit/b4d6e1c5207ad2356cc613c8c540f37ed7966424
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More cursor update logic

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 1821423e75..e7e57822cd 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -22,6 +22,7 @@
 #include "cursor.h"
 #include "actor.h"
 #include "dragons.h"
+#include "dragonimg.h"
 #include "dragonini.h"
 #include "inventory.h"
 #include "scene.h"
@@ -47,6 +48,8 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	dragonINIResource->getFlickerRecord()->actor = _actor; //TODO is this correct?
 	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
 	_iniUnderCursor = 0;
+	data_8007283c = 0;
+	data_either_5_or_0 = 0;
 }
 
 void Cursor::update() {
@@ -64,16 +67,63 @@ void Cursor::update() {
 	_actor->y_pos = _y + _vm->_scene->_camera.y;
 
 	// 0x80028104
-	if (_iniUnderCursor == 0
-	|| (!(_iniUnderCursor & 0x8000) && !(_vm->getINI(_iniUnderCursor - 1)->field_1a_flags_maybe & 0x80))
-	|| (_vm->_inventory->getType() != 1 && _vm->_inventory->getType() != 2)) {
-		//TODO 0x800281c4
-	} else {
-		// TODO 0x800281a4
+	if (_iniUnderCursor != 0
+	&& ((_iniUnderCursor & 0x8000 && (_vm->_inventory->getType() == 1 || _vm->_inventory->getType() == 2))
+		||(!(_iniUnderCursor & 0x8000) && _vm->getINI(_iniUnderCursor - 1)->field_1a_flags_maybe & 0x80))
+	) {
+		if (_actor->_sequenceID != 0x84) {
+			_actor->updateSequence(0x84);
+		}
+		return;
+	}
+	int32 inventorySequenceID = _vm->_inventory->getSequenceId();
+	if ((_iniUnderCursor == 0x8001) && (inventorySequenceID == 1)) {
+		if (_actor->_sequenceID != 0x84) {
+			_actor->updateSequence(0x84);
+		}
+		return;
+	}
+
+	if (_iniUnderCursor == 0x8002 && inventorySequenceID == 4) {//goto LAB_80028204;
 		if (_actor->_sequenceID != 0x84) {
 			_actor->updateSequence(0x84);
 		}
+		return;
 	}
+
+	if (_iniUnderCursor != 0x8002 || (inventorySequenceID != 1 && inventorySequenceID != 3)) {
+		if ((_iniUnderCursor != 0x8001) || ((inventorySequenceID != 0 && (inventorySequenceID != 3)))) {
+			if (_sequenceID == 5) {
+				uint16 uVar1 = (uint) data_8007283c;
+				if (data_either_5_or_0 != 0) {
+					uVar1 = uVar1 + 1;
+				}
+				if (uVar1 == (uint) _actor->_sequenceID) {
+					return;
+				}
+				_actor->updateSequence((uint) data_8007283c + (uint) (data_either_5_or_0 != 0));
+			} else {
+				if (_sequenceID + (uint) data_either_5_or_0 != (uint) _actor->_sequenceID) {
+					_actor->updateSequence(_sequenceID + (uint) data_either_5_or_0);
+				}
+			}
+			return;
+		}
+	}
+
+	if (_vm->data_8006f3a8 == 0) {
+		if (_actor->_sequenceID != 0x84) {
+			_actor->updateSequence(0x84);
+		}
+		return;
+	}
+	else {
+		if ((uint)_actor->_sequenceID != (uint)data_8007283c + 1) {
+			_actor->updateSequence((uint)data_8007283c + 1);
+		}
+	}
+
+	// 0x_800281c0
 }
 
 void Cursor::updateVisibility() {
@@ -117,9 +167,59 @@ int16 Cursor::updateINIUnderCursor() {
 		}
 	}
 
+	_iniUnderCursor = 0; //TODO remove this once we complete function.
+
 	// TODO 0x80028940
+	int16 inventoryType = _vm->_inventory->getType();
+	if (inventoryType == 1) {
+		// Might be open inventory bag.
+		//TODO 0x80028da8
+	} else if (inventoryType > 2) {
+		_iniUnderCursor = 0;
+		return 0;
+	}
+
+	return updateIniFromScene();
+}
+
+int16 Cursor::updateIniFromScene() {
+	int16 cursorTileX = _actor->x_pos / 32;
+	int16 cursorTileY = _actor->y_pos / 8;
+
+	for(int i=0;i <_vm->_dragonINIResource->totalRecords(); i++) {
+		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
+		if (ini->sceneId != _vm->_scene->getSceneId()) {
+			// 0x80028be4
+		} else if (!_vm->_dragonINIResource->isFlicker(ini) && !(ini->field_1a_flags_maybe & 0x40)) {
+			int16 cursorOverIni = 0;
+			// 0x80028a10
+			if (ini->field_1a_flags_maybe & 1) {
+				// 0x80028b18
+			} else {
+				// 0x80028a24
+				if (ini->field_2 != -1) {
+					IMG *img = _vm->_dragonIMG->getIMG((uint32)ini->field_2);
+					if (img->field_e - 1 >= 2) {
+						if (cursorTileX >= img->x && cursorTileX < img->x + img->w && cursorTileY >= img->y && cursorTileY < img->y + img->h) {
+							cursorOverIni = i + 1;
+						}
+					} else {
+						// 0x80028ac4
+						if (_actor->x_pos >= img->x && _actor->x_pos < img->x + img->w && _actor->y_pos >= img->y && _actor->y_pos < img->y + img->h) {
+							cursorOverIni = i + 1;
+						}
+					}
+				}
+			}
+			if (cursorOverIni != 0) {
+				// 0x80028bf0
+				debug(1, "here OK!!!");
+				_iniUnderCursor = cursorOverIni;
+			}
+		}
+	}
 
-	return 0;
+			return 0;
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index a9900cf630..a026cac513 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -40,6 +40,9 @@ private:
 	int32 _sequenceID;
 	uint16 _iniUnderCursor;
 
+	int16 data_8007283c;
+	int16 data_either_5_or_0;
+
 public:
 	Cursor(DragonsEngine *vm);
 	void init(ActorManager *actorManager, DragonINIResource *dragonINIResource);
@@ -47,6 +50,7 @@ public:
 	void updateVisibility();
 	void updatePosition(int16 x, int16 y);
 	int16 updateINIUnderCursor();
+	int16 updateIniFromScene();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 98a8d9cac2..b6f4e5913d 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -67,6 +67,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	run_func_ptr_unk_countdown_timer = 0;
 	data_8006a3a0_flag = 0;
 	data_800633fa = 0;
+	data_8006f3a8 = 0;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index ce7ad277ab..a47db93399 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -113,6 +113,7 @@ public:
 	uint16 data_800633fa;
 	Inventory *_inventory;
 	Cursor *_cursor;
+	uint16 data_8006f3a8;
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;


Commit: cbf85f6913f05ff27ba7b76da44eaae157f394c5
    https://github.com/scummvm/scummvm/commit/cbf85f6913f05ff27ba7b76da44eaae157f394c5
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Implementing more script opcodes

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index e7e57822cd..38c4244a4c 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -24,8 +24,10 @@
 #include "dragons.h"
 #include "dragonimg.h"
 #include "dragonini.h"
+#include "dragonobd.h"
 #include "inventory.h"
 #include "scene.h"
+#include "scriptopcodes.h"
 
 namespace Dragons {
 
@@ -50,6 +52,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	_iniUnderCursor = 0;
 	data_8007283c = 0;
 	data_either_5_or_0 = 0;
+	data_800728b0_cursor_seqID = 0;
 }
 
 void Cursor::update() {
@@ -214,12 +217,84 @@ int16 Cursor::updateIniFromScene() {
 			if (cursorOverIni != 0) {
 				// 0x80028bf0
 				debug(1, "here OK!!!");
-				_iniUnderCursor = cursorOverIni;
+				// _iniUnderCursor = cursorOverIni;
+				data_80072890 = _iniUnderCursor;
+				data_800728b0_cursor_seqID = _sequenceID;
+				if (ini->field_1a_flags_maybe & 0x800) {
+					data_80072890 = cursorOverIni;
+					uint32 newSeqId = 1;
+					for(int idx=0; idx < 5; idx++) {
+						byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
+						ScriptOpCall scriptOpCall;
+						scriptOpCall._code = obd + 8;
+						scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+
+//						uVar17 = uVar15;
+//						local_58 = dragon_Obd_Offset + *(int *)(uVar16 * 8 + dragon_Opt_Offset + -8) + 8;
+//						data_800728b0 = idx;
+//						local_54 = read_int32();
+//						local_54 = local_54 + local_58;
+//						uVar6 = ;
+						if (executeScript(scriptOpCall, 0)) {
+							newSeqId = idx;
+							break;
+						}
+					}
+
+					_sequenceID = newSeqId;
+					_iniUnderCursor = cursorOverIni;
+					data_80072890 = _iniUnderCursor;
+					data_800728b0_cursor_seqID = _sequenceID;
+					return _iniUnderCursor;
+				}
+				if (_sequenceID != 0) {
+					_iniUnderCursor = cursorOverIni;
+//					data_80072890 = uVar3; TODO
+//					data_800728b0 = uVar4;
+					return _iniUnderCursor;
+				}
+				byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
+				ScriptOpCall scriptOpCall;
+				scriptOpCall._code = obd + 8;
+				scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+
+//				local_48 = dragon_Obd_Offset + *(int *)(uVar16 * 8 + dragon_Opt_Offset + -8) + 8;
+//				local_44 = read_int32();
+//				local_44 = local_44 + local_48;
+				if(executeScript(scriptOpCall, 0)) {
+					_iniUnderCursor = cursorOverIni;
+//					data_80072890 = uVar3; //TODO
+//					data_800728b0 = uVar4;
+					return _iniUnderCursor;
+				}
 			}
 		}
 	}
+	_iniUnderCursor = 0;
+//	data_80072890 = uVar3; TODO
+//	data_800728b0 = uVar4;
+	return 0;
+}
 
-			return 0;
+int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
+	int16 temp = _vm->_scriptOpcodes->_data_800728c0;
+	scriptOpCall._field8 = 1;
+	scriptOpCall._result = 0;
+	_vm->_scriptOpcodes->_data_80071f5c = 0;
+	_vm->_scriptOpcodes->executeScriptLoop(scriptOpCall);
+
+	if (!(scriptOpCall._result & 1) && data_800728b0_cursor_seqID == 5 && unkFlag != 0) {
+		_vm->_scriptOpcodes->_data_800728c0 = -1;
+		scriptOpCall._field8 = 1;
+		scriptOpCall._result = 0;
+		_vm->_scriptOpcodes->_data_80071f5c = 0;
+		_vm->_scriptOpcodes->executeScriptLoop(scriptOpCall);
+		_vm->_scriptOpcodes->_data_800728c0 = temp;
+		if (scriptOpCall._result & 1) {
+			scriptOpCall._result |= 2;
+		}
+	}
+	return scriptOpCall._result & 3;
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index a026cac513..1a06f38baf 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -23,6 +23,7 @@
 #define DRAGONS_CURSOR_H
 
 #include "common/system.h"
+#include "scriptopcodes.h"
 
 namespace Dragons {
 
@@ -32,6 +33,8 @@ class DragonsEngine;
 class DragonINIResource;
 
 class Cursor {
+public:
+	int16 data_800728b0_cursor_seqID;
 private:
 	DragonsEngine *_vm;
 	int16 _x;
@@ -40,8 +43,9 @@ private:
 	int32 _sequenceID;
 	uint16 _iniUnderCursor;
 
-	int16 data_8007283c;
 	int16 data_either_5_or_0;
+	int16 data_8007283c;
+	int16 data_80072890;
 
 public:
 	Cursor(DragonsEngine *vm);
@@ -50,6 +54,8 @@ public:
 	void updateVisibility();
 	void updatePosition(int16 x, int16 y);
 	int16 updateINIUnderCursor();
+	int16 executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag);
+private:
 	int16 updateIniFromScene();
 };
 
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index a47db93399..884883bdf2 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -108,6 +108,7 @@ public:
 	DragonRMS *_dragonRMS;
 	ActorManager *_actorManager;
 	DragonINIResource *_dragonINIResource;
+	ScriptOpcodes *_scriptOpcodes;
 	uint16 _cursorSequenceID;
 	Scene *_scene;
 	uint16 data_800633fa;
@@ -121,7 +122,6 @@ private:
 	DragonVAR *_dragonVAR;
 	BackgroundResourceLoader *_backgroundResourceLoader;
 	SequenceOpcodes *_sequenceOpcodes;
-	ScriptOpcodes *_scriptOpcodes;
 	uint32 _nextUpdatetime;
 	uint32 _flags;
 	uint32 _unkFlags1;
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index bd9f27a103..059c5dc557 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -21,9 +21,11 @@
  */
 
 #include "dragons/actorresource.h"
+#include "dragons/cursor.h"
 #include "dragons/dragons.h"
 #include "dragons/dragonflg.h"
 #include "dragons/dragonini.h"
+#include "dragons/dragonimg.h"
 #include "dragons/dragonobd.h"
 #include "dragons/scene.h"
 #include "dragons/scriptopcodes.h"
@@ -61,6 +63,7 @@ ScriptOpcodes::ScriptOpcodes(DragonsEngine *vm, DragonFLG *dragonFLG)
 	: _vm(vm), _dragonFLG(dragonFLG), _data_80071f5c(0) {
 	_specialOpCodes = new SpecialOpcodes(_vm);
 	initOpcodes();
+	_data_800728c0 = 0;
 }
 
 ScriptOpcodes::~ScriptOpcodes() {
@@ -86,7 +89,7 @@ void ScriptOpcodes::initOpcodes() {
 		_opcodes[i] = 0;
 	}
 	// Register opcodes
-	// OPCODE(1, opUnk1);
+	OPCODE(1, opUnk1);
 
 	OPCODE(4,  opExecuteScript);
 	OPCODE(5,  opActorSetSequenceID2);
@@ -100,11 +103,14 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0xD, opDelay);
 	OPCODE(0xE, opUnkE);
 	OPCODE(0xF, opUnkF);
-
+	OPCODE(0x10, opUnk10);
 	OPCODE(0x11, opUnk11FlickerTalk);
 	OPCODE(0x12, opUnk12LoadScene);
 	OPCODE(0x13, opUnk13PropertiesRelated);
 
+	OPCODE(0x16, opUnk16);
+	OPCODE(0x17, opUnk17);
+
 	OPCODE(0x1F, opPlayMusic);
 
 	OPCODE(0x22, opCodeActorTalk);
@@ -188,12 +194,18 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 // Opcodes
 
 void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
-//	ARG_INT16(framePointer);
-//	debug(3, "set frame pointer %X", framePointer);
-//	actor->loadFrame((uint16)framePointer);
-//	actor->flags |= Dragons::ACTOR_FLAG_2;
-//	actor->sequenceTimer = actor->field_c;
-//	updateReturn(scriptOpCall, 1);
+	ARG_SKIP(2);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+
+	if (field2 >> _vm->_cursor->data_800728b0_cursor_seqID & 1
+	&& (_vm->_cursor->data_800728b0_cursor_seqID < 5 || field4 == _data_800728c0)
+	&& scriptOpCall._field8 == 1) {
+		scriptOpCall._result |= 1;
+	} else {
+		scriptOpCall._code += (8 + field6);
+	}
 }
 
 void ScriptOpcodes::opExecuteScript(ScriptOpCall &scriptOpCall) {
@@ -446,7 +458,7 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 		}
 		ini->x = point.x;
 		ini->y = point.y;
-		ini->actor->flags &= ~Dragons::ACTOR_FLAG_800;
+		ini->actor->clearFlag(Dragons::ACTOR_FLAG_800);
 
 	} else {
 		ini->x = point.x;
@@ -515,6 +527,109 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+	ARG_INT16(field8);
+
+	//TODO these should be passed in as arguments and xparam should be set correctly.
+	int16 someXParam = 0;
+	int16 someYParam = _data_800728c0;
+	uint someBooleanFlag = 0;
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	bool bVar1 = false;
+	DragonINI *firstIni = _vm->getINI(field4 - 1);
+	DragonINI *secondIni = _vm->getINI(field2 - 1);
+//	secondIndexIntoINI = (uint)field2 - 1;
+//	firstIndexIntoINI = (uint)field4 - 1;
+	if ((field6 & 0x8000) != 0) {
+		bVar1 = (field6 != -1);
+	}
+	if (field8 == -1) {
+		if ((firstIni->field_1a_flags_maybe & 1) == 0) {
+			if ((int)firstIni->field_2 != -1) {
+				IMG *firstDragonImg1 = _vm->_dragonIMG->getIMG(firstIni->field_2);
+				int16 newXPos1 = firstDragonImg1->field_a + firstIni->field_1c;
+				secondIni->x = newXPos1;
+				secondIni->actor->x_pos = newXPos1;
+				int16 newYPos1 = firstDragonImg1->field_c + firstIni->field_1e;
+				secondIni->y = newYPos1;
+				secondIni->actor->y_pos = newYPos1;
+			}
+		}
+		else {
+			int16 newYPos2 = firstIni->actor->y_pos + firstIni->field_1e;
+			firstIni->y = newYPos2;
+			secondIni->actor->y_pos = newYPos2;
+			someXParam = firstIni->actor->x_pos + firstIni->field_1c;
+			secondIni->x = someXParam;
+			secondIni->actor->x_pos = someXParam;
+		}
+		if (field6 != -1) {
+			secondIni->actor->field_7c = -1;
+			secondIni->actor->updateSequence(field6 & 0x7fff);
+		}
+		secondIni->x = someXParam;
+		secondIni->y = someYParam;
+		return;
+	}
+	if ((field8 & 0x8000) == 0) {
+		someBooleanFlag = (uint)field8 << 0x10;
+	}
+	else {
+		someBooleanFlag = ((uint)field8 & 0x7fff) << 7;
+	}
+	if (field6 != -1) {
+		if (((int)(short)field0 & 0x8000) == 0) {
+			secondIni->actor->setFlag(ACTOR_FLAG_800);
+			secondIni->actor->updateSequence(field6 & 0x7fff);
+		}
+		secondIni->actor->field_7c =
+				someBooleanFlag;
+	}
+	int16 newXPosAgain = 0;
+	int16 newYPosAgain = 0;
+	someBooleanFlag = 1;
+	if ((firstIni->field_1a_flags_maybe & 1) == 0) {
+		if ((int)firstIni->field_2 == -1) {
+			return;
+		}
+		IMG *firstDragonImg2 = _vm->_dragonIMG->getIMG(firstIni->field_2);
+
+		newXPosAgain = firstDragonImg2->field_a + firstIni->field_1c;
+		newYPosAgain = firstDragonImg2->field_c + firstIni->field_1e;
+		if (_vm->_dragonINIResource->isFlicker(secondIni)) {
+			someBooleanFlag = 0;
+		}
+	}
+	else {
+		newXPosAgain = firstIni->actor->x_pos + firstIni->field_1c;
+		newYPosAgain = firstIni->actor->y_pos + firstIni->field_1e;
+		if (_vm->_dragonINIResource->isFlicker(secondIni)) {
+			someBooleanFlag = 0;
+		}
+	}
+	secondIni->actor->pathfinding_maybe(newXPosAgain, newYPosAgain, someBooleanFlag);
+	if (!bVar1) {
+		while (secondIni->actor->flags & Dragons::ACTOR_FLAG_10) {
+			_vm->waitForFrames(1);
+		}
+	}
+
+	secondIni->actor->_sequenceID2 = firstIni->field_e;
+
+	secondIni->x = newXPosAgain;
+	secondIni->y = newYPosAgain;
+	secondIni->actor->clearFlag(ACTOR_FLAG_800);
+	return;
+
+}
+
 void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(8);
 	// TODO implement me!
@@ -701,6 +816,27 @@ void ScriptOpcodes::opUnk15(ScriptOpCall &scriptOpCall) {
 
 }
 
+void ScriptOpcodes::opUnk16(ScriptOpCall &scriptOpCall) {
+	if (scriptOpCall._field8 == 4) {
+		scriptOpCall._result |= 1;
+	} else {
+		scriptOpCall._code += 4;
+	}
+}
+
+void ScriptOpcodes::opUnk17(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(iniId);
+
+	DragonINI *ini = _vm->getINI(iniId - 1);
+	if (ini->field_1a_flags_maybe & 1) {
+		while (!(ini->actor->flags & Dragons::ACTOR_FLAG_4)) {
+			_vm->waitForFrames(1);
+		}
+	}
+
+}
+
 void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 3c22f74c71..4cb03c5e5a 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -63,18 +63,19 @@ public:
 	void runScript(ScriptOpCall &scriptOpCall);
 	void runScript3(ScriptOpCall &scriptOpCall);
 	void execOpcode(ScriptOpCall &scriptOpCall);
+	void executeScriptLoop(ScriptOpCall &scriptOpCall);
+	int16 _data_80071f5c;
+	int16 _data_800728c0;
 protected:
 	DragonsEngine *_vm;
 	DragonFLG *_dragonFLG;
 	SpecialOpcodes *_specialOpCodes;
 	ScriptOpcode *_opcodes[DRAGONS_NUM_SCRIPT_OPCODES];
 	Common::String _opcodeNames[DRAGONS_NUM_SCRIPT_OPCODES];
-	int16 _data_80071f5c;
 
 	void initOpcodes();
 	void freeOpcodes();
 	void updateReturn(ScriptOpCall &scriptOpCall, uint16 size);
-	void executeScriptLoop(ScriptOpCall &scriptOpCall);
 
 
 	// Opcodes
@@ -91,12 +92,14 @@ protected:
 	void opDelay(ScriptOpCall &scriptOpCall); //op D
 	void opUnkE(ScriptOpCall &scriptOpCall);
 	void opUnkF(ScriptOpCall &scriptOpCall);
-
+	void opUnk10(ScriptOpCall &scriptOpCall);
 	void opUnk11FlickerTalk(ScriptOpCall &scriptOpCall);
 	void opUnk12LoadScene(ScriptOpCall &scriptOpCall);
 	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opUnk14(ScriptOpCall &scriptOpCall);
 	void opUnk15(ScriptOpCall &scriptOpCall);
+	void opUnk16(ScriptOpCall &scriptOpCall);
+	void opUnk17(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
 
 	bool checkPropertyFlag(ScriptOpCall &scriptOpCall);


Commit: c287fa71067cce3eeb3d30f6d9effc2211359aa2
    https://github.com/scummvm/scummvm/commit/c287fa71067cce3eeb3d30f6d9effc2211359aa2
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Started work on cursor cycling via right clicking

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 38c4244a4c..0c65451e4a 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -297,4 +297,22 @@ int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 	return scriptOpCall._result & 3;
 }
 
+void Cursor::selectPreviousCursor() {
+	int16 uVar7 = _sequenceID - 1;
+	int16 inventoryType = _vm->_inventory->getType();
+	if ((uVar7 == 0) && ((inventoryType == 1 || (inventoryType == 2)))) {
+		uVar7 = _sequenceID - 2;
+	}
+	_sequenceID = uVar7;
+	if ((_sequenceID == 3) && (inventoryType == 1)) {
+		_sequenceID = 1;
+	}
+	if (_sequenceID == 2) {
+		_sequenceID = 1;
+	}
+	if (_sequenceID == -1) {
+		_sequenceID = _vm->data_8006f3a8 == 0 ? 4 : 5;
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 1a06f38baf..0ed904e574 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -55,6 +55,8 @@ public:
 	void updatePosition(int16 x, int16 y);
 	int16 updateINIUnderCursor();
 	int16 executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag);
+	void selectPreviousCursor();
+	void selectNextCursor();
 private:
 	int16 updateIniFromScene();
 };
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index b6f4e5913d..8046372257 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -70,6 +70,8 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	data_8006f3a8 = 0;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
+
+	_rightMouseButtonUp = false;
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -79,6 +81,7 @@ DragonsEngine::~DragonsEngine() {
 
 void DragonsEngine::updateEvents() {
 	Common::Event event;
+	_rightMouseButtonUp = false;
 	while (_eventMan->pollEvent(event)) {
 //		_input->processEvent(event);
 		switch (event.type) {
@@ -88,6 +91,9 @@ void DragonsEngine::updateEvents() {
 			case Common::EVENT_MOUSEMOVE:
 				_cursor->updatePosition(event.mouse.x, event.mouse.y);
 				break;
+			case Common::EVENT_RBUTTONUP:
+				_rightMouseButtonUp = true;
+				break;
 			default:
 				break;
 		}
@@ -189,6 +195,10 @@ void DragonsEngine::gameLoop() {
 		// 0x80026d38
 		_cursor->updateINIUnderCursor();
 
+		if (_rightMouseButtonUp) {
+			_cursor->selectPreviousCursor();
+		}
+
 		runINIScripts();
 
 		_scene->draw();
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 884883bdf2..d903d3c4ee 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -134,6 +134,9 @@ private:
 
 	uint16 run_func_ptr_unk_countdown_timer;
 
+	// input
+	bool _rightMouseButtonUp;
+
 public:
 	DragonsEngine(OSystem *syst);
 	~DragonsEngine();


Commit: 28a75525fd4f9cf6c5aa89f0185d7908f6674591
    https://github.com/scummvm/scummvm/commit/28a75525fd4f9cf6c5aa89f0185d7908f6674591
Author: Edu Garcia (28616+Arcnor at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Implementing opcode 14

Changed paths:
    engines/dragons/dragons.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index d903d3c4ee..7a1d1d36c6 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -65,6 +65,7 @@ enum Flags {
 	ENGINE_FLAG_100 = 0x100,
 	ENGINE_FLAG_200 = 0x200,
 
+	ENGINE_FLAG_TEXT_ENABLED = 0x1000,
 	ENGINE_FLAG_10000    =    0x10000,
 	ENGINE_FLAG_80000    =    0x80000,
 	ENGINE_FLAG_100000   =   0x100000,
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 059c5dc557..fe246e87a5 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -107,6 +107,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x11, opUnk11FlickerTalk);
 	OPCODE(0x12, opUnk12LoadScene);
 	OPCODE(0x13, opUnk13PropertiesRelated);
+	OPCODE(0x14, opUnk14PropertiesRelated);
 
 	OPCODE(0x16, opUnk16);
 	OPCODE(0x17, opUnk17);
@@ -288,6 +289,31 @@ void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
+	if (checkPropertyFlag(scriptOpCall)) {
+		ScriptOpCall localScriptOpCall;
+		byte *codePtrOffset2 = scriptOpCall._code + 4;
+		localScriptOpCall._code = codePtrOffset2;
+		localScriptOpCall._codeEnd = localScriptOpCall._code + READ_LE_UINT32(scriptOpCall._code);
+		localScriptOpCall._field8 = scriptOpCall._field8;
+		localScriptOpCall._result = 0;
+
+		executeScriptLoop(scriptOpCall);
+
+		if (scriptOpCall._field8 == 1) {
+			scriptOpCall._result = localScriptOpCall._result;
+			if ((localScriptOpCall._result & 1) != 0) {
+				scriptOpCall._code = localScriptOpCall._code;
+				return;
+			}
+		}
+
+		scriptOpCall._code = localScriptOpCall._code + READ_LE_UINT16(scriptOpCall._code);
+	} else {
+		scriptOpCall._code += 4 + READ_LE_UINT16(scriptOpCall._code);
+	}
+}
+
 bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {
 	byte *codePtrOffsetA = scriptOpCall._code + 0xA;
 	byte *codePtrOffset2 = scriptOpCall._code + 2;
@@ -631,8 +657,12 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 }
 
 void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
-	ARG_SKIP(8);
+	ARG_SKIP(2);
+	ARG_INT16(actorId)
+	ARG_UINT32(textIndex)
 	// TODO implement me!
+
+    debug("Main actor talk: 0x%04x and text 0x%04x", actorId, textIndex);
 }
 
 void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
@@ -660,15 +690,16 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 
 void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
-	ARG_INT16(field2);
+	ARG_INT16(actorId);
 	ARG_SKIP(6);
-	ARG_UINT32(fieldA);
+	ARG_UINT32(textIndex);
 
 	if (scriptOpCall._field8 != 0) {
 		return;
 	}
 
 	//TODO implement actor talk.
+	debug("Actor talk: 0x%04x and text 0x%04x", actorId, textIndex);
 }
 
 void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
@@ -808,10 +839,6 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 
 }
 
-void ScriptOpcodes::opUnk14(ScriptOpCall &scriptOpCall) {
-
-}
-
 void ScriptOpcodes::opUnk15(ScriptOpCall &scriptOpCall) {
 
 }
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 4cb03c5e5a..4bc28fd94c 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -96,7 +96,7 @@ protected:
 	void opUnk11FlickerTalk(ScriptOpCall &scriptOpCall);
 	void opUnk12LoadScene(ScriptOpCall &scriptOpCall);
 	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
-	void opUnk14(ScriptOpCall &scriptOpCall);
+	void opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opUnk15(ScriptOpCall &scriptOpCall);
 	void opUnk16(ScriptOpCall &scriptOpCall);
 	void opUnk17(ScriptOpCall &scriptOpCall);


Commit: deecd245821b1505ffda51e84cc3dfa2471bfeee
    https://github.com/scummvm/scummvm/commit/deecd245821b1505ffda51e84cc3dfa2471bfeee
Author: Edu Garcia (28616+Arcnor at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Implementing opcode 15

Changed paths:
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index fe246e87a5..0c8346b4c8 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -108,6 +108,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x12, opUnk12LoadScene);
 	OPCODE(0x13, opUnk13PropertiesRelated);
 	OPCODE(0x14, opUnk14PropertiesRelated);
+	OPCODE(0x15, opUnk15PropertiesRelated);
 
 	OPCODE(0x16, opUnk16);
 	OPCODE(0x17, opUnk17);
@@ -292,8 +293,7 @@ void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
 void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	if (checkPropertyFlag(scriptOpCall)) {
 		ScriptOpCall localScriptOpCall;
-		byte *codePtrOffset2 = scriptOpCall._code + 4;
-		localScriptOpCall._code = codePtrOffset2;
+		localScriptOpCall._code = scriptOpCall._code + 4;
 		localScriptOpCall._codeEnd = localScriptOpCall._code + READ_LE_UINT32(scriptOpCall._code);
 		localScriptOpCall._field8 = scriptOpCall._field8;
 		localScriptOpCall._result = 0;
@@ -314,6 +314,24 @@ void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall) {
+	while (true) {
+		if (checkPropertyFlag(scriptOpCall)) {
+			ScriptOpCall localScriptOpCall;
+			localScriptOpCall._code = scriptOpCall._code + 4;
+			localScriptOpCall._codeEnd = localScriptOpCall._code + READ_LE_UINT32(scriptOpCall._code);
+
+			runScript(localScriptOpCall);
+
+			scriptOpCall._code = (scriptOpCall._code - ((uint)*(scriptOpCall._code + 2) + 2));
+		} else {
+			break;
+		}
+	}
+
+	scriptOpCall._code += 4 + READ_LE_UINT16(scriptOpCall._code);
+}
+
 bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {
 	byte *codePtrOffsetA = scriptOpCall._code + 0xA;
 	byte *codePtrOffset2 = scriptOpCall._code + 2;
@@ -839,10 +857,6 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 
 }
 
-void ScriptOpcodes::opUnk15(ScriptOpCall &scriptOpCall) {
-
-}
-
 void ScriptOpcodes::opUnk16(ScriptOpCall &scriptOpCall) {
 	if (scriptOpCall._field8 == 4) {
 		scriptOpCall._result |= 1;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 4bc28fd94c..78306a96c7 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -97,7 +97,7 @@ protected:
 	void opUnk12LoadScene(ScriptOpCall &scriptOpCall);
 	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall);
-	void opUnk15(ScriptOpCall &scriptOpCall);
+	void opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opUnk16(ScriptOpCall &scriptOpCall);
 	void opUnk17(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);


Commit: 22ab216b787775d486d2835bcaf927b7a5b0ae35
    https://github.com/scummvm/scummvm/commit/22ab216b787775d486d2835bcaf927b7a5b0ae35
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Adding game loop from original logic

Changed paths:
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.h
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 0ed904e574..6224469e6f 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -35,13 +35,13 @@ class DragonINIResource;
 class Cursor {
 public:
 	int16 data_800728b0_cursor_seqID;
+	uint16 _iniUnderCursor;
+	int32 _sequenceID;
 private:
 	DragonsEngine *_vm;
 	int16 _x;
 	int16 _y;
 	Actor *_actor;
-	int32 _sequenceID;
-	uint16 _iniUnderCursor;
 
 	int16 data_either_5_or_0;
 	int16 data_8007283c;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 8046372257..499fc5fd87 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -62,15 +62,15 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_sequenceOpcodes = new SequenceOpcodes(this);
 	_scriptOpcodes = NULL;
 	_engine = this;
-	_cursorPosition = Common::Point();
-	_cursorSequenceID = 0;
 	run_func_ptr_unk_countdown_timer = 0;
 	data_8006a3a0_flag = 0;
 	data_800633fa = 0;
 	data_8006f3a8 = 0;
+	_data_either_5_or_0 = 0;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
 
+	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
 }
 
@@ -81,6 +81,7 @@ DragonsEngine::~DragonsEngine() {
 
 void DragonsEngine::updateEvents() {
 	Common::Event event;
+	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
 	while (_eventMan->pollEvent(event)) {
 //		_input->processEvent(event);
@@ -91,6 +92,9 @@ void DragonsEngine::updateEvents() {
 			case Common::EVENT_MOUSEMOVE:
 				_cursor->updatePosition(event.mouse.x, event.mouse.y);
 				break;
+			case Common::EVENT_LBUTTONUP:
+				_leftMouseButtonUp = true;
+				break;
 			case Common::EVENT_RBUTTONUP:
 				_rightMouseButtonUp = true;
 				break;
@@ -195,10 +199,15 @@ void DragonsEngine::gameLoop() {
 		// 0x80026d38
 		_cursor->updateINIUnderCursor();
 
-		if (_rightMouseButtonUp) {
+		if (_rightMouseButtonUp && !isFlagSet(ENGINE_FLAG_20000000) && !isFlagSet(ENGINE_FLAG_400)) {
 			_cursor->selectPreviousCursor();
 		}
 
+		// Action input
+		if (_leftMouseButtonUp && !isFlagSet(ENGINE_FLAG_20000000) && !isFlagSet(ENGINE_FLAG_400)) {
+			//TODO
+		}
+
 		runINIScripts();
 
 		_scene->draw();
@@ -207,6 +216,417 @@ void DragonsEngine::gameLoop() {
 	}
 }
 
+
+
+/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */
+
+void DragonsEngine::game_loop()
+
+{
+	/**
+	bool bVar1;
+	DragonINI *pDVar2;
+	uint uVar3;
+	uint32_t uVar4;
+	uint actorId;
+	int iVar5;
+	ushort uVar6;
+	ushort uVar7;
+	uint actorId_00;
+	void *buffer;
+	uint16_t sequenceId;
+	DragonINI *pDVar8;
+	ushort *puVar9;
+	ScriptOpCall local_30;
+
+	_data_either_5_or_0 = 0;
+	bit_flags_8006fbd8 = 0;
+	_counter = 0;
+	setFlags(ENGINE_FLAG_8);
+	actorId = 0;
+
+	while(!shouldQuit()) {
+		LAB_80026a74:
+		wait();
+		pDVar2 = dragon_ini_pointer;
+		iVar5 = data_80063940_const_c3_maybe;
+		if ((uint)currentSceneId != _const_value_2) {
+			sceneId_1 = currentSceneId;
+		}
+		_counter++;
+		if (0x4af < _counter) {
+			pDVar8 = _dragonINIResource->getFlickerRecord(); //dragon_ini_pointer + (uint)dragon_ini_maybe_flicker_control;
+			if (pDVar8->actor->resourceID == 0xe) {
+				pDVar8->actor->_sequenceID2 = 2;
+				pDVar8->field_20_actor_field_14 = 2;
+				if (getINI(0xc2)->field_1e == 1) {
+					sequenceId = 0x30;
+				}
+				else {
+					sequenceId = 2;
+				}
+				pDVar8->actor->updateSequence(sequenceId);
+				_counter = 0;
+				setFlags(ENGINE_FLAG_80000000);
+			}
+		}
+		if (isFlagSet(ENGINE_FLAG_80000000)
+			&& _dragonINIResource->getFlickerRecord()->actor->isFlagSet(ACTOR_FLAG_4)) {
+			_counter = 0;
+			clearFlags(ENGINE_FLAG_80000000);
+		}
+		if (bit_flags_8006fbd8 == 0) {
+			setFlags(ENGINE_FLAG_8);
+		}
+		if (dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].sceneId_maybe == currentSceneId) {
+			uVar3 = ipt_img_file_related();
+			actorId_00 = uVar3 & 0xffff;
+			if (actorId_00 == 0) goto LAB_80026d34;
+			if (actorId_00 != (actorId & 0xffff)) {
+				buffer = (void *)((int)dragon_Obd_Offset + dragon_Opt_Offset[actorId_00 - 1].obdOffset);
+				local_30.code = (void *)((int)buffer + 8);
+				uVar4 = read_int32(buffer);
+				local_30.codeEnd = (void *)(uVar4 + (int)local_30.code);
+				actorId = run_script_field8_eq_4(&local_30);
+				if ((actorId & 0xffff) != 0) {
+					local_30.codeEnd =
+							(void *)((uint)*(ushort *)((int)local_30.code + 2) +
+									 (int)(void *)((int)local_30.code + 4));
+					local_30.code = (void *)((int)local_30.code + 4);
+					run_script(&local_30);
+					_counter = 0;
+				}
+			}
+		}
+		else {
+			LAB_80026d34:
+			uVar3 = 0;
+		}
+		actorId = updateINIUnderCursor();
+		if (((actorId & 0xffff) == 0) ||
+			((dragon_ini_pointer[(uint)_cursor->_iniUnderCursor].actorId & 0x4000) != 0)) {
+			_data_either_5_or_0 = 0;
+		}
+		else {
+			_data_either_5_or_0 = 5;
+		}
+		actorId = CheckButtonMapPress_CycleDown(0);
+		if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 0x20000400) == 0)) {
+			uVar6 = _cursor->_sequenceID - 1;
+			if ((uVar6 == 0) && ((_inventory->getType() == 1 || (_inventory->getType() == 2)))) {
+				uVar6 = _cursor->_sequenceID - 2;
+			}
+			_cursor->_sequenceID = uVar6;
+			if ((_cursor->_sequenceID == 3) && (_inventory->getType() == 1)) {
+				_cursor->_sequenceID = 1;
+			}
+			if (_cursor->_sequenceID == 2) {
+				_cursor->_sequenceID = 1;
+			}
+			if (_cursor->_sequenceID == 0xffff) {
+				uVar6 = 5;
+				if (DAT_8006f3a8 == 0) {
+					uVar6 = 4;
+				}
+				LAB_80026fb0:
+				_cursor->_sequenceID = uVar6;
+			}
+			_counter = 0;
+			actorId = uVar3;
+			continue;
+		}
+		actorId = CheckButtonMapPress_CycleUp(0);
+		if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 0x20000400) == 0)) {
+			_cursor->_sequenceID = _cursor->_sequenceID + 1;
+			if (DAT_8006f3a8 == 0) {
+				bVar1 = _cursor->_sequenceID < 5;
+			}
+			else {
+				bVar1 = _cursor->_sequenceID < 6;
+			}
+			if (!bVar1) {
+				_cursor->_sequenceID = 0;
+			}
+			if ((_cursor->_sequenceID == 0) && ((_inventory->getType() == 1 || (_inventory->getType() == 2)))) {
+				_cursor->_sequenceID = 1;
+			}
+			if (_cursor->_sequenceID == 2) {
+				if (_inventory->getType() == 1) {
+					_cursor->_sequenceID = 4;
+				}
+				uVar6 = 3;
+				if (_cursor->_sequenceID == 2) goto LAB_80026fb0;
+			}
+			_counter = 0;
+			actorId = uVar3;
+			continue;
+		}
+		if (bit_flags_8006fbd8 == 3) {
+			bit_flags_8006fbd8 = 0;
+			if ((dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].sceneId_maybe == currentSceneId)
+				&& (actorId = (uint)dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].actorId,
+					actors[actorId]._sequenceID2 != 0xffff)) {
+				uVar6 = DAT_800728c0;
+				if (_cursor->_sequenceID != 5) {
+					uVar6 = DAT_80072890;
+				}
+				actors[actorId]._sequenceID2 = dragon_ini_pointer[(uint)uVar6 - 1].field_0x20;
+			}
+			works_with_obd_data_1();
+			if (((uint)currentSceneId == DAT_80063a70) && (dragon_ini_pointer[DAT_80063b0c].field_0x2 != 0))
+			{
+				engine_flags_maybe = engine_flags_maybe & 0xfffffff7;
+			}
+			else {
+				engine_flags_maybe = engine_flags_maybe | 8;
+			}
+			_counter = 0;
+			actorId = uVar3;
+			continue;
+		}
+		if (_inventory->getType() != 1) {
+			if (_inventory->getType() < 2) {
+				if (_inventory->getType() == 0) {
+					actorId = CheckButtonMapPress_InventoryBag(0);
+					if ((((actorId & 0xffff) != 0) && ((engine_flags_maybe & 0x20000400) == 0)) &&
+						((bit_flags_8006fbd8 & 3) != 1)) {
+						sequenceId = dragon_Var_Offset[dragon_var_index_const_7];
+						uVar7 = inventory_old_showing_value;
+						inventory_old_showing_value = _inventory->getType();
+						joined_r0x800271d0:
+						_inventory->setType(inventory_old_showing_value);
+						if (sequenceId == 1) {
+							LAB_800279f4:
+							inventory_old_showing_value = uVar7;
+							FUN_8003130c();
+							actorId = uVar3;
+						}
+						else {
+							_counter = 0;
+							_inventory->setType(1);
+							actor_related_80030e88();
+							joined_r0x80027a38:
+							if (DAT_8006f3a8 == 0) {
+								_cursor->_sequenceID = 1;
+								actorId = uVar3;
+							}
+							else {
+								_cursor->_sequenceID = 5;
+								actorId = uVar3;
+							}
+						}
+						goto LAB_80026a74;
+					}
+					actorId = CheckButtonMapPress_Action(0);
+					uVar6 = _inventory->getType();
+					if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 8) != 0)) {
+						_counter = 0;
+						if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
+							if (_cursor->_iniUnderCursor == 0x8002) {
+								LAB_80027294:
+								uVar7 = 0;
+								if (DAT_8006f3a8 == 0) {
+									if ((bit_flags_8006fbd8 & 3) != 1) {
+										sequenceId = dragon_Var_Offset[dragon_var_index_const_7];
+										uVar7 = inventory_old_showing_value;
+										inventory_old_showing_value = _inventory->getType();
+										goto joined_r0x800271d0;
+									}
+								}
+								else {
+									actorId = 0;
+									do {
+										if (unkArray_uint16[actorId] == 0) break;
+										uVar7 = uVar7 + 1;
+										actorId = (uint)uVar7;
+									} while (uVar7 < 0x29);
+									if (uVar7 < 0x29) {
+										_cursor->_sequenceID = 1;
+										ContinueGame?();
+										uVar6 = DAT_8006f3a8;
+										DAT_8006f3a8 = 0;
+										_cursor->_iniUnderCursor = 0;
+										unkArray_uint16[(uint)uVar7] = uVar6;
+										actorId = uVar3;
+										goto LAB_80026a74;
+									}
+								}
+							}
+							else {
+								if (_cursor->_iniUnderCursor != 0x8001) goto LAB_80027ab4;
+								if (inventorySequenceId == 0) goto LAB_80027294;
+							}
+							if ((_cursor->_iniUnderCursor == 0x8001) && (inventorySequenceId == 1)) {
+								_inventory->setType(2);
+								inventory_old_showing_value = uVar6;
+								FUN_80038890();
+								actorId = uVar3;
+								goto LAB_80026a74;
+							}
+						}
+						LAB_80027ab4:
+						_counter = 0;
+						DAT_80072890 = _cursor->_iniUnderCursor;
+						if (_cursor->_sequenceID < 5) {
+							DATA_800728b0_cursor_seqID = _cursor->_sequenceID;
+							FUN_8002837c();
+							if (bit_flags_8006fbd8 != 0) {
+								engine_flags_maybe = engine_flags_maybe & 0xfffffff7;
+							}
+						}
+						else {
+							DATA_800728b0_cursor_seqID = _cursor->_sequenceID;
+							FUN_8002837c();
+							if (bit_flags_8006fbd8 != 0) {
+								engine_flags_maybe = engine_flags_maybe & 0xfffffff7;
+							}
+							DAT_800728c0 = DAT_80072890;
+							DAT_80072890 = DAT_8006f3a8;
+						}
+					}
+				}
+			}
+			else {
+				if (_inventory->getType() == 2) {
+					actorId = CheckButtonMapPress_InventoryBag(0);
+					uVar6 = _inventory->getType();
+					if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 0x20000400) == 0)) {
+						uVar7 = inventory_old_showing_value;
+						if (dragon_Var_Offset[dragon_var_index_const_7] == 1) goto LAB_800279f4;
+						_counter = 0;
+						_inventory->setType(1);
+						inventory_old_showing_value = uVar6;
+						actor_related_80030e88();
+						goto joined_r0x80027a38;
+					}
+					actorId = CheckButtonMapPress_Action(0);
+					if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 8) != 0)) goto LAB_80027ab4;
+				}
+			}
+			LAB_80027b58:
+			run_ini_scripts();
+			actorId = uVar3;
+			goto LAB_80026a74;
+		}
+		actorId = CheckButtonMapPress_InventoryBag(0);
+		if ((actorId & 0xffff) != 0) {
+			_counter = 0;
+			LAB_80027970:
+			FUN_80031480();
+			uVar6 = inventory_old_showing_value;
+			inventory_old_showing_value = _inventory->getType();
+			actorId = uVar3;
+			_inventory->setType(uVar6);
+			goto LAB_80026a74;
+		}
+		actorId = CheckButtonMapPress_Action(0);
+		uVar6 = _inventory->getType();
+		if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 8) != 0)) {
+			_counter = 0;
+			if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
+				if (_cursor->_iniUnderCursor == 0x8001) {
+					FUN_80031480();
+					_inventory->setType(0);
+					if (inventory_old_showing_value == 2) {
+						FUN_80038994();
+					}
+				}
+				else {
+					if (_cursor->_iniUnderCursor != 0x8002) goto LAB_8002790c;
+					FUN_80031480();
+					_inventory->setType(2);
+					if (inventory_old_showing_value != 2) {
+						FUN_80038890();
+					}
+				}
+				inventory_old_showing_value = uVar6;
+				actorId = uVar3;
+				goto LAB_80026a74;
+			}
+			if (_cursor->_iniUnderCursor != 0) {
+				actorId_00 = 0;
+				if ((_cursor->_sequenceID != 4) && (_cursor->_sequenceID != 2)) {
+					DATA_800728b0_cursor_seqID = _cursor->_sequenceID;
+					DAT_80072890 = _cursor->_iniUnderCursor;
+					if (4 < _cursor->_sequenceID) {
+						DAT_80072890 = DAT_8006f3a8;
+						DAT_800728c0 = _cursor->_iniUnderCursor;
+					}
+					engine_flags_maybe = engine_flags_maybe & 0xfffffff7;
+					FUN_8002837c();
+					goto LAB_8002790c;
+				}
+				if (_cursor->_iniUnderCursor != unkArray_uint16[0]) {
+					actorId = 1;
+					do {
+						actorId_00 = actorId;
+						actorId = actorId_00 + 1;
+					} while (_cursor->_iniUnderCursor != unkArray_uint16[actorId_00 & 0xffff]);
+				}
+				puVar9 = unkArray_uint16 + (actorId_00 & 0xffff);
+				iVar5 = (actorId_00 & 0xffff) + 0x17;
+				*puVar9 = DAT_8006f3a8;
+				DAT_8007283c = actors[iVar5]._sequenceID;
+				actors[iVar5].flags = actors[iVar5].flags & 0xffbf;
+				DAT_8006f3a8 = _cursor->_iniUnderCursor;
+				_cursor->_sequenceID = 5;
+				actorId = uVar3;
+				if (*puVar9 != 0) {
+					actorId = actorId_00 + 0x17 & 0xffff;
+					actors[actorId].flags = 0;
+					actors[actorId].priorityLayer_maybe = 0;
+					actors[actorId].field_0xe = 0x100;
+					actor_update_sequenceID
+							(actorId,dragon_ini_pointer[(uint)*puVar9 - 1].field_1a_flags_maybe * 2 + 10);
+					actors[actorId].flags = actors[actorId].flags | 0x3c0;
+					actors[actorId].priorityLayer_maybe = 6;
+					actorId = uVar3;
+				}
+				goto LAB_80026a74;
+			}
+			uVar6 = 0;
+			if (DAT_8006f3a8 == 0) goto LAB_80027b58;
+			actorId = 0;
+			do {
+				iVar5 = actorId + 0x17;
+				if (((((int)(short)actors[iVar5].x_pos + -0x10 <= (int)cursor_x_var) &&
+					  ((int)cursor_x_var < (int)(short)actors[iVar5].x_pos + 0x10)) &&
+					 ((int)(short)actors[iVar5].y_pos + -0xc <= (int)cursor_y_var)) &&
+					(actorId = (uint)uVar6, (int)cursor_y_var < (int)(short)actors[iVar5].y_pos + 0xc)) break;
+				uVar6 = uVar6 + 1;
+				actorId = (uint)uVar6;
+			} while (uVar6 < 0x29);
+			if (actorId != 0x29) {
+				actorId_00 = (uint)(ushort)(uVar6 + 0x17);
+				unkArray_uint16[actorId] = DAT_8006f3a8;
+				actors[actorId_00].flags = 0;
+				actors[actorId_00].priorityLayer_maybe = 0;
+				actors[actorId_00].field_0xe = 0x100;
+				DAT_8006f3a8 = 0;
+				actor_update_sequenceID
+						(actorId_00,
+						 dragon_ini_pointer[(uint)unkArray_uint16[actorId] - 1].field_1a_flags_maybe * 2 +
+						 10);
+				uVar6 = _cursor->_sequenceID;
+				actors[actorId_00].flags = actors[actorId_00].flags | 0x3c0;
+				actors[actorId_00].priorityLayer_maybe = 6;
+				if (uVar6 == 5) {
+					_cursor->_sequenceID = 4;
+				}
+			}
+		}
+		LAB_8002790c:
+		if ((DAT_8006f3a8 == 0) ||
+			(((ushort)(cursor_x_var - 10U) < 300 && ((ushort)(cursor_y_var - 10U) < 0xb4))))
+			goto LAB_80027b58;
+		_cursor->_sequenceID = 5;
+		delayFunction(2);
+		goto LAB_80027970;
+	}
+	 **/
+}
+
+
 void DragonsEngine::updateHandler() {
 	data_8006a3a0_flag |= 0x40;
 	//TODO logic here
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 7a1d1d36c6..e0c46f9390 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -64,6 +64,7 @@ enum Flags {
 	ENGINE_FLAG_80 = 0x80,
 	ENGINE_FLAG_100 = 0x100,
 	ENGINE_FLAG_200 = 0x200,
+	ENGINE_FLAG_400 = 0x400,
 
 	ENGINE_FLAG_TEXT_ENABLED = 0x1000,
 	ENGINE_FLAG_10000    =    0x10000,
@@ -71,6 +72,7 @@ enum Flags {
 	ENGINE_FLAG_100000   =   0x100000,
 	ENGINE_FLAG_400000   =   0x400000,
 	ENGINE_FLAG_4000000  =  0x4000000,
+	ENGINE_FLAG_20000000 = 0x20000000,
 	ENGINE_FLAG_80000000 = 0x80000000
 };
 
@@ -110,7 +112,6 @@ public:
 	ActorManager *_actorManager;
 	DragonINIResource *_dragonINIResource;
 	ScriptOpcodes *_scriptOpcodes;
-	uint16 _cursorSequenceID;
 	Scene *_scene;
 	uint16 data_800633fa;
 	Inventory *_inventory;
@@ -131,11 +132,13 @@ private:
 	uint32 _counter;
 	uint32 bit_flags_8006fbd8;
 	uint16 data_8006a3a0_flag; // screen related flags?
+	int16 _data_either_5_or_0;
 	//unk
 
 	uint16 run_func_ptr_unk_countdown_timer;
 
 	// input
+	bool _leftMouseButtonUp;
 	bool _rightMouseButtonUp;
 
 public:
@@ -174,6 +177,7 @@ public:
 
 private:
 	void gameLoop();
+	void game_loop();
 	void updateHandler();
 	void updatePathfindingActors();
 	uint32 calulateTimeLeft();
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 92b17f5e24..db3c10a003 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -49,6 +49,8 @@ public:
 	}
 
 	int16 getType() { return _type; }
+	void setType(int16 newType) { _type = newType; }
+
 	int16 getPositionIndex() { return _screenPositionIndex; }
 	Common::Point getPosition();
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 717713665e..3604626410 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -20,6 +20,7 @@
  *
  */
 
+#include "dragons/cursor.h"
 #include "dragons/dragons.h"
 #include "dragons/dragonflg.h"
 #include "dragons/dragonini.h"
@@ -123,7 +124,7 @@ void SpecialOpcodes::spcSetEngineFlag0x4000000() {
 }
 
 void SpecialOpcodes::spcSetCursorSequenceIdToZero() {
-	_vm->_cursorSequenceID = 0;
+	_vm->_cursor->_sequenceID = 0;
 }
 
 } // End of namespace Dragons


Commit: 2eac8db4807ac4377f6cf9a4f6f8992c1ab4641b
    https://github.com/scummvm/scummvm/commit/2eac8db4807ac4377f6cf9a4f6f8992c1ab4641b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added original game loop logic

Changed paths:
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h


diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 6224469e6f..c5680dfb11 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -37,15 +37,15 @@ public:
 	int16 data_800728b0_cursor_seqID;
 	uint16 _iniUnderCursor;
 	int32 _sequenceID;
-private:
-	DragonsEngine *_vm;
+	int16 data_80072890;
 	int16 _x;
 	int16 _y;
+	int16 data_8007283c;
+private:
+	DragonsEngine *_vm;
 	Actor *_actor;
 
 	int16 data_either_5_or_0;
-	int16 data_8007283c;
-	int16 data_80072890;
 
 public:
 	Cursor(DragonsEngine *vm);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 499fc5fd87..c6b85d834c 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -72,6 +72,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
+	_iKeyUp = false;
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -83,6 +84,7 @@ void DragonsEngine::updateEvents() {
 	Common::Event event;
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
+	_iKeyUp = false;
 	while (_eventMan->pollEvent(event)) {
 //		_input->processEvent(event);
 		switch (event.type) {
@@ -98,6 +100,10 @@ void DragonsEngine::updateEvents() {
 			case Common::EVENT_RBUTTONUP:
 				_rightMouseButtonUp = true;
 				break;
+			case Common::EVENT_KEYUP:
+				if (event.kbd.keycode == Common::KeyCode::KEYCODE_i) {
+					_iKeyUp = true;
+				}
 			default:
 				break;
 		}
@@ -148,7 +154,8 @@ Common::Error DragonsEngine::run() {
 	return Common::kNoError;
 }
 
-void DragonsEngine::gameLoop() {
+// Not used any more.....
+void DragonsEngine::gameLoopOld() {
 	_counter = 0;
 	bit_flags_8006fbd8 = 0;
 	while (!shouldQuit()) {
@@ -216,16 +223,30 @@ void DragonsEngine::gameLoop() {
 	}
 }
 
+uint16 DragonsEngine::ipt_img_file_related()
+{
+	DragonINI *ini;
+    DragonINI *flicker = _dragonINIResource->getFlickerRecord();
+	assert(flicker);
 
+	int16 tileX = flicker->actor->x_pos / 32;
+	int16 tileY = flicker->actor->y_pos / 8;
 
-/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */
-
-void DragonsEngine::game_loop()
+	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
+		ini = getINI(i);
+		if ((ini->sceneId == getCurrentSceneId()) && (ini->field_1a_flags_maybe == 0)) {
+			IMG *img = _dragonIMG->getIMG(ini->field_2);
+			if ((img->x <= tileX) && (((tileX <= img->x + img->w && (img->y <= tileY)) && (tileY <= img->y + img->h)))) {
+				return i + 1;
+			}
+		}
+	}
+	return 0;
+}
 
+void DragonsEngine::gameLoop()
 {
-	/**
 	bool bVar1;
-	DragonINI *pDVar2;
 	uint uVar3;
 	uint32_t uVar4;
 	uint actorId;
@@ -247,15 +268,19 @@ void DragonsEngine::game_loop()
 
 	while(!shouldQuit()) {
 		LAB_80026a74:
+		_scene->draw();
+		_screen->updateScreen();
 		wait();
-		pDVar2 = dragon_ini_pointer;
-		iVar5 = data_80063940_const_c3_maybe;
-		if ((uint)currentSceneId != _const_value_2) {
-			sceneId_1 = currentSceneId;
+		updateHandler();
+		updateEvents();
+
+		if (getCurrentSceneId() != 2) {
+			_sceneId1 = getCurrentSceneId();
 		}
+
 		_counter++;
 		if (0x4af < _counter) {
-			pDVar8 = _dragonINIResource->getFlickerRecord(); //dragon_ini_pointer + (uint)dragon_ini_maybe_flicker_control;
+			pDVar8 = _dragonINIResource->getFlickerRecord();
 			if (pDVar8->actor->resourceID == 0xe) {
 				pDVar8->actor->_sequenceID2 = 2;
 				pDVar8->field_20_actor_field_14 = 2;
@@ -278,107 +303,91 @@ void DragonsEngine::game_loop()
 		if (bit_flags_8006fbd8 == 0) {
 			setFlags(ENGINE_FLAG_8);
 		}
-		if (dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].sceneId_maybe == currentSceneId) {
+		if (_dragonINIResource->getFlickerRecord()->sceneId == getCurrentSceneId()) {
 			uVar3 = ipt_img_file_related();
 			actorId_00 = uVar3 & 0xffff;
 			if (actorId_00 == 0) goto LAB_80026d34;
 			if (actorId_00 != (actorId & 0xffff)) {
-				buffer = (void *)((int)dragon_Obd_Offset + dragon_Opt_Offset[actorId_00 - 1].obdOffset);
-				local_30.code = (void *)((int)buffer + 8);
-				uVar4 = read_int32(buffer);
-				local_30.codeEnd = (void *)(uVar4 + (int)local_30.code);
-				actorId = run_script_field8_eq_4(&local_30);
-				if ((actorId & 0xffff) != 0) {
-					local_30.codeEnd =
-							(void *)((uint)*(ushort *)((int)local_30.code + 2) +
-									 (int)(void *)((int)local_30.code + 4));
-					local_30.code = (void *)((int)local_30.code + 4);
-					run_script(&local_30);
-					_counter = 0;
-				}
+				//TODO implement this
+				error("actorId_00 != (actorId & 0xffff)");
+//				buffer = (void *)((int)dragon_Obd_Offset + dragon_Opt_Offset[actorId_00 - 1].obdOffset);
+//				local_30.code = (void *)((int)buffer + 8);
+//				uVar4 = read_int32(buffer);
+//				local_30.codeEnd = (void *)(uVar4 + (int)local_30.code);
+//				actorId = run_script_field8_eq_4(&local_30);
+//				if ((actorId & 0xffff) != 0) {
+//					local_30.codeEnd =
+//							(void *)((uint)*(ushort *)((int)local_30.code + 2) +
+//									 (int)(void *)((int)local_30.code + 4));
+//					local_30.code = (void *)((int)local_30.code + 4);
+//					run_script(&local_30);
+//					_counter = 0;
+//				}
 			}
 		}
 		else {
 			LAB_80026d34:
 			uVar3 = 0;
 		}
-		actorId = updateINIUnderCursor();
-		if (((actorId & 0xffff) == 0) ||
-			((dragon_ini_pointer[(uint)_cursor->_iniUnderCursor].actorId & 0x4000) != 0)) {
+		if (_cursor->updateINIUnderCursor() == 0 ||
+			(getINI(_cursor->_iniUnderCursor)->actor && (getINI(_cursor->_iniUnderCursor)->actor->_actorID & 0x4000) != 0)) { //TODO check this. This logic looks a bit strange.
 			_data_either_5_or_0 = 0;
 		}
 		else {
 			_data_either_5_or_0 = 5;
 		}
-		actorId = CheckButtonMapPress_CycleDown(0);
-		if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 0x20000400) == 0)) {
-			uVar6 = _cursor->_sequenceID - 1;
-			if ((uVar6 == 0) && ((_inventory->getType() == 1 || (_inventory->getType() == 2)))) {
-				uVar6 = _cursor->_sequenceID - 2;
-			}
-			_cursor->_sequenceID = uVar6;
-			if ((_cursor->_sequenceID == 3) && (_inventory->getType() == 1)) {
-				_cursor->_sequenceID = 1;
-			}
-			if (_cursor->_sequenceID == 2) {
-				_cursor->_sequenceID = 1;
-			}
-			if (_cursor->_sequenceID == 0xffff) {
-				uVar6 = 5;
-				if (DAT_8006f3a8 == 0) {
-					uVar6 = 4;
-				}
-				LAB_80026fb0:
-				_cursor->_sequenceID = uVar6;
-			}
-			_counter = 0;
-			actorId = uVar3;
-			continue;
-		}
-		actorId = CheckButtonMapPress_CycleUp(0);
-		if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 0x20000400) == 0)) {
-			_cursor->_sequenceID = _cursor->_sequenceID + 1;
-			if (DAT_8006f3a8 == 0) {
-				bVar1 = _cursor->_sequenceID < 5;
-			}
-			else {
-				bVar1 = _cursor->_sequenceID < 6;
-			}
-			if (!bVar1) {
-				_cursor->_sequenceID = 0;
-			}
-			if ((_cursor->_sequenceID == 0) && ((_inventory->getType() == 1 || (_inventory->getType() == 2)))) {
-				_cursor->_sequenceID = 1;
-			}
-			if (_cursor->_sequenceID == 2) {
-				if (_inventory->getType() == 1) {
-					_cursor->_sequenceID = 4;
-				}
-				uVar6 = 3;
-				if (_cursor->_sequenceID == 2) goto LAB_80026fb0;
-			}
+
+		if (_rightMouseButtonUp && isInputEnabled()) {
+			_cursor->selectPreviousCursor();
 			_counter = 0;
 			actorId = uVar3;
 			continue;
 		}
+		// TODO implement cycle cursor up.
+//		actorId = CheckButtonMapPress_CycleUp(0);
+//		if (((actorId & 0xffff) != 0) && isInputEnabled()) {
+//			_cursor->_sequenceID = _cursor->_sequenceID + 1;
+//			if (data_8006f3a8 == 0) {
+//				bVar1 = _cursor->_sequenceID < 5;
+//			}
+//			else {
+//				bVar1 = _cursor->_sequenceID < 6;
+//			}
+//			if (!bVar1) {
+//				_cursor->_sequenceID = 0;
+//			}
+//			if ((_cursor->_sequenceID == 0) && ((_inventory->getType() == 1 || (_inventory->getType() == 2)))) {
+//				_cursor->_sequenceID = 1;
+//			}
+//			if (_cursor->_sequenceID == 2) {
+//				if (_inventory->getType() == 1) {
+//					_cursor->_sequenceID = 4;
+//				}
+//				uVar6 = 3;
+//				if (_cursor->_sequenceID == 2) goto LAB_80026fb0;
+//			}
+//			_counter = 0;
+//			actorId = uVar3;
+//			continue;
+//		}
+
 		if (bit_flags_8006fbd8 == 3) {
 			bit_flags_8006fbd8 = 0;
-			if ((dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].sceneId_maybe == currentSceneId)
-				&& (actorId = (uint)dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].actorId,
-					actors[actorId]._sequenceID2 != 0xffff)) {
-				uVar6 = DAT_800728c0;
+			DragonINI *flicker = _dragonINIResource->getFlickerRecord();
+			if (flicker->sceneId == getCurrentSceneId() && flicker->actor->_sequenceID2 != -1) {
+				uVar6 = _scriptOpcodes->_data_800728c0;
 				if (_cursor->_sequenceID != 5) {
-					uVar6 = DAT_80072890;
+					uVar6 = _cursor->data_80072890;
 				}
-				actors[actorId]._sequenceID2 = dragon_ini_pointer[(uint)uVar6 - 1].field_0x20;
+				flicker->actor->_sequenceID2 = getINI(uVar6 - 1)->field_20_actor_field_14;
 			}
+
 			works_with_obd_data_1();
-			if (((uint)currentSceneId == DAT_80063a70) && (dragon_ini_pointer[DAT_80063b0c].field_0x2 != 0))
+			if ((getCurrentSceneId() == 0x1d) && (getINI(0x179)->field_2 != 0))
 			{
-				engine_flags_maybe = engine_flags_maybe & 0xfffffff7;
-			}
-			else {
-				engine_flags_maybe = engine_flags_maybe | 8;
+				clearFlags(ENGINE_FLAG_8);
+			} else {
+				setFlags(ENGINE_FLAG_8);
 			}
 			_counter = 0;
 			actorId = uVar3;
@@ -387,17 +396,16 @@ void DragonsEngine::game_loop()
 		if (_inventory->getType() != 1) {
 			if (_inventory->getType() < 2) {
 				if (_inventory->getType() == 0) {
-					actorId = CheckButtonMapPress_InventoryBag(0);
-					if ((((actorId & 0xffff) != 0) && ((engine_flags_maybe & 0x20000400) == 0)) &&
+					if ((checkForInventoryButtonRelease() && isInputEnabled()) &&
 						((bit_flags_8006fbd8 & 3) != 1)) {
-						sequenceId = dragon_Var_Offset[dragon_var_index_const_7];
-						uVar7 = inventory_old_showing_value;
-						inventory_old_showing_value = _inventory->getType();
+						sequenceId = _dragonVAR->getVar(7);
+						uVar7 = _inventory->_old_showing_value;
+						_inventory->_old_showing_value = _inventory->getType();
 						joined_r0x800271d0:
-						_inventory->setType(inventory_old_showing_value);
+						_inventory->setType(_inventory->_old_showing_value);
 						if (sequenceId == 1) {
 							LAB_800279f4:
-							inventory_old_showing_value = uVar7;
+							_inventory->_old_showing_value = uVar7;
 							FUN_8003130c();
 							actorId = uVar3;
 						}
@@ -406,7 +414,7 @@ void DragonsEngine::game_loop()
 							_inventory->setType(1);
 							actor_related_80030e88();
 							joined_r0x80027a38:
-							if (DAT_8006f3a8 == 0) {
+							if (data_8006f3a8 == 0) {
 								_cursor->_sequenceID = 1;
 								actorId = uVar3;
 							}
@@ -417,19 +425,18 @@ void DragonsEngine::game_loop()
 						}
 						goto LAB_80026a74;
 					}
-					actorId = CheckButtonMapPress_Action(0);
 					uVar6 = _inventory->getType();
-					if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 8) != 0)) {
+					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
 						_counter = 0;
 						if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
 							if (_cursor->_iniUnderCursor == 0x8002) {
 								LAB_80027294:
 								uVar7 = 0;
-								if (DAT_8006f3a8 == 0) {
+								if (data_8006f3a8 == 0) {
 									if ((bit_flags_8006fbd8 & 3) != 1) {
-										sequenceId = dragon_Var_Offset[dragon_var_index_const_7];
-										uVar7 = inventory_old_showing_value;
-										inventory_old_showing_value = _inventory->getType();
+										sequenceId = _dragonVAR->getVar(7);
+										uVar7 = _inventory->_old_showing_value;
+										_inventory->_old_showing_value = _inventory->getType();
 										goto joined_r0x800271d0;
 									}
 								}
@@ -442,9 +449,9 @@ void DragonsEngine::game_loop()
 									} while (uVar7 < 0x29);
 									if (uVar7 < 0x29) {
 										_cursor->_sequenceID = 1;
-										ContinueGame?();
-										uVar6 = DAT_8006f3a8;
-										DAT_8006f3a8 = 0;
+										waitForFrames(1);
+										uVar6 = data_8006f3a8;
+										data_8006f3a8 = 0;
 										_cursor->_iniUnderCursor = 0;
 										unkArray_uint16[(uint)uVar7] = uVar6;
 										actorId = uVar3;
@@ -454,11 +461,11 @@ void DragonsEngine::game_loop()
 							}
 							else {
 								if (_cursor->_iniUnderCursor != 0x8001) goto LAB_80027ab4;
-								if (inventorySequenceId == 0) goto LAB_80027294;
+								if (_inventory->getSequenceId() == 0) goto LAB_80027294;
 							}
-							if ((_cursor->_iniUnderCursor == 0x8001) && (inventorySequenceId == 1)) {
+							if ((_cursor->_iniUnderCursor == 0x8001) && (_inventory->getSequenceId() == 1)) {
 								_inventory->setType(2);
-								inventory_old_showing_value = uVar6;
+								_inventory->_old_showing_value = uVar6;
 								FUN_80038890();
 								actorId = uVar3;
 								goto LAB_80026a74;
@@ -466,68 +473,64 @@ void DragonsEngine::game_loop()
 						}
 						LAB_80027ab4:
 						_counter = 0;
-						DAT_80072890 = _cursor->_iniUnderCursor;
+						_cursor->data_80072890 = _cursor->_iniUnderCursor;
 						if (_cursor->_sequenceID < 5) {
-							DATA_800728b0_cursor_seqID = _cursor->_sequenceID;
+							_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
 							FUN_8002837c();
 							if (bit_flags_8006fbd8 != 0) {
-								engine_flags_maybe = engine_flags_maybe & 0xfffffff7;
+								clearFlags(ENGINE_FLAG_8);
 							}
 						}
 						else {
-							DATA_800728b0_cursor_seqID = _cursor->_sequenceID;
+							_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
 							FUN_8002837c();
 							if (bit_flags_8006fbd8 != 0) {
-								engine_flags_maybe = engine_flags_maybe & 0xfffffff7;
+								clearFlags(ENGINE_FLAG_8);
 							}
-							DAT_800728c0 = DAT_80072890;
-							DAT_80072890 = DAT_8006f3a8;
+							_scriptOpcodes->_data_800728c0 = _cursor->data_80072890;
+							_cursor->data_80072890 = data_8006f3a8;
 						}
 					}
 				}
 			}
 			else {
 				if (_inventory->getType() == 2) {
-					actorId = CheckButtonMapPress_InventoryBag(0);
 					uVar6 = _inventory->getType();
-					if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 0x20000400) == 0)) {
-						uVar7 = inventory_old_showing_value;
-						if (dragon_Var_Offset[dragon_var_index_const_7] == 1) goto LAB_800279f4;
+					if (checkForInventoryButtonRelease() && isInputEnabled()) {
+						uVar7 = _inventory->_old_showing_value;
+						if (_dragonVAR->getVar(7) == 1) goto LAB_800279f4;
 						_counter = 0;
 						_inventory->setType(1);
-						inventory_old_showing_value = uVar6;
+						_inventory->_old_showing_value = uVar6;
 						actor_related_80030e88();
 						goto joined_r0x80027a38;
 					}
-					actorId = CheckButtonMapPress_Action(0);
-					if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 8) != 0)) goto LAB_80027ab4;
+					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) goto LAB_80027ab4;
 				}
 			}
 			LAB_80027b58:
-			run_ini_scripts();
+			runINIScripts();
 			actorId = uVar3;
 			goto LAB_80026a74;
 		}
-		actorId = CheckButtonMapPress_InventoryBag(0);
-		if ((actorId & 0xffff) != 0) {
+		if (checkForInventoryButtonRelease()) {
 			_counter = 0;
 			LAB_80027970:
 			FUN_80031480();
-			uVar6 = inventory_old_showing_value;
-			inventory_old_showing_value = _inventory->getType();
+			uVar6 = _inventory->_old_showing_value;
+			_inventory->_old_showing_value = _inventory->getType();
 			actorId = uVar3;
 			_inventory->setType(uVar6);
 			goto LAB_80026a74;
 		}
-		actorId = CheckButtonMapPress_Action(0);
 		uVar6 = _inventory->getType();
-		if (((actorId & 0xffff) != 0) && ((engine_flags_maybe & 8) != 0)) {
+		if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
 			_counter = 0;
 			if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
 				if (_cursor->_iniUnderCursor == 0x8001) {
 					FUN_80031480();
 					_inventory->setType(0);
-					if (inventory_old_showing_value == 2) {
+					if (_inventory->_old_showing_value == 2) {
 						FUN_80038994();
 					}
 				}
@@ -535,24 +538,24 @@ void DragonsEngine::game_loop()
 					if (_cursor->_iniUnderCursor != 0x8002) goto LAB_8002790c;
 					FUN_80031480();
 					_inventory->setType(2);
-					if (inventory_old_showing_value != 2) {
+					if (_inventory->_old_showing_value != 2) {
 						FUN_80038890();
 					}
 				}
-				inventory_old_showing_value = uVar6;
+				_inventory->_old_showing_value = uVar6;
 				actorId = uVar3;
 				goto LAB_80026a74;
 			}
 			if (_cursor->_iniUnderCursor != 0) {
 				actorId_00 = 0;
 				if ((_cursor->_sequenceID != 4) && (_cursor->_sequenceID != 2)) {
-					DATA_800728b0_cursor_seqID = _cursor->_sequenceID;
-					DAT_80072890 = _cursor->_iniUnderCursor;
+					_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
+					_cursor->data_80072890 = _cursor->_iniUnderCursor;
 					if (4 < _cursor->_sequenceID) {
-						DAT_80072890 = DAT_8006f3a8;
-						DAT_800728c0 = _cursor->_iniUnderCursor;
+						_cursor->data_80072890 = data_8006f3a8;
+						_scriptOpcodes->_data_800728c0 = _cursor->_iniUnderCursor;
 					}
-					engine_flags_maybe = engine_flags_maybe & 0xfffffff7;
+					clearFlags(ENGINE_FLAG_8);
 					FUN_8002837c();
 					goto LAB_8002790c;
 				}
@@ -564,66 +567,69 @@ void DragonsEngine::game_loop()
 					} while (_cursor->_iniUnderCursor != unkArray_uint16[actorId_00 & 0xffff]);
 				}
 				puVar9 = unkArray_uint16 + (actorId_00 & 0xffff);
-				iVar5 = (actorId_00 & 0xffff) + 0x17;
-				*puVar9 = DAT_8006f3a8;
-				DAT_8007283c = actors[iVar5]._sequenceID;
-				actors[iVar5].flags = actors[iVar5].flags & 0xffbf;
-				DAT_8006f3a8 = _cursor->_iniUnderCursor;
+				Actor *actor = _actorManager->getActor(actorId_00 + 0x17);
+				*puVar9 = data_8006f3a8;
+				_cursor->data_8007283c = actor->_sequenceID;
+				actor->clearFlag(ACTOR_FLAG_40);
+				data_8006f3a8 = _cursor->_iniUnderCursor;
 				_cursor->_sequenceID = 5;
 				actorId = uVar3;
 				if (*puVar9 != 0) {
 					actorId = actorId_00 + 0x17 & 0xffff;
-					actors[actorId].flags = 0;
-					actors[actorId].priorityLayer_maybe = 0;
-					actors[actorId].field_0xe = 0x100;
-					actor_update_sequenceID
-							(actorId,dragon_ini_pointer[(uint)*puVar9 - 1].field_1a_flags_maybe * 2 + 10);
-					actors[actorId].flags = actors[actorId].flags | 0x3c0;
-					actors[actorId].priorityLayer_maybe = 6;
+					actor->flags = 0;
+					actor->priorityLayer = 0;
+					actor->field_e = 0x100;
+					actor->updateSequence(getINI((uint)*puVar9 - 1)->field_1a_flags_maybe * 2 + 10);
+					actor->setFlag(ACTOR_FLAG_40);
+					actor->setFlag(ACTOR_FLAG_80);
+					actor->setFlag(ACTOR_FLAG_100);
+					actor->setFlag(ACTOR_FLAG_200);
+					actor->priorityLayer = 6;
 					actorId = uVar3;
 				}
 				goto LAB_80026a74;
 			}
 			uVar6 = 0;
-			if (DAT_8006f3a8 == 0) goto LAB_80027b58;
+			if (data_8006f3a8 == 0) goto LAB_80027b58;
 			actorId = 0;
 			do {
-				iVar5 = actorId + 0x17;
-				if (((((int)(short)actors[iVar5].x_pos + -0x10 <= (int)cursor_x_var) &&
-					  ((int)cursor_x_var < (int)(short)actors[iVar5].x_pos + 0x10)) &&
-					 ((int)(short)actors[iVar5].y_pos + -0xc <= (int)cursor_y_var)) &&
-					(actorId = (uint)uVar6, (int)cursor_y_var < (int)(short)actors[iVar5].y_pos + 0xc)) break;
+				Actor *actor = _actorManager->getActor(actorId + 0x17);
+				if (((((int)(short)actor->x_pos + -0x10 <= (int)_cursor->_x) &&
+					  ((int)_cursor->_x < (int)(short)actor->x_pos + 0x10)) &&
+					 ((int)(short)actor->y_pos + -0xc <= (int)_cursor->_y)) &&
+					(actorId = (uint)uVar6, (int)_cursor->_y < (int)(short)actor->y_pos + 0xc)) break;
 				uVar6 = uVar6 + 1;
 				actorId = (uint)uVar6;
 			} while (uVar6 < 0x29);
 			if (actorId != 0x29) {
 				actorId_00 = (uint)(ushort)(uVar6 + 0x17);
-				unkArray_uint16[actorId] = DAT_8006f3a8;
-				actors[actorId_00].flags = 0;
-				actors[actorId_00].priorityLayer_maybe = 0;
-				actors[actorId_00].field_0xe = 0x100;
-				DAT_8006f3a8 = 0;
-				actor_update_sequenceID
-						(actorId_00,
-						 dragon_ini_pointer[(uint)unkArray_uint16[actorId] - 1].field_1a_flags_maybe * 2 +
-						 10);
+				unkArray_uint16[actorId] = data_8006f3a8;
+				Actor *actor = _actorManager->getActor(actorId_00);
+				actor->flags = 0;
+				actor->priorityLayer = 0;
+				actor->field_e = 0x100;
+				data_8006f3a8 = 0;
+				actor->updateSequence(
+						 getINI((uint)unkArray_uint16[actorId] - 1)->field_1a_flags_maybe * 2 + 10);
 				uVar6 = _cursor->_sequenceID;
-				actors[actorId_00].flags = actors[actorId_00].flags | 0x3c0;
-				actors[actorId_00].priorityLayer_maybe = 6;
+				actor->setFlag(ACTOR_FLAG_40);
+				actor->setFlag(ACTOR_FLAG_80);
+				actor->setFlag(ACTOR_FLAG_100);
+				actor->setFlag(ACTOR_FLAG_200);
+				actor->priorityLayer = 6;
 				if (uVar6 == 5) {
 					_cursor->_sequenceID = 4;
 				}
 			}
 		}
 		LAB_8002790c:
-		if ((DAT_8006f3a8 == 0) ||
-			(((ushort)(cursor_x_var - 10U) < 300 && ((ushort)(cursor_y_var - 10U) < 0xb4))))
+		if ((data_8006f3a8 == 0) ||
+			(((ushort)(_cursor->_x - 10U) < 300 && ((ushort)(_cursor->_y - 10U) < 0xb4))))
 			goto LAB_80027b58;
 		_cursor->_sequenceID = 5;
-		delayFunction(2);
+		waitForFrames(2);
 		goto LAB_80027970;
 	}
-	 **/
 }
 
 
@@ -964,4 +970,44 @@ void DragonsEngine::call_fade_related_1f() {
 	fade_related(0x1f);
 }
 
+void DragonsEngine::works_with_obd_data_1() {
+	error("works_with_obd_data_1");
+}
+
+bool DragonsEngine::checkForInventoryButtonRelease() {
+	return _iKeyUp;
+}
+
+bool DragonsEngine::isInputEnabled() {
+	return !isFlagSet(ENGINE_FLAG_20000000) && !isFlagSet(ENGINE_FLAG_400);
+}
+
+bool DragonsEngine::checkForActionButtonRelease() {
+	return _leftMouseButtonUp;
+}
+
+void DragonsEngine::FUN_8003130c() {
+	error("FUN_8003130c"); //TODO
+}
+
+void DragonsEngine::actor_related_80030e88() {
+	error("actor_related_80030e88"); //TODO
+}
+
+void DragonsEngine::FUN_80038890() {
+	error("FUN_80038890"); //TODO
+}
+
+void DragonsEngine::FUN_8002837c() {
+	error("FUN_8002837c"); //TODO
+}
+
+void DragonsEngine::FUN_80031480() {
+	error("FUN_80031480"); //TODO
+}
+
+void DragonsEngine::FUN_80038994() {
+	error("FUN_80038994"); //TODO
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index e0c46f9390..1b5967fccd 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -117,6 +117,9 @@ public:
 	Inventory *_inventory;
 	Cursor *_cursor;
 	uint16 data_8006f3a8;
+
+	uint16 unkArray_uint16[42];
+
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
@@ -140,6 +143,7 @@ private:
 	// input
 	bool _leftMouseButtonUp;
 	bool _rightMouseButtonUp;
+	bool _iKeyUp;
 
 public:
 	DragonsEngine(OSystem *syst);
@@ -175,9 +179,11 @@ public:
 	void call_fade_related_1f();
 	void fade_related(uint32 flags);
 
+	uint16 ipt_img_file_related();
+
 private:
+	void gameLoopOld();
 	void gameLoop();
-	void game_loop();
 	void updateHandler();
 	void updatePathfindingActors();
 	uint32 calulateTimeLeft();
@@ -186,6 +192,19 @@ private:
 	uint16 updateINIUnderCursor();
 	void runINIScripts();
 	void engineFlag0x20UpdateFunction();
+
+	void works_with_obd_data_1();
+
+	bool isInputEnabled();
+	bool checkForInventoryButtonRelease();
+	bool checkForActionButtonRelease();
+
+	void FUN_8003130c();
+	void actor_related_80030e88();
+	void FUN_80038890();
+	void FUN_8002837c();
+	void FUN_80031480();
+	void FUN_80038994();
 };
 
 DragonsEngine *getEngine();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 91e3ade824..451aadb73f 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -38,6 +38,7 @@ Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 	_type = 0;
 	_sequenceId = 0;
 	_screenPositionIndex = 0;
+	_old_showing_value = 0;
 }
 
 void Inventory::init(ActorManager *actorManager) {
@@ -52,6 +53,7 @@ void Inventory::init(ActorManager *actorManager) {
 						 Dragons::ACTOR_FLAG_200);
 	_sequenceId = 0;
 	_type = 0;
+	_old_showing_value = 0;
 }
 
 
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index db3c10a003..c92552e4ad 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -31,6 +31,8 @@ class Actor;
 class ActorManager;
 
 class Inventory {
+public:
+	int16 _old_showing_value;
 private:
 	DragonsEngine *_vm;
 	int32 _sequenceId;


Commit: 64ff1a2b466ca18e7639a1818af7acb63c6c35fb
    https://github.com/scummvm/scummvm/commit/64ff1a2b466ca18e7639a1818af7acb63c6c35fb
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: implement click action logic

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 0c65451e4a..7297c60815 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -188,7 +188,8 @@ int16 Cursor::updateINIUnderCursor() {
 int16 Cursor::updateIniFromScene() {
 	int16 cursorTileX = _actor->x_pos / 32;
 	int16 cursorTileY = _actor->y_pos / 8;
-
+	int16 data_80072890_orig = data_80072890;
+	int16 data_800728b0_cursor_seqID_orig = data_800728b0_cursor_seqID;
 	for(int i=0;i <_vm->_dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId != _vm->_scene->getSceneId()) {
@@ -249,8 +250,8 @@ int16 Cursor::updateIniFromScene() {
 				}
 				if (_sequenceID != 0) {
 					_iniUnderCursor = cursorOverIni;
-//					data_80072890 = uVar3; TODO
-//					data_800728b0 = uVar4;
+					data_80072890 = data_80072890_orig;
+					data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
 				byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
@@ -263,16 +264,16 @@ int16 Cursor::updateIniFromScene() {
 //				local_44 = local_44 + local_48;
 				if(executeScript(scriptOpCall, 0)) {
 					_iniUnderCursor = cursorOverIni;
-//					data_80072890 = uVar3; //TODO
-//					data_800728b0 = uVar4;
+					data_80072890 = data_80072890_orig;
+					data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
 			}
 		}
 	}
 	_iniUnderCursor = 0;
-//	data_80072890 = uVar3; TODO
-//	data_800728b0 = uVar4;
+	data_80072890 = data_80072890_orig;
+	data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 	return 0;
 }
 
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 251eeb68ab..0766eb174b 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -46,7 +46,7 @@ struct DragonINI
 		uint16 id;
 		int16 iptIndex_maybe;
 		int16 field_2;
-		uint16 actorResourceId;
+		int16 actorResourceId;
 		uint16 sequenceId;
 		int16 field_8;
 		Actor *actor;
@@ -60,7 +60,7 @@ struct DragonINI
 		uint16 field_1a_flags_maybe;
 		int16 field_1c;
 		int16 field_1e;
-		uint16 field_20_actor_field_14;
+		int16 field_20_actor_field_14;
 	};
 
 class DragonINIResource {
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index c6b85d834c..eda7029084 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -329,8 +329,9 @@ void DragonsEngine::gameLoop()
 			LAB_80026d34:
 			uVar3 = 0;
 		}
+
 		if (_cursor->updateINIUnderCursor() == 0 ||
-			(getINI(_cursor->_iniUnderCursor)->actor && (getINI(_cursor->_iniUnderCursor)->actor->_actorID & 0x4000) != 0)) { //TODO check this. This logic looks a bit strange.
+			(!(_cursor->_iniUnderCursor & 0x8000) && (getINI(_cursor->_iniUnderCursor - 1)->field_1a_flags_maybe & 0x4000) != 0)) { //TODO check this. This logic looks a bit strange.
 			_data_either_5_or_0 = 0;
 		}
 		else {
@@ -998,8 +999,76 @@ void DragonsEngine::FUN_80038890() {
 	error("FUN_80038890"); //TODO
 }
 
-void DragonsEngine::FUN_8002837c() {
-	error("FUN_8002837c"); //TODO
+void DragonsEngine::FUN_8002837c()
+{
+	ushort targetX;
+	ushort targetY;
+	uint uVar7;
+	uint uVar8;
+	DragonINI *targetINI;
+	DragonINI *flickerINI;
+
+	flickerINI = _dragonINIResource->getFlickerRecord();
+	if (flickerINI->sceneId == getCurrentSceneId()) {
+		if (_cursor->data_80072890 != 0) {
+
+			if (!(READ_LE_UINT16(_dragonOBD->getFromOpt(_cursor->data_80072890 - 1) + 4) & 8)
+			&& (_inventory->getType() == 0) && !isFlagSet(ENGINE_FLAG_200000)) {
+				targetINI = getINI(_cursor->data_80072890 - 1);
+				if ((targetINI->field_1a_flags_maybe & 1) == 0) {
+					if (targetINI->actorResourceId == -1) {
+						return;
+					}
+					IMG *img = _dragonIMG->getIMG(targetINI->field_2);
+					targetX = img->field_a;
+					targetY = img->field_c;
+				}
+				else {
+					targetX = targetINI->actor->x_pos;
+					targetY = targetINI->actor->y_pos;
+				}
+				flickerINI->actor->field_7c = 0x10000;
+				if (flickerINI->field_20_actor_field_14 == -1) {
+					flickerINI->actor->setFlag(ACTOR_FLAG_800);
+				}
+				flickerINI->actor->pathfinding_maybe((int)(((uint)targetX + (uint)targetINI->field_1c) * 0x10000) >> 0x10,
+												  (int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10,0);
+				bit_flags_8006fbd8 = 1;
+				return;
+			}
+			if (isFlagSet(ENGINE_FLAG_200000)) {
+				bit_flags_8006fbd8 = 3;
+				return;
+			}
+			flickerINI = _dragonINIResource->getFlickerRecord();
+			if (flickerINI != NULL && flickerINI->actor != NULL) {
+				flickerINI->actor->clearFlag(ACTOR_FLAG_10);
+				uVar8 = (uint)_cursor->data_80072890;
+				flickerINI->actor->setFlag(ACTOR_FLAG_4);
+				targetINI = getINI(_cursor->data_80072890 - 1);
+				flickerINI->field_20_actor_field_14 = targetINI->field_e;
+				flickerINI->actor->_sequenceID2 = targetINI->field_e;
+			}
+			bit_flags_8006fbd8 = 3;
+			return;
+		}
+		if (_inventory->getType() == 0 && !isFlagSet(ENGINE_FLAG_200000)) {
+			uVar7 = (uint)(ushort)_cursor->_x;
+			uVar8 = (uint)(ushort)_cursor->_y;
+			flickerINI->actor->field_7c = 0x10000;
+			flickerINI->actor->pathfinding_maybe(
+					(int)((uVar7 + (uint)_scene->_camera.x) * 0x10000) >> 0x10,
+					 (int)((uVar8 + (uint)_scene->_camera.y) * 0x10000) >> 0x10,0);
+		}
+	}
+	else {
+		if (_cursor->data_80072890 != 0) {
+			bit_flags_8006fbd8 = 3;
+			return;
+		}
+	}
+	bit_flags_8006fbd8 = 0;
+	return;
 }
 
 void DragonsEngine::FUN_80031480() {
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 1b5967fccd..ea28bfa473 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -70,6 +70,7 @@ enum Flags {
 	ENGINE_FLAG_10000    =    0x10000,
 	ENGINE_FLAG_80000    =    0x80000,
 	ENGINE_FLAG_100000   =   0x100000,
+	ENGINE_FLAG_200000   =   0x200000,
 	ENGINE_FLAG_400000   =   0x400000,
 	ENGINE_FLAG_4000000  =  0x4000000,
 	ENGINE_FLAG_20000000 = 0x20000000,


Commit: 22cec7535060e2188b8ea08eb603c4567675a7e7
    https://github.com/scummvm/scummvm/commit/22cec7535060e2188b8ea08eb603c4567675a7e7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Pathfinding fixes

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/dragons.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 7a67e7a620..8aecddd0cc 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -351,7 +351,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 			int16 tempX = newX;
 			int16 tempY = newY;
 			for(int j = 0; j < 0x20; j++) {
-				Common::Point point = getEngine()->_scene->getPoint(i);
+				Common::Point point = getEngine()->_scene->getPoint(j);
 				if (point.x == -1) {
 					continue;
 				}
@@ -413,7 +413,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 			if (i == 0x20) {
 				// 0x80033ed0
 				for(int j = 0; j < 0x20; j++) {
-					Common::Point point = getEngine()->_scene->getPoint(i);
+					Common::Point point = getEngine()->_scene->getPoint(j);
 					if (point.x == -1) {
 						continue;
 					}
@@ -791,12 +791,13 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		}
 	}
 
+	// 0x80034930
 	int16 Actor::pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y,
 											 int16 unkType, uint8 *pointsInUseTbl) {
 		int16 pointId = -1;
 		uint32 minDist = 0xffffffff;
 
-		for (int i = 0; i < 0x22; i++) {
+		for (int i = 0; i < 0x20; i++) {
 			Common::Point point = getEngine()->_scene->getPoint(i);
 			if (point.x != -1 && pointsInUseTbl[i] == 0) {
 				if (pathfindingUnk(point.x, point.y, target_x, target_y, unkType)) {
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index eda7029084..aa208a2ef3 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1032,7 +1032,7 @@ void DragonsEngine::FUN_8002837c()
 					flickerINI->actor->setFlag(ACTOR_FLAG_800);
 				}
 				flickerINI->actor->pathfinding_maybe((int)(((uint)targetX + (uint)targetINI->field_1c) * 0x10000) >> 0x10,
-												  (int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10,0);
+													(int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10,0);
 				bit_flags_8006fbd8 = 1;
 				return;
 			}
@@ -1058,7 +1058,7 @@ void DragonsEngine::FUN_8002837c()
 			flickerINI->actor->field_7c = 0x10000;
 			flickerINI->actor->pathfinding_maybe(
 					(int)((uVar7 + (uint)_scene->_camera.x) * 0x10000) >> 0x10,
-					 (int)((uVar8 + (uint)_scene->_camera.y) * 0x10000) >> 0x10,0);
+					(int)((uVar8 + (uint)_scene->_camera.y) * 0x10000) >> 0x10,0);
 		}
 	}
 	else {


Commit: b339a9da7b8affe8791f0329c8bd49b4e86d121c
    https://github.com/scummvm/scummvm/commit/b339a9da7b8affe8791f0329c8bd49b4e86d121c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: more pathfinder fixes

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/cursor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 8aecddd0cc..3ceeb62a29 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -714,7 +714,8 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 				newSequenceId = absDiffX < (absDiffY * 2) ? 2 : 0;
 				break;
 			case 1 :
-				error("TODO t2 == 1 0x80035138");
+				newSequenceId =  absDiffX < (absDiffY * 2) ? 0 : 6;
+				break;
 			case 2 :
 				newSequenceId = absDiffX < (absDiffY * 2) ? 2 : 4;
 				break;
@@ -728,8 +729,9 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		field_30 = field_30 / 2;
 
 		if (getEngine()->_dragonINIResource->isFlicker(_actorID)) {
-			// TODO 0x8003523c
-			error("FIXME 0x8003523c");
+			DragonINI *ini = getEngine()->_dragonINIResource->getFlickerRecord();
+			ini->actor->field_2c = (ini->actor->field_2c * 3 + ((ini->actor->field_2c * 3) >> 0x1f)) >> 1;
+			ini->actor->field_30 = (ini->actor->field_30 * 3 + ((ini->actor->field_30 * 3) >> 0x1f)) >> 1;
 		}
 
 		target_x_pos = newTargetX;
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 7297c60815..230c30fd23 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -225,6 +225,7 @@ int16 Cursor::updateIniFromScene() {
 					data_80072890 = cursorOverIni;
 					uint32 newSeqId = 1;
 					for(int idx=0; idx < 5; idx++) {
+						data_800728b0_cursor_seqID = idx;
 						byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
 						ScriptOpCall scriptOpCall;
 						scriptOpCall._code = obd + 8;


Commit: 7a75ae2190ffb211805c30872a63746fe6771643
    https://github.com/scummvm/scummvm/commit/7a75ae2190ffb211805c30872a63746fe6771643
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on cursor action logic

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 230c30fd23..51ef7c9756 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -21,6 +21,7 @@
  */
 #include "cursor.h"
 #include "actor.h"
+#include "actorresource.h"
 #include "dragons.h"
 #include "dragonimg.h"
 #include "dragonini.h"
@@ -199,6 +200,14 @@ int16 Cursor::updateIniFromScene() {
 			// 0x80028a10
 			if (ini->field_1a_flags_maybe & 1) {
 				// 0x80028b18
+				if (ini->actor->isFlagSet(ACTOR_FLAG_40) && ini->actor->isFlagSet(ACTOR_FLAG_8)) {
+					int16 iniActorXPosition = ini->actor->x_pos - ini->actor->frame->xOffset;
+					int16 iniActorYPosition = ini->actor->y_pos - ini->actor->frame->yOffset;
+					if (_actor->x_pos >= iniActorXPosition && _actor->x_pos < iniActorXPosition + ini->actor->frame->width
+					&& _actor->y_pos >= iniActorYPosition && _actor->y_pos < iniActorYPosition + ini->actor->frame->height) {
+						cursorOverIni = i + 1;
+					}
+				}
 			} else {
 				// 0x80028a24
 				if (ini->field_2 != -1) {
@@ -310,7 +319,7 @@ void Cursor::selectPreviousCursor() {
 		_sequenceID = 1;
 	}
 	if (_sequenceID == 2) {
-		_sequenceID = 1;
+		_sequenceID = 0x10001;
 	}
 	if (_sequenceID == -1) {
 		_sequenceID = _vm->data_8006f3a8 == 0 ? 4 : 5;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index aa208a2ef3..6f6d8ba756 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -380,7 +380,7 @@ void DragonsEngine::gameLoop()
 				if (_cursor->_sequenceID != 5) {
 					uVar6 = _cursor->data_80072890;
 				}
-				flicker->actor->_sequenceID2 = getINI(uVar6 - 1)->field_20_actor_field_14;
+				flicker->actor->_sequenceID2 = getINI(uVar6 - 1)->field_e;
 			}
 
 			works_with_obd_data_1();
@@ -972,7 +972,74 @@ void DragonsEngine::call_fade_related_1f() {
 }
 
 void DragonsEngine::works_with_obd_data_1() {
-	error("works_with_obd_data_1");
+	uint uVar1;
+	ushort uVar2;
+	uint uVar4;
+	uint uVar5;
+	uint uVar6;
+	ScriptOpCall local_48;
+	ScriptOpCall local_38;
+	ScriptOpCall local_58;
+	byte * pvVar7;
+	byte * pvVar8;
+
+	uVar2 = _scriptOpcodes->_data_800728c0;
+	uVar1 = _flags;
+	local_58._code = NULL;
+	local_58._codeEnd = NULL;
+	local_58._result = 0;
+
+	uVar6 = 0;
+	_scriptOpcodes->_data_80071f5c = 0;
+
+	byte *obd = _dragonOBD->getFromOpt(_cursor->data_80072890 - 1);
+
+
+	local_48._code = pvVar7 = obd + 8;
+	local_48._codeEnd = pvVar8 = local_48._code + READ_LE_UINT32(obd);
+
+	uVar4 = _cursor->executeScript(local_48, 1);
+	if (_cursor->data_800728b0_cursor_seqID > 4) {
+		_scriptOpcodes->_data_80071f5c = 0;
+		_scriptOpcodes->_data_800728c0 = _cursor->data_80072890;
+
+		obd = _dragonOBD->getFromOpt(_scriptOpcodes->_data_800728c0 - 1);
+
+		local_38._code = obd + 8;
+		local_38._codeEnd = local_38._code + READ_LE_UINT32(obd);
+
+		uVar6 = _cursor->executeScript(local_38, 1);
+		_scriptOpcodes->_data_800728c0 = uVar2;
+	}
+	if ((uVar6 & 0xffff) != 0) {
+		local_58._code = local_38._code + 8;
+		local_58._codeEnd = local_58._code + READ_LE_UINT16(local_38._code + 6);
+	}
+	if (((uVar4 & 0xffff) != 0) && ((((uVar4 & 2) == 0 || ((uVar6 & 2) != 0)) || ((uVar6 & 0xffff) == 0)))) {
+		local_58._code = local_48._code + 8;
+		local_58._codeEnd = local_58._code + READ_LE_UINT16(local_48._code + 6);
+	}
+	uVar4 = uVar4 & 0xfffd;
+	if (local_58._code != NULL && local_58._codeEnd != NULL) {
+		clearFlags(ENGINE_FLAG_8);
+		_scriptOpcodes->runScript(local_58);
+	}
+	if ((local_58._result & 1U) == 0) {
+		if (_cursor->data_800728b0_cursor_seqID == 3) {
+			local_58._code = pvVar7;
+			local_58._codeEnd = pvVar8;
+			uVar5 = _scriptOpcodes->FUN_800297d8(local_58);
+			uVar4 = uVar4 | uVar5;
+		}
+		if (((uVar4 & 0xffff) == 0) && ((uVar6 & 0xfffd) == 0)) {
+			FUN_8002931c();
+		}
+	}
+	else {
+		_scriptOpcodes->_data_80071f5c--;
+	}
+	_flags |= uVar1 & ENGINE_FLAG_8;
+	return;
 }
 
 bool DragonsEngine::checkForInventoryButtonRelease() {
@@ -1079,4 +1146,8 @@ void DragonsEngine::FUN_80038994() {
 	error("FUN_80038994"); //TODO
 }
 
+void DragonsEngine::FUN_8002931c() {
+	error("FUN_8002931c"); //TODO
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index ea28bfa473..e846c7aa16 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -181,6 +181,7 @@ public:
 	void fade_related(uint32 flags);
 
 	uint16 ipt_img_file_related();
+	void works_with_obd_data_1();
 
 private:
 	void gameLoopOld();
@@ -194,7 +195,6 @@ private:
 	void runINIScripts();
 	void engineFlag0x20UpdateFunction();
 
-	void works_with_obd_data_1();
 
 	bool isInputEnabled();
 	bool checkForInventoryButtonRelease();
@@ -206,6 +206,8 @@ private:
 	void FUN_8002837c();
 	void FUN_80031480();
 	void FUN_80038994();
+
+	void FUN_8002931c();
 };
 
 DragonsEngine *getEngine();
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 0c8346b4c8..cf9e33070e 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -93,7 +93,7 @@ void ScriptOpcodes::initOpcodes() {
 
 	OPCODE(4,  opExecuteScript);
 	OPCODE(5,  opActorSetSequenceID2);
-
+	OPCODE(6,  opUnk6);
 	OPCODE(7,  opUnk7);
 	OPCODE(8,  opActorLoadSequence);
 
@@ -193,6 +193,10 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+int16 ScriptOpcodes::FUN_800297d8(ScriptOpCall &scriptOpCall) {
+	error("FUN_800297d8"); //TODO
+}
+
 // Opcodes
 
 void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
@@ -201,12 +205,13 @@ void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field4);
 	ARG_INT16(field6);
 
-	if (field2 >> _vm->_cursor->data_800728b0_cursor_seqID & 1
+	if ((field2 >> _vm->_cursor->data_800728b0_cursor_seqID) & 1
 	&& (_vm->_cursor->data_800728b0_cursor_seqID < 5 || field4 == _data_800728c0)
 	&& scriptOpCall._field8 == 1) {
+		scriptOpCall._code -= 8;
 		scriptOpCall._result |= 1;
 	} else {
-		scriptOpCall._code += (8 + field6);
+		scriptOpCall._code += field6;
 	}
 }
 
@@ -235,6 +240,45 @@ void ScriptOpcodes::opActorSetSequenceID2(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	int16 uVar6 = _data_800728c0;
+	int16 uVar5 = _vm->_cursor->data_800728b0_cursor_seqID;
+	int16 uVar4 = _vm->_cursor->data_80072890;
+	int16 uVar3 = _vm->_cursor->_iniUnderCursor;
+	int32 uVar2 = _vm->_cursor->_sequenceID;
+	bool isEngineFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_8);
+//	DisableVSyncEvent();
+	_vm->_cursor->_iniUnderCursor = field4;
+	_vm->_cursor->_sequenceID = 0;
+
+	for(int16 i = field2 >> 1; i != 0; i = i >> 1) {
+		_vm->_cursor->_sequenceID++;
+	}
+
+	_data_800728c0 = field6;
+	_vm->_cursor->data_800728b0_cursor_seqID = _vm->_cursor->_sequenceID;
+	_vm->_cursor->data_80072890 = _vm->_cursor->_iniUnderCursor;
+//	EnableVSyncEvent();
+	_vm->works_with_obd_data_1();
+	if (isEngineFlag8Set) {
+		_vm->setFlags(ENGINE_FLAG_8);
+	}
+	_vm->_cursor->_sequenceID = uVar2;
+	_vm->_cursor->_iniUnderCursor = uVar3;
+	_vm->_cursor->data_80072890 = uVar4;
+	_vm->_cursor->data_800728b0_cursor_seqID = uVar5;
+	_data_800728c0 = uVar6;
+}
 
 void ScriptOpcodes::opUnk7(ScriptOpCall &scriptOpCall) {
 	if (scriptOpCall._field8 == 0) {
@@ -936,6 +980,35 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 		if (sceneId == 1) {
 			// TODO 0x8002d2f4
 			error("0x8002d2f4");
+//			if (_vm->data_8006f3a8 != 0) {
+//				uVar5 = 0;
+//				if (_vm->unkArray_uint16[0] != 0) {
+//					uVar7 = 1;
+//					do {
+//						uVar5 = uVar7;
+//						uVar7 = uVar5 + 1;
+//					} while (_vm->unkArray_uint16[uVar5 & 0xffff] != 0);
+//				}
+//				_vm->unkArray_uint16[uVar5 & 0xffff] = _vm->data_8006f3a8;
+//				if (_vm->_inventory->getType() == 1) {
+//					uVar7 = uVar5 + 0x17 & 0xffff;
+//					actors[uVar7].flags = 0;
+//					actors[uVar7].priorityLayer_maybe = 0;
+//					actors[uVar7].field_0xe = 0x100;
+//					actor_update_sequenceID(uVar7,dragon_ini_pointer[(uint)_vm->unkArray_uint16[uVar5 & 0xffff] - 1].field_1a_flags_maybe * 2 + 10);
+//					actors[uVar7].flags = actors[uVar7].flags | 0x3c0;
+//					actors[uVar7].priorityLayer_maybe = 6;
+//				}
+//			}
+//			DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+//			actors[0].x_pos = actors[(uint)dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].actorId].x_pos - camera_x;
+//			DAT_800728b0 = 5;
+//			_vm->_cursor->_sequenceID = 5;
+//			actors[0].y_pos = actors[(uint)dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].actorId].y_pos - (camera_y + 0x1e);
+//			DAT_8007283c = dragon_ini_pointer[uVar9 & 0xffff].field_0x8 * 2 + 10;
+//			_vm->data_8006f3a8 = uVar1;
+//			cursor_x_var = actors[0].x_pos;
+//			cursor_y_var = actors[0].y_pos;
 		}
 	}
 	ini->sceneId = sceneId;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 78306a96c7..e2acf1e273 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -64,6 +64,7 @@ public:
 	void runScript3(ScriptOpCall &scriptOpCall);
 	void execOpcode(ScriptOpCall &scriptOpCall);
 	void executeScriptLoop(ScriptOpCall &scriptOpCall);
+	int16 FUN_800297d8(ScriptOpCall &scriptOpCall);
 	int16 _data_80071f5c;
 	int16 _data_800728c0;
 protected:
@@ -82,7 +83,7 @@ protected:
 	void opUnk1(ScriptOpCall &scriptOpCall);
 	void opExecuteScript(ScriptOpCall &scriptOpCall); //op 4
 	void opActorSetSequenceID2(ScriptOpCall &scriptOpCall); //op 5
-
+	void opUnk6(ScriptOpCall &scriptOpCall);
 	void opUnk7(ScriptOpCall &scriptOpCall);
 	void opActorLoadSequence(ScriptOpCall &scriptOpCall);
 


Commit: 67496578779238f76b7103d530a21d73d2015df2
    https://github.com/scummvm/scummvm/commit/67496578779238f76b7103d530a21d73d2015df2
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More opcodes. Work on scene changing

Changed paths:
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index a5fee252a5..ff362a7155 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -36,6 +36,7 @@ namespace Dragons {
 Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
 		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
 	_backgroundLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
+	data_80063392 = 2;
 }
 void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 	// TODO
@@ -339,4 +340,8 @@ void Scene::removeImageOverlay(uint16 iptId) {
 	_stage->restoreTiles(img->layerNum - 1, img->x, img->y, img->w, img->h);
 }
 
+void Scene::setSceneId(int16 newSceneId) {
+	_currentSceneId = newSceneId;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 42bb82e32d..9f87ae3cfc 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -41,6 +41,8 @@ struct DragonINI;
 class Scene {
 public:
 	Common::Point _camera;
+	int16 data_80063392;
+
 private:
 	DragonsEngine *_vm;
 	Screen *_screen;
@@ -63,6 +65,7 @@ public:
 	bool contains(DragonINI *ini);
 	byte *getPalette();
 	uint16 getSceneId();
+	void setSceneId(int16 newSceneId);
 	Common::Point getPoint(uint32 pointIndex);
 	uint16 getStageWidth();
 	uint16 getStageHeight();
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index cf9e33070e..2464bdd4f1 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -27,6 +27,7 @@
 #include "dragons/dragonini.h"
 #include "dragons/dragonimg.h"
 #include "dragons/dragonobd.h"
+#include "dragons/inventory.h"
 #include "dragons/scene.h"
 #include "dragons/scriptopcodes.h"
 #include "dragons/specialopcodes.h"
@@ -114,6 +115,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x17, opUnk17);
 
 	OPCODE(0x1F, opPlayMusic);
+	OPCODE(0x20, opUnk20);
 
 	OPCODE(0x22, opCodeActorTalk);
 }
@@ -376,6 +378,12 @@ void ScriptOpcodes::opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	scriptOpCall._code += 4 + READ_LE_UINT16(scriptOpCall._code);
 }
 
+void ScriptOpcodes::opUnk20(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	//TODO do we need this? It looks like it is pre-loading scene data.
+}
+
 bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {
 	byte *codePtrOffsetA = scriptOpCall._code + 0xA;
 	byte *codePtrOffset2 = scriptOpCall._code + 2;
@@ -729,8 +737,8 @@ void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 
 void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
-	ARG_INT16(field2);
-	ARG_INT16(field4);
+	ARG_INT16(newSceneID);
+	ARG_INT16(cameraPointID);
 	ARG_INT16(field6);
 
 	if (scriptOpCall._field8 != 0) {
@@ -741,10 +749,14 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 	// func_ptr_unk = 0;
 	// PauseCDMusic();
 
-	if (field2 != 0) {
+	if (newSceneID != 0) {
 		// load scene here.
 		//TODO
-		error("0x8002efe4");
+		_vm->_scene->data_80063392 = _vm->_scene->getSceneId();
+		_vm->_scene->setSceneId(newSceneID);
+		_vm->data_800633fa = field6;
+
+		_vm->_scene->loadScene(newSceneID, cameraPointID);
 	} else {
 		_vm->setFlags(Dragons::ENGINE_FLAG_100000);
 	}
@@ -978,37 +990,34 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 		}
 
 		if (sceneId == 1) {
-			// TODO 0x8002d2f4
-			error("0x8002d2f4");
-//			if (_vm->data_8006f3a8 != 0) {
-//				uVar5 = 0;
-//				if (_vm->unkArray_uint16[0] != 0) {
-//					uVar7 = 1;
-//					do {
-//						uVar5 = uVar7;
-//						uVar7 = uVar5 + 1;
-//					} while (_vm->unkArray_uint16[uVar5 & 0xffff] != 0);
-//				}
-//				_vm->unkArray_uint16[uVar5 & 0xffff] = _vm->data_8006f3a8;
-//				if (_vm->_inventory->getType() == 1) {
-//					uVar7 = uVar5 + 0x17 & 0xffff;
-//					actors[uVar7].flags = 0;
-//					actors[uVar7].priorityLayer_maybe = 0;
-//					actors[uVar7].field_0xe = 0x100;
-//					actor_update_sequenceID(uVar7,dragon_ini_pointer[(uint)_vm->unkArray_uint16[uVar5 & 0xffff] - 1].field_1a_flags_maybe * 2 + 10);
-//					actors[uVar7].flags = actors[uVar7].flags | 0x3c0;
-//					actors[uVar7].priorityLayer_maybe = 6;
-//				}
-//			}
-//			DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
-//			actors[0].x_pos = actors[(uint)dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].actorId].x_pos - camera_x;
-//			DAT_800728b0 = 5;
-//			_vm->_cursor->_sequenceID = 5;
-//			actors[0].y_pos = actors[(uint)dragon_ini_pointer[(uint)dragon_ini_maybe_flicker_control].actorId].y_pos - (camera_y + 0x1e);
-//			DAT_8007283c = dragon_ini_pointer[uVar9 & 0xffff].field_0x8 * 2 + 10;
-//			_vm->data_8006f3a8 = uVar1;
-//			cursor_x_var = actors[0].x_pos;
-//			cursor_y_var = actors[0].y_pos;
+			if (_vm->data_8006f3a8 != 0) {
+				uint16 freeSlot = 0;
+				for( ;_vm->unkArray_uint16[freeSlot] != 0; freeSlot++) {
+					if (_vm->unkArray_uint16[freeSlot] == 0) {
+						break;
+					}
+				}
+				_vm->unkArray_uint16[freeSlot] = _vm->data_8006f3a8;
+				if (_vm->_inventory->getType() == 1) {
+					Actor *actor = _vm->_actorManager->getActor(freeSlot + 0x17);
+					actor->flags = 0;
+					actor->priorityLayer = 0;
+					actor->field_e = 0x100;
+					actor->updateSequence((_vm->getINI(_vm->unkArray_uint16[freeSlot] - 1)->field_8 * 2 + 10) & 0xfffe);
+					actor->setFlag(ACTOR_FLAG_40);
+					actor->setFlag(ACTOR_FLAG_80);
+					actor->setFlag(ACTOR_FLAG_100);
+					actor->setFlag(ACTOR_FLAG_200);
+					actor->priorityLayer = 6;
+				}
+			}
+			DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+			_vm->_cursor->updatePosition(flicker->actor->x_pos - _vm->_scene->_camera.x,
+					flicker->actor->y_pos - (_vm->_scene->_camera.y + 0x1e));
+			_vm->_cursor->data_800728b0_cursor_seqID = 5;
+			_vm->_cursor->_sequenceID = 5;
+			_vm->_cursor->data_8007283c = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
+			_vm->data_8006f3a8 = field2;
 		}
 	}
 	ini->sceneId = sceneId;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index e2acf1e273..f1d93641a0 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -102,6 +102,7 @@ protected:
 	void opUnk16(ScriptOpCall &scriptOpCall);
 	void opUnk17(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
+	void opUnk20(ScriptOpCall &scriptOpCall);
 
 	bool checkPropertyFlag(ScriptOpCall &scriptOpCall);
 	void opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 3604626410..2a2a438a54 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -67,6 +67,9 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(9, spcUnk9);
 	OPCODE(0xa, spcUnkA);
+
+	OPCODE(0xc, spcUnkC);
+
 	OPCODE(0x14, spcClearEngineFlag8);
 	OPCODE(0x15, spcSetEngineFlag8);
 
@@ -110,6 +113,9 @@ void SpecialOpcodes::spcUnkA() {
 	_vm->getINI(1)->field_1a_flags_maybe &= ~Dragons::INI_FLAG_20;
 }
 
+void SpecialOpcodes::spcUnkC() {
+	//TODO fade_related_calls_with_1f();
+}
 
 void SpecialOpcodes::spcClearEngineFlag8() {
 	_vm->clearFlags(Dragons::ENGINE_FLAG_8);
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 7611eb2f9e..7f9e0815b5 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -55,6 +55,8 @@ protected:
 	void spcUnk9();
 	void spcUnkA();
 
+	void spcUnkC();
+
 	void spcClearEngineFlag8(); // 0x14
 	void spcSetEngineFlag8(); // 0x15
 


Commit: 963cd5441e334ba299af4298da6c56ef12c5e519
    https://github.com/scummvm/scummvm/commit/963cd5441e334ba299af4298da6c56ef12c5e519
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on scene change logic

Changed paths:
    engines/dragons/scene.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index ff362a7155..58b2260fd9 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -247,7 +247,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 }
 
 void Scene::draw() {
-	Common::Rect rect(_camera.x, _camera.y, 320, 200);
+	Common::Rect rect(_camera.x, _camera.y, _camera.x + 320, _camera.y + 200);
 
 	for(uint16 priority = 1; priority < 16; priority++) {
 		if (priority == 1) {
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 2a2a438a54..02e2f5b1a4 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -26,6 +26,7 @@
 #include "dragons/dragonini.h"
 #include "dragons/dragonobd.h"
 #include "dragons/specialopcodes.h"
+#include "dragons/scene.h"
 #include "dragons/actor.h"
 #include "specialopcodes.h"
 
@@ -73,8 +74,14 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x14, spcClearEngineFlag8);
 	OPCODE(0x15, spcSetEngineFlag8);
 
+	OPCODE(0x4e, spcUnk4e);
+	OPCODE(0x4f, spcUnk4f);
+
 	OPCODE(0x54, spcSetEngineFlag0x4000000);
 	OPCODE(0x55, spcSetCursorSequenceIdToZero);
+
+	OPCODE(0x5e, spcUnk5e);
+	OPCODE(0x5f, spcUnk5f);
 }
 
 #undef OPCODE
@@ -125,6 +132,15 @@ void SpecialOpcodes::spcSetEngineFlag8() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_8);
 }
 
+
+void SpecialOpcodes::spcUnk4e() {
+	panCamera(1);
+}
+
+void SpecialOpcodes::spcUnk4f() {
+	panCamera(2);
+}
+
 void SpecialOpcodes::spcSetEngineFlag0x4000000() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
 }
@@ -133,4 +149,47 @@ void SpecialOpcodes::spcSetCursorSequenceIdToZero() {
 	_vm->_cursor->_sequenceID = 0;
 }
 
+void SpecialOpcodes::spcUnk5e() {
+	panCamera(1);
+	_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(0));
+}
+
+void SpecialOpcodes::spcUnk5f() {
+	_vm->getINI(0x2ab)->field_12 = 0;
+	panCamera(2);
+}
+
+// 0x80038c1c
+void SpecialOpcodes::panCamera(int16 mode) {
+	int iVar1;
+	int iVar2;
+
+	if (mode == 1) {
+		_vm->getINI(0x2ab)->field_12 = _vm->_scene->_camera.x;
+		_vm->_dragonINIResource->setFlickerRecord(NULL);
+		iVar2 = (int) _vm->_scene->_camera.x;
+		iVar1 = iVar2;
+		while (iVar1 <= (_vm->_scene->getStageWidth() - 320)) {
+			_vm->_scene->_camera.x = (short) iVar2;
+			_vm->waitForFrames(1);
+			iVar2 = iVar2 + 4;
+			iVar1 = iVar2 * 0x10000 >> 0x10;
+		}
+		_vm->_scene->_camera.x = _vm->_scene->getStageWidth() - 320;
+	}
+	if (mode == 2) {
+		iVar2 = (int) _vm->_scene->_camera.x;
+		iVar1 = iVar2;
+		while (-1 < iVar1) {
+			_vm->_scene->_camera.x = (short) iVar2;
+			_vm->waitForFrames(1);
+			iVar2 = iVar2 + -3;
+			iVar1 = iVar2 * 0x10000;
+		}
+		_vm->_scene->_camera.x = 0;
+		_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(0));
+	}
+	return;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 7f9e0815b5..1c549954c2 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -60,9 +60,16 @@ protected:
 	void spcClearEngineFlag8(); // 0x14
 	void spcSetEngineFlag8(); // 0x15
 
+	void spcUnk4e();
+	void spcUnk4f();
+
 	void spcSetEngineFlag0x4000000(); // 0x54
 	void spcSetCursorSequenceIdToZero(); // 0x55
+	void spcUnk5e();
+	void spcUnk5f();
 
+private:
+	void panCamera(int16 mode);
 };
 
 } // End of namespace Dragons


Commit: a0ada3357ca7547e5e436aef9dc86a2c5ebe8c40
    https://github.com/scummvm/scummvm/commit/a0ada3357ca7547e5e436aef9dc86a2c5ebe8c40
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Adding more scene loading logic

Changed paths:
    engines/dragons/actor.h
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h


diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 7e598eb71c..2cd1d95af1 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -51,6 +51,11 @@ enum ActorFlags {
 	ACTOR_FLAG_8000 = 0x8000  //Seems turn off semi trans mode when selected.
 };
 
+enum ActorFrameFlags {
+	ACTOR_FRAME_FLAG_10 = 0x10,
+	ACTOR_FRAME_FLAG_20 = 0x20
+};
+
 class ActorManager {
 public:
 	typedef Common::Array<Actor> Actors;
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 51ef7c9756..481f6febc0 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -56,6 +56,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	data_800728b0_cursor_seqID = 0;
 }
 
+
 void Cursor::update() {
 	if (!_vm->isFlagSet(Dragons::ENGINE_FLAG_8) || _vm->isFlagSet(Dragons::ENGINE_FLAG_100)) {
 		return;
@@ -326,4 +327,14 @@ void Cursor::selectPreviousCursor() {
 	}
 }
 
+void Cursor::updateSequenceID(int16 sequenceID) {
+	_sequenceID = sequenceID;
+	_actor->updateSequence(_sequenceID);
+
+}
+
+void Cursor::setActorFlag400() {
+	_actor->setFlag(ACTOR_FLAG_400);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index c5680dfb11..736a7e3fd9 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -51,12 +51,14 @@ public:
 	Cursor(DragonsEngine *vm);
 	void init(ActorManager *actorManager, DragonINIResource *dragonINIResource);
 	void update();
+	void updateSequenceID(int16 sequenceID);
 	void updateVisibility();
 	void updatePosition(int16 x, int16 y);
 	int16 updateINIUnderCursor();
 	int16 executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag);
 	void selectPreviousCursor();
 	void selectNextCursor();
+	void setActorFlag400();
 private:
 	int16 updateIniFromScene();
 };
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 6f6d8ba756..598dde4e73 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -73,6 +73,14 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
 	_iKeyUp = false;
+
+	for(int i = 0; i < 8; i++) {
+		opCode1A_tbl[i].field0 = 0;
+		opCode1A_tbl[i].field2 = 0;
+		opCode1A_tbl[i].field4 = 0;
+		opCode1A_tbl[i].field6 = 0;
+		opCode1A_tbl[i].field8 = 0;
+	}
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -1150,4 +1158,9 @@ void DragonsEngine::FUN_8002931c() {
 	error("FUN_8002931c"); //TODO
 }
 
+void DragonsEngine::reset_screen_maybe() {
+	data_8006a3a0_flag &= ~0x10;
+	//TODO
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index e846c7aa16..6f307ef937 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -73,6 +73,7 @@ enum Flags {
 	ENGINE_FLAG_200000   =   0x200000,
 	ENGINE_FLAG_400000   =   0x400000,
 	ENGINE_FLAG_4000000  =  0x4000000,
+	ENGINE_FLAG_8000000  =  0x8000000,
 	ENGINE_FLAG_20000000 = 0x20000000,
 	ENGINE_FLAG_80000000 = 0x80000000
 };
@@ -88,6 +89,14 @@ enum UnkFlags {
 	ENGINE_UNK1_FLAG_80 = 0x80
 };
 
+struct opCode1AStruct {
+	int16 field0;
+	int16 field2;
+	int16 field4;
+	int16 field6;
+	int16 field8;
+};
+
 class BigfileArchive;
 class BackgroundResourceLoader;
 class Cursor;
@@ -105,6 +114,7 @@ class SequenceOpcodes;
 class ScriptOpcodes;
 struct DragonINI;
 
+
 class DragonsEngine : public Engine {
 public:
 	DragonOBD *_dragonOBD;
@@ -120,6 +130,7 @@ public:
 	uint16 data_8006f3a8;
 
 	uint16 unkArray_uint16[42];
+	opCode1AStruct opCode1A_tbl[8];
 
 private:
 	Screen *_screen;
@@ -183,6 +194,8 @@ public:
 	uint16 ipt_img_file_related();
 	void works_with_obd_data_1();
 
+	void reset_screen_maybe();
+
 private:
 	void gameLoopOld();
 	void gameLoop();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 451aadb73f..339f0ab1c5 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -84,4 +84,8 @@ Common::Point Inventory::getPosition() {
 	return positionTable[_screenPositionIndex];
 }
 
+void Inventory::setActorFlag400() {
+	_actor->setFlag(ACTOR_FLAG_400);
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index c92552e4ad..150279bc75 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -64,7 +64,7 @@ public:
 	void show(int16 type) { _type = type; }
 
 	void updateVisibility();
-
+	void setActorFlag400();
 
 };
 
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 58b2260fd9..bb00041af5 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -23,6 +23,7 @@
 #include "dragons.h"
 #include "actor.h"
 #include "background.h"
+#include "cursor.h"
 #include "dragonini.h"
 #include "dragonimg.h"
 #include "inventory.h"
@@ -37,17 +38,40 @@ Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, Bi
 		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
 	_backgroundLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 	data_80063392 = 2;
+	_data_800633ee = 0;
 }
 void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
+	if (!_vm->isFlagSet(ENGINE_FLAG_40)) {
+		//TODO fade_related_calls_with_1f();
+	}
+	bool unkFlag2Set = _vm->isUnkFlagSet(ENGINE_UNK1_FLAG_2);
+	bool flag8set = _vm->isFlagSet(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+
+	for (int i = 0; i < 8; i++) {
+		_vm->opCode1A_tbl[i].field6 = 0;
+	}
+
 	// TODO
+	_vm->reset_screen_maybe();
+
 	loadSceneData(sceneId, cameraPointId);
 
-	if (sceneId != 4) {
-		Actor *cursor = _actorManager->getActor(0);
-		//TODO update cursor.
+	if (flag8set) {
+		_vm->setFlags(ENGINE_FLAG_8);
+	}
 
+	if (!_vm->isFlagSet(ENGINE_FLAG_8000000) && sceneId != 4) {
+		_vm->_cursor->updateSequenceID((int16)_vm->_cursor->_sequenceID);
+	}
+	_vm->waitForFrames(2);
+	// TODO call_fade_related_1f();
+	if (!unkFlag2Set) {
+		_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
 	}
-	//TODO
+	_data_800633ee = 0;
+
 	if (!(sceneId & 0x8000)) {
 		byte *obd = _dragonRMS->getObdDataFieldC(sceneId);
 		ScriptOpCall scriptOpCall;
@@ -83,16 +107,43 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_actorManager->clearActorFlags(2);
 	//TODO sub_8003fadc(); might be fade related
 
+	_vm->_cursor->setActorFlag400();
+	_vm->_inventory->setActorFlag400();
+	_vm->clearFlags(ENGINE_FLAG_200);
+
+	resetActorFrameFlags();
+
+	// Loading animation logic would go here. 0x8002f538
+
 	_vm->clearFlags(Dragons::ENGINE_FLAG_20);
 	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_10);
 
 	_vm->call_fade_related_1f();
 	// TODO 0x8002f7c4
 
+	_vm->_cursor->updatePosition(160, 100);
+
+	_vm->clearFlags(ENGINE_FLAG_100000);
+	_vm->clearFlags(ENGINE_FLAG_200000);
+
+	// TODO   UnkSoundFunc4(dragon_Rms_Offset[(uint)local_b0].sceneName);
+
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+
+	if (flicker == NULL || flicker->sceneId == 0) {
+		_vm->getINI(1)->sceneId = 0;
+	} else {
+		_currentSceneId = (uint16)(sceneId & 0x7fff);
+		flicker->sceneId = _currentSceneId;
+		_vm->getINI(1)->sceneId = _currentSceneId;
+	}
+
 	_stage = _backgroundLoader->load(sceneId);
 
 	_camera = _stage->getPoint2(cameraPointId);
 
+
+
 	debug("Flicker: (%X, %X)", _camera.x, _camera.y);
 
 	if (_camera.x > 160) {
@@ -196,7 +247,6 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 		ini->actor->priorityLayer = 0;
 	}
 
-	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 
 	if (flicker && flicker->sceneId != 0) {
 		flicker->field_20_actor_field_14 = _vm->data_800633fa;
@@ -344,4 +394,12 @@ void Scene::setSceneId(int16 newSceneId) {
 	_currentSceneId = newSceneId;
 }
 
+void Scene::resetActorFrameFlags() {
+	for (int i = 0; i < 0x17; i++) {
+		Actor *actor = _vm->_actorManager->getActor(i);
+		actor->frame_flags &= ~ACTOR_FRAME_FLAG_10;
+		actor->frame_flags &= ~ACTOR_FRAME_FLAG_20;
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 9f87ae3cfc..37e761d3ed 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -55,6 +55,7 @@ private:
 	ScriptOpcodes *_scriptOpcodes;
 
 	int16 _currentSceneId;
+	int16 _data_800633ee;
 
 public:
 	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
@@ -73,7 +74,7 @@ public:
 	void removeImageOverlay(uint16 iptId);
 private:
 	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
-
+	void resetActorFrameFlags();
 };
 
 } // End of namespace Dragons


Commit: 43498fda209aebd6765bf92cf7536bafa7dc7e8d
    https://github.com/scummvm/scummvm/commit/43498fda209aebd6765bf92cf7536bafa7dc7e8d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: update flicker coords when changing scenes

Changed paths:
    engines/dragons/scene.cpp


diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index bb00041af5..797ce9c2e8 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -99,9 +99,10 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 		ScriptOpCall scriptOpCall;
 		scriptOpCall._code = obd + 4;
 		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		uint16 oldSceneId = _currentSceneId;
 		_currentSceneId = -1;
 		_scriptOpcodes->runScript(scriptOpCall);
-		_currentSceneId = (uint16)(sceneId & 0x7fff);
+		_currentSceneId = oldSceneId;
 	}
 
 	_actorManager->clearActorFlags(2);
@@ -142,7 +143,12 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	_camera = _stage->getPoint2(cameraPointId);
 
-
+	if (flicker && !(sceneId & 0x8000)) {
+		flicker->x = _camera.x;
+		flicker->y = _camera.y;
+		_vm->getINI(1)->x = _camera.x;
+		_vm->getINI(1)->y = _camera.y;
+	}
 
 	debug("Flicker: (%X, %X)", _camera.x, _camera.y);
 
@@ -238,7 +244,6 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 			}
 		}
 	}
-	_currentSceneId = (uint16)(sceneId & 0x7fff); //TODO is this the right spot for this?
 
 	// 0x80030458
 	DragonINI *ini = _vm->getINI(1);


Commit: 11483dfc73e4db6e037c20559b08dc8f608c5e97
    https://github.com/scummvm/scummvm/commit/11483dfc73e4db6e037c20559b08dc8f608c5e97
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: bug fixing pathfinder logic

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 3ceeb62a29..18b0bfdee2 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -234,7 +234,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 	}
 
 	if (unkTypeMaybe < 2) {
-		priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x_pos, target_y_pos));
+		priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x, target_y));
 		if (priority < 0) {
 			priority = 1;
 		}
@@ -452,7 +452,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 	}
 
 	for (; !pathfindingUnk(newX, newY, newTargetX, newTargetY, unkTypeMaybe); ) {
-		int16 pointId = pathfindingFindClosestPoint(newX, newY, newTargetX, newTargetX, unkTypeMaybe, pathfinderData);
+		int16 pointId = pathfindingFindClosestPoint(newX, newY, newTargetX, newTargetY, unkTypeMaybe, pathfinderData);
 		if (pointId == -1) {
 			if (isFlag0x10Set) {
 				pathfindingCleanup();
@@ -461,8 +461,10 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		}
 		pathfinderData[pointId] = 1;
 		Common::Point point = getEngine()->_scene->getPoint(pointId);
+		newTargetX = point.x;
+		newTargetY = point.y;
 		if (numWalkPoints < 2) {
-			if (numWalkPoints > 0 && pathfindingUnk(point.x, point.y, newTargetX, newTargetY, unkTypeMaybe)) {
+			if (numWalkPoints > 0 && pathfindingUnk(point.x, point.y, target_x, target_y, unkTypeMaybe)) {
 				numWalkPoints--;
 			}
 		} else {


Commit: 7c10fe11d0fda38bbf3a0728930a21e5123ce4f2
    https://github.com/scummvm/scummvm/commit/7c10fe11d0fda38bbf3a0728930a21e5123ce4f2
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Bug fixes for pathfinding

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/scene.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 18b0bfdee2..46ad33180d 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -216,7 +216,7 @@ static const int32 pathfinderXYOffsetTbl[32] =
 		};
 
 
-bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe) {
+bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, uint16 unkTypeMaybe) {
 	uint8 pathfinderData[32];
 	debug(1, "pathfinding. (%X,%X) -> (%X,%X)", x_pos, y_pos, target_x, target_y);
 	int16 priority = 0;
@@ -233,6 +233,9 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		return true;
 	}
 
+	int16 newTargetX = target_x;
+	int16 newTargetY = target_y;
+
 	if (unkTypeMaybe < 2) {
 		priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x, target_y));
 		if (priority < 0) {
@@ -251,15 +254,15 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 				if (v0_19 <  0) {
 					v0_19 = s3_1 - 8;
 				}
-				int16 y_offset = (x_related_idx * pathfinderXYOffsetTbl[v0_19 & 0x1f]) / 16;
-				int16 x_offset = (x_related_idx * pathfinderXYOffsetTbl[s3_1 & 0x1f]) / 16;
+				int16 y_offset = (x_related_idx * pathfinderXYOffsetTbl[v0_19 & 0x1f]) / 256;
+				int16 x_offset = (x_related_idx * pathfinderXYOffsetTbl[s3_1 & 0x1f]) / 256;
 				if (target_x + x_offset >= 0 &&
 					target_y + y_offset >= 0) {
-					priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x + x_offset, target_y + y_offset));
+					priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(newTargetX + x_offset, newTargetY + y_offset));
 
 					if ((unkTypeMaybe == 0 && priority - 1 < 8) || (unkTypeMaybe == 1 && priority -1 < 0x10)) {
-						target_x += x_offset;
-						target_y += y_offset;
+						newTargetX += x_offset;
+						newTargetY += y_offset;
 						x_related_idx = -1;
 						break;
 					}
@@ -280,7 +283,7 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 		var_90_1 = 1;
 	}
 
-	if (x_pos == target_x && y_pos == target_y) {
+	if (x_pos == newTargetX && y_pos == newTargetY) {
 		if (isFlag0x10Set) {
 			pathfindingCleanup();
 		}
@@ -289,17 +292,15 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, int16 unkTypeMaybe
 
 	int16 numWalkPoints = 0;
 
-	int16 newTargetX = target_x;
-	int16 newTargetY = target_y;
 	int16 newX = x_pos;
 	int16 newY = y_pos;
 
 	memset(pathfinderData, 0, 32);
 
-	field_76 = target_x;
-	field_78 = target_y;
+	field_76 = newTargetX;
+	field_78 = newTargetY;
 
-	if(!pathfindingUnk(x_pos, y_pos, target_x, target_y, unkTypeMaybe)) {
+	if(!pathfindingUnk(x_pos, y_pos, newTargetX, newTargetY, unkTypeMaybe)) {
 		//  0x8003398c
 		int16 xOffset = -1;
 		//TODO convert to for loops
@@ -652,12 +653,12 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		if ( priority < 0) {
 			priority = 1;
 		}
-		if (!(unkType & 0x7fff) && (priority == 0 || priority >= 9)) {
+		if (!(unkType & 0x7fff) && (priority == 0 || priority >= 8)) {
 			return 0;
 		}
 
 		if ((unkType & 0x7fff) == 1) {
-			if (priority == 0 || priority >= 0x11) {
+			if (priority == 0 || priority >= 0x10) {
 				return 0;
 			}
 		}
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 2cd1d95af1..f89f15df52 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -125,7 +125,7 @@ public:
 	byte *getSeqIpAtOffset(uint32 offset);
 	void loadFrame(uint16 frameOffset);
 	void reset_maybe();
-	bool pathfinding_maybe(int16 target_x, int16 target_y, int16 isNotFlicker);
+	bool pathfinding_maybe(int16 target_x, int16 target_y, uint16 isNotFlicker);
 	void walkPath();
 	void waitUntilFlag8IsSet();
 	void waitUntilFlag8And4AreSet();
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 8c09dc9e0b..6cb6b1bd53 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -28,7 +28,7 @@ namespace Dragons {
 
 #define TILE_WIDTH 32
 #define TILE_HEIGHT 8
-#define TILE_SIZE (TILE_WIDTH * TILE_HEIGHT * 2)
+#define TILE_SIZE (TILE_WIDTH * TILE_HEIGHT)
 
 
 void Dragons::PriorityLayer::load(TileMap &tileMap, byte *tiles) {
@@ -50,8 +50,15 @@ int16 PriorityLayer::getPriority(Common::Point pos) {
 	const int16 tx = pos.x / TILE_WIDTH, sx = pos.x % TILE_WIDTH;
 	const int16 ty = pos.y / TILE_HEIGHT, sy = pos.y % TILE_HEIGHT;
 	uint16 mapIndex = READ_LE_UINT16(_map + 2 * (tx + ty * _mapWidth));
-	return _values[mapIndex * TILE_WIDTH * TILE_HEIGHT + sx + sy * TILE_WIDTH] + 1;
 
+//
+//	byte priority = *(byte *)((((uint)*(ushort *)
+//			(((int)pos.x / 32) * 2 +
+//			 ((int)pos.y / 8) * (uint)_mapWidth * 2 +
+//					_map) * 32) * 8) +
+//			_values + (((int)pos.y % 8) * 32) +
+//						 ((int)pos.x % 32));
+	return _values[mapIndex * TILE_WIDTH * TILE_HEIGHT + sx + sy * TILE_WIDTH] + 1;
 }
 
 Background::Background() : _priorityLayer(0), _points1(0), _points2(0), _data(0) {
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index f34aa07caf..85d1f1589c 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -45,7 +45,7 @@ struct TileMap {
 	uint16 h;
 	uint32 size;
 	byte *map;
-	uint8 tileIndexOffset;
+	uint16 tileIndexOffset;
 };
 
 class Background {
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 797ce9c2e8..56eda8f4ff 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -94,6 +94,16 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 		ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
 	}
 
+	uint16 sceneIdStripped = (uint16)sceneId & ~0x8000;
+	if ((((((sceneIdStripped == 0x18) || (sceneIdStripped == 0x26)) ||
+		   (sceneIdStripped == 0x7)) ||
+		  ((sceneIdStripped == 0x17 || (sceneIdStripped == 0x5)))) ||
+		 ((sceneIdStripped == 0x19 || ((sceneIdStripped == 0x34 || (sceneIdStripped == 0x1d)))
+		 ))) || (sceneIdStripped == 0x6)) {
+//		buf2048bytes = buf2048bytes + 0x1800;
+		error("0x8002f404"); //TODO do we need this logic?
+	}
+
 	if (!(sceneId & 0x8000)) {
 		byte *obd = _dragonRMS->getObdDataField10(sceneId);
 		ScriptOpCall scriptOpCall;


Commit: 3f4ad5b2f224628e748aa7b69c140ac8b8f4f31d
    https://github.com/scummvm/scummvm/commit/3f4ad5b2f224628e748aa7b69c140ac8b8f4f31d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Update priority tilemap when adding/removing overlays
Pathfinding bug fixes

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 46ad33180d..85566f4720 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -584,7 +584,7 @@ bool Actor::isFlagSet(uint32 flag) {
 	return (flags & flag) == flag;
 }
 
-uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType) {
+uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 unkType) {
 	debug(1, "pathfindingUnk. (%X,%X) -> (%X,%X) %d", x_pos, y_pos, target_x, target_y, unkType);
 
 	if (unkType == 2) {
@@ -593,16 +593,17 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 	uint16 width = getEngine()->_scene->getStageWidth();
 	uint16 height = getEngine()->_scene->getStageHeight();
 
-	if (unkType & 0x8000
-	|| actor_x < 0
-	|| width - 1 < actor_x
-	|| actor_y < 0
-	|| height - 1 < actor_y
-	|| target_x < 0
-	|| width - 1 < target_x
-	|| target_y < 0
-	|| height - 1 < target_y) {
-		return 0;
+	if (unkType & 0x8000) {
+		if (actor_x < 0
+			|| width - 1 < actor_x
+			|| actor_y < 0
+			|| height - 1 < actor_y
+			|| target_x < 0
+			|| width - 1 < target_x
+			|| target_y < 0
+			|| height - 1 < target_y) {
+			return 0;
+		}
 	}
 
 	int32 x_increment = 0;
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index f89f15df52..6a74dabf88 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -137,7 +137,7 @@ public:
 
 private:
 	void pathfindingCleanup();
-	uint16 pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType);
+	uint16 pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 unkType);
 	int16 pathfindingUpdateTarget(int16 newTargetX, int16 newTargetY);
 	int16 pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType,
 									  uint8 *pointsInUseTbl);
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 6cb6b1bd53..74a42cc5f1 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -38,9 +38,11 @@ void Dragons::PriorityLayer::load(TileMap &tileMap, byte *tiles) {
 	_mapHeight = tileMap.h;
 	size_t tileSize = (size_t)tileMap.tileIndexOffset * TILE_SIZE;
 	_map = new byte[tileMap.size];
+	_mapBase = new byte[tileMap.size];
 	_values = new byte[tileSize];
 
 	memcpy(_map, tileMap.map, tileMap.size);
+	memcpy(_mapBase, tileMap.map, tileMap.size);
 	memcpy(_values, tiles, tileSize);
 }
 
@@ -61,6 +63,27 @@ int16 PriorityLayer::getPriority(Common::Point pos) {
 	return _values[mapIndex * TILE_WIDTH * TILE_HEIGHT + sx + sy * TILE_WIDTH] + 1;
 }
 
+void PriorityLayer::overlayTileMap(byte *data, int16 x, int16 y, int16 w, int16 h) {
+	byte *ptr = _map + (x + y * _mapWidth) * 2;
+	byte *src = data;
+	for (int i=0;i < h; i++) {
+		memcpy(ptr, src, w * 2);
+		src += w * 2;
+		ptr += _mapWidth * 2;
+	}
+}
+
+void PriorityLayer::restoreTileMap(int16 x, int16 y, int16 w, int16 h) {
+	byte *ptr = _map + (x + y * _mapWidth) * 2;
+	byte *src = _mapBase + (x + y * _mapWidth) * 2;
+	for (int i=0;i < h; i++) {
+		memcpy(ptr, src, w * 2);
+		src += _mapWidth * 2;
+		ptr += _mapWidth * 2;
+	}
+
+}
+
 Background::Background() : _priorityLayer(0), _points1(0), _points2(0), _data(0) {
 	_layer[0] = NULL;
 	_layer[1] = NULL;
@@ -213,6 +236,14 @@ void Background::restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16
 	}
 }
 
+void Background::overlayPriorityTileMap(byte *data, int16 x, int16 y, int16 w, int16 h) {
+	_priorityLayer->overlayTileMap(data, x, y, w, h);
+}
+
+void Background::restorePriorityTileMap(int16 x, int16 y, int16 w, int16 h) {
+	_priorityLayer->restoreTileMap(x, y, w, h);
+}
+
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
 	bigFileArchive), _dragonRMS(dragonRMS) {}
 
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 85d1f1589c..92eb1c3747 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -72,6 +72,8 @@ public:
 	Common::Point getPoint2(uint32 pointIndex);
 	byte *getPalette() { return _palette; }
 
+	void overlayPriorityTileMap(byte *data, int16 x, int16 y, int16 w, int16 h);
+	void restorePriorityTileMap(int16 x, int16 y, int16 w, int16 h);
 	void overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h);
 	void restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h);
 
@@ -85,10 +87,13 @@ class PriorityLayer {
 public:
 	void load(TileMap &tileMap, byte *tiles);
 	int16 getPriority(Common::Point pos);
+	void overlayTileMap(byte *data, int16 x, int16 y, int16 w, int16 h);
+	void restoreTileMap(int16 x, int16 y, int16 w, int16 h);
 protected:
 	int16 _width, _height;
 	int16 _mapWidth, _mapHeight;
 	byte *_map, *_values;
+	byte *_mapBase;
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 481f6febc0..86a6f193be 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -172,16 +172,26 @@ int16 Cursor::updateINIUnderCursor() {
 		}
 	}
 
-	_iniUnderCursor = 0; //TODO remove this once we complete function.
+	// _iniUnderCursor = 0; //TODO remove this once we complete function.
 
 	// TODO 0x80028940
 	int16 inventoryType = _vm->_inventory->getType();
 	if (inventoryType == 1) {
 		// Might be open inventory bag.
 		//TODO 0x80028da8
-	} else if (inventoryType > 2) {
-		_iniUnderCursor = 0;
-		return 0;
+	} else {
+		if (inventoryType < 2) {
+			if (inventoryType != 0) {
+				_iniUnderCursor = 0;
+				return 0;
+			}
+		}
+		else {
+			if (inventoryType != 2) {
+				_iniUnderCursor = 0;
+				return 0;
+			}
+		}
 	}
 
 	return updateIniFromScene();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 598dde4e73..ad3b2776d6 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -485,14 +485,14 @@ void DragonsEngine::gameLoop()
 						_cursor->data_80072890 = _cursor->_iniUnderCursor;
 						if (_cursor->_sequenceID < 5) {
 							_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
-							FUN_8002837c();
+							walkFlickerToObject();
 							if (bit_flags_8006fbd8 != 0) {
 								clearFlags(ENGINE_FLAG_8);
 							}
 						}
 						else {
 							_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
-							FUN_8002837c();
+							walkFlickerToObject();
 							if (bit_flags_8006fbd8 != 0) {
 								clearFlags(ENGINE_FLAG_8);
 							}
@@ -565,7 +565,7 @@ void DragonsEngine::gameLoop()
 						_scriptOpcodes->_data_800728c0 = _cursor->_iniUnderCursor;
 					}
 					clearFlags(ENGINE_FLAG_8);
-					FUN_8002837c();
+					walkFlickerToObject();
 					goto LAB_8002790c;
 				}
 				if (_cursor->_iniUnderCursor != unkArray_uint16[0]) {
@@ -1074,7 +1074,7 @@ void DragonsEngine::FUN_80038890() {
 	error("FUN_80038890"); //TODO
 }
 
-void DragonsEngine::FUN_8002837c()
+void DragonsEngine::walkFlickerToObject()
 {
 	ushort targetX;
 	ushort targetY;
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 6f307ef937..ac5e22991e 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -216,7 +216,7 @@ private:
 	void FUN_8003130c();
 	void actor_related_80030e88();
 	void FUN_80038890();
-	void FUN_8002837c();
+	void walkFlickerToObject();
 	void FUN_80031480();
 	void FUN_80038994();
 
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 56eda8f4ff..7d7a78a3d0 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -394,8 +394,7 @@ void Scene::loadImageOverlay(uint16 iptId) {
 		}
 
 		if (img->field_e == 2 || img->field_e == 0) {
-			// error("img->field_e == 2 || img->field_e == 0");
-			//TODO what does this do? Do we need it? 0x800177f8
+			_stage->overlayPriorityTileMap(img->data + img->w * img->h * 2, img->x, img->y, img->w, img->h);
 		}
 	}
 }
@@ -403,6 +402,7 @@ void Scene::loadImageOverlay(uint16 iptId) {
 void Scene::removeImageOverlay(uint16 iptId) {
 	IMG *img =_vm->_dragonIMG->getIMG(iptId);
 	_stage->restoreTiles(img->layerNum - 1, img->x, img->y, img->w, img->h);
+	_stage->restorePriorityTileMap(img->x, img->y, img->w, img->h);
 }
 
 void Scene::setSceneId(int16 newSceneId) {


Commit: 1746fefb0db37437896f55826a3dfbf5f260a7c7
    https://github.com/scummvm/scummvm/commit/1746fefb0db37437896f55826a3dfbf5f260a7c7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: execute action after walking to location

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index ad3b2776d6..e284398504 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -912,6 +912,79 @@ void DragonsEngine::runINIScripts() {
 		}
 	}
 }
+/*
+void DragonsEngine::engineFlag0x20UpdateFunction() {
+{
+	ushort uVar1;
+	uint16_t uVar2;
+	DragonINI *pDVar3;
+	DragonINI *pDVar4;
+	ushort uVar5;
+	uint actorId;
+
+	DragonINI *flickerINI = _dragonINIResource->getFlickerRecord();
+	uint16 currentSceneId = _scene->getSceneId();
+
+
+//	uVar1 = flickerINI->actorId;
+//	actorId = (uint)uVar1;
+//	uVar5 = dragon_ini_pointer[dragon_ini_const__2 + -1].field_0x1c;
+	if (flickerINI == NULL) {
+		//LAB_80027d40:
+//		if ((flickerINI->sceneId == currentSceneId)
+//			&& (uVar5 != 0xffff)) {
+//			actors[(uint)uVar5]._sequenceID = 8;
+//			actors[(uint)uVar5].priorityLayer_maybe = 0;
+//		}
+	}
+	else {
+		if (flickerINI->sceneId == currentSceneId) {
+			if ((flickerINI == NULL) || flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
+				if ((flickerINI->sceneId == currentSceneId)
+					&& (uVar5 != 0xffff)) {
+//					actors[(uint)uVar5]._sequenceID = 8;
+//					actors[(uint)uVar5].priorityLayer_maybe = 0;
+				}
+			} else {
+				if ((bit_flags_8006fbd8 & 2) == 0) {
+					bit_flags_8006fbd8 = bit_flags_8006fbd8 | 2;
+				}
+//				if (((((actors[actorId].flags & 0x2000) == 0) && ((actors[actorId].flags & 4) != 0)) &&
+//					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
+//				(actors[actorId]._sequenceID2 != -1)) {
+//					actor_update_sequenceID(actorId,actors[actorId]._sequenceID2);
+//				}
+			}
+
+		} else {
+			//actors[(uint)uVar5].priorityLayer_maybe = 0;
+		}
+
+	}
+
+
+	LAB_80027db4:
+	uVar1 = num_ini_records_maybe;
+	pDVar3 = dragon_ini_pointer;
+	uVar2 = currentSceneId;
+	if ((inventoryType == 0) && (uVar5 = 0, num_ini_records_maybe != 0)) {
+		actorId = 0;
+		do {
+			pDVar4 = pDVar3 + actorId;
+			if (((-1 < (int)((uint)pDVar4->field_0x10 << 0x10)) && (pDVar4->sceneId_maybe == uVar2)) &&
+				(pDVar4->field_0x10 = pDVar4->field_0x10 - 1, (int)((uint)pDVar4->field_0x10 << 0x10) < 0))
+			{
+				pDVar4->field_1a_flags_maybe = pDVar4->field_1a_flags_maybe | 0x10;
+			}
+			uVar5 = uVar5 + 1;
+			actorId = (uint)uVar5;
+		} while (uVar5 < uVar1);
+	}
+	if (run_func_ptr_unk_countdown_timer != 0) {
+		run_func_ptr_unk_countdown_timer = run_func_ptr_unk_countdown_timer - 1;
+	}
+	return (uint)run_func_ptr_unk_countdown_timer;
+} */
 
 void DragonsEngine::engineFlag0x20UpdateFunction() {
 	if (_flags & Dragons::ENGINE_FLAG_20) {
@@ -922,6 +995,47 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 
 		uint16 currentSceneId = _scene->getSceneId();
 
+
+		DragonINI *flickerINI = _dragonINIResource->getFlickerRecord();
+//		uint16 currentSceneId = _scene->getSceneId();
+
+
+//	uVar1 = flickerINI->actorId;
+//	actorId = (uint)uVar1;
+//	uVar5 = dragon_ini_pointer[dragon_ini_const__2 + -1].field_0x1c;
+		if (flickerINI == NULL) {
+			//LAB_80027d40:
+//		if ((flickerINI->sceneId == currentSceneId)
+//			&& (uVar5 != 0xffff)) {
+//			actors[(uint)uVar5]._sequenceID = 8;
+//			actors[(uint)uVar5].priorityLayer_maybe = 0;
+//		}
+		}
+		else {
+			if (flickerINI->sceneId == currentSceneId) {
+				if ((flickerINI == NULL) || flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
+					if ((flickerINI->sceneId == currentSceneId)) {
+						//&& (uVar5 != 0xffff)) {
+//					actors[(uint)uVar5]._sequenceID = 8;
+//					actors[(uint)uVar5].priorityLayer_maybe = 0;
+					}
+				} else {
+					if ((bit_flags_8006fbd8 & 2) == 0) {
+						bit_flags_8006fbd8 = bit_flags_8006fbd8 | 2;
+					}
+//				if (((((actors[actorId].flags & 0x2000) == 0) && ((actors[actorId].flags & 4) != 0)) &&
+//					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
+//				(actors[actorId]._sequenceID2 != -1)) {
+//					actor_update_sequenceID(actorId,actors[actorId]._sequenceID2);
+//				}
+				}
+
+			} else {
+				//actors[(uint)uVar5].priorityLayer_maybe = 0;
+			}
+
+		}
+
 		// 0x80027db8
 		if (!_inventory->isVisible()) {
 			for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
@@ -938,8 +1052,6 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 		if (run_func_ptr_unk_countdown_timer != 0) {
 			run_func_ptr_unk_countdown_timer--;
 		}
-	} else {
-		run_func_ptr_unk_countdown_timer = 1;
 	}
 }
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 2464bdd4f1..9f62aaee79 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -883,6 +883,7 @@ uint16 ScriptOpcodes::getINIField(uint32 iniIndex, uint16 fieldOffset) {
 
 	switch (fieldOffset) {
 		case 0 : return ini->iptIndex_maybe;
+		case 4 : return ini->actorResourceId;
 		case 6 : return ini->sequenceId;
 		case 0xC  : return ini->sceneId;
 		case 0x12  : return ini->field_12;
@@ -900,6 +901,7 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 
 	switch (fieldOffset) {
 		case 0 : ini->iptIndex_maybe = value; break;
+		case 4 : ini->actorResourceId = value; break;
 		case 6 : ini->sequenceId = value; break;
 		case 0xc  : ini->sceneId = value; break;
 		case 0x12 : ini->field_12 = value; break;


Commit: 98f935efb989ef5937bfc6b85380abb9cf5e76b7
    https://github.com/scummvm/scummvm/commit/98f935efb989ef5937bfc6b85380abb9cf5e76b7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: update flicker after walking to destination

Changed paths:
    engines/dragons/dragons.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index e284398504..c494173423 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -388,7 +388,9 @@ void DragonsEngine::gameLoop()
 				if (_cursor->_sequenceID != 5) {
 					uVar6 = _cursor->data_80072890;
 				}
-				flicker->actor->_sequenceID2 = getINI(uVar6 - 1)->field_e;
+				if (uVar6 > 0) {
+					flicker->actor->_sequenceID2 = getINI(uVar6 - 1)->field_e;
+				}
 			}
 
 			works_with_obd_data_1();
@@ -588,7 +590,7 @@ void DragonsEngine::gameLoop()
 					actor->flags = 0;
 					actor->priorityLayer = 0;
 					actor->field_e = 0x100;
-					actor->updateSequence(getINI((uint)*puVar9 - 1)->field_1a_flags_maybe * 2 + 10);
+					actor->updateSequence(getINI((uint)*puVar9 - 1)->field_1a_flags_maybe * 2 + 10); //TODO this doesn't look right
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);
@@ -1023,6 +1025,12 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 					if ((bit_flags_8006fbd8 & 2) == 0) {
 						bit_flags_8006fbd8 = bit_flags_8006fbd8 | 2;
 					}
+					if (flickerINI->actor->isFlagClear(ACTOR_FLAG_2000)
+					&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
+					&& flickerINI->actor->_sequenceID2 != -1
+					&& flickerINI->actor->_sequenceID2 != flickerINI->actor->_sequenceID)	{
+						flickerINI->actor->updateSequence(flickerINI->actor->_sequenceID2);
+					}
 //				if (((((actors[actorId].flags & 0x2000) == 0) && ((actors[actorId].flags & 4) != 0)) &&
 //					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
 //				(actors[actorId]._sequenceID2 != -1)) {
@@ -1112,6 +1120,7 @@ void DragonsEngine::works_with_obd_data_1() {
 	uVar6 = 0;
 	_scriptOpcodes->_data_80071f5c = 0;
 
+	assert(_cursor->data_80072890 > 0);
 	byte *obd = _dragonOBD->getFromOpt(_cursor->data_80072890 - 1);
 
 


Commit: 0acc07116f6f02a5a7376769fbbb1b3cc61f944a
    https://github.com/scummvm/scummvm/commit/0acc07116f6f02a5a7376769fbbb1b3cc61f944a
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fix issue with cursor hover animations

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 86a6f193be..cc072f199b 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -52,7 +52,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
 	_iniUnderCursor = 0;
 	data_8007283c = 0;
-	data_either_5_or_0 = 0;
+	_cursorActivationSeqOffset = 0;
 	data_800728b0_cursor_seqID = 0;
 }
 
@@ -100,16 +100,16 @@ void Cursor::update() {
 		if ((_iniUnderCursor != 0x8001) || ((inventorySequenceID != 0 && (inventorySequenceID != 3)))) {
 			if (_sequenceID == 5) {
 				uint16 uVar1 = (uint) data_8007283c;
-				if (data_either_5_or_0 != 0) {
+				if (_cursorActivationSeqOffset != 0) {
 					uVar1 = uVar1 + 1;
 				}
 				if (uVar1 == (uint) _actor->_sequenceID) {
 					return;
 				}
-				_actor->updateSequence((uint) data_8007283c + (uint) (data_either_5_or_0 != 0));
+				_actor->updateSequence((uint) data_8007283c + (uint) (_cursorActivationSeqOffset != 0));
 			} else {
-				if (_sequenceID + (uint) data_either_5_or_0 != (uint) _actor->_sequenceID) {
-					_actor->updateSequence(_sequenceID + (uint) data_either_5_or_0);
+				if (_sequenceID + (uint) _cursorActivationSeqOffset != (uint) _actor->_sequenceID) {
+					_actor->updateSequence(_sequenceID + (uint) _cursorActivationSeqOffset);
 				}
 			}
 			return;
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 736a7e3fd9..b2be91c4d4 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -41,11 +41,11 @@ public:
 	int16 _x;
 	int16 _y;
 	int16 data_8007283c;
+	int16 _cursorActivationSeqOffset;
 private:
 	DragonsEngine *_vm;
 	Actor *_actor;
 
-	int16 data_either_5_or_0;
 
 public:
 	Cursor(DragonsEngine *vm);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index c494173423..f683ad6694 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -66,7 +66,6 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	data_8006a3a0_flag = 0;
 	data_800633fa = 0;
 	data_8006f3a8 = 0;
-	_data_either_5_or_0 = 0;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
 
@@ -81,6 +80,8 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 		opCode1A_tbl[i].field6 = 0;
 		opCode1A_tbl[i].field8 = 0;
 	}
+
+	memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -268,7 +269,7 @@ void DragonsEngine::gameLoop()
 	ushort *puVar9;
 	ScriptOpCall local_30;
 
-	_data_either_5_or_0 = 0;
+	_cursor->_cursorActivationSeqOffset = 0;
 	bit_flags_8006fbd8 = 0;
 	_counter = 0;
 	setFlags(ENGINE_FLAG_8);
@@ -340,10 +341,10 @@ void DragonsEngine::gameLoop()
 
 		if (_cursor->updateINIUnderCursor() == 0 ||
 			(!(_cursor->_iniUnderCursor & 0x8000) && (getINI(_cursor->_iniUnderCursor - 1)->field_1a_flags_maybe & 0x4000) != 0)) { //TODO check this. This logic looks a bit strange.
-			_data_either_5_or_0 = 0;
+			_cursor->_cursorActivationSeqOffset = 0;
 		}
 		else {
-			_data_either_5_or_0 = 5;
+			_cursor->_cursorActivationSeqOffset = 5;
 		}
 
 		if (_rightMouseButtonUp && isInputEnabled()) {
@@ -423,7 +424,7 @@ void DragonsEngine::gameLoop()
 						else {
 							_counter = 0;
 							_inventory->setType(1);
-							actor_related_80030e88();
+							_inventory->actor_related_80030e88();
 							joined_r0x80027a38:
 							if (data_8006f3a8 == 0) {
 								_cursor->_sequenceID = 1;
@@ -513,7 +514,7 @@ void DragonsEngine::gameLoop()
 						_counter = 0;
 						_inventory->setType(1);
 						_inventory->_old_showing_value = uVar6;
-						actor_related_80030e88();
+						_inventory->actor_related_80030e88();
 						goto joined_r0x80027a38;
 					}
 					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) goto LAB_80027ab4;
@@ -996,10 +997,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 		//TODO 0x80027be4
 
 		uint16 currentSceneId = _scene->getSceneId();
-
-
 		DragonINI *flickerINI = _dragonINIResource->getFlickerRecord();
-//		uint16 currentSceneId = _scene->getSceneId();
 
 
 //	uVar1 = flickerINI->actorId;
@@ -1007,6 +1005,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 //	uVar5 = dragon_ini_pointer[dragon_ini_const__2 + -1].field_0x1c;
 		if (flickerINI == NULL) {
 			//LAB_80027d40:
+			//error("LAB_80027d40"); //TODO is this logic required?
 //		if ((flickerINI->sceneId == currentSceneId)
 //			&& (uVar5 != 0xffff)) {
 //			actors[(uint)uVar5]._sequenceID = 8;
@@ -1015,11 +1014,10 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 		}
 		else {
 			if (flickerINI->sceneId == currentSceneId) {
-				if ((flickerINI == NULL) || flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
-					if ((flickerINI->sceneId == currentSceneId)) {
-						//&& (uVar5 != 0xffff)) {
-//					actors[(uint)uVar5]._sequenceID = 8;
-//					actors[(uint)uVar5].priorityLayer_maybe = 0;
+				if (flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
+					if (_inventory->isActorSet()) {
+						_inventory->setActorSequenceId(8);
+						_inventory->setPriority(0);
 					}
 				} else {
 					if ((bit_flags_8006fbd8 & 2) == 0) {
@@ -1028,18 +1026,12 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 					if (flickerINI->actor->isFlagClear(ACTOR_FLAG_2000)
 					&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
 					&& flickerINI->actor->_sequenceID2 != -1
-					&& flickerINI->actor->_sequenceID2 != flickerINI->actor->_sequenceID)	{
+					&& flickerINI->actor->_sequenceID2 != flickerINI->actor->_sequenceID) {
 						flickerINI->actor->updateSequence(flickerINI->actor->_sequenceID2);
 					}
-//				if (((((actors[actorId].flags & 0x2000) == 0) && ((actors[actorId].flags & 4) != 0)) &&
-//					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
-//				(actors[actorId]._sequenceID2 != -1)) {
-//					actor_update_sequenceID(actorId,actors[actorId]._sequenceID2);
-//				}
 				}
-
 			} else {
-				//actors[(uint)uVar5].priorityLayer_maybe = 0;
+				_inventory->setPriority(0); //TODO I don't think this is quite right.
 			}
 
 		}
@@ -1187,10 +1179,6 @@ void DragonsEngine::FUN_8003130c() {
 	error("FUN_8003130c"); //TODO
 }
 
-void DragonsEngine::actor_related_80030e88() {
-	error("actor_related_80030e88"); //TODO
-}
-
 void DragonsEngine::FUN_80038890() {
 	error("FUN_80038890"); //TODO
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index ac5e22991e..45f54bd1f1 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -147,7 +147,6 @@ private:
 	uint32 _counter;
 	uint32 bit_flags_8006fbd8;
 	uint16 data_8006a3a0_flag; // screen related flags?
-	int16 _data_either_5_or_0;
 	//unk
 
 	uint16 run_func_ptr_unk_countdown_timer;
@@ -214,7 +213,6 @@ private:
 	bool checkForActionButtonRelease();
 
 	void FUN_8003130c();
-	void actor_related_80030e88();
 	void FUN_80038890();
 	void walkFlickerToObject();
 	void FUN_80031480();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 339f0ab1c5..4bc8c4df00 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -23,6 +23,7 @@
 #include "actor.h"
 #include "dragons.h"
 #include "dragonrms.h"
+#include "dragonini.h"
 #include "inventory.h"
 
 namespace Dragons {
@@ -88,4 +89,35 @@ void Inventory::setActorFlag400() {
 	_actor->setFlag(ACTOR_FLAG_400);
 }
 
+void Inventory::setPriority(uint16 priority) {
+	_actor->priorityLayer = priority;
+}
+
+void Inventory::setActorSequenceId(int32 sequenceId) {
+	if (isActorSet()) {
+		_actor->_sequenceID = sequenceId;
+	}
+}
+
+void Inventory::actor_related_80030e88() {
+
+	for(int i = 0; i < 0x29; i++) {
+		Actor *item = _vm->_actorManager->getActor(i + 0x17);
+
+		item->x_pos = 0x28; //TODO
+		item->y_pos = 0x28;
+
+		if (_vm->unkArray_uint16[i]) {
+			item->field_e = 0x100;
+			item->priorityLayer = 0;
+			item->updateSequence(_vm->getINI(_vm->unkArray_uint16[i] - 1)->field_8 * 2 + 10);
+			item->setFlag(ACTOR_FLAG_200); //80 + 40
+			item->setFlag(ACTOR_FLAG_100);
+			item->setFlag(ACTOR_FLAG_80);
+			item->setFlag(ACTOR_FLAG_40);
+			item->priorityLayer = 6;
+		}
+	}
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 150279bc75..9f85d124bb 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -45,11 +45,12 @@ public:
 
 	void init(ActorManager *actorManager);
 	void loadScene(uint32 sceneId);
+	bool isActorSet() { return true; }
 
 	int32 getSequenceId() {
 		return _sequenceId;
 	}
-
+	void setActorSequenceId(int32 sequenceId);
 	int16 getType() { return _type; }
 	void setType(int16 newType) { _type = newType; }
 
@@ -65,7 +66,9 @@ public:
 
 	void updateVisibility();
 	void setActorFlag400();
+	void setPriority(uint16 priority);
 
+	void actor_related_80030e88();
 };
 
 } // End of namespace Dragons


Commit: 2805bb4cab35c3c33b92fbd7b42a8cdd30c8abfc
    https://github.com/scummvm/scummvm/commit/2805bb4cab35c3c33b92fbd7b42a8cdd30c8abfc
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: show hide inventory bag

Changed paths:
  A engines/dragons/bag.cpp
  A engines/dragons/bag.h
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/module.mk
    engines/dragons/scene.cpp
    engines/dragons/scene.h


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 74a42cc5f1..d5ab39b69e 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -169,20 +169,20 @@ Graphics::Surface *Background::loadGfxLayer(TileMap &tileMap, byte *tiles) {
 		for(int x = 0; x < tileMap.w; x++) {
 			uint16 idx = READ_LE_UINT16(&tileMap.map[(y * tileMap.w + x) * 2]) + tileMap.tileIndexOffset;
 			//debug("tileIdx: %d", idx);
-			drawTileToSurface(surface, tiles + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
+			drawTileToSurface(surface, _palette, tiles + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
 		}
 	}
 	return surface;
 }
 
-void Background::drawTileToSurface(Graphics::Surface *surface, byte *tile, uint32 x, uint32 y) {
+void drawTileToSurface(Graphics::Surface *surface, byte *palette, byte *tile, uint32 x, uint32 y) {
 	byte *pixels = (byte *)surface->getPixels();
 	for(int ty = 0; ty < TILE_HEIGHT; ty++) {
 		for(int tx = 0; tx < TILE_WIDTH; tx++) {
 			uint32 cidx = *tile;
 			uint32 offset = (y + ty) * surface->pitch + (x + tx) * 2;
-			pixels[offset] = _palette[cidx * 2];
-			pixels[offset + 1] = _palette[cidx * 2 + 1];
+			pixels[offset] = palette[cidx * 2];
+			pixels[offset + 1] = palette[cidx * 2 + 1];
 			tile++;
 		}
 	}
@@ -216,6 +216,7 @@ void Background::overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int
 		for(int j = 0; j < w; j++ ) {
 			int16 idx = READ_LE_UINT16(data) + _tileMap[layerNum].tileIndexOffset;
 			drawTileToSurface(_layer[layerNum],
+					_palette,
 					_tileDataOffset + idx * 0x100,
 					(j + x) * TILE_WIDTH,
 					(i + y) * TILE_HEIGHT);
@@ -231,7 +232,7 @@ void Background::restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16
 		for(int x = 0; x < tmw; x++) {
 			uint16 idx = READ_LE_UINT16(&_tileMap[layerNum].map[(y * _tileMap[layerNum].w + x) * 2]) + _tileMap[layerNum].tileIndexOffset;
 			//debug("tileIdx: %d", idx);
-			drawTileToSurface(_layer[layerNum], _tileDataOffset + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
+			drawTileToSurface(_layer[layerNum], _palette, _tileDataOffset + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
 		}
 	}
 }
@@ -250,6 +251,10 @@ BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchiv
 Background *BackgroundResourceLoader::load(uint32 sceneId) {
 	char filename[] = "nnnn.scr";
 	memcpy(filename, _dragonRMS->getSceneName(sceneId), 4);
+	return load(filename);
+}
+
+Background *BackgroundResourceLoader::load(const char *filename) {
 	debug("Loading %s", filename);
 	uint32 size;
 	byte *scrData = _bigFileArchive->load(filename, size);
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 92eb1c3747..5483c04a82 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -31,6 +31,8 @@ namespace Dragons {
 class PriorityLayer;
 class Background;
 
+void drawTileToSurface(Graphics::Surface *surface, byte *palette, byte *tile, uint32 x, uint32 y);
+
 class BackgroundResourceLoader {
 private:
 	BigfileArchive *_bigFileArchive;
@@ -38,6 +40,7 @@ private:
 public:
 	BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS);
 	Background *load(uint32 sceneId);
+	Background *load(const char *filename);
 };
 
 struct TileMap {
@@ -80,7 +83,6 @@ public:
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
 	Graphics::Surface *loadGfxLayer(TileMap &tileMap, byte *tiles);
-	void drawTileToSurface(Graphics::Surface *surface, byte *tile, uint32 x, uint32 y);
 };
 
 class PriorityLayer {
diff --git a/engines/dragons/bag.cpp b/engines/dragons/bag.cpp
new file mode 100644
index 0000000000..3f1a599c25
--- /dev/null
+++ b/engines/dragons/bag.cpp
@@ -0,0 +1,91 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <common/memstream.h>
+#include "bigfile.h"
+#include "screen.h"
+#include "bag.h"
+#include "background.h"
+
+namespace Dragons {
+
+#define TILEMAP_WIDTH 10
+#define TILEMAP_HEIGHT 25
+
+Bag::Bag(BigfileArchive *bigFileArchive, Screen *screen): _screen(screen) {
+	_surface = NULL;
+	_position.x = 0;
+	_position.y = 0;
+	load(bigFileArchive);
+}
+
+Bag::~Bag() {
+	_surface->free();
+	delete _surface;
+}
+
+void Bag::updatePosition(Common::Point newPos) {
+	_position = newPos;
+}
+
+void Bag::draw() {
+	_screen->copyRectToSurface(*_surface, _position.x, _position.y, Common::Rect(_surface->w, _surface->h));
+}
+
+void Bag::load(BigfileArchive *bigFileArchive) {
+	byte pal[512];
+	byte tilemap[0x1f4];
+	byte *tiles;
+	uint32 size;
+	byte *scrData = bigFileArchive->load("bag.scr", size);
+	Common::MemoryReadStream stream(scrData, size, DisposeAfterUse::YES);
+
+	stream.seek(0x4);
+	stream.read(pal, 512);
+	pal[0] = 0x80; //FIXME update palette
+	pal[1] = 0x80;
+
+	stream.seek(0x308);
+	stream.read(tilemap, 0x1f4);
+
+	stream.seek(0xadc);
+
+	size = stream.readUint32LE();
+	tiles = (byte *)malloc(size);
+	stream.read(tiles, size);
+
+	_surface = new Graphics::Surface();
+	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
+	_surface->create(320, 200, pixelFormat16);
+
+	for(int y = 0; y < TILEMAP_HEIGHT; y++) {
+		for(int x = 0; x < TILEMAP_WIDTH; x++) {
+			uint16 idx = READ_LE_UINT16(&tilemap[(y * TILEMAP_WIDTH + x) * 2]);
+			//debug("tileIdx: %d", idx);
+			drawTileToSurface(_surface, pal, tiles + idx * 0x100, x * 32, y * 8);
+		}
+	}
+
+	free(tiles);
+}
+
+} // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/bag.h b/engines/dragons/bag.h
new file mode 100644
index 0000000000..f58ce42aed
--- /dev/null
+++ b/engines/dragons/bag.h
@@ -0,0 +1,53 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SCUMMVM_BAG_H
+#define SCUMMVM_BAG_H
+
+#include <graphics/surface.h>
+#include <common/rect.h>
+
+namespace Dragons {
+
+class BigfileArchive;
+class Screen;
+
+class Bag {
+private:
+	Screen *_screen;
+	Graphics::Surface *_surface;
+	Common::Point _position;
+
+public:
+	Bag(BigfileArchive *bigFileArchive, Screen *screen);
+	~Bag();
+	void updatePosition(Common::Point newPos);
+	void draw();
+	Common::Point getPosition() { return _position; }
+
+private:
+	void load(BigfileArchive *bigFileArchive);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_BAG_H
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index cc072f199b..b653e65f74 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -54,6 +54,10 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	data_8007283c = 0;
 	_cursorActivationSeqOffset = 0;
 	data_800728b0_cursor_seqID = 0;
+
+	for(int i = 0x17; i < 0x29; i++) {
+		actorManager->loadActor(0, i); //TODO hack this should be with inventory
+	}
 }
 
 
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index f683ad6694..162f335839 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -40,6 +40,7 @@
 #include "screen.h"
 #include "sequenceopcodes.h"
 #include "scriptopcodes.h"
+#include "bag.h"
 
 namespace Dragons {
 
@@ -131,13 +132,14 @@ Common::Error DragonsEngine::run() {
 	ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
 	_actorManager = new ActorManager(actorResourceLoader);
 	_scriptOpcodes = new ScriptOpcodes(this, _dragonFLG);
-	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
+	_backgroundResourceLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
+	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource, _backgroundResourceLoader);
 	_flags = 0x1046;
 	_flags &= 0x1c07040;
 	_flags |= 0x26;
 
 	_cursor->init(_actorManager, _dragonINIResource);
-	_inventory->init(_actorManager);
+	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen));
 
 	uint16 sceneId = 0x12;
 	_dragonINIResource->getFlickerRecord()->sceneId = sceneId; //TODO
@@ -424,7 +426,7 @@ void DragonsEngine::gameLoop()
 						else {
 							_counter = 0;
 							_inventory->setType(1);
-							_inventory->actor_related_80030e88();
+							_inventory->openInventory();
 							joined_r0x80027a38:
 							if (data_8006f3a8 == 0) {
 								_cursor->_sequenceID = 1;
@@ -514,7 +516,7 @@ void DragonsEngine::gameLoop()
 						_counter = 0;
 						_inventory->setType(1);
 						_inventory->_old_showing_value = uVar6;
-						_inventory->actor_related_80030e88();
+						_inventory->openInventory();
 						goto joined_r0x80027a38;
 					}
 					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) goto LAB_80027ab4;
@@ -528,7 +530,7 @@ void DragonsEngine::gameLoop()
 		if (checkForInventoryButtonRelease()) {
 			_counter = 0;
 			LAB_80027970:
-			FUN_80031480();
+			_inventory->closeInventory();
 			uVar6 = _inventory->_old_showing_value;
 			_inventory->_old_showing_value = _inventory->getType();
 			actorId = uVar3;
@@ -540,7 +542,7 @@ void DragonsEngine::gameLoop()
 			_counter = 0;
 			if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
 				if (_cursor->_iniUnderCursor == 0x8001) {
-					FUN_80031480();
+					_inventory->closeInventory();
 					_inventory->setType(0);
 					if (_inventory->_old_showing_value == 2) {
 						FUN_80038994();
@@ -548,7 +550,7 @@ void DragonsEngine::gameLoop()
 				}
 				else {
 					if (_cursor->_iniUnderCursor != 0x8002) goto LAB_8002790c;
-					FUN_80031480();
+					_inventory->closeInventory();
 					_inventory->setType(2);
 					if (_inventory->_old_showing_value != 2) {
 						FUN_80038890();
@@ -1255,10 +1257,6 @@ void DragonsEngine::walkFlickerToObject()
 	return;
 }
 
-void DragonsEngine::FUN_80031480() {
-	error("FUN_80031480"); //TODO
-}
-
 void DragonsEngine::FUN_80038994() {
 	error("FUN_80038994"); //TODO
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 45f54bd1f1..efa5cd9c25 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -61,7 +61,7 @@ enum Flags {
 	ENGINE_FLAG_10 = 0x10,
 	ENGINE_FLAG_20 = 0x20,
 	ENGINE_FLAG_40 = 0x40,
-	ENGINE_FLAG_80 = 0x80,
+	ENGINE_FLAG_80 = 0x80, // Inventory bag visible
 	ENGINE_FLAG_100 = 0x100,
 	ENGINE_FLAG_200 = 0x200,
 	ENGINE_FLAG_400 = 0x400,
@@ -215,7 +215,6 @@ private:
 	void FUN_8003130c();
 	void FUN_80038890();
 	void walkFlickerToObject();
-	void FUN_80031480();
 	void FUN_80038994();
 
 	void FUN_8002931c();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 4bc8c4df00..0598e9f759 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -24,7 +24,9 @@
 #include "dragons.h"
 #include "dragonrms.h"
 #include "dragonini.h"
+#include "background.h"
 #include "inventory.h"
+#include "bag.h"
 
 namespace Dragons {
 
@@ -40,9 +42,10 @@ Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 	_sequenceId = 0;
 	_screenPositionIndex = 0;
 	_old_showing_value = 0;
+	_bag = NULL;
 }
 
-void Inventory::init(ActorManager *actorManager) {
+void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag) {
 	_actor = actorManager->loadActor(1, 1); //Load inventory
 	_actor->x_pos = 2;
 	_actor->y_pos = 0;
@@ -55,6 +58,7 @@ void Inventory::init(ActorManager *actorManager) {
 	_sequenceId = 0;
 	_type = 0;
 	_old_showing_value = 0;
+	_bag = bag;
 }
 
 
@@ -99,7 +103,23 @@ void Inventory::setActorSequenceId(int32 sequenceId) {
 	}
 }
 
-void Inventory::actor_related_80030e88() {
+void Inventory::openInventory() {
+	//TODO 0x80030e8c
+	_sequenceId = 4;
+
+	if (!_vm->isFlagSet(ENGINE_FLAG_400000)) {
+		_sequenceId = 2;
+	}
+	_actor->updateSequence(_sequenceId);
+	_screenPositionIndex = 1;
+	_actor->x_pos = positionTable[_screenPositionIndex].x;
+	if ((_sequenceId == 0) || (_sequenceId == 2)) {
+		_actor->x_pos = positionTable[_screenPositionIndex].x + 0x32;
+	}
+	_actor->y_pos = positionTable[_screenPositionIndex].y;
+	animateBagIn();
+
+	//TODO 0x800310e0 update cursor position.
 
 	for(int i = 0; i < 0x29; i++) {
 		Actor *item = _vm->_actorManager->getActor(i + 0x17);
@@ -120,4 +140,72 @@ void Inventory::actor_related_80030e88() {
 	}
 }
 
+void Inventory::animateBagIn() {
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->setFlags(ENGINE_FLAG_80);
+
+	Common::Point pos = _bag->getPosition();
+	pos.y = -228;
+	int16 accel = 8;
+
+	while (pos.y < 0) {
+		pos.y += accel;
+		_bag->updatePosition(pos);
+		_vm->waitForFrames(1);
+		accel += 2;
+	}
+
+	_vm->playSound(0x8001);
+
+	// TODO wait here
+
+	pos.y = 0;
+	_bag->updatePosition(pos);
+
+	_vm->setFlags(ENGINE_FLAG_8);
+	_vm->setFlags(ENGINE_FLAG_10);
+}
+
+void Inventory::animateBagOut() {
+	_vm->playSound(0x8000);
+	Common::Point pos = _bag->getPosition();
+	if (pos.y != 0xc8) {
+		for (;pos.y != 0xc8; pos.y += 0x19) {
+			_bag->updatePosition(pos);
+			_vm->waitForFrames(1);
+		}
+	}
+	_vm->clearFlags(ENGINE_FLAG_80);
+}
+
+void Inventory::closeInventory() {
+	_vm->_actorManager->clearActorFlags(0x17);
+	_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(_vm->getCurrentSceneId());
+
+	if (!_vm->isFlagSet(ENGINE_FLAG_400000)) {
+		_sequenceId = 0;
+	}
+	else {
+		if (_old_showing_value == 2) {
+			_sequenceId = 3;
+		}
+		else {
+			_sequenceId = 1;
+		}
+	}
+	_actor->updateSequence(_sequenceId);
+	_actor->x_pos = positionTable[_screenPositionIndex].x;
+	if (((_sequenceId == 0) || (_sequenceId == 2)) && ((_screenPositionIndex == 1 || (_screenPositionIndex == 3)))) {
+		_actor->x_pos += 0x32;
+	}
+	_actor->y_pos = positionTable[_screenPositionIndex].y;
+	animateBagOut();
+}
+
+void Inventory::draw() {
+	if(_bag) {
+		_bag->draw();
+	}
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 9f85d124bb..1d347bdf9a 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -29,6 +29,9 @@ namespace Dragons {
 
 class Actor;
 class ActorManager;
+class BackgroundResourceLoader;
+class Background;
+class Bag;
 
 class Inventory {
 public:
@@ -39,11 +42,11 @@ private:
 	int16 _screenPositionIndex;
 	Actor *_actor;
 	int16 _type;
-
+	Bag *_bag;
 public:
 	Inventory(DragonsEngine *vm);
 
-	void init(ActorManager *actorManager);
+	void init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag);
 	void loadScene(uint32 sceneId);
 	bool isActorSet() { return true; }
 
@@ -68,7 +71,13 @@ public:
 	void setActorFlag400();
 	void setPriority(uint16 priority);
 
-	void actor_related_80030e88();
+	void openInventory();
+	void closeInventory();
+
+	void draw();
+private:
+	void animateBagIn();
+	void animateBagOut();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index a971380a3f..1b5a5b1d6e 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -4,6 +4,7 @@ MODULE_OBJS := \
     actor.o \
     actorresource.o \
     background.o \
+    bag.o \
     bigfile.o \
     cursor.o \
 	detection.o \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 7d7a78a3d0..946edcdbde 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -34,9 +34,8 @@
 namespace Dragons {
 
 
-Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource)
-		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource) {
-	_backgroundLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
+Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader)
+		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource), _backgroundLoader(backgroundResourceLoader) {
 	data_80063392 = 2;
 	_data_800633ee = 0;
 }
@@ -321,6 +320,10 @@ void Scene::draw() {
 			_screen->copyRectToSurface(*_stage->getMgLayer(), 0, 0, rect);
 		} else if (priority == 3) {
 			_screen->copyRectToSurface(*_stage->getFgLayer(), 0, 0, rect);
+		} else if (priority == 4) { //TODO check if this is the correct priority
+			if (_vm->isFlagSet(ENGINE_FLAG_80)) {
+				_vm->_inventory->draw();
+			}
 		}
 
 		for (uint16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 37e761d3ed..068a6d4ebc 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -30,6 +30,7 @@ namespace Dragons {
 class DragonsEngine;
 class ActorManager;
 class Background;
+class Bag;
 class DragonRMS;
 class BackgroundResourceLoader;
 class DragonINIResource;
@@ -56,9 +57,10 @@ private:
 
 	int16 _currentSceneId;
 	int16 _data_800633ee;
+	Bag *bag;
 
 public:
-	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource);
+	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader);
 
 	void loadScene(uint32 sceneId, uint32 cameraPointId);
 	int16 getPriorityAtPosition(Common::Point pos);


Commit: c2d584533b5cdb244a60a588fdd7a87c4f06f4c4
    https://github.com/scummvm/scummvm/commit/c2d584533b5cdb244a60a588fdd7a87c4f06f4c4
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: bounce the inventory bag when drops in

Changed paths:
    engines/dragons/inventory.cpp


diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 0598e9f759..b8d26e3a66 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -37,6 +37,10 @@ static const Common::Point positionTable[4] = {
 		{0xce,0x9e}
 };
 
+static const int16 bagBounceTable[4] = {
+		-5, -0xa, -5, 0
+};
+
 Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 	_type = 0;
 	_sequenceId = 0;
@@ -131,7 +135,7 @@ void Inventory::openInventory() {
 			item->field_e = 0x100;
 			item->priorityLayer = 0;
 			item->updateSequence(_vm->getINI(_vm->unkArray_uint16[i] - 1)->field_8 * 2 + 10);
-			item->setFlag(ACTOR_FLAG_200); //80 + 40
+			item->setFlag(ACTOR_FLAG_200);
 			item->setFlag(ACTOR_FLAG_100);
 			item->setFlag(ACTOR_FLAG_80);
 			item->setFlag(ACTOR_FLAG_40);
@@ -148,6 +152,7 @@ void Inventory::animateBagIn() {
 	pos.y = -228;
 	int16 accel = 8;
 
+	// Drop bag down into position.
 	while (pos.y < 0) {
 		pos.y += accel;
 		_bag->updatePosition(pos);
@@ -157,10 +162,12 @@ void Inventory::animateBagIn() {
 
 	_vm->playSound(0x8001);
 
-	// TODO wait here
-
-	pos.y = 0;
-	_bag->updatePosition(pos);
+	// Shake bag at the end.
+	for (int i = 0; i < 4; i++) {
+		pos.y = bagBounceTable[i];
+		_bag->updatePosition(pos);
+		_vm->waitForFrames(2);
+	}
 
 	_vm->setFlags(ENGINE_FLAG_8);
 	_vm->setFlags(ENGINE_FLAG_10);


Commit: c9204e3090a49b6f302496f32d4e7e64a79b0d08
    https://github.com/scummvm/scummvm/commit/c9204e3090a49b6f302496f32d4e7e64a79b0d08
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added items to inventory display

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index b653e65f74..a0730161a0 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -54,10 +54,6 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	data_8007283c = 0;
 	_cursorActivationSeqOffset = 0;
 	data_800728b0_cursor_seqID = 0;
-
-	for(int i = 0x17; i < 0x29; i++) {
-		actorManager->loadActor(0, i); //TODO hack this should be with inventory
-	}
 }
 
 
@@ -120,7 +116,7 @@ void Cursor::update() {
 		}
 	}
 
-	if (_vm->data_8006f3a8 == 0) {
+	if (_vm->iniItemInHand == 0) {
 		if (_actor->_sequenceID != 0x84) {
 			_actor->updateSequence(0x84);
 		}
@@ -176,13 +172,14 @@ int16 Cursor::updateINIUnderCursor() {
 		}
 	}
 
-	// _iniUnderCursor = 0; //TODO remove this once we complete function.
-
 	// TODO 0x80028940
 	int16 inventoryType = _vm->_inventory->getType();
 	if (inventoryType == 1) {
-		// Might be open inventory bag.
-		//TODO 0x80028da8
+		int16 invIni = _vm->_inventory->getIniAtPosition(_x, _y);
+		if (invIni > 0) {
+			_iniUnderCursor = invIni;
+			return _iniUnderCursor;
+		}
 	} else {
 		if (inventoryType < 2) {
 			if (inventoryType != 0) {
@@ -337,7 +334,7 @@ void Cursor::selectPreviousCursor() {
 		_sequenceID = 0x10001;
 	}
 	if (_sequenceID == -1) {
-		_sequenceID = _vm->data_8006f3a8 == 0 ? 4 : 5;
+		_sequenceID = _vm->iniItemInHand == 0 ? 4 : 5;
 	}
 }
 
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 162f335839..9495689fb7 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -66,7 +66,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	run_func_ptr_unk_countdown_timer = 0;
 	data_8006a3a0_flag = 0;
 	data_800633fa = 0;
-	data_8006f3a8 = 0;
+	iniItemInHand = 0;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
 
@@ -139,7 +139,7 @@ Common::Error DragonsEngine::run() {
 	_flags |= 0x26;
 
 	_cursor->init(_actorManager, _dragonINIResource);
-	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen));
+	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
 
 	uint16 sceneId = 0x12;
 	_dragonINIResource->getFlickerRecord()->sceneId = sceneId; //TODO
@@ -165,75 +165,6 @@ Common::Error DragonsEngine::run() {
 	return Common::kNoError;
 }
 
-// Not used any more.....
-void DragonsEngine::gameLoopOld() {
-	_counter = 0;
-	bit_flags_8006fbd8 = 0;
-	while (!shouldQuit()) {
-		updateHandler();
-		updateEvents();
-
-		if (getCurrentSceneId() != 2) {
-			_sceneId1 = getCurrentSceneId();
-		}
-
-		_counter++;
-		DragonINI *flickerIni = _dragonINIResource->getFlickerRecord();
-		if (_counter >= 1200 && flickerIni->actor->resourceID == 0xe) { // 0xe == flicker.act
-			Actor *actor = flickerIni->actor;
-			actor->_sequenceID2 = 2;
-			flickerIni->field_20_actor_field_14 = 2;
-
-			actor->updateSequence(getINI(0xc2)->sceneId == 1 ? 0x30 : 2);
-			_counter = 0;
-			setFlags(Dragons::ENGINE_FLAG_80000000);
-		}
-
-		if (_flags & Dragons::ENGINE_FLAG_80000000) {
-			if (flickerIni->actor->flags & Dragons::ACTOR_FLAG_4) {
-				_counter = 0;
-				clearFlags(Dragons::ENGINE_FLAG_80000000);
-			}
-		}
-
-		if (bit_flags_8006fbd8 == 0) {
-			setFlags(Dragons::ENGINE_FLAG_8);
-		}
-
-		if (flickerIni->sceneId == getCurrentSceneId()) {
-			uint16 id = getIniFromImg();
-			if (id != 0) {
-				// 0x80026cac
-				error("todo 0x80026cac run script");
-			} else {
-				// 0x80026d34
-				// $s4_1 = 0;
-			}
-		} else {
-			// 0x80026d34
-			// $s4_1 = 0;
-		}
-
-		// 0x80026d38
-		_cursor->updateINIUnderCursor();
-
-		if (_rightMouseButtonUp && !isFlagSet(ENGINE_FLAG_20000000) && !isFlagSet(ENGINE_FLAG_400)) {
-			_cursor->selectPreviousCursor();
-		}
-
-		// Action input
-		if (_leftMouseButtonUp && !isFlagSet(ENGINE_FLAG_20000000) && !isFlagSet(ENGINE_FLAG_400)) {
-			//TODO
-		}
-
-		runINIScripts();
-
-		_scene->draw();
-		_screen->updateScreen();
-		wait();
-	}
-}
-
 uint16 DragonsEngine::ipt_img_file_related()
 {
 	DragonINI *ini;
@@ -359,7 +290,7 @@ void DragonsEngine::gameLoop()
 //		actorId = CheckButtonMapPress_CycleUp(0);
 //		if (((actorId & 0xffff) != 0) && isInputEnabled()) {
 //			_cursor->_sequenceID = _cursor->_sequenceID + 1;
-//			if (data_8006f3a8 == 0) {
+//			if (iniItemInHand == 0) {
 //				bVar1 = _cursor->_sequenceID < 5;
 //			}
 //			else {
@@ -428,7 +359,7 @@ void DragonsEngine::gameLoop()
 							_inventory->setType(1);
 							_inventory->openInventory();
 							joined_r0x80027a38:
-							if (data_8006f3a8 == 0) {
+							if (iniItemInHand == 0) {
 								_cursor->_sequenceID = 1;
 								actorId = uVar3;
 							}
@@ -446,7 +377,7 @@ void DragonsEngine::gameLoop()
 							if (_cursor->_iniUnderCursor == 0x8002) {
 								LAB_80027294:
 								uVar7 = 0;
-								if (data_8006f3a8 == 0) {
+								if (iniItemInHand == 0) {
 									if ((bit_flags_8006fbd8 & 3) != 1) {
 										sequenceId = _dragonVAR->getVar(7);
 										uVar7 = _inventory->_old_showing_value;
@@ -464,8 +395,8 @@ void DragonsEngine::gameLoop()
 									if (uVar7 < 0x29) {
 										_cursor->_sequenceID = 1;
 										waitForFrames(1);
-										uVar6 = data_8006f3a8;
-										data_8006f3a8 = 0;
+										uVar6 = iniItemInHand;
+										iniItemInHand = 0;
 										_cursor->_iniUnderCursor = 0;
 										unkArray_uint16[(uint)uVar7] = uVar6;
 										actorId = uVar3;
@@ -502,7 +433,7 @@ void DragonsEngine::gameLoop()
 								clearFlags(ENGINE_FLAG_8);
 							}
 							_scriptOpcodes->_data_800728c0 = _cursor->data_80072890;
-							_cursor->data_80072890 = data_8006f3a8;
+							_cursor->data_80072890 = iniItemInHand;
 						}
 					}
 				}
@@ -566,7 +497,7 @@ void DragonsEngine::gameLoop()
 					_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
 					_cursor->data_80072890 = _cursor->_iniUnderCursor;
 					if (4 < _cursor->_sequenceID) {
-						_cursor->data_80072890 = data_8006f3a8;
+						_cursor->data_80072890 = iniItemInHand;
 						_scriptOpcodes->_data_800728c0 = _cursor->_iniUnderCursor;
 					}
 					clearFlags(ENGINE_FLAG_8);
@@ -582,10 +513,10 @@ void DragonsEngine::gameLoop()
 				}
 				puVar9 = unkArray_uint16 + (actorId_00 & 0xffff);
 				Actor *actor = _actorManager->getActor(actorId_00 + 0x17);
-				*puVar9 = data_8006f3a8;
+				*puVar9 = iniItemInHand;
 				_cursor->data_8007283c = actor->_sequenceID;
 				actor->clearFlag(ACTOR_FLAG_40);
-				data_8006f3a8 = _cursor->_iniUnderCursor;
+				iniItemInHand = _cursor->_iniUnderCursor;
 				_cursor->_sequenceID = 5;
 				actorId = uVar3;
 				if (*puVar9 != 0) {
@@ -593,7 +524,7 @@ void DragonsEngine::gameLoop()
 					actor->flags = 0;
 					actor->priorityLayer = 0;
 					actor->field_e = 0x100;
-					actor->updateSequence(getINI((uint)*puVar9 - 1)->field_1a_flags_maybe * 2 + 10); //TODO this doesn't look right
+					actor->updateSequence(getINI((uint)*puVar9 - 1)->field_8 * 2 + 10);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);
@@ -604,27 +535,30 @@ void DragonsEngine::gameLoop()
 				goto LAB_80026a74;
 			}
 			uVar6 = 0;
-			if (data_8006f3a8 == 0) goto LAB_80027b58;
+			if (iniItemInHand == 0) goto LAB_80027b58;
+			//drop item back into inventory
 			actorId = 0;
 			do {
 				Actor *actor = _actorManager->getActor(actorId + 0x17);
-				if (((((int)(short)actor->x_pos + -0x10 <= (int)_cursor->_x) &&
+				if (((((int)(short)actor->x_pos - 0x10 <= (int)_cursor->_x) &&
 					  ((int)_cursor->_x < (int)(short)actor->x_pos + 0x10)) &&
-					 ((int)(short)actor->y_pos + -0xc <= (int)_cursor->_y)) &&
-					(actorId = (uint)uVar6, (int)_cursor->_y < (int)(short)actor->y_pos + 0xc)) break;
+					 ((int)(short)actor->y_pos - 0xc <= (int)_cursor->_y)) &&
+					(actorId = (uint)uVar6, (int)_cursor->_y < (int)(short)actor->y_pos + 0xc)) {
+					break;
+				}
 				uVar6 = uVar6 + 1;
 				actorId = (uint)uVar6;
 			} while (uVar6 < 0x29);
 			if (actorId != 0x29) {
 				actorId_00 = (uint)(ushort)(uVar6 + 0x17);
-				unkArray_uint16[actorId] = data_8006f3a8;
+				unkArray_uint16[actorId] = iniItemInHand;
 				Actor *actor = _actorManager->getActor(actorId_00);
 				actor->flags = 0;
 				actor->priorityLayer = 0;
 				actor->field_e = 0x100;
-				data_8006f3a8 = 0;
+				iniItemInHand = 0;
 				actor->updateSequence(
-						 getINI((uint)unkArray_uint16[actorId] - 1)->field_1a_flags_maybe * 2 + 10);
+						 getINI((uint)unkArray_uint16[actorId] - 1)->field_8 * 2 + 10);
 				uVar6 = _cursor->_sequenceID;
 				actor->setFlag(ACTOR_FLAG_40);
 				actor->setFlag(ACTOR_FLAG_80);
@@ -637,7 +571,7 @@ void DragonsEngine::gameLoop()
 			}
 		}
 		LAB_8002790c:
-		if ((data_8006f3a8 == 0) ||
+		if ((iniItemInHand == 0) ||
 			(((ushort)(_cursor->_x - 10U) < 300 && ((ushort)(_cursor->_y - 10U) < 0xb4))))
 			goto LAB_80027b58;
 		_cursor->_sequenceID = 5;
@@ -800,10 +734,12 @@ void DragonsEngine::updateActorSequences() {
 
 			if (actor->flags & Dragons::ACTOR_FLAG_1) {
 				actor->resetSequenceIP();
-				actor->flags &= 0xeff6; //TODO rewrite using ACTOR_FLAG_nnn
+				//clear flag mask 0xeff6;
+				actor->clearFlag(ACTOR_FLAG_1);
+				actor->clearFlag(ACTOR_FLAG_8);
+				actor->clearFlag(ACTOR_FLAG_1000);
 				actor->field_7a = 0;
 			}
-			//TODO execute sequence Opcode here.
 			OpCall opCall;
 			opCall._result = 1;
 			while (opCall._result == 1) {
@@ -885,22 +821,6 @@ uint16 DragonsEngine::getIniFromImg() {
 	return 0;
 }
 
-uint16 DragonsEngine::updateINIUnderCursor() {
-	int32 x = (_cursorPosition.x + _scene->_camera.x) / 32;
-	int32 y = (_cursorPosition.y + _scene->_camera.y) / 8;
-
-	if (_flags & Dragons::ENGINE_FLAG_10) {
-
-		if (_inventory->getSequenceId() == 0 || _inventory->getSequenceId() == 2) {
-//TODO
-		} else {
-
-		}
-	}
-
-	return 0;
-}
-
 void DragonsEngine::runINIScripts() {
 	for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index efa5cd9c25..0b08a846e7 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -127,7 +127,7 @@ public:
 	uint16 data_800633fa;
 	Inventory *_inventory;
 	Cursor *_cursor;
-	uint16 data_8006f3a8;
+	uint16 iniItemInHand;
 
 	uint16 unkArray_uint16[42];
 	opCode1AStruct opCode1A_tbl[8];
@@ -196,14 +196,12 @@ public:
 	void reset_screen_maybe();
 
 private:
-	void gameLoopOld();
 	void gameLoop();
 	void updateHandler();
 	void updatePathfindingActors();
 	uint32 calulateTimeLeft();
 	void wait();
 	uint16 getIniFromImg();
-	uint16 updateINIUnderCursor();
 	void runINIScripts();
 	void engineFlag0x20UpdateFunction();
 
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index b8d26e3a66..969fcea0ed 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -41,6 +41,24 @@ static const int16 bagBounceTable[4] = {
 		-5, -0xa, -5, 0
 };
 
+static const int16 invXPosTable[41] = {
+				0x0080, 0x00a0, 0x00c0, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+				0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+				0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+				0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+				0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+				0x0100
+};
+
+static const int16 invYPosTable[41] = {
+				0x0028, 0x0028, 0x0028, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040,
+				0x0040, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058,
+				0x0058, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070,
+				0x0070, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088,
+				0x0088, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
+				0x00a0
+};
+
 Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 	_type = 0;
 	_sequenceId = 0;
@@ -49,7 +67,7 @@ Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 	_bag = NULL;
 }
 
-void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag) {
+void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag, DragonINIResource *dragonIniResource) {
 	_actor = actorManager->loadActor(1, 1); //Load inventory
 	_actor->x_pos = 2;
 	_actor->y_pos = 0;
@@ -63,6 +81,18 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_type = 0;
 	_old_showing_value = 0;
 	_bag = bag;
+
+	for(int i = 0x17; i < 0x29; i++) {
+		actorManager->loadActor(0, i); // TODO need to share resource between inventory item actors.
+	}
+
+	int j = 0;
+	for (int i=0; i < dragonIniResource->totalRecords() && j < 0x29; i++ ) {
+		DragonINI *ini = dragonIniResource->getRecord(i);
+		if (ini->sceneId == 1) {
+			_vm->unkArray_uint16[j++] = i + 1;
+		}
+	}
 }
 
 
@@ -128,10 +158,11 @@ void Inventory::openInventory() {
 	for(int i = 0; i < 0x29; i++) {
 		Actor *item = _vm->_actorManager->getActor(i + 0x17);
 
-		item->x_pos = 0x28; //TODO
-		item->y_pos = 0x28;
+		item->x_pos = item->target_x_pos = invXPosTable[i] + 0x10;
+		item->y_pos = item->target_y_pos = invYPosTable[i] + 0xc;
 
 		if (_vm->unkArray_uint16[i]) {
+			item->flags = 0; //clear all flags
 			item->field_e = 0x100;
 			item->priorityLayer = 0;
 			item->updateSequence(_vm->getINI(_vm->unkArray_uint16[i] - 1)->field_8 * 2 + 10);
@@ -215,4 +246,17 @@ void Inventory::draw() {
 	}
 }
 
+uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
+	for (int i = 0; i < 0x29; i++) {
+		if (_vm->unkArray_uint16[i]) {
+			Actor *item = _vm->_actorManager->getActor(i + 0x17);
+			if (item->x_pos - 0x10 <= x && x < item->x_pos + 0x10
+				&& item->y_pos - 0xc <= y && y < item->y_pos + 0xc) {
+				return _vm->unkArray_uint16[i];
+			}
+		}
+	}
+	return 0;
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 1d347bdf9a..a4d933eaa6 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -32,6 +32,7 @@ class ActorManager;
 class BackgroundResourceLoader;
 class Background;
 class Bag;
+class DragonINIResource;
 
 class Inventory {
 public:
@@ -46,7 +47,7 @@ private:
 public:
 	Inventory(DragonsEngine *vm);
 
-	void init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag);
+	void init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag, DragonINIResource *dragonIniResource);
 	void loadScene(uint32 sceneId);
 	bool isActorSet() { return true; }
 
@@ -75,6 +76,7 @@ public:
 	void closeInventory();
 
 	void draw();
+	uint16 getIniAtPosition(int16 x, int16 y);
 private:
 	void animateBagIn();
 	void animateBagOut();
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 9f62aaee79..6a20e77a34 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -992,14 +992,14 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 		}
 
 		if (sceneId == 1) {
-			if (_vm->data_8006f3a8 != 0) {
+			if (_vm->iniItemInHand != 0) {
 				uint16 freeSlot = 0;
 				for( ;_vm->unkArray_uint16[freeSlot] != 0; freeSlot++) {
 					if (_vm->unkArray_uint16[freeSlot] == 0) {
 						break;
 					}
 				}
-				_vm->unkArray_uint16[freeSlot] = _vm->data_8006f3a8;
+				_vm->unkArray_uint16[freeSlot] = _vm->iniItemInHand;
 				if (_vm->_inventory->getType() == 1) {
 					Actor *actor = _vm->_actorManager->getActor(freeSlot + 0x17);
 					actor->flags = 0;
@@ -1019,7 +1019,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 			_vm->_cursor->data_800728b0_cursor_seqID = 5;
 			_vm->_cursor->_sequenceID = 5;
 			_vm->_cursor->data_8007283c = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
-			_vm->data_8006f3a8 = field2;
+			_vm->iniItemInHand = field2;
 		}
 	}
 	ini->sceneId = sceneId;


Commit: 2e7b8b91b5aa570226161665fa4b7fd99c4fcce3
    https://github.com/scummvm/scummvm/commit/2e7b8b91b5aa570226161665fa4b7fd99c4fcce3
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed inventory selection logic

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/cursor.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 85566f4720..2e3ffc362e 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -82,12 +82,16 @@ void ActorManager::clearActorFlags(uint16 startingActorId) {
 	}
 }
 
-Actor *ActorManager::loadActor(uint32 resourceId, uint16 actorId) {
+Actor *ActorManager::loadActor(uint32 resourceId, uint16 actorId) { //TODO should we rename this. loadActorResource or updateActorResource
 	Actor *actor = getActor(actorId);
 	actor->_actorResource = _actorResourceLoader->load(resourceId);
 	return actor;
 }
 
+ActorResource *ActorManager::getActorResource(uint32 resourceId) {
+	return _actorResourceLoader->load(resourceId);
+}
+
 Actor::Actor(uint16 id) : _actorID(id) {
 	_actorResource = NULL;
 	resourceID = -1;
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 6a74dabf88..b0ce3d11af 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -73,7 +73,7 @@ public:
 	Actor *loadActor(uint32 resourceId, uint16 actorId);
 	Actor *getActor(uint16 actorId);
 	void clearActorFlags(uint16 startingActorId);
-
+	ActorResource *getActorResource(uint32 resourceId);
 private:
 	Actor *findFreeActor(int16 resourceID);
 };
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index a0730161a0..98057d0589 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -175,11 +175,8 @@ int16 Cursor::updateINIUnderCursor() {
 	// TODO 0x80028940
 	int16 inventoryType = _vm->_inventory->getType();
 	if (inventoryType == 1) {
-		int16 invIni = _vm->_inventory->getIniAtPosition(_x, _y);
-		if (invIni > 0) {
-			_iniUnderCursor = invIni;
-			return _iniUnderCursor;
-		}
+		_iniUnderCursor = _vm->_inventory->getIniAtPosition(_x, _y);
+		return _iniUnderCursor;
 	} else {
 		if (inventoryType < 2) {
 			if (inventoryType != 0) {
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 0b08a846e7..6beac6fe51 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -132,6 +132,8 @@ public:
 	uint16 unkArray_uint16[42];
 	opCode1AStruct opCode1A_tbl[8];
 
+	uint16 data_800633fc;
+
 private:
 	Screen *_screen;
 	BigfileArchive *_bigfileArchive;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 946edcdbde..297654be92 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -188,8 +188,10 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_vm->clearUnkFlags(Dragons::ENGINE_UNK1_FLAG_10);
 	_vm->setFlags(Dragons::ENGINE_FLAG_20);
 	// TODO reset vsync_updater_function
+
 	_vm->setFlags(Dragons::ENGINE_FLAG_200);
 	_actorManager->clearActorFlags(2);
+	_vm->data_800633fc = 0;
 	// TODO 0x8002fff0
 
 	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 6a20e77a34..15a56e839b 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -307,8 +307,10 @@ void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
 		ini->actor->flags |= Dragons::ACTOR_FLAG_2000;
 	}
 
-	assert(ini->actor->_actorResource);
-	assert(ini->actor->_actorResource->_id == ini->actorResourceId); // TODO need to rework selecting resourceId for an actor.
+	if (!ini->actor->_actorResource || ini->actor->_actorResource->_id != ini->actorResourceId) {
+		ini->actor->_actorResource = _vm->_actorManager->getActorResource(ini->actorResourceId);
+	}
+
 	ini->actor->updateSequence(sequenceId);
 
 	if (field0 & 0x8000) {
@@ -381,7 +383,12 @@ void ScriptOpcodes::opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall) {
 void ScriptOpcodes::opUnk20(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
-	//TODO do we need this? It looks like it is pre-loading scene data.
+
+	_vm->data_800633fc = 0;
+
+	if (field2 >= 2) {
+		//TODO do we need this? It looks like it is pre-loading the next scene's data.
+	}
 }
 
 bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {


Commit: c848548c027ffd2cca2de333490757019a0f59e5
    https://github.com/scummvm/scummvm/commit/c848548c027ffd2cca2de333490757019a0f59e5
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on save/load

Changed paths:
  A engines/dragons/saveload.cpp
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonflg.h
    engines/dragons/dragonini.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/dragonvar.cpp
    engines/dragons/dragonvar.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 98057d0589..61adaeffd5 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -51,6 +51,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	dragonINIResource->getFlickerRecord()->actor = _actor; //TODO is this correct?
 	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
 	_iniUnderCursor = 0;
+	iniItemInHand = 0;
 	data_8007283c = 0;
 	_cursorActivationSeqOffset = 0;
 	data_800728b0_cursor_seqID = 0;
@@ -116,7 +117,7 @@ void Cursor::update() {
 		}
 	}
 
-	if (_vm->iniItemInHand == 0) {
+	if (iniItemInHand == 0) {
 		if (_actor->_sequenceID != 0x84) {
 			_actor->updateSequence(0x84);
 		}
@@ -331,7 +332,7 @@ void Cursor::selectPreviousCursor() {
 		_sequenceID = 0x10001;
 	}
 	if (_sequenceID == -1) {
-		_sequenceID = _vm->iniItemInHand == 0 ? 4 : 5;
+		_sequenceID = iniItemInHand == 0 ? 4 : 5;
 	}
 }
 
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index b2be91c4d4..d9c78fceeb 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -42,6 +42,7 @@ public:
 	int16 _y;
 	int16 data_8007283c;
 	int16 _cursorActivationSeqOffset;
+	uint16 iniItemInHand;
 private:
 	DragonsEngine *_vm;
 	Actor *_actor;
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index e1d7bdc2e1..501500b7d5 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -27,13 +27,22 @@ namespace Dragons {
 
 // Properties
 
-Properties::Properties()
-		: _count(0), _properties(0) {
+Properties::Properties(uint count)
+		: _count(count) {
+	_properties = (byte *)malloc(getSize());
+	if(!_properties) {
+		error("Failed to allocate mem for properties");
+	}
+	memset(_properties, 0, getSize());
+}
+
+Properties::~Properties() {
+	free(_properties);
 }
 
 void Properties::init(uint count, byte *properties) {
-	_count = count;
-	_properties = properties;
+	assert(count <= getSize());
+	memcpy(_properties, properties, count);
 }
 
 void Properties::clear() {
@@ -71,23 +80,42 @@ void Properties::getProperyPos(uint32 propertyId, uint &index, byte &mask) {
 	mask = 1 << (propertyId & 7);
 }
 
+void Properties::save(uint numberToWrite, Common::WriteStream *out) {
+	assert(numberToWrite % 8 == 0);
+	assert(numberToWrite <= _count);
+	out->write(_properties, numberToWrite / 8);
+}
+
 DragonFLG::DragonFLG(BigfileArchive *bigfileArchive) {
 	_data = bigfileArchive->load("dragon.flg", _dataSize);
-	properties.init(288, _data);
+	properties = new Properties(288);
+	properties->init(_dataSize, _data);
 }
 
 DragonFLG::~DragonFLG() {
-	if (_data) {
-		delete _data;
-	}
+	delete _data;
 }
 
 bool DragonFLG::get(uint32 propertyId) {
-	return properties.get(propertyId);
+	return properties->get(propertyId);
 }
 
 void DragonFLG::set(uint32 propertyId, bool value) {
-	properties.set(propertyId, value);
+	properties->set(propertyId, value);
+}
+
+void DragonFLG::saveState(Common::WriteStream *out) {
+	properties->save(128, out); // save first 80 flags.
+}
+
+void DragonFLG::loadState(Common::ReadStream *in) {
+	byte savedState[0x10];
+
+	properties->init(_dataSize, _data);
+
+	in->read(savedState, 0x10);
+	properties->init(0x10, savedState);
+
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonflg.h b/engines/dragons/dragonflg.h
index c2e3a873fd..0a5049687e 100644
--- a/engines/dragons/dragonflg.h
+++ b/engines/dragons/dragonflg.h
@@ -22,6 +22,7 @@
 #ifndef SCUMMVM_DRAGONFLG_H
 #define SCUMMVM_DRAGONFLG_H
 
+#include "common/stream.h"
 #include "common/system.h"
 
 namespace Dragons {
@@ -30,11 +31,13 @@ class BigfileArchive;
 
 class Properties {
 public:
-	Properties();
+	Properties(uint count);
+	~Properties();
 	void init(uint count, byte *properties);
 	void clear();
 	bool get(uint32 propertyId);
 	void set(uint32 propertyId, bool value);
+	void save(uint numberToWrite, Common::WriteStream *out);
 private:
 	uint _count;
 	byte *_properties;
@@ -46,13 +49,16 @@ class DragonFLG {
 private:
 	byte *_data;
 	uint32_t _dataSize;
-	Properties properties;
+	Properties *properties;
 public:
 	virtual ~DragonFLG();
 
 	DragonFLG(BigfileArchive *bigfileArchive);
 	bool get(uint32 propertyId);
 	void set(uint32 propertyId, bool value);
+
+	void saveState(Common::WriteStream *out);
+	void loadState(Common::ReadStream *in);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index f3874003f8..35316d7583 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -26,14 +26,19 @@
 namespace Dragons {
 
 #define DRAGON_INI_STRUCT_SIZE 0x22
-DragonINIResource::DragonINIResource(BigfileArchive *bigfileArchive) {
+DragonINIResource::DragonINIResource(BigfileArchive *bigfileArchive): _bigfileArchive(bigfileArchive), _dragonINI(0) {
+	reset();
+}
+
+void DragonINIResource::reset() {
 	uint32 fileSize;
-	byte *data = bigfileArchive->load("dragon.ini", fileSize);
+	byte *data = _bigfileArchive->load("dragon.ini", fileSize);
 	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(data, fileSize, DisposeAfterUse::YES);
 
-	_count = fileSize / DRAGON_INI_STRUCT_SIZE;
-
-	_dragonINI = new DragonINI[_count];
+	if (!_dragonINI) {
+		_count = fileSize / DRAGON_INI_STRUCT_SIZE;
+		_dragonINI = new DragonINI[_count];
+	}
 
 	for(int i=0; i < _count; i++) {
 		_dragonINI[i].id = (uint16)i;
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 0766eb174b..8912aa2fdb 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -65,11 +65,13 @@ struct DragonINI
 
 class DragonINIResource {
 private:
+	BigfileArchive *_bigfileArchive;
 	DragonINI *_dragonINI;
 	uint16 _count;
 	DragonINI *_flickerINI;
 public:
 	DragonINIResource(BigfileArchive *bigfileArchive);
+	void reset();
 	uint16 totalRecords() { return _count; }
 	DragonINI *getRecord(uint16 index);
 	void setFlickerRecord(DragonINI *dragonINI);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 9495689fb7..37835d6a2e 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -66,7 +66,6 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	run_func_ptr_unk_countdown_timer = 0;
 	data_8006a3a0_flag = 0;
 	data_800633fa = 0;
-	iniItemInHand = 0;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
 
@@ -141,8 +140,21 @@ Common::Error DragonsEngine::run() {
 	_cursor->init(_actorManager, _dragonINIResource);
 	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
 
+	_dragonVAR->setVar(1, 1);
+
+	_scene->setSceneId(2);
+	byte *obd = _dragonOBD->getObdAtOffset(0x2c5a); //TODO read value from dragon.spt + 0xc
+	ScriptOpCall scriptOpCall;
+	scriptOpCall._code = obd + 4;
+	scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+	_scriptOpcodes->runScript(scriptOpCall);
+
 	uint16 sceneId = 0x12;
-	_dragonINIResource->getFlickerRecord()->sceneId = sceneId; //TODO
+	if(getINI(0)->sceneId == 0) {
+		getINI(0)->sceneId = sceneId; //TODO
+	} else {
+		_scene->setSceneId(getINI(0)->sceneId);
+	}
 	_sceneId1 = sceneId;
 	_scene->loadScene(sceneId, 0x1e);
 
@@ -209,7 +221,6 @@ void DragonsEngine::gameLoop()
 	actorId = 0;
 
 	while(!shouldQuit()) {
-		LAB_80026a74:
 		_scene->draw();
 		_screen->updateScreen();
 		wait();
@@ -290,7 +301,7 @@ void DragonsEngine::gameLoop()
 //		actorId = CheckButtonMapPress_CycleUp(0);
 //		if (((actorId & 0xffff) != 0) && isInputEnabled()) {
 //			_cursor->_sequenceID = _cursor->_sequenceID + 1;
-//			if (iniItemInHand == 0) {
+//			if (_cursor->iniItemInHand == 0) {
 //				bVar1 = _cursor->_sequenceID < 5;
 //			}
 //			else {
@@ -359,7 +370,7 @@ void DragonsEngine::gameLoop()
 							_inventory->setType(1);
 							_inventory->openInventory();
 							joined_r0x80027a38:
-							if (iniItemInHand == 0) {
+							if (_cursor->iniItemInHand == 0) {
 								_cursor->_sequenceID = 1;
 								actorId = uVar3;
 							}
@@ -368,7 +379,7 @@ void DragonsEngine::gameLoop()
 								actorId = uVar3;
 							}
 						}
-						goto LAB_80026a74;
+						continue;
 					}
 					uVar6 = _inventory->getType();
 					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
@@ -377,7 +388,7 @@ void DragonsEngine::gameLoop()
 							if (_cursor->_iniUnderCursor == 0x8002) {
 								LAB_80027294:
 								uVar7 = 0;
-								if (iniItemInHand == 0) {
+								if (_cursor->iniItemInHand == 0) {
 									if ((bit_flags_8006fbd8 & 3) != 1) {
 										sequenceId = _dragonVAR->getVar(7);
 										uVar7 = _inventory->_old_showing_value;
@@ -395,12 +406,12 @@ void DragonsEngine::gameLoop()
 									if (uVar7 < 0x29) {
 										_cursor->_sequenceID = 1;
 										waitForFrames(1);
-										uVar6 = iniItemInHand;
-										iniItemInHand = 0;
+										uVar6 = _cursor->iniItemInHand;
+										_cursor->iniItemInHand = 0;
 										_cursor->_iniUnderCursor = 0;
 										unkArray_uint16[(uint)uVar7] = uVar6;
 										actorId = uVar3;
-										goto LAB_80026a74;
+										continue;
 									}
 								}
 							}
@@ -413,7 +424,7 @@ void DragonsEngine::gameLoop()
 								_inventory->_old_showing_value = uVar6;
 								FUN_80038890();
 								actorId = uVar3;
-								goto LAB_80026a74;
+								continue;
 							}
 						}
 						LAB_80027ab4:
@@ -433,7 +444,7 @@ void DragonsEngine::gameLoop()
 								clearFlags(ENGINE_FLAG_8);
 							}
 							_scriptOpcodes->_data_800728c0 = _cursor->data_80072890;
-							_cursor->data_80072890 = iniItemInHand;
+							_cursor->data_80072890 = _cursor->iniItemInHand;
 						}
 					}
 				}
@@ -456,7 +467,7 @@ void DragonsEngine::gameLoop()
 			LAB_80027b58:
 			runINIScripts();
 			actorId = uVar3;
-			goto LAB_80026a74;
+			continue;
 		}
 		if (checkForInventoryButtonRelease()) {
 			_counter = 0;
@@ -466,7 +477,7 @@ void DragonsEngine::gameLoop()
 			_inventory->_old_showing_value = _inventory->getType();
 			actorId = uVar3;
 			_inventory->setType(uVar6);
-			goto LAB_80026a74;
+			continue;
 		}
 		uVar6 = _inventory->getType();
 		if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
@@ -489,7 +500,7 @@ void DragonsEngine::gameLoop()
 				}
 				_inventory->_old_showing_value = uVar6;
 				actorId = uVar3;
-				goto LAB_80026a74;
+				continue;
 			}
 			if (_cursor->_iniUnderCursor != 0) {
 				actorId_00 = 0;
@@ -497,7 +508,7 @@ void DragonsEngine::gameLoop()
 					_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
 					_cursor->data_80072890 = _cursor->_iniUnderCursor;
 					if (4 < _cursor->_sequenceID) {
-						_cursor->data_80072890 = iniItemInHand;
+						_cursor->data_80072890 = _cursor->iniItemInHand;
 						_scriptOpcodes->_data_800728c0 = _cursor->_iniUnderCursor;
 					}
 					clearFlags(ENGINE_FLAG_8);
@@ -513,10 +524,10 @@ void DragonsEngine::gameLoop()
 				}
 				puVar9 = unkArray_uint16 + (actorId_00 & 0xffff);
 				Actor *actor = _actorManager->getActor(actorId_00 + 0x17);
-				*puVar9 = iniItemInHand;
+				*puVar9 = _cursor->iniItemInHand;
 				_cursor->data_8007283c = actor->_sequenceID;
 				actor->clearFlag(ACTOR_FLAG_40);
-				iniItemInHand = _cursor->_iniUnderCursor;
+				_cursor->iniItemInHand = _cursor->_iniUnderCursor;
 				_cursor->_sequenceID = 5;
 				actorId = uVar3;
 				if (*puVar9 != 0) {
@@ -532,10 +543,10 @@ void DragonsEngine::gameLoop()
 					actor->priorityLayer = 6;
 					actorId = uVar3;
 				}
-				goto LAB_80026a74;
+				continue;
 			}
 			uVar6 = 0;
-			if (iniItemInHand == 0) goto LAB_80027b58;
+			if (_cursor->iniItemInHand == 0) goto LAB_80027b58;
 			//drop item back into inventory
 			actorId = 0;
 			do {
@@ -551,12 +562,12 @@ void DragonsEngine::gameLoop()
 			} while (uVar6 < 0x29);
 			if (actorId != 0x29) {
 				actorId_00 = (uint)(ushort)(uVar6 + 0x17);
-				unkArray_uint16[actorId] = iniItemInHand;
+				unkArray_uint16[actorId] = _cursor->iniItemInHand;
 				Actor *actor = _actorManager->getActor(actorId_00);
 				actor->flags = 0;
 				actor->priorityLayer = 0;
 				actor->field_e = 0x100;
-				iniItemInHand = 0;
+				_cursor->iniItemInHand = 0;
 				actor->updateSequence(
 						 getINI((uint)unkArray_uint16[actorId] - 1)->field_8 * 2 + 10);
 				uVar6 = _cursor->_sequenceID;
@@ -571,7 +582,7 @@ void DragonsEngine::gameLoop()
 			}
 		}
 		LAB_8002790c:
-		if ((iniItemInHand == 0) ||
+		if ((_cursor->iniItemInHand == 0) ||
 			(((ushort)(_cursor->_x - 10U) < 300 && ((ushort)(_cursor->_y - 10U) < 0xb4))))
 			goto LAB_80027b58;
 		_cursor->_sequenceID = 5;
@@ -653,45 +664,6 @@ void DragonsEngine::updateHandler() {
 	data_8006a3a0_flag &= ~0x40;
 }
 
-const char *DragonsEngine::getSavegameFilename(int num) {
-	static Common::String filename;
-	filename = getSavegameFilename(_targetName, num);
-	return filename.c_str();
-}
-
-Common::String DragonsEngine::getSavegameFilename(const Common::String &target, int num) {
-	assert(num >= 0 && num <= 999);
-	return Common::String::format("%s.%03d", target.c_str(), num);
-}
-
-#define DRAGONS_SAVEGAME_VERSION 0
-
-kReadSaveHeaderError
-DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
-
-	header.version = in->readUint32LE();
-	if (header.version > DRAGONS_SAVEGAME_VERSION)
-		return kRSHEInvalidVersion;
-
-	byte descriptionLen = in->readByte();
-	header.description = "";
-	while (descriptionLen--) {
-		header.description += (char) in->readByte();
-	}
-
-	if (!Graphics::loadThumbnail(*in, header.thumbnail, skipThumbnail)) {
-		return kRSHEIoError;
-	}
-
-	header.flags = in->readUint32LE();
-
-	header.saveDate = in->readUint32LE();
-	header.saveTime = in->readUint32LE();
-	header.playTime = in->readUint32LE();
-
-	return ((in->eos() || in->err()) ? kRSHEIoError : kRSHENoError);
-}
-
 uint32 DragonsEngine::calulateTimeLeft() {
 	uint32 now;
 
@@ -1182,6 +1154,19 @@ void DragonsEngine::FUN_80038994() {
 }
 
 void DragonsEngine::FUN_8002931c() {
+
+	DragonINI *flicker = _dragonINIResource->getFlickerRecord();
+	if (flicker && flicker->actor) {
+		flicker->actor->clearFlag(ACTOR_FLAG_10);
+		if (getCurrentSceneId() != 0x2e || !flicker->actor->_actorResource || flicker->actor->_actorResource->_id != 0x91) {
+			flicker->actor->setFlag(ACTOR_FLAG_4);
+		}
+	}
+//TODO
+//	uVar1 = FUN_80023830(9);
+//	local_30 = 0x11;
+//	local_2c = local_280[(uint)DAT_800728b0 * 9 + (uVar1 & 0xffff)];
+//	FlickerTalkMaybe(&local_30);
 	error("FUN_8002931c"); //TODO
 }
 
@@ -1190,4 +1175,19 @@ void DragonsEngine::reset_screen_maybe() {
 	//TODO
 }
 
+bool DragonsEngine::canLoadGameStateCurrently() {
+	return isInputEnabled();
+}
+
+bool DragonsEngine::canSaveGameStateCurrently() {
+	return isInputEnabled() && _inventory->getType() != 1;
+}
+
+bool DragonsEngine::hasFeature(Engine::EngineFeature f) const {
+	return
+		// TODO (f == kSupportsRTL) ||
+		(f == kSupportsLoadingDuringRuntime) ||
+		(f == kSupportsSavingDuringRuntime);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 6beac6fe51..22dd7b8216 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -127,7 +127,6 @@ public:
 	uint16 data_800633fa;
 	Inventory *_inventory;
 	Cursor *_cursor;
-	uint16 iniItemInHand;
 
 	uint16 unkArray_uint16[42];
 	opCode1AStruct opCode1A_tbl[8];
@@ -157,7 +156,8 @@ private:
 	bool _leftMouseButtonUp;
 	bool _rightMouseButtonUp;
 	bool _iKeyUp;
-
+protected:
+	virtual bool hasFeature(EngineFeature f) const;
 public:
 	DragonsEngine(OSystem *syst);
 	~DragonsEngine();
@@ -169,6 +169,11 @@ public:
 	static Common::String getSavegameFilename(const Common::String &target, int num);
 	static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
 
+	virtual Common::Error loadGameState(int slot);
+	virtual bool canLoadGameStateCurrently();
+	virtual Common::Error saveGameState(int slot, const Common::String &desc);
+	virtual bool canSaveGameStateCurrently();
+
 	void updateActorSequences();
 	void setFlags(uint32 flags);
 	void clearFlags(uint32 flags);
@@ -198,6 +203,8 @@ public:
 	void reset_screen_maybe();
 
 private:
+	bool savegame(const char *filename, const char *description);
+	bool loadgame(const char *filename);
 	void gameLoop();
 	void updateHandler();
 	void updatePathfindingActors();
diff --git a/engines/dragons/dragonvar.cpp b/engines/dragons/dragonvar.cpp
index 18df773006..d35fe5b454 100644
--- a/engines/dragons/dragonvar.cpp
+++ b/engines/dragons/dragonvar.cpp
@@ -24,16 +24,12 @@
 
 namespace Dragons {
 
-DragonVAR::DragonVAR(BigfileArchive *bigfileArchive) {
-	uint32 size;
-	_data = bigfileArchive->load("dragon.var", size);
-	assert(size == 30);
+DragonVAR::DragonVAR(BigfileArchive *bigfileArchive): _bigfileArchive(bigfileArchive), _data(0) {
+	reset();
 }
 
 DragonVAR::~DragonVAR() {
-	if (_data) {
 		delete _data;
-	}
 }
 
 uint16 DragonVAR::getVar(uint16 offset) {
@@ -48,4 +44,11 @@ void DragonVAR::setVar(uint16 offset, uint16 value) {
 	WRITE_LE_INT16(_data + offset * 2, value);
 }
 
+void DragonVAR::reset() {
+	delete _data;
+	uint32 size;
+	_data = _bigfileArchive->load("dragon.var", size);
+	assert(size == 30);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonvar.h b/engines/dragons/dragonvar.h
index 46991c09c1..1ead7699d7 100644
--- a/engines/dragons/dragonvar.h
+++ b/engines/dragons/dragonvar.h
@@ -31,10 +31,12 @@ class BigfileArchive;
 class DragonVAR {
 private:
 	byte *_data;
+	BigfileArchive *_bigfileArchive;
 public:
 	virtual ~DragonVAR();
 
 	DragonVAR(BigfileArchive *bigfileArchive);
+	void reset();
 	uint16 getVar(uint16 offset);
 	void setVar(uint16 offset, uint16 value);
 };
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
new file mode 100644
index 0000000000..d5eee02c26
--- /dev/null
+++ b/engines/dragons/saveload.cpp
@@ -0,0 +1,184 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "common/savefile.h"
+
+#include "graphics/thumbnail.h"
+
+#include "dragons.h"
+#include "dragonflg.h"
+#include "dragonini.h"
+#include "dragonvar.h"
+#include "scene.h"
+#include "cursor.h"
+
+
+namespace Dragons {
+
+#define ILLUSIONS_SAVEGAME_VERSION 0
+
+Dragons::kReadSaveHeaderError DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
+
+	header.version = in->readUint32LE();
+	if (header.version > ILLUSIONS_SAVEGAME_VERSION)
+		return kRSHEInvalidVersion;
+
+	byte descriptionLen = in->readByte();
+	header.description = "";
+	while (descriptionLen--) {
+		header.description += (char)in->readByte();
+	}
+
+	if (!Graphics::loadThumbnail(*in, header.thumbnail, skipThumbnail)) {
+		return kRSHEIoError;
+	}
+
+	// Not used yet, reserved for future usage
+//	header.gameID = in->readByte();
+	header.flags = in->readUint32LE();
+
+	header.saveDate = in->readUint32LE();
+	header.saveTime = in->readUint32LE();
+	header.playTime = in->readUint32LE();
+
+	return ((in->eos() || in->err()) ? kRSHEIoError : kRSHENoError);
+}
+
+bool DragonsEngine::savegame(const char *filename, const char *description) {
+
+	Common::OutSaveFile *out;
+	if (!(out = g_system->getSavefileManager()->openForSaving(filename))) {
+		warning("Can't create file '%s', game not saved", filename);
+		return false;
+	}
+
+	TimeDate curTime;
+	g_system->getTimeAndDate(curTime);
+
+	// Header start
+	out->writeUint32LE(ILLUSIONS_SAVEGAME_VERSION);
+
+	byte descriptionLen = strlen(description);
+	out->writeByte(descriptionLen);
+	out->write(description, descriptionLen);
+
+	// TODO Probably pre-generate the thumbnail before the internal menu system is
+	// called to have a thumbnail without the menu system itself on it.
+	// Use the automatic thumbnail generation only when the ScummVM save dialog is used.
+	Graphics::saveThumbnail(*out);
+
+	// Not used yet, reserved for future usage
+	//out->writeByte(0);
+	out->writeUint32LE(0);
+	uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
+	uint32 saveTime = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
+	uint32 playTime = g_engine->getTotalPlayTime() / 1000;
+	out->writeUint32LE(saveDate);
+	out->writeUint32LE(saveTime);
+	out->writeUint32LE(playTime);
+	// Header end
+
+	//TODO save gamestate here. _gameState->write(out);
+	out->writeByte((int8)getCurrentSceneId());
+	_dragonFLG->saveState(out);
+
+	out->finalize();
+	delete out;
+	return true;
+}
+
+bool DragonsEngine::loadgame(const char *filename) {
+	Common::InSaveFile *in;
+	if (!(in = g_system->getSavefileManager()->openForLoading(filename))) {
+		warning("Can't open file '%s', game not loaded", filename);
+		return false;
+	}
+
+	SaveHeader header;
+
+	kReadSaveHeaderError errorCode = readSaveHeader(in, header);
+
+	if (errorCode != kRSHENoError) {
+		warning("Error loading savegame '%s'", filename);
+		delete in;
+		return false;
+	}
+
+	g_engine->setTotalPlayTime(header.playTime * 1000);
+
+	// TODO load game state here. _gameState->read(in);
+	uint16 newSceneId = (uint16)in->readByte();
+	_dragonFLG->loadState(in);
+	_dragonFLG->set(165, false);
+
+	_dragonVAR->reset();
+
+	_dragonVAR->setVar(1, 1);
+
+	_dragonINIResource->reset();
+
+	_flags = 0x1046;
+	_flags &= 0x1c07040;
+	_flags |= 0x26;
+	_unkFlags1 = 0;
+
+	_cursor->init(_actorManager, _dragonINIResource);
+//	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
+
+	if(getINI(0)->sceneId == 0) {
+		getINI(0)->sceneId = newSceneId; //TODO
+	} else {
+		_scene->setSceneId(getINI(0)->sceneId);
+	}
+	_sceneId1 = newSceneId;
+
+	_scene->loadScene(newSceneId, 0x1e); //TODO
+
+	delete in;
+	return true;
+}
+
+Common::Error DragonsEngine::loadGameState(int slot) {
+	const char *fileName = getSavegameFilename(slot);
+	if (!loadgame(fileName))
+		return Common::kReadingFailed;
+	return Common::kNoError;
+}
+
+Common::Error DragonsEngine::saveGameState(int slot, const Common::String &description) {
+	const char *fileName = getSavegameFilename(slot);
+	if (!savegame(fileName, description.c_str()))
+		return Common::kWritingFailed;
+	return Common::kNoError;
+}
+
+const char *DragonsEngine::getSavegameFilename(int num) {
+	static Common::String filename;
+	filename = getSavegameFilename(_targetName, num);
+	return filename.c_str();
+}
+
+Common::String DragonsEngine::getSavegameFilename(const Common::String &target, int num) {
+	assert(num >= 0 && num <= 999);
+	return Common::String::format("%s.%03d", target.c_str(), num);
+}
+
+} // End of namespace Illusions
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 15a56e839b..71b7b11523 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -999,14 +999,14 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 		}
 
 		if (sceneId == 1) {
-			if (_vm->iniItemInHand != 0) {
+			if (_vm->_cursor->iniItemInHand != 0) {
 				uint16 freeSlot = 0;
 				for( ;_vm->unkArray_uint16[freeSlot] != 0; freeSlot++) {
 					if (_vm->unkArray_uint16[freeSlot] == 0) {
 						break;
 					}
 				}
-				_vm->unkArray_uint16[freeSlot] = _vm->iniItemInHand;
+				_vm->unkArray_uint16[freeSlot] = _vm->_cursor->iniItemInHand;
 				if (_vm->_inventory->getType() == 1) {
 					Actor *actor = _vm->_actorManager->getActor(freeSlot + 0x17);
 					actor->flags = 0;
@@ -1026,7 +1026,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 			_vm->_cursor->data_800728b0_cursor_seqID = 5;
 			_vm->_cursor->_sequenceID = 5;
 			_vm->_cursor->data_8007283c = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
-			_vm->iniItemInHand = field2;
+			_vm->_cursor->iniItemInHand = field2;
 		}
 	}
 	ini->sceneId = sceneId;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 02e2f5b1a4..aff0cb8b13 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -82,6 +82,9 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0x5e, spcUnk5e);
 	OPCODE(0x5f, spcUnk5f);
+
+	OPCODE(0x7b, spcSetCameraXToZero);
+
 }
 
 #undef OPCODE
@@ -192,4 +195,8 @@ void SpecialOpcodes::panCamera(int16 mode) {
 	return;
 }
 
+void SpecialOpcodes::spcSetCameraXToZero() {
+	_vm->_scene->_camera.x = 0;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 1c549954c2..9c348a2940 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -68,6 +68,7 @@ protected:
 	void spcUnk5e();
 	void spcUnk5f();
 
+	void spcSetCameraXToZero(); //0x7b
 private:
 	void panCamera(int16 mode);
 };


Commit: 8c0fc756a17f7c004ab170554b7302c72faebf8c
    https://github.com/scummvm/scummvm/commit/8c0fc756a17f7c004ab170554b7302c72faebf8c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add savelog to make file

Changed paths:
    engines/dragons/module.mk


diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 1b5a5b1d6e..7af8e1da06 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -16,6 +16,7 @@ MODULE_OBJS := \
     dragonvar.o \
 	dragons.o \
 	inventory.o \
+	saveload.o \
 	scene.o \
 	screen.o \
 	scriptopcodes.o \


Commit: 799c33ccb2e79f2e2df777dc6d1fb2fdbbc98970
    https://github.com/scummvm/scummvm/commit/799c33ccb2e79f2e2df777dc6d1fb2fdbbc98970
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: script bug fixes. Improving load game logic

Changed paths:
    engines/dragons/actorresource.cpp
    engines/dragons/cursor.cpp
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonobd.cpp
    engines/dragons/dragonobd.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/saveload.cpp
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 8efed4d706..579c7e6ca6 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -79,7 +79,7 @@ bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream
 		_frames[i].frameDataOffset = &dataStart[frameDataOffset];
 		_frames[i].flags = stream.readUint16LE();
 		_frames[i].field_c = stream.readUint16LE();
-		debug("Frame[%d] @%X, xOffset: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
+		debug(3, "Frame[%d] @%X, xOffset: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
 				i, offset, _frames[i].xOffset, _frames[i].yOffset, _frames[i].width, _frames[i].height, frameDataOffset, _frames[i].flags, _frames[i].field_c);
 	}
 
@@ -110,7 +110,7 @@ Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame, byte *palett
 
 	int32 blockSize = ((actorFrame.width / 2) * actorFrame.height * 2) / 4;
 
-	debug("Frame blockSize: %d width: %d height: %d", blockSize, actorFrame.width, actorFrame.height);
+	debug(3, "Frame blockSize: %d width: %d height: %d", blockSize, actorFrame.width, actorFrame.height);
 
 	byte *data = actorFrame.frameDataOffset;
 
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 61adaeffd5..3f5fcdbfa4 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -55,6 +55,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	data_8007283c = 0;
 	_cursorActivationSeqOffset = 0;
 	data_800728b0_cursor_seqID = 0;
+	data_80072890 = 0;
 }
 
 
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index 501500b7d5..2137a77c44 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -75,9 +75,8 @@ uint32 Properties::getSize() {
 
 void Properties::getProperyPos(uint32 propertyId, uint &index, byte &mask) {
 	assert(propertyId < _count);
-	propertyId &= 0xFFFF;
-	index = propertyId >> 3;
-	mask = 1 << (propertyId & 7);
+	index = propertyId / 8;
+	mask = 1 << (propertyId % 8);
 }
 
 void Properties::save(uint numberToWrite, Common::WriteStream *out) {
diff --git a/engines/dragons/dragonobd.cpp b/engines/dragons/dragonobd.cpp
index a1568f246c..3563de69a7 100644
--- a/engines/dragons/dragonobd.cpp
+++ b/engines/dragons/dragonobd.cpp
@@ -28,7 +28,10 @@ namespace Dragons {
 DragonOBD::DragonOBD(BigfileArchive *bigfileArchive) {
 	uint32 size;
 	byte *optData = bigfileArchive->load("dragon.opt", size);
-	optReadStream = new Common::MemoryReadStream(optData, size, DisposeAfterUse::NO);
+	optReadStream = new Common::MemoryReadStream(optData, size, DisposeAfterUse::YES);
+
+	byte *sptData = bigfileArchive->load("dragon.spt", size);
+	sptReadStream = new Common::MemoryReadStream(sptData, size, DisposeAfterUse::YES);
 
 	_data = bigfileArchive->load("dragon.obd", _dataSize);
 }
@@ -44,6 +47,7 @@ DragonOBD::~DragonOBD() {
 		delete _data;
 	}
 	delete optReadStream;
+	delete sptReadStream;
 }
 
 byte *DragonOBD::getFromOpt(uint32 index) {
@@ -51,4 +55,9 @@ byte *DragonOBD::getFromOpt(uint32 index) {
 	return getObdAtOffset(optReadStream->readUint32LE());
 }
 
+byte *DragonOBD::getFromSpt(uint32 index) {
+	sptReadStream->seek(index * 4);
+	return getObdAtOffset(sptReadStream->readUint32LE());
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonobd.h b/engines/dragons/dragonobd.h
index 10ff63596f..92ac05a3b0 100644
--- a/engines/dragons/dragonobd.h
+++ b/engines/dragons/dragonobd.h
@@ -33,6 +33,7 @@ private:
 	byte *_data;
 	uint32_t _dataSize;
 	Common::SeekableReadStream *optReadStream;
+	Common::SeekableReadStream *sptReadStream;
 
 public:
 	virtual ~DragonOBD();
@@ -40,6 +41,7 @@ public:
 	DragonOBD(BigfileArchive *bigfileArchive);
 	byte *getObdAtOffset(uint32 offset);
 	byte *getFromOpt(uint32 index);
+	byte *getFromSpt(uint32 index);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 37835d6a2e..0a193fbf83 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -57,31 +57,16 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_dragonRMS = NULL;
 	_backgroundResourceLoader = NULL;
 	_screen = NULL;
-	_nextUpdatetime = 0;
-	_flags = 0;
-	_unkFlags1 = 0;
 	_sequenceOpcodes = new SequenceOpcodes(this);
 	_scriptOpcodes = NULL;
 	_engine = this;
-	run_func_ptr_unk_countdown_timer = 0;
-	data_8006a3a0_flag = 0;
-	data_800633fa = 0;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
 
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
 	_iKeyUp = false;
-
-	for(int i = 0; i < 8; i++) {
-		opCode1A_tbl[i].field0 = 0;
-		opCode1A_tbl[i].field2 = 0;
-		opCode1A_tbl[i].field4 = 0;
-		opCode1A_tbl[i].field6 = 0;
-		opCode1A_tbl[i].field8 = 0;
-	}
-
-	memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
+	reset();
 }
 
 DragonsEngine::~DragonsEngine() {
@@ -133,30 +118,8 @@ Common::Error DragonsEngine::run() {
 	_scriptOpcodes = new ScriptOpcodes(this, _dragonFLG);
 	_backgroundResourceLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource, _backgroundResourceLoader);
-	_flags = 0x1046;
-	_flags &= 0x1c07040;
-	_flags |= 0x26;
 
-	_cursor->init(_actorManager, _dragonINIResource);
-	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
-
-	_dragonVAR->setVar(1, 1);
-
-	_scene->setSceneId(2);
-	byte *obd = _dragonOBD->getObdAtOffset(0x2c5a); //TODO read value from dragon.spt + 0xc
-	ScriptOpCall scriptOpCall;
-	scriptOpCall._code = obd + 4;
-	scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
-	_scriptOpcodes->runScript(scriptOpCall);
-
-	uint16 sceneId = 0x12;
-	if(getINI(0)->sceneId == 0) {
-		getINI(0)->sceneId = sceneId; //TODO
-	} else {
-		_scene->setSceneId(getINI(0)->sceneId);
-	}
-	_sceneId1 = sceneId;
-	_scene->loadScene(sceneId, 0x1e);
+	loadScene(0);
 
 	_scene->draw();
 	_screen->updateScreen();
@@ -702,7 +665,7 @@ void DragonsEngine::updateActorSequences() {
 			!(actor->flags & Dragons::ACTOR_FLAG_4) &&
 			!(actor->flags & Dragons::ACTOR_FLAG_400) &&
 			(actor->sequenceTimer == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
-			debug("Actor[%d] execute sequenceOp", actorId);
+			debug(3, "Actor[%d] execute sequenceOp", actorId);
 
 			if (actor->flags & Dragons::ACTOR_FLAG_1) {
 				actor->resetSequenceIP();
@@ -1167,7 +1130,8 @@ void DragonsEngine::FUN_8002931c() {
 //	local_30 = 0x11;
 //	local_2c = local_280[(uint)DAT_800728b0 * 9 + (uVar1 & 0xffff)];
 //	FlickerTalkMaybe(&local_30);
-	error("FUN_8002931c"); //TODO
+
+error("FUN_8002931c"); //TODO
 }
 
 void DragonsEngine::reset_screen_maybe() {
@@ -1190,4 +1154,58 @@ bool DragonsEngine::hasFeature(Engine::EngineFeature f) const {
 		(f == kSupportsSavingDuringRuntime);
 }
 
+void DragonsEngine::loadScene(uint16 sceneId) {
+	_flags = 0x1046;
+	_flags &= 0x1c07040;
+	_flags |= 0x26;
+	_unkFlags1 = 0;
+
+	_scriptOpcodes->_data_800728c0 = 0; //TODO this should be reset in scriptopcode.
+	_cursor->init(_actorManager, _dragonINIResource);
+	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
+
+	if (sceneId > 2) {
+		_dragonVAR->setVar(1, 1);
+	}
+
+	if (sceneId > 2) { //TODO remove this restriction to enable intro sequence.
+		_scene->setSceneId(2);
+		byte *obd = _dragonOBD->getFromSpt(3);
+		ScriptOpCall scriptOpCall;
+		scriptOpCall._code = obd + 4;
+		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		_scriptOpcodes->runScript(scriptOpCall);
+	} else {
+		sceneId = 0x12; // HACK the first scene. TODO remove this
+	}
+
+	if(getINI(0)->sceneId == 0) {
+		getINI(0)->sceneId = sceneId; //TODO
+	} else {
+		_scene->setSceneId(getINI(0)->sceneId);
+	}
+	_sceneId1 = sceneId;
+	_scene->loadScene(sceneId, 0x1e);
+}
+
+void DragonsEngine::reset() {
+	_nextUpdatetime = 0;
+	_flags = 0;
+	_unkFlags1 = 0;
+	run_func_ptr_unk_countdown_timer = 0;
+	data_8006a3a0_flag = 0;
+	data_800633fa = 0;
+
+	for(int i = 0; i < 8; i++) {
+		opCode1A_tbl[i].field0 = 0;
+		opCode1A_tbl[i].field2 = 0;
+		opCode1A_tbl[i].field4 = 0;
+		opCode1A_tbl[i].field6 = 0;
+		opCode1A_tbl[i].field8 = 0;
+	}
+
+	memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
+
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 22dd7b8216..d49e5a180a 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -202,6 +202,10 @@ public:
 
 	void reset_screen_maybe();
 
+	void loadScene(uint16 sceneId);
+
+	void reset();
+
 private:
 	bool savegame(const char *filename, const char *description);
 	bool loadgame(const char *filename);
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
index d5eee02c26..30f6122a33 100644
--- a/engines/dragons/saveload.cpp
+++ b/engines/dragons/saveload.cpp
@@ -124,33 +124,16 @@ bool DragonsEngine::loadgame(const char *filename) {
 
 	g_engine->setTotalPlayTime(header.playTime * 1000);
 
+	reset();
 	// TODO load game state here. _gameState->read(in);
 	uint16 newSceneId = (uint16)in->readByte();
 	_dragonFLG->loadState(in);
-	_dragonFLG->set(165, false);
 
 	_dragonVAR->reset();
 
-	_dragonVAR->setVar(1, 1);
-
 	_dragonINIResource->reset();
 
-	_flags = 0x1046;
-	_flags &= 0x1c07040;
-	_flags |= 0x26;
-	_unkFlags1 = 0;
-
-	_cursor->init(_actorManager, _dragonINIResource);
-//	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
-
-	if(getINI(0)->sceneId == 0) {
-		getINI(0)->sceneId = newSceneId; //TODO
-	} else {
-		_scene->setSceneId(getINI(0)->sceneId);
-	}
-	_sceneId1 = newSceneId;
-
-	_scene->loadScene(newSceneId, 0x1e); //TODO
+	loadScene(newSceneId);
 
 	delete in;
 	return true;
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 71b7b11523..1064aec48d 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -75,7 +75,7 @@ ScriptOpcodes::~ScriptOpcodes() {
 void ScriptOpcodes::execOpcode(ScriptOpCall &scriptOpCall) {
 	if (!_opcodes[scriptOpCall._op])
 		error("ScriptOpcodes::execOpcode() Unimplemented opcode %d (0x%X)", scriptOpCall._op, scriptOpCall._op);
-	debug(3, "execScriptOpcode(%d) %s", scriptOpCall._op, _opcodeNames[scriptOpCall._op].c_str());
+	debug("execScriptOpcode(%d) %s", scriptOpCall._op, _opcodeNames[scriptOpCall._op].c_str());
 	(*_opcodes[scriptOpCall._op])(scriptOpCall);
 }
 
@@ -342,7 +342,7 @@ void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	if (checkPropertyFlag(scriptOpCall)) {
 		ScriptOpCall localScriptOpCall;
 		localScriptOpCall._code = scriptOpCall._code + 4;
-		localScriptOpCall._codeEnd = localScriptOpCall._code + READ_LE_UINT32(scriptOpCall._code);
+		localScriptOpCall._codeEnd = localScriptOpCall._code + READ_LE_UINT16(scriptOpCall._code);
 		localScriptOpCall._field8 = scriptOpCall._field8;
 		localScriptOpCall._result = 0;
 
@@ -356,7 +356,7 @@ void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
 			}
 		}
 
-		scriptOpCall._code = localScriptOpCall._code + READ_LE_UINT16(scriptOpCall._code);
+		scriptOpCall._code = localScriptOpCall._code + READ_LE_UINT16(scriptOpCall._code + 2);
 	} else {
 		scriptOpCall._code += 4 + READ_LE_UINT16(scriptOpCall._code);
 	}


Commit: 10df96224e14de9c544902970da26d80290a80ee
    https://github.com/scummvm/scummvm/commit/10df96224e14de9c544902970da26d80290a80ee
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fix op14 if instruction

Changed paths:
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 1064aec48d..a591df983e 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -346,7 +346,7 @@ void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
 		localScriptOpCall._field8 = scriptOpCall._field8;
 		localScriptOpCall._result = 0;
 
-		executeScriptLoop(scriptOpCall);
+		executeScriptLoop(localScriptOpCall);
 
 		if (scriptOpCall._field8 == 1) {
 			scriptOpCall._result = localScriptOpCall._result;


Commit: 916d5da7151829e81c9d5a11d37bc87cf5928977
    https://github.com/scummvm/scummvm/commit/916d5da7151829e81c9d5a11d37bc87cf5928977
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: allow load save game at start

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/saveload.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 0a193fbf83..2e98ede2a0 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
+#include "common/config-manager.h"
 #include "engines/util.h"
 #include "graphics/thumbnail.h"
 #include "graphics/surface.h"
@@ -119,7 +120,11 @@ Common::Error DragonsEngine::run() {
 	_backgroundResourceLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource, _backgroundResourceLoader);
 
-	loadScene(0);
+	if (ConfMan.hasKey("save_slot")) {
+		loadGameState(ConfMan.getInt("save_slot"));
+	} else {
+		loadScene(0);
+	}
 
 	_scene->draw();
 	_screen->updateScreen();
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
index 30f6122a33..ee8ea9684c 100644
--- a/engines/dragons/saveload.cpp
+++ b/engines/dragons/saveload.cpp
@@ -134,6 +134,7 @@ bool DragonsEngine::loadgame(const char *filename) {
 	_dragonINIResource->reset();
 
 	loadScene(newSceneId);
+	setFlags(ENGINE_FLAG_8); //Re-enable cursor TODO should we need to do this?
 
 	delete in;
 	return true;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index aff0cb8b13..92cface7ea 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -74,6 +74,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x14, spcClearEngineFlag8);
 	OPCODE(0x15, spcSetEngineFlag8);
 
+	OPCODE(0x49, spcLoadScene1);
+
 	OPCODE(0x4e, spcUnk4e);
 	OPCODE(0x4f, spcUnk4f);
 
@@ -199,4 +201,8 @@ void SpecialOpcodes::spcSetCameraXToZero() {
 	_vm->_scene->_camera.x = 0;
 }
 
+void SpecialOpcodes::spcLoadScene1() {
+	// TODO spcLoadScene1 knights around the table.
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 9c348a2940..a878aca90d 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -60,6 +60,7 @@ protected:
 	void spcClearEngineFlag8(); // 0x14
 	void spcSetEngineFlag8(); // 0x15
 
+	void spcLoadScene1(); // 0x49
 	void spcUnk4e();
 	void spcUnk4f();
 


Commit: f6b9ea6e410fb678d8d5bde325e3b3cfd4cd0a56
    https://github.com/scummvm/scummvm/commit/f6b9ea6e410fb678d8d5bde325e3b3cfd4cd0a56
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added special op 0x53

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 92cface7ea..07b2820742 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -79,6 +79,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x4e, spcUnk4e);
 	OPCODE(0x4f, spcUnk4f);
 
+	OPCODE(0x53, spcClearEngineFlag0x4000000);
 	OPCODE(0x54, spcSetEngineFlag0x4000000);
 	OPCODE(0x55, spcSetCursorSequenceIdToZero);
 
@@ -150,6 +151,10 @@ void SpecialOpcodes::spcSetEngineFlag0x4000000() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
 }
 
+void SpecialOpcodes::spcClearEngineFlag0x4000000() {
+	_vm->clearFlags(Dragons::ENGINE_FLAG_4000000);
+}
+
 void SpecialOpcodes::spcSetCursorSequenceIdToZero() {
 	_vm->_cursor->_sequenceID = 0;
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index a878aca90d..d3eb49382d 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -64,6 +64,7 @@ protected:
 	void spcUnk4e();
 	void spcUnk4f();
 
+	void spcClearEngineFlag0x4000000(); // 0x53
 	void spcSetEngineFlag0x4000000(); // 0x54
 	void spcSetCursorSequenceIdToZero(); // 0x55
 	void spcUnk5e();


Commit: d0d1f29722698142871b6e853b9b06cd3741b562
    https://github.com/scummvm/scummvm/commit/d0d1f29722698142871b6e853b9b06cd3741b562
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added more script opcodes

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 3f5fcdbfa4..205a913d79 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -223,7 +223,7 @@ int16 Cursor::updateIniFromScene() {
 				// 0x80028a24
 				if (ini->field_2 != -1) {
 					IMG *img = _vm->_dragonIMG->getIMG((uint32)ini->field_2);
-					if (img->field_e - 1 >= 2) {
+					if (img->field_e - 1 >= 1) { // TODO this is >= 2 in the original.
 						if (cursorTileX >= img->x && cursorTileX < img->x + img->w && cursorTileY >= img->y && cursorTileY < img->y + img->h) {
 							cursorOverIni = i + 1;
 						}
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 2e98ede2a0..a2034b8e99 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -229,21 +229,17 @@ void DragonsEngine::gameLoop()
 			actorId_00 = uVar3 & 0xffff;
 			if (actorId_00 == 0) goto LAB_80026d34;
 			if (actorId_00 != (actorId & 0xffff)) {
-				//TODO implement this
-				error("actorId_00 != (actorId & 0xffff)");
-//				buffer = (void *)((int)dragon_Obd_Offset + dragon_Opt_Offset[actorId_00 - 1].obdOffset);
-//				local_30.code = (void *)((int)buffer + 8);
-//				uVar4 = read_int32(buffer);
-//				local_30.codeEnd = (void *)(uVar4 + (int)local_30.code);
-//				actorId = run_script_field8_eq_4(&local_30);
-//				if ((actorId & 0xffff) != 0) {
-//					local_30.codeEnd =
-//							(void *)((uint)*(ushort *)((int)local_30.code + 2) +
-//									 (int)(void *)((int)local_30.code + 4));
-//					local_30.code = (void *)((int)local_30.code + 4);
-//					run_script(&local_30);
-//					_counter = 0;
-//				}
+				byte *obd = _dragonOBD->getFromOpt(actorId_00 - 1);
+				ScriptOpCall scriptOpCall;
+				scriptOpCall._code = obd + 8;
+				scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+
+				if(_scriptOpcodes->runScript4(scriptOpCall)) {
+					scriptOpCall._codeEnd = scriptOpCall._code + 4 + READ_LE_UINT16(scriptOpCall._code + 2);
+					scriptOpCall._code += 4;
+					_scriptOpcodes->runScript(scriptOpCall);
+					_counter = 0;
+				}
 			}
 		}
 		else {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index a591df983e..583f41f455 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -113,6 +113,10 @@ void ScriptOpcodes::initOpcodes() {
 
 	OPCODE(0x16, opUnk16);
 	OPCODE(0x17, opUnk17);
+	OPCODE(0x18, opUnk18);
+
+	OPCODE(0x1B, opUnk1B);
+	OPCODE(0x1C, opSetActorFlag0x1000);
 
 	OPCODE(0x1F, opPlayMusic);
 	OPCODE(0x20, opUnk20);
@@ -148,6 +152,14 @@ void ScriptOpcodes::runScript3(ScriptOpCall &scriptOpCall) {
 	executeScriptLoop(scriptOpCall);
 }
 
+bool ScriptOpcodes::runScript4(ScriptOpCall &scriptOpCall) {
+	scriptOpCall._field8 = 4;
+	scriptOpCall._result = 0;
+	_data_80071f5c = 0;
+	executeScriptLoop(scriptOpCall);
+	return scriptOpCall._result;
+}
+
 void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 
 	if (scriptOpCall._code >= scriptOpCall._codeEnd || scriptOpCall._result & 1) {
@@ -943,6 +955,50 @@ void ScriptOpcodes::opUnk17(ScriptOpCall &scriptOpCall) {
 
 }
 
+
+void ScriptOpcodes::opUnk18(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+	ARG_INT16(field8);
+	ARG_INT16(fieldA);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+	//TODO implement me!
+	error("opUnk18");
+}
+
+void ScriptOpcodes::opUnk1B(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(iniId);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	DragonINI *ini = _vm->getINI(iniId - 1);
+	if (ini->field_1a_flags_maybe & 1) {
+		while (ini->actor->isFlagSet(ACTOR_FLAG_10)) {
+			_vm->waitForFrames(1);
+		}
+	}
+}
+
+void ScriptOpcodes::opSetActorFlag0x1000(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(iniId);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	DragonINI *ini = _vm->getINI(iniId - 1);
+	ini->actor->isFlagSet(ACTOR_FLAG_1000);
+}
+
 void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
@@ -994,8 +1050,21 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 		}
 
 		if (ini->sceneId == 1) {
-			//TODO 0x8002d218
-			error("0x8002d218");
+			if ((uint)_vm->_cursor->iniItemInHand - 1 == ini->id) {
+				_vm->_cursor->data_800728b0_cursor_seqID = 0;
+				_vm->_cursor->_sequenceID = 0;
+				_vm->_cursor->iniItemInHand = 0;
+			}
+			else {
+				for (int i = 0; i < 0x29; i++) {
+					if (_vm->unkArray_uint16[i] - 1 == ini->id) {
+						_vm->unkArray_uint16[i] = 0;
+						if (_vm->_inventory->getType() == 1) {
+							ini->actor->clearFlag(ACTOR_FLAG_40);
+						}
+					}
+				}
+			}
 		}
 
 		if (sceneId == 1) {
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index f1d93641a0..f6d800e2ff 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -62,6 +62,7 @@ public:
 	~ScriptOpcodes();
 	void runScript(ScriptOpCall &scriptOpCall);
 	void runScript3(ScriptOpCall &scriptOpCall);
+	bool runScript4(ScriptOpCall &scriptOpCall);
 	void execOpcode(ScriptOpCall &scriptOpCall);
 	void executeScriptLoop(ScriptOpCall &scriptOpCall);
 	int16 FUN_800297d8(ScriptOpCall &scriptOpCall);
@@ -101,6 +102,9 @@ protected:
 	void opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opUnk16(ScriptOpCall &scriptOpCall);
 	void opUnk17(ScriptOpCall &scriptOpCall);
+	void opUnk18(ScriptOpCall &scriptOpCall);
+	void opUnk1B(ScriptOpCall &scriptOpCall);
+	void opSetActorFlag0x1000(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
 	void opUnk20(ScriptOpCall &scriptOpCall);
 


Commit: ba284455b6fd868d39295e51e0964728ef73d3e2
    https://github.com/scummvm/scummvm/commit/ba284455b6fd868d39295e51e0964728ef73d3e2
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on talk sequences

Changed paths:
  A engines/dragons/talk.cpp
  A engines/dragons/talk.h
    engines/dragons/actor.cpp
    engines/dragons/actorresource.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/module.mk
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sequenceopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 2e3ffc362e..7e4117b248 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -161,7 +161,7 @@ void Actor::loadFrame(uint16 frameOffset) {
 
 	surface = _actorResource->loadFrame(*frame, NULL); // TODO paletteId == 0xf1 ? getEngine()->getBackgroundPalette() : NULL);
 
-	debug(3, "ActorId: %d load frame header: (%d,%d) palette: %X", _actorID, frame->width, frame->height, paletteId);
+	debug(5, "ActorId: %d load frame header: (%d,%d) palette: %X", _actorID, frame->width, frame->height, paletteId);
 
 	flags |= Dragons::ACTOR_FLAG_8; //TODO check if this is the right spot. engine sets it at 0x800185b0
 
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 579c7e6ca6..6fa3d8d77b 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -110,7 +110,7 @@ Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame, byte *palett
 
 	int32 blockSize = ((actorFrame.width / 2) * actorFrame.height * 2) / 4;
 
-	debug(3, "Frame blockSize: %d width: %d height: %d", blockSize, actorFrame.width, actorFrame.height);
+	debug(5, "Frame blockSize: %d width: %d height: %d", blockSize, actorFrame.width, actorFrame.height);
 
 	byte *data = actorFrame.frameDataOffset;
 
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index a2034b8e99..13fce4c89a 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -42,6 +42,7 @@
 #include "sequenceopcodes.h"
 #include "scriptopcodes.h"
 #include "bag.h"
+#include "talk.h"
 
 namespace Dragons {
 
@@ -63,6 +64,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_engine = this;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
+	_talk = NULL;
 
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
@@ -108,6 +110,7 @@ void DragonsEngine::updateEvents() {
 Common::Error DragonsEngine::run() {
 	_screen = new Screen();
 	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
+	_talk = new Talk(this, _bigfileArchive);
 	_dragonFLG = new DragonFLG(_bigfileArchive);
 	_dragonIMG = new DragonIMG(_bigfileArchive);
 	_dragonOBD = new DragonOBD(_bigfileArchive);
@@ -666,7 +669,7 @@ void DragonsEngine::updateActorSequences() {
 			!(actor->flags & Dragons::ACTOR_FLAG_4) &&
 			!(actor->flags & Dragons::ACTOR_FLAG_400) &&
 			(actor->sequenceTimer == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
-			debug(3, "Actor[%d] execute sequenceOp", actorId);
+			debug(5, "Actor[%d] execute sequenceOp", actorId);
 
 			if (actor->flags & Dragons::ACTOR_FLAG_1) {
 				actor->resetSequenceIP();
@@ -1164,6 +1167,7 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 	_scriptOpcodes->_data_800728c0 = 0; //TODO this should be reset in scriptopcode.
 	_cursor->init(_actorManager, _dragonINIResource);
 	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
+	_talk->init();
 
 	if (sceneId > 2) {
 		_dragonVAR->setVar(1, 1);
@@ -1180,6 +1184,8 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 		sceneId = 0x12; // HACK the first scene. TODO remove this
 	}
 
+	_inventory->loadInventoryItemsFromSave();
+
 	if(getINI(0)->sceneId == 0) {
 		getINI(0)->sceneId = sceneId; //TODO
 	} else {
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index d49e5a180a..6c4c71b13f 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -66,7 +66,7 @@ enum Flags {
 	ENGINE_FLAG_200 = 0x200,
 	ENGINE_FLAG_400 = 0x400,
 
-	ENGINE_FLAG_TEXT_ENABLED = 0x1000,
+	ENGINE_FLAG_1000_TEXT_ENABLED = 0x1000,
 	ENGINE_FLAG_10000    =    0x10000,
 	ENGINE_FLAG_80000    =    0x80000,
 	ENGINE_FLAG_100000   =   0x100000,
@@ -112,6 +112,7 @@ class Screen;
 class ActorManager;
 class SequenceOpcodes;
 class ScriptOpcodes;
+class Talk;
 struct DragonINI;
 
 
@@ -127,6 +128,7 @@ public:
 	uint16 data_800633fa;
 	Inventory *_inventory;
 	Cursor *_cursor;
+	Talk *_talk;
 
 	uint16 unkArray_uint16[42];
 	opCode1AStruct opCode1A_tbl[8];
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 969fcea0ed..59a8c2f8eb 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -86,13 +86,7 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 		actorManager->loadActor(0, i); // TODO need to share resource between inventory item actors.
 	}
 
-	int j = 0;
-	for (int i=0; i < dragonIniResource->totalRecords() && j < 0x29; i++ ) {
-		DragonINI *ini = dragonIniResource->getRecord(i);
-		if (ini->sceneId == 1) {
-			_vm->unkArray_uint16[j++] = i + 1;
-		}
-	}
+	loadInventoryItemsFromSave();
 }
 
 
@@ -259,4 +253,14 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 	return 0;
 }
 
+void Inventory::loadInventoryItemsFromSave() {
+	int j = 0;
+	for (int i=0; i < _vm->_dragonINIResource->totalRecords() && j < 0x29; i++ ) {
+		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
+		if (ini->sceneId == 1) {
+			_vm->unkArray_uint16[j++] = i + 1;
+		}
+	}
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index a4d933eaa6..307ec62219 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -77,6 +77,7 @@ public:
 
 	void draw();
 	uint16 getIniAtPosition(int16 x, int16 y);
+	void loadInventoryItemsFromSave();
 private:
 	void animateBagIn();
 	void animateBagOut();
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 7af8e1da06..7eed03d390 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -21,7 +21,8 @@ MODULE_OBJS := \
 	screen.o \
 	scriptopcodes.o \
 	sequenceopcodes.o \
-	specialopcodes.o
+	specialopcodes.o \
+	talk.o
 
 MODULE_DIRS += \
 	engines/dragons
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 583f41f455..668f9f3757 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -32,6 +32,7 @@
 #include "dragons/scriptopcodes.h"
 #include "dragons/specialopcodes.h"
 #include "dragons/actor.h"
+#include "dragons/talk.h"
 #include "scriptopcodes.h"
 
 
@@ -783,8 +784,10 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 
 void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
-	ARG_INT16(actorId);
-	ARG_SKIP(6);
+	ARG_INT16(iniId);
+	ARG_INT16(startSequenceId);
+	ARG_INT16(endSequenceId);
+	ARG_SKIP(2);
 	ARG_UINT32(textIndex);
 
 	if (scriptOpCall._field8 != 0) {
@@ -792,7 +795,40 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 	}
 
 	//TODO implement actor talk.
-	debug("Actor talk: 0x%04x and text 0x%04x", actorId, textIndex);
+
+	char *dialog = NULL;
+	int sVar2 = -1; //TODO FUN_8001ca48(textIndex);
+
+	if (!_vm->isUnkFlagSet(1) && (!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || sVar2 == -1)) {
+		dialog = _vm->_talk->loadText(textIndex);
+	}
+
+	ushort uVar1;
+	int iVar2;
+	uint uVar3;
+
+	DragonINI *ini = iniId == 0 ? _vm->_dragonINIResource->getFlickerRecord() : _vm->getINI(iniId - 1);
+
+	if ((ini->field_1a_flags_maybe & 1) == 0) {
+		IMG *img = _vm->_dragonIMG->getIMG(ini->field_2);
+
+		int y = img->field_e == 0 ? img->y : img->y << 3;
+
+		_vm->_talk->FUN_8003239c(dialog,
+				(int)(((uint)img->field_a - (uint)_vm->_scene->_camera.x) * 0x10000) >> 0x13,
+				(int)(((y - 8) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13,
+				READ_LE_INT16(_vm->_dragonOBD->getFromOpt(iniId) + 6),
+				1,
+				ini->actor, startSequenceId, endSequenceId, textIndex);
+	}
+	else {
+		_vm->_talk->FUN_8003239c(dialog,
+								 (int)(((uint)ini->actor->x_pos - (uint)_vm->_scene->_camera.x) * 0x10000) >> 0x13,
+								 (int)(((ini->actor->y_pos - ini->actor->frame->yOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13,
+								 READ_LE_INT16(_vm->_dragonOBD->getFromOpt(iniId) + 6),
+								 1,
+								 ini->actor, startSequenceId, endSequenceId, textIndex);
+	}
 }
 
 void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 542a4ecd8b..fb78e78f78 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -64,7 +64,7 @@ void SequenceOpcodes::execOpcode(Actor *control, OpCall &opCall) {
 	assert(opCall._op < DRAGONS_NUM_SEQ_OPCODES);
 	if (!_opcodes[opCall._op])
 		error("SequenceOpcodes::execOpcode() Unimplemented opcode %d", opCall._op);
-	debug(3, "execSequenceOpcode(%d) %s", opCall._op, _opcodeNames[opCall._op].c_str());
+	debug(4, "execSequenceOpcode(%d) %s", opCall._op, _opcodeNames[opCall._op].c_str());
 	(*_opcodes[opCall._op])(control, opCall);
 }
 
@@ -117,7 +117,7 @@ void SequenceOpcodes::updateReturn(OpCall &opCall, uint16 size) {
 
 void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
 	ARG_INT16(framePointer);
-	debug(3, "set frame pointer %X", framePointer);
+	debug(4, "set frame pointer %X", framePointer);
 	actor->loadFrame((uint16)framePointer);
 	actor->flags |= Dragons::ACTOR_FLAG_2;
 	actor->sequenceTimer = actor->field_c;
@@ -135,7 +135,7 @@ void SequenceOpcodes::opJmp(Actor *actor, OpCall &opCall) {
 	if (!(actor->flags & Dragons::ACTOR_FLAG_1000)) {
 		byte *newOffset = actor->getSeqIpAtOffset((uint32)newIp);
 		opCall._deltaOfs = (int32)(newOffset - actor->_seqCodeIp); //opCall._code);
-		debug(3, "opJump delta: %d", opCall._deltaOfs);
+		debug(5, "opJump delta: %d", opCall._deltaOfs);
 	} else {
 		updateReturn(opCall, 1);
 	}
@@ -144,14 +144,14 @@ void SequenceOpcodes::opJmp(Actor *actor, OpCall &opCall) {
 void SequenceOpcodes::opSetFieldC(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newFieldC);
 	actor->field_c = (uint16)newFieldC;
-	debug(3, "set fieldC: %d", newFieldC);
+	debug(5, "set fieldC: %d", newFieldC);
 	updateReturn(opCall, 1);
 }
 
 void SequenceOpcodes::opSetSequenceTimer(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newSeqTimer);
 	actor->sequenceTimer = (uint16)newSeqTimer;
-	debug(3, "set sequenceTimer: %d", newSeqTimer);
+	debug(5, "set sequenceTimer: %d", newSeqTimer);
 	updateReturn(opCall, 1);
 	opCall._result = 0;
 }
@@ -163,7 +163,7 @@ void SequenceOpcodes::opUpdateXYResetSeqTimer(Actor *actor, OpCall &opCall) {
 	actor->y_pos += yOffset;
 	actor->sequenceTimer = actor->field_c;
 
-	debug(3, "update actor %d XY offset (%d,%d) new values (%d, %d) %d", actor->_actorID, xOffset, yOffset, actor->x_pos, actor->y_pos, actor->sequenceTimer);
+	debug(5, "update actor %d XY offset (%d,%d) new values (%d, %d) %d", actor->_actorID, xOffset, yOffset, actor->x_pos, actor->y_pos, actor->sequenceTimer);
 	updateReturn(opCall, 1);
 }
 
@@ -210,7 +210,7 @@ void SequenceOpcodes::opUpdateFlags(Actor *actor, OpCall &opCall) {
 
 void SequenceOpcodes::opPlaySound(Actor *actor, OpCall &opCall) {
 	ARG_INT16(soundId);
-	debug(3, "opPlaySound actorId: %d soundId: %d", actor->_actorID, soundId);
+	debug(5, "opPlaySound actorId: %d soundId: %d", actor->_actorID, soundId);
 
 	_vm->playSound((uint16)soundId);
 	updateReturn(opCall, 1);
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
new file mode 100644
index 0000000000..c87198f2a6
--- /dev/null
+++ b/engines/dragons/talk.cpp
@@ -0,0 +1,77 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <common/debug.h>
+#include "bigfile.h"
+#include "actor.h"
+#include "talk.h"
+#include "dragons.h"
+
+namespace Dragons {
+
+Talk::Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive): _vm(vm), _bigfileArchive(bigfileArchive) {
+
+}
+
+void Talk::init() {
+
+}
+
+char *Talk::loadText(uint32 textIndex) {
+	char filename[13] = "drag0000.txt";
+	uint32 fileNo = (textIndex >> 0xc) & 0xffff;
+	uint32 fileOffset = textIndex & 0xfff;
+
+	sprintf(filename, "drag%04d.txt", fileNo);
+	uint32 size;
+	byte *data = _bigfileArchive->load(filename, size);
+	printWideText(data + 10 + fileOffset);
+	delete data;
+	return NULL; //TODO fix me
+}
+
+void Talk::printWideText(byte *text) {
+	char buf[2000];
+	int i = 0;
+	for (; READ_LE_INT16(text) != 0 && i < 1999; i++) {
+		buf[i] = *text;
+		text += 2;
+	}
+	buf[i] = 0;
+	debug("TEXT: %s", buf);
+}
+
+void
+Talk::FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId,
+				   uint16 endSequenceId, uint32 textId) {
+	//TODO 0x800323a4
+
+	//TODO dragon_text_related(textId);
+	_vm->data_800633fc = 1;
+	uint32 uVar4 = 0; //TODO FUN_8001d1ac(0,textId,0);
+
+	actor->updateSequence(startSequenceId);
+	//TODO conversation_related_maybe(&dialog[10],(int)x,(int)y,param_4 & 0xffff,(uint)param_5,textId,uVar4 & 0xffff);
+	actor->updateSequence(endSequenceId);
+}
+
+} // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
new file mode 100644
index 0000000000..b1d2133515
--- /dev/null
+++ b/engines/dragons/talk.h
@@ -0,0 +1,49 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef DRAGONS_TALK_H
+#define DRAGONS_TALK_H
+
+#include <common/str.h>
+
+namespace Dragons {
+
+class BigfileArchive;
+class Actor;
+class DragonsEngine;
+
+class Talk {
+private:
+	DragonsEngine *_vm;
+	BigfileArchive *_bigfileArchive;
+public:
+	Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive);
+	void init();
+	char *loadText(uint32 textIndex);
+	void printWideText(byte *text);
+
+	void FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId, uint16 endSequenceId, uint32 textId);
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_TALK_H


Commit: 5e3804e0e05ad7ee955df75c2c1c035cc5780034
    https://github.com/scummvm/scummvm/commit/5e3804e0e05ad7ee955df75c2c1c035cc5780034
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on flicker talk logic

Changed paths:
    engines/dragons/dragons.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 6c4c71b13f..0e328c86d2 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -72,6 +72,7 @@ enum Flags {
 	ENGINE_FLAG_100000   =   0x100000,
 	ENGINE_FLAG_200000   =   0x200000,
 	ENGINE_FLAG_400000   =   0x400000,
+	ENGINE_FLAG_2000000  =  0x2000000,
 	ENGINE_FLAG_4000000  =  0x4000000,
 	ENGINE_FLAG_8000000  =  0x8000000,
 	ENGINE_FLAG_20000000 = 0x20000000,
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 668f9f3757..5e1e508dfc 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -748,11 +748,60 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 
 void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
-	ARG_INT16(actorId)
+	ARG_INT16(iniId)
 	ARG_UINT32(textIndex)
 	// TODO implement me!
 
-    debug("Main actor talk: 0x%04x and text 0x%04x", actorId, textIndex);
+    debug("Main actor talk: 0x%04x and text 0x%04x", iniId, textIndex);
+
+	if (textIndex == 0) {
+		return;
+	}
+	Actor *actor = NULL;
+	if (iniId == 0) {
+		//TODO playSoundFromTxtIndex(textIndex);
+		actor = _vm->_dragonINIResource->getFlickerRecord()->actor;
+		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
+			if (_vm->getCurrentSceneId() == 0x32) {
+				_vm->getINI(0x2b1)->actor->updateSequence(2);
+			}
+			else {
+				actor->setFlag(ACTOR_FLAG_2000);
+				if (actor->_sequenceID2 != -1) {
+					actor->updateSequence(actor->_sequenceID2 + 0x10);
+				}
+			}
+		}
+		else {
+			if (actor->_sequenceID == 5) {
+				actor->updateSequence(0x10);
+			}
+		}
+	}
+	// TODO sVar1 = findTextToDtSpeechIndex(textIndex);
+//	pcVar2 = (char *)0x0;
+//	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
+//		pcVar2 = load_string_from_dragon_txt(textIndex,acStack2016);
+//	}
+//	FUN_80031d98((uint)iniId,pcVar2,textIndex);
+	if (iniId == 0) {
+		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
+			if (_vm->getCurrentSceneId() != 0x32) {
+				actor->setFlag(ACTOR_FLAG_4);
+				actor->clearFlag(ACTOR_FLAG_2000);
+				_vm->waitForFrames(1);
+				return;
+			}
+			_vm->getINI(0x2b1)->actor->updateSequence(1);
+
+		}
+		else {
+			if (actor->_sequenceID != 0x10) {
+				return;
+			}
+			actor->updateSequence(5);
+		}
+	}
 }
 
 void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index c87198f2a6..0f4f87a8be 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -44,6 +44,7 @@ char *Talk::loadText(uint32 textIndex) {
 	sprintf(filename, "drag%04d.txt", fileNo);
 	uint32 size;
 	byte *data = _bigfileArchive->load(filename, size);
+	debug("DIALOG: %s, %d", filename, fileOffset);
 	printWideText(data + 10 + fileOffset);
 	delete data;
 	return NULL; //TODO fix me


Commit: e399d5b27232d50b4fac55b7734ae1462462e178
    https://github.com/scummvm/scummvm/commit/e399d5b27232d50b4fac55b7734ae1462462e178
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGOMS: work on speech audio

Changed paths:
  A engines/dragons/sound.cpp
  A engines/dragons/sound.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 13fce4c89a..a3822cd44c 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -43,6 +43,7 @@
 #include "scriptopcodes.h"
 #include "bag.h"
 #include "talk.h"
+#include "sound.h"
 
 namespace Dragons {
 
@@ -65,6 +66,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
 	_talk = NULL;
+	_sound = new Sound(this);
 
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
@@ -568,6 +570,11 @@ void DragonsEngine::updateHandler() {
 	_cursor->updateVisibility();
 	_inventory->updateVisibility();
 
+	// 0x8001b200
+	if (isFlagSet(ENGINE_FLAG_8000) && !_sound->isSpeechPlaying()) {
+		clearFlags(ENGINE_FLAG_8000);
+	}
+
 	//TODO logic here
 	for (uint16 i = 0; i < 0x17; i++) {
 		Actor *actor = _actorManager->getActor(i);
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 0e328c86d2..7fe4bf22bb 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -67,6 +67,8 @@ enum Flags {
 	ENGINE_FLAG_400 = 0x400,
 
 	ENGINE_FLAG_1000_TEXT_ENABLED = 0x1000,
+	ENGINE_FLAG_8000     =     0x8000, // speech dialog is playing.
+
 	ENGINE_FLAG_10000    =    0x10000,
 	ENGINE_FLAG_80000    =    0x80000,
 	ENGINE_FLAG_100000   =   0x100000,
@@ -114,6 +116,7 @@ class ActorManager;
 class SequenceOpcodes;
 class ScriptOpcodes;
 class Talk;
+class Sound;
 struct DragonINI;
 
 
@@ -130,6 +133,7 @@ public:
 	Inventory *_inventory;
 	Cursor *_cursor;
 	Talk *_talk;
+	Sound *_sound;
 
 	uint16 unkArray_uint16[42];
 	opCode1AStruct opCode1A_tbl[8];
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 7eed03d390..c5b8f77b84 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -22,6 +22,7 @@ MODULE_OBJS := \
 	scriptopcodes.o \
 	sequenceopcodes.o \
 	specialopcodes.o \
+	sound.o \
 	talk.o
 
 MODULE_DIRS += \
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 5e1e508dfc..afd6b0e674 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -1081,7 +1081,7 @@ void ScriptOpcodes::opSetActorFlag0x1000(ScriptOpCall &scriptOpCall) {
 	}
 
 	DragonINI *ini = _vm->getINI(iniId - 1);
-	ini->actor->isFlagSet(ACTOR_FLAG_1000);
+	ini->actor->setFlag(ACTOR_FLAG_1000);
 }
 
 void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index fb78e78f78..af1d3c1f20 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -202,8 +202,8 @@ void SequenceOpcodes::opSetField7a(Actor *actor, OpCall &opCall) {
 }
 
 void SequenceOpcodes::opUpdateFlags(Actor *actor, OpCall &opCall) {
-	if (actor->flags & Dragons::ACTOR_FLAG_1000) {
-		actor->flags &= Dragons::ACTOR_FLAG_4;
+	if(actor->isFlagSet(ACTOR_FLAG_1000)) {
+		actor->setFlag(ACTOR_FLAG_4);
 	}
 	updateReturn(opCall, 0);
 }
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
new file mode 100644
index 0000000000..95daca13b8
--- /dev/null
+++ b/engines/dragons/sound.cpp
@@ -0,0 +1,247 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "sound.h"
+#include "dragons.h"
+#include "audio/mixer.h"
+#include "audio/audiostream.h"
+#include "audio/decoders/raw.h"
+#include "audio/decoders/xa.h"
+#include "common/file.h"
+
+#define RAW_CD_SECTOR_SIZE 2352
+
+#define CDXA_TYPE_MASK     0x0E
+#define CDXA_TYPE_DATA     0x08
+#define CDXA_TYPE_AUDIO    0x04
+
+namespace Dragons {
+
+struct SpeechLocation {
+	uint32 talkId;
+	uint16 sectorStart;
+	int8 startOffset;
+	uint16 sectorEnd;
+} SpeechLocation;
+
+Sound::Sound(DragonsEngine *vm): _vm(vm) {
+}
+
+void CdIntToPos_0(uint32 param_1)//, byte *param_2)
+{
+	int iVar1;
+	int iVar2;
+	int iVar3;
+	uint8 minute;
+	uint8 second;
+	uint8 sector;
+
+	iVar3 = (param_1 + 0x96) / 0x4b;
+	iVar2 = (param_1 + 0x96) % 0x4b;
+	iVar1 = iVar3 / 0x3c;
+	iVar3 = iVar3 % 0x3c;
+	second = (char)iVar3 + (char)(iVar3 / 10) * 6;
+	sector = (char)iVar2 + (char)(iVar2 / 10) * 6;
+	minute = (char)iVar1 + (char)(iVar1 / 10) * 6;
+
+
+	uint32 out =          (((uint)(minute >> 4) * 10 + ((uint)minute & 0xf)) * 0x3c +
+						   (uint)(second >> 4) * 10 + ((uint)second & 0xf)) * 0x4b +
+						  (uint)(sector >> 4) * 10 + ((uint)sector & 0xf) + -0x96;
+
+	debug("Seek Audio %2X:%2X:%2X  in: %d out %d", minute, second, sector, param_1, out);
+
+	return;
+}
+
+void Sound::playSpeech(uint32 textIndex) {
+	if (isSpeechPlaying()) {
+//		_vm->_mixer->stopHandle(_speechHandle);
+		return;
+	}
+
+	struct SpeechLocation speechLocation;
+	if (!getSpeechLocation(textIndex, &speechLocation)) {
+		return;
+	}
+
+	Common::File *fd = new Common::File();
+	if (!fd->open("dtspeech.xa")) {
+		error("Failed to open dtspeech.xa");
+	}
+	CdIntToPos_0(speechLocation.sectorStart * 32);
+	fd->seek(((speechLocation.sectorStart * 32) + speechLocation.startOffset) * RAW_CD_SECTOR_SIZE);
+	PSXAudioTrack *_audioTrack = new PSXAudioTrack(fd, Audio::Mixer::SoundType::kSpeechSoundType);
+	for (int i = 0x0; i < speechLocation.sectorEnd - speechLocation.sectorStart;i++) {
+		fd->seek(((speechLocation.sectorStart * 32) + speechLocation.startOffset + i * 32) * RAW_CD_SECTOR_SIZE);
+		_audioTrack->queueAudioFromSector(fd);
+	}
+	_audioTrack->getAudioStream()->finish();
+	_vm->setFlags(ENGINE_FLAG_8000);
+	_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, _audioTrack->getAudioStream());
+	delete _audioTrack;
+}
+
+bool Sound::isSpeechPlaying() {
+	return _vm->_mixer->isSoundHandleActive(_speechHandle);
+}
+
+bool Sound::getSpeechLocation(uint32 talkId, struct SpeechLocation *location) {
+	Common::File *fd = new Common::File();
+	if (!fd->open("dragon.exe")) {
+		error("Failed to open dragon.exe");
+	}
+	fd->seek(0x4e138);
+	bool foundId = false;
+	for (int i = 0; i < 2272; i++) {
+		uint32 id = (fd->readUint32LE() & 0xffffff);
+		fd->seek(-1, SEEK_CUR);
+		int8 startOffset = fd->readSByte();
+		uint16 start = fd->readUint16LE();
+		uint16 end = fd->readUint16LE();
+		if (id == talkId) {
+			location->talkId = id;
+			location->sectorStart = start;
+			location->startOffset = startOffset;
+			location->sectorEnd = end;
+			foundId = true;
+			debug("sectors [%d-%d] unk byte = %d", start * 32, end * 32, startOffset);
+			break;
+		}
+	}
+
+	fd->close();
+	delete fd;
+
+	return foundId;
+}
+
+Sound::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType) {
+	sector->skip(19);
+	byte format = sector->readByte();
+	bool stereo = (format & (1 << 0)) != 0;
+	uint rate = (format & (1 << 2)) ? 18900 : 37800;
+	_audStream = Audio::makeQueuingAudioStream(rate, stereo);
+
+	memset(&_adpcmStatus, 0, sizeof(_adpcmStatus));
+}
+
+Sound::PSXAudioTrack::~PSXAudioTrack() {
+}
+
+// Ha! It's palindromic!
+#define AUDIO_DATA_CHUNK_SIZE   2304
+#define AUDIO_DATA_SAMPLE_COUNT 4032
+
+static const int s_xaTable[5][2] = {
+		{   0,   0 },
+		{  60,   0 },
+		{ 115, -52 },
+		{  98, -55 },
+		{ 122, -60 }
+};
+
+void Sound::PSXAudioTrack::queueAudioFromSector(Common::SeekableReadStream *sector) {
+	sector->skip(24);
+
+	// This XA audio is different (yet similar) from normal XA audio! Watch out!
+	// TODO: It's probably similar enough to normal XA that we can merge it somehow...
+	// TODO: RTZ PSX needs the same audio code in a regular AudioStream class. Probably
+	// will do something similar to QuickTime and creating a base class 'ISOMode2Parser'
+	// or something similar.
+	byte *buf = new byte[AUDIO_DATA_CHUNK_SIZE];
+	sector->read(buf, AUDIO_DATA_CHUNK_SIZE);
+
+	int channels = _audStream->isStereo() ? 2 : 1;
+	int16 *dst = new int16[AUDIO_DATA_SAMPLE_COUNT];
+	int16 *leftChannel = dst;
+	int16 *rightChannel = dst + 1;
+
+	for (byte *src = buf; src < buf + AUDIO_DATA_CHUNK_SIZE; src += 128) {
+		for (int i = 0; i < 4; i++) {
+			int shift = 12 - (src[4 + i * 2] & 0xf);
+			int filter = src[4 + i * 2] >> 4;
+			int f0 = s_xaTable[filter][0];
+			int f1 = s_xaTable[filter][1];
+			int16 s_1 = _adpcmStatus[0].sample[0];
+			int16 s_2 = _adpcmStatus[0].sample[1];
+
+			for (int j = 0; j < 28; j++) {
+				byte d = src[16 + i + j * 4];
+				int t = (int8)(d << 4) >> 4;
+				int s = (t << shift) + ((s_1 * f0 + s_2 * f1 + 32) >> 6);
+				s_2 = s_1;
+				s_1 = CLIP<int>(s, -32768, 32767);
+				*leftChannel = s_1;
+				leftChannel += channels;
+			}
+
+			if (channels == 2) {
+				_adpcmStatus[0].sample[0] = s_1;
+				_adpcmStatus[0].sample[1] = s_2;
+				s_1 = _adpcmStatus[1].sample[0];
+				s_2 = _adpcmStatus[1].sample[1];
+			}
+
+			shift = 12 - (src[5 + i * 2] & 0xf);
+			filter = src[5 + i * 2] >> 4;
+			f0 = s_xaTable[filter][0];
+			f1 = s_xaTable[filter][1];
+
+			for (int j = 0; j < 28; j++) {
+				byte d = src[16 + i + j * 4];
+				int t = (int8)d >> 4;
+				int s = (t << shift) + ((s_1 * f0 + s_2 * f1 + 32) >> 6);
+				s_2 = s_1;
+				s_1 = CLIP<int>(s, -32768, 32767);
+
+				if (channels == 2) {
+					*rightChannel = s_1;
+					rightChannel += 2;
+				} else {
+					*leftChannel++ = s_1;
+				}
+			}
+
+			if (channels == 2) {
+				_adpcmStatus[1].sample[0] = s_1;
+				_adpcmStatus[1].sample[1] = s_2;
+			} else {
+				_adpcmStatus[0].sample[0] = s_1;
+				_adpcmStatus[0].sample[1] = s_2;
+			}
+		}
+	}
+
+	int flags = Audio::FLAG_16BITS;
+
+	if (_audStream->isStereo())
+		flags |= Audio::FLAG_STEREO;
+
+#ifdef SCUMM_LITTLE_ENDIAN
+	flags |= Audio::FLAG_LITTLE_ENDIAN;
+#endif
+
+	_audStream->queueBuffer((byte *)dst, AUDIO_DATA_SAMPLE_COUNT * 2, DisposeAfterUse::YES, flags);
+	delete[] buf;
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
new file mode 100644
index 0000000000..5bd1e62852
--- /dev/null
+++ b/engines/dragons/sound.h
@@ -0,0 +1,68 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef DRAGONS_SOUND_H
+#define DRAGONS_SOUND_H
+
+#include "common/scummsys.h"
+#include "audio/mixer.h"
+#include "audio/audiostream.h"
+
+
+namespace Dragons {
+
+class DragonsEngine;
+struct SpeechLocation;
+
+class Sound {
+private:
+	DragonsEngine *_vm;
+	Audio::SoundHandle _speechHandle;
+
+public:
+	Sound(DragonsEngine *vm);
+	void playSpeech(uint32 textIndex);
+	bool isSpeechPlaying();
+private:
+	bool getSpeechLocation(uint32 talkId, struct SpeechLocation *location);
+
+private:
+	class PSXAudioTrack {
+	public:
+		PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
+		~PSXAudioTrack();
+
+		void queueAudioFromSector(Common::SeekableReadStream *sector);
+		Audio::QueuingAudioStream *getAudioStream() {
+			return _audStream;
+		}
+	private:
+		Audio::QueuingAudioStream *_audStream;
+
+		struct ADPCMStatus {
+			int16 sample[2];
+		} _adpcmStatus[2];
+	};
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_SOUND_H
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 0f4f87a8be..13b54f58b1 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -24,6 +24,7 @@
 #include "bigfile.h"
 #include "actor.h"
 #include "talk.h"
+#include "sound.h"
 #include "dragons.h"
 
 namespace Dragons {
@@ -71,8 +72,21 @@ Talk::FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5
 	uint32 uVar4 = 0; //TODO FUN_8001d1ac(0,textId,0);
 
 	actor->updateSequence(startSequenceId);
-	//TODO conversation_related_maybe(&dialog[10],(int)x,(int)y,param_4 & 0xffff,(uint)param_5,textId,uVar4 & 0xffff);
+	_vm->_sound->playSpeech(textId);
+	conversation_related_maybe(NULL /*TODO &dialog[10]*/, (int)x, (int)y,param_4 & 0xffff, (uint)param_5, textId, uVar4 & 0xffff);
+
 	actor->updateSequence(endSequenceId);
 }
 
+void
+Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
+								 int16 param_7) {
+	//TODO display dialog text here and wait for audio stream to complete.
+
+	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
+		_vm->waitForFrames(1);
+	}
+}
+
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index b1d2133515..5a4729adff 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -42,6 +42,9 @@ public:
 	void printWideText(byte *text);
 
 	void FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId, uint16 endSequenceId, uint32 textId);
+
+	void conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId, int16 param_7);
+
 };
 
 } // End of namespace Dragons


Commit: 7cf98ce5d3c8e658a5c42bbad1408c89e9f66738
    https://github.com/scummvm/scummvm/commit/7cf98ce5d3c8e658a5c42bbad1408c89e9f66738
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: more dialog work

Changed paths:
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index afd6b0e674..bb7b8607ff 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -92,6 +92,7 @@ void ScriptOpcodes::initOpcodes() {
 	}
 	// Register opcodes
 	OPCODE(1, opUnk1);
+	OPCODE(2, opUnk2); //dialog related
 
 	OPCODE(4,  opExecuteScript);
 	OPCODE(5,  opActorSetSequenceID2);
@@ -230,6 +231,22 @@ void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opUnk2(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+	ARG_INT16(field8);
+	ARG_INT16(fieldA);
+	ARG_INT16(fieldC);
+	ARG_INT16(fieldE);
+
+	if (scriptOpCall._field8 == 2) {
+		//TODO do something here.
+	}
+	scriptOpCall._code += fieldA;
+}
+
 void ScriptOpcodes::opExecuteScript(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_UINT32(obdOffset);
@@ -779,11 +796,13 @@ void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 		}
 	}
 	// TODO sVar1 = findTextToDtSpeechIndex(textIndex);
+	char *dialog = _vm->_talk->loadText(textIndex);
+
 //	pcVar2 = (char *)0x0;
 //	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
 //		pcVar2 = load_string_from_dragon_txt(textIndex,acStack2016);
 //	}
-//	FUN_80031d98((uint)iniId,pcVar2,textIndex);
+	_vm->_talk->displayDialogAroundINI(iniId, NULL, textIndex); //TODO need to pass dialog here (pcVar2). not NULL
 	if (iniId == 0) {
 		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
 			if (_vm->getCurrentSceneId() != 0x32) {
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index f6d800e2ff..2b89dffac9 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -82,6 +82,7 @@ protected:
 
 	// Opcodes
 	void opUnk1(ScriptOpCall &scriptOpCall);
+	void opUnk2(ScriptOpCall &scriptOpCall);
 	void opExecuteScript(ScriptOpCall &scriptOpCall); //op 4
 	void opActorSetSequenceID2(ScriptOpCall &scriptOpCall); //op 5
 	void opUnk6(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 13b54f58b1..7e760c984f 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -23,9 +23,14 @@
 #include <common/debug.h>
 #include "bigfile.h"
 #include "actor.h"
+#include "actorresource.h"
 #include "talk.h"
 #include "sound.h"
 #include "dragons.h"
+#include "dragonini.h"
+#include "dragonimg.h"
+#include "dragonobd.h"
+#include "scene.h"
 
 namespace Dragons {
 
@@ -81,7 +86,7 @@ Talk::FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5
 void
 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
 								 int16 param_7) {
-	//TODO display dialog text here and wait for audio stream to complete.
+	//TODO display dialog text here while we wait for audio stream to complete.
 
 	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
 		_vm->waitForFrames(1);
@@ -89,4 +94,77 @@ Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16
 }
 
 
+uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex)
+
+{
+	DragonINI *ini = iniId == 0 ? _vm->_dragonINIResource->getFlickerRecord() : _vm->getINI(iniId - 1);
+
+	if ((ini->field_1a_flags_maybe & 1) == 0) {
+		IMG *local_v1_184 = _vm->_dragonIMG->getIMG(ini->field_2);
+		int x, y;
+		if (local_v1_184->field_e == 0) {
+			y = (uint)(ushort)local_v1_184->y;
+			x = local_v1_184->field_a;
+		}
+		else {
+			x = local_v1_184->field_a;
+			y = (uint)(ushort)local_v1_184->y << 3;
+		}
+		displayDialogAroundPoint
+				(dialogText,
+						((x - _vm->_scene->_camera.x) * 0x10000) >> 0x13,
+				 ((y - _vm->_scene->_camera.y) * 0x10000) >> 0x13,
+				 READ_LE_UINT16(_vm->_dragonOBD->getFromOpt(ini->id) + 6)
+						,1,textIndex);
+	}
+	else {
+		displayDialogAroundActor
+				(ini->actor,
+				 READ_LE_UINT16(_vm->_dragonOBD->getFromOpt(ini->id) + 6),
+				 dialogText,textIndex);
+	}
+	return 1;
+}
+
+void
+Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId) {
+// TODO
+//
+//		puVar1 = &DAT_80011a60;
+//		puVar2 = local_58;
+//		do {
+//			puVar8 = puVar2;
+//			puVar7 = puVar1;
+//			uVar4 = puVar7[1];
+//			uVar5 = puVar7[2];
+//			uVar6 = puVar7[3];
+//			*puVar8 = *puVar7;
+//			puVar8[1] = uVar4;
+//			puVar8[2] = uVar5;
+//			puVar8[3] = uVar6;
+//			puVar1 = puVar7 + 4;
+//			puVar2 = puVar8 + 4;
+//		} while (puVar7 + 4 != (undefined4 *)&DAT_80011a80);
+//		uVar4 = puVar7[5];
+//		puVar8[4] = _DAT_80011a80;
+//		puVar8[5] = uVar4;
+		_vm->data_800633fc = 1;
+
+		// sVar3 = FUN_8001d1ac(0,textId,0);
+		_vm->_sound->playSpeech(textId);
+
+//		if (dialogText == (uint16_t *)0x0) {
+//			dialogText = (uint16_t *)local_58;
+//		}
+		conversation_related_maybe(dialogText + 5,x,y,param_4,param_5,textId,0); // sVar3); TODO I think this is audio status
+}
+
+void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex) {
+	displayDialogAroundPoint
+			(dialogText,(ushort)((int)(((uint)actor->x_pos - _vm->_scene->_camera.x) * 0x10000) >> 0x13),
+			 (short)((int)((((uint)actor->y_pos - (uint)actor->frame->yOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13) - 3,
+			 param_2,1,textIndex);
+}
+
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 5a4729adff..4a6f8e1016 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -41,6 +41,10 @@ public:
 	char *loadText(uint32 textIndex);
 	void printWideText(byte *text);
 
+	uint32 displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex);
+	void displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId);
+	void displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex);
+
 	void FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId, uint16 endSequenceId, uint32 textId);
 
 	void conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId, int16 param_7);


Commit: fe6600cc1f198fc94e4b92d5bda63d03b2a09661
    https://github.com/scummvm/scummvm/commit/fe6600cc1f198fc94e4b92d5bda63d03b2a09661
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added Font class

Changed paths:
  A engines/dragons/font.cpp
  A engines/dragons/font.h
    engines/dragons/actorresource.cpp
    engines/dragons/actorresource.h
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 6fa3d8d77b..3290569700 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -190,4 +190,8 @@ byte *ActorResource::getSequenceDataAtOffset(uint32 offset) {
 	return &_data[offset];
 }
 
+byte *ActorResource::getPalette() {
+	return _palette;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index f6ad943615..c2014dc474 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -73,6 +73,7 @@ public:
 	byte *getSequenceData(int16 sequenceId);
 	byte *getSequenceDataAtOffset(uint32 offset);
 	const char *getFilename();
+	byte *getPalette();
 
 private:
 	void writePixelBlock(byte *pixels, byte *data, byte *palette);
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 205a913d79..24016aea54 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -347,4 +347,8 @@ void Cursor::setActorFlag400() {
 	_actor->setFlag(ACTOR_FLAG_400);
 }
 
+byte *Cursor::getPalette() {
+	return _actor->_actorResource->getPalette();
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index d9c78fceeb..ef714e24a6 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -60,6 +60,7 @@ public:
 	void selectPreviousCursor();
 	void selectNextCursor();
 	void setActorFlag400();
+	byte *getPalette();
 private:
 	int16 updateIniFromScene();
 };
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index a3822cd44c..786e2dbb1a 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -36,6 +36,7 @@
 #include "dragonrms.h"
 #include "dragonvar.h"
 #include "dragons.h"
+#include "font.h"
 #include "inventory.h"
 #include "scene.h"
 #include "screen.h"
@@ -67,6 +68,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_cursor = new Cursor(this);
 	_talk = NULL;
 	_sound = new Sound(this);
+	_fontManager = NULL;
 
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
@@ -119,6 +121,7 @@ Common::Error DragonsEngine::run() {
 	_dragonRMS = new DragonRMS(_bigfileArchive, _dragonOBD);
 	_dragonVAR = new DragonVAR(_bigfileArchive);
 	_dragonINIResource = new DragonINIResource(_bigfileArchive);
+	_fontManager = new FontManager(this, _screen, _bigfileArchive);
 	ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
 	_actorManager = new ActorManager(actorResourceLoader);
 	_scriptOpcodes = new ScriptOpcodes(this, _dragonFLG);
@@ -143,6 +146,7 @@ Common::Error DragonsEngine::run() {
 	delete _dragonIMG;
 	delete _dragonRMS;
 	delete _dragonVAR;
+	delete _fontManager;
 	delete _bigfileArchive;
 	delete _screen;
 
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 7fe4bf22bb..8ac860290a 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -109,6 +109,7 @@ class DragonOBD;
 class DragonRMS;
 class DragonVAR;
 class DragonINIResource;
+class FontManager;
 class Inventory;
 class Scene;
 class Screen;
@@ -127,6 +128,7 @@ public:
 	DragonRMS *_dragonRMS;
 	ActorManager *_actorManager;
 	DragonINIResource *_dragonINIResource;
+	FontManager *_fontManager;
 	ScriptOpcodes *_scriptOpcodes;
 	Scene *_scene;
 	uint16 data_800633fa;
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
new file mode 100644
index 0000000000..29100f9371
--- /dev/null
+++ b/engines/dragons/font.cpp
@@ -0,0 +1,183 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include <common/memstream.h>
+#include <common/textconsole.h>
+#include "bigfile.h"
+#include "cursor.h"
+#include "font.h"
+#include "scene.h"
+#include "screen.h"
+#include "dragons.h"
+
+
+namespace Dragons {
+
+Font::Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelSize) {
+	_size = mapSize / 2;
+	_map = (uint16 *)malloc(mapSize);
+	if (!_map) {
+		error("Allocating memory for font map.");
+	}
+
+	for (int i = 0; i < _size; i++) {
+		_map[i] = stream.readUint16LE();
+	}
+
+	_pixels = (byte *)malloc(pixelSize);
+	if (!_pixels) {
+		error("Allocating memory for font pixels.");
+	}
+
+	stream.read(_pixels, pixelSize);
+}
+
+Font::~Font() {
+	free(_map);
+	free(_pixels);
+}
+
+void writePixelBlock(byte *pixels, byte *data, byte *palette) {
+	pixels[2] = palette[data[1] * 2];
+	pixels[3] = palette[data[1] * 2 + 1];
+	pixels[4] = palette[data[2] * 2];
+	pixels[5] = palette[data[2] * 2 + 1];
+	pixels[6] = palette[data[3] * 2];
+	pixels[7] = palette[data[3] * 2 + 1];
+}
+
+
+Graphics::Surface *Font::render(uint16 *text, uint16 length, byte *palette) {
+	Graphics::Surface *surface = new Graphics::Surface();
+	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
+	surface->create(length * 8, 8, pixelFormat16);
+
+
+	for (int i = 0; i < length; i++) {
+		byte *pixels = (byte *)surface->getPixels();
+		pixels += i * 8 * 2;
+		byte *data = _pixels + i * 64; //(_map[text[i] + 5] ) * 64;
+		for (int y = 0; y < 8; y++) {
+			for (int x = 0; x < 8; x++) {
+				pixels[x * 2] = palette[(data[0]+2) * 2];
+				pixels[x * 2 + 1] = palette[(data[0]+2) * 2 + 1];
+				data++;
+			}
+			pixels += surface->pitch;
+		}
+	}
+
+	return surface;
+}
+
+FontManager::FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive): _vm(vm), _screen(screen) {
+	uint32 fileSize;
+	byte *data = bigfileArchive->load("fntfiles.dat", fileSize);
+	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(data, fileSize, DisposeAfterUse::YES);
+
+	_fonts[0] = loadFont(0, *readStream);
+	_fonts[1] = loadFont(1, *readStream);
+	_fonts[2] = loadFont(2, *readStream);
+
+	loadPalettes();
+
+	delete readStream;
+}
+
+FontManager::~FontManager() {
+	delete _fonts[0];
+	delete _fonts[1];
+	delete _fonts[2];
+	free(_palettes);
+}
+
+void FontManager::addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 fontType) {
+	assert(length < 1024);
+	assert(fontType < 4);
+	byte *palette = _vm->_cursor->getPalette();
+	ScreenTextEntry *screenTextEntry = new ScreenTextEntry();
+	screenTextEntry->position = Common::Point(x, y);
+	screenTextEntry->surface = _fonts[fontType]->render(text, length, palette);
+
+	_screenTexts.push_back(screenTextEntry);
+
+}
+
+void FontManager::draw() {
+	Common::List<ScreenTextEntry*>::iterator it = _screenTexts.begin();
+	while (it != _screenTexts.end()) {
+		ScreenTextEntry *entry = *it;
+//		_screen->copyRectToSurface(*entry->surface, entry->position.x, entry->position.y);
+		_screen->copyRectToSurface(*entry->surface, entry->position.x, entry->position.y, Common::Rect(entry->surface->w, entry->surface->h));
+
+		it++;
+	}
+}
+
+void FontManager::clearText() {
+	while (!_screenTexts.empty()) {
+		ScreenTextEntry *screenText = _screenTexts.back();
+		screenText->surface->free();
+		delete screenText->surface;
+		delete screenText;
+		_screenTexts.pop_back();
+	}
+}
+
+Font *FontManager::loadFont(uint16 index, Common::SeekableReadStream &stream) {
+	Common::File fd;
+	if (!fd.open("dragon.exe")) {
+		error("Failed to open dragon.exe");
+	}
+	fd.seek(0x4a144); //TODO handle other game variants
+	fd.skip((index * 2)  * 28);
+
+//	fd->read(info.filename, 16);
+	fd.skip(16);
+	uint32 mapOffset = fd.readUint32LE();
+	uint32 mapSize = fd.readUint32LE();
+	fd.skip(4); //unk
+
+	fd.skip(16); //filename
+//	uint32 pixelsOffset = fd.readUint32LE();
+	uint32 pixelsSize = fd.readUint32LE();
+
+	fd.close();
+
+	stream.seek(mapOffset);
+	return new Font(stream, mapSize, pixelsSize);
+}
+
+void FontManager::loadPalettes() {
+	Common::File fd;
+	if (!fd.open("dragon.exe")) {
+		error("Failed to open dragon.exe");
+	}
+	fd.seek(0x5336c); //TODO handle other game variants
+
+	_palettes = (byte *)malloc(256 * 2 * 4);
+	fd.read(_palettes, 256 * 2 * 4);
+
+	_palettes[2 * 256 + 0x21] = 0x80; //HACK make this color transparent
+	fd.close();
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
new file mode 100644
index 0000000000..ae78a59335
--- /dev/null
+++ b/engines/dragons/font.h
@@ -0,0 +1,73 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 DRAGONS_FONT_H
+#define DRAGONS_FONT_H
+
+#include <common/scummsys.h>
+#include <common/stream.h>
+#include <graphics/surface.h>
+#include <common/rect.h>
+
+namespace Dragons {
+
+class DragonsEngine;
+class BigfileArchive;
+class Screen;
+
+class Font {
+private:
+	uint32 _size;
+	uint16 *_map;
+	byte *_pixels;
+public:
+	Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelSize);
+	~Font();
+	Graphics::Surface *render(uint16 *text, uint16 length, byte *palette);
+};
+
+struct ScreenTextEntry {
+	Common::Point position;
+	Graphics::Surface *surface;
+};
+
+class FontManager {
+private:
+	DragonsEngine *_vm;
+	Font *_fonts[3];
+	Screen *_screen;
+	Common::List<ScreenTextEntry*> _screenTexts;
+	byte *_palettes;
+
+public:
+	FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive);
+	~FontManager();
+	void addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 fontType);
+	void draw();
+	void clearText();
+private:
+	Font *loadFont(uint16 index, Common::SeekableReadStream &stream);
+	void loadPalettes();
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_FONT_H
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index c5b8f77b84..5bd86533f8 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -15,6 +15,7 @@ MODULE_OBJS := \
     dragonrms.o \
     dragonvar.o \
 	dragons.o \
+	font.o \
 	inventory.o \
 	saveload.o \
 	scene.o \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 297654be92..ec44be5156 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -26,6 +26,7 @@
 #include "cursor.h"
 #include "dragonini.h"
 #include "dragonimg.h"
+#include "font.h"
 #include "inventory.h"
 #include "screen.h"
 #include "actorresource.h"
@@ -328,7 +329,7 @@ void Scene::draw() {
 			}
 		}
 
-		for (uint16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
+		for (int16 i = DRAGONS_ENGINE_NUM_ACTORS - 1; i >= 0; i--) {
 			Actor *actor = _actorManager->getActor(i);
 			if (actor->x_pos == -100 && actor->y_pos == 100) {
 				actor->priorityLayer = 0;
@@ -359,6 +360,7 @@ void Scene::draw() {
 			}
 		}
 	}
+	_vm->_fontManager->draw();
 }
 
 int16 Scene::getPriorityAtPosition(Common::Point pos) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index bb7b8607ff..ac065c2fcc 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -796,13 +796,15 @@ void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 		}
 	}
 	// TODO sVar1 = findTextToDtSpeechIndex(textIndex);
-	char *dialog = _vm->_talk->loadText(textIndex);
+	uint16 dialog[2048];
+	dialog[0] = 0;
+	_vm->_talk->loadText(textIndex, dialog, 2048);
 
 //	pcVar2 = (char *)0x0;
 //	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
 //		pcVar2 = load_string_from_dragon_txt(textIndex,acStack2016);
 //	}
-	_vm->_talk->displayDialogAroundINI(iniId, NULL, textIndex); //TODO need to pass dialog here (pcVar2). not NULL
+	_vm->_talk->displayDialogAroundINI(iniId, dialog, textIndex); //TODO need to pass dialog here (pcVar2). not NULL
 	if (iniId == 0) {
 		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
 			if (_vm->getCurrentSceneId() != 0x32) {
@@ -864,11 +866,13 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 
 	//TODO implement actor talk.
 
-	char *dialog = NULL;
+	uint16 dialog[2048];
+	dialog[0] = 0;
+
 	int sVar2 = -1; //TODO FUN_8001ca48(textIndex);
 
 	if (!_vm->isUnkFlagSet(1) && (!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || sVar2 == -1)) {
-		dialog = _vm->_talk->loadText(textIndex);
+		_vm->_talk->loadText(textIndex, dialog, 2048);
 	}
 
 	ushort uVar1;
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 7e760c984f..e4c9d0f37f 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -31,6 +31,7 @@
 #include "dragonimg.h"
 #include "dragonobd.h"
 #include "scene.h"
+#include "font.h"
 
 namespace Dragons {
 
@@ -42,7 +43,7 @@ void Talk::init() {
 
 }
 
-char *Talk::loadText(uint32 textIndex) {
+void Talk::loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength) {
 	char filename[13] = "drag0000.txt";
 	uint32 fileNo = (textIndex >> 0xc) & 0xffff;
 	uint32 fileOffset = textIndex & 0xfff;
@@ -52,8 +53,9 @@ char *Talk::loadText(uint32 textIndex) {
 	byte *data = _bigfileArchive->load(filename, size);
 	debug("DIALOG: %s, %d", filename, fileOffset);
 	printWideText(data + 10 + fileOffset);
+
+	copyTextToBuffer(textBuffer, data + 10 + fileOffset, bufferLength);
 	delete data;
-	return NULL; //TODO fix me
 }
 
 void Talk::printWideText(byte *text) {
@@ -68,7 +70,7 @@ void Talk::printWideText(byte *text) {
 }
 
 void
-Talk::FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId,
+Talk::FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId,
 				   uint16 endSequenceId, uint32 textId) {
 	//TODO 0x800323a4
 
@@ -78,7 +80,7 @@ Talk::FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5
 
 	actor->updateSequence(startSequenceId);
 	_vm->_sound->playSpeech(textId);
-	conversation_related_maybe(NULL /*TODO &dialog[10]*/, (int)x, (int)y,param_4 & 0xffff, (uint)param_5, textId, uVar4 & 0xffff);
+	conversation_related_maybe(dialog, (int)x, (int)y,param_4 & 0xffff, (uint)param_5, textId, uVar4 & 0xffff);
 
 	actor->updateSequence(endSequenceId);
 }
@@ -87,7 +89,7 @@ void
 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
 								 int16 param_7) {
 	//TODO display dialog text here while we wait for audio stream to complete.
-
+	_vm->_fontManager->addText(x, y, dialogText, wideStrLen(dialogText), 0);
 	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
 		_vm->waitForFrames(1);
 	}
@@ -166,5 +168,25 @@ void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialog
 			 param_2,1,textIndex);
 }
 
+void Talk::copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength) {
+	for(int i = 0; i < destBufferLength - 1; i++) {
+		destBuffer[i] = READ_LE_UINT16(src);
+		src += 2;
+		if(destBuffer[i] == 0) {
+			return;
+		}
+	}
+
+	destBuffer[destBufferLength - 1] = 0;
+}
+
+uint32 Talk::wideStrLen(uint16 *text) {
+	int i = 0;
+	while(text[i] != 0) {
+		i++;
+	}
+	return i;
+}
+
 
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 4a6f8e1016..899747048b 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -38,17 +38,21 @@ private:
 public:
 	Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive);
 	void init();
-	char *loadText(uint32 textIndex);
+	void loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength);
 	void printWideText(byte *text);
 
 	uint32 displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex);
 	void displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId);
 	void displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex);
 
-	void FUN_8003239c(char *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId, uint16 endSequenceId, uint32 textId);
+	void FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId, uint16 endSequenceId, uint32 textId);
 
 	void conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId, int16 param_7);
 
+private:
+	void copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength);
+	uint32 wideStrLen(uint16 *text);
+
 };
 
 } // End of namespace Dragons


Commit: a1a2b53248e362db874cb130ddde5faacec32ee1
    https://github.com/scummvm/scummvm/commit/a1a2b53248e362db874cb130ddde5faacec32ee1
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on font handling

Changed paths:
    engines/dragons/font.cpp
    engines/dragons/font.h
    engines/dragons/talk.cpp


diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 29100f9371..d8b041b373 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -31,7 +31,7 @@
 
 namespace Dragons {
 
-Font::Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelSize) {
+Font::Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelOffset, uint32 pixelSize) {
 	_size = mapSize / 2;
 	_map = (uint16 *)malloc(mapSize);
 	if (!_map) {
@@ -46,8 +46,9 @@ Font::Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelSize)
 	if (!_pixels) {
 		error("Allocating memory for font pixels.");
 	}
-
+	stream.seek(pixelOffset);
 	stream.read(_pixels, pixelSize);
+	_numChars = pixelSize / 64;
 }
 
 Font::~Font() {
@@ -55,16 +56,12 @@ Font::~Font() {
 	free(_pixels);
 }
 
-void writePixelBlock(byte *pixels, byte *data, byte *palette) {
-	pixels[2] = palette[data[1] * 2];
-	pixels[3] = palette[data[1] * 2 + 1];
-	pixels[4] = palette[data[2] * 2];
-	pixels[5] = palette[data[2] * 2 + 1];
-	pixels[6] = palette[data[3] * 2];
-	pixels[7] = palette[data[3] * 2 + 1];
+uint16 mapChar(uint16 in) {
+	if (in >= 97) {
+		return in - 0x23;
+	}
+	return in - 0x20;
 }
-
-
 Graphics::Surface *Font::render(uint16 *text, uint16 length, byte *palette) {
 	Graphics::Surface *surface = new Graphics::Surface();
 	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
@@ -74,11 +71,12 @@ Graphics::Surface *Font::render(uint16 *text, uint16 length, byte *palette) {
 	for (int i = 0; i < length; i++) {
 		byte *pixels = (byte *)surface->getPixels();
 		pixels += i * 8 * 2;
-		byte *data = _pixels + i * 64; //(_map[text[i] + 5] ) * 64;
+		debug("char: %d size: %d %d", (text[i] - 0x20), _numChars, (30 + i));
+		byte *data = _pixels + mapChar(text[i]) * 64;
 		for (int y = 0; y < 8; y++) {
 			for (int x = 0; x < 8; x++) {
-				pixels[x * 2] = palette[(data[0]+2) * 2];
-				pixels[x * 2 + 1] = palette[(data[0]+2) * 2 + 1];
+				pixels[x * 2] = palette[(data[0]) * 2];
+				pixels[x * 2 + 1] = palette[(data[0]) * 2 + 1];
 				data++;
 			}
 			pixels += surface->pitch;
@@ -115,7 +113,7 @@ void FontManager::addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 f
 	byte *palette = _vm->_cursor->getPalette();
 	ScreenTextEntry *screenTextEntry = new ScreenTextEntry();
 	screenTextEntry->position = Common::Point(x, y);
-	screenTextEntry->surface = _fonts[fontType]->render(text, length, palette);
+	screenTextEntry->surface = _fonts[fontType]->render(text, length, _palettes); //palette);
 
 	_screenTexts.push_back(screenTextEntry);
 
@@ -157,27 +155,47 @@ Font *FontManager::loadFont(uint16 index, Common::SeekableReadStream &stream) {
 	fd.skip(4); //unk
 
 	fd.skip(16); //filename
-//	uint32 pixelsOffset = fd.readUint32LE();
+	uint32 pixelsOffset = fd.readUint32LE();
 	uint32 pixelsSize = fd.readUint32LE();
 
 	fd.close();
 
 	stream.seek(mapOffset);
-	return new Font(stream, mapSize, pixelsSize);
+	return new Font(stream, mapSize, pixelsOffset, pixelsSize);
 }
 
-void FontManager::loadPalettes() {
-	Common::File fd;
-	if (!fd.open("dragon.exe")) {
-		error("Failed to open dragon.exe");
-	}
-	fd.seek(0x5336c); //TODO handle other game variants
-
-	_palettes = (byte *)malloc(256 * 2 * 4);
-	fd.read(_palettes, 256 * 2 * 4);
+uint16 packColor(uint8 r, uint8 g, uint8 b) {
+	return (r / 8) << 10 | (g / 8) << 5 | (b / 8);
+}
 
-	_palettes[2 * 256 + 0x21] = 0x80; //HACK make this color transparent
-	fd.close();
+void FontManager::loadPalettes() {
+//	Common::File fd;
+//	if (!fd.open("dragon.exe")) {
+//		error("Failed to open dragon.exe");
+//	}
+//	fd.seek(0x5336c); //TODO handle other game variants
+//
+//	_palettes = (byte *)malloc(256 * 2 * 4);
+//	fd.read(_palettes, 256 * 2 * 4);
+//
+//	_palettes[2 * 256 + 0x21] = 0x80; //HACK make this color transparent
+//	fd.close();
+
+	//TODO where does original set its palette???
+	_palettes = (byte *)malloc(0x200);
+	memset(_palettes, 0, 0x200);
+	WRITE_LE_INT16(&_palettes[0], 0x8000);
+
+//	WRITE_LE_INT16(&_palettes[0x11 * 2], packColor(95, 95, 95));
+	WRITE_LE_INT16(&_palettes[0x10 * 2], packColor(0, 0, 0) | 0x8000);
+	WRITE_LE_INT16(&_palettes[0x11 * 2], packColor(254, 255, 0));
+	WRITE_LE_INT16(&_palettes[0x12 * 2], packColor(95, 95, 95));
+	WRITE_LE_INT16(&_palettes[0x13 * 2], packColor(175, 175, 175));
+
+	WRITE_LE_INT16(&_palettes[0x20 * 2], packColor(0, 0, 0) | 0x8000);
+	WRITE_LE_INT16(&_palettes[0x21 * 2], packColor(254, 255, 0));
+	WRITE_LE_INT16(&_palettes[0x22 * 2], packColor(95, 95, 95));
+	WRITE_LE_INT16(&_palettes[0x23 * 2], packColor(175, 175, 175));
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index ae78a59335..98701f027f 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -38,8 +38,9 @@ private:
 	uint32 _size;
 	uint16 *_map;
 	byte *_pixels;
+	uint32 _numChars;
 public:
-	Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelSize);
+	Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelOffset, uint32 pixelSize);
 	~Font();
 	Graphics::Surface *render(uint16 *text, uint16 length, byte *palette);
 };
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index e4c9d0f37f..600d81dff1 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -158,7 +158,7 @@ Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 pa
 //		if (dialogText == (uint16_t *)0x0) {
 //			dialogText = (uint16_t *)local_58;
 //		}
-		conversation_related_maybe(dialogText + 5,x,y,param_4,param_5,textId,0); // sVar3); TODO I think this is audio status
+		conversation_related_maybe(dialogText,x,y,param_4,param_5,textId,0); // sVar3); TODO I think this is audio status
 }
 
 void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex) {


Commit: f4b4156b513c59181591dc5226c2ad8c97601a17
    https://github.com/scummvm/scummvm/commit/f4b4156b513c59181591dc5226c2ad8c97601a17
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on talk dialog logic

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 786e2dbb1a..8c9ad434c5 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1021,7 +1021,7 @@ void DragonsEngine::works_with_obd_data_1() {
 		if (_cursor->data_800728b0_cursor_seqID == 3) {
 			local_58._code = pvVar7;
 			local_58._codeEnd = pvVar8;
-			uVar5 = _scriptOpcodes->FUN_800297d8(local_58);
+			uVar5 = _talk->talkToActor(local_58);
 			uVar4 = uVar4 | uVar5;
 		}
 		if (((uVar4 & 0xffff) == 0) && ((uVar6 & 0xfffd) == 0)) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index ac065c2fcc..5f1d07497d 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -93,7 +93,7 @@ void ScriptOpcodes::initOpcodes() {
 	// Register opcodes
 	OPCODE(1, opUnk1);
 	OPCODE(2, opUnk2); //dialog related
-
+	OPCODE(3, opUnk3); //dialog related
 	OPCODE(4,  opExecuteScript);
 	OPCODE(5,  opActorSetSequenceID2);
 	OPCODE(6,  opUnk6);
@@ -112,7 +112,6 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x13, opUnk13PropertiesRelated);
 	OPCODE(0x14, opUnk14PropertiesRelated);
 	OPCODE(0x15, opUnk15PropertiesRelated);
-
 	OPCODE(0x16, opUnk16);
 	OPCODE(0x17, opUnk17);
 	OPCODE(0x18, opUnk18);
@@ -209,10 +208,6 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-int16 ScriptOpcodes::FUN_800297d8(ScriptOpCall &scriptOpCall) {
-	error("FUN_800297d8"); //TODO
-}
-
 // Opcodes
 
 void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
@@ -233,20 +228,41 @@ void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
 
 void ScriptOpcodes::opUnk2(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
-	ARG_INT16(field2);
-	ARG_INT16(field4);
-	ARG_INT16(field6);
-	ARG_INT16(field8);
+	ARG_UINT32(field2);
+	ARG_UINT32(field6);
 	ARG_INT16(fieldA);
 	ARG_INT16(fieldC);
 	ARG_INT16(fieldE);
 
 	if (scriptOpCall._field8 == 2) {
 		//TODO do something here.
+		TalkDialogEntry *talkDialogEntry = new TalkDialogEntry();
+
+		_vm->_talk->loadText(field2, (uint16 *)(&talkDialogEntry->dialogText[10]), 295);
+
+		talkDialogEntry->textIndex = field2;
+		talkDialogEntry->textIndex1 = field6;
+		talkDialogEntry->scriptCodeStartPtr = scriptOpCall._code;
+		talkDialogEntry->flags = 0;
+		talkDialogEntry->scriptCodeEndPtr = scriptOpCall._code + fieldA;
+		if ((field0 & 0x8000U) != 0) {
+			talkDialogEntry->flags = 2;
+		}
+		talkDialogEntry->field_26c = fieldC;
+		talkDialogEntry->iniId = fieldE;
+		_vm->_talk->addTalkDialogEntry(talkDialogEntry);
 	}
 	scriptOpCall._code += fieldA;
 }
 
+void ScriptOpcodes::opUnk3(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	if (scriptOpCall._field8 == 0) {
+		_data_80071f5c = field2;
+	}
+}
+
 void ScriptOpcodes::opExecuteScript(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_UINT32(obdOffset);
@@ -1066,17 +1082,27 @@ void ScriptOpcodes::opUnk17(ScriptOpCall &scriptOpCall) {
 
 void ScriptOpcodes::opUnk18(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
-	ARG_INT16(field2);
-	ARG_INT16(field4);
-	ARG_INT16(field6);
-	ARG_INT16(field8);
+	ARG_UINT32(field2);
+	ARG_INT16(x);
+	ARG_INT16(y);
 	ARG_INT16(fieldA);
 
 	if (scriptOpCall._field8 != 0) {
 		return;
 	}
-	//TODO implement me!
-	error("opUnk18");
+
+	uint16 dialog[2000];
+	dialog[0] = 0;
+	_vm->_talk->loadText(field2, dialog, 2000);
+
+//	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
+//		dialogText = (uint8_t *)load_string_from_dragon_txt(offset,acStack2016);
+//	}
+
+	if (fieldA != 0) {
+		fieldA = READ_LE_INT16(_vm->_dragonOBD->getFromOpt(fieldA - 1) + 6);
+	}
+	_vm->_talk->displayDialogAroundPoint(dialog,x,y,fieldA,1,field2);
 }
 
 void ScriptOpcodes::opUnk1B(ScriptOpCall &scriptOpCall) {
@@ -1209,4 +1235,12 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 	ini->sceneId = sceneId;
 }
 
+void ScriptOpcodes::loadTalkDialogEntries(ScriptOpCall &scriptOpCall) {
+	scriptOpCall._field8 = 2;
+	scriptOpCall._result = 0;
+	_data_80071f5c = 0;
+	executeScriptLoop(scriptOpCall);
+
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 2b89dffac9..8681fd1044 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -65,7 +65,8 @@ public:
 	bool runScript4(ScriptOpCall &scriptOpCall);
 	void execOpcode(ScriptOpCall &scriptOpCall);
 	void executeScriptLoop(ScriptOpCall &scriptOpCall);
-	int16 FUN_800297d8(ScriptOpCall &scriptOpCall);
+	void loadTalkDialogEntries(ScriptOpCall &scriptOpCall);
+
 	int16 _data_80071f5c;
 	int16 _data_800728c0;
 protected:
@@ -83,6 +84,7 @@ protected:
 	// Opcodes
 	void opUnk1(ScriptOpCall &scriptOpCall);
 	void opUnk2(ScriptOpCall &scriptOpCall);
+	void opUnk3(ScriptOpCall &scriptOpCall);
 	void opExecuteScript(ScriptOpCall &scriptOpCall); //op 4
 	void opActorSetSequenceID2(ScriptOpCall &scriptOpCall); //op 5
 	void opUnk6(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 600d81dff1..e34d7cd77b 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -23,6 +23,7 @@
 #include <common/debug.h>
 #include "bigfile.h"
 #include "actor.h"
+#include "cursor.h"
 #include "actorresource.h"
 #include "talk.h"
 #include "sound.h"
@@ -32,6 +33,7 @@
 #include "dragonobd.h"
 #include "scene.h"
 #include "font.h"
+#include "scriptopcodes.h"
 
 namespace Dragons {
 
@@ -51,7 +53,7 @@ void Talk::loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength) {
 	sprintf(filename, "drag%04d.txt", fileNo);
 	uint32 size;
 	byte *data = _bigfileArchive->load(filename, size);
-	debug("DIALOG: %s, %d", filename, fileOffset);
+	debug("DIALOG: %s, %s, %d", filename, data, fileOffset);
 	printWideText(data + 10 + fileOffset);
 
 	copyTextToBuffer(textBuffer, data + 10 + fileOffset, bufferLength);
@@ -93,6 +95,7 @@ Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16
 	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
 		_vm->waitForFrames(1);
 	}
+	_vm->_fontManager->clearText();
 }
 
 
@@ -188,5 +191,129 @@ uint32 Talk::wideStrLen(uint16 *text) {
 	return i;
 }
 
+void Talk::addTalkDialogEntry(TalkDialogEntry *talkDialogEntry) {
+	_dialogEntries.push_back(talkDialogEntry);
+}
+
+void callMaybeResetData() {
+	//TODO do we need this?
+}
+
+bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
+	uint16 numEntries;
+
+	uint16_t sequenceId;
+	TalkDialogEntry *selectedDialogText;
+	uint iniId;
+	ScriptOpCall local_1d20;
+	short local_990 [5];
+	byte auStack2438 [390];
+	short local_800 [1000];
+
+	bool isFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
+	bool isFlag100Set = _vm->isFlagSet(ENGINE_FLAG_100);
+
+	_vm->clearFlags(ENGINE_FLAG_8);
+	Actor *flickerActor = _vm->_dragonINIResource->getFlickerRecord()->actor;
+
+	//TODO clear entries;
+	_vm->_scriptOpcodes->loadTalkDialogEntries(scriptOpCall);
+	numEntries = _dialogEntries.size();
+	if (numEntries == 0) {
+		return 0;
+	}
+	_vm->setFlags(ENGINE_FLAG_100);
+	do {
+		callMaybeResetData();
+		int numActiveDialogEntries = 0;
+		for (Common::List<TalkDialogEntry*>::iterator it = _dialogEntries.begin(); it != _dialogEntries.end(); it++) {
+			if (!(*it)->flags & 1) {
+				numActiveDialogEntries++;
+			}
+		}
+		if (numActiveDialogEntries == 0) {
+			//TODO logic from LAB_80029bc0 reset cursor
+			exitTalkMenu(isFlag8Set, isFlag100Set);
+			return 1;
+		}
+
+		selectedDialogText = displayTalkDialogMenu();
+		if (selectedDialogText == NULL) {
+			callMaybeResetData();
+			exitTalkMenu(isFlag8Set, isFlag100Set);
+			return 1;
+		}
+		_vm->clearFlags(ENGINE_FLAG_8);
+		strcpy((char *)local_990,selectedDialogText->dialogText);
+//		UTF16ToUTF16Z(auStack2438,selectedDialogText->dialogText + 10);
+//		load_string_from_dragon_txt(selectedDialogText->textIndex1,(char *)local_800);
+//		if (local_990[0] != 0) {
+//			flickerActor->setFlag(ACTOR_FLAG_2000);
+//			sequenceId = flickerActor->_sequenceID;
+//			playSoundFromTxtIndex(selectedDialogText->textIndex);
+//			if (flickerActor->_sequenceID2 != -1) {
+//				flickerActor->updateSequence(flickerActor->_sequenceID2 + 0x10);
+//			}
+//			displayDialogAroundINI(0,(uint8_t *)local_990,selectedDialogText->textIndex);
+//			flickerActor->updateSequence(sequenceId);
+//			flickerActor->clearFlag(ACTOR_FLAG_2000);
+//		}
+		if ((selectedDialogText->flags & 2) == 0) {
+			selectedDialogText->flags = selectedDialogText->flags | 1;
+		}
+		callMaybeResetData();
+		if (local_800[0] != 0) {
+			if (selectedDialogText->field_26c == -1) {
+//				displayDialogAroundINI
+//						((uint)dragon_ini_index_under_active_cursor,(uint8_t *)local_800,
+//						 selectedDialogText->textIndex1);
+			}
+			else {
+				iniId = _vm->_cursor->_iniUnderCursor; //dragon_ini_index_under_active_cursor;
+				if (selectedDialogText->iniId != 0) {
+					iniId = selectedDialogText->iniId;
+				}
+				Actor *iniActor = _vm->_dragonINIResource->getRecord(iniId - 1)->actor;
+				sequenceId = iniActor->_sequenceID;
+//				playSoundFromTxtIndex(selectedDialogText->textIndex1);
+//				iniActor->updateSequence(selectedDialogText->field_26c);
+//				displayDialogAroundINI(iniId,(uint8_t *)local_800,selectedDialogText->textIndex1);
+//				iniActor->updateSequence(sequenceId);
+			}
+		}
+		local_1d20._code = selectedDialogText->scriptCodeStartPtr;
+		local_1d20._codeEnd = selectedDialogText->scriptCodeEndPtr;
+		_vm->_scriptOpcodes->runScript(local_1d20);
+		if (_vm->_scriptOpcodes->_data_80071f5c != 0) break;
+		local_1d20._code = selectedDialogText->scriptCodeStartPtr;
+		local_1d20._codeEnd = selectedDialogText->scriptCodeEndPtr;
+		talkToActor(local_1d20);
+
+	} while (_vm->_scriptOpcodes->_data_80071f5c == 0);
+	_vm->_scriptOpcodes->_data_80071f5c--;
+//	LAB_80029bc0:
+//	actors[0].x_pos = cursor_x_var;
+//	actors[0].y_pos = cursor_y_var;
+	exitTalkMenu(isFlag8Set, isFlag100Set);
+	return 1;
+}
+
+TalkDialogEntry *Talk::displayTalkDialogMenu() {
+	return *_dialogEntries.begin();
+}
+
+void Talk::exitTalkMenu(bool isFlag8Set, bool isFlag100Set) {
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_100);
+
+	if (isFlag8Set) {
+		_vm->setFlags(ENGINE_FLAG_8);
+	}
+	if (isFlag100Set) {
+		_vm->setFlags(ENGINE_FLAG_100);
+	}
+
+}
+
 
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 899747048b..6ff298f2a0 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -24,6 +24,7 @@
 #define DRAGONS_TALK_H
 
 #include <common/str.h>
+#include "scriptopcodes.h"
 
 namespace Dragons {
 
@@ -31,10 +32,26 @@ class BigfileArchive;
 class Actor;
 class DragonsEngine;
 
+struct TalkDialogEntry {
+	char dialogText[600];
+	uint32 textIndex;
+	uint32 textIndex1;
+	byte *scriptCodeStartPtr;
+	byte *scriptCodeEndPtr;
+	uint16 flags;
+	uint8 xPosMaybe;
+	uint8 yPosMaybe;
+	int16 field_26c;
+	uint16 iniId;
+};
+
+
 class Talk {
 private:
 	DragonsEngine *_vm;
 	BigfileArchive *_bigfileArchive;
+	Common::List<TalkDialogEntry*> _dialogEntries;
+
 public:
 	Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive);
 	void init();
@@ -49,10 +66,15 @@ public:
 
 	void conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId, int16 param_7);
 
+	void addTalkDialogEntry(TalkDialogEntry *talkDialogEntry);
+
+	bool talkToActor(ScriptOpCall &scriptOpCall);
+
 private:
 	void copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength);
 	uint32 wideStrLen(uint16 *text);
-
+	TalkDialogEntry *displayTalkDialogMenu();
+	void exitTalkMenu(bool isFlag8Set, bool isFlag100Set);
 };
 
 } // End of namespace Dragons


Commit: 118fa61835e2088fd73a8154cfbe1f56e00aaaab
    https://github.com/scummvm/scummvm/commit/118fa61835e2088fd73a8154cfbe1f56e00aaaab
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Pizza maker logic

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 8c9ad434c5..dd997ab245 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -69,6 +69,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_talk = NULL;
 	_sound = new Sound(this);
 	_fontManager = NULL;
+	_sceneUpdateFunction = NULL;
 
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
@@ -203,6 +204,7 @@ void DragonsEngine::gameLoop()
 		wait();
 		updateHandler();
 		updateEvents();
+		runSceneUpdaterFunction(); //TODO is this the right place for this logic?
 
 		if (getCurrentSceneId() != 2) {
 			_sceneId1 = getCurrentSceneId();
@@ -934,6 +936,7 @@ void DragonsEngine::waitForFrames(uint16 numFrames) {
 
 		_scene->draw();
 		_screen->updateScreen();
+		runSceneUpdaterFunction();
 		updateEvents();
 	}
 }
@@ -1226,4 +1229,19 @@ void DragonsEngine::reset() {
 
 }
 
+void DragonsEngine::runSceneUpdaterFunction() {
+	if ((isFlagSet(ENGINE_FLAG_20) && (run_func_ptr_unk_countdown_timer == 0)) &&
+		(run_func_ptr_unk_countdown_timer = 1, _sceneUpdateFunction != NULL)) {
+		_sceneUpdateFunction();
+	}
+}
+
+void DragonsEngine::setSceneUpdateFunction(void (*newUpdateFunction)()) {
+	_sceneUpdateFunction = newUpdateFunction;
+}
+
+//void  (*DragonsEngine::getSceneUpdateFunction())() {
+//	return _sceneUpdateFunction ;
+//}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 8ac860290a..72c574e35a 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -24,6 +24,7 @@
 
 #include "gui/EventRecorder.h"
 #include "engines/engine.h"
+#include "specialopcodes.h"
 
 namespace Dragons {
 
@@ -165,6 +166,7 @@ private:
 	bool _leftMouseButtonUp;
 	bool _rightMouseButtonUp;
 	bool _iKeyUp;
+	void (*_sceneUpdateFunction)();
 protected:
 	virtual bool hasFeature(EngineFeature f) const;
 public:
@@ -215,6 +217,9 @@ public:
 
 	void reset();
 
+	void runSceneUpdaterFunction();
+	void setSceneUpdateFunction(void (*newUpdateFunction)());
+
 private:
 	bool savegame(const char *filename, const char *description);
 	bool loadgame(const char *filename);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 07b2820742..9484b5d8bb 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -25,6 +25,7 @@
 #include "dragons/dragonflg.h"
 #include "dragons/dragonini.h"
 #include "dragons/dragonobd.h"
+#include "dragons/inventory.h"
 #include "dragons/specialopcodes.h"
 #include "dragons/scene.h"
 #include "dragons/actor.h"
@@ -74,18 +75,33 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x14, spcClearEngineFlag8);
 	OPCODE(0x15, spcSetEngineFlag8);
 
+	OPCODE(0x1a, spcActivatePizzaMakerActor);
+	OPCODE(0x1b, spcDeactivatePizzaMakerActor);
+	OPCODE(0x1c, spcPizzaMakerActorStopWorking);
+
+	OPCODE(0x36, spcFlickerClearFlag0x80);
+
+	OPCODE(0x3b, spcSetEngineFlag0x2000000);
+	OPCODE(0x3c, spcClearEngineFlag0x2000000);
+
 	OPCODE(0x49, spcLoadScene1);
 
 	OPCODE(0x4e, spcUnk4e);
 	OPCODE(0x4f, spcUnk4f);
+	OPCODE(0x50, spcCloseInventory);
 
 	OPCODE(0x53, spcClearEngineFlag0x4000000);
 	OPCODE(0x54, spcSetEngineFlag0x4000000);
 	OPCODE(0x55, spcSetCursorSequenceIdToZero);
 
+	OPCODE(0x5b, spcFlickerSetFlag0x80);
+
 	OPCODE(0x5e, spcUnk5e);
 	OPCODE(0x5f, spcUnk5f);
 
+	OPCODE(0x6b, spcTransitionToMap);
+	OPCODE(0x6c, spcTransitionFromMap);
+
 	OPCODE(0x7b, spcSetCameraXToZero);
 
 }
@@ -138,6 +154,30 @@ void SpecialOpcodes::spcSetEngineFlag8() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_8);
 }
 
+void SpecialOpcodes::spcActivatePizzaMakerActor() {
+	_vm->setSceneUpdateFunction(pizzaUpdateFunction);
+}
+
+void SpecialOpcodes::spcDeactivatePizzaMakerActor() {
+	_vm->setSceneUpdateFunction(NULL); //TODO only remove if currently running
+}
+
+void SpecialOpcodes::spcPizzaMakerActorStopWorking() {
+	_vm->setSceneUpdateFunction(NULL); //TODO only remove if currently running
+	pizzaMakerStopWorking();
+}
+
+void SpecialOpcodes::spcFlickerClearFlag0x80() {
+	_vm->_dragonINIResource->getFlickerRecord()->actor->clearFlag(ACTOR_FLAG_80);
+}
+
+void SpecialOpcodes::spcSetEngineFlag0x2000000() {
+	_vm->setFlags(Dragons::ENGINE_FLAG_2000000);
+}
+
+void SpecialOpcodes::spcClearEngineFlag0x2000000() {
+	_vm->clearFlags(Dragons::ENGINE_FLAG_2000000);
+}
 
 void SpecialOpcodes::spcUnk4e() {
 	panCamera(1);
@@ -147,6 +187,13 @@ void SpecialOpcodes::spcUnk4f() {
 	panCamera(2);
 }
 
+void SpecialOpcodes::spcCloseInventory() {
+	if (_vm->_inventory->getType() == 1) {
+		_vm->_inventory->closeInventory();
+		_vm->_inventory->setType(0);
+	}
+}
+
 void SpecialOpcodes::spcSetEngineFlag0x4000000() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
 }
@@ -159,6 +206,10 @@ void SpecialOpcodes::spcSetCursorSequenceIdToZero() {
 	_vm->_cursor->_sequenceID = 0;
 }
 
+void SpecialOpcodes::spcFlickerSetFlag0x80() {
+	_vm->_dragonINIResource->getFlickerRecord()->actor->setFlag(ACTOR_FLAG_80);
+}
+
 void SpecialOpcodes::spcUnk5e() {
 	panCamera(1);
 	_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(0));
@@ -210,4 +261,103 @@ void SpecialOpcodes::spcLoadScene1() {
 	// TODO spcLoadScene1 knights around the table.
 }
 
+void SpecialOpcodes::spcTransitionToMap() {
+	//TODO map transition
+//	DAT_8006a422 = 0;
+//	DAT_8006a424 = 0;
+//	cursorSequenceId = 0;
+//	ContinueGame?();
+//	engine_flags_maybe = engine_flags_maybe | 0x20000000;
+//	FUN_80023b34(0,0,1);
+}
+
+void SpecialOpcodes::spcTransitionFromMap() {
+	//TODO map transition
+}
+
+void SpecialOpcodes::pizzaMakerStopWorking() {
+	Actor *actorf4 = _vm->getINI(0xf4)->actor;
+	Actor *actorf5 = _vm->getINI(0xf5)->actor;
+
+	if (actorf4->_sequenceID != 0) {
+		if (actorf4->_sequenceID == 1) {
+			actorf4->waitUntilFlag8And4AreSet();
+			actorf4->updateSequence(2);
+			actorf5->x_pos = 0x115;
+			actorf5->y_pos = 0x5c;
+			actorf5->updateSequence(7);
+			_vm->waitForFrames(0x78);
+			actorf5->updateSequence(8);
+			actorf5->waitUntilFlag8And4AreSet();
+			actorf5->x_pos = 0xff9c;
+			actorf5->y_pos = 100;
+			actorf4->updateSequence(3);
+		}
+		else {
+			if (actorf4->_sequenceID == 2) {
+				_vm->waitForFrames(0x78);
+				actorf5->updateSequence(8);
+				actorf5->waitUntilFlag8And4AreSet();
+				actorf5->x_pos = 0xff9c;
+				actorf5->y_pos = 100;
+				actorf4->updateSequence(3);
+			}
+			else {
+				if (actorf4->_sequenceID != 3) {
+					return;
+				}
+			}
+		}
+		actorf4->waitUntilFlag8And4AreSet();
+		actorf4->updateSequence(0);
+	}
+}
+
+void pizzaUpdateFunction() {
+		static int16 DAT_800634bc = 0;
+		DragonsEngine *vm = getEngine();
+
+		Actor *actorf4 = vm->getINI(0xf4)->actor;
+		Actor *actorf5 = vm->getINI(0xf5)->actor;
+
+		if (DAT_800634bc == 0) {
+			if (actorf4->isFlagSet(ACTOR_FLAG_4)) {
+				if (actorf4->_sequenceID == 0) {
+					actorf4->updateSequence(1);
+				} else {
+					if (actorf4->_sequenceID == 1) {
+						actorf4->updateSequence(2);
+						actorf5->x_pos = 0x115;
+						actorf5->y_pos = 0x5c;
+						actorf5->updateSequence(7);
+						DAT_800634bc = 0x2d;
+						return;
+					}
+					if (actorf4->_sequenceID == 2) {
+						if ((actorf5->_sequenceID == 8) &&
+							(actorf5->isFlagSet(ACTOR_FLAG_4))) {
+							actorf5->x_pos = -100;
+							actorf5->y_pos = 100;
+							actorf4->updateSequence(3);
+						} else {
+							if (actorf5->_sequenceID == 8) {
+								return;
+							}
+							actorf5->updateSequence(8);
+						}
+					} else {
+						if (actorf4->_sequenceID != 3) {
+							return;
+						}
+						actorf4->updateSequence(0);
+					}
+				}
+			}
+		}
+		else {
+			DAT_800634bc--;
+		}
+		return;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index d3eb49382d..4e39bae61c 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -60,21 +60,42 @@ protected:
 	void spcClearEngineFlag8(); // 0x14
 	void spcSetEngineFlag8(); // 0x15
 
+	void spcActivatePizzaMakerActor(); // 0x1a
+	void spcDeactivatePizzaMakerActor(); // 0x1b
+	void spcPizzaMakerActorStopWorking(); // 0x1c
+
+	void spcFlickerClearFlag0x80(); //0x36
+
+	void spcSetEngineFlag0x2000000(); // 0x3b
+	void spcClearEngineFlag0x2000000(); // 0x3c
+
 	void spcLoadScene1(); // 0x49
 	void spcUnk4e();
 	void spcUnk4f();
+	void spcCloseInventory(); // 0x50
 
 	void spcClearEngineFlag0x4000000(); // 0x53
 	void spcSetEngineFlag0x4000000(); // 0x54
 	void spcSetCursorSequenceIdToZero(); // 0x55
+
+	void spcFlickerSetFlag0x80();
+
 	void spcUnk5e();
 	void spcUnk5f();
 
+	void spcTransitionToMap(); // 0x6b
+	void spcTransitionFromMap(); // 0x6c
+
 	void spcSetCameraXToZero(); //0x7b
 private:
 	void panCamera(int16 mode);
+	void pizzaMakerStopWorking();
 };
 
+// update functions
+
+void pizzaUpdateFunction();
+
 } // End of namespace Dragons
 
 #endif // DRAGONS_SPECIALOPCODES_H


Commit: a77889f85adb6bdf9d822ceb7338a08e16ce7a1f
    https://github.com/scummvm/scummvm/commit/a77889f85adb6bdf9d822ceb7338a08e16ce7a1f
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More script/special opcodes

Changed paths:
    engines/dragons/dragons.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 72c574e35a..38af010a3a 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -71,6 +71,7 @@ enum Flags {
 	ENGINE_FLAG_8000     =     0x8000, // speech dialog is playing.
 
 	ENGINE_FLAG_10000    =    0x10000,
+	ENGINE_FLAG_20000    =    0x20000,
 	ENGINE_FLAG_80000    =    0x80000,
 	ENGINE_FLAG_100000   =   0x100000,
 	ENGINE_FLAG_200000   =   0x200000,
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 5f1d07497d..08ece050c9 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -116,6 +116,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x17, opUnk17);
 	OPCODE(0x18, opUnk18);
 
+	OPCODE(0x1A, opUnk1A);
 	OPCODE(0x1B, opUnk1B);
 	OPCODE(0x1C, opSetActorFlag0x1000);
 
@@ -1029,6 +1030,8 @@ uint16 ScriptOpcodes::getINIField(uint32 iniIndex, uint16 fieldOffset) {
 		case 4 : return ini->actorResourceId;
 		case 6 : return ini->sequenceId;
 		case 0xC  : return ini->sceneId;
+		case 0xE  : return ini->field_e;
+		case 0x10 : return ini->field_10;
 		case 0x12  : return ini->field_12;
 		case 0x14 : return ini->field_14;
 		case 0x16 : return ini->x;
@@ -1046,7 +1049,9 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 		case 0 : ini->iptIndex_maybe = value; break;
 		case 4 : ini->actorResourceId = value; break;
 		case 6 : ini->sequenceId = value; break;
-		case 0xc  : ini->sceneId = value; break;
+		case 0xc : ini->sceneId = value; break;
+		case 0xe : ini->field_e = value; break;
+		case 0x10 : ini->field_10 = value; break;
 		case 0x12 : ini->field_12 = value; break;
 		case 0x14 : ini->field_14 = value; break;
 		case 0x16 : ini->x = value; break;
@@ -1105,6 +1110,27 @@ void ScriptOpcodes::opUnk18(ScriptOpCall &scriptOpCall) {
 	_vm->_talk->displayDialogAroundPoint(dialog,x,y,fieldA,1,field2);
 }
 
+void ScriptOpcodes::opUnk1A(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(index);
+	ARG_INT16(field4);
+	ARG_INT16(field6);
+	ARG_INT16(field8);
+	ARG_INT16(fieldA);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	assert(index < 8);
+
+	_vm->opCode1A_tbl[index].field0 = field4;
+	_vm->opCode1A_tbl[index].field2 = field6;
+	_vm->opCode1A_tbl[index].field4 = field8;
+	_vm->opCode1A_tbl[index].field6 = fieldA;
+	_vm->opCode1A_tbl[index].field8 = 0;
+}
+
 void ScriptOpcodes::opUnk1B(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(iniId);
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 8681fd1044..edffa86604 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -106,6 +106,7 @@ protected:
 	void opUnk16(ScriptOpCall &scriptOpCall);
 	void opUnk17(ScriptOpCall &scriptOpCall);
 	void opUnk18(ScriptOpCall &scriptOpCall);
+	void opUnk1A(ScriptOpCall &scriptOpCall);
 	void opUnk1B(ScriptOpCall &scriptOpCall);
 	void opSetActorFlag0x1000(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 9484b5d8bb..11f9af7f30 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -79,6 +79,11 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x1b, spcDeactivatePizzaMakerActor);
 	OPCODE(0x1c, spcPizzaMakerActorStopWorking);
 
+	OPCODE(0x21, spcSetEngineFlag0x20000);
+	OPCODE(0x22, spcClearEngineFlag0x20000);
+	OPCODE(0x23, spcSetEngineFlag0x200000);
+	OPCODE(0x24, spcClearEngineFlag0x200000);
+
 	OPCODE(0x36, spcFlickerClearFlag0x80);
 
 	OPCODE(0x3b, spcSetEngineFlag0x2000000);
@@ -89,7 +94,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x4e, spcUnk4e);
 	OPCODE(0x4f, spcUnk4f);
 	OPCODE(0x50, spcCloseInventory);
-
+	OPCODE(0x51, spcOpenInventionBook);
+	OPCODE(0x52, spcCloseInventionBook);
 	OPCODE(0x53, spcClearEngineFlag0x4000000);
 	OPCODE(0x54, spcSetEngineFlag0x4000000);
 	OPCODE(0x55, spcSetCursorSequenceIdToZero);
@@ -167,6 +173,22 @@ void SpecialOpcodes::spcPizzaMakerActorStopWorking() {
 	pizzaMakerStopWorking();
 }
 
+void SpecialOpcodes::spcSetEngineFlag0x20000() {
+	_vm->setFlags(ENGINE_FLAG_20000);
+}
+
+void SpecialOpcodes::spcClearEngineFlag0x20000() {
+	_vm->clearFlags(ENGINE_FLAG_20000);
+}
+
+void SpecialOpcodes::spcSetEngineFlag0x200000() {
+	_vm->setFlags(ENGINE_FLAG_200000);
+}
+
+void SpecialOpcodes::spcClearEngineFlag0x200000() {
+	_vm->clearFlags(ENGINE_FLAG_200000);
+}
+
 void SpecialOpcodes::spcFlickerClearFlag0x80() {
 	_vm->_dragonINIResource->getFlickerRecord()->actor->clearFlag(ACTOR_FLAG_80);
 }
@@ -194,6 +216,37 @@ void SpecialOpcodes::spcCloseInventory() {
 	}
 }
 
+void SpecialOpcodes::spcOpenInventionBook() {
+	if (_vm->_inventory->getType() == 1) {
+		_vm->_inventory->closeInventory();
+	}
+	error("spcOpenInventionBook"); //TODO
+	DragonINI *pDVar1;
+
+//	DAT_80086f3c = func_ptr_unk;
+//	func_ptr_unk = 0;
+//	fade_related_calls_with_1f();
+//	inventorySequenceId = 2;
+//	actor_update_sequenceID(1,2);
+//	DAT_80083078 = currentSceneId;
+//	if (dragon_ini_maybe_flicker_control != 0xffff) {
+//		pDVar1 = dragon_ini_pointer + (uint)dragon_ini_maybe_flicker_control;
+//		DAT_800864a8 = actors[(uint)pDVar1->actorId].x_pos;
+//		DAT_80086424 = pDVar1->sceneId_maybe;
+//		DAT_800864ac = actors[(uint)pDVar1->actorId].y_pos;
+//		pDVar1->sceneId_maybe = 0;
+//	}
+//	currentSceneId = const_value_2;
+//	load_scene_maybe((uint)const_value_2,0);
+
+	_vm->_inventory->setType(2);
+}
+
+void SpecialOpcodes::spcCloseInventionBook() {
+	error("spcCloseInventionBook");
+	_vm->_inventory->setType(0);
+}
+
 void SpecialOpcodes::spcSetEngineFlag0x4000000() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 4e39bae61c..6472984824 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -64,15 +64,23 @@ protected:
 	void spcDeactivatePizzaMakerActor(); // 0x1b
 	void spcPizzaMakerActorStopWorking(); // 0x1c
 
+	void spcSetEngineFlag0x20000(); // 0x21
+	void spcClearEngineFlag0x20000(); // 0x22
+	void spcSetEngineFlag0x200000(); // 0x23
+	void spcClearEngineFlag0x200000(); // 0x24
+
 	void spcFlickerClearFlag0x80(); //0x36
 
 	void spcSetEngineFlag0x2000000(); // 0x3b
 	void spcClearEngineFlag0x2000000(); // 0x3c
 
 	void spcLoadScene1(); // 0x49
+
 	void spcUnk4e();
 	void spcUnk4f();
 	void spcCloseInventory(); // 0x50
+	void spcOpenInventionBook(); // 0x51
+	void spcCloseInventionBook(); // 0x52
 
 	void spcClearEngineFlag0x4000000(); // 0x53
 	void spcSetEngineFlag0x4000000(); // 0x54


Commit: 8286a6de7afd3f9bd1e343ba0ffc44f062392d35
    https://github.com/scummvm/scummvm/commit/8286a6de7afd3f9bd1e343ba0ffc44f062392d35
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed bug with missing inventory items when loading from save game.

Changed paths:
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonflg.h
    engines/dragons/saveload.cpp


diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index 2137a77c44..7a0536dd2c 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
+#include <common/debug.h>
 #include "dragonflg.h"
 #include "bigfile.h"
 
@@ -85,6 +86,18 @@ void Properties::save(uint numberToWrite, Common::WriteStream *out) {
 	out->write(_properties, numberToWrite / 8);
 }
 
+void Properties::print(char *prefix) {
+	char *str = new char[_count + 1];
+	int i = 0;
+	for(; i < _count; i++) {
+		str[i] = get(i) ? '1' : '0';
+	}
+	str[i] = 0;
+	debug("%s: props = %s", prefix, str);
+
+	delete str;
+}
+
 DragonFLG::DragonFLG(BigfileArchive *bigfileArchive) {
 	_data = bigfileArchive->load("dragon.flg", _dataSize);
 	properties = new Properties(288);
@@ -104,6 +117,7 @@ void DragonFLG::set(uint32 propertyId, bool value) {
 }
 
 void DragonFLG::saveState(Common::WriteStream *out) {
+	//properties->print("save");
 	properties->save(128, out); // save first 80 flags.
 }
 
@@ -114,6 +128,7 @@ void DragonFLG::loadState(Common::ReadStream *in) {
 
 	in->read(savedState, 0x10);
 	properties->init(0x10, savedState);
+	//properties->print("load");
 
 }
 
diff --git a/engines/dragons/dragonflg.h b/engines/dragons/dragonflg.h
index 0a5049687e..def1869406 100644
--- a/engines/dragons/dragonflg.h
+++ b/engines/dragons/dragonflg.h
@@ -38,6 +38,7 @@ public:
 	bool get(uint32 propertyId);
 	void set(uint32 propertyId, bool value);
 	void save(uint numberToWrite, Common::WriteStream *out);
+	void print(char *prefix);
 private:
 	uint _count;
 	byte *_properties;
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
index ee8ea9684c..78685d45ba 100644
--- a/engines/dragons/saveload.cpp
+++ b/engines/dragons/saveload.cpp
@@ -128,7 +128,7 @@ bool DragonsEngine::loadgame(const char *filename) {
 	// TODO load game state here. _gameState->read(in);
 	uint16 newSceneId = (uint16)in->readByte();
 	_dragonFLG->loadState(in);
-
+	_dragonFLG->set(165, true); //TODO check why this is needed to load save games properly.
 	_dragonVAR->reset();
 
 	_dragonINIResource->reset();


Commit: 7392c4bc1f0d65988e6dcf6ba61bd1afb87be1c6
    https://github.com/scummvm/scummvm/commit/7392c4bc1f0d65988e6dcf6ba61bd1afb87be1c6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Invention book display, work on intro sequence

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonimg.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 7e4117b248..fc6225cc5e 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -822,4 +822,18 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		return pointId;
 	}
 
+bool Actor::actorSetSequenceAndWaitAllowSkip(uint16 newSequenceID) {
+	updateSequence(newSequenceID);
+	waitUntilFlag8IsSet();
+
+	while(!isFlagSet(ACTOR_FLAG_4)) {
+		getEngine()->waitForFrames(1);
+		if (getEngine()->checkForActionButtonRelease()) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index b0ce3d11af..a9415c3060 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -130,6 +130,8 @@ public:
 	void waitUntilFlag8IsSet();
 	void waitUntilFlag8And4AreSet();
 
+	bool actorSetSequenceAndWaitAllowSkip(uint16 newSequenceID);
+
 	void clearFlag(uint32 flag);
 	void setFlag(uint32 flag);
 	bool isFlagSet(uint32 flag);
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index 7a0536dd2c..3749de1430 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -95,7 +95,7 @@ void Properties::print(char *prefix) {
 	str[i] = 0;
 	debug("%s: props = %s", prefix, str);
 
-	delete str;
+	delete[] str;
 }
 
 DragonFLG::DragonFLG(BigfileArchive *bigfileArchive) {
diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
index 0504e8454a..0d57210f1f 100644
--- a/engines/dragons/dragonimg.cpp
+++ b/engines/dragons/dragonimg.cpp
@@ -61,7 +61,6 @@ DragonIMG::~DragonIMG() {
 
 IMG *DragonIMG::getIMG(uint32 iptId) {
 	iptId &= 0xffff;
-	assert(iptId > 1);
 	assert(iptId < _count);
 	return &_imgObjects[iptId];
 }
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index dd997ab245..61b911590d 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1187,16 +1187,16 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 		_dragonVAR->setVar(1, 1);
 	}
 
-	if (sceneId > 2) { //TODO remove this restriction to enable intro sequence.
+	//if (sceneId > 2) { //TODO remove this restriction to enable intro sequence.
 		_scene->setSceneId(2);
 		byte *obd = _dragonOBD->getFromSpt(3);
 		ScriptOpCall scriptOpCall;
 		scriptOpCall._code = obd + 4;
 		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
 		_scriptOpcodes->runScript(scriptOpCall);
-	} else {
-		sceneId = 0x12; // HACK the first scene. TODO remove this
-	}
+	//} else {
+//		sceneId = 0x12; // HACK the first scene. TODO remove this
+//	}
 
 	_inventory->loadInventoryItemsFromSave();
 
@@ -1206,7 +1206,7 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 		_scene->setSceneId(getINI(0)->sceneId);
 	}
 	_sceneId1 = sceneId;
-	_scene->loadScene(sceneId, 0x1e);
+	_scene->loadScene(sceneId ? sceneId : 0x12, 0x1e);
 }
 
 void DragonsEngine::reset() {
@@ -1240,8 +1240,8 @@ void DragonsEngine::setSceneUpdateFunction(void (*newUpdateFunction)()) {
 	_sceneUpdateFunction = newUpdateFunction;
 }
 
-//void  (*DragonsEngine::getSceneUpdateFunction())() {
-//	return _sceneUpdateFunction ;
-//}
+void (*DragonsEngine::getSceneUpdateFunction())() {
+	return _sceneUpdateFunction;
+}
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 38af010a3a..1f7ec416df 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -220,7 +220,9 @@ public:
 
 	void runSceneUpdaterFunction();
 	void setSceneUpdateFunction(void (*newUpdateFunction)());
+	void (*getSceneUpdateFunction())();
 
+	bool checkForActionButtonRelease();
 private:
 	bool savegame(const char *filename, const char *description);
 	bool loadgame(const char *filename);
@@ -236,7 +238,6 @@ private:
 
 	bool isInputEnabled();
 	bool checkForInventoryButtonRelease();
-	bool checkForActionButtonRelease();
 
 	void FUN_8003130c();
 	void FUN_80038890();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 59a8c2f8eb..1b17fe0a72 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -27,6 +27,7 @@
 #include "background.h"
 #include "inventory.h"
 #include "bag.h"
+#include "scene.h"
 
 namespace Dragons {
 
@@ -65,6 +66,11 @@ Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 	_screenPositionIndex = 0;
 	_old_showing_value = 0;
 	_bag = NULL;
+
+	inventionBookPrevSceneUpdateFunc = NULL;
+	inventionBookPrevSceneId = 0;
+	inventionBookPrevFlickerINISceneId = 0;
+	inventionBookPrevFlickerINIPosition = Common::Point(0,0);
 }
 
 void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag, DragonINIResource *dragonIniResource) {
@@ -94,7 +100,6 @@ void Inventory::loadScene(uint32 sceneId) {
 	if (!_type) {
 		_sequenceId = _vm->isFlagSet(Dragons::ENGINE_FLAG_400000) ? 1 : 0;
 	}
-	_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(sceneId);
 
 	if (_sequenceId == 0 && _vm->getVar(7) == 1) {
 		_actor->updateSequence(5);
@@ -102,11 +107,7 @@ void Inventory::loadScene(uint32 sceneId) {
 		_actor->updateSequence(_sequenceId);
 	}
 
-	_actor->x_pos = positionTable[_screenPositionIndex].x;
-	if ((_sequenceId == 0 || _sequenceId == 2) && (_screenPositionIndex == 1 || _screenPositionIndex == 3)) {
-		_actor->x_pos += 0x32;
-	}
-	_actor->y_pos = positionTable[_screenPositionIndex].y;
+	setPositionFromSceneId(sceneId);
 }
 
 void Inventory::updateVisibility() {
@@ -263,4 +264,68 @@ void Inventory::loadInventoryItemsFromSave() {
 	}
 }
 
+void Inventory::openInventionBook() {
+	inventionBookPrevSceneUpdateFunc = _vm->getSceneUpdateFunction();
+	_vm->setSceneUpdateFunction(NULL);
+//	fade_related_calls_with_1f();
+	_sequenceId = 2;
+	_actor->updateSequence(2);
+	inventionBookPrevSceneId = _vm->getCurrentSceneId();
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+	if (flicker && flicker->actor) {
+		inventionBookPrevFlickerINISceneId = flicker->sceneId;
+		inventionBookPrevFlickerINIPosition = Common::Point(flicker->actor->x_pos, flicker->actor->y_pos);
+		flicker->sceneId = 0;
+	}
+	_vm->_scene->setSceneId(2);
+	_vm->_scene->loadScene(2, 0);
+}
+
+void Inventory::closeInventionBook() {
+	uint uVar1;
+	uint uVar2;
+
+	// TODO fade_related_calls_with_1f();
+
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+	if (flicker && flicker->actor) {
+		flicker->actor->x_pos = inventionBookPrevFlickerINIPosition.x;
+		flicker->actor->y_pos = inventionBookPrevFlickerINIPosition.y;
+		flicker->sceneId = inventionBookPrevFlickerINISceneId;
+	}
+	_vm->_scene->setSceneId(inventionBookPrevSceneId);
+
+	_sequenceId = 0;
+	setActorSequenceId(0);
+	setPositionFromSceneId(inventionBookPrevSceneId);
+	uVar2 = _vm->_scene->getSceneId();
+	if (((((uVar2 == 0x23) || (uVar2 == 0x2d)) || (uVar2 == 0x2e)) || ((uVar2 == 0x31 || (uVar2 == 0x32)))) || (uVar2 == 0x28)) {
+		LAB_80038b9c:
+		if ((uint)_vm->_scene->getSceneId() == 0x27) goto LAB_80038bb8;
+	}
+	else {
+		if (uVar2 != 0x27) {
+			if (((uVar2 != 0x1c) && (uVar2 != 0x1d)) && (uVar1 = uVar2 | 0x8000, uVar2 != 0x21)) goto LAB_80038be8;
+			goto LAB_80038b9c;
+		}
+		LAB_80038bb8:
+		_vm->getINI(0x206)->sceneId = 0;
+	}
+	uVar1 = (uint)_vm->_scene->getSceneId();
+	LAB_80038be8:
+	_vm->_scene->loadScene(uVar1,0x1e);
+	_vm->setSceneUpdateFunction(inventionBookPrevSceneUpdateFunc);
+	return;
+}
+
+void Inventory::setPositionFromSceneId(uint32 sceneId) {
+	_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(sceneId);
+
+	_actor->x_pos = positionTable[_screenPositionIndex].x;
+	if ((_sequenceId == 0 || _sequenceId == 2) && (_screenPositionIndex == 1 || _screenPositionIndex == 3)) {
+		_actor->x_pos += 0x32;
+	}
+	_actor->y_pos = positionTable[_screenPositionIndex].y;
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 307ec62219..4228fe2c62 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -44,6 +44,12 @@ private:
 	Actor *_actor;
 	int16 _type;
 	Bag *_bag;
+
+	void (*inventionBookPrevSceneUpdateFunc)();
+	uint16 inventionBookPrevSceneId;
+	uint16 inventionBookPrevFlickerINISceneId;
+	Common::Point inventionBookPrevFlickerINIPosition;
+
 public:
 	Inventory(DragonsEngine *vm);
 
@@ -78,7 +84,11 @@ public:
 	void draw();
 	uint16 getIniAtPosition(int16 x, int16 y);
 	void loadInventoryItemsFromSave();
+
+	void openInventionBook();
+	void closeInventionBook();
 private:
+	void setPositionFromSceneId(uint32 sceneId);
 	void animateBagIn();
 	void animateBagOut();
 };
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 11f9af7f30..4be3984ba0 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -72,6 +72,8 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0xc, spcUnkC);
 
+	OPCODE(0x12, spcHandleInventionBookTransition);
+	OPCODE(0x13, spcUnk13InventionBookCloseRelated);
 	OPCODE(0x14, spcClearEngineFlag8);
 	OPCODE(0x15, spcSetEngineFlag8);
 
@@ -109,6 +111,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x6c, spcTransitionFromMap);
 
 	OPCODE(0x7b, spcSetCameraXToZero);
+	OPCODE(0x7c, spcDiamondIntroSequenceLogic);
 
 }
 
@@ -152,6 +155,26 @@ void SpecialOpcodes::spcUnkC() {
 	//TODO fade_related_calls_with_1f();
 }
 
+void SpecialOpcodes::spcHandleInventionBookTransition() {
+	int16 invType =_vm->_inventory->getType();
+	if (invType == 1) {
+		_vm->_inventory->closeInventory();
+		_vm->_inventory->setType(0);
+	}
+	if (invType == 2) {
+		_vm->_inventory->closeInventionBook();
+		_vm->_inventory->setType(0);
+	}
+	_vm->_cursor->updateSequenceID(1);
+	_vm->setFlags(ENGINE_FLAG_400);
+	_vm->clearFlags(ENGINE_FLAG_10);
+}
+
+void SpecialOpcodes::spcUnk13InventionBookCloseRelated() {
+	_vm->clearFlags(ENGINE_FLAG_400);
+	_vm->setFlags(ENGINE_FLAG_10);
+}
+
 void SpecialOpcodes::spcClearEngineFlag8() {
 	_vm->clearFlags(Dragons::ENGINE_FLAG_8);
 }
@@ -165,11 +188,13 @@ void SpecialOpcodes::spcActivatePizzaMakerActor() {
 }
 
 void SpecialOpcodes::spcDeactivatePizzaMakerActor() {
-	_vm->setSceneUpdateFunction(NULL); //TODO only remove if currently running
+	if (_vm->getSceneUpdateFunction() == pizzaUpdateFunction) {
+		_vm->setSceneUpdateFunction(NULL);
+	}
 }
 
 void SpecialOpcodes::spcPizzaMakerActorStopWorking() {
-	_vm->setSceneUpdateFunction(NULL); //TODO only remove if currently running
+	spcDeactivatePizzaMakerActor();
 	pizzaMakerStopWorking();
 }
 
@@ -220,30 +245,12 @@ void SpecialOpcodes::spcOpenInventionBook() {
 	if (_vm->_inventory->getType() == 1) {
 		_vm->_inventory->closeInventory();
 	}
-	error("spcOpenInventionBook"); //TODO
-	DragonINI *pDVar1;
-
-//	DAT_80086f3c = func_ptr_unk;
-//	func_ptr_unk = 0;
-//	fade_related_calls_with_1f();
-//	inventorySequenceId = 2;
-//	actor_update_sequenceID(1,2);
-//	DAT_80083078 = currentSceneId;
-//	if (dragon_ini_maybe_flicker_control != 0xffff) {
-//		pDVar1 = dragon_ini_pointer + (uint)dragon_ini_maybe_flicker_control;
-//		DAT_800864a8 = actors[(uint)pDVar1->actorId].x_pos;
-//		DAT_80086424 = pDVar1->sceneId_maybe;
-//		DAT_800864ac = actors[(uint)pDVar1->actorId].y_pos;
-//		pDVar1->sceneId_maybe = 0;
-//	}
-//	currentSceneId = const_value_2;
-//	load_scene_maybe((uint)const_value_2,0);
-
+	_vm->_inventory->openInventionBook();
 	_vm->_inventory->setType(2);
 }
 
 void SpecialOpcodes::spcCloseInventionBook() {
-	error("spcCloseInventionBook");
+	_vm->_inventory->closeInventionBook();
 	_vm->_inventory->setType(0);
 }
 
@@ -310,6 +317,123 @@ void SpecialOpcodes::spcSetCameraXToZero() {
 	_vm->_scene->_camera.x = 0;
 }
 
+void SpecialOpcodes::spcDiamondIntroSequenceLogic() {
+	/*
+	bool bVar1;
+	ushort uVar2;
+	undefined4 uVar3;
+	DragonINI *pDVar4;
+	int iVar5;
+	uint uVar6;
+	short sVar7;
+	Actor *actorId;
+	Actor *actorId_00;
+	Actor *actorId_01;
+	Actor *actorId_02;
+	Actor *actorId_03;
+
+	pDVar4 = dragon_ini_pointer;
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+	actorId = _vm->getINI(0x257)->actor;
+	actorId_03 = _vm->getINI(0x259)->actor;
+	actorId_01 = _vm->getINI(0x258)->actor;
+	actorId_03->flags = actorId_03->flags | 0x100;
+	actorId_03->priorityLayer = 4;
+	uVar3 = scrFileData_maybe;
+	actorId_00 = _vm->getINI(0x256)->actor; //(uint)(ushort)pDVar4[iVar5 + -1].field_0x1c;
+	uVar2 = *(ushort *)((&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2] + 10);
+	_vm->setFlags(ENGINE_FLAG_20000);
+	actorId_02 = _vm->getINI(0x25a)->actor; //(uint)(ushort)pDVar4[DAT_80063ed4 + -1].field_0x1c;
+	iVar5 = (&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2];
+	if ((somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,DAT_80063ed8,0x2601) != 2) && (uVar6 = actorId->actorSetSequenceAndWaitAllowSkip(2), (uVar6 & 0xffff) == 0)) {
+		actorId->updateSequence(3);
+		uVar6 = actorId_01->actorSetSequenceAndWaitAllowSkip(0x18);
+		if ((uVar6 & 0xffff) == 0) {
+			sVar7 = 0x2c;
+			do {
+				_vm->waitForFrames(1);
+				uVar6 = _vm->checkForActionButtonRelease();
+				if ((uVar6 & 0xffff) != 0) break;
+				bVar1 = sVar7 != 0;
+				sVar7 = sVar7 + -1;
+			} while (bVar1);
+			//TODO fade_related_calls_with_1f();
+			load_palette_into_frame_buffer(0,(uint)uVar2 + iVar5);
+			camera_x = 0x140;
+			//TODO call_fade_related_1f();
+			uVar6 = actorId_00->actorSetSequenceAndWaitAllowSkip(0);
+			if ((uVar6 & 0xffff) == 0) {
+				playSoundFromTxtIndex(0x42A66);
+				uVar6 = somethingTextAndSpeechAndAnimRelated(actorId_00,1,2,DAT_80063ee0,0x3c01);
+				if ((uVar6 & 0xffff) != 2) {
+					sVar7 = 0x13;
+					do {
+						_vm->waitForFrames(1);
+						uVar6 = _vm->checkForActionButtonRelease();
+						if ((uVar6 & 0xffff) != 0) break;
+						bVar1 = sVar7 != 0;
+						sVar7 = sVar7 + -1;
+					} while (bVar1);
+					//TODO fade_related_calls_with_1f();
+					load_palette_into_frame_buffer(0,uVar3);
+					camera_x = 0;
+					sVar7 = 0xf;
+					//TODO call_fade_related_1f();
+					actorId_01->updateSequence(0x19);
+					do {
+						_vm->waitForFrames(1);
+						uVar6 = _vm->checkForActionButtonRelease();
+						if ((uVar6 & 0xffff) != 0) break;
+						bVar1 = sVar7 != 0;
+						sVar7 = sVar7 + -1;
+					} while (bVar1);
+					actorId->updateSequence(4);
+					sVar7 = 0x17;
+					do {
+						_vm->waitForFrames(1);
+						uVar6 = _vm->checkForActionButtonRelease();
+						if ((uVar6 & 0xffff) != 0) break;
+						bVar1 = sVar7 != 0;
+						sVar7 = sVar7 + -1;
+					} while (bVar1);
+					actorId_03->updateSequence(9);
+					actorId_03->x_pos = 0x82;
+					actorId_03->y_pos = 0xc4;
+					actorId_03->priorityLayer = 4;
+					uVar2 = actors[actorId].flags;
+					bVar1 = false;
+					while ((uVar2 & 4) == 0) {
+						uVar6 = _vm->checkForActionButtonRelease();
+						if ((uVar6 & 0xffff) != 0) {
+							bVar1 = true;
+							break;
+						}
+						uVar2 = actors[actorId].flags;
+					}
+					if (!bVar1) {
+						actorId->updateSequence(5);
+						uVar6 = somethingTextAndSpeechAndAnimRelated(actorId_01,0x10,2,DAT_80063ee4,0x3c01);
+						if (((uVar6 & 0xffff) != 2) && (uVar6 = somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,DAT_80063edc,0x2601), (uVar6 & 0xffff) != 2)) {
+							sVar7 = 0x3b;
+							do {
+								_vm->waitForFrames(1);
+								uVar6 = _vm->checkForActionButtonRelease();
+								if ((uVar6 & 0xffff) != 0) break;
+								bVar1 = sVar7 != 0;
+								sVar7 = sVar7 + -1;
+							} while (bVar1);
+						}
+					}
+				}
+			}
+		}
+	}
+	*/
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
+	_vm->clearFlags(ENGINE_FLAG_20000);
+	return;
+}
+
 void SpecialOpcodes::spcLoadScene1() {
 	// TODO spcLoadScene1 knights around the table.
 }
@@ -319,7 +443,7 @@ void SpecialOpcodes::spcTransitionToMap() {
 //	DAT_8006a422 = 0;
 //	DAT_8006a424 = 0;
 //	cursorSequenceId = 0;
-//	ContinueGame?();
+//	_vm->waitForFrames();
 //	engine_flags_maybe = engine_flags_maybe | 0x20000000;
 //	FUN_80023b34(0,0,1);
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 6472984824..ef5a1a457e 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -57,6 +57,8 @@ protected:
 
 	void spcUnkC();
 
+	void spcHandleInventionBookTransition(); // 0x12
+	void spcUnk13InventionBookCloseRelated(); //0x13
 	void spcClearEngineFlag8(); // 0x14
 	void spcSetEngineFlag8(); // 0x15
 
@@ -95,6 +97,7 @@ protected:
 	void spcTransitionFromMap(); // 0x6c
 
 	void spcSetCameraXToZero(); //0x7b
+	void spcDiamondIntroSequenceLogic(); //0x7c
 private:
 	void panCamera(int16 mode);
 	void pizzaMakerStopWorking();


Commit: 0312e613452423a51cbc3f6f3dd45795e8759ed1
    https://github.com/scummvm/scummvm/commit/0312e613452423a51cbc3f6f3dd45795e8759ed1
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on intro sequences

Changed paths:
  A engines/dragons/cutscene.cpp
  A engines/dragons/cutscene.h
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index fc6225cc5e..7ff4e16652 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -825,7 +825,10 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 bool Actor::actorSetSequenceAndWaitAllowSkip(uint16 newSequenceID) {
 	updateSequence(newSequenceID);
 	waitUntilFlag8IsSet();
+	return waitUntilFlag4IsSetAllowSkip();
+}
 
+bool Actor::waitUntilFlag4IsSetAllowSkip() {
 	while(!isFlagSet(ACTOR_FLAG_4)) {
 		getEngine()->waitForFrames(1);
 		if (getEngine()->checkForActionButtonRelease()) {
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index a9415c3060..73d151becb 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -130,6 +130,7 @@ public:
 	void waitUntilFlag8IsSet();
 	void waitUntilFlag8And4AreSet();
 
+	bool waitUntilFlag4IsSetAllowSkip();
 	bool actorSetSequenceAndWaitAllowSkip(uint16 newSequenceID);
 
 	void clearFlag(uint32 flag);
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
new file mode 100644
index 0000000000..96fa96fee7
--- /dev/null
+++ b/engines/dragons/cutscene.cpp
@@ -0,0 +1,384 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "cutscene.h"
+#include "dragons.h"
+#include "dragons/actor.h"
+#include "dragons/scene.h"
+#include "dragons/talk.h"
+
+namespace Dragons {
+
+CutScene::CutScene(DragonsEngine *vm): _vm(vm) {
+
+}
+
+void CutScene::scene1() {
+	// TODO spcLoadScene1 knights around the table.
+/* WIP
+	bool bVar1;
+	undefined2 uVar2;
+	undefined2 *puVar3;
+	uint actorId_arg;
+	uint8_t *dialogText;
+	undefined2 *puVar4;
+	uint uVar5;
+	uint uVar6;
+	uint uVar7;
+	uint uVar8;
+	short sVar9;
+	uint uVar10;
+	char acStack4024 [4000];
+
+	uVar2 = dragon_ini_maybe_flicker_control;
+	DAT_80063514 = 0xb00;
+	dragon_ini_maybe_flicker_control = 0xffff;
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+	uVar10 = engine_flags_maybe & 0x10;
+	//fade_related_calls_with_1f();
+	_vm->clearFlags(ENGINE_FLAG_10);
+	actors[0].flags = actors[0].flags | 0x400;
+	scr_tilemap1_w = 0x28;
+	actors[1].flags = actors[1].flags | 0x400;
+	DAT_8006a3f0 = DAT_8006a3ec;
+	load_actor_file(0x81);
+	load_actor_file(0x7d);
+	load_actor_file(0x7e);
+	load_actor_file(0x8f);
+	load_actor_file(0xaa);
+	_vm->setFlags(ENGINE_FLAG_20000);
+	FUN_8003d7d4();
+	_vm->waitForFrames(0x5a);
+	FUN_8003d97c(0xd3,0,0x233,0x17a);
+	//playSoundFromTxtIndex(0x4e26);
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x4e26,0x2e01) != 2) {
+		FUN_8003c108(DAT_80072de8);
+		FUN_8003d97c(0xd8,0,0xfd,0x60);
+		//playSoundFromTxtIndex(0x4ea2);
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x4ea2,0x701) != 2) {
+			FUN_8003c108(DAT_80072de8);
+			FUN_8003d97c(0xd3,0,0x233,0x17a);
+			//playSoundFromTxtIndex(0x4eec);
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x4eec,0x2e01) != 2) {
+				FUN_8003c108(DAT_80072de8);
+				FUN_8003d7d4();
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5000,0x2e01) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_800830c0,0x1d,0x1c,0x5074,0x501) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,9,5,0x511c,0xc01) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_800830c0,0x1d,0x1c,0x5138,0x501) != 2) {
+					FUN_8003d97c(0xd7,0,0x312,0x260);
+					//playSoundFromTxtIndex(0x5152);
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x5152,0x3e01) != 2) {
+						FUN_8003c108(DAT_80072de8);
+						FUN_8003d97c(0xd8,0,0xfd,0x60);
+						//playSoundFromTxtIndex(0x51fc);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x51fc,0x701) != 2) {
+							_vm->playSound(0x8004);
+							_vm->waitForFrames(0x28);
+							_vm->playSound(0x8003);
+							FUN_8003c108(DAT_80072de8);
+							DAT_80063514 = DAT_80063514 | 0x40;
+							FUN_8003d8e8(0xd6,0,0x37a,0x280);
+							DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3);
+							DAT_80072df0 = _vm->_actorManager->loadActor(0xd3,2,0x87,199,3);
+							_vm->waitForFramesAllowSkip(4);
+							// call_fade_related_1f();
+							if (FUN_8003dab8(0x52d6,0,0,0x701,1) != 2) {
+								callMaybeResetData();
+								//playSoundFromTxtIndex(0x530c);
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,2,0,0x530c,0x3c01) != 2) {
+									while (0x10 < _vm->_scene->_camera.x) {
+										_vm->_scene->_camera.x = _vm->_scene->_camera.x + -0x10;
+										_vm->waitForFrames(1);
+									}
+									_vm->_scene->_camera.x = 0;
+									//playSoundFromTxtIndex(0x54dc);
+									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,6,2,0x54dc,0x2e01) != 2) {
+										FUN_8003c108(DAT_80072de8);
+										FUN_8003c108(DAT_80072dec);
+										FUN_8003c108(DAT_80072df0);
+										FUN_8003d7d4();
+										if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e08,3,2,0x55d4,0xc01) != 2) {
+											FUN_8003d97c(0xd4,0,0x8a,0);
+											//playSoundFromTxtIndex(0x562c);
+											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x562c,0xc01) != 2) {
+												FUN_8003c108(DAT_80072de8);
+												FUN_8003d8e8(0xd6,0,0x37a,0x280);
+												DAT_80072dec = _vm->_actorManager->loadActor(0xd5,4,0x2d6,0xc6,3);
+												_vm->waitForFramesAllowSkip(4);
+												// call_fade_related_1f();
+												if (FUN_8003dab8(0x5780,0x14,0,0xc01,1) != 2) {
+													DAT_80063514 = DAT_80063514 | 0x40;
+													FUN_8003c108(DAT_80072de8);
+													FUN_8003c108(DAT_80072dec);
+													FUN_8003d97c(0xd7,0,0x312,0x260);
+													//playSoundFromTxtIndex(0x581c);
+													if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x581c,0x3e01) != 2) {
+														FUN_8003c108(DAT_80072de8);
+														FUN_8003d97c(0xd4,0,0x8a,0);
+														//playSoundFromTxtIndex(0x5942);
+														if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x5942,0xc01) != 2) {
+															FUN_8003c108(DAT_80072de8);
+															FUN_8003d97c(0xd3,2,0x87,0);
+															//playSoundFromTxtIndex(0x5aaa);
+															if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,7,2,0x5aaa,0x2e01) != 2) {
+																FUN_8003c108(DAT_80072de8);
+																FUN_8003d8e8(0xd6,0,0x37a,0x280);
+																DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3);
+																_vm->waitForFramesAllowSkip(4);
+																// call_fade_related_1f();
+																//playSoundFromTxtIndex(0x5afc);
+																if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,3,0,0x5afc,0x3c01) != 2) {
+																	FUN_8003c108(DAT_80072de8);
+																	FUN_8003c108(DAT_80072dec);
+																	DAT_80063514 = DAT_80063514 & 0xffbf;
+																	FUN_8003d7fc();
+																	_vm->playSound(0x8003);
+																	//playSoundFromTxtIndex(0x5b96);
+																	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,8,4,0x5b96,0xc01) != 2) {
+																		//playSoundFromTxtIndex(0x5c4a);
+																		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x5c4a,0x2e01) != 2) {
+																			//playSoundFromTxtIndex(0x5dc8);
+																			DAT_80072df0->updateSequence(0xf);
+																			DAT_80072df4->updateSequence(0xd);
+																			DAT_80072df8->updateSequence(0xe);
+																			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0xc,4,0x5dc8,0xc01) != 2) {
+																				DAT_80072df0->updateSequence(6);
+																				DAT_80072df4->updateSequence(0);
+																				DAT_80072df8->updateSequence(2);
+																				FUN_8003d8e8(0xd3,2,0x28d,0x250);
+																				DAT_80072dec = _vm->_actorManager->loadActor(0xd7,0,0x348,199,3);
+																				_vm->waitForFramesAllowSkip(4);
+																				//call_fade_related_1f();
+																				//playSoundFromTxtIndex(0x5ef2);
+																				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5ef2,0x3e01) != 2) {
+																					FUN_8003c108(DAT_80072de8);
+																					FUN_8003c108(DAT_80072dec);
+																					FUN_8003d97c(0xd3,0,0x233,0x17a);
+																					//playSoundFromTxtIndex(0x6000);
+																					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,8,0,0x6000,0x2e01) != 2) {
+																						FUN_8003c108(DAT_80072de8);
+																						FUN_8003d7fc();
+																						//playSoundFromTxtIndex(0x7dcc);
+																						DAT_80072df0->updateSequence(0x13);
+																						DAT_80072df4->updateSequence(0x10);
+																						DAT_80072df8->updateSequence(0x11);
+																						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
+																							FUN_8003d7d4();
+																							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x60ee,0x701) != 2) {
+																								FUN_8003d7fc();
+																								DAT_80072df0->updateSequence(6);
+																								DAT_80072df4->updateSequence(0);
+																								DAT_80072df8->updateSequence(2);
+																								DAT_80072dec->updateSequence(4);
+																								//playSoundFromTxtIndex(0x5de8);
+																								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df8,0xb,2,0x5de8,0xc01) != 2) {
+																									FUN_8003d7d4();
+																									_vm->playSound(1);
+																									DAT_80072df0->updateSequence(8);
+																									DAT_80072df4->updateSequence(0xd);
+																									DAT_80072df8->updateSequence(0x11);
+																									DAT_80072dfc->updateSequence(0x15);
+																									DAT_80072df0->waitUntilFlag8And4AreSet();
+																									DAT_80072df4->waitUntilFlag8And4AreSet();
+																									DAT_80072df8->waitUntilFlag8And4AreSet();
+																									DAT_80072dfc->waitUntilFlag8And4AreSet();
+																									// DisableVSyncEvent();
+																									load_actor_file(0x82);
+																									// EnableVSyncEvent();
+																									_vm->waitForFramesAllowSkip(0x3b);
+																									_vm->clearFlags(ENGINE_FLAG_20000);
+																									// fade_related_calls_with_1f();
+																									// DisableVSyncEvent();
+																									actorId_arg = 2;
+																									puVar4 = scrData_offset_200 + 4;
+																									do {
+																										*puVar4 = 0xffff;
+																										puVar4[1] = 0xffff;
+																										puVar3 = scrData_offset_200;
+																										actorId_arg = actorId_arg + 1;
+																										puVar4 = puVar4 + 2;
+																									} while (actorId_arg < 0x20);
+																									sVar9 = 0xe;
+																									scrData_offset_200[1] = 0x11;
+																									puVar3[2] = 199;
+																									*puVar3 = 0;
+																									puVar3[3] = 1;
+																									// EnableVSyncEvent();
+																									system_palette_related(2,0);
+																									// clearActorFlags(2);
+																									DAT_80072de8 = _vm->_actorManager->loadActor(0x82,0,0x60,0x114,1);
+																									DAT_80072dec = _vm->_actorManager->loadActor(0x82,2,0x91,0x113,1);
+																									DAT_80072df0 = _vm->_actorManager->loadActor(0x82,1,0xd0,199,1);
+																									DAT_80072df4 = _vm->_actorManager->loadActor(0x82,3,0xb6,0x113,1);
+																									DAT_80072de8 = _vm->_actorManager->loadActor(0x82,4,0x98,0x40,1);
+																									uVar5->setFlags()
+																									actors[uVar5].flags = actors[uVar5].flags | 0x8900
+																											;
+																									actorId_arg = (uint)DAT_80072dec;
+																									actors[uVar5].field_0x7c = 0x20000;
+																									uVar6 = (uint)DAT_80072df0;
+																									actors[actorId_arg].flags =
+																											actors[actorId_arg].flags | 0x8900;
+																									actors[actorId_arg].field_0x7c = 0x18000;
+																									uVar7 = (uint)DAT_80072df4;
+																									actors[uVar6].flags = actors[uVar6].flags | 0x8900
+																											;
+																									actors[uVar6].field_0x7c = 0x14000;
+																									uVar8 = (uint)DAT_80072df8;
+																									actors[uVar7].flags = actors[uVar7].flags | 0x8900
+																											;
+																									actors[uVar7].field_0x7c = 0x1c000;
+																									actors[uVar8].flags = actors[uVar8].flags | 0x8980
+																											;
+																									actors[uVar5].priorityLayer_maybe = 3;
+																									actors[actorId_arg].priorityLayer_maybe = 3;
+																									actors[uVar6].priorityLayer_maybe = 3;
+																									actors[uVar7].priorityLayer_maybe = 3;
+																									actors[uVar8].priorityLayer_maybe = 3;
+																									do {
+																										_vm->waitForFrames(1);
+																										actorId_arg = PressedThisFrameStart(0);
+																										if ((actorId_arg & 0xffff) != 0) break;
+																										bVar1 = sVar9 != 0;
+																										sVar9 = sVar9 + -1;
+																									} while (bVar1);
+																									call_fade_related_1f();
+																									actor_path_finding_maybe
+																											((uint)DAT_80072df0,0xe8,0xa8,2);
+																									while ((actors[(uint)DAT_80072df0].flags & 0x10)
+																										   != 0) {
+																										_vm->waitForFrames(1);
+																									}
+																									actor_path_finding_maybe((uint)DAT_80072de8,0x97,0x37,2);
+																									actor_path_finding_maybe((uint)DAT_80072dec,0x97,0x37,2);
+																									actor_path_finding_maybe((uint)DAT_80072df4,0x97,0x37,2);
+																									actor_wait_for_8_set_1000_wait_for_4((uint)DAT_80072df0);
+																									DAT_80072df0->updateSequence(6);
+																									dialogText = (uint8_t *)load_string_from_dragon_txt(0x5ea2,acStack4024);
+																									displayDialogAroundPoint(dialogText,0x27,0xc,0xc01,0,0x5ea2);
+																									waitUntilFlag8And4AreSet((uint)DAT_80072df0);
+																									actorId_arg = (uint)DAT_80072df0;
+																									actors[actorId_arg].x_pos = 0xcf;
+																									actors[actorId_arg].y_pos = 0x90;
+																									actor_path_finding_maybe(actorId_arg,0x97,0x37,2);
+																									DAT_80072df0->updateSequence(7);
+																									if (((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0))
+																										|| ((DAT_8008e844 != 0 || (DAT_8008e874 != 0)))
+																											) {
+																										FUN_8001a7c4((uint)DAT_8008e7e8,
+																													 (uint)DAT_8008e844,
+																													 (uint)DAT_8008e848,
+																													 (uint)DAT_8008e874);
+																									}
+																									dialogText = (uint8_t *)
+																											load_string_from_dragon_txt
+																													(0x5ecc,acStack4024);
+																									_vm->_talk->displayDialogAroundPoint(dialogText,0x14,6,0xc01,0,0x5ecc);
+																									FUN_80023794(1);
+																								}
+																							}
+																						}
+																					}
+																				}
+																			}
+																		}
+																	}
+																}
+															}
+														}
+													}
+												}
+											}
+										}
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+	// fade_related_calls_with_1f();
+	_vm->clearFlags(ENGINE_FLAG_20000);
+	// DisableVSyncEvent();
+	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+	// EnableVSyncEvent();
+	engine_flags_maybe = uVar10 | engine_flags_maybe;
+	dragon_ini_maybe_flicker_control = uVar2;
+	FUN_80021fc4();
+*/
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
+
+}
+
+void CutScene::FUN_8003c108(Actor *actor) {
+	// TODO fade_related_calls_with_1f();
+	//DisableVSyncEvent();
+	actor->reset_maybe();
+	//EnableVSyncEvent();
+
+}
+
+void CutScene::FUN_8003d97c(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4) {
+	FUN_8003d8e8(resourceId, sequenceId, x, param_4);
+	_vm->waitForFrames(5);
+	// TODO call_fade_related_1f();
+}
+
+
+void CutScene::FUN_8003d8e8(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4) {
+	// fade_related_calls_with_1f();
+	_vm->_actorManager->clearActorFlags(2);
+	//DisableVSyncEvent();
+	Actor *DAT_80072de8 = _vm->_actorManager->loadActor(resourceId, sequenceId, x, 199, 3);
+	//EnableVSyncEvent();
+	//TODO system_palette_related(3,param_4 & 0xffff);
+
+}
+
+void CutScene::FUN_8003d7d4() {
+	FUN_8003d388();
+	// call_fade_related_1f();
+
+}
+
+void CutScene::FUN_8003d388() {
+	//TODO implement me.
+}
+
+
+void CutScene::FUN_8003d7fc() {
+	//fade_related_calls_with_1f();
+	_vm->_actorManager->clearActorFlags(2);
+	DAT_80072de8 = _vm->_actorManager->loadActor(0x7d,0,2,199,1);
+	DAT_80072dec = _vm->_actorManager->loadActor(0x81,4,2,199,1);
+	DAT_80072df0 = _vm->_actorManager->loadActor(0x81,6,2,199,1);
+	DAT_80072df4 = _vm->_actorManager->loadActor(0x81,0,2,199,1);
+	DAT_80072df8 = _vm->_actorManager->loadActor(0x81,2,2,199,1);
+	//TODO system_palette_related(1,0);
+	_vm->waitForFrames(0xf);
+	//call_fade_related_1f();
+
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
new file mode 100644
index 0000000000..ff9296627d
--- /dev/null
+++ b/engines/dragons/cutscene.h
@@ -0,0 +1,63 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#ifndef DRAGONS_CUTSCENE_H
+#define DRAGONS_CUTSCENE_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class Actor;
+class DragonsEngine;
+
+class CutScene {
+private:
+	DragonsEngine *_vm;
+
+	Actor *DAT_80072de8;
+	Actor *DAT_80072dec;
+	Actor *DAT_800830c0;
+	Actor *DAT_80072df0;
+	Actor *DAT_80072e08;
+	Actor *DAT_80072df4;
+	Actor *DAT_80072df8;
+	Actor *DAT_80072dfc;
+
+	uint16 DAT_80063514; //flags
+public:
+	CutScene(DragonsEngine *vm);
+
+	void scene1();
+
+private:
+	//Scene 1 related functions
+	void FUN_8003c108(Actor *actor);
+	void FUN_8003d97c(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4);
+	void FUN_8003d8e8(uint16 resourceId,uint16 sequenceId,int16 x,uint32 param_4);
+	void FUN_8003d7d4();
+	void FUN_8003d388();
+	void FUN_8003d7fc();
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_CUTSCENE_H
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 61b911590d..38f4018152 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -29,6 +29,7 @@
 #include "background.h"
 #include "bigfile.h"
 #include "cursor.h"
+#include "cutscene.h"
 #include "dragonflg.h"
 #include "dragonimg.h"
 #include "dragonini.h"
@@ -66,6 +67,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_engine = this;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
+	_cutScene = new CutScene(this);
 	_talk = NULL;
 	_sound = new Sound(this);
 	_fontManager = NULL;
@@ -941,6 +943,15 @@ void DragonsEngine::waitForFrames(uint16 numFrames) {
 	}
 }
 
+void DragonsEngine::waitForFramesAllowSkip(uint16 numFrames) {
+	for (int i = 0; i < numFrames; i++) {
+		waitForFrames(1);
+		if (checkForActionButtonRelease()) { // TODO should this be any input?
+			return;
+		}
+	}
+}
+
 void DragonsEngine::playSound(uint16 soundId) {
 	debug(3, "TODO: play sound %d", soundId);
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 1f7ec416df..36912e886f 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -105,6 +105,7 @@ struct opCode1AStruct {
 class BigfileArchive;
 class BackgroundResourceLoader;
 class Cursor;
+class CutScene;
 class DragonFLG;
 class DragonIMG;
 class DragonOBD;
@@ -138,6 +139,7 @@ public:
 	Cursor *_cursor;
 	Talk *_talk;
 	Sound *_sound;
+	CutScene *_cutScene;
 
 	uint16 unkArray_uint16[42];
 	opCode1AStruct opCode1A_tbl[8];
@@ -202,6 +204,8 @@ public:
 	uint16 getCurrentSceneId();
 
 	void waitForFrames(uint16 numFrames);
+	void waitForFramesAllowSkip(uint16 numFrames);
+
 
 	void playSound(uint16 soundId);
 
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 5bd86533f8..c9e0e2eecc 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -7,6 +7,7 @@ MODULE_OBJS := \
     bag.o \
     bigfile.o \
     cursor.o \
+    cutscene.o \
 	detection.o \
     dragonflg.o \
     dragonimg.o \
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 4be3984ba0..93582ef116 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -21,6 +21,7 @@
  */
 
 #include "dragons/cursor.h"
+#include "dragons/cutscene.h"
 #include "dragons/dragons.h"
 #include "dragons/dragonflg.h"
 #include "dragons/dragonini.h"
@@ -29,6 +30,7 @@
 #include "dragons/specialopcodes.h"
 #include "dragons/scene.h"
 #include "dragons/actor.h"
+#include "talk.h"
 #include "specialopcodes.h"
 
 
@@ -318,124 +320,67 @@ void SpecialOpcodes::spcSetCameraXToZero() {
 }
 
 void SpecialOpcodes::spcDiamondIntroSequenceLogic() {
-	/*
-	bool bVar1;
-	ushort uVar2;
-	undefined4 uVar3;
-	DragonINI *pDVar4;
-	int iVar5;
-	uint uVar6;
-	short sVar7;
 	Actor *actorId;
 	Actor *actorId_00;
 	Actor *actorId_01;
 	Actor *actorId_02;
 	Actor *actorId_03;
 
-	pDVar4 = dragon_ini_pointer;
+//	pDVar4 = dragon_ini_pointer;
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 	actorId = _vm->getINI(0x257)->actor;
 	actorId_03 = _vm->getINI(0x259)->actor;
 	actorId_01 = _vm->getINI(0x258)->actor;
-	actorId_03->flags = actorId_03->flags | 0x100;
+	actorId_03->setFlag(ACTOR_FLAG_100);
 	actorId_03->priorityLayer = 4;
-	uVar3 = scrFileData_maybe;
-	actorId_00 = _vm->getINI(0x256)->actor; //(uint)(ushort)pDVar4[iVar5 + -1].field_0x1c;
-	uVar2 = *(ushort *)((&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2] + 10);
+//	uVar3 = scrFileData_maybe;
+	actorId_00 = _vm->getINI(0x256)->actor;
+//	uVar2 = *(ushort *)((&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2] + 10);
 	_vm->setFlags(ENGINE_FLAG_20000);
-	actorId_02 = _vm->getINI(0x25a)->actor; //(uint)(ushort)pDVar4[DAT_80063ed4 + -1].field_0x1c;
-	iVar5 = (&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2];
-	if ((somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,DAT_80063ed8,0x2601) != 2) && (uVar6 = actorId->actorSetSequenceAndWaitAllowSkip(2), (uVar6 & 0xffff) == 0)) {
+	actorId_02 = _vm->getINI(0x25a)->actor;
+//	iVar5 = (&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2];
+	if ((_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x4294a,0x2601) != 2) && !actorId->actorSetSequenceAndWaitAllowSkip(2)) {
 		actorId->updateSequence(3);
-		uVar6 = actorId_01->actorSetSequenceAndWaitAllowSkip(0x18);
-		if ((uVar6 & 0xffff) == 0) {
-			sVar7 = 0x2c;
-			do {
-				_vm->waitForFrames(1);
-				uVar6 = _vm->checkForActionButtonRelease();
-				if ((uVar6 & 0xffff) != 0) break;
-				bVar1 = sVar7 != 0;
-				sVar7 = sVar7 + -1;
-			} while (bVar1);
+		if (!actorId_01->actorSetSequenceAndWaitAllowSkip(0x18)) {
+			_vm->waitForFramesAllowSkip(0x2c);
 			//TODO fade_related_calls_with_1f();
-			load_palette_into_frame_buffer(0,(uint)uVar2 + iVar5);
-			camera_x = 0x140;
+			//TODO load_palette_into_frame_buffer(0,(uint)uVar2 + iVar5);
+			_vm->_scene->_camera.x = 0x140;
 			//TODO call_fade_related_1f();
-			uVar6 = actorId_00->actorSetSequenceAndWaitAllowSkip(0);
-			if ((uVar6 & 0xffff) == 0) {
-				playSoundFromTxtIndex(0x42A66);
-				uVar6 = somethingTextAndSpeechAndAnimRelated(actorId_00,1,2,DAT_80063ee0,0x3c01);
-				if ((uVar6 & 0xffff) != 2) {
-					sVar7 = 0x13;
-					do {
-						_vm->waitForFrames(1);
-						uVar6 = _vm->checkForActionButtonRelease();
-						if ((uVar6 & 0xffff) != 0) break;
-						bVar1 = sVar7 != 0;
-						sVar7 = sVar7 + -1;
-					} while (bVar1);
+			if (!actorId_00->actorSetSequenceAndWaitAllowSkip(0)) {
+				// TODO is this needed playSoundFromTxtIndex(0x42A66);
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_00,1,2,0x42a66,0x3c01) != 2) {
+					_vm->waitForFramesAllowSkip(0x13);
 					//TODO fade_related_calls_with_1f();
-					load_palette_into_frame_buffer(0,uVar3);
-					camera_x = 0;
-					sVar7 = 0xf;
+					// TODO load_palette_into_frame_buffer(0,uVar3);
+					_vm->_scene->_camera.x = 0;
 					//TODO call_fade_related_1f();
 					actorId_01->updateSequence(0x19);
-					do {
-						_vm->waitForFrames(1);
-						uVar6 = _vm->checkForActionButtonRelease();
-						if ((uVar6 & 0xffff) != 0) break;
-						bVar1 = sVar7 != 0;
-						sVar7 = sVar7 + -1;
-					} while (bVar1);
+					_vm->waitForFramesAllowSkip(0xf);
 					actorId->updateSequence(4);
-					sVar7 = 0x17;
-					do {
-						_vm->waitForFrames(1);
-						uVar6 = _vm->checkForActionButtonRelease();
-						if ((uVar6 & 0xffff) != 0) break;
-						bVar1 = sVar7 != 0;
-						sVar7 = sVar7 + -1;
-					} while (bVar1);
+					_vm->waitForFramesAllowSkip(0x17);
 					actorId_03->updateSequence(9);
 					actorId_03->x_pos = 0x82;
 					actorId_03->y_pos = 0xc4;
 					actorId_03->priorityLayer = 4;
-					uVar2 = actors[actorId].flags;
-					bVar1 = false;
-					while ((uVar2 & 4) == 0) {
-						uVar6 = _vm->checkForActionButtonRelease();
-						if ((uVar6 & 0xffff) != 0) {
-							bVar1 = true;
-							break;
-						}
-						uVar2 = actors[actorId].flags;
-					}
-					if (!bVar1) {
+					if (!actorId->waitUntilFlag4IsSetAllowSkip()) {
 						actorId->updateSequence(5);
-						uVar6 = somethingTextAndSpeechAndAnimRelated(actorId_01,0x10,2,DAT_80063ee4,0x3c01);
-						if (((uVar6 & 0xffff) != 2) && (uVar6 = somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,DAT_80063edc,0x2601), (uVar6 & 0xffff) != 2)) {
-							sVar7 = 0x3b;
-							do {
-								_vm->waitForFrames(1);
-								uVar6 = _vm->checkForActionButtonRelease();
-								if ((uVar6 & 0xffff) != 0) break;
-								bVar1 = sVar7 != 0;
-								sVar7 = sVar7 + -1;
-							} while (bVar1);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_01,0x10,2,0x42ac2,0x3c01) != 2 &&
+								_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x42b56,0x2601) != 2) {
+							_vm->waitForFramesAllowSkip(0x3b);
 						}
 					}
 				}
 			}
 		}
 	}
-	*/
 	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
 	_vm->clearFlags(ENGINE_FLAG_20000);
 	return;
 }
 
 void SpecialOpcodes::spcLoadScene1() {
-	// TODO spcLoadScene1 knights around the table.
+	_vm->_cutScene->scene1();
 }
 
 void SpecialOpcodes::spcTransitionToMap() {
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index ef5a1a457e..907aac69e2 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -101,6 +101,7 @@ protected:
 private:
 	void panCamera(int16 mode);
 	void pizzaMakerStopWorking();
+
 };
 
 // update functions
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index e34d7cd77b..83e3595715 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -315,5 +315,24 @@ void Talk::exitTalkMenu(bool isFlag8Set, bool isFlag100Set) {
 
 }
 
+uint Talk::somethingTextAndSpeechAndAnimRelated(Actor *actor, int16 sequenceId1, int16 sequenceId2, uint32 textIndex,
+												uint16 param_5) {
+	short sVar1;
+	uint uVar2;
+
+	uint16 dialog[2048];
+	dialog[0] = 0;
+	_vm->_talk->loadText(textIndex, dialog, 2048);
+
+	if (sequenceId1 != -1) {
+		actor->updateSequence(sequenceId1);
+	}
+	displayDialogAroundActor(actor,param_5, dialog, textIndex);
+	if (sequenceId2 != -1) {
+		actor->updateSequence(sequenceId2);
+	}
+	return 1; //TODO this should get return value from  displayDialogAroundActor();
+}
+
 
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 6ff298f2a0..c0115de806 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -70,6 +70,7 @@ public:
 
 	bool talkToActor(ScriptOpCall &scriptOpCall);
 
+	uint somethingTextAndSpeechAndAnimRelated(Actor *actor,int16 sequenceId1,int16 sequenceId2,uint32 textIndex, uint16 param_5);
 private:
 	void copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength);
 	uint32 wideStrLen(uint16 *text);


Commit: 627989e46f6449c737e4efbf0983c0148bcff94c
    https://github.com/scummvm/scummvm/commit/627989e46f6449c737e4efbf0983c0148bcff94c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: fixed font mapping

Changed paths:
    engines/dragons/font.cpp
    engines/dragons/font.h


diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index d8b041b373..91c17a573c 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -56,12 +56,10 @@ Font::~Font() {
 	free(_pixels);
 }
 
-uint16 mapChar(uint16 in) {
-	if (in >= 97) {
-		return in - 0x23;
-	}
-	return in - 0x20;
+uint16 Font::mapChar(uint16 in) {
+	return _map[in - _map[0x03] + 0x05];
 }
+
 Graphics::Surface *Font::render(uint16 *text, uint16 length, byte *palette) {
 	Graphics::Surface *surface = new Graphics::Surface();
 	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index 98701f027f..21276e144b 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -43,6 +43,8 @@ public:
 	Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelOffset, uint32 pixelSize);
 	~Font();
 	Graphics::Surface *render(uint16 *text, uint16 length, byte *palette);
+private:
+	uint16 mapChar(uint16 in);
 };
 
 struct ScreenTextEntry {
@@ -55,7 +57,7 @@ private:
 	DragonsEngine *_vm;
 	Font *_fonts[3];
 	Screen *_screen;
-	Common::List<ScreenTextEntry*> _screenTexts;
+	Common::List<ScreenTextEntry *> _screenTexts;
 	byte *_palettes;
 
 public:


Commit: 7d7946e87acf6394f577a63a2374b6dcc1486c84
    https://github.com/scummvm/scummvm/commit/7d7946e87acf6394f577a63a2374b6dcc1486c84
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on scene 1 logic

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 7ff4e16652..354dde94ef 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -576,6 +576,16 @@ void Actor::waitUntilFlag8And4AreSet() {
 	}
 }
 
+void Actor::waitUntilFlag8SetThenSet1000AndWaitFor4() {
+	waitUntilFlag8IsSet();
+
+	setFlag(ACTOR_FLAG_1000);
+
+	while(!isFlagSet(ACTOR_FLAG_4)) {
+		getEngine()->waitForFrames(1);
+	}
+}
+
 void Actor::clearFlag(uint32 flag) {
 	flags &= ~flag;
 }
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 73d151becb..2c6a81b88f 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -129,6 +129,7 @@ public:
 	void walkPath();
 	void waitUntilFlag8IsSet();
 	void waitUntilFlag8And4AreSet();
+	void waitUntilFlag8SetThenSet1000AndWaitFor4();
 
 	bool waitUntilFlag4IsSetAllowSkip();
 	bool actorSetSequenceAndWaitAllowSkip(uint16 newSequenceID);
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 24016aea54..636bf8ba86 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -347,6 +347,10 @@ void Cursor::setActorFlag400() {
 	_actor->setFlag(ACTOR_FLAG_400);
 }
 
+void Cursor::clearActorFlag400() {
+	_actor->clearFlag(ACTOR_FLAG_400);
+}
+
 byte *Cursor::getPalette() {
 	return _actor->_actorResource->getPalette();
 }
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index ef714e24a6..3b274dd26c 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -60,6 +60,7 @@ public:
 	void selectPreviousCursor();
 	void selectNextCursor();
 	void setActorFlag400();
+	void clearActorFlag400();
 	byte *getPalette();
 private:
 	int16 updateIniFromScene();
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 96fa96fee7..1cfb59475a 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -22,6 +22,9 @@
 #include "cutscene.h"
 #include "dragons.h"
 #include "dragons/actor.h"
+#include "dragons/inventory.h"
+#include "dragons/cursor.h"
+#include "dragons/dragonini.h"
 #include "dragons/scene.h"
 #include "dragons/talk.h"
 
@@ -33,37 +36,28 @@ CutScene::CutScene(DragonsEngine *vm): _vm(vm) {
 
 void CutScene::scene1() {
 	// TODO spcLoadScene1 knights around the table.
-/* WIP
-	bool bVar1;
-	undefined2 uVar2;
-	undefined2 *puVar3;
-	uint actorId_arg;
-	uint8_t *dialogText;
-	undefined2 *puVar4;
-	uint uVar5;
-	uint uVar6;
-	uint uVar7;
-	uint uVar8;
-	short sVar9;
-	uint uVar10;
-	char acStack4024 [4000];
-
-	uVar2 = dragon_ini_maybe_flicker_control;
+	bool isFlag10Set = _vm->isFlagSet(ENGINE_FLAG_10);
+
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+
 	DAT_80063514 = 0xb00;
-	dragon_ini_maybe_flicker_control = 0xffff;
+	_vm->_dragonINIResource->setFlickerRecord(NULL);
+
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
-	uVar10 = engine_flags_maybe & 0x10;
 	//fade_related_calls_with_1f();
 	_vm->clearFlags(ENGINE_FLAG_10);
-	actors[0].flags = actors[0].flags | 0x400;
-	scr_tilemap1_w = 0x28;
-	actors[1].flags = actors[1].flags | 0x400;
-	DAT_8006a3f0 = DAT_8006a3ec;
-	load_actor_file(0x81);
-	load_actor_file(0x7d);
-	load_actor_file(0x7e);
-	load_actor_file(0x8f);
-	load_actor_file(0xaa);
+
+	_vm->_inventory->setActorFlag400();
+	_vm->_cursor->setActorFlag400();
+
+//	scr_tilemap1_w = 0x28;
+//	DAT_8006a3f0 = DAT_8006a3ec;
+
+//	load_actor_file(0x81);
+//	load_actor_file(0x7d);
+//	load_actor_file(0x7e);
+//	load_actor_file(0x8f);
+//	load_actor_file(0xaa);
 	_vm->setFlags(ENGINE_FLAG_20000);
 	FUN_8003d7d4();
 	_vm->waitForFrames(0x5a);
@@ -102,7 +96,7 @@ void CutScene::scene1() {
 							_vm->waitForFramesAllowSkip(4);
 							// call_fade_related_1f();
 							if (FUN_8003dab8(0x52d6,0,0,0x701,1) != 2) {
-								callMaybeResetData();
+								// TODO callMaybeResetData();
 								//playSoundFromTxtIndex(0x530c);
 								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,2,0,0x530c,0x3c01) != 2) {
 									while (0x10 < _vm->_scene->_camera.x) {
@@ -202,98 +196,101 @@ void CutScene::scene1() {
 																									DAT_80072df8->waitUntilFlag8And4AreSet();
 																									DAT_80072dfc->waitUntilFlag8And4AreSet();
 																									// DisableVSyncEvent();
-																									load_actor_file(0x82);
+																									// TODO load_actor_file(0x82);
 																									// EnableVSyncEvent();
 																									_vm->waitForFramesAllowSkip(0x3b);
 																									_vm->clearFlags(ENGINE_FLAG_20000);
 																									// fade_related_calls_with_1f();
 																									// DisableVSyncEvent();
-																									actorId_arg = 2;
-																									puVar4 = scrData_offset_200 + 4;
-																									do {
-																										*puVar4 = 0xffff;
-																										puVar4[1] = 0xffff;
-																										puVar3 = scrData_offset_200;
-																										actorId_arg = actorId_arg + 1;
-																										puVar4 = puVar4 + 2;
-																									} while (actorId_arg < 0x20);
-																									sVar9 = 0xe;
-																									scrData_offset_200[1] = 0x11;
-																									puVar3[2] = 199;
-																									*puVar3 = 0;
-																									puVar3[3] = 1;
+//TODO
+//																									actorId_arg = 2;
+//																									puVar4 = scrData_offset_200 + 4;
+//																									do {
+//																										*puVar4 = 0xffff;
+//																										puVar4[1] = 0xffff;
+//																										puVar3 = scrData_offset_200;
+//																										actorId_arg = actorId_arg + 1;
+//																										puVar4 = puVar4 + 2;
+//																									} while (actorId_arg < 0x20);
+//																									sVar9 = 0xe;
+//																									scrData_offset_200[1] = 0x11;
+//																									puVar3[2] = 199;
+//																									*puVar3 = 0;
+//																									puVar3[3] = 1;
+
 																									// EnableVSyncEvent();
-																									system_palette_related(2,0);
-																									// clearActorFlags(2);
+																									// system_palette_related(2,0);
+																									_vm->_actorManager->clearActorFlags(2);
 																									DAT_80072de8 = _vm->_actorManager->loadActor(0x82,0,0x60,0x114,1);
 																									DAT_80072dec = _vm->_actorManager->loadActor(0x82,2,0x91,0x113,1);
 																									DAT_80072df0 = _vm->_actorManager->loadActor(0x82,1,0xd0,199,1);
 																									DAT_80072df4 = _vm->_actorManager->loadActor(0x82,3,0xb6,0x113,1);
 																									DAT_80072de8 = _vm->_actorManager->loadActor(0x82,4,0x98,0x40,1);
-																									uVar5->setFlags()
-																									actors[uVar5].flags = actors[uVar5].flags | 0x8900
-																											;
-																									actorId_arg = (uint)DAT_80072dec;
-																									actors[uVar5].field_0x7c = 0x20000;
-																									uVar6 = (uint)DAT_80072df0;
-																									actors[actorId_arg].flags =
-																											actors[actorId_arg].flags | 0x8900;
-																									actors[actorId_arg].field_0x7c = 0x18000;
-																									uVar7 = (uint)DAT_80072df4;
-																									actors[uVar6].flags = actors[uVar6].flags | 0x8900
-																											;
-																									actors[uVar6].field_0x7c = 0x14000;
-																									uVar8 = (uint)DAT_80072df8;
-																									actors[uVar7].flags = actors[uVar7].flags | 0x8900
-																											;
-																									actors[uVar7].field_0x7c = 0x1c000;
-																									actors[uVar8].flags = actors[uVar8].flags | 0x8980
-																											;
-																									actors[uVar5].priorityLayer_maybe = 3;
-																									actors[actorId_arg].priorityLayer_maybe = 3;
-																									actors[uVar6].priorityLayer_maybe = 3;
-																									actors[uVar7].priorityLayer_maybe = 3;
-																									actors[uVar8].priorityLayer_maybe = 3;
-																									do {
-																										_vm->waitForFrames(1);
-																										actorId_arg = PressedThisFrameStart(0);
-																										if ((actorId_arg & 0xffff) != 0) break;
-																										bVar1 = sVar9 != 0;
-																										sVar9 = sVar9 + -1;
-																									} while (bVar1);
-																									call_fade_related_1f();
-																									actor_path_finding_maybe
-																											((uint)DAT_80072df0,0xe8,0xa8,2);
-																									while ((actors[(uint)DAT_80072df0].flags & 0x10)
-																										   != 0) {
+
+																									DAT_80072de8->setFlag(ACTOR_FLAG_100);
+																									DAT_80072de8->setFlag(ACTOR_FLAG_800);
+																									DAT_80072de8->setFlag(ACTOR_FLAG_8000);
+																									DAT_80072de8->field_7c = 0x20000;
+																									DAT_80072de8->priorityLayer = 3;
+
+																									DAT_80072dec->setFlag(ACTOR_FLAG_100);
+																									DAT_80072dec->setFlag(ACTOR_FLAG_800);
+																									DAT_80072dec->setFlag(ACTOR_FLAG_8000);
+																									DAT_80072dec->field_7c = 0x18000;
+																									DAT_80072dec->priorityLayer = 3;
+
+																									DAT_80072df0->setFlag(ACTOR_FLAG_100);
+																									DAT_80072df0->setFlag(ACTOR_FLAG_800);
+																									DAT_80072df0->setFlag(ACTOR_FLAG_8000);
+																									DAT_80072df0->field_7c = 0x14000;
+																									DAT_80072df0->priorityLayer = 3;
+
+																									DAT_80072df4->setFlag(ACTOR_FLAG_100);
+																									DAT_80072df4->setFlag(ACTOR_FLAG_800);
+																									DAT_80072df4->setFlag(ACTOR_FLAG_8000);
+																									DAT_80072df4->field_7c = 0x1c000;
+																									DAT_80072df4->priorityLayer = 3;
+
+																									DAT_80072df8->setFlag(ACTOR_FLAG_100);
+																									DAT_80072df8->setFlag(ACTOR_FLAG_800);
+																									DAT_80072df8->setFlag(ACTOR_FLAG_8000);
+																									DAT_80072df8->priorityLayer = 3;
+
+																									_vm->waitForFramesAllowSkip(0xe);
+																									// call_fade_related_1f();
+																									DAT_80072df0->pathfinding_maybe(0xe8,0xa8,2);
+																									while (DAT_80072df0->isFlagSet(ACTOR_FLAG_10)) {
 																										_vm->waitForFrames(1);
 																									}
-																									actor_path_finding_maybe((uint)DAT_80072de8,0x97,0x37,2);
-																									actor_path_finding_maybe((uint)DAT_80072dec,0x97,0x37,2);
-																									actor_path_finding_maybe((uint)DAT_80072df4,0x97,0x37,2);
-																									actor_wait_for_8_set_1000_wait_for_4((uint)DAT_80072df0);
+																									DAT_80072de8->pathfinding_maybe(0x97,0x37,2);
+																									DAT_80072dec->pathfinding_maybe(0x97,0x37,2);
+																									DAT_80072df4->pathfinding_maybe(0x97,0x37,2);
+																									DAT_80072df0->waitUntilFlag8SetThenSet1000AndWaitFor4();
 																									DAT_80072df0->updateSequence(6);
-																									dialogText = (uint8_t *)load_string_from_dragon_txt(0x5ea2,acStack4024);
-																									displayDialogAroundPoint(dialogText,0x27,0xc,0xc01,0,0x5ea2);
-																									waitUntilFlag8And4AreSet((uint)DAT_80072df0);
-																									actorId_arg = (uint)DAT_80072df0;
-																									actors[actorId_arg].x_pos = 0xcf;
-																									actors[actorId_arg].y_pos = 0x90;
-																									actor_path_finding_maybe(actorId_arg,0x97,0x37,2);
+																									uint16 dialog[2000];
+																									dialog[0] = 0;
+																									_vm->_talk->loadText(0x5ea2, dialog, 2000);
+
+																									_vm->_talk->displayDialogAroundPoint(dialog,0x27,0xc,0xc01,0,0x5ea2);
+																									DAT_80072df0->waitUntilFlag8And4AreSet();
+																									DAT_80072df0->x_pos = 0xcf;
+																									DAT_80072df0->y_pos = 0x90;
+																									DAT_80072df0->pathfinding_maybe(0x97, 0x37, 2);
 																									DAT_80072df0->updateSequence(7);
-																									if (((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0))
-																										|| ((DAT_8008e844 != 0 || (DAT_8008e874 != 0)))
-																											) {
-																										FUN_8001a7c4((uint)DAT_8008e7e8,
-																													 (uint)DAT_8008e844,
-																													 (uint)DAT_8008e848,
-																													 (uint)DAT_8008e874);
-																									}
-																									dialogText = (uint8_t *)
-																											load_string_from_dragon_txt
-																													(0x5ecc,acStack4024);
-																									_vm->_talk->displayDialogAroundPoint(dialogText,0x14,6,0xc01,0,0x5ecc);
-																									FUN_80023794(1);
+//TODO
+//																									if (((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0))
+//																										|| ((DAT_8008e844 != 0 || (DAT_8008e874 != 0)))
+//																											) {
+//																										FUN_8001a7c4((uint)DAT_8008e7e8,
+//																													 (uint)DAT_8008e844,
+//																													 (uint)DAT_8008e848,
+//																													 (uint)DAT_8008e874);
+//																									}
+
+																									dialog[0] = 0;
+																									_vm->_talk->loadText(0x5ecc, dialog, 2000);
+																									_vm->_talk->displayDialogAroundPoint(dialog,0x14,6,0xc01,0,0x5ecc);
+																									_vm->waitForFrames(0x3c);
 																								}
 																							}
 																						}
@@ -321,12 +318,16 @@ void CutScene::scene1() {
 	// fade_related_calls_with_1f();
 	_vm->clearFlags(ENGINE_FLAG_20000);
 	// DisableVSyncEvent();
-	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+	//file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
 	// EnableVSyncEvent();
-	engine_flags_maybe = uVar10 | engine_flags_maybe;
-	dragon_ini_maybe_flicker_control = uVar2;
-	FUN_80021fc4();
-*/
+	if (isFlag10Set) {
+		_vm->setFlags(ENGINE_FLAG_10);
+	} else {
+		_vm->clearFlags(ENGINE_FLAG_10);
+	}
+
+	_vm->_dragonINIResource->setFlickerRecord(flicker);
+	cursorInventoryClearFlag400();
 	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
 
 }
@@ -350,7 +351,7 @@ void CutScene::FUN_8003d8e8(uint16 resourceId, uint16 sequenceId, int16 x, uint3
 	// fade_related_calls_with_1f();
 	_vm->_actorManager->clearActorFlags(2);
 	//DisableVSyncEvent();
-	Actor *DAT_80072de8 = _vm->_actorManager->loadActor(resourceId, sequenceId, x, 199, 3);
+	DAT_80072de8 = _vm->_actorManager->loadActor(resourceId, sequenceId, x, 199, 3);
 	//EnableVSyncEvent();
 	//TODO system_palette_related(3,param_4 & 0xffff);
 
@@ -363,7 +364,61 @@ void CutScene::FUN_8003d7d4() {
 }
 
 void CutScene::FUN_8003d388() {
-	//TODO implement me.
+	uint sequenceId;
+
+	// fade_related_calls_with_1f();
+	_vm->_actorManager->clearActorFlags(2);
+	if ((DAT_80063514 & 0x80) == 0) {
+		DAT_80072de8 = _vm->_actorManager->loadActor(0x7e,0x16,0x40,0xa0,1);
+	}
+	DAT_80072dec = _vm->_actorManager->loadActor(0x7e,0,0xbf,0xba,1);
+	if ((DAT_80063514 & 8) == 0) {
+		DAT_80072df0 = _vm->_actorManager->loadActor(0x7e,5,0x94,0x82,1);
+	}
+	if ((DAT_80063514 & 0x10) == 0) {
+		DAT_80072df4 = _vm->_actorManager->loadActor(0x7e,10,0x6f,0x95,1);
+	}
+	if ((DAT_80063514 & 4) == 0) {
+		DAT_80072df8 = _vm->_actorManager->loadActor(0x7e,0xe,0xa9,0x87,1);
+	}
+	if ((DAT_80063514 & 0x20) == 0) {
+		DAT_80072dfc = _vm->_actorManager->loadActor(0x7e,0x12,0xcd,0x8e,1);
+	}
+	if ((DAT_80063514 & 1) == 0) {
+		DAT_80072e04 = _vm->_actorManager->loadActor(0x7e,0x19,0x10e,0x89,1);
+	}
+	if ((DAT_80063514 & 2) == 0) {
+		DAT_80072e08 = _vm->_actorManager->loadActor(0x8f,2,100,0xbc,1);
+	}
+	if ((DAT_80063514 & 0x40) != 0) {
+		DAT_80072e0c = _vm->_actorManager->loadActor(0x8f,0,0xd2,100,1);
+		DAT_800830a0 = _vm->_actorManager->loadActor(0x8f,1,0xe6,0x6e,1);
+	}
+	DAT_800830b8 = _vm->_actorManager->loadActor(0xaa,0,0x2e,0x2d,1);
+	DAT_800830b8->setFlag(ACTOR_FLAG_8000);
+	DAT_800830bc = _vm->_actorManager->loadActor(0xaa,1,0x115,0x22,1);
+	DAT_800830bc->setFlag(ACTOR_FLAG_100);
+	DAT_800830bc->setFlag(ACTOR_FLAG_8000);
+	DAT_800830bc->priorityLayer = 4;
+	if ((DAT_80063514 & 0x100) != 0) {
+		DAT_800830c0 = _vm->_actorManager->loadActor(0x7e,0x1c,0x21,0x87,1);
+	}
+	if ((DAT_80063514 & 0x200) != 0) {
+		if ((DAT_80063514 & 0x800) == 0) {
+			sequenceId = 2;
+		}
+		else {
+			sequenceId = 4;
+		}
+		DAT_800830d4 = _vm->_actorManager->loadActor(0xaa,sequenceId,0xf4,199,1);
+		DAT_800830d4->setFlag(ACTOR_FLAG_8000);
+	}
+	if ((DAT_80063514 & 0x400) != 0) {
+		DAT_800830dc = _vm->_actorManager->loadActor(0xaa,3,0xf4,199,1);
+		DAT_800830dc->setFlag(ACTOR_FLAG_8000);
+	}
+	// system_palette_related(0,0);
+	_vm->waitForFramesAllowSkip(0xe);
 }
 
 
@@ -381,4 +436,19 @@ void CutScene::FUN_8003d7fc() {
 
 }
 
+uint16 CutScene::FUN_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5)
+{
+	uint16 dialog[2000];
+	dialog[0] = 0;
+	_vm->_talk->loadText(textId, dialog, 2000);
+
+	_vm->_talk->displayDialogAroundPoint(dialog,x,y,param_4,param_5,textId);
+	return 1; //TODO this should return (uint)dialogText & 0xffff;
+}
+
+void CutScene::cursorInventoryClearFlag400() {
+	_vm->_cursor->clearActorFlag400();
+	_vm->_inventory->clearActorFlag400();
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index ff9296627d..40a6b3d7c3 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -41,6 +41,13 @@ private:
 	Actor *DAT_80072df4;
 	Actor *DAT_80072df8;
 	Actor *DAT_80072dfc;
+	Actor *DAT_800830bc;
+	Actor *DAT_800830b8;
+	Actor *DAT_80072e0c;
+	Actor *DAT_800830a0;
+	Actor *DAT_800830d4;
+	Actor *DAT_800830dc;
+	Actor *DAT_80072e04;
 
 	uint16 DAT_80063514; //flags
 public:
@@ -56,6 +63,8 @@ private:
 	void FUN_8003d7d4();
 	void FUN_8003d388();
 	void FUN_8003d7fc();
+	uint16 FUN_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5);
+	void cursorInventoryClearFlag400();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 1b17fe0a72..b28b6ac4c2 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -122,6 +122,10 @@ void Inventory::setActorFlag400() {
 	_actor->setFlag(ACTOR_FLAG_400);
 }
 
+void Inventory::clearActorFlag400() {
+	_actor->clearFlag(ACTOR_FLAG_400);
+}
+
 void Inventory::setPriority(uint16 priority) {
 	_actor->priorityLayer = priority;
 }
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 4228fe2c62..73a9506223 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -76,6 +76,7 @@ public:
 
 	void updateVisibility();
 	void setActorFlag400();
+	void clearActorFlag400();
 	void setPriority(uint16 priority);
 
 	void openInventory();


Commit: a65be38d90432d72a6f19b88c23e10cc0948131b
    https://github.com/scummvm/scummvm/commit/a65be38d90432d72a6f19b88c23e10cc0948131b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Improved camera logic in scene 1 cutscene

Changed paths:
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 1cfb59475a..7abd122c11 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -219,7 +219,8 @@ void CutScene::scene1() {
 //																									puVar3[3] = 1;
 
 																									// EnableVSyncEvent();
-																									// system_palette_related(2,0);
+																									changeBackgroundPosition(
+																											2, 0);
 																									_vm->_actorManager->clearActorFlags(2);
 																									DAT_80072de8 = _vm->_actorManager->loadActor(0x82,0,0x60,0x114,1);
 																									DAT_80072dec = _vm->_actorManager->loadActor(0x82,2,0x91,0x113,1);
@@ -353,7 +354,7 @@ void CutScene::FUN_8003d8e8(uint16 resourceId, uint16 sequenceId, int16 x, uint3
 	//DisableVSyncEvent();
 	DAT_80072de8 = _vm->_actorManager->loadActor(resourceId, sequenceId, x, 199, 3);
 	//EnableVSyncEvent();
-	//TODO system_palette_related(3,param_4 & 0xffff);
+	changeBackgroundPosition(3, param_4);
 
 }
 
@@ -417,7 +418,7 @@ void CutScene::FUN_8003d388() {
 		DAT_800830dc = _vm->_actorManager->loadActor(0xaa,3,0xf4,199,1);
 		DAT_800830dc->setFlag(ACTOR_FLAG_8000);
 	}
-	// system_palette_related(0,0);
+	changeBackgroundPosition(0, 0);
 	_vm->waitForFramesAllowSkip(0xe);
 }
 
@@ -430,7 +431,7 @@ void CutScene::FUN_8003d7fc() {
 	DAT_80072df0 = _vm->_actorManager->loadActor(0x81,6,2,199,1);
 	DAT_80072df4 = _vm->_actorManager->loadActor(0x81,0,2,199,1);
 	DAT_80072df8 = _vm->_actorManager->loadActor(0x81,2,2,199,1);
-	//TODO system_palette_related(1,0);
+	changeBackgroundPosition(1, 0);
 	_vm->waitForFrames(0xf);
 	//call_fade_related_1f();
 
@@ -451,4 +452,52 @@ void CutScene::cursorInventoryClearFlag400() {
 	_vm->_inventory->clearActorFlag400();
 }
 
+void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
+{
+	//TODO handle palette changes here.
+	//undefined *puVar3;
+
+	if (newPosition == 1) {
+		//DAT_8006a420 = 1;
+		//DAT_8006a422 = 2;
+		_vm->_scene->_camera.x = sParm2 + 0x3c0;
+		//DAT_8006a424 = 0;
+		//load_palette_into_frame_buffer(0,&SYSTEM_PALETTE_3);
+		for (int i = 2; i < 0x17; i++) {
+			Actor *actor = _vm->_actorManager->getActor(i);
+			actor->x_pos += 0x3c0;
+		}
+	}
+	else {
+		if (newPosition < 2) {
+			if (newPosition != 0) {
+				return;
+			}
+			//puVar3 = &SYSTEM_PALETTE_1;
+			//DAT_8006a422 = 0;
+			//DAT_8006a424 = 0;
+			_vm->_scene->_camera.x = 0;
+		}
+		else {
+			if (newPosition == 2) {
+				//puVar3 = &SYSTEM_PALETTE_4;
+				//DAT_8006a422 = 2;
+				//DAT_8006a424 = 3;
+				_vm->_scene->_camera.x = 0;
+			}
+			else {
+				if (newPosition != 3) {
+					return;
+				}
+				//puVar3 = &SYSTEM_PALETTE_2;
+				//DAT_8006a422 = 2;
+				//DAT_8006a424 = 0;
+				_vm->_scene->_camera.x = sParm2;
+			}
+		}
+		//DAT_8006a420 = 1;
+		//load_palette_into_frame_buffer(0,puVar3);
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index 40a6b3d7c3..9e71d8e402 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -65,6 +65,7 @@ private:
 	void FUN_8003d7fc();
 	uint16 FUN_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5);
 	void cursorInventoryClearFlag400();
+	void changeBackgroundPosition(uint16 newPosition, int16 sParm2);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 08ece050c9..9180f40e18 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -853,7 +853,7 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 	}
 
 	//TODO fade_related_calls_with_1f();
-	// func_ptr_unk = 0;
+	_vm->setSceneUpdateFunction(NULL);
 	// PauseCDMusic();
 
 	if (newSceneID != 0) {


Commit: 9aa66dd9ee79407093942ab105c5ff7bfbeb7b44
    https://github.com/scummvm/scummvm/commit/9aa66dd9ee79407093942ab105c5ff7bfbeb7b44
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed background display priority logic

Changed paths:
    engines/dragons/actor.h
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/cutscene.cpp
    engines/dragons/scene.cpp
    engines/dragons/scene.h


diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 2c6a81b88f..0736c1f237 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -89,7 +89,7 @@ public:
 	ActorFrame *frame;
 	Graphics::Surface *surface;
 	uint16 field_c;
-	int16 field_e;
+	int16 field_e; // might be the amount to scale actor sprite.
 	uint16 sequenceTimer;
 	uint16 _sequenceID;
 	int16 _sequenceID2;
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index d5ab39b69e..75c6a72972 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -146,6 +146,10 @@ bool Background::load(byte *dataStart, uint32 size) {
 		_layer[i] = loadGfxLayer(_tileMap[i], _tileDataOffset);
 	}
 
+	layerPriority[0] = 1;
+	layerPriority[1] = 2;
+	layerPriority[2] = 3;
+
 	return false;
 }
 
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 5483c04a82..0c055873a4 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -61,6 +61,8 @@ private:
 	Graphics::Surface *_layer[3];
 	Common::Point *_points1;
 	Common::Point *_points2;
+	uint8 layerPriority[3];
+
 public:
 	Background();
 	~Background();
@@ -71,6 +73,14 @@ public:
 	Graphics::Surface *getBgLayer() { return _layer[0]; }
 	Graphics::Surface *getMgLayer() { return _layer[1]; }
 	Graphics::Surface *getFgLayer() { return _layer[2]; }
+	uint8 getBgLayerPriority() { return layerPriority[0]; }
+	uint8 getMgLayerPriority() { return layerPriority[1]; }
+	uint8 getFgLayerPriority() { return layerPriority[2]; }
+
+	void setBgLayerPriority(uint8 newPriority) { layerPriority[0] = newPriority; }
+	void setMgLayerPriority(uint8 newPriority) { layerPriority[1] = newPriority; }
+	void setFgLayerPriority(uint8 newPriority) { layerPriority[2] = newPriority; }
+
 	int16 getPriorityAtPoint(Common::Point pos);
 	Common::Point getPoint2(uint32 pointIndex);
 	byte *getPalette() { return _palette; }
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 7abd122c11..aa3157a7df 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -22,6 +22,7 @@
 #include "cutscene.h"
 #include "dragons.h"
 #include "dragons/actor.h"
+#include "dragons/background.h"
 #include "dragons/inventory.h"
 #include "dragons/cursor.h"
 #include "dragons/dragonini.h"
@@ -458,10 +459,10 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 	//undefined *puVar3;
 
 	if (newPosition == 1) {
-		//DAT_8006a420 = 1;
-		//DAT_8006a422 = 2;
+		_vm->_scene->setBgLayerPriority(1);
+		_vm->_scene->setMgLayerPriority(2);
 		_vm->_scene->_camera.x = sParm2 + 0x3c0;
-		//DAT_8006a424 = 0;
+		_vm->_scene->setFgLayerPriority(0);
 		//load_palette_into_frame_buffer(0,&SYSTEM_PALETTE_3);
 		for (int i = 2; i < 0x17; i++) {
 			Actor *actor = _vm->_actorManager->getActor(i);
@@ -474,15 +475,15 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 				return;
 			}
 			//puVar3 = &SYSTEM_PALETTE_1;
-			//DAT_8006a422 = 0;
-			//DAT_8006a424 = 0;
+			_vm->_scene->setMgLayerPriority(0);
+			_vm->_scene->setFgLayerPriority(0);
 			_vm->_scene->_camera.x = 0;
 		}
 		else {
 			if (newPosition == 2) {
 				//puVar3 = &SYSTEM_PALETTE_4;
-				//DAT_8006a422 = 2;
-				//DAT_8006a424 = 3;
+				_vm->_scene->setMgLayerPriority(2);
+				_vm->_scene->setFgLayerPriority(3);
 				_vm->_scene->_camera.x = 0;
 			}
 			else {
@@ -490,12 +491,12 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 					return;
 				}
 				//puVar3 = &SYSTEM_PALETTE_2;
-				//DAT_8006a422 = 2;
-				//DAT_8006a424 = 0;
+				_vm->_scene->setMgLayerPriority(2);
+				_vm->_scene->setFgLayerPriority(0);
 				_vm->_scene->_camera.x = sParm2;
 			}
 		}
-		//DAT_8006a420 = 1;
+		_vm->_scene->setBgLayerPriority(1);
 		//load_palette_into_frame_buffer(0,puVar3);
 	}
 }
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index ec44be5156..d8dd321c7c 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -317,13 +317,13 @@ void Scene::draw() {
 	Common::Rect rect(_camera.x, _camera.y, _camera.x + 320, _camera.y + 200);
 
 	for(uint16 priority = 1; priority < 16; priority++) {
-		if (priority == 1) {
+		if (priority == _stage->getBgLayerPriority()) {
 			_screen->copyRectToSurface(*_stage->getBgLayer(), 0, 0, rect);
-		} else if (priority == 2) {
+		} else if (priority == _stage->getMgLayerPriority()) {
 			_screen->copyRectToSurface(*_stage->getMgLayer(), 0, 0, rect);
-		} else if (priority == 3) {
+		} else if (priority == _stage->getFgLayerPriority()) {
 			_screen->copyRectToSurface(*_stage->getFgLayer(), 0, 0, rect);
-		} else if (priority == 4) { //TODO check if this is the correct priority
+		} else if (priority == 5) {
 			if (_vm->isFlagSet(ENGINE_FLAG_80)) {
 				_vm->_inventory->draw();
 			}
@@ -424,4 +424,16 @@ void Scene::resetActorFrameFlags() {
 	}
 }
 
+void Scene::setBgLayerPriority(uint8 newPriority) {
+	_stage->setBgLayerPriority(newPriority);
+}
+
+void Scene::setMgLayerPriority(uint8 newPriority) {
+	_stage->setMgLayerPriority(newPriority);
+}
+
+void Scene::setFgLayerPriority(uint8 newPriority) {
+	_stage->setFgLayerPriority(newPriority);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 068a6d4ebc..519747dee6 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -74,6 +74,11 @@ public:
 	uint16 getStageHeight();
 	void loadImageOverlay(uint16 iptId);
 	void removeImageOverlay(uint16 iptId);
+
+	void setBgLayerPriority(uint8 newPriority);
+	void setMgLayerPriority(uint8 newPriority);
+	void setFgLayerPriority(uint8 newPriority);
+
 private:
 	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
 	void resetActorFrameFlags();


Commit: efedc385110d6f02ac3fc23ad7b0485a76c548e6
    https://github.com/scummvm/scummvm/commit/efedc385110d6f02ac3fc23ad7b0485a76c548e6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add actor display order logic.

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/dragons.cpp
    engines/dragons/scene.cpp
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 354dde94ef..c1d9dd1bcd 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -32,6 +32,7 @@ ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorRes
 	for (uint16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
 		_actors.push_back(Actor(i));
 	}
+	resetDisplayOrder();
 }
 
 
@@ -54,6 +55,7 @@ Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, in
 		//TODO run find by resource and remove from mem logic here. @0x800358c8
 		debug("Unable to find free actor slot!!");
 	}
+	resetDisplayOrder();
 	return actor;
 }
 
@@ -92,6 +94,40 @@ ActorResource *ActorManager::getActorResource(uint32 resourceId) {
 	return _actorResourceLoader->load(resourceId);
 }
 
+void ActorManager::updateActorDisplayOrder() {
+	bool shouldContinue = true;
+
+	while(shouldContinue) {
+		shouldContinue = false;
+		for (int i = 0; i < DRAGONS_ENGINE_NUM_ACTORS - 1; i++) {
+			Actor *curActor = getActor(_displayOrder[i]);
+			Actor *nextActor = getActor(_displayOrder[i + 1]);
+			int16 curY = curActor->y_pos > 0 ? curActor->y_pos : 0;
+			int16 nextY = nextActor->y_pos > 0 ? nextActor->y_pos : 0;
+			if (nextActor->priorityLayer * 0x1000000 + nextY * 0x100 + nextActor->_actorID <
+				curActor->priorityLayer * 0x1000000 + curY * 0x100 + curActor->_actorID) {
+				_displayOrder[i] = nextActor->_actorID;
+				_displayOrder[i + 1] = curActor->_actorID;
+				shouldContinue = true;
+			}
+		}
+	}
+}
+
+void ActorManager::resetDisplayOrder() {
+	for (uint16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
+		Actor *actor = getActor(i);
+		_displayOrder[i] = i;
+		if (!actor->isFlagSet(ACTOR_FLAG_40)) {
+			actor->priorityLayer = 0;
+		}
+	}
+}
+
+Actor *ActorManager::getActorByDisplayOrder(uint16 position) {
+	return getActor(_displayOrder[position]);
+}
+
 Actor::Actor(uint16 id) : _actorID(id) {
 	_actorResource = NULL;
 	resourceID = -1;
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 0736c1f237..68d3f4df59 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -64,6 +64,7 @@ public:
 private:
 	ActorResourceLoader *_actorResourceLoader;
 	Actors _actors;
+	uint16 _displayOrder[DRAGONS_ENGINE_NUM_ACTORS];
 public:
 	ActorManager(ActorResourceLoader *actorResourceLoader);
 
@@ -72,10 +73,13 @@ public:
 	Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 priorityLayer);
 	Actor *loadActor(uint32 resourceId, uint16 actorId);
 	Actor *getActor(uint16 actorId);
+	Actor *getActorByDisplayOrder(uint16 position);
 	void clearActorFlags(uint16 startingActorId);
 	ActorResource *getActorResource(uint32 resourceId);
+	void updateActorDisplayOrder();
 private:
 	Actor *findFreeActor(int16 resourceID);
+	void resetDisplayOrder();
 };
 
 class Actor {
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index aa3157a7df..ed1518e547 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -60,30 +60,30 @@ void CutScene::scene1() {
 //	load_actor_file(0x8f);
 //	load_actor_file(0xaa);
 	_vm->setFlags(ENGINE_FLAG_20000);
-	FUN_8003d7d4();
+	wideAngleEveryoneAtTable();
 	_vm->waitForFrames(0x5a);
-	FUN_8003d97c(0xd3,0,0x233,0x17a);
+	closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 	//playSoundFromTxtIndex(0x4e26);
 	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x4e26,0x2e01) != 2) {
 		FUN_8003c108(DAT_80072de8);
-		FUN_8003d97c(0xd8,0,0xfd,0x60);
+		closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); // cut to flicker
 		//playSoundFromTxtIndex(0x4ea2);
 		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x4ea2,0x701) != 2) {
 			FUN_8003c108(DAT_80072de8);
-			FUN_8003d97c(0xd3,0,0x233,0x17a);
+			closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 			//playSoundFromTxtIndex(0x4eec);
 			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x4eec,0x2e01) != 2) {
 				FUN_8003c108(DAT_80072de8);
-				FUN_8003d7d4();
+				wideAngleEveryoneAtTable();  // shot of whole room
 				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5000,0x2e01) != 2 &&
 					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_800830c0,0x1d,0x1c,0x5074,0x501) != 2 &&
 					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,9,5,0x511c,0xc01) != 2 &&
 					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_800830c0,0x1d,0x1c,0x5138,0x501) != 2) {
-					FUN_8003d97c(0xd7,0,0x312,0x260);
+					closeUpShotOnActor(0xd7, 0, 0x312, 0x260); //close up on flame
 					//playSoundFromTxtIndex(0x5152);
 					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x5152,0x3e01) != 2) {
 						FUN_8003c108(DAT_80072de8);
-						FUN_8003d97c(0xd8,0,0xfd,0x60);
+						closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); //close up flicker
 						//playSoundFromTxtIndex(0x51fc);
 						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x51fc,0x701) != 2) {
 							_vm->playSound(0x8004);
@@ -92,7 +92,7 @@ void CutScene::scene1() {
 							FUN_8003c108(DAT_80072de8);
 							DAT_80063514 = DAT_80063514 | 0x40;
 							FUN_8003d8e8(0xd6,0,0x37a,0x280);
-							DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3);
+							DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3); //load humans
 							DAT_80072df0 = _vm->_actorManager->loadActor(0xd3,2,0x87,199,3);
 							_vm->waitForFramesAllowSkip(4);
 							// call_fade_related_1f();
@@ -110,9 +110,9 @@ void CutScene::scene1() {
 										FUN_8003c108(DAT_80072de8);
 										FUN_8003c108(DAT_80072dec);
 										FUN_8003c108(DAT_80072df0);
-										FUN_8003d7d4();
+										wideAngleEveryoneAtTable();
 										if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e08,3,2,0x55d4,0xc01) != 2) {
-											FUN_8003d97c(0xd4,0,0x8a,0);
+											closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 											//playSoundFromTxtIndex(0x562c);
 											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x562c,0xc01) != 2) {
 												FUN_8003c108(DAT_80072de8);
@@ -124,15 +124,15 @@ void CutScene::scene1() {
 													DAT_80063514 = DAT_80063514 | 0x40;
 													FUN_8003c108(DAT_80072de8);
 													FUN_8003c108(DAT_80072dec);
-													FUN_8003d97c(0xd7,0,0x312,0x260);
+													closeUpShotOnActor(0xd7, 0, 0x312, 0x260); // close up flame
 													//playSoundFromTxtIndex(0x581c);
 													if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x581c,0x3e01) != 2) {
 														FUN_8003c108(DAT_80072de8);
-														FUN_8003d97c(0xd4,0,0x8a,0);
+														closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 														//playSoundFromTxtIndex(0x5942);
 														if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x5942,0xc01) != 2) {
 															FUN_8003c108(DAT_80072de8);
-															FUN_8003d97c(0xd3,2,0x87,0);
+															closeUpShotOnActor(0xd3, 2, 0x87, 0); // close up king
 															//playSoundFromTxtIndex(0x5aaa);
 															if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,7,2,0x5aaa,0x2e01) != 2) {
 																FUN_8003c108(DAT_80072de8);
@@ -145,7 +145,7 @@ void CutScene::scene1() {
 																	FUN_8003c108(DAT_80072de8);
 																	FUN_8003c108(DAT_80072dec);
 																	DAT_80063514 = DAT_80063514 & 0xffbf;
-																	FUN_8003d7fc();
+																	closeUpKnightsAtTable(); // close up of knights at table. TODO draw order not right here
 																	_vm->playSound(0x8003);
 																	//playSoundFromTxtIndex(0x5b96);
 																	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,8,4,0x5b96,0xc01) != 2) {
@@ -161,32 +161,33 @@ void CutScene::scene1() {
 																				DAT_80072df8->updateSequence(2);
 																				FUN_8003d8e8(0xd3,2,0x28d,0x250);
 																				DAT_80072dec = _vm->_actorManager->loadActor(0xd7,0,0x348,199,3);
-																				_vm->waitForFramesAllowSkip(4);
+																				_vm->waitForFramesAllowSkip(4); // close up of king and flame
 																				//call_fade_related_1f();
 																				//playSoundFromTxtIndex(0x5ef2);
 																				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5ef2,0x3e01) != 2) {
 																					FUN_8003c108(DAT_80072de8);
 																					FUN_8003c108(DAT_80072dec);
-																					FUN_8003d97c(0xd3,0,0x233,0x17a);
+																					closeUpShotOnActor(0xd3, 0, 0x233,
+																									   0x17a); // close up of king
 																					//playSoundFromTxtIndex(0x6000);
 																					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,8,0,0x6000,0x2e01) != 2) {
 																						FUN_8003c108(DAT_80072de8);
-																						FUN_8003d7fc();
+																						closeUpKnightsAtTable(); // close up knights at table
 																						//playSoundFromTxtIndex(0x7dcc);
 																						DAT_80072df0->updateSequence(0x13);
 																						DAT_80072df4->updateSequence(0x10);
 																						DAT_80072df8->updateSequence(0x11);
 																						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
-																							FUN_8003d7d4();
+																							wideAngleEveryoneAtTable(); //whole room shot
 																							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x60ee,0x701) != 2) {
-																								FUN_8003d7fc();
+																								closeUpKnightsAtTable();
 																								DAT_80072df0->updateSequence(6);
 																								DAT_80072df4->updateSequence(0);
 																								DAT_80072df8->updateSequence(2);
 																								DAT_80072dec->updateSequence(4);
 																								//playSoundFromTxtIndex(0x5de8);
 																								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df8,0xb,2,0x5de8,0xc01) != 2) {
-																									FUN_8003d7d4();
+																									wideAngleEveryoneAtTable();
 																									_vm->playSound(1);
 																									DAT_80072df0->updateSequence(8);
 																									DAT_80072df4->updateSequence(0xd);
@@ -342,7 +343,7 @@ void CutScene::FUN_8003c108(Actor *actor) {
 
 }
 
-void CutScene::FUN_8003d97c(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4) {
+void CutScene::closeUpShotOnActor(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4) {
 	FUN_8003d8e8(resourceId, sequenceId, x, param_4);
 	_vm->waitForFrames(5);
 	// TODO call_fade_related_1f();
@@ -359,7 +360,7 @@ void CutScene::FUN_8003d8e8(uint16 resourceId, uint16 sequenceId, int16 x, uint3
 
 }
 
-void CutScene::FUN_8003d7d4() {
+void CutScene::wideAngleEveryoneAtTable() {
 	FUN_8003d388();
 	// call_fade_related_1f();
 
@@ -424,7 +425,7 @@ void CutScene::FUN_8003d388() {
 }
 
 
-void CutScene::FUN_8003d7fc() {
+void CutScene::closeUpKnightsAtTable() {
 	//fade_related_calls_with_1f();
 	_vm->_actorManager->clearActorFlags(2);
 	DAT_80072de8 = _vm->_actorManager->loadActor(0x7d,0,2,199,1);
@@ -501,4 +502,63 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 	}
 }
 
+void CutScene::diamondScene() {
+	Actor *actorId;
+	Actor *actorId_00;
+	Actor *actorId_01;
+	Actor *actorId_02;
+	Actor *actorId_03;
+
+//	pDVar4 = dragon_ini_pointer;
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+	actorId = _vm->getINI(0x257)->actor;
+	actorId_03 = _vm->getINI(0x259)->actor;
+	actorId_01 = _vm->getINI(0x258)->actor;
+	actorId_03->setFlag(ACTOR_FLAG_100);
+	actorId_03->priorityLayer = 4;
+//	uVar3 = scrFileData_maybe;
+	actorId_00 = _vm->getINI(0x256)->actor;
+//	uVar2 = *(ushort *)((&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2] + 10);
+	_vm->setFlags(ENGINE_FLAG_20000);
+	actorId_02 = _vm->getINI(0x25a)->actor;
+//	iVar5 = (&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2];
+	if ((_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x4294a,0x2601) != 2) && !actorId->actorSetSequenceAndWaitAllowSkip(2)) {
+		actorId->updateSequence(3);
+		if (!actorId_01->actorSetSequenceAndWaitAllowSkip(0x18)) {
+			_vm->waitForFramesAllowSkip(0x2c);
+			//TODO fade_related_calls_with_1f();
+			//TODO load_palette_into_frame_buffer(0,(uint)uVar2 + iVar5);
+			_vm->_scene->_camera.x = 0x140;
+			//TODO call_fade_related_1f();
+			if (!actorId_00->actorSetSequenceAndWaitAllowSkip(0)) {
+				// TODO is this needed playSoundFromTxtIndex(0x42A66);
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_00,1,2,0x42a66,0x3c01) != 2) {
+					_vm->waitForFramesAllowSkip(0x13);
+					//TODO fade_related_calls_with_1f();
+					// TODO load_palette_into_frame_buffer(0,uVar3);
+					_vm->_scene->_camera.x = 0;
+					//TODO call_fade_related_1f();
+					actorId_01->updateSequence(0x19);
+					_vm->waitForFramesAllowSkip(0xf);
+					actorId->updateSequence(4);
+					_vm->waitForFramesAllowSkip(0x17);
+					actorId_03->updateSequence(9);
+					actorId_03->x_pos = 0x82;
+					actorId_03->y_pos = 0xc4;
+					actorId_03->priorityLayer = 4;
+					if (!actorId->waitUntilFlag4IsSetAllowSkip()) {
+						actorId->updateSequence(5);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_01,0x10,2,0x42ac2,0x3c01) != 2 &&
+							_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x42b56,0x2601) != 2) {
+							_vm->waitForFramesAllowSkip(0x3b);
+						}
+					}
+				}
+			}
+		}
+	}
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
+	_vm->clearFlags(ENGINE_FLAG_20000);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index 9e71d8e402..2475f9c5b1 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -54,15 +54,16 @@ public:
 	CutScene(DragonsEngine *vm);
 
 	void scene1();
+	void diamondScene();
 
 private:
 	//Scene 1 related functions
 	void FUN_8003c108(Actor *actor);
-	void FUN_8003d97c(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4);
+	void closeUpShotOnActor(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4);
 	void FUN_8003d8e8(uint16 resourceId,uint16 sequenceId,int16 x,uint32 param_4);
-	void FUN_8003d7d4();
+	void wideAngleEveryoneAtTable();
 	void FUN_8003d388();
-	void FUN_8003d7fc();
+	void closeUpKnightsAtTable();
 	uint16 FUN_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5);
 	void cursorInventoryClearFlag400();
 	void changeBackgroundPosition(uint16 newPosition, int16 sParm2);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 38f4018152..e5d19fb30a 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -578,6 +578,8 @@ void DragonsEngine::updateHandler() {
 	_cursor->updateVisibility();
 	_inventory->updateVisibility();
 
+	_actorManager->updateActorDisplayOrder();
+
 	// 0x8001b200
 	if (isFlagSet(ENGINE_FLAG_8000) && !_sound->isSpeechPlaying()) {
 		clearFlags(ENGINE_FLAG_8000);
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index d8dd321c7c..b42241bfe2 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -329,8 +329,8 @@ void Scene::draw() {
 			}
 		}
 
-		for (int16 i = DRAGONS_ENGINE_NUM_ACTORS - 1; i >= 0; i--) {
-			Actor *actor = _actorManager->getActor(i);
+		for (int16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
+			Actor *actor = _actorManager->getActorByDisplayOrder(i);
 			if (actor->x_pos == -100 && actor->y_pos == 100) {
 				actor->priorityLayer = 0;
 				continue;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 93582ef116..f051f7c893 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -320,63 +320,7 @@ void SpecialOpcodes::spcSetCameraXToZero() {
 }
 
 void SpecialOpcodes::spcDiamondIntroSequenceLogic() {
-	Actor *actorId;
-	Actor *actorId_00;
-	Actor *actorId_01;
-	Actor *actorId_02;
-	Actor *actorId_03;
-
-//	pDVar4 = dragon_ini_pointer;
-	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
-	actorId = _vm->getINI(0x257)->actor;
-	actorId_03 = _vm->getINI(0x259)->actor;
-	actorId_01 = _vm->getINI(0x258)->actor;
-	actorId_03->setFlag(ACTOR_FLAG_100);
-	actorId_03->priorityLayer = 4;
-//	uVar3 = scrFileData_maybe;
-	actorId_00 = _vm->getINI(0x256)->actor;
-//	uVar2 = *(ushort *)((&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2] + 10);
-	_vm->setFlags(ENGINE_FLAG_20000);
-	actorId_02 = _vm->getINI(0x25a)->actor;
-//	iVar5 = (&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2];
-	if ((_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x4294a,0x2601) != 2) && !actorId->actorSetSequenceAndWaitAllowSkip(2)) {
-		actorId->updateSequence(3);
-		if (!actorId_01->actorSetSequenceAndWaitAllowSkip(0x18)) {
-			_vm->waitForFramesAllowSkip(0x2c);
-			//TODO fade_related_calls_with_1f();
-			//TODO load_palette_into_frame_buffer(0,(uint)uVar2 + iVar5);
-			_vm->_scene->_camera.x = 0x140;
-			//TODO call_fade_related_1f();
-			if (!actorId_00->actorSetSequenceAndWaitAllowSkip(0)) {
-				// TODO is this needed playSoundFromTxtIndex(0x42A66);
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_00,1,2,0x42a66,0x3c01) != 2) {
-					_vm->waitForFramesAllowSkip(0x13);
-					//TODO fade_related_calls_with_1f();
-					// TODO load_palette_into_frame_buffer(0,uVar3);
-					_vm->_scene->_camera.x = 0;
-					//TODO call_fade_related_1f();
-					actorId_01->updateSequence(0x19);
-					_vm->waitForFramesAllowSkip(0xf);
-					actorId->updateSequence(4);
-					_vm->waitForFramesAllowSkip(0x17);
-					actorId_03->updateSequence(9);
-					actorId_03->x_pos = 0x82;
-					actorId_03->y_pos = 0xc4;
-					actorId_03->priorityLayer = 4;
-					if (!actorId->waitUntilFlag4IsSetAllowSkip()) {
-						actorId->updateSequence(5);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_01,0x10,2,0x42ac2,0x3c01) != 2 &&
-								_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x42b56,0x2601) != 2) {
-							_vm->waitForFramesAllowSkip(0x3b);
-						}
-					}
-				}
-			}
-		}
-	}
-	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
-	_vm->clearFlags(ENGINE_FLAG_20000);
-	return;
+	_vm->_cutScene->diamondScene();
 }
 
 void SpecialOpcodes::spcLoadScene1() {


Commit: 8612ccf5e0450ffa25beaaa9e0b1bf4933656e49
    https://github.com/scummvm/scummvm/commit/8612ccf5e0450ffa25beaaa9e0b1bf4933656e49
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Improved scene 1 draw order

Changed paths:
    engines/dragons/cutscene.cpp


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index ed1518e547..eeaa0d9069 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -460,8 +460,8 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 	//undefined *puVar3;
 
 	if (newPosition == 1) {
-		_vm->_scene->setBgLayerPriority(1);
-		_vm->_scene->setMgLayerPriority(2);
+		_vm->_scene->setBgLayerPriority(0); //TODO investigate why this is 0 not 1
+		_vm->_scene->setMgLayerPriority(1); //TODO investigate why this is 1 not 2
 		_vm->_scene->_camera.x = sParm2 + 0x3c0;
 		_vm->_scene->setFgLayerPriority(0);
 		//load_palette_into_frame_buffer(0,&SYSTEM_PALETTE_3);


Commit: 235c4464aa3245ef4c54cbbb321f48f551b12827
    https://github.com/scummvm/scummvm/commit/235c4464aa3245ef4c54cbbb321f48f551b12827
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed background palette logic for cut scenes

Changed paths:
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 75c6a72972..317438c508 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -85,15 +85,23 @@ void PriorityLayer::restoreTileMap(int16 x, int16 y, int16 w, int16 h) {
 }
 
 Background::Background() : _priorityLayer(0), _points1(0), _points2(0), _data(0) {
-	_layer[0] = NULL;
-	_layer[1] = NULL;
-	_layer[2] = NULL;
+	_layerSurface[0] = NULL;
+	_layerSurface[1] = NULL;
+	_layerSurface[2] = NULL;
 }
 
 Background::~Background() {
 	if(_data) {
 		delete _data;
 	}
+
+	for (int i = 0; i < 3; i++) {
+		if (_layerSurface[i]) {
+			_layerSurface[i]->free();
+			delete _layerSurface[i];
+		}
+	}
+
 }
 
 bool Background::load(byte *dataStart, uint32 size) {
@@ -143,7 +151,8 @@ bool Background::load(byte *dataStart, uint32 size) {
 	debug("tileIndexOffset: %d", _tileMap[0].tileIndexOffset);
 
 	for(int i = 0; i < 3; i++) {
-		_layer[i] = loadGfxLayer(_tileMap[i], _tileDataOffset);
+		_layerSurface[i] = initGfxLayer(_tileMap[i]);
+		loadGfxLayer(_layerSurface[i], _tileMap[i], _tileDataOffset);
 	}
 
 	layerPriority[0] = 1;
@@ -164,11 +173,14 @@ Common::Point *Background::loadPoints(Common::SeekableReadStream &stream) {
 	return points;
 }
 
-Graphics::Surface *Background::loadGfxLayer(TileMap &tileMap, byte *tiles) {
+Graphics::Surface *Background::initGfxLayer(TileMap &tileMap) {
 	Graphics::Surface *surface = new Graphics::Surface();
 	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
 	surface->create(tileMap.w * TILE_WIDTH, tileMap.h * TILE_HEIGHT, pixelFormat16);
+	return surface;
+}
 
+void Background::loadGfxLayer(Graphics::Surface *surface, TileMap &tileMap, byte *tiles) {
 	for(int y = 0; y < tileMap.h; y++) {
 		for(int x = 0; x < tileMap.w; x++) {
 			uint16 idx = READ_LE_UINT16(&tileMap.map[(y * tileMap.w + x) * 2]) + tileMap.tileIndexOffset;
@@ -176,7 +188,6 @@ Graphics::Surface *Background::loadGfxLayer(TileMap &tileMap, byte *tiles) {
 			drawTileToSurface(surface, _palette, tiles + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
 		}
 	}
-	return surface;
 }
 
 void drawTileToSurface(Graphics::Surface *surface, byte *palette, byte *tile, uint32 x, uint32 y) {
@@ -198,13 +209,13 @@ Common::Point Background::getPoint2(uint32 pointIndex) {
 }
 
 uint16 Background::getWidth() {
-	assert (_layer[0]);
-	return _layer[0]->w;
+	assert (_layerSurface[0]);
+	return _layerSurface[0]->w;
 }
 
 uint16 Background::getHeight() {
-	assert (_layer[0]);
-	return _layer[0]->h;
+	assert (_layerSurface[0]);
+	return _layerSurface[0]->h;
 }
 
 int16 Background::getPriorityAtPoint(Common::Point pos) {
@@ -219,7 +230,7 @@ void Background::overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int
 	for(int i = 0; i < h; i++ ) {
 		for(int j = 0; j < w; j++ ) {
 			int16 idx = READ_LE_UINT16(data) + _tileMap[layerNum].tileIndexOffset;
-			drawTileToSurface(_layer[layerNum],
+			drawTileToSurface(_layerSurface[layerNum],
 					_palette,
 					_tileDataOffset + idx * 0x100,
 					(j + x) * TILE_WIDTH,
@@ -236,7 +247,7 @@ void Background::restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16
 		for(int x = 0; x < tmw; x++) {
 			uint16 idx = READ_LE_UINT16(&_tileMap[layerNum].map[(y * _tileMap[layerNum].w + x) * 2]) + _tileMap[layerNum].tileIndexOffset;
 			//debug("tileIdx: %d", idx);
-			drawTileToSurface(_layer[layerNum], _palette, _tileDataOffset + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
+			drawTileToSurface(_layerSurface[layerNum], _palette, _tileDataOffset + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
 		}
 	}
 }
@@ -249,6 +260,13 @@ void Background::restorePriorityTileMap(int16 x, int16 y, int16 w, int16 h) {
 	_priorityLayer->restoreTileMap(x, y, w, h);
 }
 
+void Background::setPalette(byte *newPalette) {
+	memcpy(_palette, newPalette, 512);
+	for (int i = 0; i < 3; i++) {
+		loadGfxLayer(_layerSurface[i], _tileMap[i], _tileDataOffset);
+	}
+}
+
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
 	bigFileArchive), _dragonRMS(dragonRMS) {}
 
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 0c055873a4..bc35bc45bc 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -58,7 +58,7 @@ private:
 	TileMap _tileMap[4];
 	PriorityLayer *_priorityLayer;
 	byte _palette[512];
-	Graphics::Surface *_layer[3];
+	Graphics::Surface *_layerSurface[3];
 	Common::Point *_points1;
 	Common::Point *_points2;
 	uint8 layerPriority[3];
@@ -70,9 +70,9 @@ public:
 	bool load(byte *dataStart, uint32 size);
 	uint16 getWidth();
 	uint16 getHeight();
-	Graphics::Surface *getBgLayer() { return _layer[0]; }
-	Graphics::Surface *getMgLayer() { return _layer[1]; }
-	Graphics::Surface *getFgLayer() { return _layer[2]; }
+	Graphics::Surface *getBgLayer() { return _layerSurface[0]; }
+	Graphics::Surface *getMgLayer() { return _layerSurface[1]; }
+	Graphics::Surface *getFgLayer() { return _layerSurface[2]; }
 	uint8 getBgLayerPriority() { return layerPriority[0]; }
 	uint8 getMgLayerPriority() { return layerPriority[1]; }
 	uint8 getFgLayerPriority() { return layerPriority[2]; }
@@ -89,10 +89,13 @@ public:
 	void restorePriorityTileMap(int16 x, int16 y, int16 w, int16 h);
 	void overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h);
 	void restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h);
+	void setPalette(byte *newPalette);
 
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
-	Graphics::Surface *loadGfxLayer(TileMap &tileMap, byte *tiles);
+	Graphics::Surface *initGfxLayer(TileMap &tileMap);
+	void loadGfxLayer(Graphics::Surface *surface, TileMap &tileMap, byte *tiles);
+
 };
 
 class PriorityLayer {
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index eeaa0d9069..c1fdcd29cc 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -22,6 +22,7 @@
 #include "cutscene.h"
 #include "dragons.h"
 #include "dragons/actor.h"
+#include "dragons/actorresource.h"
 #include "dragons/background.h"
 #include "dragons/inventory.h"
 #include "dragons/cursor.h"
@@ -32,7 +33,13 @@
 namespace Dragons {
 
 CutScene::CutScene(DragonsEngine *vm): _vm(vm) {
+	loadPalettes();
+}
 
+CutScene::~CutScene() {
+	if (_palettes) {
+		free(_palettes);
+	}
 }
 
 void CutScene::scene1() {
@@ -145,7 +152,7 @@ void CutScene::scene1() {
 																	FUN_8003c108(DAT_80072de8);
 																	FUN_8003c108(DAT_80072dec);
 																	DAT_80063514 = DAT_80063514 & 0xffbf;
-																	closeUpKnightsAtTable(); // close up of knights at table. TODO draw order not right here
+																	closeUpKnightsAtTable(); // close up of knights at table.
 																	_vm->playSound(0x8003);
 																	//playSoundFromTxtIndex(0x5b96);
 																	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,8,4,0x5b96,0xc01) != 2) {
@@ -456,15 +463,12 @@ void CutScene::cursorInventoryClearFlag400() {
 
 void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 {
-	//TODO handle palette changes here.
-	//undefined *puVar3;
-
 	if (newPosition == 1) {
 		_vm->_scene->setBgLayerPriority(0); //TODO investigate why this is 0 not 1
 		_vm->_scene->setMgLayerPriority(1); //TODO investigate why this is 1 not 2
 		_vm->_scene->_camera.x = sParm2 + 0x3c0;
 		_vm->_scene->setFgLayerPriority(0);
-		//load_palette_into_frame_buffer(0,&SYSTEM_PALETTE_3);
+		_vm->_scene->setStagePalette(_palettes + 2 * 512);
 		for (int i = 2; i < 0x17; i++) {
 			Actor *actor = _vm->_actorManager->getActor(i);
 			actor->x_pos += 0x3c0;
@@ -475,14 +479,14 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 			if (newPosition != 0) {
 				return;
 			}
-			//puVar3 = &SYSTEM_PALETTE_1;
+			_vm->_scene->setStagePalette(_palettes + 0 * 512);
 			_vm->_scene->setMgLayerPriority(0);
 			_vm->_scene->setFgLayerPriority(0);
 			_vm->_scene->_camera.x = 0;
 		}
 		else {
 			if (newPosition == 2) {
-				//puVar3 = &SYSTEM_PALETTE_4;
+				_vm->_scene->setStagePalette(_palettes + 3 * 512);
 				_vm->_scene->setMgLayerPriority(2);
 				_vm->_scene->setFgLayerPriority(3);
 				_vm->_scene->_camera.x = 0;
@@ -491,14 +495,13 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 				if (newPosition != 3) {
 					return;
 				}
-				//puVar3 = &SYSTEM_PALETTE_2;
+				_vm->_scene->setStagePalette(_palettes + 1 * 512);
 				_vm->_scene->setMgLayerPriority(2);
 				_vm->_scene->setFgLayerPriority(0);
 				_vm->_scene->_camera.x = sParm2;
 			}
 		}
 		_vm->_scene->setBgLayerPriority(1);
-		//load_palette_into_frame_buffer(0,puVar3);
 	}
 }
 
@@ -508,26 +511,24 @@ void CutScene::diamondScene() {
 	Actor *actorId_01;
 	Actor *actorId_02;
 	Actor *actorId_03;
+	byte palette[512];
 
-//	pDVar4 = dragon_ini_pointer;
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 	actorId = _vm->getINI(0x257)->actor;
 	actorId_03 = _vm->getINI(0x259)->actor;
 	actorId_01 = _vm->getINI(0x258)->actor;
 	actorId_03->setFlag(ACTOR_FLAG_100);
 	actorId_03->priorityLayer = 4;
-//	uVar3 = scrFileData_maybe;
 	actorId_00 = _vm->getINI(0x256)->actor;
-//	uVar2 = *(ushort *)((&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2] + 10);
 	_vm->setFlags(ENGINE_FLAG_20000);
 	actorId_02 = _vm->getINI(0x25a)->actor;
-//	iVar5 = (&actor_dictionary)[(uint)actors[actorId_00].actorFileDictionaryIndex * 2];
 	if ((_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x4294a,0x2601) != 2) && !actorId->actorSetSequenceAndWaitAllowSkip(2)) {
 		actorId->updateSequence(3);
 		if (!actorId_01->actorSetSequenceAndWaitAllowSkip(0x18)) {
 			_vm->waitForFramesAllowSkip(0x2c);
 			//TODO fade_related_calls_with_1f();
-			//TODO load_palette_into_frame_buffer(0,(uint)uVar2 + iVar5);
+			memcpy(palette, _vm->_scene->getPalette(), 512);
+			_vm->_scene->setStagePalette(actorId_00->_actorResource->getPalette());
 			_vm->_scene->_camera.x = 0x140;
 			//TODO call_fade_related_1f();
 			if (!actorId_00->actorSetSequenceAndWaitAllowSkip(0)) {
@@ -535,7 +536,7 @@ void CutScene::diamondScene() {
 				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_00,1,2,0x42a66,0x3c01) != 2) {
 					_vm->waitForFramesAllowSkip(0x13);
 					//TODO fade_related_calls_with_1f();
-					// TODO load_palette_into_frame_buffer(0,uVar3);
+					_vm->_scene->setStagePalette(palette);
 					_vm->_scene->_camera.x = 0;
 					//TODO call_fade_related_1f();
 					actorId_01->updateSequence(0x19);
@@ -561,4 +562,16 @@ void CutScene::diamondScene() {
 	_vm->clearFlags(ENGINE_FLAG_20000);
 }
 
+void CutScene::loadPalettes() {
+	Common::File fd;
+	if (!fd.open("dragon.exe")) {
+		error("Failed to open dragon.exe");
+	}
+	fd.seek(0x5336c); //TODO handle other game variants
+
+	_palettes = (byte *)malloc(256 * 2 * 4);
+	fd.read(_palettes, 256 * 2 * 4);
+}
+
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index 2475f9c5b1..ed66c39d8c 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -50,9 +50,13 @@ private:
 	Actor *DAT_80072e04;
 
 	uint16 DAT_80063514; //flags
+
+	byte *_palettes;
 public:
 	CutScene(DragonsEngine *vm);
 
+	virtual ~CutScene();
+
 	void scene1();
 	void diamondScene();
 
@@ -67,6 +71,7 @@ private:
 	uint16 FUN_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5);
 	void cursorInventoryClearFlag400();
 	void changeBackgroundPosition(uint16 newPosition, int16 sParm2);
+	void loadPalettes();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index e5d19fb30a..7fd0dfa39d 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -29,7 +29,6 @@
 #include "background.h"
 #include "bigfile.h"
 #include "cursor.h"
-#include "cutscene.h"
 #include "dragonflg.h"
 #include "dragonimg.h"
 #include "dragonini.h"
@@ -67,7 +66,6 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_engine = this;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
-	_cutScene = new CutScene(this);
 	_talk = NULL;
 	_sound = new Sound(this);
 	_fontManager = NULL;
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 36912e886f..7fd911f450 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -105,7 +105,6 @@ struct opCode1AStruct {
 class BigfileArchive;
 class BackgroundResourceLoader;
 class Cursor;
-class CutScene;
 class DragonFLG;
 class DragonIMG;
 class DragonOBD;
@@ -139,7 +138,6 @@ public:
 	Cursor *_cursor;
 	Talk *_talk;
 	Sound *_sound;
-	CutScene *_cutScene;
 
 	uint16 unkArray_uint16[42];
 	opCode1AStruct opCode1A_tbl[8];
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index b42241bfe2..75deec76fd 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -436,4 +436,8 @@ void Scene::setFgLayerPriority(uint8 newPriority) {
 	_stage->setFgLayerPriority(newPriority);
 }
 
+void Scene::setStagePalette(byte *newPalette) {
+	_stage->setPalette(newPalette);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 519747dee6..5b4cfbdbf3 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -67,6 +67,7 @@ public:
 	void draw();
 	bool contains(DragonINI *ini);
 	byte *getPalette();
+	void setStagePalette(byte *newPalette);
 	uint16 getSceneId();
 	void setSceneId(int16 newSceneId);
 	Common::Point getPoint(uint32 pointIndex);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index f051f7c893..9ac92df352 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -320,11 +320,15 @@ void SpecialOpcodes::spcSetCameraXToZero() {
 }
 
 void SpecialOpcodes::spcDiamondIntroSequenceLogic() {
-	_vm->_cutScene->diamondScene();
+	CutScene *cutScene = new CutScene(_vm);
+	cutScene->diamondScene();
+	delete cutScene;
 }
 
 void SpecialOpcodes::spcLoadScene1() {
-	_vm->_cutScene->scene1();
+	CutScene *cutScene = new CutScene(_vm);
+	cutScene->scene1();
+	delete cutScene;
 }
 
 void SpecialOpcodes::spcTransitionToMap() {


Commit: 015d68c114dca6bcc9f80403c103fb6c3ad83732
    https://github.com/scummvm/scummvm/commit/015d68c114dca6bcc9f80403c103fb6c3ad83732
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added random function. Cleaned up method names

Changed paths:
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/saveload.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index c1fdcd29cc..5d24fa2848 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -72,15 +72,15 @@ void CutScene::scene1() {
 	closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 	//playSoundFromTxtIndex(0x4e26);
 	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x4e26,0x2e01) != 2) {
-		FUN_8003c108(DAT_80072de8);
+		clearActor(DAT_80072de8);
 		closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); // cut to flicker
 		//playSoundFromTxtIndex(0x4ea2);
 		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x4ea2,0x701) != 2) {
-			FUN_8003c108(DAT_80072de8);
+			clearActor(DAT_80072de8);
 			closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 			//playSoundFromTxtIndex(0x4eec);
 			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x4eec,0x2e01) != 2) {
-				FUN_8003c108(DAT_80072de8);
+				clearActor(DAT_80072de8);
 				wideAngleEveryoneAtTable();  // shot of whole room
 				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5000,0x2e01) != 2 &&
 					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_800830c0,0x1d,0x1c,0x5074,0x501) != 2 &&
@@ -89,14 +89,14 @@ void CutScene::scene1() {
 					closeUpShotOnActor(0xd7, 0, 0x312, 0x260); //close up on flame
 					//playSoundFromTxtIndex(0x5152);
 					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x5152,0x3e01) != 2) {
-						FUN_8003c108(DAT_80072de8);
+						clearActor(DAT_80072de8);
 						closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); //close up flicker
 						//playSoundFromTxtIndex(0x51fc);
 						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x51fc,0x701) != 2) {
 							_vm->playSound(0x8004);
 							_vm->waitForFrames(0x28);
 							_vm->playSound(0x8003);
-							FUN_8003c108(DAT_80072de8);
+							clearActor(DAT_80072de8);
 							DAT_80063514 = DAT_80063514 | 0x40;
 							FUN_8003d8e8(0xd6,0,0x37a,0x280);
 							DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3); //load humans
@@ -114,43 +114,43 @@ void CutScene::scene1() {
 									_vm->_scene->_camera.x = 0;
 									//playSoundFromTxtIndex(0x54dc);
 									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,6,2,0x54dc,0x2e01) != 2) {
-										FUN_8003c108(DAT_80072de8);
-										FUN_8003c108(DAT_80072dec);
-										FUN_8003c108(DAT_80072df0);
+										clearActor(DAT_80072de8);
+										clearActor(DAT_80072dec);
+										clearActor(DAT_80072df0);
 										wideAngleEveryoneAtTable();
 										if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e08,3,2,0x55d4,0xc01) != 2) {
 											closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 											//playSoundFromTxtIndex(0x562c);
 											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x562c,0xc01) != 2) {
-												FUN_8003c108(DAT_80072de8);
+												clearActor(DAT_80072de8);
 												FUN_8003d8e8(0xd6,0,0x37a,0x280);
 												DAT_80072dec = _vm->_actorManager->loadActor(0xd5,4,0x2d6,0xc6,3);
 												_vm->waitForFramesAllowSkip(4);
 												// call_fade_related_1f();
 												if (FUN_8003dab8(0x5780,0x14,0,0xc01,1) != 2) {
 													DAT_80063514 = DAT_80063514 | 0x40;
-													FUN_8003c108(DAT_80072de8);
-													FUN_8003c108(DAT_80072dec);
+													clearActor(DAT_80072de8);
+													clearActor(DAT_80072dec);
 													closeUpShotOnActor(0xd7, 0, 0x312, 0x260); // close up flame
 													//playSoundFromTxtIndex(0x581c);
 													if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x581c,0x3e01) != 2) {
-														FUN_8003c108(DAT_80072de8);
+														clearActor(DAT_80072de8);
 														closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 														//playSoundFromTxtIndex(0x5942);
 														if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x5942,0xc01) != 2) {
-															FUN_8003c108(DAT_80072de8);
+															clearActor(DAT_80072de8);
 															closeUpShotOnActor(0xd3, 2, 0x87, 0); // close up king
 															//playSoundFromTxtIndex(0x5aaa);
 															if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,7,2,0x5aaa,0x2e01) != 2) {
-																FUN_8003c108(DAT_80072de8);
+																clearActor(DAT_80072de8);
 																FUN_8003d8e8(0xd6,0,0x37a,0x280);
 																DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3);
 																_vm->waitForFramesAllowSkip(4);
 																// call_fade_related_1f();
 																//playSoundFromTxtIndex(0x5afc);
 																if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,3,0,0x5afc,0x3c01) != 2) {
-																	FUN_8003c108(DAT_80072de8);
-																	FUN_8003c108(DAT_80072dec);
+																	clearActor(DAT_80072de8);
+																	clearActor(DAT_80072dec);
 																	DAT_80063514 = DAT_80063514 & 0xffbf;
 																	closeUpKnightsAtTable(); // close up of knights at table.
 																	_vm->playSound(0x8003);
@@ -172,13 +172,13 @@ void CutScene::scene1() {
 																				//call_fade_related_1f();
 																				//playSoundFromTxtIndex(0x5ef2);
 																				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5ef2,0x3e01) != 2) {
-																					FUN_8003c108(DAT_80072de8);
-																					FUN_8003c108(DAT_80072dec);
+																					clearActor(DAT_80072de8);
+																					clearActor(DAT_80072dec);
 																					closeUpShotOnActor(0xd3, 0, 0x233,
 																									   0x17a); // close up of king
 																					//playSoundFromTxtIndex(0x6000);
 																					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,8,0,0x6000,0x2e01) != 2) {
-																						FUN_8003c108(DAT_80072de8);
+																						clearActor(DAT_80072de8);
 																						closeUpKnightsAtTable(); // close up knights at table
 																						//playSoundFromTxtIndex(0x7dcc);
 																						DAT_80072df0->updateSequence(0x13);
@@ -342,7 +342,8 @@ void CutScene::scene1() {
 
 }
 
-void CutScene::FUN_8003c108(Actor *actor) {
+//FUN_8003c108
+void CutScene::clearActor(Actor *actor) {
 	// TODO fade_related_calls_with_1f();
 	//DisableVSyncEvent();
 	actor->reset_maybe();
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index ed66c39d8c..dc7ddf364e 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -62,7 +62,7 @@ public:
 
 private:
 	//Scene 1 related functions
-	void FUN_8003c108(Actor *actor);
+	void clearActor(Actor *actor);
 	void closeUpShotOnActor(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4);
 	void FUN_8003d8e8(uint16 resourceId,uint16 sequenceId,int16 x,uint32 param_4);
 	void wideAngleEveryoneAtTable();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 7fd0dfa39d..ea7d2a5ba3 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1039,7 +1039,7 @@ void DragonsEngine::works_with_obd_data_1() {
 			uVar4 = uVar4 | uVar5;
 		}
 		if (((uVar4 & 0xffff) == 0) && ((uVar6 & 0xfffd) == 0)) {
-			FUN_8002931c();
+			_talk->flickerRandomDefaultResponse();
 		}
 	}
 	else {
@@ -1145,24 +1145,6 @@ void DragonsEngine::FUN_80038994() {
 	error("FUN_80038994"); //TODO
 }
 
-void DragonsEngine::FUN_8002931c() {
-
-	DragonINI *flicker = _dragonINIResource->getFlickerRecord();
-	if (flicker && flicker->actor) {
-		flicker->actor->clearFlag(ACTOR_FLAG_10);
-		if (getCurrentSceneId() != 0x2e || !flicker->actor->_actorResource || flicker->actor->_actorResource->_id != 0x91) {
-			flicker->actor->setFlag(ACTOR_FLAG_4);
-		}
-	}
-//TODO
-//	uVar1 = FUN_80023830(9);
-//	local_30 = 0x11;
-//	local_2c = local_280[(uint)DAT_800728b0 * 9 + (uVar1 & 0xffff)];
-//	FlickerTalkMaybe(&local_30);
-
-error("FUN_8002931c"); //TODO
-}
-
 void DragonsEngine::reset_screen_maybe() {
 	data_8006a3a0_flag &= ~0x10;
 	//TODO
@@ -1221,6 +1203,7 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 }
 
 void DragonsEngine::reset() {
+	seedRandom(0x1dd); //TODO should we randomise this better? I got this value from a couple of runs in the emulator
 	_nextUpdatetime = 0;
 	_flags = 0;
 	_unkFlags1 = 0;
@@ -1237,7 +1220,7 @@ void DragonsEngine::reset() {
 	}
 
 	memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
-
+	setSceneUpdateFunction(NULL);
 }
 
 void DragonsEngine::runSceneUpdaterFunction() {
@@ -1251,6 +1234,30 @@ void DragonsEngine::setSceneUpdateFunction(void (*newUpdateFunction)()) {
 	_sceneUpdateFunction = newUpdateFunction;
 }
 
+void DragonsEngine::seedRandom(int32 seed) {
+		_randomState = seed * -0x2b0e2b0f;
+}
+
+uint32 DragonsEngine::shuffleRandState()
+{
+	uint32 returnBit;
+
+	returnBit = _randomState & 1;
+	_randomState = _randomState >> 1 |
+				  (_randomState << 0x1e ^ _randomState ^ _randomState << 0x1d ^ _randomState << 0x1b ^
+						  _randomState << 0x19) & 0x80000000;
+	return returnBit;
+}
+
+uint16 DragonsEngine::getRand(uint16 max) {
+	uint16 rand = 0;
+
+	for (int i = 0; i < 0x10; i++) {
+		rand = shuffleRandState() | rand << i;
+	}
+	return rand % max;
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 7fd911f450..0b660e9ad2 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -163,6 +163,8 @@ private:
 
 	uint16 run_func_ptr_unk_countdown_timer;
 
+	uint32 _randomState;
+
 	// input
 	bool _leftMouseButtonUp;
 	bool _rightMouseButtonUp;
@@ -225,6 +227,7 @@ public:
 	void (*getSceneUpdateFunction())();
 
 	bool checkForActionButtonRelease();
+	uint16 getRand(uint16 max);
 private:
 	bool savegame(const char *filename, const char *description);
 	bool loadgame(const char *filename);
@@ -246,7 +249,8 @@ private:
 	void walkFlickerToObject();
 	void FUN_80038994();
 
-	void FUN_8002931c();
+	void seedRandom(int32 seed);
+	uint32 shuffleRandState();
 };
 
 DragonsEngine *getEngine();
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
index 78685d45ba..456df1fb4f 100644
--- a/engines/dragons/saveload.cpp
+++ b/engines/dragons/saveload.cpp
@@ -128,7 +128,8 @@ bool DragonsEngine::loadgame(const char *filename) {
 	// TODO load game state here. _gameState->read(in);
 	uint16 newSceneId = (uint16)in->readByte();
 	_dragonFLG->loadState(in);
-	_dragonFLG->set(165, true); //TODO check why this is needed to load save games properly.
+	//_dragonFLG->set(165, true); //TODO check why this is needed to load save games properly.
+	_dragonFLG->set(125, false);  //TODO check why this is needed to load save games properly.
 	_dragonVAR->reset();
 
 	_dragonINIResource->reset();
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 9180f40e18..6cec4b4b61 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -115,7 +115,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x16, opUnk16);
 	OPCODE(0x17, opUnk17);
 	OPCODE(0x18, opUnk18);
-
+	OPCODE(0x19, opUnk19);
 	OPCODE(0x1A, opUnk1A);
 	OPCODE(0x1B, opUnk1B);
 	OPCODE(0x1C, opSetActorFlag0x1000);
@@ -786,60 +786,7 @@ void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 	ARG_UINT32(textIndex)
 	// TODO implement me!
 
-    debug("Main actor talk: 0x%04x and text 0x%04x", iniId, textIndex);
-
-	if (textIndex == 0) {
-		return;
-	}
-	Actor *actor = NULL;
-	if (iniId == 0) {
-		//TODO playSoundFromTxtIndex(textIndex);
-		actor = _vm->_dragonINIResource->getFlickerRecord()->actor;
-		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
-			if (_vm->getCurrentSceneId() == 0x32) {
-				_vm->getINI(0x2b1)->actor->updateSequence(2);
-			}
-			else {
-				actor->setFlag(ACTOR_FLAG_2000);
-				if (actor->_sequenceID2 != -1) {
-					actor->updateSequence(actor->_sequenceID2 + 0x10);
-				}
-			}
-		}
-		else {
-			if (actor->_sequenceID == 5) {
-				actor->updateSequence(0x10);
-			}
-		}
-	}
-	// TODO sVar1 = findTextToDtSpeechIndex(textIndex);
-	uint16 dialog[2048];
-	dialog[0] = 0;
-	_vm->_talk->loadText(textIndex, dialog, 2048);
-
-//	pcVar2 = (char *)0x0;
-//	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
-//		pcVar2 = load_string_from_dragon_txt(textIndex,acStack2016);
-//	}
-	_vm->_talk->displayDialogAroundINI(iniId, dialog, textIndex); //TODO need to pass dialog here (pcVar2). not NULL
-	if (iniId == 0) {
-		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
-			if (_vm->getCurrentSceneId() != 0x32) {
-				actor->setFlag(ACTOR_FLAG_4);
-				actor->clearFlag(ACTOR_FLAG_2000);
-				_vm->waitForFrames(1);
-				return;
-			}
-			_vm->getINI(0x2b1)->actor->updateSequence(1);
-
-		}
-		else {
-			if (actor->_sequenceID != 0x10) {
-				return;
-			}
-			actor->updateSequence(5);
-		}
-	}
+	_vm->_talk->talkFromIni(iniId, textIndex);
 }
 
 void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
@@ -1007,8 +954,7 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 					s2 -= s1;
 				} else {
 					if (fieldB == 3) {
-						//TODO s2 = sub_80023830(s1);
-						error("TODO s2 = sub_80023830(s1);");
+						s2 = _vm->getRand(s1);
 					}
 				}
 			}
@@ -1110,6 +1056,20 @@ void ScriptOpcodes::opUnk18(ScriptOpCall &scriptOpCall) {
 	_vm->_talk->displayDialogAroundPoint(dialog,x,y,fieldA,1,field2);
 }
 
+void ScriptOpcodes::opUnk19(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(size);
+
+	if (scriptOpCall._field8 == 3) {
+		ScriptOpCall newCall;
+		newCall._code = scriptOpCall._code;
+		newCall._codeEnd = scriptOpCall._code + size;
+		_vm->_scriptOpcodes->runScript(newCall);
+	}
+	scriptOpCall._code += size;
+
+}
+
 void ScriptOpcodes::opUnk1A(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(index);
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index edffa86604..fd2cbcfecb 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -106,6 +106,7 @@ protected:
 	void opUnk16(ScriptOpCall &scriptOpCall);
 	void opUnk17(ScriptOpCall &scriptOpCall);
 	void opUnk18(ScriptOpCall &scriptOpCall);
+	void opUnk19(ScriptOpCall &scriptOpCall);
 	void opUnk1A(ScriptOpCall &scriptOpCall);
 	void opUnk1B(ScriptOpCall &scriptOpCall);
 	void opSetActorFlag0x1000(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 83e3595715..d23cd01819 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -334,5 +334,75 @@ uint Talk::somethingTextAndSpeechAndAnimRelated(Actor *actor, int16 sequenceId1,
 	return 1; //TODO this should get return value from  displayDialogAroundActor();
 }
 
+void Talk::talkFromIni(uint32 iniId, uint32 textIndex) {
+	debug("Main actor talk: 0x%04x and text 0x%04x", iniId, textIndex);
+
+	if (textIndex == 0) {
+		return;
+	}
+	Actor *actor = NULL;
+	if (iniId == 0) {
+		//TODO playSoundFromTxtIndex(textIndex);
+		actor = _vm->_dragonINIResource->getFlickerRecord()->actor;
+		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
+			if (_vm->getCurrentSceneId() == 0x32) {
+				_vm->getINI(0x2b1)->actor->updateSequence(2);
+			}
+			else {
+				actor->setFlag(ACTOR_FLAG_2000);
+				if (actor->_sequenceID2 != -1) {
+					actor->updateSequence(actor->_sequenceID2 + 0x10);
+				}
+			}
+		}
+		else {
+			if (actor->_sequenceID == 5) {
+				actor->updateSequence(0x10);
+			}
+		}
+	}
+	// TODO sVar1 = findTextToDtSpeechIndex(textIndex);
+	uint16 dialog[2048];
+	dialog[0] = 0;
+	_vm->_talk->loadText(textIndex, dialog, 2048);
+
+//	pcVar2 = (char *)0x0;
+//	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
+//		pcVar2 = load_string_from_dragon_txt(textIndex,acStack2016);
+//	}
+	_vm->_talk->displayDialogAroundINI(iniId, dialog, textIndex); //TODO need to pass dialog here (pcVar2). not NULL
+	if (iniId == 0) {
+		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
+			if (_vm->getCurrentSceneId() != 0x32) {
+				actor->setFlag(ACTOR_FLAG_4);
+				actor->clearFlag(ACTOR_FLAG_2000);
+				_vm->waitForFrames(1);
+				return;
+			}
+			_vm->getINI(0x2b1)->actor->updateSequence(1);
+
+		}
+		else {
+			if (actor->_sequenceID != 0x10) {
+				return;
+			}
+			actor->updateSequence(5);
+		}
+	}
+}
+
+void Talk::flickerRandomDefaultResponse() {
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+	if (flicker && flicker->actor) {
+		flicker->actor->clearFlag(ACTOR_FLAG_10);
+		if (_vm->getCurrentSceneId() != 0x2e || !flicker->actor->_actorResource || flicker->actor->_actorResource->_id != 0x91) {
+			flicker->actor->setFlag(ACTOR_FLAG_4);
+		}
+	}
+	uint16 rand = _vm->getRand(9);
+	//TODO defaultResponseTable[_cursor->data_800728b0_cursor_seqID * 9 + rand];
+	talkFromIni(0x11, 0x1902);
+}
+
 
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index c0115de806..367b2c2ee8 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -58,6 +58,9 @@ public:
 	void loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength);
 	void printWideText(byte *text);
 
+	void talkFromIni(uint32 iniId, uint32 textIndex);
+	void flickerRandomDefaultResponse();
+
 	uint32 displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex);
 	void displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId);
 	void displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex);


Commit: 4bd381242af1115d8864bed95bbb80d825942621
    https://github.com/scummvm/scummvm/commit/4bd381242af1115d8864bed95bbb80d825942621
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added default talk response ids

Changed paths:
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index d23cd01819..4d08a8e51a 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -42,7 +42,8 @@ Talk::Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive): _vm(vm), _bigfile
 }
 
 void Talk::init() {
-
+	memset(defaultResponseTbl, 0, sizeof(defaultResponseTbl));
+	initDefaultResponseTable();
 }
 
 void Talk::loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength) {
@@ -399,9 +400,77 @@ void Talk::flickerRandomDefaultResponse() {
 			flicker->actor->setFlag(ACTOR_FLAG_4);
 		}
 	}
+	talkFromIni(0x11, getDefaultResponseTextIndex());
+}
+
+uint32 Talk::getDefaultResponseTextIndex() {
 	uint16 rand = _vm->getRand(9);
-	//TODO defaultResponseTable[_cursor->data_800728b0_cursor_seqID * 9 + rand];
-	talkFromIni(0x11, 0x1902);
+	return defaultResponseTbl[(_vm->_cursor->data_800728b0_cursor_seqID - 1) * 9 + rand];
+}
+
+uint32_t extractTextIndex(Common::File *fd, uint16_t offset) {
+	fd->seek(0x541b0 + offset * 4);
+	return fd->readUint32LE();
+}
+
+void Talk::initDefaultResponseTable() {
+	Common::File *fd = new Common::File();
+	if (!fd->open("dragon.exe")) {
+		error("Failed to open dragon.exe");
+	}
+
+	defaultResponseTbl[0] = extractTextIndex(fd, 19);
+	defaultResponseTbl[1] = extractTextIndex(fd, 20);
+	defaultResponseTbl[2] = extractTextIndex(fd, 21);
+	defaultResponseTbl[3] = extractTextIndex(fd, 22);
+	defaultResponseTbl[4] = extractTextIndex(fd, 19);
+	defaultResponseTbl[5] = extractTextIndex(fd, 20);
+	defaultResponseTbl[6] = extractTextIndex(fd, 21);
+	defaultResponseTbl[7] = extractTextIndex(fd, 22);
+	defaultResponseTbl[8] = extractTextIndex(fd, 19);
+
+	defaultResponseTbl[9] = extractTextIndex(fd, 0);
+	defaultResponseTbl[10] = extractTextIndex(fd, 1);
+	defaultResponseTbl[11] = extractTextIndex(fd, 2);
+	defaultResponseTbl[12] = extractTextIndex(fd, 3);
+	defaultResponseTbl[13] = extractTextIndex(fd, 4);
+	defaultResponseTbl[14] = extractTextIndex(fd, 5);
+	defaultResponseTbl[15] = extractTextIndex(fd, 2);
+	defaultResponseTbl[16] = extractTextIndex(fd, 3);
+	defaultResponseTbl[17] = extractTextIndex(fd, 4);
+
+	defaultResponseTbl[18] = extractTextIndex(fd, 6);
+	defaultResponseTbl[19] = extractTextIndex(fd, 7);
+	defaultResponseTbl[20] = extractTextIndex(fd, 8);
+	defaultResponseTbl[21] = extractTextIndex(fd, 9);
+	defaultResponseTbl[22] = extractTextIndex(fd, 7);
+	defaultResponseTbl[23] = extractTextIndex(fd, 8);
+	defaultResponseTbl[24] = extractTextIndex(fd, 9);
+	defaultResponseTbl[25] = extractTextIndex(fd, 6);
+	defaultResponseTbl[26] = extractTextIndex(fd, 7);
+
+	defaultResponseTbl[27] = extractTextIndex(fd, 10);
+	defaultResponseTbl[28] = extractTextIndex(fd, 11);
+	defaultResponseTbl[29] = extractTextIndex(fd, 12);
+	defaultResponseTbl[30] = extractTextIndex(fd, 13);
+	defaultResponseTbl[31] = extractTextIndex(fd, 14);
+	defaultResponseTbl[32] = extractTextIndex(fd, 15);
+	defaultResponseTbl[33] = extractTextIndex(fd, 16);
+	defaultResponseTbl[34] = extractTextIndex(fd, 17);
+	defaultResponseTbl[35] = extractTextIndex(fd, 18);
+
+	defaultResponseTbl[36] = extractTextIndex(fd, 23);
+	defaultResponseTbl[37] = extractTextIndex(fd, 24);
+	defaultResponseTbl[38] = extractTextIndex(fd, 25);
+	defaultResponseTbl[39] = extractTextIndex(fd, 26);
+	defaultResponseTbl[40] = extractTextIndex(fd, 27);
+	defaultResponseTbl[41] = extractTextIndex(fd, 28);
+	defaultResponseTbl[42] = extractTextIndex(fd, 29);
+	defaultResponseTbl[43] = extractTextIndex(fd, 30);
+	defaultResponseTbl[44] = extractTextIndex(fd, 31);
+
+	fd->close();
+	delete fd;
 }
 
 
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 367b2c2ee8..dbbc3253e7 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -51,6 +51,7 @@ private:
 	DragonsEngine *_vm;
 	BigfileArchive *_bigfileArchive;
 	Common::List<TalkDialogEntry*> _dialogEntries;
+	uint32 defaultResponseTbl[45];
 
 public:
 	Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive);
@@ -79,6 +80,8 @@ private:
 	uint32 wideStrLen(uint16 *text);
 	TalkDialogEntry *displayTalkDialogMenu();
 	void exitTalkMenu(bool isFlag8Set, bool isFlag100Set);
+	uint32 getDefaultResponseTextIndex();
+	void initDefaultResponseTable();
 };
 
 } // End of namespace Dragons


Commit: c20d288e22478c09d4c47f862981a6006d92536f
    https://github.com/scummvm/scummvm/commit/c20d288e22478c09d4c47f862981a6006d92536f
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: refactored inventory logic into inventory class

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index ea7d2a5ba3..a23d1606d7 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -362,7 +362,6 @@ void DragonsEngine::gameLoop()
 						if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
 							if (_cursor->_iniUnderCursor == 0x8002) {
 								LAB_80027294:
-								uVar7 = 0;
 								if (_cursor->iniItemInHand == 0) {
 									if ((bit_flags_8006fbd8 & 3) != 1) {
 										sequenceId = _dragonVAR->getVar(7);
@@ -372,19 +371,11 @@ void DragonsEngine::gameLoop()
 									}
 								}
 								else {
-									actorId = 0;
-									do {
-										if (unkArray_uint16[actorId] == 0) break;
-										uVar7 = uVar7 + 1;
-										actorId = (uint)uVar7;
-									} while (uVar7 < 0x29);
-									if (uVar7 < 0x29) {
+									if(_inventory->addItem(_cursor->iniItemInHand)) {
 										_cursor->_sequenceID = 1;
 										waitForFrames(1);
-										uVar6 = _cursor->iniItemInHand;
 										_cursor->iniItemInHand = 0;
 										_cursor->_iniUnderCursor = 0;
-										unkArray_uint16[(uint)uVar7] = uVar6;
 										actorId = uVar3;
 										continue;
 									}
@@ -478,7 +469,6 @@ void DragonsEngine::gameLoop()
 				continue;
 			}
 			if (_cursor->_iniUnderCursor != 0) {
-				actorId_00 = 0;
 				if ((_cursor->_sequenceID != 4) && (_cursor->_sequenceID != 2)) {
 					_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
 					_cursor->data_80072890 = _cursor->_iniUnderCursor;
@@ -490,27 +480,19 @@ void DragonsEngine::gameLoop()
 					walkFlickerToObject();
 					goto LAB_8002790c;
 				}
-				if (_cursor->_iniUnderCursor != unkArray_uint16[0]) {
-					actorId = 1;
-					do {
-						actorId_00 = actorId;
-						actorId = actorId_00 + 1;
-					} while (_cursor->_iniUnderCursor != unkArray_uint16[actorId_00 & 0xffff]);
-				}
-				puVar9 = unkArray_uint16 + (actorId_00 & 0xffff);
-				Actor *actor = _actorManager->getActor(actorId_00 + 0x17);
-				*puVar9 = _cursor->iniItemInHand;
+				Actor *actor = _inventory->getInventoryItemActor(_cursor->_iniUnderCursor);
+				uint16 tmpId = _cursor->iniItemInHand;
+				_inventory->replaceItem(_cursor->_iniUnderCursor, _cursor->iniItemInHand);
 				_cursor->data_8007283c = actor->_sequenceID;
 				actor->clearFlag(ACTOR_FLAG_40);
 				_cursor->iniItemInHand = _cursor->_iniUnderCursor;
 				_cursor->_sequenceID = 5;
 				actorId = uVar3;
-				if (*puVar9 != 0) {
-					actorId = actorId_00 + 0x17 & 0xffff;
+				if (tmpId != 0) {
 					actor->flags = 0;
 					actor->priorityLayer = 0;
 					actor->field_e = 0x100;
-					actor->updateSequence(getINI((uint)*puVar9 - 1)->field_8 * 2 + 10);
+					actor->updateSequence(getINI(tmpId - 1)->field_8 * 2 + 10);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);
@@ -520,38 +502,22 @@ void DragonsEngine::gameLoop()
 				}
 				continue;
 			}
-			uVar6 = 0;
 			if (_cursor->iniItemInHand == 0) goto LAB_80027b58;
 			//drop item back into inventory
-			actorId = 0;
-			do {
-				Actor *actor = _actorManager->getActor(actorId + 0x17);
-				if (((((int)(short)actor->x_pos - 0x10 <= (int)_cursor->_x) &&
-					  ((int)_cursor->_x < (int)(short)actor->x_pos + 0x10)) &&
-					 ((int)(short)actor->y_pos - 0xc <= (int)_cursor->_y)) &&
-					(actorId = (uint)uVar6, (int)_cursor->_y < (int)(short)actor->y_pos + 0xc)) {
-					break;
-				}
-				uVar6 = uVar6 + 1;
-				actorId = (uint)uVar6;
-			} while (uVar6 < 0x29);
-			if (actorId != 0x29) {
-				actorId_00 = (uint)(ushort)(uVar6 + 0x17);
-				unkArray_uint16[actorId] = _cursor->iniItemInHand;
-				Actor *actor = _actorManager->getActor(actorId_00);
-				actor->flags = 0;
-				actor->priorityLayer = 0;
-				actor->field_e = 0x100;
+			Actor *invActor = _inventory->addItemIfPositionIsEmpty(_cursor->iniItemInHand, _cursor->_x, _cursor->_y);
+			if (invActor != NULL) {
+				invActor->flags = 0;
+				invActor->priorityLayer = 0;
+				invActor->field_e = 0x100;
+				invActor->updateSequence(
+						 getINI(_cursor->iniItemInHand - 1)->field_8 * 2 + 10);
 				_cursor->iniItemInHand = 0;
-				actor->updateSequence(
-						 getINI((uint)unkArray_uint16[actorId] - 1)->field_8 * 2 + 10);
-				uVar6 = _cursor->_sequenceID;
-				actor->setFlag(ACTOR_FLAG_40);
-				actor->setFlag(ACTOR_FLAG_80);
-				actor->setFlag(ACTOR_FLAG_100);
-				actor->setFlag(ACTOR_FLAG_200);
-				actor->priorityLayer = 6;
-				if (uVar6 == 5) {
+				invActor->setFlag(ACTOR_FLAG_40);
+				invActor->setFlag(ACTOR_FLAG_80);
+				invActor->setFlag(ACTOR_FLAG_100);
+				invActor->setFlag(ACTOR_FLAG_200);
+				invActor->priorityLayer = 6;
+				if (_cursor->_sequenceID == 5) {
 					_cursor->_sequenceID = 4;
 				}
 			}
@@ -1219,7 +1185,6 @@ void DragonsEngine::reset() {
 		opCode1A_tbl[i].field8 = 0;
 	}
 
-	memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
 	setSceneUpdateFunction(NULL);
 }
 
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 0b660e9ad2..fa953407bf 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -139,7 +139,6 @@ public:
 	Talk *_talk;
 	Sound *_sound;
 
-	uint16 unkArray_uint16[42];
 	opCode1AStruct opCode1A_tbl[8];
 
 	uint16 data_800633fc;
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index b28b6ac4c2..dc794472e5 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -160,11 +160,11 @@ void Inventory::openInventory() {
 		item->x_pos = item->target_x_pos = invXPosTable[i] + 0x10;
 		item->y_pos = item->target_y_pos = invYPosTable[i] + 0xc;
 
-		if (_vm->unkArray_uint16[i]) {
+		if (unkArray_uint16[i]) {
 			item->flags = 0; //clear all flags
 			item->field_e = 0x100;
 			item->priorityLayer = 0;
-			item->updateSequence(_vm->getINI(_vm->unkArray_uint16[i] - 1)->field_8 * 2 + 10);
+			item->updateSequence(_vm->getINI(unkArray_uint16[i] - 1)->field_8 * 2 + 10);
 			item->setFlag(ACTOR_FLAG_200);
 			item->setFlag(ACTOR_FLAG_100);
 			item->setFlag(ACTOR_FLAG_80);
@@ -247,11 +247,11 @@ void Inventory::draw() {
 
 uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 	for (int i = 0; i < 0x29; i++) {
-		if (_vm->unkArray_uint16[i]) {
+		if (unkArray_uint16[i]) {
 			Actor *item = _vm->_actorManager->getActor(i + 0x17);
 			if (item->x_pos - 0x10 <= x && x < item->x_pos + 0x10
 				&& item->y_pos - 0xc <= y && y < item->y_pos + 0xc) {
-				return _vm->unkArray_uint16[i];
+				return unkArray_uint16[i];
 			}
 		}
 	}
@@ -259,11 +259,12 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 }
 
 void Inventory::loadInventoryItemsFromSave() {
+	memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
 	int j = 0;
 	for (int i=0; i < _vm->_dragonINIResource->totalRecords() && j < 0x29; i++ ) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId == 1) {
-			_vm->unkArray_uint16[j++] = i + 1;
+			unkArray_uint16[j++] = i + 1;
 		}
 	}
 }
@@ -332,4 +333,56 @@ void Inventory::setPositionFromSceneId(uint32 sceneId) {
 	_actor->y_pos = positionTable[_screenPositionIndex].y;
 }
 
+bool Inventory::addItem(uint16 initId) {
+	for (int i = 0; i < 0x29; i++) {
+		if (unkArray_uint16[i] == 0) {
+			unkArray_uint16[i] = initId;
+			return true;
+		}
+	}
+
+	return false;
+}
+
+Actor *Inventory::getInventoryItemActor(uint16 iniId) {
+	for (int i = 0; i < 0x29; i++) {
+		if (unkArray_uint16[i] == iniId) {
+			return _vm->_actorManager->getActor(i + 0x17);
+		}
+	}
+	error("getInventoryItemActor(%d) not found", iniId);
+}
+
+void Inventory::replaceItem(uint16 existingIniId, uint16 newIniId) {
+	for (int i = 0; i < 0x29; i++) {
+		if (unkArray_uint16[i] == existingIniId) {
+			unkArray_uint16[i] = newIniId;
+			return;
+		}
+	}
+}
+
+Actor *Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
+	for (int i = 0; i < 0x29; i++) {
+		Actor *actor = _vm->_actorManager->getActor(i + 0x17);
+		if ((((actor->x_pos - 0x10 <= x) &&
+			  (x < actor->x_pos + 0x10)) &&
+			 (actor->y_pos - 0xc <= y)) &&
+			(y < actor->y_pos + 0xc)) {
+			unkArray_uint16[i] = iniId;
+			return actor;
+		}
+	}
+	return NULL;
+}
+
+bool Inventory::clearItem(uint16 iniId) {
+	for (int i = 0; i < 0x29; i++) {
+		if(unkArray_uint16[i] == iniId) {
+			unkArray_uint16[i] = 0;
+		}
+	}
+	return false;
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 73a9506223..6cd6e8233c 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -50,6 +50,7 @@ private:
 	uint16 inventionBookPrevFlickerINISceneId;
 	Common::Point inventionBookPrevFlickerINIPosition;
 
+	uint16 unkArray_uint16[42];
 public:
 	Inventory(DragonsEngine *vm);
 
@@ -88,6 +89,14 @@ public:
 
 	void openInventionBook();
 	void closeInventionBook();
+
+	bool addItem(uint16 iniId);
+	Actor *addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y);
+	void replaceItem(uint16 existingIniId, uint16 newIniId);
+	bool clearItem(uint16 iniId);
+
+	Actor *getInventoryItemActor(uint16 iniId);
+
 private:
 	void setPositionFromSceneId(uint32 sceneId);
 	void animateBagIn();
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 6cec4b4b61..4e5d6113e9 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -1176,12 +1176,9 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 				_vm->_cursor->iniItemInHand = 0;
 			}
 			else {
-				for (int i = 0; i < 0x29; i++) {
-					if (_vm->unkArray_uint16[i] - 1 == ini->id) {
-						_vm->unkArray_uint16[i] = 0;
-						if (_vm->_inventory->getType() == 1) {
-							ini->actor->clearFlag(ACTOR_FLAG_40);
-						}
+				if (_vm->_inventory->clearItem(ini->id + 1)) {
+					if (_vm->_inventory->getType() == 1) {
+						ini->actor->clearFlag(ACTOR_FLAG_40);
 					}
 				}
 			}
@@ -1189,19 +1186,13 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 
 		if (sceneId == 1) {
 			if (_vm->_cursor->iniItemInHand != 0) {
-				uint16 freeSlot = 0;
-				for( ;_vm->unkArray_uint16[freeSlot] != 0; freeSlot++) {
-					if (_vm->unkArray_uint16[freeSlot] == 0) {
-						break;
-					}
-				}
-				_vm->unkArray_uint16[freeSlot] = _vm->_cursor->iniItemInHand;
+				_vm->_inventory->addItem(_vm->_cursor->iniItemInHand);
 				if (_vm->_inventory->getType() == 1) {
-					Actor *actor = _vm->_actorManager->getActor(freeSlot + 0x17);
+					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->iniItemInHand);
 					actor->flags = 0;
 					actor->priorityLayer = 0;
 					actor->field_e = 0x100;
-					actor->updateSequence((_vm->getINI(_vm->unkArray_uint16[freeSlot] - 1)->field_8 * 2 + 10) & 0xfffe);
+					actor->updateSequence((_vm->getINI(_vm->_cursor->iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);


Commit: 3f8c1596a42653722b26d72fce4687e8d471edb6
    https://github.com/scummvm/scummvm/commit/3f8c1596a42653722b26d72fce4687e8d471edb6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed crash when moving items in inventory bag

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index a23d1606d7..13b24e99d0 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -504,8 +504,8 @@ void DragonsEngine::gameLoop()
 			}
 			if (_cursor->iniItemInHand == 0) goto LAB_80027b58;
 			//drop item back into inventory
-			Actor *invActor = _inventory->addItemIfPositionIsEmpty(_cursor->iniItemInHand, _cursor->_x, _cursor->_y);
-			if (invActor != NULL) {
+			if (_inventory->addItemIfPositionIsEmpty(_cursor->iniItemInHand, _cursor->_x, _cursor->_y)) {
+				Actor *invActor = _inventory->getInventoryItemActor(_cursor->iniItemInHand);
 				invActor->flags = 0;
 				invActor->priorityLayer = 0;
 				invActor->field_e = 0x100;
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index dc794472e5..0346a0d09f 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -88,8 +88,8 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_old_showing_value = 0;
 	_bag = bag;
 
-	for(int i = 0x17; i < 0x29; i++) {
-		actorManager->loadActor(0, i); // TODO need to share resource between inventory item actors.
+	for(int i = 0; i < 0x29; i++) {
+		actorManager->loadActor(0, i + 0x17); // TODO need to share resource between inventory item actors.
 	}
 
 	loadInventoryItemsFromSave();
@@ -362,7 +362,7 @@ void Inventory::replaceItem(uint16 existingIniId, uint16 newIniId) {
 	}
 }
 
-Actor *Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
+bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 	for (int i = 0; i < 0x29; i++) {
 		Actor *actor = _vm->_actorManager->getActor(i + 0x17);
 		if ((((actor->x_pos - 0x10 <= x) &&
@@ -370,10 +370,10 @@ Actor *Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 			 (actor->y_pos - 0xc <= y)) &&
 			(y < actor->y_pos + 0xc)) {
 			unkArray_uint16[i] = iniId;
-			return actor;
+			return true;
 		}
 	}
-	return NULL;
+	return false;
 }
 
 bool Inventory::clearItem(uint16 iniId) {
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 6cd6e8233c..2d9e49008a 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -91,7 +91,7 @@ public:
 	void closeInventionBook();
 
 	bool addItem(uint16 iniId);
-	Actor *addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y);
+	bool addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y);
 	void replaceItem(uint16 existingIniId, uint16 newIniId);
 	bool clearItem(uint16 iniId);
 


Commit: c8ea9b28637afe1c4391e39d4db630df15a50fa5
    https://github.com/scummvm/scummvm/commit/c8ea9b28637afe1c4391e39d4db630df15a50fa5
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Renamed inventory item table

Changed paths:
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h


diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 0346a0d09f..9f39ab58ff 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -160,11 +160,11 @@ void Inventory::openInventory() {
 		item->x_pos = item->target_x_pos = invXPosTable[i] + 0x10;
 		item->y_pos = item->target_y_pos = invYPosTable[i] + 0xc;
 
-		if (unkArray_uint16[i]) {
+		if (inventoryItemTbl[i]) {
 			item->flags = 0; //clear all flags
 			item->field_e = 0x100;
 			item->priorityLayer = 0;
-			item->updateSequence(_vm->getINI(unkArray_uint16[i] - 1)->field_8 * 2 + 10);
+			item->updateSequence(_vm->getINI(inventoryItemTbl[i] - 1)->field_8 * 2 + 10);
 			item->setFlag(ACTOR_FLAG_200);
 			item->setFlag(ACTOR_FLAG_100);
 			item->setFlag(ACTOR_FLAG_80);
@@ -247,11 +247,11 @@ void Inventory::draw() {
 
 uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 	for (int i = 0; i < 0x29; i++) {
-		if (unkArray_uint16[i]) {
+		if (inventoryItemTbl[i]) {
 			Actor *item = _vm->_actorManager->getActor(i + 0x17);
 			if (item->x_pos - 0x10 <= x && x < item->x_pos + 0x10
 				&& item->y_pos - 0xc <= y && y < item->y_pos + 0xc) {
-				return unkArray_uint16[i];
+				return inventoryItemTbl[i];
 			}
 		}
 	}
@@ -259,12 +259,12 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 }
 
 void Inventory::loadInventoryItemsFromSave() {
-	memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
+	memset(inventoryItemTbl, 0, sizeof(inventoryItemTbl));
 	int j = 0;
 	for (int i=0; i < _vm->_dragonINIResource->totalRecords() && j < 0x29; i++ ) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId == 1) {
-			unkArray_uint16[j++] = i + 1;
+			inventoryItemTbl[j++] = i + 1;
 		}
 	}
 }
@@ -335,8 +335,8 @@ void Inventory::setPositionFromSceneId(uint32 sceneId) {
 
 bool Inventory::addItem(uint16 initId) {
 	for (int i = 0; i < 0x29; i++) {
-		if (unkArray_uint16[i] == 0) {
-			unkArray_uint16[i] = initId;
+		if (inventoryItemTbl[i] == 0) {
+			inventoryItemTbl[i] = initId;
 			return true;
 		}
 	}
@@ -346,7 +346,7 @@ bool Inventory::addItem(uint16 initId) {
 
 Actor *Inventory::getInventoryItemActor(uint16 iniId) {
 	for (int i = 0; i < 0x29; i++) {
-		if (unkArray_uint16[i] == iniId) {
+		if (inventoryItemTbl[i] == iniId) {
 			return _vm->_actorManager->getActor(i + 0x17);
 		}
 	}
@@ -355,8 +355,8 @@ Actor *Inventory::getInventoryItemActor(uint16 iniId) {
 
 void Inventory::replaceItem(uint16 existingIniId, uint16 newIniId) {
 	for (int i = 0; i < 0x29; i++) {
-		if (unkArray_uint16[i] == existingIniId) {
-			unkArray_uint16[i] = newIniId;
+		if (inventoryItemTbl[i] == existingIniId) {
+			inventoryItemTbl[i] = newIniId;
 			return;
 		}
 	}
@@ -369,7 +369,7 @@ bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 			  (x < actor->x_pos + 0x10)) &&
 			 (actor->y_pos - 0xc <= y)) &&
 			(y < actor->y_pos + 0xc)) {
-			unkArray_uint16[i] = iniId;
+			inventoryItemTbl[i] = iniId;
 			return true;
 		}
 	}
@@ -378,8 +378,8 @@ bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 
 bool Inventory::clearItem(uint16 iniId) {
 	for (int i = 0; i < 0x29; i++) {
-		if(unkArray_uint16[i] == iniId) {
-			unkArray_uint16[i] = 0;
+		if(inventoryItemTbl[i] == iniId) {
+			inventoryItemTbl[i] = 0;
 		}
 	}
 	return false;
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 2d9e49008a..990f4f91a9 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -50,7 +50,7 @@ private:
 	uint16 inventionBookPrevFlickerINISceneId;
 	Common::Point inventionBookPrevFlickerINIPosition;
 
-	uint16 unkArray_uint16[42];
+	uint16 inventoryItemTbl[42];
 public:
 	Inventory(DragonsEngine *vm);
 


Commit: d173ea7c5d9630a14e5aba260297cbfe88dfc0ac
    https://github.com/scummvm/scummvm/commit/d173ea7c5d9630a14e5aba260297cbfe88dfc0ac
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Removed some magic numbers

Changed paths:
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 9f39ab58ff..b436bda834 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -31,6 +31,8 @@
 
 namespace Dragons {
 
+#define ACTOR_INVENTORY_OFFSET 0x17
+
 static const Common::Point positionTable[4] = {
 		{2,0},
 		{0xce,0},
@@ -88,8 +90,8 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_old_showing_value = 0;
 	_bag = bag;
 
-	for(int i = 0; i < 0x29; i++) {
-		actorManager->loadActor(0, i + 0x17); // TODO need to share resource between inventory item actors.
+	for(int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
+		actorManager->loadActor(0, i + ACTOR_INVENTORY_OFFSET); // TODO need to share resource between inventory item actors.
 	}
 
 	loadInventoryItemsFromSave();
@@ -154,8 +156,8 @@ void Inventory::openInventory() {
 
 	//TODO 0x800310e0 update cursor position.
 
-	for(int i = 0; i < 0x29; i++) {
-		Actor *item = _vm->_actorManager->getActor(i + 0x17);
+	for(int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
+		Actor *item = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 
 		item->x_pos = item->target_x_pos = invXPosTable[i] + 0x10;
 		item->y_pos = item->target_y_pos = invYPosTable[i] + 0xc;
@@ -216,7 +218,7 @@ void Inventory::animateBagOut() {
 }
 
 void Inventory::closeInventory() {
-	_vm->_actorManager->clearActorFlags(0x17);
+	_vm->_actorManager->clearActorFlags(ACTOR_INVENTORY_OFFSET);
 	_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(_vm->getCurrentSceneId());
 
 	if (!_vm->isFlagSet(ENGINE_FLAG_400000)) {
@@ -246,9 +248,9 @@ void Inventory::draw() {
 }
 
 uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
-	for (int i = 0; i < 0x29; i++) {
+	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		if (inventoryItemTbl[i]) {
-			Actor *item = _vm->_actorManager->getActor(i + 0x17);
+			Actor *item = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 			if (item->x_pos - 0x10 <= x && x < item->x_pos + 0x10
 				&& item->y_pos - 0xc <= y && y < item->y_pos + 0xc) {
 				return inventoryItemTbl[i];
@@ -261,7 +263,7 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 void Inventory::loadInventoryItemsFromSave() {
 	memset(inventoryItemTbl, 0, sizeof(inventoryItemTbl));
 	int j = 0;
-	for (int i=0; i < _vm->_dragonINIResource->totalRecords() && j < 0x29; i++ ) {
+	for (int i=0; i < _vm->_dragonINIResource->totalRecords() && j < DRAGONS_MAX_INVENTORY_ITEMS; i++ ) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId == 1) {
 			inventoryItemTbl[j++] = i + 1;
@@ -334,7 +336,7 @@ void Inventory::setPositionFromSceneId(uint32 sceneId) {
 }
 
 bool Inventory::addItem(uint16 initId) {
-	for (int i = 0; i < 0x29; i++) {
+	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		if (inventoryItemTbl[i] == 0) {
 			inventoryItemTbl[i] = initId;
 			return true;
@@ -345,16 +347,16 @@ bool Inventory::addItem(uint16 initId) {
 }
 
 Actor *Inventory::getInventoryItemActor(uint16 iniId) {
-	for (int i = 0; i < 0x29; i++) {
+	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		if (inventoryItemTbl[i] == iniId) {
-			return _vm->_actorManager->getActor(i + 0x17);
+			return _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 		}
 	}
 	error("getInventoryItemActor(%d) not found", iniId);
 }
 
 void Inventory::replaceItem(uint16 existingIniId, uint16 newIniId) {
-	for (int i = 0; i < 0x29; i++) {
+	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		if (inventoryItemTbl[i] == existingIniId) {
 			inventoryItemTbl[i] = newIniId;
 			return;
@@ -363,8 +365,8 @@ void Inventory::replaceItem(uint16 existingIniId, uint16 newIniId) {
 }
 
 bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
-	for (int i = 0; i < 0x29; i++) {
-		Actor *actor = _vm->_actorManager->getActor(i + 0x17);
+	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
+		Actor *actor = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 		if ((((actor->x_pos - 0x10 <= x) &&
 			  (x < actor->x_pos + 0x10)) &&
 			 (actor->y_pos - 0xc <= y)) &&
@@ -377,7 +379,7 @@ bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 }
 
 bool Inventory::clearItem(uint16 iniId) {
-	for (int i = 0; i < 0x29; i++) {
+	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		if(inventoryItemTbl[i] == iniId) {
 			inventoryItemTbl[i] = 0;
 		}
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 990f4f91a9..52be9009cb 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -34,6 +34,8 @@ class Background;
 class Bag;
 class DragonINIResource;
 
+#define DRAGONS_MAX_INVENTORY_ITEMS 0x29
+
 class Inventory {
 public:
 	int16 _old_showing_value;
@@ -50,7 +52,7 @@ private:
 	uint16 inventionBookPrevFlickerINISceneId;
 	Common::Point inventionBookPrevFlickerINIPosition;
 
-	uint16 inventoryItemTbl[42];
+	uint16 inventoryItemTbl[DRAGONS_MAX_INVENTORY_ITEMS];
 public:
 	Inventory(DragonsEngine *vm);
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 4e5d6113e9..ac52323240 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -839,10 +839,6 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 		_vm->_talk->loadText(textIndex, dialog, 2048);
 	}
 
-	ushort uVar1;
-	int iVar2;
-	uint uVar3;
-
 	DragonINI *ini = iniId == 0 ? _vm->_dragonINIResource->getFlickerRecord() : _vm->getINI(iniId - 1);
 
 	if ((ini->field_1a_flags_maybe & 1) == 0) {


Commit: 7b0c04eb3d6a2833fe2db1607e40a26c34052fa4
    https://github.com/scummvm/scummvm/commit/7b0c04eb3d6a2833fe2db1607e40a26c34052fa4
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on text formatting and dialog menu

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sound.cpp
    engines/dragons/sound.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 636bf8ba86..1a830b3f8c 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -355,4 +355,10 @@ byte *Cursor::getPalette() {
 	return _actor->_actorResource->getPalette();
 }
 
+void Cursor::updateActorPosition(int16 x, int16 y) {
+	updatePosition(x, y);
+	_actor->x_pos = _x + _vm->_scene->_camera.x;
+	_actor->y_pos = _y + _vm->_scene->_camera.y;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 3b274dd26c..24d4246f9d 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -55,6 +55,7 @@ public:
 	void updateSequenceID(int16 sequenceID);
 	void updateVisibility();
 	void updatePosition(int16 x, int16 y);
+	void updateActorPosition(int16 x, int16 y);
 	int16 updateINIUnderCursor();
 	int16 executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag);
 	void selectPreviousCursor();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 13b24e99d0..8088f50009 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -74,6 +74,9 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
 	_iKeyUp = false;
+	_downKeyUp = false;
+	_upKeyUp = false;
+	_enterKeyUp = false;
 	reset();
 }
 
@@ -87,6 +90,9 @@ void DragonsEngine::updateEvents() {
 	_leftMouseButtonUp = false;
 	_rightMouseButtonUp = false;
 	_iKeyUp = false;
+	_downKeyUp = false;
+	_upKeyUp = false;
+	_enterKeyUp = false;
 	while (_eventMan->pollEvent(event)) {
 //		_input->processEvent(event);
 		switch (event.type) {
@@ -105,6 +111,13 @@ void DragonsEngine::updateEvents() {
 			case Common::EVENT_KEYUP:
 				if (event.kbd.keycode == Common::KeyCode::KEYCODE_i) {
 					_iKeyUp = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_DOWN) {
+					_downKeyUp = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_UP) {
+					_upKeyUp = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RETURN ||
+							event.kbd.keycode == Common::KeyCode::KEYCODE_KP_ENTER) {
+					_enterKeyUp = true;
 				}
 			default:
 				break;
@@ -1024,7 +1037,7 @@ bool DragonsEngine::isInputEnabled() {
 }
 
 bool DragonsEngine::checkForActionButtonRelease() {
-	return _leftMouseButtonUp;
+	return _leftMouseButtonUp || _enterKeyUp;
 }
 
 void DragonsEngine::FUN_8003130c() {
@@ -1137,6 +1150,8 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 	_flags |= 0x26;
 	_unkFlags1 = 0;
 
+	clearFlags(ENGINE_FLAG_1000_TEXT_ENABLED); //TODO wire this up to subtitle config.
+
 	_scriptOpcodes->_data_800728c0 = 0; //TODO this should be reset in scriptopcode.
 	_cursor->init(_actorManager, _dragonINIResource);
 	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
@@ -1223,6 +1238,14 @@ uint16 DragonsEngine::getRand(uint16 max) {
 	return rand % max;
 }
 
+bool DragonsEngine::checkForDownKeyRelease() {
+	return _downKeyUp;
+}
+
+bool DragonsEngine::checkForUpKeyRelease() {
+	return _upKeyUp;
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index fa953407bf..90592ebf53 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -168,6 +168,10 @@ private:
 	bool _leftMouseButtonUp;
 	bool _rightMouseButtonUp;
 	bool _iKeyUp;
+	bool _downKeyUp;
+	bool _upKeyUp;
+	bool _enterKeyUp;
+
 	void (*_sceneUpdateFunction)();
 protected:
 	virtual bool hasFeature(EngineFeature f) const;
@@ -226,6 +230,9 @@ public:
 	void (*getSceneUpdateFunction())();
 
 	bool checkForActionButtonRelease();
+	bool checkForDownKeyRelease();
+	bool checkForUpKeyRelease();
+
 	uint16 getRand(uint16 max);
 private:
 	bool savegame(const char *filename, const char *description);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index ac52323240..51c18e090e 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -1211,6 +1211,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 void ScriptOpcodes::loadTalkDialogEntries(ScriptOpCall &scriptOpCall) {
 	scriptOpCall._field8 = 2;
 	scriptOpCall._result = 0;
+	_vm->_talk->clearDialogEntries();
 	_data_80071f5c = 0;
 	executeScriptLoop(scriptOpCall);
 
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index 95daca13b8..dc4401bdb3 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -43,6 +43,7 @@ struct SpeechLocation {
 } SpeechLocation;
 
 Sound::Sound(DragonsEngine *vm): _vm(vm) {
+	DAT_8006bb60_sound_related = 0;
 }
 
 void CdIntToPos_0(uint32 param_1)//, byte *param_2)
@@ -134,6 +135,10 @@ bool Sound::getSpeechLocation(uint32 talkId, struct SpeechLocation *location) {
 	return foundId;
 }
 
+void Sound::PauseCDMusic() {
+	//TODO PauseCDMusic()
+}
+
 Sound::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType) {
 	sector->skip(19);
 	byte format = sector->readByte();
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index 5bd1e62852..18e13fb658 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -36,11 +36,14 @@ class Sound {
 private:
 	DragonsEngine *_vm;
 	Audio::SoundHandle _speechHandle;
+public:
+	uint16 DAT_8006bb60_sound_related;
 
 public:
 	Sound(DragonsEngine *vm);
 	void playSpeech(uint32 textIndex);
 	bool isSpeechPlaying();
+	void PauseCDMusic();
 private:
 	bool getSpeechLocation(uint32 talkId, struct SpeechLocation *location);
 
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 4d08a8e51a..cec640ad04 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -38,12 +38,14 @@
 namespace Dragons {
 
 Talk::Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive): _vm(vm), _bigfileArchive(bigfileArchive) {
-
+	DAT_800726ec_tfont_field0 = 1; //TODO source from font file
+	DAT_800726f0_tfont_field2 = 1; // TODO source from font file
 }
 
 void Talk::init() {
 	memset(defaultResponseTbl, 0, sizeof(defaultResponseTbl));
 	initDefaultResponseTable();
+	DAT_800633f8_talkDialogFlag = 0;
 }
 
 void Talk::loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength) {
@@ -88,17 +90,337 @@ Talk::FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param
 	actor->updateSequence(endSequenceId);
 }
 
-void
-Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
-								 int16 param_7) {
-	//TODO display dialog text here while we wait for audio stream to complete.
-	_vm->_fontManager->addText(x, y, dialogText, wideStrLen(dialogText), 0);
-	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
-		_vm->waitForFrames(1);
-	}
-	_vm->_fontManager->clearText();
-}
+//void Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
+//								 int16 param_7) {
+//	//TODO display dialog text here while we wait for audio stream to complete.
+//	_vm->_fontManager->addText(x, y, dialogText, wideStrLen(dialogText), 0);
+//	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
+//		_vm->waitForFrames(1);
+//	}
+//	_vm->_fontManager->clearText();
+//}
+
+uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
+									  int16 param_7) {
+		uint32_t *puVar1;
+		uint32_t *puVar2;
+		short sVar3;
+		short sVar4;
+		uint16 *tmpTextPtr;
+		int iVar5;
+		int iVar6;
+		int iVar7;
+		int iVar8;
+		uint uVar9;
+		uint uVar10;
+		ushort uVar11;
+		uint32_t uVar12;
+		ushort *puVar13;
+		uint32_t uVar14;
+		uint32_t uVar15;
+		uint32_t *puVar16;
+		uint32_t *puVar17;
+		ushort *dialogTextLinePtr;
+		ushort *puVar18;
+		ushort *curDialogTextPtr;
+		int unaff_s4;
+		ushort uVar19;
+		short sVar20;
+		uint32 maxLineLengthMaybe;
+		uint16 currentLine [44];
+		uint16 asStack2592 [1208];
+		uint32_t local_b0 [14];
+		ushort local_58;
+		ushort returnStatus;
+		byte *lineTblPtr;
+		uint oldEngineFlags;
 
+		bool isFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
+		returnStatus = 0;
+// TODO what does this do?
+//		puVar1 = uint32_t_ARRAY_80011a60;
+//		puVar2 = local_b0;
+//		do {
+//			puVar17 = puVar2;
+//			puVar16 = puVar1;
+//			uVar12 = puVar16[1];
+//			uVar14 = puVar16[2];
+//			uVar15 = puVar16[3];
+//			*puVar17 = *puVar16;
+//			puVar17[1] = uVar12;
+//			puVar17[2] = uVar14;
+//			puVar17[3] = uVar15;
+//			puVar1 = puVar16 + 4;
+//			puVar2 = puVar17 + 4;
+//		} while (puVar16 + 4 != (uint32_t *)&DAT_80011a80);
+//		uVar12 = puVar16[5];
+//		puVar17[4] = _DAT_80011a80;
+//		puVar17[5] = uVar12;
+		if (param_5 != 0) {
+			_vm->clearFlags(ENGINE_FLAG_8);
+		}
+		tmpTextPtr = findCharInU16Str(dialogText,0x5c);
+		while (tmpTextPtr != NULL) {
+			sVar3 = tmpTextPtr[1];
+			*tmpTextPtr = sVar3;
+			while (sVar3 != 0) {
+				sVar3 = tmpTextPtr[2];
+				tmpTextPtr[1] = sVar3;
+				tmpTextPtr = tmpTextPtr + 1;
+			}
+		}
+		iVar5 = (uint)x << 0x10;
+		if ((short)x < 0xf) {
+			x = 0xf;
+			iVar5 = 0xf0000;
+		}
+		if (0x19 < iVar5 >> 0x10) {
+			x = 0x19;
+		}
+		iVar5 = (uint)y << 0x10;
+		if ((int)((uint)y << 0x10) < 0) {
+			y = 0;
+			iVar5 = 0;
+		}
+		if (0x18 < iVar5 >> 0x10) {
+			y = 0x18;
+		}
+		local_58 = x;
+		if (0x13 < (short)x) {
+			local_58 = 0x27 - x;
+		}
+		iVar5 = ((int)((uint)local_58 << 0x10) >> 0xf) + 2;
+//		if (DAT_800726ec_tfont_field0 == 0) {
+//			trap(0x1c00);
+//		}
+//		if (((uint)DAT_800726ec_tfont_field0 == 0xffffffff) && (iVar5 == -0x80000000)) {
+//			trap(0x1800);
+//		}
+		sVar3 = (short)(iVar5 / (int)(uint)DAT_800726ec_tfont_field0);
+		if (*dialogText != 0) {
+			/* check for space or hyphen */
+			curDialogTextPtr = dialogText;
+			do {
+				maxLineLengthMaybe = 0;
+				iVar5 = 0;
+				do {
+					sVar20 = (short)maxLineLengthMaybe;
+					uVar19 = *curDialogTextPtr;
+					iVar6 = iVar5;
+					if (uVar19 == 0) break;
+					while (uVar19 == 0x20) {
+						curDialogTextPtr = curDialogTextPtr + 1;
+						uVar19 = *curDialogTextPtr;
+					}
+					iVar8 = 0;
+					iVar6 = (int)sVar3 + -2;
+					for (unaff_s4 = 0; unaff_s4 < iVar6; unaff_s4++) {
+						currentLine[unaff_s4] = curDialogTextPtr[unaff_s4];
+						if (currentLine[unaff_s4] == 0) {
+							iVar8 = -1;
+							break;
+						}
+					}
+//					unaff_s4 = 0;
+//					if (0 < iVar6) {
+//						iVar7 = 0;
+//						do {
+//							currentLine[unaff_s4] = curDialogTextPtr[unaff_s4];
+//							sVar4 = *(short *)((iVar7 >> 0xf) + (int)curDialogTextPtr);
+//							*(short *)((iVar7 >> 0xf) + (int)currentLine) = sVar4;
+//							if (sVar4 == 0) {
+//								iVar8 = -1;
+//								break;
+//							}
+//							unaff_s4 = unaff_s4 + 1;
+//							iVar7 = unaff_s4 * 0x10000;
+//						} while (unaff_s4 < iVar6);
+//					}
+					iVar6 = iVar5;
+					if ((int)(short)unaff_s4 == 0) break;
+					currentLine[(int)(short)unaff_s4] = 0;
+
+					if (iVar8 == 0) {
+						iVar8 = unaff_s4 - 1;
+						for (; iVar8 >= 0 ; iVar8--) {
+							if (currentLine[iVar8] == 0x20 || currentLine[iVar8] == 0x2d) {
+								break;
+							}
+						}
+						goto LAB_800328f8;
+					}
+//					iVar6 = (iVar8 << 0x10) >> 0x10;
+//					if (iVar8 << 0x10 == 0) {
+//						iVar8 = unaff_s4 + -1;
+//						if (-1 < iVar8 * 0x10000) {
+//							do {
+//								/* check for space or hyphen */
+//								sVar4 = *(short *)(((iVar8 << 0x10) >> 0xf) + (int)currentLine);
+//								if ((sVar4 == 0x20) || (iVar6 = iVar8 + -1, sVar4 == 0x2d)) break;
+//								iVar8 = iVar6;
+//							} while (-1 < iVar6 * 0x10000);
+//							iVar6 = (int)(short)iVar8;
+//							goto LAB_800328f8;
+//						}
+//					}
+					else {
+						LAB_800328f8:
+						if (-1 < iVar8) {
+							if (currentLine[iVar8] == 0x20) {
+								for (; iVar8 >= 0; iVar8--) {
+									if (currentLine[iVar8] != 0x20) {
+										break;
+									}
+									currentLine[iVar8] = 0;
+								}
+
+//								do {
+//									if (*(short *)(((iVar8 << 0x10) >> 0xf) + (int)currentLine) != 0x20) break;
+//									iVar6 = iVar8 + -1;
+//									*(undefined2 *)(((iVar8 << 0x10) >> 0xf) + (int)currentLine) = 0;
+//									iVar8 = iVar6;
+//								} while (-1 < iVar6 * 0x10000);
+							}
+							else {
+								currentLine[iVar8 + 1] = 0;
+							}
+						}
+					}
+
+					iVar6 = iVar5;
+					if (currentLine[0] == 0) break;
+					iVar6 = iVar5 + 1;
+					UTF16ToUTF16Z(asStack2592 + (int)(short)iVar5 * 0x29,currentLine);
+					uVar9 = strlenUTF16(currentLine);
+					if ((int)sVar20 < (int)(uVar9 & 0xffff)) {
+						maxLineLengthMaybe = strlenUTF16(currentLine);
+					}
+					sVar20 = (short)maxLineLengthMaybe;
+					uVar9 = strlenUTF16(currentLine);
+					curDialogTextPtr = curDialogTextPtr + (uVar9 & 0xffff);
+					iVar5 = iVar6;
+				} while (iVar6 * 0x10000 >> 0x10 < 5);
+				sVar4 = (short)iVar6;
+				iVar5 = iVar6 << 0x10;
+				puVar18 = curDialogTextPtr;
+				if (sVar4 == 5) {
+					if (*curDialogTextPtr != 0) {
+						uVar19 = *curDialogTextPtr;
+						puVar13 = curDialogTextPtr;
+						do {
+							if (0x20 < uVar19) break;
+							puVar13 = puVar13 + 1;
+							uVar19 = *puVar13;
+						} while (uVar19 != 0);
+						iVar5 = iVar6 << 0x10;
+						puVar18 = curDialogTextPtr;
+						if (*puVar13 == 0) goto LAB_80032a70;
+						uVar9 = strlenUTF16(currentLine);
+//						curDialogTextPtr = curDialogTextPtr + (uVar9 & 0xffff) * 0x7fffffff; TODO why was this line generated?
+						curDialogTextPtr -= uVar9;
+						iVar6 = iVar6 + -1;
+					}
+					sVar4 = (short)iVar6;
+					iVar5 = iVar6 << 0x10;
+					puVar18 = curDialogTextPtr;
+				}
+				LAB_80032a70:
+				iVar5 = (iVar5 >> 0x10) * (uint)DAT_800726f0_tfont_field2 + -1;
+				uVar19 = y;
+				if ((int)(short)y < iVar5) {
+					uVar19 = (ushort)iVar5;
+				}
+				if (0x16 < (short)uVar19) {
+					uVar19 = 0x16;
+				}
+				uVar11 = sVar20 * DAT_800726ec_tfont_field0 + 3 & 0xfffe;
+				sVar20 = (short)uVar11 >> 1;
+				if ((short)x < 0x14) {
+					DAT_8008e7e8_dialogBox_x1 = (x - sVar20) + 1;
+				}
+				else {
+					DAT_8008e7e8_dialogBox_x1 = x - sVar20;
+				}
+				DAT_8008e848_dialogBox_x2 = (uVar11 + DAT_8008e7e8_dialogBox_x1) - 1;
+				DAT_8008e844_dialogBox_y1 = (uVar19 - sVar4 * DAT_800726f0_tfont_field2) + 1;
+				DAT_8008e874_dialogBox_y2 = DAT_8008e844_dialogBox_y1 + sVar4 * DAT_800726f0_tfont_field2 + 1;
+				if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) && ((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)))) {
+					unaff_s4 = 0;
+					FUN_8001a4e4_draw_dialogbox((uint) DAT_8008e7e8_dialogBox_x1, (uint) DAT_8008e844_dialogBox_y1,
+												(uint) DAT_8008e848_dialogBox_x2, (uint) DAT_8008e874_dialogBox_y2, 0);
+					if (sVar4 > 0) {
+						for (; unaff_s4 < sVar4; unaff_s4++) {
+							if ((short)x < 0x14) {
+								dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
+								uVar9 = strlenUTF16(dialogTextLinePtr);
+								uVar9 = ((uint)x - ((int)((uint)DAT_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1)) + 1;
+							}
+							else {
+								dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
+								uVar9 = strlenUTF16(dialogTextLinePtr);
+								uVar9 = (uint)x - ((int)((uint)DAT_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1);
+							}
+							_vm->_fontManager->addText(uVar9 * 8,
+													   ((uint)DAT_8008e844_dialogBox_y1 + unaff_s4 * (uint)DAT_800726f0_tfont_field2 + 1) * 8,
+									dialogTextLinePtr, wideStrLen(dialogTextLinePtr), 0);
+//							ProbablyShowUTF16Msg3
+//									(dialogTextLinePtr,uVar9 & 0xffff,
+//									 (uint)DAT_8008e844_dialogBox_y1 + iVar5 * (uint)DAT_800726f0_tfont_field2 + 1
+//									 & 0xffff,(uint)param_4, 0xffffffff);
+						}
+					}
+				}
+				if (param_5 == 0) goto LAB_80032efc;
+				uVar9 = ((int)((int)(short)unaff_s4 * (uint)1 * (int)sVar3) >> 3) * 0x3c;
+				if ((param_7 == 0) && _vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED)) {
+					uVar9 = 0;
+				}
+				do {
+					curDialogTextPtr = puVar18;
+					if (!_vm->isFlagSet(ENGINE_FLAG_8000)) goto LAB_80032e18;
+					_vm->waitForFrames(1);
+					if (_vm->_sound->DAT_8006bb60_sound_related != 0) {
+						_vm->_sound->DAT_8006bb60_sound_related = 0;
+						curDialogTextPtr = dialogText;
+						if (!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED)) {
+							returnStatus = 1;
+							goto LAB_80032e18;
+						}
+					}
+					if ((uVar9 & 0xffff) != 0) {
+						uVar9--;
+					}
+					uVar10 = _vm->checkForActionButtonRelease() ? 1 : 0; // CheckButtonMapPress_ActionOrCross(0);
+					curDialogTextPtr = puVar18;
+					if ((uVar10 & 0xffff) != 0) {
+						returnStatus = 1;
+						goto LAB_80032e18;
+					}
+					uVar10 = 0; //TODO PressedThisFrameStart(0);
+				} while ((uVar10 & 0xffff) == 0);
+				returnStatus = 2;
+				curDialogTextPtr = puVar18;
+				LAB_80032e18:
+				//TODO CheckIfCdShellIsOpen();
+				if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
+					FUN_8001a7c4((uint)DAT_8008e7e8_dialogBox_x1,(uint)DAT_8008e844_dialogBox_y1,
+								 (uint)DAT_8008e848_dialogBox_x2,(uint)DAT_8008e874_dialogBox_y2);
+				}
+			} while (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) &&
+					 (((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)) && (*curDialogTextPtr != 0))));
+		}
+		if (param_5 != 0) {
+			if (_vm->isFlagSet(ENGINE_FLAG_8000)) {
+				_vm->_sound->PauseCDMusic();
+			}
+			if (isFlag8Set) {
+				_vm->setFlags(ENGINE_FLAG_8);
+			}
+		}
+		LAB_80032efc:
+		// TODO DAT_800633fc = 0;
+		return (uint)returnStatus;
+}
 
 uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex)
 
@@ -227,7 +549,7 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 	do {
 		callMaybeResetData();
 		int numActiveDialogEntries = 0;
-		for (Common::List<TalkDialogEntry*>::iterator it = _dialogEntries.begin(); it != _dialogEntries.end(); it++) {
+		for (Common::Array<TalkDialogEntry*>::iterator it = _dialogEntries.begin(); it != _dialogEntries.end(); it++) {
 			if (!(*it)->flags & 1) {
 				numActiveDialogEntries++;
 			}
@@ -300,7 +622,195 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 }
 
 TalkDialogEntry *Talk::displayTalkDialogMenu() {
-	return *_dialogEntries.begin();
+	//return *_dialogEntries.begin();
+
+	bool bVar1;
+	short sVar2;
+	uint uVar3;
+	uint uVar4;
+	ushort y;
+	ushort x;
+	uint uVar6;
+	uint uVar7;
+	ushort uVar8;
+	TalkDialogEntry *talkDialogEntry;
+	uint16 local_430 [80];
+	uint16 local_390[5];
+	uint16 local_386 [195];
+	uint16 asStack512 [200];
+	uint16 numEntries;
+	ushort local_60;
+	ushort local_58;
+	short local_50;
+	uint16 *local_40;
+	uint local_38;
+	bool hasDialogEntries;
+	uint16 *DAT_80083104;
+
+	talkDialogEntry = NULL;
+	for (int i = 0; i < 0x24; i++) {
+		local_430[i] = 0x20;
+	}
+	local_430[0x24] = 0;
+
+	uVar8 = 0;
+	local_60 = 0;
+	local_58 = 0;
+	numEntries = _dialogEntries.size();
+	if (numEntries != 0) {
+		uVar3 = 0;
+		do {
+			talkDialogEntry =  _dialogEntries[uVar3];
+			if ((talkDialogEntry->flags & 1) == 0) {
+				local_60 = local_60 + 1;
+				talkDialogEntry->yPosMaybe = '\0';
+				strcpy((char *)&local_390,(char *)talkDialogEntry);
+				UTF16ToUTF16Z(local_386, (uint16 *)(&talkDialogEntry->dialogText[10]));
+				DAT_80083104 = local_386;
+				if (*local_386 == 0x20) {
+					DAT_80083104 = &local_386[1];
+				}
+				uVar3 = FindLastPositionOf5cChar(DAT_80083104);
+				sVar2 = FUN_80031c28(DAT_80083104,asStack512,uVar3 & 0xffff,0x20);
+				talkDialogEntry->xPosMaybe = (uint8_t)local_58;
+				local_58 = local_58 + sVar2;
+				talkDialogEntry->yPosMaybe = talkDialogEntry->yPosMaybe + (char)sVar2;
+			}
+			uVar8 = uVar8 + 1;
+			uVar3 = (uint)uVar8;
+		} while (uVar8 < numEntries);
+	}
+	FUN_8001a4e4_draw_dialogbox(1,0x17 - (uint)local_58 & 0xffff,0x26,0x18,1);
+	uVar8 = 0;
+	_vm->_cursor->updateSequenceID(3);
+	local_50 = -2;
+	local_38 = (uint)numEntries;
+	DAT_800633f8_talkDialogFlag = 1;
+	hasDialogEntries = (numEntries != 0);
+	local_40 = asStack512;
+	LAB_800317a4:
+//		CheckIfCdShellIsOpen();
+	_vm->waitForFrames(1);
+	y = 0;
+	x = 0;
+	if (hasDialogEntries) {
+		uVar3 = 0;
+		do {
+			talkDialogEntry = _dialogEntries[uVar3];
+			if (((talkDialogEntry->flags & 1) == 0) && (bVar1 = y == uVar8, y = y + 1, bVar1)) break;
+			x = x + 1;
+			uVar3 = (uint)x;
+		} while (x < numEntries);
+	}
+	_vm->_cursor->updateActorPosition(0xf, (((ushort)talkDialogEntry->xPosMaybe + 0x18) - local_58) * 8 + 5);
+
+	if (!_vm->isFlagSet(ENGINE_FLAG_8)) {
+		_vm->waitForFrames(1);
+		_vm->setFlags(ENGINE_FLAG_8);
+	}
+	if (local_50 != -2) {
+		if (_vm->checkForActionButtonRelease()) {
+			_vm->playSound(0x800a);
+
+			_vm->clearFlags(ENGINE_FLAG_8);
+			y = 0;
+			callMaybeResetData();
+			if (hasDialogEntries) {
+				uVar3 = 0;
+				do {
+					talkDialogEntry = _dialogEntries[uVar3];
+					y = y + 1;
+					if ((talkDialogEntry->flags & 1) == 0) {
+						if (uVar8 == 0) {
+							DAT_800633f8_talkDialogFlag = 0;
+							return talkDialogEntry;
+						}
+						uVar8--;
+					}
+					uVar3 = (uint)y;
+				} while (y < numEntries);
+			}
+		}
+		if ((uVar8 == 0) || !_vm->checkForUpKeyRelease()) goto LAB_80031970;
+		uVar8--;
+		goto LAB_800319a0;
+	}
+	goto LAB_800319a8;
+	LAB_80031970:
+	if (((int)(uint)uVar8 < (int)((uint)local_60 - 1)) &&
+		_vm->checkForDownKeyRelease()) {
+		uVar8 = uVar8 + 1;
+		LAB_800319a0:
+		_vm->playSound(0x8009);
+		LAB_800319a8:
+		y = 0x18 - local_58;
+		local_50 = -1;
+		uVar3 = 0;
+		if (hasDialogEntries) {
+			uVar6 = 0;
+			do {
+				talkDialogEntry = _dialogEntries[uVar6];
+				uVar6 = (uint)talkDialogEntry->flags & 1;
+				if ((talkDialogEntry->flags & 1) == 0) {
+					sVar2 = local_50 + 1;
+					local_50 = sVar2;
+					UTF16ToUTF16Z(local_390, (uint16 *)(&talkDialogEntry->dialogText[10]));
+					DAT_80083104 = local_390;
+					if (*local_390 == 0x20) {
+						DAT_80083104 = &local_390[1];
+					}
+					uVar4 = FindLastPositionOf5cChar(DAT_80083104);
+					uVar4 = FUN_80031c28(DAT_80083104,local_40,uVar4 & 0xffff,0x20);
+					DAT_80083104 = local_40;
+					if ((int)sVar2 == (uint)uVar8) {
+						uVar7 = 0;
+						if (uVar6 < (uVar4 & 0xffff)) {
+							do {
+								x = 5;
+								if ((uVar7 & 0xffff) == 0) {
+									x = 4;
+								}
+								//TODO ProbablyShowUTF16Msg(DAT_80083104,x,y,0,-1);
+								_vm->_fontManager->addText(x * 8, y * 8, DAT_80083104, wideStrLen(DAT_80083104), 0);
+								sVar2 = *DAT_80083104;
+								while (sVar2 != 0) {
+									sVar2 = DAT_80083104[1];
+									DAT_80083104 = DAT_80083104 + 1;
+								}
+								uVar7 = uVar7 + 1;
+								DAT_80083104 = DAT_80083104 + 1;
+								y = y + 1;
+							} while ((uVar7 & 0xffff) < (uVar4 & 0xffff));
+						}
+					}
+					else {
+						uVar7 = 0;
+						if (uVar6 < (uVar4 & 0xffff)) {
+							do {
+								x = 5;
+								if ((uVar7 & 0xffff) == 0) {
+									x = 4;
+								}
+								//TODO ProbablyShowUTF16Msg2(DAT_80083104,x,(uint)y,0x401,0xffffffff);
+								_vm->_fontManager->addText(x * 8, y * 8, DAT_80083104, wideStrLen(DAT_80083104), 0);
+								sVar2 = *DAT_80083104;
+								while (sVar2 != 0) {
+									sVar2 = DAT_80083104[1];
+									DAT_80083104 = DAT_80083104 + 1;
+								}
+								uVar7 = uVar7 + 1;
+								DAT_80083104 = DAT_80083104 + 1;
+								y = y + 1;
+							} while ((uVar7 & 0xffff) < (uVar4 & 0xffff));
+						}
+					}
+				}
+				uVar3 = uVar3 + 1;
+				uVar6 = uVar3 & 0xffff;
+			} while ((uVar3 & 0xffff) < local_38);
+		}
+	}
+	goto LAB_800317a4;
 }
 
 void Talk::exitTalkMenu(bool isFlag8Set, bool isFlag100Set) {
@@ -473,5 +983,120 @@ void Talk::initDefaultResponseTable() {
 	delete fd;
 }
 
+uint32 Talk::strlenUTF16(uint16 *text) {
+	uint32 i = 0;
+
+	for ( ; text[i] != 0; i++) {
+	}
+	return i;
+}
+
+void Talk::FUN_8001a4e4_draw_dialogbox(uint32 x1, uint32 y1, uint32 x2, uint32 y2, uint16 unk) {
+	//TODO this might be rendering the box under the text.
+	debug("FUN_8001a4e4_draw_dialogbox(%d, %d, %d, %d, %d)", x1, y1, x2, y2, unk);
+}
+
+uint16 *Talk::findCharInU16Str(uint16 *text, uint16 chr) {
+	for ( int i = 0; text[i] != 0; i++) {
+		if (text[i] == chr) {
+			return &text[i];
+		}
+	}
+
+	return NULL;
+}
+
+uint16 *Talk::UTF16ToUTF16Z(uint16 *dest, uint16 *src)
+{
+	uint16 chr;
+	uint16 *ptr;
+
+	chr = *src;
+	src++;
+	ptr = dest + 1;
+	*dest = chr;
+	while (chr != 0) {
+		chr = *src;
+		src++;
+		*ptr = chr;
+		ptr++;
+	}
+	return dest;
+}
+
+void Talk::FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2) {
+	//TODO
+	_vm->_fontManager->clearText();
+}
+
+uint16 Talk::FindLastPositionOf5cChar(uint16 *text) {
+	uint16 len = strlenUTF16(text);
+	for (int i = len - 1; i >= 0; i--) {
+		if (text[i] == 0x5c) {
+			return i + 1;
+		}
+	}
+	return len;
+}
+
+uint32 Talk::FUN_80031c28(uint16 *srcText, uint16 *destText, uint32 cutLength, uint16 param_4) {
+	ushort destCurIndex;
+	ushort uVar1;
+	ushort uVar2;
+	uint srcCurIndex;
+	ushort uVar3;
+	uint uVar4;
+	short chr;
+	bool finished;
+
+	finished = false;
+	uVar3 = 0;
+	srcCurIndex = 0;
+	uVar2 = 0;
+	destCurIndex = 0;
+	uVar4 = 1;
+	do {
+		if ((cutLength & 0xffff) <= (srcCurIndex & 0xffff)) break;
+		chr = srcText[srcCurIndex & 0xffff];
+		destText[(uint)destCurIndex] = chr;
+		uVar2 = uVar2 + 1;
+		if ((chr == 0x5c) || (chr == 0)) {
+			finished = true;
+			uVar1 = destCurIndex;
+			if ((srcText + (srcCurIndex & 0xffff))[1] == 0x5c) {
+				uVar1 = destCurIndex + 3;
+				destText[(uint)destCurIndex] = 0x2e;
+				destText[(uint)(ushort)(destCurIndex + 1)] = 0x2e;
+				destText[(uint)(ushort)(destCurIndex + 2)] = 0x2e;
+			}
+			destCurIndex = uVar1 - 1;
+			uVar1 = uVar3;
+			LAB_80031d3c:
+			uVar3 = uVar1;
+		}
+		else {
+			if (((((chr != 0x20) && (chr != 0x2e)) && (chr != 0x3f)) &&
+				 ((chr != 0x21 && (uVar1 = uVar3, chr != 0x2d)))) ||
+				((uVar1 = uVar3, srcText[(srcCurIndex & 0xffff) + 1] == 0 ||
+								 (uVar1 = destCurIndex, srcText[(srcCurIndex & 0xffff) + 1] != 0x5c)))) goto LAB_80031d3c;
+		}
+		srcCurIndex = srcCurIndex + 1;
+		if ((param_4 < uVar2) && (!finished)) {
+			destText[uVar3] = 0;
+			uVar2 = destCurIndex - uVar3;
+			uVar4 = uVar4 + 1;
+		}
+		destCurIndex = destCurIndex + 1;
+	} while (!finished);
+	destText[(uint)destCurIndex] = 0;
+	return uVar4 & 0xffff;
+}
+
+void Talk::clearDialogEntries() {
+	for (Common::Array<TalkDialogEntry*>::iterator it = _dialogEntries.begin(); it != _dialogEntries.end(); it++) {
+		delete *it;
+	}
+	_dialogEntries.clear();
+}
 
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index dbbc3253e7..0e5de9b1ae 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -50,9 +50,18 @@ class Talk {
 private:
 	DragonsEngine *_vm;
 	BigfileArchive *_bigfileArchive;
-	Common::List<TalkDialogEntry*> _dialogEntries;
+	Common::Array<TalkDialogEntry*> _dialogEntries;
 	uint32 defaultResponseTbl[45];
 
+	uint8 DAT_800726ec_tfont_field0;
+	uint8 DAT_800726f0_tfont_field2;
+
+	uint32 DAT_8008e7e8_dialogBox_x1;
+	uint32 DAT_8008e844_dialogBox_y1;
+	uint32 DAT_8008e848_dialogBox_x2;
+	uint32 DAT_8008e874_dialogBox_y2;
+	uint8 DAT_800633f8_talkDialogFlag;
+
 public:
 	Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive);
 	void init();
@@ -68,9 +77,10 @@ public:
 
 	void FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param_5, Actor *actor, uint16 startSequenceId, uint16 endSequenceId, uint32 textId);
 
-	void conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId, int16 param_7);
+	uint8 conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId, int16 param_7);
 
 	void addTalkDialogEntry(TalkDialogEntry *talkDialogEntry);
+	void clearDialogEntries();
 
 	bool talkToActor(ScriptOpCall &scriptOpCall);
 
@@ -82,6 +92,14 @@ private:
 	void exitTalkMenu(bool isFlag8Set, bool isFlag100Set);
 	uint32 getDefaultResponseTextIndex();
 	void initDefaultResponseTable();
+	uint32 strlenUTF16(uint16 *text);
+	uint16 *findCharInU16Str(uint16 *text, uint16 chr);
+	void FUN_8001a4e4_draw_dialogbox(uint32 x1, uint32 y1, uint32 x2, uint32 y2, uint16 unk);
+	void FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2); //clear box maybe?
+	uint16 *UTF16ToUTF16Z(uint16 *dest, uint16 *src);
+	uint16 FindLastPositionOf5cChar(uint16 *text);
+	uint32 FUN_80031c28(uint16 *srcText, uint16 *destText,uint32 cutLength, uint16 param_4);
+
 };
 
 } // End of namespace Dragons


Commit: f65a55783d08122e5da8c6c582d266b49748694b
    https://github.com/scummvm/scummvm/commit/f65a55783d08122e5da8c6c582d266b49748694b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed font colours. More work on talking to actors

Changed paths:
    engines/dragons/font.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 91c17a573c..4558337e5d 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -186,13 +186,13 @@ void FontManager::loadPalettes() {
 
 //	WRITE_LE_INT16(&_palettes[0x11 * 2], packColor(95, 95, 95));
 	WRITE_LE_INT16(&_palettes[0x10 * 2], packColor(0, 0, 0) | 0x8000);
-	WRITE_LE_INT16(&_palettes[0x11 * 2], packColor(254, 255, 0));
-	WRITE_LE_INT16(&_palettes[0x12 * 2], packColor(95, 95, 95));
+	WRITE_LE_INT16(&_palettes[0x11 * 2], 0x7fe0); //packColor(254, 255, 0));
+	WRITE_LE_INT16(&_palettes[0x12 * 2], 0); //packColor(95, 95, 95));
 	WRITE_LE_INT16(&_palettes[0x13 * 2], packColor(175, 175, 175));
 
 	WRITE_LE_INT16(&_palettes[0x20 * 2], packColor(0, 0, 0) | 0x8000);
-	WRITE_LE_INT16(&_palettes[0x21 * 2], packColor(254, 255, 0));
-	WRITE_LE_INT16(&_palettes[0x22 * 2], packColor(95, 95, 95));
+	WRITE_LE_INT16(&_palettes[0x21 * 2], packColor(175, 175, 175));
+	WRITE_LE_INT16(&_palettes[0x22 * 2], 0);
 	WRITE_LE_INT16(&_palettes[0x23 * 2], packColor(175, 175, 175));
 }
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 51c18e090e..ca6724da79 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -239,7 +239,7 @@ void ScriptOpcodes::opUnk2(ScriptOpCall &scriptOpCall) {
 		//TODO do something here.
 		TalkDialogEntry *talkDialogEntry = new TalkDialogEntry();
 
-		_vm->_talk->loadText(field2, (uint16 *)(&talkDialogEntry->dialogText[10]), 295);
+		talkDialogEntry->hasText = _vm->_talk->loadText(field2, (uint16 *)(&talkDialogEntry->dialogText[10]), 295);
 
 		talkDialogEntry->textIndex = field2;
 		talkDialogEntry->textIndex1 = field6;
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index cec640ad04..0f459f3399 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -48,7 +48,7 @@ void Talk::init() {
 	DAT_800633f8_talkDialogFlag = 0;
 }
 
-void Talk::loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength) {
+bool Talk::loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength) {
 	char filename[13] = "drag0000.txt";
 	uint32 fileNo = (textIndex >> 0xc) & 0xffff;
 	uint32 fileOffset = textIndex & 0xfff;
@@ -60,7 +60,9 @@ void Talk::loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength) {
 	printWideText(data + 10 + fileOffset);
 
 	copyTextToBuffer(textBuffer, data + 10 + fileOffset, bufferLength);
+	bool status = (READ_LE_INT16(data) != 0);
 	delete data;
+	return status;
 }
 
 void Talk::printWideText(byte *text) {
@@ -160,7 +162,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 			_vm->clearFlags(ENGINE_FLAG_8);
 		}
 		tmpTextPtr = findCharInU16Str(dialogText,0x5c);
-		while (tmpTextPtr != NULL) {
+		if (tmpTextPtr != NULL) {
 			sVar3 = tmpTextPtr[1];
 			*tmpTextPtr = sVar3;
 			while (sVar3 != 0) {
@@ -530,8 +532,8 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 	uint iniId;
 	ScriptOpCall local_1d20;
 	short local_990 [5];
-	byte auStack2438 [390];
-	short local_800 [1000];
+	uint16 auStack2438 [195];
+	uint16 local_800 [1000];
 
 	bool isFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
 	bool isFlag100Set = _vm->isFlagSet(ENGINE_FLAG_100);
@@ -567,29 +569,27 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 			return 1;
 		}
 		_vm->clearFlags(ENGINE_FLAG_8);
-		strcpy((char *)local_990,selectedDialogText->dialogText);
-//		UTF16ToUTF16Z(auStack2438,selectedDialogText->dialogText + 10);
+		strcpy((char *)local_990, selectedDialogText->dialogText);
+		UTF16ToUTF16Z(auStack2438,(uint16 *)(selectedDialogText->dialogText + 10));
 //		load_string_from_dragon_txt(selectedDialogText->textIndex1,(char *)local_800);
-//		if (local_990[0] != 0) {
-//			flickerActor->setFlag(ACTOR_FLAG_2000);
-//			sequenceId = flickerActor->_sequenceID;
+		if (selectedDialogText->hasText) {
+			flickerActor->setFlag(ACTOR_FLAG_2000);
+			sequenceId = flickerActor->_sequenceID;
 //			playSoundFromTxtIndex(selectedDialogText->textIndex);
-//			if (flickerActor->_sequenceID2 != -1) {
-//				flickerActor->updateSequence(flickerActor->_sequenceID2 + 0x10);
-//			}
-//			displayDialogAroundINI(0,(uint8_t *)local_990,selectedDialogText->textIndex);
-//			flickerActor->updateSequence(sequenceId);
-//			flickerActor->clearFlag(ACTOR_FLAG_2000);
-//		}
+			if (flickerActor->_sequenceID2 != -1) {
+				flickerActor->updateSequence(flickerActor->_sequenceID2 + 0x10);
+			}
+			displayDialogAroundINI(0, auStack2438, selectedDialogText->textIndex);
+			flickerActor->updateSequence(sequenceId);
+			flickerActor->clearFlag(ACTOR_FLAG_2000);
+		}
 		if ((selectedDialogText->flags & 2) == 0) {
 			selectedDialogText->flags = selectedDialogText->flags | 1;
 		}
 		callMaybeResetData();
-		if (local_800[0] != 0) {
+		if (loadText(selectedDialogText->textIndex1, local_800, 1000)) {
 			if (selectedDialogText->field_26c == -1) {
-//				displayDialogAroundINI
-//						((uint)dragon_ini_index_under_active_cursor,(uint8_t *)local_800,
-//						 selectedDialogText->textIndex1);
+				displayDialogAroundINI(_vm->_cursor->_iniUnderCursor, local_800, selectedDialogText->textIndex1);
 			}
 			else {
 				iniId = _vm->_cursor->_iniUnderCursor; //dragon_ini_index_under_active_cursor;
@@ -599,9 +599,9 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 				Actor *iniActor = _vm->_dragonINIResource->getRecord(iniId - 1)->actor;
 				sequenceId = iniActor->_sequenceID;
 //				playSoundFromTxtIndex(selectedDialogText->textIndex1);
-//				iniActor->updateSequence(selectedDialogText->field_26c);
-//				displayDialogAroundINI(iniId,(uint8_t *)local_800,selectedDialogText->textIndex1);
-//				iniActor->updateSequence(sequenceId);
+				iniActor->updateSequence(selectedDialogText->field_26c);
+				displayDialogAroundINI(iniId, local_800, selectedDialogText->textIndex1);
+				iniActor->updateSequence(sequenceId);
 			}
 		}
 		local_1d20._code = selectedDialogText->scriptCodeStartPtr;
@@ -622,8 +622,6 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 }
 
 TalkDialogEntry *Talk::displayTalkDialogMenu() {
-	//return *_dialogEntries.begin();
-
 	bool bVar1;
 	short sVar2;
 	uint uVar3;
@@ -792,7 +790,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu() {
 									x = 4;
 								}
 								//TODO ProbablyShowUTF16Msg2(DAT_80083104,x,(uint)y,0x401,0xffffffff);
-								_vm->_fontManager->addText(x * 8, y * 8, DAT_80083104, wideStrLen(DAT_80083104), 0);
+								_vm->_fontManager->addText(x * 8, y * 8, DAT_80083104, wideStrLen(DAT_80083104), 1);
 								sVar2 = *DAT_80083104;
 								while (sVar2 != 0) {
 									sVar2 = DAT_80083104[1];
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 0e5de9b1ae..cea64d5bf1 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -43,6 +43,7 @@ struct TalkDialogEntry {
 	uint8 yPosMaybe;
 	int16 field_26c;
 	uint16 iniId;
+	bool hasText;
 };
 
 
@@ -65,7 +66,7 @@ private:
 public:
 	Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive);
 	void init();
-	void loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength);
+	bool loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength);
 	void printWideText(byte *text);
 
 	void talkFromIni(uint32 iniId, uint32 textIndex);


Commit: 52c0f285a043f09f4732ed17254834bdc12912f4
    https://github.com/scummvm/scummvm/commit/52c0f285a043f09f4732ed17254834bdc12912f4
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed bug with sequence animations not reseting to the correct sequenceID. Fixed mem smashing bug with dialog menu

Changed paths:
    engines/dragons/font.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/talk.cpp


diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 4558337e5d..a55b7dcc85 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -69,7 +69,7 @@ Graphics::Surface *Font::render(uint16 *text, uint16 length, byte *palette) {
 	for (int i = 0; i < length; i++) {
 		byte *pixels = (byte *)surface->getPixels();
 		pixels += i * 8 * 2;
-		debug("char: %d size: %d %d", (text[i] - 0x20), _numChars, (30 + i));
+//		debug("char: %d size: %d %d", (text[i] - 0x20), _numChars, (30 + i));
 		byte *data = _pixels + mapChar(text[i]) * 64;
 		for (int y = 0; y < 8; y++) {
 			for (int x = 0; x < 8; x++) {
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 75deec76fd..70b58a44ab 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -101,7 +101,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 		 ((sceneIdStripped == 0x19 || ((sceneIdStripped == 0x34 || (sceneIdStripped == 0x1d)))
 		 ))) || (sceneIdStripped == 0x6)) {
 //		buf2048bytes = buf2048bytes + 0x1800;
-		error("0x8002f404"); //TODO do we need this logic?
+		// error("0x8002f404"); //TODO do we need this logic?
 	}
 
 	if (!(sceneId & 0x8000)) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index ca6724da79..efa6b16b97 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -119,7 +119,8 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x1A, opUnk1A);
 	OPCODE(0x1B, opUnk1B);
 	OPCODE(0x1C, opSetActorFlag0x1000);
-
+	OPCODE(0x1D, opUnk1DClearActorFlag0x400);
+	OPCODE(0x1E, opUnk1ESetActorFlag0x400);
 	OPCODE(0x1F, opPlayMusic);
 	OPCODE(0x20, opUnk20);
 
@@ -672,8 +673,8 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 
 		if (field4 != field6) {
 			ini->actor->field_7c = field4;
+			ini->actor->updateSequence(field6 & 0x7fff);
 		}
-		ini->actor->updateSequence(field6 & 0x7fff);
 	}
 }
 
@@ -1103,6 +1104,30 @@ void ScriptOpcodes::opUnk1B(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opUnk1DClearActorFlag0x400(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(iniId);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	DragonINI *ini = _vm->getINI(iniId - 1);
+	ini->actor->setFlag(ACTOR_FLAG_400);
+}
+
+void ScriptOpcodes::opUnk1ESetActorFlag0x400(ScriptOpCall &scriptOpCall) {
+	ARG_SKIP(2);
+	ARG_INT16(iniId);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
+
+	DragonINI *ini = _vm->getINI(iniId - 1);
+	ini->actor->setFlag(ACTOR_FLAG_400);
+}
+
 void ScriptOpcodes::opSetActorFlag0x1000(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(iniId);
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index fd2cbcfecb..5457ea83b4 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -109,6 +109,8 @@ protected:
 	void opUnk19(ScriptOpCall &scriptOpCall);
 	void opUnk1A(ScriptOpCall &scriptOpCall);
 	void opUnk1B(ScriptOpCall &scriptOpCall);
+	void opUnk1DClearActorFlag0x400(ScriptOpCall &scriptOpCall);
+	void opUnk1ESetActorFlag0x400(ScriptOpCall &scriptOpCall);
 	void opSetActorFlag0x1000(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
 	void opUnk20(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 0f459f3399..ca095e44cf 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -662,7 +662,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu() {
 			if ((talkDialogEntry->flags & 1) == 0) {
 				local_60 = local_60 + 1;
 				talkDialogEntry->yPosMaybe = '\0';
-				strcpy((char *)&local_390,(char *)talkDialogEntry);
+				strcpy((char *)&local_390,(char *)talkDialogEntry->dialogText);
 				UTF16ToUTF16Z(local_386, (uint16 *)(&talkDialogEntry->dialogText[10]));
 				DAT_80083104 = local_386;
 				if (*local_386 == 0x20) {
@@ -752,10 +752,10 @@ TalkDialogEntry *Talk::displayTalkDialogMenu() {
 				if ((talkDialogEntry->flags & 1) == 0) {
 					sVar2 = local_50 + 1;
 					local_50 = sVar2;
-					UTF16ToUTF16Z(local_390, (uint16 *)(&talkDialogEntry->dialogText[10]));
-					DAT_80083104 = local_390;
-					if (*local_390 == 0x20) {
-						DAT_80083104 = &local_390[1];
+					UTF16ToUTF16Z(local_386, (uint16 *)(&talkDialogEntry->dialogText[10]));
+					DAT_80083104 = local_386;
+					if (local_386[0] == 0x20) {
+						DAT_80083104 = &local_386[1];
 					}
 					uVar4 = FindLastPositionOf5cChar(DAT_80083104);
 					uVar4 = FUN_80031c28(DAT_80083104,local_40,uVar4 & 0xffff,0x20);


Commit: 59b26b78f51aad6f70df532794c9e739fb7fc18a
    https://github.com/scummvm/scummvm/commit/59b26b78f51aad6f70df532794c9e739fb7fc18a
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed bug when attempting some actions. More work on special
opcodes

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 8088f50009..f43d4fd44b 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -326,7 +326,7 @@ void DragonsEngine::gameLoop()
 				}
 			}
 
-			works_with_obd_data_1();
+			performAction();
 			if ((getCurrentSceneId() == 0x1d) && (getINI(0x179)->field_2 != 0))
 			{
 				clearFlags(ENGINE_FLAG_8);
@@ -956,7 +956,7 @@ void DragonsEngine::call_fade_related_1f() {
 	fade_related(0x1f);
 }
 
-void DragonsEngine::works_with_obd_data_1() {
+void DragonsEngine::performAction() {
 	uint uVar1;
 	ushort uVar2;
 	uint uVar4;
@@ -987,9 +987,9 @@ void DragonsEngine::works_with_obd_data_1() {
 	uVar4 = _cursor->executeScript(local_48, 1);
 	if (_cursor->data_800728b0_cursor_seqID > 4) {
 		_scriptOpcodes->_data_80071f5c = 0;
-		_scriptOpcodes->_data_800728c0 = _cursor->data_80072890;
 
 		obd = _dragonOBD->getFromOpt(_scriptOpcodes->_data_800728c0 - 1);
+		_scriptOpcodes->_data_800728c0 = _cursor->data_80072890;
 
 		local_38._code = obd + 8;
 		local_38._codeEnd = local_38._code + READ_LE_UINT32(obd);
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 90592ebf53..fe066bdff9 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -217,7 +217,7 @@ public:
 	void fade_related(uint32 flags);
 
 	uint16 ipt_img_file_related();
-	void works_with_obd_data_1();
+	void performAction();
 
 	void reset_screen_maybe();
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index efa6b16b97..fa75c05412 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -319,7 +319,7 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	_vm->_cursor->data_800728b0_cursor_seqID = _vm->_cursor->_sequenceID;
 	_vm->_cursor->data_80072890 = _vm->_cursor->_iniUnderCursor;
 //	EnableVSyncEvent();
-	_vm->works_with_obd_data_1();
+	_vm->performAction();
 	if (isEngineFlag8Set) {
 		_vm->setFlags(ENGINE_FLAG_8);
 	}
@@ -980,6 +980,8 @@ uint16 ScriptOpcodes::getINIField(uint32 iniIndex, uint16 fieldOffset) {
 		case 0x16 : return ini->x;
 		case 0x18 : return ini->y;
 		case 0x1A : return ini->field_1a_flags_maybe;
+		case 0x1C : return ini->field_1c;
+		case 0x1E : return ini->field_1e;
 		case 0x20 : return ini->field_20_actor_field_14;
 		default: error("getINIField() Invalid fieldOffset 0x%X", fieldOffset);
 	}
@@ -1000,6 +1002,8 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 		case 0x16 : ini->x = value; break;
 		case 0x18 : ini->y = value; break;
 		case 0x1A : ini->field_1a_flags_maybe = value; break;
+		case 0x1C : ini->field_1c = value; break;
+		case 0x1E : ini->field_1e = value; break;
 		case 0x20 : ini->field_20_actor_field_14 = value; break;
 		default: error("setINIField() Invalid fieldOffset 0x%X", fieldOffset);
 	}
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 9ac92df352..a6d2f66c55 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -71,7 +71,7 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(9, spcUnk9);
 	OPCODE(0xa, spcUnkA);
-
+	OPCODE(0xb, clearSceneUpdateFunction);
 	OPCODE(0xc, spcUnkC);
 
 	OPCODE(0x12, spcHandleInventionBookTransition);
@@ -79,6 +79,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x14, spcClearEngineFlag8);
 	OPCODE(0x15, spcSetEngineFlag8);
 
+	OPCODE(0x18, clearSceneUpdateFunction);
+
 	OPCODE(0x1a, spcActivatePizzaMakerActor);
 	OPCODE(0x1b, spcDeactivatePizzaMakerActor);
 	OPCODE(0x1c, spcPizzaMakerActorStopWorking);
@@ -92,6 +94,9 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0x3b, spcSetEngineFlag0x2000000);
 	OPCODE(0x3c, spcClearEngineFlag0x2000000);
+	OPCODE(0x3d, clearSceneUpdateFunction);
+	OPCODE(0x3e, spcZigmondFraudSceneLogic);
+	OPCODE(0x3f, clearSceneUpdateFunction);
 
 	OPCODE(0x49, spcLoadScene1);
 
@@ -228,6 +233,10 @@ void SpecialOpcodes::spcClearEngineFlag0x2000000() {
 	_vm->clearFlags(Dragons::ENGINE_FLAG_2000000);
 }
 
+void SpecialOpcodes::spcZigmondFraudSceneLogic() {
+	//TODO
+}
+
 void SpecialOpcodes::spcUnk4e() {
 	panCamera(1);
 }
@@ -383,6 +392,17 @@ void SpecialOpcodes::pizzaMakerStopWorking() {
 	}
 }
 
+void SpecialOpcodes::clearSceneUpdateFunction() {
+	//TODO
+//	if (DAT_80083148 != DAT_80083154) {
+//		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
+//	}
+//	if (DAT_8006f3a4 != 0xffff) {
+//		actor_update_sequenceID((uint)dragon_ini_pointer[(uint)DAT_80069630].actorId,DAT_8006f3a4);
+//	}
+	_vm->setSceneUpdateFunction(NULL);
+}
+
 void pizzaUpdateFunction() {
 		static int16 DAT_800634bc = 0;
 		DragonsEngine *vm = getEngine();
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 907aac69e2..2b7ddd6a8d 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -76,6 +76,8 @@ protected:
 	void spcSetEngineFlag0x2000000(); // 0x3b
 	void spcClearEngineFlag0x2000000(); // 0x3c
 
+	void spcZigmondFraudSceneLogic(); // 0x3e
+
 	void spcLoadScene1(); // 0x49
 
 	void spcUnk4e();
@@ -102,6 +104,8 @@ private:
 	void panCamera(int16 mode);
 	void pizzaMakerStopWorking();
 
+	void clearSceneUpdateFunction();
+
 };
 
 // update functions


Commit: 8f37b37e24dadfb21cab725dbb7bfd533f3eb1cc
    https://github.com/scummvm/scummvm/commit/8f37b37e24dadfb21cab725dbb7bfd533f3eb1cc
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on table based scene update function

Changed paths:
    engines/dragons/scriptopcodes.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h
    engines/dragons/talk.cpp


diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 5457ea83b4..5c713f664d 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -69,10 +69,10 @@ public:
 
 	int16 _data_80071f5c;
 	int16 _data_800728c0;
+	SpecialOpcodes *_specialOpCodes;
 protected:
 	DragonsEngine *_vm;
 	DragonFLG *_dragonFLG;
-	SpecialOpcodes *_specialOpCodes;
 	ScriptOpcode *_opcodes[DRAGONS_NUM_SCRIPT_OPCODES];
 	Common::String _opcodeNames[DRAGONS_NUM_SCRIPT_OPCODES];
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index a6d2f66c55..aeccf18723 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -69,6 +69,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(3, spcClearEngineFlag10);
 	OPCODE(4, spcSetEngineFlag10);
 
+	OPCODE(8, spcCastleGardenLogic);
 	OPCODE(9, spcUnk9);
 	OPCODE(0xa, spcUnkA);
 	OPCODE(0xb, clearSceneUpdateFunction);
@@ -79,6 +80,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x14, spcClearEngineFlag8);
 	OPCODE(0x15, spcSetEngineFlag8);
 
+	OPCODE(0x17, spcKnightPoolReflectionLogic);
 	OPCODE(0x18, clearSceneUpdateFunction);
 
 	OPCODE(0x1a, spcActivatePizzaMakerActor);
@@ -97,6 +99,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x3d, clearSceneUpdateFunction);
 	OPCODE(0x3e, spcZigmondFraudSceneLogic);
 	OPCODE(0x3f, clearSceneUpdateFunction);
+	OPCODE(0x40, spcZigmondFraudSceneLogic1);
 
 	OPCODE(0x49, spcLoadScene1);
 
@@ -114,6 +117,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x5e, spcUnk5e);
 	OPCODE(0x5f, spcUnk5f);
 
+	OPCODE(0x66, spcUnk66);
+
 	OPCODE(0x6b, spcTransitionToMap);
 	OPCODE(0x6c, spcTransitionFromMap);
 
@@ -140,6 +145,10 @@ void SpecialOpcodes::spcSetEngineFlag10() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_10);
 }
 
+void SpecialOpcodes::spcCastleGardenLogic() {
+	//TODO
+}
+
 void SpecialOpcodes::spcUnk9() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	assert(flicker);
@@ -190,6 +199,10 @@ void SpecialOpcodes::spcSetEngineFlag8() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_8);
 }
 
+void SpecialOpcodes::spcKnightPoolReflectionLogic() {
+	//TODO
+}
+
 void SpecialOpcodes::spcActivatePizzaMakerActor() {
 	_vm->setSceneUpdateFunction(pizzaUpdateFunction);
 }
@@ -235,6 +248,56 @@ void SpecialOpcodes::spcClearEngineFlag0x2000000() {
 
 void SpecialOpcodes::spcZigmondFraudSceneLogic() {
 	//TODO
+	sceneUpdater.numSteps[0] = 2;
+	sceneUpdater.numSteps[1] = 2;
+	sceneUpdater.numSteps[2] = 1;
+	sceneUpdater.numSteps[3] = 1;
+	sceneUpdater.numSteps[4] = 2;
+	sceneUpdater.numSteps[5] = 2;
+	sceneUpdater.numSteps[6] = 2;
+	sceneUpdater.numSteps[7] = 2;
+
+	sceneUpdater.iniIDTbl[0][0] = 0x19E;
+	sceneUpdater.iniIDTbl[0][1] = 0x197;
+	sceneUpdater.iniIDTbl[1][0] = 0x19E;
+	sceneUpdater.iniIDTbl[1][1] = 0x197;
+	sceneUpdater.iniIDTbl[2][0] = 0x197;
+	sceneUpdater.iniIDTbl[3][0] = 0x19e;
+	sceneUpdater.iniIDTbl[4][0] = 0x197;
+	sceneUpdater.iniIDTbl[4][1] = 0x19e;
+	sceneUpdater.iniIDTbl[5][0] = 0x19e;
+	sceneUpdater.iniIDTbl[5][1] = 0x197;
+	sceneUpdater.iniIDTbl[6][0] = 0x197;
+	sceneUpdater.iniIDTbl[6][1] = 0x19e;
+	sceneUpdater.iniIDTbl[7][0] = 0x19e;
+	sceneUpdater.iniIDTbl[7][1] = 0x197;
+
+	sceneUpdater.sequenceIDTbl[0][0] = 2;
+	sceneUpdater.sequenceIDTbl[0][1] = 0xe;
+	sceneUpdater.sequenceIDTbl[1][0] = 2;
+	sceneUpdater.sequenceIDTbl[1][1] = 0xe;
+	sceneUpdater.sequenceIDTbl[2][0] = 0xe;
+	sceneUpdater.sequenceIDTbl[3][0] = 2;
+	sceneUpdater.sequenceIDTbl[4][0] = 0xe;
+	sceneUpdater.sequenceIDTbl[4][1] = 2;
+	sceneUpdater.sequenceIDTbl[5][0] = 2;
+	sceneUpdater.sequenceIDTbl[5][1] = 0xe;
+	sceneUpdater.sequenceIDTbl[6][0] = 0xe;
+	sceneUpdater.sequenceIDTbl[6][1] = 2;
+	sceneUpdater.sequenceIDTbl[7][0] = 2;
+	sceneUpdater.sequenceIDTbl[7][1] = 0xe;
+
+	//TODO field4
+	setupTableBasedSceneUpdateFunction(0x168,8,0xb4);
+}
+
+void SpecialOpcodes::spcZigmondFraudSceneLogic1() {
+	sceneUpdater.numSteps[0] = 1;
+	sceneUpdater.iniIDTbl[0][0] = 0x197;
+	sceneUpdater.sequenceIDTbl[0][0] = 0x12;
+	sceneUpdater.textTbl[0][0] = 0x2F422; //TODO this might change between game versions
+
+	setupTableBasedSceneUpdateFunction(300,1,0x708);
 }
 
 void SpecialOpcodes::spcUnk4e() {
@@ -291,6 +354,20 @@ void SpecialOpcodes::spcUnk5f() {
 	panCamera(2);
 }
 
+void SpecialOpcodes::spcUnk66() {
+	uint16 var =_vm->getVar(2);
+
+	uint16 bVar1 = (var & 1) == 0;
+	uint16 uVar9 = bVar1;
+	if ((var & 4) == 0) {
+		uVar9 = (ushort)bVar1 + 1;
+	}
+	if ((var & 2) == 0) {
+		uVar9 = uVar9 + 1;
+	}
+	_vm->getINI(1)->field_12 = uVar9;
+}
+
 // 0x80038c1c
 void SpecialOpcodes::panCamera(int16 mode) {
 	int iVar1;
@@ -403,6 +480,24 @@ void SpecialOpcodes::clearSceneUpdateFunction() {
 	_vm->setSceneUpdateFunction(NULL);
 }
 
+void SpecialOpcodes::setupTableBasedSceneUpdateFunction(uint16 initialCounter, uint16 numSequences,
+														uint16 sequenceDuration) {
+	sceneUpdater.sequenceID = -1;
+//TODO
+//	DAT_80083154 = 0;
+//	DAT_80083148 = 0;
+//	DAT_80072858 = 0;
+	sceneUpdater.curSequenceIndex = 0;
+	sceneUpdater.numTotalSequences = numSequences;
+	sceneUpdater.curSequence = _vm->getRand(numSequences);
+	sceneUpdater.sequenceDuration = sequenceDuration;
+	sceneUpdater.counter = initialCounter;
+
+	//TODO
+
+	_vm->setSceneUpdateFunction(tableBasedSceneUpdateFunction);
+}
+
 void pizzaUpdateFunction() {
 		static int16 DAT_800634bc = 0;
 		DragonsEngine *vm = getEngine();
@@ -447,7 +542,43 @@ void pizzaUpdateFunction() {
 		else {
 			DAT_800634bc--;
 		}
-		return;
+}
+
+void tableBasedSceneUpdateFunction() {
+	uint uVar3;
+	DragonsEngine *vm = getEngine();
+	SpecialOpcodes *spc = vm->_scriptOpcodes->_specialOpCodes;
+
+	uVar3 = (uint)spc->sceneUpdater.curSequence;
+	if (!vm->isFlagSet(ENGINE_FLAG_8000) || vm->data_800633fc == 1) {
+		if (spc->sceneUpdater.sequenceID != -1) {
+			vm->getINI(spc->sceneUpdater.iniID)->actor->updateSequence(spc->sceneUpdater.sequenceID);
+			spc->sceneUpdater.sequenceID = -1;
+		}
+		if (vm->data_800633fc == 0) {
+			spc->sceneUpdater.counter--;
+			if (spc->sceneUpdater.counter == 0) {
+				spc->sceneUpdater.sequenceID = spc->sceneUpdater.sequenceIDTbl[uVar3][spc->sceneUpdater.curSequenceIndex]; //*(int16_t *) (sceneUpdateSequenceTbl[uVar3].sequenceIdPtr + (uint) spc->sceneUpdater.curSequenceIndex);
+				spc->sceneUpdater.iniID = spc->sceneUpdater.iniIDTbl[uVar3][spc->sceneUpdater.curSequenceIndex] - 1;
+//						*(short *) (sceneUpdateSequenceTbl[uVar3].iniIdPtr + (uint) spc->sceneUpdater.curSequenceIndex) -
+//						1;
+				if (spc->sceneUpdater.sequenceID != -1) {
+					Actor *actor = vm->getINI(spc->sceneUpdater.iniID)->actor;
+					uint16 originalSequenceID = actor->_sequenceID;
+					actor->updateSequence(spc->sceneUpdater.sequenceID);
+					spc->sceneUpdater.sequenceID = originalSequenceID;
+				}
+				//TODO FUN_80036a68((&DAT_800832d8)[sceneUpdateSequenceTbl[uVar3].field_0x4[(uint) spc->sceneUpdater.curSequenceIndex]]);
+				spc->sceneUpdater.curSequenceIndex++;
+				spc->sceneUpdater.counter = 0x1e;
+				if (spc->sceneUpdater.numSteps[uVar3] <= (uint) spc->sceneUpdater.curSequenceIndex) {
+					spc->sceneUpdater.curSequenceIndex = 0;
+					spc->sceneUpdater.curSequence = vm->getRand((uint) spc->sceneUpdater.numTotalSequences);
+					spc->sceneUpdater.counter = spc->sceneUpdater.sequenceDuration;
+				}
+			}
+		}
+	}
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 2b7ddd6a8d..9f2f002a88 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -40,11 +40,28 @@ public:
 	SpecialOpcodes(DragonsEngine *vm);
 	~SpecialOpcodes();
 	void run(int16 opcode);
+
+	struct {
+		void *tbl;
+		uint16 counter;
+		int16 iniID;
+		int16 sequenceID;
+		uint32 curSequence;
+		uint32 curSequenceIndex;
+		uint32 numTotalSequences;
+		uint32 sequenceDuration;
+		uint16 numSteps[8];
+		uint16 iniIDTbl[8][5];
+		uint16 sequenceIDTbl[8][5];
+		uint32 textTbl[8][5];
+	} sceneUpdater;
+
 protected:
 	DragonsEngine *_vm;
 	SpecialOpcode *_opcodes[DRAGONS_NUM_SPECIAL_OPCODES];
 	Common::String _opcodeNames[DRAGONS_NUM_SPECIAL_OPCODES];
 
+
 	void initOpcodes();
 	void freeOpcodes();
 
@@ -52,6 +69,7 @@ protected:
 	void spcClearEngineFlag10(); // 3
 	void spcSetEngineFlag10();   // 4
 
+	void spcCastleGardenLogic();
 	void spcUnk9();
 	void spcUnkA();
 
@@ -62,6 +80,8 @@ protected:
 	void spcClearEngineFlag8(); // 0x14
 	void spcSetEngineFlag8(); // 0x15
 
+	void spcKnightPoolReflectionLogic(); //0x17
+
 	void spcActivatePizzaMakerActor(); // 0x1a
 	void spcDeactivatePizzaMakerActor(); // 0x1b
 	void spcPizzaMakerActorStopWorking(); // 0x1c
@@ -78,6 +98,8 @@ protected:
 
 	void spcZigmondFraudSceneLogic(); // 0x3e
 
+	void spcZigmondFraudSceneLogic1(); // 0x40
+
 	void spcLoadScene1(); // 0x49
 
 	void spcUnk4e();
@@ -95,11 +117,15 @@ protected:
 	void spcUnk5e();
 	void spcUnk5f();
 
+	void spcUnk66();
+
 	void spcTransitionToMap(); // 0x6b
 	void spcTransitionFromMap(); // 0x6c
 
 	void spcSetCameraXToZero(); //0x7b
 	void spcDiamondIntroSequenceLogic(); //0x7c
+
+	void setupTableBasedSceneUpdateFunction(uint16 initialCounter, uint16 numSequences, uint16 sequenceDuration);
 private:
 	void panCamera(int16 mode);
 	void pizzaMakerStopWorking();
@@ -111,6 +137,7 @@ private:
 // update functions
 
 void pizzaUpdateFunction();
+void tableBasedSceneUpdateFunction();
 
 } // End of namespace Dragons
 
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index ca095e44cf..b8a2027e3b 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -420,7 +420,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 			}
 		}
 		LAB_80032efc:
-		// TODO DAT_800633fc = 0;
+		_vm->data_800633fc = 0;
 		return (uint)returnStatus;
 }
 


Commit: ec14cbe46400c3e3192aa7856de14b25a5e824e8
    https://github.com/scummvm/scummvm/commit/ec14cbe46400c3e3192aa7856de14b25a5e824e8
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add spcUnk5d

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index aeccf18723..64dcb3f07f 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -114,6 +114,7 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0x5b, spcFlickerSetFlag0x80);
 
+	OPCODE(0x5d, spcUnk5d); //knights in castle garden
 	OPCODE(0x5e, spcUnk5e);
 	OPCODE(0x5f, spcUnk5f);
 
@@ -344,6 +345,11 @@ void SpecialOpcodes::spcFlickerSetFlag0x80() {
 	_vm->_dragonINIResource->getFlickerRecord()->actor->setFlag(ACTOR_FLAG_80);
 }
 
+//used in castle garden scene with knights
+void SpecialOpcodes::spcUnk5d() {
+	_vm->getINI(_vm->getINI(0x13b)->field_12 + 0x13c)->actor->updateSequence(_vm->getINI(0x13b)->field_14);
+}
+
 void SpecialOpcodes::spcUnk5e() {
 	panCamera(1);
 	_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(0));
@@ -470,13 +476,13 @@ void SpecialOpcodes::pizzaMakerStopWorking() {
 }
 
 void SpecialOpcodes::clearSceneUpdateFunction() {
-	//TODO
+//TODO
 //	if (DAT_80083148 != DAT_80083154) {
 //		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
 //	}
-//	if (DAT_8006f3a4 != 0xffff) {
-//		actor_update_sequenceID((uint)dragon_ini_pointer[(uint)DAT_80069630].actorId,DAT_8006f3a4);
-//	}
+	if (sceneUpdater.sequenceID != -1) {
+		_vm->getINI(sceneUpdater.iniID)->actor->updateSequence(sceneUpdater.sequenceID);
+	}
 	_vm->setSceneUpdateFunction(NULL);
 }
 
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 9f2f002a88..435719cac3 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -114,6 +114,7 @@ protected:
 
 	void spcFlickerSetFlag0x80();
 
+	void spcUnk5d();
 	void spcUnk5e();
 	void spcUnk5f();
 


Commit: a8f3cbe911413a56aedcb6c4123fbaed3dd17b44
    https://github.com/scummvm/scummvm/commit/a8f3cbe911413a56aedcb6c4123fbaed3dd17b44
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added place holder functions for screenshake and dragon on hill scene

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 64dcb3f07f..68cec715ad 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -75,6 +75,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0xb, clearSceneUpdateFunction);
 	OPCODE(0xc, spcUnkC);
 
+	OPCODE(0x11, spc11ShakeScreen);
 	OPCODE(0x12, spcHandleInventionBookTransition);
 	OPCODE(0x13, spcUnk13InventionBookCloseRelated);
 	OPCODE(0x14, spcClearEngineFlag8);
@@ -101,6 +102,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x3f, clearSceneUpdateFunction);
 	OPCODE(0x40, spcZigmondFraudSceneLogic1);
 
+	OPCODE(0x46, spcBlackDragonOnHillSceneLogic);
+
 	OPCODE(0x49, spcLoadScene1);
 
 	OPCODE(0x4e, spcUnk4e);
@@ -172,6 +175,25 @@ void SpecialOpcodes::spcUnkC() {
 	//TODO fade_related_calls_with_1f();
 }
 
+void SpecialOpcodes::spc11ShakeScreen() {
+	//TODO
+//	iVar18 = 1;
+//	local_10a0 = DAT_8001170c;
+//	local_109c = DAT_80011710;
+//	local_1098 = DAT_80011714;
+//	local_1094 = uint32_t_80011718;
+//	local_1090 = DAT_8001171c;
+//	local_108c = DAT_80011720;
+//	local_1088 = DAT_80011724;
+//	local_1084 = DAT_80011728;
+//	screenShakeOffset = (short)local_10a0;
+//	while (screenShakeOffset != 0) {
+//		ContinueGame?();
+//		screenShakeOffset = *(short *)((int)&local_10a0 + ((iVar18 << 0x10) >> 0xf));
+//		iVar18 = iVar18 + 1;
+//	}
+}
+
 void SpecialOpcodes::spcHandleInventionBookTransition() {
 	int16 invType =_vm->_inventory->getType();
 	if (invType == 1) {
@@ -301,6 +323,10 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic1() {
 	setupTableBasedSceneUpdateFunction(300,1,0x708);
 }
 
+void SpecialOpcodes::spcBlackDragonOnHillSceneLogic() {
+	//TODO
+}
+
 void SpecialOpcodes::spcUnk4e() {
 	panCamera(1);
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 435719cac3..bed7cdf9ab 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -75,6 +75,7 @@ protected:
 
 	void spcUnkC();
 
+	void spc11ShakeScreen(); //0x11
 	void spcHandleInventionBookTransition(); // 0x12
 	void spcUnk13InventionBookCloseRelated(); //0x13
 	void spcClearEngineFlag8(); // 0x14
@@ -100,6 +101,8 @@ protected:
 
 	void spcZigmondFraudSceneLogic1(); // 0x40
 
+	void spcBlackDragonOnHillSceneLogic(); //0x46
+
 	void spcLoadScene1(); // 0x49
 
 	void spcUnk4e();


Commit: 81577ad2f0576af82786f7816ac2b209020ba216
    https://github.com/scummvm/scummvm/commit/81577ad2f0576af82786f7816ac2b209020ba216
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Started work on first minigame

Changed paths:
  A engines/dragons/minigame1.cpp
  A engines/dragons/minigame1.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index f43d4fd44b..ae4e1f6ac7 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -693,6 +693,9 @@ void DragonsEngine::clearFlags(uint32 flags) {
 	_flags &= ~flags;
 }
 
+uint32 DragonsEngine::getMultipleFlags(uint32 flags) {
+	return _flags & flags;
+}
 void DragonsEngine::setUnkFlags(uint32 flags) {
 	_unkFlags1 |= flags;
 }
@@ -1036,6 +1039,21 @@ bool DragonsEngine::isInputEnabled() {
 	return !isFlagSet(ENGINE_FLAG_20000000) && !isFlagSet(ENGINE_FLAG_400);
 }
 
+bool DragonsEngine::isActionButtonPressed() {
+	//TODO
+	return false;
+}
+
+bool DragonsEngine::isLeftKeyPressed() {
+	//TODO
+	return false;
+}
+
+bool DragonsEngine::isRightKeyPressed() {
+	//TODO
+	return false;
+}
+
 bool DragonsEngine::checkForActionButtonRelease() {
 	return _leftMouseButtonUp || _enterKeyUp;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index fe066bdff9..bb90c873cd 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -194,6 +194,7 @@ public:
 	void updateActorSequences();
 	void setFlags(uint32 flags);
 	void clearFlags(uint32 flags);
+	uint32 getMultipleFlags(uint32 flags);
 	bool isFlagSet(uint32 flag);
 	bool isUnkFlagSet(uint32 flag);
 
@@ -229,6 +230,9 @@ public:
 	void setSceneUpdateFunction(void (*newUpdateFunction)());
 	void (*getSceneUpdateFunction())();
 
+	bool isActionButtonPressed();
+	bool isLeftKeyPressed();
+	bool isRightKeyPressed();
 	bool checkForActionButtonRelease();
 	bool checkForDownKeyRelease();
 	bool checkForUpKeyRelease();
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
new file mode 100644
index 0000000000..c779e0d885
--- /dev/null
+++ b/engines/dragons/minigame1.cpp
@@ -0,0 +1,915 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "minigame1.h"
+#include "actor.h"
+#include "dragons.h"
+#include "dragons/dragonini.h"
+#include "dragons/talk.h"
+
+namespace Dragons {
+
+#define DAT_80063a48 0x12d
+#define DAT_80063a40 0x12f
+#define DAT_80063ab8 0x216D2
+
+Minigame1::Minigame1(DragonsEngine *vm) : _vm(vm) {}
+
+void Minigame1::run() {
+
+	//TODO this might change for different game versions.
+	const uint32 dialogIdTbl[17] = {
+			0x21312,0x2134C,0x21386,0x213C0,
+			0x213E2,0x21428,0x2146C,0x214B4,
+			0x214E4,0x21514,0x21540,0x21590,
+			0x215E2,0x2164E,0x216AA,0x216D2,
+			0x217D8
+	};
+/* WARNING: Could not reconcile some variable overlaps */
+/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */
+
+	Actor *uVar1;
+	short sVar2;
+	bool bVar3;
+	uint16 uVar5;
+	uint savedEngineFlags;
+	uint16 flickerXPos;
+	uint16 auStack1008 [200];
+	DragonINI *originalFlickerIniID;
+	uint16 local_25c;
+	uint16 local_25a;
+	uint16 catFieldE_scaleMaybe;
+	uint16 local_256;
+	uint16 local_254;
+	short local_252;
+	short local_250;
+	uint16 local_246;
+	uint16 local_242;
+	uint16 local_240;
+	uint16 local_23e;
+	short local_23c;
+	short local_23a;
+	short local_238;
+	short gameState;
+	uint16 local_234;
+	short local_232;
+	uint16 local_22e;
+	uint16 local_22c;
+	Actor *targetActorIdTbl [5];
+	short local_21e;
+	uint16 auStack536 [71];
+	uint16 uStack394;
+	short local_188 [7];
+	uint16 auStack378 [5];
+	uint16 i;
+	uint16 local_16e;
+	short local_16a;
+	uint32_t local_168;
+	uint16 auStack352 [24];
+	uint16_t local_130 [10];
+	int32_t local_118 [22];
+	uint32_t local_c0 [22];
+	uint16_t actorFieldC;
+
+	Actor *catActor;
+	Actor *pusherActor;
+	Actor *flickerActor;
+	Actor *wheelsActor;
+	Actor *dustSpriteActor;
+
+	Common::File *fd = new Common::File();
+	if (!fd->open("arc1.bin")) {
+		error("Failed to open arc1.bin");
+	}
+
+	for (i = 0; i < 0x42; i++) {
+		auStack536[i] = fd->readUint16LE();
+	}
+
+	fd->seek(132);
+	for (i = 0; i < 0x18; i++) {
+		auStack352[i] = fd->readUint16LE();
+	}
+
+	for (i = 0; i < 10; i++) {
+		local_130[i] = fd->readUint16LE();
+	}
+	fd->close();
+	delete fd;
+
+//	local_130._0_4_ = DAT_8008e940;
+//	local_130._4_4_ = DAT_8008e944;
+//	local_130._8_4_ = DAT_8008e948;
+//	local_130._12_4_ = DAT_8008e94c;
+//	local_130[8] = DAT_8008e950;
+
+	local_c0[0] = dialogIdTbl[0];
+	local_c0[1] = 0x1e;
+	local_c0[2] = dialogIdTbl[1];
+	local_c0[3] = 0x23;
+	local_c0[4] = dialogIdTbl[2];
+	local_c0[5] = 0x1e;
+	local_c0[6] = dialogIdTbl[3];
+	local_c0[7] = 0x1e;
+	local_c0[8] = dialogIdTbl[4];
+	local_c0[9] = 0x28;
+	local_c0[10] = dialogIdTbl[5];
+	local_c0[11] = 0x1e;
+	local_c0[12] = dialogIdTbl[6];
+	local_c0[13] = 0x28;
+	local_c0[14] = dialogIdTbl[7];
+	local_c0[15] = 0x23;
+	local_c0[16] = dialogIdTbl[8];
+	local_c0[17] = 0x23;
+	local_c0[18] = dialogIdTbl[9];
+	local_c0[19] = 0x1e;
+	local_c0[20] = dialogIdTbl[10];
+	local_c0[21] = 0x32;
+
+	memcpy(local_118,local_c0,0x58);
+
+	local_c0[0] = dialogIdTbl[11];
+	local_c0[1] = 0x3c;
+	local_c0[2] = dialogIdTbl[12];
+	local_c0[3] = 0x3c;
+	local_c0[12] = dialogIdTbl[13];
+	local_c0[13] = 0x3c;
+	local_c0[8] = dialogIdTbl[13];
+	local_c0[9] = 0x3c;
+	local_c0[14] = dialogIdTbl[14];
+	local_c0[15] = 0x3c;
+	local_c0[10] = dialogIdTbl[14];
+	local_c0[11] = 0x3c;
+	local_c0[4] = dialogIdTbl[13];
+	local_c0[5] = 0x3c;
+	local_c0[6] = dialogIdTbl[14];
+	local_c0[7] = 0x3c;
+
+	originalFlickerIniID = _vm->_dragonINIResource->getFlickerRecord();
+	originalFlickerIniID->actor->setFlag(ACTOR_FLAG_100);
+	originalFlickerIniID->actor->priorityLayer = 0;
+
+	savedEngineFlags = _vm->getMultipleFlags(ENGINE_FLAG_8 | ENGINE_FLAG_10 | ENGINE_FLAG_20 | ENGINE_FLAG_80);
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_10);
+	_vm->clearFlags(ENGINE_FLAG_20);
+	_vm->clearFlags(ENGINE_FLAG_80);
+	_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(DAT_80063a40 - 1));
+	flickerActor = _vm->getINI(DAT_80063a40 - 1)->actor;
+	flickerActor->flags = flickerActor->flags | 0x380;
+	flickerActor->field_e = 0x100;
+	flickerActor->priorityLayer = 4;
+	flickerActor->_sequenceID2 = -1;
+	flickerActor->updateSequence(0x15);
+	local_256 = 0;
+	local_254 = 0;
+	local_252 = 0;
+	flickerXPos = flickerActor->x_pos;
+	local_25c = 0;
+	pusherActor = _vm->_actorManager->loadActor(0x26,1, flickerXPos,
+								  (int)(((uint)(uint16)flickerActor->y_pos + 5) * 0x10000) >> 0x10);
+//	if (pusherActorId == -1) {
+//		ProbablyShowASCIIMessage(s_couldn't_alloc_pusher_8008e954,2,4,0,0xffffffff);
+//	}
+	pusherActor->flags = pusherActor->flags | 0x380;
+	pusherActor->x_pos = flickerActor->x_pos + -0xe;
+	pusherActor->y_pos = flickerActor->y_pos + 7;
+	pusherActor->field_e = 0x100;
+	pusherActor->priorityLayer = 6;
+	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
+//	if (wheelsActorId == -1) {
+//		ProbablyShowASCIIMessage(s_couldn't_alloc_wheels_8008e96c,2,4,0,0xffffffff);
+//	}
+	wheelsActor->flags = wheelsActor->flags | 0x380;
+	wheelsActor->field_e = 0x100;
+	wheelsActor->x_pos = flickerActor->x_pos;
+	wheelsActor->y_pos = flickerActor->y_pos;
+	wheelsActor->priorityLayer = 5;
+	wheelsActor->updateSequence(0x11);
+	local_242 = 0;
+	catActor = _vm->_actorManager->loadActor(7,9,0,0);
+//	if (catActorId == -1) {
+//		ProbablyShowASCIIMessage(s_couldn't_alloc-cat_8008e984,2,4,0,0xffffffff);
+//	}
+	catActor->flags = catActor->flags | 0x380;
+	catActor->field_e = 0x100;
+	catActor->priorityLayer = 0;
+	i = 0;
+	while (i < 3) {
+		targetActorIdTbl[(uint)i + 1] = _vm->_actorManager->loadActor(8,1,0,0,0);
+//		if (targetActorIdTbl[(uint)i + 1] == -1) {
+//			ProbablyShowASCIIMessage(s_couldn't_alloc_target!_8008e998,2,4,0,0xffffffff);
+//		}
+		targetActorIdTbl[(uint)i + 1]->flags = targetActorIdTbl[(uint)i + 1]->flags | 0x380;
+		targetActorIdTbl[(uint)i + 1]->field_e = 0x100;
+		auStack378[(uint)i + 1] = 0;
+		//TODO FUN_80017010_update_actor_texture_maybe(1);
+		i = i + 1;
+	}
+	i = 0;
+	while (i < 8) {
+		local_188[(uint)i] = 0;
+		i = i + 1;
+	}
+	dustSpriteActor = _vm->_actorManager->loadActor(8,8,100,100,0);
+//	if (dustSpriteActorId == 0xffff) {
+//		ProbablyShowASCIIMessage(s_couldn't_alloc_dust_sprite!_8008e9b0,2,5,0,0xffffffff);
+//	}
+	dustSpriteActor->flags = dustSpriteActor->flags | 0x380;
+	dustSpriteActor->field_e = 0x100;
+	uVar1 = _vm->getINI(DAT_80063a48 - 1)->actor; //dragon_ini_pointer[DAT_80063a48 + -1].actorId;
+	local_21e = 0;
+	actorFieldC = uVar1->field_c;
+	_vm->setFlags(ENGINE_FLAG_4000000);
+	local_23e = 0x3700;
+	local_23a = 0x100;
+	local_240 = 0x4a80;
+	local_238 = 0;
+	catFieldE_scaleMaybe = 0x30;
+	catActor->y_pos = 0x6e;
+	catActor->x_pos = 0x95;
+	catActor->field_e = 0x30;
+	catActor->priorityLayer = 2;
+	catActor->updateSequence(0xb);
+	gameState = 5;
+	local_246 = 1;
+	bVar3 = false;
+	local_22e = 0;
+	local_22c = 0;
+	local_250 = 0;
+	LAB_8008fa78:
+	do {
+		do {
+			_vm->waitForFrames(1);
+			if ((local_250 != 0) && (local_250 = local_250 + -1, local_250 == 0)) {
+				_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
+			}
+			if ((local_21e == 1) && (local_252 == 0)) {
+				uVar1->field_c = actorFieldC;
+			}
+			if (local_21e != 0) {
+				local_21e = local_21e + -1;
+			}
+			switch(gameState) {
+				case 0:
+					break;
+				case 1:
+					if (local_252 == 0) {
+						if (local_246 != 8) {
+							local_246 = 0;
+						}
+//						iVar6 = IsButtonBeingPressed((uint)DAT_800728ac,0);
+						if (!_vm->isActionButtonPressed()) {
+							if (local_25c == 0) {
+								if ((((flickerActor->_sequenceID != 0) &&
+									  (flickerActor->_sequenceID != 5)) &&
+									 (flickerActor->_sequenceID != 6)) ||
+									((flickerActor->flags & 4) != 0)) {
+									flickerActor->updateSequence(0);
+								}
+							}
+							else {
+								local_246 = 1;
+								bVar3 = false;
+								pusherActor->updateSequence(1);
+								gameState = 2;
+								if (local_25c < 0x14) {
+									local_25a = 1;
+								}
+								else {
+									if (local_25c < 0x2d) {
+										local_25a = 2;
+									}
+									else {
+										if (local_25c < 0x169) {
+											local_25a = 3;
+										}
+									}
+								}
+							}
+							local_25c = 0;
+						}
+						else {
+							pusherActor->x_pos = flickerActor->x_pos + -0xe;
+							pusherActor->y_pos = flickerActor->y_pos + 7;
+							if (local_25c < 0x168) {
+								local_25c = local_25c + 1;
+								if (local_25c < 0x14) {
+									if (((pusherActor->_sequenceID != 4) &&
+									(pusherActor->_sequenceID != 2)) &&
+									(pusherActor->_sequenceID != 3)) {
+										pusherActor->updateSequence(4);
+									}
+									if (flickerActor->_sequenceID != 1) {
+										flickerActor->updateSequence(1);
+										_vm->playSound(2);
+									}
+								}
+								else {
+									if (local_25c < 0x2d) {
+										if (((pusherActor->_sequenceID != 5) &&
+										(pusherActor->_sequenceID != 2)) &&
+										(pusherActor->_sequenceID != 3)) {
+											pusherActor->updateSequence(5);
+										}
+										if (flickerActor->_sequenceID != 2) {
+											flickerActor->updateSequence(2);
+											_vm->playSound(3);
+										}
+									}
+									else {
+										if (local_25c < 0x169) {
+											if (((pusherActor->_sequenceID != 6) &&
+											(pusherActor->_sequenceID != 2)) &&
+											(pusherActor->_sequenceID != 3)) {
+												pusherActor->updateSequence(6);
+											}
+											if (flickerActor->_sequenceID != 3) {
+												flickerActor->updateSequence(3);
+												_vm->playSound(4);
+											}
+										}
+									}
+								}
+							}
+							else {
+								if (pusherActor->_sequenceID != 6) {
+									pusherActor->updateSequence(6);
+								}
+								if (flickerActor->_sequenceID != 3) {
+									flickerActor->updateSequence(3);
+								}
+							}
+						}
+					}
+					break;
+				case 2:
+					if (flickerActor->_sequenceID == 7) {
+						if ((flickerActor->flags & 4) != 0) {
+							i = 1;
+							while ((i < 8 && ((((int)(uint)flickerXPos < (int)((uint)auStack352[(uint)i * 3] - 6) ||
+												((uint)auStack352[(uint)i * 3 + 1] + 6 < (uint)flickerXPos)) ||
+											   (local_25a != auStack352[(uint)i * 3 + 2]))))) {
+								i = i + 1;
+							}
+							local_23c = 0;
+							if ((i != 8) &&
+								((flickerXPos < auStack352[(uint)i * 3] || (auStack352[(uint)i * 3] < flickerXPos))))
+							{
+								local_23c = (short)((int)(((uint)auStack352[(uint)i * 3] + 8) * 0x80) / 0x2a) -
+											(short)((int)((uint)flickerXPos << 7) / 0x2a);
+							}
+							local_240 = flickerXPos << 7;
+							catActor->x_pos = flickerXPos & 0x1ff;
+							local_23e = 0x2d00;
+							local_23a = (local_25a + 3) * 0x80;
+							catActor->y_pos = 0x5a;
+							catFieldE_scaleMaybe = 0x100;
+							catActor->field_e = 0x100;
+							catActor->updateSequence(0xc);
+							_vm->playSound(5);
+							catActor->priorityLayer = 3;
+							flickerActor->updateSequence(8);
+							gameState = 3;
+						}
+					}
+					else {
+						flickerActor->updateSequence(7);
+						_vm->playSound(1);
+					}
+					break;
+				case 3:
+					local_240 = local_240 + local_23c;
+					if ((uint)local_25a * 2 + 0xb4 < (uint)catFieldE_scaleMaybe) {
+						local_23e = local_23e - local_23a;
+						local_23a = local_23a - local_130[((uint)local_25a - 1) * 3];
+						if (local_23a < 0) {
+							local_23a = 0;
+						}
+					}
+					else {
+						if ((int)(uint)catFieldE_scaleMaybe < (int)((uint)local_25a * -4 + 0xba)) {
+							local_23e = local_23e + local_23a;
+							local_23a = local_23a + local_130[((uint)local_25a - 1) * 3 + 2];
+						}
+						else {
+							local_23a = 0;
+						}
+					}
+					catActor->x_pos = local_240 >> 7;
+					catActor->y_pos = local_23e >> 7;
+					catFieldE_scaleMaybe = catFieldE_scaleMaybe - 3;
+					catActor->field_e = catFieldE_scaleMaybe;
+					if (catFieldE_scaleMaybe == 0x7f) {
+						i = 0;
+						while ((i < 8 && (((local_240 >> 7 < auStack352[(uint)i * 3] ||
+											(auStack352[(uint)i * 3 + 1] < local_240 >> 7)) ||
+										   (local_25a != auStack352[(uint)i * 3 + 2]))))) {
+							i = i + 1;
+						}
+						if ((i != 8) && (local_188[(uint)i] != 0)) {
+							uVar1->field_c = 2;
+							local_21e = 0x3c;
+							if (local_250 != 0) {
+								_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
+								local_250 = 0;
+							}
+							local_256 = local_256 + 1;
+							catActor->updateSequence(0xd);
+							if ((i == 0) && (9 < local_256)) {
+								local_22c = 0x16;
+								local_252 = 2;
+								catActor->updateSequence(0xd);
+								gameState = 4;
+							}
+							else {
+								catActor->updateSequence(0xd);
+								_vm->playSound(6);
+								gameState = 8;
+								local_234 = 0;
+							}
+							if (local_252 == 0) {
+								_vm->_talk->loadText(local_118[((uint)local_256 - 1) * 2], auStack1008, 200);
+								_vm->_talk->displayDialogAroundPoint(auStack1008, (int)(short)(flickerXPos >> 3),0xc,0,0,
+										 local_118[((uint)local_256 - 1) * 2]);
+								local_250 = *(short *)(local_118 + ((uint)local_256 - 1) * 2 + 1);
+							}
+							targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->priorityLayer = 3;
+							if (i == 0) {
+								targetActorIdTbl[(uint)local_188[0]]->updateSequence(7);
+							}
+							else {
+								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->y_pos -= 3;
+								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(6);
+							}
+							auStack378[(uint)(uint16)local_188[(uint)i]] = 0;
+							local_188[(uint)i] = 0;
+							break;
+						}
+						if ((i == 8) &&
+							((((local_25a == 1 && (local_240 >> 7 < 0x10e)) ||
+							   ((local_25a == 2 &&
+								 ((((0x7f < local_240 >> 7 && (local_240 >> 7 < 0xad)) ||
+									((0x30 < local_240 >> 7 && (local_240 >> 7 < 0x4a)))) ||
+								   ((0xf8 < local_240 >> 7 && (local_240 >> 7 < 0x10f)))))))) ||
+							  ((local_25a == 3 &&
+								(((0x3c < local_240 >> 7 && (local_240 >> 7 < 0x46)) ||
+								  ((0x101 < local_240 >> 7 && (local_240 >> 7 < 0x10a)))))))))) {
+							dustSpriteActor->x_pos = catActor->x_pos;
+							dustSpriteActor->y_pos = catActor->y_pos + 2;
+							dustSpriteActor->updateSequence(8);
+							catActor->priorityLayer = 4;
+							dustSpriteActor->priorityLayer = 3;
+							catActor->updateSequence(0xd);
+							gameState = 4;
+							_vm->playSound(6);
+						}
+					}
+					if (catFieldE_scaleMaybe < 0x7f) {
+						catActor->priorityLayer = 2;
+					}
+					if ((0xc < catFieldE_scaleMaybe) && (catFieldE_scaleMaybe < 0x41)) {
+						catActor->priorityLayer = 0;
+					}
+					if ((short)catFieldE_scaleMaybe < 2) {
+						local_23e = 0x3700;
+						local_23a = 0x100;
+						local_240 = 0x4a80;
+						catFieldE_scaleMaybe = 0x30;
+						catActor->y_pos = 0x6e;
+						catActor->x_pos = 0x95;
+						catActor->field_e = 0x30;
+						catActor->updateSequence(0xb);
+						gameState = 5;
+					}
+					break;
+				case 4:
+					if (((catActor->flags & 4) != 0) &&
+					((dustSpriteActor->flags & 4) != 0)) {
+				if (catActor->_sequenceID == 0xe) {
+					if (local_23e < 0x4300) {
+						local_23e = local_23e + local_23a;
+						local_23a = local_23a + 0x18;
+						catActor->y_pos = local_23e >> 7;
+					}
+					else {
+						catActor->updateSequence(0xf);
+						_vm->playSound(7);
+						gameState = 6;
+					}
+				}
+				else {
+					dustSpriteActor->priorityLayer = 0;
+					catActor->priorityLayer = 3;
+					catActor->updateSequence(0xe);
+					_vm->playSound(8);
+					local_23a = 0x40;
+				}
+			}
+					break;
+				case 5:
+					if (local_23e >> 7 < 0x86) {
+						local_23e = local_23e + local_23a;
+						catFieldE_scaleMaybe = catFieldE_scaleMaybe + 8;
+						catActor->y_pos = local_23e >> 7;
+						catActor->field_e = catFieldE_scaleMaybe;
+					}
+					else {
+						gameState = 6;
+						catActor->_sequenceID = 0x10;
+						catActor->flags = catActor->flags | 4;
+					}
+					break;
+				case 6:
+					catActor->priorityLayer = 3;
+					if (local_252 == 0) {
+						if (catActor->_sequenceID == 0xf) {
+							if ((catActor->flags & 4) != 0) {
+								catActor->updateSequence(0x10);
+							}
+						}
+						else {
+							if (catActor->_sequenceID == 0x10) {
+								if ((catActor->flags & 4) != 0) {
+									catFieldE_scaleMaybe = 0x80;
+									local_23e = 0x4300;
+									local_23a = 0x100;
+									catActor->y_pos = 0x86;
+									catActor->field_e = 0x80;
+									catActor->updateSequence(0xb);
+									if (flickerXPos < local_240 >> 7) {
+										sVar2 = flickerXPos + 0x32;
+									}
+									else {
+										sVar2 = flickerXPos - 0x32;
+									}
+									local_16e = sVar2 * 0x80;
+									local_23c = (short)(((int)(((uint)local_16e - (uint)local_240) * 0x10000) >> 0x10) /
+														0x1c);
+								}
+							}
+							else {
+								if (local_23e < 0x5f00) {
+									if (local_238 == 0) {
+										local_23e = local_23e + local_23a;
+										local_240 = local_240 + local_23c;
+										catFieldE_scaleMaybe = catFieldE_scaleMaybe + 6;
+										if (0x100 < catFieldE_scaleMaybe) {
+											catFieldE_scaleMaybe = 0x100;
+										}
+										catActor->field_e = catFieldE_scaleMaybe;
+										catActor->y_pos = local_23e >> 7;
+										catActor->x_pos = local_240 >> 7;
+										local_238 = 1;
+									}
+									else {
+										local_238 = local_238 + -1;
+									}
+								}
+								else {
+									if ((int)(uint)(local_240 >> 7) < (int)((uint)flickerXPos - 0x32)) {
+										if (catActor->_sequenceID != 9) {
+											catActor->field_e = 0x100;
+											catActor->updateSequence(9);
+										}
+										local_240 = local_240 + 0x180;
+										catActor->x_pos = local_240 >> 7;
+									}
+									else {
+										if ((uint)flickerXPos + 0x32 < (uint)(local_240 >> 7)) {
+											if (catActor->_sequenceID != 10) {
+												catActor->field_e = 0x100;
+												catActor->updateSequence(10);
+											}
+											local_240 = local_240 - 0x180;
+											catActor->x_pos = local_240 >> 7;
+										}
+										else {
+											gameState = 7;
+										}
+									}
+								}
+							}
+						}
+					}
+					break;
+				case 7:
+					if (catActor->priorityLayer == 0) {
+				gameState = 1;
+			}
+					else {
+				catActor->priorityLayer = 0;
+				if (local_240 >> 7 < flickerXPos) {
+					flickerActor->updateSequence(5);
+				}
+				else {
+					flickerActor->updateSequence(6);
+				}
+			}
+					break;
+				case 8:
+					if (local_234 == 1) {
+						if (local_23a < 1) {
+							local_234 = 2;
+						}
+						else {
+							local_23a = local_23a + -1;
+							catActor->y_pos = catActor->y_pos + 2;
+						}
+					}
+					else {
+						if (local_234 < 2) {
+							if ((local_234 == 0) && ((catActor->flags & 4) != 0)) {
+								local_234 = 3;
+								local_232 = 0;
+							}
+						}
+						else {
+							if (local_234 == 2) {
+								local_23e = 0x4100;
+								local_240 = 0x4a80;
+								catActor->y_pos = 0x82;
+								catActor->x_pos = 0x95;
+								catActor->priorityLayer = 3;
+								catActor->field_e = 0x80;
+								catActor->updateSequence(0x10);
+								gameState = 6;
+							}
+							else {
+								if (local_234 == 3) {
+									if (local_232 == 0) {
+										catActor->priorityLayer = 2;
+										local_23a = 8;
+										local_234 = 1;
+									}
+									else {
+										local_232 = local_232 + -1;
+									}
+								}
+							}
+						}
+					}
+					break;
+				default:
+					//ProbablyShowASCIIMessage(s_undefined_state!_8008e9cc,2,3,0,0xffffffff);
+					gameState = 1;
+					catActor->priorityLayer = 0;
+					flickerActor->updateSequence(0);
+			}
+			if ((local_252 == 0) && (gameState != 2)) {
+				if (!_vm->isLeftKeyPressed() || (flickerXPos < 0x37)) {
+					if (!_vm->isRightKeyPressed() || (0x107 < flickerXPos)) {
+						if ((pusherActor->_sequenceID != local_246) &&
+						(((pusherActor->_sequenceID != 4 &&
+															   (pusherActor->_sequenceID != 5)) &&
+						(pusherActor->_sequenceID != 6)))) {
+							pusherActor->updateSequence((uint)local_246);
+							if (bVar3) {
+								pusherActor->x_pos = flickerActor->x_pos + 2;
+								pusherActor->y_pos = flickerActor->y_pos;
+							}
+							else {
+								pusherActor->x_pos = flickerActor->x_pos - 0xe;
+								pusherActor->y_pos = flickerActor->y_pos + 7;
+							}
+						}
+					}
+					else {
+						bVar3 = true;
+						local_246 = 8;
+						if (pusherActor->_sequenceID != 2) {
+							pusherActor->updateSequence(2);
+						}
+						flickerXPos = flickerXPos + 2;
+						if (flickerXPos < 0x109) {
+							if (flickerXPos < 0x36) {
+								flickerXPos = 0x36;
+							}
+						}
+						else {
+							flickerXPos = 0x108;
+						}
+						if (local_242 == 0) {
+							local_242 = 0xb;
+						}
+						else {
+							local_242 = local_242 - 1;
+						}
+						flickerActor->x_pos = flickerXPos;
+						wheelsActor->x_pos = flickerXPos;
+						if ((uint)wheelsActor->_sequenceID != (uint)local_242 / 3 + 0x11)
+						{
+							wheelsActor->updateSequence((uint)local_242 / 3 + 0x11);
+						}
+						pusherActor->x_pos = flickerActor->x_pos + 2;
+						pusherActor->y_pos = flickerActor->y_pos;
+					}
+				}
+				else {
+					bVar3 = false;
+					local_246 = (uint16)(gameState != 1);
+					if (pusherActor->_sequenceID != 3) {
+						pusherActor->updateSequence(3);
+					}
+					flickerXPos = flickerXPos - 2;
+					if (flickerXPos < 0x109) {
+						if (flickerXPos < 0x36) {
+							flickerXPos = 0x36;
+						}
+					}
+					else {
+						flickerXPos = 0x108;
+					}
+					local_242 = (short)((uint)local_242 + 1) +
+								(short)((int)((uint)local_242 + 1) / 6 >> 1) * -0xc;
+					flickerActor->x_pos = flickerXPos;
+					wheelsActor->x_pos = flickerXPos;
+					if ((uint)wheelsActor->_sequenceID != (uint)local_242 / 3 + 0x11) {
+						wheelsActor->updateSequence((uint)local_242 / 3 + 0x11);
+					}
+					pusherActor->x_pos = flickerActor->x_pos + -2;
+					pusherActor->y_pos = flickerActor->y_pos;
+				}
+			}
+			if ((local_22c < 0x16) && (auStack536[(uint)local_22c * 3 + 2] <= local_22e)) {
+				if ((local_22c == 0x14) && (local_256 < 9)) {
+					local_252 = 1;
+					local_22c = 0x16;
+				}
+				else {
+					if (auStack536[(uint)local_22c * 3 + 1] == 1) {
+						i = 0;
+						while ((i < 3 && (auStack378[(uint)i + 1] != 0))) {
+							i = i + 1;
+						}
+						if (i == 3) {
+							error("too many targets");
+//							ProbablyShowASCIIMessage(s_too_many_targets!_8008e9e0,2,4,0,0xffffffff);
+						}
+						if (auStack536[(uint)local_22c * 3] == 0) {
+							targetActorIdTbl[(uint)i + 1]->x_pos = auStack352[(uint)auStack536[(uint)local_22c * 3] * 3] + 0xd;
+						}
+						else {
+							targetActorIdTbl[(uint)i + 1]->x_pos = auStack352[(uint)auStack536[(uint)local_22c * 3] * 3] + 8;
+						}
+						targetActorIdTbl[(uint)i + 1]->y_pos = (4 - auStack352[(uint)auStack536[(uint)local_22c * 3] * 3 + 2]) * 0x20;
+						targetActorIdTbl[(uint)i + 1]->priorityLayer = 2;
+						if (auStack536[(uint)local_22c * 3] == 0) {
+							targetActorIdTbl[(uint)i + 1]->updateSequence(3);
+						}
+						else {
+							targetActorIdTbl[(uint)i + 1]->updateSequence(0);
+						}
+						targetActorIdTbl[(uint)i + 1]->priorityLayer = 2;
+						local_188[(uint)auStack536[(uint)local_22c * 3]] = i + 1;
+						auStack378[(uint)i + 1] = auStack536[(uint)local_22c * 3] + 1;
+					}
+					else {
+						if ((auStack536[(uint)local_22c * 3 + 1] == 2) &&
+							(i = auStack536[(uint)local_22c * 3], local_188[(uint)i] != 0)) {
+							if (auStack536[(uint)local_22c * 3] == 0) {
+								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(5);
+							}
+							else {
+								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(2);
+							}
+							if (local_250 != 0) {
+								_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
+								local_250 = 0;
+							}
+							if ((local_254 == 0) && (local_252 == 0)) {
+								if (auStack536[(uint)local_22c * 3] == 0) {
+									uVar5 = _vm->getRand(2);
+									local_168 = local_c0[(uint)uVar5 * 2 + 4];
+									local_16a = *(short *)(local_c0 + (uint)uVar5 * 2 + 5);
+								}
+								else {
+									uVar5 = _vm->getRand(2);
+									local_168 = local_c0[(uint)uVar5 * 2];
+									local_16a = *(short *)(local_c0 + (uint)uVar5 * 2 + 1);
+								}
+							}
+							else {
+								uVar5 = _vm->getRand(2);
+								local_168 = local_c0[(uint)uVar5 * 2 + 4];
+								local_16a = *(short *)(local_c0 + (uint)uVar5 * 2 + 5);
+							}
+							if ((local_252 == 0) || ((auStack536[(uint)local_22c * 3] == 0 && (local_254 == 0))))
+							{
+								_vm->_talk->loadText(local_168, auStack1008, 200);
+								_vm->_talk->displayDialogAroundPoint(auStack1008,(int)(short)(flickerXPos >> 3),0xc,0,0,local_168);
+								local_250 = local_16a;
+							}
+							if (local_254 < 2) {
+								local_254 = local_254 + 1;
+							}
+							auStack378[(uint)(uint16)local_188[(uint)i]] = 0;
+							local_188[(uint)i] = 0;
+							if ((1 < local_254) || (auStack536[(uint)local_22c * 3] == 0)) {
+								local_252 = 1;
+							}
+						}
+					}
+				}
+				local_22e = 0;
+				local_22c = local_22c + 1;
+			}
+			i = 0;
+			while (i < 3) {
+				if ((targetActorIdTbl[(uint)i + 1]->_sequenceID == 1) ||
+				(targetActorIdTbl[(uint)i + 1]->_sequenceID == 4)) {
+					(&uStack394)[(uint)auStack378[(uint)i + 1]] = 0;
+					auStack378[(uint)i + 1] = 0;
+				}
+				i = i + 1;
+			}
+			local_22e = local_22e + 1;
+		} while (local_252 == 0);
+		if (flickerActor->x_pos < 0x118) {
+			flickerActor->x_pos = flickerActor->x_pos + 2;
+			if (pusherActor->_sequenceID != 2) {
+				pusherActor->updateSequence(2);
+			}
+			pusherActor->x_pos = flickerActor->x_pos + 2;
+			pusherActor->y_pos = flickerActor->y_pos;
+			wheelsActor->x_pos = wheelsActor->x_pos + 2;
+			if (local_242 == 0) {
+				local_242 = 0xb;
+			}
+			else {
+				local_242--;
+			}
+			if ((uint)wheelsActor->_sequenceID != (uint)local_242 / 3 + 0x11) {
+				wheelsActor->updateSequence((uint)local_242 / 3 + 0x11);
+			}
+			goto LAB_8008fa78;
+		}
+		if ((local_252 == 1) && ((gameState == 6 || (gameState == 1)))) {
+			pusherActor->updateSequence(9);
+			_vm->waitForFrames(0xf);
+			if (local_250 != 0) {
+				_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
+			}
+			_vm->waitForFrames(0x3c);
+			_vm->getINI(DAT_80063a40 - 1)->actor->clearFlag(ACTOR_FLAG_100);
+			break;
+		}
+		if ((local_252 == 2) && (gameState == 6)) {
+			_vm->getINI(DAT_80063a40)->actorResourceId = 2;
+			if (local_250 != 0) {
+				_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
+			}
+			pusherActor->updateSequence(7);
+			_vm->_talk->loadText(DAT_80063ab8, auStack1008, 200);
+			_vm->_talk->displayDialogAroundPoint(auStack1008, 0x19, 0xc, 0, 1, DAT_80063ab8);
+
+			pusherActor->updateSequence(1);
+			_vm->waitForFrames(0x1e);
+			_vm->getINI(DAT_80063a40 - 1)->actor->clearFlag(ACTOR_FLAG_100);
+			break;
+		}
+	} while( true );
+
+	//TODO callMaybeResetData();
+	flickerActor->updateSequence(0x15);
+	// DisableVSyncEvent();
+	catActor->reset_maybe();
+	wheelsActor->reset_maybe();
+	i = 0;
+	while (i < 3) {
+		targetActorIdTbl[(uint)i + 1]->reset_maybe();
+		i = i + 1;
+	}
+	pusherActor->reset_maybe();
+	dustSpriteActor->reset_maybe();
+	// EnableVSyncEvent();
+	_vm->_dragonINIResource->getFlickerRecord()->actor->clearFlag(ACTOR_FLAG_100);
+	_vm->_dragonINIResource->setFlickerRecord(originalFlickerIniID);
+	flickerActor = originalFlickerIniID->actor;
+	flickerActor->clearFlag(ACTOR_FLAG_100);
+	flickerActor->priorityLayer = 2;
+	_vm->clearFlags(ENGINE_FLAG_4000000);
+	_vm->setFlags(savedEngineFlags);
+	uVar1->field_c = actorFieldC;
+	return;
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/minigame1.h b/engines/dragons/minigame1.h
new file mode 100644
index 0000000000..59051503e0
--- /dev/null
+++ b/engines/dragons/minigame1.h
@@ -0,0 +1,42 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 DRAGONS_MINIGAME1_H
+#define DRAGONS_MINIGAME1_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class DragonsEngine;
+
+class Minigame1 {
+private:
+	DragonsEngine *_vm;
+public:
+	Minigame1(DragonsEngine *vm);
+
+	void run();
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_MINIGAME1_H
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index c9e0e2eecc..f482bc8bb8 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -18,6 +18,7 @@ MODULE_OBJS := \
 	dragons.o \
 	font.o \
 	inventory.o \
+	minigame1.o \
 	saveload.o \
 	scene.o \
 	screen.o \
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 68cec715ad..a121cbd46d 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -30,8 +30,10 @@
 #include "dragons/specialopcodes.h"
 #include "dragons/scene.h"
 #include "dragons/actor.h"
+#include "dragons/minigame1.h"
 #include "talk.h"
 #include "specialopcodes.h"
+#include "minigame1.h"
 
 
 namespace Dragons {
@@ -65,7 +67,7 @@ void SpecialOpcodes::initOpcodes() {
 		_opcodes[i] = 0;
 	}
 	// Register opcodes
-	// OPCODE(1, opUnk1);
+	OPCODE(1, spcCatapultMiniGame);
 	OPCODE(3, spcClearEngineFlag10);
 	OPCODE(4, spcSetEngineFlag10);
 
@@ -141,6 +143,11 @@ void SpecialOpcodes::freeOpcodes() {
 
 // Opcodes
 
+void SpecialOpcodes::spcCatapultMiniGame() {
+	Minigame1 minigame1(_vm);
+	minigame1.run();
+}
+
 void SpecialOpcodes::spcClearEngineFlag10() {
 	_vm->clearFlags(Dragons::ENGINE_FLAG_10);
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index bed7cdf9ab..e551033cbb 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -66,6 +66,7 @@ protected:
 	void freeOpcodes();
 
 	// Opcodes
+	void spcCatapultMiniGame(); // 1
 	void spcClearEngineFlag10(); // 3
 	void spcSetEngineFlag10();   // 4
 
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index b8a2027e3b..c9ea517fc6 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -1097,4 +1097,9 @@ void Talk::clearDialogEntries() {
 	_dialogEntries.clear();
 }
 
+void Talk::FUN_8001a7c4_clearDialogBoxMaybe() {
+	FUN_8001a7c4((uint)DAT_8008e7e8_dialogBox_x1,(uint)DAT_8008e844_dialogBox_y1,
+			(uint)DAT_8008e848_dialogBox_x2,(uint)DAT_8008e874_dialogBox_y2);
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index cea64d5bf1..f8c219fce6 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -86,7 +86,9 @@ public:
 	bool talkToActor(ScriptOpCall &scriptOpCall);
 
 	uint somethingTextAndSpeechAndAnimRelated(Actor *actor,int16 sequenceId1,int16 sequenceId2,uint32 textIndex, uint16 param_5);
+	void FUN_8001a7c4_clearDialogBoxMaybe(); //clear box maybe?
 private:
+	void FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2); //clear box maybe?
 	void copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength);
 	uint32 wideStrLen(uint16 *text);
 	TalkDialogEntry *displayTalkDialogMenu();
@@ -96,7 +98,6 @@ private:
 	uint32 strlenUTF16(uint16 *text);
 	uint16 *findCharInU16Str(uint16 *text, uint16 chr);
 	void FUN_8001a4e4_draw_dialogbox(uint32 x1, uint32 y1, uint32 x2, uint32 y2, uint16 unk);
-	void FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2); //clear box maybe?
 	uint16 *UTF16ToUTF16Z(uint16 *dest, uint16 *src);
 	uint16 FindLastPositionOf5cChar(uint16 *text);
 	uint32 FUN_80031c28(uint16 *srcText, uint16 *destText,uint32 cutLength, uint16 param_4);


Commit: c91c21bf89b6822ec811e0ddfdb79f618c42fa07
    https://github.com/scummvm/scummvm/commit/c91c21bf89b6822ec811e0ddfdb79f618c42fa07
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixes for the first mini game.

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/minigame1.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index ae4e1f6ac7..a8bffb6d20 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -72,11 +72,16 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_sceneUpdateFunction = NULL;
 
 	_leftMouseButtonUp = false;
+	_leftMouseButtonDown = false;
 	_rightMouseButtonUp = false;
 	_iKeyUp = false;
 	_downKeyUp = false;
 	_upKeyUp = false;
 	_enterKeyUp = false;
+	_leftKeyDown = false;
+	_leftKeyUp = false;
+	_rightKeyDown = false;
+	_rightKeyUp = false;
 	reset();
 }
 
@@ -93,6 +98,8 @@ void DragonsEngine::updateEvents() {
 	_downKeyUp = false;
 	_upKeyUp = false;
 	_enterKeyUp = false;
+	_leftKeyUp = false;
+	_rightKeyUp = false;
 	while (_eventMan->pollEvent(event)) {
 //		_input->processEvent(event);
 		switch (event.type) {
@@ -104,6 +111,10 @@ void DragonsEngine::updateEvents() {
 				break;
 			case Common::EVENT_LBUTTONUP:
 				_leftMouseButtonUp = true;
+				_leftMouseButtonDown = false;
+				break;
+			case Common::EVENT_LBUTTONDOWN:
+				_leftMouseButtonDown = true;
 				break;
 			case Common::EVENT_RBUTTONUP:
 				_rightMouseButtonUp = true;
@@ -118,7 +129,21 @@ void DragonsEngine::updateEvents() {
 				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RETURN ||
 							event.kbd.keycode == Common::KeyCode::KEYCODE_KP_ENTER) {
 					_enterKeyUp = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_LEFT) {
+					_leftKeyUp = true;
+					_leftKeyDown = false;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RIGHT) {
+					_rightKeyUp = true;
+					_rightKeyDown = false;
+				}
+				break;
+			case Common::EVENT_KEYDOWN:
+				if (event.kbd.keycode == Common::KeyCode::KEYCODE_LEFT) {
+					_leftKeyDown = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RIGHT) {
+					_rightKeyDown = true;
 				}
+				break;
 			default:
 				break;
 		}
@@ -1040,18 +1065,15 @@ bool DragonsEngine::isInputEnabled() {
 }
 
 bool DragonsEngine::isActionButtonPressed() {
-	//TODO
-	return false;
+	return _leftMouseButtonDown;
 }
 
 bool DragonsEngine::isLeftKeyPressed() {
-	//TODO
-	return false;
+	return _leftKeyDown;
 }
 
 bool DragonsEngine::isRightKeyPressed() {
-	//TODO
-	return false;
+	return _rightKeyDown;
 }
 
 bool DragonsEngine::checkForActionButtonRelease() {
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index bb90c873cd..c10663d089 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -166,12 +166,18 @@ private:
 
 	// input
 	bool _leftMouseButtonUp;
+	bool _leftMouseButtonDown;
 	bool _rightMouseButtonUp;
 	bool _iKeyUp;
 	bool _downKeyUp;
 	bool _upKeyUp;
 	bool _enterKeyUp;
 
+	bool _leftKeyDown;
+	bool _leftKeyUp;
+	bool _rightKeyDown;
+	bool _rightKeyUp;
+
 	void (*_sceneUpdateFunction)();
 protected:
 	virtual bool hasFeature(EngineFeature f) const;
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index c779e0d885..5a3310f99b 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -57,7 +57,7 @@ void Minigame1::run() {
 	uint16 local_25c;
 	uint16 local_25a;
 	uint16 catFieldE_scaleMaybe;
-	uint16 local_256;
+	uint16 hitCounter;
 	uint16 local_254;
 	short local_252;
 	short local_250;
@@ -75,10 +75,9 @@ void Minigame1::run() {
 	uint16 local_22c;
 	Actor *targetActorIdTbl [5];
 	short local_21e;
-	uint16 auStack536 [71];
-	uint16 uStack394;
-	short local_188 [7];
-	uint16 auStack378 [5];
+	uint16 auStack536 [72];
+	short local_188 [8];
+	uint16 auStack378 [4];
 	uint16 i;
 	uint16 local_16e;
 	short local_16a;
@@ -179,7 +178,7 @@ void Minigame1::run() {
 	flickerActor->priorityLayer = 4;
 	flickerActor->_sequenceID2 = -1;
 	flickerActor->updateSequence(0x15);
-	local_256 = 0;
+	hitCounter = 0;
 	local_254 = 0;
 	local_252 = 0;
 	flickerXPos = flickerActor->x_pos;
@@ -220,7 +219,7 @@ void Minigame1::run() {
 //		}
 		targetActorIdTbl[(uint)i + 1]->flags = targetActorIdTbl[(uint)i + 1]->flags | 0x380;
 		targetActorIdTbl[(uint)i + 1]->field_e = 0x100;
-		auStack378[(uint)i + 1] = 0;
+		auStack378[(uint)i] = 0;
 		//TODO FUN_80017010_update_actor_texture_maybe(1);
 		i = i + 1;
 	}
@@ -271,7 +270,7 @@ void Minigame1::run() {
 			switch(gameState) {
 				case 0:
 					break;
-				case 1:
+				case 1: //cat in the catapult ready to fire.
 					if (local_252 == 0) {
 						if (local_246 != 8) {
 							local_246 = 0;
@@ -361,7 +360,7 @@ void Minigame1::run() {
 						}
 					}
 					break;
-				case 2:
+				case 2: // initial release of cat.
 					if (flickerActor->_sequenceID == 7) {
 						if ((flickerActor->flags & 4) != 0) {
 							i = 1;
@@ -396,7 +395,7 @@ void Minigame1::run() {
 						_vm->playSound(1);
 					}
 					break;
-				case 3:
+				case 3: // cat flying through the air
 					local_240 = local_240 + local_23c;
 					if ((uint)local_25a * 2 + 0xb4 < (uint)catFieldE_scaleMaybe) {
 						local_23e = local_23e - local_23a;
@@ -432,9 +431,9 @@ void Minigame1::run() {
 								_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
 								local_250 = 0;
 							}
-							local_256 = local_256 + 1;
+							hitCounter = hitCounter + 1;
 							catActor->updateSequence(0xd);
-							if ((i == 0) && (9 < local_256)) {
+							if ((i == 0) && (9 < hitCounter)) {
 								local_22c = 0x16;
 								local_252 = 2;
 								catActor->updateSequence(0xd);
@@ -446,11 +445,11 @@ void Minigame1::run() {
 								gameState = 8;
 								local_234 = 0;
 							}
-							if (local_252 == 0) {
-								_vm->_talk->loadText(local_118[((uint)local_256 - 1) * 2], auStack1008, 200);
+							if (local_252 == 0) { //successful hit maybe?
+								_vm->_talk->loadText(local_118[((uint)hitCounter - 1) * 2], auStack1008, 200);
 								_vm->_talk->displayDialogAroundPoint(auStack1008, (int)(short)(flickerXPos >> 3),0xc,0,0,
-										 local_118[((uint)local_256 - 1) * 2]);
-								local_250 = *(short *)(local_118 + ((uint)local_256 - 1) * 2 + 1);
+										 local_118[((uint)hitCounter - 1) * 2]);
+								local_250 = *(short *)(local_118 + ((uint)hitCounter - 1) * 2 + 1);
 							}
 							targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->priorityLayer = 3;
 							if (i == 0) {
@@ -460,7 +459,7 @@ void Minigame1::run() {
 								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->y_pos -= 3;
 								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(6);
 							}
-							auStack378[(uint)(uint16)local_188[(uint)i]] = 0;
+							auStack378[(uint)(uint16)local_188[(uint)i] - 1] = 0;
 							local_188[(uint)i] = 0;
 							break;
 						}
@@ -501,31 +500,31 @@ void Minigame1::run() {
 						gameState = 5;
 					}
 					break;
-				case 4:
+				case 4: // cat sliding down wall.
 					if (((catActor->flags & 4) != 0) &&
 					((dustSpriteActor->flags & 4) != 0)) {
-				if (catActor->_sequenceID == 0xe) {
-					if (local_23e < 0x4300) {
-						local_23e = local_23e + local_23a;
-						local_23a = local_23a + 0x18;
-						catActor->y_pos = local_23e >> 7;
-					}
-					else {
-						catActor->updateSequence(0xf);
-						_vm->playSound(7);
-						gameState = 6;
+						if (catActor->_sequenceID == 0xe) {
+							if (local_23e < 0x4300) {
+								local_23e = local_23e + local_23a;
+								local_23a = local_23a + 0x18;
+								catActor->y_pos = local_23e >> 7;
+							}
+							else {
+								catActor->updateSequence(0xf);
+								_vm->playSound(7);
+								gameState = 6;
+							}
+						}
+						else {
+							dustSpriteActor->priorityLayer = 0;
+							catActor->priorityLayer = 3;
+							catActor->updateSequence(0xe);
+							_vm->playSound(8);
+							local_23a = 0x40;
+						}
 					}
-				}
-				else {
-					dustSpriteActor->priorityLayer = 0;
-					catActor->priorityLayer = 3;
-					catActor->updateSequence(0xe);
-					_vm->playSound(8);
-					local_23a = 0x40;
-				}
-			}
 					break;
-				case 5:
+				case 5: // cat behind portcullis
 					if (local_23e >> 7 < 0x86) {
 						local_23e = local_23e + local_23a;
 						catFieldE_scaleMaybe = catFieldE_scaleMaybe + 8;
@@ -538,7 +537,7 @@ void Minigame1::run() {
 						catActor->flags = catActor->flags | 4;
 					}
 					break;
-				case 6:
+				case 6: // cat run across field
 					catActor->priorityLayer = 3;
 					if (local_252 == 0) {
 						if (catActor->_sequenceID == 0xf) {
@@ -611,27 +610,27 @@ void Minigame1::run() {
 						}
 					}
 					break;
-				case 7:
+				case 7: // cat jumping into catapult
 					if (catActor->priorityLayer == 0) {
-				gameState = 1;
-			}
+						gameState = 1;
+					}
 					else {
-				catActor->priorityLayer = 0;
-				if (local_240 >> 7 < flickerXPos) {
-					flickerActor->updateSequence(5);
-				}
-				else {
-					flickerActor->updateSequence(6);
-				}
-			}
+						catActor->priorityLayer = 0;
+						if (local_240 >> 7 < flickerXPos) {
+							flickerActor->updateSequence(5);
+						}
+						else {
+							flickerActor->updateSequence(6);
+						}
+					}
 					break;
-				case 8:
+				case 8: // cat hit target.
 					if (local_234 == 1) {
 						if (local_23a < 1) {
 							local_234 = 2;
 						}
 						else {
-							local_23a = local_23a + -1;
+							local_23a--;
 							catActor->y_pos = catActor->y_pos + 2;
 						}
 					}
@@ -750,18 +749,18 @@ void Minigame1::run() {
 				}
 			}
 			if ((local_22c < 0x16) && (auStack536[(uint)local_22c * 3 + 2] <= local_22e)) {
-				if ((local_22c == 0x14) && (local_256 < 9)) {
+				if ((local_22c == 0x14) && (hitCounter < 9)) {
 					local_252 = 1;
 					local_22c = 0x16;
 				}
 				else {
 					if (auStack536[(uint)local_22c * 3 + 1] == 1) {
 						i = 0;
-						while ((i < 3 && (auStack378[(uint)i + 1] != 0))) {
+						while ((i < 3 && (auStack378[(uint)i] != 0))) {
 							i = i + 1;
 						}
 						if (i == 3) {
-							error("too many targets");
+							debug("too many targets");
 //							ProbablyShowASCIIMessage(s_too_many_targets!_8008e9e0,2,4,0,0xffffffff);
 						}
 						if (auStack536[(uint)local_22c * 3] == 0) {
@@ -780,7 +779,7 @@ void Minigame1::run() {
 						}
 						targetActorIdTbl[(uint)i + 1]->priorityLayer = 2;
 						local_188[(uint)auStack536[(uint)local_22c * 3]] = i + 1;
-						auStack378[(uint)i + 1] = auStack536[(uint)local_22c * 3] + 1;
+						auStack378[(uint)i] = auStack536[(uint)local_22c * 3] + 1;
 					}
 					else {
 						if ((auStack536[(uint)local_22c * 3 + 1] == 2) &&
@@ -821,7 +820,7 @@ void Minigame1::run() {
 							if (local_254 < 2) {
 								local_254 = local_254 + 1;
 							}
-							auStack378[(uint)(uint16)local_188[(uint)i]] = 0;
+							auStack378[(uint)(uint16)local_188[(uint)i] - 1] = 0;
 							local_188[(uint)i] = 0;
 							if ((1 < local_254) || (auStack536[(uint)local_22c * 3] == 0)) {
 								local_252 = 1;
@@ -836,8 +835,8 @@ void Minigame1::run() {
 			while (i < 3) {
 				if ((targetActorIdTbl[(uint)i + 1]->_sequenceID == 1) ||
 				(targetActorIdTbl[(uint)i + 1]->_sequenceID == 4)) {
-					(&uStack394)[(uint)auStack378[(uint)i + 1]] = 0;
-					auStack378[(uint)i + 1] = 0;
+					local_188[(uint)auStack378[(uint)i]] = 0;
+					auStack378[(uint)i] = 0;
 				}
 				i = i + 1;
 			}
@@ -905,7 +904,7 @@ void Minigame1::run() {
 	_vm->_dragonINIResource->setFlickerRecord(originalFlickerIniID);
 	flickerActor = originalFlickerIniID->actor;
 	flickerActor->clearFlag(ACTOR_FLAG_100);
-	flickerActor->priorityLayer = 2;
+	flickerActor->priorityLayer = 6; //TODO this is 2 in the original but that leave flicker invisible.
 	_vm->clearFlags(ENGINE_FLAG_4000000);
 	_vm->setFlags(savedEngineFlags);
 	uVar1->field_c = actorFieldC;


Commit: 4a0a4ee1af1fa33a17653dc01985aa71805e195b
    https://github.com/scummvm/scummvm/commit/4a0a4ee1af1fa33a17653dc01985aa71805e195b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed bugs in first mini game. It should be winable now

Changed paths:
    engines/dragons/minigame1.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 5a3310f99b..ddcd4a8f24 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -872,7 +872,7 @@ void Minigame1::run() {
 			break;
 		}
 		if ((local_252 == 2) && (gameState == 6)) {
-			_vm->getINI(DAT_80063a40)->actorResourceId = 2;
+			_vm->getINI(DAT_80063a40 - 1)->field_14 = 2;
 			if (local_250 != 0) {
 				_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
 			}
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index fa75c05412..f7be917e83 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -123,7 +123,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x1E, opUnk1ESetActorFlag0x400);
 	OPCODE(0x1F, opPlayMusic);
 	OPCODE(0x20, opUnk20);
-
+	OPCODE(0x21, opUnk21);
 	OPCODE(0x22, opCodeActorTalk);
 }
 
@@ -439,6 +439,15 @@ void ScriptOpcodes::opUnk20(ScriptOpCall &scriptOpCall) {
 	}
 }
 
+void ScriptOpcodes::opUnk21(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_UINT32(textIndex);
+
+	if (scriptOpCall._field8 == 0) {
+		//TODO play dialog audio without text on screen.
+	}
+}
+
 bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {
 	byte *codePtrOffsetA = scriptOpCall._code + 0xA;
 	byte *codePtrOffset2 = scriptOpCall._code + 2;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 5c713f664d..7195863baa 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -114,6 +114,7 @@ protected:
 	void opSetActorFlag0x1000(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
 	void opUnk20(ScriptOpCall &scriptOpCall);
+	void opUnk21(ScriptOpCall &scriptOpCall);
 
 	bool checkPropertyFlag(ScriptOpCall &scriptOpCall);
 	void opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index a121cbd46d..573d89f6e0 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -128,9 +128,15 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x6b, spcTransitionToMap);
 	OPCODE(0x6c, spcTransitionFromMap);
 
+	OPCODE(0x7a, spcBlackDragonDialogForCamelhot);
 	OPCODE(0x7b, spcSetCameraXToZero);
 	OPCODE(0x7c, spcDiamondIntroSequenceLogic);
 
+	OPCODE(0x82, spc82CallResetDataMaybe);
+
+	OPCODE(0x89, spcSetUnkFlag2);
+	OPCODE(0x8a, spcClearUnkFlag2);
+
 }
 
 #undef OPCODE
@@ -332,6 +338,7 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic1() {
 
 void SpecialOpcodes::spcBlackDragonOnHillSceneLogic() {
 	//TODO
+	sceneUpdater.sequenceID = -1;
 }
 
 void SpecialOpcodes::spcUnk4e() {
@@ -440,6 +447,12 @@ void SpecialOpcodes::panCamera(int16 mode) {
 	return;
 }
 
+void SpecialOpcodes::spcBlackDragonDialogForCamelhot() {
+	uint16 buffer[1024];
+	_vm->_talk->loadText(0x30DD8, buffer, 1024); //TODO might need to check dialog in other game versions
+	_vm->_talk->displayDialogAroundPoint(buffer,0x27,0xc,0xc01,0,0x30DD8);
+}
+
 void SpecialOpcodes::spcSetCameraXToZero() {
 	_vm->_scene->_camera.x = 0;
 }
@@ -450,6 +463,18 @@ void SpecialOpcodes::spcDiamondIntroSequenceLogic() {
 	delete cutScene;
 }
 
+void SpecialOpcodes::spc82CallResetDataMaybe() {
+	//TODO callMaybeResetData();
+}
+
+void SpecialOpcodes::spcSetUnkFlag2() {
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+}
+
+void SpecialOpcodes::spcClearUnkFlag2() {
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
+}
+
 void SpecialOpcodes::spcLoadScene1() {
 	CutScene *cutScene = new CutScene(_vm);
 	cutScene->scene1();
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index e551033cbb..b80664a05a 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -127,9 +127,15 @@ protected:
 	void spcTransitionToMap(); // 0x6b
 	void spcTransitionFromMap(); // 0x6c
 
+	void spcBlackDragonDialogForCamelhot(); // 0x7a
 	void spcSetCameraXToZero(); //0x7b
 	void spcDiamondIntroSequenceLogic(); //0x7c
 
+	void spc82CallResetDataMaybe(); // 0x82
+
+	void spcSetUnkFlag2(); // 0x89
+	void spcClearUnkFlag2(); //0x8a
+
 	void setupTableBasedSceneUpdateFunction(uint16 initialCounter, uint16 numSequences, uint16 sequenceDuration);
 private:
 	void panCamera(int16 mode);


Commit: 57cb891a55c87f3ff1573625a6f80e445ced810a
    https://github.com/scummvm/scummvm/commit/57cb891a55c87f3ff1573625a6f80e445ced810a
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More special opcodes. Saved knights cutscene.

Changed paths:
  A engines/dragons/minigame4.cpp
  A engines/dragons/minigame4.h
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/module.mk
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h
    engines/dragons/talk.cpp


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 5d24fa2848..d9ffa1bd25 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -72,15 +72,15 @@ void CutScene::scene1() {
 	closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 	//playSoundFromTxtIndex(0x4e26);
 	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x4e26,0x2e01) != 2) {
-		clearActor(DAT_80072de8);
+		fadeScreenAndResetActor(DAT_80072de8);
 		closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); // cut to flicker
 		//playSoundFromTxtIndex(0x4ea2);
 		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x4ea2,0x701) != 2) {
-			clearActor(DAT_80072de8);
+			fadeScreenAndResetActor(DAT_80072de8);
 			closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 			//playSoundFromTxtIndex(0x4eec);
 			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x4eec,0x2e01) != 2) {
-				clearActor(DAT_80072de8);
+				fadeScreenAndResetActor(DAT_80072de8);
 				wideAngleEveryoneAtTable();  // shot of whole room
 				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5000,0x2e01) != 2 &&
 					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_800830c0,0x1d,0x1c,0x5074,0x501) != 2 &&
@@ -89,14 +89,14 @@ void CutScene::scene1() {
 					closeUpShotOnActor(0xd7, 0, 0x312, 0x260); //close up on flame
 					//playSoundFromTxtIndex(0x5152);
 					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x5152,0x3e01) != 2) {
-						clearActor(DAT_80072de8);
+						fadeScreenAndResetActor(DAT_80072de8);
 						closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); //close up flicker
 						//playSoundFromTxtIndex(0x51fc);
 						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x51fc,0x701) != 2) {
 							_vm->playSound(0x8004);
 							_vm->waitForFrames(0x28);
 							_vm->playSound(0x8003);
-							clearActor(DAT_80072de8);
+							fadeScreenAndResetActor(DAT_80072de8);
 							DAT_80063514 = DAT_80063514 | 0x40;
 							FUN_8003d8e8(0xd6,0,0x37a,0x280);
 							DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3); //load humans
@@ -114,43 +114,43 @@ void CutScene::scene1() {
 									_vm->_scene->_camera.x = 0;
 									//playSoundFromTxtIndex(0x54dc);
 									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,6,2,0x54dc,0x2e01) != 2) {
-										clearActor(DAT_80072de8);
-										clearActor(DAT_80072dec);
-										clearActor(DAT_80072df0);
+										fadeScreenAndResetActor(DAT_80072de8);
+										fadeScreenAndResetActor(DAT_80072dec);
+										fadeScreenAndResetActor(DAT_80072df0);
 										wideAngleEveryoneAtTable();
 										if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e08,3,2,0x55d4,0xc01) != 2) {
 											closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 											//playSoundFromTxtIndex(0x562c);
 											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x562c,0xc01) != 2) {
-												clearActor(DAT_80072de8);
+												fadeScreenAndResetActor(DAT_80072de8);
 												FUN_8003d8e8(0xd6,0,0x37a,0x280);
 												DAT_80072dec = _vm->_actorManager->loadActor(0xd5,4,0x2d6,0xc6,3);
 												_vm->waitForFramesAllowSkip(4);
 												// call_fade_related_1f();
 												if (FUN_8003dab8(0x5780,0x14,0,0xc01,1) != 2) {
 													DAT_80063514 = DAT_80063514 | 0x40;
-													clearActor(DAT_80072de8);
-													clearActor(DAT_80072dec);
+													fadeScreenAndResetActor(DAT_80072de8);
+													fadeScreenAndResetActor(DAT_80072dec);
 													closeUpShotOnActor(0xd7, 0, 0x312, 0x260); // close up flame
 													//playSoundFromTxtIndex(0x581c);
 													if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x581c,0x3e01) != 2) {
-														clearActor(DAT_80072de8);
+														fadeScreenAndResetActor(DAT_80072de8);
 														closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 														//playSoundFromTxtIndex(0x5942);
 														if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x5942,0xc01) != 2) {
-															clearActor(DAT_80072de8);
+															fadeScreenAndResetActor(DAT_80072de8);
 															closeUpShotOnActor(0xd3, 2, 0x87, 0); // close up king
 															//playSoundFromTxtIndex(0x5aaa);
 															if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,7,2,0x5aaa,0x2e01) != 2) {
-																clearActor(DAT_80072de8);
+																fadeScreenAndResetActor(DAT_80072de8);
 																FUN_8003d8e8(0xd6,0,0x37a,0x280);
 																DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3);
 																_vm->waitForFramesAllowSkip(4);
 																// call_fade_related_1f();
 																//playSoundFromTxtIndex(0x5afc);
 																if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,3,0,0x5afc,0x3c01) != 2) {
-																	clearActor(DAT_80072de8);
-																	clearActor(DAT_80072dec);
+																	fadeScreenAndResetActor(DAT_80072de8);
+																	fadeScreenAndResetActor(DAT_80072dec);
 																	DAT_80063514 = DAT_80063514 & 0xffbf;
 																	closeUpKnightsAtTable(); // close up of knights at table.
 																	_vm->playSound(0x8003);
@@ -172,13 +172,13 @@ void CutScene::scene1() {
 																				//call_fade_related_1f();
 																				//playSoundFromTxtIndex(0x5ef2);
 																				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5ef2,0x3e01) != 2) {
-																					clearActor(DAT_80072de8);
-																					clearActor(DAT_80072dec);
+																					fadeScreenAndResetActor(DAT_80072de8);
+																					fadeScreenAndResetActor(DAT_80072dec);
 																					closeUpShotOnActor(0xd3, 0, 0x233,
 																									   0x17a); // close up of king
 																					//playSoundFromTxtIndex(0x6000);
 																					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,8,0,0x6000,0x2e01) != 2) {
-																						clearActor(DAT_80072de8);
+																						fadeScreenAndResetActor(DAT_80072de8);
 																						closeUpKnightsAtTable(); // close up knights at table
 																						//playSoundFromTxtIndex(0x7dcc);
 																						DAT_80072df0->updateSequence(0x13);
@@ -342,8 +342,8 @@ void CutScene::scene1() {
 
 }
 
-//FUN_8003c108
-void CutScene::clearActor(Actor *actor) {
+//fadeScreenAndResetActor
+void CutScene::fadeScreenAndResetActor(Actor *actor) {
 	// TODO fade_related_calls_with_1f();
 	//DisableVSyncEvent();
 	actor->reset_maybe();
@@ -563,6 +563,104 @@ void CutScene::diamondScene() {
 	_vm->clearFlags(ENGINE_FLAG_20000);
 }
 
+void CutScene::knightsSavedBackAtCastle() {
+	DragonINI *uVar1;
+	uint actorId;
+	bool isFlag0x10Set;
+
+	uVar1 = _vm->_dragonINIResource->getFlickerRecord();
+	DAT_80063514 = 0xa00;
+	_vm->_dragonINIResource->setFlickerRecord(NULL);
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+	isFlag0x10Set = _vm->isFlagSet(ENGINE_FLAG_10);
+	//TODO fade_related_calls_with_1f();
+	_vm->clearFlags(ENGINE_FLAG_10);
+	_vm->_inventory->setActorFlag400();
+	_vm->_cursor->setActorFlag400();
+
+//	scr_tilemap1_w = 0x28;
+//	DAT_8006a3f0 = DAT_8006a3ec;
+//	load_actor_file(0x81);
+//	load_actor_file(0x7d);
+//	load_actor_file(0x7e);
+//	load_actor_file(0x8f);
+//	load_actor_file(0xaa);
+
+	_vm->setFlags(ENGINE_FLAG_20000);
+	closeUpKnightsAtTable();
+//	playSoundFromTxtIndex(0x7854);
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,10,4,0x7854,0xc01) != 2) {
+		closeUpShotOnActor(0xd8,0,0xfd,0x60);
+//		playSoundFromTxtIndex(0x78c6);
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x78c6,0x701) != 2) {
+			fadeScreenAndResetActor(DAT_80072de8);
+			closeUpKnightsAtTable();
+//			playSoundFromTxtIndex(0x78e8);
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x78e8,0x2e01) != 2) {
+				wideAngleEveryoneAtTable();
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e04,0x1a,0x19,0x7a1e,0x3e01) != 2) {
+					DAT_80072e04->field_7c = 0x10000;
+					DAT_80072e04->setFlag(ACTOR_FLAG_800);
+					DAT_80072e04->updateSequence(0x21);
+					DAT_80072e04->pathfinding_maybe(0x13f,0x6e,2);
+					// wait for pathfinding to complete
+					while (DAT_80072e04->isFlagSet(ACTOR_FLAG_10)) { //TODO move to method on Actor waitForPathfinding() ??
+						//empty
+					}
+					DAT_80063514 = DAT_80063514 | 1;
+					closeUpShotOnActor(0xd3,0,0x233,0x17a);
+//					playSoundFromTxtIndex(0x7aba);
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,9,0,0x7aba,0x2e01) != 2) {
+						fadeScreenAndResetActor(DAT_80072de8);
+						closeUpShotOnActor(0xd8,0,0xfd,0x60);
+//						playSoundFromTxtIndex(0x7b60);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x7b60,0x701) != 2) {
+							fadeScreenAndResetActor(DAT_80072de8);
+							wideAngleEveryoneAtTable();
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,9,5,0x7c20,0xc01) != 2) {
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x7c9c,0x701) != 2) {
+									_vm->playSound(0x800f);
+									_vm->waitForFrames(10);
+									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x7cf2,0x701) != 2) {
+										closeUpKnightsAtTable();
+//										playSoundFromTxtIndex(0x7dcc);
+										DAT_80072df0->updateSequence(0x13);
+										DAT_80072df4->updateSequence(0x10);
+										DAT_80072df8->updateSequence(0x11);
+										actorId = _vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0x12,6,0x7dcc,0xc01);
+										if ((actorId & 0xffff) != 2) {
+											closeUpShotOnActor(0xd3,0,0x233,0x17a);
+//											playSoundFromTxtIndex(0x7e1a);
+											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,10,0,0x7e1a,0x2e01) != 2) {
+												fadeScreenAndResetActor(DAT_80072de8);
+												wideAngleEveryoneAtTable();
+												if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x7e96,0x2e01) != 2) {
+													_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x7f0a,0x701);
+												}
+											}
+										}
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+	// fade_related_calls_with_1f();
+	//DisableVSyncEvent();
+//	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+	//EnableVSyncEvent();
+	if(isFlag0x10Set) {
+		_vm->setFlags(ENGINE_FLAG_10);
+	}
+	_vm->clearFlags(ENGINE_FLAG_20000);
+	_vm->_dragonINIResource->setFlickerRecord(uVar1);
+	cursorInventoryClearFlag400();
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
+}
+
 void CutScene::loadPalettes() {
 	Common::File fd;
 	if (!fd.open("dragon.exe")) {
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index dc7ddf364e..83416b1014 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -59,10 +59,11 @@ public:
 
 	void scene1();
 	void diamondScene();
+	void knightsSavedBackAtCastle();
 
 private:
 	//Scene 1 related functions
-	void clearActor(Actor *actor);
+	void fadeScreenAndResetActor(Actor *actor);
 	void closeUpShotOnActor(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4);
 	void FUN_8003d8e8(uint16 resourceId,uint16 sequenceId,int16 x,uint32 param_4);
 	void wideAngleEveryoneAtTable();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index b436bda834..6968d4f7a0 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -138,6 +138,16 @@ void Inventory::setActorSequenceId(int32 sequenceId) {
 	}
 }
 
+void Inventory::updateActorSequenceId(int32 sequenceId) {
+	if (isActorSet()) {
+		_actor->updateSequence(sequenceId);
+	}
+}
+
+void Inventory::resetSequenceId() {
+	_actor->updateSequence(_sequenceId);
+}
+
 void Inventory::openInventory() {
 	//TODO 0x80030e8c
 	_sequenceId = 4;
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 52be9009cb..019c867283 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -64,6 +64,9 @@ public:
 		return _sequenceId;
 	}
 	void setActorSequenceId(int32 sequenceId);
+	void updateActorSequenceId(int32 sequenceId);
+	void resetSequenceId();
+
 	int16 getType() { return _type; }
 	void setType(int16 newType) { _type = newType; }
 
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
new file mode 100644
index 0000000000..c3845b772d
--- /dev/null
+++ b/engines/dragons/minigame4.cpp
@@ -0,0 +1,35 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "minigame4.h"
+#include "actor.h"
+#include "dragons.h"
+#include "dragons/dragonini.h"
+#include "dragons/talk.h"
+
+namespace Dragons {
+
+Minigame4::Minigame4(DragonsEngine *vm) : _vm(vm) {}
+
+void Minigame4::run() {
+
+}
+} // End of namespace Dragons
diff --git a/engines/dragons/minigame4.h b/engines/dragons/minigame4.h
new file mode 100644
index 0000000000..7731503244
--- /dev/null
+++ b/engines/dragons/minigame4.h
@@ -0,0 +1,42 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 DRAGONS_MINIGAME4_H
+#define DRAGONS_MINIGAME4_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class DragonsEngine;
+
+class Minigame4 {
+private:
+	DragonsEngine *_vm;
+public:
+	Minigame4(DragonsEngine *vm);
+
+	void run();
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_MINIGAME4_H
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index f482bc8bb8..1f19ada532 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -19,6 +19,7 @@ MODULE_OBJS := \
 	font.o \
 	inventory.o \
 	minigame1.o \
+	minigame4.o \
 	saveload.o \
 	scene.o \
 	screen.o \
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 573d89f6e0..b27cee730a 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -76,6 +76,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0xa, spcUnkA);
 	OPCODE(0xb, clearSceneUpdateFunction);
 	OPCODE(0xc, spcUnkC);
+	OPCODE(0xd, spcFadeScreen);
 
 	OPCODE(0x11, spc11ShakeScreen);
 	OPCODE(0x12, spcHandleInventionBookTransition);
@@ -95,8 +96,19 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x23, spcSetEngineFlag0x200000);
 	OPCODE(0x24, spcClearEngineFlag0x200000);
 
+	OPCODE(0x28, spcMonksAtBarSceneLogic);
+	OPCODE(0x29, spcStopMonksAtBarSceneLogic);
+
+	OPCODE(0x2b, spcFlameBedroomEscapeSceneLogic);
+	OPCODE(0x2c, spcStopFlameBedroomEscapeSceneLogic);
+
+	OPCODE(0x34, spcUnk34);
+
 	OPCODE(0x36, spcFlickerClearFlag0x80);
 
+	OPCODE(0x38, spcNoop1);
+	OPCODE(0x39, spcTownAngryVillagersSceneLogic);
+
 	OPCODE(0x3b, spcSetEngineFlag0x2000000);
 	OPCODE(0x3c, spcClearEngineFlag0x2000000);
 	OPCODE(0x3d, clearSceneUpdateFunction);
@@ -104,10 +116,14 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x3f, clearSceneUpdateFunction);
 	OPCODE(0x40, spcZigmondFraudSceneLogic1);
 
+	OPCODE(0x42, spcDodoUnderAttackSceneLogic);
+
 	OPCODE(0x46, spcBlackDragonOnHillSceneLogic);
 
 	OPCODE(0x49, spcLoadScene1);
 
+	OPCODE(0x4b, spcKnightsSavedCastleCutScene);
+
 	OPCODE(0x4e, spcUnk4e);
 	OPCODE(0x4f, spcUnk4f);
 	OPCODE(0x50, spcCloseInventory);
@@ -123,11 +139,16 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x5e, spcUnk5e);
 	OPCODE(0x5f, spcUnk5f);
 
+	OPCODE(0x63, spcSetInventorySequenceTo5);
+	OPCODE(0x64, spcResetInventorySequence);
+	OPCODE(0x65, spcUnk65ScenePaletteRelated);
 	OPCODE(0x66, spcUnk66);
 
 	OPCODE(0x6b, spcTransitionToMap);
 	OPCODE(0x6c, spcTransitionFromMap);
 
+	OPCODE(0x77, spcJesterInLibrarySceneLogic);
+
 	OPCODE(0x7a, spcBlackDragonDialogForCamelhot);
 	OPCODE(0x7b, spcSetCameraXToZero);
 	OPCODE(0x7c, spcDiamondIntroSequenceLogic);
@@ -188,6 +209,10 @@ void SpecialOpcodes::spcUnkC() {
 	//TODO fade_related_calls_with_1f();
 }
 
+void SpecialOpcodes::spcFadeScreen() {
+	//TODO call_fade_related_1f();
+}
+
 void SpecialOpcodes::spc11ShakeScreen() {
 	//TODO
 //	iVar18 = 1;
@@ -270,10 +295,73 @@ void SpecialOpcodes::spcClearEngineFlag0x200000() {
 	_vm->clearFlags(ENGINE_FLAG_200000);
 }
 
+void SpecialOpcodes::spcMonksAtBarSceneLogic() {
+	//TODO
+}
+
+void SpecialOpcodes::spcStopMonksAtBarSceneLogic() {
+	//TODO
+}
+
+void SpecialOpcodes::spcFlameBedroomEscapeSceneLogic() {
+	//TODO
+//	local_fc8 = DAT_80063cb8;
+//	local_fc4 = DAT_80063cbc;
+//	local_fc0 = DAT_80063cc0;
+//	local_fbc = DAT_80063cc0;
+//	local_fb8 = DAT_80063cc8;
+//	local_fb4 = DAT_80063ccc;
+//	local_ff0[0] = DAT_80063cb8;
+//	local_ff0[1] = DAT_80063cbc;
+//	local_ff0[2] = DAT_80063cc0;
+//	local_ff0[3] = DAT_80063cc0;
+//	local_fe0 = DAT_80063cc8;
+//	local_fdc = DAT_80063ccc;
+//	DisableVSyncEvent();
+//	uVar13 = 0;
+//	uVar7 = 0;
+//	do {
+//		uVar13 = uVar13 + 1;
+//		(&DAT_800832d8)[uVar7] = local_ff0[uVar7];
+//		uVar7 = (uint)uVar13;
+//	} while (uVar13 < 6);
+//	EnableVSyncEvent();
+//	DAT_80072898 = 0xffff;
+//	if ((DAT_80083148 != 0) && (DAT_80083154 != 0)) {
+//		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
+//	}
+//	func_ptr_unk = FUN_80038164;
+}
+
+void SpecialOpcodes::spcStopFlameBedroomEscapeSceneLogic() {
+	//TODO
+//	DAT_80072898 = 0;
+//	FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
+//	DAT_80083154 = 0;
+//	DAT_80083148 = 0;
+//	actor_update_sequenceID((uint)(ushort)dragon_ini_pointer[DAT_80063a3c + -1].field_0x1c,0);
+//	if (func_ptr_unk == FUN_80038164) {
+//		func_ptr_unk = 0;
+//	}
+}
+
+void SpecialOpcodes::spcUnk34() {
+	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;
+	flicker->setFlag(ACTOR_FLAG_80);
+	flicker->field_e = 0x100;
+}
+
 void SpecialOpcodes::spcFlickerClearFlag0x80() {
 	_vm->_dragonINIResource->getFlickerRecord()->actor->clearFlag(ACTOR_FLAG_80);
 }
 
+void SpecialOpcodes::spcNoop1() {
+	//No op
+}
+
+void SpecialOpcodes::spcTownAngryVillagersSceneLogic() {
+	//TODO
+}
 void SpecialOpcodes::spcSetEngineFlag0x2000000() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_2000000);
 }
@@ -336,6 +424,11 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic1() {
 	setupTableBasedSceneUpdateFunction(300,1,0x708);
 }
 
+void SpecialOpcodes::spcDodoUnderAttackSceneLogic() {
+	//TODO
+	sceneUpdater.sequenceID = -1;
+}
+
 void SpecialOpcodes::spcBlackDragonOnHillSceneLogic() {
 	//TODO
 	sceneUpdater.sequenceID = -1;
@@ -400,6 +493,35 @@ void SpecialOpcodes::spcUnk5f() {
 	panCamera(2);
 }
 
+void SpecialOpcodes::spcSetInventorySequenceTo5() {
+	_vm->_inventory->updateActorSequenceId(5);
+}
+
+void SpecialOpcodes::spcResetInventorySequence() {
+	_vm->_inventory->resetSequenceId();
+}
+
+void SpecialOpcodes::spcUnk65ScenePaletteRelated() {
+	//TODO
+//	uint uVar1;
+//	ushort uVar2;
+//	RECT local_10;
+//
+//	uVar2 = 0xb1;
+//	local_10.y = 0xf1;
+//	local_10.w = 0x100;
+//	local_10.x = 0;
+//	local_10.h = 1;
+//	uVar1 = 0xb1;
+//	do {
+//		uVar2 = uVar2 + 1;
+//		*(undefined2 *)(uVar1 * 2 + scrFileData_maybe) = 0;
+//		uVar1 = (uint)uVar2;
+//	} while (uVar2 < 0xc0);
+//	LoadImage(&local_10,&palette_data);
+//	DrawSync(0);
+}
+
 void SpecialOpcodes::spcUnk66() {
 	uint16 var =_vm->getVar(2);
 
@@ -481,6 +603,11 @@ void SpecialOpcodes::spcLoadScene1() {
 	delete cutScene;
 }
 
+void SpecialOpcodes::spcKnightsSavedCastleCutScene() {
+	CutScene *cutScene = new CutScene(_vm);
+	cutScene->knightsSavedBackAtCastle();
+	delete cutScene;
+}
 void SpecialOpcodes::spcTransitionToMap() {
 	//TODO map transition
 //	DAT_8006a422 = 0;
@@ -495,6 +622,10 @@ void SpecialOpcodes::spcTransitionFromMap() {
 	//TODO map transition
 }
 
+void SpecialOpcodes::spcJesterInLibrarySceneLogic() {
+	//TODO
+}
+
 void SpecialOpcodes::pizzaMakerStopWorking() {
 	Actor *actorf4 = _vm->getINI(0xf4)->actor;
 	Actor *actorf5 = _vm->getINI(0xf5)->actor;
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index b80664a05a..6712df9ef8 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -70,11 +70,12 @@ protected:
 	void spcClearEngineFlag10(); // 3
 	void spcSetEngineFlag10();   // 4
 
-	void spcCastleGardenLogic();
+	void spcCastleGardenLogic(); // 8
 	void spcUnk9();
 	void spcUnkA();
 
 	void spcUnkC();
+	void spcFadeScreen(); // 0xd
 
 	void spc11ShakeScreen(); //0x11
 	void spcHandleInventionBookTransition(); // 0x12
@@ -93,8 +94,19 @@ protected:
 	void spcSetEngineFlag0x200000(); // 0x23
 	void spcClearEngineFlag0x200000(); // 0x24
 
+	void spcMonksAtBarSceneLogic(); //0x28
+	void spcStopMonksAtBarSceneLogic(); //0x29
+
+	void spcFlameBedroomEscapeSceneLogic(); // 0x2b
+	void spcStopFlameBedroomEscapeSceneLogic(); // 0x2b
+
+	void spcUnk34(); //0x34 pitchfork mole.
+
 	void spcFlickerClearFlag0x80(); //0x36
 
+	void spcNoop1(); // 0x38
+	void spcTownAngryVillagersSceneLogic(); //0x39
+
 	void spcSetEngineFlag0x2000000(); // 0x3b
 	void spcClearEngineFlag0x2000000(); // 0x3c
 
@@ -102,31 +114,39 @@ protected:
 
 	void spcZigmondFraudSceneLogic1(); // 0x40
 
+	void spcDodoUnderAttackSceneLogic(); //0x42
+
 	void spcBlackDragonOnHillSceneLogic(); //0x46
 
 	void spcLoadScene1(); // 0x49
 
+	void spcKnightsSavedCastleCutScene(); //0x4b
+
 	void spcUnk4e();
 	void spcUnk4f();
 	void spcCloseInventory(); // 0x50
 	void spcOpenInventionBook(); // 0x51
 	void spcCloseInventionBook(); // 0x52
-
 	void spcClearEngineFlag0x4000000(); // 0x53
 	void spcSetEngineFlag0x4000000(); // 0x54
 	void spcSetCursorSequenceIdToZero(); // 0x55
 
-	void spcFlickerSetFlag0x80();
+	void spcFlickerSetFlag0x80(); // 0x5b
 
 	void spcUnk5d();
 	void spcUnk5e();
 	void spcUnk5f();
 
+	void spcSetInventorySequenceTo5(); // 0x63
+	void spcResetInventorySequence(); // 0x64
+	void spcUnk65ScenePaletteRelated(); // 0x65;
 	void spcUnk66();
 
 	void spcTransitionToMap(); // 0x6b
 	void spcTransitionFromMap(); // 0x6c
 
+	void spcJesterInLibrarySceneLogic(); // 0x77
+
 	void spcBlackDragonDialogForCamelhot(); // 0x7a
 	void spcSetCameraXToZero(); //0x7b
 	void spcDiamondIntroSequenceLogic(); //0x7c
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index c9ea517fc6..c4d0b4796c 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -826,9 +826,6 @@ void Talk::exitTalkMenu(bool isFlag8Set, bool isFlag100Set) {
 
 uint Talk::somethingTextAndSpeechAndAnimRelated(Actor *actor, int16 sequenceId1, int16 sequenceId2, uint32 textIndex,
 												uint16 param_5) {
-	short sVar1;
-	uint uVar2;
-
 	uint16 dialog[2048];
 	dialog[0] = 0;
 	_vm->_talk->loadText(textIndex, dialog, 2048);


Commit: e774fe42014bbf0161ad378fe52b9b800b2ff2d5
    https://github.com/scummvm/scummvm/commit/e774fe42014bbf0161ad378fe52b9b800b2ff2d5
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on dance battle mini game

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/minigame4.cpp
    engines/dragons/minigame4.h
    engines/dragons/scene.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index c1d9dd1bcd..58d00a7e3c 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -590,6 +590,12 @@ void Actor::pathfindingCleanup() {
 	}
 }
 
+void Actor::waitUntilFlag4IsSet() {
+	while(!isFlagSet(ACTOR_FLAG_4)) {
+		getEngine()->waitForFrames(1);
+	}
+}
+
 void Actor::waitUntilFlag8IsSet() {
 	if (flags & Dragons::ACTOR_FLAG_8) {
 		return;
@@ -602,24 +608,17 @@ void Actor::waitUntilFlag8IsSet() {
 
 void Actor::waitUntilFlag8And4AreSet() {
 	waitUntilFlag8IsSet();
-
-	if (flags & Dragons::ACTOR_FLAG_4) {
-		return;
-	}
-
-	while(!(flags & Dragons::ACTOR_FLAG_4)) {
-		getEngine()->waitForFrames(1);
-	}
+	waitUntilFlag4IsSet();
 }
 
-void Actor::waitUntilFlag8SetThenSet1000AndWaitFor4() {
+void Actor::waitUntilFlag8SetThenSet1000() {
 	waitUntilFlag8IsSet();
-
 	setFlag(ACTOR_FLAG_1000);
+}
 
-	while(!isFlagSet(ACTOR_FLAG_4)) {
-		getEngine()->waitForFrames(1);
-	}
+void Actor::waitUntilFlag8SetThenSet1000AndWaitFor4() {
+	waitUntilFlag8SetThenSet1000();
+	waitUntilFlag4IsSet();
 }
 
 void Actor::clearFlag(uint32 flag) {
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 68d3f4df59..fdaec449a1 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -131,8 +131,10 @@ public:
 	void reset_maybe();
 	bool pathfinding_maybe(int16 target_x, int16 target_y, uint16 isNotFlicker);
 	void walkPath();
+	void waitUntilFlag4IsSet();
 	void waitUntilFlag8IsSet();
 	void waitUntilFlag8And4AreSet();
+	void waitUntilFlag8SetThenSet1000();
 	void waitUntilFlag8SetThenSet1000AndWaitFor4();
 
 	bool waitUntilFlag4IsSetAllowSkip();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index a8bffb6d20..11b66c0b90 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -721,6 +721,15 @@ void DragonsEngine::clearFlags(uint32 flags) {
 uint32 DragonsEngine::getMultipleFlags(uint32 flags) {
 	return _flags & flags;
 }
+
+uint32 DragonsEngine::getAllFlags() {
+	return _flags;
+}
+
+void DragonsEngine::setAllFlags(uint32 flags) {
+	_flags = flags;
+}
+
 void DragonsEngine::setUnkFlags(uint32 flags) {
 	_unkFlags1 |= flags;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index c10663d089..05237dd334 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -201,6 +201,8 @@ public:
 	void setFlags(uint32 flags);
 	void clearFlags(uint32 flags);
 	uint32 getMultipleFlags(uint32 flags);
+	uint32 getAllFlags();
+	void setAllFlags(uint32 flags);
 	bool isFlagSet(uint32 flag);
 	bool isUnkFlagSet(uint32 flag);
 
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index c3845b772d..5b4b28c0be 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -24,12 +24,292 @@
 #include "dragons.h"
 #include "dragons/dragonini.h"
 #include "dragons/talk.h"
+#include "dragons/inventory.h"
+#include "dragons/scene.h"
 
 namespace Dragons {
 
 Minigame4::Minigame4(DragonsEngine *vm) : _vm(vm) {}
 
 void Minigame4::run() {
+	uint16 uVar1;
+	DragonINI *uVar2;
+	uint uVar4;
+	ushort result;
+	int16_t uVar3;
 
+	uVar4 = _vm->getAllFlags();
+	uVar3 = _vm->_inventory->getType(); //inventoryType;
+	uVar2 = _vm->_dragonINIResource->getFlickerRecord();
+	uVar1 = _vm->getCurrentSceneId();
+	// fade_related_calls_with_1f();
+	_vm->reset_screen_maybe();
+	_vm->_dragonINIResource->getFlickerRecord()->sceneId = 0;
+	_vm->_dragonINIResource->setFlickerRecord(NULL);
+	_vm->_inventory->setType(0);
+	_vm->_scene->setSceneId(7);
+	_vm->_scene->loadSceneData(0x8007,0);
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_10);
+	_vm->clearFlags(ENGINE_FLAG_20);
+	_vm->clearFlags(ENGINE_FLAG_80);
+	// DisableVSyncEvent();
+	_vm->clearFlags(ENGINE_FLAG_1);
+	DAT_80090428_videoUpdateRelated = 0;
+	//TODO vsync_updater_function = videoUpdateFunction;
+	//load_palette_into_frame_buffer(4,DAT_8006a3f8);
+	//load_palette_into_frame_buffer_2(4,1,0xff,1);
+	//FUN_80017f30_setSomeOtherFlags_4();
+	//FUN_80017ea0_layer_priority_related(0,2);
+	//FUN_80017ea0_layer_priority_related(1,1);
+	DAT_80090434 = _vm->_actorManager->loadActor(0x18,0,0xcb,0x79,1);
+	DAT_80090440 = _vm->_actorManager->loadActor(0x17,0,0x68,0x7b,1);
+	DAT_80090430 = _vm->_actorManager->loadActor(0x17,0x16,0x9f,0x19,1);
+	DAT_80090438 = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
+	DAT_8009043c = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
+	//EnableVSyncEvent();
+	DAT_80090434->setFlag(ACTOR_FLAG_80);
+	DAT_80090434->setFlag(ACTOR_FLAG_100);
+	DAT_80090434->setFlag(ACTOR_FLAG_200);
+	DAT_80090434->priorityLayer = 3;
+	DAT_80090440->setFlag(ACTOR_FLAG_80);
+	DAT_80090440->setFlag(ACTOR_FLAG_100);
+	DAT_80090440->setFlag(ACTOR_FLAG_200);
+	DAT_80090440->priorityLayer = 3;
+	//DAT_800830e0_soundRelated = 0xf;
+	//UnkSoundFunc5(0xf);
+	//call_fade_related_1f();
+	if (_vm->_dragonINIResource->getRecord(0x1f5)->field_12 == 3) {
+		actorTalk(DAT_80090440,0x3321,0x4A84);
+	}
+	else {
+		actorTalk(DAT_80090440,0x3321,0x49A2);
+		actorTalk(DAT_80090434,0,0x4A56);
+	}
+	result = runDanceBattle();
+	/* field_0x12 */
+	_vm->_dragonINIResource->getRecord(0)->field_12 = result ^ 1;
+	if (_vm->_dragonINIResource->getRecord(0)->field_12 == 1) {
+		_vm->_dragonINIResource->getRecord(0x1f5)->sceneId = 0;
+	}
+//	dragon_ini_pointer[DAT_80063970].field_0x2 = result ^ 1;
+//	if (dragon_ini_pointer[DAT_80063970].field_0x2 == 1) {
+//		/* sceneId */
+//		dragon_ini_pointer[DAT_80063b10 + -1].field_0x1e = 0;
+//	}
+
+	_vm->waitForFrames(2 * 0x3c);
+//	fade_related_calls_with_1f();
+	//DisableVSyncEvent();
+	//vsync_updater_function = (code *)0x0;
+	_vm->setFlags(ENGINE_FLAG_1);
+	//FUN_80017f50_clearSomeFlag4();
+	// EnableVSyncEvent();
+	_vm->_dragonINIResource->setFlickerRecord(uVar2);
+	_vm->_inventory->setType(uVar3);
+//	load_palette_into_frame_buffer
+//			(4,(uint)*(ushort *)
+//					(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10)
+//			   + *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
+//	load_palette_into_frame_buffer_2(4,1,0xff,1);
+	_vm->_scene->setSceneId(uVar1);
+	_vm->setAllFlags(uVar4);
+	uVar2->sceneId = uVar1;
+	_vm->_scene->loadScene(uVar1,0x1e);
+
+}
+
+void Minigame4::actorTalk(Actor *actorId,ushort param_2,uint32 textIndex)
+{
+	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
+	if (actorId == DAT_80090440) {
+		DAT_80090440->updateSequence(9);
+	}
+	else {
+		DAT_80090434->updateSequence(9);
+	}
+
+	actorDialog(actorId, (uint)param_2, textIndex);
+	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
+	if (actorId == DAT_80090440) {
+		DAT_80090440->updateSequence(0);
+	}
+	else {
+		DAT_80090434->updateSequence(0);
+	}
+}
+
+void Minigame4::actorDialog(Actor *actorId, ushort param_2, uint32 textIndex) {
+	uint16 buf[1000];
+	_vm->_talk->loadText(textIndex, buf, 1000);
+	_vm->_talk->displayDialogAroundActor(actorId, param_2, buf, textIndex);
 }
+
+uint16 Minigame4::runDanceBattle() {
+	uint32 uVar1;
+	uint32 uVar2;
+	uint16 auStack2192 [1000];
+	uint16 currentStep;
+	uint16 round1StepPositionTbl [12];
+	uint16 round1DurationTbl [12];
+	uint16 round2StepPositionTbl [12];
+	uint16 round2DurationTbl [12];
+	uint16 round3StepPositionTbl [20];
+	uint16 round3DurationTbl [20];
+
+	Common::File *fd = new Common::File();
+	if (!fd->open("arc4.bin")) {
+		error("Failed to open arc4.bin");
+	}
+
+	for (int i = 0; i < 0xc; i++) {
+		round1StepPositionTbl[i] = fd->readUint16LE();
+	}
+	for (int i = 0; i < 0xc; i++) {
+		round1DurationTbl[i] = fd->readUint16LE();
+	}
+	for (int i = 0; i < 0xc; i++) {
+		round2StepPositionTbl[i] = fd->readUint16LE();
+	}
+	for (int i = 0; i < 0xc; i++) {
+		round2DurationTbl[i] = fd->readUint16LE();
+	}
+	for (int i = 0; i < 0x12; i++) {
+		round3StepPositionTbl[i] = fd->readUint16LE();
+	}
+	for (int i = 0; i < 0x12; i++) {
+		round3DurationTbl[i] = fd->readUint16LE();
+	}
+	fd->close();
+	delete fd;
+
+	currentStep = 0;
+	while (currentStep < 0xc) {
+		uVar1 = singleDanceRound(round1StepPositionTbl[(uint)currentStep],
+								 round1DurationTbl[(uint)currentStep]);
+		if ((uVar1 & 0xffff) != 0) {
+			actorTalk(DAT_80090440,0x3321, 0x4D50);
+			return 1;
+		}
+		currentStep = currentStep + 1;
+	}
+	resetActors();
+	actorTalk(DAT_80090440,0x3321, 0x4ADE);
+	currentStep = 0;
+	while (currentStep < 0xc) {
+		uVar1 = singleDanceRound(round2StepPositionTbl[(uint)currentStep],
+								 round2DurationTbl[(uint)currentStep]);
+		if ((uVar1 & 0xffff) != 0) {
+			actorTalk(DAT_80090440,0x3321,0x4DD4);
+			return 1;
+		}
+		currentStep = currentStep + 1;
+	}
+	resetActors();
+	actorTalk(DAT_80090440,0x3321, 0x4B6A);
+	currentStep = 0;
+	while( true ) {
+		if (0x11 < currentStep) {
+			_vm->_talk->loadText(0x4C0C, auStack2192, 1000);
+			_vm->_talk->displayDialogAroundPoint(auStack2192, 0x27,0xc,0x3321,0,0x4C0C);
+			_vm->waitForFrames(0x10a);
+			DAT_80090440->updateSequence(8);
+			//TODO
+//			if ((((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0)) || (DAT_8008e844 != 0)) ||
+//				(DAT_8008e874 != 0)) {
+//				FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+//			}
+			DAT_80090434->waitUntilFlag8SetThenSet1000AndWaitFor4();
+			DAT_80090434->updateSequence(7);
+			actorTalk(DAT_80090434,0, 0x4CC8);
+			return 0;
+		}
+		uVar1 = singleDanceRound(round3StepPositionTbl[(uint)currentStep],
+								 round3DurationTbl[(uint)currentStep]);
+		if ((uVar1 & 0xffff) != 0) break;
+		currentStep = currentStep + 1;
+	}
+	actorTalk(DAT_80090440,0x3321, 0x4DEE);
+	return 1;
+}
+
+const static uint16 xDancePosTbl[] = { 0xAC, 0xB5, 0xBC, 0xB3, 0xB4, 0xAF };
+const static uint16 yDancePosTbl[] = { 0x1C, 0x23, 0x1A, 0x14, 0x12, 0xF };
+
+const static uint16 uint16_t_ARRAY_80090400[] = { 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
+const static uint16 uint16_t_ARRAY_800903e8[] = { 1, 2, 3, 4, 5, 6 };
+
+uint16 Minigame4::singleDanceRound(uint16 currentDancePosition, uint16 duration) {
+	uint uVar1;
+	uint uVar2;
+
+	DAT_80090438->x_pos = xDancePosTbl[(uint)currentDancePosition];
+	DAT_80090438->y_pos = yDancePosTbl[(uint)currentDancePosition];
+	DAT_80090438->updateSequence(10);
+	DAT_80090430->updateSequence(uint16_t_ARRAY_80090400[(uint)currentDancePosition]);
+	DAT_80090440->updateSequence(uint16_t_ARRAY_800903e8[(uint)currentDancePosition]);
+	while ((DAT_80090434->_sequenceID != uint16_t_ARRAY_800903e8[(uint)currentDancePosition] &&
+			(duration = duration + -1, duration != 0))) {
+		_vm->waitForFrames(1);
+		updateFlickerFromInput((uint)currentDancePosition);
+	}
+	if (DAT_80090434->_sequenceID == uint16_t_ARRAY_800903e8[(uint)currentDancePosition]) {
+		while (duration = duration + -1, duration != 0) {
+			_vm->waitForFrames(1);
+		}
+		DAT_80090438->x_pos = xDancePosTbl[(uint)currentDancePosition];
+		DAT_8009043c->x_pos = DAT_80090438->x_pos;
+		DAT_80090438->y_pos = yDancePosTbl[(uint)currentDancePosition];
+		DAT_8009043c->y_pos = DAT_80090438->y_pos;
+		DAT_8009043c->updateSequence(0xb);
+		DAT_80090430->updateSequence(0x16);
+		uVar1 = 0;
+	}
+	else {
+		uVar1 = FUN_8009009c(1);
+	}
+	return uVar1;
+}
+
+void Minigame4::resetActors() {
+	DAT_80090440->waitUntilFlag8SetThenSet1000();
+	DAT_80090434->waitUntilFlag8SetThenSet1000();
+	while (DAT_80090440->_sequenceID != 0 || DAT_80090434->_sequenceID != 0) {
+		_vm->waitForFrames(1);
+		if (DAT_80090440->_sequenceID != 0 &&
+			DAT_80090440->isFlagSet(ACTOR_FLAG_4) &&
+			DAT_80090440->isFlagSet(ACTOR_FLAG_8)) {
+			DAT_80090440->updateSequence(0);
+		}
+		if (DAT_80090434->_sequenceID != 0 &&
+			DAT_80090434->isFlagSet(ACTOR_FLAG_4) &&
+			DAT_80090434->isFlagSet(ACTOR_FLAG_8)) {
+			DAT_80090434->updateSequence(0);
+		}
+	}
+}
+
+void Minigame4::updateFlickerFromInput(uint16 desiredPosition) {
+
+}
+
+uint16 Minigame4::FUN_8009009c(uint16 unk) {
+	resetActors();
+	if (unk == 0) {
+		DAT_80090440->updateSequence(8);
+		DAT_80090434->updateSequence(7);
+	}
+	else {
+		DAT_80090440->updateSequence(7);
+		DAT_80090434->updateSequence(8);
+	}
+	do {
+		do {
+		} while (DAT_80090440->isFlagSet(ACTOR_FLAG_4));
+
+	} while (DAT_80090434->isFlagSet(ACTOR_FLAG_4));
+	return (uint)unk;
+}
+
+
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame4.h b/engines/dragons/minigame4.h
index 7731503244..4f355ae4f6 100644
--- a/engines/dragons/minigame4.h
+++ b/engines/dragons/minigame4.h
@@ -28,13 +28,33 @@ namespace Dragons {
 
 class DragonsEngine;
 
+class Actor;
+
 class Minigame4 {
 private:
 	DragonsEngine *_vm;
+
+	Actor *DAT_80090434;
+	Actor *DAT_80090440;
+	Actor *DAT_80090430;
+	Actor *DAT_80090438;
+	Actor *DAT_8009043c;
+
+
 public:
+	uint16 DAT_80090428_videoUpdateRelated;
+
 	Minigame4(DragonsEngine *vm);
 
 	void run();
+private:
+	void actorTalk(Actor *actorId,ushort param_2,uint32 textIndex);
+	void actorDialog(Actor *actorId,ushort param_2,uint32 textIndex);
+	uint16 runDanceBattle();
+	uint16 singleDanceRound(uint16 desiredPosition, uint16 duration);
+	void resetActors();
+	void updateFlickerFromInput(uint16 desiredPosition);
+	uint16 FUN_8009009c(uint16 unk);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 5b4cfbdbf3..a3cf0aa1f5 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -63,6 +63,7 @@ public:
 	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader);
 
 	void loadScene(uint32 sceneId, uint32 cameraPointId);
+	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
 	int16 getPriorityAtPosition(Common::Point pos);
 	void draw();
 	bool contains(DragonINI *ini);
@@ -81,7 +82,6 @@ public:
 	void setFgLayerPriority(uint8 newPriority);
 
 private:
-	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
 	void resetActorFrameFlags();
 };
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index b27cee730a..d776798f92 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -34,6 +34,7 @@
 #include "talk.h"
 #include "specialopcodes.h"
 #include "minigame1.h"
+#include "minigame4.h"
 
 
 namespace Dragons {
@@ -71,6 +72,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(3, spcClearEngineFlag10);
 	OPCODE(4, spcSetEngineFlag10);
 
+	OPCODE(7, spcDancingMiniGame);
 	OPCODE(8, spcCastleGardenLogic);
 	OPCODE(9, spcUnk9);
 	OPCODE(0xa, spcUnkA);
@@ -144,6 +146,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x65, spcUnk65ScenePaletteRelated);
 	OPCODE(0x66, spcUnk66);
 
+	OPCODE(0x6a, spcCastleGateSceneLogic);
 	OPCODE(0x6b, spcTransitionToMap);
 	OPCODE(0x6c, spcTransitionFromMap);
 
@@ -183,6 +186,11 @@ void SpecialOpcodes::spcSetEngineFlag10() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_10);
 }
 
+void SpecialOpcodes::spcDancingMiniGame() {
+	Minigame4 minigame4(_vm);
+	minigame4.run();
+}
+
 void SpecialOpcodes::spcCastleGardenLogic() {
 	//TODO
 }
@@ -536,6 +544,10 @@ void SpecialOpcodes::spcUnk66() {
 	_vm->getINI(1)->field_12 = uVar9;
 }
 
+void SpecialOpcodes::spcCastleGateSceneLogic() {
+//TODO spcCastleGateSceneLogic
+}
+
 // 0x80038c1c
 void SpecialOpcodes::panCamera(int16 mode) {
 	int iVar1;
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 6712df9ef8..d83e232888 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -70,6 +70,7 @@ protected:
 	void spcClearEngineFlag10(); // 3
 	void spcSetEngineFlag10();   // 4
 
+	void spcDancingMiniGame(); // 7
 	void spcCastleGardenLogic(); // 8
 	void spcUnk9();
 	void spcUnkA();
@@ -142,6 +143,7 @@ protected:
 	void spcUnk65ScenePaletteRelated(); // 0x65;
 	void spcUnk66();
 
+	void spcCastleGateSceneLogic(); // 0x6a
 	void spcTransitionToMap(); // 0x6b
 	void spcTransitionFromMap(); // 0x6c
 


Commit: a58a8d08c38ce331f8ea9d7ba67374c1d7a88762
    https://github.com/scummvm/scummvm/commit/a58a8d08c38ce331f8ea9d7ba67374c1d7a88762
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Missing bag logic

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 11b66c0b90..f413aa5fa0 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -375,7 +375,7 @@ void DragonsEngine::gameLoop()
 						if (sequenceId == 1) {
 							LAB_800279f4:
 							_inventory->_old_showing_value = uVar7;
-							FUN_8003130c();
+							_inventory->inventoryMissing();
 							actorId = uVar3;
 						}
 						else {
@@ -1089,10 +1089,6 @@ bool DragonsEngine::checkForActionButtonRelease() {
 	return _leftMouseButtonUp || _enterKeyUp;
 }
 
-void DragonsEngine::FUN_8003130c() {
-	error("FUN_8003130c"); //TODO
-}
-
 void DragonsEngine::FUN_80038890() {
 	error("FUN_80038890"); //TODO
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 05237dd334..423b93b6c1 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -262,7 +262,6 @@ private:
 	bool isInputEnabled();
 	bool checkForInventoryButtonRelease();
 
-	void FUN_8003130c();
 	void FUN_80038890();
 	void walkFlickerToObject();
 	void FUN_80038994();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 6968d4f7a0..05754fcc66 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -28,6 +28,7 @@
 #include "inventory.h"
 #include "bag.h"
 #include "scene.h"
+#include "talk.h"
 
 namespace Dragons {
 
@@ -397,4 +398,31 @@ bool Inventory::clearItem(uint16 iniId) {
 	return false;
 }
 
+void Inventory::inventoryMissing() {
+	bool flag8Set;
+	uint32 textIndex;
+	static uint16 counter = 0;
+
+	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+	if (flicker->actor != NULL) {
+		flicker->actor->clearFlag(ACTOR_FLAG_10);
+		if ((_vm->getCurrentSceneId() != 0x2e) || (flicker->actor->resourceID != 0x91)) {
+			flicker->actor->setFlag(ACTOR_FLAG_4);
+		}
+	}
+	flag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_8);
+	if (counter == 0) {
+		textIndex = 0x114FA; //Hey!  My bag is missing!
+	}
+	else {
+		textIndex = 0x11538; //The Chancellor snaked my bag!
+	}
+	counter = counter + 1;
+	_vm->_talk->talkFromIni(0, textIndex);
+	if (flag8Set) {
+		_vm->setFlags(ENGINE_FLAG_8);
+	}
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 019c867283..4e1fa72f0b 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -101,6 +101,7 @@ public:
 	bool clearItem(uint16 iniId);
 
 	Actor *getInventoryItemActor(uint16 iniId);
+	void inventoryMissing();
 
 private:
 	void setPositionFromSceneId(uint32 sceneId);


Commit: 6aaa143fe0e5a74a9e9960a75750318732b9439d
    https://github.com/scummvm/scummvm/commit/6aaa143fe0e5a74a9e9960a75750318732b9439d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: added input handling for mini game 4

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/minigame4.cpp
    engines/dragons/minigame4.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index f413aa5fa0..4aa0a4eb11 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -82,6 +82,12 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_leftKeyUp = false;
 	_rightKeyDown = false;
 	_rightKeyUp = false;
+	_wKeyDown = false;
+	_aKeyDown = false;
+	_sKeyDown = false;
+	_dKeyDown = false;
+	_oKeyDown = false;
+	_pKeyDown = false;
 	reset();
 }
 
@@ -135,6 +141,18 @@ void DragonsEngine::updateEvents() {
 				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RIGHT) {
 					_rightKeyUp = true;
 					_rightKeyDown = false;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_w) {
+					_wKeyDown = false;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_a) {
+					_aKeyDown = false;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_s) {
+					_sKeyDown = false;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_d) {
+					_dKeyDown = false;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_o) {
+					_oKeyDown = false;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_p) {
+					_pKeyDown = false;
 				}
 				break;
 			case Common::EVENT_KEYDOWN:
@@ -142,6 +160,18 @@ void DragonsEngine::updateEvents() {
 					_leftKeyDown = true;
 				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RIGHT) {
 					_rightKeyDown = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_w) {
+					_wKeyDown = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_a) {
+					_aKeyDown = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_s) {
+					_sKeyDown = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_d) {
+					_dKeyDown = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_o) {
+					_oKeyDown = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_p) {
+					_pKeyDown = true;
 				}
 				break;
 			default:
@@ -572,7 +602,7 @@ void DragonsEngine::gameLoop()
 
 
 void DragonsEngine::updateHandler() {
-	data_8006a3a0_flag |= 0x40;
+	videoFlags |= 0x40;
 	//TODO logic here
 
 	updateActorSequences();
@@ -647,7 +677,7 @@ void DragonsEngine::updateHandler() {
 
 	// TODO data_8006a3a0 logic. @ 0x8001c2f4
 
-	data_8006a3a0_flag &= ~0x40;
+	videoFlags &= ~0x40;
 }
 
 uint32 DragonsEngine::calulateTimeLeft() {
@@ -1170,7 +1200,7 @@ void DragonsEngine::FUN_80038994() {
 }
 
 void DragonsEngine::reset_screen_maybe() {
-	data_8006a3a0_flag &= ~0x10;
+	videoFlags &= ~0x10;
 	//TODO
 }
 
@@ -1234,7 +1264,7 @@ void DragonsEngine::reset() {
 	_flags = 0;
 	_unkFlags1 = 0;
 	run_func_ptr_unk_countdown_timer = 0;
-	data_8006a3a0_flag = 0;
+	videoFlags = 0;
 	data_800633fa = 0;
 
 	for(int i = 0; i < 8; i++) {
@@ -1291,6 +1321,30 @@ bool DragonsEngine::checkForUpKeyRelease() {
 	return _upKeyUp;
 }
 
+bool DragonsEngine::isSquareButtonPressed() {
+	return _aKeyDown;
+}
+
+bool DragonsEngine::isTriangleButtonPressed() {
+	return _wKeyDown;
+}
+
+bool DragonsEngine::isCircleButtonPressed() {
+	return _dKeyDown;
+}
+
+bool DragonsEngine::isCrossButtonPressed() {
+	return _sKeyDown;
+}
+
+bool DragonsEngine::isL1ButtonPressed() {
+	return _oKeyDown;
+}
+
+bool DragonsEngine::isR1ButtonPressed() {
+	return _pKeyDown;
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 423b93b6c1..e3c2d087c3 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -142,6 +142,7 @@ public:
 	opCode1AStruct opCode1A_tbl[8];
 
 	uint16 data_800633fc;
+	uint16 videoFlags; // TODO move to screen?
 
 private:
 	Screen *_screen;
@@ -157,7 +158,6 @@ private:
 	uint16 _sceneId1;
 	uint32 _counter;
 	uint32 bit_flags_8006fbd8;
-	uint16 data_8006a3a0_flag; // screen related flags?
 	//unk
 
 	uint16 run_func_ptr_unk_countdown_timer;
@@ -177,6 +177,12 @@ private:
 	bool _leftKeyUp;
 	bool _rightKeyDown;
 	bool _rightKeyUp;
+	bool _wKeyDown;
+	bool _aKeyDown;
+	bool _sKeyDown;
+	bool _dKeyDown;
+	bool _oKeyDown;
+	bool _pKeyDown;
 
 	void (*_sceneUpdateFunction)();
 protected:
@@ -241,6 +247,12 @@ public:
 	bool isActionButtonPressed();
 	bool isLeftKeyPressed();
 	bool isRightKeyPressed();
+	bool isSquareButtonPressed();
+	bool isTriangleButtonPressed();
+	bool isCircleButtonPressed();
+	bool isCrossButtonPressed();
+	bool isL1ButtonPressed();
+	bool isR1ButtonPressed();
 	bool checkForActionButtonRelease();
 	bool checkForDownKeyRelease();
 	bool checkForUpKeyRelease();
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 5b4b28c0be..dfee06c640 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -39,7 +39,7 @@ void Minigame4::run() {
 	int16_t uVar3;
 
 	uVar4 = _vm->getAllFlags();
-	uVar3 = _vm->_inventory->getType(); //inventoryType;
+	uVar3 = _vm->_inventory->getType();
 	uVar2 = _vm->_dragonINIResource->getFlickerRecord();
 	uVar1 = _vm->getCurrentSceneId();
 	// fade_related_calls_with_1f();
@@ -59,32 +59,32 @@ void Minigame4::run() {
 	//TODO vsync_updater_function = videoUpdateFunction;
 	//load_palette_into_frame_buffer(4,DAT_8006a3f8);
 	//load_palette_into_frame_buffer_2(4,1,0xff,1);
-	//FUN_80017f30_setSomeOtherFlags_4();
-	//FUN_80017ea0_layer_priority_related(0,2);
-	//FUN_80017ea0_layer_priority_related(1,1);
-	DAT_80090434 = _vm->_actorManager->loadActor(0x18,0,0xcb,0x79,1);
-	DAT_80090440 = _vm->_actorManager->loadActor(0x17,0,0x68,0x7b,1);
-	DAT_80090430 = _vm->_actorManager->loadActor(0x17,0x16,0x9f,0x19,1);
+	_vm->videoFlags |= 4;
+	_vm->_scene->setBgLayerPriority(2);
+	_vm->_scene->setMgLayerPriority(1);
+	flickerActor = _vm->_actorManager->loadActor(0x18,0,0xcb,0x79,1);
+	bruteActor = _vm->_actorManager->loadActor(0x17,0,0x68,0x7b,1);
+	ps1ControllerActor = _vm->_actorManager->loadActor(0x17,0x16,0x9f,0x19,1);
 	DAT_80090438 = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
 	DAT_8009043c = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
 	//EnableVSyncEvent();
-	DAT_80090434->setFlag(ACTOR_FLAG_80);
-	DAT_80090434->setFlag(ACTOR_FLAG_100);
-	DAT_80090434->setFlag(ACTOR_FLAG_200);
-	DAT_80090434->priorityLayer = 3;
-	DAT_80090440->setFlag(ACTOR_FLAG_80);
-	DAT_80090440->setFlag(ACTOR_FLAG_100);
-	DAT_80090440->setFlag(ACTOR_FLAG_200);
-	DAT_80090440->priorityLayer = 3;
+	flickerActor->setFlag(ACTOR_FLAG_80);
+	flickerActor->setFlag(ACTOR_FLAG_100);
+	flickerActor->setFlag(ACTOR_FLAG_200);
+	flickerActor->priorityLayer = 3;
+	bruteActor->setFlag(ACTOR_FLAG_80);
+	bruteActor->setFlag(ACTOR_FLAG_100);
+	bruteActor->setFlag(ACTOR_FLAG_200);
+	bruteActor->priorityLayer = 3;
 	//DAT_800830e0_soundRelated = 0xf;
 	//UnkSoundFunc5(0xf);
 	//call_fade_related_1f();
 	if (_vm->_dragonINIResource->getRecord(0x1f5)->field_12 == 3) {
-		actorTalk(DAT_80090440,0x3321,0x4A84);
+		actorTalk(bruteActor,0x3321,0x4A84);
 	}
 	else {
-		actorTalk(DAT_80090440,0x3321,0x49A2);
-		actorTalk(DAT_80090434,0,0x4A56);
+		actorTalk(bruteActor,0x3321,0x49A2);
+		actorTalk(flickerActor,0,0x4A56);
 	}
 	result = runDanceBattle();
 	/* field_0x12 */
@@ -92,18 +92,13 @@ void Minigame4::run() {
 	if (_vm->_dragonINIResource->getRecord(0)->field_12 == 1) {
 		_vm->_dragonINIResource->getRecord(0x1f5)->sceneId = 0;
 	}
-//	dragon_ini_pointer[DAT_80063970].field_0x2 = result ^ 1;
-//	if (dragon_ini_pointer[DAT_80063970].field_0x2 == 1) {
-//		/* sceneId */
-//		dragon_ini_pointer[DAT_80063b10 + -1].field_0x1e = 0;
-//	}
 
 	_vm->waitForFrames(2 * 0x3c);
 //	fade_related_calls_with_1f();
 	//DisableVSyncEvent();
 	//vsync_updater_function = (code *)0x0;
 	_vm->setFlags(ENGINE_FLAG_1);
-	//FUN_80017f50_clearSomeFlag4();
+	_vm->videoFlags &= ~(uint16)4;
 	// EnableVSyncEvent();
 	_vm->_dragonINIResource->setFlickerRecord(uVar2);
 	_vm->_inventory->setType(uVar3);
@@ -116,26 +111,25 @@ void Minigame4::run() {
 	_vm->setAllFlags(uVar4);
 	uVar2->sceneId = uVar1;
 	_vm->_scene->loadScene(uVar1,0x1e);
-
 }
 
 void Minigame4::actorTalk(Actor *actorId,ushort param_2,uint32 textIndex)
 {
 	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
-	if (actorId == DAT_80090440) {
-		DAT_80090440->updateSequence(9);
+	if (actorId == bruteActor) {
+		bruteActor->updateSequence(9);
 	}
 	else {
-		DAT_80090434->updateSequence(9);
+		flickerActor->updateSequence(9);
 	}
 
 	actorDialog(actorId, (uint)param_2, textIndex);
 	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
-	if (actorId == DAT_80090440) {
-		DAT_80090440->updateSequence(0);
+	if (actorId == bruteActor) {
+		bruteActor->updateSequence(0);
 	}
 	else {
-		DAT_80090434->updateSequence(0);
+		flickerActor->updateSequence(0);
 	}
 }
 
@@ -146,8 +140,6 @@ void Minigame4::actorDialog(Actor *actorId, ushort param_2, uint32 textIndex) {
 }
 
 uint16 Minigame4::runDanceBattle() {
-	uint32 uVar1;
-	uint32 uVar2;
 	uint16 auStack2192 [1000];
 	uint16 currentStep;
 	uint16 round1StepPositionTbl [12];
@@ -185,51 +177,48 @@ uint16 Minigame4::runDanceBattle() {
 
 	currentStep = 0;
 	while (currentStep < 0xc) {
-		uVar1 = singleDanceRound(round1StepPositionTbl[(uint)currentStep],
-								 round1DurationTbl[(uint)currentStep]);
-		if ((uVar1 & 0xffff) != 0) {
-			actorTalk(DAT_80090440,0x3321, 0x4D50);
+		if (singleDanceRound(round1StepPositionTbl[(uint)currentStep], round1DurationTbl[(uint)currentStep])) {
+			actorTalk(bruteActor,0x3321, 0x4D50);
 			return 1;
 		}
 		currentStep = currentStep + 1;
 	}
 	resetActors();
-	actorTalk(DAT_80090440,0x3321, 0x4ADE);
+	actorTalk(bruteActor,0x3321, 0x4ADE);
 	currentStep = 0;
 	while (currentStep < 0xc) {
-		uVar1 = singleDanceRound(round2StepPositionTbl[(uint)currentStep],
-								 round2DurationTbl[(uint)currentStep]);
-		if ((uVar1 & 0xffff) != 0) {
-			actorTalk(DAT_80090440,0x3321,0x4DD4);
+		if (singleDanceRound(round2StepPositionTbl[(uint)currentStep], round2DurationTbl[(uint)currentStep])) {
+			actorTalk(bruteActor,0x3321,0x4DD4);
 			return 1;
 		}
 		currentStep = currentStep + 1;
 	}
 	resetActors();
-	actorTalk(DAT_80090440,0x3321, 0x4B6A);
+	actorTalk(bruteActor,0x3321, 0x4B6A);
 	currentStep = 0;
 	while( true ) {
 		if (0x11 < currentStep) {
 			_vm->_talk->loadText(0x4C0C, auStack2192, 1000);
 			_vm->_talk->displayDialogAroundPoint(auStack2192, 0x27,0xc,0x3321,0,0x4C0C);
 			_vm->waitForFrames(0x10a);
-			DAT_80090440->updateSequence(8);
+			bruteActor->updateSequence(8);
 			//TODO
 //			if ((((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0)) || (DAT_8008e844 != 0)) ||
 //				(DAT_8008e874 != 0)) {
 //				FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
 //			}
-			DAT_80090434->waitUntilFlag8SetThenSet1000AndWaitFor4();
-			DAT_80090434->updateSequence(7);
-			actorTalk(DAT_80090434,0, 0x4CC8);
+			flickerActor->waitUntilFlag8SetThenSet1000AndWaitFor4();
+			flickerActor->updateSequence(7);
+			actorTalk(flickerActor,0, 0x4CC8);
 			return 0;
 		}
-		uVar1 = singleDanceRound(round3StepPositionTbl[(uint)currentStep],
-								 round3DurationTbl[(uint)currentStep]);
-		if ((uVar1 & 0xffff) != 0) break;
+
+		if (singleDanceRound(round3StepPositionTbl[(uint)currentStep], round3DurationTbl[(uint)currentStep])) {
+			break;
+		}
 		currentStep = currentStep + 1;
 	}
-	actorTalk(DAT_80090440,0x3321, 0x4DEE);
+	actorTalk(bruteActor,0x3321, 0x4DEE);
 	return 1;
 }
 
@@ -240,20 +229,17 @@ const static uint16 uint16_t_ARRAY_80090400[] = { 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
 const static uint16 uint16_t_ARRAY_800903e8[] = { 1, 2, 3, 4, 5, 6 };
 
 uint16 Minigame4::singleDanceRound(uint16 currentDancePosition, uint16 duration) {
-	uint uVar1;
-	uint uVar2;
-
 	DAT_80090438->x_pos = xDancePosTbl[(uint)currentDancePosition];
 	DAT_80090438->y_pos = yDancePosTbl[(uint)currentDancePosition];
 	DAT_80090438->updateSequence(10);
-	DAT_80090430->updateSequence(uint16_t_ARRAY_80090400[(uint)currentDancePosition]);
-	DAT_80090440->updateSequence(uint16_t_ARRAY_800903e8[(uint)currentDancePosition]);
-	while ((DAT_80090434->_sequenceID != uint16_t_ARRAY_800903e8[(uint)currentDancePosition] &&
+	ps1ControllerActor->updateSequence(uint16_t_ARRAY_80090400[(uint)currentDancePosition]);
+	bruteActor->updateSequence(uint16_t_ARRAY_800903e8[(uint)currentDancePosition]);
+	while ((flickerActor->_sequenceID != uint16_t_ARRAY_800903e8[(uint)currentDancePosition] &&
 			(duration = duration + -1, duration != 0))) {
 		_vm->waitForFrames(1);
-		updateFlickerFromInput((uint)currentDancePosition);
+		updateFlickerFromInput();
 	}
-	if (DAT_80090434->_sequenceID == uint16_t_ARRAY_800903e8[(uint)currentDancePosition]) {
+	if (flickerActor->_sequenceID == uint16_t_ARRAY_800903e8[(uint)currentDancePosition]) {
 		while (duration = duration + -1, duration != 0) {
 			_vm->waitForFrames(1);
 		}
@@ -262,52 +248,72 @@ uint16 Minigame4::singleDanceRound(uint16 currentDancePosition, uint16 duration)
 		DAT_80090438->y_pos = yDancePosTbl[(uint)currentDancePosition];
 		DAT_8009043c->y_pos = DAT_80090438->y_pos;
 		DAT_8009043c->updateSequence(0xb);
-		DAT_80090430->updateSequence(0x16);
-		uVar1 = 0;
+		ps1ControllerActor->updateSequence(0x16);
+		return 0;
 	}
-	else {
-		uVar1 = FUN_8009009c(1);
-	}
-	return uVar1;
+
+	return FUN_8009009c(1);
 }
 
 void Minigame4::resetActors() {
-	DAT_80090440->waitUntilFlag8SetThenSet1000();
-	DAT_80090434->waitUntilFlag8SetThenSet1000();
-	while (DAT_80090440->_sequenceID != 0 || DAT_80090434->_sequenceID != 0) {
+	bruteActor->waitUntilFlag8SetThenSet1000();
+	flickerActor->waitUntilFlag8SetThenSet1000();
+	while (bruteActor->_sequenceID != 0 || flickerActor->_sequenceID != 0) {
 		_vm->waitForFrames(1);
-		if (DAT_80090440->_sequenceID != 0 &&
-			DAT_80090440->isFlagSet(ACTOR_FLAG_4) &&
-			DAT_80090440->isFlagSet(ACTOR_FLAG_8)) {
-			DAT_80090440->updateSequence(0);
+		if (bruteActor->_sequenceID != 0 &&
+			bruteActor->isFlagSet(ACTOR_FLAG_4) &&
+			bruteActor->isFlagSet(ACTOR_FLAG_8)) {
+			bruteActor->updateSequence(0);
 		}
-		if (DAT_80090434->_sequenceID != 0 &&
-			DAT_80090434->isFlagSet(ACTOR_FLAG_4) &&
-			DAT_80090434->isFlagSet(ACTOR_FLAG_8)) {
-			DAT_80090434->updateSequence(0);
+		if (flickerActor->_sequenceID != 0 &&
+			flickerActor->isFlagSet(ACTOR_FLAG_4) &&
+			flickerActor->isFlagSet(ACTOR_FLAG_8)) {
+			flickerActor->updateSequence(0);
 		}
 	}
 }
 
-void Minigame4::updateFlickerFromInput(uint16 desiredPosition) {
+void Minigame4::updateFlickerFromInput() {
+	if (_vm->isSquareButtonPressed() && flickerActor->_sequenceID != 1) {
+		flickerActor->updateSequence(1);
+	}
 
+	if (_vm->isCrossButtonPressed() && flickerActor->_sequenceID != 2) {
+		flickerActor->updateSequence(2);
+	}
+
+	if (_vm->isCircleButtonPressed() && flickerActor->_sequenceID != 3) {
+		flickerActor->updateSequence(3);
+	}
+
+	if (_vm->isTriangleButtonPressed() && flickerActor->_sequenceID != 4) {
+		flickerActor->updateSequence(4);
+	}
+
+	if (_vm->isR1ButtonPressed() && flickerActor->_sequenceID != 5) {
+		flickerActor->updateSequence(5);
+	}
+
+	if (_vm->isL1ButtonPressed() && flickerActor->_sequenceID != 6) {
+		flickerActor->updateSequence(6);
+	}
 }
 
 uint16 Minigame4::FUN_8009009c(uint16 unk) {
 	resetActors();
 	if (unk == 0) {
-		DAT_80090440->updateSequence(8);
-		DAT_80090434->updateSequence(7);
+		bruteActor->updateSequence(8);
+		flickerActor->updateSequence(7);
 	}
 	else {
-		DAT_80090440->updateSequence(7);
-		DAT_80090434->updateSequence(8);
+		bruteActor->updateSequence(7);
+		flickerActor->updateSequence(8);
 	}
 	do {
 		do {
-		} while (DAT_80090440->isFlagSet(ACTOR_FLAG_4));
+		} while (bruteActor->isFlagSet(ACTOR_FLAG_4));
 
-	} while (DAT_80090434->isFlagSet(ACTOR_FLAG_4));
+	} while (flickerActor->isFlagSet(ACTOR_FLAG_4));
 	return (uint)unk;
 }
 
diff --git a/engines/dragons/minigame4.h b/engines/dragons/minigame4.h
index 4f355ae4f6..37283fdaa5 100644
--- a/engines/dragons/minigame4.h
+++ b/engines/dragons/minigame4.h
@@ -34,9 +34,9 @@ class Minigame4 {
 private:
 	DragonsEngine *_vm;
 
-	Actor *DAT_80090434;
-	Actor *DAT_80090440;
-	Actor *DAT_80090430;
+	Actor *flickerActor;
+	Actor *bruteActor;
+	Actor *ps1ControllerActor;
 	Actor *DAT_80090438;
 	Actor *DAT_8009043c;
 
@@ -53,7 +53,7 @@ private:
 	uint16 runDanceBattle();
 	uint16 singleDanceRound(uint16 desiredPosition, uint16 duration);
 	void resetActors();
-	void updateFlickerFromInput(uint16 desiredPosition);
+	void updateFlickerFromInput();
 	uint16 FUN_8009009c(uint16 unk);
 };
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index d776798f92..ced56328c1 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -104,6 +104,10 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x2b, spcFlameBedroomEscapeSceneLogic);
 	OPCODE(0x2c, spcStopFlameBedroomEscapeSceneLogic);
 
+	OPCODE(0x2e, spcCastleMoatFull);
+
+	OPCODE(0x30, spcCastleMoatUpdateActorSceneScalePoints);
+
 	OPCODE(0x34, spcUnk34);
 
 	OPCODE(0x36, spcFlickerClearFlag0x80);
@@ -353,6 +357,14 @@ void SpecialOpcodes::spcStopFlameBedroomEscapeSceneLogic() {
 //	}
 }
 
+void SpecialOpcodes::spcCastleMoatFull() {
+	//TODO
+}
+
+void SpecialOpcodes::spcCastleMoatUpdateActorSceneScalePoints() {
+	//TODO
+}
+
 void SpecialOpcodes::spcUnk34() {
 	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;
 	flicker->setFlag(ACTOR_FLAG_80);
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index d83e232888..64fd3eb805 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -101,6 +101,10 @@ protected:
 	void spcFlameBedroomEscapeSceneLogic(); // 0x2b
 	void spcStopFlameBedroomEscapeSceneLogic(); // 0x2b
 
+	void spcCastleMoatFull(); //0x2e
+
+	void spcCastleMoatUpdateActorSceneScalePoints(); //0x30
+
 	void spcUnk34(); //0x34 pitchfork mole.
 
 	void spcFlickerClearFlag0x80(); //0x36


Commit: 6c3596446c4e0361e34eb1723a9f4ae8b7bf01d3
    https://github.com/scummvm/scummvm/commit/6c3596446c4e0361e34eb1723a9f4ae8b7bf01d3
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: added more special opcode stubs

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index ced56328c1..7a877bb446 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -105,8 +105,9 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x2c, spcStopFlameBedroomEscapeSceneLogic);
 
 	OPCODE(0x2e, spcCastleMoatFull);
-
+	OPCODE(0x2f, spcCastleRestoreScalePoints);
 	OPCODE(0x30, spcCastleMoatUpdateActorSceneScalePoints);
+	OPCODE(0x31, spcCastleGateMoatDrainedSceneLogic);
 
 	OPCODE(0x34, spcUnk34);
 
@@ -160,6 +161,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x7b, spcSetCameraXToZero);
 	OPCODE(0x7c, spcDiamondIntroSequenceLogic);
 
+	OPCODE(0x7f, spcFlickerPutOnStGeorgeArmor);
+
 	OPCODE(0x82, spc82CallResetDataMaybe);
 
 	OPCODE(0x89, spcSetUnkFlag2);
@@ -361,10 +364,17 @@ void SpecialOpcodes::spcCastleMoatFull() {
 	//TODO
 }
 
+void SpecialOpcodes::spcCastleRestoreScalePoints() {
+	//TODO spcCastleRestoreScalePoints
+}
+
 void SpecialOpcodes::spcCastleMoatUpdateActorSceneScalePoints() {
 	//TODO
 }
 
+void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
+	// TODO spcCastleGateMoatDrainedSceneLogic
+}
 void SpecialOpcodes::spcUnk34() {
 	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;
 	flicker->setFlag(ACTOR_FLAG_80);
@@ -609,6 +619,10 @@ void SpecialOpcodes::spcDiamondIntroSequenceLogic() {
 	delete cutScene;
 }
 
+void SpecialOpcodes::spcFlickerPutOnStGeorgeArmor() {
+	//TODO here.....
+}
+
 void SpecialOpcodes::spc82CallResetDataMaybe() {
 	//TODO callMaybeResetData();
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 64fd3eb805..dc3a728e12 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -102,8 +102,9 @@ protected:
 	void spcStopFlameBedroomEscapeSceneLogic(); // 0x2b
 
 	void spcCastleMoatFull(); //0x2e
-
+	void spcCastleRestoreScalePoints(); //0x2f
 	void spcCastleMoatUpdateActorSceneScalePoints(); //0x30
+	void spcCastleGateMoatDrainedSceneLogic(); //0x31
 
 	void spcUnk34(); //0x34 pitchfork mole.
 
@@ -157,6 +158,8 @@ protected:
 	void spcSetCameraXToZero(); //0x7b
 	void spcDiamondIntroSequenceLogic(); //0x7c
 
+	void spcFlickerPutOnStGeorgeArmor(); //0x7f
+
 	void spc82CallResetDataMaybe(); // 0x82
 
 	void spcSetUnkFlag2(); // 0x89


Commit: f5c3790df411e3fca77d47731cb3e69cd32a040e
    https://github.com/scummvm/scummvm/commit/f5c3790df411e3fca77d47731cb3e69cd32a040e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added more specialOpcode logic

Changed paths:
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index d9ffa1bd25..d78d43dc05 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -672,5 +672,9 @@ void CutScene::loadPalettes() {
 	fd.read(_palettes, 256 * 2 * 4);
 }
 
+void CutScene::flickerReturnsCutScene() {
+	//TODO
+}
+
 
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index 83416b1014..27d0fa74fa 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -60,6 +60,7 @@ public:
 	void scene1();
 	void diamondScene();
 	void knightsSavedBackAtCastle();
+	void flickerReturnsCutScene();
 
 private:
 	//Scene 1 related functions
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 7a877bb446..60caa1c3bb 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -115,21 +115,23 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0x38, spcNoop1);
 	OPCODE(0x39, spcTownAngryVillagersSceneLogic);
-
+	OPCODE(0x3a, spcBlackDragonCrashThroughGate);
 	OPCODE(0x3b, spcSetEngineFlag0x2000000);
 	OPCODE(0x3c, spcClearEngineFlag0x2000000);
 	OPCODE(0x3d, clearSceneUpdateFunction);
 	OPCODE(0x3e, spcZigmondFraudSceneLogic);
 	OPCODE(0x3f, clearSceneUpdateFunction);
 	OPCODE(0x40, spcZigmondFraudSceneLogic1);
-
+	OPCODE(0x41, spcBrokenBlackDragonSceneLogic);
 	OPCODE(0x42, spcDodoUnderAttackSceneLogic);
+	OPCODE(0x43, spcForestWithoutDodoSceneLogic);
 
 	OPCODE(0x46, spcBlackDragonOnHillSceneLogic);
 
 	OPCODE(0x49, spcLoadScene1);
 
 	OPCODE(0x4b, spcKnightsSavedCastleCutScene);
+	OPCODE(0x4c, spcFlickerReturnsCutScene);
 
 	OPCODE(0x4e, spcUnk4e);
 	OPCODE(0x4f, spcUnk4f);
@@ -146,6 +148,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x5e, spcUnk5e);
 	OPCODE(0x5f, spcUnk5f);
 
+	OPCODE(0x61, spcCastleBuildBlackDragonSceneLogic);
+	OPCODE(0x62, spcStopSceneUpdateFunction)
 	OPCODE(0x63, spcSetInventorySequenceTo5);
 	OPCODE(0x64, spcResetInventorySequence);
 	OPCODE(0x65, spcUnk65ScenePaletteRelated);
@@ -162,12 +166,14 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x7c, spcDiamondIntroSequenceLogic);
 
 	OPCODE(0x7f, spcFlickerPutOnStGeorgeArmor);
-
+	OPCODE(0x80, spcUnk80FlickerArmorOn);
+	OPCODE(0x81, spcShakeScreenSceneLogic);
 	OPCODE(0x82, spc82CallResetDataMaybe);
+	OPCODE(0x83, spcStopScreenShakeUpdater);
 
 	OPCODE(0x89, spcSetUnkFlag2);
 	OPCODE(0x8a, spcClearUnkFlag2);
-
+	OPCODE(0x8b, spcUnk8b);
 }
 
 #undef OPCODE
@@ -392,6 +398,28 @@ void SpecialOpcodes::spcNoop1() {
 void SpecialOpcodes::spcTownAngryVillagersSceneLogic() {
 	//TODO
 }
+
+void SpecialOpcodes::spcBlackDragonCrashThroughGate() {
+	//TODO spcBlackDragonCrashThroughGate
+	//shake screen.
+//	iVar18 = 1;
+//	local_fd8 = DAT_8001170c;
+//	local_fd4 = DAT_80011710;
+//	local_fd0 = DAT_80011714;
+//	local_fcc = uint32_t_80011718;
+//	local_fc8 = DAT_8001171c;
+//	local_fc4 = DAT_80011720;
+//	local_fc0 = DAT_80011724;
+//	local_fbc = DAT_80011728;
+//	DAT_8006339a = (short)local_10a0;
+//	while (screenShakeOffset = DAT_8006339a, DAT_8006339a != 0) {
+//		screenShakeOffset = DAT_8006339a;
+//		ContinueGame?();
+//		DAT_8006339a = *(short *)((int)&local_fd8 + ((iVar18 << 0x10) >> 0xf));
+//		iVar18 = iVar18 + 1;
+//	}
+}
+
 void SpecialOpcodes::spcSetEngineFlag0x2000000() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_2000000);
 }
@@ -454,11 +482,20 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic1() {
 	setupTableBasedSceneUpdateFunction(300,1,0x708);
 }
 
+void SpecialOpcodes::spcBrokenBlackDragonSceneLogic() {
+	//TODO spcBrokenBlackDragonSceneLogic
+}
+
 void SpecialOpcodes::spcDodoUnderAttackSceneLogic() {
 	//TODO
 	sceneUpdater.sequenceID = -1;
 }
 
+void SpecialOpcodes::spcForestWithoutDodoSceneLogic() {
+	//TODO
+	sceneUpdater.sequenceID = -1;
+}
+
 void SpecialOpcodes::spcBlackDragonOnHillSceneLogic() {
 	//TODO
 	sceneUpdater.sequenceID = -1;
@@ -523,6 +560,14 @@ void SpecialOpcodes::spcUnk5f() {
 	panCamera(2);
 }
 
+void SpecialOpcodes::spcCastleBuildBlackDragonSceneLogic() {
+	_vm->setSceneUpdateFunction(castleBuildingBlackDragon2UpdateFunction);
+}
+
+void SpecialOpcodes::spcStopSceneUpdateFunction() {
+	_vm->setSceneUpdateFunction(NULL);
+}
+
 void SpecialOpcodes::spcSetInventorySequenceTo5() {
 	_vm->_inventory->updateActorSequenceId(5);
 }
@@ -627,6 +672,13 @@ void SpecialOpcodes::spc82CallResetDataMaybe() {
 	//TODO callMaybeResetData();
 }
 
+void SpecialOpcodes::spcStopScreenShakeUpdater() {
+	_vm->setSceneUpdateFunction(NULL);
+	//TODO spcStopScreenShakeUpdater
+//	DAT_8006339a = 0;
+//	screenShakeOffset = 0;
+}
+
 void SpecialOpcodes::spcSetUnkFlag2() {
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 }
@@ -635,6 +687,10 @@ void SpecialOpcodes::spcClearUnkFlag2() {
 	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
 }
 
+void SpecialOpcodes::spcUnk8b() {
+	//TODO sceneId_1 = DAT_80063e20; //0xA
+}
+
 void SpecialOpcodes::spcLoadScene1() {
 	CutScene *cutScene = new CutScene(_vm);
 	cutScene->scene1();
@@ -646,6 +702,13 @@ void SpecialOpcodes::spcKnightsSavedCastleCutScene() {
 	cutScene->knightsSavedBackAtCastle();
 	delete cutScene;
 }
+
+void SpecialOpcodes::spcFlickerReturnsCutScene() {
+	CutScene *cutScene = new CutScene(_vm);
+	cutScene->flickerReturnsCutScene();
+	delete cutScene;
+}
+
 void SpecialOpcodes::spcTransitionToMap() {
 	//TODO map transition
 //	DAT_8006a422 = 0;
@@ -731,6 +794,16 @@ void SpecialOpcodes::setupTableBasedSceneUpdateFunction(uint16 initialCounter, u
 	_vm->setSceneUpdateFunction(tableBasedSceneUpdateFunction);
 }
 
+void SpecialOpcodes::spcUnk80FlickerArmorOn() {
+	Actor *actor = _vm->_dragonINIResource->getRecord(0x21f)->actor;
+	actor->priorityLayer = 2;
+	actor->clearFlag(ACTOR_FLAG_100);
+}
+
+void SpecialOpcodes::spcShakeScreenSceneLogic() {
+	_vm->setSceneUpdateFunction(shakeScreenUpdateFunction);
+}
+
 void pizzaUpdateFunction() {
 		static int16 DAT_800634bc = 0;
 		DragonsEngine *vm = getEngine();
@@ -814,4 +887,41 @@ void tableBasedSceneUpdateFunction() {
 	}
 }
 
+void castleBuildingBlackDragon2UpdateFunction() {
+	DragonINI *ini;
+	DragonsEngine *vm = getEngine();
+
+	ini = vm->_dragonINIResource->getRecord(0x231);
+	if (ini->field_10 <= 0) {
+		if (ini->field_12 == 0) {
+			ini->actor->updateSequence(0xb);
+			ini->field_10 = 0x68;
+			ini->field_12 = 1;
+		}
+		else if (ini->field_12 == 1) {
+			ini->actor->updateSequence(4);
+			ini->field_10 = vm->getRand(0xb4);
+			ini->field_12 = 0;
+		}
+	}
+}
+
+void shakeScreenUpdateFunction() {
+	//TODO shakeScreenUpdateFunction
+//	uint uVar1;
+//
+//	if (int16_t_80072898 == 0) {
+//		DAT_80083148 = DAT_80083148 ^ 1;
+//		uVar1 = 1;
+//		if (DAT_80083148 == 0) {
+//			uVar1 = 0xffffffff;
+//		}
+//		DAT_8006339a = (undefined2)uVar1;
+//		screenShakeOffset = DAT_8006339a;
+//	}
+//	else {
+//		int16_t_80072898 = int16_t_80072898 - 1;
+//		uVar1 = (uint)(ushort)int16_t_80072898;
+//	}
+}
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index dc3a728e12..d97860e204 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -112,21 +112,23 @@ protected:
 
 	void spcNoop1(); // 0x38
 	void spcTownAngryVillagersSceneLogic(); //0x39
-
+	void spcBlackDragonCrashThroughGate(); //0x3a
 	void spcSetEngineFlag0x2000000(); // 0x3b
 	void spcClearEngineFlag0x2000000(); // 0x3c
 
 	void spcZigmondFraudSceneLogic(); // 0x3e
 
 	void spcZigmondFraudSceneLogic1(); // 0x40
-
+	void spcBrokenBlackDragonSceneLogic(); // 0x41
 	void spcDodoUnderAttackSceneLogic(); //0x42
+	void spcForestWithoutDodoSceneLogic();
 
 	void spcBlackDragonOnHillSceneLogic(); //0x46
 
 	void spcLoadScene1(); // 0x49
 
 	void spcKnightsSavedCastleCutScene(); //0x4b
+	void spcFlickerReturnsCutScene(); // 0x4c
 
 	void spcUnk4e();
 	void spcUnk4f();
@@ -143,6 +145,8 @@ protected:
 	void spcUnk5e();
 	void spcUnk5f();
 
+	void spcCastleBuildBlackDragonSceneLogic(); //0x61
+	void spcStopSceneUpdateFunction(); //0x62
 	void spcSetInventorySequenceTo5(); // 0x63
 	void spcResetInventorySequence(); // 0x64
 	void spcUnk65ScenePaletteRelated(); // 0x65;
@@ -159,11 +163,14 @@ protected:
 	void spcDiamondIntroSequenceLogic(); //0x7c
 
 	void spcFlickerPutOnStGeorgeArmor(); //0x7f
-
+	void spcUnk80FlickerArmorOn(); //0x80
+	void spcShakeScreenSceneLogic(); //0x81
 	void spc82CallResetDataMaybe(); // 0x82
+	void spcStopScreenShakeUpdater(); // 0x83
 
 	void spcSetUnkFlag2(); // 0x89
 	void spcClearUnkFlag2(); //0x8a
+	void spcUnk8b(); //0x8b
 
 	void setupTableBasedSceneUpdateFunction(uint16 initialCounter, uint16 numSequences, uint16 sequenceDuration);
 private:
@@ -178,6 +185,8 @@ private:
 
 void pizzaUpdateFunction();
 void tableBasedSceneUpdateFunction();
+void castleBuildingBlackDragon2UpdateFunction();
+void shakeScreenUpdateFunction();
 
 } // End of namespace Dragons
 


Commit: b1536f236028c1bf0d48e4345e7d5277766063ce
    https://github.com/scummvm/scummvm/commit/b1536f236028c1bf0d48e4345e7d5277766063ce
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More special opcode stubs

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 60caa1c3bb..4d0ae02489 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -98,6 +98,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x23, spcSetEngineFlag0x200000);
 	OPCODE(0x24, spcClearEngineFlag0x200000);
 
+	OPCODE(0x26, spcMenInMinesSceneLogic);
+	OPCODE(0x27, spcStopMenInMinesSceneLogic);
 	OPCODE(0x28, spcMonksAtBarSceneLogic);
 	OPCODE(0x29, spcStopMonksAtBarSceneLogic);
 
@@ -316,6 +318,14 @@ void SpecialOpcodes::spcClearEngineFlag0x200000() {
 	_vm->clearFlags(ENGINE_FLAG_200000);
 }
 
+void SpecialOpcodes::spcMenInMinesSceneLogic() {
+	//TODO
+}
+
+void SpecialOpcodes::spcStopMenInMinesSceneLogic() {
+	//TODO
+}
+
 void SpecialOpcodes::spcMonksAtBarSceneLogic() {
 	//TODO
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index d97860e204..f003eac29f 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -95,6 +95,8 @@ protected:
 	void spcSetEngineFlag0x200000(); // 0x23
 	void spcClearEngineFlag0x200000(); // 0x24
 
+	void spcMenInMinesSceneLogic(); //0x26
+	void spcStopMenInMinesSceneLogic(); //0x27
 	void spcMonksAtBarSceneLogic(); //0x28
 	void spcStopMonksAtBarSceneLogic(); //0x29
 


Commit: d5aec116c1748c80e1cccc34ed231051a234138d
    https://github.com/scummvm/scummvm/commit/d5aec116c1748c80e1cccc34ed231051a234138d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added more special script logic.

Changed paths:
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/scene.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index d78d43dc05..2696bba387 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -676,5 +676,9 @@ void CutScene::flickerReturnsCutScene() {
 	//TODO
 }
 
+void CutScene::knightsSavedAgain() {
+	//TODO
+}
+
 
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index 27d0fa74fa..23a430e004 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -61,6 +61,7 @@ public:
 	void diamondScene();
 	void knightsSavedBackAtCastle();
 	void flickerReturnsCutScene();
+	void knightsSavedAgain();
 
 private:
 	//Scene 1 related functions
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 05754fcc66..7dad65ee4c 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -32,7 +32,6 @@
 
 namespace Dragons {
 
-#define ACTOR_INVENTORY_OFFSET 0x17
 
 static const Common::Point positionTable[4] = {
 		{2,0},
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 4e1fa72f0b..31e40fbcda 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -36,6 +36,8 @@ class DragonINIResource;
 
 #define DRAGONS_MAX_INVENTORY_ITEMS 0x29
 
+#define ACTOR_INVENTORY_OFFSET 0x17
+
 class Inventory {
 public:
 	int16 _old_showing_value;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 70b58a44ab..162594f4d2 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -343,7 +343,7 @@ void Scene::draw() {
 				actor->frame->height != 0
 				) {
 				Graphics::Surface *s = actor->surface;
-				int x = actor->x_pos - actor->frame->xOffset - _camera.x;
+				int x = actor->x_pos - actor->frame->xOffset - (actor->_actorID < ACTOR_INVENTORY_OFFSET ? _camera.x : 0);
 				int y = actor->y_pos - actor->frame->yOffset - _camera.y;
 				//int x = ini->x;// - actor->frame_vram_x;
 				//int y = ini->y;// - actor->frame_vram_y;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 4d0ae02489..d478a533b8 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -20,6 +20,7 @@
  *
  */
 
+#include "dragons/actorresource.h"
 #include "dragons/cursor.h"
 #include "dragons/cutscene.h"
 #include "dragons/dragons.h"
@@ -79,7 +80,9 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0xb, clearSceneUpdateFunction);
 	OPCODE(0xc, spcUnkC);
 	OPCODE(0xd, spcFadeScreen);
-
+	OPCODE(0xe, spcLadyOfTheLakeCapturedSceneLogic);
+	OPCODE(0xf, spcLadyOfTheLakeCapturedSceneLogic);
+	OPCODE(0x10, spcStopLadyOfTheLakeCapturedSceneLogic);
 	OPCODE(0x11, spc11ShakeScreen);
 	OPCODE(0x12, spcHandleInventionBookTransition);
 	OPCODE(0x13, spcUnk13InventionBookCloseRelated);
@@ -88,7 +91,7 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0x17, spcKnightPoolReflectionLogic);
 	OPCODE(0x18, clearSceneUpdateFunction);
-
+	OPCODE(0x19, spcWalkOnStilts);
 	OPCODE(0x1a, spcActivatePizzaMakerActor);
 	OPCODE(0x1b, spcDeactivatePizzaMakerActor);
 	OPCODE(0x1c, spcPizzaMakerActorStopWorking);
@@ -97,7 +100,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x22, spcClearEngineFlag0x20000);
 	OPCODE(0x23, spcSetEngineFlag0x200000);
 	OPCODE(0x24, spcClearEngineFlag0x200000);
-
+	OPCODE(0x25, spcFlickerSetPriority2);
 	OPCODE(0x26, spcMenInMinesSceneLogic);
 	OPCODE(0x27, spcStopMenInMinesSceneLogic);
 	OPCODE(0x28, spcMonksAtBarSceneLogic);
@@ -134,7 +137,7 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0x4b, spcKnightsSavedCastleCutScene);
 	OPCODE(0x4c, spcFlickerReturnsCutScene);
-
+	OPCODE(0x4d, spcKnightsSavedAgainCutScene);
 	OPCODE(0x4e, spcUnk4e);
 	OPCODE(0x4f, spcUnk4f);
 	OPCODE(0x50, spcCloseInventory);
@@ -160,13 +163,18 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x6a, spcCastleGateSceneLogic);
 	OPCODE(0x6b, spcTransitionToMap);
 	OPCODE(0x6c, spcTransitionFromMap);
+	OPCODE(0x6d, spcCaveOfDilemmaSceneLogic);
+
+	OPCODE(0x70, spcLoadLadyOfTheLakeActor);
 
 	OPCODE(0x77, spcJesterInLibrarySceneLogic);
 
+	OPCODE(0x79, spcSetUnkFlag2);
 	OPCODE(0x7a, spcBlackDragonDialogForCamelhot);
 	OPCODE(0x7b, spcSetCameraXToZero);
 	OPCODE(0x7c, spcDiamondIntroSequenceLogic);
-
+	OPCODE(0x7d, spcLoadFileS10a6act);
+	OPCODE(0x7e, spcLoadFileS10a7act);
 	OPCODE(0x7f, spcFlickerPutOnStGeorgeArmor);
 	OPCODE(0x80, spcUnk80FlickerArmorOn);
 	OPCODE(0x81, spcShakeScreenSceneLogic);
@@ -236,6 +244,24 @@ void SpecialOpcodes::spcFadeScreen() {
 	//TODO call_fade_related_1f();
 }
 
+void SpecialOpcodes::spcLadyOfTheLakeCapturedSceneLogic() {
+	//TODO
+	//DAT_80083148 = 0;
+	//DAT_80083154 = 0;
+	_vm->setSceneUpdateFunction(ladyOfTheLakeCapturedUpdateFunction);
+}
+
+void SpecialOpcodes::spcStopLadyOfTheLakeCapturedSceneLogic() {
+	_vm->setSceneUpdateFunction(NULL);
+// TODO
+//	PauseCDMusic();
+//	if ((DAT_80083148 != 0) || (DAT_80083154 != 0)) {
+//		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
+//	}
+//	DAT_80083148 = 0;
+//	DAT_80083154 = 0;
+}
+
 void SpecialOpcodes::spc11ShakeScreen() {
 	//TODO
 //	iVar18 = 1;
@@ -287,6 +313,37 @@ void SpecialOpcodes::spcKnightPoolReflectionLogic() {
 	//TODO
 }
 
+void SpecialOpcodes::spcWalkOnStilts() {
+	//TODO
+	ushort uVar1;
+	bool bVar2;
+	void *pvVar3;
+	uint actorId;
+	uint uVar4;
+
+	Actor *actor = _vm->_dragonINIResource->getRecord(0x2a0)->actor;
+	Actor *actor1 = _vm->_dragonINIResource->getRecord(0x2a9)->actor;
+
+	actor->field_2c = actor->field_2c / 3;
+	actor->field_30 = actor->field_30 / 3;
+	bVar2 = false;
+	while (actor->isFlagSet(ACTOR_FLAG_10)) {
+		//pvVar3 = actor->frame_pointer_maybe;
+		if (actor->frame->field_c == 0) { //*(short *)((int)pvVar3 + 0xc) == 0) {
+			bVar2 = false;
+		}
+		else {
+			if (((!bVar2) && (0x6a < actor->y_pos)) && (actor->y_pos < 0x96)) {
+				bVar2 = true;
+				actor1->x_pos = actor->x_pos - READ_LE_INT16(actor->frame->frameDataOffset); //*(short *)((int)pvVar3 + 0xe);
+				actor1->y_pos = actor->y_pos - READ_LE_INT16(actor->frame->frameDataOffset + 2); //*(short *)((int)pvVar3 + 0x10);
+				actor1->updateSequence(9);
+			}
+		}
+		_vm->waitForFrames(1);
+	}
+}
+
 void SpecialOpcodes::spcActivatePizzaMakerActor() {
 	_vm->setSceneUpdateFunction(pizzaUpdateFunction);
 }
@@ -318,6 +375,10 @@ void SpecialOpcodes::spcClearEngineFlag0x200000() {
 	_vm->clearFlags(ENGINE_FLAG_200000);
 }
 
+void SpecialOpcodes::spcFlickerSetPriority2() {
+	_vm->_dragonINIResource->getFlickerRecord()->actor->priorityLayer = 2;
+}
+
 void SpecialOpcodes::spcMenInMinesSceneLogic() {
 	//TODO
 }
@@ -674,6 +735,14 @@ void SpecialOpcodes::spcDiamondIntroSequenceLogic() {
 	delete cutScene;
 }
 
+void SpecialOpcodes::spcLoadFileS10a6act() {
+	//TODO is this needed?
+}
+
+void SpecialOpcodes::spcLoadFileS10a7act() {
+	//TODO is this needed?
+}
+
 void SpecialOpcodes::spcFlickerPutOnStGeorgeArmor() {
 	//TODO here.....
 }
@@ -719,6 +788,12 @@ void SpecialOpcodes::spcFlickerReturnsCutScene() {
 	delete cutScene;
 }
 
+void SpecialOpcodes::spcKnightsSavedAgainCutScene() {
+	CutScene *cutScene = new CutScene(_vm);
+	cutScene->knightsSavedAgain();
+	delete cutScene;
+}
+
 void SpecialOpcodes::spcTransitionToMap() {
 	//TODO map transition
 //	DAT_8006a422 = 0;
@@ -733,6 +808,29 @@ void SpecialOpcodes::spcTransitionFromMap() {
 	//TODO map transition
 }
 
+void SpecialOpcodes::spcCaveOfDilemmaSceneLogic() {
+	_vm->setSceneUpdateFunction(caveOfDilemmaUpdateFunction);
+}
+
+void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
+	//TODO
+	DragonINI *ini = _vm->_dragonINIResource->getRecord(0x2a7);
+	_vm->_actorManager->loadActor(0xcd, ini->actor->_actorID);
+	ini->actor->setFlag(ACTOR_FLAG_4);
+	ini->actorResourceId = 0xcd;
+	//DisableVSyncEvent();
+//	uVar17 = (uint)(ushort)dragon_ini_pointer[DAT_8006398c + -1].field_0x1c;
+//	uVar7 = load_actor_file(0xcc);
+//	file_read_to_buffer(s_s12a6.act_80011740,(&actor_dictionary)[(uVar7 & 0xffff) * 2]);
+//	actors[uVar17].actorFileDictionaryIndex = (uint16_t)uVar7;
+//	actors[uVar17].resourceID = 0xcd;
+//	iVar18 = DAT_8006398c;
+//	actors[uVar17].flags = actors[uVar17].flags | 4;
+//	dragon_ini_pointer[iVar18 + -1].x = 0xcd;
+//	LAB_8002ad94:
+	//EnableVSyncEvent();
+}
+
 void SpecialOpcodes::spcJesterInLibrarySceneLogic() {
 	//TODO
 }
@@ -934,4 +1032,57 @@ void shakeScreenUpdateFunction() {
 //		uVar1 = (uint)(ushort)int16_t_80072898;
 //	}
 }
+
+void ladyOfTheLakeCapturedUpdateFunction() {
+	const uint32 dialogTbl[] = {
+			0x490C8, 0x490FC, 0x4913A
+	};
+	static int ladyofLakeCountdownTimer = 0x12c;
+	static uint8 ladyOfLakeDialogIndex = 0;
+	DragonsEngine *vm = getEngine();
+
+	if (!vm->isFlagSet(ENGINE_FLAG_8000)) {
+		ladyofLakeCountdownTimer--;
+		if (ladyofLakeCountdownTimer == 0) {
+			vm->_talk->playDialogAudioDontWait(dialogTbl[ladyOfLakeDialogIndex]);
+			if (ladyOfLakeDialogIndex == 2) {
+				ladyOfLakeDialogIndex = 0;
+			} else {
+				ladyOfLakeDialogIndex++;
+			}
+			ladyofLakeCountdownTimer = 0x708;
+		}
+	}
+}
+
+void caveOfDilemmaUpdateFunction() {
+	static int32 counter = 0;
+	static int16 direction = 1;
+	int16 yOffset;
+	Actor *oldManActor;
+	Actor *cloudChairActor;
+	DragonsEngine *vm = getEngine();
+
+	if (counter == 0) {
+		oldManActor = vm->_dragonINIResource->getRecord(0x161)->actor;
+		cloudChairActor = vm->_dragonINIResource->getRecord(0x160)->actor;
+		if (oldManActor->y_pos < 0x53) {
+			oldManActor->y_pos = 0x52;
+			cloudChairActor->y_pos = 0x52;
+			direction = 1;
+		}
+		if (0x5b < oldManActor->y_pos) {
+			oldManActor->y_pos = 0x5c;
+			cloudChairActor->y_pos = 0x5c;
+			direction = -1;
+		}
+		yOffset = direction * 2;
+		oldManActor->y_pos = oldManActor->y_pos + yOffset;
+		cloudChairActor->y_pos = cloudChairActor->y_pos + yOffset;
+		counter = 10;
+	}
+	else {
+		counter--;
+	}
+}
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index f003eac29f..6f6177489e 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -77,7 +77,8 @@ protected:
 
 	void spcUnkC();
 	void spcFadeScreen(); // 0xd
-
+	void spcLadyOfTheLakeCapturedSceneLogic(); // 0xe, 0xf
+	void spcStopLadyOfTheLakeCapturedSceneLogic(); // 0x10
 	void spc11ShakeScreen(); //0x11
 	void spcHandleInventionBookTransition(); // 0x12
 	void spcUnk13InventionBookCloseRelated(); //0x13
@@ -86,6 +87,7 @@ protected:
 
 	void spcKnightPoolReflectionLogic(); //0x17
 
+	void spcWalkOnStilts(); //0x19
 	void spcActivatePizzaMakerActor(); // 0x1a
 	void spcDeactivatePizzaMakerActor(); // 0x1b
 	void spcPizzaMakerActorStopWorking(); // 0x1c
@@ -94,7 +96,7 @@ protected:
 	void spcClearEngineFlag0x20000(); // 0x22
 	void spcSetEngineFlag0x200000(); // 0x23
 	void spcClearEngineFlag0x200000(); // 0x24
-
+	void spcFlickerSetPriority2(); // 0x25
 	void spcMenInMinesSceneLogic(); //0x26
 	void spcStopMenInMinesSceneLogic(); //0x27
 	void spcMonksAtBarSceneLogic(); //0x28
@@ -131,7 +133,7 @@ protected:
 
 	void spcKnightsSavedCastleCutScene(); //0x4b
 	void spcFlickerReturnsCutScene(); // 0x4c
-
+	void spcKnightsSavedAgainCutScene(); //0c4d
 	void spcUnk4e();
 	void spcUnk4f();
 	void spcCloseInventory(); // 0x50
@@ -157,13 +159,17 @@ protected:
 	void spcCastleGateSceneLogic(); // 0x6a
 	void spcTransitionToMap(); // 0x6b
 	void spcTransitionFromMap(); // 0x6c
+	void spcCaveOfDilemmaSceneLogic(); // 0x6d
+
+	void spcLoadLadyOfTheLakeActor(); //0x70
 
 	void spcJesterInLibrarySceneLogic(); // 0x77
 
 	void spcBlackDragonDialogForCamelhot(); // 0x7a
 	void spcSetCameraXToZero(); //0x7b
 	void spcDiamondIntroSequenceLogic(); //0x7c
-
+	void spcLoadFileS10a6act(); //0x7d
+	void spcLoadFileS10a7act(); //0x7e
 	void spcFlickerPutOnStGeorgeArmor(); //0x7f
 	void spcUnk80FlickerArmorOn(); //0x80
 	void spcShakeScreenSceneLogic(); //0x81
@@ -189,6 +195,8 @@ void pizzaUpdateFunction();
 void tableBasedSceneUpdateFunction();
 void castleBuildingBlackDragon2UpdateFunction();
 void shakeScreenUpdateFunction();
+void ladyOfTheLakeCapturedUpdateFunction();
+void caveOfDilemmaUpdateFunction();
 
 } // End of namespace Dragons
 
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index c4d0b4796c..1394ced37c 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -1099,4 +1099,8 @@ void Talk::FUN_8001a7c4_clearDialogBoxMaybe() {
 			(uint)DAT_8008e848_dialogBox_x2,(uint)DAT_8008e874_dialogBox_y2);
 }
 
+void Talk::playDialogAudioDontWait(uint32 textIndex) {
+	_vm->_sound->playSpeech(textIndex);
+}
+
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index f8c219fce6..088c1e5efa 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -87,6 +87,8 @@ public:
 
 	uint somethingTextAndSpeechAndAnimRelated(Actor *actor,int16 sequenceId1,int16 sequenceId2,uint32 textIndex, uint16 param_5);
 	void FUN_8001a7c4_clearDialogBoxMaybe(); //clear box maybe?
+
+	void playDialogAudioDontWait(uint32 textIndex);
 private:
 	void FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2); //clear box maybe?
 	void copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength);


Commit: 77d0b6770e22c56f862c7503688a6c733aa84806
    https://github.com/scummvm/scummvm/commit/77d0b6770e22c56f862c7503688a6c733aa84806
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on mini game 3. Work on cutscenes.

Changed paths:
  A engines/dragons/minigame3.cpp
  A engines/dragons/minigame3.h
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/cursor.cpp
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/module.mk
    engines/dragons/screen.cpp
    engines/dragons/screen.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 58d00a7e3c..716bdae3bc 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -156,7 +156,7 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	sequenceTimer = 0;
 	target_x_pos = x;
 	target_y_pos = y;
-	field_e = 0x100;
+	scale = 0x100;
 	_sequenceID2 = 0;
 	flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
 	frame_width = 0;
@@ -795,8 +795,8 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 
 	void Actor::walkPath() {
 		if (isFlagClear(Dragons::ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
-			field_24_x += (((field_e * field_2c) / 256) * 5) / 4;
-			field_28_y += (((field_e * field_30) / 256) * 5) / 4;
+			field_24_x += (((scale * field_2c) / 256) * 5) / 4;
+			field_28_y += (((scale * field_30) / 256) * 5) / 4;
 
 			if ( (field_2c >= 0 && target_x_pos < (field_24_x >> 0x10))
 			|| (field_2c < 0 && (field_24_x >> 0x10) < target_x_pos)) {
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index fdaec449a1..b7bcf5ddcd 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -93,7 +93,7 @@ public:
 	ActorFrame *frame;
 	Graphics::Surface *surface;
 	uint16 field_c;
-	int16 field_e; // might be the amount to scale actor sprite.
+	int16 scale; // scale factor 0x100 is 100%
 	uint16 sequenceTimer;
 	uint16 _sequenceID;
 	int16 _sequenceID2;
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 1a830b3f8c..0891a848a1 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -43,7 +43,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	_actor->y_pos = _y = 100;
 	_actor->priorityLayer = 6;
 	_actor->flags = 0;
-	_actor->field_e = 0x100;
+	_actor->scale = 0x100;
 	_actor->updateSequence(_sequenceID);
 	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
 					  Dragons::ACTOR_FLAG_200);
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 2696bba387..0f5d8041de 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -672,12 +672,162 @@ void CutScene::loadPalettes() {
 	fd.read(_palettes, 256 * 2 * 4);
 }
 
-void CutScene::flickerReturnsCutScene() {
-	//TODO
+void CutScene::flameReturnsCutScene() {
+	DragonINI *uVar1;
+	uint engineFlag10Set;
+
+	uVar1 = _vm->_dragonINIResource->getFlickerRecord();
+	DAT_80063514 = 0x3f;
+	_vm->_dragonINIResource->setFlickerRecord(NULL);
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+	engineFlag10Set = _vm->isFlagSet(ENGINE_FLAG_10);
+	//fade_related_calls_with_1f();
+	_vm->clearFlags(ENGINE_FLAG_10);
+	_vm->_cursor->setActorFlag400();
+	_vm->_inventory->setActorFlag400();
+//	scr_tilemap1_w = 0x28;
+//	DAT_8006a3f0 = DAT_8006a3ec;
+//	load_actor_file(0x81);
+//	load_actor_file(0x7d);
+//	load_actor_file(0x7e);
+//	load_actor_file(0x8f);
+//	load_actor_file(0xaa);
+	DAT_80063514 = DAT_80063514 & 0xfffe | 0x600;
+	FUN_8003d388();
+	DAT_80072de8->updateSequence(0x1f);
+	DAT_80072e04->x_pos = 0x10b;
+	DAT_80072e04->y_pos = 99;
+	DAT_80072de8->x_pos = 0x10a;
+	DAT_80072de8->y_pos = 0x5a;
+	DAT_80072de8->field_7c = 0x10000;
+	DAT_80072e04->field_7c = 0x10000;
+	DAT_80072de8->setFlag(ACTOR_FLAG_800);
+	DAT_80072e04->setFlag(ACTOR_FLAG_800);
+	//	call_fade_related_1f();
+	_vm->setFlags(ENGINE_FLAG_20000);
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x8ab2,0x2e01) != 2) {
+		DAT_80072de8->updateSequence(0x1e);
+		DAT_80072de8->pathfinding_maybe(0xb0,0x6b,2);
+		do {
+		} while (DAT_80072de8->isFlagSet(ACTOR_FLAG_10));
+		DAT_80072de8->updateSequence(0x1f);
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x8b40,0x2e01) != 2) {
+			DAT_80072e04->updateSequence(0x1b);
+			DAT_80072e04->pathfinding_maybe(0xd5,0x6b,2);
+			do {
+			} while (DAT_80072e04->isFlagSet(ACTOR_FLAG_10));
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e04,0x1a,0x19,0x8bb6,0x3e01) != 2) {
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x8bd8,0x2e01) != 2) {
+					closeUpShotOnActor(0xd8,0,0xfd,0x60);
+//					playSoundFromTxtIndex(0x8c70);
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,7,0,0x8c70,0x701) != 2) {
+						fadeScreenAndResetActor(DAT_80072de8);
+						closeUpShotOnActor(0xd3,0,0x233,0x17a);
+//						playSoundFromTxtIndex(0x8cd2);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0xc,0,0x8cd2,0x2e01) != 2) {
+							fadeScreenAndResetActor(DAT_80072de8);
+							closeUpShotOnActor(0xd7,0,0x312,0x260);
+//							playSoundFromTxtIndex(0x8e1e);
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x8e1e,0x3e01) != 2) {
+								fadeScreenAndResetActor(DAT_80072de8);
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+//	fade_related_calls_with_1f();
+//	DisableVSyncEvent();
+//	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+//	EnableVSyncEvent();
+	_vm->clearFlags(ENGINE_FLAG_20000);
+	if(engineFlag10Set) {
+		_vm->setFlags(ENGINE_FLAG_10);
+	}
+	_vm->_dragonINIResource->setFlickerRecord(uVar1);
+	cursorInventoryClearFlag400();
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
 }
 
 void CutScene::knightsSavedAgain() {
-	//TODO
+	DragonINI *flicker;
+	bool engineFlag10Set;
+
+	flicker = _vm->_dragonINIResource->getFlickerRecord();
+	DAT_80063514 = 0;
+	_vm->_dragonINIResource->setFlickerRecord(NULL);
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+	engineFlag10Set = _vm->isFlagSet(ENGINE_FLAG_10);
+	//fade_related_calls_with_1f();
+
+	_vm->clearFlags(ENGINE_FLAG_10);
+	_vm->_cursor->setActorFlag400();
+	_vm->_inventory->setActorFlag400();
+
+//	scr_tilemap1_w = 0x28;
+//TODO what is this?	DAT_8006a3f0 = DAT_8006a3ec;
+
+//	load_actor_file(0x81);
+//	load_actor_file(0x7d);
+//	load_actor_file(0x7e);
+//	load_actor_file(0x8f);
+//	load_actor_file(0xaa);
+	wideAngleEveryoneAtTable();
+	_vm->setFlags(ENGINE_FLAG_20000);
+	_vm->waitForFramesAllowSkip(0x3b);
+	closeUpShotOnActor(0xd3,0,0x233,0x17a);
+	//playSoundFromTxtIndex(0x9000);
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0xd,0,0x9000,0x2e01) != 2) {
+		fadeScreenAndResetActor(DAT_80072de8);
+		closeUpKnightsAtTable();
+//		playSoundFromTxtIndex(0x90de);
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x90de,0x2e01) != 2) {
+			closeUpShotOnActor(0xd8,0,0xfd,0x60);
+//			playSoundFromTxtIndex(0x921c);
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,8,0,0x921c,0x701) != 2) {
+				fadeScreenAndResetActor(DAT_80072de8);
+				closeUpKnightsAtTable();
+//				playSoundFromTxtIndex(0x92aa);
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,9,4,0x92aa,0xc01) != 2) {
+					closeUpShotOnActor(0xd7,0,0x312,0x260);
+//					playSoundFromTxtIndex(0x932c);
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,6,0,0x932c,0x3e01) != 2) {
+						fadeScreenAndResetActor(DAT_80072de8);
+						closeUpShotOnActor(0xd3,2,0x87,0);
+//						playSoundFromTxtIndex(0x93d6);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0xe,2,0x93d6,0x2e01) != 2) {
+							fadeScreenAndResetActor(DAT_80072de8);
+							closeUpKnightsAtTable();
+//							playSoundFromTxtIndex(0x7dcc);
+							DAT_80072df0->updateSequence(0x13);
+							DAT_80072df4->updateSequence(0x10);
+							DAT_80072df8->updateSequence(0x11);
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
+								closeUpShotOnActor(0xd8,0,0xfd,0x60);
+//								playSoundFromTxtIndex(0x948c);
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,9,0,0x948c,0x701) != 2) {
+									fadeScreenAndResetActor(DAT_80072de8);
+									_vm->waitForFramesAllowSkip(0x3b);
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+	//fade_related_calls_with_1f();
+//	DisableVSyncEvent();
+//	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+//	EnableVSyncEvent();
+	_vm->clearFlags(ENGINE_FLAG_20000);
+	if(engineFlag10Set) {
+		_vm->setFlags(ENGINE_FLAG_10);
+	}
+	_vm->_dragonINIResource->setFlickerRecord(flicker);
+	cursorInventoryClearFlag400();
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
 }
 
 
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index 23a430e004..df004e1ff0 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -60,7 +60,7 @@ public:
 	void scene1();
 	void diamondScene();
 	void knightsSavedBackAtCastle();
-	void flickerReturnsCutScene();
+	void flameReturnsCutScene();
 	void knightsSavedAgain();
 
 private:
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 4aa0a4eb11..152ce6ef1f 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -382,7 +382,7 @@ void DragonsEngine::gameLoop()
 			}
 
 			performAction();
-			if ((getCurrentSceneId() == 0x1d) && (getINI(0x179)->field_2 != 0))
+			if ((getCurrentSceneId() == 0x1d) && (getINI(0x178)->field_12 != 0)) //cave of dilemma
 			{
 				clearFlags(ENGINE_FLAG_8);
 			} else {
@@ -559,7 +559,7 @@ void DragonsEngine::gameLoop()
 				if (tmpId != 0) {
 					actor->flags = 0;
 					actor->priorityLayer = 0;
-					actor->field_e = 0x100;
+					actor->scale = 0x100;
 					actor->updateSequence(getINI(tmpId - 1)->field_8 * 2 + 10);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
@@ -576,7 +576,7 @@ void DragonsEngine::gameLoop()
 				Actor *invActor = _inventory->getInventoryItemActor(_cursor->iniItemInHand);
 				invActor->flags = 0;
 				invActor->priorityLayer = 0;
-				invActor->field_e = 0x100;
+				invActor->scale = 0x100;
 				invActor->updateSequence(
 						 getINI(_cursor->iniItemInHand - 1)->field_8 * 2 + 10);
 				_cursor->iniItemInHand = 0;
@@ -1115,6 +1115,14 @@ bool DragonsEngine::isRightKeyPressed() {
 	return _rightKeyDown;
 }
 
+bool DragonsEngine::isUpKeyPressed() {
+	return false; // TODO
+}
+
+bool DragonsEngine::isDownKeyPressed() {
+	return false; // TODO
+}
+
 bool DragonsEngine::checkForActionButtonRelease() {
 	return _leftMouseButtonUp || _enterKeyUp;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index e3c2d087c3..baf229d120 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -144,8 +144,8 @@ public:
 	uint16 data_800633fc;
 	uint16 videoFlags; // TODO move to screen?
 
-private:
 	Screen *_screen;
+private:
 	BigfileArchive *_bigfileArchive;
 	DragonFLG *_dragonFLG;
 	DragonVAR *_dragonVAR;
@@ -247,6 +247,8 @@ public:
 	bool isActionButtonPressed();
 	bool isLeftKeyPressed();
 	bool isRightKeyPressed();
+	bool isUpKeyPressed();
+	bool isDownKeyPressed();
 	bool isSquareButtonPressed();
 	bool isTriangleButtonPressed();
 	bool isCircleButtonPressed();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 7dad65ee4c..9353a47aa8 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -81,7 +81,7 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_actor->y_pos = 0;
 	_actor->priorityLayer = 6;
 	_actor->flags = 0;
-	_actor->field_e = 0x100;
+	_actor->scale = 0x100;
 	_actor->updateSequence(0);
 	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
 						 Dragons::ACTOR_FLAG_200);
@@ -174,7 +174,7 @@ void Inventory::openInventory() {
 
 		if (inventoryItemTbl[i]) {
 			item->flags = 0; //clear all flags
-			item->field_e = 0x100;
+			item->scale = 0x100;
 			item->priorityLayer = 0;
 			item->updateSequence(_vm->getINI(inventoryItemTbl[i] - 1)->field_8 * 2 + 10);
 			item->setFlag(ACTOR_FLAG_200);
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index ddcd4a8f24..6e7ef67105 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -174,7 +174,7 @@ void Minigame1::run() {
 	_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(DAT_80063a40 - 1));
 	flickerActor = _vm->getINI(DAT_80063a40 - 1)->actor;
 	flickerActor->flags = flickerActor->flags | 0x380;
-	flickerActor->field_e = 0x100;
+	flickerActor->scale = 0x100;
 	flickerActor->priorityLayer = 4;
 	flickerActor->_sequenceID2 = -1;
 	flickerActor->updateSequence(0x15);
@@ -191,14 +191,14 @@ void Minigame1::run() {
 	pusherActor->flags = pusherActor->flags | 0x380;
 	pusherActor->x_pos = flickerActor->x_pos + -0xe;
 	pusherActor->y_pos = flickerActor->y_pos + 7;
-	pusherActor->field_e = 0x100;
+	pusherActor->scale = 0x100;
 	pusherActor->priorityLayer = 6;
 	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
 //	if (wheelsActorId == -1) {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_wheels_8008e96c,2,4,0,0xffffffff);
 //	}
 	wheelsActor->flags = wheelsActor->flags | 0x380;
-	wheelsActor->field_e = 0x100;
+	wheelsActor->scale = 0x100;
 	wheelsActor->x_pos = flickerActor->x_pos;
 	wheelsActor->y_pos = flickerActor->y_pos;
 	wheelsActor->priorityLayer = 5;
@@ -209,7 +209,7 @@ void Minigame1::run() {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc-cat_8008e984,2,4,0,0xffffffff);
 //	}
 	catActor->flags = catActor->flags | 0x380;
-	catActor->field_e = 0x100;
+	catActor->scale = 0x100;
 	catActor->priorityLayer = 0;
 	i = 0;
 	while (i < 3) {
@@ -218,7 +218,7 @@ void Minigame1::run() {
 //			ProbablyShowASCIIMessage(s_couldn't_alloc_target!_8008e998,2,4,0,0xffffffff);
 //		}
 		targetActorIdTbl[(uint)i + 1]->flags = targetActorIdTbl[(uint)i + 1]->flags | 0x380;
-		targetActorIdTbl[(uint)i + 1]->field_e = 0x100;
+		targetActorIdTbl[(uint)i + 1]->scale = 0x100;
 		auStack378[(uint)i] = 0;
 		//TODO FUN_80017010_update_actor_texture_maybe(1);
 		i = i + 1;
@@ -233,7 +233,7 @@ void Minigame1::run() {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_dust_sprite!_8008e9b0,2,5,0,0xffffffff);
 //	}
 	dustSpriteActor->flags = dustSpriteActor->flags | 0x380;
-	dustSpriteActor->field_e = 0x100;
+	dustSpriteActor->scale = 0x100;
 	uVar1 = _vm->getINI(DAT_80063a48 - 1)->actor; //dragon_ini_pointer[DAT_80063a48 + -1].actorId;
 	local_21e = 0;
 	actorFieldC = uVar1->field_c;
@@ -245,7 +245,7 @@ void Minigame1::run() {
 	catFieldE_scaleMaybe = 0x30;
 	catActor->y_pos = 0x6e;
 	catActor->x_pos = 0x95;
-	catActor->field_e = 0x30;
+	catActor->scale = 0x30;
 	catActor->priorityLayer = 2;
 	catActor->updateSequence(0xb);
 	gameState = 5;
@@ -382,7 +382,7 @@ void Minigame1::run() {
 							local_23a = (local_25a + 3) * 0x80;
 							catActor->y_pos = 0x5a;
 							catFieldE_scaleMaybe = 0x100;
-							catActor->field_e = 0x100;
+							catActor->scale = 0x100;
 							catActor->updateSequence(0xc);
 							_vm->playSound(5);
 							catActor->priorityLayer = 3;
@@ -416,7 +416,7 @@ void Minigame1::run() {
 					catActor->x_pos = local_240 >> 7;
 					catActor->y_pos = local_23e >> 7;
 					catFieldE_scaleMaybe = catFieldE_scaleMaybe - 3;
-					catActor->field_e = catFieldE_scaleMaybe;
+					catActor->scale = catFieldE_scaleMaybe;
 					if (catFieldE_scaleMaybe == 0x7f) {
 						i = 0;
 						while ((i < 8 && (((local_240 >> 7 < auStack352[(uint)i * 3] ||
@@ -495,7 +495,7 @@ void Minigame1::run() {
 						catFieldE_scaleMaybe = 0x30;
 						catActor->y_pos = 0x6e;
 						catActor->x_pos = 0x95;
-						catActor->field_e = 0x30;
+						catActor->scale = 0x30;
 						catActor->updateSequence(0xb);
 						gameState = 5;
 					}
@@ -529,7 +529,7 @@ void Minigame1::run() {
 						local_23e = local_23e + local_23a;
 						catFieldE_scaleMaybe = catFieldE_scaleMaybe + 8;
 						catActor->y_pos = local_23e >> 7;
-						catActor->field_e = catFieldE_scaleMaybe;
+						catActor->scale = catFieldE_scaleMaybe;
 					}
 					else {
 						gameState = 6;
@@ -552,7 +552,7 @@ void Minigame1::run() {
 									local_23e = 0x4300;
 									local_23a = 0x100;
 									catActor->y_pos = 0x86;
-									catActor->field_e = 0x80;
+									catActor->scale = 0x80;
 									catActor->updateSequence(0xb);
 									if (flickerXPos < local_240 >> 7) {
 										sVar2 = flickerXPos + 0x32;
@@ -574,7 +574,7 @@ void Minigame1::run() {
 										if (0x100 < catFieldE_scaleMaybe) {
 											catFieldE_scaleMaybe = 0x100;
 										}
-										catActor->field_e = catFieldE_scaleMaybe;
+										catActor->scale = catFieldE_scaleMaybe;
 										catActor->y_pos = local_23e >> 7;
 										catActor->x_pos = local_240 >> 7;
 										local_238 = 1;
@@ -586,7 +586,7 @@ void Minigame1::run() {
 								else {
 									if ((int)(uint)(local_240 >> 7) < (int)((uint)flickerXPos - 0x32)) {
 										if (catActor->_sequenceID != 9) {
-											catActor->field_e = 0x100;
+											catActor->scale = 0x100;
 											catActor->updateSequence(9);
 										}
 										local_240 = local_240 + 0x180;
@@ -595,7 +595,7 @@ void Minigame1::run() {
 									else {
 										if ((uint)flickerXPos + 0x32 < (uint)(local_240 >> 7)) {
 											if (catActor->_sequenceID != 10) {
-												catActor->field_e = 0x100;
+												catActor->scale = 0x100;
 												catActor->updateSequence(10);
 											}
 											local_240 = local_240 - 0x180;
@@ -648,7 +648,7 @@ void Minigame1::run() {
 								catActor->y_pos = 0x82;
 								catActor->x_pos = 0x95;
 								catActor->priorityLayer = 3;
-								catActor->field_e = 0x80;
+								catActor->scale = 0x80;
 								catActor->updateSequence(0x10);
 								gameState = 6;
 							}
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
new file mode 100644
index 0000000000..035cd97132
--- /dev/null
+++ b/engines/dragons/minigame3.cpp
@@ -0,0 +1,778 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "common/scummsys.h"
+#include "common/rect.h"
+#include "dragons/actor.h"
+#include "dragons/minigame3.h"
+#include "dragons/dragonini.h"
+#include "dragons/inventory.h"
+#include "dragons/scene.h"
+#include "dragons/screen.h"
+#include "dragons/talk.h"
+#include "dragons.h"
+
+namespace Dragons {
+
+struct BunnyStruct {
+	uint32 positionIdx;
+	uint32 x;
+	uint32 y;
+	uint32 field_0xc;
+	uint32 field_0x10;
+};
+
+struct TearInfo {
+	uint16 x;
+	uint16 y;
+	uint16 unk;
+	uint16 yRelated;
+};
+
+struct UnkStruct {
+	uint16 position1;
+	uint16 position2;
+	uint32 unk4;
+	uint32 unk8;
+	uint32 unk12;
+	uint32 unk16;
+	uint32 field_0x14;
+};
+
+Minigame3::Minigame3(DragonsEngine *vm) : _vm(vm) {}
+
+void Minigame3::run() {
+	bool bVar1;
+	Actor *handActorId;
+	uint16 actorId;
+	int16 sVar2;
+	int iVar3;
+	uint tmpValue;
+	int iVar4;
+	DragonINI *flicker;
+	uint16 origSceneId;
+	byte auStack1584_palette [512]; //[126];
+	uint16 local_5b2;
+	byte auStack1072_palette [512];
+	Actor *bunnyActorTbl [4];
+	uint16 local_228;
+	uint16 local_226;
+	int16 local_224;
+	Actor *tearActorTbl [8];
+	uint16 local_210;
+	int16 local_208 [16];
+	uint local_1e8;
+	uint oldEngineFlags;
+	uint16 local_1e0;
+	uint16 local_1de;
+	Actor *tearBlinkActorTbl2 [4];
+	Actor *tearBlinkActorTbl [4];
+	int16 local_1c8;
+	int16 local_1c6;
+	uint16 local_1c2;
+	int16 local_1c0;
+	int16 local_1be;
+	int16 local_1bc;
+	int16 local_1ba;
+	uint16 local_1b8;
+//	undefined auStack432 [20];
+	int16 asStack412 [14];
+	TearInfo tearInfo [30];
+	Common::Point bunnyPositionsTbl [4];
+	Common::Point handPositionsTbl [4];
+	uint16 goodRabbitPositionTbl [4];
+	uint16 bunnyPositionTbl [4];
+	int16 currentState;
+	uint16 flags;
+	int16 local_5c;
+	int16 local_5a;
+	int16 local_58;
+	int16 local_56;
+	int16 local_52;
+	uint16 local_50;
+	BunnyStruct bunnyInfo [2];
+	uint16 local_20;
+	uint16 local_1e;
+	uint16 local_1c;
+	uint16 local_1a;
+	uint16 i;
+	int16 local_16;
+	int16 local_14;
+	int16 origInventoryType;
+	int16 local_10;
+	int16 local_e;
+	UnkStruct UnkStruct_ARRAY_800931a0[5];
+
+
+	Common::File *fd = new Common::File();
+	if (!fd->open("arc3.bin")) {
+		error("Failed to open arc1.bin");
+	}
+
+	//TODO do we need this?	memcpy(auStack432,&DAT_8008e88c,0x2a);
+
+	fd->seek(0x2c);
+	for (i = 0; i < 30; i++) {
+		tearInfo[i].x = fd->readUint16LE();
+		tearInfo[i].x = fd->readUint16LE();
+		tearInfo[i].unk = fd->readUint16LE();
+		tearInfo[i].yRelated = fd->readUint16LE();
+	}
+
+	for (int i = 0; i < 4; i++) {
+		bunnyPositionsTbl[i].x = fd->readUint16LE();
+		bunnyPositionsTbl[i].y = fd->readUint16LE();
+	}
+
+	for (int i = 0; i < 4; i++) {
+		handPositionsTbl[i].x = fd->readUint16LE();
+		handPositionsTbl[i].y = fd->readUint16LE();
+	}
+
+	fd->seek(0x4914);
+
+	for (int i = 0; i < 5; i++) {
+		UnkStruct_ARRAY_800931a0[i].position1 = fd->readUint16LE();
+		UnkStruct_ARRAY_800931a0[i].position2 = fd->readUint16LE();
+		UnkStruct_ARRAY_800931a0[i].unk4 = fd->readUint32LE();
+		UnkStruct_ARRAY_800931a0[i].unk8 = fd->readUint32LE();
+		UnkStruct_ARRAY_800931a0[i].unk12 = fd->readUint32LE();
+		UnkStruct_ARRAY_800931a0[i].unk16 = fd->readUint32LE();
+		UnkStruct_ARRAY_800931a0[i].field_0x14 = fd->readUint32LE();
+	}
+
+	fd->close();
+	delete fd;
+
+	origInventoryType = _vm->_inventory->getType();
+//	fade_related_calls_with_1f();
+	_vm->_inventory->setType(0);
+	_vm->reset_screen_maybe();
+	flicker = _vm->_dragonINIResource->getFlickerRecord();
+	flicker->sceneId = 0;
+	_vm->_dragonINIResource->setFlickerRecord(NULL);
+	origSceneId = _vm->getCurrentSceneId();
+	_vm->_scene->setSceneId(6);
+	_vm->_scene->loadScene(6 | 0x8000, 0);
+	_vm->_scene->setFgLayerPriority(0);
+// TODO
+//	load_palette_into_frame_buffer(1,scrFileData_maybe);
+//	load_palette_into_frame_buffer(4,scrFileData_maybe);
+	_vm->_screen->updatePaletteTransparency(4, 1, 0xff, true);
+//	FUN_80017ef0();
+	oldEngineFlags = _vm->getAllFlags();
+	_vm->clearFlags(ENGINE_FLAG_80);
+	_vm->clearFlags(ENGINE_FLAG_20);
+	_vm->clearFlags(ENGINE_FLAG_10);
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_1);
+	_vm->setFlags(ENGINE_FLAG_100);
+	_vm->setFlags(ENGINE_FLAG_1000_TEXT_ENABLED);
+// TODO
+//	memcpy2(auStack1584_palette,scrFileData_maybe,0x200);
+//	memcpy2(auStack1072_palette,scrFileData_maybe,0x200);
+	local_5b2 = 0x7fff;
+//	DisableVSyncEvent();
+	i = 0;
+	while ((int16)i < 4) {
+		bunnyActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x15,4,0,0);
+		if (bunnyActorTbl[(int16)i] == NULL) {
+			error("Couldn't_alloc_bunny");
+		}
+		bunnyActorTbl[(int16)i]->setFlag(ACTOR_FLAG_80);
+		bunnyActorTbl[(int16)i]->setFlag(ACTOR_FLAG_100);
+		bunnyActorTbl[(int16)i]->setFlag(ACTOR_FLAG_200);
+		bunnyActorTbl[(int16)i]->setFlag(ACTOR_FLAG_4000);
+
+		bunnyActorTbl[(int16)i]->priorityLayer = 0;
+		bunnyActorTbl[(int16)i]->x_pos = bunnyPositionsTbl[(int16)i].x;
+		bunnyActorTbl[(int16)i]->y_pos = bunnyPositionsTbl[(int16)i].y;
+		i = i + 1;
+	}
+	i = 0;
+	while ((int16)i < 8) {
+		tearActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x15,0x13,0,0);
+		if (tearActorTbl[(int16)i] == NULL) {
+			error("Couldn't alloc tear");
+		}
+		tearActorTbl[(int16)i]->flags = tearActorTbl[(int16)i]->flags | 0x380;
+		tearActorTbl[(int16)i]->scale = 0x100;
+		tearActorTbl[(int16)i]->priorityLayer = 0;
+		local_208[(int16)i] = -1;
+		local_208[(int)(int16)i + 8] = 0;
+		i = i + 1;
+	}
+	local_1e0 = 0;
+	local_1e8 = 0;
+	handActorId = _vm->_actorManager->loadActor(0x19,0,0,0);
+	if (handActorId == NULL) {
+		error("Couldn't alloc hand");
+	}
+	handActorId->setFlag(ACTOR_FLAG_80);
+	handActorId->setFlag(ACTOR_FLAG_100);
+	handActorId->setFlag(ACTOR_FLAG_200);
+	handActorId->setFlag(ACTOR_FLAG_800);
+	handActorId->setFlag(ACTOR_FLAG_2000);
+	handActorId->setFlag(ACTOR_FLAG_4000);
+	handActorId->scale = 0x100;
+	handActorId->priorityLayer = 0;
+	handActorId->field_7c = 0x40000;
+	i = 0;
+	while ((int16)i < 2) {
+		tearBlinkActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x34,(uint)i,0,0);
+		if (tearBlinkActorTbl[(int16)i] == NULL) {
+			error("Couldn't alloc tear blink");
+		}
+		tearBlinkActorTbl[(int16)i]->flags = tearBlinkActorTbl[(int16)i]->flags | 0x4384;
+		tearBlinkActorTbl[(int16)i]->scale = 0x100;
+		tearBlinkActorTbl[(int16)i]->priorityLayer = 0;
+		i = i + 1;
+	}
+	i = 0;
+	while ((int16)i < 2) {
+		tearBlinkActorTbl2[(int16)i] = _vm->_actorManager->loadActor(0x16,(uint)i,0,0);
+		if (tearBlinkActorTbl2[(int16)i] == NULL) {
+			error("Couldn't alloc tear blink");
+		}
+		tearBlinkActorTbl2[(int16)i]->setFlag(ACTOR_FLAG_100);
+		tearBlinkActorTbl2[(int16)i]->setFlag(ACTOR_FLAG_800);
+		tearBlinkActorTbl2[(int16)i]->scale = 0x100;
+		tearBlinkActorTbl2[(int16)i]->priorityLayer = 0;
+		i = i + 1;
+	}
+	tearBlinkActorTbl2[0]->x_pos = 0x56;
+	tearBlinkActorTbl2[0]->y_pos = 0x8c;
+	tearBlinkActorTbl2[1]->x_pos = 0xf0;
+	tearBlinkActorTbl2[1]->y_pos = 0x8c;
+	tearBlinkActorTbl[0]->x_pos = 0x23; //DAT_80093228_23;
+	tearBlinkActorTbl[1]->x_pos = 0xbf; //DAT_8009322a_bf;
+	tearBlinkActorTbl[0]->y_pos = 0xcc;
+	tearBlinkActorTbl[1]->y_pos = 0xcc;
+//	EnableVSyncEvent();
+	i = 0;
+	while ((int16)i < 4) {
+		goodRabbitPositionTbl[(int16)i] = 0;
+		i = i + 1;
+	}
+	local_16 = _vm->getRand(4);
+	goodRabbitPositionTbl[(int16)local_16] = 1;
+	i = 0;
+	while ((int16)i < 4) {
+		bunnyPositionTbl[(int16)i] = i;
+		bunnyActorTbl[(int16)i]->priorityLayer = 2;
+		bunnyActorTbl[(int16)i]->updateSequence(4);
+		i = i + 1;
+	}
+	_vm->waitForFrames(1);
+	FUN_80017e64(2,0x280,0);
+	FUN_80017e64(1,0,0);
+	FUN_80017e64(0,0,0);
+//	call_fade_related_1f();
+	_vm->waitForFrames(0xf);
+	_vm->_talk->loadAndDisplayDialogAroundPoint(0x479A,0x14,3,0x1e01,0);
+	_vm->waitForFrames(0x1e);
+	// TODO FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+	i = 0;
+	while ((int16)i < 4) {
+		if (goodRabbitPositionTbl[(int16)i] == 0) {
+			bunnyActorTbl[(int16)i]->updateSequence(1);
+		}
+		else {
+			local_16 = i;
+		}
+		i = i + 1;
+	}
+//TODO why doesn't this work?
+//	do {
+//		iVar3 = (int)(int16)local_16 + 1;
+//		iVar4 = iVar3;
+//		if (iVar3 < 0) {
+//			iVar4 = (int)(int16)local_16 + 4;
+//		}
+//	} while (!bunnyActorTbl[iVar3 + (iVar4 >> 2) * -4]->isFlagSet(ACTOR_FLAG_4));
+	bunnyActorTbl[local_16]->waitUntilFlag4IsSet();
+
+	bunnyActorTbl[(int16)local_16]->updateSequence(0);
+	bunnyActorTbl[(int16)local_16]->waitUntilFlag4IsSet();
+	i = 0;
+	while ((int16)i < 4) {
+		bunnyActorTbl[(int16)i]->updateSequence(4);
+		i = i + 1;
+	}
+	_vm->waitForFrames(0x1e);
+	_vm->waitForFrames(0x1e);
+	// TODO FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+	local_56 = 0;
+	local_1c0 = 0;
+	currentState = 2;
+	flags = 0;
+	local_58 = 0x1e;
+	local_52 = 0;
+	local_210 = 0;
+	local_1de = 0;
+	local_5a = 0;
+	local_5c = _vm->getRand(2);
+	local_5c = local_5c + 5;
+	local_1be = 1;
+	local_1bc = _vm->getRand(3);
+	local_1bc = local_1bc + 3;
+	local_1ba = 10;
+	local_1b8 = 0;
+	local_10 = 0;
+	local_e = 0;
+	tearBlinkActorTbl[0]->priorityLayer = 3;
+	tearBlinkActorTbl[1]->priorityLayer = 3;
+	tearBlinkActorTbl[0]->updateSequence(0);
+	tearBlinkActorTbl[1]->updateSequence(1);
+	local_1c2 = 0;
+	while( true ) {
+		_vm->waitForFrames(1);
+		switch(currentState) {
+			case 1:
+				if ((bunnyActorTbl[local_1a]->_sequenceID != 5) || ((bunnyActorTbl[local_1a]->flags & 4) != 0)) {
+					if ((local_56 < 1) ||
+						(((int)bunnyInfo[local_20].x >> 9 <= (int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x ||
+																				((int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x <= (int)bunnyInfo[local_1e].x >> 9)))) {
+						bunnyActorTbl[local_1c]->x_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x;
+						bunnyActorTbl[local_1a]->x_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x;
+						bunnyActorTbl[local_1c]->y_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].y;
+						bunnyActorTbl[local_1a]->y_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].y;
+						currentState = 5;
+					}
+					else {
+						if (bunnyActorTbl[local_1a]->_sequenceID == 5) {
+							bunnyActorTbl[local_1a]->updateSequence(6);
+							bunnyActorTbl[local_1c]->updateSequence(0xd);
+						}
+						else {
+							local_56 = local_56 - *(int16 *)&UnkStruct_ARRAY_800931a0[local_50].field_0x14;
+							bunnyInfo[local_20].x = bunnyInfo[local_20].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * -0x200;
+							bunnyInfo[local_20].y = bunnyInfo[local_20].y - bunnyInfo[local_20].field_0xc;
+							bunnyInfo[local_20].field_0xc = bunnyInfo[local_20].field_0xc + bunnyInfo[local_20].field_0x10;
+							bunnyActorTbl[local_1c]->x_pos = (int16_t)((int)bunnyInfo[local_20].x >> 9);
+							bunnyActorTbl[local_1c]->y_pos = (int16_t)((int)bunnyInfo[local_20].y >> 9);
+							bunnyInfo[local_1e].x = bunnyInfo[local_1e].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * 0x200;
+							bunnyInfo[local_1e].y = bunnyInfo[local_1e].y - bunnyInfo[local_1e].field_0xc;
+							bunnyInfo[local_1e].field_0xc = bunnyInfo[local_1e].field_0xc + bunnyInfo[local_1e].field_0x10;
+							bunnyActorTbl[local_1a]->x_pos = (int16_t)((int)bunnyInfo[local_1e].x >> 9);
+							bunnyActorTbl[local_1a]->y_pos = (int16_t)((int)bunnyInfo[local_1e].y >> 9);
+//							if ((local_228 < 4) && (*(int16 *)((uint)local_228 * 2 + (uint)local_50 * 8 + -0x7ff6ce00) < bunnyActorTbl[local_1a]->x_pos)) {
+							if ((local_228 < 4) && _vm->_actorManager->getActor(0)->x_pos < bunnyActorTbl[local_1a]->x_pos) {
+								local_228 = local_228 + 1;
+								bunnyActorTbl[local_1a]->updateSequence((uint)local_228 + 6 & 0xffff);
+								bunnyActorTbl[local_1c]->updateSequence((uint)local_228 + 0xd & 0xffff);
+							}
+						}
+					}
+				}
+				break;
+			case 2:
+				if (local_58 == 0) {
+					currentState = 4;
+				}
+				break;
+			case 3:
+				if (local_58 == 0) {
+					currentState = 4;
+				}
+				break;
+			case 4:
+				local_50 = _vm->getRand(4);
+				if (local_50 < 2) {
+					i = _vm->getRand(2);
+				}
+				else {
+					i = 0;
+				}
+				bunnyInfo[(int16)i].positionIdx = (uint)UnkStruct_ARRAY_800931a0[local_50].position1;
+				bunnyInfo[(int16)i].x = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].x << 9;
+				bunnyInfo[(int16)i].y = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].y << 9;
+				bunnyInfo[(int16)i].field_0xc = UnkStruct_ARRAY_800931a0[local_50].unk4;
+				bunnyInfo[(int16)i].field_0x10 = UnkStruct_ARRAY_800931a0[local_50].unk8;
+				i = i ^ 1;
+				bunnyInfo[(int16)i].positionIdx = (uint)UnkStruct_ARRAY_800931a0[local_50].position2;
+				bunnyInfo[(int16)i].x = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].x << 9;
+				bunnyInfo[(int16)i].y = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].y << 9;
+				bunnyInfo[(int16)i].field_0xc = UnkStruct_ARRAY_800931a0[local_50].unk12;
+				bunnyInfo[(int16)i].field_0x10 = UnkStruct_ARRAY_800931a0[local_50].unk16;
+				local_56 = bunnyPositionsTbl[UnkStruct_ARRAY_800931a0[local_50].position2].x - bunnyPositionsTbl[UnkStruct_ARRAY_800931a0[local_50].position1].x;
+				local_1e = (uint16)((int)bunnyInfo[1].x <= (int)bunnyInfo[0].x);
+				local_20 = (int16)((uint)local_1e + 1) + (int16)((int)((uint)local_1e + 1) / 2) * -2;
+				local_1a = bunnyPositionTbl[bunnyInfo[local_1e].positionIdx];
+				local_1c = bunnyPositionTbl[bunnyInfo[local_20].positionIdx];
+				bunnyActorTbl[local_1a]->updateSequence(5);
+				bunnyActorTbl[local_1c]->updateSequence(0xc);
+				if (local_52 == 0x1d) {
+					_vm->playSound(2);
+				}
+				else {
+					_vm->playSound((uint)local_1c2);
+					local_1c2 = 1 - local_1c2;
+				}
+				local_228 = 0;
+				i = goodRabbitPositionTbl[bunnyInfo[local_1e].positionIdx];
+				goodRabbitPositionTbl[bunnyInfo[local_1e].positionIdx] = goodRabbitPositionTbl[bunnyInfo[local_20].positionIdx];
+				goodRabbitPositionTbl[bunnyInfo[local_20].positionIdx] = i;
+				i = bunnyPositionTbl[bunnyInfo[local_1e].positionIdx];
+				bunnyPositionTbl[bunnyInfo[local_1e].positionIdx] = bunnyPositionTbl[bunnyInfo[local_20].positionIdx];
+				bunnyPositionTbl[bunnyInfo[local_20].positionIdx] = i;
+				currentState = 1;
+				break;
+			case 5:
+				local_52 = local_52 + 1;
+				local_5a = local_5a + 1;
+				bunnyActorTbl[local_1a]->updateSequence(0xb);
+				bunnyActorTbl[local_1c]->updateSequence(0x12);
+				if (local_5a == local_5c) {
+					local_5a = 0;
+					local_5c = _vm->getRand(2);
+					local_5c = local_5c + 5;
+					currentState = 3;
+					local_58 = 0x3c;
+				}
+				else {
+					currentState = 2;
+					local_58 = 2;
+				}
+				break;
+			case 6:
+				local_10 = 0;
+				if (local_1e8 == 0) {
+					flags = flags | 8;
+				}
+				break;
+			default:
+				error("Unknown state");
+		}
+		i = 0;
+		while ((int16)i < 8) {
+			if (local_208[(int16)i] != -1) {
+				tearActorTbl[(int16)i]->y_pos = tearActorTbl[(int16)i]->y_pos + ((uint16)local_208[(int)(int16)i + 8] >> 6);
+				if (tearActorTbl[(int16)i]->y_pos < (int16)tearInfo[local_208[(int16)i]].yRelated) {
+					local_208[(int)(int16)i + 8] = local_208[(int)(int16)i + 8] + 8;
+				}
+				else {
+					tearActorTbl[(int16)i]->priorityLayer = 0;
+					local_1e8 = local_1e8 & ~(1 << ((int)local_208[(int16)i] & 0x1fU));
+					local_208[(int16)i] = -1;
+					local_1e0 = local_1e0 - 1;
+				}
+			}
+			i = i + 1;
+		}
+		if (((local_1e0 < local_1de) && (currentState != 6)) && (sVar2 = _vm->getRand(2), sVar2 == 0)) {
+			if ((local_1e8 & 0x7fff) < local_1e8 >> 0xf) {
+				local_14 = 0;
+			}
+			else {
+				local_14 = 0xf;
+			}
+			do {
+				sVar2 = _vm->getRand(0xf);
+				sVar2 = sVar2 + local_14;
+			} while ((1 << ((int)sVar2 & 0x1fU) & local_1e8) != 0);
+			local_1e8 = local_1e8 | 1 << ((int)sVar2 & 0x1fU);
+			local_14 = 0;
+			while ((local_14 < 8 && (local_208[local_14] != -1))) {
+				local_14 = local_14 + 1;
+			}
+			local_208[local_14] = sVar2;
+			tearActorTbl[local_14]->x_pos = tearInfo[sVar2].x;
+			tearActorTbl[local_14]->y_pos = tearInfo[sVar2].y;
+			local_208[(int)local_14 + 8] = 0x20;
+			tearActorTbl[local_14]->updateSequence(0x13);
+			tearActorTbl[local_14]->priorityLayer = 3;
+			local_1e0 = local_1e0 + 1;
+		}
+		if ((flags & 1) == 0) {
+			if ((flags & 2) == 0) {
+				if ((flags & 4) == 0) {
+					if (_vm->isActionButtonPressed()) {
+						local_1c8 = 1;
+						flags = flags | 1;
+						local_1c6 = 3;
+						FUN_80017e64(2,0x640,0);
+						if (((currentState != 3) && (currentState != 6)) && (local_e == 0)) {
+							local_10 = 0x5a;
+							local_e = 1;
+						}
+					}
+				}
+				else {
+					if (local_1c6 == 0) {
+						if (local_1c8 == 2) {
+							local_1c6 = 3;
+							local_1c8 = 1;
+							FUN_80017e64(2,0x640,0);
+						}
+						else {
+							if (local_1c8 == 1) {
+								local_1c8 = 0;
+								local_1ba = 0;
+								flags = flags & 0xfffb;
+								tearBlinkActorTbl2[0]->priorityLayer = 0;
+								tearBlinkActorTbl2[1]->priorityLayer = 0;
+								tearBlinkActorTbl2[0]->updateSequence(0);
+								tearBlinkActorTbl2[1]->updateSequence(1);
+							}
+						}
+					}
+					else {
+						local_1c6 = local_1c6 + -1;
+					}
+				}
+			}
+			else {
+				if (local_1c6 == 0) {
+					i = 0;
+					while ((int16)i < 8) {
+						tearActorTbl[(int16)i]->priorityLayer = 0;
+						local_208[(int16)i] = -1;
+						i = i + 1;
+					}
+					local_210 = 0;
+					local_1e0 = 0;
+					local_1de = 0;
+					local_1e8 = 0;
+					FUN_80017f70_paletteRelated(0);
+					local_1b8 = 0;
+					flags = flags & 0xfffd | 4;
+					local_1c8 = 2;
+					local_1c6 = 3;
+					FUN_80017e64(2,0x780,0);
+					tearBlinkActorTbl[0]->y_pos = 0xcc;
+					tearBlinkActorTbl[1]->y_pos = 0xcc;
+				}
+				else {
+					local_1c6 = local_1c6 + -1;
+				}
+			}
+		}
+		else {
+			if (local_1c6 == 0) {
+				if (local_1c8 == 1) {
+					local_1c6 = 3;
+					local_1c8 = 2;
+					FUN_80017e64(2,0x780,0);
+					tearBlinkActorTbl2[0]->updateSequence(0);
+					tearBlinkActorTbl2[1]->updateSequence(1);
+					tearBlinkActorTbl2[0]->priorityLayer = 4;
+					tearBlinkActorTbl2[1]->priorityLayer = 4;
+				}
+				else {
+					if (local_1c8 == 2) {
+						local_1c6 = 0x14;
+						local_1c8 = 3;
+						FUN_80017e64(2,0x8c0,0);
+						tearBlinkActorTbl2[0]->updateSequence(2);
+						tearBlinkActorTbl2[1]->updateSequence(3);
+						flags = flags & 0xfffe | 2;
+					}
+				}
+			}
+			else {
+				local_1c6 = local_1c6 + -1;
+			}
+		}
+		if ((local_e != 0) && (local_10 == 0)) {
+			//TODO implement this. FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+			local_e = 0;
+		}
+		if ((local_e != 0) && (local_10 != 0)) {
+			local_10 = local_10 + -1;
+		}
+		if (local_58 != 0) {
+			local_58 = local_58 + -1;
+		}
+		local_210 = local_210 + 1;
+		if (((uint)local_210 % 0x14 == 0) && (local_1de < 8)) {
+			local_1de = local_1de + 1;
+		}
+		if (((uint)local_210 % 10 == 0) && (0x1d < local_210)) {
+			if ((int16)local_1b8 < 0x1e) {
+				local_1b8 = local_1b8 + 1;
+				FUN_80017f70_paletteRelated((uint)local_1b8);
+			}
+			if (100 < tearBlinkActorTbl[0]->y_pos) {
+				tearBlinkActorTbl[0]->y_pos = tearBlinkActorTbl[0]->y_pos + -3;
+				tearBlinkActorTbl[1]->y_pos = tearBlinkActorTbl[1]->y_pos + -3;
+			}
+		}
+		if (local_52 == 0x1e) {
+			currentState = 6;
+		}
+		if ((flags & 8) != 0) break;
+		if (local_1c8 == 0) {
+			if (local_1ba == 0) {
+				if (local_1bc == 0) {
+					tmpValue = _vm->getRand(2);
+					if ((tmpValue & 0xffff) == 0) {
+						local_1be = 1;
+					}
+					else {
+						local_1be = 0xffff;
+					}
+					local_1bc = _vm->getRand(3);
+					local_1bc = local_1bc + 3;
+					local_1ba = _vm->getRand(10);
+					local_1ba = local_1ba + 10;
+				}
+				else {
+					if (((local_1be < 0) && (-10 < local_1c0)) || ((0 < local_1be && (local_1c0 < 10)))) {
+						local_1c0 = local_1c0 + local_1be;
+					}
+					local_1ba = 2;
+					local_1bc = local_1bc + -1;
+					iVar4 = (int)local_1c0 + 10;
+					if (iVar4 < 0) {
+						iVar4 = (int)local_1c0 + 0xd;
+					}
+					local_14 = (int16)(iVar4 >> 2);
+					if (local_14 == 5) {
+						local_14 = 4;
+					}
+					FUN_80017e64(2,(int)local_14 * 0x1400000 >> 0x10,0);
+					FUN_80017e64(1,(int)-local_1c0,(int)asStack412[local_1c0]);
+					FUN_80017e64(0,(int)-local_1c0,(int)asStack412[local_1c0]);
+				}
+			}
+			else {
+				local_1ba = local_1ba + -1;
+			}
+		}
+	}
+	_vm->waitForFrames(1);
+	i = 0;
+	while ((int16)i < 3) {
+		local_16 = 0;
+		while ((int16)local_16 < 3) {
+			FUN_80017e64(2,((int)(int16)local_16 * 0x140 + 0x640) * 0x10000 >> 0x10,0);
+			_vm->waitForFrames(5);
+			local_16 = local_16 + 1;
+		}
+		local_1b8 = local_1b8 - 0xb;
+		if ((int16)local_1b8 < 0) {
+			local_1b8 = 0;
+		}
+		FUN_80017f70_paletteRelated((uint)local_1b8);
+		tearBlinkActorTbl[0]->y_pos = tearBlinkActorTbl[0]->y_pos + 0x1e;
+		if (199 < tearBlinkActorTbl[0]->y_pos) {
+			tearBlinkActorTbl[0]->y_pos = 199;
+		}
+		tearBlinkActorTbl[1]->y_pos = tearBlinkActorTbl[1]->y_pos + 0x1e;
+		if (199 < tearBlinkActorTbl[1]->y_pos) {
+			tearBlinkActorTbl[1]->y_pos = 199;
+		}
+		_vm->waitForFrames(0xf);
+		local_16 = 1;
+		while (-1 < (int16)local_16) {
+			FUN_80017e64(2,((int)(int16)local_16 * 0x140 + 0x640) * 0x10000 >> 0x10,0);
+			_vm->waitForFrames(5);
+			local_16 = local_16 + -1;
+		}
+		i = i + 1;
+	}
+	tearBlinkActorTbl[0]->flags = tearBlinkActorTbl[0]->flags | 4;
+	tearBlinkActorTbl[1]->flags = tearBlinkActorTbl[1]->flags | 4;
+	FUN_80017e64(2,0x280,0);
+	FUN_80017e64(1,0,0);
+	FUN_80017e64(0,0,0);
+	local_224 = _vm->getRand(2);
+	handActorId->updateSequence(0);
+	handActorId->x_pos = handPositionsTbl[local_224].x;
+	handActorId->y_pos = handPositionsTbl[local_224].y;
+	handActorId->priorityLayer = 2;
+	bVar1 = false;
+	_vm->_talk->loadAndDisplayDialogAroundPoint(0x2958A,0x14,3,0x1e01,0);
+	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
+		_vm->waitForFrames(1);
+	}
+	while (_vm->waitForFrames(1), handActorId->isFlagSet(ACTOR_FLAG_10) || !_vm->isActionButtonPressed()) {
+		if (_vm->isLeftKeyPressed() && ((local_224 == 1 || (local_224 == 3)))) {
+			local_224 = local_224 + -1;
+			bVar1 = true;
+		}
+		if (_vm->isRightKeyPressed() && ((local_224 == 0 || (local_224 == 2)))) {
+			local_224 = local_224 + 1;
+			bVar1 = true;
+		}
+		if (_vm->isUpKeyPressed() && ((local_224 == 2 || (local_224 == 3)))) {
+			local_224 = local_224 + -2;
+			bVar1 = true;
+		}
+		if (_vm->isDownKeyPressed() && ((local_224 == 0 || (local_224 == 1)))) {
+			local_224 = local_224 + 2;
+			bVar1 = true;
+		}
+		if (bVar1) {
+			handActorId->pathfinding_maybe((int)handPositionsTbl[local_224].x, (int)handPositionsTbl[local_224].y, 2);
+			bVar1 = false;
+		}
+	}
+	handActorId->updateSequence(1);
+	do {
+	} while ((handActorId->flags & 4) == 0);
+	_vm->_dragonINIResource->getRecord(0x178)->field_12 = local_224 + 1;
+	if (goodRabbitPositionTbl[local_224] == 1) {
+		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(2);
+		_vm->_dragonINIResource->getRecord(0x178)->field_14 = 1;
+	}
+	else {
+		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(3);
+		i = 0;
+		while (((int16)i < 4 && (goodRabbitPositionTbl[(int16)i] != 1))) {
+			i = i + 1;
+		}
+		_vm->waitForFrames(0x1e);
+		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(2);
+		_vm->_dragonINIResource->getRecord(0x178)->field_14 = 0;
+	}
+	_vm->waitForFrames(0x3c * 2);
+//	PauseCDMusic();
+//	fade_related_calls_with_1f();
+//	FUN_80017f28_noop();
+//	DAT_80093234 = DAT_80093234 + 1;
+	_vm->_dragonINIResource->setFlickerRecord(flicker);
+	flicker->sceneId = 1;
+	_vm->setAllFlags(oldEngineFlags);
+	_vm->setFlags(ENGINE_FLAG_40);
+//	load_palette_into_frame_buffer
+//			(1,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
+//			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
+//	UnkCursorFunc1();
+//	load_palette_into_frame_buffer
+//			(4,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
+//			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
+	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
+	_vm->_inventory->setType(origInventoryType);
+	_vm->_scene->setSceneId(origSceneId);
+	_vm->_scene->loadScene(origSceneId, 0);
+}
+
+void Minigame3::FUN_80017e64(uint32 param_1, int16 param_2, int16 param_3) {
+	//TODO what does this do?
+}
+
+void Minigame3::FUN_80017f70_paletteRelated(uint16 unk) {
+	//TODO
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/minigame3.h b/engines/dragons/minigame3.h
new file mode 100644
index 0000000000..50b2b11d5f
--- /dev/null
+++ b/engines/dragons/minigame3.h
@@ -0,0 +1,44 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 DRAGONS_MINIGAME3_H
+#define DRAGONS_MINIGAME3_H
+
+namespace Dragons {
+
+class DragonsEngine;
+
+class Minigame3 {
+private:
+	DragonsEngine *_vm;
+public:
+	Minigame3(DragonsEngine *vm);
+
+	void run();
+private:
+	void FUN_80017e64(uint32 param_1, int16 param_2, int16 param_3);
+	void FUN_80017f70_paletteRelated(uint16 unk);
+
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_MINIGAME3_H
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index dfee06c640..8ec87c23f7 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -26,6 +26,7 @@
 #include "dragons/talk.h"
 #include "dragons/inventory.h"
 #include "dragons/scene.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
@@ -58,7 +59,7 @@ void Minigame4::run() {
 	DAT_80090428_videoUpdateRelated = 0;
 	//TODO vsync_updater_function = videoUpdateFunction;
 	//load_palette_into_frame_buffer(4,DAT_8006a3f8);
-	//load_palette_into_frame_buffer_2(4,1,0xff,1);
+	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
 	_vm->videoFlags |= 4;
 	_vm->_scene->setBgLayerPriority(2);
 	_vm->_scene->setMgLayerPriority(1);
@@ -106,7 +107,7 @@ void Minigame4::run() {
 //			(4,(uint)*(ushort *)
 //					(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10)
 //			   + *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
-//	load_palette_into_frame_buffer_2(4,1,0xff,1);
+	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
 	_vm->_scene->setSceneId(uVar1);
 	_vm->setAllFlags(uVar4);
 	uVar2->sceneId = uVar1;
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 1f19ada532..f5aff6222c 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -19,6 +19,7 @@ MODULE_OBJS := \
 	font.o \
 	inventory.o \
 	minigame1.o \
+	minigame3.o \
 	minigame4.o \
 	saveload.o \
 	scene.o \
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 9bd2098a96..b5167be8e3 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -132,4 +132,8 @@ Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect r
 	return Common::Rect(x, y, x + w, y + h);
 }
 
+void Screen::updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, uint16 endOffset, bool isTransparent) {
+	//TODO
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 8c3ee8a321..1b8db6e9b3 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -40,6 +40,7 @@ public:
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false);
 	void updateScreen();
+	void updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, uint16 endOffset, bool isTransparent);
 private:
 	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX);
 	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index f7be917e83..634959c63a 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -924,7 +924,7 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 		if (field2 == 0x1a && ini->field_1a_flags_maybe & 1 && ini->sceneId == _vm->getCurrentSceneId()) {
 			if (s1 & 2) {
 				ini->actor->flags |= Dragons::ACTOR_FLAG_80;
-				ini->actor->field_e = 0x100;
+				ini->actor->scale = 0x100;
 			} else {
 				ini->actor->flags &= ~Dragons::ACTOR_FLAG_80;
 			}
@@ -1225,7 +1225,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->iniItemInHand);
 					actor->flags = 0;
 					actor->priorityLayer = 0;
-					actor->field_e = 0x100;
+					actor->scale = 0x100;
 					actor->updateSequence((_vm->getINI(_vm->_cursor->iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index d478a533b8..ecf35d04e5 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -32,10 +32,11 @@
 #include "dragons/scene.h"
 #include "dragons/actor.h"
 #include "dragons/minigame1.h"
-#include "talk.h"
-#include "specialopcodes.h"
-#include "minigame1.h"
-#include "minigame4.h"
+#include "dragons/talk.h"
+#include "dragons/specialopcodes.h"
+#include "dragons/minigame1.h"
+#include "dragons/minigame3.h"
+#include "dragons/minigame4.h"
 
 
 namespace Dragons {
@@ -73,6 +74,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(3, spcClearEngineFlag10);
 	OPCODE(4, spcSetEngineFlag10);
 
+	OPCODE(6, spcRabbitsMiniGame);
 	OPCODE(7, spcDancingMiniGame);
 	OPCODE(8, spcCastleGardenLogic);
 	OPCODE(9, spcUnk9);
@@ -133,6 +135,7 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0x46, spcBlackDragonOnHillSceneLogic);
 
+	OPCODE(0x48, spcHedgehogTest);
 	OPCODE(0x49, spcLoadScene1);
 
 	OPCODE(0x4b, spcKnightsSavedCastleCutScene);
@@ -209,6 +212,11 @@ void SpecialOpcodes::spcSetEngineFlag10() {
 	_vm->setFlags(Dragons::ENGINE_FLAG_10);
 }
 
+void SpecialOpcodes::spcRabbitsMiniGame() {
+	Minigame3 minigame3(_vm);
+	minigame3.run();
+}
+
 void SpecialOpcodes::spcDancingMiniGame() {
 	Minigame4 minigame4(_vm);
 	minigame4.run();
@@ -455,7 +463,7 @@ void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
 void SpecialOpcodes::spcUnk34() {
 	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;
 	flicker->setFlag(ACTOR_FLAG_80);
-	flicker->field_e = 0x100;
+	flicker->scale = 0x100;
 }
 
 void SpecialOpcodes::spcFlickerClearFlag0x80() {
@@ -770,6 +778,16 @@ void SpecialOpcodes::spcUnk8b() {
 	//TODO sceneId_1 = DAT_80063e20; //0xA
 }
 
+void SpecialOpcodes::spcHedgehogTest() {
+	if (_vm->_dragonINIResource->getRecord(0x168)->actor->_sequenceID == 4 &&
+		_vm->_dragonINIResource->getRecord(0x169)->actor->_sequenceID == 4 &&
+		_vm->_dragonINIResource->getRecord(0x16a)->actor->_sequenceID == 4) {
+		_vm->_dragonINIResource->getRecord(0x169)->field_12 = 1;
+	} else {
+		_vm->_dragonINIResource->getRecord(0x169)->field_12 = 0;
+	}
+}
+
 void SpecialOpcodes::spcLoadScene1() {
 	CutScene *cutScene = new CutScene(_vm);
 	cutScene->scene1();
@@ -784,7 +802,7 @@ void SpecialOpcodes::spcKnightsSavedCastleCutScene() {
 
 void SpecialOpcodes::spcFlickerReturnsCutScene() {
 	CutScene *cutScene = new CutScene(_vm);
-	cutScene->flickerReturnsCutScene();
+	cutScene->flameReturnsCutScene();
 	delete cutScene;
 }
 
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 6f6177489e..bcc5c6c991 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -70,6 +70,7 @@ protected:
 	void spcClearEngineFlag10(); // 3
 	void spcSetEngineFlag10();   // 4
 
+	void spcRabbitsMiniGame(); //6
 	void spcDancingMiniGame(); // 7
 	void spcCastleGardenLogic(); // 8
 	void spcUnk9();
@@ -129,6 +130,7 @@ protected:
 
 	void spcBlackDragonOnHillSceneLogic(); //0x46
 
+	void spcHedgehogTest(); // 0x48
 	void spcLoadScene1(); // 0x49
 
 	void spcKnightsSavedCastleCutScene(); //0x4b
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 1394ced37c..79a66dbd32 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -456,6 +456,12 @@ uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 tex
 	return 1;
 }
 
+void Talk::loadAndDisplayDialogAroundPoint(uint32 textId, uint16 x, uint16 y, uint16 param_4, int16 param_5) {
+	uint16 buffer[1000];
+	loadText(textId, buffer, 1000);
+	displayDialogAroundPoint(buffer, x, y, param_4, param_5, textId);
+}
+
 void
 Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId) {
 // TODO
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 088c1e5efa..5f808f32ee 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -72,6 +72,7 @@ public:
 	void talkFromIni(uint32 iniId, uint32 textIndex);
 	void flickerRandomDefaultResponse();
 
+	void loadAndDisplayDialogAroundPoint(uint32 textId, uint16 x, uint16 y, uint16 param_4, int16 param_5);
 	uint32 displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex);
 	void displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId);
 	void displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex);


Commit: c7b9b69035e5b2747e6eb95d8132cf7b07e55f11
    https://github.com/scummvm/scummvm/commit/c7b9b69035e5b2747e6eb95d8132cf7b07e55f11
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on screen palette handling

Changed paths:
    engines/dragons/minigame3.cpp
    engines/dragons/minigame3.h
    engines/dragons/minigame4.cpp
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 035cd97132..0032c7513f 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -172,12 +172,13 @@ void Minigame3::run() {
 	origSceneId = _vm->getCurrentSceneId();
 	_vm->_scene->setSceneId(6);
 	_vm->_scene->loadScene(6 | 0x8000, 0);
-	_vm->_scene->setFgLayerPriority(0);
+	_vm->_scene->setFgLayerPriority(4);
+
 // TODO
-//	load_palette_into_frame_buffer(1,scrFileData_maybe);
-//	load_palette_into_frame_buffer(4,scrFileData_maybe);
+	_vm->_screen->loadPalette(1, _vm->_scene->getPalette());
+	_vm->_screen->loadPalette(4, _vm->_scene->getPalette());
 	_vm->_screen->updatePaletteTransparency(4, 1, 0xff, true);
-//	FUN_80017ef0();
+	FUN_80017ef0();
 	oldEngineFlags = _vm->getAllFlags();
 	_vm->clearFlags(ENGINE_FLAG_80);
 	_vm->clearFlags(ENGINE_FLAG_20);
@@ -754,12 +755,10 @@ void Minigame3::run() {
 	flicker->sceneId = 1;
 	_vm->setAllFlags(oldEngineFlags);
 	_vm->setFlags(ENGINE_FLAG_40);
-//	load_palette_into_frame_buffer
-//			(1,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
+//	_vm->_screen->loadPalette(1,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
 //			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
 //	UnkCursorFunc1();
-//	load_palette_into_frame_buffer
-//			(4,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
+//	_vm->_screen->loadPalette(4,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
 //			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
 	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
 	_vm->_inventory->setType(origInventoryType);
@@ -769,10 +768,32 @@ void Minigame3::run() {
 
 void Minigame3::FUN_80017e64(uint32 param_1, int16 param_2, int16 param_3) {
 	//TODO what does this do?
+//	int iVar1;
+//
+//	iVar1 = (param_1 & 0xffff) * 0x24;
+//	*(undefined2 *)(&DAT_80069644 + iVar1) = param_2;
+//	*(short *)(&DAT_80069646 + iVar1) = param_3 + 8;
+
+}
+
+void Minigame3::FUN_80017f70_paletteRelated(uint16 param_1) {
+	if (0x1f < param_1) {
+		param_1 = 0x1f;
+	}
+//	uVar1 = IsVSyncEventEnabled & 1;
+//	DisableVSyncEvent();
+	_vm->_screen->loadPalette(0, _vm->_scene->getPalette());
+	_vm->_screen->setPaletteRecord(0, 0x3f, param_1 * 0x421);
+//	load_palette_into_frame_buffer(0,abStack528);
+	_vm->_screen->updatePaletteTransparency(0, 0x3f,0x3f, true);
+//	if (uVar1 != 0) {
+//		EnableVSyncEvent();
+//	}
 }
 
-void Minigame3::FUN_80017f70_paletteRelated(uint16 unk) {
-	//TODO
+void Minigame3::FUN_80017ef0() {
+	//TODO DAT_80069680 = DAT_80069680 | 0x50000000;
+	FUN_80017f70_paletteRelated(0);
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame3.h b/engines/dragons/minigame3.h
index 50b2b11d5f..3bf4e9efd2 100644
--- a/engines/dragons/minigame3.h
+++ b/engines/dragons/minigame3.h
@@ -36,6 +36,7 @@ public:
 private:
 	void FUN_80017e64(uint32 param_1, int16 param_2, int16 param_3);
 	void FUN_80017f70_paletteRelated(uint16 unk);
+	void FUN_80017ef0();
 
 };
 
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 8ec87c23f7..302424024a 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -58,7 +58,7 @@ void Minigame4::run() {
 	_vm->clearFlags(ENGINE_FLAG_1);
 	DAT_80090428_videoUpdateRelated = 0;
 	//TODO vsync_updater_function = videoUpdateFunction;
-	//load_palette_into_frame_buffer(4,DAT_8006a3f8);
+	_vm->_screen->loadPalette(4, _vm->_scene->getPalette());
 	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
 	_vm->videoFlags |= 4;
 	_vm->_scene->setBgLayerPriority(2);
@@ -103,8 +103,7 @@ void Minigame4::run() {
 	// EnableVSyncEvent();
 	_vm->_dragonINIResource->setFlickerRecord(uVar2);
 	_vm->_inventory->setType(uVar3);
-//	load_palette_into_frame_buffer
-//			(4,(uint)*(ushort *)
+//	_vm->_screen->loadPalette(4,(uint)*(ushort *)
 //					(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10)
 //			   + *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
 	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index b5167be8e3..3c762fc62f 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -19,9 +19,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
+#include <common/endian.h>
 #include "common/system.h"
 #include "common/rect.h"
 #include "engines/util.h"
+#include "dragons/dragons.h"
+#include "dragons/scene.h"
 #include "screen.h"
 
 namespace Dragons {
@@ -133,7 +136,46 @@ Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect r
 }
 
 void Screen::updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, uint16 endOffset, bool isTransparent) {
-	//TODO
+	assert(paletteNum < DRAGONS_NUM_PALETTES);
+	assert(startOffset < 256);
+	assert(endOffset < 256);
+
+	// TODO
+	// this is needed for palette 0 for some reason.
+//	DAT_80069638 = DAT_80069638 | 0x50000000;
+//	DAT_8006965c = DAT_8006965c | 0x50000000;
+//	DAT_80069680 = DAT_80069680 | 0x50000000;
+
+	for (int i = startOffset; i <= endOffset; i++) {
+		if (isTransparent) {
+			_palettes[paletteNum][i * 2 + 1] |= 0x80;
+		} else {
+			_palettes[paletteNum][i * 2 + 1] &= ~0x80;
+		}
+	}
+}
+
+void Screen::loadPalette(uint16 paletteNum, byte *palette) {
+	assert(paletteNum < DRAGONS_NUM_PALETTES);
+	if (paletteNum == 0) {
+		Dragons::getEngine()->_scene->setStagePalette(palette);
+	} else {
+		memcpy(&_palettes[paletteNum][0], palette, 512);
+	}
+}
+
+void Screen::setPaletteRecord(uint16 paletteNum, uint16 offset, uint16 newValue) {
+	assert(paletteNum < DRAGONS_NUM_PALETTES);
+	assert(offset < 256);
+	WRITE_LE_UINT16(&_palettes[paletteNum][offset * 2], newValue);
+	if (paletteNum == 0) {
+		Dragons::getEngine()->_scene->setStagePalette(&_palettes[0][0]);
+	}
+}
+
+byte *Screen::getPalette(uint16 paletteNum) {
+	assert(paletteNum < DRAGONS_NUM_PALETTES);
+	return _palettes[paletteNum];
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 1b8db6e9b3..5ef286035a 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -26,11 +26,12 @@
 #include "graphics/pixelformat.h"
 
 namespace Dragons {
-
+#define DRAGONS_NUM_PALETTES 5
 class Screen {
 private:
 	Graphics::PixelFormat _pixelFormat;
 	Graphics::Surface *_backSurface;
+	byte _palettes[DRAGONS_NUM_PALETTES][512];
 public:
 	virtual ~Screen();
 
@@ -40,6 +41,9 @@ public:
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false);
 	void updateScreen();
+	void loadPalette(uint16 paletteNum, byte *palette);
+	byte *getPalette(uint16 paletteNum);
+	void setPaletteRecord(uint16 paletteNum, uint16 offset, uint16 newValue);
 	void updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, uint16 endOffset, bool isTransparent);
 private:
 	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX);


Commit: 16ae7e579ec96b7e44f12f4a11133536d90d3765
    https://github.com/scummvm/scummvm/commit/16ae7e579ec96b7e44f12f4a11133536d90d3765
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Working on semi-transparent actors

Changed paths:
    engines/dragons/actorresource.cpp
    engines/dragons/background.cpp
    engines/dragons/bag.cpp
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 3290569700..5851c32d00 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -57,7 +57,7 @@ bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream
 
 	stream.seek(paletteOffset);
 	stream.read(_palette, 512);
-	_palette[1] = 0x80; // set alpha (bit 15) on first palette entry.
+	//_palette[1] = 0x80; // set alpha (bit 15) on first palette entry.
 
 	stream.seek(frameOffset);
 
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 317438c508..d48bd145ee 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -109,8 +109,8 @@ bool Background::load(byte *dataStart, uint32 size) {
 	_data = dataStart;
 
 	stream.read(_palette, 512);
-	_palette[0] = 0x80; //FIXME update palette
-	_palette[1] = 0x80;
+	_palette[0] = 0x00; //FIXME update palette
+	_palette[1] = 0x00;
 
 	_points1 = loadPoints(stream); // 0x200
 	_points2 = loadPoints(stream); // 0x280
diff --git a/engines/dragons/bag.cpp b/engines/dragons/bag.cpp
index 3f1a599c25..8ca1e7e702 100644
--- a/engines/dragons/bag.cpp
+++ b/engines/dragons/bag.cpp
@@ -61,8 +61,18 @@ void Bag::load(BigfileArchive *bigFileArchive) {
 
 	stream.seek(0x4);
 	stream.read(pal, 512);
-	pal[0] = 0x80; //FIXME update palette
-	pal[1] = 0x80;
+
+	pal[0] = 0x0;
+	pal[1] = 0x0;
+	for (int i = 1; i < 0x100; i++) {
+		uint c = READ_LE_INT16(&pal[i * 2]);
+		if ( c == 0 ) {
+			c = 0x8000;
+		} else {
+			//c = (ushort)(((uint)c & 0x1f) << 10) | (ushort)(((uint)c & 0x7c00) >> 10) | c & 0x3e0;
+		}
+		WRITE_LE_UINT16(&pal[i * 2], c);
+	}
 
 	stream.seek(0x308);
 	stream.read(tilemap, 0x1f4);
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 162594f4d2..e8b1d2590d 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -315,6 +315,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 void Scene::draw() {
 	Common::Rect rect(_camera.x, _camera.y, _camera.x + 320, _camera.y + 200);
+	_vm->_screen->clearScreen();
 
 	for(uint16 priority = 1; priority < 16; priority++) {
 		if (priority == _stage->getBgLayerPriority()) {
@@ -351,7 +352,7 @@ void Scene::draw() {
 					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
 						  s->w, s->h, actor->priorityLayer);
-					_screen->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X));
+					_screen->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? 255 : 128);
 				} else {
 					debug(4, "Actor (not displayed) %d %s (%d, %d) Priority: %d", actor->_actorID,
 						  actor->_actorResource->getFilename(),
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 3c762fc62f..5207cef748 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -47,10 +47,10 @@ Screen::~Screen() {
 }
 
 void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY) {
-	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, srcSurface.w, 0, destX, destY, srcSurface.w, srcSurface.h, false);
+	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, srcSurface.w, 0, destX, destY, srcSurface.w, srcSurface.h, false, 255);
 }
 
-void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect, bool flipX) {
+void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect, bool flipX, uint8 alpha) {
 	Common::Rect clipRect = clipRectToScreen( destX,  destY, srcRect);
 	if (clipRect.width() == 0 || clipRect.height() == 0) {
 		return;
@@ -63,10 +63,24 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
 		destY = 0;
 	}
 
-	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, srcSurface.w, clipRect.left, destX, destY, clipRect.width(), clipRect.height(), flipX);
+	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, srcSurface.w, clipRect.left, destX, destY, clipRect.width(), clipRect.height(), flipX, alpha);
 }
 
-void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX) {
+/**
+ * Fast RGB555 pixel blending
+ * @param fg      The foreground color in uint16_t RGB565 format
+ * @param bg      The background color in uint16_t RGB565 format
+ * @param alpha   The alpha in range 0-255
+ **/
+uint16 alphaBlendRGB555( uint32 fg, uint32 bg, uint8 alpha ){
+	alpha = ( alpha + 4 ) >> 3;
+	bg = (bg | (bg << 16)) & 0b00000011111000001111100000011111;
+	fg = (fg | (fg << 16)) & 0b00000011111000001111100000011111;
+	uint32_t result = ((((fg - bg) * alpha) >> 5) + bg) & 0b00000011111000001111100000011111;
+	return (uint16_t)((result >> 16) | result);
+}
+
+void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha) {
 	assert(buffer);
 
 	assert(destX >= 0 && destX < _backSurface->w);
@@ -80,10 +94,15 @@ void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, i
 	for (int i = 0; i < height; i++) {
 		for (int j = 0; j < width; j++) {
 			int32 srcIdx = flipX ? srcWidth - (srcXOffset * 2) - j - 1 : j;
-			if ((src[srcIdx * 2 + 1] & 0x80) == 0) {
-				// only copy opaque pixels
-				dst[j * 2] = src[srcIdx * 2];
-				dst[j * 2 + 1] = src[srcIdx * 2 + 1];
+			if (src[srcIdx * 2] != 0 || src[srcIdx * 2 + 1] != 0) {
+				if ((src[srcIdx * 2 + 1] & 0x80) == 0 || alpha == 255) {
+					// only copy opaque pixels
+					dst[j * 2] = src[srcIdx * 2];
+					dst[j * 2 + 1] = src[srcIdx * 2 + 1];
+				} else {
+					WRITE_LE_UINT16(&dst[j * 2], alphaBlendRGB555(READ_LE_INT16(&src[srcIdx * 2]), READ_LE_INT16(&dst[j * 2]), alpha));
+					// semi-transparent pixels.
+				}
 			}
 		}
 		src += srcPitch;
@@ -178,4 +197,8 @@ byte *Screen::getPalette(uint16 paletteNum) {
 	return _palettes[paletteNum];
 }
 
+void Screen::clearScreen() {
+	_backSurface->fillRect(Common::Rect(0,0, _backSurface->w, _backSurface->h), 0);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 5ef286035a..34753e57d7 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -39,14 +39,15 @@ public:
 
 	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
-	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false);
+	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255);
 	void updateScreen();
 	void loadPalette(uint16 paletteNum, byte *palette);
 	byte *getPalette(uint16 paletteNum);
 	void setPaletteRecord(uint16 paletteNum, uint16 offset, uint16 newValue);
 	void updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, uint16 endOffset, bool isTransparent);
+	void clearScreen();
 private:
-	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX);
+	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
 	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
 };
 


Commit: 939bd5dfd63816a7ab1f59461f80d8102cc2d6ac
    https://github.com/scummvm/scummvm/commit/939bd5dfd63816a7ab1f59461f80d8102cc2d6ac
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on palette handling. Converted Actor back to 8bit surface.
Added debug mode. Toggle with Tab key.

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/actorresource.cpp
    engines/dragons/actorresource.h
    engines/dragons/cutscene.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/minigame3.cpp
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/screen.cpp
    engines/dragons/screen.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 716bdae3bc..fc3d8bcd92 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -25,6 +25,7 @@
 #include "actorresource.h"
 #include "actor.h"
 #include "scene.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
@@ -186,18 +187,16 @@ void Actor::loadFrame(uint16 frameOffset) {
 	}
 
 	frame = _actorResource->loadFrameHeader(frameOffset);
-	uint16 paletteId = 0;
-	if (flags & Dragons::ACTOR_FLAG_4000) {
-		paletteId = 0xf7;
-	} else if (flags & Dragons::ACTOR_FLAG_8000) {
-		paletteId = 0xf1;
+
+	if (frame->flags & 0x800) {
+		frame_flags |= ACTOR_FRAME_FLAG_2;
 	} else {
-		paletteId = 0;
+		frame_flags &= ~ACTOR_FRAME_FLAG_2;
 	}
 
 	surface = _actorResource->loadFrame(*frame, NULL); // TODO paletteId == 0xf1 ? getEngine()->getBackgroundPalette() : NULL);
 
-	debug(5, "ActorId: %d load frame header: (%d,%d) palette: %X", _actorID, frame->width, frame->height, paletteId);
+	debug(5, "ActorId: %d load frame header: (%d,%d)", _actorID, frame->width, frame->height);
 
 	flags |= Dragons::ACTOR_FLAG_8; //TODO check if this is the right spot. engine sets it at 0x800185b0
 
@@ -884,4 +883,16 @@ bool Actor::waitUntilFlag4IsSetAllowSkip() {
 	return false;
 }
 
+byte *Actor::getPalette() {
+	if (!isFlagSet(ACTOR_FLAG_4000)) {
+		if (!isFlagSet(ACTOR_FLAG_8000)) {
+			//TODO need to support per actor custom palettes.
+			return getEngine()->_screen->getPalette(1);
+		} else {
+			return getEngine()->_scene->getPalette();
+		}
+	}
+	return getEngine()->_screen->getPalette(4);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index b7bcf5ddcd..87ae580646 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -52,6 +52,7 @@ enum ActorFlags {
 };
 
 enum ActorFrameFlags {
+	ACTOR_FRAME_FLAG_2 = 0x2,
 	ACTOR_FRAME_FLAG_10 = 0x10,
 	ACTOR_FRAME_FLAG_20 = 0x20
 };
@@ -85,7 +86,7 @@ private:
 class Actor {
 public:
 	uint16 _actorID;
-	ActorResource*_actorResource;
+	ActorResource* _actorResource;
 	uint16 actorFileDictionaryIndex;
 	int16 resourceID;
 	byte *_seqCodeIp;
@@ -145,6 +146,7 @@ public:
 	bool isFlagSet(uint32 flag);
 	bool isFlagClear(uint32 flag) { return !isFlagSet(flag); }
 
+	byte *getPalette();
 private:
 	void pathfindingCleanup();
 	uint16 pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 unkType);
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 5851c32d00..223842f7a9 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -57,7 +57,15 @@ bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream
 
 	stream.seek(paletteOffset);
 	stream.read(_palette, 512);
-	//_palette[1] = 0x80; // set alpha (bit 15) on first palette entry.
+	_palette[0] = 0;
+	_palette[1] = 0;
+//	_palette[1] = 0x80; // set alpha (bit 15) on first palette entry.
+
+//	for (int i = 1; i < 0x100; i++) {
+//		if (_palette[i * 2] == 0 && _palette[i * 2 + 1] == 0) {
+//			_palette[i * 2 + 1] = 0x80;
+//		}
+//	}
 
 	stream.seek(frameOffset);
 
@@ -86,25 +94,13 @@ bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream
 	return false;
 }
 
-void ActorResource::writePixelBlock(byte *pixels, byte *data, byte *palette) {
-	pixels[0] = palette[data[0] * 2];
-	pixels[1] = palette[data[0] * 2 + 1];
-	pixels[2] = palette[data[1] * 2];
-	pixels[3] = palette[data[1] * 2 + 1];
-	pixels[4] = palette[data[2] * 2];
-	pixels[5] = palette[data[2] * 2 + 1];
-	pixels[6] = palette[data[3] * 2];
-	pixels[7] = palette[data[3] * 2 + 1];
-}
-
 Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame, byte *palette) {
 	if (!palette) {
 		palette = _palette;
 	}
 
 	Graphics::Surface *surface = new Graphics::Surface();
-	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
-	surface->create(actorFrame.width, actorFrame.height, pixelFormat16);
+	surface->create(actorFrame.width, actorFrame.height, Graphics::PixelFormat::createFormatCLUT8());
 
 	byte *pixels = (byte *)surface->getPixels();
 
@@ -124,13 +120,9 @@ Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame, byte *palett
 			blockSize -= size;
 
 			if (size != 0) {
-				for(int32 i = size; i != 0; i--) {
-					//TODO clean up this copy.
-					writePixelBlock(pixels, data, palette);
-
-					data += 4;
-					pixels += 8;
-				}
+				memcpy(pixels, data, size * 4);
+				data += size * 4;
+				pixels += size * 4;
 			}
 		} else {
 			size = size & 0x7fffffff;
@@ -140,9 +132,8 @@ Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame, byte *palett
 			blockSize -= size;
 			if (size != 0) {
 				for(int32 i = size; i != 0; i--) {
-					//TODO write bytes to pixel data.
-					writePixelBlock(pixels, data, palette);
-					pixels += 8;
+					memcpy(pixels, data, 4);
+					pixels += 4;
 				}
 			}
 			data += 4;
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index c2014dc474..228c0a89a4 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -76,7 +76,6 @@ public:
 	byte *getPalette();
 
 private:
-	void writePixelBlock(byte *pixels, byte *data, byte *palette);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 0f5d8041de..b3bec33116 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -28,6 +28,7 @@
 #include "dragons/cursor.h"
 #include "dragons/dragonini.h"
 #include "dragons/scene.h"
+#include "dragons/screen.h"
 #include "dragons/talk.h"
 
 namespace Dragons {
@@ -469,7 +470,7 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 		_vm->_scene->setMgLayerPriority(1); //TODO investigate why this is 1 not 2
 		_vm->_scene->_camera.x = sParm2 + 0x3c0;
 		_vm->_scene->setFgLayerPriority(0);
-		_vm->_scene->setStagePalette(_palettes + 2 * 512);
+		_vm->_screen->loadPalette(0, _palettes + 2 * 512);
 		for (int i = 2; i < 0x17; i++) {
 			Actor *actor = _vm->_actorManager->getActor(i);
 			actor->x_pos += 0x3c0;
@@ -480,14 +481,14 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 			if (newPosition != 0) {
 				return;
 			}
-			_vm->_scene->setStagePalette(_palettes + 0 * 512);
+			_vm->_screen->loadPalette(0, _palettes + 0 * 512);
 			_vm->_scene->setMgLayerPriority(0);
 			_vm->_scene->setFgLayerPriority(0);
 			_vm->_scene->_camera.x = 0;
 		}
 		else {
 			if (newPosition == 2) {
-				_vm->_scene->setStagePalette(_palettes + 3 * 512);
+				_vm->_screen->loadPalette(0, _palettes + 3 * 512);
 				_vm->_scene->setMgLayerPriority(2);
 				_vm->_scene->setFgLayerPriority(3);
 				_vm->_scene->_camera.x = 0;
@@ -496,7 +497,7 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 				if (newPosition != 3) {
 					return;
 				}
-				_vm->_scene->setStagePalette(_palettes + 1 * 512);
+				_vm->_screen->loadPalette(0, _palettes + 1 * 512);
 				_vm->_scene->setMgLayerPriority(2);
 				_vm->_scene->setFgLayerPriority(0);
 				_vm->_scene->_camera.x = sParm2;
@@ -529,7 +530,7 @@ void CutScene::diamondScene() {
 			_vm->waitForFramesAllowSkip(0x2c);
 			//TODO fade_related_calls_with_1f();
 			memcpy(palette, _vm->_scene->getPalette(), 512);
-			_vm->_scene->setStagePalette(actorId_00->_actorResource->getPalette());
+			_vm->_screen->loadPalette(0, actorId_00->_actorResource->getPalette());
 			_vm->_scene->_camera.x = 0x140;
 			//TODO call_fade_related_1f();
 			if (!actorId_00->actorSetSequenceAndWaitAllowSkip(0)) {
@@ -537,7 +538,7 @@ void CutScene::diamondScene() {
 				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_00,1,2,0x42a66,0x3c01) != 2) {
 					_vm->waitForFramesAllowSkip(0x13);
 					//TODO fade_related_calls_with_1f();
-					_vm->_scene->setStagePalette(palette);
+					_vm->_screen->loadPalette(0, palette);
 					_vm->_scene->_camera.x = 0;
 					//TODO call_fade_related_1f();
 					actorId_01->updateSequence(0x19);
@@ -692,7 +693,7 @@ void CutScene::flameReturnsCutScene() {
 //	load_actor_file(0x7e);
 //	load_actor_file(0x8f);
 //	load_actor_file(0xaa);
-	DAT_80063514 = DAT_80063514 & 0xfffe | 0x600;
+	DAT_80063514 = (DAT_80063514 & 0xfffe) | 0x600;
 	FUN_8003d388();
 	DAT_80072de8->updateSequence(0x1f);
 	DAT_80072e04->x_pos = 0x10b;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 152ce6ef1f..1d0e03f10a 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -88,6 +88,9 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_dKeyDown = false;
 	_oKeyDown = false;
 	_pKeyDown = false;
+
+	_debugMode = false;
+
 	reset();
 }
 
@@ -172,6 +175,8 @@ void DragonsEngine::updateEvents() {
 					_oKeyDown = true;
 				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_p) {
 					_pKeyDown = true;
+				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_TAB) {
+					_debugMode = !_debugMode;
 				}
 				break;
 			default:
@@ -1240,6 +1245,14 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
 	_talk->init();
 
+	_screen->loadPalette(1, _cursor->getPalette());
+	setupPalette1();
+
+	_screen->loadPalette(2, _cursor->getPalette());
+	_screen->loadPalette(4, _cursor->getPalette());
+	_screen->updatePaletteTransparency(4, 1, 0xff, true);
+
+	// TODO FUN_80017010_update_actor_texture_maybe();
 	if (sceneId > 2) {
 		_dragonVAR->setVar(1, 1);
 	}
@@ -1276,7 +1289,7 @@ void DragonsEngine::reset() {
 	data_800633fa = 0;
 
 	for(int i = 0; i < 8; i++) {
-		opCode1A_tbl[i].field0 = 0;
+		opCode1A_tbl[i].paletteType = 0;
 		opCode1A_tbl[i].field2 = 0;
 		opCode1A_tbl[i].field4 = 0;
 		opCode1A_tbl[i].field6 = 0;
@@ -1307,8 +1320,8 @@ uint32 DragonsEngine::shuffleRandState()
 
 	returnBit = _randomState & 1;
 	_randomState = _randomState >> 1 |
-				  (_randomState << 0x1e ^ _randomState ^ _randomState << 0x1d ^ _randomState << 0x1b ^
-						  _randomState << 0x19) & 0x80000000;
+			((_randomState << 0x1e ^ _randomState ^ _randomState << 0x1d ^ _randomState << 0x1b ^
+						  _randomState << 0x19) & 0x80000000);
 	return returnBit;
 }
 
@@ -1353,6 +1366,18 @@ bool DragonsEngine::isR1ButtonPressed() {
 	return _pKeyDown;
 }
 
+void DragonsEngine::setupPalette1() {
+	byte palette[512];
+	memcpy(palette, _cursor->getPalette(), 0x100);
+	memcpy(palette + 0x100, _cursor->getPalette(), 0x100);
+	_screen->loadPalette(1, palette);
+	_screen->updatePaletteTransparency(1,0x40,0x7f,true);
+}
+
+bool DragonsEngine::isDebugMode() {
+	return _debugMode;
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index baf229d120..cf88314c0d 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -95,7 +95,7 @@ enum UnkFlags {
 };
 
 struct opCode1AStruct {
-	int16 field0;
+	int16 paletteType;
 	int16 field2;
 	int16 field4;
 	int16 field6;
@@ -184,6 +184,8 @@ private:
 	bool _oKeyDown;
 	bool _pKeyDown;
 
+	bool _debugMode;
+
 	void (*_sceneUpdateFunction)();
 protected:
 	virtual bool hasFeature(EngineFeature f) const;
@@ -259,7 +261,11 @@ public:
 	bool checkForDownKeyRelease();
 	bool checkForUpKeyRelease();
 
+	bool isDebugMode();
+
 	uint16 getRand(uint16 max);
+
+	void setupPalette1();
 private:
 	bool savegame(const char *filename, const char *description);
 	bool loadgame(const char *filename);
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 0032c7513f..3ba48442d5 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -757,7 +757,7 @@ void Minigame3::run() {
 	_vm->setFlags(ENGINE_FLAG_40);
 //	_vm->_screen->loadPalette(1,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
 //			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
-//	UnkCursorFunc1();
+	_vm->setupPalette1();
 //	_vm->_screen->loadPalette(4,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
 //			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
 	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index e8b1d2590d..a434b13b18 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -203,13 +203,13 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 				if (actor) {
 					ini->actor = actor;
-					if (ini->sequenceId & 0x1000) {
+					if (ini->field_1a_flags_maybe & 0x1000) {
 						actor->frame_flags |= 0x10;
 					} else {
 						if (ini->field_1a_flags_maybe & 0x2000) {
 							actor->frame_flags |= 0x20;
 						} else {
-							actor->frame_flags &= 0xffef;
+							actor->frame_flags &= ~0x10;
 						}
 					}
 
@@ -352,7 +352,11 @@ void Scene::draw() {
 					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
 						  s->w, s->h, actor->priorityLayer);
-					_screen->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? 255 : 128);
+					_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? 255 : 128);
+					if (_vm->isDebugMode()) {
+						_screen->drawRect(0x7fff, Common::Rect(x, y, x + s->w, y + s->h), actor->_actorID);
+						drawActorNumber(x + s->w, y + 8, actor->_actorID);
+					}
 				} else {
 					debug(4, "Actor (not displayed) %d %s (%d, %d) Priority: %d", actor->_actorID,
 						  actor->_actorResource->getFilename(),
@@ -362,6 +366,9 @@ void Scene::draw() {
 		}
 	}
 	_vm->_fontManager->draw();
+	if (_vm->isDebugMode()) {
+		_vm->_fontManager->clearText();
+	}
 }
 
 int16 Scene::getPriorityAtPosition(Common::Point pos) {
@@ -441,4 +448,17 @@ void Scene::setStagePalette(byte *newPalette) {
 	_stage->setPalette(newPalette);
 }
 
+
+void Scene::drawActorNumber(int16 x, int16 y, uint16 actorId) {
+	uint16 text[30];
+	char text8[15];
+
+	sprintf(text8, "%d", actorId);
+
+	for(int i = 0; i < strlen(text8); i++) {
+		text[i] = text8[i];
+	}
+	_vm->_fontManager->addText(x, y, text, strlen(text8), 1);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index a3cf0aa1f5..c9cffdddbe 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -83,6 +83,7 @@ public:
 
 private:
 	void resetActorFrameFlags();
+	void drawActorNumber(int16 x, int16 y, uint16 actorId);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 5207cef748..766e261f18 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -66,6 +66,22 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
 	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, srcSurface.w, clipRect.left, destX, destY, clipRect.width(), clipRect.height(), flipX, alpha);
 }
 
+void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, const Common::Rect srcRect, bool flipX, uint8 alpha) {
+	Common::Rect clipRect = clipRectToScreen( destX,  destY, srcRect);
+	if (clipRect.width() == 0 || clipRect.height() == 0) {
+		return;
+	}
+
+	if (destX < 0) {
+		destX = 0;
+	}
+	if (destY < 0) {
+		destY = 0;
+	}
+
+	copyRectToSurface8bpp(srcSurface.getBasePtr(clipRect.left, clipRect.top), palette, srcSurface.pitch, srcSurface.w, clipRect.left, destX, destY, clipRect.width(), clipRect.height(), flipX, alpha);
+}
+
 /**
  * Fast RGB555 pixel blending
  * @param fg      The foreground color in uint16_t RGB565 format
@@ -74,9 +90,9 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
  **/
 uint16 alphaBlendRGB555( uint32 fg, uint32 bg, uint8 alpha ){
 	alpha = ( alpha + 4 ) >> 3;
-	bg = (bg | (bg << 16)) & 0b00000011111000001111100000011111;
-	fg = (fg | (fg << 16)) & 0b00000011111000001111100000011111;
-	uint32_t result = ((((fg - bg) * alpha) >> 5) + bg) & 0b00000011111000001111100000011111;
+	bg = (bg | (bg << 16)) & 0b00000011111000000111110000011111;
+	fg = (fg | (fg << 16)) & 0b00000011111000000111110000011111;
+	uint32_t result = ((((fg - bg) * alpha) >> 5) + bg) & 0b00000011111000000111110000011111;
 	return (uint16_t)((result >> 16) | result);
 }
 
@@ -110,6 +126,36 @@ void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, i
 	}
 }
 
+void Screen::copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha) {
+	assert(buffer);
+
+	assert(destX >= 0 && destX < _backSurface->w);
+	assert(destY >= 0 && destY < _backSurface->h);
+	assert(height > 0 && destY + height <= _backSurface->h);
+	assert(width > 0 && destX + width <= _backSurface->w);
+
+	// Copy buffer data to internal buffer
+	const byte *src = (const byte *)buffer;
+	byte *dst = (byte *)_backSurface->getBasePtr(destX, destY);
+	for (int i = 0; i < height; i++) {
+		for (int j = 0; j < width; j++) {
+			int32 srcIdx = flipX ? srcWidth - (srcXOffset * 2) - j - 1 : j;
+			uint16 c = READ_LE_UINT16(&palette[src[srcIdx] * 2]);
+			if (c != 0) {
+				if (!(c & 0x8000) || alpha == 255) {
+					// only copy opaque pixels
+					WRITE_LE_UINT16(&dst[j * 2], c & ~0x8000);
+				} else {
+					WRITE_LE_UINT16(&dst[j * 2], alphaBlendRGB555(c, READ_LE_INT16(&dst[j * 2]), alpha));
+					// semi-transparent pixels.
+				}
+			}
+		}
+		src += srcPitch;
+		dst += _backSurface->pitch;
+	}
+}
+
 Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect rect) {
 	int16 x, y, w, h;
 	x = rect.left;
@@ -175,12 +221,36 @@ void Screen::updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, ui
 }
 
 void Screen::loadPalette(uint16 paletteNum, byte *palette) {
+	bool isTransPalette = (paletteNum & 0x8000);
+	paletteNum &= ~0x8000;
 	assert(paletteNum < DRAGONS_NUM_PALETTES);
 	if (paletteNum == 0) {
 		Dragons::getEngine()->_scene->setStagePalette(palette);
 	} else {
 		memcpy(&_palettes[paletteNum][0], palette, 512);
+		if (paletteNum == 2 || paletteNum == 4 || paletteNum == 5) {
+			_palettes[paletteNum][2] = 0;
+			_palettes[paletteNum][3] = 0;
+		}
+		if (paletteNum == 1) {
+			_palettes[paletteNum][2] = 1;
+			_palettes[paletteNum][3] = 0;
+		}
+	}
+
+	for (int i =1 ; i < 0x100; i++) {
+		uint16 c = READ_LE_INT16(&_palettes[paletteNum][i * 2]);
+		if ((c & ~0x8000) == 0) {
+			if (!isTransPalette) {
+				WRITE_LE_UINT16(&_palettes[paletteNum][i * 2], 0x8000);
+			}
+		} else {
+			//TODO is this needed? see load_palette_into_frame_buffer()
+//			c = (ushort)(((uint)c & 0x1f) << 10) | (ushort)(((uint)c & 0x7c00) >> 10) |
+//					(c & 0x3e0) | (c & 0x8000);
+		}
 	}
+	WRITE_LE_UINT16(&_palettes[paletteNum][0], 0);
 }
 
 void Screen::setPaletteRecord(uint16 paletteNum, uint16 offset, uint16 newValue) {
@@ -201,4 +271,17 @@ void Screen::clearScreen() {
 	_backSurface->fillRect(Common::Rect(0,0, _backSurface->w, _backSurface->h), 0);
 }
 
+void Screen::drawRect(uint16 colour, Common::Rect rect, int id) {
+	Common::Rect clippedRect = clipRectToScreen(0, 0, rect);
+	//top
+	_backSurface->drawLine(clippedRect.left, clippedRect.top, clippedRect.right, clippedRect.top, colour);
+	//right
+	_backSurface->drawLine(clippedRect.right, clippedRect.top, clippedRect.right, clippedRect.bottom, colour);
+	//bottom
+	_backSurface->drawLine(clippedRect.left, clippedRect.bottom, clippedRect.right, clippedRect.bottom, colour);
+	//left
+	_backSurface->drawLine(clippedRect.left, clippedRect.top, clippedRect.left, clippedRect.bottom, colour);
+
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 34753e57d7..2adf2e314a 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -40,14 +40,17 @@ public:
 	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255);
+	void copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255);
 	void updateScreen();
 	void loadPalette(uint16 paletteNum, byte *palette);
 	byte *getPalette(uint16 paletteNum);
 	void setPaletteRecord(uint16 paletteNum, uint16 offset, uint16 newValue);
 	void updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, uint16 endOffset, bool isTransparent);
 	void clearScreen();
+	void drawRect(uint16 colour, Common::Rect rect, int id);
 private:
 	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
+	void copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
 	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
 };
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 634959c63a..521ce0c911 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -1094,7 +1094,7 @@ void ScriptOpcodes::opUnk1A(ScriptOpCall &scriptOpCall) {
 
 	assert(index < 8);
 
-	_vm->opCode1A_tbl[index].field0 = field4;
+	_vm->opCode1A_tbl[index].paletteType = field4;
 	_vm->opCode1A_tbl[index].field2 = field6;
 	_vm->opCode1A_tbl[index].field4 = field8;
 	_vm->opCode1A_tbl[index].field6 = fieldA;
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 79a66dbd32..7f192254a4 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -558,7 +558,7 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 		callMaybeResetData();
 		int numActiveDialogEntries = 0;
 		for (Common::Array<TalkDialogEntry*>::iterator it = _dialogEntries.begin(); it != _dialogEntries.end(); it++) {
-			if (!(*it)->flags & 1) {
+			if (!((*it)->flags & 1)) {
 				numActiveDialogEntries++;
 			}
 		}


Commit: d23849d95dcc16313de0053d45bc4793191f98e7
    https://github.com/scummvm/scummvm/commit/d23849d95dcc16313de0053d45bc4793191f98e7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: more palette fixes. Update scene palette with cursor palette

Changed paths:
    engines/dragons/background.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index d48bd145ee..b85d96463d 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -175,8 +175,7 @@ Common::Point *Background::loadPoints(Common::SeekableReadStream &stream) {
 
 Graphics::Surface *Background::initGfxLayer(TileMap &tileMap) {
 	Graphics::Surface *surface = new Graphics::Surface();
-	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
-	surface->create(tileMap.w * TILE_WIDTH, tileMap.h * TILE_HEIGHT, pixelFormat16);
+	surface->create(tileMap.w * TILE_WIDTH, tileMap.h * TILE_HEIGHT, Graphics::PixelFormat::createFormatCLUT8());
 	return surface;
 }
 
@@ -192,13 +191,20 @@ void Background::loadGfxLayer(Graphics::Surface *surface, TileMap &tileMap, byte
 
 void drawTileToSurface(Graphics::Surface *surface, byte *palette, byte *tile, uint32 x, uint32 y) {
 	byte *pixels = (byte *)surface->getPixels();
-	for(int ty = 0; ty < TILE_HEIGHT; ty++) {
-		for(int tx = 0; tx < TILE_WIDTH; tx++) {
-			uint32 cidx = *tile;
-			uint32 offset = (y + ty) * surface->pitch + (x + tx) * 2;
-			pixels[offset] = palette[cidx * 2];
-			pixels[offset + 1] = palette[cidx * 2 + 1];
-			tile++;
+	if (surface->format.bpp() == 16) {
+		for(int ty = 0; ty < TILE_HEIGHT; ty++) {
+			for(int tx = 0; tx < TILE_WIDTH; tx++) {
+				uint32 cidx = *tile;
+				uint32 offset = (y + ty) * surface->pitch + (x + tx) * 2;
+				pixels[offset] = palette[cidx * 2];
+				pixels[offset + 1] = palette[cidx * 2 + 1];
+				tile++;
+			}
+		}
+	} else {
+		for (int ty = 0; ty < TILE_HEIGHT; ty++) {
+			memcpy(&pixels[(y + ty) * surface->pitch + x], tile, TILE_WIDTH);
+			tile += TILE_WIDTH;
 		}
 	}
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index cf88314c0d..0f79c4a81a 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -66,7 +66,7 @@ enum Flags {
 	ENGINE_FLAG_100 = 0x100,
 	ENGINE_FLAG_200 = 0x200,
 	ENGINE_FLAG_400 = 0x400,
-
+	ENGINE_FLAG_800 = 0x800,
 	ENGINE_FLAG_1000_TEXT_ENABLED = 0x1000,
 	ENGINE_FLAG_8000     =     0x8000, // speech dialog is playing.
 
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index a434b13b18..7fa0daf717 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -150,6 +150,22 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	}
 
 	_stage = _backgroundLoader->load(sceneId);
+	if (!_vm->isFlagSet(ENGINE_FLAG_800)) {
+		byte *cursorPalette = _vm->_cursor->getPalette();
+		byte *stagePalette = _stage->getPalette();
+		for (int i = 0xc0; i < 0x100; i++) {
+			stagePalette[i * 2] = cursorPalette[(i-0xc0) * 2];
+			stagePalette[i * 2 + 1] = cursorPalette[(i-0xc0) * 2 + 1];
+		}
+	}
+	for(int i = 1; i < 0x100; i ++) {
+		byte *stagePalette = _stage->getPalette();
+		uint16 c = READ_LE_INT16(stagePalette + i * 2);
+		if ((c & 0x7fff) == 0) {
+			stagePalette[i * 2 + 1] |= 0x80;
+		}
+	}
+	_screen->loadPalette(0, _stage->getPalette());
 
 	_camera = _stage->getPoint2(cameraPointId);
 
@@ -319,11 +335,11 @@ void Scene::draw() {
 
 	for(uint16 priority = 1; priority < 16; priority++) {
 		if (priority == _stage->getBgLayerPriority()) {
-			_screen->copyRectToSurface(*_stage->getBgLayer(), 0, 0, rect);
+			_screen->copyRectToSurface8bpp(*_stage->getBgLayer(), _screen->getPalette(0), 0, 0, rect);
 		} else if (priority == _stage->getMgLayerPriority()) {
-			_screen->copyRectToSurface(*_stage->getMgLayer(), 0, 0, rect);
+			_screen->copyRectToSurface8bpp(*_stage->getMgLayer(), _screen->getPalette(0), 0, 0, rect);
 		} else if (priority == _stage->getFgLayerPriority()) {
-			_screen->copyRectToSurface(*_stage->getFgLayer(), 0, 0, rect);
+			_screen->copyRectToSurface8bpp(*_stage->getFgLayer(), _screen->getPalette(0), 0, 0, rect);
 		} else if (priority == 5) {
 			if (_vm->isFlagSet(ENGINE_FLAG_80)) {
 				_vm->_inventory->draw();
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 766e261f18..d6bdee9ad5 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -225,7 +225,7 @@ void Screen::loadPalette(uint16 paletteNum, byte *palette) {
 	paletteNum &= ~0x8000;
 	assert(paletteNum < DRAGONS_NUM_PALETTES);
 	if (paletteNum == 0) {
-		Dragons::getEngine()->_scene->setStagePalette(palette);
+		memcpy(&_palettes[paletteNum][0], palette, 512);
 	} else {
 		memcpy(&_palettes[paletteNum][0], palette, 512);
 		if (paletteNum == 2 || paletteNum == 4 || paletteNum == 5) {


Commit: 13a9ddaa793d57cc54e8fd18fe6bbfb4089c6bb0
    https://github.com/scummvm/scummvm/commit/13a9ddaa793d57cc54e8fd18fe6bbfb4089c6bb0
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on font palette

Changed paths:
    engines/dragons/font.cpp
    engines/dragons/font.h
    engines/dragons/scene.cpp


diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index a55b7dcc85..c0554da7d2 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -60,23 +60,19 @@ uint16 Font::mapChar(uint16 in) {
 	return _map[in - _map[0x03] + 0x05];
 }
 
-Graphics::Surface *Font::render(uint16 *text, uint16 length, byte *palette) {
+Graphics::Surface *Font::render(uint16 *text, uint16 length) {
 	Graphics::Surface *surface = new Graphics::Surface();
-	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
-	surface->create(length * 8, 8, pixelFormat16);
+	surface->create(length * 8, 8, Graphics::PixelFormat::createFormatCLUT8());
 
 
 	for (int i = 0; i < length; i++) {
 		byte *pixels = (byte *)surface->getPixels();
-		pixels += i * 8 * 2;
+		pixels += i * 8;
 //		debug("char: %d size: %d %d", (text[i] - 0x20), _numChars, (30 + i));
 		byte *data = _pixels + mapChar(text[i]) * 64;
 		for (int y = 0; y < 8; y++) {
-			for (int x = 0; x < 8; x++) {
-				pixels[x * 2] = palette[(data[0]) * 2];
-				pixels[x * 2 + 1] = palette[(data[0]) * 2 + 1];
-				data++;
-			}
+			memcpy(pixels, data, 8);
+			data += 8;
 			pixels += surface->pitch;
 		}
 	}
@@ -96,6 +92,8 @@ FontManager::FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigf
 	loadPalettes();
 
 	delete readStream;
+
+	DAT_80086f48_fontColor_flag = 0;
 }
 
 FontManager::~FontManager() {
@@ -111,7 +109,7 @@ void FontManager::addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 f
 	byte *palette = _vm->_cursor->getPalette();
 	ScreenTextEntry *screenTextEntry = new ScreenTextEntry();
 	screenTextEntry->position = Common::Point(x, y);
-	screenTextEntry->surface = _fonts[fontType]->render(text, length, _palettes); //palette);
+	screenTextEntry->surface = _fonts[fontType]->render(text, length);
 
 	_screenTexts.push_back(screenTextEntry);
 
@@ -121,9 +119,7 @@ void FontManager::draw() {
 	Common::List<ScreenTextEntry*>::iterator it = _screenTexts.begin();
 	while (it != _screenTexts.end()) {
 		ScreenTextEntry *entry = *it;
-//		_screen->copyRectToSurface(*entry->surface, entry->position.x, entry->position.y);
-		_screen->copyRectToSurface(*entry->surface, entry->position.x, entry->position.y, Common::Rect(entry->surface->w, entry->surface->h));
-
+		_screen->copyRectToSurface8bpp(*entry->surface, _screen->getPalette(2), entry->position.x, entry->position.y, Common::Rect(entry->surface->w, entry->surface->h), false, 128);
 		it++;
 	}
 }
@@ -196,4 +192,45 @@ void FontManager::loadPalettes() {
 	WRITE_LE_INT16(&_palettes[0x23 * 2], packColor(175, 175, 175));
 }
 
+void updatePalEntry(uint16 *pal, uint16 index, uint16 newValue) {
+	newValue = (uint16)(((uint16)newValue & 0x1f) << 10) | (uint16)(((uint16)newValue & 0x7c00) >> 10) |
+			(newValue & 0x3e0) | (newValue & 0x8000);
+	WRITE_LE_INT16(pal + index, newValue);
+}
+
+void FontManager::updatePalette() {
+//	if (( != 0 && ((engine_flags_maybe & 0x200) != 0))) {
+	uint16 *palette_f2_font_maybe = (uint16 *)_screen->getPalette(2);
+	uint16 cursor3 = 0x14a5 | 0x8000;
+	if(_vm->isFlagSet(ENGINE_FLAG_200)) {
+		if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
+			updatePalEntry(palette_f2_font_maybe, 16, cursor3);
+		} else {
+			updatePalEntry(palette_f2_font_maybe, 16, 0);
+		}
+		if (_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_4) && DAT_80086f48_fontColor_flag != 0) {
+			updatePalEntry(palette_f2_font_maybe, 17, 0x421);
+		} else {
+			updatePalEntry(palette_f2_font_maybe, 17, 0xfff);
+		}
+		updatePalEntry(palette_f2_font_maybe, 18, 0x421);
+		updatePalEntry(palette_f2_font_maybe, 19, 0x3def);
+		updatePalEntry(palette_f2_font_maybe, 32, cursor3);
+		updatePalEntry(palette_f2_font_maybe, 49, 0xfff);
+		updatePalEntry(palette_f2_font_maybe, 1, 0x8000);
+
+		updatePalEntry(palette_f2_font_maybe, 34, 0x421);
+		updatePalEntry(palette_f2_font_maybe, 35, 0x3def);
+		updatePalEntry(palette_f2_font_maybe, 48, cursor3);
+		updatePalEntry(palette_f2_font_maybe, 50, 0x421);
+		updatePalEntry(palette_f2_font_maybe, 51, 0x3def);
+		//TODO WRITE_LE_INT16(&palette_f2_font_maybe[33], READ_LE_INT16(&palette_f0[DAT_80084f58 >> 8]) & 0x7fff);
+		if (_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
+			updatePalEntry(palette_f2_font_maybe, 17, 0x3bee);
+			updatePalEntry(palette_f2_font_maybe, 33, 0x3bee);
+			updatePalEntry(palette_f2_font_maybe, 49, 0x3bee);
+		}
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index 21276e144b..916d216a23 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -42,7 +42,7 @@ private:
 public:
 	Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelOffset, uint32 pixelSize);
 	~Font();
-	Graphics::Surface *render(uint16 *text, uint16 length, byte *palette);
+	Graphics::Surface *render(uint16 *text, uint16 length);
 private:
 	uint16 mapChar(uint16 in);
 };
@@ -53,6 +53,7 @@ struct ScreenTextEntry {
 };
 
 class FontManager {
+	uint16 DAT_80086f48_fontColor_flag;
 private:
 	DragonsEngine *_vm;
 	Font *_fonts[3];
@@ -66,6 +67,7 @@ public:
 	void addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 fontType);
 	void draw();
 	void clearText();
+	void updatePalette();
 private:
 	Font *loadFont(uint16 index, Common::SeekableReadStream &stream);
 	void loadPalettes();
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 7fa0daf717..77d72a5c8d 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -334,6 +334,10 @@ void Scene::draw() {
 	_vm->_screen->clearScreen();
 
 	for(uint16 priority = 1; priority < 16; priority++) {
+		if (priority == 7 && _vm->isFlagSet(ENGINE_FLAG_200)) {
+			_vm->_fontManager->updatePalette();
+		}
+
 		if (priority == _stage->getBgLayerPriority()) {
 			_screen->copyRectToSurface8bpp(*_stage->getBgLayer(), _screen->getPalette(0), 0, 0, rect);
 		} else if (priority == _stage->getMgLayerPriority()) {


Commit: a3458f42570db65c7df78aab0aa6646a4bb06c77
    https://github.com/scummvm/scummvm/commit/a3458f42570db65c7df78aab0aa6646a4bb06c77
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on mini game 3

Changed paths:
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/font.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame3.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index b85d96463d..93bebaf376 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -88,6 +88,7 @@ Background::Background() : _priorityLayer(0), _points1(0), _points2(0), _data(0)
 	_layerSurface[0] = NULL;
 	_layerSurface[1] = NULL;
 	_layerSurface[2] = NULL;
+	_xOffset = 0;
 }
 
 Background::~Background() {
@@ -273,6 +274,14 @@ void Background::setPalette(byte *newPalette) {
 	}
 }
 
+void Background::setXOffset(int16 xOffset) {
+	_xOffset = xOffset;
+}
+
+int16 Background::getXOffset() {
+	return _xOffset;
+}
+
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
 	bigFileArchive), _dragonRMS(dragonRMS) {}
 
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index bc35bc45bc..bf36f59732 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -62,6 +62,7 @@ private:
 	Common::Point *_points1;
 	Common::Point *_points2;
 	uint8 layerPriority[3];
+	int16 _xOffset;
 
 public:
 	Background();
@@ -90,7 +91,8 @@ public:
 	void overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h);
 	void restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h);
 	void setPalette(byte *newPalette);
-
+	void setXOffset(int16 xOffset);
+	int16 getXOffset();
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
 	Graphics::Surface *initGfxLayer(TileMap &tileMap);
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index c0554da7d2..6ce2d6efbd 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -224,7 +224,8 @@ void FontManager::updatePalette() {
 		updatePalEntry(palette_f2_font_maybe, 48, cursor3);
 		updatePalEntry(palette_f2_font_maybe, 50, 0x421);
 		updatePalEntry(palette_f2_font_maybe, 51, 0x3def);
-		//TODO WRITE_LE_INT16(&palette_f2_font_maybe[33], READ_LE_INT16(&palette_f0[DAT_80084f58 >> 8]) & 0x7fff);
+		//TODO WRITE_LE_INT16(&palette_f2_font_maybe[33], READ_LE_INT16(&palette_f0[DAT_80084f58 >> 8]) & 0x7fff); //DAT_80084f58 is set in ActuallyShowMessage()
+		updatePalEntry(palette_f2_font_maybe, 33, 0x3def); //temporarily put in standard gray
 		if (_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
 			updatePalEntry(palette_f2_font_maybe, 17, 0x3bee);
 			updatePalEntry(palette_f2_font_maybe, 33, 0x3bee);
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 3ba48442d5..f80eaa1a62 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -283,9 +283,9 @@ void Minigame3::run() {
 		i = i + 1;
 	}
 	_vm->waitForFrames(1);
-	FUN_80017e64(2,0x280,0);
-	FUN_80017e64(1,0,0);
-	FUN_80017e64(0,0,0);
+	updateBackgroundLayerOffset(2, 0x280, 0);
+	updateBackgroundLayerOffset(1, 0, 0);
+	updateBackgroundLayerOffset(0, 0, 0);
 //	call_fade_related_1f();
 	_vm->waitForFrames(0xf);
 	_vm->_talk->loadAndDisplayDialogAroundPoint(0x479A,0x14,3,0x1e01,0);
@@ -510,7 +510,7 @@ void Minigame3::run() {
 						local_1c8 = 1;
 						flags = flags | 1;
 						local_1c6 = 3;
-						FUN_80017e64(2,0x640,0);
+						updateBackgroundLayerOffset(2, 0x640, 0);
 						if (((currentState != 3) && (currentState != 6)) && (local_e == 0)) {
 							local_10 = 0x5a;
 							local_e = 1;
@@ -522,7 +522,7 @@ void Minigame3::run() {
 						if (local_1c8 == 2) {
 							local_1c6 = 3;
 							local_1c8 = 1;
-							FUN_80017e64(2,0x640,0);
+							updateBackgroundLayerOffset(2, 0x640, 0);
 						}
 						else {
 							if (local_1c8 == 1) {
@@ -558,7 +558,7 @@ void Minigame3::run() {
 					flags = flags & 0xfffd | 4;
 					local_1c8 = 2;
 					local_1c6 = 3;
-					FUN_80017e64(2,0x780,0);
+					updateBackgroundLayerOffset(2, 0x780, 0);
 					tearBlinkActorTbl[0]->y_pos = 0xcc;
 					tearBlinkActorTbl[1]->y_pos = 0xcc;
 				}
@@ -572,7 +572,7 @@ void Minigame3::run() {
 				if (local_1c8 == 1) {
 					local_1c6 = 3;
 					local_1c8 = 2;
-					FUN_80017e64(2,0x780,0);
+					updateBackgroundLayerOffset(2, 0x780, 0);
 					tearBlinkActorTbl2[0]->updateSequence(0);
 					tearBlinkActorTbl2[1]->updateSequence(1);
 					tearBlinkActorTbl2[0]->priorityLayer = 4;
@@ -582,7 +582,7 @@ void Minigame3::run() {
 					if (local_1c8 == 2) {
 						local_1c6 = 0x14;
 						local_1c8 = 3;
-						FUN_80017e64(2,0x8c0,0);
+						updateBackgroundLayerOffset(2, 0x8c0, 0);
 						tearBlinkActorTbl2[0]->updateSequence(2);
 						tearBlinkActorTbl2[1]->updateSequence(3);
 						flags = flags & 0xfffe | 2;
@@ -650,9 +650,9 @@ void Minigame3::run() {
 					if (local_14 == 5) {
 						local_14 = 4;
 					}
-					FUN_80017e64(2,(int)local_14 * 0x1400000 >> 0x10,0);
-					FUN_80017e64(1,(int)-local_1c0,(int)asStack412[local_1c0]);
-					FUN_80017e64(0,(int)-local_1c0,(int)asStack412[local_1c0]);
+					updateBackgroundLayerOffset(2, (int) local_14 * 0x140, 0);
+					updateBackgroundLayerOffset(1, (int) -local_1c0, (int) asStack412[local_1c0]);
+					updateBackgroundLayerOffset(0, (int) -local_1c0, (int) asStack412[local_1c0]);
 				}
 			}
 			else {
@@ -665,7 +665,7 @@ void Minigame3::run() {
 	while ((int16)i < 3) {
 		local_16 = 0;
 		while ((int16)local_16 < 3) {
-			FUN_80017e64(2,((int)(int16)local_16 * 0x140 + 0x640) * 0x10000 >> 0x10,0);
+			updateBackgroundLayerOffset(2, ((int) (int16) local_16 * 0x140 + 0x640) * 0x10000 >> 0x10, 0);
 			_vm->waitForFrames(5);
 			local_16 = local_16 + 1;
 		}
@@ -685,7 +685,7 @@ void Minigame3::run() {
 		_vm->waitForFrames(0xf);
 		local_16 = 1;
 		while (-1 < (int16)local_16) {
-			FUN_80017e64(2,((int)(int16)local_16 * 0x140 + 0x640) * 0x10000 >> 0x10,0);
+			updateBackgroundLayerOffset(2, ((int) (int16) local_16 * 0x140 + 0x640) * 0x10000 >> 0x10, 0);
 			_vm->waitForFrames(5);
 			local_16 = local_16 + -1;
 		}
@@ -693,9 +693,9 @@ void Minigame3::run() {
 	}
 	tearBlinkActorTbl[0]->flags = tearBlinkActorTbl[0]->flags | 4;
 	tearBlinkActorTbl[1]->flags = tearBlinkActorTbl[1]->flags | 4;
-	FUN_80017e64(2,0x280,0);
-	FUN_80017e64(1,0,0);
-	FUN_80017e64(0,0,0);
+	updateBackgroundLayerOffset(2, 0x280, 0);
+	updateBackgroundLayerOffset(1, 0, 0);
+	updateBackgroundLayerOffset(0, 0, 0);
 	local_224 = _vm->getRand(2);
 	handActorId->updateSequence(0);
 	handActorId->x_pos = handPositionsTbl[local_224].x;
@@ -766,8 +766,8 @@ void Minigame3::run() {
 	_vm->_scene->loadScene(origSceneId, 0);
 }
 
-void Minigame3::FUN_80017e64(uint32 param_1, int16 param_2, int16 param_3) {
-	//TODO what does this do?
+void Minigame3::updateBackgroundLayerOffset(uint32 layerNumber, int16 xOffset, int16 yOffset) {
+	_vm->_scene->setLayerXOffset(layerNumber, xOffset);
 //	int iVar1;
 //
 //	iVar1 = (param_1 & 0xffff) * 0x24;
diff --git a/engines/dragons/minigame3.h b/engines/dragons/minigame3.h
index 3bf4e9efd2..e904426ec5 100644
--- a/engines/dragons/minigame3.h
+++ b/engines/dragons/minigame3.h
@@ -34,7 +34,7 @@ public:
 
 	void run();
 private:
-	void FUN_80017e64(uint32 param_1, int16 param_2, int16 param_3);
+	void updateBackgroundLayerOffset(uint32 layerNumber, int16 xOffset, int16 yOffset);
 	void FUN_80017f70_paletteRelated(uint16 unk);
 	void FUN_80017ef0();
 
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 77d72a5c8d..557f3c8283 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -330,7 +330,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 }
 
 void Scene::draw() {
-	Common::Rect rect(_camera.x, _camera.y, _camera.x + 320, _camera.y + 200);
+	Common::Rect rect(_camera.x + _stage->getXOffset(), _camera.y, _camera.x + 320 + _stage->getXOffset(), _camera.y + 200);
 	_vm->_screen->clearScreen();
 
 	for(uint16 priority = 1; priority < 16; priority++) {
@@ -481,4 +481,10 @@ void Scene::drawActorNumber(int16 x, int16 y, uint16 actorId) {
 	_vm->_fontManager->addText(x, y, text, strlen(text8), 1);
 }
 
+void Scene::setLayerXOffset(uint8 layerNumber, uint16 xOffset) {
+	if (layerNumber == 2) {
+		_stage->setXOffset(xOffset);
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index c9cffdddbe..3959d6bf39 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -81,6 +81,7 @@ public:
 	void setMgLayerPriority(uint8 newPriority);
 	void setFgLayerPriority(uint8 newPriority);
 
+	void setLayerXOffset(uint8 layerNumber, uint16 xOffset);
 private:
 	void resetActorFrameFlags();
 	void drawActorNumber(int16 x, int16 y, uint16 actorId);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index ecf35d04e5..c09b0a3b4f 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -200,8 +200,9 @@ void SpecialOpcodes::freeOpcodes() {
 // Opcodes
 
 void SpecialOpcodes::spcCatapultMiniGame() {
-	Minigame1 minigame1(_vm);
-	minigame1.run();
+	spcRabbitsMiniGame();
+//	Minigame1 minigame1(_vm);
+//	minigame1.run();
 }
 
 void SpecialOpcodes::spcClearEngineFlag10() {


Commit: d510e2541fb6f844fcbc5f963d40f33e9638738e
    https://github.com/scummvm/scummvm/commit/d510e2541fb6f844fcbc5f963d40f33e9638738e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Renamed magic variable

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 0891a848a1..1f6a1317fc 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -299,19 +299,19 @@ int16 Cursor::updateIniFromScene() {
 }
 
 int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
-	int16 temp = _vm->_scriptOpcodes->_data_800728c0;
+	int16 temp = _vm->_scriptOpcodes->_scriptTargetINI;
 	scriptOpCall._field8 = 1;
 	scriptOpCall._result = 0;
 	_vm->_scriptOpcodes->_data_80071f5c = 0;
 	_vm->_scriptOpcodes->executeScriptLoop(scriptOpCall);
 
 	if (!(scriptOpCall._result & 1) && data_800728b0_cursor_seqID == 5 && unkFlag != 0) {
-		_vm->_scriptOpcodes->_data_800728c0 = -1;
+		_vm->_scriptOpcodes->_scriptTargetINI = -1;
 		scriptOpCall._field8 = 1;
 		scriptOpCall._result = 0;
 		_vm->_scriptOpcodes->_data_80071f5c = 0;
 		_vm->_scriptOpcodes->executeScriptLoop(scriptOpCall);
-		_vm->_scriptOpcodes->_data_800728c0 = temp;
+		_vm->_scriptOpcodes->_scriptTargetINI = temp;
 		if (scriptOpCall._result & 1) {
 			scriptOpCall._result |= 2;
 		}
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 1d0e03f10a..91547b4fa0 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -377,7 +377,7 @@ void DragonsEngine::gameLoop()
 			bit_flags_8006fbd8 = 0;
 			DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 			if (flicker->sceneId == getCurrentSceneId() && flicker->actor->_sequenceID2 != -1) {
-				uVar6 = _scriptOpcodes->_data_800728c0;
+				uVar6 = _scriptOpcodes->_scriptTargetINI;
 				if (_cursor->_sequenceID != 5) {
 					uVar6 = _cursor->data_80072890;
 				}
@@ -482,7 +482,7 @@ void DragonsEngine::gameLoop()
 							if (bit_flags_8006fbd8 != 0) {
 								clearFlags(ENGINE_FLAG_8);
 							}
-							_scriptOpcodes->_data_800728c0 = _cursor->data_80072890;
+							_scriptOpcodes->_scriptTargetINI = _cursor->data_80072890;
 							_cursor->data_80072890 = _cursor->iniItemInHand;
 						}
 					}
@@ -547,7 +547,7 @@ void DragonsEngine::gameLoop()
 					_cursor->data_80072890 = _cursor->_iniUnderCursor;
 					if (4 < _cursor->_sequenceID) {
 						_cursor->data_80072890 = _cursor->iniItemInHand;
-						_scriptOpcodes->_data_800728c0 = _cursor->_iniUnderCursor;
+						_scriptOpcodes->_scriptTargetINI = _cursor->_iniUnderCursor;
 					}
 					clearFlags(ENGINE_FLAG_8);
 					walkFlickerToObject();
@@ -1040,7 +1040,7 @@ void DragonsEngine::performAction() {
 	byte * pvVar7;
 	byte * pvVar8;
 
-	uVar2 = _scriptOpcodes->_data_800728c0;
+	uVar2 = _scriptOpcodes->_scriptTargetINI;
 	uVar1 = _flags;
 	local_58._code = NULL;
 	local_58._codeEnd = NULL;
@@ -1060,14 +1060,14 @@ void DragonsEngine::performAction() {
 	if (_cursor->data_800728b0_cursor_seqID > 4) {
 		_scriptOpcodes->_data_80071f5c = 0;
 
-		obd = _dragonOBD->getFromOpt(_scriptOpcodes->_data_800728c0 - 1);
-		_scriptOpcodes->_data_800728c0 = _cursor->data_80072890;
+		obd = _dragonOBD->getFromOpt(_scriptOpcodes->_scriptTargetINI - 1);
+		_scriptOpcodes->_scriptTargetINI = _cursor->data_80072890;
 
 		local_38._code = obd + 8;
 		local_38._codeEnd = local_38._code + READ_LE_UINT32(obd);
 
 		uVar6 = _cursor->executeScript(local_38, 1);
-		_scriptOpcodes->_data_800728c0 = uVar2;
+		_scriptOpcodes->_scriptTargetINI = uVar2;
 	}
 	if ((uVar6 & 0xffff) != 0) {
 		local_58._code = local_38._code + 8;
@@ -1240,7 +1240,7 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 
 	clearFlags(ENGINE_FLAG_1000_TEXT_ENABLED); //TODO wire this up to subtitle config.
 
-	_scriptOpcodes->_data_800728c0 = 0; //TODO this should be reset in scriptopcode.
+	_scriptOpcodes->_scriptTargetINI = 0; //TODO this should be reset in scriptopcode.
 	_cursor->init(_actorManager, _dragonINIResource);
 	_inventory->init(_actorManager, _backgroundResourceLoader, new Bag(_bigfileArchive, _screen), _dragonINIResource);
 	_talk->init();
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 521ce0c911..e5fa3fbd7d 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -65,7 +65,7 @@ ScriptOpcodes::ScriptOpcodes(DragonsEngine *vm, DragonFLG *dragonFLG)
 	: _vm(vm), _dragonFLG(dragonFLG), _data_80071f5c(0) {
 	_specialOpCodes = new SpecialOpcodes(_vm);
 	initOpcodes();
-	_data_800728c0 = 0;
+	_scriptTargetINI = 0;
 }
 
 ScriptOpcodes::~ScriptOpcodes() {
@@ -219,7 +219,7 @@ void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field6);
 
 	if ((field2 >> _vm->_cursor->data_800728b0_cursor_seqID) & 1
-	&& (_vm->_cursor->data_800728b0_cursor_seqID < 5 || field4 == _data_800728c0)
+	&& (_vm->_cursor->data_800728b0_cursor_seqID < 5 || field4 == _scriptTargetINI)
 	&& scriptOpCall._field8 == 1) {
 		scriptOpCall._code -= 8;
 		scriptOpCall._result |= 1;
@@ -300,7 +300,7 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 		return;
 	}
 
-	int16 uVar6 = _data_800728c0;
+	int16 uVar6 = _scriptTargetINI;
 	int16 uVar5 = _vm->_cursor->data_800728b0_cursor_seqID;
 	int16 uVar4 = _vm->_cursor->data_80072890;
 	int16 uVar3 = _vm->_cursor->_iniUnderCursor;
@@ -315,7 +315,7 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 		_vm->_cursor->_sequenceID++;
 	}
 
-	_data_800728c0 = field6;
+	_scriptTargetINI = field6;
 	_vm->_cursor->data_800728b0_cursor_seqID = _vm->_cursor->_sequenceID;
 	_vm->_cursor->data_80072890 = _vm->_cursor->_iniUnderCursor;
 //	EnableVSyncEvent();
@@ -327,7 +327,7 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	_vm->_cursor->_iniUnderCursor = uVar3;
 	_vm->_cursor->data_80072890 = uVar4;
 	_vm->_cursor->data_800728b0_cursor_seqID = uVar5;
-	_data_800728c0 = uVar6;
+	_scriptTargetINI = uVar6;
 }
 
 void ScriptOpcodes::opUnk7(ScriptOpCall &scriptOpCall) {
@@ -472,7 +472,7 @@ bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {
 
 			if (*codePtrOffsetA & 4) {
 				t2 = getINIField(READ_LE_INT16(codePtrOffsetA - 6) - 1, READ_LE_INT16(codePtrOffset2));
-				debug(3, "Op13 get here!! & 4 %d, %d", READ_LE_INT16(codePtrOffsetA - 6), t2);
+				debug(3, "Op13 get here!! & 4 read ini field ini: %X fieldOffset: %X value: %d", READ_LE_INT16(codePtrOffsetA - 6) - 1, READ_LE_INT16(codePtrOffset2), t2);
 
 			}
 
@@ -492,8 +492,8 @@ bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {
 			}
 
 			if (!(*codePtrOffsetA & 0x18)) {
-				debug(3, "Op13 get here!! & 0x18");
 				t0 = READ_LE_UINT16(codePtrOffsetA - 2);
+				debug(3, "Op13 get here!! & 0x18 t0 == %d", t0);
 			}
 
 			if (*(codePtrOffsetA + 1) == 0 && t0 == t2) {
@@ -696,7 +696,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 
 	//TODO these should be passed in as arguments and xparam should be set correctly.
 	int16 someXParam = 0;
-	int16 someYParam = _data_800728c0;
+	int16 someYParam = _scriptTargetINI;
 	uint someBooleanFlag = 0;
 	if (scriptOpCall._field8 != 0) {
 		return;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 7195863baa..ae75d91e0f 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -68,7 +68,7 @@ public:
 	void loadTalkDialogEntries(ScriptOpCall &scriptOpCall);
 
 	int16 _data_80071f5c;
-	int16 _data_800728c0;
+	int16 _scriptTargetINI;
 	SpecialOpcodes *_specialOpCodes;
 protected:
 	DragonsEngine *_vm;


Commit: 2e714a421e3258687ce9e7b7042da66190eb328c
    https://github.com/scummvm/scummvm/commit/2e714a421e3258687ce9e7b7042da66190eb328c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on minigame 3

Changed paths:
    engines/dragons/minigame3.cpp
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp


diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index f80eaa1a62..77ea85bb89 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -729,8 +729,7 @@ void Minigame3::run() {
 		}
 	}
 	handActorId->updateSequence(1);
-	do {
-	} while ((handActorId->flags & 4) == 0);
+	handActorId->waitUntilFlag4IsSet();
 	_vm->_dragonINIResource->getRecord(0x178)->field_12 = local_224 + 1;
 	if (goodRabbitPositionTbl[local_224] == 1) {
 		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(2);
@@ -743,7 +742,7 @@ void Minigame3::run() {
 			i = i + 1;
 		}
 		_vm->waitForFrames(0x1e);
-		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(2);
+		bunnyActorTbl[bunnyPositionTbl[i]]->updateSequence(2);
 		_vm->_dragonINIResource->getRecord(0x178)->field_14 = 0;
 	}
 	_vm->waitForFrames(0x3c * 2);
@@ -777,7 +776,7 @@ void Minigame3::updateBackgroundLayerOffset(uint32 layerNumber, int16 xOffset, i
 }
 
 void Minigame3::FUN_80017f70_paletteRelated(uint16 param_1) {
-	if (0x1f < param_1) {
+	if (param_1 > 0x1f) {
 		param_1 = 0x1f;
 	}
 //	uVar1 = IsVSyncEventEnabled & 1;
@@ -785,7 +784,7 @@ void Minigame3::FUN_80017f70_paletteRelated(uint16 param_1) {
 	_vm->_screen->loadPalette(0, _vm->_scene->getPalette());
 	_vm->_screen->setPaletteRecord(0, 0x3f, param_1 * 0x421);
 //	load_palette_into_frame_buffer(0,abStack528);
-	_vm->_screen->updatePaletteTransparency(0, 0x3f,0x3f, true);
+	_vm->_screen->updatePaletteTransparency(0, 0x3f,0x3f, param_1 == 0x1e ? false : true);
 //	if (uVar1 != 0) {
 //		EnableVSyncEvent();
 //	}
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 557f3c8283..03b8910994 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -167,6 +167,15 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	}
 	_screen->loadPalette(0, _stage->getPalette());
 
+	for(int i = 1; i < 0x100; i ++) {
+		byte *stagePalette = _stage->getPalette();
+		uint16 c = READ_LE_INT16(stagePalette + i * 2);
+		if ((c & 0x7fff) == 0) {
+			stagePalette[i * 2] = 1;
+			stagePalette[i * 2 + 1] = 0;
+		}
+	}
+
 	_camera = _stage->getPoint2(cameraPointId);
 
 	if (flicker && !(sceneId & 0x8000)) {
@@ -339,11 +348,11 @@ void Scene::draw() {
 		}
 
 		if (priority == _stage->getBgLayerPriority()) {
-			_screen->copyRectToSurface8bpp(*_stage->getBgLayer(), _screen->getPalette(0), 0, 0, rect);
+			_screen->copyRectToSurface8bpp(*_stage->getBgLayer(), _screen->getPalette(0), 0, 0, rect, false, 128);
 		} else if (priority == _stage->getMgLayerPriority()) {
-			_screen->copyRectToSurface8bpp(*_stage->getMgLayer(), _screen->getPalette(0), 0, 0, rect);
+			_screen->copyRectToSurface8bpp(*_stage->getMgLayer(), _screen->getPalette(0), 0, 0, rect, false, 128);
 		} else if (priority == _stage->getFgLayerPriority()) {
-			_screen->copyRectToSurface8bpp(*_stage->getFgLayer(), _screen->getPalette(0), 0, 0, rect);
+			_screen->copyRectToSurface8bpp(*_stage->getFgLayer(), _screen->getPalette(0), 0, 0, rect, false, 128);
 		} else if (priority == 5) {
 			if (_vm->isFlagSet(ENGINE_FLAG_80)) {
 				_vm->_inventory->draw();
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index d6bdee9ad5..4e9df61f95 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -257,9 +257,6 @@ void Screen::setPaletteRecord(uint16 paletteNum, uint16 offset, uint16 newValue)
 	assert(paletteNum < DRAGONS_NUM_PALETTES);
 	assert(offset < 256);
 	WRITE_LE_UINT16(&_palettes[paletteNum][offset * 2], newValue);
-	if (paletteNum == 0) {
-		Dragons::getEngine()->_scene->setStagePalette(&_palettes[0][0]);
-	}
 }
 
 byte *Screen::getPalette(uint16 paletteNum) {


Commit: 3299c2136d4868a86281368eba79858d7080be24
    https://github.com/scummvm/scummvm/commit/3299c2136d4868a86281368eba79858d7080be24
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed bug with performAction script

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 1f6a1317fc..db9f5ad716 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -300,6 +300,7 @@ int16 Cursor::updateIniFromScene() {
 
 int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 	int16 temp = _vm->_scriptOpcodes->_scriptTargetINI;
+	byte *codeStart = scriptOpCall._code;
 	scriptOpCall._field8 = 1;
 	scriptOpCall._result = 0;
 	_vm->_scriptOpcodes->_data_80071f5c = 0;
@@ -307,6 +308,7 @@ int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 
 	if (!(scriptOpCall._result & 1) && data_800728b0_cursor_seqID == 5 && unkFlag != 0) {
 		_vm->_scriptOpcodes->_scriptTargetINI = -1;
+		scriptOpCall._code = codeStart;
 		scriptOpCall._field8 = 1;
 		scriptOpCall._result = 0;
 		_vm->_scriptOpcodes->_data_80071f5c = 0;
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index e5fa3fbd7d..da45aa0eaa 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -76,7 +76,7 @@ ScriptOpcodes::~ScriptOpcodes() {
 void ScriptOpcodes::execOpcode(ScriptOpCall &scriptOpCall) {
 	if (!_opcodes[scriptOpCall._op])
 		error("ScriptOpcodes::execOpcode() Unimplemented opcode %d (0x%X)", scriptOpCall._op, scriptOpCall._op);
-	debug("execScriptOpcode(%d) %s", scriptOpCall._op, _opcodeNames[scriptOpCall._op].c_str());
+	debug("execScriptOpcode(0x%X) %s", scriptOpCall._op, _opcodeNames[scriptOpCall._op].c_str());
 	(*_opcodes[scriptOpCall._op])(scriptOpCall);
 }
 


Commit: fcd92dc4c37fae57581e31f5c0f24a0ce792d65f
    https://github.com/scummvm/scummvm/commit/fcd92dc4c37fae57581e31f5c0f24a0ce792d65f
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: handle negative offsets in background shift for minigame 3

Changed paths:
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/minigame3.cpp
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/screen.cpp
    engines/dragons/screen.h
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 93bebaf376..3170333a81 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -88,7 +88,9 @@ Background::Background() : _priorityLayer(0), _points1(0), _points2(0), _data(0)
 	_layerSurface[0] = NULL;
 	_layerSurface[1] = NULL;
 	_layerSurface[2] = NULL;
-	_xOffset = 0;
+	layerOffset[0] = Common::Point(0,0);
+	layerOffset[1] = Common::Point(0,0);
+	layerOffset[2] = Common::Point(0,0);
 }
 
 Background::~Background() {
@@ -274,12 +276,14 @@ void Background::setPalette(byte *newPalette) {
 	}
 }
 
-void Background::setXOffset(int16 xOffset) {
-	_xOffset = xOffset;
+void Background::setLayerOffset(uint8 layerNumber, Common::Point offset) {
+	assert(layerNumber < 4);
+	layerOffset[layerNumber] = offset;
 }
 
-int16 Background::getXOffset() {
-	return _xOffset;
+Common::Point Background::getLayerOffset(uint8 layerNumber) {
+	assert(layerNumber < 4);
+	return layerOffset[layerNumber];
 }
 
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index bf36f59732..3c6f1a76c6 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -62,8 +62,7 @@ private:
 	Common::Point *_points1;
 	Common::Point *_points2;
 	uint8 layerPriority[3];
-	int16 _xOffset;
-
+	Common::Point layerOffset[3];
 public:
 	Background();
 	~Background();
@@ -91,8 +90,8 @@ public:
 	void overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h);
 	void restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h);
 	void setPalette(byte *newPalette);
-	void setXOffset(int16 xOffset);
-	int16 getXOffset();
+	void setLayerOffset(uint8 layerNumber, Common::Point offset);
+	Common::Point getLayerOffset(uint8 layerNumber);
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
 	Graphics::Surface *initGfxLayer(TileMap &tileMap);
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 77ea85bb89..18ef0c2f96 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -766,13 +766,7 @@ void Minigame3::run() {
 }
 
 void Minigame3::updateBackgroundLayerOffset(uint32 layerNumber, int16 xOffset, int16 yOffset) {
-	_vm->_scene->setLayerXOffset(layerNumber, xOffset);
-//	int iVar1;
-//
-//	iVar1 = (param_1 & 0xffff) * 0x24;
-//	*(undefined2 *)(&DAT_80069644 + iVar1) = param_2;
-//	*(short *)(&DAT_80069646 + iVar1) = param_3 + 8;
-
+	_vm->_scene->setLayerOffset(layerNumber, Common::Point(xOffset, yOffset));
 }
 
 void Minigame3::FUN_80017f70_paletteRelated(uint16 param_1) {
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 03b8910994..f3c87284d8 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -339,7 +339,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 }
 
 void Scene::draw() {
-	Common::Rect rect(_camera.x + _stage->getXOffset(), _camera.y, _camera.x + 320 + _stage->getXOffset(), _camera.y + 200);
+	Common::Rect rect(_camera.x, _camera.y, _camera.x + 320, _camera.y + 200);
 	_vm->_screen->clearScreen();
 
 	for(uint16 priority = 1; priority < 16; priority++) {
@@ -348,11 +348,11 @@ void Scene::draw() {
 		}
 
 		if (priority == _stage->getBgLayerPriority()) {
-			_screen->copyRectToSurface8bpp(*_stage->getBgLayer(), _screen->getPalette(0), 0, 0, rect, false, 128);
+			drawBgLayer(0, rect, _stage->getBgLayer());
 		} else if (priority == _stage->getMgLayerPriority()) {
-			_screen->copyRectToSurface8bpp(*_stage->getMgLayer(), _screen->getPalette(0), 0, 0, rect, false, 128);
+			drawBgLayer(1, rect, _stage->getMgLayer());
 		} else if (priority == _stage->getFgLayerPriority()) {
-			_screen->copyRectToSurface8bpp(*_stage->getFgLayer(), _screen->getPalette(0), 0, 0, rect, false, 128);
+			drawBgLayer(2, rect, _stage->getFgLayer());
 		} else if (priority == 5) {
 			if (_vm->isFlagSet(ENGINE_FLAG_80)) {
 				_vm->_inventory->draw();
@@ -490,10 +490,22 @@ void Scene::drawActorNumber(int16 x, int16 y, uint16 actorId) {
 	_vm->_fontManager->addText(x, y, text, strlen(text8), 1);
 }
 
-void Scene::setLayerXOffset(uint8 layerNumber, uint16 xOffset) {
-	if (layerNumber == 2) {
-		_stage->setXOffset(xOffset);
-	}
+void Scene::setLayerOffset(uint8 layerNumber, Common::Point offset) {
+	_stage->setLayerOffset(layerNumber, offset);
+}
+
+Common::Point Scene::getLayerOffset(uint8 layerNumber) {
+	return _stage->getLayerOffset(layerNumber);
+}
+
+void Scene::drawBgLayer(uint8 layerNumber, Common::Rect rect, Graphics::Surface *surface) {
+	Common::Point offset = _stage->getLayerOffset(layerNumber);
+	Common::Rect clippedRect = _screen->clipRectToRect(offset.x, offset.y, rect, Common::Rect(_stage->getBgLayer()->w, _stage->getBgLayer()->h));
+	clippedRect.left += offset.x < 0 ? -offset.x : 0;
+	clippedRect.right += offset.x < 0 ? -offset.x : 0;
+	clippedRect.top += offset.y < 0 ? -offset.y : 0;
+	clippedRect.bottom += offset.y < 0 ? -offset.y : 0;
+	_screen->copyRectToSurface8bpp(*surface, _screen->getPalette(0), 0, 0, clippedRect, false, 128);
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 3959d6bf39..c615b80a01 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -81,10 +81,12 @@ public:
 	void setMgLayerPriority(uint8 newPriority);
 	void setFgLayerPriority(uint8 newPriority);
 
-	void setLayerXOffset(uint8 layerNumber, uint16 xOffset);
+	void setLayerOffset(uint8 layerNumber, Common::Point offset);
+	Common::Point getLayerOffset(uint8 layerNumber);
 private:
 	void resetActorFrameFlags();
 	void drawActorNumber(int16 x, int16 y, uint16 actorId);
+	void drawBgLayer(uint8 layerNumber, Common::Rect rect, Graphics::Surface *surface);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 4e9df61f95..7df1518578 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -157,17 +157,21 @@ void Screen::copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPit
 }
 
 Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect rect) {
+	return clipRectToRect(destX, destY, rect, Common::Rect(320, 200));
+}
+
+Common::Rect Screen::clipRectToRect(int destX, int destY, const Common::Rect rect, const Common::Rect containerRect) {
 	int16 x, y, w, h;
 	x = rect.left;
 	y = rect.top;
 	w = rect.width();
 	h = rect.height();
 
-	if (destX >= 320) {
+	if (destX >= containerRect.width()) {
 		w = 0;
 	}
 
-	if (destY >= 200) {
+	if (destY >= containerRect.height()) {
 		h = 0;
 	}
 
@@ -181,12 +185,12 @@ Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect r
 		y += -destY;
 	}
 
-	if (w > 0 && destX + w >= 320) {
-		w -= (destX + w) - 320;
+	if (w > 0 && destX + w >= containerRect.width()) {
+		w -= (destX + w) - containerRect.width();
 	}
 
-	if (h > 0 && destY + h >= 200) {
-		h -= (destY + h) - 200;
+	if (h > 0 && destY + h >= containerRect.height()) {
+		h -= (destY + h) - containerRect.height();
 	}
 
 	if (w < 0) {
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 2adf2e314a..eb20da2e42 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -48,10 +48,12 @@ public:
 	void updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, uint16 endOffset, bool isTransparent);
 	void clearScreen();
 	void drawRect(uint16 colour, Common::Rect rect, int id);
+	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
+	Common::Rect clipRectToRect(int destX, int destY, const Common::Rect rect, const Common::Rect containerRect);
+
 private:
 	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
 	void copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
-	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index da45aa0eaa..0f85318b60 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -164,30 +164,30 @@ bool ScriptOpcodes::runScript4(ScriptOpCall &scriptOpCall) {
 }
 
 void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
-
-	if (scriptOpCall._code >= scriptOpCall._codeEnd || scriptOpCall._result & 1) {
-		return;
-	}
-
-	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
-		return;
-	}
-
-	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
-		//TODO
-//		if (IsPressedStart(0)) {
-//			Dragons::getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
-//		}
-	}
-
-	uint16 opcode = READ_LE_UINT16(scriptOpCall._code) & 0x7fff;
-
-	scriptOpCall._op = (byte) opcode;
-	if (opcode < DRAGONS_NUM_SCRIPT_OPCODES) {
-		execOpcode(scriptOpCall);
-	}
-
-	while (scriptOpCall._code < scriptOpCall._codeEnd && !(scriptOpCall._result & 1) && _data_80071f5c == 0) {
+//
+//	if (scriptOpCall._code >= scriptOpCall._codeEnd || scriptOpCall._result & 1) {
+//		return;
+//	}
+//
+//	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
+//		return;
+//	}
+//
+//	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
+//		//TODO
+////		if (IsPressedStart(0)) {
+////			Dragons::getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
+////		}
+//	}
+//
+//	uint16 opcode = READ_LE_UINT16(scriptOpCall._code) & 0x7fff;
+//
+//	scriptOpCall._op = (byte) opcode;
+//	if (opcode < DRAGONS_NUM_SCRIPT_OPCODES) {
+//		execOpcode(scriptOpCall);
+//	}
+//
+	while (scriptOpCall._code < scriptOpCall._codeEnd && !(scriptOpCall._result & 1)) {
 
 		if (_vm->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
 			return;
@@ -200,13 +200,18 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 //		}
 		}
 
-		opcode = READ_LE_UINT16(scriptOpCall._code) & 0x7fff;
+		uint16 opcode = READ_LE_UINT16(scriptOpCall._code) & 0x7fff;
 
 		if (opcode >= DRAGONS_NUM_SCRIPT_OPCODES) {
 			return; //TODO should continue here.
 		}
 		scriptOpCall._op = (byte) opcode;
 		execOpcode(scriptOpCall);
+
+		if (_data_80071f5c != 0) {
+			scriptOpCall._result |= 1;
+			break;
+		}
 	}
 }
 


Commit: c836646b69a685ff59818a130bd98555d481d010
    https://github.com/scummvm/scummvm/commit/c836646b69a685ff59818a130bd98555d481d010
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: added ScriptOpCode constructor. Work on eyes bg layer in mini
game 3

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/talk.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index db9f5ad716..09d86292b7 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -247,9 +247,7 @@ int16 Cursor::updateIniFromScene() {
 					for(int idx=0; idx < 5; idx++) {
 						data_800728b0_cursor_seqID = idx;
 						byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
-						ScriptOpCall scriptOpCall;
-						scriptOpCall._code = obd + 8;
-						scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+						ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
 //						uVar17 = uVar15;
 //						local_58 = dragon_Obd_Offset + *(int *)(uVar16 * 8 + dragon_Opt_Offset + -8) + 8;
@@ -276,9 +274,7 @@ int16 Cursor::updateIniFromScene() {
 					return _iniUnderCursor;
 				}
 				byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
-				ScriptOpCall scriptOpCall;
-				scriptOpCall._code = obd + 8;
-				scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+				ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
 //				local_48 = dragon_Obd_Offset + *(int *)(uVar16 * 8 + dragon_Opt_Offset + -8) + 8;
 //				local_44 = read_int32();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 91547b4fa0..a24573eb3c 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -263,7 +263,6 @@ void DragonsEngine::gameLoop()
 	uint16_t sequenceId;
 	DragonINI *pDVar8;
 	ushort *puVar9;
-	ScriptOpCall local_30;
 
 	_cursor->_cursorActivationSeqOffset = 0;
 	bit_flags_8006fbd8 = 0;
@@ -314,9 +313,7 @@ void DragonsEngine::gameLoop()
 			if (actorId_00 == 0) goto LAB_80026d34;
 			if (actorId_00 != (actorId & 0xffff)) {
 				byte *obd = _dragonOBD->getFromOpt(actorId_00 - 1);
-				ScriptOpCall scriptOpCall;
-				scriptOpCall._code = obd + 8;
-				scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+				ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
 				if(_scriptOpcodes->runScript4(scriptOpCall)) {
 					scriptOpCall._codeEnd = scriptOpCall._code + 4 + READ_LE_UINT16(scriptOpCall._code + 2);
@@ -832,9 +829,7 @@ void DragonsEngine::runINIScripts() {
 		if (ini->field_1a_flags_maybe & Dragons::INI_FLAG_10) {
 			ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
 			byte *data = _dragonOBD->getFromOpt(i);
-			ScriptOpCall scriptOpCall;
-			scriptOpCall._code = data + 8;
-			scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(data);
+			ScriptOpCall scriptOpCall(data + 8, READ_LE_UINT32(data));
 			uint32 currentFlags = _flags;
 			clearFlags(Dragons::ENGINE_FLAG_8);
 			_scriptOpcodes->runScript3(scriptOpCall);
@@ -1034,17 +1029,16 @@ void DragonsEngine::performAction() {
 	uint uVar4;
 	uint uVar5;
 	uint uVar6;
-	ScriptOpCall local_48;
-	ScriptOpCall local_38;
-	ScriptOpCall local_58;
 	byte * pvVar7;
 	byte * pvVar8;
+	byte *local_58_code;
+	byte *local_58_codeEnd;
+	bool load_58_result = false;
 
 	uVar2 = _scriptOpcodes->_scriptTargetINI;
 	uVar1 = _flags;
-	local_58._code = NULL;
-	local_58._codeEnd = NULL;
-	local_58._result = 0;
+	local_58_code = NULL;
+	local_58_codeEnd = NULL;
 
 	uVar6 = 0;
 	_scriptOpcodes->_data_80071f5c = 0;
@@ -1053,8 +1047,9 @@ void DragonsEngine::performAction() {
 	byte *obd = _dragonOBD->getFromOpt(_cursor->data_80072890 - 1);
 
 
-	local_48._code = pvVar7 = obd + 8;
-	local_48._codeEnd = pvVar8 = local_48._code + READ_LE_UINT32(obd);
+	ScriptOpCall local_48(obd + 8, READ_LE_UINT32(obd));
+	pvVar7 = local_48._code;
+	pvVar8 = local_48._codeEnd;
 
 	uVar4 = _cursor->executeScript(local_48, 1);
 	if (_cursor->data_800728b0_cursor_seqID > 4) {
@@ -1063,29 +1058,30 @@ void DragonsEngine::performAction() {
 		obd = _dragonOBD->getFromOpt(_scriptOpcodes->_scriptTargetINI - 1);
 		_scriptOpcodes->_scriptTargetINI = _cursor->data_80072890;
 
-		local_38._code = obd + 8;
-		local_38._codeEnd = local_38._code + READ_LE_UINT32(obd);
+		ScriptOpCall local_38(obd + 8, READ_LE_UINT32(obd));
 
 		uVar6 = _cursor->executeScript(local_38, 1);
 		_scriptOpcodes->_scriptTargetINI = uVar2;
-	}
-	if ((uVar6 & 0xffff) != 0) {
-		local_58._code = local_38._code + 8;
-		local_58._codeEnd = local_58._code + READ_LE_UINT16(local_38._code + 6);
+
+		if ((uVar6 & 0xffff) != 0) {
+			local_58_code = local_38._code + 8;
+			local_58_codeEnd = local_58_code + READ_LE_UINT16(local_38._code + 6);
+		}
 	}
 	if (((uVar4 & 0xffff) != 0) && ((((uVar4 & 2) == 0 || ((uVar6 & 2) != 0)) || ((uVar6 & 0xffff) == 0)))) {
-		local_58._code = local_48._code + 8;
-		local_58._codeEnd = local_58._code + READ_LE_UINT16(local_48._code + 6);
+		local_58_code = local_48._code + 8;
+		local_58_codeEnd = local_58_code + READ_LE_UINT16(local_48._code + 6);
 	}
 	uVar4 = uVar4 & 0xfffd;
-	if (local_58._code != NULL && local_58._codeEnd != NULL) {
+	if (local_58_code != NULL && local_58_codeEnd != NULL) {
 		clearFlags(ENGINE_FLAG_8);
+		ScriptOpCall local_58(local_58_code, local_58_codeEnd - local_58_code);
 		_scriptOpcodes->runScript(local_58);
+		load_58_result = local_58._result;
 	}
-	if ((local_58._result & 1U) == 0) {
+	if (!load_58_result) {
 		if (_cursor->data_800728b0_cursor_seqID == 3) {
-			local_58._code = pvVar7;
-			local_58._codeEnd = pvVar8;
+			ScriptOpCall local_58(pvVar7, pvVar8 - pvVar7);
 			uVar5 = _talk->talkToActor(local_58);
 			uVar4 = uVar4 | uVar5;
 		}
@@ -1260,9 +1256,7 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 	//if (sceneId > 2) { //TODO remove this restriction to enable intro sequence.
 		_scene->setSceneId(2);
 		byte *obd = _dragonOBD->getFromSpt(3);
-		ScriptOpCall scriptOpCall;
-		scriptOpCall._code = obd + 4;
-		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		ScriptOpCall scriptOpCall(obd + 4, READ_LE_UINT32(obd));
 		_scriptOpcodes->runScript(scriptOpCall);
 	//} else {
 //		sceneId = 0x12; // HACK the first scene. TODO remove this
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 18ef0c2f96..136061119b 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -93,8 +93,7 @@ void Minigame3::run() {
 	int16 local_1bc;
 	int16 local_1ba;
 	uint16 local_1b8;
-//	undefined auStack432 [20];
-	int16 asStack412 [14];
+	int16 eyeBgYOffsetTbl[21];
 	TearInfo tearInfo [30];
 	Common::Point bunnyPositionsTbl [4];
 	Common::Point handPositionsTbl [4];
@@ -127,7 +126,9 @@ void Minigame3::run() {
 		error("Failed to open arc1.bin");
 	}
 
-	//TODO do we need this?	memcpy(auStack432,&DAT_8008e88c,0x2a);
+	for (i = 0;i < 21; i++) {
+		eyeBgYOffsetTbl[i] = fd->readUint16LE();
+	}
 
 	fd->seek(0x2c);
 	for (i = 0; i < 30; i++) {
@@ -651,8 +652,8 @@ void Minigame3::run() {
 						local_14 = 4;
 					}
 					updateBackgroundLayerOffset(2, (int) local_14 * 0x140, 0);
-					updateBackgroundLayerOffset(1, (int) -local_1c0, (int) asStack412[local_1c0]);
-					updateBackgroundLayerOffset(0, (int) -local_1c0, (int) asStack412[local_1c0]);
+					updateBackgroundLayerOffset(1, (int) -local_1c0, (int) eyeBgYOffsetTbl[local_1c0 + 10]);
+					updateBackgroundLayerOffset(0, (int) -local_1c0, (int) eyeBgYOffsetTbl[local_1c0 + 10]);
 				}
 			}
 			else {
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index f3c87284d8..da578a0a59 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -74,9 +74,7 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 
 	if (!(sceneId & 0x8000)) {
 		byte *obd = _dragonRMS->getObdDataFieldC(sceneId);
-		ScriptOpCall scriptOpCall;
-		scriptOpCall._code = obd + 4;
-		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		ScriptOpCall scriptOpCall(obd + 4, READ_LE_UINT32(obd));
 		_scriptOpcodes->runScript(scriptOpCall);
 	}
 	DragonINI *ini = _dragonINIResource->getRecord(0xc4);
@@ -106,9 +104,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	if (!(sceneId & 0x8000)) {
 		byte *obd = _dragonRMS->getObdDataField10(sceneId);
-		ScriptOpCall scriptOpCall;
-		scriptOpCall._code = obd + 4;
-		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		ScriptOpCall scriptOpCall(obd + 4, READ_LE_UINT32(obd));
 		uint16 oldSceneId = _currentSceneId;
 		_currentSceneId = -1;
 		_scriptOpcodes->runScript(scriptOpCall);
@@ -330,9 +326,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	if (!(sceneId & 0x8000)) {
 		byte *obd = _dragonRMS->getObdData(sceneId);
-		ScriptOpCall scriptOpCall;
-		scriptOpCall._code = obd + 4;
-		scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(obd);
+		ScriptOpCall scriptOpCall(obd + 4, READ_LE_UINT32(obd));
 		_scriptOpcodes->runScript(scriptOpCall);
 	}
 
@@ -500,12 +494,22 @@ Common::Point Scene::getLayerOffset(uint8 layerNumber) {
 
 void Scene::drawBgLayer(uint8 layerNumber, Common::Rect rect, Graphics::Surface *surface) {
 	Common::Point offset = _stage->getLayerOffset(layerNumber);
-	Common::Rect clippedRect = _screen->clipRectToRect(offset.x, offset.y, rect, Common::Rect(_stage->getBgLayer()->w, _stage->getBgLayer()->h));
-	clippedRect.left += offset.x < 0 ? -offset.x : 0;
-	clippedRect.right += offset.x < 0 ? -offset.x : 0;
-	clippedRect.top += offset.y < 0 ? -offset.y : 0;
-	clippedRect.bottom += offset.y < 0 ? -offset.y : 0;
-	_screen->copyRectToSurface8bpp(*surface, _screen->getPalette(0), 0, 0, clippedRect, false, 128);
+//	Common::Rect clippedRect = _screen->clipRectToRect(offset.x, offset.y, rect, Common::Rect(_stage->getBgLayer()->w, _stage->getBgLayer()->h));
+	rect.left += rect.left + offset.x < 0 ? -(rect.left + offset.x) : offset.x;
+	if (rect.right + offset.x > surface->w) {
+		rect.right = surface->w - 1;
+	} else {
+		rect.right += offset.x;
+	}
+//	clippedRect.right += offset.x < 0 ? -offset.x : 0;
+	rect.top += rect.top + offset.y < 0 ? -(rect.top + offset.y) : offset.y;
+	if (rect.bottom + offset.y > surface->h) {
+		rect.bottom = surface->h - 1;
+	} else {
+		rect.bottom += offset.y;
+	}
+//	clippedRect.bottom += offset.y < 0 ? -offset.y : 0;
+	_screen->copyRectToSurface8bpp(*surface, _screen->getPalette(0), 0, 0, rect, false, 128);
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 0f85318b60..9b11af5d08 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -59,6 +59,11 @@ uint32 ScriptOpCall::readUint32() {
 	return value;
 }
 
+ScriptOpCall::ScriptOpCall(byte *start, uint32 length): _op(0), _result(0), _field8(0) {
+	_code = _base = start;
+	_codeEnd = _code + length;
+}
+
 // ScriptOpcodes
 
 ScriptOpcodes::ScriptOpcodes(DragonsEngine *vm, DragonFLG *dragonFLG)
@@ -76,7 +81,7 @@ ScriptOpcodes::~ScriptOpcodes() {
 void ScriptOpcodes::execOpcode(ScriptOpCall &scriptOpCall) {
 	if (!_opcodes[scriptOpCall._op])
 		error("ScriptOpcodes::execOpcode() Unimplemented opcode %d (0x%X)", scriptOpCall._op, scriptOpCall._op);
-	debug("execScriptOpcode(0x%X) %s", scriptOpCall._op, _opcodeNames[scriptOpCall._op].c_str());
+	debug("execScriptOpcode(0x%X) @%X  %s", scriptOpCall._op, scriptOpCall._code - scriptOpCall._base, _opcodeNames[scriptOpCall._op].c_str());
 	(*_opcodes[scriptOpCall._op])(scriptOpCall);
 }
 
@@ -273,11 +278,9 @@ void ScriptOpcodes::opUnk3(ScriptOpCall &scriptOpCall) {
 void ScriptOpcodes::opExecuteScript(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_UINT32(obdOffset);
-	ScriptOpCall newScriptOpCall;
 	byte *data =_vm->_dragonOBD->getObdAtOffset(obdOffset);
 
-	newScriptOpCall._code = data + 4;
-	newScriptOpCall._codeEnd = newScriptOpCall._code + READ_LE_UINT32(data);
+	ScriptOpCall newScriptOpCall(data + 4, READ_LE_UINT32(data));
 	newScriptOpCall._field8 = scriptOpCall._field8;
 	newScriptOpCall._result = 0;
 
@@ -393,9 +396,7 @@ void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
 
 void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	if (checkPropertyFlag(scriptOpCall)) {
-		ScriptOpCall localScriptOpCall;
-		localScriptOpCall._code = scriptOpCall._code + 4;
-		localScriptOpCall._codeEnd = localScriptOpCall._code + READ_LE_UINT16(scriptOpCall._code);
+		ScriptOpCall localScriptOpCall(scriptOpCall._code + 4, READ_LE_UINT16(scriptOpCall._code));
 		localScriptOpCall._field8 = scriptOpCall._field8;
 		localScriptOpCall._result = 0;
 
@@ -418,9 +419,7 @@ void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
 void ScriptOpcodes::opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	while (true) {
 		if (checkPropertyFlag(scriptOpCall)) {
-			ScriptOpCall localScriptOpCall;
-			localScriptOpCall._code = scriptOpCall._code + 4;
-			localScriptOpCall._codeEnd = localScriptOpCall._code + READ_LE_UINT32(scriptOpCall._code);
+			ScriptOpCall localScriptOpCall(scriptOpCall._code + 4, READ_LE_UINT32(scriptOpCall._code));
 
 			runScript(localScriptOpCall);
 
@@ -1076,9 +1075,7 @@ void ScriptOpcodes::opUnk19(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(size);
 
 	if (scriptOpCall._field8 == 3) {
-		ScriptOpCall newCall;
-		newCall._code = scriptOpCall._code;
-		newCall._codeEnd = scriptOpCall._code + size;
+		ScriptOpCall newCall(scriptOpCall._code, size);
 		_vm->_scriptOpcodes->runScript(newCall);
 	}
 	scriptOpCall._code += size;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index ae75d91e0f..7f2ddf29b1 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -34,10 +34,12 @@ class DragonsEngine;
 
 struct ScriptOpCall {
 	byte _op;
+	byte *_base;
 	byte *_code;
 	byte *_codeEnd;
 	int _field8;
 	int _result;
+	ScriptOpCall(byte *start, uint32 length);
 	void skip(uint size);
 	byte readByte();
 	int16 readSint16();
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 7f192254a4..81021c2617 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -536,7 +536,6 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 	uint16_t sequenceId;
 	TalkDialogEntry *selectedDialogText;
 	uint iniId;
-	ScriptOpCall local_1d20;
 	short local_990 [5];
 	uint16 auStack2438 [195];
 	uint16 local_800 [1000];
@@ -610,8 +609,7 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 				iniActor->updateSequence(sequenceId);
 			}
 		}
-		local_1d20._code = selectedDialogText->scriptCodeStartPtr;
-		local_1d20._codeEnd = selectedDialogText->scriptCodeEndPtr;
+		ScriptOpCall local_1d20(selectedDialogText->scriptCodeStartPtr, selectedDialogText->scriptCodeEndPtr - selectedDialogText->scriptCodeStartPtr);
 		_vm->_scriptOpcodes->runScript(local_1d20);
 		if (_vm->_scriptOpcodes->_data_80071f5c != 0) break;
 		local_1d20._code = selectedDialogText->scriptCodeStartPtr;


Commit: 88b0e2cff5392b023019e7424d4bc11674ce9d13
    https://github.com/scummvm/scummvm/commit/88b0e2cff5392b023019e7424d4bc11674ce9d13
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed bug while evaluating script expressions. expression
operands are signed.

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index a24573eb3c..b8aba5a30a 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -824,18 +824,20 @@ uint16 DragonsEngine::getIniFromImg() {
 }
 
 void DragonsEngine::runINIScripts() {
+	bool isFlag8Set = isFlagSet(ENGINE_FLAG_8);
 	for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
 		if (ini->field_1a_flags_maybe & Dragons::INI_FLAG_10) {
 			ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
 			byte *data = _dragonOBD->getFromOpt(i);
 			ScriptOpCall scriptOpCall(data + 8, READ_LE_UINT32(data));
-			uint32 currentFlags = _flags;
 			clearFlags(Dragons::ENGINE_FLAG_8);
 			_scriptOpcodes->runScript3(scriptOpCall);
-			_flags = currentFlags;
 		}
 	}
+	if (isFlag8Set) {
+		setFlags(ENGINE_FLAG_8);
+	}
 }
 /*
 void DragonsEngine::engineFlag0x20UpdateFunction() {
@@ -911,6 +913,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 	return (uint)run_func_ptr_unk_countdown_timer;
 } */
 
+//TODO the logic in this function doesn't match the original. It should be redone.
 void DragonsEngine::engineFlag0x20UpdateFunction() {
 	if (_flags & Dragons::ENGINE_FLAG_20) {
 		if ((_flags & (Dragons::ENGINE_FLAG_80000000 | Dragons::ENGINE_FLAG_8)) == 8) {
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 302424024a..5fb3c35db3 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -34,14 +34,14 @@ Minigame4::Minigame4(DragonsEngine *vm) : _vm(vm) {}
 
 void Minigame4::run() {
 	uint16 uVar1;
-	DragonINI *uVar2;
+	DragonINI *flicker;
 	uint uVar4;
 	ushort result;
 	int16_t uVar3;
 
 	uVar4 = _vm->getAllFlags();
 	uVar3 = _vm->_inventory->getType();
-	uVar2 = _vm->_dragonINIResource->getFlickerRecord();
+	flicker = _vm->_dragonINIResource->getFlickerRecord();
 	uVar1 = _vm->getCurrentSceneId();
 	// fade_related_calls_with_1f();
 	_vm->reset_screen_maybe();
@@ -101,7 +101,7 @@ void Minigame4::run() {
 	_vm->setFlags(ENGINE_FLAG_1);
 	_vm->videoFlags &= ~(uint16)4;
 	// EnableVSyncEvent();
-	_vm->_dragonINIResource->setFlickerRecord(uVar2);
+	_vm->_dragonINIResource->setFlickerRecord(flicker);
 	_vm->_inventory->setType(uVar3);
 //	_vm->_screen->loadPalette(4,(uint)*(ushort *)
 //					(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10)
@@ -109,7 +109,7 @@ void Minigame4::run() {
 	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
 	_vm->_scene->setSceneId(uVar1);
 	_vm->setAllFlags(uVar4);
-	uVar2->sceneId = uVar1;
+	flicker->sceneId = uVar1;
 	_vm->_scene->loadScene(uVar1,0x1e);
 }
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 9b11af5d08..ab01f39133 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -387,7 +387,7 @@ void ScriptOpcodes::opPlayMusic(ScriptOpCall &scriptOpCall) {
 }
 
 void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
-	if (checkPropertyFlag(scriptOpCall)) {
+	if (evaluateExpression(scriptOpCall)) {
 		scriptOpCall._code += 4;
 	} else {
 		scriptOpCall._code += 4 + READ_LE_UINT16(scriptOpCall._code);
@@ -395,7 +395,7 @@ void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
 }
 
 void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
-	if (checkPropertyFlag(scriptOpCall)) {
+	if (evaluateExpression(scriptOpCall)) {
 		ScriptOpCall localScriptOpCall(scriptOpCall._code + 4, READ_LE_UINT16(scriptOpCall._code));
 		localScriptOpCall._field8 = scriptOpCall._field8;
 		localScriptOpCall._result = 0;
@@ -418,7 +418,7 @@ void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
 
 void ScriptOpcodes::opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	while (true) {
-		if (checkPropertyFlag(scriptOpCall)) {
+		if (evaluateExpression(scriptOpCall)) {
 			ScriptOpCall localScriptOpCall(scriptOpCall._code + 4, READ_LE_UINT32(scriptOpCall._code));
 
 			runScript(localScriptOpCall);
@@ -452,15 +452,15 @@ void ScriptOpcodes::opUnk21(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-bool ScriptOpcodes::checkPropertyFlag(ScriptOpCall &scriptOpCall) {
+bool ScriptOpcodes::evaluateExpression(ScriptOpCall &scriptOpCall) {
 	byte *codePtrOffsetA = scriptOpCall._code + 0xA;
 	byte *codePtrOffset2 = scriptOpCall._code + 2;
 
 	uint16 status = 0;
 	uint16 result = 0;
 
-	uint16 t2 = 0;
-	uint16 t0 = 0;
+	int16 t2 = 0;
+	int16 t0 = 0;
 
 	for(;;) {
 		byte value = 0;
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 7f2ddf29b1..bb7881e97f 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -118,7 +118,7 @@ protected:
 	void opUnk20(ScriptOpCall &scriptOpCall);
 	void opUnk21(ScriptOpCall &scriptOpCall);
 
-	bool checkPropertyFlag(ScriptOpCall &scriptOpCall);
+	bool evaluateExpression(ScriptOpCall &scriptOpCall);
 	void opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall);
 	void opCode_Unk7(ScriptOpCall &scriptOpCall);
 


Commit: 9dcc30945ae89e94ad2ee33d5cded7933f951bd0
    https://github.com/scummvm/scummvm/commit/9dcc30945ae89e94ad2ee33d5cded7933f951bd0
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Started on mini game 2. Added vsync updater function logic

Changed paths:
  A engines/dragons/minigame2.cpp
  A engines/dragons/minigame2.h
    engines/dragons/actor.cpp
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index fc3d8bcd92..43f79486e4 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -281,6 +281,8 @@ bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, uint16 unkTypeMayb
 			priority = 1;
 		}
 	}
+//	if (((unkTypeMaybe == 0) && (7 < (priority - 1 & 0xffff))) || 	//TODO this is the correct logic I think. need to redo all the pathfinding logic.
+//		((unkTypeMaybe == 1 && (0xf < (priority - 1 & 0xffff))))) {
 	if ((unkTypeMaybe != 0 || priority - 1 < 8) && (unkTypeMaybe != 1 || priority - 1 < 16)) {
 		var_90_1 = (unkTypeMaybe ^ 2) < 1 ? 1 : 0;
 
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index b3bec33116..a82b5ca3fb 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -831,5 +831,70 @@ void CutScene::knightsSavedAgain() {
 	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
 }
 
+static uint16 tournamentUpdateCameraX = 0;
+
+void tournamentUpdateFunction() {
+	tournamentUpdateCameraX++;
+	if (tournamentUpdateCameraX > 0x280) {
+		return;
+	}
+	getEngine()->_scene->_camera.x = tournamentUpdateCameraX;
+}
+
+void CutScene::tournamentCutScene() {
+	uint actorId;
+	ushort uVar1;
+	uint16 dialogText[1000];
+//	undefined2 local_218 [256];
+
+	uVar1 = 0;
+	actorId = 0;
+//	do {
+//		uVar1 = uVar1 + 1;
+//		local_218[actorId] = *(undefined2 *)(actorId * 2 + scrFileData_maybe);
+//		actorId = (uint)uVar1;
+//	} while (uVar1 < 0x100);
+
+	tournamentUpdateCameraX = 0x140;
+	_vm->setVsyncUpdateFunction(tournamentUpdateFunction);
+	_vm->_talk->loadText(0x4C40C, dialogText, 1000);
+	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0x1e01,1,0x4C40C);
+
+	_vm->_talk->loadText(0x4C530, dialogText, 1000);
+	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0xc01,1,0x4C530);
+
+	_vm->_talk->loadText(0x4C588, dialogText, 1000);
+	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0x1e01,1, 0x4C588);
+
+	_vm->_talk->loadText(0x4C6B0, dialogText, 1000);
+	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0xc01,1, 0x4C6B0);
+
+	_vm->_talk->loadText(0x4C6E8, dialogText, 1000);
+	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0x1e01,1, 0x4C6E8);
+	_vm->setVsyncUpdateFunction(NULL);
+	_vm->setFlags(ENGINE_FLAG_20000);
+	// fade_related_calls_with_1f();
+	Actor *actor = _vm->_dragonINIResource->getRecord(0x02BE)->actor;
+	_vm->_screen->loadPalette(0, actor->getPalette());
+	_vm->_scene->_camera.x = 0;
+	_vm->playSound(0);
+//	call_fade_related_1f();
+	_vm->waitForFrames(300);
+	actor->setFlag(ACTOR_FLAG_1000);
+	actor->waitUntilFlag8And4AreSet();
+	_vm->waitForFrames(0x3c);
+//	fade_related_calls_with_1f();
+	_vm->_screen->loadPalette(0, _vm->_scene->getPalette());
+	_vm->playSound(0x4000);
+	_vm->_scene->_camera.x = 0x3c0;
+//	call_fade_related_1f();
+	_vm->_talk->loadText(0x4C814, dialogText, 1000);
+	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0xc01,1, 0x4C814);
+	_vm->_talk->loadText(0x4C852, dialogText, 1000);
+	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0x1e01,1, 0x4C852);
+	_vm->setFlags(ENGINE_FLAG_20000);
+//	fade_related_calls_with_1f();
+}
+
 
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index df004e1ff0..3189fd97af 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -62,6 +62,7 @@ public:
 	void knightsSavedBackAtCastle();
 	void flameReturnsCutScene();
 	void knightsSavedAgain();
+	void tournamentCutScene();
 
 private:
 	//Scene 1 related functions
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index b8aba5a30a..cf8bdb3e65 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -70,6 +70,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_sound = new Sound(this);
 	_fontManager = NULL;
 	_sceneUpdateFunction = NULL;
+	_vsyncUpdateFunction = NULL;
 
 	_leftMouseButtonUp = false;
 	_leftMouseButtonDown = false;
@@ -675,7 +676,7 @@ void DragonsEngine::updateHandler() {
 		engineFlag0x20UpdateFunction();
 	}
 
-	//TODO vsync update function
+	runVsyncUpdaterFunction();
 
 	// TODO data_8006a3a0 logic. @ 0x8001c2f4
 
@@ -1307,6 +1308,10 @@ void DragonsEngine::setSceneUpdateFunction(void (*newUpdateFunction)()) {
 	_sceneUpdateFunction = newUpdateFunction;
 }
 
+void DragonsEngine::setVsyncUpdateFunction(void (*newUpdateFunction)()) {
+	_vsyncUpdateFunction = newUpdateFunction;
+}
+
 void DragonsEngine::seedRandom(int32 seed) {
 		_randomState = seed * -0x2b0e2b0f;
 }
@@ -1375,6 +1380,16 @@ bool DragonsEngine::isDebugMode() {
 	return _debugMode;
 }
 
+bool DragonsEngine::isVsyncUpdaterFunctionRunning() {
+	return _vsyncUpdateFunction != NULL;
+}
+
+void DragonsEngine::runVsyncUpdaterFunction() {
+	if (isVsyncUpdaterFunctionRunning()) {
+		_vsyncUpdateFunction();
+	}
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 0f79c4a81a..dfd46ee205 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -187,6 +187,7 @@ private:
 	bool _debugMode;
 
 	void (*_sceneUpdateFunction)();
+	void (*_vsyncUpdateFunction)();
 protected:
 	virtual bool hasFeature(EngineFeature f) const;
 public:
@@ -246,6 +247,10 @@ public:
 	void setSceneUpdateFunction(void (*newUpdateFunction)());
 	void (*getSceneUpdateFunction())();
 
+	void setVsyncUpdateFunction(void (*newUpdateFunction)());
+	bool isVsyncUpdaterFunctionRunning();
+	void runVsyncUpdaterFunction();
+
 	bool isActionButtonPressed();
 	bool isLeftKeyPressed();
 	bool isRightKeyPressed();
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
new file mode 100644
index 0000000000..67a4ae3781
--- /dev/null
+++ b/engines/dragons/minigame2.cpp
@@ -0,0 +1,35 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "minigame2.h"
+#include "actor.h"
+#include "dragons.h"
+#include "dragons/dragonini.h"
+#include "dragons/talk.h"
+
+namespace Dragons {
+
+Minigame2::Minigame2(DragonsEngine *vm) : _vm(vm) {}
+
+void Minigame2::run() {
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/minigame2.h b/engines/dragons/minigame2.h
new file mode 100644
index 0000000000..707516ed9d
--- /dev/null
+++ b/engines/dragons/minigame2.h
@@ -0,0 +1,42 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 DRAGONS_MINIGAME2_H
+#define DRAGONS_MINIGAME2_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class DragonsEngine;
+
+class Minigame2 {
+private:
+	DragonsEngine *_vm;
+public:
+	Minigame2(DragonsEngine *vm);
+
+	void run();
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_MINIGAME2_H
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index f5aff6222c..21d08a32a2 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -19,6 +19,7 @@ MODULE_OBJS := \
 	font.o \
 	inventory.o \
 	minigame1.o \
+	minigame2.o \
 	minigame3.o \
 	minigame4.o \
 	saveload.o \
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index c09b0a3b4f..b57c88cebd 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -35,6 +35,7 @@
 #include "dragons/talk.h"
 #include "dragons/specialopcodes.h"
 #include "dragons/minigame1.h"
+#include "dragons/minigame2.h"
 #include "dragons/minigame3.h"
 #include "dragons/minigame4.h"
 
@@ -71,6 +72,7 @@ void SpecialOpcodes::initOpcodes() {
 	}
 	// Register opcodes
 	OPCODE(1, spcCatapultMiniGame);
+	OPCODE(2, spcThumbWrestlingMiniGame);
 	OPCODE(3, spcClearEngineFlag10);
 	OPCODE(4, spcSetEngineFlag10);
 
@@ -162,6 +164,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x64, spcResetInventorySequence);
 	OPCODE(0x65, spcUnk65ScenePaletteRelated);
 	OPCODE(0x66, spcUnk66);
+	OPCODE(0x67, spcTournamentSetCamera);
+	OPCODE(0x68, spcTournamentCutScene);
 
 	OPCODE(0x6a, spcCastleGateSceneLogic);
 	OPCODE(0x6b, spcTransitionToMap);
@@ -200,9 +204,13 @@ void SpecialOpcodes::freeOpcodes() {
 // Opcodes
 
 void SpecialOpcodes::spcCatapultMiniGame() {
-	spcRabbitsMiniGame();
-//	Minigame1 minigame1(_vm);
-//	minigame1.run();
+	Minigame1 minigame1(_vm);
+	minigame1.run();
+}
+
+void SpecialOpcodes::spcThumbWrestlingMiniGame() {
+	Minigame2 minigame2(_vm);
+	minigame2.run();
 }
 
 void SpecialOpcodes::spcClearEngineFlag10() {
@@ -691,6 +699,16 @@ void SpecialOpcodes::spcUnk66() {
 	_vm->getINI(1)->field_12 = uVar9;
 }
 
+void SpecialOpcodes::spcTournamentSetCamera() {
+	_vm->_scene->_camera.x = 0x140; // TODO should have method for updating camera.
+}
+
+void SpecialOpcodes::spcTournamentCutScene() {
+	CutScene *cutScene = new CutScene(_vm);
+	cutScene->tournamentCutScene();
+	delete cutScene;
+}
+
 void SpecialOpcodes::spcCastleGateSceneLogic() {
 //TODO spcCastleGateSceneLogic
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index bcc5c6c991..cd263d684d 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -67,6 +67,7 @@ protected:
 
 	// Opcodes
 	void spcCatapultMiniGame(); // 1
+	void spcThumbWrestlingMiniGame(); // 2
 	void spcClearEngineFlag10(); // 3
 	void spcSetEngineFlag10();   // 4
 
@@ -157,6 +158,8 @@ protected:
 	void spcResetInventorySequence(); // 0x64
 	void spcUnk65ScenePaletteRelated(); // 0x65;
 	void spcUnk66();
+	void spcTournamentSetCamera(); // 0x67
+	void spcTournamentCutScene(); // 0x68
 
 	void spcCastleGateSceneLogic(); // 0x6a
 	void spcTransitionToMap(); // 0x6b


Commit: 8df472f6999a65ea26fab831ef9f3403797e9f2e
    https://github.com/scummvm/scummvm/commit/8df472f6999a65ea26fab831ef9f3403797e9f2e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed random number generator. Fixed returning to dialog menu while talking

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index cf8bdb3e65..dcfea3489d 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1331,7 +1331,7 @@ uint16 DragonsEngine::getRand(uint16 max) {
 	uint16 rand = 0;
 
 	for (int i = 0; i < 0x10; i++) {
-		rand = shuffleRandState() | rand << i;
+		rand |= shuffleRandState() << i;
 	}
 	return rand % max;
 }
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 136061119b..73f5356aeb 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -105,7 +105,7 @@ void Minigame3::run() {
 	int16 local_5a;
 	int16 local_58;
 	int16 local_56;
-	int16 local_52;
+	int16 hopCounter;
 	uint16 local_50;
 	BunnyStruct bunnyInfo [2];
 	uint16 local_20;
@@ -118,7 +118,8 @@ void Minigame3::run() {
 	int16 origInventoryType;
 	int16 local_10;
 	int16 local_e;
-	UnkStruct UnkStruct_ARRAY_800931a0[5];
+	UnkStruct UnkStruct_ARRAY_800931a0[4];
+	int16 unkXPosTbl[20];
 
 
 	Common::File *fd = new Common::File();
@@ -150,7 +151,7 @@ void Minigame3::run() {
 
 	fd->seek(0x4914);
 
-	for (int i = 0; i < 5; i++) {
+	for (int i = 0; i < 4; i++) {
 		UnkStruct_ARRAY_800931a0[i].position1 = fd->readUint16LE();
 		UnkStruct_ARRAY_800931a0[i].position2 = fd->readUint16LE();
 		UnkStruct_ARRAY_800931a0[i].unk4 = fd->readUint32LE();
@@ -160,6 +161,10 @@ void Minigame3::run() {
 		UnkStruct_ARRAY_800931a0[i].field_0x14 = fd->readUint32LE();
 	}
 
+	for (int i = 0; i < 20; i++) {
+		unkXPosTbl[i] = fd->readSint16LE();
+	}
+
 	fd->close();
 	delete fd;
 
@@ -327,7 +332,7 @@ void Minigame3::run() {
 	currentState = 2;
 	flags = 0;
 	local_58 = 0x1e;
-	local_52 = 0;
+	hopCounter = 0;
 	local_210 = 0;
 	local_1de = 0;
 	local_5a = 0;
@@ -376,8 +381,7 @@ void Minigame3::run() {
 							bunnyInfo[local_1e].field_0xc = bunnyInfo[local_1e].field_0xc + bunnyInfo[local_1e].field_0x10;
 							bunnyActorTbl[local_1a]->x_pos = (int16_t)((int)bunnyInfo[local_1e].x >> 9);
 							bunnyActorTbl[local_1a]->y_pos = (int16_t)((int)bunnyInfo[local_1e].y >> 9);
-//							if ((local_228 < 4) && (*(int16 *)((uint)local_228 * 2 + (uint)local_50 * 8 + -0x7ff6ce00) < bunnyActorTbl[local_1a]->x_pos)) {
-							if ((local_228 < 4) && _vm->_actorManager->getActor(0)->x_pos < bunnyActorTbl[local_1a]->x_pos) {
+							if ((local_228 < 4) && unkXPosTbl[local_50 * 4 + local_228] < bunnyActorTbl[local_1a]->x_pos) {
 								local_228 = local_228 + 1;
 								bunnyActorTbl[local_1a]->updateSequence((uint)local_228 + 6 & 0xffff);
 								bunnyActorTbl[local_1c]->updateSequence((uint)local_228 + 0xd & 0xffff);
@@ -422,7 +426,7 @@ void Minigame3::run() {
 				local_1c = bunnyPositionTbl[bunnyInfo[local_20].positionIdx];
 				bunnyActorTbl[local_1a]->updateSequence(5);
 				bunnyActorTbl[local_1c]->updateSequence(0xc);
-				if (local_52 == 0x1d) {
+				if (hopCounter == 0x1d) {
 					_vm->playSound(2);
 				}
 				else {
@@ -439,7 +443,7 @@ void Minigame3::run() {
 				currentState = 1;
 				break;
 			case 5:
-				local_52 = local_52 + 1;
+				hopCounter = hopCounter + 1;
 				local_5a = local_5a + 1;
 				bunnyActorTbl[local_1a]->updateSequence(0xb);
 				bunnyActorTbl[local_1c]->updateSequence(0x12);
@@ -618,7 +622,7 @@ void Minigame3::run() {
 				tearBlinkActorTbl[1]->y_pos = tearBlinkActorTbl[1]->y_pos + -3;
 			}
 		}
-		if (local_52 == 0x1e) {
+		if (hopCounter == 0x1e) {
 			currentState = 6;
 		}
 		if ((flags & 8) != 0) break;
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 81021c2617..9d8429f3df 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -539,6 +539,7 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 	short local_990 [5];
 	uint16 auStack2438 [195];
 	uint16 local_800 [1000];
+	Common::Array<TalkDialogEntry *> dialogEntries;
 
 	bool isFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
 	bool isFlag100Set = _vm->isFlagSet(ENGINE_FLAG_100);
@@ -552,25 +553,32 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 	if (numEntries == 0) {
 		return 0;
 	}
+
+	for (Common::Array<TalkDialogEntry*>::iterator it = _dialogEntries.begin(); it != _dialogEntries.end(); it++) {
+		TalkDialogEntry *entry = (TalkDialogEntry *)malloc(sizeof(TalkDialogEntry));
+		memcpy(entry, *it, sizeof(TalkDialogEntry));
+		dialogEntries.push_back(entry);
+	}
+
 	_vm->setFlags(ENGINE_FLAG_100);
 	do {
 		callMaybeResetData();
 		int numActiveDialogEntries = 0;
-		for (Common::Array<TalkDialogEntry*>::iterator it = _dialogEntries.begin(); it != _dialogEntries.end(); it++) {
+		for (Common::Array<TalkDialogEntry*>::iterator it = dialogEntries.begin(); it != dialogEntries.end(); it++) {
 			if (!((*it)->flags & 1)) {
 				numActiveDialogEntries++;
 			}
 		}
 		if (numActiveDialogEntries == 0) {
 			//TODO logic from LAB_80029bc0 reset cursor
-			exitTalkMenu(isFlag8Set, isFlag100Set);
+			exitTalkMenu(isFlag8Set, isFlag100Set, dialogEntries);
 			return 1;
 		}
 
-		selectedDialogText = displayTalkDialogMenu();
+		selectedDialogText = displayTalkDialogMenu(dialogEntries);
 		if (selectedDialogText == NULL) {
 			callMaybeResetData();
-			exitTalkMenu(isFlag8Set, isFlag100Set);
+			exitTalkMenu(isFlag8Set, isFlag100Set, dialogEntries);
 			return 1;
 		}
 		_vm->clearFlags(ENGINE_FLAG_8);
@@ -621,11 +629,12 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 //	LAB_80029bc0:
 //	actors[0].x_pos = cursor_x_var;
 //	actors[0].y_pos = cursor_y_var;
-	exitTalkMenu(isFlag8Set, isFlag100Set);
+
+	exitTalkMenu(isFlag8Set, isFlag100Set, dialogEntries);
 	return 1;
 }
 
-TalkDialogEntry *Talk::displayTalkDialogMenu() {
+TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dialogEntries) {
 	bool bVar1;
 	short sVar2;
 	uint uVar3;
@@ -658,11 +667,11 @@ TalkDialogEntry *Talk::displayTalkDialogMenu() {
 	uVar8 = 0;
 	local_60 = 0;
 	local_58 = 0;
-	numEntries = _dialogEntries.size();
+	numEntries = dialogEntries.size();
 	if (numEntries != 0) {
 		uVar3 = 0;
 		do {
-			talkDialogEntry =  _dialogEntries[uVar3];
+			talkDialogEntry =  dialogEntries[uVar3];
 			if ((talkDialogEntry->flags & 1) == 0) {
 				local_60 = local_60 + 1;
 				talkDialogEntry->yPosMaybe = '\0';
@@ -698,7 +707,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu() {
 	if (hasDialogEntries) {
 		uVar3 = 0;
 		do {
-			talkDialogEntry = _dialogEntries[uVar3];
+			talkDialogEntry = dialogEntries[uVar3];
 			if (((talkDialogEntry->flags & 1) == 0) && (bVar1 = y == uVar8, y = y + 1, bVar1)) break;
 			x = x + 1;
 			uVar3 = (uint)x;
@@ -720,7 +729,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu() {
 			if (hasDialogEntries) {
 				uVar3 = 0;
 				do {
-					talkDialogEntry = _dialogEntries[uVar3];
+					talkDialogEntry = dialogEntries[uVar3];
 					y = y + 1;
 					if ((talkDialogEntry->flags & 1) == 0) {
 						if (uVar8 == 0) {
@@ -751,7 +760,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu() {
 		if (hasDialogEntries) {
 			uVar6 = 0;
 			do {
-				talkDialogEntry = _dialogEntries[uVar6];
+				talkDialogEntry = dialogEntries[uVar6];
 				uVar6 = (uint)talkDialogEntry->flags & 1;
 				if ((talkDialogEntry->flags & 1) == 0) {
 					sVar2 = local_50 + 1;
@@ -815,7 +824,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu() {
 	goto LAB_800317a4;
 }
 
-void Talk::exitTalkMenu(bool isFlag8Set, bool isFlag100Set) {
+void Talk::exitTalkMenu(bool isFlag8Set, bool isFlag100Set, Common::Array<TalkDialogEntry*> dialogEntries) {
 	_vm->clearFlags(ENGINE_FLAG_8);
 	_vm->clearFlags(ENGINE_FLAG_100);
 
@@ -826,6 +835,10 @@ void Talk::exitTalkMenu(bool isFlag8Set, bool isFlag100Set) {
 		_vm->setFlags(ENGINE_FLAG_100);
 	}
 
+	for (Common::Array<TalkDialogEntry*>::iterator it = dialogEntries.begin(); it != dialogEntries.end(); it++) {
+		delete *it;
+	}
+	dialogEntries.clear();
 }
 
 uint Talk::somethingTextAndSpeechAndAnimRelated(Actor *actor, int16 sequenceId1, int16 sequenceId2, uint32 textIndex,
@@ -1107,4 +1120,4 @@ void Talk::playDialogAudioDontWait(uint32 textIndex) {
 	_vm->_sound->playSpeech(textIndex);
 }
 
-} // End of namespace Dragons
\ No newline at end of file
+} // End of namespace Dragons
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 5f808f32ee..a1e41216a5 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -94,8 +94,8 @@ private:
 	void FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2); //clear box maybe?
 	void copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength);
 	uint32 wideStrLen(uint16 *text);
-	TalkDialogEntry *displayTalkDialogMenu();
-	void exitTalkMenu(bool isFlag8Set, bool isFlag100Set);
+	TalkDialogEntry *displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dialogEntries);
+	void exitTalkMenu(bool isFlag8Set, bool isFlag100Set, Common::Array<TalkDialogEntry*> dialogEntries);
 	uint32 getDefaultResponseTextIndex();
 	void initDefaultResponseTable();
 	uint32 strlenUTF16(uint16 *text);


Commit: e51fe35e3ade6f597f9aff4614d40771dd82661b
    https://github.com/scummvm/scummvm/commit/e51fe35e3ade6f597f9aff4614d40771dd82661b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Palette fixes

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/cutscene.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 43f79486e4..410fdb77bc 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -889,9 +889,12 @@ byte *Actor::getPalette() {
 	if (!isFlagSet(ACTOR_FLAG_4000)) {
 		if (!isFlagSet(ACTOR_FLAG_8000)) {
 			//TODO need to support per actor custom palettes.
+			if ((frame_flags & 0x30) != 0) {
+				return _actorResource->getPalette();
+			}
 			return getEngine()->_screen->getPalette(1);
 		} else {
-			return getEngine()->_scene->getPalette();
+			return getEngine()->_screen->getPalette(0);
 		}
 	}
 	return getEngine()->_screen->getPalette(4);
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index a82b5ca3fb..43413f98ea 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -875,7 +875,7 @@ void CutScene::tournamentCutScene() {
 	_vm->setFlags(ENGINE_FLAG_20000);
 	// fade_related_calls_with_1f();
 	Actor *actor = _vm->_dragonINIResource->getRecord(0x02BE)->actor;
-	_vm->_screen->loadPalette(0, actor->getPalette());
+	_vm->_screen->loadPalette(0, actor->_actorResource->getPalette());
 	_vm->_scene->_camera.x = 0;
 	_vm->playSound(0);
 //	call_fade_related_1f();


Commit: 211377a5b3ee32316b1ba8e14179acbe092ec7cc
    https://github.com/scummvm/scummvm/commit/211377a5b3ee32316b1ba8e14179acbe092ec7cc
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on mini game 2

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame2.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 410fdb77bc..3046d63155 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -888,7 +888,6 @@ bool Actor::waitUntilFlag4IsSetAllowSkip() {
 byte *Actor::getPalette() {
 	if (!isFlagSet(ACTOR_FLAG_4000)) {
 		if (!isFlagSet(ACTOR_FLAG_8000)) {
-			//TODO need to support per actor custom palettes.
 			if ((frame_flags & 0x30) != 0) {
 				return _actorResource->getPalette();
 			}
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 67a4ae3781..3a0d57702b 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -21,15 +21,800 @@
  */
 #include "minigame2.h"
 #include "actor.h"
+#include "dragons/actorresource.h"
 #include "dragons.h"
 #include "dragons/dragonini.h"
 #include "dragons/talk.h"
+#include "dragons/inventory.h"
+#include "dragons/scene.h"
+#include "dragons/screen.h"
+#include "dragons/cursor.h"
+#include "dragons/sound.h"
 
 namespace Dragons {
 
 Minigame2::Minigame2(DragonsEngine *vm) : _vm(vm) {}
 
-void Minigame2::run() {
+static const uint16 unkArray[5] = {
+		0xC, 0xA, 0x8, 0x6, 0x4
+};
+
+void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
+	uint16_t uVar1;
+	short sVar2;
+	short sVar3;
+	bool shouldExit;
+	bool bVar4;
+	DragonINI *flicker;
+	uint32 origEngineFlags;
+	Actor *uVar5;
+	Actor *uVar6;
+	Actor *uVar7;
+	Actor *uVar8;
+	Actor *uVar9;
+	Actor *uVar10;
+	Actor *uVar11;
+	Actor *uVar12;
+	Actor *uVar13;
+	Actor *uVar14;
+	Actor *uVar15;
+	ushort uVar16;
+	ushort uVar17;
+	uint uVar18;
+	uint uVar19;
+	int iVar20;
+	bool shouldShakeScreen;
+	byte *actorFrameData;
+	ushort local_2e6;
+	int16_t actorSequenceIdTbl [15];
+	uint32_t textIdTbl [4];
+	uint16_t local_2b0 [8];
+	ushort local_288;
+	ushort local_286;
+	ushort local_284;
+	ushort local_282;
+	ushort local_27a;
+	ushort local_278;
+	short local_272;
+	short local_26c;
+	ushort local_268;
+	ushort local_264;
+	ushort local_262;
+	short local_260;
+	short local_258;
+	short local_256;
+	int16_t screenShakeTbl [10];
+	ushort screenShakeCounter;
+	uint8 paletteData [0x200];
+	ushort local_28;
+	int16 originalInventoryType;
+
+	origEngineFlags = _vm->getAllFlags();
+	originalInventoryType = _vm->_inventory->getType();
+	flicker = _vm->_dragonINIResource->getFlickerRecord();
+
+	Common::File *fd = new Common::File();
+	if (!fd->open("arc2.bin")) {
+		error("Failed to open arc2.bin");
+	}
+
+	for (int i = 0; i < 15; i++) {
+		actorSequenceIdTbl[i] = fd->readSint16LE();
+	}
+
+	fd->skip(2);
+
+	for (int i = 0; i < 6; i++) {
+		local_2b0[i] = fd->readSint16LE();
+	}
+
+	for (int i = 0; i < 9; i++) {
+		screenShakeTbl[i] = fd->readSint16LE();
+	}
+
+	fd->close();
+
+	textIdTbl[0] = 0x4500;
+	textIdTbl[1] = 0x454A;
+	textIdTbl[2] = 0x4576;
+
+	bVar4 = false;
+	shouldExit = false;
+	local_27a = 0;
+	local_278 = 0;
+	local_272 = 0;
+	local_26c = 0x1e;
+	shouldShakeScreen = false;
+	local_264 = 0;
+	local_262 = 0;
+	local_260 = 300;
+	local_258 = 0;
+	local_256 = 0;
+	screenShakeCounter = 0;
+	local_2e6 = param_2;
+	if (4 < param_2) {
+		local_2e6 = 4;
+	}
+	DAT_80093ca4 = unkArray[local_2e6];
+	DAT_80093c90 = unkArray[local_2e6];
+	DAT_80093c94 = 0;
+	_vm->_inventory->setType(0);
+	DAT_80093cb4 = 2;
+	DAT_80093cbc = 0;
+	DAT_80093cb8 = 2;
+	DAT_80093cc0 = 0;
+	DAT_80093cac = 0;
+	DAT_80093cb0 = 0;
+	DAT_80093c9c = 0;
+	_vm->_talk->DAT_8008e874_dialogBox_y2 = 0;
+	_vm->_talk->DAT_8008e844_dialogBox_y1 = 0;
+	_vm->_talk->DAT_8008e848_dialogBox_x2 = 0;
+	_vm->_talk->DAT_8008e7e8_dialogBox_x1 = 0;
+	DAT_80093c98 = DAT_80093c90;
+	DAT_80093ca0 = param_1;
+	DAT_80093cc4 = DAT_80093ca4;
+	DAT_80093cc8 = DAT_80093ca4;
+	//fade_related_calls_with_1f();
+	_vm->reset_screen_maybe();
+	_vm->_inventory->setType(0);
+	flicker->sceneId = 0;
+	_vm->_dragonINIResource->setFlickerRecord(NULL);
+	_vm->setFlags(ENGINE_FLAG_800);
+	_vm->_scene->setSceneId(5);
+	_vm->_scene->loadSceneData(5 | 0x8000,0);
+	//DisableVSyncEvent();
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_10);
+	_vm->clearFlags(ENGINE_FLAG_20);
+	_vm->clearFlags(ENGINE_FLAG_80);
+
+	memcpy(paletteData, _vm->_scene->getPalette() + 0x180, 0x80);
+	memcpy(paletteData + 0x80, _vm->_scene->getPalette() + 0x180, 0x80);
+	_vm->_screen->loadPalette(1, paletteData);
+	_vm->_screen->updatePaletteTransparency(1,0x40,0x7f,true);
+
+	uVar5 = _vm->_actorManager->loadActor(0x11,0,0,0,6);
+	uVar6 = _vm->_actorManager->loadActor(0xd,0,0x7d,199,4);
+	uVar7 = _vm->_actorManager->loadActor(0xb,2,0x7d,199,4);
+	uVar8 = _vm->_actorManager->loadActor(0xf,0,0x7d,199,4);
+	uVar9 = _vm->_actorManager->loadActor(0x10,0,0x7d,199,4);
+	actorFrameData = uVar7->frame->frameDataOffset;
+	uVar10 = _vm->_actorManager->loadActor(9,(uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
+								uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe),
+								uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10),4);
+	uVar11 = _vm->_actorManager->loadActor(0x12,(uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
+								uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe),
+								uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10),4);
+	actorFrameData = uVar10->frame->frameDataOffset;
+	uVar12 = _vm->_actorManager->loadActor(10,(uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
+			uVar10->x_pos - READ_LE_INT16(actorFrameData + 0xe),
+			uVar10->y_pos - READ_LE_INT16(actorFrameData + 0x10),4);
+	uVar13 = _vm->_actorManager->loadActor(0x13,(uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
+			uVar10->x_pos - READ_LE_INT16(actorFrameData + 0xe),
+			uVar10->y_pos - READ_LE_INT16(actorFrameData + 0x10),4);
+	uVar14 = _vm->_actorManager->loadActor(0x27,0,0x10,0xac,4);
+	uVar15 = _vm->_actorManager->loadActor(0x27,1,0x10,0x8c,4);
+	uVar5->setFlag(ACTOR_FLAG_100);
+	uVar6->setFlag(ACTOR_FLAG_100);
+	uVar7->setFlag(ACTOR_FLAG_100);
+	uVar8->setFlag(ACTOR_FLAG_100);
+	uVar9->setFlag(ACTOR_FLAG_100);
+	uVar10->setFlag(ACTOR_FLAG_100);
+	uVar11->setFlag(ACTOR_FLAG_100);
+	uVar12->setFlag(ACTOR_FLAG_100);
+	uVar13->setFlag(ACTOR_FLAG_100);
+	uVar14->setFlag(ACTOR_FLAG_100);
+	uVar15->setFlag(ACTOR_FLAG_100);
+
+	uVar5->priorityLayer = 6;
+	uVar10->priorityLayer = 5;
+	uVar12->priorityLayer = 5;
+	uVar11->priorityLayer = 4;
+	uVar13->priorityLayer = 3;
+	uVar9->priorityLayer = 3;
+	uVar7->priorityLayer = 2;
+	uVar6->priorityLayer = 2;
+	uVar8->priorityLayer = 1;
+	uVar14->priorityLayer = 0;
+	uVar15->priorityLayer = 0;
+	//TODO
+//	uVar16 = AddFlatShadedQuad(0x28,0xa8,0x67,0xa8,0x67,0xaf,0x28,0xaf,0x1f,7,0);
+//	uVar17 = AddFlatShadedQuad(0x28,0x88,0x67,0x88,0x67,0x8f,0x28,0x8f,0x3e0,7,0);
+//	(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] & 0xfffe;
+//	(&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] & 0xfffe;
+//	EnableVSyncEvent();
+	uVar6->setFlag(ACTOR_FLAG_1);
+	uVar7->setFlag(ACTOR_FLAG_1);
+	uVar8->setFlag(ACTOR_FLAG_1);
+	uVar9->setFlag(ACTOR_FLAG_1);
+	uVar10->setFlag(ACTOR_FLAG_1);
+	uVar11->setFlag(ACTOR_FLAG_1);
+	uVar12->setFlag(ACTOR_FLAG_1);
+	uVar13->setFlag(ACTOR_FLAG_1);
+	uVar10->waitUntilFlag8And4AreSet();
+	uVar12->waitUntilFlag8And4AreSet();
+	uVar11->waitUntilFlag8And4AreSet();
+	uVar13->waitUntilFlag8And4AreSet();
+	uVar7->waitUntilFlag8And4AreSet();
+	uVar9->waitUntilFlag8And4AreSet();
+	uVar6->waitUntilFlag8And4AreSet();
+	uVar8->waitUntilFlag8And4AreSet();
+
+	uVar5->setFlag(ACTOR_FLAG_400);
+	actorFrameData = uVar7->frame->frameDataOffset;
+	uVar10->x_pos = uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe);
+	uVar10->y_pos = uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10);
+	uVar11->x_pos = uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe);
+	uVar11->y_pos = uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10);
+	actorFrameData = uVar10->frame->frameDataOffset;
+	uVar12->x_pos = uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe);
+	uVar12->y_pos = uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10);
+	uVar13->x_pos = uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe);
+	uVar13->y_pos = uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10);
+	_vm->waitForFrames(200);
+	// call_fade_related_1f();
+
+	LAB_80090188:
+	do {
+		if (shouldExit) {
+//			fade_related_calls_with_1f();
+			_vm->_sound->PauseCDMusic();
+//			DisableVSyncEvent();
+			_vm->_dragonINIResource->getRecord(0)->x = 0x91;
+			_vm->_dragonINIResource->getRecord(0)->y = 0x9b;
+			_vm->_dragonINIResource->getRecord(0x123)->x = 0xc3;
+			_vm->_dragonINIResource->getRecord(0x123)->y = 0x9b;
+			_vm->_screen->loadPalette(1, _vm->_cursor->getPalette());
+			_vm->setupPalette1();
+			//TODO FUN_80035e74((uint)uVar17);
+			//TODO FUN_80035e74((uint)uVar16);
+			_vm->_dragonINIResource->setFlickerRecord(flicker);
+			_vm->_inventory->setType(originalInventoryType);
+			flicker->field_12 = local_258 + -1;
+			if (flicker->field_12 == 0) {
+				_vm->setVar(0xb, 1);
+				flicker->actorResourceId = 0xd2; //TODO is this correct?
+				_vm->_dragonINIResource->getRecord(0x120)->sceneId = 0x17;
+			}
+			uVar6->clearFlag(ACTOR_FLAG_40);
+			uVar7->clearFlag(ACTOR_FLAG_40);
+			uVar8->clearFlag(ACTOR_FLAG_40);
+			uVar9->clearFlag(ACTOR_FLAG_40);
+			uVar10->clearFlag(ACTOR_FLAG_40);
+			uVar11->clearFlag(ACTOR_FLAG_40);
+			uVar12->clearFlag(ACTOR_FLAG_40);
+			uVar13->clearFlag(ACTOR_FLAG_40);
+//			EnableVSyncEvent();
+			if (param_3 == 0) {
+//				fade_related_calls_with_1f();
+//				TODO ClearFlatShadedQuads(0);
+				uVar14->clearFlag(ACTOR_FLAG_40);
+				uVar15->clearFlag(ACTOR_FLAG_40);
+				_vm->reset_screen_maybe();
+			}
+			else {
+				_vm->reset_screen_maybe();
+				_vm->_scene->setSceneId(0x17);
+				flicker->sceneId = 0x17;
+				_vm->_scene->loadSceneData((uint)(0x17 | 0x8000),0);
+				_vm->setAllFlags(origEngineFlags & 0xfefdffff | _vm->getAllFlags() & 0x1000000 | 0x40);
+//				call_fade_related_1f();
+			}
+			return;
+		}
+		_vm->waitForFrames(1);
+		shouldExit = true;
+		/*
+		if ((DAT_80093c9c != 0) && ((engine_flags_maybe & 0x8000) == 0)) {
+			actor_update_sequenceID((uint)uVar6,0);
+			FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+			DAT_80093c9c = 0;
+		}
+		if (DAT_80093c94 != 0) {
+			local_264 = 0;
+		}
+		if (*(short *)&Actor[uVar8].field_0x7a == 1) {
+			shouldShakeScreen = true;
+			*(undefined2 *)&Actor[uVar8].field_0x7a = 0;
+			screenShakeCounter = 0;
+		}
+		if (shouldShakeScreen) {
+			uVar18 = (uint)screenShakeCounter;
+			screenShakeCounter = screenShakeCounter + 1;
+			screenShakeOffset = screenShakeTbl[uVar18];
+			if (screenShakeOffset == 0) {
+				shouldShakeScreen = false;
+			}
+		}
+		if (DAT_80093ca4 == 0) {
+			DAT_80093ca4 = DAT_80093cc8;
+		}
+		else {
+			DAT_80093ca4 = DAT_80093ca4 - 1;
+		}
+		if (DAT_80093c90 == 0) {
+			DAT_80093c90 = DAT_80093c98;
+		}
+		else {
+			DAT_80093c90 = DAT_80093c90 - 1;
+		}
+		if (DAT_80093cc4 == 0) {
+			DAT_80093cc4 = DAT_80093cc8;
+		}
+		else {
+			DAT_80093cc4 = DAT_80093cc4 - 1;
+		}
+		if (local_27a == 0) {
+			(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] & 0xfffe;
+		}
+		else {
+			(&DAT_8008316c)[(uint)uVar16 * 0xb] = local_27a + 0x27;
+			(&DAT_80083168)[(uint)uVar16 * 0xb] = local_27a + 0x27;
+			(&DAT_80083176)[(uint)uVar16 * 0xb] =
+					(ushort)(((int)((uint)local_27a - 1) >> 1) << 5) |
+					(ushort)(((int)(0x40 - (uint)local_27a) >> 1) << 10);
+			(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] | 1;
+		}
+		if (local_278 == 0) {
+			(&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] & 0xfffe;
+			if ((local_27a != 0) || (local_258 != 0)) goto LAB_800907c4;
+		}
+		else {
+			(&DAT_8008316c)[(uint)uVar17 * 0xb] = local_278 + 0x27;
+			(&DAT_80083168)[(uint)uVar17 * 0xb] = local_278 + 0x27;
+			(&DAT_80083176)[(uint)uVar17 * 0xb] =
+					(ushort)(((int)((uint)local_278 - 1) >> 1) << 5) |
+					(ushort)(((int)(0x40 - (uint)local_278) >> 1) << 10);
+			(&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] | 1;
+			LAB_800907c4:
+			if (!bVar4) {
+				FUN_8001a4e4_draw_dialogbox(4,0x14,0xd,0x16,1);
+				FUN_8001a4e4_draw_dialogbox(4,0x10,0xd,0x12,1);
+				uVar14->priorityLayer = 6;
+				uVar15->priorityLayer = 6;
+				bVar4 = true;
+			}
+		}
+		if ((((local_278 == 0) && (local_27a == 0)) && (local_258 == 0)) && (bVar4)) {
+			FUN_8001a7c4(4,0x14,0xd,0x16);
+			FUN_8001a7c4(4,0x10,0xd,0x12);
+			uVar14->priorityLayer = 0;
+			uVar15->priorityLayer = 0;
+			bVar4 = false;
+		}
+		DisableVSyncEvent();
+		actorFrameData = Actor[uVar7].frame_pointer_maybe;
+		Actor[uVar11].x_pos = Actor[uVar7].x_pos - *(short *)((int)actorFrameData + 0xe);
+		Actor[uVar10].x_pos = Actor[uVar11].x_pos;
+		sVar2 = Actor[uVar10].x_pos;
+		Actor[uVar11].y_pos = Actor[uVar7].y_pos - *(short *)((int)actorFrameData + 0x10);
+		Actor[uVar10].y_pos = Actor[uVar11].y_pos;
+		sVar3 = Actor[uVar10].y_pos;
+		actorFrameData = Actor[uVar10].frame_pointer_maybe;
+		Actor[uVar13].x_pos = sVar2 - *(short *)((int)actorFrameData + 0xe);
+		Actor[uVar12].x_pos = Actor[uVar13].x_pos;
+		Actor[uVar13].y_pos = sVar3 - *(short *)((int)actorFrameData + 0x10);
+		Actor[uVar12].y_pos = Actor[uVar13].y_pos;
+		EnableVSyncEvent();
+		local_282 = DAT_80093cc0;
+		local_286 = DAT_80093cbc;
+		local_284 = DAT_80093cb8;
+		local_288 = DAT_80093cb4;
+		if (DAT_80093c94 != 1) {
+			if (DAT_80093c94 < 2) {
+				if (DAT_80093c94 == 0) {
+					if (((local_264 < 300) || (DAT_80093ca0 != 0)) || (DAT_80093cbc == 2)) {
+						if ((local_260 != 0) && (local_260 = local_260 + -1, local_260 == 0)) {
+							if (local_262 != 0) {
+								local_262 = local_262 - 1;
+							}
+							local_260 = 300;
+						}
+					}
+					else {
+						local_264 = 0;
+						local_260 = 300;
+						playSoundFromTxtIndex(textIdTbl[local_262]);
+						actor_update_sequenceID((uint)uVar6,(uint)local_2b0[(uint)local_262 * 2]);
+						uVar18 = (uint)local_262;
+						local_262 = local_262 + 1;
+						FUN_80093aec_dialog(textIdTbl[uVar18],0x14,1);
+						if (local_262 == 3) {
+							while (((DAT_80093cb4 != 2 || (DAT_80093cbc != 0)) ||
+									((DAT_80093cb8 != 2 || (DAT_80093cc0 != 0))))) {
+								ContinueGame?();
+								if ((Actor[uVar10].flags & 4) != 0) {
+									if (DAT_80093cbc != 0) {
+										DAT_80093cbc = DAT_80093cbc - 1;
+									}
+									if (2 < DAT_80093cb4) {
+										DAT_80093cb4 = DAT_80093cb4 - 1;
+									}
+									if (DAT_80093cb4 < 2) {
+										DAT_80093cb4 = DAT_80093cb4 + 1;
+									}
+								}
+								if ((Actor[uVar12].flags & 4) != 0) {
+									if (DAT_80093cc0 != 0) {
+										DAT_80093cc0 = DAT_80093cc0 - 1;
+									}
+									if (2 < DAT_80093cb8) {
+										DAT_80093cb8 = DAT_80093cb8 - 1;
+									}
+									if (DAT_80093cb8 < 2) {
+										DAT_80093cb8 = DAT_80093cb8 + 1;
+									}
+								}
+								if (Actor[uVar10]._sequenceID !=
+									actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]) {
+									actor_update_sequenceID
+											((uint)uVar10,
+											 (uint)(ushort)actorSequenceIdTbl
+											 [(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+									actor_update_sequenceID
+											((uint)uVar11,
+											 (uint)(ushort)actorSequenceIdTbl
+											 [(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+								}
+								if (Actor[uVar12]._sequenceID !=
+									actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]) {
+									actor_update_sequenceID
+											((uint)uVar12,
+											 (uint)(ushort)actorSequenceIdTbl
+											 [(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+									actor_update_sequenceID
+											((uint)uVar13,
+											 (uint)(ushort)actorSequenceIdTbl
+											 [(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+								}
+							}
+							waitForFrames_times0x3c(2);
+							DisableVSyncEvent();
+							memset(paletteData,0,0x200);
+							Actor[uVar5].flags = Actor[uVar5].flags & 0xfbff;
+							Actor[uVar6].flags = Actor[uVar6].flags | 0x400;
+							Actor[uVar7].flags = Actor[uVar7].flags | 0x400;
+							Actor[uVar9].flags = Actor[uVar9].flags | 0x400;
+							Actor[uVar8].flags = Actor[uVar8].flags | 0x400;
+							Actor[uVar10].flags = Actor[uVar10].flags | 0x400;
+							Actor[uVar11].flags = Actor[uVar11].flags | 0x400;
+							Actor[uVar12].flags = Actor[uVar12].flags | 0x400;
+							Actor[uVar13].flags = Actor[uVar13].flags | 0x400;
+							EnableVSyncEvent();
+							_vm->waitForFrames(6);
+							actor_update_sequenceID((uint)uVar5,1);
+							do {
+							} while ((Actor[uVar5].flags & 4) == 0);
+							ContinueGame?();
+							load_palette_into_frame_buffer(0,paletteData);
+							load_palette_into_frame_buffer(1,paletteData);
+							FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,
+										 (uint)DAT_8008e874);
+							shouldExit = true;
+							goto LAB_80090188;
+						}
+					}
+					if (local_26c != 0) {
+						local_26c = local_26c + -1;
+					}
+					if (local_278 != 0) {
+						local_278 = local_278 - 1;
+					}
+					if (local_27a != 0) {
+						local_27a = local_27a - 1;
+					}
+					local_268 = 2;
+					uVar18 = IsPressedLeft(0);
+					if ((uVar18 & 0xffff) != 0) {
+						local_268 = 1;
+					}
+					uVar18 = FUN_80093520();
+					if ((uVar18 & 0xffff) != 0) {
+						local_268 = local_268 - 1;
+					}
+					uVar18 = IsPressedRight(0);
+					if ((uVar18 & 0xffff) != 0) {
+						local_268 = local_268 + 1;
+					}
+					uVar18 = FUN_80093248();
+					if ((uVar18 & 0xffff) != 0) {
+						local_268 = local_268 + 1;
+					}
+					if (Actor[uVar7]._sequenceID != local_268) {
+						actor_update_sequenceID((uint)uVar7,(uint)local_268);
+					}
+					if ((Actor[uVar10].flags & 4) != 0) {
+						uVar18 = IsPressedRight(0);
+						if (((uVar18 & 0xffff) != 0) && (local_288 != 0)) {
+							local_288 = local_288 - 1;
+						}
+						uVar18 = IsPressedLeft(0);
+						if (((uVar18 & 0xffff) != 0) && (local_288 < 4)) {
+							local_288 = local_288 + 1;
+						}
+						uVar18 = IsPressedLeft(0);
+						if ((((uVar18 & 0xffff) == 0) && (uVar18 = IsPressedRight(0), (uVar18 & 0xffff) == 0))
+							&& (local_288 != 2)) {
+							if (local_288 < 2) {
+								local_288 = local_288 + 1;
+							}
+							else {
+								local_288 = local_288 - 1;
+							}
+						}
+						iVar20 = IsButtonBeingPressed((uint)buttonMap_Action,0);
+						if ((iVar20 == 0) || (local_26c != 0)) {
+							if (local_286 != 0) {
+								local_286 = local_286 - 1;
+							}
+						}
+						else {
+							if (local_286 < 2) {
+								local_286 = local_286 + 1;
+							}
+						}
+					}
+					if (local_286 == 2) {
+						if (local_256 < 0x14) {
+							local_256 = local_256 + 1;
+						}
+						else {
+							local_256 = 0;
+						}
+					}
+					if (local_256 < 0x14) {
+						local_264 = local_264 + 1;
+					}
+					else {
+						local_264 = 0;
+					}
+					if ((Actor[uVar12].flags & 4) != 0) {
+						uVar18 = FUN_80093248();
+						if (((uVar18 & 0xffff) != 0) && (local_284 != 0)) {
+							local_284 = local_284 - 1;
+						}
+						uVar18 = FUN_80093520();
+						if (((uVar18 & 0xffff) != 0) && (local_284 < 4)) {
+							local_284 = local_284 + 1;
+						}
+						uVar18 = FUN_80093520();
+						if ((((uVar18 & 0xffff) == 0) && (uVar18 = FUN_80093248(), (uVar18 & 0xffff) == 0)) &&
+							(local_284 != 2)) {
+							if (local_284 < 2) {
+								local_284 = local_284 + 1;
+							}
+							else {
+								local_284 = local_284 - 1;
+							}
+						}
+						uVar18 = FUN_80093800();
+						if (((uVar18 & 0xffff) == 0) || (local_26c != 0)) {
+							if (local_282 != 0) {
+								local_282 = local_282 - 1;
+							}
+						}
+						else {
+							if (local_282 < 2) {
+								local_282 = local_282 + 1;
+							}
+						}
+					}
+					if (((local_286 == 2) && (local_282 == 2)) && (local_288 == local_284)) {
+						if ((DAT_80093cbc == 2) && (DAT_80093cc0 != 2)) {
+							local_258 = 2;
+						}
+						else {
+							if ((DAT_80093cbc == 2) || (DAT_80093cc0 != 2)) {
+								local_288 = DAT_80093cb4;
+								local_286 = DAT_80093cbc;
+								local_284 = DAT_80093cb8;
+								local_282 = DAT_80093cc0;
+							}
+							else {
+								local_258 = 1;
+							}
+						}
+					}
+					if (local_258 == 0) {
+						if ((local_286 != DAT_80093cbc) || (local_288 != DAT_80093cb4)) {
+							DAT_80093cb4 = local_288;
+							DAT_80093cbc = local_286;
+							actor_update_sequenceID
+									((uint)uVar10,
+									 (uint)(ushort)actorSequenceIdTbl[(uint)local_288 * 3 + (uint)local_286]);
+							actor_update_sequenceID
+									((uint)uVar11,
+									 (uint)(ushort)actorSequenceIdTbl
+									 [(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+						}
+						if ((local_282 != DAT_80093cc0) || (local_284 != DAT_80093cb8)) {
+							DAT_80093cb8 = local_284;
+							DAT_80093cc0 = local_282;
+							actor_update_sequenceID
+									((uint)uVar12,
+									 (uint)(ushort)actorSequenceIdTbl[(uint)local_284 * 3 + (uint)local_282]);
+							actor_update_sequenceID
+									((uint)uVar13,
+									 (uint)(ushort)actorSequenceIdTbl
+									 [(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+						}
+					}
+					else {
+						if (local_258 == 1) {
+							actor_update_sequenceID((uint)uVar6,1);
+							actor_update_sequenceID((uint)uVar8,1);
+							if (local_288 == 2) {
+								local_28 = 1;
+							}
+							else {
+								if (local_288 < 3) {
+									if (local_288 == 0) {
+										local_28 = 0;
+									}
+									else {
+										LAB_800926a4:
+										local_28 = 2;
+									}
+								}
+								else {
+									if (local_288 != 4) goto LAB_800926a4;
+									local_28 = 2;
+								}
+							}
+						}
+						else {
+							actor_update_sequenceID((uint)uVar6,3);
+							actor_update_sequenceID((uint)uVar9,1);
+							if (local_284 == 2) {
+								local_28 = 4;
+							}
+							else {
+								if (local_284 < 3) {
+									if (local_284 == 0) {
+										local_28 = 3;
+									}
+									else {
+										LAB_80092754:
+										local_28 = 4;
+									}
+								}
+								else {
+									if (local_284 != 4) goto LAB_80092754;
+									local_28 = 5;
+								}
+							}
+						}
+						Actor[uVar12].flags = Actor[uVar12].flags | 0x400;
+						Actor[uVar13].flags = Actor[uVar13].flags | 0x400;
+						actor_update_sequenceID((uint)uVar10,(uint)local_28 + 0xf);
+						actor_update_sequenceID((uint)uVar11,(uint)local_28 + 0xf);
+						DAT_80093c94 = 1;
+						DAT_80093c90 = 0x1e;
+					}
+				}
+			}
+			else {
+				if (DAT_80093c94 == 2) {
+					Actor[uVar12].flags = Actor[uVar12].flags | 0x1000;
+					Actor[uVar13].flags = Actor[uVar13].flags | 0x1000;
+					Actor[uVar10].flags = Actor[uVar10].flags | 0x1000;
+					Actor[uVar11].flags = Actor[uVar11].flags | 0x1000;
+					screenShakeOffset = 0;
+					if (local_258 == 1) {
+						playSoundFromTxtIndex(DAT_80063ad0);
+						actor_update_sequenceID((uint)uVar6,9);
+						FUN_80093aec_dialog(DAT_80063ad0,0x14,1);
+						do {
+						} while ((engine_flags_maybe & 0x8000) != 0);
+						actor_update_sequenceID((uint)uVar6,2);
+						actor_update_sequenceID((uint)uVar9,3);
+					}
+					else {
+						playSoundFromTxtIndex(DAT_80063ad4);
+						actor_update_sequenceID((uint)uVar6,10);
+						FUN_80093aec_dialog(DAT_80063ad4,0x14,1);
+						actor_update_sequenceID((uint)uVar9,2);
+						do {
+						} while ((engine_flags_maybe & 0x8000) != 0);
+						actor_update_sequenceID((uint)uVar6,4);
+					}
+					waitForFrames_times0x3c(2);
+					shouldExit = true;
+				}
+			}
+			goto LAB_80090188;
+		}
+		if (local_272 == 0) {
+			local_272 = 1;
+			if (local_27a != 0) {
+				local_27a = local_27a - 1;
+			}
+			if (local_278 != 0) {
+				local_278 = local_278 - 1;
+			}
+		}
+		else {
+			local_272 = local_272 + -1;
+		}
+		uVar18 = PressedThisFrameR2(0);
+		uVar19 = PressedThisFrameR1(0);
+		if (((uVar18 | uVar19) & 0xffff) != 0) {
+			local_27a = local_27a + 4;
+		}
+		uVar18 = PressedThisFrameL2(0);
+		uVar19 = PressedThisFrameL1(0);
+		if (((uVar18 | uVar19) & 0xffff) != 0) {
+			local_27a = local_27a + 4;
+		}
+		uVar18 = FUN_80093990();
+		if ((uVar18 & 0xffff) != 0) {
+			if (param_1 == 1) {
+				local_278 = local_278 + 4;
+			}
+			else {
+				local_278 = local_278 + 6;
+			}
+		}
+		uVar18 = FUN_80093a30();
+		if ((uVar18 & 0xffff) != 0) {
+			if (param_1 == 1) {
+				local_278 = local_278 + 4;
+			}
+			else {
+				local_278 = local_278 + 6;
+			}
+		}
+		if ((0x3f < local_278) || (0x3f < local_27a)) {
+			Actor[uVar6].flags = Actor[uVar6].flags | 0x1000;
+			Actor[uVar8].flags = Actor[uVar8].flags | 0x1000;
+			Actor[uVar9].flags = Actor[uVar9].flags | 0x1000;
+			if (0x40 < local_27a) {
+				local_27a = 0x40;
+			}
+			if (0x40 < local_278) {
+				local_278 = 0x40;
+			}
+			if (((local_278 == local_27a) || ((local_258 == 2 && (local_278 < local_27a)))) ||
+				((local_258 == 1 && (local_27a < local_278)))) {
+				if (local_258 == 1) {
+					playSoundFromTxtIndex(DAT_80063ad8);
+					actor_update_sequenceID((uint)uVar6,0xb);
+					FUN_80093aec_dialog(DAT_80063ad8,0x14,1);
+				}
+				else {
+					playSoundFromTxtIndex(DAT_80063adc);
+					actor_update_sequenceID((uint)uVar6,0xc);
+					FUN_80093aec_dialog(DAT_80063adc,0x14,1);
+				}
+				local_258 = 0;
+				DAT_80093cb4 = 2;
+				DAT_80093cbc = 1;
+				DAT_80093cb8 = 0;
+				DAT_80093cc0 = 1;
+				Actor[uVar12].flags = Actor[uVar12].flags & 0xfbff;
+				Actor[uVar13].flags = Actor[uVar13].flags & 0xfbff;
+				actor_update_sequenceID
+						((uint)uVar10,
+						 (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+				actor_update_sequenceID
+						((uint)uVar11,
+						 (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+				actor_update_sequenceID
+						((uint)uVar12,
+						 (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+				actor_update_sequenceID
+						((uint)uVar13,
+						 (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+				DAT_80093c94 = 0;
+				local_26c = 0x1e;
+			}
+			else {
+				DAT_80093c94 = 2;
+			}
+		}
+		 */
+	} while( true );
+
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame2.h b/engines/dragons/minigame2.h
index 707516ed9d..24a9d7dbad 100644
--- a/engines/dragons/minigame2.h
+++ b/engines/dragons/minigame2.h
@@ -31,10 +31,27 @@ class DragonsEngine;
 class Minigame2 {
 private:
 	DragonsEngine *_vm;
+	uint16 DAT_80093cb4;
+	uint16 DAT_80093cbc;
+	uint16 DAT_80093cb8;
+	uint16 DAT_80093cc0;
+
+	uint16 DAT_80093ca4;
+	uint16 DAT_80093c90;
+	uint16 DAT_80093c94;
+
+	uint16 DAT_80093cac;
+	uint16 DAT_80093cb0;
+	uint16 DAT_80093c9c;
+
+	uint16 DAT_80093c98;
+	uint16 DAT_80093ca0;
+	uint16 DAT_80093cc4;
+	uint16 DAT_80093cc8;
 public:
 	Minigame2(DragonsEngine *vm);
 
-	void run();
+	void run(int16 param_1, uint16 param_2, int16 param_3);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index b57c88cebd..7e4810c3e6 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -210,7 +210,7 @@ void SpecialOpcodes::spcCatapultMiniGame() {
 
 void SpecialOpcodes::spcThumbWrestlingMiniGame() {
 	Minigame2 minigame2(_vm);
-	minigame2.run();
+	minigame2.run(0,1,1);
 }
 
 void SpecialOpcodes::spcClearEngineFlag10() {
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index a1e41216a5..347c60e8e8 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -48,6 +48,11 @@ struct TalkDialogEntry {
 
 
 class Talk {
+public:
+	uint32 DAT_8008e7e8_dialogBox_x1;
+	uint32 DAT_8008e844_dialogBox_y1;
+	uint32 DAT_8008e848_dialogBox_x2;
+	uint32 DAT_8008e874_dialogBox_y2;
 private:
 	DragonsEngine *_vm;
 	BigfileArchive *_bigfileArchive;
@@ -57,10 +62,6 @@ private:
 	uint8 DAT_800726ec_tfont_field0;
 	uint8 DAT_800726f0_tfont_field2;
 
-	uint32 DAT_8008e7e8_dialogBox_x1;
-	uint32 DAT_8008e844_dialogBox_y1;
-	uint32 DAT_8008e848_dialogBox_x2;
-	uint32 DAT_8008e874_dialogBox_y2;
 	uint8 DAT_800633f8_talkDialogFlag;
 
 public:


Commit: 71817f7b1effe432ce3c6981fb2ac8410bd0c59d
    https://github.com/scummvm/scummvm/commit/71817f7b1effe432ce3c6981fb2ac8410bd0c59d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on mini game 2

Changed paths:
    engines/dragons/actorresource.cpp
    engines/dragons/actorresource.h
    engines/dragons/minigame2.cpp
    engines/dragons/minigame2.h
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 223842f7a9..5acc73428c 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -167,6 +167,8 @@ ActorFrame *ActorResource::loadFrameHeader(uint16 frameOffset) {
 	frame->frameDataOffset = &_data[frameDataOffset];
 	frame->flags = stream->readUint16LE();
 	frame->field_c = stream->readUint16LE();
+	frame->field_e = stream->readSint16LE();
+	frame->field_10 = stream->readSint16LE();
 
 	delete stream;
 	return frame;
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index 228c0a89a4..335accef6f 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -37,6 +37,8 @@ struct ActorFrame {
 	byte *frameDataOffset;
 	uint16 flags;
 	uint16 field_c;
+	int16 field_e;
+	int16 field_10;
 };
 
 enum FrameFlags {
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 3a0d57702b..212e50094b 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -48,12 +48,12 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	DragonINI *flicker;
 	uint32 origEngineFlags;
 	Actor *uVar5;
-	Actor *uVar6;
-	Actor *uVar7;
+	Actor *loungealotHeadActor;
+	Actor *loungealotLeftUpperArm;
 	Actor *uVar8;
-	Actor *uVar9;
-	Actor *uVar10;
-	Actor *uVar11;
+	Actor *loungealotRightArm;
+	Actor *flickerArm;
+	Actor *loungealotThumb;
 	Actor *uVar12;
 	Actor *uVar13;
 	Actor *uVar14;
@@ -174,46 +174,46 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	_vm->_screen->updatePaletteTransparency(1,0x40,0x7f,true);
 
 	uVar5 = _vm->_actorManager->loadActor(0x11,0,0,0,6);
-	uVar6 = _vm->_actorManager->loadActor(0xd,0,0x7d,199,4);
-	uVar7 = _vm->_actorManager->loadActor(0xb,2,0x7d,199,4);
+	loungealotHeadActor = _vm->_actorManager->loadActor(0xd, 0, 0x7d, 199, 4);
+	loungealotLeftUpperArm = _vm->_actorManager->loadActor(0xb, 2, 0x7d, 199, 4);
 	uVar8 = _vm->_actorManager->loadActor(0xf,0,0x7d,199,4);
-	uVar9 = _vm->_actorManager->loadActor(0x10,0,0x7d,199,4);
-	actorFrameData = uVar7->frame->frameDataOffset;
-	uVar10 = _vm->_actorManager->loadActor(9,(uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
-								uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe),
-								uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10),4);
-	uVar11 = _vm->_actorManager->loadActor(0x12,(uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
-								uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe),
-								uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10),4);
-	actorFrameData = uVar10->frame->frameDataOffset;
-	uVar12 = _vm->_actorManager->loadActor(10,(uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
-			uVar10->x_pos - READ_LE_INT16(actorFrameData + 0xe),
-			uVar10->y_pos - READ_LE_INT16(actorFrameData + 0x10),4);
-	uVar13 = _vm->_actorManager->loadActor(0x13,(uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
-			uVar10->x_pos - READ_LE_INT16(actorFrameData + 0xe),
-			uVar10->y_pos - READ_LE_INT16(actorFrameData + 0x10),4);
+	loungealotRightArm = _vm->_actorManager->loadActor(0x10, 0, 0x7d, 199, 4);
+	actorFrameData = loungealotLeftUpperArm->frame->frameDataOffset;
+	flickerArm = _vm->_actorManager->loadActor(9, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
+											   loungealotLeftUpperArm->x_pos - READ_LE_INT16(actorFrameData + 0xe),
+											   loungealotLeftUpperArm->y_pos - READ_LE_INT16(actorFrameData + 0x10), 4);
+	loungealotThumb = _vm->_actorManager->loadActor(0x12, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
+													loungealotLeftUpperArm->x_pos - READ_LE_INT16(actorFrameData + 0xe),
+													loungealotLeftUpperArm->y_pos - READ_LE_INT16(actorFrameData + 0x10), 4);
+	actorFrameData = flickerArm->frame->frameDataOffset;
+	uVar12 = _vm->_actorManager->loadActor(10, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
+										   flickerArm->x_pos - READ_LE_INT16(actorFrameData + 0xe),
+										   flickerArm->y_pos - READ_LE_INT16(actorFrameData + 0x10), 4);
+	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
+										   flickerArm->x_pos - READ_LE_INT16(actorFrameData + 0xe),
+										   flickerArm->y_pos - READ_LE_INT16(actorFrameData + 0x10), 4);
 	uVar14 = _vm->_actorManager->loadActor(0x27,0,0x10,0xac,4);
 	uVar15 = _vm->_actorManager->loadActor(0x27,1,0x10,0x8c,4);
 	uVar5->setFlag(ACTOR_FLAG_100);
-	uVar6->setFlag(ACTOR_FLAG_100);
-	uVar7->setFlag(ACTOR_FLAG_100);
+	loungealotHeadActor->setFlag(ACTOR_FLAG_100);
+	loungealotLeftUpperArm->setFlag(ACTOR_FLAG_100);
 	uVar8->setFlag(ACTOR_FLAG_100);
-	uVar9->setFlag(ACTOR_FLAG_100);
-	uVar10->setFlag(ACTOR_FLAG_100);
-	uVar11->setFlag(ACTOR_FLAG_100);
+	loungealotRightArm->setFlag(ACTOR_FLAG_100);
+	flickerArm->setFlag(ACTOR_FLAG_100);
+	loungealotThumb->setFlag(ACTOR_FLAG_100);
 	uVar12->setFlag(ACTOR_FLAG_100);
 	uVar13->setFlag(ACTOR_FLAG_100);
 	uVar14->setFlag(ACTOR_FLAG_100);
 	uVar15->setFlag(ACTOR_FLAG_100);
 
 	uVar5->priorityLayer = 6;
-	uVar10->priorityLayer = 5;
+	flickerArm->priorityLayer = 5;
 	uVar12->priorityLayer = 5;
-	uVar11->priorityLayer = 4;
+	loungealotThumb->priorityLayer = 4;
 	uVar13->priorityLayer = 3;
-	uVar9->priorityLayer = 3;
-	uVar7->priorityLayer = 2;
-	uVar6->priorityLayer = 2;
+	loungealotRightArm->priorityLayer = 3;
+	loungealotLeftUpperArm->priorityLayer = 2;
+	loungealotHeadActor->priorityLayer = 2;
 	uVar8->priorityLayer = 1;
 	uVar14->priorityLayer = 0;
 	uVar15->priorityLayer = 0;
@@ -223,34 +223,34 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 //	(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] & 0xfffe;
 //	(&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] & 0xfffe;
 //	EnableVSyncEvent();
-	uVar6->setFlag(ACTOR_FLAG_1);
-	uVar7->setFlag(ACTOR_FLAG_1);
+	loungealotHeadActor->setFlag(ACTOR_FLAG_1);
+	loungealotLeftUpperArm->setFlag(ACTOR_FLAG_1);
 	uVar8->setFlag(ACTOR_FLAG_1);
-	uVar9->setFlag(ACTOR_FLAG_1);
-	uVar10->setFlag(ACTOR_FLAG_1);
-	uVar11->setFlag(ACTOR_FLAG_1);
+	loungealotRightArm->setFlag(ACTOR_FLAG_1);
+	flickerArm->setFlag(ACTOR_FLAG_1);
+	loungealotThumb->setFlag(ACTOR_FLAG_1);
 	uVar12->setFlag(ACTOR_FLAG_1);
 	uVar13->setFlag(ACTOR_FLAG_1);
-	uVar10->waitUntilFlag8And4AreSet();
+	flickerArm->waitUntilFlag8And4AreSet();
 	uVar12->waitUntilFlag8And4AreSet();
-	uVar11->waitUntilFlag8And4AreSet();
+	loungealotThumb->waitUntilFlag8And4AreSet();
 	uVar13->waitUntilFlag8And4AreSet();
-	uVar7->waitUntilFlag8And4AreSet();
-	uVar9->waitUntilFlag8And4AreSet();
-	uVar6->waitUntilFlag8And4AreSet();
+	loungealotLeftUpperArm->waitUntilFlag8And4AreSet();
+	loungealotRightArm->waitUntilFlag8And4AreSet();
+	loungealotHeadActor->waitUntilFlag8And4AreSet();
 	uVar8->waitUntilFlag8And4AreSet();
 
 	uVar5->setFlag(ACTOR_FLAG_400);
-	actorFrameData = uVar7->frame->frameDataOffset;
-	uVar10->x_pos = uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe);
-	uVar10->y_pos = uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10);
-	uVar11->x_pos = uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe);
-	uVar11->y_pos = uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10);
-	actorFrameData = uVar10->frame->frameDataOffset;
-	uVar12->x_pos = uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe);
-	uVar12->y_pos = uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10);
-	uVar13->x_pos = uVar7->x_pos - READ_LE_INT16(actorFrameData + 0xe);
-	uVar13->y_pos = uVar7->y_pos - READ_LE_INT16(actorFrameData + 0x10);
+	actorFrameData = loungealotLeftUpperArm->frame->frameDataOffset;
+	flickerArm->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e; //READ_LE_INT16(actorFrameData + 0xe);
+	flickerArm->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10; //READ_LE_INT16(actorFrameData + 0x10);
+	loungealotThumb->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e; //READ_LE_INT16(actorFrameData + 0xe);
+	loungealotThumb->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10; //READ_LE_INT16(actorFrameData + 0x10);
+	actorFrameData = flickerArm->frame->frameDataOffset;
+	uVar12->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e; //READ_LE_INT16(actorFrameData + 0xe);
+	uVar12->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10; //READ_LE_INT16(actorFrameData + 0x10);
+	uVar13->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e; //READ_LE_INT16(actorFrameData + 0xe);
+	uVar13->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10; //READ_LE_INT16(actorFrameData + 0x10);
 	_vm->waitForFrames(200);
 	// call_fade_related_1f();
 
@@ -276,12 +276,12 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				flicker->actorResourceId = 0xd2; //TODO is this correct?
 				_vm->_dragonINIResource->getRecord(0x120)->sceneId = 0x17;
 			}
-			uVar6->clearFlag(ACTOR_FLAG_40);
-			uVar7->clearFlag(ACTOR_FLAG_40);
+			loungealotHeadActor->clearFlag(ACTOR_FLAG_40);
+			loungealotLeftUpperArm->clearFlag(ACTOR_FLAG_40);
 			uVar8->clearFlag(ACTOR_FLAG_40);
-			uVar9->clearFlag(ACTOR_FLAG_40);
-			uVar10->clearFlag(ACTOR_FLAG_40);
-			uVar11->clearFlag(ACTOR_FLAG_40);
+			loungealotRightArm->clearFlag(ACTOR_FLAG_40);
+			flickerArm->clearFlag(ACTOR_FLAG_40);
+			loungealotThumb->clearFlag(ACTOR_FLAG_40);
 			uVar12->clearFlag(ACTOR_FLAG_40);
 			uVar13->clearFlag(ACTOR_FLAG_40);
 //			EnableVSyncEvent();
@@ -303,28 +303,26 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			return;
 		}
 		_vm->waitForFrames(1);
-		shouldExit = true;
-		/*
-		if ((DAT_80093c9c != 0) && ((engine_flags_maybe & 0x8000) == 0)) {
-			actor_update_sequenceID((uint)uVar6,0);
-			FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+
+		if ((DAT_80093c9c != 0) && !_vm->isFlagSet(ENGINE_FLAG_8000)) {
+			loungealotHeadActor->updateSequence(0);
+			//TODO _vm->_talk->FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
 			DAT_80093c9c = 0;
 		}
 		if (DAT_80093c94 != 0) {
 			local_264 = 0;
 		}
-		if (*(short *)&Actor[uVar8].field_0x7a == 1) {
+		if (uVar8->field_7a == 1) {
 			shouldShakeScreen = true;
-			*(undefined2 *)&Actor[uVar8].field_0x7a = 0;
+			uVar8->field_7a = 0;
 			screenShakeCounter = 0;
 		}
 		if (shouldShakeScreen) {
-			uVar18 = (uint)screenShakeCounter;
-			screenShakeCounter = screenShakeCounter + 1;
-			screenShakeOffset = screenShakeTbl[uVar18];
-			if (screenShakeOffset == 0) {
+			_vm->_screen->setScreenShakeOffset(screenShakeTbl[screenShakeCounter]);
+			if (screenShakeTbl[screenShakeCounter] == 0) {
 				shouldShakeScreen = false;
 			}
+			screenShakeCounter = screenShakeCounter + 1;
 		}
 		if (DAT_80093ca4 == 0) {
 			DAT_80093ca4 = DAT_80093cc8;
@@ -344,6 +342,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		else {
 			DAT_80093cc4 = DAT_80093cc4 - 1;
 		}
+		/*
 		if (local_27a == 0) {
 			(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] & 0xfffe;
 		}
@@ -382,20 +381,19 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			uVar15->priorityLayer = 0;
 			bVar4 = false;
 		}
-		DisableVSyncEvent();
-		actorFrameData = Actor[uVar7].frame_pointer_maybe;
-		Actor[uVar11].x_pos = Actor[uVar7].x_pos - *(short *)((int)actorFrameData + 0xe);
-		Actor[uVar10].x_pos = Actor[uVar11].x_pos;
-		sVar2 = Actor[uVar10].x_pos;
-		Actor[uVar11].y_pos = Actor[uVar7].y_pos - *(short *)((int)actorFrameData + 0x10);
-		Actor[uVar10].y_pos = Actor[uVar11].y_pos;
-		sVar3 = Actor[uVar10].y_pos;
-		actorFrameData = Actor[uVar10].frame_pointer_maybe;
-		Actor[uVar13].x_pos = sVar2 - *(short *)((int)actorFrameData + 0xe);
-		Actor[uVar12].x_pos = Actor[uVar13].x_pos;
-		Actor[uVar13].y_pos = sVar3 - *(short *)((int)actorFrameData + 0x10);
-		Actor[uVar12].y_pos = Actor[uVar13].y_pos;
-		EnableVSyncEvent();
+*/
+		//DisableVSyncEvent();
+		loungealotThumb->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
+		flickerArm->x_pos = loungealotThumb->x_pos;
+		sVar2 = flickerArm->x_pos;
+		loungealotThumb->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10;
+		flickerArm->y_pos = loungealotThumb->y_pos;
+		sVar3 = flickerArm->y_pos;
+		uVar13->x_pos = sVar2 - flickerArm->frame->field_e;
+		uVar12->x_pos = uVar13->x_pos;
+		uVar13->y_pos = sVar3 - flickerArm->frame->field_10;
+		uVar12->y_pos = uVar13->y_pos;
+//		EnableVSyncEvent();
 		local_282 = DAT_80093cc0;
 		local_286 = DAT_80093cbc;
 		local_284 = DAT_80093cb8;
@@ -414,16 +412,16 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					else {
 						local_264 = 0;
 						local_260 = 300;
-						playSoundFromTxtIndex(textIdTbl[local_262]);
-						actor_update_sequenceID((uint)uVar6,(uint)local_2b0[(uint)local_262 * 2]);
+//						playSoundFromTxtIndex(textIdTbl[local_262]);
+						loungealotHeadActor->updateSequence((uint)local_2b0[(uint)local_262 * 2]);
 						uVar18 = (uint)local_262;
 						local_262 = local_262 + 1;
 						FUN_80093aec_dialog(textIdTbl[uVar18],0x14,1);
 						if (local_262 == 3) {
 							while (((DAT_80093cb4 != 2 || (DAT_80093cbc != 0)) ||
 									((DAT_80093cb8 != 2 || (DAT_80093cc0 != 0))))) {
-								ContinueGame?();
-								if ((Actor[uVar10].flags & 4) != 0) {
+								_vm->waitForFrames(1);
+								if (flickerArm->isFlagSet(ACTOR_FLAG_4)) {
 									if (DAT_80093cbc != 0) {
 										DAT_80093cbc = DAT_80093cbc - 1;
 									}
@@ -434,7 +432,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 										DAT_80093cb4 = DAT_80093cb4 + 1;
 									}
 								}
-								if ((Actor[uVar12].flags & 4) != 0) {
+								if ((uVar12->flags & 4) != 0) {
 									if (DAT_80093cc0 != 0) {
 										DAT_80093cc0 = DAT_80093cc0 - 1;
 									}
@@ -445,51 +443,37 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 										DAT_80093cb8 = DAT_80093cb8 + 1;
 									}
 								}
-								if (Actor[uVar10]._sequenceID !=
-									actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]) {
-									actor_update_sequenceID
-											((uint)uVar10,
-											 (uint)(ushort)actorSequenceIdTbl
-											 [(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-									actor_update_sequenceID
-											((uint)uVar11,
-											 (uint)(ushort)actorSequenceIdTbl
-											 [(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+								if (flickerArm->_sequenceID != actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]) {
+									flickerArm->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+									loungealotThumb->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
 								}
-								if (Actor[uVar12]._sequenceID !=
+								if (uVar12->_sequenceID !=
 									actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]) {
-									actor_update_sequenceID
-											((uint)uVar12,
-											 (uint)(ushort)actorSequenceIdTbl
-											 [(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
-									actor_update_sequenceID
-											((uint)uVar13,
-											 (uint)(ushort)actorSequenceIdTbl
-											 [(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+									uVar12->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+									uVar13->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
 								}
 							}
-							waitForFrames_times0x3c(2);
-							DisableVSyncEvent();
+							_vm->waitForFrames(2 * 0x3c);
+//							DisableVSyncEvent();
 							memset(paletteData,0,0x200);
-							Actor[uVar5].flags = Actor[uVar5].flags & 0xfbff;
-							Actor[uVar6].flags = Actor[uVar6].flags | 0x400;
-							Actor[uVar7].flags = Actor[uVar7].flags | 0x400;
-							Actor[uVar9].flags = Actor[uVar9].flags | 0x400;
-							Actor[uVar8].flags = Actor[uVar8].flags | 0x400;
-							Actor[uVar10].flags = Actor[uVar10].flags | 0x400;
-							Actor[uVar11].flags = Actor[uVar11].flags | 0x400;
-							Actor[uVar12].flags = Actor[uVar12].flags | 0x400;
-							Actor[uVar13].flags = Actor[uVar13].flags | 0x400;
-							EnableVSyncEvent();
+							uVar5->flags = uVar5->flags & 0xfbff;
+							loungealotHeadActor->setFlag(ACTOR_FLAG_400);
+							loungealotLeftUpperArm->setFlag(ACTOR_FLAG_400);
+							loungealotRightArm->setFlag(ACTOR_FLAG_400);
+							uVar8->flags = uVar8->flags | 0x400;
+							flickerArm->setFlag(ACTOR_FLAG_400);
+							loungealotThumb->setFlag(ACTOR_FLAG_400);
+							uVar12->setFlag(ACTOR_FLAG_400);
+							uVar13->setFlag(ACTOR_FLAG_400);
+//							EnableVSyncEvent();
 							_vm->waitForFrames(6);
-							actor_update_sequenceID((uint)uVar5,1);
-							do {
-							} while ((Actor[uVar5].flags & 4) == 0);
-							ContinueGame?();
-							load_palette_into_frame_buffer(0,paletteData);
-							load_palette_into_frame_buffer(1,paletteData);
-							FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,
-										 (uint)DAT_8008e874);
+							uVar5->updateSequence(1);
+							uVar5->waitUntilFlag4IsSet();
+							_vm->waitForFrames(1);
+							_vm->_screen->loadPalette(0,paletteData);
+							_vm->_screen->loadPalette(1,paletteData);
+//	TODO						FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,
+//										 (uint)DAT_8008e874);
 							shouldExit = true;
 							goto LAB_80090188;
 						}
@@ -504,37 +488,29 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						local_27a = local_27a - 1;
 					}
 					local_268 = 2;
-					uVar18 = IsPressedLeft(0);
-					if ((uVar18 & 0xffff) != 0) {
+					if (_vm->isLeftKeyPressed()) {
 						local_268 = 1;
 					}
-					uVar18 = FUN_80093520();
-					if ((uVar18 & 0xffff) != 0) {
+					if (FUN_80093520()) {
 						local_268 = local_268 - 1;
 					}
-					uVar18 = IsPressedRight(0);
-					if ((uVar18 & 0xffff) != 0) {
+					if (_vm->isRightKeyPressed()) {
 						local_268 = local_268 + 1;
 					}
-					uVar18 = FUN_80093248();
-					if ((uVar18 & 0xffff) != 0) {
+					if (FUN_80093248()) {
 						local_268 = local_268 + 1;
 					}
-					if (Actor[uVar7]._sequenceID != local_268) {
-						actor_update_sequenceID((uint)uVar7,(uint)local_268);
+					if (loungealotLeftUpperArm->_sequenceID != local_268) {
+						loungealotLeftUpperArm->updateSequence(local_268);
 					}
-					if ((Actor[uVar10].flags & 4) != 0) {
-						uVar18 = IsPressedRight(0);
-						if (((uVar18 & 0xffff) != 0) && (local_288 != 0)) {
+					if ((flickerArm->flags & 4) != 0) {
+						if (_vm->isRightKeyPressed() && (local_288 != 0)) {
 							local_288 = local_288 - 1;
 						}
-						uVar18 = IsPressedLeft(0);
-						if (((uVar18 & 0xffff) != 0) && (local_288 < 4)) {
+						if (_vm->isLeftKeyPressed() && (local_288 < 4)) {
 							local_288 = local_288 + 1;
 						}
-						uVar18 = IsPressedLeft(0);
-						if ((((uVar18 & 0xffff) == 0) && (uVar18 = IsPressedRight(0), (uVar18 & 0xffff) == 0))
-							&& (local_288 != 2)) {
+						if ((!_vm->isLeftKeyPressed() && !_vm->isRightKeyPressed()) && (local_288 != 2)) {
 							if (local_288 < 2) {
 								local_288 = local_288 + 1;
 							}
@@ -542,8 +518,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 								local_288 = local_288 - 1;
 							}
 						}
-						iVar20 = IsButtonBeingPressed((uint)buttonMap_Action,0);
-						if ((iVar20 == 0) || (local_26c != 0)) {
+						if (!_vm->isActionButtonPressed() || (local_26c != 0)) {
 							if (local_286 != 0) {
 								local_286 = local_286 - 1;
 							}
@@ -568,18 +543,14 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					else {
 						local_264 = 0;
 					}
-					if ((Actor[uVar12].flags & 4) != 0) {
-						uVar18 = FUN_80093248();
-						if (((uVar18 & 0xffff) != 0) && (local_284 != 0)) {
+					if ((uVar12->flags & 4) != 0) {
+						if (FUN_80093248() && (local_284 != 0)) {
 							local_284 = local_284 - 1;
 						}
-						uVar18 = FUN_80093520();
-						if (((uVar18 & 0xffff) != 0) && (local_284 < 4)) {
+						if (FUN_80093520() && (local_284 < 4)) {
 							local_284 = local_284 + 1;
 						}
-						uVar18 = FUN_80093520();
-						if ((((uVar18 & 0xffff) == 0) && (uVar18 = FUN_80093248(), (uVar18 & 0xffff) == 0)) &&
-							(local_284 != 2)) {
+						if ((!FUN_80093520() && !FUN_80093248()) && (local_284 != 2)) {
 							if (local_284 < 2) {
 								local_284 = local_284 + 1;
 							}
@@ -587,8 +558,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 								local_284 = local_284 - 1;
 							}
 						}
-						uVar18 = FUN_80093800();
-						if (((uVar18 & 0xffff) == 0) || (local_26c != 0)) {
+						if (!FUN_80093800() || (local_26c != 0)) {
 							if (local_282 != 0) {
 								local_282 = local_282 - 1;
 							}
@@ -619,30 +589,20 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						if ((local_286 != DAT_80093cbc) || (local_288 != DAT_80093cb4)) {
 							DAT_80093cb4 = local_288;
 							DAT_80093cbc = local_286;
-							actor_update_sequenceID
-									((uint)uVar10,
-									 (uint)(ushort)actorSequenceIdTbl[(uint)local_288 * 3 + (uint)local_286]);
-							actor_update_sequenceID
-									((uint)uVar11,
-									 (uint)(ushort)actorSequenceIdTbl
-									 [(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+							flickerArm->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)local_288 * 3 + (uint)local_286]);
+							loungealotThumb->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
 						}
 						if ((local_282 != DAT_80093cc0) || (local_284 != DAT_80093cb8)) {
 							DAT_80093cb8 = local_284;
 							DAT_80093cc0 = local_282;
-							actor_update_sequenceID
-									((uint)uVar12,
-									 (uint)(ushort)actorSequenceIdTbl[(uint)local_284 * 3 + (uint)local_282]);
-							actor_update_sequenceID
-									((uint)uVar13,
-									 (uint)(ushort)actorSequenceIdTbl
-									 [(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+							uVar12->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)local_284 * 3 + (uint)local_282]);
+							uVar13->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
 						}
 					}
 					else {
 						if (local_258 == 1) {
-							actor_update_sequenceID((uint)uVar6,1);
-							actor_update_sequenceID((uint)uVar8,1);
+							loungealotHeadActor->updateSequence(1);
+							uVar8->updateSequence(1);
 							if (local_288 == 2) {
 								local_28 = 1;
 							}
@@ -663,8 +623,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 							}
 						}
 						else {
-							actor_update_sequenceID((uint)uVar6,3);
-							actor_update_sequenceID((uint)uVar9,1);
+							loungealotHeadActor->updateSequence(3);
+							loungealotRightArm->updateSequence(1);
 							if (local_284 == 2) {
 								local_28 = 4;
 							}
@@ -684,10 +644,10 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 								}
 							}
 						}
-						Actor[uVar12].flags = Actor[uVar12].flags | 0x400;
-						Actor[uVar13].flags = Actor[uVar13].flags | 0x400;
-						actor_update_sequenceID((uint)uVar10,(uint)local_28 + 0xf);
-						actor_update_sequenceID((uint)uVar11,(uint)local_28 + 0xf);
+						uVar12->flags = uVar12->flags | 0x400;
+						uVar13->flags = uVar13->flags | 0x400;
+						flickerArm->updateSequence((uint)local_28 + 0xf);
+						loungealotThumb->updateSequence((uint)local_28 + 0xf);
 						DAT_80093c94 = 1;
 						DAT_80093c90 = 0x1e;
 					}
@@ -695,30 +655,32 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			}
 			else {
 				if (DAT_80093c94 == 2) {
-					Actor[uVar12].flags = Actor[uVar12].flags | 0x1000;
-					Actor[uVar13].flags = Actor[uVar13].flags | 0x1000;
-					Actor[uVar10].flags = Actor[uVar10].flags | 0x1000;
-					Actor[uVar11].flags = Actor[uVar11].flags | 0x1000;
-					screenShakeOffset = 0;
+					uVar12->flags = uVar12->flags | 0x1000;
+					uVar13->flags = uVar13->flags | 0x1000;
+					flickerArm->flags = flickerArm->flags | 0x1000;
+					loungealotThumb->flags = loungealotThumb->flags | 0x1000;
+					_vm->_screen->setScreenShakeOffset(0);
 					if (local_258 == 1) {
-						playSoundFromTxtIndex(DAT_80063ad0);
-						actor_update_sequenceID((uint)uVar6,9);
-						FUN_80093aec_dialog(DAT_80063ad0,0x14,1);
+//						playSoundFromTxtIndex(DAT_80063ad0);
+						loungealotHeadActor->updateSequence(9);
+						FUN_80093aec_dialog(0x46BC,0x14,1);
 						do {
-						} while ((engine_flags_maybe & 0x8000) != 0);
-						actor_update_sequenceID((uint)uVar6,2);
-						actor_update_sequenceID((uint)uVar9,3);
+							_vm->waitForFrames(1);
+						} while (_vm->isFlagSet(ENGINE_FLAG_8000));
+						loungealotHeadActor->updateSequence(2);
+						loungealotRightArm->updateSequence(3);
 					}
 					else {
-						playSoundFromTxtIndex(DAT_80063ad4);
-						actor_update_sequenceID((uint)uVar6,10);
-						FUN_80093aec_dialog(DAT_80063ad4,0x14,1);
-						actor_update_sequenceID((uint)uVar9,2);
+//						playSoundFromTxtIndex(DAT_80063ad4);
+						loungealotHeadActor->updateSequence(10);
+						FUN_80093aec_dialog(0x4718,0x14,1);
+						loungealotRightArm->updateSequence(2);
 						do {
-						} while ((engine_flags_maybe & 0x8000) != 0);
-						actor_update_sequenceID((uint)uVar6,4);
+							_vm->waitForFrames(1);
+						} while (_vm->isFlagSet(ENGINE_FLAG_8000));
+						loungealotHeadActor->updateSequence(4);
 					}
-					waitForFrames_times0x3c(2);
+					_vm->waitForFrames(2 * 0x3c);
 					shouldExit = true;
 				}
 			}
@@ -736,18 +698,14 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		else {
 			local_272 = local_272 + -1;
 		}
-		uVar18 = PressedThisFrameR2(0);
-		uVar19 = PressedThisFrameR1(0);
-		if (((uVar18 | uVar19) & 0xffff) != 0) {
+
+		if (_vm->isR1ButtonPressed()) { //TODO || _vm->isR2ButtonPressed()) {
 			local_27a = local_27a + 4;
 		}
-		uVar18 = PressedThisFrameL2(0);
-		uVar19 = PressedThisFrameL1(0);
-		if (((uVar18 | uVar19) & 0xffff) != 0) {
+		if (_vm->isL1ButtonPressed()) { //TODO || _vm->isL2ButtonPressed()) {
 			local_27a = local_27a + 4;
 		}
-		uVar18 = FUN_80093990();
-		if ((uVar18 & 0xffff) != 0) {
+		if (FUN_80093990()) {
 			if (param_1 == 1) {
 				local_278 = local_278 + 4;
 			}
@@ -755,8 +713,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				local_278 = local_278 + 6;
 			}
 		}
-		uVar18 = FUN_80093a30();
-		if ((uVar18 & 0xffff) != 0) {
+		if (FUN_80093a30()) {
 			if (param_1 == 1) {
 				local_278 = local_278 + 4;
 			}
@@ -765,9 +722,9 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			}
 		}
 		if ((0x3f < local_278) || (0x3f < local_27a)) {
-			Actor[uVar6].flags = Actor[uVar6].flags | 0x1000;
-			Actor[uVar8].flags = Actor[uVar8].flags | 0x1000;
-			Actor[uVar9].flags = Actor[uVar9].flags | 0x1000;
+			loungealotHeadActor->setFlag(ACTOR_FLAG_1000);
+			uVar8->setFlag(ACTOR_FLAG_1000);
+			loungealotRightArm->setFlag(ACTOR_FLAG_1000);
 			if (0x40 < local_27a) {
 				local_27a = 0x40;
 			}
@@ -777,34 +734,26 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			if (((local_278 == local_27a) || ((local_258 == 2 && (local_278 < local_27a)))) ||
 				((local_258 == 1 && (local_27a < local_278)))) {
 				if (local_258 == 1) {
-					playSoundFromTxtIndex(DAT_80063ad8);
-					actor_update_sequenceID((uint)uVar6,0xb);
-					FUN_80093aec_dialog(DAT_80063ad8,0x14,1);
+//					playSoundFromTxtIndex(DAT_80063ad8);
+					loungealotHeadActor->updateSequence(0xb);
+					FUN_80093aec_dialog(0x475E,0x14,1);
 				}
 				else {
-					playSoundFromTxtIndex(DAT_80063adc);
-					actor_update_sequenceID((uint)uVar6,0xc);
-					FUN_80093aec_dialog(DAT_80063adc,0x14,1);
+//					playSoundFromTxtIndex(DAT_80063adc);
+					loungealotHeadActor->updateSequence(0xc);
+					FUN_80093aec_dialog(0x4774,0x14,1);
 				}
 				local_258 = 0;
 				DAT_80093cb4 = 2;
 				DAT_80093cbc = 1;
 				DAT_80093cb8 = 0;
 				DAT_80093cc0 = 1;
-				Actor[uVar12].flags = Actor[uVar12].flags & 0xfbff;
-				Actor[uVar13].flags = Actor[uVar13].flags & 0xfbff;
-				actor_update_sequenceID
-						((uint)uVar10,
-						 (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-				actor_update_sequenceID
-						((uint)uVar11,
-						 (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-				actor_update_sequenceID
-						((uint)uVar12,
-						 (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
-				actor_update_sequenceID
-						((uint)uVar13,
-						 (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+				uVar12->flags = uVar12->flags & 0xfbff;
+				uVar13->flags = uVar13->flags & 0xfbff;
+				flickerArm->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+				loungealotThumb->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+				uVar12->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+				uVar13->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
 				DAT_80093c94 = 0;
 				local_26c = 0x1e;
 			}
@@ -812,9 +761,33 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				DAT_80093c94 = 2;
 			}
 		}
-		 */
+		
 	} while( true );
 
 }
 
+void Minigame2::FUN_80093aec_dialog(uint32 textId, int16 x, int16 y) {
+
+}
+
+bool Minigame2::FUN_80093520() {
+	return false; //TODO
+}
+
+bool Minigame2::FUN_80093248() {
+	return false; //TODO
+}
+
+bool Minigame2::FUN_80093800() {
+	return false; //TODO
+}
+
+bool Minigame2::FUN_80093a30() {
+	return false; //TODO
+}
+
+bool Minigame2::FUN_80093990() {
+	return false; //TODO
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame2.h b/engines/dragons/minigame2.h
index 24a9d7dbad..292e12bd73 100644
--- a/engines/dragons/minigame2.h
+++ b/engines/dragons/minigame2.h
@@ -52,6 +52,13 @@ public:
 	Minigame2(DragonsEngine *vm);
 
 	void run(int16 param_1, uint16 param_2, int16 param_3);
+private:
+	void FUN_80093aec_dialog(uint32 textId, int16 x, int16 y);
+	bool FUN_80093520();
+	bool FUN_80093a30();
+	bool FUN_80093248();
+	bool FUN_80093800();
+	bool FUN_80093990();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 7df1518578..2fb746a2fb 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -34,6 +34,7 @@ Screen::Screen() {
 	initGraphics(320, 200, &_pixelFormat);
 	_backSurface = new Graphics::Surface();
 	_backSurface->create(320, 200, _pixelFormat);
+	_screenShakeOffset = 0;
 }
 
 void Screen::updateScreen() {
@@ -285,4 +286,8 @@ void Screen::drawRect(uint16 colour, Common::Rect rect, int id) {
 
 }
 
+void Screen::setScreenShakeOffset(int16 newOffset) {
+	_screenShakeOffset = newOffset;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index eb20da2e42..b52681f129 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -32,6 +32,7 @@ private:
 	Graphics::PixelFormat _pixelFormat;
 	Graphics::Surface *_backSurface;
 	byte _palettes[DRAGONS_NUM_PALETTES][512];
+	int16 _screenShakeOffset;
 public:
 	virtual ~Screen();
 
@@ -51,6 +52,7 @@ public:
 	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
 	Common::Rect clipRectToRect(int destX, int destY, const Common::Rect rect, const Common::Rect containerRect);
 
+	void setScreenShakeOffset(int16 newOffset);
 private:
 	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
 	void copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);


Commit: 633bbeb89ca90059c5433c78a363965f698a8518
    https://github.com/scummvm/scummvm/commit/633bbeb89ca90059c5433c78a363965f698a8518
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More work on mini game 2

Changed paths:
    engines/dragons/dragons.h
    engines/dragons/minigame2.cpp
    engines/dragons/minigame2.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index dfd46ee205..fcae3bad21 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -145,6 +145,7 @@ public:
 	uint16 videoFlags; // TODO move to screen?
 
 	Screen *_screen;
+	uint16 _sceneId1; //TODO wire this up. I think it might be where to restore save game from?
 private:
 	BigfileArchive *_bigfileArchive;
 	DragonFLG *_dragonFLG;
@@ -155,7 +156,6 @@ private:
 	uint32 _flags;
 	uint32 _unkFlags1;
 	Common::Point _cursorPosition;
-	uint16 _sceneId1;
 	uint32 _counter;
 	uint32 bit_flags_8006fbd8;
 	//unk
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 212e50094b..8eaa95b638 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -33,7 +33,7 @@
 
 namespace Dragons {
 
-Minigame2::Minigame2(DragonsEngine *vm) : _vm(vm) {}
+Minigame2::Minigame2(DragonsEngine *vm) : _vm(vm), DAT_80093c70(false), DAT_80093c72(false), DAT_80093c74(0), DAT_80093ca8(false) {}
 
 static const uint16 unkArray[5] = {
 		0xC, 0xA, 0x8, 0x6, 0x4
@@ -144,7 +144,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	DAT_80093cb8 = 2;
 	DAT_80093cc0 = 0;
 	DAT_80093cac = 0;
-	DAT_80093cb0 = 0;
+	DAT_80093cb0 = false;
 	DAT_80093c9c = 0;
 	_vm->_talk->DAT_8008e874_dialogBox_y2 = 0;
 	_vm->_talk->DAT_8008e844_dialogBox_y1 = 0;
@@ -767,27 +767,195 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 }
 
 void Minigame2::FUN_80093aec_dialog(uint32 textId, int16 x, int16 y) {
-
+	uint16 auStack4024 [2000];
+//TODO
+//	if ((((DAT_8008e7e8_dialogBox_x1 != 0) || (DAT_8008e848_dialogBox_x2 != 0)) ||
+//		 (DAT_8008e844_dialogBox_y1 != 0)) || (DAT_8008e874_dialogBox_y2 != 0)) {
+//		_vm->_talk->FUN_8001a7c4((uint)DAT_8008e7e8_dialogBox_x1,(uint)DAT_8008e844_dialogBox_y1,
+//					 (uint)DAT_8008e848_dialogBox_x2,(uint)DAT_8008e874_dialogBox_y2);
+//	}
+	_vm->_talk->loadText(textId, auStack4024, 2000);
+	_vm->_talk->displayDialogAroundPoint(auStack4024, x, y, 0, 0, textId);
+	DAT_80093c9c = 1;
 }
 
 bool Minigame2::FUN_80093520() {
-	return false; //TODO
+	bool uVar2;
+
+	if (DAT_80093ca0 == 0) {
+		if (!DAT_80093c70) {
+			if (!DAT_80093c72 || (3 < DAT_80093cb8)) {
+				DAT_80093c72 = false;
+				DAT_80093c74 = DAT_80093c74 + 1;
+				if (DAT_80093c74 < 2) {
+					DAT_80093c70 = true;
+					DAT_80093cac = 0;
+					uVar2 = false;
+				}
+				else {
+					if (DAT_80093ca4 == 0) {
+						DAT_80093cac = 0;
+						if (DAT_80093cb8 == DAT_80093cb4) {
+							if (DAT_80093cbc < DAT_80093cc0) {
+								DAT_80093cac = (ushort)(DAT_80093cb8 < 4);
+							}
+							else {
+								if (!DAT_80093cb0 && _vm->getRand(8) < 3) {
+									if (_vm->getRand(8) < 3) {
+										DAT_80093c72 = 1;
+										DAT_80093c74 = 0;
+										DAT_80093cac = 1;
+									} else {
+										DAT_80093ca4 = DAT_80093cc8 + _vm->getRand(10);
+										DAT_80093cac = 1;
+									}
+									return true;
+								}
+								if (DAT_80093cb4 == 4) {
+									DAT_80093cac = 1;
+								}
+							}
+						}
+						else {
+							if ((DAT_80093cb8 < DAT_80093cb4) && (DAT_80093cb4 != 2)) {
+								DAT_80093cac = 1;
+							}
+						}
+					}
+					uVar2 = (uint)DAT_80093cac;
+				}
+			}
+			else {
+				DAT_80093cac = 1;
+				uVar2 = true;
+			}
+		}
+		else {
+			DAT_80093cac = 0;
+			uVar2 = false;
+		}
+	}
+	else {
+		uVar2 = _vm->isLeftKeyPressed();
+	}
+	return uVar2;
 }
 
 bool Minigame2::FUN_80093248() {
-	return false; //TODO
+	bool uVar2;
+
+	if (DAT_80093ca0 == 0) {
+		if (!DAT_80093c72) {
+			if (!DAT_80093c70 || (DAT_80093cb8 == 0)) {
+				DAT_80093c70 = false;
+				DAT_80093c74 = DAT_80093c74 + 1;
+				if (DAT_80093c74 < 2) {
+					DAT_80093c72 = true;
+					DAT_80093cb0 = false;
+					uVar2 = false;
+				}
+				else {
+					if (DAT_80093ca4 == 0) {
+						DAT_80093cb0 = false;
+						if (DAT_80093cb8 == DAT_80093cb4) {
+							if (DAT_80093cbc < DAT_80093cc0) {
+								DAT_80093cb0 = (bool)(DAT_80093cb8 != 0);
+							}
+							else {
+								if ((DAT_80093cac == 0) &&  _vm->getRand(8) < 3) {
+									if (_vm->getRand(8) < 3) {
+										DAT_80093c70 = true;
+										DAT_80093c74 = 0;
+										DAT_80093cb0 = true;
+									} else {
+										DAT_80093ca4 = DAT_80093cc8 + _vm->getRand(10);
+										DAT_80093cb0 = true;
+									}
+
+									return true;
+								}
+								if (DAT_80093cb4 == 0) {
+									DAT_80093cb0 = true;
+								}
+							}
+						}
+						else {
+							if ((DAT_80093cb4 < DAT_80093cb8) && (DAT_80093cb4 != 2)) {
+								DAT_80093cb0 = true;
+							}
+						}
+					}
+					uVar2 = DAT_80093cb0;
+				}
+			}
+			else {
+				DAT_80093cb0 = true;
+				uVar2 = true;
+			}
+		}
+		else {
+			DAT_80093cb0 = false;
+			uVar2 = false;
+		}
+	}
+	else {
+		uVar2 = _vm->isRightKeyPressed();
+	}
+	return uVar2;
 }
 
 bool Minigame2::FUN_80093800() {
-	return false; //TODO
+	bool uVar2;
+
+	if (DAT_80093ca0 == 0) {
+		if (DAT_80093ca4 == 0) {
+			DAT_80093ca8 = false;
+			if ((DAT_80093cb8 == DAT_80093cb4) && (DAT_80093cc0 < DAT_80093cbc)) {
+				DAT_80093ca8 = true;
+			}
+			else {
+				if (_vm->getRand(8) < 3) {
+					DAT_80093ca4 = _vm->getRand(10);
+					DAT_80093ca4 = DAT_80093cc8 + DAT_80093ca4;
+					DAT_80093ca8 = true;
+				}
+			}
+		}
+		uVar2 = DAT_80093ca8;
+	}
+	else {
+		uVar2 = false;
+		if (_vm->isSquareButtonPressed() || _vm->isCrossButtonPressed() ||
+			 _vm->isCircleButtonPressed() ||
+			_vm->isTriangleButtonPressed()) {
+			uVar2 = true;
+		}
+	}
+	return uVar2;
 }
 
 bool Minigame2::FUN_80093a30() {
-	return false; //TODO
+	bool uVar1;
+
+	if (DAT_80093ca0 == 0) {
+		uVar1 = (uint) DAT_80093c90 == (uint) DAT_80093cc8 / 3;
+	}
+	else {
+		uVar1 = _vm->isL1ButtonPressed(); // TODO || _vm->isL2ButtonPressed();
+	}
+	return uVar1;
 }
 
 bool Minigame2::FUN_80093990() {
-	return false; //TODO
+	bool uVar1;
+
+	if (DAT_80093ca0 == 0) {
+		uVar1 = DAT_80093c90 == 0;
+	}
+	else {
+		uVar1 = _vm->isR1ButtonPressed(); // TODO || _vm->isR2ButtonPressed();
+	}
+	return uVar1;
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame2.h b/engines/dragons/minigame2.h
index 292e12bd73..62882b7ccc 100644
--- a/engines/dragons/minigame2.h
+++ b/engines/dragons/minigame2.h
@@ -41,13 +41,18 @@ private:
 	uint16 DAT_80093c94;
 
 	uint16 DAT_80093cac;
-	uint16 DAT_80093cb0;
+	bool DAT_80093cb0;
 	uint16 DAT_80093c9c;
 
 	uint16 DAT_80093c98;
 	uint16 DAT_80093ca0;
 	uint16 DAT_80093cc4;
 	uint16 DAT_80093cc8;
+
+	bool DAT_80093c70;
+	bool DAT_80093c72;
+	uint16 DAT_80093c74;
+	bool DAT_80093ca8;
 public:
 	Minigame2(DragonsEngine *vm);
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 7e4810c3e6..edfb7c7170 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -188,6 +188,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x82, spc82CallResetDataMaybe);
 	OPCODE(0x83, spcStopScreenShakeUpdater);
 
+	OPCODE(0x88, spc88SetScene1To0x16);
 	OPCODE(0x89, spcSetUnkFlag2);
 	OPCODE(0x8a, spcClearUnkFlag2);
 	OPCODE(0x8b, spcUnk8b);
@@ -785,6 +786,10 @@ void SpecialOpcodes::spcStopScreenShakeUpdater() {
 //	screenShakeOffset = 0;
 }
 
+void SpecialOpcodes::spc88SetScene1To0x16() {
+	_vm->_sceneId1 = 0x16;
+}
+
 void SpecialOpcodes::spcSetUnkFlag2() {
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index cd263d684d..039d191246 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -181,6 +181,7 @@ protected:
 	void spc82CallResetDataMaybe(); // 0x82
 	void spcStopScreenShakeUpdater(); // 0x83
 
+	void spc88SetScene1To0x16(); //0x88
 	void spcSetUnkFlag2(); // 0x89
 	void spcClearUnkFlag2(); //0x8a
 	void spcUnk8b(); //0x8b


Commit: e64a53a32bcfd2a519ccf5057dab5af1b419d212
    https://github.com/scummvm/scummvm/commit/e64a53a32bcfd2a519ccf5057dab5af1b419d212
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on mini game 2 and mini game 5

Changed paths:
  A engines/dragons/minigame5.cpp
  A engines/dragons/minigame5.h
    engines/dragons/minigame2.cpp
    engines/dragons/module.mk
    engines/dragons/scene.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 8eaa95b638..92bc6e4115 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -178,20 +178,18 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	loungealotLeftUpperArm = _vm->_actorManager->loadActor(0xb, 2, 0x7d, 199, 4);
 	uVar8 = _vm->_actorManager->loadActor(0xf,0,0x7d,199,4);
 	loungealotRightArm = _vm->_actorManager->loadActor(0x10, 0, 0x7d, 199, 4);
-	actorFrameData = loungealotLeftUpperArm->frame->frameDataOffset;
 	flickerArm = _vm->_actorManager->loadActor(9, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
-											   loungealotLeftUpperArm->x_pos - READ_LE_INT16(actorFrameData + 0xe),
-											   loungealotLeftUpperArm->y_pos - READ_LE_INT16(actorFrameData + 0x10), 4);
+											   loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e,
+											   loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10, 4);
 	loungealotThumb = _vm->_actorManager->loadActor(0x12, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
-													loungealotLeftUpperArm->x_pos - READ_LE_INT16(actorFrameData + 0xe),
-													loungealotLeftUpperArm->y_pos - READ_LE_INT16(actorFrameData + 0x10), 4);
-	actorFrameData = flickerArm->frame->frameDataOffset;
+													loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e,
+													loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10, 4);
 	uVar12 = _vm->_actorManager->loadActor(10, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
-										   flickerArm->x_pos - READ_LE_INT16(actorFrameData + 0xe),
-										   flickerArm->y_pos - READ_LE_INT16(actorFrameData + 0x10), 4);
+										   flickerArm->x_pos - flickerArm->frame->field_e,
+										   flickerArm->y_pos - flickerArm->frame->field_10, 4);
 	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
-										   flickerArm->x_pos - READ_LE_INT16(actorFrameData + 0xe),
-										   flickerArm->y_pos - READ_LE_INT16(actorFrameData + 0x10), 4);
+										   flickerArm->x_pos - flickerArm->frame->field_e,
+										   flickerArm->y_pos - flickerArm->frame->field_10, 4);
 	uVar14 = _vm->_actorManager->loadActor(0x27,0,0x10,0xac,4);
 	uVar15 = _vm->_actorManager->loadActor(0x27,1,0x10,0x8c,4);
 	uVar5->setFlag(ACTOR_FLAG_100);
@@ -242,16 +240,16 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 
 	uVar5->setFlag(ACTOR_FLAG_400);
 	actorFrameData = loungealotLeftUpperArm->frame->frameDataOffset;
-	flickerArm->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e; //READ_LE_INT16(actorFrameData + 0xe);
-	flickerArm->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10; //READ_LE_INT16(actorFrameData + 0x10);
-	loungealotThumb->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e; //READ_LE_INT16(actorFrameData + 0xe);
-	loungealotThumb->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10; //READ_LE_INT16(actorFrameData + 0x10);
+	flickerArm->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
+	flickerArm->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10;
+	loungealotThumb->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
+	loungealotThumb->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10;
 	actorFrameData = flickerArm->frame->frameDataOffset;
-	uVar12->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e; //READ_LE_INT16(actorFrameData + 0xe);
-	uVar12->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10; //READ_LE_INT16(actorFrameData + 0x10);
-	uVar13->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e; //READ_LE_INT16(actorFrameData + 0xe);
-	uVar13->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10; //READ_LE_INT16(actorFrameData + 0x10);
-	_vm->waitForFrames(200);
+	uVar12->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e;
+	uVar12->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10;
+	uVar13->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e;
+	uVar13->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10;
+	_vm->waitForFrames(2);
 	// call_fade_related_1f();
 
 	LAB_80090188:
@@ -274,6 +272,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			if (flicker->field_12 == 0) {
 				_vm->setVar(0xb, 1);
 				flicker->actorResourceId = 0xd2; //TODO is this correct?
+				_vm->_actorManager->loadActor(0xd2, flicker->actor->_actorID);
 				_vm->_dragonINIResource->getRecord(0x120)->sceneId = 0x17;
 			}
 			loungealotHeadActor->clearFlag(ACTOR_FLAG_40);
@@ -297,7 +296,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				_vm->_scene->setSceneId(0x17);
 				flicker->sceneId = 0x17;
 				_vm->_scene->loadSceneData((uint)(0x17 | 0x8000),0);
-				_vm->setAllFlags(origEngineFlags & 0xfefdffff | _vm->getAllFlags() & 0x1000000 | 0x40);
+				_vm->setAllFlags((origEngineFlags & 0xfefdffff) | (_vm->getAllFlags() & 0x1000000) | 0x40);
 //				call_fade_related_1f();
 			}
 			return;
@@ -342,46 +341,50 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		else {
 			DAT_80093cc4 = DAT_80093cc4 - 1;
 		}
-		/*
+
 		if (local_27a == 0) {
-			(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] & 0xfffe;
+//	TODO		(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] & 0xfffe;
 		}
 		else {
+			/* TODO
 			(&DAT_8008316c)[(uint)uVar16 * 0xb] = local_27a + 0x27;
 			(&DAT_80083168)[(uint)uVar16 * 0xb] = local_27a + 0x27;
 			(&DAT_80083176)[(uint)uVar16 * 0xb] =
 					(ushort)(((int)((uint)local_27a - 1) >> 1) << 5) |
 					(ushort)(((int)(0x40 - (uint)local_27a) >> 1) << 10);
 			(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] | 1;
+			 */
 		}
 		if (local_278 == 0) {
-			(&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] & 0xfffe;
+			//TODO (&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] & 0xfffe;
 			if ((local_27a != 0) || (local_258 != 0)) goto LAB_800907c4;
 		}
 		else {
+			/*TODO
 			(&DAT_8008316c)[(uint)uVar17 * 0xb] = local_278 + 0x27;
 			(&DAT_80083168)[(uint)uVar17 * 0xb] = local_278 + 0x27;
 			(&DAT_80083176)[(uint)uVar17 * 0xb] =
 					(ushort)(((int)((uint)local_278 - 1) >> 1) << 5) |
 					(ushort)(((int)(0x40 - (uint)local_278) >> 1) << 10);
 			(&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] | 1;
+			 */
 			LAB_800907c4:
 			if (!bVar4) {
-				FUN_8001a4e4_draw_dialogbox(4,0x14,0xd,0x16,1);
-				FUN_8001a4e4_draw_dialogbox(4,0x10,0xd,0x12,1);
+				//TODO FUN_8001a4e4_draw_dialogbox(4,0x14,0xd,0x16,1);
+				//TODO FUN_8001a4e4_draw_dialogbox(4,0x10,0xd,0x12,1);
 				uVar14->priorityLayer = 6;
 				uVar15->priorityLayer = 6;
 				bVar4 = true;
 			}
 		}
 		if ((((local_278 == 0) && (local_27a == 0)) && (local_258 == 0)) && (bVar4)) {
-			FUN_8001a7c4(4,0x14,0xd,0x16);
-			FUN_8001a7c4(4,0x10,0xd,0x12);
+			// TODO FUN_8001a7c4(4,0x14,0xd,0x16);
+			// TODO FUN_8001a7c4(4,0x10,0xd,0x12);
 			uVar14->priorityLayer = 0;
 			uVar15->priorityLayer = 0;
 			bVar4 = false;
 		}
-*/
+
 		//DisableVSyncEvent();
 		loungealotThumb->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
 		flickerArm->x_pos = loungealotThumb->x_pos;
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
new file mode 100644
index 0000000000..615aeffd17
--- /dev/null
+++ b/engines/dragons/minigame5.cpp
@@ -0,0 +1,548 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "minigame5.h"
+#include "actor.h"
+#include "dragons.h"
+#include "dragons/dragonini.h"
+#include "dragons/talk.h"
+#include "dragons/scene.h"
+
+namespace Dragons {
+
+#define DAT_80063a48 0x12d
+#define DAT_80063a40 0x12f
+#define DAT_80063bd0 0x133
+#define DAT_8006393c 0x21BF0
+#define DAT_80063938 0x21DAE
+#define DAT_80063e38 0x21E3E
+#define DAT_8006391c 0x475DA
+
+
+Minigame5::Minigame5(DragonsEngine *vm) : _vm(vm), DAT_800633e6(0) {}
+
+void Minigame5::run() {
+	ushort uVar1;
+	int iVar2;
+	byte *local_v0_7008;
+	void *local_v0_7256;
+	byte *uVar3;
+	uint uVar4;
+	ushort local_850;
+	uint16 auStack2120 [1000];
+	DragonINI*local_78;
+	uint16 local_76;
+	ushort local_74;
+	ushort local_72;
+	ushort local_70;
+	Actor *bombActor;
+	Actor *flickerActor;
+	Actor *pusherActor;
+	Actor *dustActor;
+	ushort local_66;
+	Actor *wheelsActor;
+	ushort local_62;
+	ushort local_60;
+	ushort local_5e;
+	short local_5c;
+	short local_5a;
+	ushort currentState;
+	short local_50;
+	Actor *local_4e;
+	uint16 local_4c;
+	uint16_t local_4a;
+	uint16 local_48;
+	int16_t local_46;
+	int16_t local_44;
+	short local_42;
+	uint16_t local_30 [4];
+	uint16_t uStack42;
+	uint16_t local_28 [10];
+	short local_10;
+	uint32 savedEngineFlags;
+
+	Common::File *fd = new Common::File();
+	if (!fd->open("arc5.bin")) {
+		error("Failed to open arc5.bin");
+	}
+
+	for (int i = 0; i < 4; i++) {
+		local_30[i] = fd->readUint16LE();
+	}
+
+	for (int i = 0; i < 10; i++) {
+		local_28[i] = fd->readUint16LE();
+	}
+
+	fd->close();
+
+	local_48 = 0;
+	local_76 = _vm->_scene->getSceneId();
+	local_78 = _vm->_dragonINIResource->getFlickerRecord();
+	local_78->actor->setFlag(ACTOR_FLAG_100);
+	local_78->actor->priorityLayer = 0;
+	savedEngineFlags = _vm->getMultipleFlags(ENGINE_FLAG_8 | ENGINE_FLAG_10 | ENGINE_FLAG_20 | ENGINE_FLAG_80);
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_10);
+	_vm->clearFlags(ENGINE_FLAG_20);
+	_vm->clearFlags(ENGINE_FLAG_80);
+	_vm->_dragonINIResource->setFlickerRecord(_vm->_dragonINIResource->getRecord(DAT_80063a40 - 1));
+	flickerActor = _vm->_dragonINIResource->getFlickerRecord()->actor;
+	flickerActor->flags = flickerActor->flags | 0x380;
+	flickerActor->scale = 0x100;
+	flickerActor->priorityLayer = 4;
+	flickerActor->_sequenceID2 = -1;
+	flickerActor->updateSequence(0x19);
+	currentState = 0;
+	local_10 = 0;
+	local_850 = flickerActor->x_pos;
+	uVar1 = flickerActor->y_pos;
+	local_74 = 0;
+//	DisableVSyncEvent();
+	pusherActor = _vm->_actorManager->loadActor
+			(0x26,0,(int)(short)local_850,(int)(((uint)uVar1 + 5) * 0x10000) >> 0x10);
+//	EnableVSyncEvent();
+	if (pusherActor == NULL) {
+		error("Couldn't alloc pusher!");
+	}
+	pusherActor->flags = pusherActor->flags | 0x380;
+	pusherActor->x_pos = flickerActor->x_pos + -0xe;
+	pusherActor->y_pos = flickerActor->y_pos + 7;
+	pusherActor->scale = 0x100;
+	pusherActor->priorityLayer = 6;
+//	DisableVSyncEvent();
+	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
+//	EnableVSyncEvent();
+	if (wheelsActor == NULL) {
+		error("Couldn't alloc wheels!");
+	}
+	wheelsActor->flags = wheelsActor->flags | 0x380;
+	wheelsActor->scale = 0x100;
+	wheelsActor->x_pos = flickerActor->x_pos;
+	wheelsActor->y_pos = flickerActor->y_pos;
+	wheelsActor->priorityLayer = 5;
+	wheelsActor->updateSequence(0x11);
+	local_62 = 0;
+//	DisableVSyncEvent();
+	bombActor = _vm->_actorManager->loadActor(7,0x1c,0,0);
+//	EnableVSyncEvent();
+	if (bombActor == NULL) {
+		error("Couldn't alloc bomb!");
+	}
+	bombActor->flags = bombActor->flags | 0x380;
+	bombActor->scale = 0x100;
+	bombActor->priorityLayer = 0;
+//	DisableVSyncEvent();
+	dustActor = _vm->_actorManager->loadActor(8,8,100,100,0);
+//	EnableVSyncEvent();
+	if (dustActor == NULL) {
+		error("Couldn't alloc dust sprite!");
+	}
+	dustActor->flags = dustActor->flags | 0x380;
+	dustActor->scale = 0x100;
+	local_4e = _vm->_dragonINIResource->getRecord(DAT_80063a48 + -1)->actor;
+	local_4c = 0;
+	local_4a = local_4e->field_c;
+	_vm->setFlags(ENGINE_FLAG_4000000);
+	currentState = 1;
+	local_66 = 0;
+	local_50 = 0;
+	while( true ) {
+		while( true ) {
+			do {
+				_vm->waitForFrames(1);
+				if ((uint)currentState - 1 < 8) {
+					switch(currentState) {
+						case 1:
+							if (local_66 != 8) {
+								local_66 = 0;
+							}
+							//iVar2 = IsButtonBeingPressed((uint)DAT_800728ac,0);
+							if (!_vm->isActionButtonPressed()) {
+								if (local_74 == 0) {
+									if ((((flickerActor->_sequenceID != 0) &&
+										  (flickerActor->_sequenceID != 5)) &&
+										 (flickerActor->_sequenceID != 6)) ||
+										((flickerActor->flags & 4) != 0)) {
+										flickerActor->updateSequence(0x19);
+									}
+								}
+								else {
+									local_66 = 1;
+									local_50 = 0;
+									pusherActor->updateSequence(1);
+									currentState = 2;
+									if (local_74 < 0x14) {
+										local_72 = 1;
+									}
+									else {
+										if (local_74 < 0x2d) {
+											local_72 = 2;
+										}
+										else {
+											if (local_74 < 0x169) {
+												local_72 = 3;
+											}
+										}
+									}
+								}
+								local_74 = 0;
+							}
+							else {
+								pusherActor->x_pos = flickerActor->x_pos + -0xe;
+								pusherActor->y_pos = flickerActor->y_pos + 7;
+								if (local_74 < 0x168) {
+									local_74 = local_74 + 1;
+									if (local_74 < 0x14) {
+										if (((pusherActor->_sequenceID != 4) &&
+											 (pusherActor->_sequenceID != 2)) &&
+											(pusherActor->_sequenceID != 3)) {
+											pusherActor->updateSequence(4);
+										}
+										if (flickerActor->_sequenceID != 0x1a) {
+											flickerActor->updateSequence(0x1a);
+											_vm->playSound(2);
+										}
+									}
+									else {
+										if (local_74 < 0x2d) {
+											if (((pusherActor->_sequenceID != 5) &&
+												 (pusherActor->_sequenceID != 2)) &&
+												(pusherActor->_sequenceID != 3)) {
+												pusherActor->updateSequence(5);
+											}
+											if (flickerActor->_sequenceID != 0x1e) {
+												flickerActor->updateSequence(0x1e);
+												_vm->playSound(3);
+											}
+										}
+										else {
+											if (local_74 < 0x169) {
+												if (((pusherActor->_sequenceID != 6) &&
+													 (pusherActor->_sequenceID != 2)) &&
+													(pusherActor->_sequenceID != 3)) {
+													pusherActor->updateSequence(6);
+												}
+												if (flickerActor->_sequenceID != 0x1f) {
+													flickerActor->updateSequence(0x1f);
+													_vm->playSound(4);
+												}
+											}
+										}
+									}
+								}
+								else {
+									if (pusherActor->_sequenceID != 6) {
+										pusherActor->updateSequence(6);
+									}
+									if (flickerActor->_sequenceID != 0x1f) {
+										flickerActor->updateSequence(0x1f);
+									}
+								}
+							}
+							break;
+						case 2:
+							if (flickerActor->_sequenceID == 0x1b) {
+								if ((flickerActor->flags & 4) != 0) {
+									if ((((int)(uint)local_850 < (int)((local_30[0]) - 6)) ||
+										 ((uint)local_30[1] + 6 < (uint)local_850)) || (local_72 != local_30[2])) {
+										local_42 = 8;
+									}
+									else {
+										local_42 = 0;
+									}
+									local_5c = 0;
+									if ((local_42 != 8) && ((local_850 < local_30[0] || (local_30[1] < local_850)))) {
+										local_5c = (short)((int)(((local_30[0]) + 0x17) * 0x80) / 0x2a) -
+												   (short)((int)((uint)local_850 << 7) / 0x2a);
+									}
+									local_60 = local_850 << 7;
+									bombActor->x_pos = local_850 & 0x1ff;
+									local_5e = 0x2d00;
+									local_5a = (local_72 + 3) * 0x80;
+									bombActor->y_pos = 0x5a;
+									local_70 = 0x100;
+									bombActor->scale = 0x100;
+									_vm->playSound(10);
+									bombActor->priorityLayer = 3;
+									flickerActor->updateSequence(8);
+									currentState = 3;
+								}
+							}
+							else {
+								flickerActor->updateSequence(0x1b);
+								_vm->playSound(1);
+							}
+							break;
+						case 3:
+							local_60 = local_60 + local_5c;
+							if ((uint)local_72 * 2 + 0xb4 < (uint)local_70) {
+								local_5e = local_5e - local_5a;
+								local_5a = local_5a - local_28[((uint)local_72 - 1) * 3];
+								if (local_5a < 0) {
+									local_5a = 0;
+								}
+							}
+							else {
+								if ((int)(uint)local_70 < (int)((uint)local_72 * -4 + 0xba)) {
+									local_5e = local_5e + local_5a;
+									local_5a = local_5a + local_28[((uint)local_72 - 1) * 3 + 2];
+								}
+								else {
+									local_5a = 0;
+								}
+							}
+							bombActor->x_pos = local_60 >> 7;
+							bombActor->y_pos = local_5e >> 7;
+							local_70 = local_70 - 3;
+							bombActor->scale = local_70;
+							if (local_70 == 0x7f) {
+								if (((local_60 >> 7 < local_30[0]) || (local_30[1] < local_60 >> 7)) ||
+									(local_72 != local_30[2])) {
+									local_42 = 8;
+								}
+								else {
+									local_42 = 0;
+								}
+								if (local_42 == 8) {
+									if ((((local_72 == 1) && (local_60 >> 7 < 0x10e)) ||
+										 ((local_72 == 2 &&
+										   ((((0x7f < local_60 >> 7 && (local_60 >> 7 < 0xad)) ||
+											  ((0x30 < local_60 >> 7 && (local_60 >> 7 < 0x4a)))) ||
+											 ((0xf8 < local_60 >> 7 && (local_60 >> 7 < 0x10f)))))))) ||
+										((local_72 == 3 &&
+										  (((0x3c < local_60 >> 7 && (local_60 >> 7 < 0x46)) ||
+											((0x101 < local_60 >> 7 && (local_60 >> 7 < 0x10a)))))))) {
+										bombActor->priorityLayer = 0;
+										dustActor->priorityLayer = 4;
+										dustActor->x_pos = bombActor->x_pos;
+										dustActor->y_pos = bombActor->y_pos;
+										dustActor->updateSequence(9);
+										currentState = 4;
+									}
+								}
+								else {
+									local_4e->field_c = 2;
+									local_4c = 0x3c;
+									bombActor->priorityLayer = 0;
+									currentState = 8;
+								}
+							}
+							if (local_70 < 0x7f) {
+								bombActor->priorityLayer = 2;
+							}
+							if ((0xc < local_70) && (local_70 < 0x41)) {
+								bombActor->priorityLayer = 0;
+							}
+							if ((short)local_70 < 2) {
+								currentState = 5;
+							}
+							break;
+						case 4:
+							pusherActor->updateSequence(9);
+							_vm->waitForFrames(0x3c);
+							pusherActor->updateSequence(0xb);
+							if (DAT_800633e6 == 0) {
+								_vm->_talk->loadText(DAT_8006393c,auStack2120, 1000);
+								_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1,DAT_8006393c);
+								DAT_800633e6 = 1;
+							}
+							else {
+								_vm->_talk->loadText(DAT_80063938, auStack2120, 1000);
+								_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1, DAT_80063938);
+							}
+							_vm->waitForFrames(10);
+							local_10 = 1;
+							currentState = 6;
+							break;
+						case 5:
+							currentState = 4;
+							break;
+						case 6:
+							currentState = 7;
+							break;
+						case 7:
+							break;
+						case 8:
+							bombActor->priorityLayer = 0;
+							pusherActor->updateSequence(0);
+							_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(2);
+							_vm->waitForFrames(0x12);
+							_vm->_talk->loadText(DAT_80063e38, auStack2120, 1000);
+							_vm->_talk->displayDialogAroundPoint(auStack2120,0xf,2,0x501,0,DAT_80063e38);
+//						TODO	callMaybeResetData();
+							_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(3);
+							_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->waitUntilFlag8And4AreSet();
+							pusherActor->updateSequence(7);
+							_vm->_talk->loadText(DAT_8006391c, auStack2120, 1000);
+							_vm->_talk->displayDialogAroundPoint(auStack2120, (int)(short)(local_850 >> 3),0xc,0,1,DAT_8006391c);
+							pusherActor->flags = pusherActor->flags | 0x1000;
+							local_10 = 2;
+							local_48 = 1;
+							currentState = 6;
+					}
+				}
+				else {
+					debug("undefined state!");
+					currentState = 1;
+					bombActor->priorityLayer = 0;
+				}
+				if ((local_10 == 0) && (currentState != 2)) {
+					if (!_vm->isLeftKeyPressed() || (local_850 < 0x37)) {
+						if (!_vm->isRightKeyPressed() || (0x107 < local_850)) {
+							if ((pusherActor->_sequenceID != local_66) &&
+								(((pusherActor->_sequenceID != 4 && (pusherActor->_sequenceID != 5))
+								  && (pusherActor->_sequenceID != 6)))) {
+								pusherActor->updateSequence((uint)local_66);
+								if (local_50 == 0) {
+									pusherActor->x_pos = flickerActor->x_pos + -0xe;
+									pusherActor->y_pos = flickerActor->y_pos + 7;
+								}
+								else {
+									pusherActor->x_pos = flickerActor->x_pos + 2;
+									pusherActor->y_pos = flickerActor->y_pos;
+								}
+							}
+						}
+						else {
+							local_50 = 1;
+							local_66 = 8;
+							if (pusherActor->_sequenceID != 2) {
+								pusherActor->updateSequence(2);
+							}
+							local_850 = local_850 + 2;
+							if (local_850 < 0x109) {
+								if (local_850 < 0x36) {
+									local_850 = 0x36;
+								}
+							}
+							else {
+								local_850 = 0x108;
+							}
+							if (local_62 == 0) {
+								local_62 = 0xb;
+							}
+							else {
+								local_62 = local_62 - 1;
+							}
+							flickerActor->x_pos = local_850;
+							wheelsActor->x_pos = local_850;
+							if ((uint)wheelsActor->_sequenceID != (uint)local_62 / 3 + 0x11) {
+								wheelsActor->updateSequence((uint)local_62 / 3 + 0x11);
+							}
+							pusherActor->x_pos = flickerActor->x_pos + 2;
+							pusherActor->y_pos = flickerActor->y_pos;
+						}
+					}
+					else {
+						local_50 = 0;
+						local_66 = (ushort)(currentState != 1);
+						if (pusherActor->_sequenceID != 3) {
+							pusherActor->updateSequence(3);
+						}
+						local_850 = local_850 - 2;
+						if (local_850 < 0x109) {
+							if (local_850 < 0x36) {
+								local_850 = 0x36;
+							}
+						}
+						else {
+							local_850 = 0x108;
+						}
+						local_62 = (short)((uint)local_62 + 1) +
+								   (short)((int)((uint)local_62 + 1) / 6 >> 1) * -0xc;
+						flickerActor->x_pos = local_850;
+						wheelsActor->x_pos = local_850;
+						if ((uint)wheelsActor->_sequenceID != (uint)local_62 / 3 + 0x11) {
+							wheelsActor->updateSequence((uint)local_62 / 3 + 0x11);
+						}
+						pusherActor->x_pos = flickerActor->x_pos + -2;
+						pusherActor->y_pos = flickerActor->y_pos;
+					}
+				}
+			} while (local_10 == 0);
+			if ((local_10 == 2) || (0x117 < flickerActor->x_pos)) break;
+			flickerActor->x_pos = flickerActor->x_pos + 2;
+			if (pusherActor->_sequenceID != 2) {
+				pusherActor->updateSequence(2);
+			}
+			pusherActor->x_pos = flickerActor->x_pos + 2;
+			pusherActor->y_pos = flickerActor->y_pos;
+			wheelsActor->x_pos = wheelsActor->x_pos + 2;
+			if (local_62 == 0) {
+				local_62 = 0xb;
+			}
+			else {
+				local_62 = local_62 - 1;
+			}
+			if ((uint)wheelsActor->_sequenceID != (uint)local_62 / 3 + 0x11) {
+				wheelsActor->updateSequence((uint)local_62 / 3 + 0x11);
+			}
+		}
+		if (local_10 == 1) break;
+		if (local_10 == 2) {
+			_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->field_14 = 2;
+			pusherActor->updateSequence(7);
+			_vm->waitForFrames(0x3c);
+			pusherActor->updateSequence(1);
+			_vm->waitForFrames(0x1e);
+			_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->actor->clearFlag(ACTOR_FLAG_100);
+			LAB_8009157c:
+//			callMaybeResetData();
+			flickerActor->updateSequence(0x15);
+			local_46 = 0;
+			local_44 = 0;
+			if (local_10 == 2) {
+//				DisableVSyncEvent();
+				local_46 = pusherActor->x_pos;
+				local_44 = pusherActor->y_pos;
+				pusherActor->reset_maybe();
+//				EnableVSyncEvent();
+			}
+			else {
+//				DisableVSyncEvent();
+				dustActor->reset_maybe();
+				bombActor->reset_maybe();
+				wheelsActor->reset_maybe();
+				pusherActor->reset_maybe();
+//				EnableVSyncEvent();
+			}
+			_vm->_dragonINIResource->setFlickerRecord(local_78);
+			if (local_10 == 2) {
+				local_78->actor->x_pos = local_46;
+				local_78->actor->setFlag(ACTOR_FLAG_100);
+				local_78->actor->priorityLayer = 5;
+			}
+			else {
+				local_78->actor->clearFlag(ACTOR_FLAG_100);
+				local_78->actor->priorityLayer = 2;
+			}
+			_vm->clearFlags(ENGINE_FLAG_4000000);
+			_vm->setFlags(savedEngineFlags);
+			return;
+		}
+	}
+	_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->actor->clearFlag(ACTOR_FLAG_100);
+	_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->field_14 = 0;
+	goto LAB_8009157c;
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/minigame5.h b/engines/dragons/minigame5.h
new file mode 100644
index 0000000000..8540e0cd32
--- /dev/null
+++ b/engines/dragons/minigame5.h
@@ -0,0 +1,43 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 DRAGONS_MINIGAME5_H
+#define DRAGONS_MINIGAME5_H
+
+#include "common/system.h"
+
+namespace Dragons {
+
+class DragonsEngine;
+
+class Minigame5 {
+private:
+	DragonsEngine *_vm;
+	uint16 DAT_800633e6;
+public:
+	Minigame5(DragonsEngine *vm);
+
+	void run();
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_MINIGAME5_H
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 21d08a32a2..8a87c226ca 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -22,6 +22,7 @@ MODULE_OBJS := \
 	minigame2.o \
 	minigame3.o \
 	minigame4.o \
+	minigame5.o \
 	saveload.o \
 	scene.o \
 	screen.o \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index da578a0a59..02e1057375 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -218,7 +218,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
-		if (ini->sceneId == sceneId) {
+		if (ini->sceneId == sceneIdStripped) {
 			if (ini->field_1a_flags_maybe & 1) {
 				Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index edfb7c7170..79e6b7d848 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -38,6 +38,7 @@
 #include "dragons/minigame2.h"
 #include "dragons/minigame3.h"
 #include "dragons/minigame4.h"
+#include "dragons/minigame5.h"
 
 
 namespace Dragons {
@@ -99,6 +100,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x1a, spcActivatePizzaMakerActor);
 	OPCODE(0x1b, spcDeactivatePizzaMakerActor);
 	OPCODE(0x1c, spcPizzaMakerActorStopWorking);
+	OPCODE(0x1d, spcDragonArrivesAtTournament);
+	OPCODE(0x1e, spcDragonCatapultMiniGame);
 
 	OPCODE(0x21, spcSetEngineFlag0x20000);
 	OPCODE(0x22, spcClearEngineFlag0x20000);
@@ -188,6 +191,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x82, spc82CallResetDataMaybe);
 	OPCODE(0x83, spcStopScreenShakeUpdater);
 
+	OPCODE(0x87, spc87SetScene1To0x17);
 	OPCODE(0x88, spc88SetScene1To0x16);
 	OPCODE(0x89, spcSetUnkFlag2);
 	OPCODE(0x8a, spcClearUnkFlag2);
@@ -377,6 +381,17 @@ void SpecialOpcodes::spcPizzaMakerActorStopWorking() {
 	pizzaMakerStopWorking();
 }
 
+void SpecialOpcodes::spcDragonArrivesAtTournament() {
+	_vm->_dragonINIResource->getRecord(0x123)->actor->setFlag(ACTOR_FLAG_400);
+	_vm->_dragonINIResource->getRecord(0x124)->actor->setFlag(ACTOR_FLAG_400);
+	_vm->_dragonINIResource->getRecord(0)->actor->setFlag(ACTOR_FLAG_400);
+}
+
+void SpecialOpcodes::spcDragonCatapultMiniGame() {
+	Minigame5 minigame5(_vm);
+	minigame5.run();
+}
+
 void SpecialOpcodes::spcSetEngineFlag0x20000() {
 	_vm->setFlags(ENGINE_FLAG_20000);
 }
@@ -786,6 +801,10 @@ void SpecialOpcodes::spcStopScreenShakeUpdater() {
 //	screenShakeOffset = 0;
 }
 
+void SpecialOpcodes::spc87SetScene1To0x17() {
+	_vm->_sceneId1 = 0x17;
+}
+
 void SpecialOpcodes::spc88SetScene1To0x16() {
 	_vm->_sceneId1 = 0x16;
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 039d191246..f9cbecd70f 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -93,6 +93,8 @@ protected:
 	void spcActivatePizzaMakerActor(); // 0x1a
 	void spcDeactivatePizzaMakerActor(); // 0x1b
 	void spcPizzaMakerActorStopWorking(); // 0x1c
+	void spcDragonArrivesAtTournament(); // 0x1d
+	void spcDragonCatapultMiniGame(); // 0x1e
 
 	void spcSetEngineFlag0x20000(); // 0x21
 	void spcClearEngineFlag0x20000(); // 0x22
@@ -181,6 +183,7 @@ protected:
 	void spc82CallResetDataMaybe(); // 0x82
 	void spcStopScreenShakeUpdater(); // 0x83
 
+	void spc87SetScene1To0x17(); //0x87
 	void spc88SetScene1To0x16(); //0x88
 	void spcSetUnkFlag2(); // 0x89
 	void spcClearUnkFlag2(); //0x8a


Commit: 7f0b7d2dc6e7a350defc3f686b3e05426d62e6c6
    https://github.com/scummvm/scummvm/commit/7f0b7d2dc6e7a350defc3f686b3e05426d62e6c6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More special opcodes for final scene logic

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 79e6b7d848..678d0b0f91 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -34,6 +34,7 @@
 #include "dragons/minigame1.h"
 #include "dragons/talk.h"
 #include "dragons/specialopcodes.h"
+#include "dragons/screen.h"
 #include "dragons/minigame1.h"
 #include "dragons/minigame2.h"
 #include "dragons/minigame3.h"
@@ -102,6 +103,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x1c, spcPizzaMakerActorStopWorking);
 	OPCODE(0x1d, spcDragonArrivesAtTournament);
 	OPCODE(0x1e, spcDragonCatapultMiniGame);
+	OPCODE(0x1f, spcStGeorgeDragonLanded);
 
 	OPCODE(0x21, spcSetEngineFlag0x20000);
 	OPCODE(0x22, spcClearEngineFlag0x20000);
@@ -169,7 +171,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x66, spcUnk66);
 	OPCODE(0x67, spcTournamentSetCamera);
 	OPCODE(0x68, spcTournamentCutScene);
-
+	OPCODE(0x69, spcInsideBlackDragonUpdatePalette);
 	OPCODE(0x6a, spcCastleGateSceneLogic);
 	OPCODE(0x6b, spcTransitionToMap);
 	OPCODE(0x6c, spcTransitionFromMap);
@@ -177,6 +179,8 @@ void SpecialOpcodes::initOpcodes() {
 
 	OPCODE(0x70, spcLoadLadyOfTheLakeActor);
 
+	OPCODE(0x74, spcUseClickerOnLever);
+
 	OPCODE(0x77, spcJesterInLibrarySceneLogic);
 
 	OPCODE(0x79, spcSetUnkFlag2);
@@ -190,7 +194,9 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x81, spcShakeScreenSceneLogic);
 	OPCODE(0x82, spc82CallResetDataMaybe);
 	OPCODE(0x83, spcStopScreenShakeUpdater);
-
+	OPCODE(0x84, spcInsideBlackDragonScreenShake);
+	OPCODE(0x85, spc85SetScene1To0x35);
+	OPCODE(0x86, spc86SetScene1To0x33);
 	OPCODE(0x87, spc87SetScene1To0x17);
 	OPCODE(0x88, spc88SetScene1To0x16);
 	OPCODE(0x89, spcSetUnkFlag2);
@@ -392,6 +398,22 @@ void SpecialOpcodes::spcDragonCatapultMiniGame() {
 	minigame5.run();
 }
 
+void SpecialOpcodes::spcStGeorgeDragonLanded() {
+//	DisableVSyncEvent();
+	DragonINI *ini121 = _vm->_dragonINIResource->getRecord(0x121);
+	Actor *origActor = ini121->actor;
+	ini121->actor = _vm->_actorManager->loadActor(0x48, 4, ini121->actor->x_pos, ini121->actor->y_pos);
+	origActor->reset_maybe();
+//	reset_actor_maybe();
+	ini121->actor->setFlag(ACTOR_FLAG_80);
+	ini121->actor->scale = 0x100;
+	ini121->actor->priorityLayer = 2;
+	ini121->actorResourceId = 0x48;
+
+	_vm->updateActorSequences();
+	_vm->_scene->draw();
+}
+
 void SpecialOpcodes::spcSetEngineFlag0x20000() {
 	_vm->setFlags(ENGINE_FLAG_20000);
 }
@@ -725,6 +747,13 @@ void SpecialOpcodes::spcTournamentCutScene() {
 	delete cutScene;
 }
 
+void SpecialOpcodes::spcInsideBlackDragonUpdatePalette() {
+	memcpy(_vm->_scene->getPalette() + 0x180,
+			_vm->_dragonINIResource->getRecord(0x2b2)->actor->_actorResource->getPalette() + 0x180,
+			0x80);
+	_vm->_screen->loadPalette(0, _vm->_scene->getPalette());
+}
+
 void SpecialOpcodes::spcCastleGateSceneLogic() {
 //TODO spcCastleGateSceneLogic
 }
@@ -801,6 +830,22 @@ void SpecialOpcodes::spcStopScreenShakeUpdater() {
 //	screenShakeOffset = 0;
 }
 
+void SpecialOpcodes::spcInsideBlackDragonScreenShake() {
+	const int16 shakeTbl[5] = {5, -2, 4, -1, 0};
+	for (int i = 0; i < 5; i ++) {
+		_vm->_screen->setScreenShakeOffset(shakeTbl[i]);
+		_vm->waitForFrames(1);
+	}
+}
+
+void SpecialOpcodes::spc85SetScene1To0x35() {
+	_vm->_sceneId1 = 0x35;
+}
+
+void SpecialOpcodes::spc86SetScene1To0x33() {
+	_vm->_sceneId1 = 0x33;
+}
+
 void SpecialOpcodes::spc87SetScene1To0x17() {
 	_vm->_sceneId1 = 0x17;
 }
@@ -892,6 +937,15 @@ void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
 	//EnableVSyncEvent();
 }
 
+void SpecialOpcodes::spcUseClickerOnLever() {
+	if (_vm->_inventory->getType() != 0) {
+		_vm->_talk->flickerRandomDefaultResponse();
+		_vm->_dragonINIResource->getRecord(0)->field_12 = 1;
+	} else {
+		_vm->_dragonINIResource->getRecord(0)->field_12 = 0;
+	}
+}
+
 void SpecialOpcodes::spcJesterInLibrarySceneLogic() {
 	//TODO
 }
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index f9cbecd70f..49198d3beb 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -95,6 +95,7 @@ protected:
 	void spcPizzaMakerActorStopWorking(); // 0x1c
 	void spcDragonArrivesAtTournament(); // 0x1d
 	void spcDragonCatapultMiniGame(); // 0x1e
+	void spcStGeorgeDragonLanded(); // 0x1f
 
 	void spcSetEngineFlag0x20000(); // 0x21
 	void spcClearEngineFlag0x20000(); // 0x22
@@ -129,7 +130,7 @@ protected:
 	void spcZigmondFraudSceneLogic1(); // 0x40
 	void spcBrokenBlackDragonSceneLogic(); // 0x41
 	void spcDodoUnderAttackSceneLogic(); //0x42
-	void spcForestWithoutDodoSceneLogic();
+	void spcForestWithoutDodoSceneLogic(); //0x43
 
 	void spcBlackDragonOnHillSceneLogic(); //0x46
 
@@ -162,7 +163,7 @@ protected:
 	void spcUnk66();
 	void spcTournamentSetCamera(); // 0x67
 	void spcTournamentCutScene(); // 0x68
-
+	void spcInsideBlackDragonUpdatePalette(); // 0x69
 	void spcCastleGateSceneLogic(); // 0x6a
 	void spcTransitionToMap(); // 0x6b
 	void spcTransitionFromMap(); // 0x6c
@@ -170,6 +171,8 @@ protected:
 
 	void spcLoadLadyOfTheLakeActor(); //0x70
 
+	void spcUseClickerOnLever(); // 0x74
+
 	void spcJesterInLibrarySceneLogic(); // 0x77
 
 	void spcBlackDragonDialogForCamelhot(); // 0x7a
@@ -182,7 +185,9 @@ protected:
 	void spcShakeScreenSceneLogic(); //0x81
 	void spc82CallResetDataMaybe(); // 0x82
 	void spcStopScreenShakeUpdater(); // 0x83
-
+	void spcInsideBlackDragonScreenShake(); // 0x84
+	void spc85SetScene1To0x35(); //0x85
+	void spc86SetScene1To0x33(); //0x86
 	void spc87SetScene1To0x17(); //0x87
 	void spc88SetScene1To0x16(); //0x88
 	void spcSetUnkFlag2(); // 0x89


Commit: 1db640963fd2524a06d00373ebbd8f574bacf876
    https://github.com/scummvm/scummvm/commit/1db640963fd2524a06d00373ebbd8f574bacf876
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Started on credits logic

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 678d0b0f91..9b05999eaa 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -178,6 +178,8 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x6d, spcCaveOfDilemmaSceneLogic);
 
 	OPCODE(0x70, spcLoadLadyOfTheLakeActor);
+	OPCODE(0x71, spcFadeCreditsToBackStageScene);
+	OPCODE(0x72, spcRunCredits);
 
 	OPCODE(0x74, spcUseClickerOnLever);
 
@@ -918,6 +920,40 @@ void SpecialOpcodes::spcCaveOfDilemmaSceneLogic() {
 	_vm->setSceneUpdateFunction(caveOfDilemmaUpdateFunction);
 }
 
+void SpecialOpcodes::spcFadeCreditsToBackStageScene() {
+//	call_fade_related();
+	_vm->_screen->loadPalette(0, _vm->_scene->getPalette());
+	_vm->_scene->_camera.x = 0x140;
+	_vm->waitForFrames(0x3c);
+//	Call_SomeShadeTexThingB1E();
+//TODO
+}
+
+void SpecialOpcodes::spcRunCredits() {
+//	int iVar1;
+//	DAT_8006a440 = 0x1a;
+//	DAT_80087270 = 0x78;
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_1);
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
+//	open_files_slot_number_tbl = 0;
+//	DAT_80072de4 = 0;
+//	buf2048bytes = actor_dictionary;
+//	DAT_8007273c = actor_dictionary;
+	_vm->_cursor->setActorFlag400();
+	_vm->clearFlags(ENGINE_FLAG_8);
+	_vm->setFlags(ENGINE_FLAG_8000000);
+//	iVar1 = file_read_to_buffer(strCredits_txt);
+//	DAT_800728ec = iVar1 + (int)DAT_8007273c;
+//	buf2048bytes = (int32_t *)((iVar1 + 3U & 0xfffffffc) + (int)buf2048bytes);
+//	memcpy2((byte *)buf2048bytes,scrFileData_maybe,0x200);
+//	buf2048bytes = buf2048bytes + 0x80;
+	_vm->_screen->loadPalette(0, _vm->_dragonINIResource->getRecord(0x2C8)->actor->_actorResource->getPalette());
+	_vm->_scene->setMgLayerPriority(0);
+	_vm->_scene->setFgLayerPriority(0);
+//	vsync_updater_function = creditsUpdateFunction;
+//TODO
+}
+
 void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
 	//TODO
 	DragonINI *ini = _vm->_dragonINIResource->getRecord(0x2a7);
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 49198d3beb..8859d49447 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -170,6 +170,8 @@ protected:
 	void spcCaveOfDilemmaSceneLogic(); // 0x6d
 
 	void spcLoadLadyOfTheLakeActor(); //0x70
+	void spcFadeCreditsToBackStageScene(); //0x71
+	void spcRunCredits(); //0x72
 
 	void spcUseClickerOnLever(); // 0x74
 


Commit: 218bfd0bff48852a627ce7e62d2a8cd2db0d7f46
    https://github.com/scummvm/scummvm/commit/218bfd0bff48852a627ce7e62d2a8cd2db0d7f46
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on end credits

Changed paths:
  A engines/dragons/credits.cpp
  A engines/dragons/credits.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/font.cpp
    engines/dragons/font.h
    engines/dragons/module.mk
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp
    engines/dragons/screen.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h
    engines/dragons/talk.cpp


diff --git a/engines/dragons/credits.cpp b/engines/dragons/credits.cpp
new file mode 100644
index 0000000000..27eb3f6d41
--- /dev/null
+++ b/engines/dragons/credits.cpp
@@ -0,0 +1,116 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "credits.h"
+
+#include "common/system.h"
+#include "dragons/bigfile.h"
+#include "dragons/dragons.h"
+#include "dragons/screen.h"
+#include "font.h"
+
+namespace Dragons {
+
+void creditsUpdateFunction() {
+	getEngine()->_credits->update();
+}
+
+Credits::Credits(DragonsEngine *vm, FontManager *fontManager, BigfileArchive *bigfileArchive) : _vm(vm), _fontManager(fontManager), _bigfileArchive(bigfileArchive), _surface(NULL) {
+	_running = false;
+	_updateCounter = 0;
+	_yOffset = 0;
+	_linesRemaining = 0x1a;
+}
+
+void Credits::start() {
+	_surface = new Graphics::Surface();
+	_surface->create(320, 208, Graphics::PixelFormat::createFormatCLUT8());
+	_updateCounter = 0x78;
+	_curPosition = 0;
+	_creditsData = _bigfileArchive->load("credits.txt", _dataLength);
+	_curPtr = (char *)_creditsData;
+	assert(_creditsData);
+	_vm->setVsyncUpdateFunction(creditsUpdateFunction);
+	_running = true;
+}
+
+bool Credits::isRunning() {
+	return _running;
+}
+
+void Credits::draw() {
+	if(_running) {
+		_vm->_screen->copyRectToSurface8bppWrappedY(*_surface, _vm->_screen->getPalette(2), _yOffset);
+	}
+}
+
+void Credits::cleanup() {
+	_vm->setVsyncUpdateFunction(NULL);
+	_surface->free();
+	delete _surface;
+}
+
+void Credits::update() {
+	uint16 line[41];
+	if (_updateCounter == 0) {
+		_updateCounter = 3;
+		_yOffset = (_yOffset + 1) % 208;
+		if (_yOffset % 8 == 0) {
+			if (_curPosition <= _dataLength) {
+				uint32 length = strlen(_curPtr);
+				//TODO add line here.
+				debug("Credit line: %s", _curPtr);
+				convertToWideChar(line, (byte *)_curPtr, 40);
+				_curPtr += length + 1;
+				_curPosition += length + 1;
+			} else {
+				if (_linesRemaining) {
+					_linesRemaining--;
+				}
+				convertToWideChar(line, (byte *)" ", 40);
+			}
+			_fontManager->_fonts[0]->renderToSurface(_surface, 0, (_yOffset + 200) % 208, line, 40);
+
+		}
+
+	} else {
+		_updateCounter--;
+	}
+
+	if (_linesRemaining == 0) {
+		_running = false;
+		cleanup();
+	}
+
+}
+
+void Credits::convertToWideChar(uint16 *destBuf, byte *text, uint16 maxLength) {
+	int i = 0;
+	bool finished = false;
+	for (; i < maxLength; i++) {
+		if (text[i] == 0) {
+			finished = true;
+		}
+		destBuf[i] = !finished ? text[i] : ' ';
+	}
+}
+
+} // End of namespace Dragons
diff --git a/engines/dragons/credits.h b/engines/dragons/credits.h
new file mode 100644
index 0000000000..0d23671154
--- /dev/null
+++ b/engines/dragons/credits.h
@@ -0,0 +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 DRAGONS_CREDITS_H
+#define DRAGONS_CREDITS_H
+
+#include "graphics/surface.h"
+#include "graphics/pixelformat.h"
+
+namespace Dragons {
+
+class BigfileArchive;
+class DragonsEngine;
+class FontManager;
+
+class Credits {
+private:
+	DragonsEngine *_vm;
+	FontManager *_fontManager;
+	BigfileArchive *_bigfileArchive;
+	Graphics::Surface *_surface;
+	bool _running;
+	int16 _yOffset;
+	int16 _linesRemaining;
+	int16 _updateCounter;
+
+	byte *_creditsData;
+	char *_curPtr;
+	uint32 _dataLength;
+	uint32 _curPosition;
+public:
+	Credits(DragonsEngine *vm, FontManager *fontManager, BigfileArchive *bigfileArchive);
+	void start();
+	bool isRunning();
+	void draw();
+	void update();
+private:
+	void cleanup();
+	void convertToWideChar(uint16 *destBuf, byte *text, uint16 maxLength);
+};
+
+} // End of namespace Dragons
+
+#endif //DRAGONS_CREDITS_H
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index dcfea3489d..a33349da8e 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -29,6 +29,7 @@
 #include "background.h"
 #include "bigfile.h"
 #include "cursor.h"
+#include "credits.h"
 #include "dragonflg.h"
 #include "dragonimg.h"
 #include "dragonini.h"
@@ -66,6 +67,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_engine = this;
 	_inventory = new Inventory(this);
 	_cursor = new Cursor(this);
+	_credits = NULL;
 	_talk = NULL;
 	_sound = new Sound(this);
 	_fontManager = NULL;
@@ -197,6 +199,7 @@ Common::Error DragonsEngine::run() {
 	_dragonVAR = new DragonVAR(_bigfileArchive);
 	_dragonINIResource = new DragonINIResource(_bigfileArchive);
 	_fontManager = new FontManager(this, _screen, _bigfileArchive);
+	_credits = new Credits(this, _fontManager, _bigfileArchive);
 	ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
 	_actorManager = new ActorManager(actorResourceLoader);
 	_scriptOpcodes = new ScriptOpcodes(this, _dragonFLG);
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index fcae3bad21..6c51ccf29e 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -105,6 +105,7 @@ struct opCode1AStruct {
 class BigfileArchive;
 class BackgroundResourceLoader;
 class Cursor;
+class Credits;
 class DragonFLG;
 class DragonIMG;
 class DragonOBD;
@@ -136,6 +137,7 @@ public:
 	uint16 data_800633fa;
 	Inventory *_inventory;
 	Cursor *_cursor;
+	Credits *_credits;
 	Talk *_talk;
 	Sound *_sound;
 
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 6ce2d6efbd..c223b276a7 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -64,9 +64,15 @@ Graphics::Surface *Font::render(uint16 *text, uint16 length) {
 	Graphics::Surface *surface = new Graphics::Surface();
 	surface->create(length * 8, 8, Graphics::PixelFormat::createFormatCLUT8());
 
+	renderToSurface(surface, 0, 0, text, length);
 
+	return surface;
+}
+
+void Font::renderToSurface(Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint16 length) {
+	byte *startPixelOffset = (byte *)surface->getPixels() + y * surface->pitch + x * surface->format.bytesPerPixel;
 	for (int i = 0; i < length; i++) {
-		byte *pixels = (byte *)surface->getPixels();
+		byte *pixels = startPixelOffset;
 		pixels += i * 8;
 //		debug("char: %d size: %d %d", (text[i] - 0x20), _numChars, (30 + i));
 		byte *data = _pixels + mapChar(text[i]) * 64;
@@ -76,8 +82,6 @@ Graphics::Surface *Font::render(uint16 *text, uint16 length) {
 			pixels += surface->pitch;
 		}
 	}
-
-	return surface;
 }
 
 FontManager::FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive): _vm(vm), _screen(screen) {
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index 916d216a23..b6e2521085 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -43,6 +43,7 @@ public:
 	Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelOffset, uint32 pixelSize);
 	~Font();
 	Graphics::Surface *render(uint16 *text, uint16 length);
+	void renderToSurface(Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint16 length);
 private:
 	uint16 mapChar(uint16 in);
 };
@@ -53,10 +54,11 @@ struct ScreenTextEntry {
 };
 
 class FontManager {
-	uint16 DAT_80086f48_fontColor_flag;
+public:
+	Font *_fonts[3];
 private:
+	uint16 DAT_80086f48_fontColor_flag;
 	DragonsEngine *_vm;
-	Font *_fonts[3];
 	Screen *_screen;
 	Common::List<ScreenTextEntry *> _screenTexts;
 	byte *_palettes;
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 8a87c226ca..e14b54dbc8 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -6,6 +6,7 @@ MODULE_OBJS := \
     background.o \
     bag.o \
     bigfile.o \
+    credits.o \
     cursor.o \
     cutscene.o \
 	detection.o \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 02e1057375..805d09fdc5 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -24,6 +24,7 @@
 #include "actor.h"
 #include "background.h"
 #include "cursor.h"
+#include "credits.h"
 #include "dragonini.h"
 #include "dragonimg.h"
 #include "font.h"
@@ -389,6 +390,10 @@ void Scene::draw() {
 		}
 	}
 	_vm->_fontManager->draw();
+	if (_vm->_credits->isRunning()) {
+		_vm->_credits->draw();
+	}
+
 	if (_vm->isDebugMode()) {
 		_vm->_fontManager->clearText();
 	}
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 2fb746a2fb..24a8b2344f 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -290,4 +290,18 @@ void Screen::setScreenShakeOffset(int16 newOffset) {
 	_screenShakeOffset = newOffset;
 }
 
+void Screen::copyRectToSurface8bppWrappedY(const Graphics::Surface &srcSurface, byte *palette, int yOffset) {
+	byte *dst = (byte *)_backSurface->getBasePtr(0, 0);
+	for (int i = 0; i < 200; i++) {
+		byte *src = (byte *)srcSurface.getPixels() + ((yOffset + i) % srcSurface.h) * srcSurface.pitch;
+		for (int j = 0; j < 320; j++) {
+			uint16 c = READ_LE_UINT16(&palette[src[j] * 2]);
+			if (c != 0) {
+					WRITE_LE_UINT16(&dst[j * 2], c & ~0x8000);
+			}
+		}
+		dst += _backSurface->pitch;
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index b52681f129..21fdb3f72c 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -53,6 +53,9 @@ public:
 	Common::Rect clipRectToRect(int destX, int destY, const Common::Rect rect, const Common::Rect containerRect);
 
 	void setScreenShakeOffset(int16 newOffset);
+
+	void copyRectToSurface8bppWrappedY(const Graphics::Surface &srcSurface, byte *palette, int yOffset);
+
 private:
 	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
 	void copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 9b05999eaa..27bffc326f 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -23,6 +23,7 @@
 #include "dragons/actorresource.h"
 #include "dragons/cursor.h"
 #include "dragons/cutscene.h"
+#include "dragons/credits.h"
 #include "dragons/dragons.h"
 #include "dragons/dragonflg.h"
 #include "dragons/dragonini.h"
@@ -180,7 +181,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x70, spcLoadLadyOfTheLakeActor);
 	OPCODE(0x71, spcFadeCreditsToBackStageScene);
 	OPCODE(0x72, spcRunCredits);
-
+	OPCODE(0x73, spcEndCreditsAndRestartGame);
 	OPCODE(0x74, spcUseClickerOnLever);
 
 	OPCODE(0x77, spcJesterInLibrarySceneLogic);
@@ -951,7 +952,19 @@ void SpecialOpcodes::spcRunCredits() {
 	_vm->_scene->setMgLayerPriority(0);
 	_vm->_scene->setFgLayerPriority(0);
 //	vsync_updater_function = creditsUpdateFunction;
-//TODO
+	_vm->_credits->start();
+}
+
+void SpecialOpcodes::spcEndCreditsAndRestartGame() {
+//	call_fade_related();
+//	_volumeSFX = 0;
+//	setCDAVolumes();
+	while (_vm->_credits->isRunning()) {
+		_vm->waitForFrames(1);
+	}
+//	ReloadGameFlag = 2;
+//	Exec_FMV_RELOADTT();
+//TODO need to return to main menu here.
 }
 
 void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 8859d49447..f34f8cd4b0 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -172,7 +172,7 @@ protected:
 	void spcLoadLadyOfTheLakeActor(); //0x70
 	void spcFadeCreditsToBackStageScene(); //0x71
 	void spcRunCredits(); //0x72
-
+	void spcEndCreditsAndRestartGame(); //0x73
 	void spcUseClickerOnLever(); // 0x74
 
 	void spcJesterInLibrarySceneLogic(); // 0x77
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 9d8429f3df..1cd951f0e9 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -496,9 +496,10 @@ Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 pa
 }
 
 void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex) {
+	int16 frameYOffset = actor->frame ? actor->frame->yOffset : 0;
 	displayDialogAroundPoint
 			(dialogText,(ushort)((int)(((uint)actor->x_pos - _vm->_scene->_camera.x) * 0x10000) >> 0x13),
-			 (short)((int)((((uint)actor->y_pos - (uint)actor->frame->yOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13) - 3,
+			 (short)((int)((((uint)actor->y_pos - (uint)frameYOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13) - 3,
 			 param_2,1,textIndex);
 }
 


Commit: 8512c91c79de242c116f58c1a08bc8156c2f1de9
    https://github.com/scummvm/scummvm/commit/8512c91c79de242c116f58c1a08bc8156c2f1de9
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed talk script opcode

Changed paths:
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index ab01f39133..1020166ed8 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -798,7 +798,10 @@ void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(iniId)
 	ARG_UINT32(textIndex)
-	// TODO implement me!
+
+	if (scriptOpCall._field8 != 0) {
+		return;
+	}
 
 	_vm->_talk->talkFromIni(iniId, textIndex);
 }


Commit: 77ebe94f2684c640b18012d228631786b8aff7b4
    https://github.com/scummvm/scummvm/commit/77ebe94f2684c640b18012d228631786b8aff7b4
Author: Edu Garcia (28616+Arcnor at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: sound plays (WIP, hack)

Changed paths:
  A engines/dragons/VabSound.cpp
  A engines/dragons/VabSound.h
    engines/dragons/cutscene.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame4.h
    engines/dragons/minigame5.cpp
    engines/dragons/module.mk
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/sound.cpp
    engines/dragons/sound.h
    engines/dragons/talk.cpp


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
new file mode 100644
index 0000000000..6c42969cd4
--- /dev/null
+++ b/engines/dragons/VabSound.cpp
@@ -0,0 +1,67 @@
+#include <common/textconsole.h>
+#include <common/debug.h>
+#include <audio/decoders/xa.h>
+#include <audio/audiostream.h>
+#include <audio/mixer.h>
+#include "common/memstream.h"
+#include "VabSound.h"
+#include "dragons.h"
+
+namespace Dragons {
+	VabSound::VabSound(Common::SeekableReadStream *msfData, const DragonsEngine *_vm) {
+		loadHeader(msfData);
+
+		auto dataSize = msfData->size() - msfData->pos();
+		byte *newData = new byte[dataSize];
+		msfData->read(newData, dataSize);
+
+		_vbData = new Common::MemoryReadStream(newData, dataSize, DisposeAfterUse::YES);
+
+		Audio::AudioStream *str = Audio::makeXAStream(_vbData, 11025);
+		Audio::SoundHandle _speechHandle;
+		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speechHandle, str);
+
+		delete msfData;
+	}
+
+	VabSound::VabSound(Common::SeekableReadStream *vhData, Common::SeekableReadStream *vbData): _vbData(vbData) {
+		loadHeader(vhData);
+
+		assert(vhData->pos() == vhData->size());
+
+		delete vhData;
+	}
+
+	void VabSound::loadHeader(Common::SeekableReadStream *vhData) {
+		vhData->seek(0);
+		vhData->read(&_header, sizeof(_header));
+		if (strncmp(_header.magic, "pBAV", 4) != 0) {
+			error("Invalid VAB file");
+		}
+		// TODO: is sizeof(array) the right thing to do here?
+		vhData->read(&_programAttrs, sizeof(_programAttrs));
+
+		const int numTones = 16 * _header.numPrograms;
+		_toneAttrs = new VabToneAttr[numTones];
+		vhData->read(_toneAttrs, sizeof(VabToneAttr) * numTones);
+
+		uint16 tempOffsets[0x100];
+		vhData->read(tempOffsets, sizeof(tempOffsets));
+		_vagOffsets[0] = tempOffsets[0] << 3u;
+		for (int j = 1; j < 0x100; ++j) {
+			const int vagSize = tempOffsets[j] << 3u;
+			_vagSizes[j - 1] = vagSize;
+			_vagOffsets[j] = vagSize + _vagOffsets[j - 1];
+		}
+	}
+
+	VabSound::~VabSound() {
+		delete _toneAttrs;
+		delete _vbData;
+	}
+
+	void VabSound::playSound(uint16 program, uint16 key) {
+		// TODO
+		debug("Playing program %d, key %d", program, key);
+	}
+} // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/VabSound.h b/engines/dragons/VabSound.h
new file mode 100644
index 0000000000..9063d3bcc7
--- /dev/null
+++ b/engines/dragons/VabSound.h
@@ -0,0 +1,108 @@
+//
+// Created by Edu García on 2019-07-25.
+//
+
+#ifndef DRAGONS_VABSOUND_H
+#define DRAGONS_VABSOUND_H
+
+#include <common/scummsys.h>
+
+namespace Common {
+	class SeekableReadStream;
+}
+
+namespace Dragons {
+class DragonsEngine;
+
+struct VabHeader {
+	char magic[4];
+
+	uint32 version;
+	uint32 vabId;
+	uint32 waveformSize;
+
+	uint16 reserved0;
+	uint16 numPrograms;
+	uint16 numTones;
+	uint16 numVAG;
+
+	uint8 masterVolume;
+	uint8 masterPan;
+	uint8 bankAttr1;
+	uint8 bankAttr2;
+
+	uint32 reserved1;
+};
+
+struct VabProgramAttr {
+	uint8 tones;
+	uint8 mvol;
+	uint8 prior;
+	uint8 mode;
+	uint8 mpan;
+	uint8 reserved0;
+	uint16 attr;
+	uint32 reserved1;
+	uint32 reserved2;
+};
+
+struct VabToneAttr {
+	uint8 prior;
+	uint8 mode;
+	uint8 vol;
+	uint8 pan;
+	uint8 center;
+	uint8 shift;
+	uint8 min;
+	uint8 max;
+	uint8 vibW;
+	uint8 vibT;
+	uint8 porW;
+	uint8 porT;
+	uint8 pbmin;
+	uint8 pbmax;
+	uint8 reserved1;
+	uint8 reserved2;
+	uint16 adsr1;
+	uint16 adsr2;
+	int16 prog;
+	int16 vag;
+	int16 reserved[4];
+};
+
+class VabSound {
+public:
+	/**
+	 * Creates a VAB file with both header and body (*.MSF). VabSound will dispose msfData
+	 * @param data
+	 */
+	VabSound(Common::SeekableReadStream* msfData, const DragonsEngine *_vm);
+
+	/**
+	 * Creates a VAB file with separate header and body (*.VH and *.VB). VabSound will dispose vhData & vbData
+	 *
+	 * @param dataHeader
+	 * @param dataBody
+	 */
+	VabSound(Common::SeekableReadStream* vhData, Common::SeekableReadStream* vbData);
+
+	~VabSound();
+
+	void playSound(uint16 program, uint16 key);
+
+private:
+	Common::SeekableReadStream *_vbData;
+
+	VabHeader _header;
+	VabProgramAttr _programAttrs[128];
+	VabToneAttr *_toneAttrs;
+
+	uint32 _vagSizes[0x100];
+	uint32 _vagOffsets[0x100];
+
+	void loadHeader(Common::SeekableReadStream *vhData);
+};
+
+} // End of namespace Dragons
+
+#endif //SCUMMVM_VABSOUND_H
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 43413f98ea..dab99b6461 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -94,9 +94,9 @@ void CutScene::scene1() {
 						closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); //close up flicker
 						//playSoundFromTxtIndex(0x51fc);
 						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x51fc,0x701) != 2) {
-							_vm->playSound(0x8004);
+							_vm->playOrStopSound(0x8004);
 							_vm->waitForFrames(0x28);
-							_vm->playSound(0x8003);
+							_vm->playOrStopSound(0x8003);
 							fadeScreenAndResetActor(DAT_80072de8);
 							DAT_80063514 = DAT_80063514 | 0x40;
 							FUN_8003d8e8(0xd6,0,0x37a,0x280);
@@ -154,7 +154,7 @@ void CutScene::scene1() {
 																	fadeScreenAndResetActor(DAT_80072dec);
 																	DAT_80063514 = DAT_80063514 & 0xffbf;
 																	closeUpKnightsAtTable(); // close up of knights at table.
-																	_vm->playSound(0x8003);
+																	_vm->playOrStopSound(0x8003);
 																	//playSoundFromTxtIndex(0x5b96);
 																	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,8,4,0x5b96,0xc01) != 2) {
 																		//playSoundFromTxtIndex(0x5c4a);
@@ -196,7 +196,7 @@ void CutScene::scene1() {
 																								//playSoundFromTxtIndex(0x5de8);
 																								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df8,0xb,2,0x5de8,0xc01) != 2) {
 																									wideAngleEveryoneAtTable();
-																									_vm->playSound(1);
+																									_vm->playOrStopSound(1);
 																									DAT_80072df0->updateSequence(8);
 																									DAT_80072df4->updateSequence(0xd);
 																									DAT_80072df8->updateSequence(0x11);
@@ -620,7 +620,7 @@ void CutScene::knightsSavedBackAtCastle() {
 							wideAngleEveryoneAtTable();
 							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,9,5,0x7c20,0xc01) != 2) {
 								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x7c9c,0x701) != 2) {
-									_vm->playSound(0x800f);
+									_vm->playOrStopSound(0x800f);
 									_vm->waitForFrames(10);
 									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x7cf2,0x701) != 2) {
 										closeUpKnightsAtTable();
@@ -877,7 +877,7 @@ void CutScene::tournamentCutScene() {
 	Actor *actor = _vm->_dragonINIResource->getRecord(0x02BE)->actor;
 	_vm->_screen->loadPalette(0, actor->_actorResource->getPalette());
 	_vm->_scene->_camera.x = 0;
-	_vm->playSound(0);
+	_vm->playOrStopSound(0);
 //	call_fade_related_1f();
 	_vm->waitForFrames(300);
 	actor->setFlag(ACTOR_FLAG_1000);
@@ -885,7 +885,7 @@ void CutScene::tournamentCutScene() {
 	_vm->waitForFrames(0x3c);
 //	fade_related_calls_with_1f();
 	_vm->_screen->loadPalette(0, _vm->_scene->getPalette());
-	_vm->playSound(0x4000);
+	_vm->playOrStopSound(0x4000);
 	_vm->_scene->_camera.x = 0x3c0;
 //	call_fade_related_1f();
 	_vm->_talk->loadText(0x4C814, dialogText, 1000);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index a33349da8e..8fa788b5c6 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -206,6 +206,8 @@ Common::Error DragonsEngine::run() {
 	_backgroundResourceLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource, _backgroundResourceLoader);
 
+	_soundManager = new SoundManager(this, _bigfileArchive, _dragonRMS);
+
 	if (ConfMan.hasKey("save_slot")) {
 		loadGameState(ConfMan.getInt("save_slot"));
 	} else {
@@ -227,6 +229,7 @@ Common::Error DragonsEngine::run() {
 	delete _fontManager;
 	delete _bigfileArchive;
 	delete _screen;
+	delete _soundManager;
 
 	debug("Ok");
 	return Common::kNoError;
@@ -795,7 +798,7 @@ uint16 DragonsEngine::getVar(uint16 offset) {
 	return _dragonVAR->getVar(offset);
 }
 
-uint16 DragonsEngine::getCurrentSceneId() {
+uint16 DragonsEngine::getCurrentSceneId() const {
 	return _scene->getSceneId();
 }
 
@@ -1005,8 +1008,10 @@ void DragonsEngine::waitForFramesAllowSkip(uint16 numFrames) {
 	}
 }
 
-void DragonsEngine::playSound(uint16 soundId) {
-	debug(3, "TODO: play sound %d", soundId);
+void DragonsEngine::playOrStopSound(uint16 soundId) {
+	debug("play sound 0x%x", soundId);
+
+	this->_soundManager->playOrStopSound(soundId);
 }
 
 void DragonsEngine::updatePathfindingActors() {
@@ -1393,6 +1398,10 @@ void DragonsEngine::runVsyncUpdaterFunction() {
 	}
 }
 
+void DragonsEngine::loadCurrentSceneMsf() {
+	_soundManager->loadMsf(getCurrentSceneId());
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 6c51ccf29e..4d7ed222f9 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -28,6 +28,8 @@
 
 namespace Dragons {
 
+#define ushort uint16
+
 enum {
 	kGameIdDragons = 1
 };
@@ -121,6 +123,7 @@ class SequenceOpcodes;
 class ScriptOpcodes;
 class Talk;
 class Sound;
+class SoundManager;
 struct DragonINI;
 
 
@@ -140,12 +143,15 @@ public:
 	Credits *_credits;
 	Talk *_talk;
 	Sound *_sound;
+	SoundManager *_soundManager;
 
 	opCode1AStruct opCode1A_tbl[8];
 
 	uint16 data_800633fc;
 	uint16 videoFlags; // TODO move to screen?
 
+	void loadCurrentSceneMsf();
+
 	Screen *_screen;
 	uint16 _sceneId1; //TODO wire this up. I think it might be where to restore save game from?
 private:
@@ -224,13 +230,13 @@ public:
 	DragonINI *getINI(uint32 index);
 	uint16 getVar(uint16 offset);
 	void setVar(uint16 offset, uint16 value);
-	uint16 getCurrentSceneId();
+	uint16 getCurrentSceneId() const;
 
 	void waitForFrames(uint16 numFrames);
 	void waitForFramesAllowSkip(uint16 numFrames);
 
 
-	void playSound(uint16 soundId);
+	void playOrStopSound(uint16 soundId);
 
 	//TODO what are these functions really doing?
 	void call_fade_related_1f();
@@ -295,6 +301,11 @@ private:
 
 	void seedRandom(int32 seed);
 	uint32 shuffleRandState();
+	void FUN_8002931c();
+
+	void initializeSound();
+
+	void SomeInitSound_FUN_8003f64c();
 };
 
 DragonsEngine *getEngine();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 9353a47aa8..2bf25f71b5 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -34,10 +34,10 @@ namespace Dragons {
 
 
 static const Common::Point positionTable[4] = {
-		{2,0},
-		{0xce,0},
-		{2,0x9e},
-		{0xce,0x9e}
+		Common::Point(2,0),
+		Common::Point(0xce,0),
+		Common::Point(2,0x9e),
+		Common::Point(0xce,0x9e)
 };
 
 static const int16 bagBounceTable[4] = {
@@ -202,7 +202,7 @@ void Inventory::animateBagIn() {
 		accel += 2;
 	}
 
-	_vm->playSound(0x8001);
+	_vm->playOrStopSound(0x8001);
 
 	// Shake bag at the end.
 	for (int i = 0; i < 4; i++) {
@@ -216,7 +216,7 @@ void Inventory::animateBagIn() {
 }
 
 void Inventory::animateBagOut() {
-	_vm->playSound(0x8000);
+	_vm->playOrStopSound(0x8000);
 	Common::Point pos = _bag->getPosition();
 	if (pos.y != 0xc8) {
 		for (;pos.y != 0xc8; pos.y += 0x19) {
@@ -424,4 +424,4 @@ void Inventory::inventoryMissing() {
 	}
 }
 
-} // End of namespace Dragons
\ No newline at end of file
+} // End of namespace Dragons
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 6e7ef67105..44d0cdf090 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -319,7 +319,7 @@ void Minigame1::run() {
 									}
 									if (flickerActor->_sequenceID != 1) {
 										flickerActor->updateSequence(1);
-										_vm->playSound(2);
+										_vm->playOrStopSound(2);
 									}
 								}
 								else {
@@ -331,7 +331,7 @@ void Minigame1::run() {
 										}
 										if (flickerActor->_sequenceID != 2) {
 											flickerActor->updateSequence(2);
-											_vm->playSound(3);
+											_vm->playOrStopSound(3);
 										}
 									}
 									else {
@@ -343,7 +343,7 @@ void Minigame1::run() {
 											}
 											if (flickerActor->_sequenceID != 3) {
 												flickerActor->updateSequence(3);
-												_vm->playSound(4);
+												_vm->playOrStopSound(4);
 											}
 										}
 									}
@@ -384,7 +384,7 @@ void Minigame1::run() {
 							catFieldE_scaleMaybe = 0x100;
 							catActor->scale = 0x100;
 							catActor->updateSequence(0xc);
-							_vm->playSound(5);
+							_vm->playOrStopSound(5);
 							catActor->priorityLayer = 3;
 							flickerActor->updateSequence(8);
 							gameState = 3;
@@ -392,7 +392,7 @@ void Minigame1::run() {
 					}
 					else {
 						flickerActor->updateSequence(7);
-						_vm->playSound(1);
+						_vm->playOrStopSound(1);
 					}
 					break;
 				case 3: // cat flying through the air
@@ -441,7 +441,7 @@ void Minigame1::run() {
 							}
 							else {
 								catActor->updateSequence(0xd);
-								_vm->playSound(6);
+								_vm->playOrStopSound(6);
 								gameState = 8;
 								local_234 = 0;
 							}
@@ -479,7 +479,7 @@ void Minigame1::run() {
 							dustSpriteActor->priorityLayer = 3;
 							catActor->updateSequence(0xd);
 							gameState = 4;
-							_vm->playSound(6);
+							_vm->playOrStopSound(6);
 						}
 					}
 					if (catFieldE_scaleMaybe < 0x7f) {
@@ -511,7 +511,7 @@ void Minigame1::run() {
 							}
 							else {
 								catActor->updateSequence(0xf);
-								_vm->playSound(7);
+								_vm->playOrStopSound(7);
 								gameState = 6;
 							}
 						}
@@ -519,7 +519,7 @@ void Minigame1::run() {
 							dustSpriteActor->priorityLayer = 0;
 							catActor->priorityLayer = 3;
 							catActor->updateSequence(0xe);
-							_vm->playSound(8);
+							_vm->playOrStopSound(8);
 							local_23a = 0x40;
 						}
 					}
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 73f5356aeb..caf534f8e0 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -427,10 +427,10 @@ void Minigame3::run() {
 				bunnyActorTbl[local_1a]->updateSequence(5);
 				bunnyActorTbl[local_1c]->updateSequence(0xc);
 				if (hopCounter == 0x1d) {
-					_vm->playSound(2);
+					_vm->playOrStopSound(2);
 				}
 				else {
-					_vm->playSound((uint)local_1c2);
+					_vm->playOrStopSound((uint)local_1c2);
 					local_1c2 = 1 - local_1c2;
 				}
 				local_228 = 0;
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 5fb3c35db3..53e59d8acb 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -113,7 +113,7 @@ void Minigame4::run() {
 	_vm->_scene->loadScene(uVar1,0x1e);
 }
 
-void Minigame4::actorTalk(Actor *actorId,ushort param_2,uint32 textIndex)
+void Minigame4::actorTalk(Actor *actorId,uint16 param_2,uint32 textIndex)
 {
 	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
 	if (actorId == bruteActor) {
@@ -133,7 +133,7 @@ void Minigame4::actorTalk(Actor *actorId,ushort param_2,uint32 textIndex)
 	}
 }
 
-void Minigame4::actorDialog(Actor *actorId, ushort param_2, uint32 textIndex) {
+void Minigame4::actorDialog(Actor *actorId, uint16 param_2, uint32 textIndex) {
 	uint16 buf[1000];
 	_vm->_talk->loadText(textIndex, buf, 1000);
 	_vm->_talk->displayDialogAroundActor(actorId, param_2, buf, textIndex);
diff --git a/engines/dragons/minigame4.h b/engines/dragons/minigame4.h
index 37283fdaa5..4da35679f7 100644
--- a/engines/dragons/minigame4.h
+++ b/engines/dragons/minigame4.h
@@ -48,8 +48,8 @@ public:
 
 	void run();
 private:
-	void actorTalk(Actor *actorId,ushort param_2,uint32 textIndex);
-	void actorDialog(Actor *actorId,ushort param_2,uint32 textIndex);
+	void actorTalk(Actor *actorId,uint16 param_2,uint32 textIndex);
+	void actorDialog(Actor *actorId,uint16 param_2,uint32 textIndex);
 	uint16 runDanceBattle();
 	uint16 singleDanceRound(uint16 desiredPosition, uint16 duration);
 	void resetActors();
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index 615aeffd17..acdfd86dcf 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -219,7 +219,7 @@ void Minigame5::run() {
 										}
 										if (flickerActor->_sequenceID != 0x1a) {
 											flickerActor->updateSequence(0x1a);
-											_vm->playSound(2);
+											_vm->playOrStopSound(2);
 										}
 									}
 									else {
@@ -231,7 +231,7 @@ void Minigame5::run() {
 											}
 											if (flickerActor->_sequenceID != 0x1e) {
 												flickerActor->updateSequence(0x1e);
-												_vm->playSound(3);
+												_vm->playOrStopSound(3);
 											}
 										}
 										else {
@@ -243,7 +243,7 @@ void Minigame5::run() {
 												}
 												if (flickerActor->_sequenceID != 0x1f) {
 													flickerActor->updateSequence(0x1f);
-													_vm->playSound(4);
+													_vm->playOrStopSound(4);
 												}
 											}
 										}
@@ -281,7 +281,7 @@ void Minigame5::run() {
 									bombActor->y_pos = 0x5a;
 									local_70 = 0x100;
 									bombActor->scale = 0x100;
-									_vm->playSound(10);
+									_vm->playOrStopSound(10);
 									bombActor->priorityLayer = 3;
 									flickerActor->updateSequence(8);
 									currentState = 3;
@@ -289,7 +289,7 @@ void Minigame5::run() {
 							}
 							else {
 								flickerActor->updateSequence(0x1b);
-								_vm->playSound(1);
+								_vm->playOrStopSound(1);
 							}
 							break;
 						case 3:
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index e14b54dbc8..948e5b926e 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -31,6 +31,7 @@ MODULE_OBJS := \
 	sequenceopcodes.o \
 	specialopcodes.o \
 	sound.o \
+	VabSound.o \
 	talk.o
 
 MODULE_DIRS += \
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 805d09fdc5..672f620472 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -134,7 +134,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_vm->clearFlags(ENGINE_FLAG_100000);
 	_vm->clearFlags(ENGINE_FLAG_200000);
 
-	// TODO   UnkSoundFunc4(dragon_Rms_Offset[(uint)local_b0].sceneName);
+	_vm->loadCurrentSceneMsf();
 
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 1020166ed8..092596292f 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -568,7 +568,7 @@ void ScriptOpcodes::opUnkCSoundRelatedMaybe(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(soundId);
 
 	if (scriptOpCall._field8 == 0) {
-		_vm->playSound((uint16)soundId);
+		_vm->playOrStopSound((uint16) soundId);
 	}
 }
 
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index af1d3c1f20..e8fbea19da 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -212,7 +212,7 @@ void SequenceOpcodes::opPlaySound(Actor *actor, OpCall &opCall) {
 	ARG_INT16(soundId);
 	debug(5, "opPlaySound actorId: %d soundId: %d", actor->_actorID, soundId);
 
-	_vm->playSound((uint16)soundId);
+	_vm->playOrStopSound((uint16) soundId);
 	updateReturn(opCall, 1);
 }
 
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index dc4401bdb3..d3bbcdb7b6 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -26,6 +26,10 @@
 #include "audio/decoders/raw.h"
 #include "audio/decoders/xa.h"
 #include "common/file.h"
+#include "common/memstream.h"
+#include "bigfile.h"
+#include "dragonrms.h"
+#include "VabSound.h"
 
 #define RAW_CD_SECTOR_SIZE 2352
 
@@ -97,7 +101,7 @@ void Sound::playSpeech(uint32 textIndex) {
 	}
 	_audioTrack->getAudioStream()->finish();
 	_vm->setFlags(ENGINE_FLAG_8000);
-	_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, _audioTrack->getAudioStream());
+	_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, _audioTrack->getAudioStream(), -1, 0);
 	delete _audioTrack;
 }
 
@@ -249,4 +253,165 @@ void Sound::PSXAudioTrack::queueAudioFromSector(Common::SeekableReadStream *sect
 	delete[] buf;
 }
 
+SoundManager::SoundManager(DragonsEngine *vm, BigfileArchive *bigFileArchive, DragonRMS *dragonRMS)
+		: _vm(vm),
+		  _bigFileArchive(bigFileArchive),
+		  _dragonRMS(dragonRMS) {
+	// TODO: Set volumes
+	SomeInitSound_FUN_8003f64c();
+	loadMusAndGlob();
+}
+
+SoundManager::~SoundManager() {
+	delete _vabMusx;
+	delete _vabGlob;
+}
+
+void SoundManager::SomeInitSound_FUN_8003f64c() {
+	// TODO: Check if this changes on different game versions?
+	memset(_soundArr, 0x10, sizeof(_soundArr));
+
+	_soundArr[192] = 0x0b;
+	_soundArr[193] = 0x0b;
+	_soundArr[226] = _soundArr[226] | 0x80u;
+	_soundArr[229] = 0x0b;
+	_soundArr[230] = 0x0b;
+	_soundArr[450] = 0x0b;
+	_soundArr[451] = 0x0b;
+	_soundArr[514] = 0x8b;
+	_soundArr[515] = 0x0b;
+	_soundArr[516] = 0x0b;
+	_soundArr[578] = 0x0b;
+	_soundArr[579] = 0x0b;
+	_soundArr[580] = 0x0b;
+	_soundArr[611] = 0x0b;
+	_soundArr[674] = 0x8b;
+	_soundArr[675] = 0x88;
+	_soundArr[711] = 0x08;
+	_soundArr[866] = 0x0b;
+	_soundArr[896] = 0x0b;
+	_soundArr[897] = _soundArr[897] | 0x80u;
+	_soundArr[930] = _soundArr[930] | 0x80u;
+	_soundArr[934] = 0x8b;
+	_soundArr[935] = 0x8b;
+	_soundArr[936] = 0x0b;
+	_soundArr[937] = 0x88;
+	_soundArr[941] = 0x0b;
+	_soundArr[964] = 0x0b;
+	_soundArr[995] = _soundArr[995] | 0x80u;
+	_soundArr[1027] = 0x08;
+	_soundArr[1056] = 0x8b;
+	_soundArr[1059] = _soundArr[1059] | 0x80u;
+	_soundArr[1122] = 0x0b;
+	_soundArr[1250] = 0x08;
+	_soundArr[1252] = 0x0b;
+	_soundArr[1256] = 0x0b;
+	_soundArr[1257] = 0x08;
+	_soundArr[1258] = 0x0b;
+	_soundArr[1284] = 0x0b;
+	_soundArr[1378] = 0x0b;
+	_soundArr[1379] = _soundArr[1379] | 0x80u;
+	_soundArr[1380] = 0x0b;
+	_soundArr[1385] = 0x0b;
+	_soundArr[1443] = 0x8b;
+	_soundArr[1444] = _soundArr[1444] | 0x80u;
+	_soundArr[1445] = _soundArr[1445] | 0x80u;
+	_soundArr[1446] = 0x8b;
+	_soundArr[1472] = 0x8b;
+	_soundArr[1508] = _soundArr[1508] | 0x80u;
+	_soundArr[1575] = 0x08;
+	_soundArr[1576] = 0x08;
+	_soundArr[1577] = 0x08;
+	_soundArr[1604] = 0x08;
+	_soundArr[1605] = 0x08;
+	_soundArr[1610] = 0x0b;
+	_soundArr[1611] = 0x0b;
+	_soundArr[1612] = 0x0b;
+}
+
+void SoundManager::loadMusAndGlob() {
+	_vabMusx = loadVab("musx.vh", "musx.vb");
+	_vabGlob = loadVab("glob.vh", "glob.vb");
+}
+
+VabSound * SoundManager::loadVab(const char *headerFilename, const char *bodyFilename) {
+	uint32 headSize, bodySize;
+
+	auto headData = _bigFileArchive->load(headerFilename, headSize);
+	auto bodyData = _bigFileArchive->load(bodyFilename, bodySize);
+
+	auto *headStream = new Common::MemoryReadStream(headData, headSize, DisposeAfterUse::YES);
+	auto *bodyStream = new Common::MemoryReadStream(bodyData, bodySize, DisposeAfterUse::YES);
+
+	return new VabSound(headStream, bodyStream);
+}
+
+/**
+ *
+ * @param soundId Bit 0x4000 set indicates STOP SOUND, bit 0x8000 set indicates SOUND IS GLOBAL (comes from glob.v[hb])
+ */
+void SoundManager::playOrStopSound(uint16 soundId) {
+	uint16 volumeId;
+	if ((soundId & 0x8000u) == 0) {
+		volumeId = soundId + _vm->getCurrentSceneId() * 0x20;
+	} else {
+		volumeId = soundId & 0x7fffu;
+	}
+
+	if ((soundId & 0x4000u) == 0) {
+		playSound(soundId, volumeId);
+	} else {
+		stopSound(soundId, volumeId);
+	}
+}
+
+void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
+	byte volume = 0;
+
+	volume = _soundArr[volumeId];
+	_soundArr[volumeId] = _soundArr[volumeId] | 0x40u;      // Set bit 0x40
+
+	auto vabSound = ((soundId & 0x8000u) != 0) ? _vabGlob : _vabMusx;
+
+	// TODO: CdVolume!
+	auto cdVolume = 1;
+	auto newVolume = cdVolume * volume;
+	if (newVolume < 0) {
+		newVolume += 0xf;
+	}
+
+	auto realId = soundId & 0x7fffu;
+
+	auto program = realId >> 4u;
+	auto key = ((realId & 0xfu) << 1u | 0x40u);
+
+	// TODO: Volume
+	vabSound->playSound(program, key);
+}
+
+void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
+	_soundArr[volumeId] = _soundArr[volumeId] & 0xbfu;      // Clear bit 0x40
+
+	auto vabId = getVabFromSoundId(soundId);
+	// TODO: Actually stop sound
+}
+
+uint16 SoundManager::getVabFromSoundId(uint16 soundId) {
+	// TODO
+	return -1;
+}
+
+void SoundManager::loadMsf(uint32 sceneId) {
+	char msfFileName[] = "XXXX.MSF";
+	memcpy(msfFileName, _dragonRMS->getSceneName(sceneId), 4);
+
+	uint32 msfSize;
+	byte *msfData = _bigFileArchive->load(msfFileName, msfSize);
+
+	auto *msfStream = new Common::MemoryReadStream(msfData, msfSize, DisposeAfterUse::YES);
+
+	delete _vabMusx;
+	_vabMusx = new VabSound(msfStream, _vm);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index 18e13fb658..d199840306 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -30,6 +30,9 @@
 namespace Dragons {
 
 class DragonsEngine;
+class BigfileArchive;
+class DragonRMS;
+class VabSound;
 struct SpeechLocation;
 
 class Sound {
@@ -66,6 +69,39 @@ private:
 	};
 };
 
+class SoundManager {
+public:
+	SoundManager(DragonsEngine *vm, BigfileArchive* bigFileArchive, DragonRMS *dragonRms);
+	~SoundManager();
+
+	void loadMsf(uint32 sceneId);
+	void playOrStopSound(uint16 soundId);
+
+private:
+	const DragonsEngine *_vm;
+	BigfileArchive *_bigFileArchive;
+	DragonRMS *_dragonRMS;
+
+	// SOUND_ARR_DAT_80071f6c
+	uint8_t _soundArr[0x780];
+
+	VabSound* _vabMusx;
+	VabSound* _vabGlob;
+
+private:
+	void SomeInitSound_FUN_8003f64c();
+
+	void loadMusAndGlob();
+
+	void playSound(uint16 soundId, uint16 i);
+
+	void stopSound(uint16 id, uint16 i);
+
+	uint16 getVabFromSoundId(uint16 id);
+
+	VabSound * loadVab(const char *headerFilename, const char *bodyFilename);
+};
+
 } // End of namespace Dragons
 
 #endif //DRAGONS_SOUND_H
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 1cd951f0e9..d25bb71272 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -69,7 +69,15 @@ void Talk::printWideText(byte *text) {
 	char buf[2000];
 	int i = 0;
 	for (; READ_LE_INT16(text) != 0 && i < 1999; i++) {
-		buf[i] = *text;
+	    auto c = *text;
+	    if (c < 0x20) {
+	        buf[i++] = '0';
+	        buf[i++] = 'x';
+	        buf[i++] = (c & 0xF0 >> 4) + '0';
+	        buf[i] = (c & 0x0F) + '0';
+	    } else {
+            buf[i] = *text;
+        }
 		text += 2;
 	}
 	buf[i] = 0;
@@ -722,7 +730,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 	}
 	if (local_50 != -2) {
 		if (_vm->checkForActionButtonRelease()) {
-			_vm->playSound(0x800a);
+			_vm->playOrStopSound(0x800a);
 
 			_vm->clearFlags(ENGINE_FLAG_8);
 			y = 0;
@@ -753,7 +761,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 		_vm->checkForDownKeyRelease()) {
 		uVar8 = uVar8 + 1;
 		LAB_800319a0:
-		_vm->playSound(0x8009);
+		_vm->playOrStopSound(0x8009);
 		LAB_800319a8:
 		y = 0x18 - local_58;
 		local_50 = -1;


Commit: ddcec20428c97e45595b0cf2b69c9bb7dd8aec3c
    https://github.com/scummvm/scummvm/commit/ddcec20428c97e45595b0cf2b69c9bb7dd8aec3c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Merged two sound classes

Changed paths:
    engines/dragons/VabSound.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/module.mk
    engines/dragons/sound.cpp
    engines/dragons/sound.h


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
index 6c42969cd4..799cd8b482 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/VabSound.cpp
@@ -8,18 +8,18 @@
 #include "dragons.h"
 
 namespace Dragons {
-	VabSound::VabSound(Common::SeekableReadStream *msfData, const DragonsEngine *_vm) {
+	VabSound::VabSound(Common::SeekableReadStream *msfData, const DragonsEngine *_vm): _toneAttrs(NULL), _vbData(NULL) {
 		loadHeader(msfData);
 
 		auto dataSize = msfData->size() - msfData->pos();
 		byte *newData = new byte[dataSize];
 		msfData->read(newData, dataSize);
 
-		_vbData = new Common::MemoryReadStream(newData, dataSize, DisposeAfterUse::YES);
-
-		Audio::AudioStream *str = Audio::makeXAStream(_vbData, 11025);
-		Audio::SoundHandle _speechHandle;
-		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speechHandle, str);
+//		_vbData = new Common::MemoryReadStream(newData, dataSize, DisposeAfterUse::YES);
+//
+//		Audio::AudioStream *str = Audio::makeXAStream(_vbData, 11025);
+//		Audio::SoundHandle _speechHandle;
+//		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speechHandle, str);
 
 		delete msfData;
 	}
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 8fa788b5c6..8f0d92f476 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -69,7 +69,6 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_cursor = new Cursor(this);
 	_credits = NULL;
 	_talk = NULL;
-	_sound = new Sound(this);
 	_fontManager = NULL;
 	_sceneUpdateFunction = NULL;
 	_vsyncUpdateFunction = NULL;
@@ -206,7 +205,7 @@ Common::Error DragonsEngine::run() {
 	_backgroundResourceLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
 	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource, _backgroundResourceLoader);
 
-	_soundManager = new SoundManager(this, _bigfileArchive, _dragonRMS);
+	_sound = new SoundManager(this, _bigfileArchive, _dragonRMS);
 
 	if (ConfMan.hasKey("save_slot")) {
 		loadGameState(ConfMan.getInt("save_slot"));
@@ -229,7 +228,7 @@ Common::Error DragonsEngine::run() {
 	delete _fontManager;
 	delete _bigfileArchive;
 	delete _screen;
-	delete _soundManager;
+	delete _sound;
 
 	debug("Ok");
 	return Common::kNoError;
@@ -1011,7 +1010,7 @@ void DragonsEngine::waitForFramesAllowSkip(uint16 numFrames) {
 void DragonsEngine::playOrStopSound(uint16 soundId) {
 	debug("play sound 0x%x", soundId);
 
-	this->_soundManager->playOrStopSound(soundId);
+	this->_sound->playOrStopSound(soundId);
 }
 
 void DragonsEngine::updatePathfindingActors() {
@@ -1399,7 +1398,7 @@ void DragonsEngine::runVsyncUpdaterFunction() {
 }
 
 void DragonsEngine::loadCurrentSceneMsf() {
-	_soundManager->loadMsf(getCurrentSceneId());
+	_sound->loadMsf(getCurrentSceneId());
 }
 
 void (*DragonsEngine::getSceneUpdateFunction())() {
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 4d7ed222f9..30e021b030 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -122,7 +122,6 @@ class ActorManager;
 class SequenceOpcodes;
 class ScriptOpcodes;
 class Talk;
-class Sound;
 class SoundManager;
 struct DragonINI;
 
@@ -142,8 +141,7 @@ public:
 	Cursor *_cursor;
 	Credits *_credits;
 	Talk *_talk;
-	Sound *_sound;
-	SoundManager *_soundManager;
+	SoundManager *_sound;
 
 	opCode1AStruct opCode1A_tbl[8];
 
diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 948e5b926e..81d8559741 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -31,8 +31,8 @@ MODULE_OBJS := \
 	sequenceopcodes.o \
 	specialopcodes.o \
 	sound.o \
-	VabSound.o \
-	talk.o
+	talk.o \
+	VabSound.o
 
 MODULE_DIRS += \
 	engines/dragons
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index d3bbcdb7b6..f9805014f3 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -46,10 +46,6 @@ struct SpeechLocation {
 	uint16 sectorEnd;
 } SpeechLocation;
 
-Sound::Sound(DragonsEngine *vm): _vm(vm) {
-	DAT_8006bb60_sound_related = 0;
-}
-
 void CdIntToPos_0(uint32 param_1)//, byte *param_2)
 {
 	int iVar1;
@@ -77,7 +73,7 @@ void CdIntToPos_0(uint32 param_1)//, byte *param_2)
 	return;
 }
 
-void Sound::playSpeech(uint32 textIndex) {
+void SoundManager::playSpeech(uint32 textIndex) {
 	if (isSpeechPlaying()) {
 //		_vm->_mixer->stopHandle(_speechHandle);
 		return;
@@ -101,15 +97,15 @@ void Sound::playSpeech(uint32 textIndex) {
 	}
 	_audioTrack->getAudioStream()->finish();
 	_vm->setFlags(ENGINE_FLAG_8000);
-	_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, _audioTrack->getAudioStream(), -1, 0);
+	_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, _audioTrack->getAudioStream());
 	delete _audioTrack;
 }
 
-bool Sound::isSpeechPlaying() {
+bool SoundManager::isSpeechPlaying() {
 	return _vm->_mixer->isSoundHandleActive(_speechHandle);
 }
 
-bool Sound::getSpeechLocation(uint32 talkId, struct SpeechLocation *location) {
+bool SoundManager::getSpeechLocation(uint32 talkId, struct SpeechLocation *location) {
 	Common::File *fd = new Common::File();
 	if (!fd->open("dragon.exe")) {
 		error("Failed to open dragon.exe");
@@ -139,11 +135,11 @@ bool Sound::getSpeechLocation(uint32 talkId, struct SpeechLocation *location) {
 	return foundId;
 }
 
-void Sound::PauseCDMusic() {
+void SoundManager::PauseCDMusic() {
 	//TODO PauseCDMusic()
 }
 
-Sound::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType) {
+SoundManager::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType) {
 	sector->skip(19);
 	byte format = sector->readByte();
 	bool stereo = (format & (1 << 0)) != 0;
@@ -153,7 +149,7 @@ Sound::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::M
 	memset(&_adpcmStatus, 0, sizeof(_adpcmStatus));
 }
 
-Sound::PSXAudioTrack::~PSXAudioTrack() {
+SoundManager::PSXAudioTrack::~PSXAudioTrack() {
 }
 
 // Ha! It's palindromic!
@@ -168,7 +164,7 @@ static const int s_xaTable[5][2] = {
 		{ 122, -60 }
 };
 
-void Sound::PSXAudioTrack::queueAudioFromSector(Common::SeekableReadStream *sector) {
+void SoundManager::PSXAudioTrack::queueAudioFromSector(Common::SeekableReadStream *sector) {
 	sector->skip(24);
 
 	// This XA audio is different (yet similar) from normal XA audio! Watch out!
@@ -257,6 +253,7 @@ SoundManager::SoundManager(DragonsEngine *vm, BigfileArchive *bigFileArchive, Dr
 		: _vm(vm),
 		  _bigFileArchive(bigFileArchive),
 		  _dragonRMS(dragonRMS) {
+	DAT_8006bb60_sound_related = 0;
 	// TODO: Set volumes
 	SomeInitSound_FUN_8003f64c();
 	loadMusAndGlob();
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index d199840306..ef36370815 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -35,40 +35,6 @@ class DragonRMS;
 class VabSound;
 struct SpeechLocation;
 
-class Sound {
-private:
-	DragonsEngine *_vm;
-	Audio::SoundHandle _speechHandle;
-public:
-	uint16 DAT_8006bb60_sound_related;
-
-public:
-	Sound(DragonsEngine *vm);
-	void playSpeech(uint32 textIndex);
-	bool isSpeechPlaying();
-	void PauseCDMusic();
-private:
-	bool getSpeechLocation(uint32 talkId, struct SpeechLocation *location);
-
-private:
-	class PSXAudioTrack {
-	public:
-		PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
-		~PSXAudioTrack();
-
-		void queueAudioFromSector(Common::SeekableReadStream *sector);
-		Audio::QueuingAudioStream *getAudioStream() {
-			return _audStream;
-		}
-	private:
-		Audio::QueuingAudioStream *_audStream;
-
-		struct ADPCMStatus {
-			int16 sample[2];
-		} _adpcmStatus[2];
-	};
-};
-
 class SoundManager {
 public:
 	SoundManager(DragonsEngine *vm, BigfileArchive* bigFileArchive, DragonRMS *dragonRms);
@@ -77,8 +43,15 @@ public:
 	void loadMsf(uint32 sceneId);
 	void playOrStopSound(uint16 soundId);
 
+	void playSpeech(uint32 textIndex);
+	bool isSpeechPlaying();
+	void PauseCDMusic();
+
+public:
+	uint16 DAT_8006bb60_sound_related;
+
 private:
-	const DragonsEngine *_vm;
+	DragonsEngine *_vm;
 	BigfileArchive *_bigFileArchive;
 	DragonRMS *_dragonRMS;
 
@@ -88,6 +61,8 @@ private:
 	VabSound* _vabMusx;
 	VabSound* _vabGlob;
 
+	Audio::SoundHandle _speechHandle;
+
 private:
 	void SomeInitSound_FUN_8003f64c();
 
@@ -100,6 +75,26 @@ private:
 	uint16 getVabFromSoundId(uint16 id);
 
 	VabSound * loadVab(const char *headerFilename, const char *bodyFilename);
+
+	bool getSpeechLocation(uint32 talkId, struct SpeechLocation *location);
+
+private:
+	class PSXAudioTrack {
+	public:
+		PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType);
+		~PSXAudioTrack();
+
+		void queueAudioFromSector(Common::SeekableReadStream *sector);
+		Audio::QueuingAudioStream *getAudioStream() {
+			return _audStream;
+		}
+	private:
+		Audio::QueuingAudioStream *_audStream;
+
+		struct ADPCMStatus {
+			int16 sample[2];
+		} _adpcmStatus[2];
+	};
 };
 
 } // End of namespace Dragons


Commit: f9db411416edc0df0168624e7e42304beb8ca2f0
    https://github.com/scummvm/scummvm/commit/f9db411416edc0df0168624e7e42304beb8ca2f0
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on sfx

Changed paths:
    engines/dragons/VabSound.cpp
    engines/dragons/VabSound.h
    engines/dragons/sound.cpp
    engines/dragons/sound.h


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
index 799cd8b482..59ae550739 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/VabSound.cpp
@@ -1,3 +1,24 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
 #include <common/textconsole.h>
 #include <common/debug.h>
 #include <audio/decoders/xa.h>
@@ -12,8 +33,8 @@ namespace Dragons {
 		loadHeader(msfData);
 
 		auto dataSize = msfData->size() - msfData->pos();
-		byte *newData = new byte[dataSize];
-		msfData->read(newData, dataSize);
+		_vbData = new byte[dataSize];
+		msfData->read(_vbData, dataSize);
 
 //		_vbData = new Common::MemoryReadStream(newData, dataSize, DisposeAfterUse::YES);
 //
@@ -24,17 +45,21 @@ namespace Dragons {
 		delete msfData;
 	}
 
-	VabSound::VabSound(Common::SeekableReadStream *vhData, Common::SeekableReadStream *vbData): _vbData(vbData) {
+	VabSound::VabSound(Common::SeekableReadStream *vhData, Common::SeekableReadStream *vbData): _toneAttrs(NULL), _vbData(NULL) {
 		loadHeader(vhData);
 
 		assert(vhData->pos() == vhData->size());
 
+		_vbData = new byte[vbData->size()];
+		vbData->read(_vbData, vbData->size());
+
 		delete vhData;
+		delete vbData;
 	}
 
 	void VabSound::loadHeader(Common::SeekableReadStream *vhData) {
 		vhData->seek(0);
-		vhData->read(&_header, sizeof(_header));
+		vhData->read(&_header, sizeof(_header)); //TODO this is not endian safe!
 		if (strncmp(_header.magic, "pBAV", 4) != 0) {
 			error("Invalid VAB file");
 		}
@@ -60,8 +85,20 @@ namespace Dragons {
 		delete _vbData;
 	}
 
-	void VabSound::playSound(uint16 program, uint16 key) {
+	Audio::AudioStream *VabSound::getAudioStream(uint16 program, uint16 key) {
+		assert(program < _header.numVAG);
 		// TODO
-		debug("Playing program %d, key %d", program, key);
+		uint16 vagID = 0;
+		for (int i = 0; i < _header.numPrograms * 16; i++) {
+			if (_toneAttrs[i].prog == program) {
+				vagID = _toneAttrs[i].vag;
+			}
+		}
+		debug("Playing program %d, numTones: %d, key %d vagID %d, vagOffset: %x, size: %x", program, _programAttrs[program].tones, key, vagID, _vagOffsets[vagID], _vagSizes[vagID]);
+		Audio::AudioStream *str = Audio::makeXAStream(
+				new Common::MemoryReadStream(&_vbData[_vagOffsets[vagID]], _vagSizes[vagID], DisposeAfterUse::NO),
+				11025,
+				DisposeAfterUse::YES);
+		return str;
 	}
 } // End of namespace Dragons
\ No newline at end of file
diff --git a/engines/dragons/VabSound.h b/engines/dragons/VabSound.h
index 9063d3bcc7..901e9e18e0 100644
--- a/engines/dragons/VabSound.h
+++ b/engines/dragons/VabSound.h
@@ -1,6 +1,24 @@
-//
-// Created by Edu García on 2019-07-25.
-//
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 DRAGONS_VABSOUND_H
 #define DRAGONS_VABSOUND_H
@@ -11,6 +29,10 @@ namespace Common {
 	class SeekableReadStream;
 }
 
+namespace Audio {
+	class AudioStream;
+}
+
 namespace Dragons {
 class DragonsEngine;
 
@@ -88,10 +110,10 @@ public:
 
 	~VabSound();
 
-	void playSound(uint16 program, uint16 key);
+	Audio::AudioStream *getAudioStream(uint16 program, uint16 key);
 
 private:
-	Common::SeekableReadStream *_vbData;
+	byte *_vbData;
 
 	VabHeader _header;
 	VabProgramAttr _programAttrs[128];
@@ -105,4 +127,4 @@ private:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_VABSOUND_H
+#endif //DRAGONS_VABSOUND_H
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index f9805014f3..61afe149d7 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -383,7 +383,9 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
 	auto key = ((realId & 0xfu) << 1u | 0x40u);
 
 	// TODO: Volume
-	vabSound->playSound(program, key);
+	if (!_vm->_mixer->isSoundHandleActive(_sfxHandle)) {
+		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, vabSound->getAudioStream(program, key));
+	}
 }
 
 void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
@@ -391,6 +393,7 @@ void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
 
 	auto vabId = getVabFromSoundId(soundId);
 	// TODO: Actually stop sound
+	_vm->_mixer->stopHandle(_sfxHandle);
 }
 
 uint16 SoundManager::getVabFromSoundId(uint16 soundId) {
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index ef36370815..2be7033c8f 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -62,6 +62,7 @@ private:
 	VabSound* _vabGlob;
 
 	Audio::SoundHandle _speechHandle;
+	Audio::SoundHandle _sfxHandle;
 
 private:
 	void SomeInitSound_FUN_8003f64c();


Commit: 8d9dc0138ef12218a6e46f17703951ba2d77438b
    https://github.com/scummvm/scummvm/commit/8d9dc0138ef12218a6e46f17703951ba2d77438b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed timing on final backstage scene

Changed paths:
    engines/dragons/credits.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/sound.cpp
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/credits.cpp b/engines/dragons/credits.cpp
index 27eb3f6d41..021319ed85 100644
--- a/engines/dragons/credits.cpp
+++ b/engines/dragons/credits.cpp
@@ -71,12 +71,11 @@ void Credits::cleanup() {
 void Credits::update() {
 	uint16 line[41];
 	if (_updateCounter == 0) {
-		_updateCounter = 3;
+		_updateCounter = 2;
 		_yOffset = (_yOffset + 1) % 208;
 		if (_yOffset % 8 == 0) {
 			if (_curPosition <= _dataLength) {
 				uint32 length = strlen(_curPtr);
-				//TODO add line here.
 				debug("Credit line: %s", _curPtr);
 				convertToWideChar(line, (byte *)_curPtr, 40);
 				_curPtr += length + 1;
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index caf534f8e0..499a5da9b6 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -27,6 +27,7 @@
 #include "dragons/inventory.h"
 #include "dragons/scene.h"
 #include "dragons/screen.h"
+#include "dragons/sound.h"
 #include "dragons/talk.h"
 #include "dragons.h"
 
@@ -751,7 +752,7 @@ void Minigame3::run() {
 		_vm->_dragonINIResource->getRecord(0x178)->field_14 = 0;
 	}
 	_vm->waitForFrames(0x3c * 2);
-//	PauseCDMusic();
+	_vm->_sound->PauseCDMusic();
 //	fade_related_calls_with_1f();
 //	FUN_80017f28_noop();
 //	DAT_80093234 = DAT_80093234 + 1;
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 092596292f..aff8ac306b 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -32,6 +32,7 @@
 #include "dragons/scriptopcodes.h"
 #include "dragons/specialopcodes.h"
 #include "dragons/actor.h"
+#include "dragons/sound.h"
 #include "dragons/talk.h"
 #include "scriptopcodes.h"
 
@@ -128,7 +129,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x1E, opUnk1ESetActorFlag0x400);
 	OPCODE(0x1F, opPlayMusic);
 	OPCODE(0x20, opUnk20);
-	OPCODE(0x21, opUnk21);
+	OPCODE(0x21, opPauseCurrentSpeechAndFetchNextDialog);
 	OPCODE(0x22, opCodeActorTalk);
 }
 
@@ -443,12 +444,13 @@ void ScriptOpcodes::opUnk20(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-void ScriptOpcodes::opUnk21(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opPauseCurrentSpeechAndFetchNextDialog(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_UINT32(textIndex);
 
 	if (scriptOpCall._field8 == 0) {
-		//TODO play dialog audio without text on screen.
+		_vm->_sound->PauseCDMusic();
+		//The original starts seeking the CD-ROM here for the `textIndex` dialog but we don't need to do that.
 	}
 }
 
@@ -818,7 +820,7 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 
 	//TODO fade_related_calls_with_1f();
 	_vm->setSceneUpdateFunction(NULL);
-	// PauseCDMusic();
+	_vm->_sound->PauseCDMusic();
 
 	if (newSceneID != 0) {
 		// load scene here.
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index bb7881e97f..c3216799bb 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -116,7 +116,7 @@ protected:
 	void opSetActorFlag0x1000(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
 	void opUnk20(ScriptOpCall &scriptOpCall);
-	void opUnk21(ScriptOpCall &scriptOpCall);
+	void opPauseCurrentSpeechAndFetchNextDialog(ScriptOpCall &scriptOpCall);
 
 	bool evaluateExpression(ScriptOpCall &scriptOpCall);
 	void opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall);
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index 61afe149d7..7c6cde0612 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -96,6 +96,8 @@ void SoundManager::playSpeech(uint32 textIndex) {
 		_audioTrack->queueAudioFromSector(fd);
 	}
 	_audioTrack->getAudioStream()->finish();
+	fd->close();
+	delete fd;
 	_vm->setFlags(ENGINE_FLAG_8000);
 	_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, _audioTrack->getAudioStream());
 	delete _audioTrack;
@@ -136,7 +138,11 @@ bool SoundManager::getSpeechLocation(uint32 talkId, struct SpeechLocation *locat
 }
 
 void SoundManager::PauseCDMusic() {
-	//TODO PauseCDMusic()
+	//TODO check PauseCDMusic() to see if we need any more logic.
+	if(isSpeechPlaying()) {
+		_vm->_mixer->stopHandle(_speechHandle);
+		_vm->clearFlags(ENGINE_FLAG_8000);
+	}
 }
 
 SoundManager::PSXAudioTrack::PSXAudioTrack(Common::SeekableReadStream *sector, Audio::Mixer::SoundType soundType) {
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 27bffc326f..4e58db93c2 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -31,6 +31,7 @@
 #include "dragons/inventory.h"
 #include "dragons/specialopcodes.h"
 #include "dragons/scene.h"
+#include "dragons/sound.h"
 #include "dragons/actor.h"
 #include "dragons/minigame1.h"
 #include "dragons/talk.h"
@@ -285,7 +286,7 @@ void SpecialOpcodes::spcLadyOfTheLakeCapturedSceneLogic() {
 void SpecialOpcodes::spcStopLadyOfTheLakeCapturedSceneLogic() {
 	_vm->setSceneUpdateFunction(NULL);
 // TODO
-//	PauseCDMusic();
+	_vm->_sound->PauseCDMusic();
 //	if ((DAT_80083148 != 0) || (DAT_80083154 != 0)) {
 //		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
 //	}


Commit: aac561c124768583ab91577449ce8d92fc15495e
    https://github.com/scummvm/scummvm/commit/aac561c124768583ab91577449ce8d92fc15495e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Hooked up correct sfx tone

Changed paths:
    engines/dragons/VabSound.cpp
    engines/dragons/bigfile.cpp
    engines/dragons/bigfile.h
    engines/dragons/sound.cpp


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
index 59ae550739..abce2632d0 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/VabSound.cpp
@@ -89,9 +89,9 @@ namespace Dragons {
 		assert(program < _header.numVAG);
 		// TODO
 		uint16 vagID = 0;
-		for (int i = 0; i < _header.numPrograms * 16; i++) {
-			if (_toneAttrs[i].prog == program) {
-				vagID = _toneAttrs[i].vag;
+		for (int i = 0; i < _programAttrs[program].tones; i++) {
+			if (_toneAttrs[i].prog == program && _toneAttrs[i].min == key && _toneAttrs[i].max == key) {
+				vagID = _toneAttrs[i].vag - 1;
 			}
 		}
 		debug("Playing program %d, numTones: %d, key %d vagID %d, vagOffset: %x, size: %x", program, _programAttrs[program].tones, key, vagID, _vagOffsets[vagID], _vagSizes[vagID]);
@@ -101,4 +101,4 @@ namespace Dragons {
 				DisposeAfterUse::YES);
 		return str;
 	}
-} // End of namespace Dragons
\ No newline at end of file
+} // End of namespace Dragons
diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
index 723158d7b6..6651c340de 100644
--- a/engines/dragons/bigfile.cpp
+++ b/engines/dragons/bigfile.cpp
@@ -633,7 +633,7 @@ BigfileArchive::~BigfileArchive() {
 byte *BigfileArchive::load(const char *filename, uint32 &dataSize) {
 	uint32 id = getResourceId(filename);
 	if (id >= TOTAL_FILES) {
-		error("Invalid resourceID");
+		error("Invalid resourceID for input filename: %s", filename);
 	}
 
 	dataSize = fileInfo[id].size;
@@ -646,6 +646,10 @@ byte *BigfileArchive::load(const char *filename, uint32 &dataSize) {
 	return buf;
 }
 
+bool BigfileArchive::doesFileExist(const char *filename) {
+	uint32 id = getResourceId(filename);
+	return (id < TOTAL_FILES);
+}
 
 
 } // End of namespace Illusions
diff --git a/engines/dragons/bigfile.h b/engines/dragons/bigfile.h
index 6b3208c053..819dfbe042 100644
--- a/engines/dragons/bigfile.h
+++ b/engines/dragons/bigfile.h
@@ -36,6 +36,7 @@ public:
 	virtual ~BigfileArchive();
 
 	byte *load(const char *filename, uint32 &dataSize);
+	bool doesFileExist(const char *filename);
 };
 
 } // End of namespace dragons
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index 7c6cde0612..c36d25ed58 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -411,13 +411,15 @@ void SoundManager::loadMsf(uint32 sceneId) {
 	char msfFileName[] = "XXXX.MSF";
 	memcpy(msfFileName, _dragonRMS->getSceneName(sceneId), 4);
 
-	uint32 msfSize;
-	byte *msfData = _bigFileArchive->load(msfFileName, msfSize);
+	if (_bigFileArchive->doesFileExist(msfFileName)) {
+		uint32 msfSize;
+		byte *msfData = _bigFileArchive->load(msfFileName, msfSize);
 
-	auto *msfStream = new Common::MemoryReadStream(msfData, msfSize, DisposeAfterUse::YES);
+		auto *msfStream = new Common::MemoryReadStream(msfData, msfSize, DisposeAfterUse::YES);
 
-	delete _vabMusx;
-	_vabMusx = new VabSound(msfStream, _vm);
+		delete _vabMusx;
+		_vabMusx = new VabSound(msfStream, _vm);
+	}
 }
 
 } // End of namespace Dragons


Commit: bcdad1a6063586dc92815c6299b8a83ef78a59d6
    https://github.com/scummvm/scummvm/commit/bcdad1a6063586dc92815c6299b8a83ef78a59d6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: work on playing multiple sfx at once

Changed paths:
    engines/dragons/sound.cpp
    engines/dragons/sound.h


diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index c36d25ed58..40dfd0a341 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -389,17 +389,22 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
 	auto key = ((realId & 0xfu) << 1u | 0x40u);
 
 	// TODO: Volume
-	if (!_vm->_mixer->isSoundHandleActive(_sfxHandle)) {
-		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, vabSound->getAudioStream(program, key));
+	if (!isVoicePlaying(program, key)) {
+		Audio::SoundHandle *handle = getVoiceHandle(program, key);
+		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, key));
 	}
 }
 
 void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
 	_soundArr[volumeId] = _soundArr[volumeId] & 0xbfu;      // Clear bit 0x40
 
-	auto vabId = getVabFromSoundId(soundId);
-	// TODO: Actually stop sound
-	_vm->_mixer->stopHandle(_sfxHandle);
+//	auto vabId = getVabFromSoundId(soundId);
+
+	auto realId = soundId & 0x3fffu;
+
+	auto program = realId >> 4u;
+	auto key = ((realId & 0xfu) << 1u | 0x40u);
+	stopVoicePlaying(program, key);
 }
 
 uint16 SoundManager::getVabFromSoundId(uint16 soundId) {
@@ -422,4 +427,32 @@ void SoundManager::loadMsf(uint32 sceneId) {
 	}
 }
 
+bool SoundManager::isVoicePlaying(uint16 program, uint16 key) {
+	for (int i = 0; i < NUM_VOICES; i++) {
+		if (_voice[i].program == program && _voice[i].key == key && _vm->_mixer->isSoundHandleActive(_voice[i].handle)) {
+			return true;
+		}
+	}
+	return false;
+}
+
+Audio::SoundHandle *SoundManager::getVoiceHandle(uint16 program, uint16 key) {
+	for (int i = 0; i < NUM_VOICES; i++) {
+		if (!_vm->_mixer->isSoundHandleActive(_voice[i].handle)) {
+			_voice[i].program = program;
+			_voice[i].key = key;
+			return &_voice[i].handle;
+		}
+	}
+}
+
+void SoundManager::stopVoicePlaying(uint16 program, uint16 key) {
+	for (int i = 0; i < NUM_VOICES; i++) {
+		if (_voice[i].program == program && _voice[i].key == key) {
+			_vm->_mixer->stopHandle(_voice[i].handle);
+			return;
+		}
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index 2be7033c8f..b77b057a23 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -35,6 +35,19 @@ class DragonRMS;
 class VabSound;
 struct SpeechLocation;
 
+typedef struct Voice {
+	int16 program;
+	int16 key;
+	Audio::SoundHandle handle;
+
+	Voice() {
+		program = -1;
+		key = -1;
+	}
+} Voice;
+
+#define NUM_VOICES 25
+
 class SoundManager {
 public:
 	SoundManager(DragonsEngine *vm, BigfileArchive* bigFileArchive, DragonRMS *dragonRms);
@@ -62,7 +75,7 @@ private:
 	VabSound* _vabGlob;
 
 	Audio::SoundHandle _speechHandle;
-	Audio::SoundHandle _sfxHandle;
+	Voice _voice[NUM_VOICES];
 
 private:
 	void SomeInitSound_FUN_8003f64c();
@@ -78,6 +91,9 @@ private:
 	VabSound * loadVab(const char *headerFilename, const char *bodyFilename);
 
 	bool getSpeechLocation(uint32 talkId, struct SpeechLocation *location);
+	bool isVoicePlaying(uint16 program, uint16 key);
+	Audio::SoundHandle *getVoiceHandle(uint16 program, uint16 key);
+	void stopVoicePlaying(uint16 program, uint16 key);
 
 private:
 	class PSXAudioTrack {


Commit: 2abd8b6f102196a8eddfe99f06090fa1c3bace9c
    https://github.com/scummvm/scummvm/commit/2abd8b6f102196a8eddfe99f06090fa1c3bace9c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed bug when looking at objects. Stop sfx if already playing before starting it again.

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/sound.cpp
    engines/dragons/sound.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 09d86292b7..53f03f128b 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -328,7 +328,7 @@ void Cursor::selectPreviousCursor() {
 		_sequenceID = 1;
 	}
 	if (_sequenceID == 2) {
-		_sequenceID = 0x10001;
+		_sequenceID = 1;
 	}
 	if (_sequenceID == -1) {
 		_sequenceID = iniItemInHand == 0 ? 4 : 5;
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index 40dfd0a341..cd2fb636cb 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -389,10 +389,12 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
 	auto key = ((realId & 0xfu) << 1u | 0x40u);
 
 	// TODO: Volume
-	if (!isVoicePlaying(program, key)) {
-		Audio::SoundHandle *handle = getVoiceHandle(program, key);
-		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, key));
+	if (isVoicePlaying(soundId)) {
+		stopVoicePlaying(soundId);
 	}
+
+		Audio::SoundHandle *handle = getVoiceHandle(soundId);
+		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, key));
 }
 
 void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
@@ -400,11 +402,7 @@ void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
 
 //	auto vabId = getVabFromSoundId(soundId);
 
-	auto realId = soundId & 0x3fffu;
-
-	auto program = realId >> 4u;
-	auto key = ((realId & 0xfu) << 1u | 0x40u);
-	stopVoicePlaying(program, key);
+	stopVoicePlaying(soundId & ~0x4000u);
 }
 
 uint16 SoundManager::getVabFromSoundId(uint16 soundId) {
@@ -427,28 +425,27 @@ void SoundManager::loadMsf(uint32 sceneId) {
 	}
 }
 
-bool SoundManager::isVoicePlaying(uint16 program, uint16 key) {
+bool SoundManager::isVoicePlaying(uint16 soundID) {
 	for (int i = 0; i < NUM_VOICES; i++) {
-		if (_voice[i].program == program && _voice[i].key == key && _vm->_mixer->isSoundHandleActive(_voice[i].handle)) {
+		if (_voice[i].soundID == soundID && _vm->_mixer->isSoundHandleActive(_voice[i].handle)) {
 			return true;
 		}
 	}
 	return false;
 }
 
-Audio::SoundHandle *SoundManager::getVoiceHandle(uint16 program, uint16 key) {
+Audio::SoundHandle *SoundManager::getVoiceHandle(uint16 soundID) {
 	for (int i = 0; i < NUM_VOICES; i++) {
 		if (!_vm->_mixer->isSoundHandleActive(_voice[i].handle)) {
-			_voice[i].program = program;
-			_voice[i].key = key;
+			_voice[i].soundID = soundID & ~0x4000u;
 			return &_voice[i].handle;
 		}
 	}
 }
 
-void SoundManager::stopVoicePlaying(uint16 program, uint16 key) {
+void SoundManager::stopVoicePlaying(uint16 soundID) {
 	for (int i = 0; i < NUM_VOICES; i++) {
-		if (_voice[i].program == program && _voice[i].key == key) {
+		if (_voice[i].soundID == soundID) {
 			_vm->_mixer->stopHandle(_voice[i].handle);
 			return;
 		}
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index b77b057a23..c08fc81b83 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -36,13 +36,11 @@ class VabSound;
 struct SpeechLocation;
 
 typedef struct Voice {
-	int16 program;
-	int16 key;
+	int16 soundID;
 	Audio::SoundHandle handle;
 
 	Voice() {
-		program = -1;
-		key = -1;
+		soundID = -1;
 	}
 } Voice;
 
@@ -91,9 +89,9 @@ private:
 	VabSound * loadVab(const char *headerFilename, const char *bodyFilename);
 
 	bool getSpeechLocation(uint32 talkId, struct SpeechLocation *location);
-	bool isVoicePlaying(uint16 program, uint16 key);
-	Audio::SoundHandle *getVoiceHandle(uint16 program, uint16 key);
-	void stopVoicePlaying(uint16 program, uint16 key);
+	bool isVoicePlaying(uint16 soundID);
+	Audio::SoundHandle *getVoiceHandle(uint16 soundID);
+	void stopVoicePlaying(uint16 soundID);
 
 private:
 	class PSXAudioTrack {


Commit: ad2eebd3480a9997173ebfafe97c2d4d8ceb393f
    https://github.com/scummvm/scummvm/commit/ad2eebd3480a9997173ebfafe97c2d4d8ceb393f
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed initial sfx load bug. Fixed sfx volume bug when stopping audio.

Changed paths:
    engines/dragons/actorresource.cpp
    engines/dragons/scene.cpp
    engines/dragons/sound.cpp
    engines/dragons/sound.h


diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 5acc73428c..e1a54a7769 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -87,8 +87,8 @@ bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream
 		_frames[i].frameDataOffset = &dataStart[frameDataOffset];
 		_frames[i].flags = stream.readUint16LE();
 		_frames[i].field_c = stream.readUint16LE();
-		debug(3, "Frame[%d] @%X, xOffset: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
-				i, offset, _frames[i].xOffset, _frames[i].yOffset, _frames[i].width, _frames[i].height, frameDataOffset, _frames[i].flags, _frames[i].field_c);
+//		debug(3, "Frame[%d] @%X, xOffset: %d field_2: %d (%d, %d) offset: %X, flags: %X field_c: %d",
+//				i, offset, _frames[i].xOffset, _frames[i].yOffset, _frames[i].width, _frames[i].height, frameDataOffset, _frames[i].flags, _frames[i].field_c);
 	}
 
 	return false;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 672f620472..d5cc8b7261 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -134,8 +134,6 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_vm->clearFlags(ENGINE_FLAG_100000);
 	_vm->clearFlags(ENGINE_FLAG_200000);
 
-	_vm->loadCurrentSceneMsf();
-
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 
 	if (flicker == NULL || flicker->sceneId == 0) {
@@ -146,6 +144,8 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 		_vm->getINI(1)->sceneId = _currentSceneId;
 	}
 
+	_vm->loadCurrentSceneMsf();
+
 	_stage = _backgroundLoader->load(sceneId);
 	if (!_vm->isFlagSet(ENGINE_FLAG_800)) {
 		byte *cursorPalette = _vm->_cursor->getPalette();
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index cd2fb636cb..c61f44a698 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -356,9 +356,9 @@ VabSound * SoundManager::loadVab(const char *headerFilename, const char *bodyFil
 void SoundManager::playOrStopSound(uint16 soundId) {
 	uint16 volumeId;
 	if ((soundId & 0x8000u) == 0) {
-		volumeId = soundId + _vm->getCurrentSceneId() * 0x20;
+		volumeId = (soundId & ~0x4000u) + _vm->getCurrentSceneId() * 0x20;
 	} else {
-		volumeId = soundId & 0x7fffu;
+		volumeId = soundId & ~(0x4000u | 0x8000u);
 	}
 
 	if ((soundId & 0x4000u) == 0) {
@@ -420,6 +420,8 @@ void SoundManager::loadMsf(uint32 sceneId) {
 
 		auto *msfStream = new Common::MemoryReadStream(msfData, msfSize, DisposeAfterUse::YES);
 
+		stopAllVoices();
+
 		delete _vabMusx;
 		_vabMusx = new VabSound(msfStream, _vm);
 	}
@@ -452,4 +454,10 @@ void SoundManager::stopVoicePlaying(uint16 soundID) {
 	}
 }
 
+void SoundManager::stopAllVoices() {
+	for (int i = 0; i < NUM_VOICES; i++) {
+		_vm->_mixer->stopHandle(_voice[i].handle);
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index c08fc81b83..27b3e50736 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -92,6 +92,7 @@ private:
 	bool isVoicePlaying(uint16 soundID);
 	Audio::SoundHandle *getVoiceHandle(uint16 soundID);
 	void stopVoicePlaying(uint16 soundID);
+	void stopAllVoices();
 
 private:
 	class PSXAudioTrack {


Commit: 1023f3d8c2164ad4a98b3de56c3d045badc4bca6
    https://github.com/scummvm/scummvm/commit/1023f3d8c2164ad4a98b3de56c3d045badc4bca6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Clear old actor frame before recyling actor object

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 3046d63155..87918dc596 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -164,6 +164,7 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	frame_height = 0;
 	frame_flags = 4;
 	//TODO sub_80017010();
+	freeFrame();
 
 	updateSequence((uint16)sequenceID);
 }
@@ -179,12 +180,7 @@ void Actor::resetSequenceIP() {
 }
 
 void Actor::loadFrame(uint16 frameOffset) {
-	if (frame) {
-		delete frame;
-	}
-	if (surface) {
-		delete surface;
-	}
+	freeFrame();
 
 	frame = _actorResource->loadFrameHeader(frameOffset);
 
@@ -202,6 +198,13 @@ void Actor::loadFrame(uint16 frameOffset) {
 
 }
 
+void Actor::freeFrame() {
+	delete frame;
+	delete surface;
+	frame = NULL;
+	surface = NULL;
+}
+
 byte *Actor::getSeqIpAtOffset(uint32 offset) {
 	return _actorResource->getSequenceDataAtOffset(offset);
 }
@@ -209,6 +212,7 @@ byte *Actor::getSeqIpAtOffset(uint32 offset) {
 void Actor::reset_maybe() {
 	flags = 0;
 	//TODO actor_find_by_resourceId_and_remove_resource_from_mem_maybe(resourceID);
+	freeFrame();
 }
 
 static const int32 pathfinderXYOffsetTbl[32] =
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 87ae580646..ab0b609b2d 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -129,6 +129,7 @@ public:
 	void resetSequenceIP();
 	byte *getSeqIpAtOffset(uint32 offset);
 	void loadFrame(uint16 frameOffset);
+	void freeFrame();
 	void reset_maybe();
 	bool pathfinding_maybe(int16 target_x, int16 target_y, uint16 isNotFlicker);
 	void walkPath();


Commit: 06ae3c43f32f11839174e02781c18739ecd705dd
    https://github.com/scummvm/scummvm/commit/06ae3c43f32f11839174e02781c18739ecd705dd
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Some code cleanups

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 4e58db93c2..9370a3dc27 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -96,7 +96,7 @@ void SpecialOpcodes::initOpcodes() {
 	OPCODE(0x13, spcUnk13InventionBookCloseRelated);
 	OPCODE(0x14, spcClearEngineFlag8);
 	OPCODE(0x15, spcSetEngineFlag8);
-
+	OPCODE(0x16, spcNoop1);
 	OPCODE(0x17, spcKnightPoolReflectionLogic);
 	OPCODE(0x18, clearSceneUpdateFunction);
 	OPCODE(0x19, spcWalkOnStilts);
@@ -273,7 +273,7 @@ void SpecialOpcodes::spcUnkC() {
 }
 
 void SpecialOpcodes::spcFadeScreen() {
-	//TODO call_fade_related_1f();
+	_vm->call_fade_related_1f();
 }
 
 void SpecialOpcodes::spcLadyOfTheLakeCapturedSceneLogic() {
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index d25bb71272..28bbd5308d 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -380,7 +380,10 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 						}
 					}
 				}
-				if (param_5 == 0) goto LAB_80032efc;
+				if (param_5 == 0) {
+					_vm->data_800633fc = 0;
+					return (uint)returnStatus;
+				}
 				uVar9 = ((int)((int)(short)unaff_s4 * (uint)1 * (int)sVar3) >> 3) * 0x3c;
 				if ((param_7 == 0) && _vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED)) {
 					uVar9 = 0;
@@ -427,7 +430,6 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 				_vm->setFlags(ENGINE_FLAG_8);
 			}
 		}
-		LAB_80032efc:
 		_vm->data_800633fc = 0;
 		return (uint)returnStatus;
 }
@@ -560,7 +562,7 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 	_vm->_scriptOpcodes->loadTalkDialogEntries(scriptOpCall);
 	numEntries = _dialogEntries.size();
 	if (numEntries == 0) {
-		return 0;
+		return false;
 	}
 
 	for (Common::Array<TalkDialogEntry*>::iterator it = _dialogEntries.begin(); it != _dialogEntries.end(); it++) {
@@ -581,14 +583,14 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 		if (numActiveDialogEntries == 0) {
 			//TODO logic from LAB_80029bc0 reset cursor
 			exitTalkMenu(isFlag8Set, isFlag100Set, dialogEntries);
-			return 1;
+			return true;
 		}
 
 		selectedDialogText = displayTalkDialogMenu(dialogEntries);
 		if (selectedDialogText == NULL) {
 			callMaybeResetData();
 			exitTalkMenu(isFlag8Set, isFlag100Set, dialogEntries);
-			return 1;
+			return true;
 		}
 		_vm->clearFlags(ENGINE_FLAG_8);
 		strcpy((char *)local_990, selectedDialogText->dialogText);
@@ -640,7 +642,7 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 //	actors[0].y_pos = cursor_y_var;
 
 	exitTalkMenu(isFlag8Set, isFlag100Set, dialogEntries);
-	return 1;
+	return true;
 }
 
 TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dialogEntries) {


Commit: 2d25f10ddd397a6c8b85752689e42bb99214c997
    https://github.com/scummvm/scummvm/commit/2d25f10ddd397a6c8b85752689e42bb99214c997
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Work on scaling. Added support for screen coords in cursor and
inventory

Changed paths:
    engines/dragons/actor.h
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/cursor.cpp
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index ab0b609b2d..dd04a799e8 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -42,7 +42,7 @@ enum ActorFlags {
 	ACTOR_FLAG_40 = 0x40,
 	ACTOR_FLAG_80 = 0x80,
 	ACTOR_FLAG_100 = 0x100,
-	ACTOR_FLAG_200 = 0x200,
+	ACTOR_FLAG_200 = 0x200,  // Use screen coordinates not map coordinates.
 	ACTOR_FLAG_400 = 0x400,
 	ACTOR_FLAG_800 = 0x800,
 	ACTOR_FLAG_1000 = 0x1000,
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 3170333a81..2c74fe1b56 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -84,7 +84,7 @@ void PriorityLayer::restoreTileMap(int16 x, int16 y, int16 w, int16 h) {
 
 }
 
-Background::Background() : _priorityLayer(0), _points1(0), _points2(0), _data(0) {
+Background::Background() : _priorityLayer(0), _points2(0), _data(0) {
 	_layerSurface[0] = NULL;
 	_layerSurface[1] = NULL;
 	_layerSurface[2] = NULL;
@@ -115,7 +115,7 @@ bool Background::load(byte *dataStart, uint32 size) {
 	_palette[0] = 0x00; //FIXME update palette
 	_palette[1] = 0x00;
 
-	_points1 = loadPoints(stream); // 0x200
+	_scaleLayer.load(stream); // 0x200
 	_points2 = loadPoints(stream); // 0x280
 	stream.seek(0x305);
 	uint8 tileindexOffset = stream.readByte();
@@ -286,6 +286,10 @@ Common::Point Background::getLayerOffset(uint8 layerNumber) {
 	return layerOffset[layerNumber];
 }
 
+int16 Background::getScale(int16 y) {
+	return _scaleLayer.getScale(y);
+}
+
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
 	bigFileArchive), _dragonRMS(dragonRMS) {}
 
@@ -304,4 +308,90 @@ Background *BackgroundResourceLoader::load(const char *filename) {
 	return bg;
 }
 
+void ScaleLayer::load(Common::SeekableReadStream &stream) {
+	for (int i = 0; i < 32; i++) {
+		_bands[i]._y = stream.readSint16LE();
+		_bands[i]._priority = stream.readSint16LE();
+	}
+}
+
+uint16 ScaleLayer::getScale(uint16 y) {
+	short yBand;
+	uint uVar1;
+	short local_v0_368;
+	int iVar3;
+	short lowerYBandIdx;
+	ScaleBand *pSVar4;
+	short upperYBandIdx;
+	uint uVar5;
+	ScaleBand *pSVar6;
+	int uVar7;
+
+
+	upperYBandIdx = -1;
+	for (int16 i = 0x1f; i >= 0; i--) {
+		yBand = _bands[i]._y;
+		if (yBand != -1 && yBand <= y) {
+			upperYBandIdx = i;
+			break;
+		}
+	}
+//	iVar3 = 0x1f0000;
+//	do {
+//		yBand = *(ushort *)((int)&scaleBandTbl->y + (iVar3 >> 0xe));
+//		if ((yBand != 0xffff) && (yBand <= y)) break;
+//		i = i + -1;
+//		iVar3 = i * 0x10000;
+//	} while (-1 < i * 0x10000);
+	lowerYBandIdx = 32;
+	for (int16 i = 0; i < 32; i++) {
+		yBand = _bands[i]._y;
+		if (yBand != -1 && y <= yBand) {
+			lowerYBandIdx = i;
+			break;
+		}
+	}
+//	j = 0;
+//	iVar3 = 0;
+//	do {
+//		lowerYBandIdx = (short)j;
+//		yBand = *(ushort *)((int)&scaleBandTbl->y + (iVar3 >> 0xe));
+//		if ((yBand != 0xffff) && (y <= yBand)) break;
+//		j = j + 1;
+//		lowerYBandIdx = (short)j;
+//		iVar3 = j * 0x10000;
+//	} while (j * 0x10000 >> 0x10 < 0x20);
+	if ((upperYBandIdx == -1) && (lowerYBandIdx == 0x20)) {
+		return 0x100;
+	}
+	if (upperYBandIdx < 0 || lowerYBandIdx >= 32) {
+		if (upperYBandIdx >= 0) {
+			lowerYBandIdx = upperYBandIdx;
+		}
+		upperYBandIdx = lowerYBandIdx;
+	}
+
+
+	pSVar6 = &_bands[upperYBandIdx];  //scaleBandTbl + (int)upperYBandIdx;
+	uVar7 = (0x21 - (uint)pSVar6->_priority) * 8;
+	uVar1 = uVar7;
+	if (y != pSVar6->_y) {
+		pSVar4 = &_bands[lowerYBandIdx]; //scaleBandTbl + (int)lowerYBandIdx;
+		uVar5 = (0x21 - (uint)pSVar4->_priority) * 8;
+		uVar1 = uVar5;
+		if ((y != pSVar4->_y) && (uVar1 = uVar7, (int)upperYBandIdx != (int)lowerYBandIdx)) {
+			local_v0_368 = pSVar4->_y - pSVar6->_y;
+			uVar1 = uVar5;
+			if (local_v0_368 != 0) {
+				iVar3 = ((uVar5 & 0xffffu) - (uVar7 & 0xffffu)) * (uint)(ushort)(y - pSVar6->_y);
+
+				assert (((uint)(ushort)local_v0_368 != 0xffffffff) || (iVar3 != -0x80000000));
+
+				return uVar7 + iVar3 / (int)(uint)(ushort)local_v0_368 & 0xffff;
+			}
+		}
+	}
+	return uVar1 & 0xfff8u;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 3c6f1a76c6..9c6f0a10ea 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -43,6 +43,20 @@ public:
 	Background *load(const char *filename);
 };
 
+typedef struct {
+	int16 _y;
+	int16 _priority;
+} ScaleBand;
+
+class ScaleLayer {
+public:
+	void load(Common::SeekableReadStream &stream);
+	uint16 getScale(uint16 y);
+
+private:
+	ScaleBand _bands[32];
+};
+
 struct TileMap {
 	uint16 w;
 	uint16 h;
@@ -57,9 +71,9 @@ private:
 	byte *_tileDataOffset;
 	TileMap _tileMap[4];
 	PriorityLayer *_priorityLayer;
+	ScaleLayer _scaleLayer;
 	byte _palette[512];
 	Graphics::Surface *_layerSurface[3];
-	Common::Point *_points1;
 	Common::Point *_points2;
 	uint8 layerPriority[3];
 	Common::Point layerOffset[3];
@@ -92,6 +106,7 @@ public:
 	void setPalette(byte *newPalette);
 	void setLayerOffset(uint8 layerNumber, Common::Point offset);
 	Common::Point getLayerOffset(uint8 layerNumber);
+	int16 getScale(int16 y);
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
 	Graphics::Surface *initGfxLayer(TileMap &tileMap);
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 53f03f128b..3a0a5c5fc5 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -70,8 +70,8 @@ void Cursor::update() {
 		_sequenceID = 1;
 	}
 
-	_actor->x_pos = _x + _vm->_scene->_camera.x;
-	_actor->y_pos = _y + _vm->_scene->_camera.y;
+	_actor->x_pos = _x;
+	_actor->y_pos = _y;
 
 	// 0x80028104
 	if (_iniUnderCursor != 0
@@ -198,8 +198,10 @@ int16 Cursor::updateINIUnderCursor() {
 }
 
 int16 Cursor::updateIniFromScene() {
-	int16 cursorTileX = _actor->x_pos / 32;
-	int16 cursorTileY = _actor->y_pos / 8;
+	int16 cursorX = _x + _vm->_scene->_camera.x;
+	int16 cursorY = _y + _vm->_scene->_camera.y;
+	int16 cursorTileX = cursorX / 32;
+	int16 cursorTileY = cursorY / 8;
 	int16 data_80072890_orig = data_80072890;
 	int16 data_800728b0_cursor_seqID_orig = data_800728b0_cursor_seqID;
 	for(int i=0;i <_vm->_dragonINIResource->totalRecords(); i++) {
@@ -214,8 +216,8 @@ int16 Cursor::updateIniFromScene() {
 				if (ini->actor->isFlagSet(ACTOR_FLAG_40) && ini->actor->isFlagSet(ACTOR_FLAG_8)) {
 					int16 iniActorXPosition = ini->actor->x_pos - ini->actor->frame->xOffset;
 					int16 iniActorYPosition = ini->actor->y_pos - ini->actor->frame->yOffset;
-					if (_actor->x_pos >= iniActorXPosition && _actor->x_pos < iniActorXPosition + ini->actor->frame->width
-					&& _actor->y_pos >= iniActorYPosition && _actor->y_pos < iniActorYPosition + ini->actor->frame->height) {
+					if (cursorX >= iniActorXPosition && cursorX < iniActorXPosition + ini->actor->frame->width
+					&& cursorY >= iniActorYPosition && cursorY < iniActorYPosition + ini->actor->frame->height) {
 						cursorOverIni = i + 1;
 					}
 				}
@@ -229,7 +231,7 @@ int16 Cursor::updateIniFromScene() {
 						}
 					} else {
 						// 0x80028ac4
-						if (_actor->x_pos >= img->x && _actor->x_pos < img->x + img->w && _actor->y_pos >= img->y && _actor->y_pos < img->y + img->h) {
+						if (cursorX >= img->x && cursorX < img->x + img->w && cursorY >= img->y && cursorY < img->y + img->h) {
 							cursorOverIni = i + 1;
 						}
 					}
@@ -355,8 +357,8 @@ byte *Cursor::getPalette() {
 
 void Cursor::updateActorPosition(int16 x, int16 y) {
 	updatePosition(x, y);
-	_actor->x_pos = _x + _vm->_scene->_camera.x;
-	_actor->y_pos = _y + _vm->_scene->_camera.y;
+	_actor->x_pos = _x;
+	_actor->y_pos = _y;
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index d5cc8b7261..c87263ee6f 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -368,23 +368,21 @@ void Scene::draw() {
 				actor->frame->height != 0
 				) {
 				Graphics::Surface *s = actor->surface;
-				int x = actor->x_pos - actor->frame->xOffset - (actor->_actorID < ACTOR_INVENTORY_OFFSET ? _camera.x : 0);
-				int y = actor->y_pos - actor->frame->yOffset - _camera.y;
-				//int x = ini->x;// - actor->frame_vram_x;
-				//int y = ini->y;// - actor->frame_vram_y;
 				if (actor->priorityLayer == priority) { //} && x + s->w < 320 && y + s->h < 200) {
-					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
+					if (!actor->isFlagSet(ACTOR_FLAG_80)) {
+						actor->scale = _stage->getScale(actor->y_pos);
+					}
+					int x = actor->x_pos - (actor->frame->xOffset * actor->scale / 256) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.x);
+					int y = actor->y_pos - (actor->frame->yOffset * actor->scale / 256) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.y);
+
+					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d Scale: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
-						  s->w, s->h, actor->priorityLayer);
+						  s->w, s->h, actor->priorityLayer, actor->scale);
 					_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? 255 : 128);
 					if (_vm->isDebugMode()) {
 						_screen->drawRect(0x7fff, Common::Rect(x, y, x + s->w, y + s->h), actor->_actorID);
 						drawActorNumber(x + s->w, y + 8, actor->_actorID);
 					}
-				} else {
-					debug(4, "Actor (not displayed) %d %s (%d, %d) Priority: %d", actor->_actorID,
-						  actor->_actorResource->getFilename(),
-						  x, y, actor->priorityLayer);
 				}
 			}
 		}
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 24a8b2344f..1ca25dc4b5 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -157,6 +157,61 @@ void Screen::copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPit
 	}
 }
 
+void Screen::drawScaledSprite(Graphics::Surface *destSurface, byte *source, int sourceWidth, int sourceHeight,
+		int destX, int destY, int destWidth, int destHeight, byte *palette, bool flipX, uint8 alpha) {
+	// Based on the GNAP engine scaling code
+	// TODO Implement flipping
+	const int xs = ((sourceWidth - 1) << 16) / destWidth;
+	const int ys = ((sourceHeight -1) << 16) / destHeight;
+	int clipX = 0, clipY = 0;
+	const int destPitch = destSurface->pitch;
+	if (destX < 0) {
+		clipX = -destX;
+		destX = 0;
+		destWidth -= clipX;
+	}
+	if (destX + destWidth >= destSurface->w) {
+		destWidth = destSurface->w - destX;
+	}
+	if (destY < 0) {
+		clipY = -destY;
+		destY = 0;
+		destHeight -= clipY;
+	}
+	if (destY + destHeight >= destSurface->h) {
+		destHeight = destSurface->h - destY;
+	}
+	if (destWidth < 0 || destHeight < 0)
+		return;
+	byte *dst = (byte *)destSurface->getBasePtr(destX, destY);
+	int yi = ys * clipY;
+	byte *hsrc = source + sourceWidth * ((yi + 0x8000) >> 16);
+	for (int yc = 0; yc < destHeight; ++yc) {
+		byte *wdst = dst;
+		int xi = xs * clipX;
+		byte *wsrc = hsrc + ((xi + 0x8000) >> 16);
+		for (int xc = 0; xc < destWidth; ++xc) {
+			byte colorIndex = *wsrc;
+			uint16 c = READ_LE_UINT16(&palette[colorIndex * 2]);
+			if (c != 0) {
+				if (!(c & 0x8000) || alpha == 255) {
+					// only copy opaque pixels
+					WRITE_LE_UINT16(wdst, c & ~0x8000);
+				} else {
+					WRITE_LE_UINT16(wdst, alphaBlendRGB555(c, READ_LE_INT16(wdst), alpha));
+					// semi-transparent pixels.
+				}
+			}
+			wdst += 2;
+			xi += xs;
+			wsrc = hsrc + ((xi + 0x8000) >> 16);
+		}
+		dst += destPitch;
+		yi += ys;
+		hsrc = source + sourceWidth * ((yi + 0x8000) >> 16);
+	}
+}
+
 Common::Rect Screen::clipRectToScreen(int destX, int destY, const Common::Rect rect) {
 	return clipRectToRect(destX, destY, rect, Common::Rect(320, 200));
 }
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 21fdb3f72c..292bb7c828 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -59,6 +59,7 @@ public:
 private:
 	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
 	void copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
+	void drawScaledSprite(Graphics::Surface *destSurface, byte *source, int sourceWidth, int sourceHeight, int destX, int destY, int destWidth, int destHeight, byte *palette, bool flipX, uint8 alpha);
 };
 
 } // End of namespace Dragons


Commit: 5e2a7a688228bb1a6588d486f1ea39493ba796d5
    https://github.com/scummvm/scummvm/commit/5e2a7a688228bb1a6588d486f1ea39493ba796d5
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added scaling to actor sprites

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 87918dc596..39c289616c 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -157,7 +157,7 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	sequenceTimer = 0;
 	target_x_pos = x;
 	target_y_pos = y;
-	scale = 0x100;
+	scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_sequenceID2 = 0;
 	flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
 	frame_width = 0;
@@ -800,8 +800,8 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 
 	void Actor::walkPath() {
 		if (isFlagClear(Dragons::ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
-			field_24_x += (((scale * field_2c) / 256) * 5) / 4;
-			field_28_y += (((scale * field_30) / 256) * 5) / 4;
+			field_24_x += (((scale * field_2c) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
+			field_28_y += (((scale * field_30) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
 
 			if ( (field_2c >= 0 && target_x_pos < (field_24_x >> 0x10))
 			|| (field_2c < 0 && (field_24_x >> 0x10) < target_x_pos)) {
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index dd04a799e8..a2049f166d 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -31,6 +31,7 @@ class ActorResource;
 struct ActorFrame;
 
 #define DRAGONS_ENGINE_NUM_ACTORS 64
+#define DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE 256
 
 enum ActorFlags {
 	ACTOR_FLAG_1 = 1,
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index c87263ee6f..a168acba95 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -372,13 +372,13 @@ void Scene::draw() {
 					if (!actor->isFlagSet(ACTOR_FLAG_80)) {
 						actor->scale = _stage->getScale(actor->y_pos);
 					}
-					int x = actor->x_pos - (actor->frame->xOffset * actor->scale / 256) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.x);
-					int y = actor->y_pos - (actor->frame->yOffset * actor->scale / 256) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.y);
+					int x = actor->x_pos - (actor->frame->xOffset * actor->scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.x);
+					int y = actor->y_pos - (actor->frame->yOffset * actor->scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.y);
 
 					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d Scale: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
 						  s->w, s->h, actor->priorityLayer, actor->scale);
-					_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? 255 : 128);
+						_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? 255 : 128, actor->scale);
 					if (_vm->isDebugMode()) {
 						_screen->drawRect(0x7fff, Common::Rect(x, y, x + s->w, y + s->h), actor->_actorID);
 						drawActorNumber(x + s->w, y + 8, actor->_actorID);
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 1ca25dc4b5..a8c2703ec7 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -67,7 +67,15 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
 	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, srcSurface.w, clipRect.left, destX, destY, clipRect.width(), clipRect.height(), flipX, alpha);
 }
 
-void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, const Common::Rect srcRect, bool flipX, uint8 alpha) {
+void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, const Common::Rect srcRect, bool flipX, uint8 alpha, uint16 scale) {
+	if (scale != DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) {
+		drawScaledSprite(_backSurface, (byte *)srcSurface.getBasePtr(0, 0),
+				srcRect.width(), srcRect.height(),
+				destX, destY,
+				srcRect.width() * scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE, srcRect.height() * scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE,
+				palette, flipX, alpha);
+		return;
+	}
 	Common::Rect clipRect = clipRectToScreen( destX,  destY, srcRect);
 	if (clipRect.width() == 0 || clipRect.height() == 0) {
 		return;
@@ -187,7 +195,7 @@ void Screen::drawScaledSprite(Graphics::Surface *destSurface, byte *source, int
 	int yi = ys * clipY;
 	byte *hsrc = source + sourceWidth * ((yi + 0x8000) >> 16);
 	for (int yc = 0; yc < destHeight; ++yc) {
-		byte *wdst = dst;
+		byte *wdst = flipX ? dst + (destWidth - 1) * 2 : dst;
 		int xi = xs * clipX;
 		byte *wsrc = hsrc + ((xi + 0x8000) >> 16);
 		for (int xc = 0; xc < destWidth; ++xc) {
@@ -202,7 +210,7 @@ void Screen::drawScaledSprite(Graphics::Surface *destSurface, byte *source, int
 					// semi-transparent pixels.
 				}
 			}
-			wdst += 2;
+			wdst += (flipX ? -2 : 2);
 			xi += xs;
 			wsrc = hsrc + ((xi + 0x8000) >> 16);
 		}
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 292bb7c828..2d33f45754 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -27,6 +27,7 @@
 
 namespace Dragons {
 #define DRAGONS_NUM_PALETTES 5
+#define DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE 256
 class Screen {
 private:
 	Graphics::PixelFormat _pixelFormat;
@@ -41,7 +42,7 @@ public:
 	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255);
-	void copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255);
+	void copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255, uint16 scale = 0x100);
 	void updateScreen();
 	void loadPalette(uint16 paletteNum, byte *palette);
 	byte *getPalette(uint16 paletteNum);


Commit: 8c9a0cf1bb7f3031d9078f5c03a72ded07ba6b35
    https://github.com/scummvm/scummvm/commit/8c9a0cf1bb7f3031d9078f5c03a72ded07ba6b35
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Replaced max scale with define

Changed paths:
    engines/dragons/actor.h
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/screen.cpp
    engines/dragons/screen.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index a2049f166d..dd04a799e8 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -31,7 +31,6 @@ class ActorResource;
 struct ActorFrame;
 
 #define DRAGONS_ENGINE_NUM_ACTORS 64
-#define DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE 256
 
 enum ActorFlags {
 	ACTOR_FLAG_1 = 1,
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 2c74fe1b56..cbcbff65ac 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -23,6 +23,7 @@
 #include "graphics/screen.h"
 #include "common/endian.h"
 #include "background.h"
+#include "screen.h"
 
 namespace Dragons {
 
@@ -286,10 +287,6 @@ Common::Point Background::getLayerOffset(uint8 layerNumber) {
 	return layerOffset[layerNumber];
 }
 
-int16 Background::getScale(int16 y) {
-	return _scaleLayer.getScale(y);
-}
-
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
 	bigFileArchive), _dragonRMS(dragonRMS) {}
 
@@ -394,4 +391,38 @@ uint16 ScaleLayer::getScale(uint16 y) {
 	return uVar1 & 0xfff8u;
 }
 
+ScaleLayer::ScaleLayer(): _savedBands(NULL) {
+	for (int i = 0; i < 32; i++) {
+		_bands[i]._y = -1;
+		_bands[i]._priority = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	}
+}
+
+ScaleLayer::~ScaleLayer() {
+	delete _savedBands;
+}
+
+void ScaleLayer::backup() {
+	delete _savedBands;
+	_savedBands = new ScaleBand[32];
+	memcpy(_savedBands, _bands, sizeof(_bands));
+}
+
+void ScaleLayer::restore() {
+	assert(_savedBands);
+	memcpy(_bands, _savedBands, sizeof(_bands));
+}
+
+void ScaleLayer::clearAll() {
+	for (int i = 0; i < 32; i++) {
+		_bands[i]._y = -1;
+	}
+}
+
+void ScaleLayer::setValue(uint8 index, int16 y, int16 value) {
+	assert(index < 32);
+	_bands[index]._y = y;
+	_bands[index]._priority = value;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 9c6f0a10ea..d07e860997 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -50,11 +50,18 @@ typedef struct {
 
 class ScaleLayer {
 public:
+	ScaleLayer();
+	~ScaleLayer();
 	void load(Common::SeekableReadStream &stream);
 	uint16 getScale(uint16 y);
+	void backup();
+	void restore();
+	void clearAll();
+	void setValue(uint8 index, int16 y, int16 value);
 
 private:
 	ScaleBand _bands[32];
+	ScaleBand *_savedBands;
 };
 
 struct TileMap {
@@ -106,7 +113,7 @@ public:
 	void setPalette(byte *newPalette);
 	void setLayerOffset(uint8 layerNumber, Common::Point offset);
 	Common::Point getLayerOffset(uint8 layerNumber);
-	int16 getScale(int16 y);
+	ScaleLayer *getScaleLayer() { return &_scaleLayer; }
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
 	Graphics::Surface *initGfxLayer(TileMap &tileMap);
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 3a0a5c5fc5..0ff8b9c495 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -29,6 +29,7 @@
 #include "inventory.h"
 #include "scene.h"
 #include "scriptopcodes.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
@@ -43,7 +44,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	_actor->y_pos = _y = 100;
 	_actor->priorityLayer = 6;
 	_actor->flags = 0;
-	_actor->scale = 0x100;
+	_actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_actor->updateSequence(_sequenceID);
 	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
 					  Dragons::ACTOR_FLAG_200);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 8f0d92f476..9562a921a1 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -567,7 +567,7 @@ void DragonsEngine::gameLoop()
 				if (tmpId != 0) {
 					actor->flags = 0;
 					actor->priorityLayer = 0;
-					actor->scale = 0x100;
+					actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 					actor->updateSequence(getINI(tmpId - 1)->field_8 * 2 + 10);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
@@ -584,7 +584,7 @@ void DragonsEngine::gameLoop()
 				Actor *invActor = _inventory->getInventoryItemActor(_cursor->iniItemInHand);
 				invActor->flags = 0;
 				invActor->priorityLayer = 0;
-				invActor->scale = 0x100;
+				invActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 				invActor->updateSequence(
 						 getINI(_cursor->iniItemInHand - 1)->field_8 * 2 + 10);
 				_cursor->iniItemInHand = 0;
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 2bf25f71b5..c559da1f70 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -29,6 +29,7 @@
 #include "bag.h"
 #include "scene.h"
 #include "talk.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
@@ -81,7 +82,7 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_actor->y_pos = 0;
 	_actor->priorityLayer = 6;
 	_actor->flags = 0;
-	_actor->scale = 0x100;
+	_actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_actor->updateSequence(0);
 	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
 						 Dragons::ACTOR_FLAG_200);
@@ -174,7 +175,7 @@ void Inventory::openInventory() {
 
 		if (inventoryItemTbl[i]) {
 			item->flags = 0; //clear all flags
-			item->scale = 0x100;
+			item->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 			item->priorityLayer = 0;
 			item->updateSequence(_vm->getINI(inventoryItemTbl[i] - 1)->field_8 * 2 + 10);
 			item->setFlag(ACTOR_FLAG_200);
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 44d0cdf090..2466ffe15a 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -24,6 +24,7 @@
 #include "dragons.h"
 #include "dragons/dragonini.h"
 #include "dragons/talk.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
@@ -174,7 +175,7 @@ void Minigame1::run() {
 	_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(DAT_80063a40 - 1));
 	flickerActor = _vm->getINI(DAT_80063a40 - 1)->actor;
 	flickerActor->flags = flickerActor->flags | 0x380;
-	flickerActor->scale = 0x100;
+	flickerActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	flickerActor->priorityLayer = 4;
 	flickerActor->_sequenceID2 = -1;
 	flickerActor->updateSequence(0x15);
@@ -191,14 +192,14 @@ void Minigame1::run() {
 	pusherActor->flags = pusherActor->flags | 0x380;
 	pusherActor->x_pos = flickerActor->x_pos + -0xe;
 	pusherActor->y_pos = flickerActor->y_pos + 7;
-	pusherActor->scale = 0x100;
+	pusherActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	pusherActor->priorityLayer = 6;
 	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
 //	if (wheelsActorId == -1) {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_wheels_8008e96c,2,4,0,0xffffffff);
 //	}
 	wheelsActor->flags = wheelsActor->flags | 0x380;
-	wheelsActor->scale = 0x100;
+	wheelsActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	wheelsActor->x_pos = flickerActor->x_pos;
 	wheelsActor->y_pos = flickerActor->y_pos;
 	wheelsActor->priorityLayer = 5;
@@ -209,7 +210,7 @@ void Minigame1::run() {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc-cat_8008e984,2,4,0,0xffffffff);
 //	}
 	catActor->flags = catActor->flags | 0x380;
-	catActor->scale = 0x100;
+	catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	catActor->priorityLayer = 0;
 	i = 0;
 	while (i < 3) {
@@ -218,7 +219,7 @@ void Minigame1::run() {
 //			ProbablyShowASCIIMessage(s_couldn't_alloc_target!_8008e998,2,4,0,0xffffffff);
 //		}
 		targetActorIdTbl[(uint)i + 1]->flags = targetActorIdTbl[(uint)i + 1]->flags | 0x380;
-		targetActorIdTbl[(uint)i + 1]->scale = 0x100;
+		targetActorIdTbl[(uint)i + 1]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 		auStack378[(uint)i] = 0;
 		//TODO FUN_80017010_update_actor_texture_maybe(1);
 		i = i + 1;
@@ -233,7 +234,7 @@ void Minigame1::run() {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_dust_sprite!_8008e9b0,2,5,0,0xffffffff);
 //	}
 	dustSpriteActor->flags = dustSpriteActor->flags | 0x380;
-	dustSpriteActor->scale = 0x100;
+	dustSpriteActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	uVar1 = _vm->getINI(DAT_80063a48 - 1)->actor; //dragon_ini_pointer[DAT_80063a48 + -1].actorId;
 	local_21e = 0;
 	actorFieldC = uVar1->field_c;
@@ -382,7 +383,7 @@ void Minigame1::run() {
 							local_23a = (local_25a + 3) * 0x80;
 							catActor->y_pos = 0x5a;
 							catFieldE_scaleMaybe = 0x100;
-							catActor->scale = 0x100;
+							catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 							catActor->updateSequence(0xc);
 							_vm->playOrStopSound(5);
 							catActor->priorityLayer = 3;
@@ -586,7 +587,7 @@ void Minigame1::run() {
 								else {
 									if ((int)(uint)(local_240 >> 7) < (int)((uint)flickerXPos - 0x32)) {
 										if (catActor->_sequenceID != 9) {
-											catActor->scale = 0x100;
+											catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 											catActor->updateSequence(9);
 										}
 										local_240 = local_240 + 0x180;
@@ -595,7 +596,7 @@ void Minigame1::run() {
 									else {
 										if ((uint)flickerXPos + 0x32 < (uint)(local_240 >> 7)) {
 											if (catActor->_sequenceID != 10) {
-												catActor->scale = 0x100;
+												catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 												catActor->updateSequence(10);
 											}
 											local_240 = local_240 - 0x180;
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 499a5da9b6..c4245e2372 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -222,7 +222,7 @@ void Minigame3::run() {
 			error("Couldn't alloc tear");
 		}
 		tearActorTbl[(int16)i]->flags = tearActorTbl[(int16)i]->flags | 0x380;
-		tearActorTbl[(int16)i]->scale = 0x100;
+		tearActorTbl[(int16)i]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 		tearActorTbl[(int16)i]->priorityLayer = 0;
 		local_208[(int16)i] = -1;
 		local_208[(int)(int16)i + 8] = 0;
@@ -240,7 +240,7 @@ void Minigame3::run() {
 	handActorId->setFlag(ACTOR_FLAG_800);
 	handActorId->setFlag(ACTOR_FLAG_2000);
 	handActorId->setFlag(ACTOR_FLAG_4000);
-	handActorId->scale = 0x100;
+	handActorId->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	handActorId->priorityLayer = 0;
 	handActorId->field_7c = 0x40000;
 	i = 0;
@@ -250,7 +250,7 @@ void Minigame3::run() {
 			error("Couldn't alloc tear blink");
 		}
 		tearBlinkActorTbl[(int16)i]->flags = tearBlinkActorTbl[(int16)i]->flags | 0x4384;
-		tearBlinkActorTbl[(int16)i]->scale = 0x100;
+		tearBlinkActorTbl[(int16)i]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 		tearBlinkActorTbl[(int16)i]->priorityLayer = 0;
 		i = i + 1;
 	}
@@ -262,7 +262,7 @@ void Minigame3::run() {
 		}
 		tearBlinkActorTbl2[(int16)i]->setFlag(ACTOR_FLAG_100);
 		tearBlinkActorTbl2[(int16)i]->setFlag(ACTOR_FLAG_800);
-		tearBlinkActorTbl2[(int16)i]->scale = 0x100;
+		tearBlinkActorTbl2[(int16)i]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 		tearBlinkActorTbl2[(int16)i]->priorityLayer = 0;
 		i = i + 1;
 	}
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index acdfd86dcf..ef8d1ed633 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -25,6 +25,7 @@
 #include "dragons/dragonini.h"
 #include "dragons/talk.h"
 #include "dragons/scene.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
@@ -52,7 +53,7 @@ void Minigame5::run() {
 	uint16 local_76;
 	ushort local_74;
 	ushort local_72;
-	ushort local_70;
+	ushort bombScale;
 	Actor *bombActor;
 	Actor *flickerActor;
 	Actor *pusherActor;
@@ -107,7 +108,7 @@ void Minigame5::run() {
 	_vm->_dragonINIResource->setFlickerRecord(_vm->_dragonINIResource->getRecord(DAT_80063a40 - 1));
 	flickerActor = _vm->_dragonINIResource->getFlickerRecord()->actor;
 	flickerActor->flags = flickerActor->flags | 0x380;
-	flickerActor->scale = 0x100;
+	flickerActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	flickerActor->priorityLayer = 4;
 	flickerActor->_sequenceID2 = -1;
 	flickerActor->updateSequence(0x19);
@@ -126,7 +127,7 @@ void Minigame5::run() {
 	pusherActor->flags = pusherActor->flags | 0x380;
 	pusherActor->x_pos = flickerActor->x_pos + -0xe;
 	pusherActor->y_pos = flickerActor->y_pos + 7;
-	pusherActor->scale = 0x100;
+	pusherActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	pusherActor->priorityLayer = 6;
 //	DisableVSyncEvent();
 	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
@@ -135,7 +136,7 @@ void Minigame5::run() {
 		error("Couldn't alloc wheels!");
 	}
 	wheelsActor->flags = wheelsActor->flags | 0x380;
-	wheelsActor->scale = 0x100;
+	wheelsActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	wheelsActor->x_pos = flickerActor->x_pos;
 	wheelsActor->y_pos = flickerActor->y_pos;
 	wheelsActor->priorityLayer = 5;
@@ -148,7 +149,7 @@ void Minigame5::run() {
 		error("Couldn't alloc bomb!");
 	}
 	bombActor->flags = bombActor->flags | 0x380;
-	bombActor->scale = 0x100;
+	bombActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	bombActor->priorityLayer = 0;
 //	DisableVSyncEvent();
 	dustActor = _vm->_actorManager->loadActor(8,8,100,100,0);
@@ -157,7 +158,7 @@ void Minigame5::run() {
 		error("Couldn't alloc dust sprite!");
 	}
 	dustActor->flags = dustActor->flags | 0x380;
-	dustActor->scale = 0x100;
+	dustActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	local_4e = _vm->_dragonINIResource->getRecord(DAT_80063a48 + -1)->actor;
 	local_4c = 0;
 	local_4a = local_4e->field_c;
@@ -279,8 +280,8 @@ void Minigame5::run() {
 									local_5e = 0x2d00;
 									local_5a = (local_72 + 3) * 0x80;
 									bombActor->y_pos = 0x5a;
-									local_70 = 0x100;
-									bombActor->scale = 0x100;
+									bombScale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+									bombActor->scale = bombScale;
 									_vm->playOrStopSound(10);
 									bombActor->priorityLayer = 3;
 									flickerActor->updateSequence(8);
@@ -294,7 +295,7 @@ void Minigame5::run() {
 							break;
 						case 3:
 							local_60 = local_60 + local_5c;
-							if ((uint)local_72 * 2 + 0xb4 < (uint)local_70) {
+							if ((uint)local_72 * 2 + 0xb4 < (uint)bombScale) {
 								local_5e = local_5e - local_5a;
 								local_5a = local_5a - local_28[((uint)local_72 - 1) * 3];
 								if (local_5a < 0) {
@@ -302,7 +303,7 @@ void Minigame5::run() {
 								}
 							}
 							else {
-								if ((int)(uint)local_70 < (int)((uint)local_72 * -4 + 0xba)) {
+								if ((int)(uint)bombScale < (int)((uint)local_72 * -4 + 0xba)) {
 									local_5e = local_5e + local_5a;
 									local_5a = local_5a + local_28[((uint)local_72 - 1) * 3 + 2];
 								}
@@ -312,9 +313,9 @@ void Minigame5::run() {
 							}
 							bombActor->x_pos = local_60 >> 7;
 							bombActor->y_pos = local_5e >> 7;
-							local_70 = local_70 - 3;
-							bombActor->scale = local_70;
-							if (local_70 == 0x7f) {
+							bombScale = bombScale - 3;
+							bombActor->scale = bombScale;
+							if (bombScale == 0x7f) {
 								if (((local_60 >> 7 < local_30[0]) || (local_30[1] < local_60 >> 7)) ||
 									(local_72 != local_30[2])) {
 									local_42 = 8;
@@ -346,13 +347,13 @@ void Minigame5::run() {
 									currentState = 8;
 								}
 							}
-							if (local_70 < 0x7f) {
+							if (bombScale < 0x7f) {
 								bombActor->priorityLayer = 2;
 							}
-							if ((0xc < local_70) && (local_70 < 0x41)) {
+							if ((0xc < bombScale) && (bombScale < 0x41)) {
 								bombActor->priorityLayer = 0;
 							}
-							if ((short)local_70 < 2) {
+							if ((short)bombScale < 2) {
 								currentState = 5;
 							}
 							break;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index a168acba95..68ebea598d 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -370,7 +370,7 @@ void Scene::draw() {
 				Graphics::Surface *s = actor->surface;
 				if (actor->priorityLayer == priority) { //} && x + s->w < 320 && y + s->h < 200) {
 					if (!actor->isFlagSet(ACTOR_FLAG_80)) {
-						actor->scale = _stage->getScale(actor->y_pos);
+						actor->scale = _stage->getScaleLayer()->getScale(actor->y_pos);
 					}
 					int x = actor->x_pos - (actor->frame->xOffset * actor->scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.x);
 					int y = actor->y_pos - (actor->frame->yOffset * actor->scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.y);
@@ -515,4 +515,8 @@ void Scene::drawBgLayer(uint8 layerNumber, Common::Rect rect, Graphics::Surface
 	_screen->copyRectToSurface8bpp(*surface, _screen->getPalette(0), 0, 0, rect, false, 128);
 }
 
+ScaleLayer *Scene::getScaleLayer() {
+	return _stage->getScaleLayer();
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index c615b80a01..c36c1ee446 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -37,6 +37,7 @@ class DragonINIResource;
 class BigfileArchive;
 class Screen;
 class ScriptOpcodes;
+class ScaleLayer;
 struct DragonINI;
 
 class Scene {
@@ -83,6 +84,7 @@ public:
 
 	void setLayerOffset(uint8 layerNumber, Common::Point offset);
 	Common::Point getLayerOffset(uint8 layerNumber);
+	ScaleLayer *getScaleLayer();
 private:
 	void resetActorFrameFlags();
 	void drawActorNumber(int16 x, int16 y, uint16 actorId);
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index a8c2703ec7..6972c8144b 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -168,7 +168,9 @@ void Screen::copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPit
 void Screen::drawScaledSprite(Graphics::Surface *destSurface, byte *source, int sourceWidth, int sourceHeight,
 		int destX, int destY, int destWidth, int destHeight, byte *palette, bool flipX, uint8 alpha) {
 	// Based on the GNAP engine scaling code
-	// TODO Implement flipping
+	if (destWidth == 0 || destHeight == 0) {
+		return;
+	}
 	const int xs = ((sourceWidth - 1) << 16) / destWidth;
 	const int ys = ((sourceHeight -1) << 16) / destHeight;
 	int clipX = 0, clipY = 0;
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 2d33f45754..09821d93a9 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -42,7 +42,7 @@ public:
 	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255);
-	void copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255, uint16 scale = 0x100);
+	void copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255, uint16 scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE);
 	void updateScreen();
 	void loadPalette(uint16 paletteNum, byte *palette);
 	byte *getPalette(uint16 paletteNum);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index aff8ac306b..4733e69fea 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -34,6 +34,7 @@
 #include "dragons/actor.h"
 #include "dragons/sound.h"
 #include "dragons/talk.h"
+#include "dragons/screen.h"
 #include "scriptopcodes.h"
 
 
@@ -933,7 +934,7 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 		if (field2 == 0x1a && ini->field_1a_flags_maybe & 1 && ini->sceneId == _vm->getCurrentSceneId()) {
 			if (s1 & 2) {
 				ini->actor->flags |= Dragons::ACTOR_FLAG_80;
-				ini->actor->scale = 0x100;
+				ini->actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 			} else {
 				ini->actor->flags &= ~Dragons::ACTOR_FLAG_80;
 			}
@@ -1232,7 +1233,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->iniItemInHand);
 					actor->flags = 0;
 					actor->priorityLayer = 0;
-					actor->scale = 0x100;
+					actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 					actor->updateSequence((_vm->getINI(_vm->_cursor->iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 9370a3dc27..932f38fd1c 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -21,6 +21,7 @@
  */
 
 #include "dragons/actorresource.h"
+#include "dragons/background.h"
 #include "dragons/cursor.h"
 #include "dragons/cutscene.h"
 #include "dragons/credits.h"
@@ -410,7 +411,7 @@ void SpecialOpcodes::spcStGeorgeDragonLanded() {
 	origActor->reset_maybe();
 //	reset_actor_maybe();
 	ini121->actor->setFlag(ACTOR_FLAG_80);
-	ini121->actor->scale = 0x100;
+	ini121->actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	ini121->actor->priorityLayer = 2;
 	ini121->actorResourceId = 0x48;
 
@@ -497,15 +498,16 @@ void SpecialOpcodes::spcStopFlameBedroomEscapeSceneLogic() {
 }
 
 void SpecialOpcodes::spcCastleMoatFull() {
-	//TODO
+	_vm->_scene->getScaleLayer()->backup();
 }
 
 void SpecialOpcodes::spcCastleRestoreScalePoints() {
-	//TODO spcCastleRestoreScalePoints
+	_vm->_scene->getScaleLayer()->restore();
 }
 
 void SpecialOpcodes::spcCastleMoatUpdateActorSceneScalePoints() {
-	//TODO
+	_vm->_scene->getScaleLayer()->clearAll();
+	_vm->_scene->getScaleLayer()->setValue(0, 199, 7);
 }
 
 void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
@@ -514,7 +516,7 @@ void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
 void SpecialOpcodes::spcUnk34() {
 	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;
 	flicker->setFlag(ACTOR_FLAG_80);
-	flicker->scale = 0x100;
+	flicker->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 }
 
 void SpecialOpcodes::spcFlickerClearFlag0x80() {


Commit: d43bd21694ce1ec9b20dc803d02011b8588ec9e7
    https://github.com/scummvm/scummvm/commit/d43bd21694ce1ec9b20dc803d02011b8588ec9e7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Screen shake effects

Changed paths:
    engines/dragons/cutscene.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp
    engines/dragons/screen.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index dab99b6461..d724545cec 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -212,21 +212,9 @@ void CutScene::scene1() {
 																									_vm->clearFlags(ENGINE_FLAG_20000);
 																									// fade_related_calls_with_1f();
 																									// DisableVSyncEvent();
-//TODO
-//																									actorId_arg = 2;
-//																									puVar4 = scrData_offset_200 + 4;
-//																									do {
-//																										*puVar4 = 0xffff;
-//																										puVar4[1] = 0xffff;
-//																										puVar3 = scrData_offset_200;
-//																										actorId_arg = actorId_arg + 1;
-//																										puVar4 = puVar4 + 2;
-//																									} while (actorId_arg < 0x20);
-//																									sVar9 = 0xe;
-//																									scrData_offset_200[1] = 0x11;
-//																									puVar3[2] = 199;
-//																									*puVar3 = 0;
-//																									puVar3[3] = 1;
+																									_vm->_scene->getScaleLayer()->clearAll();
+																									_vm->_scene->getScaleLayer()->setValue(0, 0, 17);
+																									_vm->_scene->getScaleLayer()->setValue(1, 199, 1);
 
 																									// EnableVSyncEvent();
 																									changeBackgroundPosition(
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 92bc6e4115..a744238bf5 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -317,7 +317,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			screenShakeCounter = 0;
 		}
 		if (shouldShakeScreen) {
-			_vm->_screen->setScreenShakeOffset(screenShakeTbl[screenShakeCounter]);
+			_vm->_screen->setScreenShakeOffset(0, screenShakeTbl[screenShakeCounter]);
 			if (screenShakeTbl[screenShakeCounter] == 0) {
 				shouldShakeScreen = false;
 			}
@@ -662,7 +662,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					uVar13->flags = uVar13->flags | 0x1000;
 					flickerArm->flags = flickerArm->flags | 0x1000;
 					loungealotThumb->flags = loungealotThumb->flags | 0x1000;
-					_vm->_screen->setScreenShakeOffset(0);
+					_vm->_screen->setScreenShakeOffset(0, 0);
 					if (local_258 == 1) {
 //						playSoundFromTxtIndex(DAT_80063ad0);
 						loungealotHeadActor->updateSequence(9);
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 68ebea598d..9c429fc8f6 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -103,6 +103,8 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 		// error("0x8002f404"); //TODO do we need this logic?
 	}
 
+	_screen->setScreenShakeOffset(0, 0);
+
 	if (!(sceneId & 0x8000)) {
 		byte *obd = _dragonRMS->getObdDataField10(sceneId);
 		ScriptOpCall scriptOpCall(obd + 4, READ_LE_UINT32(obd));
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 6972c8144b..13e90941db 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -34,11 +34,24 @@ Screen::Screen() {
 	initGraphics(320, 200, &_pixelFormat);
 	_backSurface = new Graphics::Surface();
 	_backSurface->create(320, 200, _pixelFormat);
-	_screenShakeOffset = 0;
+	_screenShakeOffset = Common::Point();
 }
 
 void Screen::updateScreen() {
-	g_system->copyRectToScreen((byte*)_backSurface->getBasePtr(0, 0), _backSurface->pitch, 0, 0, _backSurface->w, _backSurface->h);
+	if (_screenShakeOffset.x != 0 || _screenShakeOffset.y != 0) {
+		g_system->fillScreen(0); //TODO this is meant for 8bit screens. we should use system shake here.
+	}
+	Common::Rect clipRect = clipRectToScreen( _screenShakeOffset.x,  _screenShakeOffset.y, Common::Rect(_backSurface->w, _backSurface->h));
+	g_system->copyRectToScreen((byte*)_backSurface->getBasePtr(clipRect.left, clipRect.top),
+			_backSurface->pitch,
+			_screenShakeOffset.x < 0 ? 0 : _screenShakeOffset.x, _screenShakeOffset.y < 0 ? 0 : _screenShakeOffset.y,
+			clipRect.width(), clipRect.height());
+//	if (_screenShakeOffset < 0) {
+//		_backSurface->fillRect(Common::Rect(0,_backSurface->h + _screenShakeOffset - 1, _backSurface->w - 1, _backSurface->h - 1), 0);
+//	}
+//	if (_screenShakeOffset > 0) {
+//		_backSurface->fillRect(Common::Rect(0,0, _backSurface->w - 1, _screenShakeOffset - 1), 0);
+//	}
 	g_system->updateScreen();
 }
 
@@ -335,7 +348,7 @@ byte *Screen::getPalette(uint16 paletteNum) {
 }
 
 void Screen::clearScreen() {
-	_backSurface->fillRect(Common::Rect(0,0, _backSurface->w, _backSurface->h), 0);
+	_backSurface->fillRect(Common::Rect(0,0, _backSurface->w - 1, _backSurface->h - 1), 0);
 }
 
 void Screen::drawRect(uint16 colour, Common::Rect rect, int id) {
@@ -351,8 +364,9 @@ void Screen::drawRect(uint16 colour, Common::Rect rect, int id) {
 
 }
 
-void Screen::setScreenShakeOffset(int16 newOffset) {
-	_screenShakeOffset = newOffset;
+void Screen::setScreenShakeOffset(int16 x, int16 y) {
+	_screenShakeOffset.x = x;
+	_screenShakeOffset.y = y;
 }
 
 void Screen::copyRectToSurface8bppWrappedY(const Graphics::Surface &srcSurface, byte *palette, int yOffset) {
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 09821d93a9..9eacdc5273 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -24,6 +24,7 @@
 
 #include "graphics/surface.h"
 #include "graphics/pixelformat.h"
+#include "common/rect.h"
 
 namespace Dragons {
 #define DRAGONS_NUM_PALETTES 5
@@ -33,7 +34,7 @@ private:
 	Graphics::PixelFormat _pixelFormat;
 	Graphics::Surface *_backSurface;
 	byte _palettes[DRAGONS_NUM_PALETTES][512];
-	int16 _screenShakeOffset;
+	Common::Point _screenShakeOffset;
 public:
 	virtual ~Screen();
 
@@ -53,7 +54,7 @@ public:
 	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
 	Common::Rect clipRectToRect(int destX, int destY, const Common::Rect rect, const Common::Rect containerRect);
 
-	void setScreenShakeOffset(int16 newOffset);
+	void setScreenShakeOffset(int16 x, int16 y);
 
 	void copyRectToSurface8bppWrappedY(const Graphics::Surface &srcSurface, byte *palette, int yOffset);
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 932f38fd1c..b11a629c7d 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -47,10 +47,17 @@
 
 namespace Dragons {
 
+const int16 shakeTbl[16] = {
+		5,      2,     -2,     -5,
+		5,      2,     -2,     -5,
+		-1,      2,     -1,     -1,
+		2,     -1,      1,      0
+};
+
 // SpecialOpcodes
 
 SpecialOpcodes::SpecialOpcodes(DragonsEngine *vm)
-	: _vm(vm) {
+	: _vm(vm), _specialOpCounter(0) {
 	initOpcodes();
 }
 
@@ -296,22 +303,10 @@ void SpecialOpcodes::spcStopLadyOfTheLakeCapturedSceneLogic() {
 }
 
 void SpecialOpcodes::spc11ShakeScreen() {
-	//TODO
-//	iVar18 = 1;
-//	local_10a0 = DAT_8001170c;
-//	local_109c = DAT_80011710;
-//	local_1098 = DAT_80011714;
-//	local_1094 = uint32_t_80011718;
-//	local_1090 = DAT_8001171c;
-//	local_108c = DAT_80011720;
-//	local_1088 = DAT_80011724;
-//	local_1084 = DAT_80011728;
-//	screenShakeOffset = (short)local_10a0;
-//	while (screenShakeOffset != 0) {
-//		ContinueGame?();
-//		screenShakeOffset = *(short *)((int)&local_10a0 + ((iVar18 << 0x10) >> 0xf));
-//		iVar18 = iVar18 + 1;
-//	}
+	for (int i = 0; i < 16; i++ ) {
+		_vm->_screen->setScreenShakeOffset(0, shakeTbl[i]);
+		_vm->waitForFrames(1);
+	}
 }
 
 void SpecialOpcodes::spcHandleInventionBookTransition() {
@@ -532,24 +527,10 @@ void SpecialOpcodes::spcTownAngryVillagersSceneLogic() {
 }
 
 void SpecialOpcodes::spcBlackDragonCrashThroughGate() {
-	//TODO spcBlackDragonCrashThroughGate
-	//shake screen.
-//	iVar18 = 1;
-//	local_fd8 = DAT_8001170c;
-//	local_fd4 = DAT_80011710;
-//	local_fd0 = DAT_80011714;
-//	local_fcc = uint32_t_80011718;
-//	local_fc8 = DAT_8001171c;
-//	local_fc4 = DAT_80011720;
-//	local_fc0 = DAT_80011724;
-//	local_fbc = DAT_80011728;
-//	DAT_8006339a = (short)local_10a0;
-//	while (screenShakeOffset = DAT_8006339a, DAT_8006339a != 0) {
-//		screenShakeOffset = DAT_8006339a;
-//		ContinueGame?();
-//		DAT_8006339a = *(short *)((int)&local_fd8 + ((iVar18 << 0x10) >> 0xf));
-//		iVar18 = iVar18 + 1;
-//	}
+	for (int i = 0; i < 16; i++ ) {
+		_vm->_screen->setScreenShakeOffset(shakeTbl[i], shakeTbl[i]);
+		_vm->waitForFrames(1);
+	}
 }
 
 void SpecialOpcodes::spcSetEngineFlag0x2000000() {
@@ -831,15 +812,13 @@ void SpecialOpcodes::spc82CallResetDataMaybe() {
 
 void SpecialOpcodes::spcStopScreenShakeUpdater() {
 	_vm->setSceneUpdateFunction(NULL);
-	//TODO spcStopScreenShakeUpdater
-//	DAT_8006339a = 0;
-//	screenShakeOffset = 0;
+	_vm->_screen->setScreenShakeOffset(0, 0);
 }
 
 void SpecialOpcodes::spcInsideBlackDragonScreenShake() {
 	const int16 shakeTbl[5] = {5, -2, 4, -1, 0};
 	for (int i = 0; i < 5; i ++) {
-		_vm->_screen->setScreenShakeOffset(shakeTbl[i]);
+		_vm->_screen->setScreenShakeOffset(0, shakeTbl[i]);
 		_vm->waitForFrames(1);
 	}
 }
@@ -1076,9 +1055,18 @@ void SpecialOpcodes::spcUnk80FlickerArmorOn() {
 }
 
 void SpecialOpcodes::spcShakeScreenSceneLogic() {
+	setSpecialOpCounter(0x1e);
 	_vm->setSceneUpdateFunction(shakeScreenUpdateFunction);
 }
 
+int16 SpecialOpcodes::getSpecialOpCounter() {
+	return _specialOpCounter;
+}
+
+void SpecialOpcodes::setSpecialOpCounter(int16 newValue) {
+	_specialOpCounter = newValue;
+}
+
 void pizzaUpdateFunction() {
 		static int16 DAT_800634bc = 0;
 		DragonsEngine *vm = getEngine();
@@ -1182,22 +1170,19 @@ void castleBuildingBlackDragon2UpdateFunction() {
 }
 
 void shakeScreenUpdateFunction() {
-	//TODO shakeScreenUpdateFunction
-//	uint uVar1;
-//
-//	if (int16_t_80072898 == 0) {
-//		DAT_80083148 = DAT_80083148 ^ 1;
-//		uVar1 = 1;
-//		if (DAT_80083148 == 0) {
-//			uVar1 = 0xffffffff;
-//		}
-//		DAT_8006339a = (undefined2)uVar1;
-//		screenShakeOffset = DAT_8006339a;
-//	}
-//	else {
-//		int16_t_80072898 = int16_t_80072898 - 1;
-//		uVar1 = (uint)(ushort)int16_t_80072898;
-//	}
+	static uint8 DAT_80083148 = 0;
+	DragonsEngine *vm = getEngine();
+	int16 int16_t_80072898 = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
+
+	if (int16_t_80072898 == 0) {
+		DAT_80083148 = DAT_80083148 ^ 1u;
+		int16 shakeValue = DAT_80083148 != 0 ? 1 : -1;
+		vm->_screen->setScreenShakeOffset(shakeValue, shakeValue);
+	}
+	else {
+		int16_t_80072898 = int16_t_80072898 - 1;
+	}
+	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(int16_t_80072898);
 }
 
 void ladyOfTheLakeCapturedUpdateFunction() {
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index f34f8cd4b0..2052022caa 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -60,8 +60,13 @@ protected:
 	DragonsEngine *_vm;
 	SpecialOpcode *_opcodes[DRAGONS_NUM_SPECIAL_OPCODES];
 	Common::String _opcodeNames[DRAGONS_NUM_SPECIAL_OPCODES];
+	int16 _specialOpCounter;
 
+public:
+	int16 getSpecialOpCounter();
+	void setSpecialOpCounter(int16 newValue);
 
+protected:
 	void initOpcodes();
 	void freeOpcodes();
 
@@ -108,7 +113,7 @@ protected:
 	void spcStopMonksAtBarSceneLogic(); //0x29
 
 	void spcFlameBedroomEscapeSceneLogic(); // 0x2b
-	void spcStopFlameBedroomEscapeSceneLogic(); // 0x2b
+	void spcStopFlameBedroomEscapeSceneLogic(); // 0x2c
 
 	void spcCastleMoatFull(); //0x2e
 	void spcCastleRestoreScalePoints(); //0x2f


Commit: f10347a5ca39fc5069146af6915d3f7cb18af15a
    https://github.com/scummvm/scummvm/commit/f10347a5ca39fc5069146af6915d3f7cb18af15a
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: variable naming cleanup

Changed paths:
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index b11a629c7d..ca63dda296 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -1068,13 +1068,13 @@ void SpecialOpcodes::setSpecialOpCounter(int16 newValue) {
 }
 
 void pizzaUpdateFunction() {
-		static int16 DAT_800634bc = 0;
+		static int16 counter = 0;
 		DragonsEngine *vm = getEngine();
 
 		Actor *actorf4 = vm->getINI(0xf4)->actor;
 		Actor *actorf5 = vm->getINI(0xf5)->actor;
 
-		if (DAT_800634bc == 0) {
+		if (counter == 0) {
 			if (actorf4->isFlagSet(ACTOR_FLAG_4)) {
 				if (actorf4->_sequenceID == 0) {
 					actorf4->updateSequence(1);
@@ -1084,7 +1084,7 @@ void pizzaUpdateFunction() {
 						actorf5->x_pos = 0x115;
 						actorf5->y_pos = 0x5c;
 						actorf5->updateSequence(7);
-						DAT_800634bc = 0x2d;
+						counter = 0x2d;
 						return;
 					}
 					if (actorf4->_sequenceID == 2) {
@@ -1109,7 +1109,7 @@ void pizzaUpdateFunction() {
 			}
 		}
 		else {
-			DAT_800634bc--;
+			counter--;
 		}
 }
 
@@ -1170,19 +1170,19 @@ void castleBuildingBlackDragon2UpdateFunction() {
 }
 
 void shakeScreenUpdateFunction() {
-	static uint8 DAT_80083148 = 0;
+	static uint8 shakeDirection = 0;
 	DragonsEngine *vm = getEngine();
-	int16 int16_t_80072898 = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
+	int16 counter = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
 
-	if (int16_t_80072898 == 0) {
-		DAT_80083148 = DAT_80083148 ^ 1u;
-		int16 shakeValue = DAT_80083148 != 0 ? 1 : -1;
+	if (counter == 0) {
+		shakeDirection = shakeDirection ^ 1u;
+		int16 shakeValue = shakeDirection != 0 ? 1 : -1;
 		vm->_screen->setScreenShakeOffset(shakeValue, shakeValue);
 	}
 	else {
-		int16_t_80072898 = int16_t_80072898 - 1;
+		counter--;
 	}
-	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(int16_t_80072898);
+	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(counter);
 }
 
 void ladyOfTheLakeCapturedUpdateFunction() {


Commit: bb0fbec3bbc9722eb95e2d5944baf59096382190
    https://github.com/scummvm/scummvm/commit/bb0fbec3bbc9722eb95e2d5944baf59096382190
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Replaced walk code with JohnDoe's walk logic. Cleaned up Actor variable names

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/background.cpp
    engines/dragons/cutscene.cpp
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 39c289616c..fa6198ae23 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -29,6 +29,8 @@
 
 namespace Dragons {
 
+static const int kPathPointsCount = 32;
+
 ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorResourceLoader(actorResourceLoader) {
 	for (uint16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
 		_actors.push_back(Actor(i));
@@ -66,7 +68,7 @@ Actor *ActorManager::findFreeActor(int16 resourceId) {
 		Actor *actor = it;
 		if (!(actor->flags & Dragons::ACTOR_FLAG_40)) {
 			actor->resourceID = resourceId;
-			actor->field_7c = 0x100000;
+			actor->_walkSpeed = 0x100000;
 			return actor;
 		}
 	}
@@ -137,9 +139,9 @@ Actor::Actor(uint16 id) : _actorID(id) {
 	priorityLayer = 3;
 	x_pos = 160;
 	y_pos = 110;
-	target_x_pos = 0;
-	target_y_pos = 0;
-	field_7c = 0;
+	_walkDestX = 0;
+	_walkDestY = 0;
+	_walkSpeed = 0;
 	flags = 0;
 	frame_width = 0;
 	frame_height = 0;
@@ -155,8 +157,8 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	x_pos = x;
 	y_pos = y;
 	sequenceTimer = 0;
-	target_x_pos = x;
-	target_y_pos = y;
+	_walkDestX = x;
+	_walkDestY = y;
 	scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_sequenceID2 = 0;
 	flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
@@ -258,336 +260,263 @@ static const int32 pathfinderXYOffsetTbl[32] =
 				0x000000fb
 		};
 
-
-bool Actor::pathfinding_maybe(int16 target_x, int16 target_y, uint16 unkTypeMaybe) {
-	uint8 pathfinderData[32];
-	debug(1, "pathfinding. (%X,%X) -> (%X,%X)", x_pos, y_pos, target_x, target_y);
-	int16 priority = 0;
-	int16 var_90_1 = 0;
-	int16 var88 = 0;
-
-	bool isFlag0x10Set = flags & Dragons::ACTOR_FLAG_10;
-	flags &= ~Dragons::ENGINE_FLAG_10;
-
-	if (x_pos == target_x && y_pos == target_y) {
-		if (isFlag0x10Set) {
-			pathfindingCleanup();
+uint32 calcDistance(int32 x1, int32 y1, int32 x2, int32 y2) {
+	return ABS(x2 - x1) * ABS(x2 - x1) + ABS(y2 - y1) * ABS(y2 - y1);
+}
+
+bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
+	static const int kCosTbl[] = {
+			// cos table
+			256, 251, 236, 212, 181, 142, 97, 49,
+			0, -49, -97, -142, -181, -212, -236, -251,
+			-255, -251, -236, -212, -181, -142, -97, -49,
+			0, 49, 97, 142, 181, 212, 236, 251,
+			11, 0, 0, 0, 0, 0, 0, 0
+	};
+	static const int kAdjustXTbl[] = {
+			1, -1, 0, 0, 1, -1, 1, -1
+	};
+	static const int kAdjustYTbl[] = {
+			0, 0, 1, -1, 1, 1, -1, -1
+	};
+
+	debug("startWalk(%d, %d, %d)", _actorID, destX, destY);
+	bool wasAlreadyWalking = isFlagSet(ACTOR_FLAG_10);
+
+	clearFlag(ACTOR_FLAG_10);
+
+	// Check if the actor already is at the destination
+	if (x_pos == destX && y_pos == destY) {
+		if (wasAlreadyWalking) {
+			stopWalk();
 		}
 		return true;
 	}
 
-	int16 newTargetX = target_x;
-	int16 newTargetY = target_y;
+	int xorflagsl = 0;
+	int flag4 = 0;
+	int origDestX = 0, origDestY = 0;
 
-	if (unkTypeMaybe < 2) {
-		priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(target_x, target_y));
-		if (priority < 0) {
-			priority = 1;
-		}
+	int destPriority = 0;
+	if (flags < 2) {
+		destPriority = getEngine()->_scene->getPriorityAtPosition(Common::Point(destX, destY));
+		if (destPriority < 0)
+			destPriority = 1;
 	}
-//	if (((unkTypeMaybe == 0) && (7 < (priority - 1 & 0xffff))) || 	//TODO this is the correct logic I think. need to redo all the pathfinding logic.
-//		((unkTypeMaybe == 1 && (0xf < (priority - 1 & 0xffff))))) {
-	if ((unkTypeMaybe != 0 || priority - 1 < 8) && (unkTypeMaybe != 1 || priority - 1 < 16)) {
-		var_90_1 = (unkTypeMaybe ^ 2) < 1 ? 1 : 0;
-
-		int32 x_related_idx=1;
-		for(; x_related_idx < 320; x_related_idx++) {
 
-			int32 v0_18 = 0;
-			for (int32 s3_1 = 0;s3_1 < 0x20; s3_1++) {
-				int32 v0_19 = s3_1 + 8;
-				if (v0_19 <  0) {
-					v0_19 = s3_1 - 8;
-				}
-				int16 y_offset = (x_related_idx * pathfinderXYOffsetTbl[v0_19 & 0x1f]) / 256;
-				int16 x_offset = (x_related_idx * pathfinderXYOffsetTbl[s3_1 & 0x1f]) / 256;
-				if (target_x + x_offset >= 0 &&
-					target_y + y_offset >= 0) {
-					priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(newTargetX + x_offset, newTargetY + y_offset));
-
-					if ((unkTypeMaybe == 0 && priority - 1 < 8) || (unkTypeMaybe == 1 && priority -1 < 0x10)) {
-						newTargetX += x_offset;
-						newTargetY += y_offset;
-						x_related_idx = -1;
+	if ((flags == 0 && destPriority - 1 >= 8) || (flags == 1 && destPriority - 1 >= 16)) {
+		// Destination point is not walkable so it has to be adjusted
+		// Try to find a walkable destination point by testing the 32 corner points of a circle
+		// in increasing radius steps.
+		bool foundDestPos = false;
+		xorflagsl = 1;
+		origDestX = destX;
+		origDestY = destY;
+		for (int testRadius = 1; testRadius < 320 && !foundDestPos; ++testRadius) {
+			for (int octant = 0; octant < 32; ++octant) {
+				int testDestX = destX + ((testRadius * kCosTbl[octant % 32]) >> 8);
+				int testDestY = destY + ((testRadius * kCosTbl[(octant + 8) % 32]) >> 8);
+				if (testDestX >= 0 && testDestY >= 0) {
+					int testDestPriority = getEngine()->_scene->getPriorityAtPosition(Common::Point(testDestX, testDestY));
+					if ((flags == 0 && testDestPriority - 1 < 8) || (flags == 1 && testDestPriority - 1 < 16)) {
+						destX = testDestX;
+						destY = testDestY;
+						foundDestPos = true;
 						break;
 					}
 				}
 			}
-			if (x_related_idx == -1) {
-				break;
-			}
 		}
-
-		if (x_related_idx == 320) {
-			if (isFlag0x10Set) {
-				pathfindingCleanup();
+		if (!foundDestPos) {
+			if (wasAlreadyWalking) {
+				stopWalk();
 			}
 			return false;
 		}
 	} else {
-		var_90_1 = 1;
+		// TODO Clean up
+		xorflagsl = (flags ^ 2) < 1 ? 1 : 0;
 	}
 
-	if (x_pos == newTargetX && y_pos == newTargetY) {
-		if (isFlag0x10Set) {
-			pathfindingCleanup();
+	// Check if the actor already is at the adjusted destination
+	if (x_pos == destX && y_pos == destY) {
+		if (wasAlreadyWalking) {
+			stopWalk();
 		}
 		return true;
 	}
 
-	int16 numWalkPoints = 0;
-
-	int16 newX = x_pos;
-	int16 newY = y_pos;
-
-	memset(pathfinderData, 0, 32);
-
-	field_76 = newTargetX;
-	field_78 = newTargetY;
-
-	if(!pathfindingUnk(x_pos, y_pos, newTargetX, newTargetY, unkTypeMaybe)) {
-		//  0x8003398c
-		int16 xOffset = -1;
-		//TODO convert to for loops
-		do {
-			int16 yOffset = -1;
-			do {
-				int16 targetXOffset = -1;
-				do {
-					int16 targetYOffset = -1;
-					do {
-						if(pathfindingUnk(newX + xOffset, newY + yOffset, newTargetX + targetXOffset, newTargetY + targetYOffset, unkTypeMaybe | 0x8000)) {
-							targetXOffset = 2;
-							newX += xOffset;
-							newY += yOffset;
-							newTargetX += targetXOffset;
-							newTargetY += targetYOffset;
-							var_90_1 = 0;
-							var88 = 1;
-							x_pos += xOffset;
-							y_pos += yOffset;
-							xOffset = 2;
-							yOffset = 2;
-							targetYOffset = 3;
-						} else {
-							targetYOffset++;
+	int tempDestX1 = destX, tempDestY1 = destY;
+	int actorX1 = x_pos, actorY1 = y_pos;
+	bool pathPointProcessed[kPathPointsCount];
+
+	for (int pointIndex = 0; pointIndex < kPathPointsCount; ++pointIndex) {
+		pathPointProcessed[pointIndex] = false;
+	}
+
+	_finalWalkDestX = destX;
+	_finalWalkDestY = destY;
+
+	if (!canWalkLine(actorX1, actorY1, tempDestX1, tempDestY1, flags)) {
+		// Adjust source/dest positions
+		for (int sxd = -1; sxd <= 1; ++sxd) {
+			for (int syd = -1; syd <= 1; ++syd) {
+				for (int dxd = -1; dxd <= 1; ++dxd) {
+					for (int dyd = -1; dyd <= 1; ++dyd) {
+						if (canWalkLine(actorX1 + sxd, actorY1 + syd, tempDestX1 + dxd, tempDestY1 + dyd, flags | 0x8000)) {
+							sxd = 2;
+							syd = 2;
+							dxd = 2;
+							dyd = 2;
+							actorX1 += sxd;
+							actorY1 += syd;
+							tempDestX1 += dxd;
+							tempDestY1 += dyd;
+							x_pos += sxd;
+							y_pos += syd;
 						}
-					} while(targetYOffset < 2);
-					targetXOffset++;
-				} while(targetXOffset < 2);
-				yOffset++;
-			} while(yOffset < 2);
-			xOffset++;
-		} while(xOffset < 2);
-	}
-
-	if (var88 == 0) { //0x80033af0
-		int16 i;
-		for (i = 0; i < 0x20; i++) {
-			Common::Point point = getEngine()->_scene->getPoint(i);
-			if (point.x != -1) {
-				if (pathfindingUnk(x_pos, x_pos, point.x, point.y, unkTypeMaybe)) {
-					break;
+					}
 				}
 			}
 		}
+	}
 
-		if (i == 0x20) {
-			// 0x80033b80
-			int16 tempX = newX;
-			int16 tempY = newY;
-			for(int j = 0; j < 0x20; j++) {
-				Common::Point point = getEngine()->_scene->getPoint(j);
-				if (point.x == -1) {
-					continue;
-				}
-				if (pathfindingUnk(newX + 1, tempY, point.x, point.y, unkTypeMaybe)) {
-					newX++;
-					x_pos++;
-					break;
-				} else if (pathfindingUnk(newX - 1, tempY, point.x, point.y, unkTypeMaybe)) {
-					newX--;
-					x_pos--;
-					break;
-				} else if (pathfindingUnk(tempX, newY + 1, point.x, point.y, unkTypeMaybe)) {
-					newY++;
-					y_pos++;
-					break;
-				} else if (pathfindingUnk(tempX, newY - 1, point.x, point.y, unkTypeMaybe)) {
-					newY--;
-					y_pos--;
-					break;
-				} else if (pathfindingUnk(newX + 1, newY + 1, point.x, point.y, unkTypeMaybe)) {
-					newX++;
-					x_pos++;
-					newY++;
-					y_pos++;
-					break;
-				} else if (pathfindingUnk(newX - 1, newY + 1, point.x, point.y, unkTypeMaybe)) {
-					newX--;
-					x_pos--;
-					newY++;
-					y_pos++;
-					break;
-				} else if (pathfindingUnk(newX + 1, newY - 1, point.x, point.y, unkTypeMaybe)) {
-					newX++;
-					x_pos++;
-					newY--;
-					y_pos--;
-					break;
-				} else if (pathfindingUnk(newX - 1, newY - 1, point.x, point.y, unkTypeMaybe)) {
-					newX--;
-					x_pos--;
-					newY--;
-					y_pos--;
-					break;
-				}
+	if (flag4 == 0) {
+		// More adjusting of the source position
+		bool needAdjustSourcePoint = true;
+		for (int pointIndex = 0; pointIndex < kPathPointsCount; ++pointIndex) {
+			const Common::Point pt = getEngine()->_scene->getPoint(pointIndex);
+			if (pt.x != -1 && canWalkLine(actorX1, actorY1, pt.x, pt.y, flags)) {
+				needAdjustSourcePoint = false;
+				break;
 			}
 		}
-
-		if (var88 == 0) {
-			// 0x80033e48
-			for (i = 0; i < 0x20; i++) {
-				Common::Point point = getEngine()->_scene->getPoint(i);
-				if (point.x != -1) {
-					if (pathfindingUnk(x_pos, x_pos, point.x, point.y, unkTypeMaybe)) {
-						break;
+		if (needAdjustSourcePoint) {
+			for (int pointIndex = 0; needAdjustSourcePoint && pointIndex < kPathPointsCount; ++pointIndex) {
+				const Common::Point pt = getEngine()->_scene->getPoint(pointIndex);
+				for (int deltaIndex = 0; needAdjustSourcePoint && deltaIndex < 8; ++deltaIndex) {
+					const int deltaX = kAdjustXTbl[deltaIndex];
+					const int deltaY = kAdjustYTbl[deltaIndex];
+					if (canWalkLine(actorX1 + deltaX, actorY1 + deltaY, pt.x, pt.y, flags)) {
+						actorX1 += deltaX;
+						actorY1 += deltaY;
+						x_pos += deltaX;
+						y_pos += deltaY;
+						needAdjustSourcePoint = false;
 					}
 				}
 			}
-
-			if (i == 0x20) {
-				// 0x80033ed0
-				for(int j = 0; j < 0x20; j++) {
-					Common::Point point = getEngine()->_scene->getPoint(j);
-					if (point.x == -1) {
-						continue;
-					}
-					if (pathfindingUnk(target_x + 1, target_y, point.x, point.y, unkTypeMaybe)) {
-						target_x++;
-						break;
-					} else if (pathfindingUnk(target_x - 1, target_y, point.x, point.y, unkTypeMaybe)) {
-						target_x--;
-						break;
-					} else if (pathfindingUnk(target_x, target_y + 1, point.x, point.y, unkTypeMaybe)) {
-						target_y++;
-						break;
-					} else if (pathfindingUnk(target_x, target_y - 1, point.x, point.y, unkTypeMaybe)) {
-						target_y--;
-						break;
-					} else if (pathfindingUnk(target_x + 1, target_y + 1, point.x, point.y, unkTypeMaybe)) {
-						target_x++;
-						target_y++;
-						break;
-					} else if (pathfindingUnk(target_x - 1, target_y + 1, point.x, point.y, unkTypeMaybe)) {
-						target_x--;
-						target_y++;
-						break;
-					} else if (pathfindingUnk(target_x + 1, target_y - 1, point.x, point.y, unkTypeMaybe)) {
-						target_x++;
-						target_y--;
-						break;
-					} else if (pathfindingUnk(target_x - 1, target_y - 1, point.x, point.y, unkTypeMaybe)) {
-						target_x--;
-						target_y--;
-						break;
+		}
+		// More adjusting of the destination position
+		bool needAdjustDestPoint = true;
+		for (int pointIndex = 0; pointIndex < kPathPointsCount; ++pointIndex) {
+			const Common::Point pt = getEngine()->_scene->getPoint(pointIndex);
+			if (pt.x != -1 && canWalkLine(destX, destY, pt.x, pt.y, flags)) {
+				needAdjustDestPoint = false;
+				break;
+			}
+		}
+		if (needAdjustDestPoint) {
+			for (int pointIndex = 0; needAdjustDestPoint && pointIndex < kPathPointsCount; ++pointIndex) {
+				const Common::Point pt = getEngine()->_scene->getPoint(pointIndex);
+				for (int deltaIndex = 0; needAdjustDestPoint && deltaIndex < 8; ++deltaIndex) {
+					const int deltaX = kAdjustXTbl[deltaIndex];
+					const int deltaY = kAdjustYTbl[deltaIndex];
+					if (canWalkLine(destX + deltaX, destY + deltaY, pt.x, pt.y, flags)) {
+						destX += deltaX;
+						destY += deltaY;
+						needAdjustDestPoint = false;
 					}
 				}
 			}
 		}
 	}
 
-	for (; !pathfindingUnk(newX, newY, newTargetX, newTargetY, unkTypeMaybe); ) {
-		int16 pointId = pathfindingFindClosestPoint(newX, newY, newTargetX, newTargetY, unkTypeMaybe, pathfinderData);
-		if (pointId == -1) {
-			if (isFlag0x10Set) {
-				pathfindingCleanup();
+	// Build the actual path. The path is constructed backwards from the destination to the source.
+	int pathPointsIndex = 0;
+	while (!canWalkLine(actorX1, actorY1, tempDestX1, tempDestY1, flags) && pathPointsIndex < kPathPointsCount) {
+		int foundPointIndex = pathfindingFindClosestPoint(actorX1, actorY1, tempDestX1, tempDestY1, flags, pathPointProcessed);
+		if (foundPointIndex < 0) {
+			if (wasAlreadyWalking) {
+				stopWalk();
 			}
 			return false;
 		}
-		pathfinderData[pointId] = 1;
-		Common::Point point = getEngine()->_scene->getPoint(pointId);
-		newTargetX = point.x;
-		newTargetY = point.y;
-		if (numWalkPoints < 2) {
-			if (numWalkPoints > 0 && pathfindingUnk(point.x, point.y, target_x, target_y, unkTypeMaybe)) {
-				numWalkPoints--;
+		pathPointProcessed[foundPointIndex] = true;
+		const Common::Point pt = getEngine()->_scene->getPoint(foundPointIndex);
+		tempDestX1 = pt.x;
+		tempDestY1 = pt.y;
+		if (pathPointsIndex >= 2) {
+			const Common::Point prevPt = getEngine()->_scene->getPoint(walkPointsTbl[pathPointsIndex - 2]);
+			if (canWalkLine(pt.x, pt.y, prevPt.x, prevPt.y, flags)) {
+				--pathPointsIndex;
 			}
-		} else {
-			Common::Point targetPoint = getEngine()->_scene->getPoint(walkPointsTbl[numWalkPoints - 2]);
-			if (pathfindingUnk(point.x, point.y, targetPoint.x, targetPoint.y, unkTypeMaybe)) {
-				numWalkPoints--;
+		} else if (pathPointsIndex == 1) {
+			if (canWalkLine(pt.x, pt.y, destX, destY, flags)) {
+				--pathPointsIndex;
 			}
 		}
-		walkPointsTbl[numWalkPoints] = (uint16)pointId;
-		numWalkPoints++;
-	}
-
-		//0x8003437c
-		int16 origDistance = abs(target_x - x_pos) * abs(target_x - x_pos) + abs(target_y - y_pos) * abs(target_y - y_pos);
-		int16 newTargetDiffDistance = abs(newTargetX - target_x) * abs(newTargetX - target_x) + abs(newTargetY - target_y) * abs(newTargetY - target_y);
-
-		if (var_90_1 == 0
-		|| origDistance >= 625
-		|| ((target_x != x_pos || target_y != y_pos) && origDistance >= newTargetDiffDistance)) {
-			//0x80034568
-			debug(1, "0x80034568");
-			walkPointsIndex = numWalkPoints - 1;
-
-			if (numWalkPoints == 0) {
-				target_x_pos = newTargetX;
-				target_y_pos = newTargetY;
-				field_76 = -1;
-				field_78 = -1;
-			} else {
-				uint16 pointId = walkPointsTbl[walkPointsIndex];
-				Common::Point point = getEngine()->_scene->getPoint(pointId);
-				target_x_pos = point.x;
-				target_y_pos = point.y;
-			}
-			int16 newSeqId = pathfindingUpdateTarget(target_x, target_y);
-			if (newSeqId != -1 && !(flags & ACTOR_FLAG_800)) {
-				_sequenceID2 = newSeqId;
-			}
-			if (_sequenceID != _sequenceID2 + 8 && !(flags & ACTOR_FLAG_800)) {
-				updateSequence(_sequenceID2 + 8);
-			}
-			setFlag(ACTOR_FLAG_10);
-			return true;
-		} else {
-			//0x80034470
-			int16 diffX = target_x - newX;
-			int16 diffY = newY - target_y;
-			int16 newSeqId = 0;
-			if (diffX == 0) {
-				newSeqId = diffY <= 0 ? 2 : 6;
-			} else {
-				int16 div = diffY / diffX;
-				if (div == 0) {
-					newSeqId = diffX < 1 ? 4 : 0;
-				} else if (div <= 0) {
-					newSeqId = diffX <= 0 ? 5 : 1;
+		walkPointsTbl[pathPointsIndex] = foundPointIndex;
+		++pathPointsIndex;
+	}
+
+	// Direction/post-processing
+	if (xorflagsl != 0) {
+		uint destDistance = calcDistance(destX, destY, tempDestX1, tempDestY1);
+		uint sourceDistance = calcDistance(actorX1, actorY1, destX, destY);
+		if (sourceDistance < 625 && ((actorX1 == destX && actorY1 == destY) || (sourceDistance < destDistance))) {
+			int newDirection;
+			int dx = origDestX - actorX1;
+			int dy = origDestY - actorY1;
+			if (dx != 0) {
+				int slope = dy / dx;
+				if (slope == 0) {
+					newDirection = (dx < 1) ? 4 : 0;
+				} else if (slope > 0) {
+					newDirection = (dx <= 0) ? 3 : 7;
 				} else {
-					newSeqId = diffX <= 0 ? 3 : 7;
+					newDirection = (dx <= 0) ? 5 : 1;
 				}
+			} else {
+				newDirection = (dy <= 0)  ? 2 : 6;
 			}
-			_sequenceID2 = newSeqId;
-			if (isFlag0x10Set) {
-				pathfindingCleanup();
+			_sequenceID2 = newDirection;
+			if (wasAlreadyWalking) {
+				stopWalk();
 			}
+			return false;
 		}
+	}
 
-
-	return false;
+	walkPointsIndex = pathPointsIndex - 1;
+	if (pathPointsIndex == 0) {
+		_walkDestX = tempDestX1;
+		_walkDestY = tempDestY1;
+		_finalWalkDestX = -1;
+		_finalWalkDestY = -1;
+	} else {
+		const Common::Point pt = getEngine()->_scene->getPoint(walkPointsTbl[walkPointsIndex]);
+		_walkDestX = pt.x;
+		_walkDestY = pt.y;
+	}
+	int direction = startMoveToPoint(_walkDestX, _walkDestY);
+	if (direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
+		_sequenceID2 = direction;
+	}
+	if (_sequenceID != _sequenceID2 + 8 && !isFlagSet(ACTOR_FLAG_800)) {
+		updateSequence(_sequenceID2 + 8);
+	}
+	setFlag(ACTOR_FLAG_10);
+	return true;
 }
 
-void Actor::pathfindingCleanup() {
+void Actor::stopWalk() {
 	clearFlag(Dragons::ACTOR_FLAG_10);
 	walkPointsIndex = 0;
-	target_x_pos = x_pos;
-	target_y_pos = y_pos;
-	field_76 = -1;
-	field_78 = -1;
+	_walkDestX = x_pos;
+	_walkDestY = y_pos;
+	_finalWalkDestX = -1;
+	_finalWalkDestY = -1;
 	setFlag(Dragons::ACTOR_FLAG_4);
 
 	if (flags & Dragons::ACTOR_FLAG_200) {
@@ -638,16 +567,16 @@ bool Actor::isFlagSet(uint32 flag) {
 	return (flags & flag) == flag;
 }
 
-uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 unkType) {
-	debug(1, "pathfindingUnk. (%X,%X) -> (%X,%X) %d", x_pos, y_pos, target_x, target_y, unkType);
+uint16 Actor::canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 flags) {
+	debug(1, "canWalkLine. (%X,%X) -> (%X,%X) %d", x_pos, y_pos, target_x, target_y, flags);
 
-	if (unkType == 2) {
+	if (flags == 2) {
 		return 1;
 	}
 	uint16 width = getEngine()->_scene->getStageWidth();
 	uint16 height = getEngine()->_scene->getStageHeight();
 
-	if (unkType & 0x8000) {
+	if (flags & 0x8000) {
 		if (actor_x < 0
 			|| width - 1 < actor_x
 			|| actor_y < 0
@@ -666,31 +595,31 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		return 1;
 	}
 
-	int16 diffX = target_x - actor_x;
-	int16 diffY = target_y - actor_y;
+	int16 deltaX = target_x - actor_x;
+	int16 deltaY = target_y - actor_y;
 
 	if (target_y != actor_y && target_x == actor_x) {
-		y_increment = diffY > 0 ? 1 : -1;
+		y_increment = deltaY > 0 ? 0x10000 : -0x10000;
 	} else {
 		if (target_y == actor_y) {
 			if (target_x == actor_x) {
 				x_increment = 0;
-				y_increment = diffY > 0 ? 1 : -1;
+				y_increment = deltaY > 0 ? 0x10000 : -0x10000;
 			} else {
-				x_increment = diffX > 0 ? 1 : -1;
+				x_increment = deltaX > 0 ? 0x10000 : -0x10000;
 				y_increment = 0;
 			}
 		} else {
-			if (ABS(diffY) < ABS(diffX)) {
-				x_increment = diffX > 0 ? 1 : -1;
-				y_increment = ((diffY) /*<< 0x10*/) / (diffX);
-				if ((diffY > 0 && y_increment < 0) || (diffY < 0 && y_increment > 0)) {
+			if (ABS(deltaY) < ABS(deltaX)) {
+				x_increment = deltaX > 0 ? 0x10000 : -0x10000;
+				y_increment = ((deltaY) << 0x10) / (deltaX);
+				if ((deltaY > 0 && y_increment < 0) || (deltaY < 0 && y_increment > 0)) {
 					y_increment = -y_increment;
 				}
 			} else {
-				y_increment = diffY > 0 ? 1 : -1;
-				x_increment = ((diffX) /*<< 0x10*/) / (diffY);
-				if ((diffX > 0 && x_increment < 0) || (diffX < 0 && x_increment > 0)) {
+				y_increment = deltaY > 0 ? 0x10000 : -0x10000;
+				x_increment = ((deltaX) << 0x10) / (deltaY);
+				if ((deltaX > 0 && x_increment < 0) || (deltaX < 0 && x_increment > 0)) {
 					x_increment = -x_increment;
 				}
 			}
@@ -708,11 +637,11 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 		if ( priority < 0) {
 			priority = 1;
 		}
-		if (!(unkType & 0x7fff) && (priority == 0 || priority >= 8)) {
+		if (!(flags & 0x7fff) && (priority == 0 || priority >= 8)) {
 			return 0;
 		}
 
-		if ((unkType & 0x7fff) == 1) {
+		if ((flags & 0x7fff) == 1) {
 			if (priority == 0 || priority >= 0x10) {
 				return 0;
 			}
@@ -722,103 +651,105 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 	}
 }
 
-	int16 Actor::pathfindingUpdateTarget(int16 newTargetX, int16 newTargetY) {
-		field_24_x = x_pos << 0x10;
-		field_28_y = y_pos << 0x10;
+int Actor::startMoveToPoint(int destX, int destY) {
+	int direction = 0;
+	int quadrant = 0;
+	int deltaX = destX - x_pos;
+	int deltaY = (destY - y_pos) * 2;
+	int absDeltaX = ABS(deltaX);
+	int absDeltaY = ABS(deltaY);
+	// debug("from: (%d, %d); to: (%d, %d); d: (%d, %d); actor._walkSpeed: %08X", x_pos, actor._y, destX, destY, deltaX, deltaY, actor._walkSpeed);
 
-		int16 diffX = newTargetX - x_pos;
-		int16 diffY = newTargetY - y_pos;
-		int16 absDiffX = abs(diffX);
-		int16 absDiffY = abs(diffY) * 2;
+	_xShl16 = x_pos << 16;
+	_yShl16 = y_pos << 16;
 
-		int16 t2 = 0;
-		int16 newSequenceId = -1;
+	// Walk slope is a fixed point value, where the upper 16 bits are the integral part,
+	// and the lower 16 bits the fractional part. 0x10000 is 1.0.
 
-		if (diffX == 0) {
-			if (diffY == 0) {
-				return -1;
-			}
-			field_2c = 0;
-			field_30 = 0x10000;
+	if (deltaX != 0 && deltaY != 0) {
+		// Walk along both X and Y axis
+		if (absDeltaX < absDeltaY) {
+			_walkSlopeX = (absDeltaX << 16) / absDeltaY;
+			_walkSlopeY = 0x10000;
 		} else {
-			if (diffY == 0) {
-				field_2c = 0x10000;
-				field_30 = 0;
-			} else {
-				if (absDiffX >= absDiffY) {
-					field_2c = 0x10000;
-					field_30 = (absDiffY << 0x10) / absDiffX;
-				} else {
-					field_2c = (absDiffX << 0x10) / absDiffY;
-					field_30 = 0x10000;
-				}
-			}
-		}
-		field_30 = ((field_30 >> 5) * field_7c) >> 0xb;
-		field_2c = ((field_2c >> 5) * field_7c) >> 0xb;
-
-		if (diffX < 0) {
-			field_2c = -field_2c;
-			t2 = 2;
+			_walkSlopeX = 0x10000;
+			_walkSlopeY = (absDeltaY << 16) / absDeltaX;
 		}
+	} else if (deltaX != 0) {
+		// Walk along X only
+		_walkSlopeX = 0x10000;
+		_walkSlopeY = 0;
+	} else if (deltaY != 0) {
+		// Walk along Y only
+		_walkSlopeX = 0;
+		_walkSlopeY = 0x10000;
+	} else {
+		// Already at dest
+		return -1;
+	}
 
-		if (diffY < 0) {
-			field_30 = -field_30;
-			t2++;
-		}
+	_walkSlopeX = (_walkSlopeX / 32) * (_walkSpeed / 0x800);
+	_walkSlopeY = (_walkSlopeY / 32) * (_walkSpeed / 0x800);
 
-		switch (t2) {
-			case 0 :
-				newSequenceId = absDiffX < (absDiffY * 2) ? 2 : 0;
-				break;
-			case 1 :
-				newSequenceId =  absDiffX < (absDiffY * 2) ? 0 : 6;
-				break;
-			case 2 :
-				newSequenceId = absDiffX < (absDiffY * 2) ? 2 : 4;
-				break;
-			case 3 :
-				newSequenceId = absDiffX < (absDiffY * 2) ? 6 : 4;
-				break;
-			default :
-				break;
-		}
+	if (deltaX < 0) {
+		_walkSlopeX = -_walkSlopeX;
+		quadrant += 2;
+	}
 
-		field_30 = field_30 / 2;
+	if (deltaY < 0) {
+		_walkSlopeY = -_walkSlopeY;
+		quadrant += 1;
+	}
 
-		if (getEngine()->_dragonINIResource->isFlicker(_actorID)) {
-			DragonINI *ini = getEngine()->_dragonINIResource->getFlickerRecord();
-			ini->actor->field_2c = (ini->actor->field_2c * 3 + ((ini->actor->field_2c * 3) >> 0x1f)) >> 1;
-			ini->actor->field_30 = (ini->actor->field_30 * 3 + ((ini->actor->field_30 * 3) >> 0x1f)) >> 1;
-		}
+	switch (quadrant) {
+		case 0:
+			direction = (absDeltaX < absDeltaY) ? 2 : 0;
+			break;
+		case 1:
+			direction = (absDeltaX < absDeltaY) ? 6 : 0;
+			break;
+		case 2:
+			direction = (absDeltaX < absDeltaY) ? 2 : 4;
+			break;
+		case 3:
+			direction = (absDeltaX < absDeltaY) ? 6 : 4;
+			break;
+	}
 
-		target_x_pos = newTargetX;
-		target_y_pos = newTargetY;
+	_walkSlopeY /= 2;
+	_walkDestX = destX;
+	_walkDestY = destY;
 
-		return newSequenceId;
+	if (getEngine()->_dragonINIResource->isFlicker(_actorID)) {
+		// Adjust walk slope for the main actor
+		_walkSlopeX = _walkSlopeX * 3 / 2;
+		_walkSlopeY = _walkSlopeY * 3 / 2;
 	}
 
+	return direction;
+}
+
 	void Actor::walkPath() {
 		if (isFlagClear(Dragons::ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
-			field_24_x += (((scale * field_2c) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
-			field_28_y += (((scale * field_30) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
+			_xShl16 += (((scale * _walkSlopeX) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
+			_yShl16 += (((scale * _walkSlopeY) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
 
-			if ( (field_2c >= 0 && target_x_pos < (field_24_x >> 0x10))
-			|| (field_2c < 0 && (field_24_x >> 0x10) < target_x_pos)) {
-				field_24_x = target_x_pos << 0x10;
+			if ( (_walkSlopeX >= 0 && _walkDestX < (_xShl16 >> 0x10))
+			|| (_walkSlopeX < 0 && (_xShl16 >> 0x10) < _walkDestX)) {
+				_xShl16 = _walkDestX << 0x10;
 			}
 
-			if ( (field_30 >= 0 && target_y_pos < (field_28_y >> 0x10))
-				 || (field_30 < 0 && (field_28_y >> 0x10) < target_y_pos)) {
-				field_28_y = target_y_pos << 0x10;
+			if ( (_walkSlopeY >= 0 && _walkDestY < (_yShl16 >> 0x10))
+				 || (_walkSlopeY < 0 && (_yShl16 >> 0x10) < _walkDestY)) {
+				_yShl16 = _walkDestY << 0x10;
 			}
 
-			x_pos = field_24_x >> 0x10;
-			y_pos = field_28_y >> 0x10;
+			x_pos = _xShl16 >> 0x10;
+			y_pos = _yShl16 >> 0x10;
 
-			if (x_pos == target_x_pos && y_pos == target_y_pos) {
+			if (x_pos == _walkDestX && y_pos == _walkDestY) {
 				if (walkPointsIndex <= 0) {
-					if (field_76 < 0) {
+					if (_finalWalkDestX < 0) {
 						clearFlag(ACTOR_FLAG_10);
 						if (isFlagClear(ACTOR_FLAG_200)) {
 							clearFlag(ACTOR_FLAG_800);
@@ -827,24 +758,24 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 						clearFlag(ACTOR_FLAG_1);
 						return;
 					} else {
-						target_x_pos = field_76;
-						target_y_pos = field_78;
-						field_76 = -1;
-						field_78 = -1;
+						_walkDestX = _finalWalkDestX;
+						_walkDestY = _finalWalkDestY;
+						_finalWalkDestX = -1;
+						_finalWalkDestY = -1;
 					}
 				} else {
 					walkPointsIndex--;
 					Common::Point point = getEngine()->_scene->getPoint(walkPointsTbl[walkPointsIndex]);
-					target_x_pos = point.x;
-					target_y_pos = point.y;
+					_walkDestX = point.x;
+					_walkDestY = point.y;
 				}
 				// 0x8001bcc8
-				if(pathfindingUpdateTarget(target_x_pos, target_y_pos) == -1) {
-					_sequenceID2 = -1;
-				} else {
-					if (_sequenceID != _sequenceID2 + 8 && !(flags & ACTOR_FLAG_800)) {
-						updateSequence(_sequenceID2 + 8);
-					}
+				int direction = startMoveToPoint(_walkDestX, _walkDestY);
+				if(direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
+					_sequenceID2 = direction;
+				}
+				if (_sequenceID != _sequenceID2 + 8 && _sequenceID2 != -1 && !(flags & ACTOR_FLAG_800)) {
+					updateSequence(_sequenceID2 + 8);
 				}
 				setFlag(ACTOR_FLAG_10);
 			}
@@ -853,14 +784,14 @@ uint16 Actor::pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16
 
 	// 0x80034930
 	int16 Actor::pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y,
-											 int16 unkType, uint8 *pointsInUseTbl) {
+											 int16 unkType, bool *pointsInUseTbl) {
 		int16 pointId = -1;
 		uint32 minDist = 0xffffffff;
 
-		for (int i = 0; i < 0x20; i++) {
+		for (int i = 0; i < kPathPointsCount; i++) {
 			Common::Point point = getEngine()->_scene->getPoint(i);
-			if (point.x != -1 && pointsInUseTbl[i] == 0) {
-				if (pathfindingUnk(point.x, point.y, target_x, target_y, unkType)) {
+			if (point.x != -1 && !pointsInUseTbl[i]) {
+				if (canWalkLine(point.x, point.y, target_x, target_y, unkType)) {
 					uint32 dist = abs(point.x - actor_x) * abs(point.x - actor_x) + abs(point.y - actor_y) * abs(point.y - actor_y);
 					if ( dist < minDist) {
 						minDist = dist;
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index dd04a799e8..8fb25d00be 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -102,18 +102,18 @@ public:
 	uint16 flags;
 	int16 x_pos;
 	int16 y_pos;
-	int16 target_x_pos;
-	int16 target_y_pos;
-	int32 field_24_x;
-	int32 field_28_y;
-	int32 field_2c;
-	int32 field_30;
+	int16 _walkDestX;
+	int16 _walkDestY;
+	int32 _xShl16;
+	int32 _yShl16;
+	int32 _walkSlopeX;
+	int32 _walkSlopeY;
 	uint16 walkPointsTbl[32];
 	int16 walkPointsIndex;
-	int16 field_76;
-	int16 field_78;
+	int16 _finalWalkDestX;
+	int16 _finalWalkDestY;
 	uint16 field_7a;
-	int32 field_7c;
+	int32 _walkSpeed;
 	uint16 field_80;
 	uint16 frame_vram_x;
 	uint16 frame_vram_y;
@@ -131,7 +131,7 @@ public:
 	void loadFrame(uint16 frameOffset);
 	void freeFrame();
 	void reset_maybe();
-	bool pathfinding_maybe(int16 target_x, int16 target_y, uint16 isNotFlicker);
+	bool startWalk(int16 destX, int16 destY, uint16 flags);
 	void walkPath();
 	void waitUntilFlag4IsSet();
 	void waitUntilFlag8IsSet();
@@ -149,11 +149,11 @@ public:
 
 	byte *getPalette();
 private:
-	void pathfindingCleanup();
-	uint16 pathfindingUnk(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 unkType);
-	int16 pathfindingUpdateTarget(int16 newTargetX, int16 newTargetY);
+	void stopWalk();
+	uint16 canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 flags);
 	int16 pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType,
-									  uint8 *pointsInUseTbl);
+									  bool *pointsInUseTbl);
+	int startMoveToPoint(int destX, int destY);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index cbcbff65ac..d4ec0d6e1c 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -380,11 +380,11 @@ uint16 ScaleLayer::getScale(uint16 y) {
 			local_v0_368 = pSVar4->_y - pSVar6->_y;
 			uVar1 = uVar5;
 			if (local_v0_368 != 0) {
-				iVar3 = ((uVar5 & 0xffffu) - (uVar7 & 0xffffu)) * (uint)(ushort)(y - pSVar6->_y);
+				iVar3 = ((uVar5 & 0xffffu) - (uVar7 & 0xffffu)) * (uint)(uint16)(y - pSVar6->_y);
 
-				assert (((uint)(ushort)local_v0_368 != 0xffffffff) || (iVar3 != -0x80000000));
+				assert (((uint)(uint16)local_v0_368 != 0xffffffff) || (iVar3 != -0x80000000));
 
-				return uVar7 + iVar3 / (int)(uint)(ushort)local_v0_368 & 0xffff;
+				return uVar7 + iVar3 / (int)(uint)(uint16)local_v0_368 & 0xffff;
 			}
 		}
 	}
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index d724545cec..772d385132 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -229,25 +229,25 @@ void CutScene::scene1() {
 																									DAT_80072de8->setFlag(ACTOR_FLAG_100);
 																									DAT_80072de8->setFlag(ACTOR_FLAG_800);
 																									DAT_80072de8->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072de8->field_7c = 0x20000;
+																									DAT_80072de8->_walkSpeed = 0x20000;
 																									DAT_80072de8->priorityLayer = 3;
 
 																									DAT_80072dec->setFlag(ACTOR_FLAG_100);
 																									DAT_80072dec->setFlag(ACTOR_FLAG_800);
 																									DAT_80072dec->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072dec->field_7c = 0x18000;
+																									DAT_80072dec->_walkSpeed = 0x18000;
 																									DAT_80072dec->priorityLayer = 3;
 
 																									DAT_80072df0->setFlag(ACTOR_FLAG_100);
 																									DAT_80072df0->setFlag(ACTOR_FLAG_800);
 																									DAT_80072df0->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072df0->field_7c = 0x14000;
+																									DAT_80072df0->_walkSpeed = 0x14000;
 																									DAT_80072df0->priorityLayer = 3;
 
 																									DAT_80072df4->setFlag(ACTOR_FLAG_100);
 																									DAT_80072df4->setFlag(ACTOR_FLAG_800);
 																									DAT_80072df4->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072df4->field_7c = 0x1c000;
+																									DAT_80072df4->_walkSpeed = 0x1c000;
 																									DAT_80072df4->priorityLayer = 3;
 
 																									DAT_80072df8->setFlag(ACTOR_FLAG_100);
@@ -257,13 +257,13 @@ void CutScene::scene1() {
 
 																									_vm->waitForFramesAllowSkip(0xe);
 																									// call_fade_related_1f();
-																									DAT_80072df0->pathfinding_maybe(0xe8,0xa8,2);
+																									DAT_80072df0->startWalk(0xe8,0xa8,2);
 																									while (DAT_80072df0->isFlagSet(ACTOR_FLAG_10)) {
 																										_vm->waitForFrames(1);
 																									}
-																									DAT_80072de8->pathfinding_maybe(0x97,0x37,2);
-																									DAT_80072dec->pathfinding_maybe(0x97,0x37,2);
-																									DAT_80072df4->pathfinding_maybe(0x97,0x37,2);
+																									DAT_80072de8->startWalk(0x97,0x37,2);
+																									DAT_80072dec->startWalk(0x97,0x37,2);
+																									DAT_80072df4->startWalk(0x97,0x37,2);
 																									DAT_80072df0->waitUntilFlag8SetThenSet1000AndWaitFor4();
 																									DAT_80072df0->updateSequence(6);
 																									uint16 dialog[2000];
@@ -274,7 +274,7 @@ void CutScene::scene1() {
 																									DAT_80072df0->waitUntilFlag8And4AreSet();
 																									DAT_80072df0->x_pos = 0xcf;
 																									DAT_80072df0->y_pos = 0x90;
-																									DAT_80072df0->pathfinding_maybe(0x97, 0x37, 2);
+																									DAT_80072df0->startWalk(0x97, 0x37, 2);
 																									DAT_80072df0->updateSequence(7);
 //TODO
 //																									if (((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0))
@@ -588,10 +588,10 @@ void CutScene::knightsSavedBackAtCastle() {
 			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x78e8,0x2e01) != 2) {
 				wideAngleEveryoneAtTable();
 				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e04,0x1a,0x19,0x7a1e,0x3e01) != 2) {
-					DAT_80072e04->field_7c = 0x10000;
+					DAT_80072e04->_walkSpeed = 0x10000;
 					DAT_80072e04->setFlag(ACTOR_FLAG_800);
 					DAT_80072e04->updateSequence(0x21);
-					DAT_80072e04->pathfinding_maybe(0x13f,0x6e,2);
+					DAT_80072e04->startWalk(0x13f,0x6e,2);
 					// wait for pathfinding to complete
 					while (DAT_80072e04->isFlagSet(ACTOR_FLAG_10)) { //TODO move to method on Actor waitForPathfinding() ??
 						//empty
@@ -688,21 +688,21 @@ void CutScene::flameReturnsCutScene() {
 	DAT_80072e04->y_pos = 99;
 	DAT_80072de8->x_pos = 0x10a;
 	DAT_80072de8->y_pos = 0x5a;
-	DAT_80072de8->field_7c = 0x10000;
-	DAT_80072e04->field_7c = 0x10000;
+	DAT_80072de8->_walkSpeed = 0x10000;
+	DAT_80072e04->_walkSpeed = 0x10000;
 	DAT_80072de8->setFlag(ACTOR_FLAG_800);
 	DAT_80072e04->setFlag(ACTOR_FLAG_800);
 	//	call_fade_related_1f();
 	_vm->setFlags(ENGINE_FLAG_20000);
 	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x8ab2,0x2e01) != 2) {
 		DAT_80072de8->updateSequence(0x1e);
-		DAT_80072de8->pathfinding_maybe(0xb0,0x6b,2);
+		DAT_80072de8->startWalk(0xb0,0x6b,2);
 		do {
 		} while (DAT_80072de8->isFlagSet(ACTOR_FLAG_10));
 		DAT_80072de8->updateSequence(0x1f);
 		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x8b40,0x2e01) != 2) {
 			DAT_80072e04->updateSequence(0x1b);
-			DAT_80072e04->pathfinding_maybe(0xd5,0x6b,2);
+			DAT_80072e04->startWalk(0xd5,0x6b,2);
 			do {
 			} while (DAT_80072e04->isFlagSet(ACTOR_FLAG_10));
 			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e04,0x1a,0x19,0x8bb6,0x3e01) != 2) {
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 9562a921a1..9e74952ac3 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1171,11 +1171,11 @@ void DragonsEngine::walkFlickerToObject()
 					targetX = targetINI->actor->x_pos;
 					targetY = targetINI->actor->y_pos;
 				}
-				flickerINI->actor->field_7c = 0x10000;
+				flickerINI->actor->_walkSpeed = 0x10000;
 				if (flickerINI->field_20_actor_field_14 == -1) {
 					flickerINI->actor->setFlag(ACTOR_FLAG_800);
 				}
-				flickerINI->actor->pathfinding_maybe((int)(((uint)targetX + (uint)targetINI->field_1c) * 0x10000) >> 0x10,
+				flickerINI->actor->startWalk((int)(((uint)targetX + (uint)targetINI->field_1c) * 0x10000) >> 0x10,
 													(int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10,0);
 				bit_flags_8006fbd8 = 1;
 				return;
@@ -1199,8 +1199,8 @@ void DragonsEngine::walkFlickerToObject()
 		if (_inventory->getType() == 0 && !isFlagSet(ENGINE_FLAG_200000)) {
 			uVar7 = (uint)(ushort)_cursor->_x;
 			uVar8 = (uint)(ushort)_cursor->_y;
-			flickerINI->actor->field_7c = 0x10000;
-			flickerINI->actor->pathfinding_maybe(
+			flickerINI->actor->_walkSpeed = 0x10000;
+			flickerINI->actor->startWalk(
 					(int)((uVar7 + (uint)_scene->_camera.x) * 0x10000) >> 0x10,
 					(int)((uVar8 + (uint)_scene->_camera.y) * 0x10000) >> 0x10,0);
 		}
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index c559da1f70..6137d66321 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -170,8 +170,8 @@ void Inventory::openInventory() {
 	for(int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		Actor *item = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 
-		item->x_pos = item->target_x_pos = invXPosTable[i] + 0x10;
-		item->y_pos = item->target_y_pos = invYPosTable[i] + 0xc;
+		item->x_pos = item->_walkDestX = invXPosTable[i] + 0x10;
+		item->y_pos = item->_walkDestY = invYPosTable[i] + 0xc;
 
 		if (inventoryItemTbl[i]) {
 			item->flags = 0; //clear all flags
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index c4245e2372..f68ef67af3 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -242,7 +242,7 @@ void Minigame3::run() {
 	handActorId->setFlag(ACTOR_FLAG_4000);
 	handActorId->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	handActorId->priorityLayer = 0;
-	handActorId->field_7c = 0x40000;
+	handActorId->_walkSpeed = 0x40000;
 	i = 0;
 	while ((int16)i < 2) {
 		tearBlinkActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x34,(uint)i,0,0);
@@ -730,7 +730,7 @@ void Minigame3::run() {
 			bVar1 = true;
 		}
 		if (bVar1) {
-			handActorId->pathfinding_maybe((int)handPositionsTbl[local_224].x, (int)handPositionsTbl[local_224].y, 2);
+			handActorId->startWalk((int)handPositionsTbl[local_224].x, (int)handPositionsTbl[local_224].y, 2);
 			bVar1 = false;
 		}
 	}
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 4733e69fea..2f04779fb8 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -612,11 +612,11 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 				ini->actor->flags |= Dragons::ACTOR_FLAG_800;
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
-			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
+			ini->actor->_walkSpeed = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
 		}
 
 		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
-		ini->actor->pathfinding_maybe(point.x, point.y, isFlicker ? 0 : 1);
+		ini->actor->startWalk(point.x, point.y, isFlicker ? 0 : 1);
 
 		if(s3 == 0) {
 			while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
@@ -634,7 +634,7 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 		ini->actor->y_pos = point.y;
 
 		if (field4 != field6) {
-			ini->actor->field_7c = field4;
+			ini->actor->_walkSpeed = field4;
 			ini->actor->updateSequence(field6 & 0x7fff);
 		}
 	}
@@ -666,10 +666,10 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 				ini->actor->flags |= Dragons::ACTOR_FLAG_800;
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
-			ini->actor->field_7c = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
+			ini->actor->_walkSpeed = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
 		}
 		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
-		ini->actor->pathfinding_maybe(field8, fieldA, isFlicker ? 0 : 1);
+		ini->actor->startWalk(field8, fieldA, isFlicker ? 0 : 1);
 
 		if(s3 == 0) {
 			while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
@@ -688,7 +688,7 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 		ini->actor->y_pos = fieldA;
 
 		if (field4 != field6) {
-			ini->actor->field_7c = field4;
+			ini->actor->_walkSpeed = field4;
 			ini->actor->updateSequence(field6 & 0x7fff);
 		}
 	}
@@ -738,7 +738,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 			secondIni->actor->x_pos = someXParam;
 		}
 		if (field6 != -1) {
-			secondIni->actor->field_7c = -1;
+			secondIni->actor->_walkSpeed = -1;
 			secondIni->actor->updateSequence(field6 & 0x7fff);
 		}
 		secondIni->x = someXParam;
@@ -756,7 +756,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 			secondIni->actor->setFlag(ACTOR_FLAG_800);
 			secondIni->actor->updateSequence(field6 & 0x7fff);
 		}
-		secondIni->actor->field_7c =
+		secondIni->actor->_walkSpeed =
 				someBooleanFlag;
 	}
 	int16 newXPosAgain = 0;
@@ -781,7 +781,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 			someBooleanFlag = 0;
 		}
 	}
-	secondIni->actor->pathfinding_maybe(newXPosAgain, newYPosAgain, someBooleanFlag);
+	secondIni->actor->startWalk(newXPosAgain, newYPosAgain, someBooleanFlag);
 	if (!bVar1) {
 		while (secondIni->actor->flags & Dragons::ACTOR_FLAG_10) {
 			_vm->waitForFrames(1);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index ca63dda296..df1269d0e9 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -352,8 +352,8 @@ void SpecialOpcodes::spcWalkOnStilts() {
 	Actor *actor = _vm->_dragonINIResource->getRecord(0x2a0)->actor;
 	Actor *actor1 = _vm->_dragonINIResource->getRecord(0x2a9)->actor;
 
-	actor->field_2c = actor->field_2c / 3;
-	actor->field_30 = actor->field_30 / 3;
+	actor->_walkSlopeX = actor->_walkSlopeX / 3;
+	actor->_walkSlopeY = actor->_walkSlopeY / 3;
 	bVar2 = false;
 	while (actor->isFlagSet(ACTOR_FLAG_10)) {
 		//pvVar3 = actor->frame_pointer_maybe;


Commit: 31e314ef7ead12ee06533aa141d15b4f88ac4396
    https://github.com/scummvm/scummvm/commit/31e314ef7ead12ee06533aa141d15b4f88ac4396
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add textIds to spcZigmondFraudSceneLogic

Changed paths:
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index df1269d0e9..3cf246c7d2 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -542,7 +542,6 @@ void SpecialOpcodes::spcClearEngineFlag0x2000000() {
 }
 
 void SpecialOpcodes::spcZigmondFraudSceneLogic() {
-	//TODO
 	sceneUpdater.numSteps[0] = 2;
 	sceneUpdater.numSteps[1] = 2;
 	sceneUpdater.numSteps[2] = 1;
@@ -551,7 +550,7 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic() {
 	sceneUpdater.numSteps[5] = 2;
 	sceneUpdater.numSteps[6] = 2;
 	sceneUpdater.numSteps[7] = 2;
-
+//TODO do we need this -> DAT_80072dc0 = 2;
 	sceneUpdater.iniIDTbl[0][0] = 0x19E;
 	sceneUpdater.iniIDTbl[0][1] = 0x197;
 	sceneUpdater.iniIDTbl[1][0] = 0x19E;
@@ -582,7 +581,21 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic() {
 	sceneUpdater.sequenceIDTbl[7][0] = 2;
 	sceneUpdater.sequenceIDTbl[7][1] = 0xe;
 
-	//TODO field4
+	sceneUpdater.textTbl[0][0] = 0x2D000;
+	sceneUpdater.textTbl[0][1] = 0x2D044;
+	sceneUpdater.textTbl[1][0] = 0x2D0B2;
+	sceneUpdater.textTbl[1][1] = 0x2D0D6;
+	sceneUpdater.textTbl[2][0] = 0x2D152;
+	sceneUpdater.textTbl[3][0] = 0x2D1A4;
+	sceneUpdater.textTbl[4][0] = 0x2D20A;
+	sceneUpdater.textTbl[4][1] = 0x2D27C;
+	sceneUpdater.textTbl[5][0] = 0x2D2EC;
+	sceneUpdater.textTbl[5][1] = 0x2D336;
+	sceneUpdater.textTbl[6][0] = 0x2D3E0;
+	sceneUpdater.textTbl[6][1] = 0x2D456;
+	sceneUpdater.textTbl[7][0] = 0x2D4A8;
+	sceneUpdater.textTbl[7][1] = 0x2D504;
+
 	setupTableBasedSceneUpdateFunction(0x168,8,0xb4);
 }
 


Commit: af43722a35631e76b274d2ffe8af305b307fe33d
    https://github.com/scummvm/scummvm/commit/af43722a35631e76b274d2ffe8af305b307fe33d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add garden scene logic

Changed paths:
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 3cf246c7d2..fa16c62f48 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -255,7 +255,46 @@ void SpecialOpcodes::spcDancingMiniGame() {
 }
 
 void SpecialOpcodes::spcCastleGardenLogic() {
-	//TODO
+	sceneUpdater.textTbl[0][0] = 0x22660;
+	sceneUpdater.textTbl[0][1] = 0x226CA;
+	sceneUpdater.textTbl[1][0] = 0x22738;
+	sceneUpdater.textTbl[1][1] = 0x22790;
+	sceneUpdater.textTbl[2][0] = 0x227E8;
+	sceneUpdater.textTbl[2][1] = 0x2283C;
+	sceneUpdater.textTbl[3][0] = 0x228A0;
+	sceneUpdater.textTbl[3][1] = 0x228EC;
+	if (_vm->getCurrentSceneId() == 0x1a) {
+		sceneUpdater.sequenceIDTbl[0][0] = 1;
+		sceneUpdater.sequenceIDTbl[1][0] = 1;
+		sceneUpdater.sequenceIDTbl[2][0] = 1;
+		sceneUpdater.sequenceIDTbl[3][0] = 1;
+		sceneUpdater.iniIDTbl[3][0] = 0x145;
+		sceneUpdater.iniIDTbl[4][0] = 0x144;
+	}
+	else {
+		sceneUpdater.sequenceIDTbl[0][0] = -1;
+		sceneUpdater.sequenceIDTbl[1][0] = -1;
+		sceneUpdater.sequenceIDTbl[2][0] = -1;
+		sceneUpdater.sequenceIDTbl[3][0] = -1;
+		sceneUpdater.iniIDTbl[3][0] = 0x83;
+		sceneUpdater.iniIDTbl[4][0] = 0x74;
+	}
+	sceneUpdater.sequenceIDTbl[3][1] = 1;
+	sceneUpdater.sequenceIDTbl[2][1] = 1;
+	sceneUpdater.sequenceIDTbl[1][1] = 1;
+	sceneUpdater.sequenceIDTbl[0][1] = 1;
+	sceneUpdater.numSteps[0] = 2;
+	sceneUpdater.numSteps[1] = 2;
+	sceneUpdater.numSteps[2] = 2;
+	sceneUpdater.numSteps[3] = 2;
+	sceneUpdater.iniIDTbl[0][0] = sceneUpdater.iniIDTbl[3][0];
+	sceneUpdater.iniIDTbl[0][1] = sceneUpdater.iniIDTbl[4][0];
+	sceneUpdater.iniIDTbl[1][0] = sceneUpdater.iniIDTbl[3][0];
+	sceneUpdater.iniIDTbl[1][1] = sceneUpdater.iniIDTbl[4][0];
+	sceneUpdater.iniIDTbl[2][0] = sceneUpdater.iniIDTbl[3][0];
+	sceneUpdater.iniIDTbl[2][1] = sceneUpdater.iniIDTbl[4][0];
+	sceneUpdater.iniIDTbl[3][1] = sceneUpdater.iniIDTbl[4][0];
+	setupTableBasedSceneUpdateFunction(1,4,0xb4);
 }
 
 void SpecialOpcodes::spcUnk9() {
@@ -339,6 +378,99 @@ void SpecialOpcodes::spcSetEngineFlag8() {
 
 void SpecialOpcodes::spcKnightPoolReflectionLogic() {
 	//TODO
+	/*
+	sceneUpdateTblTextId0[0] = DAT_80063c10;
+	sceneUpdateTblTextId0[1] = DAT_80063c14;
+	sceneUpdateTblTextId0[2] = DAT_80063c18;
+	sceneUpdateTblTextId0[3] = DAT_80063c1c;
+	sceneUpdateTblTextId1[0] = DAT_80063c20;
+	sceneUpdateTblTextId1[1] = DAT_80063c24;
+	sceneUpdateTblTextId2[0] = DAT_80063c28;
+	sceneUpdateTblTextId2[1] = DAT_80063c2c;
+	sceneUpdateTblTextId2[2] = DAT_80063c30;
+	sceneUpdateTblTextId2[3] = DAT_80063c34;
+	sceneUpdateTblTextId2[4] = DAT_80063c38;
+	sceneUpdateTblTextId3[0] = DAT_80063c3c;
+	sceneUpdateTblTextId3[1] = DAT_80063c40;
+	sceneUpdateTblTextId3[2] = DAT_80063c44;
+	sceneUpdateTblTextId3[3] = DAT_80063c48;
+	sceneUpdateTblTextId4[0] = DAT_80063c4c;
+	sceneUpdateTblTextId4[1] = DAT_80063c50;
+	sceneUpdateTblTextId4[2] = DAT_80063c54;
+	sceneUpdateTblTextId4[3] = DAT_80063c58;
+	sceneUpdateTblTextId5[0] = DAT_80063c5c;
+	sceneUpdateTblTextId5[1] = DAT_80063c60;
+	sceneUpdateTblTextId5[2] = DAT_80063c64;
+	sceneUpdateTblIniId0[0] = DAT_80063bb0;
+	sceneUpdateTblIniId0[1] = DAT_80063bac;
+	sceneUpdateTblIniId0[2] = DAT_80063bb0;
+	sceneUpdateTblIniId0[3] = DAT_80063bac;
+	sceneUpdateTblIniId1[0] = DAT_80063bb0;
+	sceneUpdateTblIniId1[1] = DAT_80063bac;
+	sceneUpdateTblIniId2[0] = DAT_80063bb0;
+	sceneUpdateTblIniId2[1] = DAT_80063bac;
+	sceneUpdateTblIniId2[2] = DAT_80063bb0;
+	sceneUpdateTblIniId2[3] = DAT_80063bac;
+	sceneUpdateTblIniId2[4] = DAT_80063bb0;
+	sceneUpdateTblIniId3[0] = DAT_80063bb0;
+	sceneUpdateTblIniId3[1] = DAT_80063bac;
+	sceneUpdateTblIniId3[2] = DAT_80063bb0;
+	sceneUpdateTblIniId3[3] = DAT_80063bac;
+	sceneUpdateTblIniId4[0] = DAT_80063bac;
+	sceneUpdateTblIniId4[1] = DAT_80063bb0;
+	sceneUpdateTblIniId4[2] = DAT_80063bac;
+	sceneUpdateTblIniId4[3] = DAT_80063bb0;
+	sceneUpdateTblIniId5[0] = DAT_80063bb0;
+	sceneUpdateTblIniId5[1] = DAT_80063bac;
+	sceneUpdateTblIniId5[2] = DAT_80063bb0;
+	sceneUpdateTblSeqId0[0] = 10;
+	sceneUpdateTblSeqId0[1] = 2;
+	sceneUpdateTblSeqId0[2] = 10;
+	sceneUpdateTblSeqId0[3] = 2;
+	sceneUpdateTblSeqId1[0] = 10;
+	sceneUpdateTblSeqId1[1] = 2;
+	sceneUpdateTblSeqId2[0] = 10;
+	sceneUpdateTblSeqId2[1] = 2;
+	sceneUpdateTblSeqId2[2] = 10;
+	sceneUpdateTblSeqId2[3] = 2;
+	sceneUpdateTblSeqId2[4] = 10;
+	sceneUpdateTblSeqId3[0] = 10;
+	sceneUpdateTblSeqId3[1] = 2;
+	sceneUpdateTblSeqId3[2] = 10;
+	sceneUpdateTblSeqId3[3] = 2;
+	sceneUpdateTblSeqId4[0] = 2;
+	sceneUpdateTblSeqId4[1] = 10;
+	sceneUpdateTblSeqId4[2] = 2;
+	sceneUpdateTblSeqId4[3] = 10;
+	sceneUpdateTblSeqId5[0] = 10;
+	sceneUpdateTblSeqId5[2] = 10;
+	sceneUpdateSequenceTbl[2].numSteps = 5;
+	sceneUpdateTblSeqId5[1] = 2;
+	sceneUpdateSequenceTbl[1].numSteps = 2;
+	sceneUpdateSequenceTbl[0].numSteps = 4;
+	sceneUpdateSequenceTbl[3].numSteps = 4;
+	sceneUpdateSequenceTbl[4].numSteps = 4;
+	sceneUpdateSequenceTbl[5].numSteps = 3;
+	sceneUpdateSequenceTbl[0].textTbl = sceneUpdateTblTextId0;
+	sceneUpdateSequenceTbl[1].textTbl = sceneUpdateTblTextId1;
+	sceneUpdateSequenceTbl[2].textTbl = sceneUpdateTblTextId2;
+	sceneUpdateSequenceTbl[3].textTbl = sceneUpdateTblTextId3;
+	sceneUpdateSequenceTbl[4].textTbl = sceneUpdateTblTextId4;
+	sceneUpdateSequenceTbl[5].textTbl = sceneUpdateTblTextId5;
+	sceneUpdateSequenceTbl[5].sequenceIdPtr = sceneUpdateTblSeqId5;
+	sceneUpdateSequenceTbl[4].sequenceIdPtr = sceneUpdateTblSeqId4;
+	sceneUpdateSequenceTbl[0].iniIdPtr = sceneUpdateTblIniId0;
+	sceneUpdateSequenceTbl[1].iniIdPtr = sceneUpdateTblIniId1;
+	sceneUpdateSequenceTbl[2].iniIdPtr = sceneUpdateTblIniId2;
+	sceneUpdateSequenceTbl[3].iniIdPtr = sceneUpdateTblIniId3;
+	sceneUpdateSequenceTbl[4].iniIdPtr = sceneUpdateTblIniId4;
+	sceneUpdateSequenceTbl[5].iniIdPtr = sceneUpdateTblIniId5;
+	sceneUpdateSequenceTbl[0].sequenceIdPtr = sceneUpdateTblSeqId0;
+	sceneUpdateSequenceTbl[1].sequenceIdPtr = sceneUpdateTblSeqId1;
+	sceneUpdateSequenceTbl[2].sequenceIdPtr = sceneUpdateTblSeqId2;
+	sceneUpdateSequenceTbl[3].sequenceIdPtr = sceneUpdateTblSeqId3;
+	setupTableBasedSceneUpdateFunction(0x168,6,300);
+	 */
 }
 
 void SpecialOpcodes::spcWalkOnStilts() {
@@ -829,7 +961,6 @@ void SpecialOpcodes::spcStopScreenShakeUpdater() {
 }
 
 void SpecialOpcodes::spcInsideBlackDragonScreenShake() {
-	const int16 shakeTbl[5] = {5, -2, 4, -1, 0};
 	for (int i = 0; i < 5; i ++) {
 		_vm->_screen->setScreenShakeOffset(0, shakeTbl[i]);
 		_vm->waitForFrames(1);
@@ -1150,7 +1281,7 @@ void tableBasedSceneUpdateFunction() {
 					actor->updateSequence(spc->sceneUpdater.sequenceID);
 					spc->sceneUpdater.sequenceID = originalSequenceID;
 				}
-				//TODO FUN_80036a68((&DAT_800832d8)[sceneUpdateSequenceTbl[uVar3].field_0x4[(uint) spc->sceneUpdater.curSequenceIndex]]);
+				vm->_talk->playDialogAudioDontWait(spc->sceneUpdater.textTbl[uVar3][spc->sceneUpdater.curSequenceIndex]);
 				spc->sceneUpdater.curSequenceIndex++;
 				spc->sceneUpdater.counter = 0x1e;
 				if (spc->sceneUpdater.numSteps[uVar3] <= (uint) spc->sceneUpdater.curSequenceIndex) {


Commit: 1116df23c1daaa2d0bcab3cc207ad9935c501837
    https://github.com/scummvm/scummvm/commit/1116df23c1daaa2d0bcab3cc207ad9935c501837
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added table based scene updater logic

Changed paths:
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index fa16c62f48..bf66c80780 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -377,100 +377,80 @@ void SpecialOpcodes::spcSetEngineFlag8() {
 }
 
 void SpecialOpcodes::spcKnightPoolReflectionLogic() {
-	//TODO
-	/*
-	sceneUpdateTblTextId0[0] = DAT_80063c10;
-	sceneUpdateTblTextId0[1] = DAT_80063c14;
-	sceneUpdateTblTextId0[2] = DAT_80063c18;
-	sceneUpdateTblTextId0[3] = DAT_80063c1c;
-	sceneUpdateTblTextId1[0] = DAT_80063c20;
-	sceneUpdateTblTextId1[1] = DAT_80063c24;
-	sceneUpdateTblTextId2[0] = DAT_80063c28;
-	sceneUpdateTblTextId2[1] = DAT_80063c2c;
-	sceneUpdateTblTextId2[2] = DAT_80063c30;
-	sceneUpdateTblTextId2[3] = DAT_80063c34;
-	sceneUpdateTblTextId2[4] = DAT_80063c38;
-	sceneUpdateTblTextId3[0] = DAT_80063c3c;
-	sceneUpdateTblTextId3[1] = DAT_80063c40;
-	sceneUpdateTblTextId3[2] = DAT_80063c44;
-	sceneUpdateTblTextId3[3] = DAT_80063c48;
-	sceneUpdateTblTextId4[0] = DAT_80063c4c;
-	sceneUpdateTblTextId4[1] = DAT_80063c50;
-	sceneUpdateTblTextId4[2] = DAT_80063c54;
-	sceneUpdateTblTextId4[3] = DAT_80063c58;
-	sceneUpdateTblTextId5[0] = DAT_80063c5c;
-	sceneUpdateTblTextId5[1] = DAT_80063c60;
-	sceneUpdateTblTextId5[2] = DAT_80063c64;
-	sceneUpdateTblIniId0[0] = DAT_80063bb0;
-	sceneUpdateTblIniId0[1] = DAT_80063bac;
-	sceneUpdateTblIniId0[2] = DAT_80063bb0;
-	sceneUpdateTblIniId0[3] = DAT_80063bac;
-	sceneUpdateTblIniId1[0] = DAT_80063bb0;
-	sceneUpdateTblIniId1[1] = DAT_80063bac;
-	sceneUpdateTblIniId2[0] = DAT_80063bb0;
-	sceneUpdateTblIniId2[1] = DAT_80063bac;
-	sceneUpdateTblIniId2[2] = DAT_80063bb0;
-	sceneUpdateTblIniId2[3] = DAT_80063bac;
-	sceneUpdateTblIniId2[4] = DAT_80063bb0;
-	sceneUpdateTblIniId3[0] = DAT_80063bb0;
-	sceneUpdateTblIniId3[1] = DAT_80063bac;
-	sceneUpdateTblIniId3[2] = DAT_80063bb0;
-	sceneUpdateTblIniId3[3] = DAT_80063bac;
-	sceneUpdateTblIniId4[0] = DAT_80063bac;
-	sceneUpdateTblIniId4[1] = DAT_80063bb0;
-	sceneUpdateTblIniId4[2] = DAT_80063bac;
-	sceneUpdateTblIniId4[3] = DAT_80063bb0;
-	sceneUpdateTblIniId5[0] = DAT_80063bb0;
-	sceneUpdateTblIniId5[1] = DAT_80063bac;
-	sceneUpdateTblIniId5[2] = DAT_80063bb0;
-	sceneUpdateTblSeqId0[0] = 10;
-	sceneUpdateTblSeqId0[1] = 2;
-	sceneUpdateTblSeqId0[2] = 10;
-	sceneUpdateTblSeqId0[3] = 2;
-	sceneUpdateTblSeqId1[0] = 10;
-	sceneUpdateTblSeqId1[1] = 2;
-	sceneUpdateTblSeqId2[0] = 10;
-	sceneUpdateTblSeqId2[1] = 2;
-	sceneUpdateTblSeqId2[2] = 10;
-	sceneUpdateTblSeqId2[3] = 2;
-	sceneUpdateTblSeqId2[4] = 10;
-	sceneUpdateTblSeqId3[0] = 10;
-	sceneUpdateTblSeqId3[1] = 2;
-	sceneUpdateTblSeqId3[2] = 10;
-	sceneUpdateTblSeqId3[3] = 2;
-	sceneUpdateTblSeqId4[0] = 2;
-	sceneUpdateTblSeqId4[1] = 10;
-	sceneUpdateTblSeqId4[2] = 2;
-	sceneUpdateTblSeqId4[3] = 10;
-	sceneUpdateTblSeqId5[0] = 10;
-	sceneUpdateTblSeqId5[2] = 10;
-	sceneUpdateSequenceTbl[2].numSteps = 5;
-	sceneUpdateTblSeqId5[1] = 2;
-	sceneUpdateSequenceTbl[1].numSteps = 2;
-	sceneUpdateSequenceTbl[0].numSteps = 4;
-	sceneUpdateSequenceTbl[3].numSteps = 4;
-	sceneUpdateSequenceTbl[4].numSteps = 4;
-	sceneUpdateSequenceTbl[5].numSteps = 3;
-	sceneUpdateSequenceTbl[0].textTbl = sceneUpdateTblTextId0;
-	sceneUpdateSequenceTbl[1].textTbl = sceneUpdateTblTextId1;
-	sceneUpdateSequenceTbl[2].textTbl = sceneUpdateTblTextId2;
-	sceneUpdateSequenceTbl[3].textTbl = sceneUpdateTblTextId3;
-	sceneUpdateSequenceTbl[4].textTbl = sceneUpdateTblTextId4;
-	sceneUpdateSequenceTbl[5].textTbl = sceneUpdateTblTextId5;
-	sceneUpdateSequenceTbl[5].sequenceIdPtr = sceneUpdateTblSeqId5;
-	sceneUpdateSequenceTbl[4].sequenceIdPtr = sceneUpdateTblSeqId4;
-	sceneUpdateSequenceTbl[0].iniIdPtr = sceneUpdateTblIniId0;
-	sceneUpdateSequenceTbl[1].iniIdPtr = sceneUpdateTblIniId1;
-	sceneUpdateSequenceTbl[2].iniIdPtr = sceneUpdateTblIniId2;
-	sceneUpdateSequenceTbl[3].iniIdPtr = sceneUpdateTblIniId3;
-	sceneUpdateSequenceTbl[4].iniIdPtr = sceneUpdateTblIniId4;
-	sceneUpdateSequenceTbl[5].iniIdPtr = sceneUpdateTblIniId5;
-	sceneUpdateSequenceTbl[0].sequenceIdPtr = sceneUpdateTblSeqId0;
-	sceneUpdateSequenceTbl[1].sequenceIdPtr = sceneUpdateTblSeqId1;
-	sceneUpdateSequenceTbl[2].sequenceIdPtr = sceneUpdateTblSeqId2;
-	sceneUpdateSequenceTbl[3].sequenceIdPtr = sceneUpdateTblSeqId3;
+	sceneUpdater.textTbl[0][0] = 0x23E90;
+	sceneUpdater.textTbl[0][1] = 0x23EE6;
+	sceneUpdater.textTbl[0][2] = 0x23F0C;
+	sceneUpdater.textTbl[0][3] = 0x23F86;
+	sceneUpdater.textTbl[1][0] = 0x24000;
+	sceneUpdater.textTbl[1][1] = 0x2406A;
+	sceneUpdater.textTbl[2][0] = 0x240C2;
+	sceneUpdater.textTbl[2][1] = 0x2411E;
+	sceneUpdater.textTbl[2][2] = 0x24158;
+	sceneUpdater.textTbl[2][3] = 0x241BC;
+	sceneUpdater.textTbl[2][4] = 0x241EE;
+	sceneUpdater.textTbl[3][0] = 0x24240;
+	sceneUpdater.textTbl[3][1] = 0x24286;
+	sceneUpdater.textTbl[3][2] = 0x242B0;
+	sceneUpdater.textTbl[3][3] = 0x2431C;
+	sceneUpdater.textTbl[4][0] = 0x2437C;
+	sceneUpdater.textTbl[4][1] = 0x243B2;
+	sceneUpdater.textTbl[4][2] = 0x2440A;
+	sceneUpdater.textTbl[4][3] = 0x24432;
+	sceneUpdater.textTbl[5][0] = 0x24480;
+	sceneUpdater.textTbl[5][1] = 0x244EE;
+	sceneUpdater.textTbl[5][2] = 0x2453C;
+
+	sceneUpdater.iniIDTbl[0][0] = 0x155;
+	sceneUpdater.iniIDTbl[0][1] = 0x14B;
+	sceneUpdater.iniIDTbl[0][2] = 0x155;
+	sceneUpdater.iniIDTbl[0][3] = 0x14B;
+	sceneUpdater.iniIDTbl[1][0] = 0x155;
+	sceneUpdater.iniIDTbl[1][1] = 0x14B;
+	sceneUpdater.iniIDTbl[2][0] = 0x155;
+	sceneUpdater.iniIDTbl[2][1] = 0x14B;
+	sceneUpdater.iniIDTbl[2][2] = 0x155;
+	sceneUpdater.iniIDTbl[2][3] = 0x14B;
+	sceneUpdater.iniIDTbl[2][4] = 0x155;
+	sceneUpdater.iniIDTbl[3][0] = 0x155;
+	sceneUpdater.iniIDTbl[3][1] = 0x14B;
+	sceneUpdater.iniIDTbl[3][2] = 0x155;
+	sceneUpdater.iniIDTbl[3][3] = 0x14B;
+	sceneUpdater.iniIDTbl[4][0] = 0x14B;
+	sceneUpdater.iniIDTbl[4][1] = 0x155;
+	sceneUpdater.iniIDTbl[4][2] = 0x14B;
+	sceneUpdater.iniIDTbl[4][3] = 0x155;
+	sceneUpdater.iniIDTbl[5][0] = 0x155;
+	sceneUpdater.iniIDTbl[5][1] = 0x14B;
+	sceneUpdater.iniIDTbl[5][2] = 0x155;
+	sceneUpdater.sequenceIDTbl[0][0] = 10;
+	sceneUpdater.sequenceIDTbl[0][1] = 2;
+	sceneUpdater.sequenceIDTbl[0][2] = 10;
+	sceneUpdater.sequenceIDTbl[0][3] = 2;
+	sceneUpdater.sequenceIDTbl[1][0] = 10;
+	sceneUpdater.sequenceIDTbl[1][1] = 2;
+	sceneUpdater.sequenceIDTbl[2][0] = 10;
+	sceneUpdater.sequenceIDTbl[2][1] = 2;
+	sceneUpdater.sequenceIDTbl[2][2] = 10;
+	sceneUpdater.sequenceIDTbl[2][3] = 2;
+	sceneUpdater.sequenceIDTbl[2][4] = 10;
+	sceneUpdater.sequenceIDTbl[3][0] = 10;
+	sceneUpdater.sequenceIDTbl[3][1] = 2;
+	sceneUpdater.sequenceIDTbl[3][2] = 10;
+	sceneUpdater.sequenceIDTbl[3][3] = 2;
+	sceneUpdater.sequenceIDTbl[4][0] = 2;
+	sceneUpdater.sequenceIDTbl[4][1] = 10;
+	sceneUpdater.sequenceIDTbl[4][2] = 2;
+	sceneUpdater.sequenceIDTbl[4][3] = 10;
+	sceneUpdater.sequenceIDTbl[5][0] = 10;
+	sceneUpdater.sequenceIDTbl[5][2] = 10;
+	sceneUpdater.numSteps[2] = 5;
+	sceneUpdater.sequenceIDTbl[5][1] = 2;
+	sceneUpdater.numSteps[1] = 2;
+	sceneUpdater.numSteps[0] = 4;
+	sceneUpdater.numSteps[3] = 4;
+	sceneUpdater.numSteps[4] = 4;
+	sceneUpdater.numSteps[5] = 3;
 	setupTableBasedSceneUpdateFunction(0x168,6,300);
-	 */
 }
 
 void SpecialOpcodes::spcWalkOnStilts() {
@@ -655,7 +635,42 @@ void SpecialOpcodes::spcNoop1() {
 }
 
 void SpecialOpcodes::spcTownAngryVillagersSceneLogic() {
-	//TODO
+	sceneUpdater.textTbl[0][0] = 0x35946;
+	sceneUpdater.textTbl[0][1] = 0x359BC;
+	sceneUpdater.textTbl[1][0] = 0x35A38;
+	sceneUpdater.textTbl[1][1] = 0x35ABC;
+	sceneUpdater.textTbl[2][0] = 0x35B28;
+	sceneUpdater.textTbl[2][1] = 0x35B9C;
+	sceneUpdater.textTbl[3][0] = 0x35C10;
+	sceneUpdater.textTbl[3][1] = 0x35C80;
+	sceneUpdater.textTbl[4][0] = 0x35CFA;
+	sceneUpdater.textTbl[4][1] = 0x35D64;
+	sceneUpdater.iniIDTbl[0][0] = 0x1DC;
+	sceneUpdater.iniIDTbl[0][1] = 0x1DD;
+	sceneUpdater.iniIDTbl[1][0] = 0x1DC;
+	sceneUpdater.iniIDTbl[1][1] = 0x1DD;
+	sceneUpdater.iniIDTbl[2][0] = 0x1DC;
+	sceneUpdater.iniIDTbl[2][1] = 0x1DD;
+	sceneUpdater.iniIDTbl[3][0] = 0x1DC;
+	sceneUpdater.iniIDTbl[3][1] = 0x1DD;
+	sceneUpdater.iniIDTbl[4][0] = 0x1DC;
+	sceneUpdater.iniIDTbl[4][1] = 0x1DD;
+	sceneUpdater.sequenceIDTbl[0][0] = 0x11;
+	sceneUpdater.sequenceIDTbl[0][1] = 6;
+	sceneUpdater.sequenceIDTbl[1][0] = 0x11;
+	sceneUpdater.sequenceIDTbl[1][1] = 6;
+	sceneUpdater.sequenceIDTbl[2][0] = 0x11;
+	sceneUpdater.sequenceIDTbl[2][1] = 6;
+	sceneUpdater.sequenceIDTbl[3][0] = 0x11;
+	sceneUpdater.sequenceIDTbl[3][1] = 6;
+	sceneUpdater.sequenceIDTbl[4][0] = 0x11;
+	sceneUpdater.sequenceIDTbl[4][1] = 6;
+	sceneUpdater.numSteps[0] = 2;
+	sceneUpdater.numSteps[1] = 2;
+	sceneUpdater.numSteps[2] = 2;
+	sceneUpdater.numSteps[3] = 2;
+	sceneUpdater.numSteps[4] = 2;
+	setupTableBasedSceneUpdateFunction(0xf0,5,0x708);
 }
 
 void SpecialOpcodes::spcBlackDragonCrashThroughGate() {
@@ -741,22 +756,103 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic1() {
 }
 
 void SpecialOpcodes::spcBrokenBlackDragonSceneLogic() {
-	//TODO spcBrokenBlackDragonSceneLogic
+	sceneUpdater.sequenceIDTbl[0][0] = 5;
+	sceneUpdater.sequenceIDTbl[1][0] = 5;
+	sceneUpdater.sequenceIDTbl[1][1] = 2;
+	sceneUpdater.sequenceIDTbl[2][0] = 5;
+	sceneUpdater.numSteps[0] = 1;
+	sceneUpdater.sequenceIDTbl[2][1] = 2;
+	sceneUpdater.numSteps[1] = 2;
+	sceneUpdater.numSteps[2] = 2;
+	sceneUpdater.textTbl[0][0] = 0x40802;
+	sceneUpdater.textTbl[1][0] = 0x40852;
+	sceneUpdater.textTbl[1][1] = 0x40896;
+	sceneUpdater.textTbl[2][0] = 0x408C0;
+	sceneUpdater.textTbl[2][1] = 0x4092A;
+	sceneUpdater.iniIDTbl[0][0] = 0x23B;
+	sceneUpdater.iniIDTbl[1][0] = 0x23B;
+	sceneUpdater.iniIDTbl[1][1] = 0x231;
+	sceneUpdater.iniIDTbl[2][0] = 0x23B;
+	sceneUpdater.iniIDTbl[2][1] = 0x231;
+	setupTableBasedSceneUpdateFunction(300,3,600);
 }
 
 void SpecialOpcodes::spcDodoUnderAttackSceneLogic() {
-	//TODO
-	sceneUpdater.sequenceID = -1;
+	sceneUpdater.sequenceIDTbl[0][0] = 8;
+	sceneUpdater.sequenceIDTbl[1][0] = 8;
+	sceneUpdater.sequenceIDTbl[2][0] = 8;
+	sceneUpdater.sequenceIDTbl[3][0] = 8;
+	sceneUpdater.sequenceIDTbl[4][0] = 8;
+	sceneUpdater.sequenceIDTbl[5][0] = 8;
+	sceneUpdater.numSteps[0] = 1;
+	sceneUpdater.numSteps[1] = 1;
+	sceneUpdater.textTbl[0][0] = 0x3353A;
+	sceneUpdater.iniIDTbl[0][0] = 0x1C4;
+	sceneUpdater.textTbl[1][0] = 0x335AC;
+	sceneUpdater.iniIDTbl[1][0] = 0x1C4;
+	sceneUpdater.textTbl[2][0] = 0x335F8;
+	sceneUpdater.iniIDTbl[2][0] = 0x1C4;
+	sceneUpdater.textTbl[3][0] = 0x33660;
+	sceneUpdater.iniIDTbl[3][0] = 0x1C4;
+	sceneUpdater.textTbl[4][0] = 0x336DE;
+	sceneUpdater.iniIDTbl[4][0] = 0x1C4;
+	sceneUpdater.textTbl[5][0] = 0x3375C;
+	sceneUpdater.iniIDTbl[5][0] = 0x1C4;
+	sceneUpdater.numSteps[2] = 1;
+	sceneUpdater.numSteps[3] = 1;
+	sceneUpdater.numSteps[4] = 1;
+	sceneUpdater.numSteps[5] = 1;
+	setupTableBasedSceneUpdateFunction(0x1e0,6,0x1e0);
 }
 
 void SpecialOpcodes::spcForestWithoutDodoSceneLogic() {
-	//TODO
-	sceneUpdater.sequenceID = -1;
+	sceneUpdater.sequenceIDTbl[0][0] = 5;
+	sceneUpdater.sequenceIDTbl[0][1] = 0xb;
+	sceneUpdater.sequenceIDTbl[1][0] = 0xb;
+	sceneUpdater.sequenceIDTbl[1][2] = 0xb;
+	sceneUpdater.numSteps[0] = 2;
+	sceneUpdater.numSteps[1] = 3;
+	sceneUpdater.sequenceIDTbl[1][1] = 5;
+	sceneUpdater.textTbl[0][0] = 0x33EA0;
+	sceneUpdater.iniIDTbl[0][0] = 0x1C5;
+	sceneUpdater.textTbl[0][1] = 0x33EFC;
+	sceneUpdater.iniIDTbl[0][1] = 0x1C4;
+	sceneUpdater.textTbl[1][0] = 0x33F34;
+	sceneUpdater.iniIDTbl[1][0] = 0x1C4;
+	sceneUpdater.textTbl[1][1] = 0x34000;
+	sceneUpdater.iniIDTbl[1][1] = 0x1C5;
+	sceneUpdater.textTbl[1][2] = 0x34074;
+	sceneUpdater.iniIDTbl[1][2] = 0x1C4;
+	setupTableBasedSceneUpdateFunction(300,2,600);
 }
 
 void SpecialOpcodes::spcBlackDragonOnHillSceneLogic() {
-	//TODO
-	sceneUpdater.sequenceID = -1;
+	sceneUpdater.sequenceIDTbl[0][0] = 3;
+	sceneUpdater.sequenceIDTbl[0][1] = 7;
+	sceneUpdater.sequenceIDTbl[1][0] = 3;
+	sceneUpdater.sequenceIDTbl[1][1] = 7;
+	sceneUpdater.sequenceIDTbl[2][0] = 3;
+	sceneUpdater.sequenceIDTbl[2][1] = 7;
+	sceneUpdater.sequenceIDTbl[3][0] = 3;
+	sceneUpdater.numSteps[0] = 2;
+	sceneUpdater.textTbl[0][0] = 0x325EA;
+	sceneUpdater.textTbl[0][1] = 0x3262A;
+	sceneUpdater.textTbl[1][0] = 0x32686;
+	sceneUpdater.textTbl[1][1] = 0x326D8;
+	sceneUpdater.textTbl[2][0] = 0x3270E;
+	sceneUpdater.textTbl[2][1] = 0x32774;
+	sceneUpdater.textTbl[3][0] = 0x32D72;
+	sceneUpdater.iniIDTbl[0][0] = 0x1B6;
+	sceneUpdater.iniIDTbl[0][1] = 0x1B7;
+	sceneUpdater.iniIDTbl[1][0] = 0x1B6;
+	sceneUpdater.iniIDTbl[1][1] = 0x1B7;
+	sceneUpdater.iniIDTbl[2][0] = 0x1B6;
+	sceneUpdater.iniIDTbl[2][1] = 0x1B7;
+	sceneUpdater.iniIDTbl[3][0] = 0x1B6;
+	sceneUpdater.numSteps[1] = 2;
+	sceneUpdater.numSteps[2] = 2;
+	sceneUpdater.numSteps[3] = 1;
+	setupTableBasedSceneUpdateFunction(300,4,300);
 }
 
 void SpecialOpcodes::spcUnk4e() {
@@ -1122,7 +1218,19 @@ void SpecialOpcodes::spcUseClickerOnLever() {
 }
 
 void SpecialOpcodes::spcJesterInLibrarySceneLogic() {
-	//TODO
+	sceneUpdater.sequenceIDTbl[0][0] = 0xffff;
+	sceneUpdater.sequenceIDTbl[1][0] = 0xffff;
+	sceneUpdater.sequenceIDTbl[2][0] = 0xffff;
+	sceneUpdater.numSteps[0] = 1;
+	sceneUpdater.numSteps[1] = 1;
+	sceneUpdater.numSteps[2] = 1;
+	sceneUpdater.textTbl[0][0] = 0x18502;
+	sceneUpdater.textTbl[1][0] = 0x185E0;
+	sceneUpdater.textTbl[2][0] = 0x18596;
+	sceneUpdater.iniIDTbl[0][0] = 0xD7;
+	sceneUpdater.iniIDTbl[1][0] = 0xD7;
+	sceneUpdater.iniIDTbl[2][0] = 0xD7;
+	setupTableBasedSceneUpdateFunction(300,3,0x708);
 }
 
 void SpecialOpcodes::pizzaMakerStopWorking() {


Commit: 8a639a6eba936e46e69c26a5b895f2bbfc2a2e43
    https://github.com/scummvm/scummvm/commit/8a639a6eba936e46e69c26a5b895f2bbfc2a2e43
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added more scene update functions

Changed paths:
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index bf66c80780..e59f32cae4 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -547,61 +547,73 @@ void SpecialOpcodes::spcFlickerSetPriority2() {
 }
 
 void SpecialOpcodes::spcMenInMinesSceneLogic() {
+	_vm->setSceneUpdateFunction(menInMinesSceneUpdateFunction);
 	//TODO
+//	uint16_t_80083154 = 0;
+//	DAT_80083148 = 0;
+	setSpecialOpCounter(0);
 }
 
 void SpecialOpcodes::spcStopMenInMinesSceneLogic() {
-	//TODO
+	if (_vm->getSceneUpdateFunction() == monksAtBarSceneUpdateFunction) {
+		_vm->setSceneUpdateFunction(NULL);
+		if (0x3c < _specialOpCounter) {
+			_specialOpCounter = 0x3c;
+		}
+		for (; _specialOpCounter > 0; _specialOpCounter--) {
+			_vm->waitForFrames(1);
+		}
+		//TODO
+		//FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+	}
 }
 
 void SpecialOpcodes::spcMonksAtBarSceneLogic() {
+	setSpecialOpCounter(-1);
+	_vm->setSceneUpdateFunction(monksAtBarSceneUpdateFunction);
 	//TODO
+//	uint16_t_80083154 = 0;
+//	DAT_80083148 = 0;
 }
 
 void SpecialOpcodes::spcStopMonksAtBarSceneLogic() {
-	//TODO
+	if (_vm->getSceneUpdateFunction() == monksAtBarSceneUpdateFunction) {
+		_vm->setSceneUpdateFunction(NULL);
+		//TODO
+//		if ((DAT_80083148 != 0) && (uint16_t_80083154 != 0)) {
+//			FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,
+//						 (uint)DAT_80083158);
+//		}
+		setSpecialOpCounter(0);
+//		uint16_t_80083154 = 0;
+//		DAT_80083148 = 0;
+	}
+
 }
 
 void SpecialOpcodes::spcFlameBedroomEscapeSceneLogic() {
+	setSpecialOpCounter(-1);
 	//TODO
-//	local_fc8 = DAT_80063cb8;
-//	local_fc4 = DAT_80063cbc;
-//	local_fc0 = DAT_80063cc0;
-//	local_fbc = DAT_80063cc0;
-//	local_fb8 = DAT_80063cc8;
-//	local_fb4 = DAT_80063ccc;
-//	local_ff0[0] = DAT_80063cb8;
-//	local_ff0[1] = DAT_80063cbc;
-//	local_ff0[2] = DAT_80063cc0;
-//	local_ff0[3] = DAT_80063cc0;
-//	local_fe0 = DAT_80063cc8;
-//	local_fdc = DAT_80063ccc;
-//	DisableVSyncEvent();
-//	uVar13 = 0;
-//	uVar7 = 0;
-//	do {
-//		uVar13 = uVar13 + 1;
-//		(&DAT_800832d8)[uVar7] = local_ff0[uVar7];
-//		uVar7 = (uint)uVar13;
-//	} while (uVar13 < 6);
-//	EnableVSyncEvent();
-//	DAT_80072898 = 0xffff;
 //	if ((DAT_80083148 != 0) && (DAT_80083154 != 0)) {
 //		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
 //	}
-//	func_ptr_unk = FUN_80038164;
+	_vm->setSceneUpdateFunction(flameEscapeSceneUpdateFunction);
+	//TODO
+//	DAT_80083154 = 0;
+//	DAT_80083148 = 0;
+
 }
 
 void SpecialOpcodes::spcStopFlameBedroomEscapeSceneLogic() {
+	setSpecialOpCounter(0);
 	//TODO
-//	DAT_80072898 = 0;
-//	FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
+//	FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
 //	DAT_80083154 = 0;
 //	DAT_80083148 = 0;
-//	actor_update_sequenceID((uint)(ushort)dragon_ini_pointer[DAT_80063a3c + -1].field_0x1c,0);
-//	if (func_ptr_unk == FUN_80038164) {
-//		func_ptr_unk = 0;
-//	}
+	_vm->_dragonINIResource->getRecord(0x96)->actor->updateSequence(0);
+	if (_vm->getSceneUpdateFunction() == flameEscapeSceneUpdateFunction) {
+		_vm->setSceneUpdateFunction(NULL);
+	}
 }
 
 void SpecialOpcodes::spcCastleMoatFull() {
@@ -1459,6 +1471,268 @@ void ladyOfTheLakeCapturedUpdateFunction() {
 	}
 }
 
+void menInMinesSceneUpdateFunction() {
+	static const uint32_t sceneUpdateFuncDialogTbl[] = {
+			0x4590A, 0x45994, 0x459F4, 0x45A60
+	};
+	DragonsEngine *vm = getEngine();
+	uint16_t sequenceId;
+	Actor *actor = vm->_dragonINIResource->getRecord(0x293)->actor;
+
+	if (!vm->isFlagSet(ENGINE_FLAG_8000)) {
+		uint16 specialOpCounter = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
+		if (specialOpCounter != 0) {
+			if (actor->_sequenceID != 0) {
+				actor->updateSequence(0);
+			}
+			vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter - 1);
+			return;
+		}
+		vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(vm->getRand(5) * 0x3c + 0x708);
+		vm->_talk->playDialogAudioDontWait(sceneUpdateFuncDialogTbl[vm->getRand(4)]);
+		sequenceId = 2;
+	}
+	else {
+		if (vm->data_800633fc == 0) {
+			return;
+		}
+		sequenceId = 0;
+	}
+	actor->updateSequence(sequenceId);
+}
+
+void monksAtBarSceneUpdateFunction() {
+	static uint8 monksAtBarCurrentState = 0;
+	static const uint32_t sceneUpdateFuncDialogTbl[] = {
+			0x37800, 0x37854, 0x378CA,
+			0x39152, 0x3919A, 0x3922C
+	};
+	static const uint32_t barKeeperTextIdTbl[] = {
+			0x38C68, 0x38CE2, 0x38D4E, 0x38CE2,
+			0x38DC2, 0x38E0C, 0x38C68, 0x38E5C,
+			0x38ED0, 0x38CE2
+	};
+	static const uint32_t DAT_800832f0[] = {0x38F2A, 0x39000, 0x39084, 0x390E8};
+
+	DragonsEngine *vm = getEngine();
+	Actor *barKeeper = vm->_dragonINIResource->getRecord(0x1e7)->actor;
+	Actor *monk1 = vm->_dragonINIResource->getRecord(0x1ec)->actor;
+	Actor *monk2 = vm->_dragonINIResource->getRecord(0x1ed)->actor;
+	DragonINI *ini = vm->_dragonINIResource->getRecord(0x1e6);
+	bool bVar1;
+	short sVar2;
+	uint32_t textIndex;
+	uint16_t sequenceId;
+	int16 specialOpCounter = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
+	if (specialOpCounter == -1) {
+		monksAtBarCurrentState = vm->getRand(2) * 2;
+		specialOpCounter = 600;
+	}
+	if (vm->isFlagSet(ENGINE_FLAG_8000)) {
+		if (vm->data_800633fc == 0) {
+			return;
+		}
+		monk1->updateSequence(0);
+		monk2->updateSequence(8);
+		return;
+	}
+	bVar1 = ini->sceneId != 0;
+	if (specialOpCounter != 0) {
+		specialOpCounter = specialOpCounter + -1;
+	}
+	if (specialOpCounter == 0) {
+
+
+		switch (monksAtBarCurrentState) {
+			case 0:
+				if (0x31 < vm->getRand(100)) {
+					sVar2 = vm->getRand(3);
+					specialOpCounter = (sVar2 + 3) * 0x3c;
+					monksAtBarCurrentState = 2;
+					break;
+				}
+				if (bVar1) {
+					barKeeper->updateSequence(0xc);
+					textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3) + 3];
+				} else {
+					barKeeper->updateSequence(2);
+					textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3)];
+				}
+				vm->_talk->playDialogAudioDontWait(textIndex);
+				monksAtBarCurrentState = 1;
+				specialOpCounter = 0;
+				break;
+			case 1:
+				if (bVar1) {
+					sequenceId = 8;
+				} else {
+					sequenceId = 0;
+				}
+				barKeeper->updateSequence(sequenceId);
+				specialOpCounter = 0x168;
+				monksAtBarCurrentState = 2;
+				break;
+			case 2: {
+				uint16 randTextId = vm->getRand(10);
+				if ((randTextId & 1) == 0) {
+					monk1->updateSequence(2);
+				} else {
+					monk2->updateSequence(10);
+				}
+				vm->_talk->playDialogAudioDontWait(barKeeperTextIdTbl[randTextId]);
+				monksAtBarCurrentState = 3;
+				specialOpCounter = 0;
+				break;
+			}
+			case 3:
+				monk1->updateSequence(0);
+				monk2->updateSequence(8);
+				specialOpCounter = 0x3c;
+				monksAtBarCurrentState = 4;
+				break;
+			case 4:
+				if (bVar1) {
+					barKeeper->updateSequence(0xc);
+					textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3) + 3];
+				} else {
+					barKeeper->updateSequence(2);
+					textIndex = DAT_800832f0[vm->getRand(4)];
+				}
+				vm->_talk->playDialogAudioDontWait(textIndex);
+				monksAtBarCurrentState = 5;
+				specialOpCounter = 0;
+				break;
+			case 5:
+				if (bVar1) {
+					sequenceId = 8;
+				} else {
+					sequenceId = 0;
+				}
+				barKeeper->updateSequence(sequenceId);
+				specialOpCounter = 0x78;
+				if (!bVar1) {
+					monksAtBarCurrentState = 0x37;
+					break;
+				}
+				monksAtBarCurrentState = 6;
+				break;
+			case 6:
+				if (bVar1) {
+					barKeeper->updateSequence(0xb);
+					ini->actor->updateSequence(7);
+					monksAtBarCurrentState = 10;
+				} else {
+					barKeeper->updateSequence(0xd);
+					monk1->updateSequence(0x14);
+					monksAtBarCurrentState = 0x41;
+				}
+				specialOpCounter = 0;
+				break;
+			case 7:
+				if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
+					break;
+				}
+				barKeeper->updateSequence(0xe);
+				monk2->updateSequence(0x15);
+				monksAtBarCurrentState = 8;
+				specialOpCounter = 0;
+				break;
+			case 8:
+				if (barKeeper->isFlagSet(ACTOR_FLAG_4)) {
+					monk2->updateSequence(8);
+					barKeeper->updateSequence(0);
+					monksAtBarCurrentState = 9;
+					specialOpCounter = 300;
+				}
+				break;
+			case 9:
+				sequenceId = 0x10;
+				if (0x31 < vm->getRand(100)) {
+					sequenceId = 0x16;
+				}
+				monk1->updateSequence(sequenceId);
+				sequenceId = 0x11;
+				if (0x31 < vm->getRand(100)) {
+					sequenceId = 0x17;
+				}
+				monk2->updateSequence(sequenceId);
+				monksAtBarCurrentState = 0;
+				sVar2 = vm->getRand(10);
+				specialOpCounter = (sVar2 + 10) * 0x3c;
+				break;
+			case 10:
+				if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
+					break;
+				}
+				ini->actor->updateSequence(0);
+				sequenceId = 8;
+				monk2 = barKeeper;
+				monk2->updateSequence(sequenceId);
+				monksAtBarCurrentState = 0;
+				sVar2 = vm->getRand(10);
+				specialOpCounter = (sVar2 + 10) * 0x3c;
+				break;
+			case 0x37:
+				barKeeper->updateSequence(0x11);
+				specialOpCounter = 0x14;
+				monksAtBarCurrentState = 6;
+				break;
+			case 0x41:
+				if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
+					break;
+				}
+				barKeeper->updateSequence(0xf);
+				monk1->updateSequence(0);
+				monksAtBarCurrentState = 7;
+				specialOpCounter = 0;
+				break;
+		}
+	}
+	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
+	vm->_dragonINIResource->getRecord(0)->field_12 = 0;
+}
+
+void flameEscapeSceneUpdateFunction() {
+	static const uint32 dialogTbl[] = {
+			0x10458, 0x104A0, 0x10500, 0x10500, 0x10550, 0x10578 //TODO support multiple languages
+	};
+	static bool DAT_800634c0 = false;
+	DragonsEngine *vm = getEngine();
+	Actor *flame = vm->_dragonINIResource->getRecord(0x96)->actor;
+
+	if (!vm->isFlagSet(ENGINE_FLAG_8000)) {
+		int16 specialOpCounter = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
+		if (specialOpCounter == -1) {
+			DAT_800634c0 = false;
+			specialOpCounter = 300;
+		}
+		if (specialOpCounter != 0) {
+			specialOpCounter = specialOpCounter + -1;
+		}
+		if (specialOpCounter == 0) {
+			if (DAT_800634c0 == 0) {
+				flame->updateSequence(0x12);
+				vm->_talk->playDialogAudioDontWait(dialogTbl[vm->getRand(6)]);
+				specialOpCounter = 0;
+				DAT_800634c0 = 1;
+			}
+			else {
+				if (DAT_800634c0 == 1) {
+					flame->updateSequence(0x10);
+					specialOpCounter = (vm->getRand(0x14) + 10) * 0x3c;
+					DAT_800634c0 = 0;
+				}
+			}
+		}
+		vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
+	}
+	else {
+		if ((vm->data_800633fc != 0) && flame->_sequenceID != 0x10) {
+			flame->updateSequence(0x10);
+		}
+	}
+}
+
 void caveOfDilemmaUpdateFunction() {
 	static int32 counter = 0;
 	static int16 direction = 1;
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 2052022caa..4fbaf9b16e 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -212,6 +212,9 @@ private:
 
 // update functions
 
+void menInMinesSceneUpdateFunction();
+void monksAtBarSceneUpdateFunction();
+void flameEscapeSceneUpdateFunction();
 void pizzaUpdateFunction();
 void tableBasedSceneUpdateFunction();
 void castleBuildingBlackDragon2UpdateFunction();


Commit: f94d3e7671bb715423705a619de0758e42cec919
    https://github.com/scummvm/scummvm/commit/f94d3e7671bb715423705a619de0758e42cec919
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed men in mine stop scene updater script function

Changed paths:
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index e59f32cae4..de9ebfa180 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -555,7 +555,7 @@ void SpecialOpcodes::spcMenInMinesSceneLogic() {
 }
 
 void SpecialOpcodes::spcStopMenInMinesSceneLogic() {
-	if (_vm->getSceneUpdateFunction() == monksAtBarSceneUpdateFunction) {
+	if (_vm->getSceneUpdateFunction() == menInMinesSceneUpdateFunction) {
 		_vm->setSceneUpdateFunction(NULL);
 		if (0x3c < _specialOpCounter) {
 			_specialOpCounter = 0x3c;
@@ -631,6 +631,8 @@ void SpecialOpcodes::spcCastleMoatUpdateActorSceneScalePoints() {
 
 void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
 	// TODO spcCastleGateMoatDrainedSceneLogic
+	setSpecialOpCounter(-1);
+
 }
 void SpecialOpcodes::spcUnk34() {
 	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;


Commit: 56e0a2fa0a934bdeba6c7c36c41c909ed22760b1
    https://github.com/scummvm/scummvm/commit/56e0a2fa0a934bdeba6c7c36c41c909ed22760b1
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Working on castle fog update logic

Changed paths:
    engines/dragons/minigame3.cpp
    engines/dragons/screen.cpp
    engines/dragons/screen.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index f68ef67af3..26bbb45103 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -791,7 +791,8 @@ void Minigame3::FUN_80017f70_paletteRelated(uint16 param_1) {
 }
 
 void Minigame3::FUN_80017ef0() {
-	//TODO DAT_80069680 = DAT_80069680 | 0x50000000;
+	//TODO BgLayerGsSprite[2].attribute = BgLayerGsSprite[2].attribute | 0x50000000;
+	// this sets the FG layer to additive colour blending (100% x Back + 100% x Sprite)
 	FUN_80017f70_paletteRelated(0);
 }
 
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 13e90941db..47f8d6ff57 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -289,10 +289,12 @@ void Screen::updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, ui
 	assert(endOffset < 256);
 
 	// TODO
-	// this is needed for palette 0 for some reason.
-//	DAT_80069638 = DAT_80069638 | 0x50000000;
-//	DAT_8006965c = DAT_8006965c | 0x50000000;
-//	DAT_80069680 = DAT_80069680 | 0x50000000;
+	if (paletteNum == 0) {
+		// set all layers to pixel addition blending (100% back + 100% sprite)
+//		BgLayerGsSprite[0].attribute = BgLayerGsSprite[0].attribute | 0x50000000;
+//		BgLayerGsSprite[1].attribute = BgLayerGsSprite[1].attribute | 0x50000000;
+//		BgLayerGsSprite[2].attribute = BgLayerGsSprite[2].attribute | 0x50000000;
+	}
 
 	for (int i = startOffset; i <= endOffset; i++) {
 		if (isTransparent) {
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 9eacdc5273..1b3cba522b 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -29,6 +29,15 @@
 namespace Dragons {
 #define DRAGONS_NUM_PALETTES 5
 #define DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE 256
+
+enum AlphaBlendMode {
+	NONE,
+	NORMAL,       // 50% x Back + 50% x Sprite
+	ADDITIVE,     // 100% x Back + 100% x Sprite
+	ADDITIVE_50,  // 100% x Back + 50% x Sprite
+	SUBTRACTIVE   // 100% x Back - 100% x Sprite
+};
+
 class Screen {
 private:
 	Graphics::PixelFormat _pixelFormat;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index de9ebfa180..ab529e2b88 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -58,6 +58,8 @@ const int16 shakeTbl[16] = {
 
 SpecialOpcodes::SpecialOpcodes(DragonsEngine *vm)
 	: _vm(vm), _specialOpCounter(0) {
+	DAT_80083148 = 0;
+	uint16_t_80083154 = 0;
 	initOpcodes();
 }
 
@@ -324,21 +326,19 @@ void SpecialOpcodes::spcFadeScreen() {
 }
 
 void SpecialOpcodes::spcLadyOfTheLakeCapturedSceneLogic() {
-	//TODO
-	//DAT_80083148 = 0;
-	//DAT_80083154 = 0;
+	DAT_80083148 = 0;
+	uint16_t_80083154 = 0;
 	_vm->setSceneUpdateFunction(ladyOfTheLakeCapturedUpdateFunction);
 }
 
 void SpecialOpcodes::spcStopLadyOfTheLakeCapturedSceneLogic() {
 	_vm->setSceneUpdateFunction(NULL);
-// TODO
 	_vm->_sound->PauseCDMusic();
-//	if ((DAT_80083148 != 0) || (DAT_80083154 != 0)) {
-//		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
-//	}
-//	DAT_80083148 = 0;
-//	DAT_80083154 = 0;
+	if ((DAT_80083148 != 0) || (uint16_t_80083154 != 0)) {
+		//TODO FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+	}
+	DAT_80083148 = 0;
+	uint16_t_80083154 = 0;
 }
 
 void SpecialOpcodes::spc11ShakeScreen() {
@@ -548,9 +548,8 @@ void SpecialOpcodes::spcFlickerSetPriority2() {
 
 void SpecialOpcodes::spcMenInMinesSceneLogic() {
 	_vm->setSceneUpdateFunction(menInMinesSceneUpdateFunction);
-	//TODO
-//	uint16_t_80083154 = 0;
-//	DAT_80083148 = 0;
+	uint16_t_80083154 = 0;
+	DAT_80083148 = 0;
 	setSpecialOpCounter(0);
 }
 
@@ -571,45 +570,38 @@ void SpecialOpcodes::spcStopMenInMinesSceneLogic() {
 void SpecialOpcodes::spcMonksAtBarSceneLogic() {
 	setSpecialOpCounter(-1);
 	_vm->setSceneUpdateFunction(monksAtBarSceneUpdateFunction);
-	//TODO
-//	uint16_t_80083154 = 0;
-//	DAT_80083148 = 0;
+	uint16_t_80083154 = 0;
+	DAT_80083148 = 0;
 }
 
 void SpecialOpcodes::spcStopMonksAtBarSceneLogic() {
 	if (_vm->getSceneUpdateFunction() == monksAtBarSceneUpdateFunction) {
 		_vm->setSceneUpdateFunction(NULL);
-		//TODO
-//		if ((DAT_80083148 != 0) && (uint16_t_80083154 != 0)) {
-//			FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,
-//						 (uint)DAT_80083158);
-//		}
+		if ((DAT_80083148 != 0) && (uint16_t_80083154 != 0)) {
+			//TODO FUN_8001ac5c((uint)DAT_80083148, (uint)DAT_80083150, (uint)uint16_t_80083154, (uint)DAT_80083158);
+		}
 		setSpecialOpCounter(0);
-//		uint16_t_80083154 = 0;
-//		DAT_80083148 = 0;
+		uint16_t_80083154 = 0;
+		DAT_80083148 = 0;
 	}
 
 }
 
 void SpecialOpcodes::spcFlameBedroomEscapeSceneLogic() {
 	setSpecialOpCounter(-1);
-	//TODO
-//	if ((DAT_80083148 != 0) && (DAT_80083154 != 0)) {
-//		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
-//	}
+	if ((DAT_80083148 != 0) && (uint16_t_80083154 != 0)) {
+		//TODO FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+	}
 	_vm->setSceneUpdateFunction(flameEscapeSceneUpdateFunction);
-	//TODO
-//	DAT_80083154 = 0;
-//	DAT_80083148 = 0;
-
+	uint16_t_80083154 = 0;
+	DAT_80083148 = 0;
 }
 
 void SpecialOpcodes::spcStopFlameBedroomEscapeSceneLogic() {
 	setSpecialOpCounter(0);
-	//TODO
-//	FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
-//	DAT_80083154 = 0;
-//	DAT_80083148 = 0;
+//	TODO FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+	uint16_t_80083154 = 0;
+	DAT_80083148 = 0;
 	_vm->_dragonINIResource->getRecord(0x96)->actor->updateSequence(0);
 	if (_vm->getSceneUpdateFunction() == flameEscapeSceneUpdateFunction) {
 		_vm->setSceneUpdateFunction(NULL);
@@ -997,7 +989,11 @@ void SpecialOpcodes::spcInsideBlackDragonUpdatePalette() {
 }
 
 void SpecialOpcodes::spcCastleGateSceneLogic() {
-//TODO spcCastleGateSceneLogic
+	_vm->_screen->updatePaletteTransparency(0, 0xc0,0xff, true);
+	//TODO FUN_80017d68(3,0);
+	setSpecialOpCounter(-1);
+	_vm->clearFlags(ENGINE_FLAG_1);
+	_vm->setSceneUpdateFunction(castleFogUpdateFunction);
 }
 
 // 0x80038c1c
@@ -1286,10 +1282,9 @@ void SpecialOpcodes::pizzaMakerStopWorking() {
 }
 
 void SpecialOpcodes::clearSceneUpdateFunction() {
-//TODO
-//	if (DAT_80083148 != DAT_80083154) {
-//		FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)DAT_80083154,(uint)DAT_80083158);
-//	}
+	if (DAT_80083148 != uint16_t_80083154) {
+		//TODO FUN_8001ac5c((uint)DAT_80083148, (uint)DAT_80083150, (uint)uint16_t_80083154, (uint)DAT_80083158);
+	}
 	if (sceneUpdater.sequenceID != -1) {
 		_vm->getINI(sceneUpdater.iniID)->actor->updateSequence(sceneUpdater.sequenceID);
 	}
@@ -1299,9 +1294,9 @@ void SpecialOpcodes::clearSceneUpdateFunction() {
 void SpecialOpcodes::setupTableBasedSceneUpdateFunction(uint16 initialCounter, uint16 numSequences,
 														uint16 sequenceDuration) {
 	sceneUpdater.sequenceID = -1;
+	uint16_t_80083154 = 0;
+	DAT_80083148 = 0;
 //TODO
-//	DAT_80083154 = 0;
-//	DAT_80083148 = 0;
 //	DAT_80072858 = 0;
 	sceneUpdater.curSequenceIndex = 0;
 	sceneUpdater.numTotalSequences = numSequences;
@@ -1473,6 +1468,28 @@ void ladyOfTheLakeCapturedUpdateFunction() {
 	}
 }
 
+void castleFogUpdateFunction() {
+	static int16 castleFogXOffset = 0;
+	DragonsEngine *vm = getEngine();
+	int16 specialOpCounter = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
+	if (specialOpCounter == -1) {
+		castleFogXOffset = 0;
+		specialOpCounter = 6;
+	}
+	if (specialOpCounter == 0) {
+		castleFogXOffset--;
+		if (castleFogXOffset < 0) {
+			castleFogXOffset = 0x13f;
+		}
+		vm->_scene->setLayerOffset(2, Common::Point(castleFogXOffset, 0));
+		specialOpCounter = 6;
+	}
+	else {
+		specialOpCounter--;
+	}
+	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
+}
+
 void menInMinesSceneUpdateFunction() {
 	static const uint32_t sceneUpdateFuncDialogTbl[] = {
 			0x4590A, 0x45994, 0x459F4, 0x45A60
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 4fbaf9b16e..24cd87939c 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -61,6 +61,8 @@ protected:
 	SpecialOpcode *_opcodes[DRAGONS_NUM_SPECIAL_OPCODES];
 	Common::String _opcodeNames[DRAGONS_NUM_SPECIAL_OPCODES];
 	int16 _specialOpCounter;
+	uint8 DAT_80083148;
+	uint16 uint16_t_80083154;
 
 public:
 	int16 getSpecialOpCounter();
@@ -212,6 +214,7 @@ private:
 
 // update functions
 
+void castleFogUpdateFunction();
 void menInMinesSceneUpdateFunction();
 void monksAtBarSceneUpdateFunction();
 void flameEscapeSceneUpdateFunction();


Commit: 5cc1ff8dad924b7650b797ea8f66eea662989819
    https://github.com/scummvm/scummvm/commit/5cc1ff8dad924b7650b797ea8f66eea662989819
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add additive pixel blending for scene layers

Changed paths:
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/font.cpp
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/screen.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index d4ec0d6e1c..e6d0ed82fd 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -92,6 +92,9 @@ Background::Background() : _priorityLayer(0), _points2(0), _data(0) {
 	layerOffset[0] = Common::Point(0,0);
 	layerOffset[1] = Common::Point(0,0);
 	layerOffset[2] = Common::Point(0,0);
+	layerAlphaMode[0] = NORMAL;
+	layerAlphaMode[1] = NORMAL;
+	layerAlphaMode[2] = NORMAL;
 }
 
 Background::~Background() {
@@ -287,6 +290,16 @@ Common::Point Background::getLayerOffset(uint8 layerNumber) {
 	return layerOffset[layerNumber];
 }
 
+Dragons::AlphaBlendMode Background::getLayerAlphaMode(uint8 layerNumber) {
+	assert(layerNumber < 4);
+	return layerAlphaMode[layerNumber];
+}
+
+void Background::setLayerAlphaMode(uint8 layerNumber, Dragons::AlphaBlendMode mode) {
+	assert(layerNumber < 4);
+	layerAlphaMode[layerNumber] = mode;
+}
+
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
 	bigFileArchive), _dragonRMS(dragonRMS) {}
 
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index d07e860997..f0286c072d 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -26,6 +26,7 @@
 #include "common/system.h"
 #include "bigfile.h"
 #include "dragonrms.h"
+#include "screen.h"
 
 namespace Dragons {
 class PriorityLayer;
@@ -84,6 +85,8 @@ private:
 	Common::Point *_points2;
 	uint8 layerPriority[3];
 	Common::Point layerOffset[3];
+	AlphaBlendMode layerAlphaMode[3];
+
 public:
 	Background();
 	~Background();
@@ -114,6 +117,10 @@ public:
 	void setLayerOffset(uint8 layerNumber, Common::Point offset);
 	Common::Point getLayerOffset(uint8 layerNumber);
 	ScaleLayer *getScaleLayer() { return &_scaleLayer; }
+
+	Dragons::AlphaBlendMode getLayerAlphaMode(uint8 layerNumber);
+	void setLayerAlphaMode(uint8 layerNumber, Dragons::AlphaBlendMode mode);
+
 private:
 	Common::Point *loadPoints(Common::SeekableReadStream &stream);
 	Graphics::Surface *initGfxLayer(TileMap &tileMap);
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index c223b276a7..1f452ae03a 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -123,7 +123,7 @@ void FontManager::draw() {
 	Common::List<ScreenTextEntry*>::iterator it = _screenTexts.begin();
 	while (it != _screenTexts.end()) {
 		ScreenTextEntry *entry = *it;
-		_screen->copyRectToSurface8bpp(*entry->surface, _screen->getPalette(2), entry->position.x, entry->position.y, Common::Rect(entry->surface->w, entry->surface->h), false, 128);
+		_screen->copyRectToSurface8bpp(*entry->surface, _screen->getPalette(2), entry->position.x, entry->position.y, Common::Rect(entry->surface->w, entry->surface->h), false, NORMAL);
 		it++;
 	}
 }
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 9c429fc8f6..1785a9318f 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -380,7 +380,7 @@ void Scene::draw() {
 					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d Scale: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
 						  s->w, s->h, actor->priorityLayer, actor->scale);
-						_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? 255 : 128, actor->scale);
+						_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? NONE : NORMAL, actor->scale);
 					if (_vm->isDebugMode()) {
 						_screen->drawRect(0x7fff, Common::Rect(x, y, x + s->w, y + s->h), actor->_actorID);
 						drawActorNumber(x + s->w, y + 8, actor->_actorID);
@@ -514,11 +514,15 @@ void Scene::drawBgLayer(uint8 layerNumber, Common::Rect rect, Graphics::Surface
 		rect.bottom += offset.y;
 	}
 //	clippedRect.bottom += offset.y < 0 ? -offset.y : 0;
-	_screen->copyRectToSurface8bpp(*surface, _screen->getPalette(0), 0, 0, rect, false, 128);
+	_screen->copyRectToSurface8bpp(*surface, _screen->getPalette(0), 0, 0, rect, false, _stage->getLayerAlphaMode(layerNumber));
 }
 
 ScaleLayer *Scene::getScaleLayer() {
 	return _stage->getScaleLayer();
 }
 
+void Scene::setLayerAlphaMode(uint8 layerNumber, AlphaBlendMode mode) {
+	_stage->setLayerAlphaMode(layerNumber, mode);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index c36c1ee446..4d6db7c73a 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -24,6 +24,7 @@
 
 #include "common/rect.h"
 #include "common/system.h"
+#include "screen.h"
 
 namespace Dragons {
 
@@ -85,6 +86,7 @@ public:
 	void setLayerOffset(uint8 layerNumber, Common::Point offset);
 	Common::Point getLayerOffset(uint8 layerNumber);
 	ScaleLayer *getScaleLayer();
+	void setLayerAlphaMode(uint8 layerNumber, AlphaBlendMode mode);
 private:
 	void resetActorFrameFlags();
 	void drawActorNumber(int16 x, int16 y, uint16 actorId);
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 47f8d6ff57..b81850cd5c 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -61,10 +61,10 @@ Screen::~Screen() {
 }
 
 void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY) {
-	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, srcSurface.w, 0, destX, destY, srcSurface.w, srcSurface.h, false, 255);
+	copyRectToSurface(srcSurface.getBasePtr(0, 0), srcSurface.pitch, srcSurface.w, 0, destX, destY, srcSurface.w, srcSurface.h, false, NONE);
 }
 
-void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect, bool flipX, uint8 alpha) {
+void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect, bool flipX, AlphaBlendMode alpha) {
 	Common::Rect clipRect = clipRectToScreen( destX,  destY, srcRect);
 	if (clipRect.width() == 0 || clipRect.height() == 0) {
 		return;
@@ -80,7 +80,7 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
 	copyRectToSurface(srcSurface.getBasePtr(clipRect.left, clipRect.top), srcSurface.pitch, srcSurface.w, clipRect.left, destX, destY, clipRect.width(), clipRect.height(), flipX, alpha);
 }
 
-void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, const Common::Rect srcRect, bool flipX, uint8 alpha, uint16 scale) {
+void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, const Common::Rect srcRect, bool flipX, AlphaBlendMode alpha, uint16 scale) {
 	if (scale != DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) {
 		drawScaledSprite(_backSurface, (byte *)srcSurface.getBasePtr(0, 0),
 				srcRect.width(), srcRect.height(),
@@ -118,7 +118,29 @@ uint16 alphaBlendRGB555( uint32 fg, uint32 bg, uint8 alpha ){
 	return (uint16_t)((result >> 16) | result);
 }
 
-void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha) {
+uint16 alphaBlendAdditiveRGB555( uint32 fg, uint32 bg){
+	bg = (bg | (bg << 16)) & 0b00000011111000000111110000011111;
+	fg = (fg | (fg << 16)) & 0b00000011111000000111110000011111;
+
+	uint32_t result = bg + fg;
+	if (result & (0b111111 << 26)) {
+		result &= 0x1fffff;
+		result |= 0x3E00000;
+	}
+
+	if (result & 0x1F8000) {
+		result &= 0b00000011111000000111111111111111;
+		result |= 0x7C00;
+	}
+
+	if (result & 0x3E0) {
+		result &= 0b00000011111000000111110000011111;
+		result |= 0x1f;
+	}
+	return (uint16_t)((result >> 16) | result);
+}
+
+void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, AlphaBlendMode alpha) {
 	assert(buffer);
 
 	assert(destX >= 0 && destX < _backSurface->w);
@@ -133,12 +155,12 @@ void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, i
 		for (int j = 0; j < width; j++) {
 			int32 srcIdx = flipX ? srcWidth - (srcXOffset * 2) - j - 1 : j;
 			if (src[srcIdx * 2] != 0 || src[srcIdx * 2 + 1] != 0) {
-				if ((src[srcIdx * 2 + 1] & 0x80) == 0 || alpha == 255) {
+				if ((src[srcIdx * 2 + 1] & 0x80) == 0 || alpha == NONE) {
 					// only copy opaque pixels
 					dst[j * 2] = src[srcIdx * 2];
 					dst[j * 2 + 1] = src[srcIdx * 2 + 1];
 				} else {
-					WRITE_LE_UINT16(&dst[j * 2], alphaBlendRGB555(READ_LE_INT16(&src[srcIdx * 2]), READ_LE_INT16(&dst[j * 2]), alpha));
+					WRITE_LE_UINT16(&dst[j * 2], alphaBlendRGB555(READ_LE_INT16(&src[srcIdx * 2]), READ_LE_INT16(&dst[j * 2]), 128));
 					// semi-transparent pixels.
 				}
 			}
@@ -148,7 +170,7 @@ void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, i
 	}
 }
 
-void Screen::copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha) {
+void Screen::copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, AlphaBlendMode alpha) {
 	assert(buffer);
 
 	assert(destX >= 0 && destX < _backSurface->w);
@@ -164,11 +186,11 @@ void Screen::copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPit
 			int32 srcIdx = flipX ? srcWidth - (srcXOffset * 2) - j - 1 : j;
 			uint16 c = READ_LE_UINT16(&palette[src[srcIdx] * 2]);
 			if (c != 0) {
-				if (!(c & 0x8000) || alpha == 255) {
+				if (!(c & 0x8000) || alpha == NONE) {
 					// only copy opaque pixels
 					WRITE_LE_UINT16(&dst[j * 2], c & ~0x8000);
 				} else {
-					WRITE_LE_UINT16(&dst[j * 2], alphaBlendRGB555(c, READ_LE_INT16(&dst[j * 2]), alpha));
+					WRITE_LE_UINT16(&dst[j * 2], alpha == NORMAL ? alphaBlendRGB555(c, READ_LE_INT16(&dst[j * 2]), 128) : alphaBlendAdditiveRGB555(c, READ_LE_INT16(&dst[j * 2])));
 					// semi-transparent pixels.
 				}
 			}
@@ -288,12 +310,12 @@ void Screen::updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, ui
 	assert(startOffset < 256);
 	assert(endOffset < 256);
 
-	// TODO
 	if (paletteNum == 0) {
 		// set all layers to pixel addition blending (100% back + 100% sprite)
-//		BgLayerGsSprite[0].attribute = BgLayerGsSprite[0].attribute | 0x50000000;
-//		BgLayerGsSprite[1].attribute = BgLayerGsSprite[1].attribute | 0x50000000;
-//		BgLayerGsSprite[2].attribute = BgLayerGsSprite[2].attribute | 0x50000000;
+		DragonsEngine *vm = getEngine();
+		vm->_scene->setLayerAlphaMode(0, ADDITIVE);
+		vm->_scene->setLayerAlphaMode(1, ADDITIVE);
+		vm->_scene->setLayerAlphaMode(2, ADDITIVE);
 	}
 
 	for (int i = startOffset; i <= endOffset; i++) {
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 1b3cba522b..b91eeb7156 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -51,8 +51,8 @@ public:
 
 	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
-	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255);
-	void copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, Common::Rect srcRect, bool flipX = false, uint8 alpha = 255, uint16 scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE);
+	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false, AlphaBlendMode alpha = NONE);
+	void copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *palette, int destX, int destY, Common::Rect srcRect, bool flipX = false, AlphaBlendMode alpha = NONE, uint16 scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE);
 	void updateScreen();
 	void loadPalette(uint16 paletteNum, byte *palette);
 	byte *getPalette(uint16 paletteNum);
@@ -68,8 +68,8 @@ public:
 	void copyRectToSurface8bppWrappedY(const Graphics::Surface &srcSurface, byte *palette, int yOffset);
 
 private:
-	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
-	void copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, uint8 alpha);
+	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, AlphaBlendMode alpha);
+	void copyRectToSurface8bpp(const void *buffer, byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, AlphaBlendMode alpha);
 	void drawScaledSprite(Graphics::Surface *destSurface, byte *source, int sourceWidth, int sourceHeight, int destX, int destY, int destWidth, int destHeight, byte *palette, bool flipX, uint8 alpha);
 };
 


Commit: 894e0d99df51f4658c656fe781c00d4f5d3c590e
    https://github.com/scummvm/scummvm/commit/894e0d99df51f4658c656fe781c00d4f5d3c590e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added more missing specialOpcode logic

Changed paths:
    engines/dragons/screen.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h


diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index b81850cd5c..1bc5bfc371 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -100,7 +100,7 @@ void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *pa
 	if (destY < 0) {
 		destY = 0;
 	}
-
+	//TODO should we have different methods for alpha modes?
 	copyRectToSurface8bpp(srcSurface.getBasePtr(clipRect.left, clipRect.top), palette, srcSurface.pitch, srcSurface.w, clipRect.left, destX, destY, clipRect.width(), clipRect.height(), flipX, alpha);
 }
 
@@ -123,6 +123,7 @@ uint16 alphaBlendAdditiveRGB555( uint32 fg, uint32 bg){
 	fg = (fg | (fg << 16)) & 0b00000011111000000111110000011111;
 
 	uint32_t result = bg + fg;
+	//clip r g b values to 565.
 	if (result & (0b111111 << 26)) {
 		result &= 0x1fffff;
 		result |= 0x3E00000;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index ab529e2b88..beb23d1978 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -622,9 +622,13 @@ void SpecialOpcodes::spcCastleMoatUpdateActorSceneScalePoints() {
 }
 
 void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
-	// TODO spcCastleGateMoatDrainedSceneLogic
 	setSpecialOpCounter(-1);
-
+	if ((DAT_80083148 != 0) && (uint16_t_80083154 != 0)) {
+		//TODO FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+	}
+	_vm->setSceneUpdateFunction(moatDrainedSceneUpdateFunction);
+	uint16_t_80083154 = 0;
+	DAT_80083148 = 0;
 }
 void SpecialOpcodes::spcUnk34() {
 	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;
@@ -937,7 +941,9 @@ void SpecialOpcodes::spcResetInventorySequence() {
 }
 
 void SpecialOpcodes::spcUnk65ScenePaletteRelated() {
-	//TODO
+	byte *palette = _vm->_scene->getPalette();
+	memset(palette + 0xb1 * 2, 0, 32); //zero out 16 palette records from index 0xb1 to 0xc0
+	//TODO Check above logic works. triggers on dodo under attack scene.
 //	uint uVar1;
 //	ushort uVar2;
 //	RECT local_10;
@@ -990,7 +996,7 @@ void SpecialOpcodes::spcInsideBlackDragonUpdatePalette() {
 
 void SpecialOpcodes::spcCastleGateSceneLogic() {
 	_vm->_screen->updatePaletteTransparency(0, 0xc0,0xff, true);
-	//TODO FUN_80017d68(3,0);
+	//TODO FUN_80017d68(3,0); sets sprite layer attribute from layers 0 and 1. Doesn't seem to be needed.
 	setSpecialOpCounter(-1);
 	_vm->clearFlags(ENGINE_FLAG_1);
 	_vm->setSceneUpdateFunction(castleFogUpdateFunction);
@@ -1033,6 +1039,7 @@ void SpecialOpcodes::spcBlackDragonDialogForCamelhot() {
 	uint16 buffer[1024];
 	_vm->_talk->loadText(0x30DD8, buffer, 1024); //TODO might need to check dialog in other game versions
 	_vm->_talk->displayDialogAroundPoint(buffer,0x27,0xc,0xc01,0,0x30DD8);
+	//TODO this isn't quite right. The audio isn't played and it's not waiting long enough.
 }
 
 void SpecialOpcodes::spcSetCameraXToZero() {
@@ -1054,11 +1061,13 @@ void SpecialOpcodes::spcLoadFileS10a7act() {
 }
 
 void SpecialOpcodes::spcFlickerPutOnStGeorgeArmor() {
-	//TODO here.....
+	Actor *actor = _vm->_dragonINIResource->getRecord(0x21f)->actor;
+	actor->setFlag(ACTOR_FLAG_100);
+	actor->priorityLayer = 1;
 }
 
 void SpecialOpcodes::spc82CallResetDataMaybe() {
-	//TODO callMaybeResetData();
+	//TODO callMaybeResetData(); LOOKS like it clears text from the screen.
 }
 
 void SpecialOpcodes::spcStopScreenShakeUpdater() {
@@ -1782,4 +1791,38 @@ void caveOfDilemmaUpdateFunction() {
 		counter--;
 	}
 }
+
+void moatDrainedSceneUpdateFunction() {
+	static const uint32 moatDrainedTextIdTbl[] {
+			0x3C97A, 0x3C9AC, 0x3C9F8, 0x3CA48
+	};
+	static uint16 moatDrainedUpdateCounter = 0;
+	static bool moatDrainedStatus = false;
+	DragonsEngine *vm = getEngine();
+
+	if (vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter() == -1) {
+		moatDrainedUpdateCounter = 600;
+	}
+	castleFogUpdateFunction();
+	if (((vm->_dragonINIResource->getRecord(0x208)->field_14 == 2) &&
+		 !vm->isFlagSet(ENGINE_FLAG_8000))) {
+		if (moatDrainedUpdateCounter != 0) {
+			moatDrainedUpdateCounter--;
+		}
+		if (moatDrainedUpdateCounter <= 0) {
+			if (!moatDrainedStatus) {
+				vm->_talk->playDialogAudioDontWait(moatDrainedTextIdTbl[vm->getRand(4)]);
+				moatDrainedStatus = true;
+				moatDrainedUpdateCounter = 0x1e;
+			} else {
+				if (moatDrainedStatus) {
+					vm->_dragonINIResource->getRecord(0x1fa)->actor->updateSequence(7);
+					moatDrainedUpdateCounter = vm->getRand(300) + 0x4b0;
+					moatDrainedStatus = false;
+				}
+			}
+		}
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index 24cd87939c..ec025894bb 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -224,6 +224,7 @@ void castleBuildingBlackDragon2UpdateFunction();
 void shakeScreenUpdateFunction();
 void ladyOfTheLakeCapturedUpdateFunction();
 void caveOfDilemmaUpdateFunction();
+void moatDrainedSceneUpdateFunction();
 
 } // End of namespace Dragons
 


Commit: 40a13a853edacd3cb1c28c58502f4d42d13f4635
    https://github.com/scummvm/scummvm/commit/40a13a853edacd3cb1c28c58502f4d42d13f4635
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added palette cycling logic

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 9e74952ac3..5f28e001c0 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -92,6 +92,7 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
 	_pKeyDown = false;
 
 	_debugMode = false;
+	_isGamePaused = false;
 
 	reset();
 }
@@ -671,6 +672,7 @@ void DragonsEngine::updateHandler() {
 	}
 
 	// TODO 0x8001bed0
+	updatePaletteCycling();
 
 	// 0x8001c294
 	if (!(_unkFlags1 & ENGINE_UNK1_FLAG_8)) {
@@ -1294,11 +1296,11 @@ void DragonsEngine::reset() {
 	data_800633fa = 0;
 
 	for(int i = 0; i < 8; i++) {
-		opCode1A_tbl[i].paletteType = 0;
-		opCode1A_tbl[i].field2 = 0;
-		opCode1A_tbl[i].field4 = 0;
-		opCode1A_tbl[i].field6 = 0;
-		opCode1A_tbl[i].field8 = 0;
+		_paletteCyclingTbl[i].paletteType = 0;
+		_paletteCyclingTbl[i].startOffset = 0;
+		_paletteCyclingTbl[i].endOffset = 0;
+		_paletteCyclingTbl[i].updateInterval = 0;
+		_paletteCyclingTbl[i].updateCounter = 0;
 	}
 
 	setSceneUpdateFunction(NULL);
@@ -1401,6 +1403,52 @@ void DragonsEngine::loadCurrentSceneMsf() {
 	_sound->loadMsf(getCurrentSceneId());
 }
 
+void DragonsEngine::updatePaletteCycling() {
+	if (!_isGamePaused) {
+		for (int loopIndex = 0; loopIndex < 8 ; loopIndex++) {
+			if (_paletteCyclingTbl[loopIndex].updateInterval != 0) {
+				if (_paletteCyclingTbl[loopIndex].updateCounter == 0) {
+					uint16 *palette = (uint16 *)_screen->getPalette(_paletteCyclingTbl[loopIndex].paletteType);
+					int16 uVar14 = (uint)(ushort)_paletteCyclingTbl[loopIndex].startOffset;
+					int16 uVar8 = (uint)(ushort)_paletteCyclingTbl[loopIndex].endOffset;
+					if (uVar14 < uVar8) {
+						uint16 uVar11 = palette[uVar8];
+						int uVar15 = uVar8;
+						if (uVar14 < uVar8) {
+							do {
+								uVar8--;
+								palette[uVar15] = palette[uVar15 - 1];
+								uVar15 = uVar8 & 0xffff;
+							} while ((uint)(ushort)_paletteCyclingTbl[loopIndex].startOffset < (uVar8 & 0xffff));
+						}
+						palette[(ushort)_paletteCyclingTbl[loopIndex].startOffset] = uVar11;
+						_paletteCyclingTbl[loopIndex].updateCounter = _paletteCyclingTbl[loopIndex].updateInterval;
+					}
+					else {
+						if (uVar8 < uVar14) {
+							uint16 uVar11 = palette[uVar14];
+							uint16 uVar15 = uVar8;
+							if (uVar8 < uVar14) {
+								do {
+									uVar8--;
+									palette[uVar15] = palette[uVar15 + 1];
+									uVar15 = uVar8 & 0xffff;
+								} while ((uVar8 & 0xffff) < (uint)(ushort)_paletteCyclingTbl[loopIndex].startOffset);
+							}
+							palette[(ushort)_paletteCyclingTbl[loopIndex].endOffset] = uVar11;
+							_paletteCyclingTbl[loopIndex].updateCounter =
+									_paletteCyclingTbl[loopIndex].updateInterval;
+						}
+					}
+				}
+				else {
+					_paletteCyclingTbl[loopIndex].updateCounter = _paletteCyclingTbl[loopIndex].updateCounter + -1;
+				}
+			}
+		}
+	}
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 30e021b030..f3865687b8 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -96,12 +96,12 @@ enum UnkFlags {
 	ENGINE_UNK1_FLAG_80 = 0x80
 };
 
-struct opCode1AStruct {
+struct PaletteCyclingInstruction {
 	int16 paletteType;
-	int16 field2;
-	int16 field4;
-	int16 field6;
-	int16 field8;
+	int16 startOffset;
+	int16 endOffset;
+	int16 updateInterval;
+	int16 updateCounter;
 };
 
 class BigfileArchive;
@@ -143,7 +143,7 @@ public:
 	Talk *_talk;
 	SoundManager *_sound;
 
-	opCode1AStruct opCode1A_tbl[8];
+	PaletteCyclingInstruction _paletteCyclingTbl[8];
 
 	uint16 data_800633fc;
 	uint16 videoFlags; // TODO move to screen?
@@ -191,6 +191,7 @@ private:
 	bool _pKeyDown;
 
 	bool _debugMode;
+	bool _isGamePaused;
 
 	void (*_sceneUpdateFunction)();
 	void (*_vsyncUpdateFunction)();
@@ -283,6 +284,7 @@ private:
 	void gameLoop();
 	void updateHandler();
 	void updatePathfindingActors();
+	void updatePaletteCycling();
 	uint32 calulateTimeLeft();
 	void wait();
 	uint16 getIniFromImg();
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 1785a9318f..f69166dcf7 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -51,7 +51,7 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 
 	for (int i = 0; i < 8; i++) {
-		_vm->opCode1A_tbl[i].field6 = 0;
+		_vm->_paletteCyclingTbl[i].updateInterval = 0;
 	}
 
 	// TODO
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 2f04779fb8..36cb33a8e1 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -1102,11 +1102,11 @@ void ScriptOpcodes::opUnk1A(ScriptOpCall &scriptOpCall) {
 
 	assert(index < 8);
 
-	_vm->opCode1A_tbl[index].paletteType = field4;
-	_vm->opCode1A_tbl[index].field2 = field6;
-	_vm->opCode1A_tbl[index].field4 = field8;
-	_vm->opCode1A_tbl[index].field6 = fieldA;
-	_vm->opCode1A_tbl[index].field8 = 0;
+	_vm->_paletteCyclingTbl[index].paletteType = field4;
+	_vm->_paletteCyclingTbl[index].startOffset = field6;
+	_vm->_paletteCyclingTbl[index].endOffset = field8;
+	_vm->_paletteCyclingTbl[index].updateInterval = fieldA;
+	_vm->_paletteCyclingTbl[index].updateCounter = 0;
 }
 
 void ScriptOpcodes::opUnk1B(ScriptOpCall &scriptOpCall) {
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index beb23d1978..f4f0bd50ce 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -941,26 +941,8 @@ void SpecialOpcodes::spcResetInventorySequence() {
 }
 
 void SpecialOpcodes::spcUnk65ScenePaletteRelated() {
-	byte *palette = _vm->_scene->getPalette();
+	byte *palette = _vm->_screen->getPalette(0);
 	memset(palette + 0xb1 * 2, 0, 32); //zero out 16 palette records from index 0xb1 to 0xc0
-	//TODO Check above logic works. triggers on dodo under attack scene.
-//	uint uVar1;
-//	ushort uVar2;
-//	RECT local_10;
-//
-//	uVar2 = 0xb1;
-//	local_10.y = 0xf1;
-//	local_10.w = 0x100;
-//	local_10.x = 0;
-//	local_10.h = 1;
-//	uVar1 = 0xb1;
-//	do {
-//		uVar2 = uVar2 + 1;
-//		*(undefined2 *)(uVar1 * 2 + scrFileData_maybe) = 0;
-//		uVar1 = (uint)uVar2;
-//	} while (uVar2 < 0xc0);
-//	LoadImage(&local_10,&palette_data);
-//	DrawSync(0);
 }
 
 void SpecialOpcodes::spcUnk66() {


Commit: 780070f995f344e9d0aae4da004ed4ee52557920
    https://github.com/scummvm/scummvm/commit/780070f995f344e9d0aae4da004ed4ee52557920
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Updated palette cycling script opcode

Changed paths:
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 36cb33a8e1..0894273650 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -123,7 +123,7 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(0x17, opUnk17);
 	OPCODE(0x18, opUnk18);
 	OPCODE(0x19, opUnk19);
-	OPCODE(0x1A, opUnk1A);
+	OPCODE(0x1A, opUpdatePaletteCycling);
 	OPCODE(0x1B, opUnk1B);
 	OPCODE(0x1C, opSetActorFlag0x1000);
 	OPCODE(0x1D, opUnk1DClearActorFlag0x400);
@@ -1088,7 +1088,7 @@ void ScriptOpcodes::opUnk19(ScriptOpCall &scriptOpCall) {
 
 }
 
-void ScriptOpcodes::opUnk1A(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opUpdatePaletteCycling(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(index);
 	ARG_INT16(field4);
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index c3216799bb..2f2380d229 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -109,7 +109,7 @@ protected:
 	void opUnk17(ScriptOpCall &scriptOpCall);
 	void opUnk18(ScriptOpCall &scriptOpCall);
 	void opUnk19(ScriptOpCall &scriptOpCall);
-	void opUnk1A(ScriptOpCall &scriptOpCall);
+	void opUpdatePaletteCycling(ScriptOpCall &scriptOpCall);
 	void opUnk1B(ScriptOpCall &scriptOpCall);
 	void opUnk1DClearActorFlag0x400(ScriptOpCall &scriptOpCall);
 	void opUnk1ESetActorFlag0x400(ScriptOpCall &scriptOpCall);


Commit: dc312c59f33633938b6130369924b7e5159350dc
    https://github.com/scummvm/scummvm/commit/dc312c59f33633938b6130369924b7e5159350dc
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added lights to mini game 4

Changed paths:
    engines/dragons/minigame4.cpp
    engines/dragons/minigame4.h


diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 53e59d8acb..40dc30c63c 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -30,6 +30,8 @@
 
 namespace Dragons {
 
+static void videoUpdaterFunction();
+
 Minigame4::Minigame4(DragonsEngine *vm) : _vm(vm) {}
 
 void Minigame4::run() {
@@ -56,8 +58,8 @@ void Minigame4::run() {
 	_vm->clearFlags(ENGINE_FLAG_80);
 	// DisableVSyncEvent();
 	_vm->clearFlags(ENGINE_FLAG_1);
-	DAT_80090428_videoUpdateRelated = 0;
-	//TODO vsync_updater_function = videoUpdateFunction;
+	_layer2XOffset = 0;
+	_vm->setVsyncUpdateFunction(videoUpdaterFunction);
 	_vm->_screen->loadPalette(4, _vm->_scene->getPalette());
 	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
 	_vm->videoFlags |= 4;
@@ -97,7 +99,7 @@ void Minigame4::run() {
 	_vm->waitForFrames(2 * 0x3c);
 //	fade_related_calls_with_1f();
 	//DisableVSyncEvent();
-	//vsync_updater_function = (code *)0x0;
+	_vm->setVsyncUpdateFunction(NULL);
 	_vm->setFlags(ENGINE_FLAG_1);
 	_vm->videoFlags &= ~(uint16)4;
 	// EnableVSyncEvent();
@@ -317,5 +319,15 @@ uint16 Minigame4::FUN_8009009c(uint16 unk) {
 	return (uint)unk;
 }
 
+void videoUpdaterFunction() {
+	static uint16 layer2XOffset = 0;
+	static uint16 layer0XOffset = 0;
+	DragonsEngine *vm = getEngine();
+	vm->_scene->setLayerOffset(2, Common::Point(layer2XOffset, 0));
+	layer2XOffset = (layer2XOffset + 3) % 512;
+	vm->_scene->setLayerOffset(0, Common::Point(layer0XOffset, 0));
+	layer0XOffset = (layer0XOffset + 4) % 512;
+}
+
 
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame4.h b/engines/dragons/minigame4.h
index 4da35679f7..1b3449a3d0 100644
--- a/engines/dragons/minigame4.h
+++ b/engines/dragons/minigame4.h
@@ -42,7 +42,7 @@ private:
 
 
 public:
-	uint16 DAT_80090428_videoUpdateRelated;
+	uint16 _layer2XOffset;
 
 	Minigame4(DragonsEngine *vm);
 


Commit: 0036271c85a0e458189481be3513d9ad9b399de9
    https://github.com/scummvm/scummvm/commit/0036271c85a0e458189481be3513d9ad9b399de9
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More code cleanups

Changed paths:
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 0894273650..36f036ee66 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -249,7 +249,6 @@ void ScriptOpcodes::opUnk2(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(fieldE);
 
 	if (scriptOpCall._field8 == 2) {
-		//TODO do something here.
 		TalkDialogEntry *talkDialogEntry = new TalkDialogEntry();
 
 		talkDialogEntry->hasText = _vm->_talk->loadText(field2, (uint16 *)(&talkDialogEntry->dialogText[10]), 295);
@@ -438,7 +437,8 @@ void ScriptOpcodes::opUnk20(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
 
-	_vm->data_800633fc = 0;
+	_vm->_sound->PauseCDMusic();
+	_vm->data_800633fc = 1;
 
 	if (field2 >= 2) {
 		//TODO do we need this? It looks like it is pre-loading the next scene's data.
@@ -825,7 +825,6 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 
 	if (newSceneID != 0) {
 		// load scene here.
-		//TODO
 		_vm->_scene->data_80063392 = _vm->_scene->getSceneId();
 		_vm->_scene->setSceneId(newSceneID);
 		_vm->data_800633fa = field6;
@@ -853,7 +852,7 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 	uint16 dialog[2048];
 	dialog[0] = 0;
 
-	int sVar2 = -1; //TODO FUN_8001ca48(textIndex);
+	int sVar2 = -1; //TODO findTextToDtSpeechIndex(textIndex);
 
 	if (!_vm->isUnkFlagSet(1) && (!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || sVar2 == -1)) {
 		_vm->_talk->loadText(textIndex, dialog, 2048);


Commit: 952442d56a5678a762606e308ae24f26672c5f85
    https://github.com/scummvm/scummvm/commit/952442d56a5678a762606e308ae24f26672c5f85
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Code cleanup

Changed paths:
    engines/dragons/VabSound.cpp
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/actorfiles.h
    engines/dragons/actorresource.cpp
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/bag.cpp
    engines/dragons/bigfile.cpp
    engines/dragons/credits.cpp
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/cutscene.cpp
    engines/dragons/detection.cpp
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonimg.cpp
    engines/dragons/dragonini.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragonobd.cpp
    engines/dragons/dragonrms.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/dragonvar.cpp
    engines/dragons/font.cpp
    engines/dragons/inventory.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/saveload.cpp
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/screen.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/sound.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
index abce2632d0..9a77d0d789 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/VabSound.cpp
@@ -25,8 +25,8 @@
 #include <audio/audiostream.h>
 #include <audio/mixer.h>
 #include "common/memstream.h"
-#include "VabSound.h"
-#include "dragons.h"
+#include "dragons/VabSound.h"
+#include "dragons/dragons.h"
 
 namespace Dragons {
 	VabSound::VabSound(Common::SeekableReadStream *msfData, const DragonsEngine *_vm): _toneAttrs(NULL), _vbData(NULL) {
diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index fa6198ae23..505ffd02b7 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -20,11 +20,11 @@
  *
  */
 #include <common/debug.h>
-#include "dragons.h"
-#include "dragonini.h"
-#include "actorresource.h"
-#include "actor.h"
-#include "scene.h"
+#include "dragons/dragons.h"
+#include "dragons/dragonini.h"
+#include "dragons/actorresource.h"
+#include "dragons/actor.h"
+#include "dragons/scene.h"
 #include "dragons/screen.h"
 
 namespace Dragons {
@@ -66,7 +66,7 @@ Actor *ActorManager::findFreeActor(int16 resourceId) {
 	int i = 0;
 	for (ActorsIterator it = _actors.begin(); it != _actors.end() && i < 23; ++it, i++) {
 		Actor *actor = it;
-		if (!(actor->flags & Dragons::ACTOR_FLAG_40)) {
+		if (!(actor->_flags & Dragons::ACTOR_FLAG_40)) {
 			actor->resourceID = resourceId;
 			actor->_walkSpeed = 0x100000;
 			return actor;
@@ -83,7 +83,7 @@ Actor *ActorManager::getActor(uint16 actorId) {
 void ActorManager::clearActorFlags(uint16 startingActorId) {
 	assert(startingActorId < DRAGONS_ENGINE_NUM_ACTORS);
 	for(uint16 i = startingActorId; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
-		_actors[i].flags = 0;
+		_actors[i]._flags = 0;
 	}
 }
 
@@ -142,7 +142,7 @@ Actor::Actor(uint16 id) : _actorID(id) {
 	_walkDestX = 0;
 	_walkDestY = 0;
 	_walkSpeed = 0;
-	flags = 0;
+	_flags = 0;
 	frame_width = 0;
 	frame_height = 0;
 	frame_flags = 0;
@@ -161,7 +161,7 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	_walkDestY = y;
 	scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_sequenceID2 = 0;
-	flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
+	_flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
 	frame_width = 0;
 	frame_height = 0;
 	frame_flags = 4;
@@ -173,8 +173,8 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 
 void Actor::updateSequence(uint16 newSequenceID) {
 	_sequenceID = newSequenceID;
-	flags &= 0xfbf1;
-	flags |= Dragons::ACTOR_FLAG_1;
+	_flags &= 0xfbf1;
+	_flags |= Dragons::ACTOR_FLAG_1;
 }
 
 void Actor::resetSequenceIP() {
@@ -196,7 +196,7 @@ void Actor::loadFrame(uint16 frameOffset) {
 
 	debug(5, "ActorId: %d load frame header: (%d,%d)", _actorID, frame->width, frame->height);
 
-	flags |= Dragons::ACTOR_FLAG_8; //TODO check if this is the right spot. engine sets it at 0x800185b0
+	_flags |= Dragons::ACTOR_FLAG_8; //TODO check if this is the right spot. engine sets it at 0x800185b0
 
 }
 
@@ -212,54 +212,11 @@ byte *Actor::getSeqIpAtOffset(uint32 offset) {
 }
 
 void Actor::reset_maybe() {
-	flags = 0;
+	_flags = 0;
 	//TODO actor_find_by_resourceId_and_remove_resource_from_mem_maybe(resourceID);
 	freeFrame();
 }
 
-static const int32 pathfinderXYOffsetTbl[32] =
-		{
-				0x00000100,
-				0x000000fb,
-				0x000000ec,
-				0x000000d4,
-
-				0x000000b5,
-				0x0000008e,
-				0x00000061,
-				0x00000031,
-
-				-0x00000000,
-				-0x31,
-				-0x61,
-				-0x8e,
-
-				-0xb5,
-				-0xd4,
-				-0xec,
-				-0xfb,
-
-				-0xff,
-				-0xfb,
-				-0xec,
-				-0xd4,
-
-				-0xb5,
-				-0x8e,
-				-0x61,
-				-0x31,
-
-				0x00000000,
-				0x00000031,
-				0x00000061,
-				0x0000008e,
-
-				0x000000b5,
-				0x000000d4,
-				0x000000ec,
-				0x000000fb
-		};
-
 uint32 calcDistance(int32 x1, int32 y1, int32 x2, int32 y2) {
 	return ABS(x2 - x1) * ABS(x2 - x1) + ABS(y2 - y1) * ABS(y2 - y1);
 }
@@ -519,7 +476,7 @@ void Actor::stopWalk() {
 	_finalWalkDestY = -1;
 	setFlag(Dragons::ACTOR_FLAG_4);
 
-	if (flags & Dragons::ACTOR_FLAG_200) {
+	if (_flags & Dragons::ACTOR_FLAG_200) {
 		clearFlag(Dragons::ACTOR_FLAG_800);
 	}
 }
@@ -531,11 +488,11 @@ void Actor::waitUntilFlag4IsSet() {
 }
 
 void Actor::waitUntilFlag8IsSet() {
-	if (flags & Dragons::ACTOR_FLAG_8) {
+	if (_flags & Dragons::ACTOR_FLAG_8) {
 		return;
 	}
 
-	while(!(flags & Dragons::ACTOR_FLAG_8)) {
+	while(!(_flags & Dragons::ACTOR_FLAG_8)) {
 		getEngine()->waitForFrames(1);
 	}
 }
@@ -556,27 +513,27 @@ void Actor::waitUntilFlag8SetThenSet1000AndWaitFor4() {
 }
 
 void Actor::clearFlag(uint32 flag) {
-	flags &= ~flag;
+	_flags &= ~flag;
 }
 
 void Actor::setFlag(uint32 flag) {
-	flags |= flag;
+	_flags |= flag;
 }
 
 bool Actor::isFlagSet(uint32 flag) {
-	return (flags & flag) == flag;
+	return (_flags & flag) == flag;
 }
 
-uint16 Actor::canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 flags) {
-	debug(1, "canWalkLine. (%X,%X) -> (%X,%X) %d", x_pos, y_pos, target_x, target_y, flags);
+uint16 Actor::canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 walkFlags) {
+	debug(1, "canWalkLine. (%X,%X) -> (%X,%X) %d", x_pos, y_pos, target_x, target_y, walkFlags);
 
-	if (flags == 2) {
+	if (walkFlags == 2) {
 		return 1;
 	}
 	uint16 width = getEngine()->_scene->getStageWidth();
 	uint16 height = getEngine()->_scene->getStageHeight();
 
-	if (flags & 0x8000) {
+	if (walkFlags & 0x8000) {
 		if (actor_x < 0
 			|| width - 1 < actor_x
 			|| actor_y < 0
@@ -637,11 +594,11 @@ uint16 Actor::canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 ta
 		if ( priority < 0) {
 			priority = 1;
 		}
-		if (!(flags & 0x7fff) && (priority == 0 || priority >= 8)) {
+		if (!(walkFlags & 0x7fff) && (priority == 0 || priority >= 8)) {
 			return 0;
 		}
 
-		if ((flags & 0x7fff) == 1) {
+		if ((walkFlags & 0x7fff) == 1) {
 			if (priority == 0 || priority >= 0x10) {
 				return 0;
 			}
@@ -774,7 +731,7 @@ int Actor::startMoveToPoint(int destX, int destY) {
 				if(direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
 					_sequenceID2 = direction;
 				}
-				if (_sequenceID != _sequenceID2 + 8 && _sequenceID2 != -1 && !(flags & ACTOR_FLAG_800)) {
+				if (_sequenceID != _sequenceID2 + 8 && _sequenceID2 != -1 && !isFlagSet(ACTOR_FLAG_800)) {
 					updateSequence(_sequenceID2 + 8);
 				}
 				setFlag(ACTOR_FLAG_10);
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 8fb25d00be..dc16534f5c 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -99,7 +99,7 @@ public:
 	uint16 _sequenceID;
 	int16 _sequenceID2;
 	int16 priorityLayer;
-	uint16 flags;
+	uint16 _flags;
 	int16 x_pos;
 	int16 y_pos;
 	int16 _walkDestX;
@@ -150,7 +150,7 @@ public:
 	byte *getPalette();
 private:
 	void stopWalk();
-	uint16 canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 flags);
+	uint16 canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 walkFlags);
 	int16 pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType,
 									  bool *pointsInUseTbl);
 	int startMoveToPoint(int destX, int destY);
diff --git a/engines/dragons/actorfiles.h b/engines/dragons/actorfiles.h
index 0eabf70bad..11a3b3df02 100644
--- a/engines/dragons/actorfiles.h
+++ b/engines/dragons/actorfiles.h
@@ -1,5 +1,24 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
 
+ * You should have received a copy of the GNU General Public 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 SCUMMVM_ACTORFILES_H
 #define SCUMMVM_ACTORFILES_H
 
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index e1a54a7769..b778230c57 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -22,9 +22,9 @@
 #include "common/debug.h"
 #include "common/memstream.h"
 #include "graphics/surface.h"
-#include "actorfiles.h"
-#include "bigfile.h"
-#include "actorresource.h"
+#include "dragons/actorfiles.h"
+#include "dragons/bigfile.h"
+#include "dragons/actorresource.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index e6d0ed82fd..57eb1ab481 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -19,11 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/memstream.h>
-#include "graphics/screen.h"
+#include "common/memstream.h"
 #include "common/endian.h"
-#include "background.h"
-#include "screen.h"
+#include "dragons/background.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index f0286c072d..e1905d44ff 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -24,9 +24,9 @@
 
 #include "common/rect.h"
 #include "common/system.h"
-#include "bigfile.h"
-#include "dragonrms.h"
-#include "screen.h"
+#include "dragons/bigfile.h"
+#include "dragons/dragonrms.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 class PriorityLayer;
diff --git a/engines/dragons/bag.cpp b/engines/dragons/bag.cpp
index 8ca1e7e702..a56b771a60 100644
--- a/engines/dragons/bag.cpp
+++ b/engines/dragons/bag.cpp
@@ -21,10 +21,10 @@
  */
 
 #include <common/memstream.h>
-#include "bigfile.h"
-#include "screen.h"
-#include "bag.h"
-#include "background.h"
+#include "dragons/bigfile.h"
+#include "dragons/screen.h"
+#include "dragons/bag.h"
+#include "dragons/background.h"
 
 namespace Dragons {
 
@@ -98,4 +98,4 @@ void Bag::load(BigfileArchive *bigFileArchive) {
 	free(tiles);
 }
 
-} // End of namespace Dragons
\ No newline at end of file
+} // End of namespace Dragons
diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
index 6651c340de..03b9e5cdd0 100644
--- a/engines/dragons/bigfile.cpp
+++ b/engines/dragons/bigfile.cpp
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "bigfile.h"
+#include "dragons/bigfile.h"
 
 namespace Dragons {
 typedef struct FileInfo {
@@ -652,4 +652,4 @@ bool BigfileArchive::doesFileExist(const char *filename) {
 }
 
 
-} // End of namespace Illusions
+} // End of namespace Dragons
diff --git a/engines/dragons/credits.cpp b/engines/dragons/credits.cpp
index 021319ed85..19f28ef986 100644
--- a/engines/dragons/credits.cpp
+++ b/engines/dragons/credits.cpp
@@ -25,7 +25,7 @@
 #include "dragons/bigfile.h"
 #include "dragons/dragons.h"
 #include "dragons/screen.h"
-#include "font.h"
+#include "dragons/font.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 0ff8b9c495..20f8796642 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -19,16 +19,16 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "cursor.h"
-#include "actor.h"
-#include "actorresource.h"
-#include "dragons.h"
-#include "dragonimg.h"
-#include "dragonini.h"
-#include "dragonobd.h"
-#include "inventory.h"
-#include "scene.h"
-#include "scriptopcodes.h"
+#include "dragons/cursor.h"
+#include "dragons/actor.h"
+#include "dragons/actorresource.h"
+#include "dragons/dragons.h"
+#include "dragons/dragonimg.h"
+#include "dragons/dragonini.h"
+#include "dragons/dragonobd.h"
+#include "dragons/inventory.h"
+#include "dragons/scene.h"
+#include "dragons/scriptopcodes.h"
 #include "dragons/screen.h"
 
 namespace Dragons {
@@ -43,11 +43,11 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	_actor->x_pos = _x = 160;
 	_actor->y_pos = _y = 100;
 	_actor->priorityLayer = 6;
-	_actor->flags = 0;
+	_actor->_flags = 0;
 	_actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_actor->updateSequence(_sequenceID);
-	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
-					  Dragons::ACTOR_FLAG_200);
+	_actor->_flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
+					   Dragons::ACTOR_FLAG_200);
 
 	dragonINIResource->getFlickerRecord()->actor = _actor; //TODO is this correct?
 	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
@@ -240,7 +240,6 @@ int16 Cursor::updateIniFromScene() {
 			}
 			if (cursorOverIni != 0) {
 				// 0x80028bf0
-				debug(1, "here OK!!!");
 				// _iniUnderCursor = cursorOverIni;
 				data_80072890 = _iniUnderCursor;
 				data_800728b0_cursor_seqID = _sequenceID;
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 24d4246f9d..d88ac9fa00 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -23,7 +23,7 @@
 #define DRAGONS_CURSOR_H
 
 #include "common/system.h"
-#include "scriptopcodes.h"
+#include "dragons/scriptopcodes.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 772d385132..4e227c3df1 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "cutscene.h"
-#include "dragons.h"
+#include "dragons/cutscene.h"
+#include "dragons/dragons.h"
 #include "dragons/actor.h"
 #include "dragons/actorresource.h"
 #include "dragons/background.h"
diff --git a/engines/dragons/detection.cpp b/engines/dragons/detection.cpp
index 572fdf2e50..ed3a7dff0b 100644
--- a/engines/dragons/detection.cpp
+++ b/engines/dragons/detection.cpp
@@ -21,8 +21,6 @@
  */
 
 #include "dragons/dragons.h"
-
-#include "common/config-manager.h"
 #include "engines/advancedDetector.h"
 #include "common/savefile.h"
 #include "common/system.h"
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index 3749de1430..3e12b9beec 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -20,8 +20,8 @@
  *
  */
 #include <common/debug.h>
-#include "dragonflg.h"
-#include "bigfile.h"
+#include "dragons/dragonflg.h"
+#include "dragons/bigfile.h"
 
 
 namespace Dragons {
diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
index 0d57210f1f..3fa1fc405e 100644
--- a/engines/dragons/dragonimg.cpp
+++ b/engines/dragons/dragonimg.cpp
@@ -20,8 +20,8 @@
  *
  */
 #include <common/memstream.h>
-#include "dragonimg.h"
-#include "bigfile.h"
+#include "dragons/dragonimg.h"
+#include "dragons/bigfile.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index 35316d7583..9fd43f2397 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -21,7 +21,7 @@
  */
 #include <common/debug.h>
 #include "common/memstream.h"
-#include "dragonini.h"
+#include "dragons/dragonini.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 8912aa2fdb..23ed7f0c40 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -23,7 +23,7 @@
 #define SCUMMVM_DRAGONINI_H
 
 #include "common/system.h"
-#include "bigfile.h"
+#include "dragons/bigfile.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/dragonobd.cpp b/engines/dragons/dragonobd.cpp
index 3563de69a7..9571d0a04a 100644
--- a/engines/dragons/dragonobd.cpp
+++ b/engines/dragons/dragonobd.cpp
@@ -20,8 +20,8 @@
  *
  */
 #include "common/memstream.h"
-#include "dragonobd.h"
-#include "bigfile.h"
+#include "dragons/dragonobd.h"
+#include "dragons/bigfile.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
index f095935e9e..d6ffb29c3f 100644
--- a/engines/dragons/dragonrms.cpp
+++ b/engines/dragons/dragonrms.cpp
@@ -20,9 +20,9 @@
  *
  */
 #include <common/memstream.h>
-#include "dragonrms.h"
-#include "dragonobd.h"
-#include "bigfile.h"
+#include "dragons/dragonrms.h"
+#include "dragons/dragonobd.h"
+#include "dragons/bigfile.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 5f28e001c0..919a8bb8af 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -22,30 +22,29 @@
 #include "common/config-manager.h"
 #include "engines/util.h"
 #include "graphics/thumbnail.h"
-#include "graphics/surface.h"
 #include "common/error.h"
-#include "actor.h"
-#include "actorresource.h"
-#include "background.h"
-#include "bigfile.h"
-#include "cursor.h"
-#include "credits.h"
-#include "dragonflg.h"
-#include "dragonimg.h"
-#include "dragonini.h"
-#include "dragonobd.h"
-#include "dragonrms.h"
-#include "dragonvar.h"
-#include "dragons.h"
-#include "font.h"
-#include "inventory.h"
-#include "scene.h"
-#include "screen.h"
-#include "sequenceopcodes.h"
-#include "scriptopcodes.h"
-#include "bag.h"
-#include "talk.h"
-#include "sound.h"
+#include "dragons/actor.h"
+#include "dragons/actorresource.h"
+#include "dragons/background.h"
+#include "dragons/bigfile.h"
+#include "dragons/cursor.h"
+#include "dragons/credits.h"
+#include "dragons/dragonflg.h"
+#include "dragons/dragonimg.h"
+#include "dragons/dragonini.h"
+#include "dragons/dragonobd.h"
+#include "dragons/dragonrms.h"
+#include "dragons/dragonvar.h"
+#include "dragons/dragons.h"
+#include "dragons/font.h"
+#include "dragons/inventory.h"
+#include "dragons/scene.h"
+#include "dragons/screen.h"
+#include "dragons/sequenceopcodes.h"
+#include "dragons/scriptopcodes.h"
+#include "dragons/bag.h"
+#include "dragons/talk.h"
+#include "dragons/sound.h"
 
 namespace Dragons {
 
@@ -204,7 +203,7 @@ Common::Error DragonsEngine::run() {
 	_actorManager = new ActorManager(actorResourceLoader);
 	_scriptOpcodes = new ScriptOpcodes(this, _dragonFLG);
 	_backgroundResourceLoader = new BackgroundResourceLoader(_bigfileArchive, _dragonRMS);
-	_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource, _backgroundResourceLoader);
+	_scene = new Scene(this, _screen, _scriptOpcodes, _actorManager, _dragonRMS, _dragonINIResource, _backgroundResourceLoader);
 
 	_sound = new SoundManager(this, _bigfileArchive, _dragonRMS);
 
@@ -258,18 +257,13 @@ uint16 DragonsEngine::ipt_img_file_related()
 
 void DragonsEngine::gameLoop()
 {
-	bool bVar1;
 	uint uVar3;
-	uint32_t uVar4;
 	uint actorId;
-	int iVar5;
 	ushort uVar6;
 	ushort uVar7;
 	uint actorId_00;
-	void *buffer;
 	uint16_t sequenceId;
 	DragonINI *pDVar8;
-	ushort *puVar9;
 
 	_cursor->_cursorActivationSeqOffset = 0;
 	bit_flags_8006fbd8 = 0;
@@ -566,7 +560,7 @@ void DragonsEngine::gameLoop()
 				_cursor->_sequenceID = 5;
 				actorId = uVar3;
 				if (tmpId != 0) {
-					actor->flags = 0;
+					actor->_flags = 0;
 					actor->priorityLayer = 0;
 					actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 					actor->updateSequence(getINI(tmpId - 1)->field_8 * 2 + 10);
@@ -583,7 +577,7 @@ void DragonsEngine::gameLoop()
 			//drop item back into inventory
 			if (_inventory->addItemIfPositionIsEmpty(_cursor->iniItemInHand, _cursor->_x, _cursor->_y)) {
 				Actor *invActor = _inventory->getInventoryItemActor(_cursor->iniItemInHand);
-				invActor->flags = 0;
+				invActor->_flags = 0;
 				invActor->priorityLayer = 0;
 				invActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 				invActor->updateSequence(
@@ -629,8 +623,8 @@ void DragonsEngine::updateHandler() {
 	//TODO logic here
 	for (uint16 i = 0; i < 0x17; i++) {
 		Actor *actor = _actorManager->getActor(i);
-		if (actor->flags & Dragons::ACTOR_FLAG_40) {
-			if (!(actor->flags & Dragons::ACTOR_FLAG_100)) {
+		if (actor->_flags & Dragons::ACTOR_FLAG_40) {
+			if (!(actor->_flags & Dragons::ACTOR_FLAG_100)) {
 				int16 priority = _scene->getPriorityAtPosition(Common::Point(actor->x_pos, actor->y_pos));
 				DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 				if (flicker && _scene->contains(flicker) && flicker->actor->_actorID == i) {
@@ -724,13 +718,13 @@ void DragonsEngine::updateActorSequences() {
 			continue;
 		}
 
-		if (actor->flags & Dragons::ACTOR_FLAG_40 &&
-			!(actor->flags & Dragons::ACTOR_FLAG_4) &&
-			!(actor->flags & Dragons::ACTOR_FLAG_400) &&
-			(actor->sequenceTimer == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
+		if (actor->_flags & Dragons::ACTOR_FLAG_40 &&
+			!(actor->_flags & Dragons::ACTOR_FLAG_4) &&
+			!(actor->_flags & Dragons::ACTOR_FLAG_400) &&
+			(actor->sequenceTimer == 0 || actor->_flags & Dragons::ACTOR_FLAG_1)) {
 			debug(5, "Actor[%d] execute sequenceOp", actorId);
 
-			if (actor->flags & Dragons::ACTOR_FLAG_1) {
+			if (actor->_flags & Dragons::ACTOR_FLAG_1) {
 				actor->resetSequenceIP();
 				//clear flag mask 0xeff6;
 				actor->clearFlag(ACTOR_FLAG_1);
@@ -884,7 +878,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 				if ((bit_flags_8006fbd8 & 2) == 0) {
 					bit_flags_8006fbd8 = bit_flags_8006fbd8 | 2;
 				}
-//				if (((((actors[actorId].flags & 0x2000) == 0) && ((actors[actorId].flags & 4) != 0)) &&
+//				if (((((actors[actorId]._flags & 0x2000) == 0) && ((actors[actorId]._flags & 4) != 0)) &&
 //					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
 //				(actors[actorId]._sequenceID2 != -1)) {
 //					actor_update_sequenceID(actorId,actors[actorId]._sequenceID2);
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index f3865687b8..3dc45f9823 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -24,7 +24,7 @@
 
 #include "gui/EventRecorder.h"
 #include "engines/engine.h"
-#include "specialopcodes.h"
+#include "dragons/specialopcodes.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/dragonvar.cpp b/engines/dragons/dragonvar.cpp
index d35fe5b454..c5bf58b92c 100644
--- a/engines/dragons/dragonvar.cpp
+++ b/engines/dragons/dragonvar.cpp
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "dragonvar.h"
-#include "bigfile.h"
+#include "dragons/dragonvar.h"
+#include "dragons/bigfile.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 1f452ae03a..d612089f67 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -21,12 +21,12 @@
  */
 #include <common/memstream.h>
 #include <common/textconsole.h>
-#include "bigfile.h"
-#include "cursor.h"
-#include "font.h"
-#include "scene.h"
-#include "screen.h"
-#include "dragons.h"
+#include "dragons/bigfile.h"
+#include "dragons/cursor.h"
+#include "dragons/font.h"
+#include "dragons/scene.h"
+#include "dragons/screen.h"
+#include "dragons/dragons.h"
 
 
 namespace Dragons {
@@ -76,7 +76,7 @@ void Font::renderToSurface(Graphics::Surface *surface, int16 x, int16 y, uint16
 		pixels += i * 8;
 //		debug("char: %d size: %d %d", (text[i] - 0x20), _numChars, (30 + i));
 		byte *data = _pixels + mapChar(text[i]) * 64;
-		for (int y = 0; y < 8; y++) {
+		for (int j = 0; j < 8; j++) {
 			memcpy(pixels, data, 8);
 			data += 8;
 			pixels += surface->pitch;
@@ -110,7 +110,6 @@ FontManager::~FontManager() {
 void FontManager::addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 fontType) {
 	assert(length < 1024);
 	assert(fontType < 4);
-	byte *palette = _vm->_cursor->getPalette();
 	ScreenTextEntry *screenTextEntry = new ScreenTextEntry();
 	screenTextEntry->position = Common::Point(x, y);
 	screenTextEntry->surface = _fonts[fontType]->render(text, length);
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 6137d66321..ec42bcae70 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -20,15 +20,14 @@
  *
  */
 
-#include "actor.h"
-#include "dragons.h"
-#include "dragonrms.h"
-#include "dragonini.h"
-#include "background.h"
-#include "inventory.h"
-#include "bag.h"
-#include "scene.h"
-#include "talk.h"
+#include "dragons/actor.h"
+#include "dragons/dragons.h"
+#include "dragons/dragonini.h"
+#include "dragons/background.h"
+#include "dragons/inventory.h"
+#include "dragons/bag.h"
+#include "dragons/scene.h"
+#include "dragons/talk.h"
 #include "dragons/screen.h"
 
 namespace Dragons {
@@ -81,11 +80,11 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_actor->x_pos = 2;
 	_actor->y_pos = 0;
 	_actor->priorityLayer = 6;
-	_actor->flags = 0;
+	_actor->_flags = 0;
 	_actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_actor->updateSequence(0);
-	_actor->flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
-						 Dragons::ACTOR_FLAG_200);
+	_actor->_flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
+					   Dragons::ACTOR_FLAG_200);
 	_sequenceId = 0;
 	_type = 0;
 	_old_showing_value = 0;
@@ -174,7 +173,7 @@ void Inventory::openInventory() {
 		item->y_pos = item->_walkDestY = invYPosTable[i] + 0xc;
 
 		if (inventoryItemTbl[i]) {
-			item->flags = 0; //clear all flags
+			item->_flags = 0; //clear all flags
 			item->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 			item->priorityLayer = 0;
 			item->updateSequence(_vm->getINI(inventoryItemTbl[i] - 1)->field_8 * 2 + 10);
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 2466ffe15a..836c2dc047 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -19,9 +19,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "minigame1.h"
-#include "actor.h"
-#include "dragons.h"
+#include "dragons/minigame1.h"
+#include "dragons/actor.h"
+#include "dragons/dragons.h"
 #include "dragons/dragonini.h"
 #include "dragons/talk.h"
 #include "dragons/screen.h"
@@ -174,7 +174,7 @@ void Minigame1::run() {
 	_vm->clearFlags(ENGINE_FLAG_80);
 	_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(DAT_80063a40 - 1));
 	flickerActor = _vm->getINI(DAT_80063a40 - 1)->actor;
-	flickerActor->flags = flickerActor->flags | 0x380;
+	flickerActor->_flags = flickerActor->_flags | 0x380;
 	flickerActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	flickerActor->priorityLayer = 4;
 	flickerActor->_sequenceID2 = -1;
@@ -189,7 +189,7 @@ void Minigame1::run() {
 //	if (pusherActorId == -1) {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_pusher_8008e954,2,4,0,0xffffffff);
 //	}
-	pusherActor->flags = pusherActor->flags | 0x380;
+	pusherActor->_flags = pusherActor->_flags | 0x380;
 	pusherActor->x_pos = flickerActor->x_pos + -0xe;
 	pusherActor->y_pos = flickerActor->y_pos + 7;
 	pusherActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
@@ -198,7 +198,7 @@ void Minigame1::run() {
 //	if (wheelsActorId == -1) {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_wheels_8008e96c,2,4,0,0xffffffff);
 //	}
-	wheelsActor->flags = wheelsActor->flags | 0x380;
+	wheelsActor->_flags = wheelsActor->_flags | 0x380;
 	wheelsActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	wheelsActor->x_pos = flickerActor->x_pos;
 	wheelsActor->y_pos = flickerActor->y_pos;
@@ -209,7 +209,7 @@ void Minigame1::run() {
 //	if (catActorId == -1) {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc-cat_8008e984,2,4,0,0xffffffff);
 //	}
-	catActor->flags = catActor->flags | 0x380;
+	catActor->_flags = catActor->_flags | 0x380;
 	catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	catActor->priorityLayer = 0;
 	i = 0;
@@ -218,7 +218,7 @@ void Minigame1::run() {
 //		if (targetActorIdTbl[(uint)i + 1] == -1) {
 //			ProbablyShowASCIIMessage(s_couldn't_alloc_target!_8008e998,2,4,0,0xffffffff);
 //		}
-		targetActorIdTbl[(uint)i + 1]->flags = targetActorIdTbl[(uint)i + 1]->flags | 0x380;
+		targetActorIdTbl[(uint)i + 1]->_flags = targetActorIdTbl[(uint)i + 1]->_flags | 0x380;
 		targetActorIdTbl[(uint)i + 1]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 		auStack378[(uint)i] = 0;
 		//TODO FUN_80017010_update_actor_texture_maybe(1);
@@ -233,7 +233,7 @@ void Minigame1::run() {
 //	if (dustSpriteActorId == 0xffff) {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_dust_sprite!_8008e9b0,2,5,0,0xffffffff);
 //	}
-	dustSpriteActor->flags = dustSpriteActor->flags | 0x380;
+	dustSpriteActor->_flags = dustSpriteActor->_flags | 0x380;
 	dustSpriteActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	uVar1 = _vm->getINI(DAT_80063a48 - 1)->actor; //dragon_ini_pointer[DAT_80063a48 + -1].actorId;
 	local_21e = 0;
@@ -282,7 +282,7 @@ void Minigame1::run() {
 								if ((((flickerActor->_sequenceID != 0) &&
 									  (flickerActor->_sequenceID != 5)) &&
 									 (flickerActor->_sequenceID != 6)) ||
-									((flickerActor->flags & 4) != 0)) {
+									((flickerActor->_flags & 4) != 0)) {
 									flickerActor->updateSequence(0);
 								}
 							}
@@ -363,7 +363,7 @@ void Minigame1::run() {
 					break;
 				case 2: // initial release of cat.
 					if (flickerActor->_sequenceID == 7) {
-						if ((flickerActor->flags & 4) != 0) {
+						if ((flickerActor->_flags & 4) != 0) {
 							i = 1;
 							while ((i < 8 && ((((int)(uint)flickerXPos < (int)((uint)auStack352[(uint)i * 3] - 6) ||
 												((uint)auStack352[(uint)i * 3 + 1] + 6 < (uint)flickerXPos)) ||
@@ -502,8 +502,8 @@ void Minigame1::run() {
 					}
 					break;
 				case 4: // cat sliding down wall.
-					if (((catActor->flags & 4) != 0) &&
-					((dustSpriteActor->flags & 4) != 0)) {
+					if (((catActor->_flags & 4) != 0) &&
+						((dustSpriteActor->_flags & 4) != 0)) {
 						if (catActor->_sequenceID == 0xe) {
 							if (local_23e < 0x4300) {
 								local_23e = local_23e + local_23a;
@@ -535,20 +535,20 @@ void Minigame1::run() {
 					else {
 						gameState = 6;
 						catActor->_sequenceID = 0x10;
-						catActor->flags = catActor->flags | 4;
+						catActor->_flags = catActor->_flags | 4;
 					}
 					break;
 				case 6: // cat run across field
 					catActor->priorityLayer = 3;
 					if (local_252 == 0) {
 						if (catActor->_sequenceID == 0xf) {
-							if ((catActor->flags & 4) != 0) {
+							if ((catActor->_flags & 4) != 0) {
 								catActor->updateSequence(0x10);
 							}
 						}
 						else {
 							if (catActor->_sequenceID == 0x10) {
-								if ((catActor->flags & 4) != 0) {
+								if ((catActor->_flags & 4) != 0) {
 									catFieldE_scaleMaybe = 0x80;
 									local_23e = 0x4300;
 									local_23a = 0x100;
@@ -637,7 +637,7 @@ void Minigame1::run() {
 					}
 					else {
 						if (local_234 < 2) {
-							if ((local_234 == 0) && ((catActor->flags & 4) != 0)) {
+							if ((local_234 == 0) && ((catActor->_flags & 4) != 0)) {
 								local_234 = 3;
 								local_232 = 0;
 							}
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index a744238bf5..10a873a74a 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -19,10 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "minigame2.h"
-#include "actor.h"
+#include "dragons/minigame2.h"
+#include "dragons/actor.h"
 #include "dragons/actorresource.h"
-#include "dragons.h"
+#include "dragons/dragons.h"
 #include "dragons/dragonini.h"
 #include "dragons/talk.h"
 #include "dragons/inventory.h"
@@ -435,7 +435,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 										DAT_80093cb4 = DAT_80093cb4 + 1;
 									}
 								}
-								if ((uVar12->flags & 4) != 0) {
+								if ((uVar12->_flags & 4) != 0) {
 									if (DAT_80093cc0 != 0) {
 										DAT_80093cc0 = DAT_80093cc0 - 1;
 									}
@@ -459,11 +459,11 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 							_vm->waitForFrames(2 * 0x3c);
 //							DisableVSyncEvent();
 							memset(paletteData,0,0x200);
-							uVar5->flags = uVar5->flags & 0xfbff;
+							uVar5->_flags = uVar5->_flags & 0xfbff;
 							loungealotHeadActor->setFlag(ACTOR_FLAG_400);
 							loungealotLeftUpperArm->setFlag(ACTOR_FLAG_400);
 							loungealotRightArm->setFlag(ACTOR_FLAG_400);
-							uVar8->flags = uVar8->flags | 0x400;
+							uVar8->_flags = uVar8->_flags | 0x400;
 							flickerArm->setFlag(ACTOR_FLAG_400);
 							loungealotThumb->setFlag(ACTOR_FLAG_400);
 							uVar12->setFlag(ACTOR_FLAG_400);
@@ -506,7 +506,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					if (loungealotLeftUpperArm->_sequenceID != local_268) {
 						loungealotLeftUpperArm->updateSequence(local_268);
 					}
-					if ((flickerArm->flags & 4) != 0) {
+					if ((flickerArm->_flags & 4) != 0) {
 						if (_vm->isRightKeyPressed() && (local_288 != 0)) {
 							local_288 = local_288 - 1;
 						}
@@ -546,7 +546,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					else {
 						local_264 = 0;
 					}
-					if ((uVar12->flags & 4) != 0) {
+					if ((uVar12->_flags & 4) != 0) {
 						if (FUN_80093248() && (local_284 != 0)) {
 							local_284 = local_284 - 1;
 						}
@@ -647,8 +647,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 								}
 							}
 						}
-						uVar12->flags = uVar12->flags | 0x400;
-						uVar13->flags = uVar13->flags | 0x400;
+						uVar12->_flags = uVar12->_flags | 0x400;
+						uVar13->_flags = uVar13->_flags | 0x400;
 						flickerArm->updateSequence((uint)local_28 + 0xf);
 						loungealotThumb->updateSequence((uint)local_28 + 0xf);
 						DAT_80093c94 = 1;
@@ -658,10 +658,10 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			}
 			else {
 				if (DAT_80093c94 == 2) {
-					uVar12->flags = uVar12->flags | 0x1000;
-					uVar13->flags = uVar13->flags | 0x1000;
-					flickerArm->flags = flickerArm->flags | 0x1000;
-					loungealotThumb->flags = loungealotThumb->flags | 0x1000;
+					uVar12->_flags = uVar12->_flags | 0x1000;
+					uVar13->_flags = uVar13->_flags | 0x1000;
+					flickerArm->_flags = flickerArm->_flags | 0x1000;
+					loungealotThumb->_flags = loungealotThumb->_flags | 0x1000;
 					_vm->_screen->setScreenShakeOffset(0, 0);
 					if (local_258 == 1) {
 //						playSoundFromTxtIndex(DAT_80063ad0);
@@ -751,8 +751,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				DAT_80093cbc = 1;
 				DAT_80093cb8 = 0;
 				DAT_80093cc0 = 1;
-				uVar12->flags = uVar12->flags & 0xfbff;
-				uVar13->flags = uVar13->flags & 0xfbff;
+				uVar12->_flags = uVar12->_flags & 0xfbff;
+				uVar13->_flags = uVar13->_flags & 0xfbff;
 				flickerArm->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
 				loungealotThumb->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
 				uVar12->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 26bbb45103..f874013739 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -29,7 +29,7 @@
 #include "dragons/screen.h"
 #include "dragons/sound.h"
 #include "dragons/talk.h"
-#include "dragons.h"
+#include "dragons/dragons.h"
 
 namespace Dragons {
 
@@ -221,7 +221,7 @@ void Minigame3::run() {
 		if (tearActorTbl[(int16)i] == NULL) {
 			error("Couldn't alloc tear");
 		}
-		tearActorTbl[(int16)i]->flags = tearActorTbl[(int16)i]->flags | 0x380;
+		tearActorTbl[(int16)i]->_flags = tearActorTbl[(int16)i]->_flags | 0x380;
 		tearActorTbl[(int16)i]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 		tearActorTbl[(int16)i]->priorityLayer = 0;
 		local_208[(int16)i] = -1;
@@ -249,7 +249,7 @@ void Minigame3::run() {
 		if (tearBlinkActorTbl[(int16)i] == NULL) {
 			error("Couldn't alloc tear blink");
 		}
-		tearBlinkActorTbl[(int16)i]->flags = tearBlinkActorTbl[(int16)i]->flags | 0x4384;
+		tearBlinkActorTbl[(int16)i]->_flags = tearBlinkActorTbl[(int16)i]->_flags | 0x4384;
 		tearBlinkActorTbl[(int16)i]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 		tearBlinkActorTbl[(int16)i]->priorityLayer = 0;
 		i = i + 1;
@@ -355,7 +355,7 @@ void Minigame3::run() {
 		_vm->waitForFrames(1);
 		switch(currentState) {
 			case 1:
-				if ((bunnyActorTbl[local_1a]->_sequenceID != 5) || ((bunnyActorTbl[local_1a]->flags & 4) != 0)) {
+				if ((bunnyActorTbl[local_1a]->_sequenceID != 5) || ((bunnyActorTbl[local_1a]->_flags & 4) != 0)) {
 					if ((local_56 < 1) ||
 						(((int)bunnyInfo[local_20].x >> 9 <= (int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x ||
 																				((int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x <= (int)bunnyInfo[local_1e].x >> 9)))) {
@@ -697,8 +697,8 @@ void Minigame3::run() {
 		}
 		i = i + 1;
 	}
-	tearBlinkActorTbl[0]->flags = tearBlinkActorTbl[0]->flags | 4;
-	tearBlinkActorTbl[1]->flags = tearBlinkActorTbl[1]->flags | 4;
+	tearBlinkActorTbl[0]->_flags = tearBlinkActorTbl[0]->_flags | 4;
+	tearBlinkActorTbl[1]->_flags = tearBlinkActorTbl[1]->_flags | 4;
 	updateBackgroundLayerOffset(2, 0x280, 0);
 	updateBackgroundLayerOffset(1, 0, 0);
 	updateBackgroundLayerOffset(0, 0, 0);
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 40dc30c63c..db68905db1 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -19,9 +19,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "minigame4.h"
-#include "actor.h"
-#include "dragons.h"
+#include "dragons/minigame4.h"
+#include "dragons/actor.h"
+#include "dragons/dragons.h"
 #include "dragons/dragonini.h"
 #include "dragons/talk.h"
 #include "dragons/inventory.h"
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index ef8d1ed633..9fad252410 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -19,9 +19,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "minigame5.h"
-#include "actor.h"
-#include "dragons.h"
+#include "dragons/minigame5.h"
+#include "dragons/actor.h"
+#include "dragons/dragons.h"
 #include "dragons/dragonini.h"
 #include "dragons/talk.h"
 #include "dragons/scene.h"
@@ -107,7 +107,7 @@ void Minigame5::run() {
 	_vm->clearFlags(ENGINE_FLAG_80);
 	_vm->_dragonINIResource->setFlickerRecord(_vm->_dragonINIResource->getRecord(DAT_80063a40 - 1));
 	flickerActor = _vm->_dragonINIResource->getFlickerRecord()->actor;
-	flickerActor->flags = flickerActor->flags | 0x380;
+	flickerActor->_flags = flickerActor->_flags | 0x380;
 	flickerActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	flickerActor->priorityLayer = 4;
 	flickerActor->_sequenceID2 = -1;
@@ -124,7 +124,7 @@ void Minigame5::run() {
 	if (pusherActor == NULL) {
 		error("Couldn't alloc pusher!");
 	}
-	pusherActor->flags = pusherActor->flags | 0x380;
+	pusherActor->_flags = pusherActor->_flags | 0x380;
 	pusherActor->x_pos = flickerActor->x_pos + -0xe;
 	pusherActor->y_pos = flickerActor->y_pos + 7;
 	pusherActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
@@ -135,7 +135,7 @@ void Minigame5::run() {
 	if (wheelsActor == NULL) {
 		error("Couldn't alloc wheels!");
 	}
-	wheelsActor->flags = wheelsActor->flags | 0x380;
+	wheelsActor->_flags = wheelsActor->_flags | 0x380;
 	wheelsActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	wheelsActor->x_pos = flickerActor->x_pos;
 	wheelsActor->y_pos = flickerActor->y_pos;
@@ -148,7 +148,7 @@ void Minigame5::run() {
 	if (bombActor == NULL) {
 		error("Couldn't alloc bomb!");
 	}
-	bombActor->flags = bombActor->flags | 0x380;
+	bombActor->_flags = bombActor->_flags | 0x380;
 	bombActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	bombActor->priorityLayer = 0;
 //	DisableVSyncEvent();
@@ -157,7 +157,7 @@ void Minigame5::run() {
 	if (dustActor == NULL) {
 		error("Couldn't alloc dust sprite!");
 	}
-	dustActor->flags = dustActor->flags | 0x380;
+	dustActor->_flags = dustActor->_flags | 0x380;
 	dustActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	local_4e = _vm->_dragonINIResource->getRecord(DAT_80063a48 + -1)->actor;
 	local_4c = 0;
@@ -182,7 +182,7 @@ void Minigame5::run() {
 									if ((((flickerActor->_sequenceID != 0) &&
 										  (flickerActor->_sequenceID != 5)) &&
 										 (flickerActor->_sequenceID != 6)) ||
-										((flickerActor->flags & 4) != 0)) {
+										((flickerActor->_flags & 4) != 0)) {
 										flickerActor->updateSequence(0x19);
 									}
 								}
@@ -262,7 +262,7 @@ void Minigame5::run() {
 							break;
 						case 2:
 							if (flickerActor->_sequenceID == 0x1b) {
-								if ((flickerActor->flags & 4) != 0) {
+								if ((flickerActor->_flags & 4) != 0) {
 									if ((((int)(uint)local_850 < (int)((local_30[0]) - 6)) ||
 										 ((uint)local_30[1] + 6 < (uint)local_850)) || (local_72 != local_30[2])) {
 										local_42 = 8;
@@ -395,7 +395,7 @@ void Minigame5::run() {
 							pusherActor->updateSequence(7);
 							_vm->_talk->loadText(DAT_8006391c, auStack2120, 1000);
 							_vm->_talk->displayDialogAroundPoint(auStack2120, (int)(short)(local_850 >> 3),0xc,0,1,DAT_8006391c);
-							pusherActor->flags = pusherActor->flags | 0x1000;
+							pusherActor->_flags = pusherActor->_flags | 0x1000;
 							local_10 = 2;
 							local_48 = 1;
 							currentState = 6;
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
index 456df1fb4f..aeb98e2ff5 100644
--- a/engines/dragons/saveload.cpp
+++ b/engines/dragons/saveload.cpp
@@ -23,12 +23,12 @@
 
 #include "graphics/thumbnail.h"
 
-#include "dragons.h"
-#include "dragonflg.h"
-#include "dragonini.h"
-#include "dragonvar.h"
-#include "scene.h"
-#include "cursor.h"
+#include "dragons/dragons.h"
+#include "dragons/dragonflg.h"
+#include "dragons/dragonini.h"
+#include "dragons/dragonvar.h"
+#include "dragons/scene.h"
+#include "dragons/cursor.h"
 
 
 namespace Dragons {
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index f69166dcf7..993060d929 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -19,25 +19,25 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "scene.h"
-#include "dragons.h"
-#include "actor.h"
-#include "background.h"
-#include "cursor.h"
-#include "credits.h"
-#include "dragonini.h"
-#include "dragonimg.h"
-#include "font.h"
-#include "inventory.h"
-#include "screen.h"
-#include "actorresource.h"
-#include "scriptopcodes.h"
+#include "dragons/scene.h"
+#include "dragons/dragons.h"
+#include "dragons/actor.h"
+#include "dragons/background.h"
+#include "dragons/cursor.h"
+#include "dragons/credits.h"
+#include "dragons/dragonini.h"
+#include "dragons/dragonimg.h"
+#include "dragons/font.h"
+#include "dragons/inventory.h"
+#include "dragons/screen.h"
+#include "dragons/actorresource.h"
+#include "dragons/scriptopcodes.h"
 
 namespace Dragons {
 
 
-Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader)
-		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _bigfileArchive(bigfileArchive), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource), _backgroundLoader(backgroundResourceLoader) {
+Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader)
+		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource), _backgroundLoader(backgroundResourceLoader) {
 	data_80063392 = 2;
 	_data_800633ee = 0;
 }
@@ -240,27 +240,27 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 					actor->_sequenceID2 = ini->field_20_actor_field_14;
 
 					if (ini->field_1a_flags_maybe & 2) {
-						actor->flags |= Dragons::ACTOR_FLAG_80;
+						actor->_flags |= Dragons::ACTOR_FLAG_80;
 					} else {
-						actor->flags &= 0xfeff;
+						actor->_flags &= 0xfeff;
 					}
 
 					if (ini->field_1a_flags_maybe & 0x20) {
-						actor->flags |= Dragons::ACTOR_FLAG_100;
+						actor->_flags |= Dragons::ACTOR_FLAG_100;
 					} else {
-						actor->flags &= 0xfeff;
+						actor->_flags &= 0xfeff;
 					}
 
 					if (ini->field_1a_flags_maybe & 4) {
-						actor->flags |= Dragons::ACTOR_FLAG_8000;
+						actor->_flags |= Dragons::ACTOR_FLAG_8000;
 					} else {
-						actor->flags &= 0x7fff;
+						actor->_flags &= 0x7fff;
 					}
 
 					if (ini->field_1a_flags_maybe & 0x100) {
-						actor->flags |= Dragons::ACTOR_FLAG_4000;
+						actor->_flags |= Dragons::ACTOR_FLAG_4000;
 					} else {
-						actor->flags &= 0xbfff;
+						actor->_flags &= 0xbfff;
 					}
 //
 //				Graphics::Surface *s = actor->getCurrentFrame();
@@ -363,8 +363,8 @@ void Scene::draw() {
 				continue;
 			}
 
-			if (actor->flags & Dragons::ACTOR_FLAG_40 &&
-				!(actor->flags & Dragons::ACTOR_FLAG_400) &&
+			if (actor->_flags & Dragons::ACTOR_FLAG_40 &&
+				!(actor->_flags & Dragons::ACTOR_FLAG_400) &&
 				actor->surface &&
 				actor->frame->width != 0 &&
 				actor->frame->height != 0
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 4d6db7c73a..de56ecd740 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -19,23 +19,21 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_SCENE_H
-#define SCUMMVM_SCENE_H
+#ifndef DRAGONS_SCENE_H
+#define DRAGONS_SCENE_H
 
 #include "common/rect.h"
 #include "common/system.h"
-#include "screen.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
 class DragonsEngine;
 class ActorManager;
 class Background;
-class Bag;
 class DragonRMS;
 class BackgroundResourceLoader;
 class DragonINIResource;
-class BigfileArchive;
 class Screen;
 class ScriptOpcodes;
 class ScaleLayer;
@@ -51,7 +49,6 @@ private:
 	Screen *_screen;
 	ActorManager *_actorManager;
 	Background *_stage;
-	BigfileArchive *_bigfileArchive;
 	DragonRMS *_dragonRMS;
 	DragonINIResource *_dragonINIResource;
 	BackgroundResourceLoader *_backgroundLoader;
@@ -59,10 +56,9 @@ private:
 
 	int16 _currentSceneId;
 	int16 _data_800633ee;
-	Bag *bag;
 
 public:
-	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, BigfileArchive *bigfileArchive, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader);
+	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader);
 
 	void loadScene(uint32 sceneId, uint32 cameraPointId);
 	void loadSceneData(uint32 sceneId, uint32 cameraPointId);
@@ -95,4 +91,4 @@ private:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_SCENE_H
+#endif //DRAGONS_SCENE_H
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 1bc5bfc371..90c9b00d8e 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -19,13 +19,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/endian.h>
+#include "common/endian.h"
 #include "common/system.h"
 #include "common/rect.h"
 #include "engines/util.h"
 #include "dragons/dragons.h"
 #include "dragons/scene.h"
-#include "screen.h"
+#include "dragons/screen.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 36f036ee66..e5c0739419 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -35,10 +35,17 @@
 #include "dragons/sound.h"
 #include "dragons/talk.h"
 #include "dragons/screen.h"
-#include "scriptopcodes.h"
 
 
 namespace Dragons {
+
+// Convenience macros
+#define ARG_SKIP(x) scriptOpCall.skip(x);
+#define ARG_BYTE(name) byte name = scriptOpCall.readByte(); debug(5, "ARG_BYTE(" #name " = %d)", name);
+#define ARG_INT8(name) int8 name = scriptOpCall.readByte(); debug(5, "ARG_INT8(" #name " = %d)", name);
+#define ARG_INT16(name) int16 name = scriptOpCall.readSint16(); debug(5, "ARG_INT16(" #name " = %d)", name);
+#define ARG_UINT32(name) uint32 name = scriptOpCall.readUint32(); debug(5, "ARG_UINT32(" #name " = %08X)", name);
+
 // ScriptOpCall
 
 void ScriptOpCall::skip(uint size) {
@@ -361,7 +368,7 @@ void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
 
 	bool isFlicker = _vm->_dragonINIResource->isFlicker(field2 - 1);
 	if (isFlicker) {
-		ini->actor->flags |= Dragons::ACTOR_FLAG_2000;
+		ini->actor->_flags |= Dragons::ACTOR_FLAG_2000;
 	}
 
 	if (!ini->actor->_actorResource || ini->actor->_actorResource->_id != ini->actorResourceId) {
@@ -375,7 +382,7 @@ void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
 	}
 
 	if (isFlicker) {
-		ini->actor->flags &= ~Dragons::ACTOR_FLAG_2000;
+		ini->actor->_flags &= ~Dragons::ACTOR_FLAG_2000;
 	}
 }
 
@@ -609,7 +616,7 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 		if (field6 != -1) {
 			if (!(field0 & 0x8000)) {
 				assert(ini->actor);
-				ini->actor->flags |= Dragons::ACTOR_FLAG_800;
+				ini->actor->_flags |= Dragons::ACTOR_FLAG_800;
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
 			ini->actor->_walkSpeed = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
@@ -619,7 +626,7 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 		ini->actor->startWalk(point.x, point.y, isFlicker ? 0 : 1);
 
 		if(s3 == 0) {
-			while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
+			while (ini->actor->_flags & Dragons::ACTOR_FLAG_10) {
 				_vm->waitForFrames(1);
 			}
 		}
@@ -663,7 +670,7 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 		if (field6 != -1) {
 			if (!(field0 & 0x8000)) {
 				assert(ini->actor);
-				ini->actor->flags |= Dragons::ACTOR_FLAG_800;
+				ini->actor->_flags |= Dragons::ACTOR_FLAG_800;
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
 			ini->actor->_walkSpeed = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
@@ -672,13 +679,13 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 		ini->actor->startWalk(field8, fieldA, isFlicker ? 0 : 1);
 
 		if(s3 == 0) {
-			while (ini->actor->flags & Dragons::ACTOR_FLAG_10) {
+			while (ini->actor->_flags & Dragons::ACTOR_FLAG_10) {
 				_vm->waitForFrames(1);
 			}
 		}
 		ini->x = field8;
 		ini->y = fieldA;
-		ini->actor->flags &= ~Dragons::ACTOR_FLAG_800;
+		ini->actor->_flags &= ~Dragons::ACTOR_FLAG_800;
 
 	} else {
 		assert(ini->actor);
@@ -783,7 +790,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 	}
 	secondIni->actor->startWalk(newXPosAgain, newYPosAgain, someBooleanFlag);
 	if (!bVar1) {
-		while (secondIni->actor->flags & Dragons::ACTOR_FLAG_10) {
+		while (secondIni->actor->_flags & Dragons::ACTOR_FLAG_10) {
 			_vm->waitForFrames(1);
 		}
 	}
@@ -932,16 +939,16 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 
 		if (field2 == 0x1a && ini->field_1a_flags_maybe & 1 && ini->sceneId == _vm->getCurrentSceneId()) {
 			if (s1 & 2) {
-				ini->actor->flags |= Dragons::ACTOR_FLAG_80;
+				ini->actor->_flags |= Dragons::ACTOR_FLAG_80;
 				ini->actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 			} else {
-				ini->actor->flags &= ~Dragons::ACTOR_FLAG_80;
+				ini->actor->_flags &= ~Dragons::ACTOR_FLAG_80;
 			}
 
 			if (s1 & 4) {
-				ini->actor->flags |= Dragons::ACTOR_FLAG_8000;
+				ini->actor->_flags |= Dragons::ACTOR_FLAG_8000;
 			} else {
-				ini->actor->flags &= ~Dragons::ACTOR_FLAG_8000;
+				ini->actor->_flags &= ~Dragons::ACTOR_FLAG_8000;
 			}
 		}
 
@@ -1042,7 +1049,7 @@ void ScriptOpcodes::opUnk17(ScriptOpCall &scriptOpCall) {
 
 	DragonINI *ini = _vm->getINI(iniId - 1);
 	if (ini->field_1a_flags_maybe & 1) {
-		while (!(ini->actor->flags & Dragons::ACTOR_FLAG_4)) {
+		while (!(ini->actor->_flags & Dragons::ACTOR_FLAG_4)) {
 			_vm->waitForFrames(1);
 		}
 	}
@@ -1178,27 +1185,27 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 				ini->actor = _vm->_actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
 				ini->actor->_sequenceID2 = ini->field_20_actor_field_14;
 				if (ini->field_1a_flags_maybe & 2) {
-					ini->actor->flags |= Dragons::ACTOR_FLAG_80;
+					ini->actor->_flags |= Dragons::ACTOR_FLAG_80;
 				} else {
-					ini->actor->flags &= ~Dragons::ACTOR_FLAG_80;
+					ini->actor->_flags &= ~Dragons::ACTOR_FLAG_80;
 				}
 
 				if (ini->field_1a_flags_maybe & 0x20) {
-					ini->actor->flags |= Dragons::ACTOR_FLAG_100;
+					ini->actor->_flags |= Dragons::ACTOR_FLAG_100;
 				} else {
-					ini->actor->flags &= ~Dragons::ACTOR_FLAG_100;
+					ini->actor->_flags &= ~Dragons::ACTOR_FLAG_100;
 				}
 
 				if (ini->field_1a_flags_maybe & 4) {
-					ini->actor->flags |= Dragons::ACTOR_FLAG_8000;
+					ini->actor->_flags |= Dragons::ACTOR_FLAG_8000;
 				} else {
-					ini->actor->flags &= ~Dragons::ACTOR_FLAG_8000;
+					ini->actor->_flags &= ~Dragons::ACTOR_FLAG_8000;
 				}
 
 				if (ini->field_1a_flags_maybe & 0x100) {
-					ini->actor->flags |= Dragons::ACTOR_FLAG_4000;
+					ini->actor->_flags |= Dragons::ACTOR_FLAG_4000;
 				} else {
-					ini->actor->flags &= ~Dragons::ACTOR_FLAG_4000;
+					ini->actor->_flags &= ~Dragons::ACTOR_FLAG_4000;
 				}
 			}
 		} else {
@@ -1230,7 +1237,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 				_vm->_inventory->addItem(_vm->_cursor->iniItemInHand);
 				if (_vm->_inventory->getType() == 1) {
 					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->iniItemInHand);
-					actor->flags = 0;
+					actor->_flags = 0;
 					actor->priorityLayer = 0;
 					actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 					actor->updateSequence((_vm->getINI(_vm->_cursor->iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 2f2380d229..d74e58e710 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -46,13 +46,6 @@ struct ScriptOpCall {
 	uint32 readUint32();
 };
 
-// Convenience macros
-#define ARG_SKIP(x) scriptOpCall.skip(x);
-#define ARG_BYTE(name) byte name = scriptOpCall.readByte(); debug(5, "ARG_BYTE(" #name " = %d)", name);
-#define ARG_INT8(name) int8 name = scriptOpCall.readByte(); debug(5, "ARG_INT8(" #name " = %d)", name);
-#define ARG_INT16(name) int16 name = scriptOpCall.readSint16(); debug(5, "ARG_INT16(" #name " = %d)", name);
-#define ARG_UINT32(name) uint32 name = scriptOpCall.readUint32(); debug(5, "ARG_UINT32(" #name " = %08X)", name);
-
 typedef Common::Functor1<ScriptOpCall&, void> ScriptOpcode;
 
 class DragonFLG;
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index e8fbea19da..a3683d2e7e 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -23,8 +23,6 @@
 #include "dragons/dragons.h"
 #include "dragons/sequenceopcodes.h"
 #include "dragons/actor.h"
-#include "sequenceopcodes.h"
-
 
 namespace Dragons {
 // OpCall
@@ -119,7 +117,7 @@ void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
 	ARG_INT16(framePointer);
 	debug(4, "set frame pointer %X", framePointer);
 	actor->loadFrame((uint16)framePointer);
-	actor->flags |= Dragons::ACTOR_FLAG_2;
+	actor->_flags |= Dragons::ACTOR_FLAG_2;
 	actor->sequenceTimer = actor->field_c;
 	updateReturn(opCall, 1);
 }
@@ -132,7 +130,7 @@ void SequenceOpcodes::opSetFramePointerAndStop(Actor *actor, OpCall &opCall) {
 void SequenceOpcodes::opJmp(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newIp);
 
-	if (!(actor->flags & Dragons::ACTOR_FLAG_1000)) {
+	if (!(actor->_flags & Dragons::ACTOR_FLAG_1000)) {
 		byte *newOffset = actor->getSeqIpAtOffset((uint32)newIp);
 		opCall._deltaOfs = (int32)(newOffset - actor->_seqCodeIp); //opCall._code);
 		debug(5, "opJump delta: %d", opCall._deltaOfs);
@@ -173,19 +171,19 @@ void SequenceOpcodes::opUpdateXYResetSeqTimerAndStop(Actor *actor, OpCall &opCal
 }
 
 void SequenceOpcodes::opSetActorFlag4AndStop(Actor *actor, OpCall &opCall) {
-	actor->flags |= Dragons::ACTOR_FLAG_4;
+	actor->_flags |= Dragons::ACTOR_FLAG_4;
 	opCall._deltaOfs = 0;
 	opCall._result = 0;
 	//updateReturn(opCall, 1);
 }
 
 void SequenceOpcodes::opSetActorFlags404(Actor *actor, OpCall &opCall) {
-	actor->flags |= (Dragons::ACTOR_FLAG_4 | Dragons::ACTOR_FLAG_400 );
+	actor->_flags |= (Dragons::ACTOR_FLAG_4 | Dragons::ACTOR_FLAG_400 );
 	updateReturn(opCall, 1);
 }
 
 void SequenceOpcodes::opClearActorFlag400(Actor *actor, OpCall &opCall) {
-	actor->flags &= ~Dragons::ACTOR_FLAG_400;
+	actor->_flags &= ~Dragons::ACTOR_FLAG_400;
 	updateReturn(opCall, 1);
 }
 
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index c61f44a698..674c1d6a58 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -19,17 +19,17 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "sound.h"
-#include "dragons.h"
 #include "audio/mixer.h"
 #include "audio/audiostream.h"
 #include "audio/decoders/raw.h"
 #include "audio/decoders/xa.h"
 #include "common/file.h"
 #include "common/memstream.h"
-#include "bigfile.h"
-#include "dragonrms.h"
-#include "VabSound.h"
+#include "dragons/dragons.h"
+#include "dragons/sound.h"
+#include "dragons/bigfile.h"
+#include "dragons/dragonrms.h"
+#include "dragons/VabSound.h"
 
 #define RAW_CD_SECTOR_SIZE 2352
 
@@ -393,8 +393,10 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
 		stopVoicePlaying(soundId);
 	}
 
-		Audio::SoundHandle *handle = getVoiceHandle(soundId);
+	Audio::SoundHandle *handle = getVoiceHandle(soundId);
+	if (handle) {
 		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, key));
+	}
 }
 
 void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
@@ -443,6 +445,7 @@ Audio::SoundHandle *SoundManager::getVoiceHandle(uint16 soundID) {
 			return &_voice[i].handle;
 		}
 	}
+	return NULL;
 }
 
 void SoundManager::stopVoicePlaying(uint16 soundID) {
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index f4f0bd50ce..0a46de53c6 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -36,9 +36,7 @@
 #include "dragons/actor.h"
 #include "dragons/minigame1.h"
 #include "dragons/talk.h"
-#include "dragons/specialopcodes.h"
 #include "dragons/screen.h"
-#include "dragons/minigame1.h"
 #include "dragons/minigame2.h"
 #include "dragons/minigame3.h"
 #include "dragons/minigame4.h"
@@ -304,7 +302,7 @@ void SpecialOpcodes::spcUnk9() {
 	assert(flicker);
 	flicker->field_1a_flags_maybe |= Dragons::INI_FLAG_20;
 	assert(flicker->actor);
-	flicker->actor->flags |= Dragons::ACTOR_FLAG_100;
+	flicker->actor->_flags |= Dragons::ACTOR_FLAG_100;
 	flicker->actor->priorityLayer = 0;
 	_vm->getINI(1)->field_1a_flags_maybe |= Dragons::INI_FLAG_20;
 }
@@ -313,7 +311,7 @@ void SpecialOpcodes::spcUnk9() {
 void SpecialOpcodes::spcUnkA() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	flicker->field_1a_flags_maybe &= ~Dragons::INI_FLAG_20;
-	flicker->actor->flags &= ~Dragons::ACTOR_FLAG_100;
+	flicker->actor->_flags &= ~Dragons::ACTOR_FLAG_100;
 	_vm->getINI(1)->field_1a_flags_maybe &= ~Dragons::INI_FLAG_20;
 }
 
@@ -1203,7 +1201,7 @@ void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
 //	actors[uVar17].actorFileDictionaryIndex = (uint16_t)uVar7;
 //	actors[uVar17].resourceID = 0xcd;
 //	iVar18 = DAT_8006398c;
-//	actors[uVar17].flags = actors[uVar17].flags | 4;
+//	actors[uVar17]._flags = actors[uVar17]._flags | 4;
 //	dragon_ini_pointer[iVar18 + -1].x = 0xcd;
 //	LAB_8002ad94:
 	//EnableVSyncEvent();
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 28bbd5308d..451f4cf43c 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -21,19 +21,19 @@
  */
 
 #include <common/debug.h>
-#include "bigfile.h"
-#include "actor.h"
-#include "cursor.h"
-#include "actorresource.h"
-#include "talk.h"
-#include "sound.h"
-#include "dragons.h"
-#include "dragonini.h"
-#include "dragonimg.h"
-#include "dragonobd.h"
-#include "scene.h"
-#include "font.h"
-#include "scriptopcodes.h"
+#include "dragons/bigfile.h"
+#include "dragons/actor.h"
+#include "dragons/cursor.h"
+#include "dragons/actorresource.h"
+#include "dragons/talk.h"
+#include "dragons/sound.h"
+#include "dragons/dragons.h"
+#include "dragons/dragonini.h"
+#include "dragons/dragonimg.h"
+#include "dragons/dragonobd.h"
+#include "dragons/scene.h"
+#include "dragons/font.h"
+#include "dragons/scriptopcodes.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 347c60e8e8..a049025f3c 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -24,7 +24,7 @@
 #define DRAGONS_TALK_H
 
 #include <common/str.h>
-#include "scriptopcodes.h"
+#include "dragons/scriptopcodes.h"
 
 namespace Dragons {
 


Commit: 77544a8b2600989918f84c768a38e1e597c8fd47
    https://github.com/scummvm/scummvm/commit/77544a8b2600989918f84c768a38e1e597c8fd47
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed naming on include define check

Changed paths:
    engines/dragons/actor.h
    engines/dragons/actorfiles.h
    engines/dragons/actorresource.h
    engines/dragons/background.h
    engines/dragons/bag.h
    engines/dragons/bigfile.h
    engines/dragons/dragonflg.h
    engines/dragons/dragonimg.h
    engines/dragons/dragonini.h
    engines/dragons/dragonobd.h
    engines/dragons/dragonrms.h
    engines/dragons/dragons.h
    engines/dragons/dragonvar.h
    engines/dragons/screen.h


diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index dc16534f5c..07b2616a0a 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_ACTOR_H
-#define SCUMMVM_ACTOR_H
+#ifndef DRAGONS_ACTOR_H
+#define DRAGONS_ACTOR_H
 
 #include "common/system.h"
 
@@ -158,4 +158,4 @@ private:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_ACTOR_H
+#endif //DRAGONS_ACTOR_H
diff --git a/engines/dragons/actorfiles.h b/engines/dragons/actorfiles.h
index 11a3b3df02..d688ab7a7e 100644
--- a/engines/dragons/actorfiles.h
+++ b/engines/dragons/actorfiles.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_ACTORFILES_H
-#define SCUMMVM_ACTORFILES_H
+#ifndef DRAGONS_ACTORFILES_H
+#define DRAGONS_ACTORFILES_H
 
 #define DRAGONS_NUM_ACTOR_FILES 219
 
@@ -245,4 +245,4 @@ const char actorResourceFiles[DRAGONS_NUM_ACTOR_FILES][13] = {
 		"titles.act",
 		"dem11.act"
 };
-#endif //SCUMMVM_ACTORFILES_H
+#endif //DRAGONS_ACTORFILES_H
diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index 335accef6f..82636c2ea1 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_ACTORRESOURCE_H
-#define SCUMMVM_ACTORRESOURCE_H
+#ifndef DRAGONS_ACTORRESOURCE_H
+#define DRAGONS_ACTORRESOURCE_H
 
 #include "common/system.h"
 
@@ -82,4 +82,4 @@ private:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_ACTORRESOURCE_H
+#endif //DRAGONS_ACTORRESOURCE_H
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index e1905d44ff..33f49878ae 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_BACKGROUND_H
-#define SCUMMVM_BACKGROUND_H
+#ifndef DRAGONS_BACKGROUND_H
+#define DRAGONS_BACKGROUND_H
 
 #include "common/rect.h"
 #include "common/system.h"
@@ -143,4 +143,4 @@ protected:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_BACKGROUND_H
+#endif //DRAGONS_BACKGROUND_H
diff --git a/engines/dragons/bag.h b/engines/dragons/bag.h
index f58ce42aed..5ff1663e83 100644
--- a/engines/dragons/bag.h
+++ b/engines/dragons/bag.h
@@ -20,8 +20,8 @@
  *
  */
 
-#ifndef SCUMMVM_BAG_H
-#define SCUMMVM_BAG_H
+#ifndef DRAGONS_BAG_H
+#define DRAGONS_BAG_H
 
 #include <graphics/surface.h>
 #include <common/rect.h>
@@ -50,4 +50,4 @@ private:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_BAG_H
+#endif //DRAGONS_BAG_H
diff --git a/engines/dragons/bigfile.h b/engines/dragons/bigfile.h
index 819dfbe042..d5376a7bd5 100644
--- a/engines/dragons/bigfile.h
+++ b/engines/dragons/bigfile.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_BIGFILE_H
-#define SCUMMVM_BIGFILE_H
+#ifndef DRAGONS_BIGFILE_H
+#define DRAGONS_BIGFILE_H
 
 #include "common/file.h"
 #include "common/language.h"
@@ -41,4 +41,4 @@ public:
 
 } // End of namespace dragons
 
-#endif //SCUMMVM_BIGFILE_H
+#endif //DRAGONS_BIGFILE_H
diff --git a/engines/dragons/dragonflg.h b/engines/dragons/dragonflg.h
index def1869406..d671528b85 100644
--- a/engines/dragons/dragonflg.h
+++ b/engines/dragons/dragonflg.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_DRAGONFLG_H
-#define SCUMMVM_DRAGONFLG_H
+#ifndef DRAGONS_DRAGONFLG_H
+#define DRAGONS_DRAGONFLG_H
 
 #include "common/stream.h"
 #include "common/system.h"
@@ -64,4 +64,4 @@ public:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_DRAGONFLG_H
+#endif //DRAGONS_DRAGONFLG_H
diff --git a/engines/dragons/dragonimg.h b/engines/dragons/dragonimg.h
index 0ad7420f18..4b32308d2e 100644
--- a/engines/dragons/dragonimg.h
+++ b/engines/dragons/dragonimg.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_DRAGONIMG_H
-#define SCUMMVM_DRAGONIMG_H
+#ifndef DRAGONS_DRAGONIMG_H
+#define DRAGONS_DRAGONIMG_H
 
 #include "common/system.h"
 
@@ -53,4 +53,4 @@ public:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_DRAGONIMG_H
+#endif //DRAGONS_DRAGONIMG_H
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 23ed7f0c40..3ba1d90716 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_DRAGONINI_H
-#define SCUMMVM_DRAGONINI_H
+#ifndef DRAGONS_DRAGONINI_H
+#define DRAGONS_DRAGONINI_H
 
 #include "common/system.h"
 #include "dragons/bigfile.h"
@@ -87,4 +87,4 @@ public:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_DRAGONINI_H
+#endif //DRAGONS_DRAGONINI_H
diff --git a/engines/dragons/dragonobd.h b/engines/dragons/dragonobd.h
index 92ac05a3b0..4fd43343b0 100644
--- a/engines/dragons/dragonobd.h
+++ b/engines/dragons/dragonobd.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_DRAGONOBD_H
-#define SCUMMVM_DRAGONOBD_H
+#ifndef DRAGONS_DRAGONOBD_H
+#define DRAGONS_DRAGONOBD_H
 
 #include "common/system.h"
 
@@ -46,4 +46,4 @@ public:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_DRAGONOBD_H
+#endif //DRAGONS_DRAGONOBD_H
diff --git a/engines/dragons/dragonrms.h b/engines/dragons/dragonrms.h
index d22be5a53f..763d756e6f 100644
--- a/engines/dragons/dragonrms.h
+++ b/engines/dragons/dragonrms.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_DRAGONRMS_H
-#define SCUMMVM_DRAGONRMS_H
+#ifndef DRAGONS_DRAGONRMS_H
+#define DRAGONS_DRAGONRMS_H
 
 #include "common/system.h"
 
@@ -59,4 +59,4 @@ private:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_DRAGONRMS_H
+#endif //DRAGONS_DRAGONRMS_H
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 3dc45f9823..51b7693dfd 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_DRAGONS_H
-#define SCUMMVM_DRAGONS_H
+#ifndef DRAGONS_DRAGONS_H
+#define DRAGONS_DRAGONS_H
 
 #include "gui/EventRecorder.h"
 #include "engines/engine.h"
@@ -312,4 +312,4 @@ DragonsEngine *getEngine();
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_DRAGONS_H
+#endif //DRAGONS_DRAGONS_H
diff --git a/engines/dragons/dragonvar.h b/engines/dragons/dragonvar.h
index 1ead7699d7..5ad7ff28ae 100644
--- a/engines/dragons/dragonvar.h
+++ b/engines/dragons/dragonvar.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_DRAGONVAR_H
-#define SCUMMVM_DRAGONVAR_H
+#ifndef DRAGONS_DRAGONVAR_H
+#define DRAGONS_DRAGONVAR_H
 
 #include "common/system.h"
 
@@ -43,4 +43,4 @@ public:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_DRAGONVAR_H
+#endif //DRAGONS_DRAGONVAR_H
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index b91eeb7156..0cee05023f 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef SCUMMVM_SCREEN_H
-#define SCUMMVM_SCREEN_H
+#ifndef DRAGONS_SCREEN_H
+#define DRAGONS_SCREEN_H
 
 #include "graphics/surface.h"
 #include "graphics/pixelformat.h"
@@ -75,4 +75,4 @@ private:
 
 } // End of namespace Dragons
 
-#endif //SCUMMVM_SCREEN_H
+#endif //DRAGONS_SCREEN_H


Commit: 6dcb16fc116b4454c1f07d55261f46a77232729b
    https://github.com/scummvm/scummvm/commit/6dcb16fc116b4454c1f07d55261f46a77232729b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added splashes to stilt walking sequence.

Changed paths:
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 0a46de53c6..3b7a828d61 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -452,30 +452,24 @@ void SpecialOpcodes::spcKnightPoolReflectionLogic() {
 }
 
 void SpecialOpcodes::spcWalkOnStilts() {
-	//TODO
-	ushort uVar1;
-	bool bVar2;
-	void *pvVar3;
-	uint actorId;
-	uint uVar4;
-
-	Actor *actor = _vm->_dragonINIResource->getRecord(0x2a0)->actor;
-	Actor *actor1 = _vm->_dragonINIResource->getRecord(0x2a9)->actor;
-
-	actor->_walkSlopeX = actor->_walkSlopeX / 3;
-	actor->_walkSlopeY = actor->_walkSlopeY / 3;
-	bVar2 = false;
-	while (actor->isFlagSet(ACTOR_FLAG_10)) {
-		//pvVar3 = actor->frame_pointer_maybe;
-		if (actor->frame->field_c == 0) { //*(short *)((int)pvVar3 + 0xc) == 0) {
-			bVar2 = false;
+	bool isInWater = false;
+
+	Actor *flickerOnStilts = _vm->_dragonINIResource->getRecord(0x2a0)->actor;
+	Actor *waterRipples = _vm->_dragonINIResource->getRecord(0x2a9)->actor;
+
+	flickerOnStilts->_walkSlopeX = flickerOnStilts->_walkSlopeX / 3;
+	flickerOnStilts->_walkSlopeY = flickerOnStilts->_walkSlopeY / 3;
+
+	while (flickerOnStilts->isFlagSet(ACTOR_FLAG_10)) {
+		if (flickerOnStilts->frame->field_c == 0) {
+			isInWater = false;
 		}
 		else {
-			if (((!bVar2) && (0x6a < actor->y_pos)) && (actor->y_pos < 0x96)) {
-				bVar2 = true;
-				actor1->x_pos = actor->x_pos - READ_LE_INT16(actor->frame->frameDataOffset); //*(short *)((int)pvVar3 + 0xe);
-				actor1->y_pos = actor->y_pos - READ_LE_INT16(actor->frame->frameDataOffset + 2); //*(short *)((int)pvVar3 + 0x10);
-				actor1->updateSequence(9);
+			if (!isInWater && flickerOnStilts->y_pos >= 0x6a && flickerOnStilts->y_pos < 0x96) {
+				isInWater = true;
+				waterRipples->x_pos = flickerOnStilts->x_pos - flickerOnStilts->frame->field_e;
+				waterRipples->y_pos = flickerOnStilts->y_pos - flickerOnStilts->frame->field_10;
+				waterRipples->updateSequence(9);
 			}
 		}
 		_vm->waitForFrames(1);
@@ -514,7 +508,7 @@ void SpecialOpcodes::spcStGeorgeDragonLanded() {
 	Actor *origActor = ini121->actor;
 	ini121->actor = _vm->_actorManager->loadActor(0x48, 4, ini121->actor->x_pos, ini121->actor->y_pos);
 	origActor->reset_maybe();
-//	reset_actor_maybe();
+//TODO	reset_actor_maybe();
 	ini121->actor->setFlag(ACTOR_FLAG_80);
 	ini121->actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	ini121->actor->priorityLayer = 2;


Commit: adba45ce33e1d66f05f4f6fd710b6a3f80f58860
    https://github.com/scummvm/scummvm/commit/adba45ce33e1d66f05f4f6fd710b6a3f80f58860
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Compile fixes

Changed paths:
    engines/dragons/dragonobd.h


diff --git a/engines/dragons/dragonobd.h b/engines/dragons/dragonobd.h
index 4fd43343b0..dc79489d64 100644
--- a/engines/dragons/dragonobd.h
+++ b/engines/dragons/dragonobd.h
@@ -31,7 +31,7 @@ class BigfileArchive;
 class DragonOBD {
 private:
 	byte *_data;
-	uint32_t _dataSize;
+	uint32 _dataSize;
 	Common::SeekableReadStream *optReadStream;
 	Common::SeekableReadStream *sptReadStream;
 


Commit: 837af740c5e443474c479157b7f49ecbf026e7c2
    https://github.com/scummvm/scummvm/commit/837af740c5e443474c479157b7f49ecbf026e7c2
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Removed uint32_t int32_t and ushort

Changed paths:
    engines/dragons/background.cpp
    engines/dragons/bag.cpp
    engines/dragons/cutscene.cpp
    engines/dragons/dragonflg.h
    engines/dragons/dragons.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/screen.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 57eb1ab481..f87649448e 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -54,7 +54,7 @@ int16 PriorityLayer::getPriority(Common::Point pos) {
 	uint16 mapIndex = READ_LE_UINT16(_map + 2 * (tx + ty * _mapWidth));
 
 //
-//	byte priority = *(byte *)((((uint)*(ushort *)
+//	byte priority = *(byte *)((((uint)*(uint16 *)
 //			(((int)pos.x / 32) * 2 +
 //			 ((int)pos.y / 8) * (uint)_mapWidth * 2 +
 //					_map) * 32) * 8) +
@@ -347,7 +347,7 @@ uint16 ScaleLayer::getScale(uint16 y) {
 	}
 //	iVar3 = 0x1f0000;
 //	do {
-//		yBand = *(ushort *)((int)&scaleBandTbl->y + (iVar3 >> 0xe));
+//		yBand = *(uint16 *)((int)&scaleBandTbl->y + (iVar3 >> 0xe));
 //		if ((yBand != 0xffff) && (yBand <= y)) break;
 //		i = i + -1;
 //		iVar3 = i * 0x10000;
@@ -364,7 +364,7 @@ uint16 ScaleLayer::getScale(uint16 y) {
 //	iVar3 = 0;
 //	do {
 //		lowerYBandIdx = (short)j;
-//		yBand = *(ushort *)((int)&scaleBandTbl->y + (iVar3 >> 0xe));
+//		yBand = *(uint16 *)((int)&scaleBandTbl->y + (iVar3 >> 0xe));
 //		if ((yBand != 0xffff) && (y <= yBand)) break;
 //		j = j + 1;
 //		lowerYBandIdx = (short)j;
diff --git a/engines/dragons/bag.cpp b/engines/dragons/bag.cpp
index a56b771a60..3b79568b1b 100644
--- a/engines/dragons/bag.cpp
+++ b/engines/dragons/bag.cpp
@@ -69,7 +69,7 @@ void Bag::load(BigfileArchive *bigFileArchive) {
 		if ( c == 0 ) {
 			c = 0x8000;
 		} else {
-			//c = (ushort)(((uint)c & 0x1f) << 10) | (ushort)(((uint)c & 0x7c00) >> 10) | c & 0x3e0;
+			//c = (uint16)(((uint)c & 0x1f) << 10) | (uint16)(((uint)c & 0x7c00) >> 10) | c & 0x3e0;
 		}
 		WRITE_LE_UINT16(&pal[i * 2], c);
 	}
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 4e227c3df1..737d5fe325 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -831,7 +831,7 @@ void tournamentUpdateFunction() {
 
 void CutScene::tournamentCutScene() {
 	uint actorId;
-	ushort uVar1;
+	uint16 uVar1;
 	uint16 dialogText[1000];
 //	undefined2 local_218 [256];
 
diff --git a/engines/dragons/dragonflg.h b/engines/dragons/dragonflg.h
index d671528b85..4ba19f4ad4 100644
--- a/engines/dragons/dragonflg.h
+++ b/engines/dragons/dragonflg.h
@@ -49,7 +49,7 @@ private:
 class DragonFLG {
 private:
 	byte *_data;
-	uint32_t _dataSize;
+	uint32 _dataSize;
 	Properties *properties;
 public:
 	virtual ~DragonFLG();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 919a8bb8af..2f9de25fe0 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -259,8 +259,8 @@ void DragonsEngine::gameLoop()
 {
 	uint uVar3;
 	uint actorId;
-	ushort uVar6;
-	ushort uVar7;
+	uint16 uVar6;
+	uint16 uVar7;
 	uint actorId_00;
 	uint16_t sequenceId;
 	DragonINI *pDVar8;
@@ -595,7 +595,7 @@ void DragonsEngine::gameLoop()
 		}
 		LAB_8002790c:
 		if ((_cursor->iniItemInHand == 0) ||
-			(((ushort)(_cursor->_x - 10U) < 300 && ((ushort)(_cursor->_y - 10U) < 0xb4))))
+			(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4))))
 			goto LAB_80027b58;
 		_cursor->_sequenceID = 5;
 		waitForFrames(2);
@@ -844,11 +844,11 @@ void DragonsEngine::runINIScripts() {
 /*
 void DragonsEngine::engineFlag0x20UpdateFunction() {
 {
-	ushort uVar1;
+	uint16 uVar1;
 	uint16_t uVar2;
 	DragonINI *pDVar3;
 	DragonINI *pDVar4;
-	ushort uVar5;
+	uint16 uVar5;
 	uint actorId;
 
 	DragonINI *flickerINI = _dragonINIResource->getFlickerRecord();
@@ -1032,7 +1032,7 @@ void DragonsEngine::call_fade_related_1f() {
 
 void DragonsEngine::performAction() {
 	uint uVar1;
-	ushort uVar2;
+	uint16 uVar2;
 	uint uVar4;
 	uint uVar5;
 	uint uVar6;
@@ -1141,8 +1141,8 @@ void DragonsEngine::FUN_80038890() {
 
 void DragonsEngine::walkFlickerToObject()
 {
-	ushort targetX;
-	ushort targetY;
+	uint16 targetX;
+	uint16 targetY;
 	uint uVar7;
 	uint uVar8;
 	DragonINI *targetINI;
@@ -1193,8 +1193,8 @@ void DragonsEngine::walkFlickerToObject()
 			return;
 		}
 		if (_inventory->getType() == 0 && !isFlagSet(ENGINE_FLAG_200000)) {
-			uVar7 = (uint)(ushort)_cursor->_x;
-			uVar8 = (uint)(ushort)_cursor->_y;
+			uVar7 = (uint)(uint16)_cursor->_x;
+			uVar8 = (uint)(uint16)_cursor->_y;
 			flickerINI->actor->_walkSpeed = 0x10000;
 			flickerINI->actor->startWalk(
 					(int)((uVar7 + (uint)_scene->_camera.x) * 0x10000) >> 0x10,
@@ -1403,8 +1403,8 @@ void DragonsEngine::updatePaletteCycling() {
 			if (_paletteCyclingTbl[loopIndex].updateInterval != 0) {
 				if (_paletteCyclingTbl[loopIndex].updateCounter == 0) {
 					uint16 *palette = (uint16 *)_screen->getPalette(_paletteCyclingTbl[loopIndex].paletteType);
-					int16 uVar14 = (uint)(ushort)_paletteCyclingTbl[loopIndex].startOffset;
-					int16 uVar8 = (uint)(ushort)_paletteCyclingTbl[loopIndex].endOffset;
+					int16 uVar14 = (uint)(uint16)_paletteCyclingTbl[loopIndex].startOffset;
+					int16 uVar8 = (uint)(uint16)_paletteCyclingTbl[loopIndex].endOffset;
 					if (uVar14 < uVar8) {
 						uint16 uVar11 = palette[uVar8];
 						int uVar15 = uVar8;
@@ -1413,9 +1413,9 @@ void DragonsEngine::updatePaletteCycling() {
 								uVar8--;
 								palette[uVar15] = palette[uVar15 - 1];
 								uVar15 = uVar8 & 0xffff;
-							} while ((uint)(ushort)_paletteCyclingTbl[loopIndex].startOffset < (uVar8 & 0xffff));
+							} while ((uint)(uint16)_paletteCyclingTbl[loopIndex].startOffset < (uVar8 & 0xffff));
 						}
-						palette[(ushort)_paletteCyclingTbl[loopIndex].startOffset] = uVar11;
+						palette[(uint16)_paletteCyclingTbl[loopIndex].startOffset] = uVar11;
 						_paletteCyclingTbl[loopIndex].updateCounter = _paletteCyclingTbl[loopIndex].updateInterval;
 					}
 					else {
@@ -1427,9 +1427,9 @@ void DragonsEngine::updatePaletteCycling() {
 									uVar8--;
 									palette[uVar15] = palette[uVar15 + 1];
 									uVar15 = uVar8 & 0xffff;
-								} while ((uVar8 & 0xffff) < (uint)(ushort)_paletteCyclingTbl[loopIndex].startOffset);
+								} while ((uVar8 & 0xffff) < (uint)(uint16)_paletteCyclingTbl[loopIndex].startOffset);
 							}
-							palette[(ushort)_paletteCyclingTbl[loopIndex].endOffset] = uVar11;
+							palette[(uint16)_paletteCyclingTbl[loopIndex].endOffset] = uVar11;
 							_paletteCyclingTbl[loopIndex].updateCounter =
 									_paletteCyclingTbl[loopIndex].updateInterval;
 						}
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 836c2dc047..6ebf0aac76 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -82,11 +82,11 @@ void Minigame1::run() {
 	uint16 i;
 	uint16 local_16e;
 	short local_16a;
-	uint32_t local_168;
+	uint32 local_168;
 	uint16 auStack352 [24];
 	uint16_t local_130 [10];
-	int32_t local_118 [22];
-	uint32_t local_c0 [22];
+	int32 local_118 [22];
+	uint32 local_c0 [22];
 	uint16_t actorFieldC;
 
 	Actor *catActor;
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 10a873a74a..f489c67e00 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -40,7 +40,7 @@ static const uint16 unkArray[5] = {
 };
 
 void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
-	uint16_t uVar1;
+	uint16 uVar1;
 	short sVar2;
 	short sVar3;
 	bool shouldExit;
@@ -58,35 +58,35 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	Actor *uVar13;
 	Actor *uVar14;
 	Actor *uVar15;
-	ushort uVar16;
-	ushort uVar17;
+	uint16 uVar16;
+	uint16 uVar17;
 	uint uVar18;
 	uint uVar19;
 	int iVar20;
 	bool shouldShakeScreen;
 	byte *actorFrameData;
-	ushort local_2e6;
-	int16_t actorSequenceIdTbl [15];
-	uint32_t textIdTbl [4];
-	uint16_t local_2b0 [8];
-	ushort local_288;
-	ushort local_286;
-	ushort local_284;
-	ushort local_282;
-	ushort local_27a;
-	ushort local_278;
+	uint16 local_2e6;
+	int16 actorSequenceIdTbl [15];
+	uint32 textIdTbl [4];
+	uint16 local_2b0 [8];
+	uint16 local_288;
+	uint16 local_286;
+	uint16 local_284;
+	uint16 local_282;
+	uint16 local_27a;
+	uint16 local_278;
 	short local_272;
 	short local_26c;
-	ushort local_268;
-	ushort local_264;
-	ushort local_262;
+	uint16 local_268;
+	uint16 local_264;
+	uint16 local_262;
 	short local_260;
 	short local_258;
 	short local_256;
 	int16_t screenShakeTbl [10];
-	ushort screenShakeCounter;
+	uint16 screenShakeCounter;
 	uint8 paletteData [0x200];
-	ushort local_28;
+	uint16 local_28;
 	int16 originalInventoryType;
 
 	origEngineFlags = _vm->getAllFlags();
@@ -178,16 +178,16 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	loungealotLeftUpperArm = _vm->_actorManager->loadActor(0xb, 2, 0x7d, 199, 4);
 	uVar8 = _vm->_actorManager->loadActor(0xf,0,0x7d,199,4);
 	loungealotRightArm = _vm->_actorManager->loadActor(0x10, 0, 0x7d, 199, 4);
-	flickerArm = _vm->_actorManager->loadActor(9, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
+	flickerArm = _vm->_actorManager->loadActor(9, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
 											   loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e,
 											   loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10, 4);
-	loungealotThumb = _vm->_actorManager->loadActor(0x12, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
+	loungealotThumb = _vm->_actorManager->loadActor(0x12, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
 													loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e,
 													loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10, 4);
-	uVar12 = _vm->_actorManager->loadActor(10, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
+	uVar12 = _vm->_actorManager->loadActor(10, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
 										   flickerArm->x_pos - flickerArm->frame->field_e,
 										   flickerArm->y_pos - flickerArm->frame->field_10, 4);
-	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
+	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
 										   flickerArm->x_pos - flickerArm->frame->field_e,
 										   flickerArm->y_pos - flickerArm->frame->field_10, 4);
 	uVar14 = _vm->_actorManager->loadActor(0x27,0,0x10,0xac,4);
@@ -350,8 +350,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			(&DAT_8008316c)[(uint)uVar16 * 0xb] = local_27a + 0x27;
 			(&DAT_80083168)[(uint)uVar16 * 0xb] = local_27a + 0x27;
 			(&DAT_80083176)[(uint)uVar16 * 0xb] =
-					(ushort)(((int)((uint)local_27a - 1) >> 1) << 5) |
-					(ushort)(((int)(0x40 - (uint)local_27a) >> 1) << 10);
+					(uint16)(((int)((uint)local_27a - 1) >> 1) << 5) |
+					(uint16)(((int)(0x40 - (uint)local_27a) >> 1) << 10);
 			(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] | 1;
 			 */
 		}
@@ -364,8 +364,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			(&DAT_8008316c)[(uint)uVar17 * 0xb] = local_278 + 0x27;
 			(&DAT_80083168)[(uint)uVar17 * 0xb] = local_278 + 0x27;
 			(&DAT_80083176)[(uint)uVar17 * 0xb] =
-					(ushort)(((int)((uint)local_278 - 1) >> 1) << 5) |
-					(ushort)(((int)(0x40 - (uint)local_278) >> 1) << 10);
+					(uint16)(((int)((uint)local_278 - 1) >> 1) << 5) |
+					(uint16)(((int)(0x40 - (uint)local_278) >> 1) << 10);
 			(&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] | 1;
 			 */
 			LAB_800907c4:
@@ -447,13 +447,13 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 									}
 								}
 								if (flickerArm->_sequenceID != actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]) {
-									flickerArm->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-									loungealotThumb->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+									flickerArm->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+									loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
 								}
 								if (uVar12->_sequenceID !=
 									actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]) {
-									uVar12->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
-									uVar13->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+									uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+									uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
 								}
 							}
 							_vm->waitForFrames(2 * 0x3c);
@@ -592,14 +592,14 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						if ((local_286 != DAT_80093cbc) || (local_288 != DAT_80093cb4)) {
 							DAT_80093cb4 = local_288;
 							DAT_80093cbc = local_286;
-							flickerArm->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)local_288 * 3 + (uint)local_286]);
-							loungealotThumb->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+							flickerArm->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)local_288 * 3 + (uint)local_286]);
+							loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
 						}
 						if ((local_282 != DAT_80093cc0) || (local_284 != DAT_80093cb8)) {
 							DAT_80093cb8 = local_284;
 							DAT_80093cc0 = local_282;
-							uVar12->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)local_284 * 3 + (uint)local_282]);
-							uVar13->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+							uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)local_284 * 3 + (uint)local_282]);
+							uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
 						}
 					}
 					else {
@@ -753,10 +753,10 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				DAT_80093cc0 = 1;
 				uVar12->_flags = uVar12->_flags & 0xfbff;
 				uVar13->_flags = uVar13->_flags & 0xfbff;
-				flickerArm->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-				loungealotThumb->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-				uVar12->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
-				uVar13->updateSequence((uint)(ushort)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+				flickerArm->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+				loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+				uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+				uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
 				DAT_80093c94 = 0;
 				local_26c = 0x1e;
 			}
@@ -800,7 +800,7 @@ bool Minigame2::FUN_80093520() {
 						DAT_80093cac = 0;
 						if (DAT_80093cb8 == DAT_80093cb4) {
 							if (DAT_80093cbc < DAT_80093cc0) {
-								DAT_80093cac = (ushort)(DAT_80093cb8 < 4);
+								DAT_80093cac = (uint16)(DAT_80093cb8 < 4);
 							}
 							else {
 								if (!DAT_80093cb0 && _vm->getRand(8) < 3) {
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index db68905db1..2855ea8c34 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -38,7 +38,7 @@ void Minigame4::run() {
 	uint16 uVar1;
 	DragonINI *flicker;
 	uint uVar4;
-	ushort result;
+	uint16 result;
 	int16_t uVar3;
 
 	uVar4 = _vm->getAllFlags();
@@ -105,7 +105,7 @@ void Minigame4::run() {
 	// EnableVSyncEvent();
 	_vm->_dragonINIResource->setFlickerRecord(flicker);
 	_vm->_inventory->setType(uVar3);
-//	_vm->_screen->loadPalette(4,(uint)*(ushort *)
+//	_vm->_screen->loadPalette(4,(uint)*(uint16 *)
 //					(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10)
 //			   + *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
 	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index 9fad252410..fa55dfa320 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -41,31 +41,31 @@ namespace Dragons {
 Minigame5::Minigame5(DragonsEngine *vm) : _vm(vm), DAT_800633e6(0) {}
 
 void Minigame5::run() {
-	ushort uVar1;
+	uint16 uVar1;
 	int iVar2;
 	byte *local_v0_7008;
 	void *local_v0_7256;
 	byte *uVar3;
 	uint uVar4;
-	ushort local_850;
+	uint16 local_850;
 	uint16 auStack2120 [1000];
 	DragonINI*local_78;
 	uint16 local_76;
-	ushort local_74;
-	ushort local_72;
-	ushort bombScale;
+	uint16 local_74;
+	uint16 local_72;
+	uint16 bombScale;
 	Actor *bombActor;
 	Actor *flickerActor;
 	Actor *pusherActor;
 	Actor *dustActor;
-	ushort local_66;
+	uint16 local_66;
 	Actor *wheelsActor;
-	ushort local_62;
-	ushort local_60;
-	ushort local_5e;
+	uint16 local_62;
+	uint16 local_60;
+	uint16 local_5e;
 	short local_5c;
 	short local_5a;
-	ushort currentState;
+	uint16 currentState;
 	short local_50;
 	Actor *local_4e;
 	uint16 local_4c;
@@ -455,7 +455,7 @@ void Minigame5::run() {
 					}
 					else {
 						local_50 = 0;
-						local_66 = (ushort)(currentState != 1);
+						local_66 = (uint16)(currentState != 1);
 						if (pusherActor->_sequenceID != 3) {
 							pusherActor->updateSequence(3);
 						}
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 90c9b00d8e..226fe90390 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -114,7 +114,7 @@ uint16 alphaBlendRGB555( uint32 fg, uint32 bg, uint8 alpha ){
 	alpha = ( alpha + 4 ) >> 3;
 	bg = (bg | (bg << 16)) & 0b00000011111000000111110000011111;
 	fg = (fg | (fg << 16)) & 0b00000011111000000111110000011111;
-	uint32_t result = ((((fg - bg) * alpha) >> 5) + bg) & 0b00000011111000000111110000011111;
+	uint32 result = ((((fg - bg) * alpha) >> 5) + bg) & 0b00000011111000000111110000011111;
 	return (uint16_t)((result >> 16) | result);
 }
 
@@ -122,7 +122,7 @@ uint16 alphaBlendAdditiveRGB555( uint32 fg, uint32 bg){
 	bg = (bg | (bg << 16)) & 0b00000011111000000111110000011111;
 	fg = (fg | (fg << 16)) & 0b00000011111000000111110000011111;
 
-	uint32_t result = bg + fg;
+	uint32 result = bg + fg;
 	//clip r g b values to 565.
 	if (result & (0b111111 << 26)) {
 		result &= 0x1fffff;
@@ -354,7 +354,7 @@ void Screen::loadPalette(uint16 paletteNum, byte *palette) {
 			}
 		} else {
 			//TODO is this needed? see load_palette_into_frame_buffer()
-//			c = (ushort)(((uint)c & 0x1f) << 10) | (ushort)(((uint)c & 0x7c00) >> 10) |
+//			c = (uint16)(((uint)c & 0x1f) << 10) | (uint16)(((uint)c & 0x7c00) >> 10) |
 //					(c & 0x3e0) | (c & 0x8000);
 		}
 	}
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 3b7a828d61..7ae57fe1ee 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -943,7 +943,7 @@ void SpecialOpcodes::spcUnk66() {
 	uint16 bVar1 = (var & 1) == 0;
 	uint16 uVar9 = bVar1;
 	if ((var & 4) == 0) {
-		uVar9 = (ushort)bVar1 + 1;
+		uVar9 = (uint16)bVar1 + 1;
 	}
 	if ((var & 2) == 0) {
 		uVar9 = uVar9 + 1;
@@ -1160,7 +1160,7 @@ void SpecialOpcodes::spcRunCredits() {
 	_vm->setFlags(ENGINE_FLAG_8000000);
 //	iVar1 = file_read_to_buffer(strCredits_txt);
 //	DAT_800728ec = iVar1 + (int)DAT_8007273c;
-//	buf2048bytes = (int32_t *)((iVar1 + 3U & 0xfffffffc) + (int)buf2048bytes);
+//	buf2048bytes = (int32 *)((iVar1 + 3U & 0xfffffffc) + (int)buf2048bytes);
 //	memcpy2((byte *)buf2048bytes,scrFileData_maybe,0x200);
 //	buf2048bytes = buf2048bytes + 0x80;
 	_vm->_screen->loadPalette(0, _vm->_dragonINIResource->getRecord(0x2C8)->actor->_actorResource->getPalette());
@@ -1189,7 +1189,7 @@ void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
 	ini->actor->setFlag(ACTOR_FLAG_4);
 	ini->actorResourceId = 0xcd;
 	//DisableVSyncEvent();
-//	uVar17 = (uint)(ushort)dragon_ini_pointer[DAT_8006398c + -1].field_0x1c;
+//	uVar17 = (uint)(uint16)dragon_ini_pointer[DAT_8006398c + -1].field_0x1c;
 //	uVar7 = load_actor_file(0xcc);
 //	file_read_to_buffer(s_s12a6.act_80011740,(&actor_dictionary)[(uVar7 & 0xffff) * 2]);
 //	actors[uVar17].actorFileDictionaryIndex = (uint16_t)uVar7;
@@ -1474,7 +1474,7 @@ void castleFogUpdateFunction() {
 }
 
 void menInMinesSceneUpdateFunction() {
-	static const uint32_t sceneUpdateFuncDialogTbl[] = {
+	static const uint32 sceneUpdateFuncDialogTbl[] = {
 			0x4590A, 0x45994, 0x459F4, 0x45A60
 	};
 	DragonsEngine *vm = getEngine();
@@ -1505,16 +1505,16 @@ void menInMinesSceneUpdateFunction() {
 
 void monksAtBarSceneUpdateFunction() {
 	static uint8 monksAtBarCurrentState = 0;
-	static const uint32_t sceneUpdateFuncDialogTbl[] = {
+	static const uint32 sceneUpdateFuncDialogTbl[] = {
 			0x37800, 0x37854, 0x378CA,
 			0x39152, 0x3919A, 0x3922C
 	};
-	static const uint32_t barKeeperTextIdTbl[] = {
+	static const uint32 barKeeperTextIdTbl[] = {
 			0x38C68, 0x38CE2, 0x38D4E, 0x38CE2,
 			0x38DC2, 0x38E0C, 0x38C68, 0x38E5C,
 			0x38ED0, 0x38CE2
 	};
-	static const uint32_t DAT_800832f0[] = {0x38F2A, 0x39000, 0x39084, 0x390E8};
+	static const uint32 DAT_800832f0[] = {0x38F2A, 0x39000, 0x39084, 0x390E8};
 
 	DragonsEngine *vm = getEngine();
 	Actor *barKeeper = vm->_dragonINIResource->getRecord(0x1e7)->actor;
@@ -1523,7 +1523,7 @@ void monksAtBarSceneUpdateFunction() {
 	DragonINI *ini = vm->_dragonINIResource->getRecord(0x1e6);
 	bool bVar1;
 	short sVar2;
-	uint32_t textIndex;
+	uint32 textIndex;
 	uint16_t sequenceId;
 	int16 specialOpCounter = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
 	if (specialOpCounter == -1) {
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 451f4cf43c..549f13fbb0 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -112,8 +112,8 @@ Talk::FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param
 
 uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
 									  int16 param_7) {
-		uint32_t *puVar1;
-		uint32_t *puVar2;
+		uint32 *puVar1;
+		uint32 *puVar2;
 		short sVar3;
 		short sVar4;
 		uint16 *tmpTextPtr;
@@ -123,32 +123,32 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 		int iVar8;
 		uint uVar9;
 		uint uVar10;
-		ushort uVar11;
-		uint32_t uVar12;
-		ushort *puVar13;
-		uint32_t uVar14;
-		uint32_t uVar15;
-		uint32_t *puVar16;
-		uint32_t *puVar17;
-		ushort *dialogTextLinePtr;
-		ushort *puVar18;
-		ushort *curDialogTextPtr;
+		uint16 uVar11;
+		uint32 uVar12;
+		uint16 *puVar13;
+		uint32 uVar14;
+		uint32 uVar15;
+		uint32 *puVar16;
+		uint32 *puVar17;
+		uint16 *dialogTextLinePtr;
+		uint16 *puVar18;
+		uint16 *curDialogTextPtr;
 		int unaff_s4;
-		ushort uVar19;
+		uint16 uVar19;
 		short sVar20;
 		uint32 maxLineLengthMaybe;
 		uint16 currentLine [44];
 		uint16 asStack2592 [1208];
-		uint32_t local_b0 [14];
-		ushort local_58;
-		ushort returnStatus;
+		uint32 local_b0 [14];
+		uint16 local_58;
+		uint16 returnStatus;
 		byte *lineTblPtr;
 		uint oldEngineFlags;
 
 		bool isFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
 		returnStatus = 0;
 // TODO what does this do?
-//		puVar1 = uint32_t_ARRAY_80011a60;
+//		puVar1 = uint32_ARRAY_80011a60;
 //		puVar2 = local_b0;
 //		do {
 //			puVar17 = puVar2;
@@ -162,7 +162,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 //			puVar17[3] = uVar15;
 //			puVar1 = puVar16 + 4;
 //			puVar2 = puVar17 + 4;
-//		} while (puVar16 + 4 != (uint32_t *)&DAT_80011a80);
+//		} while (puVar16 + 4 != (uint32 *)&DAT_80011a80);
 //		uVar12 = puVar16[5];
 //		puVar17[4] = _DAT_80011a80;
 //		puVar17[5] = uVar12;
@@ -338,7 +338,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 				iVar5 = (iVar5 >> 0x10) * (uint)DAT_800726f0_tfont_field2 + -1;
 				uVar19 = y;
 				if ((int)(short)y < iVar5) {
-					uVar19 = (ushort)iVar5;
+					uVar19 = (uint16)iVar5;
 				}
 				if (0x16 < (short)uVar19) {
 					uVar19 = 0x16;
@@ -443,12 +443,12 @@ uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 tex
 		IMG *local_v1_184 = _vm->_dragonIMG->getIMG(ini->field_2);
 		int x, y;
 		if (local_v1_184->field_e == 0) {
-			y = (uint)(ushort)local_v1_184->y;
+			y = (uint)(uint16)local_v1_184->y;
 			x = local_v1_184->field_a;
 		}
 		else {
 			x = local_v1_184->field_a;
-			y = (uint)(ushort)local_v1_184->y << 3;
+			y = (uint)(uint16)local_v1_184->y << 3;
 		}
 		displayDialogAroundPoint
 				(dialogText,
@@ -499,8 +499,8 @@ Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 pa
 		// sVar3 = FUN_8001d1ac(0,textId,0);
 		_vm->_sound->playSpeech(textId);
 
-//		if (dialogText == (uint16_t *)0x0) {
-//			dialogText = (uint16_t *)local_58;
+//		if (dialogText == (uint16 *)0x0) {
+//			dialogText = (uint16 *)local_58;
 //		}
 		conversation_related_maybe(dialogText,x,y,param_4,param_5,textId,0); // sVar3); TODO I think this is audio status
 }
@@ -508,7 +508,7 @@ Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 pa
 void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex) {
 	int16 frameYOffset = actor->frame ? actor->frame->yOffset : 0;
 	displayDialogAroundPoint
-			(dialogText,(ushort)((int)(((uint)actor->x_pos - _vm->_scene->_camera.x) * 0x10000) >> 0x13),
+			(dialogText,(uint16)((int)(((uint)actor->x_pos - _vm->_scene->_camera.x) * 0x10000) >> 0x13),
 			 (short)((int)((((uint)actor->y_pos - (uint)frameYOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13) - 3,
 			 param_2,1,textIndex);
 }
@@ -544,7 +544,7 @@ void callMaybeResetData() {
 bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 	uint16 numEntries;
 
-	uint16_t sequenceId;
+	uint16 sequenceId;
 	TalkDialogEntry *selectedDialogText;
 	uint iniId;
 	short local_990 [5];
@@ -650,19 +650,19 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 	short sVar2;
 	uint uVar3;
 	uint uVar4;
-	ushort y;
-	ushort x;
+	uint16 y;
+	uint16 x;
 	uint uVar6;
 	uint uVar7;
-	ushort uVar8;
+	uint16 uVar8;
 	TalkDialogEntry *talkDialogEntry;
 	uint16 local_430 [80];
 	uint16 local_390[5];
 	uint16 local_386 [195];
 	uint16 asStack512 [200];
 	uint16 numEntries;
-	ushort local_60;
-	ushort local_58;
+	uint16 local_60;
+	uint16 local_58;
 	short local_50;
 	uint16 *local_40;
 	uint local_38;
@@ -724,7 +724,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 			uVar3 = (uint)x;
 		} while (x < numEntries);
 	}
-	_vm->_cursor->updateActorPosition(0xf, (((ushort)talkDialogEntry->xPosMaybe + 0x18) - local_58) * 8 + 5);
+	_vm->_cursor->updateActorPosition(0xf, (((uint16)talkDialogEntry->xPosMaybe + 0x18) - local_58) * 8 + 5);
 
 	if (!_vm->isFlagSet(ENGINE_FLAG_8)) {
 		_vm->waitForFrames(1);
@@ -941,7 +941,7 @@ uint32 Talk::getDefaultResponseTextIndex() {
 	return defaultResponseTbl[(_vm->_cursor->data_800728b0_cursor_seqID - 1) * 9 + rand];
 }
 
-uint32_t extractTextIndex(Common::File *fd, uint16_t offset) {
+uint32 extractTextIndex(Common::File *fd, uint16 offset) {
 	fd->seek(0x541b0 + offset * 4);
 	return fd->readUint32LE();
 }
@@ -1063,11 +1063,11 @@ uint16 Talk::FindLastPositionOf5cChar(uint16 *text) {
 }
 
 uint32 Talk::FUN_80031c28(uint16 *srcText, uint16 *destText, uint32 cutLength, uint16 param_4) {
-	ushort destCurIndex;
-	ushort uVar1;
-	ushort uVar2;
+	uint16 destCurIndex;
+	uint16 uVar1;
+	uint16 uVar2;
 	uint srcCurIndex;
-	ushort uVar3;
+	uint16 uVar3;
 	uint uVar4;
 	short chr;
 	bool finished;
@@ -1089,8 +1089,8 @@ uint32 Talk::FUN_80031c28(uint16 *srcText, uint16 *destText, uint32 cutLength, u
 			if ((srcText + (srcCurIndex & 0xffff))[1] == 0x5c) {
 				uVar1 = destCurIndex + 3;
 				destText[(uint)destCurIndex] = 0x2e;
-				destText[(uint)(ushort)(destCurIndex + 1)] = 0x2e;
-				destText[(uint)(ushort)(destCurIndex + 2)] = 0x2e;
+				destText[(uint)(uint16)(destCurIndex + 1)] = 0x2e;
+				destText[(uint)(uint16)(destCurIndex + 2)] = 0x2e;
 			}
 			destCurIndex = uVar1 - 1;
 			uVar1 = uVar3;


Commit: b792c8bd1325446ed964aa1f0d196d8e436dd6ee
    https://github.com/scummvm/scummvm/commit/b792c8bd1325446ed964aa1f0d196d8e436dd6ee
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More compile fixes

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/screen.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sound.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 2f9de25fe0..75c6423244 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -20,6 +20,8 @@
  *
  */
 #include "common/config-manager.h"
+#include "common/keyboard.h"
+#include "common/language.h"
 #include "engines/util.h"
 #include "graphics/thumbnail.h"
 #include "common/error.h"
@@ -262,7 +264,7 @@ void DragonsEngine::gameLoop()
 	uint16 uVar6;
 	uint16 uVar7;
 	uint actorId_00;
-	uint16_t sequenceId;
+	uint16 sequenceId;
 	DragonINI *pDVar8;
 
 	_cursor->_cursorActivationSeqOffset = 0;
@@ -845,7 +847,7 @@ void DragonsEngine::runINIScripts() {
 void DragonsEngine::engineFlag0x20UpdateFunction() {
 {
 	uint16 uVar1;
-	uint16_t uVar2;
+	uint16 uVar2;
 	DragonINI *pDVar3;
 	DragonINI *pDVar4;
 	uint16 uVar5;
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 6ebf0aac76..6e467753b4 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -84,10 +84,10 @@ void Minigame1::run() {
 	short local_16a;
 	uint32 local_168;
 	uint16 auStack352 [24];
-	uint16_t local_130 [10];
+	uint16 local_130 [10];
 	int32 local_118 [22];
 	uint32 local_c0 [22];
-	uint16_t actorFieldC;
+	uint16 actorFieldC;
 
 	Actor *catActor;
 	Actor *pusherActor;
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index fa55dfa320..88c37dcaed 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -69,14 +69,14 @@ void Minigame5::run() {
 	short local_50;
 	Actor *local_4e;
 	uint16 local_4c;
-	uint16_t local_4a;
+	uint16 local_4a;
 	uint16 local_48;
 	int16_t local_46;
 	int16_t local_44;
 	short local_42;
-	uint16_t local_30 [4];
-	uint16_t uStack42;
-	uint16_t local_28 [10];
+	uint16 local_30 [4];
+	uint16 uStack42;
+	uint16 local_28 [10];
 	short local_10;
 	uint32 savedEngineFlags;
 
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 226fe90390..e9eaef3cbf 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -106,8 +106,8 @@ void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *pa
 
 /**
  * Fast RGB555 pixel blending
- * @param fg      The foreground color in uint16_t RGB565 format
- * @param bg      The background color in uint16_t RGB565 format
+ * @param fg      The foreground color in uint16 RGB565 format
+ * @param bg      The background color in uint16 RGB565 format
  * @param alpha   The alpha in range 0-255
  **/
 uint16 alphaBlendRGB555( uint32 fg, uint32 bg, uint8 alpha ){
@@ -115,7 +115,7 @@ uint16 alphaBlendRGB555( uint32 fg, uint32 bg, uint8 alpha ){
 	bg = (bg | (bg << 16)) & 0b00000011111000000111110000011111;
 	fg = (fg | (fg << 16)) & 0b00000011111000000111110000011111;
 	uint32 result = ((((fg - bg) * alpha) >> 5) + bg) & 0b00000011111000000111110000011111;
-	return (uint16_t)((result >> 16) | result);
+	return (uint16)((result >> 16) | result);
 }
 
 uint16 alphaBlendAdditiveRGB555( uint32 fg, uint32 bg){
@@ -138,7 +138,7 @@ uint16 alphaBlendAdditiveRGB555( uint32 fg, uint32 bg){
 		result &= 0b00000011111000000111110000011111;
 		result |= 0x1f;
 	}
-	return (uint16_t)((result >> 16) | result);
+	return (uint16)((result >> 16) | result);
 }
 
 void Screen::copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, AlphaBlendMode alpha) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index e5c0739419..10c1ac33bb 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -1073,7 +1073,7 @@ void ScriptOpcodes::opUnk18(ScriptOpCall &scriptOpCall) {
 	_vm->_talk->loadText(field2, dialog, 2000);
 
 //	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
-//		dialogText = (uint8_t *)load_string_from_dragon_txt(offset,acStack2016);
+//		dialogText = (uint8 *)load_string_from_dragon_txt(offset,acStack2016);
 //	}
 
 	if (fieldA != 0) {
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index 27b3e50736..5d822dcf2c 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -67,7 +67,7 @@ private:
 	DragonRMS *_dragonRMS;
 
 	// SOUND_ARR_DAT_80071f6c
-	uint8_t _soundArr[0x780];
+	uint8 _soundArr[0x780];
 
 	VabSound* _vabMusx;
 	VabSound* _vabGlob;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 7ae57fe1ee..1b25e2205f 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -1478,7 +1478,7 @@ void menInMinesSceneUpdateFunction() {
 			0x4590A, 0x45994, 0x459F4, 0x45A60
 	};
 	DragonsEngine *vm = getEngine();
-	uint16_t sequenceId;
+	uint16 sequenceId;
 	Actor *actor = vm->_dragonINIResource->getRecord(0x293)->actor;
 
 	if (!vm->isFlagSet(ENGINE_FLAG_8000)) {
@@ -1524,7 +1524,7 @@ void monksAtBarSceneUpdateFunction() {
 	bool bVar1;
 	short sVar2;
 	uint32 textIndex;
-	uint16_t sequenceId;
+	uint16 sequenceId;
 	int16 specialOpCounter = vm->_scriptOpcodes->_specialOpCodes->getSpecialOpCounter();
 	if (specialOpCounter == -1) {
 		monksAtBarCurrentState = vm->getRand(2) * 2;
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 549f13fbb0..7ddeb23c84 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -694,7 +694,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 				}
 				uVar3 = FindLastPositionOf5cChar(DAT_80083104);
 				sVar2 = FUN_80031c28(DAT_80083104,asStack512,uVar3 & 0xffff,0x20);
-				talkDialogEntry->xPosMaybe = (uint8_t)local_58;
+				talkDialogEntry->xPosMaybe = (uint8)local_58;
 				local_58 = local_58 + sVar2;
 				talkDialogEntry->yPosMaybe = talkDialogEntry->yPosMaybe + (char)sVar2;
 			}


Commit: 8301d0dbb19395e2ec4ed29c185dcba6a960fc74
    https://github.com/scummvm/scummvm/commit/8301d0dbb19395e2ec4ed29c185dcba6a960fc74
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Compile fixes + formatting

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actorresource.cpp
    engines/dragons/background.cpp
    engines/dragons/bag.cpp
    engines/dragons/bigfile.cpp
    engines/dragons/credits.cpp
    engines/dragons/cursor.cpp
    engines/dragons/cutscene.cpp
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonimg.cpp
    engines/dragons/dragonini.cpp
    engines/dragons/dragonrms.cpp
    engines/dragons/dragons.cpp
    engines/dragons/font.cpp
    engines/dragons/inventory.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/sound.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 505ffd02b7..75c0bcf8fb 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -41,7 +41,7 @@ ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorRes
 
 Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 priorityLayer) {
 	Actor *actor = loadActor(resourceId, sequenceId, x, y);
-	if(actor) {
+	if (actor) {
 		actor->priorityLayer = priorityLayer;
 	}
 	return actor;
@@ -82,7 +82,7 @@ Actor *ActorManager::getActor(uint16 actorId) {
 
 void ActorManager::clearActorFlags(uint16 startingActorId) {
 	assert(startingActorId < DRAGONS_ENGINE_NUM_ACTORS);
-	for(uint16 i = startingActorId; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
+	for (uint16 i = startingActorId; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
 		_actors[i]._flags = 0;
 	}
 }
@@ -100,7 +100,7 @@ ActorResource *ActorManager::getActorResource(uint32 resourceId) {
 void ActorManager::updateActorDisplayOrder() {
 	bool shouldContinue = true;
 
-	while(shouldContinue) {
+	while (shouldContinue) {
 		shouldContinue = false;
 		for (int i = 0; i < DRAGONS_ENGINE_NUM_ACTORS - 1; i++) {
 			Actor *curActor = getActor(_displayOrder[i]);
@@ -482,7 +482,7 @@ void Actor::stopWalk() {
 }
 
 void Actor::waitUntilFlag4IsSet() {
-	while(!isFlagSet(ACTOR_FLAG_4)) {
+	while (!isFlagSet(ACTOR_FLAG_4)) {
 		getEngine()->waitForFrames(1);
 	}
 }
@@ -492,7 +492,7 @@ void Actor::waitUntilFlag8IsSet() {
 		return;
 	}
 
-	while(!(_flags & Dragons::ACTOR_FLAG_8)) {
+	while (!(_flags & Dragons::ACTOR_FLAG_8)) {
 		getEngine()->waitForFrames(1);
 	}
 }
@@ -586,7 +586,7 @@ uint16 Actor::canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 ta
 	// 0x80034d28
 	int32 x = actor_x << 0x10;
 	int32 y = actor_y << 0x10;
-	for(;;) {
+	for (;;) {
 		if ((x+0x8000) >> 0x10 == target_x && (y+0x8000) >> 0x10 == target_y) {
 			return 1;
 		}
@@ -728,7 +728,7 @@ int Actor::startMoveToPoint(int destX, int destY) {
 				}
 				// 0x8001bcc8
 				int direction = startMoveToPoint(_walkDestX, _walkDestY);
-				if(direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
+				if (direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
 					_sequenceID2 = direction;
 				}
 				if (_sequenceID != _sequenceID2 + 8 && _sequenceID2 != -1 && !isFlagSet(ACTOR_FLAG_800)) {
@@ -767,7 +767,7 @@ bool Actor::actorSetSequenceAndWaitAllowSkip(uint16 newSequenceID) {
 }
 
 bool Actor::waitUntilFlag4IsSetAllowSkip() {
-	while(!isFlagSet(ACTOR_FLAG_4)) {
+	while (!isFlagSet(ACTOR_FLAG_4)) {
 		getEngine()->waitForFrames(1);
 		if (getEngine()->checkForActionButtonRelease()) {
 			return true;
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index b778230c57..2346020143 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -110,7 +110,7 @@ Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame, byte *palett
 
 	byte *data = actorFrame.frameDataOffset;
 
-	while(blockSize > 0) {
+	while (blockSize > 0) {
 		int32 size = READ_BE_INT32(data);
 		data += 4;
 		if (size >= 0) {
@@ -131,7 +131,7 @@ Graphics::Surface *ActorResource::loadFrame(ActorFrame &actorFrame, byte *palett
 			}
 			blockSize -= size;
 			if (size != 0) {
-				for(int32 i = size; i != 0; i--) {
+				for (int32 i = size; i != 0; i--) {
 					memcpy(pixels, data, 4);
 					pixels += 4;
 				}
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index f87649448e..ee423115bd 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -97,7 +97,7 @@ Background::Background() : _priorityLayer(0), _points2(0), _data(0) {
 }
 
 Background::~Background() {
-	if(_data) {
+	if (_data) {
 		delete _data;
 	}
 
@@ -125,7 +125,7 @@ bool Background::load(byte *dataStart, uint32 size) {
 	stream.seek(0x308);
 
 	uint32 tilemapOffset = 0x324;
-	for(int i=0;i< 3;i++) {
+	for (int i=0;i< 3;i++) {
 		_tileMap[i].w = stream.readUint16LE();
 		_tileMap[i].h = stream.readUint16LE();
 		_tileMap[i].size = stream.readUint32LE();
@@ -156,7 +156,7 @@ bool Background::load(byte *dataStart, uint32 size) {
 	debug("Tiles: %X", tilesOffset);
 	debug("tileIndexOffset: %d", _tileMap[0].tileIndexOffset);
 
-	for(int i = 0; i < 3; i++) {
+	for (int i = 0; i < 3; i++) {
 		_layerSurface[i] = initGfxLayer(_tileMap[i]);
 		loadGfxLayer(_layerSurface[i], _tileMap[i], _tileDataOffset);
 	}
@@ -186,8 +186,8 @@ Graphics::Surface *Background::initGfxLayer(TileMap &tileMap) {
 }
 
 void Background::loadGfxLayer(Graphics::Surface *surface, TileMap &tileMap, byte *tiles) {
-	for(int y = 0; y < tileMap.h; y++) {
-		for(int x = 0; x < tileMap.w; x++) {
+	for (int y = 0; y < tileMap.h; y++) {
+		for (int x = 0; x < tileMap.w; x++) {
 			uint16 idx = READ_LE_UINT16(&tileMap.map[(y * tileMap.w + x) * 2]) + tileMap.tileIndexOffset;
 			//debug("tileIdx: %d", idx);
 			drawTileToSurface(surface, _palette, tiles + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
@@ -198,8 +198,8 @@ void Background::loadGfxLayer(Graphics::Surface *surface, TileMap &tileMap, byte
 void drawTileToSurface(Graphics::Surface *surface, byte *palette, byte *tile, uint32 x, uint32 y) {
 	byte *pixels = (byte *)surface->getPixels();
 	if (surface->format.bpp() == 16) {
-		for(int ty = 0; ty < TILE_HEIGHT; ty++) {
-			for(int tx = 0; tx < TILE_WIDTH; tx++) {
+		for (int ty = 0; ty < TILE_HEIGHT; ty++) {
+			for (int tx = 0; tx < TILE_WIDTH; tx++) {
 				uint32 cidx = *tile;
 				uint32 offset = (y + ty) * surface->pitch + (x + tx) * 2;
 				pixels[offset] = palette[cidx * 2];
@@ -239,8 +239,8 @@ int16 Background::getPriorityAtPoint(Common::Point pos) {
 }
 
 void Background::overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h) {
-	for(int i = 0; i < h; i++ ) {
-		for(int j = 0; j < w; j++ ) {
+	for (int i = 0; i < h; i++ ) {
+		for (int j = 0; j < w; j++ ) {
 			int16 idx = READ_LE_UINT16(data) + _tileMap[layerNum].tileIndexOffset;
 			drawTileToSurface(_layerSurface[layerNum],
 					_palette,
@@ -255,8 +255,8 @@ void Background::overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int
 void Background::restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h) {
 	int16 tmw = x + w;
 	int16 tmh = y + h;
-	for(int y = 0; y < tmh; y++) {
-		for(int x = 0; x < tmw; x++) {
+	for (int y = 0; y < tmh; y++) {
+		for (int x = 0; x < tmw; x++) {
 			uint16 idx = READ_LE_UINT16(&_tileMap[layerNum].map[(y * _tileMap[layerNum].w + x) * 2]) + _tileMap[layerNum].tileIndexOffset;
 			//debug("tileIdx: %d", idx);
 			drawTileToSurface(_layerSurface[layerNum], _palette, _tileDataOffset + idx * 0x100, x * TILE_WIDTH, y * TILE_HEIGHT);
diff --git a/engines/dragons/bag.cpp b/engines/dragons/bag.cpp
index 3b79568b1b..c548a52d96 100644
--- a/engines/dragons/bag.cpp
+++ b/engines/dragons/bag.cpp
@@ -87,8 +87,8 @@ void Bag::load(BigfileArchive *bigFileArchive) {
 	Graphics::PixelFormat pixelFormat16(2, 5, 5, 5, 1, 10, 5, 0, 15); //TODO move this to a better location.
 	_surface->create(320, 200, pixelFormat16);
 
-	for(int y = 0; y < TILEMAP_HEIGHT; y++) {
-		for(int x = 0; x < TILEMAP_WIDTH; x++) {
+	for (int y = 0; y < TILEMAP_HEIGHT; y++) {
+		for (int x = 0; x < TILEMAP_WIDTH; x++) {
 			uint16 idx = READ_LE_UINT16(&tilemap[(y * TILEMAP_WIDTH + x) * 2]);
 			//debug("tileIdx: %d", idx);
 			drawTileToSurface(_surface, pal, tiles + idx * 0x100, x * 32, y * 8);
diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
index 03b9e5cdd0..c012d7d138 100644
--- a/engines/dragons/bigfile.cpp
+++ b/engines/dragons/bigfile.cpp
@@ -610,7 +610,7 @@ FileInfo fileInfo[TOTAL_FILES] = {
 };
 
 uint32 getResourceId(const char *filename) {
-	for(uint32 i=0; i < TOTAL_FILES; i++) {
+	for (uint32 i=0; i < TOTAL_FILES; i++) {
 		if (scumm_stricmp(fileInfo[i].filename, filename) == 0) {
 			return i;
 		}
diff --git a/engines/dragons/credits.cpp b/engines/dragons/credits.cpp
index 19f28ef986..87c05c303e 100644
--- a/engines/dragons/credits.cpp
+++ b/engines/dragons/credits.cpp
@@ -57,7 +57,7 @@ bool Credits::isRunning() {
 }
 
 void Credits::draw() {
-	if(_running) {
+	if (_running) {
 		_vm->_screen->copyRectToSurface8bppWrappedY(*_surface, _vm->_screen->getPalette(2), _yOffset);
 	}
 }
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 20f8796642..33e40d7afb 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -205,7 +205,7 @@ int16 Cursor::updateIniFromScene() {
 	int16 cursorTileY = cursorY / 8;
 	int16 data_80072890_orig = data_80072890;
 	int16 data_800728b0_cursor_seqID_orig = data_800728b0_cursor_seqID;
-	for(int i=0;i <_vm->_dragonINIResource->totalRecords(); i++) {
+	for (int i=0;i <_vm->_dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId != _vm->_scene->getSceneId()) {
 			// 0x80028be4
@@ -246,7 +246,7 @@ int16 Cursor::updateIniFromScene() {
 				if (ini->field_1a_flags_maybe & 0x800) {
 					data_80072890 = cursorOverIni;
 					uint32 newSeqId = 1;
-					for(int idx=0; idx < 5; idx++) {
+					for (int idx=0; idx < 5; idx++) {
 						data_800728b0_cursor_seqID = idx;
 						byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
 						ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
@@ -281,7 +281,7 @@ int16 Cursor::updateIniFromScene() {
 //				local_48 = dragon_Obd_Offset + *(int *)(uVar16 * 8 + dragon_Opt_Offset + -8) + 8;
 //				local_44 = read_int32();
 //				local_44 = local_44 + local_48;
-				if(executeScript(scriptOpCall, 0)) {
+				if (executeScript(scriptOpCall, 0)) {
 					_iniUnderCursor = cursorOverIni;
 					data_80072890 = data_80072890_orig;
 					data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 737d5fe325..1649740cc9 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -641,7 +641,7 @@ void CutScene::knightsSavedBackAtCastle() {
 	//DisableVSyncEvent();
 //	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
 	//EnableVSyncEvent();
-	if(isFlag0x10Set) {
+	if (isFlag0x10Set) {
 		_vm->setFlags(ENGINE_FLAG_10);
 	}
 	_vm->clearFlags(ENGINE_FLAG_20000);
@@ -731,7 +731,7 @@ void CutScene::flameReturnsCutScene() {
 //	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
 //	EnableVSyncEvent();
 	_vm->clearFlags(ENGINE_FLAG_20000);
-	if(engineFlag10Set) {
+	if (engineFlag10Set) {
 		_vm->setFlags(ENGINE_FLAG_10);
 	}
 	_vm->_dragonINIResource->setFlickerRecord(uVar1);
@@ -811,7 +811,7 @@ void CutScene::knightsSavedAgain() {
 //	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
 //	EnableVSyncEvent();
 	_vm->clearFlags(ENGINE_FLAG_20000);
-	if(engineFlag10Set) {
+	if (engineFlag10Set) {
 		_vm->setFlags(ENGINE_FLAG_10);
 	}
 	_vm->_dragonINIResource->setFlickerRecord(flicker);
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index 3e12b9beec..ddc6f12a6e 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -31,7 +31,7 @@ namespace Dragons {
 Properties::Properties(uint count)
 		: _count(count) {
 	_properties = (byte *)malloc(getSize());
-	if(!_properties) {
+	if (!_properties) {
 		error("Failed to allocate mem for properties");
 	}
 	memset(_properties, 0, getSize());
@@ -89,7 +89,7 @@ void Properties::save(uint numberToWrite, Common::WriteStream *out) {
 void Properties::print(char *prefix) {
 	char *str = new char[_count + 1];
 	int i = 0;
-	for(; i < _count; i++) {
+	for (; i < _count; i++) {
 		str[i] = get(i) ? '1' : '0';
 	}
 	str[i] = 0;
diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
index 3fa1fc405e..5c91972830 100644
--- a/engines/dragons/dragonimg.cpp
+++ b/engines/dragons/dragonimg.cpp
@@ -38,7 +38,7 @@ DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
 
 	_imgObjects = new IMG[_count];
 
-	for(int i=0; i < _count; i++) {
+	for (int i=0; i < _count; i++) {
 		imgReadStream->seek(iptReadStream->readUint32LE());
 		_imgObjects[i].x = imgReadStream->readUint16LE();
 		_imgObjects[i].y = imgReadStream->readUint16LE();
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index 9fd43f2397..10a8888de1 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -40,7 +40,7 @@ void DragonINIResource::reset() {
 		_dragonINI = new DragonINI[_count];
 	}
 
-	for(int i=0; i < _count; i++) {
+	for (int i=0; i < _count; i++) {
 		_dragonINI[i].id = (uint16)i;
 		_dragonINI[i].iptIndex_maybe = readStream->readSint16LE();
 		_dragonINI[i].field_2 = readStream->readSint16LE();
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
index d6ffb29c3f..12bcdc7dc2 100644
--- a/engines/dragons/dragonrms.cpp
+++ b/engines/dragons/dragonrms.cpp
@@ -37,7 +37,7 @@ DragonRMS::DragonRMS(BigfileArchive *bigfileArchive, DragonOBD *dragonOBD) : _dr
 
 	_rmsObjects = new RMS[_count];
 
-	for(int i=0; i < _count; i++) {
+	for (int i=0; i < _count; i++) {
 		_rmsObjects[i]._field0 = readStream->readSint32LE();
 		readStream->read(_rmsObjects[i]._sceneName, 4);
 		_rmsObjects[i]._obdOffset = readStream->readSint32LE();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 75c6423244..2b8af2e45c 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -133,53 +133,53 @@ void DragonsEngine::updateEvents() {
 				_rightMouseButtonUp = true;
 				break;
 			case Common::EVENT_KEYUP:
-				if (event.kbd.keycode == Common::KeyCode::KEYCODE_i) {
+				if (event.kbd.keycode == Common::KEYCODE_i) {
 					_iKeyUp = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_DOWN) {
+				} else if (event.kbd.keycode == Common::KEYCODE_DOWN) {
 					_downKeyUp = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_UP) {
+				} else if (event.kbd.keycode == Common::KEYCODE_UP) {
 					_upKeyUp = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RETURN ||
-							event.kbd.keycode == Common::KeyCode::KEYCODE_KP_ENTER) {
+				} else if (event.kbd.keycode == Common::KEYCODE_RETURN ||
+							event.kbd.keycode == Common::KEYCODE_KP_ENTER) {
 					_enterKeyUp = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_LEFT) {
+				} else if (event.kbd.keycode == Common::KEYCODE_LEFT) {
 					_leftKeyUp = true;
 					_leftKeyDown = false;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RIGHT) {
+				} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) {
 					_rightKeyUp = true;
 					_rightKeyDown = false;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_w) {
+				} else if (event.kbd.keycode == Common::KEYCODE_w) {
 					_wKeyDown = false;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_a) {
+				} else if (event.kbd.keycode == Common::KEYCODE_a) {
 					_aKeyDown = false;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_s) {
+				} else if (event.kbd.keycode == Common::KEYCODE_s) {
 					_sKeyDown = false;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_d) {
+				} else if (event.kbd.keycode == Common::KEYCODE_d) {
 					_dKeyDown = false;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_o) {
+				} else if (event.kbd.keycode == Common::KEYCODE_o) {
 					_oKeyDown = false;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_p) {
+				} else if (event.kbd.keycode == Common::KEYCODE_p) {
 					_pKeyDown = false;
 				}
 				break;
 			case Common::EVENT_KEYDOWN:
-				if (event.kbd.keycode == Common::KeyCode::KEYCODE_LEFT) {
+				if (event.kbd.keycode == Common::KEYCODE_LEFT) {
 					_leftKeyDown = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_RIGHT) {
+				} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) {
 					_rightKeyDown = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_w) {
+				} else if (event.kbd.keycode == Common::KEYCODE_w) {
 					_wKeyDown = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_a) {
+				} else if (event.kbd.keycode == Common::KEYCODE_a) {
 					_aKeyDown = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_s) {
+				} else if (event.kbd.keycode == Common::KEYCODE_s) {
 					_sKeyDown = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_d) {
+				} else if (event.kbd.keycode == Common::KEYCODE_d) {
 					_dKeyDown = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_o) {
+				} else if (event.kbd.keycode == Common::KEYCODE_o) {
 					_oKeyDown = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_p) {
+				} else if (event.kbd.keycode == Common::KEYCODE_p) {
 					_pKeyDown = true;
-				} else if (event.kbd.keycode == Common::KeyCode::KEYCODE_TAB) {
+				} else if (event.kbd.keycode == Common::KEYCODE_TAB) {
 					_debugMode = !_debugMode;
 				}
 				break;
@@ -191,7 +191,7 @@ void DragonsEngine::updateEvents() {
 
 Common::Error DragonsEngine::run() {
 	_screen = new Screen();
-	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
+	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::EN_ANY);
 	_talk = new Talk(this, _bigfileArchive);
 	_dragonFLG = new DragonFLG(_bigfileArchive);
 	_dragonIMG = new DragonIMG(_bigfileArchive);
@@ -245,7 +245,7 @@ uint16 DragonsEngine::ipt_img_file_related()
 	int16 tileX = flicker->actor->x_pos / 32;
 	int16 tileY = flicker->actor->y_pos / 8;
 
-	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		ini = getINI(i);
 		if ((ini->sceneId == getCurrentSceneId()) && (ini->field_1a_flags_maybe == 0)) {
 			IMG *img = _dragonIMG->getIMG(ini->field_2);
@@ -273,7 +273,7 @@ void DragonsEngine::gameLoop()
 	setFlags(ENGINE_FLAG_8);
 	actorId = 0;
 
-	while(!shouldQuit()) {
+	while (!shouldQuit()) {
 		_scene->draw();
 		_screen->updateScreen();
 		wait();
@@ -318,7 +318,7 @@ void DragonsEngine::gameLoop()
 				byte *obd = _dragonOBD->getFromOpt(actorId_00 - 1);
 				ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
-				if(_scriptOpcodes->runScript4(scriptOpCall)) {
+				if (_scriptOpcodes->runScript4(scriptOpCall)) {
 					scriptOpCall._codeEnd = scriptOpCall._code + 4 + READ_LE_UINT16(scriptOpCall._code + 2);
 					scriptOpCall._code += 4;
 					_scriptOpcodes->runScript(scriptOpCall);
@@ -444,7 +444,7 @@ void DragonsEngine::gameLoop()
 									}
 								}
 								else {
-									if(_inventory->addItem(_cursor->iniItemInHand)) {
+									if (_inventory->addItem(_cursor->iniItemInHand)) {
 										_cursor->_sequenceID = 1;
 										waitForFrames(1);
 										_cursor->iniItemInHand = 0;
@@ -1273,7 +1273,7 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 
 	_inventory->loadInventoryItemsFromSave();
 
-	if(getINI(0)->sceneId == 0) {
+	if (getINI(0)->sceneId == 0) {
 		getINI(0)->sceneId = sceneId; //TODO
 	} else {
 		_scene->setSceneId(getINI(0)->sceneId);
@@ -1291,7 +1291,7 @@ void DragonsEngine::reset() {
 	videoFlags = 0;
 	data_800633fa = 0;
 
-	for(int i = 0; i < 8; i++) {
+	for (int i = 0; i < 8; i++) {
 		_paletteCyclingTbl[i].paletteType = 0;
 		_paletteCyclingTbl[i].startOffset = 0;
 		_paletteCyclingTbl[i].endOffset = 0;
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index d612089f67..6f4cb30a6e 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -205,7 +205,7 @@ void FontManager::updatePalette() {
 //	if (( != 0 && ((engine_flags_maybe & 0x200) != 0))) {
 	uint16 *palette_f2_font_maybe = (uint16 *)_screen->getPalette(2);
 	uint16 cursor3 = 0x14a5 | 0x8000;
-	if(_vm->isFlagSet(ENGINE_FLAG_200)) {
+	if (_vm->isFlagSet(ENGINE_FLAG_200)) {
 		if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
 			updatePalEntry(palette_f2_font_maybe, 16, cursor3);
 		} else {
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index ec42bcae70..537a472b4f 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -90,7 +90,7 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_old_showing_value = 0;
 	_bag = bag;
 
-	for(int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
+	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		actorManager->loadActor(0, i + ACTOR_INVENTORY_OFFSET); // TODO need to share resource between inventory item actors.
 	}
 
@@ -166,7 +166,7 @@ void Inventory::openInventory() {
 
 	//TODO 0x800310e0 update cursor position.
 
-	for(int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
+	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		Actor *item = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 
 		item->x_pos = item->_walkDestX = invXPosTable[i] + 0x10;
@@ -252,7 +252,7 @@ void Inventory::closeInventory() {
 }
 
 void Inventory::draw() {
-	if(_bag) {
+	if (_bag) {
 		_bag->draw();
 	}
 }
@@ -390,7 +390,7 @@ bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 
 bool Inventory::clearItem(uint16 iniId) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
-		if(inventoryItemTbl[i] == iniId) {
+		if (inventoryItemTbl[i] == iniId) {
 			inventoryItemTbl[i] = 0;
 		}
 	}
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 6e467753b4..ce37357d10 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -886,7 +886,7 @@ void Minigame1::run() {
 			_vm->getINI(DAT_80063a40 - 1)->actor->clearFlag(ACTOR_FLAG_100);
 			break;
 		}
-	} while( true );
+	} while ( true );
 
 	//TODO callMaybeResetData();
 	flickerActor->updateSequence(0x15);
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index f489c67e00..40a929f39a 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -765,7 +765,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			}
 		}
 		
-	} while( true );
+	} while ( true );
 
 }
 
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index f874013739..6bf3e8db55 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -351,7 +351,7 @@ void Minigame3::run() {
 	tearBlinkActorTbl[0]->updateSequence(0);
 	tearBlinkActorTbl[1]->updateSequence(1);
 	local_1c2 = 0;
-	while( true ) {
+	while ( true ) {
 		_vm->waitForFrames(1);
 		switch(currentState) {
 			case 1:
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 2855ea8c34..1ee2cac6c7 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -198,7 +198,7 @@ uint16 Minigame4::runDanceBattle() {
 	resetActors();
 	actorTalk(bruteActor,0x3321, 0x4B6A);
 	currentStep = 0;
-	while( true ) {
+	while ( true ) {
 		if (0x11 < currentStep) {
 			_vm->_talk->loadText(0x4C0C, auStack2192, 1000);
 			_vm->_talk->displayDialogAroundPoint(auStack2192, 0x27,0xc,0x3321,0,0x4C0C);
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index 88c37dcaed..f52b1508bf 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -166,8 +166,8 @@ void Minigame5::run() {
 	currentState = 1;
 	local_66 = 0;
 	local_50 = 0;
-	while( true ) {
-		while( true ) {
+	while ( true ) {
+		while ( true ) {
 			do {
 				_vm->waitForFrames(1);
 				if ((uint)currentState - 1 < 8) {
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 993060d929..ea8d6296a3 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -87,7 +87,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_2 | Dragons::ENGINE_UNK1_FLAG_8);
 
-	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		ini->field_10 = -1;
 		ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
@@ -157,7 +157,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 			stagePalette[i * 2 + 1] = cursorPalette[(i-0xc0) * 2 + 1];
 		}
 	}
-	for(int i = 1; i < 0x100; i ++) {
+	for (int i = 1; i < 0x100; i ++) {
 		byte *stagePalette = _stage->getPalette();
 		uint16 c = READ_LE_INT16(stagePalette + i * 2);
 		if ((c & 0x7fff) == 0) {
@@ -166,7 +166,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	}
 	_screen->loadPalette(0, _stage->getPalette());
 
-	for(int i = 1; i < 0x100; i ++) {
+	for (int i = 1; i < 0x100; i ++) {
 		byte *stagePalette = _stage->getPalette();
 		uint16 c = READ_LE_INT16(stagePalette + i * 2);
 		if ((c & 0x7fff) == 0) {
@@ -219,7 +219,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_vm->data_800633fc = 0;
 	// TODO 0x8002fff0
 
-	for(int i=0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		if (ini->sceneId == sceneIdStripped) {
 			if (ini->field_1a_flags_maybe & 1) {
@@ -339,7 +339,7 @@ void Scene::draw() {
 	Common::Rect rect(_camera.x, _camera.y, _camera.x + 320, _camera.y + 200);
 	_vm->_screen->clearScreen();
 
-	for(uint16 priority = 1; priority < 16; priority++) {
+	for (uint16 priority = 1; priority < 16; priority++) {
 		if (priority == 7 && _vm->isFlagSet(ENGINE_FLAG_200)) {
 			_vm->_fontManager->updatePalette();
 		}
@@ -483,7 +483,7 @@ void Scene::drawActorNumber(int16 x, int16 y, uint16 actorId) {
 
 	sprintf(text8, "%d", actorId);
 
-	for(int i = 0; i < strlen(text8); i++) {
+	for (int i = 0; i < strlen(text8); i++) {
 		text[i] = text8[i];
 	}
 	_vm->_fontManager->addText(x, y, text, strlen(text8), 1);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 10c1ac33bb..cbc769abde 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -327,7 +327,7 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	_vm->_cursor->_iniUnderCursor = field4;
 	_vm->_cursor->_sequenceID = 0;
 
-	for(int16 i = field2 >> 1; i != 0; i = i >> 1) {
+	for (int16 i = field2 >> 1; i != 0; i = i >> 1) {
 		_vm->_cursor->_sequenceID++;
 	}
 
@@ -472,7 +472,7 @@ bool ScriptOpcodes::evaluateExpression(ScriptOpCall &scriptOpCall) {
 	int16 t2 = 0;
 	int16 t0 = 0;
 
-	for(;;) {
+	for (;;) {
 		byte value = 0;
 		if (*codePtrOffsetA & 1) {
 			uint32 propId = READ_LE_UINT16(codePtrOffset2) * 8 + READ_LE_UINT16(codePtrOffsetA - 6);
@@ -625,7 +625,7 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
 		ini->actor->startWalk(point.x, point.y, isFlicker ? 0 : 1);
 
-		if(s3 == 0) {
+		if (s3 == 0) {
 			while (ini->actor->_flags & Dragons::ACTOR_FLAG_10) {
 				_vm->waitForFrames(1);
 			}
@@ -678,7 +678,7 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
 		ini->actor->startWalk(field8, fieldA, isFlicker ? 0 : 1);
 
-		if(s3 == 0) {
+		if (s3 == 0) {
 			while (ini->actor->_flags & Dragons::ACTOR_FLAG_10) {
 				_vm->waitForFrames(1);
 			}
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index a3683d2e7e..5e5ffc77a7 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -200,7 +200,7 @@ void SequenceOpcodes::opSetField7a(Actor *actor, OpCall &opCall) {
 }
 
 void SequenceOpcodes::opUpdateFlags(Actor *actor, OpCall &opCall) {
-	if(actor->isFlagSet(ACTOR_FLAG_1000)) {
+	if (actor->isFlagSet(ACTOR_FLAG_1000)) {
 		actor->setFlag(ACTOR_FLAG_4);
 	}
 	updateReturn(opCall, 0);
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index 674c1d6a58..0fb1550a62 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -139,7 +139,7 @@ bool SoundManager::getSpeechLocation(uint32 talkId, struct SpeechLocation *locat
 
 void SoundManager::PauseCDMusic() {
 	//TODO check PauseCDMusic() to see if we need any more logic.
-	if(isSpeechPlaying()) {
+	if (isSpeechPlaying()) {
 		_vm->_mixer->stopHandle(_speechHandle);
 		_vm->clearFlags(ENGINE_FLAG_8000);
 	}
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 7ddeb23c84..5de370b9f6 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -514,10 +514,10 @@ void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialog
 }
 
 void Talk::copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength) {
-	for(int i = 0; i < destBufferLength - 1; i++) {
+	for (int i = 0; i < destBufferLength - 1; i++) {
 		destBuffer[i] = READ_LE_UINT16(src);
 		src += 2;
-		if(destBuffer[i] == 0) {
+		if (destBuffer[i] == 0) {
 			return;
 		}
 	}
@@ -527,7 +527,7 @@ void Talk::copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLeng
 
 uint32 Talk::wideStrLen(uint16 *text) {
 	int i = 0;
-	while(text[i] != 0) {
+	while (text[i] != 0) {
 		i++;
 	}
 	return i;


Commit: 47f7d0aed56244b26c27ea84e4f97c75935bccb6
    https://github.com/scummvm/scummvm/commit/47f7d0aed56244b26c27ea84e4f97c75935bccb6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Add size to const array data

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 75c0bcf8fb..bb9a5ebe64 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -222,7 +222,7 @@ uint32 calcDistance(int32 x1, int32 y1, int32 x2, int32 y2) {
 }
 
 bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
-	static const int kCosTbl[] = {
+	static const int kCosTbl[40] = {
 			// cos table
 			256, 251, 236, 212, 181, 142, 97, 49,
 			0, -49, -97, -142, -181, -212, -236, -251,
@@ -230,10 +230,10 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 			0, 49, 97, 142, 181, 212, 236, 251,
 			11, 0, 0, 0, 0, 0, 0, 0
 	};
-	static const int kAdjustXTbl[] = {
+	static const int kAdjustXTbl[8] = {
 			1, -1, 0, 0, 1, -1, 1, -1
 	};
-	static const int kAdjustYTbl[] = {
+	static const int kAdjustYTbl[8] = {
 			0, 0, 1, -1, 1, 1, -1, -1
 	};
 
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 1ee2cac6c7..1fb30cfd6b 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -224,11 +224,11 @@ uint16 Minigame4::runDanceBattle() {
 	return 1;
 }
 
-const static uint16 xDancePosTbl[] = { 0xAC, 0xB5, 0xBC, 0xB3, 0xB4, 0xAF };
-const static uint16 yDancePosTbl[] = { 0x1C, 0x23, 0x1A, 0x14, 0x12, 0xF };
+const static uint16 xDancePosTbl[6] = { 0xAC, 0xB5, 0xBC, 0xB3, 0xB4, 0xAF };
+const static uint16 yDancePosTbl[6] = { 0x1C, 0x23, 0x1A, 0x14, 0x12, 0xF };
 
-const static uint16 uint16_t_ARRAY_80090400[] = { 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
-const static uint16 uint16_t_ARRAY_800903e8[] = { 1, 2, 3, 4, 5, 6 };
+const static uint16 uint16_t_ARRAY_80090400[6] = { 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
+const static uint16 uint16_t_ARRAY_800903e8[6] = { 1, 2, 3, 4, 5, 6 };
 
 uint16 Minigame4::singleDanceRound(uint16 currentDancePosition, uint16 duration) {
 	DAT_80090438->x_pos = xDancePosTbl[(uint)currentDancePosition];
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 1b25e2205f..2bbbb460f5 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -1430,7 +1430,7 @@ void shakeScreenUpdateFunction() {
 }
 
 void ladyOfTheLakeCapturedUpdateFunction() {
-	const uint32 dialogTbl[] = {
+	const uint32 dialogTbl[3] = {
 			0x490C8, 0x490FC, 0x4913A
 	};
 	static int ladyofLakeCountdownTimer = 0x12c;
@@ -1474,7 +1474,7 @@ void castleFogUpdateFunction() {
 }
 
 void menInMinesSceneUpdateFunction() {
-	static const uint32 sceneUpdateFuncDialogTbl[] = {
+	const uint32 sceneUpdateFuncDialogTbl[4] = {
 			0x4590A, 0x45994, 0x459F4, 0x45A60
 	};
 	DragonsEngine *vm = getEngine();
@@ -1505,16 +1505,16 @@ void menInMinesSceneUpdateFunction() {
 
 void monksAtBarSceneUpdateFunction() {
 	static uint8 monksAtBarCurrentState = 0;
-	static const uint32 sceneUpdateFuncDialogTbl[] = {
+	static const uint32 sceneUpdateFuncDialogTbl[6] = {
 			0x37800, 0x37854, 0x378CA,
 			0x39152, 0x3919A, 0x3922C
 	};
-	static const uint32 barKeeperTextIdTbl[] = {
+	static const uint32 barKeeperTextIdTbl[10] = {
 			0x38C68, 0x38CE2, 0x38D4E, 0x38CE2,
 			0x38DC2, 0x38E0C, 0x38C68, 0x38E5C,
 			0x38ED0, 0x38CE2
 	};
-	static const uint32 DAT_800832f0[] = {0x38F2A, 0x39000, 0x39084, 0x390E8};
+	static const uint32 DAT_800832f0[4] = {0x38F2A, 0x39000, 0x39084, 0x390E8};
 
 	DragonsEngine *vm = getEngine();
 	Actor *barKeeper = vm->_dragonINIResource->getRecord(0x1e7)->actor;
@@ -1695,7 +1695,7 @@ void monksAtBarSceneUpdateFunction() {
 }
 
 void flameEscapeSceneUpdateFunction() {
-	static const uint32 dialogTbl[] = {
+	static const uint32 dialogTbl[6] = {
 			0x10458, 0x104A0, 0x10500, 0x10500, 0x10550, 0x10578 //TODO support multiple languages
 	};
 	static bool DAT_800634c0 = false;
@@ -1767,7 +1767,7 @@ void caveOfDilemmaUpdateFunction() {
 }
 
 void moatDrainedSceneUpdateFunction() {
-	static const uint32 moatDrainedTextIdTbl[] {
+	static const uint32 moatDrainedTextIdTbl[4] {
 			0x3C97A, 0x3C9AC, 0x3C9F8, 0x3CA48
 	};
 	static uint16 moatDrainedUpdateCounter = 0;


Commit: f32a199876998b6a03f854d9dffa41624142d4e9
    https://github.com/scummvm/scummvm/commit/f32a199876998b6a03f854d9dffa41624142d4e9
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed formatting on includes

Changed paths:
    engines/dragons/VabSound.cpp
    engines/dragons/VabSound.h
    engines/dragons/actor.cpp
    engines/dragons/bag.cpp
    engines/dragons/bag.h
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonimg.cpp
    engines/dragons/dragonini.cpp
    engines/dragons/dragonrms.cpp
    engines/dragons/font.cpp
    engines/dragons/font.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
index 9a77d0d789..a3cf685fe5 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/VabSound.cpp
@@ -19,11 +19,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/textconsole.h>
-#include <common/debug.h>
-#include <audio/decoders/xa.h>
-#include <audio/audiostream.h>
-#include <audio/mixer.h>
+#include "common/textconsole.h"
+#include "common/debug.h"
+#include "audio/decoders/xa.h"
+#include "audio/audiostream.h"
+#include "audio/mixer.h"
 #include "common/memstream.h"
 #include "dragons/VabSound.h"
 #include "dragons/dragons.h"
diff --git a/engines/dragons/VabSound.h b/engines/dragons/VabSound.h
index 901e9e18e0..7b82da36f0 100644
--- a/engines/dragons/VabSound.h
+++ b/engines/dragons/VabSound.h
@@ -23,7 +23,7 @@
 #ifndef DRAGONS_VABSOUND_H
 #define DRAGONS_VABSOUND_H
 
-#include <common/scummsys.h>
+#include "common/scummsys.h"
 
 namespace Common {
 	class SeekableReadStream;
diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index bb9a5ebe64..bdf22b22c4 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/debug.h>
+#include "common/debug.h"
 #include "dragons/dragons.h"
 #include "dragons/dragonini.h"
 #include "dragons/actorresource.h"
diff --git a/engines/dragons/bag.cpp b/engines/dragons/bag.cpp
index c548a52d96..803b881feb 100644
--- a/engines/dragons/bag.cpp
+++ b/engines/dragons/bag.cpp
@@ -20,7 +20,7 @@
  *
  */
 
-#include <common/memstream.h>
+#include "common/memstream.h"
 #include "dragons/bigfile.h"
 #include "dragons/screen.h"
 #include "dragons/bag.h"
diff --git a/engines/dragons/bag.h b/engines/dragons/bag.h
index 5ff1663e83..e198c5f407 100644
--- a/engines/dragons/bag.h
+++ b/engines/dragons/bag.h
@@ -23,8 +23,8 @@
 #ifndef DRAGONS_BAG_H
 #define DRAGONS_BAG_H
 
-#include <graphics/surface.h>
-#include <common/rect.h>
+#include "graphics/surface.h"
+#include "common/rect.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index ddc6f12a6e..a012a285e4 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/debug.h>
+#include "common/debug.h"
 #include "dragons/dragonflg.h"
 #include "dragons/bigfile.h"
 
diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
index 5c91972830..be9a364012 100644
--- a/engines/dragons/dragonimg.cpp
+++ b/engines/dragons/dragonimg.cpp
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/memstream.h>
+#include "common/memstream.h"
 #include "dragons/dragonimg.h"
 #include "dragons/bigfile.h"
 
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index 10a8888de1..25a6ea3305 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/debug.h>
+#include "common/debug.h"
 #include "common/memstream.h"
 #include "dragons/dragonini.h"
 
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
index 12bcdc7dc2..18301779be 100644
--- a/engines/dragons/dragonrms.cpp
+++ b/engines/dragons/dragonrms.cpp
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/memstream.h>
+#include "common/memstream.h"
 #include "dragons/dragonrms.h"
 #include "dragons/dragonobd.h"
 #include "dragons/bigfile.h"
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 6f4cb30a6e..0cccf54aa2 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include <common/memstream.h>
-#include <common/textconsole.h>
+#include "common/memstream.h"
+#include "common/textconsole.h"
 #include "dragons/bigfile.h"
 #include "dragons/cursor.h"
 #include "dragons/font.h"
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index b6e2521085..48b406f36e 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -22,10 +22,10 @@
 #ifndef DRAGONS_FONT_H
 #define DRAGONS_FONT_H
 
-#include <common/scummsys.h>
-#include <common/stream.h>
-#include <graphics/surface.h>
-#include <common/rect.h>
+#include "common/scummsys.h"
+#include "common/stream.h"
+#include "graphics/surface.h"
+#include "common/rect.h"
 
 namespace Dragons {
 
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 5de370b9f6..a031e47f68 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -20,7 +20,7 @@
  *
  */
 
-#include <common/debug.h>
+#include "common/debug.h"
 #include "dragons/bigfile.h"
 #include "dragons/actor.h"
 #include "dragons/cursor.h"
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index a049025f3c..5e12c025d7 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -23,7 +23,7 @@
 #ifndef DRAGONS_TALK_H
 #define DRAGONS_TALK_H
 
-#include <common/str.h>
+#include "common/str.h"
 #include "dragons/scriptopcodes.h"
 
 namespace Dragons {


Commit: 11eee8190f05a23de441c488318eee5771bb1e2b
    https://github.com/scummvm/scummvm/commit/11eee8190f05a23de441c488318eee5771bb1e2b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Remove usages of auto keyword

Changed paths:
    engines/dragons/VabSound.cpp
    engines/dragons/sound.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
index a3cf685fe5..dbeb0ab3fa 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/VabSound.cpp
@@ -32,7 +32,7 @@ namespace Dragons {
 	VabSound::VabSound(Common::SeekableReadStream *msfData, const DragonsEngine *_vm): _toneAttrs(NULL), _vbData(NULL) {
 		loadHeader(msfData);
 
-		auto dataSize = msfData->size() - msfData->pos();
+		int32 dataSize = msfData->size() - msfData->pos();
 		_vbData = new byte[dataSize];
 		msfData->read(_vbData, dataSize);
 
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index 0fb1550a62..d144733551 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -90,7 +90,7 @@ void SoundManager::playSpeech(uint32 textIndex) {
 	}
 	CdIntToPos_0(speechLocation.sectorStart * 32);
 	fd->seek(((speechLocation.sectorStart * 32) + speechLocation.startOffset) * RAW_CD_SECTOR_SIZE);
-	PSXAudioTrack *_audioTrack = new PSXAudioTrack(fd, Audio::Mixer::SoundType::kSpeechSoundType);
+	PSXAudioTrack *_audioTrack = new PSXAudioTrack(fd, Audio::Mixer::kSpeechSoundType);
 	for (int i = 0x0; i < speechLocation.sectorEnd - speechLocation.sectorStart;i++) {
 		fd->seek(((speechLocation.sectorStart * 32) + speechLocation.startOffset + i * 32) * RAW_CD_SECTOR_SIZE);
 		_audioTrack->queueAudioFromSector(fd);
@@ -340,11 +340,11 @@ void SoundManager::loadMusAndGlob() {
 VabSound * SoundManager::loadVab(const char *headerFilename, const char *bodyFilename) {
 	uint32 headSize, bodySize;
 
-	auto headData = _bigFileArchive->load(headerFilename, headSize);
-	auto bodyData = _bigFileArchive->load(bodyFilename, bodySize);
+	byte *headData = _bigFileArchive->load(headerFilename, headSize);
+	byte *bodyData = _bigFileArchive->load(bodyFilename, bodySize);
 
-	auto *headStream = new Common::MemoryReadStream(headData, headSize, DisposeAfterUse::YES);
-	auto *bodyStream = new Common::MemoryReadStream(bodyData, bodySize, DisposeAfterUse::YES);
+	Common::SeekableReadStream *headStream = new Common::MemoryReadStream(headData, headSize, DisposeAfterUse::YES);
+	Common::SeekableReadStream *bodyStream = new Common::MemoryReadStream(bodyData, bodySize, DisposeAfterUse::YES);
 
 	return new VabSound(headStream, bodyStream);
 }
@@ -374,19 +374,19 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
 	volume = _soundArr[volumeId];
 	_soundArr[volumeId] = _soundArr[volumeId] | 0x40u;      // Set bit 0x40
 
-	auto vabSound = ((soundId & 0x8000u) != 0) ? _vabGlob : _vabMusx;
+	VabSound *vabSound = ((soundId & 0x8000u) != 0) ? _vabGlob : _vabMusx;
 
 	// TODO: CdVolume!
-	auto cdVolume = 1;
-	auto newVolume = cdVolume * volume;
+	int cdVolume = 1;
+	int newVolume = cdVolume * volume;
 	if (newVolume < 0) {
 		newVolume += 0xf;
 	}
 
-	auto realId = soundId & 0x7fffu;
+	uint16 realId = soundId & 0x7fffu;
 
-	auto program = realId >> 4u;
-	auto key = ((realId & 0xfu) << 1u | 0x40u);
+	uint16 program = realId >> 4u;
+	uint16 key = ((realId & 0xfu) << 1u | 0x40u);
 
 	// TODO: Volume
 	if (isVoicePlaying(soundId)) {
@@ -402,7 +402,7 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
 void SoundManager::stopSound(uint16 soundId, uint16 volumeId) {
 	_soundArr[volumeId] = _soundArr[volumeId] & 0xbfu;      // Clear bit 0x40
 
-//	auto vabId = getVabFromSoundId(soundId);
+//	uint16 vabId = getVabFromSoundId(soundId);
 
 	stopVoicePlaying(soundId & ~0x4000u);
 }
@@ -420,7 +420,7 @@ void SoundManager::loadMsf(uint32 sceneId) {
 		uint32 msfSize;
 		byte *msfData = _bigFileArchive->load(msfFileName, msfSize);
 
-		auto *msfStream = new Common::MemoryReadStream(msfData, msfSize, DisposeAfterUse::YES);
+		Common::SeekableReadStream *msfStream = new Common::MemoryReadStream(msfData, msfSize, DisposeAfterUse::YES);
 
 		stopAllVoices();
 
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index a031e47f68..d166e2bbc9 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -69,7 +69,7 @@ void Talk::printWideText(byte *text) {
 	char buf[2000];
 	int i = 0;
 	for (; READ_LE_INT16(text) != 0 && i < 1999; i++) {
-	    auto c = *text;
+	    char c = *text;
 	    if (c < 0x20) {
 	        buf[i++] = '0';
 	        buf[i++] = 'x';


Commit: 559a96c1ca80944dce6719a6c57eaa4680e53a5d
    https://github.com/scummvm/scummvm/commit/559a96c1ca80944dce6719a6c57eaa4680e53a5d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed platform specific issues in VabSound.

Changed paths:
    engines/dragons/VabSound.cpp
    engines/dragons/VabSound.h
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
index dbeb0ab3fa..0681508bb6 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/VabSound.cpp
@@ -59,19 +59,34 @@ namespace Dragons {
 
 	void VabSound::loadHeader(Common::SeekableReadStream *vhData) {
 		vhData->seek(0);
-		vhData->read(&_header, sizeof(_header)); //TODO this is not endian safe!
+		vhData->read(&_header.magic, 4);
+		_header.version = vhData->readUint32LE();
+		_header.vabId = vhData->readUint32LE();
+		_header.waveformSize = vhData->readUint32LE();
+
+		_header.reserved0 = vhData->readUint16LE();
+		_header.numPrograms = vhData->readUint16LE();
+		_header.numTones = vhData->readUint16LE();
+		_header.numVAG = vhData->readUint16LE();
+
+		_header.masterVolume = vhData->readByte();
+		_header.masterPan = vhData->readByte();
+		_header.bankAttr1 = vhData->readByte();
+		_header.bankAttr2 = vhData->readByte();
+
+		_header.reserved1 = vhData->readUint32LE();
+
 		if (strncmp(_header.magic, "pBAV", 4) != 0) {
 			error("Invalid VAB file");
 		}
-		// TODO: is sizeof(array) the right thing to do here?
-		vhData->read(&_programAttrs, sizeof(_programAttrs));
 
-		const int numTones = 16 * _header.numPrograms;
-		_toneAttrs = new VabToneAttr[numTones];
-		vhData->read(_toneAttrs, sizeof(VabToneAttr) * numTones);
+		loadProgramAttributes(vhData);
+		loadToneAttributes(vhData);
 
 		uint16 tempOffsets[0x100];
-		vhData->read(tempOffsets, sizeof(tempOffsets));
+		for (int i = 0; i < 0x100; i++) {
+			tempOffsets[i] = vhData->readUint16LE();
+		}
 		_vagOffsets[0] = tempOffsets[0] << 3u;
 		for (int j = 1; j < 0x100; ++j) {
 			const int vagSize = tempOffsets[j] << 3u;
@@ -101,4 +116,50 @@ namespace Dragons {
 				DisposeAfterUse::YES);
 		return str;
 	}
+
+void VabSound::loadProgramAttributes(Common::SeekableReadStream *vhData) {
+	for (int i = 0; i < DRAGONS_VAB_NUM_PROG_ATTRS; i++) {
+		_programAttrs[i].tones = vhData->readByte();
+		_programAttrs[i].mvol = vhData->readByte();
+		_programAttrs[i].prior = vhData->readByte();
+		_programAttrs[i].mode = vhData->readByte();
+		_programAttrs[i].mpan = vhData->readByte();
+		_programAttrs[i].reserved0 = vhData->readByte();
+		_programAttrs[i].attr = vhData->readUint16LE();
+		_programAttrs[i].reserved1 = vhData->readUint32LE();
+		_programAttrs[i].reserved2 = vhData->readUint32LE();
+	}
+}
+
+void VabSound::loadToneAttributes(Common::SeekableReadStream *vhData) {
+	const int numTones = 16 * _header.numPrograms;
+	_toneAttrs = new VabToneAttr[numTones];
+	VabToneAttr *pVabToneAttr = _toneAttrs;
+	for (int i = 0; i < numTones; i++, pVabToneAttr++) {
+		pVabToneAttr->prior = vhData->readByte();
+		pVabToneAttr->mode = vhData->readByte();
+		pVabToneAttr->vol = vhData->readByte();
+		pVabToneAttr->pan = vhData->readByte();
+		pVabToneAttr->center = vhData->readByte();
+		pVabToneAttr->shift = vhData->readByte();
+		pVabToneAttr->min = vhData->readByte();
+		pVabToneAttr->max = vhData->readByte();
+		pVabToneAttr->vibW = vhData->readByte();
+		pVabToneAttr->vibT = vhData->readByte();
+		pVabToneAttr->porW = vhData->readByte();
+		pVabToneAttr->porT = vhData->readByte();
+		pVabToneAttr->pbmin = vhData->readByte();
+		pVabToneAttr->pbmax = vhData->readByte();
+		pVabToneAttr->reserved1 = vhData->readByte();
+		pVabToneAttr->reserved2 = vhData->readByte();
+		pVabToneAttr->adsr1 = vhData->readUint16LE();
+		pVabToneAttr->adsr2 = vhData->readUint16LE();
+		pVabToneAttr->prog = vhData->readSint16LE();
+		pVabToneAttr->vag = vhData->readSint16LE();
+		for (int j = 0; j < 4; j++) {
+			pVabToneAttr->reserved[j] = vhData->readSint16LE();
+		}
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/VabSound.h b/engines/dragons/VabSound.h
index 7b82da36f0..a7ab4e09d5 100644
--- a/engines/dragons/VabSound.h
+++ b/engines/dragons/VabSound.h
@@ -36,6 +36,8 @@ namespace Audio {
 namespace Dragons {
 class DragonsEngine;
 
+#define DRAGONS_VAB_NUM_PROG_ATTRS 128
+
 struct VabHeader {
 	char magic[4];
 
@@ -116,13 +118,15 @@ private:
 	byte *_vbData;
 
 	VabHeader _header;
-	VabProgramAttr _programAttrs[128];
+	VabProgramAttr _programAttrs[DRAGONS_VAB_NUM_PROG_ATTRS];
 	VabToneAttr *_toneAttrs;
 
 	uint32 _vagSizes[0x100];
 	uint32 _vagOffsets[0x100];
 
 	void loadHeader(Common::SeekableReadStream *vhData);
+	void loadProgramAttributes(Common::SeekableReadStream *vhData);
+	void loadToneAttributes(Common::SeekableReadStream *vhData);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 2bbbb460f5..074c295ba1 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -1767,7 +1767,7 @@ void caveOfDilemmaUpdateFunction() {
 }
 
 void moatDrainedSceneUpdateFunction() {
-	static const uint32 moatDrainedTextIdTbl[4] {
+	static const uint32 moatDrainedTextIdTbl[4] = {
 			0x3C97A, 0x3C9AC, 0x3C9F8, 0x3CA48
 	};
 	static uint16 moatDrainedUpdateCounter = 0;


Commit: dfee40fd243c42b224eaca171420898abd7aba72
    https://github.com/scummvm/scummvm/commit/dfee40fd243c42b224eaca171420898abd7aba72
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More code formatting

Changed paths:
    engines/dragons/credits.cpp
    engines/dragons/cutscene.cpp
    engines/dragons/dragons.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame5.cpp


diff --git a/engines/dragons/credits.cpp b/engines/dragons/credits.cpp
index 87c05c303e..dd6d4912b9 100644
--- a/engines/dragons/credits.cpp
+++ b/engines/dragons/credits.cpp
@@ -33,7 +33,8 @@ void creditsUpdateFunction() {
 	getEngine()->_credits->update();
 }
 
-Credits::Credits(DragonsEngine *vm, FontManager *fontManager, BigfileArchive *bigfileArchive) : _vm(vm), _fontManager(fontManager), _bigfileArchive(bigfileArchive), _surface(NULL) {
+Credits::Credits(DragonsEngine *vm, FontManager *fontManager, BigfileArchive *bigfileArchive) : _vm(vm),
+				_fontManager(fontManager), _bigfileArchive(bigfileArchive), _surface(NULL), _curPtr(NULL) {
 	_running = false;
 	_updateCounter = 0;
 	_yOffset = 0;
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 1649740cc9..e6cd169da0 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -830,18 +830,7 @@ void tournamentUpdateFunction() {
 }
 
 void CutScene::tournamentCutScene() {
-	uint actorId;
-	uint16 uVar1;
 	uint16 dialogText[1000];
-//	undefined2 local_218 [256];
-
-	uVar1 = 0;
-	actorId = 0;
-//	do {
-//		uVar1 = uVar1 + 1;
-//		local_218[actorId] = *(undefined2 *)(actorId * 2 + scrFileData_maybe);
-//		actorId = (uint)uVar1;
-//	} while (uVar1 < 0x100);
 
 	tournamentUpdateCameraX = 0x140;
 	_vm->setVsyncUpdateFunction(tournamentUpdateFunction);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 2b8af2e45c..b288503afa 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -236,9 +236,7 @@ Common::Error DragonsEngine::run() {
 	return Common::kNoError;
 }
 
-uint16 DragonsEngine::ipt_img_file_related()
-{
-	DragonINI *ini;
+uint16 DragonsEngine::ipt_img_file_related() {
     DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 	assert(flicker);
 
@@ -246,7 +244,7 @@ uint16 DragonsEngine::ipt_img_file_related()
 	int16 tileY = flicker->actor->y_pos / 8;
 
 	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
-		ini = getINI(i);
+		DragonINI *ini = getINI(i);
 		if ((ini->sceneId == getCurrentSceneId()) && (ini->field_1a_flags_maybe == 0)) {
 			IMG *img = _dragonIMG->getIMG(ini->field_2);
 			if ((img->x <= tileX) && (((tileX <= img->x + img->w && (img->y <= tileY)) && (tileY <= img->y + img->h)))) {
@@ -257,8 +255,7 @@ uint16 DragonsEngine::ipt_img_file_related()
 	return 0;
 }
 
-void DragonsEngine::gameLoop()
-{
+void DragonsEngine::gameLoop() {
 	uint uVar3;
 	uint actorId;
 	uint16 uVar6;
@@ -1185,7 +1182,6 @@ void DragonsEngine::walkFlickerToObject()
 			flickerINI = _dragonINIResource->getFlickerRecord();
 			if (flickerINI != NULL && flickerINI->actor != NULL) {
 				flickerINI->actor->clearFlag(ACTOR_FLAG_10);
-				uVar8 = (uint)_cursor->data_80072890;
 				flickerINI->actor->setFlag(ACTOR_FLAG_4);
 				targetINI = getINI(_cursor->data_80072890 - 1);
 				flickerINI->field_20_actor_field_14 = targetINI->field_e;
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index ce37357d10..3b394be309 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -268,7 +268,7 @@ void Minigame1::run() {
 			if (local_21e != 0) {
 				local_21e = local_21e + -1;
 			}
-			switch(gameState) {
+			switch (gameState) {
 				case 0:
 					break;
 				case 1: //cat in the catapult ready to fire.
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 40a929f39a..5255782017 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -64,7 +64,6 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uint uVar19;
 	int iVar20;
 	bool shouldShakeScreen;
-	byte *actorFrameData;
 	uint16 local_2e6;
 	int16 actorSequenceIdTbl [15];
 	uint32 textIdTbl [4];
@@ -239,12 +238,10 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uVar8->waitUntilFlag8And4AreSet();
 
 	uVar5->setFlag(ACTOR_FLAG_400);
-	actorFrameData = loungealotLeftUpperArm->frame->frameDataOffset;
 	flickerArm->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
 	flickerArm->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10;
 	loungealotThumb->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
 	loungealotThumb->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10;
-	actorFrameData = flickerArm->frame->frameDataOffset;
 	uVar12->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e;
 	uVar12->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10;
 	uVar13->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e;
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 6bf3e8db55..e44fe5e264 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -135,7 +135,7 @@ void Minigame3::run() {
 	fd->seek(0x2c);
 	for (i = 0; i < 30; i++) {
 		tearInfo[i].x = fd->readUint16LE();
-		tearInfo[i].x = fd->readUint16LE();
+		tearInfo[i].y = fd->readUint16LE();
 		tearInfo[i].unk = fd->readUint16LE();
 		tearInfo[i].yRelated = fd->readUint16LE();
 	}
@@ -353,7 +353,7 @@ void Minigame3::run() {
 	local_1c2 = 0;
 	while ( true ) {
 		_vm->waitForFrames(1);
-		switch(currentState) {
+		switch (currentState) {
 			case 1:
 				if ((bunnyActorTbl[local_1a]->_sequenceID != 5) || ((bunnyActorTbl[local_1a]->_flags & 4) != 0)) {
 					if ((local_56 < 1) ||
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index f52b1508bf..242f6c0369 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -170,241 +170,240 @@ void Minigame5::run() {
 		while ( true ) {
 			do {
 				_vm->waitForFrames(1);
-				if ((uint)currentState - 1 < 8) {
-					switch(currentState) {
-						case 1:
-							if (local_66 != 8) {
-								local_66 = 0;
+				switch (currentState) {
+				case 1:
+					if (local_66 != 8) {
+						local_66 = 0;
+					}
+					//iVar2 = IsButtonBeingPressed((uint)DAT_800728ac,0);
+					if (!_vm->isActionButtonPressed()) {
+						if (local_74 == 0) {
+							if ((((flickerActor->_sequenceID != 0) &&
+								  (flickerActor->_sequenceID != 5)) &&
+								 (flickerActor->_sequenceID != 6)) ||
+								((flickerActor->_flags & 4) != 0)) {
+								flickerActor->updateSequence(0x19);
 							}
-							//iVar2 = IsButtonBeingPressed((uint)DAT_800728ac,0);
-							if (!_vm->isActionButtonPressed()) {
-								if (local_74 == 0) {
-									if ((((flickerActor->_sequenceID != 0) &&
-										  (flickerActor->_sequenceID != 5)) &&
-										 (flickerActor->_sequenceID != 6)) ||
-										((flickerActor->_flags & 4) != 0)) {
-										flickerActor->updateSequence(0x19);
-									}
-								}
-								else {
-									local_66 = 1;
-									local_50 = 0;
-									pusherActor->updateSequence(1);
-									currentState = 2;
-									if (local_74 < 0x14) {
-										local_72 = 1;
-									}
-									else {
-										if (local_74 < 0x2d) {
-											local_72 = 2;
-										}
-										else {
-											if (local_74 < 0x169) {
-												local_72 = 3;
-											}
-										}
-									}
-								}
-								local_74 = 0;
+						}
+						else {
+							local_66 = 1;
+							local_50 = 0;
+							pusherActor->updateSequence(1);
+							currentState = 2;
+							if (local_74 < 0x14) {
+								local_72 = 1;
 							}
 							else {
-								pusherActor->x_pos = flickerActor->x_pos + -0xe;
-								pusherActor->y_pos = flickerActor->y_pos + 7;
-								if (local_74 < 0x168) {
-									local_74 = local_74 + 1;
-									if (local_74 < 0x14) {
-										if (((pusherActor->_sequenceID != 4) &&
-											 (pusherActor->_sequenceID != 2)) &&
-											(pusherActor->_sequenceID != 3)) {
-											pusherActor->updateSequence(4);
-										}
-										if (flickerActor->_sequenceID != 0x1a) {
-											flickerActor->updateSequence(0x1a);
-											_vm->playOrStopSound(2);
-										}
-									}
-									else {
-										if (local_74 < 0x2d) {
-											if (((pusherActor->_sequenceID != 5) &&
-												 (pusherActor->_sequenceID != 2)) &&
-												(pusherActor->_sequenceID != 3)) {
-												pusherActor->updateSequence(5);
-											}
-											if (flickerActor->_sequenceID != 0x1e) {
-												flickerActor->updateSequence(0x1e);
-												_vm->playOrStopSound(3);
-											}
-										}
-										else {
-											if (local_74 < 0x169) {
-												if (((pusherActor->_sequenceID != 6) &&
-													 (pusherActor->_sequenceID != 2)) &&
-													(pusherActor->_sequenceID != 3)) {
-													pusherActor->updateSequence(6);
-												}
-												if (flickerActor->_sequenceID != 0x1f) {
-													flickerActor->updateSequence(0x1f);
-													_vm->playOrStopSound(4);
-												}
-											}
-										}
-									}
+								if (local_74 < 0x2d) {
+									local_72 = 2;
 								}
 								else {
-									if (pusherActor->_sequenceID != 6) {
-										pusherActor->updateSequence(6);
-									}
-									if (flickerActor->_sequenceID != 0x1f) {
-										flickerActor->updateSequence(0x1f);
+									if (local_74 < 0x169) {
+										local_72 = 3;
 									}
 								}
 							}
-							break;
-						case 2:
-							if (flickerActor->_sequenceID == 0x1b) {
-								if ((flickerActor->_flags & 4) != 0) {
-									if ((((int)(uint)local_850 < (int)((local_30[0]) - 6)) ||
-										 ((uint)local_30[1] + 6 < (uint)local_850)) || (local_72 != local_30[2])) {
-										local_42 = 8;
-									}
-									else {
-										local_42 = 0;
-									}
-									local_5c = 0;
-									if ((local_42 != 8) && ((local_850 < local_30[0] || (local_30[1] < local_850)))) {
-										local_5c = (short)((int)(((local_30[0]) + 0x17) * 0x80) / 0x2a) -
-												   (short)((int)((uint)local_850 << 7) / 0x2a);
-									}
-									local_60 = local_850 << 7;
-									bombActor->x_pos = local_850 & 0x1ff;
-									local_5e = 0x2d00;
-									local_5a = (local_72 + 3) * 0x80;
-									bombActor->y_pos = 0x5a;
-									bombScale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-									bombActor->scale = bombScale;
-									_vm->playOrStopSound(10);
-									bombActor->priorityLayer = 3;
-									flickerActor->updateSequence(8);
-									currentState = 3;
+						}
+						local_74 = 0;
+					}
+					else {
+						pusherActor->x_pos = flickerActor->x_pos + -0xe;
+						pusherActor->y_pos = flickerActor->y_pos + 7;
+						if (local_74 < 0x168) {
+							local_74 = local_74 + 1;
+							if (local_74 < 0x14) {
+								if (((pusherActor->_sequenceID != 4) &&
+									 (pusherActor->_sequenceID != 2)) &&
+									(pusherActor->_sequenceID != 3)) {
+									pusherActor->updateSequence(4);
 								}
-							}
-							else {
-								flickerActor->updateSequence(0x1b);
-								_vm->playOrStopSound(1);
-							}
-							break;
-						case 3:
-							local_60 = local_60 + local_5c;
-							if ((uint)local_72 * 2 + 0xb4 < (uint)bombScale) {
-								local_5e = local_5e - local_5a;
-								local_5a = local_5a - local_28[((uint)local_72 - 1) * 3];
-								if (local_5a < 0) {
-									local_5a = 0;
+								if (flickerActor->_sequenceID != 0x1a) {
+									flickerActor->updateSequence(0x1a);
+									_vm->playOrStopSound(2);
 								}
 							}
 							else {
-								if ((int)(uint)bombScale < (int)((uint)local_72 * -4 + 0xba)) {
-									local_5e = local_5e + local_5a;
-									local_5a = local_5a + local_28[((uint)local_72 - 1) * 3 + 2];
-								}
-								else {
-									local_5a = 0;
-								}
-							}
-							bombActor->x_pos = local_60 >> 7;
-							bombActor->y_pos = local_5e >> 7;
-							bombScale = bombScale - 3;
-							bombActor->scale = bombScale;
-							if (bombScale == 0x7f) {
-								if (((local_60 >> 7 < local_30[0]) || (local_30[1] < local_60 >> 7)) ||
-									(local_72 != local_30[2])) {
-									local_42 = 8;
-								}
-								else {
-									local_42 = 0;
-								}
-								if (local_42 == 8) {
-									if ((((local_72 == 1) && (local_60 >> 7 < 0x10e)) ||
-										 ((local_72 == 2 &&
-										   ((((0x7f < local_60 >> 7 && (local_60 >> 7 < 0xad)) ||
-											  ((0x30 < local_60 >> 7 && (local_60 >> 7 < 0x4a)))) ||
-											 ((0xf8 < local_60 >> 7 && (local_60 >> 7 < 0x10f)))))))) ||
-										((local_72 == 3 &&
-										  (((0x3c < local_60 >> 7 && (local_60 >> 7 < 0x46)) ||
-											((0x101 < local_60 >> 7 && (local_60 >> 7 < 0x10a)))))))) {
-										bombActor->priorityLayer = 0;
-										dustActor->priorityLayer = 4;
-										dustActor->x_pos = bombActor->x_pos;
-										dustActor->y_pos = bombActor->y_pos;
-										dustActor->updateSequence(9);
-										currentState = 4;
+								if (local_74 < 0x2d) {
+									if (((pusherActor->_sequenceID != 5) &&
+										 (pusherActor->_sequenceID != 2)) &&
+										(pusherActor->_sequenceID != 3)) {
+										pusherActor->updateSequence(5);
+									}
+									if (flickerActor->_sequenceID != 0x1e) {
+										flickerActor->updateSequence(0x1e);
+										_vm->playOrStopSound(3);
 									}
 								}
 								else {
-									local_4e->field_c = 2;
-									local_4c = 0x3c;
-									bombActor->priorityLayer = 0;
-									currentState = 8;
+									if (local_74 < 0x169) {
+										if (((pusherActor->_sequenceID != 6) &&
+											 (pusherActor->_sequenceID != 2)) &&
+											(pusherActor->_sequenceID != 3)) {
+											pusherActor->updateSequence(6);
+										}
+										if (flickerActor->_sequenceID != 0x1f) {
+											flickerActor->updateSequence(0x1f);
+											_vm->playOrStopSound(4);
+										}
+									}
 								}
 							}
-							if (bombScale < 0x7f) {
-								bombActor->priorityLayer = 2;
-							}
-							if ((0xc < bombScale) && (bombScale < 0x41)) {
-								bombActor->priorityLayer = 0;
+						}
+						else {
+							if (pusherActor->_sequenceID != 6) {
+								pusherActor->updateSequence(6);
 							}
-							if ((short)bombScale < 2) {
-								currentState = 5;
+							if (flickerActor->_sequenceID != 0x1f) {
+								flickerActor->updateSequence(0x1f);
 							}
-							break;
-						case 4:
-							pusherActor->updateSequence(9);
-							_vm->waitForFrames(0x3c);
-							pusherActor->updateSequence(0xb);
-							if (DAT_800633e6 == 0) {
-								_vm->_talk->loadText(DAT_8006393c,auStack2120, 1000);
-								_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1,DAT_8006393c);
-								DAT_800633e6 = 1;
+						}
+					}
+					break;
+				case 2:
+					if (flickerActor->_sequenceID == 0x1b) {
+						if ((flickerActor->_flags & 4) != 0) {
+							if ((((int)(uint)local_850 < (int)((local_30[0]) - 6)) ||
+								 ((uint)local_30[1] + 6 < (uint)local_850)) || (local_72 != local_30[2])) {
+								local_42 = 8;
 							}
 							else {
-								_vm->_talk->loadText(DAT_80063938, auStack2120, 1000);
-								_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1, DAT_80063938);
+								local_42 = 0;
+							}
+							local_5c = 0;
+							if ((local_42 != 8) && ((local_850 < local_30[0] || (local_30[1] < local_850)))) {
+								local_5c = (short)((int)(((local_30[0]) + 0x17) * 0x80) / 0x2a) -
+										   (short)((int)((uint)local_850 << 7) / 0x2a);
+							}
+							local_60 = local_850 << 7;
+							bombActor->x_pos = local_850 & 0x1ff;
+							local_5e = 0x2d00;
+							local_5a = (local_72 + 3) * 0x80;
+							bombActor->y_pos = 0x5a;
+							bombScale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+							bombActor->scale = bombScale;
+							_vm->playOrStopSound(10);
+							bombActor->priorityLayer = 3;
+							flickerActor->updateSequence(8);
+							currentState = 3;
+						}
+					}
+					else {
+						flickerActor->updateSequence(0x1b);
+						_vm->playOrStopSound(1);
+					}
+					break;
+				case 3:
+					local_60 = local_60 + local_5c;
+					if ((uint)local_72 * 2 + 0xb4 < (uint)bombScale) {
+						local_5e = local_5e - local_5a;
+						local_5a = local_5a - local_28[((uint)local_72 - 1) * 3];
+						if (local_5a < 0) {
+							local_5a = 0;
+						}
+					}
+					else {
+						if ((int)(uint)bombScale < (int)((uint)local_72 * -4 + 0xba)) {
+							local_5e = local_5e + local_5a;
+							local_5a = local_5a + local_28[((uint)local_72 - 1) * 3 + 2];
+						}
+						else {
+							local_5a = 0;
+						}
+					}
+					bombActor->x_pos = local_60 >> 7;
+					bombActor->y_pos = local_5e >> 7;
+					bombScale = bombScale - 3;
+					bombActor->scale = bombScale;
+					if (bombScale == 0x7f) {
+						if (((local_60 >> 7 < local_30[0]) || (local_30[1] < local_60 >> 7)) ||
+							(local_72 != local_30[2])) {
+							local_42 = 8;
+						}
+						else {
+							local_42 = 0;
+						}
+						if (local_42 == 8) {
+							if ((((local_72 == 1) && (local_60 >> 7 < 0x10e)) ||
+								 ((local_72 == 2 &&
+								   ((((0x7f < local_60 >> 7 && (local_60 >> 7 < 0xad)) ||
+									  ((0x30 < local_60 >> 7 && (local_60 >> 7 < 0x4a)))) ||
+									 ((0xf8 < local_60 >> 7 && (local_60 >> 7 < 0x10f)))))))) ||
+								((local_72 == 3 &&
+								  (((0x3c < local_60 >> 7 && (local_60 >> 7 < 0x46)) ||
+									((0x101 < local_60 >> 7 && (local_60 >> 7 < 0x10a)))))))) {
+								bombActor->priorityLayer = 0;
+								dustActor->priorityLayer = 4;
+								dustActor->x_pos = bombActor->x_pos;
+								dustActor->y_pos = bombActor->y_pos;
+								dustActor->updateSequence(9);
+								currentState = 4;
 							}
-							_vm->waitForFrames(10);
-							local_10 = 1;
-							currentState = 6;
-							break;
-						case 5:
-							currentState = 4;
-							break;
-						case 6:
-							currentState = 7;
-							break;
-						case 7:
-							break;
-						case 8:
+						}
+						else {
+							local_4e->field_c = 2;
+							local_4c = 0x3c;
 							bombActor->priorityLayer = 0;
-							pusherActor->updateSequence(0);
-							_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(2);
-							_vm->waitForFrames(0x12);
-							_vm->_talk->loadText(DAT_80063e38, auStack2120, 1000);
-							_vm->_talk->displayDialogAroundPoint(auStack2120,0xf,2,0x501,0,DAT_80063e38);
-//						TODO	callMaybeResetData();
-							_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(3);
-							_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->waitUntilFlag8And4AreSet();
-							pusherActor->updateSequence(7);
-							_vm->_talk->loadText(DAT_8006391c, auStack2120, 1000);
-							_vm->_talk->displayDialogAroundPoint(auStack2120, (int)(short)(local_850 >> 3),0xc,0,1,DAT_8006391c);
-							pusherActor->_flags = pusherActor->_flags | 0x1000;
-							local_10 = 2;
-							local_48 = 1;
-							currentState = 6;
+							currentState = 8;
+						}
 					}
-				}
-				else {
+					if (bombScale < 0x7f) {
+						bombActor->priorityLayer = 2;
+					}
+					if ((0xc < bombScale) && (bombScale < 0x41)) {
+						bombActor->priorityLayer = 0;
+					}
+					if ((short)bombScale < 2) {
+						currentState = 5;
+					}
+					break;
+				case 4:
+					pusherActor->updateSequence(9);
+					_vm->waitForFrames(0x3c);
+					pusherActor->updateSequence(0xb);
+					if (DAT_800633e6 == 0) {
+						_vm->_talk->loadText(DAT_8006393c,auStack2120, 1000);
+						_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1,DAT_8006393c);
+						DAT_800633e6 = 1;
+					}
+					else {
+						_vm->_talk->loadText(DAT_80063938, auStack2120, 1000);
+						_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1, DAT_80063938);
+					}
+					_vm->waitForFrames(10);
+					local_10 = 1;
+					currentState = 6;
+					break;
+				case 5:
+					currentState = 4;
+					break;
+				case 6:
+					currentState = 7;
+					break;
+				case 7:
+					break;
+				case 8:
+					bombActor->priorityLayer = 0;
+					pusherActor->updateSequence(0);
+					_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(2);
+					_vm->waitForFrames(0x12);
+					_vm->_talk->loadText(DAT_80063e38, auStack2120, 1000);
+					_vm->_talk->displayDialogAroundPoint(auStack2120,0xf,2,0x501,0,DAT_80063e38);
+//						TODO	callMaybeResetData();
+					_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(3);
+					_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->waitUntilFlag8And4AreSet();
+					pusherActor->updateSequence(7);
+					_vm->_talk->loadText(DAT_8006391c, auStack2120, 1000);
+					_vm->_talk->displayDialogAroundPoint(auStack2120, (int)(short)(local_850 >> 3),0xc,0,1,DAT_8006391c);
+					pusherActor->_flags = pusherActor->_flags | 0x1000;
+					local_10 = 2;
+					local_48 = 1;
+					currentState = 6;
+					break;
+				default:
 					debug("undefined state!");
 					currentState = 1;
 					bombActor->priorityLayer = 0;
+					break;
 				}
 				if ((local_10 == 0) && (currentState != 2)) {
 					if (!_vm->isLeftKeyPressed() || (local_850 < 0x37)) {


Commit: 08fb9da119c8adc18b4a4a7f5c3d7ed78fe6bebf
    https://github.com/scummvm/scummvm/commit/08fb9da119c8adc18b4a4a7f5c3d7ed78fe6bebf
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Rename Actor class variables to conform our naming standards

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/cursor.cpp
    engines/dragons/cutscene.cpp
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index bdf22b22c4..062ef5e5c2 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -42,7 +42,7 @@ ActorManager::ActorManager(ActorResourceLoader *actorResourceLoader) : _actorRes
 Actor *ActorManager::loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 priorityLayer) {
 	Actor *actor = loadActor(resourceId, sequenceId, x, y);
 	if (actor) {
-		actor->priorityLayer = priorityLayer;
+		actor->_priorityLayer = priorityLayer;
 	}
 	return actor;
 }
@@ -67,7 +67,7 @@ Actor *ActorManager::findFreeActor(int16 resourceId) {
 	for (ActorsIterator it = _actors.begin(); it != _actors.end() && i < 23; ++it, i++) {
 		Actor *actor = it;
 		if (!(actor->_flags & Dragons::ACTOR_FLAG_40)) {
-			actor->resourceID = resourceId;
+			actor->_resourceID = resourceId;
 			actor->_walkSpeed = 0x100000;
 			return actor;
 		}
@@ -105,10 +105,10 @@ void ActorManager::updateActorDisplayOrder() {
 		for (int i = 0; i < DRAGONS_ENGINE_NUM_ACTORS - 1; i++) {
 			Actor *curActor = getActor(_displayOrder[i]);
 			Actor *nextActor = getActor(_displayOrder[i + 1]);
-			int16 curY = curActor->y_pos > 0 ? curActor->y_pos : 0;
-			int16 nextY = nextActor->y_pos > 0 ? nextActor->y_pos : 0;
-			if (nextActor->priorityLayer * 0x1000000 + nextY * 0x100 + nextActor->_actorID <
-				curActor->priorityLayer * 0x1000000 + curY * 0x100 + curActor->_actorID) {
+			int16 curY = curActor->_y_pos > 0 ? curActor->_y_pos : 0;
+			int16 nextY = nextActor->_y_pos > 0 ? nextActor->_y_pos : 0;
+			if (nextActor->_priorityLayer * 0x1000000 + nextY * 0x100 + nextActor->_actorID <
+				curActor->_priorityLayer * 0x1000000 + curY * 0x100 + curActor->_actorID) {
 				_displayOrder[i] = nextActor->_actorID;
 				_displayOrder[i + 1] = curActor->_actorID;
 				shouldContinue = true;
@@ -122,7 +122,7 @@ void ActorManager::resetDisplayOrder() {
 		Actor *actor = getActor(i);
 		_displayOrder[i] = i;
 		if (!actor->isFlagSet(ACTOR_FLAG_40)) {
-			actor->priorityLayer = 0;
+			actor->_priorityLayer = 0;
 		}
 	}
 }
@@ -133,38 +133,38 @@ Actor *ActorManager::getActorByDisplayOrder(uint16 position) {
 
 Actor::Actor(uint16 id) : _actorID(id) {
 	_actorResource = NULL;
-	resourceID = -1;
+	_resourceID = -1;
 	_seqCodeIp = 0;
-	frame_pointer_maybe = NULL;
-	priorityLayer = 3;
-	x_pos = 160;
-	y_pos = 110;
+	_frame_pointer_maybe = NULL;
+	_priorityLayer = 3;
+	_x_pos = 160;
+	_y_pos = 110;
 	_walkDestX = 0;
 	_walkDestY = 0;
 	_walkSpeed = 0;
 	_flags = 0;
-	frame_width = 0;
-	frame_height = 0;
-	frame_flags = 0;
-	clut = 0;
-	frame = NULL;
-	surface = NULL;
+	_frame_width = 0;
+	_frame_height = 0;
+	_frame_flags = 0;
+	_clut = 0;
+	_frame = NULL;
+	_surface = NULL;
 }
 
 void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	debug(3, "actor %d Init", _actorID);
 	_actorResource = resource;
-	x_pos = x;
-	y_pos = y;
-	sequenceTimer = 0;
+	_x_pos = x;
+	_y_pos = y;
+	_sequenceTimer = 0;
 	_walkDestX = x;
 	_walkDestY = y;
-	scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_sequenceID2 = 0;
 	_flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
-	frame_width = 0;
-	frame_height = 0;
-	frame_flags = 4;
+	_frame_width = 0;
+	_frame_height = 0;
+	_frame_flags = 4;
 	//TODO sub_80017010();
 	freeFrame();
 
@@ -184,27 +184,27 @@ void Actor::resetSequenceIP() {
 void Actor::loadFrame(uint16 frameOffset) {
 	freeFrame();
 
-	frame = _actorResource->loadFrameHeader(frameOffset);
+	_frame = _actorResource->loadFrameHeader(frameOffset);
 
-	if (frame->flags & 0x800) {
-		frame_flags |= ACTOR_FRAME_FLAG_2;
+	if (_frame->flags & 0x800) {
+		_frame_flags |= ACTOR_FRAME_FLAG_2;
 	} else {
-		frame_flags &= ~ACTOR_FRAME_FLAG_2;
+		_frame_flags &= ~ACTOR_FRAME_FLAG_2;
 	}
 
-	surface = _actorResource->loadFrame(*frame, NULL); // TODO paletteId == 0xf1 ? getEngine()->getBackgroundPalette() : NULL);
+	_surface = _actorResource->loadFrame(*_frame, NULL); // TODO paletteId == 0xf1 ? getEngine()->getBackgroundPalette() : NULL);
 
-	debug(5, "ActorId: %d load frame header: (%d,%d)", _actorID, frame->width, frame->height);
+	debug(5, "ActorId: %d load frame header: (%d,%d)", _actorID, _frame->width, _frame->height);
 
 	_flags |= Dragons::ACTOR_FLAG_8; //TODO check if this is the right spot. engine sets it at 0x800185b0
 
 }
 
 void Actor::freeFrame() {
-	delete frame;
-	delete surface;
-	frame = NULL;
-	surface = NULL;
+	delete _frame;
+	delete _surface;
+	_frame = NULL;
+	_surface = NULL;
 }
 
 byte *Actor::getSeqIpAtOffset(uint32 offset) {
@@ -243,7 +243,7 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 	clearFlag(ACTOR_FLAG_10);
 
 	// Check if the actor already is at the destination
-	if (x_pos == destX && y_pos == destY) {
+	if (_x_pos == destX && _y_pos == destY) {
 		if (wasAlreadyWalking) {
 			stopWalk();
 		}
@@ -296,7 +296,7 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 	}
 
 	// Check if the actor already is at the adjusted destination
-	if (x_pos == destX && y_pos == destY) {
+	if (_x_pos == destX && _y_pos == destY) {
 		if (wasAlreadyWalking) {
 			stopWalk();
 		}
@@ -304,7 +304,7 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 	}
 
 	int tempDestX1 = destX, tempDestY1 = destY;
-	int actorX1 = x_pos, actorY1 = y_pos;
+	int actorX1 = _x_pos, actorY1 = _y_pos;
 	bool pathPointProcessed[kPathPointsCount];
 
 	for (int pointIndex = 0; pointIndex < kPathPointsCount; ++pointIndex) {
@@ -329,8 +329,8 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 							actorY1 += syd;
 							tempDestX1 += dxd;
 							tempDestY1 += dyd;
-							x_pos += sxd;
-							y_pos += syd;
+							_x_pos += sxd;
+							_y_pos += syd;
 						}
 					}
 				}
@@ -357,8 +357,8 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 					if (canWalkLine(actorX1 + deltaX, actorY1 + deltaY, pt.x, pt.y, flags)) {
 						actorX1 += deltaX;
 						actorY1 += deltaY;
-						x_pos += deltaX;
-						y_pos += deltaY;
+						_x_pos += deltaX;
+						_y_pos += deltaY;
 						needAdjustSourcePoint = false;
 					}
 				}
@@ -404,7 +404,7 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 		tempDestX1 = pt.x;
 		tempDestY1 = pt.y;
 		if (pathPointsIndex >= 2) {
-			const Common::Point prevPt = getEngine()->_scene->getPoint(walkPointsTbl[pathPointsIndex - 2]);
+			const Common::Point prevPt = getEngine()->_scene->getPoint(_walkPointsTbl[pathPointsIndex - 2]);
 			if (canWalkLine(pt.x, pt.y, prevPt.x, prevPt.y, flags)) {
 				--pathPointsIndex;
 			}
@@ -413,7 +413,7 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 				--pathPointsIndex;
 			}
 		}
-		walkPointsTbl[pathPointsIndex] = foundPointIndex;
+		_walkPointsTbl[pathPointsIndex] = foundPointIndex;
 		++pathPointsIndex;
 	}
 
@@ -445,14 +445,14 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 		}
 	}
 
-	walkPointsIndex = pathPointsIndex - 1;
+	_walkPointsIndex = pathPointsIndex - 1;
 	if (pathPointsIndex == 0) {
 		_walkDestX = tempDestX1;
 		_walkDestY = tempDestY1;
 		_finalWalkDestX = -1;
 		_finalWalkDestY = -1;
 	} else {
-		const Common::Point pt = getEngine()->_scene->getPoint(walkPointsTbl[walkPointsIndex]);
+		const Common::Point pt = getEngine()->_scene->getPoint(_walkPointsTbl[_walkPointsIndex]);
 		_walkDestX = pt.x;
 		_walkDestY = pt.y;
 	}
@@ -469,9 +469,9 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 
 void Actor::stopWalk() {
 	clearFlag(Dragons::ACTOR_FLAG_10);
-	walkPointsIndex = 0;
-	_walkDestX = x_pos;
-	_walkDestY = y_pos;
+	_walkPointsIndex = 0;
+	_walkDestX = _x_pos;
+	_walkDestY = _y_pos;
 	_finalWalkDestX = -1;
 	_finalWalkDestY = -1;
 	setFlag(Dragons::ACTOR_FLAG_4);
@@ -525,7 +525,7 @@ bool Actor::isFlagSet(uint32 flag) {
 }
 
 uint16 Actor::canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 walkFlags) {
-	debug(1, "canWalkLine. (%X,%X) -> (%X,%X) %d", x_pos, y_pos, target_x, target_y, walkFlags);
+	debug(1, "canWalkLine. (%X,%X) -> (%X,%X) %d", _x_pos, _y_pos, target_x, target_y, walkFlags);
 
 	if (walkFlags == 2) {
 		return 1;
@@ -611,14 +611,14 @@ uint16 Actor::canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 ta
 int Actor::startMoveToPoint(int destX, int destY) {
 	int direction = 0;
 	int quadrant = 0;
-	int deltaX = destX - x_pos;
-	int deltaY = (destY - y_pos) * 2;
+	int deltaX = destX - _x_pos;
+	int deltaY = (destY - _y_pos) * 2;
 	int absDeltaX = ABS(deltaX);
 	int absDeltaY = ABS(deltaY);
-	// debug("from: (%d, %d); to: (%d, %d); d: (%d, %d); actor._walkSpeed: %08X", x_pos, actor._y, destX, destY, deltaX, deltaY, actor._walkSpeed);
+	// debug("from: (%d, %d); to: (%d, %d); d: (%d, %d); actor._walkSpeed: %08X", _x_pos, actor._y, destX, destY, deltaX, deltaY, actor._walkSpeed);
 
-	_xShl16 = x_pos << 16;
-	_yShl16 = y_pos << 16;
+	_xShl16 = _x_pos << 16;
+	_yShl16 = _y_pos << 16;
 
 	// Walk slope is a fixed point value, where the upper 16 bits are the integral part,
 	// and the lower 16 bits the fractional part. 0x10000 is 1.0.
@@ -688,8 +688,8 @@ int Actor::startMoveToPoint(int destX, int destY) {
 
 	void Actor::walkPath() {
 		if (isFlagClear(Dragons::ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
-			_xShl16 += (((scale * _walkSlopeX) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
-			_yShl16 += (((scale * _walkSlopeY) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
+			_xShl16 += (((_scale * _walkSlopeX) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
+			_yShl16 += (((_scale * _walkSlopeY) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
 
 			if ( (_walkSlopeX >= 0 && _walkDestX < (_xShl16 >> 0x10))
 			|| (_walkSlopeX < 0 && (_xShl16 >> 0x10) < _walkDestX)) {
@@ -701,11 +701,11 @@ int Actor::startMoveToPoint(int destX, int destY) {
 				_yShl16 = _walkDestY << 0x10;
 			}
 
-			x_pos = _xShl16 >> 0x10;
-			y_pos = _yShl16 >> 0x10;
+			_x_pos = _xShl16 >> 0x10;
+			_y_pos = _yShl16 >> 0x10;
 
-			if (x_pos == _walkDestX && y_pos == _walkDestY) {
-				if (walkPointsIndex <= 0) {
+			if (_x_pos == _walkDestX && _y_pos == _walkDestY) {
+				if (_walkPointsIndex <= 0) {
 					if (_finalWalkDestX < 0) {
 						clearFlag(ACTOR_FLAG_10);
 						if (isFlagClear(ACTOR_FLAG_200)) {
@@ -721,8 +721,8 @@ int Actor::startMoveToPoint(int destX, int destY) {
 						_finalWalkDestY = -1;
 					}
 				} else {
-					walkPointsIndex--;
-					Common::Point point = getEngine()->_scene->getPoint(walkPointsTbl[walkPointsIndex]);
+					_walkPointsIndex--;
+					Common::Point point = getEngine()->_scene->getPoint(_walkPointsTbl[_walkPointsIndex]);
 					_walkDestX = point.x;
 					_walkDestY = point.y;
 				}
@@ -780,7 +780,7 @@ bool Actor::waitUntilFlag4IsSetAllowSkip() {
 byte *Actor::getPalette() {
 	if (!isFlagSet(ACTOR_FLAG_4000)) {
 		if (!isFlagSet(ACTOR_FLAG_8000)) {
-			if ((frame_flags & 0x30) != 0) {
+			if ((_frame_flags & 0x30) != 0) {
 				return _actorResource->getPalette();
 			}
 			return getEngine()->_screen->getPalette(1);
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 07b2616a0a..b179ac49fc 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -87,40 +87,40 @@ class Actor {
 public:
 	uint16 _actorID;
 	ActorResource* _actorResource;
-	uint16 actorFileDictionaryIndex;
-	int16 resourceID;
+	uint16 _actorFileDictionaryIndex;
+	int16 _resourceID;
 	byte *_seqCodeIp;
-	void* frame_pointer_maybe;
-	ActorFrame *frame;
-	Graphics::Surface *surface;
-	uint16 field_c;
-	int16 scale; // scale factor 0x100 is 100%
-	uint16 sequenceTimer;
+	void* _frame_pointer_maybe;
+	ActorFrame *_frame;
+	Graphics::Surface *_surface;
+	uint16 _field_c;
+	int16 _scale; // scale factor 0x100 is 100%
+	uint16 _sequenceTimer;
 	uint16 _sequenceID;
 	int16 _sequenceID2;
-	int16 priorityLayer;
+	int16 _priorityLayer;
 	uint16 _flags;
-	int16 x_pos;
-	int16 y_pos;
+	int16 _x_pos;
+	int16 _y_pos;
 	int16 _walkDestX;
 	int16 _walkDestY;
 	int32 _xShl16;
 	int32 _yShl16;
 	int32 _walkSlopeX;
 	int32 _walkSlopeY;
-	uint16 walkPointsTbl[32];
-	int16 walkPointsIndex;
+	uint16 _walkPointsTbl[32];
+	int16 _walkPointsIndex;
 	int16 _finalWalkDestX;
 	int16 _finalWalkDestY;
-	uint16 field_7a;
+	uint16 _field_7a;
 	int32 _walkSpeed;
-	uint16 field_80;
-	uint16 frame_vram_x;
-	uint16 frame_vram_y;
-	uint16 frame_width;
-	uint16 frame_height;
-	uint16 frame_flags;
-	uint16 clut;
+	uint16 _field_80;
+	uint16 _frame_vram_x;
+	uint16 _frame_vram_y;
+	uint16 _frame_width;
+	uint16 _frame_height;
+	uint16 _frame_flags;
+	uint16 _clut;
 public:
 
 	Actor(uint16 id);
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 33e40d7afb..55ed3c0779 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -40,11 +40,11 @@ Cursor::Cursor(DragonsEngine *vm): _vm(vm), _actor(0), _x(0), _y(0) {
 void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResource) {
 	_sequenceID = 0;
 	_actor = actorManager->loadActor(0, 0); //Load cursor
-	_actor->x_pos = _x = 160;
-	_actor->y_pos = _y = 100;
-	_actor->priorityLayer = 6;
+	_actor->_x_pos = _x = 160;
+	_actor->_y_pos = _y = 100;
+	_actor->_priorityLayer = 6;
 	_actor->_flags = 0;
-	_actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	_actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_actor->updateSequence(_sequenceID);
 	_actor->_flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
 					   Dragons::ACTOR_FLAG_200);
@@ -71,8 +71,8 @@ void Cursor::update() {
 		_sequenceID = 1;
 	}
 
-	_actor->x_pos = _x;
-	_actor->y_pos = _y;
+	_actor->_x_pos = _x;
+	_actor->_y_pos = _y;
 
 	// 0x80028104
 	if (_iniUnderCursor != 0
@@ -136,9 +136,9 @@ void Cursor::update() {
 
 void Cursor::updateVisibility() {
 	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_8) && !_vm->isUnkFlagSet(Dragons::ENGINE_UNK1_FLAG_10)) {
-		_actor->priorityLayer = 9;
+		_actor->_priorityLayer = 9;
 	} else {
-		_actor->priorityLayer = 0;
+		_actor->_priorityLayer = 0;
 	}
 }
 
@@ -215,10 +215,10 @@ int16 Cursor::updateIniFromScene() {
 			if (ini->field_1a_flags_maybe & 1) {
 				// 0x80028b18
 				if (ini->actor->isFlagSet(ACTOR_FLAG_40) && ini->actor->isFlagSet(ACTOR_FLAG_8)) {
-					int16 iniActorXPosition = ini->actor->x_pos - ini->actor->frame->xOffset;
-					int16 iniActorYPosition = ini->actor->y_pos - ini->actor->frame->yOffset;
-					if (cursorX >= iniActorXPosition && cursorX < iniActorXPosition + ini->actor->frame->width
-					&& cursorY >= iniActorYPosition && cursorY < iniActorYPosition + ini->actor->frame->height) {
+					int16 iniActorXPosition = ini->actor->_x_pos - ini->actor->_frame->xOffset;
+					int16 iniActorYPosition = ini->actor->_y_pos - ini->actor->_frame->yOffset;
+					if (cursorX >= iniActorXPosition && cursorX < iniActorXPosition + ini->actor->_frame->width
+							&& cursorY >= iniActorYPosition && cursorY < iniActorYPosition + ini->actor->_frame->height) {
 						cursorOverIni = i + 1;
 					}
 				}
@@ -357,8 +357,8 @@ byte *Cursor::getPalette() {
 
 void Cursor::updateActorPosition(int16 x, int16 y) {
 	updatePosition(x, y);
-	_actor->x_pos = _x;
-	_actor->y_pos = _y;
+	_actor->_x_pos = _x;
+	_actor->_y_pos = _y;
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index e6cd169da0..93d50832b4 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -230,30 +230,30 @@ void CutScene::scene1() {
 																									DAT_80072de8->setFlag(ACTOR_FLAG_800);
 																									DAT_80072de8->setFlag(ACTOR_FLAG_8000);
 																									DAT_80072de8->_walkSpeed = 0x20000;
-																									DAT_80072de8->priorityLayer = 3;
+																									DAT_80072de8->_priorityLayer = 3;
 
 																									DAT_80072dec->setFlag(ACTOR_FLAG_100);
 																									DAT_80072dec->setFlag(ACTOR_FLAG_800);
 																									DAT_80072dec->setFlag(ACTOR_FLAG_8000);
 																									DAT_80072dec->_walkSpeed = 0x18000;
-																									DAT_80072dec->priorityLayer = 3;
+																									DAT_80072dec->_priorityLayer = 3;
 
 																									DAT_80072df0->setFlag(ACTOR_FLAG_100);
 																									DAT_80072df0->setFlag(ACTOR_FLAG_800);
 																									DAT_80072df0->setFlag(ACTOR_FLAG_8000);
 																									DAT_80072df0->_walkSpeed = 0x14000;
-																									DAT_80072df0->priorityLayer = 3;
+																									DAT_80072df0->_priorityLayer = 3;
 
 																									DAT_80072df4->setFlag(ACTOR_FLAG_100);
 																									DAT_80072df4->setFlag(ACTOR_FLAG_800);
 																									DAT_80072df4->setFlag(ACTOR_FLAG_8000);
 																									DAT_80072df4->_walkSpeed = 0x1c000;
-																									DAT_80072df4->priorityLayer = 3;
+																									DAT_80072df4->_priorityLayer = 3;
 
 																									DAT_80072df8->setFlag(ACTOR_FLAG_100);
 																									DAT_80072df8->setFlag(ACTOR_FLAG_800);
 																									DAT_80072df8->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072df8->priorityLayer = 3;
+																									DAT_80072df8->_priorityLayer = 3;
 
 																									_vm->waitForFramesAllowSkip(0xe);
 																									// call_fade_related_1f();
@@ -272,8 +272,8 @@ void CutScene::scene1() {
 
 																									_vm->_talk->displayDialogAroundPoint(dialog,0x27,0xc,0xc01,0,0x5ea2);
 																									DAT_80072df0->waitUntilFlag8And4AreSet();
-																									DAT_80072df0->x_pos = 0xcf;
-																									DAT_80072df0->y_pos = 0x90;
+																									DAT_80072df0->_x_pos = 0xcf;
+																									DAT_80072df0->_y_pos = 0x90;
 																									DAT_80072df0->startWalk(0x97, 0x37, 2);
 																									DAT_80072df0->updateSequence(7);
 //TODO
@@ -399,7 +399,7 @@ void CutScene::FUN_8003d388() {
 	DAT_800830bc = _vm->_actorManager->loadActor(0xaa,1,0x115,0x22,1);
 	DAT_800830bc->setFlag(ACTOR_FLAG_100);
 	DAT_800830bc->setFlag(ACTOR_FLAG_8000);
-	DAT_800830bc->priorityLayer = 4;
+	DAT_800830bc->_priorityLayer = 4;
 	if ((DAT_80063514 & 0x100) != 0) {
 		DAT_800830c0 = _vm->_actorManager->loadActor(0x7e,0x1c,0x21,0x87,1);
 	}
@@ -461,7 +461,7 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 		_vm->_screen->loadPalette(0, _palettes + 2 * 512);
 		for (int i = 2; i < 0x17; i++) {
 			Actor *actor = _vm->_actorManager->getActor(i);
-			actor->x_pos += 0x3c0;
+			actor->_x_pos += 0x3c0;
 		}
 	}
 	else {
@@ -508,7 +508,7 @@ void CutScene::diamondScene() {
 	actorId_03 = _vm->getINI(0x259)->actor;
 	actorId_01 = _vm->getINI(0x258)->actor;
 	actorId_03->setFlag(ACTOR_FLAG_100);
-	actorId_03->priorityLayer = 4;
+	actorId_03->_priorityLayer = 4;
 	actorId_00 = _vm->getINI(0x256)->actor;
 	_vm->setFlags(ENGINE_FLAG_20000);
 	actorId_02 = _vm->getINI(0x25a)->actor;
@@ -534,9 +534,9 @@ void CutScene::diamondScene() {
 					actorId->updateSequence(4);
 					_vm->waitForFramesAllowSkip(0x17);
 					actorId_03->updateSequence(9);
-					actorId_03->x_pos = 0x82;
-					actorId_03->y_pos = 0xc4;
-					actorId_03->priorityLayer = 4;
+					actorId_03->_x_pos = 0x82;
+					actorId_03->_y_pos = 0xc4;
+					actorId_03->_priorityLayer = 4;
 					if (!actorId->waitUntilFlag4IsSetAllowSkip()) {
 						actorId->updateSequence(5);
 						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_01,0x10,2,0x42ac2,0x3c01) != 2 &&
@@ -684,10 +684,10 @@ void CutScene::flameReturnsCutScene() {
 	DAT_80063514 = (DAT_80063514 & 0xfffe) | 0x600;
 	FUN_8003d388();
 	DAT_80072de8->updateSequence(0x1f);
-	DAT_80072e04->x_pos = 0x10b;
-	DAT_80072e04->y_pos = 99;
-	DAT_80072de8->x_pos = 0x10a;
-	DAT_80072de8->y_pos = 0x5a;
+	DAT_80072e04->_x_pos = 0x10b;
+	DAT_80072e04->_y_pos = 99;
+	DAT_80072de8->_x_pos = 0x10a;
+	DAT_80072de8->_y_pos = 0x5a;
 	DAT_80072de8->_walkSpeed = 0x10000;
 	DAT_80072e04->_walkSpeed = 0x10000;
 	DAT_80072de8->setFlag(ACTOR_FLAG_800);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index b288503afa..04609b07fd 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -240,8 +240,8 @@ uint16 DragonsEngine::ipt_img_file_related() {
     DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 	assert(flicker);
 
-	int16 tileX = flicker->actor->x_pos / 32;
-	int16 tileY = flicker->actor->y_pos / 8;
+	int16 tileX = flicker->actor->_x_pos / 32;
+	int16 tileY = flicker->actor->_y_pos / 8;
 
 	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
@@ -285,7 +285,7 @@ void DragonsEngine::gameLoop() {
 		_counter++;
 		if (0x4af < _counter) {
 			pDVar8 = _dragonINIResource->getFlickerRecord();
-			if (pDVar8->actor->resourceID == 0xe) {
+			if (pDVar8->actor->_resourceID == 0xe) {
 				pDVar8->actor->_sequenceID2 = 2;
 				pDVar8->field_20_actor_field_14 = 2;
 				if (getINI(0xc2)->field_1e == 1) {
@@ -560,14 +560,14 @@ void DragonsEngine::gameLoop() {
 				actorId = uVar3;
 				if (tmpId != 0) {
 					actor->_flags = 0;
-					actor->priorityLayer = 0;
-					actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+					actor->_priorityLayer = 0;
+					actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 					actor->updateSequence(getINI(tmpId - 1)->field_8 * 2 + 10);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);
 					actor->setFlag(ACTOR_FLAG_200);
-					actor->priorityLayer = 6;
+					actor->_priorityLayer = 6;
 					actorId = uVar3;
 				}
 				continue;
@@ -577,8 +577,8 @@ void DragonsEngine::gameLoop() {
 			if (_inventory->addItemIfPositionIsEmpty(_cursor->iniItemInHand, _cursor->_x, _cursor->_y)) {
 				Actor *invActor = _inventory->getInventoryItemActor(_cursor->iniItemInHand);
 				invActor->_flags = 0;
-				invActor->priorityLayer = 0;
-				invActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+				invActor->_priorityLayer = 0;
+				invActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 				invActor->updateSequence(
 						 getINI(_cursor->iniItemInHand - 1)->field_8 * 2 + 10);
 				_cursor->iniItemInHand = 0;
@@ -586,7 +586,7 @@ void DragonsEngine::gameLoop() {
 				invActor->setFlag(ACTOR_FLAG_80);
 				invActor->setFlag(ACTOR_FLAG_100);
 				invActor->setFlag(ACTOR_FLAG_200);
-				invActor->priorityLayer = 6;
+				invActor->_priorityLayer = 6;
 				if (_cursor->_sequenceID == 5) {
 					_cursor->_sequenceID = 4;
 				}
@@ -624,29 +624,29 @@ void DragonsEngine::updateHandler() {
 		Actor *actor = _actorManager->getActor(i);
 		if (actor->_flags & Dragons::ACTOR_FLAG_40) {
 			if (!(actor->_flags & Dragons::ACTOR_FLAG_100)) {
-				int16 priority = _scene->getPriorityAtPosition(Common::Point(actor->x_pos, actor->y_pos));
+				int16 priority = _scene->getPriorityAtPosition(Common::Point(actor->_x_pos, actor->_y_pos));
 				DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 				if (flicker && _scene->contains(flicker) && flicker->actor->_actorID == i) {
 					if (priority < 8 || priority == 0x10) {
-						actor->priorityLayer = priority;
+						actor->_priorityLayer = priority;
 					}
 				} else {
 					if (priority != -1) {
-						actor->priorityLayer = priority;
+						actor->_priorityLayer = priority;
 					}
 				}
 
-				if (actor->priorityLayer >= 0x11) {
-					actor->priorityLayer = 0;
+				if (actor->_priorityLayer >= 0x11) {
+					actor->_priorityLayer = 0;
 				}
 
-				if (actor->priorityLayer >= 9) {
-					actor->priorityLayer -= 8;
+				if (actor->_priorityLayer >= 9) {
+					actor->_priorityLayer -= 8;
 				}
 			}
 
-			if (actor->sequenceTimer != 0) {
-				actor->sequenceTimer--;
+			if (actor->_sequenceTimer != 0) {
+				actor->_sequenceTimer--;
 			}
 		}
 	}
@@ -654,8 +654,8 @@ void DragonsEngine::updateHandler() {
 	if (_flags & Dragons::ENGINE_FLAG_80) {
 		for (uint16 i = 0x17; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
 			Actor *actor = _actorManager->getActor(i);
-			if (actor->sequenceTimer != 0) {
-				actor->sequenceTimer--;
+			if (actor->_sequenceTimer != 0) {
+				actor->_sequenceTimer--;
 			}
 		}
 	}
@@ -720,7 +720,7 @@ void DragonsEngine::updateActorSequences() {
 		if (actor->_flags & Dragons::ACTOR_FLAG_40 &&
 			!(actor->_flags & Dragons::ACTOR_FLAG_4) &&
 			!(actor->_flags & Dragons::ACTOR_FLAG_400) &&
-			(actor->sequenceTimer == 0 || actor->_flags & Dragons::ACTOR_FLAG_1)) {
+			(actor->_sequenceTimer == 0 || actor->_flags & Dragons::ACTOR_FLAG_1)) {
 			debug(5, "Actor[%d] execute sequenceOp", actorId);
 
 			if (actor->_flags & Dragons::ACTOR_FLAG_1) {
@@ -729,7 +729,7 @@ void DragonsEngine::updateActorSequences() {
 				actor->clearFlag(ACTOR_FLAG_1);
 				actor->clearFlag(ACTOR_FLAG_8);
 				actor->clearFlag(ACTOR_FLAG_1000);
-				actor->field_7a = 0;
+				actor->_field_7a = 0;
 			}
 			OpCall opCall;
 			opCall._result = 1;
@@ -803,8 +803,8 @@ void DragonsEngine::setVar(uint16 offset, uint16 value) {
 uint16 DragonsEngine::getIniFromImg() {
 	DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 
-	int16 x = flicker->actor->x_pos / 32;
-	int16 y = flicker->actor->y_pos / 8;
+	int16 x = flicker->actor->_x_pos / 32;
+	int16 y = flicker->actor->_y_pos / 8;
 
 	uint16 currentSceneId = _scene->getSceneId();
 
@@ -862,7 +862,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 //		if ((flickerINI->sceneId == currentSceneId)
 //			&& (uVar5 != 0xffff)) {
 //			actors[(uint)uVar5]._sequenceID = 8;
-//			actors[(uint)uVar5].priorityLayer_maybe = 0;
+//			actors[(uint)uVar5]._priorityLayer_maybe = 0;
 //		}
 	}
 	else {
@@ -871,7 +871,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 				if ((flickerINI->sceneId == currentSceneId)
 					&& (uVar5 != 0xffff)) {
 //					actors[(uint)uVar5]._sequenceID = 8;
-//					actors[(uint)uVar5].priorityLayer_maybe = 0;
+//					actors[(uint)uVar5]._priorityLayer_maybe = 0;
 				}
 			} else {
 				if ((bit_flags_8006fbd8 & 2) == 0) {
@@ -885,7 +885,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 			}
 
 		} else {
-			//actors[(uint)uVar5].priorityLayer_maybe = 0;
+			//actors[(uint)uVar5]._priorityLayer_maybe = 0;
 		}
 
 	}
@@ -935,7 +935,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 //		if ((flickerINI->sceneId == currentSceneId)
 //			&& (uVar5 != 0xffff)) {
 //			actors[(uint)uVar5]._sequenceID = 8;
-//			actors[(uint)uVar5].priorityLayer_maybe = 0;
+//			actors[(uint)uVar5]._priorityLayer_maybe = 0;
 //		}
 		}
 		else {
@@ -1163,8 +1163,8 @@ void DragonsEngine::walkFlickerToObject()
 					targetY = img->field_c;
 				}
 				else {
-					targetX = targetINI->actor->x_pos;
-					targetY = targetINI->actor->y_pos;
+					targetX = targetINI->actor->_x_pos;
+					targetY = targetINI->actor->_y_pos;
 				}
 				flickerINI->actor->_walkSpeed = 0x10000;
 				if (flickerINI->field_20_actor_field_14 == -1) {
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 537a472b4f..41a2bbce4d 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -77,11 +77,11 @@ Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 
 void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag, DragonINIResource *dragonIniResource) {
 	_actor = actorManager->loadActor(1, 1); //Load inventory
-	_actor->x_pos = 2;
-	_actor->y_pos = 0;
-	_actor->priorityLayer = 6;
+	_actor->_x_pos = 2;
+	_actor->_y_pos = 0;
+	_actor->_priorityLayer = 6;
 	_actor->_flags = 0;
-	_actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	_actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_actor->updateSequence(0);
 	_actor->_flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
 					   Dragons::ACTOR_FLAG_200);
@@ -113,7 +113,7 @@ void Inventory::loadScene(uint32 sceneId) {
 }
 
 void Inventory::updateVisibility() {
-	_actor->priorityLayer = _vm->isFlagSet(Dragons::ENGINE_FLAG_10) ? (int16)6 : (int16)0;
+	_actor->_priorityLayer = _vm->isFlagSet(Dragons::ENGINE_FLAG_10) ? (int16)6 : (int16)0;
 }
 
 Common::Point Inventory::getPosition() {
@@ -129,7 +129,7 @@ void Inventory::clearActorFlag400() {
 }
 
 void Inventory::setPriority(uint16 priority) {
-	_actor->priorityLayer = priority;
+	_actor->_priorityLayer = priority;
 }
 
 void Inventory::setActorSequenceId(int32 sequenceId) {
@@ -157,11 +157,11 @@ void Inventory::openInventory() {
 	}
 	_actor->updateSequence(_sequenceId);
 	_screenPositionIndex = 1;
-	_actor->x_pos = positionTable[_screenPositionIndex].x;
+	_actor->_x_pos = positionTable[_screenPositionIndex].x;
 	if ((_sequenceId == 0) || (_sequenceId == 2)) {
-		_actor->x_pos = positionTable[_screenPositionIndex].x + 0x32;
+		_actor->_x_pos = positionTable[_screenPositionIndex].x + 0x32;
 	}
-	_actor->y_pos = positionTable[_screenPositionIndex].y;
+	_actor->_y_pos = positionTable[_screenPositionIndex].y;
 	animateBagIn();
 
 	//TODO 0x800310e0 update cursor position.
@@ -169,19 +169,19 @@ void Inventory::openInventory() {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		Actor *item = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 
-		item->x_pos = item->_walkDestX = invXPosTable[i] + 0x10;
-		item->y_pos = item->_walkDestY = invYPosTable[i] + 0xc;
+		item->_x_pos = item->_walkDestX = invXPosTable[i] + 0x10;
+		item->_y_pos = item->_walkDestY = invYPosTable[i] + 0xc;
 
 		if (inventoryItemTbl[i]) {
 			item->_flags = 0; //clear all flags
-			item->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-			item->priorityLayer = 0;
+			item->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+			item->_priorityLayer = 0;
 			item->updateSequence(_vm->getINI(inventoryItemTbl[i] - 1)->field_8 * 2 + 10);
 			item->setFlag(ACTOR_FLAG_200);
 			item->setFlag(ACTOR_FLAG_100);
 			item->setFlag(ACTOR_FLAG_80);
 			item->setFlag(ACTOR_FLAG_40);
-			item->priorityLayer = 6;
+			item->_priorityLayer = 6;
 		}
 	}
 }
@@ -243,11 +243,11 @@ void Inventory::closeInventory() {
 		}
 	}
 	_actor->updateSequence(_sequenceId);
-	_actor->x_pos = positionTable[_screenPositionIndex].x;
+	_actor->_x_pos = positionTable[_screenPositionIndex].x;
 	if (((_sequenceId == 0) || (_sequenceId == 2)) && ((_screenPositionIndex == 1 || (_screenPositionIndex == 3)))) {
-		_actor->x_pos += 0x32;
+		_actor->_x_pos += 0x32;
 	}
-	_actor->y_pos = positionTable[_screenPositionIndex].y;
+	_actor->_y_pos = positionTable[_screenPositionIndex].y;
 	animateBagOut();
 }
 
@@ -261,8 +261,8 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		if (inventoryItemTbl[i]) {
 			Actor *item = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
-			if (item->x_pos - 0x10 <= x && x < item->x_pos + 0x10
-				&& item->y_pos - 0xc <= y && y < item->y_pos + 0xc) {
+			if (item->_x_pos - 0x10 <= x && x < item->_x_pos + 0x10
+				&& item->_y_pos - 0xc <= y && y < item->_y_pos + 0xc) {
 				return inventoryItemTbl[i];
 			}
 		}
@@ -291,7 +291,7 @@ void Inventory::openInventionBook() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	if (flicker && flicker->actor) {
 		inventionBookPrevFlickerINISceneId = flicker->sceneId;
-		inventionBookPrevFlickerINIPosition = Common::Point(flicker->actor->x_pos, flicker->actor->y_pos);
+		inventionBookPrevFlickerINIPosition = Common::Point(flicker->actor->_x_pos, flicker->actor->_y_pos);
 		flicker->sceneId = 0;
 	}
 	_vm->_scene->setSceneId(2);
@@ -306,8 +306,8 @@ void Inventory::closeInventionBook() {
 
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	if (flicker && flicker->actor) {
-		flicker->actor->x_pos = inventionBookPrevFlickerINIPosition.x;
-		flicker->actor->y_pos = inventionBookPrevFlickerINIPosition.y;
+		flicker->actor->_x_pos = inventionBookPrevFlickerINIPosition.x;
+		flicker->actor->_y_pos = inventionBookPrevFlickerINIPosition.y;
 		flicker->sceneId = inventionBookPrevFlickerINISceneId;
 	}
 	_vm->_scene->setSceneId(inventionBookPrevSceneId);
@@ -338,11 +338,11 @@ void Inventory::closeInventionBook() {
 void Inventory::setPositionFromSceneId(uint32 sceneId) {
 	_screenPositionIndex = _vm->_dragonRMS->getInventoryPosition(sceneId);
 
-	_actor->x_pos = positionTable[_screenPositionIndex].x;
+	_actor->_x_pos = positionTable[_screenPositionIndex].x;
 	if ((_sequenceId == 0 || _sequenceId == 2) && (_screenPositionIndex == 1 || _screenPositionIndex == 3)) {
-		_actor->x_pos += 0x32;
+		_actor->_x_pos += 0x32;
 	}
-	_actor->y_pos = positionTable[_screenPositionIndex].y;
+	_actor->_y_pos = positionTable[_screenPositionIndex].y;
 }
 
 bool Inventory::addItem(uint16 initId) {
@@ -377,10 +377,10 @@ void Inventory::replaceItem(uint16 existingIniId, uint16 newIniId) {
 bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		Actor *actor = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
-		if ((((actor->x_pos - 0x10 <= x) &&
-			  (x < actor->x_pos + 0x10)) &&
-			 (actor->y_pos - 0xc <= y)) &&
-			(y < actor->y_pos + 0xc)) {
+		if ((((actor->_x_pos - 0x10 <= x) &&
+			  (x < actor->_x_pos + 0x10)) &&
+			 (actor->_y_pos - 0xc <= y)) &&
+			(y < actor->_y_pos + 0xc)) {
 			inventoryItemTbl[i] = iniId;
 			return true;
 		}
@@ -405,7 +405,7 @@ void Inventory::inventoryMissing() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	if (flicker->actor != NULL) {
 		flicker->actor->clearFlag(ACTOR_FLAG_10);
-		if ((_vm->getCurrentSceneId() != 0x2e) || (flicker->actor->resourceID != 0x91)) {
+		if ((_vm->getCurrentSceneId() != 0x2e) || (flicker->actor->_resourceID != 0x91)) {
 			flicker->actor->setFlag(ACTOR_FLAG_4);
 		}
 	}
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 3b394be309..aa9df0c506 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -165,7 +165,7 @@ void Minigame1::run() {
 
 	originalFlickerIniID = _vm->_dragonINIResource->getFlickerRecord();
 	originalFlickerIniID->actor->setFlag(ACTOR_FLAG_100);
-	originalFlickerIniID->actor->priorityLayer = 0;
+	originalFlickerIniID->actor->_priorityLayer = 0;
 
 	savedEngineFlags = _vm->getMultipleFlags(ENGINE_FLAG_8 | ENGINE_FLAG_10 | ENGINE_FLAG_20 | ENGINE_FLAG_80);
 	_vm->clearFlags(ENGINE_FLAG_8);
@@ -175,34 +175,34 @@ void Minigame1::run() {
 	_vm->_dragonINIResource->setFlickerRecord(_vm->getINI(DAT_80063a40 - 1));
 	flickerActor = _vm->getINI(DAT_80063a40 - 1)->actor;
 	flickerActor->_flags = flickerActor->_flags | 0x380;
-	flickerActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	flickerActor->priorityLayer = 4;
+	flickerActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	flickerActor->_priorityLayer = 4;
 	flickerActor->_sequenceID2 = -1;
 	flickerActor->updateSequence(0x15);
 	hitCounter = 0;
 	local_254 = 0;
 	local_252 = 0;
-	flickerXPos = flickerActor->x_pos;
+	flickerXPos = flickerActor->_x_pos;
 	local_25c = 0;
 	pusherActor = _vm->_actorManager->loadActor(0x26,1, flickerXPos,
-								  (int)(((uint)(uint16)flickerActor->y_pos + 5) * 0x10000) >> 0x10);
+								  (int)(((uint)(uint16)flickerActor->_y_pos + 5) * 0x10000) >> 0x10);
 //	if (pusherActorId == -1) {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_pusher_8008e954,2,4,0,0xffffffff);
 //	}
 	pusherActor->_flags = pusherActor->_flags | 0x380;
-	pusherActor->x_pos = flickerActor->x_pos + -0xe;
-	pusherActor->y_pos = flickerActor->y_pos + 7;
-	pusherActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	pusherActor->priorityLayer = 6;
+	pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
+	pusherActor->_y_pos = flickerActor->_y_pos + 7;
+	pusherActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	pusherActor->_priorityLayer = 6;
 	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
 //	if (wheelsActorId == -1) {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_wheels_8008e96c,2,4,0,0xffffffff);
 //	}
 	wheelsActor->_flags = wheelsActor->_flags | 0x380;
-	wheelsActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	wheelsActor->x_pos = flickerActor->x_pos;
-	wheelsActor->y_pos = flickerActor->y_pos;
-	wheelsActor->priorityLayer = 5;
+	wheelsActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	wheelsActor->_x_pos = flickerActor->_x_pos;
+	wheelsActor->_y_pos = flickerActor->_y_pos;
+	wheelsActor->_priorityLayer = 5;
 	wheelsActor->updateSequence(0x11);
 	local_242 = 0;
 	catActor = _vm->_actorManager->loadActor(7,9,0,0);
@@ -210,8 +210,8 @@ void Minigame1::run() {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc-cat_8008e984,2,4,0,0xffffffff);
 //	}
 	catActor->_flags = catActor->_flags | 0x380;
-	catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	catActor->priorityLayer = 0;
+	catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	catActor->_priorityLayer = 0;
 	i = 0;
 	while (i < 3) {
 		targetActorIdTbl[(uint)i + 1] = _vm->_actorManager->loadActor(8,1,0,0,0);
@@ -219,7 +219,7 @@ void Minigame1::run() {
 //			ProbablyShowASCIIMessage(s_couldn't_alloc_target!_8008e998,2,4,0,0xffffffff);
 //		}
 		targetActorIdTbl[(uint)i + 1]->_flags = targetActorIdTbl[(uint)i + 1]->_flags | 0x380;
-		targetActorIdTbl[(uint)i + 1]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+		targetActorIdTbl[(uint)i + 1]->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 		auStack378[(uint)i] = 0;
 		//TODO FUN_80017010_update_actor_texture_maybe(1);
 		i = i + 1;
@@ -234,20 +234,20 @@ void Minigame1::run() {
 //		ProbablyShowASCIIMessage(s_couldn't_alloc_dust_sprite!_8008e9b0,2,5,0,0xffffffff);
 //	}
 	dustSpriteActor->_flags = dustSpriteActor->_flags | 0x380;
-	dustSpriteActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	dustSpriteActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	uVar1 = _vm->getINI(DAT_80063a48 - 1)->actor; //dragon_ini_pointer[DAT_80063a48 + -1].actorId;
 	local_21e = 0;
-	actorFieldC = uVar1->field_c;
+	actorFieldC = uVar1->_field_c;
 	_vm->setFlags(ENGINE_FLAG_4000000);
 	local_23e = 0x3700;
 	local_23a = 0x100;
 	local_240 = 0x4a80;
 	local_238 = 0;
 	catFieldE_scaleMaybe = 0x30;
-	catActor->y_pos = 0x6e;
-	catActor->x_pos = 0x95;
-	catActor->scale = 0x30;
-	catActor->priorityLayer = 2;
+	catActor->_y_pos = 0x6e;
+	catActor->_x_pos = 0x95;
+	catActor->_scale = 0x30;
+	catActor->_priorityLayer = 2;
 	catActor->updateSequence(0xb);
 	gameState = 5;
 	local_246 = 1;
@@ -263,7 +263,7 @@ void Minigame1::run() {
 				_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
 			}
 			if ((local_21e == 1) && (local_252 == 0)) {
-				uVar1->field_c = actorFieldC;
+				uVar1->_field_c = actorFieldC;
 			}
 			if (local_21e != 0) {
 				local_21e = local_21e + -1;
@@ -308,8 +308,8 @@ void Minigame1::run() {
 							local_25c = 0;
 						}
 						else {
-							pusherActor->x_pos = flickerActor->x_pos + -0xe;
-							pusherActor->y_pos = flickerActor->y_pos + 7;
+							pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
+							pusherActor->_y_pos = flickerActor->_y_pos + 7;
 							if (local_25c < 0x168) {
 								local_25c = local_25c + 1;
 								if (local_25c < 0x14) {
@@ -378,15 +378,15 @@ void Minigame1::run() {
 											(short)((int)((uint)flickerXPos << 7) / 0x2a);
 							}
 							local_240 = flickerXPos << 7;
-							catActor->x_pos = flickerXPos & 0x1ff;
+							catActor->_x_pos = flickerXPos & 0x1ff;
 							local_23e = 0x2d00;
 							local_23a = (local_25a + 3) * 0x80;
-							catActor->y_pos = 0x5a;
+							catActor->_y_pos = 0x5a;
 							catFieldE_scaleMaybe = 0x100;
-							catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+							catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 							catActor->updateSequence(0xc);
 							_vm->playOrStopSound(5);
-							catActor->priorityLayer = 3;
+							catActor->_priorityLayer = 3;
 							flickerActor->updateSequence(8);
 							gameState = 3;
 						}
@@ -414,10 +414,10 @@ void Minigame1::run() {
 							local_23a = 0;
 						}
 					}
-					catActor->x_pos = local_240 >> 7;
-					catActor->y_pos = local_23e >> 7;
+					catActor->_x_pos = local_240 >> 7;
+					catActor->_y_pos = local_23e >> 7;
 					catFieldE_scaleMaybe = catFieldE_scaleMaybe - 3;
-					catActor->scale = catFieldE_scaleMaybe;
+					catActor->_scale = catFieldE_scaleMaybe;
 					if (catFieldE_scaleMaybe == 0x7f) {
 						i = 0;
 						while ((i < 8 && (((local_240 >> 7 < auStack352[(uint)i * 3] ||
@@ -426,7 +426,7 @@ void Minigame1::run() {
 							i = i + 1;
 						}
 						if ((i != 8) && (local_188[(uint)i] != 0)) {
-							uVar1->field_c = 2;
+							uVar1->_field_c = 2;
 							local_21e = 0x3c;
 							if (local_250 != 0) {
 								_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
@@ -452,12 +452,12 @@ void Minigame1::run() {
 										 local_118[((uint)hitCounter - 1) * 2]);
 								local_250 = *(short *)(local_118 + ((uint)hitCounter - 1) * 2 + 1);
 							}
-							targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->priorityLayer = 3;
+							targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->_priorityLayer = 3;
 							if (i == 0) {
 								targetActorIdTbl[(uint)local_188[0]]->updateSequence(7);
 							}
 							else {
-								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->y_pos -= 3;
+								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->_y_pos -= 3;
 								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(6);
 							}
 							auStack378[(uint)(uint16)local_188[(uint)i] - 1] = 0;
@@ -473,30 +473,30 @@ void Minigame1::run() {
 							  ((local_25a == 3 &&
 								(((0x3c < local_240 >> 7 && (local_240 >> 7 < 0x46)) ||
 								  ((0x101 < local_240 >> 7 && (local_240 >> 7 < 0x10a)))))))))) {
-							dustSpriteActor->x_pos = catActor->x_pos;
-							dustSpriteActor->y_pos = catActor->y_pos + 2;
+							dustSpriteActor->_x_pos = catActor->_x_pos;
+							dustSpriteActor->_y_pos = catActor->_y_pos + 2;
 							dustSpriteActor->updateSequence(8);
-							catActor->priorityLayer = 4;
-							dustSpriteActor->priorityLayer = 3;
+							catActor->_priorityLayer = 4;
+							dustSpriteActor->_priorityLayer = 3;
 							catActor->updateSequence(0xd);
 							gameState = 4;
 							_vm->playOrStopSound(6);
 						}
 					}
 					if (catFieldE_scaleMaybe < 0x7f) {
-						catActor->priorityLayer = 2;
+						catActor->_priorityLayer = 2;
 					}
 					if ((0xc < catFieldE_scaleMaybe) && (catFieldE_scaleMaybe < 0x41)) {
-						catActor->priorityLayer = 0;
+						catActor->_priorityLayer = 0;
 					}
 					if ((short)catFieldE_scaleMaybe < 2) {
 						local_23e = 0x3700;
 						local_23a = 0x100;
 						local_240 = 0x4a80;
 						catFieldE_scaleMaybe = 0x30;
-						catActor->y_pos = 0x6e;
-						catActor->x_pos = 0x95;
-						catActor->scale = 0x30;
+						catActor->_y_pos = 0x6e;
+						catActor->_x_pos = 0x95;
+						catActor->_scale = 0x30;
 						catActor->updateSequence(0xb);
 						gameState = 5;
 					}
@@ -508,7 +508,7 @@ void Minigame1::run() {
 							if (local_23e < 0x4300) {
 								local_23e = local_23e + local_23a;
 								local_23a = local_23a + 0x18;
-								catActor->y_pos = local_23e >> 7;
+								catActor->_y_pos = local_23e >> 7;
 							}
 							else {
 								catActor->updateSequence(0xf);
@@ -517,8 +517,8 @@ void Minigame1::run() {
 							}
 						}
 						else {
-							dustSpriteActor->priorityLayer = 0;
-							catActor->priorityLayer = 3;
+							dustSpriteActor->_priorityLayer = 0;
+							catActor->_priorityLayer = 3;
 							catActor->updateSequence(0xe);
 							_vm->playOrStopSound(8);
 							local_23a = 0x40;
@@ -529,8 +529,8 @@ void Minigame1::run() {
 					if (local_23e >> 7 < 0x86) {
 						local_23e = local_23e + local_23a;
 						catFieldE_scaleMaybe = catFieldE_scaleMaybe + 8;
-						catActor->y_pos = local_23e >> 7;
-						catActor->scale = catFieldE_scaleMaybe;
+						catActor->_y_pos = local_23e >> 7;
+						catActor->_scale = catFieldE_scaleMaybe;
 					}
 					else {
 						gameState = 6;
@@ -539,7 +539,7 @@ void Minigame1::run() {
 					}
 					break;
 				case 6: // cat run across field
-					catActor->priorityLayer = 3;
+					catActor->_priorityLayer = 3;
 					if (local_252 == 0) {
 						if (catActor->_sequenceID == 0xf) {
 							if ((catActor->_flags & 4) != 0) {
@@ -552,8 +552,8 @@ void Minigame1::run() {
 									catFieldE_scaleMaybe = 0x80;
 									local_23e = 0x4300;
 									local_23a = 0x100;
-									catActor->y_pos = 0x86;
-									catActor->scale = 0x80;
+									catActor->_y_pos = 0x86;
+									catActor->_scale = 0x80;
 									catActor->updateSequence(0xb);
 									if (flickerXPos < local_240 >> 7) {
 										sVar2 = flickerXPos + 0x32;
@@ -575,9 +575,9 @@ void Minigame1::run() {
 										if (0x100 < catFieldE_scaleMaybe) {
 											catFieldE_scaleMaybe = 0x100;
 										}
-										catActor->scale = catFieldE_scaleMaybe;
-										catActor->y_pos = local_23e >> 7;
-										catActor->x_pos = local_240 >> 7;
+										catActor->_scale = catFieldE_scaleMaybe;
+										catActor->_y_pos = local_23e >> 7;
+										catActor->_x_pos = local_240 >> 7;
 										local_238 = 1;
 									}
 									else {
@@ -587,20 +587,20 @@ void Minigame1::run() {
 								else {
 									if ((int)(uint)(local_240 >> 7) < (int)((uint)flickerXPos - 0x32)) {
 										if (catActor->_sequenceID != 9) {
-											catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+											catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 											catActor->updateSequence(9);
 										}
 										local_240 = local_240 + 0x180;
-										catActor->x_pos = local_240 >> 7;
+										catActor->_x_pos = local_240 >> 7;
 									}
 									else {
 										if ((uint)flickerXPos + 0x32 < (uint)(local_240 >> 7)) {
 											if (catActor->_sequenceID != 10) {
-												catActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+												catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 												catActor->updateSequence(10);
 											}
 											local_240 = local_240 - 0x180;
-											catActor->x_pos = local_240 >> 7;
+											catActor->_x_pos = local_240 >> 7;
 										}
 										else {
 											gameState = 7;
@@ -612,11 +612,11 @@ void Minigame1::run() {
 					}
 					break;
 				case 7: // cat jumping into catapult
-					if (catActor->priorityLayer == 0) {
+					if (catActor->_priorityLayer == 0) {
 						gameState = 1;
 					}
 					else {
-						catActor->priorityLayer = 0;
+						catActor->_priorityLayer = 0;
 						if (local_240 >> 7 < flickerXPos) {
 							flickerActor->updateSequence(5);
 						}
@@ -632,7 +632,7 @@ void Minigame1::run() {
 						}
 						else {
 							local_23a--;
-							catActor->y_pos = catActor->y_pos + 2;
+							catActor->_y_pos = catActor->_y_pos + 2;
 						}
 					}
 					else {
@@ -646,17 +646,17 @@ void Minigame1::run() {
 							if (local_234 == 2) {
 								local_23e = 0x4100;
 								local_240 = 0x4a80;
-								catActor->y_pos = 0x82;
-								catActor->x_pos = 0x95;
-								catActor->priorityLayer = 3;
-								catActor->scale = 0x80;
+								catActor->_y_pos = 0x82;
+								catActor->_x_pos = 0x95;
+								catActor->_priorityLayer = 3;
+								catActor->_scale = 0x80;
 								catActor->updateSequence(0x10);
 								gameState = 6;
 							}
 							else {
 								if (local_234 == 3) {
 									if (local_232 == 0) {
-										catActor->priorityLayer = 2;
+										catActor->_priorityLayer = 2;
 										local_23a = 8;
 										local_234 = 1;
 									}
@@ -671,7 +671,7 @@ void Minigame1::run() {
 				default:
 					//ProbablyShowASCIIMessage(s_undefined_state!_8008e9cc,2,3,0,0xffffffff);
 					gameState = 1;
-					catActor->priorityLayer = 0;
+					catActor->_priorityLayer = 0;
 					flickerActor->updateSequence(0);
 			}
 			if ((local_252 == 0) && (gameState != 2)) {
@@ -683,12 +683,12 @@ void Minigame1::run() {
 						(pusherActor->_sequenceID != 6)))) {
 							pusherActor->updateSequence((uint)local_246);
 							if (bVar3) {
-								pusherActor->x_pos = flickerActor->x_pos + 2;
-								pusherActor->y_pos = flickerActor->y_pos;
+								pusherActor->_x_pos = flickerActor->_x_pos + 2;
+								pusherActor->_y_pos = flickerActor->_y_pos;
 							}
 							else {
-								pusherActor->x_pos = flickerActor->x_pos - 0xe;
-								pusherActor->y_pos = flickerActor->y_pos + 7;
+								pusherActor->_x_pos = flickerActor->_x_pos - 0xe;
+								pusherActor->_y_pos = flickerActor->_y_pos + 7;
 							}
 						}
 					}
@@ -713,14 +713,14 @@ void Minigame1::run() {
 						else {
 							local_242 = local_242 - 1;
 						}
-						flickerActor->x_pos = flickerXPos;
-						wheelsActor->x_pos = flickerXPos;
+						flickerActor->_x_pos = flickerXPos;
+						wheelsActor->_x_pos = flickerXPos;
 						if ((uint)wheelsActor->_sequenceID != (uint)local_242 / 3 + 0x11)
 						{
 							wheelsActor->updateSequence((uint)local_242 / 3 + 0x11);
 						}
-						pusherActor->x_pos = flickerActor->x_pos + 2;
-						pusherActor->y_pos = flickerActor->y_pos;
+						pusherActor->_x_pos = flickerActor->_x_pos + 2;
+						pusherActor->_y_pos = flickerActor->_y_pos;
 					}
 				}
 				else {
@@ -740,13 +740,13 @@ void Minigame1::run() {
 					}
 					local_242 = (short)((uint)local_242 + 1) +
 								(short)((int)((uint)local_242 + 1) / 6 >> 1) * -0xc;
-					flickerActor->x_pos = flickerXPos;
-					wheelsActor->x_pos = flickerXPos;
+					flickerActor->_x_pos = flickerXPos;
+					wheelsActor->_x_pos = flickerXPos;
 					if ((uint)wheelsActor->_sequenceID != (uint)local_242 / 3 + 0x11) {
 						wheelsActor->updateSequence((uint)local_242 / 3 + 0x11);
 					}
-					pusherActor->x_pos = flickerActor->x_pos + -2;
-					pusherActor->y_pos = flickerActor->y_pos;
+					pusherActor->_x_pos = flickerActor->_x_pos + -2;
+					pusherActor->_y_pos = flickerActor->_y_pos;
 				}
 			}
 			if ((local_22c < 0x16) && (auStack536[(uint)local_22c * 3 + 2] <= local_22e)) {
@@ -765,20 +765,20 @@ void Minigame1::run() {
 //							ProbablyShowASCIIMessage(s_too_many_targets!_8008e9e0,2,4,0,0xffffffff);
 						}
 						if (auStack536[(uint)local_22c * 3] == 0) {
-							targetActorIdTbl[(uint)i + 1]->x_pos = auStack352[(uint)auStack536[(uint)local_22c * 3] * 3] + 0xd;
+							targetActorIdTbl[(uint)i + 1]->_x_pos = auStack352[(uint)auStack536[(uint)local_22c * 3] * 3] + 0xd;
 						}
 						else {
-							targetActorIdTbl[(uint)i + 1]->x_pos = auStack352[(uint)auStack536[(uint)local_22c * 3] * 3] + 8;
+							targetActorIdTbl[(uint)i + 1]->_x_pos = auStack352[(uint)auStack536[(uint)local_22c * 3] * 3] + 8;
 						}
-						targetActorIdTbl[(uint)i + 1]->y_pos = (4 - auStack352[(uint)auStack536[(uint)local_22c * 3] * 3 + 2]) * 0x20;
-						targetActorIdTbl[(uint)i + 1]->priorityLayer = 2;
+						targetActorIdTbl[(uint)i + 1]->_y_pos = (4 - auStack352[(uint)auStack536[(uint)local_22c * 3] * 3 + 2]) * 0x20;
+						targetActorIdTbl[(uint)i + 1]->_priorityLayer = 2;
 						if (auStack536[(uint)local_22c * 3] == 0) {
 							targetActorIdTbl[(uint)i + 1]->updateSequence(3);
 						}
 						else {
 							targetActorIdTbl[(uint)i + 1]->updateSequence(0);
 						}
-						targetActorIdTbl[(uint)i + 1]->priorityLayer = 2;
+						targetActorIdTbl[(uint)i + 1]->_priorityLayer = 2;
 						local_188[(uint)auStack536[(uint)local_22c * 3]] = i + 1;
 						auStack378[(uint)i] = auStack536[(uint)local_22c * 3] + 1;
 					}
@@ -843,14 +843,14 @@ void Minigame1::run() {
 			}
 			local_22e = local_22e + 1;
 		} while (local_252 == 0);
-		if (flickerActor->x_pos < 0x118) {
-			flickerActor->x_pos = flickerActor->x_pos + 2;
+		if (flickerActor->_x_pos < 0x118) {
+			flickerActor->_x_pos = flickerActor->_x_pos + 2;
 			if (pusherActor->_sequenceID != 2) {
 				pusherActor->updateSequence(2);
 			}
-			pusherActor->x_pos = flickerActor->x_pos + 2;
-			pusherActor->y_pos = flickerActor->y_pos;
-			wheelsActor->x_pos = wheelsActor->x_pos + 2;
+			pusherActor->_x_pos = flickerActor->_x_pos + 2;
+			pusherActor->_y_pos = flickerActor->_y_pos;
+			wheelsActor->_x_pos = wheelsActor->_x_pos + 2;
 			if (local_242 == 0) {
 				local_242 = 0xb;
 			}
@@ -905,10 +905,10 @@ void Minigame1::run() {
 	_vm->_dragonINIResource->setFlickerRecord(originalFlickerIniID);
 	flickerActor = originalFlickerIniID->actor;
 	flickerActor->clearFlag(ACTOR_FLAG_100);
-	flickerActor->priorityLayer = 6; //TODO this is 2 in the original but that leave flicker invisible.
+	flickerActor->_priorityLayer = 6; //TODO this is 2 in the original but that leave flicker invisible.
 	_vm->clearFlags(ENGINE_FLAG_4000000);
 	_vm->setFlags(savedEngineFlags);
-	uVar1->field_c = actorFieldC;
+	uVar1->_field_c = actorFieldC;
 	return;
 }
 
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 5255782017..745c4a8078 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -178,17 +178,17 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uVar8 = _vm->_actorManager->loadActor(0xf,0,0x7d,199,4);
 	loungealotRightArm = _vm->_actorManager->loadActor(0x10, 0, 0x7d, 199, 4);
 	flickerArm = _vm->_actorManager->loadActor(9, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
-											   loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e,
-											   loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10, 4);
+											   loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e,
+											   loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10, 4);
 	loungealotThumb = _vm->_actorManager->loadActor(0x12, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
-													loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e,
-													loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10, 4);
+													loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e,
+													loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10, 4);
 	uVar12 = _vm->_actorManager->loadActor(10, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
-										   flickerArm->x_pos - flickerArm->frame->field_e,
-										   flickerArm->y_pos - flickerArm->frame->field_10, 4);
+										   flickerArm->_x_pos - flickerArm->_frame->field_e,
+										   flickerArm->_y_pos - flickerArm->_frame->field_10, 4);
 	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
-										   flickerArm->x_pos - flickerArm->frame->field_e,
-										   flickerArm->y_pos - flickerArm->frame->field_10, 4);
+										   flickerArm->_x_pos - flickerArm->_frame->field_e,
+										   flickerArm->_y_pos - flickerArm->_frame->field_10, 4);
 	uVar14 = _vm->_actorManager->loadActor(0x27,0,0x10,0xac,4);
 	uVar15 = _vm->_actorManager->loadActor(0x27,1,0x10,0x8c,4);
 	uVar5->setFlag(ACTOR_FLAG_100);
@@ -203,17 +203,17 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uVar14->setFlag(ACTOR_FLAG_100);
 	uVar15->setFlag(ACTOR_FLAG_100);
 
-	uVar5->priorityLayer = 6;
-	flickerArm->priorityLayer = 5;
-	uVar12->priorityLayer = 5;
-	loungealotThumb->priorityLayer = 4;
-	uVar13->priorityLayer = 3;
-	loungealotRightArm->priorityLayer = 3;
-	loungealotLeftUpperArm->priorityLayer = 2;
-	loungealotHeadActor->priorityLayer = 2;
-	uVar8->priorityLayer = 1;
-	uVar14->priorityLayer = 0;
-	uVar15->priorityLayer = 0;
+	uVar5->_priorityLayer = 6;
+	flickerArm->_priorityLayer = 5;
+	uVar12->_priorityLayer = 5;
+	loungealotThumb->_priorityLayer = 4;
+	uVar13->_priorityLayer = 3;
+	loungealotRightArm->_priorityLayer = 3;
+	loungealotLeftUpperArm->_priorityLayer = 2;
+	loungealotHeadActor->_priorityLayer = 2;
+	uVar8->_priorityLayer = 1;
+	uVar14->_priorityLayer = 0;
+	uVar15->_priorityLayer = 0;
 	//TODO
 //	uVar16 = AddFlatShadedQuad(0x28,0xa8,0x67,0xa8,0x67,0xaf,0x28,0xaf,0x1f,7,0);
 //	uVar17 = AddFlatShadedQuad(0x28,0x88,0x67,0x88,0x67,0x8f,0x28,0x8f,0x3e0,7,0);
@@ -238,14 +238,14 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uVar8->waitUntilFlag8And4AreSet();
 
 	uVar5->setFlag(ACTOR_FLAG_400);
-	flickerArm->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
-	flickerArm->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10;
-	loungealotThumb->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
-	loungealotThumb->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10;
-	uVar12->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e;
-	uVar12->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10;
-	uVar13->x_pos = loungealotLeftUpperArm->x_pos - flickerArm->frame->field_e;
-	uVar13->y_pos = loungealotLeftUpperArm->y_pos - flickerArm->frame->field_10;
+	flickerArm->_x_pos = loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e;
+	flickerArm->_y_pos = loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10;
+	loungealotThumb->_x_pos = loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e;
+	loungealotThumb->_y_pos = loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10;
+	uVar12->_x_pos = loungealotLeftUpperArm->_x_pos - flickerArm->_frame->field_e;
+	uVar12->_y_pos = loungealotLeftUpperArm->_y_pos - flickerArm->_frame->field_10;
+	uVar13->_x_pos = loungealotLeftUpperArm->_x_pos - flickerArm->_frame->field_e;
+	uVar13->_y_pos = loungealotLeftUpperArm->_y_pos - flickerArm->_frame->field_10;
 	_vm->waitForFrames(2);
 	// call_fade_related_1f();
 
@@ -308,9 +308,9 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		if (DAT_80093c94 != 0) {
 			local_264 = 0;
 		}
-		if (uVar8->field_7a == 1) {
+		if (uVar8->_field_7a == 1) {
 			shouldShakeScreen = true;
-			uVar8->field_7a = 0;
+			uVar8->_field_7a = 0;
 			screenShakeCounter = 0;
 		}
 		if (shouldShakeScreen) {
@@ -369,30 +369,30 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			if (!bVar4) {
 				//TODO FUN_8001a4e4_draw_dialogbox(4,0x14,0xd,0x16,1);
 				//TODO FUN_8001a4e4_draw_dialogbox(4,0x10,0xd,0x12,1);
-				uVar14->priorityLayer = 6;
-				uVar15->priorityLayer = 6;
+				uVar14->_priorityLayer = 6;
+				uVar15->_priorityLayer = 6;
 				bVar4 = true;
 			}
 		}
 		if ((((local_278 == 0) && (local_27a == 0)) && (local_258 == 0)) && (bVar4)) {
 			// TODO FUN_8001a7c4(4,0x14,0xd,0x16);
 			// TODO FUN_8001a7c4(4,0x10,0xd,0x12);
-			uVar14->priorityLayer = 0;
-			uVar15->priorityLayer = 0;
+			uVar14->_priorityLayer = 0;
+			uVar15->_priorityLayer = 0;
 			bVar4 = false;
 		}
 
 		//DisableVSyncEvent();
-		loungealotThumb->x_pos = loungealotLeftUpperArm->x_pos - loungealotLeftUpperArm->frame->field_e;
-		flickerArm->x_pos = loungealotThumb->x_pos;
-		sVar2 = flickerArm->x_pos;
-		loungealotThumb->y_pos = loungealotLeftUpperArm->y_pos - loungealotLeftUpperArm->frame->field_10;
-		flickerArm->y_pos = loungealotThumb->y_pos;
-		sVar3 = flickerArm->y_pos;
-		uVar13->x_pos = sVar2 - flickerArm->frame->field_e;
-		uVar12->x_pos = uVar13->x_pos;
-		uVar13->y_pos = sVar3 - flickerArm->frame->field_10;
-		uVar12->y_pos = uVar13->y_pos;
+		loungealotThumb->_x_pos = loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e;
+		flickerArm->_x_pos = loungealotThumb->_x_pos;
+		sVar2 = flickerArm->_x_pos;
+		loungealotThumb->_y_pos = loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10;
+		flickerArm->_y_pos = loungealotThumb->_y_pos;
+		sVar3 = flickerArm->_y_pos;
+		uVar13->_x_pos = sVar2 - flickerArm->_frame->field_e;
+		uVar12->_x_pos = uVar13->_x_pos;
+		uVar13->_y_pos = sVar3 - flickerArm->_frame->field_10;
+		uVar12->_y_pos = uVar13->_y_pos;
 //		EnableVSyncEvent();
 		local_282 = DAT_80093cc0;
 		local_286 = DAT_80093cbc;
@@ -761,7 +761,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				DAT_80093c94 = 2;
 			}
 		}
-		
+
 	} while ( true );
 
 }
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index e44fe5e264..e78643061e 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -210,9 +210,9 @@ void Minigame3::run() {
 		bunnyActorTbl[(int16)i]->setFlag(ACTOR_FLAG_200);
 		bunnyActorTbl[(int16)i]->setFlag(ACTOR_FLAG_4000);
 
-		bunnyActorTbl[(int16)i]->priorityLayer = 0;
-		bunnyActorTbl[(int16)i]->x_pos = bunnyPositionsTbl[(int16)i].x;
-		bunnyActorTbl[(int16)i]->y_pos = bunnyPositionsTbl[(int16)i].y;
+		bunnyActorTbl[(int16)i]->_priorityLayer = 0;
+		bunnyActorTbl[(int16)i]->_x_pos = bunnyPositionsTbl[(int16)i].x;
+		bunnyActorTbl[(int16)i]->_y_pos = bunnyPositionsTbl[(int16)i].y;
 		i = i + 1;
 	}
 	i = 0;
@@ -222,8 +222,8 @@ void Minigame3::run() {
 			error("Couldn't alloc tear");
 		}
 		tearActorTbl[(int16)i]->_flags = tearActorTbl[(int16)i]->_flags | 0x380;
-		tearActorTbl[(int16)i]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-		tearActorTbl[(int16)i]->priorityLayer = 0;
+		tearActorTbl[(int16)i]->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+		tearActorTbl[(int16)i]->_priorityLayer = 0;
 		local_208[(int16)i] = -1;
 		local_208[(int)(int16)i + 8] = 0;
 		i = i + 1;
@@ -240,8 +240,8 @@ void Minigame3::run() {
 	handActorId->setFlag(ACTOR_FLAG_800);
 	handActorId->setFlag(ACTOR_FLAG_2000);
 	handActorId->setFlag(ACTOR_FLAG_4000);
-	handActorId->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	handActorId->priorityLayer = 0;
+	handActorId->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	handActorId->_priorityLayer = 0;
 	handActorId->_walkSpeed = 0x40000;
 	i = 0;
 	while ((int16)i < 2) {
@@ -250,8 +250,8 @@ void Minigame3::run() {
 			error("Couldn't alloc tear blink");
 		}
 		tearBlinkActorTbl[(int16)i]->_flags = tearBlinkActorTbl[(int16)i]->_flags | 0x4384;
-		tearBlinkActorTbl[(int16)i]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-		tearBlinkActorTbl[(int16)i]->priorityLayer = 0;
+		tearBlinkActorTbl[(int16)i]->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+		tearBlinkActorTbl[(int16)i]->_priorityLayer = 0;
 		i = i + 1;
 	}
 	i = 0;
@@ -262,18 +262,18 @@ void Minigame3::run() {
 		}
 		tearBlinkActorTbl2[(int16)i]->setFlag(ACTOR_FLAG_100);
 		tearBlinkActorTbl2[(int16)i]->setFlag(ACTOR_FLAG_800);
-		tearBlinkActorTbl2[(int16)i]->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-		tearBlinkActorTbl2[(int16)i]->priorityLayer = 0;
+		tearBlinkActorTbl2[(int16)i]->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+		tearBlinkActorTbl2[(int16)i]->_priorityLayer = 0;
 		i = i + 1;
 	}
-	tearBlinkActorTbl2[0]->x_pos = 0x56;
-	tearBlinkActorTbl2[0]->y_pos = 0x8c;
-	tearBlinkActorTbl2[1]->x_pos = 0xf0;
-	tearBlinkActorTbl2[1]->y_pos = 0x8c;
-	tearBlinkActorTbl[0]->x_pos = 0x23; //DAT_80093228_23;
-	tearBlinkActorTbl[1]->x_pos = 0xbf; //DAT_8009322a_bf;
-	tearBlinkActorTbl[0]->y_pos = 0xcc;
-	tearBlinkActorTbl[1]->y_pos = 0xcc;
+	tearBlinkActorTbl2[0]->_x_pos = 0x56;
+	tearBlinkActorTbl2[0]->_y_pos = 0x8c;
+	tearBlinkActorTbl2[1]->_x_pos = 0xf0;
+	tearBlinkActorTbl2[1]->_y_pos = 0x8c;
+	tearBlinkActorTbl[0]->_x_pos = 0x23; //DAT_80093228_23;
+	tearBlinkActorTbl[1]->_x_pos = 0xbf; //DAT_8009322a_bf;
+	tearBlinkActorTbl[0]->_y_pos = 0xcc;
+	tearBlinkActorTbl[1]->_y_pos = 0xcc;
 //	EnableVSyncEvent();
 	i = 0;
 	while ((int16)i < 4) {
@@ -285,7 +285,7 @@ void Minigame3::run() {
 	i = 0;
 	while ((int16)i < 4) {
 		bunnyPositionTbl[(int16)i] = i;
-		bunnyActorTbl[(int16)i]->priorityLayer = 2;
+		bunnyActorTbl[(int16)i]->_priorityLayer = 2;
 		bunnyActorTbl[(int16)i]->updateSequence(4);
 		i = i + 1;
 	}
@@ -346,8 +346,8 @@ void Minigame3::run() {
 	local_1b8 = 0;
 	local_10 = 0;
 	local_e = 0;
-	tearBlinkActorTbl[0]->priorityLayer = 3;
-	tearBlinkActorTbl[1]->priorityLayer = 3;
+	tearBlinkActorTbl[0]->_priorityLayer = 3;
+	tearBlinkActorTbl[1]->_priorityLayer = 3;
 	tearBlinkActorTbl[0]->updateSequence(0);
 	tearBlinkActorTbl[1]->updateSequence(1);
 	local_1c2 = 0;
@@ -359,10 +359,10 @@ void Minigame3::run() {
 					if ((local_56 < 1) ||
 						(((int)bunnyInfo[local_20].x >> 9 <= (int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x ||
 																				((int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x <= (int)bunnyInfo[local_1e].x >> 9)))) {
-						bunnyActorTbl[local_1c]->x_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x;
-						bunnyActorTbl[local_1a]->x_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x;
-						bunnyActorTbl[local_1c]->y_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].y;
-						bunnyActorTbl[local_1a]->y_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].y;
+						bunnyActorTbl[local_1c]->_x_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x;
+						bunnyActorTbl[local_1a]->_x_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x;
+						bunnyActorTbl[local_1c]->_y_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].y;
+						bunnyActorTbl[local_1a]->_y_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].y;
 						currentState = 5;
 					}
 					else {
@@ -375,14 +375,14 @@ void Minigame3::run() {
 							bunnyInfo[local_20].x = bunnyInfo[local_20].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * -0x200;
 							bunnyInfo[local_20].y = bunnyInfo[local_20].y - bunnyInfo[local_20].field_0xc;
 							bunnyInfo[local_20].field_0xc = bunnyInfo[local_20].field_0xc + bunnyInfo[local_20].field_0x10;
-							bunnyActorTbl[local_1c]->x_pos = (int16_t)((int)bunnyInfo[local_20].x >> 9);
-							bunnyActorTbl[local_1c]->y_pos = (int16_t)((int)bunnyInfo[local_20].y >> 9);
+							bunnyActorTbl[local_1c]->_x_pos = (int16_t)((int)bunnyInfo[local_20].x >> 9);
+							bunnyActorTbl[local_1c]->_y_pos = (int16_t)((int)bunnyInfo[local_20].y >> 9);
 							bunnyInfo[local_1e].x = bunnyInfo[local_1e].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * 0x200;
 							bunnyInfo[local_1e].y = bunnyInfo[local_1e].y - bunnyInfo[local_1e].field_0xc;
 							bunnyInfo[local_1e].field_0xc = bunnyInfo[local_1e].field_0xc + bunnyInfo[local_1e].field_0x10;
-							bunnyActorTbl[local_1a]->x_pos = (int16_t)((int)bunnyInfo[local_1e].x >> 9);
-							bunnyActorTbl[local_1a]->y_pos = (int16_t)((int)bunnyInfo[local_1e].y >> 9);
-							if ((local_228 < 4) && unkXPosTbl[local_50 * 4 + local_228] < bunnyActorTbl[local_1a]->x_pos) {
+							bunnyActorTbl[local_1a]->_x_pos = (int16_t)((int)bunnyInfo[local_1e].x >> 9);
+							bunnyActorTbl[local_1a]->_y_pos = (int16_t)((int)bunnyInfo[local_1e].y >> 9);
+							if ((local_228 < 4) && unkXPosTbl[local_50 * 4 + local_228] < bunnyActorTbl[local_1a]->_x_pos) {
 								local_228 = local_228 + 1;
 								bunnyActorTbl[local_1a]->updateSequence((uint)local_228 + 6 & 0xffff);
 								bunnyActorTbl[local_1c]->updateSequence((uint)local_228 + 0xd & 0xffff);
@@ -472,12 +472,12 @@ void Minigame3::run() {
 		i = 0;
 		while ((int16)i < 8) {
 			if (local_208[(int16)i] != -1) {
-				tearActorTbl[(int16)i]->y_pos = tearActorTbl[(int16)i]->y_pos + ((uint16)local_208[(int)(int16)i + 8] >> 6);
-				if (tearActorTbl[(int16)i]->y_pos < (int16)tearInfo[local_208[(int16)i]].yRelated) {
+				tearActorTbl[(int16)i]->_y_pos = tearActorTbl[(int16)i]->_y_pos + ((uint16)local_208[(int)(int16)i + 8] >> 6);
+				if (tearActorTbl[(int16)i]->_y_pos < (int16)tearInfo[local_208[(int16)i]].yRelated) {
 					local_208[(int)(int16)i + 8] = local_208[(int)(int16)i + 8] + 8;
 				}
 				else {
-					tearActorTbl[(int16)i]->priorityLayer = 0;
+					tearActorTbl[(int16)i]->_priorityLayer = 0;
 					local_1e8 = local_1e8 & ~(1 << ((int)local_208[(int16)i] & 0x1fU));
 					local_208[(int16)i] = -1;
 					local_1e0 = local_1e0 - 1;
@@ -502,11 +502,11 @@ void Minigame3::run() {
 				local_14 = local_14 + 1;
 			}
 			local_208[local_14] = sVar2;
-			tearActorTbl[local_14]->x_pos = tearInfo[sVar2].x;
-			tearActorTbl[local_14]->y_pos = tearInfo[sVar2].y;
+			tearActorTbl[local_14]->_x_pos = tearInfo[sVar2].x;
+			tearActorTbl[local_14]->_y_pos = tearInfo[sVar2].y;
 			local_208[(int)local_14 + 8] = 0x20;
 			tearActorTbl[local_14]->updateSequence(0x13);
-			tearActorTbl[local_14]->priorityLayer = 3;
+			tearActorTbl[local_14]->_priorityLayer = 3;
 			local_1e0 = local_1e0 + 1;
 		}
 		if ((flags & 1) == 0) {
@@ -535,8 +535,8 @@ void Minigame3::run() {
 								local_1c8 = 0;
 								local_1ba = 0;
 								flags = flags & 0xfffb;
-								tearBlinkActorTbl2[0]->priorityLayer = 0;
-								tearBlinkActorTbl2[1]->priorityLayer = 0;
+								tearBlinkActorTbl2[0]->_priorityLayer = 0;
+								tearBlinkActorTbl2[1]->_priorityLayer = 0;
 								tearBlinkActorTbl2[0]->updateSequence(0);
 								tearBlinkActorTbl2[1]->updateSequence(1);
 							}
@@ -551,7 +551,7 @@ void Minigame3::run() {
 				if (local_1c6 == 0) {
 					i = 0;
 					while ((int16)i < 8) {
-						tearActorTbl[(int16)i]->priorityLayer = 0;
+						tearActorTbl[(int16)i]->_priorityLayer = 0;
 						local_208[(int16)i] = -1;
 						i = i + 1;
 					}
@@ -565,8 +565,8 @@ void Minigame3::run() {
 					local_1c8 = 2;
 					local_1c6 = 3;
 					updateBackgroundLayerOffset(2, 0x780, 0);
-					tearBlinkActorTbl[0]->y_pos = 0xcc;
-					tearBlinkActorTbl[1]->y_pos = 0xcc;
+					tearBlinkActorTbl[0]->_y_pos = 0xcc;
+					tearBlinkActorTbl[1]->_y_pos = 0xcc;
 				}
 				else {
 					local_1c6 = local_1c6 + -1;
@@ -581,8 +581,8 @@ void Minigame3::run() {
 					updateBackgroundLayerOffset(2, 0x780, 0);
 					tearBlinkActorTbl2[0]->updateSequence(0);
 					tearBlinkActorTbl2[1]->updateSequence(1);
-					tearBlinkActorTbl2[0]->priorityLayer = 4;
-					tearBlinkActorTbl2[1]->priorityLayer = 4;
+					tearBlinkActorTbl2[0]->_priorityLayer = 4;
+					tearBlinkActorTbl2[1]->_priorityLayer = 4;
 				}
 				else {
 					if (local_1c8 == 2) {
@@ -618,9 +618,9 @@ void Minigame3::run() {
 				local_1b8 = local_1b8 + 1;
 				FUN_80017f70_paletteRelated((uint)local_1b8);
 			}
-			if (100 < tearBlinkActorTbl[0]->y_pos) {
-				tearBlinkActorTbl[0]->y_pos = tearBlinkActorTbl[0]->y_pos + -3;
-				tearBlinkActorTbl[1]->y_pos = tearBlinkActorTbl[1]->y_pos + -3;
+			if (100 < tearBlinkActorTbl[0]->_y_pos) {
+				tearBlinkActorTbl[0]->_y_pos = tearBlinkActorTbl[0]->_y_pos + -3;
+				tearBlinkActorTbl[1]->_y_pos = tearBlinkActorTbl[1]->_y_pos + -3;
 			}
 		}
 		if (hopCounter == 0x1e) {
@@ -680,13 +680,13 @@ void Minigame3::run() {
 			local_1b8 = 0;
 		}
 		FUN_80017f70_paletteRelated((uint)local_1b8);
-		tearBlinkActorTbl[0]->y_pos = tearBlinkActorTbl[0]->y_pos + 0x1e;
-		if (199 < tearBlinkActorTbl[0]->y_pos) {
-			tearBlinkActorTbl[0]->y_pos = 199;
+		tearBlinkActorTbl[0]->_y_pos = tearBlinkActorTbl[0]->_y_pos + 0x1e;
+		if (199 < tearBlinkActorTbl[0]->_y_pos) {
+			tearBlinkActorTbl[0]->_y_pos = 199;
 		}
-		tearBlinkActorTbl[1]->y_pos = tearBlinkActorTbl[1]->y_pos + 0x1e;
-		if (199 < tearBlinkActorTbl[1]->y_pos) {
-			tearBlinkActorTbl[1]->y_pos = 199;
+		tearBlinkActorTbl[1]->_y_pos = tearBlinkActorTbl[1]->_y_pos + 0x1e;
+		if (199 < tearBlinkActorTbl[1]->_y_pos) {
+			tearBlinkActorTbl[1]->_y_pos = 199;
 		}
 		_vm->waitForFrames(0xf);
 		local_16 = 1;
@@ -704,9 +704,9 @@ void Minigame3::run() {
 	updateBackgroundLayerOffset(0, 0, 0);
 	local_224 = _vm->getRand(2);
 	handActorId->updateSequence(0);
-	handActorId->x_pos = handPositionsTbl[local_224].x;
-	handActorId->y_pos = handPositionsTbl[local_224].y;
-	handActorId->priorityLayer = 2;
+	handActorId->_x_pos = handPositionsTbl[local_224].x;
+	handActorId->_y_pos = handPositionsTbl[local_224].y;
+	handActorId->_priorityLayer = 2;
 	bVar1 = false;
 	_vm->_talk->loadAndDisplayDialogAroundPoint(0x2958A,0x14,3,0x1e01,0);
 	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 1fb30cfd6b..2b620ec7c2 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -74,11 +74,11 @@ void Minigame4::run() {
 	flickerActor->setFlag(ACTOR_FLAG_80);
 	flickerActor->setFlag(ACTOR_FLAG_100);
 	flickerActor->setFlag(ACTOR_FLAG_200);
-	flickerActor->priorityLayer = 3;
+	flickerActor->_priorityLayer = 3;
 	bruteActor->setFlag(ACTOR_FLAG_80);
 	bruteActor->setFlag(ACTOR_FLAG_100);
 	bruteActor->setFlag(ACTOR_FLAG_200);
-	bruteActor->priorityLayer = 3;
+	bruteActor->_priorityLayer = 3;
 	//DAT_800830e0_soundRelated = 0xf;
 	//UnkSoundFunc5(0xf);
 	//call_fade_related_1f();
@@ -231,8 +231,8 @@ const static uint16 uint16_t_ARRAY_80090400[6] = { 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
 const static uint16 uint16_t_ARRAY_800903e8[6] = { 1, 2, 3, 4, 5, 6 };
 
 uint16 Minigame4::singleDanceRound(uint16 currentDancePosition, uint16 duration) {
-	DAT_80090438->x_pos = xDancePosTbl[(uint)currentDancePosition];
-	DAT_80090438->y_pos = yDancePosTbl[(uint)currentDancePosition];
+	DAT_80090438->_x_pos = xDancePosTbl[(uint)currentDancePosition];
+	DAT_80090438->_y_pos = yDancePosTbl[(uint)currentDancePosition];
 	DAT_80090438->updateSequence(10);
 	ps1ControllerActor->updateSequence(uint16_t_ARRAY_80090400[(uint)currentDancePosition]);
 	bruteActor->updateSequence(uint16_t_ARRAY_800903e8[(uint)currentDancePosition]);
@@ -245,10 +245,10 @@ uint16 Minigame4::singleDanceRound(uint16 currentDancePosition, uint16 duration)
 		while (duration = duration + -1, duration != 0) {
 			_vm->waitForFrames(1);
 		}
-		DAT_80090438->x_pos = xDancePosTbl[(uint)currentDancePosition];
-		DAT_8009043c->x_pos = DAT_80090438->x_pos;
-		DAT_80090438->y_pos = yDancePosTbl[(uint)currentDancePosition];
-		DAT_8009043c->y_pos = DAT_80090438->y_pos;
+		DAT_80090438->_x_pos = xDancePosTbl[(uint)currentDancePosition];
+		DAT_8009043c->_x_pos = DAT_80090438->_x_pos;
+		DAT_80090438->_y_pos = yDancePosTbl[(uint)currentDancePosition];
+		DAT_8009043c->_y_pos = DAT_80090438->_y_pos;
 		DAT_8009043c->updateSequence(0xb);
 		ps1ControllerActor->updateSequence(0x16);
 		return 0;
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index 242f6c0369..dc3dfec9f5 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -99,7 +99,7 @@ void Minigame5::run() {
 	local_76 = _vm->_scene->getSceneId();
 	local_78 = _vm->_dragonINIResource->getFlickerRecord();
 	local_78->actor->setFlag(ACTOR_FLAG_100);
-	local_78->actor->priorityLayer = 0;
+	local_78->actor->_priorityLayer = 0;
 	savedEngineFlags = _vm->getMultipleFlags(ENGINE_FLAG_8 | ENGINE_FLAG_10 | ENGINE_FLAG_20 | ENGINE_FLAG_80);
 	_vm->clearFlags(ENGINE_FLAG_8);
 	_vm->clearFlags(ENGINE_FLAG_10);
@@ -108,14 +108,14 @@ void Minigame5::run() {
 	_vm->_dragonINIResource->setFlickerRecord(_vm->_dragonINIResource->getRecord(DAT_80063a40 - 1));
 	flickerActor = _vm->_dragonINIResource->getFlickerRecord()->actor;
 	flickerActor->_flags = flickerActor->_flags | 0x380;
-	flickerActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	flickerActor->priorityLayer = 4;
+	flickerActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	flickerActor->_priorityLayer = 4;
 	flickerActor->_sequenceID2 = -1;
 	flickerActor->updateSequence(0x19);
 	currentState = 0;
 	local_10 = 0;
-	local_850 = flickerActor->x_pos;
-	uVar1 = flickerActor->y_pos;
+	local_850 = flickerActor->_x_pos;
+	uVar1 = flickerActor->_y_pos;
 	local_74 = 0;
 //	DisableVSyncEvent();
 	pusherActor = _vm->_actorManager->loadActor
@@ -125,10 +125,10 @@ void Minigame5::run() {
 		error("Couldn't alloc pusher!");
 	}
 	pusherActor->_flags = pusherActor->_flags | 0x380;
-	pusherActor->x_pos = flickerActor->x_pos + -0xe;
-	pusherActor->y_pos = flickerActor->y_pos + 7;
-	pusherActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	pusherActor->priorityLayer = 6;
+	pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
+	pusherActor->_y_pos = flickerActor->_y_pos + 7;
+	pusherActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	pusherActor->_priorityLayer = 6;
 //	DisableVSyncEvent();
 	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
 //	EnableVSyncEvent();
@@ -136,10 +136,10 @@ void Minigame5::run() {
 		error("Couldn't alloc wheels!");
 	}
 	wheelsActor->_flags = wheelsActor->_flags | 0x380;
-	wheelsActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	wheelsActor->x_pos = flickerActor->x_pos;
-	wheelsActor->y_pos = flickerActor->y_pos;
-	wheelsActor->priorityLayer = 5;
+	wheelsActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	wheelsActor->_x_pos = flickerActor->_x_pos;
+	wheelsActor->_y_pos = flickerActor->_y_pos;
+	wheelsActor->_priorityLayer = 5;
 	wheelsActor->updateSequence(0x11);
 	local_62 = 0;
 //	DisableVSyncEvent();
@@ -149,8 +149,8 @@ void Minigame5::run() {
 		error("Couldn't alloc bomb!");
 	}
 	bombActor->_flags = bombActor->_flags | 0x380;
-	bombActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	bombActor->priorityLayer = 0;
+	bombActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	bombActor->_priorityLayer = 0;
 //	DisableVSyncEvent();
 	dustActor = _vm->_actorManager->loadActor(8,8,100,100,0);
 //	EnableVSyncEvent();
@@ -158,10 +158,10 @@ void Minigame5::run() {
 		error("Couldn't alloc dust sprite!");
 	}
 	dustActor->_flags = dustActor->_flags | 0x380;
-	dustActor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	dustActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	local_4e = _vm->_dragonINIResource->getRecord(DAT_80063a48 + -1)->actor;
 	local_4c = 0;
-	local_4a = local_4e->field_c;
+	local_4a = local_4e->_field_c;
 	_vm->setFlags(ENGINE_FLAG_4000000);
 	currentState = 1;
 	local_66 = 0;
@@ -207,8 +207,8 @@ void Minigame5::run() {
 						local_74 = 0;
 					}
 					else {
-						pusherActor->x_pos = flickerActor->x_pos + -0xe;
-						pusherActor->y_pos = flickerActor->y_pos + 7;
+						pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
+						pusherActor->_y_pos = flickerActor->_y_pos + 7;
 						if (local_74 < 0x168) {
 							local_74 = local_74 + 1;
 							if (local_74 < 0x14) {
@@ -275,14 +275,14 @@ void Minigame5::run() {
 										   (short)((int)((uint)local_850 << 7) / 0x2a);
 							}
 							local_60 = local_850 << 7;
-							bombActor->x_pos = local_850 & 0x1ff;
+							bombActor->_x_pos = local_850 & 0x1ff;
 							local_5e = 0x2d00;
 							local_5a = (local_72 + 3) * 0x80;
-							bombActor->y_pos = 0x5a;
+							bombActor->_y_pos = 0x5a;
 							bombScale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-							bombActor->scale = bombScale;
+							bombActor->_scale = bombScale;
 							_vm->playOrStopSound(10);
-							bombActor->priorityLayer = 3;
+							bombActor->_priorityLayer = 3;
 							flickerActor->updateSequence(8);
 							currentState = 3;
 						}
@@ -310,10 +310,10 @@ void Minigame5::run() {
 							local_5a = 0;
 						}
 					}
-					bombActor->x_pos = local_60 >> 7;
-					bombActor->y_pos = local_5e >> 7;
+					bombActor->_x_pos = local_60 >> 7;
+					bombActor->_y_pos = local_5e >> 7;
 					bombScale = bombScale - 3;
-					bombActor->scale = bombScale;
+					bombActor->_scale = bombScale;
 					if (bombScale == 0x7f) {
 						if (((local_60 >> 7 < local_30[0]) || (local_30[1] < local_60 >> 7)) ||
 							(local_72 != local_30[2])) {
@@ -331,26 +331,26 @@ void Minigame5::run() {
 								((local_72 == 3 &&
 								  (((0x3c < local_60 >> 7 && (local_60 >> 7 < 0x46)) ||
 									((0x101 < local_60 >> 7 && (local_60 >> 7 < 0x10a)))))))) {
-								bombActor->priorityLayer = 0;
-								dustActor->priorityLayer = 4;
-								dustActor->x_pos = bombActor->x_pos;
-								dustActor->y_pos = bombActor->y_pos;
+								bombActor->_priorityLayer = 0;
+								dustActor->_priorityLayer = 4;
+								dustActor->_x_pos = bombActor->_x_pos;
+								dustActor->_y_pos = bombActor->_y_pos;
 								dustActor->updateSequence(9);
 								currentState = 4;
 							}
 						}
 						else {
-							local_4e->field_c = 2;
+							local_4e->_field_c = 2;
 							local_4c = 0x3c;
-							bombActor->priorityLayer = 0;
+							bombActor->_priorityLayer = 0;
 							currentState = 8;
 						}
 					}
 					if (bombScale < 0x7f) {
-						bombActor->priorityLayer = 2;
+						bombActor->_priorityLayer = 2;
 					}
 					if ((0xc < bombScale) && (bombScale < 0x41)) {
-						bombActor->priorityLayer = 0;
+						bombActor->_priorityLayer = 0;
 					}
 					if ((short)bombScale < 2) {
 						currentState = 5;
@@ -382,7 +382,7 @@ void Minigame5::run() {
 				case 7:
 					break;
 				case 8:
-					bombActor->priorityLayer = 0;
+					bombActor->_priorityLayer = 0;
 					pusherActor->updateSequence(0);
 					_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(2);
 					_vm->waitForFrames(0x12);
@@ -402,7 +402,7 @@ void Minigame5::run() {
 				default:
 					debug("undefined state!");
 					currentState = 1;
-					bombActor->priorityLayer = 0;
+					bombActor->_priorityLayer = 0;
 					break;
 				}
 				if ((local_10 == 0) && (currentState != 2)) {
@@ -413,12 +413,12 @@ void Minigame5::run() {
 								  && (pusherActor->_sequenceID != 6)))) {
 								pusherActor->updateSequence((uint)local_66);
 								if (local_50 == 0) {
-									pusherActor->x_pos = flickerActor->x_pos + -0xe;
-									pusherActor->y_pos = flickerActor->y_pos + 7;
+									pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
+									pusherActor->_y_pos = flickerActor->_y_pos + 7;
 								}
 								else {
-									pusherActor->x_pos = flickerActor->x_pos + 2;
-									pusherActor->y_pos = flickerActor->y_pos;
+									pusherActor->_x_pos = flickerActor->_x_pos + 2;
+									pusherActor->_y_pos = flickerActor->_y_pos;
 								}
 							}
 						}
@@ -443,13 +443,13 @@ void Minigame5::run() {
 							else {
 								local_62 = local_62 - 1;
 							}
-							flickerActor->x_pos = local_850;
-							wheelsActor->x_pos = local_850;
+							flickerActor->_x_pos = local_850;
+							wheelsActor->_x_pos = local_850;
 							if ((uint)wheelsActor->_sequenceID != (uint)local_62 / 3 + 0x11) {
 								wheelsActor->updateSequence((uint)local_62 / 3 + 0x11);
 							}
-							pusherActor->x_pos = flickerActor->x_pos + 2;
-							pusherActor->y_pos = flickerActor->y_pos;
+							pusherActor->_x_pos = flickerActor->_x_pos + 2;
+							pusherActor->_y_pos = flickerActor->_y_pos;
 						}
 					}
 					else {
@@ -469,24 +469,24 @@ void Minigame5::run() {
 						}
 						local_62 = (short)((uint)local_62 + 1) +
 								   (short)((int)((uint)local_62 + 1) / 6 >> 1) * -0xc;
-						flickerActor->x_pos = local_850;
-						wheelsActor->x_pos = local_850;
+						flickerActor->_x_pos = local_850;
+						wheelsActor->_x_pos = local_850;
 						if ((uint)wheelsActor->_sequenceID != (uint)local_62 / 3 + 0x11) {
 							wheelsActor->updateSequence((uint)local_62 / 3 + 0x11);
 						}
-						pusherActor->x_pos = flickerActor->x_pos + -2;
-						pusherActor->y_pos = flickerActor->y_pos;
+						pusherActor->_x_pos = flickerActor->_x_pos + -2;
+						pusherActor->_y_pos = flickerActor->_y_pos;
 					}
 				}
 			} while (local_10 == 0);
-			if ((local_10 == 2) || (0x117 < flickerActor->x_pos)) break;
-			flickerActor->x_pos = flickerActor->x_pos + 2;
+			if ((local_10 == 2) || (0x117 < flickerActor->_x_pos)) break;
+			flickerActor->_x_pos = flickerActor->_x_pos + 2;
 			if (pusherActor->_sequenceID != 2) {
 				pusherActor->updateSequence(2);
 			}
-			pusherActor->x_pos = flickerActor->x_pos + 2;
-			pusherActor->y_pos = flickerActor->y_pos;
-			wheelsActor->x_pos = wheelsActor->x_pos + 2;
+			pusherActor->_x_pos = flickerActor->_x_pos + 2;
+			pusherActor->_y_pos = flickerActor->_y_pos;
+			wheelsActor->_x_pos = wheelsActor->_x_pos + 2;
 			if (local_62 == 0) {
 				local_62 = 0xb;
 			}
@@ -512,8 +512,8 @@ void Minigame5::run() {
 			local_44 = 0;
 			if (local_10 == 2) {
 //				DisableVSyncEvent();
-				local_46 = pusherActor->x_pos;
-				local_44 = pusherActor->y_pos;
+				local_46 = pusherActor->_x_pos;
+				local_44 = pusherActor->_y_pos;
 				pusherActor->reset_maybe();
 //				EnableVSyncEvent();
 			}
@@ -527,13 +527,13 @@ void Minigame5::run() {
 			}
 			_vm->_dragonINIResource->setFlickerRecord(local_78);
 			if (local_10 == 2) {
-				local_78->actor->x_pos = local_46;
+				local_78->actor->_x_pos = local_46;
 				local_78->actor->setFlag(ACTOR_FLAG_100);
-				local_78->actor->priorityLayer = 5;
+				local_78->actor->_priorityLayer = 5;
 			}
 			else {
 				local_78->actor->clearFlag(ACTOR_FLAG_100);
-				local_78->actor->priorityLayer = 2;
+				local_78->actor->_priorityLayer = 2;
 			}
 			_vm->clearFlags(ENGINE_FLAG_4000000);
 			_vm->setFlags(savedEngineFlags);
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index ea8d6296a3..563386088b 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -228,12 +228,12 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 				if (actor) {
 					ini->actor = actor;
 					if (ini->field_1a_flags_maybe & 0x1000) {
-						actor->frame_flags |= 0x10;
+						actor->_frame_flags |= 0x10;
 					} else {
 						if (ini->field_1a_flags_maybe & 0x2000) {
-							actor->frame_flags |= 0x20;
+							actor->_frame_flags |= 0x20;
 						} else {
-							actor->frame_flags &= ~0x10;
+							actor->_frame_flags &= ~0x10;
 						}
 					}
 
@@ -264,8 +264,8 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 					}
 //
 //				Graphics::Surface *s = actor->getCurrentFrame();
-//				int x = ini->x - actor->frame_vram_x;
-//				int y = ini->y - actor->frame_vram_y;
+//				int x = ini->x - actor->_frame_vram_x;
+//				int y = ini->y - actor->_frame_vram_y;
 //				if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
 //					debug("Actor %d, %d %d (%d, %d)", actor->_actorID, ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
 //					_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
@@ -285,7 +285,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	DragonINI *ini = _vm->getINI(1);
 	if (ini->actor && _vm->_dragonINIResource->getFlickerRecord() && _vm->_dragonINIResource->getFlickerRecord()->sceneId == _currentSceneId) {
 		ini->actor->setFlag(Dragons::ACTOR_FLAG_100);
-		ini->actor->priorityLayer = 0;
+		ini->actor->_priorityLayer = 0;
 	}
 
 
@@ -358,29 +358,29 @@ void Scene::draw() {
 
 		for (int16 i = 0; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
 			Actor *actor = _actorManager->getActorByDisplayOrder(i);
-			if (actor->x_pos == -100 && actor->y_pos == 100) {
-				actor->priorityLayer = 0;
+			if (actor->_x_pos == -100 && actor->_y_pos == 100) {
+				actor->_priorityLayer = 0;
 				continue;
 			}
 
 			if (actor->_flags & Dragons::ACTOR_FLAG_40 &&
 				!(actor->_flags & Dragons::ACTOR_FLAG_400) &&
-				actor->surface &&
-				actor->frame->width != 0 &&
-				actor->frame->height != 0
+				actor->_surface &&
+				actor->_frame->width != 0 &&
+				actor->_frame->height != 0
 				) {
-				Graphics::Surface *s = actor->surface;
-				if (actor->priorityLayer == priority) { //} && x + s->w < 320 && y + s->h < 200) {
+				Graphics::Surface *s = actor->_surface;
+				if (actor->_priorityLayer == priority) { //} && x + s->w < 320 && y + s->h < 200) {
 					if (!actor->isFlagSet(ACTOR_FLAG_80)) {
-						actor->scale = _stage->getScaleLayer()->getScale(actor->y_pos);
+						actor->_scale = _stage->getScaleLayer()->getScale(actor->_y_pos);
 					}
-					int x = actor->x_pos - (actor->frame->xOffset * actor->scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.x);
-					int y = actor->y_pos - (actor->frame->yOffset * actor->scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.y);
+					int x = actor->_x_pos - (actor->_frame->xOffset * actor->_scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.x);
+					int y = actor->_y_pos - (actor->_frame->yOffset * actor->_scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.y);
 
 					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d Scale: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
-						  s->w, s->h, actor->priorityLayer, actor->scale);
-						_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? NONE : NORMAL, actor->scale);
+						  s->w, s->h, actor->_priorityLayer, actor->_scale);
+						_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->_frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? NONE : NORMAL, actor->_scale);
 					if (_vm->isDebugMode()) {
 						_screen->drawRect(0x7fff, Common::Rect(x, y, x + s->w, y + s->h), actor->_actorID);
 						drawActorNumber(x + s->w, y + 8, actor->_actorID);
@@ -455,8 +455,8 @@ void Scene::setSceneId(int16 newSceneId) {
 void Scene::resetActorFrameFlags() {
 	for (int i = 0; i < 0x17; i++) {
 		Actor *actor = _vm->_actorManager->getActor(i);
-		actor->frame_flags &= ~ACTOR_FRAME_FLAG_10;
-		actor->frame_flags &= ~ACTOR_FRAME_FLAG_20;
+		actor->_frame_flags &= ~ACTOR_FRAME_FLAG_10;
+		actor->_frame_flags &= ~ACTOR_FRAME_FLAG_20;
 	}
 }
 
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index cbc769abde..a7dcee50a1 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -636,9 +636,9 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 
 	} else {
 		ini->x = point.x;
-		ini->actor->x_pos = point.x;
+		ini->actor->_x_pos = point.x;
 		ini->y = point.y;
-		ini->actor->y_pos = point.y;
+		ini->actor->_y_pos = point.y;
 
 		if (field4 != field6) {
 			ini->actor->_walkSpeed = field4;
@@ -690,9 +690,9 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 	} else {
 		assert(ini->actor);
 		ini->x = field8;
-		ini->actor->x_pos = field8;
+		ini->actor->_x_pos = field8;
 		ini->y = fieldA;
-		ini->actor->y_pos = fieldA;
+		ini->actor->_y_pos = fieldA;
 
 		if (field4 != field6) {
 			ini->actor->_walkSpeed = field4;
@@ -730,19 +730,19 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 				IMG *firstDragonImg1 = _vm->_dragonIMG->getIMG(firstIni->field_2);
 				int16 newXPos1 = firstDragonImg1->field_a + firstIni->field_1c;
 				secondIni->x = newXPos1;
-				secondIni->actor->x_pos = newXPos1;
+				secondIni->actor->_x_pos = newXPos1;
 				int16 newYPos1 = firstDragonImg1->field_c + firstIni->field_1e;
 				secondIni->y = newYPos1;
-				secondIni->actor->y_pos = newYPos1;
+				secondIni->actor->_y_pos = newYPos1;
 			}
 		}
 		else {
-			int16 newYPos2 = firstIni->actor->y_pos + firstIni->field_1e;
+			int16 newYPos2 = firstIni->actor->_y_pos + firstIni->field_1e;
 			firstIni->y = newYPos2;
-			secondIni->actor->y_pos = newYPos2;
-			someXParam = firstIni->actor->x_pos + firstIni->field_1c;
+			secondIni->actor->_y_pos = newYPos2;
+			someXParam = firstIni->actor->_x_pos + firstIni->field_1c;
 			secondIni->x = someXParam;
-			secondIni->actor->x_pos = someXParam;
+			secondIni->actor->_x_pos = someXParam;
 		}
 		if (field6 != -1) {
 			secondIni->actor->_walkSpeed = -1;
@@ -782,8 +782,8 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 		}
 	}
 	else {
-		newXPosAgain = firstIni->actor->x_pos + firstIni->field_1c;
-		newYPosAgain = firstIni->actor->y_pos + firstIni->field_1e;
+		newXPosAgain = firstIni->actor->_x_pos + firstIni->field_1c;
+		newYPosAgain = firstIni->actor->_y_pos + firstIni->field_1e;
 		if (_vm->_dragonINIResource->isFlicker(secondIni)) {
 			someBooleanFlag = 0;
 		}
@@ -881,8 +881,8 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 	}
 	else {
 		_vm->_talk->FUN_8003239c(dialog,
-								 (int)(((uint)ini->actor->x_pos - (uint)_vm->_scene->_camera.x) * 0x10000) >> 0x13,
-								 (int)(((ini->actor->y_pos - ini->actor->frame->yOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13,
+								 (int)(((uint)ini->actor->_x_pos - (uint)_vm->_scene->_camera.x) * 0x10000) >> 0x13,
+								 (int)(((ini->actor->_y_pos - ini->actor->_frame->yOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13,
 								 READ_LE_INT16(_vm->_dragonOBD->getFromOpt(iniId) + 6),
 								 1,
 								 ini->actor, startSequenceId, endSequenceId, textIndex);
@@ -940,7 +940,7 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 		if (field2 == 0x1a && ini->field_1a_flags_maybe & 1 && ini->sceneId == _vm->getCurrentSceneId()) {
 			if (s1 & 2) {
 				ini->actor->_flags |= Dragons::ACTOR_FLAG_80;
-				ini->actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+				ini->actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 			} else {
 				ini->actor->_flags &= ~Dragons::ACTOR_FLAG_80;
 			}
@@ -1238,19 +1238,19 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 				if (_vm->_inventory->getType() == 1) {
 					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->iniItemInHand);
 					actor->_flags = 0;
-					actor->priorityLayer = 0;
-					actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+					actor->_priorityLayer = 0;
+					actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 					actor->updateSequence((_vm->getINI(_vm->_cursor->iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);
 					actor->setFlag(ACTOR_FLAG_200);
-					actor->priorityLayer = 6;
+					actor->_priorityLayer = 6;
 				}
 			}
 			DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
-			_vm->_cursor->updatePosition(flicker->actor->x_pos - _vm->_scene->_camera.x,
-					flicker->actor->y_pos - (_vm->_scene->_camera.y + 0x1e));
+			_vm->_cursor->updatePosition(flicker->actor->_x_pos - _vm->_scene->_camera.x,
+					flicker->actor->_y_pos - (_vm->_scene->_camera.y + 0x1e));
 			_vm->_cursor->data_800728b0_cursor_seqID = 5;
 			_vm->_cursor->_sequenceID = 5;
 			_vm->_cursor->data_8007283c = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 5e5ffc77a7..28475ecbe0 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -118,7 +118,7 @@ void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
 	debug(4, "set frame pointer %X", framePointer);
 	actor->loadFrame((uint16)framePointer);
 	actor->_flags |= Dragons::ACTOR_FLAG_2;
-	actor->sequenceTimer = actor->field_c;
+	actor->_sequenceTimer = actor->_field_c;
 	updateReturn(opCall, 1);
 }
 
@@ -141,15 +141,15 @@ void SequenceOpcodes::opJmp(Actor *actor, OpCall &opCall) {
 
 void SequenceOpcodes::opSetFieldC(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newFieldC);
-	actor->field_c = (uint16)newFieldC;
+	actor->_field_c = (uint16)newFieldC;
 	debug(5, "set fieldC: %d", newFieldC);
 	updateReturn(opCall, 1);
 }
 
 void SequenceOpcodes::opSetSequenceTimer(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newSeqTimer);
-	actor->sequenceTimer = (uint16)newSeqTimer;
-	debug(5, "set sequenceTimer: %d", newSeqTimer);
+	actor->_sequenceTimer = (uint16)newSeqTimer;
+	debug(5, "set _sequenceTimer: %d", newSeqTimer);
 	updateReturn(opCall, 1);
 	opCall._result = 0;
 }
@@ -157,11 +157,11 @@ void SequenceOpcodes::opSetSequenceTimer(Actor *actor, OpCall &opCall) {
 void SequenceOpcodes::opUpdateXYResetSeqTimer(Actor *actor, OpCall &opCall) {
 	ARG_INT8(xOffset);
 	ARG_INT8(yOffset);
-	actor->x_pos += xOffset;
-	actor->y_pos += yOffset;
-	actor->sequenceTimer = actor->field_c;
+	actor->_x_pos += xOffset;
+	actor->_y_pos += yOffset;
+	actor->_sequenceTimer = actor->_field_c;
 
-	debug(5, "update actor %d XY offset (%d,%d) new values (%d, %d) %d", actor->_actorID, xOffset, yOffset, actor->x_pos, actor->y_pos, actor->sequenceTimer);
+	debug(5, "update actor %d XY offset (%d,%d) new values (%d, %d) %d", actor->_actorID, xOffset, yOffset, actor->_x_pos, actor->_y_pos, actor->_sequenceTimer);
 	updateReturn(opCall, 1);
 }
 
@@ -195,7 +195,7 @@ void SequenceOpcodes::opChangeSequence(Actor *actor, OpCall &opCall) {
 
 void SequenceOpcodes::opSetField7a(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newValue);
-	actor->field_7a = (uint16)newValue;
+	actor->_field_7a = (uint16)newValue;
 	updateReturn(opCall, 1);
 }
 
@@ -217,8 +217,8 @@ void SequenceOpcodes::opPlaySound(Actor *actor, OpCall &opCall) {
 void SequenceOpcodes::opSetXY(Actor *actor, OpCall &opCall) {
 	ARG_INT16(x);
 	ARG_INT16(y);
-	actor->x_pos = x;
-	actor->y_pos = y;
+	actor->_x_pos = x;
+	actor->_y_pos = y;
 	updateReturn(opCall, 2);
 }
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 074c295ba1..ac3ab0f7c6 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -303,7 +303,7 @@ void SpecialOpcodes::spcUnk9() {
 	flicker->field_1a_flags_maybe |= Dragons::INI_FLAG_20;
 	assert(flicker->actor);
 	flicker->actor->_flags |= Dragons::ACTOR_FLAG_100;
-	flicker->actor->priorityLayer = 0;
+	flicker->actor->_priorityLayer = 0;
 	_vm->getINI(1)->field_1a_flags_maybe |= Dragons::INI_FLAG_20;
 }
 
@@ -461,14 +461,14 @@ void SpecialOpcodes::spcWalkOnStilts() {
 	flickerOnStilts->_walkSlopeY = flickerOnStilts->_walkSlopeY / 3;
 
 	while (flickerOnStilts->isFlagSet(ACTOR_FLAG_10)) {
-		if (flickerOnStilts->frame->field_c == 0) {
+		if (flickerOnStilts->_frame->field_c == 0) {
 			isInWater = false;
 		}
 		else {
-			if (!isInWater && flickerOnStilts->y_pos >= 0x6a && flickerOnStilts->y_pos < 0x96) {
+			if (!isInWater && flickerOnStilts->_y_pos >= 0x6a && flickerOnStilts->_y_pos < 0x96) {
 				isInWater = true;
-				waterRipples->x_pos = flickerOnStilts->x_pos - flickerOnStilts->frame->field_e;
-				waterRipples->y_pos = flickerOnStilts->y_pos - flickerOnStilts->frame->field_10;
+				waterRipples->_x_pos = flickerOnStilts->_x_pos - flickerOnStilts->_frame->field_e;
+				waterRipples->_y_pos = flickerOnStilts->_y_pos - flickerOnStilts->_frame->field_10;
 				waterRipples->updateSequence(9);
 			}
 		}
@@ -506,12 +506,12 @@ void SpecialOpcodes::spcStGeorgeDragonLanded() {
 //	DisableVSyncEvent();
 	DragonINI *ini121 = _vm->_dragonINIResource->getRecord(0x121);
 	Actor *origActor = ini121->actor;
-	ini121->actor = _vm->_actorManager->loadActor(0x48, 4, ini121->actor->x_pos, ini121->actor->y_pos);
+	ini121->actor = _vm->_actorManager->loadActor(0x48, 4, ini121->actor->_x_pos, ini121->actor->_y_pos);
 	origActor->reset_maybe();
 //TODO	reset_actor_maybe();
 	ini121->actor->setFlag(ACTOR_FLAG_80);
-	ini121->actor->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	ini121->actor->priorityLayer = 2;
+	ini121->actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	ini121->actor->_priorityLayer = 2;
 	ini121->actorResourceId = 0x48;
 
 	_vm->updateActorSequences();
@@ -535,7 +535,7 @@ void SpecialOpcodes::spcClearEngineFlag0x200000() {
 }
 
 void SpecialOpcodes::spcFlickerSetPriority2() {
-	_vm->_dragonINIResource->getFlickerRecord()->actor->priorityLayer = 2;
+	_vm->_dragonINIResource->getFlickerRecord()->actor->_priorityLayer = 2;
 }
 
 void SpecialOpcodes::spcMenInMinesSceneLogic() {
@@ -625,7 +625,7 @@ void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
 void SpecialOpcodes::spcUnk34() {
 	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;
 	flicker->setFlag(ACTOR_FLAG_80);
-	flicker->scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+	flicker->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 }
 
 void SpecialOpcodes::spcFlickerClearFlag0x80() {
@@ -1037,7 +1037,7 @@ void SpecialOpcodes::spcLoadFileS10a7act() {
 void SpecialOpcodes::spcFlickerPutOnStGeorgeArmor() {
 	Actor *actor = _vm->_dragonINIResource->getRecord(0x21f)->actor;
 	actor->setFlag(ACTOR_FLAG_100);
-	actor->priorityLayer = 1;
+	actor->_priorityLayer = 1;
 }
 
 void SpecialOpcodes::spc82CallResetDataMaybe() {
@@ -1234,14 +1234,14 @@ void SpecialOpcodes::pizzaMakerStopWorking() {
 		if (actorf4->_sequenceID == 1) {
 			actorf4->waitUntilFlag8And4AreSet();
 			actorf4->updateSequence(2);
-			actorf5->x_pos = 0x115;
-			actorf5->y_pos = 0x5c;
+			actorf5->_x_pos = 0x115;
+			actorf5->_y_pos = 0x5c;
 			actorf5->updateSequence(7);
 			_vm->waitForFrames(0x78);
 			actorf5->updateSequence(8);
 			actorf5->waitUntilFlag8And4AreSet();
-			actorf5->x_pos = 0xff9c;
-			actorf5->y_pos = 100;
+			actorf5->_x_pos = 0xff9c;
+			actorf5->_y_pos = 100;
 			actorf4->updateSequence(3);
 		}
 		else {
@@ -1249,8 +1249,8 @@ void SpecialOpcodes::pizzaMakerStopWorking() {
 				_vm->waitForFrames(0x78);
 				actorf5->updateSequence(8);
 				actorf5->waitUntilFlag8And4AreSet();
-				actorf5->x_pos = 0xff9c;
-				actorf5->y_pos = 100;
+				actorf5->_x_pos = 0xff9c;
+				actorf5->_y_pos = 100;
 				actorf4->updateSequence(3);
 			}
 			else {
@@ -1294,7 +1294,7 @@ void SpecialOpcodes::setupTableBasedSceneUpdateFunction(uint16 initialCounter, u
 
 void SpecialOpcodes::spcUnk80FlickerArmorOn() {
 	Actor *actor = _vm->_dragonINIResource->getRecord(0x21f)->actor;
-	actor->priorityLayer = 2;
+	actor->_priorityLayer = 2;
 	actor->clearFlag(ACTOR_FLAG_100);
 }
 
@@ -1325,8 +1325,8 @@ void pizzaUpdateFunction() {
 				} else {
 					if (actorf4->_sequenceID == 1) {
 						actorf4->updateSequence(2);
-						actorf5->x_pos = 0x115;
-						actorf5->y_pos = 0x5c;
+						actorf5->_x_pos = 0x115;
+						actorf5->_y_pos = 0x5c;
 						actorf5->updateSequence(7);
 						counter = 0x2d;
 						return;
@@ -1334,8 +1334,8 @@ void pizzaUpdateFunction() {
 					if (actorf4->_sequenceID == 2) {
 						if ((actorf5->_sequenceID == 8) &&
 							(actorf5->isFlagSet(ACTOR_FLAG_4))) {
-							actorf5->x_pos = -100;
-							actorf5->y_pos = 100;
+							actorf5->_x_pos = -100;
+							actorf5->_y_pos = 100;
 							actorf4->updateSequence(3);
 						} else {
 							if (actorf5->_sequenceID == 8) {
@@ -1746,19 +1746,19 @@ void caveOfDilemmaUpdateFunction() {
 	if (counter == 0) {
 		oldManActor = vm->_dragonINIResource->getRecord(0x161)->actor;
 		cloudChairActor = vm->_dragonINIResource->getRecord(0x160)->actor;
-		if (oldManActor->y_pos < 0x53) {
-			oldManActor->y_pos = 0x52;
-			cloudChairActor->y_pos = 0x52;
+		if (oldManActor->_y_pos < 0x53) {
+			oldManActor->_y_pos = 0x52;
+			cloudChairActor->_y_pos = 0x52;
 			direction = 1;
 		}
-		if (0x5b < oldManActor->y_pos) {
-			oldManActor->y_pos = 0x5c;
-			cloudChairActor->y_pos = 0x5c;
+		if (0x5b < oldManActor->_y_pos) {
+			oldManActor->_y_pos = 0x5c;
+			cloudChairActor->_y_pos = 0x5c;
 			direction = -1;
 		}
 		yOffset = direction * 2;
-		oldManActor->y_pos = oldManActor->y_pos + yOffset;
-		cloudChairActor->y_pos = cloudChairActor->y_pos + yOffset;
+		oldManActor->_y_pos = oldManActor->_y_pos + yOffset;
+		cloudChairActor->_y_pos = cloudChairActor->_y_pos + yOffset;
 		counter = 10;
 	}
 	else {
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index d166e2bbc9..e20fd1d840 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -506,10 +506,10 @@ Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 pa
 }
 
 void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex) {
-	int16 frameYOffset = actor->frame ? actor->frame->yOffset : 0;
+	int16 frameYOffset = actor->_frame ? actor->_frame->yOffset : 0;
 	displayDialogAroundPoint
-			(dialogText,(uint16)((int)(((uint)actor->x_pos - _vm->_scene->_camera.x) * 0x10000) >> 0x13),
-			 (short)((int)((((uint)actor->y_pos - (uint)frameYOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13) - 3,
+			(dialogText,(uint16)((int)(((uint)actor->_x_pos - _vm->_scene->_camera.x) * 0x10000) >> 0x13),
+			 (short)((int)((((uint)actor->_y_pos - (uint)frameYOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13) - 3,
 			 param_2,1,textIndex);
 }
 
@@ -638,8 +638,8 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 	} while (_vm->_scriptOpcodes->_data_80071f5c == 0);
 	_vm->_scriptOpcodes->_data_80071f5c--;
 //	LAB_80029bc0:
-//	actors[0].x_pos = cursor_x_var;
-//	actors[0].y_pos = cursor_y_var;
+//	actors[0]._x_pos = cursor_x_var;
+//	actors[0]._y_pos = cursor_y_var;
 
 	exitTalkMenu(isFlag8Set, isFlag100Set, dialogEntries);
 	return true;


Commit: 2ca5dc3f11340c172a974fd8cc836e79b2f52b93
    https://github.com/scummvm/scummvm/commit/2ca5dc3f11340c172a974fd8cc836e79b2f52b93
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Whitespace fixes

Changed paths:
    engines/dragons/actor.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index 062ef5e5c2..c723576b4f 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -108,7 +108,7 @@ void ActorManager::updateActorDisplayOrder() {
 			int16 curY = curActor->_y_pos > 0 ? curActor->_y_pos : 0;
 			int16 nextY = nextActor->_y_pos > 0 ? nextActor->_y_pos : 0;
 			if (nextActor->_priorityLayer * 0x1000000 + nextY * 0x100 + nextActor->_actorID <
-				curActor->_priorityLayer * 0x1000000 + curY * 0x100 + curActor->_actorID) {
+					curActor->_priorityLayer * 0x1000000 + curY * 0x100 + curActor->_actorID) {
 				_displayOrder[i] = nextActor->_actorID;
 				_displayOrder[i + 1] = curActor->_actorID;
 				shouldContinue = true;
@@ -223,18 +223,18 @@ uint32 calcDistance(int32 x1, int32 y1, int32 x2, int32 y2) {
 
 bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 	static const int kCosTbl[40] = {
-			// cos table
-			256, 251, 236, 212, 181, 142, 97, 49,
-			0, -49, -97, -142, -181, -212, -236, -251,
-			-255, -251, -236, -212, -181, -142, -97, -49,
-			0, 49, 97, 142, 181, 212, 236, 251,
-			11, 0, 0, 0, 0, 0, 0, 0
+		// cos table
+		256, 251, 236, 212, 181, 142, 97, 49,
+		0, -49, -97, -142, -181, -212, -236, -251,
+		-255, -251, -236, -212, -181, -142, -97, -49,
+		0, 49, 97, 142, 181, 212, 236, 251,
+		11, 0, 0, 0, 0, 0, 0, 0
 	};
 	static const int kAdjustXTbl[8] = {
-			1, -1, 0, 0, 1, -1, 1, -1
+		1, -1, 0, 0, 1, -1, 1, -1
 	};
 	static const int kAdjustYTbl[8] = {
-			0, 0, 1, -1, 1, 1, -1, -1
+		0, 0, 1, -1, 1, 1, -1, -1
 	};
 
 	debug("startWalk(%d, %d, %d)", _actorID, destX, destY);
@@ -659,18 +659,20 @@ int Actor::startMoveToPoint(int destX, int destY) {
 	}
 
 	switch (quadrant) {
-		case 0:
-			direction = (absDeltaX < absDeltaY) ? 2 : 0;
-			break;
-		case 1:
-			direction = (absDeltaX < absDeltaY) ? 6 : 0;
-			break;
-		case 2:
-			direction = (absDeltaX < absDeltaY) ? 2 : 4;
-			break;
-		case 3:
-			direction = (absDeltaX < absDeltaY) ? 6 : 4;
-			break;
+	case 0:
+		direction = (absDeltaX < absDeltaY) ? 2 : 0;
+		break;
+	case 1:
+		direction = (absDeltaX < absDeltaY) ? 6 : 0;
+		break;
+	case 2:
+		direction = (absDeltaX < absDeltaY) ? 2 : 4;
+		break;
+	case 3:
+		direction = (absDeltaX < absDeltaY) ? 6 : 4;
+		break;
+	default:
+		break;
 	}
 
 	_walkSlopeY /= 2;
@@ -686,79 +688,79 @@ int Actor::startMoveToPoint(int destX, int destY) {
 	return direction;
 }
 
-	void Actor::walkPath() {
-		if (isFlagClear(Dragons::ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
-			_xShl16 += (((_scale * _walkSlopeX) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
-			_yShl16 += (((_scale * _walkSlopeY) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
+void Actor::walkPath() {
+	if (isFlagClear(Dragons::ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
+		_xShl16 += (((_scale * _walkSlopeX) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
+		_yShl16 += (((_scale * _walkSlopeY) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
 
-			if ( (_walkSlopeX >= 0 && _walkDestX < (_xShl16 >> 0x10))
-			|| (_walkSlopeX < 0 && (_xShl16 >> 0x10) < _walkDestX)) {
-				_xShl16 = _walkDestX << 0x10;
-			}
+		if ( (_walkSlopeX >= 0 && _walkDestX < (_xShl16 >> 0x10))
+				|| (_walkSlopeX < 0 && (_xShl16 >> 0x10) < _walkDestX)) {
+			_xShl16 = _walkDestX << 0x10;
+		}
 
-			if ( (_walkSlopeY >= 0 && _walkDestY < (_yShl16 >> 0x10))
-				 || (_walkSlopeY < 0 && (_yShl16 >> 0x10) < _walkDestY)) {
-				_yShl16 = _walkDestY << 0x10;
-			}
+		if ( (_walkSlopeY >= 0 && _walkDestY < (_yShl16 >> 0x10))
+				|| (_walkSlopeY < 0 && (_yShl16 >> 0x10) < _walkDestY)) {
+			_yShl16 = _walkDestY << 0x10;
+		}
 
-			_x_pos = _xShl16 >> 0x10;
-			_y_pos = _yShl16 >> 0x10;
+		_x_pos = _xShl16 >> 0x10;
+		_y_pos = _yShl16 >> 0x10;
 
-			if (_x_pos == _walkDestX && _y_pos == _walkDestY) {
-				if (_walkPointsIndex <= 0) {
-					if (_finalWalkDestX < 0) {
-						clearFlag(ACTOR_FLAG_10);
-						if (isFlagClear(ACTOR_FLAG_200)) {
-							clearFlag(ACTOR_FLAG_800);
-						}
-						setFlag(ACTOR_FLAG_4);
-						clearFlag(ACTOR_FLAG_1);
-						return;
-					} else {
-						_walkDestX = _finalWalkDestX;
-						_walkDestY = _finalWalkDestY;
-						_finalWalkDestX = -1;
-						_finalWalkDestY = -1;
+		if (_x_pos == _walkDestX && _y_pos == _walkDestY) {
+			if (_walkPointsIndex <= 0) {
+				if (_finalWalkDestX < 0) {
+					clearFlag(ACTOR_FLAG_10);
+					if (isFlagClear(ACTOR_FLAG_200)) {
+						clearFlag(ACTOR_FLAG_800);
 					}
+					setFlag(ACTOR_FLAG_4);
+					clearFlag(ACTOR_FLAG_1);
+					return;
 				} else {
-					_walkPointsIndex--;
-					Common::Point point = getEngine()->_scene->getPoint(_walkPointsTbl[_walkPointsIndex]);
-					_walkDestX = point.x;
-					_walkDestY = point.y;
-				}
-				// 0x8001bcc8
-				int direction = startMoveToPoint(_walkDestX, _walkDestY);
-				if (direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
-					_sequenceID2 = direction;
-				}
-				if (_sequenceID != _sequenceID2 + 8 && _sequenceID2 != -1 && !isFlagSet(ACTOR_FLAG_800)) {
-					updateSequence(_sequenceID2 + 8);
+					_walkDestX = _finalWalkDestX;
+					_walkDestY = _finalWalkDestY;
+					_finalWalkDestX = -1;
+					_finalWalkDestY = -1;
 				}
-				setFlag(ACTOR_FLAG_10);
+			} else {
+				_walkPointsIndex--;
+				Common::Point point = getEngine()->_scene->getPoint(_walkPointsTbl[_walkPointsIndex]);
+				_walkDestX = point.x;
+				_walkDestY = point.y;
+			}
+			// 0x8001bcc8
+			int direction = startMoveToPoint(_walkDestX, _walkDestY);
+			if (direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
+				_sequenceID2 = direction;
 			}
+			if (_sequenceID != _sequenceID2 + 8 && _sequenceID2 != -1 && !isFlagSet(ACTOR_FLAG_800)) {
+				updateSequence(_sequenceID2 + 8);
+			}
+			setFlag(ACTOR_FLAG_10);
 		}
 	}
+}
 
-	// 0x80034930
-	int16 Actor::pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y,
-											 int16 unkType, bool *pointsInUseTbl) {
-		int16 pointId = -1;
-		uint32 minDist = 0xffffffff;
-
-		for (int i = 0; i < kPathPointsCount; i++) {
-			Common::Point point = getEngine()->_scene->getPoint(i);
-			if (point.x != -1 && !pointsInUseTbl[i]) {
-				if (canWalkLine(point.x, point.y, target_x, target_y, unkType)) {
-					uint32 dist = abs(point.x - actor_x) * abs(point.x - actor_x) + abs(point.y - actor_y) * abs(point.y - actor_y);
-					if ( dist < minDist) {
-						minDist = dist;
-						pointId = i;
-					}
+// 0x80034930
+int16 Actor::pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y,
+										 int16 unkType, bool *pointsInUseTbl) {
+	int16 pointId = -1;
+	uint32 minDist = 0xffffffff;
+
+	for (int i = 0; i < kPathPointsCount; i++) {
+		Common::Point point = getEngine()->_scene->getPoint(i);
+		if (point.x != -1 && !pointsInUseTbl[i]) {
+			if (canWalkLine(point.x, point.y, target_x, target_y, unkType)) {
+				uint32 dist = abs(point.x - actor_x) * abs(point.x - actor_x) + abs(point.y - actor_y) * abs(point.y - actor_y);
+				if ( dist < minDist) {
+					minDist = dist;
+					pointId = i;
 				}
 			}
 		}
-		return pointId;
 	}
+	return pointId;
+}
 
 bool Actor::actorSetSequenceAndWaitAllowSkip(uint16 newSequenceID) {
 	updateSequence(newSequenceID);


Commit: 1d783366c090d248174635c21fd5748871271692
    https://github.com/scummvm/scummvm/commit/1d783366c090d248174635c21fd5748871271692
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Remove superfluous namespace references

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/background.cpp
    engines/dragons/cursor.cpp
    engines/dragons/detection.cpp
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/saveload.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index c723576b4f..c6735e4b10 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -66,7 +66,7 @@ Actor *ActorManager::findFreeActor(int16 resourceId) {
 	int i = 0;
 	for (ActorsIterator it = _actors.begin(); it != _actors.end() && i < 23; ++it, i++) {
 		Actor *actor = it;
-		if (!(actor->_flags & Dragons::ACTOR_FLAG_40)) {
+		if (!(actor->_flags & ACTOR_FLAG_40)) {
 			actor->_resourceID = resourceId;
 			actor->_walkSpeed = 0x100000;
 			return actor;
@@ -161,7 +161,7 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	_walkDestY = y;
 	_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_sequenceID2 = 0;
-	_flags = (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
+	_flags = (ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
 	_frame_width = 0;
 	_frame_height = 0;
 	_frame_flags = 4;
@@ -174,7 +174,7 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 void Actor::updateSequence(uint16 newSequenceID) {
 	_sequenceID = newSequenceID;
 	_flags &= 0xfbf1;
-	_flags |= Dragons::ACTOR_FLAG_1;
+	_flags |= ACTOR_FLAG_1;
 }
 
 void Actor::resetSequenceIP() {
@@ -196,7 +196,7 @@ void Actor::loadFrame(uint16 frameOffset) {
 
 	debug(5, "ActorId: %d load frame header: (%d,%d)", _actorID, _frame->width, _frame->height);
 
-	_flags |= Dragons::ACTOR_FLAG_8; //TODO check if this is the right spot. engine sets it at 0x800185b0
+	_flags |= ACTOR_FLAG_8; //TODO check if this is the right spot. engine sets it at 0x800185b0
 
 }
 
@@ -468,16 +468,16 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 }
 
 void Actor::stopWalk() {
-	clearFlag(Dragons::ACTOR_FLAG_10);
+	clearFlag(ACTOR_FLAG_10);
 	_walkPointsIndex = 0;
 	_walkDestX = _x_pos;
 	_walkDestY = _y_pos;
 	_finalWalkDestX = -1;
 	_finalWalkDestY = -1;
-	setFlag(Dragons::ACTOR_FLAG_4);
+	setFlag(ACTOR_FLAG_4);
 
-	if (_flags & Dragons::ACTOR_FLAG_200) {
-		clearFlag(Dragons::ACTOR_FLAG_800);
+	if (_flags & ACTOR_FLAG_200) {
+		clearFlag(ACTOR_FLAG_800);
 	}
 }
 
@@ -488,11 +488,11 @@ void Actor::waitUntilFlag4IsSet() {
 }
 
 void Actor::waitUntilFlag8IsSet() {
-	if (_flags & Dragons::ACTOR_FLAG_8) {
+	if (_flags & ACTOR_FLAG_8) {
 		return;
 	}
 
-	while (!(_flags & Dragons::ACTOR_FLAG_8)) {
+	while (!(_flags & ACTOR_FLAG_8)) {
 		getEngine()->waitForFrames(1);
 	}
 }
@@ -689,7 +689,7 @@ int Actor::startMoveToPoint(int destX, int destY) {
 }
 
 void Actor::walkPath() {
-	if (isFlagClear(Dragons::ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
+	if (isFlagClear(ACTOR_FLAG_400) && isFlagSet(Dragons::ACTOR_FLAG_40) && isFlagSet(Dragons::ACTOR_FLAG_10)) {
 		_xShl16 += (((_scale * _walkSlopeX) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
 		_yShl16 += (((_scale * _walkSlopeY) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
 
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index ee423115bd..b2773a7c37 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -31,7 +31,7 @@ namespace Dragons {
 #define TILE_SIZE (TILE_WIDTH * TILE_HEIGHT)
 
 
-void Dragons::PriorityLayer::load(TileMap &tileMap, byte *tiles) {
+void PriorityLayer::load(TileMap &tileMap, byte *tiles) {
 	_width = tileMap.w * TILE_WIDTH;
 	_height = tileMap.h * TILE_HEIGHT;
 	_mapWidth = tileMap.w;
@@ -289,12 +289,12 @@ Common::Point Background::getLayerOffset(uint8 layerNumber) {
 	return layerOffset[layerNumber];
 }
 
-Dragons::AlphaBlendMode Background::getLayerAlphaMode(uint8 layerNumber) {
+AlphaBlendMode Background::getLayerAlphaMode(uint8 layerNumber) {
 	assert(layerNumber < 4);
 	return layerAlphaMode[layerNumber];
 }
 
-void Background::setLayerAlphaMode(uint8 layerNumber, Dragons::AlphaBlendMode mode) {
+void Background::setLayerAlphaMode(uint8 layerNumber, AlphaBlendMode mode) {
 	assert(layerNumber < 4);
 	layerAlphaMode[layerNumber] = mode;
 }
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 55ed3c0779..141b5a9ec6 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -46,11 +46,11 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	_actor->_flags = 0;
 	_actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_actor->updateSequence(_sequenceID);
-	_actor->_flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
-					   Dragons::ACTOR_FLAG_200);
+	_actor->_flags |= (ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
+					   ACTOR_FLAG_200);
 
 	dragonINIResource->getFlickerRecord()->actor = _actor; //TODO is this correct?
-	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= Dragons::INI_FLAG_1;
+	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= INI_FLAG_1;
 	_iniUnderCursor = 0;
 	iniItemInHand = 0;
 	data_8007283c = 0;
@@ -61,7 +61,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 
 
 void Cursor::update() {
-	if (!_vm->isFlagSet(Dragons::ENGINE_FLAG_8) || _vm->isFlagSet(Dragons::ENGINE_FLAG_100)) {
+	if (!_vm->isFlagSet(ENGINE_FLAG_8) || _vm->isFlagSet(Dragons::ENGINE_FLAG_100)) {
 		return;
 	}
 	// TODO update cursor from inputs here.
@@ -135,7 +135,7 @@ void Cursor::update() {
 }
 
 void Cursor::updateVisibility() {
-	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_8) && !_vm->isUnkFlagSet(Dragons::ENGINE_UNK1_FLAG_10)) {
+	if (_vm->isFlagSet(ENGINE_FLAG_8) && !_vm->isUnkFlagSet(Dragons::ENGINE_UNK1_FLAG_10)) {
 		_actor->_priorityLayer = 9;
 	} else {
 		_actor->_priorityLayer = 0;
@@ -148,7 +148,7 @@ void Cursor::updatePosition(int16 x, int16 y) {
 }
 
 int16 Cursor::updateINIUnderCursor() {
-	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_10)) {
+	if (_vm->isFlagSet(ENGINE_FLAG_10)) {
 		int16 xOffset = 0;
 		if (_vm->_inventory->getSequenceId() == 0 || _vm->_inventory->getSequenceId() == 2) {
 			if (_vm->_inventory->getPositionIndex() == 1 || _vm->_inventory->getPositionIndex() == 3) {
diff --git a/engines/dragons/detection.cpp b/engines/dragons/detection.cpp
index ed3a7dff0b..a0b877e74d 100644
--- a/engines/dragons/detection.cpp
+++ b/engines/dragons/detection.cpp
@@ -34,7 +34,7 @@ static const PlainGameDescriptor dragonsGames[] = {
 
 namespace Dragons {
 
-static const Dragons::DragonsGameDescription gameDescriptions[] = {
+static const DragonsGameDescription gameDescriptions[] = {
 		{
 				{
 						"dragons",
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 04609b07fd..1b02d7cd3f 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -622,8 +622,8 @@ void DragonsEngine::updateHandler() {
 	//TODO logic here
 	for (uint16 i = 0; i < 0x17; i++) {
 		Actor *actor = _actorManager->getActor(i);
-		if (actor->_flags & Dragons::ACTOR_FLAG_40) {
-			if (!(actor->_flags & Dragons::ACTOR_FLAG_100)) {
+		if (actor->_flags & ACTOR_FLAG_40) {
+			if (!(actor->_flags & ACTOR_FLAG_100)) {
 				int16 priority = _scene->getPriorityAtPosition(Common::Point(actor->_x_pos, actor->_y_pos));
 				DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 				if (flicker && _scene->contains(flicker) && flicker->actor->_actorID == i) {
@@ -651,7 +651,7 @@ void DragonsEngine::updateHandler() {
 		}
 	}
 
-	if (_flags & Dragons::ENGINE_FLAG_80) {
+	if (_flags & ENGINE_FLAG_80) {
 		for (uint16 i = 0x17; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
 			Actor *actor = _actorManager->getActor(i);
 			if (actor->_sequenceTimer != 0) {
@@ -702,28 +702,28 @@ void DragonsEngine::wait() {
 }
 
 void DragonsEngine::updateActorSequences() {
-	if (!(_flags & Dragons::ENGINE_FLAG_4)) {
+	if (!(_flags & ENGINE_FLAG_4)) {
 		return;
 	}
 
 	//TODO ResetRCnt(0xf2000001);
 
-	int16 actorId = _flags & Dragons::ENGINE_FLAG_80 ? (int16) 64 : (int16) 23;
+	int16 actorId = _flags & ENGINE_FLAG_80 ? (int16) 64 : (int16) 23;
 
 	while (actorId > 0) {
 		actorId--;
 		Actor *actor = _actorManager->getActor((uint16) actorId);
-		if (actorId < 2 && _flags & Dragons::ENGINE_FLAG_40) {
+		if (actorId < 2 && _flags & ENGINE_FLAG_40) {
 			continue;
 		}
 
-		if (actor->_flags & Dragons::ACTOR_FLAG_40 &&
-			!(actor->_flags & Dragons::ACTOR_FLAG_4) &&
-			!(actor->_flags & Dragons::ACTOR_FLAG_400) &&
-			(actor->_sequenceTimer == 0 || actor->_flags & Dragons::ACTOR_FLAG_1)) {
+		if (actor->_flags & ACTOR_FLAG_40 &&
+			!(actor->_flags & ACTOR_FLAG_4) &&
+			!(actor->_flags & ACTOR_FLAG_400) &&
+			(actor->_sequenceTimer == 0 || actor->_flags & ACTOR_FLAG_1)) {
 			debug(5, "Actor[%d] execute sequenceOp", actorId);
 
-			if (actor->_flags & Dragons::ACTOR_FLAG_1) {
+			if (actor->_flags & ACTOR_FLAG_1) {
 				actor->resetSequenceIP();
 				//clear flag mask 0xeff6;
 				actor->clearFlag(ACTOR_FLAG_1);
@@ -828,11 +828,11 @@ void DragonsEngine::runINIScripts() {
 	bool isFlag8Set = isFlagSet(ENGINE_FLAG_8);
 	for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
-		if (ini->field_1a_flags_maybe & Dragons::INI_FLAG_10) {
-			ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
+		if (ini->field_1a_flags_maybe & INI_FLAG_10) {
+			ini->field_1a_flags_maybe &= ~INI_FLAG_10;
 			byte *data = _dragonOBD->getFromOpt(i);
 			ScriptOpCall scriptOpCall(data + 8, READ_LE_UINT32(data));
-			clearFlags(Dragons::ENGINE_FLAG_8);
+			clearFlags(ENGINE_FLAG_8);
 			_scriptOpcodes->runScript3(scriptOpCall);
 		}
 	}
@@ -916,8 +916,8 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 
 //TODO the logic in this function doesn't match the original. It should be redone.
 void DragonsEngine::engineFlag0x20UpdateFunction() {
-	if (_flags & Dragons::ENGINE_FLAG_20) {
-		if ((_flags & (Dragons::ENGINE_FLAG_80000000 | Dragons::ENGINE_FLAG_8)) == 8) {
+	if (_flags & ENGINE_FLAG_20) {
+		if ((_flags & (ENGINE_FLAG_80000000 | Dragons::ENGINE_FLAG_8)) == 8) {
 			_cursor->update();
 		}
 		//TODO 0x80027be4
@@ -969,7 +969,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 				if (ini->field_10 >= 0 && ini->sceneId == currentSceneId) {
 					ini->field_10--;
 					if (ini->field_10 < 0) {
-						ini->field_1a_flags_maybe |= Dragons::INI_FLAG_10;
+						ini->field_1a_flags_maybe |= INI_FLAG_10;
 					}
 				}
 			}
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 41a2bbce4d..7f96b502b8 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -83,8 +83,8 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_actor->_flags = 0;
 	_actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_actor->updateSequence(0);
-	_actor->_flags |= (Dragons::ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
-					   Dragons::ACTOR_FLAG_200);
+	_actor->_flags |= (ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
+					   ACTOR_FLAG_200);
 	_sequenceId = 0;
 	_type = 0;
 	_old_showing_value = 0;
@@ -100,7 +100,7 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 
 void Inventory::loadScene(uint32 sceneId) {
 	if (!_type) {
-		_sequenceId = _vm->isFlagSet(Dragons::ENGINE_FLAG_400000) ? 1 : 0;
+		_sequenceId = _vm->isFlagSet(ENGINE_FLAG_400000) ? 1 : 0;
 	}
 
 	if (_sequenceId == 0 && _vm->getVar(7) == 1) {
@@ -113,7 +113,7 @@ void Inventory::loadScene(uint32 sceneId) {
 }
 
 void Inventory::updateVisibility() {
-	_actor->_priorityLayer = _vm->isFlagSet(Dragons::ENGINE_FLAG_10) ? (int16)6 : (int16)0;
+	_actor->_priorityLayer = _vm->isFlagSet(ENGINE_FLAG_10) ? (int16)6 : (int16)0;
 }
 
 Common::Point Inventory::getPosition() {
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
index aeb98e2ff5..61f929d627 100644
--- a/engines/dragons/saveload.cpp
+++ b/engines/dragons/saveload.cpp
@@ -35,7 +35,7 @@ namespace Dragons {
 
 #define ILLUSIONS_SAVEGAME_VERSION 0
 
-Dragons::kReadSaveHeaderError DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
+kReadSaveHeaderError DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
 
 	header.version = in->readUint32LE();
 	if (header.version > ILLUSIONS_SAVEGAME_VERSION)
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 563386088b..c05ee87c1e 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -83,14 +83,14 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 }
 
 void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
-	bool isUnkFlag2Set = _vm->isUnkFlagSet(Dragons::ENGINE_UNK1_FLAG_2);
+	bool isUnkFlag2Set = _vm->isUnkFlagSet(ENGINE_UNK1_FLAG_2);
 
-	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_2 | Dragons::ENGINE_UNK1_FLAG_8);
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2 | Dragons::ENGINE_UNK1_FLAG_8);
 
 	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		ini->field_10 = -1;
-		ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
+		ini->field_1a_flags_maybe &= ~INI_FLAG_10;
 	}
 
 	uint16 sceneIdStripped = (uint16)sceneId & ~0x8000;
@@ -125,8 +125,8 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	// Loading animation logic would go here. 0x8002f538
 
-	_vm->clearFlags(Dragons::ENGINE_FLAG_20);
-	_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_10);
+	_vm->clearFlags(ENGINE_FLAG_20);
+	_vm->setUnkFlags(ENGINE_UNK1_FLAG_10);
 
 	_vm->call_fade_related_1f();
 	// TODO 0x8002f7c4
@@ -210,11 +210,11 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	// 0x8002ff80
 	// TODO fade_related_calls_with_1f();
-	_vm->clearUnkFlags(Dragons::ENGINE_UNK1_FLAG_10);
-	_vm->setFlags(Dragons::ENGINE_FLAG_20);
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_10);
+	_vm->setFlags(ENGINE_FLAG_20);
 	// TODO reset vsync_updater_function
 
-	_vm->setFlags(Dragons::ENGINE_FLAG_200);
+	_vm->setFlags(ENGINE_FLAG_200);
 	_actorManager->clearActorFlags(2);
 	_vm->data_800633fc = 0;
 	// TODO 0x8002fff0
@@ -240,25 +240,25 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 					actor->_sequenceID2 = ini->field_20_actor_field_14;
 
 					if (ini->field_1a_flags_maybe & 2) {
-						actor->_flags |= Dragons::ACTOR_FLAG_80;
+						actor->_flags |= ACTOR_FLAG_80;
 					} else {
 						actor->_flags &= 0xfeff;
 					}
 
 					if (ini->field_1a_flags_maybe & 0x20) {
-						actor->_flags |= Dragons::ACTOR_FLAG_100;
+						actor->_flags |= ACTOR_FLAG_100;
 					} else {
 						actor->_flags &= 0xfeff;
 					}
 
 					if (ini->field_1a_flags_maybe & 4) {
-						actor->_flags |= Dragons::ACTOR_FLAG_8000;
+						actor->_flags |= ACTOR_FLAG_8000;
 					} else {
 						actor->_flags &= 0x7fff;
 					}
 
 					if (ini->field_1a_flags_maybe & 0x100) {
-						actor->_flags |= Dragons::ACTOR_FLAG_4000;
+						actor->_flags |= ACTOR_FLAG_4000;
 					} else {
 						actor->_flags &= 0xbfff;
 					}
@@ -284,7 +284,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	// 0x80030458
 	DragonINI *ini = _vm->getINI(1);
 	if (ini->actor && _vm->_dragonINIResource->getFlickerRecord() && _vm->_dragonINIResource->getFlickerRecord()->sceneId == _currentSceneId) {
-		ini->actor->setFlag(Dragons::ACTOR_FLAG_100);
+		ini->actor->setFlag(ACTOR_FLAG_100);
 		ini->actor->_priorityLayer = 0;
 	}
 
@@ -293,7 +293,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 		flicker->field_20_actor_field_14 = _vm->data_800633fa;
 		if (flicker->actor) {
 			flicker->actor->_sequenceID2 = _vm->data_800633fa;
-			flicker->actor->setFlag(Dragons::ACTOR_FLAG_4);
+			flicker->actor->setFlag(ACTOR_FLAG_4);
 		}
 	}
 
@@ -307,24 +307,24 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 		_vm->_inventory->hide();
 	}
 
-	if (!_vm->isFlagSet(Dragons::ENGINE_FLAG_10000)) {
-		_vm->setFlags(Dragons::ENGINE_FLAG_10);
+	if (!_vm->isFlagSet(ENGINE_FLAG_10000)) {
+		_vm->setFlags(ENGINE_FLAG_10);
 	}
 
-	_vm->setFlags(Dragons::ENGINE_FLAG_1);
-	_vm->setFlags(Dragons::ENGINE_FLAG_200);
-	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
+	_vm->setFlags(ENGINE_FLAG_1);
+	_vm->setFlags(ENGINE_FLAG_200);
+	_vm->setFlags(ENGINE_FLAG_4000000);
 
 	if (flicker && flicker->sceneId == _currentSceneId) {
 
 		flicker->actor->updateSequence((uint16)flicker->actor->_sequenceID2);
 	}
 
-	_vm->clearUnkFlags(Dragons::ENGINE_UNK1_FLAG_2);
-	_vm->clearUnkFlags(Dragons::ENGINE_UNK1_FLAG_8);
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
+	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_8);
 
 	if (isUnkFlag2Set) {
-		_vm->setUnkFlags(Dragons::ENGINE_UNK1_FLAG_2);
+		_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 	}
 
 	if (!(sceneId & 0x8000)) {
@@ -363,8 +363,8 @@ void Scene::draw() {
 				continue;
 			}
 
-			if (actor->_flags & Dragons::ACTOR_FLAG_40 &&
-				!(actor->_flags & Dragons::ACTOR_FLAG_400) &&
+			if (actor->_flags & ACTOR_FLAG_40 &&
+				!(actor->_flags & ACTOR_FLAG_400) &&
 				actor->_surface &&
 				actor->_frame->width != 0 &&
 				actor->_frame->height != 0
@@ -380,7 +380,7 @@ void Scene::draw() {
 					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d Scale: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
 						  s->w, s->h, actor->_priorityLayer, actor->_scale);
-						_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->_frame->flags & Dragons::FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? NONE : NORMAL, actor->_scale);
+						_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->_frame->flags & FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? NONE : NORMAL, actor->_scale);
 					if (_vm->isDebugMode()) {
 						_screen->drawRect(0x7fff, Common::Rect(x, y, x + s->w, y + s->h), actor->_actorID);
 						drawActorNumber(x + s->w, y + 8, actor->_actorID);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index a7dcee50a1..20614142b6 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -183,14 +183,14 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 //		return;
 //	}
 //
-//	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
+//	if (_vm->isFlagSet(ENGINE_FLAG_100000)) {
 //		return;
 //	}
 //
-//	if (_vm->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
+//	if (_vm->isFlagSet(ENGINE_FLAG_80000)) {
 //		//TODO
 ////		if (IsPressedStart(0)) {
-////			Dragons::getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
+////			getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
 ////		}
 //	}
 //
@@ -203,14 +203,14 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 //
 	while (scriptOpCall._code < scriptOpCall._codeEnd && !(scriptOpCall._result & 1)) {
 
-		if (_vm->isFlagSet(Dragons::ENGINE_FLAG_100000)) {
+		if (_vm->isFlagSet(ENGINE_FLAG_100000)) {
 			return;
 		}
 
-		if (_vm->isFlagSet(Dragons::ENGINE_FLAG_80000)) {
+		if (_vm->isFlagSet(ENGINE_FLAG_80000)) {
 			//TODO
 //		if (IsPressedStart(0)) {
-//			Dragons::getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
+//			getEngine()->setFlags(Dragons::ENGINE_FLAG_100000);
 //		}
 		}
 
@@ -368,7 +368,7 @@ void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
 
 	bool isFlicker = _vm->_dragonINIResource->isFlicker(field2 - 1);
 	if (isFlicker) {
-		ini->actor->_flags |= Dragons::ACTOR_FLAG_2000;
+		ini->actor->_flags |= ACTOR_FLAG_2000;
 	}
 
 	if (!ini->actor->_actorResource || ini->actor->_actorResource->_id != ini->actorResourceId) {
@@ -382,7 +382,7 @@ void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
 	}
 
 	if (isFlicker) {
-		ini->actor->_flags &= ~Dragons::ACTOR_FLAG_2000;
+		ini->actor->_flags &= ~ACTOR_FLAG_2000;
 	}
 }
 
@@ -616,7 +616,7 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 		if (field6 != -1) {
 			if (!(field0 & 0x8000)) {
 				assert(ini->actor);
-				ini->actor->_flags |= Dragons::ACTOR_FLAG_800;
+				ini->actor->_flags |= ACTOR_FLAG_800;
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
 			ini->actor->_walkSpeed = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
@@ -626,13 +626,13 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 		ini->actor->startWalk(point.x, point.y, isFlicker ? 0 : 1);
 
 		if (s3 == 0) {
-			while (ini->actor->_flags & Dragons::ACTOR_FLAG_10) {
+			while (ini->actor->_flags & ACTOR_FLAG_10) {
 				_vm->waitForFrames(1);
 			}
 		}
 		ini->x = point.x;
 		ini->y = point.y;
-		ini->actor->clearFlag(Dragons::ACTOR_FLAG_800);
+		ini->actor->clearFlag(ACTOR_FLAG_800);
 
 	} else {
 		ini->x = point.x;
@@ -670,7 +670,7 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 		if (field6 != -1) {
 			if (!(field0 & 0x8000)) {
 				assert(ini->actor);
-				ini->actor->_flags |= Dragons::ACTOR_FLAG_800;
+				ini->actor->_flags |= ACTOR_FLAG_800;
 				ini->actor->updateSequence(field6 & 0x7fff);
 			}
 			ini->actor->_walkSpeed = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
@@ -679,13 +679,13 @@ void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
 		ini->actor->startWalk(field8, fieldA, isFlicker ? 0 : 1);
 
 		if (s3 == 0) {
-			while (ini->actor->_flags & Dragons::ACTOR_FLAG_10) {
+			while (ini->actor->_flags & ACTOR_FLAG_10) {
 				_vm->waitForFrames(1);
 			}
 		}
 		ini->x = field8;
 		ini->y = fieldA;
-		ini->actor->_flags &= ~Dragons::ACTOR_FLAG_800;
+		ini->actor->_flags &= ~ACTOR_FLAG_800;
 
 	} else {
 		assert(ini->actor);
@@ -790,7 +790,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 	}
 	secondIni->actor->startWalk(newXPosAgain, newYPosAgain, someBooleanFlag);
 	if (!bVar1) {
-		while (secondIni->actor->_flags & Dragons::ACTOR_FLAG_10) {
+		while (secondIni->actor->_flags & ACTOR_FLAG_10) {
 			_vm->waitForFrames(1);
 		}
 	}
@@ -838,7 +838,7 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 
 		_vm->_scene->loadScene(newSceneID, cameraPointID);
 	} else {
-		_vm->setFlags(Dragons::ENGINE_FLAG_100000);
+		_vm->setFlags(ENGINE_FLAG_100000);
 	}
 }
 
@@ -939,16 +939,16 @@ void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
 
 		if (field2 == 0x1a && ini->field_1a_flags_maybe & 1 && ini->sceneId == _vm->getCurrentSceneId()) {
 			if (s1 & 2) {
-				ini->actor->_flags |= Dragons::ACTOR_FLAG_80;
+				ini->actor->_flags |= ACTOR_FLAG_80;
 				ini->actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 			} else {
-				ini->actor->_flags &= ~Dragons::ACTOR_FLAG_80;
+				ini->actor->_flags &= ~ACTOR_FLAG_80;
 			}
 
 			if (s1 & 4) {
-				ini->actor->_flags |= Dragons::ACTOR_FLAG_8000;
+				ini->actor->_flags |= ACTOR_FLAG_8000;
 			} else {
-				ini->actor->_flags &= ~Dragons::ACTOR_FLAG_8000;
+				ini->actor->_flags &= ~ACTOR_FLAG_8000;
 			}
 		}
 
@@ -1049,7 +1049,7 @@ void ScriptOpcodes::opUnk17(ScriptOpCall &scriptOpCall) {
 
 	DragonINI *ini = _vm->getINI(iniId - 1);
 	if (ini->field_1a_flags_maybe & 1) {
-		while (!(ini->actor->_flags & Dragons::ACTOR_FLAG_4)) {
+		while (!(ini->actor->_flags & ACTOR_FLAG_4)) {
 			_vm->waitForFrames(1);
 		}
 	}
@@ -1185,27 +1185,27 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 				ini->actor = _vm->_actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
 				ini->actor->_sequenceID2 = ini->field_20_actor_field_14;
 				if (ini->field_1a_flags_maybe & 2) {
-					ini->actor->_flags |= Dragons::ACTOR_FLAG_80;
+					ini->actor->_flags |= ACTOR_FLAG_80;
 				} else {
-					ini->actor->_flags &= ~Dragons::ACTOR_FLAG_80;
+					ini->actor->_flags &= ~ACTOR_FLAG_80;
 				}
 
 				if (ini->field_1a_flags_maybe & 0x20) {
-					ini->actor->_flags |= Dragons::ACTOR_FLAG_100;
+					ini->actor->_flags |= ACTOR_FLAG_100;
 				} else {
-					ini->actor->_flags &= ~Dragons::ACTOR_FLAG_100;
+					ini->actor->_flags &= ~ACTOR_FLAG_100;
 				}
 
 				if (ini->field_1a_flags_maybe & 4) {
-					ini->actor->_flags |= Dragons::ACTOR_FLAG_8000;
+					ini->actor->_flags |= ACTOR_FLAG_8000;
 				} else {
-					ini->actor->_flags &= ~Dragons::ACTOR_FLAG_8000;
+					ini->actor->_flags &= ~ACTOR_FLAG_8000;
 				}
 
 				if (ini->field_1a_flags_maybe & 0x100) {
-					ini->actor->_flags |= Dragons::ACTOR_FLAG_4000;
+					ini->actor->_flags |= ACTOR_FLAG_4000;
 				} else {
-					ini->actor->_flags &= ~Dragons::ACTOR_FLAG_4000;
+					ini->actor->_flags &= ~ACTOR_FLAG_4000;
 				}
 			}
 		} else {
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 28475ecbe0..227e10a65b 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -117,7 +117,7 @@ void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
 	ARG_INT16(framePointer);
 	debug(4, "set frame pointer %X", framePointer);
 	actor->loadFrame((uint16)framePointer);
-	actor->_flags |= Dragons::ACTOR_FLAG_2;
+	actor->_flags |= ACTOR_FLAG_2;
 	actor->_sequenceTimer = actor->_field_c;
 	updateReturn(opCall, 1);
 }
@@ -130,7 +130,7 @@ void SequenceOpcodes::opSetFramePointerAndStop(Actor *actor, OpCall &opCall) {
 void SequenceOpcodes::opJmp(Actor *actor, OpCall &opCall) {
 	ARG_INT16(newIp);
 
-	if (!(actor->_flags & Dragons::ACTOR_FLAG_1000)) {
+	if (!(actor->_flags & ACTOR_FLAG_1000)) {
 		byte *newOffset = actor->getSeqIpAtOffset((uint32)newIp);
 		opCall._deltaOfs = (int32)(newOffset - actor->_seqCodeIp); //opCall._code);
 		debug(5, "opJump delta: %d", opCall._deltaOfs);
@@ -171,19 +171,19 @@ void SequenceOpcodes::opUpdateXYResetSeqTimerAndStop(Actor *actor, OpCall &opCal
 }
 
 void SequenceOpcodes::opSetActorFlag4AndStop(Actor *actor, OpCall &opCall) {
-	actor->_flags |= Dragons::ACTOR_FLAG_4;
+	actor->_flags |= ACTOR_FLAG_4;
 	opCall._deltaOfs = 0;
 	opCall._result = 0;
 	//updateReturn(opCall, 1);
 }
 
 void SequenceOpcodes::opSetActorFlags404(Actor *actor, OpCall &opCall) {
-	actor->_flags |= (Dragons::ACTOR_FLAG_4 | Dragons::ACTOR_FLAG_400 );
+	actor->_flags |= (ACTOR_FLAG_4 | Dragons::ACTOR_FLAG_400 );
 	updateReturn(opCall, 1);
 }
 
 void SequenceOpcodes::opClearActorFlag400(Actor *actor, OpCall &opCall) {
-	actor->_flags &= ~Dragons::ACTOR_FLAG_400;
+	actor->_flags &= ~ACTOR_FLAG_400;
 	updateReturn(opCall, 1);
 }
 
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index ac3ab0f7c6..06e459c264 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -237,11 +237,11 @@ void SpecialOpcodes::spcThumbWrestlingMiniGame() {
 }
 
 void SpecialOpcodes::spcClearEngineFlag10() {
-	_vm->clearFlags(Dragons::ENGINE_FLAG_10);
+	_vm->clearFlags(ENGINE_FLAG_10);
 }
 
 void SpecialOpcodes::spcSetEngineFlag10() {
-	_vm->setFlags(Dragons::ENGINE_FLAG_10);
+	_vm->setFlags(ENGINE_FLAG_10);
 }
 
 void SpecialOpcodes::spcRabbitsMiniGame() {
@@ -300,19 +300,19 @@ void SpecialOpcodes::spcCastleGardenLogic() {
 void SpecialOpcodes::spcUnk9() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	assert(flicker);
-	flicker->field_1a_flags_maybe |= Dragons::INI_FLAG_20;
+	flicker->field_1a_flags_maybe |= INI_FLAG_20;
 	assert(flicker->actor);
-	flicker->actor->_flags |= Dragons::ACTOR_FLAG_100;
+	flicker->actor->_flags |= ACTOR_FLAG_100;
 	flicker->actor->_priorityLayer = 0;
-	_vm->getINI(1)->field_1a_flags_maybe |= Dragons::INI_FLAG_20;
+	_vm->getINI(1)->field_1a_flags_maybe |= INI_FLAG_20;
 }
 
 
 void SpecialOpcodes::spcUnkA() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
-	flicker->field_1a_flags_maybe &= ~Dragons::INI_FLAG_20;
-	flicker->actor->_flags &= ~Dragons::ACTOR_FLAG_100;
-	_vm->getINI(1)->field_1a_flags_maybe &= ~Dragons::INI_FLAG_20;
+	flicker->field_1a_flags_maybe &= ~INI_FLAG_20;
+	flicker->actor->_flags &= ~ACTOR_FLAG_100;
+	_vm->getINI(1)->field_1a_flags_maybe &= ~INI_FLAG_20;
 }
 
 void SpecialOpcodes::spcUnkC() {
@@ -367,11 +367,11 @@ void SpecialOpcodes::spcUnk13InventionBookCloseRelated() {
 }
 
 void SpecialOpcodes::spcClearEngineFlag8() {
-	_vm->clearFlags(Dragons::ENGINE_FLAG_8);
+	_vm->clearFlags(ENGINE_FLAG_8);
 }
 
 void SpecialOpcodes::spcSetEngineFlag8() {
-	_vm->setFlags(Dragons::ENGINE_FLAG_8);
+	_vm->setFlags(ENGINE_FLAG_8);
 }
 
 void SpecialOpcodes::spcKnightPoolReflectionLogic() {
@@ -683,11 +683,11 @@ void SpecialOpcodes::spcBlackDragonCrashThroughGate() {
 }
 
 void SpecialOpcodes::spcSetEngineFlag0x2000000() {
-	_vm->setFlags(Dragons::ENGINE_FLAG_2000000);
+	_vm->setFlags(ENGINE_FLAG_2000000);
 }
 
 void SpecialOpcodes::spcClearEngineFlag0x2000000() {
-	_vm->clearFlags(Dragons::ENGINE_FLAG_2000000);
+	_vm->clearFlags(ENGINE_FLAG_2000000);
 }
 
 void SpecialOpcodes::spcZigmondFraudSceneLogic() {
@@ -886,11 +886,11 @@ void SpecialOpcodes::spcCloseInventionBook() {
 }
 
 void SpecialOpcodes::spcSetEngineFlag0x4000000() {
-	_vm->setFlags(Dragons::ENGINE_FLAG_4000000);
+	_vm->setFlags(ENGINE_FLAG_4000000);
 }
 
 void SpecialOpcodes::spcClearEngineFlag0x4000000() {
-	_vm->clearFlags(Dragons::ENGINE_FLAG_4000000);
+	_vm->clearFlags(ENGINE_FLAG_4000000);
 }
 
 void SpecialOpcodes::spcSetCursorSequenceIdToZero() {


Commit: 7a912ee39f8386fc23f58d3b44f37ed568a7d7e1
    https://github.com/scummvm/scummvm/commit/7a912ee39f8386fc23f58d3b44f37ed568a7d7e1
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More whitespace fixes

Changed paths:
    engines/dragons/actorfiles.h
    engines/dragons/actorresource.cpp
    engines/dragons/background.cpp
    engines/dragons/bigfile.cpp
    engines/dragons/cursor.cpp
    engines/dragons/dragonimg.cpp
    engines/dragons/dragonini.cpp
    engines/dragons/dragonrms.cpp
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/scene.cpp


diff --git a/engines/dragons/actorfiles.h b/engines/dragons/actorfiles.h
index d688ab7a7e..c73be815b2 100644
--- a/engines/dragons/actorfiles.h
+++ b/engines/dragons/actorfiles.h
@@ -25,224 +25,224 @@
 #define DRAGONS_NUM_ACTOR_FILES 219
 
 const char actorResourceFiles[DRAGONS_NUM_ACTOR_FILES][13] = {
-		"cursor.act",
-		"invenicn.act",
-		"s01b1.act",
-		"s00f1.act",
-		"s01h4.act",
-		"s07b2.act",
-		"s01g6.act",
-		"s02d1.act",
-		"s02d4.act",
-		"s00h6.act",
-		"s00h8.act",
-		"s00h3.act",
-		"s03a3.act",
-		"s00h2.act",
-		"flicker.act",
-		"s00h4.act",
-		"s00h5.act",
-		"s00h1.act",
-		"s00h7.act",
-		"s00h9.act",
-		"s03a6.act",
-		"s00i1.act",
-		"s00i4.act",
-		"s00j2.act",
-		"s00j1.act",
-		"s00i2.act",
-		"s01h1.act",
-		"flkspec.act",
-		"s03a2.act",
-		"s03a1.act",
-		"s12a2.act",
-		"s12a1.act",
-		"s12a4.act",
-		"s01f1.act",
-		"s01l1.act",
-		"s02c4.act",
-		"s03a4.act",
-		"s12a3.act",
-		"s02d3.act",
-		"s00ha.act",
-		"s01j2.act",
-		"s01j1.act",
-		"s01j0.act",
-		"s07a1.act",
-		"s07a2.act",
-		"s02b1.act",
-		"s02b2.act",
-		"s06a1.act",
-		"s06a2.act",
-		"s12c1.act",
-		"s12b2.act",
-		"s04a1.act",
-		"s00i3.act",
-		"s04a2.act",
-		"s02a2.act",
-		"s09i1.act",
-		"s02a3.act",
-		"s02a1.act",
-		"s02a4.act",
-		"s02d2.act",
-		"s05a1.act",
-		"s02c3.act",
-		"s02c1.act",
-		"s02c2.act",
-		"s02c5.act",
-		"s02c8.act",
-		"s02a5.act",
-		"s02c9.act",
-		"s02c6.act",
-		"s02c51.act",
-		"s09i2.act",
-		"s00f2.act",
-		"s02ca.act",
-		"s02c11.act",
-		"s02c7.act",
-		"s11a1.act",
-		"s09b2.act",
-		"s09b3.act",
-		"s09b6.act",
-		"s09b7.act",
-		"s09b1.act",
-		"s09b4.act",
-		"shadow.act",
-		"s09e1.act",
-		"flkg.act",
-		"s01g4.act",
-		"s01g3.act",
-		"s01g2.act",
-		"s00f3.act",
-		"s01g7.act",
-		"s09h4.act",
-		"s09c3.act",
-		"s09c2.act",
-		"s09c1.act",
-		"s09c4.act",
-		"s00b1.act",
-		"s09b5.act",
-		"s01k2.act",
-		"s01k1.act",
-		"s10b1.act",
-		"s01c1.act",
-		"s01h5.act",
-		"s09a1.act",
-		"s13a4.act",
-		"s09f1.act",
-		"s08a1.act",
-		"s09f3.act",
-		"s08b1.act",
-		"s07b1.act",
-		"s09f2.act",
-		"s00f4.act",
-		"s06b1.act",
-		"s05b1.act",
-		"s05b2.act",
-		"s05b3.act",
-		"s05b4.act",
-		"s05b5.act",
-		"s10a3.act",
-		"s10a6.act",
-		"s10a2.act",
-		"s10a1.act",
-		"s10a5.act",
-		"s10a7.act",
-		"s10a4.act",
-		"s01d1.act",
-		"s01d2.act",
-		"s01d3.act",
-		"s12b1.act",
-		"s12b3.act",
-		"s01d4.act",
-		"s01d5.act",
-		"s13a1.act",
-		"s13a2.act",
-		"s13a0.act",
-		"s04a3.act",
-		"s13a3.act",
-		"s13a5.act",
-		"flickert.act",
-		"s01a1.act",
-		"s01d7.act",
-		"s01d8.act",
-		"s14e1.act",
-		"s14e2.act",
-		"s01d9.act",
-		"s07c1.act",
-		"s10b2.act",
-		"s01g1.act",
-		"s01g5.act",
-		"s01h2.act",
-		"s01h3.act",
-		"s01i1.act",
-		"s02b3.act",
-		"s03a5.act",
-		"s09i4.act",
-		"s09i3.act",
-		"s14a1.act",
-		"s14a2.act",
-		"s01k3.act",
-		"s01i2.act",
-		"s01b2.act",
-		"s01c2.act",
-		"s14a3.act",
-		"s01j3.act",
-		"s01f2.act",
-		"s01c3.act",
-		"s01i3.act",
-		"s01e1.act",
-		"s01h6.act",
-		"s07b3.act",
-		"s01a2.act",
-		"s01da.act",
-		"s02a6.act",
-		"s02d5.act",
-		"s07a3.act",
-		"s07b4.act",
-		"s09e2.act",
-		"s10b3.act",
-		"s10b4.act",
-		"s09c5.act",
-		"s09h5.act",
-		"s14d1.act",
-		"s02e1.act",
-		"s09d1.act",
-		"s14f1.act",
-		"s14g1.act",
-		"s14g2.act",
-		"s14g3.act",
-		"s10d1.act",
-		"s08a2.act",
-		"s09c6.act",
-		"s00g1.act",
-		"s00g2.act",
-		"s00g3.act",
-		"s04a4.act",
-		"s08a3.act",
-		"s11a2.act",
-		"s02cb.act",
-		"s11a3.act",
-		"s05b0.act",
-		"s14a5.act",
-		"s14a25.act",
-		"s14a0.act",
-		"s14a15.act",
-		"s05b6.act",
-		"s12a5.act",
-		"s12a6.act",
-		"s13b1.act",
-		"s13b2.act",
-		"s01g8.act",
-		"s01g9.act",
-		"s02cc.act",
-		"s01d20.act",
-		"s01d21.act",
-		"s01d22.act",
-		"s01d23.act",
-		"s01d24.act",
-		"s01d25.act",
-		"titles.act",
-		"dem11.act"
+	"cursor.act",
+	"invenicn.act",
+	"s01b1.act",
+	"s00f1.act",
+	"s01h4.act",
+	"s07b2.act",
+	"s01g6.act",
+	"s02d1.act",
+	"s02d4.act",
+	"s00h6.act",
+	"s00h8.act",
+	"s00h3.act",
+	"s03a3.act",
+	"s00h2.act",
+	"flicker.act",
+	"s00h4.act",
+	"s00h5.act",
+	"s00h1.act",
+	"s00h7.act",
+	"s00h9.act",
+	"s03a6.act",
+	"s00i1.act",
+	"s00i4.act",
+	"s00j2.act",
+	"s00j1.act",
+	"s00i2.act",
+	"s01h1.act",
+	"flkspec.act",
+	"s03a2.act",
+	"s03a1.act",
+	"s12a2.act",
+	"s12a1.act",
+	"s12a4.act",
+	"s01f1.act",
+	"s01l1.act",
+	"s02c4.act",
+	"s03a4.act",
+	"s12a3.act",
+	"s02d3.act",
+	"s00ha.act",
+	"s01j2.act",
+	"s01j1.act",
+	"s01j0.act",
+	"s07a1.act",
+	"s07a2.act",
+	"s02b1.act",
+	"s02b2.act",
+	"s06a1.act",
+	"s06a2.act",
+	"s12c1.act",
+	"s12b2.act",
+	"s04a1.act",
+	"s00i3.act",
+	"s04a2.act",
+	"s02a2.act",
+	"s09i1.act",
+	"s02a3.act",
+	"s02a1.act",
+	"s02a4.act",
+	"s02d2.act",
+	"s05a1.act",
+	"s02c3.act",
+	"s02c1.act",
+	"s02c2.act",
+	"s02c5.act",
+	"s02c8.act",
+	"s02a5.act",
+	"s02c9.act",
+	"s02c6.act",
+	"s02c51.act",
+	"s09i2.act",
+	"s00f2.act",
+	"s02ca.act",
+	"s02c11.act",
+	"s02c7.act",
+	"s11a1.act",
+	"s09b2.act",
+	"s09b3.act",
+	"s09b6.act",
+	"s09b7.act",
+	"s09b1.act",
+	"s09b4.act",
+	"shadow.act",
+	"s09e1.act",
+	"flkg.act",
+	"s01g4.act",
+	"s01g3.act",
+	"s01g2.act",
+	"s00f3.act",
+	"s01g7.act",
+	"s09h4.act",
+	"s09c3.act",
+	"s09c2.act",
+	"s09c1.act",
+	"s09c4.act",
+	"s00b1.act",
+	"s09b5.act",
+	"s01k2.act",
+	"s01k1.act",
+	"s10b1.act",
+	"s01c1.act",
+	"s01h5.act",
+	"s09a1.act",
+	"s13a4.act",
+	"s09f1.act",
+	"s08a1.act",
+	"s09f3.act",
+	"s08b1.act",
+	"s07b1.act",
+	"s09f2.act",
+	"s00f4.act",
+	"s06b1.act",
+	"s05b1.act",
+	"s05b2.act",
+	"s05b3.act",
+	"s05b4.act",
+	"s05b5.act",
+	"s10a3.act",
+	"s10a6.act",
+	"s10a2.act",
+	"s10a1.act",
+	"s10a5.act",
+	"s10a7.act",
+	"s10a4.act",
+	"s01d1.act",
+	"s01d2.act",
+	"s01d3.act",
+	"s12b1.act",
+	"s12b3.act",
+	"s01d4.act",
+	"s01d5.act",
+	"s13a1.act",
+	"s13a2.act",
+	"s13a0.act",
+	"s04a3.act",
+	"s13a3.act",
+	"s13a5.act",
+	"flickert.act",
+	"s01a1.act",
+	"s01d7.act",
+	"s01d8.act",
+	"s14e1.act",
+	"s14e2.act",
+	"s01d9.act",
+	"s07c1.act",
+	"s10b2.act",
+	"s01g1.act",
+	"s01g5.act",
+	"s01h2.act",
+	"s01h3.act",
+	"s01i1.act",
+	"s02b3.act",
+	"s03a5.act",
+	"s09i4.act",
+	"s09i3.act",
+	"s14a1.act",
+	"s14a2.act",
+	"s01k3.act",
+	"s01i2.act",
+	"s01b2.act",
+	"s01c2.act",
+	"s14a3.act",
+	"s01j3.act",
+	"s01f2.act",
+	"s01c3.act",
+	"s01i3.act",
+	"s01e1.act",
+	"s01h6.act",
+	"s07b3.act",
+	"s01a2.act",
+	"s01da.act",
+	"s02a6.act",
+	"s02d5.act",
+	"s07a3.act",
+	"s07b4.act",
+	"s09e2.act",
+	"s10b3.act",
+	"s10b4.act",
+	"s09c5.act",
+	"s09h5.act",
+	"s14d1.act",
+	"s02e1.act",
+	"s09d1.act",
+	"s14f1.act",
+	"s14g1.act",
+	"s14g2.act",
+	"s14g3.act",
+	"s10d1.act",
+	"s08a2.act",
+	"s09c6.act",
+	"s00g1.act",
+	"s00g2.act",
+	"s00g3.act",
+	"s04a4.act",
+	"s08a3.act",
+	"s11a2.act",
+	"s02cb.act",
+	"s11a3.act",
+	"s05b0.act",
+	"s14a5.act",
+	"s14a25.act",
+	"s14a0.act",
+	"s14a15.act",
+	"s05b6.act",
+	"s12a5.act",
+	"s12a6.act",
+	"s13b1.act",
+	"s13b2.act",
+	"s01g8.act",
+	"s01g9.act",
+	"s02cc.act",
+	"s01d20.act",
+	"s01d21.act",
+	"s01d22.act",
+	"s01d23.act",
+	"s01d24.act",
+	"s01d25.act",
+	"titles.act",
+	"dem11.act"
 };
 #endif //DRAGONS_ACTORFILES_H
diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index 2346020143..dc40dc5090 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -74,7 +74,7 @@ bool ActorResource::load(uint32 id, byte *dataStart, Common::SeekableReadStream
 	debug("Frame Count: %d", _framesCount);
 
 	_frames = new ActorFrame[_framesCount];
-	for (int i=0; i < _framesCount; i++) {
+	for (int i = 0; i < _framesCount; i++) {
 		stream.seek(frameOffset + i * 2);
 
 		uint16 offset = stream.readUint16LE();
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index b2773a7c37..4e94473d86 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -66,7 +66,7 @@ int16 PriorityLayer::getPriority(Common::Point pos) {
 void PriorityLayer::overlayTileMap(byte *data, int16 x, int16 y, int16 w, int16 h) {
 	byte *ptr = _map + (x + y * _mapWidth) * 2;
 	byte *src = data;
-	for (int i=0;i < h; i++) {
+	for (int i = 0;i < h; i++) {
 		memcpy(ptr, src, w * 2);
 		src += w * 2;
 		ptr += _mapWidth * 2;
@@ -76,7 +76,7 @@ void PriorityLayer::overlayTileMap(byte *data, int16 x, int16 y, int16 w, int16
 void PriorityLayer::restoreTileMap(int16 x, int16 y, int16 w, int16 h) {
 	byte *ptr = _map + (x + y * _mapWidth) * 2;
 	byte *src = _mapBase + (x + y * _mapWidth) * 2;
-	for (int i=0;i < h; i++) {
+	for (int i = 0;i < h; i++) {
 		memcpy(ptr, src, w * 2);
 		src += _mapWidth * 2;
 		ptr += _mapWidth * 2;
@@ -125,7 +125,7 @@ bool Background::load(byte *dataStart, uint32 size) {
 	stream.seek(0x308);
 
 	uint32 tilemapOffset = 0x324;
-	for (int i=0;i< 3;i++) {
+	for (int i = 0;i< 3;i++) {
 		_tileMap[i].w = stream.readUint16LE();
 		_tileMap[i].h = stream.readUint16LE();
 		_tileMap[i].size = stream.readUint32LE();
@@ -171,7 +171,7 @@ bool Background::load(byte *dataStart, uint32 size) {
 Common::Point *Background::loadPoints(Common::SeekableReadStream &stream) {
 	Common::Point *points = new Common::Point[0x20];
 
-	for (int i=0;i < 0x20;i++) {
+	for (int i = 0;i < 0x20;i++) {
 		points[i].x = stream.readUint16LE();
 		points[i].y = stream.readUint16LE();
 	}
diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
index c012d7d138..c95f9878b3 100644
--- a/engines/dragons/bigfile.cpp
+++ b/engines/dragons/bigfile.cpp
@@ -610,7 +610,7 @@ FileInfo fileInfo[TOTAL_FILES] = {
 };
 
 uint32 getResourceId(const char *filename) {
-	for (uint32 i=0; i < TOTAL_FILES; i++) {
+	for (uint32 i = 0; i < TOTAL_FILES; i++) {
 		if (scumm_stricmp(fileInfo[i].filename, filename) == 0) {
 			return i;
 		}
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 141b5a9ec6..86bf2593c1 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -205,7 +205,7 @@ int16 Cursor::updateIniFromScene() {
 	int16 cursorTileY = cursorY / 8;
 	int16 data_80072890_orig = data_80072890;
 	int16 data_800728b0_cursor_seqID_orig = data_800728b0_cursor_seqID;
-	for (int i=0;i <_vm->_dragonINIResource->totalRecords(); i++) {
+	for (int i = 0;i <_vm->_dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId != _vm->_scene->getSceneId()) {
 			// 0x80028be4
diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
index be9a364012..a39fdbd0f8 100644
--- a/engines/dragons/dragonimg.cpp
+++ b/engines/dragons/dragonimg.cpp
@@ -38,7 +38,7 @@ DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
 
 	_imgObjects = new IMG[_count];
 
-	for (int i=0; i < _count; i++) {
+	for (int i = 0; i < _count; i++) {
 		imgReadStream->seek(iptReadStream->readUint32LE());
 		_imgObjects[i].x = imgReadStream->readUint16LE();
 		_imgObjects[i].y = imgReadStream->readUint16LE();
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index 25a6ea3305..b3410804bb 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -40,7 +40,7 @@ void DragonINIResource::reset() {
 		_dragonINI = new DragonINI[_count];
 	}
 
-	for (int i=0; i < _count; i++) {
+	for (int i = 0; i < _count; i++) {
 		_dragonINI[i].id = (uint16)i;
 		_dragonINI[i].iptIndex_maybe = readStream->readSint16LE();
 		_dragonINI[i].field_2 = readStream->readSint16LE();
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
index 18301779be..ffc218a0ae 100644
--- a/engines/dragons/dragonrms.cpp
+++ b/engines/dragons/dragonrms.cpp
@@ -37,7 +37,7 @@ DragonRMS::DragonRMS(BigfileArchive *bigfileArchive, DragonOBD *dragonOBD) : _dr
 
 	_rmsObjects = new RMS[_count];
 
-	for (int i=0; i < _count; i++) {
+	for (int i = 0; i < _count; i++) {
 		_rmsObjects[i]._field0 = readStream->readSint32LE();
 		readStream->read(_rmsObjects[i]._sceneName, 4);
 		_rmsObjects[i]._obdOffset = readStream->readSint32LE();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 1b02d7cd3f..6e95456704 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -243,7 +243,7 @@ uint16 DragonsEngine::ipt_img_file_related() {
 	int16 tileX = flicker->actor->_x_pos / 32;
 	int16 tileY = flicker->actor->_y_pos / 8;
 
-	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i = 0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
 		if ((ini->sceneId == getCurrentSceneId()) && (ini->field_1a_flags_maybe == 0)) {
 			IMG *img = _dragonIMG->getIMG(ini->field_2);
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 7f96b502b8..59a0dfb80f 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -273,7 +273,7 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 void Inventory::loadInventoryItemsFromSave() {
 	memset(inventoryItemTbl, 0, sizeof(inventoryItemTbl));
 	int j = 0;
-	for (int i=0; i < _vm->_dragonINIResource->totalRecords() && j < DRAGONS_MAX_INVENTORY_ITEMS; i++ ) {
+	for (int i = 0; i < _vm->_dragonINIResource->totalRecords() && j < DRAGONS_MAX_INVENTORY_ITEMS; i++ ) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId == 1) {
 			inventoryItemTbl[j++] = i + 1;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index c05ee87c1e..f0716da369 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -87,7 +87,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2 | Dragons::ENGINE_UNK1_FLAG_8);
 
-	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i = 0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		ini->field_10 = -1;
 		ini->field_1a_flags_maybe &= ~INI_FLAG_10;
@@ -219,7 +219,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_vm->data_800633fc = 0;
 	// TODO 0x8002fff0
 
-	for (int i=0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i = 0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		if (ini->sceneId == sceneIdStripped) {
 			if (ini->field_1a_flags_maybe & 1) {


Commit: c28b2d2a07a1f7220f28292282a87ce78b1ec2c6
    https://github.com/scummvm/scummvm/commit/c28b2d2a07a1f7220f28292282a87ce78b1ec2c6
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fix warnings

Changed paths:
    engines/dragons/actorresource.h
    engines/dragons/background.cpp
    engines/dragons/bigfile.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/screen.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/actorresource.h b/engines/dragons/actorresource.h
index 82636c2ea1..b9d35ca384 100644
--- a/engines/dragons/actorresource.h
+++ b/engines/dragons/actorresource.h
@@ -64,7 +64,7 @@ private:
 	uint16 _framesCount;
 	byte _palette[512];
 	uint16 _sequenceTableOffset;
-	uint16 _sequenceCount;
+	//uint16 _sequenceCount;
 
 public:
 	bool load(uint32 id, byte *dataStart, Common::SeekableReadStream &stream);
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 4e94473d86..6535fe1fd1 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -252,9 +252,9 @@ void Background::overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int
 	}
 }
 
-void Background::restoreTiles(uint16 layerNum, int16 x, int16 y, int16 w, int16 h) {
-	int16 tmw = x + w;
-	int16 tmh = y + h;
+void Background::restoreTiles(uint16 layerNum, int16 x1, int16 y1, int16 w, int16 h) {
+	int16 tmw = x1 + w;
+	int16 tmh = y1 + h;
 	for (int y = 0; y < tmh; y++) {
 		for (int x = 0; x < tmw; x++) {
 			uint16 idx = READ_LE_UINT16(&_tileMap[layerNum].map[(y * _tileMap[layerNum].w + x) * 2]) + _tileMap[layerNum].tileIndexOffset;
diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
index c95f9878b3..396eea30a7 100644
--- a/engines/dragons/bigfile.cpp
+++ b/engines/dragons/bigfile.cpp
@@ -619,7 +619,8 @@ uint32 getResourceId(const char *filename) {
 	return TOTAL_FILES;
 }
 
-BigfileArchive::BigfileArchive(const char *filename, Common::Language language) :_fd(0), _language(language) {
+BigfileArchive::BigfileArchive(const char *filename, Common::Language language) :_fd(0) {
+	_language = language;
 	_fd = new Common::File();
 	if (!_fd->open(filename))
 		error("BigfileArchive::BigfileArchive() Could not open %s", filename);
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 745c4a8078..95287a9377 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -40,7 +40,7 @@ static const uint16 unkArray[5] = {
 };
 
 void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
-	uint16 uVar1;
+	//uint16 uVar1;
 	short sVar2;
 	short sVar3;
 	bool shouldExit;
@@ -58,11 +58,11 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	Actor *uVar13;
 	Actor *uVar14;
 	Actor *uVar15;
-	uint16 uVar16;
-	uint16 uVar17;
+	//uint16 uVar16;
+	//uint16 uVar17;
 	uint uVar18;
-	uint uVar19;
-	int iVar20;
+	//uint uVar19;
+	//int iVar20;
 	bool shouldShakeScreen;
 	uint16 local_2e6;
 	int16 actorSequenceIdTbl [15];
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index e78643061e..5dae9d385d 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -63,19 +63,19 @@ Minigame3::Minigame3(DragonsEngine *vm) : _vm(vm) {}
 void Minigame3::run() {
 	bool bVar1;
 	Actor *handActorId;
-	uint16 actorId;
+	//uint16 actorId;
 	int16 sVar2;
-	int iVar3;
+	//int iVar3;
 	uint tmpValue;
 	int iVar4;
 	DragonINI *flicker;
 	uint16 origSceneId;
-	byte auStack1584_palette [512]; //[126];
+	//byte auStack1584_palette [512]; //[126];
 	uint16 local_5b2;
-	byte auStack1072_palette [512];
+	//byte auStack1072_palette [512];
 	Actor *bunnyActorTbl [4];
 	uint16 local_228;
-	uint16 local_226;
+	//uint16 local_226;
 	int16 local_224;
 	Actor *tearActorTbl [8];
 	uint16 local_210;
@@ -113,7 +113,6 @@ void Minigame3::run() {
 	uint16 local_1e;
 	uint16 local_1c;
 	uint16 local_1a;
-	uint16 i;
 	int16 local_16;
 	int16 local_14;
 	int16 origInventoryType;
@@ -128,12 +127,12 @@ void Minigame3::run() {
 		error("Failed to open arc1.bin");
 	}
 
-	for (i = 0;i < 21; i++) {
+	for (int i = 0; i < 21; i++) {
 		eyeBgYOffsetTbl[i] = fd->readUint16LE();
 	}
 
 	fd->seek(0x2c);
-	for (i = 0; i < 30; i++) {
+	for (int i = 0; i < 30; i++) {
 		tearInfo[i].x = fd->readUint16LE();
 		tearInfo[i].y = fd->readUint16LE();
 		tearInfo[i].unk = fd->readUint16LE();
@@ -199,7 +198,7 @@ void Minigame3::run() {
 //	memcpy2(auStack1072_palette,scrFileData_maybe,0x200);
 	local_5b2 = 0x7fff;
 //	DisableVSyncEvent();
-	i = 0;
+	int i = 0;
 	while ((int16)i < 4) {
 		bunnyActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x15,4,0,0);
 		if (bunnyActorTbl[(int16)i] == NULL) {
@@ -561,7 +560,7 @@ void Minigame3::run() {
 					local_1e8 = 0;
 					FUN_80017f70_paletteRelated(0);
 					local_1b8 = 0;
-					flags = flags & 0xfffd | 4;
+					flags = (flags & 0xfffd) | 4;
 					local_1c8 = 2;
 					local_1c6 = 3;
 					updateBackgroundLayerOffset(2, 0x780, 0);
@@ -591,7 +590,7 @@ void Minigame3::run() {
 						updateBackgroundLayerOffset(2, 0x8c0, 0);
 						tearBlinkActorTbl2[0]->updateSequence(2);
 						tearBlinkActorTbl2[1]->updateSequence(3);
-						flags = flags & 0xfffe | 2;
+						flags = (flags & 0xfffe) | 2;
 					}
 				}
 			}
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index e9eaef3cbf..596928d247 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -112,30 +112,30 @@ void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *pa
  **/
 uint16 alphaBlendRGB555( uint32 fg, uint32 bg, uint8 alpha ){
 	alpha = ( alpha + 4 ) >> 3;
-	bg = (bg | (bg << 16)) & 0b00000011111000000111110000011111;
-	fg = (fg | (fg << 16)) & 0b00000011111000000111110000011111;
-	uint32 result = ((((fg - bg) * alpha) >> 5) + bg) & 0b00000011111000000111110000011111;
+	bg = (bg | (bg << 16)) & 0x3e07c1f;
+	fg = (fg | (fg << 16)) & 0x3e07c1f;
+	uint32 result = ((((fg - bg) * alpha) >> 5) + bg) & 0x3e07c1f;
 	return (uint16)((result >> 16) | result);
 }
 
 uint16 alphaBlendAdditiveRGB555( uint32 fg, uint32 bg){
-	bg = (bg | (bg << 16)) & 0b00000011111000000111110000011111;
-	fg = (fg | (fg << 16)) & 0b00000011111000000111110000011111;
+	bg = (bg | (bg << 16)) & 0x3e07c1f;
+	fg = (fg | (fg << 16)) & 0x3e07c1f;
 
 	uint32 result = bg + fg;
 	//clip r g b values to 565.
-	if (result & (0b111111 << 26)) {
+	if (result & (0x3f << 26)) {
 		result &= 0x1fffff;
 		result |= 0x3E00000;
 	}
 
 	if (result & 0x1F8000) {
-		result &= 0b00000011111000000111111111111111;
+		result &= 0x3e07fff;
 		result |= 0x7C00;
 	}
 
 	if (result & 0x3E0) {
-		result &= 0b00000011111000000111110000011111;
+		result &= 0x3e07c1f;
 		result |= 0x1f;
 	}
 	return (uint16)((result >> 16) | result);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 20614142b6..b488e6e4d2 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -90,7 +90,7 @@ ScriptOpcodes::~ScriptOpcodes() {
 void ScriptOpcodes::execOpcode(ScriptOpCall &scriptOpCall) {
 	if (!_opcodes[scriptOpCall._op])
 		error("ScriptOpcodes::execOpcode() Unimplemented opcode %d (0x%X)", scriptOpCall._op, scriptOpCall._op);
-	debug("execScriptOpcode(0x%X) @%X  %s", scriptOpCall._op, scriptOpCall._code - scriptOpCall._base, _opcodeNames[scriptOpCall._op].c_str());
+	debug("execScriptOpcode(0x%X) @%lX  %s", scriptOpCall._op, scriptOpCall._code - scriptOpCall._base, _opcodeNames[scriptOpCall._op].c_str());
 	(*_opcodes[scriptOpCall._op])(scriptOpCall);
 }
 
@@ -387,7 +387,7 @@ void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
 }
 
 void ScriptOpcodes::opPlayMusic(ScriptOpCall &scriptOpCall) {
-	byte *code = scriptOpCall._code;
+	//byte *code = scriptOpCall._code;
 	scriptOpCall._code += 4;
 	if (scriptOpCall._field8 == 0) {
 		//TODO play music here.
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index e20fd1d840..291df0905d 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -112,24 +112,24 @@ Talk::FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param
 
 uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
 									  int16 param_7) {
-		uint32 *puVar1;
-		uint32 *puVar2;
+		//uint32 *puVar1;
+		//uint32 *puVar2;
 		short sVar3;
 		short sVar4;
 		uint16 *tmpTextPtr;
 		int iVar5;
 		int iVar6;
-		int iVar7;
+		//int iVar7;
 		int iVar8;
 		uint uVar9;
 		uint uVar10;
 		uint16 uVar11;
-		uint32 uVar12;
+		//uint32 uVar12;
 		uint16 *puVar13;
-		uint32 uVar14;
-		uint32 uVar15;
-		uint32 *puVar16;
-		uint32 *puVar17;
+		//uint32 uVar14;
+		//uint32 uVar15;
+		//uint32 *puVar16;
+		//uint32 *puVar17;
 		uint16 *dialogTextLinePtr;
 		uint16 *puVar18;
 		uint16 *curDialogTextPtr;
@@ -139,11 +139,11 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 		uint32 maxLineLengthMaybe;
 		uint16 currentLine [44];
 		uint16 asStack2592 [1208];
-		uint32 local_b0 [14];
+		//uint32 local_b0 [14];
 		uint16 local_58;
 		uint16 returnStatus;
-		byte *lineTblPtr;
-		uint oldEngineFlags;
+		//byte *lineTblPtr;
+		//uint oldEngineFlags;
 
 		bool isFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
 		returnStatus = 0;


Commit: 039d8c027413f0c919297ddad5785b03e54241d5
    https://github.com/scummvm/scummvm/commit/039d8c027413f0c919297ddad5785b03e54241d5
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fix warnings

Changed paths:
    engines/dragons/minigame5.cpp


diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index dc3dfec9f5..914d0cb6cf 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -42,11 +42,11 @@ Minigame5::Minigame5(DragonsEngine *vm) : _vm(vm), DAT_800633e6(0) {}
 
 void Minigame5::run() {
 	uint16 uVar1;
-	int iVar2;
-	byte *local_v0_7008;
-	void *local_v0_7256;
-	byte *uVar3;
-	uint uVar4;
+	//int iVar2;
+	//byte *local_v0_7008;
+	//void *local_v0_7256;
+	//byte *uVar3;
+	//uint uVar4;
 	uint16 local_850;
 	uint16 auStack2120 [1000];
 	DragonINI*local_78;
@@ -75,7 +75,7 @@ void Minigame5::run() {
 	int16_t local_44;
 	short local_42;
 	uint16 local_30 [4];
-	uint16 uStack42;
+	//uint16 uStack42;
 	uint16 local_28 [10];
 	short local_10;
 	uint32 savedEngineFlags;


Commit: 647f687830a6f609073255ed13615cb44ceb2b86
    https://github.com/scummvm/scummvm/commit/647f687830a6f609073255ed13615cb44ceb2b86
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Whitespace fixes

Changed paths:
    engines/dragons/actorresource.cpp
    engines/dragons/background.cpp
    engines/dragons/bag.cpp


diff --git a/engines/dragons/actorresource.cpp b/engines/dragons/actorresource.cpp
index dc40dc5090..dae8f50ea5 100644
--- a/engines/dragons/actorresource.cpp
+++ b/engines/dragons/actorresource.cpp
@@ -149,8 +149,7 @@ ActorFrame *ActorResource::getFrameHeader(uint16 frameNumber) {
 	return &_frames[frameNumber];
 }
 
-byte *ActorResource::getSequenceData(int16 sequenceId)
-{
+byte *ActorResource::getSequenceData(int16 sequenceId) {
 	uint16 offset = READ_LE_UINT16(_data + _sequenceTableOffset + (sequenceId * 2));
 	return &_data[offset];
 }
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 6535fe1fd1..568c4a9283 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -66,7 +66,7 @@ int16 PriorityLayer::getPriority(Common::Point pos) {
 void PriorityLayer::overlayTileMap(byte *data, int16 x, int16 y, int16 w, int16 h) {
 	byte *ptr = _map + (x + y * _mapWidth) * 2;
 	byte *src = data;
-	for (int i = 0;i < h; i++) {
+	for (int i = 0; i < h; i++) {
 		memcpy(ptr, src, w * 2);
 		src += w * 2;
 		ptr += _mapWidth * 2;
@@ -76,7 +76,7 @@ void PriorityLayer::overlayTileMap(byte *data, int16 x, int16 y, int16 w, int16
 void PriorityLayer::restoreTileMap(int16 x, int16 y, int16 w, int16 h) {
 	byte *ptr = _map + (x + y * _mapWidth) * 2;
 	byte *src = _mapBase + (x + y * _mapWidth) * 2;
-	for (int i = 0;i < h; i++) {
+	for (int i = 0; i < h; i++) {
 		memcpy(ptr, src, w * 2);
 		src += _mapWidth * 2;
 		ptr += _mapWidth * 2;
@@ -125,7 +125,7 @@ bool Background::load(byte *dataStart, uint32 size) {
 	stream.seek(0x308);
 
 	uint32 tilemapOffset = 0x324;
-	for (int i = 0;i< 3;i++) {
+	for (int i = 0; i < 3;i++) {
 		_tileMap[i].w = stream.readUint16LE();
 		_tileMap[i].h = stream.readUint16LE();
 		_tileMap[i].size = stream.readUint32LE();
@@ -171,7 +171,7 @@ bool Background::load(byte *dataStart, uint32 size) {
 Common::Point *Background::loadPoints(Common::SeekableReadStream &stream) {
 	Common::Point *points = new Common::Point[0x20];
 
-	for (int i = 0;i < 0x20;i++) {
+	for (int i = 0; i < 0x20; i++) {
 		points[i].x = stream.readUint16LE();
 		points[i].y = stream.readUint16LE();
 	}
@@ -353,7 +353,7 @@ uint16 ScaleLayer::getScale(uint16 y) {
 //		iVar3 = i * 0x10000;
 //	} while (-1 < i * 0x10000);
 	lowerYBandIdx = 32;
-	for (int16 i = 0; i < 32; i++) {
+	for (int i = 0; i < 32; i++) {
 		yBand = _bands[i]._y;
 		if (yBand != -1 && y <= yBand) {
 			lowerYBandIdx = i;
@@ -394,7 +394,7 @@ uint16 ScaleLayer::getScale(uint16 y) {
 			if (local_v0_368 != 0) {
 				iVar3 = ((uVar5 & 0xffffu) - (uVar7 & 0xffffu)) * (uint)(uint16)(y - pSVar6->_y);
 
-				assert (((uint)(uint16)local_v0_368 != 0xffffffff) || (iVar3 != -0x80000000));
+				assert(((uint)(uint16)local_v0_368 != 0xffffffff) || (iVar3 != -0x80000000));
 
 				return uVar7 + iVar3 / (int)(uint)(uint16)local_v0_368 & 0xffff;
 			}
diff --git a/engines/dragons/bag.cpp b/engines/dragons/bag.cpp
index 803b881feb..01697ce4bd 100644
--- a/engines/dragons/bag.cpp
+++ b/engines/dragons/bag.cpp
@@ -66,7 +66,7 @@ void Bag::load(BigfileArchive *bigFileArchive) {
 	pal[1] = 0x0;
 	for (int i = 1; i < 0x100; i++) {
 		uint c = READ_LE_INT16(&pal[i * 2]);
-		if ( c == 0 ) {
+		if (c == 0) {
 			c = 0x8000;
 		} else {
 			//c = (uint16)(((uint)c & 0x1f) << 10) | (uint16)(((uint)c & 0x7c00) >> 10) | c & 0x3e0;


Commit: 89e9e76efafedd7a6d2058345b27d5cbeb9f9650
    https://github.com/scummvm/scummvm/commit/89e9e76efafedd7a6d2058345b27d5cbeb9f9650
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More class variable renames

Changed paths:
    engines/dragons/background.cpp
    engines/dragons/background.h
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonflg.h
    engines/dragons/dragonimg.cpp
    engines/dragons/dragonimg.h
    engines/dragons/dragonobd.cpp
    engines/dragons/dragonobd.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/font.cpp
    engines/dragons/font.h
    engines/dragons/minigame4.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 568c4a9283..66ed3c067c 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -88,12 +88,12 @@ Background::Background() : _priorityLayer(0), _points2(0), _data(0) {
 	_layerSurface[0] = NULL;
 	_layerSurface[1] = NULL;
 	_layerSurface[2] = NULL;
-	layerOffset[0] = Common::Point(0,0);
-	layerOffset[1] = Common::Point(0,0);
-	layerOffset[2] = Common::Point(0,0);
-	layerAlphaMode[0] = NORMAL;
-	layerAlphaMode[1] = NORMAL;
-	layerAlphaMode[2] = NORMAL;
+	_layerOffset[0] = Common::Point(0,0);
+	_layerOffset[1] = Common::Point(0,0);
+	_layerOffset[2] = Common::Point(0,0);
+	_layerAlphaMode[0] = NORMAL;
+	_layerAlphaMode[1] = NORMAL;
+	_layerAlphaMode[2] = NORMAL;
 }
 
 Background::~Background() {
@@ -161,9 +161,9 @@ bool Background::load(byte *dataStart, uint32 size) {
 		loadGfxLayer(_layerSurface[i], _tileMap[i], _tileDataOffset);
 	}
 
-	layerPriority[0] = 1;
-	layerPriority[1] = 2;
-	layerPriority[2] = 3;
+	_layerPriority[0] = 1;
+	_layerPriority[1] = 2;
+	_layerPriority[2] = 3;
 
 	return false;
 }
@@ -281,22 +281,22 @@ void Background::setPalette(byte *newPalette) {
 
 void Background::setLayerOffset(uint8 layerNumber, Common::Point offset) {
 	assert(layerNumber < 4);
-	layerOffset[layerNumber] = offset;
+	_layerOffset[layerNumber] = offset;
 }
 
 Common::Point Background::getLayerOffset(uint8 layerNumber) {
 	assert(layerNumber < 4);
-	return layerOffset[layerNumber];
+	return _layerOffset[layerNumber];
 }
 
 AlphaBlendMode Background::getLayerAlphaMode(uint8 layerNumber) {
 	assert(layerNumber < 4);
-	return layerAlphaMode[layerNumber];
+	return _layerAlphaMode[layerNumber];
 }
 
 void Background::setLayerAlphaMode(uint8 layerNumber, AlphaBlendMode mode) {
 	assert(layerNumber < 4);
-	layerAlphaMode[layerNumber] = mode;
+	_layerAlphaMode[layerNumber] = mode;
 }
 
 BackgroundResourceLoader::BackgroundResourceLoader(BigfileArchive *bigFileArchive, DragonRMS *dragonRMS) : _bigFileArchive(
diff --git a/engines/dragons/background.h b/engines/dragons/background.h
index 33f49878ae..549ed39885 100644
--- a/engines/dragons/background.h
+++ b/engines/dragons/background.h
@@ -83,9 +83,9 @@ private:
 	byte _palette[512];
 	Graphics::Surface *_layerSurface[3];
 	Common::Point *_points2;
-	uint8 layerPriority[3];
-	Common::Point layerOffset[3];
-	AlphaBlendMode layerAlphaMode[3];
+	uint8 _layerPriority[3];
+	Common::Point _layerOffset[3];
+	AlphaBlendMode _layerAlphaMode[3];
 
 public:
 	Background();
@@ -97,13 +97,13 @@ public:
 	Graphics::Surface *getBgLayer() { return _layerSurface[0]; }
 	Graphics::Surface *getMgLayer() { return _layerSurface[1]; }
 	Graphics::Surface *getFgLayer() { return _layerSurface[2]; }
-	uint8 getBgLayerPriority() { return layerPriority[0]; }
-	uint8 getMgLayerPriority() { return layerPriority[1]; }
-	uint8 getFgLayerPriority() { return layerPriority[2]; }
+	uint8 getBgLayerPriority() { return _layerPriority[0]; }
+	uint8 getMgLayerPriority() { return _layerPriority[1]; }
+	uint8 getFgLayerPriority() { return _layerPriority[2]; }
 
-	void setBgLayerPriority(uint8 newPriority) { layerPriority[0] = newPriority; }
-	void setMgLayerPriority(uint8 newPriority) { layerPriority[1] = newPriority; }
-	void setFgLayerPriority(uint8 newPriority) { layerPriority[2] = newPriority; }
+	void setBgLayerPriority(uint8 newPriority) { _layerPriority[0] = newPriority; }
+	void setMgLayerPriority(uint8 newPriority) { _layerPriority[1] = newPriority; }
+	void setFgLayerPriority(uint8 newPriority) { _layerPriority[2] = newPriority; }
 
 	int16 getPriorityAtPoint(Common::Point pos);
 	Common::Point getPoint2(uint32 pointIndex);
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 86bf2593c1..aa0b9d4003 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -52,11 +52,11 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	dragonINIResource->getFlickerRecord()->actor = _actor; //TODO is this correct?
 	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= INI_FLAG_1;
 	_iniUnderCursor = 0;
-	iniItemInHand = 0;
+	_iniItemInHand = 0;
 	data_8007283c = 0;
 	_cursorActivationSeqOffset = 0;
-	data_800728b0_cursor_seqID = 0;
-	data_80072890 = 0;
+	_data_800728b0_cursor_seqID = 0;
+	_data_80072890 = 0;
 }
 
 
@@ -119,7 +119,7 @@ void Cursor::update() {
 		}
 	}
 
-	if (iniItemInHand == 0) {
+	if (_iniItemInHand == 0) {
 		if (_actor->_sequenceID != 0x84) {
 			_actor->updateSequence(0x84);
 		}
@@ -203,8 +203,8 @@ int16 Cursor::updateIniFromScene() {
 	int16 cursorY = _y + _vm->_scene->_camera.y;
 	int16 cursorTileX = cursorX / 32;
 	int16 cursorTileY = cursorY / 8;
-	int16 data_80072890_orig = data_80072890;
-	int16 data_800728b0_cursor_seqID_orig = data_800728b0_cursor_seqID;
+	int16 _data_80072890_orig = _data_80072890;
+	int16 _data_800728b0_cursor_seqID_orig = _data_800728b0_cursor_seqID;
 	for (int i = 0;i <_vm->_dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId != _vm->_scene->getSceneId()) {
@@ -225,7 +225,7 @@ int16 Cursor::updateIniFromScene() {
 			} else {
 				// 0x80028a24
 				if (ini->field_2 != -1) {
-					IMG *img = _vm->_dragonIMG->getIMG((uint32)ini->field_2);
+					Img *img = _vm->_dragonImg->getImg((uint32)ini->field_2);
 					if (img->field_e - 1 >= 1) { // TODO this is >= 2 in the original.
 						if (cursorTileX >= img->x && cursorTileX < img->x + img->w && cursorTileY >= img->y && cursorTileY < img->y + img->h) {
 							cursorOverIni = i + 1;
@@ -241,13 +241,13 @@ int16 Cursor::updateIniFromScene() {
 			if (cursorOverIni != 0) {
 				// 0x80028bf0
 				// _iniUnderCursor = cursorOverIni;
-				data_80072890 = _iniUnderCursor;
-				data_800728b0_cursor_seqID = _sequenceID;
+				_data_80072890 = _iniUnderCursor;
+				_data_800728b0_cursor_seqID = _sequenceID;
 				if (ini->field_1a_flags_maybe & 0x800) {
-					data_80072890 = cursorOverIni;
+					_data_80072890 = cursorOverIni;
 					uint32 newSeqId = 1;
 					for (int idx=0; idx < 5; idx++) {
-						data_800728b0_cursor_seqID = idx;
+						_data_800728b0_cursor_seqID = idx;
 						byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
 						ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
@@ -265,14 +265,14 @@ int16 Cursor::updateIniFromScene() {
 
 					_sequenceID = newSeqId;
 					_iniUnderCursor = cursorOverIni;
-					data_80072890 = _iniUnderCursor;
-					data_800728b0_cursor_seqID = _sequenceID;
+					_data_80072890 = _iniUnderCursor;
+					_data_800728b0_cursor_seqID = _sequenceID;
 					return _iniUnderCursor;
 				}
 				if (_sequenceID != 0) {
 					_iniUnderCursor = cursorOverIni;
-					data_80072890 = data_80072890_orig;
-					data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
+					_data_80072890 = _data_80072890_orig;
+					_data_800728b0_cursor_seqID = _data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
 				byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
@@ -283,16 +283,16 @@ int16 Cursor::updateIniFromScene() {
 //				local_44 = local_44 + local_48;
 				if (executeScript(scriptOpCall, 0)) {
 					_iniUnderCursor = cursorOverIni;
-					data_80072890 = data_80072890_orig;
-					data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
+					_data_80072890 = _data_80072890_orig;
+					_data_800728b0_cursor_seqID = _data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
 			}
 		}
 	}
 	_iniUnderCursor = 0;
-	data_80072890 = data_80072890_orig;
-	data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
+	_data_80072890 = _data_80072890_orig;
+	_data_800728b0_cursor_seqID = _data_800728b0_cursor_seqID_orig;
 	return 0;
 }
 
@@ -304,7 +304,7 @@ int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 	_vm->_scriptOpcodes->_data_80071f5c = 0;
 	_vm->_scriptOpcodes->executeScriptLoop(scriptOpCall);
 
-	if (!(scriptOpCall._result & 1) && data_800728b0_cursor_seqID == 5 && unkFlag != 0) {
+	if (!(scriptOpCall._result & 1) && _data_800728b0_cursor_seqID == 5 && unkFlag != 0) {
 		_vm->_scriptOpcodes->_scriptTargetINI = -1;
 		scriptOpCall._code = codeStart;
 		scriptOpCall._field8 = 1;
@@ -333,7 +333,7 @@ void Cursor::selectPreviousCursor() {
 		_sequenceID = 1;
 	}
 	if (_sequenceID == -1) {
-		_sequenceID = iniItemInHand == 0 ? 4 : 5;
+		_sequenceID = _iniItemInHand == 0 ? 4 : 5;
 	}
 }
 
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index d88ac9fa00..53d4a689fd 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -34,15 +34,15 @@ class DragonINIResource;
 
 class Cursor {
 public:
-	int16 data_800728b0_cursor_seqID;
+	int16 _data_800728b0_cursor_seqID;
 	uint16 _iniUnderCursor;
 	int32 _sequenceID;
-	int16 data_80072890;
+	int16 _data_80072890;
 	int16 _x;
 	int16 _y;
 	int16 data_8007283c;
 	int16 _cursorActivationSeqOffset;
-	uint16 iniItemInHand;
+	uint16 _iniItemInHand;
 private:
 	DragonsEngine *_vm;
 	Actor *_actor;
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 93d50832b4..42cded37d5 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -49,7 +49,7 @@ void CutScene::scene1() {
 
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 
-	DAT_80063514 = 0xb00;
+	_actor_80063514 = 0xb00;
 	_vm->_dragonINIResource->setFlickerRecord(NULL);
 
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
@@ -60,7 +60,7 @@ void CutScene::scene1() {
 	_vm->_cursor->setActorFlag400();
 
 //	scr_tilemap1_w = 0x28;
-//	DAT_8006a3f0 = DAT_8006a3ec;
+//	_actor_8006a3f0 = _actor_8006a3ec;
 
 //	load_actor_file(0x81);
 //	load_actor_file(0x7d);
@@ -72,139 +72,139 @@ void CutScene::scene1() {
 	_vm->waitForFrames(0x5a);
 	closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 	//playSoundFromTxtIndex(0x4e26);
-	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x4e26,0x2e01) != 2) {
-		fadeScreenAndResetActor(DAT_80072de8);
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,4,0,0x4e26,0x2e01) != 2) {
+		fadeScreenAndResetActor(_actor_80072de8);
 		closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); // cut to flicker
 		//playSoundFromTxtIndex(0x4ea2);
-		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x4ea2,0x701) != 2) {
-			fadeScreenAndResetActor(DAT_80072de8);
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,2,0,0x4ea2,0x701) != 2) {
+			fadeScreenAndResetActor(_actor_80072de8);
 			closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 			//playSoundFromTxtIndex(0x4eec);
-			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x4eec,0x2e01) != 2) {
-				fadeScreenAndResetActor(DAT_80072de8);
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,5,0,0x4eec,0x2e01) != 2) {
+				fadeScreenAndResetActor(_actor_80072de8);
 				wideAngleEveryoneAtTable();  // shot of whole room
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5000,0x2e01) != 2 &&
-					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_800830c0,0x1d,0x1c,0x5074,0x501) != 2 &&
-					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,9,5,0x511c,0xc01) != 2 &&
-					_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_800830c0,0x1d,0x1c,0x5138,0x501) != 2) {
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x5000,0x2e01) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_800830c0,0x1d,0x1c,0x5074,0x501) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0,9,5,0x511c,0xc01) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_800830c0,0x1d,0x1c,0x5138,0x501) != 2) {
 					closeUpShotOnActor(0xd7, 0, 0x312, 0x260); //close up on flame
 					//playSoundFromTxtIndex(0x5152);
-					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x5152,0x3e01) != 2) {
-						fadeScreenAndResetActor(DAT_80072de8);
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,2,0,0x5152,0x3e01) != 2) {
+						fadeScreenAndResetActor(_actor_80072de8);
 						closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); //close up flicker
 						//playSoundFromTxtIndex(0x51fc);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x51fc,0x701) != 2) {
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,3,0,0x51fc,0x701) != 2) {
 							_vm->playOrStopSound(0x8004);
 							_vm->waitForFrames(0x28);
 							_vm->playOrStopSound(0x8003);
-							fadeScreenAndResetActor(DAT_80072de8);
-							DAT_80063514 = DAT_80063514 | 0x40;
+							fadeScreenAndResetActor(_actor_80072de8);
+							_actor_80063514 = _actor_80063514 | 0x40;
 							FUN_8003d8e8(0xd6,0,0x37a,0x280);
-							DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3); //load humans
-							DAT_80072df0 = _vm->_actorManager->loadActor(0xd3,2,0x87,199,3);
+							_actor_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3); //load humans
+							_actor_80072df0 = _vm->_actorManager->loadActor(0xd3,2,0x87,199,3);
 							_vm->waitForFramesAllowSkip(4);
 							// call_fade_related_1f();
 							if (FUN_8003dab8(0x52d6,0,0,0x701,1) != 2) {
 								// TODO callMaybeResetData();
 								//playSoundFromTxtIndex(0x530c);
-								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,2,0,0x530c,0x3c01) != 2) {
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,2,0,0x530c,0x3c01) != 2) {
 									while (0x10 < _vm->_scene->_camera.x) {
 										_vm->_scene->_camera.x = _vm->_scene->_camera.x + -0x10;
 										_vm->waitForFrames(1);
 									}
 									_vm->_scene->_camera.x = 0;
 									//playSoundFromTxtIndex(0x54dc);
-									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,6,2,0x54dc,0x2e01) != 2) {
-										fadeScreenAndResetActor(DAT_80072de8);
-										fadeScreenAndResetActor(DAT_80072dec);
-										fadeScreenAndResetActor(DAT_80072df0);
+									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0,6,2,0x54dc,0x2e01) != 2) {
+										fadeScreenAndResetActor(_actor_80072de8);
+										fadeScreenAndResetActor(_actor_80072dec);
+										fadeScreenAndResetActor(_actor_80072df0);
 										wideAngleEveryoneAtTable();
-										if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e08,3,2,0x55d4,0xc01) != 2) {
+										if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e08,3,2,0x55d4,0xc01) != 2) {
 											closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 											//playSoundFromTxtIndex(0x562c);
-											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x562c,0xc01) != 2) {
-												fadeScreenAndResetActor(DAT_80072de8);
+											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,2,0,0x562c,0xc01) != 2) {
+												fadeScreenAndResetActor(_actor_80072de8);
 												FUN_8003d8e8(0xd6,0,0x37a,0x280);
-												DAT_80072dec = _vm->_actorManager->loadActor(0xd5,4,0x2d6,0xc6,3);
+												_actor_80072dec = _vm->_actorManager->loadActor(0xd5,4,0x2d6,0xc6,3);
 												_vm->waitForFramesAllowSkip(4);
 												// call_fade_related_1f();
 												if (FUN_8003dab8(0x5780,0x14,0,0xc01,1) != 2) {
-													DAT_80063514 = DAT_80063514 | 0x40;
-													fadeScreenAndResetActor(DAT_80072de8);
-													fadeScreenAndResetActor(DAT_80072dec);
+													_actor_80063514 = _actor_80063514 | 0x40;
+													fadeScreenAndResetActor(_actor_80072de8);
+													fadeScreenAndResetActor(_actor_80072dec);
 													closeUpShotOnActor(0xd7, 0, 0x312, 0x260); // close up flame
 													//playSoundFromTxtIndex(0x581c);
-													if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x581c,0x3e01) != 2) {
-														fadeScreenAndResetActor(DAT_80072de8);
+													if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,3,0,0x581c,0x3e01) != 2) {
+														fadeScreenAndResetActor(_actor_80072de8);
 														closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 														//playSoundFromTxtIndex(0x5942);
-														if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x5942,0xc01) != 2) {
-															fadeScreenAndResetActor(DAT_80072de8);
+														if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,4,0,0x5942,0xc01) != 2) {
+															fadeScreenAndResetActor(_actor_80072de8);
 															closeUpShotOnActor(0xd3, 2, 0x87, 0); // close up king
 															//playSoundFromTxtIndex(0x5aaa);
-															if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,7,2,0x5aaa,0x2e01) != 2) {
-																fadeScreenAndResetActor(DAT_80072de8);
+															if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,7,2,0x5aaa,0x2e01) != 2) {
+																fadeScreenAndResetActor(_actor_80072de8);
 																FUN_8003d8e8(0xd6,0,0x37a,0x280);
-																DAT_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3);
+																_actor_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3);
 																_vm->waitForFramesAllowSkip(4);
 																// call_fade_related_1f();
 																//playSoundFromTxtIndex(0x5afc);
-																if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,3,0,0x5afc,0x3c01) != 2) {
-																	fadeScreenAndResetActor(DAT_80072de8);
-																	fadeScreenAndResetActor(DAT_80072dec);
-																	DAT_80063514 = DAT_80063514 & 0xffbf;
+																if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,3,0,0x5afc,0x3c01) != 2) {
+																	fadeScreenAndResetActor(_actor_80072de8);
+																	fadeScreenAndResetActor(_actor_80072dec);
+																	_actor_80063514 = _actor_80063514 & 0xffbf;
 																	closeUpKnightsAtTable(); // close up of knights at table.
 																	_vm->playOrStopSound(0x8003);
 																	//playSoundFromTxtIndex(0x5b96);
-																	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,8,4,0x5b96,0xc01) != 2) {
+																	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,8,4,0x5b96,0xc01) != 2) {
 																		//playSoundFromTxtIndex(0x5c4a);
-																		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,2,0,0x5c4a,0x2e01) != 2) {
+																		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,2,0,0x5c4a,0x2e01) != 2) {
 																			//playSoundFromTxtIndex(0x5dc8);
-																			DAT_80072df0->updateSequence(0xf);
-																			DAT_80072df4->updateSequence(0xd);
-																			DAT_80072df8->updateSequence(0xe);
-																			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0xc,4,0x5dc8,0xc01) != 2) {
-																				DAT_80072df0->updateSequence(6);
-																				DAT_80072df4->updateSequence(0);
-																				DAT_80072df8->updateSequence(2);
+																			_actor_80072df0->updateSequence(0xf);
+																			_actor_80072df4->updateSequence(0xd);
+																			_actor_80072df8->updateSequence(0xe);
+																			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,0xc,4,0x5dc8,0xc01) != 2) {
+																				_actor_80072df0->updateSequence(6);
+																				_actor_80072df4->updateSequence(0);
+																				_actor_80072df8->updateSequence(2);
 																				FUN_8003d8e8(0xd3,2,0x28d,0x250);
-																				DAT_80072dec = _vm->_actorManager->loadActor(0xd7,0,0x348,199,3);
+																				_actor_80072dec = _vm->_actorManager->loadActor(0xd7,0,0x348,199,3);
 																				_vm->waitForFramesAllowSkip(4); // close up of king and flame
 																				//call_fade_related_1f();
 																				//playSoundFromTxtIndex(0x5ef2);
-																				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x5ef2,0x3e01) != 2) {
-																					fadeScreenAndResetActor(DAT_80072de8);
-																					fadeScreenAndResetActor(DAT_80072dec);
+																				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x5ef2,0x3e01) != 2) {
+																					fadeScreenAndResetActor(_actor_80072de8);
+																					fadeScreenAndResetActor(_actor_80072dec);
 																					closeUpShotOnActor(0xd3, 0, 0x233,
 																									   0x17a); // close up of king
 																					//playSoundFromTxtIndex(0x6000);
-																					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,8,0,0x6000,0x2e01) != 2) {
-																						fadeScreenAndResetActor(DAT_80072de8);
+																					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,8,0,0x6000,0x2e01) != 2) {
+																						fadeScreenAndResetActor(_actor_80072de8);
 																						closeUpKnightsAtTable(); // close up knights at table
 																						//playSoundFromTxtIndex(0x7dcc);
-																						DAT_80072df0->updateSequence(0x13);
-																						DAT_80072df4->updateSequence(0x10);
-																						DAT_80072df8->updateSequence(0x11);
-																						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
+																						_actor_80072df0->updateSequence(0x13);
+																						_actor_80072df4->updateSequence(0x10);
+																						_actor_80072df8->updateSequence(0x11);
+																						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
 																							wideAngleEveryoneAtTable(); //whole room shot
-																							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x60ee,0x701) != 2) {
+																							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0x17,0x16,0x60ee,0x701) != 2) {
 																								closeUpKnightsAtTable();
-																								DAT_80072df0->updateSequence(6);
-																								DAT_80072df4->updateSequence(0);
-																								DAT_80072df8->updateSequence(2);
-																								DAT_80072dec->updateSequence(4);
+																								_actor_80072df0->updateSequence(6);
+																								_actor_80072df4->updateSequence(0);
+																								_actor_80072df8->updateSequence(2);
+																								_actor_80072dec->updateSequence(4);
 																								//playSoundFromTxtIndex(0x5de8);
-																								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df8,0xb,2,0x5de8,0xc01) != 2) {
+																								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df8,0xb,2,0x5de8,0xc01) != 2) {
 																									wideAngleEveryoneAtTable();
 																									_vm->playOrStopSound(1);
-																									DAT_80072df0->updateSequence(8);
-																									DAT_80072df4->updateSequence(0xd);
-																									DAT_80072df8->updateSequence(0x11);
-																									DAT_80072dfc->updateSequence(0x15);
-																									DAT_80072df0->waitUntilFlag8And4AreSet();
-																									DAT_80072df4->waitUntilFlag8And4AreSet();
-																									DAT_80072df8->waitUntilFlag8And4AreSet();
-																									DAT_80072dfc->waitUntilFlag8And4AreSet();
+																									_actor_80072df0->updateSequence(8);
+																									_actor_80072df4->updateSequence(0xd);
+																									_actor_80072df8->updateSequence(0x11);
+																									_actor_80072dfc->updateSequence(0x15);
+																									_actor_80072df0->waitUntilFlag8And4AreSet();
+																									_actor_80072df4->waitUntilFlag8And4AreSet();
+																									_actor_80072df8->waitUntilFlag8And4AreSet();
+																									_actor_80072dfc->waitUntilFlag8And4AreSet();
 																									// DisableVSyncEvent();
 																									// TODO load_actor_file(0x82);
 																									// EnableVSyncEvent();
@@ -220,70 +220,70 @@ void CutScene::scene1() {
 																									changeBackgroundPosition(
 																											2, 0);
 																									_vm->_actorManager->clearActorFlags(2);
-																									DAT_80072de8 = _vm->_actorManager->loadActor(0x82,0,0x60,0x114,1);
-																									DAT_80072dec = _vm->_actorManager->loadActor(0x82,2,0x91,0x113,1);
-																									DAT_80072df0 = _vm->_actorManager->loadActor(0x82,1,0xd0,199,1);
-																									DAT_80072df4 = _vm->_actorManager->loadActor(0x82,3,0xb6,0x113,1);
-																									DAT_80072de8 = _vm->_actorManager->loadActor(0x82,4,0x98,0x40,1);
-
-																									DAT_80072de8->setFlag(ACTOR_FLAG_100);
-																									DAT_80072de8->setFlag(ACTOR_FLAG_800);
-																									DAT_80072de8->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072de8->_walkSpeed = 0x20000;
-																									DAT_80072de8->_priorityLayer = 3;
-
-																									DAT_80072dec->setFlag(ACTOR_FLAG_100);
-																									DAT_80072dec->setFlag(ACTOR_FLAG_800);
-																									DAT_80072dec->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072dec->_walkSpeed = 0x18000;
-																									DAT_80072dec->_priorityLayer = 3;
-
-																									DAT_80072df0->setFlag(ACTOR_FLAG_100);
-																									DAT_80072df0->setFlag(ACTOR_FLAG_800);
-																									DAT_80072df0->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072df0->_walkSpeed = 0x14000;
-																									DAT_80072df0->_priorityLayer = 3;
-
-																									DAT_80072df4->setFlag(ACTOR_FLAG_100);
-																									DAT_80072df4->setFlag(ACTOR_FLAG_800);
-																									DAT_80072df4->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072df4->_walkSpeed = 0x1c000;
-																									DAT_80072df4->_priorityLayer = 3;
-
-																									DAT_80072df8->setFlag(ACTOR_FLAG_100);
-																									DAT_80072df8->setFlag(ACTOR_FLAG_800);
-																									DAT_80072df8->setFlag(ACTOR_FLAG_8000);
-																									DAT_80072df8->_priorityLayer = 3;
+																									_actor_80072de8 = _vm->_actorManager->loadActor(0x82,0,0x60,0x114,1);
+																									_actor_80072dec = _vm->_actorManager->loadActor(0x82,2,0x91,0x113,1);
+																									_actor_80072df0 = _vm->_actorManager->loadActor(0x82,1,0xd0,199,1);
+																									_actor_80072df4 = _vm->_actorManager->loadActor(0x82,3,0xb6,0x113,1);
+																									_actor_80072de8 = _vm->_actorManager->loadActor(0x82,4,0x98,0x40,1);
+
+																									_actor_80072de8->setFlag(ACTOR_FLAG_100);
+																									_actor_80072de8->setFlag(ACTOR_FLAG_800);
+																									_actor_80072de8->setFlag(ACTOR_FLAG_8000);
+																									_actor_80072de8->_walkSpeed = 0x20000;
+																									_actor_80072de8->_priorityLayer = 3;
+
+																									_actor_80072dec->setFlag(ACTOR_FLAG_100);
+																									_actor_80072dec->setFlag(ACTOR_FLAG_800);
+																									_actor_80072dec->setFlag(ACTOR_FLAG_8000);
+																									_actor_80072dec->_walkSpeed = 0x18000;
+																									_actor_80072dec->_priorityLayer = 3;
+
+																									_actor_80072df0->setFlag(ACTOR_FLAG_100);
+																									_actor_80072df0->setFlag(ACTOR_FLAG_800);
+																									_actor_80072df0->setFlag(ACTOR_FLAG_8000);
+																									_actor_80072df0->_walkSpeed = 0x14000;
+																									_actor_80072df0->_priorityLayer = 3;
+
+																									_actor_80072df4->setFlag(ACTOR_FLAG_100);
+																									_actor_80072df4->setFlag(ACTOR_FLAG_800);
+																									_actor_80072df4->setFlag(ACTOR_FLAG_8000);
+																									_actor_80072df4->_walkSpeed = 0x1c000;
+																									_actor_80072df4->_priorityLayer = 3;
+
+																									_actor_80072df8->setFlag(ACTOR_FLAG_100);
+																									_actor_80072df8->setFlag(ACTOR_FLAG_800);
+																									_actor_80072df8->setFlag(ACTOR_FLAG_8000);
+																									_actor_80072df8->_priorityLayer = 3;
 
 																									_vm->waitForFramesAllowSkip(0xe);
 																									// call_fade_related_1f();
-																									DAT_80072df0->startWalk(0xe8,0xa8,2);
-																									while (DAT_80072df0->isFlagSet(ACTOR_FLAG_10)) {
+																									_actor_80072df0->startWalk(0xe8,0xa8,2);
+																									while (_actor_80072df0->isFlagSet(ACTOR_FLAG_10)) {
 																										_vm->waitForFrames(1);
 																									}
-																									DAT_80072de8->startWalk(0x97,0x37,2);
-																									DAT_80072dec->startWalk(0x97,0x37,2);
-																									DAT_80072df4->startWalk(0x97,0x37,2);
-																									DAT_80072df0->waitUntilFlag8SetThenSet1000AndWaitFor4();
-																									DAT_80072df0->updateSequence(6);
+																									_actor_80072de8->startWalk(0x97,0x37,2);
+																									_actor_80072dec->startWalk(0x97,0x37,2);
+																									_actor_80072df4->startWalk(0x97,0x37,2);
+																									_actor_80072df0->waitUntilFlag8SetThenSet1000AndWaitFor4();
+																									_actor_80072df0->updateSequence(6);
 																									uint16 dialog[2000];
 																									dialog[0] = 0;
 																									_vm->_talk->loadText(0x5ea2, dialog, 2000);
 
 																									_vm->_talk->displayDialogAroundPoint(dialog,0x27,0xc,0xc01,0,0x5ea2);
-																									DAT_80072df0->waitUntilFlag8And4AreSet();
-																									DAT_80072df0->_x_pos = 0xcf;
-																									DAT_80072df0->_y_pos = 0x90;
-																									DAT_80072df0->startWalk(0x97, 0x37, 2);
-																									DAT_80072df0->updateSequence(7);
+																									_actor_80072df0->waitUntilFlag8And4AreSet();
+																									_actor_80072df0->_x_pos = 0xcf;
+																									_actor_80072df0->_y_pos = 0x90;
+																									_actor_80072df0->startWalk(0x97, 0x37, 2);
+																									_actor_80072df0->updateSequence(7);
 //TODO
-//																									if (((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0))
-//																										|| ((DAT_8008e844 != 0 || (DAT_8008e874 != 0)))
+//																									if (((_actor_8008e7e8 != 0) || (_actor_8008e848 != 0))
+//																										|| ((_actor_8008e844 != 0 || (_actor_8008e874 != 0)))
 //																											) {
-//																										FUN_8001a7c4((uint)DAT_8008e7e8,
-//																													 (uint)DAT_8008e844,
-//																													 (uint)DAT_8008e848,
-//																													 (uint)DAT_8008e874);
+//																										FUN_8001a7c4((uint)_actor_8008e7e8,
+//																													 (uint)_actor_8008e844,
+//																													 (uint)_actor_8008e848,
+//																													 (uint)_actor_8008e874);
 //																									}
 
 																									dialog[0] = 0;
@@ -351,7 +351,7 @@ void CutScene::FUN_8003d8e8(uint16 resourceId, uint16 sequenceId, int16 x, uint3
 	// fade_related_calls_with_1f();
 	_vm->_actorManager->clearActorFlags(2);
 	//DisableVSyncEvent();
-	DAT_80072de8 = _vm->_actorManager->loadActor(resourceId, sequenceId, x, 199, 3);
+	_actor_80072de8 = _vm->_actorManager->loadActor(resourceId, sequenceId, x, 199, 3);
 	//EnableVSyncEvent();
 	changeBackgroundPosition(3, param_4);
 
@@ -368,54 +368,54 @@ void CutScene::FUN_8003d388() {
 
 	// fade_related_calls_with_1f();
 	_vm->_actorManager->clearActorFlags(2);
-	if ((DAT_80063514 & 0x80) == 0) {
-		DAT_80072de8 = _vm->_actorManager->loadActor(0x7e,0x16,0x40,0xa0,1);
+	if ((_actor_80063514 & 0x80) == 0) {
+		_actor_80072de8 = _vm->_actorManager->loadActor(0x7e,0x16,0x40,0xa0,1);
 	}
-	DAT_80072dec = _vm->_actorManager->loadActor(0x7e,0,0xbf,0xba,1);
-	if ((DAT_80063514 & 8) == 0) {
-		DAT_80072df0 = _vm->_actorManager->loadActor(0x7e,5,0x94,0x82,1);
+	_actor_80072dec = _vm->_actorManager->loadActor(0x7e,0,0xbf,0xba,1);
+	if ((_actor_80063514 & 8) == 0) {
+		_actor_80072df0 = _vm->_actorManager->loadActor(0x7e,5,0x94,0x82,1);
 	}
-	if ((DAT_80063514 & 0x10) == 0) {
-		DAT_80072df4 = _vm->_actorManager->loadActor(0x7e,10,0x6f,0x95,1);
+	if ((_actor_80063514 & 0x10) == 0) {
+		_actor_80072df4 = _vm->_actorManager->loadActor(0x7e,10,0x6f,0x95,1);
 	}
-	if ((DAT_80063514 & 4) == 0) {
-		DAT_80072df8 = _vm->_actorManager->loadActor(0x7e,0xe,0xa9,0x87,1);
+	if ((_actor_80063514 & 4) == 0) {
+		_actor_80072df8 = _vm->_actorManager->loadActor(0x7e,0xe,0xa9,0x87,1);
 	}
-	if ((DAT_80063514 & 0x20) == 0) {
-		DAT_80072dfc = _vm->_actorManager->loadActor(0x7e,0x12,0xcd,0x8e,1);
+	if ((_actor_80063514 & 0x20) == 0) {
+		_actor_80072dfc = _vm->_actorManager->loadActor(0x7e,0x12,0xcd,0x8e,1);
 	}
-	if ((DAT_80063514 & 1) == 0) {
-		DAT_80072e04 = _vm->_actorManager->loadActor(0x7e,0x19,0x10e,0x89,1);
+	if ((_actor_80063514 & 1) == 0) {
+		_actor_80072e04 = _vm->_actorManager->loadActor(0x7e,0x19,0x10e,0x89,1);
 	}
-	if ((DAT_80063514 & 2) == 0) {
-		DAT_80072e08 = _vm->_actorManager->loadActor(0x8f,2,100,0xbc,1);
+	if ((_actor_80063514 & 2) == 0) {
+		_actor_80072e08 = _vm->_actorManager->loadActor(0x8f,2,100,0xbc,1);
 	}
-	if ((DAT_80063514 & 0x40) != 0) {
-		DAT_80072e0c = _vm->_actorManager->loadActor(0x8f,0,0xd2,100,1);
-		DAT_800830a0 = _vm->_actorManager->loadActor(0x8f,1,0xe6,0x6e,1);
+	if ((_actor_80063514 & 0x40) != 0) {
+		_actor_80072e0c = _vm->_actorManager->loadActor(0x8f,0,0xd2,100,1);
+		_actor_800830a0 = _vm->_actorManager->loadActor(0x8f,1,0xe6,0x6e,1);
 	}
-	DAT_800830b8 = _vm->_actorManager->loadActor(0xaa,0,0x2e,0x2d,1);
-	DAT_800830b8->setFlag(ACTOR_FLAG_8000);
-	DAT_800830bc = _vm->_actorManager->loadActor(0xaa,1,0x115,0x22,1);
-	DAT_800830bc->setFlag(ACTOR_FLAG_100);
-	DAT_800830bc->setFlag(ACTOR_FLAG_8000);
-	DAT_800830bc->_priorityLayer = 4;
-	if ((DAT_80063514 & 0x100) != 0) {
-		DAT_800830c0 = _vm->_actorManager->loadActor(0x7e,0x1c,0x21,0x87,1);
+	_actor_800830b8 = _vm->_actorManager->loadActor(0xaa,0,0x2e,0x2d,1);
+	_actor_800830b8->setFlag(ACTOR_FLAG_8000);
+	_actor_800830bc = _vm->_actorManager->loadActor(0xaa,1,0x115,0x22,1);
+	_actor_800830bc->setFlag(ACTOR_FLAG_100);
+	_actor_800830bc->setFlag(ACTOR_FLAG_8000);
+	_actor_800830bc->_priorityLayer = 4;
+	if ((_actor_80063514 & 0x100) != 0) {
+		_actor_800830c0 = _vm->_actorManager->loadActor(0x7e,0x1c,0x21,0x87,1);
 	}
-	if ((DAT_80063514 & 0x200) != 0) {
-		if ((DAT_80063514 & 0x800) == 0) {
+	if ((_actor_80063514 & 0x200) != 0) {
+		if ((_actor_80063514 & 0x800) == 0) {
 			sequenceId = 2;
 		}
 		else {
 			sequenceId = 4;
 		}
-		DAT_800830d4 = _vm->_actorManager->loadActor(0xaa,sequenceId,0xf4,199,1);
-		DAT_800830d4->setFlag(ACTOR_FLAG_8000);
+		_actor_800830d4 = _vm->_actorManager->loadActor(0xaa,sequenceId,0xf4,199,1);
+		_actor_800830d4->setFlag(ACTOR_FLAG_8000);
 	}
-	if ((DAT_80063514 & 0x400) != 0) {
-		DAT_800830dc = _vm->_actorManager->loadActor(0xaa,3,0xf4,199,1);
-		DAT_800830dc->setFlag(ACTOR_FLAG_8000);
+	if ((_actor_80063514 & 0x400) != 0) {
+		_actor_800830dc = _vm->_actorManager->loadActor(0xaa,3,0xf4,199,1);
+		_actor_800830dc->setFlag(ACTOR_FLAG_8000);
 	}
 	changeBackgroundPosition(0, 0);
 	_vm->waitForFramesAllowSkip(0xe);
@@ -425,11 +425,11 @@ void CutScene::FUN_8003d388() {
 void CutScene::closeUpKnightsAtTable() {
 	//fade_related_calls_with_1f();
 	_vm->_actorManager->clearActorFlags(2);
-	DAT_80072de8 = _vm->_actorManager->loadActor(0x7d,0,2,199,1);
-	DAT_80072dec = _vm->_actorManager->loadActor(0x81,4,2,199,1);
-	DAT_80072df0 = _vm->_actorManager->loadActor(0x81,6,2,199,1);
-	DAT_80072df4 = _vm->_actorManager->loadActor(0x81,0,2,199,1);
-	DAT_80072df8 = _vm->_actorManager->loadActor(0x81,2,2,199,1);
+	_actor_80072de8 = _vm->_actorManager->loadActor(0x7d,0,2,199,1);
+	_actor_80072dec = _vm->_actorManager->loadActor(0x81,4,2,199,1);
+	_actor_80072df0 = _vm->_actorManager->loadActor(0x81,6,2,199,1);
+	_actor_80072df4 = _vm->_actorManager->loadActor(0x81,0,2,199,1);
+	_actor_80072df8 = _vm->_actorManager->loadActor(0x81,2,2,199,1);
 	changeBackgroundPosition(1, 0);
 	_vm->waitForFrames(0xf);
 	//call_fade_related_1f();
@@ -558,7 +558,7 @@ void CutScene::knightsSavedBackAtCastle() {
 	bool isFlag0x10Set;
 
 	uVar1 = _vm->_dragonINIResource->getFlickerRecord();
-	DAT_80063514 = 0xa00;
+	_actor_80063514 = 0xa00;
 	_vm->_dragonINIResource->setFlickerRecord(NULL);
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 	isFlag0x10Set = _vm->isFlagSet(ENGINE_FLAG_10);
@@ -568,7 +568,7 @@ void CutScene::knightsSavedBackAtCastle() {
 	_vm->_cursor->setActorFlag400();
 
 //	scr_tilemap1_w = 0x28;
-//	DAT_8006a3f0 = DAT_8006a3ec;
+//	_actor_8006a3f0 = _actor_8006a3ec;
 //	load_actor_file(0x81);
 //	load_actor_file(0x7d);
 //	load_actor_file(0x7e);
@@ -578,53 +578,53 @@ void CutScene::knightsSavedBackAtCastle() {
 	_vm->setFlags(ENGINE_FLAG_20000);
 	closeUpKnightsAtTable();
 //	playSoundFromTxtIndex(0x7854);
-	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,10,4,0x7854,0xc01) != 2) {
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,10,4,0x7854,0xc01) != 2) {
 		closeUpShotOnActor(0xd8,0,0xfd,0x60);
 //		playSoundFromTxtIndex(0x78c6);
-		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x78c6,0x701) != 2) {
-			fadeScreenAndResetActor(DAT_80072de8);
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,4,0,0x78c6,0x701) != 2) {
+			fadeScreenAndResetActor(_actor_80072de8);
 			closeUpKnightsAtTable();
 //			playSoundFromTxtIndex(0x78e8);
-			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,3,0,0x78e8,0x2e01) != 2) {
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,3,0,0x78e8,0x2e01) != 2) {
 				wideAngleEveryoneAtTable();
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e04,0x1a,0x19,0x7a1e,0x3e01) != 2) {
-					DAT_80072e04->_walkSpeed = 0x10000;
-					DAT_80072e04->setFlag(ACTOR_FLAG_800);
-					DAT_80072e04->updateSequence(0x21);
-					DAT_80072e04->startWalk(0x13f,0x6e,2);
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e04,0x1a,0x19,0x7a1e,0x3e01) != 2) {
+					_actor_80072e04->_walkSpeed = 0x10000;
+					_actor_80072e04->setFlag(ACTOR_FLAG_800);
+					_actor_80072e04->updateSequence(0x21);
+					_actor_80072e04->startWalk(0x13f,0x6e,2);
 					// wait for pathfinding to complete
-					while (DAT_80072e04->isFlagSet(ACTOR_FLAG_10)) { //TODO move to method on Actor waitForPathfinding() ??
+					while (_actor_80072e04->isFlagSet(ACTOR_FLAG_10)) { //TODO move to method on Actor waitForPathfinding() ??
 						//empty
 					}
-					DAT_80063514 = DAT_80063514 | 1;
+					_actor_80063514 = _actor_80063514 | 1;
 					closeUpShotOnActor(0xd3,0,0x233,0x17a);
 //					playSoundFromTxtIndex(0x7aba);
-					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,9,0,0x7aba,0x2e01) != 2) {
-						fadeScreenAndResetActor(DAT_80072de8);
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,9,0,0x7aba,0x2e01) != 2) {
+						fadeScreenAndResetActor(_actor_80072de8);
 						closeUpShotOnActor(0xd8,0,0xfd,0x60);
 //						playSoundFromTxtIndex(0x7b60);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x7b60,0x701) != 2) {
-							fadeScreenAndResetActor(DAT_80072de8);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,5,0,0x7b60,0x701) != 2) {
+							fadeScreenAndResetActor(_actor_80072de8);
 							wideAngleEveryoneAtTable();
-							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072df0,9,5,0x7c20,0xc01) != 2) {
-								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x7c9c,0x701) != 2) {
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0,9,5,0x7c20,0xc01) != 2) {
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0x17,0x16,0x7c9c,0x701) != 2) {
 									_vm->playOrStopSound(0x800f);
 									_vm->waitForFrames(10);
-									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x7cf2,0x701) != 2) {
+									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0x17,0x16,0x7cf2,0x701) != 2) {
 										closeUpKnightsAtTable();
 //										playSoundFromTxtIndex(0x7dcc);
-										DAT_80072df0->updateSequence(0x13);
-										DAT_80072df4->updateSequence(0x10);
-										DAT_80072df8->updateSequence(0x11);
-										actorId = _vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0x12,6,0x7dcc,0xc01);
+										_actor_80072df0->updateSequence(0x13);
+										_actor_80072df4->updateSequence(0x10);
+										_actor_80072df8->updateSequence(0x11);
+										actorId = _vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,0x12,6,0x7dcc,0xc01);
 										if ((actorId & 0xffff) != 2) {
 											closeUpShotOnActor(0xd3,0,0x233,0x17a);
 //											playSoundFromTxtIndex(0x7e1a);
-											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,10,0,0x7e1a,0x2e01) != 2) {
-												fadeScreenAndResetActor(DAT_80072de8);
+											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,10,0,0x7e1a,0x2e01) != 2) {
+												fadeScreenAndResetActor(_actor_80072de8);
 												wideAngleEveryoneAtTable();
-												if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x7e96,0x2e01) != 2) {
-													_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0x17,0x16,0x7f0a,0x701);
+												if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x7e96,0x2e01) != 2) {
+													_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0x17,0x16,0x7f0a,0x701);
 												}
 											}
 										}
@@ -666,7 +666,7 @@ void CutScene::flameReturnsCutScene() {
 	uint engineFlag10Set;
 
 	uVar1 = _vm->_dragonINIResource->getFlickerRecord();
-	DAT_80063514 = 0x3f;
+	_actor_80063514 = 0x3f;
 	_vm->_dragonINIResource->setFlickerRecord(NULL);
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 	engineFlag10Set = _vm->isFlagSet(ENGINE_FLAG_10);
@@ -675,50 +675,50 @@ void CutScene::flameReturnsCutScene() {
 	_vm->_cursor->setActorFlag400();
 	_vm->_inventory->setActorFlag400();
 //	scr_tilemap1_w = 0x28;
-//	DAT_8006a3f0 = DAT_8006a3ec;
+//	_actor_8006a3f0 = _actor_8006a3ec;
 //	load_actor_file(0x81);
 //	load_actor_file(0x7d);
 //	load_actor_file(0x7e);
 //	load_actor_file(0x8f);
 //	load_actor_file(0xaa);
-	DAT_80063514 = (DAT_80063514 & 0xfffe) | 0x600;
+	_actor_80063514 = (_actor_80063514 & 0xfffe) | 0x600;
 	FUN_8003d388();
-	DAT_80072de8->updateSequence(0x1f);
-	DAT_80072e04->_x_pos = 0x10b;
-	DAT_80072e04->_y_pos = 99;
-	DAT_80072de8->_x_pos = 0x10a;
-	DAT_80072de8->_y_pos = 0x5a;
-	DAT_80072de8->_walkSpeed = 0x10000;
-	DAT_80072e04->_walkSpeed = 0x10000;
-	DAT_80072de8->setFlag(ACTOR_FLAG_800);
-	DAT_80072e04->setFlag(ACTOR_FLAG_800);
+	_actor_80072de8->updateSequence(0x1f);
+	_actor_80072e04->_x_pos = 0x10b;
+	_actor_80072e04->_y_pos = 99;
+	_actor_80072de8->_x_pos = 0x10a;
+	_actor_80072de8->_y_pos = 0x5a;
+	_actor_80072de8->_walkSpeed = 0x10000;
+	_actor_80072e04->_walkSpeed = 0x10000;
+	_actor_80072de8->setFlag(ACTOR_FLAG_800);
+	_actor_80072e04->setFlag(ACTOR_FLAG_800);
 	//	call_fade_related_1f();
 	_vm->setFlags(ENGINE_FLAG_20000);
-	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x8ab2,0x2e01) != 2) {
-		DAT_80072de8->updateSequence(0x1e);
-		DAT_80072de8->startWalk(0xb0,0x6b,2);
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x8ab2,0x2e01) != 2) {
+		_actor_80072de8->updateSequence(0x1e);
+		_actor_80072de8->startWalk(0xb0,0x6b,2);
 		do {
-		} while (DAT_80072de8->isFlagSet(ACTOR_FLAG_10));
-		DAT_80072de8->updateSequence(0x1f);
-		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x8b40,0x2e01) != 2) {
-			DAT_80072e04->updateSequence(0x1b);
-			DAT_80072e04->startWalk(0xd5,0x6b,2);
+		} while (_actor_80072de8->isFlagSet(ACTOR_FLAG_10));
+		_actor_80072de8->updateSequence(0x1f);
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x8b40,0x2e01) != 2) {
+			_actor_80072e04->updateSequence(0x1b);
+			_actor_80072e04->startWalk(0xd5,0x6b,2);
 			do {
-			} while (DAT_80072e04->isFlagSet(ACTOR_FLAG_10));
-			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072e04,0x1a,0x19,0x8bb6,0x3e01) != 2) {
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,4,0,0x8bd8,0x2e01) != 2) {
+			} while (_actor_80072e04->isFlagSet(ACTOR_FLAG_10));
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e04,0x1a,0x19,0x8bb6,0x3e01) != 2) {
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x8bd8,0x2e01) != 2) {
 					closeUpShotOnActor(0xd8,0,0xfd,0x60);
 //					playSoundFromTxtIndex(0x8c70);
-					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,7,0,0x8c70,0x701) != 2) {
-						fadeScreenAndResetActor(DAT_80072de8);
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,7,0,0x8c70,0x701) != 2) {
+						fadeScreenAndResetActor(_actor_80072de8);
 						closeUpShotOnActor(0xd3,0,0x233,0x17a);
 //						playSoundFromTxtIndex(0x8cd2);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0xc,0,0x8cd2,0x2e01) != 2) {
-							fadeScreenAndResetActor(DAT_80072de8);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0xc,0,0x8cd2,0x2e01) != 2) {
+							fadeScreenAndResetActor(_actor_80072de8);
 							closeUpShotOnActor(0xd7,0,0x312,0x260);
 //							playSoundFromTxtIndex(0x8e1e);
-							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,5,0,0x8e1e,0x3e01) != 2) {
-								fadeScreenAndResetActor(DAT_80072de8);
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,5,0,0x8e1e,0x3e01) != 2) {
+								fadeScreenAndResetActor(_actor_80072de8);
 							}
 						}
 					}
@@ -744,7 +744,7 @@ void CutScene::knightsSavedAgain() {
 	bool engineFlag10Set;
 
 	flicker = _vm->_dragonINIResource->getFlickerRecord();
-	DAT_80063514 = 0;
+	_actor_80063514 = 0;
 	_vm->_dragonINIResource->setFlickerRecord(NULL);
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2);
 	engineFlag10Set = _vm->isFlagSet(ENGINE_FLAG_10);
@@ -755,7 +755,7 @@ void CutScene::knightsSavedAgain() {
 	_vm->_inventory->setActorFlag400();
 
 //	scr_tilemap1_w = 0x28;
-//TODO what is this?	DAT_8006a3f0 = DAT_8006a3ec;
+//TODO what is this?	_actor_8006a3f0 = _actor_8006a3ec;
 
 //	load_actor_file(0x81);
 //	load_actor_file(0x7d);
@@ -767,36 +767,36 @@ void CutScene::knightsSavedAgain() {
 	_vm->waitForFramesAllowSkip(0x3b);
 	closeUpShotOnActor(0xd3,0,0x233,0x17a);
 	//playSoundFromTxtIndex(0x9000);
-	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0xd,0,0x9000,0x2e01) != 2) {
-		fadeScreenAndResetActor(DAT_80072de8);
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0xd,0,0x9000,0x2e01) != 2) {
+		fadeScreenAndResetActor(_actor_80072de8);
 		closeUpKnightsAtTable();
 //		playSoundFromTxtIndex(0x90de);
-		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,4,0,0x90de,0x2e01) != 2) {
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,4,0,0x90de,0x2e01) != 2) {
 			closeUpShotOnActor(0xd8,0,0xfd,0x60);
 //			playSoundFromTxtIndex(0x921c);
-			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,8,0,0x921c,0x701) != 2) {
-				fadeScreenAndResetActor(DAT_80072de8);
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,8,0,0x921c,0x701) != 2) {
+				fadeScreenAndResetActor(_actor_80072de8);
 				closeUpKnightsAtTable();
 //				playSoundFromTxtIndex(0x92aa);
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,9,4,0x92aa,0xc01) != 2) {
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,9,4,0x92aa,0xc01) != 2) {
 					closeUpShotOnActor(0xd7,0,0x312,0x260);
 //					playSoundFromTxtIndex(0x932c);
-					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,6,0,0x932c,0x3e01) != 2) {
-						fadeScreenAndResetActor(DAT_80072de8);
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,6,0,0x932c,0x3e01) != 2) {
+						fadeScreenAndResetActor(_actor_80072de8);
 						closeUpShotOnActor(0xd3,2,0x87,0);
 //						playSoundFromTxtIndex(0x93d6);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,0xe,2,0x93d6,0x2e01) != 2) {
-							fadeScreenAndResetActor(DAT_80072de8);
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0xe,2,0x93d6,0x2e01) != 2) {
+							fadeScreenAndResetActor(_actor_80072de8);
 							closeUpKnightsAtTable();
 //							playSoundFromTxtIndex(0x7dcc);
-							DAT_80072df0->updateSequence(0x13);
-							DAT_80072df4->updateSequence(0x10);
-							DAT_80072df8->updateSequence(0x11);
-							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
+							_actor_80072df0->updateSequence(0x13);
+							_actor_80072df4->updateSequence(0x10);
+							_actor_80072df8->updateSequence(0x11);
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
 								closeUpShotOnActor(0xd8,0,0xfd,0x60);
 //								playSoundFromTxtIndex(0x948c);
-								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(DAT_80072de8,9,0,0x948c,0x701) != 2) {
-									fadeScreenAndResetActor(DAT_80072de8);
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,9,0,0x948c,0x701) != 2) {
+									fadeScreenAndResetActor(_actor_80072de8);
 									_vm->waitForFramesAllowSkip(0x3b);
 								}
 							}
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index 3189fd97af..c3658af24d 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -33,23 +33,23 @@ class CutScene {
 private:
 	DragonsEngine *_vm;
 
-	Actor *DAT_80072de8;
-	Actor *DAT_80072dec;
-	Actor *DAT_800830c0;
-	Actor *DAT_80072df0;
-	Actor *DAT_80072e08;
-	Actor *DAT_80072df4;
-	Actor *DAT_80072df8;
-	Actor *DAT_80072dfc;
-	Actor *DAT_800830bc;
-	Actor *DAT_800830b8;
-	Actor *DAT_80072e0c;
-	Actor *DAT_800830a0;
-	Actor *DAT_800830d4;
-	Actor *DAT_800830dc;
-	Actor *DAT_80072e04;
+	Actor *_actor_80072de8;
+	Actor *_actor_80072dec;
+	Actor *_actor_800830c0;
+	Actor *_actor_80072df0;
+	Actor *_actor_80072e08;
+	Actor *_actor_80072df4;
+	Actor *_actor_80072df8;
+	Actor *_actor_80072dfc;
+	Actor *_actor_800830bc;
+	Actor *_actor_800830b8;
+	Actor *_actor_80072e0c;
+	Actor *_actor_800830a0;
+	Actor *_actor_800830d4;
+	Actor *_actor_800830dc;
+	Actor *_actor_80072e04;
 
-	uint16 DAT_80063514; //flags
+	uint16 _actor_80063514; //flags
 
 	byte *_palettes;
 public:
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index a012a285e4..b7e0d7c734 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -100,8 +100,8 @@ void Properties::print(char *prefix) {
 
 DragonFLG::DragonFLG(BigfileArchive *bigfileArchive) {
 	_data = bigfileArchive->load("dragon.flg", _dataSize);
-	properties = new Properties(288);
-	properties->init(_dataSize, _data);
+	_properties = new Properties(288);
+	_properties->init(_dataSize, _data);
 }
 
 DragonFLG::~DragonFLG() {
@@ -109,25 +109,25 @@ DragonFLG::~DragonFLG() {
 }
 
 bool DragonFLG::get(uint32 propertyId) {
-	return properties->get(propertyId);
+	return _properties->get(propertyId);
 }
 
 void DragonFLG::set(uint32 propertyId, bool value) {
-	properties->set(propertyId, value);
+	_properties->set(propertyId, value);
 }
 
 void DragonFLG::saveState(Common::WriteStream *out) {
 	//properties->print("save");
-	properties->save(128, out); // save first 80 flags.
+	_properties->save(128, out); // save first 80 flags.
 }
 
 void DragonFLG::loadState(Common::ReadStream *in) {
 	byte savedState[0x10];
 
-	properties->init(_dataSize, _data);
+	_properties->init(_dataSize, _data);
 
 	in->read(savedState, 0x10);
-	properties->init(0x10, savedState);
+	_properties->init(0x10, savedState);
 	//properties->print("load");
 
 }
diff --git a/engines/dragons/dragonflg.h b/engines/dragons/dragonflg.h
index 4ba19f4ad4..3e346bf214 100644
--- a/engines/dragons/dragonflg.h
+++ b/engines/dragons/dragonflg.h
@@ -50,7 +50,7 @@ class DragonFLG {
 private:
 	byte *_data;
 	uint32 _dataSize;
-	Properties *properties;
+	Properties *_properties;
 public:
 	virtual ~DragonFLG();
 
diff --git a/engines/dragons/dragonimg.cpp b/engines/dragons/dragonimg.cpp
index a39fdbd0f8..e01ae533d7 100644
--- a/engines/dragons/dragonimg.cpp
+++ b/engines/dragons/dragonimg.cpp
@@ -25,7 +25,7 @@
 
 namespace Dragons {
 
-DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
+DragonImg::DragonImg(BigfileArchive *bigfileArchive) {
 	uint32 fileSize;
 	byte *iptData = bigfileArchive->load("dragon.ipt", fileSize);
 	Common::SeekableReadStream *iptReadStream = new Common::MemoryReadStream(iptData, fileSize, DisposeAfterUse::YES);
@@ -36,7 +36,7 @@ DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
 	Common::SeekableReadStream *imgReadStream = new Common::MemoryReadStream(_imgData, fileSize, DisposeAfterUse::NO);
 
 
-	_imgObjects = new IMG[_count];
+	_imgObjects = new Img[_count];
 
 	for (int i = 0; i < _count; i++) {
 		imgReadStream->seek(iptReadStream->readUint32LE());
@@ -55,11 +55,11 @@ DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
 	delete imgReadStream;
 }
 
-DragonIMG::~DragonIMG() {
+DragonImg::~DragonImg() {
 	delete _imgData;
 }
 
-IMG *DragonIMG::getIMG(uint32 iptId) {
+Img *DragonImg::getImg(uint32 iptId) {
 	iptId &= 0xffff;
 	assert(iptId < _count);
 	return &_imgObjects[iptId];
diff --git a/engines/dragons/dragonimg.h b/engines/dragons/dragonimg.h
index 4b32308d2e..d12fe0182c 100644
--- a/engines/dragons/dragonimg.h
+++ b/engines/dragons/dragonimg.h
@@ -19,14 +19,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#ifndef DRAGONS_DRAGONIMG_H
-#define DRAGONS_DRAGONIMG_H
+#ifndef DRAGONS_DRAGONImg_H
+#define DRAGONS_DRAGONImg_H
 
 #include "common/system.h"
 
 namespace Dragons {
 
-struct IMG {
+struct Img {
 	uint16 x;
 	uint16 y;
 	uint16 w;
@@ -40,17 +40,17 @@ struct IMG {
 
 class BigfileArchive;
 
-class DragonIMG {
+class DragonImg {
 private:
 	int16 _count;
-	IMG *_imgObjects;
+	Img *_imgObjects;
 	byte *_imgData;
 public:
-	DragonIMG(BigfileArchive *bigfileArchive);
-	~DragonIMG();
-	IMG *getIMG(uint32 iptId);
+	DragonImg(BigfileArchive *bigfileArchive);
+	~DragonImg();
+	Img *getImg(uint32 iptId);
 };
 
 } // End of namespace Dragons
 
-#endif //DRAGONS_DRAGONIMG_H
+#endif //DRAGONS_DRAGONImg_H
diff --git a/engines/dragons/dragonobd.cpp b/engines/dragons/dragonobd.cpp
index 9571d0a04a..cf1528bc95 100644
--- a/engines/dragons/dragonobd.cpp
+++ b/engines/dragons/dragonobd.cpp
@@ -28,10 +28,10 @@ namespace Dragons {
 DragonOBD::DragonOBD(BigfileArchive *bigfileArchive) {
 	uint32 size;
 	byte *optData = bigfileArchive->load("dragon.opt", size);
-	optReadStream = new Common::MemoryReadStream(optData, size, DisposeAfterUse::YES);
+	_optReadStream = new Common::MemoryReadStream(optData, size, DisposeAfterUse::YES);
 
 	byte *sptData = bigfileArchive->load("dragon.spt", size);
-	sptReadStream = new Common::MemoryReadStream(sptData, size, DisposeAfterUse::YES);
+	_sptReadStream = new Common::MemoryReadStream(sptData, size, DisposeAfterUse::YES);
 
 	_data = bigfileArchive->load("dragon.obd", _dataSize);
 }
@@ -46,18 +46,18 @@ DragonOBD::~DragonOBD() {
 	if (_data) {
 		delete _data;
 	}
-	delete optReadStream;
-	delete sptReadStream;
+	delete _optReadStream;
+	delete _sptReadStream;
 }
 
 byte *DragonOBD::getFromOpt(uint32 index) {
-	optReadStream->seek(index * 8);
-	return getObdAtOffset(optReadStream->readUint32LE());
+	_optReadStream->seek(index * 8);
+	return getObdAtOffset(_optReadStream->readUint32LE());
 }
 
 byte *DragonOBD::getFromSpt(uint32 index) {
-	sptReadStream->seek(index * 4);
-	return getObdAtOffset(sptReadStream->readUint32LE());
+	_sptReadStream->seek(index * 4);
+	return getObdAtOffset(_sptReadStream->readUint32LE());
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonobd.h b/engines/dragons/dragonobd.h
index dc79489d64..27d68a8fbe 100644
--- a/engines/dragons/dragonobd.h
+++ b/engines/dragons/dragonobd.h
@@ -32,8 +32,8 @@ class DragonOBD {
 private:
 	byte *_data;
 	uint32 _dataSize;
-	Common::SeekableReadStream *optReadStream;
-	Common::SeekableReadStream *sptReadStream;
+	Common::SeekableReadStream *_optReadStream;
+	Common::SeekableReadStream *_sptReadStream;
 
 public:
 	virtual ~DragonOBD();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 6e95456704..82f289c2dd 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -194,7 +194,7 @@ Common::Error DragonsEngine::run() {
 	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::EN_ANY);
 	_talk = new Talk(this, _bigfileArchive);
 	_dragonFLG = new DragonFLG(_bigfileArchive);
-	_dragonIMG = new DragonIMG(_bigfileArchive);
+	_dragonImg = new DragonImg(_bigfileArchive);
 	_dragonOBD = new DragonOBD(_bigfileArchive);
 	_dragonRMS = new DragonRMS(_bigfileArchive, _dragonOBD);
 	_dragonVAR = new DragonVAR(_bigfileArchive);
@@ -224,7 +224,7 @@ Common::Error DragonsEngine::run() {
 	delete _actorManager;
 	delete _backgroundResourceLoader;
 	delete _dragonFLG;
-	delete _dragonIMG;
+	delete _dragonImg;
 	delete _dragonRMS;
 	delete _dragonVAR;
 	delete _fontManager;
@@ -246,7 +246,7 @@ uint16 DragonsEngine::ipt_img_file_related() {
 	for (int i = 0;i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
 		if ((ini->sceneId == getCurrentSceneId()) && (ini->field_1a_flags_maybe == 0)) {
-			IMG *img = _dragonIMG->getIMG(ini->field_2);
+			Img *img = _dragonImg->getImg(ini->field_2);
 			if ((img->x <= tileX) && (((tileX <= img->x + img->w && (img->y <= tileY)) && (tileY <= img->y + img->h)))) {
 				return i + 1;
 			}
@@ -346,7 +346,7 @@ void DragonsEngine::gameLoop() {
 //		actorId = CheckButtonMapPress_CycleUp(0);
 //		if (((actorId & 0xffff) != 0) && isInputEnabled()) {
 //			_cursor->_sequenceID = _cursor->_sequenceID + 1;
-//			if (_cursor->iniItemInHand == 0) {
+//			if (_cursor->_iniItemInHand == 0) {
 //				bVar1 = _cursor->_sequenceID < 5;
 //			}
 //			else {
@@ -376,7 +376,7 @@ void DragonsEngine::gameLoop() {
 			if (flicker->sceneId == getCurrentSceneId() && flicker->actor->_sequenceID2 != -1) {
 				uVar6 = _scriptOpcodes->_scriptTargetINI;
 				if (_cursor->_sequenceID != 5) {
-					uVar6 = _cursor->data_80072890;
+					uVar6 = _cursor->_data_80072890;
 				}
 				if (uVar6 > 0) {
 					flicker->actor->_sequenceID2 = getINI(uVar6 - 1)->field_e;
@@ -415,7 +415,7 @@ void DragonsEngine::gameLoop() {
 							_inventory->setType(1);
 							_inventory->openInventory();
 							joined_r0x80027a38:
-							if (_cursor->iniItemInHand == 0) {
+							if (_cursor->_iniItemInHand == 0) {
 								_cursor->_sequenceID = 1;
 								actorId = uVar3;
 							}
@@ -432,7 +432,7 @@ void DragonsEngine::gameLoop() {
 						if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
 							if (_cursor->_iniUnderCursor == 0x8002) {
 								LAB_80027294:
-								if (_cursor->iniItemInHand == 0) {
+								if (_cursor->_iniItemInHand == 0) {
 									if ((bit_flags_8006fbd8 & 3) != 1) {
 										sequenceId = _dragonVAR->getVar(7);
 										uVar7 = _inventory->_old_showing_value;
@@ -441,10 +441,10 @@ void DragonsEngine::gameLoop() {
 									}
 								}
 								else {
-									if (_inventory->addItem(_cursor->iniItemInHand)) {
+									if (_inventory->addItem(_cursor->_iniItemInHand)) {
 										_cursor->_sequenceID = 1;
 										waitForFrames(1);
-										_cursor->iniItemInHand = 0;
+										_cursor->_iniItemInHand = 0;
 										_cursor->_iniUnderCursor = 0;
 										actorId = uVar3;
 										continue;
@@ -465,22 +465,22 @@ void DragonsEngine::gameLoop() {
 						}
 						LAB_80027ab4:
 						_counter = 0;
-						_cursor->data_80072890 = _cursor->_iniUnderCursor;
+						_cursor->_data_80072890 = _cursor->_iniUnderCursor;
 						if (_cursor->_sequenceID < 5) {
-							_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
+							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 							walkFlickerToObject();
 							if (bit_flags_8006fbd8 != 0) {
 								clearFlags(ENGINE_FLAG_8);
 							}
 						}
 						else {
-							_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
+							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 							walkFlickerToObject();
 							if (bit_flags_8006fbd8 != 0) {
 								clearFlags(ENGINE_FLAG_8);
 							}
-							_scriptOpcodes->_scriptTargetINI = _cursor->data_80072890;
-							_cursor->data_80072890 = _cursor->iniItemInHand;
+							_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
+							_cursor->_data_80072890 = _cursor->_iniItemInHand;
 						}
 					}
 				}
@@ -540,10 +540,10 @@ void DragonsEngine::gameLoop() {
 			}
 			if (_cursor->_iniUnderCursor != 0) {
 				if ((_cursor->_sequenceID != 4) && (_cursor->_sequenceID != 2)) {
-					_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
-					_cursor->data_80072890 = _cursor->_iniUnderCursor;
+					_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+					_cursor->_data_80072890 = _cursor->_iniUnderCursor;
 					if (4 < _cursor->_sequenceID) {
-						_cursor->data_80072890 = _cursor->iniItemInHand;
+						_cursor->_data_80072890 = _cursor->_iniItemInHand;
 						_scriptOpcodes->_scriptTargetINI = _cursor->_iniUnderCursor;
 					}
 					clearFlags(ENGINE_FLAG_8);
@@ -551,11 +551,11 @@ void DragonsEngine::gameLoop() {
 					goto LAB_8002790c;
 				}
 				Actor *actor = _inventory->getInventoryItemActor(_cursor->_iniUnderCursor);
-				uint16 tmpId = _cursor->iniItemInHand;
-				_inventory->replaceItem(_cursor->_iniUnderCursor, _cursor->iniItemInHand);
+				uint16 tmpId = _cursor->_iniItemInHand;
+				_inventory->replaceItem(_cursor->_iniUnderCursor, _cursor->_iniItemInHand);
 				_cursor->data_8007283c = actor->_sequenceID;
 				actor->clearFlag(ACTOR_FLAG_40);
-				_cursor->iniItemInHand = _cursor->_iniUnderCursor;
+				_cursor->_iniItemInHand = _cursor->_iniUnderCursor;
 				_cursor->_sequenceID = 5;
 				actorId = uVar3;
 				if (tmpId != 0) {
@@ -572,16 +572,16 @@ void DragonsEngine::gameLoop() {
 				}
 				continue;
 			}
-			if (_cursor->iniItemInHand == 0) goto LAB_80027b58;
+			if (_cursor->_iniItemInHand == 0) goto LAB_80027b58;
 			//drop item back into inventory
-			if (_inventory->addItemIfPositionIsEmpty(_cursor->iniItemInHand, _cursor->_x, _cursor->_y)) {
-				Actor *invActor = _inventory->getInventoryItemActor(_cursor->iniItemInHand);
+			if (_inventory->addItemIfPositionIsEmpty(_cursor->_iniItemInHand, _cursor->_x, _cursor->_y)) {
+				Actor *invActor = _inventory->getInventoryItemActor(_cursor->_iniItemInHand);
 				invActor->_flags = 0;
 				invActor->_priorityLayer = 0;
 				invActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 				invActor->updateSequence(
-						 getINI(_cursor->iniItemInHand - 1)->field_8 * 2 + 10);
-				_cursor->iniItemInHand = 0;
+						 getINI(_cursor->_iniItemInHand - 1)->field_8 * 2 + 10);
+				_cursor->_iniItemInHand = 0;
 				invActor->setFlag(ACTOR_FLAG_40);
 				invActor->setFlag(ACTOR_FLAG_80);
 				invActor->setFlag(ACTOR_FLAG_100);
@@ -593,7 +593,7 @@ void DragonsEngine::gameLoop() {
 			}
 		}
 		LAB_8002790c:
-		if ((_cursor->iniItemInHand == 0) ||
+		if ((_cursor->_iniItemInHand == 0) ||
 			(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4))))
 			goto LAB_80027b58;
 		_cursor->_sequenceID = 5;
@@ -604,7 +604,7 @@ void DragonsEngine::gameLoop() {
 
 
 void DragonsEngine::updateHandler() {
-	videoFlags |= 0x40;
+	_videoFlags |= 0x40;
 	//TODO logic here
 
 	updateActorSequences();
@@ -680,7 +680,7 @@ void DragonsEngine::updateHandler() {
 
 	// TODO data_8006a3a0 logic. @ 0x8001c2f4
 
-	videoFlags &= ~0x40;
+	_videoFlags &= ~0x40;
 }
 
 uint32 DragonsEngine::calulateTimeLeft() {
@@ -811,7 +811,7 @@ uint16 DragonsEngine::getIniFromImg() {
 	for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
 		if (ini->sceneId == currentSceneId && ini->field_1a_flags_maybe == 0) {
-			IMG *img = _dragonIMG->getIMG(ini->field_2);
+			Img *img = _dragonImg->getImg(ini->field_2);
 			if (x >= img->x &&
 				img->x + img->w >= x &&
 				y >= img->y &&
@@ -908,10 +908,10 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 			actorId = (uint)uVar5;
 		} while (uVar5 < uVar1);
 	}
-	if (run_func_ptr_unk_countdown_timer != 0) {
-		run_func_ptr_unk_countdown_timer = run_func_ptr_unk_countdown_timer - 1;
+	if (_run_func_ptr_unk_countdown_timer != 0) {
+		_run_func_ptr_unk_countdown_timer = _run_func_ptr_unk_countdown_timer - 1;
 	}
-	return (uint)run_func_ptr_unk_countdown_timer;
+	return (uint)_run_func_ptr_unk_countdown_timer;
 } */
 
 //TODO the logic in this function doesn't match the original. It should be redone.
@@ -975,8 +975,8 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 			}
 		}
 
-		if (run_func_ptr_unk_countdown_timer != 0) {
-			run_func_ptr_unk_countdown_timer--;
+		if (_run_func_ptr_unk_countdown_timer != 0) {
+			_run_func_ptr_unk_countdown_timer--;
 		}
 	}
 }
@@ -1049,8 +1049,8 @@ void DragonsEngine::performAction() {
 	uVar6 = 0;
 	_scriptOpcodes->_data_80071f5c = 0;
 
-	assert(_cursor->data_80072890 > 0);
-	byte *obd = _dragonOBD->getFromOpt(_cursor->data_80072890 - 1);
+	assert(_cursor->_data_80072890 > 0);
+	byte *obd = _dragonOBD->getFromOpt(_cursor->_data_80072890 - 1);
 
 
 	ScriptOpCall local_48(obd + 8, READ_LE_UINT32(obd));
@@ -1058,11 +1058,11 @@ void DragonsEngine::performAction() {
 	pvVar8 = local_48._codeEnd;
 
 	uVar4 = _cursor->executeScript(local_48, 1);
-	if (_cursor->data_800728b0_cursor_seqID > 4) {
+	if (_cursor->_data_800728b0_cursor_seqID > 4) {
 		_scriptOpcodes->_data_80071f5c = 0;
 
 		obd = _dragonOBD->getFromOpt(_scriptOpcodes->_scriptTargetINI - 1);
-		_scriptOpcodes->_scriptTargetINI = _cursor->data_80072890;
+		_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
 
 		ScriptOpCall local_38(obd + 8, READ_LE_UINT32(obd));
 
@@ -1086,7 +1086,7 @@ void DragonsEngine::performAction() {
 		load_58_result = local_58._result;
 	}
 	if (!load_58_result) {
-		if (_cursor->data_800728b0_cursor_seqID == 3) {
+		if (_cursor->_data_800728b0_cursor_seqID == 3) {
 			ScriptOpCall local_58(pvVar7, pvVar8 - pvVar7);
 			uVar5 = _talk->talkToActor(local_58);
 			uVar4 = uVar4 | uVar5;
@@ -1149,16 +1149,16 @@ void DragonsEngine::walkFlickerToObject()
 
 	flickerINI = _dragonINIResource->getFlickerRecord();
 	if (flickerINI->sceneId == getCurrentSceneId()) {
-		if (_cursor->data_80072890 != 0) {
+		if (_cursor->_data_80072890 != 0) {
 
-			if (!(READ_LE_UINT16(_dragonOBD->getFromOpt(_cursor->data_80072890 - 1) + 4) & 8)
+			if (!(READ_LE_UINT16(_dragonOBD->getFromOpt(_cursor->_data_80072890 - 1) + 4) & 8)
 			&& (_inventory->getType() == 0) && !isFlagSet(ENGINE_FLAG_200000)) {
-				targetINI = getINI(_cursor->data_80072890 - 1);
+				targetINI = getINI(_cursor->_data_80072890 - 1);
 				if ((targetINI->field_1a_flags_maybe & 1) == 0) {
 					if (targetINI->actorResourceId == -1) {
 						return;
 					}
-					IMG *img = _dragonIMG->getIMG(targetINI->field_2);
+					Img *img = _dragonImg->getImg(targetINI->field_2);
 					targetX = img->field_a;
 					targetY = img->field_c;
 				}
@@ -1183,7 +1183,7 @@ void DragonsEngine::walkFlickerToObject()
 			if (flickerINI != NULL && flickerINI->actor != NULL) {
 				flickerINI->actor->clearFlag(ACTOR_FLAG_10);
 				flickerINI->actor->setFlag(ACTOR_FLAG_4);
-				targetINI = getINI(_cursor->data_80072890 - 1);
+				targetINI = getINI(_cursor->_data_80072890 - 1);
 				flickerINI->field_20_actor_field_14 = targetINI->field_e;
 				flickerINI->actor->_sequenceID2 = targetINI->field_e;
 			}
@@ -1200,7 +1200,7 @@ void DragonsEngine::walkFlickerToObject()
 		}
 	}
 	else {
-		if (_cursor->data_80072890 != 0) {
+		if (_cursor->_data_80072890 != 0) {
 			bit_flags_8006fbd8 = 3;
 			return;
 		}
@@ -1214,7 +1214,7 @@ void DragonsEngine::FUN_80038994() {
 }
 
 void DragonsEngine::reset_screen_maybe() {
-	videoFlags &= ~0x10;
+	_videoFlags &= ~0x10;
 	//TODO
 }
 
@@ -1283,9 +1283,9 @@ void DragonsEngine::reset() {
 	_nextUpdatetime = 0;
 	_flags = 0;
 	_unkFlags1 = 0;
-	run_func_ptr_unk_countdown_timer = 0;
-	videoFlags = 0;
-	data_800633fa = 0;
+	_run_func_ptr_unk_countdown_timer = 0;
+	_videoFlags = 0;
+	_data_800633fa = 0;
 
 	for (int i = 0; i < 8; i++) {
 		_paletteCyclingTbl[i].paletteType = 0;
@@ -1299,8 +1299,8 @@ void DragonsEngine::reset() {
 }
 
 void DragonsEngine::runSceneUpdaterFunction() {
-	if ((isFlagSet(ENGINE_FLAG_20) && (run_func_ptr_unk_countdown_timer == 0)) &&
-		(run_func_ptr_unk_countdown_timer = 1, _sceneUpdateFunction != NULL)) {
+	if ((isFlagSet(ENGINE_FLAG_20) && (_run_func_ptr_unk_countdown_timer == 0)) &&
+		(_run_func_ptr_unk_countdown_timer = 1, _sceneUpdateFunction != NULL)) {
 		_sceneUpdateFunction();
 	}
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 51b7693dfd..684d4044ec 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -109,7 +109,7 @@ class BackgroundResourceLoader;
 class Cursor;
 class Credits;
 class DragonFLG;
-class DragonIMG;
+class DragonImg;
 class DragonOBD;
 class DragonRMS;
 class DragonVAR;
@@ -129,14 +129,14 @@ struct DragonINI;
 class DragonsEngine : public Engine {
 public:
 	DragonOBD *_dragonOBD;
-	DragonIMG *_dragonIMG;
+	DragonImg *_dragonImg;
 	DragonRMS *_dragonRMS;
 	ActorManager *_actorManager;
 	DragonINIResource *_dragonINIResource;
 	FontManager *_fontManager;
 	ScriptOpcodes *_scriptOpcodes;
 	Scene *_scene;
-	uint16 data_800633fa;
+	uint16 _data_800633fa;
 	Inventory *_inventory;
 	Cursor *_cursor;
 	Credits *_credits;
@@ -145,8 +145,8 @@ public:
 
 	PaletteCyclingInstruction _paletteCyclingTbl[8];
 
-	uint16 data_800633fc;
-	uint16 videoFlags; // TODO move to screen?
+	uint16 _data_800633fc;
+	uint16 _videoFlags; // TODO move to screen?
 
 	void loadCurrentSceneMsf();
 
@@ -166,7 +166,7 @@ private:
 	uint32 bit_flags_8006fbd8;
 	//unk
 
-	uint16 run_func_ptr_unk_countdown_timer;
+	uint16 _run_func_ptr_unk_countdown_timer;
 
 	uint32 _randomState;
 
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 0cccf54aa2..4f56db6129 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -97,7 +97,7 @@ FontManager::FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigf
 
 	delete readStream;
 
-	DAT_80086f48_fontColor_flag = 0;
+	_dat_80086f48_fontColor_flag = 0;
 }
 
 FontManager::~FontManager() {
@@ -211,7 +211,7 @@ void FontManager::updatePalette() {
 		} else {
 			updatePalEntry(palette_f2_font_maybe, 16, 0);
 		}
-		if (_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_4) && DAT_80086f48_fontColor_flag != 0) {
+		if (_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_4) && _dat_80086f48_fontColor_flag != 0) {
 			updatePalEntry(palette_f2_font_maybe, 17, 0x421);
 		} else {
 			updatePalEntry(palette_f2_font_maybe, 17, 0xfff);
@@ -227,7 +227,7 @@ void FontManager::updatePalette() {
 		updatePalEntry(palette_f2_font_maybe, 48, cursor3);
 		updatePalEntry(palette_f2_font_maybe, 50, 0x421);
 		updatePalEntry(palette_f2_font_maybe, 51, 0x3def);
-		//TODO WRITE_LE_INT16(&palette_f2_font_maybe[33], READ_LE_INT16(&palette_f0[DAT_80084f58 >> 8]) & 0x7fff); //DAT_80084f58 is set in ActuallyShowMessage()
+		//TODO WRITE_LE_INT16(&palette_f2_font_maybe[33], READ_LE_INT16(&palette_f0[_dat_80084f58 >> 8]) & 0x7fff); //_dat_80084f58 is set in ActuallyShowMessage()
 		updatePalEntry(palette_f2_font_maybe, 33, 0x3def); //temporarily put in standard gray
 		if (_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
 			updatePalEntry(palette_f2_font_maybe, 17, 0x3bee);
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index 48b406f36e..db90dc7b93 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -57,7 +57,7 @@ class FontManager {
 public:
 	Font *_fonts[3];
 private:
-	uint16 DAT_80086f48_fontColor_flag;
+	uint16 _dat_80086f48_fontColor_flag;
 	DragonsEngine *_vm;
 	Screen *_screen;
 	Common::List<ScreenTextEntry *> _screenTexts;
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 2b620ec7c2..60db0dbb41 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -62,7 +62,7 @@ void Minigame4::run() {
 	_vm->setVsyncUpdateFunction(videoUpdaterFunction);
 	_vm->_screen->loadPalette(4, _vm->_scene->getPalette());
 	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
-	_vm->videoFlags |= 4;
+	_vm->_videoFlags |= 4;
 	_vm->_scene->setBgLayerPriority(2);
 	_vm->_scene->setMgLayerPriority(1);
 	flickerActor = _vm->_actorManager->loadActor(0x18,0,0xcb,0x79,1);
@@ -101,7 +101,7 @@ void Minigame4::run() {
 	//DisableVSyncEvent();
 	_vm->setVsyncUpdateFunction(NULL);
 	_vm->setFlags(ENGINE_FLAG_1);
-	_vm->videoFlags &= ~(uint16)4;
+	_vm->_videoFlags &= ~(uint16)4;
 	// EnableVSyncEvent();
 	_vm->_dragonINIResource->setFlickerRecord(flicker);
 	_vm->_inventory->setType(uVar3);
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index f0716da369..1f50c2bb05 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -216,7 +216,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	_vm->setFlags(ENGINE_FLAG_200);
 	_actorManager->clearActorFlags(2);
-	_vm->data_800633fc = 0;
+	_vm->_data_800633fc = 0;
 	// TODO 0x8002fff0
 
 	for (int i = 0;i < _dragonINIResource->totalRecords(); i++) {
@@ -290,9 +290,9 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 
 	if (flicker && flicker->sceneId != 0) {
-		flicker->field_20_actor_field_14 = _vm->data_800633fa;
+		flicker->field_20_actor_field_14 = _vm->_data_800633fa;
 		if (flicker->actor) {
-			flicker->actor->_sequenceID2 = _vm->data_800633fa;
+			flicker->actor->_sequenceID2 = _vm->_data_800633fa;
 			flicker->actor->setFlag(ACTOR_FLAG_4);
 		}
 	}
@@ -430,7 +430,7 @@ uint16 Scene::getStageHeight() {
 }
 
 void Scene::loadImageOverlay(uint16 iptId) {
-	IMG *img =_vm->_dragonIMG->getIMG(iptId);
+	Img *img =_vm->_dragonImg->getImg(iptId);
 	if (img->h != 0) {
 		if (img->field_e <= 2) {
 			_stage->overlayImage(img->layerNum - 1, img->data, img->x, img->y, img->w, img->h);
@@ -443,7 +443,7 @@ void Scene::loadImageOverlay(uint16 iptId) {
 }
 
 void Scene::removeImageOverlay(uint16 iptId) {
-	IMG *img =_vm->_dragonIMG->getIMG(iptId);
+	Img *img =_vm->_dragonImg->getImg(iptId);
 	_stage->restoreTiles(img->layerNum - 1, img->x, img->y, img->w, img->h);
 	_stage->restorePriorityTileMap(img->x, img->y, img->w, img->h);
 }
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index b488e6e4d2..10024e10b2 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -237,8 +237,8 @@ void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field4);
 	ARG_INT16(field6);
 
-	if ((field2 >> _vm->_cursor->data_800728b0_cursor_seqID) & 1
-	&& (_vm->_cursor->data_800728b0_cursor_seqID < 5 || field4 == _scriptTargetINI)
+	if ((field2 >> _vm->_cursor->_data_800728b0_cursor_seqID) & 1
+	&& (_vm->_cursor->_data_800728b0_cursor_seqID < 5 || field4 == _scriptTargetINI)
 	&& scriptOpCall._field8 == 1) {
 		scriptOpCall._code -= 8;
 		scriptOpCall._result |= 1;
@@ -317,8 +317,8 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	}
 
 	int16 uVar6 = _scriptTargetINI;
-	int16 uVar5 = _vm->_cursor->data_800728b0_cursor_seqID;
-	int16 uVar4 = _vm->_cursor->data_80072890;
+	int16 uVar5 = _vm->_cursor->_data_800728b0_cursor_seqID;
+	int16 uVar4 = _vm->_cursor->_data_80072890;
 	int16 uVar3 = _vm->_cursor->_iniUnderCursor;
 	int32 uVar2 = _vm->_cursor->_sequenceID;
 	bool isEngineFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
@@ -332,8 +332,8 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	}
 
 	_scriptTargetINI = field6;
-	_vm->_cursor->data_800728b0_cursor_seqID = _vm->_cursor->_sequenceID;
-	_vm->_cursor->data_80072890 = _vm->_cursor->_iniUnderCursor;
+	_vm->_cursor->_data_800728b0_cursor_seqID = _vm->_cursor->_sequenceID;
+	_vm->_cursor->_data_80072890 = _vm->_cursor->_iniUnderCursor;
 //	EnableVSyncEvent();
 	_vm->performAction();
 	if (isEngineFlag8Set) {
@@ -341,8 +341,8 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	}
 	_vm->_cursor->_sequenceID = uVar2;
 	_vm->_cursor->_iniUnderCursor = uVar3;
-	_vm->_cursor->data_80072890 = uVar4;
-	_vm->_cursor->data_800728b0_cursor_seqID = uVar5;
+	_vm->_cursor->_data_80072890 = uVar4;
+	_vm->_cursor->_data_800728b0_cursor_seqID = uVar5;
 	_scriptTargetINI = uVar6;
 }
 
@@ -445,7 +445,7 @@ void ScriptOpcodes::opUnk20(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field2);
 
 	_vm->_sound->PauseCDMusic();
-	_vm->data_800633fc = 1;
+	_vm->_data_800633fc = 1;
 
 	if (field2 >= 2) {
 		//TODO do we need this? It looks like it is pre-loading the next scene's data.
@@ -727,7 +727,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 	if (field8 == -1) {
 		if ((firstIni->field_1a_flags_maybe & 1) == 0) {
 			if ((int)firstIni->field_2 != -1) {
-				IMG *firstDragonImg1 = _vm->_dragonIMG->getIMG(firstIni->field_2);
+				Img *firstDragonImg1 = _vm->_dragonImg->getImg(firstIni->field_2);
 				int16 newXPos1 = firstDragonImg1->field_a + firstIni->field_1c;
 				secondIni->x = newXPos1;
 				secondIni->actor->_x_pos = newXPos1;
@@ -773,7 +773,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 		if ((int)firstIni->field_2 == -1) {
 			return;
 		}
-		IMG *firstDragonImg2 = _vm->_dragonIMG->getIMG(firstIni->field_2);
+		Img *firstDragonImg2 = _vm->_dragonImg->getImg(firstIni->field_2);
 
 		newXPosAgain = firstDragonImg2->field_a + firstIni->field_1c;
 		newYPosAgain = firstDragonImg2->field_c + firstIni->field_1e;
@@ -834,7 +834,7 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 		// load scene here.
 		_vm->_scene->data_80063392 = _vm->_scene->getSceneId();
 		_vm->_scene->setSceneId(newSceneID);
-		_vm->data_800633fa = field6;
+		_vm->_data_800633fa = field6;
 
 		_vm->_scene->loadScene(newSceneID, cameraPointID);
 	} else {
@@ -868,7 +868,7 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 	DragonINI *ini = iniId == 0 ? _vm->_dragonINIResource->getFlickerRecord() : _vm->getINI(iniId - 1);
 
 	if ((ini->field_1a_flags_maybe & 1) == 0) {
-		IMG *img = _vm->_dragonIMG->getIMG(ini->field_2);
+		Img *img = _vm->_dragonImg->getImg(ini->field_2);
 
 		int y = img->field_e == 0 ? img->y : img->y << 3;
 
@@ -1218,10 +1218,10 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 		}
 
 		if (ini->sceneId == 1) {
-			if ((uint)_vm->_cursor->iniItemInHand - 1 == ini->id) {
-				_vm->_cursor->data_800728b0_cursor_seqID = 0;
+			if ((uint)_vm->_cursor->_iniItemInHand - 1 == ini->id) {
+				_vm->_cursor->_data_800728b0_cursor_seqID = 0;
 				_vm->_cursor->_sequenceID = 0;
-				_vm->_cursor->iniItemInHand = 0;
+				_vm->_cursor->_iniItemInHand = 0;
 			}
 			else {
 				if (_vm->_inventory->clearItem(ini->id + 1)) {
@@ -1233,14 +1233,14 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 		}
 
 		if (sceneId == 1) {
-			if (_vm->_cursor->iniItemInHand != 0) {
-				_vm->_inventory->addItem(_vm->_cursor->iniItemInHand);
+			if (_vm->_cursor->_iniItemInHand != 0) {
+				_vm->_inventory->addItem(_vm->_cursor->_iniItemInHand);
 				if (_vm->_inventory->getType() == 1) {
-					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->iniItemInHand);
+					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->_iniItemInHand);
 					actor->_flags = 0;
 					actor->_priorityLayer = 0;
 					actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-					actor->updateSequence((_vm->getINI(_vm->_cursor->iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
+					actor->updateSequence((_vm->getINI(_vm->_cursor->_iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);
@@ -1251,10 +1251,10 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 			DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 			_vm->_cursor->updatePosition(flicker->actor->_x_pos - _vm->_scene->_camera.x,
 					flicker->actor->_y_pos - (_vm->_scene->_camera.y + 0x1e));
-			_vm->_cursor->data_800728b0_cursor_seqID = 5;
+			_vm->_cursor->_data_800728b0_cursor_seqID = 5;
 			_vm->_cursor->_sequenceID = 5;
 			_vm->_cursor->data_8007283c = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
-			_vm->_cursor->iniItemInHand = field2;
+			_vm->_cursor->_iniItemInHand = field2;
 		}
 	}
 	ini->sceneId = sceneId;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 06e459c264..01614b2fd7 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -1363,12 +1363,12 @@ void tableBasedSceneUpdateFunction() {
 	SpecialOpcodes *spc = vm->_scriptOpcodes->_specialOpCodes;
 
 	uVar3 = (uint)spc->sceneUpdater.curSequence;
-	if (!vm->isFlagSet(ENGINE_FLAG_8000) || vm->data_800633fc == 1) {
+	if (!vm->isFlagSet(ENGINE_FLAG_8000) || vm->_data_800633fc == 1) {
 		if (spc->sceneUpdater.sequenceID != -1) {
 			vm->getINI(spc->sceneUpdater.iniID)->actor->updateSequence(spc->sceneUpdater.sequenceID);
 			spc->sceneUpdater.sequenceID = -1;
 		}
-		if (vm->data_800633fc == 0) {
+		if (vm->_data_800633fc == 0) {
 			spc->sceneUpdater.counter--;
 			if (spc->sceneUpdater.counter == 0) {
 				spc->sceneUpdater.sequenceID = spc->sceneUpdater.sequenceIDTbl[uVar3][spc->sceneUpdater.curSequenceIndex]; //*(int16_t *) (sceneUpdateSequenceTbl[uVar3].sequenceIdPtr + (uint) spc->sceneUpdater.curSequenceIndex);
@@ -1495,7 +1495,7 @@ void menInMinesSceneUpdateFunction() {
 		sequenceId = 2;
 	}
 	else {
-		if (vm->data_800633fc == 0) {
+		if (vm->_data_800633fc == 0) {
 			return;
 		}
 		sequenceId = 0;
@@ -1531,7 +1531,7 @@ void monksAtBarSceneUpdateFunction() {
 		specialOpCounter = 600;
 	}
 	if (vm->isFlagSet(ENGINE_FLAG_8000)) {
-		if (vm->data_800633fc == 0) {
+		if (vm->_data_800633fc == 0) {
 			return;
 		}
 		monk1->updateSequence(0);
@@ -1729,7 +1729,7 @@ void flameEscapeSceneUpdateFunction() {
 		vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
 	}
 	else {
-		if ((vm->data_800633fc != 0) && flame->_sequenceID != 0x10) {
+		if ((vm->_data_800633fc != 0) && flame->_sequenceID != 0x10) {
 			flame->updateSequence(0x10);
 		}
 	}
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 291df0905d..ce8f5e8c40 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -90,7 +90,7 @@ Talk::FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param
 	//TODO 0x800323a4
 
 	//TODO dragon_text_related(textId);
-	_vm->data_800633fc = 1;
+	_vm->_data_800633fc = 1;
 	uint32 uVar4 = 0; //TODO FUN_8001d1ac(0,textId,0);
 
 	actor->updateSequence(startSequenceId);
@@ -381,7 +381,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 					}
 				}
 				if (param_5 == 0) {
-					_vm->data_800633fc = 0;
+					_vm->_data_800633fc = 0;
 					return (uint)returnStatus;
 				}
 				uVar9 = ((int)((int)(short)unaff_s4 * (uint)1 * (int)sVar3) >> 3) * 0x3c;
@@ -430,7 +430,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 				_vm->setFlags(ENGINE_FLAG_8);
 			}
 		}
-		_vm->data_800633fc = 0;
+		_vm->_data_800633fc = 0;
 		return (uint)returnStatus;
 }
 
@@ -440,7 +440,7 @@ uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 tex
 	DragonINI *ini = iniId == 0 ? _vm->_dragonINIResource->getFlickerRecord() : _vm->getINI(iniId - 1);
 
 	if ((ini->field_1a_flags_maybe & 1) == 0) {
-		IMG *local_v1_184 = _vm->_dragonIMG->getIMG(ini->field_2);
+		Img *local_v1_184 = _vm->_dragonImg->getImg(ini->field_2);
 		int x, y;
 		if (local_v1_184->field_e == 0) {
 			y = (uint)(uint16)local_v1_184->y;
@@ -494,7 +494,7 @@ Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 pa
 //		uVar4 = puVar7[5];
 //		puVar8[4] = _DAT_80011a80;
 //		puVar8[5] = uVar4;
-		_vm->data_800633fc = 1;
+		_vm->_data_800633fc = 1;
 
 		// sVar3 = FUN_8001d1ac(0,textId,0);
 		_vm->_sound->playSpeech(textId);
@@ -938,7 +938,7 @@ void Talk::flickerRandomDefaultResponse() {
 
 uint32 Talk::getDefaultResponseTextIndex() {
 	uint16 rand = _vm->getRand(9);
-	return defaultResponseTbl[(_vm->_cursor->data_800728b0_cursor_seqID - 1) * 9 + rand];
+	return defaultResponseTbl[(_vm->_cursor->_data_800728b0_cursor_seqID - 1) * 9 + rand];
 }
 
 uint32 extractTextIndex(Common::File *fd, uint16 offset) {


Commit: df7102298eb165d397b1b1d0602adadc7109641f
    https://github.com/scummvm/scummvm/commit/df7102298eb165d397b1b1d0602adadc7109641f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More renames for the class variables

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/minigame2.cpp
    engines/dragons/minigame2.h
    engines/dragons/minigame3.cpp
    engines/dragons/minigame3.h
    engines/dragons/minigame4.cpp
    engines/dragons/minigame4.h
    engines/dragons/minigame5.cpp
    engines/dragons/minigame5.h
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/sequenceopcodes.h
    engines/dragons/sound.cpp
    engines/dragons/sound.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/specialopcodes.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 82f289c2dd..e80a79e025 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -265,7 +265,7 @@ void DragonsEngine::gameLoop() {
 	DragonINI *pDVar8;
 
 	_cursor->_cursorActivationSeqOffset = 0;
-	bit_flags_8006fbd8 = 0;
+	_bit_flags_8006fbd8 = 0;
 	_counter = 0;
 	setFlags(ENGINE_FLAG_8);
 	actorId = 0;
@@ -304,7 +304,7 @@ void DragonsEngine::gameLoop() {
 			_counter = 0;
 			clearFlags(ENGINE_FLAG_80000000);
 		}
-		if (bit_flags_8006fbd8 == 0) {
+		if (_bit_flags_8006fbd8 == 0) {
 			setFlags(ENGINE_FLAG_8);
 		}
 		if (_dragonINIResource->getFlickerRecord()->sceneId == getCurrentSceneId()) {
@@ -370,8 +370,8 @@ void DragonsEngine::gameLoop() {
 //			continue;
 //		}
 
-		if (bit_flags_8006fbd8 == 3) {
-			bit_flags_8006fbd8 = 0;
+		if (_bit_flags_8006fbd8 == 3) {
+			_bit_flags_8006fbd8 = 0;
 			DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 			if (flicker->sceneId == getCurrentSceneId() && flicker->actor->_sequenceID2 != -1) {
 				uVar6 = _scriptOpcodes->_scriptTargetINI;
@@ -398,7 +398,7 @@ void DragonsEngine::gameLoop() {
 			if (_inventory->getType() < 2) {
 				if (_inventory->getType() == 0) {
 					if ((checkForInventoryButtonRelease() && isInputEnabled()) &&
-						((bit_flags_8006fbd8 & 3) != 1)) {
+						((_bit_flags_8006fbd8 & 3) != 1)) {
 						sequenceId = _dragonVAR->getVar(7);
 						uVar7 = _inventory->_old_showing_value;
 						_inventory->_old_showing_value = _inventory->getType();
@@ -433,7 +433,7 @@ void DragonsEngine::gameLoop() {
 							if (_cursor->_iniUnderCursor == 0x8002) {
 								LAB_80027294:
 								if (_cursor->_iniItemInHand == 0) {
-									if ((bit_flags_8006fbd8 & 3) != 1) {
+									if ((_bit_flags_8006fbd8 & 3) != 1) {
 										sequenceId = _dragonVAR->getVar(7);
 										uVar7 = _inventory->_old_showing_value;
 										_inventory->_old_showing_value = _inventory->getType();
@@ -469,14 +469,14 @@ void DragonsEngine::gameLoop() {
 						if (_cursor->_sequenceID < 5) {
 							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 							walkFlickerToObject();
-							if (bit_flags_8006fbd8 != 0) {
+							if (_bit_flags_8006fbd8 != 0) {
 								clearFlags(ENGINE_FLAG_8);
 							}
 						}
 						else {
 							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 							walkFlickerToObject();
-							if (bit_flags_8006fbd8 != 0) {
+							if (_bit_flags_8006fbd8 != 0) {
 								clearFlags(ENGINE_FLAG_8);
 							}
 							_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
@@ -861,8 +861,8 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 		//LAB_80027d40:
 //		if ((flickerINI->sceneId == currentSceneId)
 //			&& (uVar5 != 0xffff)) {
-//			actors[(uint)uVar5]._sequenceID = 8;
-//			actors[(uint)uVar5]._priorityLayer_maybe = 0;
+//			actors[(uint)uVar5]._sequenceID = 8;
+//			actors[(uint)uVar5]._priorityLayer_maybe = 0;
 //		}
 	}
 	else {
@@ -870,22 +870,22 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 			if ((flickerINI == NULL) || flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
 				if ((flickerINI->sceneId == currentSceneId)
 					&& (uVar5 != 0xffff)) {
-//					actors[(uint)uVar5]._sequenceID = 8;
-//					actors[(uint)uVar5]._priorityLayer_maybe = 0;
+//					actors[(uint)uVar5]._sequenceID = 8;
+//					actors[(uint)uVar5]._priorityLayer_maybe = 0;
 				}
 			} else {
-				if ((bit_flags_8006fbd8 & 2) == 0) {
-					bit_flags_8006fbd8 = bit_flags_8006fbd8 | 2;
+				if ((_bit_flags_8006fbd8 & 2) == 0) {
+					_bit_flags_8006fbd8 = _bit_flags_8006fbd8 | 2;
 				}
 //				if (((((actors[actorId]._flags & 0x2000) == 0) && ((actors[actorId]._flags & 4) != 0)) &&
-//					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
-//				(actors[actorId]._sequenceID2 != -1)) {
-//					actor_update_sequenceID(actorId,actors[actorId]._sequenceID2);
+//					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
+//				(actors[actorId]._sequenceID2 != -1)) {
+//					actor_update_sequenceID(actorId,actors[actorId]._sequenceID2);
 //				}
 			}
 
 		} else {
-			//actors[(uint)uVar5]._priorityLayer_maybe = 0;
+			//actors[(uint)uVar5]._priorityLayer_maybe = 0;
 		}
 
 	}
@@ -934,8 +934,8 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 			//error("LAB_80027d40"); //TODO is this logic required?
 //		if ((flickerINI->sceneId == currentSceneId)
 //			&& (uVar5 != 0xffff)) {
-//			actors[(uint)uVar5]._sequenceID = 8;
-//			actors[(uint)uVar5]._priorityLayer_maybe = 0;
+//			actors[(uint)uVar5]._sequenceID = 8;
+//			actors[(uint)uVar5]._priorityLayer_maybe = 0;
 //		}
 		}
 		else {
@@ -946,8 +946,8 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 						_inventory->setPriority(0);
 					}
 				} else {
-					if ((bit_flags_8006fbd8 & 2) == 0) {
-						bit_flags_8006fbd8 = bit_flags_8006fbd8 | 2;
+					if ((_bit_flags_8006fbd8 & 2) == 0) {
+						_bit_flags_8006fbd8 = _bit_flags_8006fbd8 | 2;
 					}
 					if (flickerINI->actor->isFlagClear(ACTOR_FLAG_2000)
 					&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
@@ -1172,11 +1172,11 @@ void DragonsEngine::walkFlickerToObject()
 				}
 				flickerINI->actor->startWalk((int)(((uint)targetX + (uint)targetINI->field_1c) * 0x10000) >> 0x10,
 													(int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10,0);
-				bit_flags_8006fbd8 = 1;
+				_bit_flags_8006fbd8 = 1;
 				return;
 			}
 			if (isFlagSet(ENGINE_FLAG_200000)) {
-				bit_flags_8006fbd8 = 3;
+				_bit_flags_8006fbd8 = 3;
 				return;
 			}
 			flickerINI = _dragonINIResource->getFlickerRecord();
@@ -1187,7 +1187,7 @@ void DragonsEngine::walkFlickerToObject()
 				flickerINI->field_20_actor_field_14 = targetINI->field_e;
 				flickerINI->actor->_sequenceID2 = targetINI->field_e;
 			}
-			bit_flags_8006fbd8 = 3;
+			_bit_flags_8006fbd8 = 3;
 			return;
 		}
 		if (_inventory->getType() == 0 && !isFlagSet(ENGINE_FLAG_200000)) {
@@ -1201,11 +1201,11 @@ void DragonsEngine::walkFlickerToObject()
 	}
 	else {
 		if (_cursor->_data_80072890 != 0) {
-			bit_flags_8006fbd8 = 3;
+			_bit_flags_8006fbd8 = 3;
 			return;
 		}
 	}
-	bit_flags_8006fbd8 = 0;
+	_bit_flags_8006fbd8 = 0;
 	return;
 }
 
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 684d4044ec..e841ce598c 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -163,7 +163,7 @@ private:
 	uint32 _unkFlags1;
 	Common::Point _cursorPosition;
 	uint32 _counter;
-	uint32 bit_flags_8006fbd8;
+	uint32 _bit_flags_8006fbd8;
 	//unk
 
 	uint16 _run_func_ptr_unk_countdown_timer;
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 59a0dfb80f..e0e6a75e72 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -69,10 +69,10 @@ Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 	_old_showing_value = 0;
 	_bag = NULL;
 
-	inventionBookPrevSceneUpdateFunc = NULL;
-	inventionBookPrevSceneId = 0;
-	inventionBookPrevFlickerINISceneId = 0;
-	inventionBookPrevFlickerINIPosition = Common::Point(0,0);
+	_inventionBookPrevSceneUpdateFunc = NULL;
+	_inventionBookPrevSceneId = 0;
+	_inventionBookPrevFlickerINISceneId = 0;
+	_inventionBookPrevFlickerINIPosition = Common::Point(0,0);
 }
 
 void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag, DragonINIResource *dragonIniResource) {
@@ -172,11 +172,11 @@ void Inventory::openInventory() {
 		item->_x_pos = item->_walkDestX = invXPosTable[i] + 0x10;
 		item->_y_pos = item->_walkDestY = invYPosTable[i] + 0xc;
 
-		if (inventoryItemTbl[i]) {
+		if (_inventoryItemTbl[i]) {
 			item->_flags = 0; //clear all flags
 			item->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 			item->_priorityLayer = 0;
-			item->updateSequence(_vm->getINI(inventoryItemTbl[i] - 1)->field_8 * 2 + 10);
+			item->updateSequence(_vm->getINI(_inventoryItemTbl[i] - 1)->field_8 * 2 + 10);
 			item->setFlag(ACTOR_FLAG_200);
 			item->setFlag(ACTOR_FLAG_100);
 			item->setFlag(ACTOR_FLAG_80);
@@ -259,11 +259,11 @@ void Inventory::draw() {
 
 uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
-		if (inventoryItemTbl[i]) {
+		if (_inventoryItemTbl[i]) {
 			Actor *item = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 			if (item->_x_pos - 0x10 <= x && x < item->_x_pos + 0x10
 				&& item->_y_pos - 0xc <= y && y < item->_y_pos + 0xc) {
-				return inventoryItemTbl[i];
+				return _inventoryItemTbl[i];
 			}
 		}
 	}
@@ -271,27 +271,27 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 }
 
 void Inventory::loadInventoryItemsFromSave() {
-	memset(inventoryItemTbl, 0, sizeof(inventoryItemTbl));
+	memset(_inventoryItemTbl, 0, sizeof(_inventoryItemTbl));
 	int j = 0;
 	for (int i = 0; i < _vm->_dragonINIResource->totalRecords() && j < DRAGONS_MAX_INVENTORY_ITEMS; i++ ) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId == 1) {
-			inventoryItemTbl[j++] = i + 1;
+			_inventoryItemTbl[j++] = i + 1;
 		}
 	}
 }
 
 void Inventory::openInventionBook() {
-	inventionBookPrevSceneUpdateFunc = _vm->getSceneUpdateFunction();
+	_inventionBookPrevSceneUpdateFunc = _vm->getSceneUpdateFunction();
 	_vm->setSceneUpdateFunction(NULL);
 //	fade_related_calls_with_1f();
 	_sequenceId = 2;
 	_actor->updateSequence(2);
-	inventionBookPrevSceneId = _vm->getCurrentSceneId();
+	_inventionBookPrevSceneId = _vm->getCurrentSceneId();
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	if (flicker && flicker->actor) {
-		inventionBookPrevFlickerINISceneId = flicker->sceneId;
-		inventionBookPrevFlickerINIPosition = Common::Point(flicker->actor->_x_pos, flicker->actor->_y_pos);
+		_inventionBookPrevFlickerINISceneId = flicker->sceneId;
+		_inventionBookPrevFlickerINIPosition = Common::Point(flicker->actor->_x_pos, flicker->actor->_y_pos);
 		flicker->sceneId = 0;
 	}
 	_vm->_scene->setSceneId(2);
@@ -306,15 +306,15 @@ void Inventory::closeInventionBook() {
 
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	if (flicker && flicker->actor) {
-		flicker->actor->_x_pos = inventionBookPrevFlickerINIPosition.x;
-		flicker->actor->_y_pos = inventionBookPrevFlickerINIPosition.y;
-		flicker->sceneId = inventionBookPrevFlickerINISceneId;
+		flicker->actor->_x_pos = _inventionBookPrevFlickerINIPosition.x;
+		flicker->actor->_y_pos = _inventionBookPrevFlickerINIPosition.y;
+		flicker->sceneId = _inventionBookPrevFlickerINISceneId;
 	}
-	_vm->_scene->setSceneId(inventionBookPrevSceneId);
+	_vm->_scene->setSceneId(_inventionBookPrevSceneId);
 
 	_sequenceId = 0;
 	setActorSequenceId(0);
-	setPositionFromSceneId(inventionBookPrevSceneId);
+	setPositionFromSceneId(_inventionBookPrevSceneId);
 	uVar2 = _vm->_scene->getSceneId();
 	if (((((uVar2 == 0x23) || (uVar2 == 0x2d)) || (uVar2 == 0x2e)) || ((uVar2 == 0x31 || (uVar2 == 0x32)))) || (uVar2 == 0x28)) {
 		LAB_80038b9c:
@@ -331,7 +331,7 @@ void Inventory::closeInventionBook() {
 	uVar1 = (uint)_vm->_scene->getSceneId();
 	LAB_80038be8:
 	_vm->_scene->loadScene(uVar1,0x1e);
-	_vm->setSceneUpdateFunction(inventionBookPrevSceneUpdateFunc);
+	_vm->setSceneUpdateFunction(_inventionBookPrevSceneUpdateFunc);
 	return;
 }
 
@@ -347,8 +347,8 @@ void Inventory::setPositionFromSceneId(uint32 sceneId) {
 
 bool Inventory::addItem(uint16 initId) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
-		if (inventoryItemTbl[i] == 0) {
-			inventoryItemTbl[i] = initId;
+		if (_inventoryItemTbl[i] == 0) {
+			_inventoryItemTbl[i] = initId;
 			return true;
 		}
 	}
@@ -358,7 +358,7 @@ bool Inventory::addItem(uint16 initId) {
 
 Actor *Inventory::getInventoryItemActor(uint16 iniId) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
-		if (inventoryItemTbl[i] == iniId) {
+		if (_inventoryItemTbl[i] == iniId) {
 			return _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 		}
 	}
@@ -367,8 +367,8 @@ Actor *Inventory::getInventoryItemActor(uint16 iniId) {
 
 void Inventory::replaceItem(uint16 existingIniId, uint16 newIniId) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
-		if (inventoryItemTbl[i] == existingIniId) {
-			inventoryItemTbl[i] = newIniId;
+		if (_inventoryItemTbl[i] == existingIniId) {
+			_inventoryItemTbl[i] = newIniId;
 			return;
 		}
 	}
@@ -381,7 +381,7 @@ bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 			  (x < actor->_x_pos + 0x10)) &&
 			 (actor->_y_pos - 0xc <= y)) &&
 			(y < actor->_y_pos + 0xc)) {
-			inventoryItemTbl[i] = iniId;
+			_inventoryItemTbl[i] = iniId;
 			return true;
 		}
 	}
@@ -390,8 +390,8 @@ bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 
 bool Inventory::clearItem(uint16 iniId) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
-		if (inventoryItemTbl[i] == iniId) {
-			inventoryItemTbl[i] = 0;
+		if (_inventoryItemTbl[i] == iniId) {
+			_inventoryItemTbl[i] = 0;
 		}
 	}
 	return false;
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 31e40fbcda..89d3140935 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -49,12 +49,12 @@ private:
 	int16 _type;
 	Bag *_bag;
 
-	void (*inventionBookPrevSceneUpdateFunc)();
-	uint16 inventionBookPrevSceneId;
-	uint16 inventionBookPrevFlickerINISceneId;
-	Common::Point inventionBookPrevFlickerINIPosition;
+	void (*_inventionBookPrevSceneUpdateFunc)();
+	uint16 _inventionBookPrevSceneId;
+	uint16 _inventionBookPrevFlickerINISceneId;
+	Common::Point _inventionBookPrevFlickerINIPosition;
 
-	uint16 inventoryItemTbl[DRAGONS_MAX_INVENTORY_ITEMS];
+	uint16 _inventoryItemTbl[DRAGONS_MAX_INVENTORY_ITEMS];
 public:
 	Inventory(DragonsEngine *vm);
 
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 95287a9377..dc1b7bbba5 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -33,7 +33,7 @@
 
 namespace Dragons {
 
-Minigame2::Minigame2(DragonsEngine *vm) : _vm(vm), DAT_80093c70(false), DAT_80093c72(false), DAT_80093c74(0), DAT_80093ca8(false) {}
+Minigame2::Minigame2(DragonsEngine *vm) : _vm(vm), _dat_80093c70(false), _dat_80093c72(false), _dat_80093c74(0), _dat_80093ca8(false) {}
 
 static const uint16 unkArray[5] = {
 		0xC, 0xA, 0x8, 0x6, 0x4
@@ -134,25 +134,25 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	if (4 < param_2) {
 		local_2e6 = 4;
 	}
-	DAT_80093ca4 = unkArray[local_2e6];
-	DAT_80093c90 = unkArray[local_2e6];
-	DAT_80093c94 = 0;
+	_dat_80093ca4 = unkArray[local_2e6];
+	_dat_80093c90 = unkArray[local_2e6];
+	_dat_80093c94 = 0;
 	_vm->_inventory->setType(0);
-	DAT_80093cb4 = 2;
-	DAT_80093cbc = 0;
-	DAT_80093cb8 = 2;
-	DAT_80093cc0 = 0;
-	DAT_80093cac = 0;
-	DAT_80093cb0 = false;
-	DAT_80093c9c = 0;
-	_vm->_talk->DAT_8008e874_dialogBox_y2 = 0;
-	_vm->_talk->DAT_8008e844_dialogBox_y1 = 0;
-	_vm->_talk->DAT_8008e848_dialogBox_x2 = 0;
-	_vm->_talk->DAT_8008e7e8_dialogBox_x1 = 0;
-	DAT_80093c98 = DAT_80093c90;
-	DAT_80093ca0 = param_1;
-	DAT_80093cc4 = DAT_80093ca4;
-	DAT_80093cc8 = DAT_80093ca4;
+	_dat_80093cb4 = 2;
+	_dat_80093cbc = 0;
+	_dat_80093cb8 = 2;
+	_dat_80093cc0 = 0;
+	_dat_80093cac = 0;
+	_dat_80093cb0 = false;
+	_dat_80093c9c = 0;
+	_vm->_talk->_dat_8008e874_dialogBox_y2 = 0;
+	_vm->_talk->_dat_8008e844_dialogBox_y1 = 0;
+	_vm->_talk->_dat_8008e848_dialogBox_x2 = 0;
+	_vm->_talk->_dat_8008e7e8_dialogBox_x1 = 0;
+	_dat_80093c98 = _dat_80093c90;
+	_dat_80093ca0 = param_1;
+	_dat_80093cc4 = _dat_80093ca4;
+	_dat_80093cc8 = _dat_80093ca4;
 	//fade_related_calls_with_1f();
 	_vm->reset_screen_maybe();
 	_vm->_inventory->setType(0);
@@ -177,16 +177,16 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	loungealotLeftUpperArm = _vm->_actorManager->loadActor(0xb, 2, 0x7d, 199, 4);
 	uVar8 = _vm->_actorManager->loadActor(0xf,0,0x7d,199,4);
 	loungealotRightArm = _vm->_actorManager->loadActor(0x10, 0, 0x7d, 199, 4);
-	flickerArm = _vm->_actorManager->loadActor(9, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
+	flickerArm = _vm->_actorManager->loadActor(9, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc],
 											   loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e,
 											   loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10, 4);
-	loungealotThumb = _vm->_actorManager->loadActor(0x12, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc],
+	loungealotThumb = _vm->_actorManager->loadActor(0x12, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc],
 													loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e,
 													loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10, 4);
-	uVar12 = _vm->_actorManager->loadActor(10, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
+	uVar12 = _vm->_actorManager->loadActor(10, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0],
 										   flickerArm->_x_pos - flickerArm->_frame->field_e,
 										   flickerArm->_y_pos - flickerArm->_frame->field_10, 4);
-	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0],
+	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0],
 										   flickerArm->_x_pos - flickerArm->_frame->field_e,
 										   flickerArm->_y_pos - flickerArm->_frame->field_10, 4);
 	uVar14 = _vm->_actorManager->loadActor(0x27,0,0x10,0xac,4);
@@ -300,12 +300,12 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		}
 		_vm->waitForFrames(1);
 
-		if ((DAT_80093c9c != 0) && !_vm->isFlagSet(ENGINE_FLAG_8000)) {
+		if ((_dat_80093c9c != 0) && !_vm->isFlagSet(ENGINE_FLAG_8000)) {
 			loungealotHeadActor->updateSequence(0);
-			//TODO _vm->_talk->FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
-			DAT_80093c9c = 0;
+			//TODO _vm->_talk->FUN_8001a7c4((uint)_dat_8008e7e8,(uint)_dat_8008e844,(uint)_dat_8008e848,(uint)_dat_8008e874);
+			_dat_80093c9c = 0;
 		}
-		if (DAT_80093c94 != 0) {
+		if (_dat_80093c94 != 0) {
 			local_264 = 0;
 		}
 		if (uVar8->_field_7a == 1) {
@@ -320,23 +320,23 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			}
 			screenShakeCounter = screenShakeCounter + 1;
 		}
-		if (DAT_80093ca4 == 0) {
-			DAT_80093ca4 = DAT_80093cc8;
+		if (_dat_80093ca4 == 0) {
+			_dat_80093ca4 = _dat_80093cc8;
 		}
 		else {
-			DAT_80093ca4 = DAT_80093ca4 - 1;
+			_dat_80093ca4 = _dat_80093ca4 - 1;
 		}
-		if (DAT_80093c90 == 0) {
-			DAT_80093c90 = DAT_80093c98;
+		if (_dat_80093c90 == 0) {
+			_dat_80093c90 = _dat_80093c98;
 		}
 		else {
-			DAT_80093c90 = DAT_80093c90 - 1;
+			_dat_80093c90 = _dat_80093c90 - 1;
 		}
-		if (DAT_80093cc4 == 0) {
-			DAT_80093cc4 = DAT_80093cc8;
+		if (_dat_80093cc4 == 0) {
+			_dat_80093cc4 = _dat_80093cc8;
 		}
 		else {
-			DAT_80093cc4 = DAT_80093cc4 - 1;
+			_dat_80093cc4 = _dat_80093cc4 - 1;
 		}
 
 		if (local_27a == 0) {
@@ -394,14 +394,14 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		uVar13->_y_pos = sVar3 - flickerArm->_frame->field_10;
 		uVar12->_y_pos = uVar13->_y_pos;
 //		EnableVSyncEvent();
-		local_282 = DAT_80093cc0;
-		local_286 = DAT_80093cbc;
-		local_284 = DAT_80093cb8;
-		local_288 = DAT_80093cb4;
-		if (DAT_80093c94 != 1) {
-			if (DAT_80093c94 < 2) {
-				if (DAT_80093c94 == 0) {
-					if (((local_264 < 300) || (DAT_80093ca0 != 0)) || (DAT_80093cbc == 2)) {
+		local_282 = _dat_80093cc0;
+		local_286 = _dat_80093cbc;
+		local_284 = _dat_80093cb8;
+		local_288 = _dat_80093cb4;
+		if (_dat_80093c94 != 1) {
+			if (_dat_80093c94 < 2) {
+				if (_dat_80093c94 == 0) {
+					if (((local_264 < 300) || (_dat_80093ca0 != 0)) || (_dat_80093cbc == 2)) {
 						if ((local_260 != 0) && (local_260 = local_260 + -1, local_260 == 0)) {
 							if (local_262 != 0) {
 								local_262 = local_262 - 1;
@@ -416,41 +416,41 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						loungealotHeadActor->updateSequence((uint)local_2b0[(uint)local_262 * 2]);
 						uVar18 = (uint)local_262;
 						local_262 = local_262 + 1;
-						FUN_80093aec_dialog(textIdTbl[uVar18],0x14,1);
+						fun_80093aec_dialog(textIdTbl[uVar18],0x14,1);
 						if (local_262 == 3) {
-							while (((DAT_80093cb4 != 2 || (DAT_80093cbc != 0)) ||
-									((DAT_80093cb8 != 2 || (DAT_80093cc0 != 0))))) {
+							while (((_dat_80093cb4 != 2 || (_dat_80093cbc != 0)) ||
+									((_dat_80093cb8 != 2 || (_dat_80093cc0 != 0))))) {
 								_vm->waitForFrames(1);
 								if (flickerArm->isFlagSet(ACTOR_FLAG_4)) {
-									if (DAT_80093cbc != 0) {
-										DAT_80093cbc = DAT_80093cbc - 1;
+									if (_dat_80093cbc != 0) {
+										_dat_80093cbc = _dat_80093cbc - 1;
 									}
-									if (2 < DAT_80093cb4) {
-										DAT_80093cb4 = DAT_80093cb4 - 1;
+									if (2 < _dat_80093cb4) {
+										_dat_80093cb4 = _dat_80093cb4 - 1;
 									}
-									if (DAT_80093cb4 < 2) {
-										DAT_80093cb4 = DAT_80093cb4 + 1;
+									if (_dat_80093cb4 < 2) {
+										_dat_80093cb4 = _dat_80093cb4 + 1;
 									}
 								}
 								if ((uVar12->_flags & 4) != 0) {
-									if (DAT_80093cc0 != 0) {
-										DAT_80093cc0 = DAT_80093cc0 - 1;
+									if (_dat_80093cc0 != 0) {
+										_dat_80093cc0 = _dat_80093cc0 - 1;
 									}
-									if (2 < DAT_80093cb8) {
-										DAT_80093cb8 = DAT_80093cb8 - 1;
+									if (2 < _dat_80093cb8) {
+										_dat_80093cb8 = _dat_80093cb8 - 1;
 									}
-									if (DAT_80093cb8 < 2) {
-										DAT_80093cb8 = DAT_80093cb8 + 1;
+									if (_dat_80093cb8 < 2) {
+										_dat_80093cb8 = _dat_80093cb8 + 1;
 									}
 								}
-								if (flickerArm->_sequenceID != actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]) {
-									flickerArm->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-									loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+								if (flickerArm->_sequenceID != actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc]) {
+									flickerArm->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc]);
+									loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc]);
 								}
 								if (uVar12->_sequenceID !=
-									actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]) {
-									uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
-									uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+									actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0]) {
+									uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0]);
+									uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0]);
 								}
 							}
 							_vm->waitForFrames(2 * 0x3c);
@@ -472,8 +472,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 							_vm->waitForFrames(1);
 							_vm->_screen->loadPalette(0,paletteData);
 							_vm->_screen->loadPalette(1,paletteData);
-//	TODO						FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,
-//										 (uint)DAT_8008e874);
+//	TODO						FUN_8001a7c4((uint)_dat_8008e7e8,(uint)_dat_8008e844,(uint)_dat_8008e848,
+//										 (uint)_dat_8008e874);
 							shouldExit = true;
 							goto LAB_80090188;
 						}
@@ -491,13 +491,13 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					if (_vm->isLeftKeyPressed()) {
 						local_268 = 1;
 					}
-					if (FUN_80093520()) {
+					if (fun_80093520()) {
 						local_268 = local_268 - 1;
 					}
 					if (_vm->isRightKeyPressed()) {
 						local_268 = local_268 + 1;
 					}
-					if (FUN_80093248()) {
+					if (fun_80093248()) {
 						local_268 = local_268 + 1;
 					}
 					if (loungealotLeftUpperArm->_sequenceID != local_268) {
@@ -544,13 +544,13 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						local_264 = 0;
 					}
 					if ((uVar12->_flags & 4) != 0) {
-						if (FUN_80093248() && (local_284 != 0)) {
+						if (fun_80093248() && (local_284 != 0)) {
 							local_284 = local_284 - 1;
 						}
-						if (FUN_80093520() && (local_284 < 4)) {
+						if (fun_80093520() && (local_284 < 4)) {
 							local_284 = local_284 + 1;
 						}
-						if ((!FUN_80093520() && !FUN_80093248()) && (local_284 != 2)) {
+						if ((!fun_80093520() && !fun_80093248()) && (local_284 != 2)) {
 							if (local_284 < 2) {
 								local_284 = local_284 + 1;
 							}
@@ -558,7 +558,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 								local_284 = local_284 - 1;
 							}
 						}
-						if (!FUN_80093800() || (local_26c != 0)) {
+						if (!fun_80093800() || (local_26c != 0)) {
 							if (local_282 != 0) {
 								local_282 = local_282 - 1;
 							}
@@ -570,15 +570,15 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						}
 					}
 					if (((local_286 == 2) && (local_282 == 2)) && (local_288 == local_284)) {
-						if ((DAT_80093cbc == 2) && (DAT_80093cc0 != 2)) {
+						if ((_dat_80093cbc == 2) && (_dat_80093cc0 != 2)) {
 							local_258 = 2;
 						}
 						else {
-							if ((DAT_80093cbc == 2) || (DAT_80093cc0 != 2)) {
-								local_288 = DAT_80093cb4;
-								local_286 = DAT_80093cbc;
-								local_284 = DAT_80093cb8;
-								local_282 = DAT_80093cc0;
+							if ((_dat_80093cbc == 2) || (_dat_80093cc0 != 2)) {
+								local_288 = _dat_80093cb4;
+								local_286 = _dat_80093cbc;
+								local_284 = _dat_80093cb8;
+								local_282 = _dat_80093cc0;
 							}
 							else {
 								local_258 = 1;
@@ -586,17 +586,17 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						}
 					}
 					if (local_258 == 0) {
-						if ((local_286 != DAT_80093cbc) || (local_288 != DAT_80093cb4)) {
-							DAT_80093cb4 = local_288;
-							DAT_80093cbc = local_286;
+						if ((local_286 != _dat_80093cbc) || (local_288 != _dat_80093cb4)) {
+							_dat_80093cb4 = local_288;
+							_dat_80093cbc = local_286;
 							flickerArm->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)local_288 * 3 + (uint)local_286]);
-							loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
+							loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc]);
 						}
-						if ((local_282 != DAT_80093cc0) || (local_284 != DAT_80093cb8)) {
-							DAT_80093cb8 = local_284;
-							DAT_80093cc0 = local_282;
+						if ((local_282 != _dat_80093cc0) || (local_284 != _dat_80093cb8)) {
+							_dat_80093cb8 = local_284;
+							_dat_80093cc0 = local_282;
 							uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)local_284 * 3 + (uint)local_282]);
-							uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
+							uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0]);
 						}
 					}
 					else {
@@ -648,13 +648,13 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						uVar13->_flags = uVar13->_flags | 0x400;
 						flickerArm->updateSequence((uint)local_28 + 0xf);
 						loungealotThumb->updateSequence((uint)local_28 + 0xf);
-						DAT_80093c94 = 1;
-						DAT_80093c90 = 0x1e;
+						_dat_80093c94 = 1;
+						_dat_80093c90 = 0x1e;
 					}
 				}
 			}
 			else {
-				if (DAT_80093c94 == 2) {
+				if (_dat_80093c94 == 2) {
 					uVar12->_flags = uVar12->_flags | 0x1000;
 					uVar13->_flags = uVar13->_flags | 0x1000;
 					flickerArm->_flags = flickerArm->_flags | 0x1000;
@@ -663,7 +663,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					if (local_258 == 1) {
 //						playSoundFromTxtIndex(DAT_80063ad0);
 						loungealotHeadActor->updateSequence(9);
-						FUN_80093aec_dialog(0x46BC,0x14,1);
+						fun_80093aec_dialog(0x46BC,0x14,1);
 						do {
 							_vm->waitForFrames(1);
 						} while (_vm->isFlagSet(ENGINE_FLAG_8000));
@@ -673,7 +673,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					else {
 //						playSoundFromTxtIndex(DAT_80063ad4);
 						loungealotHeadActor->updateSequence(10);
-						FUN_80093aec_dialog(0x4718,0x14,1);
+						fun_80093aec_dialog(0x4718,0x14,1);
 						loungealotRightArm->updateSequence(2);
 						do {
 							_vm->waitForFrames(1);
@@ -705,7 +705,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		if (_vm->isL1ButtonPressed()) { //TODO || _vm->isL2ButtonPressed()) {
 			local_27a = local_27a + 4;
 		}
-		if (FUN_80093990()) {
+		if (fun_80093990()) {
 			if (param_1 == 1) {
 				local_278 = local_278 + 4;
 			}
@@ -713,7 +713,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				local_278 = local_278 + 6;
 			}
 		}
-		if (FUN_80093a30()) {
+		if (fun_80093a30()) {
 			if (param_1 == 1) {
 				local_278 = local_278 + 4;
 			}
@@ -736,29 +736,29 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				if (local_258 == 1) {
 //					playSoundFromTxtIndex(DAT_80063ad8);
 					loungealotHeadActor->updateSequence(0xb);
-					FUN_80093aec_dialog(0x475E,0x14,1);
+					fun_80093aec_dialog(0x475E,0x14,1);
 				}
 				else {
 //					playSoundFromTxtIndex(DAT_80063adc);
 					loungealotHeadActor->updateSequence(0xc);
-					FUN_80093aec_dialog(0x4774,0x14,1);
+					fun_80093aec_dialog(0x4774,0x14,1);
 				}
 				local_258 = 0;
-				DAT_80093cb4 = 2;
-				DAT_80093cbc = 1;
-				DAT_80093cb8 = 0;
-				DAT_80093cc0 = 1;
+				_dat_80093cb4 = 2;
+				_dat_80093cbc = 1;
+				_dat_80093cb8 = 0;
+				_dat_80093cc0 = 1;
 				uVar12->_flags = uVar12->_flags & 0xfbff;
 				uVar13->_flags = uVar13->_flags & 0xfbff;
-				flickerArm->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-				loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb4 * 3 + (uint)DAT_80093cbc]);
-				uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
-				uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)DAT_80093cb8 * 3 + (uint)DAT_80093cc0]);
-				DAT_80093c94 = 0;
+				flickerArm->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc]);
+				loungealotThumb->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc]);
+				uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0]);
+				uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0]);
+				_dat_80093c94 = 0;
 				local_26c = 0x1e;
 			}
 			else {
-				DAT_80093c94 = 2;
+				_dat_80093c94 = 2;
 			}
 		}
 
@@ -766,72 +766,72 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 
 }
 
-void Minigame2::FUN_80093aec_dialog(uint32 textId, int16 x, int16 y) {
+void Minigame2::fun_80093aec_dialog(uint32 textId, int16 x, int16 y) {
 	uint16 auStack4024 [2000];
 //TODO
-//	if ((((DAT_8008e7e8_dialogBox_x1 != 0) || (DAT_8008e848_dialogBox_x2 != 0)) ||
-//		 (DAT_8008e844_dialogBox_y1 != 0)) || (DAT_8008e874_dialogBox_y2 != 0)) {
-//		_vm->_talk->FUN_8001a7c4((uint)DAT_8008e7e8_dialogBox_x1,(uint)DAT_8008e844_dialogBox_y1,
-//					 (uint)DAT_8008e848_dialogBox_x2,(uint)DAT_8008e874_dialogBox_y2);
+//	if ((((_dat_8008e7e8_dialogBox_x1 != 0) || (_dat_8008e848_dialogBox_x2 != 0)) ||
+//		 (_dat_8008e844_dialogBox_y1 != 0)) || (_dat_8008e874_dialogBox_y2 != 0)) {
+//		_vm->_talk->FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1,(uint)_dat_8008e844_dialogBox_y1,
+//					 (uint)_dat_8008e848_dialogBox_x2,(uint)_dat_8008e874_dialogBox_y2);
 //	}
 	_vm->_talk->loadText(textId, auStack4024, 2000);
 	_vm->_talk->displayDialogAroundPoint(auStack4024, x, y, 0, 0, textId);
-	DAT_80093c9c = 1;
+	_dat_80093c9c = 1;
 }
 
-bool Minigame2::FUN_80093520() {
+bool Minigame2::fun_80093520() {
 	bool uVar2;
 
-	if (DAT_80093ca0 == 0) {
-		if (!DAT_80093c70) {
-			if (!DAT_80093c72 || (3 < DAT_80093cb8)) {
-				DAT_80093c72 = false;
-				DAT_80093c74 = DAT_80093c74 + 1;
-				if (DAT_80093c74 < 2) {
-					DAT_80093c70 = true;
-					DAT_80093cac = 0;
+	if (_dat_80093ca0 == 0) {
+		if (!_dat_80093c70) {
+			if (!_dat_80093c72 || (3 < _dat_80093cb8)) {
+				_dat_80093c72 = false;
+				_dat_80093c74 = _dat_80093c74 + 1;
+				if (_dat_80093c74 < 2) {
+					_dat_80093c70 = true;
+					_dat_80093cac = 0;
 					uVar2 = false;
 				}
 				else {
-					if (DAT_80093ca4 == 0) {
-						DAT_80093cac = 0;
-						if (DAT_80093cb8 == DAT_80093cb4) {
-							if (DAT_80093cbc < DAT_80093cc0) {
-								DAT_80093cac = (uint16)(DAT_80093cb8 < 4);
+					if (_dat_80093ca4 == 0) {
+						_dat_80093cac = 0;
+						if (_dat_80093cb8 == _dat_80093cb4) {
+							if (_dat_80093cbc < _dat_80093cc0) {
+								_dat_80093cac = (uint16)(_dat_80093cb8 < 4);
 							}
 							else {
-								if (!DAT_80093cb0 && _vm->getRand(8) < 3) {
+								if (!_dat_80093cb0 && _vm->getRand(8) < 3) {
 									if (_vm->getRand(8) < 3) {
-										DAT_80093c72 = 1;
-										DAT_80093c74 = 0;
-										DAT_80093cac = 1;
+										_dat_80093c72 = 1;
+										_dat_80093c74 = 0;
+										_dat_80093cac = 1;
 									} else {
-										DAT_80093ca4 = DAT_80093cc8 + _vm->getRand(10);
-										DAT_80093cac = 1;
+										_dat_80093ca4 = _dat_80093cc8 + _vm->getRand(10);
+										_dat_80093cac = 1;
 									}
 									return true;
 								}
-								if (DAT_80093cb4 == 4) {
-									DAT_80093cac = 1;
+								if (_dat_80093cb4 == 4) {
+									_dat_80093cac = 1;
 								}
 							}
 						}
 						else {
-							if ((DAT_80093cb8 < DAT_80093cb4) && (DAT_80093cb4 != 2)) {
-								DAT_80093cac = 1;
+							if ((_dat_80093cb8 < _dat_80093cb4) && (_dat_80093cb4 != 2)) {
+								_dat_80093cac = 1;
 							}
 						}
 					}
-					uVar2 = (uint)DAT_80093cac;
+					uVar2 = (uint)_dat_80093cac;
 				}
 			}
 			else {
-				DAT_80093cac = 1;
+				_dat_80093cac = 1;
 				uVar2 = true;
 			}
 		}
 		else {
-			DAT_80093cac = 0;
+			_dat_80093cac = 0;
 			uVar2 = false;
 		}
 	}
@@ -841,60 +841,60 @@ bool Minigame2::FUN_80093520() {
 	return uVar2;
 }
 
-bool Minigame2::FUN_80093248() {
+bool Minigame2::fun_80093248() {
 	bool uVar2;
 
-	if (DAT_80093ca0 == 0) {
-		if (!DAT_80093c72) {
-			if (!DAT_80093c70 || (DAT_80093cb8 == 0)) {
-				DAT_80093c70 = false;
-				DAT_80093c74 = DAT_80093c74 + 1;
-				if (DAT_80093c74 < 2) {
-					DAT_80093c72 = true;
-					DAT_80093cb0 = false;
+	if (_dat_80093ca0 == 0) {
+		if (!_dat_80093c72) {
+			if (!_dat_80093c70 || (_dat_80093cb8 == 0)) {
+				_dat_80093c70 = false;
+				_dat_80093c74 = _dat_80093c74 + 1;
+				if (_dat_80093c74 < 2) {
+					_dat_80093c72 = true;
+					_dat_80093cb0 = false;
 					uVar2 = false;
 				}
 				else {
-					if (DAT_80093ca4 == 0) {
-						DAT_80093cb0 = false;
-						if (DAT_80093cb8 == DAT_80093cb4) {
-							if (DAT_80093cbc < DAT_80093cc0) {
-								DAT_80093cb0 = (bool)(DAT_80093cb8 != 0);
+					if (_dat_80093ca4 == 0) {
+						_dat_80093cb0 = false;
+						if (_dat_80093cb8 == _dat_80093cb4) {
+							if (_dat_80093cbc < _dat_80093cc0) {
+								_dat_80093cb0 = (bool)(_dat_80093cb8 != 0);
 							}
 							else {
-								if ((DAT_80093cac == 0) &&  _vm->getRand(8) < 3) {
+								if ((_dat_80093cac == 0) &&  _vm->getRand(8) < 3) {
 									if (_vm->getRand(8) < 3) {
-										DAT_80093c70 = true;
-										DAT_80093c74 = 0;
-										DAT_80093cb0 = true;
+										_dat_80093c70 = true;
+										_dat_80093c74 = 0;
+										_dat_80093cb0 = true;
 									} else {
-										DAT_80093ca4 = DAT_80093cc8 + _vm->getRand(10);
-										DAT_80093cb0 = true;
+										_dat_80093ca4 = _dat_80093cc8 + _vm->getRand(10);
+										_dat_80093cb0 = true;
 									}
 
 									return true;
 								}
-								if (DAT_80093cb4 == 0) {
-									DAT_80093cb0 = true;
+								if (_dat_80093cb4 == 0) {
+									_dat_80093cb0 = true;
 								}
 							}
 						}
 						else {
-							if ((DAT_80093cb4 < DAT_80093cb8) && (DAT_80093cb4 != 2)) {
-								DAT_80093cb0 = true;
+							if ((_dat_80093cb4 < _dat_80093cb8) && (_dat_80093cb4 != 2)) {
+								_dat_80093cb0 = true;
 							}
 						}
 					}
-					uVar2 = DAT_80093cb0;
+					uVar2 = _dat_80093cb0;
 				}
 			}
 			else {
-				DAT_80093cb0 = true;
+				_dat_80093cb0 = true;
 				uVar2 = true;
 			}
 		}
 		else {
-			DAT_80093cb0 = false;
+			_dat_80093cb0 = false;
 			uVar2 = false;
 		}
 	}
@@ -904,24 +904,24 @@ bool Minigame2::FUN_80093248() {
 	return uVar2;
 }
 
-bool Minigame2::FUN_80093800() {
+bool Minigame2::fun_80093800() {
 	bool uVar2;
 
-	if (DAT_80093ca0 == 0) {
-		if (DAT_80093ca4 == 0) {
-			DAT_80093ca8 = false;
-			if ((DAT_80093cb8 == DAT_80093cb4) && (DAT_80093cc0 < DAT_80093cbc)) {
-				DAT_80093ca8 = true;
+	if (_dat_80093ca0 == 0) {
+		if (_dat_80093ca4 == 0) {
+			_dat_80093ca8 = false;
+			if ((_dat_80093cb8 == _dat_80093cb4) && (_dat_80093cc0 < _dat_80093cbc)) {
+				_dat_80093ca8 = true;
 			}
 			else {
 				if (_vm->getRand(8) < 3) {
-					DAT_80093ca4 = _vm->getRand(10);
-					DAT_80093ca4 = DAT_80093cc8 + DAT_80093ca4;
-					DAT_80093ca8 = true;
+					_dat_80093ca4 = _vm->getRand(10);
+					_dat_80093ca4 = _dat_80093cc8 + _dat_80093ca4;
+					_dat_80093ca8 = true;
 				}
 			}
 		}
-		uVar2 = DAT_80093ca8;
+		uVar2 = _dat_80093ca8;
 	}
 	else {
 		uVar2 = false;
@@ -934,11 +934,11 @@ bool Minigame2::FUN_80093800() {
 	return uVar2;
 }
 
-bool Minigame2::FUN_80093a30() {
+bool Minigame2::fun_80093a30() {
 	bool uVar1;
 
-	if (DAT_80093ca0 == 0) {
-		uVar1 = (uint) DAT_80093c90 == (uint) DAT_80093cc8 / 3;
+	if (_dat_80093ca0 == 0) {
+		uVar1 = (uint) _dat_80093c90 == (uint) _dat_80093cc8 / 3;
 	}
 	else {
 		uVar1 = _vm->isL1ButtonPressed(); // TODO || _vm->isL2ButtonPressed();
@@ -946,11 +946,11 @@ bool Minigame2::FUN_80093a30() {
 	return uVar1;
 }
 
-bool Minigame2::FUN_80093990() {
+bool Minigame2::fun_80093990() {
 	bool uVar1;
 
-	if (DAT_80093ca0 == 0) {
-		uVar1 = DAT_80093c90 == 0;
+	if (_dat_80093ca0 == 0) {
+		uVar1 = _dat_80093c90 == 0;
 	}
 	else {
 		uVar1 = _vm->isR1ButtonPressed(); // TODO || _vm->isR2ButtonPressed();
diff --git a/engines/dragons/minigame2.h b/engines/dragons/minigame2.h
index 62882b7ccc..8ee66f2265 100644
--- a/engines/dragons/minigame2.h
+++ b/engines/dragons/minigame2.h
@@ -31,39 +31,39 @@ class DragonsEngine;
 class Minigame2 {
 private:
 	DragonsEngine *_vm;
-	uint16 DAT_80093cb4;
-	uint16 DAT_80093cbc;
-	uint16 DAT_80093cb8;
-	uint16 DAT_80093cc0;
+	uint16 _dat_80093cb4;
+	uint16 _dat_80093cbc;
+	uint16 _dat_80093cb8;
+	uint16 _dat_80093cc0;
 
-	uint16 DAT_80093ca4;
-	uint16 DAT_80093c90;
-	uint16 DAT_80093c94;
+	uint16 _dat_80093ca4;
+	uint16 _dat_80093c90;
+	uint16 _dat_80093c94;
 
-	uint16 DAT_80093cac;
-	bool DAT_80093cb0;
-	uint16 DAT_80093c9c;
+	uint16 _dat_80093cac;
+	bool _dat_80093cb0;
+	uint16 _dat_80093c9c;
 
-	uint16 DAT_80093c98;
-	uint16 DAT_80093ca0;
-	uint16 DAT_80093cc4;
-	uint16 DAT_80093cc8;
+	uint16 _dat_80093c98;
+	uint16 _dat_80093ca0;
+	uint16 _dat_80093cc4;
+	uint16 _dat_80093cc8;
 
-	bool DAT_80093c70;
-	bool DAT_80093c72;
-	uint16 DAT_80093c74;
-	bool DAT_80093ca8;
+	bool _dat_80093c70;
+	bool _dat_80093c72;
+	uint16 _dat_80093c74;
+	bool _dat_80093ca8;
 public:
 	Minigame2(DragonsEngine *vm);
 
 	void run(int16 param_1, uint16 param_2, int16 param_3);
 private:
-	void FUN_80093aec_dialog(uint32 textId, int16 x, int16 y);
-	bool FUN_80093520();
-	bool FUN_80093a30();
-	bool FUN_80093248();
-	bool FUN_80093800();
-	bool FUN_80093990();
+	void fun_80093aec_dialog(uint32 textId, int16 x, int16 y);
+	bool fun_80093520();
+	bool fun_80093a30();
+	bool fun_80093248();
+	bool fun_80093800();
+	bool fun_80093990();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 5dae9d385d..e4827b7f5d 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -184,7 +184,7 @@ void Minigame3::run() {
 	_vm->_screen->loadPalette(1, _vm->_scene->getPalette());
 	_vm->_screen->loadPalette(4, _vm->_scene->getPalette());
 	_vm->_screen->updatePaletteTransparency(4, 1, 0xff, true);
-	FUN_80017ef0();
+	fun_80017ef0();
 	oldEngineFlags = _vm->getAllFlags();
 	_vm->clearFlags(ENGINE_FLAG_80);
 	_vm->clearFlags(ENGINE_FLAG_20);
@@ -558,7 +558,7 @@ void Minigame3::run() {
 					local_1e0 = 0;
 					local_1de = 0;
 					local_1e8 = 0;
-					FUN_80017f70_paletteRelated(0);
+					fun_80017f70_paletteRelated(0);
 					local_1b8 = 0;
 					flags = (flags & 0xfffd) | 4;
 					local_1c8 = 2;
@@ -615,7 +615,7 @@ void Minigame3::run() {
 		if (((uint)local_210 % 10 == 0) && (0x1d < local_210)) {
 			if ((int16)local_1b8 < 0x1e) {
 				local_1b8 = local_1b8 + 1;
-				FUN_80017f70_paletteRelated((uint)local_1b8);
+				fun_80017f70_paletteRelated((uint)local_1b8);
 			}
 			if (100 < tearBlinkActorTbl[0]->_y_pos) {
 				tearBlinkActorTbl[0]->_y_pos = tearBlinkActorTbl[0]->_y_pos + -3;
@@ -678,7 +678,7 @@ void Minigame3::run() {
 		if ((int16)local_1b8 < 0) {
 			local_1b8 = 0;
 		}
-		FUN_80017f70_paletteRelated((uint)local_1b8);
+		fun_80017f70_paletteRelated((uint)local_1b8);
 		tearBlinkActorTbl[0]->_y_pos = tearBlinkActorTbl[0]->_y_pos + 0x1e;
 		if (199 < tearBlinkActorTbl[0]->_y_pos) {
 			tearBlinkActorTbl[0]->_y_pos = 199;
@@ -753,7 +753,7 @@ void Minigame3::run() {
 	_vm->waitForFrames(0x3c * 2);
 	_vm->_sound->PauseCDMusic();
 //	fade_related_calls_with_1f();
-//	FUN_80017f28_noop();
+//	fun_80017f28_noop();
 //	DAT_80093234 = DAT_80093234 + 1;
 	_vm->_dragonINIResource->setFlickerRecord(flicker);
 	flicker->sceneId = 1;
@@ -774,7 +774,7 @@ void Minigame3::updateBackgroundLayerOffset(uint32 layerNumber, int16 xOffset, i
 	_vm->_scene->setLayerOffset(layerNumber, Common::Point(xOffset, yOffset));
 }
 
-void Minigame3::FUN_80017f70_paletteRelated(uint16 param_1) {
+void Minigame3::fun_80017f70_paletteRelated(uint16 param_1) {
 	if (param_1 > 0x1f) {
 		param_1 = 0x1f;
 	}
@@ -789,10 +789,10 @@ void Minigame3::FUN_80017f70_paletteRelated(uint16 param_1) {
 //	}
 }
 
-void Minigame3::FUN_80017ef0() {
+void Minigame3::fun_80017ef0() {
 	//TODO BgLayerGsSprite[2].attribute = BgLayerGsSprite[2].attribute | 0x50000000;
 	// this sets the FG layer to additive colour blending (100% x Back + 100% x Sprite)
-	FUN_80017f70_paletteRelated(0);
+	fun_80017f70_paletteRelated(0);
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame3.h b/engines/dragons/minigame3.h
index e904426ec5..b0efcd5082 100644
--- a/engines/dragons/minigame3.h
+++ b/engines/dragons/minigame3.h
@@ -35,8 +35,8 @@ public:
 	void run();
 private:
 	void updateBackgroundLayerOffset(uint32 layerNumber, int16 xOffset, int16 yOffset);
-	void FUN_80017f70_paletteRelated(uint16 unk);
-	void FUN_80017ef0();
+	void fun_80017f70_paletteRelated(uint16 unk);
+	void fun_80017ef0();
 
 };
 
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 60db0dbb41..a01d6c31b1 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -65,29 +65,29 @@ void Minigame4::run() {
 	_vm->_videoFlags |= 4;
 	_vm->_scene->setBgLayerPriority(2);
 	_vm->_scene->setMgLayerPriority(1);
-	flickerActor = _vm->_actorManager->loadActor(0x18,0,0xcb,0x79,1);
-	bruteActor = _vm->_actorManager->loadActor(0x17,0,0x68,0x7b,1);
-	ps1ControllerActor = _vm->_actorManager->loadActor(0x17,0x16,0x9f,0x19,1);
-	DAT_80090438 = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
-	DAT_8009043c = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
+	_flickerActor = _vm->_actorManager->loadActor(0x18,0,0xcb,0x79,1);
+	_bruteActor = _vm->_actorManager->loadActor(0x17,0,0x68,0x7b,1);
+	_ps1ControllerActor = _vm->_actorManager->loadActor(0x17,0x16,0x9f,0x19,1);
+	_dat_80090438 = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
+	_dat_8009043c = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
 	//EnableVSyncEvent();
-	flickerActor->setFlag(ACTOR_FLAG_80);
-	flickerActor->setFlag(ACTOR_FLAG_100);
-	flickerActor->setFlag(ACTOR_FLAG_200);
-	flickerActor->_priorityLayer = 3;
-	bruteActor->setFlag(ACTOR_FLAG_80);
-	bruteActor->setFlag(ACTOR_FLAG_100);
-	bruteActor->setFlag(ACTOR_FLAG_200);
-	bruteActor->_priorityLayer = 3;
+	_flickerActor->setFlag(ACTOR_FLAG_80);
+	_flickerActor->setFlag(ACTOR_FLAG_100);
+	_flickerActor->setFlag(ACTOR_FLAG_200);
+	_flickerActor->_priorityLayer = 3;
+	_bruteActor->setFlag(ACTOR_FLAG_80);
+	_bruteActor->setFlag(ACTOR_FLAG_100);
+	_bruteActor->setFlag(ACTOR_FLAG_200);
+	_bruteActor->_priorityLayer = 3;
 	//DAT_800830e0_soundRelated = 0xf;
 	//UnkSoundFunc5(0xf);
 	//call_fade_related_1f();
 	if (_vm->_dragonINIResource->getRecord(0x1f5)->field_12 == 3) {
-		actorTalk(bruteActor,0x3321,0x4A84);
+		actorTalk(_bruteActor,0x3321,0x4A84);
 	}
 	else {
-		actorTalk(bruteActor,0x3321,0x49A2);
-		actorTalk(flickerActor,0,0x4A56);
+		actorTalk(_bruteActor,0x3321,0x49A2);
+		actorTalk(_flickerActor,0,0x4A56);
 	}
 	result = runDanceBattle();
 	/* field_0x12 */
@@ -118,20 +118,20 @@ void Minigame4::run() {
 void Minigame4::actorTalk(Actor *actorId,uint16 param_2,uint32 textIndex)
 {
 	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
-	if (actorId == bruteActor) {
-		bruteActor->updateSequence(9);
+	if (actorId == _bruteActor) {
+		_bruteActor->updateSequence(9);
 	}
 	else {
-		flickerActor->updateSequence(9);
+		_flickerActor->updateSequence(9);
 	}
 
 	actorDialog(actorId, (uint)param_2, textIndex);
 	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
-	if (actorId == bruteActor) {
-		bruteActor->updateSequence(0);
+	if (actorId == _bruteActor) {
+		_bruteActor->updateSequence(0);
 	}
 	else {
-		flickerActor->updateSequence(0);
+		_flickerActor->updateSequence(0);
 	}
 }
 
@@ -180,38 +180,38 @@ uint16 Minigame4::runDanceBattle() {
 	currentStep = 0;
 	while (currentStep < 0xc) {
 		if (singleDanceRound(round1StepPositionTbl[(uint)currentStep], round1DurationTbl[(uint)currentStep])) {
-			actorTalk(bruteActor,0x3321, 0x4D50);
+			actorTalk(_bruteActor,0x3321, 0x4D50);
 			return 1;
 		}
 		currentStep = currentStep + 1;
 	}
 	resetActors();
-	actorTalk(bruteActor,0x3321, 0x4ADE);
+	actorTalk(_bruteActor,0x3321, 0x4ADE);
 	currentStep = 0;
 	while (currentStep < 0xc) {
 		if (singleDanceRound(round2StepPositionTbl[(uint)currentStep], round2DurationTbl[(uint)currentStep])) {
-			actorTalk(bruteActor,0x3321,0x4DD4);
+			actorTalk(_bruteActor,0x3321,0x4DD4);
 			return 1;
 		}
 		currentStep = currentStep + 1;
 	}
 	resetActors();
-	actorTalk(bruteActor,0x3321, 0x4B6A);
+	actorTalk(_bruteActor,0x3321, 0x4B6A);
 	currentStep = 0;
 	while ( true ) {
 		if (0x11 < currentStep) {
 			_vm->_talk->loadText(0x4C0C, auStack2192, 1000);
 			_vm->_talk->displayDialogAroundPoint(auStack2192, 0x27,0xc,0x3321,0,0x4C0C);
 			_vm->waitForFrames(0x10a);
-			bruteActor->updateSequence(8);
+			_bruteActor->updateSequence(8);
 			//TODO
 //			if ((((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0)) || (DAT_8008e844 != 0)) ||
 //				(DAT_8008e874 != 0)) {
 //				FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
 //			}
-			flickerActor->waitUntilFlag8SetThenSet1000AndWaitFor4();
-			flickerActor->updateSequence(7);
-			actorTalk(flickerActor,0, 0x4CC8);
+			_flickerActor->waitUntilFlag8SetThenSet1000AndWaitFor4();
+			_flickerActor->updateSequence(7);
+			actorTalk(_flickerActor,0, 0x4CC8);
 			return 0;
 		}
 
@@ -220,7 +220,7 @@ uint16 Minigame4::runDanceBattle() {
 		}
 		currentStep = currentStep + 1;
 	}
-	actorTalk(bruteActor,0x3321, 0x4DEE);
+	actorTalk(_bruteActor,0x3321, 0x4DEE);
 	return 1;
 }
 
@@ -231,91 +231,91 @@ const static uint16 uint16_t_ARRAY_80090400[6] = { 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
 const static uint16 uint16_t_ARRAY_800903e8[6] = { 1, 2, 3, 4, 5, 6 };
 
 uint16 Minigame4::singleDanceRound(uint16 currentDancePosition, uint16 duration) {
-	DAT_80090438->_x_pos = xDancePosTbl[(uint)currentDancePosition];
-	DAT_80090438->_y_pos = yDancePosTbl[(uint)currentDancePosition];
-	DAT_80090438->updateSequence(10);
-	ps1ControllerActor->updateSequence(uint16_t_ARRAY_80090400[(uint)currentDancePosition]);
-	bruteActor->updateSequence(uint16_t_ARRAY_800903e8[(uint)currentDancePosition]);
-	while ((flickerActor->_sequenceID != uint16_t_ARRAY_800903e8[(uint)currentDancePosition] &&
+	_dat_80090438->_x_pos = xDancePosTbl[(uint)currentDancePosition];
+	_dat_80090438->_y_pos = yDancePosTbl[(uint)currentDancePosition];
+	_dat_80090438->updateSequence(10);
+	_ps1ControllerActor->updateSequence(uint16_t_ARRAY_80090400[(uint)currentDancePosition]);
+	_bruteActor->updateSequence(uint16_t_ARRAY_800903e8[(uint)currentDancePosition]);
+	while ((_flickerActor->_sequenceID != uint16_t_ARRAY_800903e8[(uint)currentDancePosition] &&
 			(duration = duration + -1, duration != 0))) {
 		_vm->waitForFrames(1);
 		updateFlickerFromInput();
 	}
-	if (flickerActor->_sequenceID == uint16_t_ARRAY_800903e8[(uint)currentDancePosition]) {
+	if (_flickerActor->_sequenceID == uint16_t_ARRAY_800903e8[(uint)currentDancePosition]) {
 		while (duration = duration + -1, duration != 0) {
 			_vm->waitForFrames(1);
 		}
-		DAT_80090438->_x_pos = xDancePosTbl[(uint)currentDancePosition];
-		DAT_8009043c->_x_pos = DAT_80090438->_x_pos;
-		DAT_80090438->_y_pos = yDancePosTbl[(uint)currentDancePosition];
-		DAT_8009043c->_y_pos = DAT_80090438->_y_pos;
-		DAT_8009043c->updateSequence(0xb);
-		ps1ControllerActor->updateSequence(0x16);
+		_dat_80090438->_x_pos = xDancePosTbl[(uint)currentDancePosition];
+		_dat_8009043c->_x_pos = _dat_80090438->_x_pos;
+		_dat_80090438->_y_pos = yDancePosTbl[(uint)currentDancePosition];
+		_dat_8009043c->_y_pos = _dat_80090438->_y_pos;
+		_dat_8009043c->updateSequence(0xb);
+		_ps1ControllerActor->updateSequence(0x16);
 		return 0;
 	}
 
-	return FUN_8009009c(1);
+	return fun_8009009c(1);
 }
 
 void Minigame4::resetActors() {
-	bruteActor->waitUntilFlag8SetThenSet1000();
-	flickerActor->waitUntilFlag8SetThenSet1000();
-	while (bruteActor->_sequenceID != 0 || flickerActor->_sequenceID != 0) {
+	_bruteActor->waitUntilFlag8SetThenSet1000();
+	_flickerActor->waitUntilFlag8SetThenSet1000();
+	while (_bruteActor->_sequenceID != 0 || _flickerActor->_sequenceID != 0) {
 		_vm->waitForFrames(1);
-		if (bruteActor->_sequenceID != 0 &&
-			bruteActor->isFlagSet(ACTOR_FLAG_4) &&
-			bruteActor->isFlagSet(ACTOR_FLAG_8)) {
-			bruteActor->updateSequence(0);
+		if (_bruteActor->_sequenceID != 0 &&
+			_bruteActor->isFlagSet(ACTOR_FLAG_4) &&
+			_bruteActor->isFlagSet(ACTOR_FLAG_8)) {
+			_bruteActor->updateSequence(0);
 		}
-		if (flickerActor->_sequenceID != 0 &&
-			flickerActor->isFlagSet(ACTOR_FLAG_4) &&
-			flickerActor->isFlagSet(ACTOR_FLAG_8)) {
-			flickerActor->updateSequence(0);
+		if (_flickerActor->_sequenceID != 0 &&
+			_flickerActor->isFlagSet(ACTOR_FLAG_4) &&
+			_flickerActor->isFlagSet(ACTOR_FLAG_8)) {
+			_flickerActor->updateSequence(0);
 		}
 	}
 }
 
 void Minigame4::updateFlickerFromInput() {
-	if (_vm->isSquareButtonPressed() && flickerActor->_sequenceID != 1) {
-		flickerActor->updateSequence(1);
+	if (_vm->isSquareButtonPressed() && _flickerActor->_sequenceID != 1) {
+		_flickerActor->updateSequence(1);
 	}
 
-	if (_vm->isCrossButtonPressed() && flickerActor->_sequenceID != 2) {
-		flickerActor->updateSequence(2);
+	if (_vm->isCrossButtonPressed() && _flickerActor->_sequenceID != 2) {
+		_flickerActor->updateSequence(2);
 	}
 
-	if (_vm->isCircleButtonPressed() && flickerActor->_sequenceID != 3) {
-		flickerActor->updateSequence(3);
+	if (_vm->isCircleButtonPressed() && _flickerActor->_sequenceID != 3) {
+		_flickerActor->updateSequence(3);
 	}
 
-	if (_vm->isTriangleButtonPressed() && flickerActor->_sequenceID != 4) {
-		flickerActor->updateSequence(4);
+	if (_vm->isTriangleButtonPressed() && _flickerActor->_sequenceID != 4) {
+		_flickerActor->updateSequence(4);
 	}
 
-	if (_vm->isR1ButtonPressed() && flickerActor->_sequenceID != 5) {
-		flickerActor->updateSequence(5);
+	if (_vm->isR1ButtonPressed() && _flickerActor->_sequenceID != 5) {
+		_flickerActor->updateSequence(5);
 	}
 
-	if (_vm->isL1ButtonPressed() && flickerActor->_sequenceID != 6) {
-		flickerActor->updateSequence(6);
+	if (_vm->isL1ButtonPressed() && _flickerActor->_sequenceID != 6) {
+		_flickerActor->updateSequence(6);
 	}
 }
 
-uint16 Minigame4::FUN_8009009c(uint16 unk) {
+uint16 Minigame4::fun_8009009c(uint16 unk) {
 	resetActors();
 	if (unk == 0) {
-		bruteActor->updateSequence(8);
-		flickerActor->updateSequence(7);
+		_bruteActor->updateSequence(8);
+		_flickerActor->updateSequence(7);
 	}
 	else {
-		bruteActor->updateSequence(7);
-		flickerActor->updateSequence(8);
+		_bruteActor->updateSequence(7);
+		_flickerActor->updateSequence(8);
 	}
 	do {
 		do {
-		} while (bruteActor->isFlagSet(ACTOR_FLAG_4));
+		} while (_bruteActor->isFlagSet(ACTOR_FLAG_4));
 
-	} while (flickerActor->isFlagSet(ACTOR_FLAG_4));
+	} while (_flickerActor->isFlagSet(ACTOR_FLAG_4));
 	return (uint)unk;
 }
 
diff --git a/engines/dragons/minigame4.h b/engines/dragons/minigame4.h
index 1b3449a3d0..7e15273adb 100644
--- a/engines/dragons/minigame4.h
+++ b/engines/dragons/minigame4.h
@@ -34,11 +34,11 @@ class Minigame4 {
 private:
 	DragonsEngine *_vm;
 
-	Actor *flickerActor;
-	Actor *bruteActor;
-	Actor *ps1ControllerActor;
-	Actor *DAT_80090438;
-	Actor *DAT_8009043c;
+	Actor *_flickerActor;
+	Actor *_bruteActor;
+	Actor *_ps1ControllerActor;
+	Actor *_dat_80090438;
+	Actor *_dat_8009043c;
 
 
 public:
@@ -54,7 +54,7 @@ private:
 	uint16 singleDanceRound(uint16 desiredPosition, uint16 duration);
 	void resetActors();
 	void updateFlickerFromInput();
-	uint16 FUN_8009009c(uint16 unk);
+	uint16 fun_8009009c(uint16 unk);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index 914d0cb6cf..58cbce647a 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -38,7 +38,7 @@ namespace Dragons {
 #define DAT_8006391c 0x475DA
 
 
-Minigame5::Minigame5(DragonsEngine *vm) : _vm(vm), DAT_800633e6(0) {}
+Minigame5::Minigame5(DragonsEngine *vm) : _vm(vm), _dat_800633e6(0) {}
 
 void Minigame5::run() {
 	uint16 uVar1;
@@ -360,10 +360,10 @@ void Minigame5::run() {
 					pusherActor->updateSequence(9);
 					_vm->waitForFrames(0x3c);
 					pusherActor->updateSequence(0xb);
-					if (DAT_800633e6 == 0) {
+					if (_dat_800633e6 == 0) {
 						_vm->_talk->loadText(DAT_8006393c,auStack2120, 1000);
 						_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1,DAT_8006393c);
-						DAT_800633e6 = 1;
+						_dat_800633e6 = 1;
 					}
 					else {
 						_vm->_talk->loadText(DAT_80063938, auStack2120, 1000);
diff --git a/engines/dragons/minigame5.h b/engines/dragons/minigame5.h
index 8540e0cd32..8bdc86f9bc 100644
--- a/engines/dragons/minigame5.h
+++ b/engines/dragons/minigame5.h
@@ -31,7 +31,7 @@ class DragonsEngine;
 class Minigame5 {
 private:
 	DragonsEngine *_vm;
-	uint16 DAT_800633e6;
+	uint16 _dat_800633e6;
 public:
 	Minigame5(DragonsEngine *vm);
 
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 1f50c2bb05..238f1acc9c 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -38,7 +38,7 @@ namespace Dragons {
 
 Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader)
 		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource), _backgroundLoader(backgroundResourceLoader) {
-	data_80063392 = 2;
+	_data_80063392 = 2;
 	_data_800633ee = 0;
 }
 void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index de56ecd740..7ee95a20ca 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -42,7 +42,7 @@ struct DragonINI;
 class Scene {
 public:
 	Common::Point _camera;
-	int16 data_80063392;
+	int16 _data_80063392;
 
 private:
 	DragonsEngine *_vm;
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 10024e10b2..6e72cb63e5 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -832,7 +832,7 @@ void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
 
 	if (newSceneID != 0) {
 		// load scene here.
-		_vm->_scene->data_80063392 = _vm->_scene->getSceneId();
+		_vm->_scene->_data_80063392 = _vm->_scene->getSceneId();
 		_vm->_scene->setSceneId(newSceneID);
 		_vm->_data_800633fa = field6;
 
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index d74e58e710..940cf4d98a 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -39,6 +39,7 @@ struct ScriptOpCall {
 	byte *_codeEnd;
 	int _field8;
 	int _result;
+
 	ScriptOpCall(byte *start, uint32 length);
 	void skip(uint size);
 	byte readByte();
diff --git a/engines/dragons/sequenceopcodes.h b/engines/dragons/sequenceopcodes.h
index 88b84c4ba1..f072ef6044 100644
--- a/engines/dragons/sequenceopcodes.h
+++ b/engines/dragons/sequenceopcodes.h
@@ -39,6 +39,7 @@ struct OpCall {
 	int32 _deltaOfs;
 	byte *_code;
 	int _result;
+
 	void skip(uint size);
 	byte readByte();
 	int16 readSint16();
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index d144733551..c918baeab5 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -259,7 +259,7 @@ SoundManager::SoundManager(DragonsEngine *vm, BigfileArchive *bigFileArchive, Dr
 		: _vm(vm),
 		  _bigFileArchive(bigFileArchive),
 		  _dragonRMS(dragonRMS) {
-	DAT_8006bb60_sound_related = 0;
+	_dat_8006bb60_sound_related = 0;
 	// TODO: Set volumes
 	SomeInitSound_FUN_8003f64c();
 	loadMusAndGlob();
diff --git a/engines/dragons/sound.h b/engines/dragons/sound.h
index 5d822dcf2c..691bf09282 100644
--- a/engines/dragons/sound.h
+++ b/engines/dragons/sound.h
@@ -59,7 +59,7 @@ public:
 	void PauseCDMusic();
 
 public:
-	uint16 DAT_8006bb60_sound_related;
+	uint16 _dat_8006bb60_sound_related;
 
 private:
 	DragonsEngine *_vm;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 01614b2fd7..a2a86304e6 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -56,8 +56,8 @@ const int16 shakeTbl[16] = {
 
 SpecialOpcodes::SpecialOpcodes(DragonsEngine *vm)
 	: _vm(vm), _specialOpCounter(0) {
-	DAT_80083148 = 0;
-	uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
+	_uint16_t_80083154 = 0;
 	initOpcodes();
 }
 
@@ -324,19 +324,19 @@ void SpecialOpcodes::spcFadeScreen() {
 }
 
 void SpecialOpcodes::spcLadyOfTheLakeCapturedSceneLogic() {
-	DAT_80083148 = 0;
-	uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
+	_uint16_t_80083154 = 0;
 	_vm->setSceneUpdateFunction(ladyOfTheLakeCapturedUpdateFunction);
 }
 
 void SpecialOpcodes::spcStopLadyOfTheLakeCapturedSceneLogic() {
 	_vm->setSceneUpdateFunction(NULL);
 	_vm->_sound->PauseCDMusic();
-	if ((DAT_80083148 != 0) || (uint16_t_80083154 != 0)) {
-		//TODO FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+	if ((_dat_80083148 != 0) || (_uint16_t_80083154 != 0)) {
+		//TODO FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
 	}
-	DAT_80083148 = 0;
-	uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
+	_uint16_t_80083154 = 0;
 }
 
 void SpecialOpcodes::spc11ShakeScreen() {
@@ -540,8 +540,8 @@ void SpecialOpcodes::spcFlickerSetPriority2() {
 
 void SpecialOpcodes::spcMenInMinesSceneLogic() {
 	_vm->setSceneUpdateFunction(menInMinesSceneUpdateFunction);
-	uint16_t_80083154 = 0;
-	DAT_80083148 = 0;
+	_uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
 	setSpecialOpCounter(0);
 }
 
@@ -555,45 +555,45 @@ void SpecialOpcodes::spcStopMenInMinesSceneLogic() {
 			_vm->waitForFrames(1);
 		}
 		//TODO
-		//FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+		//FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
 	}
 }
 
 void SpecialOpcodes::spcMonksAtBarSceneLogic() {
 	setSpecialOpCounter(-1);
 	_vm->setSceneUpdateFunction(monksAtBarSceneUpdateFunction);
-	uint16_t_80083154 = 0;
-	DAT_80083148 = 0;
+	_uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
 }
 
 void SpecialOpcodes::spcStopMonksAtBarSceneLogic() {
 	if (_vm->getSceneUpdateFunction() == monksAtBarSceneUpdateFunction) {
 		_vm->setSceneUpdateFunction(NULL);
-		if ((DAT_80083148 != 0) && (uint16_t_80083154 != 0)) {
-			//TODO FUN_8001ac5c((uint)DAT_80083148, (uint)DAT_80083150, (uint)uint16_t_80083154, (uint)DAT_80083158);
+		if ((_dat_80083148 != 0) && (_uint16_t_80083154 != 0)) {
+			//TODO FUN_8001ac5c((uint)_dat_80083148, (uint)DAT_80083150, (uint)_uint16_t_80083154, (uint)DAT_80083158);
 		}
 		setSpecialOpCounter(0);
-		uint16_t_80083154 = 0;
-		DAT_80083148 = 0;
+		_uint16_t_80083154 = 0;
+		_dat_80083148 = 0;
 	}
 
 }
 
 void SpecialOpcodes::spcFlameBedroomEscapeSceneLogic() {
 	setSpecialOpCounter(-1);
-	if ((DAT_80083148 != 0) && (uint16_t_80083154 != 0)) {
-		//TODO FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+	if ((_dat_80083148 != 0) && (_uint16_t_80083154 != 0)) {
+		//TODO FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
 	}
 	_vm->setSceneUpdateFunction(flameEscapeSceneUpdateFunction);
-	uint16_t_80083154 = 0;
-	DAT_80083148 = 0;
+	_uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
 }
 
 void SpecialOpcodes::spcStopFlameBedroomEscapeSceneLogic() {
 	setSpecialOpCounter(0);
-//	TODO FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
-	uint16_t_80083154 = 0;
-	DAT_80083148 = 0;
+//	TODO FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
+	_uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
 	_vm->_dragonINIResource->getRecord(0x96)->actor->updateSequence(0);
 	if (_vm->getSceneUpdateFunction() == flameEscapeSceneUpdateFunction) {
 		_vm->setSceneUpdateFunction(NULL);
@@ -615,12 +615,12 @@ void SpecialOpcodes::spcCastleMoatUpdateActorSceneScalePoints() {
 
 void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
 	setSpecialOpCounter(-1);
-	if ((DAT_80083148 != 0) && (uint16_t_80083154 != 0)) {
-		//TODO FUN_8001ac5c((uint)DAT_80083148,(uint)DAT_80083150,(uint)uint16_t_80083154,(uint)DAT_80083158);
+	if ((_dat_80083148 != 0) && (_uint16_t_80083154 != 0)) {
+		//TODO FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
 	}
 	_vm->setSceneUpdateFunction(moatDrainedSceneUpdateFunction);
-	uint16_t_80083154 = 0;
-	DAT_80083148 = 0;
+	_uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
 }
 void SpecialOpcodes::spcUnk34() {
 	Actor *flicker = _vm->_dragonINIResource->getFlickerRecord()->actor;
@@ -1265,8 +1265,8 @@ void SpecialOpcodes::pizzaMakerStopWorking() {
 }
 
 void SpecialOpcodes::clearSceneUpdateFunction() {
-	if (DAT_80083148 != uint16_t_80083154) {
-		//TODO FUN_8001ac5c((uint)DAT_80083148, (uint)DAT_80083150, (uint)uint16_t_80083154, (uint)DAT_80083158);
+	if (_dat_80083148 != _uint16_t_80083154) {
+		//TODO FUN_8001ac5c((uint)_dat_80083148, (uint)DAT_80083150, (uint)_uint16_t_80083154, (uint)DAT_80083158);
 	}
 	if (sceneUpdater.sequenceID != -1) {
 		_vm->getINI(sceneUpdater.iniID)->actor->updateSequence(sceneUpdater.sequenceID);
@@ -1277,8 +1277,8 @@ void SpecialOpcodes::clearSceneUpdateFunction() {
 void SpecialOpcodes::setupTableBasedSceneUpdateFunction(uint16 initialCounter, uint16 numSequences,
 														uint16 sequenceDuration) {
 	sceneUpdater.sequenceID = -1;
-	uint16_t_80083154 = 0;
-	DAT_80083148 = 0;
+	_uint16_t_80083154 = 0;
+	_dat_80083148 = 0;
 //TODO
 //	DAT_80072858 = 0;
 	sceneUpdater.curSequenceIndex = 0;
diff --git a/engines/dragons/specialopcodes.h b/engines/dragons/specialopcodes.h
index ec025894bb..e879ae18ed 100644
--- a/engines/dragons/specialopcodes.h
+++ b/engines/dragons/specialopcodes.h
@@ -61,8 +61,8 @@ protected:
 	SpecialOpcode *_opcodes[DRAGONS_NUM_SPECIAL_OPCODES];
 	Common::String _opcodeNames[DRAGONS_NUM_SPECIAL_OPCODES];
 	int16 _specialOpCounter;
-	uint8 DAT_80083148;
-	uint16 uint16_t_80083154;
+	uint8 _dat_80083148;
+	uint16 _uint16_t_80083154;
 
 public:
 	int16 getSpecialOpCounter();
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index ce8f5e8c40..21e3bf81ff 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -38,14 +38,14 @@
 namespace Dragons {
 
 Talk::Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive): _vm(vm), _bigfileArchive(bigfileArchive) {
-	DAT_800726ec_tfont_field0 = 1; //TODO source from font file
-	DAT_800726f0_tfont_field2 = 1; // TODO source from font file
+	_dat_800726ec_tfont_field0 = 1; //TODO source from font file
+	_dat_800726f0_tfont_field2 = 1; // TODO source from font file
 }
 
 void Talk::init() {
-	memset(defaultResponseTbl, 0, sizeof(defaultResponseTbl));
+	memset(_defaultResponseTbl, 0, sizeof(_defaultResponseTbl));
 	initDefaultResponseTable();
-	DAT_800633f8_talkDialogFlag = 0;
+	_dat_800633f8_talkDialogFlag = 0;
 }
 
 bool Talk::loadText(uint32 textIndex, uint16 *textBuffer, uint16 bufferLength) {
@@ -162,9 +162,9 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 //			puVar17[3] = uVar15;
 //			puVar1 = puVar16 + 4;
 //			puVar2 = puVar17 + 4;
-//		} while (puVar16 + 4 != (uint32 *)&DAT_80011a80);
+//		} while (puVar16 + 4 != (uint32 *)&_dat_80011a80);
 //		uVar12 = puVar16[5];
-//		puVar17[4] = _DAT_80011a80;
+//		puVar17[4] = __dat_80011a80;
 //		puVar17[5] = uVar12;
 		if (param_5 != 0) {
 			_vm->clearFlags(ENGINE_FLAG_8);
@@ -200,13 +200,13 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 			local_58 = 0x27 - x;
 		}
 		iVar5 = ((int)((uint)local_58 << 0x10) >> 0xf) + 2;
-//		if (DAT_800726ec_tfont_field0 == 0) {
+//		if (_dat_800726ec_tfont_field0 == 0) {
 //			trap(0x1c00);
 //		}
-//		if (((uint)DAT_800726ec_tfont_field0 == 0xffffffff) && (iVar5 == -0x80000000)) {
+//		if (((uint)_dat_800726ec_tfont_field0 == 0xffffffff) && (iVar5 == -0x80000000)) {
 //			trap(0x1800);
 //		}
-		sVar3 = (short)(iVar5 / (int)(uint)DAT_800726ec_tfont_field0);
+		sVar3 = (short)(iVar5 / (int)(uint)_dat_800726ec_tfont_field0);
 		if (*dialogText != 0) {
 			/* check for space or hyphen */
 			curDialogTextPtr = dialogText;
@@ -335,7 +335,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 					puVar18 = curDialogTextPtr;
 				}
 				LAB_80032a70:
-				iVar5 = (iVar5 >> 0x10) * (uint)DAT_800726f0_tfont_field2 + -1;
+				iVar5 = (iVar5 >> 0x10) * (uint)_dat_800726f0_tfont_field2 + -1;
 				uVar19 = y;
 				if ((int)(short)y < iVar5) {
 					uVar19 = (uint16)iVar5;
@@ -343,39 +343,39 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 				if (0x16 < (short)uVar19) {
 					uVar19 = 0x16;
 				}
-				uVar11 = sVar20 * DAT_800726ec_tfont_field0 + 3 & 0xfffe;
+				uVar11 = sVar20 * _dat_800726ec_tfont_field0 + 3 & 0xfffe;
 				sVar20 = (short)uVar11 >> 1;
 				if ((short)x < 0x14) {
-					DAT_8008e7e8_dialogBox_x1 = (x - sVar20) + 1;
+					_dat_8008e7e8_dialogBox_x1 = (x - sVar20) + 1;
 				}
 				else {
-					DAT_8008e7e8_dialogBox_x1 = x - sVar20;
+					_dat_8008e7e8_dialogBox_x1 = x - sVar20;
 				}
-				DAT_8008e848_dialogBox_x2 = (uVar11 + DAT_8008e7e8_dialogBox_x1) - 1;
-				DAT_8008e844_dialogBox_y1 = (uVar19 - sVar4 * DAT_800726f0_tfont_field2) + 1;
-				DAT_8008e874_dialogBox_y2 = DAT_8008e844_dialogBox_y1 + sVar4 * DAT_800726f0_tfont_field2 + 1;
+				_dat_8008e848_dialogBox_x2 = (uVar11 + _dat_8008e7e8_dialogBox_x1) - 1;
+				_dat_8008e844_dialogBox_y1 = (uVar19 - sVar4 * _dat_800726f0_tfont_field2) + 1;
+				_dat_8008e874_dialogBox_y2 = _dat_8008e844_dialogBox_y1 + sVar4 * _dat_800726f0_tfont_field2 + 1;
 				if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) && ((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)))) {
 					unaff_s4 = 0;
-					FUN_8001a4e4_draw_dialogbox((uint) DAT_8008e7e8_dialogBox_x1, (uint) DAT_8008e844_dialogBox_y1,
-												(uint) DAT_8008e848_dialogBox_x2, (uint) DAT_8008e874_dialogBox_y2, 0);
+					FUN_8001a4e4_draw_dialogbox((uint) _dat_8008e7e8_dialogBox_x1, (uint) _dat_8008e844_dialogBox_y1,
+												(uint) _dat_8008e848_dialogBox_x2, (uint) _dat_8008e874_dialogBox_y2, 0);
 					if (sVar4 > 0) {
 						for (; unaff_s4 < sVar4; unaff_s4++) {
 							if ((short)x < 0x14) {
 								dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
 								uVar9 = strlenUTF16(dialogTextLinePtr);
-								uVar9 = ((uint)x - ((int)((uint)DAT_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1)) + 1;
+								uVar9 = ((uint)x - ((int)((uint)_dat_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1)) + 1;
 							}
 							else {
 								dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
 								uVar9 = strlenUTF16(dialogTextLinePtr);
-								uVar9 = (uint)x - ((int)((uint)DAT_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1);
+								uVar9 = (uint)x - ((int)((uint)_dat_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1);
 							}
 							_vm->_fontManager->addText(uVar9 * 8,
-													   ((uint)DAT_8008e844_dialogBox_y1 + unaff_s4 * (uint)DAT_800726f0_tfont_field2 + 1) * 8,
+													   ((uint)_dat_8008e844_dialogBox_y1 + unaff_s4 * (uint)_dat_800726f0_tfont_field2 + 1) * 8,
 									dialogTextLinePtr, wideStrLen(dialogTextLinePtr), 0);
 //							ProbablyShowUTF16Msg3
 //									(dialogTextLinePtr,uVar9 & 0xffff,
-//									 (uint)DAT_8008e844_dialogBox_y1 + iVar5 * (uint)DAT_800726f0_tfont_field2 + 1
+//									 (uint)_dat_8008e844_dialogBox_y1 + iVar5 * (uint)_dat_800726f0_tfont_field2 + 1
 //									 & 0xffff,(uint)param_4, 0xffffffff);
 						}
 					}
@@ -392,8 +392,8 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 					curDialogTextPtr = puVar18;
 					if (!_vm->isFlagSet(ENGINE_FLAG_8000)) goto LAB_80032e18;
 					_vm->waitForFrames(1);
-					if (_vm->_sound->DAT_8006bb60_sound_related != 0) {
-						_vm->_sound->DAT_8006bb60_sound_related = 0;
+					if (_vm->_sound->_dat_8006bb60_sound_related != 0) {
+						_vm->_sound->_dat_8006bb60_sound_related = 0;
 						curDialogTextPtr = dialogText;
 						if (!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED)) {
 							returnStatus = 1;
@@ -416,8 +416,8 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 				LAB_80032e18:
 				//TODO CheckIfCdShellIsOpen();
 				if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
-					FUN_8001a7c4((uint)DAT_8008e7e8_dialogBox_x1,(uint)DAT_8008e844_dialogBox_y1,
-								 (uint)DAT_8008e848_dialogBox_x2,(uint)DAT_8008e874_dialogBox_y2);
+					FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1,(uint)_dat_8008e844_dialogBox_y1,
+								 (uint)_dat_8008e848_dialogBox_x2,(uint)_dat_8008e874_dialogBox_y2);
 				}
 			} while (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) &&
 					 (((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)) && (*curDialogTextPtr != 0))));
@@ -476,7 +476,7 @@ void
 Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId) {
 // TODO
 //
-//		puVar1 = &DAT_80011a60;
+//		puVar1 = &_dat_80011a60;
 //		puVar2 = local_58;
 //		do {
 //			puVar8 = puVar2;
@@ -490,9 +490,9 @@ Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 pa
 //			puVar8[3] = uVar6;
 //			puVar1 = puVar7 + 4;
 //			puVar2 = puVar8 + 4;
-//		} while (puVar7 + 4 != (undefined4 *)&DAT_80011a80);
+//		} while (puVar7 + 4 != (undefined4 *)&_dat_80011a80);
 //		uVar4 = puVar7[5];
-//		puVar8[4] = _DAT_80011a80;
+//		puVar8[4] = __dat_80011a80;
 //		puVar8[5] = uVar4;
 		_vm->_data_800633fc = 1;
 
@@ -667,7 +667,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 	uint16 *local_40;
 	uint local_38;
 	bool hasDialogEntries;
-	uint16 *DAT_80083104;
+	uint16 *_dat_80083104;
 
 	talkDialogEntry = NULL;
 	for (int i = 0; i < 0x24; i++) {
@@ -688,12 +688,12 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 				talkDialogEntry->yPosMaybe = '\0';
 				strcpy((char *)&local_390,(char *)talkDialogEntry->dialogText);
 				UTF16ToUTF16Z(local_386, (uint16 *)(&talkDialogEntry->dialogText[10]));
-				DAT_80083104 = local_386;
+				_dat_80083104 = local_386;
 				if (*local_386 == 0x20) {
-					DAT_80083104 = &local_386[1];
+					_dat_80083104 = &local_386[1];
 				}
-				uVar3 = FindLastPositionOf5cChar(DAT_80083104);
-				sVar2 = FUN_80031c28(DAT_80083104,asStack512,uVar3 & 0xffff,0x20);
+				uVar3 = FindLastPositionOf5cChar(_dat_80083104);
+				sVar2 = FUN_80031c28(_dat_80083104,asStack512,uVar3 & 0xffff,0x20);
 				talkDialogEntry->xPosMaybe = (uint8)local_58;
 				local_58 = local_58 + sVar2;
 				talkDialogEntry->yPosMaybe = talkDialogEntry->yPosMaybe + (char)sVar2;
@@ -707,7 +707,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 	_vm->_cursor->updateSequenceID(3);
 	local_50 = -2;
 	local_38 = (uint)numEntries;
-	DAT_800633f8_talkDialogFlag = 1;
+	_dat_800633f8_talkDialogFlag = 1;
 	hasDialogEntries = (numEntries != 0);
 	local_40 = asStack512;
 	LAB_800317a4:
@@ -744,7 +744,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 					y = y + 1;
 					if ((talkDialogEntry->flags & 1) == 0) {
 						if (uVar8 == 0) {
-							DAT_800633f8_talkDialogFlag = 0;
+							_dat_800633f8_talkDialogFlag = 0;
 							return talkDialogEntry;
 						}
 						uVar8--;
@@ -777,13 +777,13 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 					sVar2 = local_50 + 1;
 					local_50 = sVar2;
 					UTF16ToUTF16Z(local_386, (uint16 *)(&talkDialogEntry->dialogText[10]));
-					DAT_80083104 = local_386;
+					_dat_80083104 = local_386;
 					if (local_386[0] == 0x20) {
-						DAT_80083104 = &local_386[1];
+						_dat_80083104 = &local_386[1];
 					}
-					uVar4 = FindLastPositionOf5cChar(DAT_80083104);
-					uVar4 = FUN_80031c28(DAT_80083104,local_40,uVar4 & 0xffff,0x20);
-					DAT_80083104 = local_40;
+					uVar4 = FindLastPositionOf5cChar(_dat_80083104);
+					uVar4 = FUN_80031c28(_dat_80083104,local_40,uVar4 & 0xffff,0x20);
+					_dat_80083104 = local_40;
 					if ((int)sVar2 == (uint)uVar8) {
 						uVar7 = 0;
 						if (uVar6 < (uVar4 & 0xffff)) {
@@ -792,15 +792,15 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 								if ((uVar7 & 0xffff) == 0) {
 									x = 4;
 								}
-								//TODO ProbablyShowUTF16Msg(DAT_80083104,x,y,0,-1);
-								_vm->_fontManager->addText(x * 8, y * 8, DAT_80083104, wideStrLen(DAT_80083104), 0);
-								sVar2 = *DAT_80083104;
+								//TODO ProbablyShowUTF16Msg(_dat_80083104,x,y,0,-1);
+								_vm->_fontManager->addText(x * 8, y * 8, _dat_80083104, wideStrLen(_dat_80083104), 0);
+								sVar2 = *_dat_80083104;
 								while (sVar2 != 0) {
-									sVar2 = DAT_80083104[1];
-									DAT_80083104 = DAT_80083104 + 1;
+									sVar2 = _dat_80083104[1];
+									_dat_80083104 = _dat_80083104 + 1;
 								}
 								uVar7 = uVar7 + 1;
-								DAT_80083104 = DAT_80083104 + 1;
+								_dat_80083104 = _dat_80083104 + 1;
 								y = y + 1;
 							} while ((uVar7 & 0xffff) < (uVar4 & 0xffff));
 						}
@@ -813,15 +813,15 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 								if ((uVar7 & 0xffff) == 0) {
 									x = 4;
 								}
-								//TODO ProbablyShowUTF16Msg2(DAT_80083104,x,(uint)y,0x401,0xffffffff);
-								_vm->_fontManager->addText(x * 8, y * 8, DAT_80083104, wideStrLen(DAT_80083104), 1);
-								sVar2 = *DAT_80083104;
+								//TODO ProbablyShowUTF16Msg2(_dat_80083104,x,(uint)y,0x401,0xffffffff);
+								_vm->_fontManager->addText(x * 8, y * 8, _dat_80083104, wideStrLen(_dat_80083104), 1);
+								sVar2 = *_dat_80083104;
 								while (sVar2 != 0) {
-									sVar2 = DAT_80083104[1];
-									DAT_80083104 = DAT_80083104 + 1;
+									sVar2 = _dat_80083104[1];
+									_dat_80083104 = _dat_80083104 + 1;
 								}
 								uVar7 = uVar7 + 1;
-								DAT_80083104 = DAT_80083104 + 1;
+								_dat_80083104 = _dat_80083104 + 1;
 								y = y + 1;
 							} while ((uVar7 & 0xffff) < (uVar4 & 0xffff));
 						}
@@ -938,7 +938,7 @@ void Talk::flickerRandomDefaultResponse() {
 
 uint32 Talk::getDefaultResponseTextIndex() {
 	uint16 rand = _vm->getRand(9);
-	return defaultResponseTbl[(_vm->_cursor->_data_800728b0_cursor_seqID - 1) * 9 + rand];
+	return _defaultResponseTbl[(_vm->_cursor->_data_800728b0_cursor_seqID - 1) * 9 + rand];
 }
 
 uint32 extractTextIndex(Common::File *fd, uint16 offset) {
@@ -952,55 +952,55 @@ void Talk::initDefaultResponseTable() {
 		error("Failed to open dragon.exe");
 	}
 
-	defaultResponseTbl[0] = extractTextIndex(fd, 19);
-	defaultResponseTbl[1] = extractTextIndex(fd, 20);
-	defaultResponseTbl[2] = extractTextIndex(fd, 21);
-	defaultResponseTbl[3] = extractTextIndex(fd, 22);
-	defaultResponseTbl[4] = extractTextIndex(fd, 19);
-	defaultResponseTbl[5] = extractTextIndex(fd, 20);
-	defaultResponseTbl[6] = extractTextIndex(fd, 21);
-	defaultResponseTbl[7] = extractTextIndex(fd, 22);
-	defaultResponseTbl[8] = extractTextIndex(fd, 19);
-
-	defaultResponseTbl[9] = extractTextIndex(fd, 0);
-	defaultResponseTbl[10] = extractTextIndex(fd, 1);
-	defaultResponseTbl[11] = extractTextIndex(fd, 2);
-	defaultResponseTbl[12] = extractTextIndex(fd, 3);
-	defaultResponseTbl[13] = extractTextIndex(fd, 4);
-	defaultResponseTbl[14] = extractTextIndex(fd, 5);
-	defaultResponseTbl[15] = extractTextIndex(fd, 2);
-	defaultResponseTbl[16] = extractTextIndex(fd, 3);
-	defaultResponseTbl[17] = extractTextIndex(fd, 4);
-
-	defaultResponseTbl[18] = extractTextIndex(fd, 6);
-	defaultResponseTbl[19] = extractTextIndex(fd, 7);
-	defaultResponseTbl[20] = extractTextIndex(fd, 8);
-	defaultResponseTbl[21] = extractTextIndex(fd, 9);
-	defaultResponseTbl[22] = extractTextIndex(fd, 7);
-	defaultResponseTbl[23] = extractTextIndex(fd, 8);
-	defaultResponseTbl[24] = extractTextIndex(fd, 9);
-	defaultResponseTbl[25] = extractTextIndex(fd, 6);
-	defaultResponseTbl[26] = extractTextIndex(fd, 7);
-
-	defaultResponseTbl[27] = extractTextIndex(fd, 10);
-	defaultResponseTbl[28] = extractTextIndex(fd, 11);
-	defaultResponseTbl[29] = extractTextIndex(fd, 12);
-	defaultResponseTbl[30] = extractTextIndex(fd, 13);
-	defaultResponseTbl[31] = extractTextIndex(fd, 14);
-	defaultResponseTbl[32] = extractTextIndex(fd, 15);
-	defaultResponseTbl[33] = extractTextIndex(fd, 16);
-	defaultResponseTbl[34] = extractTextIndex(fd, 17);
-	defaultResponseTbl[35] = extractTextIndex(fd, 18);
-
-	defaultResponseTbl[36] = extractTextIndex(fd, 23);
-	defaultResponseTbl[37] = extractTextIndex(fd, 24);
-	defaultResponseTbl[38] = extractTextIndex(fd, 25);
-	defaultResponseTbl[39] = extractTextIndex(fd, 26);
-	defaultResponseTbl[40] = extractTextIndex(fd, 27);
-	defaultResponseTbl[41] = extractTextIndex(fd, 28);
-	defaultResponseTbl[42] = extractTextIndex(fd, 29);
-	defaultResponseTbl[43] = extractTextIndex(fd, 30);
-	defaultResponseTbl[44] = extractTextIndex(fd, 31);
+	_defaultResponseTbl[0] = extractTextIndex(fd, 19);
+	_defaultResponseTbl[1] = extractTextIndex(fd, 20);
+	_defaultResponseTbl[2] = extractTextIndex(fd, 21);
+	_defaultResponseTbl[3] = extractTextIndex(fd, 22);
+	_defaultResponseTbl[4] = extractTextIndex(fd, 19);
+	_defaultResponseTbl[5] = extractTextIndex(fd, 20);
+	_defaultResponseTbl[6] = extractTextIndex(fd, 21);
+	_defaultResponseTbl[7] = extractTextIndex(fd, 22);
+	_defaultResponseTbl[8] = extractTextIndex(fd, 19);
+
+	_defaultResponseTbl[9] = extractTextIndex(fd, 0);
+	_defaultResponseTbl[10] = extractTextIndex(fd, 1);
+	_defaultResponseTbl[11] = extractTextIndex(fd, 2);
+	_defaultResponseTbl[12] = extractTextIndex(fd, 3);
+	_defaultResponseTbl[13] = extractTextIndex(fd, 4);
+	_defaultResponseTbl[14] = extractTextIndex(fd, 5);
+	_defaultResponseTbl[15] = extractTextIndex(fd, 2);
+	_defaultResponseTbl[16] = extractTextIndex(fd, 3);
+	_defaultResponseTbl[17] = extractTextIndex(fd, 4);
+
+	_defaultResponseTbl[18] = extractTextIndex(fd, 6);
+	_defaultResponseTbl[19] = extractTextIndex(fd, 7);
+	_defaultResponseTbl[20] = extractTextIndex(fd, 8);
+	_defaultResponseTbl[21] = extractTextIndex(fd, 9);
+	_defaultResponseTbl[22] = extractTextIndex(fd, 7);
+	_defaultResponseTbl[23] = extractTextIndex(fd, 8);
+	_defaultResponseTbl[24] = extractTextIndex(fd, 9);
+	_defaultResponseTbl[25] = extractTextIndex(fd, 6);
+	_defaultResponseTbl[26] = extractTextIndex(fd, 7);
+
+	_defaultResponseTbl[27] = extractTextIndex(fd, 10);
+	_defaultResponseTbl[28] = extractTextIndex(fd, 11);
+	_defaultResponseTbl[29] = extractTextIndex(fd, 12);
+	_defaultResponseTbl[30] = extractTextIndex(fd, 13);
+	_defaultResponseTbl[31] = extractTextIndex(fd, 14);
+	_defaultResponseTbl[32] = extractTextIndex(fd, 15);
+	_defaultResponseTbl[33] = extractTextIndex(fd, 16);
+	_defaultResponseTbl[34] = extractTextIndex(fd, 17);
+	_defaultResponseTbl[35] = extractTextIndex(fd, 18);
+
+	_defaultResponseTbl[36] = extractTextIndex(fd, 23);
+	_defaultResponseTbl[37] = extractTextIndex(fd, 24);
+	_defaultResponseTbl[38] = extractTextIndex(fd, 25);
+	_defaultResponseTbl[39] = extractTextIndex(fd, 26);
+	_defaultResponseTbl[40] = extractTextIndex(fd, 27);
+	_defaultResponseTbl[41] = extractTextIndex(fd, 28);
+	_defaultResponseTbl[42] = extractTextIndex(fd, 29);
+	_defaultResponseTbl[43] = extractTextIndex(fd, 30);
+	_defaultResponseTbl[44] = extractTextIndex(fd, 31);
 
 	fd->close();
 	delete fd;
@@ -1123,8 +1123,8 @@ void Talk::clearDialogEntries() {
 }
 
 void Talk::FUN_8001a7c4_clearDialogBoxMaybe() {
-	FUN_8001a7c4((uint)DAT_8008e7e8_dialogBox_x1,(uint)DAT_8008e844_dialogBox_y1,
-			(uint)DAT_8008e848_dialogBox_x2,(uint)DAT_8008e874_dialogBox_y2);
+	FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1,(uint)_dat_8008e844_dialogBox_y1,
+			(uint)_dat_8008e848_dialogBox_x2,(uint)_dat_8008e874_dialogBox_y2);
 }
 
 void Talk::playDialogAudioDontWait(uint32 textIndex) {
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 5e12c025d7..16f3ea4098 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -49,20 +49,20 @@ struct TalkDialogEntry {
 
 class Talk {
 public:
-	uint32 DAT_8008e7e8_dialogBox_x1;
-	uint32 DAT_8008e844_dialogBox_y1;
-	uint32 DAT_8008e848_dialogBox_x2;
-	uint32 DAT_8008e874_dialogBox_y2;
+	uint32 _dat_8008e7e8_dialogBox_x1;
+	uint32 _dat_8008e844_dialogBox_y1;
+	uint32 _dat_8008e848_dialogBox_x2;
+	uint32 _dat_8008e874_dialogBox_y2;
 private:
 	DragonsEngine *_vm;
 	BigfileArchive *_bigfileArchive;
 	Common::Array<TalkDialogEntry*> _dialogEntries;
-	uint32 defaultResponseTbl[45];
+	uint32 _defaultResponseTbl[45];
 
-	uint8 DAT_800726ec_tfont_field0;
-	uint8 DAT_800726f0_tfont_field2;
+	uint8 _dat_800726ec_tfont_field0;
+	uint8 _dat_800726f0_tfont_field2;
 
-	uint8 DAT_800633f8_talkDialogFlag;
+	uint8 _dat_800633f8_talkDialogFlag;
 
 public:
 	Talk(DragonsEngine *vm, BigfileArchive *bigfileArchive);
@@ -91,6 +91,7 @@ public:
 	void FUN_8001a7c4_clearDialogBoxMaybe(); //clear box maybe?
 
 	void playDialogAudioDontWait(uint32 textIndex);
+
 private:
 	void FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2); //clear box maybe?
 	void copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength);


Commit: 36008ba9e90c13b91423733ca3f16a9ca6254832
    https://github.com/scummvm/scummvm/commit/36008ba9e90c13b91423733ca3f16a9ca6254832
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Whitespace fixes

Changed paths:
    engines/dragons/bigfile.cpp
    engines/dragons/bigfile.h
    engines/dragons/credits.cpp
    engines/dragons/credits.h
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/cutscene.cpp
    engines/dragons/cutscene.h
    engines/dragons/detection.cpp
    engines/dragons/dragonflg.cpp
    engines/dragons/dragonflg.h
    engines/dragons/dragonimg.h


diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
index 396eea30a7..5c0f6e9f15 100644
--- a/engines/dragons/bigfile.cpp
+++ b/engines/dragons/bigfile.cpp
@@ -31,582 +31,582 @@ typedef struct FileInfo {
 #define TOTAL_FILES 576
 //TODO add support for other game types. get data directly from DRAGON.EXE
 FileInfo fileInfo[TOTAL_FILES] = {
-		{"loadpic.tim", 0x0, 0x1F414},
-		{"fntfiles.dat", 0x1F800, 0x6E44},
-		{"tfont.map", 0x26800, 0xC6A},
-		{"tfont.chr", 0x27800, 0x16C0},
-		{"tfont1.map", 0x29000, 0xC6A},
-		{"tfont1.chr", 0x2A000, 0x16C0},
-		{"sfont.map", 0x2B800, 0xC6A},
-		{"sfont.chr", 0x2C800, 0x16C0},
-		{"boxfont.chr", 0x2E000, 0x4C0},
-		{"bag.scr", 0x2E800, 0xA2E4},
-		{"igfiles.dat", 0x39000, 0x29208},
-		{"dragon.flg", 0x62800, 0x24},
-		{"dragon.var", 0x63000, 0x1E},
-		{"dragon.ini", 0x63800, 0x6028},
-		{"dragon.img", 0x6A000, 0x441C},
-		{"dragon.opt", 0x6E800, 0x16A0},
-		{"dragon.ipt", 0x70000, 0x5D8},
-		{"dragon.rms", 0x70800, 0x63C},
-		{"dragon.obd", 0x71000, 0x1C9DC},
-		{"dragon.txt", 0x8E000, 0x4E8A4},
-		{"dragon.spt", 0xDD000, 0xD0},
-		{"musx.vh", 0xDD800, 0x2E20},
-		{"musx.vb", 0xE0800, 0x402A0},
-		{"glob.vh", 0x121000, 0xC20},
-		{"glob.vb", 0x122000, 0xBB90},
-		{"glob.vab", 0x12E000, 0xC7B0},
-		{"cursor.act", 0x13A800, 0x1863C},
-		{"invenicn.act", 0x153000, 0x3D3C},
-		{"shadow.act", 0x157000, 0x508},
-		{"flicker.act", 0x157800, 0x3CDF0},
-		{"flickert.act", 0x194800, 0x1A4A0},
-		{"flkg.act", 0x1AF000, 0x4D298},
-		{"flkspec.act", 0x1FC800, 0xE008},
-		{"credits.txt", 0x20B000, 0x249A},
-		{"titles.act", 0x20D800, 0x15214},
-		{"drag0000.txt", 0x223000, 0x1000},
-		{"drag0001.txt", 0x224000, 0x1000},
-		{"drag0002.txt", 0x225000, 0x1000},
-		{"drag0003.txt", 0x226000, 0x1000},
-		{"drag0004.txt", 0x227000, 0x1000},
-		{"drag0005.txt", 0x228000, 0x1000},
-		{"drag0006.txt", 0x229000, 0x1000},
-		{"drag0007.txt", 0x22A000, 0x1000},
-		{"drag0008.txt", 0x22B000, 0x1000},
-		{"drag0009.txt", 0x22C000, 0x1000},
-		{"drag0010.txt", 0x22D000, 0x1000},
-		{"drag0011.txt", 0x22E000, 0x1000},
-		{"drag0012.txt", 0x22F000, 0x1000},
-		{"drag0013.txt", 0x230000, 0x1000},
-		{"drag0014.txt", 0x231000, 0x1000},
-		{"drag0015.txt", 0x232000, 0x1000},
-		{"drag0016.txt", 0x233000, 0x1000},
-		{"drag0017.txt", 0x234000, 0x1000},
-		{"drag0018.txt", 0x235000, 0x1000},
-		{"drag0019.txt", 0x236000, 0x1000},
-		{"drag0020.txt", 0x237000, 0x1000},
-		{"drag0021.txt", 0x238000, 0x1000},
-		{"drag0022.txt", 0x239000, 0x1000},
-		{"drag0023.txt", 0x23A000, 0x1000},
-		{"drag0024.txt", 0x23B000, 0x1000},
-		{"drag0025.txt", 0x23C000, 0x1000},
-		{"drag0026.txt", 0x23D000, 0x1000},
-		{"drag0027.txt", 0x23E000, 0x1000},
-		{"drag0028.txt", 0x23F000, 0x1000},
-		{"drag0029.txt", 0x240000, 0x1000},
-		{"drag0030.txt", 0x241000, 0x1000},
-		{"drag0031.txt", 0x242000, 0x1000},
-		{"drag0032.txt", 0x243000, 0x1000},
-		{"drag0033.txt", 0x244000, 0x1000},
-		{"drag0034.txt", 0x245000, 0x1000},
-		{"drag0035.txt", 0x246000, 0x1000},
-		{"drag0036.txt", 0x247000, 0x1000},
-		{"drag0037.txt", 0x248000, 0x1000},
-		{"drag0038.txt", 0x249000, 0x1000},
-		{"drag0039.txt", 0x24A000, 0x1000},
-		{"drag0040.txt", 0x24B000, 0x1000},
-		{"drag0041.txt", 0x24C000, 0x1000},
-		{"drag0042.txt", 0x24D000, 0x1000},
-		{"drag0043.txt", 0x24E000, 0x1000},
-		{"drag0044.txt", 0x24F000, 0x1000},
-		{"drag0045.txt", 0x250000, 0x1000},
-		{"drag0046.txt", 0x251000, 0x1000},
-		{"drag0047.txt", 0x252000, 0x1000},
-		{"drag0048.txt", 0x253000, 0x1000},
-		{"drag0049.txt", 0x254000, 0x1000},
-		{"drag0050.txt", 0x255000, 0x1000},
-		{"drag0051.txt", 0x256000, 0x1000},
-		{"drag0052.txt", 0x257000, 0x1000},
-		{"drag0053.txt", 0x258000, 0x1000},
-		{"drag0054.txt", 0x259000, 0x1000},
-		{"drag0055.txt", 0x25A000, 0x1000},
-		{"drag0056.txt", 0x25B000, 0x1000},
-		{"drag0057.txt", 0x25C000, 0x1000},
-		{"drag0058.txt", 0x25D000, 0x1000},
-		{"drag0059.txt", 0x25E000, 0x1000},
-		{"drag0060.txt", 0x25F000, 0x1000},
-		{"drag0061.txt", 0x260000, 0x1000},
-		{"drag0062.txt", 0x261000, 0x1000},
-		{"drag0063.txt", 0x262000, 0x1000},
-		{"drag0064.txt", 0x263000, 0x1000},
-		{"drag0065.txt", 0x264000, 0x1000},
-		{"drag0066.txt", 0x265000, 0x1000},
-		{"drag0067.txt", 0x266000, 0x1000},
-		{"drag0068.txt", 0x267000, 0x1000},
-		{"drag0069.txt", 0x268000, 0x1000},
-		{"drag0070.txt", 0x269000, 0x1000},
-		{"drag0071.txt", 0x26A000, 0x1000},
-		{"drag0072.txt", 0x26B000, 0x1000},
-		{"drag0073.txt", 0x26C000, 0x1000},
-		{"drag0074.txt", 0x26D000, 0x1000},
-		{"drag0075.txt", 0x26E000, 0x1000},
-		{"drag0076.txt", 0x26F000, 0x1000},
-		{"drag0077.txt", 0x270000, 0x1000},
-		{"drag0078.txt", 0x271000, 0x1000},
-		{"drag0079.txt", 0x272000, 0x1000},
-		{"drag0080.txt", 0x273000, 0x1000},
-		{"dem1.msf", 0x274000, 0x128C0},
-		{"dem1.scr", 0x287000, 0x1934C},
-		{"dem11.act", 0x2A0800, 0x573FC},
-		{"dem1z15.msq", 0x2F8000, 0x3A03},
-		{"dem2.msf", 0x2FC000, 0x23C50},
-		{"dem2.scr", 0x320000, 0x160F4},
-		{"dem2z10.msq", 0x336800, 0x192B},
-		{"dem2z13.msq", 0x338800, 0x3D20},
-		{"demoz00.msq", 0x33C800, 0x1D7A},
-		{"demoz01.msq", 0x33E800, 0x136D},
-		{"demoz02.msq", 0x340000, 0x2F1D},
-		{"demoz03.msq", 0x343000, 0x246A},
-		{"demoz04.msq", 0x345800, 0xFA1},
-		{"demoz05.msq", 0x346800, 0x61C},
-		{"demoz06.msq", 0x347000, 0x3A4B},
-		{"demoz07.msq", 0x34B000, 0x3909},
-		{"demoz08.msq", 0x34F000, 0x25B8},
-		{"demoz09.msq", 0x351800, 0x673F},
-		{"demoz10.msq", 0x358000, 0x192B},
-		{"demoz11.msq", 0x35A000, 0x2A5A},
-		{"demoz12.msq", 0x35D000, 0xE7B},
-		{"demoz13.msq", 0x35E000, 0x3D20},
-		{"demoz14.msq", 0x362000, 0x1B9B},
-		{"demoz15.msq", 0x364000, 0x3A03},
-		{"demoz16.msq", 0x368000, 0x2B6B},
-		{"demoz17.msq", 0x36B000, 0x1D7A},
-		{"demoz18.msq", 0x36D000, 0x33FE},
-		{"demoz19.msq", 0x370800, 0x20D7},
-		{"demoz20.msq", 0x373000, 0x673F},
-		{"demoz21.msq", 0x379800, 0x2EA7},
-		{"demoz22.msq", 0x37C800, 0x286C},
-		{"demoz23.msq", 0x37F800, 0x246A},
-		{"demoz24.msq", 0x382000, 0x2463},
-		{"demoz25.msq", 0x384800, 0x245B},
-		{"demoz26.msq", 0x387000, 0x2AE},
-		{"demoz27.msq", 0x387800, 0xB6E},
-		{"demoz99.msq", 0x388800, 0x2EA7},
-		{"s00b.msf", 0x38B800, 0x1CD0},
-		{"s00b.scr", 0x38D800, 0xEF4},
-		{"s00b1.act", 0x38E800, 0x3DE24},
-		{"s00bz00.msq", 0x3CC800, 0x1D7A},
-		{"s00f.msf", 0x3CE800, 0x158D0},
-		{"s00f.scr", 0x3E4800, 0x138F4},
-		{"s00f1.act", 0x3F8800, 0x2CBB0},
-		{"s00f2.act", 0x425800, 0x16738},
-		{"s00f3.act", 0x43C000, 0x32C78},
-		{"s00f4.act", 0x46F000, 0xB78},
-		{"s00fz01.msq", 0x470000, 0x136D},
-		{"s00g.msf", 0x471800, 0x3840},
-		{"s00g.scr", 0x475800, 0x106F4},
-		{"s00g1.act", 0x486000, 0xAA50},
-		{"s00g2.act", 0x491000, 0x4DDC},
-		{"s00g3.act", 0x496000, 0x1944},
-		{"s00gz00.msq", 0x498000, 0x1D7A},
-		{"s00h.msf", 0x49A000, 0x4FB0},
-		{"s00h.scr", 0x49F000, 0x17AF4},
-		{"s00h1.act", 0x4B7000, 0x34D94},
-		{"s00h2.act", 0x4EC000, 0x1BF4C},
-		{"s00h3.act", 0x508000, 0xA92C},
-		{"s00h4.act", 0x513000, 0x3F58},
-		{"s00h5.act", 0x517000, 0xC850},
-		{"s00h6.act", 0x524000, 0x32174},
-		{"s00h7.act", 0x556800, 0x3BC4},
-		{"s00h8.act", 0x55A800, 0x2D78},
-		{"s00h9.act", 0x55D800, 0x28B0},
-		{"s00ha.act", 0x560800, 0x6F0},
-		{"s00hz10.msq", 0x561000, 0x192B},
-		{"s00i.msf", 0x563000, 0x4A20},
-		{"s00i.scr", 0x568000, 0x61EA0},
-		{"s00i1.act", 0x5CA000, 0x4708},
-		{"s00i2.act", 0x5CE800, 0x32B4},
-		{"s00i3.act", 0x5D2000, 0x2530},
-		{"s00i4.act", 0x5D4800, 0x222C},
-		{"s00iz06.msq", 0x5D7000, 0x3A4B},
-		{"s00j.msf", 0x5DB000, 0x1D2A0},
-		{"s00j.scr", 0x5F8800, 0x1934C},
-		{"s00j1.act", 0x612000, 0x50914},
-		{"s00j2.act", 0x663000, 0x43FCC},
-		{"s00jz15.msq", 0x6A7000, 0x3A03},
-		{"s00k.msf", 0x6AB000, 0x144F0},
-		{"s00k.scr", 0x6BF800, 0x200F4},
-		{"s00kz21.msq", 0x6E0000, 0x2EA7},
-		{"s00l.scr", 0x6E3000, 0xBDF4},
-		{"s00lz16.msq", 0x6EF000, 0x2B6B},
-		{"s00lz21.msq", 0x6F2000, 0x2EA7},
-		{"s01a.msf", 0x6F5000, 0x10590},
-		{"s01a.scr", 0x705800, 0x1B0F4},
-		{"s01a1.act", 0x721000, 0xFBF0},
-		{"s01a2.act", 0x731000, 0x591C},
-		{"s01az00.msq", 0x737000, 0x1D7A},
-		{"s01az08.msq", 0x739000, 0x25B8},
-		{"s01az17.msq", 0x73B800, 0x1D7A},
-		{"s01b.msf", 0x73D800, 0xCDF0},
-		{"s01b.scr", 0x74A800, 0x1DAF4},
-		{"s01b1.act", 0x768800, 0xAF78},
-		{"s01b2.act", 0x773800, 0xAA8},
-		{"s01bz00.msq", 0x774800, 0x1D7A},
-		{"s01c.msf", 0x776800, 0x7D70},
-		{"s01c.scr", 0x77E800, 0x1CCF4},
-		{"s01c1.act", 0x79B800, 0x76CBC},
-		{"s01c2.act", 0x812800, 0x4D0},
-		{"s01c3.act", 0x813000, 0xEE4},
-		{"s01cz01.msq", 0x814000, 0x136D},
-		{"s01d.msf", 0x815800, 0xE740},
-		{"s01d.scr", 0x824000, 0x5E0AC},
-		{"s01d1.act", 0x882800, 0x90A2C},
-		{"s01d2.act", 0x913800, 0x11AB4},
-		{"s01d3.act", 0x925800, 0x20FD8},
-		{"s01d4.act", 0x946800, 0x17D2C},
-		{"s01d5.act", 0x95E800, 0x1BAF4},
-		{"s01d7.act", 0x97A800, 0x6A974},
-		{"s01d8.act", 0x9E5800, 0x2852C},
-		{"s01d9.act", 0xA0E000, 0x958C},
-		{"s01d20.act", 0xA17800, 0x1B9D8},
-		{"s01d21.act", 0xA33800, 0x1D460},
-		{"s01d22.act", 0xA51000, 0x287C8},
-		{"s01d23.act", 0xA79800, 0x16734},
-		{"s01d24.act", 0xA90000, 0x138A8},
-		{"s01d25.act", 0xAA4000, 0x1A290},
-		{"s01da.act", 0xABE800, 0x702C},
-		{"s01dz00.msq", 0xAC6000, 0x1D7A},
-		{"s01dz17.msq", 0xAC8000, 0x1D7A},
-		{"s01e.scr", 0xACA000, 0x189F4},
-		{"s01e1.act", 0xAE3000, 0x7004},
-		{"s01ez00.msq", 0xAEA800, 0x1D7A},
-		{"s01f.msf", 0xAEC800, 0x11210},
-		{"s01f.scr", 0xAFE000, 0x195F4},
-		{"s01f1.act", 0xB17800, 0x33868},
-		{"s01f2.act", 0xB4B800, 0x734C},
-		{"s01fz00.msq", 0xB53000, 0x1D7A},
-		{"s01fz03.msq", 0xB55000, 0x246A},
-		{"s01fz06.msq", 0xB57800, 0x3A4B},
-		{"s01fz23.msq", 0xB5B800, 0x246A},
-		{"s01g.msf", 0xB5E000, 0x1E010},
-		{"s01g.scr", 0xB7C800, 0x1BBF4},
-		{"s01g1.act", 0xB98800, 0xD30},
-		{"s01g2.act", 0xB99800, 0x18794},
-		{"s01g3.act", 0xBB2000, 0x38FC},
-		{"s01g4.act", 0xBB6000, 0x39784},
-		{"s01g5.act", 0xBEF800, 0x20694},
-		{"s01g6.act", 0xC10000, 0x10A18},
-		{"s01g7.act", 0xC21000, 0x13AD4},
-		{"s01g8.act", 0xC35000, 0x1A750},
-		{"s01g9.act", 0xC4F800, 0x12958},
-		{"s01gz00.msq", 0xC62800, 0x1D7A},
-		{"s01gz01.msq", 0xC64800, 0x136D},
-		{"s01gz08.msq", 0xC66000, 0x25B8},
-		{"s01h.msf", 0xC68800, 0xFBF0},
-		{"s01h.scr", 0xC78800, 0x10CF4},
-		{"s01h1.act", 0xC89800, 0x5E5A8},
-		{"s01h2.act", 0xCE8000, 0x52FC0},
-		{"s01h3.act", 0xD3B000, 0x2CC68},
-		{"s01h4.act", 0xD68000, 0xC3CC},
-		{"s01h5.act", 0xD74800, 0x8D8},
-		{"s01h6.act", 0xD75800, 0x1A044},
-		{"s01hz00.msq", 0xD90000, 0x1D7A},
-		{"s01hz01.msq", 0xD92000, 0x136D},
-		{"s01i.msf", 0xD93800, 0x3840},
-		{"s01i.scr", 0xD97800, 0x25FDC},
-		{"s01i1.act", 0xDBD800, 0x19CF0},
-		{"s01i2.act", 0xDD7800, 0x514},
-		{"s01i3.act", 0xDD8000, 0x3BC8},
-		{"s01iz00.msq", 0xDDC000, 0x1D7A},
-		{"s01j.msf", 0xDDE000, 0xBBA0},
-		{"s01j.scr", 0xDEA000, 0x15BF4},
-		{"s01j0.act", 0xE00000, 0x245B8},
-		{"s01j1.act", 0xE24800, 0x8A34},
-		{"s01j2.act", 0xE2D800, 0x3C0A0},
-		{"s01j3.act", 0xE6A000, 0x2944},
-		{"s01jz00.msq", 0xE6D000, 0x1D7A},
-		{"s01k.msf", 0xE6F000, 0x12FA0},
-		{"s01k.scr", 0xE82000, 0x189F4},
-		{"s01k1.act", 0xE9B000, 0x4394},
-		{"s01k2.act", 0xE9F800, 0x75068},
-		{"s01k3.act", 0xF15000, 0x9A0},
-		{"s01kz00.msq", 0xF16000, 0x1D7A},
-		{"s01l.msf", 0xF18000, 0x9A70},
-		{"s01l.scr", 0xF22000, 0x12BF4},
-		{"s01l1.act", 0xF35000, 0x1CDC},
-		{"s01lz00.msq", 0xF37000, 0x1D7A},
-		{"s02a.msf", 0xF39000, 0x11240},
-		{"s02a.scr", 0xF4A800, 0x197F4},
-		{"s02a1.act", 0xF64000, 0x17110},
-		{"s02a2.act", 0xF7B800, 0x13EB4},
-		{"s02a3.act", 0xF8F800, 0x8D20},
-		{"s02a4.act", 0xF98800, 0x36F8},
-		{"s02a5.act", 0xF9C000, 0x22F58},
-		{"s02a6.act", 0xFBF000, 0xE3C},
-		{"s02az02.msq", 0xFC0000, 0x2F1D},
-		{"s02az11.msq", 0xFC3000, 0x2A5A},
-		{"s02b.msf", 0xFC6000, 0x170D0},
-		{"s02b.scr", 0xFDD800, 0x14EF4},
-		{"s02b1.act", 0xFF2800, 0x49F08},
-		{"s02b2.act", 0x103C800, 0xDE78},
-		{"s02b3.act", 0x104A800, 0x3768},
-		{"s02bz02.msq", 0x104E000, 0x2F1D},
-		{"s02bz11.msq", 0x1051000, 0x2A5A},
-		{"s02bz13.msq", 0x1054000, 0x3D20},
-		{"s02bz20.msq", 0x1058000, 0x673F},
-		{"s02c.msf", 0x105E800, 0x20240},
-		{"s02c.scr", 0x107F000, 0x277F4},
-		{"s02c1.act", 0x10A6800, 0x30448},
-		{"s02c2.act", 0x10D7000, 0x15828},
-		{"s02c3.act", 0x10ED000, 0x1708C},
-		{"s02c4.act", 0x1104800, 0x12D1C},
-		{"s02c5.act", 0x1117800, 0x39970},
-		{"s02c6.act", 0x1151800, 0x1B114},
-		{"s02c7.act", 0x116D000, 0x5F7C},
-		{"s02c8.act", 0x1173000, 0x82368},
-		{"s02c9.act", 0x11F5800, 0x3D02C},
-		{"s02c11.act", 0x1233000, 0x2A934},
-		{"s02c51.act", 0x125E000, 0x3004},
-		{"s02ca.act", 0x1261800, 0x7F0D0},
-		{"s02cb.act", 0x12E1000, 0x125A8},
-		{"s02cc.act", 0x12F3800, 0x4150},
-		{"s02cz11.msq", 0x12F8000, 0x2A5A},
-		{"s02cz12.msq", 0x12FB000, 0xE7B},
-		{"s02cz13.msq", 0x12FC000, 0x3D20},
-		{"s02cz20.msq", 0x1300000, 0x673F},
-		{"s02d.msf", 0x1306800, 0x21940},
-		{"s02d.scr", 0x1328800, 0x160F4},
-		{"s02d1.act", 0x133F000, 0x2E09C},
-		{"s02d2.act", 0x136D800, 0x26D74},
-		{"s02d3.act", 0x1394800, 0x14EA0},
-		{"s02d4.act", 0x13A9800, 0x2294},
-		{"s02d5.act", 0x13AC000, 0x4A48},
-		{"s02dz10.msq", 0x13B1000, 0x192B},
-		{"s02dz13.msq", 0x13B3000, 0x3D20},
-		{"s02e.msf", 0x13B7000, 0x5EB0},
-		{"s02e.scr", 0x13BD000, 0x107F4},
-		{"s02e1.act", 0x13CD800, 0x62BC8},
-		{"s02ez18.msq", 0x1430800, 0x33FE},
-		{"s03a.msf", 0x1434000, 0x12070},
-		{"s03a.scr", 0x1446800, 0x18BF4},
-		{"s03a1.act", 0x145F800, 0x49E0},
-		{"s03a2.act", 0x1464800, 0x3DF4},
-		{"s03a3.act", 0x1468800, 0x45774},
-		{"s03a4.act", 0x14AE000, 0x23D4},
-		{"s03a5.act", 0x14B0800, 0x13E64},
-		{"s03a6.act", 0x14C4800, 0x46BC},
-		{"s03az03.msq", 0x14C9000, 0x246A},
-		{"s03az06.msq", 0x14CB800, 0x3A4B},
-		{"s03az23.msq", 0x14CF800, 0x246A},
-		{"s04a.msf", 0x14D2000, 0x11D60},
-		{"s04a.scr", 0x14E4000, 0x12AF4},
-		{"s04a1.act", 0x14F7000, 0x2AC40},
-		{"s04a2.act", 0x1522000, 0x6544},
-		{"s04a3.act", 0x1528800, 0x46C8},
-		{"s04a4.act", 0x152D000, 0x2240},
-		{"s04az03.msq", 0x152F800, 0x246A},
-		{"s04az10.msq", 0x1532000, 0x192B},
-		{"s04az24.msq", 0x1534000, 0x2463},
-		{"s05a.msf", 0x1536800, 0x5D60},
-		{"s05a.scr", 0x153C800, 0x127F4},
-		{"s05a1.act", 0x154F000, 0x3E1CC},
-		{"s05az04.msq", 0x158D800, 0xFA1},
-		{"s05b.msf", 0x158E800, 0x28640},
-		{"s05b.scr", 0x15B7000, 0x2C3C4},
-		{"s05b0.act", 0x15E3800, 0x16474},
-		{"s05b1.act", 0x15FA000, 0x1F2F4},
-		{"s05b2.act", 0x1619800, 0x113E8},
-		{"s05b3.act", 0x162B000, 0x1D424},
-		{"s05b4.act", 0x1648800, 0x501C4},
-		{"s05b5.act", 0x1699000, 0x1F510},
-		{"s05b6.act", 0x16B8800, 0x8860},
-		{"s05bz05.msq", 0x16C1800, 0x61C},
-		{"s05bz06.msq", 0x16C2000, 0x3A4B},
-		{"s05bz07.msq", 0x16C6000, 0x3909},
-		{"s06a.msf", 0x16CA000, 0x1C750},
-		{"s06a.scr", 0x16E6800, 0x151F4},
-		{"s06a1.act", 0x16FC000, 0x24654},
-		{"s06a2.act", 0x1720800, 0x25D0},
-		{"s06az19.msq", 0x1723000, 0x20D7},
-		{"s06b.msf", 0x1725800, 0x1BF60},
-		{"s06b.scr", 0x1741800, 0x182F4},
-		{"s06b1.act", 0x175A000, 0x6CE68},
-		{"s06bz19.msq", 0x17C7000, 0x20D7},
-		{"s07a.msf", 0x17C9800, 0x15240},
-		{"s07a.scr", 0x17DF000, 0x1ACF4},
-		{"s07a1.act", 0x17FA000, 0xE5A0},
-		{"s07a2.act", 0x1808800, 0x425D0},
-		{"s07a3.act", 0x184B000, 0x18810},
-		{"s07az03.msq", 0x1864000, 0x246A},
-		{"s07az08.msq", 0x1866800, 0x25B8},
-		{"s07az25.msq", 0x1869000, 0x245B},
-		{"s07b.msf", 0x186B800, 0x14960},
-		{"s07b.scr", 0x1880800, 0x15CF4},
-		{"s07b1.act", 0x1896800, 0x419C8},
-		{"s07b2.act", 0x18D8800, 0x1A560},
-		{"s07b3.act", 0x18F3000, 0x76F4},
-		{"s07b4.act", 0x18FA800, 0x76C8},
-		{"s07bz03.msq", 0x1902000, 0x246A},
-		{"s07bz08.msq", 0x1904800, 0x25B8},
-		{"s07bz25.msq", 0x1907000, 0x245B},
-		{"s07c.scr", 0x1909800, 0x143F4},
-		{"s07c1.act", 0x191E000, 0xA25C},
-		{"s08a.msf", 0x1928800, 0xB9E0},
-		{"s08a.scr", 0x1934800, 0x322F4},
-		{"s08a1.act", 0x1967000, 0xA668},
-		{"s08a2.act", 0x1971800, 0x2C828},
-		{"s08a3.act", 0x199E800, 0x6CF0},
-		{"s08az03.msq", 0x19A5800, 0x246A},
-		{"s08az06.msq", 0x19A8000, 0x3A4B},
-		{"s08az23.msq", 0x19AC000, 0x246A},
-		{"s08b.scr", 0x19AE800, 0x399F4},
-		{"s08b1.act", 0x19E8800, 0x1F0A0},
-		{"s08bz03.msq", 0x1A08000, 0x246A},
-		{"s08bz06.msq", 0x1A0A800, 0x3A4B},
-		{"s08bz23.msq", 0x1A0E800, 0x246A},
-		{"s09a.msf", 0x1A11000, 0x14190},
-		{"s09a.scr", 0x1A25800, 0x1B4F4},
-		{"s09a1.act", 0x1A41000, 0x634B8},
-		{"s09az14.msq", 0x1AA4800, 0x1B9B},
-		{"s09b.msf", 0x1AA6800, 0x1F2E0},
-		{"s09b.scr", 0x1AC6000, 0x1B4F4},
-		{"s09b1.act", 0x1AE1800, 0x71B8},
-		{"s09b2.act", 0x1AE9000, 0x2299C},
-		{"s09b3.act", 0x1B0C000, 0x1B360},
-		{"s09b4.act", 0x1B27800, 0x14B64},
-		{"s09b5.act", 0x1B3C800, 0x5E4},
-		{"s09b6.act", 0x1B3D000, 0xAA78},
-		{"s09b7.act", 0x1B48000, 0x9B24},
-		{"s09bz14.msq", 0x1B52000, 0x1B9B},
-		{"s09bz15.msq", 0x1B54000, 0x3A03},
-		{"s09c.msf", 0x1B58000, 0x2D640},
-		{"s09c.scr", 0x1B85800, 0x200F4},
-		{"s09c1.act", 0x1BA6000, 0x10F68},
-		{"s09c2.act", 0x1BB7000, 0x25B1C},
-		{"s09c3.act", 0x1BDD000, 0x15DF0},
-		{"s09c4.act", 0x1BF3000, 0x11310},
-		{"s09c5.act", 0x1C04800, 0x14F8C},
-		{"s09c6.act", 0x1C19800, 0x3810},
-		{"s09cz16.msq", 0x1C1D800, 0x2B6B},
-		{"s09d.msf", 0x1C20800, 0xF2F0},
-		{"s09d.scr", 0x1C30000, 0x1C0F4},
-		{"s09d1.act", 0x1C4C800, 0x2FE78},
-		{"s09dz16.msq", 0x1C7C800, 0x2B6B},
-		{"s09e.msf", 0x1C7F800, 0xCBD0},
-		{"s09e.scr", 0x1C8C800, 0x152F4},
-		{"s09e1.act", 0x1CA2000, 0x32538},
-		{"s09e2.act", 0x1CD4800, 0xADE4},
-		{"s09ez16.msq", 0x1CDF800, 0x2B6B},
-		{"s09f.msf", 0x1CE2800, 0x29380},
-		{"s09f.scr", 0x1D0C000, 0x177F4},
-		{"s09f1.act", 0x1D23800, 0x13B84},
-		{"s09f2.act", 0x1D37800, 0x5106C},
-		{"s09f3.act", 0x1D89000, 0xBDB4},
-		{"s09fz16.msq", 0x1D95000, 0x2B6B},
-		{"s09h.msf", 0x1D98000, 0x20F20},
-		{"s09h.scr", 0x1DB9000, 0x1EDF4},
-		{"s09h1.act", 0x1DD8000, 0x11A80},
-		{"s09h2.act", 0x1DEA000, 0x23FC0},
-		{"s09h3.act", 0x1E0E000, 0x2CC88},
-		{"s09h4.act", 0x1E3B000, 0x54534},
-		{"s09h5.act", 0x1E8F800, 0x2BFF4},
-		{"s09hz16.msq", 0x1EBB800, 0x2B6B},
-		{"s09i.msf", 0x1EBE800, 0x3840},
-		{"s09i.scr", 0x1EC2800, 0x229C4},
-		{"s09i1.act", 0x1EE5800, 0x2DD38},
-		{"s09i2.act", 0x1F13800, 0x11A24},
-		{"s09i3.act", 0x1F25800, 0x2CCA8},
-		{"s09i4.act", 0x1F52800, 0x343C},
-		{"s09iz16.msq", 0x1F56000, 0x2B6B},
-		{"s10a.msf", 0x1F59000, 0x270F0},
-		{"s10a.scr", 0x1F80800, 0x406F4},
-		{"s10a1.act", 0x1FC1000, 0x1F82C},
-		{"s10a2.act", 0x1FE1000, 0x5D690},
-		{"s10a3.act", 0x203E800, 0x5E800},
-		{"s10a4.act", 0x209D000, 0xBAF8},
-		{"s10a5.act", 0x20A9000, 0x181C},
-		{"s10a6.act", 0x20AB000, 0x36404},
-		{"s10a7.act", 0x20E1800, 0x51C44},
-		{"s10az17.msq", 0x2133800, 0x1D7A},
-		{"s10az18.msq", 0x2135800, 0x33FE},
-		{"s10b.msf", 0x2139000, 0xD5E0},
-		{"s10b.scr", 0x2146800, 0x14DF4},
-		{"s10b1.act", 0x215B800, 0x27B20},
-		{"s10b2.act", 0x2183800, 0x2B900},
-		{"s10b3.act", 0x21AF800, 0x8D78},
-		{"s10b4.act", 0x21B8800, 0x1A78},
-		{"s10bz17.msq", 0x21BA800, 0x1D7A},
-		{"s10bz18.msq", 0x21BC800, 0x33FE},
-		{"s10d.msf", 0x21C0000, 0x16D20},
-		{"s10d.scr", 0x21D7000, 0x220F4},
-		{"s10d1.act", 0x21F9800, 0x4DFB8},
-		{"s11a.msf", 0x2247800, 0xD650},
-		{"s11a.scr", 0x2255000, 0x16CF4},
-		{"s11a1.act", 0x226C000, 0x13BB4},
-		{"s11a2.act", 0x2280000, 0x4794},
-		{"s11a3.act", 0x2284800, 0x186E0},
-		{"s11az03.msq", 0x229D000, 0x246A},
-		{"s11az17.msq", 0x229F800, 0x1D7A},
-		{"s12a.msf", 0x22A1800, 0x22B60},
-		{"s12a.scr", 0x22C4800, 0x21AAA},
-		{"s12a1.act", 0x22E6800, 0xFE24},
-		{"s12a2.act", 0x22F6800, 0x123D4},
-		{"s12a3.act", 0x2309000, 0x39510},
-		{"s12a4.act", 0x2342800, 0x48474},
-		{"s12a5.act", 0x238B000, 0x35D24},
-		{"s12a6.act", 0x23C1000, 0x12850},
-		{"s12az04.msq", 0x23D4000, 0xFA1},
-		{"s12az26.msq", 0x23D5000, 0x2AE},
-		{"s12b.msf", 0x23D5800, 0xA720},
-		{"s12b.scr", 0x23E0000, 0x117F4},
-		{"s12b1.act", 0x23F1800, 0x50C0},
-		{"s12b2.act", 0x23F7000, 0xAE2C},
-		{"s12b3.act", 0x2402000, 0x6A4},
-		{"s12c.scr", 0x2402800, 0x106F4},
-		{"s12c1.act", 0x2413000, 0xA21B4},
-		{"s13a.msf", 0x24B5800, 0x251A0},
-		{"s13a.scr", 0x24DB000, 0x117F4},
-		{"s13a0.act", 0x24EC800, 0x74C},
-		{"s13a1.act", 0x24ED000, 0x7784},
-		{"s13a2.act", 0x24F4800, 0x923A8},
-		{"s13a3.act", 0x2587000, 0x381F4},
-		{"s13a4.act", 0x25BF800, 0x6E140},
-		{"s13a5.act", 0x262E000, 0x4B18},
-		{"s13az20.msq", 0x2633000, 0x673F},
-		{"s13b.msf", 0x2639800, 0xAB70},
-		{"s13b.scr", 0x2644800, 0xEF4},
-		{"s13b1.act", 0x2645800, 0x7784},
-		{"s13b2.act", 0x264D000, 0x4FAB0},
-		{"s13bz20.msq", 0x269D000, 0x673F},
-		{"s14a.msf", 0x26A3800, 0xF310},
-		{"s14a.scr", 0x26B3000, 0x30A94},
-		{"s14a0.act", 0x26E4000, 0xD320},
-		{"s14a1.act", 0x26F1800, 0x13FC8},
-		{"s14a2.act", 0x2705800, 0xD5E30},
-		{"s14a3.act", 0x27DB800, 0x13274},
-		{"s14a5.act", 0x27EF000, 0x5A6A4},
-		{"s14a15.act", 0x2849800, 0x6D50},
-		{"s14a25.act", 0x2850800, 0x7B564},
-		{"s14az21.msq", 0x28CC000, 0x2EA7},
-		{"s14b.msf", 0x28CF000, 0x187E0},
-		{"s14b.scr", 0x28E7800, 0x106F4},
-		{"s14bz21.msq", 0x28F8000, 0x2EA7},
-		{"s14d.msf", 0x28FB000, 0xC0E0},
-		{"s14d.scr", 0x2907800, 0x23E34},
-		{"s14d1.act", 0x292B800, 0x2D11C},
-		{"s14dz10.msq", 0x2959000, 0x192B},
-		{"s14dz11.msq", 0x295B000, 0x2A5A},
-		{"s14e.msf", 0x295E000, 0x8600},
-		{"s14e.scr", 0x2966800, 0x106F4},
-		{"s14e1.act", 0x2977000, 0xAA00},
-		{"s14e2.act", 0x2982000, 0x1F848},
-		{"s14ez03.msq", 0x29A2000, 0x246A},
-		{"s14ez20.msq", 0x29A4800, 0x673F},
-		{"s14ez22.msq", 0x29AB000, 0x286C},
-		{"s14f.scr", 0x29AE000, 0x106F4},
-		{"s14f1.act", 0x29BE800, 0x27A2C},
-		{"s14fz22.msq", 0x29E6800, 0x286C},
-		{"s14fz27.msq", 0x29E9800, 0xB6E},
-		{"s14g.msf", 0x29EA800, 0x2500},
-		{"s14g.scr", 0x29ED000, 0x1C3C4},
-		{"s14g1.act", 0x2A09800, 0x140FC},
-		{"s14g2.act", 0x2A1E000, 0x943F8},
-		{"s14g3.act", 0x2AB2800, 0x1E9A8},
-		{"s14gz22.msq", 0x2AD1800, 0x286C},
-		{"s14h.scr", 0x2AD4800, 0x106F4},
-		{"s14hz22.msq", 0x2AE5000, 0x286C}
+	{"loadpic.tim", 0x0, 0x1F414},
+	{"fntfiles.dat", 0x1F800, 0x6E44},
+	{"tfont.map", 0x26800, 0xC6A},
+	{"tfont.chr", 0x27800, 0x16C0},
+	{"tfont1.map", 0x29000, 0xC6A},
+	{"tfont1.chr", 0x2A000, 0x16C0},
+	{"sfont.map", 0x2B800, 0xC6A},
+	{"sfont.chr", 0x2C800, 0x16C0},
+	{"boxfont.chr", 0x2E000, 0x4C0},
+	{"bag.scr", 0x2E800, 0xA2E4},
+	{"igfiles.dat", 0x39000, 0x29208},
+	{"dragon.flg", 0x62800, 0x24},
+	{"dragon.var", 0x63000, 0x1E},
+	{"dragon.ini", 0x63800, 0x6028},
+	{"dragon.img", 0x6A000, 0x441C},
+	{"dragon.opt", 0x6E800, 0x16A0},
+	{"dragon.ipt", 0x70000, 0x5D8},
+	{"dragon.rms", 0x70800, 0x63C},
+	{"dragon.obd", 0x71000, 0x1C9DC},
+	{"dragon.txt", 0x8E000, 0x4E8A4},
+	{"dragon.spt", 0xDD000, 0xD0},
+	{"musx.vh", 0xDD800, 0x2E20},
+	{"musx.vb", 0xE0800, 0x402A0},
+	{"glob.vh", 0x121000, 0xC20},
+	{"glob.vb", 0x122000, 0xBB90},
+	{"glob.vab", 0x12E000, 0xC7B0},
+	{"cursor.act", 0x13A800, 0x1863C},
+	{"invenicn.act", 0x153000, 0x3D3C},
+	{"shadow.act", 0x157000, 0x508},
+	{"flicker.act", 0x157800, 0x3CDF0},
+	{"flickert.act", 0x194800, 0x1A4A0},
+	{"flkg.act", 0x1AF000, 0x4D298},
+	{"flkspec.act", 0x1FC800, 0xE008},
+	{"credits.txt", 0x20B000, 0x249A},
+	{"titles.act", 0x20D800, 0x15214},
+	{"drag0000.txt", 0x223000, 0x1000},
+	{"drag0001.txt", 0x224000, 0x1000},
+	{"drag0002.txt", 0x225000, 0x1000},
+	{"drag0003.txt", 0x226000, 0x1000},
+	{"drag0004.txt", 0x227000, 0x1000},
+	{"drag0005.txt", 0x228000, 0x1000},
+	{"drag0006.txt", 0x229000, 0x1000},
+	{"drag0007.txt", 0x22A000, 0x1000},
+	{"drag0008.txt", 0x22B000, 0x1000},
+	{"drag0009.txt", 0x22C000, 0x1000},
+	{"drag0010.txt", 0x22D000, 0x1000},
+	{"drag0011.txt", 0x22E000, 0x1000},
+	{"drag0012.txt", 0x22F000, 0x1000},
+	{"drag0013.txt", 0x230000, 0x1000},
+	{"drag0014.txt", 0x231000, 0x1000},
+	{"drag0015.txt", 0x232000, 0x1000},
+	{"drag0016.txt", 0x233000, 0x1000},
+	{"drag0017.txt", 0x234000, 0x1000},
+	{"drag0018.txt", 0x235000, 0x1000},
+	{"drag0019.txt", 0x236000, 0x1000},
+	{"drag0020.txt", 0x237000, 0x1000},
+	{"drag0021.txt", 0x238000, 0x1000},
+	{"drag0022.txt", 0x239000, 0x1000},
+	{"drag0023.txt", 0x23A000, 0x1000},
+	{"drag0024.txt", 0x23B000, 0x1000},
+	{"drag0025.txt", 0x23C000, 0x1000},
+	{"drag0026.txt", 0x23D000, 0x1000},
+	{"drag0027.txt", 0x23E000, 0x1000},
+	{"drag0028.txt", 0x23F000, 0x1000},
+	{"drag0029.txt", 0x240000, 0x1000},
+	{"drag0030.txt", 0x241000, 0x1000},
+	{"drag0031.txt", 0x242000, 0x1000},
+	{"drag0032.txt", 0x243000, 0x1000},
+	{"drag0033.txt", 0x244000, 0x1000},
+	{"drag0034.txt", 0x245000, 0x1000},
+	{"drag0035.txt", 0x246000, 0x1000},
+	{"drag0036.txt", 0x247000, 0x1000},
+	{"drag0037.txt", 0x248000, 0x1000},
+	{"drag0038.txt", 0x249000, 0x1000},
+	{"drag0039.txt", 0x24A000, 0x1000},
+	{"drag0040.txt", 0x24B000, 0x1000},
+	{"drag0041.txt", 0x24C000, 0x1000},
+	{"drag0042.txt", 0x24D000, 0x1000},
+	{"drag0043.txt", 0x24E000, 0x1000},
+	{"drag0044.txt", 0x24F000, 0x1000},
+	{"drag0045.txt", 0x250000, 0x1000},
+	{"drag0046.txt", 0x251000, 0x1000},
+	{"drag0047.txt", 0x252000, 0x1000},
+	{"drag0048.txt", 0x253000, 0x1000},
+	{"drag0049.txt", 0x254000, 0x1000},
+	{"drag0050.txt", 0x255000, 0x1000},
+	{"drag0051.txt", 0x256000, 0x1000},
+	{"drag0052.txt", 0x257000, 0x1000},
+	{"drag0053.txt", 0x258000, 0x1000},
+	{"drag0054.txt", 0x259000, 0x1000},
+	{"drag0055.txt", 0x25A000, 0x1000},
+	{"drag0056.txt", 0x25B000, 0x1000},
+	{"drag0057.txt", 0x25C000, 0x1000},
+	{"drag0058.txt", 0x25D000, 0x1000},
+	{"drag0059.txt", 0x25E000, 0x1000},
+	{"drag0060.txt", 0x25F000, 0x1000},
+	{"drag0061.txt", 0x260000, 0x1000},
+	{"drag0062.txt", 0x261000, 0x1000},
+	{"drag0063.txt", 0x262000, 0x1000},
+	{"drag0064.txt", 0x263000, 0x1000},
+	{"drag0065.txt", 0x264000, 0x1000},
+	{"drag0066.txt", 0x265000, 0x1000},
+	{"drag0067.txt", 0x266000, 0x1000},
+	{"drag0068.txt", 0x267000, 0x1000},
+	{"drag0069.txt", 0x268000, 0x1000},
+	{"drag0070.txt", 0x269000, 0x1000},
+	{"drag0071.txt", 0x26A000, 0x1000},
+	{"drag0072.txt", 0x26B000, 0x1000},
+	{"drag0073.txt", 0x26C000, 0x1000},
+	{"drag0074.txt", 0x26D000, 0x1000},
+	{"drag0075.txt", 0x26E000, 0x1000},
+	{"drag0076.txt", 0x26F000, 0x1000},
+	{"drag0077.txt", 0x270000, 0x1000},
+	{"drag0078.txt", 0x271000, 0x1000},
+	{"drag0079.txt", 0x272000, 0x1000},
+	{"drag0080.txt", 0x273000, 0x1000},
+	{"dem1.msf", 0x274000, 0x128C0},
+	{"dem1.scr", 0x287000, 0x1934C},
+	{"dem11.act", 0x2A0800, 0x573FC},
+	{"dem1z15.msq", 0x2F8000, 0x3A03},
+	{"dem2.msf", 0x2FC000, 0x23C50},
+	{"dem2.scr", 0x320000, 0x160F4},
+	{"dem2z10.msq", 0x336800, 0x192B},
+	{"dem2z13.msq", 0x338800, 0x3D20},
+	{"demoz00.msq", 0x33C800, 0x1D7A},
+	{"demoz01.msq", 0x33E800, 0x136D},
+	{"demoz02.msq", 0x340000, 0x2F1D},
+	{"demoz03.msq", 0x343000, 0x246A},
+	{"demoz04.msq", 0x345800, 0xFA1},
+	{"demoz05.msq", 0x346800, 0x61C},
+	{"demoz06.msq", 0x347000, 0x3A4B},
+	{"demoz07.msq", 0x34B000, 0x3909},
+	{"demoz08.msq", 0x34F000, 0x25B8},
+	{"demoz09.msq", 0x351800, 0x673F},
+	{"demoz10.msq", 0x358000, 0x192B},
+	{"demoz11.msq", 0x35A000, 0x2A5A},
+	{"demoz12.msq", 0x35D000, 0xE7B},
+	{"demoz13.msq", 0x35E000, 0x3D20},
+	{"demoz14.msq", 0x362000, 0x1B9B},
+	{"demoz15.msq", 0x364000, 0x3A03},
+	{"demoz16.msq", 0x368000, 0x2B6B},
+	{"demoz17.msq", 0x36B000, 0x1D7A},
+	{"demoz18.msq", 0x36D000, 0x33FE},
+	{"demoz19.msq", 0x370800, 0x20D7},
+	{"demoz20.msq", 0x373000, 0x673F},
+	{"demoz21.msq", 0x379800, 0x2EA7},
+	{"demoz22.msq", 0x37C800, 0x286C},
+	{"demoz23.msq", 0x37F800, 0x246A},
+	{"demoz24.msq", 0x382000, 0x2463},
+	{"demoz25.msq", 0x384800, 0x245B},
+	{"demoz26.msq", 0x387000, 0x2AE},
+	{"demoz27.msq", 0x387800, 0xB6E},
+	{"demoz99.msq", 0x388800, 0x2EA7},
+	{"s00b.msf", 0x38B800, 0x1CD0},
+	{"s00b.scr", 0x38D800, 0xEF4},
+	{"s00b1.act", 0x38E800, 0x3DE24},
+	{"s00bz00.msq", 0x3CC800, 0x1D7A},
+	{"s00f.msf", 0x3CE800, 0x158D0},
+	{"s00f.scr", 0x3E4800, 0x138F4},
+	{"s00f1.act", 0x3F8800, 0x2CBB0},
+	{"s00f2.act", 0x425800, 0x16738},
+	{"s00f3.act", 0x43C000, 0x32C78},
+	{"s00f4.act", 0x46F000, 0xB78},
+	{"s00fz01.msq", 0x470000, 0x136D},
+	{"s00g.msf", 0x471800, 0x3840},
+	{"s00g.scr", 0x475800, 0x106F4},
+	{"s00g1.act", 0x486000, 0xAA50},
+	{"s00g2.act", 0x491000, 0x4DDC},
+	{"s00g3.act", 0x496000, 0x1944},
+	{"s00gz00.msq", 0x498000, 0x1D7A},
+	{"s00h.msf", 0x49A000, 0x4FB0},
+	{"s00h.scr", 0x49F000, 0x17AF4},
+	{"s00h1.act", 0x4B7000, 0x34D94},
+	{"s00h2.act", 0x4EC000, 0x1BF4C},
+	{"s00h3.act", 0x508000, 0xA92C},
+	{"s00h4.act", 0x513000, 0x3F58},
+	{"s00h5.act", 0x517000, 0xC850},
+	{"s00h6.act", 0x524000, 0x32174},
+	{"s00h7.act", 0x556800, 0x3BC4},
+	{"s00h8.act", 0x55A800, 0x2D78},
+	{"s00h9.act", 0x55D800, 0x28B0},
+	{"s00ha.act", 0x560800, 0x6F0},
+	{"s00hz10.msq", 0x561000, 0x192B},
+	{"s00i.msf", 0x563000, 0x4A20},
+	{"s00i.scr", 0x568000, 0x61EA0},
+	{"s00i1.act", 0x5CA000, 0x4708},
+	{"s00i2.act", 0x5CE800, 0x32B4},
+	{"s00i3.act", 0x5D2000, 0x2530},
+	{"s00i4.act", 0x5D4800, 0x222C},
+	{"s00iz06.msq", 0x5D7000, 0x3A4B},
+	{"s00j.msf", 0x5DB000, 0x1D2A0},
+	{"s00j.scr", 0x5F8800, 0x1934C},
+	{"s00j1.act", 0x612000, 0x50914},
+	{"s00j2.act", 0x663000, 0x43FCC},
+	{"s00jz15.msq", 0x6A7000, 0x3A03},
+	{"s00k.msf", 0x6AB000, 0x144F0},
+	{"s00k.scr", 0x6BF800, 0x200F4},
+	{"s00kz21.msq", 0x6E0000, 0x2EA7},
+	{"s00l.scr", 0x6E3000, 0xBDF4},
+	{"s00lz16.msq", 0x6EF000, 0x2B6B},
+	{"s00lz21.msq", 0x6F2000, 0x2EA7},
+	{"s01a.msf", 0x6F5000, 0x10590},
+	{"s01a.scr", 0x705800, 0x1B0F4},
+	{"s01a1.act", 0x721000, 0xFBF0},
+	{"s01a2.act", 0x731000, 0x591C},
+	{"s01az00.msq", 0x737000, 0x1D7A},
+	{"s01az08.msq", 0x739000, 0x25B8},
+	{"s01az17.msq", 0x73B800, 0x1D7A},
+	{"s01b.msf", 0x73D800, 0xCDF0},
+	{"s01b.scr", 0x74A800, 0x1DAF4},
+	{"s01b1.act", 0x768800, 0xAF78},
+	{"s01b2.act", 0x773800, 0xAA8},
+	{"s01bz00.msq", 0x774800, 0x1D7A},
+	{"s01c.msf", 0x776800, 0x7D70},
+	{"s01c.scr", 0x77E800, 0x1CCF4},
+	{"s01c1.act", 0x79B800, 0x76CBC},
+	{"s01c2.act", 0x812800, 0x4D0},
+	{"s01c3.act", 0x813000, 0xEE4},
+	{"s01cz01.msq", 0x814000, 0x136D},
+	{"s01d.msf", 0x815800, 0xE740},
+	{"s01d.scr", 0x824000, 0x5E0AC},
+	{"s01d1.act", 0x882800, 0x90A2C},
+	{"s01d2.act", 0x913800, 0x11AB4},
+	{"s01d3.act", 0x925800, 0x20FD8},
+	{"s01d4.act", 0x946800, 0x17D2C},
+	{"s01d5.act", 0x95E800, 0x1BAF4},
+	{"s01d7.act", 0x97A800, 0x6A974},
+	{"s01d8.act", 0x9E5800, 0x2852C},
+	{"s01d9.act", 0xA0E000, 0x958C},
+	{"s01d20.act", 0xA17800, 0x1B9D8},
+	{"s01d21.act", 0xA33800, 0x1D460},
+	{"s01d22.act", 0xA51000, 0x287C8},
+	{"s01d23.act", 0xA79800, 0x16734},
+	{"s01d24.act", 0xA90000, 0x138A8},
+	{"s01d25.act", 0xAA4000, 0x1A290},
+	{"s01da.act", 0xABE800, 0x702C},
+	{"s01dz00.msq", 0xAC6000, 0x1D7A},
+	{"s01dz17.msq", 0xAC8000, 0x1D7A},
+	{"s01e.scr", 0xACA000, 0x189F4},
+	{"s01e1.act", 0xAE3000, 0x7004},
+	{"s01ez00.msq", 0xAEA800, 0x1D7A},
+	{"s01f.msf", 0xAEC800, 0x11210},
+	{"s01f.scr", 0xAFE000, 0x195F4},
+	{"s01f1.act", 0xB17800, 0x33868},
+	{"s01f2.act", 0xB4B800, 0x734C},
+	{"s01fz00.msq", 0xB53000, 0x1D7A},
+	{"s01fz03.msq", 0xB55000, 0x246A},
+	{"s01fz06.msq", 0xB57800, 0x3A4B},
+	{"s01fz23.msq", 0xB5B800, 0x246A},
+	{"s01g.msf", 0xB5E000, 0x1E010},
+	{"s01g.scr", 0xB7C800, 0x1BBF4},
+	{"s01g1.act", 0xB98800, 0xD30},
+	{"s01g2.act", 0xB99800, 0x18794},
+	{"s01g3.act", 0xBB2000, 0x38FC},
+	{"s01g4.act", 0xBB6000, 0x39784},
+	{"s01g5.act", 0xBEF800, 0x20694},
+	{"s01g6.act", 0xC10000, 0x10A18},
+	{"s01g7.act", 0xC21000, 0x13AD4},
+	{"s01g8.act", 0xC35000, 0x1A750},
+	{"s01g9.act", 0xC4F800, 0x12958},
+	{"s01gz00.msq", 0xC62800, 0x1D7A},
+	{"s01gz01.msq", 0xC64800, 0x136D},
+	{"s01gz08.msq", 0xC66000, 0x25B8},
+	{"s01h.msf", 0xC68800, 0xFBF0},
+	{"s01h.scr", 0xC78800, 0x10CF4},
+	{"s01h1.act", 0xC89800, 0x5E5A8},
+	{"s01h2.act", 0xCE8000, 0x52FC0},
+	{"s01h3.act", 0xD3B000, 0x2CC68},
+	{"s01h4.act", 0xD68000, 0xC3CC},
+	{"s01h5.act", 0xD74800, 0x8D8},
+	{"s01h6.act", 0xD75800, 0x1A044},
+	{"s01hz00.msq", 0xD90000, 0x1D7A},
+	{"s01hz01.msq", 0xD92000, 0x136D},
+	{"s01i.msf", 0xD93800, 0x3840},
+	{"s01i.scr", 0xD97800, 0x25FDC},
+	{"s01i1.act", 0xDBD800, 0x19CF0},
+	{"s01i2.act", 0xDD7800, 0x514},
+	{"s01i3.act", 0xDD8000, 0x3BC8},
+	{"s01iz00.msq", 0xDDC000, 0x1D7A},
+	{"s01j.msf", 0xDDE000, 0xBBA0},
+	{"s01j.scr", 0xDEA000, 0x15BF4},
+	{"s01j0.act", 0xE00000, 0x245B8},
+	{"s01j1.act", 0xE24800, 0x8A34},
+	{"s01j2.act", 0xE2D800, 0x3C0A0},
+	{"s01j3.act", 0xE6A000, 0x2944},
+	{"s01jz00.msq", 0xE6D000, 0x1D7A},
+	{"s01k.msf", 0xE6F000, 0x12FA0},
+	{"s01k.scr", 0xE82000, 0x189F4},
+	{"s01k1.act", 0xE9B000, 0x4394},
+	{"s01k2.act", 0xE9F800, 0x75068},
+	{"s01k3.act", 0xF15000, 0x9A0},
+	{"s01kz00.msq", 0xF16000, 0x1D7A},
+	{"s01l.msf", 0xF18000, 0x9A70},
+	{"s01l.scr", 0xF22000, 0x12BF4},
+	{"s01l1.act", 0xF35000, 0x1CDC},
+	{"s01lz00.msq", 0xF37000, 0x1D7A},
+	{"s02a.msf", 0xF39000, 0x11240},
+	{"s02a.scr", 0xF4A800, 0x197F4},
+	{"s02a1.act", 0xF64000, 0x17110},
+	{"s02a2.act", 0xF7B800, 0x13EB4},
+	{"s02a3.act", 0xF8F800, 0x8D20},
+	{"s02a4.act", 0xF98800, 0x36F8},
+	{"s02a5.act", 0xF9C000, 0x22F58},
+	{"s02a6.act", 0xFBF000, 0xE3C},
+	{"s02az02.msq", 0xFC0000, 0x2F1D},
+	{"s02az11.msq", 0xFC3000, 0x2A5A},
+	{"s02b.msf", 0xFC6000, 0x170D0},
+	{"s02b.scr", 0xFDD800, 0x14EF4},
+	{"s02b1.act", 0xFF2800, 0x49F08},
+	{"s02b2.act", 0x103C800, 0xDE78},
+	{"s02b3.act", 0x104A800, 0x3768},
+	{"s02bz02.msq", 0x104E000, 0x2F1D},
+	{"s02bz11.msq", 0x1051000, 0x2A5A},
+	{"s02bz13.msq", 0x1054000, 0x3D20},
+	{"s02bz20.msq", 0x1058000, 0x673F},
+	{"s02c.msf", 0x105E800, 0x20240},
+	{"s02c.scr", 0x107F000, 0x277F4},
+	{"s02c1.act", 0x10A6800, 0x30448},
+	{"s02c2.act", 0x10D7000, 0x15828},
+	{"s02c3.act", 0x10ED000, 0x1708C},
+	{"s02c4.act", 0x1104800, 0x12D1C},
+	{"s02c5.act", 0x1117800, 0x39970},
+	{"s02c6.act", 0x1151800, 0x1B114},
+	{"s02c7.act", 0x116D000, 0x5F7C},
+	{"s02c8.act", 0x1173000, 0x82368},
+	{"s02c9.act", 0x11F5800, 0x3D02C},
+	{"s02c11.act", 0x1233000, 0x2A934},
+	{"s02c51.act", 0x125E000, 0x3004},
+	{"s02ca.act", 0x1261800, 0x7F0D0},
+	{"s02cb.act", 0x12E1000, 0x125A8},
+	{"s02cc.act", 0x12F3800, 0x4150},
+	{"s02cz11.msq", 0x12F8000, 0x2A5A},
+	{"s02cz12.msq", 0x12FB000, 0xE7B},
+	{"s02cz13.msq", 0x12FC000, 0x3D20},
+	{"s02cz20.msq", 0x1300000, 0x673F},
+	{"s02d.msf", 0x1306800, 0x21940},
+	{"s02d.scr", 0x1328800, 0x160F4},
+	{"s02d1.act", 0x133F000, 0x2E09C},
+	{"s02d2.act", 0x136D800, 0x26D74},
+	{"s02d3.act", 0x1394800, 0x14EA0},
+	{"s02d4.act", 0x13A9800, 0x2294},
+	{"s02d5.act", 0x13AC000, 0x4A48},
+	{"s02dz10.msq", 0x13B1000, 0x192B},
+	{"s02dz13.msq", 0x13B3000, 0x3D20},
+	{"s02e.msf", 0x13B7000, 0x5EB0},
+	{"s02e.scr", 0x13BD000, 0x107F4},
+	{"s02e1.act", 0x13CD800, 0x62BC8},
+	{"s02ez18.msq", 0x1430800, 0x33FE},
+	{"s03a.msf", 0x1434000, 0x12070},
+	{"s03a.scr", 0x1446800, 0x18BF4},
+	{"s03a1.act", 0x145F800, 0x49E0},
+	{"s03a2.act", 0x1464800, 0x3DF4},
+	{"s03a3.act", 0x1468800, 0x45774},
+	{"s03a4.act", 0x14AE000, 0x23D4},
+	{"s03a5.act", 0x14B0800, 0x13E64},
+	{"s03a6.act", 0x14C4800, 0x46BC},
+	{"s03az03.msq", 0x14C9000, 0x246A},
+	{"s03az06.msq", 0x14CB800, 0x3A4B},
+	{"s03az23.msq", 0x14CF800, 0x246A},
+	{"s04a.msf", 0x14D2000, 0x11D60},
+	{"s04a.scr", 0x14E4000, 0x12AF4},
+	{"s04a1.act", 0x14F7000, 0x2AC40},
+	{"s04a2.act", 0x1522000, 0x6544},
+	{"s04a3.act", 0x1528800, 0x46C8},
+	{"s04a4.act", 0x152D000, 0x2240},
+	{"s04az03.msq", 0x152F800, 0x246A},
+	{"s04az10.msq", 0x1532000, 0x192B},
+	{"s04az24.msq", 0x1534000, 0x2463},
+	{"s05a.msf", 0x1536800, 0x5D60},
+	{"s05a.scr", 0x153C800, 0x127F4},
+	{"s05a1.act", 0x154F000, 0x3E1CC},
+	{"s05az04.msq", 0x158D800, 0xFA1},
+	{"s05b.msf", 0x158E800, 0x28640},
+	{"s05b.scr", 0x15B7000, 0x2C3C4},
+	{"s05b0.act", 0x15E3800, 0x16474},
+	{"s05b1.act", 0x15FA000, 0x1F2F4},
+	{"s05b2.act", 0x1619800, 0x113E8},
+	{"s05b3.act", 0x162B000, 0x1D424},
+	{"s05b4.act", 0x1648800, 0x501C4},
+	{"s05b5.act", 0x1699000, 0x1F510},
+	{"s05b6.act", 0x16B8800, 0x8860},
+	{"s05bz05.msq", 0x16C1800, 0x61C},
+	{"s05bz06.msq", 0x16C2000, 0x3A4B},
+	{"s05bz07.msq", 0x16C6000, 0x3909},
+	{"s06a.msf", 0x16CA000, 0x1C750},
+	{"s06a.scr", 0x16E6800, 0x151F4},
+	{"s06a1.act", 0x16FC000, 0x24654},
+	{"s06a2.act", 0x1720800, 0x25D0},
+	{"s06az19.msq", 0x1723000, 0x20D7},
+	{"s06b.msf", 0x1725800, 0x1BF60},
+	{"s06b.scr", 0x1741800, 0x182F4},
+	{"s06b1.act", 0x175A000, 0x6CE68},
+	{"s06bz19.msq", 0x17C7000, 0x20D7},
+	{"s07a.msf", 0x17C9800, 0x15240},
+	{"s07a.scr", 0x17DF000, 0x1ACF4},
+	{"s07a1.act", 0x17FA000, 0xE5A0},
+	{"s07a2.act", 0x1808800, 0x425D0},
+	{"s07a3.act", 0x184B000, 0x18810},
+	{"s07az03.msq", 0x1864000, 0x246A},
+	{"s07az08.msq", 0x1866800, 0x25B8},
+	{"s07az25.msq", 0x1869000, 0x245B},
+	{"s07b.msf", 0x186B800, 0x14960},
+	{"s07b.scr", 0x1880800, 0x15CF4},
+	{"s07b1.act", 0x1896800, 0x419C8},
+	{"s07b2.act", 0x18D8800, 0x1A560},
+	{"s07b3.act", 0x18F3000, 0x76F4},
+	{"s07b4.act", 0x18FA800, 0x76C8},
+	{"s07bz03.msq", 0x1902000, 0x246A},
+	{"s07bz08.msq", 0x1904800, 0x25B8},
+	{"s07bz25.msq", 0x1907000, 0x245B},
+	{"s07c.scr", 0x1909800, 0x143F4},
+	{"s07c1.act", 0x191E000, 0xA25C},
+	{"s08a.msf", 0x1928800, 0xB9E0},
+	{"s08a.scr", 0x1934800, 0x322F4},
+	{"s08a1.act", 0x1967000, 0xA668},
+	{"s08a2.act", 0x1971800, 0x2C828},
+	{"s08a3.act", 0x199E800, 0x6CF0},
+	{"s08az03.msq", 0x19A5800, 0x246A},
+	{"s08az06.msq", 0x19A8000, 0x3A4B},
+	{"s08az23.msq", 0x19AC000, 0x246A},
+	{"s08b.scr", 0x19AE800, 0x399F4},
+	{"s08b1.act", 0x19E8800, 0x1F0A0},
+	{"s08bz03.msq", 0x1A08000, 0x246A},
+	{"s08bz06.msq", 0x1A0A800, 0x3A4B},
+	{"s08bz23.msq", 0x1A0E800, 0x246A},
+	{"s09a.msf", 0x1A11000, 0x14190},
+	{"s09a.scr", 0x1A25800, 0x1B4F4},
+	{"s09a1.act", 0x1A41000, 0x634B8},
+	{"s09az14.msq", 0x1AA4800, 0x1B9B},
+	{"s09b.msf", 0x1AA6800, 0x1F2E0},
+	{"s09b.scr", 0x1AC6000, 0x1B4F4},
+	{"s09b1.act", 0x1AE1800, 0x71B8},
+	{"s09b2.act", 0x1AE9000, 0x2299C},
+	{"s09b3.act", 0x1B0C000, 0x1B360},
+	{"s09b4.act", 0x1B27800, 0x14B64},
+	{"s09b5.act", 0x1B3C800, 0x5E4},
+	{"s09b6.act", 0x1B3D000, 0xAA78},
+	{"s09b7.act", 0x1B48000, 0x9B24},
+	{"s09bz14.msq", 0x1B52000, 0x1B9B},
+	{"s09bz15.msq", 0x1B54000, 0x3A03},
+	{"s09c.msf", 0x1B58000, 0x2D640},
+	{"s09c.scr", 0x1B85800, 0x200F4},
+	{"s09c1.act", 0x1BA6000, 0x10F68},
+	{"s09c2.act", 0x1BB7000, 0x25B1C},
+	{"s09c3.act", 0x1BDD000, 0x15DF0},
+	{"s09c4.act", 0x1BF3000, 0x11310},
+	{"s09c5.act", 0x1C04800, 0x14F8C},
+	{"s09c6.act", 0x1C19800, 0x3810},
+	{"s09cz16.msq", 0x1C1D800, 0x2B6B},
+	{"s09d.msf", 0x1C20800, 0xF2F0},
+	{"s09d.scr", 0x1C30000, 0x1C0F4},
+	{"s09d1.act", 0x1C4C800, 0x2FE78},
+	{"s09dz16.msq", 0x1C7C800, 0x2B6B},
+	{"s09e.msf", 0x1C7F800, 0xCBD0},
+	{"s09e.scr", 0x1C8C800, 0x152F4},
+	{"s09e1.act", 0x1CA2000, 0x32538},
+	{"s09e2.act", 0x1CD4800, 0xADE4},
+	{"s09ez16.msq", 0x1CDF800, 0x2B6B},
+	{"s09f.msf", 0x1CE2800, 0x29380},
+	{"s09f.scr", 0x1D0C000, 0x177F4},
+	{"s09f1.act", 0x1D23800, 0x13B84},
+	{"s09f2.act", 0x1D37800, 0x5106C},
+	{"s09f3.act", 0x1D89000, 0xBDB4},
+	{"s09fz16.msq", 0x1D95000, 0x2B6B},
+	{"s09h.msf", 0x1D98000, 0x20F20},
+	{"s09h.scr", 0x1DB9000, 0x1EDF4},
+	{"s09h1.act", 0x1DD8000, 0x11A80},
+	{"s09h2.act", 0x1DEA000, 0x23FC0},
+	{"s09h3.act", 0x1E0E000, 0x2CC88},
+	{"s09h4.act", 0x1E3B000, 0x54534},
+	{"s09h5.act", 0x1E8F800, 0x2BFF4},
+	{"s09hz16.msq", 0x1EBB800, 0x2B6B},
+	{"s09i.msf", 0x1EBE800, 0x3840},
+	{"s09i.scr", 0x1EC2800, 0x229C4},
+	{"s09i1.act", 0x1EE5800, 0x2DD38},
+	{"s09i2.act", 0x1F13800, 0x11A24},
+	{"s09i3.act", 0x1F25800, 0x2CCA8},
+	{"s09i4.act", 0x1F52800, 0x343C},
+	{"s09iz16.msq", 0x1F56000, 0x2B6B},
+	{"s10a.msf", 0x1F59000, 0x270F0},
+	{"s10a.scr", 0x1F80800, 0x406F4},
+	{"s10a1.act", 0x1FC1000, 0x1F82C},
+	{"s10a2.act", 0x1FE1000, 0x5D690},
+	{"s10a3.act", 0x203E800, 0x5E800},
+	{"s10a4.act", 0x209D000, 0xBAF8},
+	{"s10a5.act", 0x20A9000, 0x181C},
+	{"s10a6.act", 0x20AB000, 0x36404},
+	{"s10a7.act", 0x20E1800, 0x51C44},
+	{"s10az17.msq", 0x2133800, 0x1D7A},
+	{"s10az18.msq", 0x2135800, 0x33FE},
+	{"s10b.msf", 0x2139000, 0xD5E0},
+	{"s10b.scr", 0x2146800, 0x14DF4},
+	{"s10b1.act", 0x215B800, 0x27B20},
+	{"s10b2.act", 0x2183800, 0x2B900},
+	{"s10b3.act", 0x21AF800, 0x8D78},
+	{"s10b4.act", 0x21B8800, 0x1A78},
+	{"s10bz17.msq", 0x21BA800, 0x1D7A},
+	{"s10bz18.msq", 0x21BC800, 0x33FE},
+	{"s10d.msf", 0x21C0000, 0x16D20},
+	{"s10d.scr", 0x21D7000, 0x220F4},
+	{"s10d1.act", 0x21F9800, 0x4DFB8},
+	{"s11a.msf", 0x2247800, 0xD650},
+	{"s11a.scr", 0x2255000, 0x16CF4},
+	{"s11a1.act", 0x226C000, 0x13BB4},
+	{"s11a2.act", 0x2280000, 0x4794},
+	{"s11a3.act", 0x2284800, 0x186E0},
+	{"s11az03.msq", 0x229D000, 0x246A},
+	{"s11az17.msq", 0x229F800, 0x1D7A},
+	{"s12a.msf", 0x22A1800, 0x22B60},
+	{"s12a.scr", 0x22C4800, 0x21AAA},
+	{"s12a1.act", 0x22E6800, 0xFE24},
+	{"s12a2.act", 0x22F6800, 0x123D4},
+	{"s12a3.act", 0x2309000, 0x39510},
+	{"s12a4.act", 0x2342800, 0x48474},
+	{"s12a5.act", 0x238B000, 0x35D24},
+	{"s12a6.act", 0x23C1000, 0x12850},
+	{"s12az04.msq", 0x23D4000, 0xFA1},
+	{"s12az26.msq", 0x23D5000, 0x2AE},
+	{"s12b.msf", 0x23D5800, 0xA720},
+	{"s12b.scr", 0x23E0000, 0x117F4},
+	{"s12b1.act", 0x23F1800, 0x50C0},
+	{"s12b2.act", 0x23F7000, 0xAE2C},
+	{"s12b3.act", 0x2402000, 0x6A4},
+	{"s12c.scr", 0x2402800, 0x106F4},
+	{"s12c1.act", 0x2413000, 0xA21B4},
+	{"s13a.msf", 0x24B5800, 0x251A0},
+	{"s13a.scr", 0x24DB000, 0x117F4},
+	{"s13a0.act", 0x24EC800, 0x74C},
+	{"s13a1.act", 0x24ED000, 0x7784},
+	{"s13a2.act", 0x24F4800, 0x923A8},
+	{"s13a3.act", 0x2587000, 0x381F4},
+	{"s13a4.act", 0x25BF800, 0x6E140},
+	{"s13a5.act", 0x262E000, 0x4B18},
+	{"s13az20.msq", 0x2633000, 0x673F},
+	{"s13b.msf", 0x2639800, 0xAB70},
+	{"s13b.scr", 0x2644800, 0xEF4},
+	{"s13b1.act", 0x2645800, 0x7784},
+	{"s13b2.act", 0x264D000, 0x4FAB0},
+	{"s13bz20.msq", 0x269D000, 0x673F},
+	{"s14a.msf", 0x26A3800, 0xF310},
+	{"s14a.scr", 0x26B3000, 0x30A94},
+	{"s14a0.act", 0x26E4000, 0xD320},
+	{"s14a1.act", 0x26F1800, 0x13FC8},
+	{"s14a2.act", 0x2705800, 0xD5E30},
+	{"s14a3.act", 0x27DB800, 0x13274},
+	{"s14a5.act", 0x27EF000, 0x5A6A4},
+	{"s14a15.act", 0x2849800, 0x6D50},
+	{"s14a25.act", 0x2850800, 0x7B564},
+	{"s14az21.msq", 0x28CC000, 0x2EA7},
+	{"s14b.msf", 0x28CF000, 0x187E0},
+	{"s14b.scr", 0x28E7800, 0x106F4},
+	{"s14bz21.msq", 0x28F8000, 0x2EA7},
+	{"s14d.msf", 0x28FB000, 0xC0E0},
+	{"s14d.scr", 0x2907800, 0x23E34},
+	{"s14d1.act", 0x292B800, 0x2D11C},
+	{"s14dz10.msq", 0x2959000, 0x192B},
+	{"s14dz11.msq", 0x295B000, 0x2A5A},
+	{"s14e.msf", 0x295E000, 0x8600},
+	{"s14e.scr", 0x2966800, 0x106F4},
+	{"s14e1.act", 0x2977000, 0xAA00},
+	{"s14e2.act", 0x2982000, 0x1F848},
+	{"s14ez03.msq", 0x29A2000, 0x246A},
+	{"s14ez20.msq", 0x29A4800, 0x673F},
+	{"s14ez22.msq", 0x29AB000, 0x286C},
+	{"s14f.scr", 0x29AE000, 0x106F4},
+	{"s14f1.act", 0x29BE800, 0x27A2C},
+	{"s14fz22.msq", 0x29E6800, 0x286C},
+	{"s14fz27.msq", 0x29E9800, 0xB6E},
+	{"s14g.msf", 0x29EA800, 0x2500},
+	{"s14g.scr", 0x29ED000, 0x1C3C4},
+	{"s14g1.act", 0x2A09800, 0x140FC},
+	{"s14g2.act", 0x2A1E000, 0x943F8},
+	{"s14g3.act", 0x2AB2800, 0x1E9A8},
+	{"s14gz22.msq", 0x2AD1800, 0x286C},
+	{"s14h.scr", 0x2AD4800, 0x106F4},
+	{"s14hz22.msq", 0x2AE5000, 0x286C}
 };
 
 uint32 getResourceId(const char *filename) {
diff --git a/engines/dragons/bigfile.h b/engines/dragons/bigfile.h
index d5376a7bd5..cea46fb81d 100644
--- a/engines/dragons/bigfile.h
+++ b/engines/dragons/bigfile.h
@@ -31,6 +31,7 @@ class BigfileArchive {
 private:
 	Common::Language _language;
 	Common::File *_fd;
+
 public:
 	BigfileArchive(const char *filename, Common::Language language);
 	virtual ~BigfileArchive();
diff --git a/engines/dragons/credits.cpp b/engines/dragons/credits.cpp
index dd6d4912b9..a41b5b0578 100644
--- a/engines/dragons/credits.cpp
+++ b/engines/dragons/credits.cpp
@@ -103,9 +103,8 @@ void Credits::update() {
 }
 
 void Credits::convertToWideChar(uint16 *destBuf, byte *text, uint16 maxLength) {
-	int i = 0;
 	bool finished = false;
-	for (; i < maxLength; i++) {
+	for (int i = 0; i < maxLength; i++) {
 		if (text[i] == 0) {
 			finished = true;
 		}
diff --git a/engines/dragons/credits.h b/engines/dragons/credits.h
index 0d23671154..702940276d 100644
--- a/engines/dragons/credits.h
+++ b/engines/dragons/credits.h
@@ -46,6 +46,7 @@ private:
 	char *_curPtr;
 	uint32 _dataLength;
 	uint32 _curPosition;
+
 public:
 	Credits(DragonsEngine *vm, FontManager *fontManager, BigfileArchive *bigfileArchive);
 	void start();
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index aa0b9d4003..462dd52c25 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -76,9 +76,8 @@ void Cursor::update() {
 
 	// 0x80028104
 	if (_iniUnderCursor != 0
-	&& ((_iniUnderCursor & 0x8000 && (_vm->_inventory->getType() == 1 || _vm->_inventory->getType() == 2))
-		||(!(_iniUnderCursor & 0x8000) && _vm->getINI(_iniUnderCursor - 1)->field_1a_flags_maybe & 0x80))
-	) {
+			&& ((_iniUnderCursor & 0x8000 && (_vm->_inventory->getType() == 1 || _vm->_inventory->getType() == 2))
+			||(!(_iniUnderCursor & 0x8000) && _vm->getINI(_iniUnderCursor - 1)->field_1a_flags_maybe & 0x80))) {
 		if (_actor->_sequenceID != 0x84) {
 			_actor->updateSequence(0x84);
 		}
@@ -124,8 +123,7 @@ void Cursor::update() {
 			_actor->updateSequence(0x84);
 		}
 		return;
-	}
-	else {
+	} else {
 		if ((uint)_actor->_sequenceID != (uint)data_8007283c + 1) {
 			_actor->updateSequence((uint)data_8007283c + 1);
 		}
@@ -157,19 +155,19 @@ int16 Cursor::updateINIUnderCursor() {
 		}
 		Common::Point inventoryPosition = _vm->_inventory->getPosition();
 		if (_x >= inventoryPosition.x + 0xa + xOffset
-			&& _x < inventoryPosition.x + 0x35 + xOffset
-			&& _y >= inventoryPosition.y + 0xa
-			&& _y < inventoryPosition.y + 0x25) {
+				&& _x < inventoryPosition.x + 0x35 + xOffset
+				&& _y >= inventoryPosition.y + 0xa
+				&& _y < inventoryPosition.y + 0x25) {
 			_iniUnderCursor = 0x8001;
 			return _iniUnderCursor;
 		}
 
 		if (_x >= inventoryPosition.x + 0x36
-			&& _x < inventoryPosition.x + 0x5f
-			&& _y >= inventoryPosition.y + 0xa
-			&& _y < inventoryPosition.y + 0x25
-			&& _vm->_inventory->getPositionIndex() != 0
-			&& _vm->_inventory->getPositionIndex() != 2) {
+				&& _x < inventoryPosition.x + 0x5f
+				&& _y >= inventoryPosition.y + 0xa
+				&& _y < inventoryPosition.y + 0x25
+				&& _vm->_inventory->getPositionIndex() != 0
+				&& _vm->_inventory->getPositionIndex() != 2) {
 			_iniUnderCursor = 0x8002;
 			return _iniUnderCursor;
 		}
@@ -186,8 +184,7 @@ int16 Cursor::updateINIUnderCursor() {
 				_iniUnderCursor = 0;
 				return 0;
 			}
-		}
-		else {
+		} else {
 			if (inventoryType != 2) {
 				_iniUnderCursor = 0;
 				return 0;
@@ -203,8 +200,9 @@ int16 Cursor::updateIniFromScene() {
 	int16 cursorY = _y + _vm->_scene->_camera.y;
 	int16 cursorTileX = cursorX / 32;
 	int16 cursorTileY = cursorY / 8;
-	int16 _data_80072890_orig = _data_80072890;
-	int16 _data_800728b0_cursor_seqID_orig = _data_800728b0_cursor_seqID;
+	int16 data_80072890_orig = _data_80072890;
+	int16 data_800728b0_cursor_seqID_orig = _data_800728b0_cursor_seqID;
+
 	for (int i = 0;i <_vm->_dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId != _vm->_scene->getSceneId()) {
@@ -243,10 +241,11 @@ int16 Cursor::updateIniFromScene() {
 				// _iniUnderCursor = cursorOverIni;
 				_data_80072890 = _iniUnderCursor;
 				_data_800728b0_cursor_seqID = _sequenceID;
+
 				if (ini->field_1a_flags_maybe & 0x800) {
 					_data_80072890 = cursorOverIni;
 					uint32 newSeqId = 1;
-					for (int idx=0; idx < 5; idx++) {
+					for (int idx = 0; idx < 5; idx++) {
 						_data_800728b0_cursor_seqID = idx;
 						byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
 						ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
@@ -272,7 +271,7 @@ int16 Cursor::updateIniFromScene() {
 				if (_sequenceID != 0) {
 					_iniUnderCursor = cursorOverIni;
 					_data_80072890 = _data_80072890_orig;
-					_data_800728b0_cursor_seqID = _data_800728b0_cursor_seqID_orig;
+					_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
 				byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
@@ -284,21 +283,22 @@ int16 Cursor::updateIniFromScene() {
 				if (executeScript(scriptOpCall, 0)) {
 					_iniUnderCursor = cursorOverIni;
 					_data_80072890 = _data_80072890_orig;
-					_data_800728b0_cursor_seqID = _data_800728b0_cursor_seqID_orig;
+					_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
 			}
 		}
 	}
 	_iniUnderCursor = 0;
-	_data_80072890 = _data_80072890_orig;
-	_data_800728b0_cursor_seqID = _data_800728b0_cursor_seqID_orig;
+	_data_80072890 = data_80072890_orig;
+	_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 	return 0;
 }
 
 int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 	int16 temp = _vm->_scriptOpcodes->_scriptTargetINI;
 	byte *codeStart = scriptOpCall._code;
+
 	scriptOpCall._field8 = 1;
 	scriptOpCall._result = 0;
 	_vm->_scriptOpcodes->_data_80071f5c = 0;
@@ -340,7 +340,6 @@ void Cursor::selectPreviousCursor() {
 void Cursor::updateSequenceID(int16 sequenceID) {
 	_sequenceID = sequenceID;
 	_actor->updateSequence(_sequenceID);
-
 }
 
 void Cursor::setActorFlag400() {
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 53d4a689fd..2d103f90d4 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -43,11 +43,11 @@ public:
 	int16 data_8007283c;
 	int16 _cursorActivationSeqOffset;
 	uint16 _iniItemInHand;
+
 private:
 	DragonsEngine *_vm;
 	Actor *_actor;
 
-
 public:
 	Cursor(DragonsEngine *vm);
 	void init(ActorManager *actorManager, DragonINIResource *dragonINIResource);
@@ -63,6 +63,7 @@ public:
 	void setActorFlag400();
 	void clearActorFlag400();
 	byte *getPalette();
+
 private:
 	int16 updateIniFromScene();
 };
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 42cded37d5..43d84f423f 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -72,129 +72,129 @@ void CutScene::scene1() {
 	_vm->waitForFrames(0x5a);
 	closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 	//playSoundFromTxtIndex(0x4e26);
-	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,4,0,0x4e26,0x2e01) != 2) {
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 4, 0, 0x4e26, 0x2e01) != 2) {
 		fadeScreenAndResetActor(_actor_80072de8);
 		closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); // cut to flicker
 		//playSoundFromTxtIndex(0x4ea2);
-		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,2,0,0x4ea2,0x701) != 2) {
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 2, 0, 0x4ea2, 0x701) != 2) {
 			fadeScreenAndResetActor(_actor_80072de8);
 			closeUpShotOnActor(0xd3, 0, 0x233, 0x17a); //close up on king
 			//playSoundFromTxtIndex(0x4eec);
-			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,5,0,0x4eec,0x2e01) != 2) {
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 5, 0, 0x4eec, 0x2e01) != 2) {
 				fadeScreenAndResetActor(_actor_80072de8);
 				wideAngleEveryoneAtTable();  // shot of whole room
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x5000,0x2e01) != 2 &&
-					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_800830c0,0x1d,0x1c,0x5074,0x501) != 2 &&
-					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0,9,5,0x511c,0xc01) != 2 &&
-					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_800830c0,0x1d,0x1c,0x5138,0x501) != 2) {
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 4, 0, 0x5000, 0x2e01) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_800830c0, 0x1d, 0x1c, 0x5074, 0x501) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0, 9, 5, 0x511c, 0xc01) != 2 &&
+					_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_800830c0, 0x1d, 0x1c, 0x5138, 0x501) != 2) {
 					closeUpShotOnActor(0xd7, 0, 0x312, 0x260); //close up on flame
 					//playSoundFromTxtIndex(0x5152);
-					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,2,0,0x5152,0x3e01) != 2) {
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 2, 0, 0x5152, 0x3e01) != 2) {
 						fadeScreenAndResetActor(_actor_80072de8);
 						closeUpShotOnActor(0xd8, 0, 0xfd, 0x60); //close up flicker
 						//playSoundFromTxtIndex(0x51fc);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,3,0,0x51fc,0x701) != 2) {
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 3, 0, 0x51fc, 0x701) != 2) {
 							_vm->playOrStopSound(0x8004);
 							_vm->waitForFrames(0x28);
 							_vm->playOrStopSound(0x8003);
 							fadeScreenAndResetActor(_actor_80072de8);
 							_actor_80063514 = _actor_80063514 | 0x40;
-							FUN_8003d8e8(0xd6,0,0x37a,0x280);
-							_actor_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3); //load humans
-							_actor_80072df0 = _vm->_actorManager->loadActor(0xd3,2,0x87,199,3);
+							fun_8003d8e8(0xd6, 0, 0x37a, 0x280);
+							_actor_80072dec = _vm->_actorManager->loadActor(0xd5, 0, 0x2d6, 0xc6, 3); //load humans
+							_actor_80072df0 = _vm->_actorManager->loadActor(0xd3, 2, 0x87, 199, 3);
 							_vm->waitForFramesAllowSkip(4);
 							// call_fade_related_1f();
-							if (FUN_8003dab8(0x52d6,0,0,0x701,1) != 2) {
+							if (fun_8003dab8(0x52d6, 0, 0, 0x701, 1) != 2) {
 								// TODO callMaybeResetData();
 								//playSoundFromTxtIndex(0x530c);
-								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,2,0,0x530c,0x3c01) != 2) {
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 2, 0, 0x530c, 0x3c01) != 2) {
 									while (0x10 < _vm->_scene->_camera.x) {
 										_vm->_scene->_camera.x = _vm->_scene->_camera.x + -0x10;
 										_vm->waitForFrames(1);
 									}
 									_vm->_scene->_camera.x = 0;
 									//playSoundFromTxtIndex(0x54dc);
-									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0,6,2,0x54dc,0x2e01) != 2) {
+									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0, 6, 2, 0x54dc, 0x2e01) != 2) {
 										fadeScreenAndResetActor(_actor_80072de8);
 										fadeScreenAndResetActor(_actor_80072dec);
 										fadeScreenAndResetActor(_actor_80072df0);
 										wideAngleEveryoneAtTable();
-										if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e08,3,2,0x55d4,0xc01) != 2) {
+										if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e08, 3, 2, 0x55d4, 0xc01) != 2) {
 											closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 											//playSoundFromTxtIndex(0x562c);
-											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,2,0,0x562c,0xc01) != 2) {
+											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 2, 0, 0x562c, 0xc01) != 2) {
 												fadeScreenAndResetActor(_actor_80072de8);
-												FUN_8003d8e8(0xd6,0,0x37a,0x280);
-												_actor_80072dec = _vm->_actorManager->loadActor(0xd5,4,0x2d6,0xc6,3);
+												fun_8003d8e8(0xd6, 0, 0x37a, 0x280);
+												_actor_80072dec = _vm->_actorManager->loadActor(0xd5, 4, 0x2d6, 0xc6, 3);
 												_vm->waitForFramesAllowSkip(4);
 												// call_fade_related_1f();
-												if (FUN_8003dab8(0x5780,0x14,0,0xc01,1) != 2) {
+												if (fun_8003dab8(0x5780, 0x14, 0, 0xc01, 1) != 2) {
 													_actor_80063514 = _actor_80063514 | 0x40;
 													fadeScreenAndResetActor(_actor_80072de8);
 													fadeScreenAndResetActor(_actor_80072dec);
 													closeUpShotOnActor(0xd7, 0, 0x312, 0x260); // close up flame
 													//playSoundFromTxtIndex(0x581c);
-													if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,3,0,0x581c,0x3e01) != 2) {
+													if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 3, 0, 0x581c, 0x3e01) != 2) {
 														fadeScreenAndResetActor(_actor_80072de8);
 														closeUpShotOnActor(0xd4, 0, 0x8a, 0); //close up chancellor
 														//playSoundFromTxtIndex(0x5942);
-														if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,4,0,0x5942,0xc01) != 2) {
+														if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 4, 0, 0x5942, 0xc01) != 2) {
 															fadeScreenAndResetActor(_actor_80072de8);
 															closeUpShotOnActor(0xd3, 2, 0x87, 0); // close up king
 															//playSoundFromTxtIndex(0x5aaa);
-															if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,7,2,0x5aaa,0x2e01) != 2) {
+															if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 7, 2, 0x5aaa, 0x2e01) != 2) {
 																fadeScreenAndResetActor(_actor_80072de8);
-																FUN_8003d8e8(0xd6,0,0x37a,0x280);
-																_actor_80072dec = _vm->_actorManager->loadActor(0xd5,0,0x2d6,0xc6,3);
+																fun_8003d8e8(0xd6, 0, 0x37a, 0x280);
+																_actor_80072dec = _vm->_actorManager->loadActor(0xd5, 0, 0x2d6, 0xc6, 3);
 																_vm->waitForFramesAllowSkip(4);
 																// call_fade_related_1f();
 																//playSoundFromTxtIndex(0x5afc);
-																if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,3,0,0x5afc,0x3c01) != 2) {
+																if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 3, 0, 0x5afc, 0x3c01) != 2) {
 																	fadeScreenAndResetActor(_actor_80072de8);
 																	fadeScreenAndResetActor(_actor_80072dec);
 																	_actor_80063514 = _actor_80063514 & 0xffbf;
 																	closeUpKnightsAtTable(); // close up of knights at table.
 																	_vm->playOrStopSound(0x8003);
 																	//playSoundFromTxtIndex(0x5b96);
-																	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,8,4,0x5b96,0xc01) != 2) {
+																	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 8, 4, 0x5b96, 0xc01) != 2) {
 																		//playSoundFromTxtIndex(0x5c4a);
-																		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,2,0,0x5c4a,0x2e01) != 2) {
+																		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 2, 0, 0x5c4a, 0x2e01) != 2) {
 																			//playSoundFromTxtIndex(0x5dc8);
 																			_actor_80072df0->updateSequence(0xf);
 																			_actor_80072df4->updateSequence(0xd);
 																			_actor_80072df8->updateSequence(0xe);
-																			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,0xc,4,0x5dc8,0xc01) != 2) {
+																			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 0xc, 4, 0x5dc8, 0xc01) != 2) {
 																				_actor_80072df0->updateSequence(6);
 																				_actor_80072df4->updateSequence(0);
 																				_actor_80072df8->updateSequence(2);
-																				FUN_8003d8e8(0xd3,2,0x28d,0x250);
-																				_actor_80072dec = _vm->_actorManager->loadActor(0xd7,0,0x348,199,3);
+																				fun_8003d8e8(0xd3, 2, 0x28d, 0x250);
+																				_actor_80072dec = _vm->_actorManager->loadActor(0xd7, 0, 0x348, 199, 3);
 																				_vm->waitForFramesAllowSkip(4); // close up of king and flame
 																				//call_fade_related_1f();
 																				//playSoundFromTxtIndex(0x5ef2);
-																				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x5ef2,0x3e01) != 2) {
+																				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 4, 0, 0x5ef2, 0x3e01) != 2) {
 																					fadeScreenAndResetActor(_actor_80072de8);
 																					fadeScreenAndResetActor(_actor_80072dec);
 																					closeUpShotOnActor(0xd3, 0, 0x233,
 																									   0x17a); // close up of king
 																					//playSoundFromTxtIndex(0x6000);
-																					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,8,0,0x6000,0x2e01) != 2) {
+																					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 8, 0, 0x6000, 0x2e01) != 2) {
 																						fadeScreenAndResetActor(_actor_80072de8);
 																						closeUpKnightsAtTable(); // close up knights at table
 																						//playSoundFromTxtIndex(0x7dcc);
 																						_actor_80072df0->updateSequence(0x13);
 																						_actor_80072df4->updateSequence(0x10);
 																						_actor_80072df8->updateSequence(0x11);
-																						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
+																						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 0x12, 6, 0x7dcc, 0xc01) != 2) {
 																							wideAngleEveryoneAtTable(); //whole room shot
-																							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0x17,0x16,0x60ee,0x701) != 2) {
+																							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 0x17, 0x16, 0x60ee, 0x701) != 2) {
 																								closeUpKnightsAtTable();
 																								_actor_80072df0->updateSequence(6);
 																								_actor_80072df4->updateSequence(0);
 																								_actor_80072df8->updateSequence(2);
 																								_actor_80072dec->updateSequence(4);
 																								//playSoundFromTxtIndex(0x5de8);
-																								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df8,0xb,2,0x5de8,0xc01) != 2) {
+																								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df8, 0xb, 2, 0x5de8, 0xc01) != 2) {
 																									wideAngleEveryoneAtTable();
 																									_vm->playOrStopSound(1);
 																									_actor_80072df0->updateSequence(8);
@@ -220,11 +220,11 @@ void CutScene::scene1() {
 																									changeBackgroundPosition(
 																											2, 0);
 																									_vm->_actorManager->clearActorFlags(2);
-																									_actor_80072de8 = _vm->_actorManager->loadActor(0x82,0,0x60,0x114,1);
-																									_actor_80072dec = _vm->_actorManager->loadActor(0x82,2,0x91,0x113,1);
-																									_actor_80072df0 = _vm->_actorManager->loadActor(0x82,1,0xd0,199,1);
-																									_actor_80072df4 = _vm->_actorManager->loadActor(0x82,3,0xb6,0x113,1);
-																									_actor_80072de8 = _vm->_actorManager->loadActor(0x82,4,0x98,0x40,1);
+																									_actor_80072de8 = _vm->_actorManager->loadActor(0x82, 0, 0x60, 0x114, 1);
+																									_actor_80072dec = _vm->_actorManager->loadActor(0x82, 2, 0x91, 0x113, 1);
+																									_actor_80072df0 = _vm->_actorManager->loadActor(0x82, 1, 0xd0, 199, 1);
+																									_actor_80072df4 = _vm->_actorManager->loadActor(0x82, 3, 0xb6, 0x113, 1);
+																									_actor_80072de8 = _vm->_actorManager->loadActor(0x82, 4, 0x98, 0x40, 1);
 
 																									_actor_80072de8->setFlag(ACTOR_FLAG_100);
 																									_actor_80072de8->setFlag(ACTOR_FLAG_800);
@@ -257,20 +257,20 @@ void CutScene::scene1() {
 
 																									_vm->waitForFramesAllowSkip(0xe);
 																									// call_fade_related_1f();
-																									_actor_80072df0->startWalk(0xe8,0xa8,2);
+																									_actor_80072df0->startWalk(0xe8, 0xa8, 2);
 																									while (_actor_80072df0->isFlagSet(ACTOR_FLAG_10)) {
 																										_vm->waitForFrames(1);
 																									}
-																									_actor_80072de8->startWalk(0x97,0x37,2);
-																									_actor_80072dec->startWalk(0x97,0x37,2);
-																									_actor_80072df4->startWalk(0x97,0x37,2);
+																									_actor_80072de8->startWalk(0x97, 0x37, 2);
+																									_actor_80072dec->startWalk(0x97, 0x37, 2);
+																									_actor_80072df4->startWalk(0x97, 0x37, 2);
 																									_actor_80072df0->waitUntilFlag8SetThenSet1000AndWaitFor4();
 																									_actor_80072df0->updateSequence(6);
 																									uint16 dialog[2000];
 																									dialog[0] = 0;
 																									_vm->_talk->loadText(0x5ea2, dialog, 2000);
 
-																									_vm->_talk->displayDialogAroundPoint(dialog,0x27,0xc,0xc01,0,0x5ea2);
+																									_vm->_talk->displayDialogAroundPoint(dialog, 0x27, 0xc, 0xc01, 0, 0x5ea2);
 																									_actor_80072df0->waitUntilFlag8And4AreSet();
 																									_actor_80072df0->_x_pos = 0xcf;
 																									_actor_80072df0->_y_pos = 0x90;
@@ -288,7 +288,7 @@ void CutScene::scene1() {
 
 																									dialog[0] = 0;
 																									_vm->_talk->loadText(0x5ecc, dialog, 2000);
-																									_vm->_talk->displayDialogAroundPoint(dialog,0x14,6,0xc01,0,0x5ecc);
+																									_vm->_talk->displayDialogAroundPoint(dialog, 0x14, 6, 0xc01, 0, 0x5ecc);
 																									_vm->waitForFrames(0x3c);
 																								}
 																							}
@@ -317,7 +317,7 @@ void CutScene::scene1() {
 	// fade_related_calls_with_1f();
 	_vm->clearFlags(ENGINE_FLAG_20000);
 	// DisableVSyncEvent();
-	//file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+	//file_read_to_buffer(s_cursor.act_80011c44, actor_dictionary);
 	// EnableVSyncEvent();
 	if (isFlag10Set) {
 		_vm->setFlags(ENGINE_FLAG_10);
@@ -341,67 +341,64 @@ void CutScene::fadeScreenAndResetActor(Actor *actor) {
 }
 
 void CutScene::closeUpShotOnActor(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4) {
-	FUN_8003d8e8(resourceId, sequenceId, x, param_4);
+	fun_8003d8e8(resourceId, sequenceId, x, param_4);
 	_vm->waitForFrames(5);
 	// TODO call_fade_related_1f();
 }
 
-
-void CutScene::FUN_8003d8e8(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4) {
+void CutScene::fun_8003d8e8(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4) {
 	// fade_related_calls_with_1f();
 	_vm->_actorManager->clearActorFlags(2);
 	//DisableVSyncEvent();
 	_actor_80072de8 = _vm->_actorManager->loadActor(resourceId, sequenceId, x, 199, 3);
 	//EnableVSyncEvent();
 	changeBackgroundPosition(3, param_4);
-
 }
 
 void CutScene::wideAngleEveryoneAtTable() {
-	FUN_8003d388();
+	fun_8003d388();
 	// call_fade_related_1f();
-
 }
 
-void CutScene::FUN_8003d388() {
+void CutScene::fun_8003d388() {
 	uint sequenceId;
 
 	// fade_related_calls_with_1f();
 	_vm->_actorManager->clearActorFlags(2);
 	if ((_actor_80063514 & 0x80) == 0) {
-		_actor_80072de8 = _vm->_actorManager->loadActor(0x7e,0x16,0x40,0xa0,1);
+		_actor_80072de8 = _vm->_actorManager->loadActor(0x7e, 0x16, 0x40, 0xa0, 1);
 	}
-	_actor_80072dec = _vm->_actorManager->loadActor(0x7e,0,0xbf,0xba,1);
+	_actor_80072dec = _vm->_actorManager->loadActor(0x7e, 0, 0xbf, 0xba, 1);
 	if ((_actor_80063514 & 8) == 0) {
-		_actor_80072df0 = _vm->_actorManager->loadActor(0x7e,5,0x94,0x82,1);
+		_actor_80072df0 = _vm->_actorManager->loadActor(0x7e, 5, 0x94, 0x82, 1);
 	}
 	if ((_actor_80063514 & 0x10) == 0) {
-		_actor_80072df4 = _vm->_actorManager->loadActor(0x7e,10,0x6f,0x95,1);
+		_actor_80072df4 = _vm->_actorManager->loadActor(0x7e, 10, 0x6f, 0x95, 1);
 	}
 	if ((_actor_80063514 & 4) == 0) {
-		_actor_80072df8 = _vm->_actorManager->loadActor(0x7e,0xe,0xa9,0x87,1);
+		_actor_80072df8 = _vm->_actorManager->loadActor(0x7e, 0xe, 0xa9, 0x87, 1);
 	}
 	if ((_actor_80063514 & 0x20) == 0) {
-		_actor_80072dfc = _vm->_actorManager->loadActor(0x7e,0x12,0xcd,0x8e,1);
+		_actor_80072dfc = _vm->_actorManager->loadActor(0x7e, 0x12, 0xcd, 0x8e, 1);
 	}
 	if ((_actor_80063514 & 1) == 0) {
-		_actor_80072e04 = _vm->_actorManager->loadActor(0x7e,0x19,0x10e,0x89,1);
+		_actor_80072e04 = _vm->_actorManager->loadActor(0x7e, 0x19, 0x10e, 0x89, 1);
 	}
 	if ((_actor_80063514 & 2) == 0) {
-		_actor_80072e08 = _vm->_actorManager->loadActor(0x8f,2,100,0xbc,1);
+		_actor_80072e08 = _vm->_actorManager->loadActor(0x8f, 2, 100, 0xbc, 1);
 	}
 	if ((_actor_80063514 & 0x40) != 0) {
-		_actor_80072e0c = _vm->_actorManager->loadActor(0x8f,0,0xd2,100,1);
-		_actor_800830a0 = _vm->_actorManager->loadActor(0x8f,1,0xe6,0x6e,1);
+		_actor_80072e0c = _vm->_actorManager->loadActor(0x8f, 0, 0xd2, 100, 1);
+		_actor_800830a0 = _vm->_actorManager->loadActor(0x8f, 1, 0xe6, 0x6e, 1);
 	}
-	_actor_800830b8 = _vm->_actorManager->loadActor(0xaa,0,0x2e,0x2d,1);
+	_actor_800830b8 = _vm->_actorManager->loadActor(0xaa, 0, 0x2e, 0x2d, 1);
 	_actor_800830b8->setFlag(ACTOR_FLAG_8000);
-	_actor_800830bc = _vm->_actorManager->loadActor(0xaa,1,0x115,0x22,1);
+	_actor_800830bc = _vm->_actorManager->loadActor(0xaa, 1, 0x115, 0x22, 1);
 	_actor_800830bc->setFlag(ACTOR_FLAG_100);
 	_actor_800830bc->setFlag(ACTOR_FLAG_8000);
 	_actor_800830bc->_priorityLayer = 4;
 	if ((_actor_80063514 & 0x100) != 0) {
-		_actor_800830c0 = _vm->_actorManager->loadActor(0x7e,0x1c,0x21,0x87,1);
+		_actor_800830c0 = _vm->_actorManager->loadActor(0x7e, 0x1c, 0x21, 0x87, 1);
 	}
 	if ((_actor_80063514 & 0x200) != 0) {
 		if ((_actor_80063514 & 0x800) == 0) {
@@ -410,11 +407,11 @@ void CutScene::FUN_8003d388() {
 		else {
 			sequenceId = 4;
 		}
-		_actor_800830d4 = _vm->_actorManager->loadActor(0xaa,sequenceId,0xf4,199,1);
+		_actor_800830d4 = _vm->_actorManager->loadActor(0xaa, sequenceId, 0xf4, 199, 1);
 		_actor_800830d4->setFlag(ACTOR_FLAG_8000);
 	}
 	if ((_actor_80063514 & 0x400) != 0) {
-		_actor_800830dc = _vm->_actorManager->loadActor(0xaa,3,0xf4,199,1);
+		_actor_800830dc = _vm->_actorManager->loadActor(0xaa, 3, 0xf4, 199, 1);
 		_actor_800830dc->setFlag(ACTOR_FLAG_8000);
 	}
 	changeBackgroundPosition(0, 0);
@@ -425,24 +422,23 @@ void CutScene::FUN_8003d388() {
 void CutScene::closeUpKnightsAtTable() {
 	//fade_related_calls_with_1f();
 	_vm->_actorManager->clearActorFlags(2);
-	_actor_80072de8 = _vm->_actorManager->loadActor(0x7d,0,2,199,1);
-	_actor_80072dec = _vm->_actorManager->loadActor(0x81,4,2,199,1);
-	_actor_80072df0 = _vm->_actorManager->loadActor(0x81,6,2,199,1);
-	_actor_80072df4 = _vm->_actorManager->loadActor(0x81,0,2,199,1);
-	_actor_80072df8 = _vm->_actorManager->loadActor(0x81,2,2,199,1);
+	_actor_80072de8 = _vm->_actorManager->loadActor(0x7d, 0, 2, 199, 1);
+	_actor_80072dec = _vm->_actorManager->loadActor(0x81, 4, 2, 199, 1);
+	_actor_80072df0 = _vm->_actorManager->loadActor(0x81, 6, 2, 199, 1);
+	_actor_80072df4 = _vm->_actorManager->loadActor(0x81, 0, 2, 199, 1);
+	_actor_80072df8 = _vm->_actorManager->loadActor(0x81, 2, 2, 199, 1);
 	changeBackgroundPosition(1, 0);
 	_vm->waitForFrames(0xf);
 	//call_fade_related_1f();
 
 }
 
-uint16 CutScene::FUN_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5)
-{
+uint16 CutScene::fun_8003dab8(uint32 textId, uint16 x, uint16 y, uint16 param_4, int16 param_5) {
 	uint16 dialog[2000];
 	dialog[0] = 0;
 	_vm->_talk->loadText(textId, dialog, 2000);
 
-	_vm->_talk->displayDialogAroundPoint(dialog,x,y,param_4,param_5,textId);
+	_vm->_talk->displayDialogAroundPoint(dialog, x, y, param_4, param_5, textId);
 	return 1; //TODO this should return (uint)dialogText & 0xffff;
 }
 
@@ -451,8 +447,7 @@ void CutScene::cursorInventoryClearFlag400() {
 	_vm->_inventory->clearActorFlag400();
 }
 
-void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
-{
+void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2) {
 	if (newPosition == 1) {
 		_vm->_scene->setBgLayerPriority(0); //TODO investigate why this is 0 not 1
 		_vm->_scene->setMgLayerPriority(1); //TODO investigate why this is 1 not 2
@@ -463,8 +458,7 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 			Actor *actor = _vm->_actorManager->getActor(i);
 			actor->_x_pos += 0x3c0;
 		}
-	}
-	else {
+	} else {
 		if (newPosition < 2) {
 			if (newPosition != 0) {
 				return;
@@ -473,15 +467,13 @@ void CutScene::changeBackgroundPosition(uint16 newPosition, int16 sParm2)
 			_vm->_scene->setMgLayerPriority(0);
 			_vm->_scene->setFgLayerPriority(0);
 			_vm->_scene->_camera.x = 0;
-		}
-		else {
+		} else {
 			if (newPosition == 2) {
 				_vm->_screen->loadPalette(0, _palettes + 3 * 512);
 				_vm->_scene->setMgLayerPriority(2);
 				_vm->_scene->setFgLayerPriority(3);
 				_vm->_scene->_camera.x = 0;
-			}
-			else {
+			} else {
 				if (newPosition != 3) {
 					return;
 				}
@@ -512,7 +504,7 @@ void CutScene::diamondScene() {
 	actorId_00 = _vm->getINI(0x256)->actor;
 	_vm->setFlags(ENGINE_FLAG_20000);
 	actorId_02 = _vm->getINI(0x25a)->actor;
-	if ((_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x4294a,0x2601) != 2) && !actorId->actorSetSequenceAndWaitAllowSkip(2)) {
+	if ((_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02, 1, 0, 0x4294a, 0x2601) != 2) && !actorId->actorSetSequenceAndWaitAllowSkip(2)) {
 		actorId->updateSequence(3);
 		if (!actorId_01->actorSetSequenceAndWaitAllowSkip(0x18)) {
 			_vm->waitForFramesAllowSkip(0x2c);
@@ -523,7 +515,7 @@ void CutScene::diamondScene() {
 			//TODO call_fade_related_1f();
 			if (!actorId_00->actorSetSequenceAndWaitAllowSkip(0)) {
 				// TODO is this needed playSoundFromTxtIndex(0x42A66);
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_00,1,2,0x42a66,0x3c01) != 2) {
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_00, 1, 2, 0x42a66, 0x3c01) != 2) {
 					_vm->waitForFramesAllowSkip(0x13);
 					//TODO fade_related_calls_with_1f();
 					_vm->_screen->loadPalette(0, palette);
@@ -539,8 +531,8 @@ void CutScene::diamondScene() {
 					actorId_03->_priorityLayer = 4;
 					if (!actorId->waitUntilFlag4IsSetAllowSkip()) {
 						actorId->updateSequence(5);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_01,0x10,2,0x42ac2,0x3c01) != 2 &&
-							_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02,1,0,0x42b56,0x2601) != 2) {
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_01, 0x10, 2, 0x42ac2, 0x3c01) != 2 &&
+							_vm->_talk->somethingTextAndSpeechAndAnimRelated(actorId_02, 1, 0, 0x42b56, 0x2601) != 2) {
 							_vm->waitForFramesAllowSkip(0x3b);
 						}
 					}
@@ -578,53 +570,53 @@ void CutScene::knightsSavedBackAtCastle() {
 	_vm->setFlags(ENGINE_FLAG_20000);
 	closeUpKnightsAtTable();
 //	playSoundFromTxtIndex(0x7854);
-	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,10,4,0x7854,0xc01) != 2) {
-		closeUpShotOnActor(0xd8,0,0xfd,0x60);
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 10, 4, 0x7854, 0xc01) != 2) {
+		closeUpShotOnActor(0xd8, 0, 0xfd, 0x60);
 //		playSoundFromTxtIndex(0x78c6);
-		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,4,0,0x78c6,0x701) != 2) {
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 4, 0, 0x78c6, 0x701) != 2) {
 			fadeScreenAndResetActor(_actor_80072de8);
 			closeUpKnightsAtTable();
 //			playSoundFromTxtIndex(0x78e8);
-			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,3,0,0x78e8,0x2e01) != 2) {
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 3, 0, 0x78e8, 0x2e01) != 2) {
 				wideAngleEveryoneAtTable();
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e04,0x1a,0x19,0x7a1e,0x3e01) != 2) {
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e04, 0x1a, 0x19, 0x7a1e, 0x3e01) != 2) {
 					_actor_80072e04->_walkSpeed = 0x10000;
 					_actor_80072e04->setFlag(ACTOR_FLAG_800);
 					_actor_80072e04->updateSequence(0x21);
-					_actor_80072e04->startWalk(0x13f,0x6e,2);
+					_actor_80072e04->startWalk(0x13f, 0x6e, 2);
 					// wait for pathfinding to complete
 					while (_actor_80072e04->isFlagSet(ACTOR_FLAG_10)) { //TODO move to method on Actor waitForPathfinding() ??
 						//empty
 					}
 					_actor_80063514 = _actor_80063514 | 1;
-					closeUpShotOnActor(0xd3,0,0x233,0x17a);
+					closeUpShotOnActor(0xd3, 0, 0x233, 0x17a);
 //					playSoundFromTxtIndex(0x7aba);
-					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,9,0,0x7aba,0x2e01) != 2) {
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 9, 0, 0x7aba, 0x2e01) != 2) {
 						fadeScreenAndResetActor(_actor_80072de8);
-						closeUpShotOnActor(0xd8,0,0xfd,0x60);
+						closeUpShotOnActor(0xd8, 0, 0xfd, 0x60);
 //						playSoundFromTxtIndex(0x7b60);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,5,0,0x7b60,0x701) != 2) {
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 5, 0, 0x7b60, 0x701) != 2) {
 							fadeScreenAndResetActor(_actor_80072de8);
 							wideAngleEveryoneAtTable();
-							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0,9,5,0x7c20,0xc01) != 2) {
-								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0x17,0x16,0x7c9c,0x701) != 2) {
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072df0, 9, 5, 0x7c20, 0xc01) != 2) {
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 0x17, 0x16, 0x7c9c, 0x701) != 2) {
 									_vm->playOrStopSound(0x800f);
 									_vm->waitForFrames(10);
-									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0x17,0x16,0x7cf2,0x701) != 2) {
+									if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 0x17, 0x16, 0x7cf2, 0x701) != 2) {
 										closeUpKnightsAtTable();
 //										playSoundFromTxtIndex(0x7dcc);
 										_actor_80072df0->updateSequence(0x13);
 										_actor_80072df4->updateSequence(0x10);
 										_actor_80072df8->updateSequence(0x11);
-										actorId = _vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,0x12,6,0x7dcc,0xc01);
+										actorId = _vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 0x12, 6, 0x7dcc, 0xc01);
 										if ((actorId & 0xffff) != 2) {
-											closeUpShotOnActor(0xd3,0,0x233,0x17a);
+											closeUpShotOnActor(0xd3, 0, 0x233, 0x17a);
 //											playSoundFromTxtIndex(0x7e1a);
-											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,10,0,0x7e1a,0x2e01) != 2) {
+											if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 10, 0, 0x7e1a, 0x2e01) != 2) {
 												fadeScreenAndResetActor(_actor_80072de8);
 												wideAngleEveryoneAtTable();
-												if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x7e96,0x2e01) != 2) {
-													_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0x17,0x16,0x7f0a,0x701);
+												if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 4, 0, 0x7e96, 0x2e01) != 2) {
+													_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 0x17, 0x16, 0x7f0a, 0x701);
 												}
 											}
 										}
@@ -639,7 +631,7 @@ void CutScene::knightsSavedBackAtCastle() {
 	}
 	// fade_related_calls_with_1f();
 	//DisableVSyncEvent();
-//	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+//	file_read_to_buffer(s_cursor.act_80011c44, actor_dictionary);
 	//EnableVSyncEvent();
 	if (isFlag0x10Set) {
 		_vm->setFlags(ENGINE_FLAG_10);
@@ -682,7 +674,7 @@ void CutScene::flameReturnsCutScene() {
 //	load_actor_file(0x8f);
 //	load_actor_file(0xaa);
 	_actor_80063514 = (_actor_80063514 & 0xfffe) | 0x600;
-	FUN_8003d388();
+	fun_8003d388();
 	_actor_80072de8->updateSequence(0x1f);
 	_actor_80072e04->_x_pos = 0x10b;
 	_actor_80072e04->_y_pos = 99;
@@ -694,30 +686,30 @@ void CutScene::flameReturnsCutScene() {
 	_actor_80072e04->setFlag(ACTOR_FLAG_800);
 	//	call_fade_related_1f();
 	_vm->setFlags(ENGINE_FLAG_20000);
-	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x8ab2,0x2e01) != 2) {
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 4, 0, 0x8ab2, 0x2e01) != 2) {
 		_actor_80072de8->updateSequence(0x1e);
-		_actor_80072de8->startWalk(0xb0,0x6b,2);
+		_actor_80072de8->startWalk(0xb0, 0x6b, 2);
 		do {
 		} while (_actor_80072de8->isFlagSet(ACTOR_FLAG_10));
 		_actor_80072de8->updateSequence(0x1f);
-		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x8b40,0x2e01) != 2) {
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 4, 0, 0x8b40, 0x2e01) != 2) {
 			_actor_80072e04->updateSequence(0x1b);
-			_actor_80072e04->startWalk(0xd5,0x6b,2);
+			_actor_80072e04->startWalk(0xd5, 0x6b, 2);
 			do {
 			} while (_actor_80072e04->isFlagSet(ACTOR_FLAG_10));
-			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e04,0x1a,0x19,0x8bb6,0x3e01) != 2) {
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,4,0,0x8bd8,0x2e01) != 2) {
-					closeUpShotOnActor(0xd8,0,0xfd,0x60);
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072e04, 0x1a, 0x19, 0x8bb6, 0x3e01) != 2) {
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 4, 0, 0x8bd8, 0x2e01) != 2) {
+					closeUpShotOnActor(0xd8, 0, 0xfd, 0x60);
 //					playSoundFromTxtIndex(0x8c70);
-					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,7,0,0x8c70,0x701) != 2) {
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 7, 0, 0x8c70, 0x701) != 2) {
 						fadeScreenAndResetActor(_actor_80072de8);
-						closeUpShotOnActor(0xd3,0,0x233,0x17a);
+						closeUpShotOnActor(0xd3, 0, 0x233, 0x17a);
 //						playSoundFromTxtIndex(0x8cd2);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0xc,0,0x8cd2,0x2e01) != 2) {
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 0xc, 0, 0x8cd2, 0x2e01) != 2) {
 							fadeScreenAndResetActor(_actor_80072de8);
-							closeUpShotOnActor(0xd7,0,0x312,0x260);
+							closeUpShotOnActor(0xd7, 0, 0x312, 0x260);
 //							playSoundFromTxtIndex(0x8e1e);
-							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,5,0,0x8e1e,0x3e01) != 2) {
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 5, 0, 0x8e1e, 0x3e01) != 2) {
 								fadeScreenAndResetActor(_actor_80072de8);
 							}
 						}
@@ -728,7 +720,7 @@ void CutScene::flameReturnsCutScene() {
 	}
 //	fade_related_calls_with_1f();
 //	DisableVSyncEvent();
-//	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+//	file_read_to_buffer(s_cursor.act_80011c44, actor_dictionary);
 //	EnableVSyncEvent();
 	_vm->clearFlags(ENGINE_FLAG_20000);
 	if (engineFlag10Set) {
@@ -765,37 +757,37 @@ void CutScene::knightsSavedAgain() {
 	wideAngleEveryoneAtTable();
 	_vm->setFlags(ENGINE_FLAG_20000);
 	_vm->waitForFramesAllowSkip(0x3b);
-	closeUpShotOnActor(0xd3,0,0x233,0x17a);
+	closeUpShotOnActor(0xd3, 0, 0x233, 0x17a);
 	//playSoundFromTxtIndex(0x9000);
-	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0xd,0,0x9000,0x2e01) != 2) {
+	if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 0xd, 0, 0x9000, 0x2e01) != 2) {
 		fadeScreenAndResetActor(_actor_80072de8);
 		closeUpKnightsAtTable();
 //		playSoundFromTxtIndex(0x90de);
-		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,4,0,0x90de,0x2e01) != 2) {
-			closeUpShotOnActor(0xd8,0,0xfd,0x60);
+		if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 4, 0, 0x90de, 0x2e01) != 2) {
+			closeUpShotOnActor(0xd8, 0, 0xfd, 0x60);
 //			playSoundFromTxtIndex(0x921c);
-			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,8,0,0x921c,0x701) != 2) {
+			if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 8, 0, 0x921c, 0x701) != 2) {
 				fadeScreenAndResetActor(_actor_80072de8);
 				closeUpKnightsAtTable();
 //				playSoundFromTxtIndex(0x92aa);
-				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,9,4,0x92aa,0xc01) != 2) {
-					closeUpShotOnActor(0xd7,0,0x312,0x260);
+				if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 9, 4, 0x92aa, 0xc01) != 2) {
+					closeUpShotOnActor(0xd7, 0, 0x312, 0x260);
 //					playSoundFromTxtIndex(0x932c);
-					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,6,0,0x932c,0x3e01) != 2) {
+					if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 6, 0, 0x932c, 0x3e01) != 2) {
 						fadeScreenAndResetActor(_actor_80072de8);
-						closeUpShotOnActor(0xd3,2,0x87,0);
+						closeUpShotOnActor(0xd3, 2, 0x87, 0);
 //						playSoundFromTxtIndex(0x93d6);
-						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,0xe,2,0x93d6,0x2e01) != 2) {
+						if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 0xe, 2, 0x93d6, 0x2e01) != 2) {
 							fadeScreenAndResetActor(_actor_80072de8);
 							closeUpKnightsAtTable();
 //							playSoundFromTxtIndex(0x7dcc);
 							_actor_80072df0->updateSequence(0x13);
 							_actor_80072df4->updateSequence(0x10);
 							_actor_80072df8->updateSequence(0x11);
-							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec,0x12,6,0x7dcc,0xc01) != 2) {
-								closeUpShotOnActor(0xd8,0,0xfd,0x60);
+							if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072dec, 0x12, 6, 0x7dcc, 0xc01) != 2) {
+								closeUpShotOnActor(0xd8, 0, 0xfd, 0x60);
 //								playSoundFromTxtIndex(0x948c);
-								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8,9,0,0x948c,0x701) != 2) {
+								if (_vm->_talk->somethingTextAndSpeechAndAnimRelated(_actor_80072de8, 9, 0, 0x948c, 0x701) != 2) {
 									fadeScreenAndResetActor(_actor_80072de8);
 									_vm->waitForFramesAllowSkip(0x3b);
 								}
@@ -808,7 +800,7 @@ void CutScene::knightsSavedAgain() {
 	}
 	//fade_related_calls_with_1f();
 //	DisableVSyncEvent();
-//	file_read_to_buffer(s_cursor.act_80011c44,actor_dictionary);
+//	file_read_to_buffer(s_cursor.act_80011c44, actor_dictionary);
 //	EnableVSyncEvent();
 	_vm->clearFlags(ENGINE_FLAG_20000);
 	if (engineFlag10Set) {
@@ -835,19 +827,19 @@ void CutScene::tournamentCutScene() {
 	tournamentUpdateCameraX = 0x140;
 	_vm->setVsyncUpdateFunction(tournamentUpdateFunction);
 	_vm->_talk->loadText(0x4C40C, dialogText, 1000);
-	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0x1e01,1,0x4C40C);
+	_vm->_talk->displayDialogAroundPoint(dialogText, 0, 0, 0x1e01, 1, 0x4C40C);
 
 	_vm->_talk->loadText(0x4C530, dialogText, 1000);
-	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0xc01,1,0x4C530);
+	_vm->_talk->displayDialogAroundPoint(dialogText, 0, 0, 0xc01, 1, 0x4C530);
 
 	_vm->_talk->loadText(0x4C588, dialogText, 1000);
-	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0x1e01,1, 0x4C588);
+	_vm->_talk->displayDialogAroundPoint(dialogText, 0, 0, 0x1e01, 1, 0x4C588);
 
 	_vm->_talk->loadText(0x4C6B0, dialogText, 1000);
-	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0xc01,1, 0x4C6B0);
+	_vm->_talk->displayDialogAroundPoint(dialogText, 0, 0, 0xc01, 1, 0x4C6B0);
 
 	_vm->_talk->loadText(0x4C6E8, dialogText, 1000);
-	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0x1e01,1, 0x4C6E8);
+	_vm->_talk->displayDialogAroundPoint(dialogText, 0, 0, 0x1e01, 1, 0x4C6E8);
 	_vm->setVsyncUpdateFunction(NULL);
 	_vm->setFlags(ENGINE_FLAG_20000);
 	// fade_related_calls_with_1f();
@@ -866,9 +858,9 @@ void CutScene::tournamentCutScene() {
 	_vm->_scene->_camera.x = 0x3c0;
 //	call_fade_related_1f();
 	_vm->_talk->loadText(0x4C814, dialogText, 1000);
-	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0xc01,1, 0x4C814);
+	_vm->_talk->displayDialogAroundPoint(dialogText, 0, 0, 0xc01, 1, 0x4C814);
 	_vm->_talk->loadText(0x4C852, dialogText, 1000);
-	_vm->_talk->displayDialogAroundPoint(dialogText,0,0,0x1e01,1, 0x4C852);
+	_vm->_talk->displayDialogAroundPoint(dialogText, 0, 0, 0x1e01, 1, 0x4C852);
 	_vm->setFlags(ENGINE_FLAG_20000);
 //	fade_related_calls_with_1f();
 }
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index c3658af24d..c5d1957e23 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -68,11 +68,11 @@ private:
 	//Scene 1 related functions
 	void fadeScreenAndResetActor(Actor *actor);
 	void closeUpShotOnActor(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4);
-	void FUN_8003d8e8(uint16 resourceId,uint16 sequenceId,int16 x,uint32 param_4);
+	void fun_8003d8e8(uint16 resourceId,uint16 sequenceId,int16 x,uint32 param_4);
 	void wideAngleEveryoneAtTable();
-	void FUN_8003d388();
+	void fun_8003d388();
 	void closeUpKnightsAtTable();
-	uint16 FUN_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5);
+	uint16 fun_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5);
 	void cursorInventoryClearFlag400();
 	void changeBackgroundPosition(uint16 newPosition, int16 sParm2);
 	void loadPalettes();
diff --git a/engines/dragons/detection.cpp b/engines/dragons/detection.cpp
index a0b877e74d..6b44f15e5e 100644
--- a/engines/dragons/detection.cpp
+++ b/engines/dragons/detection.cpp
@@ -35,40 +35,40 @@ static const PlainGameDescriptor dragonsGames[] = {
 namespace Dragons {
 
 static const DragonsGameDescription gameDescriptions[] = {
-		{
-				{
-						"dragons",
-						0,
-						AD_ENTRY1s("bigfile.dat", "02c26712bee57266f28235fdc0207725", 44990464),
-						Common::EN_USA,
-						Common::kPlatformPSX,
-						ADGF_DROPPLATFORM,
-						GUIO0()
-				},
-				kGameIdDragons
-		},
-
-		{
-				{
-						"dragons",
-						0,
-						AD_ENTRY1s("bigfile.dat", "234234234234", 29779968),
-						Common::DE_DEU,
-						Common::kPlatformPSX,
-						ADGF_DROPPLATFORM,
-						GUIO0()
-				},
-				kGameIdDragons
-		},
-
-		{AD_TABLE_END_MARKER, 0}
+	{
+			{
+					"dragons",
+					0,
+					AD_ENTRY1s("bigfile.dat", "02c26712bee57266f28235fdc0207725", 44990464),
+					Common::EN_USA,
+					Common::kPlatformPSX,
+					ADGF_DROPPLATFORM,
+					GUIO0()
+			},
+			kGameIdDragons
+	},
+
+	{
+			{
+					"dragons",
+					0,
+					AD_ENTRY1s("bigfile.dat", "234234234234", 29779968),
+					Common::DE_DEU,
+					Common::kPlatformPSX,
+					ADGF_DROPPLATFORM,
+					GUIO0()
+			},
+			kGameIdDragons
+	},
+
+	{ AD_TABLE_END_MARKER, 0 }
 };
 
 } // End of namespace Dragons
 
 static const char * const directoryGlobs[] = {
-		"resource",
-		0
+	"resource",
+	0
 };
 
 class DragonsMetaEngine : public AdvancedMetaEngine {
@@ -169,12 +169,12 @@ bool DragonsMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADG
 	const Dragons::DragonsGameDescription *gd = (const Dragons::DragonsGameDescription *)desc;
 	if (gd) {
 		switch (gd->gameId) {
-			case Dragons::kGameIdDragons:
-				*engine = new Dragons::DragonsEngine(syst);
-				break;
-			default:
-				error("Unknown game id");
-				break;
+		case Dragons::kGameIdDragons:
+			*engine = new Dragons::DragonsEngine(syst);
+			break;
+		default:
+			error("Unknown game id");
+			break;
 		}
 	}
 	return desc != 0;
diff --git a/engines/dragons/dragonflg.cpp b/engines/dragons/dragonflg.cpp
index b7e0d7c734..75768829cd 100644
--- a/engines/dragons/dragonflg.cpp
+++ b/engines/dragons/dragonflg.cpp
@@ -28,8 +28,7 @@ namespace Dragons {
 
 // Properties
 
-Properties::Properties(uint count)
-		: _count(count) {
+Properties::Properties(uint count) : _count(count) {
 	_properties = (byte *)malloc(getSize());
 	if (!_properties) {
 		error("Failed to allocate mem for properties");
@@ -129,7 +128,6 @@ void DragonFLG::loadState(Common::ReadStream *in) {
 	in->read(savedState, 0x10);
 	_properties->init(0x10, savedState);
 	//properties->print("load");
-
 }
 
 } // End of namespace Dragons
diff --git a/engines/dragons/dragonflg.h b/engines/dragons/dragonflg.h
index 3e346bf214..43a0d05964 100644
--- a/engines/dragons/dragonflg.h
+++ b/engines/dragons/dragonflg.h
@@ -39,6 +39,7 @@ public:
 	void set(uint32 propertyId, bool value);
 	void save(uint numberToWrite, Common::WriteStream *out);
 	void print(char *prefix);
+
 private:
 	uint _count;
 	byte *_properties;
@@ -51,6 +52,7 @@ private:
 	byte *_data;
 	uint32 _dataSize;
 	Properties *_properties;
+
 public:
 	virtual ~DragonFLG();
 
diff --git a/engines/dragons/dragonimg.h b/engines/dragons/dragonimg.h
index d12fe0182c..85e5bb22be 100644
--- a/engines/dragons/dragonimg.h
+++ b/engines/dragons/dragonimg.h
@@ -45,6 +45,7 @@ private:
 	int16 _count;
 	Img *_imgObjects;
 	byte *_imgData;
+
 public:
 	DragonImg(BigfileArchive *bigfileArchive);
 	~DragonImg();


Commit: 9ea348117b2b1031781420838ae82b407d0dc30a
    https://github.com/scummvm/scummvm/commit/9ea348117b2b1031781420838ae82b407d0dc30a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fix incorrect assert() usage.

At release builds assert() statements will be skipped. Thus, it is
wrong to use functions with side effects in those.

Changed paths:
    engines/dragons/dragonini.cpp


diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index b3410804bb..9bddc39043 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -47,7 +47,8 @@ void DragonINIResource::reset() {
 		_dragonINI[i].actorResourceId = readStream->readSint16LE();
 		_dragonINI[i].sequenceId = readStream->readSint16LE();
 		_dragonINI[i].field_8 = readStream->readSint16LE();
-		assert(readStream->readUint16LE() == 0); // actorId
+		uint16 v = readStream->readUint16LE();
+		assert(v == 0); // actorId
 		_dragonINI[i].actor = NULL;
 		_dragonINI[i].sceneId = readStream->readUint16LE();
 		_dragonINI[i].field_e = readStream->readSint16LE();


Commit: 5d39aab174252c734e2968d9870f04bf58aef82f
    https://github.com/scummvm/scummvm/commit/5d39aab174252c734e2968d9870f04bf58aef82f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Whitespace fixes

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cutscene.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/dragonvar.cpp
    engines/dragons/dragonvar.h
    engines/dragons/font.cpp
    engines/dragons/font.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/minigame1.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 462dd52c25..1012402bca 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -270,7 +270,7 @@ int16 Cursor::updateIniFromScene() {
 				}
 				if (_sequenceID != 0) {
 					_iniUnderCursor = cursorOverIni;
-					_data_80072890 = _data_80072890_orig;
+					_data_80072890 = data_80072890_orig;
 					_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
@@ -282,7 +282,7 @@ int16 Cursor::updateIniFromScene() {
 //				local_44 = local_44 + local_48;
 				if (executeScript(scriptOpCall, 0)) {
 					_iniUnderCursor = cursorOverIni;
-					_data_80072890 = _data_80072890_orig;
+					_data_80072890 = data_80072890_orig;
 					_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 43d84f423f..a6d1cce96d 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -403,8 +403,7 @@ void CutScene::fun_8003d388() {
 	if ((_actor_80063514 & 0x200) != 0) {
 		if ((_actor_80063514 & 0x800) == 0) {
 			sequenceId = 2;
-		}
-		else {
+		} else {
 			sequenceId = 4;
 		}
 		_actor_800830d4 = _vm->_actorManager->loadActor(0xaa, sequenceId, 0xf4, 199, 1);
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 3ba1d90716..5beb8986c6 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -41,27 +41,26 @@ enum IniFlags {
 };
 
 
-struct DragonINI
-	{
-		uint16 id;
-		int16 iptIndex_maybe;
-		int16 field_2;
-		int16 actorResourceId;
-		uint16 sequenceId;
-		int16 field_8;
-		Actor *actor;
-		uint16 sceneId;
-		int16 field_e;
-		int16 field_10;
-		int16 field_12;
-		uint16 field_14;
-		int16 x;
-		int16 y;
-		uint16 field_1a_flags_maybe;
-		int16 field_1c;
-		int16 field_1e;
-		int16 field_20_actor_field_14;
-	};
+struct DragonINI {
+	uint16 id;
+	int16 iptIndex_maybe;
+	int16 field_2;
+	int16 actorResourceId;
+	uint16 sequenceId;
+	int16 field_8;
+	Actor *actor;
+	uint16 sceneId;
+	int16 field_e;
+	int16 field_10;
+	int16 field_12;
+	uint16 field_14;
+	int16 x;
+	int16 y;
+	uint16 field_1a_flags_maybe;
+	int16 field_1c;
+	int16 field_1e;
+	int16 field_20_actor_field_14;
+};
 
 class DragonINIResource {
 private:
@@ -69,6 +68,7 @@ private:
 	DragonINI *_dragonINI;
 	uint16 _count;
 	DragonINI *_flickerINI;
+
 public:
 	DragonINIResource(BigfileArchive *bigfileArchive);
 	void reset();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index e80a79e025..bfec818c31 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -116,75 +116,75 @@ void DragonsEngine::updateEvents() {
 	while (_eventMan->pollEvent(event)) {
 //		_input->processEvent(event);
 		switch (event.type) {
-			case Common::EVENT_QUIT:
-				quitGame();
-				break;
-			case Common::EVENT_MOUSEMOVE:
-				_cursor->updatePosition(event.mouse.x, event.mouse.y);
-				break;
-			case Common::EVENT_LBUTTONUP:
-				_leftMouseButtonUp = true;
-				_leftMouseButtonDown = false;
-				break;
-			case Common::EVENT_LBUTTONDOWN:
-				_leftMouseButtonDown = true;
-				break;
-			case Common::EVENT_RBUTTONUP:
-				_rightMouseButtonUp = true;
-				break;
-			case Common::EVENT_KEYUP:
-				if (event.kbd.keycode == Common::KEYCODE_i) {
-					_iKeyUp = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_DOWN) {
-					_downKeyUp = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_UP) {
-					_upKeyUp = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_RETURN ||
-							event.kbd.keycode == Common::KEYCODE_KP_ENTER) {
-					_enterKeyUp = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_LEFT) {
-					_leftKeyUp = true;
-					_leftKeyDown = false;
-				} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) {
-					_rightKeyUp = true;
-					_rightKeyDown = false;
-				} else if (event.kbd.keycode == Common::KEYCODE_w) {
-					_wKeyDown = false;
-				} else if (event.kbd.keycode == Common::KEYCODE_a) {
-					_aKeyDown = false;
-				} else if (event.kbd.keycode == Common::KEYCODE_s) {
-					_sKeyDown = false;
-				} else if (event.kbd.keycode == Common::KEYCODE_d) {
-					_dKeyDown = false;
-				} else if (event.kbd.keycode == Common::KEYCODE_o) {
-					_oKeyDown = false;
-				} else if (event.kbd.keycode == Common::KEYCODE_p) {
-					_pKeyDown = false;
-				}
-				break;
-			case Common::EVENT_KEYDOWN:
-				if (event.kbd.keycode == Common::KEYCODE_LEFT) {
-					_leftKeyDown = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) {
-					_rightKeyDown = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_w) {
-					_wKeyDown = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_a) {
-					_aKeyDown = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_s) {
-					_sKeyDown = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_d) {
-					_dKeyDown = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_o) {
-					_oKeyDown = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_p) {
-					_pKeyDown = true;
-				} else if (event.kbd.keycode == Common::KEYCODE_TAB) {
-					_debugMode = !_debugMode;
-				}
-				break;
-			default:
-				break;
+		case Common::EVENT_QUIT:
+			quitGame();
+			break;
+		case Common::EVENT_MOUSEMOVE:
+			_cursor->updatePosition(event.mouse.x, event.mouse.y);
+			break;
+		case Common::EVENT_LBUTTONUP:
+			_leftMouseButtonUp = true;
+			_leftMouseButtonDown = false;
+			break;
+		case Common::EVENT_LBUTTONDOWN:
+			_leftMouseButtonDown = true;
+			break;
+		case Common::EVENT_RBUTTONUP:
+			_rightMouseButtonUp = true;
+			break;
+		case Common::EVENT_KEYUP:
+			if (event.kbd.keycode == Common::KEYCODE_i) {
+				_iKeyUp = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_DOWN) {
+				_downKeyUp = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_UP) {
+				_upKeyUp = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_RETURN ||
+						event.kbd.keycode == Common::KEYCODE_KP_ENTER) {
+				_enterKeyUp = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_LEFT) {
+				_leftKeyUp = true;
+				_leftKeyDown = false;
+			} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) {
+				_rightKeyUp = true;
+				_rightKeyDown = false;
+			} else if (event.kbd.keycode == Common::KEYCODE_w) {
+				_wKeyDown = false;
+			} else if (event.kbd.keycode == Common::KEYCODE_a) {
+				_aKeyDown = false;
+			} else if (event.kbd.keycode == Common::KEYCODE_s) {
+				_sKeyDown = false;
+			} else if (event.kbd.keycode == Common::KEYCODE_d) {
+				_dKeyDown = false;
+			} else if (event.kbd.keycode == Common::KEYCODE_o) {
+				_oKeyDown = false;
+			} else if (event.kbd.keycode == Common::KEYCODE_p) {
+				_pKeyDown = false;
+			}
+			break;
+		case Common::EVENT_KEYDOWN:
+			if (event.kbd.keycode == Common::KEYCODE_LEFT) {
+				_leftKeyDown = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) {
+				_rightKeyDown = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_w) {
+				_wKeyDown = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_a) {
+				_aKeyDown = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_s) {
+				_sKeyDown = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_d) {
+				_dKeyDown = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_o) {
+				_oKeyDown = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_p) {
+				_pKeyDown = true;
+			} else if (event.kbd.keycode == Common::KEYCODE_TAB) {
+				_debugMode = !_debugMode;
+			}
+			break;
+		default:
+			break;
 		}
 	}
 }
@@ -237,7 +237,7 @@ Common::Error DragonsEngine::run() {
 }
 
 uint16 DragonsEngine::ipt_img_file_related() {
-    DragonINI *flicker = _dragonINIResource->getFlickerRecord();
+	DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 	assert(flicker);
 
 	int16 tileX = flicker->actor->_x_pos / 32;
@@ -290,8 +290,7 @@ void DragonsEngine::gameLoop() {
 				pDVar8->field_20_actor_field_14 = 2;
 				if (getINI(0xc2)->field_1e == 1) {
 					sequenceId = 0x30;
-				}
-				else {
+				} else {
 					sequenceId = 2;
 				}
 				pDVar8->actor->updateSequence(sequenceId);
@@ -322,8 +321,7 @@ void DragonsEngine::gameLoop() {
 					_counter = 0;
 				}
 			}
-		}
-		else {
+		} else {
 			LAB_80026d34:
 			uVar3 = 0;
 		}
@@ -331,8 +329,7 @@ void DragonsEngine::gameLoop() {
 		if (_cursor->updateINIUnderCursor() == 0 ||
 			(!(_cursor->_iniUnderCursor & 0x8000) && (getINI(_cursor->_iniUnderCursor - 1)->field_1a_flags_maybe & 0x4000) != 0)) { //TODO check this. This logic looks a bit strange.
 			_cursor->_cursorActivationSeqOffset = 0;
-		}
-		else {
+		} else {
 			_cursor->_cursorActivationSeqOffset = 5;
 		}
 
@@ -384,8 +381,7 @@ void DragonsEngine::gameLoop() {
 			}
 
 			performAction();
-			if ((getCurrentSceneId() == 0x1d) && (getINI(0x178)->field_12 != 0)) //cave of dilemma
-			{
+			if ((getCurrentSceneId() == 0x1d) && (getINI(0x178)->field_12 != 0)) { //cave of dilemma
 				clearFlags(ENGINE_FLAG_8);
 			} else {
 				setFlags(ENGINE_FLAG_8);
@@ -402,24 +398,22 @@ void DragonsEngine::gameLoop() {
 						sequenceId = _dragonVAR->getVar(7);
 						uVar7 = _inventory->_old_showing_value;
 						_inventory->_old_showing_value = _inventory->getType();
-						joined_r0x800271d0:
+				joined_r0x800271d0:
 						_inventory->setType(_inventory->_old_showing_value);
 						if (sequenceId == 1) {
 							LAB_800279f4:
 							_inventory->_old_showing_value = uVar7;
 							_inventory->inventoryMissing();
 							actorId = uVar3;
-						}
-						else {
+						} else {
 							_counter = 0;
 							_inventory->setType(1);
 							_inventory->openInventory();
-							joined_r0x80027a38:
+				joined_r0x80027a38:
 							if (_cursor->_iniItemInHand == 0) {
 								_cursor->_sequenceID = 1;
 								actorId = uVar3;
-							}
-							else {
+							} else {
 								_cursor->_sequenceID = 5;
 								actorId = uVar3;
 							}
@@ -439,8 +433,7 @@ void DragonsEngine::gameLoop() {
 										_inventory->_old_showing_value = _inventory->getType();
 										goto joined_r0x800271d0;
 									}
-								}
-								else {
+								} else {
 									if (_inventory->addItem(_cursor->_iniItemInHand)) {
 										_cursor->_sequenceID = 1;
 										waitForFrames(1);
@@ -450,20 +443,19 @@ void DragonsEngine::gameLoop() {
 										continue;
 									}
 								}
-							}
-							else {
+							} else {
 								if (_cursor->_iniUnderCursor != 0x8001) goto LAB_80027ab4;
 								if (_inventory->getSequenceId() == 0) goto LAB_80027294;
 							}
 							if ((_cursor->_iniUnderCursor == 0x8001) && (_inventory->getSequenceId() == 1)) {
 								_inventory->setType(2);
 								_inventory->_old_showing_value = uVar6;
-								FUN_80038890();
+								fun_80038890();
 								actorId = uVar3;
 								continue;
 							}
 						}
-						LAB_80027ab4:
+				LAB_80027ab4:
 						_counter = 0;
 						_cursor->_data_80072890 = _cursor->_iniUnderCursor;
 						if (_cursor->_sequenceID < 5) {
@@ -472,8 +464,7 @@ void DragonsEngine::gameLoop() {
 							if (_bit_flags_8006fbd8 != 0) {
 								clearFlags(ENGINE_FLAG_8);
 							}
-						}
-						else {
+						} else {
 							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 							walkFlickerToObject();
 							if (_bit_flags_8006fbd8 != 0) {
@@ -484,23 +475,24 @@ void DragonsEngine::gameLoop() {
 						}
 					}
 				}
-			}
-			else {
+			} else {
 				if (_inventory->getType() == 2) {
 					uVar6 = _inventory->getType();
 					if (checkForInventoryButtonRelease() && isInputEnabled()) {
 						uVar7 = _inventory->_old_showing_value;
-						if (_dragonVAR->getVar(7) == 1) goto LAB_800279f4;
+						if (_dragonVAR->getVar(7) == 1)
+							goto LAB_800279f4;
 						_counter = 0;
 						_inventory->setType(1);
 						_inventory->_old_showing_value = uVar6;
 						_inventory->openInventory();
 						goto joined_r0x80027a38;
 					}
-					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) goto LAB_80027ab4;
+					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8))
+						goto LAB_80027ab4;
 				}
 			}
-			LAB_80027b58:
+	LAB_80027b58:
 			runINIScripts();
 			actorId = uVar3;
 			continue;
@@ -523,15 +515,14 @@ void DragonsEngine::gameLoop() {
 					_inventory->closeInventory();
 					_inventory->setType(0);
 					if (_inventory->_old_showing_value == 2) {
-						FUN_80038994();
+						fun_80038994();
 					}
-				}
-				else {
+				} else {
 					if (_cursor->_iniUnderCursor != 0x8002) goto LAB_8002790c;
 					_inventory->closeInventory();
 					_inventory->setType(2);
 					if (_inventory->_old_showing_value != 2) {
-						FUN_80038890();
+						fun_80038890();
 					}
 				}
 				_inventory->_old_showing_value = uVar6;
@@ -572,15 +563,15 @@ void DragonsEngine::gameLoop() {
 				}
 				continue;
 			}
-			if (_cursor->_iniItemInHand == 0) goto LAB_80027b58;
+			if (_cursor->_iniItemInHand == 0)
+				goto LAB_80027b58;
 			//drop item back into inventory
 			if (_inventory->addItemIfPositionIsEmpty(_cursor->_iniItemInHand, _cursor->_x, _cursor->_y)) {
 				Actor *invActor = _inventory->getInventoryItemActor(_cursor->_iniItemInHand);
 				invActor->_flags = 0;
 				invActor->_priorityLayer = 0;
 				invActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-				invActor->updateSequence(
-						 getINI(_cursor->_iniItemInHand - 1)->field_8 * 2 + 10);
+				invActor->updateSequence(getINI(_cursor->_iniItemInHand - 1)->field_8 * 2 + 10);
 				_cursor->_iniItemInHand = 0;
 				invActor->setFlag(ACTOR_FLAG_40);
 				invActor->setFlag(ACTOR_FLAG_80);
@@ -592,7 +583,7 @@ void DragonsEngine::gameLoop() {
 				}
 			}
 		}
-		LAB_8002790c:
+LAB_8002790c:
 		if ((_cursor->_iniItemInHand == 0) ||
 			(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4))))
 			goto LAB_80027b58;
@@ -718,9 +709,9 @@ void DragonsEngine::updateActorSequences() {
 		}
 
 		if (actor->_flags & ACTOR_FLAG_40 &&
-			!(actor->_flags & ACTOR_FLAG_4) &&
-			!(actor->_flags & ACTOR_FLAG_400) &&
-			(actor->_sequenceTimer == 0 || actor->_flags & ACTOR_FLAG_1)) {
+				!(actor->_flags & ACTOR_FLAG_4) &&
+				!(actor->_flags & ACTOR_FLAG_400) &&
+				(actor->_sequenceTimer == 0 || actor->_flags & ACTOR_FLAG_1)) {
 			debug(5, "Actor[%d] execute sequenceOp", actorId);
 
 			if (actor->_flags & ACTOR_FLAG_1) {
@@ -864,8 +855,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 //			actors[(uint)uVar5]._sequenceID = 8;
 //			actors[(uint)uVar5]._priorityLayer_maybe = 0;
 //		}
-	}
-	else {
+	} else {
 		if (flickerINI->sceneId == currentSceneId) {
 			if ((flickerINI == NULL) || flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
 				if ((flickerINI->sceneId == currentSceneId)
@@ -937,8 +927,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 //			actors[(uint)uVar5]._sequenceID = 8;
 //			actors[(uint)uVar5]._priorityLayer_maybe = 0;
 //		}
-		}
-		else {
+		} else {
 			if (flickerINI->sceneId == currentSceneId) {
 				if (flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
 					if (_inventory->isActorSet()) {
@@ -950,9 +939,9 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 						_bit_flags_8006fbd8 = _bit_flags_8006fbd8 | 2;
 					}
 					if (flickerINI->actor->isFlagClear(ACTOR_FLAG_2000)
-					&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
-					&& flickerINI->actor->_sequenceID2 != -1
-					&& flickerINI->actor->_sequenceID2 != flickerINI->actor->_sequenceID) {
+							&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
+							&& flickerINI->actor->_sequenceID2 != -1
+							&& flickerINI->actor->_sequenceID2 != flickerINI->actor->_sequenceID) {
 						flickerINI->actor->updateSequence(flickerINI->actor->_sequenceID2);
 					}
 				}
@@ -1094,8 +1083,7 @@ void DragonsEngine::performAction() {
 		if (((uVar4 & 0xffff) == 0) && ((uVar6 & 0xfffd) == 0)) {
 			_talk->flickerRandomDefaultResponse();
 		}
-	}
-	else {
+	} else {
 		_scriptOpcodes->_data_80071f5c--;
 	}
 	_flags |= uVar1 & ENGINE_FLAG_8;
@@ -1134,12 +1122,11 @@ bool DragonsEngine::checkForActionButtonRelease() {
 	return _leftMouseButtonUp || _enterKeyUp;
 }
 
-void DragonsEngine::FUN_80038890() {
-	error("FUN_80038890"); //TODO
+void DragonsEngine::fun_80038890() {
+	error("fun_80038890"); //TODO
 }
 
-void DragonsEngine::walkFlickerToObject()
-{
+void DragonsEngine::walkFlickerToObject() {
 	uint16 targetX;
 	uint16 targetY;
 	uint uVar7;
@@ -1152,7 +1139,7 @@ void DragonsEngine::walkFlickerToObject()
 		if (_cursor->_data_80072890 != 0) {
 
 			if (!(READ_LE_UINT16(_dragonOBD->getFromOpt(_cursor->_data_80072890 - 1) + 4) & 8)
-			&& (_inventory->getType() == 0) && !isFlagSet(ENGINE_FLAG_200000)) {
+					&& (_inventory->getType() == 0) && !isFlagSet(ENGINE_FLAG_200000)) {
 				targetINI = getINI(_cursor->_data_80072890 - 1);
 				if ((targetINI->field_1a_flags_maybe & 1) == 0) {
 					if (targetINI->actorResourceId == -1) {
@@ -1161,8 +1148,7 @@ void DragonsEngine::walkFlickerToObject()
 					Img *img = _dragonImg->getImg(targetINI->field_2);
 					targetX = img->field_a;
 					targetY = img->field_c;
-				}
-				else {
+				} else {
 					targetX = targetINI->actor->_x_pos;
 					targetY = targetINI->actor->_y_pos;
 				}
@@ -1198,8 +1184,7 @@ void DragonsEngine::walkFlickerToObject()
 					(int)((uVar7 + (uint)_scene->_camera.x) * 0x10000) >> 0x10,
 					(int)((uVar8 + (uint)_scene->_camera.y) * 0x10000) >> 0x10,0);
 		}
-	}
-	else {
+	} else {
 		if (_cursor->_data_80072890 != 0) {
 			_bit_flags_8006fbd8 = 3;
 			return;
@@ -1209,8 +1194,8 @@ void DragonsEngine::walkFlickerToObject()
 	return;
 }
 
-void DragonsEngine::FUN_80038994() {
-	error("FUN_80038994"); //TODO
+void DragonsEngine::fun_80038994() {
+	error("fun_80038994"); //TODO
 }
 
 void DragonsEngine::reset_screen_maybe() {
@@ -1253,7 +1238,7 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 	_screen->loadPalette(4, _cursor->getPalette());
 	_screen->updatePaletteTransparency(4, 1, 0xff, true);
 
-	// TODO FUN_80017010_update_actor_texture_maybe();
+	// TODO fun_80017010_update_actor_texture_maybe();
 	if (sceneId > 2) {
 		_dragonVAR->setVar(1, 1);
 	}
@@ -1300,7 +1285,7 @@ void DragonsEngine::reset() {
 
 void DragonsEngine::runSceneUpdaterFunction() {
 	if ((isFlagSet(ENGINE_FLAG_20) && (_run_func_ptr_unk_countdown_timer == 0)) &&
-		(_run_func_ptr_unk_countdown_timer = 1, _sceneUpdateFunction != NULL)) {
+			(_run_func_ptr_unk_countdown_timer = 1, _sceneUpdateFunction != NULL)) {
 		_sceneUpdateFunction();
 	}
 }
@@ -1314,11 +1299,10 @@ void DragonsEngine::setVsyncUpdateFunction(void (*newUpdateFunction)()) {
 }
 
 void DragonsEngine::seedRandom(int32 seed) {
-		_randomState = seed * -0x2b0e2b0f;
+	_randomState = seed * -0x2b0e2b0f;
 }
 
-uint32 DragonsEngine::shuffleRandState()
-{
+uint32 DragonsEngine::shuffleRandState() {
 	uint32 returnBit;
 
 	returnBit = _randomState & 1;
@@ -1415,8 +1399,7 @@ void DragonsEngine::updatePaletteCycling() {
 						}
 						palette[(uint16)_paletteCyclingTbl[loopIndex].startOffset] = uVar11;
 						_paletteCyclingTbl[loopIndex].updateCounter = _paletteCyclingTbl[loopIndex].updateInterval;
-					}
-					else {
+					} else {
 						if (uVar8 < uVar14) {
 							uint16 uVar11 = palette[uVar14];
 							uint16 uVar15 = uVar8;
@@ -1432,8 +1415,7 @@ void DragonsEngine::updatePaletteCycling() {
 									_paletteCyclingTbl[loopIndex].updateInterval;
 						}
 					}
-				}
-				else {
+				} else {
 					_paletteCyclingTbl[loopIndex].updateCounter = _paletteCyclingTbl[loopIndex].updateCounter + -1;
 				}
 			}
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index e841ce598c..07393a8acb 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -152,6 +152,7 @@ public:
 
 	Screen *_screen;
 	uint16 _sceneId1; //TODO wire this up. I think it might be where to restore save game from?
+
 private:
 	BigfileArchive *_bigfileArchive;
 	DragonFLG *_dragonFLG;
@@ -295,17 +296,17 @@ private:
 	bool isInputEnabled();
 	bool checkForInventoryButtonRelease();
 
-	void FUN_80038890();
+	void fun_80038890();
 	void walkFlickerToObject();
-	void FUN_80038994();
+	void fun_80038994();
 
 	void seedRandom(int32 seed);
 	uint32 shuffleRandState();
-	void FUN_8002931c();
+	void fun_8002931c();
 
 	void initializeSound();
 
-	void SomeInitSound_FUN_8003f64c();
+	void SomeInitSound_fun_8003f64c();
 };
 
 DragonsEngine *getEngine();
diff --git a/engines/dragons/dragonvar.cpp b/engines/dragons/dragonvar.cpp
index c5bf58b92c..9cb18a87e0 100644
--- a/engines/dragons/dragonvar.cpp
+++ b/engines/dragons/dragonvar.cpp
@@ -29,7 +29,7 @@ DragonVAR::DragonVAR(BigfileArchive *bigfileArchive): _bigfileArchive(bigfileArc
 }
 
 DragonVAR::~DragonVAR() {
-		delete _data;
+	delete _data;
 }
 
 uint16 DragonVAR::getVar(uint16 offset) {
diff --git a/engines/dragons/dragonvar.h b/engines/dragons/dragonvar.h
index 5ad7ff28ae..df0e255631 100644
--- a/engines/dragons/dragonvar.h
+++ b/engines/dragons/dragonvar.h
@@ -32,6 +32,7 @@ class DragonVAR {
 private:
 	byte *_data;
 	BigfileArchive *_bigfileArchive;
+
 public:
 	virtual ~DragonVAR();
 
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 4f56db6129..418caf904d 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -115,7 +115,6 @@ void FontManager::addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 f
 	screenTextEntry->surface = _fonts[fontType]->render(text, length);
 
 	_screenTexts.push_back(screenTextEntry);
-
 }
 
 void FontManager::draw() {
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index db90dc7b93..0c801a9ca5 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -39,11 +39,13 @@ private:
 	uint16 *_map;
 	byte *_pixels;
 	uint32 _numChars;
+
 public:
 	Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelOffset, uint32 pixelSize);
 	~Font();
 	Graphics::Surface *render(uint16 *text, uint16 length);
 	void renderToSurface(Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint16 length);
+
 private:
 	uint16 mapChar(uint16 in);
 };
@@ -56,6 +58,7 @@ struct ScreenTextEntry {
 class FontManager {
 public:
 	Font *_fonts[3];
+
 private:
 	uint16 _dat_80086f48_fontColor_flag;
 	DragonsEngine *_vm;
@@ -70,6 +73,7 @@ public:
 	void draw();
 	void clearText();
 	void updatePalette();
+
 private:
 	Font *loadFont(uint16 index, Common::SeekableReadStream &stream);
 	void loadPalettes();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index e0e6a75e72..53bff1191f 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -34,32 +34,32 @@ namespace Dragons {
 
 
 static const Common::Point positionTable[4] = {
-		Common::Point(2,0),
-		Common::Point(0xce,0),
-		Common::Point(2,0x9e),
-		Common::Point(0xce,0x9e)
+	Common::Point(2,0),
+	Common::Point(0xce,0),
+	Common::Point(2,0x9e),
+	Common::Point(0xce,0x9e)
 };
 
 static const int16 bagBounceTable[4] = {
-		-5, -0xa, -5, 0
+	-5, -0xa, -5, 0
 };
 
 static const int16 invXPosTable[41] = {
-				0x0080, 0x00a0, 0x00c0, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
-				0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
-				0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
-				0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
-				0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
-				0x0100
+	0x0080, 0x00a0, 0x00c0, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+	0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+	0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+	0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+	0x0100, 0x0020, 0x0040, 0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+	0x0100
 };
 
 static const int16 invYPosTable[41] = {
-				0x0028, 0x0028, 0x0028, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040,
-				0x0040, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058,
-				0x0058, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070,
-				0x0070, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088,
-				0x0088, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
-				0x00a0
+	0x0028, 0x0028, 0x0028, 0x0040, 0x0040, 0x0040, 0x0040, 0x0040,
+	0x0040, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058, 0x0058,
+	0x0058, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070, 0x0070,
+	0x0070, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088, 0x0088,
+	0x0088, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
+	0x00a0
 };
 
 Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
@@ -233,12 +233,10 @@ void Inventory::closeInventory() {
 
 	if (!_vm->isFlagSet(ENGINE_FLAG_400000)) {
 		_sequenceId = 0;
-	}
-	else {
+	} else {
 		if (_old_showing_value == 2) {
 			_sequenceId = 3;
-		}
-		else {
+		} else {
 			_sequenceId = 1;
 		}
 	}
@@ -262,7 +260,7 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 		if (_inventoryItemTbl[i]) {
 			Actor *item = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 			if (item->_x_pos - 0x10 <= x && x < item->_x_pos + 0x10
-				&& item->_y_pos - 0xc <= y && y < item->_y_pos + 0xc) {
+					&& item->_y_pos - 0xc <= y && y < item->_y_pos + 0xc) {
 				return _inventoryItemTbl[i];
 			}
 		}
@@ -319,8 +317,7 @@ void Inventory::closeInventionBook() {
 	if (((((uVar2 == 0x23) || (uVar2 == 0x2d)) || (uVar2 == 0x2e)) || ((uVar2 == 0x31 || (uVar2 == 0x32)))) || (uVar2 == 0x28)) {
 		LAB_80038b9c:
 		if ((uint)_vm->_scene->getSceneId() == 0x27) goto LAB_80038bb8;
-	}
-	else {
+	} else {
 		if (uVar2 != 0x27) {
 			if (((uVar2 != 0x1c) && (uVar2 != 0x1d)) && (uVar1 = uVar2 | 0x8000, uVar2 != 0x21)) goto LAB_80038be8;
 			goto LAB_80038b9c;
@@ -329,7 +326,7 @@ void Inventory::closeInventionBook() {
 		_vm->getINI(0x206)->sceneId = 0;
 	}
 	uVar1 = (uint)_vm->_scene->getSceneId();
-	LAB_80038be8:
+LAB_80038be8:
 	_vm->_scene->loadScene(uVar1,0x1e);
 	_vm->setSceneUpdateFunction(_inventionBookPrevSceneUpdateFunc);
 	return;
@@ -378,9 +375,9 @@ bool Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		Actor *actor = _vm->_actorManager->getActor(i + ACTOR_INVENTORY_OFFSET);
 		if ((((actor->_x_pos - 0x10 <= x) &&
-			  (x < actor->_x_pos + 0x10)) &&
-			 (actor->_y_pos - 0xc <= y)) &&
-			(y < actor->_y_pos + 0xc)) {
+				(x < actor->_x_pos + 0x10)) &&
+				(actor->_y_pos - 0xc <= y)) &&
+				(y < actor->_y_pos + 0xc)) {
 			_inventoryItemTbl[i] = iniId;
 			return true;
 		}
@@ -413,8 +410,7 @@ void Inventory::inventoryMissing() {
 	_vm->clearFlags(ENGINE_FLAG_8);
 	if (counter == 0) {
 		textIndex = 0x114FA; //Hey!  My bag is missing!
-	}
-	else {
+	} else {
 		textIndex = 0x11538; //The Chancellor snaked my bag!
 	}
 	counter = counter + 1;
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 89d3140935..60d215bfcf 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -55,6 +55,7 @@ private:
 	Common::Point _inventionBookPrevFlickerINIPosition;
 
 	uint16 _inventoryItemTbl[DRAGONS_MAX_INVENTORY_ITEMS];
+
 public:
 	Inventory(DragonsEngine *vm);
 
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index aa9df0c506..e2d4465618 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -38,11 +38,11 @@ void Minigame1::run() {
 
 	//TODO this might change for different game versions.
 	const uint32 dialogIdTbl[17] = {
-			0x21312,0x2134C,0x21386,0x213C0,
-			0x213E2,0x21428,0x2146C,0x214B4,
-			0x214E4,0x21514,0x21540,0x21590,
-			0x215E2,0x2164E,0x216AA,0x216D2,
-			0x217D8
+		0x21312, 0x2134C, 0x21386, 0x213C0,
+		0x213E2, 0x21428, 0x2146C, 0x214B4,
+		0x214E4, 0x21514, 0x21540, 0x21590,
+		0x215E2, 0x2164E, 0x216AA, 0x216D2,
+		0x217D8
 	};
 /* WARNING: Could not reconcile some variable overlaps */
 /* WARNING: Globals starting with '_' overlap smaller symbols at the same address */
@@ -144,7 +144,7 @@ void Minigame1::run() {
 	local_c0[20] = dialogIdTbl[10];
 	local_c0[21] = 0x32;
 
-	memcpy(local_118,local_c0,0x58);
+	memcpy(local_118, local_c0, 0x58);
 
 	local_c0[0] = dialogIdTbl[11];
 	local_c0[1] = 0x3c;
@@ -184,19 +184,19 @@ void Minigame1::run() {
 	local_252 = 0;
 	flickerXPos = flickerActor->_x_pos;
 	local_25c = 0;
-	pusherActor = _vm->_actorManager->loadActor(0x26,1, flickerXPos,
+	pusherActor = _vm->_actorManager->loadActor(0x26, 1, flickerXPos,
 								  (int)(((uint)(uint16)flickerActor->_y_pos + 5) * 0x10000) >> 0x10);
 //	if (pusherActorId == -1) {
-//		ProbablyShowASCIIMessage(s_couldn't_alloc_pusher_8008e954,2,4,0,0xffffffff);
+//		ProbablyShowASCIIMessage(s_couldn't_alloc_pusher_8008e954, 2, 4, 0, 0xffffffff);
 //	}
 	pusherActor->_flags = pusherActor->_flags | 0x380;
 	pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
 	pusherActor->_y_pos = flickerActor->_y_pos + 7;
 	pusherActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	pusherActor->_priorityLayer = 6;
-	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
+	wheelsActor = _vm->_actorManager->loadActor(7, 0x11, 0, 0);
 //	if (wheelsActorId == -1) {
-//		ProbablyShowASCIIMessage(s_couldn't_alloc_wheels_8008e96c,2,4,0,0xffffffff);
+//		ProbablyShowASCIIMessage(s_couldn't_alloc_wheels_8008e96c, 2, 4, 0, 0xffffffff);
 //	}
 	wheelsActor->_flags = wheelsActor->_flags | 0x380;
 	wheelsActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
@@ -205,18 +205,18 @@ void Minigame1::run() {
 	wheelsActor->_priorityLayer = 5;
 	wheelsActor->updateSequence(0x11);
 	local_242 = 0;
-	catActor = _vm->_actorManager->loadActor(7,9,0,0);
+	catActor = _vm->_actorManager->loadActor(7, 9, 0, 0);
 //	if (catActorId == -1) {
-//		ProbablyShowASCIIMessage(s_couldn't_alloc-cat_8008e984,2,4,0,0xffffffff);
+//		ProbablyShowASCIIMessage(s_couldn't_alloc-cat_8008e984, 2, 4, 0, 0xffffffff);
 //	}
 	catActor->_flags = catActor->_flags | 0x380;
 	catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	catActor->_priorityLayer = 0;
 	i = 0;
 	while (i < 3) {
-		targetActorIdTbl[(uint)i + 1] = _vm->_actorManager->loadActor(8,1,0,0,0);
+		targetActorIdTbl[(uint)i + 1] = _vm->_actorManager->loadActor(8, 1, 0, 0, 0);
 //		if (targetActorIdTbl[(uint)i + 1] == -1) {
-//			ProbablyShowASCIIMessage(s_couldn't_alloc_target!_8008e998,2,4,0,0xffffffff);
+//			ProbablyShowASCIIMessage(s_couldn't_alloc_target!_8008e998, 2, 4, 0, 0xffffffff);
 //		}
 		targetActorIdTbl[(uint)i + 1]->_flags = targetActorIdTbl[(uint)i + 1]->_flags | 0x380;
 		targetActorIdTbl[(uint)i + 1]->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
@@ -224,14 +224,12 @@ void Minigame1::run() {
 		//TODO FUN_80017010_update_actor_texture_maybe(1);
 		i = i + 1;
 	}
-	i = 0;
-	while (i < 8) {
-		local_188[(uint)i] = 0;
-		i = i + 1;
+	for (i = 0; i < 8; i++) {
+		local_188[i] = 0;
 	}
-	dustSpriteActor = _vm->_actorManager->loadActor(8,8,100,100,0);
+	dustSpriteActor = _vm->_actorManager->loadActor(8, 8, 100, 100, 0);
 //	if (dustSpriteActorId == 0xffff) {
-//		ProbablyShowASCIIMessage(s_couldn't_alloc_dust_sprite!_8008e9b0,2,5,0,0xffffffff);
+//		ProbablyShowASCIIMessage(s_couldn't_alloc_dust_sprite!_8008e9b0, 2, 5, 0, 0xffffffff);
 //	}
 	dustSpriteActor->_flags = dustSpriteActor->_flags | 0x380;
 	dustSpriteActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
@@ -269,410 +267,379 @@ void Minigame1::run() {
 				local_21e = local_21e + -1;
 			}
 			switch (gameState) {
-				case 0:
-					break;
-				case 1: //cat in the catapult ready to fire.
-					if (local_252 == 0) {
-						if (local_246 != 8) {
-							local_246 = 0;
-						}
-//						iVar6 = IsButtonBeingPressed((uint)DAT_800728ac,0);
-						if (!_vm->isActionButtonPressed()) {
-							if (local_25c == 0) {
-								if ((((flickerActor->_sequenceID != 0) &&
-									  (flickerActor->_sequenceID != 5)) &&
-									 (flickerActor->_sequenceID != 6)) ||
-									((flickerActor->_flags & 4) != 0)) {
-									flickerActor->updateSequence(0);
-								}
+			case 0:
+				break;
+			case 1: //cat in the catapult ready to fire.
+				if (local_252 == 0) {
+					if (local_246 != 8) {
+						local_246 = 0;
+					}
+//						iVar6 = IsButtonBeingPressed((uint)DAT_800728ac, 0);
+					if (!_vm->isActionButtonPressed()) {
+						if (local_25c == 0) {
+							if ((((flickerActor->_sequenceID != 0) &&
+								  (flickerActor->_sequenceID != 5)) &&
+								 (flickerActor->_sequenceID != 6)) ||
+								((flickerActor->_flags & 4) != 0)) {
+								flickerActor->updateSequence(0);
 							}
-							else {
-								local_246 = 1;
-								bVar3 = false;
-								pusherActor->updateSequence(1);
-								gameState = 2;
-								if (local_25c < 0x14) {
-									local_25a = 1;
-								}
-								else {
-									if (local_25c < 0x2d) {
-										local_25a = 2;
-									}
-									else {
-										if (local_25c < 0x169) {
-											local_25a = 3;
-										}
+						} else {
+							local_246 = 1;
+							bVar3 = false;
+							pusherActor->updateSequence(1);
+							gameState = 2;
+							if (local_25c < 0x14) {
+								local_25a = 1;
+							} else {
+								if (local_25c < 0x2d) {
+									local_25a = 2;
+								} else {
+									if (local_25c < 0x169) {
+										local_25a = 3;
 									}
 								}
 							}
-							local_25c = 0;
 						}
-						else {
-							pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
-							pusherActor->_y_pos = flickerActor->_y_pos + 7;
-							if (local_25c < 0x168) {
-								local_25c = local_25c + 1;
-								if (local_25c < 0x14) {
-									if (((pusherActor->_sequenceID != 4) &&
+						local_25c = 0;
+					} else {
+						pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
+						pusherActor->_y_pos = flickerActor->_y_pos + 7;
+						if (local_25c < 0x168) {
+							local_25c = local_25c + 1;
+							if (local_25c < 0x14) {
+								if (((pusherActor->_sequenceID != 4) &&
+								(pusherActor->_sequenceID != 2)) &&
+								(pusherActor->_sequenceID != 3)) {
+									pusherActor->updateSequence(4);
+								}
+								if (flickerActor->_sequenceID != 1) {
+									flickerActor->updateSequence(1);
+									_vm->playOrStopSound(2);
+								}
+							} else {
+								if (local_25c < 0x2d) {
+									if (((pusherActor->_sequenceID != 5) &&
 									(pusherActor->_sequenceID != 2)) &&
 									(pusherActor->_sequenceID != 3)) {
-										pusherActor->updateSequence(4);
+										pusherActor->updateSequence(5);
 									}
-									if (flickerActor->_sequenceID != 1) {
-										flickerActor->updateSequence(1);
-										_vm->playOrStopSound(2);
+									if (flickerActor->_sequenceID != 2) {
+										flickerActor->updateSequence(2);
+										_vm->playOrStopSound(3);
 									}
-								}
-								else {
-									if (local_25c < 0x2d) {
-										if (((pusherActor->_sequenceID != 5) &&
+								} else {
+									if (local_25c < 0x169) {
+										if (((pusherActor->_sequenceID != 6) &&
 										(pusherActor->_sequenceID != 2)) &&
 										(pusherActor->_sequenceID != 3)) {
-											pusherActor->updateSequence(5);
+											pusherActor->updateSequence(6);
 										}
-										if (flickerActor->_sequenceID != 2) {
-											flickerActor->updateSequence(2);
-											_vm->playOrStopSound(3);
-										}
-									}
-									else {
-										if (local_25c < 0x169) {
-											if (((pusherActor->_sequenceID != 6) &&
-											(pusherActor->_sequenceID != 2)) &&
-											(pusherActor->_sequenceID != 3)) {
-												pusherActor->updateSequence(6);
-											}
-											if (flickerActor->_sequenceID != 3) {
-												flickerActor->updateSequence(3);
-												_vm->playOrStopSound(4);
-											}
+										if (flickerActor->_sequenceID != 3) {
+											flickerActor->updateSequence(3);
+											_vm->playOrStopSound(4);
 										}
 									}
 								}
 							}
-							else {
-								if (pusherActor->_sequenceID != 6) {
-									pusherActor->updateSequence(6);
-								}
-								if (flickerActor->_sequenceID != 3) {
-									flickerActor->updateSequence(3);
-								}
+						} else {
+							if (pusherActor->_sequenceID != 6) {
+								pusherActor->updateSequence(6);
+							}
+							if (flickerActor->_sequenceID != 3) {
+								flickerActor->updateSequence(3);
 							}
 						}
 					}
-					break;
-				case 2: // initial release of cat.
-					if (flickerActor->_sequenceID == 7) {
-						if ((flickerActor->_flags & 4) != 0) {
-							i = 1;
-							while ((i < 8 && ((((int)(uint)flickerXPos < (int)((uint)auStack352[(uint)i * 3] - 6) ||
-												((uint)auStack352[(uint)i * 3 + 1] + 6 < (uint)flickerXPos)) ||
-											   (local_25a != auStack352[(uint)i * 3 + 2]))))) {
-								i = i + 1;
-							}
-							local_23c = 0;
-							if ((i != 8) &&
-								((flickerXPos < auStack352[(uint)i * 3] || (auStack352[(uint)i * 3] < flickerXPos))))
-							{
-								local_23c = (short)((int)(((uint)auStack352[(uint)i * 3] + 8) * 0x80) / 0x2a) -
-											(short)((int)((uint)flickerXPos << 7) / 0x2a);
-							}
-							local_240 = flickerXPos << 7;
-							catActor->_x_pos = flickerXPos & 0x1ff;
-							local_23e = 0x2d00;
-							local_23a = (local_25a + 3) * 0x80;
-							catActor->_y_pos = 0x5a;
-							catFieldE_scaleMaybe = 0x100;
-							catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-							catActor->updateSequence(0xc);
-							_vm->playOrStopSound(5);
-							catActor->_priorityLayer = 3;
-							flickerActor->updateSequence(8);
-							gameState = 3;
+				}
+				break;
+			case 2: // initial release of cat.
+				if (flickerActor->_sequenceID == 7) {
+					if ((flickerActor->_flags & 4) != 0) {
+						i = 1;
+						while ((i < 8 && ((((int)(uint)flickerXPos < (int)((uint)auStack352[(uint)i * 3] - 6) ||
+											((uint)auStack352[(uint)i * 3 + 1] + 6 < (uint)flickerXPos)) ||
+											(local_25a != auStack352[(uint)i * 3 + 2]))))) {
+							i = i + 1;
 						}
+						local_23c = 0;
+						if ((i != 8) && ((flickerXPos < auStack352[(uint)i * 3] || (auStack352[(uint)i * 3] < flickerXPos)))) {
+							local_23c = (short)((int)(((uint)auStack352[(uint)i * 3] + 8) * 0x80) / 0x2a) -
+										(short)((int)((uint)flickerXPos << 7) / 0x2a);
+						}
+						local_240 = flickerXPos << 7;
+						catActor->_x_pos = flickerXPos & 0x1ff;
+						local_23e = 0x2d00;
+						local_23a = (local_25a + 3) * 0x80;
+						catActor->_y_pos = 0x5a;
+						catFieldE_scaleMaybe = 0x100;
+						catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+						catActor->updateSequence(0xc);
+						_vm->playOrStopSound(5);
+						catActor->_priorityLayer = 3;
+						flickerActor->updateSequence(8);
+						gameState = 3;
 					}
-					else {
-						flickerActor->updateSequence(7);
-						_vm->playOrStopSound(1);
+				} else {
+					flickerActor->updateSequence(7);
+					_vm->playOrStopSound(1);
+				}
+				break;
+			case 3: // cat flying through the air
+				local_240 = local_240 + local_23c;
+				if ((uint)local_25a * 2 + 0xb4 < (uint)catFieldE_scaleMaybe) {
+					local_23e = local_23e - local_23a;
+					local_23a = local_23a - local_130[((uint)local_25a - 1) * 3];
+					if (local_23a < 0) {
+						local_23a = 0;
 					}
-					break;
-				case 3: // cat flying through the air
-					local_240 = local_240 + local_23c;
-					if ((uint)local_25a * 2 + 0xb4 < (uint)catFieldE_scaleMaybe) {
-						local_23e = local_23e - local_23a;
-						local_23a = local_23a - local_130[((uint)local_25a - 1) * 3];
-						if (local_23a < 0) {
-							local_23a = 0;
-						}
+				} else {
+					if ((int)(uint)catFieldE_scaleMaybe < (int)((uint)local_25a * -4 + 0xba)) {
+						local_23e = local_23e + local_23a;
+						local_23a = local_23a + local_130[((uint)local_25a - 1) * 3 + 2];
+					} else {
+						local_23a = 0;
 					}
-					else {
-						if ((int)(uint)catFieldE_scaleMaybe < (int)((uint)local_25a * -4 + 0xba)) {
-							local_23e = local_23e + local_23a;
-							local_23a = local_23a + local_130[((uint)local_25a - 1) * 3 + 2];
-						}
-						else {
-							local_23a = 0;
-						}
+				}
+				catActor->_x_pos = local_240 >> 7;
+				catActor->_y_pos = local_23e >> 7;
+				catFieldE_scaleMaybe = catFieldE_scaleMaybe - 3;
+				catActor->_scale = catFieldE_scaleMaybe;
+				if (catFieldE_scaleMaybe == 0x7f) {
+					i = 0;
+					while ((i < 8 && (((local_240 >> 7 < auStack352[(uint)i * 3] ||
+										(auStack352[(uint)i * 3 + 1] < local_240 >> 7)) ||
+									   (local_25a != auStack352[(uint)i * 3 + 2]))))) {
+						i = i + 1;
 					}
-					catActor->_x_pos = local_240 >> 7;
-					catActor->_y_pos = local_23e >> 7;
-					catFieldE_scaleMaybe = catFieldE_scaleMaybe - 3;
-					catActor->_scale = catFieldE_scaleMaybe;
-					if (catFieldE_scaleMaybe == 0x7f) {
-						i = 0;
-						while ((i < 8 && (((local_240 >> 7 < auStack352[(uint)i * 3] ||
-											(auStack352[(uint)i * 3 + 1] < local_240 >> 7)) ||
-										   (local_25a != auStack352[(uint)i * 3 + 2]))))) {
-							i = i + 1;
-						}
-						if ((i != 8) && (local_188[(uint)i] != 0)) {
-							uVar1->_field_c = 2;
-							local_21e = 0x3c;
-							if (local_250 != 0) {
-								_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
-								local_250 = 0;
-							}
-							hitCounter = hitCounter + 1;
-							catActor->updateSequence(0xd);
-							if ((i == 0) && (9 < hitCounter)) {
-								local_22c = 0x16;
-								local_252 = 2;
-								catActor->updateSequence(0xd);
-								gameState = 4;
-							}
-							else {
-								catActor->updateSequence(0xd);
-								_vm->playOrStopSound(6);
-								gameState = 8;
-								local_234 = 0;
-							}
-							if (local_252 == 0) { //successful hit maybe?
-								_vm->_talk->loadText(local_118[((uint)hitCounter - 1) * 2], auStack1008, 200);
-								_vm->_talk->displayDialogAroundPoint(auStack1008, (int)(short)(flickerXPos >> 3),0xc,0,0,
-										 local_118[((uint)hitCounter - 1) * 2]);
-								local_250 = *(short *)(local_118 + ((uint)hitCounter - 1) * 2 + 1);
-							}
-							targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->_priorityLayer = 3;
-							if (i == 0) {
-								targetActorIdTbl[(uint)local_188[0]]->updateSequence(7);
-							}
-							else {
-								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->_y_pos -= 3;
-								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(6);
-							}
-							auStack378[(uint)(uint16)local_188[(uint)i] - 1] = 0;
-							local_188[(uint)i] = 0;
-							break;
-						}
-						if ((i == 8) &&
-							((((local_25a == 1 && (local_240 >> 7 < 0x10e)) ||
-							   ((local_25a == 2 &&
-								 ((((0x7f < local_240 >> 7 && (local_240 >> 7 < 0xad)) ||
-									((0x30 < local_240 >> 7 && (local_240 >> 7 < 0x4a)))) ||
-								   ((0xf8 < local_240 >> 7 && (local_240 >> 7 < 0x10f)))))))) ||
-							  ((local_25a == 3 &&
-								(((0x3c < local_240 >> 7 && (local_240 >> 7 < 0x46)) ||
-								  ((0x101 < local_240 >> 7 && (local_240 >> 7 < 0x10a)))))))))) {
-							dustSpriteActor->_x_pos = catActor->_x_pos;
-							dustSpriteActor->_y_pos = catActor->_y_pos + 2;
-							dustSpriteActor->updateSequence(8);
-							catActor->_priorityLayer = 4;
-							dustSpriteActor->_priorityLayer = 3;
+					if ((i != 8) && (local_188[(uint)i] != 0)) {
+						uVar1->_field_c = 2;
+						local_21e = 0x3c;
+						if (local_250 != 0) {
+							_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
+							local_250 = 0;
+						}
+						hitCounter = hitCounter + 1;
+						catActor->updateSequence(0xd);
+						if ((i == 0) && (9 < hitCounter)) {
+							local_22c = 0x16;
+							local_252 = 2;
 							catActor->updateSequence(0xd);
 							gameState = 4;
+						} else {
+							catActor->updateSequence(0xd);
 							_vm->playOrStopSound(6);
-						}
-					}
-					if (catFieldE_scaleMaybe < 0x7f) {
-						catActor->_priorityLayer = 2;
-					}
-					if ((0xc < catFieldE_scaleMaybe) && (catFieldE_scaleMaybe < 0x41)) {
-						catActor->_priorityLayer = 0;
-					}
-					if ((short)catFieldE_scaleMaybe < 2) {
-						local_23e = 0x3700;
-						local_23a = 0x100;
-						local_240 = 0x4a80;
-						catFieldE_scaleMaybe = 0x30;
-						catActor->_y_pos = 0x6e;
-						catActor->_x_pos = 0x95;
-						catActor->_scale = 0x30;
-						catActor->updateSequence(0xb);
-						gameState = 5;
+							gameState = 8;
+							local_234 = 0;
+						}
+						if (local_252 == 0) { //successful hit maybe?
+							_vm->_talk->loadText(local_118[((uint)hitCounter - 1) * 2], auStack1008, 200);
+							_vm->_talk->displayDialogAroundPoint(auStack1008, (int)(short)(flickerXPos >> 3), 0xc, 0, 0,
+									 local_118[((uint)hitCounter - 1) * 2]);
+							local_250 = *(short *)(local_118 + ((uint)hitCounter - 1) * 2 + 1);
+						}
+						targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->_priorityLayer = 3;
+						if (i == 0) {
+							targetActorIdTbl[(uint)local_188[0]]->updateSequence(7);
+						} else {
+							targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->_y_pos -= 3;
+							targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(6);
+						}
+						auStack378[(uint)(uint16)local_188[(uint)i] - 1] = 0;
+						local_188[(uint)i] = 0;
+						break;
 					}
-					break;
-				case 4: // cat sliding down wall.
-					if (((catActor->_flags & 4) != 0) &&
-						((dustSpriteActor->_flags & 4) != 0)) {
-						if (catActor->_sequenceID == 0xe) {
-							if (local_23e < 0x4300) {
-								local_23e = local_23e + local_23a;
-								local_23a = local_23a + 0x18;
-								catActor->_y_pos = local_23e >> 7;
-							}
-							else {
-								catActor->updateSequence(0xf);
-								_vm->playOrStopSound(7);
-								gameState = 6;
-							}
-						}
-						else {
-							dustSpriteActor->_priorityLayer = 0;
-							catActor->_priorityLayer = 3;
-							catActor->updateSequence(0xe);
-							_vm->playOrStopSound(8);
-							local_23a = 0x40;
-						}
-					}
-					break;
-				case 5: // cat behind portcullis
-					if (local_23e >> 7 < 0x86) {
-						local_23e = local_23e + local_23a;
-						catFieldE_scaleMaybe = catFieldE_scaleMaybe + 8;
-						catActor->_y_pos = local_23e >> 7;
-						catActor->_scale = catFieldE_scaleMaybe;
+					if ((i == 8) &&
+						((((local_25a == 1 && (local_240 >> 7 < 0x10e)) ||
+						   ((local_25a == 2 &&
+							 ((((0x7f < local_240 >> 7 && (local_240 >> 7 < 0xad)) ||
+								((0x30 < local_240 >> 7 && (local_240 >> 7 < 0x4a)))) ||
+							   ((0xf8 < local_240 >> 7 && (local_240 >> 7 < 0x10f)))))))) ||
+						  ((local_25a == 3 &&
+							(((0x3c < local_240 >> 7 && (local_240 >> 7 < 0x46)) ||
+							  ((0x101 < local_240 >> 7 && (local_240 >> 7 < 0x10a)))))))))) {
+						dustSpriteActor->_x_pos = catActor->_x_pos;
+						dustSpriteActor->_y_pos = catActor->_y_pos + 2;
+						dustSpriteActor->updateSequence(8);
+						catActor->_priorityLayer = 4;
+						dustSpriteActor->_priorityLayer = 3;
+						catActor->updateSequence(0xd);
+						gameState = 4;
+						_vm->playOrStopSound(6);
 					}
-					else {
-						gameState = 6;
-						catActor->_sequenceID = 0x10;
-						catActor->_flags = catActor->_flags | 4;
+				}
+				if (catFieldE_scaleMaybe < 0x7f) {
+					catActor->_priorityLayer = 2;
+				}
+				if ((0xc < catFieldE_scaleMaybe) && (catFieldE_scaleMaybe < 0x41)) {
+					catActor->_priorityLayer = 0;
+				}
+				if ((short)catFieldE_scaleMaybe < 2) {
+					local_23e = 0x3700;
+					local_23a = 0x100;
+					local_240 = 0x4a80;
+					catFieldE_scaleMaybe = 0x30;
+					catActor->_y_pos = 0x6e;
+					catActor->_x_pos = 0x95;
+					catActor->_scale = 0x30;
+					catActor->updateSequence(0xb);
+					gameState = 5;
+				}
+				break;
+			case 4: // cat sliding down wall.
+				if (((catActor->_flags & 4) != 0) &&
+					((dustSpriteActor->_flags & 4) != 0)) {
+					if (catActor->_sequenceID == 0xe) {
+						if (local_23e < 0x4300) {
+							local_23e = local_23e + local_23a;
+							local_23a = local_23a + 0x18;
+							catActor->_y_pos = local_23e >> 7;
+						} else {
+							catActor->updateSequence(0xf);
+							_vm->playOrStopSound(7);
+							gameState = 6;
+						}
+					} else {
+						dustSpriteActor->_priorityLayer = 0;
+						catActor->_priorityLayer = 3;
+						catActor->updateSequence(0xe);
+						_vm->playOrStopSound(8);
+						local_23a = 0x40;
 					}
-					break;
-				case 6: // cat run across field
-					catActor->_priorityLayer = 3;
-					if (local_252 == 0) {
-						if (catActor->_sequenceID == 0xf) {
+				}
+				break;
+			case 5: // cat behind portcullis
+				if (local_23e >> 7 < 0x86) {
+					local_23e = local_23e + local_23a;
+					catFieldE_scaleMaybe = catFieldE_scaleMaybe + 8;
+					catActor->_y_pos = local_23e >> 7;
+					catActor->_scale = catFieldE_scaleMaybe;
+				} else {
+					gameState = 6;
+					catActor->_sequenceID = 0x10;
+					catActor->_flags = catActor->_flags | 4;
+				}
+				break;
+			case 6: // cat run across field
+				catActor->_priorityLayer = 3;
+				if (local_252 == 0) {
+					if (catActor->_sequenceID == 0xf) {
+						if ((catActor->_flags & 4) != 0) {
+							catActor->updateSequence(0x10);
+						}
+					} else {
+						if (catActor->_sequenceID == 0x10) {
 							if ((catActor->_flags & 4) != 0) {
-								catActor->updateSequence(0x10);
-							}
-						}
-						else {
-							if (catActor->_sequenceID == 0x10) {
-								if ((catActor->_flags & 4) != 0) {
-									catFieldE_scaleMaybe = 0x80;
-									local_23e = 0x4300;
-									local_23a = 0x100;
-									catActor->_y_pos = 0x86;
-									catActor->_scale = 0x80;
-									catActor->updateSequence(0xb);
-									if (flickerXPos < local_240 >> 7) {
-										sVar2 = flickerXPos + 0x32;
-									}
-									else {
-										sVar2 = flickerXPos - 0x32;
-									}
-									local_16e = sVar2 * 0x80;
-									local_23c = (short)(((int)(((uint)local_16e - (uint)local_240) * 0x10000) >> 0x10) /
-														0x1c);
+								catFieldE_scaleMaybe = 0x80;
+								local_23e = 0x4300;
+								local_23a = 0x100;
+								catActor->_y_pos = 0x86;
+								catActor->_scale = 0x80;
+								catActor->updateSequence(0xb);
+								if (flickerXPos < local_240 >> 7) {
+									sVar2 = flickerXPos + 0x32;
+								} else {
+									sVar2 = flickerXPos - 0x32;
 								}
+								local_16e = sVar2 * 0x80;
+								local_23c = (short)(((int)(((uint)local_16e - (uint)local_240) * 0x10000) >> 0x10) /
+													0x1c);
 							}
-							else {
-								if (local_23e < 0x5f00) {
-									if (local_238 == 0) {
-										local_23e = local_23e + local_23a;
-										local_240 = local_240 + local_23c;
-										catFieldE_scaleMaybe = catFieldE_scaleMaybe + 6;
-										if (0x100 < catFieldE_scaleMaybe) {
-											catFieldE_scaleMaybe = 0x100;
-										}
-										catActor->_scale = catFieldE_scaleMaybe;
-										catActor->_y_pos = local_23e >> 7;
-										catActor->_x_pos = local_240 >> 7;
-										local_238 = 1;
-									}
-									else {
-										local_238 = local_238 + -1;
+						} else {
+							if (local_23e < 0x5f00) {
+								if (local_238 == 0) {
+									local_23e = local_23e + local_23a;
+									local_240 = local_240 + local_23c;
+									catFieldE_scaleMaybe = catFieldE_scaleMaybe + 6;
+									if (0x100 < catFieldE_scaleMaybe) {
+										catFieldE_scaleMaybe = 0x100;
 									}
+									catActor->_scale = catFieldE_scaleMaybe;
+									catActor->_y_pos = local_23e >> 7;
+									catActor->_x_pos = local_240 >> 7;
+									local_238 = 1;
+								} else {
+									local_238 = local_238 + -1;
 								}
-								else {
-									if ((int)(uint)(local_240 >> 7) < (int)((uint)flickerXPos - 0x32)) {
-										if (catActor->_sequenceID != 9) {
+							} else {
+								if ((int)(uint)(local_240 >> 7) < (int)((uint)flickerXPos - 0x32)) {
+									if (catActor->_sequenceID != 9) {
+										catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+										catActor->updateSequence(9);
+									}
+									local_240 = local_240 + 0x180;
+									catActor->_x_pos = local_240 >> 7;
+								} else {
+									if ((uint)flickerXPos + 0x32 < (uint)(local_240 >> 7)) {
+										if (catActor->_sequenceID != 10) {
 											catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-											catActor->updateSequence(9);
+											catActor->updateSequence(10);
 										}
-										local_240 = local_240 + 0x180;
+										local_240 = local_240 - 0x180;
 										catActor->_x_pos = local_240 >> 7;
-									}
-									else {
-										if ((uint)flickerXPos + 0x32 < (uint)(local_240 >> 7)) {
-											if (catActor->_sequenceID != 10) {
-												catActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-												catActor->updateSequence(10);
-											}
-											local_240 = local_240 - 0x180;
-											catActor->_x_pos = local_240 >> 7;
-										}
-										else {
-											gameState = 7;
-										}
+									} else {
+										gameState = 7;
 									}
 								}
 							}
 						}
 					}
-					break;
-				case 7: // cat jumping into catapult
-					if (catActor->_priorityLayer == 0) {
-						gameState = 1;
-					}
-					else {
-						catActor->_priorityLayer = 0;
-						if (local_240 >> 7 < flickerXPos) {
-							flickerActor->updateSequence(5);
-						}
-						else {
-							flickerActor->updateSequence(6);
-						}
+				}
+				break;
+			case 7: // cat jumping into catapult
+				if (catActor->_priorityLayer == 0) {
+					gameState = 1;
+				} else {
+					catActor->_priorityLayer = 0;
+					if (local_240 >> 7 < flickerXPos) {
+						flickerActor->updateSequence(5);
+					} else {
+						flickerActor->updateSequence(6);
 					}
-					break;
-				case 8: // cat hit target.
-					if (local_234 == 1) {
-						if (local_23a < 1) {
-							local_234 = 2;
-						}
-						else {
-							local_23a--;
-							catActor->_y_pos = catActor->_y_pos + 2;
-						}
+				}
+				break;
+			case 8: // cat hit target.
+				if (local_234 == 1) {
+					if (local_23a < 1) {
+						local_234 = 2;
+					} else {
+						local_23a--;
+						catActor->_y_pos = catActor->_y_pos + 2;
 					}
-					else {
-						if (local_234 < 2) {
-							if ((local_234 == 0) && ((catActor->_flags & 4) != 0)) {
-								local_234 = 3;
-								local_232 = 0;
-							}
-						}
-						else {
-							if (local_234 == 2) {
-								local_23e = 0x4100;
-								local_240 = 0x4a80;
-								catActor->_y_pos = 0x82;
-								catActor->_x_pos = 0x95;
-								catActor->_priorityLayer = 3;
-								catActor->_scale = 0x80;
-								catActor->updateSequence(0x10);
-								gameState = 6;
-							}
-							else {
-								if (local_234 == 3) {
-									if (local_232 == 0) {
-										catActor->_priorityLayer = 2;
-										local_23a = 8;
-										local_234 = 1;
-									}
-									else {
-										local_232 = local_232 + -1;
-									}
+				} else {
+					if (local_234 < 2) {
+						if ((local_234 == 0) && ((catActor->_flags & 4) != 0)) {
+							local_234 = 3;
+							local_232 = 0;
+						}
+					} else {
+						if (local_234 == 2) {
+							local_23e = 0x4100;
+							local_240 = 0x4a80;
+							catActor->_y_pos = 0x82;
+							catActor->_x_pos = 0x95;
+							catActor->_priorityLayer = 3;
+							catActor->_scale = 0x80;
+							catActor->updateSequence(0x10);
+							gameState = 6;
+						} else {
+							if (local_234 == 3) {
+								if (local_232 == 0) {
+									catActor->_priorityLayer = 2;
+									local_23a = 8;
+									local_234 = 1;
+								} else {
+									local_232 = local_232 + -1;
 								}
 							}
 						}
 					}
-					break;
-				default:
-					//ProbablyShowASCIIMessage(s_undefined_state!_8008e9cc,2,3,0,0xffffffff);
-					gameState = 1;
-					catActor->_priorityLayer = 0;
-					flickerActor->updateSequence(0);
+				}
+				break;
+			default:
+				//ProbablyShowASCIIMessage(s_undefined_state!_8008e9cc, 2, 3, 0, 0xffffffff);
+				gameState = 1;
+				catActor->_priorityLayer = 0;
+				flickerActor->updateSequence(0);
 			}
 			if ((local_252 == 0) && (gameState != 2)) {
 				if (!_vm->isLeftKeyPressed() || (flickerXPos < 0x37)) {
@@ -685,14 +652,12 @@ void Minigame1::run() {
 							if (bVar3) {
 								pusherActor->_x_pos = flickerActor->_x_pos + 2;
 								pusherActor->_y_pos = flickerActor->_y_pos;
-							}
-							else {
+							} else {
 								pusherActor->_x_pos = flickerActor->_x_pos - 0xe;
 								pusherActor->_y_pos = flickerActor->_y_pos + 7;
 							}
 						}
-					}
-					else {
+					} else {
 						bVar3 = true;
 						local_246 = 8;
 						if (pusherActor->_sequenceID != 2) {
@@ -703,14 +668,12 @@ void Minigame1::run() {
 							if (flickerXPos < 0x36) {
 								flickerXPos = 0x36;
 							}
-						}
-						else {
+						} else {
 							flickerXPos = 0x108;
 						}
 						if (local_242 == 0) {
 							local_242 = 0xb;
-						}
-						else {
+						} else {
 							local_242 = local_242 - 1;
 						}
 						flickerActor->_x_pos = flickerXPos;
@@ -722,8 +685,7 @@ void Minigame1::run() {
 						pusherActor->_x_pos = flickerActor->_x_pos + 2;
 						pusherActor->_y_pos = flickerActor->_y_pos;
 					}
-				}
-				else {
+				} else {
 					bVar3 = false;
 					local_246 = (uint16)(gameState != 1);
 					if (pusherActor->_sequenceID != 3) {
@@ -734,8 +696,7 @@ void Minigame1::run() {
 						if (flickerXPos < 0x36) {
 							flickerXPos = 0x36;
 						}
-					}
-					else {
+					} else {
 						flickerXPos = 0x108;
 					}
 					local_242 = (short)((uint)local_242 + 1) +
@@ -753,8 +714,7 @@ void Minigame1::run() {
 				if ((local_22c == 0x14) && (hitCounter < 9)) {
 					local_252 = 1;
 					local_22c = 0x16;
-				}
-				else {
+				} else {
 					if (auStack536[(uint)local_22c * 3 + 1] == 1) {
 						i = 0;
 						while ((i < 3 && (auStack378[(uint)i] != 0))) {
@@ -762,33 +722,29 @@ void Minigame1::run() {
 						}
 						if (i == 3) {
 							debug("too many targets");
-//							ProbablyShowASCIIMessage(s_too_many_targets!_8008e9e0,2,4,0,0xffffffff);
+//							ProbablyShowASCIIMessage(s_too_many_targets!_8008e9e0, 2, 4, 0, 0xffffffff);
 						}
 						if (auStack536[(uint)local_22c * 3] == 0) {
 							targetActorIdTbl[(uint)i + 1]->_x_pos = auStack352[(uint)auStack536[(uint)local_22c * 3] * 3] + 0xd;
-						}
-						else {
+						} else {
 							targetActorIdTbl[(uint)i + 1]->_x_pos = auStack352[(uint)auStack536[(uint)local_22c * 3] * 3] + 8;
 						}
 						targetActorIdTbl[(uint)i + 1]->_y_pos = (4 - auStack352[(uint)auStack536[(uint)local_22c * 3] * 3 + 2]) * 0x20;
 						targetActorIdTbl[(uint)i + 1]->_priorityLayer = 2;
 						if (auStack536[(uint)local_22c * 3] == 0) {
 							targetActorIdTbl[(uint)i + 1]->updateSequence(3);
-						}
-						else {
+						} else {
 							targetActorIdTbl[(uint)i + 1]->updateSequence(0);
 						}
 						targetActorIdTbl[(uint)i + 1]->_priorityLayer = 2;
 						local_188[(uint)auStack536[(uint)local_22c * 3]] = i + 1;
 						auStack378[(uint)i] = auStack536[(uint)local_22c * 3] + 1;
-					}
-					else {
+					} else {
 						if ((auStack536[(uint)local_22c * 3 + 1] == 2) &&
 							(i = auStack536[(uint)local_22c * 3], local_188[(uint)i] != 0)) {
 							if (auStack536[(uint)local_22c * 3] == 0) {
 								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(5);
-							}
-							else {
+							} else {
 								targetActorIdTbl[(uint)(uint16)local_188[(uint)i]]->updateSequence(2);
 							}
 							if (local_250 != 0) {
@@ -800,22 +756,19 @@ void Minigame1::run() {
 									uVar5 = _vm->getRand(2);
 									local_168 = local_c0[(uint)uVar5 * 2 + 4];
 									local_16a = *(short *)(local_c0 + (uint)uVar5 * 2 + 5);
-								}
-								else {
+								} else {
 									uVar5 = _vm->getRand(2);
 									local_168 = local_c0[(uint)uVar5 * 2];
 									local_16a = *(short *)(local_c0 + (uint)uVar5 * 2 + 1);
 								}
-							}
-							else {
+							} else {
 								uVar5 = _vm->getRand(2);
 								local_168 = local_c0[(uint)uVar5 * 2 + 4];
 								local_16a = *(short *)(local_c0 + (uint)uVar5 * 2 + 5);
 							}
-							if ((local_252 == 0) || ((auStack536[(uint)local_22c * 3] == 0 && (local_254 == 0))))
-							{
+							if ((local_252 == 0) || ((auStack536[(uint)local_22c * 3] == 0 && (local_254 == 0)))) {
 								_vm->_talk->loadText(local_168, auStack1008, 200);
-								_vm->_talk->displayDialogAroundPoint(auStack1008,(int)(short)(flickerXPos >> 3),0xc,0,0,local_168);
+								_vm->_talk->displayDialogAroundPoint(auStack1008, (int)(short)(flickerXPos >> 3), 0xc, 0, 0, local_168);
 								local_250 = local_16a;
 							}
 							if (local_254 < 2) {
@@ -843,6 +796,7 @@ void Minigame1::run() {
 			}
 			local_22e = local_22e + 1;
 		} while (local_252 == 0);
+
 		if (flickerActor->_x_pos < 0x118) {
 			flickerActor->_x_pos = flickerActor->_x_pos + 2;
 			if (pusherActor->_sequenceID != 2) {
@@ -853,8 +807,7 @@ void Minigame1::run() {
 			wheelsActor->_x_pos = wheelsActor->_x_pos + 2;
 			if (local_242 == 0) {
 				local_242 = 0xb;
-			}
-			else {
+			} else {
 				local_242--;
 			}
 			if ((uint)wheelsActor->_sequenceID != (uint)local_242 / 3 + 0x11) {
@@ -862,6 +815,7 @@ void Minigame1::run() {
 			}
 			goto LAB_8008fa78;
 		}
+
 		if ((local_252 == 1) && ((gameState == 6 || (gameState == 1)))) {
 			pusherActor->updateSequence(9);
 			_vm->waitForFrames(0xf);
@@ -872,6 +826,7 @@ void Minigame1::run() {
 			_vm->getINI(DAT_80063a40 - 1)->actor->clearFlag(ACTOR_FLAG_100);
 			break;
 		}
+
 		if ((local_252 == 2) && (gameState == 6)) {
 			_vm->getINI(DAT_80063a40 - 1)->field_14 = 2;
 			if (local_250 != 0) {
@@ -886,7 +841,7 @@ void Minigame1::run() {
 			_vm->getINI(DAT_80063a40 - 1)->actor->clearFlag(ACTOR_FLAG_100);
 			break;
 		}
-	} while ( true );
+	} while (true);
 
 	//TODO callMaybeResetData();
 	flickerActor->updateSequence(0x15);
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index dc1b7bbba5..94bff0b2ab 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -36,7 +36,7 @@ namespace Dragons {
 Minigame2::Minigame2(DragonsEngine *vm) : _vm(vm), _dat_80093c70(false), _dat_80093c72(false), _dat_80093c74(0), _dat_80093ca8(false) {}
 
 static const uint16 unkArray[5] = {
-		0xC, 0xA, 0x8, 0x6, 0x4
+	0xC, 0xA, 0x8, 0x6, 0x4
 };
 
 void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
@@ -287,8 +287,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				uVar14->clearFlag(ACTOR_FLAG_40);
 				uVar15->clearFlag(ACTOR_FLAG_40);
 				_vm->reset_screen_maybe();
-			}
-			else {
+			} else {
 				_vm->reset_screen_maybe();
 				_vm->_scene->setSceneId(0x17);
 				flicker->sceneId = 0x17;
@@ -322,27 +321,23 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		}
 		if (_dat_80093ca4 == 0) {
 			_dat_80093ca4 = _dat_80093cc8;
-		}
-		else {
+		} else {
 			_dat_80093ca4 = _dat_80093ca4 - 1;
 		}
 		if (_dat_80093c90 == 0) {
 			_dat_80093c90 = _dat_80093c98;
-		}
-		else {
+		} else {
 			_dat_80093c90 = _dat_80093c90 - 1;
 		}
 		if (_dat_80093cc4 == 0) {
 			_dat_80093cc4 = _dat_80093cc8;
-		}
-		else {
+		} else {
 			_dat_80093cc4 = _dat_80093cc4 - 1;
 		}
 
 		if (local_27a == 0) {
 //	TODO		(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] & 0xfffe;
-		}
-		else {
+		} else {
 			/* TODO
 			(&DAT_8008316c)[(uint)uVar16 * 0xb] = local_27a + 0x27;
 			(&DAT_80083168)[(uint)uVar16 * 0xb] = local_27a + 0x27;
@@ -355,8 +350,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		if (local_278 == 0) {
 			//TODO (&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] & 0xfffe;
 			if ((local_27a != 0) || (local_258 != 0)) goto LAB_800907c4;
-		}
-		else {
+		} else {
 			/*TODO
 			(&DAT_8008316c)[(uint)uVar17 * 0xb] = local_278 + 0x27;
 			(&DAT_80083168)[(uint)uVar17 * 0xb] = local_278 + 0x27;
@@ -408,8 +402,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 							}
 							local_260 = 300;
 						}
-					}
-					else {
+					} else {
 						local_264 = 0;
 						local_260 = 300;
 //						playSoundFromTxtIndex(textIdTbl[local_262]);
@@ -513,8 +506,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						if ((!_vm->isLeftKeyPressed() && !_vm->isRightKeyPressed()) && (local_288 != 2)) {
 							if (local_288 < 2) {
 								local_288 = local_288 + 1;
-							}
-							else {
+							} else {
 								local_288 = local_288 - 1;
 							}
 						}
@@ -522,8 +514,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 							if (local_286 != 0) {
 								local_286 = local_286 - 1;
 							}
-						}
-						else {
+						} else {
 							if (local_286 < 2) {
 								local_286 = local_286 + 1;
 							}
@@ -532,15 +523,13 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					if (local_286 == 2) {
 						if (local_256 < 0x14) {
 							local_256 = local_256 + 1;
-						}
-						else {
+						} else {
 							local_256 = 0;
 						}
 					}
 					if (local_256 < 0x14) {
 						local_264 = local_264 + 1;
-					}
-					else {
+					} else {
 						local_264 = 0;
 					}
 					if ((uVar12->_flags & 4) != 0) {
@@ -553,8 +542,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						if ((!fun_80093520() && !fun_80093248()) && (local_284 != 2)) {
 							if (local_284 < 2) {
 								local_284 = local_284 + 1;
-							}
-							else {
+							} else {
 								local_284 = local_284 - 1;
 							}
 						}
@@ -562,8 +550,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 							if (local_282 != 0) {
 								local_282 = local_282 - 1;
 							}
-						}
-						else {
+						} else {
 							if (local_282 < 2) {
 								local_282 = local_282 + 1;
 							}
@@ -572,15 +559,13 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 					if (((local_286 == 2) && (local_282 == 2)) && (local_288 == local_284)) {
 						if ((_dat_80093cbc == 2) && (_dat_80093cc0 != 2)) {
 							local_258 = 2;
-						}
-						else {
+						} else {
 							if ((_dat_80093cbc == 2) || (_dat_80093cc0 != 2)) {
 								local_288 = _dat_80093cb4;
 								local_286 = _dat_80093cbc;
 								local_284 = _dat_80093cb8;
 								local_282 = _dat_80093cc0;
-							}
-							else {
+							} else {
 								local_258 = 1;
 							}
 						}
@@ -598,47 +583,39 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 							uVar12->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)local_284 * 3 + (uint)local_282]);
 							uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0]);
 						}
-					}
-					else {
+					} else {
 						if (local_258 == 1) {
 							loungealotHeadActor->updateSequence(1);
 							uVar8->updateSequence(1);
 							if (local_288 == 2) {
 								local_28 = 1;
-							}
-							else {
+							} else {
 								if (local_288 < 3) {
 									if (local_288 == 0) {
 										local_28 = 0;
-									}
-									else {
+									} else {
 										LAB_800926a4:
 										local_28 = 2;
 									}
-								}
-								else {
+								} else {
 									if (local_288 != 4) goto LAB_800926a4;
 									local_28 = 2;
 								}
 							}
-						}
-						else {
+						} else {
 							loungealotHeadActor->updateSequence(3);
 							loungealotRightArm->updateSequence(1);
 							if (local_284 == 2) {
 								local_28 = 4;
-							}
-							else {
+							} else {
 								if (local_284 < 3) {
 									if (local_284 == 0) {
 										local_28 = 3;
-									}
-									else {
+									} else {
 										LAB_80092754:
 										local_28 = 4;
 									}
-								}
-								else {
+								} else {
 									if (local_284 != 4) goto LAB_80092754;
 									local_28 = 5;
 								}
@@ -652,8 +629,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						_dat_80093c90 = 0x1e;
 					}
 				}
-			}
-			else {
+			} else {
 				if (_dat_80093c94 == 2) {
 					uVar12->_flags = uVar12->_flags | 0x1000;
 					uVar13->_flags = uVar13->_flags | 0x1000;
@@ -669,8 +645,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 						} while (_vm->isFlagSet(ENGINE_FLAG_8000));
 						loungealotHeadActor->updateSequence(2);
 						loungealotRightArm->updateSequence(3);
-					}
-					else {
+					} else {
 //						playSoundFromTxtIndex(DAT_80063ad4);
 						loungealotHeadActor->updateSequence(10);
 						fun_80093aec_dialog(0x4718,0x14,1);
@@ -694,8 +669,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			if (local_278 != 0) {
 				local_278 = local_278 - 1;
 			}
-		}
-		else {
+		} else {
 			local_272 = local_272 + -1;
 		}
 
@@ -708,16 +682,14 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 		if (fun_80093990()) {
 			if (param_1 == 1) {
 				local_278 = local_278 + 4;
-			}
-			else {
+			} else {
 				local_278 = local_278 + 6;
 			}
 		}
 		if (fun_80093a30()) {
 			if (param_1 == 1) {
 				local_278 = local_278 + 4;
-			}
-			else {
+			} else {
 				local_278 = local_278 + 6;
 			}
 		}
@@ -737,8 +709,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 //					playSoundFromTxtIndex(DAT_80063ad8);
 					loungealotHeadActor->updateSequence(0xb);
 					fun_80093aec_dialog(0x475E,0x14,1);
-				}
-				else {
+				} else {
 //					playSoundFromTxtIndex(DAT_80063adc);
 					loungealotHeadActor->updateSequence(0xc);
 					fun_80093aec_dialog(0x4774,0x14,1);
@@ -756,8 +727,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 				uVar13->updateSequence((uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0]);
 				_dat_80093c94 = 0;
 				local_26c = 0x1e;
-			}
-			else {
+			} else {
 				_dat_80093c94 = 2;
 			}
 		}
@@ -791,15 +761,13 @@ bool Minigame2::fun_80093520() {
 					_dat_80093c70 = true;
 					_dat_80093cac = 0;
 					uVar2 = false;
-				}
-				else {
+				} else {
 					if (_dat_80093ca4 == 0) {
 						_dat_80093cac = 0;
 						if (_dat_80093cb8 == _dat_80093cb4) {
 							if (_dat_80093cbc < _dat_80093cc0) {
 								_dat_80093cac = (uint16)(_dat_80093cb8 < 4);
-							}
-							else {
+							} else {
 								if (!_dat_80093cb0 && _vm->getRand(8) < 3) {
 									if (_vm->getRand(8) < 3) {
 										_dat_80093c72 = 1;
@@ -815,8 +783,7 @@ bool Minigame2::fun_80093520() {
 									_dat_80093cac = 1;
 								}
 							}
-						}
-						else {
+						} else {
 							if ((_dat_80093cb8 < _dat_80093cb4) && (_dat_80093cb4 != 2)) {
 								_dat_80093cac = 1;
 							}
@@ -824,18 +791,15 @@ bool Minigame2::fun_80093520() {
 					}
 					uVar2 = (uint)_dat_80093cac;
 				}
-			}
-			else {
+			} else {
 				_dat_80093cac = 1;
 				uVar2 = true;
 			}
-		}
-		else {
+		} else {
 			_dat_80093cac = 0;
 			uVar2 = false;
 		}
-	}
-	else {
+	} else {
 		uVar2 = _vm->isLeftKeyPressed();
 	}
 	return uVar2;
@@ -853,15 +817,13 @@ bool Minigame2::fun_80093248() {
 					_dat_80093c72 = true;
 					_dat_80093cb0 = false;
 					uVar2 = false;
-				}
-				else {
+				} else {
 					if (_dat_80093ca4 == 0) {
 						_dat_80093cb0 = false;
 						if (_dat_80093cb8 == _dat_80093cb4) {
 							if (_dat_80093cbc < _dat_80093cc0) {
 								_dat_80093cb0 = (bool)(_dat_80093cb8 != 0);
-							}
-							else {
+							} else {
 								if ((_dat_80093cac == 0) &&  _vm->getRand(8) < 3) {
 									if (_vm->getRand(8) < 3) {
 										_dat_80093c70 = true;
@@ -878,8 +840,7 @@ bool Minigame2::fun_80093248() {
 									_dat_80093cb0 = true;
 								}
 							}
-						}
-						else {
+						} else {
 							if ((_dat_80093cb4 < _dat_80093cb8) && (_dat_80093cb4 != 2)) {
 								_dat_80093cb0 = true;
 							}
@@ -887,18 +848,15 @@ bool Minigame2::fun_80093248() {
 					}
 					uVar2 = _dat_80093cb0;
 				}
-			}
-			else {
+			} else {
 				_dat_80093cb0 = true;
 				uVar2 = true;
 			}
-		}
-		else {
+		} else {
 			_dat_80093cb0 = false;
 			uVar2 = false;
 		}
-	}
-	else {
+	} else {
 		uVar2 = _vm->isRightKeyPressed();
 	}
 	return uVar2;
@@ -912,8 +870,7 @@ bool Minigame2::fun_80093800() {
 			_dat_80093ca8 = false;
 			if ((_dat_80093cb8 == _dat_80093cb4) && (_dat_80093cc0 < _dat_80093cbc)) {
 				_dat_80093ca8 = true;
-			}
-			else {
+			} else {
 				if (_vm->getRand(8) < 3) {
 					_dat_80093ca4 = _vm->getRand(10);
 					_dat_80093ca4 = _dat_80093cc8 + _dat_80093ca4;
@@ -922,8 +879,7 @@ bool Minigame2::fun_80093800() {
 			}
 		}
 		uVar2 = _dat_80093ca8;
-	}
-	else {
+	} else {
 		uVar2 = false;
 		if (_vm->isSquareButtonPressed() || _vm->isCrossButtonPressed() ||
 			 _vm->isCircleButtonPressed() ||
@@ -939,8 +895,7 @@ bool Minigame2::fun_80093a30() {
 
 	if (_dat_80093ca0 == 0) {
 		uVar1 = (uint) _dat_80093c90 == (uint) _dat_80093cc8 / 3;
-	}
-	else {
+	} else {
 		uVar1 = _vm->isL1ButtonPressed(); // TODO || _vm->isL2ButtonPressed();
 	}
 	return uVar1;
@@ -951,8 +906,7 @@ bool Minigame2::fun_80093990() {
 
 	if (_dat_80093ca0 == 0) {
 		uVar1 = _dat_80093c90 == 0;
-	}
-	else {
+	} else {
 		uVar1 = _vm->isR1ButtonPressed(); // TODO || _vm->isR2ButtonPressed();
 	}
 	return uVar1;
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index e4827b7f5d..545a9702ab 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -301,8 +301,7 @@ void Minigame3::run() {
 	while ((int16)i < 4) {
 		if (goodRabbitPositionTbl[(int16)i] == 0) {
 			bunnyActorTbl[(int16)i]->updateSequence(1);
-		}
-		else {
+		} else {
 			local_16 = i;
 		}
 		i = i + 1;
@@ -363,13 +362,11 @@ void Minigame3::run() {
 						bunnyActorTbl[local_1c]->_y_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].y;
 						bunnyActorTbl[local_1a]->_y_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].y;
 						currentState = 5;
-					}
-					else {
+					} else {
 						if (bunnyActorTbl[local_1a]->_sequenceID == 5) {
 							bunnyActorTbl[local_1a]->updateSequence(6);
 							bunnyActorTbl[local_1c]->updateSequence(0xd);
-						}
-						else {
+						} else {
 							local_56 = local_56 - *(int16 *)&UnkStruct_ARRAY_800931a0[local_50].field_0x14;
 							bunnyInfo[local_20].x = bunnyInfo[local_20].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * -0x200;
 							bunnyInfo[local_20].y = bunnyInfo[local_20].y - bunnyInfo[local_20].field_0xc;
@@ -404,8 +401,7 @@ void Minigame3::run() {
 				local_50 = _vm->getRand(4);
 				if (local_50 < 2) {
 					i = _vm->getRand(2);
-				}
-				else {
+				} else {
 					i = 0;
 				}
 				bunnyInfo[(int16)i].positionIdx = (uint)UnkStruct_ARRAY_800931a0[local_50].position1;
@@ -428,8 +424,7 @@ void Minigame3::run() {
 				bunnyActorTbl[local_1c]->updateSequence(0xc);
 				if (hopCounter == 0x1d) {
 					_vm->playOrStopSound(2);
-				}
-				else {
+				} else {
 					_vm->playOrStopSound((uint)local_1c2);
 					local_1c2 = 1 - local_1c2;
 				}
@@ -453,8 +448,7 @@ void Minigame3::run() {
 					local_5c = local_5c + 5;
 					currentState = 3;
 					local_58 = 0x3c;
-				}
-				else {
+				} else {
 					currentState = 2;
 					local_58 = 2;
 				}
@@ -474,8 +468,7 @@ void Minigame3::run() {
 				tearActorTbl[(int16)i]->_y_pos = tearActorTbl[(int16)i]->_y_pos + ((uint16)local_208[(int)(int16)i + 8] >> 6);
 				if (tearActorTbl[(int16)i]->_y_pos < (int16)tearInfo[local_208[(int16)i]].yRelated) {
 					local_208[(int)(int16)i + 8] = local_208[(int)(int16)i + 8] + 8;
-				}
-				else {
+				} else {
 					tearActorTbl[(int16)i]->_priorityLayer = 0;
 					local_1e8 = local_1e8 & ~(1 << ((int)local_208[(int16)i] & 0x1fU));
 					local_208[(int16)i] = -1;
@@ -487,8 +480,7 @@ void Minigame3::run() {
 		if (((local_1e0 < local_1de) && (currentState != 6)) && (sVar2 = _vm->getRand(2), sVar2 == 0)) {
 			if ((local_1e8 & 0x7fff) < local_1e8 >> 0xf) {
 				local_14 = 0;
-			}
-			else {
+			} else {
 				local_14 = 0xf;
 			}
 			do {
@@ -521,15 +513,13 @@ void Minigame3::run() {
 							local_e = 1;
 						}
 					}
-				}
-				else {
+				} else {
 					if (local_1c6 == 0) {
 						if (local_1c8 == 2) {
 							local_1c6 = 3;
 							local_1c8 = 1;
 							updateBackgroundLayerOffset(2, 0x640, 0);
-						}
-						else {
+						} else {
 							if (local_1c8 == 1) {
 								local_1c8 = 0;
 								local_1ba = 0;
@@ -540,13 +530,11 @@ void Minigame3::run() {
 								tearBlinkActorTbl2[1]->updateSequence(1);
 							}
 						}
-					}
-					else {
+					} else {
 						local_1c6 = local_1c6 + -1;
 					}
 				}
-			}
-			else {
+			} else {
 				if (local_1c6 == 0) {
 					i = 0;
 					while ((int16)i < 8) {
@@ -566,13 +554,11 @@ void Minigame3::run() {
 					updateBackgroundLayerOffset(2, 0x780, 0);
 					tearBlinkActorTbl[0]->_y_pos = 0xcc;
 					tearBlinkActorTbl[1]->_y_pos = 0xcc;
-				}
-				else {
+				} else {
 					local_1c6 = local_1c6 + -1;
 				}
 			}
-		}
-		else {
+		} else {
 			if (local_1c6 == 0) {
 				if (local_1c8 == 1) {
 					local_1c6 = 3;
@@ -582,8 +568,7 @@ void Minigame3::run() {
 					tearBlinkActorTbl2[1]->updateSequence(1);
 					tearBlinkActorTbl2[0]->_priorityLayer = 4;
 					tearBlinkActorTbl2[1]->_priorityLayer = 4;
-				}
-				else {
+				} else {
 					if (local_1c8 == 2) {
 						local_1c6 = 0x14;
 						local_1c8 = 3;
@@ -593,8 +578,7 @@ void Minigame3::run() {
 						flags = (flags & 0xfffe) | 2;
 					}
 				}
-			}
-			else {
+			} else {
 				local_1c6 = local_1c6 + -1;
 			}
 		}
@@ -632,16 +616,14 @@ void Minigame3::run() {
 					tmpValue = _vm->getRand(2);
 					if ((tmpValue & 0xffff) == 0) {
 						local_1be = 1;
-					}
-					else {
+					} else {
 						local_1be = 0xffff;
 					}
 					local_1bc = _vm->getRand(3);
 					local_1bc = local_1bc + 3;
 					local_1ba = _vm->getRand(10);
 					local_1ba = local_1ba + 10;
-				}
-				else {
+				} else {
 					if (((local_1be < 0) && (-10 < local_1c0)) || ((0 < local_1be && (local_1c0 < 10)))) {
 						local_1c0 = local_1c0 + local_1be;
 					}
@@ -659,8 +641,7 @@ void Minigame3::run() {
 					updateBackgroundLayerOffset(1, (int) -local_1c0, (int) eyeBgYOffsetTbl[local_1c0 + 10]);
 					updateBackgroundLayerOffset(0, (int) -local_1c0, (int) eyeBgYOffsetTbl[local_1c0 + 10]);
 				}
-			}
-			else {
+			} else {
 				local_1ba = local_1ba + -1;
 			}
 		}
@@ -739,8 +720,7 @@ void Minigame3::run() {
 	if (goodRabbitPositionTbl[local_224] == 1) {
 		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(2);
 		_vm->_dragonINIResource->getRecord(0x178)->field_14 = 1;
-	}
-	else {
+	} else {
 		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(3);
 		i = 0;
 		while (((int16)i < 4 && (goodRabbitPositionTbl[(int16)i] != 1))) {
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index a01d6c31b1..70300a2f29 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -84,8 +84,7 @@ void Minigame4::run() {
 	//call_fade_related_1f();
 	if (_vm->_dragonINIResource->getRecord(0x1f5)->field_12 == 3) {
 		actorTalk(_bruteActor,0x3321,0x4A84);
-	}
-	else {
+	} else {
 		actorTalk(_bruteActor,0x3321,0x49A2);
 		actorTalk(_flickerActor,0,0x4A56);
 	}
@@ -120,8 +119,7 @@ void Minigame4::actorTalk(Actor *actorId,uint16 param_2,uint32 textIndex)
 	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
 	if (actorId == _bruteActor) {
 		_bruteActor->updateSequence(9);
-	}
-	else {
+	} else {
 		_flickerActor->updateSequence(9);
 	}
 
@@ -129,8 +127,7 @@ void Minigame4::actorTalk(Actor *actorId,uint16 param_2,uint32 textIndex)
 	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
 	if (actorId == _bruteActor) {
 		_bruteActor->updateSequence(0);
-	}
-	else {
+	} else {
 		_flickerActor->updateSequence(0);
 	}
 }
@@ -306,8 +303,7 @@ uint16 Minigame4::fun_8009009c(uint16 unk) {
 	if (unk == 0) {
 		_bruteActor->updateSequence(8);
 		_flickerActor->updateSequence(7);
-	}
-	else {
+	} else {
 		_bruteActor->updateSequence(7);
 		_flickerActor->updateSequence(8);
 	}
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index 58cbce647a..d4a5a350bd 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -184,20 +184,17 @@ void Minigame5::run() {
 								((flickerActor->_flags & 4) != 0)) {
 								flickerActor->updateSequence(0x19);
 							}
-						}
-						else {
+						} else {
 							local_66 = 1;
 							local_50 = 0;
 							pusherActor->updateSequence(1);
 							currentState = 2;
 							if (local_74 < 0x14) {
 								local_72 = 1;
-							}
-							else {
+							} else {
 								if (local_74 < 0x2d) {
 									local_72 = 2;
-								}
-								else {
+								} else {
 									if (local_74 < 0x169) {
 										local_72 = 3;
 									}
@@ -205,8 +202,7 @@ void Minigame5::run() {
 							}
 						}
 						local_74 = 0;
-					}
-					else {
+					} else {
 						pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
 						pusherActor->_y_pos = flickerActor->_y_pos + 7;
 						if (local_74 < 0x168) {
@@ -221,8 +217,7 @@ void Minigame5::run() {
 									flickerActor->updateSequence(0x1a);
 									_vm->playOrStopSound(2);
 								}
-							}
-							else {
+							} else {
 								if (local_74 < 0x2d) {
 									if (((pusherActor->_sequenceID != 5) &&
 										 (pusherActor->_sequenceID != 2)) &&
@@ -233,8 +228,7 @@ void Minigame5::run() {
 										flickerActor->updateSequence(0x1e);
 										_vm->playOrStopSound(3);
 									}
-								}
-								else {
+								} else {
 									if (local_74 < 0x169) {
 										if (((pusherActor->_sequenceID != 6) &&
 											 (pusherActor->_sequenceID != 2)) &&
@@ -248,8 +242,7 @@ void Minigame5::run() {
 									}
 								}
 							}
-						}
-						else {
+						} else {
 							if (pusherActor->_sequenceID != 6) {
 								pusherActor->updateSequence(6);
 							}
@@ -265,8 +258,7 @@ void Minigame5::run() {
 							if ((((int)(uint)local_850 < (int)((local_30[0]) - 6)) ||
 								 ((uint)local_30[1] + 6 < (uint)local_850)) || (local_72 != local_30[2])) {
 								local_42 = 8;
-							}
-							else {
+							} else {
 								local_42 = 0;
 							}
 							local_5c = 0;
@@ -286,8 +278,7 @@ void Minigame5::run() {
 							flickerActor->updateSequence(8);
 							currentState = 3;
 						}
-					}
-					else {
+					} else {
 						flickerActor->updateSequence(0x1b);
 						_vm->playOrStopSound(1);
 					}
@@ -300,13 +291,11 @@ void Minigame5::run() {
 						if (local_5a < 0) {
 							local_5a = 0;
 						}
-					}
-					else {
+					} else {
 						if ((int)(uint)bombScale < (int)((uint)local_72 * -4 + 0xba)) {
 							local_5e = local_5e + local_5a;
 							local_5a = local_5a + local_28[((uint)local_72 - 1) * 3 + 2];
-						}
-						else {
+						} else {
 							local_5a = 0;
 						}
 					}
@@ -318,8 +307,7 @@ void Minigame5::run() {
 						if (((local_60 >> 7 < local_30[0]) || (local_30[1] < local_60 >> 7)) ||
 							(local_72 != local_30[2])) {
 							local_42 = 8;
-						}
-						else {
+						} else {
 							local_42 = 0;
 						}
 						if (local_42 == 8) {
@@ -338,8 +326,7 @@ void Minigame5::run() {
 								dustActor->updateSequence(9);
 								currentState = 4;
 							}
-						}
-						else {
+						} else {
 							local_4e->_field_c = 2;
 							local_4c = 0x3c;
 							bombActor->_priorityLayer = 0;
@@ -364,8 +351,7 @@ void Minigame5::run() {
 						_vm->_talk->loadText(DAT_8006393c,auStack2120, 1000);
 						_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1,DAT_8006393c);
 						_dat_800633e6 = 1;
-					}
-					else {
+					} else {
 						_vm->_talk->loadText(DAT_80063938, auStack2120, 1000);
 						_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1, DAT_80063938);
 					}
@@ -415,14 +401,12 @@ void Minigame5::run() {
 								if (local_50 == 0) {
 									pusherActor->_x_pos = flickerActor->_x_pos + -0xe;
 									pusherActor->_y_pos = flickerActor->_y_pos + 7;
-								}
-								else {
+								} else {
 									pusherActor->_x_pos = flickerActor->_x_pos + 2;
 									pusherActor->_y_pos = flickerActor->_y_pos;
 								}
 							}
-						}
-						else {
+						} else {
 							local_50 = 1;
 							local_66 = 8;
 							if (pusherActor->_sequenceID != 2) {
@@ -433,14 +417,12 @@ void Minigame5::run() {
 								if (local_850 < 0x36) {
 									local_850 = 0x36;
 								}
-							}
-							else {
+							} else {
 								local_850 = 0x108;
 							}
 							if (local_62 == 0) {
 								local_62 = 0xb;
-							}
-							else {
+							} else {
 								local_62 = local_62 - 1;
 							}
 							flickerActor->_x_pos = local_850;
@@ -451,8 +433,7 @@ void Minigame5::run() {
 							pusherActor->_x_pos = flickerActor->_x_pos + 2;
 							pusherActor->_y_pos = flickerActor->_y_pos;
 						}
-					}
-					else {
+					} else {
 						local_50 = 0;
 						local_66 = (uint16)(currentState != 1);
 						if (pusherActor->_sequenceID != 3) {
@@ -463,8 +444,7 @@ void Minigame5::run() {
 							if (local_850 < 0x36) {
 								local_850 = 0x36;
 							}
-						}
-						else {
+						} else {
 							local_850 = 0x108;
 						}
 						local_62 = (short)((uint)local_62 + 1) +
@@ -489,8 +469,7 @@ void Minigame5::run() {
 			wheelsActor->_x_pos = wheelsActor->_x_pos + 2;
 			if (local_62 == 0) {
 				local_62 = 0xb;
-			}
-			else {
+			} else {
 				local_62 = local_62 - 1;
 			}
 			if ((uint)wheelsActor->_sequenceID != (uint)local_62 / 3 + 0x11) {
@@ -516,8 +495,7 @@ void Minigame5::run() {
 				local_44 = pusherActor->_y_pos;
 				pusherActor->reset_maybe();
 //				EnableVSyncEvent();
-			}
-			else {
+			} else {
 //				DisableVSyncEvent();
 				dustActor->reset_maybe();
 				bombActor->reset_maybe();
@@ -530,8 +508,7 @@ void Minigame5::run() {
 				local_78->actor->_x_pos = local_46;
 				local_78->actor->setFlag(ACTOR_FLAG_100);
 				local_78->actor->_priorityLayer = 5;
-			}
-			else {
+			} else {
 				local_78->actor->clearFlag(ACTOR_FLAG_100);
 				local_78->actor->_priorityLayer = 2;
 			}
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 6e72cb63e5..ee9a5ce8ea 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -735,8 +735,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 				secondIni->y = newYPos1;
 				secondIni->actor->_y_pos = newYPos1;
 			}
-		}
-		else {
+		} else {
 			int16 newYPos2 = firstIni->actor->_y_pos + firstIni->field_1e;
 			firstIni->y = newYPos2;
 			secondIni->actor->_y_pos = newYPos2;
@@ -754,8 +753,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 	}
 	if ((field8 & 0x8000) == 0) {
 		someBooleanFlag = (uint)field8 << 0x10;
-	}
-	else {
+	} else {
 		someBooleanFlag = ((uint)field8 & 0x7fff) << 7;
 	}
 	if (field6 != -1) {
@@ -780,8 +778,7 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 		if (_vm->_dragonINIResource->isFlicker(secondIni)) {
 			someBooleanFlag = 0;
 		}
-	}
-	else {
+	} else {
 		newXPosAgain = firstIni->actor->_x_pos + firstIni->field_1c;
 		newYPosAgain = firstIni->actor->_y_pos + firstIni->field_1e;
 		if (_vm->_dragonINIResource->isFlicker(secondIni)) {
@@ -878,8 +875,7 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 				READ_LE_INT16(_vm->_dragonOBD->getFromOpt(iniId) + 6),
 				1,
 				ini->actor, startSequenceId, endSequenceId, textIndex);
-	}
-	else {
+	} else {
 		_vm->_talk->FUN_8003239c(dialog,
 								 (int)(((uint)ini->actor->_x_pos - (uint)_vm->_scene->_camera.x) * 0x10000) >> 0x13,
 								 (int)(((ini->actor->_y_pos - ini->actor->_frame->yOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13,
@@ -1222,8 +1218,7 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
 				_vm->_cursor->_data_800728b0_cursor_seqID = 0;
 				_vm->_cursor->_sequenceID = 0;
 				_vm->_cursor->_iniItemInHand = 0;
-			}
-			else {
+			} else {
 				if (_vm->_inventory->clearItem(ini->id + 1)) {
 					if (_vm->_inventory->getType() == 1) {
 						ini->actor->clearFlag(ACTOR_FLAG_40);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index a2a86304e6..1bf4f3081d 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -270,8 +270,7 @@ void SpecialOpcodes::spcCastleGardenLogic() {
 		sceneUpdater.sequenceIDTbl[3][0] = 1;
 		sceneUpdater.iniIDTbl[3][0] = 0x145;
 		sceneUpdater.iniIDTbl[4][0] = 0x144;
-	}
-	else {
+	} else {
 		sceneUpdater.sequenceIDTbl[0][0] = -1;
 		sceneUpdater.sequenceIDTbl[1][0] = -1;
 		sceneUpdater.sequenceIDTbl[2][0] = -1;
@@ -463,8 +462,7 @@ void SpecialOpcodes::spcWalkOnStilts() {
 	while (flickerOnStilts->isFlagSet(ACTOR_FLAG_10)) {
 		if (flickerOnStilts->_frame->field_c == 0) {
 			isInWater = false;
-		}
-		else {
+		} else {
 			if (!isInWater && flickerOnStilts->_y_pos >= 0x6a && flickerOnStilts->_y_pos < 0x96) {
 				isInWater = true;
 				waterRipples->_x_pos = flickerOnStilts->_x_pos - flickerOnStilts->_frame->field_e;
@@ -1243,8 +1241,7 @@ void SpecialOpcodes::pizzaMakerStopWorking() {
 			actorf5->_x_pos = 0xff9c;
 			actorf5->_y_pos = 100;
 			actorf4->updateSequence(3);
-		}
-		else {
+		} else {
 			if (actorf4->_sequenceID == 2) {
 				_vm->waitForFrames(0x78);
 				actorf5->updateSequence(8);
@@ -1252,8 +1249,7 @@ void SpecialOpcodes::pizzaMakerStopWorking() {
 				actorf5->_x_pos = 0xff9c;
 				actorf5->_y_pos = 100;
 				actorf4->updateSequence(3);
-			}
-			else {
+			} else {
 				if (actorf4->_sequenceID != 3) {
 					return;
 				}
@@ -1351,8 +1347,7 @@ void pizzaUpdateFunction() {
 					}
 				}
 			}
-		}
-		else {
+		} else {
 			counter--;
 		}
 }
@@ -1404,8 +1399,7 @@ void castleBuildingBlackDragon2UpdateFunction() {
 			ini->actor->updateSequence(0xb);
 			ini->field_10 = 0x68;
 			ini->field_12 = 1;
-		}
-		else if (ini->field_12 == 1) {
+		} else if (ini->field_12 == 1) {
 			ini->actor->updateSequence(4);
 			ini->field_10 = vm->getRand(0xb4);
 			ini->field_12 = 0;
@@ -1422,8 +1416,7 @@ void shakeScreenUpdateFunction() {
 		shakeDirection = shakeDirection ^ 1u;
 		int16 shakeValue = shakeDirection != 0 ? 1 : -1;
 		vm->_screen->setScreenShakeOffset(shakeValue, shakeValue);
-	}
-	else {
+	} else {
 		counter--;
 	}
 	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(counter);
@@ -1466,8 +1459,7 @@ void castleFogUpdateFunction() {
 		}
 		vm->_scene->setLayerOffset(2, Common::Point(castleFogXOffset, 0));
 		specialOpCounter = 6;
-	}
-	else {
+	} else {
 		specialOpCounter--;
 	}
 	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
@@ -1493,8 +1485,7 @@ void menInMinesSceneUpdateFunction() {
 		vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(vm->getRand(5) * 0x3c + 0x708);
 		vm->_talk->playDialogAudioDontWait(sceneUpdateFuncDialogTbl[vm->getRand(4)]);
 		sequenceId = 2;
-	}
-	else {
+	} else {
 		if (vm->_data_800633fc == 0) {
 			return;
 		}
@@ -1717,8 +1708,7 @@ void flameEscapeSceneUpdateFunction() {
 				vm->_talk->playDialogAudioDontWait(dialogTbl[vm->getRand(6)]);
 				specialOpCounter = 0;
 				DAT_800634c0 = 1;
-			}
-			else {
+			} else {
 				if (DAT_800634c0 == 1) {
 					flame->updateSequence(0x10);
 					specialOpCounter = (vm->getRand(0x14) + 10) * 0x3c;
@@ -1727,8 +1717,7 @@ void flameEscapeSceneUpdateFunction() {
 			}
 		}
 		vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
-	}
-	else {
+	} else {
 		if ((vm->_data_800633fc != 0) && flame->_sequenceID != 0x10) {
 			flame->updateSequence(0x10);
 		}
@@ -1760,8 +1749,7 @@ void caveOfDilemmaUpdateFunction() {
 		oldManActor->_y_pos = oldManActor->_y_pos + yOffset;
 		cloudChairActor->_y_pos = cloudChairActor->_y_pos + yOffset;
 		counter = 10;
-	}
-	else {
+	} else {
 		counter--;
 	}
 }
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 21e3bf81ff..3579533dc7 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -272,8 +272,8 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 //							iVar6 = (int)(short)iVar8;
 //							goto LAB_800328f8;
 //						}
-//					}
-					else {
+//					} else
+					{
 						LAB_800328f8:
 						if (-1 < iVar8) {
 							if (currentLine[iVar8] == 0x20) {
@@ -290,8 +290,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 //									*(undefined2 *)(((iVar8 << 0x10) >> 0xf) + (int)currentLine) = 0;
 //									iVar8 = iVar6;
 //								} while (-1 < iVar6 * 0x10000);
-							}
-							else {
+							} else {
 								currentLine[iVar8 + 1] = 0;
 							}
 						}
@@ -347,8 +346,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 				sVar20 = (short)uVar11 >> 1;
 				if ((short)x < 0x14) {
 					_dat_8008e7e8_dialogBox_x1 = (x - sVar20) + 1;
-				}
-				else {
+				} else {
 					_dat_8008e7e8_dialogBox_x1 = x - sVar20;
 				}
 				_dat_8008e848_dialogBox_x2 = (uVar11 + _dat_8008e7e8_dialogBox_x1) - 1;
@@ -364,8 +362,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 								dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
 								uVar9 = strlenUTF16(dialogTextLinePtr);
 								uVar9 = ((uint)x - ((int)((uint)_dat_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1)) + 1;
-							}
-							else {
+							} else {
 								dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
 								uVar9 = strlenUTF16(dialogTextLinePtr);
 								uVar9 = (uint)x - ((int)((uint)_dat_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1);
@@ -445,8 +442,7 @@ uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 tex
 		if (local_v1_184->field_e == 0) {
 			y = (uint)(uint16)local_v1_184->y;
 			x = local_v1_184->field_a;
-		}
-		else {
+		} else {
 			x = local_v1_184->field_a;
 			y = (uint)(uint16)local_v1_184->y << 3;
 		}
@@ -456,8 +452,7 @@ uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 tex
 				 ((y - _vm->_scene->_camera.y) * 0x10000) >> 0x13,
 				 READ_LE_UINT16(_vm->_dragonOBD->getFromOpt(ini->id) + 6)
 						,1,textIndex);
-	}
-	else {
+	} else {
 		displayDialogAroundActor
 				(ini->actor,
 				 READ_LE_UINT16(_vm->_dragonOBD->getFromOpt(ini->id) + 6),
@@ -614,8 +609,7 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 		if (loadText(selectedDialogText->textIndex1, local_800, 1000)) {
 			if (selectedDialogText->field_26c == -1) {
 				displayDialogAroundINI(_vm->_cursor->_iniUnderCursor, local_800, selectedDialogText->textIndex1);
-			}
-			else {
+			} else {
 				iniId = _vm->_cursor->_iniUnderCursor; //dragon_ini_index_under_active_cursor;
 				if (selectedDialogText->iniId != 0) {
 					iniId = selectedDialogText->iniId;
@@ -804,8 +798,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 								y = y + 1;
 							} while ((uVar7 & 0xffff) < (uVar4 & 0xffff));
 						}
-					}
-					else {
+					} else {
 						uVar7 = 0;
 						if (uVar6 < (uVar4 & 0xffff)) {
 							do {
@@ -881,15 +874,13 @@ void Talk::talkFromIni(uint32 iniId, uint32 textIndex) {
 		if (!_vm->isFlagSet(ENGINE_FLAG_2000000)) {
 			if (_vm->getCurrentSceneId() == 0x32) {
 				_vm->getINI(0x2b1)->actor->updateSequence(2);
-			}
-			else {
+			} else {
 				actor->setFlag(ACTOR_FLAG_2000);
 				if (actor->_sequenceID2 != -1) {
 					actor->updateSequence(actor->_sequenceID2 + 0x10);
 				}
 			}
-		}
-		else {
+		} else {
 			if (actor->_sequenceID == 5) {
 				actor->updateSequence(0x10);
 			}
@@ -915,8 +906,7 @@ void Talk::talkFromIni(uint32 iniId, uint32 textIndex) {
 			}
 			_vm->getINI(0x2b1)->actor->updateSequence(1);
 
-		}
-		else {
+		} else {
 			if (actor->_sequenceID != 0x10) {
 				return;
 			}
@@ -1096,8 +1086,7 @@ uint32 Talk::FUN_80031c28(uint16 *srcText, uint16 *destText, uint32 cutLength, u
 			uVar1 = uVar3;
 			LAB_80031d3c:
 			uVar3 = uVar1;
-		}
-		else {
+		} else {
 			if (((((chr != 0x20) && (chr != 0x2e)) && (chr != 0x3f)) &&
 				 ((chr != 0x21 && (uVar1 = uVar3, chr != 0x2d)))) ||
 				((uVar1 = uVar3, srcText[(srcCurIndex & 0xffff) + 1] == 0 ||


Commit: 853b703953561aa401f33cdae3be5e4a90fef904
    https://github.com/scummvm/scummvm/commit/853b703953561aa401f33cdae3be5e4a90fef904
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fix whitespaces

Changed paths:
    engines/dragons/VabSound.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/saveload.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/sequenceopcodes.h
    engines/dragons/sound.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/VabSound.cpp
index 0681508bb6..c81c3e4d21 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/VabSound.cpp
@@ -29,12 +29,13 @@
 #include "dragons/dragons.h"
 
 namespace Dragons {
-	VabSound::VabSound(Common::SeekableReadStream *msfData, const DragonsEngine *_vm): _toneAttrs(NULL), _vbData(NULL) {
-		loadHeader(msfData);
 
-		int32 dataSize = msfData->size() - msfData->pos();
-		_vbData = new byte[dataSize];
-		msfData->read(_vbData, dataSize);
+VabSound::VabSound(Common::SeekableReadStream *msfData, const DragonsEngine *_vm): _toneAttrs(NULL), _vbData(NULL) {
+	loadHeader(msfData);
+
+	int32 dataSize = msfData->size() - msfData->pos();
+	_vbData = new byte[dataSize];
+	msfData->read(_vbData, dataSize);
 
 //		_vbData = new Common::MemoryReadStream(newData, dataSize, DisposeAfterUse::YES);
 //
@@ -42,80 +43,80 @@ namespace Dragons {
 //		Audio::SoundHandle _speechHandle;
 //		_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speechHandle, str);
 
-		delete msfData;
-	}
+	delete msfData;
+}
 
-	VabSound::VabSound(Common::SeekableReadStream *vhData, Common::SeekableReadStream *vbData): _toneAttrs(NULL), _vbData(NULL) {
-		loadHeader(vhData);
+VabSound::VabSound(Common::SeekableReadStream *vhData, Common::SeekableReadStream *vbData): _toneAttrs(NULL), _vbData(NULL) {
+	loadHeader(vhData);
 
-		assert(vhData->pos() == vhData->size());
+	assert(vhData->pos() == vhData->size());
 
-		_vbData = new byte[vbData->size()];
-		vbData->read(_vbData, vbData->size());
+	_vbData = new byte[vbData->size()];
+	vbData->read(_vbData, vbData->size());
 
-		delete vhData;
-		delete vbData;
-	}
+	delete vhData;
+	delete vbData;
+}
 
-	void VabSound::loadHeader(Common::SeekableReadStream *vhData) {
-		vhData->seek(0);
-		vhData->read(&_header.magic, 4);
-		_header.version = vhData->readUint32LE();
-		_header.vabId = vhData->readUint32LE();
-		_header.waveformSize = vhData->readUint32LE();
+void VabSound::loadHeader(Common::SeekableReadStream *vhData) {
+	vhData->seek(0);
+	vhData->read(&_header.magic, 4);
+	_header.version = vhData->readUint32LE();
+	_header.vabId = vhData->readUint32LE();
+	_header.waveformSize = vhData->readUint32LE();
 
-		_header.reserved0 = vhData->readUint16LE();
-		_header.numPrograms = vhData->readUint16LE();
-		_header.numTones = vhData->readUint16LE();
-		_header.numVAG = vhData->readUint16LE();
+	_header.reserved0 = vhData->readUint16LE();
+	_header.numPrograms = vhData->readUint16LE();
+	_header.numTones = vhData->readUint16LE();
+	_header.numVAG = vhData->readUint16LE();
 
-		_header.masterVolume = vhData->readByte();
-		_header.masterPan = vhData->readByte();
-		_header.bankAttr1 = vhData->readByte();
-		_header.bankAttr2 = vhData->readByte();
+	_header.masterVolume = vhData->readByte();
+	_header.masterPan = vhData->readByte();
+	_header.bankAttr1 = vhData->readByte();
+	_header.bankAttr2 = vhData->readByte();
 
-		_header.reserved1 = vhData->readUint32LE();
+	_header.reserved1 = vhData->readUint32LE();
 
-		if (strncmp(_header.magic, "pBAV", 4) != 0) {
-			error("Invalid VAB file");
-		}
+	if (strncmp(_header.magic, "pBAV", 4) != 0) {
+		error("Invalid VAB file");
+	}
 
-		loadProgramAttributes(vhData);
-		loadToneAttributes(vhData);
+	loadProgramAttributes(vhData);
+	loadToneAttributes(vhData);
 
-		uint16 tempOffsets[0x100];
-		for (int i = 0; i < 0x100; i++) {
-			tempOffsets[i] = vhData->readUint16LE();
-		}
-		_vagOffsets[0] = tempOffsets[0] << 3u;
-		for (int j = 1; j < 0x100; ++j) {
-			const int vagSize = tempOffsets[j] << 3u;
-			_vagSizes[j - 1] = vagSize;
-			_vagOffsets[j] = vagSize + _vagOffsets[j - 1];
-		}
+	uint16 tempOffsets[0x100];
+	for (int i = 0; i < 0x100; i++) {
+		tempOffsets[i] = vhData->readUint16LE();
 	}
-
-	VabSound::~VabSound() {
-		delete _toneAttrs;
-		delete _vbData;
+	_vagOffsets[0] = tempOffsets[0] << 3u;
+	for (int j = 1; j < 0x100; ++j) {
+		const int vagSize = tempOffsets[j] << 3u;
+		_vagSizes[j - 1] = vagSize;
+		_vagOffsets[j] = vagSize + _vagOffsets[j - 1];
 	}
+}
 
-	Audio::AudioStream *VabSound::getAudioStream(uint16 program, uint16 key) {
-		assert(program < _header.numVAG);
-		// TODO
-		uint16 vagID = 0;
-		for (int i = 0; i < _programAttrs[program].tones; i++) {
-			if (_toneAttrs[i].prog == program && _toneAttrs[i].min == key && _toneAttrs[i].max == key) {
-				vagID = _toneAttrs[i].vag - 1;
-			}
+VabSound::~VabSound() {
+	delete _toneAttrs;
+	delete _vbData;
+}
+
+Audio::AudioStream *VabSound::getAudioStream(uint16 program, uint16 key) {
+	assert(program < _header.numVAG);
+	// TODO
+	uint16 vagID = 0;
+	for (int i = 0; i < _programAttrs[program].tones; i++) {
+		if (_toneAttrs[i].prog == program && _toneAttrs[i].min == key && _toneAttrs[i].max == key) {
+			vagID = _toneAttrs[i].vag - 1;
 		}
-		debug("Playing program %d, numTones: %d, key %d vagID %d, vagOffset: %x, size: %x", program, _programAttrs[program].tones, key, vagID, _vagOffsets[vagID], _vagSizes[vagID]);
-		Audio::AudioStream *str = Audio::makeXAStream(
-				new Common::MemoryReadStream(&_vbData[_vagOffsets[vagID]], _vagSizes[vagID], DisposeAfterUse::NO),
-				11025,
-				DisposeAfterUse::YES);
-		return str;
 	}
+	debug("Playing program %d, numTones: %d, key %d vagID %d, vagOffset: %x, size: %x", program, _programAttrs[program].tones, key, vagID, _vagOffsets[vagID], _vagSizes[vagID]);
+	Audio::AudioStream *str = Audio::makeXAStream(
+			new Common::MemoryReadStream(&_vbData[_vagOffsets[vagID]], _vagSizes[vagID], DisposeAfterUse::NO),
+			11025,
+			DisposeAfterUse::YES);
+	return str;
+}
 
 void VabSound::loadProgramAttributes(Common::SeekableReadStream *vhData) {
 	for (int i = 0; i < DRAGONS_VAB_NUM_PROG_ATTRS; i++) {
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 94bff0b2ab..6c7db600ae 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -131,7 +131,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	local_256 = 0;
 	screenShakeCounter = 0;
 	local_2e6 = param_2;
-	if (4 < param_2) {
+	if (param_2 > 4) {
 		local_2e6 = 4;
 	}
 	_dat_80093ca4 = unkArray[local_2e6];
@@ -249,7 +249,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	_vm->waitForFrames(2);
 	// call_fade_related_1f();
 
-	LAB_80090188:
+LAB_80090188:
 	do {
 		if (shouldExit) {
 //			fade_related_calls_with_1f();
@@ -732,7 +732,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			}
 		}
 
-	} while ( true );
+	} while (true);
 
 }
 
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 545a9702ab..9f0acacf67 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -352,115 +352,115 @@ void Minigame3::run() {
 	while ( true ) {
 		_vm->waitForFrames(1);
 		switch (currentState) {
-			case 1:
-				if ((bunnyActorTbl[local_1a]->_sequenceID != 5) || ((bunnyActorTbl[local_1a]->_flags & 4) != 0)) {
-					if ((local_56 < 1) ||
+		case 1:
+			if ((bunnyActorTbl[local_1a]->_sequenceID != 5) || ((bunnyActorTbl[local_1a]->_flags & 4) != 0)) {
+				if ((local_56 < 1) ||
 						(((int)bunnyInfo[local_20].x >> 9 <= (int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x ||
-																				((int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x <= (int)bunnyInfo[local_1e].x >> 9)))) {
-						bunnyActorTbl[local_1c]->_x_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x;
-						bunnyActorTbl[local_1a]->_x_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x;
-						bunnyActorTbl[local_1c]->_y_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].y;
-						bunnyActorTbl[local_1a]->_y_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].y;
-						currentState = 5;
+						((int)(uint)(uint16)bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x <= (int)bunnyInfo[local_1e].x >> 9)))) {
+					bunnyActorTbl[local_1c]->_x_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].x;
+					bunnyActorTbl[local_1a]->_x_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].x;
+					bunnyActorTbl[local_1c]->_y_pos = bunnyPositionsTbl[bunnyInfo[local_1e].positionIdx].y;
+					bunnyActorTbl[local_1a]->_y_pos = bunnyPositionsTbl[bunnyInfo[local_20].positionIdx].y;
+					currentState = 5;
+				} else {
+					if (bunnyActorTbl[local_1a]->_sequenceID == 5) {
+						bunnyActorTbl[local_1a]->updateSequence(6);
+						bunnyActorTbl[local_1c]->updateSequence(0xd);
 					} else {
-						if (bunnyActorTbl[local_1a]->_sequenceID == 5) {
-							bunnyActorTbl[local_1a]->updateSequence(6);
-							bunnyActorTbl[local_1c]->updateSequence(0xd);
-						} else {
-							local_56 = local_56 - *(int16 *)&UnkStruct_ARRAY_800931a0[local_50].field_0x14;
-							bunnyInfo[local_20].x = bunnyInfo[local_20].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * -0x200;
-							bunnyInfo[local_20].y = bunnyInfo[local_20].y - bunnyInfo[local_20].field_0xc;
-							bunnyInfo[local_20].field_0xc = bunnyInfo[local_20].field_0xc + bunnyInfo[local_20].field_0x10;
-							bunnyActorTbl[local_1c]->_x_pos = (int16_t)((int)bunnyInfo[local_20].x >> 9);
-							bunnyActorTbl[local_1c]->_y_pos = (int16_t)((int)bunnyInfo[local_20].y >> 9);
-							bunnyInfo[local_1e].x = bunnyInfo[local_1e].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * 0x200;
-							bunnyInfo[local_1e].y = bunnyInfo[local_1e].y - bunnyInfo[local_1e].field_0xc;
-							bunnyInfo[local_1e].field_0xc = bunnyInfo[local_1e].field_0xc + bunnyInfo[local_1e].field_0x10;
-							bunnyActorTbl[local_1a]->_x_pos = (int16_t)((int)bunnyInfo[local_1e].x >> 9);
-							bunnyActorTbl[local_1a]->_y_pos = (int16_t)((int)bunnyInfo[local_1e].y >> 9);
-							if ((local_228 < 4) && unkXPosTbl[local_50 * 4 + local_228] < bunnyActorTbl[local_1a]->_x_pos) {
-								local_228 = local_228 + 1;
-								bunnyActorTbl[local_1a]->updateSequence((uint)local_228 + 6 & 0xffff);
-								bunnyActorTbl[local_1c]->updateSequence((uint)local_228 + 0xd & 0xffff);
-							}
+						local_56 = local_56 - *(int16 *)&UnkStruct_ARRAY_800931a0[local_50].field_0x14;
+						bunnyInfo[local_20].x = bunnyInfo[local_20].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * -0x200;
+						bunnyInfo[local_20].y = bunnyInfo[local_20].y - bunnyInfo[local_20].field_0xc;
+						bunnyInfo[local_20].field_0xc = bunnyInfo[local_20].field_0xc + bunnyInfo[local_20].field_0x10;
+						bunnyActorTbl[local_1c]->_x_pos = (int16_t)((int)bunnyInfo[local_20].x >> 9);
+						bunnyActorTbl[local_1c]->_y_pos = (int16_t)((int)bunnyInfo[local_20].y >> 9);
+						bunnyInfo[local_1e].x = bunnyInfo[local_1e].x + UnkStruct_ARRAY_800931a0[local_50].field_0x14 * 0x200;
+						bunnyInfo[local_1e].y = bunnyInfo[local_1e].y - bunnyInfo[local_1e].field_0xc;
+						bunnyInfo[local_1e].field_0xc = bunnyInfo[local_1e].field_0xc + bunnyInfo[local_1e].field_0x10;
+						bunnyActorTbl[local_1a]->_x_pos = (int16_t)((int)bunnyInfo[local_1e].x >> 9);
+						bunnyActorTbl[local_1a]->_y_pos = (int16_t)((int)bunnyInfo[local_1e].y >> 9);
+						if ((local_228 < 4) && unkXPosTbl[local_50 * 4 + local_228] < bunnyActorTbl[local_1a]->_x_pos) {
+							local_228 = local_228 + 1;
+							bunnyActorTbl[local_1a]->updateSequence((uint)local_228 + 6 & 0xffff);
+							bunnyActorTbl[local_1c]->updateSequence((uint)local_228 + 0xd & 0xffff);
 						}
 					}
 				}
-				break;
-			case 2:
-				if (local_58 == 0) {
-					currentState = 4;
-				}
-				break;
-			case 3:
-				if (local_58 == 0) {
-					currentState = 4;
-				}
-				break;
-			case 4:
-				local_50 = _vm->getRand(4);
-				if (local_50 < 2) {
-					i = _vm->getRand(2);
-				} else {
-					i = 0;
-				}
-				bunnyInfo[(int16)i].positionIdx = (uint)UnkStruct_ARRAY_800931a0[local_50].position1;
-				bunnyInfo[(int16)i].x = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].x << 9;
-				bunnyInfo[(int16)i].y = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].y << 9;
-				bunnyInfo[(int16)i].field_0xc = UnkStruct_ARRAY_800931a0[local_50].unk4;
-				bunnyInfo[(int16)i].field_0x10 = UnkStruct_ARRAY_800931a0[local_50].unk8;
-				i = i ^ 1;
-				bunnyInfo[(int16)i].positionIdx = (uint)UnkStruct_ARRAY_800931a0[local_50].position2;
-				bunnyInfo[(int16)i].x = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].x << 9;
-				bunnyInfo[(int16)i].y = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].y << 9;
-				bunnyInfo[(int16)i].field_0xc = UnkStruct_ARRAY_800931a0[local_50].unk12;
-				bunnyInfo[(int16)i].field_0x10 = UnkStruct_ARRAY_800931a0[local_50].unk16;
-				local_56 = bunnyPositionsTbl[UnkStruct_ARRAY_800931a0[local_50].position2].x - bunnyPositionsTbl[UnkStruct_ARRAY_800931a0[local_50].position1].x;
-				local_1e = (uint16)((int)bunnyInfo[1].x <= (int)bunnyInfo[0].x);
-				local_20 = (int16)((uint)local_1e + 1) + (int16)((int)((uint)local_1e + 1) / 2) * -2;
-				local_1a = bunnyPositionTbl[bunnyInfo[local_1e].positionIdx];
-				local_1c = bunnyPositionTbl[bunnyInfo[local_20].positionIdx];
-				bunnyActorTbl[local_1a]->updateSequence(5);
-				bunnyActorTbl[local_1c]->updateSequence(0xc);
-				if (hopCounter == 0x1d) {
-					_vm->playOrStopSound(2);
-				} else {
-					_vm->playOrStopSound((uint)local_1c2);
-					local_1c2 = 1 - local_1c2;
-				}
-				local_228 = 0;
-				i = goodRabbitPositionTbl[bunnyInfo[local_1e].positionIdx];
-				goodRabbitPositionTbl[bunnyInfo[local_1e].positionIdx] = goodRabbitPositionTbl[bunnyInfo[local_20].positionIdx];
-				goodRabbitPositionTbl[bunnyInfo[local_20].positionIdx] = i;
-				i = bunnyPositionTbl[bunnyInfo[local_1e].positionIdx];
-				bunnyPositionTbl[bunnyInfo[local_1e].positionIdx] = bunnyPositionTbl[bunnyInfo[local_20].positionIdx];
-				bunnyPositionTbl[bunnyInfo[local_20].positionIdx] = i;
-				currentState = 1;
-				break;
-			case 5:
-				hopCounter = hopCounter + 1;
-				local_5a = local_5a + 1;
-				bunnyActorTbl[local_1a]->updateSequence(0xb);
-				bunnyActorTbl[local_1c]->updateSequence(0x12);
-				if (local_5a == local_5c) {
-					local_5a = 0;
-					local_5c = _vm->getRand(2);
-					local_5c = local_5c + 5;
-					currentState = 3;
-					local_58 = 0x3c;
-				} else {
-					currentState = 2;
-					local_58 = 2;
-				}
-				break;
-			case 6:
-				local_10 = 0;
-				if (local_1e8 == 0) {
-					flags = flags | 8;
-				}
-				break;
-			default:
-				error("Unknown state");
+			}
+			break;
+		case 2:
+			if (local_58 == 0) {
+				currentState = 4;
+			}
+			break;
+		case 3:
+			if (local_58 == 0) {
+				currentState = 4;
+			}
+			break;
+		case 4:
+			local_50 = _vm->getRand(4);
+			if (local_50 < 2) {
+				i = _vm->getRand(2);
+			} else {
+				i = 0;
+			}
+			bunnyInfo[(int16)i].positionIdx = (uint)UnkStruct_ARRAY_800931a0[local_50].position1;
+			bunnyInfo[(int16)i].x = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].x << 9;
+			bunnyInfo[(int16)i].y = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].y << 9;
+			bunnyInfo[(int16)i].field_0xc = UnkStruct_ARRAY_800931a0[local_50].unk4;
+			bunnyInfo[(int16)i].field_0x10 = UnkStruct_ARRAY_800931a0[local_50].unk8;
+			i = i ^ 1;
+			bunnyInfo[(int16)i].positionIdx = (uint)UnkStruct_ARRAY_800931a0[local_50].position2;
+			bunnyInfo[(int16)i].x = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].x << 9;
+			bunnyInfo[(int16)i].y = (uint)(uint16)bunnyPositionsTbl[bunnyInfo[(int16)i].positionIdx].y << 9;
+			bunnyInfo[(int16)i].field_0xc = UnkStruct_ARRAY_800931a0[local_50].unk12;
+			bunnyInfo[(int16)i].field_0x10 = UnkStruct_ARRAY_800931a0[local_50].unk16;
+			local_56 = bunnyPositionsTbl[UnkStruct_ARRAY_800931a0[local_50].position2].x - bunnyPositionsTbl[UnkStruct_ARRAY_800931a0[local_50].position1].x;
+			local_1e = (uint16)((int)bunnyInfo[1].x <= (int)bunnyInfo[0].x);
+			local_20 = (int16)((uint)local_1e + 1) + (int16)((int)((uint)local_1e + 1) / 2) * -2;
+			local_1a = bunnyPositionTbl[bunnyInfo[local_1e].positionIdx];
+			local_1c = bunnyPositionTbl[bunnyInfo[local_20].positionIdx];
+			bunnyActorTbl[local_1a]->updateSequence(5);
+			bunnyActorTbl[local_1c]->updateSequence(0xc);
+			if (hopCounter == 0x1d) {
+				_vm->playOrStopSound(2);
+			} else {
+				_vm->playOrStopSound((uint)local_1c2);
+				local_1c2 = 1 - local_1c2;
+			}
+			local_228 = 0;
+			i = goodRabbitPositionTbl[bunnyInfo[local_1e].positionIdx];
+			goodRabbitPositionTbl[bunnyInfo[local_1e].positionIdx] = goodRabbitPositionTbl[bunnyInfo[local_20].positionIdx];
+			goodRabbitPositionTbl[bunnyInfo[local_20].positionIdx] = i;
+			i = bunnyPositionTbl[bunnyInfo[local_1e].positionIdx];
+			bunnyPositionTbl[bunnyInfo[local_1e].positionIdx] = bunnyPositionTbl[bunnyInfo[local_20].positionIdx];
+			bunnyPositionTbl[bunnyInfo[local_20].positionIdx] = i;
+			currentState = 1;
+			break;
+		case 5:
+			hopCounter = hopCounter + 1;
+			local_5a = local_5a + 1;
+			bunnyActorTbl[local_1a]->updateSequence(0xb);
+			bunnyActorTbl[local_1c]->updateSequence(0x12);
+			if (local_5a == local_5c) {
+				local_5a = 0;
+				local_5c = _vm->getRand(2);
+				local_5c = local_5c + 5;
+				currentState = 3;
+				local_58 = 0x3c;
+			} else {
+				currentState = 2;
+				local_58 = 2;
+			}
+			break;
+		case 6:
+			local_10 = 0;
+			if (local_1e8 == 0) {
+				flags = flags | 8;
+			}
+			break;
+		default:
+			error("Unknown state");
 		}
 		i = 0;
 		while ((int16)i < 8) {
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 70300a2f29..f89ff5254f 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -114,8 +114,7 @@ void Minigame4::run() {
 	_vm->_scene->loadScene(uVar1,0x1e);
 }
 
-void Minigame4::actorTalk(Actor *actorId,uint16 param_2,uint32 textIndex)
-{
+void Minigame4::actorTalk(Actor *actorId, uint16 param_2, uint32 textIndex) {
 	actorId->waitUntilFlag8SetThenSet1000AndWaitFor4();
 	if (actorId == _bruteActor) {
 		_bruteActor->updateSequence(9);
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index d4a5a350bd..2b285af732 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -166,8 +166,8 @@ void Minigame5::run() {
 	currentState = 1;
 	local_66 = 0;
 	local_50 = 0;
-	while ( true ) {
-		while ( true ) {
+	while (true) {
+		while (true) {
 			do {
 				_vm->waitForFrames(1);
 				switch (currentState) {
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
index 61f929d627..eaf51b878a 100644
--- a/engines/dragons/saveload.cpp
+++ b/engines/dragons/saveload.cpp
@@ -36,7 +36,6 @@ namespace Dragons {
 #define ILLUSIONS_SAVEGAME_VERSION 0
 
 kReadSaveHeaderError DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
-
 	header.version = in->readUint32LE();
 	if (header.version > ILLUSIONS_SAVEGAME_VERSION)
 		return kRSHEInvalidVersion;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 238f1acc9c..54dc7a32b3 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -219,7 +219,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_vm->_data_800633fc = 0;
 	// TODO 0x8002fff0
 
-	for (int i = 0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		if (ini->sceneId == sceneIdStripped) {
 			if (ini->field_1a_flags_maybe & 1) {
@@ -364,11 +364,10 @@ void Scene::draw() {
 			}
 
 			if (actor->_flags & ACTOR_FLAG_40 &&
-				!(actor->_flags & ACTOR_FLAG_400) &&
-				actor->_surface &&
-				actor->_frame->width != 0 &&
-				actor->_frame->height != 0
-				) {
+					!(actor->_flags & ACTOR_FLAG_400) &&
+					actor->_surface &&
+					actor->_frame->width != 0 &&
+					actor->_frame->height != 0 ) {
 				Graphics::Surface *s = actor->_surface;
 				if (actor->_priorityLayer == priority) { //} && x + s->w < 320 && y + s->h < 200) {
 					if (!actor->isFlagSet(ACTOR_FLAG_80)) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index ee9a5ce8ea..e1c5f52b59 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -238,8 +238,8 @@ void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field6);
 
 	if ((field2 >> _vm->_cursor->_data_800728b0_cursor_seqID) & 1
-	&& (_vm->_cursor->_data_800728b0_cursor_seqID < 5 || field4 == _scriptTargetINI)
-	&& scriptOpCall._field8 == 1) {
+			&& (_vm->_cursor->_data_800728b0_cursor_seqID < 5 || field4 == _scriptTargetINI)
+			&& scriptOpCall._field8 == 1) {
 		scriptOpCall._code -= 8;
 		scriptOpCall._result |= 1;
 	} else {
@@ -990,21 +990,21 @@ uint16 ScriptOpcodes::getINIField(uint32 iniIndex, uint16 fieldOffset) {
 	DragonINI *ini = _vm->getINI(iniIndex);
 
 	switch (fieldOffset) {
-		case 0 : return ini->iptIndex_maybe;
-		case 4 : return ini->actorResourceId;
-		case 6 : return ini->sequenceId;
-		case 0xC  : return ini->sceneId;
-		case 0xE  : return ini->field_e;
-		case 0x10 : return ini->field_10;
-		case 0x12  : return ini->field_12;
-		case 0x14 : return ini->field_14;
-		case 0x16 : return ini->x;
-		case 0x18 : return ini->y;
-		case 0x1A : return ini->field_1a_flags_maybe;
-		case 0x1C : return ini->field_1c;
-		case 0x1E : return ini->field_1e;
-		case 0x20 : return ini->field_20_actor_field_14;
-		default: error("getINIField() Invalid fieldOffset 0x%X", fieldOffset);
+	case 0 : return ini->iptIndex_maybe;
+	case 4 : return ini->actorResourceId;
+	case 6 : return ini->sequenceId;
+	case 0xC  : return ini->sceneId;
+	case 0xE  : return ini->field_e;
+	case 0x10 : return ini->field_10;
+	case 0x12  : return ini->field_12;
+	case 0x14 : return ini->field_14;
+	case 0x16 : return ini->x;
+	case 0x18 : return ini->y;
+	case 0x1A : return ini->field_1a_flags_maybe;
+	case 0x1C : return ini->field_1c;
+	case 0x1E : return ini->field_1e;
+	case 0x20 : return ini->field_20_actor_field_14;
+	default: error("getINIField() Invalid fieldOffset 0x%X", fieldOffset);
 	}
 }
 
@@ -1012,21 +1012,21 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 	DragonINI *ini = _vm->getINI(iniIndex);
 
 	switch (fieldOffset) {
-		case 0 : ini->iptIndex_maybe = value; break;
-		case 4 : ini->actorResourceId = value; break;
-		case 6 : ini->sequenceId = value; break;
-		case 0xc : ini->sceneId = value; break;
-		case 0xe : ini->field_e = value; break;
-		case 0x10 : ini->field_10 = value; break;
-		case 0x12 : ini->field_12 = value; break;
-		case 0x14 : ini->field_14 = value; break;
-		case 0x16 : ini->x = value; break;
-		case 0x18 : ini->y = value; break;
-		case 0x1A : ini->field_1a_flags_maybe = value; break;
-		case 0x1C : ini->field_1c = value; break;
-		case 0x1E : ini->field_1e = value; break;
-		case 0x20 : ini->field_20_actor_field_14 = value; break;
-		default: error("setINIField() Invalid fieldOffset 0x%X", fieldOffset);
+	case 0 : ini->iptIndex_maybe = value; break;
+	case 4 : ini->actorResourceId = value; break;
+	case 6 : ini->sequenceId = value; break;
+	case 0xc : ini->sceneId = value; break;
+	case 0xe : ini->field_e = value; break;
+	case 0x10 : ini->field_10 = value; break;
+	case 0x12 : ini->field_12 = value; break;
+	case 0x14 : ini->field_14 = value; break;
+	case 0x16 : ini->x = value; break;
+	case 0x18 : ini->y = value; break;
+	case 0x1A : ini->field_1a_flags_maybe = value; break;
+	case 0x1C : ini->field_1c = value; break;
+	case 0x1E : ini->field_1e = value; break;
+	case 0x20 : ini->field_20_actor_field_14 = value; break;
+	default: error("setINIField() Invalid fieldOffset 0x%X", fieldOffset);
 	}
 
 }
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index 940cf4d98a..fee9934f49 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -66,6 +66,7 @@ public:
 	int16 _data_80071f5c;
 	int16 _scriptTargetINI;
 	SpecialOpcodes *_specialOpCodes;
+
 protected:
 	DragonsEngine *_vm;
 	DragonFLG *_dragonFLG;
diff --git a/engines/dragons/sequenceopcodes.h b/engines/dragons/sequenceopcodes.h
index f072ef6044..1177b42f94 100644
--- a/engines/dragons/sequenceopcodes.h
+++ b/engines/dragons/sequenceopcodes.h
@@ -60,6 +60,7 @@ public:
 	SequenceOpcodes(DragonsEngine *vm);
 	~SequenceOpcodes();
 	void execOpcode(Actor *actor, OpCall &opCall);
+
 protected:
 	DragonsEngine *_vm;
 	SequenceOpcode *_opcodes[DRAGONS_NUM_SEQ_OPCODES];
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index c918baeab5..dc3e5f7376 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -46,8 +46,7 @@ struct SpeechLocation {
 	uint16 sectorEnd;
 } SpeechLocation;
 
-void CdIntToPos_0(uint32 param_1)//, byte *param_2)
-{
+void CdIntToPos_0(uint32 param_1) { //, byte *param_2)
 	int iVar1;
 	int iVar2;
 	int iVar3;
@@ -163,11 +162,11 @@ SoundManager::PSXAudioTrack::~PSXAudioTrack() {
 #define AUDIO_DATA_SAMPLE_COUNT 4032
 
 static const int s_xaTable[5][2] = {
-		{   0,   0 },
-		{  60,   0 },
-		{ 115, -52 },
-		{  98, -55 },
-		{ 122, -60 }
+	{   0,   0 },
+	{  60,   0 },
+	{ 115, -52 },
+	{  98, -55 },
+	{ 122, -60 }
 };
 
 void SoundManager::PSXAudioTrack::queueAudioFromSector(Common::SeekableReadStream *sector) {
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 1bf4f3081d..3ee39f778a 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -46,10 +46,10 @@
 namespace Dragons {
 
 const int16 shakeTbl[16] = {
-		5,      2,     -2,     -5,
-		5,      2,     -2,     -5,
-		-1,      2,     -1,     -1,
-		2,     -1,      1,      0
+	5,      2,     -2,     -5,
+	5,      2,     -2,     -5,
+	-1,      2,     -1,     -1,
+	2,     -1,      1,      0
 };
 
 // SpecialOpcodes
@@ -1084,8 +1084,8 @@ void SpecialOpcodes::spcUnk8b() {
 
 void SpecialOpcodes::spcHedgehogTest() {
 	if (_vm->_dragonINIResource->getRecord(0x168)->actor->_sequenceID == 4 &&
-		_vm->_dragonINIResource->getRecord(0x169)->actor->_sequenceID == 4 &&
-		_vm->_dragonINIResource->getRecord(0x16a)->actor->_sequenceID == 4) {
+			_vm->_dragonINIResource->getRecord(0x169)->actor->_sequenceID == 4 &&
+			_vm->_dragonINIResource->getRecord(0x16a)->actor->_sequenceID == 4) {
 		_vm->_dragonINIResource->getRecord(0x169)->field_12 = 1;
 	} else {
 		_vm->_dragonINIResource->getRecord(0x169)->field_12 = 0;
@@ -1308,48 +1308,48 @@ void SpecialOpcodes::setSpecialOpCounter(int16 newValue) {
 }
 
 void pizzaUpdateFunction() {
-		static int16 counter = 0;
-		DragonsEngine *vm = getEngine();
+	static int16 counter = 0;
+	DragonsEngine *vm = getEngine();
 
-		Actor *actorf4 = vm->getINI(0xf4)->actor;
-		Actor *actorf5 = vm->getINI(0xf5)->actor;
+	Actor *actorf4 = vm->getINI(0xf4)->actor;
+	Actor *actorf5 = vm->getINI(0xf5)->actor;
 
-		if (counter == 0) {
-			if (actorf4->isFlagSet(ACTOR_FLAG_4)) {
-				if (actorf4->_sequenceID == 0) {
-					actorf4->updateSequence(1);
-				} else {
-					if (actorf4->_sequenceID == 1) {
-						actorf4->updateSequence(2);
-						actorf5->_x_pos = 0x115;
-						actorf5->_y_pos = 0x5c;
-						actorf5->updateSequence(7);
-						counter = 0x2d;
-						return;
-					}
-					if (actorf4->_sequenceID == 2) {
-						if ((actorf5->_sequenceID == 8) &&
-							(actorf5->isFlagSet(ACTOR_FLAG_4))) {
-							actorf5->_x_pos = -100;
-							actorf5->_y_pos = 100;
-							actorf4->updateSequence(3);
-						} else {
-							if (actorf5->_sequenceID == 8) {
-								return;
-							}
-							actorf5->updateSequence(8);
-						}
+	if (counter == 0) {
+		if (actorf4->isFlagSet(ACTOR_FLAG_4)) {
+			if (actorf4->_sequenceID == 0) {
+				actorf4->updateSequence(1);
+			} else {
+				if (actorf4->_sequenceID == 1) {
+					actorf4->updateSequence(2);
+					actorf5->_x_pos = 0x115;
+					actorf5->_y_pos = 0x5c;
+					actorf5->updateSequence(7);
+					counter = 0x2d;
+					return;
+				}
+				if (actorf4->_sequenceID == 2) {
+					if ((actorf5->_sequenceID == 8) &&
+						(actorf5->isFlagSet(ACTOR_FLAG_4))) {
+						actorf5->_x_pos = -100;
+						actorf5->_y_pos = 100;
+						actorf4->updateSequence(3);
 					} else {
-						if (actorf4->_sequenceID != 3) {
+						if (actorf5->_sequenceID == 8) {
 							return;
 						}
-						actorf4->updateSequence(0);
+						actorf5->updateSequence(8);
+					}
+				} else {
+					if (actorf4->_sequenceID != 3) {
+						return;
 					}
+					actorf4->updateSequence(0);
 				}
 			}
-		} else {
-			counter--;
 		}
+	} else {
+		counter--;
+	}
 }
 
 void tableBasedSceneUpdateFunction() {
@@ -1467,7 +1467,7 @@ void castleFogUpdateFunction() {
 
 void menInMinesSceneUpdateFunction() {
 	const uint32 sceneUpdateFuncDialogTbl[4] = {
-			0x4590A, 0x45994, 0x459F4, 0x45A60
+		0x4590A, 0x45994, 0x459F4, 0x45A60
 	};
 	DragonsEngine *vm = getEngine();
 	uint16 sequenceId;
@@ -1497,13 +1497,13 @@ void menInMinesSceneUpdateFunction() {
 void monksAtBarSceneUpdateFunction() {
 	static uint8 monksAtBarCurrentState = 0;
 	static const uint32 sceneUpdateFuncDialogTbl[6] = {
-			0x37800, 0x37854, 0x378CA,
-			0x39152, 0x3919A, 0x3922C
+		0x37800, 0x37854, 0x378CA,
+		0x39152, 0x3919A, 0x3922C
 	};
 	static const uint32 barKeeperTextIdTbl[10] = {
-			0x38C68, 0x38CE2, 0x38D4E, 0x38CE2,
-			0x38DC2, 0x38E0C, 0x38C68, 0x38E5C,
-			0x38ED0, 0x38CE2
+		0x38C68, 0x38CE2, 0x38D4E, 0x38CE2,
+		0x38DC2, 0x38E0C, 0x38C68, 0x38E5C,
+		0x38ED0, 0x38CE2
 	};
 	static const uint32 DAT_800832f0[4] = {0x38F2A, 0x39000, 0x39084, 0x390E8};
 
@@ -1534,151 +1534,149 @@ void monksAtBarSceneUpdateFunction() {
 		specialOpCounter = specialOpCounter + -1;
 	}
 	if (specialOpCounter == 0) {
-
-
 		switch (monksAtBarCurrentState) {
-			case 0:
-				if (0x31 < vm->getRand(100)) {
-					sVar2 = vm->getRand(3);
-					specialOpCounter = (sVar2 + 3) * 0x3c;
-					monksAtBarCurrentState = 2;
-					break;
-				}
-				if (bVar1) {
-					barKeeper->updateSequence(0xc);
-					textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3) + 3];
-				} else {
-					barKeeper->updateSequence(2);
-					textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3)];
-				}
-				vm->_talk->playDialogAudioDontWait(textIndex);
-				monksAtBarCurrentState = 1;
-				specialOpCounter = 0;
-				break;
-			case 1:
-				if (bVar1) {
-					sequenceId = 8;
-				} else {
-					sequenceId = 0;
-				}
-				barKeeper->updateSequence(sequenceId);
-				specialOpCounter = 0x168;
+		case 0:
+			if (0x31 < vm->getRand(100)) {
+				sVar2 = vm->getRand(3);
+				specialOpCounter = (sVar2 + 3) * 0x3c;
 				monksAtBarCurrentState = 2;
 				break;
-			case 2: {
-				uint16 randTextId = vm->getRand(10);
-				if ((randTextId & 1) == 0) {
-					monk1->updateSequence(2);
-				} else {
-					monk2->updateSequence(10);
-				}
-				vm->_talk->playDialogAudioDontWait(barKeeperTextIdTbl[randTextId]);
-				monksAtBarCurrentState = 3;
-				specialOpCounter = 0;
-				break;
 			}
-			case 3:
-				monk1->updateSequence(0);
-				monk2->updateSequence(8);
-				specialOpCounter = 0x3c;
-				monksAtBarCurrentState = 4;
-				break;
-			case 4:
-				if (bVar1) {
-					barKeeper->updateSequence(0xc);
-					textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3) + 3];
-				} else {
-					barKeeper->updateSequence(2);
-					textIndex = DAT_800832f0[vm->getRand(4)];
-				}
-				vm->_talk->playDialogAudioDontWait(textIndex);
-				monksAtBarCurrentState = 5;
-				specialOpCounter = 0;
-				break;
-			case 5:
-				if (bVar1) {
-					sequenceId = 8;
-				} else {
-					sequenceId = 0;
-				}
-				barKeeper->updateSequence(sequenceId);
-				specialOpCounter = 0x78;
-				if (!bVar1) {
-					monksAtBarCurrentState = 0x37;
-					break;
-				}
-				monksAtBarCurrentState = 6;
-				break;
-			case 6:
-				if (bVar1) {
-					barKeeper->updateSequence(0xb);
-					ini->actor->updateSequence(7);
-					monksAtBarCurrentState = 10;
-				} else {
-					barKeeper->updateSequence(0xd);
-					monk1->updateSequence(0x14);
-					monksAtBarCurrentState = 0x41;
-				}
-				specialOpCounter = 0;
-				break;
-			case 7:
-				if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
-					break;
-				}
-				barKeeper->updateSequence(0xe);
-				monk2->updateSequence(0x15);
-				monksAtBarCurrentState = 8;
-				specialOpCounter = 0;
-				break;
-			case 8:
-				if (barKeeper->isFlagSet(ACTOR_FLAG_4)) {
-					monk2->updateSequence(8);
-					barKeeper->updateSequence(0);
-					monksAtBarCurrentState = 9;
-					specialOpCounter = 300;
-				}
-				break;
-			case 9:
-				sequenceId = 0x10;
-				if (0x31 < vm->getRand(100)) {
-					sequenceId = 0x16;
-				}
-				monk1->updateSequence(sequenceId);
-				sequenceId = 0x11;
-				if (0x31 < vm->getRand(100)) {
-					sequenceId = 0x17;
-				}
-				monk2->updateSequence(sequenceId);
-				monksAtBarCurrentState = 0;
-				sVar2 = vm->getRand(10);
-				specialOpCounter = (sVar2 + 10) * 0x3c;
-				break;
-			case 10:
-				if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
-					break;
-				}
-				ini->actor->updateSequence(0);
+			if (bVar1) {
+				barKeeper->updateSequence(0xc);
+				textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3) + 3];
+			} else {
+				barKeeper->updateSequence(2);
+				textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3)];
+			}
+			vm->_talk->playDialogAudioDontWait(textIndex);
+			monksAtBarCurrentState = 1;
+			specialOpCounter = 0;
+			break;
+		case 1:
+			if (bVar1) {
+				sequenceId = 8;
+			} else {
+				sequenceId = 0;
+			}
+			barKeeper->updateSequence(sequenceId);
+			specialOpCounter = 0x168;
+			monksAtBarCurrentState = 2;
+			break;
+		case 2: {
+			uint16 randTextId = vm->getRand(10);
+			if ((randTextId & 1) == 0) {
+				monk1->updateSequence(2);
+			} else {
+				monk2->updateSequence(10);
+			}
+			vm->_talk->playDialogAudioDontWait(barKeeperTextIdTbl[randTextId]);
+			monksAtBarCurrentState = 3;
+			specialOpCounter = 0;
+			break;
+		}
+		case 3:
+			monk1->updateSequence(0);
+			monk2->updateSequence(8);
+			specialOpCounter = 0x3c;
+			monksAtBarCurrentState = 4;
+			break;
+		case 4:
+			if (bVar1) {
+				barKeeper->updateSequence(0xc);
+				textIndex = sceneUpdateFuncDialogTbl[vm->getRand(3) + 3];
+			} else {
+				barKeeper->updateSequence(2);
+				textIndex = DAT_800832f0[vm->getRand(4)];
+			}
+			vm->_talk->playDialogAudioDontWait(textIndex);
+			monksAtBarCurrentState = 5;
+			specialOpCounter = 0;
+			break;
+		case 5:
+			if (bVar1) {
 				sequenceId = 8;
-				monk2 = barKeeper;
-				monk2->updateSequence(sequenceId);
-				monksAtBarCurrentState = 0;
-				sVar2 = vm->getRand(10);
-				specialOpCounter = (sVar2 + 10) * 0x3c;
+			} else {
+				sequenceId = 0;
+			}
+			barKeeper->updateSequence(sequenceId);
+			specialOpCounter = 0x78;
+			if (!bVar1) {
+				monksAtBarCurrentState = 0x37;
 				break;
-			case 0x37:
-				barKeeper->updateSequence(0x11);
-				specialOpCounter = 0x14;
-				monksAtBarCurrentState = 6;
+			}
+			monksAtBarCurrentState = 6;
+			break;
+		case 6:
+			if (bVar1) {
+				barKeeper->updateSequence(0xb);
+				ini->actor->updateSequence(7);
+				monksAtBarCurrentState = 10;
+			} else {
+				barKeeper->updateSequence(0xd);
+				monk1->updateSequence(0x14);
+				monksAtBarCurrentState = 0x41;
+			}
+			specialOpCounter = 0;
+			break;
+		case 7:
+			if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
 				break;
-			case 0x41:
-				if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
-					break;
-				}
-				barKeeper->updateSequence(0xf);
-				monk1->updateSequence(0);
-				monksAtBarCurrentState = 7;
-				specialOpCounter = 0;
+			}
+			barKeeper->updateSequence(0xe);
+			monk2->updateSequence(0x15);
+			monksAtBarCurrentState = 8;
+			specialOpCounter = 0;
+			break;
+		case 8:
+			if (barKeeper->isFlagSet(ACTOR_FLAG_4)) {
+				monk2->updateSequence(8);
+				barKeeper->updateSequence(0);
+				monksAtBarCurrentState = 9;
+				specialOpCounter = 300;
+			}
+			break;
+		case 9:
+			sequenceId = 0x10;
+			if (0x31 < vm->getRand(100)) {
+				sequenceId = 0x16;
+			}
+			monk1->updateSequence(sequenceId);
+			sequenceId = 0x11;
+			if (0x31 < vm->getRand(100)) {
+				sequenceId = 0x17;
+			}
+			monk2->updateSequence(sequenceId);
+			monksAtBarCurrentState = 0;
+			sVar2 = vm->getRand(10);
+			specialOpCounter = (sVar2 + 10) * 0x3c;
+			break;
+		case 10:
+			if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
+				break;
+			}
+			ini->actor->updateSequence(0);
+			sequenceId = 8;
+			monk2 = barKeeper;
+			monk2->updateSequence(sequenceId);
+			monksAtBarCurrentState = 0;
+			sVar2 = vm->getRand(10);
+			specialOpCounter = (sVar2 + 10) * 0x3c;
+			break;
+		case 0x37:
+			barKeeper->updateSequence(0x11);
+			specialOpCounter = 0x14;
+			monksAtBarCurrentState = 6;
+			break;
+		case 0x41:
+			if (!barKeeper->isFlagSet(ACTOR_FLAG_4)) {
 				break;
+			}
+			barKeeper->updateSequence(0xf);
+			monk1->updateSequence(0);
+			monksAtBarCurrentState = 7;
+			specialOpCounter = 0;
+			break;
 		}
 	}
 	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
@@ -1687,7 +1685,7 @@ void monksAtBarSceneUpdateFunction() {
 
 void flameEscapeSceneUpdateFunction() {
 	static const uint32 dialogTbl[6] = {
-			0x10458, 0x104A0, 0x10500, 0x10500, 0x10550, 0x10578 //TODO support multiple languages
+		0x10458, 0x104A0, 0x10500, 0x10500, 0x10550, 0x10578 //TODO support multiple languages
 	};
 	static bool DAT_800634c0 = false;
 	DragonsEngine *vm = getEngine();
@@ -1756,7 +1754,7 @@ void caveOfDilemmaUpdateFunction() {
 
 void moatDrainedSceneUpdateFunction() {
 	static const uint32 moatDrainedTextIdTbl[4] = {
-			0x3C97A, 0x3C9AC, 0x3C9F8, 0x3CA48
+		0x3C97A, 0x3C9AC, 0x3C9F8, 0x3CA48
 	};
 	static uint16 moatDrainedUpdateCounter = 0;
 	static bool moatDrainedStatus = false;
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 3579533dc7..b53790fa5d 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -69,15 +69,15 @@ void Talk::printWideText(byte *text) {
 	char buf[2000];
 	int i = 0;
 	for (; READ_LE_INT16(text) != 0 && i < 1999; i++) {
-	    char c = *text;
-	    if (c < 0x20) {
-	        buf[i++] = '0';
-	        buf[i++] = 'x';
-	        buf[i++] = (c & 0xF0 >> 4) + '0';
-	        buf[i] = (c & 0x0F) + '0';
-	    } else {
-            buf[i] = *text;
-        }
+		char c = *text;
+		if (c < 0x20) {
+			buf[i++] = '0';
+			buf[i++] = 'x';
+			buf[i++] = (c & 0xF0 >> 4) + '0';
+			buf[i] = (c & 0x0F) + '0';
+		} else {
+			buf[i] = *text;
+		}
 		text += 2;
 	}
 	buf[i] = 0;
@@ -110,43 +110,42 @@ Talk::FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param
 //	_vm->_fontManager->clearText();
 //}
 
-uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId,
-									  int16 param_7) {
-		//uint32 *puVar1;
-		//uint32 *puVar2;
-		short sVar3;
-		short sVar4;
-		uint16 *tmpTextPtr;
-		int iVar5;
-		int iVar6;
-		//int iVar7;
-		int iVar8;
-		uint uVar9;
-		uint uVar10;
-		uint16 uVar11;
-		//uint32 uVar12;
-		uint16 *puVar13;
-		//uint32 uVar14;
-		//uint32 uVar15;
-		//uint32 *puVar16;
-		//uint32 *puVar17;
-		uint16 *dialogTextLinePtr;
-		uint16 *puVar18;
-		uint16 *curDialogTextPtr;
-		int unaff_s4;
-		uint16 uVar19;
-		short sVar20;
-		uint32 maxLineLengthMaybe;
-		uint16 currentLine [44];
-		uint16 asStack2592 [1208];
-		//uint32 local_b0 [14];
-		uint16 local_58;
-		uint16 returnStatus;
-		//byte *lineTblPtr;
-		//uint oldEngineFlags;
-
-		bool isFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
-		returnStatus = 0;
+uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId, int16 param_7) {
+	//uint32 *puVar1;
+	//uint32 *puVar2;
+	short sVar3;
+	short sVar4;
+	uint16 *tmpTextPtr;
+	int iVar5;
+	int iVar6;
+	//int iVar7;
+	int iVar8;
+	uint uVar9;
+	uint uVar10;
+	uint16 uVar11;
+	//uint32 uVar12;
+	uint16 *puVar13;
+	//uint32 uVar14;
+	//uint32 uVar15;
+	//uint32 *puVar16;
+	//uint32 *puVar17;
+	uint16 *dialogTextLinePtr;
+	uint16 *puVar18;
+	uint16 *curDialogTextPtr;
+	int unaff_s4;
+	uint16 uVar19;
+	short sVar20;
+	uint32 maxLineLengthMaybe;
+	uint16 currentLine [44];
+	uint16 asStack2592 [1208];
+	//uint32 local_b0 [14];
+	uint16 local_58;
+	uint16 returnStatus;
+	//byte *lineTblPtr;
+	//uint oldEngineFlags;
+
+	bool isFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
+	returnStatus = 0;
 // TODO what does this do?
 //		puVar1 = uint32_ARRAY_80011a60;
 //		puVar2 = local_b0;
@@ -166,71 +165,71 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 //		uVar12 = puVar16[5];
 //		puVar17[4] = __dat_80011a80;
 //		puVar17[5] = uVar12;
-		if (param_5 != 0) {
-			_vm->clearFlags(ENGINE_FLAG_8);
-		}
-		tmpTextPtr = findCharInU16Str(dialogText,0x5c);
-		if (tmpTextPtr != NULL) {
-			sVar3 = tmpTextPtr[1];
-			*tmpTextPtr = sVar3;
-			while (sVar3 != 0) {
-				sVar3 = tmpTextPtr[2];
-				tmpTextPtr[1] = sVar3;
-				tmpTextPtr = tmpTextPtr + 1;
-			}
-		}
-		iVar5 = (uint)x << 0x10;
-		if ((short)x < 0xf) {
-			x = 0xf;
-			iVar5 = 0xf0000;
-		}
-		if (0x19 < iVar5 >> 0x10) {
-			x = 0x19;
-		}
-		iVar5 = (uint)y << 0x10;
-		if ((int)((uint)y << 0x10) < 0) {
-			y = 0;
-			iVar5 = 0;
-		}
-		if (0x18 < iVar5 >> 0x10) {
-			y = 0x18;
-		}
-		local_58 = x;
-		if (0x13 < (short)x) {
-			local_58 = 0x27 - x;
+	if (param_5 != 0) {
+		_vm->clearFlags(ENGINE_FLAG_8);
+	}
+	tmpTextPtr = findCharInU16Str(dialogText,0x5c);
+	if (tmpTextPtr != NULL) {
+		sVar3 = tmpTextPtr[1];
+		*tmpTextPtr = sVar3;
+		while (sVar3 != 0) {
+			sVar3 = tmpTextPtr[2];
+			tmpTextPtr[1] = sVar3;
+			tmpTextPtr = tmpTextPtr + 1;
 		}
-		iVar5 = ((int)((uint)local_58 << 0x10) >> 0xf) + 2;
+	}
+	iVar5 = (uint)x << 0x10;
+	if ((short)x < 0xf) {
+		x = 0xf;
+		iVar5 = 0xf0000;
+	}
+	if (0x19 < iVar5 >> 0x10) {
+		x = 0x19;
+	}
+	iVar5 = (uint)y << 0x10;
+	if ((int)((uint)y << 0x10) < 0) {
+		y = 0;
+		iVar5 = 0;
+	}
+	if (0x18 < iVar5 >> 0x10) {
+		y = 0x18;
+	}
+	local_58 = x;
+	if (0x13 < (short)x) {
+		local_58 = 0x27 - x;
+	}
+	iVar5 = ((int)((uint)local_58 << 0x10) >> 0xf) + 2;
 //		if (_dat_800726ec_tfont_field0 == 0) {
 //			trap(0x1c00);
 //		}
 //		if (((uint)_dat_800726ec_tfont_field0 == 0xffffffff) && (iVar5 == -0x80000000)) {
 //			trap(0x1800);
 //		}
-		sVar3 = (short)(iVar5 / (int)(uint)_dat_800726ec_tfont_field0);
-		if (*dialogText != 0) {
-			/* check for space or hyphen */
-			curDialogTextPtr = dialogText;
+	sVar3 = (short)(iVar5 / (int)(uint)_dat_800726ec_tfont_field0);
+	if (*dialogText != 0) {
+		/* check for space or hyphen */
+		curDialogTextPtr = dialogText;
+		do {
+			maxLineLengthMaybe = 0;
+			iVar5 = 0;
 			do {
-				maxLineLengthMaybe = 0;
-				iVar5 = 0;
-				do {
-					sVar20 = (short)maxLineLengthMaybe;
+				sVar20 = (short)maxLineLengthMaybe;
+				uVar19 = *curDialogTextPtr;
+				iVar6 = iVar5;
+				if (uVar19 == 0) break;
+				while (uVar19 == 0x20) {
+					curDialogTextPtr = curDialogTextPtr + 1;
 					uVar19 = *curDialogTextPtr;
-					iVar6 = iVar5;
-					if (uVar19 == 0) break;
-					while (uVar19 == 0x20) {
-						curDialogTextPtr = curDialogTextPtr + 1;
-						uVar19 = *curDialogTextPtr;
-					}
-					iVar8 = 0;
-					iVar6 = (int)sVar3 + -2;
-					for (unaff_s4 = 0; unaff_s4 < iVar6; unaff_s4++) {
-						currentLine[unaff_s4] = curDialogTextPtr[unaff_s4];
-						if (currentLine[unaff_s4] == 0) {
-							iVar8 = -1;
-							break;
-						}
+				}
+				iVar8 = 0;
+				iVar6 = (int)sVar3 + -2;
+				for (unaff_s4 = 0; unaff_s4 < iVar6; unaff_s4++) {
+					currentLine[unaff_s4] = curDialogTextPtr[unaff_s4];
+					if (currentLine[unaff_s4] == 0) {
+						iVar8 = -1;
+						break;
 					}
+				}
 //					unaff_s4 = 0;
 //					if (0 < iVar6) {
 //						iVar7 = 0;
@@ -246,19 +245,20 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 //							iVar7 = unaff_s4 * 0x10000;
 //						} while (unaff_s4 < iVar6);
 //					}
-					iVar6 = iVar5;
-					if ((int)(short)unaff_s4 == 0) break;
-					currentLine[(int)(short)unaff_s4] = 0;
-
-					if (iVar8 == 0) {
-						iVar8 = unaff_s4 - 1;
-						for (; iVar8 >= 0 ; iVar8--) {
-							if (currentLine[iVar8] == 0x20 || currentLine[iVar8] == 0x2d) {
-								break;
-							}
+				iVar6 = iVar5;
+				if ((int)(short)unaff_s4 == 0)
+					break;
+				currentLine[(int)(short)unaff_s4] = 0;
+
+				if (iVar8 == 0) {
+					iVar8 = unaff_s4 - 1;
+					for (; iVar8 >= 0 ; iVar8--) {
+						if (currentLine[iVar8] == 0x20 || currentLine[iVar8] == 0x2d) {
+							break;
 						}
-						goto LAB_800328f8;
 					}
+					goto LAB_800328f8;
+				}
 //					iVar6 = (iVar8 << 0x10) >> 0x10;
 //					if (iVar8 << 0x10 == 0) {
 //						iVar8 = unaff_s4 + -1;
@@ -273,16 +273,16 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 //							goto LAB_800328f8;
 //						}
 //					} else
-					{
-						LAB_800328f8:
-						if (-1 < iVar8) {
-							if (currentLine[iVar8] == 0x20) {
-								for (; iVar8 >= 0; iVar8--) {
-									if (currentLine[iVar8] != 0x20) {
-										break;
-									}
-									currentLine[iVar8] = 0;
+				{
+					LAB_800328f8:
+					if (-1 < iVar8) {
+						if (currentLine[iVar8] == 0x20) {
+							for (; iVar8 >= 0; iVar8--) {
+								if (currentLine[iVar8] != 0x20) {
+									break;
 								}
+								currentLine[iVar8] = 0;
+							}
 
 //								do {
 //									if (*(short *)(((iVar8 << 0x10) >> 0xf) + (int)currentLine) != 0x20) break;
@@ -290,150 +290,148 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 //									*(undefined2 *)(((iVar8 << 0x10) >> 0xf) + (int)currentLine) = 0;
 //									iVar8 = iVar6;
 //								} while (-1 < iVar6 * 0x10000);
-							} else {
-								currentLine[iVar8 + 1] = 0;
-							}
+						} else {
+							currentLine[iVar8 + 1] = 0;
 						}
 					}
+				}
 
-					iVar6 = iVar5;
-					if (currentLine[0] == 0) break;
-					iVar6 = iVar5 + 1;
-					UTF16ToUTF16Z(asStack2592 + (int)(short)iVar5 * 0x29,currentLine);
-					uVar9 = strlenUTF16(currentLine);
-					if ((int)sVar20 < (int)(uVar9 & 0xffff)) {
-						maxLineLengthMaybe = strlenUTF16(currentLine);
-					}
-					sVar20 = (short)maxLineLengthMaybe;
+				iVar6 = iVar5;
+				if (currentLine[0] == 0) break;
+				iVar6 = iVar5 + 1;
+				UTF16ToUTF16Z(asStack2592 + (int)(short)iVar5 * 0x29,currentLine);
+				uVar9 = strlenUTF16(currentLine);
+				if ((int)sVar20 < (int)(uVar9 & 0xffff)) {
+					maxLineLengthMaybe = strlenUTF16(currentLine);
+				}
+				sVar20 = (short)maxLineLengthMaybe;
+				uVar9 = strlenUTF16(currentLine);
+				curDialogTextPtr = curDialogTextPtr + (uVar9 & 0xffff);
+				iVar5 = iVar6;
+			} while (iVar6 * 0x10000 >> 0x10 < 5);
+			sVar4 = (short)iVar6;
+			iVar5 = iVar6 << 0x10;
+			puVar18 = curDialogTextPtr;
+			if (sVar4 == 5) {
+				if (*curDialogTextPtr != 0) {
+					uVar19 = *curDialogTextPtr;
+					puVar13 = curDialogTextPtr;
+					do {
+						if (0x20 < uVar19) break;
+						puVar13 = puVar13 + 1;
+						uVar19 = *puVar13;
+					} while (uVar19 != 0);
+					iVar5 = iVar6 << 0x10;
+					puVar18 = curDialogTextPtr;
+					if (*puVar13 == 0) goto LAB_80032a70;
 					uVar9 = strlenUTF16(currentLine);
-					curDialogTextPtr = curDialogTextPtr + (uVar9 & 0xffff);
-					iVar5 = iVar6;
-				} while (iVar6 * 0x10000 >> 0x10 < 5);
+//						curDialogTextPtr = curDialogTextPtr + (uVar9 & 0xffff) * 0x7fffffff; TODO why was this line generated?
+					curDialogTextPtr -= uVar9;
+					iVar6 = iVar6 + -1;
+				}
 				sVar4 = (short)iVar6;
 				iVar5 = iVar6 << 0x10;
 				puVar18 = curDialogTextPtr;
-				if (sVar4 == 5) {
-					if (*curDialogTextPtr != 0) {
-						uVar19 = *curDialogTextPtr;
-						puVar13 = curDialogTextPtr;
-						do {
-							if (0x20 < uVar19) break;
-							puVar13 = puVar13 + 1;
-							uVar19 = *puVar13;
-						} while (uVar19 != 0);
-						iVar5 = iVar6 << 0x10;
-						puVar18 = curDialogTextPtr;
-						if (*puVar13 == 0) goto LAB_80032a70;
-						uVar9 = strlenUTF16(currentLine);
-//						curDialogTextPtr = curDialogTextPtr + (uVar9 & 0xffff) * 0x7fffffff; TODO why was this line generated?
-						curDialogTextPtr -= uVar9;
-						iVar6 = iVar6 + -1;
-					}
-					sVar4 = (short)iVar6;
-					iVar5 = iVar6 << 0x10;
-					puVar18 = curDialogTextPtr;
-				}
-				LAB_80032a70:
-				iVar5 = (iVar5 >> 0x10) * (uint)_dat_800726f0_tfont_field2 + -1;
-				uVar19 = y;
-				if ((int)(short)y < iVar5) {
-					uVar19 = (uint16)iVar5;
-				}
-				if (0x16 < (short)uVar19) {
-					uVar19 = 0x16;
-				}
-				uVar11 = sVar20 * _dat_800726ec_tfont_field0 + 3 & 0xfffe;
-				sVar20 = (short)uVar11 >> 1;
-				if ((short)x < 0x14) {
-					_dat_8008e7e8_dialogBox_x1 = (x - sVar20) + 1;
-				} else {
-					_dat_8008e7e8_dialogBox_x1 = x - sVar20;
-				}
-				_dat_8008e848_dialogBox_x2 = (uVar11 + _dat_8008e7e8_dialogBox_x1) - 1;
-				_dat_8008e844_dialogBox_y1 = (uVar19 - sVar4 * _dat_800726f0_tfont_field2) + 1;
-				_dat_8008e874_dialogBox_y2 = _dat_8008e844_dialogBox_y1 + sVar4 * _dat_800726f0_tfont_field2 + 1;
-				if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) && ((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)))) {
-					unaff_s4 = 0;
-					FUN_8001a4e4_draw_dialogbox((uint) _dat_8008e7e8_dialogBox_x1, (uint) _dat_8008e844_dialogBox_y1,
-												(uint) _dat_8008e848_dialogBox_x2, (uint) _dat_8008e874_dialogBox_y2, 0);
-					if (sVar4 > 0) {
-						for (; unaff_s4 < sVar4; unaff_s4++) {
-							if ((short)x < 0x14) {
-								dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
-								uVar9 = strlenUTF16(dialogTextLinePtr);
-								uVar9 = ((uint)x - ((int)((uint)_dat_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1)) + 1;
-							} else {
-								dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
-								uVar9 = strlenUTF16(dialogTextLinePtr);
-								uVar9 = (uint)x - ((int)((uint)_dat_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1);
-							}
-							_vm->_fontManager->addText(uVar9 * 8,
-													   ((uint)_dat_8008e844_dialogBox_y1 + unaff_s4 * (uint)_dat_800726f0_tfont_field2 + 1) * 8,
-									dialogTextLinePtr, wideStrLen(dialogTextLinePtr), 0);
+			}
+			LAB_80032a70:
+			iVar5 = (iVar5 >> 0x10) * (uint)_dat_800726f0_tfont_field2 + -1;
+			uVar19 = y;
+			if ((int)(short)y < iVar5) {
+				uVar19 = (uint16)iVar5;
+			}
+			if (0x16 < (short)uVar19) {
+				uVar19 = 0x16;
+			}
+			uVar11 = sVar20 * _dat_800726ec_tfont_field0 + 3 & 0xfffe;
+			sVar20 = (short)uVar11 >> 1;
+			if ((short)x < 0x14) {
+				_dat_8008e7e8_dialogBox_x1 = (x - sVar20) + 1;
+			} else {
+				_dat_8008e7e8_dialogBox_x1 = x - sVar20;
+			}
+			_dat_8008e848_dialogBox_x2 = (uVar11 + _dat_8008e7e8_dialogBox_x1) - 1;
+			_dat_8008e844_dialogBox_y1 = (uVar19 - sVar4 * _dat_800726f0_tfont_field2) + 1;
+			_dat_8008e874_dialogBox_y2 = _dat_8008e844_dialogBox_y1 + sVar4 * _dat_800726f0_tfont_field2 + 1;
+			if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) && ((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)))) {
+				unaff_s4 = 0;
+				FUN_8001a4e4_draw_dialogbox((uint) _dat_8008e7e8_dialogBox_x1, (uint) _dat_8008e844_dialogBox_y1,
+											(uint) _dat_8008e848_dialogBox_x2, (uint) _dat_8008e874_dialogBox_y2, 0);
+				if (sVar4 > 0) {
+					for (; unaff_s4 < sVar4; unaff_s4++) {
+						if ((short)x < 0x14) {
+							dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
+							uVar9 = strlenUTF16(dialogTextLinePtr);
+							uVar9 = ((uint)x - ((int)((uint)_dat_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1)) + 1;
+						} else {
+							dialogTextLinePtr = asStack2592 + unaff_s4 * 0x29;
+							uVar9 = strlenUTF16(dialogTextLinePtr);
+							uVar9 = (uint)x - ((int)((uint)_dat_800726ec_tfont_field0 * (uVar9 & 0xffff) + 1) >> 1);
+						}
+						_vm->_fontManager->addText(uVar9 * 8,
+												   ((uint)_dat_8008e844_dialogBox_y1 + unaff_s4 * (uint)_dat_800726f0_tfont_field2 + 1) * 8,
+								dialogTextLinePtr, wideStrLen(dialogTextLinePtr), 0);
 //							ProbablyShowUTF16Msg3
 //									(dialogTextLinePtr,uVar9 & 0xffff,
 //									 (uint)_dat_8008e844_dialogBox_y1 + iVar5 * (uint)_dat_800726f0_tfont_field2 + 1
 //									 & 0xffff,(uint)param_4, 0xffffffff);
-						}
 					}
 				}
-				if (param_5 == 0) {
-					_vm->_data_800633fc = 0;
-					return (uint)returnStatus;
-				}
-				uVar9 = ((int)((int)(short)unaff_s4 * (uint)1 * (int)sVar3) >> 3) * 0x3c;
-				if ((param_7 == 0) && _vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED)) {
-					uVar9 = 0;
-				}
-				do {
-					curDialogTextPtr = puVar18;
-					if (!_vm->isFlagSet(ENGINE_FLAG_8000)) goto LAB_80032e18;
-					_vm->waitForFrames(1);
-					if (_vm->_sound->_dat_8006bb60_sound_related != 0) {
-						_vm->_sound->_dat_8006bb60_sound_related = 0;
-						curDialogTextPtr = dialogText;
-						if (!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED)) {
-							returnStatus = 1;
-							goto LAB_80032e18;
-						}
-					}
-					if ((uVar9 & 0xffff) != 0) {
-						uVar9--;
-					}
-					uVar10 = _vm->checkForActionButtonRelease() ? 1 : 0; // CheckButtonMapPress_ActionOrCross(0);
-					curDialogTextPtr = puVar18;
-					if ((uVar10 & 0xffff) != 0) {
+			}
+			if (param_5 == 0) {
+				_vm->_data_800633fc = 0;
+				return (uint)returnStatus;
+			}
+			uVar9 = ((int)((int)(short)unaff_s4 * (uint)1 * (int)sVar3) >> 3) * 0x3c;
+			if ((param_7 == 0) && _vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED)) {
+				uVar9 = 0;
+			}
+			do {
+				curDialogTextPtr = puVar18;
+				if (!_vm->isFlagSet(ENGINE_FLAG_8000)) goto LAB_80032e18;
+				_vm->waitForFrames(1);
+				if (_vm->_sound->_dat_8006bb60_sound_related != 0) {
+					_vm->_sound->_dat_8006bb60_sound_related = 0;
+					curDialogTextPtr = dialogText;
+					if (!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED)) {
 						returnStatus = 1;
 						goto LAB_80032e18;
 					}
-					uVar10 = 0; //TODO PressedThisFrameStart(0);
-				} while ((uVar10 & 0xffff) == 0);
-				returnStatus = 2;
+				}
+				if ((uVar9 & 0xffff) != 0) {
+					uVar9--;
+				}
+				uVar10 = _vm->checkForActionButtonRelease() ? 1 : 0; // CheckButtonMapPress_ActionOrCross(0);
 				curDialogTextPtr = puVar18;
-				LAB_80032e18:
-				//TODO CheckIfCdShellIsOpen();
-				if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
-					FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1,(uint)_dat_8008e844_dialogBox_y1,
-								 (uint)_dat_8008e848_dialogBox_x2,(uint)_dat_8008e874_dialogBox_y2);
+				if ((uVar10 & 0xffff) != 0) {
+					returnStatus = 1;
+					goto LAB_80032e18;
 				}
-			} while (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) &&
-					 (((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)) && (*curDialogTextPtr != 0))));
-		}
-		if (param_5 != 0) {
-			if (_vm->isFlagSet(ENGINE_FLAG_8000)) {
-				_vm->_sound->PauseCDMusic();
-			}
-			if (isFlag8Set) {
-				_vm->setFlags(ENGINE_FLAG_8);
+				uVar10 = 0; //TODO PressedThisFrameStart(0);
+			} while ((uVar10 & 0xffff) == 0);
+			returnStatus = 2;
+			curDialogTextPtr = puVar18;
+			LAB_80032e18:
+			//TODO CheckIfCdShellIsOpen();
+			if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
+				FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1,(uint)_dat_8008e844_dialogBox_y1,
+							 (uint)_dat_8008e848_dialogBox_x2,(uint)_dat_8008e874_dialogBox_y2);
 			}
+		} while (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) &&
+				 (((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)) && (*curDialogTextPtr != 0))));
+	}
+	if (param_5 != 0) {
+		if (_vm->isFlagSet(ENGINE_FLAG_8000)) {
+			_vm->_sound->PauseCDMusic();
+		}
+		if (isFlag8Set) {
+			_vm->setFlags(ENGINE_FLAG_8);
 		}
-		_vm->_data_800633fc = 0;
-		return (uint)returnStatus;
+	}
+	_vm->_data_800633fc = 0;
+	return (uint)returnStatus;
 }
 
-uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex)
-
-{
+uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex) {
 	DragonINI *ini = iniId == 0 ? _vm->_dragonINIResource->getFlickerRecord() : _vm->getINI(iniId - 1);
 
 	if ((ini->field_1a_flags_maybe & 1) == 0) {
@@ -467,8 +465,7 @@ void Talk::loadAndDisplayDialogAroundPoint(uint32 textId, uint16 x, uint16 y, ui
 	displayDialogAroundPoint(buffer, x, y, param_4, param_5, textId);
 }
 
-void
-Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId) {
+void Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 param_4, int16 param_5, uint32 textId) {
 // TODO
 //
 //		puVar1 = &_dat_80011a60;
@@ -497,7 +494,7 @@ Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint16 pa
 //		if (dialogText == (uint16 *)0x0) {
 //			dialogText = (uint16 *)local_58;
 //		}
-		conversation_related_maybe(dialogText,x,y,param_4,param_5,textId,0); // sVar3); TODO I think this is audio status
+	conversation_related_maybe(dialogText,x,y,param_4,param_5,textId,0); // sVar3); TODO I think this is audio status
 }
 
 void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex) {
@@ -1010,7 +1007,7 @@ void Talk::FUN_8001a4e4_draw_dialogbox(uint32 x1, uint32 y1, uint32 x2, uint32 y
 }
 
 uint16 *Talk::findCharInU16Str(uint16 *text, uint16 chr) {
-	for ( int i = 0; text[i] != 0; i++) {
+	for (int i = 0; text[i] != 0; i++) {
 		if (text[i] == chr) {
 			return &text[i];
 		}
@@ -1019,8 +1016,7 @@ uint16 *Talk::findCharInU16Str(uint16 *text, uint16 chr) {
 	return NULL;
 }
 
-uint16 *Talk::UTF16ToUTF16Z(uint16 *dest, uint16 *src)
-{
+uint16 *Talk::UTF16ToUTF16Z(uint16 *dest, uint16 *src) {
 	uint16 chr;
 	uint16 *ptr;
 


Commit: 3d72a0a816cc74cd4c7ccf520f818830c8e13e7f
    https://github.com/scummvm/scummvm/commit/3d72a0a816cc74cd4c7ccf520f818830c8e13e7f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Rename VabSound.* to vabsound.*

Changed paths:
  A engines/dragons/vabsound.cpp
  A engines/dragons/vabsound.h
  R engines/dragons/VabSound.cpp
  R engines/dragons/VabSound.h
    engines/dragons/module.mk
    engines/dragons/sound.cpp


diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index 81d8559741..ed9169508e 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -32,7 +32,7 @@ MODULE_OBJS := \
 	specialopcodes.o \
 	sound.o \
 	talk.o \
-	VabSound.o
+	vabsound.o
 
 MODULE_DIRS += \
 	engines/dragons
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index dc3e5f7376..d95595cd5b 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -29,7 +29,7 @@
 #include "dragons/sound.h"
 #include "dragons/bigfile.h"
 #include "dragons/dragonrms.h"
-#include "dragons/VabSound.h"
+#include "dragons/vabsound.h"
 
 #define RAW_CD_SECTOR_SIZE 2352
 
diff --git a/engines/dragons/VabSound.cpp b/engines/dragons/vabsound.cpp
similarity index 99%
rename from engines/dragons/VabSound.cpp
rename to engines/dragons/vabsound.cpp
index c81c3e4d21..d2e772a30d 100644
--- a/engines/dragons/VabSound.cpp
+++ b/engines/dragons/vabsound.cpp
@@ -25,7 +25,7 @@
 #include "audio/audiostream.h"
 #include "audio/mixer.h"
 #include "common/memstream.h"
-#include "dragons/VabSound.h"
+#include "dragons/vabsound.h"
 #include "dragons/dragons.h"
 
 namespace Dragons {
diff --git a/engines/dragons/VabSound.h b/engines/dragons/vabsound.h
similarity index 100%
rename from engines/dragons/VabSound.h
rename to engines/dragons/vabsound.h


Commit: aae718b99de23a65ae80f8e591cbbe7f6bc613e2
    https://github.com/scummvm/scummvm/commit/aae718b99de23a65ae80f8e591cbbe7f6bc613e2
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Whitespace fixes

Changed paths:
    engines/dragons/module.mk


diff --git a/engines/dragons/module.mk b/engines/dragons/module.mk
index ed9169508e..fc0828899d 100644
--- a/engines/dragons/module.mk
+++ b/engines/dragons/module.mk
@@ -1,21 +1,21 @@
 MODULE := engines/dragons
- 
+
 MODULE_OBJS := \
-    actor.o \
-    actorresource.o \
-    background.o \
-    bag.o \
-    bigfile.o \
-    credits.o \
-    cursor.o \
-    cutscene.o \
+	actor.o \
+	actorresource.o \
+	background.o \
+	bag.o \
+	bigfile.o \
+	credits.o \
+	cursor.o \
+	cutscene.o \
 	detection.o \
-    dragonflg.o \
-    dragonimg.o \
-    dragonini.o \
-    dragonobd.o \
-    dragonrms.o \
-    dragonvar.o \
+	dragonflg.o \
+	dragonimg.o \
+	dragonini.o \
+	dragonobd.o \
+	dragonrms.o \
+	dragonvar.o \
 	dragons.o \
 	font.o \
 	inventory.o \
@@ -36,11 +36,11 @@ MODULE_OBJS := \
 
 MODULE_DIRS += \
 	engines/dragons
- 
+
 # This module can be built as a plugin
 ifeq ($(ENABLE_QUUX), DYNAMIC_PLUGIN)
 PLUGIN := 1
 endif
- 
-# Include common rules 
+
+# Include common rules
 include $(srcdir)/rules.mk


Commit: 8ffb484c34103af0fa1594293790dcf957af698d
    https://github.com/scummvm/scummvm/commit/8ffb484c34103af0fa1594293790dcf957af698d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fix #include directive

Changed paths:
    engines/dragons/credits.cpp


diff --git a/engines/dragons/credits.cpp b/engines/dragons/credits.cpp
index a41b5b0578..3cb07cf1b0 100644
--- a/engines/dragons/credits.cpp
+++ b/engines/dragons/credits.cpp
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
-#include "credits.h"
+#include "dragons/credits.h"
 
 #include "common/system.h"
 #include "dragons/bigfile.h"


Commit: 79c7dbc8f60a5d3375097777c5c2ad436a6fc8e4
    https://github.com/scummvm/scummvm/commit/79c7dbc8f60a5d3375097777c5c2ad436a6fc8e4
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Whitespace fixes

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/background.cpp
    engines/dragons/cursor.cpp
    engines/dragons/cutscene.h
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/scene.cpp
    engines/dragons/screen.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/sound.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index c6735e4b10..e41e0bb80c 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -591,7 +591,7 @@ uint16 Actor::canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 ta
 			return 1;
 		}
 		int16 priority = getEngine()->_scene->getPriorityAtPosition(Common::Point(x>>0x10, y>>0x10));
-		if ( priority < 0) {
+		if (priority < 0) {
 			priority = 1;
 		}
 		if (!(walkFlags & 0x7fff) && (priority == 0 || priority >= 8)) {
@@ -693,12 +693,12 @@ void Actor::walkPath() {
 		_xShl16 += (((_scale * _walkSlopeX) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
 		_yShl16 += (((_scale * _walkSlopeY) / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) * 5) / 4;
 
-		if ( (_walkSlopeX >= 0 && _walkDestX < (_xShl16 >> 0x10))
+		if ((_walkSlopeX >= 0 && _walkDestX < (_xShl16 >> 0x10))
 				|| (_walkSlopeX < 0 && (_xShl16 >> 0x10) < _walkDestX)) {
 			_xShl16 = _walkDestX << 0x10;
 		}
 
-		if ( (_walkSlopeY >= 0 && _walkDestY < (_yShl16 >> 0x10))
+		if ((_walkSlopeY >= 0 && _walkDestY < (_yShl16 >> 0x10))
 				|| (_walkSlopeY < 0 && (_yShl16 >> 0x10) < _walkDestY)) {
 			_yShl16 = _walkDestY << 0x10;
 		}
@@ -752,7 +752,7 @@ int16 Actor::pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 tar
 		if (point.x != -1 && !pointsInUseTbl[i]) {
 			if (canWalkLine(point.x, point.y, target_x, target_y, unkType)) {
 				uint32 dist = abs(point.x - actor_x) * abs(point.x - actor_x) + abs(point.y - actor_y) * abs(point.y - actor_y);
-				if ( dist < minDist) {
+				if (dist < minDist) {
 					minDist = dist;
 					pointId = i;
 				}
diff --git a/engines/dragons/background.cpp b/engines/dragons/background.cpp
index 66ed3c067c..32f6247e91 100644
--- a/engines/dragons/background.cpp
+++ b/engines/dragons/background.cpp
@@ -88,9 +88,9 @@ Background::Background() : _priorityLayer(0), _points2(0), _data(0) {
 	_layerSurface[0] = NULL;
 	_layerSurface[1] = NULL;
 	_layerSurface[2] = NULL;
-	_layerOffset[0] = Common::Point(0,0);
-	_layerOffset[1] = Common::Point(0,0);
-	_layerOffset[2] = Common::Point(0,0);
+	_layerOffset[0] = Common::Point(0, 0);
+	_layerOffset[1] = Common::Point(0, 0);
+	_layerOffset[2] = Common::Point(0, 0);
 	_layerAlphaMode[0] = NORMAL;
 	_layerAlphaMode[1] = NORMAL;
 	_layerAlphaMode[2] = NORMAL;
@@ -125,13 +125,13 @@ bool Background::load(byte *dataStart, uint32 size) {
 	stream.seek(0x308);
 
 	uint32 tilemapOffset = 0x324;
-	for (int i = 0; i < 3;i++) {
+	for (int i = 0; i < 3; i++) {
 		_tileMap[i].w = stream.readUint16LE();
 		_tileMap[i].h = stream.readUint16LE();
 		_tileMap[i].size = stream.readUint32LE();
 		_tileMap[i].map = dataStart + tilemapOffset;
 		_tileMap[i].tileIndexOffset = tileindexOffset;
-		debug("Tilemap (%d,%d) map: %X", _tileMap[i].w, _tileMap[i].h, tilemapOffset);
+		debug("Tilemap (%d, %d) map: %X", _tileMap[i].w, _tileMap[i].h, tilemapOffset);
 
 		tilemapOffset += _tileMap[i].size;
 	}
@@ -239,8 +239,8 @@ int16 Background::getPriorityAtPoint(Common::Point pos) {
 }
 
 void Background::overlayImage(uint16 layerNum, byte *data, int16 x, int16 y, int16 w, int16 h) {
-	for (int i = 0; i < h; i++ ) {
-		for (int j = 0; j < w; j++ ) {
+	for (int i = 0; i < h; i++) {
+		for (int j = 0; j < w; j++) {
 			int16 idx = READ_LE_UINT16(data) + _tileMap[layerNum].tileIndexOffset;
 			drawTileToSurface(_layerSurface[layerNum],
 					_palette,
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 1012402bca..11f341e1ae 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -203,7 +203,7 @@ int16 Cursor::updateIniFromScene() {
 	int16 data_80072890_orig = _data_80072890;
 	int16 data_800728b0_cursor_seqID_orig = _data_800728b0_cursor_seqID;
 
-	for (int i = 0;i <_vm->_dragonINIResource->totalRecords(); i++) {
+	for (int i = 0; i <_vm->_dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId != _vm->_scene->getSceneId()) {
 			// 0x80028be4
diff --git a/engines/dragons/cutscene.h b/engines/dragons/cutscene.h
index c5d1957e23..88252b5dbf 100644
--- a/engines/dragons/cutscene.h
+++ b/engines/dragons/cutscene.h
@@ -68,11 +68,11 @@ private:
 	//Scene 1 related functions
 	void fadeScreenAndResetActor(Actor *actor);
 	void closeUpShotOnActor(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4);
-	void fun_8003d8e8(uint16 resourceId,uint16 sequenceId,int16 x,uint32 param_4);
+	void fun_8003d8e8(uint16 resourceId, uint16 sequenceId, int16 x, uint32 param_4);
 	void wideAngleEveryoneAtTable();
 	void fun_8003d388();
 	void closeUpKnightsAtTable();
-	uint16 fun_8003dab8(uint32 textId,uint16 x,uint16 y,uint16 param_4,int16 param_5);
+	uint16 fun_8003dab8(uint32 textId, uint16 x, uint16 y, uint16 param_4, int16 param_5);
 	void cursorInventoryClearFlag400();
 	void changeBackgroundPosition(uint16 newPosition, int16 sParm2);
 	void loadPalettes();
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index bfec818c31..1b32a51f9d 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -243,7 +243,7 @@ uint16 DragonsEngine::ipt_img_file_related() {
 	int16 tileX = flicker->actor->_x_pos / 32;
 	int16 tileY = flicker->actor->_y_pos / 8;
 
-	for (int i = 0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
 		if ((ini->sceneId == getCurrentSceneId()) && (ini->field_1a_flags_maybe == 0)) {
 			Img *img = _dragonImg->getImg(ini->field_2);
@@ -870,7 +870,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 //				if (((((actors[actorId]._flags & 0x2000) == 0) && ((actors[actorId]._flags & 4) != 0)) &&
 //					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
 //				(actors[actorId]._sequenceID2 != -1)) {
-//					actor_update_sequenceID(actorId,actors[actorId]._sequenceID2);
+//					actor_update_sequenceID(actorId, actors[actorId]._sequenceID2);
 //				}
 			}
 
@@ -1157,7 +1157,7 @@ void DragonsEngine::walkFlickerToObject() {
 					flickerINI->actor->setFlag(ACTOR_FLAG_800);
 				}
 				flickerINI->actor->startWalk((int)(((uint)targetX + (uint)targetINI->field_1c) * 0x10000) >> 0x10,
-													(int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10,0);
+													(int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10, 0);
 				_bit_flags_8006fbd8 = 1;
 				return;
 			}
@@ -1182,7 +1182,7 @@ void DragonsEngine::walkFlickerToObject() {
 			flickerINI->actor->_walkSpeed = 0x10000;
 			flickerINI->actor->startWalk(
 					(int)((uVar7 + (uint)_scene->_camera.x) * 0x10000) >> 0x10,
-					(int)((uVar8 + (uint)_scene->_camera.y) * 0x10000) >> 0x10,0);
+					(int)((uVar8 + (uint)_scene->_camera.y) * 0x10000) >> 0x10, 0);
 		}
 	} else {
 		if (_cursor->_data_80072890 != 0) {
@@ -1358,7 +1358,7 @@ void DragonsEngine::setupPalette1() {
 	memcpy(palette, _cursor->getPalette(), 0x100);
 	memcpy(palette + 0x100, _cursor->getPalette(), 0x100);
 	_screen->loadPalette(1, palette);
-	_screen->updatePaletteTransparency(1,0x40,0x7f,true);
+	_screen->updatePaletteTransparency(1, 0x40, 0x7f, true);
 }
 
 bool DragonsEngine::isDebugMode() {
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 53bff1191f..93306fb041 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -34,10 +34,10 @@ namespace Dragons {
 
 
 static const Common::Point positionTable[4] = {
-	Common::Point(2,0),
-	Common::Point(0xce,0),
-	Common::Point(2,0x9e),
-	Common::Point(0xce,0x9e)
+	Common::Point(2, 0),
+	Common::Point(0xce, 0),
+	Common::Point(2, 0x9e),
+	Common::Point(0xce, 0x9e)
 };
 
 static const int16 bagBounceTable[4] = {
@@ -72,7 +72,7 @@ Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
 	_inventionBookPrevSceneUpdateFunc = NULL;
 	_inventionBookPrevSceneId = 0;
 	_inventionBookPrevFlickerINISceneId = 0;
-	_inventionBookPrevFlickerINIPosition = Common::Point(0,0);
+	_inventionBookPrevFlickerINIPosition = Common::Point(0, 0);
 }
 
 void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backgroundResourceLoader, Bag *bag, DragonINIResource *dragonIniResource) {
@@ -219,7 +219,7 @@ void Inventory::animateBagOut() {
 	_vm->playOrStopSound(0x8000);
 	Common::Point pos = _bag->getPosition();
 	if (pos.y != 0xc8) {
-		for (;pos.y != 0xc8; pos.y += 0x19) {
+		for (; pos.y != 0xc8; pos.y += 0x19) {
 			_bag->updatePosition(pos);
 			_vm->waitForFrames(1);
 		}
@@ -271,7 +271,7 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
 void Inventory::loadInventoryItemsFromSave() {
 	memset(_inventoryItemTbl, 0, sizeof(_inventoryItemTbl));
 	int j = 0;
-	for (int i = 0; i < _vm->_dragonINIResource->totalRecords() && j < DRAGONS_MAX_INVENTORY_ITEMS; i++ ) {
+	for (int i = 0; i < _vm->_dragonINIResource->totalRecords() && j < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId == 1) {
 			_inventoryItemTbl[j++] = i + 1;
@@ -327,7 +327,7 @@ void Inventory::closeInventionBook() {
 	}
 	uVar1 = (uint)_vm->_scene->getSceneId();
 LAB_80038be8:
-	_vm->_scene->loadScene(uVar1,0x1e);
+	_vm->_scene->loadScene(uVar1, 0x1e);
 	_vm->setSceneUpdateFunction(_inventionBookPrevSceneUpdateFunc);
 	return;
 }
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 6c7db600ae..56cb72f922 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -160,7 +160,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	_vm->_dragonINIResource->setFlickerRecord(NULL);
 	_vm->setFlags(ENGINE_FLAG_800);
 	_vm->_scene->setSceneId(5);
-	_vm->_scene->loadSceneData(5 | 0x8000,0);
+	_vm->_scene->loadSceneData(5 | 0x8000, 0);
 	//DisableVSyncEvent();
 	_vm->clearFlags(ENGINE_FLAG_8);
 	_vm->clearFlags(ENGINE_FLAG_10);
@@ -170,12 +170,12 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	memcpy(paletteData, _vm->_scene->getPalette() + 0x180, 0x80);
 	memcpy(paletteData + 0x80, _vm->_scene->getPalette() + 0x180, 0x80);
 	_vm->_screen->loadPalette(1, paletteData);
-	_vm->_screen->updatePaletteTransparency(1,0x40,0x7f,true);
+	_vm->_screen->updatePaletteTransparency(1, 0x40, 0x7f, true);
 
-	uVar5 = _vm->_actorManager->loadActor(0x11,0,0,0,6);
+	uVar5 = _vm->_actorManager->loadActor(0x11, 0, 0, 0, 6);
 	loungealotHeadActor = _vm->_actorManager->loadActor(0xd, 0, 0x7d, 199, 4);
 	loungealotLeftUpperArm = _vm->_actorManager->loadActor(0xb, 2, 0x7d, 199, 4);
-	uVar8 = _vm->_actorManager->loadActor(0xf,0,0x7d,199,4);
+	uVar8 = _vm->_actorManager->loadActor(0xf, 0, 0x7d, 199, 4);
 	loungealotRightArm = _vm->_actorManager->loadActor(0x10, 0, 0x7d, 199, 4);
 	flickerArm = _vm->_actorManager->loadActor(9, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc],
 											   loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e,
@@ -189,8 +189,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0],
 										   flickerArm->_x_pos - flickerArm->_frame->field_e,
 										   flickerArm->_y_pos - flickerArm->_frame->field_10, 4);
-	uVar14 = _vm->_actorManager->loadActor(0x27,0,0x10,0xac,4);
-	uVar15 = _vm->_actorManager->loadActor(0x27,1,0x10,0x8c,4);
+	uVar14 = _vm->_actorManager->loadActor(0x27, 0, 0x10, 0xac, 4);
+	uVar15 = _vm->_actorManager->loadActor(0x27, 1, 0x10, 0x8c, 4);
 	uVar5->setFlag(ACTOR_FLAG_100);
 	loungealotHeadActor->setFlag(ACTOR_FLAG_100);
 	loungealotLeftUpperArm->setFlag(ACTOR_FLAG_100);
@@ -215,8 +215,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uVar14->_priorityLayer = 0;
 	uVar15->_priorityLayer = 0;
 	//TODO
-//	uVar16 = AddFlatShadedQuad(0x28,0xa8,0x67,0xa8,0x67,0xaf,0x28,0xaf,0x1f,7,0);
-//	uVar17 = AddFlatShadedQuad(0x28,0x88,0x67,0x88,0x67,0x8f,0x28,0x8f,0x3e0,7,0);
+//	uVar16 = AddFlatShadedQuad(0x28, 0xa8, 0x67, 0xa8, 0x67, 0xaf, 0x28, 0xaf, 0x1f, 7, 0);
+//	uVar17 = AddFlatShadedQuad(0x28, 0x88, 0x67, 0x88, 0x67, 0x8f, 0x28, 0x8f, 0x3e0, 7, 0);
 //	(&DAT_80083178)[(uint)uVar16 * 0xb] = (&DAT_80083178)[(uint)uVar16 * 0xb] & 0xfffe;
 //	(&DAT_80083178)[(uint)uVar17 * 0xb] = (&DAT_80083178)[(uint)uVar17 * 0xb] & 0xfffe;
 //	EnableVSyncEvent();
@@ -291,7 +291,7 @@ LAB_80090188:
 				_vm->reset_screen_maybe();
 				_vm->_scene->setSceneId(0x17);
 				flicker->sceneId = 0x17;
-				_vm->_scene->loadSceneData((uint)(0x17 | 0x8000),0);
+				_vm->_scene->loadSceneData((uint)(0x17 | 0x8000), 0);
 				_vm->setAllFlags((origEngineFlags & 0xfefdffff) | (_vm->getAllFlags() & 0x1000000) | 0x40);
 //				call_fade_related_1f();
 			}
@@ -301,7 +301,7 @@ LAB_80090188:
 
 		if ((_dat_80093c9c != 0) && !_vm->isFlagSet(ENGINE_FLAG_8000)) {
 			loungealotHeadActor->updateSequence(0);
-			//TODO _vm->_talk->FUN_8001a7c4((uint)_dat_8008e7e8,(uint)_dat_8008e844,(uint)_dat_8008e848,(uint)_dat_8008e874);
+			//TODO _vm->_talk->FUN_8001a7c4((uint)_dat_8008e7e8, (uint)_dat_8008e844, (uint)_dat_8008e848, (uint)_dat_8008e874);
 			_dat_80093c9c = 0;
 		}
 		if (_dat_80093c94 != 0) {
@@ -361,16 +361,16 @@ LAB_80090188:
 			 */
 			LAB_800907c4:
 			if (!bVar4) {
-				//TODO FUN_8001a4e4_draw_dialogbox(4,0x14,0xd,0x16,1);
-				//TODO FUN_8001a4e4_draw_dialogbox(4,0x10,0xd,0x12,1);
+				//TODO FUN_8001a4e4_draw_dialogbox(4, 0x14, 0xd, 0x16, 1);
+				//TODO FUN_8001a4e4_draw_dialogbox(4, 0x10, 0xd, 0x12, 1);
 				uVar14->_priorityLayer = 6;
 				uVar15->_priorityLayer = 6;
 				bVar4 = true;
 			}
 		}
 		if ((((local_278 == 0) && (local_27a == 0)) && (local_258 == 0)) && (bVar4)) {
-			// TODO FUN_8001a7c4(4,0x14,0xd,0x16);
-			// TODO FUN_8001a7c4(4,0x10,0xd,0x12);
+			// TODO FUN_8001a7c4(4, 0x14, 0xd, 0x16);
+			// TODO FUN_8001a7c4(4, 0x10, 0xd, 0x12);
 			uVar14->_priorityLayer = 0;
 			uVar15->_priorityLayer = 0;
 			bVar4 = false;
@@ -409,7 +409,7 @@ LAB_80090188:
 						loungealotHeadActor->updateSequence((uint)local_2b0[(uint)local_262 * 2]);
 						uVar18 = (uint)local_262;
 						local_262 = local_262 + 1;
-						fun_80093aec_dialog(textIdTbl[uVar18],0x14,1);
+						fun_80093aec_dialog(textIdTbl[uVar18], 0x14, 1);
 						if (local_262 == 3) {
 							while (((_dat_80093cb4 != 2 || (_dat_80093cbc != 0)) ||
 									((_dat_80093cb8 != 2 || (_dat_80093cc0 != 0))))) {
@@ -448,7 +448,7 @@ LAB_80090188:
 							}
 							_vm->waitForFrames(2 * 0x3c);
 //							DisableVSyncEvent();
-							memset(paletteData,0,0x200);
+							memset(paletteData, 0, 0x200);
 							uVar5->_flags = uVar5->_flags & 0xfbff;
 							loungealotHeadActor->setFlag(ACTOR_FLAG_400);
 							loungealotLeftUpperArm->setFlag(ACTOR_FLAG_400);
@@ -463,9 +463,9 @@ LAB_80090188:
 							uVar5->updateSequence(1);
 							uVar5->waitUntilFlag4IsSet();
 							_vm->waitForFrames(1);
-							_vm->_screen->loadPalette(0,paletteData);
-							_vm->_screen->loadPalette(1,paletteData);
-//	TODO						FUN_8001a7c4((uint)_dat_8008e7e8,(uint)_dat_8008e844,(uint)_dat_8008e848,
+							_vm->_screen->loadPalette(0, paletteData);
+							_vm->_screen->loadPalette(1, paletteData);
+//	TODO						FUN_8001a7c4((uint)_dat_8008e7e8, (uint)_dat_8008e844, (uint)_dat_8008e848,
 //										 (uint)_dat_8008e874);
 							shouldExit = true;
 							goto LAB_80090188;
@@ -639,7 +639,7 @@ LAB_80090188:
 					if (local_258 == 1) {
 //						playSoundFromTxtIndex(DAT_80063ad0);
 						loungealotHeadActor->updateSequence(9);
-						fun_80093aec_dialog(0x46BC,0x14,1);
+						fun_80093aec_dialog(0x46BC, 0x14, 1);
 						do {
 							_vm->waitForFrames(1);
 						} while (_vm->isFlagSet(ENGINE_FLAG_8000));
@@ -648,7 +648,7 @@ LAB_80090188:
 					} else {
 //						playSoundFromTxtIndex(DAT_80063ad4);
 						loungealotHeadActor->updateSequence(10);
-						fun_80093aec_dialog(0x4718,0x14,1);
+						fun_80093aec_dialog(0x4718, 0x14, 1);
 						loungealotRightArm->updateSequence(2);
 						do {
 							_vm->waitForFrames(1);
@@ -708,11 +708,11 @@ LAB_80090188:
 				if (local_258 == 1) {
 //					playSoundFromTxtIndex(DAT_80063ad8);
 					loungealotHeadActor->updateSequence(0xb);
-					fun_80093aec_dialog(0x475E,0x14,1);
+					fun_80093aec_dialog(0x475E, 0x14, 1);
 				} else {
 //					playSoundFromTxtIndex(DAT_80063adc);
 					loungealotHeadActor->updateSequence(0xc);
-					fun_80093aec_dialog(0x4774,0x14,1);
+					fun_80093aec_dialog(0x4774, 0x14, 1);
 				}
 				local_258 = 0;
 				_dat_80093cb4 = 2;
@@ -741,8 +741,8 @@ void Minigame2::fun_80093aec_dialog(uint32 textId, int16 x, int16 y) {
 //TODO
 //	if ((((_dat_8008e7e8_dialogBox_x1 != 0) || (_dat_8008e848_dialogBox_x2 != 0)) ||
 //		 (_dat_8008e844_dialogBox_y1 != 0)) || (_dat_8008e874_dialogBox_y2 != 0)) {
-//		_vm->_talk->FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1,(uint)_dat_8008e844_dialogBox_y1,
-//					 (uint)_dat_8008e848_dialogBox_x2,(uint)_dat_8008e874_dialogBox_y2);
+//		_vm->_talk->FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1, (uint)_dat_8008e844_dialogBox_y1,
+//					 (uint)_dat_8008e848_dialogBox_x2, (uint)_dat_8008e874_dialogBox_y2);
 //	}
 	_vm->_talk->loadText(textId, auStack4024, 2000);
 	_vm->_talk->displayDialogAroundPoint(auStack4024, x, y, 0, 0, textId);
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index 9f0acacf67..fd4bf27308 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -194,13 +194,13 @@ void Minigame3::run() {
 	_vm->setFlags(ENGINE_FLAG_100);
 	_vm->setFlags(ENGINE_FLAG_1000_TEXT_ENABLED);
 // TODO
-//	memcpy2(auStack1584_palette,scrFileData_maybe,0x200);
-//	memcpy2(auStack1072_palette,scrFileData_maybe,0x200);
+//	memcpy2(auStack1584_palette, scrFileData_maybe, 0x200);
+//	memcpy2(auStack1072_palette, scrFileData_maybe, 0x200);
 	local_5b2 = 0x7fff;
 //	DisableVSyncEvent();
 	int i = 0;
 	while ((int16)i < 4) {
-		bunnyActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x15,4,0,0);
+		bunnyActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x15, 4, 0, 0);
 		if (bunnyActorTbl[(int16)i] == NULL) {
 			error("Couldn't_alloc_bunny");
 		}
@@ -216,7 +216,7 @@ void Minigame3::run() {
 	}
 	i = 0;
 	while ((int16)i < 8) {
-		tearActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x15,0x13,0,0);
+		tearActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x15, 0x13, 0, 0);
 		if (tearActorTbl[(int16)i] == NULL) {
 			error("Couldn't alloc tear");
 		}
@@ -229,7 +229,7 @@ void Minigame3::run() {
 	}
 	local_1e0 = 0;
 	local_1e8 = 0;
-	handActorId = _vm->_actorManager->loadActor(0x19,0,0,0);
+	handActorId = _vm->_actorManager->loadActor(0x19, 0, 0, 0);
 	if (handActorId == NULL) {
 		error("Couldn't alloc hand");
 	}
@@ -244,7 +244,7 @@ void Minigame3::run() {
 	handActorId->_walkSpeed = 0x40000;
 	i = 0;
 	while ((int16)i < 2) {
-		tearBlinkActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x34,(uint)i,0,0);
+		tearBlinkActorTbl[(int16)i] = _vm->_actorManager->loadActor(0x34, (uint)i, 0, 0);
 		if (tearBlinkActorTbl[(int16)i] == NULL) {
 			error("Couldn't alloc tear blink");
 		}
@@ -255,7 +255,7 @@ void Minigame3::run() {
 	}
 	i = 0;
 	while ((int16)i < 2) {
-		tearBlinkActorTbl2[(int16)i] = _vm->_actorManager->loadActor(0x16,(uint)i,0,0);
+		tearBlinkActorTbl2[(int16)i] = _vm->_actorManager->loadActor(0x16, (uint)i, 0, 0);
 		if (tearBlinkActorTbl2[(int16)i] == NULL) {
 			error("Couldn't alloc tear blink");
 		}
@@ -294,9 +294,9 @@ void Minigame3::run() {
 	updateBackgroundLayerOffset(0, 0, 0);
 //	call_fade_related_1f();
 	_vm->waitForFrames(0xf);
-	_vm->_talk->loadAndDisplayDialogAroundPoint(0x479A,0x14,3,0x1e01,0);
+	_vm->_talk->loadAndDisplayDialogAroundPoint(0x479A, 0x14, 3, 0x1e01, 0);
 	_vm->waitForFrames(0x1e);
-	// TODO FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+	// TODO FUN_8001a7c4((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
 	i = 0;
 	while ((int16)i < 4) {
 		if (goodRabbitPositionTbl[(int16)i] == 0) {
@@ -325,7 +325,7 @@ void Minigame3::run() {
 	}
 	_vm->waitForFrames(0x1e);
 	_vm->waitForFrames(0x1e);
-	// TODO FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+	// TODO FUN_8001a7c4((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
 	local_56 = 0;
 	local_1c0 = 0;
 	currentState = 2;
@@ -349,7 +349,7 @@ void Minigame3::run() {
 	tearBlinkActorTbl[0]->updateSequence(0);
 	tearBlinkActorTbl[1]->updateSequence(1);
 	local_1c2 = 0;
-	while ( true ) {
+	while (true) {
 		_vm->waitForFrames(1);
 		switch (currentState) {
 		case 1:
@@ -583,7 +583,7 @@ void Minigame3::run() {
 			}
 		}
 		if ((local_e != 0) && (local_10 == 0)) {
-			//TODO implement this. FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+			//TODO implement this. FUN_8001a7c4((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
 			local_e = 0;
 		}
 		if ((local_e != 0) && (local_10 != 0)) {
@@ -688,7 +688,7 @@ void Minigame3::run() {
 	handActorId->_y_pos = handPositionsTbl[local_224].y;
 	handActorId->_priorityLayer = 2;
 	bVar1 = false;
-	_vm->_talk->loadAndDisplayDialogAroundPoint(0x2958A,0x14,3,0x1e01,0);
+	_vm->_talk->loadAndDisplayDialogAroundPoint(0x2958A, 0x14, 3, 0x1e01, 0);
 	while (_vm->isFlagSet(ENGINE_FLAG_8000)) {
 		_vm->waitForFrames(1);
 	}
@@ -739,12 +739,12 @@ void Minigame3::run() {
 	flicker->sceneId = 1;
 	_vm->setAllFlags(oldEngineFlags);
 	_vm->setFlags(ENGINE_FLAG_40);
-//	_vm->_screen->loadPalette(1,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
+//	_vm->_screen->loadPalette(1, (uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
 //			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
 	_vm->setupPalette1();
-//	_vm->_screen->loadPalette(4,(uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
+//	_vm->_screen->loadPalette(4, (uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
 //			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
-	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
+	_vm->_screen->updatePaletteTransparency(4, 1, 0xff, true);
 	_vm->_inventory->setType(origInventoryType);
 	_vm->_scene->setSceneId(origSceneId);
 	_vm->_scene->loadScene(origSceneId, 0);
@@ -762,8 +762,8 @@ void Minigame3::fun_80017f70_paletteRelated(uint16 param_1) {
 //	DisableVSyncEvent();
 	_vm->_screen->loadPalette(0, _vm->_scene->getPalette());
 	_vm->_screen->setPaletteRecord(0, 0x3f, param_1 * 0x421);
-//	load_palette_into_frame_buffer(0,abStack528);
-	_vm->_screen->updatePaletteTransparency(0, 0x3f,0x3f, param_1 == 0x1e ? false : true);
+//	load_palette_into_frame_buffer(0, abStack528);
+	_vm->_screen->updatePaletteTransparency(0, 0x3f, 0x3f, param_1 == 0x1e ? false : true);
 //	if (uVar1 != 0) {
 //		EnableVSyncEvent();
 //	}
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index f89ff5254f..26f66e87ad 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -51,7 +51,7 @@ void Minigame4::run() {
 	_vm->_dragonINIResource->setFlickerRecord(NULL);
 	_vm->_inventory->setType(0);
 	_vm->_scene->setSceneId(7);
-	_vm->_scene->loadSceneData(0x8007,0);
+	_vm->_scene->loadSceneData(0x8007, 0);
 	_vm->clearFlags(ENGINE_FLAG_8);
 	_vm->clearFlags(ENGINE_FLAG_10);
 	_vm->clearFlags(ENGINE_FLAG_20);
@@ -61,15 +61,15 @@ void Minigame4::run() {
 	_layer2XOffset = 0;
 	_vm->setVsyncUpdateFunction(videoUpdaterFunction);
 	_vm->_screen->loadPalette(4, _vm->_scene->getPalette());
-	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
+	_vm->_screen->updatePaletteTransparency(4, 1, 0xff, true);
 	_vm->_videoFlags |= 4;
 	_vm->_scene->setBgLayerPriority(2);
 	_vm->_scene->setMgLayerPriority(1);
-	_flickerActor = _vm->_actorManager->loadActor(0x18,0,0xcb,0x79,1);
-	_bruteActor = _vm->_actorManager->loadActor(0x17,0,0x68,0x7b,1);
-	_ps1ControllerActor = _vm->_actorManager->loadActor(0x17,0x16,0x9f,0x19,1);
-	_dat_80090438 = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
-	_dat_8009043c = _vm->_actorManager->loadActor(0x17,0xb,400,400,1);
+	_flickerActor = _vm->_actorManager->loadActor(0x18, 0, 0xcb, 0x79, 1);
+	_bruteActor = _vm->_actorManager->loadActor(0x17, 0, 0x68, 0x7b, 1);
+	_ps1ControllerActor = _vm->_actorManager->loadActor(0x17, 0x16, 0x9f, 0x19, 1);
+	_dat_80090438 = _vm->_actorManager->loadActor(0x17, 0xb, 400, 400, 1);
+	_dat_8009043c = _vm->_actorManager->loadActor(0x17, 0xb, 400, 400, 1);
 	//EnableVSyncEvent();
 	_flickerActor->setFlag(ACTOR_FLAG_80);
 	_flickerActor->setFlag(ACTOR_FLAG_100);
@@ -83,10 +83,10 @@ void Minigame4::run() {
 	//UnkSoundFunc5(0xf);
 	//call_fade_related_1f();
 	if (_vm->_dragonINIResource->getRecord(0x1f5)->field_12 == 3) {
-		actorTalk(_bruteActor,0x3321,0x4A84);
+		actorTalk(_bruteActor, 0x3321, 0x4A84);
 	} else {
-		actorTalk(_bruteActor,0x3321,0x49A2);
-		actorTalk(_flickerActor,0,0x4A56);
+		actorTalk(_bruteActor, 0x3321, 0x49A2);
+		actorTalk(_flickerActor, 0, 0x4A56);
 	}
 	result = runDanceBattle();
 	/* field_0x12 */
@@ -104,14 +104,14 @@ void Minigame4::run() {
 	// EnableVSyncEvent();
 	_vm->_dragonINIResource->setFlickerRecord(flicker);
 	_vm->_inventory->setType(uVar3);
-//	_vm->_screen->loadPalette(4,(uint)*(uint16 *)
+//	_vm->_screen->loadPalette(4, (uint)*(uint16 *)
 //					(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10)
 //			   + *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
-	_vm->_screen->updatePaletteTransparency(4,1,0xff,true);
+	_vm->_screen->updatePaletteTransparency(4, 1, 0xff, true);
 	_vm->_scene->setSceneId(uVar1);
 	_vm->setAllFlags(uVar4);
 	flicker->sceneId = uVar1;
-	_vm->_scene->loadScene(uVar1,0x1e);
+	_vm->_scene->loadScene(uVar1, 0x1e);
 }
 
 void Minigame4::actorTalk(Actor *actorId, uint16 param_2, uint32 textIndex) {
@@ -176,38 +176,38 @@ uint16 Minigame4::runDanceBattle() {
 	currentStep = 0;
 	while (currentStep < 0xc) {
 		if (singleDanceRound(round1StepPositionTbl[(uint)currentStep], round1DurationTbl[(uint)currentStep])) {
-			actorTalk(_bruteActor,0x3321, 0x4D50);
+			actorTalk(_bruteActor, 0x3321, 0x4D50);
 			return 1;
 		}
 		currentStep = currentStep + 1;
 	}
 	resetActors();
-	actorTalk(_bruteActor,0x3321, 0x4ADE);
+	actorTalk(_bruteActor, 0x3321, 0x4ADE);
 	currentStep = 0;
 	while (currentStep < 0xc) {
 		if (singleDanceRound(round2StepPositionTbl[(uint)currentStep], round2DurationTbl[(uint)currentStep])) {
-			actorTalk(_bruteActor,0x3321,0x4DD4);
+			actorTalk(_bruteActor, 0x3321, 0x4DD4);
 			return 1;
 		}
 		currentStep = currentStep + 1;
 	}
 	resetActors();
-	actorTalk(_bruteActor,0x3321, 0x4B6A);
+	actorTalk(_bruteActor, 0x3321, 0x4B6A);
 	currentStep = 0;
-	while ( true ) {
+	while (true) {
 		if (0x11 < currentStep) {
 			_vm->_talk->loadText(0x4C0C, auStack2192, 1000);
-			_vm->_talk->displayDialogAroundPoint(auStack2192, 0x27,0xc,0x3321,0,0x4C0C);
+			_vm->_talk->displayDialogAroundPoint(auStack2192, 0x27, 0xc, 0x3321, 0, 0x4C0C);
 			_vm->waitForFrames(0x10a);
 			_bruteActor->updateSequence(8);
 			//TODO
 //			if ((((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0)) || (DAT_8008e844 != 0)) ||
 //				(DAT_8008e874 != 0)) {
-//				FUN_8001a7c4((uint)DAT_8008e7e8,(uint)DAT_8008e844,(uint)DAT_8008e848,(uint)DAT_8008e874);
+//				FUN_8001a7c4((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
 //			}
 			_flickerActor->waitUntilFlag8SetThenSet1000AndWaitFor4();
 			_flickerActor->updateSequence(7);
-			actorTalk(_flickerActor,0, 0x4CC8);
+			actorTalk(_flickerActor, 0, 0x4CC8);
 			return 0;
 		}
 
@@ -216,7 +216,7 @@ uint16 Minigame4::runDanceBattle() {
 		}
 		currentStep = currentStep + 1;
 	}
-	actorTalk(_bruteActor,0x3321, 0x4DEE);
+	actorTalk(_bruteActor, 0x3321, 0x4DEE);
 	return 1;
 }
 
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index 2b285af732..b3db5e13c2 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -119,7 +119,7 @@ void Minigame5::run() {
 	local_74 = 0;
 //	DisableVSyncEvent();
 	pusherActor = _vm->_actorManager->loadActor
-			(0x26,0,(int)(short)local_850,(int)(((uint)uVar1 + 5) * 0x10000) >> 0x10);
+			(0x26, 0, (int)(short)local_850, (int)(((uint)uVar1 + 5) * 0x10000) >> 0x10);
 //	EnableVSyncEvent();
 	if (pusherActor == NULL) {
 		error("Couldn't alloc pusher!");
@@ -130,7 +130,7 @@ void Minigame5::run() {
 	pusherActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	pusherActor->_priorityLayer = 6;
 //	DisableVSyncEvent();
-	wheelsActor = _vm->_actorManager->loadActor(7,0x11,0,0);
+	wheelsActor = _vm->_actorManager->loadActor(7, 0x11, 0, 0);
 //	EnableVSyncEvent();
 	if (wheelsActor == NULL) {
 		error("Couldn't alloc wheels!");
@@ -143,7 +143,7 @@ void Minigame5::run() {
 	wheelsActor->updateSequence(0x11);
 	local_62 = 0;
 //	DisableVSyncEvent();
-	bombActor = _vm->_actorManager->loadActor(7,0x1c,0,0);
+	bombActor = _vm->_actorManager->loadActor(7, 0x1c, 0, 0);
 //	EnableVSyncEvent();
 	if (bombActor == NULL) {
 		error("Couldn't alloc bomb!");
@@ -152,7 +152,7 @@ void Minigame5::run() {
 	bombActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	bombActor->_priorityLayer = 0;
 //	DisableVSyncEvent();
-	dustActor = _vm->_actorManager->loadActor(8,8,100,100,0);
+	dustActor = _vm->_actorManager->loadActor(8, 8, 100, 100, 0);
 //	EnableVSyncEvent();
 	if (dustActor == NULL) {
 		error("Couldn't alloc dust sprite!");
@@ -175,7 +175,7 @@ void Minigame5::run() {
 					if (local_66 != 8) {
 						local_66 = 0;
 					}
-					//iVar2 = IsButtonBeingPressed((uint)DAT_800728ac,0);
+					//iVar2 = IsButtonBeingPressed((uint)DAT_800728ac, 0);
 					if (!_vm->isActionButtonPressed()) {
 						if (local_74 == 0) {
 							if ((((flickerActor->_sequenceID != 0) &&
@@ -348,12 +348,12 @@ void Minigame5::run() {
 					_vm->waitForFrames(0x3c);
 					pusherActor->updateSequence(0xb);
 					if (_dat_800633e6 == 0) {
-						_vm->_talk->loadText(DAT_8006393c,auStack2120, 1000);
-						_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1,DAT_8006393c);
+						_vm->_talk->loadText(DAT_8006393c, auStack2120, 1000);
+						_vm->_talk->displayDialogAroundPoint(auStack2120, (int)(short)(local_850 >> 3), 0xc, 0, 1, DAT_8006393c);
 						_dat_800633e6 = 1;
 					} else {
 						_vm->_talk->loadText(DAT_80063938, auStack2120, 1000);
-						_vm->_talk->displayDialogAroundPoint(auStack2120,(int)(short)(local_850 >> 3),0xc,0,1, DAT_80063938);
+						_vm->_talk->displayDialogAroundPoint(auStack2120, (int)(short)(local_850 >> 3), 0xc, 0, 1, DAT_80063938);
 					}
 					_vm->waitForFrames(10);
 					local_10 = 1;
@@ -373,13 +373,13 @@ void Minigame5::run() {
 					_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(2);
 					_vm->waitForFrames(0x12);
 					_vm->_talk->loadText(DAT_80063e38, auStack2120, 1000);
-					_vm->_talk->displayDialogAroundPoint(auStack2120,0xf,2,0x501,0,DAT_80063e38);
+					_vm->_talk->displayDialogAroundPoint(auStack2120, 0xf, 2, 0x501, 0, DAT_80063e38);
 //						TODO	callMaybeResetData();
 					_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->updateSequence(3);
 					_vm->_dragonINIResource->getRecord(DAT_80063bd0 + -1)->actor->waitUntilFlag8And4AreSet();
 					pusherActor->updateSequence(7);
 					_vm->_talk->loadText(DAT_8006391c, auStack2120, 1000);
-					_vm->_talk->displayDialogAroundPoint(auStack2120, (int)(short)(local_850 >> 3),0xc,0,1,DAT_8006391c);
+					_vm->_talk->displayDialogAroundPoint(auStack2120, (int)(short)(local_850 >> 3), 0xc, 0, 1, DAT_8006391c);
 					pusherActor->_flags = pusherActor->_flags | 0x1000;
 					local_10 = 2;
 					local_48 = 1;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 54dc7a32b3..f059c41e1e 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -87,18 +87,16 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	_vm->setUnkFlags(ENGINE_UNK1_FLAG_2 | Dragons::ENGINE_UNK1_FLAG_8);
 
-	for (int i = 0;i < _dragonINIResource->totalRecords(); i++) {
+	for (int i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		ini->field_10 = -1;
 		ini->field_1a_flags_maybe &= ~INI_FLAG_10;
 	}
 
 	uint16 sceneIdStripped = (uint16)sceneId & ~0x8000;
-	if ((((((sceneIdStripped == 0x18) || (sceneIdStripped == 0x26)) ||
-		   (sceneIdStripped == 0x7)) ||
-		  ((sceneIdStripped == 0x17 || (sceneIdStripped == 0x5)))) ||
-		 ((sceneIdStripped == 0x19 || ((sceneIdStripped == 0x34 || (sceneIdStripped == 0x1d)))
-		 ))) || (sceneIdStripped == 0x6)) {
+	if (sceneIdStripped == 0x18 || sceneIdStripped == 0x26 || sceneIdStripped == 0x7 ||
+			sceneIdStripped == 0x17 || sceneIdStripped == 0x5 || sceneIdStripped == 0x19 ||
+			sceneIdStripped == 0x34 || sceneIdStripped == 0x1d || sceneIdStripped == 0x6) {
 //		buf2048bytes = buf2048bytes + 0x1800;
 		// error("0x8002f404"); //TODO do we need this logic?
 	}
@@ -367,7 +365,7 @@ void Scene::draw() {
 					!(actor->_flags & ACTOR_FLAG_400) &&
 					actor->_surface &&
 					actor->_frame->width != 0 &&
-					actor->_frame->height != 0 ) {
+					actor->_frame->height != 0) {
 				Graphics::Surface *s = actor->_surface;
 				if (actor->_priorityLayer == priority) { //} && x + s->w < 320 && y + s->h < 200) {
 					if (!actor->isFlagSet(ACTOR_FLAG_80)) {
diff --git a/engines/dragons/screen.cpp b/engines/dragons/screen.cpp
index 596928d247..d470ff103f 100644
--- a/engines/dragons/screen.cpp
+++ b/engines/dragons/screen.cpp
@@ -41,16 +41,16 @@ void Screen::updateScreen() {
 	if (_screenShakeOffset.x != 0 || _screenShakeOffset.y != 0) {
 		g_system->fillScreen(0); //TODO this is meant for 8bit screens. we should use system shake here.
 	}
-	Common::Rect clipRect = clipRectToScreen( _screenShakeOffset.x,  _screenShakeOffset.y, Common::Rect(_backSurface->w, _backSurface->h));
+	Common::Rect clipRect = clipRectToScreen(_screenShakeOffset.x,  _screenShakeOffset.y, Common::Rect(_backSurface->w, _backSurface->h));
 	g_system->copyRectToScreen((byte*)_backSurface->getBasePtr(clipRect.left, clipRect.top),
 			_backSurface->pitch,
 			_screenShakeOffset.x < 0 ? 0 : _screenShakeOffset.x, _screenShakeOffset.y < 0 ? 0 : _screenShakeOffset.y,
 			clipRect.width(), clipRect.height());
 //	if (_screenShakeOffset < 0) {
-//		_backSurface->fillRect(Common::Rect(0,_backSurface->h + _screenShakeOffset - 1, _backSurface->w - 1, _backSurface->h - 1), 0);
+//		_backSurface->fillRect(Common::Rect(0, _backSurface->h + _screenShakeOffset - 1, _backSurface->w - 1, _backSurface->h - 1), 0);
 //	}
 //	if (_screenShakeOffset > 0) {
-//		_backSurface->fillRect(Common::Rect(0,0, _backSurface->w - 1, _screenShakeOffset - 1), 0);
+//		_backSurface->fillRect(Common::Rect(0, 0, _backSurface->w - 1, _screenShakeOffset - 1), 0);
 //	}
 	g_system->updateScreen();
 }
@@ -65,7 +65,7 @@ void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, i
 }
 
 void Screen::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect srcRect, bool flipX, AlphaBlendMode alpha) {
-	Common::Rect clipRect = clipRectToScreen( destX,  destY, srcRect);
+	Common::Rect clipRect = clipRectToScreen(destX,  destY, srcRect);
 	if (clipRect.width() == 0 || clipRect.height() == 0) {
 		return;
 	}
@@ -89,7 +89,7 @@ void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *pa
 				palette, flipX, alpha);
 		return;
 	}
-	Common::Rect clipRect = clipRectToScreen( destX,  destY, srcRect);
+	Common::Rect clipRect = clipRectToScreen(destX,  destY, srcRect);
 	if (clipRect.width() == 0 || clipRect.height() == 0) {
 		return;
 	}
@@ -110,15 +110,15 @@ void Screen::copyRectToSurface8bpp(const Graphics::Surface &srcSurface, byte *pa
  * @param bg      The background color in uint16 RGB565 format
  * @param alpha   The alpha in range 0-255
  **/
-uint16 alphaBlendRGB555( uint32 fg, uint32 bg, uint8 alpha ){
-	alpha = ( alpha + 4 ) >> 3;
+uint16 alphaBlendRGB555(uint32 fg, uint32 bg, uint8 alpha){
+	alpha = (alpha + 4) >> 3;
 	bg = (bg | (bg << 16)) & 0x3e07c1f;
 	fg = (fg | (fg << 16)) & 0x3e07c1f;
 	uint32 result = ((((fg - bg) * alpha) >> 5) + bg) & 0x3e07c1f;
 	return (uint16)((result >> 16) | result);
 }
 
-uint16 alphaBlendAdditiveRGB555( uint32 fg, uint32 bg){
+uint16 alphaBlendAdditiveRGB555(uint32 fg, uint32 bg){
 	bg = (bg | (bg << 16)) & 0x3e07c1f;
 	fg = (fg | (fg << 16)) & 0x3e07c1f;
 
@@ -373,7 +373,7 @@ byte *Screen::getPalette(uint16 paletteNum) {
 }
 
 void Screen::clearScreen() {
-	_backSurface->fillRect(Common::Rect(0,0, _backSurface->w - 1, _backSurface->h - 1), 0);
+	_backSurface->fillRect(Common::Rect(0, 0, _backSurface->w - 1, _backSurface->h - 1), 0);
 }
 
 void Screen::drawRect(uint16 colour, Common::Rect rect, int id) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index e1c5f52b59..7c76ae3813 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -1069,13 +1069,13 @@ void ScriptOpcodes::opUnk18(ScriptOpCall &scriptOpCall) {
 	_vm->_talk->loadText(field2, dialog, 2000);
 
 //	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
-//		dialogText = (uint8 *)load_string_from_dragon_txt(offset,acStack2016);
+//		dialogText = (uint8 *)load_string_from_dragon_txt(offset, acStack2016);
 //	}
 
 	if (fieldA != 0) {
 		fieldA = READ_LE_INT16(_vm->_dragonOBD->getFromOpt(fieldA - 1) + 6);
 	}
-	_vm->_talk->displayDialogAroundPoint(dialog,x,y,fieldA,1,field2);
+	_vm->_talk->displayDialogAroundPoint(dialog, x, y, fieldA, 1, field2);
 }
 
 void ScriptOpcodes::opUnk19(ScriptOpCall &scriptOpCall) {
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 227e10a65b..18fb7a26bb 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -161,7 +161,7 @@ void SequenceOpcodes::opUpdateXYResetSeqTimer(Actor *actor, OpCall &opCall) {
 	actor->_y_pos += yOffset;
 	actor->_sequenceTimer = actor->_field_c;
 
-	debug(5, "update actor %d XY offset (%d,%d) new values (%d, %d) %d", actor->_actorID, xOffset, yOffset, actor->_x_pos, actor->_y_pos, actor->_sequenceTimer);
+	debug(5, "update actor %d XY offset (%d, %d) new values (%d, %d) %d", actor->_actorID, xOffset, yOffset, actor->_x_pos, actor->_y_pos, actor->_sequenceTimer);
 	updateReturn(opCall, 1);
 }
 
@@ -178,7 +178,7 @@ void SequenceOpcodes::opSetActorFlag4AndStop(Actor *actor, OpCall &opCall) {
 }
 
 void SequenceOpcodes::opSetActorFlags404(Actor *actor, OpCall &opCall) {
-	actor->_flags |= (ACTOR_FLAG_4 | Dragons::ACTOR_FLAG_400 );
+	actor->_flags |= (ACTOR_FLAG_4 | Dragons::ACTOR_FLAG_400);
 	updateReturn(opCall, 1);
 }
 
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index d95595cd5b..d2fae18509 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -90,7 +90,7 @@ void SoundManager::playSpeech(uint32 textIndex) {
 	CdIntToPos_0(speechLocation.sectorStart * 32);
 	fd->seek(((speechLocation.sectorStart * 32) + speechLocation.startOffset) * RAW_CD_SECTOR_SIZE);
 	PSXAudioTrack *_audioTrack = new PSXAudioTrack(fd, Audio::Mixer::kSpeechSoundType);
-	for (int i = 0x0; i < speechLocation.sectorEnd - speechLocation.sectorStart;i++) {
+	for (int i = 0x0; i < speechLocation.sectorEnd - speechLocation.sectorStart; i++) {
 		fd->seek(((speechLocation.sectorStart * 32) + speechLocation.startOffset + i * 32) * RAW_CD_SECTOR_SIZE);
 		_audioTrack->queueAudioFromSector(fd);
 	}
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index 3ee39f778a..dcd8eb51db 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -233,7 +233,7 @@ void SpecialOpcodes::spcCatapultMiniGame() {
 
 void SpecialOpcodes::spcThumbWrestlingMiniGame() {
 	Minigame2 minigame2(_vm);
-	minigame2.run(0,1,1);
+	minigame2.run(0, 1, 1);
 }
 
 void SpecialOpcodes::spcClearEngineFlag10() {
@@ -293,7 +293,7 @@ void SpecialOpcodes::spcCastleGardenLogic() {
 	sceneUpdater.iniIDTbl[2][0] = sceneUpdater.iniIDTbl[3][0];
 	sceneUpdater.iniIDTbl[2][1] = sceneUpdater.iniIDTbl[4][0];
 	sceneUpdater.iniIDTbl[3][1] = sceneUpdater.iniIDTbl[4][0];
-	setupTableBasedSceneUpdateFunction(1,4,0xb4);
+	setupTableBasedSceneUpdateFunction(1, 4, 0xb4);
 }
 
 void SpecialOpcodes::spcUnk9() {
@@ -332,14 +332,14 @@ void SpecialOpcodes::spcStopLadyOfTheLakeCapturedSceneLogic() {
 	_vm->setSceneUpdateFunction(NULL);
 	_vm->_sound->PauseCDMusic();
 	if ((_dat_80083148 != 0) || (_uint16_t_80083154 != 0)) {
-		//TODO FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
+		//TODO FUN_8001ac5c((uint)_dat_80083148, (uint)DAT_80083150, (uint)_uint16_t_80083154, (uint)DAT_80083158);
 	}
 	_dat_80083148 = 0;
 	_uint16_t_80083154 = 0;
 }
 
 void SpecialOpcodes::spc11ShakeScreen() {
-	for (int i = 0; i < 16; i++ ) {
+	for (int i = 0; i < 16; i++) {
 		_vm->_screen->setScreenShakeOffset(0, shakeTbl[i]);
 		_vm->waitForFrames(1);
 	}
@@ -447,7 +447,7 @@ void SpecialOpcodes::spcKnightPoolReflectionLogic() {
 	sceneUpdater.numSteps[3] = 4;
 	sceneUpdater.numSteps[4] = 4;
 	sceneUpdater.numSteps[5] = 3;
-	setupTableBasedSceneUpdateFunction(0x168,6,300);
+	setupTableBasedSceneUpdateFunction(0x168, 6, 300);
 }
 
 void SpecialOpcodes::spcWalkOnStilts() {
@@ -553,7 +553,7 @@ void SpecialOpcodes::spcStopMenInMinesSceneLogic() {
 			_vm->waitForFrames(1);
 		}
 		//TODO
-		//FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
+		//FUN_8001ac5c((uint)_dat_80083148, (uint)DAT_80083150, (uint)_uint16_t_80083154, (uint)DAT_80083158);
 	}
 }
 
@@ -580,7 +580,7 @@ void SpecialOpcodes::spcStopMonksAtBarSceneLogic() {
 void SpecialOpcodes::spcFlameBedroomEscapeSceneLogic() {
 	setSpecialOpCounter(-1);
 	if ((_dat_80083148 != 0) && (_uint16_t_80083154 != 0)) {
-		//TODO FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
+		//TODO FUN_8001ac5c((uint)_dat_80083148, (uint)DAT_80083150, (uint)_uint16_t_80083154, (uint)DAT_80083158);
 	}
 	_vm->setSceneUpdateFunction(flameEscapeSceneUpdateFunction);
 	_uint16_t_80083154 = 0;
@@ -589,7 +589,7 @@ void SpecialOpcodes::spcFlameBedroomEscapeSceneLogic() {
 
 void SpecialOpcodes::spcStopFlameBedroomEscapeSceneLogic() {
 	setSpecialOpCounter(0);
-//	TODO FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
+//	TODO FUN_8001ac5c((uint)_dat_80083148, (uint)DAT_80083150, (uint)_uint16_t_80083154, (uint)DAT_80083158);
 	_uint16_t_80083154 = 0;
 	_dat_80083148 = 0;
 	_vm->_dragonINIResource->getRecord(0x96)->actor->updateSequence(0);
@@ -614,7 +614,7 @@ void SpecialOpcodes::spcCastleMoatUpdateActorSceneScalePoints() {
 void SpecialOpcodes::spcCastleGateMoatDrainedSceneLogic() {
 	setSpecialOpCounter(-1);
 	if ((_dat_80083148 != 0) && (_uint16_t_80083154 != 0)) {
-		//TODO FUN_8001ac5c((uint)_dat_80083148,(uint)DAT_80083150,(uint)_uint16_t_80083154,(uint)DAT_80083158);
+		//TODO FUN_8001ac5c((uint)_dat_80083148, (uint)DAT_80083150, (uint)_uint16_t_80083154, (uint)DAT_80083158);
 	}
 	_vm->setSceneUpdateFunction(moatDrainedSceneUpdateFunction);
 	_uint16_t_80083154 = 0;
@@ -670,11 +670,11 @@ void SpecialOpcodes::spcTownAngryVillagersSceneLogic() {
 	sceneUpdater.numSteps[2] = 2;
 	sceneUpdater.numSteps[3] = 2;
 	sceneUpdater.numSteps[4] = 2;
-	setupTableBasedSceneUpdateFunction(0xf0,5,0x708);
+	setupTableBasedSceneUpdateFunction(0xf0, 5, 0x708);
 }
 
 void SpecialOpcodes::spcBlackDragonCrashThroughGate() {
-	for (int i = 0; i < 16; i++ ) {
+	for (int i = 0; i < 16; i++) {
 		_vm->_screen->setScreenShakeOffset(shakeTbl[i], shakeTbl[i]);
 		_vm->waitForFrames(1);
 	}
@@ -743,7 +743,7 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic() {
 	sceneUpdater.textTbl[7][0] = 0x2D4A8;
 	sceneUpdater.textTbl[7][1] = 0x2D504;
 
-	setupTableBasedSceneUpdateFunction(0x168,8,0xb4);
+	setupTableBasedSceneUpdateFunction(0x168, 8, 0xb4);
 }
 
 void SpecialOpcodes::spcZigmondFraudSceneLogic1() {
@@ -752,7 +752,7 @@ void SpecialOpcodes::spcZigmondFraudSceneLogic1() {
 	sceneUpdater.sequenceIDTbl[0][0] = 0x12;
 	sceneUpdater.textTbl[0][0] = 0x2F422; //TODO this might change between game versions
 
-	setupTableBasedSceneUpdateFunction(300,1,0x708);
+	setupTableBasedSceneUpdateFunction(300, 1, 0x708);
 }
 
 void SpecialOpcodes::spcBrokenBlackDragonSceneLogic() {
@@ -774,7 +774,7 @@ void SpecialOpcodes::spcBrokenBlackDragonSceneLogic() {
 	sceneUpdater.iniIDTbl[1][1] = 0x231;
 	sceneUpdater.iniIDTbl[2][0] = 0x23B;
 	sceneUpdater.iniIDTbl[2][1] = 0x231;
-	setupTableBasedSceneUpdateFunction(300,3,600);
+	setupTableBasedSceneUpdateFunction(300, 3, 600);
 }
 
 void SpecialOpcodes::spcDodoUnderAttackSceneLogic() {
@@ -802,7 +802,7 @@ void SpecialOpcodes::spcDodoUnderAttackSceneLogic() {
 	sceneUpdater.numSteps[3] = 1;
 	sceneUpdater.numSteps[4] = 1;
 	sceneUpdater.numSteps[5] = 1;
-	setupTableBasedSceneUpdateFunction(0x1e0,6,0x1e0);
+	setupTableBasedSceneUpdateFunction(0x1e0, 6, 0x1e0);
 }
 
 void SpecialOpcodes::spcForestWithoutDodoSceneLogic() {
@@ -823,7 +823,7 @@ void SpecialOpcodes::spcForestWithoutDodoSceneLogic() {
 	sceneUpdater.iniIDTbl[1][1] = 0x1C5;
 	sceneUpdater.textTbl[1][2] = 0x34074;
 	sceneUpdater.iniIDTbl[1][2] = 0x1C4;
-	setupTableBasedSceneUpdateFunction(300,2,600);
+	setupTableBasedSceneUpdateFunction(300, 2, 600);
 }
 
 void SpecialOpcodes::spcBlackDragonOnHillSceneLogic() {
@@ -852,7 +852,7 @@ void SpecialOpcodes::spcBlackDragonOnHillSceneLogic() {
 	sceneUpdater.numSteps[1] = 2;
 	sceneUpdater.numSteps[2] = 2;
 	sceneUpdater.numSteps[3] = 1;
-	setupTableBasedSceneUpdateFunction(300,4,300);
+	setupTableBasedSceneUpdateFunction(300, 4, 300);
 }
 
 void SpecialOpcodes::spcUnk4e() {
@@ -967,8 +967,8 @@ void SpecialOpcodes::spcInsideBlackDragonUpdatePalette() {
 }
 
 void SpecialOpcodes::spcCastleGateSceneLogic() {
-	_vm->_screen->updatePaletteTransparency(0, 0xc0,0xff, true);
-	//TODO FUN_80017d68(3,0); sets sprite layer attribute from layers 0 and 1. Doesn't seem to be needed.
+	_vm->_screen->updatePaletteTransparency(0, 0xc0, 0xff, true);
+	//TODO FUN_80017d68(3, 0); sets sprite layer attribute from layers 0 and 1. Doesn't seem to be needed.
 	setSpecialOpCounter(-1);
 	_vm->clearFlags(ENGINE_FLAG_1);
 	_vm->setSceneUpdateFunction(castleFogUpdateFunction);
@@ -1010,7 +1010,7 @@ void SpecialOpcodes::panCamera(int16 mode) {
 void SpecialOpcodes::spcBlackDragonDialogForCamelhot() {
 	uint16 buffer[1024];
 	_vm->_talk->loadText(0x30DD8, buffer, 1024); //TODO might need to check dialog in other game versions
-	_vm->_talk->displayDialogAroundPoint(buffer,0x27,0xc,0xc01,0,0x30DD8);
+	_vm->_talk->displayDialogAroundPoint(buffer, 0x27, 0xc, 0xc01, 0, 0x30DD8);
 	//TODO this isn't quite right. The audio isn't played and it's not waiting long enough.
 }
 
@@ -1123,7 +1123,7 @@ void SpecialOpcodes::spcTransitionToMap() {
 //	cursorSequenceId = 0;
 //	_vm->waitForFrames();
 //	engine_flags_maybe = engine_flags_maybe | 0x20000000;
-//	FUN_80023b34(0,0,1);
+//	FUN_80023b34(0, 0, 1);
 }
 
 void SpecialOpcodes::spcTransitionFromMap() {
@@ -1159,7 +1159,7 @@ void SpecialOpcodes::spcRunCredits() {
 //	iVar1 = file_read_to_buffer(strCredits_txt);
 //	DAT_800728ec = iVar1 + (int)DAT_8007273c;
 //	buf2048bytes = (int32 *)((iVar1 + 3U & 0xfffffffc) + (int)buf2048bytes);
-//	memcpy2((byte *)buf2048bytes,scrFileData_maybe,0x200);
+//	memcpy2((byte *)buf2048bytes, scrFileData_maybe, 0x200);
 //	buf2048bytes = buf2048bytes + 0x80;
 	_vm->_screen->loadPalette(0, _vm->_dragonINIResource->getRecord(0x2C8)->actor->_actorResource->getPalette());
 	_vm->_scene->setMgLayerPriority(0);
@@ -1189,7 +1189,7 @@ void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
 	//DisableVSyncEvent();
 //	uVar17 = (uint)(uint16)dragon_ini_pointer[DAT_8006398c + -1].field_0x1c;
 //	uVar7 = load_actor_file(0xcc);
-//	file_read_to_buffer(s_s12a6.act_80011740,(&actor_dictionary)[(uVar7 & 0xffff) * 2]);
+//	file_read_to_buffer(s_s12a6.act_80011740, (&actor_dictionary)[(uVar7 & 0xffff) * 2]);
 //	actors[uVar17].actorFileDictionaryIndex = (uint16_t)uVar7;
 //	actors[uVar17].resourceID = 0xcd;
 //	iVar18 = DAT_8006398c;
@@ -1221,7 +1221,7 @@ void SpecialOpcodes::spcJesterInLibrarySceneLogic() {
 	sceneUpdater.iniIDTbl[0][0] = 0xD7;
 	sceneUpdater.iniIDTbl[1][0] = 0xD7;
 	sceneUpdater.iniIDTbl[2][0] = 0xD7;
-	setupTableBasedSceneUpdateFunction(300,3,0x708);
+	setupTableBasedSceneUpdateFunction(300, 3, 0x708);
 }
 
 void SpecialOpcodes::pizzaMakerStopWorking() {
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index b53790fa5d..e8f7df64c9 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -91,11 +91,11 @@ Talk::FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param
 
 	//TODO dragon_text_related(textId);
 	_vm->_data_800633fc = 1;
-	uint32 uVar4 = 0; //TODO FUN_8001d1ac(0,textId,0);
+	uint32 uVar4 = 0; //TODO FUN_8001d1ac(0, textId, 0);
 
 	actor->updateSequence(startSequenceId);
 	_vm->_sound->playSpeech(textId);
-	conversation_related_maybe(dialog, (int)x, (int)y,param_4 & 0xffff, (uint)param_5, textId, uVar4 & 0xffff);
+	conversation_related_maybe(dialog, (int)x, (int)y, param_4 & 0xffff, (uint)param_5, textId, uVar4 & 0xffff);
 
 	actor->updateSequence(endSequenceId);
 }
@@ -168,7 +168,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 	if (param_5 != 0) {
 		_vm->clearFlags(ENGINE_FLAG_8);
 	}
-	tmpTextPtr = findCharInU16Str(dialogText,0x5c);
+	tmpTextPtr = findCharInU16Str(dialogText, 0x5c);
 	if (tmpTextPtr != NULL) {
 		sVar3 = tmpTextPtr[1];
 		*tmpTextPtr = sVar3;
@@ -299,7 +299,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 				iVar6 = iVar5;
 				if (currentLine[0] == 0) break;
 				iVar6 = iVar5 + 1;
-				UTF16ToUTF16Z(asStack2592 + (int)(short)iVar5 * 0x29,currentLine);
+				UTF16ToUTF16Z(asStack2592 + (int)(short)iVar5 * 0x29, currentLine);
 				uVar9 = strlenUTF16(currentLine);
 				if ((int)sVar20 < (int)(uVar9 & 0xffff)) {
 					maxLineLengthMaybe = strlenUTF16(currentLine);
@@ -371,9 +371,9 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 												   ((uint)_dat_8008e844_dialogBox_y1 + unaff_s4 * (uint)_dat_800726f0_tfont_field2 + 1) * 8,
 								dialogTextLinePtr, wideStrLen(dialogTextLinePtr), 0);
 //							ProbablyShowUTF16Msg3
-//									(dialogTextLinePtr,uVar9 & 0xffff,
+//									(dialogTextLinePtr, uVar9 & 0xffff,
 //									 (uint)_dat_8008e844_dialogBox_y1 + iVar5 * (uint)_dat_800726f0_tfont_field2 + 1
-//									 & 0xffff,(uint)param_4, 0xffffffff);
+//									 & 0xffff, (uint)param_4, 0xffffffff);
 					}
 				}
 			}
@@ -413,8 +413,8 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 			LAB_80032e18:
 			//TODO CheckIfCdShellIsOpen();
 			if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
-				FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1,(uint)_dat_8008e844_dialogBox_y1,
-							 (uint)_dat_8008e848_dialogBox_x2,(uint)_dat_8008e874_dialogBox_y2);
+				FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1, (uint)_dat_8008e844_dialogBox_y1,
+							 (uint)_dat_8008e848_dialogBox_x2, (uint)_dat_8008e874_dialogBox_y2);
 			}
 		} while (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) &&
 				 (((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)) && (*curDialogTextPtr != 0))));
@@ -449,12 +449,12 @@ uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 tex
 						((x - _vm->_scene->_camera.x) * 0x10000) >> 0x13,
 				 ((y - _vm->_scene->_camera.y) * 0x10000) >> 0x13,
 				 READ_LE_UINT16(_vm->_dragonOBD->getFromOpt(ini->id) + 6)
-						,1,textIndex);
+						, 1, textIndex);
 	} else {
 		displayDialogAroundActor
 				(ini->actor,
 				 READ_LE_UINT16(_vm->_dragonOBD->getFromOpt(ini->id) + 6),
-				 dialogText,textIndex);
+				 dialogText, textIndex);
 	}
 	return 1;
 }
@@ -488,21 +488,21 @@ void Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint
 //		puVar8[5] = uVar4;
 		_vm->_data_800633fc = 1;
 
-		// sVar3 = FUN_8001d1ac(0,textId,0);
+		// sVar3 = FUN_8001d1ac(0, textId, 0);
 		_vm->_sound->playSpeech(textId);
 
 //		if (dialogText == (uint16 *)0x0) {
 //			dialogText = (uint16 *)local_58;
 //		}
-	conversation_related_maybe(dialogText,x,y,param_4,param_5,textId,0); // sVar3); TODO I think this is audio status
+	conversation_related_maybe(dialogText, x, y, param_4, param_5, textId, 0); // sVar3); TODO I think this is audio status
 }
 
 void Talk::displayDialogAroundActor(Actor *actor, uint16 param_2, uint16 *dialogText, uint32 textIndex) {
 	int16 frameYOffset = actor->_frame ? actor->_frame->yOffset : 0;
 	displayDialogAroundPoint
-			(dialogText,(uint16)((int)(((uint)actor->_x_pos - _vm->_scene->_camera.x) * 0x10000) >> 0x13),
+			(dialogText, (uint16)((int)(((uint)actor->_x_pos - _vm->_scene->_camera.x) * 0x10000) >> 0x13),
 			 (short)((int)((((uint)actor->_y_pos - (uint)frameYOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13) - 3,
-			 param_2,1,textIndex);
+			 param_2, 1, textIndex);
 }
 
 void Talk::copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength) {
@@ -586,8 +586,8 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 		}
 		_vm->clearFlags(ENGINE_FLAG_8);
 		strcpy((char *)local_990, selectedDialogText->dialogText);
-		UTF16ToUTF16Z(auStack2438,(uint16 *)(selectedDialogText->dialogText + 10));
-//		load_string_from_dragon_txt(selectedDialogText->textIndex1,(char *)local_800);
+		UTF16ToUTF16Z(auStack2438, (uint16 *)(selectedDialogText->dialogText + 10));
+//		load_string_from_dragon_txt(selectedDialogText->textIndex1, (char *)local_800);
 		if (selectedDialogText->hasText) {
 			flickerActor->setFlag(ACTOR_FLAG_2000);
 			sequenceId = flickerActor->_sequenceID;
@@ -677,14 +677,14 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 			if ((talkDialogEntry->flags & 1) == 0) {
 				local_60 = local_60 + 1;
 				talkDialogEntry->yPosMaybe = '\0';
-				strcpy((char *)&local_390,(char *)talkDialogEntry->dialogText);
+				strcpy((char *)&local_390, (char *)talkDialogEntry->dialogText);
 				UTF16ToUTF16Z(local_386, (uint16 *)(&talkDialogEntry->dialogText[10]));
 				_dat_80083104 = local_386;
 				if (*local_386 == 0x20) {
 					_dat_80083104 = &local_386[1];
 				}
 				uVar3 = FindLastPositionOf5cChar(_dat_80083104);
-				sVar2 = FUN_80031c28(_dat_80083104,asStack512,uVar3 & 0xffff,0x20);
+				sVar2 = FUN_80031c28(_dat_80083104, asStack512, uVar3 & 0xffff, 0x20);
 				talkDialogEntry->xPosMaybe = (uint8)local_58;
 				local_58 = local_58 + sVar2;
 				talkDialogEntry->yPosMaybe = talkDialogEntry->yPosMaybe + (char)sVar2;
@@ -693,7 +693,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 			uVar3 = (uint)uVar8;
 		} while (uVar8 < numEntries);
 	}
-	FUN_8001a4e4_draw_dialogbox(1,0x17 - (uint)local_58 & 0xffff,0x26,0x18,1);
+	FUN_8001a4e4_draw_dialogbox(1, 0x17 - (uint)local_58 & 0xffff, 0x26, 0x18, 1);
 	uVar8 = 0;
 	_vm->_cursor->updateSequenceID(3);
 	local_50 = -2;
@@ -773,7 +773,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 						_dat_80083104 = &local_386[1];
 					}
 					uVar4 = FindLastPositionOf5cChar(_dat_80083104);
-					uVar4 = FUN_80031c28(_dat_80083104,local_40,uVar4 & 0xffff,0x20);
+					uVar4 = FUN_80031c28(_dat_80083104, local_40, uVar4 & 0xffff, 0x20);
 					_dat_80083104 = local_40;
 					if ((int)sVar2 == (uint)uVar8) {
 						uVar7 = 0;
@@ -783,7 +783,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 								if ((uVar7 & 0xffff) == 0) {
 									x = 4;
 								}
-								//TODO ProbablyShowUTF16Msg(_dat_80083104,x,y,0,-1);
+								//TODO ProbablyShowUTF16Msg(_dat_80083104, x, y, 0, -1);
 								_vm->_fontManager->addText(x * 8, y * 8, _dat_80083104, wideStrLen(_dat_80083104), 0);
 								sVar2 = *_dat_80083104;
 								while (sVar2 != 0) {
@@ -803,7 +803,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 								if ((uVar7 & 0xffff) == 0) {
 									x = 4;
 								}
-								//TODO ProbablyShowUTF16Msg2(_dat_80083104,x,(uint)y,0x401,0xffffffff);
+								//TODO ProbablyShowUTF16Msg2(_dat_80083104, x, (uint)y, 0x401, 0xffffffff);
 								_vm->_fontManager->addText(x * 8, y * 8, _dat_80083104, wideStrLen(_dat_80083104), 1);
 								sVar2 = *_dat_80083104;
 								while (sVar2 != 0) {
@@ -851,7 +851,7 @@ uint Talk::somethingTextAndSpeechAndAnimRelated(Actor *actor, int16 sequenceId1,
 	if (sequenceId1 != -1) {
 		actor->updateSequence(sequenceId1);
 	}
-	displayDialogAroundActor(actor,param_5, dialog, textIndex);
+	displayDialogAroundActor(actor, param_5, dialog, textIndex);
 	if (sequenceId2 != -1) {
 		actor->updateSequence(sequenceId2);
 	}
@@ -890,7 +890,7 @@ void Talk::talkFromIni(uint32 iniId, uint32 textIndex) {
 
 //	pcVar2 = (char *)0x0;
 //	if (((unkFlags1 & 1) == 0) && (((engine_flags_maybe & 0x1000) == 0 || (sVar1 == -1)))) {
-//		pcVar2 = load_string_from_dragon_txt(textIndex,acStack2016);
+//		pcVar2 = load_string_from_dragon_txt(textIndex, acStack2016);
 //	}
 	_vm->_talk->displayDialogAroundINI(iniId, dialog, textIndex); //TODO need to pass dialog here (pcVar2). not NULL
 	if (iniId == 0) {
@@ -996,7 +996,7 @@ void Talk::initDefaultResponseTable() {
 uint32 Talk::strlenUTF16(uint16 *text) {
 	uint32 i = 0;
 
-	for ( ; text[i] != 0; i++) {
+	for (; text[i] != 0; i++) {
 	}
 	return i;
 }
@@ -1108,8 +1108,8 @@ void Talk::clearDialogEntries() {
 }
 
 void Talk::FUN_8001a7c4_clearDialogBoxMaybe() {
-	FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1,(uint)_dat_8008e844_dialogBox_y1,
-			(uint)_dat_8008e848_dialogBox_x2,(uint)_dat_8008e874_dialogBox_y2);
+	FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1, (uint)_dat_8008e844_dialogBox_y1,
+			(uint)_dat_8008e848_dialogBox_x2, (uint)_dat_8008e874_dialogBox_y2);
 }
 
 void Talk::playDialogAudioDontWait(uint32 textIndex) {
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 16f3ea4098..d41ebec08d 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -87,7 +87,7 @@ public:
 
 	bool talkToActor(ScriptOpCall &scriptOpCall);
 
-	uint somethingTextAndSpeechAndAnimRelated(Actor *actor,int16 sequenceId1,int16 sequenceId2,uint32 textIndex, uint16 param_5);
+	uint somethingTextAndSpeechAndAnimRelated(Actor *actor, int16 sequenceId1, int16 sequenceId2, uint32 textIndex, uint16 param_5);
 	void FUN_8001a7c4_clearDialogBoxMaybe(); //clear box maybe?
 
 	void playDialogAudioDontWait(uint32 textIndex);
@@ -105,7 +105,7 @@ private:
 	void FUN_8001a4e4_draw_dialogbox(uint32 x1, uint32 y1, uint32 x2, uint32 y2, uint16 unk);
 	uint16 *UTF16ToUTF16Z(uint16 *dest, uint16 *src);
 	uint16 FindLastPositionOf5cChar(uint16 *text);
-	uint32 FUN_80031c28(uint16 *srcText, uint16 *destText,uint32 cutLength, uint16 param_4);
+	uint32 FUN_80031c28(uint16 *srcText, uint16 *destText, uint32 cutLength, uint16 param_4);
 
 };
 


Commit: 6e86ab1d4526713177782e3ae055391344cc49d1
    https://github.com/scummvm/scummvm/commit/6e86ab1d4526713177782e3ae055391344cc49d1
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Code clean. Added names to some script opcodes. Fixes for mini game 2

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/dragons.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/talk.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index e41e0bb80c..efe7ec872f 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -160,7 +160,7 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	_walkDestX = x;
 	_walkDestY = y;
 	_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-	_sequenceID2 = 0;
+	_direction = 0;
 	_flags = (ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
 	_frame_width = 0;
 	_frame_height = 0;
@@ -437,7 +437,7 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 			} else {
 				newDirection = (dy <= 0)  ? 2 : 6;
 			}
-			_sequenceID2 = newDirection;
+			_direction = newDirection;
 			if (wasAlreadyWalking) {
 				stopWalk();
 			}
@@ -458,10 +458,10 @@ bool Actor::startWalk(int16 destX, int16 destY, uint16 flags) {
 	}
 	int direction = startMoveToPoint(_walkDestX, _walkDestY);
 	if (direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
-		_sequenceID2 = direction;
+		_direction = direction;
 	}
-	if (_sequenceID != _sequenceID2 + 8 && !isFlagSet(ACTOR_FLAG_800)) {
-		updateSequence(_sequenceID2 + 8);
+	if (_sequenceID != _direction + 8 && !isFlagSet(ACTOR_FLAG_800)) {
+		updateSequence(_direction + 8);
 	}
 	setFlag(ACTOR_FLAG_10);
 	return true;
@@ -731,10 +731,10 @@ void Actor::walkPath() {
 			// 0x8001bcc8
 			int direction = startMoveToPoint(_walkDestX, _walkDestY);
 			if (direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
-				_sequenceID2 = direction;
+				_direction = direction;
 			}
-			if (_sequenceID != _sequenceID2 + 8 && _sequenceID2 != -1 && !isFlagSet(ACTOR_FLAG_800)) {
-				updateSequence(_sequenceID2 + 8);
+			if (_sequenceID != _direction + 8 && _direction != -1 && !isFlagSet(ACTOR_FLAG_800)) {
+				updateSequence(_direction + 8);
 			}
 			setFlag(ACTOR_FLAG_10);
 		}
@@ -793,4 +793,8 @@ byte *Actor::getPalette() {
 	return getEngine()->_screen->getPalette(4);
 }
 
+int16 Actor::getFrameYOffset() {
+	return _frame ? _frame->yOffset : 0;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index b179ac49fc..f21d11d326 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -97,7 +97,7 @@ public:
 	int16 _scale; // scale factor 0x100 is 100%
 	uint16 _sequenceTimer;
 	uint16 _sequenceID;
-	int16 _sequenceID2;
+	int16 _direction;
 	int16 _priorityLayer;
 	uint16 _flags;
 	int16 _x_pos;
@@ -148,6 +148,7 @@ public:
 	bool isFlagClear(uint32 flag) { return !isFlagSet(flag); }
 
 	byte *getPalette();
+	int16 getFrameYOffset();
 private:
 	void stopWalk();
 	uint16 canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 walkFlags);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 1b32a51f9d..9c593dfd8c 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -286,7 +286,7 @@ void DragonsEngine::gameLoop() {
 		if (0x4af < _counter) {
 			pDVar8 = _dragonINIResource->getFlickerRecord();
 			if (pDVar8->actor->_resourceID == 0xe) {
-				pDVar8->actor->_sequenceID2 = 2;
+				pDVar8->actor->_direction = 2;
 				pDVar8->field_20_actor_field_14 = 2;
 				if (getINI(0xc2)->field_1e == 1) {
 					sequenceId = 0x30;
@@ -370,13 +370,13 @@ void DragonsEngine::gameLoop() {
 		if (_bit_flags_8006fbd8 == 3) {
 			_bit_flags_8006fbd8 = 0;
 			DragonINI *flicker = _dragonINIResource->getFlickerRecord();
-			if (flicker->sceneId == getCurrentSceneId() && flicker->actor->_sequenceID2 != -1) {
+			if (flicker->sceneId == getCurrentSceneId() && flicker->actor->_direction != -1) {
 				uVar6 = _scriptOpcodes->_scriptTargetINI;
 				if (_cursor->_sequenceID != 5) {
 					uVar6 = _cursor->_data_80072890;
 				}
 				if (uVar6 > 0) {
-					flicker->actor->_sequenceID2 = getINI(uVar6 - 1)->field_e;
+					flicker->actor->_direction = getINI(uVar6 - 1)->field_e;
 				}
 			}
 
@@ -868,9 +868,9 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 					_bit_flags_8006fbd8 = _bit_flags_8006fbd8 | 2;
 				}
 //				if (((((actors[actorId]._flags & 0x2000) == 0) && ((actors[actorId]._flags & 4) != 0)) &&
-//					 (actors[actorId]._sequenceID2 != actors[actorId]._sequenceID)) &&
-//				(actors[actorId]._sequenceID2 != -1)) {
-//					actor_update_sequenceID(actorId, actors[actorId]._sequenceID2);
+//					 (actors[actorId]._direction != actors[actorId]._sequenceID)) &&
+//				(actors[actorId]._direction != -1)) {
+//					actor_update_sequenceID(actorId, actors[actorId]._direction);
 //				}
 			}
 
@@ -940,9 +940,9 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 					}
 					if (flickerINI->actor->isFlagClear(ACTOR_FLAG_2000)
 							&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
-							&& flickerINI->actor->_sequenceID2 != -1
-							&& flickerINI->actor->_sequenceID2 != flickerINI->actor->_sequenceID) {
-						flickerINI->actor->updateSequence(flickerINI->actor->_sequenceID2);
+							&& flickerINI->actor->_direction != -1
+							&& flickerINI->actor->_direction != flickerINI->actor->_sequenceID) {
+						flickerINI->actor->updateSequence(flickerINI->actor->_direction);
 					}
 				}
 			} else {
@@ -1171,7 +1171,7 @@ void DragonsEngine::walkFlickerToObject() {
 				flickerINI->actor->setFlag(ACTOR_FLAG_4);
 				targetINI = getINI(_cursor->_data_80072890 - 1);
 				flickerINI->field_20_actor_field_14 = targetINI->field_e;
-				flickerINI->actor->_sequenceID2 = targetINI->field_e;
+				flickerINI->actor->_direction = targetINI->field_e;
 			}
 			_bit_flags_8006fbd8 = 3;
 			return;
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index e2d4465618..6b26b6144c 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -177,7 +177,7 @@ void Minigame1::run() {
 	flickerActor->_flags = flickerActor->_flags | 0x380;
 	flickerActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	flickerActor->_priorityLayer = 4;
-	flickerActor->_sequenceID2 = -1;
+	flickerActor->_direction = -1;
 	flickerActor->updateSequence(0x15);
 	hitCounter = 0;
 	local_254 = 0;
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index 56cb72f922..f6ec92d4bf 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -47,10 +47,10 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	bool bVar4;
 	DragonINI *flicker;
 	uint32 origEngineFlags;
-	Actor *uVar5;
+	Actor *loungealotBigPunchActor;
 	Actor *loungealotHeadActor;
 	Actor *loungealotLeftUpperArm;
-	Actor *uVar8;
+	Actor *loungealotLegActor;
 	Actor *loungealotRightArm;
 	Actor *flickerArm;
 	Actor *loungealotThumb;
@@ -172,29 +172,29 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	_vm->_screen->loadPalette(1, paletteData);
 	_vm->_screen->updatePaletteTransparency(1, 0x40, 0x7f, true);
 
-	uVar5 = _vm->_actorManager->loadActor(0x11, 0, 0, 0, 6);
+	loungealotBigPunchActor = _vm->_actorManager->loadActor(0x11, 0, 0, 0, 6);
 	loungealotHeadActor = _vm->_actorManager->loadActor(0xd, 0, 0x7d, 199, 4);
 	loungealotLeftUpperArm = _vm->_actorManager->loadActor(0xb, 2, 0x7d, 199, 4);
-	uVar8 = _vm->_actorManager->loadActor(0xf, 0, 0x7d, 199, 4);
+	loungealotLegActor = _vm->_actorManager->loadActor(0xf, 0, 0x7d, 199, 4);
 	loungealotRightArm = _vm->_actorManager->loadActor(0x10, 0, 0x7d, 199, 4);
 	flickerArm = _vm->_actorManager->loadActor(9, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc],
-											   loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e,
-											   loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10, 4);
+											   loungealotLeftUpperArm->_x_pos,
+											   loungealotLeftUpperArm->_y_pos, 4);
 	loungealotThumb = _vm->_actorManager->loadActor(0x12, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb4 * 3 + (uint)_dat_80093cbc],
-													loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e,
-													loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10, 4);
+													loungealotLeftUpperArm->_x_pos,
+													loungealotLeftUpperArm->_y_pos, 4);
 	uVar12 = _vm->_actorManager->loadActor(10, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0],
-										   flickerArm->_x_pos - flickerArm->_frame->field_e,
-										   flickerArm->_y_pos - flickerArm->_frame->field_10, 4);
+										   flickerArm->_x_pos,
+										   flickerArm->_y_pos, 4);
 	uVar13 = _vm->_actorManager->loadActor(0x13, (uint)(uint16)actorSequenceIdTbl[(uint)_dat_80093cb8 * 3 + (uint)_dat_80093cc0],
-										   flickerArm->_x_pos - flickerArm->_frame->field_e,
-										   flickerArm->_y_pos - flickerArm->_frame->field_10, 4);
+										   flickerArm->_x_pos,
+										   flickerArm->_y_pos, 4);
 	uVar14 = _vm->_actorManager->loadActor(0x27, 0, 0x10, 0xac, 4);
 	uVar15 = _vm->_actorManager->loadActor(0x27, 1, 0x10, 0x8c, 4);
-	uVar5->setFlag(ACTOR_FLAG_100);
+	loungealotBigPunchActor->setFlag(ACTOR_FLAG_100);
 	loungealotHeadActor->setFlag(ACTOR_FLAG_100);
 	loungealotLeftUpperArm->setFlag(ACTOR_FLAG_100);
-	uVar8->setFlag(ACTOR_FLAG_100);
+	loungealotLegActor->setFlag(ACTOR_FLAG_100);
 	loungealotRightArm->setFlag(ACTOR_FLAG_100);
 	flickerArm->setFlag(ACTOR_FLAG_100);
 	loungealotThumb->setFlag(ACTOR_FLAG_100);
@@ -203,7 +203,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uVar14->setFlag(ACTOR_FLAG_100);
 	uVar15->setFlag(ACTOR_FLAG_100);
 
-	uVar5->_priorityLayer = 6;
+	loungealotBigPunchActor->_priorityLayer = 6;
 	flickerArm->_priorityLayer = 5;
 	uVar12->_priorityLayer = 5;
 	loungealotThumb->_priorityLayer = 4;
@@ -211,7 +211,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	loungealotRightArm->_priorityLayer = 3;
 	loungealotLeftUpperArm->_priorityLayer = 2;
 	loungealotHeadActor->_priorityLayer = 2;
-	uVar8->_priorityLayer = 1;
+	loungealotLegActor->_priorityLayer = 1;
 	uVar14->_priorityLayer = 0;
 	uVar15->_priorityLayer = 0;
 	//TODO
@@ -222,7 +222,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 //	EnableVSyncEvent();
 	loungealotHeadActor->setFlag(ACTOR_FLAG_1);
 	loungealotLeftUpperArm->setFlag(ACTOR_FLAG_1);
-	uVar8->setFlag(ACTOR_FLAG_1);
+	loungealotLegActor->setFlag(ACTOR_FLAG_1);
 	loungealotRightArm->setFlag(ACTOR_FLAG_1);
 	flickerArm->setFlag(ACTOR_FLAG_1);
 	loungealotThumb->setFlag(ACTOR_FLAG_1);
@@ -235,9 +235,9 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	loungealotLeftUpperArm->waitUntilFlag8And4AreSet();
 	loungealotRightArm->waitUntilFlag8And4AreSet();
 	loungealotHeadActor->waitUntilFlag8And4AreSet();
-	uVar8->waitUntilFlag8And4AreSet();
+	loungealotLegActor->waitUntilFlag8And4AreSet();
 
-	uVar5->setFlag(ACTOR_FLAG_400);
+	loungealotBigPunchActor->setFlag(ACTOR_FLAG_400);
 	flickerArm->_x_pos = loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e;
 	flickerArm->_y_pos = loungealotLeftUpperArm->_y_pos - loungealotLeftUpperArm->_frame->field_10;
 	loungealotThumb->_x_pos = loungealotLeftUpperArm->_x_pos - loungealotLeftUpperArm->_frame->field_e;
@@ -249,54 +249,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	_vm->waitForFrames(2);
 	// call_fade_related_1f();
 
-LAB_80090188:
 	do {
-		if (shouldExit) {
-//			fade_related_calls_with_1f();
-			_vm->_sound->PauseCDMusic();
-//			DisableVSyncEvent();
-			_vm->_dragonINIResource->getRecord(0)->x = 0x91;
-			_vm->_dragonINIResource->getRecord(0)->y = 0x9b;
-			_vm->_dragonINIResource->getRecord(0x123)->x = 0xc3;
-			_vm->_dragonINIResource->getRecord(0x123)->y = 0x9b;
-			_vm->_screen->loadPalette(1, _vm->_cursor->getPalette());
-			_vm->setupPalette1();
-			//TODO FUN_80035e74((uint)uVar17);
-			//TODO FUN_80035e74((uint)uVar16);
-			_vm->_dragonINIResource->setFlickerRecord(flicker);
-			_vm->_inventory->setType(originalInventoryType);
-			flicker->field_12 = local_258 + -1;
-			if (flicker->field_12 == 0) {
-				_vm->setVar(0xb, 1);
-				flicker->actorResourceId = 0xd2; //TODO is this correct?
-				_vm->_actorManager->loadActor(0xd2, flicker->actor->_actorID);
-				_vm->_dragonINIResource->getRecord(0x120)->sceneId = 0x17;
-			}
-			loungealotHeadActor->clearFlag(ACTOR_FLAG_40);
-			loungealotLeftUpperArm->clearFlag(ACTOR_FLAG_40);
-			uVar8->clearFlag(ACTOR_FLAG_40);
-			loungealotRightArm->clearFlag(ACTOR_FLAG_40);
-			flickerArm->clearFlag(ACTOR_FLAG_40);
-			loungealotThumb->clearFlag(ACTOR_FLAG_40);
-			uVar12->clearFlag(ACTOR_FLAG_40);
-			uVar13->clearFlag(ACTOR_FLAG_40);
-//			EnableVSyncEvent();
-			if (param_3 == 0) {
-//				fade_related_calls_with_1f();
-//				TODO ClearFlatShadedQuads(0);
-				uVar14->clearFlag(ACTOR_FLAG_40);
-				uVar15->clearFlag(ACTOR_FLAG_40);
-				_vm->reset_screen_maybe();
-			} else {
-				_vm->reset_screen_maybe();
-				_vm->_scene->setSceneId(0x17);
-				flicker->sceneId = 0x17;
-				_vm->_scene->loadSceneData((uint)(0x17 | 0x8000), 0);
-				_vm->setAllFlags((origEngineFlags & 0xfefdffff) | (_vm->getAllFlags() & 0x1000000) | 0x40);
-//				call_fade_related_1f();
-			}
-			return;
-		}
 		_vm->waitForFrames(1);
 
 		if ((_dat_80093c9c != 0) && !_vm->isFlagSet(ENGINE_FLAG_8000)) {
@@ -307,9 +260,9 @@ LAB_80090188:
 		if (_dat_80093c94 != 0) {
 			local_264 = 0;
 		}
-		if (uVar8->_field_7a == 1) {
+		if (loungealotLegActor->_field_7a == 1) {
 			shouldShakeScreen = true;
-			uVar8->_field_7a = 0;
+			loungealotLegActor->_field_7a = 0;
 			screenShakeCounter = 0;
 		}
 		if (shouldShakeScreen) {
@@ -449,26 +402,26 @@ LAB_80090188:
 							_vm->waitForFrames(2 * 0x3c);
 //							DisableVSyncEvent();
 							memset(paletteData, 0, 0x200);
-							uVar5->_flags = uVar5->_flags & 0xfbff;
+							loungealotBigPunchActor->_flags = loungealotBigPunchActor->_flags & 0xfbff;
 							loungealotHeadActor->setFlag(ACTOR_FLAG_400);
 							loungealotLeftUpperArm->setFlag(ACTOR_FLAG_400);
 							loungealotRightArm->setFlag(ACTOR_FLAG_400);
-							uVar8->_flags = uVar8->_flags | 0x400;
+							loungealotLegActor->_flags = loungealotLegActor->_flags | 0x400;
 							flickerArm->setFlag(ACTOR_FLAG_400);
 							loungealotThumb->setFlag(ACTOR_FLAG_400);
 							uVar12->setFlag(ACTOR_FLAG_400);
 							uVar13->setFlag(ACTOR_FLAG_400);
 //							EnableVSyncEvent();
 							_vm->waitForFrames(6);
-							uVar5->updateSequence(1);
-							uVar5->waitUntilFlag4IsSet();
+							loungealotBigPunchActor->updateSequence(1);
+							loungealotBigPunchActor->waitUntilFlag4IsSet();
 							_vm->waitForFrames(1);
 							_vm->_screen->loadPalette(0, paletteData);
 							_vm->_screen->loadPalette(1, paletteData);
 //	TODO						FUN_8001a7c4((uint)_dat_8008e7e8, (uint)_dat_8008e844, (uint)_dat_8008e848,
 //										 (uint)_dat_8008e874);
-							shouldExit = true;
-							goto LAB_80090188;
+							//punched in the face.
+							break;
 						}
 					}
 					if (local_26c != 0) {
@@ -586,7 +539,7 @@ LAB_80090188:
 					} else {
 						if (local_258 == 1) {
 							loungealotHeadActor->updateSequence(1);
-							uVar8->updateSequence(1);
+							loungealotLegActor->updateSequence(1);
 							if (local_288 == 2) {
 								local_28 = 1;
 							} else {
@@ -630,7 +583,7 @@ LAB_80090188:
 					}
 				}
 			} else {
-				if (_dat_80093c94 == 2) {
+				if (_dat_80093c94 == 2) { // Flicker loses by being pinned
 					uVar12->_flags = uVar12->_flags | 0x1000;
 					uVar13->_flags = uVar13->_flags | 0x1000;
 					flickerArm->_flags = flickerArm->_flags | 0x1000;
@@ -656,10 +609,10 @@ LAB_80090188:
 						loungealotHeadActor->updateSequence(4);
 					}
 					_vm->waitForFrames(2 * 0x3c);
-					shouldExit = true;
+					break;
 				}
 			}
-			goto LAB_80090188;
+			continue;
 		}
 		if (local_272 == 0) {
 			local_272 = 1;
@@ -695,7 +648,7 @@ LAB_80090188:
 		}
 		if ((0x3f < local_278) || (0x3f < local_27a)) {
 			loungealotHeadActor->setFlag(ACTOR_FLAG_1000);
-			uVar8->setFlag(ACTOR_FLAG_1000);
+			loungealotLegActor->setFlag(ACTOR_FLAG_1000);
 			loungealotRightArm->setFlag(ACTOR_FLAG_1000);
 			if (0x40 < local_27a) {
 				local_27a = 0x40;
@@ -731,9 +684,51 @@ LAB_80090188:
 				_dat_80093c94 = 2;
 			}
 		}
-
 	} while (true);
 
+//	fade_related_calls_with_1f();
+	_vm->_sound->PauseCDMusic();
+//	DisableVSyncEvent();
+	_vm->_dragonINIResource->getRecord(0)->x = 0x91;
+	_vm->_dragonINIResource->getRecord(0)->y = 0x9b;
+	_vm->_dragonINIResource->getRecord(0x123)->x = 0xc3;
+	_vm->_dragonINIResource->getRecord(0x123)->y = 0x9b;
+	_vm->_screen->loadPalette(1, _vm->_cursor->getPalette());
+	_vm->setupPalette1();
+	//TODO FUN_80035e74((uint)uVar17);
+	//TODO FUN_80035e74((uint)uVar16);
+	_vm->_dragonINIResource->setFlickerRecord(flicker);
+	_vm->_inventory->setType(originalInventoryType);
+	flicker->field_12 = local_258 + -1;
+	if (flicker->field_12 == 0) {
+		_vm->setVar(0xb, 1);
+		flicker->actorResourceId = 0xd2; //TODO is this correct?
+		_vm->_actorManager->loadActor(0xd2, flicker->actor->_actorID);
+		_vm->_dragonINIResource->getRecord(0x120)->sceneId = 0x17;
+	}
+	loungealotHeadActor->clearFlag(ACTOR_FLAG_40);
+	loungealotLeftUpperArm->clearFlag(ACTOR_FLAG_40);
+	loungealotLegActor->clearFlag(ACTOR_FLAG_40);
+	loungealotRightArm->clearFlag(ACTOR_FLAG_40);
+	flickerArm->clearFlag(ACTOR_FLAG_40);
+	loungealotThumb->clearFlag(ACTOR_FLAG_40);
+	uVar12->clearFlag(ACTOR_FLAG_40);
+	uVar13->clearFlag(ACTOR_FLAG_40);
+//	EnableVSyncEvent();
+	if (param_3 == 0) {
+//		fade_related_calls_with_1f();
+//		TODO ClearFlatShadedQuads(0);
+		uVar14->clearFlag(ACTOR_FLAG_40);
+		uVar15->clearFlag(ACTOR_FLAG_40);
+		_vm->reset_screen_maybe();
+	} else {
+		_vm->reset_screen_maybe();
+		_vm->_scene->setSceneId(0x17);
+		flicker->sceneId = 0x17;
+		_vm->_scene->loadSceneData((uint)(0x17 | 0x8000), 0);
+		_vm->setAllFlags((origEngineFlags & 0xfefdffff) | (_vm->getAllFlags() & 0x1000000) | 0x40);
+//		call_fade_related_1f();
+	}
 }
 
 void Minigame2::fun_80093aec_dialog(uint32 textId, int16 x, int16 y) {
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index b3db5e13c2..acc04ffa7d 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -110,7 +110,7 @@ void Minigame5::run() {
 	flickerActor->_flags = flickerActor->_flags | 0x380;
 	flickerActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	flickerActor->_priorityLayer = 4;
-	flickerActor->_sequenceID2 = -1;
+	flickerActor->_direction = -1;
 	flickerActor->updateSequence(0x19);
 	currentState = 0;
 	local_10 = 0;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index f059c41e1e..59b119caec 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -235,7 +235,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 						}
 					}
 
-					actor->_sequenceID2 = ini->field_20_actor_field_14;
+					actor->_direction = ini->field_20_actor_field_14;
 
 					if (ini->field_1a_flags_maybe & 2) {
 						actor->_flags |= ACTOR_FLAG_80;
@@ -290,7 +290,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	if (flicker && flicker->sceneId != 0) {
 		flicker->field_20_actor_field_14 = _vm->_data_800633fa;
 		if (flicker->actor) {
-			flicker->actor->_sequenceID2 = _vm->_data_800633fa;
+			flicker->actor->_direction = _vm->_data_800633fa;
 			flicker->actor->setFlag(ACTOR_FLAG_4);
 		}
 	}
@@ -315,7 +315,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	if (flicker && flicker->sceneId == _currentSceneId) {
 
-		flicker->actor->updateSequence((uint16)flicker->actor->_sequenceID2);
+		flicker->actor->updateSequence((uint16)flicker->actor->_direction);
 	}
 
 	_vm->clearUnkFlags(ENGINE_UNK1_FLAG_2);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 7c76ae3813..c37a8d7fe7 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -106,17 +106,17 @@ void ScriptOpcodes::initOpcodes() {
 	}
 	// Register opcodes
 	OPCODE(1, opUnk1);
-	OPCODE(2, opUnk2); //dialog related
+	OPCODE(2, opAddDialogChoice);
 	OPCODE(3, opUnk3); //dialog related
 	OPCODE(4,  opExecuteScript);
-	OPCODE(5,  opActorSetSequenceID2);
+	OPCODE(5, opSetActorDirection);
 	OPCODE(6,  opUnk6);
-	OPCODE(7,  opUnk7);
+	OPCODE(7, opMoveObjectToScene);
 	OPCODE(8,  opActorLoadSequence);
 
-	OPCODE(0xA, opUnkA);
+	OPCODE(0xA, opSetVariable);
 	OPCODE(0xB, opRunSpecialOpCode);
-	OPCODE(0xC, opUnkCSoundRelatedMaybe);
+	OPCODE(0xC, opPlayOrStopSound);
 	OPCODE(0xD, opDelay);
 	OPCODE(0xE, opUnkE);
 	OPCODE(0xF, opUnkF);
@@ -247,7 +247,7 @@ void ScriptOpcodes::opUnk1(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-void ScriptOpcodes::opUnk2(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opAddDialogChoice(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_UINT32(field2);
 	ARG_UINT32(field6);
@@ -295,14 +295,14 @@ void ScriptOpcodes::opExecuteScript(ScriptOpCall &scriptOpCall) {
 	executeScriptLoop(newScriptOpCall);
 }
 
-void ScriptOpcodes::opActorSetSequenceID2(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opSetActorDirection(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(iniIndex);
 	ARG_SKIP(2);
-	ARG_INT16(sequenceId);
+	ARG_INT16(direction);
 
 	if (scriptOpCall._field8 == 0) {
-		_vm->getINI(iniIndex - 1)->actor->_sequenceID2 = sequenceId;
+		_vm->getINI(iniIndex - 1)->actor->_direction = direction;
 	}
 }
 
@@ -346,13 +346,100 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	_scriptTargetINI = uVar6;
 }
 
-void ScriptOpcodes::opUnk7(ScriptOpCall &scriptOpCall) {
-	if (scriptOpCall._field8 == 0) {
-		opCode_Unk7(scriptOpCall);
-	} else {
-		scriptOpCall._code += 6;
+void ScriptOpcodes::opMoveObjectToScene(ScriptOpCall &scriptOpCall) {
+	ARG_INT16(field0);
+	ARG_INT16(field2);
+	ARG_INT16(sceneId);
+
+	if (scriptOpCall._field8 != 0) {
+		return;
 	}
 
+	uint16 currentScene = _vm->getCurrentSceneId();
+	DragonINI *ini = _vm->getINI(field2 - 1);
+	if (!(field0 & 0x8000)) {
+
+		if (ini->field_1a_flags_maybe & 1) {
+			if (ini->sceneId == currentScene) {
+				assert(ini->actor);
+				ini->actor->reset_maybe();
+			}
+			if (sceneId == currentScene) {
+				ini->actor = _vm->_actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
+				ini->actor->_direction = ini->field_20_actor_field_14;
+				if (ini->field_1a_flags_maybe & 2) {
+					ini->actor->_flags |= ACTOR_FLAG_80;
+				} else {
+					ini->actor->_flags &= ~ACTOR_FLAG_80;
+				}
+
+				if (ini->field_1a_flags_maybe & 0x20) {
+					ini->actor->_flags |= ACTOR_FLAG_100;
+				} else {
+					ini->actor->_flags &= ~ACTOR_FLAG_100;
+				}
+
+				if (ini->field_1a_flags_maybe & 4) {
+					ini->actor->_flags |= ACTOR_FLAG_8000;
+				} else {
+					ini->actor->_flags &= ~ACTOR_FLAG_8000;
+				}
+
+				if (ini->field_1a_flags_maybe & 0x100) {
+					ini->actor->_flags |= ACTOR_FLAG_4000;
+				} else {
+					ini->actor->_flags &= ~ACTOR_FLAG_4000;
+				}
+			}
+		} else {
+			if (ini->sceneId == currentScene && ini->iptIndex_maybe != -1) {
+				_vm->_scene->removeImageOverlay(ini->iptIndex_maybe);
+			}
+			if (sceneId == currentScene && ini->iptIndex_maybe != -1) {
+				_vm->_scene->loadImageOverlay(ini->iptIndex_maybe);
+			}
+		}
+
+		if (ini->sceneId == 1) {
+			if ((uint)_vm->_cursor->_iniItemInHand - 1 == ini->id) {
+				_vm->_cursor->_data_800728b0_cursor_seqID = 0;
+				_vm->_cursor->_sequenceID = 0;
+				_vm->_cursor->_iniItemInHand = 0;
+			} else {
+				if (_vm->_inventory->clearItem(ini->id + 1)) {
+					if (_vm->_inventory->getType() == 1) {
+						ini->actor->clearFlag(ACTOR_FLAG_40);
+					}
+				}
+			}
+		}
+
+		if (sceneId == 1) {
+			if (_vm->_cursor->_iniItemInHand != 0) {
+				_vm->_inventory->addItem(_vm->_cursor->_iniItemInHand);
+				if (_vm->_inventory->getType() == 1) {
+					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->_iniItemInHand);
+					actor->_flags = 0;
+					actor->_priorityLayer = 0;
+					actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
+					actor->updateSequence((_vm->getINI(_vm->_cursor->_iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
+					actor->setFlag(ACTOR_FLAG_40);
+					actor->setFlag(ACTOR_FLAG_80);
+					actor->setFlag(ACTOR_FLAG_100);
+					actor->setFlag(ACTOR_FLAG_200);
+					actor->_priorityLayer = 6;
+				}
+			}
+			DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
+			_vm->_cursor->updatePosition(flicker->actor->_x_pos - _vm->_scene->_camera.x,
+										 flicker->actor->_y_pos - (_vm->_scene->_camera.y + 0x1e));
+			_vm->_cursor->_data_800728b0_cursor_seqID = 5;
+			_vm->_cursor->_sequenceID = 5;
+			_vm->_cursor->data_8007283c = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
+			_vm->_cursor->_iniItemInHand = field2;
+		}
+	}
+	ini->sceneId = sceneId;
 }
 
 void ScriptOpcodes::opActorLoadSequence(ScriptOpCall &scriptOpCall) {
@@ -549,9 +636,9 @@ bool ScriptOpcodes::evaluateExpression(ScriptOpCall &scriptOpCall) {
 	return (result & 0xffff) != 0;
 }
 
-void ScriptOpcodes::opUnkA(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opSetVariable(ScriptOpCall &scriptOpCall) {
 	if (scriptOpCall._field8 == 0) {
-		opCode_UnkA_setsProperty(scriptOpCall);
+		setVariable(scriptOpCall);
 	} else {
 		scriptOpCall._code += 0xC;
 	}
@@ -573,7 +660,7 @@ void ScriptOpcodes::opRunSpecialOpCode(ScriptOpCall &scriptOpCall) {
 	_specialOpCodes->run(specialOpCode);
 }
 
-void ScriptOpcodes::opUnkCSoundRelatedMaybe(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opPlayOrStopSound(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(soundId);
 
@@ -792,13 +879,11 @@ void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
 		}
 	}
 
-	secondIni->actor->_sequenceID2 = firstIni->field_e;
+	secondIni->actor->_direction = firstIni->field_e;
 
 	secondIni->x = newXPosAgain;
 	secondIni->y = newYPosAgain;
 	secondIni->actor->clearFlag(ACTOR_FLAG_800);
-	return;
-
 }
 
 void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
@@ -878,14 +963,14 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 	} else {
 		_vm->_talk->FUN_8003239c(dialog,
 								 (int)(((uint)ini->actor->_x_pos - (uint)_vm->_scene->_camera.x) * 0x10000) >> 0x13,
-								 (int)(((ini->actor->_y_pos - ini->actor->_frame->yOffset) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13,
+								 (int)(((ini->actor->_y_pos - ini->actor->getFrameYOffset()) - (uint)_vm->_scene->_camera.y) * 0x10000) >> 0x13,
 								 READ_LE_INT16(_vm->_dragonOBD->getFromOpt(iniId) + 6),
 								 1,
 								 ini->actor, startSequenceId, endSequenceId, textIndex);
 	}
 }
 
-void ScriptOpcodes::opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::setVariable(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
 	ARG_INT16(field4);
@@ -1164,95 +1249,7 @@ void ScriptOpcodes::opSetActorFlag0x1000(ScriptOpCall &scriptOpCall) {
 }
 
 void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
-	ARG_INT16(field0);
-	ARG_INT16(field2);
-	ARG_INT16(sceneId); //sceneId
-
-	uint16 currentScene = _vm->getCurrentSceneId();
-	DragonINI *ini = _vm->getINI(field2 - 1);
-	if (!(field0 & 0x8000)) {
-
-		if (ini->field_1a_flags_maybe & 1) {
-			if (ini->sceneId == currentScene) {
-				assert(ini->actor);
-				ini->actor->reset_maybe();
-			}
-			if (sceneId == currentScene) {
-				ini->actor = _vm->_actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
-				ini->actor->_sequenceID2 = ini->field_20_actor_field_14;
-				if (ini->field_1a_flags_maybe & 2) {
-					ini->actor->_flags |= ACTOR_FLAG_80;
-				} else {
-					ini->actor->_flags &= ~ACTOR_FLAG_80;
-				}
-
-				if (ini->field_1a_flags_maybe & 0x20) {
-					ini->actor->_flags |= ACTOR_FLAG_100;
-				} else {
-					ini->actor->_flags &= ~ACTOR_FLAG_100;
-				}
-
-				if (ini->field_1a_flags_maybe & 4) {
-					ini->actor->_flags |= ACTOR_FLAG_8000;
-				} else {
-					ini->actor->_flags &= ~ACTOR_FLAG_8000;
-				}
-
-				if (ini->field_1a_flags_maybe & 0x100) {
-					ini->actor->_flags |= ACTOR_FLAG_4000;
-				} else {
-					ini->actor->_flags &= ~ACTOR_FLAG_4000;
-				}
-			}
-		} else {
-			if (ini->sceneId == currentScene && ini->iptIndex_maybe != -1) {
-				_vm->_scene->removeImageOverlay(ini->iptIndex_maybe);
-			}
-			if (sceneId == currentScene && ini->iptIndex_maybe != -1) {
-				_vm->_scene->loadImageOverlay(ini->iptIndex_maybe);
-			}
-		}
-
-		if (ini->sceneId == 1) {
-			if ((uint)_vm->_cursor->_iniItemInHand - 1 == ini->id) {
-				_vm->_cursor->_data_800728b0_cursor_seqID = 0;
-				_vm->_cursor->_sequenceID = 0;
-				_vm->_cursor->_iniItemInHand = 0;
-			} else {
-				if (_vm->_inventory->clearItem(ini->id + 1)) {
-					if (_vm->_inventory->getType() == 1) {
-						ini->actor->clearFlag(ACTOR_FLAG_40);
-					}
-				}
-			}
-		}
 
-		if (sceneId == 1) {
-			if (_vm->_cursor->_iniItemInHand != 0) {
-				_vm->_inventory->addItem(_vm->_cursor->_iniItemInHand);
-				if (_vm->_inventory->getType() == 1) {
-					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->_iniItemInHand);
-					actor->_flags = 0;
-					actor->_priorityLayer = 0;
-					actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-					actor->updateSequence((_vm->getINI(_vm->_cursor->_iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
-					actor->setFlag(ACTOR_FLAG_40);
-					actor->setFlag(ACTOR_FLAG_80);
-					actor->setFlag(ACTOR_FLAG_100);
-					actor->setFlag(ACTOR_FLAG_200);
-					actor->_priorityLayer = 6;
-				}
-			}
-			DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
-			_vm->_cursor->updatePosition(flicker->actor->_x_pos - _vm->_scene->_camera.x,
-					flicker->actor->_y_pos - (_vm->_scene->_camera.y + 0x1e));
-			_vm->_cursor->_data_800728b0_cursor_seqID = 5;
-			_vm->_cursor->_sequenceID = 5;
-			_vm->_cursor->data_8007283c = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
-			_vm->_cursor->_iniItemInHand = field2;
-		}
-	}
-	ini->sceneId = sceneId;
 }
 
 void ScriptOpcodes::loadTalkDialogEntries(ScriptOpCall &scriptOpCall) {
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index fee9934f49..ebd22bb42c 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -80,17 +80,17 @@ protected:
 
 	// Opcodes
 	void opUnk1(ScriptOpCall &scriptOpCall);
-	void opUnk2(ScriptOpCall &scriptOpCall);
+	void opAddDialogChoice(ScriptOpCall &scriptOpCall);
 	void opUnk3(ScriptOpCall &scriptOpCall);
 	void opExecuteScript(ScriptOpCall &scriptOpCall); //op 4
-	void opActorSetSequenceID2(ScriptOpCall &scriptOpCall); //op 5
+	void opSetActorDirection(ScriptOpCall &scriptOpCall); //op 5
 	void opUnk6(ScriptOpCall &scriptOpCall);
-	void opUnk7(ScriptOpCall &scriptOpCall);
+	void opMoveObjectToScene(ScriptOpCall &scriptOpCall);
 	void opActorLoadSequence(ScriptOpCall &scriptOpCall);
 
-	void opUnkA(ScriptOpCall &scriptOpCall);
+	void opSetVariable(ScriptOpCall &scriptOpCall);
 	void opRunSpecialOpCode(ScriptOpCall &scriptOpCall); //op B
-	void opUnkCSoundRelatedMaybe(ScriptOpCall &scriptOpCall);
+	void opPlayOrStopSound(ScriptOpCall &scriptOpCall);
 	void opDelay(ScriptOpCall &scriptOpCall); //op D
 	void opUnkE(ScriptOpCall &scriptOpCall);
 	void opUnkF(ScriptOpCall &scriptOpCall);
@@ -114,7 +114,7 @@ protected:
 	void opPauseCurrentSpeechAndFetchNextDialog(ScriptOpCall &scriptOpCall);
 
 	bool evaluateExpression(ScriptOpCall &scriptOpCall);
-	void opCode_UnkA_setsProperty(ScriptOpCall &scriptOpCall);
+	void setVariable(ScriptOpCall &scriptOpCall);
 	void opCode_Unk7(ScriptOpCall &scriptOpCall);
 
 	void opCodeActorTalk(ScriptOpCall &scriptOpCall); // 0x22
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index e8f7df64c9..25c64db198 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -592,8 +592,8 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 			flickerActor->setFlag(ACTOR_FLAG_2000);
 			sequenceId = flickerActor->_sequenceID;
 //			playSoundFromTxtIndex(selectedDialogText->textIndex);
-			if (flickerActor->_sequenceID2 != -1) {
-				flickerActor->updateSequence(flickerActor->_sequenceID2 + 0x10);
+			if (flickerActor->_direction != -1) {
+				flickerActor->updateSequence(flickerActor->_direction + 0x10);
 			}
 			displayDialogAroundINI(0, auStack2438, selectedDialogText->textIndex);
 			flickerActor->updateSequence(sequenceId);
@@ -873,8 +873,8 @@ void Talk::talkFromIni(uint32 iniId, uint32 textIndex) {
 				_vm->getINI(0x2b1)->actor->updateSequence(2);
 			} else {
 				actor->setFlag(ACTOR_FLAG_2000);
-				if (actor->_sequenceID2 != -1) {
-					actor->updateSequence(actor->_sequenceID2 + 0x10);
+				if (actor->_direction != -1) {
+					actor->updateSequence(actor->_direction + 0x10);
 				}
 			}
 		} else {


Commit: 4790844720869e35c6ac9cb60e629b912f8f09ab
    https://github.com/scummvm/scummvm/commit/4790844720869e35c6ac9cb60e629b912f8f09ab
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Started adding support for other game variants. EU and DE

Changed paths:
    engines/dragons/bigfile.cpp
    engines/dragons/bigfile.h
    engines/dragons/detection.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/font.cpp
    engines/dragons/sound.cpp


diff --git a/engines/dragons/bigfile.cpp b/engines/dragons/bigfile.cpp
index 5c0f6e9f15..91492bd0db 100644
--- a/engines/dragons/bigfile.cpp
+++ b/engines/dragons/bigfile.cpp
@@ -20,610 +20,27 @@
  *
  */
 #include "dragons/bigfile.h"
+#include "dragons/dragons.h"
 
 namespace Dragons {
-typedef struct FileInfo {
-	const char filename[16];
-	uint32 offset;
-	uint32 size;
-} FileInfo;
 
-#define TOTAL_FILES 576
-//TODO add support for other game types. get data directly from DRAGON.EXE
-FileInfo fileInfo[TOTAL_FILES] = {
-	{"loadpic.tim", 0x0, 0x1F414},
-	{"fntfiles.dat", 0x1F800, 0x6E44},
-	{"tfont.map", 0x26800, 0xC6A},
-	{"tfont.chr", 0x27800, 0x16C0},
-	{"tfont1.map", 0x29000, 0xC6A},
-	{"tfont1.chr", 0x2A000, 0x16C0},
-	{"sfont.map", 0x2B800, 0xC6A},
-	{"sfont.chr", 0x2C800, 0x16C0},
-	{"boxfont.chr", 0x2E000, 0x4C0},
-	{"bag.scr", 0x2E800, 0xA2E4},
-	{"igfiles.dat", 0x39000, 0x29208},
-	{"dragon.flg", 0x62800, 0x24},
-	{"dragon.var", 0x63000, 0x1E},
-	{"dragon.ini", 0x63800, 0x6028},
-	{"dragon.img", 0x6A000, 0x441C},
-	{"dragon.opt", 0x6E800, 0x16A0},
-	{"dragon.ipt", 0x70000, 0x5D8},
-	{"dragon.rms", 0x70800, 0x63C},
-	{"dragon.obd", 0x71000, 0x1C9DC},
-	{"dragon.txt", 0x8E000, 0x4E8A4},
-	{"dragon.spt", 0xDD000, 0xD0},
-	{"musx.vh", 0xDD800, 0x2E20},
-	{"musx.vb", 0xE0800, 0x402A0},
-	{"glob.vh", 0x121000, 0xC20},
-	{"glob.vb", 0x122000, 0xBB90},
-	{"glob.vab", 0x12E000, 0xC7B0},
-	{"cursor.act", 0x13A800, 0x1863C},
-	{"invenicn.act", 0x153000, 0x3D3C},
-	{"shadow.act", 0x157000, 0x508},
-	{"flicker.act", 0x157800, 0x3CDF0},
-	{"flickert.act", 0x194800, 0x1A4A0},
-	{"flkg.act", 0x1AF000, 0x4D298},
-	{"flkspec.act", 0x1FC800, 0xE008},
-	{"credits.txt", 0x20B000, 0x249A},
-	{"titles.act", 0x20D800, 0x15214},
-	{"drag0000.txt", 0x223000, 0x1000},
-	{"drag0001.txt", 0x224000, 0x1000},
-	{"drag0002.txt", 0x225000, 0x1000},
-	{"drag0003.txt", 0x226000, 0x1000},
-	{"drag0004.txt", 0x227000, 0x1000},
-	{"drag0005.txt", 0x228000, 0x1000},
-	{"drag0006.txt", 0x229000, 0x1000},
-	{"drag0007.txt", 0x22A000, 0x1000},
-	{"drag0008.txt", 0x22B000, 0x1000},
-	{"drag0009.txt", 0x22C000, 0x1000},
-	{"drag0010.txt", 0x22D000, 0x1000},
-	{"drag0011.txt", 0x22E000, 0x1000},
-	{"drag0012.txt", 0x22F000, 0x1000},
-	{"drag0013.txt", 0x230000, 0x1000},
-	{"drag0014.txt", 0x231000, 0x1000},
-	{"drag0015.txt", 0x232000, 0x1000},
-	{"drag0016.txt", 0x233000, 0x1000},
-	{"drag0017.txt", 0x234000, 0x1000},
-	{"drag0018.txt", 0x235000, 0x1000},
-	{"drag0019.txt", 0x236000, 0x1000},
-	{"drag0020.txt", 0x237000, 0x1000},
-	{"drag0021.txt", 0x238000, 0x1000},
-	{"drag0022.txt", 0x239000, 0x1000},
-	{"drag0023.txt", 0x23A000, 0x1000},
-	{"drag0024.txt", 0x23B000, 0x1000},
-	{"drag0025.txt", 0x23C000, 0x1000},
-	{"drag0026.txt", 0x23D000, 0x1000},
-	{"drag0027.txt", 0x23E000, 0x1000},
-	{"drag0028.txt", 0x23F000, 0x1000},
-	{"drag0029.txt", 0x240000, 0x1000},
-	{"drag0030.txt", 0x241000, 0x1000},
-	{"drag0031.txt", 0x242000, 0x1000},
-	{"drag0032.txt", 0x243000, 0x1000},
-	{"drag0033.txt", 0x244000, 0x1000},
-	{"drag0034.txt", 0x245000, 0x1000},
-	{"drag0035.txt", 0x246000, 0x1000},
-	{"drag0036.txt", 0x247000, 0x1000},
-	{"drag0037.txt", 0x248000, 0x1000},
-	{"drag0038.txt", 0x249000, 0x1000},
-	{"drag0039.txt", 0x24A000, 0x1000},
-	{"drag0040.txt", 0x24B000, 0x1000},
-	{"drag0041.txt", 0x24C000, 0x1000},
-	{"drag0042.txt", 0x24D000, 0x1000},
-	{"drag0043.txt", 0x24E000, 0x1000},
-	{"drag0044.txt", 0x24F000, 0x1000},
-	{"drag0045.txt", 0x250000, 0x1000},
-	{"drag0046.txt", 0x251000, 0x1000},
-	{"drag0047.txt", 0x252000, 0x1000},
-	{"drag0048.txt", 0x253000, 0x1000},
-	{"drag0049.txt", 0x254000, 0x1000},
-	{"drag0050.txt", 0x255000, 0x1000},
-	{"drag0051.txt", 0x256000, 0x1000},
-	{"drag0052.txt", 0x257000, 0x1000},
-	{"drag0053.txt", 0x258000, 0x1000},
-	{"drag0054.txt", 0x259000, 0x1000},
-	{"drag0055.txt", 0x25A000, 0x1000},
-	{"drag0056.txt", 0x25B000, 0x1000},
-	{"drag0057.txt", 0x25C000, 0x1000},
-	{"drag0058.txt", 0x25D000, 0x1000},
-	{"drag0059.txt", 0x25E000, 0x1000},
-	{"drag0060.txt", 0x25F000, 0x1000},
-	{"drag0061.txt", 0x260000, 0x1000},
-	{"drag0062.txt", 0x261000, 0x1000},
-	{"drag0063.txt", 0x262000, 0x1000},
-	{"drag0064.txt", 0x263000, 0x1000},
-	{"drag0065.txt", 0x264000, 0x1000},
-	{"drag0066.txt", 0x265000, 0x1000},
-	{"drag0067.txt", 0x266000, 0x1000},
-	{"drag0068.txt", 0x267000, 0x1000},
-	{"drag0069.txt", 0x268000, 0x1000},
-	{"drag0070.txt", 0x269000, 0x1000},
-	{"drag0071.txt", 0x26A000, 0x1000},
-	{"drag0072.txt", 0x26B000, 0x1000},
-	{"drag0073.txt", 0x26C000, 0x1000},
-	{"drag0074.txt", 0x26D000, 0x1000},
-	{"drag0075.txt", 0x26E000, 0x1000},
-	{"drag0076.txt", 0x26F000, 0x1000},
-	{"drag0077.txt", 0x270000, 0x1000},
-	{"drag0078.txt", 0x271000, 0x1000},
-	{"drag0079.txt", 0x272000, 0x1000},
-	{"drag0080.txt", 0x273000, 0x1000},
-	{"dem1.msf", 0x274000, 0x128C0},
-	{"dem1.scr", 0x287000, 0x1934C},
-	{"dem11.act", 0x2A0800, 0x573FC},
-	{"dem1z15.msq", 0x2F8000, 0x3A03},
-	{"dem2.msf", 0x2FC000, 0x23C50},
-	{"dem2.scr", 0x320000, 0x160F4},
-	{"dem2z10.msq", 0x336800, 0x192B},
-	{"dem2z13.msq", 0x338800, 0x3D20},
-	{"demoz00.msq", 0x33C800, 0x1D7A},
-	{"demoz01.msq", 0x33E800, 0x136D},
-	{"demoz02.msq", 0x340000, 0x2F1D},
-	{"demoz03.msq", 0x343000, 0x246A},
-	{"demoz04.msq", 0x345800, 0xFA1},
-	{"demoz05.msq", 0x346800, 0x61C},
-	{"demoz06.msq", 0x347000, 0x3A4B},
-	{"demoz07.msq", 0x34B000, 0x3909},
-	{"demoz08.msq", 0x34F000, 0x25B8},
-	{"demoz09.msq", 0x351800, 0x673F},
-	{"demoz10.msq", 0x358000, 0x192B},
-	{"demoz11.msq", 0x35A000, 0x2A5A},
-	{"demoz12.msq", 0x35D000, 0xE7B},
-	{"demoz13.msq", 0x35E000, 0x3D20},
-	{"demoz14.msq", 0x362000, 0x1B9B},
-	{"demoz15.msq", 0x364000, 0x3A03},
-	{"demoz16.msq", 0x368000, 0x2B6B},
-	{"demoz17.msq", 0x36B000, 0x1D7A},
-	{"demoz18.msq", 0x36D000, 0x33FE},
-	{"demoz19.msq", 0x370800, 0x20D7},
-	{"demoz20.msq", 0x373000, 0x673F},
-	{"demoz21.msq", 0x379800, 0x2EA7},
-	{"demoz22.msq", 0x37C800, 0x286C},
-	{"demoz23.msq", 0x37F800, 0x246A},
-	{"demoz24.msq", 0x382000, 0x2463},
-	{"demoz25.msq", 0x384800, 0x245B},
-	{"demoz26.msq", 0x387000, 0x2AE},
-	{"demoz27.msq", 0x387800, 0xB6E},
-	{"demoz99.msq", 0x388800, 0x2EA7},
-	{"s00b.msf", 0x38B800, 0x1CD0},
-	{"s00b.scr", 0x38D800, 0xEF4},
-	{"s00b1.act", 0x38E800, 0x3DE24},
-	{"s00bz00.msq", 0x3CC800, 0x1D7A},
-	{"s00f.msf", 0x3CE800, 0x158D0},
-	{"s00f.scr", 0x3E4800, 0x138F4},
-	{"s00f1.act", 0x3F8800, 0x2CBB0},
-	{"s00f2.act", 0x425800, 0x16738},
-	{"s00f3.act", 0x43C000, 0x32C78},
-	{"s00f4.act", 0x46F000, 0xB78},
-	{"s00fz01.msq", 0x470000, 0x136D},
-	{"s00g.msf", 0x471800, 0x3840},
-	{"s00g.scr", 0x475800, 0x106F4},
-	{"s00g1.act", 0x486000, 0xAA50},
-	{"s00g2.act", 0x491000, 0x4DDC},
-	{"s00g3.act", 0x496000, 0x1944},
-	{"s00gz00.msq", 0x498000, 0x1D7A},
-	{"s00h.msf", 0x49A000, 0x4FB0},
-	{"s00h.scr", 0x49F000, 0x17AF4},
-	{"s00h1.act", 0x4B7000, 0x34D94},
-	{"s00h2.act", 0x4EC000, 0x1BF4C},
-	{"s00h3.act", 0x508000, 0xA92C},
-	{"s00h4.act", 0x513000, 0x3F58},
-	{"s00h5.act", 0x517000, 0xC850},
-	{"s00h6.act", 0x524000, 0x32174},
-	{"s00h7.act", 0x556800, 0x3BC4},
-	{"s00h8.act", 0x55A800, 0x2D78},
-	{"s00h9.act", 0x55D800, 0x28B0},
-	{"s00ha.act", 0x560800, 0x6F0},
-	{"s00hz10.msq", 0x561000, 0x192B},
-	{"s00i.msf", 0x563000, 0x4A20},
-	{"s00i.scr", 0x568000, 0x61EA0},
-	{"s00i1.act", 0x5CA000, 0x4708},
-	{"s00i2.act", 0x5CE800, 0x32B4},
-	{"s00i3.act", 0x5D2000, 0x2530},
-	{"s00i4.act", 0x5D4800, 0x222C},
-	{"s00iz06.msq", 0x5D7000, 0x3A4B},
-	{"s00j.msf", 0x5DB000, 0x1D2A0},
-	{"s00j.scr", 0x5F8800, 0x1934C},
-	{"s00j1.act", 0x612000, 0x50914},
-	{"s00j2.act", 0x663000, 0x43FCC},
-	{"s00jz15.msq", 0x6A7000, 0x3A03},
-	{"s00k.msf", 0x6AB000, 0x144F0},
-	{"s00k.scr", 0x6BF800, 0x200F4},
-	{"s00kz21.msq", 0x6E0000, 0x2EA7},
-	{"s00l.scr", 0x6E3000, 0xBDF4},
-	{"s00lz16.msq", 0x6EF000, 0x2B6B},
-	{"s00lz21.msq", 0x6F2000, 0x2EA7},
-	{"s01a.msf", 0x6F5000, 0x10590},
-	{"s01a.scr", 0x705800, 0x1B0F4},
-	{"s01a1.act", 0x721000, 0xFBF0},
-	{"s01a2.act", 0x731000, 0x591C},
-	{"s01az00.msq", 0x737000, 0x1D7A},
-	{"s01az08.msq", 0x739000, 0x25B8},
-	{"s01az17.msq", 0x73B800, 0x1D7A},
-	{"s01b.msf", 0x73D800, 0xCDF0},
-	{"s01b.scr", 0x74A800, 0x1DAF4},
-	{"s01b1.act", 0x768800, 0xAF78},
-	{"s01b2.act", 0x773800, 0xAA8},
-	{"s01bz00.msq", 0x774800, 0x1D7A},
-	{"s01c.msf", 0x776800, 0x7D70},
-	{"s01c.scr", 0x77E800, 0x1CCF4},
-	{"s01c1.act", 0x79B800, 0x76CBC},
-	{"s01c2.act", 0x812800, 0x4D0},
-	{"s01c3.act", 0x813000, 0xEE4},
-	{"s01cz01.msq", 0x814000, 0x136D},
-	{"s01d.msf", 0x815800, 0xE740},
-	{"s01d.scr", 0x824000, 0x5E0AC},
-	{"s01d1.act", 0x882800, 0x90A2C},
-	{"s01d2.act", 0x913800, 0x11AB4},
-	{"s01d3.act", 0x925800, 0x20FD8},
-	{"s01d4.act", 0x946800, 0x17D2C},
-	{"s01d5.act", 0x95E800, 0x1BAF4},
-	{"s01d7.act", 0x97A800, 0x6A974},
-	{"s01d8.act", 0x9E5800, 0x2852C},
-	{"s01d9.act", 0xA0E000, 0x958C},
-	{"s01d20.act", 0xA17800, 0x1B9D8},
-	{"s01d21.act", 0xA33800, 0x1D460},
-	{"s01d22.act", 0xA51000, 0x287C8},
-	{"s01d23.act", 0xA79800, 0x16734},
-	{"s01d24.act", 0xA90000, 0x138A8},
-	{"s01d25.act", 0xAA4000, 0x1A290},
-	{"s01da.act", 0xABE800, 0x702C},
-	{"s01dz00.msq", 0xAC6000, 0x1D7A},
-	{"s01dz17.msq", 0xAC8000, 0x1D7A},
-	{"s01e.scr", 0xACA000, 0x189F4},
-	{"s01e1.act", 0xAE3000, 0x7004},
-	{"s01ez00.msq", 0xAEA800, 0x1D7A},
-	{"s01f.msf", 0xAEC800, 0x11210},
-	{"s01f.scr", 0xAFE000, 0x195F4},
-	{"s01f1.act", 0xB17800, 0x33868},
-	{"s01f2.act", 0xB4B800, 0x734C},
-	{"s01fz00.msq", 0xB53000, 0x1D7A},
-	{"s01fz03.msq", 0xB55000, 0x246A},
-	{"s01fz06.msq", 0xB57800, 0x3A4B},
-	{"s01fz23.msq", 0xB5B800, 0x246A},
-	{"s01g.msf", 0xB5E000, 0x1E010},
-	{"s01g.scr", 0xB7C800, 0x1BBF4},
-	{"s01g1.act", 0xB98800, 0xD30},
-	{"s01g2.act", 0xB99800, 0x18794},
-	{"s01g3.act", 0xBB2000, 0x38FC},
-	{"s01g4.act", 0xBB6000, 0x39784},
-	{"s01g5.act", 0xBEF800, 0x20694},
-	{"s01g6.act", 0xC10000, 0x10A18},
-	{"s01g7.act", 0xC21000, 0x13AD4},
-	{"s01g8.act", 0xC35000, 0x1A750},
-	{"s01g9.act", 0xC4F800, 0x12958},
-	{"s01gz00.msq", 0xC62800, 0x1D7A},
-	{"s01gz01.msq", 0xC64800, 0x136D},
-	{"s01gz08.msq", 0xC66000, 0x25B8},
-	{"s01h.msf", 0xC68800, 0xFBF0},
-	{"s01h.scr", 0xC78800, 0x10CF4},
-	{"s01h1.act", 0xC89800, 0x5E5A8},
-	{"s01h2.act", 0xCE8000, 0x52FC0},
-	{"s01h3.act", 0xD3B000, 0x2CC68},
-	{"s01h4.act", 0xD68000, 0xC3CC},
-	{"s01h5.act", 0xD74800, 0x8D8},
-	{"s01h6.act", 0xD75800, 0x1A044},
-	{"s01hz00.msq", 0xD90000, 0x1D7A},
-	{"s01hz01.msq", 0xD92000, 0x136D},
-	{"s01i.msf", 0xD93800, 0x3840},
-	{"s01i.scr", 0xD97800, 0x25FDC},
-	{"s01i1.act", 0xDBD800, 0x19CF0},
-	{"s01i2.act", 0xDD7800, 0x514},
-	{"s01i3.act", 0xDD8000, 0x3BC8},
-	{"s01iz00.msq", 0xDDC000, 0x1D7A},
-	{"s01j.msf", 0xDDE000, 0xBBA0},
-	{"s01j.scr", 0xDEA000, 0x15BF4},
-	{"s01j0.act", 0xE00000, 0x245B8},
-	{"s01j1.act", 0xE24800, 0x8A34},
-	{"s01j2.act", 0xE2D800, 0x3C0A0},
-	{"s01j3.act", 0xE6A000, 0x2944},
-	{"s01jz00.msq", 0xE6D000, 0x1D7A},
-	{"s01k.msf", 0xE6F000, 0x12FA0},
-	{"s01k.scr", 0xE82000, 0x189F4},
-	{"s01k1.act", 0xE9B000, 0x4394},
-	{"s01k2.act", 0xE9F800, 0x75068},
-	{"s01k3.act", 0xF15000, 0x9A0},
-	{"s01kz00.msq", 0xF16000, 0x1D7A},
-	{"s01l.msf", 0xF18000, 0x9A70},
-	{"s01l.scr", 0xF22000, 0x12BF4},
-	{"s01l1.act", 0xF35000, 0x1CDC},
-	{"s01lz00.msq", 0xF37000, 0x1D7A},
-	{"s02a.msf", 0xF39000, 0x11240},
-	{"s02a.scr", 0xF4A800, 0x197F4},
-	{"s02a1.act", 0xF64000, 0x17110},
-	{"s02a2.act", 0xF7B800, 0x13EB4},
-	{"s02a3.act", 0xF8F800, 0x8D20},
-	{"s02a4.act", 0xF98800, 0x36F8},
-	{"s02a5.act", 0xF9C000, 0x22F58},
-	{"s02a6.act", 0xFBF000, 0xE3C},
-	{"s02az02.msq", 0xFC0000, 0x2F1D},
-	{"s02az11.msq", 0xFC3000, 0x2A5A},
-	{"s02b.msf", 0xFC6000, 0x170D0},
-	{"s02b.scr", 0xFDD800, 0x14EF4},
-	{"s02b1.act", 0xFF2800, 0x49F08},
-	{"s02b2.act", 0x103C800, 0xDE78},
-	{"s02b3.act", 0x104A800, 0x3768},
-	{"s02bz02.msq", 0x104E000, 0x2F1D},
-	{"s02bz11.msq", 0x1051000, 0x2A5A},
-	{"s02bz13.msq", 0x1054000, 0x3D20},
-	{"s02bz20.msq", 0x1058000, 0x673F},
-	{"s02c.msf", 0x105E800, 0x20240},
-	{"s02c.scr", 0x107F000, 0x277F4},
-	{"s02c1.act", 0x10A6800, 0x30448},
-	{"s02c2.act", 0x10D7000, 0x15828},
-	{"s02c3.act", 0x10ED000, 0x1708C},
-	{"s02c4.act", 0x1104800, 0x12D1C},
-	{"s02c5.act", 0x1117800, 0x39970},
-	{"s02c6.act", 0x1151800, 0x1B114},
-	{"s02c7.act", 0x116D000, 0x5F7C},
-	{"s02c8.act", 0x1173000, 0x82368},
-	{"s02c9.act", 0x11F5800, 0x3D02C},
-	{"s02c11.act", 0x1233000, 0x2A934},
-	{"s02c51.act", 0x125E000, 0x3004},
-	{"s02ca.act", 0x1261800, 0x7F0D0},
-	{"s02cb.act", 0x12E1000, 0x125A8},
-	{"s02cc.act", 0x12F3800, 0x4150},
-	{"s02cz11.msq", 0x12F8000, 0x2A5A},
-	{"s02cz12.msq", 0x12FB000, 0xE7B},
-	{"s02cz13.msq", 0x12FC000, 0x3D20},
-	{"s02cz20.msq", 0x1300000, 0x673F},
-	{"s02d.msf", 0x1306800, 0x21940},
-	{"s02d.scr", 0x1328800, 0x160F4},
-	{"s02d1.act", 0x133F000, 0x2E09C},
-	{"s02d2.act", 0x136D800, 0x26D74},
-	{"s02d3.act", 0x1394800, 0x14EA0},
-	{"s02d4.act", 0x13A9800, 0x2294},
-	{"s02d5.act", 0x13AC000, 0x4A48},
-	{"s02dz10.msq", 0x13B1000, 0x192B},
-	{"s02dz13.msq", 0x13B3000, 0x3D20},
-	{"s02e.msf", 0x13B7000, 0x5EB0},
-	{"s02e.scr", 0x13BD000, 0x107F4},
-	{"s02e1.act", 0x13CD800, 0x62BC8},
-	{"s02ez18.msq", 0x1430800, 0x33FE},
-	{"s03a.msf", 0x1434000, 0x12070},
-	{"s03a.scr", 0x1446800, 0x18BF4},
-	{"s03a1.act", 0x145F800, 0x49E0},
-	{"s03a2.act", 0x1464800, 0x3DF4},
-	{"s03a3.act", 0x1468800, 0x45774},
-	{"s03a4.act", 0x14AE000, 0x23D4},
-	{"s03a5.act", 0x14B0800, 0x13E64},
-	{"s03a6.act", 0x14C4800, 0x46BC},
-	{"s03az03.msq", 0x14C9000, 0x246A},
-	{"s03az06.msq", 0x14CB800, 0x3A4B},
-	{"s03az23.msq", 0x14CF800, 0x246A},
-	{"s04a.msf", 0x14D2000, 0x11D60},
-	{"s04a.scr", 0x14E4000, 0x12AF4},
-	{"s04a1.act", 0x14F7000, 0x2AC40},
-	{"s04a2.act", 0x1522000, 0x6544},
-	{"s04a3.act", 0x1528800, 0x46C8},
-	{"s04a4.act", 0x152D000, 0x2240},
-	{"s04az03.msq", 0x152F800, 0x246A},
-	{"s04az10.msq", 0x1532000, 0x192B},
-	{"s04az24.msq", 0x1534000, 0x2463},
-	{"s05a.msf", 0x1536800, 0x5D60},
-	{"s05a.scr", 0x153C800, 0x127F4},
-	{"s05a1.act", 0x154F000, 0x3E1CC},
-	{"s05az04.msq", 0x158D800, 0xFA1},
-	{"s05b.msf", 0x158E800, 0x28640},
-	{"s05b.scr", 0x15B7000, 0x2C3C4},
-	{"s05b0.act", 0x15E3800, 0x16474},
-	{"s05b1.act", 0x15FA000, 0x1F2F4},
-	{"s05b2.act", 0x1619800, 0x113E8},
-	{"s05b3.act", 0x162B000, 0x1D424},
-	{"s05b4.act", 0x1648800, 0x501C4},
-	{"s05b5.act", 0x1699000, 0x1F510},
-	{"s05b6.act", 0x16B8800, 0x8860},
-	{"s05bz05.msq", 0x16C1800, 0x61C},
-	{"s05bz06.msq", 0x16C2000, 0x3A4B},
-	{"s05bz07.msq", 0x16C6000, 0x3909},
-	{"s06a.msf", 0x16CA000, 0x1C750},
-	{"s06a.scr", 0x16E6800, 0x151F4},
-	{"s06a1.act", 0x16FC000, 0x24654},
-	{"s06a2.act", 0x1720800, 0x25D0},
-	{"s06az19.msq", 0x1723000, 0x20D7},
-	{"s06b.msf", 0x1725800, 0x1BF60},
-	{"s06b.scr", 0x1741800, 0x182F4},
-	{"s06b1.act", 0x175A000, 0x6CE68},
-	{"s06bz19.msq", 0x17C7000, 0x20D7},
-	{"s07a.msf", 0x17C9800, 0x15240},
-	{"s07a.scr", 0x17DF000, 0x1ACF4},
-	{"s07a1.act", 0x17FA000, 0xE5A0},
-	{"s07a2.act", 0x1808800, 0x425D0},
-	{"s07a3.act", 0x184B000, 0x18810},
-	{"s07az03.msq", 0x1864000, 0x246A},
-	{"s07az08.msq", 0x1866800, 0x25B8},
-	{"s07az25.msq", 0x1869000, 0x245B},
-	{"s07b.msf", 0x186B800, 0x14960},
-	{"s07b.scr", 0x1880800, 0x15CF4},
-	{"s07b1.act", 0x1896800, 0x419C8},
-	{"s07b2.act", 0x18D8800, 0x1A560},
-	{"s07b3.act", 0x18F3000, 0x76F4},
-	{"s07b4.act", 0x18FA800, 0x76C8},
-	{"s07bz03.msq", 0x1902000, 0x246A},
-	{"s07bz08.msq", 0x1904800, 0x25B8},
-	{"s07bz25.msq", 0x1907000, 0x245B},
-	{"s07c.scr", 0x1909800, 0x143F4},
-	{"s07c1.act", 0x191E000, 0xA25C},
-	{"s08a.msf", 0x1928800, 0xB9E0},
-	{"s08a.scr", 0x1934800, 0x322F4},
-	{"s08a1.act", 0x1967000, 0xA668},
-	{"s08a2.act", 0x1971800, 0x2C828},
-	{"s08a3.act", 0x199E800, 0x6CF0},
-	{"s08az03.msq", 0x19A5800, 0x246A},
-	{"s08az06.msq", 0x19A8000, 0x3A4B},
-	{"s08az23.msq", 0x19AC000, 0x246A},
-	{"s08b.scr", 0x19AE800, 0x399F4},
-	{"s08b1.act", 0x19E8800, 0x1F0A0},
-	{"s08bz03.msq", 0x1A08000, 0x246A},
-	{"s08bz06.msq", 0x1A0A800, 0x3A4B},
-	{"s08bz23.msq", 0x1A0E800, 0x246A},
-	{"s09a.msf", 0x1A11000, 0x14190},
-	{"s09a.scr", 0x1A25800, 0x1B4F4},
-	{"s09a1.act", 0x1A41000, 0x634B8},
-	{"s09az14.msq", 0x1AA4800, 0x1B9B},
-	{"s09b.msf", 0x1AA6800, 0x1F2E0},
-	{"s09b.scr", 0x1AC6000, 0x1B4F4},
-	{"s09b1.act", 0x1AE1800, 0x71B8},
-	{"s09b2.act", 0x1AE9000, 0x2299C},
-	{"s09b3.act", 0x1B0C000, 0x1B360},
-	{"s09b4.act", 0x1B27800, 0x14B64},
-	{"s09b5.act", 0x1B3C800, 0x5E4},
-	{"s09b6.act", 0x1B3D000, 0xAA78},
-	{"s09b7.act", 0x1B48000, 0x9B24},
-	{"s09bz14.msq", 0x1B52000, 0x1B9B},
-	{"s09bz15.msq", 0x1B54000, 0x3A03},
-	{"s09c.msf", 0x1B58000, 0x2D640},
-	{"s09c.scr", 0x1B85800, 0x200F4},
-	{"s09c1.act", 0x1BA6000, 0x10F68},
-	{"s09c2.act", 0x1BB7000, 0x25B1C},
-	{"s09c3.act", 0x1BDD000, 0x15DF0},
-	{"s09c4.act", 0x1BF3000, 0x11310},
-	{"s09c5.act", 0x1C04800, 0x14F8C},
-	{"s09c6.act", 0x1C19800, 0x3810},
-	{"s09cz16.msq", 0x1C1D800, 0x2B6B},
-	{"s09d.msf", 0x1C20800, 0xF2F0},
-	{"s09d.scr", 0x1C30000, 0x1C0F4},
-	{"s09d1.act", 0x1C4C800, 0x2FE78},
-	{"s09dz16.msq", 0x1C7C800, 0x2B6B},
-	{"s09e.msf", 0x1C7F800, 0xCBD0},
-	{"s09e.scr", 0x1C8C800, 0x152F4},
-	{"s09e1.act", 0x1CA2000, 0x32538},
-	{"s09e2.act", 0x1CD4800, 0xADE4},
-	{"s09ez16.msq", 0x1CDF800, 0x2B6B},
-	{"s09f.msf", 0x1CE2800, 0x29380},
-	{"s09f.scr", 0x1D0C000, 0x177F4},
-	{"s09f1.act", 0x1D23800, 0x13B84},
-	{"s09f2.act", 0x1D37800, 0x5106C},
-	{"s09f3.act", 0x1D89000, 0xBDB4},
-	{"s09fz16.msq", 0x1D95000, 0x2B6B},
-	{"s09h.msf", 0x1D98000, 0x20F20},
-	{"s09h.scr", 0x1DB9000, 0x1EDF4},
-	{"s09h1.act", 0x1DD8000, 0x11A80},
-	{"s09h2.act", 0x1DEA000, 0x23FC0},
-	{"s09h3.act", 0x1E0E000, 0x2CC88},
-	{"s09h4.act", 0x1E3B000, 0x54534},
-	{"s09h5.act", 0x1E8F800, 0x2BFF4},
-	{"s09hz16.msq", 0x1EBB800, 0x2B6B},
-	{"s09i.msf", 0x1EBE800, 0x3840},
-	{"s09i.scr", 0x1EC2800, 0x229C4},
-	{"s09i1.act", 0x1EE5800, 0x2DD38},
-	{"s09i2.act", 0x1F13800, 0x11A24},
-	{"s09i3.act", 0x1F25800, 0x2CCA8},
-	{"s09i4.act", 0x1F52800, 0x343C},
-	{"s09iz16.msq", 0x1F56000, 0x2B6B},
-	{"s10a.msf", 0x1F59000, 0x270F0},
-	{"s10a.scr", 0x1F80800, 0x406F4},
-	{"s10a1.act", 0x1FC1000, 0x1F82C},
-	{"s10a2.act", 0x1FE1000, 0x5D690},
-	{"s10a3.act", 0x203E800, 0x5E800},
-	{"s10a4.act", 0x209D000, 0xBAF8},
-	{"s10a5.act", 0x20A9000, 0x181C},
-	{"s10a6.act", 0x20AB000, 0x36404},
-	{"s10a7.act", 0x20E1800, 0x51C44},
-	{"s10az17.msq", 0x2133800, 0x1D7A},
-	{"s10az18.msq", 0x2135800, 0x33FE},
-	{"s10b.msf", 0x2139000, 0xD5E0},
-	{"s10b.scr", 0x2146800, 0x14DF4},
-	{"s10b1.act", 0x215B800, 0x27B20},
-	{"s10b2.act", 0x2183800, 0x2B900},
-	{"s10b3.act", 0x21AF800, 0x8D78},
-	{"s10b4.act", 0x21B8800, 0x1A78},
-	{"s10bz17.msq", 0x21BA800, 0x1D7A},
-	{"s10bz18.msq", 0x21BC800, 0x33FE},
-	{"s10d.msf", 0x21C0000, 0x16D20},
-	{"s10d.scr", 0x21D7000, 0x220F4},
-	{"s10d1.act", 0x21F9800, 0x4DFB8},
-	{"s11a.msf", 0x2247800, 0xD650},
-	{"s11a.scr", 0x2255000, 0x16CF4},
-	{"s11a1.act", 0x226C000, 0x13BB4},
-	{"s11a2.act", 0x2280000, 0x4794},
-	{"s11a3.act", 0x2284800, 0x186E0},
-	{"s11az03.msq", 0x229D000, 0x246A},
-	{"s11az17.msq", 0x229F800, 0x1D7A},
-	{"s12a.msf", 0x22A1800, 0x22B60},
-	{"s12a.scr", 0x22C4800, 0x21AAA},
-	{"s12a1.act", 0x22E6800, 0xFE24},
-	{"s12a2.act", 0x22F6800, 0x123D4},
-	{"s12a3.act", 0x2309000, 0x39510},
-	{"s12a4.act", 0x2342800, 0x48474},
-	{"s12a5.act", 0x238B000, 0x35D24},
-	{"s12a6.act", 0x23C1000, 0x12850},
-	{"s12az04.msq", 0x23D4000, 0xFA1},
-	{"s12az26.msq", 0x23D5000, 0x2AE},
-	{"s12b.msf", 0x23D5800, 0xA720},
-	{"s12b.scr", 0x23E0000, 0x117F4},
-	{"s12b1.act", 0x23F1800, 0x50C0},
-	{"s12b2.act", 0x23F7000, 0xAE2C},
-	{"s12b3.act", 0x2402000, 0x6A4},
-	{"s12c.scr", 0x2402800, 0x106F4},
-	{"s12c1.act", 0x2413000, 0xA21B4},
-	{"s13a.msf", 0x24B5800, 0x251A0},
-	{"s13a.scr", 0x24DB000, 0x117F4},
-	{"s13a0.act", 0x24EC800, 0x74C},
-	{"s13a1.act", 0x24ED000, 0x7784},
-	{"s13a2.act", 0x24F4800, 0x923A8},
-	{"s13a3.act", 0x2587000, 0x381F4},
-	{"s13a4.act", 0x25BF800, 0x6E140},
-	{"s13a5.act", 0x262E000, 0x4B18},
-	{"s13az20.msq", 0x2633000, 0x673F},
-	{"s13b.msf", 0x2639800, 0xAB70},
-	{"s13b.scr", 0x2644800, 0xEF4},
-	{"s13b1.act", 0x2645800, 0x7784},
-	{"s13b2.act", 0x264D000, 0x4FAB0},
-	{"s13bz20.msq", 0x269D000, 0x673F},
-	{"s14a.msf", 0x26A3800, 0xF310},
-	{"s14a.scr", 0x26B3000, 0x30A94},
-	{"s14a0.act", 0x26E4000, 0xD320},
-	{"s14a1.act", 0x26F1800, 0x13FC8},
-	{"s14a2.act", 0x2705800, 0xD5E30},
-	{"s14a3.act", 0x27DB800, 0x13274},
-	{"s14a5.act", 0x27EF000, 0x5A6A4},
-	{"s14a15.act", 0x2849800, 0x6D50},
-	{"s14a25.act", 0x2850800, 0x7B564},
-	{"s14az21.msq", 0x28CC000, 0x2EA7},
-	{"s14b.msf", 0x28CF000, 0x187E0},
-	{"s14b.scr", 0x28E7800, 0x106F4},
-	{"s14bz21.msq", 0x28F8000, 0x2EA7},
-	{"s14d.msf", 0x28FB000, 0xC0E0},
-	{"s14d.scr", 0x2907800, 0x23E34},
-	{"s14d1.act", 0x292B800, 0x2D11C},
-	{"s14dz10.msq", 0x2959000, 0x192B},
-	{"s14dz11.msq", 0x295B000, 0x2A5A},
-	{"s14e.msf", 0x295E000, 0x8600},
-	{"s14e.scr", 0x2966800, 0x106F4},
-	{"s14e1.act", 0x2977000, 0xAA00},
-	{"s14e2.act", 0x2982000, 0x1F848},
-	{"s14ez03.msq", 0x29A2000, 0x246A},
-	{"s14ez20.msq", 0x29A4800, 0x673F},
-	{"s14ez22.msq", 0x29AB000, 0x286C},
-	{"s14f.scr", 0x29AE000, 0x106F4},
-	{"s14f1.act", 0x29BE800, 0x27A2C},
-	{"s14fz22.msq", 0x29E6800, 0x286C},
-	{"s14fz27.msq", 0x29E9800, 0xB6E},
-	{"s14g.msf", 0x29EA800, 0x2500},
-	{"s14g.scr", 0x29ED000, 0x1C3C4},
-	{"s14g1.act", 0x2A09800, 0x140FC},
-	{"s14g2.act", 0x2A1E000, 0x943F8},
-	{"s14g3.act", 0x2AB2800, 0x1E9A8},
-	{"s14gz22.msq", 0x2AD1800, 0x286C},
-	{"s14h.scr", 0x2AD4800, 0x106F4},
-	{"s14hz22.msq", 0x2AE5000, 0x286C}
-};
-
-uint32 getResourceId(const char *filename) {
-	for (uint32 i = 0; i < TOTAL_FILES; i++) {
-		if (scumm_stricmp(fileInfo[i].filename, filename) == 0) {
+uint32 BigfileArchive::getResourceId(const char *filename) {
+	for (uint32 i = 0; i < DRAGONS_BIGFILE_TOTAL_FILES; i++) {
+		if (scumm_stricmp(_fileInfoTbl[i].filename.c_str(), filename) == 0) {
 			return i;
 		}
 	}
 
-	return TOTAL_FILES;
+	return DRAGONS_BIGFILE_TOTAL_FILES;
 }
 
-BigfileArchive::BigfileArchive(const char *filename, Common::Language language) :_fd(0) {
-	_language = language;
+BigfileArchive::BigfileArchive(DragonsEngine *vm, const char *filename) :_vm(vm), _fd(0) {
 	_fd = new Common::File();
-	if (!_fd->open(filename))
+	if (!_fd->open(filename)) {
 		error("BigfileArchive::BigfileArchive() Could not open %s", filename);
+	}
+
+	loadFileInfoTbl();
 }
 
 BigfileArchive::~BigfileArchive() {
@@ -631,14 +48,33 @@ BigfileArchive::~BigfileArchive() {
 	delete _fd;
 }
 
+void BigfileArchive::loadFileInfoTbl() {
+	char filename[16];
+	Common::File fd;
+	if (!fd.open("dragon.exe")) {
+		error("Failed to open dragon.exe");
+	}
+
+	fd.seek(_vm->getBigFileInfoTblFromDragonEXE());
+
+	for (int i = 0; i < DRAGONS_BIGFILE_TOTAL_FILES; i++) {
+		fd.read(filename, 16);
+		filename[15] = 0;
+		_fileInfoTbl[i].filename = filename;
+		_fileInfoTbl[i].offset = fd.readUint32LE() * 2048;
+		_fileInfoTbl[i].size = fd.readUint32LE();
+		fd.skip(4);
+	}
+}
+
 byte *BigfileArchive::load(const char *filename, uint32 &dataSize) {
 	uint32 id = getResourceId(filename);
-	if (id >= TOTAL_FILES) {
+	if (id >= DRAGONS_BIGFILE_TOTAL_FILES) {
 		error("Invalid resourceID for input filename: %s", filename);
 	}
 
-	dataSize = fileInfo[id].size;
-	_fd->seek(fileInfo[id].offset);
+	dataSize = _fileInfoTbl[id].size;
+	_fd->seek(_fileInfoTbl[id].offset);
 	byte *buf = (byte *)malloc(dataSize);
 	if (!buf) {
 		error("Failed to malloc %d bytes for '%s'", dataSize, filename);
@@ -649,7 +85,7 @@ byte *BigfileArchive::load(const char *filename, uint32 &dataSize) {
 
 bool BigfileArchive::doesFileExist(const char *filename) {
 	uint32 id = getResourceId(filename);
-	return (id < TOTAL_FILES);
+	return (id < DRAGONS_BIGFILE_TOTAL_FILES);
 }
 
 
diff --git a/engines/dragons/bigfile.h b/engines/dragons/bigfile.h
index cea46fb81d..867bcc876c 100644
--- a/engines/dragons/bigfile.h
+++ b/engines/dragons/bigfile.h
@@ -23,21 +23,40 @@
 #define DRAGONS_BIGFILE_H
 
 #include "common/file.h"
-#include "common/language.h"
 
 namespace Dragons {
 
+class DragonsEngine;
+
+#define DRAGONS_BIGFILE_TOTAL_FILES 576
+
+struct FileInfo {
+	Common::String filename;
+	uint32 offset;
+	uint32 size;
+	FileInfo() {
+		offset = 0;
+		size = 0;
+		filename = "";
+	}
+};
+
 class BigfileArchive {
 private:
-	Common::Language _language;
+	DragonsEngine *_vm;
 	Common::File *_fd;
+	FileInfo _fileInfoTbl[DRAGONS_BIGFILE_TOTAL_FILES];
 
 public:
-	BigfileArchive(const char *filename, Common::Language language);
+	BigfileArchive(DragonsEngine *vm, const char *filename);
 	virtual ~BigfileArchive();
 
 	byte *load(const char *filename, uint32 &dataSize);
 	bool doesFileExist(const char *filename);
+
+private:
+	void loadFileInfoTbl();
+	uint32 getResourceId(const char *filename);
 };
 
 } // End of namespace dragons
diff --git a/engines/dragons/detection.cpp b/engines/dragons/detection.cpp
index 6b44f15e5e..3ec5e2c30b 100644
--- a/engines/dragons/detection.cpp
+++ b/engines/dragons/detection.cpp
@@ -47,12 +47,23 @@ static const DragonsGameDescription gameDescriptions[] = {
 			},
 			kGameIdDragons
 	},
-
 	{
 			{
 					"dragons",
 					0,
-					AD_ENTRY1s("bigfile.dat", "234234234234", 29779968),
+					AD_ENTRY1s("bigfile.dat", "02c26712bee57266f28235fdc0207725", 44992512),
+					Common::EN_GRB,
+					Common::kPlatformPSX,
+					ADGF_DROPPLATFORM,
+					GUIO0()
+			},
+			kGameIdDragons
+	},
+	{
+			{
+					"dragons",
+					0,
+					AD_ENTRY1s("bigfile.dat", "9854fed0d2b48522a62973e99b52a0be", 45099008),
 					Common::DE_DEU,
 					Common::kPlatformPSX,
 					ADGF_DROPPLATFORM,
@@ -170,7 +181,7 @@ bool DragonsMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADG
 	if (gd) {
 		switch (gd->gameId) {
 		case Dragons::kGameIdDragons:
-			*engine = new Dragons::DragonsEngine(syst);
+			*engine = new Dragons::DragonsEngine(syst, desc);
 			break;
 		default:
 			error("Unknown game id");
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 9c593dfd8c..1cb59d781f 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -58,7 +58,8 @@ DragonsEngine *getEngine() {
 	return _engine;
 }
 
-DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
+DragonsEngine::DragonsEngine(OSystem *syst, const ADGameDescription *desc) : Engine(syst) {
+	_language = desc->language;
 	_bigfileArchive = NULL;
 	_dragonRMS = NULL;
 	_backgroundResourceLoader = NULL;
@@ -191,7 +192,7 @@ void DragonsEngine::updateEvents() {
 
 Common::Error DragonsEngine::run() {
 	_screen = new Screen();
-	_bigfileArchive = new BigfileArchive("bigfile.dat", Common::EN_ANY);
+	_bigfileArchive = new BigfileArchive(this, "bigfile.dat");
 	_talk = new Talk(this, _bigfileArchive);
 	_dragonFLG = new DragonFLG(_bigfileArchive);
 	_dragonImg = new DragonImg(_bigfileArchive);
@@ -1423,6 +1424,37 @@ void DragonsEngine::updatePaletteCycling() {
 	}
 }
 
+uint32 DragonsEngine::getFontOffsetFromDragonEXE() {
+	switch (_language) {
+	case Common::EN_GRB : return 0x4b4fc;
+	case Common::EN_USA : return 0x4a144;
+	case Common::DE_DEU : return 0x4af5c;
+	//TODO FR
+	default : error("Unable to get font offset from dragon.exe for %s", getLanguageCode(_language));
+	}
+}
+
+uint32 DragonsEngine::getSpeechTblOffsetFromDragonEXE() {
+	switch (_language) {
+	case Common::EN_GRB : return 0x4f4f4;
+	case Common::EN_USA : return 0x4e138;
+	case Common::DE_DEU : return 0x4f0a4;
+	//TODO FR
+	default : error("Unable to get speech table offset from dragon.exe for %s", getLanguageCode(_language));
+	}
+}
+
+uint32 DragonsEngine::getBigFileInfoTblFromDragonEXE() {
+	switch (_language) {
+	case Common::EN_USA : return 0x4a238;
+	case Common::EN_GRB : return 0x4b5f4;
+	case Common::DE_DEU : return 0x4b054;
+	//TODO FR
+	default :
+		error("Unable to get speech table offset from dragon.exe for %s", getLanguageCode(_language));
+	}
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 07393a8acb..6e4464e1ba 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -154,6 +154,7 @@ public:
 	uint16 _sceneId1; //TODO wire this up. I think it might be where to restore save game from?
 
 private:
+	Common::Language _language;
 	BigfileArchive *_bigfileArchive;
 	DragonFLG *_dragonFLG;
 	DragonVAR *_dragonVAR;
@@ -199,7 +200,7 @@ private:
 protected:
 	virtual bool hasFeature(EngineFeature f) const;
 public:
-	DragonsEngine(OSystem *syst);
+	DragonsEngine(OSystem *syst, const ADGameDescription *desc);
 	~DragonsEngine();
 
 	void updateEvents();
@@ -279,6 +280,11 @@ public:
 	uint16 getRand(uint16 max);
 
 	void setupPalette1();
+
+	//TODO this logic should probably go in its own class.
+	uint32 getBigFileInfoTblFromDragonEXE();
+	uint32 getFontOffsetFromDragonEXE();
+	uint32 getSpeechTblOffsetFromDragonEXE();
 private:
 	bool savegame(const char *filename, const char *description);
 	bool loadgame(const char *filename);
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 418caf904d..577fd50704 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -141,7 +141,7 @@ Font *FontManager::loadFont(uint16 index, Common::SeekableReadStream &stream) {
 	if (!fd.open("dragon.exe")) {
 		error("Failed to open dragon.exe");
 	}
-	fd.seek(0x4a144); //TODO handle other game variants
+	fd.seek(_vm->getFontOffsetFromDragonEXE());
 	fd.skip((index * 2)  * 28);
 
 //	fd->read(info.filename, 16);
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index d2fae18509..36d1b17ee8 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -111,9 +111,9 @@ bool SoundManager::getSpeechLocation(uint32 talkId, struct SpeechLocation *locat
 	if (!fd->open("dragon.exe")) {
 		error("Failed to open dragon.exe");
 	}
-	fd->seek(0x4e138);
+	fd->seek(_vm->getSpeechTblOffsetFromDragonEXE());
 	bool foundId = false;
-	for (int i = 0; i < 2272; i++) {
+	for (int i = 0; i < 2272; i++) { //TODO check that the number of speech audio tracks is the same across game variants
 		uint32 id = (fd->readUint32LE() & 0xffffff);
 		fd->seek(-1, SEEK_CUR);
 		int8 startOffset = fd->readSByte();


Commit: f848b87572cc8cf9b267380801215083ca00512b
    https://github.com/scummvm/scummvm/commit/f848b87572cc8cf9b267380801215083ca00512b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed cutscene palettes in other variants. Started on FR support

Changed paths:
    engines/dragons/cutscene.cpp
    engines/dragons/detection.cpp
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index a6d1cce96d..700171d9b6 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -646,7 +646,7 @@ void CutScene::loadPalettes() {
 	if (!fd.open("dragon.exe")) {
 		error("Failed to open dragon.exe");
 	}
-	fd.seek(0x5336c); //TODO handle other game variants
+	fd.seek(_vm->getCutscenePaletteOffsetFromDragonEXE());
 
 	_palettes = (byte *)malloc(256 * 2 * 4);
 	fd.read(_palettes, 256 * 2 * 4);
diff --git a/engines/dragons/detection.cpp b/engines/dragons/detection.cpp
index 3ec5e2c30b..71cebbc0b2 100644
--- a/engines/dragons/detection.cpp
+++ b/engines/dragons/detection.cpp
@@ -71,6 +71,18 @@ static const DragonsGameDescription gameDescriptions[] = {
 			},
 			kGameIdDragons
 	},
+	{
+			{
+					"dragons",
+					0,
+					AD_ENTRY1s("bigfile.dat", "9854fed0d2b48522a62973e99b52a0be", 45107200),
+					Common::FR_FRA,
+					Common::kPlatformPSX,
+					ADGF_DROPPLATFORM,
+					GUIO0()
+			},
+			kGameIdDragons
+	},
 
 	{ AD_TABLE_END_MARKER, 0 }
 };
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 1cb59d781f..bf3aab54ac 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1426,20 +1426,20 @@ void DragonsEngine::updatePaletteCycling() {
 
 uint32 DragonsEngine::getFontOffsetFromDragonEXE() {
 	switch (_language) {
-	case Common::EN_GRB : return 0x4b4fc;
 	case Common::EN_USA : return 0x4a144;
+	case Common::EN_GRB : return 0x4b4fc;
 	case Common::DE_DEU : return 0x4af5c;
-	//TODO FR
+	case Common::FR_FRA : return 0x4b158;
 	default : error("Unable to get font offset from dragon.exe for %s", getLanguageCode(_language));
 	}
 }
 
 uint32 DragonsEngine::getSpeechTblOffsetFromDragonEXE() {
 	switch (_language) {
-	case Common::EN_GRB : return 0x4f4f4;
 	case Common::EN_USA : return 0x4e138;
+	case Common::EN_GRB : return 0x4f4f4;
 	case Common::DE_DEU : return 0x4f0a4;
-	//TODO FR
+	case Common::FR_FRA : return 0x4f2a0;
 	default : error("Unable to get speech table offset from dragon.exe for %s", getLanguageCode(_language));
 	}
 }
@@ -1449,7 +1449,18 @@ uint32 DragonsEngine::getBigFileInfoTblFromDragonEXE() {
 	case Common::EN_USA : return 0x4a238;
 	case Common::EN_GRB : return 0x4b5f4;
 	case Common::DE_DEU : return 0x4b054;
-	//TODO FR
+	case Common::FR_FRA : return 0x4b250;
+	default :
+		error("Unable to get speech table offset from dragon.exe for %s", getLanguageCode(_language));
+	}
+}
+
+uint32 DragonsEngine::getCutscenePaletteOffsetFromDragonEXE() {
+	switch (_language) {
+	case Common::EN_USA : return 0x5336c;
+	case Common::EN_GRB : return 0x54628;
+	case Common::DE_DEU : return 0x541d8;
+	case Common::FR_FRA : return 0x543d4;
 	default :
 		error("Unable to get speech table offset from dragon.exe for %s", getLanguageCode(_language));
 	}
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 6e4464e1ba..9150023d89 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -285,6 +285,7 @@ public:
 	uint32 getBigFileInfoTblFromDragonEXE();
 	uint32 getFontOffsetFromDragonEXE();
 	uint32 getSpeechTblOffsetFromDragonEXE();
+	uint32 getCutscenePaletteOffsetFromDragonEXE();
 private:
 	bool savegame(const char *filename, const char *description);
 	bool loadgame(const char *filename);


Commit: bda2b9ae5a9d6170ea3e945e75962958c7464518
    https://github.com/scummvm/scummvm/commit/bda2b9ae5a9d6170ea3e945e75962958c7464518
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Adding language support for flicker's default response text

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index bf3aab54ac..b32441ff7b 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1466,6 +1466,17 @@ uint32 DragonsEngine::getCutscenePaletteOffsetFromDragonEXE() {
 	}
 }
 
+uint32 DragonsEngine::defaultResponseOffsetFromDragonEXE() {
+	switch (_language) {
+	case Common::EN_USA : return 0x541b0;
+	case Common::EN_GRB : return 0x55470;
+	case Common::DE_DEU : return 0x55020;
+	case Common::FR_FRA : return 0x5521c;
+	default :
+		error("Unable to get speech table offset from dragon.exe for %s", getLanguageCode(_language));
+	}
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 9150023d89..2dff40b982 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -286,6 +286,7 @@ public:
 	uint32 getFontOffsetFromDragonEXE();
 	uint32 getSpeechTblOffsetFromDragonEXE();
 	uint32 getCutscenePaletteOffsetFromDragonEXE();
+	uint32 defaultResponseOffsetFromDragonEXE();
 private:
 	bool savegame(const char *filename, const char *description);
 	bool loadgame(const char *filename);
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 25c64db198..ad9e210c74 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -928,8 +928,8 @@ uint32 Talk::getDefaultResponseTextIndex() {
 	return _defaultResponseTbl[(_vm->_cursor->_data_800728b0_cursor_seqID - 1) * 9 + rand];
 }
 
-uint32 extractTextIndex(Common::File *fd, uint16 offset) {
-	fd->seek(0x541b0 + offset * 4);
+uint32 Talk::extractTextIndex(Common::File *fd, uint16 offset) {
+	fd->seek(_vm->defaultResponseOffsetFromDragonEXE() + offset * 4);
 	return fd->readUint32LE();
 }
 
@@ -939,6 +939,7 @@ void Talk::initDefaultResponseTable() {
 		error("Failed to open dragon.exe");
 	}
 
+	//TODO need to check that other languages follow this pattern
 	_defaultResponseTbl[0] = extractTextIndex(fd, 19);
 	_defaultResponseTbl[1] = extractTextIndex(fd, 20);
 	_defaultResponseTbl[2] = extractTextIndex(fd, 21);
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index d41ebec08d..2852a06d60 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -107,6 +107,7 @@ private:
 	uint16 FindLastPositionOf5cChar(uint16 *text);
 	uint32 FUN_80031c28(uint16 *srcText, uint16 *destText, uint32 cutLength, uint16 param_4);
 
+	uint32 extractTextIndex(Common::File *fd, uint16 offset);
 };
 
 } // End of namespace Dragons


Commit: ccea9afda322d180d7d84b547a4bccca47f51808
    https://github.com/scummvm/scummvm/commit/ccea9afda322d180d7d84b547a4bccca47f51808
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Renamed a bunch of script opcodes

Changed paths:
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h


diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index c37a8d7fe7..ab6c98ffca 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -108,35 +108,35 @@ void ScriptOpcodes::initOpcodes() {
 	OPCODE(1, opUnk1);
 	OPCODE(2, opAddDialogChoice);
 	OPCODE(3, opUnk3); //dialog related
-	OPCODE(4,  opExecuteScript);
+	OPCODE(4, opExecuteScript);
 	OPCODE(5, opSetActorDirection);
-	OPCODE(6,  opUnk6);
+	OPCODE(6, opUnk6);
 	OPCODE(7, opMoveObjectToScene);
-	OPCODE(8,  opActorLoadSequence);
+	OPCODE(8, opActorLoadSequence);
 
 	OPCODE(0xA, opSetVariable);
 	OPCODE(0xB, opRunSpecialOpCode);
 	OPCODE(0xC, opPlayOrStopSound);
 	OPCODE(0xD, opDelay);
-	OPCODE(0xE, opUnkE);
-	OPCODE(0xF, opUnkF);
-	OPCODE(0x10, opUnk10);
+	OPCODE(0xE, opMoveActorToPoint);
+	OPCODE(0xF, opMoveActorToXY);
+	OPCODE(0x10, opMoveActorToObject);
 	OPCODE(0x11, opUnk11FlickerTalk);
-	OPCODE(0x12, opUnk12LoadScene);
-	OPCODE(0x13, opUnk13PropertiesRelated);
-	OPCODE(0x14, opUnk14PropertiesRelated);
-	OPCODE(0x15, opUnk15PropertiesRelated);
+	OPCODE(0x12, opLoadScene);
+	OPCODE(0x13, opIfStatement);
+	OPCODE(0x14, opIfElseStatement);
+	OPCODE(0x15, opUnk15PropertiesRelated); //Is this used?
 	OPCODE(0x16, opUnk16);
-	OPCODE(0x17, opUnk17);
-	OPCODE(0x18, opUnk18);
-	OPCODE(0x19, opUnk19);
+	OPCODE(0x17, opWaitForActorSequenceToFinish);
+	OPCODE(0x18, opDialogAtPoint);
+	OPCODE(0x19, opExecuteObjectSceneScript);
 	OPCODE(0x1A, opUpdatePaletteCycling);
-	OPCODE(0x1B, opUnk1B);
+	OPCODE(0x1B, opWaitForActorToFinishWalking);
 	OPCODE(0x1C, opSetActorFlag0x1000);
-	OPCODE(0x1D, opUnk1DClearActorFlag0x400);
-	OPCODE(0x1E, opUnk1ESetActorFlag0x400);
+	OPCODE(0x1D, opShowActor);
+	OPCODE(0x1E, opHideActor);
 	OPCODE(0x1F, opPlayMusic);
-	OPCODE(0x20, opUnk20);
+	OPCODE(0x20, opPreLoadSceneData);
 	OPCODE(0x21, opPauseCurrentSpeechAndFetchNextDialog);
 	OPCODE(0x22, opCodeActorTalk);
 }
@@ -481,7 +481,7 @@ void ScriptOpcodes::opPlayMusic(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opIfStatement(ScriptOpCall &scriptOpCall) {
 	if (evaluateExpression(scriptOpCall)) {
 		scriptOpCall._code += 4;
 	} else {
@@ -489,7 +489,7 @@ void ScriptOpcodes::opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-void ScriptOpcodes::opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opIfElseStatement(ScriptOpCall &scriptOpCall) {
 	if (evaluateExpression(scriptOpCall)) {
 		ScriptOpCall localScriptOpCall(scriptOpCall._code + 4, READ_LE_UINT16(scriptOpCall._code));
 		localScriptOpCall._field8 = scriptOpCall._field8;
@@ -527,14 +527,14 @@ void ScriptOpcodes::opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall) {
 	scriptOpCall._code += 4 + READ_LE_UINT16(scriptOpCall._code);
 }
 
-void ScriptOpcodes::opUnk20(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opPreLoadSceneData(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
-	ARG_INT16(field2);
+	ARG_INT16(sceneId);
 
 	_vm->_sound->PauseCDMusic();
 	_vm->_data_800633fc = 1;
 
-	if (field2 >= 2) {
+	if (sceneId >= 2) {
 		//TODO do we need this? It looks like it is pre-loading the next scene's data.
 	}
 }
@@ -680,40 +680,40 @@ void ScriptOpcodes::opDelay(ScriptOpCall &scriptOpCall) {
 	_vm->waitForFrames((uint16)delay);
 }
 
-void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opMoveActorToPoint(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
-	ARG_INT16(field2);
-	ARG_INT16(field4);
-	ARG_INT16(field6);
-	ARG_INT16(field8);
+	ARG_INT16(iniId);
+	ARG_INT16(walkSpeed);
+	ARG_INT16(sequenceId);
+	ARG_INT16(pointIndex);
 
 	if (scriptOpCall._field8 != 0) {
 		return;
 	}
 
-	int32 s3 = 0;
-	DragonINI *ini = _vm->getINI(field2 - 1);
+	bool waitForWalkToComplete = true;
+	DragonINI *ini = _vm->getINI(iniId - 1);
 
-	if (field6 & 0x8000) {
-		s3 = 0 > (field6 ^ 0xffff) ? 1 : 0;
+	if (sequenceId & 0x8000) {
+		waitForWalkToComplete = sequenceId == -1;
 	}
-	Common::Point point = _vm->_scene->getPoint(field8);
+	Common::Point point = _vm->_scene->getPoint(pointIndex);
 
-	if (field4 != -1) {
-		if (field6 != -1) {
+	if (walkSpeed != -1) {
+		if (sequenceId != -1) {
 			if (!(field0 & 0x8000)) {
 				assert(ini->actor);
 				ini->actor->_flags |= ACTOR_FLAG_800;
-				ini->actor->updateSequence(field6 & 0x7fff);
+				ini->actor->updateSequence(sequenceId & 0x7fff);
 			}
-			ini->actor->_walkSpeed = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
+			ini->actor->_walkSpeed = walkSpeed & 0x8000 ? (walkSpeed & 0x7fff) << 7 : walkSpeed << 0x10;
 		}
 
 		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
 		ini->actor->startWalk(point.x, point.y, isFlicker ? 0 : 1);
 
-		if (s3 == 0) {
-			while (ini->actor->_flags & ACTOR_FLAG_10) {
+		if (waitForWalkToComplete) {
+			while (ini->actor->isFlagSet(ACTOR_FLAG_10)) {
 				_vm->waitForFrames(1);
 			}
 		}
@@ -727,68 +727,68 @@ void ScriptOpcodes::opUnkE(ScriptOpCall &scriptOpCall) {
 		ini->y = point.y;
 		ini->actor->_y_pos = point.y;
 
-		if (field4 != field6) {
-			ini->actor->_walkSpeed = field4;
-			ini->actor->updateSequence(field6 & 0x7fff);
+		if (sequenceId != -1) {
+			ini->actor->_walkSpeed = -1;
+			ini->actor->updateSequence(sequenceId & 0x7fff);
 		}
 	}
 }
 
-void ScriptOpcodes::opUnkF(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opMoveActorToXY(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
-	ARG_INT16(field2);
-	ARG_INT16(field4);
-	ARG_INT16(field6);
-	ARG_INT16(field8);
-	ARG_INT16(fieldA);
+	ARG_INT16(iniId);
+	ARG_INT16(walkSpeed);
+	ARG_INT16(sequenceId);
+	ARG_INT16(destX);
+	ARG_INT16(destY);
 
 	if (scriptOpCall._field8 != 0) {
 		return;
 	}
 
-	int32 s3 = 0;
-	DragonINI *ini = _vm->getINI(field2 - 1);
+	bool waitForWalkToComplete = true;
+	DragonINI *ini = _vm->getINI(iniId - 1);
 
-	if (field6 & 0x8000) {
-		s3 = 0 > (field6 ^ 0xffff) ? 1 : 0;
+	if (sequenceId & 0x8000) {
+		waitForWalkToComplete = sequenceId == -1;
 	}
 
-	if (field4 != -1) {
-		if (field6 != -1) {
+	if (walkSpeed != -1) {
+		if (sequenceId != -1) {
 			if (!(field0 & 0x8000)) {
 				assert(ini->actor);
-				ini->actor->_flags |= ACTOR_FLAG_800;
-				ini->actor->updateSequence(field6 & 0x7fff);
+				ini->actor->setFlag(ACTOR_FLAG_800);
+				ini->actor->updateSequence(sequenceId & 0x7fff);
 			}
-			ini->actor->_walkSpeed = field4 & 0x8000 ? (field4 & 0x7fff) << 7 : field4 << 0x10;
+			ini->actor->_walkSpeed = walkSpeed & 0x8000 ? (walkSpeed & 0x7fff) << 7 : walkSpeed << 0x10;
 		}
 		bool isFlicker = _vm->_dragonINIResource->isFlicker(ini);
-		ini->actor->startWalk(field8, fieldA, isFlicker ? 0 : 1);
+		ini->actor->startWalk(destX, destY, isFlicker ? 0 : 1);
 
-		if (s3 == 0) {
-			while (ini->actor->_flags & ACTOR_FLAG_10) {
+		if (waitForWalkToComplete) {
+			while (ini->actor->isFlagSet(ACTOR_FLAG_10)) {
 				_vm->waitForFrames(1);
 			}
 		}
-		ini->x = field8;
-		ini->y = fieldA;
+		ini->x = destX;
+		ini->y = destY;
 		ini->actor->_flags &= ~ACTOR_FLAG_800;
 
 	} else {
 		assert(ini->actor);
-		ini->x = field8;
-		ini->actor->_x_pos = field8;
-		ini->y = fieldA;
-		ini->actor->_y_pos = fieldA;
-
-		if (field4 != field6) {
-			ini->actor->_walkSpeed = field4;
-			ini->actor->updateSequence(field6 & 0x7fff);
+		ini->x = destX;
+		ini->actor->_x_pos = destX;
+		ini->y = destY;
+		ini->actor->_y_pos = destY;
+
+		if (sequenceId != -1) {
+			ini->actor->_walkSpeed = -1;
+			ini->actor->updateSequence(sequenceId & 0x7fff);
 		}
 	}
 }
 
-void ScriptOpcodes::opUnk10(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opMoveActorToObject(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
 	ARG_INT16(field4);
@@ -898,7 +898,7 @@ void ScriptOpcodes::opUnk11FlickerTalk(ScriptOpCall &scriptOpCall) {
 	_vm->_talk->talkFromIni(iniId, textIndex);
 }
 
-void ScriptOpcodes::opUnk12LoadScene(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opLoadScene(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(newSceneID);
 	ARG_INT16(cameraPointID);
@@ -1124,7 +1124,7 @@ void ScriptOpcodes::opUnk16(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-void ScriptOpcodes::opUnk17(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opWaitForActorSequenceToFinish(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(iniId);
 
@@ -1138,7 +1138,7 @@ void ScriptOpcodes::opUnk17(ScriptOpCall &scriptOpCall) {
 }
 
 
-void ScriptOpcodes::opUnk18(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opDialogAtPoint(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_UINT32(field2);
 	ARG_INT16(x);
@@ -1163,7 +1163,7 @@ void ScriptOpcodes::opUnk18(ScriptOpCall &scriptOpCall) {
 	_vm->_talk->displayDialogAroundPoint(dialog, x, y, fieldA, 1, field2);
 }
 
-void ScriptOpcodes::opUnk19(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opExecuteObjectSceneScript(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(size);
 
@@ -1196,7 +1196,7 @@ void ScriptOpcodes::opUpdatePaletteCycling(ScriptOpCall &scriptOpCall) {
 	_vm->_paletteCyclingTbl[index].updateCounter = 0;
 }
 
-void ScriptOpcodes::opUnk1B(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opWaitForActorToFinishWalking(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(iniId);
 
@@ -1212,7 +1212,7 @@ void ScriptOpcodes::opUnk1B(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-void ScriptOpcodes::opUnk1DClearActorFlag0x400(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opShowActor(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(iniId);
 
@@ -1224,7 +1224,7 @@ void ScriptOpcodes::opUnk1DClearActorFlag0x400(ScriptOpCall &scriptOpCall) {
 	ini->actor->setFlag(ACTOR_FLAG_400);
 }
 
-void ScriptOpcodes::opUnk1ESetActorFlag0x400(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opHideActor(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(iniId);
 
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index ebd22bb42c..a225d75987 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -92,25 +92,25 @@ protected:
 	void opRunSpecialOpCode(ScriptOpCall &scriptOpCall); //op B
 	void opPlayOrStopSound(ScriptOpCall &scriptOpCall);
 	void opDelay(ScriptOpCall &scriptOpCall); //op D
-	void opUnkE(ScriptOpCall &scriptOpCall);
-	void opUnkF(ScriptOpCall &scriptOpCall);
-	void opUnk10(ScriptOpCall &scriptOpCall);
+	void opMoveActorToPoint(ScriptOpCall &scriptOpCall);
+	void opMoveActorToXY(ScriptOpCall &scriptOpCall);
+	void opMoveActorToObject(ScriptOpCall &scriptOpCall);
 	void opUnk11FlickerTalk(ScriptOpCall &scriptOpCall);
-	void opUnk12LoadScene(ScriptOpCall &scriptOpCall);
-	void opUnk13PropertiesRelated(ScriptOpCall &scriptOpCall);
-	void opUnk14PropertiesRelated(ScriptOpCall &scriptOpCall);
+	void opLoadScene(ScriptOpCall &scriptOpCall);
+	void opIfStatement(ScriptOpCall &scriptOpCall);
+	void opIfElseStatement(ScriptOpCall &scriptOpCall);
 	void opUnk15PropertiesRelated(ScriptOpCall &scriptOpCall);
 	void opUnk16(ScriptOpCall &scriptOpCall);
-	void opUnk17(ScriptOpCall &scriptOpCall);
-	void opUnk18(ScriptOpCall &scriptOpCall);
-	void opUnk19(ScriptOpCall &scriptOpCall);
+	void opWaitForActorSequenceToFinish(ScriptOpCall &scriptOpCall);
+	void opDialogAtPoint(ScriptOpCall &scriptOpCall);
+	void opExecuteObjectSceneScript(ScriptOpCall &scriptOpCall);
 	void opUpdatePaletteCycling(ScriptOpCall &scriptOpCall);
-	void opUnk1B(ScriptOpCall &scriptOpCall);
-	void opUnk1DClearActorFlag0x400(ScriptOpCall &scriptOpCall);
-	void opUnk1ESetActorFlag0x400(ScriptOpCall &scriptOpCall);
+	void opWaitForActorToFinishWalking(ScriptOpCall &scriptOpCall);
+	void opShowActor(ScriptOpCall &scriptOpCall);
+	void opHideActor(ScriptOpCall &scriptOpCall);
 	void opSetActorFlag0x1000(ScriptOpCall &scriptOpCall);
 	void opPlayMusic(ScriptOpCall &scriptOpCall);
-	void opUnk20(ScriptOpCall &scriptOpCall);
+	void opPreLoadSceneData(ScriptOpCall &scriptOpCall);
 	void opPauseCurrentSpeechAndFetchNextDialog(ScriptOpCall &scriptOpCall);
 
 	bool evaluateExpression(ScriptOpCall &scriptOpCall);


Commit: ff519c13737befefb66acfd84b95cbf517d5f07d
    https://github.com/scummvm/scummvm/commit/ff519c13737befefb66acfd84b95cbf517d5f07d
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed flicker idle animation

Changed paths:
    engines/dragons/dragons.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index b32441ff7b..f045064dc8 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -284,12 +284,12 @@ void DragonsEngine::gameLoop() {
 		}
 
 		_counter++;
-		if (0x4af < _counter) {
+		if (_counter >= 0x4af) {
 			pDVar8 = _dragonINIResource->getFlickerRecord();
 			if (pDVar8->actor->_resourceID == 0xe) {
 				pDVar8->actor->_direction = 2;
 				pDVar8->field_20_actor_field_14 = 2;
-				if (getINI(0xc2)->field_1e == 1) {
+				if (getINI(0xc2)->sceneId == 1) {
 					sequenceId = 0x30;
 				} else {
 					sequenceId = 2;


Commit: bd39b6baae4418ed85d2a7598be322ffdea461e0
    https://github.com/scummvm/scummvm/commit/bd39b6baae4418ed85d2a7598be322ffdea461e0
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Removed goto from game loop. renamed counter to flickerIdleCounter

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index f045064dc8..a58a9b22ca 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -267,7 +267,7 @@ void DragonsEngine::gameLoop() {
 
 	_cursor->_cursorActivationSeqOffset = 0;
 	_bit_flags_8006fbd8 = 0;
-	_counter = 0;
+	_flickerIdleCounter = 0;
 	setFlags(ENGINE_FLAG_8);
 	actorId = 0;
 
@@ -283,8 +283,8 @@ void DragonsEngine::gameLoop() {
 			_sceneId1 = getCurrentSceneId();
 		}
 
-		_counter++;
-		if (_counter >= 0x4af) {
+		_flickerIdleCounter++;
+		if (_flickerIdleCounter >= 0x4af) {
 			pDVar8 = _dragonINIResource->getFlickerRecord();
 			if (pDVar8->actor->_resourceID == 0xe) {
 				pDVar8->actor->_direction = 2;
@@ -295,13 +295,13 @@ void DragonsEngine::gameLoop() {
 					sequenceId = 2;
 				}
 				pDVar8->actor->updateSequence(sequenceId);
-				_counter = 0;
+				_flickerIdleCounter = 0;
 				setFlags(ENGINE_FLAG_80000000);
 			}
 		}
 		if (isFlagSet(ENGINE_FLAG_80000000)
 			&& _dragonINIResource->getFlickerRecord()->actor->isFlagSet(ACTOR_FLAG_4)) {
-			_counter = 0;
+			_flickerIdleCounter = 0;
 			clearFlags(ENGINE_FLAG_80000000);
 		}
 		if (_bit_flags_8006fbd8 == 0) {
@@ -310,8 +310,9 @@ void DragonsEngine::gameLoop() {
 		if (_dragonINIResource->getFlickerRecord()->sceneId == getCurrentSceneId()) {
 			uVar3 = ipt_img_file_related();
 			actorId_00 = uVar3 & 0xffff;
-			if (actorId_00 == 0) goto LAB_80026d34;
-			if (actorId_00 != (actorId & 0xffff)) {
+			if (actorId_00 == 0) {
+				uVar3 = 0;
+			} else if (actorId_00 != (actorId & 0xffff)) {
 				byte *obd = _dragonOBD->getFromOpt(actorId_00 - 1);
 				ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
@@ -319,11 +320,10 @@ void DragonsEngine::gameLoop() {
 					scriptOpCall._codeEnd = scriptOpCall._code + 4 + READ_LE_UINT16(scriptOpCall._code + 2);
 					scriptOpCall._code += 4;
 					_scriptOpcodes->runScript(scriptOpCall);
-					_counter = 0;
+					_flickerIdleCounter = 0;
 				}
 			}
 		} else {
-			LAB_80026d34:
 			uVar3 = 0;
 		}
 
@@ -336,7 +336,7 @@ void DragonsEngine::gameLoop() {
 
 		if (_rightMouseButtonUp && isInputEnabled()) {
 			_cursor->selectPreviousCursor();
-			_counter = 0;
+			_flickerIdleCounter = 0;
 			actorId = uVar3;
 			continue;
 		}
@@ -363,7 +363,7 @@ void DragonsEngine::gameLoop() {
 //				uVar6 = 3;
 //				if (_cursor->_sequenceID == 2) goto LAB_80026fb0;
 //			}
-//			_counter = 0;
+//			_flickerIdleCounter = 0;
 //			actorId = uVar3;
 //			continue;
 //		}
@@ -387,7 +387,7 @@ void DragonsEngine::gameLoop() {
 			} else {
 				setFlags(ENGINE_FLAG_8);
 			}
-			_counter = 0;
+			_flickerIdleCounter = 0;
 			actorId = uVar3;
 			continue;
 		}
@@ -407,7 +407,7 @@ void DragonsEngine::gameLoop() {
 							_inventory->inventoryMissing();
 							actorId = uVar3;
 						} else {
-							_counter = 0;
+							_flickerIdleCounter = 0;
 							_inventory->setType(1);
 							_inventory->openInventory();
 				joined_r0x80027a38:
@@ -423,7 +423,7 @@ void DragonsEngine::gameLoop() {
 					}
 					uVar6 = _inventory->getType();
 					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
-						_counter = 0;
+						_flickerIdleCounter = 0;
 						if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
 							if (_cursor->_iniUnderCursor == 0x8002) {
 								LAB_80027294:
@@ -457,7 +457,7 @@ void DragonsEngine::gameLoop() {
 							}
 						}
 				LAB_80027ab4:
-						_counter = 0;
+						_flickerIdleCounter = 0;
 						_cursor->_data_80072890 = _cursor->_iniUnderCursor;
 						if (_cursor->_sequenceID < 5) {
 							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
@@ -483,7 +483,7 @@ void DragonsEngine::gameLoop() {
 						uVar7 = _inventory->_old_showing_value;
 						if (_dragonVAR->getVar(7) == 1)
 							goto LAB_800279f4;
-						_counter = 0;
+						_flickerIdleCounter = 0;
 						_inventory->setType(1);
 						_inventory->_old_showing_value = uVar6;
 						_inventory->openInventory();
@@ -499,7 +499,7 @@ void DragonsEngine::gameLoop() {
 			continue;
 		}
 		if (checkForInventoryButtonRelease()) {
-			_counter = 0;
+			_flickerIdleCounter = 0;
 			LAB_80027970:
 			_inventory->closeInventory();
 			uVar6 = _inventory->_old_showing_value;
@@ -510,7 +510,7 @@ void DragonsEngine::gameLoop() {
 		}
 		uVar6 = _inventory->getType();
 		if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
-			_counter = 0;
+			_flickerIdleCounter = 0;
 			if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
 				if (_cursor->_iniUnderCursor == 0x8001) {
 					_inventory->closeInventory();
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 2dff40b982..de1112d043 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -164,7 +164,7 @@ private:
 	uint32 _flags;
 	uint32 _unkFlags1;
 	Common::Point _cursorPosition;
-	uint32 _counter;
+	uint32 _flickerIdleCounter;
 	uint32 _bit_flags_8006fbd8;
 	//unk
 


Commit: 21f61c26b9ff32cdb6396a9c51ceeef6e10c372c
    https://github.com/scummvm/scummvm/commit/21f61c26b9ff32cdb6396a9c51ceeef6e10c372c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More gameLoop refactoring

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index a58a9b22ca..6ee825f7de 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -261,9 +261,7 @@ void DragonsEngine::gameLoop() {
 	uint actorId;
 	uint16 uVar6;
 	uint16 uVar7;
-	uint actorId_00;
 	uint16 sequenceId;
-	DragonINI *pDVar8;
 
 	_cursor->_cursorActivationSeqOffset = 0;
 	_bit_flags_8006fbd8 = 0;
@@ -283,37 +281,15 @@ void DragonsEngine::gameLoop() {
 			_sceneId1 = getCurrentSceneId();
 		}
 
-		_flickerIdleCounter++;
-		if (_flickerIdleCounter >= 0x4af) {
-			pDVar8 = _dragonINIResource->getFlickerRecord();
-			if (pDVar8->actor->_resourceID == 0xe) {
-				pDVar8->actor->_direction = 2;
-				pDVar8->field_20_actor_field_14 = 2;
-				if (getINI(0xc2)->sceneId == 1) {
-					sequenceId = 0x30;
-				} else {
-					sequenceId = 2;
-				}
-				pDVar8->actor->updateSequence(sequenceId);
-				_flickerIdleCounter = 0;
-				setFlags(ENGINE_FLAG_80000000);
-			}
-		}
-		if (isFlagSet(ENGINE_FLAG_80000000)
-			&& _dragonINIResource->getFlickerRecord()->actor->isFlagSet(ACTOR_FLAG_4)) {
-			_flickerIdleCounter = 0;
-			clearFlags(ENGINE_FLAG_80000000);
-		}
+		updateFlickerIdleAnimation();
+
 		if (_bit_flags_8006fbd8 == 0) {
 			setFlags(ENGINE_FLAG_8);
 		}
 		if (_dragonINIResource->getFlickerRecord()->sceneId == getCurrentSceneId()) {
 			uVar3 = ipt_img_file_related();
-			actorId_00 = uVar3 & 0xffff;
-			if (actorId_00 == 0) {
-				uVar3 = 0;
-			} else if (actorId_00 != (actorId & 0xffff)) {
-				byte *obd = _dragonOBD->getFromOpt(actorId_00 - 1);
+			if (uVar3 != 0 && uVar3 != (actorId & 0xffff)) {
+				byte *obd = _dragonOBD->getFromOpt(uVar3 - 1);
 				ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
 				if (_scriptOpcodes->runScript4(scriptOpCall)) {
@@ -493,7 +469,6 @@ void DragonsEngine::gameLoop() {
 						goto LAB_80027ab4;
 				}
 			}
-	LAB_80027b58:
 			runINIScripts();
 			actorId = uVar3;
 			continue;
@@ -560,12 +535,14 @@ void DragonsEngine::gameLoop() {
 					actor->setFlag(ACTOR_FLAG_100);
 					actor->setFlag(ACTOR_FLAG_200);
 					actor->_priorityLayer = 6;
-					actorId = uVar3;
 				}
 				continue;
 			}
-			if (_cursor->_iniItemInHand == 0)
-				goto LAB_80027b58;
+			if (_cursor->_iniItemInHand == 0) {
+				runINIScripts();
+				actorId = uVar3;
+				continue;
+			}
 			//drop item back into inventory
 			if (_inventory->addItemIfPositionIsEmpty(_cursor->_iniItemInHand, _cursor->_x, _cursor->_y)) {
 				Actor *invActor = _inventory->getInventoryItemActor(_cursor->_iniItemInHand);
@@ -586,8 +563,11 @@ void DragonsEngine::gameLoop() {
 		}
 LAB_8002790c:
 		if ((_cursor->_iniItemInHand == 0) ||
-			(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4))))
-			goto LAB_80027b58;
+			(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4)))) {
+			runINIScripts();
+			actorId = uVar3;
+			continue;
+		}
 		_cursor->_sequenceID = 5;
 		waitForFrames(2);
 		goto LAB_80027970;
@@ -907,8 +887,8 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 
 //TODO the logic in this function doesn't match the original. It should be redone.
 void DragonsEngine::engineFlag0x20UpdateFunction() {
-	if (_flags & ENGINE_FLAG_20) {
-		if ((_flags & (ENGINE_FLAG_80000000 | Dragons::ENGINE_FLAG_8)) == 8) {
+	if (isFlagSet(ENGINE_FLAG_20)) {
+		if (isFlagSet(ENGINE_FLAG_8) && !isFlagSet(ENGINE_FLAG_80000000)) {
 			_cursor->update();
 		}
 		//TODO 0x80027be4
@@ -936,8 +916,8 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 						_inventory->setPriority(0);
 					}
 				} else {
-					if ((_bit_flags_8006fbd8 & 2) == 0) {
-						_bit_flags_8006fbd8 = _bit_flags_8006fbd8 | 2;
+					if ((_bit_flags_8006fbd8 & 2u) == 0) {
+						_bit_flags_8006fbd8 |= 2u;
 					}
 					if (flickerINI->actor->isFlagClear(ACTOR_FLAG_2000)
 							&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
@@ -1477,6 +1457,29 @@ uint32 DragonsEngine::defaultResponseOffsetFromDragonEXE() {
 	}
 }
 
+void DragonsEngine::updateFlickerIdleAnimation() {
+	_flickerIdleCounter++;
+	if (_flickerIdleCounter >= 0x4af) {
+		DragonINI *flicker = _dragonINIResource->getFlickerRecord();
+		if (flicker->actor->_resourceID == 0xe) {
+			flicker->actor->_direction = 2;
+			flicker->field_20_actor_field_14 = 2;
+			if (getINI(0xc2)->sceneId == 1) {
+				flicker->actor->updateSequence(0x30);
+			} else {
+				flicker->actor->updateSequence(2);
+			}
+			_flickerIdleCounter = 0;
+			setFlags(ENGINE_FLAG_80000000);
+		}
+	}
+	if (isFlagSet(ENGINE_FLAG_80000000)
+		&& _dragonINIResource->getFlickerRecord()->actor->isFlagSet(ACTOR_FLAG_4)) {
+		_flickerIdleCounter = 0;
+		clearFlags(ENGINE_FLAG_80000000);
+	}
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index de1112d043..0946efccd3 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -82,7 +82,7 @@ enum Flags {
 	ENGINE_FLAG_4000000  =  0x4000000,
 	ENGINE_FLAG_8000000  =  0x8000000,
 	ENGINE_FLAG_20000000 = 0x20000000,
-	ENGINE_FLAG_80000000 = 0x80000000
+	ENGINE_FLAG_80000000 = 0x80000000   //Flicker idle animation running.
 };
 
 enum UnkFlags {
@@ -294,6 +294,8 @@ private:
 	void updateHandler();
 	void updatePathfindingActors();
 	void updatePaletteCycling();
+	void updateFlickerIdleAnimation();
+
 	uint32 calulateTimeLeft();
 	void wait();
 	uint16 getIniFromImg();


Commit: a04d6206a082cf4a514984a441327e62788cbacb
    https://github.com/scummvm/scummvm/commit/a04d6206a082cf4a514984a441327e62788cbacb
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Game loop refactoring

Changed paths:
    engines/dragons/dragons.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 6ee825f7de..34ee9eaddc 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -257,8 +257,7 @@ uint16 DragonsEngine::ipt_img_file_related() {
 }
 
 void DragonsEngine::gameLoop() {
-	uint uVar3;
-	uint actorId;
+	uint16 prevImgIniId = 0;
 	uint16 uVar6;
 	uint16 uVar7;
 	uint16 sequenceId;
@@ -267,7 +266,6 @@ void DragonsEngine::gameLoop() {
 	_bit_flags_8006fbd8 = 0;
 	_flickerIdleCounter = 0;
 	setFlags(ENGINE_FLAG_8);
-	actorId = 0;
 
 	while (!shouldQuit()) {
 		_scene->draw();
@@ -287,9 +285,9 @@ void DragonsEngine::gameLoop() {
 			setFlags(ENGINE_FLAG_8);
 		}
 		if (_dragonINIResource->getFlickerRecord()->sceneId == getCurrentSceneId()) {
-			uVar3 = ipt_img_file_related();
-			if (uVar3 != 0 && uVar3 != (actorId & 0xffff)) {
-				byte *obd = _dragonOBD->getFromOpt(uVar3 - 1);
+			uint16 imgIniId = ipt_img_file_related();
+			if (imgIniId != 0 && imgIniId != (prevImgIniId & 0xffff)) {
+				byte *obd = _dragonOBD->getFromOpt(imgIniId - 1);
 				ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
 				if (_scriptOpcodes->runScript4(scriptOpCall)) {
@@ -299,8 +297,9 @@ void DragonsEngine::gameLoop() {
 					_flickerIdleCounter = 0;
 				}
 			}
+			prevImgIniId = imgIniId;
 		} else {
-			uVar3 = 0;
+			prevImgIniId = 0;
 		}
 
 		if (_cursor->updateINIUnderCursor() == 0 ||
@@ -313,7 +312,6 @@ void DragonsEngine::gameLoop() {
 		if (_rightMouseButtonUp && isInputEnabled()) {
 			_cursor->selectPreviousCursor();
 			_flickerIdleCounter = 0;
-			actorId = uVar3;
 			continue;
 		}
 		// TODO implement cycle cursor up.
@@ -364,7 +362,6 @@ void DragonsEngine::gameLoop() {
 				setFlags(ENGINE_FLAG_8);
 			}
 			_flickerIdleCounter = 0;
-			actorId = uVar3;
 			continue;
 		}
 		if (_inventory->getType() != 1) {
@@ -381,7 +378,6 @@ void DragonsEngine::gameLoop() {
 							LAB_800279f4:
 							_inventory->_old_showing_value = uVar7;
 							_inventory->inventoryMissing();
-							actorId = uVar3;
 						} else {
 							_flickerIdleCounter = 0;
 							_inventory->setType(1);
@@ -389,10 +385,8 @@ void DragonsEngine::gameLoop() {
 				joined_r0x80027a38:
 							if (_cursor->_iniItemInHand == 0) {
 								_cursor->_sequenceID = 1;
-								actorId = uVar3;
 							} else {
 								_cursor->_sequenceID = 5;
-								actorId = uVar3;
 							}
 						}
 						continue;
@@ -416,7 +410,6 @@ void DragonsEngine::gameLoop() {
 										waitForFrames(1);
 										_cursor->_iniItemInHand = 0;
 										_cursor->_iniUnderCursor = 0;
-										actorId = uVar3;
 										continue;
 									}
 								}
@@ -428,7 +421,6 @@ void DragonsEngine::gameLoop() {
 								_inventory->setType(2);
 								_inventory->_old_showing_value = uVar6;
 								fun_80038890();
-								actorId = uVar3;
 								continue;
 							}
 						}
@@ -470,7 +462,6 @@ void DragonsEngine::gameLoop() {
 				}
 			}
 			runINIScripts();
-			actorId = uVar3;
 			continue;
 		}
 		if (checkForInventoryButtonRelease()) {
@@ -479,7 +470,6 @@ void DragonsEngine::gameLoop() {
 			_inventory->closeInventory();
 			uVar6 = _inventory->_old_showing_value;
 			_inventory->_old_showing_value = _inventory->getType();
-			actorId = uVar3;
 			_inventory->setType(uVar6);
 			continue;
 		}
@@ -502,7 +492,6 @@ void DragonsEngine::gameLoop() {
 					}
 				}
 				_inventory->_old_showing_value = uVar6;
-				actorId = uVar3;
 				continue;
 			}
 			if (_cursor->_iniUnderCursor != 0) {
@@ -524,7 +513,6 @@ void DragonsEngine::gameLoop() {
 				actor->clearFlag(ACTOR_FLAG_40);
 				_cursor->_iniItemInHand = _cursor->_iniUnderCursor;
 				_cursor->_sequenceID = 5;
-				actorId = uVar3;
 				if (tmpId != 0) {
 					actor->_flags = 0;
 					actor->_priorityLayer = 0;
@@ -540,7 +528,6 @@ void DragonsEngine::gameLoop() {
 			}
 			if (_cursor->_iniItemInHand == 0) {
 				runINIScripts();
-				actorId = uVar3;
 				continue;
 			}
 			//drop item back into inventory
@@ -565,7 +552,6 @@ LAB_8002790c:
 		if ((_cursor->_iniItemInHand == 0) ||
 			(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4)))) {
 			runINIScripts();
-			actorId = uVar3;
 			continue;
 		}
 		_cursor->_sequenceID = 5;


Commit: fe1a4a705faf2c0318178a8f8a598856f6a9d388
    https://github.com/scummvm/scummvm/commit/fe1a4a705faf2c0318178a8f8a598856f6a9d388
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Cleaning up gameLoop. Removing goto logic

Changed paths:
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp


diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 34ee9eaddc..6474d2b10b 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -372,17 +372,14 @@ void DragonsEngine::gameLoop() {
 						sequenceId = _dragonVAR->getVar(7);
 						uVar7 = _inventory->_old_showing_value;
 						_inventory->_old_showing_value = _inventory->getType();
-				joined_r0x800271d0:
 						_inventory->setType(_inventory->_old_showing_value);
 						if (sequenceId == 1) {
-							LAB_800279f4:
 							_inventory->_old_showing_value = uVar7;
 							_inventory->inventoryMissing();
 						} else {
 							_flickerIdleCounter = 0;
 							_inventory->setType(1);
 							_inventory->openInventory();
-				joined_r0x80027a38:
 							if (_cursor->_iniItemInHand == 0) {
 								_cursor->_sequenceID = 1;
 							} else {
@@ -402,7 +399,21 @@ void DragonsEngine::gameLoop() {
 										sequenceId = _dragonVAR->getVar(7);
 										uVar7 = _inventory->_old_showing_value;
 										_inventory->_old_showing_value = _inventory->getType();
-										goto joined_r0x800271d0;
+										_inventory->setType(_inventory->_old_showing_value);
+										if (sequenceId == 1) {
+											_inventory->_old_showing_value = uVar7;
+											_inventory->inventoryMissing();
+										} else {
+											_flickerIdleCounter = 0;
+											_inventory->setType(1);
+											_inventory->openInventory();
+											if (_cursor->_iniItemInHand == 0) {
+												_cursor->_sequenceID = 1;
+											} else {
+												_cursor->_sequenceID = 5;
+											}
+										}
+										continue;
 									}
 								} else {
 									if (_inventory->addItem(_cursor->_iniItemInHand)) {
@@ -414,17 +425,36 @@ void DragonsEngine::gameLoop() {
 									}
 								}
 							} else {
-								if (_cursor->_iniUnderCursor != 0x8001) goto LAB_80027ab4;
+								if (_cursor->_iniUnderCursor != 0x8001) {
+									_flickerIdleCounter = 0;
+									_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+									if (_cursor->_sequenceID < 5) {
+										_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+										walkFlickerToObject();
+										if (_bit_flags_8006fbd8 != 0) {
+											clearFlags(ENGINE_FLAG_8);
+										}
+									} else {
+										_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+										walkFlickerToObject();
+										if (_bit_flags_8006fbd8 != 0) {
+											clearFlags(ENGINE_FLAG_8);
+										}
+										_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
+										_cursor->_data_80072890 = _cursor->_iniItemInHand;
+									}
+									runINIScripts();
+									continue;
+								}
 								if (_inventory->getSequenceId() == 0) goto LAB_80027294;
 							}
 							if ((_cursor->_iniUnderCursor == 0x8001) && (_inventory->getSequenceId() == 1)) {
 								_inventory->setType(2);
 								_inventory->_old_showing_value = uVar6;
-								fun_80038890();
+								_inventory->openInventionBook();
 								continue;
 							}
 						}
-				LAB_80027ab4:
 						_flickerIdleCounter = 0;
 						_cursor->_data_80072890 = _cursor->_iniUnderCursor;
 						if (_cursor->_sequenceID < 5) {
@@ -449,16 +479,41 @@ void DragonsEngine::gameLoop() {
 					uVar6 = _inventory->getType();
 					if (checkForInventoryButtonRelease() && isInputEnabled()) {
 						uVar7 = _inventory->_old_showing_value;
-						if (_dragonVAR->getVar(7) == 1)
-							goto LAB_800279f4;
+						if (_dragonVAR->getVar(7) == 1) {
+							_inventory->_old_showing_value = uVar7;
+							_inventory->inventoryMissing();
+							continue;
+						}
 						_flickerIdleCounter = 0;
 						_inventory->setType(1);
 						_inventory->_old_showing_value = uVar6;
 						_inventory->openInventory();
-						goto joined_r0x80027a38;
+						if (_cursor->_iniItemInHand == 0) {
+							_cursor->_sequenceID = 1;
+						} else {
+							_cursor->_sequenceID = 5;
+						}
+						continue;
+					}
+					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
+						_flickerIdleCounter = 0;
+						_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+						if (_cursor->_sequenceID < 5) {
+							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+							walkFlickerToObject();
+							if (_bit_flags_8006fbd8 != 0) {
+								clearFlags(ENGINE_FLAG_8);
+							}
+						} else {
+							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+							walkFlickerToObject();
+							if (_bit_flags_8006fbd8 != 0) {
+								clearFlags(ENGINE_FLAG_8);
+							}
+							_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
+							_cursor->_data_80072890 = _cursor->_iniItemInHand;
+						}
 					}
-					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8))
-						goto LAB_80027ab4;
 				}
 			}
 			runINIScripts();
@@ -466,7 +521,6 @@ void DragonsEngine::gameLoop() {
 		}
 		if (checkForInventoryButtonRelease()) {
 			_flickerIdleCounter = 0;
-			LAB_80027970:
 			_inventory->closeInventory();
 			uVar6 = _inventory->_old_showing_value;
 			_inventory->_old_showing_value = _inventory->getType();
@@ -481,14 +535,14 @@ void DragonsEngine::gameLoop() {
 					_inventory->closeInventory();
 					_inventory->setType(0);
 					if (_inventory->_old_showing_value == 2) {
-						fun_80038994();
+						_inventory->closeInventionBook();
 					}
 				} else {
 					if (_cursor->_iniUnderCursor != 0x8002) goto LAB_8002790c;
 					_inventory->closeInventory();
 					_inventory->setType(2);
 					if (_inventory->_old_showing_value != 2) {
-						fun_80038890();
+						_inventory->openInventionBook();
 					}
 				}
 				_inventory->_old_showing_value = uVar6;
@@ -498,7 +552,7 @@ void DragonsEngine::gameLoop() {
 				if ((_cursor->_sequenceID != 4) && (_cursor->_sequenceID != 2)) {
 					_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 					_cursor->_data_80072890 = _cursor->_iniUnderCursor;
-					if (4 < _cursor->_sequenceID) {
+					if (_cursor->_sequenceID >= 4) {
 						_cursor->_data_80072890 = _cursor->_iniItemInHand;
 						_scriptOpcodes->_scriptTargetINI = _cursor->_iniUnderCursor;
 					}
@@ -556,7 +610,10 @@ LAB_8002790c:
 		}
 		_cursor->_sequenceID = 5;
 		waitForFrames(2);
-		goto LAB_80027970;
+		_inventory->closeInventory();
+		uVar6 = _inventory->_old_showing_value;
+		_inventory->_old_showing_value = _inventory->getType();
+		_inventory->setType(uVar6);
 	}
 }
 
@@ -1089,10 +1146,6 @@ bool DragonsEngine::checkForActionButtonRelease() {
 	return _leftMouseButtonUp || _enterKeyUp;
 }
 
-void DragonsEngine::fun_80038890() {
-	error("fun_80038890"); //TODO
-}
-
 void DragonsEngine::walkFlickerToObject() {
 	uint16 targetX;
 	uint16 targetY;
@@ -1161,10 +1214,6 @@ void DragonsEngine::walkFlickerToObject() {
 	return;
 }
 
-void DragonsEngine::fun_80038994() {
-	error("fun_80038994"); //TODO
-}
-
 void DragonsEngine::reset_screen_maybe() {
 	_videoFlags &= ~0x10;
 	//TODO
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 0946efccd3..6c1aaf21e1 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -306,13 +306,10 @@ private:
 	bool isInputEnabled();
 	bool checkForInventoryButtonRelease();
 
-	void fun_80038890();
 	void walkFlickerToObject();
-	void fun_80038994();
 
 	void seedRandom(int32 seed);
 	uint32 shuffleRandState();
-	void fun_8002931c();
 
 	void initializeSound();
 
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 93306fb041..5b7427c3fd 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -297,8 +297,7 @@ void Inventory::openInventionBook() {
 }
 
 void Inventory::closeInventionBook() {
-	uint uVar1;
-	uint uVar2;
+	uint sceneId;
 
 	// TODO fade_related_calls_with_1f();
 
@@ -313,23 +312,27 @@ void Inventory::closeInventionBook() {
 	_sequenceId = 0;
 	setActorSequenceId(0);
 	setPositionFromSceneId(_inventionBookPrevSceneId);
-	uVar2 = _vm->_scene->getSceneId();
-	if (((((uVar2 == 0x23) || (uVar2 == 0x2d)) || (uVar2 == 0x2e)) || ((uVar2 == 0x31 || (uVar2 == 0x32)))) || (uVar2 == 0x28)) {
-		LAB_80038b9c:
-		if ((uint)_vm->_scene->getSceneId() == 0x27) goto LAB_80038bb8;
+	sceneId = _vm->_scene->getSceneId();
+	if (((((sceneId == 0x23) || (sceneId == 0x2d)) || (sceneId == 0x2e)) || ((sceneId == 0x31 || (sceneId == 0x32)))) || (sceneId == 0x28)) {
+		if ((uint)_vm->_scene->getSceneId() == 0x27) {
+			_vm->getINI(0x206)->sceneId = 0;
+		}
 	} else {
-		if (uVar2 != 0x27) {
-			if (((uVar2 != 0x1c) && (uVar2 != 0x1d)) && (uVar1 = uVar2 | 0x8000, uVar2 != 0x21)) goto LAB_80038be8;
-			goto LAB_80038b9c;
+		if (sceneId != 0x27) {
+			if (sceneId != 0x1c && sceneId != 0x1d && sceneId != 0x21) {
+				_vm->_scene->loadScene(sceneId | 0x8000u, 0x1e);
+				_vm->setSceneUpdateFunction(_inventionBookPrevSceneUpdateFunc);
+				return;
+			}
+			if ((uint)_vm->_scene->getSceneId() == 0x27) {
+				_vm->getINI(0x206)->sceneId = 0;
+			}
+		} else {
+			_vm->getINI(0x206)->sceneId = 0;
 		}
-		LAB_80038bb8:
-		_vm->getINI(0x206)->sceneId = 0;
 	}
-	uVar1 = (uint)_vm->_scene->getSceneId();
-LAB_80038be8:
-	_vm->_scene->loadScene(uVar1, 0x1e);
+	_vm->_scene->loadScene(_vm->_scene->getSceneId(), 0x1e);
 	_vm->setSceneUpdateFunction(_inventionBookPrevSceneUpdateFunc);
-	return;
 }
 
 void Inventory::setPositionFromSceneId(uint32 sceneId) {


Commit: c9aad0619256596f6ea7932b1a197363c6df8525
    https://github.com/scummvm/scummvm/commit/c9aad0619256596f6ea7932b1a197363c6df8525
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More code cleanup

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 11f341e1ae..a2f738a7fa 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -320,13 +320,13 @@ int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 }
 
 void Cursor::selectPreviousCursor() {
-	int16 uVar7 = _sequenceID - 1;
+	int16 newSequenceID = _sequenceID - 1;
 	int16 inventoryType = _vm->_inventory->getType();
-	if ((uVar7 == 0) && ((inventoryType == 1 || (inventoryType == 2)))) {
-		uVar7 = _sequenceID - 2;
+	if (newSequenceID == 0 && (inventoryType == 1 || inventoryType == 2)) {
+		newSequenceID = _sequenceID - 2;
 	}
-	_sequenceID = uVar7;
-	if ((_sequenceID == 3) && (inventoryType == 1)) {
+	_sequenceID = newSequenceID;
+	if (_sequenceID == 3 && inventoryType == 1) {
 		_sequenceID = 1;
 	}
 	if (_sequenceID == 2) {
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 6474d2b10b..26419ab327 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -446,7 +446,9 @@ void DragonsEngine::gameLoop() {
 									runINIScripts();
 									continue;
 								}
-								if (_inventory->getSequenceId() == 0) goto LAB_80027294;
+								if (_inventory->getSequenceId() == 0) {
+									goto LAB_80027294;
+								}
 							}
 							if ((_cursor->_iniUnderCursor == 0x8001) && (_inventory->getSequenceId() == 1)) {
 								_inventory->setType(2);
@@ -538,7 +540,20 @@ void DragonsEngine::gameLoop() {
 						_inventory->closeInventionBook();
 					}
 				} else {
-					if (_cursor->_iniUnderCursor != 0x8002) goto LAB_8002790c;
+					if (_cursor->_iniUnderCursor != 0x8002) {
+						if ((_cursor->_iniItemInHand == 0) ||
+							(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4)))) {
+							runINIScripts();
+						} else {
+							_cursor->_sequenceID = 5;
+							waitForFrames(2);
+							_inventory->closeInventory();
+							uVar6 = _inventory->_old_showing_value;
+							_inventory->_old_showing_value = _inventory->getType();
+							_inventory->setType(uVar6);
+						}
+						continue;
+					}
 					_inventory->closeInventory();
 					_inventory->setType(2);
 					if (_inventory->_old_showing_value != 2) {
@@ -558,7 +573,18 @@ void DragonsEngine::gameLoop() {
 					}
 					clearFlags(ENGINE_FLAG_8);
 					walkFlickerToObject();
-					goto LAB_8002790c;
+					if ((_cursor->_iniItemInHand == 0) ||
+						(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4)))) {
+						runINIScripts();
+					} else {
+						_cursor->_sequenceID = 5;
+						waitForFrames(2);
+						_inventory->closeInventory();
+						uVar6 = _inventory->_old_showing_value;
+						_inventory->_old_showing_value = _inventory->getType();
+						_inventory->setType(uVar6);
+					}
+					continue;
 				}
 				Actor *actor = _inventory->getInventoryItemActor(_cursor->_iniUnderCursor);
 				uint16 tmpId = _cursor->_iniItemInHand;
@@ -602,18 +628,17 @@ void DragonsEngine::gameLoop() {
 				}
 			}
 		}
-LAB_8002790c:
 		if ((_cursor->_iniItemInHand == 0) ||
 			(((uint16)(_cursor->_x - 10U) < 300 && ((uint16)(_cursor->_y - 10U) < 0xb4)))) {
 			runINIScripts();
-			continue;
+		} else {
+			_cursor->_sequenceID = 5;
+			waitForFrames(2);
+			_inventory->closeInventory();
+			uVar6 = _inventory->_old_showing_value;
+			_inventory->_old_showing_value = _inventory->getType();
+			_inventory->setType(uVar6);
 		}
-		_cursor->_sequenceID = 5;
-		waitForFrames(2);
-		_inventory->closeInventory();
-		uVar6 = _inventory->_old_showing_value;
-		_inventory->_old_showing_value = _inventory->getType();
-		_inventory->setType(uVar6);
 	}
 }
 


Commit: 723f082ea94b2097e6c1112e08a3fc89ace853b7
    https://github.com/scummvm/scummvm/commit/723f082ea94b2097e6c1112e08a3fc89ace853b7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Fixed flicker display bug when returning from invention book scene

Changed paths:
    engines/dragons/inventory.cpp


diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 5b7427c3fd..7b729ae1ad 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -302,9 +302,9 @@ void Inventory::closeInventionBook() {
 	// TODO fade_related_calls_with_1f();
 
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
-	if (flicker && flicker->actor) {
-		flicker->actor->_x_pos = _inventionBookPrevFlickerINIPosition.x;
-		flicker->actor->_y_pos = _inventionBookPrevFlickerINIPosition.y;
+	if (flicker) {
+		flicker->x = _inventionBookPrevFlickerINIPosition.x;
+		flicker->y = _inventionBookPrevFlickerINIPosition.y;
 		flicker->sceneId = _inventionBookPrevFlickerINISceneId;
 	}
 	_vm->_scene->setSceneId(_inventionBookPrevSceneId);


Commit: 72161554b26759c39584a3d17fffde3b46bec184
    https://github.com/scummvm/scummvm/commit/72161554b26759c39584a3d17fffde3b46bec184
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Refactoring inventory state code

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index a2f738a7fa..09e91622e8 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -67,7 +67,7 @@ void Cursor::update() {
 	// TODO update cursor from inputs here.
 
 	// 0x800280b8
-	if (_sequenceID == 0 && (_vm->_inventory->getType() == 1 || _vm->_inventory->getType() == 2)) {
+	if (_sequenceID == 0 && _vm->_inventory->isOpen()) {
 		_sequenceID = 1;
 	}
 
@@ -76,7 +76,7 @@ void Cursor::update() {
 
 	// 0x80028104
 	if (_iniUnderCursor != 0
-			&& ((_iniUnderCursor & 0x8000 && (_vm->_inventory->getType() == 1 || _vm->_inventory->getType() == 2))
+			&& ((_iniUnderCursor & 0x8000 && _vm->_inventory->isOpen())
 			||(!(_iniUnderCursor & 0x8000) && _vm->getINI(_iniUnderCursor - 1)->field_1a_flags_maybe & 0x80))) {
 		if (_actor->_sequenceID != 0x84) {
 			_actor->updateSequence(0x84);
@@ -174,22 +174,9 @@ int16 Cursor::updateINIUnderCursor() {
 	}
 
 	// TODO 0x80028940
-	int16 inventoryType = _vm->_inventory->getType();
-	if (inventoryType == 1) {
+	if (_vm->_inventory->getState() == InventoryOpen) {
 		_iniUnderCursor = _vm->_inventory->getIniAtPosition(_x, _y);
 		return _iniUnderCursor;
-	} else {
-		if (inventoryType < 2) {
-			if (inventoryType != 0) {
-				_iniUnderCursor = 0;
-				return 0;
-			}
-		} else {
-			if (inventoryType != 2) {
-				_iniUnderCursor = 0;
-				return 0;
-			}
-		}
 	}
 
 	return updateIniFromScene();
@@ -321,12 +308,12 @@ int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 
 void Cursor::selectPreviousCursor() {
 	int16 newSequenceID = _sequenceID - 1;
-	int16 inventoryType = _vm->_inventory->getType();
-	if (newSequenceID == 0 && (inventoryType == 1 || inventoryType == 2)) {
+	InventoryState inventoryType = _vm->_inventory->getState();
+	if (newSequenceID == 0 && (inventoryType == InventoryOpen || inventoryType == InventionBookOpen)) {
 		newSequenceID = _sequenceID - 2;
 	}
 	_sequenceID = newSequenceID;
-	if (_sequenceID == 3 && inventoryType == 1) {
+	if (_sequenceID == 3 && inventoryType == InventoryOpen) {
 		_sequenceID = 1;
 	}
 	if (_sequenceID == 2) {
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 26419ab327..9c224f2183 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -258,8 +258,8 @@ uint16 DragonsEngine::ipt_img_file_related() {
 
 void DragonsEngine::gameLoop() {
 	uint16 prevImgIniId = 0;
-	uint16 uVar6;
-	uint16 uVar7;
+	InventoryState uVar6;
+	InventoryState uVar7;
 	uint16 sequenceId;
 
 	_cursor->_cursorActivationSeqOffset = 0;
@@ -346,12 +346,12 @@ void DragonsEngine::gameLoop() {
 			_bit_flags_8006fbd8 = 0;
 			DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 			if (flicker->sceneId == getCurrentSceneId() && flicker->actor->_direction != -1) {
-				uVar6 = _scriptOpcodes->_scriptTargetINI;
+				int16 iniId = _scriptOpcodes->_scriptTargetINI;
 				if (_cursor->_sequenceID != 5) {
-					uVar6 = _cursor->_data_80072890;
+					iniId = _cursor->_data_80072890;
 				}
-				if (uVar6 > 0) {
-					flicker->actor->_direction = getINI(uVar6 - 1)->field_e;
+				if (iniId > 0) {
+					flicker->actor->_direction = getINI(iniId - 1)->field_e;
 				}
 			}
 
@@ -364,157 +364,154 @@ void DragonsEngine::gameLoop() {
 			_flickerIdleCounter = 0;
 			continue;
 		}
-		if (_inventory->getType() != 1) {
-			if (_inventory->getType() < 2) {
-				if (_inventory->getType() == 0) {
-					if ((checkForInventoryButtonRelease() && isInputEnabled()) &&
-						((_bit_flags_8006fbd8 & 3) != 1)) {
-						sequenceId = _dragonVAR->getVar(7);
-						uVar7 = _inventory->_old_showing_value;
-						_inventory->_old_showing_value = _inventory->getType();
-						_inventory->setType(_inventory->_old_showing_value);
-						if (sequenceId == 1) {
-							_inventory->_old_showing_value = uVar7;
-							_inventory->inventoryMissing();
+		if (_inventory->getState() != InventoryOpen) {
+			if (_inventory->getState() == Closed) {
+				if ((checkForInventoryButtonRelease() && isInputEnabled()) &&
+					((_bit_flags_8006fbd8 & 3) != 1)) {
+					sequenceId = _dragonVAR->getVar(7);
+					InventoryState uVar7 = _inventory->_previousState;
+					_inventory->_previousState = _inventory->getState();
+					_inventory->setState(_inventory->_previousState);
+					if (sequenceId == 1) {
+						_inventory->_previousState = uVar7;
+						_inventory->inventoryMissing();
+					} else {
+						_flickerIdleCounter = 0;
+						_inventory->setState(InventoryOpen);
+						_inventory->openInventory();
+						if (_cursor->_iniItemInHand == 0) {
+							_cursor->_sequenceID = 1;
 						} else {
-							_flickerIdleCounter = 0;
-							_inventory->setType(1);
-							_inventory->openInventory();
-							if (_cursor->_iniItemInHand == 0) {
-								_cursor->_sequenceID = 1;
-							} else {
-								_cursor->_sequenceID = 5;
-							}
+							_cursor->_sequenceID = 5;
 						}
-						continue;
 					}
-					uVar6 = _inventory->getType();
-					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
-						_flickerIdleCounter = 0;
-						if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
-							if (_cursor->_iniUnderCursor == 0x8002) {
-								LAB_80027294:
-								if (_cursor->_iniItemInHand == 0) {
-									if ((_bit_flags_8006fbd8 & 3) != 1) {
-										sequenceId = _dragonVAR->getVar(7);
-										uVar7 = _inventory->_old_showing_value;
-										_inventory->_old_showing_value = _inventory->getType();
-										_inventory->setType(_inventory->_old_showing_value);
-										if (sequenceId == 1) {
-											_inventory->_old_showing_value = uVar7;
-											_inventory->inventoryMissing();
+					continue;
+				}
+				InventoryState uVar6 = _inventory->getState();
+				if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
+					_flickerIdleCounter = 0;
+					if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
+						if (_cursor->_iniUnderCursor == 0x8002) {
+							LAB_80027294:
+							if (_cursor->_iniItemInHand == 0) {
+								if ((_bit_flags_8006fbd8 & 3) != 1) {
+									sequenceId = _dragonVAR->getVar(7);
+									InventoryState uVar7 = _inventory->_previousState;
+									_inventory->_previousState = _inventory->getState();
+									_inventory->setState(_inventory->_previousState);
+									if (sequenceId == 1) {
+										_inventory->_previousState = uVar7;
+										_inventory->inventoryMissing();
+									} else {
+										_flickerIdleCounter = 0;
+										_inventory->setState(InventoryOpen);
+										_inventory->openInventory();
+										if (_cursor->_iniItemInHand == 0) {
+											_cursor->_sequenceID = 1;
 										} else {
-											_flickerIdleCounter = 0;
-											_inventory->setType(1);
-											_inventory->openInventory();
-											if (_cursor->_iniItemInHand == 0) {
-												_cursor->_sequenceID = 1;
-											} else {
-												_cursor->_sequenceID = 5;
-											}
+											_cursor->_sequenceID = 5;
 										}
-										continue;
-									}
-								} else {
-									if (_inventory->addItem(_cursor->_iniItemInHand)) {
-										_cursor->_sequenceID = 1;
-										waitForFrames(1);
-										_cursor->_iniItemInHand = 0;
-										_cursor->_iniUnderCursor = 0;
-										continue;
 									}
+									continue;
 								}
 							} else {
-								if (_cursor->_iniUnderCursor != 0x8001) {
-									_flickerIdleCounter = 0;
-									_cursor->_data_80072890 = _cursor->_iniUnderCursor;
-									if (_cursor->_sequenceID < 5) {
-										_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-										walkFlickerToObject();
-										if (_bit_flags_8006fbd8 != 0) {
-											clearFlags(ENGINE_FLAG_8);
-										}
-									} else {
-										_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-										walkFlickerToObject();
-										if (_bit_flags_8006fbd8 != 0) {
-											clearFlags(ENGINE_FLAG_8);
-										}
-										_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
-										_cursor->_data_80072890 = _cursor->_iniItemInHand;
-									}
-									runINIScripts();
+								if (_inventory->addItem(_cursor->_iniItemInHand)) {
+									_cursor->_sequenceID = 1;
+									waitForFrames(1);
+									_cursor->_iniItemInHand = 0;
+									_cursor->_iniUnderCursor = 0;
 									continue;
 								}
-								if (_inventory->getSequenceId() == 0) {
-									goto LAB_80027294;
-								}
 							}
-							if ((_cursor->_iniUnderCursor == 0x8001) && (_inventory->getSequenceId() == 1)) {
-								_inventory->setType(2);
-								_inventory->_old_showing_value = uVar6;
-								_inventory->openInventionBook();
+						} else {
+							if (_cursor->_iniUnderCursor != 0x8001) {
+								_flickerIdleCounter = 0;
+								_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+								if (_cursor->_sequenceID < 5) {
+									_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+									walkFlickerToObject();
+									if (_bit_flags_8006fbd8 != 0) {
+										clearFlags(ENGINE_FLAG_8);
+									}
+								} else {
+									_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+									walkFlickerToObject();
+									if (_bit_flags_8006fbd8 != 0) {
+										clearFlags(ENGINE_FLAG_8);
+									}
+									_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
+									_cursor->_data_80072890 = _cursor->_iniItemInHand;
+								}
+								runINIScripts();
 								continue;
 							}
-						}
-						_flickerIdleCounter = 0;
-						_cursor->_data_80072890 = _cursor->_iniUnderCursor;
-						if (_cursor->_sequenceID < 5) {
-							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-							walkFlickerToObject();
-							if (_bit_flags_8006fbd8 != 0) {
-								clearFlags(ENGINE_FLAG_8);
-							}
-						} else {
-							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-							walkFlickerToObject();
-							if (_bit_flags_8006fbd8 != 0) {
-								clearFlags(ENGINE_FLAG_8);
+							if (_inventory->getSequenceId() == 0) {
+								goto LAB_80027294;
 							}
-							_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
-							_cursor->_data_80072890 = _cursor->_iniItemInHand;
 						}
-					}
-				}
-			} else {
-				if (_inventory->getType() == 2) {
-					uVar6 = _inventory->getType();
-					if (checkForInventoryButtonRelease() && isInputEnabled()) {
-						uVar7 = _inventory->_old_showing_value;
-						if (_dragonVAR->getVar(7) == 1) {
-							_inventory->_old_showing_value = uVar7;
-							_inventory->inventoryMissing();
+						if ((_cursor->_iniUnderCursor == 0x8001) && (_inventory->getSequenceId() == 1)) {
+							_inventory->setState(InventionBookOpen);
+							_inventory->_previousState = uVar6;
+							_inventory->openInventionBook();
 							continue;
 						}
-						_flickerIdleCounter = 0;
-						_inventory->setType(1);
-						_inventory->_old_showing_value = uVar6;
-						_inventory->openInventory();
-						if (_cursor->_iniItemInHand == 0) {
-							_cursor->_sequenceID = 1;
-						} else {
-							_cursor->_sequenceID = 5;
+					}
+					_flickerIdleCounter = 0;
+					_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+					if (_cursor->_sequenceID < 5) {
+						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+						walkFlickerToObject();
+						if (_bit_flags_8006fbd8 != 0) {
+							clearFlags(ENGINE_FLAG_8);
+						}
+					} else {
+						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+						walkFlickerToObject();
+						if (_bit_flags_8006fbd8 != 0) {
+							clearFlags(ENGINE_FLAG_8);
 						}
+						_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
+						_cursor->_data_80072890 = _cursor->_iniItemInHand;
+					}
+				}
+			}
+			if (_inventory->getState() == InventionBookOpen) {
+				uVar6 = _inventory->getState();
+				if (checkForInventoryButtonRelease() && isInputEnabled()) {
+					uVar7 = _inventory->_previousState;
+					if (_dragonVAR->getVar(7) == 1) {
+						_inventory->_previousState = uVar7;
+						_inventory->inventoryMissing();
 						continue;
 					}
-					if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
-						_flickerIdleCounter = 0;
-						_cursor->_data_80072890 = _cursor->_iniUnderCursor;
-						if (_cursor->_sequenceID < 5) {
-							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-							walkFlickerToObject();
-							if (_bit_flags_8006fbd8 != 0) {
-								clearFlags(ENGINE_FLAG_8);
-							}
-						} else {
-							_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-							walkFlickerToObject();
-							if (_bit_flags_8006fbd8 != 0) {
-								clearFlags(ENGINE_FLAG_8);
-							}
-							_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
-							_cursor->_data_80072890 = _cursor->_iniItemInHand;
+					_flickerIdleCounter = 0;
+					_inventory->setState(InventoryOpen);
+					_inventory->_previousState = uVar6;
+					_inventory->openInventory();
+					if (_cursor->_iniItemInHand == 0) {
+						_cursor->_sequenceID = 1;
+					} else {
+						_cursor->_sequenceID = 5;
+					}
+					continue;
+				}
+				if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
+					_flickerIdleCounter = 0;
+					_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+					if (_cursor->_sequenceID < 5) {
+						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+						walkFlickerToObject();
+						if (_bit_flags_8006fbd8 != 0) {
+							clearFlags(ENGINE_FLAG_8);
+						}
+					} else {
+						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+						walkFlickerToObject();
+						if (_bit_flags_8006fbd8 != 0) {
+							clearFlags(ENGINE_FLAG_8);
 						}
+						_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
+						_cursor->_data_80072890 = _cursor->_iniItemInHand;
 					}
 				}
 			}
@@ -524,19 +521,19 @@ void DragonsEngine::gameLoop() {
 		if (checkForInventoryButtonRelease()) {
 			_flickerIdleCounter = 0;
 			_inventory->closeInventory();
-			uVar6 = _inventory->_old_showing_value;
-			_inventory->_old_showing_value = _inventory->getType();
-			_inventory->setType(uVar6);
+			InventoryState prevInventoryMode = _inventory->_previousState;
+			_inventory->_previousState = _inventory->getState();
+			_inventory->setState(prevInventoryMode);
 			continue;
 		}
-		uVar6 = _inventory->getType();
+		uVar6 = _inventory->getState();
 		if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
 			_flickerIdleCounter = 0;
 			if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
 				if (_cursor->_iniUnderCursor == 0x8001) {
 					_inventory->closeInventory();
-					_inventory->setType(0);
-					if (_inventory->_old_showing_value == 2) {
+					_inventory->setState(Closed);
+					if (_inventory->_previousState == InventionBookOpen) {
 						_inventory->closeInventionBook();
 					}
 				} else {
@@ -548,19 +545,19 @@ void DragonsEngine::gameLoop() {
 							_cursor->_sequenceID = 5;
 							waitForFrames(2);
 							_inventory->closeInventory();
-							uVar6 = _inventory->_old_showing_value;
-							_inventory->_old_showing_value = _inventory->getType();
-							_inventory->setType(uVar6);
+							InventoryState prevInventoryMode = _inventory->_previousState;
+							_inventory->_previousState = _inventory->getState();
+							_inventory->setState(prevInventoryMode);
 						}
 						continue;
 					}
 					_inventory->closeInventory();
-					_inventory->setType(2);
-					if (_inventory->_old_showing_value != 2) {
+					_inventory->setState(InventionBookOpen);
+					if (_inventory->_previousState != InventionBookOpen) {
 						_inventory->openInventionBook();
 					}
 				}
-				_inventory->_old_showing_value = uVar6;
+				_inventory->_previousState = uVar6;
 				continue;
 			}
 			if (_cursor->_iniUnderCursor != 0) {
@@ -580,9 +577,9 @@ void DragonsEngine::gameLoop() {
 						_cursor->_sequenceID = 5;
 						waitForFrames(2);
 						_inventory->closeInventory();
-						uVar6 = _inventory->_old_showing_value;
-						_inventory->_old_showing_value = _inventory->getType();
-						_inventory->setType(uVar6);
+						uVar6 = _inventory->_previousState;
+						_inventory->_previousState = _inventory->getState();
+						_inventory->setState(uVar6);
 					}
 					continue;
 				}
@@ -635,9 +632,9 @@ void DragonsEngine::gameLoop() {
 			_cursor->_sequenceID = 5;
 			waitForFrames(2);
 			_inventory->closeInventory();
-			uVar6 = _inventory->_old_showing_value;
-			_inventory->_old_showing_value = _inventory->getType();
-			_inventory->setType(uVar6);
+			InventoryState prevInventoryMode = _inventory->_previousState;
+			_inventory->_previousState = _inventory->getState();
+			_inventory->setState(prevInventoryMode);
 		}
 	}
 }
@@ -1001,7 +998,7 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 		}
 
 		// 0x80027db8
-		if (!_inventory->isVisible()) {
+		if (!_inventory->isOpen()) {
 			for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 				DragonINI *ini = getINI(i);
 				if (ini->field_10 >= 0 && ini->sceneId == currentSceneId) {
@@ -1184,7 +1181,7 @@ void DragonsEngine::walkFlickerToObject() {
 		if (_cursor->_data_80072890 != 0) {
 
 			if (!(READ_LE_UINT16(_dragonOBD->getFromOpt(_cursor->_data_80072890 - 1) + 4) & 8)
-					&& (_inventory->getType() == 0) && !isFlagSet(ENGINE_FLAG_200000)) {
+				&& (_inventory->getState() == Closed) && !isFlagSet(ENGINE_FLAG_200000)) {
 				targetINI = getINI(_cursor->_data_80072890 - 1);
 				if ((targetINI->field_1a_flags_maybe & 1) == 0) {
 					if (targetINI->actorResourceId == -1) {
@@ -1221,7 +1218,7 @@ void DragonsEngine::walkFlickerToObject() {
 			_bit_flags_8006fbd8 = 3;
 			return;
 		}
-		if (_inventory->getType() == 0 && !isFlagSet(ENGINE_FLAG_200000)) {
+		if (_inventory->getState() == Closed && !isFlagSet(ENGINE_FLAG_200000)) {
 			uVar7 = (uint)(uint16)_cursor->_x;
 			uVar8 = (uint)(uint16)_cursor->_y;
 			flickerINI->actor->_walkSpeed = 0x10000;
@@ -1249,7 +1246,7 @@ bool DragonsEngine::canLoadGameStateCurrently() {
 }
 
 bool DragonsEngine::canSaveGameStateCurrently() {
-	return isInputEnabled() && _inventory->getType() != 1;
+	return isInputEnabled() && !_inventory->isOpen();
 }
 
 bool DragonsEngine::hasFeature(Engine::EngineFeature f) const {
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 7b729ae1ad..7c993eac06 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -63,10 +63,10 @@ static const int16 invYPosTable[41] = {
 };
 
 Inventory::Inventory(DragonsEngine *vm) : _vm(vm) {
-	_type = 0;
+	_state = Closed;
 	_sequenceId = 0;
 	_screenPositionIndex = 0;
-	_old_showing_value = 0;
+	_previousState = Closed;
 	_bag = NULL;
 
 	_inventionBookPrevSceneUpdateFunc = NULL;
@@ -86,8 +86,8 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 	_actor->_flags |= (ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_80 | Dragons::ACTOR_FLAG_100 |
 					   ACTOR_FLAG_200);
 	_sequenceId = 0;
-	_type = 0;
-	_old_showing_value = 0;
+	_state = Closed;
+	_previousState = Closed;
 	_bag = bag;
 
 	for (int i = 0; i < DRAGONS_MAX_INVENTORY_ITEMS; i++) {
@@ -99,7 +99,7 @@ void Inventory::init(ActorManager *actorManager, BackgroundResourceLoader *backg
 
 
 void Inventory::loadScene(uint32 sceneId) {
-	if (!_type) {
+	if (_state == Closed) {
 		_sequenceId = _vm->isFlagSet(ENGINE_FLAG_400000) ? 1 : 0;
 	}
 
@@ -234,7 +234,7 @@ void Inventory::closeInventory() {
 	if (!_vm->isFlagSet(ENGINE_FLAG_400000)) {
 		_sequenceId = 0;
 	} else {
-		if (_old_showing_value == 2) {
+		if (_previousState == InventionBookOpen) {
 			_sequenceId = 3;
 		} else {
 			_sequenceId = 1;
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index 60d215bfcf..ff45c6f654 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -38,15 +38,21 @@ class DragonINIResource;
 
 #define ACTOR_INVENTORY_OFFSET 0x17
 
+enum InventoryState {
+	Closed = 0,
+	InventoryOpen = 1,
+	InventionBookOpen = 2
+};
+
 class Inventory {
 public:
-	int16 _old_showing_value;
+	InventoryState _previousState;
 private:
 	DragonsEngine *_vm;
 	int32 _sequenceId;
 	int16 _screenPositionIndex;
 	Actor *_actor;
-	int16 _type;
+	InventoryState _state;
 	Bag *_bag;
 
 	void (*_inventionBookPrevSceneUpdateFunc)();
@@ -70,18 +76,17 @@ public:
 	void updateActorSequenceId(int32 sequenceId);
 	void resetSequenceId();
 
-	int16 getType() { return _type; }
-	void setType(int16 newType) { _type = newType; }
+	InventoryState getState() { return _state; }
+	void setState(InventoryState newState) { _state = newState; }
 
 	int16 getPositionIndex() { return _screenPositionIndex; }
 	Common::Point getPosition();
 
-	bool isVisible() {
-		return _type != 0;
+	bool isOpen() {
+		return _state != Closed;
 	}
 
-	void hide() { _type = 0; }
-	void show(int16 type) { _type = type; }
+	void close() { _state = Closed; }
 
 	void updateVisibility();
 	void setActorFlag400();
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index f6ec92d4bf..d986bacf8b 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -86,10 +86,10 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	uint16 screenShakeCounter;
 	uint8 paletteData [0x200];
 	uint16 local_28;
-	int16 originalInventoryType;
+	InventoryState originalInventoryType;
 
 	origEngineFlags = _vm->getAllFlags();
-	originalInventoryType = _vm->_inventory->getType();
+	originalInventoryType = _vm->_inventory->getState();
 	flicker = _vm->_dragonINIResource->getFlickerRecord();
 
 	Common::File *fd = new Common::File();
@@ -137,7 +137,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	_dat_80093ca4 = unkArray[local_2e6];
 	_dat_80093c90 = unkArray[local_2e6];
 	_dat_80093c94 = 0;
-	_vm->_inventory->setType(0);
+	_vm->_inventory->setState(Closed);
 	_dat_80093cb4 = 2;
 	_dat_80093cbc = 0;
 	_dat_80093cb8 = 2;
@@ -155,7 +155,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	_dat_80093cc8 = _dat_80093ca4;
 	//fade_related_calls_with_1f();
 	_vm->reset_screen_maybe();
-	_vm->_inventory->setType(0);
+	_vm->_inventory->setState(Closed);
 	flicker->sceneId = 0;
 	_vm->_dragonINIResource->setFlickerRecord(NULL);
 	_vm->setFlags(ENGINE_FLAG_800);
@@ -698,7 +698,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	//TODO FUN_80035e74((uint)uVar17);
 	//TODO FUN_80035e74((uint)uVar16);
 	_vm->_dragonINIResource->setFlickerRecord(flicker);
-	_vm->_inventory->setType(originalInventoryType);
+	_vm->_inventory->setState(originalInventoryType);
 	flicker->field_12 = local_258 + -1;
 	if (flicker->field_12 == 0) {
 		_vm->setVar(0xb, 1);
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index fd4bf27308..f709de6b24 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -115,7 +115,7 @@ void Minigame3::run() {
 	uint16 local_1a;
 	int16 local_16;
 	int16 local_14;
-	int16 origInventoryType;
+	InventoryState origInventoryType;
 	int16 local_10;
 	int16 local_e;
 	UnkStruct UnkStruct_ARRAY_800931a0[4];
@@ -168,9 +168,9 @@ void Minigame3::run() {
 	fd->close();
 	delete fd;
 
-	origInventoryType = _vm->_inventory->getType();
+	origInventoryType = _vm->_inventory->getState();
 //	fade_related_calls_with_1f();
-	_vm->_inventory->setType(0);
+	_vm->_inventory->setState(Closed);
 	_vm->reset_screen_maybe();
 	flicker = _vm->_dragonINIResource->getFlickerRecord();
 	flicker->sceneId = 0;
@@ -745,7 +745,7 @@ void Minigame3::run() {
 //	_vm->_screen->loadPalette(4, (uint)*(uint16 *)(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10) +
 //			   *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
 	_vm->_screen->updatePaletteTransparency(4, 1, 0xff, true);
-	_vm->_inventory->setType(origInventoryType);
+	_vm->_inventory->setState(origInventoryType);
 	_vm->_scene->setSceneId(origSceneId);
 	_vm->_scene->loadScene(origSceneId, 0);
 }
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 26f66e87ad..a1112f1986 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -39,17 +39,17 @@ void Minigame4::run() {
 	DragonINI *flicker;
 	uint uVar4;
 	uint16 result;
-	int16_t uVar3;
+	InventoryState uVar3;
 
 	uVar4 = _vm->getAllFlags();
-	uVar3 = _vm->_inventory->getType();
+	uVar3 = _vm->_inventory->getState();
 	flicker = _vm->_dragonINIResource->getFlickerRecord();
 	uVar1 = _vm->getCurrentSceneId();
 	// fade_related_calls_with_1f();
 	_vm->reset_screen_maybe();
 	_vm->_dragonINIResource->getFlickerRecord()->sceneId = 0;
 	_vm->_dragonINIResource->setFlickerRecord(NULL);
-	_vm->_inventory->setType(0);
+	_vm->_inventory->setState(Closed);
 	_vm->_scene->setSceneId(7);
 	_vm->_scene->loadSceneData(0x8007, 0);
 	_vm->clearFlags(ENGINE_FLAG_8);
@@ -103,7 +103,7 @@ void Minigame4::run() {
 	_vm->_videoFlags &= ~(uint16)4;
 	// EnableVSyncEvent();
 	_vm->_dragonINIResource->setFlickerRecord(flicker);
-	_vm->_inventory->setType(uVar3);
+	_vm->_inventory->setState(uVar3);
 //	_vm->_screen->loadPalette(4, (uint)*(uint16 *)
 //					(*(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8) + 10)
 //			   + *(int *)(&DAT_80071c30 + (uint)actors[0].actorFileDictionaryIndex * 8));
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 59b119caec..e840ac4e49 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -301,8 +301,8 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	// 0x8003070c
 	// TODO sub_80013b3c(); // palette related.
 
-	if (_vm->_inventory->isVisible()) {
-		_vm->_inventory->hide();
+	if (_vm->_inventory->isOpen()) {
+		_vm->_inventory->close();
 	}
 
 	if (!_vm->isFlagSet(ENGINE_FLAG_10000)) {
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index ab6c98ffca..19972b0b58 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -407,7 +407,7 @@ void ScriptOpcodes::opMoveObjectToScene(ScriptOpCall &scriptOpCall) {
 				_vm->_cursor->_iniItemInHand = 0;
 			} else {
 				if (_vm->_inventory->clearItem(ini->id + 1)) {
-					if (_vm->_inventory->getType() == 1) {
+					if (_vm->_inventory->getState() == InventoryOpen) {
 						ini->actor->clearFlag(ACTOR_FLAG_40);
 					}
 				}
@@ -417,7 +417,7 @@ void ScriptOpcodes::opMoveObjectToScene(ScriptOpCall &scriptOpCall) {
 		if (sceneId == 1) {
 			if (_vm->_cursor->_iniItemInHand != 0) {
 				_vm->_inventory->addItem(_vm->_cursor->_iniItemInHand);
-				if (_vm->_inventory->getType() == 1) {
+				if (_vm->_inventory->getState() == InventoryOpen) {
 					Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->_iniItemInHand);
 					actor->_flags = 0;
 					actor->_priorityLayer = 0;
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index dcd8eb51db..f12825fca4 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -346,14 +346,14 @@ void SpecialOpcodes::spc11ShakeScreen() {
 }
 
 void SpecialOpcodes::spcHandleInventionBookTransition() {
-	int16 invType =_vm->_inventory->getType();
-	if (invType == 1) {
+	int16 invType = _vm->_inventory->getState();
+	if (invType == InventoryOpen) {
 		_vm->_inventory->closeInventory();
-		_vm->_inventory->setType(0);
+		_vm->_inventory->setState(Closed);
 	}
-	if (invType == 2) {
+	if (invType == InventionBookOpen) {
 		_vm->_inventory->closeInventionBook();
-		_vm->_inventory->setType(0);
+		_vm->_inventory->setState(Closed);
 	}
 	_vm->_cursor->updateSequenceID(1);
 	_vm->setFlags(ENGINE_FLAG_400);
@@ -864,23 +864,23 @@ void SpecialOpcodes::spcUnk4f() {
 }
 
 void SpecialOpcodes::spcCloseInventory() {
-	if (_vm->_inventory->getType() == 1) {
+	if (_vm->_inventory->getState() == InventoryOpen) {
 		_vm->_inventory->closeInventory();
-		_vm->_inventory->setType(0);
+		_vm->_inventory->setState(Closed);
 	}
 }
 
 void SpecialOpcodes::spcOpenInventionBook() {
-	if (_vm->_inventory->getType() == 1) {
+	if (_vm->_inventory->getState() == InventoryOpen) {
 		_vm->_inventory->closeInventory();
 	}
 	_vm->_inventory->openInventionBook();
-	_vm->_inventory->setType(2);
+	_vm->_inventory->setState(InventionBookOpen);
 }
 
 void SpecialOpcodes::spcCloseInventionBook() {
 	_vm->_inventory->closeInventionBook();
-	_vm->_inventory->setType(0);
+	_vm->_inventory->setState(Closed);
 }
 
 void SpecialOpcodes::spcSetEngineFlag0x4000000() {
@@ -1200,7 +1200,7 @@ void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
 }
 
 void SpecialOpcodes::spcUseClickerOnLever() {
-	if (_vm->_inventory->getType() != 0) {
+	if (_vm->_inventory->isOpen()) {
 		_vm->_talk->flickerRandomDefaultResponse();
 		_vm->_dragonINIResource->getRecord(0)->field_12 = 1;
 	} else {


Commit: 832f38b3cd8ca0ae1fef75fd474b97cc64a2e297
    https://github.com/scummvm/scummvm/commit/832f38b3cd8ca0ae1fef75fd474b97cc64a2e297
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More code cleanups. Added paning while walking on wide scenes

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/inventory.cpp
    engines/dragons/inventory.h
    engines/dragons/scriptopcodes.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 09e91622e8..3c2ad745a6 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -56,7 +56,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	data_8007283c = 0;
 	_cursorActivationSeqOffset = 0;
 	_data_800728b0_cursor_seqID = 0;
-	_data_80072890 = 0;
+	_performActionTargetINI = 0;
 }
 
 
@@ -187,7 +187,7 @@ int16 Cursor::updateIniFromScene() {
 	int16 cursorY = _y + _vm->_scene->_camera.y;
 	int16 cursorTileX = cursorX / 32;
 	int16 cursorTileY = cursorY / 8;
-	int16 data_80072890_orig = _data_80072890;
+	int16 data_80072890_orig = _performActionTargetINI;
 	int16 data_800728b0_cursor_seqID_orig = _data_800728b0_cursor_seqID;
 
 	for (int i = 0; i <_vm->_dragonINIResource->totalRecords(); i++) {
@@ -226,11 +226,11 @@ int16 Cursor::updateIniFromScene() {
 			if (cursorOverIni != 0) {
 				// 0x80028bf0
 				// _iniUnderCursor = cursorOverIni;
-				_data_80072890 = _iniUnderCursor;
+				_performActionTargetINI = _iniUnderCursor;
 				_data_800728b0_cursor_seqID = _sequenceID;
 
 				if (ini->field_1a_flags_maybe & 0x800) {
-					_data_80072890 = cursorOverIni;
+					_performActionTargetINI = cursorOverIni;
 					uint32 newSeqId = 1;
 					for (int idx = 0; idx < 5; idx++) {
 						_data_800728b0_cursor_seqID = idx;
@@ -251,13 +251,13 @@ int16 Cursor::updateIniFromScene() {
 
 					_sequenceID = newSeqId;
 					_iniUnderCursor = cursorOverIni;
-					_data_80072890 = _iniUnderCursor;
+					_performActionTargetINI = _iniUnderCursor;
 					_data_800728b0_cursor_seqID = _sequenceID;
 					return _iniUnderCursor;
 				}
 				if (_sequenceID != 0) {
 					_iniUnderCursor = cursorOverIni;
-					_data_80072890 = data_80072890_orig;
+					_performActionTargetINI = data_80072890_orig;
 					_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
@@ -269,7 +269,7 @@ int16 Cursor::updateIniFromScene() {
 //				local_44 = local_44 + local_48;
 				if (executeScript(scriptOpCall, 0)) {
 					_iniUnderCursor = cursorOverIni;
-					_data_80072890 = data_80072890_orig;
+					_performActionTargetINI = data_80072890_orig;
 					_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
@@ -277,7 +277,7 @@ int16 Cursor::updateIniFromScene() {
 		}
 	}
 	_iniUnderCursor = 0;
-	_data_80072890 = data_80072890_orig;
+	_performActionTargetINI = data_80072890_orig;
 	_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 	return 0;
 }
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 2d103f90d4..7513b76f38 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -37,7 +37,7 @@ public:
 	int16 _data_800728b0_cursor_seqID;
 	uint16 _iniUnderCursor;
 	int32 _sequenceID;
-	int16 _data_80072890;
+	int16 _performActionTargetINI;
 	int16 _x;
 	int16 _y;
 	int16 data_8007283c;
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 9c224f2183..79286982b8 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -348,7 +348,7 @@ void DragonsEngine::gameLoop() {
 			if (flicker->sceneId == getCurrentSceneId() && flicker->actor->_direction != -1) {
 				int16 iniId = _scriptOpcodes->_scriptTargetINI;
 				if (_cursor->_sequenceID != 5) {
-					iniId = _cursor->_data_80072890;
+					iniId = _cursor->_performActionTargetINI;
 				}
 				if (iniId > 0) {
 					flicker->actor->_direction = getINI(iniId - 1)->field_e;
@@ -426,7 +426,7 @@ void DragonsEngine::gameLoop() {
 						} else {
 							if (_cursor->_iniUnderCursor != 0x8001) {
 								_flickerIdleCounter = 0;
-								_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+								_cursor->_performActionTargetINI = _cursor->_iniUnderCursor;
 								if (_cursor->_sequenceID < 5) {
 									_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 									walkFlickerToObject();
@@ -439,8 +439,8 @@ void DragonsEngine::gameLoop() {
 									if (_bit_flags_8006fbd8 != 0) {
 										clearFlags(ENGINE_FLAG_8);
 									}
-									_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
-									_cursor->_data_80072890 = _cursor->_iniItemInHand;
+									_scriptOpcodes->_scriptTargetINI = _cursor->_performActionTargetINI;
+									_cursor->_performActionTargetINI = _cursor->_iniItemInHand;
 								}
 								runINIScripts();
 								continue;
@@ -457,7 +457,7 @@ void DragonsEngine::gameLoop() {
 						}
 					}
 					_flickerIdleCounter = 0;
-					_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+					_cursor->_performActionTargetINI = _cursor->_iniUnderCursor;
 					if (_cursor->_sequenceID < 5) {
 						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 						walkFlickerToObject();
@@ -470,8 +470,8 @@ void DragonsEngine::gameLoop() {
 						if (_bit_flags_8006fbd8 != 0) {
 							clearFlags(ENGINE_FLAG_8);
 						}
-						_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
-						_cursor->_data_80072890 = _cursor->_iniItemInHand;
+						_scriptOpcodes->_scriptTargetINI = _cursor->_performActionTargetINI;
+						_cursor->_performActionTargetINI = _cursor->_iniItemInHand;
 					}
 				}
 			}
@@ -497,7 +497,7 @@ void DragonsEngine::gameLoop() {
 				}
 				if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
 					_flickerIdleCounter = 0;
-					_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+					_cursor->_performActionTargetINI = _cursor->_iniUnderCursor;
 					if (_cursor->_sequenceID < 5) {
 						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
 						walkFlickerToObject();
@@ -510,8 +510,8 @@ void DragonsEngine::gameLoop() {
 						if (_bit_flags_8006fbd8 != 0) {
 							clearFlags(ENGINE_FLAG_8);
 						}
-						_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
-						_cursor->_data_80072890 = _cursor->_iniItemInHand;
+						_scriptOpcodes->_scriptTargetINI = _cursor->_performActionTargetINI;
+						_cursor->_performActionTargetINI = _cursor->_iniItemInHand;
 					}
 				}
 			}
@@ -521,9 +521,7 @@ void DragonsEngine::gameLoop() {
 		if (checkForInventoryButtonRelease()) {
 			_flickerIdleCounter = 0;
 			_inventory->closeInventory();
-			InventoryState prevInventoryMode = _inventory->_previousState;
-			_inventory->_previousState = _inventory->getState();
-			_inventory->setState(prevInventoryMode);
+			_inventory->setPreviousState();
 			continue;
 		}
 		uVar6 = _inventory->getState();
@@ -545,9 +543,7 @@ void DragonsEngine::gameLoop() {
 							_cursor->_sequenceID = 5;
 							waitForFrames(2);
 							_inventory->closeInventory();
-							InventoryState prevInventoryMode = _inventory->_previousState;
-							_inventory->_previousState = _inventory->getState();
-							_inventory->setState(prevInventoryMode);
+							_inventory->setPreviousState();
 						}
 						continue;
 					}
@@ -563,9 +559,9 @@ void DragonsEngine::gameLoop() {
 			if (_cursor->_iniUnderCursor != 0) {
 				if ((_cursor->_sequenceID != 4) && (_cursor->_sequenceID != 2)) {
 					_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-					_cursor->_data_80072890 = _cursor->_iniUnderCursor;
+					_cursor->_performActionTargetINI = _cursor->_iniUnderCursor;
 					if (_cursor->_sequenceID >= 4) {
-						_cursor->_data_80072890 = _cursor->_iniItemInHand;
+						_cursor->_performActionTargetINI = _cursor->_iniItemInHand;
 						_scriptOpcodes->_scriptTargetINI = _cursor->_iniUnderCursor;
 					}
 					clearFlags(ENGINE_FLAG_8);
@@ -577,9 +573,7 @@ void DragonsEngine::gameLoop() {
 						_cursor->_sequenceID = 5;
 						waitForFrames(2);
 						_inventory->closeInventory();
-						uVar6 = _inventory->_previousState;
-						_inventory->_previousState = _inventory->getState();
-						_inventory->setState(uVar6);
+						_inventory->setPreviousState();
 					}
 					continue;
 				}
@@ -632,9 +626,7 @@ void DragonsEngine::gameLoop() {
 			_cursor->_sequenceID = 5;
 			waitForFrames(2);
 			_inventory->closeInventory();
-			InventoryState prevInventoryMode = _inventory->_previousState;
-			_inventory->_previousState = _inventory->getState();
-			_inventory->setState(prevInventoryMode);
+			_inventory->setPreviousState();
 		}
 	}
 }
@@ -646,6 +638,8 @@ void DragonsEngine::updateHandler() {
 
 	updateActorSequences();
 
+	updateCamera();
+
 	_cursor->updateVisibility();
 	_inventory->updateVisibility();
 
@@ -877,142 +871,60 @@ void DragonsEngine::runINIScripts() {
 		setFlags(ENGINE_FLAG_8);
 	}
 }
-/*
+
 void DragonsEngine::engineFlag0x20UpdateFunction() {
-{
-	uint16 uVar1;
-	uint16 uVar2;
-	DragonINI *pDVar3;
-	DragonINI *pDVar4;
-	uint16 uVar5;
-	uint actorId;
+	if (!isFlagSet(ENGINE_FLAG_20)) {
+		_run_func_ptr_unk_countdown_timer = 1;
+		return;
+	}
 
-	DragonINI *flickerINI = _dragonINIResource->getFlickerRecord();
-	uint16 currentSceneId = _scene->getSceneId();
+	if (isFlagSet(ENGINE_FLAG_8) && !isFlagSet(ENGINE_FLAG_80000000)) {
+		_cursor->update();
+	}
 
+	uint16 currentSceneId = _scene->getSceneId();
+	DragonINI *flickerINI = _dragonINIResource->getFlickerRecord();
+	DragonINI *ini1 = getINI(1);
 
-//	uVar1 = flickerINI->actorId;
-//	actorId = (uint)uVar1;
-//	uVar5 = dragon_ini_pointer[dragon_ini_const__2 + -1].field_0x1c;
-	if (flickerINI == NULL) {
-		//LAB_80027d40:
-//		if ((flickerINI->sceneId == currentSceneId)
-//			&& (uVar5 != 0xffff)) {
-//			actors[(uint)uVar5]._sequenceID = 8;
-//			actors[(uint)uVar5]._priorityLayer_maybe = 0;
-//		}
-	} else {
+	if (flickerINI != NULL) {
 		if (flickerINI->sceneId == currentSceneId) {
-			if ((flickerINI == NULL) || flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
-				if ((flickerINI->sceneId == currentSceneId)
-					&& (uVar5 != 0xffff)) {
-//					actors[(uint)uVar5]._sequenceID = 8;
-//					actors[(uint)uVar5]._priorityLayer_maybe = 0;
+			if (flickerINI->actor == NULL || flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
+				if (ini1->actor != NULL) {
+					ini1->actor->updateSequence(8);
+					ini1->actor->_priorityLayer = 0;
 				}
 			} else {
-				if ((_bit_flags_8006fbd8 & 2) == 0) {
-					_bit_flags_8006fbd8 = _bit_flags_8006fbd8 | 2;
+				if ((_bit_flags_8006fbd8 & 2u) == 0) {
+					_bit_flags_8006fbd8 |= 2u;
 				}
-//				if (((((actors[actorId]._flags & 0x2000) == 0) && ((actors[actorId]._flags & 4) != 0)) &&
-//					 (actors[actorId]._direction != actors[actorId]._sequenceID)) &&
-//				(actors[actorId]._direction != -1)) {
-//					actor_update_sequenceID(actorId, actors[actorId]._direction);
-//				}
-			}
-
-		} else {
-			//actors[(uint)uVar5]._priorityLayer_maybe = 0;
-		}
-
-	}
-
-
-	LAB_80027db4:
-	uVar1 = num_ini_records_maybe;
-	pDVar3 = dragon_ini_pointer;
-	uVar2 = currentSceneId;
-	if ((inventoryType == 0) && (uVar5 = 0, num_ini_records_maybe != 0)) {
-		actorId = 0;
-		do {
-			pDVar4 = pDVar3 + actorId;
-			if (((-1 < (int)((uint)pDVar4->field_0x10 << 0x10)) && (pDVar4->sceneId_maybe == uVar2)) &&
-				(pDVar4->field_0x10 = pDVar4->field_0x10 - 1, (int)((uint)pDVar4->field_0x10 << 0x10) < 0))
-			{
-				pDVar4->field_1a_flags_maybe = pDVar4->field_1a_flags_maybe | 0x10;
-			}
-			uVar5 = uVar5 + 1;
-			actorId = (uint)uVar5;
-		} while (uVar5 < uVar1);
-	}
-	if (_run_func_ptr_unk_countdown_timer != 0) {
-		_run_func_ptr_unk_countdown_timer = _run_func_ptr_unk_countdown_timer - 1;
-	}
-	return (uint)_run_func_ptr_unk_countdown_timer;
-} */
-
-//TODO the logic in this function doesn't match the original. It should be redone.
-void DragonsEngine::engineFlag0x20UpdateFunction() {
-	if (isFlagSet(ENGINE_FLAG_20)) {
-		if (isFlagSet(ENGINE_FLAG_8) && !isFlagSet(ENGINE_FLAG_80000000)) {
-			_cursor->update();
-		}
-		//TODO 0x80027be4
-
-		uint16 currentSceneId = _scene->getSceneId();
-		DragonINI *flickerINI = _dragonINIResource->getFlickerRecord();
-
-
-//	uVar1 = flickerINI->actorId;
-//	actorId = (uint)uVar1;
-//	uVar5 = dragon_ini_pointer[dragon_ini_const__2 + -1].field_0x1c;
-		if (flickerINI == NULL) {
-			//LAB_80027d40:
-			//error("LAB_80027d40"); //TODO is this logic required?
-//		if ((flickerINI->sceneId == currentSceneId)
-//			&& (uVar5 != 0xffff)) {
-//			actors[(uint)uVar5]._sequenceID = 8;
-//			actors[(uint)uVar5]._priorityLayer_maybe = 0;
-//		}
-		} else {
-			if (flickerINI->sceneId == currentSceneId) {
-				if (flickerINI->actor->isFlagSet(ACTOR_FLAG_10)) {
-					if (_inventory->isActorSet()) {
-						_inventory->setActorSequenceId(8);
-						_inventory->setPriority(0);
-					}
-				} else {
-					if ((_bit_flags_8006fbd8 & 2u) == 0) {
-						_bit_flags_8006fbd8 |= 2u;
-					}
-					if (flickerINI->actor->isFlagClear(ACTOR_FLAG_2000)
-							&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
-							&& flickerINI->actor->_direction != -1
-							&& flickerINI->actor->_direction != flickerINI->actor->_sequenceID) {
-						flickerINI->actor->updateSequence(flickerINI->actor->_direction);
-					}
+				if (flickerINI->actor->isFlagClear(ACTOR_FLAG_2000)
+						&& flickerINI->actor->isFlagSet(ACTOR_FLAG_4)
+						&& flickerINI->actor->_direction != -1
+						&& flickerINI->actor->_direction != flickerINI->actor->_sequenceID) {
+					flickerINI->actor->updateSequence(flickerINI->actor->_direction);
+				}
+				if (ini1->actor != NULL) {
+					ini1->actor->_priorityLayer = 0;
 				}
-			} else {
-				_inventory->setPriority(0); //TODO I don't think this is quite right.
 			}
-
 		}
+	}
 
-		// 0x80027db8
-		if (!_inventory->isOpen()) {
-			for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
-				DragonINI *ini = getINI(i);
-				if (ini->field_10 >= 0 && ini->sceneId == currentSceneId) {
-					ini->field_10--;
-					if (ini->field_10 < 0) {
-						ini->field_1a_flags_maybe |= INI_FLAG_10;
-					}
+	// 0x80027db8
+	if (!_inventory->isOpen()) {
+		for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
+			DragonINI *ini = getINI(i);
+			if (ini->field_10 >= 0 && ini->sceneId == currentSceneId) {
+				ini->field_10--;
+				if (ini->field_10 < 0) {
+					ini->field_1a_flags_maybe |= INI_FLAG_10;
 				}
 			}
 		}
+	}
 
-		if (_run_func_ptr_unk_countdown_timer != 0) {
-			_run_func_ptr_unk_countdown_timer--;
-		}
+	if (_run_func_ptr_unk_countdown_timer != 0) {
+		_run_func_ptr_unk_countdown_timer--;
 	}
 }
 
@@ -1084,8 +996,8 @@ void DragonsEngine::performAction() {
 	uVar6 = 0;
 	_scriptOpcodes->_data_80071f5c = 0;
 
-	assert(_cursor->_data_80072890 > 0);
-	byte *obd = _dragonOBD->getFromOpt(_cursor->_data_80072890 - 1);
+	assert(_cursor->_performActionTargetINI > 0);
+	byte *obd = _dragonOBD->getFromOpt(_cursor->_performActionTargetINI - 1);
 
 
 	ScriptOpCall local_48(obd + 8, READ_LE_UINT32(obd));
@@ -1097,7 +1009,7 @@ void DragonsEngine::performAction() {
 		_scriptOpcodes->_data_80071f5c = 0;
 
 		obd = _dragonOBD->getFromOpt(_scriptOpcodes->_scriptTargetINI - 1);
-		_scriptOpcodes->_scriptTargetINI = _cursor->_data_80072890;
+		_scriptOpcodes->_scriptTargetINI = _cursor->_performActionTargetINI;
 
 		ScriptOpCall local_38(obd + 8, READ_LE_UINT32(obd));
 
@@ -1178,11 +1090,11 @@ void DragonsEngine::walkFlickerToObject() {
 
 	flickerINI = _dragonINIResource->getFlickerRecord();
 	if (flickerINI->sceneId == getCurrentSceneId()) {
-		if (_cursor->_data_80072890 != 0) {
+		if (_cursor->_performActionTargetINI != 0) {
 
-			if (!(READ_LE_UINT16(_dragonOBD->getFromOpt(_cursor->_data_80072890 - 1) + 4) & 8)
+			if (!(READ_LE_UINT16(_dragonOBD->getFromOpt(_cursor->_performActionTargetINI - 1) + 4) & 8)
 				&& (_inventory->getState() == Closed) && !isFlagSet(ENGINE_FLAG_200000)) {
-				targetINI = getINI(_cursor->_data_80072890 - 1);
+				targetINI = getINI(_cursor->_performActionTargetINI - 1);
 				if ((targetINI->field_1a_flags_maybe & 1) == 0) {
 					if (targetINI->actorResourceId == -1) {
 						return;
@@ -1200,7 +1112,7 @@ void DragonsEngine::walkFlickerToObject() {
 				}
 				flickerINI->actor->startWalk((int)(((uint)targetX + (uint)targetINI->field_1c) * 0x10000) >> 0x10,
 													(int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10, 0);
-				_bit_flags_8006fbd8 = 1;
+				_bit_flags_8006fbd8 = 1; //walk to perform an action.
 				return;
 			}
 			if (isFlagSet(ENGINE_FLAG_200000)) {
@@ -1211,7 +1123,7 @@ void DragonsEngine::walkFlickerToObject() {
 			if (flickerINI != NULL && flickerINI->actor != NULL) {
 				flickerINI->actor->clearFlag(ACTOR_FLAG_10);
 				flickerINI->actor->setFlag(ACTOR_FLAG_4);
-				targetINI = getINI(_cursor->_data_80072890 - 1);
+				targetINI = getINI(_cursor->_performActionTargetINI - 1);
 				flickerINI->field_20_actor_field_14 = targetINI->field_e;
 				flickerINI->actor->_direction = targetINI->field_e;
 			}
@@ -1227,7 +1139,7 @@ void DragonsEngine::walkFlickerToObject() {
 					(int)((uVar8 + (uint)_scene->_camera.y) * 0x10000) >> 0x10, 0);
 		}
 	} else {
-		if (_cursor->_data_80072890 != 0) {
+		if (_cursor->_performActionTargetINI != 0) {
 			_bit_flags_8006fbd8 = 3;
 			return;
 		}
@@ -1537,6 +1449,44 @@ void DragonsEngine::updateFlickerIdleAnimation() {
 	}
 }
 
+void DragonsEngine::updateCamera() {
+	if (isFlagSet(ENGINE_FLAG_40) && !isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
+		return;
+	}
+
+	if (isFlagSet(ENGINE_FLAG_1) && !isUnkFlagSet(ENGINE_UNK1_FLAG_2)) { //TODO original doesn't seem to check for flag 2 here. adding to get cutscenes to work.
+		DragonINI *flicker = _dragonINIResource->getFlickerRecord();
+		if (flicker && flicker->sceneId != 0) {
+			if ((flicker->actor->_x_pos - _scene->_camera.x >= 0x4f)) {
+				if (flicker->actor->_x_pos - _scene->_camera.x >= 0xf0) {
+					_scene->_camera.x = flicker->actor->_x_pos - 0xf0;
+				}
+			} else {
+				_scene->_camera.x = flicker->actor->_x_pos - 0x50;
+			}
+
+			int16 sVar4 = flicker->actor->_y_pos + -0x1e;
+			if (((int)flicker->actor->_y_pos - (int)_scene->_camera.y < 0x1e) ||
+				(sVar4 = flicker->actor->_y_pos + -0xaa, 0xaa < (int)flicker->actor->_y_pos - (int)_scene->_camera.y)) {
+				_scene->_camera.y = sVar4;
+			}
+		}
+
+		if (_scene->_camera.x < 0) {
+			_scene->_camera.x = 0;
+		}
+		if (_scene->getStageWidth() < _scene->_camera.x + 0x140) {
+			_scene->_camera.x = _scene->getStageWidth() - 0x140;
+		}
+		if (_scene->_camera.y < 0) {
+			_scene->_camera.y = 0;
+		}
+		if (_scene->getStageHeight() < _scene->_camera.y + 200) {
+			_scene->_camera.y = _scene->getStageHeight() + -200;
+		}
+	}
+}
+
 void (*DragonsEngine::getSceneUpdateFunction())() {
 	return _sceneUpdateFunction;
 }
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 6c1aaf21e1..1cd0777f9d 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -295,6 +295,7 @@ private:
 	void updatePathfindingActors();
 	void updatePaletteCycling();
 	void updateFlickerIdleAnimation();
+	void updateCamera();
 
 	uint32 calulateTimeLeft();
 	void wait();
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index 7c993eac06..abcf4056b6 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -423,4 +423,10 @@ void Inventory::inventoryMissing() {
 	}
 }
 
+void Inventory::setPreviousState() {
+	InventoryState tmpState = _state;
+	setState(_previousState);
+	_previousState = tmpState;
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/inventory.h b/engines/dragons/inventory.h
index ff45c6f654..714b8f98ee 100644
--- a/engines/dragons/inventory.h
+++ b/engines/dragons/inventory.h
@@ -78,6 +78,7 @@ public:
 
 	InventoryState getState() { return _state; }
 	void setState(InventoryState newState) { _state = newState; }
+	void setPreviousState();
 
 	int16 getPositionIndex() { return _screenPositionIndex; }
 	Common::Point getPosition();
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 19972b0b58..305983b159 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -318,7 +318,7 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 
 	int16 uVar6 = _scriptTargetINI;
 	int16 uVar5 = _vm->_cursor->_data_800728b0_cursor_seqID;
-	int16 uVar4 = _vm->_cursor->_data_80072890;
+	int16 uVar4 = _vm->_cursor->_performActionTargetINI;
 	int16 uVar3 = _vm->_cursor->_iniUnderCursor;
 	int32 uVar2 = _vm->_cursor->_sequenceID;
 	bool isEngineFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
@@ -333,7 +333,7 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 
 	_scriptTargetINI = field6;
 	_vm->_cursor->_data_800728b0_cursor_seqID = _vm->_cursor->_sequenceID;
-	_vm->_cursor->_data_80072890 = _vm->_cursor->_iniUnderCursor;
+	_vm->_cursor->_performActionTargetINI = _vm->_cursor->_iniUnderCursor;
 //	EnableVSyncEvent();
 	_vm->performAction();
 	if (isEngineFlag8Set) {
@@ -341,7 +341,7 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	}
 	_vm->_cursor->_sequenceID = uVar2;
 	_vm->_cursor->_iniUnderCursor = uVar3;
-	_vm->_cursor->_data_80072890 = uVar4;
+	_vm->_cursor->_performActionTargetINI = uVar4;
 	_vm->_cursor->_data_800728b0_cursor_seqID = uVar5;
 	_scriptTargetINI = uVar6;
 }


Commit: 5c5eb3ad8ba544093c3ee9b504a1d21377fb212a
    https://github.com/scummvm/scummvm/commit/5c5eb3ad8ba544093c3ee9b504a1d21377fb212a
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: More code cleanup. Stop audio on exit.

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/sound.cpp


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 3c2ad745a6..1442ff4b8f 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -53,7 +53,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= INI_FLAG_1;
 	_iniUnderCursor = 0;
 	_iniItemInHand = 0;
-	data_8007283c = 0;
+	_data_8007283c_objectInHandSequenceID = 0;
 	_cursorActivationSeqOffset = 0;
 	_data_800728b0_cursor_seqID = 0;
 	_performActionTargetINI = 0;
@@ -101,14 +101,14 @@ void Cursor::update() {
 	if (_iniUnderCursor != 0x8002 || (inventorySequenceID != 1 && inventorySequenceID != 3)) {
 		if ((_iniUnderCursor != 0x8001) || ((inventorySequenceID != 0 && (inventorySequenceID != 3)))) {
 			if (_sequenceID == 5) {
-				uint16 uVar1 = (uint) data_8007283c;
+				uint16 uVar1 = (uint) _data_8007283c_objectInHandSequenceID;
 				if (_cursorActivationSeqOffset != 0) {
 					uVar1 = uVar1 + 1;
 				}
 				if (uVar1 == (uint) _actor->_sequenceID) {
 					return;
 				}
-				_actor->updateSequence((uint) data_8007283c + (uint) (_cursorActivationSeqOffset != 0));
+				_actor->updateSequence((uint) _data_8007283c_objectInHandSequenceID + (uint) (_cursorActivationSeqOffset != 0));
 			} else {
 				if (_sequenceID + (uint) _cursorActivationSeqOffset != (uint) _actor->_sequenceID) {
 					_actor->updateSequence(_sequenceID + (uint) _cursorActivationSeqOffset);
@@ -124,8 +124,8 @@ void Cursor::update() {
 		}
 		return;
 	} else {
-		if ((uint)_actor->_sequenceID != (uint)data_8007283c + 1) {
-			_actor->updateSequence((uint)data_8007283c + 1);
+		if ((uint)_actor->_sequenceID != (uint)_data_8007283c_objectInHandSequenceID + 1) {
+			_actor->updateSequence((uint)_data_8007283c_objectInHandSequenceID + 1);
 		}
 	}
 
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 7513b76f38..8331dbc7ae 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -40,7 +40,7 @@ public:
 	int16 _performActionTargetINI;
 	int16 _x;
 	int16 _y;
-	int16 data_8007283c;
+	int16 _data_8007283c_objectInHandSequenceID;
 	int16 _cursorActivationSeqOffset;
 	uint16 _iniItemInHand;
 
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 79286982b8..d85fbb589a 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -427,18 +427,12 @@ void DragonsEngine::gameLoop() {
 							if (_cursor->_iniUnderCursor != 0x8001) {
 								_flickerIdleCounter = 0;
 								_cursor->_performActionTargetINI = _cursor->_iniUnderCursor;
-								if (_cursor->_sequenceID < 5) {
-									_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-									walkFlickerToObject();
-									if (_bit_flags_8006fbd8 != 0) {
-										clearFlags(ENGINE_FLAG_8);
-									}
-								} else {
-									_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-									walkFlickerToObject();
-									if (_bit_flags_8006fbd8 != 0) {
-										clearFlags(ENGINE_FLAG_8);
-									}
+								_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+								walkFlickerToObject();
+								if (_bit_flags_8006fbd8 != 0) {
+									clearFlags(ENGINE_FLAG_8);
+								}
+								if (_cursor->_sequenceID >= 5) {
 									_scriptOpcodes->_scriptTargetINI = _cursor->_performActionTargetINI;
 									_cursor->_performActionTargetINI = _cursor->_iniItemInHand;
 								}
@@ -458,18 +452,12 @@ void DragonsEngine::gameLoop() {
 					}
 					_flickerIdleCounter = 0;
 					_cursor->_performActionTargetINI = _cursor->_iniUnderCursor;
-					if (_cursor->_sequenceID < 5) {
-						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-						walkFlickerToObject();
-						if (_bit_flags_8006fbd8 != 0) {
-							clearFlags(ENGINE_FLAG_8);
-						}
-					} else {
-						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-						walkFlickerToObject();
-						if (_bit_flags_8006fbd8 != 0) {
-							clearFlags(ENGINE_FLAG_8);
-						}
+					_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+					walkFlickerToObject();
+					if (_bit_flags_8006fbd8 != 0) {
+						clearFlags(ENGINE_FLAG_8);
+					}
+					if (_cursor->_sequenceID >= 5) {
 						_scriptOpcodes->_scriptTargetINI = _cursor->_performActionTargetINI;
 						_cursor->_performActionTargetINI = _cursor->_iniItemInHand;
 					}
@@ -498,18 +486,12 @@ void DragonsEngine::gameLoop() {
 				if (checkForActionButtonRelease() && isFlagSet(ENGINE_FLAG_8)) {
 					_flickerIdleCounter = 0;
 					_cursor->_performActionTargetINI = _cursor->_iniUnderCursor;
-					if (_cursor->_sequenceID < 5) {
-						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-						walkFlickerToObject();
-						if (_bit_flags_8006fbd8 != 0) {
-							clearFlags(ENGINE_FLAG_8);
-						}
-					} else {
-						_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
-						walkFlickerToObject();
-						if (_bit_flags_8006fbd8 != 0) {
-							clearFlags(ENGINE_FLAG_8);
-						}
+					_cursor->_data_800728b0_cursor_seqID = _cursor->_sequenceID;
+					walkFlickerToObject();
+					if (_bit_flags_8006fbd8 != 0) {
+						clearFlags(ENGINE_FLAG_8);
+					}
+					if (_cursor->_sequenceID >= 5) {
 						_scriptOpcodes->_scriptTargetINI = _cursor->_performActionTargetINI;
 						_cursor->_performActionTargetINI = _cursor->_iniItemInHand;
 					}
@@ -580,7 +562,7 @@ void DragonsEngine::gameLoop() {
 				Actor *actor = _inventory->getInventoryItemActor(_cursor->_iniUnderCursor);
 				uint16 tmpId = _cursor->_iniItemInHand;
 				_inventory->replaceItem(_cursor->_iniUnderCursor, _cursor->_iniItemInHand);
-				_cursor->data_8007283c = actor->_sequenceID;
+				_cursor->_data_8007283c_objectInHandSequenceID = actor->_sequenceID;
 				actor->clearFlag(ACTOR_FLAG_40);
 				_cursor->_iniItemInHand = _cursor->_iniUnderCursor;
 				_cursor->_sequenceID = 5;
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 305983b159..fa57e09d14 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -435,7 +435,7 @@ void ScriptOpcodes::opMoveObjectToScene(ScriptOpCall &scriptOpCall) {
 										 flicker->actor->_y_pos - (_vm->_scene->_camera.y + 0x1e));
 			_vm->_cursor->_data_800728b0_cursor_seqID = 5;
 			_vm->_cursor->_sequenceID = 5;
-			_vm->_cursor->data_8007283c = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
+			_vm->_cursor->_data_8007283c_objectInHandSequenceID = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
 			_vm->_cursor->_iniItemInHand = field2;
 		}
 	}
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index 36d1b17ee8..cf4f79f543 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -265,6 +265,12 @@ SoundManager::SoundManager(DragonsEngine *vm, BigfileArchive *bigFileArchive, Dr
 }
 
 SoundManager::~SoundManager() {
+	if (isSpeechPlaying()) {
+		_vm->_mixer->stopHandle(_speechHandle);
+	}
+
+	stopAllVoices();
+
 	delete _vabMusx;
 	delete _vabGlob;
 }


Commit: f10f1f5e6a34aa60d3507f44179eb5685e3f4a0c
    https://github.com/scummvm/scummvm/commit/f10f1f5e6a34aa60d3507f44179eb5685e3f4a0c
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Improve method/variable names

Changed paths:
    engines/dragons/actor.h
    engines/dragons/cursor.cpp
    engines/dragons/cursor.h
    engines/dragons/dragons.cpp
    engines/dragons/dragons.h
    engines/dragons/minigame1.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/scene.cpp
    engines/dragons/scene.h
    engines/dragons/scriptopcodes.cpp
    engines/dragons/scriptopcodes.h
    engines/dragons/sequenceopcodes.cpp
    engines/dragons/sequenceopcodes.h
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index f21d11d326..3cc7c3d6bf 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -93,7 +93,7 @@ public:
 	void* _frame_pointer_maybe;
 	ActorFrame *_frame;
 	Graphics::Surface *_surface;
-	uint16 _field_c;
+	uint16 _sequenceTimerMaxValue;
 	int16 _scale; // scale factor 0x100 is 100%
 	uint16 _sequenceTimer;
 	uint16 _sequenceID;
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index 1442ff4b8f..f679ffa52e 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -53,7 +53,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= INI_FLAG_1;
 	_iniUnderCursor = 0;
 	_iniItemInHand = 0;
-	_data_8007283c_objectInHandSequenceID = 0;
+	_objectInHandSequenceID = 0;
 	_cursorActivationSeqOffset = 0;
 	_data_800728b0_cursor_seqID = 0;
 	_performActionTargetINI = 0;
@@ -101,14 +101,14 @@ void Cursor::update() {
 	if (_iniUnderCursor != 0x8002 || (inventorySequenceID != 1 && inventorySequenceID != 3)) {
 		if ((_iniUnderCursor != 0x8001) || ((inventorySequenceID != 0 && (inventorySequenceID != 3)))) {
 			if (_sequenceID == 5) {
-				uint16 uVar1 = (uint) _data_8007283c_objectInHandSequenceID;
+				uint16 uVar1 = (uint) _objectInHandSequenceID;
 				if (_cursorActivationSeqOffset != 0) {
 					uVar1 = uVar1 + 1;
 				}
 				if (uVar1 == (uint) _actor->_sequenceID) {
 					return;
 				}
-				_actor->updateSequence((uint) _data_8007283c_objectInHandSequenceID + (uint) (_cursorActivationSeqOffset != 0));
+				_actor->updateSequence((uint) _objectInHandSequenceID + (uint) (_cursorActivationSeqOffset != 0));
 			} else {
 				if (_sequenceID + (uint) _cursorActivationSeqOffset != (uint) _actor->_sequenceID) {
 					_actor->updateSequence(_sequenceID + (uint) _cursorActivationSeqOffset);
@@ -124,8 +124,8 @@ void Cursor::update() {
 		}
 		return;
 	} else {
-		if ((uint)_actor->_sequenceID != (uint)_data_8007283c_objectInHandSequenceID + 1) {
-			_actor->updateSequence((uint)_data_8007283c_objectInHandSequenceID + 1);
+		if ((uint)_actor->_sequenceID != (uint)_objectInHandSequenceID + 1) {
+			_actor->updateSequence((uint)_objectInHandSequenceID + 1);
 		}
 	}
 
@@ -288,7 +288,7 @@ int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 
 	scriptOpCall._field8 = 1;
 	scriptOpCall._result = 0;
-	_vm->_scriptOpcodes->_data_80071f5c = 0;
+	_vm->_scriptOpcodes->_numDialogStackFramesToPop = 0;
 	_vm->_scriptOpcodes->executeScriptLoop(scriptOpCall);
 
 	if (!(scriptOpCall._result & 1) && _data_800728b0_cursor_seqID == 5 && unkFlag != 0) {
@@ -296,7 +296,7 @@ int16 Cursor::executeScript(ScriptOpCall &scriptOpCall, uint16 unkFlag) {
 		scriptOpCall._code = codeStart;
 		scriptOpCall._field8 = 1;
 		scriptOpCall._result = 0;
-		_vm->_scriptOpcodes->_data_80071f5c = 0;
+		_vm->_scriptOpcodes->_numDialogStackFramesToPop = 0;
 		_vm->_scriptOpcodes->executeScriptLoop(scriptOpCall);
 		_vm->_scriptOpcodes->_scriptTargetINI = temp;
 		if (scriptOpCall._result & 1) {
diff --git a/engines/dragons/cursor.h b/engines/dragons/cursor.h
index 8331dbc7ae..9c83d8f635 100644
--- a/engines/dragons/cursor.h
+++ b/engines/dragons/cursor.h
@@ -40,7 +40,7 @@ public:
 	int16 _performActionTargetINI;
 	int16 _x;
 	int16 _y;
-	int16 _data_8007283c_objectInHandSequenceID;
+	int16 _objectInHandSequenceID;
 	int16 _cursorActivationSeqOffset;
 	uint16 _iniItemInHand;
 
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index d85fbb589a..4c23f90bb6 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -562,7 +562,7 @@ void DragonsEngine::gameLoop() {
 				Actor *actor = _inventory->getInventoryItemActor(_cursor->_iniUnderCursor);
 				uint16 tmpId = _cursor->_iniItemInHand;
 				_inventory->replaceItem(_cursor->_iniUnderCursor, _cursor->_iniItemInHand);
-				_cursor->_data_8007283c_objectInHandSequenceID = actor->_sequenceID;
+				_cursor->_objectInHandSequenceID = actor->_sequenceID;
 				actor->clearFlag(ACTOR_FLAG_40);
 				_cursor->_iniItemInHand = _cursor->_iniUnderCursor;
 				_cursor->_sequenceID = 5;
@@ -976,7 +976,7 @@ void DragonsEngine::performAction() {
 	local_58_codeEnd = NULL;
 
 	uVar6 = 0;
-	_scriptOpcodes->_data_80071f5c = 0;
+	_scriptOpcodes->_numDialogStackFramesToPop = 0;
 
 	assert(_cursor->_performActionTargetINI > 0);
 	byte *obd = _dragonOBD->getFromOpt(_cursor->_performActionTargetINI - 1);
@@ -988,7 +988,7 @@ void DragonsEngine::performAction() {
 
 	uVar4 = _cursor->executeScript(local_48, 1);
 	if (_cursor->_data_800728b0_cursor_seqID > 4) {
-		_scriptOpcodes->_data_80071f5c = 0;
+		_scriptOpcodes->_numDialogStackFramesToPop = 0;
 
 		obd = _dragonOBD->getFromOpt(_scriptOpcodes->_scriptTargetINI - 1);
 		_scriptOpcodes->_scriptTargetINI = _cursor->_performActionTargetINI;
@@ -1024,7 +1024,7 @@ void DragonsEngine::performAction() {
 			_talk->flickerRandomDefaultResponse();
 		}
 	} else {
-		_scriptOpcodes->_data_80071f5c--;
+		_scriptOpcodes->_numDialogStackFramesToPop--;
 	}
 	_flags |= uVar1 & ENGINE_FLAG_8;
 	return;
@@ -1202,7 +1202,7 @@ void DragonsEngine::reset() {
 	_unkFlags1 = 0;
 	_run_func_ptr_unk_countdown_timer = 0;
 	_videoFlags = 0;
-	_data_800633fa = 0;
+	_flickerInitialSceneDirection = 0;
 
 	for (int i = 0; i < 8; i++) {
 		_paletteCyclingTbl[i].paletteType = 0;
diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 1cd0777f9d..a9ba671e30 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -136,7 +136,7 @@ public:
 	FontManager *_fontManager;
 	ScriptOpcodes *_scriptOpcodes;
 	Scene *_scene;
-	uint16 _data_800633fa;
+	uint16 _flickerInitialSceneDirection;
 	Inventory *_inventory;
 	Cursor *_cursor;
 	Credits *_credits;
@@ -145,7 +145,7 @@ public:
 
 	PaletteCyclingInstruction _paletteCyclingTbl[8];
 
-	uint16 _data_800633fc;
+	bool _isLoadingDialogAudio;
 	uint16 _videoFlags; // TODO move to screen?
 
 	void loadCurrentSceneMsf();
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 6b26b6144c..55585440d3 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -87,7 +87,7 @@ void Minigame1::run() {
 	uint16 local_130 [10];
 	int32 local_118 [22];
 	uint32 local_c0 [22];
-	uint16 actorFieldC;
+	uint16 actorSequenceTimerStartValue;
 
 	Actor *catActor;
 	Actor *pusherActor;
@@ -235,7 +235,7 @@ void Minigame1::run() {
 	dustSpriteActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	uVar1 = _vm->getINI(DAT_80063a48 - 1)->actor; //dragon_ini_pointer[DAT_80063a48 + -1].actorId;
 	local_21e = 0;
-	actorFieldC = uVar1->_field_c;
+	actorSequenceTimerStartValue = uVar1->_sequenceTimerMaxValue;
 	_vm->setFlags(ENGINE_FLAG_4000000);
 	local_23e = 0x3700;
 	local_23a = 0x100;
@@ -261,7 +261,7 @@ void Minigame1::run() {
 				_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
 			}
 			if ((local_21e == 1) && (local_252 == 0)) {
-				uVar1->_field_c = actorFieldC;
+				uVar1->_sequenceTimerMaxValue = actorSequenceTimerStartValue;
 			}
 			if (local_21e != 0) {
 				local_21e = local_21e + -1;
@@ -412,7 +412,7 @@ void Minigame1::run() {
 						i = i + 1;
 					}
 					if ((i != 8) && (local_188[(uint)i] != 0)) {
-						uVar1->_field_c = 2;
+						uVar1->_sequenceTimerMaxValue = 2;
 						local_21e = 0x3c;
 						if (local_250 != 0) {
 							_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
@@ -863,7 +863,7 @@ void Minigame1::run() {
 	flickerActor->_priorityLayer = 6; //TODO this is 2 in the original but that leave flicker invisible.
 	_vm->clearFlags(ENGINE_FLAG_4000000);
 	_vm->setFlags(savedEngineFlags);
-	uVar1->_field_c = actorFieldC;
+	uVar1->_sequenceTimerMaxValue = actorSequenceTimerStartValue;
 	return;
 }
 
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index acc04ffa7d..22a44f968b 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -161,7 +161,7 @@ void Minigame5::run() {
 	dustActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	local_4e = _vm->_dragonINIResource->getRecord(DAT_80063a48 + -1)->actor;
 	local_4c = 0;
-	local_4a = local_4e->_field_c;
+	local_4a = local_4e->_sequenceTimerMaxValue;
 	_vm->setFlags(ENGINE_FLAG_4000000);
 	currentState = 1;
 	local_66 = 0;
@@ -327,7 +327,7 @@ void Minigame5::run() {
 								currentState = 4;
 							}
 						} else {
-							local_4e->_field_c = 2;
+							local_4e->_sequenceTimerMaxValue = 2;
 							local_4c = 0x3c;
 							bombActor->_priorityLayer = 0;
 							currentState = 8;
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index e840ac4e49..21a1be63b7 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -38,7 +38,7 @@ namespace Dragons {
 
 Scene::Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, ActorManager *actorManager, DragonRMS *dragonRMS, DragonINIResource *dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader)
 		: _vm(vm), _screen(screen), _scriptOpcodes(scriptOpcodes), _stage(0), _actorManager(actorManager), _dragonRMS(dragonRMS), _dragonINIResource(dragonINIResource), _backgroundLoader(backgroundResourceLoader) {
-	_data_80063392 = 2;
+	_mapTransitionEffectSceneID = 2;
 	_data_800633ee = 0;
 }
 void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
@@ -214,7 +214,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	_vm->setFlags(ENGINE_FLAG_200);
 	_actorManager->clearActorFlags(2);
-	_vm->_data_800633fc = 0;
+	_vm->_isLoadingDialogAudio = false;
 	// TODO 0x8002fff0
 
 	for (int i = 0; i < _dragonINIResource->totalRecords(); i++) {
@@ -288,9 +288,9 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 
 	if (flicker && flicker->sceneId != 0) {
-		flicker->field_20_actor_field_14 = _vm->_data_800633fa;
+		flicker->field_20_actor_field_14 = _vm->_flickerInitialSceneDirection;
 		if (flicker->actor) {
-			flicker->actor->_direction = _vm->_data_800633fa;
+			flicker->actor->_direction = _vm->_flickerInitialSceneDirection;
 			flicker->actor->setFlag(ACTOR_FLAG_4);
 		}
 	}
diff --git a/engines/dragons/scene.h b/engines/dragons/scene.h
index 7ee95a20ca..19e5fec4c9 100644
--- a/engines/dragons/scene.h
+++ b/engines/dragons/scene.h
@@ -42,7 +42,7 @@ struct DragonINI;
 class Scene {
 public:
 	Common::Point _camera;
-	int16 _data_80063392;
+	int16 _mapTransitionEffectSceneID;
 
 private:
 	DragonsEngine *_vm;
@@ -55,7 +55,7 @@ private:
 	ScriptOpcodes *_scriptOpcodes;
 
 	int16 _currentSceneId;
-	int16 _data_800633ee;
+	int16 _data_800633ee; //TODO this isn't referenced. Is it needed?
 
 public:
 	Scene(DragonsEngine *vm, Screen *screen, ScriptOpcodes *scriptOpcodes, ActorManager *actorManager, DragonRMS *_dragonRMS, DragonINIResource *_dragonINIResource, BackgroundResourceLoader *backgroundResourceLoader);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index fa57e09d14..3a9148ef35 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -76,7 +76,7 @@ ScriptOpCall::ScriptOpCall(byte *start, uint32 length): _op(0), _result(0), _fie
 // ScriptOpcodes
 
 ScriptOpcodes::ScriptOpcodes(DragonsEngine *vm, DragonFLG *dragonFLG)
-	: _vm(vm), _dragonFLG(dragonFLG), _data_80071f5c(0) {
+	: _vm(vm), _dragonFLG(dragonFLG), _numDialogStackFramesToPop(0) {
 	_specialOpCodes = new SpecialOpcodes(_vm);
 	initOpcodes();
 	_scriptTargetINI = 0;
@@ -107,10 +107,10 @@ void ScriptOpcodes::initOpcodes() {
 	// Register opcodes
 	OPCODE(1, opUnk1);
 	OPCODE(2, opAddDialogChoice);
-	OPCODE(3, opUnk3); //dialog related
+	OPCODE(3, opPopDialogStack);
 	OPCODE(4, opExecuteScript);
 	OPCODE(5, opSetActorDirection);
-	OPCODE(6, opUnk6);
+	OPCODE(6, opPerformActionOnObject);
 	OPCODE(7, opMoveObjectToScene);
 	OPCODE(8, opActorLoadSequence);
 
@@ -157,7 +157,7 @@ void ScriptOpcodes::updateReturn(ScriptOpCall &scriptOpCall, uint16 size) {
 void ScriptOpcodes::runScript(ScriptOpCall &scriptOpCall) {
 	scriptOpCall._field8 = 0;
 	scriptOpCall._result = 0;
-	_data_80071f5c = 0;
+	_numDialogStackFramesToPop = 0;
 	executeScriptLoop(scriptOpCall);
 }
 
@@ -165,14 +165,14 @@ void ScriptOpcodes::runScript(ScriptOpCall &scriptOpCall) {
 void ScriptOpcodes::runScript3(ScriptOpCall &scriptOpCall) {
 	scriptOpCall._field8 = 3;
 	scriptOpCall._result = 0;
-	_data_80071f5c = 0;
+	_numDialogStackFramesToPop = 0;
 	executeScriptLoop(scriptOpCall);
 }
 
 bool ScriptOpcodes::runScript4(ScriptOpCall &scriptOpCall) {
 	scriptOpCall._field8 = 4;
 	scriptOpCall._result = 0;
-	_data_80071f5c = 0;
+	_numDialogStackFramesToPop = 0;
 	executeScriptLoop(scriptOpCall);
 	return scriptOpCall._result;
 }
@@ -222,7 +222,7 @@ void ScriptOpcodes::executeScriptLoop(ScriptOpCall &scriptOpCall) {
 		scriptOpCall._op = (byte) opcode;
 		execOpcode(scriptOpCall);
 
-		if (_data_80071f5c != 0) {
+		if (_numDialogStackFramesToPop != 0) {
 			scriptOpCall._result |= 1;
 			break;
 		}
@@ -275,11 +275,12 @@ void ScriptOpcodes::opAddDialogChoice(ScriptOpCall &scriptOpCall) {
 	scriptOpCall._code += fieldA;
 }
 
-void ScriptOpcodes::opUnk3(ScriptOpCall &scriptOpCall) {
+// The number of dialog frames to pop off the stack. this returns up from nested conversation trees.
+void ScriptOpcodes::opPopDialogStack(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(field0);
 	ARG_INT16(field2);
 	if (scriptOpCall._field8 == 0) {
-		_data_80071f5c = field2;
+		_numDialogStackFramesToPop = field2;
 	}
 }
 
@@ -306,11 +307,11 @@ void ScriptOpcodes::opSetActorDirection(ScriptOpCall &scriptOpCall) {
 	}
 }
 
-void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
+void ScriptOpcodes::opPerformActionOnObject(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
-	ARG_INT16(field2);
-	ARG_INT16(field4);
-	ARG_INT16(field6);
+	ARG_INT16(verb);
+	ARG_INT16(srcINI);
+	ARG_INT16(targetINI);
 
 	if (scriptOpCall._field8 != 0) {
 		return;
@@ -324,14 +325,14 @@ void ScriptOpcodes::opUnk6(ScriptOpCall &scriptOpCall) {
 	bool isEngineFlag8Set = _vm->isFlagSet(ENGINE_FLAG_8);
 	_vm->clearFlags(ENGINE_FLAG_8);
 //	DisableVSyncEvent();
-	_vm->_cursor->_iniUnderCursor = field4;
+	_vm->_cursor->_iniUnderCursor = srcINI;
 	_vm->_cursor->_sequenceID = 0;
 
-	for (int16 i = field2 >> 1; i != 0; i = i >> 1) {
+	for (int16 i = verb >> 1; i != 0; i = i >> 1) {
 		_vm->_cursor->_sequenceID++;
 	}
 
-	_scriptTargetINI = field6;
+	_scriptTargetINI = targetINI;
 	_vm->_cursor->_data_800728b0_cursor_seqID = _vm->_cursor->_sequenceID;
 	_vm->_cursor->_performActionTargetINI = _vm->_cursor->_iniUnderCursor;
 //	EnableVSyncEvent();
@@ -435,7 +436,7 @@ void ScriptOpcodes::opMoveObjectToScene(ScriptOpCall &scriptOpCall) {
 										 flicker->actor->_y_pos - (_vm->_scene->_camera.y + 0x1e));
 			_vm->_cursor->_data_800728b0_cursor_seqID = 5;
 			_vm->_cursor->_sequenceID = 5;
-			_vm->_cursor->_data_8007283c_objectInHandSequenceID = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
+			_vm->_cursor->_objectInHandSequenceID = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
 			_vm->_cursor->_iniItemInHand = field2;
 		}
 	}
@@ -532,7 +533,7 @@ void ScriptOpcodes::opPreLoadSceneData(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(sceneId);
 
 	_vm->_sound->PauseCDMusic();
-	_vm->_data_800633fc = 1;
+	_vm->_isLoadingDialogAudio = true;
 
 	if (sceneId >= 2) {
 		//TODO do we need this? It looks like it is pre-loading the next scene's data.
@@ -902,7 +903,7 @@ void ScriptOpcodes::opLoadScene(ScriptOpCall &scriptOpCall) {
 	ARG_SKIP(2);
 	ARG_INT16(newSceneID);
 	ARG_INT16(cameraPointID);
-	ARG_INT16(field6);
+	ARG_INT16(flickerDirection);
 
 	if (scriptOpCall._field8 != 0) {
 		return;
@@ -914,9 +915,9 @@ void ScriptOpcodes::opLoadScene(ScriptOpCall &scriptOpCall) {
 
 	if (newSceneID != 0) {
 		// load scene here.
-		_vm->_scene->_data_80063392 = _vm->_scene->getSceneId();
+		_vm->_scene->_mapTransitionEffectSceneID = _vm->_scene->getSceneId();
 		_vm->_scene->setSceneId(newSceneID);
-		_vm->_data_800633fa = field6;
+		_vm->_flickerInitialSceneDirection = flickerDirection;
 
 		_vm->_scene->loadScene(newSceneID, cameraPointID);
 	} else {
@@ -1256,7 +1257,7 @@ void ScriptOpcodes::loadTalkDialogEntries(ScriptOpCall &scriptOpCall) {
 	scriptOpCall._field8 = 2;
 	scriptOpCall._result = 0;
 	_vm->_talk->clearDialogEntries();
-	_data_80071f5c = 0;
+	_numDialogStackFramesToPop = 0;
 	executeScriptLoop(scriptOpCall);
 
 }
diff --git a/engines/dragons/scriptopcodes.h b/engines/dragons/scriptopcodes.h
index a225d75987..32f5f09ef1 100644
--- a/engines/dragons/scriptopcodes.h
+++ b/engines/dragons/scriptopcodes.h
@@ -63,7 +63,7 @@ public:
 	void executeScriptLoop(ScriptOpCall &scriptOpCall);
 	void loadTalkDialogEntries(ScriptOpCall &scriptOpCall);
 
-	int16 _data_80071f5c;
+	int16 _numDialogStackFramesToPop;
 	int16 _scriptTargetINI;
 	SpecialOpcodes *_specialOpCodes;
 
@@ -81,10 +81,10 @@ protected:
 	// Opcodes
 	void opUnk1(ScriptOpCall &scriptOpCall);
 	void opAddDialogChoice(ScriptOpCall &scriptOpCall);
-	void opUnk3(ScriptOpCall &scriptOpCall);
+	void opPopDialogStack(ScriptOpCall &scriptOpCall);
 	void opExecuteScript(ScriptOpCall &scriptOpCall); //op 4
 	void opSetActorDirection(ScriptOpCall &scriptOpCall); //op 5
-	void opUnk6(ScriptOpCall &scriptOpCall);
+	void opPerformActionOnObject(ScriptOpCall &scriptOpCall);
 	void opMoveObjectToScene(ScriptOpCall &scriptOpCall);
 	void opActorLoadSequence(ScriptOpCall &scriptOpCall);
 
diff --git a/engines/dragons/sequenceopcodes.cpp b/engines/dragons/sequenceopcodes.cpp
index 18fb7a26bb..0fb710aa0b 100644
--- a/engines/dragons/sequenceopcodes.cpp
+++ b/engines/dragons/sequenceopcodes.cpp
@@ -80,7 +80,7 @@ void SequenceOpcodes::initOpcodes() {
 	OPCODE(1, opSetFramePointer);
 	OPCODE(2, opSetFramePointerAndStop);
 	OPCODE(3, opJmp);
-	OPCODE(4, opSetFieldC);
+	OPCODE(4, opSetSequenceTimerStartValue);
 	OPCODE(5, opSetSequenceTimer);
 	OPCODE(6, opUpdateXYResetSeqTimer);
 	OPCODE(7, opUpdateXYResetSeqTimerAndStop);
@@ -118,7 +118,7 @@ void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
 	debug(4, "set frame pointer %X", framePointer);
 	actor->loadFrame((uint16)framePointer);
 	actor->_flags |= ACTOR_FLAG_2;
-	actor->_sequenceTimer = actor->_field_c;
+	actor->_sequenceTimer = actor->_sequenceTimerMaxValue;
 	updateReturn(opCall, 1);
 }
 
@@ -139,10 +139,10 @@ void SequenceOpcodes::opJmp(Actor *actor, OpCall &opCall) {
 	}
 }
 
-void SequenceOpcodes::opSetFieldC(Actor *actor, OpCall &opCall) {
-	ARG_INT16(newFieldC);
-	actor->_field_c = (uint16)newFieldC;
-	debug(5, "set fieldC: %d", newFieldC);
+void SequenceOpcodes::opSetSequenceTimerStartValue(Actor *actor, OpCall &opCall) {
+	ARG_INT16(startValue);
+	actor->_sequenceTimerMaxValue = (uint16)startValue;
+	debug(5, "set sequenceTimerStartValue: %d", startValue);
 	updateReturn(opCall, 1);
 }
 
@@ -159,7 +159,7 @@ void SequenceOpcodes::opUpdateXYResetSeqTimer(Actor *actor, OpCall &opCall) {
 	ARG_INT8(yOffset);
 	actor->_x_pos += xOffset;
 	actor->_y_pos += yOffset;
-	actor->_sequenceTimer = actor->_field_c;
+	actor->_sequenceTimer = actor->_sequenceTimerMaxValue;
 
 	debug(5, "update actor %d XY offset (%d, %d) new values (%d, %d) %d", actor->_actorID, xOffset, yOffset, actor->_x_pos, actor->_y_pos, actor->_sequenceTimer);
 	updateReturn(opCall, 1);
diff --git a/engines/dragons/sequenceopcodes.h b/engines/dragons/sequenceopcodes.h
index 1177b42f94..34ce3710b5 100644
--- a/engines/dragons/sequenceopcodes.h
+++ b/engines/dragons/sequenceopcodes.h
@@ -73,7 +73,7 @@ protected:
 	void opSetFramePointer(Actor *actor, OpCall &opCall);
 	void opSetFramePointerAndStop(Actor *actor, OpCall &opCall);
 	void opJmp(Actor *actor, OpCall &opCall);
-	void opSetFieldC(Actor *actor, OpCall &opCall);
+	void opSetSequenceTimerStartValue(Actor *actor, OpCall &opCall);
 	void opSetSequenceTimer(Actor *actor, OpCall &opCall);
 	void opUpdateXYResetSeqTimer(Actor *actor, OpCall &opCall);
 	void opUpdateXYResetSeqTimerAndStop(Actor *actor, OpCall &opCall);
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index f12825fca4..f7cc62ac44 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -1358,12 +1358,12 @@ void tableBasedSceneUpdateFunction() {
 	SpecialOpcodes *spc = vm->_scriptOpcodes->_specialOpCodes;
 
 	uVar3 = (uint)spc->sceneUpdater.curSequence;
-	if (!vm->isFlagSet(ENGINE_FLAG_8000) || vm->_data_800633fc == 1) {
+	if (!vm->isFlagSet(ENGINE_FLAG_8000) || vm->_isLoadingDialogAudio) {
 		if (spc->sceneUpdater.sequenceID != -1) {
 			vm->getINI(spc->sceneUpdater.iniID)->actor->updateSequence(spc->sceneUpdater.sequenceID);
 			spc->sceneUpdater.sequenceID = -1;
 		}
-		if (vm->_data_800633fc == 0) {
+		if (!vm->_isLoadingDialogAudio) {
 			spc->sceneUpdater.counter--;
 			if (spc->sceneUpdater.counter == 0) {
 				spc->sceneUpdater.sequenceID = spc->sceneUpdater.sequenceIDTbl[uVar3][spc->sceneUpdater.curSequenceIndex]; //*(int16_t *) (sceneUpdateSequenceTbl[uVar3].sequenceIdPtr + (uint) spc->sceneUpdater.curSequenceIndex);
@@ -1486,7 +1486,7 @@ void menInMinesSceneUpdateFunction() {
 		vm->_talk->playDialogAudioDontWait(sceneUpdateFuncDialogTbl[vm->getRand(4)]);
 		sequenceId = 2;
 	} else {
-		if (vm->_data_800633fc == 0) {
+		if (!vm->_isLoadingDialogAudio) {
 			return;
 		}
 		sequenceId = 0;
@@ -1522,7 +1522,7 @@ void monksAtBarSceneUpdateFunction() {
 		specialOpCounter = 600;
 	}
 	if (vm->isFlagSet(ENGINE_FLAG_8000)) {
-		if (vm->_data_800633fc == 0) {
+		if (!vm->_isLoadingDialogAudio) {
 			return;
 		}
 		monk1->updateSequence(0);
@@ -1716,7 +1716,7 @@ void flameEscapeSceneUpdateFunction() {
 		}
 		vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
 	} else {
-		if ((vm->_data_800633fc != 0) && flame->_sequenceID != 0x10) {
+		if (vm->_isLoadingDialogAudio && flame->_sequenceID != 0x10) {
 			flame->updateSequence(0x10);
 		}
 	}
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index ad9e210c74..f89b92ae64 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -90,7 +90,7 @@ Talk::FUN_8003239c(uint16 *dialog, int16 x, int16 y, int32 param_4, uint16 param
 	//TODO 0x800323a4
 
 	//TODO dragon_text_related(textId);
-	_vm->_data_800633fc = 1;
+	_vm->_isLoadingDialogAudio = true;
 	uint32 uVar4 = 0; //TODO FUN_8001d1ac(0, textId, 0);
 
 	actor->updateSequence(startSequenceId);
@@ -378,7 +378,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 				}
 			}
 			if (param_5 == 0) {
-				_vm->_data_800633fc = 0;
+				_vm->_isLoadingDialogAudio = false;
 				return (uint)returnStatus;
 			}
 			uVar9 = ((int)((int)(short)unaff_s4 * (uint)1 * (int)sVar3) >> 3) * 0x3c;
@@ -427,7 +427,7 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 			_vm->setFlags(ENGINE_FLAG_8);
 		}
 	}
-	_vm->_data_800633fc = 0;
+	_vm->_isLoadingDialogAudio = false;
 	return (uint)returnStatus;
 }
 
@@ -486,7 +486,7 @@ void Talk::displayDialogAroundPoint(uint16 *dialogText, uint16 x, uint16 y, uint
 //		uVar4 = puVar7[5];
 //		puVar8[4] = __dat_80011a80;
 //		puVar8[5] = uVar4;
-		_vm->_data_800633fc = 1;
+		_vm->_isLoadingDialogAudio = true;
 
 		// sVar3 = FUN_8001d1ac(0, textId, 0);
 		_vm->_sound->playSpeech(textId);
@@ -621,13 +621,13 @@ bool Talk::talkToActor(ScriptOpCall &scriptOpCall) {
 		}
 		ScriptOpCall local_1d20(selectedDialogText->scriptCodeStartPtr, selectedDialogText->scriptCodeEndPtr - selectedDialogText->scriptCodeStartPtr);
 		_vm->_scriptOpcodes->runScript(local_1d20);
-		if (_vm->_scriptOpcodes->_data_80071f5c != 0) break;
+		if (_vm->_scriptOpcodes->_numDialogStackFramesToPop != 0) break;
 		local_1d20._code = selectedDialogText->scriptCodeStartPtr;
 		local_1d20._codeEnd = selectedDialogText->scriptCodeEndPtr;
 		talkToActor(local_1d20);
 
-	} while (_vm->_scriptOpcodes->_data_80071f5c == 0);
-	_vm->_scriptOpcodes->_data_80071f5c--;
+	} while (_vm->_scriptOpcodes->_numDialogStackFramesToPop == 0);
+	_vm->_scriptOpcodes->_numDialogStackFramesToPop--;
 //	LAB_80029bc0:
 //	actors[0]._x_pos = cursor_x_var;
 //	actors[0]._y_pos = cursor_y_var;


Commit: ed2bf372d9f3edfc1490e78ff0940106591553a6
    https://github.com/scummvm/scummvm/commit/ed2bf372d9f3edfc1490e78ff0940106591553a6
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Renaming variables

Changed paths:
    engines/dragons/actor.cpp
    engines/dragons/actor.h
    engines/dragons/cursor.cpp
    engines/dragons/dragonini.cpp
    engines/dragons/dragonini.h
    engines/dragons/dragons.cpp
    engines/dragons/inventory.cpp
    engines/dragons/minigame1.cpp
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/minigame5.cpp
    engines/dragons/scene.cpp
    engines/dragons/scriptopcodes.cpp
    engines/dragons/specialopcodes.cpp
    engines/dragons/talk.cpp


diff --git a/engines/dragons/actor.cpp b/engines/dragons/actor.cpp
index efe7ec872f..c1ad563616 100644
--- a/engines/dragons/actor.cpp
+++ b/engines/dragons/actor.cpp
@@ -135,7 +135,6 @@ Actor::Actor(uint16 id) : _actorID(id) {
 	_actorResource = NULL;
 	_resourceID = -1;
 	_seqCodeIp = 0;
-	_frame_pointer_maybe = NULL;
 	_priorityLayer = 3;
 	_x_pos = 160;
 	_y_pos = 110;
@@ -143,10 +142,7 @@ Actor::Actor(uint16 id) : _actorID(id) {
 	_walkDestY = 0;
 	_walkSpeed = 0;
 	_flags = 0;
-	_frame_width = 0;
-	_frame_height = 0;
 	_frame_flags = 0;
-	_clut = 0;
 	_frame = NULL;
 	_surface = NULL;
 }
@@ -162,8 +158,6 @@ void Actor::init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID) {
 	_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 	_direction = 0;
 	_flags = (ACTOR_FLAG_40 | Dragons::ACTOR_FLAG_4);
-	_frame_width = 0;
-	_frame_height = 0;
 	_frame_flags = 4;
 	//TODO sub_80017010();
 	freeFrame();
diff --git a/engines/dragons/actor.h b/engines/dragons/actor.h
index 3cc7c3d6bf..74f7451950 100644
--- a/engines/dragons/actor.h
+++ b/engines/dragons/actor.h
@@ -90,7 +90,6 @@ public:
 	uint16 _actorFileDictionaryIndex;
 	int16 _resourceID;
 	byte *_seqCodeIp;
-	void* _frame_pointer_maybe;
 	ActorFrame *_frame;
 	Graphics::Surface *_surface;
 	uint16 _sequenceTimerMaxValue;
@@ -114,13 +113,7 @@ public:
 	int16 _finalWalkDestY;
 	uint16 _field_7a;
 	int32 _walkSpeed;
-	uint16 _field_80;
-	uint16 _frame_vram_x;
-	uint16 _frame_vram_y;
-	uint16 _frame_width;
-	uint16 _frame_height;
 	uint16 _frame_flags;
-	uint16 _clut;
 public:
 
 	Actor(uint16 id);
diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index f679ffa52e..e837b191dc 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -50,7 +50,7 @@ void Cursor::init(ActorManager *actorManager, DragonINIResource *dragonINIResour
 					   ACTOR_FLAG_200);
 
 	dragonINIResource->getFlickerRecord()->actor = _actor; //TODO is this correct?
-	dragonINIResource->getFlickerRecord()->field_1a_flags_maybe |= INI_FLAG_1;
+	dragonINIResource->getFlickerRecord()->flags |= INI_FLAG_1;
 	_iniUnderCursor = 0;
 	_iniItemInHand = 0;
 	_objectInHandSequenceID = 0;
@@ -77,7 +77,7 @@ void Cursor::update() {
 	// 0x80028104
 	if (_iniUnderCursor != 0
 			&& ((_iniUnderCursor & 0x8000 && _vm->_inventory->isOpen())
-			||(!(_iniUnderCursor & 0x8000) && _vm->getINI(_iniUnderCursor - 1)->field_1a_flags_maybe & 0x80))) {
+			||(!(_iniUnderCursor & 0x8000) && _vm->getINI(_iniUnderCursor - 1)->flags & 0x80))) {
 		if (_actor->_sequenceID != 0x84) {
 			_actor->updateSequence(0x84);
 		}
@@ -194,10 +194,10 @@ int16 Cursor::updateIniFromScene() {
 		DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
 		if (ini->sceneId != _vm->_scene->getSceneId()) {
 			// 0x80028be4
-		} else if (!_vm->_dragonINIResource->isFlicker(ini) && !(ini->field_1a_flags_maybe & 0x40)) {
+		} else if (!_vm->_dragonINIResource->isFlicker(ini) && !(ini->flags & 0x40)) {
 			int16 cursorOverIni = 0;
 			// 0x80028a10
-			if (ini->field_1a_flags_maybe & 1) {
+			if (ini->flags & 1) {
 				// 0x80028b18
 				if (ini->actor->isFlagSet(ACTOR_FLAG_40) && ini->actor->isFlagSet(ACTOR_FLAG_8)) {
 					int16 iniActorXPosition = ini->actor->_x_pos - ini->actor->_frame->xOffset;
@@ -209,8 +209,8 @@ int16 Cursor::updateIniFromScene() {
 				}
 			} else {
 				// 0x80028a24
-				if (ini->field_2 != -1) {
-					Img *img = _vm->_dragonImg->getImg((uint32)ini->field_2);
+				if (ini->imgId != -1) {
+					Img *img = _vm->_dragonImg->getImg((uint32)ini->imgId);
 					if (img->field_e - 1 >= 1) { // TODO this is >= 2 in the original.
 						if (cursorTileX >= img->x && cursorTileX < img->x + img->w && cursorTileY >= img->y && cursorTileY < img->y + img->h) {
 							cursorOverIni = i + 1;
@@ -229,7 +229,7 @@ int16 Cursor::updateIniFromScene() {
 				_performActionTargetINI = _iniUnderCursor;
 				_data_800728b0_cursor_seqID = _sequenceID;
 
-				if (ini->field_1a_flags_maybe & 0x800) {
+				if (ini->flags & 0x800) {
 					_performActionTargetINI = cursorOverIni;
 					uint32 newSeqId = 1;
 					for (int idx = 0; idx < 5; idx++) {
diff --git a/engines/dragons/dragonini.cpp b/engines/dragons/dragonini.cpp
index 9bddc39043..afa10fa399 100644
--- a/engines/dragons/dragonini.cpp
+++ b/engines/dragons/dragonini.cpp
@@ -43,24 +43,24 @@ void DragonINIResource::reset() {
 	for (int i = 0; i < _count; i++) {
 		_dragonINI[i].id = (uint16)i;
 		_dragonINI[i].iptIndex_maybe = readStream->readSint16LE();
-		_dragonINI[i].field_2 = readStream->readSint16LE();
+		_dragonINI[i].imgId = readStream->readSint16LE();
 		_dragonINI[i].actorResourceId = readStream->readSint16LE();
 		_dragonINI[i].sequenceId = readStream->readSint16LE();
-		_dragonINI[i].field_8 = readStream->readSint16LE();
+		_dragonINI[i].inventorySequenceId = readStream->readSint16LE();
 		uint16 v = readStream->readUint16LE();
 		assert(v == 0); // actorId
 		_dragonINI[i].actor = NULL;
 		_dragonINI[i].sceneId = readStream->readUint16LE();
-		_dragonINI[i].field_e = readStream->readSint16LE();
-		_dragonINI[i].field_10 = readStream->readSint16LE();
-		_dragonINI[i].field_12 = readStream->readSint16LE();
-		_dragonINI[i].field_14 = readStream->readSint16LE();
+		_dragonINI[i].direction = readStream->readSint16LE();
+		_dragonINI[i].counter = readStream->readSint16LE();
+		_dragonINI[i].objectState = readStream->readSint16LE();
+		_dragonINI[i].objectState2 = readStream->readSint16LE();
 		_dragonINI[i].x = readStream->readSint16LE();
 		_dragonINI[i].y = readStream->readSint16LE();
-		_dragonINI[i].field_1a_flags_maybe = readStream->readUint16LE();
-		_dragonINI[i].field_1c = readStream->readSint16LE();
-		_dragonINI[i].field_1e = readStream->readSint16LE();
-		_dragonINI[i].field_20_actor_field_14 = readStream->readUint16LE();
+		_dragonINI[i].flags = readStream->readUint16LE();
+		_dragonINI[i].baseXOffset = readStream->readSint16LE();
+		_dragonINI[i].baseYOffset = readStream->readSint16LE();
+		_dragonINI[i].direction2 = readStream->readUint16LE();
 	}
 
 	_flickerINI = &_dragonINI[0];
diff --git a/engines/dragons/dragonini.h b/engines/dragons/dragonini.h
index 5beb8986c6..6074ec4765 100644
--- a/engines/dragons/dragonini.h
+++ b/engines/dragons/dragonini.h
@@ -44,22 +44,22 @@ enum IniFlags {
 struct DragonINI {
 	uint16 id;
 	int16 iptIndex_maybe;
-	int16 field_2;
+	int16 imgId;
 	int16 actorResourceId;
 	uint16 sequenceId;
-	int16 field_8;
+	int16 inventorySequenceId;
 	Actor *actor;
 	uint16 sceneId;
-	int16 field_e;
-	int16 field_10;
-	int16 field_12;
-	uint16 field_14;
+	int16 direction;
+	int16 counter;
+	int16 objectState;
+	uint16 objectState2;
 	int16 x;
 	int16 y;
-	uint16 field_1a_flags_maybe;
-	int16 field_1c;
-	int16 field_1e;
-	int16 field_20_actor_field_14;
+	uint16 flags;
+	int16 baseXOffset;
+	int16 baseYOffset;
+	int16 direction2;
 };
 
 class DragonINIResource {
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 4c23f90bb6..522b516025 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -246,8 +246,8 @@ uint16 DragonsEngine::ipt_img_file_related() {
 
 	for (int i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
-		if ((ini->sceneId == getCurrentSceneId()) && (ini->field_1a_flags_maybe == 0)) {
-			Img *img = _dragonImg->getImg(ini->field_2);
+		if ((ini->sceneId == getCurrentSceneId()) && (ini->flags == 0)) {
+			Img *img = _dragonImg->getImg(ini->imgId);
 			if ((img->x <= tileX) && (((tileX <= img->x + img->w && (img->y <= tileY)) && (tileY <= img->y + img->h)))) {
 				return i + 1;
 			}
@@ -303,7 +303,7 @@ void DragonsEngine::gameLoop() {
 		}
 
 		if (_cursor->updateINIUnderCursor() == 0 ||
-			(!(_cursor->_iniUnderCursor & 0x8000) && (getINI(_cursor->_iniUnderCursor - 1)->field_1a_flags_maybe & 0x4000) != 0)) { //TODO check this. This logic looks a bit strange.
+			(!(_cursor->_iniUnderCursor & 0x8000) && (getINI(_cursor->_iniUnderCursor - 1)->flags & 0x4000) != 0)) { //TODO check this. This logic looks a bit strange.
 			_cursor->_cursorActivationSeqOffset = 0;
 		} else {
 			_cursor->_cursorActivationSeqOffset = 5;
@@ -351,12 +351,12 @@ void DragonsEngine::gameLoop() {
 					iniId = _cursor->_performActionTargetINI;
 				}
 				if (iniId > 0) {
-					flicker->actor->_direction = getINI(iniId - 1)->field_e;
+					flicker->actor->_direction = getINI(iniId - 1)->direction;
 				}
 			}
 
 			performAction();
-			if ((getCurrentSceneId() == 0x1d) && (getINI(0x178)->field_12 != 0)) { //cave of dilemma
+			if ((getCurrentSceneId() == 0x1d) && (getINI(0x178)->objectState != 0)) { //cave of dilemma
 				clearFlags(ENGINE_FLAG_8);
 			} else {
 				setFlags(ENGINE_FLAG_8);
@@ -570,7 +570,7 @@ void DragonsEngine::gameLoop() {
 					actor->_flags = 0;
 					actor->_priorityLayer = 0;
 					actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-					actor->updateSequence(getINI(tmpId - 1)->field_8 * 2 + 10);
+					actor->updateSequence(getINI(tmpId - 1)->inventorySequenceId * 2 + 10);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);
@@ -589,7 +589,7 @@ void DragonsEngine::gameLoop() {
 				invActor->_flags = 0;
 				invActor->_priorityLayer = 0;
 				invActor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-				invActor->updateSequence(getINI(_cursor->_iniItemInHand - 1)->field_8 * 2 + 10);
+				invActor->updateSequence(getINI(_cursor->_iniItemInHand - 1)->inventorySequenceId * 2 + 10);
 				_cursor->_iniItemInHand = 0;
 				invActor->setFlag(ACTOR_FLAG_40);
 				invActor->setFlag(ACTOR_FLAG_80);
@@ -823,8 +823,8 @@ uint16 DragonsEngine::getIniFromImg() {
 
 	for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
-		if (ini->sceneId == currentSceneId && ini->field_1a_flags_maybe == 0) {
-			Img *img = _dragonImg->getImg(ini->field_2);
+		if (ini->sceneId == currentSceneId && ini->flags == 0) {
+			Img *img = _dragonImg->getImg(ini->imgId);
 			if (x >= img->x &&
 				img->x + img->w >= x &&
 				y >= img->y &&
@@ -841,8 +841,8 @@ void DragonsEngine::runINIScripts() {
 	bool isFlag8Set = isFlagSet(ENGINE_FLAG_8);
 	for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = getINI(i);
-		if (ini->field_1a_flags_maybe & INI_FLAG_10) {
-			ini->field_1a_flags_maybe &= ~INI_FLAG_10;
+		if (ini->flags & INI_FLAG_10) {
+			ini->flags &= ~INI_FLAG_10;
 			byte *data = _dragonOBD->getFromOpt(i);
 			ScriptOpCall scriptOpCall(data + 8, READ_LE_UINT32(data));
 			clearFlags(ENGINE_FLAG_8);
@@ -896,10 +896,10 @@ void DragonsEngine::engineFlag0x20UpdateFunction() {
 	if (!_inventory->isOpen()) {
 		for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
 			DragonINI *ini = getINI(i);
-			if (ini->field_10 >= 0 && ini->sceneId == currentSceneId) {
-				ini->field_10--;
-				if (ini->field_10 < 0) {
-					ini->field_1a_flags_maybe |= INI_FLAG_10;
+			if (ini->counter >= 0 && ini->sceneId == currentSceneId) {
+				ini->counter--;
+				if (ini->counter < 0) {
+					ini->flags |= INI_FLAG_10;
 				}
 			}
 		}
@@ -1077,11 +1077,11 @@ void DragonsEngine::walkFlickerToObject() {
 			if (!(READ_LE_UINT16(_dragonOBD->getFromOpt(_cursor->_performActionTargetINI - 1) + 4) & 8)
 				&& (_inventory->getState() == Closed) && !isFlagSet(ENGINE_FLAG_200000)) {
 				targetINI = getINI(_cursor->_performActionTargetINI - 1);
-				if ((targetINI->field_1a_flags_maybe & 1) == 0) {
+				if ((targetINI->flags & 1) == 0) {
 					if (targetINI->actorResourceId == -1) {
 						return;
 					}
-					Img *img = _dragonImg->getImg(targetINI->field_2);
+					Img *img = _dragonImg->getImg(targetINI->imgId);
 					targetX = img->field_a;
 					targetY = img->field_c;
 				} else {
@@ -1089,11 +1089,11 @@ void DragonsEngine::walkFlickerToObject() {
 					targetY = targetINI->actor->_y_pos;
 				}
 				flickerINI->actor->_walkSpeed = 0x10000;
-				if (flickerINI->field_20_actor_field_14 == -1) {
+				if (flickerINI->direction2 == -1) {
 					flickerINI->actor->setFlag(ACTOR_FLAG_800);
 				}
-				flickerINI->actor->startWalk((int)(((uint)targetX + (uint)targetINI->field_1c) * 0x10000) >> 0x10,
-													(int)(((uint)targetY + (uint)targetINI->field_1e) * 0x10000) >> 0x10, 0);
+				flickerINI->actor->startWalk((int)(((uint)targetX + (uint)targetINI->baseXOffset) * 0x10000) >> 0x10,
+											 (int)(((uint)targetY + (uint)targetINI->baseYOffset) * 0x10000) >> 0x10, 0);
 				_bit_flags_8006fbd8 = 1; //walk to perform an action.
 				return;
 			}
@@ -1106,8 +1106,8 @@ void DragonsEngine::walkFlickerToObject() {
 				flickerINI->actor->clearFlag(ACTOR_FLAG_10);
 				flickerINI->actor->setFlag(ACTOR_FLAG_4);
 				targetINI = getINI(_cursor->_performActionTargetINI - 1);
-				flickerINI->field_20_actor_field_14 = targetINI->field_e;
-				flickerINI->actor->_direction = targetINI->field_e;
+				flickerINI->direction2 = targetINI->direction;
+				flickerINI->actor->_direction = targetINI->direction;
 			}
 			_bit_flags_8006fbd8 = 3;
 			return;
@@ -1414,7 +1414,7 @@ void DragonsEngine::updateFlickerIdleAnimation() {
 		DragonINI *flicker = _dragonINIResource->getFlickerRecord();
 		if (flicker->actor->_resourceID == 0xe) {
 			flicker->actor->_direction = 2;
-			flicker->field_20_actor_field_14 = 2;
+			flicker->direction2 = 2;
 			if (getINI(0xc2)->sceneId == 1) {
 				flicker->actor->updateSequence(0x30);
 			} else {
diff --git a/engines/dragons/inventory.cpp b/engines/dragons/inventory.cpp
index abcf4056b6..3af6d3d154 100644
--- a/engines/dragons/inventory.cpp
+++ b/engines/dragons/inventory.cpp
@@ -176,7 +176,7 @@ void Inventory::openInventory() {
 			item->_flags = 0; //clear all flags
 			item->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
 			item->_priorityLayer = 0;
-			item->updateSequence(_vm->getINI(_inventoryItemTbl[i] - 1)->field_8 * 2 + 10);
+			item->updateSequence(_vm->getINI(_inventoryItemTbl[i] - 1)->inventorySequenceId * 2 + 10);
 			item->setFlag(ACTOR_FLAG_200);
 			item->setFlag(ACTOR_FLAG_100);
 			item->setFlag(ACTOR_FLAG_80);
diff --git a/engines/dragons/minigame1.cpp b/engines/dragons/minigame1.cpp
index 55585440d3..53abed9c20 100644
--- a/engines/dragons/minigame1.cpp
+++ b/engines/dragons/minigame1.cpp
@@ -828,7 +828,7 @@ void Minigame1::run() {
 		}
 
 		if ((local_252 == 2) && (gameState == 6)) {
-			_vm->getINI(DAT_80063a40 - 1)->field_14 = 2;
+			_vm->getINI(DAT_80063a40 - 1)->objectState2 = 2;
 			if (local_250 != 0) {
 				_vm->_talk->FUN_8001a7c4_clearDialogBoxMaybe();
 			}
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index d986bacf8b..f1962d0041 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -699,8 +699,8 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 	//TODO FUN_80035e74((uint)uVar16);
 	_vm->_dragonINIResource->setFlickerRecord(flicker);
 	_vm->_inventory->setState(originalInventoryType);
-	flicker->field_12 = local_258 + -1;
-	if (flicker->field_12 == 0) {
+	flicker->objectState = local_258 + -1;
+	if (flicker->objectState == 0) {
 		_vm->setVar(0xb, 1);
 		flicker->actorResourceId = 0xd2; //TODO is this correct?
 		_vm->_actorManager->loadActor(0xd2, flicker->actor->_actorID);
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index f709de6b24..fe8cb538ed 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -716,10 +716,10 @@ void Minigame3::run() {
 	}
 	handActorId->updateSequence(1);
 	handActorId->waitUntilFlag4IsSet();
-	_vm->_dragonINIResource->getRecord(0x178)->field_12 = local_224 + 1;
+	_vm->_dragonINIResource->getRecord(0x178)->objectState = local_224 + 1;
 	if (goodRabbitPositionTbl[local_224] == 1) {
 		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(2);
-		_vm->_dragonINIResource->getRecord(0x178)->field_14 = 1;
+		_vm->_dragonINIResource->getRecord(0x178)->objectState2 = 1;
 	} else {
 		bunnyActorTbl[bunnyPositionTbl[local_224]]->updateSequence(3);
 		i = 0;
@@ -728,7 +728,7 @@ void Minigame3::run() {
 		}
 		_vm->waitForFrames(0x1e);
 		bunnyActorTbl[bunnyPositionTbl[i]]->updateSequence(2);
-		_vm->_dragonINIResource->getRecord(0x178)->field_14 = 0;
+		_vm->_dragonINIResource->getRecord(0x178)->objectState2 = 0;
 	}
 	_vm->waitForFrames(0x3c * 2);
 	_vm->_sound->PauseCDMusic();
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index a1112f1986..17f007d33c 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -82,7 +82,7 @@ void Minigame4::run() {
 	//DAT_800830e0_soundRelated = 0xf;
 	//UnkSoundFunc5(0xf);
 	//call_fade_related_1f();
-	if (_vm->_dragonINIResource->getRecord(0x1f5)->field_12 == 3) {
+	if (_vm->_dragonINIResource->getRecord(0x1f5)->objectState == 3) {
 		actorTalk(_bruteActor, 0x3321, 0x4A84);
 	} else {
 		actorTalk(_bruteActor, 0x3321, 0x49A2);
@@ -90,8 +90,8 @@ void Minigame4::run() {
 	}
 	result = runDanceBattle();
 	/* field_0x12 */
-	_vm->_dragonINIResource->getRecord(0)->field_12 = result ^ 1;
-	if (_vm->_dragonINIResource->getRecord(0)->field_12 == 1) {
+	_vm->_dragonINIResource->getRecord(0)->objectState = result ^ 1;
+	if (_vm->_dragonINIResource->getRecord(0)->objectState == 1) {
 		_vm->_dragonINIResource->getRecord(0x1f5)->sceneId = 0;
 	}
 
diff --git a/engines/dragons/minigame5.cpp b/engines/dragons/minigame5.cpp
index 22a44f968b..49dfbda8bd 100644
--- a/engines/dragons/minigame5.cpp
+++ b/engines/dragons/minigame5.cpp
@@ -478,7 +478,7 @@ void Minigame5::run() {
 		}
 		if (local_10 == 1) break;
 		if (local_10 == 2) {
-			_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->field_14 = 2;
+			_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->objectState2 = 2;
 			pusherActor->updateSequence(7);
 			_vm->waitForFrames(0x3c);
 			pusherActor->updateSequence(1);
@@ -518,7 +518,7 @@ void Minigame5::run() {
 		}
 	}
 	_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->actor->clearFlag(ACTOR_FLAG_100);
-	_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->field_14 = 0;
+	_vm->_dragonINIResource->getRecord(DAT_80063a40 + -1)->objectState2 = 0;
 	goto LAB_8009157c;
 }
 
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 21a1be63b7..9085b1cc84 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -79,7 +79,7 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 		_scriptOpcodes->runScript(scriptOpCall);
 	}
 	DragonINI *ini = _dragonINIResource->getRecord(0xc4);
-	ini->field_12 = 0;
+	ini->objectState = 0;
 }
 
 void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
@@ -89,8 +89,8 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 	for (int i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
-		ini->field_10 = -1;
-		ini->field_1a_flags_maybe &= ~INI_FLAG_10;
+		ini->counter = -1;
+		ini->flags &= ~INI_FLAG_10;
 	}
 
 	uint16 sceneIdStripped = (uint16)sceneId & ~0x8000;
@@ -220,42 +220,42 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	for (int i = 0; i < _dragonINIResource->totalRecords(); i++) {
 		DragonINI *ini = _dragonINIResource->getRecord(i);
 		if (ini->sceneId == sceneIdStripped) {
-			if (ini->field_1a_flags_maybe & 1) {
+			if (ini->flags & 1) {
 				Actor *actor = _actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
 
 				if (actor) {
 					ini->actor = actor;
-					if (ini->field_1a_flags_maybe & 0x1000) {
+					if (ini->flags & 0x1000) {
 						actor->_frame_flags |= 0x10;
 					} else {
-						if (ini->field_1a_flags_maybe & 0x2000) {
+						if (ini->flags & 0x2000) {
 							actor->_frame_flags |= 0x20;
 						} else {
 							actor->_frame_flags &= ~0x10;
 						}
 					}
 
-					actor->_direction = ini->field_20_actor_field_14;
+					actor->_direction = ini->direction2;
 
-					if (ini->field_1a_flags_maybe & 2) {
+					if (ini->flags & 2) {
 						actor->_flags |= ACTOR_FLAG_80;
 					} else {
 						actor->_flags &= 0xfeff;
 					}
 
-					if (ini->field_1a_flags_maybe & 0x20) {
+					if (ini->flags & 0x20) {
 						actor->_flags |= ACTOR_FLAG_100;
 					} else {
 						actor->_flags &= 0xfeff;
 					}
 
-					if (ini->field_1a_flags_maybe & 4) {
+					if (ini->flags & 4) {
 						actor->_flags |= ACTOR_FLAG_8000;
 					} else {
 						actor->_flags &= 0x7fff;
 					}
 
-					if (ini->field_1a_flags_maybe & 0x100) {
+					if (ini->flags & 0x100) {
 						actor->_flags |= ACTOR_FLAG_4000;
 					} else {
 						actor->_flags &= 0xbfff;
@@ -265,7 +265,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 //				int x = ini->x - actor->_frame_vram_x;
 //				int y = ini->y - actor->_frame_vram_y;
 //				if (x >= 0 && y >= 0 && x + s->w < 320 && y + s->h < 200) {
-//					debug("Actor %d, %d %d (%d, %d)", actor->_actorID, ini->actorResourceId, ini->field_1a_flags_maybe, ini->x, ini->y);
+//					debug("Actor %d, %d %d (%d, %d)", actor->_actorID, ini->actorResourceId, ini->flags, ini->x, ini->y);
 //					_stage->getFgLayer()->copyRectToSurface(*s, x, y, Common::Rect(s->w, s->h));
 //				}
 				}
@@ -288,7 +288,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 
 
 	if (flicker && flicker->sceneId != 0) {
-		flicker->field_20_actor_field_14 = _vm->_flickerInitialSceneDirection;
+		flicker->direction2 = _vm->_flickerInitialSceneDirection;
 		if (flicker->actor) {
 			flicker->actor->_direction = _vm->_flickerInitialSceneDirection;
 			flicker->actor->setFlag(ACTOR_FLAG_4);
@@ -374,7 +374,7 @@ void Scene::draw() {
 					int x = actor->_x_pos - (actor->_frame->xOffset * actor->_scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.x);
 					int y = actor->_y_pos - (actor->_frame->yOffset * actor->_scale / DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE) - (actor->isFlagSet(ACTOR_FLAG_200) ? 0 : _camera.y);
 
-					debug(4, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d Scale: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
+					debug(5, "Actor %d %s (%d, %d) w:%d h:%d Priority: %d Scale: %d", actor->_actorID, actor->_actorResource->getFilename(), x,
 						  y,
 						  s->w, s->h, actor->_priorityLayer, actor->_scale);
 						_screen->copyRectToSurface8bpp(*s, actor->getPalette(), x, y, Common::Rect(s->w, s->h), (bool)(actor->_frame->flags & FRAME_FLAG_FLIP_X), actor->isFlagSet(ACTOR_FLAG_8000) ? NONE : NORMAL, actor->_scale);
diff --git a/engines/dragons/scriptopcodes.cpp b/engines/dragons/scriptopcodes.cpp
index 3a9148ef35..666f14e806 100644
--- a/engines/dragons/scriptopcodes.cpp
+++ b/engines/dragons/scriptopcodes.cpp
@@ -360,33 +360,33 @@ void ScriptOpcodes::opMoveObjectToScene(ScriptOpCall &scriptOpCall) {
 	DragonINI *ini = _vm->getINI(field2 - 1);
 	if (!(field0 & 0x8000)) {
 
-		if (ini->field_1a_flags_maybe & 1) {
+		if (ini->flags & 1) {
 			if (ini->sceneId == currentScene) {
 				assert(ini->actor);
 				ini->actor->reset_maybe();
 			}
 			if (sceneId == currentScene) {
 				ini->actor = _vm->_actorManager->loadActor(ini->actorResourceId, ini->sequenceId, ini->x, ini->y, 0);
-				ini->actor->_direction = ini->field_20_actor_field_14;
-				if (ini->field_1a_flags_maybe & 2) {
+				ini->actor->_direction = ini->direction2;
+				if (ini->flags & 2) {
 					ini->actor->_flags |= ACTOR_FLAG_80;
 				} else {
 					ini->actor->_flags &= ~ACTOR_FLAG_80;
 				}
 
-				if (ini->field_1a_flags_maybe & 0x20) {
+				if (ini->flags & 0x20) {
 					ini->actor->_flags |= ACTOR_FLAG_100;
 				} else {
 					ini->actor->_flags &= ~ACTOR_FLAG_100;
 				}
 
-				if (ini->field_1a_flags_maybe & 4) {
+				if (ini->flags & 4) {
 					ini->actor->_flags |= ACTOR_FLAG_8000;
 				} else {
 					ini->actor->_flags &= ~ACTOR_FLAG_8000;
 				}
 
-				if (ini->field_1a_flags_maybe & 0x100) {
+				if (ini->flags & 0x100) {
 					ini->actor->_flags |= ACTOR_FLAG_4000;
 				} else {
 					ini->actor->_flags &= ~ACTOR_FLAG_4000;
@@ -423,7 +423,7 @@ void ScriptOpcodes::opMoveObjectToScene(ScriptOpCall &scriptOpCall) {
 					actor->_flags = 0;
 					actor->_priorityLayer = 0;
 					actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
-					actor->updateSequence((_vm->getINI(_vm->_cursor->_iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
+					actor->updateSequence((_vm->getINI(_vm->_cursor->_iniItemInHand - 1)->inventorySequenceId * 2 + 10) & 0xfffe);
 					actor->setFlag(ACTOR_FLAG_40);
 					actor->setFlag(ACTOR_FLAG_80);
 					actor->setFlag(ACTOR_FLAG_100);
@@ -436,7 +436,7 @@ void ScriptOpcodes::opMoveObjectToScene(ScriptOpCall &scriptOpCall) {
 										 flicker->actor->_y_pos - (_vm->_scene->_camera.y + 0x1e));
 			_vm->_cursor->_data_800728b0_cursor_seqID = 5;
 			_vm->_cursor->_sequenceID = 5;
-			_vm->_cursor->_objectInHandSequenceID = _vm->getINI(field2 - 1)->field_8 * 2 + 10;
+			_vm->_cursor->_objectInHandSequenceID = _vm->getINI(field2 - 1)->inventorySequenceId * 2 + 10;
 			_vm->_cursor->_iniItemInHand = field2;
 		}
 	}
@@ -813,21 +813,21 @@ void ScriptOpcodes::opMoveActorToObject(ScriptOpCall &scriptOpCall) {
 		bVar1 = (field6 != -1);
 	}
 	if (field8 == -1) {
-		if ((firstIni->field_1a_flags_maybe & 1) == 0) {
-			if ((int)firstIni->field_2 != -1) {
-				Img *firstDragonImg1 = _vm->_dragonImg->getImg(firstIni->field_2);
-				int16 newXPos1 = firstDragonImg1->field_a + firstIni->field_1c;
+		if ((firstIni->flags & 1) == 0) {
+			if ((int)firstIni->imgId != -1) {
+				Img *firstDragonImg1 = _vm->_dragonImg->getImg(firstIni->imgId);
+				int16 newXPos1 = firstDragonImg1->field_a + firstIni->baseXOffset;
 				secondIni->x = newXPos1;
 				secondIni->actor->_x_pos = newXPos1;
-				int16 newYPos1 = firstDragonImg1->field_c + firstIni->field_1e;
+				int16 newYPos1 = firstDragonImg1->field_c + firstIni->baseYOffset;
 				secondIni->y = newYPos1;
 				secondIni->actor->_y_pos = newYPos1;
 			}
 		} else {
-			int16 newYPos2 = firstIni->actor->_y_pos + firstIni->field_1e;
+			int16 newYPos2 = firstIni->actor->_y_pos + firstIni->baseYOffset;
 			firstIni->y = newYPos2;
 			secondIni->actor->_y_pos = newYPos2;
-			someXParam = firstIni->actor->_x_pos + firstIni->field_1c;
+			someXParam = firstIni->actor->_x_pos + firstIni->baseXOffset;
 			secondIni->x = someXParam;
 			secondIni->actor->_x_pos = someXParam;
 		}
@@ -855,20 +855,20 @@ void ScriptOpcodes::opMoveActorToObject(ScriptOpCall &scriptOpCall) {
 	int16 newXPosAgain = 0;
 	int16 newYPosAgain = 0;
 	someBooleanFlag = 1;
-	if ((firstIni->field_1a_flags_maybe & 1) == 0) {
-		if ((int)firstIni->field_2 == -1) {
+	if ((firstIni->flags & 1) == 0) {
+		if ((int)firstIni->imgId == -1) {
 			return;
 		}
-		Img *firstDragonImg2 = _vm->_dragonImg->getImg(firstIni->field_2);
+		Img *firstDragonImg2 = _vm->_dragonImg->getImg(firstIni->imgId);
 
-		newXPosAgain = firstDragonImg2->field_a + firstIni->field_1c;
-		newYPosAgain = firstDragonImg2->field_c + firstIni->field_1e;
+		newXPosAgain = firstDragonImg2->field_a + firstIni->baseXOffset;
+		newYPosAgain = firstDragonImg2->field_c + firstIni->baseYOffset;
 		if (_vm->_dragonINIResource->isFlicker(secondIni)) {
 			someBooleanFlag = 0;
 		}
 	} else {
-		newXPosAgain = firstIni->actor->_x_pos + firstIni->field_1c;
-		newYPosAgain = firstIni->actor->_y_pos + firstIni->field_1e;
+		newXPosAgain = firstIni->actor->_x_pos + firstIni->baseXOffset;
+		newYPosAgain = firstIni->actor->_y_pos + firstIni->baseYOffset;
 		if (_vm->_dragonINIResource->isFlicker(secondIni)) {
 			someBooleanFlag = 0;
 		}
@@ -880,7 +880,7 @@ void ScriptOpcodes::opMoveActorToObject(ScriptOpCall &scriptOpCall) {
 		}
 	}
 
-	secondIni->actor->_direction = firstIni->field_e;
+	secondIni->actor->_direction = firstIni->direction;
 
 	secondIni->x = newXPosAgain;
 	secondIni->y = newYPosAgain;
@@ -950,8 +950,8 @@ void ScriptOpcodes::opCodeActorTalk(ScriptOpCall &scriptOpCall) {
 
 	DragonINI *ini = iniId == 0 ? _vm->_dragonINIResource->getFlickerRecord() : _vm->getINI(iniId - 1);
 
-	if ((ini->field_1a_flags_maybe & 1) == 0) {
-		Img *img = _vm->_dragonImg->getImg(ini->field_2);
+	if ((ini->flags & 1) == 0) {
+		Img *img = _vm->_dragonImg->getImg(ini->imgId);
 
 		int y = img->field_e == 0 ? img->y : img->y << 3;
 
@@ -1019,7 +1019,7 @@ void ScriptOpcodes::setVariable(ScriptOpCall &scriptOpCall) {
 		s2 = getINIField(field4 - 1, field2);
 		DragonINI *ini = _vm->getINI(field4 - 1);
 
-		if (field2 == 0x1a && ini->field_1a_flags_maybe & 1 && ini->sceneId == _vm->getCurrentSceneId()) {
+		if (field2 == 0x1a && ini->flags & 1 && ini->sceneId == _vm->getCurrentSceneId()) {
 			if (s1 & 2) {
 				ini->actor->_flags |= ACTOR_FLAG_80;
 				ini->actor->_scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE;
@@ -1034,7 +1034,7 @@ void ScriptOpcodes::setVariable(ScriptOpCall &scriptOpCall) {
 			}
 		}
 
-		if (fieldA & 4 && field2 == 0 && !(ini->field_1a_flags_maybe & 1) && ini->sceneId == _vm->getCurrentSceneId()) {
+		if (fieldA & 4 && field2 == 0 && !(ini->flags & 1) && ini->sceneId == _vm->getCurrentSceneId()) {
 			if (s1 == -1) {
 				if (ini->iptIndex_maybe != -1) {
 					_vm->_scene->removeImageOverlay(ini->iptIndex_maybe);
@@ -1080,16 +1080,16 @@ uint16 ScriptOpcodes::getINIField(uint32 iniIndex, uint16 fieldOffset) {
 	case 4 : return ini->actorResourceId;
 	case 6 : return ini->sequenceId;
 	case 0xC  : return ini->sceneId;
-	case 0xE  : return ini->field_e;
-	case 0x10 : return ini->field_10;
-	case 0x12  : return ini->field_12;
-	case 0x14 : return ini->field_14;
+	case 0xE  : return ini->direction;
+	case 0x10 : return ini->counter;
+	case 0x12  : return ini->objectState;
+	case 0x14 : return ini->objectState2;
 	case 0x16 : return ini->x;
 	case 0x18 : return ini->y;
-	case 0x1A : return ini->field_1a_flags_maybe;
-	case 0x1C : return ini->field_1c;
-	case 0x1E : return ini->field_1e;
-	case 0x20 : return ini->field_20_actor_field_14;
+	case 0x1A : return ini->flags;
+	case 0x1C : return ini->baseXOffset;
+	case 0x1E : return ini->baseYOffset;
+	case 0x20 : return ini->direction2;
 	default: error("getINIField() Invalid fieldOffset 0x%X", fieldOffset);
 	}
 }
@@ -1102,16 +1102,16 @@ void ScriptOpcodes::setINIField(uint32 iniIndex, uint16 fieldOffset, uint16 valu
 	case 4 : ini->actorResourceId = value; break;
 	case 6 : ini->sequenceId = value; break;
 	case 0xc : ini->sceneId = value; break;
-	case 0xe : ini->field_e = value; break;
-	case 0x10 : ini->field_10 = value; break;
-	case 0x12 : ini->field_12 = value; break;
-	case 0x14 : ini->field_14 = value; break;
+	case 0xe : ini->direction = value; break;
+	case 0x10 : ini->counter = value; break;
+	case 0x12 : ini->objectState = value; break;
+	case 0x14 : ini->objectState2 = value; break;
 	case 0x16 : ini->x = value; break;
 	case 0x18 : ini->y = value; break;
-	case 0x1A : ini->field_1a_flags_maybe = value; break;
-	case 0x1C : ini->field_1c = value; break;
-	case 0x1E : ini->field_1e = value; break;
-	case 0x20 : ini->field_20_actor_field_14 = value; break;
+	case 0x1A : ini->flags = value; break;
+	case 0x1C : ini->baseXOffset = value; break;
+	case 0x1E : ini->baseYOffset = value; break;
+	case 0x20 : ini->direction2 = value; break;
 	default: error("setINIField() Invalid fieldOffset 0x%X", fieldOffset);
 	}
 
@@ -1130,7 +1130,7 @@ void ScriptOpcodes::opWaitForActorSequenceToFinish(ScriptOpCall &scriptOpCall) {
 	ARG_INT16(iniId);
 
 	DragonINI *ini = _vm->getINI(iniId - 1);
-	if (ini->field_1a_flags_maybe & 1) {
+	if (ini->flags & 1) {
 		while (!(ini->actor->_flags & ACTOR_FLAG_4)) {
 			_vm->waitForFrames(1);
 		}
@@ -1206,7 +1206,7 @@ void ScriptOpcodes::opWaitForActorToFinishWalking(ScriptOpCall &scriptOpCall) {
 	}
 
 	DragonINI *ini = _vm->getINI(iniId - 1);
-	if (ini->field_1a_flags_maybe & 1) {
+	if (ini->flags & 1) {
 		while (ini->actor->isFlagSet(ACTOR_FLAG_10)) {
 			_vm->waitForFrames(1);
 		}
diff --git a/engines/dragons/specialopcodes.cpp b/engines/dragons/specialopcodes.cpp
index f7cc62ac44..611b9f32d8 100644
--- a/engines/dragons/specialopcodes.cpp
+++ b/engines/dragons/specialopcodes.cpp
@@ -299,19 +299,19 @@ void SpecialOpcodes::spcCastleGardenLogic() {
 void SpecialOpcodes::spcUnk9() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
 	assert(flicker);
-	flicker->field_1a_flags_maybe |= INI_FLAG_20;
+	flicker->flags |= INI_FLAG_20;
 	assert(flicker->actor);
 	flicker->actor->_flags |= ACTOR_FLAG_100;
 	flicker->actor->_priorityLayer = 0;
-	_vm->getINI(1)->field_1a_flags_maybe |= INI_FLAG_20;
+	_vm->getINI(1)->flags |= INI_FLAG_20;
 }
 
 
 void SpecialOpcodes::spcUnkA() {
 	DragonINI *flicker = _vm->_dragonINIResource->getFlickerRecord();
-	flicker->field_1a_flags_maybe &= ~INI_FLAG_20;
+	flicker->flags &= ~INI_FLAG_20;
 	flicker->actor->_flags &= ~ACTOR_FLAG_100;
-	_vm->getINI(1)->field_1a_flags_maybe &= ~INI_FLAG_20;
+	_vm->getINI(1)->flags &= ~INI_FLAG_20;
 }
 
 void SpecialOpcodes::spcUnkC() {
@@ -901,7 +901,7 @@ void SpecialOpcodes::spcFlickerSetFlag0x80() {
 
 //used in castle garden scene with knights
 void SpecialOpcodes::spcUnk5d() {
-	_vm->getINI(_vm->getINI(0x13b)->field_12 + 0x13c)->actor->updateSequence(_vm->getINI(0x13b)->field_14);
+	_vm->getINI(_vm->getINI(0x13b)->objectState + 0x13c)->actor->updateSequence(_vm->getINI(0x13b)->objectState2);
 }
 
 void SpecialOpcodes::spcUnk5e() {
@@ -910,7 +910,7 @@ void SpecialOpcodes::spcUnk5e() {
 }
 
 void SpecialOpcodes::spcUnk5f() {
-	_vm->getINI(0x2ab)->field_12 = 0;
+	_vm->getINI(0x2ab)->objectState = 0;
 	panCamera(2);
 }
 
@@ -946,7 +946,7 @@ void SpecialOpcodes::spcUnk66() {
 	if ((var & 2) == 0) {
 		uVar9 = uVar9 + 1;
 	}
-	_vm->getINI(1)->field_12 = uVar9;
+	_vm->getINI(1)->objectState = uVar9;
 }
 
 void SpecialOpcodes::spcTournamentSetCamera() {
@@ -980,7 +980,7 @@ void SpecialOpcodes::panCamera(int16 mode) {
 	int iVar2;
 
 	if (mode == 1) {
-		_vm->getINI(0x2ab)->field_12 = _vm->_scene->_camera.x;
+		_vm->getINI(0x2ab)->objectState = _vm->_scene->_camera.x;
 		_vm->_dragonINIResource->setFlickerRecord(NULL);
 		iVar2 = (int) _vm->_scene->_camera.x;
 		iVar1 = iVar2;
@@ -1086,9 +1086,9 @@ void SpecialOpcodes::spcHedgehogTest() {
 	if (_vm->_dragonINIResource->getRecord(0x168)->actor->_sequenceID == 4 &&
 			_vm->_dragonINIResource->getRecord(0x169)->actor->_sequenceID == 4 &&
 			_vm->_dragonINIResource->getRecord(0x16a)->actor->_sequenceID == 4) {
-		_vm->_dragonINIResource->getRecord(0x169)->field_12 = 1;
+		_vm->_dragonINIResource->getRecord(0x169)->objectState = 1;
 	} else {
-		_vm->_dragonINIResource->getRecord(0x169)->field_12 = 0;
+		_vm->_dragonINIResource->getRecord(0x169)->objectState = 0;
 	}
 }
 
@@ -1202,9 +1202,9 @@ void SpecialOpcodes::spcLoadLadyOfTheLakeActor() {
 void SpecialOpcodes::spcUseClickerOnLever() {
 	if (_vm->_inventory->isOpen()) {
 		_vm->_talk->flickerRandomDefaultResponse();
-		_vm->_dragonINIResource->getRecord(0)->field_12 = 1;
+		_vm->_dragonINIResource->getRecord(0)->objectState = 1;
 	} else {
-		_vm->_dragonINIResource->getRecord(0)->field_12 = 0;
+		_vm->_dragonINIResource->getRecord(0)->objectState = 0;
 	}
 }
 
@@ -1394,15 +1394,15 @@ void castleBuildingBlackDragon2UpdateFunction() {
 	DragonsEngine *vm = getEngine();
 
 	ini = vm->_dragonINIResource->getRecord(0x231);
-	if (ini->field_10 <= 0) {
-		if (ini->field_12 == 0) {
+	if (ini->counter <= 0) {
+		if (ini->objectState == 0) {
 			ini->actor->updateSequence(0xb);
-			ini->field_10 = 0x68;
-			ini->field_12 = 1;
-		} else if (ini->field_12 == 1) {
+			ini->counter = 0x68;
+			ini->objectState = 1;
+		} else if (ini->objectState == 1) {
 			ini->actor->updateSequence(4);
-			ini->field_10 = vm->getRand(0xb4);
-			ini->field_12 = 0;
+			ini->counter = vm->getRand(0xb4);
+			ini->objectState = 0;
 		}
 	}
 }
@@ -1680,7 +1680,7 @@ void monksAtBarSceneUpdateFunction() {
 		}
 	}
 	vm->_scriptOpcodes->_specialOpCodes->setSpecialOpCounter(specialOpCounter);
-	vm->_dragonINIResource->getRecord(0)->field_12 = 0;
+	vm->_dragonINIResource->getRecord(0)->objectState = 0;
 }
 
 void flameEscapeSceneUpdateFunction() {
@@ -1764,7 +1764,7 @@ void moatDrainedSceneUpdateFunction() {
 		moatDrainedUpdateCounter = 600;
 	}
 	castleFogUpdateFunction();
-	if (((vm->_dragonINIResource->getRecord(0x208)->field_14 == 2) &&
+	if (((vm->_dragonINIResource->getRecord(0x208)->objectState2 == 2) &&
 		 !vm->isFlagSet(ENGINE_FLAG_8000))) {
 		if (moatDrainedUpdateCounter != 0) {
 			moatDrainedUpdateCounter--;
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index f89b92ae64..93f987fe89 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -434,8 +434,8 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 uint32 Talk::displayDialogAroundINI(uint32 iniId, uint16 *dialogText, uint32 textIndex) {
 	DragonINI *ini = iniId == 0 ? _vm->_dragonINIResource->getFlickerRecord() : _vm->getINI(iniId - 1);
 
-	if ((ini->field_1a_flags_maybe & 1) == 0) {
-		Img *local_v1_184 = _vm->_dragonImg->getImg(ini->field_2);
+	if ((ini->flags & 1) == 0) {
+		Img *local_v1_184 = _vm->_dragonImg->getImg(ini->imgId);
 		int x, y;
 		if (local_v1_184->field_e == 0) {
 			y = (uint)(uint16)local_v1_184->y;


Commit: 355d3087572c55f3904e6446c5cc47b749d4bf12
    https://github.com/scummvm/scummvm/commit/355d3087572c55f3904e6446c5cc47b749d4bf12
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Improved FontManager logic. More var renaming

Changed paths:
    engines/dragons/cursor.cpp
    engines/dragons/dragonrms.cpp
    engines/dragons/dragonrms.h
    engines/dragons/font.cpp
    engines/dragons/font.h
    engines/dragons/scene.cpp
    engines/dragons/screen.h


diff --git a/engines/dragons/cursor.cpp b/engines/dragons/cursor.cpp
index e837b191dc..76a4c51a6c 100644
--- a/engines/dragons/cursor.cpp
+++ b/engines/dragons/cursor.cpp
@@ -234,7 +234,7 @@ int16 Cursor::updateIniFromScene() {
 					uint32 newSeqId = 1;
 					for (int idx = 0; idx < 5; idx++) {
 						_data_800728b0_cursor_seqID = idx;
-						byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
+						byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getAfterSceneLoadedScript(sceneId);
 						ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
 //						uVar17 = uVar15;
@@ -261,7 +261,7 @@ int16 Cursor::updateIniFromScene() {
 					_data_800728b0_cursor_seqID = data_800728b0_cursor_seqID_orig;
 					return _iniUnderCursor;
 				}
-				byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getObdDataFieldC(sceneId);
+				byte *obd = _vm->_dragonOBD->getFromOpt(cursorOverIni - 1); //_dragonRMS->getAfterSceneLoadedScript(sceneId);
 				ScriptOpCall scriptOpCall(obd + 8, READ_LE_UINT32(obd));
 
 //				local_48 = dragon_Obd_Offset + *(int *)(uVar16 * 8 + dragon_Opt_Offset + -8) + 8;
diff --git a/engines/dragons/dragonrms.cpp b/engines/dragons/dragonrms.cpp
index ffc218a0ae..a62c7d0836 100644
--- a/engines/dragons/dragonrms.cpp
+++ b/engines/dragons/dragonrms.cpp
@@ -40,9 +40,9 @@ DragonRMS::DragonRMS(BigfileArchive *bigfileArchive, DragonOBD *dragonOBD) : _dr
 	for (int i = 0; i < _count; i++) {
 		_rmsObjects[i]._field0 = readStream->readSint32LE();
 		readStream->read(_rmsObjects[i]._sceneName, 4);
-		_rmsObjects[i]._obdOffset = readStream->readSint32LE();
-		_rmsObjects[i]._fieldC = readStream->readSint32LE();
-		_rmsObjects[i]._field10ObdOffset = readStream->readSint32LE();
+		_rmsObjects[i]._afterDataLoadScript = readStream->readSint32LE();
+		_rmsObjects[i]._afterSceneLoadScript = readStream->readSint32LE();
+		_rmsObjects[i]._beforeLoadScript = readStream->readSint32LE();
 		_rmsObjects[i]._inventoryBagPosition = readStream->readSint16LE();
 		_rmsObjects[i]._field16 = readStream->readSint32LE();
 		_rmsObjects[i]._field1a = readStream->readSint16LE();
@@ -53,16 +53,16 @@ char *DragonRMS::getSceneName(uint32 sceneId) {
 	return getRMS(sceneId)->_sceneName;
 }
 
-byte *DragonRMS::getObdData(uint32 sceneId) {
-	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_obdOffset);
+byte *DragonRMS::getBeforeSceneDataLoadedScript(uint32 sceneId) {
+	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_beforeLoadScript);
 }
 
-byte *DragonRMS::getObdDataField10(uint32 sceneId) {
-	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_field10ObdOffset);
+byte *DragonRMS::getAfterSceneDataLoadedScript(uint32 sceneId) {
+	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_afterDataLoadScript);
 }
 
-byte *DragonRMS::getObdDataFieldC(uint32 sceneId) {
-	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_fieldC);
+byte *DragonRMS::getAfterSceneLoadedScript(uint32 sceneId) {
+	return _dragonOBD->getObdAtOffset(getRMS(sceneId)->_afterSceneLoadScript);
 }
 
 int16 DragonRMS::getInventoryPosition(uint32 sceneId) {
diff --git a/engines/dragons/dragonrms.h b/engines/dragons/dragonrms.h
index 763d756e6f..b869095804 100644
--- a/engines/dragons/dragonrms.h
+++ b/engines/dragons/dragonrms.h
@@ -29,9 +29,9 @@ namespace Dragons {
 struct RMS {
 	int32 _field0;
 	char _sceneName[4];
-	uint32 _obdOffset;
-	int32 _fieldC;
-	uint32 _field10ObdOffset;
+	uint32 _afterDataLoadScript;
+	int32 _afterSceneLoadScript;
+	uint32 _beforeLoadScript;
 	int16 _inventoryBagPosition;
 	int32 _field16;
 	int16 _field1a;
@@ -48,9 +48,9 @@ private:
 public:
 	DragonRMS(BigfileArchive *bigfileArchive, DragonOBD *dragonOBD);
 	char *getSceneName(uint32 sceneId);
-	byte *getObdData(uint32 sceneId);
-	byte *getObdDataField10(uint32 sceneId);
-	byte *getObdDataFieldC(uint32 sceneId);
+	byte *getAfterSceneDataLoadedScript(uint32 sceneId);
+	byte *getBeforeSceneDataLoadedScript(uint32 sceneId);
+	byte *getAfterSceneLoadedScript(uint32 sceneId);
 	int16 getInventoryPosition(uint32 sceneId);
 
 private:
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index 577fd50704..c9a375dac8 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -28,7 +28,6 @@
 #include "dragons/screen.h"
 #include "dragons/dragons.h"
 
-
 namespace Dragons {
 
 Font::Font(Common::SeekableReadStream &stream, uint32 mapSize, uint32 pixelOffset, uint32 pixelSize) {
@@ -70,6 +69,9 @@ Graphics::Surface *Font::render(uint16 *text, uint16 length) {
 }
 
 void Font::renderToSurface(Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint16 length) {
+	if (x < 0 || y < 0 || x + length * 8 >= DRAGONS_SCREEN_WIDTH || y + 8 >= DRAGONS_SCREEN_HEIGHT) {
+		return;
+	}
 	byte *startPixelOffset = (byte *)surface->getPixels() + y * surface->pitch + x * surface->format.bytesPerPixel;
 	for (int i = 0; i < length; i++) {
 		byte *pixels = startPixelOffset;
@@ -84,7 +86,7 @@ void Font::renderToSurface(Graphics::Surface *surface, int16 x, int16 y, uint16
 	}
 }
 
-FontManager::FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive): _vm(vm), _screen(screen) {
+FontManager::FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive): _vm(vm), _screen(screen), _numTextEntries(0) {
 	uint32 fileSize;
 	byte *data = bigfileArchive->load("fntfiles.dat", fileSize);
 	Common::SeekableReadStream *readStream = new Common::MemoryReadStream(data, fileSize, DisposeAfterUse::YES);
@@ -93,47 +95,40 @@ FontManager::FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigf
 	_fonts[1] = loadFont(1, *readStream);
 	_fonts[2] = loadFont(2, *readStream);
 
-	loadPalettes();
-
 	delete readStream;
 
 	_dat_80086f48_fontColor_flag = 0;
+
+	_surface = new Graphics::Surface();
+	_surface->create(DRAGONS_SCREEN_WIDTH, DRAGONS_SCREEN_HEIGHT, Graphics::PixelFormat::createFormatCLUT8());
+	clearText(); //clear backing surface.
 }
 
 FontManager::~FontManager() {
 	delete _fonts[0];
 	delete _fonts[1];
 	delete _fonts[2];
-	free(_palettes);
+
+	_surface->free();
+	delete _surface;
 }
 
 void FontManager::addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 fontType) {
 	assert(length < 1024);
 	assert(fontType < 4);
-	ScreenTextEntry *screenTextEntry = new ScreenTextEntry();
-	screenTextEntry->position = Common::Point(x, y);
-	screenTextEntry->surface = _fonts[fontType]->render(text, length);
-
-	_screenTexts.push_back(screenTextEntry);
+	_fonts[fontType]->renderToSurface(_surface, x, y, text, length);
+	++_numTextEntries;
 }
 
 void FontManager::draw() {
-	Common::List<ScreenTextEntry*>::iterator it = _screenTexts.begin();
-	while (it != _screenTexts.end()) {
-		ScreenTextEntry *entry = *it;
-		_screen->copyRectToSurface8bpp(*entry->surface, _screen->getPalette(2), entry->position.x, entry->position.y, Common::Rect(entry->surface->w, entry->surface->h), false, NORMAL);
-		it++;
+	if(_numTextEntries > 0) {
+		_screen->copyRectToSurface8bpp(*_surface, _screen->getPalette(2), 0, 0, Common::Rect(_surface->w, _surface->h), false, NORMAL);
 	}
 }
 
 void FontManager::clearText() {
-	while (!_screenTexts.empty()) {
-		ScreenTextEntry *screenText = _screenTexts.back();
-		screenText->surface->free();
-		delete screenText->surface;
-		delete screenText;
-		_screenTexts.pop_back();
-	}
+	_numTextEntries = 0;
+	_surface->fillRect(Common::Rect(0, 0, _surface->w - 1, _surface->h - 1), 0);
 }
 
 Font *FontManager::loadFont(uint16 index, Common::SeekableReadStream &stream) {
@@ -160,40 +155,6 @@ Font *FontManager::loadFont(uint16 index, Common::SeekableReadStream &stream) {
 	return new Font(stream, mapSize, pixelsOffset, pixelsSize);
 }
 
-uint16 packColor(uint8 r, uint8 g, uint8 b) {
-	return (r / 8) << 10 | (g / 8) << 5 | (b / 8);
-}
-
-void FontManager::loadPalettes() {
-//	Common::File fd;
-//	if (!fd.open("dragon.exe")) {
-//		error("Failed to open dragon.exe");
-//	}
-//	fd.seek(0x5336c); //TODO handle other game variants
-//
-//	_palettes = (byte *)malloc(256 * 2 * 4);
-//	fd.read(_palettes, 256 * 2 * 4);
-//
-//	_palettes[2 * 256 + 0x21] = 0x80; //HACK make this color transparent
-//	fd.close();
-
-	//TODO where does original set its palette???
-	_palettes = (byte *)malloc(0x200);
-	memset(_palettes, 0, 0x200);
-	WRITE_LE_INT16(&_palettes[0], 0x8000);
-
-//	WRITE_LE_INT16(&_palettes[0x11 * 2], packColor(95, 95, 95));
-	WRITE_LE_INT16(&_palettes[0x10 * 2], packColor(0, 0, 0) | 0x8000);
-	WRITE_LE_INT16(&_palettes[0x11 * 2], 0x7fe0); //packColor(254, 255, 0));
-	WRITE_LE_INT16(&_palettes[0x12 * 2], 0); //packColor(95, 95, 95));
-	WRITE_LE_INT16(&_palettes[0x13 * 2], packColor(175, 175, 175));
-
-	WRITE_LE_INT16(&_palettes[0x20 * 2], packColor(0, 0, 0) | 0x8000);
-	WRITE_LE_INT16(&_palettes[0x21 * 2], packColor(175, 175, 175));
-	WRITE_LE_INT16(&_palettes[0x22 * 2], 0);
-	WRITE_LE_INT16(&_palettes[0x23 * 2], packColor(175, 175, 175));
-}
-
 void updatePalEntry(uint16 *pal, uint16 index, uint16 newValue) {
 	newValue = (uint16)(((uint16)newValue & 0x1f) << 10) | (uint16)(((uint16)newValue & 0x7c00) >> 10) |
 			(newValue & 0x3e0) | (newValue & 0x8000);
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index 0c801a9ca5..f8b22202f2 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -50,11 +50,6 @@ private:
 	uint16 mapChar(uint16 in);
 };
 
-struct ScreenTextEntry {
-	Common::Point position;
-	Graphics::Surface *surface;
-};
-
 class FontManager {
 public:
 	Font *_fonts[3];
@@ -63,8 +58,9 @@ private:
 	uint16 _dat_80086f48_fontColor_flag;
 	DragonsEngine *_vm;
 	Screen *_screen;
-	Common::List<ScreenTextEntry *> _screenTexts;
-	byte *_palettes;
+	Graphics::Surface *_surface;
+
+	int _numTextEntries;
 
 public:
 	FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigfileArchive);
@@ -76,7 +72,6 @@ public:
 
 private:
 	Font *loadFont(uint16 index, Common::SeekableReadStream &stream);
-	void loadPalettes();
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index 9085b1cc84..3afb296d2a 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -74,7 +74,7 @@ void Scene::loadScene(uint32 sceneId, uint32 cameraPointId) {
 	_data_800633ee = 0;
 
 	if (!(sceneId & 0x8000)) {
-		byte *obd = _dragonRMS->getObdDataFieldC(sceneId);
+		byte *obd = _dragonRMS->getAfterSceneLoadedScript(sceneId);
 		ScriptOpCall scriptOpCall(obd + 4, READ_LE_UINT32(obd));
 		_scriptOpcodes->runScript(scriptOpCall);
 	}
@@ -104,7 +104,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	_screen->setScreenShakeOffset(0, 0);
 
 	if (!(sceneId & 0x8000)) {
-		byte *obd = _dragonRMS->getObdDataField10(sceneId);
+		byte *obd = _dragonRMS->getBeforeSceneDataLoadedScript(sceneId);
 		ScriptOpCall scriptOpCall(obd + 4, READ_LE_UINT32(obd));
 		uint16 oldSceneId = _currentSceneId;
 		_currentSceneId = -1;
@@ -326,7 +326,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	}
 
 	if (!(sceneId & 0x8000)) {
-		byte *obd = _dragonRMS->getObdData(sceneId);
+		byte *obd = _dragonRMS->getAfterSceneDataLoadedScript(sceneId);
 		ScriptOpCall scriptOpCall(obd + 4, READ_LE_UINT32(obd));
 		_scriptOpcodes->runScript(scriptOpCall);
 	}
diff --git a/engines/dragons/screen.h b/engines/dragons/screen.h
index 0cee05023f..4639a48c04 100644
--- a/engines/dragons/screen.h
+++ b/engines/dragons/screen.h
@@ -30,6 +30,9 @@ namespace Dragons {
 #define DRAGONS_NUM_PALETTES 5
 #define DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE 256
 
+#define DRAGONS_SCREEN_WIDTH 320
+#define DRAGONS_SCREEN_HEIGHT 200
+
 enum AlphaBlendMode {
 	NONE,
 	NORMAL,       // 50% x Back + 50% x Sprite


Commit: f7e7d5649ef4af9a12bc63a18d5f1d7591fcb95b
    https://github.com/scummvm/scummvm/commit/f7e7d5649ef4af9a12bc63a18d5f1d7591fcb95b
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Added dialog box borders

Changed paths:
    engines/dragons/cutscene.cpp
    engines/dragons/dragons.cpp
    engines/dragons/font.cpp
    engines/dragons/font.h
    engines/dragons/minigame2.cpp
    engines/dragons/minigame3.cpp
    engines/dragons/minigame4.cpp
    engines/dragons/talk.cpp
    engines/dragons/talk.h


diff --git a/engines/dragons/cutscene.cpp b/engines/dragons/cutscene.cpp
index 700171d9b6..b2f08b6c3e 100644
--- a/engines/dragons/cutscene.cpp
+++ b/engines/dragons/cutscene.cpp
@@ -280,7 +280,7 @@ void CutScene::scene1() {
 //																									if (((_actor_8008e7e8 != 0) || (_actor_8008e848 != 0))
 //																										|| ((_actor_8008e844 != 0 || (_actor_8008e874 != 0)))
 //																											) {
-//																										FUN_8001a7c4((uint)_actor_8008e7e8,
+//																										clearTextDialog((uint)_actor_8008e7e8,
 //																													 (uint)_actor_8008e844,
 //																													 (uint)_actor_8008e848,
 //																													 (uint)_actor_8008e874);
diff --git a/engines/dragons/dragons.cpp b/engines/dragons/dragons.cpp
index 522b516025..44de724785 100644
--- a/engines/dragons/dragons.cpp
+++ b/engines/dragons/dragons.cpp
@@ -1167,6 +1167,9 @@ void DragonsEngine::loadScene(uint16 sceneId) {
 	setupPalette1();
 
 	_screen->loadPalette(2, _cursor->getPalette());
+	_screen->updatePaletteTransparency(2, 1, 5, true);
+	_screen->updatePaletteTransparency(2, 0xc1, 0xc3, true);
+
 	_screen->loadPalette(4, _cursor->getPalette());
 	_screen->updatePaletteTransparency(4, 1, 0xff, true);
 
diff --git a/engines/dragons/font.cpp b/engines/dragons/font.cpp
index c9a375dac8..c65472571a 100644
--- a/engines/dragons/font.cpp
+++ b/engines/dragons/font.cpp
@@ -102,6 +102,8 @@ FontManager::FontManager(DragonsEngine *vm, Screen *screen, BigfileArchive *bigf
 	_surface = new Graphics::Surface();
 	_surface->create(DRAGONS_SCREEN_WIDTH, DRAGONS_SCREEN_HEIGHT, Graphics::PixelFormat::createFormatCLUT8());
 	clearText(); //clear backing surface.
+
+	_boxFontChr = bigfileArchive->load("boxfont.chr", fileSize);
 }
 
 FontManager::~FontManager() {
@@ -111,6 +113,8 @@ FontManager::~FontManager() {
 
 	_surface->free();
 	delete _surface;
+
+	free(_boxFontChr);
 }
 
 void FontManager::addText(int16 x, int16 y, uint16 *text, uint16 length, uint8 fontType) {
@@ -166,6 +170,7 @@ void FontManager::updatePalette() {
 	uint16 *palette_f2_font_maybe = (uint16 *)_screen->getPalette(2);
 	uint16 cursor3 = 0x14a5 | 0x8000;
 	if (_vm->isFlagSet(ENGINE_FLAG_200)) {
+		updatePalEntry(palette_f2_font_maybe, 1, 0);
 		if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
 			updatePalEntry(palette_f2_font_maybe, 16, cursor3);
 		} else {
@@ -197,4 +202,53 @@ void FontManager::updatePalette() {
 	}
 }
 
+void FontManager::drawTextDialogBox(uint32 x1, uint32 y1, uint32 x2, uint32 y2) {
+	const uint16 kTextColCount = 0x28;
+	const uint16 kTileBaseIndex = 1;
+	const uint16 kTileIndexTop = kTileBaseIndex + 10;
+	const uint16 kTileIndexBottom = kTileBaseIndex + 16;
+	const uint16 kTileIndexLeft = kTileBaseIndex + 12;
+	const uint16 kTileIndexRight = kTileBaseIndex + 14;
+	const uint16 kTileIndexBackground = kTileBaseIndex + 13;
+	const uint16 kTileIndexTopLeft = kTileBaseIndex + 9;
+	const uint16 kTileIndexTopRight = kTileBaseIndex + 11;
+	const uint16 kTileIndexBottomLeft = kTileBaseIndex + 15;
+	const uint16 kTileIndexBottomRight = kTileBaseIndex + 17;
+	// Fill background
+	for (int yc = y1 + 1; yc <= y2 - 1; ++yc) {
+		for (int xc = x1 + 1; xc <= x2 - 1; ++xc) {
+			drawBoxChar(xc, yc, kTileIndexBackground);
+		}
+	}
+	// Fill top and bottom rows
+	for (int xc = x1 + 1; xc <= x2 - 1; ++xc) {
+		drawBoxChar(xc, y1, kTileIndexTop);
+		drawBoxChar(xc, y2, kTileIndexBottom);
+	}
+	// Fill left and right columns
+	for (int yc = y1 + 1; yc <= y2 - 1; ++yc) {
+		drawBoxChar(x1, yc, kTileIndexLeft);
+		drawBoxChar(x2, yc, kTileIndexRight);
+	}
+	// Fill corners
+	drawBoxChar(x1, y1, kTileIndexTopLeft);
+	drawBoxChar(x2, y1, kTileIndexTopRight);
+	drawBoxChar(x1, y2, kTileIndexBottomLeft);
+	drawBoxChar(x2, y2, kTileIndexBottomRight);
+}
+
+void FontManager::clearTextDialog(uint32 x1, uint32 y1, uint32 x2, uint32 y2) {
+
+}
+
+void FontManager::drawBoxChar(uint32 x, uint32 y, uint8 tileIndex) {
+	byte *pixels = (byte *)_surface->getBasePtr(x * 8, y * 8);
+	byte *data = _boxFontChr + tileIndex * 64;
+	for (int j = 0; j < 8; j++) {
+		memcpy(pixels, data, 8);
+		data += 8;
+		pixels += _surface->pitch;
+	}
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/font.h b/engines/dragons/font.h
index f8b22202f2..3d581bb643 100644
--- a/engines/dragons/font.h
+++ b/engines/dragons/font.h
@@ -59,6 +59,7 @@ private:
 	DragonsEngine *_vm;
 	Screen *_screen;
 	Graphics::Surface *_surface;
+	byte *_boxFontChr;
 
 	int _numTextEntries;
 
@@ -69,9 +70,12 @@ public:
 	void draw();
 	void clearText();
 	void updatePalette();
+	void drawTextDialogBox(uint32 x1, uint32 y1, uint32 x2, uint32 y2);
+	void clearTextDialog(uint32 x1, uint32 y1, uint32 x2, uint32 y2);
 
 private:
 	Font *loadFont(uint16 index, Common::SeekableReadStream &stream);
+	void drawBoxChar(uint32 x, uint32 y, uint8 tileIndex);
 };
 
 } // End of namespace Dragons
diff --git a/engines/dragons/minigame2.cpp b/engines/dragons/minigame2.cpp
index f1962d0041..9f9a8b4dca 100644
--- a/engines/dragons/minigame2.cpp
+++ b/engines/dragons/minigame2.cpp
@@ -254,7 +254,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 
 		if ((_dat_80093c9c != 0) && !_vm->isFlagSet(ENGINE_FLAG_8000)) {
 			loungealotHeadActor->updateSequence(0);
-			//TODO _vm->_talk->FUN_8001a7c4((uint)_dat_8008e7e8, (uint)_dat_8008e844, (uint)_dat_8008e848, (uint)_dat_8008e874);
+			//TODO _vm->_talk->clearTextDialog((uint)_dat_8008e7e8, (uint)_dat_8008e844, (uint)_dat_8008e848, (uint)_dat_8008e874);
 			_dat_80093c9c = 0;
 		}
 		if (_dat_80093c94 != 0) {
@@ -314,16 +314,16 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 			 */
 			LAB_800907c4:
 			if (!bVar4) {
-				//TODO FUN_8001a4e4_draw_dialogbox(4, 0x14, 0xd, 0x16, 1);
-				//TODO FUN_8001a4e4_draw_dialogbox(4, 0x10, 0xd, 0x12, 1);
+				//TODO drawTextDialogBox(4, 0x14, 0xd, 0x16, 1);
+				//TODO drawTextDialogBox(4, 0x10, 0xd, 0x12, 1);
 				uVar14->_priorityLayer = 6;
 				uVar15->_priorityLayer = 6;
 				bVar4 = true;
 			}
 		}
 		if ((((local_278 == 0) && (local_27a == 0)) && (local_258 == 0)) && (bVar4)) {
-			// TODO FUN_8001a7c4(4, 0x14, 0xd, 0x16);
-			// TODO FUN_8001a7c4(4, 0x10, 0xd, 0x12);
+			// TODO clearTextDialog(4, 0x14, 0xd, 0x16);
+			// TODO clearTextDialog(4, 0x10, 0xd, 0x12);
 			uVar14->_priorityLayer = 0;
 			uVar15->_priorityLayer = 0;
 			bVar4 = false;
@@ -418,7 +418,7 @@ void Minigame2::run(int16 param_1, uint16 param_2, int16 param_3) {
 							_vm->waitForFrames(1);
 							_vm->_screen->loadPalette(0, paletteData);
 							_vm->_screen->loadPalette(1, paletteData);
-//	TODO						FUN_8001a7c4((uint)_dat_8008e7e8, (uint)_dat_8008e844, (uint)_dat_8008e848,
+//	TODO						clearTextDialog((uint)_dat_8008e7e8, (uint)_dat_8008e844, (uint)_dat_8008e848,
 //										 (uint)_dat_8008e874);
 							//punched in the face.
 							break;
@@ -736,7 +736,7 @@ void Minigame2::fun_80093aec_dialog(uint32 textId, int16 x, int16 y) {
 //TODO
 //	if ((((_dat_8008e7e8_dialogBox_x1 != 0) || (_dat_8008e848_dialogBox_x2 != 0)) ||
 //		 (_dat_8008e844_dialogBox_y1 != 0)) || (_dat_8008e874_dialogBox_y2 != 0)) {
-//		_vm->_talk->FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1, (uint)_dat_8008e844_dialogBox_y1,
+//		_vm->_talk->clearTextDialog((uint)_dat_8008e7e8_dialogBox_x1, (uint)_dat_8008e844_dialogBox_y1,
 //					 (uint)_dat_8008e848_dialogBox_x2, (uint)_dat_8008e874_dialogBox_y2);
 //	}
 	_vm->_talk->loadText(textId, auStack4024, 2000);
diff --git a/engines/dragons/minigame3.cpp b/engines/dragons/minigame3.cpp
index fe8cb538ed..f85637a989 100644
--- a/engines/dragons/minigame3.cpp
+++ b/engines/dragons/minigame3.cpp
@@ -296,7 +296,7 @@ void Minigame3::run() {
 	_vm->waitForFrames(0xf);
 	_vm->_talk->loadAndDisplayDialogAroundPoint(0x479A, 0x14, 3, 0x1e01, 0);
 	_vm->waitForFrames(0x1e);
-	// TODO FUN_8001a7c4((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
+	// TODO clearTextDialog((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
 	i = 0;
 	while ((int16)i < 4) {
 		if (goodRabbitPositionTbl[(int16)i] == 0) {
@@ -325,7 +325,7 @@ void Minigame3::run() {
 	}
 	_vm->waitForFrames(0x1e);
 	_vm->waitForFrames(0x1e);
-	// TODO FUN_8001a7c4((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
+	// TODO clearTextDialog((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
 	local_56 = 0;
 	local_1c0 = 0;
 	currentState = 2;
@@ -583,7 +583,7 @@ void Minigame3::run() {
 			}
 		}
 		if ((local_e != 0) && (local_10 == 0)) {
-			//TODO implement this. FUN_8001a7c4((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
+			//TODO implement this. clearTextDialog((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
 			local_e = 0;
 		}
 		if ((local_e != 0) && (local_10 != 0)) {
diff --git a/engines/dragons/minigame4.cpp b/engines/dragons/minigame4.cpp
index 17f007d33c..9111b50e48 100644
--- a/engines/dragons/minigame4.cpp
+++ b/engines/dragons/minigame4.cpp
@@ -203,7 +203,7 @@ uint16 Minigame4::runDanceBattle() {
 			//TODO
 //			if ((((DAT_8008e7e8 != 0) || (DAT_8008e848 != 0)) || (DAT_8008e844 != 0)) ||
 //				(DAT_8008e874 != 0)) {
-//				FUN_8001a7c4((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
+//				clearTextDialog((uint)DAT_8008e7e8, (uint)DAT_8008e844, (uint)DAT_8008e848, (uint)DAT_8008e874);
 //			}
 			_flickerActor->waitUntilFlag8SetThenSet1000AndWaitFor4();
 			_flickerActor->updateSequence(7);
diff --git a/engines/dragons/talk.cpp b/engines/dragons/talk.cpp
index 93f987fe89..0606d5a682 100644
--- a/engines/dragons/talk.cpp
+++ b/engines/dragons/talk.cpp
@@ -354,8 +354,8 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 			_dat_8008e874_dialogBox_y2 = _dat_8008e844_dialogBox_y1 + sVar4 * _dat_800726f0_tfont_field2 + 1;
 			if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) && ((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)))) {
 				unaff_s4 = 0;
-				FUN_8001a4e4_draw_dialogbox((uint) _dat_8008e7e8_dialogBox_x1, (uint) _dat_8008e844_dialogBox_y1,
-											(uint) _dat_8008e848_dialogBox_x2, (uint) _dat_8008e874_dialogBox_y2, 0);
+				drawDialogBox((uint) _dat_8008e7e8_dialogBox_x1, (uint) _dat_8008e844_dialogBox_y1,
+							  (uint) _dat_8008e848_dialogBox_x2, (uint) _dat_8008e874_dialogBox_y2, 0);
 				if (sVar4 > 0) {
 					for (; unaff_s4 < sVar4; unaff_s4++) {
 						if ((short)x < 0x14) {
@@ -413,8 +413,8 @@ uint8 Talk::conversation_related_maybe(uint16 *dialogText, uint16 x, uint16 y, u
 			LAB_80032e18:
 			//TODO CheckIfCdShellIsOpen();
 			if (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1)) {
-				FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1, (uint)_dat_8008e844_dialogBox_y1,
-							 (uint)_dat_8008e848_dialogBox_x2, (uint)_dat_8008e874_dialogBox_y2);
+				clearTextDialog((uint) _dat_8008e7e8_dialogBox_x1, (uint) _dat_8008e844_dialogBox_y1,
+								(uint) _dat_8008e848_dialogBox_x2, (uint) _dat_8008e874_dialogBox_y2);
 			}
 		} while (!_vm->isUnkFlagSet(ENGINE_UNK1_FLAG_1) &&
 				 (((!_vm->isFlagSet(ENGINE_FLAG_1000_TEXT_ENABLED) || (param_7 != 0)) && (*curDialogTextPtr != 0))));
@@ -693,7 +693,7 @@ TalkDialogEntry *Talk::displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dia
 			uVar3 = (uint)uVar8;
 		} while (uVar8 < numEntries);
 	}
-	FUN_8001a4e4_draw_dialogbox(1, 0x17 - (uint)local_58 & 0xffff, 0x26, 0x18, 1);
+	drawDialogBox(1, 0x17 - (uint) local_58 & 0xffff, 0x26, 0x18, 1);
 	uVar8 = 0;
 	_vm->_cursor->updateSequenceID(3);
 	local_50 = -2;
@@ -1002,9 +1002,10 @@ uint32 Talk::strlenUTF16(uint16 *text) {
 	return i;
 }
 
-void Talk::FUN_8001a4e4_draw_dialogbox(uint32 x1, uint32 y1, uint32 x2, uint32 y2, uint16 unk) {
+void Talk::drawDialogBox(uint32 x1, uint32 y1, uint32 x2, uint32 y2, uint16 unk) {
 	//TODO this might be rendering the box under the text.
-	debug("FUN_8001a4e4_draw_dialogbox(%d, %d, %d, %d, %d)", x1, y1, x2, y2, unk);
+	debug("drawTextDialogBox(%d, %d, %d, %d, %d)", x1, y1, x2, y2, unk);
+	_vm->_fontManager->drawTextDialogBox(x1, y1, x2, y2);
 }
 
 uint16 *Talk::findCharInU16Str(uint16 *text, uint16 chr) {
@@ -1034,8 +1035,9 @@ uint16 *Talk::UTF16ToUTF16Z(uint16 *dest, uint16 *src) {
 	return dest;
 }
 
-void Talk::FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2) {
+void Talk::clearTextDialog(uint32 x1, uint32 y1, uint32 x2, uint32 y2) {
 	//TODO
+	debug("Clear text (%d,%d) -> (%d,%d)", x1, y1, x2, y2);
 	_vm->_fontManager->clearText();
 }
 
@@ -1109,8 +1111,8 @@ void Talk::clearDialogEntries() {
 }
 
 void Talk::FUN_8001a7c4_clearDialogBoxMaybe() {
-	FUN_8001a7c4((uint)_dat_8008e7e8_dialogBox_x1, (uint)_dat_8008e844_dialogBox_y1,
-			(uint)_dat_8008e848_dialogBox_x2, (uint)_dat_8008e874_dialogBox_y2);
+	clearTextDialog((uint) _dat_8008e7e8_dialogBox_x1, (uint) _dat_8008e844_dialogBox_y1,
+					(uint) _dat_8008e848_dialogBox_x2, (uint) _dat_8008e874_dialogBox_y2);
 }
 
 void Talk::playDialogAudioDontWait(uint32 textIndex) {
diff --git a/engines/dragons/talk.h b/engines/dragons/talk.h
index 2852a06d60..b9748828f0 100644
--- a/engines/dragons/talk.h
+++ b/engines/dragons/talk.h
@@ -93,7 +93,7 @@ public:
 	void playDialogAudioDontWait(uint32 textIndex);
 
 private:
-	void FUN_8001a7c4(uint32 x1, uint32 y1, uint32 x2, uint32 y2); //clear box maybe?
+	void clearTextDialog(uint32 x1, uint32 y1, uint32 x2, uint32 y2); //clear box maybe?
 	void copyTextToBuffer(uint16 *destBuffer, byte *src, uint32 destBufferLength);
 	uint32 wideStrLen(uint16 *text);
 	TalkDialogEntry *displayTalkDialogMenu(Common::Array<TalkDialogEntry*> dialogEntries);
@@ -102,7 +102,7 @@ private:
 	void initDefaultResponseTable();
 	uint32 strlenUTF16(uint16 *text);
 	uint16 *findCharInU16Str(uint16 *text, uint16 chr);
-	void FUN_8001a4e4_draw_dialogbox(uint32 x1, uint32 y1, uint32 x2, uint32 y2, uint16 unk);
+	void drawDialogBox(uint32 x1, uint32 y1, uint32 x2, uint32 y2, uint16 unk);
 	uint16 *UTF16ToUTF16Z(uint16 *dest, uint16 *src);
 	uint16 FindLastPositionOf5cChar(uint16 *text);
 	uint32 FUN_80031c28(uint16 *srcText, uint16 *destText, uint32 cutLength, uint16 param_4);


Commit: fad43ef8be00084a482a1f62a247dd107df924e7
    https://github.com/scummvm/scummvm/commit/fad43ef8be00084a482a1f62a247dd107df924e7
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Changed engine methods from virtual to override

Changed paths:
    engines/dragons/dragons.h
    engines/dragons/saveload.cpp


diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index a9ba671e30..0d285d8c91 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -204,16 +204,16 @@ public:
 	~DragonsEngine();
 
 	void updateEvents();
-	virtual Common::Error run();
+	Common::Error run() override;
 
 	const char *getSavegameFilename(int num);
 	static Common::String getSavegameFilename(const Common::String &target, int num);
 	static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
 
-	virtual Common::Error loadGameState(int slot);
-	virtual bool canLoadGameStateCurrently();
-	virtual Common::Error saveGameState(int slot, const Common::String &desc);
-	virtual bool canSaveGameStateCurrently();
+	Common::Error loadGameState(int slot) override;
+	bool canLoadGameStateCurrently() override;
+	Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave) override;
+	bool canSaveGameStateCurrently() override;
 
 	void updateActorSequences();
 	void setFlags(uint32 flags);
diff --git a/engines/dragons/saveload.cpp b/engines/dragons/saveload.cpp
index eaf51b878a..d6d3da8835 100644
--- a/engines/dragons/saveload.cpp
+++ b/engines/dragons/saveload.cpp
@@ -147,7 +147,7 @@ Common::Error DragonsEngine::loadGameState(int slot) {
 	return Common::kNoError;
 }
 
-Common::Error DragonsEngine::saveGameState(int slot, const Common::String &description) {
+Common::Error DragonsEngine::saveGameState(int slot, const Common::String &description, bool isAutoSave) {
 	const char *fileName = getSavegameFilename(slot);
 	if (!savegame(fileName, description.c_str()))
 		return Common::kWritingFailed;


Commit: 0c12087ccca878281dccd1c6d760a615ddf2fc77
    https://github.com/scummvm/scummvm/commit/0c12087ccca878281dccd1c6d760a615ddf2fc77
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-02-25T14:43:42+01:00

Commit Message:
DRAGONS: Removed temp ushort define

Changed paths:
    engines/dragons/dragons.h


diff --git a/engines/dragons/dragons.h b/engines/dragons/dragons.h
index 0d285d8c91..21755ee033 100644
--- a/engines/dragons/dragons.h
+++ b/engines/dragons/dragons.h
@@ -28,8 +28,6 @@
 
 namespace Dragons {
 
-#define ushort uint16
-
 enum {
 	kGameIdDragons = 1
 };




More information about the Scummvm-git-logs mailing list