[Scummvm-git-logs] scummvm master -> 74ce6af22e6916179f426a180a69cc0031ac8e05

sev- sev at scummvm.org
Wed Mar 28 17:39:34 CEST 2018


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

Summary:
5757ffaff0 LILLIPUT: Add skeletton
561b20edde LILLIPUT: Add resource loading
38b7961bcb LILLIPUT: Add detection for French, German and Italian versions
6ab621dbd7 LILLIPUT: Add a script handler skeletton. All opcodes are stubbed
4dd99da6dc LILLIPUT: Start implementing some functions
17320cadb7 LILLIPUT: Implement OC_sub184F5, modify struct18560
53518bc677 LILLIPUT: Fix a couple of bugs in handleOpcode()
7865322c0a LILLIPUT: Implement a couple of other opcodes, add proper debugc
629b142206 LILLIPUT: Implement some more opcodes
07f7ddde0f LILLIPUT: Implement 4 more opcodes
a2fc07a702 LILLIPUT: Complete function getValue2()
2acfb7e2b3 LILLIPUT: Implement some more opcodes, fix stupid bug in script parser termination check
4ed7a10155 LILLIPUT: Add default palette, and palette fixup (thanks to SylvainTV for the help)
bda5b14cdc LILLIPUT: Partially implement displayVGAFile(). Title is now displayed
cabc7a375d LILLIPUT: Add preliminar mouse handler
47b9c1f6a7 LILLIPUT: Modify event polling
0ee1ba0786 LILLIPUT: Fix a bug in VGA file loading
a5271f5418 LILLIPUT: Add preliminar menu support and main loop
58dc875b2e LILLIPUT: Start game scripts
9074e59fef LILLIPUT: Implement opcodes used by game scripts 3 and 4
ea8d934d60 LILLIPUT: Implement opcodes. 29 groups are now executed in a row
697ab10bf3 LILLIPUT: Implement more opcodes
a08b34fea8 LILLIPUT: Add some more opcodes. Engine is now alive!
31d4f07505 LILLIPUT: start implementing display functions
e21bb14313 LILLIPUT: Fix bug in previous commit, implement one more display function
d924342d2d LILLIPUT: Implement display function 2. This fixes mouse display
847098c705 LILLIPUT: Implement display function 6, start implementing display function 12.
3ffb103d57 LILLIPUT: Some more display functions
0c0182d364 LILLIPUT: Fix to render cubes
c67d5e127d LILLIPUT: Isomap rendering complete
3780999f3d LILLIPUT: Implement two more display functions
eeb69f46bc LILLIPUT: Implement fade in/fade out
4fd8507768 LILLIPUT: Start implementing engine update (int 8 replacement in the original)
c3ca01737b LILLIPUT: Int8 called every 20ms
0139ce6853 LILLIPUT: Fix 20ms frame glitch
70f1d349c5 LILLIPUT: Implement some more parts of "int 8"
f2512b82c2 LILLIPUT: Put sound stubs in a separated class
8f8dadb9e1 LILLIPUT: Implement some more functions
5d21c237f7 LILLIPUT: Add display string, accelerate fading to 50Hkz
16ec550df5 LILLIPUT: Fix display string functions, some renaming
c6ee25b179 LILLIPUT: Minor fixes
ebb7f492f0 LILLIPUT: Fix a couple of check errors in sub16626, implement some more more core functions
c4dc1e3761 LILLIPUT: Add display heroism bar
c304967abc LILLIPUT: Rename fading functions
8bc2d28e5d LILLIPUT: Small additions
b4629af558 LILLIPUT: fix regression in 6aef68e246448977f2b8ba1bb19a17d8eaf61642
98b39800a8 LILLIPUT: Implementation of sub16CA0
8d5c377b45 LILLIPUT: (Hopefully) fix sub16CA0
7bbfe71785 LILLIPUT: Implemented sub16DD5
a8699a809e LILLIPUT: Add missing addition in sub16DD5
1864f1e518 LILLIPUT: Implement some more core functions
b348db605b LILLIPUT: Implements character display on map
1b86a778f3 LILLIPUT: Implements displayFunction18
59b9b70413 LILLIPUT: Implement some more functions
9054e0f0d6 LILLIPUT: Fix a couple of glitches
bbea84b4b1 LILLIPUT: Character rendering
b525867d4a LILLIPUT: Small fixes and renaming
5b6014fb77 LILLIPUT: Implement 4 more opcodes
5ede42cd6a LILLIPUT: Some renaming, implement a couple of functions
0be54f0b1b LILLIPUT: Maybe fix a problem in sub12F37
5caad723c5 LILLIPUT: Implement 4 more opcodes
576f0217e0 LILLIPUT: Implements Load Map opcode
2947d7e469 LILLIPUT: More opcodes
413f42c283 LILLIPUT: Fix a bug in OC_compareCoords_1, implement 2 more opcodes
2c17500d01 LILLIPUT: Implement two opcodes
1f7cf60ddb LILLIPUT: Fixsome problems reported by clone2727
32ed5e62af LILLIPUT: Implement another opcode and associated function
b2ac6e0631 LILLIPUT: Replace MemoryReadStream by a custom read/write stream
dc4831d00f LILLIPUT: Fix stream write
348d46d02d LILLIPUT: Implement 3 opcodes
977c07ba70 LILLIPUT: Implements 2 opcodes
794869656b LILLIPUT: Fix a bug in OC_for
c4186ba41b LILLIPUT: Implements one more opcode
d19e92fbb0 LILLIPUT: Several opcodes & renaming
566954c8e6 LILLIPUT: More opcodes
b870535745 LILLIPUT: Remove double implementation of getMapPtr
ba0fcb521f LILLIPUT: Some renaming, implement 7 opcodes, fix one
b9a2c968db LILLIPUT: Implement 4 opcodes
d65cd866e7 LILLIPUT: Implement 2 opcodes, fix a duplicate variable detected by SylvainTV
2462b8d340 LILLIPUT: Fix bug
6dfec1f58e LILLIPUT: Last opcodes1 + first step of script decompiler
dd81316528 LILLIPUT: Implement some functions related to string display
974c223a43 LILLIPUT: Split palette functions, implement some core functions
6eccd8e6f3 LILLIPUT: Add a couple of missing debugC
8023057999 LILLIPUT: Implement some more opcodes
70afb0b9c5 LILLIPUT: More opcodes2
7320966cd7 LILLIPUT: fix (?) a couple of things in 16626, implement several core functions
f06dbf19af LILLIPUT: Fix a bug on 16675
8325be0f82 LILLIPUT: Small change
ab3b7972e0 LILLIPUT: Add sprite mirroring to fix display of characters looking left
c77a3e2e51 LILLIPUT: Some renaming
cf4d832214 LILLIPUT: Finish opcode2 list for decompiler
ca5b883ce7 LILLIPUT: Add one core function, some renaming
d7d3b50d40 LILLIPUT: Opcode2 decompiler
19f8bd899a LILLIPUT: Some renaming
eabe891bf6 LILLIPUT: Improved getValue2 decompilation
17998c7d45 LILLIPUT: Forgot to disable disasm
8019c8b26c LILLIPUT: rename one variable
3f10768dc1 LILLIPUT: Fix draw interface icons
2861a3f5ec LILLIPUT: Fix some bugs of sub16626
18029a5597 LILLIPUT: Implement case 14 in sub16626, little clean up in sub1823e
f17868ebd9 LILLIPUT: Implement 4 core functions
61e5d39546 LILLIPUT: 2 new subs
864e66cdd2 LILLIPUT: Remove duplicated function
d8f62c9780 LILLIPUT: Add a core function, make uniform the fonctions called by sub16626
ca2534dd6b LILLIPUT: Implement two opcodes and 3 core functions
9fc6e8f370 LILLIPUT: Fix some uninitialized variables reported by Valgrind (Thanks Hkz for reporting)
8d25611dcb LILLIPUT: Remove duplicated variable, introduce getCharacterVariablesPtr() to handle negative indexes used by menus
0eea1447d3 LILLIPUT: fix a bug in OC_sub17D04
e2de970a1a LILLIPUT: Some renaming. Start using Common::Point
8aeedd1e50 LILLIPUT: Rename getValue2, keep on switching to Common::Point, remove code from OC_sub18260 (incomplete and buggy)
98ac7cf0eb LILLIPUT: More renaming, fix bug in getMapPtr and sub168DA
7153a4b38a LILLIPUT: More renaming, fix a bug in sub16799, move several unsigned to signed
6b70262563 LILLIPUT: Some more renaming
23dc740de4 LILLIPUT: More renaming, fix bug in reverseFindHotspot
355f598560 LILLIPUT: Rename debug channel in order to doublecheck all function, some more renaming and bugfixing, fix some GCC warn
8871c440e5 LILLIPUT: Add a size parameter to loadVGA to fix Valgrind warnings and stick to the original
2575378f09 LILLIPUT: Fix another Valgrind warning
6b9777cc9f LILLIPUT: Turn _array12311 into a Common::Point, fix initialization of _array16C58,
59f6e304a2 LILLIPUT: More renaming
e1f6fe2226 LILLIPUT: Some more renaming
aedc95231d LILLIPUT: More renaming
872c9ea2fc LILLIPUT: double check some more function, renaming
48d59dfd2e LILLIPUT: Rewrite sub1818B
f4732601ec LILLIPUT: Remove useless buffers, renaming
d32887f367 LILLIPUT: More renaming
056541c5d9 LILLIPUT: Fix bug in displayFunction15
72b99e99e4 LILLIPUT: Some more renaming
4fe3a02154 LILLIPUT: More renaming
4c54e60be4 LILLIPUT: Fix bug in OC_sub17640
91cbbe27a7 LILLIPUT: Debug List texts + some renaming
95fa165645 LILLIPUT: Fix some code formatting
91651f4090 LILLIPUT: Intro is finally starting correctly
1f249aa23d LILLIPUT: More renaming & 2 3 missing opcodes
2d88b963a9 LILLIPUT: Fix a value in character move, some comments
127f73a1ec LILLIPUT: Some renaming, implement 3 missing opcodes
9752da62df LILLIPUT: Some renaming and refactoring
c914fdb0b7 LILLIPUT: Janitorial: fix some code formatting
6dd3a1009d LILLIPUT: Fix pathfinding & some renaming
29b476fc56 LILLIPUT: Some refactoring, fix a bug in fixx16x16Rect
1c0efa5581 LILLIPUT: Some more renaming
3a102e6f24 LILLIPUT: Some more renaming, fix issue in OC_sub17640, implement OC_sub18690
9ecbc0e327 LILLIPUT: Fix bug in OC_compWord10804
e6983de0d0 LILLIPUT: Renaming, fix interface hotspots: it's now possible to skip the intro
cdfac3cadc LILLIPUT: Some more code validation and renaming
dc45e2b791 LILLIPUT: Some more renaming
03e0d5927f LILLIPUT: More renaming, fix two bugs
b3819ede5e LILLIPUT: More verifications and renaming
742425f9a9 LILLIPUT: Some more renaming, fix a couple of glitches in sub16DD5
2ea4cc178b LILLIPUT: Verifications and renaming
aa8ecc2493 LILLIPUT: Renaming, fix bug in startSpeech
0270cd311a LILLIPUT: Fix a bug in decodePackedText, some renaming
e1bc0469de LILLIPUT: Janitorial: fix code formatting
aac437d3cb LILLIPUT: Fix display/menu bug, Some renaming
c8589eb488 LILLIPUT: Fix display of horizontal bars in character stats menu, some renaming
8c7395b947 LILLIPUT: Some renaming
f0a4290385 LILLIPUT: Implement unselectInterfaceButton, some renaming
f602ca7408 LILLIPUT: Fix mouse icon clipping, rework map Index formula, some renaming
3103cf448a LILLIPUT: Fix a bug in sub171AF
e1c783d6a2 LILLIPUT: Some more renaming, fix a bug in intro
8500175811 LILLIPUT: Some more renaming
5498523326 LILLIPUT: Fix bug in OC_turnCharacterTowardsAnother()
4d36343b0c LILLIPUT: Fix bug in viewportScrollTo(), some renaming
e8525da958 LILLIPUT: Fix a bug in sub16626. The people are now dancing in the intro
a468ebc32e LILLIPUT: Change type of _rulesBuffer2_5 and _rulesBuffer2_6
82fb9e3c23 LILLIPUT: Fix bug in sub16A76. This fixes the dance a bit more.
23f2fd8f3e LILLIPUT: Fix a bug in pathfinding, some renaming
c5e4fe1e22 LILLIPUT: Fix mouse display in title screens
2e9867086c LILLIPUT: Fix one more double variable, some renaming
21d38e3b4c LILLIPUT: bugfix: Intro is now completable
bcfbf5df47 LILLIPUT: Fix bug in OC_sub17A07 and renderCharacters, implement OC_startSpeechWithoutSpeeker
3ea95583a2 LILLIPUT: Fix bug in sub167EF
8ce9bac02a LILLIPUT: Set _shouldQuit in OC_saveAndQUIT and OC_deleteSavegameAndQuit
f625b60117 LILLIPUT: Start implementing keyboard handling
147a450834 LILLIPUT: Fix bug in OC_loadFile_AERIAL_GFX, implement OC_waitForEvent
747734a697 LILLIPUT: Fix regression in checkMapClosing, handle properly other languages
5f3a303951 LILLIPUT: Modify mouse handling to stick to original behavior
de94c90720 LILLIPUT: Improve keyboard handling. F keys are now working in the menu
4dda4abbea LILLIPUT: rename OC_checkFunctionKeyPressed
5964316074 LILLIPUT: Finish the implementation of sub13156, fix keyboard mapping
a56a10d6ea LILLIPUT: Silent warning in language check
fe906b9dad LILLIPUT: Add a couple of hacks to avoid working on disabled character
686b59e53e LILLIPUT: Implement OC_sub18260
7084803a7a LILLIPUT: Implement OC_sub17E22_speech1IfSoundOff, silent warnings in OC_loadFile_AERIAL_GFX
e70d3c4979 LILLIPUT: Fix display of variable speeches
479eaaaa9e LILLIPUT: Fix walking on click
f03571ccb1 LILLIPUT: Fix bad opcode definition for display aerial map
653c27f930 LILLIPUT: Cleanup of previous fix, add TODO comment
e6dce6ed8a LILLIPUT: Fix name of OC_changeCurrentCharacterSprite in script decompiler
7e55ed492c LILLIPUT: Some renaming
802f132f02 LILLIPUT: One more renaming
a1c5e27b77 LILLIPUT: Rename some functions, fix a bug in OC_getComputedVariantSpeech()
7fa6dea355 LILLIPUT: Improve hack in sub16EBC() to avoid checking inactive characters
10edaf6bc4 LILLIPUT: Some renaming, start fixing the map display
98032809dd LILLIPUT: Some renaming
f68712fbad LILLIPUT: Partially fix map closing
1d897d7be2 LILLIPUT: Fix a couple of errors related to the use of 0xFF instead of -1
d011a68d4f LILLIPUT: Start reworking _word16EFE
22b3a24e5f LILLIPUT: Renaming, fix a bug in OC_checkLastInterfaceHotspotIndexMenu2
2832980e92 LILLIPUT: Some more renaming, remove double variable
b2d49cef83 LILLIPUT: More renaming
f0abb4f656 LILLIPUT: Some renaming
9f93ceb8aa LILLIPUT: Fix bug in interface button re-activation
4efebbbeee LILLIPUT: Some more renaming
ed9daf2ed6 LILLIPUT: Rework _rectXMinMax and _rectYMinMax
7554c07be1 LILLIPUT: Some more renaming
b387257138 LILLIPUT: Some renaming, fix regression in intro introduced in the two previous commits
e059e81bab LILLIPUT: Some renaming, fix a warning
cf29d9ceec LILLIPUT: Removes redundant mouse cursor redraws
a5b4be6327 LILLIPUT: Substitues custom cursor handling with CursorMan
d9aa76796d LILLIPUT: Adds delay during title screens
399d1e26cb LILLIPUT: Fixes rendering by blitting mainSurface to screen
de7c3d345e LILLIPUT: Marks game as unstable
2aa505fcc8 LILLIPUT: Fix bug in OC_scrollViewPort
c8495aa457 LILLIPUT: Fix a couple of remaining 'Robin' engine strings
d6092b4cbf LILLIPUT: Fix missing break in getArgumentString
616a8291a4 LILLIPUT: Some renaming
e92e7d5bf6 LILLIPUT: Fixes formatting
1552128291 LILLIPUT: Changes KValueType to kValueType
7abc364a4a LILLIPUT: Fixes typo
40dc39d01d LILLIPUT: Reformats string
132fa2fdab LILLIPUT: Updates savefile pattern for numeric wildcard
157e69b8b1 LILLIPUT: Sorts SaveStateList instead of file names
bda21673e8 LILLIPUT: More renaming
491dd07e68 LILLUPUT: Add missing kActionType values
b17dfaad10 LILLIPUT: More renaming
37067dd6e9 LILLIPUT: Silent some CppCheck warnings
81a16b0c8e LILLIPUT: Some more renaming
2ea8d71a5a LILLIPUT: More renaming
fedbb3d7fe LILLIPUT: Rename some more opcodes
5bc90c0a4b LILLIPUT: Some more renaming
96f35b1740 LILLIPUT: Some more renaming, use CLIP in OC_scrollAwayFromCharacter
74ce6af22e LILLIPUT: more renaming and refactoring


Commit: 5757ffaff0f94e5dd18c3f1880cffaaa96c349f9
    https://github.com/scummvm/scummvm/commit/5757ffaff0f94e5dd18c3f1880cffaaa96c349f9
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add skeletton

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


diff --git a/engines/lilliput/configure.engine b/engines/lilliput/configure.engine
new file mode 100644
index 0000000..f8cb842
--- /dev/null
+++ b/engines/lilliput/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 lilliput "Lilliput engine" no
diff --git a/engines/lilliput/console.cpp b/engines/lilliput/console.cpp
new file mode 100644
index 0000000..e7746a0
--- /dev/null
+++ b/engines/lilliput/console.cpp
@@ -0,0 +1,34 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 "lilliput/console.h"
+#include "lilliput/lilliput.h"
+
+namespace Lilliput {
+
+LilliputConsole::LilliputConsole(LilliputEngine *vm) : GUI::Debugger(), _vm(vm) {
+}
+
+LilliputConsole::~LilliputConsole() {
+}
+
+} // End of namespace Lilliput
diff --git a/engines/lilliput/console.h b/engines/lilliput/console.h
new file mode 100644
index 0000000..cd7edb3
--- /dev/null
+++ b/engines/lilliput/console.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 LILLIPUT_CONSOLE_H
+#define LILLIPUT_CONSOLE_H
+
+#include "gui/debugger.h"
+
+namespace Lilliput {
+
+class LilliputEngine;
+
+class LilliputConsole : public GUI::Debugger {
+public:
+	LilliputConsole(LilliputEngine *vm);
+	virtual ~LilliputConsole(void);
+
+private:
+	LilliputEngine *_vm;
+	bool Cmd_listScreens(int argc, const char **argv);
+	bool Cmd_listObjects(int argc, const char **argv);
+	bool Cmd_getObject(int argc, const char **argv);
+	bool Cmd_getAllObjects(int argc, const char **argv);
+	bool Cmd_gotoScreen(int argc, const char **argv);
+	bool Cmd_boundaries(int argc, const char **argv);
+};
+
+} // End of namespace Lilliput
+
+#endif
diff --git a/engines/lilliput/detection.cpp b/engines/lilliput/detection.cpp
new file mode 100644
index 0000000..1925c71
--- /dev/null
+++ b/engines/lilliput/detection.cpp
@@ -0,0 +1,237 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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/advancedDetector.h"
+#include "common/system.h"
+#include "common/savefile.h"
+#include "common/textconsole.h"
+#include "graphics/thumbnail.h"
+#include "graphics/surface.h"
+
+#include "lilliput/lilliput.h"
+
+namespace Lilliput {
+
+struct LilliputGameDescription {
+	ADGameDescription desc;
+	GameType gameType;
+};
+
+uint32 LilliputEngine::getFeatures() const {
+	return _gameDescription->desc.flags;
+}
+
+const char *LilliputEngine::getGameId() const {
+	return _gameDescription->desc.gameId;
+}
+
+
+static const PlainGameDescriptor lilliputGames[] = {
+	// Games
+	{"robin", "Adventures of Robin Hood"},
+	{"rome", "Rome: Pathway to Power"},
+	{0, 0}
+};
+
+static const LilliputGameDescription gameDescriptions[] = {
+
+	// Robin Hood English
+	{
+		{
+			"robin", 0,
+			{
+				{"erules.prg", 0, "92aaf84693a8948497ad57864fa31c2a", 71010},
+				{"isomap.dta", 0, "bad97eae03a4db3e99565e39b0b3c06a", 16384},
+				AD_LISTEND
+			},
+			Common::EN_ANY,
+			Common::kPlatformDOS,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		kGameTypeRobin
+	},
+
+	{AD_TABLE_END_MARKER, kGameTypeNone}
+};
+
+class LilliputMetaEngine : public AdvancedMetaEngine {
+public:
+	LilliputMetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(LilliputGameDescription), lilliputGames) {
+	}
+
+	const char *getName() const {
+		return "Robin Hood";
+	}
+
+	const char *getOriginalCopyright() const {
+		return "Robin Hood Engine copyright S.L.Grand, Brainware, 1991-1992";
+	}
+
+	bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const;
+	bool hasFeature(MetaEngineFeature f) const;
+
+	int getMaximumSaveSlot() const;
+	SaveStateList listSaves(const char *target) const;
+	SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
+	void removeSaveState(const char *target, int slot) const;
+};
+
+bool LilliputMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const {
+	if (gd) {
+		*engine = new LilliputEngine(syst, (const LilliputGameDescription *)gd);
+		((LilliputEngine *)*engine)->initGame((const LilliputGameDescription *)gd);
+	}
+	return gd != 0;
+}
+
+bool LilliputMetaEngine::hasFeature(MetaEngineFeature f) const {
+	return
+		(f == kSupportsListSaves) ||
+		(f == kSupportsLoadingDuringStartup) ||
+		(f == kSupportsDeleteSave) ||
+		(f == kSavesSupportMetaInfo) ||
+		(f == kSavesSupportThumbnail) ||
+		(f == kSavesSupportCreationDate);
+}
+
+int LilliputMetaEngine::getMaximumSaveSlot() const { return 99; }
+
+SaveStateList LilliputMetaEngine::listSaves(const char *target) const {
+	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+	Common::StringArray filenames;
+	Common::String pattern = target;
+	pattern += "-??.SAV";
+
+	filenames = saveFileMan->listSavefiles(pattern);
+	sort(filenames.begin(), filenames.end());   // Sort (hopefully ensuring we are sorted numerically..)
+
+	SaveStateList saveList;
+	char slot[3];
+	int slotNum = 0;
+	for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) {
+		slot[0] = filename->c_str()[filename->size() - 6];
+		slot[1] = filename->c_str()[filename->size() - 5];
+		slot[2] = '\0';
+		// Obtain the last 2 digits of the filename (without extension), since they correspond to the save slot
+		slotNum = atoi(slot);
+		if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) {
+			Common::InSaveFile *file = saveFileMan->openForLoading(*filename);
+			if (file) {
+				int saveVersion = file->readByte();
+
+				if (saveVersion != kSavegameVersion) {
+					warning("Savegame of incompatible version");
+					delete file;
+					continue;
+				}
+
+				// read name
+				uint16 nameSize = file->readUint16BE();
+				if (nameSize >= 255) {
+					delete file;
+					continue;
+				}
+				char name[256];
+				file->read(name, nameSize);
+				name[nameSize] = 0;
+
+				saveList.push_back(SaveStateDescriptor(slotNum, name));
+				delete file;
+			}
+		}
+	}
+
+	return saveList;
+}
+
+SaveStateDescriptor LilliputMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
+	Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
+	Common::InSaveFile *file = g_system->getSavefileManager()->openForLoading(fileName);
+
+	if (file) {
+		int saveVersion = file->readByte();
+
+		if (saveVersion != kSavegameVersion) {
+			warning("Savegame of incompatible version");
+			delete file;
+			return SaveStateDescriptor();
+		}
+
+		uint32 saveNameLength = file->readUint16BE();
+		char saveName[256];
+		file->read(saveName, saveNameLength);
+		saveName[saveNameLength] = 0;
+
+		SaveStateDescriptor desc(slot, saveName);
+
+		Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file);
+		desc.setThumbnail(thumbnail);
+
+		desc.setDeletableFlag(true);
+		desc.setWriteProtectedFlag(false);
+
+		uint32 saveDate = file->readUint32BE();
+		uint16 saveTime = file->readUint16BE();
+
+		int day = (saveDate >> 24) & 0xFF;
+		int month = (saveDate >> 16) & 0xFF;
+		int year = saveDate & 0xFFFF;
+
+		desc.setSaveDate(year, month, day);
+
+		int hour = (saveTime >> 8) & 0xFF;
+		int minutes = saveTime & 0xFF;
+
+		desc.setSaveTime(hour, minutes);
+
+		// Slot 0 is used for the 'restart game' save in all Robin games, thus
+		// we prevent it from being deleted.
+		desc.setDeletableFlag(slot != 0);
+		desc.setWriteProtectedFlag(slot == 0);
+
+		delete file;
+		return desc;
+	}
+	return SaveStateDescriptor();
+}
+
+void LilliputMetaEngine::removeSaveState(const char *target, int slot) const {
+	Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
+	g_system->getSavefileManager()->removeSavefile(fileName);
+}
+} // End of namespace Lilliput
+
+#if PLUGIN_ENABLED_DYNAMIC(LILLIPUT)
+REGISTER_PLUGIN_DYNAMIC(LILLIPUT, PLUGIN_TYPE_ENGINE, Lilliput::LilliputMetaEngine);
+#else
+REGISTER_PLUGIN_STATIC(LILLIPUT, PLUGIN_TYPE_ENGINE, Lilliput::LilliputMetaEngine);
+#endif
+
+namespace Lilliput {
+
+void LilliputEngine::initGame(const LilliputGameDescription *gd) {
+	_gameType = gd->gameType;
+	_platform = gd->desc.platform;
+}
+
+} // End of namespace Lilliput
diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
new file mode 100644
index 0000000..befec74
--- /dev/null
+++ b/engines/lilliput/lilliput.cpp
@@ -0,0 +1,113 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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/random.h"
+#include "common/error.h"
+#include "common/events.h"
+#include "common/debug-channels.h"
+#include "common/config-manager.h"
+#include "common/textconsole.h"
+
+#include "lilliput/lilliput.h"
+
+#include "engines/util.h"
+
+namespace Lilliput {
+
+LilliputEngine *LilliputEngine::s_Engine = 0;
+
+LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) : Engine(syst), _gameDescription(gd)
+{
+	_system = syst;
+	DebugMan.addDebugChannel(kDebugSchedule, "Schedule", "Script Schedule debug level");
+	DebugMan.addDebugChannel(kDebugEngine, "Engine", "Engine debug level");
+	DebugMan.addDebugChannel(kDebugDisplay, "Display", "Display debug level");
+	DebugMan.addDebugChannel(kDebugMouse, "Mouse", "Mouse debug level");
+	DebugMan.addDebugChannel(kDebugParser, "Parser", "Parser debug level");
+	DebugMan.addDebugChannel(kDebugFile, "File", "File IO debug level");
+	DebugMan.addDebugChannel(kDebugRoute, "Route", "Route debug level");
+	DebugMan.addDebugChannel(kDebugInventory, "Inventory", "Inventory debug level");
+	DebugMan.addDebugChannel(kDebugObject, "Object", "Object debug level");
+	DebugMan.addDebugChannel(kDebugMusic, "Music", "Music debug level");
+
+	_console = new LilliputConsole(this);
+	_rnd = 0;
+}
+
+LilliputEngine::~LilliputEngine() {
+
+	DebugMan.clearAllDebugChannels();
+	delete _console;
+	delete _rnd;
+}
+
+GUI::Debugger *LilliputEngine::getDebugger() {
+	return _console;
+}
+
+bool LilliputEngine::hasFeature(EngineFeature f) const {
+	return (f == kSupportsRTL) || (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime);
+}
+
+const char *LilliputEngine::getCopyrightString() const {
+	return "Copyright 1989-1997 David P Gray, All Rights Reserved.";
+}
+
+GameType LilliputEngine::getGameType() const {
+	return _gameType;
+}
+
+Common::Platform LilliputEngine::getPlatform() const {
+	return _platform;
+}
+
+Common::Error LilliputEngine::run() {
+	s_Engine = this;
+	initGraphics(320, 200);
+
+	// Setup mixer
+	syncSoundSettings();
+
+	return Common::kNoError;
+}
+
+void LilliputEngine::initialize() {
+	debugC(1, kDebugEngine, "initialize");
+
+	_rnd = new Common::RandomSource("robin");
+	_rnd->setSeed(42);                              // Kick random number generator
+}
+
+void LilliputEngine::syncSoundSettings() {
+	Engine::syncSoundSettings();
+
+//	_sound->syncVolume();
+}
+
+Common::String LilliputEngine::getSavegameFilename(int slot) {
+	return _targetName + Common::String::format("-%02d.SAV", slot);
+}
+
+
+
+} // End of namespace Lilliput
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
new file mode 100644
index 0000000..190bbfc
--- /dev/null
+++ b/engines/lilliput/lilliput.h
@@ -0,0 +1,111 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 LILLIPUT_LILLIPUT_H
+#define LILLIPUT_LILLIPUT_H
+
+#include "engines/engine.h"
+#include "common/file.h"
+#include "lilliput/console.h"
+
+namespace Common {
+class RandomSource;
+}
+
+/**
+ * This is the namespace of the Robin engine.
+ *
+ * Status of this engine: ???
+ *
+ * Games using this engine:
+ * - Adventures of Robin Hood
+ * - Rome: Pathway to Rome
+ */
+namespace Lilliput {
+
+static const int kSavegameVersion = 1;
+
+enum GameType {
+	kGameTypeNone  = 0,
+	kGameTypeRobin,
+	kGameTypeRome
+};
+
+enum LilliputDebugChannels {
+	kDebugSchedule  = 1 <<  0,
+	kDebugEngine    = 1 <<  1,
+	kDebugDisplay   = 1 <<  2,
+	kDebugMouse     = 1 <<  3,
+	kDebugParser    = 1 <<  4,
+	kDebugFile      = 1 <<  5,
+	kDebugRoute     = 1 <<  6,
+	kDebugInventory = 1 <<  7,
+	kDebugObject    = 1 <<  8,
+	kDebugMusic     = 1 <<  9
+};
+
+struct LilliputGameDescription;
+
+class LilliputEngine : public Engine {
+public:
+	LilliputEngine(OSystem *syst, const LilliputGameDescription *gd);
+	~LilliputEngine();
+
+	OSystem *_system;
+
+	GUI::Debugger *getDebugger();
+
+	Common::RandomSource *_rnd;
+
+	const LilliputGameDescription *_gameDescription;
+	uint32 getFeatures() const;
+	const char *getGameId() const;
+
+	void initGame(const LilliputGameDescription *gd);
+
+	GameType getGameType() const;
+	Common::Platform getPlatform() const;
+
+	bool hasFeature(EngineFeature f) const;
+	const char *getCopyrightString() const;
+
+	Common::String getSavegameFilename(int slot);
+	void syncSoundSettings();
+
+protected:
+
+	// Engine APIs
+	Common::Error run();
+
+private:
+	static LilliputEngine *s_Engine;
+
+	LilliputConsole *_console;
+	GameType _gameType;
+	Common::Platform _platform;
+
+	void initialize();
+};
+
+} // End of namespace Lilliput
+
+#endif
diff --git a/engines/lilliput/module.mk b/engines/lilliput/module.mk
new file mode 100644
index 0000000..0ec4403
--- /dev/null
+++ b/engines/lilliput/module.mk
@@ -0,0 +1,17 @@
+MODULE := engines/lilliput
+
+MODULE_OBJS = \
+	console.o \
+	lilliput.o \
+	detection.o
+
+MODULE_DIRS += \
+	engines/lilliput
+
+# This module can be built as a plugin
+ifeq ($(ENABLE_LILLIPUT), DYNAMIC_PLUGIN)
+PLUGIN := 1
+endif
+
+# Include common rules
+include $(srcdir)/rules.mk


Commit: 561b20edde3d94e63acb0b0292113a3ad434b264
    https://github.com/scummvm/scummvm/commit/561b20edde3d94e63acb0b0292113a3ad434b264
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add resource loading

Changed paths:
    engines/lilliput/lilliput.h


diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 190bbfc..68dffd3 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -76,11 +76,71 @@ public:
 
 	Common::RandomSource *_rnd;
 
+	byte _buffer1[45056];
+	byte _buffer2[45056];
+	byte _buffer3[45056];
+	byte *_bufferIsoMap;
+	byte _bufferCubegfx[61440];
+	byte *_bufferMen;
+	byte *_bufferMen2;
+	byte *_bufferIsoChars;
+	byte *_bufferIdeogram;
+	byte _buffer10[4032];
+	byte _palette[768];
+	
+	int _word10800_ERULES;
+	int _word10807_ERULES;
+	byte *_rulesChunk1;
+	int _rulesBuffer2_1[40];
+	int _rulesBuffer2_2[40];
+	byte _rulesBuffer2_3[40];
+	int _rulesBuffer2_4[40];
+	byte _rulesBuffer2_5[40];
+	byte _rulesBuffer2_6[40];
+	byte _rulesBuffer2_7[40];
+	byte _rulesBuffer2_8[40];
+	byte _rulesBuffer2_9[40];
+	byte _rulesBuffer2_10[40];
+	byte _rulesBuffer2_11[40];
+	byte _rulesBuffer2_12[40];
+	byte _rulesBuffer2_13[40];
+	byte _rulesBuffer2_14[40];
+	byte _rulesBuffer2_15[40 * 32];
+	byte _rulesBuffer2_16[40 * 32];
+	int *_rulesChunk3;
+	int _rulesChunk3_size;
+	byte *_rulesChunk4;
+	int *_rulesScript;
+	int _rulesScript_size;
+	int *_rulesChunk6;
+	int _rulesChunk6_size;
+	int *_rulesChunk7;
+	int _rulesChunk7_size;
+	byte *_rulesChunk8;
+	byte _rulesChunk9[60];
+	int _rulesChunk10_size;
+	int *_rulesChunk10;
+	byte *_rulesChunk11;
+	int _rulesChunk12_size;
+	int _rulesBuffer12_1[40];
+	int _rulesBuffer12_2[40];
+	int _rulesBuffer12_3[40];
+	int _rulesBuffer12_4[40];
+	int _word12F68_ERULES;
+	byte _rulesBuffer13_1[20];
+	int _rulesBuffer13_2[20];
+	int _rulesBuffer13_3[20];
+	byte _rulesBuffer13_4[20];
+
+
 	const LilliputGameDescription *_gameDescription;
 	uint32 getFeatures() const;
 	const char *getGameId() const;
 
 	void initGame(const LilliputGameDescription *gd);
+	byte *loadVGA(Common::String filename, bool loadPal);
+	byte *loadRaw(Common::String filename);
+	void loadRules();
 
 	GameType getGameType() const;
 	Common::Platform getPlatform() const;


Commit: 38b7961bcb2ba472d7d119816dcb7cae29617e07
    https://github.com/scummvm/scummvm/commit/38b7961bcb2ba472d7d119816dcb7cae29617e07
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add detection for French, German and Italian versions

Changed paths:
    engines/lilliput/detection.cpp


diff --git a/engines/lilliput/detection.cpp b/engines/lilliput/detection.cpp
index 1925c71..bd31de1 100644
--- a/engines/lilliput/detection.cpp
+++ b/engines/lilliput/detection.cpp
@@ -70,7 +70,54 @@ static const LilliputGameDescription gameDescriptions[] = {
 		},
 		kGameTypeRobin
 	},
-
+	// Robin Hood French
+	{
+		{
+			"robin", 0,
+			{
+				{"frules.prg", 0, "cf076c5ebfe8b3571e74a6a46d79426f", 76660},
+				{"isomap.dta", 0, "bad97eae03a4db3e99565e39b0b3c06a", 16384},
+				AD_LISTEND
+			},
+			Common::FR_FRA,
+			Common::kPlatformDOS,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		kGameTypeRobin
+	},
+	// Robin Hood German
+	{
+		{
+			"robin", 0,
+			{
+				{"grules.prg", 0, "b53b7353dc1e841b206a64851e7bc58c", 78050},
+				{"isomap.dta", 0, "bad97eae03a4db3e99565e39b0b3c06a", 16384},
+				AD_LISTEND
+			},
+			Common::DE_DEU,
+			Common::kPlatformDOS,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		kGameTypeRobin
+	},
+	// Robin Hood Italian
+	{
+		{
+			"robin", 0,
+			{
+				{"irules.prg", 0, "4d69ed3cda1e1d73585905517ea705d1", 75654},
+				{"isomap.dta", 0, "bad97eae03a4db3e99565e39b0b3c06a", 16384},
+				AD_LISTEND
+			},
+			Common::IT_ITA,
+			Common::kPlatformDOS,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		kGameTypeRobin
+	},
 	{AD_TABLE_END_MARKER, kGameTypeNone}
 };
 


Commit: 6ab621dbd7fb573a7f5b7a0ee6e50ec9f72508f2
    https://github.com/scummvm/scummvm/commit/6ab621dbd7fb573a7f5b7a0ee6e50ec9f72508f2
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add a script handler skeletton. All opcodes are stubbed

Changed paths:
  A engines/lilliput/script.cpp
  A engines/lilliput/script.h
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/module.mk


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index befec74..285f03c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -27,10 +27,11 @@
 #include "common/debug-channels.h"
 #include "common/config-manager.h"
 #include "common/textconsole.h"
+#include "common/memstream.h"
 
 #include "lilliput/lilliput.h"
-
 #include "engines/util.h"
+#include "lilliput/script.h"
 
 namespace Lilliput {
 
@@ -52,6 +53,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 
 	_console = new LilliputConsole(this);
 	_rnd = 0;
+	_scriptHandler = new LilliputScript(this);
+
+	_vm_byte1714E = 0;
 }
 
 LilliputEngine::~LilliputEngine() {
@@ -70,7 +74,7 @@ bool LilliputEngine::hasFeature(EngineFeature f) const {
 }
 
 const char *LilliputEngine::getCopyrightString() const {
-	return "Copyright 1989-1997 David P Gray, All Rights Reserved.";
+	return "copyright S.L.Grand, Brainware, 1991";
 }
 
 GameType LilliputEngine::getGameType() const {
@@ -81,6 +85,232 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
+byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
+	Common::File f;
+
+	if (!f.open(filename))
+		error("Missing game file %s", filename.c_str());
+
+	int remainingSize = f.size();
+	if (loadPal) {
+		for (int i = 0; i < 768; ++i)
+			_palette[i] = f.readByte();
+		remainingSize -= 768;
+	}
+
+	uint8 curByte;
+	byte decodeBuffer[100000];
+	int size = 0;
+
+	for (;remainingSize > 0;) {
+		curByte = f.readByte();
+		--remainingSize;
+
+		if (curByte == 0xFF)
+			break;
+
+		if (curByte & 0x80) {
+			// Compressed
+			int compSize = (curByte & 0x7F);
+			curByte = f.readByte();
+			--remainingSize;
+
+			for (int i = 0; i < compSize; ++i) {
+				decodeBuffer[size] = curByte;
+				++size;
+			}
+		} else {
+			// Not compressed
+			int rawSize = (curByte & 0xF);
+			for (int i = 0; i < rawSize; ++i) {
+				decodeBuffer[size] = f.readByte();
+				--remainingSize;
+				++size;
+			}
+		}
+	}
+
+	f.close();
+
+	byte *res = (byte *)malloc(sizeof(byte) * size);
+	memcpy(res, decodeBuffer, size);
+	return res;
+}
+
+byte *LilliputEngine::loadRaw(Common::String filename) {
+	Common::File f;
+
+	if (!f.open(filename))
+		error("Missing game file %s", filename.c_str());
+
+	int size = f.size();
+	byte *res = (byte *)malloc(sizeof(byte) * size);
+	for (int i = 0; i < size; ++i)
+		res[i] = f.readByte();
+
+	f.close();
+	return res;
+}
+
+void LilliputEngine::loadRules() {
+	static const byte _rulesXlatArray[26] = {30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44};
+	Common::File f;
+	uint16 curWord;
+
+	if (!f.open("ERULES.PRG"))
+		error("Missing game file ERULES.PRG");
+
+	_word10800_ERULES = f.readUint16LE();
+
+	// Chunk 1
+	int size = f.readUint16LE();
+	_rulesChunk1 = (byte *)malloc(sizeof(byte) * size);
+	for (int i = 0; i < size; ++i)
+		_rulesChunk1[i] = f.readByte();
+
+	// Chunk 2
+	_word10807_ERULES = f.readSint16LE();
+	assert(_word10807_ERULES <= 40);
+
+	for (int i = _word10807_ERULES, j = 0; i != 0; i--, j++) {
+		curWord = f.readUint16LE();
+		if (curWord != 0xFFFF)
+			curWord = (curWord << 3) + 4;
+		_rulesBuffer2_1[j] = curWord;
+
+		curWord = f.readUint16LE();
+		if (curWord != 0xFFFF)
+			curWord = (curWord << 3) + 4;
+		_rulesBuffer2_2[j] = curWord;
+
+		_rulesBuffer2_3[j] = (f.readUint16LE() & 0xFF);
+		_rulesBuffer2_4[j] = f.readUint16LE();
+		_rulesBuffer2_5[j] = f.readByte();
+		_rulesBuffer2_6[j] = f.readByte();
+		_rulesBuffer2_7[j] = f.readByte();
+		_rulesBuffer2_8[j] = f.readByte();
+		_rulesBuffer2_9[j] = f.readByte();
+		_rulesBuffer2_10[j] = f.readByte();
+		_rulesBuffer2_11[j] = f.readByte();
+		_rulesBuffer2_12[j] = f.readByte();
+		_rulesBuffer2_13[j] = f.readByte();
+		_rulesBuffer2_14[j] = f.readByte();
+
+		for (int k = 0; k < 32; k++)
+			_rulesBuffer2_15[(j * 32) + k] = f.readByte();
+
+		for (int k = 0; k < 32; k++)
+			_rulesBuffer2_16[(j * 32) + k] = f.readByte();
+	}
+
+	// Chunk 3 & 4
+	warning("Chunk 3 & 4 Pos: %d", f.pos());
+	_rulesChunk3_size = f.readSint16LE();
+	curWord = f.readSint16LE();
+
+	warning("Pos %d", f.pos());
+	_rulesChunk3 = (int *)malloc(sizeof(int) * _rulesChunk3_size);
+	for (int i = 0; i < _rulesChunk3_size; ++i)
+		_rulesChunk3[i] = f.readUint16LE();
+
+	warning("Pos %d", f.pos());
+	_rulesChunk4 = (byte *)malloc(sizeof(byte) * curWord);
+	for (int i = 0; i < curWord; ++i)
+		_rulesChunk4[i] = f.readByte();
+
+	// Chunk 5: Scripts
+	warning("Chunk 5 Pos: %d", f.pos());
+	// Use byte instead of int, therefore multiply by two the size.
+	// This is for changing that into a memory read stream
+	_rulesScript_size = f.readUint16LE() * 2;
+	_rulesScript = (byte *)malloc(sizeof(byte) * _rulesScript_size);
+	for (int i = 0; i < _rulesScript_size; ++i)
+		_rulesScript[i] = f.readByte();
+
+	// Chunk 6
+	_rulesChunk6_size = f.readUint16LE();
+	_rulesChunk6 = (int *)malloc(sizeof(int) * _rulesChunk6_size);
+	for (int i = 0; i < _rulesChunk6_size; ++i)
+		_rulesChunk6[i] = f.readUint16LE();
+
+	// Chunk 7 & 8
+	_rulesChunk7_size = f.readUint16LE();
+	_rulesChunk7 = (int *)malloc(sizeof(int) * _rulesChunk7_size);
+	for (int i = 0; i < _rulesChunk7_size; ++i)
+		_rulesChunk7[i] = f.readUint16LE();
+
+	curWord = f.readUint16LE();
+	_rulesChunk8 = (byte *)malloc(sizeof(byte) * curWord);
+	for (int i = 0; i < curWord; ++i)
+		_rulesChunk8[i] = f.readByte();
+
+	// Chunk 9
+	for (int i = 0; i < 60; i++)
+		_rulesChunk9[i] = f.readByte();
+
+	// Chunk 10 & 11
+	_rulesChunk10_size = f.readByte();
+	assert(_rulesChunk10_size <= 20);
+
+	if (_rulesChunk10_size != 0) {
+		_rulesChunk10 = (int *)malloc(sizeof(int) * _rulesChunk10_size);
+		int totalSize = 0;
+		for (int i = 0; i < _rulesChunk10_size; ++i) {
+			_rulesChunk10[i] = totalSize;
+			totalSize += f.readByte();
+		}
+		if (totalSize != 0) {
+			_rulesChunk11 = (byte *)malloc(sizeof(byte) * totalSize);
+			for (int i = 0; i < totalSize; i++)
+				_rulesChunk11[i] = f.readByte();
+		}
+	}
+
+	// Chunk 12
+	_rulesChunk12_size = f.readUint16LE();
+	assert(_rulesChunk12_size <= 40);
+
+	for (int i = 0; i < _rulesChunk12_size; i++) {
+		_rulesBuffer12_1[i] = f.readUint16LE();
+		_rulesBuffer12_2[i] = f.readUint16LE();
+		_rulesBuffer12_3[i] = f.readUint16LE();
+		_rulesBuffer12_4[i] = f.readUint16LE();
+	}
+
+	// Chunk 13
+	_word12F68_ERULES = f.readUint16LE();
+	for (int i = 0 ; i < 20; i++)
+		_rulesBuffer13_1[i] = f.readByte();
+
+	for (int i = 0 ; i < 20; i++)
+		_rulesBuffer13_2[i] = f.readUint16LE();
+
+	for (int i = 0 ; i < 20; i++)
+		_rulesBuffer13_3[i] = f.readUint16LE();
+
+	for (int i = 0; i < 20; i++) {
+		byte curByte = f.readByte();
+
+		if (curByte == 0x20)
+			_rulesBuffer13_4[i] = 0x39;
+		else if (curByte == 0xD)
+			_rulesBuffer13_4[i] = 0x1C;
+		// Hack to avoid xlat out of bounds
+		else if (curByte == 0xFF)
+			_rulesBuffer13_4[i] = 0x21;
+		// Hack to avoid xlat out of bounds
+		else if (curByte == 0x00)
+			_rulesBuffer13_4[i] = 0xB4;
+		else {
+			assert((curByte > 0x40) && (curByte <= 0x41 + 26));
+			_rulesBuffer13_4[i] = _rulesXlatArray[curByte - 0x41];
+		}
+	}
+	f.close();
+
+	// Skipped: Load Savegame
+}
+
 Common::Error LilliputEngine::run() {
 	s_Engine = this;
 	initGraphics(320, 200);
@@ -88,6 +318,23 @@ Common::Error LilliputEngine::run() {
 	// Setup mixer
 	syncSoundSettings();
 
+	// TODO: Init Palette
+
+	// Load files. In the original, the size was hardcoded
+	_bufferIdeogram = loadVGA("IDEOGRAM.VGA", false);
+	_bufferMen = loadVGA("MEN.VGA", false);
+	_bufferMen2 = loadVGA("MEN2.VGA", false);
+	_bufferIsoChars = loadVGA("ISOCHARS.VGA", false);
+	_bufferIsoMap = loadRaw("ISOMAP.DTA");
+
+	//TODO: Init mouse handler
+
+	loadRules();
+
+	//TODO: Init sound/music player
+	_scriptHandler->runScript(Common::MemoryReadStream(_rulesScript, _rulesScript_size));
+
+	//TODO: Main loop
 	return Common::kNoError;
 }
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 68dffd3..7080868 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -26,6 +26,7 @@
 #include "engines/engine.h"
 #include "common/file.h"
 #include "lilliput/console.h"
+#include "lilliput/script.h"
 
 namespace Common {
 class RandomSource;
@@ -75,6 +76,9 @@ public:
 	GUI::Debugger *getDebugger();
 
 	Common::RandomSource *_rnd;
+	LilliputScript *_scriptHandler;
+
+	byte _vm_byte1714E;
 
 	byte _buffer1[45056];
 	byte _buffer2[45056];
@@ -110,7 +114,7 @@ public:
 	int *_rulesChunk3;
 	int _rulesChunk3_size;
 	byte *_rulesChunk4;
-	int *_rulesScript;
+	byte *_rulesScript;
 	int _rulesScript_size;
 	int *_rulesChunk6;
 	int _rulesChunk6_size;
diff --git a/engines/lilliput/module.mk b/engines/lilliput/module.mk
index 0ec4403..6f701a3 100644
--- a/engines/lilliput/module.mk
+++ b/engines/lilliput/module.mk
@@ -2,8 +2,9 @@ MODULE := engines/lilliput
 
 MODULE_OBJS = \
 	console.o \
+	detection.o \
 	lilliput.o \
-	detection.o
+	script.o
 
 MODULE_DIRS += \
 	engines/lilliput
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
new file mode 100644
index 0000000..b8f1cc9
--- /dev/null
+++ b/engines/lilliput/script.cpp
@@ -0,0 +1,1051 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 "lilliput/lilliput.h"
+#include "lilliput/script.h"
+
+namespace Lilliput {
+
+LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm) {
+}
+
+LilliputScript::~LilliputScript() {
+}
+
+byte LilliputScript::handleOpcodeType1(int curWord) {
+	warning("handleOpcodeType1: %d", curWord);
+	switch (curWord) {
+	case 0x0:
+		return OC_sub173DF();
+		break;
+	case 0x1:
+		return OC_sub173F0();
+		break;
+	case 0x2:
+		return OC_sub1740A();
+		break;
+	case 0x3:
+		return OC_sub17434();
+		break;
+	case 0x4:
+		return OC_sub17468();
+		break;
+	case 0x5:
+		return OC_getRandom();
+		break;
+	case 0x6:
+		return OC_sub1748C();
+		break;
+	case 0x7:
+		return OC_compWord18776();
+		break;
+	case 0x8:
+		return OC_checkSaveFlag();
+		break;
+	case 0x9:
+		return OC_sub174C8();
+		break;
+	case 0xA:
+		return OC_sub174D8();
+		break;
+	case 0xB:
+		return OC_sub1750E();
+		break;
+	case 0xC:
+		return OC_compareCoords_1();
+		break;
+	case 0xD:
+		return OC_compareCoords_2();
+		break;
+	case 0xE:
+		return OC_sub1757C();
+		break;
+	case 0xF:
+		return OC_sub1759E();
+		break;
+	case 0x10:
+		return OC_compWord16EF8();
+		break;
+	case 0x11:
+		return OC_sub175C8();
+		break;
+	case 0x12:
+		return OC_sub17640();
+		break;
+	case 0x13:
+		return OC_sub176C4();
+		break;
+	case 0x14:
+		return OC_compWord10804();
+		break;
+	case 0x15:
+		return OC_sub17766();
+		break;
+	case 0x16:
+		return OC_sub17782();
+		break;
+	case 0x17:
+		return OC_sub1779E();
+		break;
+	case 0x18:
+		return OC_sub177C6();
+		break;
+	case 0x19:
+		return OC_compWord16EFE();
+		break;
+	case 0x1A:
+		return OC_sub177F5();
+		break;
+	case 0x1B:
+		return OC_sub17812();
+		break;
+	case 0x1C:
+		return OC_sub17825();
+		break;
+	case 0x1D:
+		return OC_sub17844();
+		break;
+	case 0x1E:
+		return OC_sub1785C();
+		break;
+	case 0x1F:
+		return OC_sub17886();
+		break;
+	case 0x20:
+		return OC_sub178A8();
+		break;
+	case 0x21:
+		return OC_sub178BA();
+		break;
+	case 0x22:
+		return OC_sub178C2();
+		break;
+	case 0x23:
+		return OC_sub178D2();
+		break;
+	case 0x24:
+		return OC_sub178E8();
+		break;
+	case 0x25:
+		return OC_sub178FC();
+		break;
+	case 0x26:
+		return OC_sub1790F();
+		break;
+	case 0x27:
+		return OC_sub1792A();
+		break;
+	case 0x28:
+		return OC_sub1793E();
+		break;
+	case 0x29:
+		return OC_sub1795E();
+		break;
+	case 0x2A:
+		return OC_sub1796E();
+		break;
+	case 0x2B:
+		return OC_sub17984();
+		break;
+	case 0x2C:
+		return OC_checkSavedMousePos();
+		break;
+	case 0x2D:
+		return OC_sub179AE();
+		break;
+	case 0x2E:
+		return OC_sub179C2();
+		break;
+	case 0x2F:
+		return OC_sub179E5();
+		break;
+	case 0x30:
+		return OC_sub17A07();
+		break;
+	case 0x31:
+		return OC_sub17757();
+		break;
+	default:
+		error("Unexpected opcode %d", curWord);
+		break;
+	}
+}
+
+void LilliputScript::handleOpcodeType2(int curWord) {
+	warning("handleOpcodeType1: %d", curWord);
+	switch (curWord) {
+	case 0x0:
+		OC_setWord18821();
+		break;
+	case 0x1:
+		OC_sub17A3E();
+		break;
+	case 0x2:
+		OC_sub17D57();
+		break;
+	case 0x3:
+		OC_sub17D7F();
+		break;
+	case 0x4:
+		OC_sub17DB9();
+		break;
+	case 0x5:
+		OC_sub17DF9();
+		break;
+	case 0x6:
+		OC_sub17E07();
+		break;
+	case 0x7:
+		OC_sub17E15();
+		break;
+	case 0x8:
+		OC_sub17B03();
+		break;
+	case 0x9:
+		OC_getRandom_type2();
+		break;
+	case 0xA:
+		OC_sub17A66();
+		break;
+	case 0xB:
+		OC_sub17A8D();
+		break;
+	case 0xC:
+		OC_saveAndQuit();
+		break;
+	case 0xD:
+		OC_sub17B93();
+		break;
+	case 0xE:
+		OC_sub17E37();
+		break;
+	case 0xF:
+		OC_resetByte1714E();
+		break;
+	case 0x10:
+		OC_deleteSavegameAndQuit();
+		break;
+	case 0x11:
+		OC_incByte16F04();
+		break;
+	case 0x12:
+		OC_sub17BA5();
+		break;
+	case 0x13:
+		OC_setByte18823();
+		break;
+	case 0x14:
+		OC_sub17BB7();
+		break;
+	case 0x15:
+		OC_sub17BF2();
+		break;
+	case 0x16:
+		OC_sub17ACC();
+		break;
+	case 0x17:
+		OC_resetByte16F04();
+		break;
+	case 0x18:
+		OC_sub17AE1();
+		break;
+	case 0x19:
+		OC_sub17AEE();
+		break;
+	case 0x1A:
+		OC_setWord10804();
+		break;
+	case 0x1B:
+		OC_sub17C0E();
+		break;
+	case 0x1C:
+		OC_sub17C55();
+		break;
+	case 0x1D:
+		OC_sub17C76();
+		break;
+	case 0x1E:
+		OC_sub17AFC();
+		break;
+	case 0x1F:
+		OC_sub17C8B();
+		break;
+	case 0x20:
+		OC_sub17CA2();
+		break;
+	case 0x21:
+		OC_sub17CB9();
+		break;
+	case 0x22:
+		OC_sub17CD1();
+		break;
+	case 0x23:
+		OC_resetWord16EFE();
+		break;
+	case 0x24:
+		OC_sub17CEF();
+		break;
+	case 0x25:
+		OC_sub17D1B();
+		break;
+	case 0x26:
+		OC_sub17D23();
+		break;
+	case 0x27:
+		OC_sub17E6D();
+		break;
+	case 0x28:
+		OC_sub17E7E();
+		break;
+	case 0x29:
+		OC_sub17E99();
+		break;
+	case 0x2A:
+		OC_sub17EC5();
+		break;
+	case 0x2B:
+		OC_sub17EF4();
+		break;
+	case 0x2C:
+		OC_sub17F08();
+		break;
+	case 0x2D:
+		OC_sub17F4F();
+		break;
+	case 0x2E:
+		OC_sub17F68();
+		break;
+	case 0x2F:
+		OC_getNextVal();
+		break;
+	case 0x30:
+		OC_sub17FD2();
+		break;
+	case 0x31:
+		OC_sub17FDD();
+		break;
+	case 0x32:
+		OC_setByte10B29();
+		break;
+	case 0x33:
+		OC_sub18007();
+		break;
+	case 0x34:
+		OC_sub18014();
+		break;
+	case 0x35:
+		OC_sub1801D();
+		break;
+	case 0x36:
+		OC_sub1805D();
+		break;
+	case 0x37:
+		OC_sub18074();
+		break;
+	case 0x38:
+		OC_sub1808B();
+		break;
+	case 0x39:
+		OC_sub18099();
+		break;
+	case 0x3A:
+		OC_sub180C3();
+		break;
+	case 0x3B:
+		OC_sub1810A();
+		break;
+	case 0x3C:
+		OC_sub1812D();
+		break;
+	case 0x3D:
+		OC_sub1817F();
+		break;
+	case 0x3E:
+		OC_sub181BB();
+		break;
+	case 0x3F:
+		OC_sub18213();
+		break;
+	case 0x40:
+		OC_sub18252();
+		break;
+	case 0x41:
+		OC_sub18260();
+		break;
+	case 0x42:
+		OC_sub182EC();
+		break;
+	case 0x43:
+		OC_unkPaletteFunction_1();
+		break;
+	case 0x44:
+		OC_unkPaletteFunction_2();
+		break;
+	case 0x45:
+		OC_loadAndDisplayCUBESx_GFX();
+		break;
+	case 0x46:
+		OC_sub1834C();
+		break;
+	case 0x47:
+		OC_sub18359();
+		break;
+	case 0x48:
+		OC_sub18367();
+		break;
+	case 0x49:
+		OC_sub17D04();
+		break;
+	case 0x4A:
+		OC_sub18387();
+		break;
+	case 0x4B:
+		OC_setByte14835();
+		break;
+	case 0x4C:
+		OC_setByte14837();
+		break;
+	case 0x4D:
+		OC_sub183A2();
+		break;
+	case 0x4E:
+		OC_sub183C6();
+		break;
+	case 0x4F:
+		OC_loadFile_AERIAL_GFX();
+		break;
+	case 0x50:
+		OC_sub17E22();
+		break;
+	case 0x51:
+		OC_sub1844A();
+		break;
+	case 0x52:
+		OC_sub1847F();
+		break;
+	case 0x53:
+		OC_sub184AA();
+		break;
+	case 0x54:
+		OC_sub184D7();
+		break;
+	case 0x55:
+		OC_sub184F5();
+		break;
+	case 0x56:
+		OC_sub1853B();
+		break;
+	case 0x57:
+		OC_sub1864D();
+		break;
+	case 0x58:
+		OC_sub18608();
+		break;
+	case 0x59:
+		OC_sub18678();
+		break;
+	case 0x5A:
+		OC_sub18690();
+		break;
+	case 0x5B:
+		OC_setWord10802();
+		break;
+	case 0x5C:
+		OC_sub186A1();
+		break;
+	case 0x5D:
+		OC_sub186E5_snd();
+		break;
+	case 0x5E:
+		OC_sub1870A_snd();
+		break;
+	case 0x5F:
+		OC_sub18725_snd();
+		break;
+	case 0x60:
+		OC_sub18733_snd();
+		break;
+	case 0x61:
+		OC_sub1873F_snd();
+		break;
+	case 0x62:
+		OC_sub18746_snd();
+		break;
+	case 0x63:
+		OC_sub1875D_snd();
+		break;
+	case 0x64:
+		OC_sub18764();
+		break;
+	case 0x65:
+		OC_sub1853B();
+		break;
+	default:
+		error("Unknown opcode %d", curWord);
+		break;
+	}
+}
+
+int LilliputScript::handleOpcode(Common::MemoryReadStream script) {
+	uint16 curWord = script.readUint16LE();
+	if (curWord == 0xFFF6)
+		return -1;
+
+	while (curWord != 0xFFF8) {
+		byte mask = 0; 
+		if (curWord > 1000) {
+			curWord -= 1000;
+			mask = 1;
+		}
+		byte result = handleOpcodeType1(curWord);
+		if ((result ^ mask) == 0) {
+			do {
+				curWord = script.readUint16LE();
+			} while (curWord != 0xFFF7);
+			return 0;
+		}
+	}
+
+	_vm->_vm_byte1714E = 1;
+
+	for (;;) {
+		curWord = script.readUint16LE();
+		if (curWord == 0xFFF7)
+			return _vm->_vm_byte1714E;
+
+		handleOpcodeType2(curWord);
+	}
+}
+
+void LilliputScript::runScript(Common::MemoryReadStream script) {
+	_byte16F05_ScriptHandler = 1;
+	
+	while (handleOpcode(script) != 0xFF)
+		;
+	
+}
+
+byte LilliputScript::OC_sub173DF() {
+	warning("OC_sub173DF");
+	return 0;
+}
+byte LilliputScript::OC_sub173F0() {
+	warning("OC_sub173F0");
+	return 0;
+}
+byte LilliputScript::OC_sub1740A() {
+	warning("OC_sub1740A");
+	return 0;
+}
+byte LilliputScript::OC_sub17434() {
+	warning("OC_sub17434");
+	return 0;
+}
+byte LilliputScript::OC_sub17468() {
+	warning("OC_sub17468");
+	return 0;
+}
+byte LilliputScript::OC_getRandom() {
+	warning("OC_getRandom");
+	return 0;
+}
+byte LilliputScript::OC_sub1748C() {
+	warning("OC_sub1748C");
+	return 0;
+}
+byte LilliputScript::OC_compWord18776() {
+	warning("OC_compWord18776");
+	return 0;
+}
+byte LilliputScript::OC_checkSaveFlag() {
+	warning("OC_checkSaveFlag");
+	return 0;
+}
+byte LilliputScript::OC_sub174C8() {
+	warning("OC_sub174C8");
+	return 0;
+}
+byte LilliputScript::OC_sub174D8() {
+	warning("OC_sub174D8");
+	return 0;
+}
+byte LilliputScript::OC_sub1750E() {
+	warning("OC_sub1750E");
+	return 0;
+}
+byte LilliputScript::OC_compareCoords_1() {
+	warning("compareCoords_1");
+	return 0;
+}
+byte LilliputScript::OC_compareCoords_2() {
+	warning("compareCoords_2");
+	return 0;
+}
+byte LilliputScript::OC_sub1757C() {
+	warning("OC_sub1757C");
+	return 0;
+}
+byte LilliputScript::OC_sub1759E() {
+	warning("OC_sub1759E");
+	return 0;
+}
+byte LilliputScript::OC_compWord16EF8() {
+	warning("OC_compWord16EF8");
+	return 0;
+}
+byte LilliputScript::OC_sub175C8() {
+	warning("OC_sub175C8");
+	return 0;
+}
+byte LilliputScript::OC_sub17640() {
+	warning("OC_sub17640");
+	return 0;
+}
+byte LilliputScript::OC_sub176C4() {
+	warning("OC_sub176C4");
+	return 0;
+}
+byte LilliputScript::OC_compWord10804() {
+	warning("OC_compWord10804");
+	return 0;
+}
+byte LilliputScript::OC_sub17766() {
+	warning("OC_sub17766");
+	return 0;
+}
+byte LilliputScript::OC_sub17782() {
+	warning("OC_sub17782");
+	return 0;
+}
+byte LilliputScript::OC_sub1779E() {
+	warning("OC_sub1779E");
+	return 0;
+}
+byte LilliputScript::OC_sub177C6() {
+	warning("OC_sub177C6");
+	return 0;
+}
+byte LilliputScript::OC_compWord16EFE() {
+	warning("OC_compWord16EFE");
+	return 0;
+}
+byte LilliputScript::OC_sub177F5() {
+	warning("OC_sub177F5");
+	return 0;
+}
+byte LilliputScript::OC_sub17812() {
+	warning("OC_sub17812");
+	return 0;
+}
+byte LilliputScript::OC_sub17825() {
+	warning("OC_sub17825");
+	return 0;
+}
+byte LilliputScript::OC_sub17844() {
+	warning("OC_sub17844");
+	return 0;
+}
+byte LilliputScript::OC_sub1785C() {
+	warning("OC_sub1785C");
+	return 0;
+}
+byte LilliputScript::OC_sub17886() {
+	warning("OC_sub17886");
+	return 0;
+}
+byte LilliputScript::OC_sub178A8() {
+	warning("OC_sub178A8");
+	return 0;
+}
+byte LilliputScript::OC_sub178BA() {
+	warning("OC_sub178BA");
+	return 0;
+}
+byte LilliputScript::OC_sub178C2() {
+	warning("OC_sub178C2");
+	return 0;
+}
+byte LilliputScript::OC_sub178D2() {
+	warning("OC_sub178D2");
+	return 0;
+}
+byte LilliputScript::OC_sub178E8() {
+	warning("OC_sub178E8");
+	return 0;
+}
+byte LilliputScript::OC_sub178FC() {
+	warning("OC_sub178FC");
+	return 0;
+}
+byte LilliputScript::OC_sub1790F() {
+	warning("OC_sub1790F");
+	return 0;
+}
+byte LilliputScript::OC_sub1792A() {
+	warning("OC_sub1792A");
+	return 0;
+}
+byte LilliputScript::OC_sub1793E() {
+	warning("OC_sub1793E");
+	return 0;
+}
+byte LilliputScript::OC_sub1795E() {
+	warning("OC_sub1795E");
+	return 0;
+}
+byte LilliputScript::OC_sub1796E() {
+	warning("OC_sub1796E");
+	return 0;
+}
+byte LilliputScript::OC_sub17984() {
+	warning("OC_sub17984");
+	return 0;
+}
+byte LilliputScript::OC_checkSavedMousePos() {
+	warning("OC_checkSavedMousePos");
+	return 0;
+}
+byte LilliputScript::OC_sub179AE() {
+	warning("OC_sub179AE");
+	return 0;
+}
+byte LilliputScript::OC_sub179C2() {
+	warning("OC_sub179C2");
+	return 0;
+}
+byte LilliputScript::OC_sub179E5() {
+	warning("OC_sub179E5");
+	return 0;
+}
+byte LilliputScript::OC_sub17A07() {
+	warning("OC_sub17A07");
+	return 0;
+}
+byte LilliputScript::OC_sub17757() {
+	warning("OC_sub17757");
+	return 0;
+}
+
+void LilliputScript::OC_setWord18821() {
+	warning("OC_setWord18821");
+}
+void LilliputScript::OC_sub17A3E() {
+	warning("OC_sub17A3E");
+}
+void LilliputScript::OC_sub17D57() {
+	warning("OC_sub17D57");
+}
+void LilliputScript::OC_sub17D7F() {
+	warning("OC_sub17D7F");
+}
+void LilliputScript::OC_sub17DB9() {
+	warning("OC_sub17DB9");
+}
+void LilliputScript::OC_sub17DF9() {
+	warning("OC_sub17DF9");
+}
+void LilliputScript::OC_sub17E07() {
+	warning("OC_sub17E07");
+}
+void LilliputScript::OC_sub17E15() {
+	warning("OC_sub17E15");
+}
+void LilliputScript::OC_sub17B03() {
+	warning("OC_sub17B03");
+}
+void LilliputScript::OC_getRandom_type2() {
+	warning("OC_getRandom_type2");
+}
+void LilliputScript::OC_sub17A66() {
+	warning("OC_sub17A66");
+}
+void LilliputScript::OC_sub17A8D() {
+	warning("OC_sub17A8D");
+}
+void LilliputScript::OC_saveAndQuit() {
+	warning("OC_saveAndQuit");
+}
+void LilliputScript::OC_sub17B93() {
+	warning("OC_sub17B93");
+}
+void LilliputScript::OC_sub17E37() {
+	warning("OC_sub17E37");
+}
+void LilliputScript::OC_resetByte1714E() {
+	warning("OC_resetByte1714E");
+}
+void LilliputScript::OC_deleteSavegameAndQuit() {
+	warning("OC_deleteSavegameAndQuit");
+}
+void LilliputScript::OC_incByte16F04() {
+	warning("OC_incByte16F04");
+}
+void LilliputScript::OC_sub17BA5() {
+	warning("OC_sub17BA5");
+}
+void LilliputScript::OC_setByte18823() {
+	warning("OC_setByte18823");
+}
+void LilliputScript::OC_sub17BB7() {
+	warning("OC_sub17BB7");
+}
+void LilliputScript::OC_sub17BF2() {
+	warning("OC_sub17BF2");
+}
+void LilliputScript::OC_sub17ACC() {
+	warning("OC_sub17ACC");
+}
+void LilliputScript::OC_resetByte16F04() {
+	warning("OC_resetByte16F04");
+}
+void LilliputScript::OC_sub17AE1() {
+	warning("OC_sub17AE1");
+}
+void LilliputScript::OC_sub17AEE() {
+	warning("OC_sub17AEE");
+}
+void LilliputScript::OC_setWord10804() {
+	warning("OC_setWord10804");
+}
+void LilliputScript::OC_sub17C0E() {
+	warning("OC_sub17C0E");
+}
+void LilliputScript::OC_sub17C55() {
+	warning("OC_sub17C55");
+}
+void LilliputScript::OC_sub17C76() {
+	warning("OC_sub17C76");
+}
+void LilliputScript::OC_sub17AFC() {
+	warning("OC_sub17AFC");
+}
+void LilliputScript::OC_sub17C8B() {
+	warning("OC_sub17C8B");
+}
+void LilliputScript::OC_sub17CA2() {
+	warning("OC_sub17CA2");
+}
+void LilliputScript::OC_sub17CB9() {
+	warning("OC_sub17CB9");
+}
+void LilliputScript::OC_sub17CD1() {
+	warning("OC_sub17CD1");
+}
+void LilliputScript::OC_resetWord16EFE() {
+	warning("OC_resetWord16EFE");
+}
+void LilliputScript::OC_sub17CEF() {
+	warning("OC_sub17CEF");
+}
+void LilliputScript::OC_sub17D1B() {
+	warning("OC_sub17D1B");
+}
+void LilliputScript::OC_sub17D23() {
+	warning("OC_sub17D23");
+}
+void LilliputScript::OC_sub17E6D() {
+	warning("OC_sub17E6D");
+}
+void LilliputScript::OC_sub17E7E() {
+	warning("OC_sub17E7E");
+}
+void LilliputScript::OC_sub17E99() {
+	warning("OC_sub17E99");
+}
+void LilliputScript::OC_sub17EC5() {
+	warning("OC_sub17EC5");
+}
+void LilliputScript::OC_sub17EF4() {
+	warning("OC_sub17EF4");
+}
+void LilliputScript::OC_sub17F08() {
+	warning("OC_sub17F08");
+}
+void LilliputScript::OC_sub17F4F() {
+	warning("OC_sub17F4F");
+}
+void LilliputScript::OC_sub17F68() {
+	warning("OC_sub17F68");
+}
+void LilliputScript::OC_getNextVal() {
+	warning("OC_getNextVal");
+}
+void LilliputScript::OC_sub17FD2() {
+	warning("OC_sub17FD2");
+}
+void LilliputScript::OC_sub17FDD() {
+	warning("OC_sub17FDD");
+}
+void LilliputScript::OC_setByte10B29() {
+	warning("OC_setByte10B29");
+}
+void LilliputScript::OC_sub18007() {
+	warning("OC_sub18007");
+}
+void LilliputScript::OC_sub18014() {
+	warning("OC_sub18014");
+}
+void LilliputScript::OC_sub1801D() {
+	warning("OC_sub1801D");
+}
+void LilliputScript::OC_sub1805D() {
+	warning("OC_sub1805D");
+}
+void LilliputScript::OC_sub18074() {
+	warning("OC_sub18074");
+}
+void LilliputScript::OC_sub1808B() {
+	warning("OC_sub1808B");
+}
+void LilliputScript::OC_sub18099() {
+	warning("OC_sub18099");
+}
+void LilliputScript::OC_sub180C3() {
+	warning("OC_sub180C3");
+}
+void LilliputScript::OC_sub1810A() {
+	warning("OC_sub1810A");
+}
+void LilliputScript::OC_sub1812D() {
+	warning("OC_sub1812D");
+}
+void LilliputScript::OC_sub1817F() {
+	warning("OC_sub1817F");
+}
+void LilliputScript::OC_sub181BB() {
+	warning("OC_sub181BB");
+}
+void LilliputScript::OC_sub18213() {
+	warning("OC_sub18213");
+}
+void LilliputScript::OC_sub18252() {
+	warning("OC_sub18252");
+}
+void LilliputScript::OC_sub18260() {
+	warning("OC_sub18260");
+}
+void LilliputScript::OC_sub182EC() {
+	warning("OC_sub182EC");
+}
+void LilliputScript::OC_unkPaletteFunction_1() {
+	warning("OC_unkPaletteFunction_1");
+}
+void LilliputScript::OC_unkPaletteFunction_2() {
+	warning("OC_unkPaletteFunction_2");
+}
+void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
+	warning("OC_loadAndDisplayCUBESx_GFX");
+}
+void LilliputScript::OC_sub1834C() {
+	warning("OC_sub1834C");
+}
+void LilliputScript::OC_sub18359() {
+	warning("OC_sub18359");
+}
+void LilliputScript::OC_sub18367() {
+	warning("OC_sub18367");
+}
+void LilliputScript::OC_sub17D04() {
+	warning("OC_sub17D04");
+}
+void LilliputScript::OC_sub18387() {
+	warning("OC_sub18387");
+}
+void LilliputScript::OC_setByte14835() {
+	warning("OC_setByte14835");
+}
+void LilliputScript::OC_setByte14837() {
+	warning("OC_setByte14837");
+}
+void LilliputScript::OC_sub183A2() {
+	warning("OC_sub183A2");
+}
+void LilliputScript::OC_sub183C6() {
+	warning("OC_sub183C6");
+}
+void LilliputScript::OC_loadFile_AERIAL_GFX() {
+	warning("OC_loadFile_AERIAL_GFX");
+}
+void LilliputScript::OC_sub17E22() {
+	warning("OC_sub17E22");
+}
+void LilliputScript::OC_sub1844A() {
+	warning("OC_sub1844A");
+}
+void LilliputScript::OC_sub1847F() {
+	warning("OC_sub1847F");
+}
+void LilliputScript::OC_sub184AA() {
+	warning("OC_sub184AA");
+}
+void LilliputScript::OC_sub184D7() {
+	warning("OC_sub184D7");
+}
+void LilliputScript::OC_sub184F5() {
+	warning("OC_sub184F5");
+}
+void LilliputScript::OC_sub1853B() {
+	warning("OC_sub1853B");
+}
+void LilliputScript::OC_sub1864D() {
+	warning("OC_sub1864D");
+}
+void LilliputScript::OC_sub18608() {
+	warning("OC_sub18608");
+}
+void LilliputScript::OC_sub18678() {
+	warning("OC_sub18678");
+}
+void LilliputScript::OC_sub18690() {
+	warning("OC_sub18690");
+}
+void LilliputScript::OC_setWord10802() {
+	warning("OC_setWord10802");
+}
+void LilliputScript::OC_sub186A1() {
+	warning("OC_sub186A1");
+}
+void LilliputScript::OC_sub186E5_snd() {
+	warning("OC_sub186E5_snd");
+}
+void LilliputScript::OC_sub1870A_snd() {
+	warning("OC_sub1870A_snd");
+}
+void LilliputScript::OC_sub18725_snd() {
+	warning("OC_sub18725_snd");
+}
+void LilliputScript::OC_sub18733_snd() {
+	warning("OC_sub18733_snd");
+}
+void LilliputScript::OC_sub1873F_snd() {
+	warning("OC_sub1873F_snd");
+}
+void LilliputScript::OC_sub18746_snd() {
+	warning("OC_sub18746_snd");
+}
+void LilliputScript::OC_sub1875D_snd() {
+	warning("OC_sub1875D_snd");
+}
+void LilliputScript::OC_sub18764() {
+	warning("OC_sub18764");
+}
+} // End of namespace
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
new file mode 100644
index 0000000..4ad9919
--- /dev/null
+++ b/engines/lilliput/script.h
@@ -0,0 +1,205 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 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 LILLIPUT_SCRIPT_H
+#define LILLIPUT_SCRIPT_H
+
+#include "common/memstream.h"
+
+namespace Lilliput {
+
+class LilliputEngine;
+class LilliputScript {
+public:
+	LilliputScript(LilliputEngine *vm);
+	~LilliputScript();
+
+	void runScript(Common::MemoryReadStream script);
+private:
+	LilliputEngine *_vm;
+
+	byte _byte16F05_ScriptHandler;
+
+	int handleOpcode(Common::MemoryReadStream script);
+	byte handleOpcodeType1(int curWord);
+	void handleOpcodeType2(int curWord);
+
+	//Opcodes Type 1
+	byte OC_sub173DF();
+	byte OC_sub173F0();
+	byte OC_sub1740A();
+	byte OC_sub17434();
+	byte OC_sub17468();
+	byte OC_getRandom();
+	byte OC_sub1748C();
+	byte OC_compWord18776();
+	byte OC_checkSaveFlag();
+	byte OC_sub174C8();
+	byte OC_sub174D8();
+	byte OC_sub1750E();
+	byte OC_compareCoords_1();
+	byte OC_compareCoords_2();
+	byte OC_sub1757C();
+	byte OC_sub1759E();
+	byte OC_compWord16EF8();
+	byte OC_sub175C8();
+	byte OC_sub17640();
+	byte OC_sub176C4();
+	byte OC_compWord10804();
+	byte OC_sub17766();
+	byte OC_sub17782();
+	byte OC_sub1779E();
+	byte OC_sub177C6();
+	byte OC_compWord16EFE();
+	byte OC_sub177F5();
+	byte OC_sub17812();
+	byte OC_sub17825();
+	byte OC_sub17844();
+	byte OC_sub1785C();
+	byte OC_sub17886();
+	byte OC_sub178A8();
+	byte OC_sub178BA();
+	byte OC_sub178C2();
+	byte OC_sub178D2();
+	byte OC_sub178E8();
+	byte OC_sub178FC();
+	byte OC_sub1790F();
+	byte OC_sub1792A();
+	byte OC_sub1793E();
+	byte OC_sub1795E();
+	byte OC_sub1796E();
+	byte OC_sub17984();
+	byte OC_checkSavedMousePos();
+	byte OC_sub179AE();
+	byte OC_sub179C2();
+	byte OC_sub179E5();
+	byte OC_sub17A07();
+	byte OC_sub17757();
+
+	// Opcodes Type 2
+	void OC_setWord18821();
+	void OC_sub17A3E();
+	void OC_sub17D57();
+	void OC_sub17D7F();
+	void OC_sub17DB9();
+	void OC_sub17DF9();
+	void OC_sub17E07();
+	void OC_sub17E15();
+	void OC_sub17B03();
+	void OC_getRandom_type2();
+	void OC_sub17A66();
+	void OC_sub17A8D();
+	void OC_saveAndQuit();
+	void OC_sub17B93();
+	void OC_sub17E37();
+	void OC_resetByte1714E();
+	void OC_deleteSavegameAndQuit();
+	void OC_incByte16F04();
+	void OC_sub17BA5();
+	void OC_setByte18823();
+	void OC_sub17BB7();
+	void OC_sub17BF2();
+	void OC_sub17ACC();
+	void OC_resetByte16F04();
+	void OC_sub17AE1();
+	void OC_sub17AEE();
+	void OC_setWord10804();
+	void OC_sub17C0E();
+	void OC_sub17C55();
+	void OC_sub17C76();
+	void OC_sub17AFC();
+	void OC_sub17C8B();
+	void OC_sub17CA2();
+	void OC_sub17CB9();
+	void OC_sub17CD1();
+	void OC_resetWord16EFE();
+	void OC_sub17CEF();
+	void OC_sub17D1B();
+	void OC_sub17D23();
+	void OC_sub17E6D();
+	void OC_sub17E7E();
+	void OC_sub17E99();
+	void OC_sub17EC5();
+	void OC_sub17EF4();
+	void OC_sub17F08();
+	void OC_sub17F4F();
+	void OC_sub17F68();
+	void OC_getNextVal();
+	void OC_sub17FD2();
+	void OC_sub17FDD();
+	void OC_setByte10B29();
+	void OC_sub18007();
+	void OC_sub18014();
+	void OC_sub1801D();
+	void OC_sub1805D();
+	void OC_sub18074();
+	void OC_sub1808B();
+	void OC_sub18099();
+	void OC_sub180C3();
+	void OC_sub1810A();
+	void OC_sub1812D();
+	void OC_sub1817F();
+	void OC_sub181BB();
+	void OC_sub18213();
+	void OC_sub18252();
+	void OC_sub18260();
+	void OC_sub182EC();
+	void OC_unkPaletteFunction_1();
+	void OC_unkPaletteFunction_2();
+	void OC_loadAndDisplayCUBESx_GFX();
+	void OC_sub1834C();
+	void OC_sub18359();
+	void OC_sub18367();
+	void OC_sub17D04();
+	void OC_sub18387();
+	void OC_setByte14835();
+	void OC_setByte14837();
+	void OC_sub183A2();
+	void OC_sub183C6();
+	void OC_loadFile_AERIAL_GFX();
+	void OC_sub17E22();
+	void OC_sub1844A();
+	void OC_sub1847F();
+	void OC_sub184AA();
+	void OC_sub184D7();
+	void OC_sub184F5();
+	void OC_sub1853B();
+	void OC_sub1864D();
+	void OC_sub18608();
+	void OC_sub18678();
+	void OC_sub18690();
+	void OC_setWord10802();
+	void OC_sub186A1();
+	void OC_sub186E5_snd();
+	void OC_sub1870A_snd();
+	void OC_sub18725_snd();
+	void OC_sub18733_snd();
+	void OC_sub1873F_snd();
+	void OC_sub18746_snd();
+	void OC_sub1875D_snd();
+	void OC_sub18764();
+};
+
+} // End of namespace Lilliput
+
+#endif
+


Commit: 4dd99da6dcebbe2e2ffc479da707a53f9fdaa64e
    https://github.com/scummvm/scummvm/commit/4dd99da6dcebbe2e2ffc479da707a53f9fdaa64e
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Start implementing some functions

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 285f03c..12399ba 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -208,12 +208,12 @@ void LilliputEngine::loadRules() {
 	_rulesChunk3_size = f.readSint16LE();
 	curWord = f.readSint16LE();
 
-	warning("Pos %d", f.pos());
+	warning("Pos %d - size chunk3: %d", f.pos(), _rulesChunk3_size);
 	_rulesChunk3 = (int *)malloc(sizeof(int) * _rulesChunk3_size);
 	for (int i = 0; i < _rulesChunk3_size; ++i)
 		_rulesChunk3[i] = f.readUint16LE();
 
-	warning("Pos %d", f.pos());
+	warning("Pos %d - size chunk4: %d", f.pos(), curWord);
 	_rulesChunk4 = (byte *)malloc(sizeof(byte) * curWord);
 	for (int i = 0; i < curWord; ++i)
 		_rulesChunk4[i] = f.readByte();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 7080868..d423c4c 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -66,6 +66,20 @@ enum LilliputDebugChannels {
 
 struct LilliputGameDescription;
 
+struct struct18560 {
+	byte _field0;
+	int16 _field1;
+	int16 _field3;
+	int16 _field5;
+	int16 _field7;
+	int16 _field9;
+	int16 _fieldB;
+	int16 _fieldD;
+	int16 _fieldF;
+	int16 _field11;
+	int16 _field13;
+};
+
 class LilliputEngine : public Engine {
 public:
 	LilliputEngine(OSystem *syst, const LilliputGameDescription *gd);
@@ -78,6 +92,7 @@ public:
 	Common::RandomSource *_rnd;
 	LilliputScript *_scriptHandler;
 
+	struct18560 _arr18560[4];
 	byte _vm_byte1714E;
 
 	byte _buffer1[45056];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b8f1cc9..de05692 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -25,7 +25,7 @@
 
 namespace Lilliput {
 
-LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm) {
+LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 }
 
 LilliputScript::~LilliputScript() {
@@ -443,7 +443,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1847F();
 		break;
 	case 0x53:
-		OC_sub184AA();
+		OC_displayVGAFile();
 		break;
 	case 0x54:
 		OC_sub184D7();
@@ -458,7 +458,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1864D();
 		break;
 	case 0x58:
-		OC_sub18608();
+		OC_initArr18560();
 		break;
 	case 0x59:
 		OC_sub18678();
@@ -506,6 +506,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 }
 
 int LilliputScript::handleOpcode(Common::MemoryReadStream script) {
+	_currScript = &script;
 	uint16 curWord = script.readUint16LE();
 	if (curWord == 0xFFF6)
 		return -1;
@@ -994,8 +995,17 @@ void LilliputScript::OC_sub1844A() {
 void LilliputScript::OC_sub1847F() {
 	warning("OC_sub1847F");
 }
-void LilliputScript::OC_sub184AA() {
-	warning("OC_sub184AA");
+void LilliputScript::OC_displayVGAFile() {
+	warning("OC_displayVGAFile");
+
+	_vm_byte12A09 = 1;
+	warning("TODO: unkPaletteFunction_1");
+	int curWord = _currScript->readUint16LE();
+	int index = _vm->_rulesChunk3[curWord];
+	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
+	_vm_word1881B = -1;
+	warning("TODO: guess_displayFunction_VGAFile");
+	warning("TODO: unkPaletteFunction_2");
 }
 void LilliputScript::OC_sub184D7() {
 	warning("OC_sub184D7");
@@ -1009,8 +1019,21 @@ void LilliputScript::OC_sub1853B() {
 void LilliputScript::OC_sub1864D() {
 	warning("OC_sub1864D");
 }
-void LilliputScript::OC_sub18608() {
-	warning("OC_sub18608");
+void LilliputScript::OC_initArr18560() {
+	warning("OC_initArr18560");
+	int curWord = _currScript->readUint16LE();
+	assert (curWord < 4);
+	_vm->_arr18560[curWord]._field0 = 1;
+	_vm->_arr18560[curWord]._field1 = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._field3 = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._field5 = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._field7 = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._field9 = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._fieldB = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._fieldD = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._fieldF = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._field11 = _currScript->readUint16LE();
+	_vm->_arr18560[curWord]._field13 = _currScript->readUint16LE();
 }
 void LilliputScript::OC_sub18678() {
 	warning("OC_sub18678");
@@ -1041,6 +1064,9 @@ void LilliputScript::OC_sub1873F_snd() {
 }
 void LilliputScript::OC_sub18746_snd() {
 	warning("OC_sub18746_snd");
+	int curWord = _currScript->readUint16LE();
+	curWord = (2 << 8) + (curWord & 0xFF);
+	warning("TODO: ovlContentOVL Function 2, init DX and BX");
 }
 void LilliputScript::OC_sub1875D_snd() {
 	warning("OC_sub1875D_snd");
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 4ad9919..b90f61e 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -37,7 +37,12 @@ public:
 private:
 	LilliputEngine *_vm;
 
+	Common::MemoryReadStream *_currScript;
+
 	byte _byte16F05_ScriptHandler;
+	byte _vm_byte12A09;
+
+	int16 _vm_word1881B;
 
 	int handleOpcode(Common::MemoryReadStream script);
 	byte handleOpcodeType1(int curWord);
@@ -179,12 +184,12 @@ private:
 	void OC_sub17E22();
 	void OC_sub1844A();
 	void OC_sub1847F();
-	void OC_sub184AA();
+	void OC_displayVGAFile();
 	void OC_sub184D7();
 	void OC_sub184F5();
 	void OC_sub1853B();
 	void OC_sub1864D();
-	void OC_sub18608();
+	void OC_initArr18560();
 	void OC_sub18678();
 	void OC_sub18690();
 	void OC_setWord10802();


Commit: 17320cadb759c996446b34813eeff13a50b6ab56
    https://github.com/scummvm/scummvm/commit/17320cadb759c996446b34813eeff13a50b6ab56
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement OC_sub184F5, modify struct18560

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 12399ba..e62e4c8 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -204,22 +204,18 @@ void LilliputEngine::loadRules() {
 	}
 
 	// Chunk 3 & 4
-	warning("Chunk 3 & 4 Pos: %d", f.pos());
 	_rulesChunk3_size = f.readSint16LE();
 	curWord = f.readSint16LE();
 
-	warning("Pos %d - size chunk3: %d", f.pos(), _rulesChunk3_size);
 	_rulesChunk3 = (int *)malloc(sizeof(int) * _rulesChunk3_size);
 	for (int i = 0; i < _rulesChunk3_size; ++i)
 		_rulesChunk3[i] = f.readUint16LE();
 
-	warning("Pos %d - size chunk4: %d", f.pos(), curWord);
 	_rulesChunk4 = (byte *)malloc(sizeof(byte) * curWord);
 	for (int i = 0; i < curWord; ++i)
 		_rulesChunk4[i] = f.readByte();
 
 	// Chunk 5: Scripts
-	warning("Chunk 5 Pos: %d", f.pos());
 	// Use byte instead of int, therefore multiply by two the size.
 	// This is for changing that into a memory read stream
 	_rulesScript_size = f.readUint16LE() * 2;
@@ -343,6 +339,14 @@ void LilliputEngine::initialize() {
 
 	_rnd = new Common::RandomSource("robin");
 	_rnd->setSeed(42);                              // Kick random number generator
+
+	for (int i = 0; i < 4; i++) {
+		_arr18560[i]._field0 = 0;
+		_arr18560[i]._field1 = 0;
+		_arr18560[i]._field3 = 0;
+		for (int j = 0; j < 8; j ++)
+			_arr18560[i]._field5[j] = 0;
+	}
 }
 
 void LilliputEngine::syncSoundSettings() {
@@ -355,6 +359,8 @@ Common::String LilliputEngine::getSavegameFilename(int slot) {
 	return _targetName + Common::String::format("-%02d.SAV", slot);
 }
 
-
+byte LilliputEngine::_keyboard_getch() {
+	return ' ';
+}
 
 } // End of namespace Lilliput
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index d423c4c..389a20d 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -70,14 +70,7 @@ struct struct18560 {
 	byte _field0;
 	int16 _field1;
 	int16 _field3;
-	int16 _field5;
-	int16 _field7;
-	int16 _field9;
-	int16 _fieldB;
-	int16 _fieldD;
-	int16 _fieldF;
-	int16 _field11;
-	int16 _field13;
+	int16 _field5[8];
 };
 
 class LilliputEngine : public Engine {
@@ -94,6 +87,11 @@ public:
 
 	struct18560 _arr18560[4];
 	byte _vm_byte1714E;
+	byte _byte184F4;
+	byte _sound_byte16F06;
+	byte _byte16F09;
+	byte _keyboard_nextIndex;
+	byte _keyboard_oldIndex;
 
 	byte _buffer1[45056];
 	byte _buffer2[45056];
@@ -109,6 +107,9 @@ public:
 	
 	int _word10800_ERULES;
 	int _word10807_ERULES;
+	int _vm_word12D3D;
+	int _vm_word12D3F;
+
 	byte *_rulesChunk1;
 	int _rulesBuffer2_1[40];
 	int _rulesBuffer2_2[40];
@@ -170,6 +171,11 @@ public:
 	Common::String getSavegameFilename(int slot);
 	void syncSoundSettings();
 
+	// Temporary stubs
+	byte _mouse_byte1299A;
+
+	byte _keyboard_getch();
+
 protected:
 
 	// Engine APIs
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index de05692..461fb9b 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -32,7 +32,6 @@ LilliputScript::~LilliputScript() {
 }
 
 byte LilliputScript::handleOpcodeType1(int curWord) {
-	warning("handleOpcodeType1: %d", curWord);
 	switch (curWord) {
 	case 0x0:
 		return OC_sub173DF();
@@ -191,7 +190,6 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 }
 
 void LilliputScript::handleOpcodeType2(int curWord) {
-	warning("handleOpcodeType1: %d", curWord);
 	switch (curWord) {
 	case 0x0:
 		OC_setWord18821();
@@ -1004,7 +1002,7 @@ void LilliputScript::OC_displayVGAFile() {
 	int index = _vm->_rulesChunk3[curWord];
 	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
 	_vm_word1881B = -1;
-	warning("TODO: guess_displayFunction_VGAFile");
+	warning("TODO: guess_displayFunction_VGAFile(%s)", fileName.c_str());
 	warning("TODO: unkPaletteFunction_2");
 }
 void LilliputScript::OC_sub184D7() {
@@ -1012,6 +1010,36 @@ void LilliputScript::OC_sub184D7() {
 }
 void LilliputScript::OC_sub184F5() {
 	warning("OC_sub184F5");
+	_vm->_byte184F4 = (_currScript->readUint16LE() & 0xFF);
+	_vm->_sound_byte16F06 = _vm->_byte184F4;
+	// TODO: use a separated function when properly identified
+	_vm->_vm_word12D3D = 0;
+	_vm->_vm_word12D3F = 0;
+	//
+	_vm->_mouse_byte1299A = 0;
+	_vm->_byte16F09 = 0;
+
+	// TODO: Remove when the sound is hooked
+	_vm->_sound_byte16F06 = 0;
+	//
+
+	for (;;) {
+		warning("TODO: display function sub_185B4();");
+
+		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
+			_vm->_byte16F09 = _vm->_keyboard_getch();
+			_vm->_keyboard_getch();
+			break;
+		}
+		
+		if (_vm->_mouse_byte1299A == 1)
+			break;
+		
+		if ((_vm->_byte184F4 != 0) && (_vm->_sound_byte16F06 == 0))
+			break;
+	}
+	
+	_vm->_mouse_byte1299A = 0;
 }
 void LilliputScript::OC_sub1853B() {
 	warning("OC_sub1853B");
@@ -1026,14 +1054,8 @@ void LilliputScript::OC_initArr18560() {
 	_vm->_arr18560[curWord]._field0 = 1;
 	_vm->_arr18560[curWord]._field1 = _currScript->readUint16LE();
 	_vm->_arr18560[curWord]._field3 = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._field5 = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._field7 = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._field9 = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._fieldB = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._fieldD = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._fieldF = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._field11 = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._field13 = _currScript->readUint16LE();
+	for (int i = 0; i < 8; i++)
+		_vm->_arr18560[curWord]._field5[i] = _currScript->readUint16LE();
 }
 void LilliputScript::OC_sub18678() {
 	warning("OC_sub18678");


Commit: 53518bc6770e1b09211b8e2846f8655890f70a2b
    https://github.com/scummvm/scummvm/commit/53518bc6770e1b09211b8e2846f8655890f70a2b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a couple of bugs in handleOpcode()

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index e62e4c8..7192628 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -55,7 +55,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_rnd = 0;
 	_scriptHandler = new LilliputScript(this);
 
-	_vm_byte1714E = 0;
+	_byte1714E = 0;
+	_rulesBuffer2PrevIndx = 0;
 }
 
 LilliputEngine::~LilliputEngine() {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 389a20d..23f5ae0 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -86,7 +86,7 @@ public:
 	LilliputScript *_scriptHandler;
 
 	struct18560 _arr18560[4];
-	byte _vm_byte1714E;
+	byte _byte1714E;
 	byte _byte184F4;
 	byte _sound_byte16F06;
 	byte _byte16F09;
@@ -107,10 +107,11 @@ public:
 	
 	int _word10800_ERULES;
 	int _word10807_ERULES;
-	int _vm_word12D3D;
-	int _vm_word12D3F;
+	int _word12D3D;
+	int _word12D3F;
 
 	byte *_rulesChunk1;
+	int _rulesBuffer2PrevIndx;
 	int _rulesBuffer2_1[40];
 	int _rulesBuffer2_2[40];
 	byte _rulesBuffer2_3[40];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 461fb9b..f89ca7a 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -26,6 +26,9 @@
 namespace Lilliput {
 
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
+	_byte129A0 = 0xFF;
+	_word16F00 = -1;
+	_word10804 = 0;
 }
 
 LilliputScript::~LilliputScript() {
@@ -503,13 +506,13 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 	}
 }
 
-int LilliputScript::handleOpcode(Common::MemoryReadStream script) {
-	_currScript = &script;
-	uint16 curWord = script.readUint16LE();
+int LilliputScript::handleOpcode(Common::MemoryReadStream *script) {
+	_currScript = script;
+	uint16 curWord = _currScript->readUint16LE();
 	if (curWord == 0xFFF6)
 		return -1;
 
-	while (curWord != 0xFFF8) {
+	for (; curWord != 0xFFF8; curWord = _currScript->readUint16LE()) {
 		byte mask = 0; 
 		if (curWord > 1000) {
 			curWord -= 1000;
@@ -518,18 +521,18 @@ int LilliputScript::handleOpcode(Common::MemoryReadStream script) {
 		byte result = handleOpcodeType1(curWord);
 		if ((result ^ mask) == 0) {
 			do {
-				curWord = script.readUint16LE();
+				curWord = _currScript->readUint16LE();
 			} while (curWord != 0xFFF7);
 			return 0;
 		}
 	}
 
-	_vm->_vm_byte1714E = 1;
+	_vm->_byte1714E = 1;
 
 	for (;;) {
-		curWord = script.readUint16LE();
+		curWord = _currScript->readUint16LE();
 		if (curWord == 0xFFF7)
-			return _vm->_vm_byte1714E;
+			return _vm->_byte1714E;
 
 		handleOpcodeType2(curWord);
 	}
@@ -538,9 +541,52 @@ int LilliputScript::handleOpcode(Common::MemoryReadStream script) {
 void LilliputScript::runScript(Common::MemoryReadStream script) {
 	_byte16F05_ScriptHandler = 1;
 	
-	while (handleOpcode(script) != 0xFF)
+	while (handleOpcode(&script) != 0xFF)
 		;
-	
+}
+
+byte LilliputScript::compValues(byte var1, int oper, int var2) {
+	warning("compValues - %d %c %d", var1, oper & 0xFF, var2);
+	switch (oper & 0xFF) {
+	case '<':
+		return (var1 < var2);
+	case '>':
+		return (var1 > var2);
+	default:
+		return (var1 == var2);
+		break;
+	}
+}
+
+int LilliputScript::getValue1() {
+	int curWord = _currScript->readUint16LE();
+	if (curWord < 1000)
+		return curWord;
+
+	switch (curWord) {
+	case 1000:
+		return (int)_byte129A0;
+	case 1001:
+		return _vm->_rulesBuffer2PrevIndx;
+	case 1002:
+		return _word16F00;
+	case 1003:
+		return (int)_vm->_rulesBuffer2_15[6];
+	case 1004:
+		return _word10804;
+	default:
+		warning("getValue1: Unexpected large value %d", curWord);
+		return curWord;
+	}
+}
+
+byte *LilliputScript::getBuffer215Ptr() {
+	int tmpVal = getValue1();
+	tmpVal *= 32;
+	tmpVal += _currScript->readUint16LE();
+
+	assert(tmpVal < 40 * 32);
+	return &_vm->_rulesBuffer2_15[tmpVal];
 }
 
 byte LilliputScript::OC_sub173DF() {
@@ -555,14 +601,21 @@ byte LilliputScript::OC_sub1740A() {
 	warning("OC_sub1740A");
 	return 0;
 }
+
 byte LilliputScript::OC_sub17434() {
-	warning("OC_sub17434");
-	return 0;
+	byte *tmpArr = getBuffer215Ptr();
+	byte var1 = tmpArr[0];
+	uint16 oper = _currScript->readUint16LE();
+	int16 var2 = _currScript->readUint16LE();
+
+	return compValues(var1, oper, var2);
 }
+
 byte LilliputScript::OC_sub17468() {
 	warning("OC_sub17468");
 	return 0;
 }
+
 byte LilliputScript::OC_getRandom() {
 	warning("OC_getRandom");
 	return 0;
@@ -994,14 +1047,12 @@ void LilliputScript::OC_sub1847F() {
 	warning("OC_sub1847F");
 }
 void LilliputScript::OC_displayVGAFile() {
-	warning("OC_displayVGAFile");
-
-	_vm_byte12A09 = 1;
+	_byte12A09 = 1;
 	warning("TODO: unkPaletteFunction_1");
 	int curWord = _currScript->readUint16LE();
 	int index = _vm->_rulesChunk3[curWord];
 	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
-	_vm_word1881B = -1;
+	_word1881B = -1;
 	warning("TODO: guess_displayFunction_VGAFile(%s)", fileName.c_str());
 	warning("TODO: unkPaletteFunction_2");
 }
@@ -1009,12 +1060,11 @@ void LilliputScript::OC_sub184D7() {
 	warning("OC_sub184D7");
 }
 void LilliputScript::OC_sub184F5() {
-	warning("OC_sub184F5");
 	_vm->_byte184F4 = (_currScript->readUint16LE() & 0xFF);
 	_vm->_sound_byte16F06 = _vm->_byte184F4;
 	// TODO: use a separated function when properly identified
-	_vm->_vm_word12D3D = 0;
-	_vm->_vm_word12D3F = 0;
+	_vm->_word12D3D = 0;
+	_vm->_word12D3F = 0;
 	//
 	_vm->_mouse_byte1299A = 0;
 	_vm->_byte16F09 = 0;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index b90f61e..8a0793e 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -40,14 +40,21 @@ private:
 	Common::MemoryReadStream *_currScript;
 
 	byte _byte16F05_ScriptHandler;
-	byte _vm_byte12A09;
+	byte _byte12A09;
+	byte _byte129A0;
 
-	int16 _vm_word1881B;
+	int16 _word1881B;
+	int16 _word16F00;
+	int16 _word10804;
 
-	int handleOpcode(Common::MemoryReadStream script);
+	int handleOpcode(Common::MemoryReadStream *script);
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 
+	int getValue1();
+	byte *getBuffer215Ptr();
+	byte compValues(byte var1, int oper, int var2);
+
 	//Opcodes Type 1
 	byte OC_sub173DF();
 	byte OC_sub173F0();


Commit: 7865322c0a7d006e76935155ac9ac904e8c39c55
    https://github.com/scummvm/scummvm/commit/7865322c0a7d006e76935155ac9ac904e8c39c55
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement a couple of other opcodes, add proper debugc

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7192628..cb3af63 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -40,16 +40,8 @@ LilliputEngine *LilliputEngine::s_Engine = 0;
 LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) : Engine(syst), _gameDescription(gd)
 {
 	_system = syst;
-	DebugMan.addDebugChannel(kDebugSchedule, "Schedule", "Script Schedule debug level");
 	DebugMan.addDebugChannel(kDebugEngine, "Engine", "Engine debug level");
-	DebugMan.addDebugChannel(kDebugDisplay, "Display", "Display debug level");
-	DebugMan.addDebugChannel(kDebugMouse, "Mouse", "Mouse debug level");
-	DebugMan.addDebugChannel(kDebugParser, "Parser", "Parser debug level");
-	DebugMan.addDebugChannel(kDebugFile, "File", "File IO debug level");
-	DebugMan.addDebugChannel(kDebugRoute, "Route", "Route debug level");
-	DebugMan.addDebugChannel(kDebugInventory, "Inventory", "Inventory debug level");
-	DebugMan.addDebugChannel(kDebugObject, "Object", "Object debug level");
-	DebugMan.addDebugChannel(kDebugMusic, "Music", "Music debug level");
+	DebugMan.addDebugChannel(kDebugScript, "Script", "Script debug level");
 
 	_console = new LilliputConsole(this);
 	_rnd = 0;
@@ -57,6 +49,13 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 
 	_byte1714E = 0;
 	_rulesBuffer2PrevIndx = 0;
+	_word16EFA = 0;
+
+	for (int i = 0; i < 40; i++) {
+		_byte10999[i] = 0;
+		_byte109C1[i] = 0;
+	}
+
 }
 
 LilliputEngine::~LilliputEngine() {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 23f5ae0..a908dd0 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -52,16 +52,8 @@ enum GameType {
 };
 
 enum LilliputDebugChannels {
-	kDebugSchedule  = 1 <<  0,
-	kDebugEngine    = 1 <<  1,
-	kDebugDisplay   = 1 <<  2,
-	kDebugMouse     = 1 <<  3,
-	kDebugParser    = 1 <<  4,
-	kDebugFile      = 1 <<  5,
-	kDebugRoute     = 1 <<  6,
-	kDebugInventory = 1 <<  7,
-	kDebugObject    = 1 <<  8,
-	kDebugMusic     = 1 <<  9
+	kDebugEngine    = 1 <<  0,
+	kDebugScript    = 1 <<  1
 };
 
 struct LilliputGameDescription;
@@ -109,6 +101,7 @@ public:
 	int _word10807_ERULES;
 	int _word12D3D;
 	int _word12D3F;
+	int _word16EFA;
 
 	byte *_rulesChunk1;
 	int _rulesBuffer2PrevIndx;
@@ -152,7 +145,8 @@ public:
 	int _rulesBuffer13_2[20];
 	int _rulesBuffer13_3[20];
 	byte _rulesBuffer13_4[20];
-
+	byte _byte10999[40];
+	byte _byte109C1[40];
 
 	const LilliputGameDescription *_gameDescription;
 	uint32 getFeatures() const;
@@ -174,7 +168,7 @@ public:
 
 	// Temporary stubs
 	byte _mouse_byte1299A;
-
+	byte _mouse_savedMousePosDivided;
 	byte _keyboard_getch();
 
 protected:
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f89ca7a..5c1bdcf 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -22,6 +22,7 @@
 
 #include "lilliput/lilliput.h"
 #include "lilliput/script.h"
+#include "common/debug.h"
 
 namespace Lilliput {
 
@@ -35,6 +36,7 @@ LilliputScript::~LilliputScript() {
 }
 
 byte LilliputScript::handleOpcodeType1(int curWord) {
+	debugC(2, kDebugScript, "handleOpcodeType1(0x%x)", curWord);
 	switch (curWord) {
 	case 0x0:
 		return OC_sub173DF();
@@ -193,6 +195,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 }
 
 void LilliputScript::handleOpcodeType2(int curWord) {
+	debugC(2, kDebugScript, "handleOpcodeType2(0x%x)", curWord);
 	switch (curWord) {
 	case 0x0:
 		OC_setWord18821();
@@ -507,6 +510,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 }
 
 int LilliputScript::handleOpcode(Common::MemoryReadStream *script) {
+	debugC(2, kDebugScript, "handleOpcode");
 	_currScript = script;
 	uint16 curWord = _currScript->readUint16LE();
 	if (curWord == 0xFFF6)
@@ -539,6 +543,7 @@ int LilliputScript::handleOpcode(Common::MemoryReadStream *script) {
 }
 
 void LilliputScript::runScript(Common::MemoryReadStream script) {
+	debugC(1, kDebugScript, "runScript");
 	_byte16F05_ScriptHandler = 1;
 	
 	while (handleOpcode(&script) != 0xFF)
@@ -546,7 +551,7 @@ void LilliputScript::runScript(Common::MemoryReadStream script) {
 }
 
 byte LilliputScript::compValues(byte var1, int oper, int var2) {
-	warning("compValues - %d %c %d", var1, oper & 0xFF, var2);
+	debugC(1, kDebugScript, "compValues(%d, %c, %d)", var1, oper, var2);
 	switch (oper & 0xFF) {
 	case '<':
 		return (var1 < var2);
@@ -558,7 +563,49 @@ byte LilliputScript::compValues(byte var1, int oper, int var2) {
 	}
 }
 
+int LilliputScript::getValue2() {
+	debugC(1, kDebugScript, "getValue2()");
+	int curWord = _currScript->readUint16LE();
+	int tmpVal = curWord >> 8;
+	switch(tmpVal) {
+	case 0xFF:
+		assert((_vm->_rulesBuffer2PrevIndx >= 0) && (_vm->_rulesBuffer2PrevIndx < 40));
+		return ((_vm->_rulesBuffer2_13[_vm->_rulesBuffer2PrevIndx] << 8) + _vm->_rulesBuffer2_14[_vm->_rulesBuffer2PrevIndx]);
+	case 0xFE: {
+		int index = curWord & 0xFF;
+		assert((index >= 0) && (index < 40));
+		return ((_vm->_rulesBuffer2_13[index] << 8) + _vm->_rulesBuffer2_14[index]);
+		}
+	case 0xFD:
+		return _vm->_word16EFA;
+	case 0xFC:
+		warning("TODO: getValue2 - 0xFC");
+		return 0;
+	case 0xFB:
+		warning("TODO: getValue2 - 0xFB");
+		return 0;
+	case 0xFA:
+		return ((_vm->_byte10999[_vm->_rulesBuffer2PrevIndx] << 8) + _vm->_byte109C1[_vm->_rulesBuffer2PrevIndx]);
+	case 0xF9:
+		return ((_vm->_rulesBuffer2_15[4] << 8) + _vm->_rulesBuffer2_15[5]);
+	case 0xF8: {
+		int index = curWord & 0xFF;
+		assert((index >= 0) && (index < 40));
+		return _vm->_rulesBuffer12_3[index];
+		}
+	case 0xF7:
+		warning("TODO: getValue2 - 0xF7");
+		return 0;
+	case 0xF6:
+		return _vm->_mouse_savedMousePosDivided;
+	default:
+		warning("getValue2 - 0x%x - Unexpected high value %d", tmpVal, curWord);
+		return curWord;
+	}
+}
+
 int LilliputScript::getValue1() {
+	debugC(1, kDebugScript, "getValue1()");
 	int curWord = _currScript->readUint16LE();
 	if (curWord < 1000)
 		return curWord;
@@ -581,6 +628,7 @@ int LilliputScript::getValue1() {
 }
 
 byte *LilliputScript::getBuffer215Ptr() {
+	debugC(1, kDebugScript, "getBuffer215Ptr()");
 	int tmpVal = getValue1();
 	tmpVal *= 32;
 	tmpVal += _currScript->readUint16LE();
@@ -603,6 +651,8 @@ byte LilliputScript::OC_sub1740A() {
 }
 
 byte LilliputScript::OC_sub17434() {
+	debugC(1, kDebugScript, "OC_sub17434()");
+
 	byte *tmpArr = getBuffer215Ptr();
 	byte var1 = tmpArr[0];
 	uint16 oper = _currScript->readUint16LE();
@@ -1004,9 +1054,16 @@ void LilliputScript::OC_unkPaletteFunction_1() {
 void LilliputScript::OC_unkPaletteFunction_2() {
 	warning("OC_unkPaletteFunction_2");
 }
+
 void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
-	warning("OC_loadAndDisplayCUBESx_GFX");
+	debugC(1, kDebugScript, "OC_loadAndDisplayCUBESx_GFX()");
+
+	int curWord = _currScript->readUint16LE();
+	assert((curWord >= 0) && (curWord <= 9));
+	Common::String fileName = Common::String::format("CUBES%d.GFX", curWord);
+	warning("TODO: load %s then display things", fileName.c_str());
 }
+
 void LilliputScript::OC_sub1834C() {
 	warning("OC_sub1834C");
 }
@@ -1047,6 +1104,8 @@ void LilliputScript::OC_sub1847F() {
 	warning("OC_sub1847F");
 }
 void LilliputScript::OC_displayVGAFile() {
+	debugC(1, kDebugScript, "OC_displayVGAFile()");
+
 	_byte12A09 = 1;
 	warning("TODO: unkPaletteFunction_1");
 	int curWord = _currScript->readUint16LE();
@@ -1060,6 +1119,8 @@ void LilliputScript::OC_sub184D7() {
 	warning("OC_sub184D7");
 }
 void LilliputScript::OC_sub184F5() {
+	debugC(1, kDebugScript, "OC_sub184F5()");
+
 	_vm->_byte184F4 = (_currScript->readUint16LE() & 0xFF);
 	_vm->_sound_byte16F06 = _vm->_byte184F4;
 	// TODO: use a separated function when properly identified
@@ -1098,7 +1159,8 @@ void LilliputScript::OC_sub1864D() {
 	warning("OC_sub1864D");
 }
 void LilliputScript::OC_initArr18560() {
-	warning("OC_initArr18560");
+	debugC(1, kDebugScript, "OC_initArr18560()");
+
 	int curWord = _currScript->readUint16LE();
 	assert (curWord < 4);
 	_vm->_arr18560[curWord]._field0 = 1;
@@ -1122,9 +1184,15 @@ void LilliputScript::OC_sub186A1() {
 void LilliputScript::OC_sub186E5_snd() {
 	warning("OC_sub186E5_snd");
 }
+
 void LilliputScript::OC_sub1870A_snd() {
-	warning("OC_sub1870A_snd");
+	debugC(1, kDebugScript, "OC_sub1870A_snd()");
+
+	int tmpVal = getValue2();
+	int curWord = _currScript->readUint16LE();
+	warning("TODO: call sound function #2");
 }
+
 void LilliputScript::OC_sub18725_snd() {
 	warning("OC_sub18725_snd");
 }
@@ -1135,7 +1203,8 @@ void LilliputScript::OC_sub1873F_snd() {
 	warning("OC_sub1873F_snd");
 }
 void LilliputScript::OC_sub18746_snd() {
-	warning("OC_sub18746_snd");
+	debugC(1, kDebugScript, "OC_sub18746_snd()");
+
 	int curWord = _currScript->readUint16LE();
 	curWord = (2 << 8) + (curWord & 0xFF);
 	warning("TODO: ovlContentOVL Function 2, init DX and BX");
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 8a0793e..d5610ba 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -52,6 +52,8 @@ private:
 	void handleOpcodeType2(int curWord);
 
 	int getValue1();
+	int getValue2();
+
 	byte *getBuffer215Ptr();
 	byte compValues(byte var1, int oper, int var2);
 


Commit: 629b142206e149f563ebc31f142492bebc35240d
    https://github.com/scummvm/scummvm/commit/629b142206e149f563ebc31f142492bebc35240d
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement some more opcodes

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 5c1bdcf..0bce13e 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -28,8 +28,20 @@ namespace Lilliput {
 
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 	_byte129A0 = 0xFF;
+	_byte16F08 = 0;
+
 	_word16F00 = -1;
+	_word10802 = -1;
 	_word10804 = 0;
+	_word15FFB = 0;
+	_word15FFD = 0;
+
+	_savedBuffer215Ptr = NULL;
+
+	for (int i = 0; i < 20; i++) {
+		_array122E9[i] = 0;
+		_array122FD[i] = 0;
+	}
 }
 
 LilliputScript::~LilliputScript() {
@@ -563,6 +575,29 @@ byte LilliputScript::compValues(byte var1, int oper, int var2) {
 	}
 }
 
+int LilliputScript::getValue1() {
+	debugC(1, kDebugScript, "getValue1()");
+	int curWord = _currScript->readUint16LE();
+	if (curWord < 1000)
+		return curWord;
+
+	switch (curWord) {
+	case 1000:
+		return (int)_byte129A0;
+	case 1001:
+		return _vm->_rulesBuffer2PrevIndx;
+	case 1002:
+		return _word16F00;
+	case 1003:
+		return (int)_vm->_rulesBuffer2_15[6];
+	case 1004:
+		return _word10804;
+	default:
+		warning("getValue1: Unexpected large value %d", curWord);
+		return curWord;
+	}
+}
+
 int LilliputScript::getValue2() {
 	debugC(1, kDebugScript, "getValue2()");
 	int curWord = _currScript->readUint16LE();
@@ -599,31 +634,16 @@ int LilliputScript::getValue2() {
 	case 0xF6:
 		return _vm->_mouse_savedMousePosDivided;
 	default:
-		warning("getValue2 - 0x%x - Unexpected high value %d", tmpVal, curWord);
+		warning("getValue2 - 0x%x - High value %d", tmpVal, curWord);
 		return curWord;
 	}
 }
 
-int LilliputScript::getValue1() {
-	debugC(1, kDebugScript, "getValue1()");
-	int curWord = _currScript->readUint16LE();
-	if (curWord < 1000)
-		return curWord;
-
-	switch (curWord) {
-	case 1000:
-		return (int)_byte129A0;
-	case 1001:
-		return _vm->_rulesBuffer2PrevIndx;
-	case 1002:
-		return _word16F00;
-	case 1003:
-		return (int)_vm->_rulesBuffer2_15[6];
-	case 1004:
-		return _word10804;
-	default:
-		warning("getValue1: Unexpected large value %d", curWord);
-		return curWord;
+void LilliputScript::sub130B6() {
+	assert(_vm->_word12F68_ERULES <= 20);
+	for (int i = 0; i < _vm->_word12F68_ERULES; i++) {
+		if (_array122E9[i] == 3)
+			_array122E9[i] = 2;
 	}
 }
 
@@ -926,7 +946,9 @@ void LilliputScript::OC_sub17AEE() {
 	warning("OC_sub17AEE");
 }
 void LilliputScript::OC_setWord10804() {
-	warning("OC_setWord10804");
+	debugC(1, kDebugScript, "OC_setWord10804()");
+
+	_word10804 = getValue1();
 }
 void LilliputScript::OC_sub17C0E() {
 	warning("OC_sub17C0E");
@@ -1019,7 +1041,17 @@ void LilliputScript::OC_sub1808B() {
 	warning("OC_sub1808B");
 }
 void LilliputScript::OC_sub18099() {
-	warning("OC_sub18099");
+	debugC(1, kDebugScript, "OC_sub18099()");
+
+	int index = _currScript->readUint16LE();
+	assert((index >= 0) && (index < 20));
+	int curWord = _currScript->readUint16LE();
+
+	_array122E9[index] = (curWord & 0xFF);
+	_array122FD[index] = (curWord >> 8);
+
+	warning("TODO: display function #8");
+	
 }
 void LilliputScript::OC_sub180C3() {
 	warning("OC_sub180C3");
@@ -1101,7 +1133,21 @@ void LilliputScript::OC_sub1844A() {
 	warning("OC_sub1844A");
 }
 void LilliputScript::OC_sub1847F() {
-	warning("OC_sub1847F");
+	debugC(1, kDebugScript, "OC_sub1847F()");
+	byte *buf215Ptr = getBuffer215Ptr();
+	byte tmpVal = buf215Ptr[0];
+	int curWord = _currScript->readUint16LE();
+	assert(curWord != 0);
+	int var1 = tmpVal / curWord;
+	int var2 = _currScript->readUint16LE();
+	int var3 = _currScript->readUint16LE();
+
+	if (_byte16F08 != 1) {
+		warning("TODO: OC_sub1847F - Display Function 5");
+		warning("TODO: OC_sub1847F - sub_18BE6");
+		warning("TODO: OC_sub1847F - Display Function 4");
+	}
+
 }
 void LilliputScript::OC_displayVGAFile() {
 	debugC(1, kDebugScript, "OC_displayVGAFile()");
@@ -1152,9 +1198,20 @@ void LilliputScript::OC_sub184F5() {
 	
 	_vm->_mouse_byte1299A = 0;
 }
+
 void LilliputScript::OC_sub1853B() {
-	warning("OC_sub1853B");
+	debugC(1, kDebugScript, "OC_initArr1853B()");
+
+	warning("TODO: unkPaletteFunction_1");
+	_byte16F08 = 0;
+	_byte15FFA = 0;
+	sub130B6();
+	warning("TODO: Display function sub15CBC();");
+	warning("TODO: unkPaletteFunction_2");
+	_byte12A09 = 0;
+	warning("TODO: call sound function #5");
 }
+
 void LilliputScript::OC_sub1864D() {
 	warning("OC_sub1864D");
 }
@@ -1170,13 +1227,18 @@ void LilliputScript::OC_initArr18560() {
 		_vm->_arr18560[curWord]._field5[i] = _currScript->readUint16LE();
 }
 void LilliputScript::OC_sub18678() {
-	warning("OC_sub18678");
+	debugC(1, kDebugScript, "OC_initArr18578()");
+	_savedBuffer215Ptr = getBuffer215Ptr();
+	_word15FFB = _currScript->readUint16LE();
+	_word15FFD = _currScript->readUint16LE();
 }
 void LilliputScript::OC_sub18690() {
 	warning("OC_sub18690");
 }
 void LilliputScript::OC_setWord10802() {
-	warning("OC_setWord10802");
+	debugC(1, kDebugScript, "OC_setWord10802()");
+
+	_word10802 = getValue1();
 }
 void LilliputScript::OC_sub186A1() {
 	warning("OC_sub186A1");
@@ -1188,8 +1250,9 @@ void LilliputScript::OC_sub186E5_snd() {
 void LilliputScript::OC_sub1870A_snd() {
 	debugC(1, kDebugScript, "OC_sub1870A_snd()");
 
-	int tmpVal = getValue2();
-	int curWord = _currScript->readUint16LE();
+	int var3 = getValue2();
+	// TODO: int var2 = ...
+	int var1 = (_currScript->readUint16LE() & 0xFF);
 	warning("TODO: call sound function #2");
 }
 
@@ -1210,7 +1273,8 @@ void LilliputScript::OC_sub18746_snd() {
 	warning("TODO: ovlContentOVL Function 2, init DX and BX");
 }
 void LilliputScript::OC_sub1875D_snd() {
-	warning("OC_sub1875D_snd");
+	debugC(1, kDebugScript, "OC_sub1875D_snd()");
+	warning("TODO: ovlContentOVL Function 6");
 }
 void LilliputScript::OC_sub18764() {
 	warning("OC_sub18764");
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index d5610ba..f425c71 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -42,10 +42,19 @@ private:
 	byte _byte16F05_ScriptHandler;
 	byte _byte12A09;
 	byte _byte129A0;
+	byte _byte16F08;
+	byte _byte15FFA;
+
+	byte *_savedBuffer215Ptr;
+	byte _array122E9[20];
+	byte _array122FD[20];
 
 	int16 _word1881B;
 	int16 _word16F00;
+	int16 _word10802;
 	int16 _word10804;
+	int16 _word15FFB;
+	int16 _word15FFD;
 
 	int handleOpcode(Common::MemoryReadStream *script);
 	byte handleOpcodeType1(int curWord);
@@ -54,6 +63,8 @@ private:
 	int getValue1();
 	int getValue2();
 
+	void sub130B6();
+
 	byte *getBuffer215Ptr();
 	byte compValues(byte var1, int oper, int var2);
 


Commit: 07f7ddde0f343fc13dbdf52f74519cd96a8f0e37
    https://github.com/scummvm/scummvm/commit/07f7ddde0f343fc13dbdf52f74519cd96a8f0e37
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement 4 more opcodes

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index cb3af63..a35f252 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -51,6 +51,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
 
+	_saveFlag = false;
+
 	for (int i = 0; i < 40; i++) {
 		_byte10999[i] = 0;
 		_byte109C1[i] = 0;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index a908dd0..e6cbe33 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -96,6 +96,8 @@ public:
 	byte *_bufferIdeogram;
 	byte _buffer10[4032];
 	byte _palette[768];
+
+	bool _saveFlag;
 	
 	int _word10800_ERULES;
 	int _word10807_ERULES;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 0bce13e..fead98c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -42,6 +42,10 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array122E9[i] = 0;
 		_array122FD[i] = 0;
 	}
+
+	for (int i = 0; i < 40; i++) {
+		_array10B29[i] = 1;
+	}
 }
 
 LilliputScript::~LilliputScript() {
@@ -562,8 +566,8 @@ void LilliputScript::runScript(Common::MemoryReadStream script) {
 		;
 }
 
-byte LilliputScript::compValues(byte var1, int oper, int var2) {
-	debugC(1, kDebugScript, "compValues(%d, %c, %d)", var1, oper, var2);
+byte LilliputScript::compareValues(byte var1, int oper, int var2) {
+	debugC(2, kDebugScript, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
 	switch (oper & 0xFF) {
 	case '<':
 		return (var1 < var2);
@@ -575,6 +579,64 @@ byte LilliputScript::compValues(byte var1, int oper, int var2) {
 	}
 }
 
+void LilliputScript::computeOperation(byte *bufPtr, int oper, int var2) {
+	debugC(1, kDebugScript, "computeOperation(bufPtr, %c, %d)", oper & 0xFF, var2 & 0xFF);
+
+	switch (oper & 0xFF) {
+	case '=':
+		bufPtr[0] = var2 & 0xFF;
+		break;
+	case '+': {
+		int tmpVal = bufPtr[0] + var2;
+		if (tmpVal > 0xFF)
+			bufPtr[0] = 0xFF;
+		else
+			bufPtr[0] = (byte)tmpVal;
+		}
+		break;
+	case '-': {
+		int tmpVal = bufPtr[0] - var2;
+		if (tmpVal < 0)
+			bufPtr[0] = 0;
+		else
+			bufPtr[0] = (byte)tmpVal;
+		}
+		break;
+	case '*': {
+		int tmpVal = bufPtr[0] * var2;
+		bufPtr[0] = tmpVal & 0xFF;
+		}
+		break;
+	case '/': {
+		if (var2 != 0)
+			bufPtr[0] /= var2;
+		}
+		break;
+	default: {
+		warning("computeOperation : oper %d", oper);
+		if (var2 != 0) {
+			byte tmpVal = bufPtr[0] / var2;
+			if (tmpVal < 0)
+				bufPtr[0] = 0xFF;
+			else 
+				bufPtr[0] = 0;
+		}
+		break;
+		}
+	}
+}
+
+void LilliputScript::sub1823E(byte var1, byte var2, byte *curBufPtr) {
+	debugC(1, kDebugScript, "sub1823E(%d, %d, curBufPtr)", var1, var2);
+
+	assert ((var1 >= 0) && (var1 < 40));
+	_array10B29[var1] = 0;
+	curBufPtr[0] = var2;
+	curBufPtr[1] = 0;
+	curBufPtr[2] = 0;
+	curBufPtr[3] = 0;
+}
+
 int LilliputScript::getValue1() {
 	debugC(1, kDebugScript, "getValue1()");
 	int curWord = _currScript->readUint16LE();
@@ -640,6 +702,7 @@ int LilliputScript::getValue2() {
 }
 
 void LilliputScript::sub130B6() {
+	debugC(1, kDebugScript, "sub130B6()");
 	assert(_vm->_word12F68_ERULES <= 20);
 	for (int i = 0; i < _vm->_word12F68_ERULES; i++) {
 		if (_array122E9[i] == 3)
@@ -648,7 +711,7 @@ void LilliputScript::sub130B6() {
 }
 
 byte *LilliputScript::getBuffer215Ptr() {
-	debugC(1, kDebugScript, "getBuffer215Ptr()");
+	debugC(2, kDebugScript, "getBuffer215Ptr()");
 	int tmpVal = getValue1();
 	tmpVal *= 32;
 	tmpVal += _currScript->readUint16LE();
@@ -678,7 +741,7 @@ byte LilliputScript::OC_sub17434() {
 	uint16 oper = _currScript->readUint16LE();
 	int16 var2 = _currScript->readUint16LE();
 
-	return compValues(var1, oper, var2);
+	return compareValues(var1, oper, var2);
 }
 
 byte LilliputScript::OC_sub17468() {
@@ -699,9 +762,14 @@ byte LilliputScript::OC_compWord18776() {
 	return 0;
 }
 byte LilliputScript::OC_checkSaveFlag() {
-	warning("OC_checkSaveFlag");
+	debugC(1, kDebugScript, "OC_checkSaveFlag()");
+
+	if (_vm->_saveFlag)
+		return 1;
+
 	return 0;
 }
+
 byte LilliputScript::OC_sub174C8() {
 	warning("OC_sub174C8");
 	return 0;
@@ -892,7 +960,13 @@ void LilliputScript::OC_sub17E15() {
 	warning("OC_sub17E15");
 }
 void LilliputScript::OC_sub17B03() {
-	warning("OC_sub17B03");
+	debugC(1, kDebugScript, "OC_sub17B03()");
+
+	byte *bufPtr = getBuffer215Ptr();
+	int oper = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+
+	computeOperation(bufPtr, oper, var2);
 }
 void LilliputScript::OC_getRandom_type2() {
 	warning("OC_getRandom_type2");
@@ -1106,8 +1180,14 @@ void LilliputScript::OC_sub18367() {
 	warning("OC_sub18367");
 }
 void LilliputScript::OC_sub17D04() {
-	warning("OC_sub17D04");
+	debugC(1, kDebugScript, "OC_sub17D04()");
+
+	byte var1 = getValue1();
+	byte var2 = _currScript->readUint16LE() & 0xFF;
+	
+	sub1823E(var1, var2, &_vm->_rulesBuffer2_15[var1]);
 }
+
 void LilliputScript::OC_sub18387() {
 	warning("OC_sub18387");
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index f425c71..9ae89cc 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -48,6 +48,7 @@ private:
 	byte *_savedBuffer215Ptr;
 	byte _array122E9[20];
 	byte _array122FD[20];
+	byte _array10B29[40];
 
 	int16 _word1881B;
 	int16 _word16F00;
@@ -60,13 +61,16 @@ private:
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 
+	void sub1823E(byte var1, byte var2, byte *curBufPtr);
+
 	int getValue1();
 	int getValue2();
 
 	void sub130B6();
 
 	byte *getBuffer215Ptr();
-	byte compValues(byte var1, int oper, int var2);
+	byte compareValues(byte var1, int oper, int var2);
+	void computeOperation(byte *bufPtr, int oper, int var2);
 
 	//Opcodes Type 1
 	byte OC_sub173DF();


Commit: a2fc07a702d28c7a5fe398f8888af5a639c5c64a
    https://github.com/scummvm/scummvm/commit/a2fc07a702d28c7a5fe398f8888af5a639c5c64a
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Complete function getValue2()

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index fead98c..372fd0f 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -675,12 +675,22 @@ int LilliputScript::getValue2() {
 		}
 	case 0xFD:
 		return _vm->_word16EFA;
-	case 0xFC:
-		warning("TODO: getValue2 - 0xFC");
-		return 0;
-	case 0xFB:
-		warning("TODO: getValue2 - 0xFB");
-		return 0;
+	case 0xFC: {
+		int index = curWord & 0xFF;
+		assert(index < 40);
+		byte var1 = _vm->_rulesBuffer2_1[index] >> 3;
+		byte var2 = _vm->_rulesBuffer2_2[index] >> 3;
+
+		return (var1 << 8) + var2;
+		}
+	case 0xFB: {
+		int index = _word16F00;
+		assert(index < 40);
+		byte var1 = _vm->_rulesBuffer2_1[index] >> 3;
+		byte var2 = _vm->_rulesBuffer2_2[index] >> 3;
+
+		return (var1 << 8) + var2;
+		}
 	case 0xFA:
 		return ((_vm->_byte10999[_vm->_rulesBuffer2PrevIndx] << 8) + _vm->_byte109C1[_vm->_rulesBuffer2PrevIndx]);
 	case 0xF9:
@@ -690,9 +700,14 @@ int LilliputScript::getValue2() {
 		assert((index >= 0) && (index < 40));
 		return _vm->_rulesBuffer12_3[index];
 		}
-	case 0xF7:
-		warning("TODO: getValue2 - 0xF7");
-		return 0;
+	case 0xF7: {
+		int index = _vm->_rulesBuffer2_15[6];
+		assert(index < 40);
+		byte var1 = _vm->_rulesBuffer2_1[index] >> 3;
+		byte var2 = _vm->_rulesBuffer2_2[index] >> 3;
+
+		return (var1 << 8) + var2;
+		}
 	case 0xF6:
 		return _vm->_mouse_savedMousePosDivided;
 	default:


Commit: 2acfb7e2b30a84ceb46dd6c86ec5cfccbd4db333
    https://github.com/scummvm/scummvm/commit/2acfb7e2b30a84ceb46dd6c86ec5cfccbd4db333
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement some more opcodes, fix stupid bug in script parser termination check

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 372fd0f..16d834c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -29,12 +29,18 @@ namespace Lilliput {
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 	_byte129A0 = 0xFF;
 	_byte16F08 = 0;
+	_byte1855D = 0;
+	_byte12A04 = 0;
+	_byte10806 = 0;
 
+	_word1855E = 0;
 	_word16F00 = -1;
 	_word10802 = -1;
 	_word10804 = 0;
 	_word15FFB = 0;
 	_word15FFD = 0;
+	_word12A00 = 0;
+	_word12A02 = 0;
 
 	_savedBuffer215Ptr = NULL;
 
@@ -45,6 +51,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 
 	for (int i = 0; i < 40; i++) {
 		_array10B29[i] = 1;
+		_array128EF[i] = 15;
 	}
 }
 
@@ -530,7 +537,7 @@ int LilliputScript::handleOpcode(Common::MemoryReadStream *script) {
 	_currScript = script;
 	uint16 curWord = _currScript->readUint16LE();
 	if (curWord == 0xFFF6)
-		return -1;
+		return 0xFF;
 
 	for (; curWord != 0xFFF8; curWord = _currScript->readUint16LE()) {
 		byte mask = 0; 
@@ -566,6 +573,14 @@ void LilliputScript::runScript(Common::MemoryReadStream script) {
 		;
 }
 
+void LilliputScript::sub185ED(byte index, byte subIndex) {
+	debugC(2, kDebugScript, "sub185ED");
+	if (_vm->_arr18560[index]._field0 != 1)
+		return;
+
+	warning("TODO: display function #1");
+}
+
 byte LilliputScript::compareValues(byte var1, int oper, int var2) {
 	debugC(2, kDebugScript, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
 	switch (oper & 0xFF) {
@@ -626,6 +641,27 @@ void LilliputScript::computeOperation(byte *bufPtr, int oper, int var2) {
 	}
 }
 
+void LilliputScript::sub185B4_display() {
+	if (_byte12A04 == _byte1855D)
+		return;
+
+	_byte1855D = _byte12A04;
+	
+	assert(_word1855E < 8);
+	int subIndex = _word1855E;
+	sub185ED(0, subIndex);
+	sub185ED(1, subIndex);
+	sub185ED(2, subIndex);
+	sub185ED(3, subIndex);
+
+	// In the original, increment by 2 as it's an array of words
+	++subIndex;
+	if (subIndex == 8)
+		subIndex = 0;
+
+	_word1855E = subIndex;
+}
+
 void LilliputScript::sub1823E(byte var1, byte var2, byte *curBufPtr) {
 	debugC(1, kDebugScript, "sub1823E(%d, %d, curBufPtr)", var1, var2);
 
@@ -638,7 +674,7 @@ void LilliputScript::sub1823E(byte var1, byte var2, byte *curBufPtr) {
 }
 
 int LilliputScript::getValue1() {
-	debugC(1, kDebugScript, "getValue1()");
+	debugC(2, kDebugScript, "getValue1()");
 	int curWord = _currScript->readUint16LE();
 	if (curWord < 1000)
 		return curWord;
@@ -661,7 +697,8 @@ int LilliputScript::getValue1() {
 }
 
 int LilliputScript::getValue2() {
-	debugC(1, kDebugScript, "getValue2()");
+	debugC(2, kDebugScript, "getValue2()");
+
 	int curWord = _currScript->readUint16LE();
 	int tmpVal = curWord >> 8;
 	switch(tmpVal) {
@@ -1182,6 +1219,7 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 	int curWord = _currScript->readUint16LE();
 	assert((curWord >= 0) && (curWord <= 9));
 	Common::String fileName = Common::String::format("CUBES%d.GFX", curWord);
+	_byte10806 = curWord + 0x30;
 	warning("TODO: load %s then display things", fileName.c_str());
 }
 
@@ -1271,12 +1309,12 @@ void LilliputScript::OC_sub184F5() {
 	_vm->_mouse_byte1299A = 0;
 	_vm->_byte16F09 = 0;
 
-	// TODO: Remove when the sound is hooked
-	_vm->_sound_byte16F06 = 0;
+	// TODO: Remove when the sound and the events are hooked
+	_vm->_mouse_byte1299A = 1;
 	//
 
 	for (;;) {
-		warning("TODO: display function sub_185B4();");
+		sub185B4_display();
 
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
 			_vm->_byte16F09 = _vm->_keyboard_getch();
@@ -1310,6 +1348,7 @@ void LilliputScript::OC_sub1853B() {
 void LilliputScript::OC_sub1864D() {
 	warning("OC_sub1864D");
 }
+
 void LilliputScript::OC_initArr18560() {
 	debugC(1, kDebugScript, "OC_initArr18560()");
 
@@ -1318,9 +1357,11 @@ void LilliputScript::OC_initArr18560() {
 	_vm->_arr18560[curWord]._field0 = 1;
 	_vm->_arr18560[curWord]._field1 = _currScript->readUint16LE();
 	_vm->_arr18560[curWord]._field3 = _currScript->readUint16LE();
+
 	for (int i = 0; i < 8; i++)
 		_vm->_arr18560[curWord]._field5[i] = _currScript->readUint16LE();
 }
+
 void LilliputScript::OC_sub18678() {
 	debugC(1, kDebugScript, "OC_initArr18578()");
 	_savedBuffer215Ptr = getBuffer215Ptr();
@@ -1346,32 +1387,55 @@ void LilliputScript::OC_sub1870A_snd() {
 	debugC(1, kDebugScript, "OC_sub1870A_snd()");
 
 	int var3 = getValue2();
-	// TODO: int var2 = ...
+	int var4 = var3;
+	int var2 = (_word12A00 << 8) + _word12A02;
 	int var1 = (_currScript->readUint16LE() & 0xFF);
-	warning("TODO: call sound function #2");
+	warning("TODO: ovlContentOVL Function 2");
 }
 
 void LilliputScript::OC_sub18725_snd() {
-	warning("OC_sub18725_snd");
+	debugC(1, kDebugScript, "OC_sub18725_snd()");
+
+	int var4 = getValue1() | 0xFF00;
+	warning("TODO: ovlContentOVL Function 3");
 }
+
 void LilliputScript::OC_sub18733_snd() {
-	warning("OC_sub18733_snd");
+	debugC(1, kDebugScript, "OC_sub18733_snd()");
+
+	int var4 = getValue2();
+	warning("TODO: ovlContentOVL Function 3");
 }
+
 void LilliputScript::OC_sub1873F_snd() {
-	warning("OC_sub1873F_snd");
+	debugC(1, kDebugScript, "OC_sub1873F_snd()");
+
+	warning("TODO: ovlContentOVL Function 4");
 }
+
 void LilliputScript::OC_sub18746_snd() {
 	debugC(1, kDebugScript, "OC_sub18746_snd()");
 
-	int curWord = _currScript->readUint16LE();
-	curWord = (2 << 8) + (curWord & 0xFF);
-	warning("TODO: ovlContentOVL Function 2, init DX and BX");
+	int var4 = -1;
+	int var2 = (_word12A00 << 8) + _word12A02;
+	int var1 = _currScript->readUint16LE() & 0xFF;
+	warning("TODO: ovlContentOVL Function 2");
 }
+
 void LilliputScript::OC_sub1875D_snd() {
 	debugC(1, kDebugScript, "OC_sub1875D_snd()");
+
 	warning("TODO: ovlContentOVL Function 6");
 }
+
 void LilliputScript::OC_sub18764() {
-	warning("OC_sub18764");
+	debugC(1, kDebugScript, "OC_sub18764()");
+
+	int index = getValue1();
+	int var1 = _currScript->readUint16LE();
+
+	assert(index < 40);
+	_array128EF[index] = var1 & 0xFF;
 }
+
 } // End of namespace
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 9ae89cc..aff8ca0 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -41,14 +41,18 @@ private:
 
 	byte _byte16F05_ScriptHandler;
 	byte _byte12A09;
+	byte _byte12A04;
 	byte _byte129A0;
 	byte _byte16F08;
 	byte _byte15FFA;
+	byte _byte1855D;
+	byte _byte10806;
 
 	byte *_savedBuffer215Ptr;
 	byte _array122E9[20];
 	byte _array122FD[20];
 	byte _array10B29[40];
+	byte _array128EF[40];
 
 	int16 _word1881B;
 	int16 _word16F00;
@@ -56,11 +60,16 @@ private:
 	int16 _word10804;
 	int16 _word15FFB;
 	int16 _word15FFD;
+	int16 _word12A00;
+	int16 _word12A02;
+	int16 _word1855E;
 
 	int handleOpcode(Common::MemoryReadStream *script);
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 
+	void sub185ED(byte index, byte subIndex);
+	void sub185B4_display();
 	void sub1823E(byte var1, byte var2, byte *curBufPtr);
 
 	int getValue1();


Commit: 4ed7a101558cdd73e6b51132f19708bcd9251dd6
    https://github.com/scummvm/scummvm/commit/4ed7a101558cdd73e6b51132f19708bcd9251dd6
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add default palette, and palette fixup (thanks to SylvainTV for the help)

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index a35f252..a1d9cce 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -36,6 +36,72 @@
 namespace Lilliput {
 
 LilliputEngine *LilliputEngine::s_Engine = 0;
+static const byte _basisPalette[768] = {
+	0,  0,  0,  0,  0,  42, 0,  42, 0,  0,  42, 42,
+	42, 0,  0,  42, 0,  42, 42, 21, 0,  42, 42, 42,
+	21, 21, 21, 21, 21, 63, 21, 63, 21, 21, 63, 63,
+	63, 21, 21, 63, 21, 63, 63, 63, 21, 63, 63, 63,
+	63, 63, 63, 59, 59, 59, 54, 54, 54, 50, 50, 50,
+	46, 46, 46, 42, 42, 42, 38, 38, 38, 33, 33, 33,
+	29, 29, 29, 25, 25, 25, 21, 21, 21, 17, 17, 17,
+	13, 13, 13, 8,  8,  8,  4,  4,  4,  0,  0,  0,
+	63, 54, 54, 63, 46, 46, 63, 39, 39, 63, 31, 31,
+	63, 23, 23, 63, 16, 16, 63, 8,  8,  63, 0,  0,
+	57, 0,  0,  51, 0,  0,  45, 0,  0,  39, 0,  0,
+	33, 0,  0,  28, 0,  0,  22, 0,  0,  16, 0,  0,
+	63, 58, 54, 63, 54, 46, 63, 50, 39, 63, 46, 31,
+	63, 42, 23, 63, 38, 16, 63, 34, 8,  63, 30, 0,
+	57, 27, 0,  51, 24, 0,  45, 21, 0,  39, 19, 0,
+	33, 16, 0,  28, 14, 0,  22, 11, 0,  16, 8,  0,
+	63, 63, 54, 63, 63, 46, 63, 63, 39, 63, 63, 31,
+	63, 62, 23, 63, 61, 16, 63, 61, 8,  63, 61, 0,
+	57, 54, 0,  51, 49, 0,  45, 43, 0,  39, 39, 0,
+	33, 33, 0,  28, 27, 0,  22, 21, 0,  16, 16, 0,
+	62, 63, 54, 59, 61, 47, 56, 59, 42, 53, 58, 36,
+	50, 56, 32, 47, 54, 26, 44, 52, 22, 41, 50, 17,
+	36, 46, 14, 32, 42, 11, 28, 37, 8,  24, 33, 6,
+	20, 29, 4,  16, 25, 2,  13, 20, 1,  10, 16, 0,
+	54, 63, 54, 48, 61, 48, 43, 59, 43, 38, 58, 38,
+	33, 56, 33, 29, 54, 29, 25, 52, 24, 21, 50, 20,
+	16, 46, 16, 14, 42, 13, 10, 37, 9,  8,  33, 7,
+	6,  29, 4,  4,  25, 2,  2,  20, 1,  1,  16, 0,
+	59, 63, 63, 53, 63, 63, 47, 62, 63, 41, 61, 62,
+	35, 60, 62, 30, 59, 62, 24, 57, 62, 18, 55, 62,
+	20, 52, 56, 15, 47, 50, 11, 42, 45, 8,  37, 39,
+	5,  32, 33, 3,  27, 27, 1,  22, 22, 0,  16, 16,
+	54, 59, 63, 46, 56, 63, 39, 53, 63, 31, 50, 63,
+	23, 47, 63, 16, 44, 63, 8,  42, 63, 0,  39, 63,
+	0,  35, 57, 0,  31, 51, 0,  27, 45, 0,  23, 39,
+	0,  19, 33, 0,  16, 28, 0,  12, 22, 0,  9,  16,
+	54, 54, 63, 46, 47, 63, 39, 39, 63, 31, 32, 63,
+	23, 24, 63, 16, 16, 63, 8,  9,  63, 0,  1,  63,
+	0,  1,  57, 0,  1,  51, 0,  0,  45, 0,  0,  39,
+	0,  0,  33, 0,  0,  28, 0,  0,  22, 0,  0,  16,
+	54, 63, 54, 47, 63, 46, 39, 63, 39, 32, 63, 31,
+	24, 63, 23, 16, 63, 16, 8,  63, 8,  0,  63, 0,
+	0,  56, 0,  0,  49, 0,  0,  43, 0,  0,  36, 0,
+	0,  30, 0,  0,  23, 0,  0,  16, 0,  0,  10, 0,
+	63, 54, 63, 63, 46, 63, 63, 39, 63, 63, 31, 63,
+	63, 23, 63, 63, 16, 63, 63, 8,  63, 63, 0,  63,
+	56, 0,  57, 50, 0,  51, 45, 0,  45, 39, 0,  39,
+	33, 0,  33, 27, 0,  28, 22, 0,  22, 16, 0,  16,
+	63, 58, 55, 63, 56, 52, 63, 54, 49, 63, 53, 47,
+	63, 51, 44, 63, 49, 41, 63, 47, 39, 63, 46, 36,
+	63, 44, 32, 63, 41, 28, 63, 39, 24, 60, 37, 23,
+	58, 35, 22, 55, 34, 21, 52, 32, 20, 50, 31, 19,
+	47, 30, 18, 45, 28, 17, 42, 26, 16, 40, 25, 15,
+	39, 24, 14, 36, 23, 13, 34, 22, 12, 32, 20, 11,
+	29, 19, 10, 27, 18, 9,  23, 16, 8,  21, 15, 7,
+	18, 14, 6,  16, 12, 6,  14, 11, 5,  10, 8,  3,
+	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
+	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
+	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
+	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
+	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
+	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
+	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
+	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63
+};
 
 LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) : Engine(syst), _gameDescription(gd)
 {
@@ -96,8 +162,11 @@ byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 	int remainingSize = f.size();
 	if (loadPal) {
 		for (int i = 0; i < 768; ++i)
-			_palette[i] = f.readByte();
+			_curPalette[i] = f.readByte();
+
 		remainingSize -= 768;
+		fixPaletteEntries(_curPalette, 256);
+		_system->getPaletteManager()->setPalette(_curPalette, 0, 256);
 	}
 
 	uint8 curByte;
@@ -309,14 +378,37 @@ void LilliputEngine::loadRules() {
 	// Skipped: Load Savegame
 }
 
+void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
+	// Color values are coded on 6bits ( for old 6bits DAC )
+	for (int32 i = 0; i < num * 3; i++) {
+		int32 a = palette[i];
+		assert(a < 64);
+
+		a =  (a << 2) | (a >> 4);
+		if (a > 255)
+			a = 255;
+		palette[i] = a;
+	}
+}
+
+void LilliputEngine::initPalette() {
+	for (int i = 0; i < 768; i++)
+		_curPalette[i] = _basisPalette[i];
+
+	fixPaletteEntries(_curPalette, 256);
+	_system->getPaletteManager()->setPalette(_curPalette, 0, 256);
+}
+
 Common::Error LilliputEngine::run() {
 	s_Engine = this;
 	initGraphics(320, 200);
+	_mainSurface = new Graphics::Surface();
+	_mainSurface->create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
 
 	// Setup mixer
 	syncSoundSettings();
 
-	// TODO: Init Palette
+	initPalette();
 
 	// Load files. In the original, the size was hardcoded
 	_bufferIdeogram = loadVGA("IDEOGRAM.VGA", false);
@@ -333,6 +425,7 @@ Common::Error LilliputEngine::run() {
 	_scriptHandler->runScript(Common::MemoryReadStream(_rulesScript, _rulesScript_size));
 
 	//TODO: Main loop
+
 	return Common::kNoError;
 }
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index e6cbe33..b73b539 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -23,11 +23,14 @@
 #ifndef LILLIPUT_LILLIPUT_H
 #define LILLIPUT_LILLIPUT_H
 
-#include "engines/engine.h"
-#include "common/file.h"
 #include "lilliput/console.h"
 #include "lilliput/script.h"
 
+#include "common/file.h"
+#include "engines/engine.h"
+#include "graphics/palette.h"
+#include "graphics/surface.h"
+
 namespace Common {
 class RandomSource;
 }
@@ -76,6 +79,7 @@ public:
 
 	Common::RandomSource *_rnd;
 	LilliputScript *_scriptHandler;
+	Graphics::Surface *_mainSurface;
 
 	struct18560 _arr18560[4];
 	byte _byte1714E;
@@ -95,7 +99,7 @@ public:
 	byte *_bufferIsoChars;
 	byte *_bufferIdeogram;
 	byte _buffer10[4032];
-	byte _palette[768];
+	byte _curPalette[768];
 
 	bool _saveFlag;
 	
@@ -159,6 +163,9 @@ public:
 	byte *loadRaw(Common::String filename);
 	void loadRules();
 
+	void initPalette();
+	void fixPaletteEntries(uint8 *palette, int num);
+
 	GameType getGameType() const;
 	Common::Platform getPlatform() const;
 


Commit: bda5b14cdca19910b015f7a00ab9e0c851e8db74
    https://github.com/scummvm/scummvm/commit/bda5b14cdca19910b015f7a00ab9e0c851e8db74
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Partially implement displayVGAFile(). Title is now displayed

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index a1d9cce..f68c920 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -378,6 +378,17 @@ void LilliputEngine::loadRules() {
 	// Skipped: Load Savegame
 }
 
+void LilliputEngine::displayVGAFile(Common::String fileName) {
+	warning("TODO: display function #4");
+
+	byte *buffer = loadVGA(fileName, true);
+	memcpy(_mainSurface->getPixels(), buffer, 320*200);
+	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
+	_system->updateScreen();
+
+	warning("TODO: display function #5");
+}
+
 void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
 	// Color values are coded on 6bits ( for old 6bits DAC )
 	for (int32 i = 0; i < num * 3; i++) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index b73b539..8eddeb8 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -163,6 +163,7 @@ public:
 	byte *loadRaw(Common::String filename);
 	void loadRules();
 
+	void displayVGAFile(Common::String fileName);
 	void initPalette();
 	void fixPaletteEntries(uint8 *palette, int num);
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 16d834c..6ab8b71 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1282,6 +1282,7 @@ void LilliputScript::OC_sub1847F() {
 	}
 
 }
+
 void LilliputScript::OC_displayVGAFile() {
 	debugC(1, kDebugScript, "OC_displayVGAFile()");
 
@@ -1291,7 +1292,7 @@ void LilliputScript::OC_displayVGAFile() {
 	int index = _vm->_rulesChunk3[curWord];
 	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
 	_word1881B = -1;
-	warning("TODO: guess_displayFunction_VGAFile(%s)", fileName.c_str());
+	_vm->displayVGAFile(fileName);
 	warning("TODO: unkPaletteFunction_2");
 }
 void LilliputScript::OC_sub184D7() {
@@ -1310,7 +1311,7 @@ void LilliputScript::OC_sub184F5() {
 	_vm->_byte16F09 = 0;
 
 	// TODO: Remove when the sound and the events are hooked
-	_vm->_mouse_byte1299A = 1;
+//	_vm->_mouse_byte1299A = 1;
 	//
 
 	for (;;) {


Commit: cabc7a375d2a3617a4059472e70cdb519b3900e2
    https://github.com/scummvm/scummvm/commit/cabc7a375d2a3617a4059472e70cdb519b3900e2
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add preliminar mouse handler

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index f68c920..7d1ff65 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -111,6 +111,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 
 	_console = new LilliputConsole(this);
 	_rnd = 0;
+	_mouseX = 0;
+	_mouseY = 0;
+	_mouseButton = 0;
 	_scriptHandler = new LilliputScript(this);
 
 	_byte1714E = 0;
@@ -153,6 +156,18 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
+void LilliputEngine::getMouseEvent() {
+	Common::EventManager *_event = _system->getEventManager();
+
+	Common::Event event;
+	while (_event->pollEvent(event) && !_shouldQuit)
+		;
+
+	_mouseX = _event->getMousePos().x;
+	_mouseY = _event->getMousePos().y;
+	_mouseButton = _event->getButtonState();
+}
+
 byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 	Common::File f;
 
@@ -445,6 +460,7 @@ void LilliputEngine::initialize() {
 
 	_rnd = new Common::RandomSource("robin");
 	_rnd->setSeed(42);                              // Kick random number generator
+	_shouldQuit = false;
 
 	for (int i = 0; i < 4; i++) {
 		_arr18560[i]._field0 = 0;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8eddeb8..92ef2fb 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -176,12 +176,19 @@ public:
 	Common::String getSavegameFilename(int slot);
 	void syncSoundSettings();
 
+	int _mouseX;
+	int _mouseY;
+	int _mouseButton;
+
+	void getMouseEvent();
+
 	// Temporary stubs
-	byte _mouse_byte1299A;
 	byte _mouse_savedMousePosDivided;
 	byte _keyboard_getch();
 
 protected:
+	Common::EventManager *_eventMan;
+	bool _shouldQuit;
 
 	// Engine APIs
 	Common::Error run();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 6ab8b71..7108f9d 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1307,30 +1307,26 @@ void LilliputScript::OC_sub184F5() {
 	_vm->_word12D3D = 0;
 	_vm->_word12D3F = 0;
 	//
-	_vm->_mouse_byte1299A = 0;
+	_vm->_mouseButton = 0;
 	_vm->_byte16F09 = 0;
 
-	// TODO: Remove when the sound and the events are hooked
-//	_vm->_mouse_byte1299A = 1;
-	//
-
 	for (;;) {
 		sub185B4_display();
-
+		_vm->getMouseEvent();
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
 			_vm->_byte16F09 = _vm->_keyboard_getch();
 			_vm->_keyboard_getch();
 			break;
 		}
 		
-		if (_vm->_mouse_byte1299A == 1)
+		if (_vm->_mouseButton & 1)
 			break;
 		
 		if ((_vm->_byte184F4 != 0) && (_vm->_sound_byte16F06 == 0))
 			break;
 	}
 	
-	_vm->_mouse_byte1299A = 0;
+	_vm->_mouseButton = 0;
 }
 
 void LilliputScript::OC_sub1853B() {


Commit: 47b9c1f6a7032c858a7ff1145d23493d03a40797
    https://github.com/scummvm/scummvm/commit/47b9c1f6a7032c858a7ff1145d23493d03a40797
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Modify event polling

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7d1ff65..d1cab05 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -23,11 +23,12 @@
 #include "common/system.h"
 #include "common/random.h"
 #include "common/error.h"
-#include "common/events.h"
 #include "common/debug-channels.h"
 #include "common/config-manager.h"
 #include "common/textconsole.h"
 #include "common/memstream.h"
+#include "common/events.h"
+#include "engines/util.h"
 
 #include "lilliput/lilliput.h"
 #include "engines/util.h"
@@ -156,16 +157,28 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
-void LilliputEngine::getMouseEvent() {
-	Common::EventManager *_event = _system->getEventManager();
-
+void LilliputEngine::pollEvent() {
 	Common::Event event;
-	while (_event->pollEvent(event) && !_shouldQuit)
-		;
-
-	_mouseX = _event->getMousePos().x;
-	_mouseY = _event->getMousePos().y;
-	_mouseButton = _event->getButtonState();
+	while (_system->getEventManager()->pollEvent(event)) {
+		switch (event.type) {
+		case Common::EVENT_MOUSEMOVE:
+			_mouseX = event.mouse.x;
+			_mouseY = event.mouse.y;
+			break;
+		case Common::EVENT_LBUTTONUP:
+			_mouseButton |= 1;
+			break;
+		case Common::EVENT_RBUTTONUP:
+			_mouseButton |= 2;
+			break;
+		case Common::EVENT_QUIT:
+			_shouldQuit = true;
+			break;
+		// TODO: handle keyboard
+		default:
+			break;
+		}
+	}
 }
 
 byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 92ef2fb..72839cc 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -105,8 +105,6 @@ public:
 	
 	int _word10800_ERULES;
 	int _word10807_ERULES;
-	int _word12D3D;
-	int _word12D3F;
 	int _word16EFA;
 
 	byte *_rulesChunk1;
@@ -180,7 +178,7 @@ public:
 	int _mouseY;
 	int _mouseButton;
 
-	void getMouseEvent();
+	void pollEvent();
 
 	// Temporary stubs
 	byte _mouse_savedMousePosDivided;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7108f9d..e93608e 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -476,7 +476,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub184D7();
 		break;
 	case 0x55:
-		OC_sub184F5();
+		OC_displayTitleScreen();
 		break;
 	case 0x56:
 		OC_sub1853B();
@@ -1298,21 +1298,22 @@ void LilliputScript::OC_displayVGAFile() {
 void LilliputScript::OC_sub184D7() {
 	warning("OC_sub184D7");
 }
-void LilliputScript::OC_sub184F5() {
-	debugC(1, kDebugScript, "OC_sub184F5()");
+void LilliputScript::OC_displayTitleScreen() {
+	debugC(1, kDebugScript, "OC_displayTitleScreen()");
 
 	_vm->_byte184F4 = (_currScript->readUint16LE() & 0xFF);
 	_vm->_sound_byte16F06 = _vm->_byte184F4;
-	// TODO: use a separated function when properly identified
-	_vm->_word12D3D = 0;
-	_vm->_word12D3F = 0;
+
+	// TODO: Rewrite keyboard handling (this code was in a separated function)
+	_vm->_keyboard_nextIndex = 0;
+	_vm->_keyboard_oldIndex = 0;
 	//
 	_vm->_mouseButton = 0;
 	_vm->_byte16F09 = 0;
 
 	for (;;) {
 		sub185B4_display();
-		_vm->getMouseEvent();
+		_vm->pollEvent();
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
 			_vm->_byte16F09 = _vm->_keyboard_getch();
 			_vm->_keyboard_getch();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index aff8ca0..75ab5ca 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -219,7 +219,7 @@ private:
 	void OC_sub1847F();
 	void OC_displayVGAFile();
 	void OC_sub184D7();
-	void OC_sub184F5();
+	void OC_displayTitleScreen();
 	void OC_sub1853B();
 	void OC_sub1864D();
 	void OC_initArr18560();


Commit: 0ee1ba07865bacc0823aeb618b44ba14522a89ab
    https://github.com/scummvm/scummvm/commit/0ee1ba07865bacc0823aeb618b44ba14522a89ab
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a bug in VGA file loading

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index d1cab05..f2e05bf 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -220,7 +220,7 @@ byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 			}
 		} else {
 			// Not compressed
-			int rawSize = (curByte & 0xF);
+			int rawSize = (curByte & 0xFF);
 			for (int i = 0; i < rawSize; ++i) {
 				decodeBuffer[size] = f.readByte();
 				--remainingSize;


Commit: a5271f541817506f33779bc57b76d564ab2773f4
    https://github.com/scummvm/scummvm/commit/a5271f541817506f33779bc57b76d564ab2773f4
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add preliminar menu support and main loop

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index f2e05bf..65ec0c9 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -115,13 +115,20 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_mouseX = 0;
 	_mouseY = 0;
 	_mouseButton = 0;
+	_savedMousePosDivided = 0xFFFF;
+
 	_scriptHandler = new LilliputScript(this);
 
 	_byte1714E = 0;
+	_byte12FCE = 0;
+	_byte129A0 = 0xFF;
+
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
+	_word10804 = 0;
 
 	_saveFlag = false;
+	_byte16F07_menuId = 0;
 
 	for (int i = 0; i < 40; i++) {
 		_byte10999[i] = 0;
@@ -158,6 +165,8 @@ Common::Platform LilliputEngine::getPlatform() const {
 }
 
 void LilliputEngine::pollEvent() {
+	debugC(2, kDebugEngine, "pollEvent()");
+
 	Common::Event event;
 	while (_system->getEventManager()->pollEvent(event)) {
 		switch (event.type) {
@@ -182,6 +191,8 @@ void LilliputEngine::pollEvent() {
 }
 
 byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
+	debugC(1, kDebugEngine, "loadVGA(%s, %d)", filename, (loadPal) ? 1 : 0);
+
 	Common::File f;
 
 	if (!f.open(filename))
@@ -191,8 +202,8 @@ byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 	if (loadPal) {
 		for (int i = 0; i < 768; ++i)
 			_curPalette[i] = f.readByte();
-
 		remainingSize -= 768;
+
 		fixPaletteEntries(_curPalette, 256);
 		_system->getPaletteManager()->setPalette(_curPalette, 0, 256);
 	}
@@ -237,6 +248,8 @@ byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 }
 
 byte *LilliputEngine::loadRaw(Common::String filename) {
+	debugC(1, kDebugEngine, "loadRaw(%s)", filename.c_str());
+
 	Common::File f;
 
 	if (!f.open(filename))
@@ -252,6 +265,8 @@ byte *LilliputEngine::loadRaw(Common::String filename) {
 }
 
 void LilliputEngine::loadRules() {
+	debugC(1, kDebugEngine, "loadRules()");
+
 	static const byte _rulesXlatArray[26] = {30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44};
 	Common::File f;
 	uint16 curWord;
@@ -317,16 +332,16 @@ void LilliputEngine::loadRules() {
 	// Chunk 5: Scripts
 	// Use byte instead of int, therefore multiply by two the size.
 	// This is for changing that into a memory read stream
-	_rulesScript_size = f.readUint16LE() * 2;
-	_rulesScript = (byte *)malloc(sizeof(byte) * _rulesScript_size);
-	for (int i = 0; i < _rulesScript_size; ++i)
-		_rulesScript[i] = f.readByte();
+	_initScript_size = f.readUint16LE() * 2;
+	_initScript = (byte *)malloc(sizeof(byte) * _initScript_size);
+	for (int i = 0; i < _initScript_size; ++i)
+		_initScript[i] = f.readByte();
 
 	// Chunk 6
-	_rulesChunk6_size = f.readUint16LE();
-	_rulesChunk6 = (int *)malloc(sizeof(int) * _rulesChunk6_size);
-	for (int i = 0; i < _rulesChunk6_size; ++i)
-		_rulesChunk6[i] = f.readUint16LE();
+	_menuScript_size = f.readUint16LE() * 2;
+	_menuScript = (byte *)malloc(sizeof(byte) * _menuScript_size);
+	for (int i = 0; i < _menuScript_size; ++i)
+		_menuScript[i] = f.readByte();
 
 	// Chunk 7 & 8
 	_rulesChunk7_size = f.readUint16LE();
@@ -407,6 +422,7 @@ void LilliputEngine::loadRules() {
 }
 
 void LilliputEngine::displayVGAFile(Common::String fileName) {
+	debugC(1, kDebugEngine, "displayVGAFile(%s)", fileName.c_str());
 	warning("TODO: display function #4");
 
 	byte *buffer = loadVGA(fileName, true);
@@ -418,6 +434,7 @@ void LilliputEngine::displayVGAFile(Common::String fileName) {
 }
 
 void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
+	debugC(1, kDebugEngine, "fixPaletteEntries(palette, %d)", num);
 	// Color values are coded on 6bits ( for old 6bits DAC )
 	for (int32 i = 0; i < num * 3; i++) {
 		int32 a = palette[i];
@@ -431,6 +448,8 @@ void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
 }
 
 void LilliputEngine::initPalette() {
+	debugC(1, kDebugEngine, "initPalette()");
+
 	for (int i = 0; i < 768; i++)
 		_curPalette[i] = _basisPalette[i];
 
@@ -438,8 +457,52 @@ void LilliputEngine::initPalette() {
 	_system->getPaletteManager()->setPalette(_curPalette, 0, 256);
 }
 
+void LilliputEngine::sub170EE(int index) {
+	debugC(1, kDebugEngine, "sub170EE(%d)", index);
+
+	_rulesBuffer2PrevIndx = index;
+
+	assert (index < 40);
+	int var2 = _rulesBuffer2_1[index];
+	int var4 = _rulesBuffer2_2[index];
+
+	_word16EFA = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF);
+	_ptr_rulesBuffer2_15 = &_rulesBuffer2_15[_rulesBuffer2PrevIndx * 32];
+}
+
+void LilliputEngine::sub130DD() {
+	warning("sub130DD()");
+}
+
+void LilliputEngine::handleMenu() {
+	debugC(1, kDebugEngine, "handleMenu()");
+
+	if (_byte16F07_menuId == 0)
+		return;
+
+	if ((_byte12FCE == 1) && (_byte16F07_menuId != 3))
+		return;
+
+	sub170EE(_word10804);
+	_scriptHandler->runMenuScript(Common::MemoryReadStream(_menuScript, _menuScript_size));
+	_savedMousePosDivided = 0xFFFF;
+	_byte129A0 = 0xFF;
+
+	if (_byte16F07_menuId == 3)
+		sub130DD();
+
+	_byte16F07_menuId = 0;
+}
+
+void LilliputEngine::sub17083() {
+	warning("sub17083");
+}
+
 Common::Error LilliputEngine::run() {
+	debugC(1, kDebugEngine, "run()");
+
 	s_Engine = this;
+	initialize();
 	initGraphics(320, 200);
 	_mainSurface = new Graphics::Surface();
 	_mainSurface->create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
@@ -456,14 +519,17 @@ Common::Error LilliputEngine::run() {
 	_bufferIsoChars = loadVGA("ISOCHARS.VGA", false);
 	_bufferIsoMap = loadRaw("ISOMAP.DTA");
 
-	//TODO: Init mouse handler
-
 	loadRules();
 
 	//TODO: Init sound/music player
-	_scriptHandler->runScript(Common::MemoryReadStream(_rulesScript, _rulesScript_size));
+	_scriptHandler->runScript(Common::MemoryReadStream(_initScript, _initScript_size));
 
-	//TODO: Main loop
+	while(!_shouldQuit) {
+		handleMenu();
+		sub17083();
+		// To be removed when handled in the previous fonctions
+		pollEvent();
+	}
 
 	return Common::kNoError;
 }
@@ -495,6 +561,7 @@ Common::String LilliputEngine::getSavegameFilename(int slot) {
 }
 
 byte LilliputEngine::_keyboard_getch() {
+	warning("getch()");
 	return ' ';
 }
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 72839cc..4d88d4b 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -124,14 +124,15 @@ public:
 	byte _rulesBuffer2_13[40];
 	byte _rulesBuffer2_14[40];
 	byte _rulesBuffer2_15[40 * 32];
+	byte *_ptr_rulesBuffer2_15;
 	byte _rulesBuffer2_16[40 * 32];
 	int *_rulesChunk3;
 	int _rulesChunk3_size;
 	byte *_rulesChunk4;
-	byte *_rulesScript;
-	int _rulesScript_size;
-	int *_rulesChunk6;
-	int _rulesChunk6_size;
+	byte *_initScript;
+	int _initScript_size;
+	byte *_menuScript;
+	int _menuScript_size;
 	int *_rulesChunk7;
 	int _rulesChunk7_size;
 	byte *_rulesChunk8;
@@ -177,11 +178,19 @@ public:
 	int _mouseX;
 	int _mouseY;
 	int _mouseButton;
+	int _savedMousePosDivided;
+
+	byte _byte16F07_menuId;
+	byte _byte12FCE;
+	byte _byte129A0;
+	int _word10804;
 
 	void pollEvent();
+	void sub170EE(int index);
+	void sub130DD();
+	void sub17083();
 
 	// Temporary stubs
-	byte _mouse_savedMousePosDivided;
 	byte _keyboard_getch();
 
 protected:
@@ -190,6 +199,7 @@ protected:
 
 	// Engine APIs
 	Common::Error run();
+	void handleMenu();
 
 private:
 	static LilliputEngine *s_Engine;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index e93608e..2a971a0 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -32,6 +32,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte1855D = 0;
 	_byte12A04 = 0;
 	_byte10806 = 0;
+	_byte12FE4 = 0xFF;
 
 	_word1855E = 0;
 	_word16F00 = -1;
@@ -573,6 +574,15 @@ void LilliputScript::runScript(Common::MemoryReadStream script) {
 		;
 }
 
+void LilliputScript::runMenuScript(Common::MemoryReadStream script) {
+	debugC(1, kDebugScript, "runMenuScript");
+	warning("========================== Menu Script ==============================");
+	_byte16F05_ScriptHandler = 0;
+	
+	while (handleOpcode(&script) == 0)
+		;
+}
+
 void LilliputScript::sub185ED(byte index, byte subIndex) {
 	debugC(2, kDebugScript, "sub185ED");
 	if (_vm->_arr18560[index]._field0 != 1)
@@ -746,7 +756,7 @@ int LilliputScript::getValue2() {
 		return (var1 << 8) + var2;
 		}
 	case 0xF6:
-		return _vm->_mouse_savedMousePosDivided;
+		return _vm->_savedMousePosDivided;
 	default:
 		warning("getValue2 - 0x%x - High value %d", tmpVal, curWord);
 		return curWord;
@@ -899,7 +909,16 @@ byte LilliputScript::OC_sub17812() {
 	return 0;
 }
 byte LilliputScript::OC_sub17825() {
-	warning("OC_sub17825");
+	debugC(1, kDebugScript, "OC_sub17825()");
+
+	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
+	
+	if ((_vm->_byte16F07_menuId != 1) && (_vm->_byte16F07_menuId != 3))
+		return 0;
+
+	if (tmpVal == _byte12FE4)
+		return 1;
+
 	return 0;
 }
 byte LilliputScript::OC_sub17844() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 75ab5ca..4d0f0b5 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -34,6 +34,7 @@ public:
 	~LilliputScript();
 
 	void runScript(Common::MemoryReadStream script);
+	void runMenuScript(Common::MemoryReadStream script);
 private:
 	LilliputEngine *_vm;
 
@@ -47,6 +48,7 @@ private:
 	byte _byte15FFA;
 	byte _byte1855D;
 	byte _byte10806;
+	byte _byte12FE4;
 
 	byte *_savedBuffer215Ptr;
 	byte _array122E9[20];


Commit: 58dc875b2eecc2ba0482951c7c4a0df0102e7717
    https://github.com/scummvm/scummvm/commit/58dc875b2eecc2ba0482951c7c4a0df0102e7717
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Start game scripts

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 65ec0c9..5465086 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -126,6 +126,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
 	_word10804 = 0;
+	_word17081_nextIndex = 0;
+	_word16EFE = 0xFFFF;
+	_word1817B = 0;
 
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
@@ -133,6 +136,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	for (int i = 0; i < 40; i++) {
 		_byte10999[i] = 0;
 		_byte109C1[i] = 0;
+		_array11D49[i] = 0xFFFF;
 	}
 
 }
@@ -344,15 +348,18 @@ void LilliputEngine::loadRules() {
 		_menuScript[i] = f.readByte();
 
 	// Chunk 7 & 8
-	_rulesChunk7_size = f.readUint16LE();
-	_rulesChunk7 = (int *)malloc(sizeof(int) * _rulesChunk7_size);
-	for (int i = 0; i < _rulesChunk7_size; ++i)
-		_rulesChunk7[i] = f.readUint16LE();
+	_gameScriptIndexSize = f.readUint16LE();
+	// Added one position to keep the total size too, as it's useful later
+	_arrayGameScriptIndex = (int *)malloc(sizeof(int) * (_gameScriptIndexSize + 1));
+	for (int i = 0; i < _gameScriptIndexSize; ++i)
+		_arrayGameScriptIndex[i] = f.readUint16LE();
 
 	curWord = f.readUint16LE();
-	_rulesChunk8 = (byte *)malloc(sizeof(byte) * curWord);
+	_arrayGameScriptIndex[_gameScriptIndexSize] = curWord;
+
+	_arrayGameScripts = (byte *)malloc(sizeof(byte) * curWord);
 	for (int i = 0; i < curWord; ++i)
-		_rulesChunk8[i] = f.readByte();
+		_arrayGameScripts[i] = f.readByte();
 
 	// Chunk 9
 	for (int i = 0; i < 60; i++)
@@ -496,6 +503,35 @@ void LilliputEngine::handleMenu() {
 
 void LilliputEngine::sub17083() {
 	warning("sub17083");
+	int index = _word17081_nextIndex;
+	int i;
+	for (i = 0; (_scriptHandler->_array10B29[index] == 0) && (i < _word10807_ERULES); i++) {
+		++index;
+		if (index >= _word10807_ERULES)
+			index = 0;
+	}
+
+	if (i >= _word10807_ERULES)
+		return;
+
+	_scriptHandler->_array10B29[index] = 0;
+	int tmpVal = index + 1;
+	if (tmpVal >= _word10807_ERULES)
+		tmpVal = 0;
+
+	_word17081_nextIndex = tmpVal;
+	sub170EE(index);
+
+	_word16EFE = _array11D49[index];
+	_array11D49[index] = 0xFFFF;
+	_word1817B = 0;
+
+	tmpVal = _rulesBuffer2_12[index];
+	if (tmpVal == 0xFF)
+		return;
+
+	assert(tmpVal < _gameScriptIndexSize);
+	_scriptHandler->runScript(Common::MemoryReadStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
 }
 
 Common::Error LilliputEngine::run() {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 4d88d4b..0280f67 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -106,6 +106,11 @@ public:
 	int _word10800_ERULES;
 	int _word10807_ERULES;
 	int _word16EFA;
+	int _word17081_nextIndex;
+	int _word16EFE;
+	int _word1817B;
+
+	int _array11D49[40];
 
 	byte *_rulesChunk1;
 	int _rulesBuffer2PrevIndx;
@@ -133,9 +138,9 @@ public:
 	int _initScript_size;
 	byte *_menuScript;
 	int _menuScript_size;
-	int *_rulesChunk7;
-	int _rulesChunk7_size;
-	byte *_rulesChunk8;
+	int *_arrayGameScriptIndex;
+	int _gameScriptIndexSize;
+	byte *_arrayGameScripts;
 	byte _rulesChunk9[60];
 	int _rulesChunk10_size;
 	int *_rulesChunk10;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 4d0f0b5..d8a8776 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -30,6 +30,8 @@ namespace Lilliput {
 class LilliputEngine;
 class LilliputScript {
 public:
+	byte _array10B29[40];
+
 	LilliputScript(LilliputEngine *vm);
 	~LilliputScript();
 
@@ -53,7 +55,6 @@ private:
 	byte *_savedBuffer215Ptr;
 	byte _array122E9[20];
 	byte _array122FD[20];
-	byte _array10B29[40];
 	byte _array128EF[40];
 
 	int16 _word1881B;


Commit: 9074e59fef9eabb67099bc1b6977240558a19237
    https://github.com/scummvm/scummvm/commit/9074e59fef9eabb67099bc1b6977240558a19237
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement opcodes used by game scripts 3 and 4

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 5465086..efd5f38 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -139,6 +139,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array11D49[i] = 0xFFFF;
 	}
 
+	_ptr_rulesBuffer2_15 = NULL;
 }
 
 LilliputEngine::~LilliputEngine() {
@@ -501,8 +502,9 @@ void LilliputEngine::handleMenu() {
 	_byte16F07_menuId = 0;
 }
 
-void LilliputEngine::sub17083() {
-	warning("sub17083");
+void LilliputEngine::handleGameScripts() {
+	debugC(1, kDebugEngine, "handleGameScripts()");
+
 	int index = _word17081_nextIndex;
 	int i;
 	for (i = 0; (_scriptHandler->_array10B29[index] == 0) && (i < _word10807_ERULES); i++) {
@@ -531,6 +533,8 @@ void LilliputEngine::sub17083() {
 		return;
 
 	assert(tmpVal < _gameScriptIndexSize);
+	warning("========================== Game Script %d ==============================", tmpVal);
+
 	_scriptHandler->runScript(Common::MemoryReadStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
 }
 
@@ -562,7 +566,7 @@ Common::Error LilliputEngine::run() {
 
 	while(!_shouldQuit) {
 		handleMenu();
-		sub17083();
+		handleGameScripts();
 		// To be removed when handled in the previous fonctions
 		pollEvent();
 	}
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 0280f67..b59b98a 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -193,7 +193,7 @@ public:
 	void pollEvent();
 	void sub170EE(int index);
 	void sub130DD();
-	void sub17083();
+	void handleGameScripts();
 
 	// Temporary stubs
 	byte _keyboard_getch();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 2a971a0..10502b6 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -893,13 +893,26 @@ byte LilliputScript::OC_sub1779E() {
 	return 0;
 }
 byte LilliputScript::OC_sub177C6() {
-	warning("OC_sub177C6");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub177C6()");
+
+	int index = _currScript->readUint16LE();
+	if (_vm->_rulesBuffer2_1[index] == 0xFFFF)
+		return 0;
+
+	return 1;
 }
 byte LilliputScript::OC_compWord16EFE() {
-	warning("OC_compWord16EFE");
-	return 0;
+	debugC(1, kDebugScript, "OC_compWord16EFE()");
+	byte curByte = _currScript->readUint16LE() & 0xFF;
+	byte tmpVal = _vm->_word16EFE >> 8;
+
+	if (curByte != tmpVal)
+		return 0;
+
+	_word16F00 = (_vm->_word16EFE & 0xFF);
+	return 1;
 }
+
 byte LilliputScript::OC_sub177F5() {
 	warning("OC_sub177F5");
 	return 0;
@@ -942,7 +955,11 @@ byte LilliputScript::OC_sub178BA() {
 	return 0;
 }
 byte LilliputScript::OC_sub178C2() {
-	warning("OC_sub178C2");
+	debugC(1, kDebugScript, "OC_sub178C2()");
+
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	if (_vm->_ptr_rulesBuffer2_15[2] == 1)
+		return 1;
 	return 0;
 }
 byte LilliputScript::OC_sub178D2() {
@@ -970,7 +987,11 @@ byte LilliputScript::OC_sub1793E() {
 	return 0;
 }
 byte LilliputScript::OC_sub1795E() {
-	warning("OC_sub1795E");
+	debugC(1, kDebugScript, "OC_sub1795E()");
+
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	if (_vm->_ptr_rulesBuffer2_15[3] == 1)
+		return 1;
 	return 0;
 }
 byte LilliputScript::OC_sub1796E() {
@@ -978,7 +999,16 @@ byte LilliputScript::OC_sub1796E() {
 	return 0;
 }
 byte LilliputScript::OC_sub17984() {
-	warning("OC_sub17984");
+	debugC(1, kDebugScript, "OC_sub17984()");
+
+	int index = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+
+	assert(index < 20);
+
+	if (_array122E9[index] == (var2 & 0xFF))
+		return 1;
+
 	return 0;
 }
 byte LilliputScript::OC_checkSavedMousePos() {
@@ -1046,7 +1076,16 @@ void LilliputScript::OC_sub17A66() {
 	warning("OC_sub17A66");
 }
 void LilliputScript::OC_sub17A8D() {
-	warning("OC_sub17A8D");
+	debugC(1, kDebugScript, "OC_sub17A8D()");
+
+	int tmpVal = getValue1();
+	assert(tmpVal < 40);
+
+	if (tmpVal == _word10804)
+		_word10802 = 0xFFFF;
+
+	_vm->_rulesBuffer2_1[tmpVal] = 0xFFFF;
+	_vm->_rulesBuffer2_2[tmpVal] = 0xFFFF;
 }
 void LilliputScript::OC_saveAndQuit() {
 	warning("OC_saveAndQuit");
@@ -1168,7 +1207,11 @@ void LilliputScript::OC_setByte10B29() {
 	warning("OC_setByte10B29");
 }
 void LilliputScript::OC_sub18007() {
-	warning("OC_sub18007");
+	debugC(1, kDebugScript, "OC_sub18007()");
+
+	int curWord = _currScript->readUint16LE();
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	_vm->_ptr_rulesBuffer2_15[2] = curWord & 0xFF;
 }
 void LilliputScript::OC_sub18014() {
 	warning("OC_sub18014");
@@ -1243,7 +1286,12 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 }
 
 void LilliputScript::OC_sub1834C() {
-	warning("OC_sub1834C");
+	debugC(1, kDebugScript, "OC_sub1834C()");
+
+	byte curWord = _currScript->readUint16LE() & 0xFF;
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+
+	_vm->_ptr_rulesBuffer2_15[3] = curWord;
 }
 void LilliputScript::OC_sub18359() {
 	warning("OC_sub18359");
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index d8a8776..fd323b0 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -57,15 +57,15 @@ private:
 	byte _array122FD[20];
 	byte _array128EF[40];
 
-	int16 _word1881B;
-	int16 _word16F00;
-	int16 _word10802;
-	int16 _word10804;
-	int16 _word15FFB;
-	int16 _word15FFD;
-	int16 _word12A00;
-	int16 _word12A02;
-	int16 _word1855E;
+	int _word1881B;
+	int _word16F00;
+	int _word10802;
+	int _word10804;
+	int _word15FFB;
+	int _word15FFD;
+	int _word12A00;
+	int _word12A02;
+	int _word1855E;
 
 	int handleOpcode(Common::MemoryReadStream *script);
 	byte handleOpcodeType1(int curWord);


Commit: ea8d934d60cf2f26181446f26d1faf3f1e534310
    https://github.com/scummvm/scummvm/commit/ea8d934d60cf2f26181446f26d1faf3f1e534310
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement opcodes. 29 groups are now executed in a row

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 10502b6..8ba4253 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -53,6 +53,8 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	for (int i = 0; i < 40; i++) {
 		_array10B29[i] = 1;
 		_array128EF[i] = 15;
+		_array10AB1[i] = 0;
+		_array12811[i] = 16;
 	}
 }
 
@@ -683,6 +685,30 @@ void LilliputScript::sub1823E(byte var1, byte var2, byte *curBufPtr) {
 	curBufPtr[3] = 0;
 }
 
+void LilliputScript::sub17B6C(int var1) {
+	debugC(1, kDebugScript, "sub17B6C(%d)", var1);
+
+	if (var1 == 0) {
+		int curWord = 0;
+		while (curWord != 0xFFF6)
+			curWord = _currScript->readUint16LE();
+		
+		_currScript->seek(_currScript->pos() - 4);
+		return;
+	}
+
+	++var1;
+	int curVal = 0;
+	int tmpVal;
+	while (curVal < var1) {
+		tmpVal = _currScript->readUint16LE();
+		if (tmpVal == 0xFFF7)
+			++curVal;
+	}
+
+	_currScript->seek(_currScript->pos() - 2);
+}
+
 int LilliputScript::getValue1() {
 	debugC(2, kDebugScript, "getValue1()");
 	int curWord = _currScript->readUint16LE();
@@ -836,10 +862,34 @@ byte LilliputScript::OC_sub174C8() {
 	warning("OC_sub174C8");
 	return 0;
 }
+
 byte LilliputScript::OC_sub174D8() {
-	warning("OC_sub174D8");
+	debugC(1, kDebugScript, "OC_sub174D8()");
+
+	byte tmpVal = getValue1() & 0xFF;
+	int curWord = _currScript->readUint16LE();
+	
+	if (curWord == 3000) {
+		int index;
+		for (index = 0; index < _vm->_word10807_ERULES; index++) {
+			if (_vm->_rulesBuffer2_5[index] == tmpVal) {
+				_word16F00 = index;
+				return 1;
+			}
+		}
+	} else {
+		_currScript->seek(_currScript->pos() - 2);
+		int index = getValue1();
+		assert(index < 40);
+		if (_vm->_rulesBuffer2_5[index] == tmpVal) {
+			_word16F00 = index;
+			return 1;
+		}
+	}
+
 	return 0;
 }
+
 byte LilliputScript::OC_sub1750E() {
 	warning("OC_sub1750E");
 	return 0;
@@ -860,10 +910,16 @@ byte LilliputScript::OC_sub1759E() {
 	warning("OC_sub1759E");
 	return 0;
 }
+
 byte LilliputScript::OC_compWord16EF8() {
-	warning("OC_compWord16EF8");
+	debugC(1, kDebugScript, "OC_compWord16EF8()");
+	
+	int tmpVal = getValue1();
+	if (tmpVal == _vm->_rulesBuffer2PrevIndx)
+		return 1;
 	return 0;
 }
+
 byte LilliputScript::OC_sub175C8() {
 	warning("OC_sub175C8");
 	return 0;
@@ -917,10 +973,17 @@ byte LilliputScript::OC_sub177F5() {
 	warning("OC_sub177F5");
 	return 0;
 }
+
 byte LilliputScript::OC_sub17812() {
-	warning("OC_sub17812");
+	debugC(1, kDebugScript, "OC_sub17812()");
+
+	byte curByte = (_currScript->readUint16LE() & 0xFF);
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	if (_vm->_ptr_rulesBuffer2_15[0] == curByte)
+		return 1;
 	return 0;
 }
+
 byte LilliputScript::OC_sub17825() {
 	debugC(1, kDebugScript, "OC_sub17825()");
 
@@ -934,14 +997,29 @@ byte LilliputScript::OC_sub17825() {
 
 	return 0;
 }
+
 byte LilliputScript::OC_sub17844() {
 	warning("OC_sub17844");
 	return 0;
 }
+
 byte LilliputScript::OC_sub1785C() {
-	warning("OC_sub1785C");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub1785C()");
+
+	byte curByte = (_currScript->readUint16LE() & 0xFF);
+	int count = 0;
+
+	for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+		if (curByte == _vm->_rulesBuffer2_15[(32 * i)])
+			++count;
+	}
+
+	int oper = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+
+	return compareValues(count, oper, var2);
 }
+
 byte LilliputScript::OC_sub17886() {
 	warning("OC_sub17886");
 	return 0;
@@ -978,22 +1056,34 @@ byte LilliputScript::OC_sub1790F() {
 	warning("OC_sub1790F");
 	return 0;
 }
+
 byte LilliputScript::OC_sub1792A() {
-	warning("OC_sub1792A");
+	debugC(1, kDebugScript, "OC_sub1792A()");
+
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	byte curByte = (_currScript->readUint16LE() & 0xFF);
+
+	if (_vm->_ptr_rulesBuffer2_15[1] == curByte)
+		return 1;
+
 	return 0;
 }
+
 byte LilliputScript::OC_sub1793E() {
 	warning("OC_sub1793E");
 	return 0;
 }
+
 byte LilliputScript::OC_sub1795E() {
 	debugC(1, kDebugScript, "OC_sub1795E()");
 
 	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
 	if (_vm->_ptr_rulesBuffer2_15[3] == 1)
 		return 1;
+
 	return 0;
 }
+
 byte LilliputScript::OC_sub1796E() {
 	warning("OC_sub1796E");
 	return 0;
@@ -1091,8 +1181,12 @@ void LilliputScript::OC_saveAndQuit() {
 	warning("OC_saveAndQuit");
 }
 void LilliputScript::OC_sub17B93() {
-	warning("OC_sub17B93");
+	debugC(1, kDebugScript, "OC_sub17B93()");
+	int var1 = _currScript->readUint16LE();
+
+	sub17B6C(var1);
 }
+
 void LilliputScript::OC_sub17E37() {
 	warning("OC_sub17E37");
 }
@@ -1105,18 +1199,52 @@ void LilliputScript::OC_deleteSavegameAndQuit() {
 void LilliputScript::OC_incByte16F04() {
 	warning("OC_incByte16F04");
 }
+
 void LilliputScript::OC_sub17BA5() {
-	warning("OC_sub17BA5");
+	debugC(1, kDebugScript, "OC_sub17BA5()");
+	
+	byte *tmpArr = getBuffer215Ptr();
+	byte oper = (_currScript->readUint16LE() & 0xFF);
+	byte var2 = getBuffer215Ptr()[0];
+	computeOperation(tmpArr, oper, var2);
 }
+
 void LilliputScript::OC_setByte18823() {
 	warning("OC_setByte18823");
 }
 void LilliputScript::OC_sub17BB7() {
-	warning("OC_sub17BB7");
+	debugC(1, kDebugScript, "OC_sub17BB7()");
+
+	int index = _currScript->readUint16LE();
+	int var1 = getValue1();
+
+	_vm->sub170EE(var1);
+	int tmpIndex = _vm->_rulesBuffer2PrevIndx;
+
+	assert(index < _vm->_gameScriptIndexSize);
+	int scriptIndex = _vm->_arrayGameScriptIndex[index];
+
+	_scriptStack.push(_currScript);
+	warning("===> push");
+	if (_byte16F05_ScriptHandler == 0) {
+		_vm->_byte1714E = 0;
+		runMenuScript(Common::MemoryReadStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
+	} else {
+		runScript(Common::MemoryReadStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
+	}
+	warning("===> pop");
+	_currScript = _scriptStack.pop();
+
+	_vm->sub170EE(tmpIndex);
 }
+
 void LilliputScript::OC_sub17BF2() {
-	warning("OC_sub17BF2");
+	debugC(1, kDebugScript, "OC_sub17BF2()");
+
+	OC_sub17BB7();
+	sub17B6C(0);
 }
+
 void LilliputScript::OC_sub17ACC() {
 	warning("OC_sub17ACC");
 }
@@ -1164,9 +1292,14 @@ void LilliputScript::OC_resetWord16EFE() {
 void LilliputScript::OC_sub17CEF() {
 	warning("OC_sub17CEF");
 }
+
 void LilliputScript::OC_sub17D1B() {
-	warning("OC_sub17D1B");
+	debugC(1, kDebugScript, "OC_sub17D1B()");
+
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	++_vm->_ptr_rulesBuffer2_15[1];
 }
+
 void LilliputScript::OC_sub17D23() {
 	warning("OC_sub17D23");
 }
@@ -1200,12 +1333,22 @@ void LilliputScript::OC_getNextVal() {
 void LilliputScript::OC_sub17FD2() {
 	warning("OC_sub17FD2");
 }
+
 void LilliputScript::OC_sub17FDD() {
-	warning("OC_sub17FDD");
+	debugC(1, kDebugScript, "OC_sub17FDD()");
+
+	int index = _currScript->readUint16LE();
+	
+	int tmpVal = (_vm->_rulesBuffer2PrevIndx * 32) + index;
+	assert (tmpVal < 40 * 32);
+	_array10AB1[_vm->_rulesBuffer2PrevIndx] = _vm->_rulesBuffer2_16[tmpVal];
+	_array12811[_vm->_rulesBuffer2PrevIndx] = 16;
 }
+
 void LilliputScript::OC_setByte10B29() {
 	warning("OC_setByte10B29");
 }
+
 void LilliputScript::OC_sub18007() {
 	debugC(1, kDebugScript, "OC_sub18007()");
 
@@ -1213,9 +1356,14 @@ void LilliputScript::OC_sub18007() {
 	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
 	_vm->_ptr_rulesBuffer2_15[2] = curWord & 0xFF;
 }
+
 void LilliputScript::OC_sub18014() {
-	warning("OC_sub18014");
+	debugC(1, kDebugScript, "OC_sub18014()");
+
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	_vm->_ptr_rulesBuffer2_15[2] = 0;
 }
+
 void LilliputScript::OC_sub1801D() {
 	warning("OC_sub1801D");
 }
@@ -1247,9 +1395,13 @@ void LilliputScript::OC_sub180C3() {
 void LilliputScript::OC_sub1810A() {
 	warning("OC_sub1810A");
 }
+
 void LilliputScript::OC_sub1812D() {
-	warning("OC_sub1812D");
+	debugC(1, kDebugScript, "OC_sub1812D()");
+
+	_vm->_rulesBuffer2_3[_vm->_rulesBuffer2PrevIndx] = (_currScript->readUint16LE() & 0xFF);
 }
+
 void LilliputScript::OC_sub1817F() {
 	warning("OC_sub1817F");
 }
@@ -1347,7 +1499,6 @@ void LilliputScript::OC_sub1847F() {
 		warning("TODO: OC_sub1847F - sub_18BE6");
 		warning("TODO: OC_sub1847F - Display Function 4");
 	}
-
 }
 
 void LilliputScript::OC_displayVGAFile() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index fd323b0..4f7d22b 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -24,6 +24,7 @@
 #define LILLIPUT_SCRIPT_H
 
 #include "common/memstream.h"
+#include "common/stack.h"
 
 namespace Lilliput {
 
@@ -41,6 +42,7 @@ private:
 	LilliputEngine *_vm;
 
 	Common::MemoryReadStream *_currScript;
+	Common::Stack<Common::MemoryReadStream *> _scriptStack;
 
 	byte _byte16F05_ScriptHandler;
 	byte _byte12A09;
@@ -56,6 +58,8 @@ private:
 	byte _array122E9[20];
 	byte _array122FD[20];
 	byte _array128EF[40];
+	byte _array10AB1[40];
+	byte _array12811[40];
 
 	int _word1881B;
 	int _word16F00;
@@ -74,6 +78,7 @@ private:
 	void sub185ED(byte index, byte subIndex);
 	void sub185B4_display();
 	void sub1823E(byte var1, byte var2, byte *curBufPtr);
+	void sub17B6C(int var1);
 
 	int getValue1();
 	int getValue2();


Commit: 697ab10bf3f3e1440f7c05dad8dbc0523907aabb
    https://github.com/scummvm/scummvm/commit/697ab10bf3f3e1440f7c05dad8dbc0523907aabb
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement more opcodes

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index efd5f38..8240816 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -513,7 +513,7 @@ void LilliputEngine::handleGameScripts() {
 			index = 0;
 	}
 
-	if (i >= _word10807_ERULES)
+	if (i > _word10807_ERULES)
 		return;
 
 	_scriptHandler->_array10B29[index] = 0;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 8ba4253..c8cba15 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -33,6 +33,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte12A04 = 0;
 	_byte10806 = 0;
 	_byte12FE4 = 0xFF;
+	_byte16F02 = 0;
 
 	_word1855E = 0;
 	_word16F00 = -1;
@@ -55,6 +56,11 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array128EF[i] = 15;
 		_array10AB1[i] = 0;
 		_array12811[i] = 16;
+		_array12839[i] = 0xFF;
+	}
+
+	for (int i = 0; i < 640; i++) {
+		_array12311[i] = 0xFFFF;
 	}
 }
 
@@ -709,6 +715,35 @@ void LilliputScript::sub17B6C(int var1) {
 	_currScript->seek(_currScript->pos() - 2);
 }
 
+void LilliputScript::sub16C86(int index, byte *buf) {
+	debugC(1, kDebugScript, "sub16C86()");
+
+	_array12811[index] = 0;
+
+	for (int i = 0; i < 16; i++) {
+		_array12311[(index * 16) + i] = (buf[2 * i] << 8) + buf[(2 * i) + 1];
+	}
+}
+
+void LilliputScript::sub16C5C(int index, byte var3) {
+	debugC(1, kDebugScript, "sub16C5C(%d, %d)", index, var3);
+
+	assert(index < 40);
+	_array12839[index] = var3;
+
+	byte *buf = _vm->_rulesChunk1;
+	if (var3 != 0) {
+		int count = 0;
+		while (count < var3) {
+			if ((buf[0] == 0xFF) && (buf[1] == 0xFF))
+				++count;
+			buf = &buf[2];
+		}
+	}
+
+	sub16C86(index, buf);
+}
+
 int LilliputScript::getValue1() {
 	debugC(2, kDebugScript, "getValue1()");
 	int curWord = _currScript->readUint16LE();
@@ -838,9 +873,16 @@ byte LilliputScript::OC_sub17468() {
 }
 
 byte LilliputScript::OC_getRandom() {
-	warning("OC_getRandom");
+	debugC(1, kDebugScript, "OC_getRandom()");
+
+	int maxVal = _currScript->readUint16LE();
+	_byte16F02 = _vm->_rnd->getRandomNumber(maxVal);
+	
+	if (_byte16F02 == 0)
+		return 1;
 	return 0;
 }
+
 byte LilliputScript::OC_sub1748C() {
 	warning("OC_sub1748C");
 	return 0;
@@ -921,19 +963,105 @@ byte LilliputScript::OC_compWord16EF8() {
 }
 
 byte LilliputScript::OC_sub175C8() {
-	warning("OC_sub175C8");
+	debugC(1, kDebugScript, "OC_sub175C8()");
+	
+	byte var4 = _currScript->readUint16LE() & 0xFF;
+
+	int tmpVal = _currScript->readUint16LE();
+	
+	if (tmpVal < 2000) {
+		_currScript->seek(_currScript->pos() - 2);
+		int index = getValue1();
+		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + index];
+		if ((var1 & 0xFF) < var4)
+			return 0;
+		
+		_word16F00 = index;
+		return 1;
+	}
+
+	if (tmpVal == 3000) {
+		for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+			int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
+			if ((var1 & 0xFF) >= var4) {
+				_word16F00 = i;
+				return 1;
+			}
+		}
+		return 0;
+	}
+	
+	tmpVal -= 2000;
+	byte var4b = tmpVal & 0xFF;
+	for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
+		if ((var1 & 0xFF) >= var4) {
+			if (_vm->_rulesBuffer2_12[i] == var4b) {
+				_word16F00 = i;
+				return 1;
+			}
+		}
+	}	
+	
 	return 0;
 }
 byte LilliputScript::OC_sub17640() {
 	warning("OC_sub17640");
 	return 0;
 }
+
 byte LilliputScript::OC_sub176C4() {
-	warning("OC_sub176C4");
+	debugC(1, kDebugScript, "OC_sub176C4()");
+	
+	byte var4 = _currScript->readUint16LE() & 0xFF;
+
+	int tmpVal = _currScript->readUint16LE();
+	
+	if (tmpVal < 2000) {
+		_currScript->seek(_currScript->pos() - 2);
+		int index = getValue1();
+		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + index];
+		if (((var1 & 0xFF) >= var4) || ((var1 >> 8) < var4))
+			return 0;
+		
+		_word16F00 = index;
+		return 1;
+	}
+
+	if (tmpVal == 3000) {
+		for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+			int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
+			if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
+				_word16F00 = i;
+				return 1;
+			}
+		}
+		return 0;
+	}
+	
+	tmpVal -= 2000;
+	byte var4b = tmpVal & 0xFF;
+	for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
+		if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
+			if (_vm->_rulesBuffer2_12[i] == var4b) {
+				_word16F00 = i;
+				return 1;
+			}
+		}
+	}	
+	
 	return 0;
 }
+
 byte LilliputScript::OC_compWord10804() {
-	warning("OC_compWord10804");
+	debugC(1, kDebugScript, "OC_compWord10804()");
+	
+	byte tmpVal = getValue1();
+	
+	if (tmpVal == _word10804)
+		return 1;
+
 	return 0;
 }
 byte LilliputScript::OC_sub17766() {
@@ -970,7 +1098,16 @@ byte LilliputScript::OC_compWord16EFE() {
 }
 
 byte LilliputScript::OC_sub177F5() {
-	warning("OC_sub177F5");
+	debugC(1, kDebugScript, "OC_sub177F5()");
+
+	byte var1 = _currScript->readUint16LE() & 0xFF;
+	byte var2 = _currScript->readUint16LE() & 0xFF;
+
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+
+	if ((var1 == _vm->_ptr_rulesBuffer2_15[0]) && (var2 == _vm->_ptr_rulesBuffer2_15[1]))
+		return 1;
+
 	return 0;
 }
 
@@ -1150,6 +1287,7 @@ void LilliputScript::OC_sub17E07() {
 void LilliputScript::OC_sub17E15() {
 	warning("OC_sub17E15");
 }
+
 void LilliputScript::OC_sub17B03() {
 	debugC(1, kDebugScript, "OC_sub17B03()");
 
@@ -1159,12 +1297,25 @@ void LilliputScript::OC_sub17B03() {
 
 	computeOperation(bufPtr, oper, var2);
 }
+
 void LilliputScript::OC_getRandom_type2() {
 	warning("OC_getRandom_type2");
 }
+
 void LilliputScript::OC_sub17A66() {
-	warning("OC_sub17A66");
+	debugC(1, kDebugScript, "OC_sub17A66()");
+	
+	int index = getValue1();
+	int tmpVal = getValue2();
+
+	int var2 = ((tmpVal >> 8) << 3) + 4;
+	int var4 = ((tmpVal & 0xFF) << 3) + 4;
+
+	assert(index < 40);
+	_vm->_rulesBuffer2_1[index] = var2;
+	_vm->_rulesBuffer2_2[index] = var4;
 }
+
 void LilliputScript::OC_sub17A8D() {
 	debugC(1, kDebugScript, "OC_sub17A8D()");
 
@@ -1251,12 +1402,21 @@ void LilliputScript::OC_sub17ACC() {
 void LilliputScript::OC_resetByte16F04() {
 	warning("OC_resetByte16F04");
 }
+
 void LilliputScript::OC_sub17AE1() {
-	warning("OC_sub17AE1");
+	debugC(1, kDebugScript, "OC_sub17AE1()");
+
+	byte var3 = (_currScript->readUint16LE() & 0xFF);
+	sub16C5C(_vm->_rulesBuffer2PrevIndx, var3);
 }
+
 void LilliputScript::OC_sub17AEE() {
-	warning("OC_sub17AEE");
+	debugC(1, kDebugScript, "OC_sub17AEE()");
+
+	byte var3 = (_currScript->readUint16LE() & 0xFF);
+	sub16C5C(_vm->_rulesBuffer2PrevIndx + 1, var3);
 }
+
 void LilliputScript::OC_setWord10804() {
 	debugC(1, kDebugScript, "OC_setWord10804()");
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 4f7d22b..92bed1f 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -25,6 +25,7 @@
 
 #include "common/memstream.h"
 #include "common/stack.h"
+#include "common/random.h"
 
 namespace Lilliput {
 
@@ -53,6 +54,7 @@ private:
 	byte _byte1855D;
 	byte _byte10806;
 	byte _byte12FE4;
+	byte _byte16F02;
 
 	byte *_savedBuffer215Ptr;
 	byte _array122E9[20];
@@ -60,6 +62,10 @@ private:
 	byte _array128EF[40];
 	byte _array10AB1[40];
 	byte _array12811[40];
+	byte _array12839[40];
+	byte _array10B51[40 * 40];
+
+	int _array12311[640];
 
 	int _word1881B;
 	int _word16F00;
@@ -79,6 +85,8 @@ private:
 	void sub185B4_display();
 	void sub1823E(byte var1, byte var2, byte *curBufPtr);
 	void sub17B6C(int var1);
+	void sub16C86(int index, byte *buf);
+	void sub16C5C(int index, byte var3);
 
 	int getValue1();
 	int getValue2();


Commit: a08b34fea866bff239c06105c32293598327ae9c
    https://github.com/scummvm/scummvm/commit/a08b34fea866bff239c06105c32293598327ae9c
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add some more opcodes. Engine is now alive!

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8240816..8799c47 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -196,7 +196,7 @@ void LilliputEngine::pollEvent() {
 }
 
 byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
-	debugC(1, kDebugEngine, "loadVGA(%s, %d)", filename, (loadPal) ? 1 : 0);
+	debugC(1, kDebugEngine, "loadVGA(%s, %d)", filename.c_str(), (loadPal) ? 1 : 0);
 
 	Common::File f;
 
@@ -533,7 +533,7 @@ void LilliputEngine::handleGameScripts() {
 		return;
 
 	assert(tmpVal < _gameScriptIndexSize);
-	warning("========================== Game Script %d ==============================", tmpVal);
+	debugC(1, kDebugEngine, "========================== Game Script %d ==========================", tmpVal);
 
 	_scriptHandler->runScript(Common::MemoryReadStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
 }
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index c8cba15..47ec8a8 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -43,6 +43,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_word15FFD = 0;
 	_word12A00 = 0;
 	_word12A02 = 0;
+	_word18776 = 0;
 
 	_savedBuffer215Ptr = NULL;
 
@@ -57,6 +58,9 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array10AB1[i] = 0;
 		_array12811[i] = 16;
 		_array12839[i] = 0xFF;
+		_array16123[i] = 0;
+		_array1614B[i] = 0;
+		_array16173[i] = 0xFF;
 	}
 
 	for (int i = 0; i < 640; i++) {
@@ -744,8 +748,52 @@ void LilliputScript::sub16C5C(int index, byte var3) {
 	sub16C86(index, buf);
 }
 
+int LilliputScript::sub17D40(int var) {
+	debugC(1, kDebugScript, "sub17D40(%d)", var);
+
+	if ((_byte16F08 != 1) && (_array16173[_vm->_rulesBuffer2PrevIndx] != 0xFF))
+		return var;
+
+	warning("sub17D40() - FIXME: Unexpected POP");
+	return var;
+}
+
+void LilliputScript::sub18A56(byte *buf) {
+	warning("TODO: sub18A56(buf)");
+}
+
+void LilliputScript::sub18B3C(int var) {
+	debugC(2, kDebugScript, "sub18B3C(%d)", var);
+
+	if (var == 0xFFFF)
+		return;
+
+	_word18776 = var;
+
+	int index = _vm->_rulesChunk3[var];
+	int count = 0;
+	while (_vm->_rulesChunk4[index + count] != 0x5B)
+		++count;
+
+	int i = 0;
+	if (count != 0) {
+		int tmpVal = _vm->_rnd->getRandomNumber(count + 1);
+		if (tmpVal != 0) {
+			int i = 0;
+			for (int j = 0; j < tmpVal; j++) {
+				do
+					++i;
+				while (_vm->_rulesChunk4[index + count + i] != 0x5B);
+			}
+		}
+	}
+
+	sub18A56(&_vm->_rulesChunk4[index + count + i]);
+}
+
 int LilliputScript::getValue1() {
 	debugC(2, kDebugScript, "getValue1()");
+
 	int curWord = _currScript->readUint16LE();
 	if (curWord < 1000)
 		return curWord;
@@ -876,10 +924,12 @@ byte LilliputScript::OC_getRandom() {
 	debugC(1, kDebugScript, "OC_getRandom()");
 
 	int maxVal = _currScript->readUint16LE();
-	_byte16F02 = _vm->_rnd->getRandomNumber(maxVal);
+	int rand = _vm->_rnd->getRandomNumber(maxVal);
+	_byte16F02 = (rand & 0xFF);
 	
-	if (_byte16F02 == 0)
+	if (rand == 0)
 		return 1;
+
 	return 0;
 }
 
@@ -1087,6 +1137,7 @@ byte LilliputScript::OC_sub177C6() {
 }
 byte LilliputScript::OC_compWord16EFE() {
 	debugC(1, kDebugScript, "OC_compWord16EFE()");
+
 	byte curByte = _currScript->readUint16LE() & 0xFF;
 	byte tmpVal = _vm->_word16EFE >> 8;
 
@@ -1269,18 +1320,36 @@ void LilliputScript::OC_setWord18821() {
 void LilliputScript::OC_sub17A3E() {
 	warning("OC_sub17A3E");
 }
+
 void LilliputScript::OC_sub17D57() {
-	warning("OC_sub17D57");
+	debugC(1, kDebugScript, "OC_sub17D57()");
+
+	int curWord = _currScript->readUint16LE();
+	curWord = sub17D40(curWord);
+
+	_word1881B = _vm->_rulesBuffer2PrevIndx;
+
+	sub18B3C(curWord);
 }
+
 void LilliputScript::OC_sub17D7F() {
 	warning("OC_sub17D7F");
 }
 void LilliputScript::OC_sub17DB9() {
 	warning("OC_sub17DB9");
 }
+
 void LilliputScript::OC_sub17DF9() {
-	warning("OC_sub17DF9");
+	debugC(1, kDebugScript, "OC_sub17DF9()");
+
+	if ((_word1881B & 0xFF) == 0xFF) {
+		OC_sub17D57();
+		return;
+	}
+
+	_currScript->readUint16LE();
 }
+
 void LilliputScript::OC_sub17E07() {
 	warning("OC_sub17E07");
 }
@@ -1752,11 +1821,25 @@ void LilliputScript::OC_setWord10802() {
 
 	_word10802 = getValue1();
 }
+
 void LilliputScript::OC_sub186A1() {
 	warning("OC_sub186A1");
 }
+
 void LilliputScript::OC_sub186E5_snd() {
-	warning("OC_sub186E5_snd");
+	debugC(1, kDebugScript, "OC_sub186E5_snd()");
+	int index = getValue1();
+	assert(index < 40);
+
+	byte var4h = 0xFF;
+	byte var4l = (index & 0xFF);
+	byte var3h = _array16123[index];
+	byte var3l = _array1614B[index];
+	byte var2h = (_word12A00 & 0xFF);
+	byte var2l = (_word12A02 & 0xFF);
+	int var1 = _currScript->readUint16LE();
+
+	warning("TODO: call sound function #2");
 }
 
 void LilliputScript::OC_sub1870A_snd() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 92bed1f..07a7233 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -63,6 +63,9 @@ private:
 	byte _array10AB1[40];
 	byte _array12811[40];
 	byte _array12839[40];
+	byte _array16123[40];
+	byte _array1614B[40];
+	byte _array16173[40];
 	byte _array10B51[40 * 40];
 
 	int _array12311[640];
@@ -76,6 +79,7 @@ private:
 	int _word12A00;
 	int _word12A02;
 	int _word1855E;
+	int _word18776;
 
 	int handleOpcode(Common::MemoryReadStream *script);
 	byte handleOpcodeType1(int curWord);
@@ -87,6 +91,9 @@ private:
 	void sub17B6C(int var1);
 	void sub16C86(int index, byte *buf);
 	void sub16C5C(int index, byte var3);
+	int sub17D40(int var);
+	void sub18A56(byte *buf);
+	void sub18B3C(int var);
 
 	int getValue1();
 	int getValue2();


Commit: 31d4f0750560585418441d659fa1828cfa35b6f2
    https://github.com/scummvm/scummvm/commit/31d4f0750560585418441d659fa1828cfa35b6f2
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: start implementing display functions

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8799c47..3b48d8a 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -114,8 +114,14 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_rnd = 0;
 	_mouseX = 0;
 	_mouseY = 0;
+	_oldMouseX = 0;
+	_oldMouseY = 0;
+	_mouseDisplayX = 0;
+	_mouseDisplayY = 0;
 	_mouseButton = 0;
 	_savedMousePosDivided = 0xFFFF;
+	_skipDisplayFlag1 = 1;
+	_skipDisplayFlag2 = 0;
 
 	_scriptHandler = new LilliputScript(this);
 
@@ -129,6 +135,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word17081_nextIndex = 0;
 	_word16EFE = 0xFFFF;
 	_word1817B = 0;
+	_word15BC8 = 0;
+	_word15BCA = 0;
 
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
@@ -139,6 +147,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array11D49[i] = 0xFFFF;
 	}
 
+	for (int i = 0; i < 256; i++)
+		_array15AC8[i] = 0;
+
 	_ptr_rulesBuffer2_15 = NULL;
 }
 
@@ -169,6 +180,73 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
+void LilliputEngine::displayFunction1(byte *buf, int var1, int var2, int var4) {
+	debugC(2, kDebugEngine, "displayFunction1a(buf, %d, %d, %d)", var1, var2, var4);
+
+	int index1 = ((var1 & 0xFF) << 8) + (var1 >> 8);
+	byte *newBuf = &buf[index1];
+
+	int tmpVal = ((var4 & 0xFF) << 8) + (var4 >> 8);
+	int index2 = var2 + tmpVal + (tmpVal >> 2);
+
+	for (int i = 0; i < 16; i++) {
+		if (newBuf[0] != 0)
+			((byte *)_mainSurface->getPixels())[index2] = newBuf[0];
+		if (newBuf[1] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 1] = newBuf[1];
+		if (newBuf[2] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 2] = newBuf[2];
+		if (newBuf[3] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 3] = newBuf[3];
+		if (newBuf[4] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 4] = newBuf[4];
+		if (newBuf[5] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 5] = newBuf[5];
+		if (newBuf[6] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 6] = newBuf[6];
+		if (newBuf[7] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 7] = newBuf[7];
+		if (newBuf[8] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 8] = newBuf[8];
+		if (newBuf[9] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 9] = newBuf[9];
+		if (newBuf[10] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 10] = newBuf[10];
+		if (newBuf[11] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 11] = newBuf[11];
+		if (newBuf[12] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 12] = newBuf[12];
+		if (newBuf[13] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 13] = newBuf[13];
+		if (newBuf[14] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 14] = newBuf[14];
+		if (newBuf[15] != 0)
+			((byte *)_mainSurface->getPixels())[index2 + 15] = newBuf[15];
+
+		index2 += 304;
+		newBuf = &newBuf[16];
+	}
+	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
+	_system->updateScreen();
+}
+
+void LilliputEngine::displayFunction1a(byte *buf, int var2, int var4) {
+	debugC(2, kDebugEngine, "displayFunction1a(buf, %d, %d)", var2, var4);
+
+	displayFunction1(buf, 0, var2, var4);
+}
+
+void LilliputEngine::displayFunction5() {
+	debugC(2, kDebugEngine, "displayFunction5()");
+
+	if ((_skipDisplayFlag1 != 0) && (_skipDisplayFlag2 != 1)) {
+		_skipDisplayFlag2 = 1;
+		displayFunction1a(_array15AC8, _word15BC8, _word15BCA);
+		_skipDisplayFlag1 = 0;
+		_skipDisplayFlag2 = 0;
+	}
+}
+
 void LilliputEngine::pollEvent() {
 	debugC(2, kDebugEngine, "pollEvent()");
 
@@ -176,8 +254,8 @@ void LilliputEngine::pollEvent() {
 	while (_system->getEventManager()->pollEvent(event)) {
 		switch (event.type) {
 		case Common::EVENT_MOUSEMOVE:
-			_mouseX = event.mouse.x;
-			_mouseY = event.mouse.y;
+			_mouseX = CLIP<int>(event.mouse.x, 0, 304) + 5;
+			_mouseY = CLIP<int>(event.mouse.y, 0, 184) + 1;
 			break;
 		case Common::EVENT_LBUTTONUP:
 			_mouseButton |= 1;
@@ -193,6 +271,20 @@ void LilliputEngine::pollEvent() {
 			break;
 		}
 	}
+
+	if ((_mouseX != _oldMouseX) || (_mouseY != _oldMouseY)) {
+		_oldMouseX = _mouseX;
+		_oldMouseY = _mouseY;
+		if (_skipDisplayFlag1 != 0) {
+			warning("Display function 5");
+			_mouseDisplayX = _mouseX;
+			_mouseDisplayY = _mouseY;
+			warning("Display function 4");
+		} else {
+			_mouseDisplayX = _mouseX;
+			_mouseDisplayY = _mouseY;
+		}
+	}
 }
 
 byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index b59b98a..ba86542 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -109,6 +109,8 @@ public:
 	int _word17081_nextIndex;
 	int _word16EFE;
 	int _word1817B;
+	int _word15BC8;
+	int _word15BCA;
 
 	int _array11D49[40];
 
@@ -157,11 +159,16 @@ public:
 	byte _rulesBuffer13_4[20];
 	byte _byte10999[40];
 	byte _byte109C1[40];
+	byte _array15AC8[256];
 
 	const LilliputGameDescription *_gameDescription;
 	uint32 getFeatures() const;
 	const char *getGameId() const;
 
+	void displayFunction1(byte *buf, int var1, int var2, int var4);
+	void displayFunction1a(byte *buf, int var2, int var4);
+	void displayFunction5();
+
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
 	byte *loadRaw(Common::String filename);
@@ -182,8 +189,14 @@ public:
 
 	int _mouseX;
 	int _mouseY;
+	int _oldMouseX;
+	int _oldMouseY;
+	int _mouseDisplayX;
+	int _mouseDisplayY;
 	int _mouseButton;
 	int _savedMousePosDivided;
+	int _skipDisplayFlag1;
+	int _skipDisplayFlag2;
 
 	byte _byte16F07_menuId;
 	byte _byte12FCE;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 47ec8a8..77a9f7a 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -652,7 +652,7 @@ void LilliputScript::computeOperation(byte *bufPtr, int oper, int var2) {
 	default: {
 		warning("computeOperation : oper %d", oper);
 		if (var2 != 0) {
-			byte tmpVal = bufPtr[0] / var2;
+			int tmpVal = bufPtr[0] / var2;
 			if (tmpVal < 0)
 				bufPtr[0] = 0xFF;
 			else 


Commit: e21bb143135698735fbb0f18c9a86ad33243f97b
    https://github.com/scummvm/scummvm/commit/e21bb143135698735fbb0f18c9a86ad33243f97b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in previous commit, implement one more display function

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3b48d8a..29d53fe 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -137,6 +137,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word1817B = 0;
 	_word15BC8 = 0;
 	_word15BCA = 0;
+	_word15AC2 = 0;
 
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
@@ -181,7 +182,7 @@ Common::Platform LilliputEngine::getPlatform() const {
 }
 
 void LilliputEngine::displayFunction1(byte *buf, int var1, int var2, int var4) {
-	debugC(2, kDebugEngine, "displayFunction1a(buf, %d, %d, %d)", var1, var2, var4);
+	debugC(2, kDebugEngine, "displayFunction1(buf, %d, %d, %d)", var1, var2, var4);
 
 	int index1 = ((var1 & 0xFF) << 8) + (var1 >> 8);
 	byte *newBuf = &buf[index1];
@@ -223,7 +224,7 @@ void LilliputEngine::displayFunction1(byte *buf, int var1, int var2, int var4) {
 		if (newBuf[15] != 0)
 			((byte *)_mainSurface->getPixels())[index2 + 15] = newBuf[15];
 
-		index2 += 304;
+		index2 += 320;
 		newBuf = &newBuf[16];
 	}
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
@@ -236,6 +237,24 @@ void LilliputEngine::displayFunction1a(byte *buf, int var2, int var4) {
 	displayFunction1(buf, 0, var2, var4);
 }
 
+void LilliputEngine::displayFunction4() {
+	debugC(2, kDebugEngine, "displayFunction4()");
+
+	if ((_skipDisplayFlag1 != 1) && (_skipDisplayFlag2 != 1)) {
+		_skipDisplayFlag2 = 1;
+
+		_word15BC8 = _mouseDisplayX;
+		_word15BCA = _mouseDisplayY;
+
+		warning("Display function 2");
+
+		displayFunction1(_bufferIdeogram, _word15AC2 + 80, _mouseDisplayX, _mouseDisplayY);
+
+		_skipDisplayFlag1 = 1;
+		_skipDisplayFlag2 = 0;
+	}
+}
+
 void LilliputEngine::displayFunction5() {
 	debugC(2, kDebugEngine, "displayFunction5()");
 
@@ -276,10 +295,10 @@ void LilliputEngine::pollEvent() {
 		_oldMouseX = _mouseX;
 		_oldMouseY = _mouseY;
 		if (_skipDisplayFlag1 != 0) {
-			warning("Display function 5");
+			displayFunction5();
 			_mouseDisplayX = _mouseX;
 			_mouseDisplayY = _mouseY;
-			warning("Display function 4");
+			displayFunction4();
 		} else {
 			_mouseDisplayX = _mouseX;
 			_mouseDisplayY = _mouseY;
@@ -523,14 +542,15 @@ void LilliputEngine::loadRules() {
 
 void LilliputEngine::displayVGAFile(Common::String fileName) {
 	debugC(1, kDebugEngine, "displayVGAFile(%s)", fileName.c_str());
-	warning("TODO: display function #4");
+
+	displayFunction4();
 
 	byte *buffer = loadVGA(fileName, true);
 	memcpy(_mainSurface->getPixels(), buffer, 320*200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
 
-	warning("TODO: display function #5");
+	displayFunction5();
 }
 
 void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index ba86542..ed04959 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -111,6 +111,7 @@ public:
 	int _word1817B;
 	int _word15BC8;
 	int _word15BCA;
+	int _word15AC2;
 
 	int _array11D49[40];
 
@@ -167,6 +168,7 @@ public:
 
 	void displayFunction1(byte *buf, int var1, int var2, int var4);
 	void displayFunction1a(byte *buf, int var2, int var4);
+	void displayFunction4();
 	void displayFunction5();
 
 	void initGame(const LilliputGameDescription *gd);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 77a9f7a..f979008 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -600,7 +600,7 @@ void LilliputScript::sub185ED(byte index, byte subIndex) {
 	if (_vm->_arr18560[index]._field0 != 1)
 		return;
 
-	warning("TODO: display function #1");
+	_vm->displayFunction1(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[0], _vm->_arr18560[index]._field1, _vm->_arr18560[index]._field3);
 }
 
 byte LilliputScript::compareValues(byte var1, int oper, int var2) {
@@ -1724,9 +1724,9 @@ void LilliputScript::OC_sub1847F() {
 	int var3 = _currScript->readUint16LE();
 
 	if (_byte16F08 != 1) {
-		warning("TODO: OC_sub1847F - Display Function 5");
+		_vm->displayFunction5();
 		warning("TODO: OC_sub1847F - sub_18BE6");
-		warning("TODO: OC_sub1847F - Display Function 4");
+		_vm->displayFunction4();
 	}
 }
 


Commit: d924342d2dca0c14efd7d0607d16c6aeacad84fb
    https://github.com/scummvm/scummvm/commit/d924342d2dca0c14efd7d0607d16c6aeacad84fb
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement display function 2. This fixes mouse display

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 29d53fe..10e55cd 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -237,6 +237,21 @@ void LilliputEngine::displayFunction1a(byte *buf, int var2, int var4) {
 	displayFunction1(buf, 0, var2, var4);
 }
 
+void LilliputEngine::displayFunction2(byte *buf, int var2, int var4) {
+	debugC(2, kDebugEngine, "displayFunction2(buf, %d, %d)", var2, var4);
+
+
+	int tmpVal = ((var4 & 0xFF) << 8) + (var4 >> 8);
+	int index2 = var2 + tmpVal + (tmpVal >> 2);
+
+	for (int i = 0; i < 16; i++) {
+		for (int j = 0; j < 16; j++) {
+			buf[(i * 16) + j] = ((byte *)_mainSurface->getPixels())[index2 + j];
+		}
+		index2 += 320;
+	}
+}
+
 void LilliputEngine::displayFunction4() {
 	debugC(2, kDebugEngine, "displayFunction4()");
 
@@ -246,7 +261,7 @@ void LilliputEngine::displayFunction4() {
 		_word15BC8 = _mouseDisplayX;
 		_word15BCA = _mouseDisplayY;
 
-		warning("Display function 2");
+		displayFunction2(_array15AC8, _mouseDisplayX, _mouseDisplayY);
 
 		displayFunction1(_bufferIdeogram, _word15AC2 + 80, _mouseDisplayX, _mouseDisplayY);
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index ed04959..a59b244 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -168,6 +168,7 @@ public:
 
 	void displayFunction1(byte *buf, int var1, int var2, int var4);
 	void displayFunction1a(byte *buf, int var2, int var4);
+	void displayFunction2(byte *buf, int var2, int var4);
 	void displayFunction4();
 	void displayFunction5();
 


Commit: 847098c705f3cc9f7a9155e0ffc70d4868400fda
    https://github.com/scummvm/scummvm/commit/847098c705f3cc9f7a9155e0ffc70d4868400fda
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement display function 6, start implementing display function 12.

Background is now displayed properly

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 10e55cd..b645c51 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -152,6 +152,12 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array15AC8[i] = 0;
 
 	_ptr_rulesBuffer2_15 = NULL;
+	_bufferIdeogram = NULL;
+	_bufferMen = NULL;
+	_bufferMen2 = NULL;
+	_bufferIsoChars = NULL;
+	_bufferIsoMap = NULL;
+	_bufferCubegfx = NULL;
 }
 
 LilliputEngine::~LilliputEngine() {
@@ -281,6 +287,42 @@ void LilliputEngine::displayFunction5() {
 	}
 }
 
+void LilliputEngine::displayFunction6() {
+	debugC(2, kDebugEngine, "displayFunction6()");
+
+	displayFunction5();
+
+	int index = (16 * 320) + 64;
+	for (int i = 0; i < 176; i++) {
+		for (int j = 0; j < 256; j++)
+			_buffer3_45k[(i * 256) + j] = ((byte *)_mainSurface->getPixels())[index + j];
+		index += 320;
+	}
+
+	displayFunction4();
+}
+
+void LilliputEngine::displayFunction12() {
+	debugC(1, kDebugEngine, "displayFunction12()");
+
+	displayFunction5();
+
+	byte *tmpBuf = loadVGA("SCREEN.GFX", true);
+	memcpy(_mainSurface->getPixels(), tmpBuf, 320*200);
+	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
+	_system->updateScreen();
+
+	displayFunction6();
+	warning("Display function 7");
+	warning("Display function 8");
+	warning("Display function 9");
+	warning("sub_1649F()");
+	warning("sub_154C5()");
+
+	displayFunction4();
+	free(tmpBuf);
+}
+
 void LilliputEngine::pollEvent() {
 	debugC(2, kDebugEngine, "pollEvent()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index a59b244..a677c1b 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -93,7 +93,7 @@ public:
 	byte _buffer2[45056];
 	byte _buffer3[45056];
 	byte *_bufferIsoMap;
-	byte _bufferCubegfx[61440];
+	byte *_bufferCubegfx;
 	byte *_bufferMen;
 	byte *_bufferMen2;
 	byte *_bufferIsoChars;
@@ -162,6 +162,8 @@ public:
 	byte _byte109C1[40];
 	byte _array15AC8[256];
 
+	byte _buffer3_45k[45056];
+
 	const LilliputGameDescription *_gameDescription;
 	uint32 getFeatures() const;
 	const char *getGameId() const;
@@ -171,6 +173,8 @@ public:
 	void displayFunction2(byte *buf, int var2, int var4);
 	void displayFunction4();
 	void displayFunction5();
+	void displayFunction6();
+	void displayFunction12();
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f979008..396bd41 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1445,14 +1445,14 @@ void LilliputScript::OC_sub17BB7() {
 	int scriptIndex = _vm->_arrayGameScriptIndex[index];
 
 	_scriptStack.push(_currScript);
-	warning("===> push");
+
 	if (_byte16F05_ScriptHandler == 0) {
 		_vm->_byte1714E = 0;
 		runMenuScript(Common::MemoryReadStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
 	} else {
 		runScript(Common::MemoryReadStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
 	}
-	warning("===> pop");
+
 	_currScript = _scriptStack.pop();
 
 	_vm->sub170EE(tmpIndex);
@@ -1663,7 +1663,10 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 	assert((curWord >= 0) && (curWord <= 9));
 	Common::String fileName = Common::String::format("CUBES%d.GFX", curWord);
 	_byte10806 = curWord + 0x30;
-	warning("TODO: load %s then display things", fileName.c_str());
+
+	_vm->_bufferCubegfx = _vm->loadVGA(fileName, false);
+	warning("Display function 9");
+	warning("sub_1649F()");
 }
 
 void LilliputScript::OC_sub1834C() {
@@ -1784,7 +1787,9 @@ void LilliputScript::OC_sub1853B() {
 	_byte16F08 = 0;
 	_byte15FFA = 0;
 	sub130B6();
-	warning("TODO: Display function sub15CBC();");
+
+	_vm->displayFunction12();
+
 	warning("TODO: unkPaletteFunction_2");
 	_byte12A09 = 0;
 	warning("TODO: call sound function #5");


Commit: 3ffb103d57893e1c0b0a23494e4625d9d52c296a
    https://github.com/scummvm/scummvm/commit/3ffb103d57893e1c0b0a23494e4625d9d52c296a
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more display functions

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index b645c51..06edcba 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -128,6 +128,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte1714E = 0;
 	_byte12FCE = 0;
 	_byte129A0 = 0xFF;
+	_byte160FA = 0;
+	_byte16529 = 0;
+	_byte1652A = 0;
 
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
@@ -138,14 +141,36 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word15BC8 = 0;
 	_word15BCA = 0;
 	_word15AC2 = 0;
+	_word16213 = 0;
+	_word16215 = 0;
 
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
 
 	for (int i = 0; i < 40; i++) {
-		_byte10999[i] = 0;
-		_byte109C1[i] = 0;
+		_array10999[i] = 0;
+		_array109C1[i] = 0;
+		_array160FB[i] = 0;
+		_array16173[i] = 0xFF;
+		_array1619B[i] = 0xFF;
+		_array161C3[i] = 0;
+		_array161EB[i] = 0;
+
 		_array11D49[i] = 0xFFFF;
+		_rulesBuffer2_1[i] = 0xFFFF;
+		_rulesBuffer2_2[i] = 0xFFFF;
+		_rulesBuffer2_3[i] = 0;
+		_rulesBuffer2_4[i] = 0;
+		_rulesBuffer2_5[i] = 0xFF;
+		_rulesBuffer2_6[i] = 4;
+		_rulesBuffer2_7[i] = 0;
+		_rulesBuffer2_8[i] = 20;
+		_rulesBuffer2_9[i] = 0;
+		_rulesBuffer2_10[i] = 0;
+		_rulesBuffer2_11[i] = 0;
+		_rulesBuffer2_12[i] = 0;
+		_rulesBuffer2_13[i] = 0;
+		_rulesBuffer2_14[i] = 0;
 	}
 
 	for (int i = 0; i < 256; i++)
@@ -187,6 +212,7 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
+// display mouse cursor, if any
 void LilliputEngine::displayFunction1(byte *buf, int var1, int var2, int var4) {
 	debugC(2, kDebugEngine, "displayFunction1(buf, %d, %d, %d)", var1, var2, var4);
 
@@ -243,6 +269,7 @@ void LilliputEngine::displayFunction1a(byte *buf, int var2, int var4) {
 	displayFunction1(buf, 0, var2, var4);
 }
 
+// save area under mouse cursor
 void LilliputEngine::displayFunction2(byte *buf, int var2, int var4) {
 	debugC(2, kDebugEngine, "displayFunction2(buf, %d, %d)", var2, var4);
 
@@ -258,6 +285,7 @@ void LilliputEngine::displayFunction2(byte *buf, int var2, int var4) {
 	}
 }
 
+// display mouse cursor
 void LilliputEngine::displayFunction4() {
 	debugC(2, kDebugEngine, "displayFunction4()");
 
@@ -287,6 +315,7 @@ void LilliputEngine::displayFunction5() {
 	}
 }
 
+// save game area
 void LilliputEngine::displayFunction6() {
 	debugC(2, kDebugEngine, "displayFunction6()");
 
@@ -302,6 +331,60 @@ void LilliputEngine::displayFunction6() {
 	displayFunction4();
 }
 
+// save speech zone
+void LilliputEngine::displayFunction7() {
+	debugC(2, kDebugEngine, "displayFunction7()");
+
+	displayFunction5();
+
+	int index = 66;
+	for (int i = 0; i < 16; i++) {
+		for (int j = 0; j < 252; j++)
+			_buffer10_4032[(i * 252) + j] = ((byte *)_mainSurface->getPixels())[index + j];
+		index += 320;
+	}
+
+	displayFunction4();
+}
+
+void LilliputEngine::displayFunction8() {
+	debugC(2, kDebugEngine, "displayFunction8()");
+
+	if (_scriptHandler->_byte16F08 == 1)
+		return;
+
+	displayFunction5();
+
+	int index = 0;
+	int tmpVal;
+	for (int i = 0; i < _word12F68_ERULES; i++) {
+		tmpVal = ((_scriptHandler->_array122E9[index] << 2) + (_scriptHandler->_array122E9[index] << 4)) & 0xFF;
+		displayFunction1(_bufferIdeogram, tmpVal + index, _rulesBuffer13_2[index], _rulesBuffer13_3[index]);
+	}
+
+	displayFunction4();
+}
+
+void LilliputEngine::displayFunction9() {
+	debugC(2, kDebugEngine, "displayFunction9()");
+
+	memcpy(_buffer2_45k, _buffer3_45k, 45056);
+
+	int var1 = (_scriptHandler->_word12A02 >> 8) + ((_scriptHandler->_word12A02 & 0xFF) << 8) + (_scriptHandler->_word12A00 << 2);
+	int var2;
+	int index = 0;
+
+	for (int i = 0; i < 8; i++) {
+		for (int j = 0; j < 8 ; j++) {
+			var2 = (j << 8) + i;
+			displayFunction13(_buffer2_45k, _bufferIsoMap[var1 + index], var2, 0);
+			index += 4;
+		}
+		index += 224;
+	}
+
+}
+
 void LilliputEngine::displayFunction12() {
 	debugC(1, kDebugEngine, "displayFunction12()");
 
@@ -313,16 +396,163 @@ void LilliputEngine::displayFunction12() {
 	_system->updateScreen();
 
 	displayFunction6();
-	warning("Display function 7");
-	warning("Display function 8");
-	warning("Display function 9");
-	warning("sub_1649F()");
-	warning("sub_154C5()");
+	displayFunction7();
+	displayFunction8();
+	displayFunction9();
+	displayFunction15();
+	displayFunction14();
 
 	displayFunction4();
 	free(tmpBuf);
 }
 
+void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3) {
+	debugC(1, kDebugEngine, "displayFunction13(buf, %d, %d, %d)", var1, var2, var3);
+
+	byte tmpByte1 = ((7 + (var2 >> 8) - (var2 & 0xFF)) << 4) & 0xFF;
+	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >>8) - (var3 & 0xFF)) << 3) & 0xFF;
+
+	int index = (tmpByte2 << 8) + tmpByte1;
+	int index2 = tmpByte1 << 8;
+
+	for (int i = 0; i < 32; i++) {
+		for (int j = 0; j < 32; j++) {
+			if (_bufferCubegfx[index2 + j] != 0)
+				buf[index] = _bufferCubegfx[index2 + j];
+		}
+		index += 256;
+	}
+}
+
+void LilliputEngine::displayFunction14() {
+	debugC(2, kDebugEngine, "displayFunction14()");
+
+	if (_scriptHandler->_byte16F08 == 1)
+		return;
+
+	if (_mouseDisplayX > 48)
+		displayFunction5();
+
+	int index = (16 * 320) + 64;
+	for (int i = 0; i < 176; i++) {
+		for (int j = 0; j < 256; j++)
+			((byte *)_mainSurface->getPixels())[index + j] = _buffer1_45k[(i * 256) + j];
+		index += 320;
+	}
+
+	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
+	_system->updateScreen();
+
+	displayFunction4();
+};
+
+void LilliputEngine::sub16217() {
+	debugC(2, kDebugEngine, "sub16217()");
+
+	_byte160FA = 0;
+	int index = _word10807_ERULES - 1;
+	_word16213 = _scriptHandler->_word12A00 << 3;
+	_word16215 = _scriptHandler->_word12A02 << 3;
+
+	for (int i = index; i >= 0; i--) {
+		if (_rulesBuffer2_5[i] != 0xFF) {
+			int index2 = _rulesBuffer2_5[i];
+			_rulesBuffer2_3[i] = _rulesBuffer2_3[index2] + _rulesBuffer2_7[i];
+			int tmpVal = _rulesBuffer2_6[i];
+			_rulesBuffer2_9[i] = _rulesBuffer2_9[index2];
+			int var3 = _rulesBuffer2_1[index2];
+			int var4 = _rulesBuffer2_2[index2];
+
+			switch (_rulesBuffer2_9[i]) {
+			case 0:
+				var3 -= tmpVal;
+				break;
+			case 1:
+				var4 += tmpVal;
+				break;
+			case 2:
+				var4 -= tmpVal;
+				break;
+			default:
+				var3 += tmpVal;
+				break;
+			}
+
+			_rulesBuffer2_1[i] = var3;
+			_rulesBuffer2_2[i] = var4;
+		}
+
+		_scriptHandler->_array16123[i] = (_rulesBuffer2_1[i] & 0xFF);
+		_scriptHandler->_array1614B[i] = (_rulesBuffer2_2[i] & 0xFF);
+		_scriptHandler->_array16173[i] = 0xFF;
+		_array1619B[i] = 0xFF;
+		_array161C3[i] = 0xFF;
+		_array161EB[i] = 0xFF;
+
+		int tmpVal2 = _rulesBuffer2_1[i] - _scriptHandler->_word12A00;
+		int tmpVal3 = _rulesBuffer2_2[i] - _scriptHandler->_word12A02;
+		if ((tmpVal2 >= 0) && (tmpVal2 <= 7) && (tmpVal3 >= 0) && (tmpVal3 <= 7)) {
+			_array16173[i] = tmpVal2;
+			_array1619B[i] = tmpVal3;
+			tmpVal2 = _rulesBuffer2_1[i] - _word16213;
+			tmpVal3 = _rulesBuffer2_2[i] - _word16213;
+			int tmpVal4 = _rulesBuffer2_3[i];
+			_array161C3[i] = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF;
+			_array161EB[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
+			_array160FB[_byte160FA] = i;
+			++_byte160FA;
+		}
+	}
+}
+
+void LilliputEngine::sub1652B(int var1) {
+	debugC(2, kDebugEngine, "sub1652B(%d)", var1);
+
+	if (_byte160FA < (var1 & 0xFF)) {
+		int index = _array160FB[var1 & 0xFF];
+		_byte16529 = _array16173[index];
+		_byte1652A = _array1619B[index];
+	} else {
+		_byte16529 = 0xFF;
+		_byte1652A = 0xFF;
+	}
+}
+
+void LilliputEngine::displayFunction15() {
+	debugC(2, kDebugEngine, "displayFunction15()");
+
+	sub16217();
+	_word16550 = 0;
+	sub1652B(0);
+
+	memcpy(_buffer1_45k, _buffer2_45k, 45056);
+
+	int index1 = (_scriptHandler->_word12A02 >> 8) + ((_scriptHandler->_word12A02 & 0xFF) << 8) + (_scriptHandler->_word12A00 << 2);
+	byte *map = &_bufferIsoMap[index1];
+
+	for (int i = 0; i < 8; i++) {
+		for (int j = 0; j < 8; j++) {
+			int tmpVal = (i << 8) + j;
+			if (map[1] != 0xFF) {
+				int var1 = map[1];
+				if (_rulesChunk9[var1] != 128)
+					var1 += _scriptHandler->_byte12A04;
+				displayFunction13(_buffer1_45k, var1, tmpVal, 1 << 8);
+			}
+			warning("sub_16553");
+
+			if (map[2] != 0xFF) {
+				int var1 = map[1];
+				if (_rulesChunk9[var1] != 128)
+					var1 += _scriptHandler->_byte12A04;
+				displayFunction13(_buffer1_45k, var1, tmpVal, 2 << 8);
+			}
+			map = &map[4];
+		}
+		map = &map[224];
+	}
+}
+
 void LilliputEngine::pollEvent() {
 	debugC(2, kDebugEngine, "pollEvent()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index a677c1b..88c8d9c 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -84,6 +84,8 @@ public:
 	struct18560 _arr18560[4];
 	byte _byte1714E;
 	byte _byte184F4;
+	byte _byte16529;
+	byte _byte1652A;
 	byte _sound_byte16F06;
 	byte _byte16F09;
 	byte _keyboard_nextIndex;
@@ -112,6 +114,7 @@ public:
 	int _word15BC8;
 	int _word15BCA;
 	int _word15AC2;
+	int _word16550;
 
 	int _array11D49[40];
 
@@ -158,11 +161,19 @@ public:
 	int _rulesBuffer13_2[20];
 	int _rulesBuffer13_3[20];
 	byte _rulesBuffer13_4[20];
-	byte _byte10999[40];
-	byte _byte109C1[40];
+	byte _array10999[40];
+	byte _array109C1[40];
 	byte _array15AC8[256];
-
+	byte _array160FB[40];
+	byte _array16173[40];
+	byte _array1619B[40];
+	byte _array161C3[40];
+	byte _array161EB[40];
+
+	byte _buffer1_45k[45056];
+	byte _buffer2_45k[45056];
 	byte _buffer3_45k[45056];
+	byte _buffer10_4032[4032];
 
 	const LilliputGameDescription *_gameDescription;
 	uint32 getFeatures() const;
@@ -174,7 +185,13 @@ public:
 	void displayFunction4();
 	void displayFunction5();
 	void displayFunction6();
+	void displayFunction7();
+	void displayFunction8();
+	void displayFunction9();
 	void displayFunction12();
+	void displayFunction13(byte *buf, int var1, int var2, int var3);
+	void displayFunction14();
+	void displayFunction15();
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
@@ -208,11 +225,16 @@ public:
 	byte _byte16F07_menuId;
 	byte _byte12FCE;
 	byte _byte129A0;
+	byte _byte160FA;
 	int _word10804;
+	int _word16213;
+	int _word16215;
 
 	void pollEvent();
 	void sub170EE(int index);
 	void sub130DD();
+	void sub16217();
+	void sub1652B(int var1);
 	void handleGameScripts();
 
 	// Temporary stubs
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 396bd41..8eccb26 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -848,7 +848,7 @@ int LilliputScript::getValue2() {
 		return (var1 << 8) + var2;
 		}
 	case 0xFA:
-		return ((_vm->_byte10999[_vm->_rulesBuffer2PrevIndx] << 8) + _vm->_byte109C1[_vm->_rulesBuffer2PrevIndx]);
+		return ((_vm->_array10999[_vm->_rulesBuffer2PrevIndx] << 8) + _vm->_array109C1[_vm->_rulesBuffer2PrevIndx]);
 	case 0xF9:
 		return ((_vm->_rulesBuffer2_15[4] << 8) + _vm->_rulesBuffer2_15[5]);
 	case 0xF8: {
@@ -1615,8 +1615,7 @@ void LilliputScript::OC_sub18099() {
 	_array122E9[index] = (curWord & 0xFF);
 	_array122FD[index] = (curWord >> 8);
 
-	warning("TODO: display function #8");
-	
+	_vm->displayFunction8();
 }
 void LilliputScript::OC_sub180C3() {
 	warning("OC_sub180C3");
@@ -1665,8 +1664,9 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 	_byte10806 = curWord + 0x30;
 
 	_vm->_bufferCubegfx = _vm->loadVGA(fileName, false);
-	warning("Display function 9");
-	warning("sub_1649F()");
+	_vm->displayFunction9();
+	_vm->displayFunction15();
+
 }
 
 void LilliputScript::OC_sub1834C() {
@@ -1677,12 +1677,14 @@ void LilliputScript::OC_sub1834C() {
 
 	_vm->_ptr_rulesBuffer2_15[3] = curWord;
 }
+
 void LilliputScript::OC_sub18359() {
 	warning("OC_sub18359");
 }
 void LilliputScript::OC_sub18367() {
 	warning("OC_sub18367");
 }
+
 void LilliputScript::OC_sub17D04() {
 	debugC(1, kDebugScript, "OC_sub17D04()");
 
@@ -1716,8 +1718,10 @@ void LilliputScript::OC_sub17E22() {
 void LilliputScript::OC_sub1844A() {
 	warning("OC_sub1844A");
 }
+
 void LilliputScript::OC_sub1847F() {
 	debugC(1, kDebugScript, "OC_sub1847F()");
+
 	byte *buf215Ptr = getBuffer215Ptr();
 	byte tmpVal = buf215Ptr[0];
 	int curWord = _currScript->readUint16LE();
@@ -1745,9 +1749,11 @@ void LilliputScript::OC_displayVGAFile() {
 	_vm->displayVGAFile(fileName);
 	warning("TODO: unkPaletteFunction_2");
 }
+
 void LilliputScript::OC_sub184D7() {
 	warning("OC_sub184D7");
 }
+
 void LilliputScript::OC_displayTitleScreen() {
 	debugC(1, kDebugScript, "OC_displayTitleScreen()");
 
@@ -1818,9 +1824,11 @@ void LilliputScript::OC_sub18678() {
 	_word15FFB = _currScript->readUint16LE();
 	_word15FFD = _currScript->readUint16LE();
 }
+
 void LilliputScript::OC_sub18690() {
 	warning("OC_sub18690");
 }
+
 void LilliputScript::OC_setWord10802() {
 	debugC(1, kDebugScript, "OC_setWord10802()");
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 07a7233..2d605f3 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -32,7 +32,17 @@ namespace Lilliput {
 class LilliputEngine;
 class LilliputScript {
 public:
+	byte _byte16F08;
+
 	byte _array10B29[40];
+	byte _array122E9[20];
+	byte _array16123[40];
+	byte _array1614B[40];
+	byte _array16173[40];
+
+	int _word12A00;
+	int _word12A02;
+	byte _byte12A04;
 
 	LilliputScript(LilliputEngine *vm);
 	~LilliputScript();
@@ -47,9 +57,7 @@ private:
 
 	byte _byte16F05_ScriptHandler;
 	byte _byte12A09;
-	byte _byte12A04;
 	byte _byte129A0;
-	byte _byte16F08;
 	byte _byte15FFA;
 	byte _byte1855D;
 	byte _byte10806;
@@ -57,15 +65,11 @@ private:
 	byte _byte16F02;
 
 	byte *_savedBuffer215Ptr;
-	byte _array122E9[20];
 	byte _array122FD[20];
 	byte _array128EF[40];
 	byte _array10AB1[40];
 	byte _array12811[40];
 	byte _array12839[40];
-	byte _array16123[40];
-	byte _array1614B[40];
-	byte _array16173[40];
 	byte _array10B51[40 * 40];
 
 	int _array12311[640];
@@ -76,8 +80,6 @@ private:
 	int _word10804;
 	int _word15FFB;
 	int _word15FFD;
-	int _word12A00;
-	int _word12A02;
 	int _word1855E;
 	int _word18776;
 


Commit: 0c0182d3648ea23806f320675c9f0d7b001b23b6
    https://github.com/scummvm/scummvm/commit/0c0182d3648ea23806f320675c9f0d7b001b23b6
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix to render cubes

We can see some isometric cubes but wrongly placed.

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 06edcba..8842177 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -418,8 +418,9 @@ void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3)
 	for (int i = 0; i < 32; i++) {
 		for (int j = 0; j < 32; j++) {
 			if (_bufferCubegfx[index2 + j] != 0)
-				buf[index] = _bufferCubegfx[index2 + j];
+				buf[index + j] = _bufferCubegfx[index2 + j];
 		}
+		index2 += 32;
 		index += 256;
 	}
 }
@@ -503,6 +504,9 @@ void LilliputEngine::sub16217() {
 			++_byte160FA;
 		}
 	}
+
+	warning("sub_161323");
+
 }
 
 void LilliputEngine::sub1652B(int var1) {


Commit: c67d5e127d06feeb72bb2257f3f559c864187b08
    https://github.com/scummvm/scummvm/commit/c67d5e127d06feeb72bb2257f3f559c864187b08
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Isomap rendering complete

Fixed more small things, the map renders as in game.

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8842177..89a6394 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -410,10 +410,10 @@ void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3)
 	debugC(1, kDebugEngine, "displayFunction13(buf, %d, %d, %d)", var1, var2, var3);
 
 	byte tmpByte1 = ((7 + (var2 >> 8) - (var2 & 0xFF)) << 4) & 0xFF;
-	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >>8) - (var3 & 0xFF)) << 3) & 0xFF;
+	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >> 7) ) << 3) & 0xFF;
 
 	int index = (tmpByte2 << 8) + tmpByte1;
-	int index2 = tmpByte1 << 8;
+	int index2 = var1 << 10;
 
 	for (int i = 0; i < 32; i++) {
 		for (int j = 0; j < 32; j++) {
@@ -536,7 +536,7 @@ void LilliputEngine::displayFunction15() {
 
 	for (int i = 0; i < 8; i++) {
 		for (int j = 0; j < 8; j++) {
-			int tmpVal = (i << 8) + j;
+			int tmpVal = (j << 8) + i;
 			if (map[1] != 0xFF) {
 				int var1 = map[1];
 				if (_rulesChunk9[var1] != 128)
@@ -546,14 +546,14 @@ void LilliputEngine::displayFunction15() {
 			warning("sub_16553");
 
 			if (map[2] != 0xFF) {
-				int var1 = map[1];
+				int var1 = map[2];
 				if (_rulesChunk9[var1] != 128)
 					var1 += _scriptHandler->_byte12A04;
 				displayFunction13(_buffer1_45k, var1, tmpVal, 2 << 8);
 			}
-			map = &map[4];
+			map += 4;
 		}
-		map = &map[224];
+		map += 224;
 	}
 }
 


Commit: 3780999f3d4eaea606bea4a2f800cf4731dd69e1
    https://github.com/scummvm/scummvm/commit/3780999f3d4eaea606bea4a2f800cf4731dd69e1
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement two more display functions

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 89a6394..7ddf193 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -285,6 +285,20 @@ void LilliputEngine::displayFunction2(byte *buf, int var2, int var4) {
 	}
 }
 
+void LilliputEngine::displayFunction3(int var1, int var2, int var4) {
+	debugC(2, kDebugEngine, "displayFunction3(%d, %d, %d)", var1, var2, var4);
+
+	int tmpVal = ((var4 >> 8) + (var4 & 0xFF));
+	int index = var2 + tmpVal + (tmpVal >> 2);
+	int col = var1 & 0xFF;
+	for (int i = 0; i < 16; i++) {
+		for (int j = 0; j < 16; j++) {
+			((byte *)_mainSurface->getPixels())[index + j] = col;
+		}
+		index += 320;
+	}
+}
+
 // display mouse cursor
 void LilliputEngine::displayFunction4() {
 	debugC(2, kDebugEngine, "displayFunction4()");
@@ -385,6 +399,28 @@ void LilliputEngine::displayFunction9() {
 
 }
 
+void LilliputEngine::displayFunction10() {
+	debugC(2, kDebugEngine, "displayFunction10()");
+	static const byte _array15976[16] = {244, 248, 250, 250, 252, 252, 252, 252, 252, 252, 252, 252, 250, 250, 248, 244};
+
+	displayFunction5();
+
+	int index = 192;
+	int tmpIndex;
+	int var3;
+
+	for (int i = 0; i < 16; i++) {
+		var3 = _array15976[i];
+		tmpIndex = index - (var3 / 2);
+		for (int j = 0; j < 16; j++) {
+			((byte *)_mainSurface->getPixels())[tmpIndex + j] = 17;
+		}
+		index += 320;
+	}
+
+	displayFunction4();
+}
+
 void LilliputEngine::displayFunction12() {
 	debugC(1, kDebugEngine, "displayFunction12()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 88c8d9c..1178439 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -182,12 +182,14 @@ public:
 	void displayFunction1(byte *buf, int var1, int var2, int var4);
 	void displayFunction1a(byte *buf, int var2, int var4);
 	void displayFunction2(byte *buf, int var2, int var4);
+	void displayFunction3(int var1, int var2, int var4);
 	void displayFunction4();
 	void displayFunction5();
 	void displayFunction6();
 	void displayFunction7();
 	void displayFunction8();
 	void displayFunction9();
+	void displayFunction10();
 	void displayFunction12();
 	void displayFunction13(byte *buf, int var1, int var2, int var3);
 	void displayFunction14();


Commit: eeb69f46bcdbb088fb63c06647683fbebdaec9dc
    https://github.com/scummvm/scummvm/commit/eeb69f46bcdbb088fb63c06647683fbebdaec9dc
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement fade in/fade out

Fade from/to black

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7ddf193..bf899ea 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -648,7 +648,6 @@ byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 		remainingSize -= 768;
 
 		fixPaletteEntries(_curPalette, 256);
-		_system->getPaletteManager()->setPalette(_curPalette, 0, 256);
 	}
 
 	uint8 curByte;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 8eccb26..c9e7607 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -24,6 +24,8 @@
 #include "lilliput/script.h"
 #include "common/debug.h"
 
+#include "common/system.h"
+
 namespace Lilliput {
 
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
@@ -1649,10 +1651,28 @@ void LilliputScript::OC_sub182EC() {
 	warning("OC_sub182EC");
 }
 void LilliputScript::OC_unkPaletteFunction_1() {
-	warning("OC_unkPaletteFunction_1");
+
+	byte palette[768];
+	for (int fade = 256; fade >= 0;	fade -= 8) {
+		for (int i = 0; i < 768; i++) {
+			palette[i] = (_vm->_curPalette[i] * fade) >> 8;
+		}
+		_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
+		_vm->_system->updateScreen();
+		_vm->_system->delayMillis(33);
+	}
 }
 void LilliputScript::OC_unkPaletteFunction_2() {
-	warning("OC_unkPaletteFunction_2");
+
+	byte palette[768];
+	for (int fade = 8; fade <= 256;	fade += 8) {
+		for (int i = 0; i < 768; i++) {
+			palette[i] = (_vm->_curPalette[i] * fade) >> 8;
+		}
+		_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
+		_vm->_system->updateScreen();
+		_vm->_system->delayMillis(33);
+	}
 }
 
 void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
@@ -1741,13 +1761,13 @@ void LilliputScript::OC_displayVGAFile() {
 	debugC(1, kDebugScript, "OC_displayVGAFile()");
 
 	_byte12A09 = 1;
-	warning("TODO: unkPaletteFunction_1");
+	OC_unkPaletteFunction_1();
 	int curWord = _currScript->readUint16LE();
 	int index = _vm->_rulesChunk3[curWord];
 	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
 	_word1881B = -1;
 	_vm->displayVGAFile(fileName);
-	warning("TODO: unkPaletteFunction_2");
+	OC_unkPaletteFunction_2();
 }
 
 void LilliputScript::OC_sub184D7() {
@@ -1789,14 +1809,14 @@ void LilliputScript::OC_displayTitleScreen() {
 void LilliputScript::OC_sub1853B() {
 	debugC(1, kDebugScript, "OC_initArr1853B()");
 
-	warning("TODO: unkPaletteFunction_1");
+	OC_unkPaletteFunction_1();
 	_byte16F08 = 0;
 	_byte15FFA = 0;
 	sub130B6();
 
 	_vm->displayFunction12();
 
-	warning("TODO: unkPaletteFunction_2");
+	OC_unkPaletteFunction_2();
 	_byte12A09 = 0;
 	warning("TODO: call sound function #5");
 }


Commit: 4fd850776872ad2715f054f3e3cc24684e499297
    https://github.com/scummvm/scummvm/commit/4fd850776872ad2715f054f3e3cc24684e499297
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Start implementing engine update (int 8 replacement in the original)

The screen now moves to the point expected in intro

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index bf899ea..986b6c7 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -112,6 +112,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 
 	_console = new LilliputConsole(this);
 	_rnd = 0;
+	_int8installed = false;
 	_mouseX = 0;
 	_mouseY = 0;
 	_oldMouseX = 0;
@@ -131,6 +132,12 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte160FA = 0;
 	_byte16529 = 0;
 	_byte1652A = 0;
+	_byte12A04 = 0;
+	_byte12A05 = 10;
+	_byte12A06 = 2;
+	_byte12A07 = 0;
+	_byte12A08 = 0;
+	_byte12A09 = 0;
 
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
@@ -196,6 +203,42 @@ GUI::Debugger *LilliputEngine::getDebugger() {
 	return _console;
 }
 
+void LilliputEngine::update() {
+	newInt8();
+	pollEvent();
+}
+
+void LilliputEngine::newInt8() {
+	if (!_int8installed)
+		return;
+
+	if (_byte12A06 == 0) {
+		_byte12A06 = 2;
+		_byte12A07 ^= 1;
+	}
+	--_byte12A06;
+	// TODO: check 'out 20h, 20h'
+
+	// if (_soundEnabled)
+	warning("TODO: call sound function #1");
+
+	if (_byte12A08 != 1) {
+		_byte12A08 = 1;
+		if (_byte12A05 != 0)
+			--_byte12A05;
+		else {
+			_byte12A05 = 10;
+			if (_sound_byte16F06 != 0)
+				--_sound_byte16F06;
+
+			_byte12A04 ^= 1;
+			if (_byte12A09 != 1)
+				displayFunction16();
+		}
+		_byte12A08 = 0;
+	}
+}
+
 bool LilliputEngine::hasFeature(EngineFeature f) const {
 	return (f == kSupportsRTL) || (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime);
 }
@@ -285,6 +328,7 @@ void LilliputEngine::displayFunction2(byte *buf, int var2, int var4) {
 	}
 }
 
+// Fill 16x16 rect
 void LilliputEngine::displayFunction3(int var1, int var2, int var4) {
 	debugC(2, kDebugEngine, "displayFunction3(%d, %d, %d)", var1, var2, var4);
 
@@ -399,6 +443,7 @@ void LilliputEngine::displayFunction9() {
 
 }
 
+// Display dialog bubble
 void LilliputEngine::displayFunction10() {
 	debugC(2, kDebugEngine, "displayFunction10()");
 	static const byte _array15976[16] = {244, 248, 250, 250, 252, 252, 252, 252, 252, 252, 252, 252, 250, 250, 248, 244};
@@ -412,7 +457,8 @@ void LilliputEngine::displayFunction10() {
 	for (int i = 0; i < 16; i++) {
 		var3 = _array15976[i];
 		tmpIndex = index - (var3 / 2);
-		for (int j = 0; j < 16; j++) {
+		var3 &= 0xFE;
+		for (int j = 0; j < var3; j++) {
 			((byte *)_mainSurface->getPixels())[tmpIndex + j] = 17;
 		}
 		index += 320;
@@ -593,6 +639,113 @@ void LilliputEngine::displayFunction15() {
 	}
 }
 
+void LilliputEngine::displayFunction16() {
+	debugC(2, kDebugEngine, "displayFunction16()");
+
+	if (_scriptHandler->_byte16F08 == 1) {
+		warning("sub_15F31");
+		warning("sub_15F0C");
+		warning("sub_16626");
+		warning("sub_12F37");
+		warning("sub_16CA0");
+		warning("sub_16EBC");
+		warning("sub_171CF");
+		warning("sub_15EAE");
+	} else {
+		sub1638C();
+		warning("sub_189DE");
+		displayFunction15();
+		displayFunction14();
+		warning("sub_16626");
+		warning("sub_12F37");
+		warning("sub_16CA0");
+		warning("sub_16EBC");
+		warning("sub_171CF");
+		warning("sub_130EE");
+		warning("sub_12FE5");
+		warning("sub_15FFF");
+	}
+}
+
+// Move "window" to x/y
+void LilliputEngine::sub1638C() {
+	debugC(2, kDebugEngine, "sub1638C()");
+
+	if (_scriptHandler->_word10802 == 0xFFFF)
+		return;
+
+	int var2 = (_rulesBuffer2_1[_scriptHandler->_word10802] >> 3) - _scriptHandler->_word12A00;
+	int var4 = (_rulesBuffer2_2[_scriptHandler->_word10802] >> 3) - _scriptHandler->_word12A02;
+	int var1 = _scriptHandler->_word12A00;
+
+	if (var2 >= 1) {
+		if (var2 >= 6) {
+			var1 += 4;
+			if (var1 > 56)
+				var1 = 56;
+		}
+	} else {
+		var1 -= 4;
+		if (var1 < 0)
+			var1 = 0;
+	}
+
+	int var3 = _scriptHandler->_word12A02;
+	if (var4 >= 1) {
+		if (var4 > 6) {
+			var3 += 4;
+			if (var3 >= 56)
+				var3 = 56;
+		}
+	} else {
+		var3 -= 4;
+		if (var3 < 0)
+			var3 = 0;
+	}
+
+	sub163F0(var1, var3);
+}
+
+void LilliputEngine::sub163F0(int var1, int var3) {
+	debugC(2, kDebugEngine, "sub163F0(%d, %d)", var1, var3);
+
+	if ((var1 == _scriptHandler->_word12A00) && (var3 = _scriptHandler->_word12A02))
+		return;
+
+	int var2 = 0;
+	if (var1 != _scriptHandler->_word12A00) {
+		if (var1 < _scriptHandler->_word12A00)
+			--var2;
+		else
+			++var2;
+	}
+
+	int var4 = 0;
+	if (var3!= _scriptHandler->_word12A02) {
+		if (var3 < _scriptHandler->_word12A02)
+			--var4;
+		else
+			++var4;
+	}
+
+	do {
+		_scriptHandler->_word12A00 += var2;
+		_scriptHandler->_word12A02 += var4;
+
+		displayFunction9();
+		displayFunction15();
+		displayFunction14();
+
+		if (var1 == _scriptHandler->_word12A00)
+			var2 = 0;
+
+		if (var3 == _scriptHandler->_word12A02)
+			var4 = 0;
+	} while ((var2 != 0) && (var4 !=0));
+
+	warning("Sound function #5");
+}
+
 void LilliputEngine::pollEvent() {
 	debugC(2, kDebugEngine, "pollEvent()");
 
@@ -1002,10 +1155,13 @@ Common::Error LilliputEngine::run() {
 	//TODO: Init sound/music player
 	_scriptHandler->runScript(Common::MemoryReadStream(_initScript, _initScript_size));
 
+	_int8installed = true;
+
 	while(!_shouldQuit) {
 		handleMenu();
 		handleGameScripts();
 		// To be removed when handled in the previous fonctions
+		update();
 		pollEvent();
 	}
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 1178439..c1d8f55 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -90,6 +90,12 @@ public:
 	byte _byte16F09;
 	byte _keyboard_nextIndex;
 	byte _keyboard_oldIndex;
+	byte _byte12A04;
+	byte _byte12A05;
+	byte _byte12A06;
+	byte _byte12A07;
+	byte _byte12A08;
+	byte _byte12A09;
 
 	byte _buffer1[45056];
 	byte _buffer2[45056];
@@ -104,7 +110,8 @@ public:
 	byte _curPalette[768];
 
 	bool _saveFlag;
-	
+	bool _int8installed;
+
 	int _word10800_ERULES;
 	int _word10807_ERULES;
 	int _word16EFA;
@@ -179,6 +186,9 @@ public:
 	uint32 getFeatures() const;
 	const char *getGameId() const;
 
+	void newInt8();
+	void update();
+
 	void displayFunction1(byte *buf, int var1, int var2, int var4);
 	void displayFunction1a(byte *buf, int var2, int var4);
 	void displayFunction2(byte *buf, int var2, int var4);
@@ -194,6 +204,10 @@ public:
 	void displayFunction13(byte *buf, int var1, int var2, int var3);
 	void displayFunction14();
 	void displayFunction15();
+	void displayFunction16();
+
+	void sub1638C();
+	void sub163F0(int var1, int var3);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index c9e7607..4aab2f6 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -585,7 +585,7 @@ void LilliputScript::runScript(Common::MemoryReadStream script) {
 	_byte16F05_ScriptHandler = 1;
 	
 	while (handleOpcode(&script) != 0xFF)
-		;
+		_vm->update();
 }
 
 void LilliputScript::runMenuScript(Common::MemoryReadStream script) {
@@ -594,7 +594,7 @@ void LilliputScript::runMenuScript(Common::MemoryReadStream script) {
 	_byte16F05_ScriptHandler = 0;
 	
 	while (handleOpcode(&script) == 0)
-		;
+		_vm->update();
 }
 
 void LilliputScript::sub185ED(byte index, byte subIndex) {
@@ -1789,7 +1789,7 @@ void LilliputScript::OC_displayTitleScreen() {
 
 	for (;;) {
 		sub185B4_display();
-		_vm->pollEvent();
+		_vm->update();
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
 			_vm->_byte16F09 = _vm->_keyboard_getch();
 			_vm->_keyboard_getch();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 2d605f3..6113fd8 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -42,6 +42,7 @@ public:
 
 	int _word12A00;
 	int _word12A02;
+	int _word10802;
 	byte _byte12A04;
 
 	LilliputScript(LilliputEngine *vm);
@@ -76,7 +77,6 @@ private:
 
 	int _word1881B;
 	int _word16F00;
-	int _word10802;
 	int _word10804;
 	int _word15FFB;
 	int _word15FFD;


Commit: c3ca01737b0f484a733fa9dff3fb128a6daa8569
    https://github.com/scummvm/scummvm/commit/c3ca01737b0f484a733fa9dff3fb128a6daa8569
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Int8 called every 20ms

Makes also the title stars work

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 986b6c7..86bd94e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -204,13 +204,17 @@ GUI::Debugger *LilliputEngine::getDebugger() {
 }
 
 void LilliputEngine::update() {
-	newInt8();
-	pollEvent();
+	
+	// update every 20 ms.
+	int currentTime = _system->getMillis();
+	if(currentTime - _lastTime > 20) {
+		_lastTime += 20;
+		newInt8();
+		pollEvent();
+	}
 }
 
 void LilliputEngine::newInt8() {
-	if (!_int8installed)
-		return;
 
 	if (_byte12A06 == 0) {
 		_byte12A06 = 2;
@@ -218,6 +222,10 @@ void LilliputEngine::newInt8() {
 	}
 	--_byte12A06;
 	// TODO: check 'out 20h, 20h'
+	
+	// hack for the title stars because _int8installed is not set at the good place for the moment
+	//if (!_int8installed)
+	//	return;
 
 	// if (_soundEnabled)
 	warning("TODO: call sound function #1");
@@ -232,7 +240,7 @@ void LilliputEngine::newInt8() {
 				--_sound_byte16F06;
 
 			_byte12A04 ^= 1;
-			if (_byte12A09 != 1)
+			if (_byte12A09 != 1 && _int8installed) // hack for the title stars because _int8installed is not set at the good place for the moment
 				displayFunction16();
 		}
 		_byte12A08 = 0;
@@ -709,7 +717,7 @@ void LilliputEngine::sub1638C() {
 void LilliputEngine::sub163F0(int var1, int var3) {
 	debugC(2, kDebugEngine, "sub163F0(%d, %d)", var1, var3);
 
-	if ((var1 == _scriptHandler->_word12A00) && (var3 = _scriptHandler->_word12A02))
+	if ((var1 == _scriptHandler->_word12A00) && (var3 == _scriptHandler->_word12A02))
 		return;
 
 	int var2 = 0;
@@ -1152,6 +1160,10 @@ Common::Error LilliputEngine::run() {
 
 	loadRules();
 
+	_lastTime = _system->getMillis();
+
+	
+
 	//TODO: Init sound/music player
 	_scriptHandler->runScript(Common::MemoryReadStream(_initScript, _initScript_size));
 
@@ -1162,7 +1174,6 @@ Common::Error LilliputEngine::run() {
 		handleGameScripts();
 		// To be removed when handled in the previous fonctions
 		update();
-		pollEvent();
 	}
 
 	return Common::kNoError;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index c1d8f55..adda393 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -259,6 +259,7 @@ public:
 protected:
 	Common::EventManager *_eventMan;
 	bool _shouldQuit;
+	int _lastTime;
 
 	// Engine APIs
 	Common::Error run();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 4aab2f6..576e738 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -597,12 +597,21 @@ void LilliputScript::runMenuScript(Common::MemoryReadStream script) {
 		_vm->update();
 }
 
+void LilliputScript::sub1863B() {
+	_vm->_arr18560[0]._field0 = 0;
+	_vm->_arr18560[1]._field0 = 0;
+	_vm->_arr18560[2]._field0 = 0;
+	_vm->_arr18560[3]._field0 = 0;
+	_word1855E = 0;
+}
+
+
 void LilliputScript::sub185ED(byte index, byte subIndex) {
 	debugC(2, kDebugScript, "sub185ED");
 	if (_vm->_arr18560[index]._field0 != 1)
 		return;
 
-	_vm->displayFunction1(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[0], _vm->_arr18560[index]._field1, _vm->_arr18560[index]._field3);
+	_vm->displayFunction1(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[subIndex], _vm->_arr18560[index]._field1, _vm->_arr18560[index]._field3);
 }
 
 byte LilliputScript::compareValues(byte var1, int oper, int var2) {
@@ -665,11 +674,13 @@ void LilliputScript::computeOperation(byte *bufPtr, int oper, int var2) {
 	}
 }
 
+
+
 void LilliputScript::sub185B4_display() {
-	if (_byte12A04 == _byte1855D)
+	if (_vm->_byte12A04 == _byte1855D)
 		return;
 
-	_byte1855D = _byte12A04;
+	_byte1855D = _vm->_byte12A04;
 	
 	assert(_word1855E < 8);
 	int subIndex = _word1855E;
@@ -874,6 +885,7 @@ int LilliputScript::getValue2() {
 	}
 }
 
+
 void LilliputScript::sub130B6() {
 	debugC(1, kDebugScript, "sub130B6()");
 	assert(_vm->_word12F68_ERULES <= 20);
@@ -1651,7 +1663,7 @@ void LilliputScript::OC_sub182EC() {
 	warning("OC_sub182EC");
 }
 void LilliputScript::OC_unkPaletteFunction_1() {
-
+	sub1863B();
 	byte palette[768];
 	for (int fade = 256; fade >= 0;	fade -= 8) {
 		for (int i = 0; i < 768; i++) {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 6113fd8..27140e6 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -87,6 +87,7 @@ private:
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 
+	void sub1863B();
 	void sub185ED(byte index, byte subIndex);
 	void sub185B4_display();
 	void sub1823E(byte var1, byte var2, byte *curBufPtr);


Commit: 0139ce6853b65edc4c1b57db4369124a2ace3d5e
    https://github.com/scummvm/scummvm/commit/0139ce6853b65edc4c1b57db4369124a2ace3d5e
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix 20ms frame glitch

Skip late frames if we are too slow

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 86bd94e..e066996 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -208,7 +208,7 @@ void LilliputEngine::update() {
 	// update every 20 ms.
 	int currentTime = _system->getMillis();
 	if(currentTime - _lastTime > 20) {
-		_lastTime += 20;
+		_lastTime += ((currentTime - _lastTime) / 20) * 20;
 		newInt8();
 		pollEvent();
 	}


Commit: 70f1d349c538842ed981f0950ff55f05111adb2e
    https://github.com/scummvm/scummvm/commit/70f1d349c538842ed981f0950ff55f05111adb2e
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement some more parts of "int 8"

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index e066996..eb49ea1 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -138,6 +138,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12A07 = 0;
 	_byte12A08 = 0;
 	_byte12A09 = 0;
+	_byte1881D = 0;
+	_byte16552 = 0;
 
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
@@ -162,6 +164,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array1619B[i] = 0xFF;
 		_array161C3[i] = 0;
 		_array161EB[i] = 0;
+		_array12299[i] = 0xFF;
 
 		_array11D49[i] = 0xFFFF;
 		_rulesBuffer2_1[i] = 0xFFFF;
@@ -204,7 +207,7 @@ GUI::Debugger *LilliputEngine::getDebugger() {
 }
 
 void LilliputEngine::update() {
-	
+
 	// update every 20 ms.
 	int currentTime = _system->getMillis();
 	if(currentTime - _lastTime > 20) {
@@ -222,7 +225,7 @@ void LilliputEngine::newInt8() {
 	}
 	--_byte12A06;
 	// TODO: check 'out 20h, 20h'
-	
+
 	// hack for the title stars because _int8installed is not set at the good place for the moment
 	//if (!_int8installed)
 	//	return;
@@ -633,7 +636,7 @@ void LilliputEngine::displayFunction15() {
 					var1 += _scriptHandler->_byte12A04;
 				displayFunction13(_buffer1_45k, var1, tmpVal, 1 << 8);
 			}
-			warning("sub_16553");
+			sub16553(map);
 
 			if (map[2] != 0xFF) {
 				int var1 = map[2];
@@ -653,7 +656,7 @@ void LilliputEngine::displayFunction16() {
 	if (_scriptHandler->_byte16F08 == 1) {
 		warning("sub_15F31");
 		warning("sub_15F0C");
-		warning("sub_16626");
+		sub16626();
 		warning("sub_12F37");
 		warning("sub_16CA0");
 		warning("sub_16EBC");
@@ -661,10 +664,10 @@ void LilliputEngine::displayFunction16() {
 		warning("sub_15EAE");
 	} else {
 		sub1638C();
-		warning("sub_189DE");
+		sub189DE();
 		displayFunction15();
 		displayFunction14();
-		warning("sub_16626");
+		sub16626();
 		warning("sub_12F37");
 		warning("sub_16CA0");
 		warning("sub_16EBC");
@@ -675,7 +678,19 @@ void LilliputEngine::displayFunction16() {
 	}
 }
 
-// Move "window" to x/y
+void LilliputEngine::displayFunction17() {
+	debugC(2, kDebugEngine, "displayFunction17()");
+
+	displayFunction5();
+
+	for (int i = 0; i < 16; i++)
+		for (int j = 0; j < 252; j++)
+			((byte *)_mainSurface->getPixels())[66 + (i * 320) + j] = _buffer10_4032[(252 * i) + j];
+
+	displayFunction4();
+}
+
+// Move view port to x/y
 void LilliputEngine::sub1638C() {
 	debugC(2, kDebugEngine, "sub1638C()");
 
@@ -754,6 +769,131 @@ void LilliputEngine::sub163F0(int var1, int var3) {
 	warning("Sound function #5");
 }
 
+void LilliputEngine::sub16553(byte *buf) {
+	debugC(2, kDebugEngine, "sub16553()");
+
+	if ((_byte16529 != 0) || (_byte1652A != 0))
+		return;
+
+	_byte16552 = 0;
+
+	if (buf[1] != 0xFF) {
+		int tmpIndex = buf[1];
+		if (_rulesChunk9[tmpIndex] == 16)
+			++_byte16552;
+	}
+
+	int index = _array160FB[_word16550];
+	int var2 = (_array161C3[index] << 8) + _array161EB[index];
+
+	if (index == _scriptHandler->_word1881B)
+		warning("sub_1546F(%d)", var2);
+
+	if (_byte16552 != 1) {
+		int var3 = _rulesBuffer2_9[index];
+		int var1 = _rulesBuffer2_4[index];
+
+		if (var1 != 0xFFFF) {
+			var1 += _scriptHandler->_array10AB1[index];
+			if (var3 != 1)
+				var1 += _rulesBuffer2_8[index];
+
+			if (_array12299[index] != 0xFF) {
+				var1 = _array12299[index] + 82;
+				--_array12299[index];
+				var1 = -var1;
+			}
+
+			warning("sub_152FC");
+		}
+	}
+
+	++_word16550;
+	sub1652B(_word16550);
+
+	sub16553(buf);
+}
+
+void LilliputEngine::sub189DE() {
+	debugC(2, kDebugEngine, "sub189DE()");
+
+	if (_byte1881D != 0) {
+		--_byte1881D;
+		if (_byte1881D != 0) {
+			displayFunction17();
+			_scriptHandler->_word1881B = 0xFFFF;
+		}
+	}
+}
+
+void LilliputEngine::sub16626() {
+	debugC(2, kDebugEngine, "sub16626()");
+
+	int index = _word10807_ERULES - 1;
+	int result;
+	while (index >= 0) {
+		result = 0;
+		while (result != 2) {
+			int var2 = _scriptHandler->_array12811[index];
+			if (var2 == 16)
+				break;
+			var2 = (var2 * 2) + (index << 5);
+			int var1 = _scriptHandler->_array12311[var2];
+			var2 = ((var2 & 0xFF00) + (var1 >> 8)) >> 3;
+			var2 &= 0xFE;
+
+			// temporary hack
+			result = 2;
+
+			switch (var2 / 2) {
+			case 0:
+				warning("result = sub_16675");
+				break;
+			case 1:
+				warning("result = sub_166DD");
+				break;
+			case 2:
+			case 3:
+			case 4:
+			case 5:
+			case 6:
+			case 7:
+			case 8:
+			case 9:
+				warning("result = sub_16672");
+				break;
+			case 10:
+				warning("result = sub_1675D");
+				break;
+			case 11:
+				warning("result = sub_16729");
+				break;
+			case 12:
+				warning("result = sub_16799");
+				break;
+			case 13:
+				warning("result = sub_16722");
+				break;
+			case 14:
+				warning("result = sub_166F7");
+				break;
+			case 15:
+				warning("result = sub_166EA");
+				break;
+			default:
+				error("sub16626 - unexpected value %d", var2 / 2);
+				break;
+			}
+			if (result == 1) {
+				++_scriptHandler->_array12811[index];
+				if (_scriptHandler->_array12811[index] == 16)
+					_scriptHandler->_array10B29[index] = 1;
+			}
+		}
+		--index;
+	}
+}
+
 void LilliputEngine::pollEvent() {
 	debugC(2, kDebugEngine, "pollEvent()");
 
@@ -1162,7 +1302,7 @@ Common::Error LilliputEngine::run() {
 
 	_lastTime = _system->getMillis();
 
-	
+
 
 	//TODO: Init sound/music player
 	_scriptHandler->runScript(Common::MemoryReadStream(_initScript, _initScript_size));
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index adda393..8a3f87c 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -96,6 +96,8 @@ public:
 	byte _byte12A07;
 	byte _byte12A08;
 	byte _byte12A09;
+	byte _byte1881D;
+	byte _byte16552;
 
 	byte _buffer1[45056];
 	byte _buffer2[45056];
@@ -176,6 +178,7 @@ public:
 	byte _array1619B[40];
 	byte _array161C3[40];
 	byte _array161EB[40];
+	byte _array12299[40];
 
 	byte _buffer1_45k[45056];
 	byte _buffer2_45k[45056];
@@ -205,9 +208,13 @@ public:
 	void displayFunction14();
 	void displayFunction15();
 	void displayFunction16();
+	void displayFunction17();
 
 	void sub1638C();
 	void sub163F0(int var1, int var3);
+	void sub189DE();
+	void sub16626();
+	void sub16553(byte *buf);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 27140e6..662538a 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -33,17 +33,22 @@ class LilliputEngine;
 class LilliputScript {
 public:
 	byte _byte16F08;
+	byte _byte12A04;
 
 	byte _array10B29[40];
 	byte _array122E9[20];
 	byte _array16123[40];
 	byte _array1614B[40];
 	byte _array16173[40];
+	byte _array12811[40];
+	byte _array10AB1[40];
 
 	int _word12A00;
 	int _word12A02;
 	int _word10802;
-	byte _byte12A04;
+	int _word1881B;
+
+	int _array12311[640];
 
 	LilliputScript(LilliputEngine *vm);
 	~LilliputScript();
@@ -68,14 +73,9 @@ private:
 	byte *_savedBuffer215Ptr;
 	byte _array122FD[20];
 	byte _array128EF[40];
-	byte _array10AB1[40];
-	byte _array12811[40];
 	byte _array12839[40];
 	byte _array10B51[40 * 40];
 
-	int _array12311[640];
-
-	int _word1881B;
 	int _word16F00;
 	int _word10804;
 	int _word15FFB;


Commit: f2512b82c2fcd991a0a6d7f0c83bdb0aa438681e
    https://github.com/scummvm/scummvm/commit/f2512b82c2fcd991a0a6d7f0c83bdb0aa438681e
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Put sound stubs in a separated class

Changed paths:
  A engines/lilliput/sound.cpp
  A engines/lilliput/sound.h
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/module.mk
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index eb49ea1..0014ec3 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -33,6 +33,7 @@
 #include "lilliput/lilliput.h"
 #include "engines/util.h"
 #include "lilliput/script.h"
+#include "lilliput/sound.h"
 
 namespace Lilliput {
 
@@ -109,6 +110,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_system = syst;
 	DebugMan.addDebugChannel(kDebugEngine, "Engine", "Engine debug level");
 	DebugMan.addDebugChannel(kDebugScript, "Script", "Script debug level");
+	DebugMan.addDebugChannel(kDebugSound, "Sound", "Sound debug level");
 
 	_console = new LilliputConsole(this);
 	_rnd = 0;
@@ -125,6 +127,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_skipDisplayFlag2 = 0;
 
 	_scriptHandler = new LilliputScript(this);
+	_soundHandler = new LilliputSound(this);
 
 	_byte1714E = 0;
 	_byte12FCE = 0;
@@ -231,7 +234,7 @@ void LilliputEngine::newInt8() {
 	//	return;
 
 	// if (_soundEnabled)
-	warning("TODO: call sound function #1");
+	_soundHandler->contentFct1();
 
 	if (_byte12A08 != 1) {
 		_byte12A08 = 1;
@@ -766,7 +769,7 @@ void LilliputEngine::sub163F0(int var1, int var3) {
 			var4 = 0;
 	} while ((var2 != 0) && (var4 !=0));
 
-	warning("Sound function #5");
+	_soundHandler->contentFct5();
 }
 
 void LilliputEngine::sub16553(byte *buf) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8a3f87c..298a367 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -25,6 +25,7 @@
 
 #include "lilliput/console.h"
 #include "lilliput/script.h"
+#include "lilliput/sound.h"
 
 #include "common/file.h"
 #include "engines/engine.h"
@@ -55,8 +56,9 @@ enum GameType {
 };
 
 enum LilliputDebugChannels {
-	kDebugEngine    = 1 <<  0,
-	kDebugScript    = 1 <<  1
+	kDebugEngine    = 1 << 0,
+	kDebugScript    = 1 << 1,
+	kDebugSound     = 1 << 2
 };
 
 struct LilliputGameDescription;
@@ -79,6 +81,7 @@ public:
 
 	Common::RandomSource *_rnd;
 	LilliputScript *_scriptHandler;
+	LilliputSound *_soundHandler;
 	Graphics::Surface *_mainSurface;
 
 	struct18560 _arr18560[4];
diff --git a/engines/lilliput/module.mk b/engines/lilliput/module.mk
index 6f701a3..807f536 100644
--- a/engines/lilliput/module.mk
+++ b/engines/lilliput/module.mk
@@ -4,7 +4,8 @@ MODULE_OBJS = \
 	console.o \
 	detection.o \
 	lilliput.o \
-	script.o
+	script.o \
+	sound.o
 
 MODULE_DIRS += \
 	engines/lilliput
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 576e738..a6a10e5 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1819,7 +1819,7 @@ void LilliputScript::OC_displayTitleScreen() {
 }
 
 void LilliputScript::OC_sub1853B() {
-	debugC(1, kDebugScript, "OC_initArr1853B()");
+	debugC(1, kDebugScript, "OC_sub1853B()");
 
 	OC_unkPaletteFunction_1();
 	_byte16F08 = 0;
@@ -1830,7 +1830,8 @@ void LilliputScript::OC_sub1853B() {
 
 	OC_unkPaletteFunction_2();
 	_byte12A09 = 0;
-	warning("TODO: call sound function #5");
+	
+	_vm->_soundHandler->contentFct5();
 }
 
 void LilliputScript::OC_sub1864D() {
@@ -1884,7 +1885,7 @@ void LilliputScript::OC_sub186E5_snd() {
 	byte var2l = (_word12A02 & 0xFF);
 	int var1 = _currScript->readUint16LE();
 
-	warning("TODO: call sound function #2");
+	_vm->_soundHandler->contentFct2();
 }
 
 void LilliputScript::OC_sub1870A_snd() {
@@ -1894,27 +1895,30 @@ void LilliputScript::OC_sub1870A_snd() {
 	int var4 = var3;
 	int var2 = (_word12A00 << 8) + _word12A02;
 	int var1 = (_currScript->readUint16LE() & 0xFF);
-	warning("TODO: ovlContentOVL Function 2");
+
+	_vm->_soundHandler->contentFct2();
 }
 
 void LilliputScript::OC_sub18725_snd() {
 	debugC(1, kDebugScript, "OC_sub18725_snd()");
 
 	int var4 = getValue1() | 0xFF00;
-	warning("TODO: ovlContentOVL Function 3");
+
+	_vm->_soundHandler->contentFct3();
 }
 
 void LilliputScript::OC_sub18733_snd() {
 	debugC(1, kDebugScript, "OC_sub18733_snd()");
 
 	int var4 = getValue2();
-	warning("TODO: ovlContentOVL Function 3");
+
+	_vm->_soundHandler->contentFct3();
 }
 
 void LilliputScript::OC_sub1873F_snd() {
 	debugC(1, kDebugScript, "OC_sub1873F_snd()");
 
-	warning("TODO: ovlContentOVL Function 4");
+	_vm->_soundHandler->contentFct4();
 }
 
 void LilliputScript::OC_sub18746_snd() {
@@ -1923,13 +1927,14 @@ void LilliputScript::OC_sub18746_snd() {
 	int var4 = -1;
 	int var2 = (_word12A00 << 8) + _word12A02;
 	int var1 = _currScript->readUint16LE() & 0xFF;
-	warning("TODO: ovlContentOVL Function 2");
+
+	_vm->_soundHandler->contentFct2();
 }
 
 void LilliputScript::OC_sub1875D_snd() {
 	debugC(1, kDebugScript, "OC_sub1875D_snd()");
 
-	warning("TODO: ovlContentOVL Function 6");
+	_vm->_soundHandler->contentFct6();
 }
 
 void LilliputScript::OC_sub18764() {
diff --git a/engines/lilliput/sound.cpp b/engines/lilliput/sound.cpp
new file mode 100644
index 0000000..d5f37d7
--- /dev/null
+++ b/engines/lilliput/sound.cpp
@@ -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.
+ *
+ */
+
+#include "lilliput/lilliput.h"
+#include "lilliput/sound.h"
+
+#include "common/debug.h"
+
+namespace Lilliput {
+
+LilliputSound::LilliputSound(LilliputEngine *vm) : _vm(vm) {
+}
+
+LilliputSound::~LilliputSound() {
+}
+
+void LilliputSound::contentFct1() {
+	debugC(1, kDebugSound, "contentFct1()");
+}
+
+void LilliputSound::contentFct2() {
+	debugC(1, kDebugSound, "contentFct2()");
+}
+
+void LilliputSound::contentFct3() {
+	debugC(1, kDebugSound, "contentFct3()");
+}
+
+void LilliputSound::contentFct4() {
+	debugC(1, kDebugSound, "contentFct4()");
+}
+
+void LilliputSound::contentFct5() {
+	debugC(1, kDebugSound, "contentFct5()");
+}
+
+void LilliputSound::contentFct6() {
+	debugC(1, kDebugSound, "contentFct6()");
+}
+
+} // End of namespace
diff --git a/engines/lilliput/sound.h b/engines/lilliput/sound.h
new file mode 100644
index 0000000..5fa84bf
--- /dev/null
+++ b/engines/lilliput/sound.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 LILLIPUT_SOUND_H
+#define LILLIPUT_SOUND_H
+
+namespace Lilliput {
+
+class LilliputEngine;
+
+class LilliputSound {
+public:
+	LilliputSound(LilliputEngine *vm);
+	~LilliputSound();
+
+	void contentFct1();
+	void contentFct2();
+	void contentFct3();
+	void contentFct4();
+	void contentFct5();
+	void contentFct6();
+
+private:
+	LilliputEngine *_vm;
+};
+
+} // End of namespace Lilliput
+
+#endif
+


Commit: 8f8dadb9e159154b266884d40a3daf5be192c1ea
    https://github.com/scummvm/scummvm/commit/8f8dadb9e159154b266884d40a3daf5be192c1ea
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement some more functions

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 0014ec3..3bb410a 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -168,6 +168,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array161C3[i] = 0;
 		_array161EB[i] = 0;
 		_array12299[i] = 0xFF;
+		_array109E9[i] = 0xFF;
+		_array10A11[i] = 0xFF;
 
 		_array11D49[i] = 0xFFFF;
 		_rulesBuffer2_1[i] = 0xFFFF;
@@ -601,8 +603,7 @@ void LilliputEngine::sub16217() {
 		}
 	}
 
-	warning("sub_161323");
-
+	sub16323();
 }
 
 void LilliputEngine::sub1652B(int var1) {
@@ -693,6 +694,49 @@ void LilliputEngine::displayFunction17() {
 	displayFunction4();
 }
 
+void LilliputEngine::sub16323() {
+	debugC(2, kDebugEngine, "sub16323()");
+
+	if (_byte160FA <= 1)
+		return;
+
+	int var3;
+	for (int var4 = _byte160FA - 1; var4 != 0; var4--) {
+		var3 = 0;
+
+		for (int var2 = 0; var2 < var4; var2++) {
+			int index1 = _array160FB[var2];
+			int index2 = _array160FB[var2 + 1];
+		
+			if (_array1619B[index1] < _array1619B[index2]) 
+				continue;
+
+			if (_array1619B[index1] == _array1619B[index2]) {
+				if (_array16173[index1] < _array16173[index2])
+					continue;
+
+				if (_array16173[index1] == _array16173[index2]) {
+					if (_rulesBuffer2_3[index1] < _rulesBuffer2_3[index2])
+						continue;
+
+					if (_rulesBuffer2_3[index1] == _rulesBuffer2_3[index2]) {
+						if (_array161EB[index1] < _array161EB[index2])
+							continue;
+					}
+				}
+			}
+
+			byte tmpVal = _array160FB[var2];
+			_array160FB[var2] = _array160FB[var2 + 1];
+			_array160FB[var2 + 1] = tmpVal;
+			++var3;
+		}
+
+		if (var3 == 0)
+			return;
+	}
+}
+
 // Move view port to x/y
 void LilliputEngine::sub1638C() {
 	debugC(2, kDebugEngine, "sub1638C()");
@@ -829,6 +873,64 @@ void LilliputEngine::sub189DE() {
 	}
 }
 
+int LilliputEngine::sub16B0C(int param1, int param2) {
+	debugC(2, kDebugEngine, "sub16B0C(%d, %d)", param1, param2);
+
+	static const byte _array16B04[8] = {0, 2, 0, 1, 3, 2, 3, 1};
+
+	int var1 = param2;
+	int var2 = param1;
+
+	int8 var1h = (var1 >>8) - (var2 >>8);
+	int8 var1l = (var1 & 0xFF) - (var2 & 0xFF);
+	int8 var2h = 0;
+	int8 var2l = 0;
+
+	if (var1h < var2h) {
+		var2l |= 4;
+		var1h = -var1h;
+	}
+
+	if (var1l < var2h) {
+		var2l |= 2;
+		var1l = -var1l;
+	}
+
+	if (var1h < var1l)
+		var2l |= 1;
+
+	return _array16B04[var2l];
+}
+
+int LilliputEngine::sub16799(int param1, int index) {
+	debugC(2, kDebugEngine, "sub16799(%d, %d)", param1, index);
+
+	byte var3h = _array109E9[index];
+	byte var3l = _array10A11[index];
+
+	if (var3h != 0xFF) {
+		if ((var3h != _scriptHandler->_array16123[index]) || (var3l != _scriptHandler->_array1614B[index])) {
+			warning("sub_1693A");
+			_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
+			return 3;
+		}
+
+		if ((var3h == _scriptHandler->_array12811[index]) && (var3l == _array109C1[index]))
+			return 2;
+	}
+
+	warning("sub_167EF");
+	int var1 = (_scriptHandler->_array16123[index] << 8) + _scriptHandler->_array1614B[index];
+	int var2 = (_array109E9[index] << 8) + _array10A11[index];
+
+	_rulesBuffer2_9[index] = sub16B0C(var1, var2);
+
+	warning("sub_1693A");
+	_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
+	return 3;
+
+}
+
 void LilliputEngine::sub16626() {
 	debugC(2, kDebugEngine, "sub16626()");
 
@@ -872,7 +974,7 @@ void LilliputEngine::sub16626() {
 				warning("result = sub_16729");
 				break;
 			case 12:
-				warning("result = sub_16799");
+				result = sub16799(var1, index);
 				break;
 			case 13:
 				warning("result = sub_16722");
@@ -887,6 +989,7 @@ void LilliputEngine::sub16626() {
 				error("sub16626 - unexpected value %d", var2 / 2);
 				break;
 			}
+
 			if (result == 1) {
 				++_scriptHandler->_array12811[index];
 				if (_scriptHandler->_array12811[index] == 16)
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 298a367..bdbda3f 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -182,6 +182,8 @@ public:
 	byte _array161C3[40];
 	byte _array161EB[40];
 	byte _array12299[40];
+	byte _array109E9[40];
+	byte _array10A11[40];
 
 	byte _buffer1_45k[45056];
 	byte _buffer2_45k[45056];
@@ -213,11 +215,14 @@ public:
 	void displayFunction16();
 	void displayFunction17();
 
+	void sub16323();
 	void sub1638C();
 	void sub163F0(int var1, int var3);
 	void sub189DE();
 	void sub16626();
 	void sub16553(byte *buf);
+	int sub16799(int param1, int index);
+	int sub16B0C(int param1, int param2);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a6a10e5..caa9d52 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -36,7 +36,12 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte10806 = 0;
 	_byte12FE4 = 0xFF;
 	_byte16F02 = 0;
+	_byte18778 = 0;
+	_byte18779 = 0;
+	_byte1877A = 0;
+	_byte1877B = 0;
 
+	_word18818 = 0;
 	_word1855E = 0;
 	_word16F00 = -1;
 	_word10802 = -1;
@@ -1764,11 +1769,24 @@ void LilliputScript::OC_sub1847F() {
 
 	if (_byte16F08 != 1) {
 		_vm->displayFunction5();
-		warning("TODO: OC_sub1847F - sub_18BE6");
+		sub18BE6();
 		_vm->displayFunction4();
 	}
 }
 
+void LilliputScript::sub18BE6() {
+	debugC(1, kDebugScript, "sub18BE6()");
+
+	_word18818 = 0;
+	_byte18778 = 32;
+	_byte18779 = 32;
+	_byte1877A = 32;
+	_byte1877B = 0;
+
+	warning("sub_18AEE");
+	warning("sub_15A8B(_vm_byte18778);");
+}
+
 void LilliputScript::OC_displayVGAFile() {
 	debugC(1, kDebugScript, "OC_displayVGAFile()");
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 662538a..4b5bc3d 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -69,6 +69,10 @@ private:
 	byte _byte10806;
 	byte _byte12FE4;
 	byte _byte16F02;
+	byte _byte18778;
+	byte _byte18779;
+	byte _byte1877A;
+	byte _byte1877B;
 
 	byte *_savedBuffer215Ptr;
 	byte _array122FD[20];
@@ -76,6 +80,7 @@ private:
 	byte _array12839[40];
 	byte _array10B51[40 * 40];
 
+	int _word18818;
 	int _word16F00;
 	int _word10804;
 	int _word15FFB;
@@ -97,6 +102,7 @@ private:
 	int sub17D40(int var);
 	void sub18A56(byte *buf);
 	void sub18B3C(int var);
+	void sub18BE6();
 
 	int getValue1();
 	int getValue2();


Commit: 5d21c237f70d1cdba3d3b7f978e2542088b89489
    https://github.com/scummvm/scummvm/commit/5d21c237f70d1cdba3d3b7f978e2542088b89489
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add display string, accelerate fading to 50Hkz

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3bb410a..6730f5b 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -143,6 +143,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12A09 = 0;
 	_byte1881D = 0;
 	_byte16552 = 0;
+	_byte18AED = 0;
 
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
@@ -155,6 +156,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word15AC2 = 0;
 	_word16213 = 0;
 	_word16215 = 0;
+	_displayStringIndex = 0;
 
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
@@ -191,6 +193,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	for (int i = 0; i < 256; i++)
 		_array15AC8[i] = 0;
 
+	for (int i = 0; i < 160; i++)
+		_displayStringBuf[i] = 0;
+
 	_ptr_rulesBuffer2_15 = NULL;
 	_bufferIdeogram = NULL;
 	_bufferMen = NULL;
@@ -694,6 +699,36 @@ void LilliputEngine::displayFunction17() {
 	displayFunction4();
 }
 
+void LilliputEngine::displayFunction18(byte *buf, int var2, int var4) {
+	debugC(2, kDebugEngine, "displayFunction18(buf, %d, %d)", var2, var4);
+
+	int index = var2;
+	int tmpVar4 = (var4 >> 8) + ((var4 & 0xFF) << 8);
+	index = index + tmpVar4 + (tmpVar4 >> 2);
+
+	int i = 0;
+	while (buf[i] != 0) {
+		displayChar(index, buf[i]);
+		++i;
+		index += 4;
+	}
+}
+
+void LilliputEngine::displayChar(int index, int var1) {
+	debugC(2, kDebugEngine, "displayChar(%d, %d)", index, var1);
+
+	int indexVga = index;
+	int indexChar = var1 << 5;
+
+	for (int i = 0; i < 8; i++) {
+		for (int j = 0; j < 4; j++)
+			((byte *)_mainSurface->getPixels())[indexVga + j] = _bufferIsoChars[indexChar + j];
+		indexVga += 320;
+		indexChar += 4;
+	}
+
+}
+
 void LilliputEngine::sub16323() {
 	debugC(2, kDebugEngine, "sub16323()");
 
@@ -707,8 +742,8 @@ void LilliputEngine::sub16323() {
 		for (int var2 = 0; var2 < var4; var2++) {
 			int index1 = _array160FB[var2];
 			int index2 = _array160FB[var2 + 1];
-		
-			if (_array1619B[index1] < _array1619B[index2]) 
+
+			if (_array1619B[index1] < _array1619B[index2])
 				continue;
 
 			if (_array1619B[index1] == _array1619B[index2]) {
@@ -931,6 +966,40 @@ int LilliputEngine::sub16799(int param1, int index) {
 
 }
 
+void LilliputEngine::sub18A3E(byte param1) {
+	debugC(2, kDebugEngine, "sub18A3E(%d)", param1);
+
+	_displayStringBuf[_displayStringIndex] = param1;
+	if (_displayStringIndex < 158)
+		++_displayStringIndex;
+}
+
+void LilliputEngine::sub18AEE(int param1) {
+	debugC(2, kDebugEngine, "sub18AEE(%d)", param1);
+
+	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
+
+	int count;
+	int var1 = param1;
+	for (int i = 0; i < 5; i++) {
+		count = 0;
+		while (var1 >= 0) {
+			++count;
+			var1 -= _array18AE3[i];
+		}
+		var1 += _array18AE3[i];
+		byte tmpVal = var1 + 0x30;
+
+		if (i == 4)
+			sub18A3E(tmpVal);
+		else if ((var1 != 0) || (_byte18AED != 1)) {
+			_byte18AED = 0;
+			sub18A3E(tmpVal);
+		}
+	}
+}
+
+
 void LilliputEngine::sub16626() {
 	debugC(2, kDebugEngine, "sub16626()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index bdbda3f..d4d5dfc 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -101,6 +101,7 @@ public:
 	byte _byte12A09;
 	byte _byte1881D;
 	byte _byte16552;
+	byte _byte18AED;
 
 	byte _buffer1[45056];
 	byte _buffer2[45056];
@@ -113,6 +114,7 @@ public:
 	byte *_bufferIdeogram;
 	byte _buffer10[4032];
 	byte _curPalette[768];
+	byte _displayStringBuf[160];
 
 	bool _saveFlag;
 	bool _int8installed;
@@ -127,6 +129,7 @@ public:
 	int _word15BCA;
 	int _word15AC2;
 	int _word16550;
+	int _displayStringIndex;
 
 	int _array11D49[40];
 
@@ -214,6 +217,8 @@ public:
 	void displayFunction15();
 	void displayFunction16();
 	void displayFunction17();
+	void displayFunction18(byte *buf, int var2, int var4);
+	void displayChar(int index, int var1);
 
 	void sub16323();
 	void sub1638C();
@@ -223,6 +228,8 @@ public:
 	void sub16553(byte *buf);
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
+	void sub18A3E(byte param1);
+	void sub18AEE(int param1);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index caa9d52..ca7e389 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -36,12 +36,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte10806 = 0;
 	_byte12FE4 = 0xFF;
 	_byte16F02 = 0;
-	_byte18778 = 0;
-	_byte18779 = 0;
-	_byte1877A = 0;
-	_byte1877B = 0;
 
-	_word18818 = 0;
 	_word1855E = 0;
 	_word16F00 = -1;
 	_word10802 = -1;
@@ -1676,7 +1671,7 @@ void LilliputScript::OC_unkPaletteFunction_1() {
 		}
 		_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
 		_vm->_system->updateScreen();
-		_vm->_system->delayMillis(33);
+		_vm->_system->delayMillis(20);
 	}
 }
 void LilliputScript::OC_unkPaletteFunction_2() {
@@ -1688,7 +1683,7 @@ void LilliputScript::OC_unkPaletteFunction_2() {
 		}
 		_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
 		_vm->_system->updateScreen();
-		_vm->_system->delayMillis(33);
+		_vm->_system->delayMillis(20);
 	}
 }
 
@@ -1763,28 +1758,28 @@ void LilliputScript::OC_sub1847F() {
 	byte tmpVal = buf215Ptr[0];
 	int curWord = _currScript->readUint16LE();
 	assert(curWord != 0);
-	int var1 = tmpVal / curWord;
+	int var1 = tmpVal / (curWord & 0xFF);
 	int var2 = _currScript->readUint16LE();
-	int var3 = _currScript->readUint16LE();
+	int var4 = _currScript->readUint16LE();
 
 	if (_byte16F08 != 1) {
 		_vm->displayFunction5();
-		sub18BE6();
+		sub18BE6(var1 & 0xFF, var2, var4);
 		_vm->displayFunction4();
 	}
 }
 
-void LilliputScript::sub18BE6() {
-	debugC(1, kDebugScript, "sub18BE6()");
+void LilliputScript::sub18BE6(byte var1, int var2, int var4) {
+	debugC(1, kDebugScript, "sub18BE6(%d, %d, %d)", var1, var2, var4);
 
-	_word18818 = 0;
-	_byte18778 = 32;
-	_byte18779 = 32;
-	_byte1877A = 32;
-	_byte1877B = 0;
+	_vm->_displayStringIndex = 0;
+	_vm->_displayStringBuf[0] = 32;
+	_vm->_displayStringBuf[1] = 32;
+	_vm->_displayStringBuf[2] = 32;
+	_vm->_displayStringBuf[3] = 0;
 
-	warning("sub_18AEE");
-	warning("sub_15A8B(_vm_byte18778);");
+	_vm->sub18AEE(var1);
+	_vm->displayFunction18(_vm->_displayStringBuf, var2, var4);
 }
 
 void LilliputScript::OC_displayVGAFile() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 4b5bc3d..07d2139 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -69,10 +69,6 @@ private:
 	byte _byte10806;
 	byte _byte12FE4;
 	byte _byte16F02;
-	byte _byte18778;
-	byte _byte18779;
-	byte _byte1877A;
-	byte _byte1877B;
 
 	byte *_savedBuffer215Ptr;
 	byte _array122FD[20];
@@ -80,7 +76,6 @@ private:
 	byte _array12839[40];
 	byte _array10B51[40 * 40];
 
-	int _word18818;
 	int _word16F00;
 	int _word10804;
 	int _word15FFB;
@@ -102,7 +97,7 @@ private:
 	int sub17D40(int var);
 	void sub18A56(byte *buf);
 	void sub18B3C(int var);
-	void sub18BE6();
+	void sub18BE6(byte var1, int var2, int var4);
 
 	int getValue1();
 	int getValue2();


Commit: 16ec550df57d3bb1bc661ec46872b31ca5239adb
    https://github.com/scummvm/scummvm/commit/16ec550df57d3bb1bc661ec46872b31ca5239adb
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix display string functions, some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6730f5b..caf8301 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -143,7 +143,6 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12A09 = 0;
 	_byte1881D = 0;
 	_byte16552 = 0;
-	_byte18AED = 0;
 
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
@@ -699,8 +698,8 @@ void LilliputEngine::displayFunction17() {
 	displayFunction4();
 }
 
-void LilliputEngine::displayFunction18(byte *buf, int var2, int var4) {
-	debugC(2, kDebugEngine, "displayFunction18(buf, %d, %d)", var2, var4);
+void LilliputEngine::displayString(byte *buf, int var2, int var4) {
+	debugC(2, kDebugEngine, "displayString(buf, %d, %d)", var2, var4);
 
 	int index = var2;
 	int tmpVar4 = (var4 >> 8) + ((var4 & 0xFF) << 8);
@@ -974,13 +973,14 @@ void LilliputEngine::sub18A3E(byte param1) {
 		++_displayStringIndex;
 }
 
-void LilliputEngine::sub18AEE(int param1) {
-	debugC(2, kDebugEngine, "sub18AEE(%d)", param1);
+void LilliputEngine::prepareGoldAmount(int param1) {
+	debugC(2, kDebugEngine, "prepareGoldAmount(%d)", param1);
 
 	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
 
 	int count;
 	int var1 = param1;
+	bool hideZeros = true;
 	for (int i = 0; i < 5; i++) {
 		count = 0;
 		while (var1 >= 0) {
@@ -988,12 +988,14 @@ void LilliputEngine::sub18AEE(int param1) {
 			var1 -= _array18AE3[i];
 		}
 		var1 += _array18AE3[i];
-		byte tmpVal = var1 + 0x30;
+		--count;
+
+		byte tmpVal = count + 0x30;
 
 		if (i == 4)
 			sub18A3E(tmpVal);
-		else if ((var1 != 0) || (_byte18AED != 1)) {
-			_byte18AED = 0;
+		else if ((count != 0) || (!hideZeros)) {
+			hideZeros = false;
 			sub18A3E(tmpVal);
 		}
 	}
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index d4d5dfc..a0c9eec 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -101,7 +101,6 @@ public:
 	byte _byte12A09;
 	byte _byte1881D;
 	byte _byte16552;
-	byte _byte18AED;
 
 	byte _buffer1[45056];
 	byte _buffer2[45056];
@@ -217,7 +216,7 @@ public:
 	void displayFunction15();
 	void displayFunction16();
 	void displayFunction17();
-	void displayFunction18(byte *buf, int var2, int var4);
+	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
 
 	void sub16323();
@@ -229,7 +228,7 @@ public:
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
 	void sub18A3E(byte param1);
-	void sub18AEE(int param1);
+	void prepareGoldAmount(int param1);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index ca7e389..d99b8e7 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1778,8 +1778,8 @@ void LilliputScript::sub18BE6(byte var1, int var2, int var4) {
 	_vm->_displayStringBuf[2] = 32;
 	_vm->_displayStringBuf[3] = 0;
 
-	_vm->sub18AEE(var1);
-	_vm->displayFunction18(_vm->_displayStringBuf, var2, var4);
+	_vm->prepareGoldAmount(var1);
+	_vm->displayString(_vm->_displayStringBuf, var2, var4);
 }
 
 void LilliputScript::OC_displayVGAFile() {


Commit: c6ee25b179bc88d9570e1537009fe25d7beea773
    https://github.com/scummvm/scummvm/commit/c6ee25b179bc88d9570e1537009fe25d7beea773
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Minor fixes

Prevents unexpected values in sub16626

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index caf8301..016b0f6 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1010,12 +1010,12 @@ void LilliputEngine::sub16626() {
 	while (index >= 0) {
 		result = 0;
 		while (result != 2) {
-			int var2 = _scriptHandler->_array12811[index];
+			int var2 = _scriptHandler->_array12811[index] & 0xFF;
 			if (var2 == 16)
 				break;
-			var2 = (var2 * 2) + (index << 5);
+			var2 = var2 + (index << 4);
 			int var1 = _scriptHandler->_array12311[var2];
-			var2 = ((var2 & 0xFF00) + (var1 >> 8)) >> 3;
+			var2 = (var1 >> 8) >> 3;
 			var2 &= 0xFE;
 
 			// temporary hack
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index d99b8e7..cc143f1 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1339,11 +1339,13 @@ void LilliputScript::OC_sub17D57() {
 	debugC(1, kDebugScript, "OC_sub17D57()");
 
 	int curWord = _currScript->readUint16LE();
-	curWord = sub17D40(curWord);
 
-	_word1881B = _vm->_rulesBuffer2PrevIndx;
+	if((_byte16F08 == 1) || (_array16173[_vm->_rulesBuffer2PrevIndx] == 0xFF))
+		return;
 
+	_word1881B = _vm->_rulesBuffer2PrevIndx;
 	sub18B3C(curWord);
+
 }
 
 void LilliputScript::OC_sub17D7F() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 07d2139..668040d 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -48,7 +48,7 @@ public:
 	int _word10802;
 	int _word1881B;
 
-	int _array12311[640];
+	short _array12311[640];
 
 	LilliputScript(LilliputEngine *vm);
 	~LilliputScript();


Commit: ebb7f492f062fc45223e900e5d04333cdf513e0c
    https://github.com/scummvm/scummvm/commit/ebb7f492f062fc45223e900e5d04333cdf513e0c
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a couple of check errors in sub16626, implement some more more core functions

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 016b0f6..31500e8 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -665,7 +665,7 @@ void LilliputEngine::displayFunction16() {
 		warning("sub_15F31");
 		warning("sub_15F0C");
 		sub16626();
-		warning("sub_12F37");
+		sub12F37();
 		warning("sub_16CA0");
 		warning("sub_16EBC");
 		warning("sub_171CF");
@@ -676,7 +676,7 @@ void LilliputEngine::displayFunction16() {
 		displayFunction15();
 		displayFunction14();
 		sub16626();
-		warning("sub_12F37");
+		sub12F37();
 		warning("sub_16CA0");
 		warning("sub_16EBC");
 		warning("sub_171CF");
@@ -1008,22 +1008,24 @@ void LilliputEngine::sub16626() {
 	int index = _word10807_ERULES - 1;
 	int result;
 	while (index >= 0) {
-		result = 0;
-		while (result != 2) {
-			int var2 = _scriptHandler->_array12811[index] & 0xFF;
+		result = 2;
+		while (result & 2) {
+			int var2 = _scriptHandler->_array12811[index];
 			if (var2 == 16)
 				break;
-			var2 = var2 + (index << 4);
-			int var1 = _scriptHandler->_array12311[var2];
-			var2 = (var1 >> 8) >> 3;
+
+			var2 = (2 * var2) + (index << 5);
+			int var1 = _scriptHandler->_array12311[var2 / 2];
+			int tmpVal = var2;
+			var2 = ((var1 >> 8) >> 3);
 			var2 &= 0xFE;
 
-			// temporary hack
-			result = 2;
+			// temporary hack 
+			result = 0;
 
 			switch (var2 / 2) {
 			case 0:
-				warning("result = sub_16675");
+				result = sub16675(index, var1);
 				break;
 			case 1:
 				warning("result = sub_166DD");
@@ -1061,7 +1063,7 @@ void LilliputEngine::sub16626() {
 				break;
 			}
 
-			if (result == 1) {
+			if (result & 1) {
 				++_scriptHandler->_array12811[index];
 				if (_scriptHandler->_array12811[index] == 16)
 					_scriptHandler->_array10B29[index] = 1;
@@ -1071,6 +1073,80 @@ void LilliputEngine::sub16626() {
 	}
 }
 
+void LilliputEngine::sub12F37() {
+	debugC(2, kDebugEngine, "sub12F37()");
+
+	int index1 = _byte12A04 + 2;
+	int index2 = 0;
+
+	for (int i = 0; i < _word10807_ERULES; i++) {
+		if (_rulesBuffer2_15[index1] == 1 ) {
+			--_rulesBuffer2_15[index1];
+			if (_rulesBuffer2_15[index1] == 1)
+				_scriptHandler->_array10B29[index2] = 1;
+		} else 
+			_rulesBuffer2_15[index1] = 0;
+
+		index1 += 32;
+		++index2;
+	}
+}
+
+int LilliputEngine::sub16685(int idx, int var1) {
+	debugC(2, kDebugEngine, "sub16685(%d, %d)", idx, var1);
+
+	int index = (idx << 5) + (var1 & 0xFF);
+	byte tmpVal = _rulesBuffer2_16[index];
+	_scriptHandler->_array10AB1[idx] = tmpVal;
+	return var1;
+}
+
+int LilliputEngine::sub16675(int idx, int var1) {
+	debugC(2, kDebugEngine, "sub16675(%d, %d)", idx, var1);
+
+	warning("sub16675(%d, %d)", idx, var1);
+	int index = sub16685(idx, var1);
+	
+	switch (index) {
+	case 0:
+		break;
+	case 1:
+		warning("sub_166B1");
+		break;
+	case 2:
+		warning("sub_166B6");
+		break;
+	case 3:
+		warning("sub_166BB");
+		break;
+	case 4:
+		warning("sub_16B63");
+		break;
+	case 5:
+		warning("sub_16B76");
+		break;
+	case 6:
+		warning("sub_166C0");
+		break;
+	case 7:
+		warning("sub_166C6");
+		break;
+	case 8:
+		warning("sub_166CC");
+		break;
+	case 9:
+		warning("sub_166D2");
+		break;
+	case 10:
+		warning("sub_166D8");
+		break;
+	default:
+		warning("sub16675 - Unexpected value %d", index);
+	}
+
+	return 0;
+}
+
 void LilliputEngine::pollEvent() {
 	debugC(2, kDebugEngine, "pollEvent()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index a0c9eec..2cb63f9 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -229,6 +229,9 @@ public:
 	int sub16B0C(int param1, int param2);
 	void sub18A3E(byte param1);
 	void prepareGoldAmount(int param1);
+	void sub12F37();
+	int sub16675(int idx, int var1);
+	int sub16685(int idx, int var1);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);


Commit: c4dc1e37611a0e6a00dbeb67696bba47be45f006
    https://github.com/scummvm/scummvm/commit/c4dc1e37611a0e6a00dbeb67696bba47be45f006
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add display heroism bar

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 31500e8..8d8091a 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -156,6 +156,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word16213 = 0;
 	_word16215 = 0;
 	_displayStringIndex = 0;
+	_word1289D = 0;
 
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
@@ -171,6 +172,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array12299[i] = 0xFF;
 		_array109E9[i] = 0xFF;
 		_array10A11[i] = 0xFF;
+		_array16E94[i] = 0;
 
 		_array11D49[i] = 0xFFFF;
 		_rulesBuffer2_1[i] = 0xFFFF;
@@ -187,8 +189,12 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_rulesBuffer2_12[i] = 0;
 		_rulesBuffer2_13[i] = 0;
 		_rulesBuffer2_14[i] = 0;
+		_array1289F[i] = 0xFFFF;
 	}
 
+	for (int i = 0; i < 30; i++)
+		_array12861[i] = 0xFFFF;
+
 	for (int i = 0; i < 256; i++)
 		_array15AC8[i] = 0;
 
@@ -667,8 +673,8 @@ void LilliputEngine::displayFunction16() {
 		sub16626();
 		sub12F37();
 		warning("sub_16CA0");
-		warning("sub_16EBC");
-		warning("sub_171CF");
+		sub16EBC();
+		sub171CF();
 		warning("sub_15EAE");
 	} else {
 		sub1638C();
@@ -678,11 +684,11 @@ void LilliputEngine::displayFunction16() {
 		sub16626();
 		sub12F37();
 		warning("sub_16CA0");
-		warning("sub_16EBC");
-		warning("sub_171CF");
+		sub16EBC();
+		sub171CF();
 		warning("sub_130EE");
-		warning("sub_12FE5");
-		warning("sub_15FFF");
+		sub12FE5();
+		displayHeroismIndicator();
 	}
 }
 
@@ -1001,7 +1007,6 @@ void LilliputEngine::prepareGoldAmount(int param1) {
 	}
 }
 
-
 void LilliputEngine::sub16626() {
 	debugC(2, kDebugEngine, "sub16626()");
 
@@ -1020,7 +1025,7 @@ void LilliputEngine::sub16626() {
 			var2 = ((var1 >> 8) >> 3);
 			var2 &= 0xFE;
 
-			// temporary hack 
+			// temporary hack
 			result = 0;
 
 			switch (var2 / 2) {
@@ -1073,6 +1078,24 @@ void LilliputEngine::sub16626() {
 	}
 }
 
+void LilliputEngine::sub16EBC() {
+	debugC(2, kDebugEngine, "sub16EBC()");
+
+	int index2 = 3;
+
+	for (int index1 = _word10807_ERULES - 1; index1 >= 0; index1--) {
+		int var2 = (_scriptHandler->_array1614B[index1] << 8) + (_scriptHandler->_array16123[index1] << 2);
+		int var1 = (_bufferIsoMap[index2 + var2] & 0x40);
+
+		if (var1 == _array16E94[index1])
+			continue;
+
+		_array16E94[index1] = var1;
+		if (var1 != 0)
+			_scriptHandler->_array10B29[index1] = 1;
+	}
+}
+
 void LilliputEngine::sub12F37() {
 	debugC(2, kDebugEngine, "sub12F37()");
 
@@ -1084,7 +1107,7 @@ void LilliputEngine::sub12F37() {
 			--_rulesBuffer2_15[index1];
 			if (_rulesBuffer2_15[index1] == 1)
 				_scriptHandler->_array10B29[index2] = 1;
-		} else 
+		} else
 			_rulesBuffer2_15[index1] = 0;
 
 		index1 += 32;
@@ -1106,7 +1129,7 @@ int LilliputEngine::sub16675(int idx, int var1) {
 
 	warning("sub16675(%d, %d)", idx, var1);
 	int index = sub16685(idx, var1);
-	
+
 	switch (index) {
 	case 0:
 		break;
@@ -1147,6 +1170,99 @@ int LilliputEngine::sub16675(int idx, int var1) {
 	return 0;
 }
 
+void LilliputEngine::sub171CF() {
+	debugC(2, kDebugEngine, "sub171CF()");
+
+	for (int i = 0; i < _word10807_ERULES; i++) {
+		if (_array1289F[i] != 0xFFFF) {
+			_array11D49[i] = _array1289F[i];
+			_array1289F[i] = 0xFFFF;
+			_scriptHandler->_array10B29[i] = 1;
+		}
+	}
+
+	++_word1289D;
+
+	for (int i = 0; i < 10; i++) {
+		if ((_array12861[(3 * i) + 1] != 0xFFFF) && (_array12861[3 * i] = _word1289D)) {
+			int var1 = _array12861[(3 * i) + 1];
+			int var4 = _array12861[(3 * i) + 2];
+			_array12861[(3 * i) + 1] = 0xFFFF;
+
+			warning("sub_17224");
+		}
+	}
+}
+
+void LilliputEngine::sub12FE5() {
+	debugC(2, kDebugEngine, "sub12FE5()");
+
+	if (_byte12A04 != 1)
+		return;
+
+	int index = 0;
+	int count = 0;
+	for (int i = 0; i < _word12F68_ERULES; i++) {
+		if (_scriptHandler->_array122FD[index] != 0) {
+			--_scriptHandler->_array122FD[index];
+			if (_scriptHandler->_array122FD[index] == 0) {
+				_scriptHandler->_array122E9[index] = 2;
+				++count;
+			}
+		}
+	}
+
+	if (count !=0)
+		displayFunction8();
+}
+
+void LilliputEngine::displayHeroismIndicator() {
+	debugC(2, kDebugEngine, "displayHeroismIndicator()");
+
+	if (_scriptHandler->_savedBuffer215Ptr == NULL)
+		return;
+
+	int var1 = (_scriptHandler->_savedBuffer215Ptr[0] * 25) >> 8;
+
+	if (var1 == _scriptHandler->_byte15FFA)
+		return;
+
+	displayFunction5();
+	int var2 = 1;
+	if (var1 > _scriptHandler->_byte15FFA)
+		var1 = 150;
+	else {
+		var2 = -1;
+		var1 = 40;
+	}
+
+	_scriptHandler->_byte15FFA += var2;
+
+	int var4 = (_scriptHandler->_word15FFD >> 8) + ((_scriptHandler->_word15FFD & 0xFF) << 8);
+	int index = _scriptHandler->_word15FFB + var4 + (var4 >> 2);
+
+	if ((_scriptHandler->_byte15FFA & 0xFF) == 0) {
+//		sub16064(var1, _scriptHandler->_byte15FFA);
+		for (int i = 0; i < (_scriptHandler->_byte15FFA << 2); i++) {
+			((byte *)_mainSurface->getPixels())[index - (i * 320)] = var1;
+			((byte *)_mainSurface->getPixels())[index - (i * 320) + 1] = var1;
+			((byte *)_mainSurface->getPixels())[index - (i * 320) + 2] = var1;
+		}
+	}
+
+	if (25 - _scriptHandler->_byte15FFA != 0) {
+//		sub16064(23, 25 - _scriptHandler->_byte15FFA);
+		var2 = (25 - _scriptHandler->_byte15FFA) << 2;
+		for (int i = 0; i < var2; i++) {
+			((byte *)_mainSurface->getPixels())[index - (i * 320)] = 23;
+			((byte *)_mainSurface->getPixels())[index - (i * 320) + 1] = 23;
+			((byte *)_mainSurface->getPixels())[index - (i * 320) + 2] = 23;
+		}
+	}
+
+	displayFunction4();
+}
+
 void LilliputEngine::pollEvent() {
 	debugC(2, kDebugEngine, "pollEvent()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 2cb63f9..e13cd0a 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -129,8 +129,11 @@ public:
 	int _word15AC2;
 	int _word16550;
 	int _displayStringIndex;
+	int _word1289D;
 
 	int _array11D49[40];
+	int _array1289F[40];
+	int _array12861[30];
 
 	byte *_rulesChunk1;
 	int _rulesBuffer2PrevIndx;
@@ -186,6 +189,7 @@ public:
 	byte _array12299[40];
 	byte _array109E9[40];
 	byte _array10A11[40];
+	byte _array16E94[40];
 
 	byte _buffer1_45k[45056];
 	byte _buffer2_45k[45056];
@@ -232,6 +236,10 @@ public:
 	void sub12F37();
 	int sub16675(int idx, int var1);
 	int sub16685(int idx, int var1);
+	void sub16EBC();
+	void sub171CF();
+	void sub12FE5();
+	void displayHeroismIndicator();
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 668040d..3521ad1 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -34,6 +34,7 @@ class LilliputScript {
 public:
 	byte _byte16F08;
 	byte _byte12A04;
+	byte _byte15FFA;
 
 	byte _array10B29[40];
 	byte _array122E9[20];
@@ -42,11 +43,15 @@ public:
 	byte _array16173[40];
 	byte _array12811[40];
 	byte _array10AB1[40];
+	byte _array122FD[20];
+	byte *_savedBuffer215Ptr;
 
 	int _word12A00;
 	int _word12A02;
 	int _word10802;
 	int _word1881B;
+	int _word15FFB;
+	int _word15FFD;
 
 	short _array12311[640];
 
@@ -64,22 +69,17 @@ private:
 	byte _byte16F05_ScriptHandler;
 	byte _byte12A09;
 	byte _byte129A0;
-	byte _byte15FFA;
 	byte _byte1855D;
 	byte _byte10806;
 	byte _byte12FE4;
 	byte _byte16F02;
 
-	byte *_savedBuffer215Ptr;
-	byte _array122FD[20];
 	byte _array128EF[40];
 	byte _array12839[40];
 	byte _array10B51[40 * 40];
 
 	int _word16F00;
 	int _word10804;
-	int _word15FFB;
-	int _word15FFD;
 	int _word1855E;
 	int _word18776;
 


Commit: c304967abc2a0a79f7c35f6003b4ecec72c4bf6c
    https://github.com/scummvm/scummvm/commit/c304967abc2a0a79f7c35f6003b4ecec72c4bf6c
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Rename fading functions

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index cc143f1..848c7e9 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -437,10 +437,10 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub182EC();
 		break;
 	case 0x43:
-		OC_unkPaletteFunction_1();
+		OC_PaletteFadeOut();
 		break;
 	case 0x44:
-		OC_unkPaletteFunction_2();
+		OC_PaletteFadeIn();
 		break;
 	case 0x45:
 		OC_loadAndDisplayCUBESx_GFX();
@@ -1664,7 +1664,8 @@ void LilliputScript::OC_sub18260() {
 void LilliputScript::OC_sub182EC() {
 	warning("OC_sub182EC");
 }
-void LilliputScript::OC_unkPaletteFunction_1() {
+
+void LilliputScript::OC_PaletteFadeOut() {
 	sub1863B();
 	byte palette[768];
 	for (int fade = 256; fade >= 0;	fade -= 8) {
@@ -1676,7 +1677,8 @@ void LilliputScript::OC_unkPaletteFunction_1() {
 		_vm->_system->delayMillis(20);
 	}
 }
-void LilliputScript::OC_unkPaletteFunction_2() {
+
+void LilliputScript::OC_PaletteFadeIn() {
 
 	byte palette[768];
 	for (int fade = 8; fade <= 256;	fade += 8) {
@@ -1788,13 +1790,13 @@ void LilliputScript::OC_displayVGAFile() {
 	debugC(1, kDebugScript, "OC_displayVGAFile()");
 
 	_byte12A09 = 1;
-	OC_unkPaletteFunction_1();
+	OC_PaletteFadeOut();
 	int curWord = _currScript->readUint16LE();
 	int index = _vm->_rulesChunk3[curWord];
 	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
 	_word1881B = -1;
 	_vm->displayVGAFile(fileName);
-	OC_unkPaletteFunction_2();
+	OC_PaletteFadeOut();
 }
 
 void LilliputScript::OC_sub184D7() {
@@ -1836,14 +1838,14 @@ void LilliputScript::OC_displayTitleScreen() {
 void LilliputScript::OC_sub1853B() {
 	debugC(1, kDebugScript, "OC_sub1853B()");
 
-	OC_unkPaletteFunction_1();
+	OC_PaletteFadeOut();
 	_byte16F08 = 0;
 	_byte15FFA = 0;
 	sub130B6();
 
 	_vm->displayFunction12();
 
-	OC_unkPaletteFunction_2();
+	OC_PaletteFadeIn();
 	_byte12A09 = 0;
 	
 	_vm->_soundHandler->contentFct5();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 3521ad1..9c8381e 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -228,8 +228,8 @@ private:
 	void OC_sub18252();
 	void OC_sub18260();
 	void OC_sub182EC();
-	void OC_unkPaletteFunction_1();
-	void OC_unkPaletteFunction_2();
+	void OC_PaletteFadeOut();
+	void OC_PaletteFadeIn();
 	void OC_loadAndDisplayCUBESx_GFX();
 	void OC_sub1834C();
 	void OC_sub18359();


Commit: 8bc2d28e5d23fc7bc2da1c4932fb5e6123413f6b
    https://github.com/scummvm/scummvm/commit/8bc2d28e5d23fc7bc2da1c4932fb5e6123413f6b
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Small additions

Small implementations of the int8 functions

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8d8091a..1fd207c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1033,7 +1033,7 @@ void LilliputEngine::sub16626() {
 				result = sub16675(index, var1);
 				break;
 			case 1:
-				warning("result = sub_166DD");
+				result = sub166DD(index, var1);
 				break;
 			case 2:
 			case 3:
@@ -1043,7 +1043,7 @@ void LilliputEngine::sub16626() {
 			case 7:
 			case 8:
 			case 9:
-				warning("result = sub_16672");
+				result = 0;
 				break;
 			case 10:
 				warning("result = sub_1675D");
@@ -1078,6 +1078,13 @@ void LilliputEngine::sub16626() {
 	}
 }
 
+int LilliputEngine::sub166DD(int index, int var1) {
+	
+	_rulesBuffer2_9[index] = (var1 >> 8) & 3;
+	sub16685(index, var1 & 0xFF);
+	return 0;
+}
+
 void LilliputEngine::sub16EBC() {
 	debugC(2, kDebugEngine, "sub16EBC()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index e13cd0a..48971b4 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -228,6 +228,7 @@ public:
 	void sub163F0(int var1, int var3);
 	void sub189DE();
 	void sub16626();
+
 	void sub16553(byte *buf);
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
@@ -237,6 +238,7 @@ public:
 	int sub16675(int idx, int var1);
 	int sub16685(int idx, int var1);
 	void sub16EBC();
+	int sub166DD(int index, int var1);
 	void sub171CF();
 	void sub12FE5();
 	void displayHeroismIndicator();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 848c7e9..7c8315d 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -66,7 +66,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	}
 
 	for (int i = 0; i < 640; i++) {
-		_array12311[i] = 0xFFFF;
+		_array12311[i] = -1;
 	}
 }
 
@@ -738,7 +738,7 @@ void LilliputScript::sub16C86(int index, byte *buf) {
 	_array12811[index] = 0;
 
 	for (int i = 0; i < 16; i++) {
-		_array12311[(index * 16) + i] = (buf[2 * i] << 8) + buf[(2 * i) + 1];
+		_array12311[(index * 16) + i] = (buf[(2 * i) + 1] << 8) + buf[2 * i];
 	}
 }
 


Commit: b4629af5585033bcfd8aa1f50840f6fe2a36f161
    https://github.com/scummvm/scummvm/commit/b4629af5585033bcfd8aa1f50840f6fe2a36f161
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: fix regression in 6aef68e246448977f2b8ba1bb19a17d8eaf61642

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7c8315d..59180a0 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1796,7 +1796,7 @@ void LilliputScript::OC_displayVGAFile() {
 	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
 	_word1881B = -1;
 	_vm->displayVGAFile(fileName);
-	OC_PaletteFadeOut();
+	OC_PaletteFadeIn();
 }
 
 void LilliputScript::OC_sub184D7() {


Commit: 98b39800a86f4fba98e6cb2b1e04b247a1e7c977
    https://github.com/scummvm/scummvm/commit/98b39800a86f4fba98e6cb2b1e04b247a1e7c977
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implementation of sub16CA0

Big sub16CA0 function implementation

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 1fd207c..ecefbdc 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -672,7 +672,7 @@ void LilliputEngine::displayFunction16() {
 		warning("sub_15F0C");
 		sub16626();
 		sub12F37();
-		warning("sub_16CA0");
+		sub16CA0();
 		sub16EBC();
 		sub171CF();
 		warning("sub_15EAE");
@@ -683,7 +683,7 @@ void LilliputEngine::displayFunction16() {
 		displayFunction14();
 		sub16626();
 		sub12F37();
-		warning("sub_16CA0");
+		sub16CA0();
 		sub16EBC();
 		sub171CF();
 		warning("sub_130EE");
@@ -692,6 +692,113 @@ void LilliputEngine::displayFunction16() {
 	}
 }
 
+int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
+{
+	warning("sub16DD5");
+	return 0;
+}
+
+void LilliputEngine::sub16CA0() {
+
+
+	for (int index = _word10807_ERULES - 1; index >= 0; index--) {
+		if (_rulesBuffer2_11[index] & 1)
+			continue;
+		int c1 = _scriptHandler->_array16123[index];
+		int c2 = _scriptHandler->_array1614B[index];
+
+		for(int index2 = _word10807_ERULES - 1; index2 >= 0; index2--) {
+			if ( index == index2 )
+				continue;
+
+			if (_rulesBuffer2_5[index] != index2 &&
+				_rulesBuffer2_5[index2] != index &&
+				(_rulesBuffer2_11[index2] & 2) == 0) {
+				int d1 = _scriptHandler->_array16123[index2];
+				int d2 = _scriptHandler->_array1614B[index2];
+
+				if (d1 != 0xFF) {
+					int x = c1 - d1;
+					if (x > -6 && x < 6) {
+						int y = c2 - d2;
+						if (y > -6 && y < 6) {
+							_byte16C9F = 1;
+
+							if (c1 == d1 && c2 == d2) {
+								_byte16C9F = 4;
+							}
+							else {
+								if((_rulesBuffer2_11[index] & 4) == 0) {
+									if (_rulesBuffer2_9[index] == 0) {
+										if (d1 > c1) {
+											_byte16C9F = 2;
+											if (d2 == c2) {
+												_byte16C9F = 3;
+											} else {
+												if (sub16DD5(c1,d1,c2,d2)) {
+													_byte16C9F = 1;	
+												}
+											}
+										}
+									}
+									else if (_rulesBuffer2_9[index] == 1) {
+										if (d2 < c2) {
+											_byte16C9F = 2;
+											if(d1 == c1) {
+												_byte16C9F = 3;
+											} else {
+												if (sub16DD5(c1,d1,c2,d2)) {
+													_byte16C9F = 1;	
+												}
+											}
+										}
+									}
+									else if (_rulesBuffer2_9[index] == 2) {
+										if (d2 > c2) {
+											_byte16C9F = 2;
+											if(d1 == c1) {
+												_byte16C9F = 3;
+											} else {
+												if (sub16DD5(c1,d1,c2,d2)) {
+													_byte16C9F = 1;	
+												}
+											}
+										}
+									} 
+									else {
+										if (d1 < c1) {
+											_byte16C9F = 2;
+											if (d2 == c2) {
+												_byte16C9F = 3;
+											} else {
+												if (sub16DD5(c1,d1,c2,d2)) {
+													_byte16C9F = 1;	
+												}
+											}
+										}
+									}
+
+									
+								}
+							}
+						}
+					}
+				}
+			
+				int val = _scriptHandler->_array10B51[index2 + index * 40];
+				val = (val & 0xFF) + ((val & 0xFF) << 8);
+				if( (val & 0xFF) != _byte16C9F ) {
+					_scriptHandler->_array10B29[index] = 1;
+					val = (val & 0xFF00) | _byte16C9F;
+				}
+				_scriptHandler->_array10B51[index2 + index * 40] = val;	
+			}
+
+		}
+
+	}
+}
+
 void LilliputEngine::displayFunction17() {
 	debugC(2, kDebugEngine, "displayFunction17()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 48971b4..49a1a04 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -238,9 +238,11 @@ public:
 	int sub16675(int idx, int var1);
 	int sub16685(int idx, int var1);
 	void sub16EBC();
+	void sub16CA0();
 	int sub166DD(int index, int var1);
 	void sub171CF();
 	void sub12FE5();
+	int sub16DD5(int x1, int y1, int x2, int y2);
 	void displayHeroismIndicator();
 
 	void initGame(const LilliputGameDescription *gd);
@@ -276,6 +278,7 @@ public:
 	byte _byte12FCE;
 	byte _byte129A0;
 	byte _byte160FA;
+	byte _byte16C9F; 
 	int _word10804;
 	int _word16213;
 	int _word16215;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 9c8381e..3ea5079 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -44,6 +44,8 @@ public:
 	byte _array12811[40];
 	byte _array10AB1[40];
 	byte _array122FD[20];
+	short _array10B51[40 * 40];
+
 	byte *_savedBuffer215Ptr;
 
 	int _word12A00;
@@ -76,7 +78,6 @@ private:
 
 	byte _array128EF[40];
 	byte _array12839[40];
-	byte _array10B51[40 * 40];
 
 	int _word16F00;
 	int _word10804;


Commit: 8d5c377b45fe929afec3af83619c669193808556
    https://github.com/scummvm/scummvm/commit/8d5c377b45fe929afec3af83619c669193808556
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: (Hopefully) fix sub16CA0

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ecefbdc..1ee7316 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -699,101 +699,91 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 }
 
 void LilliputEngine::sub16CA0() {
-
+	debugC(2, kDebugEngine, "sub16CA0()");
 
 	for (int index = _word10807_ERULES - 1; index >= 0; index--) {
 		if (_rulesBuffer2_11[index] & 1)
 			continue;
+
 		int c1 = _scriptHandler->_array16123[index];
 		int c2 = _scriptHandler->_array1614B[index];
 
 		for(int index2 = _word10807_ERULES - 1; index2 >= 0; index2--) {
-			if ( index == index2 )
-				continue;
-
-			if (_rulesBuffer2_5[index] != index2 &&
-				_rulesBuffer2_5[index2] != index &&
+			_byte16C9F = 0;
+			if ((index != index2 ) && 
+				(_rulesBuffer2_5[index] != index2) &&
+				(_rulesBuffer2_5[index2] != index) &&
 				(_rulesBuffer2_11[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_array16123[index2];
 				int d2 = _scriptHandler->_array1614B[index2];
-
+	
 				if (d1 != 0xFF) {
 					int x = c1 - d1;
-					if (x > -6 && x < 6) {
+					if ((x > -6) && (x < 6)) {
 						int y = c2 - d2;
-						if (y > -6 && y < 6) {
+						if ((y > -6) && (y < 6)) {
 							_byte16C9F = 1;
-
-							if (c1 == d1 && c2 == d2) {
+	
+							if ((c1 == d1) && (c2 == d2)) {
 								_byte16C9F = 4;
-							}
-							else {
-								if((_rulesBuffer2_11[index] & 4) == 0) {
-									if (_rulesBuffer2_9[index] == 0) {
-										if (d1 > c1) {
-											_byte16C9F = 2;
-											if (d2 == c2) {
-												_byte16C9F = 3;
-											} else {
-												if (sub16DD5(c1,d1,c2,d2)) {
-													_byte16C9F = 1;	
-												}
-											}
-										}
+							} else if((_rulesBuffer2_11[index] & 4) != 0) {
+								_byte16C9F = 0;
+							} else {
+								if (_rulesBuffer2_9[index] == 0) {
+									if (d1 > c1) {
+										_byte16C9F = 2;
+
+										if (d2 == c2)
+											_byte16C9F = 3;
+
+										if (sub16DD5(c1, d1, c2, d2) != 0)
+											_byte16C9F = 1;	
 									}
-									else if (_rulesBuffer2_9[index] == 1) {
-										if (d2 < c2) {
-											_byte16C9F = 2;
-											if(d1 == c1) {
-												_byte16C9F = 3;
-											} else {
-												if (sub16DD5(c1,d1,c2,d2)) {
-													_byte16C9F = 1;	
-												}
-											}
-										}
+								} else if (_rulesBuffer2_9[index] == 1) {
+									if (d2 < c2) {
+										_byte16C9F = 2;
+
+										if(d1 == c1)
+											_byte16C9F = 3;
+
+										if (sub16DD5(c1, d1, c2, d2) != 0)
+											_byte16C9F = 1;	
 									}
-									else if (_rulesBuffer2_9[index] == 2) {
-										if (d2 > c2) {
-											_byte16C9F = 2;
-											if(d1 == c1) {
-												_byte16C9F = 3;
-											} else {
-												if (sub16DD5(c1,d1,c2,d2)) {
-													_byte16C9F = 1;	
-												}
-											}
-										}
-									} 
-									else {
-										if (d1 < c1) {
-											_byte16C9F = 2;
-											if (d2 == c2) {
-												_byte16C9F = 3;
-											} else {
-												if (sub16DD5(c1,d1,c2,d2)) {
-													_byte16C9F = 1;	
-												}
-											}
-										}
+								} else if (_rulesBuffer2_9[index] == 2) {
+									if (d2 > c2) {
+										_byte16C9F = 2;
+
+										if(d1 == c1)
+											_byte16C9F = 3;
+
+										if (sub16DD5(c1, d1, c2, d2) != 0)
+											_byte16C9F = 1;	
 									}
+								} else {
+									if (d1 < c1) {
+										_byte16C9F = 2;
 
-									
+										if (d2 == c2)
+											_byte16C9F = 3;
+
+										if (sub16DD5(c1, d1, c2, d2) != 0)
+											_byte16C9F = 1;	
+									}
 								}
 							}
 						}
 					}
 				}
-			
-				int val = _scriptHandler->_array10B51[index2 + index * 40];
-				val = (val & 0xFF) + ((val & 0xFF) << 8);
-				if( (val & 0xFF) != _byte16C9F ) {
-					_scriptHandler->_array10B29[index] = 1;
-					val = (val & 0xFF00) | _byte16C9F;
-				}
-				_scriptHandler->_array10B51[index2 + index * 40] = val;	
 			}
 
+			int val = _scriptHandler->_array10B51[index2 + index * 40];
+			val = (val & 0xFF) + ((val & 0xFF) << 8);
+			if( (val & 0xFF) != _byte16C9F ) {
+				_scriptHandler->_array10B29[index] = 1;
+				val = (val & 0xFF00) | _byte16C9F;
+			}
+			_scriptHandler->_array10B51[index2 + index * 40] = val;	
+
 		}
 
 	}


Commit: 7bbfe71785f9a71d2792da0ac2e072618457950e
    https://github.com/scummvm/scummvm/commit/7bbfe71785f9a71d2792da0ac2e072618457950e
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implemented sub16DD5

It looks like a collision line test between 2 points

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 1ee7316..8fe0a34 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -694,8 +694,67 @@ void LilliputEngine::displayFunction16() {
 
 int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 {
-	warning("sub16DD5");
-	return 0;
+	byte* isoMap = _bufferIsoMap + (x1 << 8) + (y1 << 2) + 1;
+
+	int dx = x2 - x1;
+	int dy = y2 - y1;
+
+	int word16DCB = 0; 
+	int word16DCD = 0;
+	int word16DD1 = 0;
+	int word16DCF = 0;
+
+	byte byte16DD4 = 0;
+	byte byte16DD3 = 0;
+
+	if(dx < 0) {
+		dx = -dx;
+		word16DCB = -4;
+	} else {
+		word16DCB = 4;
+	}
+
+	if(dy < 0) {
+		dy = -dy;
+		word16DCD = -256;
+	} else {
+		word16DCD = 256;
+	}
+
+	if(dy > dx) {
+		word16DD1 = 0;
+		word16DCF = word16DCB;
+	} else {
+		int tmp = dx;
+		dy = dx;
+		dx = tmp;
+		word16DCF = 0;
+		word16DD1 = word16DCD;
+	}
+
+	byte16DD4 = (dx << 1) - dy;
+	byte16DD3 = (dx << 1) - 2 * dy;
+	word16DCF = word16DD1;
+	word16DCB += word16DCD;
+
+	int var1 = byte16DD4;
+	int count = 0; 
+
+	while ( *isoMap == 0xFF ) {
+		if (var1 > 0) {
+			isoMap += word16DCB;
+			var1 += byte16DD3;
+		} else {
+			isoMap += word16DCF;
+			var1 += byte16DD4;
+		}
+		
+		count++;
+		if (count == dy) {
+			return 0;
+		}
+	}
+	return 1;
 }
 
 void LilliputEngine::sub16CA0() {


Commit: a8699a809e4b72a59ea672b42c55642e21075fa0
    https://github.com/scummvm/scummvm/commit/a8699a809e4b72a59ea672b42c55642e21075fa0
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add missing addition in sub16DD5

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8fe0a34..6725a66 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -734,7 +734,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 
 	byte16DD4 = (dx << 1) - dy;
 	byte16DD3 = (dx << 1) - 2 * dy;
-	word16DCF = word16DD1;
+	word16DCF += word16DD1;
 	word16DCB += word16DCD;
 
 	int var1 = byte16DD4;


Commit: 1864f1e5189aa039a2f3c7e3aa7e9dc86927f5be
    https://github.com/scummvm/scummvm/commit/1864f1e5189aa039a2f3c7e3aa7e9dc86927f5be
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement some more core functions

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6725a66..35261f3 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -143,6 +143,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12A09 = 0;
 	_byte1881D = 0;
 	_byte16552 = 0;
+	_byte12FE4 = 0xFF;
+	_byte12FE3 = 0;
 
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
@@ -686,7 +688,7 @@ void LilliputEngine::displayFunction16() {
 		sub16CA0();
 		sub16EBC();
 		sub171CF();
-		warning("sub_130EE");
+		sub130EE();
 		sub12FE5();
 		displayHeroismIndicator();
 	}
@@ -1278,6 +1280,100 @@ void LilliputEngine::sub12F37() {
 	}
 }
 
+void LilliputEngine::sub130EE() {
+	debugC(2, kDebugEngine, "sub130EE()");
+
+	warning("sub147D7");
+	warning("sub13156");
+
+	if (_mouseButton == 0)
+		// TODO: check _mouse_byte1299F
+		return;
+
+	int button = _mouseButton;
+	_mouseButton = 0;
+
+	if (button & 2) {
+		if (_byte12FE4 != 0xFF)
+			sub1305C(_byte12FE4, button);
+		return;
+	}
+
+	sub13184();
+	int posX = _mouseX - 64;
+	int posY = _mouseY - 16;
+
+	if ((posX < 0) || (posX > 255))
+		return;
+	
+	if ((posY < 0) || (posY > 176))
+		return;
+
+	warning("sub131B2");
+	warning("sub131FC");
+}
+
+void LilliputEngine::sub13184() {
+	debugC(2, kDebugEngine, "sub13184()");
+
+	for (int index = _word12F68_ERULES - 1; index >= 0; index--) {
+		if (sub13240(_mouseX, _mouseY, _rulesBuffer13_2[index], _rulesBuffer13_3[index]) == 0) {
+			sub1305C(index, 1);
+			warning("TODO: sub13184 - add parameter to force return in calling function");
+		}
+	}
+}
+
+int LilliputEngine::sub13240(int posX, int posY, int var3, int var4) {
+	debugC(2, kDebugEngine, "sub13240(%d, %d, %d, %d)", posX, posY, var3, var4);
+
+	if ((posX < var3) || (posY < var4))
+		return -1;
+
+	var3 += 16;
+	var4 += 16;
+
+	if ((posX > var3) || (posY > var4))
+		return -1;
+
+	return 0;
+}
+
+void LilliputEngine::sub1305C(byte index, byte button) {
+	debugC(2, kDebugEngine, "sub1305C(%d, %d)", index, button);
+
+	if (_scriptHandler->_array122E9[index] < 2)
+		return;
+
+	_byte12FE4 = index;
+	_byte12FE3 = button;
+
+	if (button == 2) {
+		if (_byte12FCE != 1) {
+			_scriptHandler->_array122E9[index] = 2;
+			_byte16F07_menuId = 2;
+			displayFunction8();
+		}
+		return;
+	}
+
+	if (_byte12FCE == 1) {
+		sub130DD();
+		return;
+	}
+
+	_scriptHandler->sub130B6();
+	_scriptHandler->_array122E9[index] = 3;
+	if (_rulesBuffer13_1[index] == 1) {
+		_byte12FCE = 1;
+		_word15AC2 = 1;
+	} else {
+		_byte16F07_menuId = 1;
+	}
+
+	displayFunction8();
+}
+
 int LilliputEngine::sub16685(int idx, int var1) {
 	debugC(2, kDebugEngine, "sub16685(%d, %d)", idx, var1);
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 49a1a04..6ddfb07 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -101,6 +101,8 @@ public:
 	byte _byte12A09;
 	byte _byte1881D;
 	byte _byte16552;
+	byte _byte12FE4;
+	byte _byte12FE3;
 
 	byte _buffer1[45056];
 	byte _buffer2[45056];
@@ -244,6 +246,10 @@ public:
 	void sub12FE5();
 	int sub16DD5(int x1, int y1, int x2, int y2);
 	void displayHeroismIndicator();
+	void sub130EE();
+	void sub1305C(byte index, byte var2);
+	void sub13184();
+	int sub13240(int posX, int posY, int var3, int var4);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 3ea5079..63a9aab 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -57,6 +57,8 @@ public:
 
 	short _array12311[640];
 
+	void sub130B6();
+
 	LilliputScript(LilliputEngine *vm);
 	~LilliputScript();
 
@@ -103,8 +105,6 @@ private:
 	int getValue1();
 	int getValue2();
 
-	void sub130B6();
-
 	byte *getBuffer215Ptr();
 	byte compareValues(byte var1, int oper, int var2);
 	void computeOperation(byte *bufPtr, int oper, int var2);


Commit: b348db605b07cd829ab275d921a5b3ce8d0ecf4c
    https://github.com/scummvm/scummvm/commit/b348db605b07cd829ab275d921a5b3ce8d0ecf4c
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implements character display on map

Draw and restore points

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 35261f3..e808f48 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -436,7 +436,7 @@ void LilliputEngine::displayFunction7() {
 void LilliputEngine::displayFunction8() {
 	debugC(2, kDebugEngine, "displayFunction8()");
 
-	if (_scriptHandler->_byte16F08 == 1)
+	if (_scriptHandler->displayMap == 1)
 		return;
 
 	displayFunction5();
@@ -538,7 +538,7 @@ void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3)
 void LilliputEngine::displayFunction14() {
 	debugC(2, kDebugEngine, "displayFunction14()");
 
-	if (_scriptHandler->_byte16F08 == 1)
+	if (_scriptHandler->displayMap == 1)
 		return;
 
 	if (_mouseDisplayX > 48)
@@ -557,6 +557,37 @@ void LilliputEngine::displayFunction14() {
 	displayFunction4();
 };
 
+void LilliputEngine::restoreMapPoints() {
+	displayFunction5();
+
+	byte* buf = (byte*)_mainSurface->getPixels();
+	for (int index = 0; index < _word10807_ERULES; index++) {
+		buf[_word15E5D[index]] = _byte15E35[index];
+	}
+
+	displayFunction4();
+}
+
+void LilliputEngine::displayCharactersOnMap() {
+	sub16217();
+	displayFunction5();
+
+	byte* buf = (byte*)_mainSurface->getPixels();
+	for( int index = _word10807_ERULES - 1; index >=0; index--) {
+		if(_rulesBuffer2_11[index] & 2 == 0 &&
+		   _scriptHandler->_array1614B[index] != -1) {
+			 int y = 3 * _scriptHandler->_array1614B[index] + 1;
+			 int x = _scriptHandler->_array16123[index] * 4 + 1;
+
+			 _word15E5D[index] = y * 320 + x;
+			 _byte15E35[index] = buf[y * 320 + x];
+			 buf[y * 320 + x] = _scriptHandler->_array128EF[index];
+
+		}
+	}
+	displayFunction4();
+}
+
 void LilliputEngine::sub16217() {
 	debugC(2, kDebugEngine, "sub16217()");
 
@@ -669,15 +700,15 @@ void LilliputEngine::displayFunction15() {
 void LilliputEngine::displayFunction16() {
 	debugC(2, kDebugEngine, "displayFunction16()");
 
-	if (_scriptHandler->_byte16F08 == 1) {
+	if (_scriptHandler->displayMap == 1) {
 		warning("sub_15F31");
-		warning("sub_15F0C");
+		restoreMapPoints();
 		sub16626();
 		sub12F37();
 		sub16CA0();
 		sub16EBC();
 		sub171CF();
-		warning("sub_15EAE");
+		displayCharactersOnMap();
 	} else {
 		sub1638C();
 		sub189DE();
@@ -701,7 +732,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 	int dx = x2 - x1;
 	int dy = y2 - y1;
 
-	int word16DCB = 0; 
+	int word16DCB = 0;
 	int word16DCD = 0;
 	int word16DD1 = 0;
 	int word16DCF = 0;
@@ -740,7 +771,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 	word16DCB += word16DCD;
 
 	int var1 = byte16DD4;
-	int count = 0; 
+	int count = 0;
 
 	while ( *isoMap == 0xFF ) {
 		if (var1 > 0) {
@@ -750,7 +781,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 			isoMap += word16DCF;
 			var1 += byte16DD4;
 		}
-		
+
 		count++;
 		if (count == dy) {
 			return 0;
@@ -771,20 +802,20 @@ void LilliputEngine::sub16CA0() {
 
 		for(int index2 = _word10807_ERULES - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
-			if ((index != index2 ) && 
+			if ((index != index2 ) &&
 				(_rulesBuffer2_5[index] != index2) &&
 				(_rulesBuffer2_5[index2] != index) &&
 				(_rulesBuffer2_11[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_array16123[index2];
 				int d2 = _scriptHandler->_array1614B[index2];
-	
+
 				if (d1 != 0xFF) {
 					int x = c1 - d1;
 					if ((x > -6) && (x < 6)) {
 						int y = c2 - d2;
 						if ((y > -6) && (y < 6)) {
 							_byte16C9F = 1;
-	
+
 							if ((c1 == d1) && (c2 == d2)) {
 								_byte16C9F = 4;
 							} else if((_rulesBuffer2_11[index] & 4) != 0) {
@@ -798,7 +829,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else if (_rulesBuffer2_9[index] == 1) {
 									if (d2 < c2) {
@@ -808,7 +839,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else if (_rulesBuffer2_9[index] == 2) {
 									if (d2 > c2) {
@@ -818,7 +849,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else {
 									if (d1 < c1) {
@@ -828,7 +859,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								}
 							}
@@ -843,7 +874,7 @@ void LilliputEngine::sub16CA0() {
 				_scriptHandler->_array10B29[index] = 1;
 				val = (val & 0xFF00) | _byte16C9F;
 			}
-			_scriptHandler->_array10B51[index2 + index * 40] = val;	
+			_scriptHandler->_array10B51[index2 + index * 40] = val;
 
 		}
 
@@ -1237,7 +1268,7 @@ void LilliputEngine::sub16626() {
 }
 
 int LilliputEngine::sub166DD(int index, int var1) {
-	
+
 	_rulesBuffer2_9[index] = (var1 >> 8) & 3;
 	sub16685(index, var1 & 0xFF);
 	return 0;
@@ -1305,7 +1336,7 @@ void LilliputEngine::sub130EE() {
 
 	if ((posX < 0) || (posX > 255))
 		return;
-	
+
 	if ((posY < 0) || (posY > 176))
 		return;
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 6ddfb07..948e051 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -132,6 +132,8 @@ public:
 	int _word16550;
 	int _displayStringIndex;
 	int _word1289D;
+	short _word15E5D[40];
+	byte _byte15E35[40];
 
 	int _array11D49[40];
 	int _array1289F[40];
@@ -245,6 +247,8 @@ public:
 	void sub171CF();
 	void sub12FE5();
 	int sub16DD5(int x1, int y1, int x2, int y2);
+	void displayCharactersOnMap();
+	void restoreMapPoints();
 	void displayHeroismIndicator();
 	void sub130EE();
 	void sub1305C(byte index, byte var2);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 59180a0..4de7063 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -30,7 +30,7 @@ namespace Lilliput {
 
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 	_byte129A0 = 0xFF;
-	_byte16F08 = 0;
+	displayMap = 0;
 	_byte1855D = 0;
 	_byte12A04 = 0;
 	_byte10806 = 0;
@@ -764,7 +764,7 @@ void LilliputScript::sub16C5C(int index, byte var3) {
 int LilliputScript::sub17D40(int var) {
 	debugC(1, kDebugScript, "sub17D40(%d)", var);
 
-	if ((_byte16F08 != 1) && (_array16173[_vm->_rulesBuffer2PrevIndx] != 0xFF))
+	if ((displayMap != 1) && (_array16173[_vm->_rulesBuffer2PrevIndx] != 0xFF))
 		return var;
 
 	warning("sub17D40() - FIXME: Unexpected POP");
@@ -1340,7 +1340,7 @@ void LilliputScript::OC_sub17D57() {
 
 	int curWord = _currScript->readUint16LE();
 
-	if((_byte16F08 == 1) || (_array16173[_vm->_rulesBuffer2PrevIndx] == 0xFF))
+	if((displayMap == 1) || (_array16173[_vm->_rulesBuffer2PrevIndx] == 0xFF))
 		return;
 
 	_word1881B = _vm->_rulesBuffer2PrevIndx;
@@ -1766,7 +1766,7 @@ void LilliputScript::OC_sub1847F() {
 	int var2 = _currScript->readUint16LE();
 	int var4 = _currScript->readUint16LE();
 
-	if (_byte16F08 != 1) {
+	if (displayMap != 1) {
 		_vm->displayFunction5();
 		sub18BE6(var1 & 0xFF, var2, var4);
 		_vm->displayFunction4();
@@ -1839,7 +1839,7 @@ void LilliputScript::OC_sub1853B() {
 	debugC(1, kDebugScript, "OC_sub1853B()");
 
 	OC_PaletteFadeOut();
-	_byte16F08 = 0;
+	displayMap = 0;
 	_byte15FFA = 0;
 	sub130B6();
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 63a9aab..e29c676 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -32,7 +32,7 @@ namespace Lilliput {
 class LilliputEngine;
 class LilliputScript {
 public:
-	byte _byte16F08;
+	byte displayMap;
 	byte _byte12A04;
 	byte _byte15FFA;
 
@@ -56,6 +56,8 @@ public:
 	int _word15FFD;
 
 	short _array12311[640];
+	byte _array128EF[40];
+	byte _array12839[40];
 
 	void sub130B6();
 
@@ -78,8 +80,6 @@ private:
 	byte _byte12FE4;
 	byte _byte16F02;
 
-	byte _array128EF[40];
-	byte _array12839[40];
 
 	int _word16F00;
 	int _word10804;


Commit: 1b86a778f3e37eb54e0ea5bdfc528d3f98695c51
    https://github.com/scummvm/scummvm/commit/1b86a778f3e37eb54e0ea5bdfc528d3f98695c51
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implements displayFunction18

Draw characters (men or men2)

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index e808f48..1e21c2a 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -283,6 +283,44 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
+
+void LilliputEngine::displayFunction18(int index, int position, int flags) {
+
+	byte* buf = _buffer1_45k + ((position & 0xFF) << 8) + (position >> 8);
+
+	byte* src = _bufferMen;
+	if (index < 0) {
+		src = _bufferIdeogram;
+		index = -index;
+	} else if (index > 0xF0) {
+		src = _bufferMen2;
+		index -= 0xF0;
+	}
+
+	src += index << 8;
+
+	if ( (flags & 2) == 0 ) {
+		for (int y = 0; y < 16; y++) {
+			for (int x = 0; x < 16; x++) {
+				if (src[x] != 0)
+					buf[x] = src[x];
+			}
+			src += 16;
+			buf += 256;
+		}
+	} else {
+		src += 14;
+		for (int y = 0; y < 16; y++) {
+			for (int x = 0; x < 16; x++) {
+				if (src[x] != 0)
+					buf[x] = src[x];
+			}
+			src += 32;
+			buf += 256;
+		}
+	} 
+}
+
 // display mouse cursor, if any
 void LilliputEngine::displayFunction1(byte *buf, int var1, int var2, int var4) {
 	debugC(2, kDebugEngine, "displayFunction1(buf, %d, %d, %d)", var1, var2, var4);
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 948e051..f0f0009 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -224,6 +224,7 @@ public:
 	void displayFunction15();
 	void displayFunction16();
 	void displayFunction17();
+	void displayFunction18(int index, int var2, int flags);
 	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
 


Commit: 59b9b70413412360b8c36811f425ab5d628612cd
    https://github.com/scummvm/scummvm/commit/59b9b70413412360b8c36811f425ab5d628612cd
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement some more functions

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 1e21c2a..ae286e1 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -612,15 +612,13 @@ void LilliputEngine::displayCharactersOnMap() {
 
 	byte* buf = (byte*)_mainSurface->getPixels();
 	for( int index = _word10807_ERULES - 1; index >=0; index--) {
-		if(_rulesBuffer2_11[index] & 2 == 0 &&
-		   _scriptHandler->_array1614B[index] != -1) {
-			 int y = 3 * _scriptHandler->_array1614B[index] + 1;
-			 int x = _scriptHandler->_array16123[index] * 4 + 1;
+		if(((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614B[index] != -1)) {
+			 int y = (3 * _scriptHandler->_array1614B[index]) + 1;
+			 int x = (_scriptHandler->_array16123[index] * 4) + 1;
 
 			 _word15E5D[index] = y * 320 + x;
 			 _byte15E35[index] = buf[y * 320 + x];
 			 buf[y * 320 + x] = _scriptHandler->_array128EF[index];
-
 		}
 	}
 	displayFunction4();
@@ -1368,7 +1366,11 @@ void LilliputEngine::sub130EE() {
 		return;
 	}
 
-	sub13184();
+	bool forceReturnFl = false;
+	sub13184(forceReturnFl);
+	if (forceReturnFl)
+		return;
+
 	int posX = _mouseX - 64;
 	int posY = _mouseY - 16;
 
@@ -1378,17 +1380,62 @@ void LilliputEngine::sub130EE() {
 	if ((posY < 0) || (posY > 176))
 		return;
 
-	warning("sub131B2");
-	warning("sub131FC");
+	forceReturnFl = false;
+	sub131B2(posX, posY, forceReturnFl);
+	if (forceReturnFl)
+		return;
+
+	sub131FC(posX, posY);
+}
+
+void LilliputEngine::sub131FC(int var2, int var4) {
+	debugC(2, kDebugEngine, "sub131FC(%d, %d)", var2, var4);
+
+	int x = var2 - 8;
+	int y = var4 - 4;
+
+	x = (x >> 4) - 7;
+	y = (y >> 3) - 4;
+
+	int diff = (y - x) >> 1;
+	y = y - diff;
+
+	if ((y >= 0) && (diff >= 0) && (y < 8) && (diff < 8)) {
+		y += _scriptHandler->_word12A00;
+		diff += _scriptHandler->_word12A02;
+		_savedMousePosDivided = (y << 8) + diff;
+		_byte16F07_menuId = 5;
+	}
 }
 
-void LilliputEngine::sub13184() {
+void LilliputEngine::sub131B2(int var2, int var4, bool &forceReturnFl) {
+	debugC(2, kDebugEngine, "sub131B2(%d, %d)", var2, var4);
+
+	forceReturnFl = false;
+
+	for (int i = 0; i < _word10807_ERULES; i++) {
+		if ((var2 >= _array161C3[i]) && (var2 <= _array161C3[i] + 17) && (var4 >= _array161EB[i]) && (var4 <= _array161EB[i] + 17) && (i != _word10804)) {
+			_byte129A0 = i;
+			_byte16F07_menuId = 4;
+			if (_byte12FCE == 1)
+				_byte16F07_menuId = 3;
+
+			return;
+		}
+	}
+	forceReturnFl = true;
+	return;
+}
+
+void LilliputEngine::sub13184(bool &forceReturnFl) {
 	debugC(2, kDebugEngine, "sub13184()");
 
+	forceReturnFl = false;
 	for (int index = _word12F68_ERULES - 1; index >= 0; index--) {
 		if (sub13240(_mouseX, _mouseY, _rulesBuffer13_2[index], _rulesBuffer13_3[index]) == 0) {
 			sub1305C(index, 1);
-			warning("TODO: sub13184 - add parameter to force return in calling function");
+			forceReturnFl = true;
+			return;
 		}
 	}
 }
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index f0f0009..8ad1fef 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -253,8 +253,10 @@ public:
 	void displayHeroismIndicator();
 	void sub130EE();
 	void sub1305C(byte index, byte var2);
-	void sub13184();
+	void sub13184(bool &forceReturnFl);
 	int sub13240(int posX, int posY, int var3, int var4);
+	void sub131B2(int var2, int var4, bool &forceReturnFl);
+	void sub131FC(int var2, int var4);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);


Commit: 9054e0f0d6007a5e745e49ce20c3440aeca4bdd2
    https://github.com/scummvm/scummvm/commit/9054e0f0d6007a5e745e49ce20c3440aeca4bdd2
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a couple of glitches

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ae286e1..3bf5c87 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -285,6 +285,7 @@ Common::Platform LilliputEngine::getPlatform() const {
 
 
 void LilliputEngine::displayFunction18(int index, int position, int flags) {
+	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d)", index, position, flags);
 
 	byte* buf = _buffer1_45k + ((position & 0xFF) << 8) + (position >> 8);
 
@@ -292,7 +293,7 @@ void LilliputEngine::displayFunction18(int index, int position, int flags) {
 	if (index < 0) {
 		src = _bufferIdeogram;
 		index = -index;
-	} else if (index > 0xF0) {
+	} else if (index >= 0xF0) {
 		src = _bufferMen2;
 		index -= 0xF0;
 	}
@@ -1616,12 +1617,13 @@ void LilliputEngine::displayHeroismIndicator() {
 	int var4 = (_scriptHandler->_word15FFD >> 8) + ((_scriptHandler->_word15FFD & 0xFF) << 8);
 	int index = _scriptHandler->_word15FFB + var4 + (var4 >> 2);
 
-	if ((_scriptHandler->_byte15FFA & 0xFF) == 0) {
+	var2 = _scriptHandler->_byte15FFA & 0xFF;
+	if (var2 != 0) {
 //		sub16064(var1, _scriptHandler->_byte15FFA);
-		for (int i = 0; i < (_scriptHandler->_byte15FFA << 2); i++) {
-			((byte *)_mainSurface->getPixels())[index - (i * 320)] = var1;
-			((byte *)_mainSurface->getPixels())[index - (i * 320) + 1] = var1;
-			((byte *)_mainSurface->getPixels())[index - (i * 320) + 2] = var1;
+		for (int i = 0; i < (var2 << 2); i++) {
+			((byte *)_mainSurface->getPixels())[index - (i * 320)] = var1; 
+			((byte *)_mainSurface->getPixels())[index - (i * 320) + 1] = var1; 
+			((byte *)_mainSurface->getPixels())[index - (i * 320) + 2] = var1; 
 		}
 	}
 


Commit: bbea84b4b174b1d3f201151ec33377adf329812f
    https://github.com/scummvm/scummvm/commit/bbea84b4b174b1d3f201151ec33377adf329812f
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Character rendering

Characters are now rendered (no animation yet though)

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3bf5c87..9e114f4 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -132,7 +132,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte1714E = 0;
 	_byte12FCE = 0;
 	_byte129A0 = 0xFF;
-	_byte160FA = 0;
+	_numCharactersToDisplay = 0;
 	_byte16529 = 0;
 	_byte1652A = 0;
 	_byte12A04 = 0;
@@ -166,7 +166,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	for (int i = 0; i < 40; i++) {
 		_array10999[i] = 0;
 		_array109C1[i] = 0;
-		_array160FB[i] = 0;
+		_charactersToDisplay[i] = 0;
 		_array16173[i] = 0xFF;
 		_array1619B[i] = 0xFF;
 		_array161C3[i] = 0;
@@ -628,7 +628,7 @@ void LilliputEngine::displayCharactersOnMap() {
 void LilliputEngine::sub16217() {
 	debugC(2, kDebugEngine, "sub16217()");
 
-	_byte160FA = 0;
+	_numCharactersToDisplay = 0;
 	int index = _word10807_ERULES - 1;
 	_word16213 = _scriptHandler->_word12A00 << 3;
 	_word16215 = _scriptHandler->_word12A02 << 3;
@@ -668,29 +668,29 @@ void LilliputEngine::sub16217() {
 		_array161C3[i] = 0xFF;
 		_array161EB[i] = 0xFF;
 
-		int tmpVal2 = _rulesBuffer2_1[i] - _scriptHandler->_word12A00;
-		int tmpVal3 = _rulesBuffer2_2[i] - _scriptHandler->_word12A02;
+		int tmpVal2 = (_rulesBuffer2_1[i] >> 3) - _scriptHandler->_word12A00;
+		int tmpVal3 = (_rulesBuffer2_2[i] >> 3) - _scriptHandler->_word12A02;
 		if ((tmpVal2 >= 0) && (tmpVal2 <= 7) && (tmpVal3 >= 0) && (tmpVal3 <= 7)) {
 			_array16173[i] = tmpVal2;
 			_array1619B[i] = tmpVal3;
 			tmpVal2 = _rulesBuffer2_1[i] - _word16213;
-			tmpVal3 = _rulesBuffer2_2[i] - _word16213;
+			tmpVal3 = _rulesBuffer2_2[i] - _word16215;
 			int tmpVal4 = _rulesBuffer2_3[i];
 			_array161C3[i] = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF;
 			_array161EB[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
-			_array160FB[_byte160FA] = i;
-			++_byte160FA;
-		}
+			_charactersToDisplay[_numCharactersToDisplay] = i;
+			++_numCharactersToDisplay;
+ 		}
 	}
 
-	sub16323();
+	sortCharacters();
 }
 
 void LilliputEngine::sub1652B(int var1) {
 	debugC(2, kDebugEngine, "sub1652B(%d)", var1);
 
-	if (_byte160FA < (var1 & 0xFF)) {
-		int index = _array160FB[var1 & 0xFF];
+	if ( (var1 & 0xFF) < _numCharactersToDisplay) {
+		int index = _charactersToDisplay[var1 & 0xFF];
 		_byte16529 = _array16173[index];
 		_byte1652A = _array1619B[index];
 	} else {
@@ -720,7 +720,7 @@ void LilliputEngine::displayFunction15() {
 					var1 += _scriptHandler->_byte12A04;
 				displayFunction13(_buffer1_45k, var1, tmpVal, 1 << 8);
 			}
-			sub16553(map);
+			sub16553(map, j, i);
 
 			if (map[2] != 0xFF) {
 				int var1 = map[2];
@@ -960,19 +960,19 @@ void LilliputEngine::displayChar(int index, int var1) {
 
 }
 
-void LilliputEngine::sub16323() {
+void LilliputEngine::sortCharacters() {
 	debugC(2, kDebugEngine, "sub16323()");
 
-	if (_byte160FA <= 1)
+	if (_numCharactersToDisplay <= 1)
 		return;
 
 	int var3;
-	for (int var4 = _byte160FA - 1; var4 != 0; var4--) {
+	for (int var4 = _numCharactersToDisplay - 1; var4 != 0; var4--) {
 		var3 = 0;
 
 		for (int var2 = 0; var2 < var4; var2++) {
-			int index1 = _array160FB[var2];
-			int index2 = _array160FB[var2 + 1];
+			int index1 = _charactersToDisplay[var2];
+			int index2 = _charactersToDisplay[var2 + 1];
 
 			if (_array1619B[index1] < _array1619B[index2])
 				continue;
@@ -992,9 +992,9 @@ void LilliputEngine::sub16323() {
 				}
 			}
 
-			byte tmpVal = _array160FB[var2];
-			_array160FB[var2] = _array160FB[var2 + 1];
-			_array160FB[var2 + 1] = tmpVal;
+			byte tmpVal = _charactersToDisplay[var2];
+			_charactersToDisplay[var2] = _charactersToDisplay[var2 + 1];
+			_charactersToDisplay[var2 + 1] = tmpVal;
 			++var3;
 		}
 
@@ -1082,10 +1082,10 @@ void LilliputEngine::sub163F0(int var1, int var3) {
 	_soundHandler->contentFct5();
 }
 
-void LilliputEngine::sub16553(byte *buf) {
+void LilliputEngine::sub16553(byte *buf, int x, int y) {
 	debugC(2, kDebugEngine, "sub16553()");
 
-	if ((_byte16529 != 0) || (_byte1652A != 0))
+	if ((_byte16529 != x) || (_byte1652A != y))
 		return;
 
 	_byte16552 = 0;
@@ -1096,7 +1096,7 @@ void LilliputEngine::sub16553(byte *buf) {
 			++_byte16552;
 	}
 
-	int index = _array160FB[_word16550];
+	int index = _charactersToDisplay[_word16550];
 	int var2 = (_array161C3[index] << 8) + _array161EB[index];
 
 	if (index == _scriptHandler->_word1881B)
@@ -1117,14 +1117,14 @@ void LilliputEngine::sub16553(byte *buf) {
 				var1 = -var1;
 			}
 
-			warning("sub_152FC");
+			displayFunction18(var1, var2, var3);
 		}
 	}
 
 	++_word16550;
 	sub1652B(_word16550);
 
-	sub16553(buf);
+	sub16553(buf, x, y);
 }
 
 void LilliputEngine::sub189DE() {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8ad1fef..5b6567f 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -185,7 +185,7 @@ public:
 	byte _array10999[40];
 	byte _array109C1[40];
 	byte _array15AC8[256];
-	byte _array160FB[40];
+	byte _charactersToDisplay[40];
 	byte _array16173[40];
 	byte _array1619B[40];
 	byte _array161C3[40];
@@ -228,13 +228,13 @@ public:
 	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
 
-	void sub16323();
+	void sortCharacters();
 	void sub1638C();
 	void sub163F0(int var1, int var3);
 	void sub189DE();
 	void sub16626();
 
-	void sub16553(byte *buf);
+	void sub16553(byte *buf, int x, int y);
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
 	void sub18A3E(byte param1);
@@ -290,7 +290,7 @@ public:
 	byte _byte16F07_menuId;
 	byte _byte12FCE;
 	byte _byte129A0;
-	byte _byte160FA;
+	byte _numCharactersToDisplay;
 	byte _byte16C9F; 
 	int _word10804;
 	int _word16213;


Commit: b525867d4a0e44a3afae84b46e8801e8adac4432
    https://github.com/scummvm/scummvm/commit/b525867d4a0e44a3afae84b46e8801e8adac4432
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Small fixes and renaming

Renamed variables about character positions
Fixed heroism display

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 9e114f4..0ccfdf7 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -167,18 +167,18 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array10999[i] = 0;
 		_array109C1[i] = 0;
 		_charactersToDisplay[i] = 0;
-		_array16173[i] = 0xFF;
-		_array1619B[i] = 0xFF;
-		_array161C3[i] = 0;
-		_array161EB[i] = 0;
+		_characterRelativePositionX[i] = 0xFF;
+		_characterRelativePositionY[i] = 0xFF;
+		_characterDisplayX[i] = 0;
+		_characterDisplayY[i] = 0;
 		_array12299[i] = 0xFF;
 		_array109E9[i] = 0xFF;
 		_array10A11[i] = 0xFF;
 		_array16E94[i] = 0;
 
 		_array11D49[i] = 0xFFFF;
-		_rulesBuffer2_1[i] = 0xFFFF;
-		_rulesBuffer2_2[i] = 0xFFFF;
+		_characterPositionX[i] = 0xFFFF;
+		_characterPositionY[i] = 0xFFFF;
 		_rulesBuffer2_3[i] = 0;
 		_rulesBuffer2_4[i] = 0;
 		_rulesBuffer2_5[i] = 0xFF;
@@ -284,10 +284,10 @@ Common::Platform LilliputEngine::getPlatform() const {
 }
 
 
-void LilliputEngine::displayFunction18(int index, int position, int flags) {
-	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d)", index, position, flags);
+void LilliputEngine::displayFunction18(int index, int x, int y, int flags) {
+	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d, %d)", index, x, y, flags);
 
-	byte* buf = _buffer1_45k + ((position & 0xFF) << 8) + (position >> 8);
+	byte* buf = _buffer1_45k + (y << 8) + x;
 
 	byte* src = _bufferMen;
 	if (index < 0) {
@@ -319,7 +319,7 @@ void LilliputEngine::displayFunction18(int index, int position, int flags) {
 			src += 32;
 			buf += 256;
 		}
-	} 
+	}
 }
 
 // display mouse cursor, if any
@@ -495,7 +495,7 @@ void LilliputEngine::displayFunction9() {
 
 	memcpy(_buffer2_45k, _buffer3_45k, 45056);
 
-	int var1 = (_scriptHandler->_word12A02 >> 8) + ((_scriptHandler->_word12A02 & 0xFF) << 8) + (_scriptHandler->_word12A00 << 2);
+	int var1 = (_scriptHandler->_viewportY >> 8) + ((_scriptHandler->_viewportY & 0xFF) << 8) + (_scriptHandler->_viewportX << 2);
 	int var2;
 	int index = 0;
 
@@ -630,8 +630,8 @@ void LilliputEngine::sub16217() {
 
 	_numCharactersToDisplay = 0;
 	int index = _word10807_ERULES - 1;
-	_word16213 = _scriptHandler->_word12A00 << 3;
-	_word16215 = _scriptHandler->_word12A02 << 3;
+	_word16213 = _scriptHandler->_viewportX << 3;
+	_word16215 = _scriptHandler->_viewportY << 3;
 
 	for (int i = index; i >= 0; i--) {
 		if (_rulesBuffer2_5[i] != 0xFF) {
@@ -639,8 +639,8 @@ void LilliputEngine::sub16217() {
 			_rulesBuffer2_3[i] = _rulesBuffer2_3[index2] + _rulesBuffer2_7[i];
 			int tmpVal = _rulesBuffer2_6[i];
 			_rulesBuffer2_9[i] = _rulesBuffer2_9[index2];
-			int var3 = _rulesBuffer2_1[index2];
-			int var4 = _rulesBuffer2_2[index2];
+			int var3 = _characterPositionX[index2];
+			int var4 = _characterPositionY[index2];
 
 			switch (_rulesBuffer2_9[i]) {
 			case 0:
@@ -657,30 +657,30 @@ void LilliputEngine::sub16217() {
 				break;
 			}
 
-			_rulesBuffer2_1[i] = var3;
-			_rulesBuffer2_2[i] = var4;
+			_characterPositionX[i] = var3;
+			_characterPositionY[i] = var4;
 		}
 
-		_scriptHandler->_array16123[i] = (_rulesBuffer2_1[i] & 0xFF);
-		_scriptHandler->_array1614B[i] = (_rulesBuffer2_2[i] & 0xFF);
+		_scriptHandler->_array16123[i] = (_characterPositionX[i] & 0xFF);
+		_scriptHandler->_array1614B[i] = (_characterPositionY[i] & 0xFF);
 		_scriptHandler->_array16173[i] = 0xFF;
-		_array1619B[i] = 0xFF;
-		_array161C3[i] = 0xFF;
-		_array161EB[i] = 0xFF;
+		_characterRelativePositionY[i] = 0xFF;
+		_characterDisplayX[i] = 0xFF;
+		_characterDisplayY[i] = 0xFF;
 
-		int tmpVal2 = (_rulesBuffer2_1[i] >> 3) - _scriptHandler->_word12A00;
-		int tmpVal3 = (_rulesBuffer2_2[i] >> 3) - _scriptHandler->_word12A02;
+		int tmpVal2 = (_characterPositionX[i] >> 3) - _scriptHandler->_viewportX;
+		int tmpVal3 = (_characterPositionY[i] >> 3) - _scriptHandler->_viewportY;
 		if ((tmpVal2 >= 0) && (tmpVal2 <= 7) && (tmpVal3 >= 0) && (tmpVal3 <= 7)) {
-			_array16173[i] = tmpVal2;
-			_array1619B[i] = tmpVal3;
-			tmpVal2 = _rulesBuffer2_1[i] - _word16213;
-			tmpVal3 = _rulesBuffer2_2[i] - _word16215;
+			_characterRelativePositionX[i] = tmpVal2;
+			_characterRelativePositionY[i] = tmpVal3;
+			tmpVal2 = _characterPositionX[i] - _word16213;
+			tmpVal3 = _characterPositionY[i] - _word16215;
 			int tmpVal4 = _rulesBuffer2_3[i];
-			_array161C3[i] = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF;
-			_array161EB[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
+			_characterDisplayX[i] = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF;
+			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
 			_charactersToDisplay[_numCharactersToDisplay] = i;
 			++_numCharactersToDisplay;
- 		}
+		}
 	}
 
 	sortCharacters();
@@ -691,8 +691,8 @@ void LilliputEngine::sub1652B(int var1) {
 
 	if ( (var1 & 0xFF) < _numCharactersToDisplay) {
 		int index = _charactersToDisplay[var1 & 0xFF];
-		_byte16529 = _array16173[index];
-		_byte1652A = _array1619B[index];
+		_byte16529 = _characterRelativePositionX[index];
+		_byte1652A = _characterRelativePositionY[index];
 	} else {
 		_byte16529 = 0xFF;
 		_byte1652A = 0xFF;
@@ -703,12 +703,12 @@ void LilliputEngine::displayFunction15() {
 	debugC(2, kDebugEngine, "displayFunction15()");
 
 	sub16217();
-	_word16550 = 0;
+	_currentDisplayCharacter = 0;
 	sub1652B(0);
 
 	memcpy(_buffer1_45k, _buffer2_45k, 45056);
 
-	int index1 = (_scriptHandler->_word12A02 >> 8) + ((_scriptHandler->_word12A02 & 0xFF) << 8) + (_scriptHandler->_word12A00 << 2);
+	int index1 = (_scriptHandler->_viewportY >> 8) + ((_scriptHandler->_viewportY & 0xFF) << 8) + (_scriptHandler->_viewportX << 2);
 	byte *map = &_bufferIsoMap[index1];
 
 	for (int i = 0; i < 8; i++) {
@@ -720,7 +720,7 @@ void LilliputEngine::displayFunction15() {
 					var1 += _scriptHandler->_byte12A04;
 				displayFunction13(_buffer1_45k, var1, tmpVal, 1 << 8);
 			}
-			sub16553(map, j, i);
+			renderCharacters(map, j, i);
 
 			if (map[2] != 0xFF) {
 				int var1 = map[2];
@@ -747,7 +747,7 @@ void LilliputEngine::displayFunction16() {
 		sub171CF();
 		displayCharactersOnMap();
 	} else {
-		sub1638C();
+		scrollToViewportCharacterTarget();
 		sub189DE();
 		displayFunction15();
 		displayFunction14();
@@ -974,19 +974,19 @@ void LilliputEngine::sortCharacters() {
 			int index1 = _charactersToDisplay[var2];
 			int index2 = _charactersToDisplay[var2 + 1];
 
-			if (_array1619B[index1] < _array1619B[index2])
+			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2])
 				continue;
 
-			if (_array1619B[index1] == _array1619B[index2]) {
-				if (_array16173[index1] < _array16173[index2])
+			if (_characterRelativePositionY[index1] == _characterRelativePositionY[index2]) {
+				if (_characterRelativePositionX[index1] < _characterRelativePositionX[index2])
 					continue;
 
-				if (_array16173[index1] == _array16173[index2]) {
+				if (_characterRelativePositionX[index1] == _characterRelativePositionX[index2]) {
 					if (_rulesBuffer2_3[index1] < _rulesBuffer2_3[index2])
 						continue;
 
 					if (_rulesBuffer2_3[index1] == _rulesBuffer2_3[index2]) {
-						if (_array161EB[index1] < _array161EB[index2])
+						if (_characterDisplayY[index1] < _characterDisplayY[index2])
 							continue;
 					}
 				}
@@ -1004,15 +1004,15 @@ void LilliputEngine::sortCharacters() {
 }
 
 // Move view port to x/y
-void LilliputEngine::sub1638C() {
+void LilliputEngine::scrollToViewportCharacterTarget() {
 	debugC(2, kDebugEngine, "sub1638C()");
 
-	if (_scriptHandler->_word10802 == 0xFFFF)
+	if (_scriptHandler->_viewportCharacterTarget == 0xFFFF)
 		return;
 
-	int var2 = (_rulesBuffer2_1[_scriptHandler->_word10802] >> 3) - _scriptHandler->_word12A00;
-	int var4 = (_rulesBuffer2_2[_scriptHandler->_word10802] >> 3) - _scriptHandler->_word12A02;
-	int var1 = _scriptHandler->_word12A00;
+	int var2 = (_characterPositionX[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportX;
+	int var4 = (_characterPositionY[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportY;
+	int var1 = _scriptHandler->_viewportX;
 
 	if (var2 >= 1) {
 		if (var2 >= 6) {
@@ -1026,7 +1026,7 @@ void LilliputEngine::sub1638C() {
 			var1 = 0;
 	}
 
-	int var3 = _scriptHandler->_word12A02;
+	int var3 = _scriptHandler->_viewportY;
 	if (var4 >= 1) {
 		if (var4 > 6) {
 			var3 += 4;
@@ -1039,56 +1039,56 @@ void LilliputEngine::sub1638C() {
 			var3 = 0;
 	}
 
-	sub163F0(var1, var3);
+	viewportScrollTo(var1, var3);
 }
 
-void LilliputEngine::sub163F0(int var1, int var3) {
-	debugC(2, kDebugEngine, "sub163F0(%d, %d)", var1, var3);
+void LilliputEngine::viewportScrollTo(int goalX, int goalY) {
+	debugC(2, kDebugEngine, "sub163F0(%d, %d)", goalX, goalY);
 
-	if ((var1 == _scriptHandler->_word12A00) && (var3 == _scriptHandler->_word12A02))
+	if ((goalX == _scriptHandler->_viewportX) && (goalY == _scriptHandler->_viewportY))
 		return;
 
-	int var2 = 0;
-	if (var1 != _scriptHandler->_word12A00) {
-		if (var1 < _scriptHandler->_word12A00)
-			--var2;
+	int dx = 0;
+	if (goalX != _scriptHandler->_viewportX) {
+		if (goalX < _scriptHandler->_viewportX)
+			--dx;
 		else
-			++var2;
+			++dx;
 	}
 
-	int var4 = 0;
-	if (var3!= _scriptHandler->_word12A02) {
-		if (var3 < _scriptHandler->_word12A02)
-			--var4;
+	int dy = 0;
+	if (goalY!= _scriptHandler->_viewportY) {
+		if (goalY < _scriptHandler->_viewportY)
+			--dy;
 		else
-			++var4;
+			++dy;
 	}
 
 	do {
-		_scriptHandler->_word12A00 += var2;
-		_scriptHandler->_word12A02 += var4;
+		_scriptHandler->_viewportX += dx;
+		_scriptHandler->_viewportY += dy;
 
 		displayFunction9();
 		displayFunction15();
 		displayFunction14();
 
-		if (var1 == _scriptHandler->_word12A00)
-			var2 = 0;
+		if (goalX == _scriptHandler->_viewportX)
+			dx = 0;
 
-		if (var3 == _scriptHandler->_word12A02)
-			var4 = 0;
-	} while ((var2 != 0) && (var4 !=0));
+		if (goalY == _scriptHandler->_viewportY)
+			dy = 0;
+	} while ((dx != 0) && (dy != 0));
 
 	_soundHandler->contentFct5();
 }
 
-void LilliputEngine::sub16553(byte *buf, int x, int y) {
+void LilliputEngine::renderCharacters(byte *buf, int x, int y) {
 	debugC(2, kDebugEngine, "sub16553()");
 
 	if ((_byte16529 != x) || (_byte1652A != y))
 		return;
 
-	_byte16552 = 0;
+	bool _byte16552 = 0;
 
 	if (buf[1] != 0xFF) {
 		int tmpIndex = buf[1];
@@ -1096,35 +1096,36 @@ void LilliputEngine::sub16553(byte *buf, int x, int y) {
 			++_byte16552;
 	}
 
-	int index = _charactersToDisplay[_word16550];
-	int var2 = (_array161C3[index] << 8) + _array161EB[index];
+	int index = _charactersToDisplay[_currentDisplayCharacter];
+	int displayX = _characterDisplayX[index];
+	int displayY = _characterDisplayY[index];
 
 	if (index == _scriptHandler->_word1881B)
-		warning("sub_1546F(%d)", var2);
+		warning("sub_1546F(%d,%d)", displayX, displayY);
 
 	if (_byte16552 != 1) {
 		int var3 = _rulesBuffer2_9[index];
-		int var1 = _rulesBuffer2_4[index];
+		int frame = _rulesBuffer2_4[index];
 
-		if (var1 != 0xFFFF) {
-			var1 += _scriptHandler->_array10AB1[index];
-			if (var3 != 1)
-				var1 += _rulesBuffer2_8[index];
+		if (frame != 0xFFFF) {
+			frame += _scriptHandler->_array10AB1[index];
+			if (var3 & 1)
+				frame += _rulesBuffer2_8[index];
 
 			if (_array12299[index] != 0xFF) {
-				var1 = _array12299[index] + 82;
+				frame = _array12299[index] + 82;
 				--_array12299[index];
-				var1 = -var1;
+				frame = -frame;
 			}
 
-			displayFunction18(var1, var2, var3);
+			displayFunction18(frame, displayX, displayY, var3);
 		}
 	}
 
-	++_word16550;
-	sub1652B(_word16550);
+	++_currentDisplayCharacter;
+	sub1652B(_currentDisplayCharacter);
 
-	sub16553(buf, x, y);
+	renderCharacters(buf, x, y);
 }
 
 void LilliputEngine::sub189DE() {
@@ -1402,8 +1403,8 @@ void LilliputEngine::sub131FC(int var2, int var4) {
 	y = y - diff;
 
 	if ((y >= 0) && (diff >= 0) && (y < 8) && (diff < 8)) {
-		y += _scriptHandler->_word12A00;
-		diff += _scriptHandler->_word12A02;
+		y += _scriptHandler->_viewportX;
+		diff += _scriptHandler->_viewportY;
 		_savedMousePosDivided = (y << 8) + diff;
 		_byte16F07_menuId = 5;
 	}
@@ -1415,7 +1416,7 @@ void LilliputEngine::sub131B2(int var2, int var4, bool &forceReturnFl) {
 	forceReturnFl = false;
 
 	for (int i = 0; i < _word10807_ERULES; i++) {
-		if ((var2 >= _array161C3[i]) && (var2 <= _array161C3[i] + 17) && (var4 >= _array161EB[i]) && (var4 <= _array161EB[i] + 17) && (i != _word10804)) {
+		if ((var2 >= _characterDisplayX[i]) && (var2 <= _characterDisplayX[i] + 17) && (var4 >= _characterDisplayY[i]) && (var4 <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_byte129A0 = i;
 			_byte16F07_menuId = 4;
 			if (_byte12FCE == 1)
@@ -1560,7 +1561,7 @@ void LilliputEngine::sub171CF() {
 	++_word1289D;
 
 	for (int i = 0; i < 10; i++) {
-		if ((_array12861[(3 * i) + 1] != 0xFFFF) && (_array12861[3 * i] = _word1289D)) {
+		if ((_array12861[(3 * i) + 1] != 0xFFFF) && (_array12861[3 * i] == _word1289D)) {
 			int var1 = _array12861[(3 * i) + 1];
 			int var4 = _array12861[(3 * i) + 2];
 			_array12861[(3 * i) + 1] = 0xFFFF;
@@ -1614,16 +1615,16 @@ void LilliputEngine::displayHeroismIndicator() {
 
 	_scriptHandler->_byte15FFA += var2;
 
-	int var4 = (_scriptHandler->_word15FFD >> 8) + ((_scriptHandler->_word15FFD & 0xFF) << 8);
-	int index = _scriptHandler->_word15FFB + var4 + (var4 >> 2);
+	int index = _scriptHandler->_word15FFB + _scriptHandler->_word15FFD * 320 ;
 
 	var2 = _scriptHandler->_byte15FFA & 0xFF;
 	if (var2 != 0) {
 //		sub16064(var1, _scriptHandler->_byte15FFA);
 		for (int i = 0; i < (var2 << 2); i++) {
-			((byte *)_mainSurface->getPixels())[index - (i * 320)] = var1; 
-			((byte *)_mainSurface->getPixels())[index - (i * 320) + 1] = var1; 
-			((byte *)_mainSurface->getPixels())[index - (i * 320) + 2] = var1; 
+			((byte *)_mainSurface->getPixels())[index] = var1;
+			((byte *)_mainSurface->getPixels())[index + 1] = var1;
+			((byte *)_mainSurface->getPixels())[index + 2] = var1;
+			index -= 320;
 		}
 	}
 
@@ -1631,9 +1632,10 @@ void LilliputEngine::displayHeroismIndicator() {
 //		sub16064(23, 25 - _scriptHandler->_byte15FFA);
 		var2 = (25 - _scriptHandler->_byte15FFA) << 2;
 		for (int i = 0; i < var2; i++) {
-			((byte *)_mainSurface->getPixels())[index - (i * 320)] = 23;
-			((byte *)_mainSurface->getPixels())[index - (i * 320) + 1] = 23;
-			((byte *)_mainSurface->getPixels())[index - (i * 320) + 2] = 23;
+			((byte *)_mainSurface->getPixels())[index] = 23;
+			((byte *)_mainSurface->getPixels())[index + 1] = 23;
+			((byte *)_mainSurface->getPixels())[index + 2] = 23;
+			index -= 320;
 		}
 	}
 
@@ -1779,12 +1781,12 @@ void LilliputEngine::loadRules() {
 		curWord = f.readUint16LE();
 		if (curWord != 0xFFFF)
 			curWord = (curWord << 3) + 4;
-		_rulesBuffer2_1[j] = curWord;
+		_characterPositionX[j] = curWord;
 
 		curWord = f.readUint16LE();
 		if (curWord != 0xFFFF)
 			curWord = (curWord << 3) + 4;
-		_rulesBuffer2_2[j] = curWord;
+		_characterPositionY[j] = curWord;
 
 		_rulesBuffer2_3[j] = (f.readUint16LE() & 0xFF);
 		_rulesBuffer2_4[j] = f.readUint16LE();
@@ -1956,8 +1958,8 @@ void LilliputEngine::sub170EE(int index) {
 	_rulesBuffer2PrevIndx = index;
 
 	assert (index < 40);
-	int var2 = _rulesBuffer2_1[index];
-	int var4 = _rulesBuffer2_2[index];
+	int var2 = _characterPositionX[index];
+	int var4 = _characterPositionY[index];
 
 	_word16EFA = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF);
 	_ptr_rulesBuffer2_15 = &_rulesBuffer2_15[_rulesBuffer2PrevIndx * 32];
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 5b6567f..f912e22 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -129,7 +129,7 @@ public:
 	int _word15BC8;
 	int _word15BCA;
 	int _word15AC2;
-	int _word16550;
+	int _currentDisplayCharacter;
 	int _displayStringIndex;
 	int _word1289D;
 	short _word15E5D[40];
@@ -141,8 +141,8 @@ public:
 
 	byte *_rulesChunk1;
 	int _rulesBuffer2PrevIndx;
-	int _rulesBuffer2_1[40];
-	int _rulesBuffer2_2[40];
+	int _characterPositionX[40];
+	int _characterPositionY[40];
 	byte _rulesBuffer2_3[40];
 	int _rulesBuffer2_4[40];
 	byte _rulesBuffer2_5[40];
@@ -186,10 +186,10 @@ public:
 	byte _array109C1[40];
 	byte _array15AC8[256];
 	byte _charactersToDisplay[40];
-	byte _array16173[40];
-	byte _array1619B[40];
-	byte _array161C3[40];
-	byte _array161EB[40];
+	byte _characterRelativePositionX[40];
+	byte _characterRelativePositionY[40];
+	byte _characterDisplayX[40];
+	byte _characterDisplayY[40];
 	byte _array12299[40];
 	byte _array109E9[40];
 	byte _array10A11[40];
@@ -224,17 +224,17 @@ public:
 	void displayFunction15();
 	void displayFunction16();
 	void displayFunction17();
-	void displayFunction18(int index, int var2, int flags);
+	void displayFunction18(int index, int x, int y, int flags);
 	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
 
 	void sortCharacters();
-	void sub1638C();
-	void sub163F0(int var1, int var3);
+	void scrollToViewportCharacterTarget();
+	void viewportScrollTo(int var1, int var3);
 	void sub189DE();
 	void sub16626();
 
-	void sub16553(byte *buf, int x, int y);
+	void renderCharacters(byte *buf, int x, int y);
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
 	void sub18A3E(byte param1);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 4de7063..364211e 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -39,12 +39,12 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 
 	_word1855E = 0;
 	_word16F00 = -1;
-	_word10802 = -1;
+	_viewportCharacterTarget = -1;
 	_word10804 = 0;
 	_word15FFB = 0;
 	_word15FFD = 0;
-	_word12A00 = 0;
-	_word12A02 = 0;
+	_viewportX = 0;
+	_viewportY = 0;
 	_word18776 = 0;
 
 	_savedBuffer215Ptr = NULL;
@@ -847,16 +847,16 @@ int LilliputScript::getValue2() {
 	case 0xFC: {
 		int index = curWord & 0xFF;
 		assert(index < 40);
-		byte var1 = _vm->_rulesBuffer2_1[index] >> 3;
-		byte var2 = _vm->_rulesBuffer2_2[index] >> 3;
+		byte var1 = _vm->_characterPositionX[index] >> 3;
+		byte var2 = _vm->_characterPositionY[index] >> 3;
 
 		return (var1 << 8) + var2;
 		}
 	case 0xFB: {
 		int index = _word16F00;
 		assert(index < 40);
-		byte var1 = _vm->_rulesBuffer2_1[index] >> 3;
-		byte var2 = _vm->_rulesBuffer2_2[index] >> 3;
+		byte var1 = _vm->_characterPositionX[index] >> 3;
+		byte var2 = _vm->_characterPositionY[index] >> 3;
 
 		return (var1 << 8) + var2;
 		}
@@ -872,8 +872,8 @@ int LilliputScript::getValue2() {
 	case 0xF7: {
 		int index = _vm->_rulesBuffer2_15[6];
 		assert(index < 40);
-		byte var1 = _vm->_rulesBuffer2_1[index] >> 3;
-		byte var2 = _vm->_rulesBuffer2_2[index] >> 3;
+		byte var1 = _vm->_characterPositionX[index] >> 3;
+		byte var2 = _vm->_characterPositionY[index] >> 3;
 
 		return (var1 << 8) + var2;
 		}
@@ -1144,7 +1144,7 @@ byte LilliputScript::OC_sub177C6() {
 	debugC(1, kDebugScript, "OC_sub177C6()");
 
 	int index = _currScript->readUint16LE();
-	if (_vm->_rulesBuffer2_1[index] == 0xFFFF)
+	if (_vm->_characterPositionX[index] == 0xFFFF)
 		return 0;
 
 	return 1;
@@ -1397,8 +1397,8 @@ void LilliputScript::OC_sub17A66() {
 	int var4 = ((tmpVal & 0xFF) << 3) + 4;
 
 	assert(index < 40);
-	_vm->_rulesBuffer2_1[index] = var2;
-	_vm->_rulesBuffer2_2[index] = var4;
+	_vm->_characterPositionX[index] = var2;
+	_vm->_characterPositionY[index] = var4;
 }
 
 void LilliputScript::OC_sub17A8D() {
@@ -1408,10 +1408,10 @@ void LilliputScript::OC_sub17A8D() {
 	assert(tmpVal < 40);
 
 	if (tmpVal == _word10804)
-		_word10802 = 0xFFFF;
+		_viewportCharacterTarget = 0xFFFF;
 
-	_vm->_rulesBuffer2_1[tmpVal] = 0xFFFF;
-	_vm->_rulesBuffer2_2[tmpVal] = 0xFFFF;
+	_vm->_characterPositionX[tmpVal] = 0xFFFF;
+	_vm->_characterPositionY[tmpVal] = 0xFFFF;
 }
 void LilliputScript::OC_saveAndQuit() {
 	warning("OC_saveAndQuit");
@@ -1882,7 +1882,7 @@ void LilliputScript::OC_sub18690() {
 void LilliputScript::OC_setWord10802() {
 	debugC(1, kDebugScript, "OC_setWord10802()");
 
-	_word10802 = getValue1();
+	_viewportCharacterTarget = getValue1();
 }
 
 void LilliputScript::OC_sub186A1() {
@@ -1898,8 +1898,8 @@ void LilliputScript::OC_sub186E5_snd() {
 	byte var4l = (index & 0xFF);
 	byte var3h = _array16123[index];
 	byte var3l = _array1614B[index];
-	byte var2h = (_word12A00 & 0xFF);
-	byte var2l = (_word12A02 & 0xFF);
+	byte var2h = (_viewportX & 0xFF);
+	byte var2l = (_viewportY & 0xFF);
 	int var1 = _currScript->readUint16LE();
 
 	_vm->_soundHandler->contentFct2();
@@ -1910,7 +1910,7 @@ void LilliputScript::OC_sub1870A_snd() {
 
 	int var3 = getValue2();
 	int var4 = var3;
-	int var2 = (_word12A00 << 8) + _word12A02;
+	int var2 = (_viewportX << 8) + _viewportY;
 	int var1 = (_currScript->readUint16LE() & 0xFF);
 
 	_vm->_soundHandler->contentFct2();
@@ -1942,7 +1942,7 @@ void LilliputScript::OC_sub18746_snd() {
 	debugC(1, kDebugScript, "OC_sub18746_snd()");
 
 	int var4 = -1;
-	int var2 = (_word12A00 << 8) + _word12A02;
+	int var2 = (_viewportX << 8) + _viewportY;
 	int var1 = _currScript->readUint16LE() & 0xFF;
 
 	_vm->_soundHandler->contentFct2();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index e29c676..2a23063 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -48,9 +48,9 @@ public:
 
 	byte *_savedBuffer215Ptr;
 
-	int _word12A00;
-	int _word12A02;
-	int _word10802;
+	int _viewportX;
+	int _viewportY;
+	int _viewportCharacterTarget;
 	int _word1881B;
 	int _word15FFB;
 	int _word15FFD;


Commit: 5b6014fb77823481f2d965fbe94e940bdbb193aa
    https://github.com/scummvm/scummvm/commit/5b6014fb77823481f2d965fbe94e940bdbb193aa
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement 4 more opcodes

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 0ccfdf7..6701c45 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -163,6 +163,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
 
+	for (int i = 0; i < 3; i++)
+		_array147D1[i] = 0;
+
 	for (int i = 0; i < 40; i++) {
 		_array10999[i] = 0;
 		_array109C1[i] = 0;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index f912e22..ac185b0 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -104,6 +104,7 @@ public:
 	byte _byte12FE4;
 	byte _byte12FE3;
 
+	byte _array147D1[3];
 	byte _buffer1[45056];
 	byte _buffer2[45056];
 	byte _buffer3[45056];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 364211e..f34ec12 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1201,8 +1201,14 @@ byte LilliputScript::OC_sub17825() {
 }
 
 byte LilliputScript::OC_sub17844() {
-	warning("OC_sub17844");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub17844()");
+
+	int tmpVal = _currScript->readUint16LE();
+
+	if ((_vm->_byte16F07_menuId == 2) || ((tmpVal & 0xFF) != _byte12FE4))
+		return 0;
+
+	return 1;
 }
 
 byte LilliputScript::OC_sub1785C() {
@@ -1303,14 +1309,25 @@ byte LilliputScript::OC_sub17984() {
 
 	return 0;
 }
+
 byte LilliputScript::OC_checkSavedMousePos() {
-	warning("OC_checkSavedMousePos");
-	return 0;
+	debugC(1, kDebugScript, "OC_checkSavedMousePos()");
+
+	if ((_byte129A0 != 0xFF) || (_vm->_savedMousePosDivided == 0xFFFF))
+		return 0;
+
+	return 1;
 }
+
 byte LilliputScript::OC_sub179AE() {
-	warning("OC_sub179AE");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub179AE()");
+
+	if ((_vm->_byte12FCE == 1) || (_byte129A0 == 0xFF))
+		return 0;
+
+	return 1;
 }
+
 byte LilliputScript::OC_sub179C2() {
 	warning("OC_sub179C2");
 	return 0;
@@ -1319,10 +1336,29 @@ byte LilliputScript::OC_sub179E5() {
 	warning("OC_sub179E5");
 	return 0;
 }
+
 byte LilliputScript::OC_sub17A07() {
-	warning("OC_sub17A07");
+	debugC(1, kDebugScript, "OC_sub17A07()");
+
+	static const byte _array179FD[10] = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+
+	if (_vm->_byte16F07_menuId == 6) {
+		int index = _currScript->readUint16LE();
+		if (_array179FD[index] == _vm->_array147D1[0]) {
+			index = _currScript->readUint16LE();
+			if (_array179FD[index] == _vm->_array147D1[1]) {
+				index = _currScript->readUint16LE();
+				if (_array179FD[index] == _vm->_array147D1[2]) {
+					return 1;
+				}
+			}
+		}
+	}
+	
+	_currScript->seek(_currScript->pos() + 6);
 	return 0;
 }
+
 byte LilliputScript::OC_sub17757() {
 	warning("OC_sub17757");
 	return 0;


Commit: 5ede42cd6a9987faf2583bfe91fb11e1c563f4de
    https://github.com/scummvm/scummvm/commit/5ede42cd6a9987faf2583bfe91fb11e1c563f4de
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming, implement a couple of functions

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6701c45..6953ea3 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -133,8 +133,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12FCE = 0;
 	_byte129A0 = 0xFF;
 	_numCharactersToDisplay = 0;
-	_byte16529 = 0;
-	_byte1652A = 0;
+	_nextDisplayCharacterX = 0;
+	_nextDisplayCharacterY = 0;
 	_byte12A04 = 0;
 	_byte12A05 = 10;
 	_byte12A06 = 2;
@@ -227,7 +227,6 @@ GUI::Debugger *LilliputEngine::getDebugger() {
 }
 
 void LilliputEngine::update() {
-
 	// update every 20 ms.
 	int currentTime = _system->getMillis();
 	if(currentTime - _lastTime > 20) {
@@ -336,41 +335,12 @@ void LilliputEngine::displayFunction1(byte *buf, int var1, int var2, int var4) {
 	int index2 = var2 + tmpVal + (tmpVal >> 2);
 
 	for (int i = 0; i < 16; i++) {
-		if (newBuf[0] != 0)
-			((byte *)_mainSurface->getPixels())[index2] = newBuf[0];
-		if (newBuf[1] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 1] = newBuf[1];
-		if (newBuf[2] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 2] = newBuf[2];
-		if (newBuf[3] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 3] = newBuf[3];
-		if (newBuf[4] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 4] = newBuf[4];
-		if (newBuf[5] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 5] = newBuf[5];
-		if (newBuf[6] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 6] = newBuf[6];
-		if (newBuf[7] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 7] = newBuf[7];
-		if (newBuf[8] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 8] = newBuf[8];
-		if (newBuf[9] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 9] = newBuf[9];
-		if (newBuf[10] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 10] = newBuf[10];
-		if (newBuf[11] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 11] = newBuf[11];
-		if (newBuf[12] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 12] = newBuf[12];
-		if (newBuf[13] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 13] = newBuf[13];
-		if (newBuf[14] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 14] = newBuf[14];
-		if (newBuf[15] != 0)
-			((byte *)_mainSurface->getPixels())[index2 + 15] = newBuf[15];
-
+		for (int j = 0; j < 16; j++) {
+			if (newBuf[j] != 0)
+				((byte *)_mainSurface->getPixels())[index2 + j] = newBuf[j];
+		}
 		index2 += 320;
-		newBuf = &newBuf[16];
+		newBuf += 16;
 	}
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
@@ -689,16 +659,17 @@ void LilliputEngine::sub16217() {
 	sortCharacters();
 }
 
-void LilliputEngine::sub1652B(int var1) {
-	debugC(2, kDebugEngine, "sub1652B(%d)", var1);
+void LilliputEngine::setNextDisplayCharacter(int var1) {
+	debugC(2, kDebugEngine, "setNextDisplayCharacter(%d)", var1);
 
-	if ( (var1 & 0xFF) < _numCharactersToDisplay) {
-		int index = _charactersToDisplay[var1 & 0xFF];
-		_byte16529 = _characterRelativePositionX[index];
-		_byte1652A = _characterRelativePositionY[index];
+	byte charNum = var1 & 0xFF;
+	if ( charNum < _numCharactersToDisplay) {
+		int index = _charactersToDisplay[charNum];
+		_nextDisplayCharacterX = _characterRelativePositionX[index];
+		_nextDisplayCharacterY = _characterRelativePositionY[index];
 	} else {
-		_byte16529 = 0xFF;
-		_byte1652A = 0xFF;
+		_nextDisplayCharacterX = 0xFF;
+		_nextDisplayCharacterY = 0xFF;
 	}
 }
 
@@ -707,7 +678,7 @@ void LilliputEngine::displayFunction15() {
 
 	sub16217();
 	_currentDisplayCharacter = 0;
-	sub1652B(0);
+	setNextDisplayCharacter(0);
 
 	memcpy(_buffer1_45k, _buffer2_45k, 45056);
 
@@ -964,7 +935,7 @@ void LilliputEngine::displayChar(int index, int var1) {
 }
 
 void LilliputEngine::sortCharacters() {
-	debugC(2, kDebugEngine, "sub16323()");
+	debugC(2, kDebugEngine, "sortCharacters()");
 
 	if (_numCharactersToDisplay <= 1)
 		return;
@@ -1008,7 +979,7 @@ void LilliputEngine::sortCharacters() {
 
 // Move view port to x/y
 void LilliputEngine::scrollToViewportCharacterTarget() {
-	debugC(2, kDebugEngine, "sub1638C()");
+	debugC(2, kDebugEngine, "scrollToViewportCharacterTarget()");
 
 	if (_scriptHandler->_viewportCharacterTarget == 0xFFFF)
 		return;
@@ -1046,7 +1017,7 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 }
 
 void LilliputEngine::viewportScrollTo(int goalX, int goalY) {
-	debugC(2, kDebugEngine, "sub163F0(%d, %d)", goalX, goalY);
+	debugC(2, kDebugEngine, "viewportScrollTo(%d, %d)", goalX, goalY);
 
 	if ((goalX == _scriptHandler->_viewportX) && (goalY == _scriptHandler->_viewportY))
 		return;
@@ -1086,9 +1057,9 @@ void LilliputEngine::viewportScrollTo(int goalX, int goalY) {
 }
 
 void LilliputEngine::renderCharacters(byte *buf, int x, int y) {
-	debugC(2, kDebugEngine, "sub16553()");
+	debugC(2, kDebugEngine, "renderCharacters(buf, %d, %d)", x, y);
 
-	if ((_byte16529 != x) || (_byte1652A != y))
+	if ((_nextDisplayCharacterX != x) || (_nextDisplayCharacterY != y))
 		return;
 
 	bool _byte16552 = 0;
@@ -1104,7 +1075,7 @@ void LilliputEngine::renderCharacters(byte *buf, int x, int y) {
 	int displayY = _characterDisplayY[index];
 
 	if (index == _scriptHandler->_word1881B)
-		warning("sub_1546F(%d,%d)", displayX, displayY);
+		sub1546F(displayX, displayY);
 
 	if (_byte16552 != 1) {
 		int var3 = _rulesBuffer2_9[index];
@@ -1126,11 +1097,46 @@ void LilliputEngine::renderCharacters(byte *buf, int x, int y) {
 	}
 
 	++_currentDisplayCharacter;
-	sub1652B(_currentDisplayCharacter);
+	setNextDisplayCharacter(_currentDisplayCharacter);
 
 	renderCharacters(buf, x, y);
 }
 
+void LilliputEngine::sub1546F(byte displayX, byte displayY) {
+	debugC(2, kDebugEngine, "sub1546F(%d, %d)", displayX, displayY);
+	
+	int orgX = displayX + 8;
+	int orgY = displayY;
+	int var2 = 0;
+	
+	int x = orgX;
+	int y = orgY;
+	do {
+		sub15498(x, y, var2);
+		--x;
+		y >>= 1;
+	} while (y != 0);
+	
+	x = orgX + 1;
+	y = orgY >> 1;
+	
+	while (y != 0) {
+		sub15498(x, y, var2);
+		++x;
+		y >>= 1;
+	}
+}
+
+void LilliputEngine::sub15498(byte x, byte y, int var2) {
+	debugC(2, kDebugEngine, "sub15498(%d, %d, %d)", x, y, var2);
+	
+	int index = x + ((var2 & 0xFF) << 8) + (var2 >> 8);
+	for (int i = 1 + y - var2; i > 0; i--) {
+		_buffer1_45k[index] = 17;
+		index += 256;
+	}
+}
+
 void LilliputEngine::sub189DE() {
 	debugC(2, kDebugEngine, "sub189DE()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index ac185b0..1f355a4 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -87,8 +87,8 @@ public:
 	struct18560 _arr18560[4];
 	byte _byte1714E;
 	byte _byte184F4;
-	byte _byte16529;
-	byte _byte1652A;
+	byte _nextDisplayCharacterX;
+	byte _nextDisplayCharacterY;
 	byte _sound_byte16F06;
 	byte _byte16F09;
 	byte _keyboard_nextIndex;
@@ -258,6 +258,8 @@ public:
 	int sub13240(int posX, int posY, int var3, int var4);
 	void sub131B2(int var2, int var4, bool &forceReturnFl);
 	void sub131FC(int var2, int var4);
+	void sub1546F(byte displayX, byte displayY);
+	void sub15498(byte x, byte y, int var2);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
@@ -301,7 +303,7 @@ public:
 	void sub170EE(int index);
 	void sub130DD();
 	void sub16217();
-	void sub1652B(int var1);
+	void setNextDisplayCharacter(int var1);
 	void handleGameScripts();
 
 	// Temporary stubs


Commit: 0be54f0b1b7ade28763ca93f59d30a22801cf946
    https://github.com/scummvm/scummvm/commit/0be54f0b1b7ade28763ca93f59d30a22801cf946
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Maybe fix a problem in sub12F37

Unlocked new opcodes !

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6953ea3..7c7f9a8 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1346,12 +1346,15 @@ void LilliputEngine::sub12F37() {
 	int index2 = 0;
 
 	for (int i = 0; i < _word10807_ERULES; i++) {
-		if (_rulesBuffer2_15[index1] == 1 ) {
-			--_rulesBuffer2_15[index1];
-			if (_rulesBuffer2_15[index1] == 1)
-				_scriptHandler->_array10B29[index2] = 1;
-		} else
-			_rulesBuffer2_15[index1] = 0;
+		if (_rulesBuffer2_15[index1] != 0 ) {
+			if (_rulesBuffer2_15[index1] == 1) {
+				_rulesBuffer2_15[index1] = 0;
+			} else {
+				--_rulesBuffer2_15[index1];
+				if (_rulesBuffer2_15[index1] == 1)
+					_scriptHandler->_array10B29[index2] = 1;
+			}			
+		}
 
 		index1 += 32;
 		++index2;
@@ -1610,23 +1613,23 @@ void LilliputEngine::displayHeroismIndicator() {
 
 	int var1 = (_scriptHandler->_savedBuffer215Ptr[0] * 25) >> 8;
 
-	if (var1 == _scriptHandler->_byte15FFA)
+	if (var1 == _scriptHandler->_heroismLevel)
 		return;
 
 	displayFunction5();
 	int var2 = 1;
-	if (var1 > _scriptHandler->_byte15FFA)
+	if (var1 > _scriptHandler->_heroismLevel)
 		var1 = 150;
 	else {
 		var2 = -1;
 		var1 = 40;
 	}
 
-	_scriptHandler->_byte15FFA += var2;
-
-	int index = _scriptHandler->_word15FFB + _scriptHandler->_word15FFD * 320 ;
+	_scriptHandler->_heroismLevel += var2;
+	
+	int index = _scriptHandler->_heroismBarX + _scriptHandler->_heroismBarBottomY * 320 ;
 
-	var2 = _scriptHandler->_byte15FFA & 0xFF;
+	var2 = _scriptHandler->_heroismLevel & 0xFF;
 	if (var2 != 0) {
 //		sub16064(var1, _scriptHandler->_byte15FFA);
 		for (int i = 0; i < (var2 << 2); i++) {
@@ -1637,9 +1640,9 @@ void LilliputEngine::displayHeroismIndicator() {
 		}
 	}
 
-	if (25 - _scriptHandler->_byte15FFA != 0) {
+	if (25 - _scriptHandler->_heroismLevel != 0) {
 //		sub16064(23, 25 - _scriptHandler->_byte15FFA);
-		var2 = (25 - _scriptHandler->_byte15FFA) << 2;
+		var2 = (25 - _scriptHandler->_heroismLevel) << 2;
 		for (int i = 0; i < var2; i++) {
 			((byte *)_mainSurface->getPixels())[index] = 23;
 			((byte *)_mainSurface->getPixels())[index + 1] = 23;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f34ec12..7400241 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -41,8 +41,8 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_word16F00 = -1;
 	_viewportCharacterTarget = -1;
 	_word10804 = 0;
-	_word15FFB = 0;
-	_word15FFD = 0;
+	_heroismBarX = 0;
+	_heroismBarBottomY = 0;
 	_viewportX = 0;
 	_viewportY = 0;
 	_word18776 = 0;
@@ -63,6 +63,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array16123[i] = 0;
 		_array1614B[i] = 0;
 		_array16173[i] = 0xFF;
+		_array122C1[i] = 0;
 	}
 
 	for (int i = 0; i < 640; i++) {
@@ -1571,7 +1572,11 @@ void LilliputScript::OC_resetWord16EFE() {
 	warning("OC_resetWord16EFE");
 }
 void LilliputScript::OC_sub17CEF() {
-	warning("OC_sub17CEF");
+	debugC(1, kDebugScript, "OC_sub17CEF()");
+
+	int var1 = _currScript->readUint16LE();
+	sub1823E(_vm->_rulesBuffer2PrevIndx , var1, _vm->_ptr_rulesBuffer2_15);
+	sub17B6C(0);
 }
 
 void LilliputScript::OC_sub17D1B() {
@@ -1751,7 +1756,10 @@ void LilliputScript::OC_sub1834C() {
 }
 
 void LilliputScript::OC_sub18359() {
-	warning("OC_sub18359");
+	debugC(1, kDebugScript, "OC_sub18359()");
+
+	int var1 = _currScript->readUint16LE();
+	_array122C1[_vm->_rulesBuffer2PrevIndx] = var1;
 }
 void LilliputScript::OC_sub18367() {
 	warning("OC_sub18367");
@@ -1876,7 +1884,7 @@ void LilliputScript::OC_sub1853B() {
 
 	OC_PaletteFadeOut();
 	displayMap = 0;
-	_byte15FFA = 0;
+	_heroismLevel = 0;
 	sub130B6();
 
 	_vm->displayFunction12();
@@ -1907,8 +1915,8 @@ void LilliputScript::OC_initArr18560() {
 void LilliputScript::OC_sub18678() {
 	debugC(1, kDebugScript, "OC_initArr18578()");
 	_savedBuffer215Ptr = getBuffer215Ptr();
-	_word15FFB = _currScript->readUint16LE();
-	_word15FFD = _currScript->readUint16LE();
+	_heroismBarX = _currScript->readUint16LE();
+	_heroismBarBottomY = _currScript->readUint16LE();
 }
 
 void LilliputScript::OC_sub18690() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 2a23063..3d5e781 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -34,7 +34,7 @@ class LilliputScript {
 public:
 	byte displayMap;
 	byte _byte12A04;
-	byte _byte15FFA;
+	byte _heroismLevel;
 
 	byte _array10B29[40];
 	byte _array122E9[20];
@@ -44,6 +44,7 @@ public:
 	byte _array12811[40];
 	byte _array10AB1[40];
 	byte _array122FD[20];
+	byte _array122C1[40];
 	short _array10B51[40 * 40];
 
 	byte *_savedBuffer215Ptr;
@@ -52,8 +53,8 @@ public:
 	int _viewportY;
 	int _viewportCharacterTarget;
 	int _word1881B;
-	int _word15FFB;
-	int _word15FFD;
+	int _heroismBarX;
+	int _heroismBarBottomY;
 
 	short _array12311[640];
 	byte _array128EF[40];


Commit: 5caad723c50843b3c5926a07f7b72f22c0268bed
    https://github.com/scummvm/scummvm/commit/5caad723c50843b3c5926a07f7b72f22c0268bed
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement 4 more opcodes

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7400241..1be99b6 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1001,10 +1001,23 @@ byte LilliputScript::OC_sub1750E() {
 	warning("OC_sub1750E");
 	return 0;
 }
+
 byte LilliputScript::OC_compareCoords_1() {
-	warning("compareCoords_1");
-	return 0;
+	debugC(1, kDebugScript, "OC_compareCoords_1()");
+
+	int index = _currScript->readUint16LE();
+	assert(index < 40);
+
+	int var3 = _vm->_rulesBuffer12_1[index];
+	int var4 = _vm->_rulesBuffer12_2[index];
+	int var1 = _vm->_word16EFA;
+
+	if (((var1 >> 8) < (var3 >> 8)) || ((var1 >> 8) > (var3 & 0xFF)) || ((var1 & 0xFF) < (var3 >> 8)) || ((var1 & 0xFF) > (var3 & 0xFF)))
+		return 0;
+
+	return 1;
 }
+
 byte LilliputScript::OC_compareCoords_2() {
 	warning("compareCoords_2");
 	return 0;
@@ -1257,13 +1270,29 @@ byte LilliputScript::OC_sub178E8() {
 	warning("OC_sub178E8");
 	return 0;
 }
+
 byte LilliputScript::OC_sub178FC() {
-	warning("OC_sub178FC");
+	debugC(1, kDebugScript, "OC_sub178FC()");
+
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	byte curByte = (_currScript->readUint16LE() & 0xFF);
+
+	if (curByte <= _vm->_ptr_rulesBuffer2_15[0])
+		return 1;
 	return 0;
 }
+
 byte LilliputScript::OC_sub1790F() {
-	warning("OC_sub1790F");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub1790F()");
+
+	int index = getValue1();
+	assert(index < 40);
+	if (_vm->_rulesBuffer2_5[index] == 0xFF)
+		return 0;
+
+	_word16F00 = _vm->_rulesBuffer2_5[index];
+
+	return 1;
 }
 
 byte LilliputScript::OC_sub1792A() {
@@ -1279,8 +1308,15 @@ byte LilliputScript::OC_sub1792A() {
 }
 
 byte LilliputScript::OC_sub1793E() {
-	warning("OC_sub1793E");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub1793E()");
+
+	if (_vm->_word16EFA == 0xFFFF)
+		return 0;
+
+	if (_vm->_array16E94[_vm->_rulesBuffer2PrevIndx] == 0)
+		return 0;
+
+	return 1;
 }
 
 byte LilliputScript::OC_sub1795E() {


Commit: 576f0217e0864699541d25f553ad4eb25106fac6
    https://github.com/scummvm/scummvm/commit/576f0217e0864699541d25f553ad4eb25106fac6
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implements Load Map opcode

Loads graphics, fade out/in, display points

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7c7f9a8..b1c7c4f 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -145,6 +145,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte16552 = 0;
 	_byte12FE4 = 0xFF;
 	_byte12FE3 = 0;
+	_byte16F08 = 0;	
 
 	_rulesBuffer2PrevIndx = 0;
 	_word16EFA = 0;
@@ -157,6 +158,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word15AC2 = 0;
 	_word16213 = 0;
 	_word16215 = 0;
+	_word15AC2 = 0;
 	_displayStringIndex = 0;
 	_word1289D = 0;
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 1f355a4..14bd9ad 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -103,6 +103,8 @@ public:
 	byte _byte16552;
 	byte _byte12FE4;
 	byte _byte12FE3;
+	byte _byte16F08;
+	byte _byte15EAD;
 
 	byte _array147D1[3];
 	byte _buffer1[45056];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 1be99b6..adb0c25 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1826,8 +1826,26 @@ void LilliputScript::OC_sub183C6() {
 	warning("OC_sub183C6");
 }
 void LilliputScript::OC_loadFile_AERIAL_GFX() {
-	warning("OC_loadFile_AERIAL_GFX");
+	debugC(1, kDebugScript, "OC_loadFile_AERIAL_GFX()");
+	
+	int var1 = _currScript->readUint16LE() & 0xff;
+	_vm->_byte15EAD = var1;
+
+	_byte12A09 = 1;
+	_word1881B = 0xFFFF;
+	OC_PaletteFadeOut();
+	_vm->_word15AC2 = 1;
+	_vm->displayVGAFile("AERIAL.GFX");
+	OC_PaletteFadeIn();
+
+	_vm->displayCharactersOnMap();
+	_vm->_byte16F08 = 1;
+	_vm->_keyboard_oldIndex = 0;
+	_vm->_keyboard_nextIndex = 0;
+
+	_vm->_byte12A09 = 0;
 }
+
 void LilliputScript::OC_sub17E22() {
 	warning("OC_sub17E22");
 }


Commit: 2947d7e469ae6955c308be71857a8acbabab5655
    https://github.com/scummvm/scummvm/commit/2947d7e469ae6955c308be71857a8acbabab5655
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More opcodes

OC_sub18213, OC_sub181BB, OC_sub1817F

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index adb0c25..3716338 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -47,6 +47,8 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_viewportY = 0;
 	_word18776 = 0;
 
+
+
 	_savedBuffer215Ptr = NULL;
 
 	for (int i = 0; i < 20; i++) {
@@ -64,6 +66,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array1614B[i] = 0;
 		_array16173[i] = 0xFF;
 		_array122C1[i] = 0;
+		_array1813B[i] = 0;
 	}
 
 	for (int i = 0; i < 640; i++) {
@@ -702,7 +705,7 @@ void LilliputScript::sub1823E(byte var1, byte var2, byte *curBufPtr) {
 	debugC(1, kDebugScript, "sub1823E(%d, %d, curBufPtr)", var1, var2);
 
 	assert ((var1 >= 0) && (var1 < 40));
-	_array10B29[var1] = 0;
+	_array10B29[var1] = 1;
 	curBufPtr[0] = var2;
 	curBufPtr[1] = 0;
 	curBufPtr[2] = 0;
@@ -1724,13 +1727,75 @@ void LilliputScript::OC_sub1812D() {
 }
 
 void LilliputScript::OC_sub1817F() {
-	warning("OC_sub1817F");
+	debugC(1, kDebugScript, "OC_sub1817F()");
+
+	int var1 = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+	
+	int b1 = var1 & 0xFF;
+	int b2 = var2 & 0xFF;
+	OC_sub1817F_loop(b1,b2);
+}
+
+void LilliputScript::OC_sub1817F_loop( int b1, int b2 ) {
+	for (int i = 0; i <  _vm->_word1817B; i++) {
+		if ((_array1813B[i] >> 8) == b2 ) {
+			b2 += _array1813B[i] & 0xFF;
+			if (b2 < 0) {
+				b2 = 0xFF;
+			}
+			_array1813B[i] = (_array1813B[i] & 0xFF00) + b2;
+			return;
+		}
+	}
+
+	_array1813B[_vm->_word1817B++] = (b1 << 8) + b2;
 }
+
 void LilliputScript::OC_sub181BB() {
-	warning("OC_sub181BB");
+	debugC(1, kDebugScript, "OC_sub1817F()");
+	
+	int b = _currScript->readUint16LE();
+	int d = _currScript->readUint16LE() & 0xFF;
+	int s = _currScript->readUint16LE();
+	int c = _vm->_ptr_rulesBuffer2_15[s];
+	int c2 = 0;
+
+	if ( d == 0x2D ) {
+		c = - 1 - c;
+	} else if ( d == 0x3E ) {
+		c = c - 0x80;
+		if ( c < 0 ) 
+			c = 0;
+		c = c * 2;
+	} else if ( d == 0x3C ) {
+		c = -1 - c;
+		c = c - 0x80;
+		if ( c < 0 )
+			c = 0;
+		c = c * 2;
+	}
+
+	int a = _currScript->readUint16LE() * c + (c & 0xFF);
+	b = b & 0xFF00 + a;
+	OC_sub1817F_loop(b & 0xFF, b >> 8);
+
 }
 void LilliputScript::OC_sub18213() {
-	warning("OC_sub18213");
+	debugC(1, kDebugScript, "OC_sub18213()");
+
+	int var1 = _currScript->readUint16LE();
+
+	int maxValue = 0;
+	int maxItem = var1 & 0xFF;
+
+	for (int i = 0; i < _vm->_word1817B; i++) {
+		if ( _array1813B[i] & 0xFF > maxValue ) {
+			maxValue = _array1813B[i] & 0xFF;
+			maxItem = _array1813B[i] >> 8;
+		}
+	}
+	sub1823E(_vm->_rulesBuffer2PrevIndx, maxItem, &_vm->_rulesBuffer2_15[var1]);
 }
 void LilliputScript::OC_sub18252() {
 	warning("OC_sub18252");
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 3d5e781..23ff23e 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -57,6 +57,7 @@ public:
 	int _heroismBarBottomY;
 
 	short _array12311[640];
+	short _array1813B[40];
 	byte _array128EF[40];
 	byte _array12839[40];
 
@@ -225,6 +226,7 @@ private:
 	void OC_sub1810A();
 	void OC_sub1812D();
 	void OC_sub1817F();
+	void OC_sub1817F_loop( int b1, int b2 );
 	void OC_sub181BB();
 	void OC_sub18213();
 	void OC_sub18252();


Commit: 413f42c28389e038d411ccc1c86b02dc73f49f10
    https://github.com/scummvm/scummvm/commit/413f42c28389e038d411ccc1c86b02dc73f49f10
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a bug in OC_compareCoords_1, implement 2 more opcodes

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 3716338..4c90c34 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -56,6 +56,9 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array122FD[i] = 0;
 	}
 
+	for (int i = 0; i < 32; i++)
+		_array1813B[i] = 0;
+
 	for (int i = 0; i < 40; i++) {
 		_array10B29[i] = 1;
 		_array128EF[i] = 15;
@@ -1015,7 +1018,7 @@ byte LilliputScript::OC_compareCoords_1() {
 	int var4 = _vm->_rulesBuffer12_2[index];
 	int var1 = _vm->_word16EFA;
 
-	if (((var1 >> 8) < (var3 >> 8)) || ((var1 >> 8) > (var3 & 0xFF)) || ((var1 & 0xFF) < (var3 >> 8)) || ((var1 & 0xFF) > (var3 & 0xFF)))
+	if (((var1 >> 8) < (var3 >> 8)) || ((var1 >> 8) > (var3 & 0xFF)) || ((var1 & 0xFF) < (var4 >> 8)) || ((var1 & 0xFF) > (var4 & 0xFF)))
 		return 0;
 
 	return 1;
@@ -1087,8 +1090,54 @@ byte LilliputScript::OC_sub175C8() {
 	return 0;
 }
 byte LilliputScript::OC_sub17640() {
-	warning("OC_sub17640");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub176C4()");
+
+	int var4 = _currScript->readUint16LE();
+	int index = _vm->_rulesBuffer2PrevIndx * 40;
+	int subIndex = 0xFFFF;
+
+	int tmpVal = _currScript->readUint16LE();
+
+	if (tmpVal >= 2000) {
+		int var1 = tmpVal;
+
+		if (var1 == 3000) {
+			subIndex = 0;
+			for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+				tmpVal = _array10B51[index + i];
+				byte v1 = tmpVal & 0xFF;
+				byte v2 = tmpVal >> 8;
+				if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF))) {
+					_word16F00 = subIndex;
+					return 1;
+				}
+			}
+			return 0;
+		} else {
+			var1 -= 2000;
+			var4 &= ((var1 & 0xFF) << 8);
+			for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+				tmpVal = _array10B51[index + i];
+				byte v1 = tmpVal & 0xFF;
+				byte v2 = tmpVal >> 8;
+				if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF)) && (_vm->_rulesBuffer2_12[subIndex] != (var4 >> 8))) {
+					_word16F00 = subIndex;
+					return 1;
+				}
+			}
+			return 0;
+		}
+	} else {
+		_currScript->seek(_currScript->pos() - 2);
+		subIndex = getValue1();
+		tmpVal = _array10B51[index + subIndex];
+		byte v1 = tmpVal & 0xFF;
+		byte v2 = tmpVal >> 8;
+		if ((v1 < (var4 & 0xFF)) || (v2 >= (var4 & 0xFF)))
+			return 0;
+		_word16F00 = subIndex;
+		return 1;
+	}
 }
 
 byte LilliputScript::OC_sub176C4() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 23ff23e..d631d48 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -57,9 +57,9 @@ public:
 	int _heroismBarBottomY;
 
 	short _array12311[640];
-	short _array1813B[40];
 	byte _array128EF[40];
 	byte _array12839[40];
+	int _array1813B[32];
 
 	void sub130B6();
 


Commit: 2c17500d01de0b70d7455e4e9df5ddd0ac4fd7de
    https://github.com/scummvm/scummvm/commit/2c17500d01de0b70d7455e4e9df5ddd0ac4fd7de
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement two opcodes

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 4c90c34..46b573b 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -47,8 +47,6 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_viewportY = 0;
 	_word18776 = 0;
 
-
-
 	_savedBuffer215Ptr = NULL;
 
 	for (int i = 0; i < 20; i++) {
@@ -69,7 +67,6 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array1614B[i] = 0;
 		_array16173[i] = 0xFF;
 		_array122C1[i] = 0;
-		_array1813B[i] = 0;
 	}
 
 	for (int i = 0; i < 640; i++) {
@@ -612,7 +609,6 @@ void LilliputScript::sub1863B() {
 	_word1855E = 0;
 }
 
-
 void LilliputScript::sub185ED(byte index, byte subIndex) {
 	debugC(2, kDebugScript, "sub185ED");
 	if (_vm->_arr18560[index]._field0 != 1)
@@ -681,8 +677,6 @@ void LilliputScript::computeOperation(byte *bufPtr, int oper, int var2) {
 	}
 }
 
-
-
 void LilliputScript::sub185B4_display() {
 	if (_vm->_byte12A04 == _byte1855D)
 		return;
@@ -962,6 +956,7 @@ byte LilliputScript::OC_compWord18776() {
 	warning("OC_compWord18776");
 	return 0;
 }
+
 byte LilliputScript::OC_checkSaveFlag() {
 	debugC(1, kDebugScript, "OC_checkSaveFlag()");
 
@@ -1089,6 +1084,7 @@ byte LilliputScript::OC_sub175C8() {
 	
 	return 0;
 }
+
 byte LilliputScript::OC_sub17640() {
 	debugC(1, kDebugScript, "OC_sub176C4()");
 
@@ -1194,6 +1190,7 @@ byte LilliputScript::OC_compWord10804() {
 
 	return 0;
 }
+
 byte LilliputScript::OC_sub17766() {
 	warning("OC_sub17766");
 	return 0;
@@ -1206,6 +1203,7 @@ byte LilliputScript::OC_sub1779E() {
 	warning("OC_sub1779E");
 	return 0;
 }
+
 byte LilliputScript::OC_sub177C6() {
 	debugC(1, kDebugScript, "OC_sub177C6()");
 
@@ -1215,6 +1213,7 @@ byte LilliputScript::OC_sub177C6() {
 
 	return 1;
 }
+
 byte LilliputScript::OC_compWord16EFE() {
 	debugC(1, kDebugScript, "OC_compWord16EFE()");
 
@@ -1306,6 +1305,7 @@ byte LilliputScript::OC_sub178BA() {
 	warning("OC_sub178BA");
 	return 0;
 }
+
 byte LilliputScript::OC_sub178C2() {
 	debugC(1, kDebugScript, "OC_sub178C2()");
 
@@ -1314,12 +1314,31 @@ byte LilliputScript::OC_sub178C2() {
 		return 1;
 	return 0;
 }
+
 byte LilliputScript::OC_sub178D2() {
-	warning("OC_sub178D2");
+	debugC(1, kDebugScript, "OC_sub178D2()");
+
+	int index = getValue1();
+	assert (index < 40);
+
+	byte curByte = (_currScript->readUint16LE() & 0xFF);
+
+	if (curByte == _vm->_rulesBuffer2_12[index])
+		return 1;
+
 	return 0;
 }
+
 byte LilliputScript::OC_sub178E8() {
-	warning("OC_sub178E8");
+	debugC(1, kDebugScript, "OC_sub178E8()");
+
+	byte *bufPtr = getBuffer215Ptr();
+	byte var1 = bufPtr[0];
+	byte curByte = (_currScript->readUint16LE() & 0xFF);
+
+	if (var1 & curByte)
+		return 1;
+
 	return 0;
 }
 
@@ -1385,6 +1404,7 @@ byte LilliputScript::OC_sub1796E() {
 	warning("OC_sub1796E");
 	return 0;
 }
+
 byte LilliputScript::OC_sub17984() {
 	debugC(1, kDebugScript, "OC_sub17984()");
 
@@ -1538,9 +1558,11 @@ void LilliputScript::OC_sub17A8D() {
 	_vm->_characterPositionX[tmpVal] = 0xFFFF;
 	_vm->_characterPositionY[tmpVal] = 0xFFFF;
 }
+
 void LilliputScript::OC_saveAndQuit() {
 	warning("OC_saveAndQuit");
 }
+
 void LilliputScript::OC_sub17B93() {
 	debugC(1, kDebugScript, "OC_sub17B93()");
 	int var1 = _currScript->readUint16LE();
@@ -1573,6 +1595,7 @@ void LilliputScript::OC_sub17BA5() {
 void LilliputScript::OC_setByte18823() {
 	warning("OC_setByte18823");
 }
+
 void LilliputScript::OC_sub17BB7() {
 	debugC(1, kDebugScript, "OC_sub17BB7()");
 
@@ -1632,6 +1655,7 @@ void LilliputScript::OC_setWord10804() {
 
 	_word10804 = getValue1();
 }
+
 void LilliputScript::OC_sub17C0E() {
 	warning("OC_sub17C0E");
 }
@@ -1659,6 +1683,7 @@ void LilliputScript::OC_sub17CD1() {
 void LilliputScript::OC_resetWord16EFE() {
 	warning("OC_resetWord16EFE");
 }
+
 void LilliputScript::OC_sub17CEF() {
 	debugC(1, kDebugScript, "OC_sub17CEF()");
 
@@ -1750,6 +1775,7 @@ void LilliputScript::OC_sub18074() {
 void LilliputScript::OC_sub1808B() {
 	warning("OC_sub1808B");
 }
+
 void LilliputScript::OC_sub18099() {
 	debugC(1, kDebugScript, "OC_sub18099()");
 
@@ -1762,6 +1788,7 @@ void LilliputScript::OC_sub18099() {
 
 	_vm->displayFunction8();
 }
+
 void LilliputScript::OC_sub180C3() {
 	warning("OC_sub180C3");
 }
@@ -1783,17 +1810,19 @@ void LilliputScript::OC_sub1817F() {
 	
 	int b1 = var1 & 0xFF;
 	int b2 = var2 & 0xFF;
-	OC_sub1817F_loop(b1,b2);
+	sub1818B(b1,b2);
 }
 
-void LilliputScript::OC_sub1817F_loop( int b1, int b2 ) {
+void LilliputScript::sub1818B(int b1, int b2) {
+	debugC(2, kDebugScript, "sub1818B(%d, %d)", b1, b2);
 	for (int i = 0; i <  _vm->_word1817B; i++) {
 		if ((_array1813B[i] >> 8) == b2 ) {
 			b2 += _array1813B[i] & 0xFF;
-			if (b2 < 0) {
+			if (b2 > 0xFF) {
 				b2 = 0xFF;
+				++b1;
 			}
-			_array1813B[i] = (_array1813B[i] & 0xFF00) + b2;
+			_array1813B[i] = (b1 << 8) + b2;
 			return;
 		}
 	}
@@ -1802,7 +1831,7 @@ void LilliputScript::OC_sub1817F_loop( int b1, int b2 ) {
 }
 
 void LilliputScript::OC_sub181BB() {
-	debugC(1, kDebugScript, "OC_sub1817F()");
+	debugC(1, kDebugScript, "OC_sub181BB()");
 	
 	int b = _currScript->readUint16LE();
 	int d = _currScript->readUint16LE() & 0xFF;
@@ -1827,9 +1856,10 @@ void LilliputScript::OC_sub181BB() {
 
 	int a = _currScript->readUint16LE() * c + (c & 0xFF);
 	b = b & 0xFF00 + a;
-	OC_sub1817F_loop(b & 0xFF, b >> 8);
+	sub1818B(b & 0xFF, b >> 8);
 
 }
+
 void LilliputScript::OC_sub18213() {
 	debugC(1, kDebugScript, "OC_sub18213()");
 
@@ -1839,13 +1869,14 @@ void LilliputScript::OC_sub18213() {
 	int maxItem = var1 & 0xFF;
 
 	for (int i = 0; i < _vm->_word1817B; i++) {
-		if ( _array1813B[i] & 0xFF > maxValue ) {
+		if ((_array1813B[i] & 0xFF) > maxValue) {
 			maxValue = _array1813B[i] & 0xFF;
 			maxItem = _array1813B[i] >> 8;
 		}
 	}
 	sub1823E(_vm->_rulesBuffer2PrevIndx, maxItem, &_vm->_rulesBuffer2_15[var1]);
 }
+
 void LilliputScript::OC_sub18252() {
 	warning("OC_sub18252");
 }
@@ -1857,6 +1888,8 @@ void LilliputScript::OC_sub182EC() {
 }
 
 void LilliputScript::OC_PaletteFadeOut() {
+	debugC(1, kDebugScript, "OC_PaletteFadeOut()");
+
 	sub1863B();
 	byte palette[768];
 	for (int fade = 256; fade >= 0;	fade -= 8) {
@@ -1870,6 +1903,7 @@ void LilliputScript::OC_PaletteFadeOut() {
 }
 
 void LilliputScript::OC_PaletteFadeIn() {
+	debugC(1, kDebugScript, "OC_PaletteFadeIn()");
 
 	byte palette[768];
 	for (int fade = 8; fade <= 256;	fade += 8) {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index d631d48..daf1466 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -226,7 +226,7 @@ private:
 	void OC_sub1810A();
 	void OC_sub1812D();
 	void OC_sub1817F();
-	void OC_sub1817F_loop( int b1, int b2 );
+	void sub1818B(int b1, int b2);
 	void OC_sub181BB();
 	void OC_sub18213();
 	void OC_sub18252();


Commit: 1f7cf60ddb49f3b581d196e1631b72f45ab9a643
    https://github.com/scummvm/scummvm/commit/1f7cf60ddb49f3b581d196e1631b72f45ab9a643
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fixsome problems reported by clone2727

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index b1c7c4f..8d33df3 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -291,9 +291,9 @@ Common::Platform LilliputEngine::getPlatform() const {
 void LilliputEngine::displayFunction18(int index, int x, int y, int flags) {
 	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d, %d)", index, x, y, flags);
 
-	byte* buf = _buffer1_45k + (y << 8) + x;
+	byte *buf = _buffer1_45k + (y << 8) + x;
 
-	byte* src = _bufferMen;
+	byte *src = _bufferMen;
 	if (index < 0) {
 		src = _bufferIdeogram;
 		index = -index;
@@ -569,12 +569,12 @@ void LilliputEngine::displayFunction14() {
 	_system->updateScreen();
 
 	displayFunction4();
-};
+}
 
 void LilliputEngine::restoreMapPoints() {
 	displayFunction5();
 
-	byte* buf = (byte*)_mainSurface->getPixels();
+	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = 0; index < _word10807_ERULES; index++) {
 		buf[_word15E5D[index]] = _byte15E35[index];
 	}
@@ -586,9 +586,9 @@ void LilliputEngine::displayCharactersOnMap() {
 	sub16217();
 	displayFunction5();
 
-	byte* buf = (byte*)_mainSurface->getPixels();
-	for( int index = _word10807_ERULES - 1; index >=0; index--) {
-		if(((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614B[index] != -1)) {
+	byte *buf = (byte *)_mainSurface->getPixels();
+	for (int index = _word10807_ERULES - 1; index >=0; index--) {
+		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614B[index] != -1)) {
 			 int y = (3 * _scriptHandler->_array1614B[index]) + 1;
 			 int x = (_scriptHandler->_array16123[index] * 4) + 1;
 
@@ -740,7 +740,7 @@ void LilliputEngine::displayFunction16() {
 
 int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 {
-	byte* isoMap = _bufferIsoMap + (x1 << 8) + (y1 << 2) + 1;
+	byte *isoMap = _bufferIsoMap + (x1 << 8) + (y1 << 2) + 1;
 
 	int dx = x2 - x1;
 	int dy = y2 - y1;
@@ -813,7 +813,7 @@ void LilliputEngine::sub16CA0() {
 		int c1 = _scriptHandler->_array16123[index];
 		int c2 = _scriptHandler->_array1614B[index];
 
-		for(int index2 = _word10807_ERULES - 1; index2 >= 0; index2--) {
+		for (int index2 = _word10807_ERULES - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
 			if ((index != index2 ) &&
 				(_rulesBuffer2_5[index] != index2) &&
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 46b573b..5bef67b 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -952,6 +952,7 @@ byte LilliputScript::OC_sub1748C() {
 	warning("OC_sub1748C");
 	return 0;
 }
+
 byte LilliputScript::OC_compWord18776() {
 	warning("OC_compWord18776");
 	return 0;


Commit: 32ed5e62af5e8689babb0cb4dced12996e757655
    https://github.com/scummvm/scummvm/commit/32ed5e62af5e8689babb0cb4dced12996e757655
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement another opcode and associated function

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 5bef67b..1ca521c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1200,9 +1200,31 @@ byte LilliputScript::OC_sub17782() {
 	warning("OC_sub17782");
 	return 0;
 }
+
+byte *LilliputScript::getMapPtr(int var1) {
+	debugC(1, kDebugScript, "getMapPtr(%d)", var1);
+	
+	int index = (((var1 & 0xFF) << 6) + (var1 >> 8)) << 2;
+	return &_vm->_bufferIsoMap[index];
+}
+
 byte LilliputScript::OC_sub1779E() {
-	warning("OC_sub1779E");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub1779E()");
+
+	int tmpVal = getValue2();
+
+	if (tmpVal == 0xFFFF) {
+		_currScript->seek(_currScript->pos() + 6);
+		return 0;
+	}
+	
+	int var2 = _currScript->readUint16LE();
+	byte *buf = getMapPtr(tmpVal);
+	byte var1 = buf[var2];
+	var2 = _currScript->readUint16LE();
+	int oper = _currScript->readUint16LE();
+	
+	return compareValues(var1, oper, var2);
 }
 
 byte LilliputScript::OC_sub177C6() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index daf1466..ce92e81 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -103,6 +103,7 @@ private:
 	void sub18A56(byte *buf);
 	void sub18B3C(int var);
 	void sub18BE6(byte var1, int var2, int var4);
+	byte *getMapPtr(int var1);
 
 	int getValue1();
 	int getValue2();


Commit: b2ac6e06316405881473c78d4a84a6baa8dbcee7
    https://github.com/scummvm/scummvm/commit/b2ac6e06316405881473c78d4a84a6baa8dbcee7
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Replace MemoryReadStream by a custom read/write stream

Changed paths:
  A engines/lilliput/stream.cpp
  A engines/lilliput/stream.h
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/module.mk
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8d33df3..8786440 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1993,7 +1993,7 @@ void LilliputEngine::handleMenu() {
 		return;
 
 	sub170EE(_word10804);
-	_scriptHandler->runMenuScript(Common::MemoryReadStream(_menuScript, _menuScript_size));
+	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScript_size));
 	_savedMousePosDivided = 0xFFFF;
 	_byte129A0 = 0xFF;
 
@@ -2036,7 +2036,7 @@ void LilliputEngine::handleGameScripts() {
 	assert(tmpVal < _gameScriptIndexSize);
 	debugC(1, kDebugEngine, "========================== Game Script %d ==========================", tmpVal);
 
-	_scriptHandler->runScript(Common::MemoryReadStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
+	_scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
 }
 
 Common::Error LilliputEngine::run() {
@@ -2067,7 +2067,7 @@ Common::Error LilliputEngine::run() {
 
 
 	//TODO: Init sound/music player
-	_scriptHandler->runScript(Common::MemoryReadStream(_initScript, _initScript_size));
+	_scriptHandler->runScript(ScriptStream(_initScript, _initScript_size));
 
 	_int8installed = true;
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 14bd9ad..ddcbfbe 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -26,6 +26,7 @@
 #include "lilliput/console.h"
 #include "lilliput/script.h"
 #include "lilliput/sound.h"
+#include "lilliput/stream.h"
 
 #include "common/file.h"
 #include "engines/engine.h"
diff --git a/engines/lilliput/module.mk b/engines/lilliput/module.mk
index 807f536..8a095e8 100644
--- a/engines/lilliput/module.mk
+++ b/engines/lilliput/module.mk
@@ -5,7 +5,8 @@ MODULE_OBJS = \
 	detection.o \
 	lilliput.o \
 	script.o \
-	sound.o
+	sound.o \
+	stream.o
 
 MODULE_DIRS += \
 	engines/lilliput
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 1ca521c..fe343b4 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -551,7 +551,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 	}
 }
 
-int LilliputScript::handleOpcode(Common::MemoryReadStream *script) {
+int LilliputScript::handleOpcode(ScriptStream *script) {
 	debugC(2, kDebugScript, "handleOpcode");
 	_currScript = script;
 	uint16 curWord = _currScript->readUint16LE();
@@ -584,7 +584,7 @@ int LilliputScript::handleOpcode(Common::MemoryReadStream *script) {
 	}
 }
 
-void LilliputScript::runScript(Common::MemoryReadStream script) {
+void LilliputScript::runScript(ScriptStream script) {
 	debugC(1, kDebugScript, "runScript");
 	_byte16F05_ScriptHandler = 1;
 	
@@ -592,7 +592,7 @@ void LilliputScript::runScript(Common::MemoryReadStream script) {
 		_vm->update();
 }
 
-void LilliputScript::runMenuScript(Common::MemoryReadStream script) {
+void LilliputScript::runMenuScript(ScriptStream script) {
 	debugC(1, kDebugScript, "runMenuScript");
 	warning("========================== Menu Script ==============================");
 	_byte16F05_ScriptHandler = 0;
@@ -1217,7 +1217,6 @@ byte LilliputScript::OC_sub1779E() {
 		_currScript->seek(_currScript->pos() + 6);
 		return 0;
 	}
-	
 	int var2 = _currScript->readUint16LE();
 	byte *buf = getMapPtr(tmpVal);
 	byte var1 = buf[var2];
@@ -1635,9 +1634,9 @@ void LilliputScript::OC_sub17BB7() {
 
 	if (_byte16F05_ScriptHandler == 0) {
 		_vm->_byte1714E = 0;
-		runMenuScript(Common::MemoryReadStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
+		runMenuScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
 	} else {
-		runScript(Common::MemoryReadStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
+		runScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
 	}
 
 	_currScript = _scriptStack.pop();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index ce92e81..0b218d6 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -27,9 +27,12 @@
 #include "common/stack.h"
 #include "common/random.h"
 
+#include "lilliput/stream.h"
+
 namespace Lilliput {
 
 class LilliputEngine;
+
 class LilliputScript {
 public:
 	byte displayMap;
@@ -66,13 +69,13 @@ public:
 	LilliputScript(LilliputEngine *vm);
 	~LilliputScript();
 
-	void runScript(Common::MemoryReadStream script);
-	void runMenuScript(Common::MemoryReadStream script);
+	void runScript(ScriptStream script);
+	void runMenuScript(ScriptStream script);
 private:
 	LilliputEngine *_vm;
 
-	Common::MemoryReadStream *_currScript;
-	Common::Stack<Common::MemoryReadStream *> _scriptStack;
+	ScriptStream *_currScript;
+	Common::Stack<ScriptStream *> _scriptStack;
 
 	byte _byte16F05_ScriptHandler;
 	byte _byte12A09;
@@ -88,7 +91,7 @@ private:
 	int _word1855E;
 	int _word18776;
 
-	int handleOpcode(Common::MemoryReadStream *script);
+	int handleOpcode(ScriptStream *script);
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 
diff --git a/engines/lilliput/stream.cpp b/engines/lilliput/stream.cpp
new file mode 100644
index 0000000..30c7f14
--- /dev/null
+++ b/engines/lilliput/stream.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 "lilliput/stream.h"
+
+namespace Lilliput {
+
+ScriptStream::ScriptStream(byte *buf, int size) : Common::MemoryReadStream(buf, size) {
+	_orgPtr = buf;
+}
+
+ScriptStream::~ScriptStream() {
+}
+
+void ScriptStream::writeUint16LE(int value, int relativePos) {
+	Common::MemoryWriteStream tmpStream = Common::MemoryWriteStream(_orgPtr, size());
+	int writePos = pos() + relativePos < size();
+	
+	assert((writePos >= 0) && (writePos < size()));
+
+	tmpStream.writeSint16LE(value);
+}
+
+} // End of namespace Lilliput
diff --git a/engines/lilliput/stream.h b/engines/lilliput/stream.h
new file mode 100644
index 0000000..d6b8c36
--- /dev/null
+++ b/engines/lilliput/stream.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 LILLIPUT_STREAM_H
+#define LILLIPUT_STREAM_H
+
+#include "common/memstream.h"
+
+namespace Lilliput {
+
+class ScriptStream : public Common::MemoryReadStream {
+private:
+	byte *_orgPtr;
+public:
+	ScriptStream(byte *buf, int size);
+	virtual ~ScriptStream();
+
+	void writeUint16LE(int value, int relativePos = 0);
+};
+
+} // End of namespace Lilliput
+
+#endif


Commit: dc4831d00fcc62af77330295e589b4b7523cd391
    https://github.com/scummvm/scummvm/commit/dc4831d00fcc62af77330295e589b4b7523cd391
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix stream write

Changed paths:
    engines/lilliput/stream.cpp


diff --git a/engines/lilliput/stream.cpp b/engines/lilliput/stream.cpp
index 30c7f14..03195dc 100644
--- a/engines/lilliput/stream.cpp
+++ b/engines/lilliput/stream.cpp
@@ -32,12 +32,12 @@ ScriptStream::~ScriptStream() {
 }
 
 void ScriptStream::writeUint16LE(int value, int relativePos) {
-	Common::MemoryWriteStream tmpStream = Common::MemoryWriteStream(_orgPtr, size());
-	int writePos = pos() + relativePos < size();
 	
-	assert((writePos >= 0) && (writePos < size()));
+	int writePos = pos() + relativePos;
+	assert((writePos >= 0) && (writePos + 2 < size()));
 
-	tmpStream.writeSint16LE(value);
+	Common::MemoryWriteStream tmpStream = Common::MemoryWriteStream(_orgPtr + writePos, size() - writePos);
+	tmpStream.writeUint16LE(value);
 }
 
 } // End of namespace Lilliput


Commit: 348d46d02d505d6cf8d95f3c23c156d77b1ca4fc
    https://github.com/scummvm/scummvm/commit/348d46d02d505d6cf8d95f3c23c156d77b1ca4fc
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement 3 opcodes

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index fe343b4..6c6bef0 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -898,6 +898,7 @@ void LilliputScript::sub130B6() {
 
 byte *LilliputScript::getBuffer215Ptr() {
 	debugC(2, kDebugScript, "getBuffer215Ptr()");
+
 	int tmpVal = getValue1();
 	tmpVal *= 32;
 	tmpVal += _currScript->readUint16LE();
@@ -910,10 +911,21 @@ byte LilliputScript::OC_sub173DF() {
 	warning("OC_sub173DF");
 	return 0;
 }
+
 byte LilliputScript::OC_sub173F0() {
-	warning("OC_sub173F0");
+	debugC(2, kDebugScript, "OC_sub173F0()");
+
+	int index = getValue1();
+	byte d1 = _array16123[index];
+	byte d2 = _array1614B[index];
+	int var1 = getValue2();
+
+	if (var1 == (d1 << 8) + d2)
+		return 1;
+
 	return 0;
 }
+
 byte LilliputScript::OC_sub1740A() {
 	warning("OC_sub1740A");
 	return 0;
@@ -949,8 +961,17 @@ byte LilliputScript::OC_getRandom() {
 }
 
 byte LilliputScript::OC_sub1748C() {
-	warning("OC_sub1748C");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub1748C()");
+
+	int var1 = _currScript->readUint16LE();
+	int tmpVal = _currScript->readUint16LE() + 1;
+	// no need to seek later, the move is already done
+	_currScript->writeUint16LE(tmpVal, -2);
+	// overwrite the recently used "variable" in the script
+	if (tmpVal < var1)
+		return 0;
+
+	return 1;
 }
 
 byte LilliputScript::OC_compWord18776() {
@@ -1679,8 +1700,23 @@ void LilliputScript::OC_setWord10804() {
 }
 
 void LilliputScript::OC_sub17C0E() {
-	warning("OC_sub17C0E");
+	debugC(1, kDebugScript, "OC_sub17C0E()");
+
+	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	byte var1 = (_vm->_ptr_rulesBuffer2_15[4] << 8) + _vm->_ptr_rulesBuffer2_15[5];
+	byte b2 = _vm->_ptr_rulesBuffer2_15[6];
+
+	byte *mapPtr = getMapPtr(var1);
+	mapPtr[b2] = _vm->_ptr_rulesBuffer2_15[7];
+	mapPtr[3] = _vm->_ptr_rulesBuffer2_15[8];
+
+	if (b2 == 0) {
+		_byte12A09 = 1;
+		_vm->displayFunction9();
+		_byte12A09 = 0;
+	}
 }
+
 void LilliputScript::OC_sub17C55() {
 	warning("OC_sub17C55");
 }


Commit: 977c07ba70e8d3ebdd86b3ddf30903762e5d7ce0
    https://github.com/scummvm/scummvm/commit/977c07ba70e8d3ebdd86b3ddf30903762e5d7ce0
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implements 2 opcodes

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 6c6bef0..bd67783 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1572,7 +1572,12 @@ void LilliputScript::OC_sub17B03() {
 }
 
 void LilliputScript::OC_getRandom_type2() {
-	warning("OC_getRandom_type2");
+	debugC(1, kDebugScript, "OC_getRandom_type2()");
+
+	byte* bufPtr = getBuffer215Ptr();
+	int maxVal = _currScript->readUint16LE(); 
+	int randomVal = _vm->_rnd->getRandomNumber(maxVal);
+	*bufPtr = randomVal;
 }
 
 void LilliputScript::OC_sub17A66() {
@@ -1718,7 +1723,16 @@ void LilliputScript::OC_sub17C0E() {
 }
 
 void LilliputScript::OC_sub17C55() {
-	warning("OC_sub17C55");
+	debugC(1, kDebugScript, "OC_sub17C55()");
+	int var1 = getValue1();
+	int var2 = getValue1();
+
+	int var3 = _currScript->readUint16LE();
+	int var4 = _currScript->readUint16LE();
+
+	_vm->_rulesBuffer2_5[var2] = var1 & 0xFF;
+	_vm->_rulesBuffer2_6[var2] = var3 & 0xFF;
+	_vm->_rulesBuffer2_7[var2] = var4 & 0xFF;
 }
 void LilliputScript::OC_sub17C76() {
 	warning("OC_sub17C76");


Commit: 794869656b2d0433b69ae6627844288c1e7288d4
    https://github.com/scummvm/scummvm/commit/794869656b2d0433b69ae6627844288c1e7288d4
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a bug in OC_for

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index bd67783..df21358 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -99,7 +99,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_getRandom();
 		break;
 	case 0x6:
-		return OC_sub1748C();
+		return OC_for();
 		break;
 	case 0x7:
 		return OC_compWord18776();
@@ -960,8 +960,8 @@ byte LilliputScript::OC_getRandom() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub1748C() {
-	debugC(1, kDebugScript, "OC_sub1748C()");
+byte LilliputScript::OC_for() {
+	debugC(1, kDebugScript, "OC_for()");
 
 	int var1 = _currScript->readUint16LE();
 	int tmpVal = _currScript->readUint16LE() + 1;
@@ -971,6 +971,7 @@ byte LilliputScript::OC_sub1748C() {
 	if (tmpVal < var1)
 		return 0;
 
+	_currScript->writeUint16LE(0, -2);
 	return 1;
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 0b218d6..24a74d7 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -122,7 +122,7 @@ private:
 	byte OC_sub17434();
 	byte OC_sub17468();
 	byte OC_getRandom();
-	byte OC_sub1748C();
+	byte OC_for();
 	byte OC_compWord18776();
 	byte OC_checkSaveFlag();
 	byte OC_sub174C8();


Commit: c4186ba41bfcaa20876fed950d45cb502b7efb9a
    https://github.com/scummvm/scummvm/commit/c4186ba41bfcaa20876fed950d45cb502b7efb9a
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implements one more opcode

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index df21358..1b75bd4 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -926,9 +926,32 @@ byte LilliputScript::OC_sub173F0() {
 	return 0;
 }
 
+byte* LilliputScript::sub17399(int val) {
+	int x = (val >> 8);
+	int y = (val & 0xFF);
+	return &_vm->_bufferIsoMap[(y * 320 + x) << 2];
+}
+
 byte LilliputScript::OC_sub1740A() {
-	warning("OC_sub1740A");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub1740A()");
+
+	int var = _vm->_word16EFA;
+	if (var == 0xFFFF) {
+		_currScript->readUint16LE();
+		return 0;
+	}
+
+	byte *isoMapBuf = sub17399(var);
+	int var2 = isoMapBuf[3];
+
+	int var3 = _currScript->readUint16LE();
+	int var4 = 8 >> var3;
+
+	if( var2 & var4 ) {
+		return 1;
+	} else { 
+		return 0;
+	}
 }
 
 byte LilliputScript::OC_sub17434() {
@@ -943,8 +966,11 @@ byte LilliputScript::OC_sub17434() {
 }
 
 byte LilliputScript::OC_sub17468() {
-	warning("OC_sub17468");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub17468()");
+
+	int operation = _currScript->readUint16LE();
+	int val2 = _currScript->readUint16LE();
+	return compareValues(_byte16F02, operation, val2);
 }
 
 byte LilliputScript::OC_getRandom() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 24a74d7..4d7f5e9 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -106,6 +106,7 @@ private:
 	void sub18A56(byte *buf);
 	void sub18B3C(int var);
 	void sub18BE6(byte var1, int var2, int var4);
+	byte* sub17399(int val);
 	byte *getMapPtr(int var1);
 
 	int getValue1();


Commit: d19e92fbb0a1b410645a7badc9a229082f1763c5
    https://github.com/scummvm/scummvm/commit/d19e92fbb0a1b410645a7badc9a229082f1763c5
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Several opcodes & renaming

Rename character related variables

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8786440..3e8f4d9 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -145,10 +145,10 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte16552 = 0;
 	_byte12FE4 = 0xFF;
 	_byte12FE3 = 0;
-	_byte16F08 = 0;	
+	_byte16F08 = 0;
 
 	_rulesBuffer2PrevIndx = 0;
-	_word16EFA = 0;
+	_currentScriptCharacterPosition = 0;
 	_word10804 = 0;
 	_word17081_nextIndex = 0;
 	_word16EFE = 0xFFFF;
@@ -575,7 +575,7 @@ void LilliputEngine::restoreMapPoints() {
 	displayFunction5();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
-	for (int index = 0; index < _word10807_ERULES; index++) {
+	for (int index = 0; index < _numCharacters; index++) {
 		buf[_word15E5D[index]] = _byte15E35[index];
 	}
 
@@ -587,7 +587,7 @@ void LilliputEngine::displayCharactersOnMap() {
 	displayFunction5();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
-	for (int index = _word10807_ERULES - 1; index >=0; index--) {
+	for (int index = _numCharacters - 1; index >=0; index--) {
 		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614B[index] != -1)) {
 			 int y = (3 * _scriptHandler->_array1614B[index]) + 1;
 			 int x = (_scriptHandler->_array16123[index] * 4) + 1;
@@ -604,7 +604,7 @@ void LilliputEngine::sub16217() {
 	debugC(2, kDebugEngine, "sub16217()");
 
 	_numCharactersToDisplay = 0;
-	int index = _word10807_ERULES - 1;
+	int index = _numCharacters - 1;
 	_word16213 = _scriptHandler->_viewportX << 3;
 	_word16215 = _scriptHandler->_viewportY << 3;
 
@@ -806,14 +806,14 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 void LilliputEngine::sub16CA0() {
 	debugC(2, kDebugEngine, "sub16CA0()");
 
-	for (int index = _word10807_ERULES - 1; index >= 0; index--) {
+	for (int index = _numCharacters - 1; index >= 0; index--) {
 		if (_rulesBuffer2_11[index] & 1)
 			continue;
 
 		int c1 = _scriptHandler->_array16123[index];
 		int c2 = _scriptHandler->_array1614B[index];
 
-		for (int index2 = _word10807_ERULES - 1; index2 >= 0; index2--) {
+		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
 			if ((index != index2 ) &&
 				(_rulesBuffer2_5[index] != index2) &&
@@ -884,7 +884,7 @@ void LilliputEngine::sub16CA0() {
 			int val = _scriptHandler->_array10B51[index2 + index * 40];
 			val = (val & 0xFF) + ((val & 0xFF) << 8);
 			if( (val & 0xFF) != _byte16C9F ) {
-				_scriptHandler->_array10B29[index] = 1;
+				_scriptHandler->_characterScriptEnabled[index] = 1;
 				val = (val & 0xFF00) | _byte16C9F;
 			}
 			_scriptHandler->_array10B51[index2 + index * 40] = val;
@@ -1106,11 +1106,11 @@ void LilliputEngine::renderCharacters(byte *buf, int x, int y) {
 
 void LilliputEngine::sub1546F(byte displayX, byte displayY) {
 	debugC(2, kDebugEngine, "sub1546F(%d, %d)", displayX, displayY);
-	
+
 	int orgX = displayX + 8;
 	int orgY = displayY;
 	int var2 = 0;
-	
+
 	int x = orgX;
 	int y = orgY;
 	do {
@@ -1118,10 +1118,10 @@ void LilliputEngine::sub1546F(byte displayX, byte displayY) {
 		--x;
 		y >>= 1;
 	} while (y != 0);
-	
+
 	x = orgX + 1;
 	y = orgY >> 1;
-	
+
 	while (y != 0) {
 		sub15498(x, y, var2);
 		++x;
@@ -1131,7 +1131,7 @@ void LilliputEngine::sub1546F(byte displayX, byte displayY) {
 
 void LilliputEngine::sub15498(byte x, byte y, int var2) {
 	debugC(2, kDebugEngine, "sub15498(%d, %d, %d)", x, y, var2);
-	
+
 	int index = x + ((var2 & 0xFF) << 8) + (var2 >> 8);
 	for (int i = 1 + y - var2; i > 0; i--) {
 		_buffer1_45k[index] = 17;
@@ -1248,7 +1248,7 @@ void LilliputEngine::prepareGoldAmount(int param1) {
 void LilliputEngine::sub16626() {
 	debugC(2, kDebugEngine, "sub16626()");
 
-	int index = _word10807_ERULES - 1;
+	int index = _numCharacters - 1;
 	int result;
 	while (index >= 0) {
 		result = 2;
@@ -1263,9 +1263,6 @@ void LilliputEngine::sub16626() {
 			var2 = ((var1 >> 8) >> 3);
 			var2 &= 0xFE;
 
-			// temporary hack
-			result = 0;
-
 			switch (var2 / 2) {
 			case 0:
 				result = sub16675(index, var1);
@@ -1309,7 +1306,7 @@ void LilliputEngine::sub16626() {
 			if (result & 1) {
 				++_scriptHandler->_array12811[index];
 				if (_scriptHandler->_array12811[index] == 16)
-					_scriptHandler->_array10B29[index] = 1;
+					_scriptHandler->_characterScriptEnabled[index] = 1;
 			}
 		}
 		--index;
@@ -1328,7 +1325,7 @@ void LilliputEngine::sub16EBC() {
 
 	int index2 = 3;
 
-	for (int index1 = _word10807_ERULES - 1; index1 >= 0; index1--) {
+	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
 		int var2 = (_scriptHandler->_array1614B[index1] << 8) + (_scriptHandler->_array16123[index1] << 2);
 		int var1 = (_bufferIsoMap[index2 + var2] & 0x40);
 
@@ -1337,7 +1334,7 @@ void LilliputEngine::sub16EBC() {
 
 		_array16E94[index1] = var1;
 		if (var1 != 0)
-			_scriptHandler->_array10B29[index1] = 1;
+			_scriptHandler->_characterScriptEnabled[index1] = 1;
 	}
 }
 
@@ -1347,15 +1344,15 @@ void LilliputEngine::sub12F37() {
 	int index1 = _byte12A04 + 2;
 	int index2 = 0;
 
-	for (int i = 0; i < _word10807_ERULES; i++) {
+	for (int i = 0; i < _numCharacters; i++) {
 		if (_rulesBuffer2_15[index1] != 0 ) {
 			if (_rulesBuffer2_15[index1] == 1) {
 				_rulesBuffer2_15[index1] = 0;
 			} else {
 				--_rulesBuffer2_15[index1];
 				if (_rulesBuffer2_15[index1] == 1)
-					_scriptHandler->_array10B29[index2] = 1;
-			}			
+					_scriptHandler->_characterScriptEnabled[index2] = 1;
+			}
 		}
 
 		index1 += 32;
@@ -1429,7 +1426,7 @@ void LilliputEngine::sub131B2(int var2, int var4, bool &forceReturnFl) {
 
 	forceReturnFl = false;
 
-	for (int i = 0; i < _word10807_ERULES; i++) {
+	for (int i = 0; i < _numCharacters; i++) {
 		if ((var2 >= _characterDisplayX[i]) && (var2 <= _characterDisplayX[i] + 17) && (var4 >= _characterDisplayY[i]) && (var4 <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_byte129A0 = i;
 			_byte16F07_menuId = 4;
@@ -1564,11 +1561,11 @@ int LilliputEngine::sub16675(int idx, int var1) {
 void LilliputEngine::sub171CF() {
 	debugC(2, kDebugEngine, "sub171CF()");
 
-	for (int i = 0; i < _word10807_ERULES; i++) {
+	for (int i = 0; i < _numCharacters; i++) {
 		if (_array1289F[i] != 0xFFFF) {
 			_array11D49[i] = _array1289F[i];
 			_array1289F[i] = 0xFFFF;
-			_scriptHandler->_array10B29[i] = 1;
+			_scriptHandler->_characterScriptEnabled[i] = 1;
 		}
 	}
 
@@ -1628,7 +1625,7 @@ void LilliputEngine::displayHeroismIndicator() {
 	}
 
 	_scriptHandler->_heroismLevel += var2;
-	
+
 	int index = _scriptHandler->_heroismBarX + _scriptHandler->_heroismBarBottomY * 320 ;
 
 	var2 = _scriptHandler->_heroismLevel & 0xFF;
@@ -1788,10 +1785,10 @@ void LilliputEngine::loadRules() {
 		_rulesChunk1[i] = f.readByte();
 
 	// Chunk 2
-	_word10807_ERULES = f.readSint16LE();
-	assert(_word10807_ERULES <= 40);
+	_numCharacters = f.readSint16LE();
+	assert(_numCharacters <= 40);
 
-	for (int i = _word10807_ERULES, j = 0; i != 0; i--, j++) {
+	for (int i = _numCharacters, j = 0; i != 0; i--, j++) {
 		curWord = f.readUint16LE();
 		if (curWord != 0xFFFF)
 			curWord = (curWord << 3) + 4;
@@ -1975,7 +1972,7 @@ void LilliputEngine::sub170EE(int index) {
 	int var2 = _characterPositionX[index];
 	int var4 = _characterPositionY[index];
 
-	_word16EFA = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF);
+	_currentScriptCharacterPosition = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF);
 	_ptr_rulesBuffer2_15 = &_rulesBuffer2_15[_rulesBuffer2PrevIndx * 32];
 }
 
@@ -2008,35 +2005,34 @@ void LilliputEngine::handleGameScripts() {
 
 	int index = _word17081_nextIndex;
 	int i;
-	for (i = 0; (_scriptHandler->_array10B29[index] == 0) && (i < _word10807_ERULES); i++) {
+	for (i = 0; (_scriptHandler->_characterScriptEnabled[index] == 0) && (i < _numCharacters); i++) {
 		++index;
-		if (index >= _word10807_ERULES)
+		if (index >= _numCharacters)
 			index = 0;
 	}
 
-	if (i > _word10807_ERULES)
+	if (i > _numCharacters)
 		return;
 
-	_scriptHandler->_array10B29[index] = 0;
-	int tmpVal = index + 1;
-	if (tmpVal >= _word10807_ERULES)
-		tmpVal = 0;
+	_word17081_nextIndex = (index + 1) % _numCharacters;
+
 
-	_word17081_nextIndex = tmpVal;
+	_scriptHandler->_characterScriptEnabled[index] = 0;
 	sub170EE(index);
 
 	_word16EFE = _array11D49[index];
 	_array11D49[index] = 0xFFFF;
 	_word1817B = 0;
 
-	tmpVal = _rulesBuffer2_12[index];
+	int tmpVal = _rulesBuffer2_12[index];
 	if (tmpVal == 0xFF)
 		return;
 
 	assert(tmpVal < _gameScriptIndexSize);
-	debugC(1, kDebugEngine, "========================== Game Script %d ==========================", tmpVal);
-
+	debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index);
 	_scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
+	debugC(1, kDebugEngine, "============= End Game Script %d for character %d ==================", tmpVal, index);
+
 }
 
 Common::Error LilliputEngine::run() {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index ddcbfbe..d49385d 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -125,8 +125,8 @@ public:
 	bool _int8installed;
 
 	int _word10800_ERULES;
-	int _word10807_ERULES;
-	int _word16EFA;
+	int _numCharacters;
+	int _currentScriptCharacterPosition;
 	int _word17081_nextIndex;
 	int _word16EFE;
 	int _word1817B;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 1b75bd4..833fb14 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -58,7 +58,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array1813B[i] = 0;
 
 	for (int i = 0; i < 40; i++) {
-		_array10B29[i] = 1;
+		_characterScriptEnabled[i] = 1;
 		_array128EF[i] = 15;
 		_array10AB1[i] = 0;
 		_array12811[i] = 16;
@@ -702,7 +702,7 @@ void LilliputScript::sub1823E(byte var1, byte var2, byte *curBufPtr) {
 	debugC(1, kDebugScript, "sub1823E(%d, %d, curBufPtr)", var1, var2);
 
 	assert ((var1 >= 0) && (var1 < 40));
-	_array10B29[var1] = 1;
+	_characterScriptEnabled[var1] = 1;
 	curBufPtr[0] = var2;
 	curBufPtr[1] = 0;
 	curBufPtr[2] = 0;
@@ -844,7 +844,7 @@ int LilliputScript::getValue2() {
 		return ((_vm->_rulesBuffer2_13[index] << 8) + _vm->_rulesBuffer2_14[index]);
 		}
 	case 0xFD:
-		return _vm->_word16EFA;
+		return _vm->_currentScriptCharacterPosition;
 	case 0xFC: {
 		int index = curWord & 0xFF;
 		assert(index < 40);
@@ -908,7 +908,10 @@ byte *LilliputScript::getBuffer215Ptr() {
 }
 
 byte LilliputScript::OC_sub173DF() {
-	warning("OC_sub173DF");
+	debugC(2, kDebugScript, "OC_sub173F0()");
+	if (_vm->_currentScriptCharacterPosition == getValue2()) {
+		return 1;
+	}
 	return 0;
 }
 
@@ -935,7 +938,7 @@ byte* LilliputScript::sub17399(int val) {
 byte LilliputScript::OC_sub1740A() {
 	debugC(1, kDebugScript, "OC_sub1740A()");
 
-	int var = _vm->_word16EFA;
+	int var = _vm->_currentScriptCharacterPosition;
 	if (var == 0xFFFF) {
 		_currScript->readUint16LE();
 		return 0;
@@ -1028,7 +1031,7 @@ byte LilliputScript::OC_sub174D8() {
 	
 	if (curWord == 3000) {
 		int index;
-		for (index = 0; index < _vm->_word10807_ERULES; index++) {
+		for (index = 0; index < _vm->_numCharacters; index++) {
 			if (_vm->_rulesBuffer2_5[index] == tmpVal) {
 				_word16F00 = index;
 				return 1;
@@ -1060,7 +1063,7 @@ byte LilliputScript::OC_compareCoords_1() {
 
 	int var3 = _vm->_rulesBuffer12_1[index];
 	int var4 = _vm->_rulesBuffer12_2[index];
-	int var1 = _vm->_word16EFA;
+	int var1 = _vm->_currentScriptCharacterPosition;
 
 	if (((var1 >> 8) < (var3 >> 8)) || ((var1 >> 8) > (var3 & 0xFF)) || ((var1 & 0xFF) < (var4 >> 8)) || ((var1 & 0xFF) > (var4 & 0xFF)))
 		return 0;
@@ -1109,7 +1112,7 @@ byte LilliputScript::OC_sub175C8() {
 	}
 
 	if (tmpVal == 3000) {
-		for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+		for (int i = 0; i < _vm->_numCharacters; i++) {
 			int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
 			if ((var1 & 0xFF) >= var4) {
 				_word16F00 = i;
@@ -1121,7 +1124,7 @@ byte LilliputScript::OC_sub175C8() {
 	
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
-	for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+	for (int i = 0; i < _vm->_numCharacters; i++) {
 		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
 		if ((var1 & 0xFF) >= var4) {
 			if (_vm->_rulesBuffer2_12[i] == var4b) {
@@ -1148,7 +1151,7 @@ byte LilliputScript::OC_sub17640() {
 
 		if (var1 == 3000) {
 			subIndex = 0;
-			for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+			for (int i = 0; i < _vm->_numCharacters; i++) {
 				tmpVal = _array10B51[index + i];
 				byte v1 = tmpVal & 0xFF;
 				byte v2 = tmpVal >> 8;
@@ -1161,7 +1164,7 @@ byte LilliputScript::OC_sub17640() {
 		} else {
 			var1 -= 2000;
 			var4 &= ((var1 & 0xFF) << 8);
-			for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+			for (int i = 0; i < _vm->_numCharacters; i++) {
 				tmpVal = _array10B51[index + i];
 				byte v1 = tmpVal & 0xFF;
 				byte v2 = tmpVal >> 8;
@@ -1204,7 +1207,7 @@ byte LilliputScript::OC_sub176C4() {
 	}
 
 	if (tmpVal == 3000) {
-		for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+		for (int i = 0; i < _vm->_numCharacters; i++) {
 			int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
 			if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
 				_word16F00 = i;
@@ -1216,7 +1219,7 @@ byte LilliputScript::OC_sub176C4() {
 	
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
-	for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+	for (int i = 0; i < _vm->_numCharacters; i++) {
 		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
 		if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
 			if (_vm->_rulesBuffer2_12[i] == var4b) {
@@ -1352,7 +1355,7 @@ byte LilliputScript::OC_sub1785C() {
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 	int count = 0;
 
-	for (int i = 0; i < _vm->_word10807_ERULES; i++) {
+	for (int i = 0; i < _vm->_numCharacters; i++) {
 		if (curByte == _vm->_rulesBuffer2_15[(32 * i)])
 			++count;
 	}
@@ -1451,7 +1454,7 @@ byte LilliputScript::OC_sub1792A() {
 byte LilliputScript::OC_sub1793E() {
 	debugC(1, kDebugScript, "OC_sub1793E()");
 
-	if (_vm->_word16EFA == 0xFFFF)
+	if (_vm->_currentScriptCharacterPosition == 0xFFFF)
 		return 0;
 
 	if (_vm->_array16E94[_vm->_rulesBuffer2PrevIndx] == 0)
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 4d7f5e9..29ba6b2 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -39,7 +39,7 @@ public:
 	byte _byte12A04;
 	byte _heroismLevel;
 
-	byte _array10B29[40];
+	byte _characterScriptEnabled[40];
 	byte _array122E9[20];
 	byte _array16123[40];
 	byte _array1614B[40];


Commit: 566954c8e6026633b1474b309c8bb46980175b4f
    https://github.com/scummvm/scummvm/commit/566954c8e6026633b1474b309c8bb46980175b4f
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More opcodes

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3e8f4d9..bc2a818 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1144,7 +1144,7 @@ void LilliputEngine::sub189DE() {
 
 	if (_byte1881D != 0) {
 		--_byte1881D;
-		if (_byte1881D != 0) {
+		if (_byte1881D == 0) {
 			displayFunction17();
 			_scriptHandler->_word1881B = 0xFFFF;
 		}
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 833fb14..4851f8a 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1575,7 +1575,6 @@ void LilliputScript::OC_sub17DB9() {
 
 void LilliputScript::OC_sub17DF9() {
 	debugC(1, kDebugScript, "OC_sub17DF9()");
-
 	if ((_word1881B & 0xFF) == 0xFF) {
 		OC_sub17D57();
 		return;
@@ -1585,10 +1584,25 @@ void LilliputScript::OC_sub17DF9() {
 }
 
 void LilliputScript::OC_sub17E07() {
-	warning("OC_sub17E07");
+	debugC(1, kDebugScript, "OC_sub17E07()");
+	if ((_word1881B & 0xFF) == 0xFF) {
+		OC_sub17D7F();
+		return;
+	}
+	_currScript->readUint16LE();
+	_currScript->readUint16LE();
+	_currScript->readUint16LE();
+	_currScript->readUint16LE();
+
 }
 void LilliputScript::OC_sub17E15() {
-	warning("OC_sub17E15");
+	debugC(1, kDebugScript, "OC_sub17E15()");
+	if ((_word1881B & 0xFF) == 0xFF) {
+		OC_sub17DB9();
+		return;
+	}
+	_currScript->readUint16LE();
+	_currScript->readUint16LE();
 }
 
 void LilliputScript::OC_sub17B03() {
@@ -1652,13 +1666,15 @@ void LilliputScript::OC_sub17E37() {
 	warning("OC_sub17E37");
 }
 void LilliputScript::OC_resetByte1714E() {
-	warning("OC_resetByte1714E");
+	debugC(1, kDebugScript, "OC_resetByte1714E()");
+	_vm->_byte1714E = 0;
 }
 void LilliputScript::OC_deleteSavegameAndQuit() {
 	warning("OC_deleteSavegameAndQuit");
 }
 void LilliputScript::OC_incByte16F04() {
-	warning("OC_incByte16F04");
+	debugC(1, kDebugScript, "OC_incByte16F04()");
+	_vm->_byte1714E++;
 }
 
 void LilliputScript::OC_sub17BA5() {


Commit: b87053574536607e7dba212416531745af6d6882
    https://github.com/scummvm/scummvm/commit/b87053574536607e7dba212416531745af6d6882
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Remove double implementation of getMapPtr

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 4851f8a..7c10b82 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -929,12 +929,6 @@ byte LilliputScript::OC_sub173F0() {
 	return 0;
 }
 
-byte* LilliputScript::sub17399(int val) {
-	int x = (val >> 8);
-	int y = (val & 0xFF);
-	return &_vm->_bufferIsoMap[(y * 320 + x) << 2];
-}
-
 byte LilliputScript::OC_sub1740A() {
 	debugC(1, kDebugScript, "OC_sub1740A()");
 
@@ -944,7 +938,7 @@ byte LilliputScript::OC_sub1740A() {
 		return 0;
 	}
 
-	byte *isoMapBuf = sub17399(var);
+	byte *isoMapBuf = getMapPtr(var);
 	int var2 = isoMapBuf[3];
 
 	int var3 = _currScript->readUint16LE();
@@ -1252,11 +1246,12 @@ byte LilliputScript::OC_sub17782() {
 	return 0;
 }
 
-byte *LilliputScript::getMapPtr(int var1) {
-	debugC(1, kDebugScript, "getMapPtr(%d)", var1);
-	
-	int index = (((var1 & 0xFF) << 6) + (var1 >> 8)) << 2;
-	return &_vm->_bufferIsoMap[index];
+byte *LilliputScript::getMapPtr(int val) {
+	debugC(1, kDebugScript, "getMapPtr(%d)", val);
+
+	int x = (val >> 8);
+	int y = (val & 0xFF);
+	return &_vm->_bufferIsoMap[(y * 320 + x) << 2];
 }
 
 byte LilliputScript::OC_sub1779E() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 29ba6b2..ff55353 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -106,8 +106,7 @@ private:
 	void sub18A56(byte *buf);
 	void sub18B3C(int var);
 	void sub18BE6(byte var1, int var2, int var4);
-	byte* sub17399(int val);
-	byte *getMapPtr(int var1);
+	byte *getMapPtr(int val);
 
 	int getValue1();
 	int getValue2();


Commit: ba0fcb521f10c4b3cc6aeef9b2371abfd05bc32f
    https://github.com/scummvm/scummvm/commit/ba0fcb521f10c4b3cc6aeef9b2371abfd05bc32f
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming, implement 7 opcodes, fix one

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7c10b82..b345ed3 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -36,6 +36,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte10806 = 0;
 	_byte12FE4 = 0xFF;
 	_byte16F02 = 0;
+	_byte16F04 = 0;
 
 	_word1855E = 0;
 	_word16F00 = -1;
@@ -108,7 +109,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_checkSaveFlag();
 		break;
 	case 0x9:
-		return OC_sub174C8();
+		return OC_compByte16F04();
 		break;
 	case 0xA:
 		return OC_sub174D8();
@@ -630,15 +631,15 @@ byte LilliputScript::compareValues(byte var1, int oper, int var2) {
 	}
 }
 
-void LilliputScript::computeOperation(byte *bufPtr, int oper, int var2) {
-	debugC(1, kDebugScript, "computeOperation(bufPtr, %c, %d)", oper & 0xFF, var2 & 0xFF);
+void LilliputScript::computeOperation(byte *bufPtr, int oper, int var3) {
+	debugC(1, kDebugScript, "computeOperation(bufPtr, %c, %d)", oper & 0xFF, var3 & 0xFF);
 
 	switch (oper & 0xFF) {
 	case '=':
-		bufPtr[0] = var2 & 0xFF;
+		bufPtr[0] = var3 & 0xFF;
 		break;
 	case '+': {
-		int tmpVal = bufPtr[0] + var2;
+		int tmpVal = bufPtr[0] + var3;
 		if (tmpVal > 0xFF)
 			bufPtr[0] = 0xFF;
 		else
@@ -646,7 +647,7 @@ void LilliputScript::computeOperation(byte *bufPtr, int oper, int var2) {
 		}
 		break;
 	case '-': {
-		int tmpVal = bufPtr[0] - var2;
+		int tmpVal = bufPtr[0] - var3;
 		if (tmpVal < 0)
 			bufPtr[0] = 0;
 		else
@@ -654,19 +655,19 @@ void LilliputScript::computeOperation(byte *bufPtr, int oper, int var2) {
 		}
 		break;
 	case '*': {
-		int tmpVal = bufPtr[0] * var2;
+		int tmpVal = bufPtr[0] * var3;
 		bufPtr[0] = tmpVal & 0xFF;
 		}
 		break;
 	case '/': {
-		if (var2 != 0)
-			bufPtr[0] /= var2;
+		if (var3 != 0)
+			bufPtr[0] /= var3;
 		}
 		break;
 	default: {
 		warning("computeOperation : oper %d", oper);
-		if (var2 != 0) {
-			int tmpVal = bufPtr[0] / var2;
+		if (var3 != 0) {
+			int tmpVal = bufPtr[0] / var3;
 			if (tmpVal < 0)
 				bufPtr[0] = 0xFF;
 			else 
@@ -999,7 +1000,13 @@ byte LilliputScript::OC_for() {
 }
 
 byte LilliputScript::OC_compWord18776() {
-	warning("OC_compWord18776");
+	debugC(1, kDebugScript, "OC_compWord18776()");
+
+	int var1 = _currScript->readUint16LE();
+
+	if (var1 == _word18776)
+		return 1;
+
 	return 0;
 }
 
@@ -1012,9 +1019,14 @@ byte LilliputScript::OC_checkSaveFlag() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub174C8() {
-	warning("OC_sub174C8");
-	return 0;
+byte LilliputScript::OC_compByte16F04() {
+	warning("OC_compByte16F04");
+
+	byte var1 = _byte16F04;
+	uint16 oper = _currScript->readUint16LE();
+	int16 var2 = _currScript->readUint16LE();
+
+	return compareValues(var1, oper, var2);
 }
 
 byte LilliputScript::OC_sub174D8() {
@@ -1230,7 +1242,6 @@ byte LilliputScript::OC_compWord10804() {
 	debugC(1, kDebugScript, "OC_compWord10804()");
 	
 	byte tmpVal = getValue1();
-	
 	if (tmpVal == _word10804)
 		return 1;
 
@@ -1238,11 +1249,22 @@ byte LilliputScript::OC_compWord10804() {
 }
 
 byte LilliputScript::OC_sub17766() {
-	warning("OC_sub17766");
+	debugC(1, kDebugScript, "OC_sub17766()");
+
+	byte var1 = (_currScript->readUint16LE() & 0xFF);
+	if ((var1 == _array12839[_vm->_rulesBuffer2PrevIndx]) && (_array12811[_vm->_rulesBuffer2PrevIndx] != 16))
+		return 1;
+
 	return 0;
 }
+
 byte LilliputScript::OC_sub17782() {
-	warning("OC_sub17782");
+	debugC(1, kDebugScript, "OC_sub17782()");
+
+	byte var1 = (_currScript->readUint16LE() & 0xFF);
+	if ((var1 == _array12839[_vm->_rulesBuffer2PrevIndx]) && (_array12811[_vm->_rulesBuffer2PrevIndx] == 16))
+		return 1;
+
 	return 0;
 }
 
@@ -1605,9 +1627,9 @@ void LilliputScript::OC_sub17B03() {
 
 	byte *bufPtr = getBuffer215Ptr();
 	int oper = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
+	int var3 = _currScript->readUint16LE();
 
-	computeOperation(bufPtr, oper, var2);
+	computeOperation(bufPtr, oper, var3);
 }
 
 void LilliputScript::OC_getRandom_type2() {
@@ -1652,24 +1674,28 @@ void LilliputScript::OC_saveAndQuit() {
 
 void LilliputScript::OC_sub17B93() {
 	debugC(1, kDebugScript, "OC_sub17B93()");
-	int var1 = _currScript->readUint16LE();
 
+	int var1 = _currScript->readUint16LE();
 	sub17B6C(var1);
 }
 
 void LilliputScript::OC_sub17E37() {
 	warning("OC_sub17E37");
 }
+
 void LilliputScript::OC_resetByte1714E() {
 	debugC(1, kDebugScript, "OC_resetByte1714E()");
+
 	_vm->_byte1714E = 0;
 }
+
 void LilliputScript::OC_deleteSavegameAndQuit() {
 	warning("OC_deleteSavegameAndQuit");
 }
 void LilliputScript::OC_incByte16F04() {
 	debugC(1, kDebugScript, "OC_incByte16F04()");
-	_vm->_byte1714E++;
+
+	++_byte16F04;
 }
 
 void LilliputScript::OC_sub17BA5() {
@@ -1677,8 +1703,8 @@ void LilliputScript::OC_sub17BA5() {
 	
 	byte *tmpArr = getBuffer215Ptr();
 	byte oper = (_currScript->readUint16LE() & 0xFF);
-	byte var2 = getBuffer215Ptr()[0];
-	computeOperation(tmpArr, oper, var2);
+	byte var3 = getBuffer215Ptr()[0];
+	computeOperation(tmpArr, oper, var3);
 }
 
 void LilliputScript::OC_setByte18823() {
@@ -1721,8 +1747,11 @@ void LilliputScript::OC_sub17BF2() {
 void LilliputScript::OC_sub17ACC() {
 	warning("OC_sub17ACC");
 }
+
 void LilliputScript::OC_resetByte16F04() {
-	warning("OC_resetByte16F04");
+	debugC(1, kDebugScript, "OC_resetByte16F04()");
+
+	_byte16F04 = 0;
 }
 
 void LilliputScript::OC_sub17AE1() {
@@ -1793,8 +1822,11 @@ void LilliputScript::OC_sub17CB9() {
 void LilliputScript::OC_sub17CD1() {
 	warning("OC_sub17CD1");
 }
+
 void LilliputScript::OC_resetWord16EFE() {
-	warning("OC_resetWord16EFE");
+	debugC(1, kDebugScript, "OC_resetWord16EFE()");
+
+	_vm->_word16EFE = 0xFFFF;
 }
 
 void LilliputScript::OC_sub17CEF() {
@@ -1821,9 +1853,28 @@ void LilliputScript::OC_sub17E6D() {
 void LilliputScript::OC_sub17E7E() {
 	warning("OC_sub17E7E");
 }
+
+byte *LilliputScript::sub173D2() {
+	debugC(2, kDebugScript, "sub173D2()");
+
+	int index = _currScript->readUint16LE();	
+	return &_vm->_ptr_rulesBuffer2_15[index];
+}
+
 void LilliputScript::OC_sub17E99() {
-	warning("OC_sub17E99");
+	debugC(1, kDebugScript, "OC_sub17E99()");
+
+	byte *compBuf = sub173D2();
+	int oper = _currScript->readUint16LE();
+	int index = _currScript->readUint16LE();	
+
+	byte *buf = sub173D2();
+	byte var1 = buf[0];
+	byte var3 = _vm->_rulesChunk11[var1 + _vm->_rulesChunk10[index]];
+
+	computeOperation(compBuf, oper, var3);
 }
+
 void LilliputScript::OC_sub17EC5() {
 	warning("OC_sub17EC5");
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index ff55353..a31a4b6 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -84,7 +84,7 @@ private:
 	byte _byte10806;
 	byte _byte12FE4;
 	byte _byte16F02;
-
+	byte _byte16F04;
 
 	int _word16F00;
 	int _word10804;
@@ -107,6 +107,7 @@ private:
 	void sub18B3C(int var);
 	void sub18BE6(byte var1, int var2, int var4);
 	byte *getMapPtr(int val);
+	byte *sub173D2();
 
 	int getValue1();
 	int getValue2();
@@ -125,7 +126,7 @@ private:
 	byte OC_for();
 	byte OC_compWord18776();
 	byte OC_checkSaveFlag();
-	byte OC_sub174C8();
+	byte OC_compByte16F04();
 	byte OC_sub174D8();
 	byte OC_sub1750E();
 	byte OC_compareCoords_1();


Commit: b9a2c968db63eb43f08a468d383f17f59aa14786
    https://github.com/scummvm/scummvm/commit/b9a2c968db63eb43f08a468d383f17f59aa14786
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement 4 opcodes

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b345ed3..c63a125 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1810,17 +1810,63 @@ void LilliputScript::OC_sub17C76() {
 void LilliputScript::OC_sub17AFC() {
 	warning("OC_sub17AFC");
 }
+
+void LilliputScript::sub171AF(int var1, int var2, int var4) {
+	debugC(2, kDebugScript, "sub171AF()");
+
+	int index = 0;
+	for (int i = 0; i < 10; i++) {
+		if (_vm->_array12861[index + 1] == 0xFFFF) {
+			_vm->_array12861[index + 1] = var1;
+			_vm->_array12861[index + 2] = var2;
+			_vm->_array12861[index + 0] = _vm->_word1289D + var4;
+		}
+		index += 3;
+	}
+}
+
 void LilliputScript::OC_sub17C8B() {
-	warning("OC_sub17C8B");
+	debugC(1, kDebugScript, "OC_sub17C8B()");
+
+	int var1 = 2 << 8;
+	int var4 = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->_rulesBuffer2PrevIndx;
+	
+	sub171AF(var1, var2, var4);
 }
+
 void LilliputScript::OC_sub17CA2() {
-	warning("OC_sub17CA2");
+	debugC(1, kDebugScript, "OC_sub17CA2()");
+
+	int var1 = 1 << 8;
+	int var4 = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->_rulesBuffer2PrevIndx;
+	
+	sub171AF(var1, var2, var4);
 }
+
 void LilliputScript::OC_sub17CB9() {
-	warning("OC_sub17CB9");
+	debugC(1, kDebugScript, "OC_sub17CB9()");
+
+	int var4 = _currScript->readUint16LE();
+	int var1 = getValue1();
+	int var2 = _currScript->readUint16LE();
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->_rulesBuffer2PrevIndx;
+	
+	sub171AF(var1, var2, var4);
 }
+
 void LilliputScript::OC_sub17CD1() {
-	warning("OC_sub17CD1");
+	debugC(1, kDebugScript, "OC_sub17CD1()");
+
+	int var1 = 3 << 8;
+	int var4 = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->_rulesBuffer2PrevIndx;
+	
+	sub171AF(var1, var2, var4);
 }
 
 void LilliputScript::OC_resetWord16EFE() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index a31a4b6..fe8347f 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -108,6 +108,7 @@ private:
 	void sub18BE6(byte var1, int var2, int var4);
 	byte *getMapPtr(int val);
 	byte *sub173D2();
+	void sub171AF(int var1, int var2, int var4);
 
 	int getValue1();
 	int getValue2();


Commit: d65cd866e73e54c4e6971e1ef82d6c988f283e9a
    https://github.com/scummvm/scummvm/commit/d65cd866e73e54c4e6971e1ef82d6c988f283e9a
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement 2 opcodes, fix a duplicate variable detected by SylvainTV

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index bc2a818..2a6c009 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -638,7 +638,7 @@ void LilliputEngine::sub16217() {
 
 		_scriptHandler->_array16123[i] = (_characterPositionX[i] & 0xFF);
 		_scriptHandler->_array1614B[i] = (_characterPositionY[i] & 0xFF);
-		_scriptHandler->_array16173[i] = 0xFF;
+		_characterRelativePositionX[i] = 0xFF;
 		_characterRelativePositionY[i] = 0xFF;
 		_characterDisplayX[i] = 0xFF;
 		_characterDisplayY[i] = 0xFF;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index c63a125..c9c3512 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -66,7 +66,6 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array12839[i] = 0xFF;
 		_array16123[i] = 0;
 		_array1614B[i] = 0;
-		_array16173[i] = 0xFF;
 		_array122C1[i] = 0;
 	}
 
@@ -763,14 +762,15 @@ void LilliputScript::sub16C5C(int index, byte var3) {
 	sub16C86(index, buf);
 }
 
-int LilliputScript::sub17D40(int var) {
-	debugC(1, kDebugScript, "sub17D40(%d)", var);
+void LilliputScript::sub17D40(bool &forceReturnFl) {
+	debugC(1, kDebugScript, "sub17D40()");
 
-	if ((displayMap != 1) && (_array16173[_vm->_rulesBuffer2PrevIndx] != 0xFF))
-		return var;
+	forceReturnFl = false;
+	if ((displayMap != 1) && (_vm->_characterRelativePositionX[_vm->_rulesBuffer2PrevIndx] != 0xFF))
+		return;
 
-	warning("sub17D40() - FIXME: Unexpected POP");
-	return var;
+	forceReturnFl = true;
+	return;
 }
 
 void LilliputScript::sub18A56(byte *buf) {
@@ -1575,7 +1575,9 @@ void LilliputScript::OC_sub17D57() {
 
 	int curWord = _currScript->readUint16LE();
 
-	if((displayMap == 1) || (_array16173[_vm->_rulesBuffer2PrevIndx] == 0xFF))
+	bool forceReturnFl = false;
+	sub17D40(forceReturnFl);
+	if (forceReturnFl)
 		return;
 
 	_word1881B = _vm->_rulesBuffer2PrevIndx;
@@ -1583,9 +1585,51 @@ void LilliputScript::OC_sub17D57() {
 
 }
 
+void LilliputScript::sub18B7C(int var1, int var3) {
+	debugC(2, kDebugScript, "sub18B7C(%d, %d)", var1, var3);
+
+	if (var1 == 0xFFFF) 
+		return;
+
+	_word18776 = var1;
+	int index = _vm->_rulesChunk3[var1];
+
+	while (_vm->_rulesChunk4[index] == 91)
+		++index;
+
+	for (int i = 0; i < var3; i++) {
+		int tmpVal = 93;
+		while (tmpVal == 93) {
+			tmpVal = _vm->_rulesChunk4[index];
+			++index;
+		}
+	}
+	
+	if (_vm->_rulesChunk4[index] == 0)
+		return;
+
+	sub18A56(&_vm->_rulesChunk4[index]);
+}
+
 void LilliputScript::OC_sub17D7F() {
-	warning("OC_sub17D7F");
+	debugC(1, kDebugScript, "OC_sub17D7F()");
+
+	int var1 = getBuffer215Ptr()[0];
+	int var2 = (_currScript->readUint16LE() & 0xFF);
+	int var3 = var1 / var2;
+	
+	var1 = _currScript->readUint16LE();
+
+	bool forceReturnFl = false;
+	sub17D40(forceReturnFl);
+	if (forceReturnFl)
+		return;
+
+	_word1881B = _vm->_rulesBuffer2PrevIndx;
+
+	sub18B7C(var1, var3);
 }
+
 void LilliputScript::OC_sub17DB9() {
 	warning("OC_sub17DB9");
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index fe8347f..19094e8 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -43,7 +43,6 @@ public:
 	byte _array122E9[20];
 	byte _array16123[40];
 	byte _array1614B[40];
-	byte _array16173[40];
 	byte _array12811[40];
 	byte _array10AB1[40];
 	byte _array122FD[20];
@@ -102,13 +101,14 @@ private:
 	void sub17B6C(int var1);
 	void sub16C86(int index, byte *buf);
 	void sub16C5C(int index, byte var3);
-	int sub17D40(int var);
+	void sub17D40(bool &forceReturnFl);
 	void sub18A56(byte *buf);
 	void sub18B3C(int var);
 	void sub18BE6(byte var1, int var2, int var4);
 	byte *getMapPtr(int val);
 	byte *sub173D2();
 	void sub171AF(int var1, int var2, int var4);
+	void sub18B7C(int var1, int var3);
 
 	int getValue1();
 	int getValue2();


Commit: 2462b8d340c5345d4d2b18b138888cf9399ee902
    https://github.com/scummvm/scummvm/commit/2462b8d340c5345d4d2b18b138888cf9399ee902
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 2a6c009..a3e0217 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -636,8 +636,8 @@ void LilliputEngine::sub16217() {
 			_characterPositionY[i] = var4;
 		}
 
-		_scriptHandler->_array16123[i] = (_characterPositionX[i] & 0xFF);
-		_scriptHandler->_array1614B[i] = (_characterPositionY[i] & 0xFF);
+		_scriptHandler->_array16123[i] = _characterPositionX[i] >> 3;
+		_scriptHandler->_array1614B[i] = _characterPositionY[i] >> 3;
 		_characterRelativePositionX[i] = 0xFF;
 		_characterRelativePositionY[i] = 0xFF;
 		_characterDisplayX[i] = 0xFF;


Commit: 6dfec1f58e62ee0f3fe8237bf9460c2542d946b0
    https://github.com/scummvm/scummvm/commit/6dfec1f58e62ee0f3fe8237bf9460c2542d946b0
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Last opcodes1 + first step of script decompiler

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index a3e0217..9afa97a 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2030,6 +2030,8 @@ void LilliputEngine::handleGameScripts() {
 
 	assert(tmpVal < _gameScriptIndexSize);
 	debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index);
+	ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]);
+	//_scriptHandler->disasmScript(script);
 	_scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
 	debugC(1, kDebugEngine, "============= End Game Script %d for character %d ==================", tmpVal, index);
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index c9c3512..2479fed 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -551,6 +551,164 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 	}
 }
 
+enum KValueType {
+	kNone,
+	kImmediateValue,
+	kCompareOperation,
+	kGetValue1,
+	kGetValue2,
+};
+
+
+struct OpCode {
+	const char* _opName;
+	int _numArgs;
+	KValueType _arg1;
+	KValueType _arg2;
+	KValueType _arg3;
+	KValueType _arg4;
+	KValueType _arg5;
+};
+
+static const OpCode opCodes1[] = {
+	{ "OC_sub173DF", 1, kGetValue2, kNone, kNone, kNone, kNone },
+	{ "OC_sub173F0", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },
+	{ "OC_sub1740A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub17434", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
+	{ "OC_sub17468", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_getRandom", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_for", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_compWord18776", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_checkSaveFlag", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_compByte16F04", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub174D8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
+	{ "OC_sub1750E", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
+	{ "OC_compareCoords_1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_compareCoords_2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub1757C", 3, kGetValue2, kCompareOperation, kImmediateValue, kNone, kNone },
+	{ "OC_sub1759E", 3, kGetValue1, kCompareOperation, kImmediateValue, kNone, kNone },
+	{ "OC_compWord16EF8", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_sub175C8", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
+	{ "OC_sub17640", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
+	{ "OC_sub176C4", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
+	{ "OC_compWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_sub17766", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub17782", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub1779E", 4, kGetValue2, kImmediateValue, kImmediateValue, kCompareOperation, kNone },
+	{ "OC_sub177C6", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_compWord16EFE", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub177F5", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub17812", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub17825", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub17844", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub1785C", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
+	{ "OC_sub17886", 1, kGetValue2, kNone, kNone, kNone, kNone },
+	{ "OC_sub178A8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
+	{ "OC_sub178BA", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub178C2", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_sub178D2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub178E8", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
+	{ "OC_sub178FC", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub1790F", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_sub1792A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub1793E", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_sub1795E", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub17984", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_checkSavedMousePos", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_sub179AE", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_sub179C2", 1, kGetValue2, kNone, kNone, kNone, kNone },
+	{ "OC_sub179E5", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub17A07", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
+	{ "OC_sub17757", 1, kGetValue1, kNone, kNone, kNone, kNone },
+};
+
+static const OpCode opCodes2[] = {
+	{ "test", 1, kNone, kNone, kNone, kNone }
+};
+
+void LilliputScript::disasmScript( ScriptStream script) {
+	
+	while(!script.eos()) {
+		uint16 val = script.readUint16LE();
+		if (val == 0xFFF6) // end of script
+			return;
+
+		bool hasIf = false;
+
+		if(val != 0xFFF8) {
+			hasIf = true;
+			debugC(2, kDebugScript, "if (");
+		}
+
+		// check the conditions.
+		while (val != 0xFFF8) {
+
+			bool neg = false;
+
+			if (val > 1000) {
+				val -= 1000;
+				// negative condition
+				neg = true;
+			}
+
+			// op code type 1
+			assert(val < sizeof(opCodes1)/sizeof(OpCode));
+			const OpCode* opCode = &opCodes1[val];
+			const KValueType* opArgType = &opCode->_arg1;
+
+			Common::String str;
+
+			str = "  ";
+			if (neg) str += "not ";
+			str += Common::String(opCode->_opName);
+			str += "(";
+
+			for (int p = 0; p < opCode->_numArgs; p++) {
+				if(*opArgType == kImmediateValue) {
+					str +=  Common::String::format("%d", script.readUint16LE());
+				} else if (*opArgType == kGetValue1) {
+					str += Common::String::format("getValue1(%d)", script.readUint16LE());
+				} else if (*opArgType == kGetValue2) {
+					str += Common::String::format("getValue2(%d)", script.readUint16LE());
+				} else if (*opArgType == kCompareOperation) {
+					int comp = script.readUint16LE();
+					if(comp != '<' && comp != '>')
+						comp = '=';
+					str += Common::String::format("%c", comp );
+				}
+				
+				if(p != opCode->_numArgs - 1)
+					str += ", ";
+
+				opArgType++;
+			}
+			str += ")";
+
+			debugC(2, kDebugScript, str.c_str());
+
+			val = script.readUint16LE();
+			
+		}
+
+		if( hasIf ) {
+			debugC(2, kDebugScript, ")");
+		}
+
+
+		debugC(2, kDebugScript,"{ ");
+
+		while (val != 0xFFF7) {
+			// op code type 2 TODO
+
+			val = script.readUint16LE();
+		}
+
+		debugC(2, kDebugScript,"} ");
+
+	}
+}
+
 int LilliputScript::handleOpcode(ScriptStream *script) {
 	debugC(2, kDebugScript, "handleOpcode");
 	_currScript = script;
@@ -592,6 +750,8 @@ void LilliputScript::runScript(ScriptStream script) {
 		_vm->update();
 }
 
+
+
 void LilliputScript::runMenuScript(ScriptStream script) {
 	debugC(1, kDebugScript, "runMenuScript");
 	warning("========================== Menu Script ==============================");
@@ -1057,8 +1217,17 @@ byte LilliputScript::OC_sub174D8() {
 }
 
 byte LilliputScript::OC_sub1750E() {
-	warning("OC_sub1750E");
-	return 0;
+	debugC(1, kDebugScript, "OC_sub1750E()");
+
+	byte* buf1 = getBuffer215Ptr();
+	int var1 = *buf1;
+
+	int operation = _currScript->readUint16LE();
+
+	byte* buf2 = getBuffer215Ptr();
+	int var2 = *buf2;
+
+	return compareValues(var1, operation, var2);
 }
 
 byte LilliputScript::OC_compareCoords_1() {
@@ -1078,8 +1247,16 @@ byte LilliputScript::OC_compareCoords_1() {
 }
 
 byte LilliputScript::OC_compareCoords_2() {
-	warning("compareCoords_2");
-	return 0;
+	debugC(1, kDebugScript, "OC_compareCoords_2()");
+	int var1 = getValue1();
+	var1 = (_array16123[var1] << 8) + _array1614B[var1];
+	int var2 = _currScript->readUint16LE();
+	int var3 = _vm->_rulesBuffer12_1[var2];
+	int var4 = _vm->_rulesBuffer12_2[var2];
+
+	if (((var1 >> 8) < (var3 >> 8)) || ((var1 >> 8) > (var3 & 0xFF)) || ((var1 & 0xFF) < (var4 >> 8)) || ((var1 & 0xFF) > (var4 & 0xFF)))
+		return 0;
+	return 1;
 }
 byte LilliputScript::OC_sub1757C() {
 	warning("OC_sub1757C");
@@ -1297,7 +1474,7 @@ byte LilliputScript::OC_sub1779E() {
 byte LilliputScript::OC_sub177C6() {
 	debugC(1, kDebugScript, "OC_sub177C6()");
 
-	int index = _currScript->readUint16LE();
+	int index = getValue1();
 	if (_vm->_characterPositionX[index] == 0xFFFF)
 		return 0;
 
@@ -1384,16 +1561,31 @@ byte LilliputScript::OC_sub1785C() {
 }
 
 byte LilliputScript::OC_sub17886() {
-	warning("OC_sub17886");
+	debugC(1, kDebugScript, "OC_sub17886()");
+
+	int var1 = getValue2();
+	int x = var1 >> 8;
+	int y = var1 & 0xFF;
+
+	int dx = x - _viewportX;
+	int dy = y - _viewportY;
+
+	if ( dx >= 0 && dx < 8 && dy >= 0 && dy < 8)
+		return 1;
 	return 0;
 }
 byte LilliputScript::OC_sub178A8() {
-	warning("OC_sub178A8");
+	debugC(1, kDebugScript, "OC_sub178A8()");
+
+	int var1 = getValue1();
+	int var2 = getValue2();
+	if (var1 == var2)
+		return 1;
 	return 0;
 }
 byte LilliputScript::OC_sub178BA() {
-	warning("OC_sub178BA");
-	return 0;
+	_currScript->readUint16LE();
+	return 1;
 }
 
 byte LilliputScript::OC_sub178C2() {
@@ -1491,7 +1683,13 @@ byte LilliputScript::OC_sub1795E() {
 }
 
 byte LilliputScript::OC_sub1796E() {
-	warning("OC_sub1796E");
+	debugC(1, kDebugScript, "OC_sub1796E()");
+
+	int var1 = getValue1();
+	int var2 = _currScript->readUint16LE();
+
+	if (_vm->_rulesBuffer2_9[var1] == var2)
+		return 1;
 	return 0;
 }
 
@@ -1528,11 +1726,25 @@ byte LilliputScript::OC_sub179AE() {
 }
 
 byte LilliputScript::OC_sub179C2() {
-	warning("OC_sub179C2");
+	debugC(1, kDebugScript, "OC_sub179C2()");
+	int var1 = getValue2();
+
+	if (_vm->_array10999[_vm->_rulesBuffer2PrevIndx] == var1 >> 8
+		 && _vm->_array109C1[_vm->_rulesBuffer2PrevIndx] == var1 & 0xFF)
+		return 1;
+
 	return 0;
 }
 byte LilliputScript::OC_sub179E5() {
-	warning("OC_sub179E5");
+	debugC(1, kDebugScript, "OC_sub17A07()");
+
+	static const byte _byte179DB[10] = {0x44, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43};
+
+	int var1 = (_currScript->readUint16LE() & 0xFF) - 0x30;
+	
+	if (_byte179DB[var1] == _vm->_byte16F09)
+		return 1;
+
 	return 0;
 }
 
@@ -1559,7 +1771,12 @@ byte LilliputScript::OC_sub17A07() {
 }
 
 byte LilliputScript::OC_sub17757() {
-	warning("OC_sub17757");
+	debugC(1, kDebugScript, "OC_sub17757()");
+
+	int var1 = getValue1();
+	if ( var1 == _viewportCharacterTarget )
+		return 1;
+	
 	return 0;
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 19094e8..3bb2c92 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -68,6 +68,7 @@ public:
 	LilliputScript(LilliputEngine *vm);
 	~LilliputScript();
 
+	void disasmScript(ScriptStream script);
 	void runScript(ScriptStream script);
 	void runMenuScript(ScriptStream script);
 private:
@@ -93,6 +94,8 @@ private:
 	int handleOpcode(ScriptStream *script);
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
+	
+
 
 	void sub1863B();
 	void sub185ED(byte index, byte subIndex);


Commit: dd8131652822c78d9ce62b63a7ce00c8d5ef455f
    https://github.com/scummvm/scummvm/commit/dd8131652822c78d9ce62b63a7ce00c8d5ef455f
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement some functions related to string display

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 9afa97a..50b19c2 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -509,6 +509,71 @@ void LilliputEngine::displayFunction10() {
 	displayFunction4();
 }
 
+void LilliputEngine::sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex) {
+	debugC(2, kDebugEngine, "sub15A4C()");
+
+	int var3 = 0;
+	int var1;
+	int bckIndex = bufIndex;
+
+	for (;;) {
+		var1 = srcBuf[bufIndex];
+		if ((var1 == 0) || (var1 == '|'))
+			break;
+
+		++bufIndex;
+		++var3;
+	}
+
+	var1 = (0x3D - var3) < 1;
+	vgaIndex += var1;
+
+	bufIndex = bckIndex;
+	for (;;) {
+		var1 = srcBuf[bufIndex];
+		++bufIndex;
+		if ((var1 == 0) || (var1 == '|'))
+			break;
+
+		displayChar(vgaIndex, srcBuf[bufIndex]);
+		vgaIndex += 4;
+	}
+
+}
+
+void LilliputEngine::displayFunction11(byte *buf) {
+	debugC(2, kDebugEngine, "displayFunction11(%s)", buf);
+
+	displayFunction5();
+
+	int vgaIndex = 70;
+	int bufIndex = 0;
+
+	byte _byte15A0C = 0;
+	int var1;
+
+	for (;;) {
+		var1 = buf[bufIndex];
+		++bufIndex;
+		if (var1 == 0) {
+			vgaIndex += (4 * 320);
+			break;
+		} else if (var1 == 0x7C) {
+			_byte15A0C = 1;
+			break;
+		}
+	}
+
+	bufIndex = 0;
+	sub15A4C(vgaIndex, buf, bufIndex);
+	if (_byte15A0C == 1) {
+		vgaIndex += (8 * 320);
+		sub15A4C(vgaIndex, buf, bufIndex);
+	}
+
+	displayFunction4();
+}
+
 void LilliputEngine::displayFunction12() {
 	debugC(1, kDebugEngine, "displayFunction12()");
 
@@ -1209,10 +1274,10 @@ int LilliputEngine::sub16799(int param1, int index) {
 
 }
 
-void LilliputEngine::sub18A3E(byte param1) {
-	debugC(2, kDebugEngine, "sub18A3E(%d)", param1);
+void LilliputEngine::addCharToBuf(byte character) {
+	debugC(2, kDebugEngine, "addCharToBuf(%c)", character);
 
-	_displayStringBuf[_displayStringIndex] = param1;
+	_displayStringBuf[_displayStringIndex] = character;
 	if (_displayStringIndex < 158)
 		++_displayStringIndex;
 }
@@ -1237,10 +1302,10 @@ void LilliputEngine::prepareGoldAmount(int param1) {
 		byte tmpVal = count + 0x30;
 
 		if (i == 4)
-			sub18A3E(tmpVal);
+			addCharToBuf(tmpVal);
 		else if ((count != 0) || (!hideZeros)) {
 			hideZeros = false;
-			sub18A3E(tmpVal);
+			addCharToBuf(tmpVal);
 		}
 	}
 }
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index d49385d..756cc11 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -222,6 +222,7 @@ public:
 	void displayFunction8();
 	void displayFunction9();
 	void displayFunction10();
+	void displayFunction11(byte *buf);
 	void displayFunction12();
 	void displayFunction13(byte *buf, int var1, int var2, int var3);
 	void displayFunction14();
@@ -241,7 +242,7 @@ public:
 	void renderCharacters(byte *buf, int x, int y);
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
-	void sub18A3E(byte param1);
+	void addCharToBuf(byte character);
 	void prepareGoldAmount(int param1);
 	void sub12F37();
 	int sub16675(int idx, int var1);
@@ -263,6 +264,7 @@ public:
 	void sub131FC(int var2, int var4);
 	void sub1546F(byte displayX, byte displayY);
 	void sub15498(byte x, byte y, int var2);
+	void sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 2479fed..9bcc8ad 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -37,7 +37,10 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte12FE4 = 0xFF;
 	_byte16F02 = 0;
 	_byte16F04 = 0;
-
+	_byte1881A = 0;
+	_byte18823 = 0;
+	_byte1881E = 3;
+	_byte1881D = 0;
 	_word1855E = 0;
 	_word16F00 = -1;
 	_viewportCharacterTarget = -1;
@@ -933,8 +936,116 @@ void LilliputScript::sub17D40(bool &forceReturnFl) {
 	return;
 }
 
+void LilliputScript::sub189F5() {
+	debugC(2, kDebugScript, "sub189F5()");
+
+	int index = 0;
+	int var2 = 0x100;
+	int var1;
+
+	for (;;) {
+		var1 = _vm->_displayStringBuf[index];
+		if (var1 == 0)
+			break;
+
+		if (var1 == '|') {
+			var2 &= 0xFF;
+			++var2;
+			continue;
+		}
+
+		var2 += 0x100;
+		if ((var2 >> 8) < 61)
+			continue;
+
+		if ((var2 & 0xFF) == 1) {
+			_vm->_displayStringBuf[index - 1] = 0;
+			break;
+		}
+
+		--index;
+		while (_vm->_displayStringBuf[index] != ' ')
+			--index;
+
+		_vm->_displayStringBuf[index] = '|';
+		++var2;
+		var2 &= 0xFF;
+		++index;
+	}
+}
+
+void LilliputScript::sub189B8() {
+	debugC(2, kDebugScript, "sub189B8()");
+
+	sub189F5();
+	int index = 0;
+
+	for (;;) {
+		if (_vm->_displayStringBuf[index] == 0)
+			break;
+		++index;
+	}
+
+	index /= _byte1881E;
+	index += 4;
+	_byte1881D = index;
+	_vm->displayFunction10();
+	_vm->displayFunction11(_vm->_displayStringBuf);
+}
+
 void LilliputScript::sub18A56(byte *buf) {
-	warning("TODO: sub18A56(buf)");
+	debugC(2, kDebugScript, "sub18A56(buf)");
+
+	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I''ve |can''t |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|''s |''t |re|gg|tt|pp|nn|ay|ar|wh|";
+
+	_vm->_displayStringIndex = 0;
+	_byte1881A = 0;
+	int index = 0;
+	byte var1 = 0;
+	for (;;) {
+		var1 = buf[index];
+		++index;
+		if (var1 == ']')
+			var1 = 0;
+
+		if (var1 < 0x80) {
+			if (var1 == '@') {
+				var1 = buf[index];
+				++index;
+				if (var1 == '#') {
+					_vm->prepareGoldAmount(_byte18823);
+				}
+			} else {
+				_vm->addCharToBuf(var1);
+				if (var1 == 0)
+					break;
+			}
+		} else {
+			int nounIndex = 0;
+			byte var3 = 0xFF - var1;
+			for (int i = 0; i < var3; i++) {
+				for (;;) {
+					var1 = nounsArrayPtr[nounIndex];
+					++nounIndex;
+
+					if (var1 == '|')
+						break;
+				}
+			}
+
+			for (;;) {
+				var1 = nounsArrayPtr[nounIndex];
+				++nounIndex;
+
+				if (var1 == '|')
+					break;
+
+				_vm->addCharToBuf(var1);
+			}
+		}
+	}
+
+	sub189B8();
 }
 
 void LilliputScript::sub18B3C(int var) {
@@ -1729,8 +1840,8 @@ byte LilliputScript::OC_sub179C2() {
 	debugC(1, kDebugScript, "OC_sub179C2()");
 	int var1 = getValue2();
 
-	if (_vm->_array10999[_vm->_rulesBuffer2PrevIndx] == var1 >> 8
-		 && _vm->_array109C1[_vm->_rulesBuffer2PrevIndx] == var1 & 0xFF)
+	if ((_vm->_array10999[_vm->_rulesBuffer2PrevIndx] == (var1 >> 8))
+		 && (_vm->_array109C1[_vm->_rulesBuffer2PrevIndx] == (var1 & 0xFF)))
 		return 1;
 
 	return 0;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 3bb2c92..8356f92 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -85,6 +85,10 @@ private:
 	byte _byte12FE4;
 	byte _byte16F02;
 	byte _byte16F04;
+	byte _byte1881A;
+	byte _byte18823;
+	byte _byte1881E;
+	byte _byte1881D;
 
 	int _word16F00;
 	int _word10804;
@@ -95,8 +99,6 @@ private:
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 	
-
-
 	void sub1863B();
 	void sub185ED(byte index, byte subIndex);
 	void sub185B4_display();
@@ -112,6 +114,8 @@ private:
 	byte *sub173D2();
 	void sub171AF(int var1, int var2, int var4);
 	void sub18B7C(int var1, int var3);
+	void sub189B8();
+	void sub189F5();
 
 	int getValue1();
 	int getValue2();


Commit: 974c223a43bb490ee7602ee1cfbd36d3e11b13a8
    https://github.com/scummvm/scummvm/commit/974c223a43bb490ee7602ee1cfbd36d3e11b13a8
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Split palette functions, implement some core functions

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 50b19c2..834eeb7 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -125,6 +125,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_savedMousePosDivided = 0xFFFF;
 	_skipDisplayFlag1 = 1;
 	_skipDisplayFlag2 = 0;
+	_displayMap = 0;
 
 	_scriptHandler = new LilliputScript(this);
 	_soundHandler = new LilliputSound(this);
@@ -450,7 +451,7 @@ void LilliputEngine::displayFunction7() {
 void LilliputEngine::displayFunction8() {
 	debugC(2, kDebugEngine, "displayFunction8()");
 
-	if (_scriptHandler->displayMap == 1)
+	if (_displayMap == 1)
 		return;
 
 	displayFunction5();
@@ -617,7 +618,7 @@ void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3)
 void LilliputEngine::displayFunction14() {
 	debugC(2, kDebugEngine, "displayFunction14()");
 
-	if (_scriptHandler->displayMap == 1)
+	if (_displayMap == 1)
 		return;
 
 	if (_mouseDisplayX > 48)
@@ -778,8 +779,12 @@ void LilliputEngine::displayFunction15() {
 void LilliputEngine::displayFunction16() {
 	debugC(2, kDebugEngine, "displayFunction16()");
 
-	if (_scriptHandler->displayMap == 1) {
-		warning("sub_15F31");
+	if (_displayMap == 1) {
+		bool forceReturnFl = false;
+		sub15F31(forceReturnFl);
+		if (forceReturnFl)
+			return;
+
 		restoreMapPoints();
 		sub16626();
 		sub12F37();
@@ -803,8 +808,46 @@ void LilliputEngine::displayFunction16() {
 	}
 }
 
-int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
-{
+void LilliputEngine::sub1863B() {
+	_arr18560[0]._field0 = 0;
+	_arr18560[1]._field0 = 0;
+	_arr18560[2]._field0 = 0;
+	_arr18560[3]._field0 = 0;
+	_scriptHandler->_word1855E = 0;
+}
+
+void LilliputEngine::paletteFadeOut() {
+	debugC(2, kDebugEngine, "paletteFadeOut()");
+
+	sub1863B();
+	byte palette[768];
+	for (int fade = 256; fade >= 0;	fade -= 8) {
+		for (int i = 0; i < 768; i++) {
+			palette[i] = (_curPalette[i] * fade) >> 8;
+		}
+		_system->getPaletteManager()->setPalette(palette, 0, 256);
+		_system->updateScreen();
+		_system->delayMillis(20);
+	}
+}
+
+void LilliputEngine::paletteFadeIn() {
+	debugC(2, kDebugEngine, "paletteFadeIn()");
+
+	byte palette[768];
+	for (int fade = 8; fade <= 256;	fade += 8) {
+		for (int i = 0; i < 768; i++) {
+			palette[i] = (_curPalette[i] * fade) >> 8;
+		}
+		_system->getPaletteManager()->setPalette(palette, 0, 256);
+		_system->updateScreen();
+		_system->delayMillis(20);
+	}
+}
+
+int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
+	debugC(2, kDebugEngine, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);
+
 	byte *isoMap = _bufferIsoMap + (x1 << 8) + (y1 << 2) + 1;
 
 	int dx = x2 - x1;
@@ -868,6 +911,57 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2)
 	return 1;
 }
 
+void LilliputEngine::sub15F75() {
+	debugC(2, kDebugEngine, "sub15F75()");
+
+	_byte129A0 = 0xFF;
+	_savedMousePosDivided = 0xFFFF;
+	byte newX = _mouseX >> 2; 
+	byte newY = _mouseY / 3;
+
+	if ((newX >= 64) || (newY >= 64))
+		return;
+	
+	_savedMousePosDivided = (newX << 8) + newY;
+	_byte16F07_menuId = 5;
+}
+
+void LilliputEngine::sub130B6() {
+	debugC(2, kDebugEngine, "sub130B6()");
+
+	for (int index = 0; index < _word12F68_ERULES; index++) {
+		if (_scriptHandler->_array122E9[index] == 3)
+			_scriptHandler->_array122E9[index] = 2;
+	}
+}
+
+void LilliputEngine::sub15F31(bool &forceReturnFl) {
+	debugC(2, kDebugEngine, "sub15F31()");
+
+	forceReturnFl = false;
+	if (_displayMap != 1)
+		return;
+
+	pollEvent();
+	warning("sub15F31- TODO: Check keyboard");
+
+	if ((_mouseButton & 1) == 0)
+		return;
+
+	_mouseButton = 0;
+	sub15F75();
+	
+	_displayMap = 0;
+	paletteFadeOut();
+	_word15AC2 = 0;
+	sub130B6();
+	displayFunction12();
+	_scriptHandler->_heroismLevel = 0;
+	sub16217();
+	paletteFadeIn();
+	forceReturnFl = true;
+}
+
 void LilliputEngine::sub16CA0() {
 	debugC(2, kDebugEngine, "sub16CA0()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 756cc11..e9b4695 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -123,6 +123,7 @@ public:
 
 	bool _saveFlag;
 	bool _int8installed;
+	byte _displayMap;
 
 	int _word10800_ERULES;
 	int _numCharacters;
@@ -232,6 +233,11 @@ public:
 	void displayFunction18(int index, int x, int y, int flags);
 	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
+	void sub130B6();
+	void sub15F75();
+	void sub1863B();
+	void paletteFadeOut();
+	void paletteFadeIn();
 
 	void sortCharacters();
 	void scrollToViewportCharacterTarget();
@@ -265,6 +271,7 @@ public:
 	void sub1546F(byte displayX, byte displayY);
 	void sub15498(byte x, byte y, int var2);
 	void sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex);
+	void sub15F31(bool &forceReturnFl);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 9bcc8ad..6b57693 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -30,7 +30,6 @@ namespace Lilliput {
 
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 	_byte129A0 = 0xFF;
-	displayMap = 0;
 	_byte1855D = 0;
 	_byte12A04 = 0;
 	_byte10806 = 0;
@@ -764,14 +763,6 @@ void LilliputScript::runMenuScript(ScriptStream script) {
 		_vm->update();
 }
 
-void LilliputScript::sub1863B() {
-	_vm->_arr18560[0]._field0 = 0;
-	_vm->_arr18560[1]._field0 = 0;
-	_vm->_arr18560[2]._field0 = 0;
-	_vm->_arr18560[3]._field0 = 0;
-	_word1855E = 0;
-}
-
 void LilliputScript::sub185ED(byte index, byte subIndex) {
 	debugC(2, kDebugScript, "sub185ED");
 	if (_vm->_arr18560[index]._field0 != 1)
@@ -929,7 +920,7 @@ void LilliputScript::sub17D40(bool &forceReturnFl) {
 	debugC(1, kDebugScript, "sub17D40()");
 
 	forceReturnFl = false;
-	if ((displayMap != 1) && (_vm->_characterRelativePositionX[_vm->_rulesBuffer2PrevIndx] != 0xFF))
+	if ((_vm->_displayMap != 1) && (_vm->_characterRelativePositionX[_vm->_rulesBuffer2PrevIndx] != 0xFF))
 		return;
 
 	forceReturnFl = true;
@@ -2472,30 +2463,17 @@ void LilliputScript::OC_sub182EC() {
 void LilliputScript::OC_PaletteFadeOut() {
 	debugC(1, kDebugScript, "OC_PaletteFadeOut()");
 
-	sub1863B();
-	byte palette[768];
-	for (int fade = 256; fade >= 0;	fade -= 8) {
-		for (int i = 0; i < 768; i++) {
-			palette[i] = (_vm->_curPalette[i] * fade) >> 8;
-		}
-		_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
-		_vm->_system->updateScreen();
-		_vm->_system->delayMillis(20);
-	}
+	_byte12A09 = 1;
+	_vm->paletteFadeOut();
+	_byte12A09 = 0;
 }
 
 void LilliputScript::OC_PaletteFadeIn() {
 	debugC(1, kDebugScript, "OC_PaletteFadeIn()");
 
-	byte palette[768];
-	for (int fade = 8; fade <= 256;	fade += 8) {
-		for (int i = 0; i < 768; i++) {
-			palette[i] = (_vm->_curPalette[i] * fade) >> 8;
-		}
-		_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
-		_vm->_system->updateScreen();
-		_vm->_system->delayMillis(20);
-	}
+	_byte12A09 = 1;
+	_vm->paletteFadeIn();
+	_byte12A09 = 0;
 }
 
 void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
@@ -2594,7 +2572,7 @@ void LilliputScript::OC_sub1847F() {
 	int var2 = _currScript->readUint16LE();
 	int var4 = _currScript->readUint16LE();
 
-	if (displayMap != 1) {
+	if (_vm->_displayMap != 1) {
 		_vm->displayFunction5();
 		sub18BE6(var1 & 0xFF, var2, var4);
 		_vm->displayFunction4();
@@ -2667,7 +2645,7 @@ void LilliputScript::OC_sub1853B() {
 	debugC(1, kDebugScript, "OC_sub1853B()");
 
 	OC_PaletteFadeOut();
-	displayMap = 0;
+	_vm->_displayMap = 0;
 	_heroismLevel = 0;
 	sub130B6();
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 8356f92..9cd0899 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -35,7 +35,6 @@ class LilliputEngine;
 
 class LilliputScript {
 public:
-	byte displayMap;
 	byte _byte12A04;
 	byte _heroismLevel;
 
@@ -57,6 +56,7 @@ public:
 	int _word1881B;
 	int _heroismBarX;
 	int _heroismBarBottomY;
+	int _word1855E;
 
 	short _array12311[640];
 	byte _array128EF[40];
@@ -92,14 +92,12 @@ private:
 
 	int _word16F00;
 	int _word10804;
-	int _word1855E;
 	int _word18776;
 
 	int handleOpcode(ScriptStream *script);
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 	
-	void sub1863B();
 	void sub185ED(byte index, byte subIndex);
 	void sub185B4_display();
 	void sub1823E(byte var1, byte var2, byte *curBufPtr);


Commit: 6eccd8e6f35ed1b172d831e4b7457139163cde85
    https://github.com/scummvm/scummvm/commit/6eccd8e6f35ed1b172d831e4b7457139163cde85
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add a couple of missing debugC

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 834eeb7..4b2e5c0 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -638,6 +638,8 @@ void LilliputEngine::displayFunction14() {
 }
 
 void LilliputEngine::restoreMapPoints() {
+	debugC(2, kDebugEngine, "restoreMapPoints()");
+
 	displayFunction5();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
@@ -649,6 +651,8 @@ void LilliputEngine::restoreMapPoints() {
 }
 
 void LilliputEngine::displayCharactersOnMap() {
+	debugC(2, kDebugEngine, "displayCharactersOnMap()");
+
 	sub16217();
 	displayFunction5();
 


Commit: 802305799994b6ef33287a24bafd8ffdba0f861e
    https://github.com/scummvm/scummvm/commit/802305799994b6ef33287a24bafd8ffdba0f861e
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement some more opcodes

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 4b2e5c0..75c1faf 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -126,6 +126,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_skipDisplayFlag1 = 1;
 	_skipDisplayFlag2 = 0;
 	_displayMap = 0;
+	_debugFlag = 0;
+	_byte14837 = 0;
 
 	_scriptHandler = new LilliputScript(this);
 	_soundHandler = new LilliputSound(this);
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index e9b4695..97828f2 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -106,6 +106,8 @@ public:
 	byte _byte12FE3;
 	byte _byte16F08;
 	byte _byte15EAD;
+	byte _debugFlag; // Mostly useless, as the associated functions are empty
+	byte _byte14837; // Unused byte, set by an opcode
 
 	byte _array147D1[3];
 	byte _buffer1[45056];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 6b57693..18aef22 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -467,7 +467,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub18387();
 		break;
 	case 0x4B:
-		OC_setByte14835();
+		OC_setDebugFlag();
 		break;
 	case 0x4C:
 		OC_setByte14837();
@@ -2342,11 +2342,20 @@ void LilliputScript::OC_sub1801D() {
 void LilliputScript::OC_sub1805D() {
 	warning("OC_sub1805D");
 }
+
 void LilliputScript::OC_sub18074() {
-	warning("OC_sub18074");
+	debugC(1, kDebugScript, "OC_sub18074()");
+
+	int var2 = _currScript->readUint16LE();
+	byte var1 = (_currScript->readUint16LE() & 0xFF);
+
+	_vm->_rulesBuffer2_16[(_vm->_rulesBuffer2PrevIndx * 32) + var2] = var1;
 }
+
 void LilliputScript::OC_sub1808B() {
-	warning("OC_sub1808B");
+	debugC(1, kDebugScript, "OC_sub1808B()");
+
+	_vm->_rulesBuffer2_9[_vm->_rulesBuffer2PrevIndx] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub18099() {
@@ -2451,13 +2460,30 @@ void LilliputScript::OC_sub18213() {
 }
 
 void LilliputScript::OC_sub18252() {
-	warning("OC_sub18252");
+	debugC(1, kDebugScript, "OC_sub18252()");
+
+	int index = getValue1();
+	assert(index < 40);
+
+	_vm->_array12299[index] = 4;
 }
+
 void LilliputScript::OC_sub18260() {
 	warning("OC_sub18260");
 }
+
 void LilliputScript::OC_sub182EC() {
-	warning("OC_sub182EC");
+	debugC(1, kDebugScript, "OC_sub182EC()");
+
+	byte *tmpArr = getBuffer215Ptr();
+
+	byte var1 = (_currScript->readUint16LE() & 0xFF);
+	byte var2 = (_currScript->readUint16LE() & 0xFF);
+
+	if (var2 == 0)
+		tmpArr[0] = (0xFF ^ var1);
+	else
+		tmpArr[0] |= var1;
 }
 
 void LilliputScript::OC_PaletteFadeOut() {
@@ -2487,7 +2513,6 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 	_vm->_bufferCubegfx = _vm->loadVGA(fileName, false);
 	_vm->displayFunction9();
 	_vm->displayFunction15();
-
 }
 
 void LilliputScript::OC_sub1834C() {
@@ -2505,8 +2530,15 @@ void LilliputScript::OC_sub18359() {
 	int var1 = _currScript->readUint16LE();
 	_array122C1[_vm->_rulesBuffer2PrevIndx] = var1;
 }
+
 void LilliputScript::OC_sub18367() {
-	warning("OC_sub18367");
+	debugC(1, kDebugScript, "OC_sub18367()");
+
+	_characterScriptEnabled[_vm->_rulesBuffer2PrevIndx] = 1;
+	_vm->_ptr_rulesBuffer2_15[0] = _array122C1[_vm->_rulesBuffer2PrevIndx];
+	_vm->_ptr_rulesBuffer2_15[1] = 0;
+	_vm->_ptr_rulesBuffer2_15[2] = 0;
+	_vm->_ptr_rulesBuffer2_15[3] = 0;
 }
 
 void LilliputScript::OC_sub17D04() {
@@ -2519,14 +2551,27 @@ void LilliputScript::OC_sub17D04() {
 }
 
 void LilliputScript::OC_sub18387() {
-	warning("OC_sub18387");
+	debugC(1, kDebugScript, "OC_sub18387()");
+
+	int index = getValue1();
+	byte var1 = _currScript->readUint16LE() & 0xFF;
+
+	assert(index < 40);
+	_vm->_rulesBuffer2_10[index] = var1;
 }
-void LilliputScript::OC_setByte14835() {
-	warning("OC_setByte14835");
+
+void LilliputScript::OC_setDebugFlag() {
+	debugC(1, kDebugScript, "OC_setDebugFlag()");
+
+	_vm->_debugFlag = 1;
 }
+
 void LilliputScript::OC_setByte14837() {
-	warning("OC_setByte14837");
+	debugC(1, kDebugScript, "OC_setByte14837()");
+
+	_vm->_byte14837 = 1;
 }
+
 void LilliputScript::OC_sub183A2() {
 	warning("OC_sub183A2");
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 9cd0899..1348bd7 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -251,7 +251,7 @@ private:
 	void OC_sub18367();
 	void OC_sub17D04();
 	void OC_sub18387();
-	void OC_setByte14835();
+	void OC_setDebugFlag();
 	void OC_setByte14837();
 	void OC_sub183A2();
 	void OC_sub183C6();


Commit: 70afb0b9c51877abd7006a6262d85afe0ad4c844
    https://github.com/scummvm/scummvm/commit/70afb0b9c51877abd7006a6262d85afe0ad4c844
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More opcodes2

Building decompiler array for opcode2 at the same time

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 75c1faf..58ce4ef 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2193,10 +2193,17 @@ void LilliputEngine::handleGameScripts() {
 	if (tmpVal == 0xFF)
 		return;
 
+	for (int i = 0; i < _gameScriptIndexSize; i++) {
+		assert(tmpVal < _gameScriptIndexSize);
+		debugC(1, kDebugEngine, "================= Game Script %d ==================", i);
+		ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[i]], _arrayGameScriptIndex[i + 1] - _arrayGameScriptIndex[i]);
+		_scriptHandler->disasmScript(script);
+		debugC(1, kDebugEngine, "============= End Game Script %d ==================", i);
+
+	}
+
 	assert(tmpVal < _gameScriptIndexSize);
 	debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index);
-	ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]);
-	//_scriptHandler->disasmScript(script);
 	_scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
 	debugC(1, kDebugEngine, "============= End Game Script %d for character %d ==================", tmpVal, index);
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 18aef22..d6a35c0 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -557,6 +557,7 @@ enum KValueType {
 	kNone,
 	kImmediateValue,
 	kCompareOperation,
+	kComputeOperation,
 	kGetValue1,
 	kGetValue2,
 };
@@ -584,7 +585,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_checkSaveFlag", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_compByte16F04", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub174D8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
-	{ "OC_sub1750E", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
+	{ "OC_sub1750E", 5, kGetValue1, kImmediateValue, kCompareOperation, kGetValue1, kImmediateValue },
 	{ "OC_compareCoords_1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_compareCoords_2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub1757C", 3, kGetValue2, kCompareOperation, kImmediateValue, kNone, kNone },
@@ -625,8 +626,57 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub17757", 1, kGetValue1, kNone, kNone, kNone, kNone },
 };
 
+
 static const OpCode opCodes2[] = {
-	{ "test", 1, kNone, kNone, kNone, kNone }
+	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_sub17A3E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub17D57", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub17D7F", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
+	{ "OC_sub17DB9", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone }, // todo
+	{ "OC_sub17DF9", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub17E07", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
+	{ "OC_sub17E15", 3, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub17B03", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
+	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
+	{ "OC_sub17A66", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },
+	{ "OC_sub17A8D", 2, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_saveAndQuit", 2, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
+	{ "OC_sub17E37", 0, kNone, kNone, kNone, kNone, kNone },  // todo
+	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },  
+	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },  
+	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
+	{ "OC_sub17BA5", 0, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
+	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
+	{ "OC_sub17BA5", 0, kNone, kNone, kNone, kNone, kNone },  
+	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
+	{ "OC_sub17BB7", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone },  // run script
+	{ "OC_sub17BF2", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone },  // run script then stop
+	{ "OC_sub17ACC", 1, kGetValue2, kNone, kNone, kNone, kNone },  
+	{ "OC_resetByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
+	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
+	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
+	{ "OC_setWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },  
+	{ "OC_sub17C0E", 0, kNone, kNone, kNone, kNone, kNone },  
+ 	{ "OC_sub17C55", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone }, 
+	{ "OC_sub17C76", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17AFC", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17C8B", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub17CA2", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub17CB9", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone }, 
+	{ "OC_sub17CD1", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17CEF", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
+	{ "OC_sub17D1B", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17D23", 2, kImmediateValue, kGetValue2, kNone, kNone, kNone }, 
+	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17E7E", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+	{ "OC_sub17EF4", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17F08", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17F68", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 };
 
 void LilliputScript::disasmScript( ScriptStream script) {
@@ -648,7 +698,7 @@ void LilliputScript::disasmScript( ScriptStream script) {
 
 			bool neg = false;
 
-			if (val > 1000) {
+			if (val >= 1000) {
 				val -= 1000;
 				// negative condition
 				neg = true;
@@ -670,7 +720,23 @@ void LilliputScript::disasmScript( ScriptStream script) {
 				if(*opArgType == kImmediateValue) {
 					str +=  Common::String::format("%d", script.readUint16LE());
 				} else if (*opArgType == kGetValue1) {
-					str += Common::String::format("getValue1(%d)", script.readUint16LE());
+					int val = script.readUint16LE();
+					if(val < 1000) 
+					{ 
+						str += Common::String::format("%d", val);
+					} else if (val > 1004) { 
+						str += Common::String::format("getValue1(%d)", val);
+					} else if ( val == 1000 ) {
+						str += Common::String("_byte129A0");
+					} else if( val == 1001 ) {
+						str += Common::String("characterIndex");
+					} else if( val == 1002 ) {
+						str += Common::String("_word16F00");
+					} else if( val == 1003 ) {
+						str += Common::String("currentCharacter_var6");
+					} else if( val == 1004 ) {
+						str += Common::String("_word10804");
+					}
 				} else if (*opArgType == kGetValue2) {
 					str += Common::String::format("getValue2(%d)", script.readUint16LE());
 				} else if (*opArgType == kCompareOperation) {
@@ -1083,7 +1149,7 @@ int LilliputScript::getValue1() {
 	case 1002:
 		return _word16F00;
 	case 1003:
-		return (int)_vm->_rulesBuffer2_15[6];
+		return (int)_vm->_ptr_rulesBuffer2_15[6];
 	case 1004:
 		return _word10804;
 	default:
@@ -1883,7 +1949,8 @@ byte LilliputScript::OC_sub17757() {
 }
 
 void LilliputScript::OC_setWord18821() {
-	warning("OC_setWord18821");
+	debugC(1, kDebugScript, "OC_setWord18821()");
+	_word18821 = getValue1();
 }
 void LilliputScript::OC_sub17A3E() {
 	warning("OC_sub17A3E");
@@ -2071,7 +2138,9 @@ void LilliputScript::OC_sub17BA5() {
 }
 
 void LilliputScript::OC_setByte18823() {
-	warning("OC_setByte18823");
+	debugC(1, kDebugScript, "OC_setByte18823()");
+	byte *tmpArr = getBuffer215Ptr();
+	_byte18823 = *tmpArr;
 }
 
 void LilliputScript::OC_sub17BB7() {
@@ -2108,7 +2177,12 @@ void LilliputScript::OC_sub17BF2() {
 }
 
 void LilliputScript::OC_sub17ACC() {
-	warning("OC_sub17ACC");
+	debugC(1, kDebugScript, "OC_sub17ACC()");
+
+	int var = getValue2();
+	_vm->_array10999[_vm->_rulesBuffer2PrevIndx] = var >> 8;
+	_vm->_array109C1[_vm->_rulesBuffer2PrevIndx] = var & 0xFF;
+	_vm->_array109E9[_vm->_rulesBuffer2PrevIndx] = 0xFF;
 }
 
 void LilliputScript::OC_resetByte16F04() {
@@ -2168,10 +2242,18 @@ void LilliputScript::OC_sub17C55() {
 	_vm->_rulesBuffer2_7[var2] = var4 & 0xFF;
 }
 void LilliputScript::OC_sub17C76() {
-	warning("OC_sub17C76");
+	debugC(1, kDebugScript, "OC_sub17C76()");
+	
+	int var1 = getValue1();
+	_vm->_rulesBuffer2_5[var1] = 0xFF;
+	_vm->_rulesBuffer2_3[var1] = 0;
+	_characterScriptEnabled[var1] = 1;
+
 }
 void LilliputScript::OC_sub17AFC() {
-	warning("OC_sub17AFC");
+	debugC(1, kDebugScript, "OC_sub17AFC()");
+	int var1 = getValue1();
+	_vm->sub170EE(var1);
 }
 
 void LilliputScript::sub171AF(int var1, int var2, int var4) {
@@ -2254,13 +2336,28 @@ void LilliputScript::OC_sub17D1B() {
 }
 
 void LilliputScript::OC_sub17D23() {
-	warning("OC_sub17D23");
+	debugC(1, kDebugScript, "OC_sub17D23()");
+
+	int var1 = _currScript->readUint16LE();
+	int var2 = getValue2();
+	byte* buf = _vm->_ptr_rulesBuffer2_15 + 4;
+	computeOperation(buf, var1, var2 >> 8);
+	computeOperation(buf + 1, var1, var2 & 0xFF);
 }
 void LilliputScript::OC_sub17E6D() {
-	warning("OC_sub17E6D");
+	debugC(1, kDebugScript, "OC_sub17E6D()");
+	
+	int var1 = _currScript->readUint16LE();
+	_vm->_rulesBuffer2_12[_vm->_rulesBuffer2PrevIndx] = (var1 - 2000) & 0xFF;
 }
 void LilliputScript::OC_sub17E7E() {
-	warning("OC_sub17E7E");
+	debugC(2, kDebugScript, "OC_sub17E7E()");
+
+	int var1 = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+	_vm->_rulesBuffer2_4[_vm->_rulesBuffer2PrevIndx] = var1;
+	_vm->_rulesBuffer2_8[_vm->_rulesBuffer2PrevIndx] = var2;
+
 }
 
 byte *LilliputScript::sub173D2() {
@@ -2285,16 +2382,63 @@ void LilliputScript::OC_sub17E99() {
 }
 
 void LilliputScript::OC_sub17EC5() {
+	//debugC(1, kDebugScript, "OC_sub17EC5()");
 	warning("OC_sub17EC5");
+	/*byte *compBuf = sub173D2();
+	int oper = _currScript->readUint16LE();
+	int index = _currScript->readUint16LE();	
+
+	byte *buf = sub173D2();
+	byte var1 = buf[0];
+	byte var3 = _vm->_rulesChunk11[var1 + _vm->_rulesChunk10[index]];
+
+	computeOperation(compBuf, oper, var3);*/
 }
+
+int LilliputScript::sub17285(int index) {
+	return ((_vm->_characterPositionX[index] >> 3) << 8) + (_vm->_characterPositionY[index] >> 3);
+}
+
 void LilliputScript::OC_sub17EF4() {
-	warning("OC_sub17EF4");
+	debugC(1, kDebugScript, "OC_sub17EF4()");
+
+	int var1 = getValue2();
+	int posTile = sub17285(_vm->_rulesBuffer2PrevIndx);
+	int dir = _vm->sub16B0C(posTile, var1);
+	_vm->_rulesBuffer2_9[_vm->_rulesBuffer2PrevIndx] = dir;
+
 }
 void LilliputScript::OC_sub17F08() {
-	warning("OC_sub17F08");
+	debugC(1, kDebugScript, "OC_sub17F08()");
+	
+	int var1 = getValue1();
+
+	static const byte _array16B04[] = { 0, 2, 0, 1, 3, 2, 3, 1 };
+
+	int dx = _vm->_characterPositionX[var1] - _vm->_characterDisplayX[_vm->_rulesBuffer2PrevIndx];
+	int dy = _vm->_characterPositionY[var1] - _vm->_characterDisplayY[_vm->_rulesBuffer2PrevIndx];
+
+	int flag = 0;
+	if (dx < 0) {
+		dx = -dx;
+		flag |= 4;
+	}
+	if (dy < 0) {
+		dy = -dy;
+		flag |= 2;
+	} 
+	if (dx < dy) {
+		flag |= 1;
+	}
+
+	_vm->_rulesBuffer2_9[_vm->_rulesBuffer2PrevIndx] = _array16B04[flag];
 }
+
 void LilliputScript::OC_sub17F4F() {
-	warning("OC_sub17F4F");
+	debugC(1, kDebugScript, "OC_sub17F4F()");
+	int var = getValue1();
+	_array10A39[_vm->_rulesBuffer2PrevIndx] = var;
+	_vm->_array109E9[_vm->_rulesBuffer2PrevIndx] = 0xFF;
 }
 void LilliputScript::OC_sub17F68() {
 	warning("OC_sub17F68");
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 1348bd7..24063e4 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -46,6 +46,7 @@ public:
 	byte _array10AB1[40];
 	byte _array122FD[20];
 	byte _array122C1[40];
+	byte _array10A39[40];
 	short _array10B51[40 * 40];
 
 	byte *_savedBuffer215Ptr;
@@ -93,6 +94,7 @@ private:
 	int _word16F00;
 	int _word10804;
 	int _word18776;
+	int _word18821;
 
 	int handleOpcode(ScriptStream *script);
 	byte handleOpcodeType1(int curWord);
@@ -114,6 +116,7 @@ private:
 	void sub18B7C(int var1, int var3);
 	void sub189B8();
 	void sub189F5();
+	int sub17285(int index);
 
 	int getValue1();
 	int getValue2();


Commit: 7320966cd7b8f612424cb1fa2898e9fb7c79f934
    https://github.com/scummvm/scummvm/commit/7320966cd7b8f612424cb1fa2898e9fb7c79f934
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: fix (?) a couple of things in 16626, implement several core functions

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 58ce4ef..53e3f24 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -168,6 +168,11 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
 
+	_array16C54[0] = _array16C54[3] = 1;
+	_array16C54[1] = _array16C54[2] = 2;
+	_array16C54[2] = _array16C54[1] = 4;
+	_array16C54[3] = _array16C54[0] = 8;
+
 	for (int i = 0; i < 3; i++)
 		_array147D1[i] = 0;
 
@@ -290,7 +295,6 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
-
 void LilliputEngine::displayFunction18(int index, int x, int y, int flags) {
 	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d, %d)", index, x, y, flags);
 
@@ -1422,7 +1426,7 @@ void LilliputEngine::sub16626() {
 			if (var2 == 16)
 				break;
 
-			var2 = (2 * var2) + (index << 5);
+			var2 = (2 * (var2 & 0xFF)) + (index << 5);
 			int var1 = _scriptHandler->_array12311[var2 / 2];
 			int tmpVal = var2;
 			var2 = ((var1 >> 8) >> 3);
@@ -1464,11 +1468,11 @@ void LilliputEngine::sub16626() {
 				warning("result = sub_166EA");
 				break;
 			default:
-				error("sub16626 - unexpected value %d", var2 / 2);
+				warning("sub16626 - unexpected value %d", var2 / 2);
 				break;
 			}
 
-			if (result & 1) {
+			if ((result & 1) == 0) {
 				++_scriptHandler->_array12811[index];
 				if (_scriptHandler->_array12811[index] == 16)
 					_scriptHandler->_characterScriptEnabled[index] = 1;
@@ -1680,41 +1684,40 @@ int LilliputEngine::sub16685(int idx, int var1) {
 int LilliputEngine::sub16675(int idx, int var1) {
 	debugC(2, kDebugEngine, "sub16675(%d, %d)", idx, var1);
 
-	warning("sub16675(%d, %d)", idx, var1);
 	int index = sub16685(idx, var1);
 
 	switch (index) {
 	case 0:
 		break;
 	case 1:
-		warning("sub_166B1");
+		sub166B1(index);
 		break;
 	case 2:
-		warning("sub_166B6");
+		sub166B6(index);
 		break;
 	case 3:
-		warning("sub_166BB");
+		sub166BB(index);
 		break;
 	case 4:
-		warning("sub_16B63");
+		sub16B63(index);
 		break;
 	case 5:
-		warning("sub_16B76");
+		sub16B76(index);
 		break;
 	case 6:
-		warning("sub_166C0");
+		sub166C0(index);
 		break;
 	case 7:
-		warning("sub_166C6");
+		sub166C6(index);
 		break;
 	case 8:
-		warning("sub_166CC");
+		sub166CC(index);
 		break;
 	case 9:
-		warning("sub_166D2");
+		sub166D2(index);
 		break;
 	case 10:
-		warning("sub_166D8");
+		sub166D8(index);
 		break;
 	default:
 		warning("sub16675 - Unexpected value %d", index);
@@ -1723,6 +1726,159 @@ int LilliputEngine::sub16675(int idx, int var1) {
 	return 0;
 }
 
+void LilliputEngine::sub16B63(int index) {
+	debugC(2, kDebugEngine, "sub16B63(%d)", index);
+
+	static const byte nextFrame[4] = {1, 3, 0, 2};
+	_rulesBuffer2_9[index] = nextFrame[_rulesBuffer2_9[index]];
+}
+
+void LilliputEngine::sub16B76(int index) {
+	debugC(2, kDebugEngine, "sub16B76(%d)", index);
+
+	static const byte nextFrame[4] = {2, 0, 3, 1};
+	_rulesBuffer2_9[index] = nextFrame[_rulesBuffer2_9[index]];
+}
+
+void LilliputEngine::sub166C0(int index) {
+	debugC(2, kDebugEngine, "sub166C0(%d)", index);
+
+	_rulesBuffer2_3[index] += 1;
+}
+
+void LilliputEngine::sub166C6(int index) {
+	debugC(2, kDebugEngine, "sub166C6(%d)", index);
+
+	_rulesBuffer2_3[index] += 2;
+}
+
+void LilliputEngine::sub166CC(int index) {
+	debugC(2, kDebugEngine, "sub166CC(%d)", index);
+
+	_rulesBuffer2_3[index] -= 1;
+}
+
+void LilliputEngine::sub166D2(int index) {
+	debugC(2, kDebugEngine, "sub166D2(%d)", index);
+
+	_rulesBuffer2_3[index] -= 2;
+}
+
+void LilliputEngine::sub166B1(int index) {
+	debugC(2, kDebugEngine, "sub166B1(%d)", index);
+
+	sub16B31(index, 2);
+}
+
+void LilliputEngine::sub166B6(int index) {
+	debugC(2, kDebugEngine, "sub166B6(%d)", index);
+
+	sub16B31(index, 4);
+}
+
+void LilliputEngine::sub166BB(int index) {
+	debugC(2, kDebugEngine, "sub166BB(%d)", index);
+
+	sub16B31(index, 0xFE);
+}
+
+void LilliputEngine::sub166D8(int index) {
+	debugC(2, kDebugEngine, "sub166D8(%d)", index);
+
+	sub16B31(index, 3);
+}
+
+void LilliputEngine::sub16B31(int index, int val) {
+	debugC(2, kDebugEngine, "sub16B31(%d, %d)", index, val);
+
+	int newX = _characterPositionX[index];
+	int newY = _characterPositionY[index];
+	switch (_rulesBuffer2_9[index]) {
+	case 0:
+		newX += val;
+		break;
+	case 1:
+		newY -= val;
+		break;
+	case 2:
+		newY += val;
+		break;
+	default:
+		newX -= val;
+		break;
+	}
+	sub16B8F(index, newX, newY, _rulesBuffer2_9[index]);
+}
+
+void LilliputEngine::sub16B8F(int index, int x, int y, int flag) {
+	debugC(2, kDebugEngine, "sub16B8F(%d, %d, %d)", index, x, y);
+
+	int diffX = x >> 3;
+	if (((diffX & 0xFF) == _scriptHandler->_array16123[index]) && ((y >> 3) == _scriptHandler->_array1614B[index])) {
+		_characterPositionX[index] = x;
+		_characterPositionY[index] = y;
+	}
+
+	if ((x < 0) || (x >= 512) || (y < 0) || (y >= 512))
+		return;
+
+	int mapIndex = (_scriptHandler->_array1614B[index] << 6) + _scriptHandler->_array16123[index];
+	mapIndex <<= 2;
+
+	if ((_bufferIsoMap[mapIndex + 3] & _array16C58[flag]) == 0)
+		return;
+
+	mapIndex = ((y & 0xFFF8) << 3) + diffX;
+	mapIndex <<= 2;
+
+	if ((_bufferIsoMap[mapIndex + 3] & _array16C54[flag]) == 0)
+		return;
+
+	int var1 = _rulesBuffer2_10[index];
+	var1 &= 7;
+	var1 ^= 7;
+
+	if ((var1 & _rulesChunk9[_bufferIsoMap[mapIndex]]) != 0)
+		return;
+
+	_characterPositionX[index] = x;
+	_characterPositionY[index] = y;
+}
+
+void LilliputEngine::sub17224(int var1, int var4) {
+	debugC(2, kDebugEngine, "sub17224(%d, %d)", var1, var4);
+
+	byte type = (var1 >> 8);
+	if (type == 0) {
+		sub17264(var1, var4);
+		return;
+	}
+	
+	if (type == 3) {
+		for (int i = _numCharacters - 1; i >= 0; i--)
+			sub17264(i, var4);
+		return;
+	}
+
+	int index = var4 & 0xFF;
+	for (int i = 0; i < _numCharacters; i++) {
+		if (_scriptHandler->_array10B51[index] >= type)
+			sub17264(i, var4);
+		index += 40;
+	}
+}
+
+void LilliputEngine::sub17264(int index, int var4) {
+	debugC(2, kDebugEngine, "sub17264(%d, %d)", index, var4);
+
+	if (_array11D49[index] != 0xFFFF) {
+		_array1289F[index] = var4;
+	} else {
+		_scriptHandler->_characterScriptEnabled[index] = 1;
+		_array11D49[index] = var4;
+	}
+}
+
 void LilliputEngine::sub171CF() {
 	debugC(2, kDebugEngine, "sub171CF()");
 
@@ -1742,7 +1898,7 @@ void LilliputEngine::sub171CF() {
 			int var4 = _array12861[(3 * i) + 2];
 			_array12861[(3 * i) + 1] = 0xFFFF;
 
-			warning("sub_17224");
+			sub17224(var1, var4);
 		}
 	}
 }
@@ -2197,7 +2353,7 @@ void LilliputEngine::handleGameScripts() {
 		assert(tmpVal < _gameScriptIndexSize);
 		debugC(1, kDebugEngine, "================= Game Script %d ==================", i);
 		ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[i]], _arrayGameScriptIndex[i + 1] - _arrayGameScriptIndex[i]);
-		_scriptHandler->disasmScript(script);
+//		_scriptHandler->disasmScript(script);
 		debugC(1, kDebugEngine, "============= End Game Script %d ==================", i);
 
 	}
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 97828f2..54f8423 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -201,7 +201,8 @@ public:
 	byte _array109E9[40];
 	byte _array10A11[40];
 	byte _array16E94[40];
-
+	byte _array16C54[4];
+	byte _array16C58[4];
 	byte _buffer1_45k[45056];
 	byte _buffer2_45k[45056];
 	byte _buffer3_45k[45056];
@@ -246,6 +247,8 @@ public:
 	void viewportScrollTo(int var1, int var3);
 	void sub189DE();
 	void sub16626();
+	void sub17224(int var1, int var4);
+	void sub17264(int index, int var4);
 
 	void renderCharacters(byte *buf, int x, int y);
 	int sub16799(int param1, int index);
@@ -274,6 +277,18 @@ public:
 	void sub15498(byte x, byte y, int var2);
 	void sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex);
 	void sub15F31(bool &forceReturnFl);
+	void sub16B63(int index);
+	void sub16B76(int index);
+	void sub166C0(int index);
+	void sub166C6(int index);
+	void sub166CC(int index);
+	void sub166D2(int index);
+	void sub166B1(int index);
+	void sub166B6(int index);
+	void sub166BB(int index);
+	void sub166D8(int index);
+	void sub16B31(int index, int val);
+	void sub16B8F(int index, int x, int y, int flag);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);


Commit: f06dbf19af0c0a120fc7ee490350ebc55bfb27af
    https://github.com/scummvm/scummvm/commit/f06dbf19af0c0a120fc7ee490350ebc55bfb27af
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a bug on 16675

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 53e3f24..d8f3eb3 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1672,21 +1672,19 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	displayFunction8();
 }
 
-int LilliputEngine::sub16685(int idx, int var1) {
+void LilliputEngine::sub16685(int idx, int var1) {
 	debugC(2, kDebugEngine, "sub16685(%d, %d)", idx, var1);
 
 	int index = (idx << 5) + (var1 & 0xFF);
-	byte tmpVal = _rulesBuffer2_16[index];
-	_scriptHandler->_array10AB1[idx] = tmpVal;
-	return var1;
+	_scriptHandler->_array10AB1[idx] = _rulesBuffer2_16[index];
 }
 
 int LilliputEngine::sub16675(int idx, int var1) {
 	debugC(2, kDebugEngine, "sub16675(%d, %d)", idx, var1);
 
-	int index = sub16685(idx, var1);
-
-	switch (index) {
+	sub16685(idx, var1);
+	int index = (var1 & 0xFF);	
+	switch (var1 >> 8) {
 	case 0:
 		break;
 	case 1:
@@ -1720,7 +1718,7 @@ int LilliputEngine::sub16675(int idx, int var1) {
 		sub166D8(index);
 		break;
 	default:
-		warning("sub16675 - Unexpected value %d", index);
+		warning("sub16675 - Unexpected value %d", var1 >> 8);
 	}
 
 	return 0;
@@ -2341,6 +2339,7 @@ void LilliputEngine::handleGameScripts() {
 	_scriptHandler->_characterScriptEnabled[index] = 0;
 	sub170EE(index);
 
+
 	_word16EFE = _array11D49[index];
 	_array11D49[index] = 0xFFFF;
 	_word1817B = 0;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 54f8423..082f6f2 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -257,7 +257,7 @@ public:
 	void prepareGoldAmount(int param1);
 	void sub12F37();
 	int sub16675(int idx, int var1);
-	int sub16685(int idx, int var1);
+	void sub16685(int idx, int var1);
 	void sub16EBC();
 	void sub16CA0();
 	int sub166DD(int index, int var1);


Commit: 8325be0f825ccfd764b54f8d3799ecd4e8796054
    https://github.com/scummvm/scummvm/commit/8325be0f825ccfd764b54f8d3799ecd4e8796054
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Small change

Changed paths:
    engines/lilliput/lilliput.h


diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 082f6f2..029c843 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -247,10 +247,14 @@ public:
 	void viewportScrollTo(int var1, int var3);
 	void sub189DE();
 	void sub16626();
+
 	void sub17224(int var1, int var4);
 	void sub17264(int index, int var4);
 
 	void renderCharacters(byte *buf, int x, int y);
+
+	void sub16553(byte *buf);
+
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
 	void addCharToBuf(byte character);


Commit: ab3b7972e0dfdaa9912b22bb60f581231423032e
    https://github.com/scummvm/scummvm/commit/ab3b7972e0dfdaa9912b22bb60f581231423032e
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add sprite mirroring to fix display of characters looking left

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index d8f3eb3..a021829 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -309,7 +309,7 @@ void LilliputEngine::displayFunction18(int index, int x, int y, int flags) {
 		index -= 0xF0;
 	}
 
-	src += index << 8;
+	src += ((index & 0xFF) << 8) + (index >> 8);
 
 	if ( (flags & 2) == 0 ) {
 		for (int y = 0; y < 16; y++) {
@@ -321,13 +321,13 @@ void LilliputEngine::displayFunction18(int index, int x, int y, int flags) {
 			buf += 256;
 		}
 	} else {
-		src += 14;
+//		src += 14;
 		for (int y = 0; y < 16; y++) {
 			for (int x = 0; x < 16; x++) {
-				if (src[x] != 0)
-					buf[x] = src[x];
+				if (src[15 - x] != 0)
+					buf[x] = src[15 - x];
 			}
-			src += 32;
+			src += 16;
 			buf += 256;
 		}
 	}
@@ -1227,17 +1227,17 @@ void LilliputEngine::viewportScrollTo(int goalX, int goalY) {
 	_soundHandler->contentFct5();
 }
 
-void LilliputEngine::renderCharacters(byte *buf, int x, int y) {
+void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
 	debugC(2, kDebugEngine, "renderCharacters(buf, %d, %d)", x, y);
 
 	if ((_nextDisplayCharacterX != x) || (_nextDisplayCharacterY != y))
 		return;
 
-	bool _byte16552 = 0;
+	byte _byte16552 = 0;
 
 	if (buf[1] != 0xFF) {
 		int tmpIndex = buf[1];
-		if (_rulesChunk9[tmpIndex] == 16)
+		if ((_rulesChunk9[tmpIndex] & 16) == 0)
 			++_byte16552;
 	}
 
@@ -1249,12 +1249,12 @@ void LilliputEngine::renderCharacters(byte *buf, int x, int y) {
 		sub1546F(displayX, displayY);
 
 	if (_byte16552 != 1) {
-		int var3 = _rulesBuffer2_9[index];
+		int flag = _rulesBuffer2_9[index];
 		int frame = _rulesBuffer2_4[index];
 
 		if (frame != 0xFFFF) {
 			frame += _scriptHandler->_array10AB1[index];
-			if (var3 & 1)
+			if ((flag & 1) == 1)
 				frame += _rulesBuffer2_8[index];
 
 			if (_array12299[index] != 0xFF) {
@@ -1263,7 +1263,7 @@ void LilliputEngine::renderCharacters(byte *buf, int x, int y) {
 				frame = -frame;
 			}
 
-			displayFunction18(frame, displayX, displayY, var3);
+			displayFunction18(frame, displayX, displayY, flag);
 		}
 	}
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 029c843..1c15e8a 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -251,7 +251,7 @@ public:
 	void sub17224(int var1, int var4);
 	void sub17264(int index, int var4);
 
-	void renderCharacters(byte *buf, int x, int y);
+	void renderCharacters(byte *buf, byte x, byte y);
 
 	void sub16553(byte *buf);
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index d6a35c0..3186826 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2789,7 +2789,7 @@ void LilliputScript::OC_displayVGAFile() {
 	int curWord = _currScript->readUint16LE();
 	int index = _vm->_rulesChunk3[curWord];
 	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
-	_word1881B = -1;
+	_word1881B = 0xFFFF;
 	_vm->displayVGAFile(fileName);
 	OC_PaletteFadeIn();
 }


Commit: c77a3e2e5184f8ebaf2eb45594c5c9b52bba4675
    https://github.com/scummvm/scummvm/commit/c77a3e2e5184f8ebaf2eb45594c5c9b52bba4675
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index a021829..aee940e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -193,12 +193,12 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_characterPositionX[i] = 0xFFFF;
 		_characterPositionY[i] = 0xFFFF;
 		_rulesBuffer2_3[i] = 0;
-		_rulesBuffer2_4[i] = 0;
+		_characterFrameArray[i] = 0;
 		_rulesBuffer2_5[i] = 0xFF;
 		_rulesBuffer2_6[i] = 4;
 		_rulesBuffer2_7[i] = 0;
-		_rulesBuffer2_8[i] = 20;
-		_rulesBuffer2_9[i] = 0;
+		_spriteSizeArray[i] = 20;
+		_characterDirectionArray[i] = 0;
 		_rulesBuffer2_10[i] = 0;
 		_rulesBuffer2_11[i] = 0;
 		_rulesBuffer2_12[i] = 0;
@@ -295,8 +295,8 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
-void LilliputEngine::displayFunction18(int index, int x, int y, int flags) {
-	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d, %d)", index, x, y, flags);
+void LilliputEngine::displayCharacter(int index, int x, int y, int flags) {
+	debugC(2, kDebugEngine, "displayCharacter(%d, %d, %d, %d)", index, x, y, flags);
 
 	byte *buf = _buffer1_45k + (y << 8) + x;
 
@@ -321,9 +321,10 @@ void LilliputEngine::displayFunction18(int index, int x, int y, int flags) {
 			buf += 256;
 		}
 	} else {
-//		src += 14;
+		// Sprite mirror
 		for (int y = 0; y < 16; y++) {
 			for (int x = 0; x < 16; x++) {
+				// May need a hack of 1 pixel 
 				if (src[15 - x] != 0)
 					buf[x] = src[15 - x];
 			}
@@ -689,11 +690,11 @@ void LilliputEngine::sub16217() {
 			int index2 = _rulesBuffer2_5[i];
 			_rulesBuffer2_3[i] = _rulesBuffer2_3[index2] + _rulesBuffer2_7[i];
 			int tmpVal = _rulesBuffer2_6[i];
-			_rulesBuffer2_9[i] = _rulesBuffer2_9[index2];
+			_characterDirectionArray[i] = _characterDirectionArray[index2];
 			int var3 = _characterPositionX[index2];
 			int var4 = _characterPositionY[index2];
 
-			switch (_rulesBuffer2_9[i]) {
+			switch (_characterDirectionArray[i]) {
 			case 0:
 				var3 -= tmpVal;
 				break;
@@ -1003,7 +1004,7 @@ void LilliputEngine::sub16CA0() {
 							} else if((_rulesBuffer2_11[index] & 4) != 0) {
 								_byte16C9F = 0;
 							} else {
-								if (_rulesBuffer2_9[index] == 0) {
+								if (_characterDirectionArray[index] == 0) {
 									if (d1 > c1) {
 										_byte16C9F = 2;
 
@@ -1013,7 +1014,7 @@ void LilliputEngine::sub16CA0() {
 										if (sub16DD5(c1, d1, c2, d2) != 0)
 											_byte16C9F = 1;
 									}
-								} else if (_rulesBuffer2_9[index] == 1) {
+								} else if (_characterDirectionArray[index] == 1) {
 									if (d2 < c2) {
 										_byte16C9F = 2;
 
@@ -1023,7 +1024,7 @@ void LilliputEngine::sub16CA0() {
 										if (sub16DD5(c1, d1, c2, d2) != 0)
 											_byte16C9F = 1;
 									}
-								} else if (_rulesBuffer2_9[index] == 2) {
+								} else if (_characterDirectionArray[index] == 2) {
 									if (d2 > c2) {
 										_byte16C9F = 2;
 
@@ -1245,17 +1246,20 @@ void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
 	int displayX = _characterDisplayX[index];
 	int displayY = _characterDisplayY[index];
 
+	if ((displayX == 104) && (displayY == 132))
+		warning("");
+
 	if (index == _scriptHandler->_word1881B)
 		sub1546F(displayX, displayY);
 
 	if (_byte16552 != 1) {
-		int flag = _rulesBuffer2_9[index];
-		int frame = _rulesBuffer2_4[index];
+		int flag = _characterDirectionArray[index];
+		int frame = _characterFrameArray[index];
 
 		if (frame != 0xFFFF) {
 			frame += _scriptHandler->_array10AB1[index];
 			if ((flag & 1) == 1)
-				frame += _rulesBuffer2_8[index];
+				frame += _spriteSizeArray[index];
 
 			if (_array12299[index] != 0xFF) {
 				frame = _array12299[index] + 82;
@@ -1263,7 +1267,7 @@ void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
 				frame = -frame;
 			}
 
-			displayFunction18(frame, displayX, displayY, flag);
+			displayCharacter(frame, displayX, displayY, flag);
 		}
 	}
 
@@ -1370,7 +1374,7 @@ int LilliputEngine::sub16799(int param1, int index) {
 	int var1 = (_scriptHandler->_array16123[index] << 8) + _scriptHandler->_array1614B[index];
 	int var2 = (_array109E9[index] << 8) + _array10A11[index];
 
-	_rulesBuffer2_9[index] = sub16B0C(var1, var2);
+	_characterDirectionArray[index] = sub16B0C(var1, var2);
 
 	warning("sub_1693A");
 	_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
@@ -1484,7 +1488,7 @@ void LilliputEngine::sub16626() {
 
 int LilliputEngine::sub166DD(int index, int var1) {
 
-	_rulesBuffer2_9[index] = (var1 >> 8) & 3;
+	_characterDirectionArray[index] = (var1 >> 8) & 3;
 	sub16685(index, var1 & 0xFF);
 	return 0;
 }
@@ -1728,14 +1732,14 @@ void LilliputEngine::sub16B63(int index) {
 	debugC(2, kDebugEngine, "sub16B63(%d)", index);
 
 	static const byte nextFrame[4] = {1, 3, 0, 2};
-	_rulesBuffer2_9[index] = nextFrame[_rulesBuffer2_9[index]];
+	_characterDirectionArray[index] = nextFrame[_characterDirectionArray[index]];
 }
 
 void LilliputEngine::sub16B76(int index) {
 	debugC(2, kDebugEngine, "sub16B76(%d)", index);
 
 	static const byte nextFrame[4] = {2, 0, 3, 1};
-	_rulesBuffer2_9[index] = nextFrame[_rulesBuffer2_9[index]];
+	_characterDirectionArray[index] = nextFrame[_characterDirectionArray[index]];
 }
 
 void LilliputEngine::sub166C0(int index) {
@@ -1791,7 +1795,7 @@ void LilliputEngine::sub16B31(int index, int val) {
 
 	int newX = _characterPositionX[index];
 	int newY = _characterPositionY[index];
-	switch (_rulesBuffer2_9[index]) {
+	switch (_characterDirectionArray[index]) {
 	case 0:
 		newX += val;
 		break;
@@ -1805,7 +1809,7 @@ void LilliputEngine::sub16B31(int index, int val) {
 		newX -= val;
 		break;
 	}
-	sub16B8F(index, newX, newY, _rulesBuffer2_9[index]);
+	sub16B8F(index, newX, newY, _characterDirectionArray[index]);
 }
 
 void LilliputEngine::sub16B8F(int index, int x, int y, int flag) {
@@ -2119,12 +2123,12 @@ void LilliputEngine::loadRules() {
 		_characterPositionY[j] = curWord;
 
 		_rulesBuffer2_3[j] = (f.readUint16LE() & 0xFF);
-		_rulesBuffer2_4[j] = f.readUint16LE();
+		_characterFrameArray[j] = f.readUint16LE();
 		_rulesBuffer2_5[j] = f.readByte();
 		_rulesBuffer2_6[j] = f.readByte();
 		_rulesBuffer2_7[j] = f.readByte();
-		_rulesBuffer2_8[j] = f.readByte();
-		_rulesBuffer2_9[j] = f.readByte();
+		_spriteSizeArray[j] = f.readByte();
+		_characterDirectionArray[j] = f.readByte();
 		_rulesBuffer2_10[j] = f.readByte();
 		_rulesBuffer2_11[j] = f.readByte();
 		_rulesBuffer2_12[j] = f.readByte();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 1c15e8a..e26526e 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -151,12 +151,12 @@ public:
 	int _characterPositionX[40];
 	int _characterPositionY[40];
 	byte _rulesBuffer2_3[40];
-	int _rulesBuffer2_4[40];
+	int _characterFrameArray[40];
 	byte _rulesBuffer2_5[40];
 	byte _rulesBuffer2_6[40];
 	byte _rulesBuffer2_7[40];
-	byte _rulesBuffer2_8[40];
-	byte _rulesBuffer2_9[40];
+	byte _spriteSizeArray[40];
+	byte _characterDirectionArray[40];
 	byte _rulesBuffer2_10[40];
 	byte _rulesBuffer2_11[40];
 	byte _rulesBuffer2_12[40];
@@ -233,7 +233,7 @@ public:
 	void displayFunction15();
 	void displayFunction16();
 	void displayFunction17();
-	void displayFunction18(int index, int x, int y, int flags);
+	void displayCharacter(int index, int x, int y, int flags);
 	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
 	void sub130B6();
@@ -253,8 +253,6 @@ public:
 
 	void renderCharacters(byte *buf, byte x, byte y);
 
-	void sub16553(byte *buf);
-
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
 	void addCharToBuf(byte character);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 3186826..e8bd50c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -209,7 +209,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub1795E();
 		break;
 	case 0x2A:
-		return OC_sub1796E();
+		return OC_checkCharacterDirection();
 		break;
 	case 0x2B:
 		return OC_sub17984();
@@ -410,7 +410,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub18074();
 		break;
 	case 0x38:
-		OC_sub1808B();
+		OC_setCurrentCharacterDirection();
 		break;
 	case 0x39:
 		OC_sub18099();
@@ -515,7 +515,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub18690();
 		break;
 	case 0x5B:
-		OC_setWord10802();
+		OC_setViewPortCharacterTarget();
 		break;
 	case 0x5C:
 		OC_sub186A1();
@@ -1850,13 +1850,13 @@ byte LilliputScript::OC_sub1795E() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub1796E() {
-	debugC(1, kDebugScript, "OC_sub1796E()");
+byte LilliputScript::OC_checkCharacterDirection() {
+	debugC(1, kDebugScript, "OC_checkCharacterDirection()");
 
 	int var1 = getValue1();
 	int var2 = _currScript->readUint16LE();
 
-	if (_vm->_rulesBuffer2_9[var1] == var2)
+	if (_vm->_characterDirectionArray[var1] == var2)
 		return 1;
 	return 0;
 }
@@ -2344,19 +2344,21 @@ void LilliputScript::OC_sub17D23() {
 	computeOperation(buf, var1, var2 >> 8);
 	computeOperation(buf + 1, var1, var2 & 0xFF);
 }
+
 void LilliputScript::OC_sub17E6D() {
 	debugC(1, kDebugScript, "OC_sub17E6D()");
 	
 	int var1 = _currScript->readUint16LE();
 	_vm->_rulesBuffer2_12[_vm->_rulesBuffer2PrevIndx] = (var1 - 2000) & 0xFF;
 }
+
 void LilliputScript::OC_sub17E7E() {
 	debugC(2, kDebugScript, "OC_sub17E7E()");
 
 	int var1 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	_vm->_rulesBuffer2_4[_vm->_rulesBuffer2PrevIndx] = var1;
-	_vm->_rulesBuffer2_8[_vm->_rulesBuffer2PrevIndx] = var2;
+	_vm->_characterFrameArray[_vm->_rulesBuffer2PrevIndx] = var1;
+	_vm->_spriteSizeArray[_vm->_rulesBuffer2PrevIndx] = var2;
 
 }
 
@@ -2405,18 +2407,18 @@ void LilliputScript::OC_sub17EF4() {
 	int var1 = getValue2();
 	int posTile = sub17285(_vm->_rulesBuffer2PrevIndx);
 	int dir = _vm->sub16B0C(posTile, var1);
-	_vm->_rulesBuffer2_9[_vm->_rulesBuffer2PrevIndx] = dir;
+	_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx] = dir;
 
 }
 void LilliputScript::OC_sub17F08() {
 	debugC(1, kDebugScript, "OC_sub17F08()");
 	
-	int var1 = getValue1();
+	int index = getValue1();
 
-	static const byte _array16B04[] = { 0, 2, 0, 1, 3, 2, 3, 1 };
+	static const byte _directionsArray[] = { 0, 2, 0, 1, 3, 2, 3, 1 };
 
-	int dx = _vm->_characterPositionX[var1] - _vm->_characterDisplayX[_vm->_rulesBuffer2PrevIndx];
-	int dy = _vm->_characterPositionY[var1] - _vm->_characterDisplayY[_vm->_rulesBuffer2PrevIndx];
+	int dx = _vm->_characterPositionX[index] - _vm->_characterDisplayX[_vm->_rulesBuffer2PrevIndx];
+	int dy = _vm->_characterPositionY[index] - _vm->_characterDisplayY[_vm->_rulesBuffer2PrevIndx];
 
 	int flag = 0;
 	if (dx < 0) {
@@ -2431,7 +2433,7 @@ void LilliputScript::OC_sub17F08() {
 		flag |= 1;
 	}
 
-	_vm->_rulesBuffer2_9[_vm->_rulesBuffer2PrevIndx] = _array16B04[flag];
+	_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx] = _directionsArray[flag];
 }
 
 void LilliputScript::OC_sub17F4F() {
@@ -2440,6 +2442,7 @@ void LilliputScript::OC_sub17F4F() {
 	_array10A39[_vm->_rulesBuffer2PrevIndx] = var;
 	_vm->_array109E9[_vm->_rulesBuffer2PrevIndx] = 0xFF;
 }
+
 void LilliputScript::OC_sub17F68() {
 	warning("OC_sub17F68");
 }
@@ -2496,10 +2499,10 @@ void LilliputScript::OC_sub18074() {
 	_vm->_rulesBuffer2_16[(_vm->_rulesBuffer2PrevIndx * 32) + var2] = var1;
 }
 
-void LilliputScript::OC_sub1808B() {
-	debugC(1, kDebugScript, "OC_sub1808B()");
+void LilliputScript::OC_setCurrentCharacterDirection() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterDirection()");
 
-	_vm->_rulesBuffer2_9[_vm->_rulesBuffer2PrevIndx] = (_currScript->readUint16LE() & 0xFF);
+	_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub18099() {
@@ -2874,8 +2877,8 @@ void LilliputScript::OC_sub18690() {
 	warning("OC_sub18690");
 }
 
-void LilliputScript::OC_setWord10802() {
-	debugC(1, kDebugScript, "OC_setWord10802()");
+void LilliputScript::OC_setViewPortCharacterTarget() {
+	debugC(1, kDebugScript, "OC_setViewPortCharacterTarget()");
 
 	_viewportCharacterTarget = getValue1();
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 24063e4..b6ddafa 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -168,7 +168,7 @@ private:
 	byte OC_sub1792A();
 	byte OC_sub1793E();
 	byte OC_sub1795E();
-	byte OC_sub1796E();
+	byte OC_checkCharacterDirection();
 	byte OC_sub17984();
 	byte OC_checkSavedMousePos();
 	byte OC_sub179AE();
@@ -234,7 +234,7 @@ private:
 	void OC_sub1801D();
 	void OC_sub1805D();
 	void OC_sub18074();
-	void OC_sub1808B();
+	void OC_setCurrentCharacterDirection();
 	void OC_sub18099();
 	void OC_sub180C3();
 	void OC_sub1810A();
@@ -270,7 +270,7 @@ private:
 	void OC_initArr18560();
 	void OC_sub18678();
 	void OC_sub18690();
-	void OC_setWord10802();
+	void OC_setViewPortCharacterTarget();
 	void OC_sub186A1();
 	void OC_sub186E5_snd();
 	void OC_sub1870A_snd();


Commit: cf4d8322143970cc264d48cd8663e066fb33680b
    https://github.com/scummvm/scummvm/commit/cf4d8322143970cc264d48cd8663e066fb33680b
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Finish opcode2 list for decompiler

Implemented some opcode too but some are left.

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index e8bd50c..5a87b6d 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -635,18 +635,18 @@ static const OpCode opCodes2[] = {
 	{ "OC_sub17DB9", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone }, // todo
 	{ "OC_sub17DF9", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub17E07", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
-	{ "OC_sub17E15", 3, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_sub17E15", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub17B03", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
 	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
 	{ "OC_sub17A66", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },
-	{ "OC_sub17A8D", 2, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_saveAndQuit", 2, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_sub17A8D", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
 	{ "OC_sub17E37", 0, kNone, kNone, kNone, kNone, kNone },  // todo
 	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },  
 	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },  
 	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
-	{ "OC_sub17BA5", 0, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
+	{ "OC_sub17BA5", 5, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
 	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
 	{ "OC_sub17BA5", 0, kNone, kNone, kNone, kNone, kNone },  
 	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
@@ -676,7 +676,63 @@ static const OpCode opCodes2[] = {
 	{ "OC_sub17EF4", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
 	{ "OC_sub17F08", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17F68", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17F68", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_getNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_sub17FD2", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_setByte10B29", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18007", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18014", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1801D", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18099", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub180C3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1810A", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1812D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub181BB", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18260", 2, kGetValue1, kGetValue2, kNone, kNone, kNone }, // TODO
+	{ "OC_sub182EC", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1834C", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18359", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17D04", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub18387", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub183A2", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub183C6", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
+	{ "OC_loadFile_AERIAL_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1834C", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub17E22", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub1847F", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub184D7", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
+	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1864D", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },  // TODO
+	{ "OC_initArr18560", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+	{ "OC_sub18678", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+	{ "OC_sub18690", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },  //TODO
+	{ "OC_setViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_sub186A1", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },  //TODO
+	{ "OC_sub186E5_snd", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub1870A_snd", 2, kGetValue2, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub18725_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18733_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1873F_snd", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
+	{ "OC_sub18764", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
 void LilliputScript::disasmScript( ScriptStream script) {
@@ -2444,13 +2500,50 @@ void LilliputScript::OC_sub17F4F() {
 }
 
 void LilliputScript::OC_sub17F68() {
-	warning("OC_sub17F68");
+	if (_vm->_rulesBuffer2PrevIndx != _viewportCharacterTarget)
+		return;
+
+	static const byte _byte_17F60[] = { 0xFF, 0xFD, 0xFD, 0xFA };
+	static const byte _byte_17F64[] = { 0xFD, 0xFA, 0xFF, 0xFD };
+	
+	int cx = _byte_17F60[_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx]];
+	int cy = _byte_17F64[_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx]];
+
+	int pos = sub17285(_vm->_rulesBuffer2PrevIndx);
+
+	int posx = pos >> 8;
+	int posy = pos & 0xFF;
+
+	int newPosX = posx + cx;
+	int newPosY = posy + cy;
+
+	if (newPosX < 0)
+		newPosX = 0;
+
+	if (newPosX > 56)
+		newPosX = 56;
+
+	if (newPosY < 0)
+		newPosY = 0;
+
+	if (newPosY > 56)
+		newPosY = 56;
+
+	_byte12A09 = 1;
+	_vm->viewportScrollTo(newPosX, newPosY);
+	_byte12A09 = 0;
+
 }
 void LilliputScript::OC_getNextVal() {
-	warning("OC_getNextVal");
+	debugC(1, kDebugScript, "OC_getNextVal()");
+	 _currScript->readUint16LE();
 }
 void LilliputScript::OC_sub17FD2() {
-	warning("OC_sub17FD2");
+	debugC(1, kDebugScript, "OC_sub17FD2()");
+	
+	int var1 = getValue1();
+	_vm->_ptr_rulesBuffer2_15[6] = var1 & 0xFF;
+
 }
 
 void LilliputScript::OC_sub17FDD() {
@@ -2465,7 +2558,9 @@ void LilliputScript::OC_sub17FDD() {
 }
 
 void LilliputScript::OC_setByte10B29() {
-	warning("OC_setByte10B29");
+	debugC(1, kDebugScript, "OC_setByte10B29()");
+	int var1 = getValue1();
+	_characterScriptEnabled[var1] = 1;
 }
 
 void LilliputScript::OC_sub18007() {
@@ -2484,10 +2579,27 @@ void LilliputScript::OC_sub18014() {
 }
 
 void LilliputScript::OC_sub1801D() {
-	warning("OC_sub1801D");
+	debugC(1, kDebugScript, "OC_sub18014()");
+
+	int var1 = getValue1();
+
+	int x = _vm->_characterPositionX[var1] & 0xFFF8;
+	x += _currScript->readUint16LE();
+	_vm->_characterPositionX[var1] = x;
+
+	int y = _vm->_characterPositionY[var1] & 0xFFF8;
+	y += _currScript->readUint16LE();
+	_vm->_characterPositionY[var1] = y;
+
+	_vm->_rulesBuffer2_3[var1]  = _currScript->readUint16LE();
+	_vm->_characterDirectionArray[var1] = _currScript->readUint16LE();
+
 }
 void LilliputScript::OC_sub1805D() {
-	warning("OC_sub1805D");
+	debugC(1, kDebugScript, "OC_sub1805D()");
+	
+	int var1 = getValue1();
+	
 }
 
 void LilliputScript::OC_sub18074() {
@@ -2519,10 +2631,45 @@ void LilliputScript::OC_sub18099() {
 }
 
 void LilliputScript::OC_sub180C3() {
-	warning("OC_sub180C3");
+	debugC(1, kDebugScript, "OC_sub180C3()");
+	_viewportCharacterTarget = 0xFFFF;
+
+	int var1 = _currScript->readUint16LE();
+	
+	static const char _byte180B3[] = { 6, 0, 0, -6 };
+	static const char _byte180BB[] = { 0, -6, 6, 0 };
+	
+	int x = _viewportX + _byte180B3[var1];
+	int y = _viewportY + _byte180BB[var1];
+
+	if ( x < 0 )
+		x = 0;
+
+	if ( y < 0 )
+		y = 0;
+	
+	if ( x > 56 )
+		x = 56;
+
+	if ( y > 56 )
+		y = 56;
+
+	_byte12A09 = 1;
+	_vm->viewportScrollTo(x, y);
+	_byte12A09 = 0;
 }
+
 void LilliputScript::OC_sub1810A() {
-	warning("OC_sub1810A");
+	debugC(1, kDebugScript, "OC_sub1810A()");
+
+	_viewportCharacterTarget = 0xFFFF;
+	int var1 = getValue2();
+
+	_viewportX = var1 >> 8;
+	_viewportY = var1 & 0xFF;
+
+	_vm->displayFunction9();
+	_vm->displayFunction15();
 }
 
 void LilliputScript::OC_sub1812D() {
@@ -2616,7 +2763,22 @@ void LilliputScript::OC_sub18252() {
 }
 
 void LilliputScript::OC_sub18260() {
-	warning("OC_sub18260");
+	debugC(1, kDebugScript, "OC_sub18260()");
+	
+	int var1 = getValue1();
+	int var2 = getValue2();
+
+	int x = var1 + _viewportX;
+	int y = var2 + _viewportY;
+
+	byte* mapPtr = getMapPtr((x << 8) + (y & 0xff));
+
+	int bx = 0;
+	int by = 0;
+
+	if (mapPtr[1] == 0xFF) {
+		// TODO
+	}
 }
 
 void LilliputScript::OC_sub182EC() {


Commit: ca5b883ce7023dfead7ee7782c8246f6ae3a2983
    https://github.com/scummvm/scummvm/commit/ca5b883ce7023dfead7ee7782c8246f6ae3a2983
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add one core function, some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index aee940e..39be2af 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -366,7 +366,6 @@ void LilliputEngine::displayFunction1a(byte *buf, int var2, int var4) {
 void LilliputEngine::displayFunction2(byte *buf, int var2, int var4) {
 	debugC(2, kDebugEngine, "displayFunction2(buf, %d, %d)", var2, var4);
 
-
 	int tmpVal = ((var4 & 0xFF) << 8) + (var4 >> 8);
 	int index2 = var2 + tmpVal + (tmpVal >> 2);
 
@@ -1246,9 +1245,6 @@ void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
 	int displayX = _characterDisplayX[index];
 	int displayY = _characterDisplayY[index];
 
-	if ((displayX == 104) && (displayY == 132))
-		warning("");
-
 	if (index == _scriptHandler->_word1881B)
 		sub1546F(displayX, displayY);
 
@@ -1454,7 +1450,7 @@ void LilliputEngine::sub16626() {
 				result = 0;
 				break;
 			case 10:
-				warning("result = sub_1675D");
+				result = sub1675D(index, var1);
 				break;
 			case 11:
 				warning("result = sub_16729");
@@ -1493,6 +1489,28 @@ int LilliputEngine::sub166DD(int index, int var1) {
 	return 0;
 }
 
+int LilliputEngine::sub1675D(int index, int var1) {
+	debugC(2, kDebugEngine, "sub1675D(%d, %d)", index, var1);
+
+	int var2 = _scriptHandler->_array10A39[index];
+	int var1h = _scriptHandler->_array16123[var2];
+	int var1l = _scriptHandler->_array1614B[var2];
+	int var3 = _array109E9[index];
+
+	if ((var3 != 0xFF) && (var3 == _array10999[index])) {
+		var3 = _array10A11[index];
+		if (var3 == _array109C1[index]) {
+			_array109E9[index] = var1h;
+			_array10A11[index] = var1l;
+		}
+	}
+
+	_array10999[index] = var1h;
+	_array109C1[index] = var1l;
+
+	return sub16799(index, var1);
+}
+
 void LilliputEngine::sub16EBC() {
 	debugC(2, kDebugEngine, "sub16EBC()");
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index e26526e..8820cb9 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -291,6 +291,8 @@ public:
 	void sub166D8(int index);
 	void sub16B31(int index, int val);
 	void sub16B8F(int index, int x, int y, int flag);
+	int sub1675D(int index, int var1);
+
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 5a87b6d..2eb1185 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -362,7 +362,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17E6D();
 		break;
 	case 0x28:
-		OC_sub17E7E();
+		OC_changeCurrentCharacterSprite();
 		break;
 	case 0x29:
 		OC_sub17E99();
@@ -2408,8 +2408,8 @@ void LilliputScript::OC_sub17E6D() {
 	_vm->_rulesBuffer2_12[_vm->_rulesBuffer2PrevIndx] = (var1 - 2000) & 0xFF;
 }
 
-void LilliputScript::OC_sub17E7E() {
-	debugC(2, kDebugScript, "OC_sub17E7E()");
+void LilliputScript::OC_changeCurrentCharacterSprite() {
+	debugC(2, kDebugScript, "OC_changeCurrentCharacterSprite()");
 
 	int var1 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
@@ -2464,8 +2464,8 @@ void LilliputScript::OC_sub17EF4() {
 	int posTile = sub17285(_vm->_rulesBuffer2PrevIndx);
 	int dir = _vm->sub16B0C(posTile, var1);
 	_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx] = dir;
-
 }
+
 void LilliputScript::OC_sub17F08() {
 	debugC(1, kDebugScript, "OC_sub17F08()");
 	
@@ -2887,6 +2887,7 @@ void LilliputScript::OC_sub183A2() {
 void LilliputScript::OC_sub183C6() {
 	warning("OC_sub183C6");
 }
+
 void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	debugC(1, kDebugScript, "OC_loadFile_AERIAL_GFX()");
 	
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index b6ddafa..20ab849 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -218,7 +218,7 @@ private:
 	void OC_sub17D1B();
 	void OC_sub17D23();
 	void OC_sub17E6D();
-	void OC_sub17E7E();
+	void OC_changeCurrentCharacterSprite();
 	void OC_sub17E99();
 	void OC_sub17EC5();
 	void OC_sub17EF4();


Commit: d7d3b50d404a3f5be679f7e2a9b38bd4ea9d8f8c
    https://github.com/scummvm/scummvm/commit/d7d3b50d404a3f5be679f7e2a9b38bd4ea9d8f8c
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Opcode2 decompiler

+ one or two renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 39be2af..ae70b9e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2370,14 +2370,14 @@ void LilliputEngine::handleGameScripts() {
 	if (tmpVal == 0xFF)
 		return;
 
-	for (int i = 0; i < _gameScriptIndexSize; i++) {
+/*for (int i = 0; i < _gameScriptIndexSize; i++) {
 		assert(tmpVal < _gameScriptIndexSize);
 		debugC(1, kDebugEngine, "================= Game Script %d ==================", i);
 		ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[i]], _arrayGameScriptIndex[i + 1] - _arrayGameScriptIndex[i]);
-//		_scriptHandler->disasmScript(script);
+		_scriptHandler->disasmScript(script);
 		debugC(1, kDebugEngine, "============= End Game Script %d ==================", i);
-
 	}
+*/
 
 	assert(tmpVal < _gameScriptIndexSize);
 	debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 2eb1185..abfa2ed 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -272,7 +272,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_getRandom_type2();
 		break;
 	case 0xA:
-		OC_sub17A66();
+		OC_setCharacterPosition();
 		break;
 	case 0xB:
 		OC_sub17A8D();
@@ -302,7 +302,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setByte18823();
 		break;
 	case 0x14:
-		OC_sub17BB7();
+		OC_callScript();
 		break;
 	case 0x15:
 		OC_sub17BF2();
@@ -628,111 +628,108 @@ static const OpCode opCodes1[] = {
 
 
 static const OpCode opCodes2[] = {
-	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_sub17A3E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub17D57", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub17D7F", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
-	{ "OC_sub17DB9", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone }, // todo
-	{ "OC_sub17DF9", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub17E07", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
-	{ "OC_sub17E15", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub17B03", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
-	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
-	{ "OC_sub17A66", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },
-	{ "OC_sub17A8D", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
-	{ "OC_sub17E37", 0, kNone, kNone, kNone, kNone, kNone },  // todo
-	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },  
-	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },  
-	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
-	{ "OC_sub17BA5", 5, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
-	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
-	{ "OC_sub17BA5", 0, kNone, kNone, kNone, kNone, kNone },  
-	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
-	{ "OC_sub17BB7", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone },  // run script
-	{ "OC_sub17BF2", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone },  // run script then stop
-	{ "OC_sub17ACC", 1, kGetValue2, kNone, kNone, kNone, kNone },  
-	{ "OC_resetByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
-	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
-	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
-	{ "OC_setWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },  
-	{ "OC_sub17C0E", 0, kNone, kNone, kNone, kNone, kNone },  
- 	{ "OC_sub17C55", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone }, 
-	{ "OC_sub17C76", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17AFC", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17C8B", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub17CA2", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub17CB9", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone }, 
-	{ "OC_sub17CD1", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17CEF", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
-	{ "OC_sub17D1B", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17D23", 2, kImmediateValue, kGetValue2, kNone, kNone, kNone }, 
-	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17E7E", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-	{ "OC_sub17EF4", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17F08", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17F68", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_getNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub17FD2", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_setByte10B29", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18007", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18014", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1801D", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
-	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18099", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub180C3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1810A", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1812D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub181BB", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18260", 2, kGetValue1, kGetValue2, kNone, kNone, kNone }, // TODO
-	{ "OC_sub182EC", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1834C", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18359", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17D04", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub18387", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub183A2", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub183C6", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
-	{ "OC_loadFile_AERIAL_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1834C", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub17E22", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub1847F", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
-	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub184D7", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
-	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1864D", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },  // TODO
-	{ "OC_initArr18560", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
-	{ "OC_sub18678", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-	{ "OC_sub18690", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },  //TODO
-	{ "OC_setViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_sub186A1", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },  //TODO
-	{ "OC_sub186E5_snd", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub1870A_snd", 2, kGetValue2, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub18725_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18733_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1873F_snd", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
-	{ "OC_sub18764", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }
+/* 0x00 */	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x01 */	{ "OC_sub17A3E", 3, kGetValue2, kImmediateValue, kImmediateValue, kNone, kNone },
+/* 0x02 */	{ "OC_sub17D57", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x03 */	{ "OC_sub17D7F", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
+/* 0x04 */	{ "OC_sub17DB9", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
+/* 0x05 */	{ "OC_sub17DF9", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x06 */	{ "OC_sub17E07", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
+/* 0x07 */	{ "OC_sub17E15", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x08 */	{ "OC_sub17B03", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
+/* 0x09 */	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
+/* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },
+/* 0x0b */	{ "OC_sub17A8D", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x0d */	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
+/* 0x0e */	{ "OC_sub17E37", 0, kNone, kNone, kNone, kNone, kNone },  // todo
+/* 0x0f */	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },  
+/* 0x10 */	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },  
+/* 0x11 */	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
+/* 0x12 */	{ "OC_sub17BA5", 5, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
+/* 0x13 */	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
+/* 0x14 */	{ "OC_callScript", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script
+/* 0x15 */	{ "OC_sub17BF2", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script then stop
+/* 0x16 */	{ "OC_sub17ACC", 1, kGetValue2, kNone, kNone, kNone, kNone },  
+/* 0x17 */	{ "OC_resetByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
+/* 0x18 */	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
+/* 0x19 */	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
+/* 0x1a */	{ "OC_setWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },  
+/* 0x1b */	{ "OC_sub17C0E", 0, kNone, kNone, kNone, kNone, kNone },  
+/* 0x1c */ 	{ "OC_sub17C55", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x1d */	{ "OC_sub17C76", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x1e */	{ "OC_sub17AFC", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x1f */	{ "OC_sub17C8B", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x20 */	{ "OC_sub17CA2", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x21 */	{ "OC_sub17CB9", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone }, 
+/* 0x22 */	{ "OC_sub17CD1", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x24 */	{ "OC_sub17CEF", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
+/* 0x25 */	{ "OC_sub17D1B", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kGetValue2, kNone, kNone, kNone }, 
+/* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x28 */	{ "OC_sub17E7E", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x29 */	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x2b */	{ "OC_sub17EF4", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+/* 0x2c */	{ "OC_sub17F08", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x2e */	{ "OC_sub17F68", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x2f */	{ "OC_getNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x30 */	{ "OC_sub17FD2", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x32 */	{ "OC_setByte10B29", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x33 */	{ "OC_sub18007", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x34 */	{ "OC_sub18014", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x35 */	{ "OC_sub1801D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+/* 0x36 */	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+/* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x39 */	{ "OC_sub18099", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x3a */	{ "OC_sub180C3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x3b */	{ "OC_sub1810A", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+/* 0x3c */	{ "OC_sub1812D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x3d */	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x3e */	{ "OC_sub181BB", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x3f */	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x40 */	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x41 */	{ "OC_sub18260", 2, kGetValue1, kGetValue2, kNone, kNone, kNone }, // TODO
+/* 0x42 */	{ "OC_sub182EC", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x43 */	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x44 */	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x45 */	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x46 */	{ "OC_sub1834C", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x47 */	{ "OC_sub18359", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x48 */	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x49 */	{ "OC_sub17D04", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x4a */	{ "OC_sub18387", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x4b */	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x4d */	{ "OC_sub183A2", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x4e */	{ "OC_sub183C6", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
+/* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x50 */	{ "OC_sub17E22", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x52 */	{ "OC_sub1847F", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+/* 0x53 */	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x54 */	{ "OC_sub184D7", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
+/* 0x55 */	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x56 */	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x57 */	{ "OC_sub1864D", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },  // TODO
+/* 0x58 */	{ "OC_initArr18560", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+/* 0x59 */	{ "OC_sub18678", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },  //TODO
+/* 0x5b */	{ "OC_setViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x5c */	{ "OC_sub186A1", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },  //TODO
+/* 0x5d */	{ "OC_sub186E5_snd", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x5e */	{ "OC_sub1870A_snd", 2, kGetValue2, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x5f */	{ "OC_sub18725_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x60 */	{ "OC_sub18733_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x61 */	{ "OC_sub1873F_snd", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+/* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x63 */	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x64 */	{ "OC_sub18764", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x65 */	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
 void LilliputScript::disasmScript( ScriptStream script) {
@@ -746,8 +743,10 @@ void LilliputScript::disasmScript( ScriptStream script) {
 
 		if(val != 0xFFF8) {
 			hasIf = true;
-			debugC(2, kDebugScript, "if (");
+			
 		}
+		bool firstIf = true; 
+
 
 		// check the conditions.
 		while (val != 0xFFF8) {
@@ -767,21 +766,26 @@ void LilliputScript::disasmScript( ScriptStream script) {
 
 			Common::String str;
 
-			str = "  ";
+			if(firstIf) {
+				str = "if (";
+				firstIf = false;
+			} else {
+				str = "    ";
+			}
 			if (neg) str += "not ";
 			str += Common::String(opCode->_opName);
 			str += "(";
 
 			for (int p = 0; p < opCode->_numArgs; p++) {
 				if(*opArgType == kImmediateValue) {
-					str +=  Common::String::format("%d", script.readUint16LE());
+					str +=  Common::String::format("0x%x", script.readUint16LE());
 				} else if (*opArgType == kGetValue1) {
 					int val = script.readUint16LE();
 					if(val < 1000) 
 					{ 
-						str += Common::String::format("%d", val);
+						str += Common::String::format("0x%x", val);
 					} else if (val > 1004) { 
-						str += Common::String::format("getValue1(%d)", val);
+						str += Common::String::format("getValue1(0x%x)", val);
 					} else if ( val == 1000 ) {
 						str += Common::String("_byte129A0");
 					} else if( val == 1001 ) {
@@ -794,7 +798,7 @@ void LilliputScript::disasmScript( ScriptStream script) {
 						str += Common::String("_word10804");
 					}
 				} else if (*opArgType == kGetValue2) {
-					str += Common::String::format("getValue2(%d)", script.readUint16LE());
+					str += Common::String::format("getValue2(0x%x)", script.readUint16LE());
 				} else if (*opArgType == kCompareOperation) {
 					int comp = script.readUint16LE();
 					if(comp != '<' && comp != '>')
@@ -809,27 +813,86 @@ void LilliputScript::disasmScript( ScriptStream script) {
 			}
 			str += ")";
 
-			debugC(2, kDebugScript, str.c_str());
+			
 
 			val = script.readUint16LE();
-			
-		}
 
-		if( hasIf ) {
-			debugC(2, kDebugScript, ")");
-		}
+			if(val == 0xFFF8) {
+				str += ")";
+			}
+
+
+			debugC(2, kDebugScript, str.c_str());
 
+			
+		}
 
 		debugC(2, kDebugScript,"{ ");
 
+		val = script.readUint16LE();
+
 		while (val != 0xFFF7) {
-			// op code type 2 TODO
+			
+			// op code type 2 
+			assert(val < sizeof(opCodes2)/sizeof(OpCode));
+			const OpCode* opCode = &opCodes2[val];
+			const KValueType* opArgType = &opCode->_arg1;
+
+			Common::String str;
+
+			str = "    ";
+			str += Common::String(opCode->_opName);
+			str += "(";
+
+			for (int p = 0; p < opCode->_numArgs; p++) {
+				if(*opArgType == kImmediateValue) {
+					str +=  Common::String::format("0x%x", script.readUint16LE());
+				} else if (*opArgType == kGetValue1) {
+					int val = script.readUint16LE();
+					if(val < 1000) 
+					{ 
+						str += Common::String::format("0x%x", val);
+					} else if (val > 1004) { 
+						str += Common::String::format("getValue1(0x%x)", val);
+					} else if ( val == 1000 ) {
+						str += Common::String("_byte129A0");
+					} else if( val == 1001 ) {
+						str += Common::String("characterIndex");
+					} else if( val == 1002 ) {
+						str += Common::String("_word16F00");
+					} else if( val == 1003 ) {
+						str += Common::String("currentCharacter_var6");
+					} else if( val == 1004 ) {
+						str += Common::String("_word10804");
+					}
+				} else if (*opArgType == kGetValue2) {
+					str += Common::String::format("getValue2(0x%x)", script.readUint16LE());
+				} else if (*opArgType == kCompareOperation) {
+					int comp = script.readUint16LE();
+					if(comp != '<' && comp != '>')
+						comp = '=';
+					str += Common::String::format("%c", comp );
+				} else if (*opArgType == kComputeOperation) {
+					int comp = script.readUint16LE();
+					str += Common::String::format("%c", comp );
+				}
+
+				if (p != opCode->_numArgs - 1)
+					str += ", ";
+
+				if ( p < 5 )
+					opArgType++;
+			}
+			str += ");";
+
+			debugC(2, kDebugScript, str.c_str());
+
 
 			val = script.readUint16LE();
 		}
 
 		debugC(2, kDebugScript,"} ");
-
+		debugC(2, kDebugScript," ");
 	}
 }
 
@@ -1249,14 +1312,14 @@ int LilliputScript::getValue2() {
 	case 0xFA:
 		return ((_vm->_array10999[_vm->_rulesBuffer2PrevIndx] << 8) + _vm->_array109C1[_vm->_rulesBuffer2PrevIndx]);
 	case 0xF9:
-		return ((_vm->_rulesBuffer2_15[4] << 8) + _vm->_rulesBuffer2_15[5]);
+		return ((_vm->_ptr_rulesBuffer2_15[4] << 8) + _vm->_ptr_rulesBuffer2_15[5]);
 	case 0xF8: {
 		int index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
 		return _vm->_rulesBuffer12_3[index];
 		}
 	case 0xF7: {
-		int index = _vm->_rulesBuffer2_15[6];
+		int index = _vm->_ptr_rulesBuffer2_15[6];
 		assert(index < 40);
 		byte var1 = _vm->_characterPositionX[index] >> 3;
 		byte var2 = _vm->_characterPositionY[index] >> 3;
@@ -2009,7 +2072,21 @@ void LilliputScript::OC_setWord18821() {
 	_word18821 = getValue1();
 }
 void LilliputScript::OC_sub17A3E() {
-	warning("OC_sub17A3E");
+	debugC(1, kDebugScript, "OC_sub17A3E()");
+	int var1 = getValue2();
+	int var2 = _currScript->readUint16LE();
+	int var3 = _currScript->readUint16LE();
+
+	byte* mapPtr = getMapPtr(var1);
+	
+	int mask = 8 >> var2;
+	mask = ~mask;
+	mapPtr[3] &= mask;
+
+	if (var3 > 0) {
+		mask = ~mask;
+		mapPtr[3] |= mask;
+	}
 }
 
 void LilliputScript::OC_sub17D57() {
@@ -2127,8 +2204,8 @@ void LilliputScript::OC_getRandom_type2() {
 	*bufPtr = randomVal;
 }
 
-void LilliputScript::OC_sub17A66() {
-	debugC(1, kDebugScript, "OC_sub17A66()");
+void LilliputScript::OC_setCharacterPosition() {
+	debugC(1, kDebugScript, "OC_setCharacterPosition()");
 	
 	int index = getValue1();
 	int tmpVal = getValue2();
@@ -2199,8 +2276,8 @@ void LilliputScript::OC_setByte18823() {
 	_byte18823 = *tmpArr;
 }
 
-void LilliputScript::OC_sub17BB7() {
-	debugC(1, kDebugScript, "OC_sub17BB7()");
+void LilliputScript::OC_callScript() {
+	debugC(1, kDebugScript, "OC_callScript()");
 
 	int index = _currScript->readUint16LE();
 	int var1 = getValue1();
@@ -2228,7 +2305,7 @@ void LilliputScript::OC_sub17BB7() {
 void LilliputScript::OC_sub17BF2() {
 	debugC(1, kDebugScript, "OC_sub17BF2()");
 
-	OC_sub17BB7();
+	OC_callScript();
 	sub17B6C(0);
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 20ab849..e7f0d9f 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -188,7 +188,7 @@ private:
 	void OC_sub17E15();
 	void OC_sub17B03();
 	void OC_getRandom_type2();
-	void OC_sub17A66();
+	void OC_setCharacterPosition();
 	void OC_sub17A8D();
 	void OC_saveAndQuit();
 	void OC_sub17B93();
@@ -198,7 +198,7 @@ private:
 	void OC_incByte16F04();
 	void OC_sub17BA5();
 	void OC_setByte18823();
-	void OC_sub17BB7();
+	void OC_callScript();
 	void OC_sub17BF2();
 	void OC_sub17ACC();
 	void OC_resetByte16F04();


Commit: 19f8bd899a23bad9d53bef7c5bc73fc3a5b05050
    https://github.com/scummvm/scummvm/commit/19f8bd899a23bad9d53bef7c5bc73fc3a5b05050
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ae70b9e..7add061 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1749,15 +1749,15 @@ int LilliputEngine::sub16675(int idx, int var1) {
 void LilliputEngine::sub16B63(int index) {
 	debugC(2, kDebugEngine, "sub16B63(%d)", index);
 
-	static const byte nextFrame[4] = {1, 3, 0, 2};
-	_characterDirectionArray[index] = nextFrame[_characterDirectionArray[index]];
+	static const byte nextDirection[4] = {1, 3, 0, 2};
+	_characterDirectionArray[index] = nextDirection[_characterDirectionArray[index]];
 }
 
 void LilliputEngine::sub16B76(int index) {
 	debugC(2, kDebugEngine, "sub16B76(%d)", index);
 
-	static const byte nextFrame[4] = {2, 0, 3, 1};
-	_characterDirectionArray[index] = nextFrame[_characterDirectionArray[index]];
+	static const byte nextDirection[4] = {2, 0, 3, 1};
+	_characterDirectionArray[index] = nextDirection[_characterDirectionArray[index]];
 }
 
 void LilliputEngine::sub166C0(int index) {
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index abfa2ed..3a3ea6d 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -455,7 +455,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1834C();
 		break;
 	case 0x47:
-		OC_sub18359();
+		OC_setArray122C1();
 		break;
 	case 0x48:
 		OC_sub18367();
@@ -699,7 +699,7 @@ static const OpCode opCodes2[] = {
 /* 0x44 */	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x45 */	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x46 */	{ "OC_sub1834C", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x47 */	{ "OC_sub18359", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x47 */	{ "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x48 */	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x49 */	{ "OC_sub17D04", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x4a */	{ "OC_sub18387", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
@@ -2910,8 +2910,8 @@ void LilliputScript::OC_sub1834C() {
 	_vm->_ptr_rulesBuffer2_15[3] = curWord;
 }
 
-void LilliputScript::OC_sub18359() {
-	debugC(1, kDebugScript, "OC_sub18359()");
+void LilliputScript::OC_setArray122C1() {
+	debugC(1, kDebugScript, "OC_setArray122C1()");
 
 	int var1 = _currScript->readUint16LE();
 	_array122C1[_vm->_rulesBuffer2PrevIndx] = var1;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index e7f0d9f..e964c3c 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -250,7 +250,7 @@ private:
 	void OC_PaletteFadeIn();
 	void OC_loadAndDisplayCUBESx_GFX();
 	void OC_sub1834C();
-	void OC_sub18359();
+	void OC_setArray122C1();
 	void OC_sub18367();
 	void OC_sub17D04();
 	void OC_sub18387();


Commit: eabe891bf65f8f5bfd4ce1a27fdadfe53a37e16a
    https://github.com/scummvm/scummvm/commit/eabe891bf65f8f5bfd4ce1a27fdadfe53a37e16a
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Improved getValue2 decompilation

+ some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7add061..3b44949 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -150,7 +150,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12FE3 = 0;
 	_byte16F08 = 0;
 
-	_rulesBuffer2PrevIndx = 0;
+	currentScriptCharacter = 0;
 	_currentScriptCharacterPosition = 0;
 	_word10804 = 0;
 	_word17081_nextIndex = 0;
@@ -192,7 +192,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array11D49[i] = 0xFFFF;
 		_characterPositionX[i] = 0xFFFF;
 		_characterPositionY[i] = 0xFFFF;
-		_rulesBuffer2_3[i] = 0;
+		_characterPositionAltitude[i] = 0;
 		_characterFrameArray[i] = 0;
 		_rulesBuffer2_5[i] = 0xFF;
 		_rulesBuffer2_6[i] = 4;
@@ -216,7 +216,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	for (int i = 0; i < 160; i++)
 		_displayStringBuf[i] = 0;
 
-	_ptr_rulesBuffer2_15 = NULL;
+	_currentCharacterVariables = NULL;
 	_bufferIdeogram = NULL;
 	_bufferMen = NULL;
 	_bufferMen2 = NULL;
@@ -687,7 +687,7 @@ void LilliputEngine::sub16217() {
 	for (int i = index; i >= 0; i--) {
 		if (_rulesBuffer2_5[i] != 0xFF) {
 			int index2 = _rulesBuffer2_5[i];
-			_rulesBuffer2_3[i] = _rulesBuffer2_3[index2] + _rulesBuffer2_7[i];
+			_characterPositionAltitude[i] = _characterPositionAltitude[index2] + _rulesBuffer2_7[i];
 			int tmpVal = _rulesBuffer2_6[i];
 			_characterDirectionArray[i] = _characterDirectionArray[index2];
 			int var3 = _characterPositionX[index2];
@@ -726,7 +726,7 @@ void LilliputEngine::sub16217() {
 			_characterRelativePositionY[i] = tmpVal3;
 			tmpVal2 = _characterPositionX[i] - _word16213;
 			tmpVal3 = _characterPositionY[i] - _word16215;
-			int tmpVal4 = _rulesBuffer2_3[i];
+			int tmpVal4 = _characterPositionAltitude[i];
 			_characterDisplayX[i] = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF;
 			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
 			_charactersToDisplay[_numCharactersToDisplay] = i;
@@ -1127,10 +1127,10 @@ void LilliputEngine::sortCharacters() {
 					continue;
 
 				if (_characterRelativePositionX[index1] == _characterRelativePositionX[index2]) {
-					if (_rulesBuffer2_3[index1] < _rulesBuffer2_3[index2])
+					if (_characterPositionAltitude[index1] < _characterPositionAltitude[index2])
 						continue;
 
-					if (_rulesBuffer2_3[index1] == _rulesBuffer2_3[index2]) {
+					if (_characterPositionAltitude[index1] == _characterPositionAltitude[index2]) {
 						if (_characterDisplayY[index1] < _characterDisplayY[index2])
 							continue;
 					}
@@ -1536,12 +1536,12 @@ void LilliputEngine::sub12F37() {
 	int index2 = 0;
 
 	for (int i = 0; i < _numCharacters; i++) {
-		if (_rulesBuffer2_15[index1] != 0 ) {
-			if (_rulesBuffer2_15[index1] == 1) {
-				_rulesBuffer2_15[index1] = 0;
+		if (_characterVariables[index1] != 0 ) {
+			if (_characterVariables[index1] == 1) {
+				_characterVariables[index1] = 0;
 			} else {
-				--_rulesBuffer2_15[index1];
-				if (_rulesBuffer2_15[index1] == 1)
+				--_characterVariables[index1];
+				if (_characterVariables[index1] == 1)
 					_scriptHandler->_characterScriptEnabled[index2] = 1;
 			}
 		}
@@ -1763,25 +1763,25 @@ void LilliputEngine::sub16B76(int index) {
 void LilliputEngine::sub166C0(int index) {
 	debugC(2, kDebugEngine, "sub166C0(%d)", index);
 
-	_rulesBuffer2_3[index] += 1;
+	_characterPositionAltitude[index] += 1;
 }
 
 void LilliputEngine::sub166C6(int index) {
 	debugC(2, kDebugEngine, "sub166C6(%d)", index);
 
-	_rulesBuffer2_3[index] += 2;
+	_characterPositionAltitude[index] += 2;
 }
 
 void LilliputEngine::sub166CC(int index) {
 	debugC(2, kDebugEngine, "sub166CC(%d)", index);
 
-	_rulesBuffer2_3[index] -= 1;
+	_characterPositionAltitude[index] -= 1;
 }
 
 void LilliputEngine::sub166D2(int index) {
 	debugC(2, kDebugEngine, "sub166D2(%d)", index);
 
-	_rulesBuffer2_3[index] -= 2;
+	_characterPositionAltitude[index] -= 2;
 }
 
 void LilliputEngine::sub166B1(int index) {
@@ -2140,7 +2140,7 @@ void LilliputEngine::loadRules() {
 			curWord = (curWord << 3) + 4;
 		_characterPositionY[j] = curWord;
 
-		_rulesBuffer2_3[j] = (f.readUint16LE() & 0xFF);
+		_characterPositionAltitude[j] = (f.readUint16LE() & 0xFF);
 		_characterFrameArray[j] = f.readUint16LE();
 		_rulesBuffer2_5[j] = f.readByte();
 		_rulesBuffer2_6[j] = f.readByte();
@@ -2154,7 +2154,7 @@ void LilliputEngine::loadRules() {
 		_rulesBuffer2_14[j] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
-			_rulesBuffer2_15[(j * 32) + k] = f.readByte();
+			_characterVariables[(j * 32) + k] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
 			_rulesBuffer2_16[(j * 32) + k] = f.readByte();
@@ -2307,14 +2307,14 @@ void LilliputEngine::initPalette() {
 void LilliputEngine::sub170EE(int index) {
 	debugC(1, kDebugEngine, "sub170EE(%d)", index);
 
-	_rulesBuffer2PrevIndx = index;
+	currentScriptCharacter = index;
 
 	assert (index < 40);
 	int var2 = _characterPositionX[index];
 	int var4 = _characterPositionY[index];
 
 	_currentScriptCharacterPosition = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF);
-	_ptr_rulesBuffer2_15 = &_rulesBuffer2_15[_rulesBuffer2PrevIndx * 32];
+	_currentCharacterVariables = &_characterVariables[currentScriptCharacter * 32];
 }
 
 void LilliputEngine::sub130DD() {
@@ -2370,14 +2370,15 @@ void LilliputEngine::handleGameScripts() {
 	if (tmpVal == 0xFF)
 		return;
 
-/*for (int i = 0; i < _gameScriptIndexSize; i++) {
+	for (int i = 0; i < _gameScriptIndexSize; i++) {
 		assert(tmpVal < _gameScriptIndexSize);
 		debugC(1, kDebugEngine, "================= Game Script %d ==================", i);
 		ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[i]], _arrayGameScriptIndex[i + 1] - _arrayGameScriptIndex[i]);
 		_scriptHandler->disasmScript(script);
 		debugC(1, kDebugEngine, "============= End Game Script %d ==================", i);
 	}
-*/
+
+while(1);
 
 	assert(tmpVal < _gameScriptIndexSize);
 	debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index);
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8820cb9..f8fab06 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -147,10 +147,10 @@ public:
 	int _array12861[30];
 
 	byte *_rulesChunk1;
-	int _rulesBuffer2PrevIndx;
+	int currentScriptCharacter;
 	int _characterPositionX[40];
 	int _characterPositionY[40];
-	byte _rulesBuffer2_3[40];
+	byte _characterPositionAltitude[40];
 	int _characterFrameArray[40];
 	byte _rulesBuffer2_5[40];
 	byte _rulesBuffer2_6[40];
@@ -162,8 +162,8 @@ public:
 	byte _rulesBuffer2_12[40];
 	byte _rulesBuffer2_13[40];
 	byte _rulesBuffer2_14[40];
-	byte _rulesBuffer2_15[40 * 32];
-	byte *_ptr_rulesBuffer2_15;
+	byte _characterVariables[40 * 32];
+	byte *_currentCharacterVariables;
 	byte _rulesBuffer2_16[40 * 32];
 	int *_rulesChunk3;
 	int _rulesChunk3_size;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 3a3ea6d..477912e 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -553,25 +553,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 	}
 }
 
-enum KValueType {
-	kNone,
-	kImmediateValue,
-	kCompareOperation,
-	kComputeOperation,
-	kGetValue1,
-	kGetValue2,
-};
-
 
-struct OpCode {
-	const char* _opName;
-	int _numArgs;
-	KValueType _arg1;
-	KValueType _arg2;
-	KValueType _arg3;
-	KValueType _arg4;
-	KValueType _arg5;
-};
 
 static const OpCode opCodes1[] = {
 	{ "OC_sub173DF", 1, kGetValue2, kNone, kNone, kNone, kNone },
@@ -732,6 +714,89 @@ static const OpCode opCodes2[] = {
 /* 0x65 */	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
+Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream& script) {
+	
+	Common::String str;
+	if(type == kImmediateValue) {
+		str =  Common::String::format("0x%x", script.readUint16LE());
+	} else if (type == kGetValue1) {
+		int val = script.readUint16LE();
+		if(val < 1000) { 
+			str = Common::String::format("0x%x", val);
+		} else if (val > 1004) { 
+			str = Common::String::format("getValue1(0x%x)", val);
+		} else if ( val == 1000 ) {
+			str = Common::String("_byte129A0");
+		} else if( val == 1001 ) {
+			str = Common::String("characterIndex");
+		} else if( val == 1002 ) {
+			str = Common::String("_word16F00");
+		} else if( val == 1003 ) {
+			str = Common::String("_currentCharacterVariables[6]");
+		} else if( val == 1004 ) {
+			str = Common::String("_word10804");
+		}
+	} else if (type == kGetValue2) {
+		int curWord = script.readUint16LE();
+		int tmpVal = curWord >> 8;
+		switch(tmpVal) {
+	case 0xFF:
+		str = "(_rulesBuffer2_13[currentCharacter],_rulesBuffer2_14[currentCharacter])";
+		break;
+	case 0xFE: {
+		int index = curWord & 0xFF;
+		assert((index >= 0) && (index < 40));
+		str = Common::String::format("_vm->_rulesBuffer2_13[%d],_vm->_rulesBuffer2_14[%d]", index, index);
+		break;
+			   }
+	case 0xFD:
+		str = "_currentScriptCharacterPosition";
+		break;
+	case 0xFC: {
+		int index = curWord & 0xFF;
+		assert(index < 40);
+		str = Common::String::format("(characterPositionTileX[%d], characterPositionTileY[%d])", index, index);
+		break;
+			   }
+	case 0xFB: {
+		str = "(characterPositionTileX[_word16F00], characterPositionTileY[_word16F00])";
+		break;
+			   }
+	case 0xFA:
+		str = Common::String::format("(_array10999[currentCharacter], _array109C1[currentCharacter])");
+		break;
+	case 0xF9:
+		str = Common::String::format("(_currentCharacterVariables[4], _currentCharacterVariables[5])");
+		break;
+	case 0xF8: {
+		int index = curWord & 0xFF;
+		assert((index >= 0) && (index < 40));
+		str = Common::String::format("_vm->_rulesBuffer12_3[%d]", index);
+	}
+	case 0xF7: {
+		str = Common::String::format("(_characterPositionTileX[_currentCharacterVariables[6]], _characterPositionTileY[_currentCharacterVariables[6]])");
+		break;			 
+	}
+	case 0xF6:
+		str = "_savedMousePosDivided";
+		break;
+	default:
+		str = Common::String::format("(0x%x,0x%x)", curWord >> 8, curWord & 0xFF);
+		break;
+		}
+	} else if (type == kCompareOperation) {
+		int comp = script.readUint16LE();
+		if(comp != '<' && comp != '>')
+			comp = '=';
+		str = Common::String::format("%c", comp );
+	}
+	else if (type == kComputeOperation) {
+		int comp = script.readUint16LE();
+		str = Common::String::format("%c", comp );
+	}
+	return str;
+}
+
 void LilliputScript::disasmScript( ScriptStream script) {
 	
 	while(!script.eos()) {
@@ -777,35 +842,8 @@ void LilliputScript::disasmScript( ScriptStream script) {
 			str += "(";
 
 			for (int p = 0; p < opCode->_numArgs; p++) {
-				if(*opArgType == kImmediateValue) {
-					str +=  Common::String::format("0x%x", script.readUint16LE());
-				} else if (*opArgType == kGetValue1) {
-					int val = script.readUint16LE();
-					if(val < 1000) 
-					{ 
-						str += Common::String::format("0x%x", val);
-					} else if (val > 1004) { 
-						str += Common::String::format("getValue1(0x%x)", val);
-					} else if ( val == 1000 ) {
-						str += Common::String("_byte129A0");
-					} else if( val == 1001 ) {
-						str += Common::String("characterIndex");
-					} else if( val == 1002 ) {
-						str += Common::String("_word16F00");
-					} else if( val == 1003 ) {
-						str += Common::String("currentCharacter_var6");
-					} else if( val == 1004 ) {
-						str += Common::String("_word10804");
-					}
-				} else if (*opArgType == kGetValue2) {
-					str += Common::String::format("getValue2(0x%x)", script.readUint16LE());
-				} else if (*opArgType == kCompareOperation) {
-					int comp = script.readUint16LE();
-					if(comp != '<' && comp != '>')
-						comp = '=';
-					str += Common::String::format("%c", comp );
-				}
 				
+				str += getArgumentString(*opArgType, script);
 				if(p != opCode->_numArgs - 1)
 					str += ", ";
 
@@ -845,37 +883,7 @@ void LilliputScript::disasmScript( ScriptStream script) {
 			str += "(";
 
 			for (int p = 0; p < opCode->_numArgs; p++) {
-				if(*opArgType == kImmediateValue) {
-					str +=  Common::String::format("0x%x", script.readUint16LE());
-				} else if (*opArgType == kGetValue1) {
-					int val = script.readUint16LE();
-					if(val < 1000) 
-					{ 
-						str += Common::String::format("0x%x", val);
-					} else if (val > 1004) { 
-						str += Common::String::format("getValue1(0x%x)", val);
-					} else if ( val == 1000 ) {
-						str += Common::String("_byte129A0");
-					} else if( val == 1001 ) {
-						str += Common::String("characterIndex");
-					} else if( val == 1002 ) {
-						str += Common::String("_word16F00");
-					} else if( val == 1003 ) {
-						str += Common::String("currentCharacter_var6");
-					} else if( val == 1004 ) {
-						str += Common::String("_word10804");
-					}
-				} else if (*opArgType == kGetValue2) {
-					str += Common::String::format("getValue2(0x%x)", script.readUint16LE());
-				} else if (*opArgType == kCompareOperation) {
-					int comp = script.readUint16LE();
-					if(comp != '<' && comp != '>')
-						comp = '=';
-					str += Common::String::format("%c", comp );
-				} else if (*opArgType == kComputeOperation) {
-					int comp = script.readUint16LE();
-					str += Common::String::format("%c", comp );
-				}
+				str += getArgumentString(*opArgType, script);
 
 				if (p != opCode->_numArgs - 1)
 					str += ", ";
@@ -1105,7 +1113,7 @@ void LilliputScript::sub17D40(bool &forceReturnFl) {
 	debugC(1, kDebugScript, "sub17D40()");
 
 	forceReturnFl = false;
-	if ((_vm->_displayMap != 1) && (_vm->_characterRelativePositionX[_vm->_rulesBuffer2PrevIndx] != 0xFF))
+	if ((_vm->_displayMap != 1) && (_vm->_characterRelativePositionX[_vm->currentScriptCharacter] != 0xFF))
 		return;
 
 	forceReturnFl = true;
@@ -1264,11 +1272,11 @@ int LilliputScript::getValue1() {
 	case 1000:
 		return (int)_byte129A0;
 	case 1001:
-		return _vm->_rulesBuffer2PrevIndx;
+		return _vm->currentScriptCharacter;
 	case 1002:
 		return _word16F00;
 	case 1003:
-		return (int)_vm->_ptr_rulesBuffer2_15[6];
+		return (int)_vm->_currentCharacterVariables[6];
 	case 1004:
 		return _word10804;
 	default:
@@ -1284,8 +1292,8 @@ int LilliputScript::getValue2() {
 	int tmpVal = curWord >> 8;
 	switch(tmpVal) {
 	case 0xFF:
-		assert((_vm->_rulesBuffer2PrevIndx >= 0) && (_vm->_rulesBuffer2PrevIndx < 40));
-		return ((_vm->_rulesBuffer2_13[_vm->_rulesBuffer2PrevIndx] << 8) + _vm->_rulesBuffer2_14[_vm->_rulesBuffer2PrevIndx]);
+		assert((_vm->currentScriptCharacter >= 0) && (_vm->currentScriptCharacter < 40));
+		return ((_vm->_rulesBuffer2_13[_vm->currentScriptCharacter] << 8) + _vm->_rulesBuffer2_14[_vm->currentScriptCharacter]);
 	case 0xFE: {
 		int index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
@@ -1310,16 +1318,16 @@ int LilliputScript::getValue2() {
 		return (var1 << 8) + var2;
 		}
 	case 0xFA:
-		return ((_vm->_array10999[_vm->_rulesBuffer2PrevIndx] << 8) + _vm->_array109C1[_vm->_rulesBuffer2PrevIndx]);
+		return ((_vm->_array10999[_vm->currentScriptCharacter] << 8) + _vm->_array109C1[_vm->currentScriptCharacter]);
 	case 0xF9:
-		return ((_vm->_ptr_rulesBuffer2_15[4] << 8) + _vm->_ptr_rulesBuffer2_15[5]);
+		return ((_vm->_currentCharacterVariables[4] << 8) + _vm->_currentCharacterVariables[5]);
 	case 0xF8: {
 		int index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
 		return _vm->_rulesBuffer12_3[index];
 		}
 	case 0xF7: {
-		int index = _vm->_ptr_rulesBuffer2_15[6];
+		int index = _vm->_currentCharacterVariables[6];
 		assert(index < 40);
 		byte var1 = _vm->_characterPositionX[index] >> 3;
 		byte var2 = _vm->_characterPositionY[index] >> 3;
@@ -1344,15 +1352,15 @@ void LilliputScript::sub130B6() {
 	}
 }
 
-byte *LilliputScript::getBuffer215Ptr() {
-	debugC(2, kDebugScript, "getBuffer215Ptr()");
+byte *LilliputScript::getCharacterVariablePtr() {
+	debugC(2, kDebugScript, "getCharacterVariablePtr()");
 
 	int tmpVal = getValue1();
 	tmpVal *= 32;
 	tmpVal += _currScript->readUint16LE();
 
 	assert(tmpVal < 40 * 32);
-	return &_vm->_rulesBuffer2_15[tmpVal];
+	return &_vm->_characterVariables[tmpVal];
 }
 
 byte LilliputScript::OC_sub173DF() {
@@ -1402,7 +1410,7 @@ byte LilliputScript::OC_sub1740A() {
 byte LilliputScript::OC_sub17434() {
 	debugC(1, kDebugScript, "OC_sub17434()");
 
-	byte *tmpArr = getBuffer215Ptr();
+	byte *tmpArr = getCharacterVariablePtr();
 	byte var1 = tmpArr[0];
 	uint16 oper = _currScript->readUint16LE();
 	int16 var2 = _currScript->readUint16LE();
@@ -1506,12 +1514,12 @@ byte LilliputScript::OC_sub174D8() {
 byte LilliputScript::OC_sub1750E() {
 	debugC(1, kDebugScript, "OC_sub1750E()");
 
-	byte* buf1 = getBuffer215Ptr();
+	byte* buf1 = getCharacterVariablePtr();
 	int var1 = *buf1;
 
 	int operation = _currScript->readUint16LE();
 
-	byte* buf2 = getBuffer215Ptr();
+	byte* buf2 = getCharacterVariablePtr();
 	int var2 = *buf2;
 
 	return compareValues(var1, operation, var2);
@@ -1558,7 +1566,7 @@ byte LilliputScript::OC_compWord16EF8() {
 	debugC(1, kDebugScript, "OC_compWord16EF8()");
 	
 	int tmpVal = getValue1();
-	if (tmpVal == _vm->_rulesBuffer2PrevIndx)
+	if (tmpVal == _vm->currentScriptCharacter)
 		return 1;
 	return 0;
 }
@@ -1573,7 +1581,7 @@ byte LilliputScript::OC_sub175C8() {
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
-		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + index];
+		int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + index];
 		if ((var1 & 0xFF) < var4)
 			return 0;
 		
@@ -1583,7 +1591,7 @@ byte LilliputScript::OC_sub175C8() {
 
 	if (tmpVal == 3000) {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
-			int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
+			int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + i];
 			if ((var1 & 0xFF) >= var4) {
 				_word16F00 = i;
 				return 1;
@@ -1595,7 +1603,7 @@ byte LilliputScript::OC_sub175C8() {
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
+		int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + i];
 		if ((var1 & 0xFF) >= var4) {
 			if (_vm->_rulesBuffer2_12[i] == var4b) {
 				_word16F00 = i;
@@ -1611,7 +1619,7 @@ byte LilliputScript::OC_sub17640() {
 	debugC(1, kDebugScript, "OC_sub176C4()");
 
 	int var4 = _currScript->readUint16LE();
-	int index = _vm->_rulesBuffer2PrevIndx * 40;
+	int index = _vm->currentScriptCharacter * 40;
 	int subIndex = 0xFFFF;
 
 	int tmpVal = _currScript->readUint16LE();
@@ -1668,7 +1676,7 @@ byte LilliputScript::OC_sub176C4() {
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
-		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + index];
+		int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + index];
 		if (((var1 & 0xFF) >= var4) || ((var1 >> 8) < var4))
 			return 0;
 		
@@ -1678,7 +1686,7 @@ byte LilliputScript::OC_sub176C4() {
 
 	if (tmpVal == 3000) {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
-			int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
+			int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + i];
 			if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
 				_word16F00 = i;
 				return 1;
@@ -1690,7 +1698,7 @@ byte LilliputScript::OC_sub176C4() {
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i];
+		int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + i];
 		if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
 			if (_vm->_rulesBuffer2_12[i] == var4b) {
 				_word16F00 = i;
@@ -1716,7 +1724,7 @@ byte LilliputScript::OC_sub17766() {
 	debugC(1, kDebugScript, "OC_sub17766()");
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
-	if ((var1 == _array12839[_vm->_rulesBuffer2PrevIndx]) && (_array12811[_vm->_rulesBuffer2PrevIndx] != 16))
+	if ((var1 == _array12839[_vm->currentScriptCharacter]) && (_array12811[_vm->currentScriptCharacter] != 16))
 		return 1;
 
 	return 0;
@@ -1726,7 +1734,7 @@ byte LilliputScript::OC_sub17782() {
 	debugC(1, kDebugScript, "OC_sub17782()");
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
-	if ((var1 == _array12839[_vm->_rulesBuffer2PrevIndx]) && (_array12811[_vm->_rulesBuffer2PrevIndx] == 16))
+	if ((var1 == _array12839[_vm->currentScriptCharacter]) && (_array12811[_vm->currentScriptCharacter] == 16))
 		return 1;
 
 	return 0;
@@ -1787,9 +1795,9 @@ byte LilliputScript::OC_sub177F5() {
 	byte var1 = _currScript->readUint16LE() & 0xFF;
 	byte var2 = _currScript->readUint16LE() & 0xFF;
 
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	assert(_vm->_currentCharacterVariables != NULL);
 
-	if ((var1 == _vm->_ptr_rulesBuffer2_15[0]) && (var2 == _vm->_ptr_rulesBuffer2_15[1]))
+	if ((var1 == _vm->_currentCharacterVariables[0]) && (var2 == _vm->_currentCharacterVariables[1]))
 		return 1;
 
 	return 0;
@@ -1799,8 +1807,8 @@ byte LilliputScript::OC_sub17812() {
 	debugC(1, kDebugScript, "OC_sub17812()");
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
-	if (_vm->_ptr_rulesBuffer2_15[0] == curByte)
+	assert(_vm->_currentCharacterVariables != NULL);
+	if (_vm->_currentCharacterVariables[0] == curByte)
 		return 1;
 	return 0;
 }
@@ -1837,7 +1845,7 @@ byte LilliputScript::OC_sub1785C() {
 	int count = 0;
 
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		if (curByte == _vm->_rulesBuffer2_15[(32 * i)])
+		if (curByte == _vm->_characterVariables[(32 * i)])
 			++count;
 	}
 
@@ -1878,8 +1886,8 @@ byte LilliputScript::OC_sub178BA() {
 byte LilliputScript::OC_sub178C2() {
 	debugC(1, kDebugScript, "OC_sub178C2()");
 
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
-	if (_vm->_ptr_rulesBuffer2_15[2] == 1)
+	assert(_vm->_currentCharacterVariables != NULL);
+	if (_vm->_currentCharacterVariables[2] == 1)
 		return 1;
 	return 0;
 }
@@ -1901,7 +1909,7 @@ byte LilliputScript::OC_sub178D2() {
 byte LilliputScript::OC_sub178E8() {
 	debugC(1, kDebugScript, "OC_sub178E8()");
 
-	byte *bufPtr = getBuffer215Ptr();
+	byte *bufPtr = getCharacterVariablePtr();
 	byte var1 = bufPtr[0];
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 
@@ -1914,10 +1922,10 @@ byte LilliputScript::OC_sub178E8() {
 byte LilliputScript::OC_sub178FC() {
 	debugC(1, kDebugScript, "OC_sub178FC()");
 
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	assert(_vm->_currentCharacterVariables != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 
-	if (curByte <= _vm->_ptr_rulesBuffer2_15[0])
+	if (curByte <= _vm->_currentCharacterVariables[0])
 		return 1;
 	return 0;
 }
@@ -1938,10 +1946,10 @@ byte LilliputScript::OC_sub1790F() {
 byte LilliputScript::OC_sub1792A() {
 	debugC(1, kDebugScript, "OC_sub1792A()");
 
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	assert(_vm->_currentCharacterVariables != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 
-	if (_vm->_ptr_rulesBuffer2_15[1] == curByte)
+	if (_vm->_currentCharacterVariables[1] == curByte)
 		return 1;
 
 	return 0;
@@ -1953,7 +1961,7 @@ byte LilliputScript::OC_sub1793E() {
 	if (_vm->_currentScriptCharacterPosition == 0xFFFF)
 		return 0;
 
-	if (_vm->_array16E94[_vm->_rulesBuffer2PrevIndx] == 0)
+	if (_vm->_array16E94[_vm->currentScriptCharacter] == 0)
 		return 0;
 
 	return 1;
@@ -1962,8 +1970,8 @@ byte LilliputScript::OC_sub1793E() {
 byte LilliputScript::OC_sub1795E() {
 	debugC(1, kDebugScript, "OC_sub1795E()");
 
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
-	if (_vm->_ptr_rulesBuffer2_15[3] == 1)
+	assert(_vm->_currentCharacterVariables != NULL);
+	if (_vm->_currentCharacterVariables[3] == 1)
 		return 1;
 
 	return 0;
@@ -2016,8 +2024,8 @@ byte LilliputScript::OC_sub179C2() {
 	debugC(1, kDebugScript, "OC_sub179C2()");
 	int var1 = getValue2();
 
-	if ((_vm->_array10999[_vm->_rulesBuffer2PrevIndx] == (var1 >> 8))
-		 && (_vm->_array109C1[_vm->_rulesBuffer2PrevIndx] == (var1 & 0xFF)))
+	if ((_vm->_array10999[_vm->currentScriptCharacter] == (var1 >> 8))
+		 && (_vm->_array109C1[_vm->currentScriptCharacter] == (var1 & 0xFF)))
 		return 1;
 
 	return 0;
@@ -2099,7 +2107,7 @@ void LilliputScript::OC_sub17D57() {
 	if (forceReturnFl)
 		return;
 
-	_word1881B = _vm->_rulesBuffer2PrevIndx;
+	_word1881B = _vm->currentScriptCharacter;
 	sub18B3C(curWord);
 
 }
@@ -2133,7 +2141,7 @@ void LilliputScript::sub18B7C(int var1, int var3) {
 void LilliputScript::OC_sub17D7F() {
 	debugC(1, kDebugScript, "OC_sub17D7F()");
 
-	int var1 = getBuffer215Ptr()[0];
+	int var1 = getCharacterVariablePtr()[0];
 	int var2 = (_currScript->readUint16LE() & 0xFF);
 	int var3 = var1 / var2;
 	
@@ -2144,7 +2152,7 @@ void LilliputScript::OC_sub17D7F() {
 	if (forceReturnFl)
 		return;
 
-	_word1881B = _vm->_rulesBuffer2PrevIndx;
+	_word1881B = _vm->currentScriptCharacter;
 
 	sub18B7C(var1, var3);
 }
@@ -2188,7 +2196,7 @@ void LilliputScript::OC_sub17E15() {
 void LilliputScript::OC_sub17B03() {
 	debugC(1, kDebugScript, "OC_sub17B03()");
 
-	byte *bufPtr = getBuffer215Ptr();
+	byte *bufPtr = getCharacterVariablePtr();
 	int oper = _currScript->readUint16LE();
 	int var3 = _currScript->readUint16LE();
 
@@ -2198,7 +2206,7 @@ void LilliputScript::OC_sub17B03() {
 void LilliputScript::OC_getRandom_type2() {
 	debugC(1, kDebugScript, "OC_getRandom_type2()");
 
-	byte* bufPtr = getBuffer215Ptr();
+	byte* bufPtr = getCharacterVariablePtr();
 	int maxVal = _currScript->readUint16LE(); 
 	int randomVal = _vm->_rnd->getRandomNumber(maxVal);
 	*bufPtr = randomVal;
@@ -2264,15 +2272,15 @@ void LilliputScript::OC_incByte16F04() {
 void LilliputScript::OC_sub17BA5() {
 	debugC(1, kDebugScript, "OC_sub17BA5()");
 	
-	byte *tmpArr = getBuffer215Ptr();
+	byte *tmpArr = getCharacterVariablePtr();
 	byte oper = (_currScript->readUint16LE() & 0xFF);
-	byte var3 = getBuffer215Ptr()[0];
+	byte var3 = getCharacterVariablePtr()[0];
 	computeOperation(tmpArr, oper, var3);
 }
 
 void LilliputScript::OC_setByte18823() {
 	debugC(1, kDebugScript, "OC_setByte18823()");
-	byte *tmpArr = getBuffer215Ptr();
+	byte *tmpArr = getCharacterVariablePtr();
 	_byte18823 = *tmpArr;
 }
 
@@ -2283,7 +2291,7 @@ void LilliputScript::OC_callScript() {
 	int var1 = getValue1();
 
 	_vm->sub170EE(var1);
-	int tmpIndex = _vm->_rulesBuffer2PrevIndx;
+	int tmpIndex = _vm->currentScriptCharacter;
 
 	assert(index < _vm->_gameScriptIndexSize);
 	int scriptIndex = _vm->_arrayGameScriptIndex[index];
@@ -2313,9 +2321,9 @@ void LilliputScript::OC_sub17ACC() {
 	debugC(1, kDebugScript, "OC_sub17ACC()");
 
 	int var = getValue2();
-	_vm->_array10999[_vm->_rulesBuffer2PrevIndx] = var >> 8;
-	_vm->_array109C1[_vm->_rulesBuffer2PrevIndx] = var & 0xFF;
-	_vm->_array109E9[_vm->_rulesBuffer2PrevIndx] = 0xFF;
+	_vm->_array10999[_vm->currentScriptCharacter] = var >> 8;
+	_vm->_array109C1[_vm->currentScriptCharacter] = var & 0xFF;
+	_vm->_array109E9[_vm->currentScriptCharacter] = 0xFF;
 }
 
 void LilliputScript::OC_resetByte16F04() {
@@ -2328,14 +2336,14 @@ void LilliputScript::OC_sub17AE1() {
 	debugC(1, kDebugScript, "OC_sub17AE1()");
 
 	byte var3 = (_currScript->readUint16LE() & 0xFF);
-	sub16C5C(_vm->_rulesBuffer2PrevIndx, var3);
+	sub16C5C(_vm->currentScriptCharacter, var3);
 }
 
 void LilliputScript::OC_sub17AEE() {
 	debugC(1, kDebugScript, "OC_sub17AEE()");
 
 	byte var3 = (_currScript->readUint16LE() & 0xFF);
-	sub16C5C(_vm->_rulesBuffer2PrevIndx + 1, var3);
+	sub16C5C(_vm->currentScriptCharacter + 1, var3);
 }
 
 void LilliputScript::OC_setWord10804() {
@@ -2347,13 +2355,13 @@ void LilliputScript::OC_setWord10804() {
 void LilliputScript::OC_sub17C0E() {
 	debugC(1, kDebugScript, "OC_sub17C0E()");
 
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
-	byte var1 = (_vm->_ptr_rulesBuffer2_15[4] << 8) + _vm->_ptr_rulesBuffer2_15[5];
-	byte b2 = _vm->_ptr_rulesBuffer2_15[6];
+	assert(_vm->_currentCharacterVariables != NULL);
+	byte var1 = (_vm->_currentCharacterVariables[4] << 8) + _vm->_currentCharacterVariables[5];
+	byte b2 = _vm->_currentCharacterVariables[6];
 
 	byte *mapPtr = getMapPtr(var1);
-	mapPtr[b2] = _vm->_ptr_rulesBuffer2_15[7];
-	mapPtr[3] = _vm->_ptr_rulesBuffer2_15[8];
+	mapPtr[b2] = _vm->_currentCharacterVariables[7];
+	mapPtr[3] = _vm->_currentCharacterVariables[8];
 
 	if (b2 == 0) {
 		_byte12A09 = 1;
@@ -2379,7 +2387,7 @@ void LilliputScript::OC_sub17C76() {
 	
 	int var1 = getValue1();
 	_vm->_rulesBuffer2_5[var1] = 0xFF;
-	_vm->_rulesBuffer2_3[var1] = 0;
+	_vm->_characterPositionAltitude[var1] = 0;
 	_characterScriptEnabled[var1] = 1;
 
 }
@@ -2409,7 +2417,7 @@ void LilliputScript::OC_sub17C8B() {
 	int var1 = 2 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->_rulesBuffer2PrevIndx;
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2420,7 +2428,7 @@ void LilliputScript::OC_sub17CA2() {
 	int var1 = 1 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->_rulesBuffer2PrevIndx;
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2431,7 +2439,7 @@ void LilliputScript::OC_sub17CB9() {
 	int var4 = _currScript->readUint16LE();
 	int var1 = getValue1();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->_rulesBuffer2PrevIndx;
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2442,7 +2450,7 @@ void LilliputScript::OC_sub17CD1() {
 	int var1 = 3 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->_rulesBuffer2PrevIndx;
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2457,15 +2465,15 @@ void LilliputScript::OC_sub17CEF() {
 	debugC(1, kDebugScript, "OC_sub17CEF()");
 
 	int var1 = _currScript->readUint16LE();
-	sub1823E(_vm->_rulesBuffer2PrevIndx , var1, _vm->_ptr_rulesBuffer2_15);
+	sub1823E(_vm->currentScriptCharacter , var1, _vm->_currentCharacterVariables);
 	sub17B6C(0);
 }
 
 void LilliputScript::OC_sub17D1B() {
 	debugC(1, kDebugScript, "OC_sub17D1B()");
 
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
-	++_vm->_ptr_rulesBuffer2_15[1];
+	assert(_vm->_currentCharacterVariables != NULL);
+	++_vm->_currentCharacterVariables[1];
 }
 
 void LilliputScript::OC_sub17D23() {
@@ -2473,7 +2481,7 @@ void LilliputScript::OC_sub17D23() {
 
 	int var1 = _currScript->readUint16LE();
 	int var2 = getValue2();
-	byte* buf = _vm->_ptr_rulesBuffer2_15 + 4;
+	byte* buf = _vm->_currentCharacterVariables + 4;
 	computeOperation(buf, var1, var2 >> 8);
 	computeOperation(buf + 1, var1, var2 & 0xFF);
 }
@@ -2482,7 +2490,7 @@ void LilliputScript::OC_sub17E6D() {
 	debugC(1, kDebugScript, "OC_sub17E6D()");
 	
 	int var1 = _currScript->readUint16LE();
-	_vm->_rulesBuffer2_12[_vm->_rulesBuffer2PrevIndx] = (var1 - 2000) & 0xFF;
+	_vm->_rulesBuffer2_12[_vm->currentScriptCharacter] = (var1 - 2000) & 0xFF;
 }
 
 void LilliputScript::OC_changeCurrentCharacterSprite() {
@@ -2490,8 +2498,8 @@ void LilliputScript::OC_changeCurrentCharacterSprite() {
 
 	int var1 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	_vm->_characterFrameArray[_vm->_rulesBuffer2PrevIndx] = var1;
-	_vm->_spriteSizeArray[_vm->_rulesBuffer2PrevIndx] = var2;
+	_vm->_characterFrameArray[_vm->currentScriptCharacter] = var1;
+	_vm->_spriteSizeArray[_vm->currentScriptCharacter] = var2;
 
 }
 
@@ -2499,7 +2507,7 @@ byte *LilliputScript::sub173D2() {
 	debugC(2, kDebugScript, "sub173D2()");
 
 	int index = _currScript->readUint16LE();	
-	return &_vm->_ptr_rulesBuffer2_15[index];
+	return &_vm->_currentCharacterVariables[index];
 }
 
 void LilliputScript::OC_sub17E99() {
@@ -2538,9 +2546,9 @@ void LilliputScript::OC_sub17EF4() {
 	debugC(1, kDebugScript, "OC_sub17EF4()");
 
 	int var1 = getValue2();
-	int posTile = sub17285(_vm->_rulesBuffer2PrevIndx);
+	int posTile = sub17285(_vm->currentScriptCharacter);
 	int dir = _vm->sub16B0C(posTile, var1);
-	_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx] = dir;
+	_vm->_characterDirectionArray[_vm->currentScriptCharacter] = dir;
 }
 
 void LilliputScript::OC_sub17F08() {
@@ -2550,8 +2558,8 @@ void LilliputScript::OC_sub17F08() {
 
 	static const byte _directionsArray[] = { 0, 2, 0, 1, 3, 2, 3, 1 };
 
-	int dx = _vm->_characterPositionX[index] - _vm->_characterDisplayX[_vm->_rulesBuffer2PrevIndx];
-	int dy = _vm->_characterPositionY[index] - _vm->_characterDisplayY[_vm->_rulesBuffer2PrevIndx];
+	int dx = _vm->_characterPositionX[index] - _vm->_characterDisplayX[_vm->currentScriptCharacter];
+	int dy = _vm->_characterPositionY[index] - _vm->_characterDisplayY[_vm->currentScriptCharacter];
 
 	int flag = 0;
 	if (dx < 0) {
@@ -2566,27 +2574,27 @@ void LilliputScript::OC_sub17F08() {
 		flag |= 1;
 	}
 
-	_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx] = _directionsArray[flag];
+	_vm->_characterDirectionArray[_vm->currentScriptCharacter] = _directionsArray[flag];
 }
 
 void LilliputScript::OC_sub17F4F() {
 	debugC(1, kDebugScript, "OC_sub17F4F()");
 	int var = getValue1();
-	_array10A39[_vm->_rulesBuffer2PrevIndx] = var;
-	_vm->_array109E9[_vm->_rulesBuffer2PrevIndx] = 0xFF;
+	_array10A39[_vm->currentScriptCharacter] = var;
+	_vm->_array109E9[_vm->currentScriptCharacter] = 0xFF;
 }
 
 void LilliputScript::OC_sub17F68() {
-	if (_vm->_rulesBuffer2PrevIndx != _viewportCharacterTarget)
+	if (_vm->currentScriptCharacter != _viewportCharacterTarget)
 		return;
 
 	static const byte _byte_17F60[] = { 0xFF, 0xFD, 0xFD, 0xFA };
 	static const byte _byte_17F64[] = { 0xFD, 0xFA, 0xFF, 0xFD };
 	
-	int cx = _byte_17F60[_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx]];
-	int cy = _byte_17F64[_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx]];
+	int cx = _byte_17F60[_vm->_characterDirectionArray[_vm->currentScriptCharacter]];
+	int cy = _byte_17F64[_vm->_characterDirectionArray[_vm->currentScriptCharacter]];
 
-	int pos = sub17285(_vm->_rulesBuffer2PrevIndx);
+	int pos = sub17285(_vm->currentScriptCharacter);
 
 	int posx = pos >> 8;
 	int posy = pos & 0xFF;
@@ -2619,7 +2627,7 @@ void LilliputScript::OC_sub17FD2() {
 	debugC(1, kDebugScript, "OC_sub17FD2()");
 	
 	int var1 = getValue1();
-	_vm->_ptr_rulesBuffer2_15[6] = var1 & 0xFF;
+	_vm->_currentCharacterVariables[6] = var1 & 0xFF;
 
 }
 
@@ -2628,10 +2636,10 @@ void LilliputScript::OC_sub17FDD() {
 
 	int index = _currScript->readUint16LE();
 	
-	int tmpVal = (_vm->_rulesBuffer2PrevIndx * 32) + index;
+	int tmpVal = (_vm->currentScriptCharacter * 32) + index;
 	assert (tmpVal < 40 * 32);
-	_array10AB1[_vm->_rulesBuffer2PrevIndx] = _vm->_rulesBuffer2_16[tmpVal];
-	_array12811[_vm->_rulesBuffer2PrevIndx] = 16;
+	_array10AB1[_vm->currentScriptCharacter] = _vm->_rulesBuffer2_16[tmpVal];
+	_array12811[_vm->currentScriptCharacter] = 16;
 }
 
 void LilliputScript::OC_setByte10B29() {
@@ -2644,15 +2652,15 @@ void LilliputScript::OC_sub18007() {
 	debugC(1, kDebugScript, "OC_sub18007()");
 
 	int curWord = _currScript->readUint16LE();
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
-	_vm->_ptr_rulesBuffer2_15[2] = curWord & 0xFF;
+	assert(_vm->_currentCharacterVariables != NULL);
+	_vm->_currentCharacterVariables[2] = curWord & 0xFF;
 }
 
 void LilliputScript::OC_sub18014() {
 	debugC(1, kDebugScript, "OC_sub18014()");
 
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
-	_vm->_ptr_rulesBuffer2_15[2] = 0;
+	assert(_vm->_currentCharacterVariables != NULL);
+	_vm->_currentCharacterVariables[2] = 0;
 }
 
 void LilliputScript::OC_sub1801D() {
@@ -2668,7 +2676,7 @@ void LilliputScript::OC_sub1801D() {
 	y += _currScript->readUint16LE();
 	_vm->_characterPositionY[var1] = y;
 
-	_vm->_rulesBuffer2_3[var1]  = _currScript->readUint16LE();
+	_vm->_characterPositionAltitude[var1]  = _currScript->readUint16LE();
 	_vm->_characterDirectionArray[var1] = _currScript->readUint16LE();
 
 }
@@ -2685,13 +2693,13 @@ void LilliputScript::OC_sub18074() {
 	int var2 = _currScript->readUint16LE();
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
 
-	_vm->_rulesBuffer2_16[(_vm->_rulesBuffer2PrevIndx * 32) + var2] = var1;
+	_vm->_rulesBuffer2_16[(_vm->currentScriptCharacter * 32) + var2] = var1;
 }
 
 void LilliputScript::OC_setCurrentCharacterDirection() {
 	debugC(1, kDebugScript, "OC_setCurrentCharacterDirection()");
 
-	_vm->_characterDirectionArray[_vm->_rulesBuffer2PrevIndx] = (_currScript->readUint16LE() & 0xFF);
+	_vm->_characterDirectionArray[_vm->currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub18099() {
@@ -2752,7 +2760,7 @@ void LilliputScript::OC_sub1810A() {
 void LilliputScript::OC_sub1812D() {
 	debugC(1, kDebugScript, "OC_sub1812D()");
 
-	_vm->_rulesBuffer2_3[_vm->_rulesBuffer2PrevIndx] = (_currScript->readUint16LE() & 0xFF);
+	_vm->_characterPositionAltitude[_vm->currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub1817F() {
@@ -2789,7 +2797,7 @@ void LilliputScript::OC_sub181BB() {
 	int b = _currScript->readUint16LE();
 	int d = _currScript->readUint16LE() & 0xFF;
 	int s = _currScript->readUint16LE();
-	int c = _vm->_ptr_rulesBuffer2_15[s];
+	int c = _vm->_currentCharacterVariables[s];
 	int c2 = 0;
 
 	if ( d == 0x2D ) {
@@ -2827,7 +2835,7 @@ void LilliputScript::OC_sub18213() {
 			maxItem = _array1813B[i] >> 8;
 		}
 	}
-	sub1823E(_vm->_rulesBuffer2PrevIndx, maxItem, &_vm->_rulesBuffer2_15[var1]);
+	sub1823E(_vm->currentScriptCharacter, maxItem, &_vm->_characterVariables[var1]);
 }
 
 void LilliputScript::OC_sub18252() {
@@ -2861,7 +2869,7 @@ void LilliputScript::OC_sub18260() {
 void LilliputScript::OC_sub182EC() {
 	debugC(1, kDebugScript, "OC_sub182EC()");
 
-	byte *tmpArr = getBuffer215Ptr();
+	byte *tmpArr = getCharacterVariablePtr();
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
 	byte var2 = (_currScript->readUint16LE() & 0xFF);
@@ -2905,26 +2913,26 @@ void LilliputScript::OC_sub1834C() {
 	debugC(1, kDebugScript, "OC_sub1834C()");
 
 	byte curWord = _currScript->readUint16LE() & 0xFF;
-	assert(_vm->_ptr_rulesBuffer2_15 != NULL);
+	assert(_vm->_currentCharacterVariables != NULL);
 
-	_vm->_ptr_rulesBuffer2_15[3] = curWord;
+	_vm->_currentCharacterVariables[3] = curWord;
 }
 
 void LilliputScript::OC_setArray122C1() {
 	debugC(1, kDebugScript, "OC_setArray122C1()");
 
 	int var1 = _currScript->readUint16LE();
-	_array122C1[_vm->_rulesBuffer2PrevIndx] = var1;
+	_array122C1[_vm->currentScriptCharacter] = var1;
 }
 
 void LilliputScript::OC_sub18367() {
 	debugC(1, kDebugScript, "OC_sub18367()");
 
-	_characterScriptEnabled[_vm->_rulesBuffer2PrevIndx] = 1;
-	_vm->_ptr_rulesBuffer2_15[0] = _array122C1[_vm->_rulesBuffer2PrevIndx];
-	_vm->_ptr_rulesBuffer2_15[1] = 0;
-	_vm->_ptr_rulesBuffer2_15[2] = 0;
-	_vm->_ptr_rulesBuffer2_15[3] = 0;
+	_characterScriptEnabled[_vm->currentScriptCharacter] = 1;
+	_vm->_currentCharacterVariables[0] = _array122C1[_vm->currentScriptCharacter];
+	_vm->_currentCharacterVariables[1] = 0;
+	_vm->_currentCharacterVariables[2] = 0;
+	_vm->_currentCharacterVariables[3] = 0;
 }
 
 void LilliputScript::OC_sub17D04() {
@@ -2933,7 +2941,7 @@ void LilliputScript::OC_sub17D04() {
 	byte var1 = getValue1();
 	byte var2 = _currScript->readUint16LE() & 0xFF;
 	
-	sub1823E(var1, var2, &_vm->_rulesBuffer2_15[var1]);
+	sub1823E(var1, var2, &_vm->_characterVariables[var1]);
 }
 
 void LilliputScript::OC_sub18387() {
@@ -2996,7 +3004,7 @@ void LilliputScript::OC_sub1844A() {
 void LilliputScript::OC_sub1847F() {
 	debugC(1, kDebugScript, "OC_sub1847F()");
 
-	byte *buf215Ptr = getBuffer215Ptr();
+	byte *buf215Ptr = getCharacterVariablePtr();
 	byte tmpVal = buf215Ptr[0];
 	int curWord = _currScript->readUint16LE();
 	assert(curWord != 0);
@@ -3108,7 +3116,7 @@ void LilliputScript::OC_initArr18560() {
 
 void LilliputScript::OC_sub18678() {
 	debugC(1, kDebugScript, "OC_initArr18578()");
-	_savedBuffer215Ptr = getBuffer215Ptr();
+	_savedBuffer215Ptr = getCharacterVariablePtr();
 	_heroismBarX = _currScript->readUint16LE();
 	_heroismBarBottomY = _currScript->readUint16LE();
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index e964c3c..c5b67f8 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -33,6 +33,26 @@ namespace Lilliput {
 
 class LilliputEngine;
 
+enum KValueType {
+	kNone,
+	kImmediateValue,
+	kCompareOperation,
+	kComputeOperation,
+	kGetValue1,
+	kGetValue2,
+};
+
+
+struct OpCode {
+	const char* _opName;
+	int _numArgs;
+	KValueType _arg1;
+	KValueType _arg2;
+	KValueType _arg3;
+	KValueType _arg4;
+	KValueType _arg5;
+};
+
 class LilliputScript {
 public:
 	byte _byte12A04;
@@ -70,6 +90,7 @@ public:
 	~LilliputScript();
 
 	void disasmScript(ScriptStream script);
+	static Common::String getArgumentString(KValueType type, ScriptStream& script);
 	void runScript(ScriptStream script);
 	void runMenuScript(ScriptStream script);
 private:
@@ -121,7 +142,7 @@ private:
 	int getValue1();
 	int getValue2();
 
-	byte *getBuffer215Ptr();
+	byte *getCharacterVariablePtr();
 	byte compareValues(byte var1, int oper, int var2);
 	void computeOperation(byte *bufPtr, int oper, int var2);
 


Commit: 17998c7d459df41d4827344b6248804f9ee4f406
    https://github.com/scummvm/scummvm/commit/17998c7d459df41d4827344b6248804f9ee4f406
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Forgot to disable disasm

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3b44949..ae2515d 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2369,7 +2369,7 @@ void LilliputEngine::handleGameScripts() {
 	int tmpVal = _rulesBuffer2_12[index];
 	if (tmpVal == 0xFF)
 		return;
-
+/*
 	for (int i = 0; i < _gameScriptIndexSize; i++) {
 		assert(tmpVal < _gameScriptIndexSize);
 		debugC(1, kDebugEngine, "================= Game Script %d ==================", i);
@@ -2378,7 +2378,7 @@ void LilliputEngine::handleGameScripts() {
 		debugC(1, kDebugEngine, "============= End Game Script %d ==================", i);
 	}
 
-while(1);
+while(1);*/
 
 	assert(tmpVal < _gameScriptIndexSize);
 	debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index);


Commit: 8019c8b26ccbcce04c042d8ad70d18c51a2f432c
    https://github.com/scummvm/scummvm/commit/8019c8b26ccbcce04c042d8ad70d18c51a2f432c
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: rename one variable

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ae2515d..d3092a8 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -150,7 +150,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12FE3 = 0;
 	_byte16F08 = 0;
 
-	currentScriptCharacter = 0;
+	_currentScriptCharacter = 0;
 	_currentScriptCharacterPosition = 0;
 	_word10804 = 0;
 	_word17081_nextIndex = 0;
@@ -2307,14 +2307,14 @@ void LilliputEngine::initPalette() {
 void LilliputEngine::sub170EE(int index) {
 	debugC(1, kDebugEngine, "sub170EE(%d)", index);
 
-	currentScriptCharacter = index;
+	_currentScriptCharacter = index;
 
 	assert (index < 40);
 	int var2 = _characterPositionX[index];
 	int var4 = _characterPositionY[index];
 
 	_currentScriptCharacterPosition = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF);
-	_currentCharacterVariables = &_characterVariables[currentScriptCharacter * 32];
+	_currentCharacterVariables = &_characterVariables[_currentScriptCharacter * 32];
 }
 
 void LilliputEngine::sub130DD() {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index f8fab06..99d0eb4 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -147,7 +147,7 @@ public:
 	int _array12861[30];
 
 	byte *_rulesChunk1;
-	int currentScriptCharacter;
+	int _currentScriptCharacter;
 	int _characterPositionX[40];
 	int _characterPositionY[40];
 	byte _characterPositionAltitude[40];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 477912e..42eff08 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1113,7 +1113,7 @@ void LilliputScript::sub17D40(bool &forceReturnFl) {
 	debugC(1, kDebugScript, "sub17D40()");
 
 	forceReturnFl = false;
-	if ((_vm->_displayMap != 1) && (_vm->_characterRelativePositionX[_vm->currentScriptCharacter] != 0xFF))
+	if ((_vm->_displayMap != 1) && (_vm->_characterRelativePositionX[_vm->_currentScriptCharacter] != 0xFF))
 		return;
 
 	forceReturnFl = true;
@@ -1272,7 +1272,7 @@ int LilliputScript::getValue1() {
 	case 1000:
 		return (int)_byte129A0;
 	case 1001:
-		return _vm->currentScriptCharacter;
+		return _vm->_currentScriptCharacter;
 	case 1002:
 		return _word16F00;
 	case 1003:
@@ -1292,8 +1292,8 @@ int LilliputScript::getValue2() {
 	int tmpVal = curWord >> 8;
 	switch(tmpVal) {
 	case 0xFF:
-		assert((_vm->currentScriptCharacter >= 0) && (_vm->currentScriptCharacter < 40));
-		return ((_vm->_rulesBuffer2_13[_vm->currentScriptCharacter] << 8) + _vm->_rulesBuffer2_14[_vm->currentScriptCharacter]);
+		assert((_vm->_currentScriptCharacter >= 0) && (_vm->_currentScriptCharacter < 40));
+		return ((_vm->_rulesBuffer2_13[_vm->_currentScriptCharacter] << 8) + _vm->_rulesBuffer2_14[_vm->_currentScriptCharacter]);
 	case 0xFE: {
 		int index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
@@ -1318,7 +1318,7 @@ int LilliputScript::getValue2() {
 		return (var1 << 8) + var2;
 		}
 	case 0xFA:
-		return ((_vm->_array10999[_vm->currentScriptCharacter] << 8) + _vm->_array109C1[_vm->currentScriptCharacter]);
+		return ((_vm->_array10999[_vm->_currentScriptCharacter] << 8) + _vm->_array109C1[_vm->_currentScriptCharacter]);
 	case 0xF9:
 		return ((_vm->_currentCharacterVariables[4] << 8) + _vm->_currentCharacterVariables[5]);
 	case 0xF8: {
@@ -1566,7 +1566,7 @@ byte LilliputScript::OC_compWord16EF8() {
 	debugC(1, kDebugScript, "OC_compWord16EF8()");
 	
 	int tmpVal = getValue1();
-	if (tmpVal == _vm->currentScriptCharacter)
+	if (tmpVal == _vm->_currentScriptCharacter)
 		return 1;
 	return 0;
 }
@@ -1581,7 +1581,7 @@ byte LilliputScript::OC_sub175C8() {
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
-		int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + index];
+		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + index];
 		if ((var1 & 0xFF) < var4)
 			return 0;
 		
@@ -1591,7 +1591,7 @@ byte LilliputScript::OC_sub175C8() {
 
 	if (tmpVal == 3000) {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
-			int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + i];
+			int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
 			if ((var1 & 0xFF) >= var4) {
 				_word16F00 = i;
 				return 1;
@@ -1603,7 +1603,7 @@ byte LilliputScript::OC_sub175C8() {
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + i];
+		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
 		if ((var1 & 0xFF) >= var4) {
 			if (_vm->_rulesBuffer2_12[i] == var4b) {
 				_word16F00 = i;
@@ -1619,7 +1619,7 @@ byte LilliputScript::OC_sub17640() {
 	debugC(1, kDebugScript, "OC_sub176C4()");
 
 	int var4 = _currScript->readUint16LE();
-	int index = _vm->currentScriptCharacter * 40;
+	int index = _vm->_currentScriptCharacter * 40;
 	int subIndex = 0xFFFF;
 
 	int tmpVal = _currScript->readUint16LE();
@@ -1676,7 +1676,7 @@ byte LilliputScript::OC_sub176C4() {
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
-		int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + index];
+		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + index];
 		if (((var1 & 0xFF) >= var4) || ((var1 >> 8) < var4))
 			return 0;
 		
@@ -1686,7 +1686,7 @@ byte LilliputScript::OC_sub176C4() {
 
 	if (tmpVal == 3000) {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
-			int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + i];
+			int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
 			if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
 				_word16F00 = i;
 				return 1;
@@ -1698,7 +1698,7 @@ byte LilliputScript::OC_sub176C4() {
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		int var1 = _array10B51[(_vm->currentScriptCharacter * 40) + i];
+		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
 		if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
 			if (_vm->_rulesBuffer2_12[i] == var4b) {
 				_word16F00 = i;
@@ -1724,7 +1724,7 @@ byte LilliputScript::OC_sub17766() {
 	debugC(1, kDebugScript, "OC_sub17766()");
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
-	if ((var1 == _array12839[_vm->currentScriptCharacter]) && (_array12811[_vm->currentScriptCharacter] != 16))
+	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] != 16))
 		return 1;
 
 	return 0;
@@ -1734,7 +1734,7 @@ byte LilliputScript::OC_sub17782() {
 	debugC(1, kDebugScript, "OC_sub17782()");
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
-	if ((var1 == _array12839[_vm->currentScriptCharacter]) && (_array12811[_vm->currentScriptCharacter] == 16))
+	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] == 16))
 		return 1;
 
 	return 0;
@@ -1961,7 +1961,7 @@ byte LilliputScript::OC_sub1793E() {
 	if (_vm->_currentScriptCharacterPosition == 0xFFFF)
 		return 0;
 
-	if (_vm->_array16E94[_vm->currentScriptCharacter] == 0)
+	if (_vm->_array16E94[_vm->_currentScriptCharacter] == 0)
 		return 0;
 
 	return 1;
@@ -2024,8 +2024,8 @@ byte LilliputScript::OC_sub179C2() {
 	debugC(1, kDebugScript, "OC_sub179C2()");
 	int var1 = getValue2();
 
-	if ((_vm->_array10999[_vm->currentScriptCharacter] == (var1 >> 8))
-		 && (_vm->_array109C1[_vm->currentScriptCharacter] == (var1 & 0xFF)))
+	if ((_vm->_array10999[_vm->_currentScriptCharacter] == (var1 >> 8))
+		 && (_vm->_array109C1[_vm->_currentScriptCharacter] == (var1 & 0xFF)))
 		return 1;
 
 	return 0;
@@ -2107,7 +2107,7 @@ void LilliputScript::OC_sub17D57() {
 	if (forceReturnFl)
 		return;
 
-	_word1881B = _vm->currentScriptCharacter;
+	_word1881B = _vm->_currentScriptCharacter;
 	sub18B3C(curWord);
 
 }
@@ -2152,7 +2152,7 @@ void LilliputScript::OC_sub17D7F() {
 	if (forceReturnFl)
 		return;
 
-	_word1881B = _vm->currentScriptCharacter;
+	_word1881B = _vm->_currentScriptCharacter;
 
 	sub18B7C(var1, var3);
 }
@@ -2291,7 +2291,7 @@ void LilliputScript::OC_callScript() {
 	int var1 = getValue1();
 
 	_vm->sub170EE(var1);
-	int tmpIndex = _vm->currentScriptCharacter;
+	int tmpIndex = _vm->_currentScriptCharacter;
 
 	assert(index < _vm->_gameScriptIndexSize);
 	int scriptIndex = _vm->_arrayGameScriptIndex[index];
@@ -2321,9 +2321,9 @@ void LilliputScript::OC_sub17ACC() {
 	debugC(1, kDebugScript, "OC_sub17ACC()");
 
 	int var = getValue2();
-	_vm->_array10999[_vm->currentScriptCharacter] = var >> 8;
-	_vm->_array109C1[_vm->currentScriptCharacter] = var & 0xFF;
-	_vm->_array109E9[_vm->currentScriptCharacter] = 0xFF;
+	_vm->_array10999[_vm->_currentScriptCharacter] = var >> 8;
+	_vm->_array109C1[_vm->_currentScriptCharacter] = var & 0xFF;
+	_vm->_array109E9[_vm->_currentScriptCharacter] = 0xFF;
 }
 
 void LilliputScript::OC_resetByte16F04() {
@@ -2336,14 +2336,14 @@ void LilliputScript::OC_sub17AE1() {
 	debugC(1, kDebugScript, "OC_sub17AE1()");
 
 	byte var3 = (_currScript->readUint16LE() & 0xFF);
-	sub16C5C(_vm->currentScriptCharacter, var3);
+	sub16C5C(_vm->_currentScriptCharacter, var3);
 }
 
 void LilliputScript::OC_sub17AEE() {
 	debugC(1, kDebugScript, "OC_sub17AEE()");
 
 	byte var3 = (_currScript->readUint16LE() & 0xFF);
-	sub16C5C(_vm->currentScriptCharacter + 1, var3);
+	sub16C5C(_vm->_currentScriptCharacter + 1, var3);
 }
 
 void LilliputScript::OC_setWord10804() {
@@ -2417,7 +2417,7 @@ void LilliputScript::OC_sub17C8B() {
 	int var1 = 2 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->currentScriptCharacter;
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2428,7 +2428,7 @@ void LilliputScript::OC_sub17CA2() {
 	int var1 = 1 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->currentScriptCharacter;
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2439,7 +2439,7 @@ void LilliputScript::OC_sub17CB9() {
 	int var4 = _currScript->readUint16LE();
 	int var1 = getValue1();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->currentScriptCharacter;
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2450,7 +2450,7 @@ void LilliputScript::OC_sub17CD1() {
 	int var1 = 3 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->currentScriptCharacter;
+	var2 = ((var2 & 0xFF) << 8 ) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2465,7 +2465,7 @@ void LilliputScript::OC_sub17CEF() {
 	debugC(1, kDebugScript, "OC_sub17CEF()");
 
 	int var1 = _currScript->readUint16LE();
-	sub1823E(_vm->currentScriptCharacter , var1, _vm->_currentCharacterVariables);
+	sub1823E(_vm->_currentScriptCharacter , var1, _vm->_currentCharacterVariables);
 	sub17B6C(0);
 }
 
@@ -2490,7 +2490,7 @@ void LilliputScript::OC_sub17E6D() {
 	debugC(1, kDebugScript, "OC_sub17E6D()");
 	
 	int var1 = _currScript->readUint16LE();
-	_vm->_rulesBuffer2_12[_vm->currentScriptCharacter] = (var1 - 2000) & 0xFF;
+	_vm->_rulesBuffer2_12[_vm->_currentScriptCharacter] = (var1 - 2000) & 0xFF;
 }
 
 void LilliputScript::OC_changeCurrentCharacterSprite() {
@@ -2498,8 +2498,8 @@ void LilliputScript::OC_changeCurrentCharacterSprite() {
 
 	int var1 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	_vm->_characterFrameArray[_vm->currentScriptCharacter] = var1;
-	_vm->_spriteSizeArray[_vm->currentScriptCharacter] = var2;
+	_vm->_characterFrameArray[_vm->_currentScriptCharacter] = var1;
+	_vm->_spriteSizeArray[_vm->_currentScriptCharacter] = var2;
 
 }
 
@@ -2546,9 +2546,9 @@ void LilliputScript::OC_sub17EF4() {
 	debugC(1, kDebugScript, "OC_sub17EF4()");
 
 	int var1 = getValue2();
-	int posTile = sub17285(_vm->currentScriptCharacter);
+	int posTile = sub17285(_vm->_currentScriptCharacter);
 	int dir = _vm->sub16B0C(posTile, var1);
-	_vm->_characterDirectionArray[_vm->currentScriptCharacter] = dir;
+	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = dir;
 }
 
 void LilliputScript::OC_sub17F08() {
@@ -2558,8 +2558,8 @@ void LilliputScript::OC_sub17F08() {
 
 	static const byte _directionsArray[] = { 0, 2, 0, 1, 3, 2, 3, 1 };
 
-	int dx = _vm->_characterPositionX[index] - _vm->_characterDisplayX[_vm->currentScriptCharacter];
-	int dy = _vm->_characterPositionY[index] - _vm->_characterDisplayY[_vm->currentScriptCharacter];
+	int dx = _vm->_characterPositionX[index] - _vm->_characterDisplayX[_vm->_currentScriptCharacter];
+	int dy = _vm->_characterPositionY[index] - _vm->_characterDisplayY[_vm->_currentScriptCharacter];
 
 	int flag = 0;
 	if (dx < 0) {
@@ -2574,27 +2574,27 @@ void LilliputScript::OC_sub17F08() {
 		flag |= 1;
 	}
 
-	_vm->_characterDirectionArray[_vm->currentScriptCharacter] = _directionsArray[flag];
+	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = _directionsArray[flag];
 }
 
 void LilliputScript::OC_sub17F4F() {
 	debugC(1, kDebugScript, "OC_sub17F4F()");
 	int var = getValue1();
-	_array10A39[_vm->currentScriptCharacter] = var;
-	_vm->_array109E9[_vm->currentScriptCharacter] = 0xFF;
+	_array10A39[_vm->_currentScriptCharacter] = var;
+	_vm->_array109E9[_vm->_currentScriptCharacter] = 0xFF;
 }
 
 void LilliputScript::OC_sub17F68() {
-	if (_vm->currentScriptCharacter != _viewportCharacterTarget)
+	if (_vm->_currentScriptCharacter != _viewportCharacterTarget)
 		return;
 
 	static const byte _byte_17F60[] = { 0xFF, 0xFD, 0xFD, 0xFA };
 	static const byte _byte_17F64[] = { 0xFD, 0xFA, 0xFF, 0xFD };
 	
-	int cx = _byte_17F60[_vm->_characterDirectionArray[_vm->currentScriptCharacter]];
-	int cy = _byte_17F64[_vm->_characterDirectionArray[_vm->currentScriptCharacter]];
+	int cx = _byte_17F60[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
+	int cy = _byte_17F64[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
 
-	int pos = sub17285(_vm->currentScriptCharacter);
+	int pos = sub17285(_vm->_currentScriptCharacter);
 
 	int posx = pos >> 8;
 	int posy = pos & 0xFF;
@@ -2636,10 +2636,10 @@ void LilliputScript::OC_sub17FDD() {
 
 	int index = _currScript->readUint16LE();
 	
-	int tmpVal = (_vm->currentScriptCharacter * 32) + index;
+	int tmpVal = (_vm->_currentScriptCharacter * 32) + index;
 	assert (tmpVal < 40 * 32);
-	_array10AB1[_vm->currentScriptCharacter] = _vm->_rulesBuffer2_16[tmpVal];
-	_array12811[_vm->currentScriptCharacter] = 16;
+	_array10AB1[_vm->_currentScriptCharacter] = _vm->_rulesBuffer2_16[tmpVal];
+	_array12811[_vm->_currentScriptCharacter] = 16;
 }
 
 void LilliputScript::OC_setByte10B29() {
@@ -2693,13 +2693,13 @@ void LilliputScript::OC_sub18074() {
 	int var2 = _currScript->readUint16LE();
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
 
-	_vm->_rulesBuffer2_16[(_vm->currentScriptCharacter * 32) + var2] = var1;
+	_vm->_rulesBuffer2_16[(_vm->_currentScriptCharacter * 32) + var2] = var1;
 }
 
 void LilliputScript::OC_setCurrentCharacterDirection() {
 	debugC(1, kDebugScript, "OC_setCurrentCharacterDirection()");
 
-	_vm->_characterDirectionArray[_vm->currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
+	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub18099() {
@@ -2760,7 +2760,7 @@ void LilliputScript::OC_sub1810A() {
 void LilliputScript::OC_sub1812D() {
 	debugC(1, kDebugScript, "OC_sub1812D()");
 
-	_vm->_characterPositionAltitude[_vm->currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
+	_vm->_characterPositionAltitude[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub1817F() {
@@ -2835,7 +2835,7 @@ void LilliputScript::OC_sub18213() {
 			maxItem = _array1813B[i] >> 8;
 		}
 	}
-	sub1823E(_vm->currentScriptCharacter, maxItem, &_vm->_characterVariables[var1]);
+	sub1823E(_vm->_currentScriptCharacter, maxItem, &_vm->_characterVariables[var1]);
 }
 
 void LilliputScript::OC_sub18252() {
@@ -2922,14 +2922,14 @@ void LilliputScript::OC_setArray122C1() {
 	debugC(1, kDebugScript, "OC_setArray122C1()");
 
 	int var1 = _currScript->readUint16LE();
-	_array122C1[_vm->currentScriptCharacter] = var1;
+	_array122C1[_vm->_currentScriptCharacter] = var1;
 }
 
 void LilliputScript::OC_sub18367() {
 	debugC(1, kDebugScript, "OC_sub18367()");
 
-	_characterScriptEnabled[_vm->currentScriptCharacter] = 1;
-	_vm->_currentCharacterVariables[0] = _array122C1[_vm->currentScriptCharacter];
+	_characterScriptEnabled[_vm->_currentScriptCharacter] = 1;
+	_vm->_currentCharacterVariables[0] = _array122C1[_vm->_currentScriptCharacter];
 	_vm->_currentCharacterVariables[1] = 0;
 	_vm->_currentCharacterVariables[2] = 0;
 	_vm->_currentCharacterVariables[3] = 0;


Commit: 3f10768dc1d78f8c8b95b73e52ae3a78eb1d392b
    https://github.com/scummvm/scummvm/commit/3f10768dc1d78f8c8b95b73e52ae3a78eb1d392b
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix draw interface icons

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index d3092a8..9fa1f15 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -464,7 +464,7 @@ void LilliputEngine::displayFunction8() {
 
 	int index = 0;
 	int tmpVal;
-	for (int i = 0; i < _word12F68_ERULES; i++) {
+	for (index = 0; index < _word12F68_ERULES; index++) {
 		tmpVal = ((_scriptHandler->_array122E9[index] << 2) + (_scriptHandler->_array122E9[index] << 4)) & 0xFF;
 		displayFunction1(_bufferIdeogram, tmpVal + index, _rulesBuffer13_2[index], _rulesBuffer13_3[index]);
 	}
@@ -591,6 +591,7 @@ void LilliputEngine::displayFunction12() {
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
 
+
 	displayFunction6();
 	displayFunction7();
 	displayFunction8();


Commit: 2861a3f5ec0e57efc1190d82a2a5eed526897e56
    https://github.com/scummvm/scummvm/commit/2861a3f5ec0e57efc1190d82a2a5eed526897e56
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix some bugs of sub16626

Unsigned/signed

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 9fa1f15..6937a35 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1428,7 +1428,7 @@ void LilliputEngine::sub16626() {
 				break;
 
 			var2 = (2 * (var2 & 0xFF)) + (index << 5);
-			int var1 = _scriptHandler->_array12311[var2 / 2];
+			uint16 var1 = _scriptHandler->_array12311[var2 / 2];
 			int tmpVal = var2;
 			var2 = ((var1 >> 8) >> 3);
 			var2 &= 0xFE;
@@ -1466,7 +1466,9 @@ void LilliputEngine::sub16626() {
 				warning("result = sub_166F7");
 				break;
 			case 15:
-				warning("result = sub_166EA");
+				_scriptHandler->_array12811[index] = 0x10;
+				_scriptHandler->_characterScriptEnabled[index] = 1;
+				result = 1;
 				break;
 			default:
 				warning("sub16626 - unexpected value %d", var2 / 2);
@@ -2386,6 +2388,10 @@ while(1);*/
 	_scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
 	debugC(1, kDebugEngine, "============= End Game Script %d for character %d ==================", tmpVal, index);
 
+
+	//warning("dump char stat");
+	i = index;
+	warning("char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], _characterVariables[i*32+0], _scriptHandler->_characterScriptEnabled[i]);
 }
 
 Common::Error LilliputEngine::run() {
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 42eff08..21238aa 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2835,7 +2835,7 @@ void LilliputScript::OC_sub18213() {
 			maxItem = _array1813B[i] >> 8;
 		}
 	}
-	sub1823E(_vm->_currentScriptCharacter, maxItem, &_vm->_characterVariables[var1]);
+	sub1823E(_vm->_currentScriptCharacter, maxItem, _vm->_currentCharacterVariables);
 }
 
 void LilliputScript::OC_sub18252() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index c5b67f8..3df23d7 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -79,7 +79,7 @@ public:
 	int _heroismBarBottomY;
 	int _word1855E;
 
-	short _array12311[640];
+	uint16 _array12311[640];
 	byte _array128EF[40];
 	byte _array12839[40];
 	int _array1813B[32];


Commit: 18029a5597bee268986a02a8d04df122ba7bfc3b
    https://github.com/scummvm/scummvm/commit/18029a5597bee268986a02a8d04df122ba7bfc3b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement case 14 in sub16626, little clean up in sub1823e

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6937a35..cfb3d1e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1234,7 +1234,7 @@ void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
 	if ((_nextDisplayCharacterX != x) || (_nextDisplayCharacterY != y))
 		return;
 
-	byte _byte16552 = 0;
+	_byte16552 = 0;
 
 	if (buf[1] != 0xFF) {
 		int tmpIndex = buf[1];
@@ -1463,7 +1463,7 @@ void LilliputEngine::sub16626() {
 				warning("result = sub_16722");
 				break;
 			case 14:
-				warning("result = sub_166F7");
+				result = sub166F7(index, var1, tmpVal);
 				break;
 			case 15:
 				_scriptHandler->_array12811[index] = 0x10;
@@ -1485,8 +1485,28 @@ void LilliputEngine::sub16626() {
 	}
 }
 
-int LilliputEngine::sub166DD(int index, int var1) {
+byte LilliputEngine::sub166F7(int index, int var1, int tmpVal) {
+	debugC(2, kDebugEngine, "sub166F7(%d, %d, %d)", index, var1, tmpVal);
+
+	byte a1 = (var1 >> 8);
+	byte a2 = (var1 & 0xFF);
+	if (a2 != 0) {
+		if ((a2 & 0xF0) == 0)
+			a2 |= (a2 << 4);
+
+		a2 -= 16;
+		_scriptHandler->_array12311[tmpVal] = (a1 << 8) + a2;
+
+		if ((a2 & 0xF0) == 0)
+			return 2;
+	}
+
+	_scriptHandler->_array12811[index] -= ((var1 >> 8) & 0x0F);
+	return 3;
+}
 
+int LilliputEngine::sub166DD(int index, int var1) {
+	
 	_characterDirectionArray[index] = (var1 >> 8) & 3;
 	sub16685(index, var1 & 0xFF);
 	return 0;
@@ -2391,7 +2411,7 @@ while(1);*/
 
 	//warning("dump char stat");
 	i = index;
-	warning("char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], _characterVariables[i*32+0], _scriptHandler->_characterScriptEnabled[i]);
+	debugC(3, kDebugEngine, "char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], _characterVariables[i*32+0], _scriptHandler->_characterScriptEnabled[i]);
 }
 
 Common::Error LilliputEngine::run() {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 99d0eb4..1d01841 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -292,7 +292,7 @@ public:
 	void sub16B31(int index, int val);
 	void sub16B8F(int index, int x, int y, int flag);
 	int sub1675D(int index, int var1);
-
+	byte sub166F7(int index, int var1, int tmpVal);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 21238aa..624049f 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1045,12 +1045,12 @@ void LilliputScript::sub185B4_display() {
 	_word1855E = subIndex;
 }
 
-void LilliputScript::sub1823E(byte var1, byte var2, byte *curBufPtr) {
-	debugC(1, kDebugScript, "sub1823E(%d, %d, curBufPtr)", var1, var2);
+void LilliputScript::sub1823E(byte index, byte var1, byte *curBufPtr) {
+	debugC(1, kDebugScript, "sub1823E(%d, %d, curBufPtr)", index, var1);
 
-	assert ((var1 >= 0) && (var1 < 40));
-	_characterScriptEnabled[var1] = 1;
-	curBufPtr[0] = var2;
+	assert (index < 40);
+	_characterScriptEnabled[index] = 1;
+	curBufPtr[0] = var1;
 	curBufPtr[1] = 0;
 	curBufPtr[2] = 0;
 	curBufPtr[3] = 0;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 3df23d7..2a16b62 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -123,7 +123,7 @@ private:
 	
 	void sub185ED(byte index, byte subIndex);
 	void sub185B4_display();
-	void sub1823E(byte var1, byte var2, byte *curBufPtr);
+	void sub1823E(byte index, byte var1, byte *curBufPtr);
 	void sub17B6C(int var1);
 	void sub16C86(int index, byte *buf);
 	void sub16C5C(int index, byte var3);


Commit: f17868ebd9d5570881777d8e8d1aec0611bea738
    https://github.com/scummvm/scummvm/commit/f17868ebd9d5570881777d8e8d1aec0611bea738
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement 4 core functions

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index cfb3d1e..7002b2e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -132,6 +132,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_scriptHandler = new LilliputScript(this);
 	_soundHandler = new LilliputSound(this);
 
+	_byte16939 = 0;
 	_byte1714E = 0;
 	_byte12FCE = 0;
 	_byte129A0 = 0xFF;
@@ -176,6 +177,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	for (int i = 0; i < 3; i++)
 		_array147D1[i] = 0;
 
+	for (int i = 0; i < 4; i++)
+		_array1692B[i] = 0;
+
 	for (int i = 0; i < 40; i++) {
 		_array10999[i] = 0;
 		_array109C1[i] = 0;
@@ -1358,7 +1362,7 @@ int LilliputEngine::sub16799(int param1, int index) {
 
 	if (var3h != 0xFF) {
 		if ((var3h != _scriptHandler->_array16123[index]) || (var3l != _scriptHandler->_array1614B[index])) {
-			warning("sub_1693A");
+			sub1693A(index);
 			_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
 			return 3;
 		}
@@ -1373,12 +1377,132 @@ int LilliputEngine::sub16799(int param1, int index) {
 
 	_characterDirectionArray[index] = sub16B0C(var1, var2);
 
-	warning("sub_1693A");
+	sub1693A(index);
 	_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
 	return 3;
 
 }
 
+void LilliputEngine::sub1693A(int index) {
+	debugC(2, kDebugEngine, "sub1693A(%d)", index);
+	
+	static const uint16 _array1692F[4] = {4, 0xFF00, 0x100, 0xFFFC};
+
+	byte var1h = _scriptHandler->_array16123[index];
+	byte var1l = _scriptHandler->_array1614B[index];
+	_word16937 = (var1h << 8) + var1l;
+
+	sub16A08(index);
+	
+	int var2 = (_characterDirectionArray[index] ^ 3);
+	_array1692B[var2] += 0xF8;
+	_byte16939 = 0;
+	
+	int mapIndex = ((((var1l << 8) >> 2) + var1h) << 2);
+	int subMapIndex = 0;
+	int retVal = 0;
+	for (int i = 3; i >= 0; i--) {
+		subMapIndex = _array1692F[i];
+		if (((_bufferIsoMap[mapIndex + subMapIndex + 3] & _array16C54[i]) != 0) && ((_bufferIsoMap[mapIndex + 3] & _array16C58[i]) != 0)) {
+			if ((_bufferIsoMap[mapIndex + subMapIndex + 3] & 0x80) != 0) {
+				if (sub16A76(i, index) != 0)
+					_array1692B[i] += 0xEC;
+				
+				int tmpVal = ((_rulesBuffer2_10[index] & 7) ^ 7);
+				retVal = _rulesChunk9[_bufferIsoMap[mapIndex + subMapIndex]];
+				tmpVal &= retVal;
+				if (tmpVal == 0)
+					continue;
+			}
+		}
+		_array1692B[i] = 0x9E;
+		++_byte16939;
+	}
+
+	if (_byte16939 != 0)
+		_array1692B[_characterDirectionArray[index]] += 3;
+
+	int tmpVal = 0x9D;
+	for (int i = 3; i >= 0; i--) {
+		if (tmpVal < _array1692B[i]) {
+			retVal = i;
+			tmpVal = _array1692B[i];
+		}
+	}
+	
+	_characterDirectionArray[index] = retVal;
+}
+
+byte LilliputEngine::sub16A76(int indexb, int indexs) {
+	debugC(2, kDebugEngine, "sub16A76(%d, %d)", indexb, indexs);
+
+	static const byte _array16A6C[4] = {1, 0, 0, 0xFF};
+	static const byte _array16A70[4] = {0, 0xFF, 1, 0};
+	   
+	byte var1h = (_word16937 >> 8) + _array16A6C[indexb];
+	byte var1l = (_word16937 & 0xFF) + _array16A70[indexs];
+
+	int var2 = sub168DA(var1h, var1l);
+	if (var2 == 0xFFFF)
+		return 1;
+
+	int _word16A74 = var2; // useless?
+
+	var1h = (_word16937 >> 8);
+	var1l = (_word16937 & 0xFF);
+
+	if ((var1h >= (_rulesBuffer12_1[var2] >> 8)) && (var1h <= (_rulesBuffer12_1[var2] & 0xFF)) && (var1l >= (_rulesBuffer12_2[var2] >> 8)) && (var1l <= (_rulesBuffer12_2[var2] & 0xFF)))
+		return 0;
+
+	var1h = _array109E9[indexs];
+	var1l = _array10A11[indexs];
+
+	if ((var1h >= (_rulesBuffer12_1[var2] >> 8)) && (var1h <= (_rulesBuffer12_1[var2] & 0xFF)) && (var1l >= (_rulesBuffer12_2[var2] >> 8)) && (var1l <= (_rulesBuffer12_2[var2] & 0xFF)))
+		return 0;
+
+	return 1;
+}
+
+uint16 LilliputEngine::sub168DA(byte var1h, byte var1l) {
+	debugC(2, kDebugEngine, "sub168DA(%d, %d)", var1h, var1l);
+
+	for (int i = 0; i < _rulesChunk12_size; i++) {
+		if ((var1h >= (_rulesBuffer12_1[i] >> 8)) && (var1h <= (_rulesBuffer12_1[i] & 0xFF)) && (var1h >= (_rulesBuffer12_2[i] >> 8)) && (var1h <= (_rulesBuffer12_2[i] & 0xFF)))
+			return i;
+	}
+	return 0xFFFF;
+}
+
+void LilliputEngine::sub16A08(int index) {
+	debugC(2, kDebugEngine, "sub16A08(%d)", index);
+
+	static const byte _array169F8[4] = {1, 0, 0, 0xFF};
+	static const byte _array169FC[4] = {0, 0xFF, 1, 0};
+
+	int _array16A00[4];
+
+	for (int i = 3; i >= 0; i--) {
+		byte var1h = (_word16937 >> 8) + _array169F8[i] - _array109E9[index];
+		byte var1l = (_word16937 & 0xFF) + _array169FC[i] - _array10A11[index];
+		_array16A00[i] = (var1l * var1l) + (var1h * var1h);
+	}
+	_array1692B[0] = 0;
+	_array1692B[2] = 0;
+
+	for (int i = 6; i > 0; i--) {
+		int tmpVal = 0x7FFF;
+		int tmpIndex = 0;
+		for (int j = 0; j < 4; j++) {
+			if (tmpVal > _array16A00[j]) {
+				tmpVal = _array16A00[j];
+				tmpIndex = j;
+			}
+		}
+		_array16A00[tmpIndex] = 0x7FFF;
+		_array1692B[tmpIndex] = i;
+	}
+}
+
 void LilliputEngine::addCharToBuf(byte character) {
 	debugC(2, kDebugEngine, "addCharToBuf(%c)", character);
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 1d01841..8394fd8 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -108,8 +108,10 @@ public:
 	byte _byte15EAD;
 	byte _debugFlag; // Mostly useless, as the associated functions are empty
 	byte _byte14837; // Unused byte, set by an opcode
+	byte _byte16939;
 
 	byte _array147D1[3];
+	byte _array1692B[4];
 	byte _buffer1[45056];
 	byte _buffer2[45056];
 	byte _buffer3[45056];
@@ -139,9 +141,10 @@ public:
 	int _currentDisplayCharacter;
 	int _displayStringIndex;
 	int _word1289D;
+	int _word16937;
+
 	short _word15E5D[40];
 	byte _byte15E35[40];
-
 	int _array11D49[40];
 	int _array1289F[40];
 	int _array12861[30];
@@ -247,9 +250,11 @@ public:
 	void viewportScrollTo(int var1, int var3);
 	void sub189DE();
 	void sub16626();
-
+	void sub16A08(int index);
+	byte sub16A76(int indexb, int indexs);
 	void sub17224(int var1, int var4);
 	void sub17264(int index, int var4);
+	uint16 sub168DA(byte var1h, byte var1l);
 
 	void renderCharacters(byte *buf, byte x, byte y);
 
@@ -293,6 +298,7 @@ public:
 	void sub16B8F(int index, int x, int y, int flag);
 	int sub1675D(int index, int var1);
 	byte sub166F7(int index, int var1, int tmpVal);
+	void sub1693A(int index);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, bool loadPal);


Commit: 61e5d395464ad8924a0885ce710acf3b91ccd710
    https://github.com/scummvm/scummvm/commit/61e5d395464ad8924a0885ce710acf3b91ccd710
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: 2 new subs

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7002b2e..f50a595 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1354,6 +1354,25 @@ int LilliputEngine::sub16B0C(int param1, int param2) {
 	return _array16B04[var2l];
 }
 
+int LilliputEngine::sub168DA(int x, int y) {
+
+	int* buffer1 = _rulesBuffer12_1;
+	int* buffer2 = _rulesBuffer12_2;
+
+	for (int i = 0; i < _rulesChunk12_size; i++) {
+		if(x >= (*buffer1 >> 8) && x <= (*buffer1 & 0xff)
+			&& y >= (*buffer2 >> 8) && y <= (*buffer2 & 0xff))
+		{
+			return buffer1 - _rulesBuffer12_1;
+		}
+
+		buffer2++;
+		buffer1++;
+	}
+
+	return -1;
+}
+
 int LilliputEngine::sub16799(int param1, int index) {
 	debugC(2, kDebugEngine, "sub16799(%d, %d)", param1, index);
 
@@ -1473,6 +1492,17 @@ uint16 LilliputEngine::sub168DA(byte var1h, byte var1l) {
 	return 0xFFFF;
 }
 
+uint16 LilliputEngine::sub_16901(byte var1h, byte var1l) {
+	debugC(2, kDebugEngine, "sub_16901(%d, %d)", var1h, var1l);
+
+	for (int i = _rulesChunk12_size-1; i >= 0 ; i--) {
+		if ((var1h >= (_rulesBuffer12_1[i] >> 8)) && (var1h <= (_rulesBuffer12_1[i] & 0xFF)) && (var1h >= (_rulesBuffer12_2[i] >> 8)) && (var1h <= (_rulesBuffer12_2[i] & 0xFF)))
+			return i;
+	}
+	return 0xFFFF;
+}
+
+
 void LilliputEngine::sub16A08(int index) {
 	debugC(2, kDebugEngine, "sub16A08(%d)", index);
 
@@ -1578,7 +1608,7 @@ void LilliputEngine::sub16626() {
 				result = sub1675D(index, var1);
 				break;
 			case 11:
-				warning("result = sub_16729");
+				result = sub16729(index);
 				break;
 			case 12:
 				result = sub16799(var1, index);
@@ -1636,6 +1666,14 @@ int LilliputEngine::sub166DD(int index, int var1) {
 	return 0;
 }
 
+int LilliputEngine::sub16729(int index) {
+	int arg1 = index | 0xFF00;
+	int pos1 = (_scriptHandler->_array16123[index] << 8) | (_scriptHandler->_array1614B[index] & 0xFF);
+	int pos2 = (_scriptHandler->_viewportX << 8) | (_scriptHandler->_viewportY & 0xFF);
+	_soundHandler->contentFct2(); // TODO: add arg pos1 and pos2
+	return 2;
+}
+
 int LilliputEngine::sub1675D(int index, int var1) {
 	debugC(2, kDebugEngine, "sub1675D(%d, %d)", index, var1);
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8394fd8..731cbfe 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -255,9 +255,11 @@ public:
 	void sub17224(int var1, int var4);
 	void sub17264(int index, int var4);
 	uint16 sub168DA(byte var1h, byte var1l);
+	uint16 sub_16901(byte var1h, byte var1l);
 
 	void renderCharacters(byte *buf, byte x, byte y);
 
+	int sub168DA(int x, int y);
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
 	void addCharToBuf(byte character);
@@ -297,6 +299,7 @@ public:
 	void sub16B31(int index, int val);
 	void sub16B8F(int index, int x, int y, int flag);
 	int sub1675D(int index, int var1);
+	int sub16729(int index);
 	byte sub166F7(int index, int var1, int tmpVal);
 	void sub1693A(int index);
 
@@ -333,7 +336,7 @@ public:
 	byte _byte12FCE;
 	byte _byte129A0;
 	byte _numCharactersToDisplay;
-	byte _byte16C9F; 
+	byte _byte16C9F;
 	int _word10804;
 	int _word16213;
 	int _word16215;


Commit: 864e66cdd2b2792d70d9c1083e297c9daee5b18b
    https://github.com/scummvm/scummvm/commit/864e66cdd2b2792d70d9c1083e297c9daee5b18b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Remove duplicated function

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index f50a595..93a3578 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1354,25 +1354,6 @@ int LilliputEngine::sub16B0C(int param1, int param2) {
 	return _array16B04[var2l];
 }
 
-int LilliputEngine::sub168DA(int x, int y) {
-
-	int* buffer1 = _rulesBuffer12_1;
-	int* buffer2 = _rulesBuffer12_2;
-
-	for (int i = 0; i < _rulesChunk12_size; i++) {
-		if(x >= (*buffer1 >> 8) && x <= (*buffer1 & 0xff)
-			&& y >= (*buffer2 >> 8) && y <= (*buffer2 & 0xff))
-		{
-			return buffer1 - _rulesBuffer12_1;
-		}
-
-		buffer2++;
-		buffer1++;
-	}
-
-	return -1;
-}
-
 int LilliputEngine::sub16799(int param1, int index) {
 	debugC(2, kDebugEngine, "sub16799(%d, %d)", param1, index);
 
@@ -1492,8 +1473,8 @@ uint16 LilliputEngine::sub168DA(byte var1h, byte var1l) {
 	return 0xFFFF;
 }
 
-uint16 LilliputEngine::sub_16901(byte var1h, byte var1l) {
-	debugC(2, kDebugEngine, "sub_16901(%d, %d)", var1h, var1l);
+uint16 LilliputEngine::sub16901(byte var1h, byte var1l) {
+	debugC(2, kDebugEngine, "sub16901(%d, %d)", var1h, var1l);
 
 	for (int i = _rulesChunk12_size-1; i >= 0 ; i--) {
 		if ((var1h >= (_rulesBuffer12_1[i] >> 8)) && (var1h <= (_rulesBuffer12_1[i] & 0xFF)) && (var1h >= (_rulesBuffer12_2[i] >> 8)) && (var1h <= (_rulesBuffer12_2[i] & 0xFF)))
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 731cbfe..cbe1c52 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -255,11 +255,10 @@ public:
 	void sub17224(int var1, int var4);
 	void sub17264(int index, int var4);
 	uint16 sub168DA(byte var1h, byte var1l);
-	uint16 sub_16901(byte var1h, byte var1l);
+	uint16 sub16901(byte var1h, byte var1l);
 
 	void renderCharacters(byte *buf, byte x, byte y);
 
-	int sub168DA(int x, int y);
 	int sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
 	void addCharToBuf(byte character);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 624049f..a213413 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -72,7 +72,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	}
 
 	for (int i = 0; i < 640; i++) {
-		_array12311[i] = -1;
+		_array12311[i] = 0xFFFF;
 	}
 }
 


Commit: d8f62c9780cdbc66d8402f0bd2abc972171b254f
    https://github.com/scummvm/scummvm/commit/d8f62c9780cdbc66d8402f0bd2abc972171b254f
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add a core function, make uniform the fonctions called by sub16626

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 93a3578..75358c3 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1354,8 +1354,8 @@ int LilliputEngine::sub16B0C(int param1, int param2) {
 	return _array16B04[var2l];
 }
 
-int LilliputEngine::sub16799(int param1, int index) {
-	debugC(2, kDebugEngine, "sub16799(%d, %d)", param1, index);
+byte LilliputEngine::sub16799(int index, int param1) {
+	debugC(2, kDebugEngine, "sub16799(%d, %d)", index, param1);
 
 	byte var3h = _array109E9[index];
 	byte var3l = _array10A11[index];
@@ -1554,7 +1554,7 @@ void LilliputEngine::sub16626() {
 	debugC(2, kDebugEngine, "sub16626()");
 
 	int index = _numCharacters - 1;
-	int result;
+	byte result;
 	while (index >= 0) {
 		result = 2;
 		while (result & 2) {
@@ -1592,18 +1592,16 @@ void LilliputEngine::sub16626() {
 				result = sub16729(index);
 				break;
 			case 12:
-				result = sub16799(var1, index);
+				result = sub16799(index, var1);
 				break;
 			case 13:
-				warning("result = sub_16722");
+				result = sub16722(index, var1);
 				break;
 			case 14:
 				result = sub166F7(index, var1, tmpVal);
 				break;
 			case 15:
-				_scriptHandler->_array12811[index] = 0x10;
-				_scriptHandler->_characterScriptEnabled[index] = 1;
-				result = 1;
+				result = sub166EA(index);
 				break;
 			default:
 				warning("sub16626 - unexpected value %d", var2 / 2);
@@ -1620,6 +1618,14 @@ void LilliputEngine::sub16626() {
 	}
 }
 
+byte LilliputEngine::sub166EA(int index) {
+	debugC(2, kDebugEngine, "sub166EA(%d, %d)", index);
+
+	_scriptHandler->_array12811[index] = 0x10;
+	_scriptHandler->_characterScriptEnabled[index] = 1;
+	return 1;
+}
+
 byte LilliputEngine::sub166F7(int index, int var1, int tmpVal) {
 	debugC(2, kDebugEngine, "sub166F7(%d, %d, %d)", index, var1, tmpVal);
 
@@ -1640,14 +1646,24 @@ byte LilliputEngine::sub166F7(int index, int var1, int tmpVal) {
 	return 3;
 }
 
-int LilliputEngine::sub166DD(int index, int var1) {
+byte LilliputEngine::sub166DD(int index, int var1) {
+	debugC(2, kDebugEngine, "sub166DD(%d, %d)", index, var1);
 	
 	_characterDirectionArray[index] = (var1 >> 8) & 3;
 	sub16685(index, var1 & 0xFF);
 	return 0;
 }
 
-int LilliputEngine::sub16729(int index) {
+byte LilliputEngine::sub16722(int index, byte var1) {
+	debugC(2, kDebugEngine, "sub16722(%d, %d)", index, var1);
+
+	_rulesBuffer2_10[index] = var1;
+	return 2;
+}
+
+byte LilliputEngine::sub16729(int index) {
+	debugC(2, kDebugEngine, "sub16729(%d)", index);
+
 	int arg1 = index | 0xFF00;
 	int pos1 = (_scriptHandler->_array16123[index] << 8) | (_scriptHandler->_array1614B[index] & 0xFF);
 	int pos2 = (_scriptHandler->_viewportX << 8) | (_scriptHandler->_viewportY & 0xFF);
@@ -1655,7 +1671,7 @@ int LilliputEngine::sub16729(int index) {
 	return 2;
 }
 
-int LilliputEngine::sub1675D(int index, int var1) {
+byte LilliputEngine::sub1675D(int index, int var1) {
 	debugC(2, kDebugEngine, "sub1675D(%d, %d)", index, var1);
 
 	int var2 = _scriptHandler->_array10A39[index];
@@ -1867,7 +1883,7 @@ void LilliputEngine::sub16685(int idx, int var1) {
 	_scriptHandler->_array10AB1[idx] = _rulesBuffer2_16[index];
 }
 
-int LilliputEngine::sub16675(int idx, int var1) {
+byte LilliputEngine::sub16675(int idx, int var1) {
 	debugC(2, kDebugEngine, "sub16675(%d, %d)", idx, var1);
 
 	sub16685(idx, var1);
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index cbe1c52..b2de857 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -256,19 +256,21 @@ public:
 	void sub17264(int index, int var4);
 	uint16 sub168DA(byte var1h, byte var1l);
 	uint16 sub16901(byte var1h, byte var1l);
+	byte sub16722(int index, byte var1);
+	byte sub166EA(int index);
 
 	void renderCharacters(byte *buf, byte x, byte y);
 
-	int sub16799(int param1, int index);
+	byte sub16799(int param1, int index);
 	int sub16B0C(int param1, int param2);
 	void addCharToBuf(byte character);
 	void prepareGoldAmount(int param1);
 	void sub12F37();
-	int sub16675(int idx, int var1);
+	byte sub16675(int idx, int var1);
 	void sub16685(int idx, int var1);
 	void sub16EBC();
 	void sub16CA0();
-	int sub166DD(int index, int var1);
+	byte sub166DD(int index, int var1);
 	void sub171CF();
 	void sub12FE5();
 	int sub16DD5(int x1, int y1, int x2, int y2);
@@ -297,8 +299,8 @@ public:
 	void sub166D8(int index);
 	void sub16B31(int index, int val);
 	void sub16B8F(int index, int x, int y, int flag);
-	int sub1675D(int index, int var1);
-	int sub16729(int index);
+	byte sub1675D(int index, int var1);
+	byte sub16729(int index);
 	byte sub166F7(int index, int var1, int tmpVal);
 	void sub1693A(int index);
 


Commit: ca2534dd6b5f6d3f4e8f2e440799bcada739041f
    https://github.com/scummvm/scummvm/commit/ca2534dd6b5f6d3f4e8f2e440799bcada739041f
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement two opcodes and 3 core functions

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 75358c3..860d2e1 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -328,7 +328,7 @@ void LilliputEngine::displayCharacter(int index, int x, int y, int flags) {
 		// Sprite mirror
 		for (int y = 0; y < 16; y++) {
 			for (int x = 0; x < 16; x++) {
-				// May need a hack of 1 pixel 
+				// May need a hack of 1 pixel
 				if (src[15 - x] != 0)
 					buf[x] = src[15 - x];
 			}
@@ -931,12 +931,12 @@ void LilliputEngine::sub15F75() {
 
 	_byte129A0 = 0xFF;
 	_savedMousePosDivided = 0xFFFF;
-	byte newX = _mouseX >> 2; 
+	byte newX = _mouseX >> 2;
 	byte newY = _mouseY / 3;
 
 	if ((newX >= 64) || (newY >= 64))
 		return;
-	
+
 	_savedMousePosDivided = (newX << 8) + newY;
 	_byte16F07_menuId = 5;
 }
@@ -965,7 +965,7 @@ void LilliputEngine::sub15F31(bool &forceReturnFl) {
 
 	_mouseButton = 0;
 	sub15F75();
-	
+
 	_displayMap = 0;
 	paletteFadeOut();
 	_word15AC2 = 0;
@@ -1080,6 +1080,38 @@ void LilliputEngine::displayFunction17() {
 	displayFunction4();
 }
 
+void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
+	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
+
+	displayFunction5();
+
+	if ((var1 & 0xFF) == 0x2D) {
+		var2 += 35;
+		var3 -= 35;
+
+		if (var3 < 0) {
+			var2 += var3;
+			var3 = -var3;
+		}
+	}
+
+	byte *vgaBuf = (byte *)_mainSurface->getPixels();
+	int tmpVal = (var3 >> 8) + ((var3 & 0xFF) << 8);
+	int vgaIndex = var2 + tmpVal + (tmpVal >> 2);
+
+	if (var3 == 0)
+		++var3;
+
+	for (int i = 0; i < 4; i++) {
+		for (int j = 0; j < var3; j++) {
+			vgaBuf[vgaIndex + j] = 2;
+		}
+		vgaIndex += 320;
+	}
+
+	displayFunction4();
+}
+
 void LilliputEngine::displayString(byte *buf, int var2, int var4) {
 	debugC(2, kDebugEngine, "displayString(buf, %d, %d)", var2, var4);
 
@@ -1371,7 +1403,8 @@ byte LilliputEngine::sub16799(int index, int param1) {
 			return 2;
 	}
 
-	warning("sub_167EF");
+	sub167EF(index);
+
 	int var1 = (_scriptHandler->_array16123[index] << 8) + _scriptHandler->_array1614B[index];
 	int var2 = (_array109E9[index] << 8) + _array10A11[index];
 
@@ -1383,9 +1416,81 @@ byte LilliputEngine::sub16799(int index, int param1) {
 
 }
 
+void LilliputEngine::sub167EF(int index) {
+	debugC(2, kDebugEngine, "sub167EF(%d)", index);
+
+	int word167EB = sub168DA(_scriptHandler->_array16123[index], _scriptHandler->_array1614B[index]);
+	int word167ED = sub168DA(_array10999[index], _array109C1[index]);
+
+	if (word167EB == word167ED) {
+		_array109E9[index] = _array10999[index];
+		_array10A11[index] = _array109C1[index];
+		return;
+	}
+
+	if (word167EB = 0xFFFF) {
+		int tmpVal = sub16901(_array10999[index], _array109C1[index]);
+		_array109E9[index] = (_rulesBuffer12_4[tmpVal] >> 8);
+		_array10A11[index] = (_rulesBuffer12_4[tmpVal] & 0xFF);
+		return;
+	}
+
+	if ((word167ED != 0xFFFF) &&
+		  (_array10999[index] >= (_rulesBuffer12_1[word167EB] >> 8)) &&
+		  (_array10999[index] <= (_rulesBuffer12_1[word167EB] & 0xFF)) &&
+		  (_array109C1[index] >= (_rulesBuffer12_2[word167EB] >> 8)) &&
+		  (_array109C1[index] <= (_rulesBuffer12_2[word167EB] & 0xFF)) ) {
+		_array109E9[index] = (_rulesBuffer12_4[word167ED] >> 8);
+		_array10A11[index] = (_rulesBuffer12_4[word167ED] & 0xFF);
+		return;
+	}
+
+	_array109E9[index] = (_rulesBuffer12_4[word167EB] >> 8);
+	_array10A11[index] = (_rulesBuffer12_4[word167EB] & 0xFF);
+	int var4h = (_rulesBuffer12_1[index] >> 8);
+	int var4l = (_rulesBuffer12_1[index] & 0xFF);
+
+	if (var4h != var4l) {
+		if (_array109E9[index] == var4h) {
+			--_array109E9[index];
+			return;
+		}
+
+		if (_array109E9[index] == var4l) {
+			++_array109E9[index];
+			return;
+		}
+
+		int var4h = (_rulesBuffer12_2[index] >> 8);
+		int var4l = (_rulesBuffer12_2[index] & 0xFF);
+
+		if (var4h != var4l) {
+			if (_array10A11[index] == var4h)
+				--_array10A11[index];
+			else
+				++_array10A11[index];
+			return;
+		}
+	}
+
+	// var4h == var4l
+	int mapIndex = (((_array10A11[index] >> 2) + _array109E9[index]) << 2);
+	int tmpVal = _bufferIsoMap[mapIndex + 3];
+	if ((tmpVal & 8) != 0)
+		++_array109E9[index];
+	else if ((tmpVal & 4) != 0)
+		--_array10A11[index];
+	else if ((tmpVal & 2) != 0)
+		++_array10A11[index];
+	else
+		--_array109E9[index];
+
+	return;
+}
+
 void LilliputEngine::sub1693A(int index) {
 	debugC(2, kDebugEngine, "sub1693A(%d)", index);
-	
+
 	static const uint16 _array1692F[4] = {4, 0xFF00, 0x100, 0xFFFC};
 
 	byte var1h = _scriptHandler->_array16123[index];
@@ -1393,11 +1498,11 @@ void LilliputEngine::sub1693A(int index) {
 	_word16937 = (var1h << 8) + var1l;
 
 	sub16A08(index);
-	
+
 	int var2 = (_characterDirectionArray[index] ^ 3);
 	_array1692B[var2] += 0xF8;
 	_byte16939 = 0;
-	
+
 	int mapIndex = ((((var1l << 8) >> 2) + var1h) << 2);
 	int subMapIndex = 0;
 	int retVal = 0;
@@ -1407,7 +1512,7 @@ void LilliputEngine::sub1693A(int index) {
 			if ((_bufferIsoMap[mapIndex + subMapIndex + 3] & 0x80) != 0) {
 				if (sub16A76(i, index) != 0)
 					_array1692B[i] += 0xEC;
-				
+
 				int tmpVal = ((_rulesBuffer2_10[index] & 7) ^ 7);
 				retVal = _rulesChunk9[_bufferIsoMap[mapIndex + subMapIndex]];
 				tmpVal &= retVal;
@@ -1429,7 +1534,7 @@ void LilliputEngine::sub1693A(int index) {
 			tmpVal = _array1692B[i];
 		}
 	}
-	
+
 	_characterDirectionArray[index] = retVal;
 }
 
@@ -1438,7 +1543,7 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 
 	static const byte _array16A6C[4] = {1, 0, 0, 0xFF};
 	static const byte _array16A70[4] = {0, 0xFF, 1, 0};
-	   
+
 	byte var1h = (_word16937 >> 8) + _array16A6C[indexb];
 	byte var1l = (_word16937 & 0xFF) + _array16A70[indexs];
 
@@ -1648,7 +1753,7 @@ byte LilliputEngine::sub166F7(int index, int var1, int tmpVal) {
 
 byte LilliputEngine::sub166DD(int index, int var1) {
 	debugC(2, kDebugEngine, "sub166DD(%d, %d)", index, var1);
-	
+
 	_characterDirectionArray[index] = (var1 >> 8) & 3;
 	sub16685(index, var1 & 0xFF);
 	return 0;
@@ -1887,7 +1992,7 @@ byte LilliputEngine::sub16675(int idx, int var1) {
 	debugC(2, kDebugEngine, "sub16675(%d, %d)", idx, var1);
 
 	sub16685(idx, var1);
-	int index = (var1 & 0xFF);	
+	int index = (var1 & 0xFF);
 	switch (var1 >> 8) {
 	case 0:
 		break;
@@ -2055,7 +2160,7 @@ void LilliputEngine::sub17224(int var1, int var4) {
 		sub17264(var1, var4);
 		return;
 	}
-	
+
 	if (type == 3) {
 		for (int i = _numCharacters - 1; i >= 0; i--)
 			sub17264(i, var4);
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index b2de857..0bf211a 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -236,6 +236,8 @@ public:
 	void displayFunction15();
 	void displayFunction16();
 	void displayFunction17();
+	void displayFunction18(int var1, int var2, int var3, int var4);
+
 	void displayCharacter(int index, int x, int y, int flags);
 	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
@@ -258,6 +260,7 @@ public:
 	uint16 sub16901(byte var1h, byte var1l);
 	byte sub16722(int index, byte var1);
 	byte sub166EA(int index);
+	void sub167EF(int index);
 
 	void renderCharacters(byte *buf, byte x, byte y);
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a213413..b5f34e1 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -906,6 +906,7 @@ void LilliputScript::disasmScript( ScriptStream script) {
 
 int LilliputScript::handleOpcode(ScriptStream *script) {
 	debugC(2, kDebugScript, "handleOpcode");
+
 	_currScript = script;
 	uint16 curWord = _currScript->readUint16LE();
 	if (curWord == 0xFFF6)
@@ -939,16 +940,16 @@ int LilliputScript::handleOpcode(ScriptStream *script) {
 
 void LilliputScript::runScript(ScriptStream script) {
 	debugC(1, kDebugScript, "runScript");
+
 	_byte16F05_ScriptHandler = 1;
 	
 	while (handleOpcode(&script) != 0xFF)
 		_vm->update();
 }
 
-
-
 void LilliputScript::runMenuScript(ScriptStream script) {
 	debugC(1, kDebugScript, "runMenuScript");
+
 	warning("========================== Menu Script ==============================");
 	_byte16F05_ScriptHandler = 0;
 	
@@ -958,6 +959,7 @@ void LilliputScript::runMenuScript(ScriptStream script) {
 
 void LilliputScript::sub185ED(byte index, byte subIndex) {
 	debugC(2, kDebugScript, "sub185ED");
+
 	if (_vm->_arr18560[index]._field0 != 1)
 		return;
 
@@ -966,6 +968,7 @@ void LilliputScript::sub185ED(byte index, byte subIndex) {
 
 byte LilliputScript::compareValues(byte var1, int oper, int var2) {
 	debugC(2, kDebugScript, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
+
 	switch (oper & 0xFF) {
 	case '<':
 		return (var1 < var2);
@@ -1232,6 +1235,17 @@ void LilliputScript::sub18A56(byte *buf) {
 	sub189B8();
 }
 
+int LilliputScript::sub18BB7(int index) {
+	debugC(2, kDebugScript, "sub18BB7(%d)", index);
+	
+	int chunk4Index = _vm->_rulesChunk3[index];
+	int result = 0;
+	while (_vm->_rulesChunk4[chunk4Index + result] == 0x5B)
+		++result;
+	
+	return result + 1;
+}
+
 void LilliputScript::sub18B3C(int var) {
 	debugC(2, kDebugScript, "sub18B3C(%d)", var);
 
@@ -1342,9 +1356,9 @@ int LilliputScript::getValue2() {
 	}
 }
 
-
 void LilliputScript::sub130B6() {
 	debugC(1, kDebugScript, "sub130B6()");
+
 	assert(_vm->_word12F68_ERULES <= 20);
 	for (int i = 0; i < _vm->_word12F68_ERULES; i++) {
 		if (_array122E9[i] == 3)
@@ -1365,6 +1379,7 @@ byte *LilliputScript::getCharacterVariablePtr() {
 
 byte LilliputScript::OC_sub173DF() {
 	debugC(2, kDebugScript, "OC_sub173F0()");
+
 	if (_vm->_currentScriptCharacterPosition == getValue2()) {
 		return 1;
 	}
@@ -2158,11 +2173,31 @@ void LilliputScript::OC_sub17D7F() {
 }
 
 void LilliputScript::OC_sub17DB9() {
-	warning("OC_sub17DB9");
+	debugC(1, kDebugScript, "OC_sub17DB9()");
+
+	int index = _currScript->readUint16LE();
+	int maxValue = sub18BB7(index);
+	
+	int tmpVal = _currScript->readUint16LE() + 1;
+	int oldVal = tmpVal;
+	if (tmpVal >= maxValue)
+		tmpVal = 0;
+	_currScript->writeUint16LE(tmpVal, -2); 
+
+	bool forceReturnFl = false;
+	sub17D40(forceReturnFl);
+	if (forceReturnFl)
+		return;
+
+	_word1881B = _vm->_currentScriptCharacter;
+
+	sub18B7C(index, oldVal);
+	
 }
 
 void LilliputScript::OC_sub17DF9() {
 	debugC(1, kDebugScript, "OC_sub17DF9()");
+
 	if ((_word1881B & 0xFF) == 0xFF) {
 		OC_sub17D57();
 		return;
@@ -2173,6 +2208,7 @@ void LilliputScript::OC_sub17DF9() {
 
 void LilliputScript::OC_sub17E07() {
 	debugC(1, kDebugScript, "OC_sub17E07()");
+
 	if ((_word1881B & 0xFF) == 0xFF) {
 		OC_sub17D7F();
 		return;
@@ -3098,7 +3134,15 @@ void LilliputScript::OC_sub1853B() {
 }
 
 void LilliputScript::OC_sub1864D() {
-	warning("OC_sub1864D");
+	debugC(1, kDebugScript, "OC_sub1864D()");
+
+	byte *tmpArr = getCharacterVariablePtr();
+	int var1 = (_currScript->readUint16LE() & 0xFF);
+	int var3 = ((70 * tmpArr[0]) / (_currScript->readUint16LE() & 0xFF) & 0xFF);
+	int var2 = _currScript->readUint16LE();
+	int var4 = _currScript->readUint16LE();
+	
+	_vm->displayFunction18(var1, var2, var3, var4);
 }
 
 void LilliputScript::OC_initArr18560() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 2a16b62..d39519e 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -138,6 +138,7 @@ private:
 	void sub189B8();
 	void sub189F5();
 	int sub17285(int index);
+	int sub18BB7(int index);
 
 	int getValue1();
 	int getValue2();


Commit: 9fc6e8f370ded2e777dca5d1150ced02c82ae9b8
    https://github.com/scummvm/scummvm/commit/9fc6e8f370ded2e777dca5d1150ced02c82ae9b8
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix some uninitialized variables reported by Valgrind (Thanks Hkz for reporting)

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 860d2e1..3ccf2dd 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -150,6 +150,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12FE4 = 0xFF;
 	_byte12FE3 = 0;
 	_byte16F08 = 0;
+	_byte16C9F = 0;
 
 	_currentScriptCharacter = 0;
 	_currentScriptCharacterPosition = 0;
@@ -165,6 +166,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word15AC2 = 0;
 	_displayStringIndex = 0;
 	_word1289D = 0;
+	_numCharacters = 0;
 
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b5f34e1..9942f24 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2219,8 +2219,10 @@ void LilliputScript::OC_sub17E07() {
 	_currScript->readUint16LE();
 
 }
+
 void LilliputScript::OC_sub17E15() {
 	debugC(1, kDebugScript, "OC_sub17E15()");
+
 	if ((_word1881B & 0xFF) == 0xFF) {
 		OC_sub17DB9();
 		return;
@@ -2299,6 +2301,7 @@ void LilliputScript::OC_resetByte1714E() {
 void LilliputScript::OC_deleteSavegameAndQuit() {
 	warning("OC_deleteSavegameAndQuit");
 }
+
 void LilliputScript::OC_incByte16F04() {
 	debugC(1, kDebugScript, "OC_incByte16F04()");
 
@@ -2316,6 +2319,7 @@ void LilliputScript::OC_sub17BA5() {
 
 void LilliputScript::OC_setByte18823() {
 	debugC(1, kDebugScript, "OC_setByte18823()");
+
 	byte *tmpArr = getCharacterVariablePtr();
 	_byte18823 = *tmpArr;
 }
@@ -2408,6 +2412,7 @@ void LilliputScript::OC_sub17C0E() {
 
 void LilliputScript::OC_sub17C55() {
 	debugC(1, kDebugScript, "OC_sub17C55()");
+
 	int var1 = getValue1();
 	int var2 = getValue1();
 


Commit: 8d25611dcb8417dc874a444f077eed3459a76db1
    https://github.com/scummvm/scummvm/commit/8d25611dcb8417dc874a444f077eed3459a76db1
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Remove duplicated variable, introduce getCharacterVariablesPtr() to handle negative indexes used by menus

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3ccf2dd..95407cd 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -222,6 +222,10 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	for (int i = 0; i < 160; i++)
 		_displayStringBuf[i] = 0;
 
+	for (int i = 0; i < 1400 + 3120; i++) {
+		_characterVariables_[i] = 0;
+	}
+
 	_currentCharacterVariables = NULL;
 	_bufferIdeogram = NULL;
 	_bufferMen = NULL;
@@ -1825,12 +1829,13 @@ void LilliputEngine::sub12F37() {
 	int index2 = 0;
 
 	for (int i = 0; i < _numCharacters; i++) {
-		if (_characterVariables[index1] != 0 ) {
-			if (_characterVariables[index1] == 1) {
-				_characterVariables[index1] = 0;
+		byte *varPtr = getCharacterVariablesPtr(index1);
+		if (varPtr[0] != 0 ) {
+			if (varPtr[0] == 1) {
+				varPtr[0] = 0;
 			} else {
-				--_characterVariables[index1];
-				if (_characterVariables[index1] == 1)
+				--varPtr[0];
+				if (varPtr[0] == 1)
 					_scriptHandler->_characterScriptEnabled[index2] = 1;
 			}
 		}
@@ -2443,7 +2448,7 @@ void LilliputEngine::loadRules() {
 		_rulesBuffer2_14[j] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
-			_characterVariables[(j * 32) + k] = f.readByte();
+			_characterVariables_[(j * 32) + k] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
 			_rulesBuffer2_16[(j * 32) + k] = f.readByte();
@@ -2603,7 +2608,7 @@ void LilliputEngine::sub170EE(int index) {
 	int var4 = _characterPositionY[index];
 
 	_currentScriptCharacterPosition = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF);
-	_currentCharacterVariables = &_characterVariables[_currentScriptCharacter * 32];
+	_currentCharacterVariables = getCharacterVariablesPtr(_currentScriptCharacter * 32);
 }
 
 void LilliputEngine::sub130DD() {
@@ -2677,7 +2682,7 @@ while(1);*/
 
 	//warning("dump char stat");
 	i = index;
-	debugC(3, kDebugEngine, "char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], _characterVariables[i*32+0], _scriptHandler->_characterScriptEnabled[i]);
+	debugC(3, kDebugEngine, "char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), _scriptHandler->_characterScriptEnabled[i]);
 }
 
 Common::Error LilliputEngine::run() {
@@ -2738,6 +2743,15 @@ void LilliputEngine::initialize() {
 	}
 }
 
+byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
+	debugC(1, kDebugEngine, "getCharacterVariablesPtr(%d)", index);
+
+	if (index >= 0)
+		return &_characterVariables_[index];
+	else
+		return &_characterVariables_[1400 - index];
+}
+
 void LilliputEngine::syncSoundSettings() {
 	Engine::syncSoundSettings();
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 0bf211a..5f320d1 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -165,7 +165,7 @@ public:
 	byte _rulesBuffer2_12[40];
 	byte _rulesBuffer2_13[40];
 	byte _rulesBuffer2_14[40];
-	byte _characterVariables[40 * 32];
+	byte _characterVariables_[1400 + 3120];
 	byte *_currentCharacterVariables;
 	byte _rulesBuffer2_16[40 * 32];
 	int *_rulesChunk3;
@@ -352,6 +352,9 @@ public:
 	void setNextDisplayCharacter(int var1);
 	void handleGameScripts();
 
+	// Added by Strangerke
+	byte *getCharacterVariablesPtr(int16 index);
+
 	// Temporary stubs
 	byte _keyboard_getch();
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 9942f24..75e1fd7 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -43,7 +43,6 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_word1855E = 0;
 	_word16F00 = -1;
 	_viewportCharacterTarget = -1;
-	_word10804 = 0;
 	_heroismBarX = 0;
 	_heroismBarBottomY = 0;
 	_viewportX = 0;
@@ -1275,10 +1274,10 @@ void LilliputScript::sub18B3C(int var) {
 	sub18A56(&_vm->_rulesChunk4[index + count + i]);
 }
 
-int LilliputScript::getValue1() {
+int16 LilliputScript::getValue1() {
 	debugC(2, kDebugScript, "getValue1()");
 
-	int curWord = _currScript->readUint16LE();
+	int16 curWord = _currScript->readUint16LE();
 	if (curWord < 1000)
 		return curWord;
 
@@ -1292,7 +1291,7 @@ int LilliputScript::getValue1() {
 	case 1003:
 		return (int)_vm->_currentCharacterVariables[6];
 	case 1004:
-		return _word10804;
+		return _vm->_word10804;
 	default:
 		warning("getValue1: Unexpected large value %d", curWord);
 		return curWord;
@@ -1369,12 +1368,13 @@ void LilliputScript::sub130B6() {
 byte *LilliputScript::getCharacterVariablePtr() {
 	debugC(2, kDebugScript, "getCharacterVariablePtr()");
 
-	int tmpVal = getValue1();
-	tmpVal *= 32;
-	tmpVal += _currScript->readUint16LE();
+	int8 tmpVal = (int8) (getValue1() & 0xFF);
+	int index = tmpVal * 32;
+	index += _currScript->readUint16LE();
+
+	assert(index < 1400);
 
-	assert(tmpVal < 40 * 32);
-	return &_vm->_characterVariables[tmpVal];
+	return _vm->getCharacterVariablesPtr(index);
 }
 
 byte LilliputScript::OC_sub173DF() {
@@ -1729,7 +1729,7 @@ byte LilliputScript::OC_compWord10804() {
 	debugC(1, kDebugScript, "OC_compWord10804()");
 	
 	byte tmpVal = getValue1();
-	if (tmpVal == _word10804)
+	if (tmpVal == _vm->_word10804)
 		return 1;
 
 	return 0;
@@ -1860,7 +1860,7 @@ byte LilliputScript::OC_sub1785C() {
 	int count = 0;
 
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		if (curByte == _vm->_characterVariables[(32 * i)])
+		if (curByte == *_vm->getCharacterVariablesPtr(32 * i))
 			++count;
 	}
 
@@ -2270,7 +2270,7 @@ void LilliputScript::OC_sub17A8D() {
 	int tmpVal = getValue1();
 	assert(tmpVal < 40);
 
-	if (tmpVal == _word10804)
+	if (tmpVal == _vm->_word10804)
 		_viewportCharacterTarget = 0xFFFF;
 
 	_vm->_characterPositionX[tmpVal] = 0xFFFF;
@@ -2389,7 +2389,7 @@ void LilliputScript::OC_sub17AEE() {
 void LilliputScript::OC_setWord10804() {
 	debugC(1, kDebugScript, "OC_setWord10804()");
 
-	_word10804 = getValue1();
+	_vm->_word10804 = getValue1();
 }
 
 void LilliputScript::OC_sub17C0E() {
@@ -2982,7 +2982,7 @@ void LilliputScript::OC_sub17D04() {
 	byte var1 = getValue1();
 	byte var2 = _currScript->readUint16LE() & 0xFF;
 	
-	sub1823E(var1, var2, &_vm->_characterVariables[var1]);
+	sub1823E(var1, var2, _vm->getCharacterVariablesPtr(var1));
 }
 
 void LilliputScript::OC_sub18387() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index d39519e..0c3c86b 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -113,7 +113,6 @@ private:
 	byte _byte1881D;
 
 	int _word16F00;
-	int _word10804;
 	int _word18776;
 	int _word18821;
 
@@ -140,7 +139,7 @@ private:
 	int sub17285(int index);
 	int sub18BB7(int index);
 
-	int getValue1();
+	int16 getValue1();
 	int getValue2();
 
 	byte *getCharacterVariablePtr();


Commit: 0eea1447d378d1b7e1667aaf06dd93d1a7aa01e1
    https://github.com/scummvm/scummvm/commit/0eea1447d378d1b7e1667aaf06dd93d1a7aa01e1
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: fix a bug in OC_sub17D04

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 95407cd..a86fed8 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2746,6 +2746,7 @@ void LilliputEngine::initialize() {
 byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
 	debugC(1, kDebugEngine, "getCharacterVariablesPtr(%d)", index);
 
+	assert((index > -3120) && (index < 1400));
 	if (index >= 0)
 		return &_characterVariables_[index];
 	else
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 75e1fd7..f276822 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1372,8 +1372,6 @@ byte *LilliputScript::getCharacterVariablePtr() {
 	int index = tmpVal * 32;
 	index += _currScript->readUint16LE();
 
-	assert(index < 1400);
-
 	return _vm->getCharacterVariablesPtr(index);
 }
 
@@ -2979,10 +2977,10 @@ void LilliputScript::OC_sub18367() {
 void LilliputScript::OC_sub17D04() {
 	debugC(1, kDebugScript, "OC_sub17D04()");
 
-	byte var1 = getValue1();
+	int16 index = getValue1();
 	byte var2 = _currScript->readUint16LE() & 0xFF;
 	
-	sub1823E(var1, var2, _vm->getCharacterVariablesPtr(var1));
+	sub1823E(index, var2, _vm->getCharacterVariablesPtr(index * 32));
 }
 
 void LilliputScript::OC_sub18387() {


Commit: e2de970a1a664f1855d02cefe725f337cfab31fe
    https://github.com/scummvm/scummvm/commit/e2de970a1a664f1855d02cefe725f337cfab31fe
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming. Start using Common::Point

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index a86fed8..6c31e6e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -115,12 +115,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_console = new LilliputConsole(this);
 	_rnd = 0;
 	_int8installed = false;
-	_mouseX = 0;
-	_mouseY = 0;
-	_oldMouseX = 0;
-	_oldMouseY = 0;
-	_mouseDisplayX = 0;
-	_mouseDisplayY = 0;
+	_mousePos = Common::Point(0, 0);
+	_oldMousePos = Common::Point(0, 0);
+	_mouseDisplayPos = Common::Point(0, 0);
 	_mouseButton = 0;
 	_savedMousePosDivided = 0xFFFF;
 	_skipDisplayFlag1 = 1;
@@ -158,11 +155,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word17081_nextIndex = 0;
 	_word16EFE = 0xFFFF;
 	_word1817B = 0;
-	_word15BC8 = 0;
-	_word15BCA = 0;
+	_word15BC8Pos = Common::Point(0, 0);
 	_word15AC2 = 0;
-	_word16213 = 0;
-	_word16215 = 0;
 	_word15AC2 = 0;
 	_displayStringIndex = 0;
 	_word1289D = 0;
@@ -345,14 +339,14 @@ void LilliputEngine::displayCharacter(int index, int x, int y, int flags) {
 }
 
 // display mouse cursor, if any
-void LilliputEngine::displayFunction1(byte *buf, int var1, int var2, int var4) {
-	debugC(2, kDebugEngine, "displayFunction1(buf, %d, %d, %d)", var1, var2, var4);
+void LilliputEngine::displayFunction1(byte *buf, int var1, Common::Point pos) {
+	debugC(2, kDebugEngine, "displayFunction1(buf, %d, %d, %d)", var1, pos.x, pos.y);
 
 	int index1 = ((var1 & 0xFF) << 8) + (var1 >> 8);
 	byte *newBuf = &buf[index1];
 
-	int tmpVal = ((var4 & 0xFF) << 8) + (var4 >> 8);
-	int index2 = var2 + tmpVal + (tmpVal >> 2);
+	int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
+	int index2 = pos.x + tmpVal + (tmpVal >> 2);
 
 	for (int i = 0; i < 16; i++) {
 		for (int j = 0; j < 16; j++) {
@@ -366,18 +360,18 @@ void LilliputEngine::displayFunction1(byte *buf, int var1, int var2, int var4) {
 	_system->updateScreen();
 }
 
-void LilliputEngine::displayFunction1a(byte *buf, int var2, int var4) {
-	debugC(2, kDebugEngine, "displayFunction1a(buf, %d, %d)", var2, var4);
+void LilliputEngine::displayFunction1a(byte *buf, Common::Point pos) {
+	debugC(2, kDebugEngine, "displayFunction1a(buf, %d, %d)", pos.x, pos.y);
 
-	displayFunction1(buf, 0, var2, var4);
+	displayFunction1(buf, 0, pos);
 }
 
 // save area under mouse cursor
-void LilliputEngine::displayFunction2(byte *buf, int var2, int var4) {
-	debugC(2, kDebugEngine, "displayFunction2(buf, %d, %d)", var2, var4);
+void LilliputEngine::displayFunction2(byte *buf, Common::Point pos) {
+	debugC(2, kDebugEngine, "displayFunction2(buf, %d, %d)", pos.x, pos.y);
 
-	int tmpVal = ((var4 & 0xFF) << 8) + (var4 >> 8);
-	int index2 = var2 + tmpVal + (tmpVal >> 2);
+	int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
+	int index2 = pos.x + tmpVal + (tmpVal >> 2);
 
 	for (int i = 0; i < 16; i++) {
 		for (int j = 0; j < 16; j++) {
@@ -409,12 +403,9 @@ void LilliputEngine::displayFunction4() {
 	if ((_skipDisplayFlag1 != 1) && (_skipDisplayFlag2 != 1)) {
 		_skipDisplayFlag2 = 1;
 
-		_word15BC8 = _mouseDisplayX;
-		_word15BCA = _mouseDisplayY;
-
-		displayFunction2(_array15AC8, _mouseDisplayX, _mouseDisplayY);
-
-		displayFunction1(_bufferIdeogram, _word15AC2 + 80, _mouseDisplayX, _mouseDisplayY);
+		_word15BC8Pos = _mouseDisplayPos;
+		displayFunction2(_array15AC8, _mouseDisplayPos);
+		displayFunction1(_bufferIdeogram, _word15AC2 + 80, _mouseDisplayPos);
 
 		_skipDisplayFlag1 = 1;
 		_skipDisplayFlag2 = 0;
@@ -426,7 +417,7 @@ void LilliputEngine::displayFunction5() {
 
 	if ((_skipDisplayFlag1 != 0) && (_skipDisplayFlag2 != 1)) {
 		_skipDisplayFlag2 = 1;
-		displayFunction1a(_array15AC8, _word15BC8, _word15BCA);
+		displayFunction1a(_array15AC8, _word15BC8Pos);
 		_skipDisplayFlag1 = 0;
 		_skipDisplayFlag2 = 0;
 	}
@@ -464,8 +455,8 @@ void LilliputEngine::displayFunction7() {
 	displayFunction4();
 }
 
-void LilliputEngine::displayFunction8() {
-	debugC(2, kDebugEngine, "displayFunction8()");
+void LilliputEngine::displayInterfaceHotspots() {
+	debugC(2, kDebugEngine, "displayInterfaceHotspots()");
 
 	if (_displayMap == 1)
 		return;
@@ -476,7 +467,7 @@ void LilliputEngine::displayFunction8() {
 	int tmpVal;
 	for (index = 0; index < _word12F68_ERULES; index++) {
 		tmpVal = ((_scriptHandler->_array122E9[index] << 2) + (_scriptHandler->_array122E9[index] << 4)) & 0xFF;
-		displayFunction1(_bufferIdeogram, tmpVal + index, _rulesBuffer13_2[index], _rulesBuffer13_3[index]);
+		displayFunction1(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
 	}
 
 	displayFunction4();
@@ -487,7 +478,7 @@ void LilliputEngine::displayFunction9() {
 
 	memcpy(_buffer2_45k, _buffer3_45k, 45056);
 
-	int var1 = (_scriptHandler->_viewportY >> 8) + ((_scriptHandler->_viewportY & 0xFF) << 8) + (_scriptHandler->_viewportX << 2);
+	int var1 = (_scriptHandler->_viewportPos.y >> 8) + ((_scriptHandler->_viewportPos.y & 0xFF) << 8) + (_scriptHandler->_viewportPos.x << 2);
 	int var2;
 	int index = 0;
 
@@ -604,7 +595,7 @@ void LilliputEngine::displayFunction12() {
 
 	displayFunction6();
 	displayFunction7();
-	displayFunction8();
+	displayInterfaceHotspots();
 	displayFunction9();
 	displayFunction15();
 	displayFunction14();
@@ -638,7 +629,7 @@ void LilliputEngine::displayFunction14() {
 	if (_displayMap == 1)
 		return;
 
-	if (_mouseDisplayX > 48)
+	if (_mouseDisplayPos.x > 48)
 		displayFunction5();
 
 	int index = (16 * 320) + 64;
@@ -692,8 +683,7 @@ void LilliputEngine::sub16217() {
 
 	_numCharactersToDisplay = 0;
 	int index = _numCharacters - 1;
-	_word16213 = _scriptHandler->_viewportX << 3;
-	_word16215 = _scriptHandler->_viewportY << 3;
+	Common::Point _pos16213 = Common::Point(_scriptHandler->_viewportPos.x << 3, _scriptHandler->_viewportPos.y << 3);
 
 	for (int i = index; i >= 0; i--) {
 		if (_rulesBuffer2_5[i] != 0xFF) {
@@ -730,13 +720,13 @@ void LilliputEngine::sub16217() {
 		_characterDisplayX[i] = 0xFF;
 		_characterDisplayY[i] = 0xFF;
 
-		int tmpVal2 = (_characterPositionX[i] >> 3) - _scriptHandler->_viewportX;
-		int tmpVal3 = (_characterPositionY[i] >> 3) - _scriptHandler->_viewportY;
+		int tmpVal2 = (_characterPositionX[i] >> 3) - _scriptHandler->_viewportPos.x;
+		int tmpVal3 = (_characterPositionY[i] >> 3) - _scriptHandler->_viewportPos.y;
 		if ((tmpVal2 >= 0) && (tmpVal2 <= 7) && (tmpVal3 >= 0) && (tmpVal3 <= 7)) {
 			_characterRelativePositionX[i] = tmpVal2;
 			_characterRelativePositionY[i] = tmpVal3;
-			tmpVal2 = _characterPositionX[i] - _word16213;
-			tmpVal3 = _characterPositionY[i] - _word16215;
+			tmpVal2 = _characterPositionX[i] - _pos16213.x;
+			tmpVal3 = _characterPositionY[i] - _pos16213.y;
 			int tmpVal4 = _characterPositionAltitude[i];
 			_characterDisplayX[i] = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF;
 			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
@@ -771,7 +761,7 @@ void LilliputEngine::displayFunction15() {
 
 	memcpy(_buffer1_45k, _buffer2_45k, 45056);
 
-	int index1 = (_scriptHandler->_viewportY >> 8) + ((_scriptHandler->_viewportY & 0xFF) << 8) + (_scriptHandler->_viewportX << 2);
+	int index1 = (_scriptHandler->_viewportPos.y >> 8) + ((_scriptHandler->_viewportPos.y & 0xFF) << 8) + (_scriptHandler->_viewportPos.x << 2);
 	byte *map = &_bufferIsoMap[index1];
 
 	for (int i = 0; i < 8; i++) {
@@ -937,8 +927,8 @@ void LilliputEngine::sub15F75() {
 
 	_byte129A0 = 0xFF;
 	_savedMousePosDivided = 0xFFFF;
-	byte newX = _mouseX >> 2;
-	byte newY = _mouseY / 3;
+	byte newX = _mousePos.x >> 2; 
+	byte newY = _mousePos.y / 3;
 
 	if ((newX >= 64) || (newY >= 64))
 		return;
@@ -1198,9 +1188,9 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 	if (_scriptHandler->_viewportCharacterTarget == 0xFFFF)
 		return;
 
-	int var2 = (_characterPositionX[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportX;
-	int var4 = (_characterPositionY[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportY;
-	int var1 = _scriptHandler->_viewportX;
+	int var2 = (_characterPositionX[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportPos.x;
+	int var4 = (_characterPositionY[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportPos.y;
+	int var1 = _scriptHandler->_viewportPos.x;
 
 	if (var2 >= 1) {
 		if (var2 >= 6) {
@@ -1214,7 +1204,7 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 			var1 = 0;
 	}
 
-	int var3 = _scriptHandler->_viewportY;
+	int var3 = _scriptHandler->_viewportPos.y;
 	if (var4 >= 1) {
 		if (var4 > 6) {
 			var3 += 4;
@@ -1233,37 +1223,37 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 void LilliputEngine::viewportScrollTo(int goalX, int goalY) {
 	debugC(2, kDebugEngine, "viewportScrollTo(%d, %d)", goalX, goalY);
 
-	if ((goalX == _scriptHandler->_viewportX) && (goalY == _scriptHandler->_viewportY))
+	if ((goalX == _scriptHandler->_viewportPos.x) && (goalY == _scriptHandler->_viewportPos.y))
 		return;
 
 	int dx = 0;
-	if (goalX != _scriptHandler->_viewportX) {
-		if (goalX < _scriptHandler->_viewportX)
+	if (goalX != _scriptHandler->_viewportPos.x) {
+		if (goalX < _scriptHandler->_viewportPos.x)
 			--dx;
 		else
 			++dx;
 	}
 
 	int dy = 0;
-	if (goalY!= _scriptHandler->_viewportY) {
-		if (goalY < _scriptHandler->_viewportY)
+	if (goalY!= _scriptHandler->_viewportPos.y) {
+		if (goalY < _scriptHandler->_viewportPos.y)
 			--dy;
 		else
 			++dy;
 	}
 
 	do {
-		_scriptHandler->_viewportX += dx;
-		_scriptHandler->_viewportY += dy;
+		_scriptHandler->_viewportPos.x += dx;
+		_scriptHandler->_viewportPos.y += dy;
 
 		displayFunction9();
 		displayFunction15();
 		displayFunction14();
 
-		if (goalX == _scriptHandler->_viewportX)
+		if (goalX == _scriptHandler->_viewportPos.x)
 			dx = 0;
 
-		if (goalY == _scriptHandler->_viewportY)
+		if (goalY == _scriptHandler->_viewportPos.y)
 			dy = 0;
 	} while ((dx != 0) && (dy != 0));
 
@@ -1777,7 +1767,7 @@ byte LilliputEngine::sub16729(int index) {
 
 	int arg1 = index | 0xFF00;
 	int pos1 = (_scriptHandler->_array16123[index] << 8) | (_scriptHandler->_array1614B[index] & 0xFF);
-	int pos2 = (_scriptHandler->_viewportX << 8) | (_scriptHandler->_viewportY & 0xFF);
+	int pos2 = (_scriptHandler->_viewportPos.x << 8) | (_scriptHandler->_viewportPos.y & 0xFF);
 	_soundHandler->contentFct2(); // TODO: add arg pos1 and pos2
 	return 2;
 }
@@ -1848,8 +1838,8 @@ void LilliputEngine::sub12F37() {
 void LilliputEngine::sub130EE() {
 	debugC(2, kDebugEngine, "sub130EE()");
 
-	warning("sub147D7");
-	warning("sub13156");
+//	warning("sub147D7");
+//	warning("sub13156");
 
 	if (_mouseButton == 0)
 		// TODO: check _mouse_byte1299F
@@ -1865,12 +1855,12 @@ void LilliputEngine::sub130EE() {
 	}
 
 	bool forceReturnFl = false;
-	sub13184(forceReturnFl);
+	checkInterfaceHotspots(forceReturnFl);
 	if (forceReturnFl)
 		return;
 
-	int posX = _mouseX - 64;
-	int posY = _mouseY - 16;
+	int posX = _mousePos.x - 64;
+	int posY = _mousePos.y - 16;
 
 	if ((posX < 0) || (posX > 255))
 		return;
@@ -1899,8 +1889,8 @@ void LilliputEngine::sub131FC(int var2, int var4) {
 	y = y - diff;
 
 	if ((y >= 0) && (diff >= 0) && (y < 8) && (diff < 8)) {
-		y += _scriptHandler->_viewportX;
-		diff += _scriptHandler->_viewportY;
+		y += _scriptHandler->_viewportPos.x;
+		diff += _scriptHandler->_viewportPos.y;
 		_savedMousePosDivided = (y << 8) + diff;
 		_byte16F07_menuId = 5;
 	}
@@ -1925,12 +1915,12 @@ void LilliputEngine::sub131B2(int var2, int var4, bool &forceReturnFl) {
 	return;
 }
 
-void LilliputEngine::sub13184(bool &forceReturnFl) {
-	debugC(2, kDebugEngine, "sub13184()");
+void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {
+	debugC(2, kDebugEngine, "checkInterfaceHotspots()");
 
 	forceReturnFl = false;
 	for (int index = _word12F68_ERULES - 1; index >= 0; index--) {
-		if (sub13240(_mouseX, _mouseY, _rulesBuffer13_2[index], _rulesBuffer13_3[index]) == 0) {
+		if (sub13240(_mousePos, _interfaceHotspotsX[index], _interfaceHotspotsY[index]) == 0) {
 			sub1305C(index, 1);
 			forceReturnFl = true;
 			return;
@@ -1938,16 +1928,16 @@ void LilliputEngine::sub13184(bool &forceReturnFl) {
 	}
 }
 
-int LilliputEngine::sub13240(int posX, int posY, int var3, int var4) {
-	debugC(2, kDebugEngine, "sub13240(%d, %d, %d, %d)", posX, posY, var3, var4);
+int LilliputEngine::sub13240(Common::Point mousePos, int var3, int var4) {
+	debugC(2, kDebugEngine, "sub13240(%d, %d, %d, %d)", mousePos.x, mousePos.y, var3, var4);
 
-	if ((posX < var3) || (posY < var4))
+	if ((mousePos.x < var3) || (mousePos.y < var4))
 		return -1;
 
 	var3 += 16;
 	var4 += 16;
 
-	if ((posX > var3) || (posY > var4))
+	if ((mousePos.x > var3) || (mousePos.y > var4))
 		return -1;
 
 	return 0;
@@ -1966,7 +1956,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 		if (_byte12FCE != 1) {
 			_scriptHandler->_array122E9[index] = 2;
 			_byte16F07_menuId = 2;
-			displayFunction8();
+			displayInterfaceHotspots();
 		}
 		return;
 	}
@@ -1985,7 +1975,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 		_byte16F07_menuId = 1;
 	}
 
-	displayFunction8();
+	displayInterfaceHotspots();
 }
 
 void LilliputEngine::sub16685(int idx, int var1) {
@@ -2236,7 +2226,7 @@ void LilliputEngine::sub12FE5() {
 	}
 
 	if (count !=0)
-		displayFunction8();
+		displayInterfaceHotspots();
 }
 
 void LilliputEngine::displayHeroismIndicator() {
@@ -2295,8 +2285,8 @@ void LilliputEngine::pollEvent() {
 	while (_system->getEventManager()->pollEvent(event)) {
 		switch (event.type) {
 		case Common::EVENT_MOUSEMOVE:
-			_mouseX = CLIP<int>(event.mouse.x, 0, 304) + 5;
-			_mouseY = CLIP<int>(event.mouse.y, 0, 184) + 1;
+			_mousePos.x = CLIP<int>(event.mouse.x, 0, 304) + 5;
+			_mousePos.y = CLIP<int>(event.mouse.y, 0, 184) + 1;
 			break;
 		case Common::EVENT_LBUTTONUP:
 			_mouseButton |= 1;
@@ -2313,17 +2303,14 @@ void LilliputEngine::pollEvent() {
 		}
 	}
 
-	if ((_mouseX != _oldMouseX) || (_mouseY != _oldMouseY)) {
-		_oldMouseX = _mouseX;
-		_oldMouseY = _mouseY;
+	if (_mousePos != _oldMousePos) {
+		_oldMousePos = _mousePos;
 		if (_skipDisplayFlag1 != 0) {
 			displayFunction5();
-			_mouseDisplayX = _mouseX;
-			_mouseDisplayY = _mouseY;
+			_mouseDisplayPos = _mousePos;
 			displayFunction4();
 		} else {
-			_mouseDisplayX = _mouseX;
-			_mouseDisplayY = _mouseY;
+			_mouseDisplayPos = _mousePos;
 		}
 	}
 }
@@ -2533,10 +2520,10 @@ void LilliputEngine::loadRules() {
 		_rulesBuffer13_1[i] = f.readByte();
 
 	for (int i = 0 ; i < 20; i++)
-		_rulesBuffer13_2[i] = f.readUint16LE();
+		_interfaceHotspotsX[i] = f.readUint16LE();
 
 	for (int i = 0 ; i < 20; i++)
-		_rulesBuffer13_3[i] = f.readUint16LE();
+		_interfaceHotspotsY[i] = f.readUint16LE();
 
 	for (int i = 0; i < 20; i++) {
 		byte curByte = f.readByte();
@@ -2625,7 +2612,9 @@ void LilliputEngine::handleMenu() {
 		return;
 
 	sub170EE(_word10804);
+	debugC(1, kDebugScript, "========================== Menu Script ==============================");
 	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScript_size));
+	debugC(1, kDebugScript, "========================== End of Menu Script==============================");
 	_savedMousePosDivided = 0xFFFF;
 	_byte129A0 = 0xFF;
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 5f320d1..9c8a089 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -29,6 +29,8 @@
 #include "lilliput/stream.h"
 
 #include "common/file.h"
+#include "common/rect.h"
+
 #include "engines/engine.h"
 #include "graphics/palette.h"
 #include "graphics/surface.h"
@@ -135,8 +137,7 @@ public:
 	int _word17081_nextIndex;
 	int _word16EFE;
 	int _word1817B;
-	int _word15BC8;
-	int _word15BCA;
+	Common::Point _word15BC8Pos;
 	int _word15AC2;
 	int _currentDisplayCharacter;
 	int _displayStringIndex;
@@ -189,8 +190,8 @@ public:
 	int _rulesBuffer12_4[40];
 	int _word12F68_ERULES;
 	byte _rulesBuffer13_1[20];
-	int _rulesBuffer13_2[20];
-	int _rulesBuffer13_3[20];
+	int _interfaceHotspotsX[20];
+	int _interfaceHotspotsY[20];
 	byte _rulesBuffer13_4[20];
 	byte _array10999[40];
 	byte _array109C1[40];
@@ -218,15 +219,15 @@ public:
 	void newInt8();
 	void update();
 
-	void displayFunction1(byte *buf, int var1, int var2, int var4);
-	void displayFunction1a(byte *buf, int var2, int var4);
-	void displayFunction2(byte *buf, int var2, int var4);
+	void displayFunction1(byte *buf, int var1, Common::Point pos);
+	void displayFunction1a(byte *buf, Common::Point pos);
+	void displayFunction2(byte *buf, Common::Point pos);
 	void displayFunction3(int var1, int var2, int var4);
 	void displayFunction4();
 	void displayFunction5();
 	void displayFunction6();
 	void displayFunction7();
-	void displayFunction8();
+	void displayInterfaceHotspots();
 	void displayFunction9();
 	void displayFunction10();
 	void displayFunction11(byte *buf);
@@ -282,8 +283,8 @@ public:
 	void displayHeroismIndicator();
 	void sub130EE();
 	void sub1305C(byte index, byte var2);
-	void sub13184(bool &forceReturnFl);
-	int sub13240(int posX, int posY, int var3, int var4);
+	void checkInterfaceHotspots(bool &forceReturnFl);
+	int sub13240(Common::Point mousePos, int var3, int var4);
 	void sub131B2(int var2, int var4, bool &forceReturnFl);
 	void sub131FC(int var2, int var4);
 	void sub1546F(byte displayX, byte displayY);
@@ -325,12 +326,9 @@ public:
 	Common::String getSavegameFilename(int slot);
 	void syncSoundSettings();
 
-	int _mouseX;
-	int _mouseY;
-	int _oldMouseX;
-	int _oldMouseY;
-	int _mouseDisplayX;
-	int _mouseDisplayY;
+	Common::Point _mousePos;
+	Common::Point _oldMousePos;
+	Common::Point _mouseDisplayPos;
 	int _mouseButton;
 	int _savedMousePosDivided;
 	int _skipDisplayFlag1;
@@ -342,8 +340,6 @@ public:
 	byte _numCharactersToDisplay;
 	byte _byte16C9F;
 	int _word10804;
-	int _word16213;
-	int _word16215;
 
 	void pollEvent();
 	void sub170EE(int index);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f276822..b2dca81 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -45,8 +45,8 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_viewportCharacterTarget = -1;
 	_heroismBarX = 0;
 	_heroismBarBottomY = 0;
-	_viewportX = 0;
-	_viewportY = 0;
+	_viewportPos.x = 0;
+	_viewportPos.y = 0;
 	_word18776 = 0;
 
 	_savedBuffer215Ptr = NULL;
@@ -949,7 +949,6 @@ void LilliputScript::runScript(ScriptStream script) {
 void LilliputScript::runMenuScript(ScriptStream script) {
 	debugC(1, kDebugScript, "runMenuScript");
 
-	warning("========================== Menu Script ==============================");
 	_byte16F05_ScriptHandler = 0;
 	
 	while (handleOpcode(&script) == 0)
@@ -962,7 +961,7 @@ void LilliputScript::sub185ED(byte index, byte subIndex) {
 	if (_vm->_arr18560[index]._field0 != 1)
 		return;
 
-	_vm->displayFunction1(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[subIndex], _vm->_arr18560[index]._field1, _vm->_arr18560[index]._field3);
+	_vm->displayFunction1(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[subIndex], Common::Point(_vm->_arr18560[index]._field1, _vm->_arr18560[index]._field3));
 }
 
 byte LilliputScript::compareValues(byte var1, int oper, int var2) {
@@ -1875,8 +1874,8 @@ byte LilliputScript::OC_sub17886() {
 	int x = var1 >> 8;
 	int y = var1 & 0xFF;
 
-	int dx = x - _viewportX;
-	int dy = y - _viewportY;
+	int dx = x - _viewportPos.x;
+	int dy = y - _viewportPos.y;
 
 	if ( dx >= 0 && dx < 8 && dy >= 0 && dy < 8)
 		return 1;
@@ -2338,7 +2337,9 @@ void LilliputScript::OC_callScript() {
 
 	if (_byte16F05_ScriptHandler == 0) {
 		_vm->_byte1714E = 0;
+		debugC(1, kDebugScript, "========================== Menu Script %d==============================", scriptIndex);
 		runMenuScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
+		debugC(1, kDebugScript, "========================== End of Menu Script==============================");
 	} else {
 		runScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
 	}
@@ -2751,7 +2752,7 @@ void LilliputScript::OC_sub18099() {
 	_array122E9[index] = (curWord & 0xFF);
 	_array122FD[index] = (curWord >> 8);
 
-	_vm->displayFunction8();
+	_vm->displayInterfaceHotspots();
 }
 
 void LilliputScript::OC_sub180C3() {
@@ -2763,8 +2764,8 @@ void LilliputScript::OC_sub180C3() {
 	static const char _byte180B3[] = { 6, 0, 0, -6 };
 	static const char _byte180BB[] = { 0, -6, 6, 0 };
 	
-	int x = _viewportX + _byte180B3[var1];
-	int y = _viewportY + _byte180BB[var1];
+	int x = _viewportPos.x + _byte180B3[var1];
+	int y = _viewportPos.y + _byte180BB[var1];
 
 	if ( x < 0 )
 		x = 0;
@@ -2789,8 +2790,8 @@ void LilliputScript::OC_sub1810A() {
 	_viewportCharacterTarget = 0xFFFF;
 	int var1 = getValue2();
 
-	_viewportX = var1 >> 8;
-	_viewportY = var1 & 0xFF;
+	_viewportPos.x = var1 >> 8;
+	_viewportPos.y = var1 & 0xFF;
 
 	_vm->displayFunction9();
 	_vm->displayFunction15();
@@ -2892,8 +2893,8 @@ void LilliputScript::OC_sub18260() {
 	int var1 = getValue1();
 	int var2 = getValue2();
 
-	int x = var1 + _viewportX;
-	int y = var2 + _viewportY;
+	int x = var1 + _viewportPos.x;
+	int y = var2 + _viewportPos.y;
 
 	byte* mapPtr = getMapPtr((x << 8) + (y & 0xff));
 
@@ -3191,8 +3192,8 @@ void LilliputScript::OC_sub186E5_snd() {
 	byte var4l = (index & 0xFF);
 	byte var3h = _array16123[index];
 	byte var3l = _array1614B[index];
-	byte var2h = (_viewportX & 0xFF);
-	byte var2l = (_viewportY & 0xFF);
+	byte var2h = (_viewportPos.x & 0xFF);
+	byte var2l = (_viewportPos.y & 0xFF);
 	int var1 = _currScript->readUint16LE();
 
 	_vm->_soundHandler->contentFct2();
@@ -3203,7 +3204,7 @@ void LilliputScript::OC_sub1870A_snd() {
 
 	int var3 = getValue2();
 	int var4 = var3;
-	int var2 = (_viewportX << 8) + _viewportY;
+	int var2 = (_viewportPos.x << 8) + _viewportPos.y;
 	int var1 = (_currScript->readUint16LE() & 0xFF);
 
 	_vm->_soundHandler->contentFct2();
@@ -3235,7 +3236,7 @@ void LilliputScript::OC_sub18746_snd() {
 	debugC(1, kDebugScript, "OC_sub18746_snd()");
 
 	int var4 = -1;
-	int var2 = (_viewportX << 8) + _viewportY;
+	int var2 = (_viewportPos.x << 8) + _viewportPos.y;
 	int var1 = _currScript->readUint16LE() & 0xFF;
 
 	_vm->_soundHandler->contentFct2();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 0c3c86b..805e898 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -26,6 +26,7 @@
 #include "common/memstream.h"
 #include "common/stack.h"
 #include "common/random.h"
+#include "common/rect.h"
 
 #include "lilliput/stream.h"
 
@@ -71,8 +72,7 @@ public:
 
 	byte *_savedBuffer215Ptr;
 
-	int _viewportX;
-	int _viewportY;
+	Common::Point _viewportPos;
 	int _viewportCharacterTarget;
 	int _word1881B;
 	int _heroismBarX;


Commit: 8aeedd1e50050f636f5f3f303b201f3cf57a3f3c
    https://github.com/scummvm/scummvm/commit/8aeedd1e50050f636f5f3f303b201f3cf57a3f3c
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Rename getValue2, keep on switching to Common::Point, remove code from OC_sub18260 (incomplete and buggy)

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6c31e6e..8e239cd 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -119,7 +119,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_oldMousePos = Common::Point(0, 0);
 	_mouseDisplayPos = Common::Point(0, 0);
 	_mouseButton = 0;
-	_savedMousePosDivided = 0xFFFF;
+	_savedMousePosDivided = Common::Point(-1, -1);
 	_skipDisplayFlag1 = 1;
 	_skipDisplayFlag2 = 0;
 	_displayMap = 0;
@@ -150,7 +150,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte16C9F = 0;
 
 	_currentScriptCharacter = 0;
-	_currentScriptCharacterPosition = 0;
+	_currentScriptCharacterPos = Common::Point(0, 0);
 	_word10804 = 0;
 	_word17081_nextIndex = 0;
 	_word16EFE = 0xFFFF;
@@ -926,14 +926,14 @@ void LilliputEngine::sub15F75() {
 	debugC(2, kDebugEngine, "sub15F75()");
 
 	_byte129A0 = 0xFF;
-	_savedMousePosDivided = 0xFFFF;
+	_savedMousePosDivided = Common::Point(-1, -1);
 	byte newX = _mousePos.x >> 2; 
 	byte newY = _mousePos.y / 3;
 
 	if ((newX >= 64) || (newY >= 64))
 		return;
 
-	_savedMousePosDivided = (newX << 8) + newY;
+	_savedMousePosDivided = Common::Point(newX, newY);
 	_byte16F07_menuId = 5;
 }
 
@@ -1190,53 +1190,52 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 
 	int var2 = (_characterPositionX[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportPos.x;
 	int var4 = (_characterPositionY[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportPos.y;
-	int var1 = _scriptHandler->_viewportPos.x;
+	Common::Point newPos = _scriptHandler->_viewportPos;
 
 	if (var2 >= 1) {
 		if (var2 >= 6) {
-			var1 += 4;
-			if (var1 > 56)
-				var1 = 56;
+			newPos.x += 4;
+			if (newPos.x > 56)
+				newPos.x = 56;
 		}
 	} else {
-		var1 -= 4;
-		if (var1 < 0)
-			var1 = 0;
+		newPos.x -= 4;
+		if (newPos.x < 0)
+			newPos.x = 0;
 	}
 
-	int var3 = _scriptHandler->_viewportPos.y;
 	if (var4 >= 1) {
 		if (var4 > 6) {
-			var3 += 4;
-			if (var3 >= 56)
-				var3 = 56;
+			newPos.y += 4;
+			if (newPos.y >= 56)
+				newPos.y = 56;
 		}
 	} else {
-		var3 -= 4;
-		if (var3 < 0)
-			var3 = 0;
+		newPos.y -= 4;
+		if (newPos.y < 0)
+			newPos.y = 0;
 	}
 
-	viewportScrollTo(var1, var3);
+	viewportScrollTo(newPos);
 }
 
-void LilliputEngine::viewportScrollTo(int goalX, int goalY) {
-	debugC(2, kDebugEngine, "viewportScrollTo(%d, %d)", goalX, goalY);
+void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
+	debugC(2, kDebugEngine, "viewportScrollTo(%d, %d)", goalPos.x, goalPos.y);
 
-	if ((goalX == _scriptHandler->_viewportPos.x) && (goalY == _scriptHandler->_viewportPos.y))
+	if (goalPos == _scriptHandler->_viewportPos)
 		return;
 
 	int dx = 0;
-	if (goalX != _scriptHandler->_viewportPos.x) {
-		if (goalX < _scriptHandler->_viewportPos.x)
+	if (goalPos.x != _scriptHandler->_viewportPos.x) {
+		if (goalPos.x < _scriptHandler->_viewportPos.x)
 			--dx;
 		else
 			++dx;
 	}
 
 	int dy = 0;
-	if (goalY!= _scriptHandler->_viewportPos.y) {
-		if (goalY < _scriptHandler->_viewportPos.y)
+	if (goalPos.y!= _scriptHandler->_viewportPos.y) {
+		if (goalPos.y < _scriptHandler->_viewportPos.y)
 			--dy;
 		else
 			++dy;
@@ -1250,10 +1249,10 @@ void LilliputEngine::viewportScrollTo(int goalX, int goalY) {
 		displayFunction15();
 		displayFunction14();
 
-		if (goalX == _scriptHandler->_viewportPos.x)
+		if (goalPos.x == _scriptHandler->_viewportPos.x)
 			dx = 0;
 
-		if (goalY == _scriptHandler->_viewportPos.y)
+		if (goalPos.y == _scriptHandler->_viewportPos.y)
 			dy = 0;
 	} while ((dx != 0) && (dy != 0));
 
@@ -1353,16 +1352,17 @@ void LilliputEngine::sub189DE() {
 	}
 }
 
-int LilliputEngine::sub16B0C(int param1, int param2) {
-	debugC(2, kDebugEngine, "sub16B0C(%d, %d)", param1, param2);
+// TODO rename to determine direction parameter from/to
+int LilliputEngine::sub16B0C(Common::Point param1, Common::Point param2) {
+	debugC(2, kDebugEngine, "sub16B0C(%d - %d, %d - %d)", param1.x, param1.y, param2.x, param2.y);
 
-	static const byte _array16B04[8] = {0, 2, 0, 1, 3, 2, 3, 1};
+	static const char _array16B04[8] = {0, 2, 0, 1, 3, 2, 3, 1};
 
-	int var1 = param2;
-	int var2 = param1;
+	Common::Point var1 = param2;
+	Common::Point var2 = param1;
 
-	int8 var1h = (var1 >>8) - (var2 >>8);
-	int8 var1l = (var1 & 0xFF) - (var2 & 0xFF);
+	int8 var1h = var1.x - var2.x;
+	int8 var1l = var1.y - var2.y;
 	int8 var2h = 0;
 	int8 var2l = 0;
 
@@ -1401,10 +1401,10 @@ byte LilliputEngine::sub16799(int index, int param1) {
 
 	sub167EF(index);
 
-	int var1 = (_scriptHandler->_array16123[index] << 8) + _scriptHandler->_array1614B[index];
-	int var2 = (_array109E9[index] << 8) + _array10A11[index];
+	Common::Point pos1 = Common::Point(_scriptHandler->_array16123[index], _scriptHandler->_array1614B[index]);
+	Common::Point pos2 = Common::Point(_array109E9[index], _array10A11[index]);
 
-	_characterDirectionArray[index] = sub16B0C(var1, var2);
+	_characterDirectionArray[index] = sub16B0C(pos1, pos2);
 
 	sub1693A(index);
 	_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
@@ -1876,6 +1876,7 @@ void LilliputEngine::sub130EE() {
 	sub131FC(posX, posY);
 }
 
+// TODO use Common::Point
 void LilliputEngine::sub131FC(int var2, int var4) {
 	debugC(2, kDebugEngine, "sub131FC(%d, %d)", var2, var4);
 
@@ -1891,7 +1892,7 @@ void LilliputEngine::sub131FC(int var2, int var4) {
 	if ((y >= 0) && (diff >= 0) && (y < 8) && (diff < 8)) {
 		y += _scriptHandler->_viewportPos.x;
 		diff += _scriptHandler->_viewportPos.y;
-		_savedMousePosDivided = (y << 8) + diff;
+		_savedMousePosDivided = Common::Point(y, diff);
 		_byte16F07_menuId = 5;
 	}
 }
@@ -2594,7 +2595,7 @@ void LilliputEngine::sub170EE(int index) {
 	int var2 = _characterPositionX[index];
 	int var4 = _characterPositionY[index];
 
-	_currentScriptCharacterPosition = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF);
+	_currentScriptCharacterPos = Common::Point((var2 >> 3) & 0xFF, (var4 >> 3) & 0xFF);
 	_currentCharacterVariables = getCharacterVariablesPtr(_currentScriptCharacter * 32);
 }
 
@@ -2615,7 +2616,7 @@ void LilliputEngine::handleMenu() {
 	debugC(1, kDebugScript, "========================== Menu Script ==============================");
 	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScript_size));
 	debugC(1, kDebugScript, "========================== End of Menu Script==============================");
-	_savedMousePosDivided = 0xFFFF;
+	_savedMousePosDivided = Common::Point(-1, -1);
 	_byte129A0 = 0xFF;
 
 	if (_byte16F07_menuId == 3)
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 9c8a089..5d31ee4 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -133,7 +133,7 @@ public:
 
 	int _word10800_ERULES;
 	int _numCharacters;
-	int _currentScriptCharacterPosition;
+	Common::Point _currentScriptCharacterPos;
 	int _word17081_nextIndex;
 	int _word16EFE;
 	int _word1817B;
@@ -250,7 +250,7 @@ public:
 
 	void sortCharacters();
 	void scrollToViewportCharacterTarget();
-	void viewportScrollTo(int var1, int var3);
+	void viewportScrollTo(Common::Point goalPos);
 	void sub189DE();
 	void sub16626();
 	void sub16A08(int index);
@@ -266,7 +266,7 @@ public:
 	void renderCharacters(byte *buf, byte x, byte y);
 
 	byte sub16799(int param1, int index);
-	int sub16B0C(int param1, int param2);
+	int sub16B0C(Common::Point param1, Common::Point param2);
 	void addCharToBuf(byte character);
 	void prepareGoldAmount(int param1);
 	void sub12F37();
@@ -330,7 +330,7 @@ public:
 	Common::Point _oldMousePos;
 	Common::Point _mouseDisplayPos;
 	int _mouseButton;
-	int _savedMousePosDivided;
+	Common::Point _savedMousePosDivided;
 	int _skipDisplayFlag1;
 	int _skipDisplayFlag2;
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b2dca81..b41a445 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -555,8 +555,8 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 
 
 static const OpCode opCodes1[] = {
-	{ "OC_sub173DF", 1, kGetValue2, kNone, kNone, kNone, kNone },
-	{ "OC_sub173F0", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },
+	{ "OC_sub173DF", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+	{ "OC_sub173F0", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 	{ "OC_sub1740A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17434", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
 	{ "OC_sub17468", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
@@ -569,7 +569,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub1750E", 5, kGetValue1, kImmediateValue, kCompareOperation, kGetValue1, kImmediateValue },
 	{ "OC_compareCoords_1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_compareCoords_2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub1757C", 3, kGetValue2, kCompareOperation, kImmediateValue, kNone, kNone },
+	{ "OC_sub1757C", 3, kgetPosFromScript, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_sub1759E", 3, kGetValue1, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_compWord16EF8", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_sub175C8", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
@@ -578,7 +578,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_compWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_sub17766", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17782", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub1779E", 4, kGetValue2, kImmediateValue, kImmediateValue, kCompareOperation, kNone },
+	{ "OC_sub1779E", 4, kgetPosFromScript, kImmediateValue, kImmediateValue, kCompareOperation, kNone },
 	{ "OC_sub177C6", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_compWord16EFE", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub177F5", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
@@ -586,7 +586,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub17825", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17844", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1785C", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
-	{ "OC_sub17886", 1, kGetValue2, kNone, kNone, kNone, kNone },
+	{ "OC_sub17886", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_sub178A8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
 	{ "OC_sub178BA", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub178C2", 0, kNone, kNone, kNone, kNone, kNone },
@@ -601,7 +601,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub17984", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkSavedMousePos", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179AE", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_sub179C2", 1, kGetValue2, kNone, kNone, kNone, kNone },
+	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_sub179E5", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17A07", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
 	{ "OC_sub17757", 1, kGetValue1, kNone, kNone, kNone, kNone },
@@ -610,7 +610,7 @@ static const OpCode opCodes1[] = {
 
 static const OpCode opCodes2[] = {
 /* 0x00 */	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x01 */	{ "OC_sub17A3E", 3, kGetValue2, kImmediateValue, kImmediateValue, kNone, kNone },
+/* 0x01 */	{ "OC_sub17A3E", 3, kgetPosFromScript, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x02 */	{ "OC_sub17D57", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x03 */	{ "OC_sub17D7F", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x04 */	{ "OC_sub17DB9", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
@@ -619,7 +619,7 @@ static const OpCode opCodes2[] = {
 /* 0x07 */	{ "OC_sub17E15", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x08 */	{ "OC_sub17B03", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
 /* 0x09 */	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
-/* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },
+/* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 /* 0x0b */	{ "OC_sub17A8D", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x0d */	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
@@ -631,7 +631,7 @@ static const OpCode opCodes2[] = {
 /* 0x13 */	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
 /* 0x14 */	{ "OC_callScript", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script
 /* 0x15 */	{ "OC_sub17BF2", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script then stop
-/* 0x16 */	{ "OC_sub17ACC", 1, kGetValue2, kNone, kNone, kNone, kNone },  
+/* 0x16 */	{ "OC_sub17ACC", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },  
 /* 0x17 */	{ "OC_resetByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x18 */	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
 /* 0x19 */	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
@@ -647,12 +647,12 @@ static const OpCode opCodes2[] = {
 /* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x24 */	{ "OC_sub17CEF", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
 /* 0x25 */	{ "OC_sub17D1B", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kGetValue2, kNone, kNone, kNone }, 
+/* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone }, 
 /* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x28 */	{ "OC_sub17E7E", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x29 */	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-/* 0x2b */	{ "OC_sub17EF4", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+/* 0x2b */	{ "OC_sub17EF4", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x2c */	{ "OC_sub17F08", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x2e */	{ "OC_sub17F68", 0, kNone, kNone, kNone, kNone, kNone }, 
@@ -668,13 +668,13 @@ static const OpCode opCodes2[] = {
 /* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x39 */	{ "OC_sub18099", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x3a */	{ "OC_sub180C3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x3b */	{ "OC_sub1810A", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+/* 0x3b */	{ "OC_sub1810A", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x3c */	{ "OC_sub1812D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x3d */	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x3e */	{ "OC_sub181BB", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x3f */	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x40 */	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x41 */	{ "OC_sub18260", 2, kGetValue1, kGetValue2, kNone, kNone, kNone }, // TODO
+/* 0x41 */	{ "OC_sub18260", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone }, // TODO
 /* 0x42 */	{ "OC_sub182EC", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x43 */	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x44 */	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone }, 
@@ -699,14 +699,14 @@ static const OpCode opCodes2[] = {
 /* 0x57 */	{ "OC_sub1864D", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },  // TODO
 /* 0x58 */	{ "OC_initArr18560", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x59 */	{ "OC_sub18678", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-/* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kGetValue2, kNone, kNone, kNone },  //TODO
+/* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },  //TODO
 /* 0x5b */	{ "OC_setViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x5c */	{ "OC_sub186A1", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },  //TODO
 /* 0x5d */	{ "OC_sub186E5_snd", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x5e */	{ "OC_sub1870A_snd", 2, kGetValue2, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x5e */	{ "OC_sub1870A_snd", 2, kgetPosFromScript, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x5f */	{ "OC_sub18725_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x60 */	{ "OC_sub18733_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x61 */	{ "OC_sub1873F_snd", 1, kGetValue2, kNone, kNone, kNone, kNone }, 
+/* 0x61 */	{ "OC_sub1873F_snd", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x63 */	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x64 */	{ "OC_sub18764", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
@@ -735,7 +735,7 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 		} else if( val == 1004 ) {
 			str = Common::String("_word10804");
 		}
-	} else if (type == kGetValue2) {
+	} else if (type == kgetPosFromScript) {
 		int curWord = script.readUint16LE();
 		int tmpVal = curWord >> 8;
 		switch(tmpVal) {
@@ -1297,60 +1297,61 @@ int16 LilliputScript::getValue1() {
 	}
 }
 
-int LilliputScript::getValue2() {
-	debugC(2, kDebugScript, "getValue2()");
+Common::Point LilliputScript::getPosFromScript() {
+	debugC(2, kDebugScript, "getPosFromScript()");
 
 	int curWord = _currScript->readUint16LE();
 	int tmpVal = curWord >> 8;
 	switch(tmpVal) {
 	case 0xFF:
 		assert((_vm->_currentScriptCharacter >= 0) && (_vm->_currentScriptCharacter < 40));
-		return ((_vm->_rulesBuffer2_13[_vm->_currentScriptCharacter] << 8) + _vm->_rulesBuffer2_14[_vm->_currentScriptCharacter]);
+		return Common::Point(_vm->_rulesBuffer2_13[_vm->_currentScriptCharacter], _vm->_rulesBuffer2_14[_vm->_currentScriptCharacter]);
 	case 0xFE: {
-		int index = curWord & 0xFF;
+		int8 index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
-		return ((_vm->_rulesBuffer2_13[index] << 8) + _vm->_rulesBuffer2_14[index]);
+		return Common::Point(_vm->_rulesBuffer2_13[index], _vm->_rulesBuffer2_14[index]);
 		}
 	case 0xFD:
-		return _vm->_currentScriptCharacterPosition;
+		return _vm->_currentScriptCharacterPos;
 	case 0xFC: {
-		int index = curWord & 0xFF;
-		assert(index < 40);
-		byte var1 = _vm->_characterPositionX[index] >> 3;
-		byte var2 = _vm->_characterPositionY[index] >> 3;
+		int8 index = curWord & 0xFF;
+		assert((index >= 0) && (index < 40));
+		int16 x = _vm->_characterPositionX[index] >> 3;
+		int16 y = _vm->_characterPositionY[index] >> 3;
 
-		return (var1 << 8) + var2;
+		return Common::Point(x, y);
 		}
 	case 0xFB: {
 		int index = _word16F00;
-		assert(index < 40);
-		byte var1 = _vm->_characterPositionX[index] >> 3;
-		byte var2 = _vm->_characterPositionY[index] >> 3;
+		assert((index >= 0) && (index < 40));
+		int16 x = _vm->_characterPositionX[index] >> 3;
+		int16 y = _vm->_characterPositionY[index] >> 3;
 
-		return (var1 << 8) + var2;
+		return Common::Point(x, y);
 		}
 	case 0xFA:
-		return ((_vm->_array10999[_vm->_currentScriptCharacter] << 8) + _vm->_array109C1[_vm->_currentScriptCharacter]);
+		return Common::Point(_vm->_array10999[_vm->_currentScriptCharacter], _vm->_array109C1[_vm->_currentScriptCharacter]);
 	case 0xF9:
-		return ((_vm->_currentCharacterVariables[4] << 8) + _vm->_currentCharacterVariables[5]);
+		return Common::Point(_vm->_currentCharacterVariables[4], _vm->_currentCharacterVariables[5]);
 	case 0xF8: {
-		int index = curWord & 0xFF;
+		int8 index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
-		return _vm->_rulesBuffer12_3[index];
+		return Common::Point(_vm->_rulesBuffer12_3[index] >> 8, _vm->_rulesBuffer12_3[index] & 0xFF);
 		}
 	case 0xF7: {
-		int index = _vm->_currentCharacterVariables[6];
-		assert(index < 40);
-		byte var1 = _vm->_characterPositionX[index] >> 3;
-		byte var2 = _vm->_characterPositionY[index] >> 3;
+		int8 index = _vm->_currentCharacterVariables[6];
+		assert((index >= 0) && (index < 40));
+		int16 x = _vm->_characterPositionX[index] >> 3;
+		int16 y = _vm->_characterPositionY[index] >> 3;
 
-		return (var1 << 8) + var2;
+		return Common::Point(x, y);
 		}
 	case 0xF6:
 		return _vm->_savedMousePosDivided;
 	default:
-		warning("getValue2 - 0x%x - High value %d", tmpVal, curWord);
-		return curWord;
+		Common::Point tmpVal = Common::Point(curWord >> 8, curWord & 0xFF);
+		warning("getPosFromScript - High value %d -> %d %d", curWord, tmpVal.x, tmpVal.y);
+		return tmpVal;
 	}
 }
 
@@ -1374,24 +1375,26 @@ byte *LilliputScript::getCharacterVariablePtr() {
 	return _vm->getCharacterVariablesPtr(index);
 }
 
+//TODO rename to "check script character pos"
 byte LilliputScript::OC_sub173DF() {
 	debugC(2, kDebugScript, "OC_sub173F0()");
 
-	if (_vm->_currentScriptCharacterPosition == getValue2()) {
+	if (_vm->_currentScriptCharacterPos == getPosFromScript()) {
 		return 1;
 	}
 	return 0;
 }
 
+// TODO rename to "compare position"
 byte LilliputScript::OC_sub173F0() {
 	debugC(2, kDebugScript, "OC_sub173F0()");
 
 	int index = getValue1();
 	byte d1 = _array16123[index];
 	byte d2 = _array1614B[index];
-	int var1 = getValue2();
+	Common::Point var1 = getPosFromScript();
 
-	if (var1 == (d1 << 8) + d2)
+	if (var1 == Common::Point(d1, d2))
 		return 1;
 
 	return 0;
@@ -1400,8 +1403,8 @@ byte LilliputScript::OC_sub173F0() {
 byte LilliputScript::OC_sub1740A() {
 	debugC(1, kDebugScript, "OC_sub1740A()");
 
-	int var = _vm->_currentScriptCharacterPosition;
-	if (var == 0xFFFF) {
+	Common::Point var = _vm->_currentScriptCharacterPos;
+	if (var == Common::Point(-1, -1)) {
 		_currScript->readUint16LE();
 		return 0;
 	}
@@ -1537,6 +1540,8 @@ byte LilliputScript::OC_sub1750E() {
 	return compareValues(var1, operation, var2);
 }
 
+// TODO Rename arrays to "x min/max" and "y min/max"
+// TODO Rename function to "Check if point in rectangle"
 byte LilliputScript::OC_compareCoords_1() {
 	debugC(1, kDebugScript, "OC_compareCoords_1()");
 
@@ -1545,9 +1550,9 @@ byte LilliputScript::OC_compareCoords_1() {
 
 	int var3 = _vm->_rulesBuffer12_1[index];
 	int var4 = _vm->_rulesBuffer12_2[index];
-	int var1 = _vm->_currentScriptCharacterPosition;
+	Common::Point var1 = _vm->_currentScriptCharacterPos;
 
-	if (((var1 >> 8) < (var3 >> 8)) || ((var1 >> 8) > (var3 & 0xFF)) || ((var1 & 0xFF) < (var4 >> 8)) || ((var1 & 0xFF) > (var4 & 0xFF)))
+	if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
 		return 0;
 
 	return 1;
@@ -1752,20 +1757,19 @@ byte LilliputScript::OC_sub17782() {
 	return 0;
 }
 
-byte *LilliputScript::getMapPtr(int val) {
-	debugC(1, kDebugScript, "getMapPtr(%d)", val);
+//TODO verify "*320"
+byte *LilliputScript::getMapPtr(Common::Point val) {
+	debugC(1, kDebugScript, "getMapPtr(%d %d)", val.x, val.y);
 
-	int x = (val >> 8);
-	int y = (val & 0xFF);
-	return &_vm->_bufferIsoMap[(y * 320 + x) << 2];
+	return &_vm->_bufferIsoMap[(val.y * 320 + val.x) << 2];
 }
 
 byte LilliputScript::OC_sub1779E() {
 	debugC(1, kDebugScript, "OC_sub1779E()");
 
-	int tmpVal = getValue2();
+	Common::Point tmpVal = getPosFromScript();
 
-	if (tmpVal == 0xFFFF) {
+	if (tmpVal == Common::Point(-1, -1)) {
 		_currScript->seek(_currScript->pos() + 6);
 		return 0;
 	}
@@ -1870,26 +1874,26 @@ byte LilliputScript::OC_sub1785C() {
 byte LilliputScript::OC_sub17886() {
 	debugC(1, kDebugScript, "OC_sub17886()");
 
-	int var1 = getValue2();
-	int x = var1 >> 8;
-	int y = var1 & 0xFF;
+	Common::Point var1 = getPosFromScript();
 
-	int dx = x - _viewportPos.x;
-	int dy = y - _viewportPos.y;
+	int dx = var1.x - _viewportPos.x;
+	int dy = var1.y - _viewportPos.y;
 
-	if ( dx >= 0 && dx < 8 && dy >= 0 && dy < 8)
+	if ((dx >= 0) && (dx < 8) && (dy >= 0) && (dy < 8))
 		return 1;
 	return 0;
 }
+
 byte LilliputScript::OC_sub178A8() {
 	debugC(1, kDebugScript, "OC_sub178A8()");
 
 	int var1 = getValue1();
-	int var2 = getValue2();
+	int var2 = getValue1();
 	if (var1 == var2)
 		return 1;
 	return 0;
 }
+
 byte LilliputScript::OC_sub178BA() {
 	_currScript->readUint16LE();
 	return 1;
@@ -1970,7 +1974,7 @@ byte LilliputScript::OC_sub1792A() {
 byte LilliputScript::OC_sub1793E() {
 	debugC(1, kDebugScript, "OC_sub1793E()");
 
-	if (_vm->_currentScriptCharacterPosition == 0xFFFF)
+	if (_vm->_currentScriptCharacterPos == Common::Point(-1, -1))
 		return 0;
 
 	if (_vm->_array16E94[_vm->_currentScriptCharacter] == 0)
@@ -2017,7 +2021,7 @@ byte LilliputScript::OC_sub17984() {
 byte LilliputScript::OC_checkSavedMousePos() {
 	debugC(1, kDebugScript, "OC_checkSavedMousePos()");
 
-	if ((_byte129A0 != 0xFF) || (_vm->_savedMousePosDivided == 0xFFFF))
+	if ((_byte129A0 != 0xFF) || (_vm->_savedMousePosDivided == Common::Point(-1, -1)))
 		return 0;
 
 	return 1;
@@ -2032,12 +2036,13 @@ byte LilliputScript::OC_sub179AE() {
 	return 1;
 }
 
+//TODO rename arrays
 byte LilliputScript::OC_sub179C2() {
 	debugC(1, kDebugScript, "OC_sub179C2()");
-	int var1 = getValue2();
+	Common::Point var1 = getPosFromScript();
 
-	if ((_vm->_array10999[_vm->_currentScriptCharacter] == (var1 >> 8))
-		 && (_vm->_array109C1[_vm->_currentScriptCharacter] == (var1 & 0xFF)))
+	if ((_vm->_array10999[_vm->_currentScriptCharacter] == var1.x)
+		 && (_vm->_array109C1[_vm->_currentScriptCharacter] == var1.y))
 		return 1;
 
 	return 0;
@@ -2093,7 +2098,7 @@ void LilliputScript::OC_setWord18821() {
 }
 void LilliputScript::OC_sub17A3E() {
 	debugC(1, kDebugScript, "OC_sub17A3E()");
-	int var1 = getValue2();
+	Common::Point var1 = getPosFromScript();
 	int var2 = _currScript->readUint16LE();
 	int var3 = _currScript->readUint16LE();
 
@@ -2251,12 +2256,12 @@ void LilliputScript::OC_setCharacterPosition() {
 	debugC(1, kDebugScript, "OC_setCharacterPosition()");
 	
 	int index = getValue1();
-	int tmpVal = getValue2();
+	Common::Point tmpVal = getPosFromScript();
 
-	int var2 = ((tmpVal >> 8) << 3) + 4;
-	int var4 = ((tmpVal & 0xFF) << 3) + 4;
+	int var2 = (tmpVal.x << 3) + 4;
+	int var4 = (tmpVal.y << 3) + 4;
 
-	assert(index < 40);
+	assert((index >= 0) && (index < 40));
 	_vm->_characterPositionX[index] = var2;
 	_vm->_characterPositionY[index] = var4;
 }
@@ -2356,12 +2361,13 @@ void LilliputScript::OC_sub17BF2() {
 	sub17B6C(0);
 }
 
+// TODO: rename arrays
 void LilliputScript::OC_sub17ACC() {
 	debugC(1, kDebugScript, "OC_sub17ACC()");
 
-	int var = getValue2();
-	_vm->_array10999[_vm->_currentScriptCharacter] = var >> 8;
-	_vm->_array109C1[_vm->_currentScriptCharacter] = var & 0xFF;
+	Common::Point var = getPosFromScript();
+	_vm->_array10999[_vm->_currentScriptCharacter] = var.x;
+	_vm->_array109C1[_vm->_currentScriptCharacter] = var.y;
 	_vm->_array109E9[_vm->_currentScriptCharacter] = 0xFF;
 }
 
@@ -2395,7 +2401,7 @@ void LilliputScript::OC_sub17C0E() {
 	debugC(1, kDebugScript, "OC_sub17C0E()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
-	byte var1 = (_vm->_currentCharacterVariables[4] << 8) + _vm->_currentCharacterVariables[5];
+	Common::Point var1 = Common::Point(_vm->_currentCharacterVariables[4], _vm->_currentCharacterVariables[5]);
 	byte b2 = _vm->_currentCharacterVariables[6];
 
 	byte *mapPtr = getMapPtr(var1);
@@ -2520,10 +2526,10 @@ void LilliputScript::OC_sub17D23() {
 	debugC(1, kDebugScript, "OC_sub17D23()");
 
 	int var1 = _currScript->readUint16LE();
-	int var2 = getValue2();
+	Common::Point var2 = getPosFromScript();
 	byte* buf = _vm->_currentCharacterVariables + 4;
-	computeOperation(buf, var1, var2 >> 8);
-	computeOperation(buf + 1, var1, var2 & 0xFF);
+	computeOperation(buf, var1, var2.x);
+	computeOperation(buf + 1, var1, var2.y);
 }
 
 void LilliputScript::OC_sub17E6D() {
@@ -2578,16 +2584,17 @@ void LilliputScript::OC_sub17EC5() {
 	computeOperation(compBuf, oper, var3);*/
 }
 
-int LilliputScript::sub17285(int index) {
-	return ((_vm->_characterPositionX[index] >> 3) << 8) + (_vm->_characterPositionY[index] >> 3);
+Common::Point LilliputScript::sub17285(int index) {
+	return Common::Point(_vm->_characterPositionX[index] >> 3, _vm->_characterPositionY[index] >> 3);
 }
 
+// TODO rename to set direction
 void LilliputScript::OC_sub17EF4() {
 	debugC(1, kDebugScript, "OC_sub17EF4()");
 
-	int var1 = getValue2();
-	int posTile = sub17285(_vm->_currentScriptCharacter);
-	int dir = _vm->sub16B0C(posTile, var1);
+	Common::Point pos1 = getPosFromScript();
+	Common::Point tilePos = sub17285(_vm->_currentScriptCharacter);
+	int dir = _vm->sub16B0C(tilePos, pos1);
 	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = dir;
 }
 
@@ -2619,28 +2626,28 @@ void LilliputScript::OC_sub17F08() {
 
 void LilliputScript::OC_sub17F4F() {
 	debugC(1, kDebugScript, "OC_sub17F4F()");
+
 	int var = getValue1();
 	_array10A39[_vm->_currentScriptCharacter] = var;
 	_vm->_array109E9[_vm->_currentScriptCharacter] = 0xFF;
 }
 
 void LilliputScript::OC_sub17F68() {
+	debugC(1, kDebugScript, "OC_sub17F68()");
+
 	if (_vm->_currentScriptCharacter != _viewportCharacterTarget)
 		return;
 
-	static const byte _byte_17F60[] = { 0xFF, 0xFD, 0xFD, 0xFA };
-	static const byte _byte_17F64[] = { 0xFD, 0xFA, 0xFF, 0xFD };
+	static const char _byte17F60[] = {-1, -3, -3, -6};
+	static const char _byte17F64[] = {-3, -6, -1, -3};
 	
-	int cx = _byte_17F60[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
-	int cy = _byte_17F64[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
-
-	int pos = sub17285(_vm->_currentScriptCharacter);
+	int cx = _byte17F60[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
+	int cy = _byte17F64[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
 
-	int posx = pos >> 8;
-	int posy = pos & 0xFF;
+	Common::Point pos = sub17285(_vm->_currentScriptCharacter);
 
-	int newPosX = posx + cx;
-	int newPosY = posy + cy;
+	int newPosX = pos.x + cx;
+	int newPosY = pos.y + cy;
 
 	if (newPosX < 0)
 		newPosX = 0;
@@ -2655,7 +2662,7 @@ void LilliputScript::OC_sub17F68() {
 		newPosY = 56;
 
 	_byte12A09 = 1;
-	_vm->viewportScrollTo(newPosX, newPosY);
+	_vm->viewportScrollTo(Common::Point(newPosX, newPosY));
 	_byte12A09 = 0;
 
 }
@@ -2780,7 +2787,7 @@ void LilliputScript::OC_sub180C3() {
 		y = 56;
 
 	_byte12A09 = 1;
-	_vm->viewportScrollTo(x, y);
+	_vm->viewportScrollTo(Common::Point(x, y));
 	_byte12A09 = 0;
 }
 
@@ -2788,10 +2795,7 @@ void LilliputScript::OC_sub1810A() {
 	debugC(1, kDebugScript, "OC_sub1810A()");
 
 	_viewportCharacterTarget = 0xFFFF;
-	int var1 = getValue2();
-
-	_viewportPos.x = var1 >> 8;
-	_viewportPos.y = var1 & 0xFF;
+	_viewportPos = getPosFromScript();
 
 	_vm->displayFunction9();
 	_vm->displayFunction15();
@@ -2888,22 +2892,7 @@ void LilliputScript::OC_sub18252() {
 }
 
 void LilliputScript::OC_sub18260() {
-	debugC(1, kDebugScript, "OC_sub18260()");
-	
-	int var1 = getValue1();
-	int var2 = getValue2();
-
-	int x = var1 + _viewportPos.x;
-	int y = var2 + _viewportPos.y;
-
-	byte* mapPtr = getMapPtr((x << 8) + (y & 0xff));
-
-	int bx = 0;
-	int by = 0;
-
-	if (mapPtr[1] == 0xFF) {
-		// TODO
-	}
+	warning("OC_sub18260()");
 }
 
 void LilliputScript::OC_sub182EC() {
@@ -3202,9 +3191,9 @@ void LilliputScript::OC_sub186E5_snd() {
 void LilliputScript::OC_sub1870A_snd() {
 	debugC(1, kDebugScript, "OC_sub1870A_snd()");
 
-	int var3 = getValue2();
-	int var4 = var3;
-	int var2 = (_viewportPos.x << 8) + _viewportPos.y;
+	Common::Point var3 = getPosFromScript();
+	Common::Point var4 = var3;
+	Common::Point var2 = _viewportPos;
 	int var1 = (_currScript->readUint16LE() & 0xFF);
 
 	_vm->_soundHandler->contentFct2();
@@ -3221,7 +3210,7 @@ void LilliputScript::OC_sub18725_snd() {
 void LilliputScript::OC_sub18733_snd() {
 	debugC(1, kDebugScript, "OC_sub18733_snd()");
 
-	int var4 = getValue2();
+	Common::Point var4 = getPosFromScript();
 
 	_vm->_soundHandler->contentFct3();
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 805e898..480595b 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -40,7 +40,7 @@ enum KValueType {
 	kCompareOperation,
 	kComputeOperation,
 	kGetValue1,
-	kGetValue2,
+	kgetPosFromScript,
 };
 
 
@@ -130,17 +130,17 @@ private:
 	void sub18A56(byte *buf);
 	void sub18B3C(int var);
 	void sub18BE6(byte var1, int var2, int var4);
-	byte *getMapPtr(int val);
+	byte *getMapPtr(Common::Point val);
 	byte *sub173D2();
 	void sub171AF(int var1, int var2, int var4);
 	void sub18B7C(int var1, int var3);
 	void sub189B8();
 	void sub189F5();
-	int sub17285(int index);
+	Common::Point sub17285(int index);
 	int sub18BB7(int index);
 
 	int16 getValue1();
-	int getValue2();
+	Common::Point getPosFromScript();
 
 	byte *getCharacterVariablePtr();
 	byte compareValues(byte var1, int oper, int var2);


Commit: 98ac7cf0eb7dacfa8a63c6af6b4554f53d2cec9b
    https://github.com/scummvm/scummvm/commit/98ac7cf0eb7dacfa8a63c6af6b4554f53d2cec9b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming, fix bug in getMapPtr and sub168DA

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8e239cd..100aa02 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -177,8 +177,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array1692B[i] = 0;
 
 	for (int i = 0; i < 40; i++) {
-		_array10999[i] = 0;
-		_array109C1[i] = 0;
+		_array10999PosX[i] = 0;
+		_array109C1PosY[i] = 0;
 		_charactersToDisplay[i] = 0;
 		_characterRelativePositionX[i] = 0xFF;
 		_characterRelativePositionY[i] = 0xFF;
@@ -1395,7 +1395,7 @@ byte LilliputEngine::sub16799(int index, int param1) {
 			return 3;
 		}
 
-		if ((var3h == _scriptHandler->_array12811[index]) && (var3l == _array109C1[index]))
+		if ((var3h == _scriptHandler->_array12811[index]) && (var3l == _array109C1PosY[index]))
 			return 2;
 	}
 
@@ -1412,30 +1412,31 @@ byte LilliputEngine::sub16799(int index, int param1) {
 
 }
 
+//TODO rename arrays
 void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngine, "sub167EF(%d)", index);
 
-	int word167EB = sub168DA(_scriptHandler->_array16123[index], _scriptHandler->_array1614B[index]);
-	int word167ED = sub168DA(_array10999[index], _array109C1[index]);
+	int word167EB = sub168DA(Common::Point(_scriptHandler->_array16123[index], _scriptHandler->_array1614B[index]));
+	int word167ED = sub168DA(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
 
 	if (word167EB == word167ED) {
-		_array109E9[index] = _array10999[index];
-		_array10A11[index] = _array109C1[index];
+		_array109E9[index] = _array10999PosX[index];
+		_array10A11[index] = _array109C1PosY[index];
 		return;
 	}
 
 	if (word167EB = 0xFFFF) {
-		int tmpVal = sub16901(_array10999[index], _array109C1[index]);
+		int tmpVal = sub16901(_array10999PosX[index], _array109C1PosY[index]);
 		_array109E9[index] = (_rulesBuffer12_4[tmpVal] >> 8);
 		_array10A11[index] = (_rulesBuffer12_4[tmpVal] & 0xFF);
 		return;
 	}
 
 	if ((word167ED != 0xFFFF) &&
-		  (_array10999[index] >= (_rulesBuffer12_1[word167EB] >> 8)) &&
-		  (_array10999[index] <= (_rulesBuffer12_1[word167EB] & 0xFF)) &&
-		  (_array109C1[index] >= (_rulesBuffer12_2[word167EB] >> 8)) &&
-		  (_array109C1[index] <= (_rulesBuffer12_2[word167EB] & 0xFF)) ) {
+		  (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
+		  (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
+		  (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
+		  (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF)) ) {
 		_array109E9[index] = (_rulesBuffer12_4[word167ED] >> 8);
 		_array10A11[index] = (_rulesBuffer12_4[word167ED] & 0xFF);
 		return;
@@ -1443,8 +1444,8 @@ void LilliputEngine::sub167EF(int index) {
 
 	_array109E9[index] = (_rulesBuffer12_4[word167EB] >> 8);
 	_array10A11[index] = (_rulesBuffer12_4[word167EB] & 0xFF);
-	int var4h = (_rulesBuffer12_1[index] >> 8);
-	int var4l = (_rulesBuffer12_1[index] & 0xFF);
+	int var4h = (_rectXMinMax[index] >> 8);
+	int var4l = (_rectXMinMax[index] & 0xFF);
 
 	if (var4h != var4l) {
 		if (_array109E9[index] == var4h) {
@@ -1457,8 +1458,8 @@ void LilliputEngine::sub167EF(int index) {
 			return;
 		}
 
-		int var4h = (_rulesBuffer12_2[index] >> 8);
-		int var4l = (_rulesBuffer12_2[index] & 0xFF);
+		int var4h = (_rectYMinMax[index] >> 8);
+		int var4l = (_rectYMinMax[index] & 0xFF);
 
 		if (var4h != var4l) {
 			if (_array10A11[index] == var4h)
@@ -1534,16 +1535,17 @@ void LilliputEngine::sub1693A(int index) {
 	_characterDirectionArray[index] = retVal;
 }
 
+// TODO rename _word16937
 byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	debugC(2, kDebugEngine, "sub16A76(%d, %d)", indexb, indexs);
 
-	static const byte _array16A6C[4] = {1, 0, 0, 0xFF};
-	static const byte _array16A70[4] = {0, 0xFF, 1, 0};
+	static const char _array16A6C[4] = {1, 0, 0, -1};
+	static const char _array16A70[4] = {0, -1, 1, 0};
 
-	byte var1h = (_word16937 >> 8) + _array16A6C[indexb];
-	byte var1l = (_word16937 & 0xFF) + _array16A70[indexs];
+	char var1h = (_word16937 >> 8) + _array16A6C[indexb];
+	char var1l = (_word16937 & 0xFF) + _array16A70[indexs];
 
-	int var2 = sub168DA(var1h, var1l);
+	int var2 = sub168DA(Common::Point(var1h, var1l));
 	if (var2 == 0xFFFF)
 		return 1;
 
@@ -1552,23 +1554,23 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	var1h = (_word16937 >> 8);
 	var1l = (_word16937 & 0xFF);
 
-	if ((var1h >= (_rulesBuffer12_1[var2] >> 8)) && (var1h <= (_rulesBuffer12_1[var2] & 0xFF)) && (var1l >= (_rulesBuffer12_2[var2] >> 8)) && (var1l <= (_rulesBuffer12_2[var2] & 0xFF)))
+	if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
 		return 0;
 
 	var1h = _array109E9[indexs];
 	var1l = _array10A11[indexs];
 
-	if ((var1h >= (_rulesBuffer12_1[var2] >> 8)) && (var1h <= (_rulesBuffer12_1[var2] & 0xFF)) && (var1l >= (_rulesBuffer12_2[var2] >> 8)) && (var1l <= (_rulesBuffer12_2[var2] & 0xFF)))
+	if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
 		return 0;
 
 	return 1;
 }
 
-uint16 LilliputEngine::sub168DA(byte var1h, byte var1l) {
-	debugC(2, kDebugEngine, "sub168DA(%d, %d)", var1h, var1l);
+uint16 LilliputEngine::sub168DA(Common::Point pos) {
+	debugC(2, kDebugEngine, "sub168DA(%d, %d)", pos.x, pos.y);
 
 	for (int i = 0; i < _rulesChunk12_size; i++) {
-		if ((var1h >= (_rulesBuffer12_1[i] >> 8)) && (var1h <= (_rulesBuffer12_1[i] & 0xFF)) && (var1h >= (_rulesBuffer12_2[i] >> 8)) && (var1h <= (_rulesBuffer12_2[i] & 0xFF)))
+		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
 			return i;
 	}
 	return 0xFFFF;
@@ -1578,7 +1580,7 @@ uint16 LilliputEngine::sub16901(byte var1h, byte var1l) {
 	debugC(2, kDebugEngine, "sub16901(%d, %d)", var1h, var1l);
 
 	for (int i = _rulesChunk12_size-1; i >= 0 ; i--) {
-		if ((var1h >= (_rulesBuffer12_1[i] >> 8)) && (var1h <= (_rulesBuffer12_1[i] & 0xFF)) && (var1h >= (_rulesBuffer12_2[i] >> 8)) && (var1h <= (_rulesBuffer12_2[i] & 0xFF)))
+		if ((var1h >= (_rectXMinMax[i] >> 8)) && (var1h <= (_rectXMinMax[i] & 0xFF)) && (var1h >= (_rectYMinMax[i] >> 8)) && (var1h <= (_rectYMinMax[i] & 0xFF)))
 			return i;
 	}
 	return 0xFFFF;
@@ -1780,16 +1782,16 @@ byte LilliputEngine::sub1675D(int index, int var1) {
 	int var1l = _scriptHandler->_array1614B[var2];
 	int var3 = _array109E9[index];
 
-	if ((var3 != 0xFF) && (var3 == _array10999[index])) {
+	if ((var3 != 0xFF) && (var3 == _array10999PosX[index])) {
 		var3 = _array10A11[index];
-		if (var3 == _array109C1[index]) {
+		if (var3 == _array109C1PosY[index]) {
 			_array109E9[index] = var1h;
 			_array10A11[index] = var1l;
 		}
 	}
 
-	_array10999[index] = var1h;
-	_array109C1[index] = var1l;
+	_array10999PosX[index] = var1h;
+	_array109C1PosY[index] = var1l;
 
 	return sub16799(index, var1);
 }
@@ -2509,8 +2511,8 @@ void LilliputEngine::loadRules() {
 	assert(_rulesChunk12_size <= 40);
 
 	for (int i = 0; i < _rulesChunk12_size; i++) {
-		_rulesBuffer12_1[i] = f.readUint16LE();
-		_rulesBuffer12_2[i] = f.readUint16LE();
+		_rectXMinMax[i] = f.readUint16LE();
+		_rectYMinMax[i] = f.readUint16LE();
 		_rulesBuffer12_3[i] = f.readUint16LE();
 		_rulesBuffer12_4[i] = f.readUint16LE();
 	}
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 5d31ee4..0caf627 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -184,8 +184,8 @@ public:
 	int *_rulesChunk10;
 	byte *_rulesChunk11;
 	int _rulesChunk12_size;
-	int _rulesBuffer12_1[40];
-	int _rulesBuffer12_2[40];
+	uint16 _rectXMinMax[40];
+	uint16 _rectYMinMax[40];
 	int _rulesBuffer12_3[40];
 	int _rulesBuffer12_4[40];
 	int _word12F68_ERULES;
@@ -193,8 +193,8 @@ public:
 	int _interfaceHotspotsX[20];
 	int _interfaceHotspotsY[20];
 	byte _rulesBuffer13_4[20];
-	byte _array10999[40];
-	byte _array109C1[40];
+	byte _array10999PosX[40];
+	byte _array109C1PosY[40];
 	byte _array15AC8[256];
 	byte _charactersToDisplay[40];
 	byte _characterRelativePositionX[40];
@@ -257,7 +257,7 @@ public:
 	byte sub16A76(int indexb, int indexs);
 	void sub17224(int var1, int var4);
 	void sub17264(int index, int var4);
-	uint16 sub168DA(byte var1h, byte var1l);
+	uint16 sub168DA(Common::Point pos);
 	uint16 sub16901(byte var1h, byte var1l);
 	byte sub16722(int index, byte var1);
 	byte sub166EA(int index);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b41a445..7b267ab 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -82,10 +82,10 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 	debugC(2, kDebugScript, "handleOpcodeType1(0x%x)", curWord);
 	switch (curWord) {
 	case 0x0:
-		return OC_sub173DF();
+		return OC_checkCharacterGoalPos();
 		break;
 	case 0x1:
-		return OC_sub173F0();
+		return OC_comparePos();
 		break;
 	case 0x2:
 		return OC_sub1740A();
@@ -178,10 +178,10 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub17886();
 		break;
 	case 0x20:
-		return OC_sub178A8();
+		return OC_CompareGameVariables();
 		break;
 	case 0x21:
-		return OC_sub178BA();
+		return OC_skipNextOpcode();
 		break;
 	case 0x22:
 		return OC_sub178C2();
@@ -552,11 +552,9 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 	}
 }
 
-
-
 static const OpCode opCodes1[] = {
-	{ "OC_sub173DF", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
-	{ "OC_sub173F0", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
+	{ "OC_checkCharacterGoalPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+	{ "OC_comparePos", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 	{ "OC_sub1740A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17434", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
 	{ "OC_sub17468", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
@@ -587,8 +585,8 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub17844", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1785C", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_sub17886", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
-	{ "OC_sub178A8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
-	{ "OC_sub178BA", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_CompareGameVariables", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
+	{ "OC_skipNextOpcode", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub178C2", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub178D2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub178E8", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
@@ -762,7 +760,7 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 		break;
 			   }
 	case 0xFA:
-		str = Common::String::format("(_array10999[currentCharacter], _array109C1[currentCharacter])");
+		str = Common::String::format("(_array10999PosX[currentCharacter], _array109C1PosY[currentCharacter])");
 		break;
 	case 0xF9:
 		str = Common::String::format("(_currentCharacterVariables[4], _currentCharacterVariables[5])");
@@ -1330,7 +1328,7 @@ Common::Point LilliputScript::getPosFromScript() {
 		return Common::Point(x, y);
 		}
 	case 0xFA:
-		return Common::Point(_vm->_array10999[_vm->_currentScriptCharacter], _vm->_array109C1[_vm->_currentScriptCharacter]);
+		return Common::Point(_vm->_array10999PosX[_vm->_currentScriptCharacter], _vm->_array109C1PosY[_vm->_currentScriptCharacter]);
 	case 0xF9:
 		return Common::Point(_vm->_currentCharacterVariables[4], _vm->_currentCharacterVariables[5]);
 	case 0xF8: {
@@ -1375,9 +1373,8 @@ byte *LilliputScript::getCharacterVariablePtr() {
 	return _vm->getCharacterVariablesPtr(index);
 }
 
-//TODO rename to "check script character pos"
-byte LilliputScript::OC_sub173DF() {
-	debugC(2, kDebugScript, "OC_sub173F0()");
+byte LilliputScript::OC_checkCharacterGoalPos() {
+	debugC(2, kDebugScript, "OC_checkCharacterGoalPos()");
 
 	if (_vm->_currentScriptCharacterPos == getPosFromScript()) {
 		return 1;
@@ -1385,9 +1382,8 @@ byte LilliputScript::OC_sub173DF() {
 	return 0;
 }
 
-// TODO rename to "compare position"
-byte LilliputScript::OC_sub173F0() {
-	debugC(2, kDebugScript, "OC_sub173F0()");
+byte LilliputScript::OC_comparePos() {
+	debugC(2, kDebugScript, "OC_comparePos()");
 
 	int index = getValue1();
 	byte d1 = _array16123[index];
@@ -1422,6 +1418,7 @@ byte LilliputScript::OC_sub1740A() {
 	}
 }
 
+// Compare field0 with value -> character id?
 byte LilliputScript::OC_sub17434() {
 	debugC(1, kDebugScript, "OC_sub17434()");
 
@@ -1540,16 +1537,15 @@ byte LilliputScript::OC_sub1750E() {
 	return compareValues(var1, operation, var2);
 }
 
-// TODO Rename arrays to "x min/max" and "y min/max"
-// TODO Rename function to "Check if point in rectangle"
+// TODO Rename function to "Check if character pos in rectangle"
 byte LilliputScript::OC_compareCoords_1() {
 	debugC(1, kDebugScript, "OC_compareCoords_1()");
 
 	int index = _currScript->readUint16LE();
 	assert(index < 40);
 
-	int var3 = _vm->_rulesBuffer12_1[index];
-	int var4 = _vm->_rulesBuffer12_2[index];
+	int var3 = _vm->_rectXMinMax[index];
+	int var4 = _vm->_rectYMinMax[index];
 	Common::Point var1 = _vm->_currentScriptCharacterPos;
 
 	if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
@@ -1558,18 +1554,21 @@ byte LilliputScript::OC_compareCoords_1() {
 	return 1;
 }
 
+// TODO Rename function to "Check if character pos in rectangle"
 byte LilliputScript::OC_compareCoords_2() {
 	debugC(1, kDebugScript, "OC_compareCoords_2()");
-	int var1 = getValue1();
-	var1 = (_array16123[var1] << 8) + _array1614B[var1];
-	int var2 = _currScript->readUint16LE();
-	int var3 = _vm->_rulesBuffer12_1[var2];
-	int var4 = _vm->_rulesBuffer12_2[var2];
 
-	if (((var1 >> 8) < (var3 >> 8)) || ((var1 >> 8) > (var3 & 0xFF)) || ((var1 & 0xFF) < (var4 >> 8)) || ((var1 & 0xFF) > (var4 & 0xFF)))
+	int index = getValue1();
+	Common::Point var1 = Common::Point(_array16123[index], _array1614B[index]);
+	uint16 var2 = _currScript->readUint16LE();
+	uint16 var3 = _vm->_rectXMinMax[var2];
+	uint16 var4 = _vm->_rectYMinMax[var2];
+
+	if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
 		return 0;
 	return 1;
 }
+
 byte LilliputScript::OC_sub1757C() {
 	warning("OC_sub1757C");
 	return 0;
@@ -1757,11 +1756,10 @@ byte LilliputScript::OC_sub17782() {
 	return 0;
 }
 
-//TODO verify "*320"
 byte *LilliputScript::getMapPtr(Common::Point val) {
 	debugC(1, kDebugScript, "getMapPtr(%d %d)", val.x, val.y);
 
-	return &_vm->_bufferIsoMap[(val.y * 320 + val.x) << 2];
+	return &_vm->_bufferIsoMap[(val.y * 64 + val.x) << 2];
 }
 
 byte LilliputScript::OC_sub1779E() {
@@ -1884,8 +1882,8 @@ byte LilliputScript::OC_sub17886() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub178A8() {
-	debugC(1, kDebugScript, "OC_sub178A8()");
+byte LilliputScript::OC_CompareGameVariables() {
+	debugC(1, kDebugScript, "OC_CompareGameVariables()");
 
 	int var1 = getValue1();
 	int var2 = getValue1();
@@ -1894,7 +1892,9 @@ byte LilliputScript::OC_sub178A8() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub178BA() {
+byte LilliputScript::OC_skipNextOpcode() {
+	debugC(1, kDebugScript, "OC_skipNextOpcode()");
+
 	_currScript->readUint16LE();
 	return 1;
 }
@@ -2036,13 +2036,12 @@ byte LilliputScript::OC_sub179AE() {
 	return 1;
 }
 
-//TODO rename arrays
 byte LilliputScript::OC_sub179C2() {
 	debugC(1, kDebugScript, "OC_sub179C2()");
 	Common::Point var1 = getPosFromScript();
 
-	if ((_vm->_array10999[_vm->_currentScriptCharacter] == var1.x)
-		 && (_vm->_array109C1[_vm->_currentScriptCharacter] == var1.y))
+	if ((_vm->_array10999PosX[_vm->_currentScriptCharacter] == var1.x)
+		 && (_vm->_array109C1PosY[_vm->_currentScriptCharacter] == var1.y))
 		return 1;
 
 	return 0;
@@ -2366,8 +2365,8 @@ void LilliputScript::OC_sub17ACC() {
 	debugC(1, kDebugScript, "OC_sub17ACC()");
 
 	Common::Point var = getPosFromScript();
-	_vm->_array10999[_vm->_currentScriptCharacter] = var.x;
-	_vm->_array109C1[_vm->_currentScriptCharacter] = var.y;
+	_vm->_array10999PosX[_vm->_currentScriptCharacter] = var.x;
+	_vm->_array109C1PosY[_vm->_currentScriptCharacter] = var.y;
 	_vm->_array109E9[_vm->_currentScriptCharacter] = 0xFF;
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 480595b..0016312 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -147,8 +147,8 @@ private:
 	void computeOperation(byte *bufPtr, int oper, int var2);
 
 	//Opcodes Type 1
-	byte OC_sub173DF();
-	byte OC_sub173F0();
+	byte OC_checkCharacterGoalPos();
+	byte OC_comparePos();
 	byte OC_sub1740A();
 	byte OC_sub17434();
 	byte OC_sub17468();
@@ -179,8 +179,8 @@ private:
 	byte OC_sub17844();
 	byte OC_sub1785C();
 	byte OC_sub17886();
-	byte OC_sub178A8();
-	byte OC_sub178BA();
+	byte OC_CompareGameVariables();
+	byte OC_skipNextOpcode();
 	byte OC_sub178C2();
 	byte OC_sub178D2();
 	byte OC_sub178E8();


Commit: 7153a4b38aca78c7d9c5222c0f17d8d6342ebf2d
    https://github.com/scummvm/scummvm/commit/7153a4b38aca78c7d9c5222c0f17d8d6342ebf2d
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming, fix a bug in sub16799, move several unsigned to signed

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 100aa02..6373681 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -180,18 +180,18 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array10999PosX[i] = 0;
 		_array109C1PosY[i] = 0;
 		_charactersToDisplay[i] = 0;
-		_characterRelativePositionX[i] = 0xFF;
-		_characterRelativePositionY[i] = 0xFF;
+		_characterRelativePositionX[i] = -1;
+		_characterRelativePositionY[i] = -1;
 		_characterDisplayX[i] = 0;
 		_characterDisplayY[i] = 0;
 		_array12299[i] = 0xFF;
-		_array109E9[i] = 0xFF;
-		_array10A11[i] = 0xFF;
+		_array109E9PosX[i] = -1;
+		_array10A11PosY[i] = -1;
 		_array16E94[i] = 0;
 
 		_array11D49[i] = 0xFFFF;
-		_characterPositionX[i] = 0xFFFF;
-		_characterPositionY[i] = 0xFFFF;
+		_characterPositionX[i] = -1;
+		_characterPositionY[i] = -1;
 		_characterPositionAltitude[i] = 0;
 		_characterFrameArray[i] = 0;
 		_rulesBuffer2_5[i] = 0xFF;
@@ -666,9 +666,9 @@ void LilliputEngine::displayCharactersOnMap() {
 
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = _numCharacters - 1; index >=0; index--) {
-		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614B[index] != -1)) {
-			 int y = (3 * _scriptHandler->_array1614B[index]) + 1;
-			 int x = (_scriptHandler->_array16123[index] * 4) + 1;
+		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614BPosY[index] != -1)) {
+			 int y = (3 * _scriptHandler->_array1614BPosY[index]) + 1;
+			 int x = (_scriptHandler->_array16123PosX[index] * 4) + 1;
 
 			 _word15E5D[index] = y * 320 + x;
 			 _byte15E35[index] = buf[y * 320 + x];
@@ -713,8 +713,8 @@ void LilliputEngine::sub16217() {
 			_characterPositionY[i] = var4;
 		}
 
-		_scriptHandler->_array16123[i] = _characterPositionX[i] >> 3;
-		_scriptHandler->_array1614B[i] = _characterPositionY[i] >> 3;
+		_scriptHandler->_array16123PosX[i] = _characterPositionX[i] >> 3;
+		_scriptHandler->_array1614BPosY[i] = _characterPositionY[i] >> 3;
 		_characterRelativePositionX[i] = 0xFF;
 		_characterRelativePositionY[i] = 0xFF;
 		_characterDisplayX[i] = 0xFF;
@@ -980,8 +980,8 @@ void LilliputEngine::sub16CA0() {
 		if (_rulesBuffer2_11[index] & 1)
 			continue;
 
-		int c1 = _scriptHandler->_array16123[index];
-		int c2 = _scriptHandler->_array1614B[index];
+		int c1 = _scriptHandler->_array16123PosX[index];
+		int c2 = _scriptHandler->_array1614BPosY[index];
 
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
@@ -989,8 +989,8 @@ void LilliputEngine::sub16CA0() {
 				(_rulesBuffer2_5[index] != index2) &&
 				(_rulesBuffer2_5[index2] != index) &&
 				(_rulesBuffer2_11[index2] & 2) == 0) {
-				int d1 = _scriptHandler->_array16123[index2];
-				int d2 = _scriptHandler->_array1614B[index2];
+				int d1 = _scriptHandler->_array16123PosX[index2];
+				int d2 = _scriptHandler->_array1614BPosY[index2];
 
 				if (d1 != 0xFF) {
 					int x = c1 - d1;
@@ -1352,26 +1352,24 @@ void LilliputEngine::sub189DE() {
 	}
 }
 
-// TODO rename to determine direction parameter from/to
-int LilliputEngine::sub16B0C(Common::Point param1, Common::Point param2) {
-	debugC(2, kDebugEngine, "sub16B0C(%d - %d, %d - %d)", param1.x, param1.y, param2.x, param2.y);
+int LilliputEngine::getDirection(Common::Point param1, Common::Point param2) {
+	debugC(2, kDebugEngine, "getDirection(%d - %d, %d - %d)", param1.x, param1.y, param2.x, param2.y);
 
-	static const char _array16B04[8] = {0, 2, 0, 1, 3, 2, 3, 1};
+	static const char _directionsArray[8] = {0, 2, 0, 1, 3, 2, 3, 1};
 
 	Common::Point var1 = param2;
 	Common::Point var2 = param1;
 
 	int8 var1h = var1.x - var2.x;
 	int8 var1l = var1.y - var2.y;
-	int8 var2h = 0;
 	int8 var2l = 0;
 
-	if (var1h < var2h) {
+	if (var1h < 0) {
 		var2l |= 4;
 		var1h = -var1h;
 	}
 
-	if (var1l < var2h) {
+	if (var1l < 0) {
 		var2l |= 2;
 		var1l = -var1l;
 	}
@@ -1379,32 +1377,31 @@ int LilliputEngine::sub16B0C(Common::Point param1, Common::Point param2) {
 	if (var1h < var1l)
 		var2l |= 1;
 
-	return _array16B04[var2l];
+	return _directionsArray[var2l];
 }
 
 byte LilliputEngine::sub16799(int index, int param1) {
 	debugC(2, kDebugEngine, "sub16799(%d, %d)", index, param1);
 
-	byte var3h = _array109E9[index];
-	byte var3l = _array10A11[index];
+	Common::Point var3 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
 
-	if (var3h != 0xFF) {
-		if ((var3h != _scriptHandler->_array16123[index]) || (var3l != _scriptHandler->_array1614B[index])) {
+	if (var3.x != -1) {
+		if ((var3.x != _scriptHandler->_array16123PosX[index]) || (var3.y != _scriptHandler->_array1614BPosY[index])) {
 			sub1693A(index);
 			_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
 			return 3;
 		}
 
-		if ((var3h == _scriptHandler->_array12811[index]) && (var3l == _array109C1PosY[index]))
+		if ((var3.x == _array10999PosX[index]) && (var3.y == _array109C1PosY[index]))
 			return 2;
 	}
 
 	sub167EF(index);
 
-	Common::Point pos1 = Common::Point(_scriptHandler->_array16123[index], _scriptHandler->_array1614B[index]);
-	Common::Point pos2 = Common::Point(_array109E9[index], _array10A11[index]);
+	Common::Point pos1 = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
+	Common::Point pos2 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
 
-	_characterDirectionArray[index] = sub16B0C(pos1, pos2);
+	_characterDirectionArray[index] = getDirection(pos1, pos2);
 
 	sub1693A(index);
 	_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
@@ -1416,19 +1413,19 @@ byte LilliputEngine::sub16799(int index, int param1) {
 void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngine, "sub167EF(%d)", index);
 
-	int word167EB = sub168DA(Common::Point(_scriptHandler->_array16123[index], _scriptHandler->_array1614B[index]));
+	int word167EB = sub168DA(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
 	int word167ED = sub168DA(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
 
 	if (word167EB == word167ED) {
-		_array109E9[index] = _array10999PosX[index];
-		_array10A11[index] = _array109C1PosY[index];
+		_array109E9PosX[index] = _array10999PosX[index];
+		_array10A11PosY[index] = _array109C1PosY[index];
 		return;
 	}
 
 	if (word167EB = 0xFFFF) {
 		int tmpVal = sub16901(_array10999PosX[index], _array109C1PosY[index]);
-		_array109E9[index] = (_rulesBuffer12_4[tmpVal] >> 8);
-		_array10A11[index] = (_rulesBuffer12_4[tmpVal] & 0xFF);
+		_array109E9PosX[index] = _rulesBuffer12Pos[tmpVal].x;
+		_array10A11PosY[index] = _rulesBuffer12Pos[tmpVal].y;
 		return;
 	}
 
@@ -1437,24 +1434,24 @@ void LilliputEngine::sub167EF(int index) {
 		  (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
 		  (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
 		  (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF)) ) {
-		_array109E9[index] = (_rulesBuffer12_4[word167ED] >> 8);
-		_array10A11[index] = (_rulesBuffer12_4[word167ED] & 0xFF);
+		_array109E9PosX[index] = _rulesBuffer12Pos[word167ED].x;
+		_array10A11PosY[index] = _rulesBuffer12Pos[word167ED].y;
 		return;
 	}
 
-	_array109E9[index] = (_rulesBuffer12_4[word167EB] >> 8);
-	_array10A11[index] = (_rulesBuffer12_4[word167EB] & 0xFF);
+	_array109E9PosX[index] = _rulesBuffer12Pos[word167EB].x;
+	_array10A11PosY[index] = _rulesBuffer12Pos[word167EB].y;
 	int var4h = (_rectXMinMax[index] >> 8);
 	int var4l = (_rectXMinMax[index] & 0xFF);
 
 	if (var4h != var4l) {
-		if (_array109E9[index] == var4h) {
-			--_array109E9[index];
+		if (_array109E9PosX[index] == var4h) {
+			--_array109E9PosX[index];
 			return;
 		}
 
-		if (_array109E9[index] == var4l) {
-			++_array109E9[index];
+		if (_array109E9PosX[index] == var4l) {
+			++_array109E9PosX[index];
 			return;
 		}
 
@@ -1462,25 +1459,25 @@ void LilliputEngine::sub167EF(int index) {
 		int var4l = (_rectYMinMax[index] & 0xFF);
 
 		if (var4h != var4l) {
-			if (_array10A11[index] == var4h)
-				--_array10A11[index];
+			if (_array10A11PosY[index] == var4h)
+				--_array10A11PosY[index];
 			else
-				++_array10A11[index];
+				++_array10A11PosY[index];
 			return;
 		}
 	}
 
 	// var4h == var4l
-	int mapIndex = (((_array10A11[index] >> 2) + _array109E9[index]) << 2);
+	int mapIndex = (((_array10A11PosY[index] >> 2) + _array109E9PosX[index]) << 2);
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
 	if ((tmpVal & 8) != 0)
-		++_array109E9[index];
+		++_array109E9PosX[index];
 	else if ((tmpVal & 4) != 0)
-		--_array10A11[index];
+		--_array10A11PosY[index];
 	else if ((tmpVal & 2) != 0)
-		++_array10A11[index];
+		++_array10A11PosY[index];
 	else
-		--_array109E9[index];
+		--_array109E9PosX[index];
 
 	return;
 }
@@ -1490,8 +1487,8 @@ void LilliputEngine::sub1693A(int index) {
 
 	static const uint16 _array1692F[4] = {4, 0xFF00, 0x100, 0xFFFC};
 
-	byte var1h = _scriptHandler->_array16123[index];
-	byte var1l = _scriptHandler->_array1614B[index];
+	int var1h = _scriptHandler->_array16123PosX[index];
+	int var1l = _scriptHandler->_array1614BPosY[index];
 	_word16937 = (var1h << 8) + var1l;
 
 	sub16A08(index);
@@ -1557,8 +1554,8 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
 		return 0;
 
-	var1h = _array109E9[indexs];
-	var1l = _array10A11[indexs];
+	var1h = _array109E9PosX[indexs];
+	var1l = _array10A11PosY[indexs];
 
 	if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
 		return 0;
@@ -1596,8 +1593,8 @@ void LilliputEngine::sub16A08(int index) {
 	int _array16A00[4];
 
 	for (int i = 3; i >= 0; i--) {
-		byte var1h = (_word16937 >> 8) + _array169F8[i] - _array109E9[index];
-		byte var1l = (_word16937 & 0xFF) + _array169FC[i] - _array10A11[index];
+		byte var1h = (_word16937 >> 8) + _array169F8[i] - _array109E9PosX[index];
+		byte var1l = (_word16937 & 0xFF) + _array169FC[i] - _array10A11PosY[index];
 		_array16A00[i] = (var1l * var1l) + (var1h * var1h);
 	}
 	_array1692B[0] = 0;
@@ -1701,7 +1698,7 @@ void LilliputEngine::sub16626() {
 				result = sub16722(index, var1);
 				break;
 			case 14:
-				result = sub166F7(index, var1, tmpVal);
+				result = sub166F7(index, Common::Point(var1 >> 8, var1 && 0xFF), tmpVal);
 				break;
 			case 15:
 				result = sub166EA(index);
@@ -1722,30 +1719,29 @@ void LilliputEngine::sub16626() {
 }
 
 byte LilliputEngine::sub166EA(int index) {
-	debugC(2, kDebugEngine, "sub166EA(%d, %d)", index);
+	debugC(2, kDebugEngine, "sub166EA(%d)", index);
 
 	_scriptHandler->_array12811[index] = 0x10;
 	_scriptHandler->_characterScriptEnabled[index] = 1;
 	return 1;
 }
 
-byte LilliputEngine::sub166F7(int index, int var1, int tmpVal) {
-	debugC(2, kDebugEngine, "sub166F7(%d, %d, %d)", index, var1, tmpVal);
+byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
+	debugC(2, kDebugEngine, "sub166F7(%d, %d - %d, %d)", index, var1.x, var1.y, tmpVal);
 
-	byte a1 = (var1 >> 8);
-	byte a2 = (var1 & 0xFF);
+	byte a2 = var1.y;
 	if (a2 != 0) {
 		if ((a2 & 0xF0) == 0)
 			a2 |= (a2 << 4);
 
 		a2 -= 16;
-		_scriptHandler->_array12311[tmpVal] = (a1 << 8) + a2;
+		_scriptHandler->_array12311[tmpVal] = (var1.x << 8) + var1.y;
 
-		if ((a2 & 0xF0) == 0)
+		if ((var1.y & 0xF0) == 0)
 			return 2;
 	}
 
-	_scriptHandler->_array12811[index] -= ((var1 >> 8) & 0x0F);
+	_scriptHandler->_array12811[index] -= (var1.x & 0x0F);
 	return 3;
 }
 
@@ -1768,25 +1764,25 @@ byte LilliputEngine::sub16729(int index) {
 	debugC(2, kDebugEngine, "sub16729(%d)", index);
 
 	int arg1 = index | 0xFF00;
-	int pos1 = (_scriptHandler->_array16123[index] << 8) | (_scriptHandler->_array1614B[index] & 0xFF);
-	int pos2 = (_scriptHandler->_viewportPos.x << 8) | (_scriptHandler->_viewportPos.y & 0xFF);
+	Common::Point pos1 = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
+	Common::Point pos2 = _scriptHandler->_viewportPos;
 	_soundHandler->contentFct2(); // TODO: add arg pos1 and pos2
 	return 2;
 }
 
 byte LilliputEngine::sub1675D(int index, int var1) {
-	debugC(2, kDebugEngine, "sub1675D(%d, %d)", index, var1);
+	debugC(2, kDebugEngine, "sub1675D(%d)", index);
 
 	int var2 = _scriptHandler->_array10A39[index];
-	int var1h = _scriptHandler->_array16123[var2];
-	int var1l = _scriptHandler->_array1614B[var2];
-	int var3 = _array109E9[index];
+	int var1h = _scriptHandler->_array16123PosX[var2];
+	int var1l = _scriptHandler->_array1614BPosY[var2];
+	int var3 = _array109E9PosX[index];
 
 	if ((var3 != 0xFF) && (var3 == _array10999PosX[index])) {
-		var3 = _array10A11[index];
+		var3 = _array10A11PosY[index];
 		if (var3 == _array109C1PosY[index]) {
-			_array109E9[index] = var1h;
-			_array10A11[index] = var1l;
+			_array109E9PosX[index] = var1h;
+			_array10A11PosY[index] = var1l;
 		}
 	}
 
@@ -1802,7 +1798,7 @@ void LilliputEngine::sub16EBC() {
 	int index2 = 3;
 
 	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
-		int var2 = (_scriptHandler->_array1614B[index1] << 8) + (_scriptHandler->_array16123[index1] << 2);
+		int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2); 
 		int var1 = (_bufferIsoMap[index2 + var2] & 0x40);
 
 		if (var1 == _array16E94[index1])
@@ -2121,7 +2117,7 @@ void LilliputEngine::sub16B8F(int index, int x, int y, int flag) {
 	debugC(2, kDebugEngine, "sub16B8F(%d, %d, %d)", index, x, y);
 
 	int diffX = x >> 3;
-	if (((diffX & 0xFF) == _scriptHandler->_array16123[index]) && ((y >> 3) == _scriptHandler->_array1614B[index])) {
+	if (((diffX & 0xFF) == _scriptHandler->_array16123PosX[index]) && ((y >> 3) == _scriptHandler->_array1614BPosY[index])) {
 		_characterPositionX[index] = x;
 		_characterPositionY[index] = y;
 	}
@@ -2129,7 +2125,7 @@ void LilliputEngine::sub16B8F(int index, int x, int y, int flag) {
 	if ((x < 0) || (x >= 512) || (y < 0) || (y >= 512))
 		return;
 
-	int mapIndex = (_scriptHandler->_array1614B[index] << 6) + _scriptHandler->_array16123[index];
+	int mapIndex = (_scriptHandler->_array1614BPosY[index] << 6) + _scriptHandler->_array16123PosX[index];
 	mapIndex <<= 2;
 
 	if ((_bufferIsoMap[mapIndex + 3] & _array16C58[flag]) == 0)
@@ -2509,12 +2505,14 @@ void LilliputEngine::loadRules() {
 	// Chunk 12
 	_rulesChunk12_size = f.readUint16LE();
 	assert(_rulesChunk12_size <= 40);
+	uint16 tmpVal;
 
 	for (int i = 0; i < _rulesChunk12_size; i++) {
 		_rectXMinMax[i] = f.readUint16LE();
 		_rectYMinMax[i] = f.readUint16LE();
 		_rulesBuffer12_3[i] = f.readUint16LE();
-		_rulesBuffer12_4[i] = f.readUint16LE();
+		tmpVal = f.readUint16LE();
+		_rulesBuffer12Pos[i] = Common::Point(tmpVal >> 8, tmpVal & 0xFF);
 	}
 
 	// Chunk 13
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 0caf627..f2b38ca 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -152,9 +152,9 @@ public:
 
 	byte *_rulesChunk1;
 	int _currentScriptCharacter;
-	int _characterPositionX[40];
-	int _characterPositionY[40];
-	byte _characterPositionAltitude[40];
+	int16 _characterPositionX[40];
+	int16 _characterPositionY[40];
+	char _characterPositionAltitude[40];
 	int _characterFrameArray[40];
 	byte _rulesBuffer2_5[40];
 	byte _rulesBuffer2_6[40];
@@ -184,26 +184,26 @@ public:
 	int *_rulesChunk10;
 	byte *_rulesChunk11;
 	int _rulesChunk12_size;
-	uint16 _rectXMinMax[40];
-	uint16 _rectYMinMax[40];
+	int16 _rectXMinMax[40];
+	int16 _rectYMinMax[40];
 	int _rulesBuffer12_3[40];
-	int _rulesBuffer12_4[40];
+	Common::Point _rulesBuffer12Pos[40];
 	int _word12F68_ERULES;
 	byte _rulesBuffer13_1[20];
 	int _interfaceHotspotsX[20];
 	int _interfaceHotspotsY[20];
 	byte _rulesBuffer13_4[20];
-	byte _array10999PosX[40];
-	byte _array109C1PosY[40];
+	int16 _array10999PosX[40];
+	int16 _array109C1PosY[40];
 	byte _array15AC8[256];
 	byte _charactersToDisplay[40];
-	byte _characterRelativePositionX[40];
-	byte _characterRelativePositionY[40];
-	byte _characterDisplayX[40];
-	byte _characterDisplayY[40];
+	int16 _characterRelativePositionX[40];
+	int16 _characterRelativePositionY[40];
+	int16 _characterDisplayX[40];
+	int16 _characterDisplayY[40];
 	byte _array12299[40];
-	byte _array109E9[40];
-	byte _array10A11[40];
+	int16 _array109E9PosX[40];
+	int16 _array10A11PosY[40];
 	byte _array16E94[40];
 	byte _array16C54[4];
 	byte _array16C58[4];
@@ -266,7 +266,7 @@ public:
 	void renderCharacters(byte *buf, byte x, byte y);
 
 	byte sub16799(int param1, int index);
-	int sub16B0C(Common::Point param1, Common::Point param2);
+	int getDirection(Common::Point param1, Common::Point param2);
 	void addCharToBuf(byte character);
 	void prepareGoldAmount(int param1);
 	void sub12F37();
@@ -305,7 +305,7 @@ public:
 	void sub16B8F(int index, int x, int y, int flag);
 	byte sub1675D(int index, int var1);
 	byte sub16729(int index);
-	byte sub166F7(int index, int var1, int tmpVal);
+	byte sub166F7(int index, Common::Point var1, int tmpVal);
 	void sub1693A(int index);
 
 	void initGame(const LilliputGameDescription *gd);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7b267ab..c38bc8f 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -65,8 +65,8 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array10AB1[i] = 0;
 		_array12811[i] = 16;
 		_array12839[i] = 0xFF;
-		_array16123[i] = 0;
-		_array1614B[i] = 0;
+		_array16123PosX[i] = 0;
+		_array1614BPosY[i] = 0;
 		_array122C1[i] = 0;
 	}
 
@@ -307,7 +307,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17BF2();
 		break;
 	case 0x16:
-		OC_sub17ACC();
+		OC_setCurrentScriptCharacterPos();
 		break;
 	case 0x17:
 		OC_resetByte16F04();
@@ -370,7 +370,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17EC5();
 		break;
 	case 0x2B:
-		OC_sub17EF4();
+		OC_setCharacterDirectionTowardsPos();
 		break;
 	case 0x2C:
 		OC_sub17F08();
@@ -382,7 +382,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17F68();
 		break;
 	case 0x2F:
-		OC_getNextVal();
+		OC_skipNextVal();
 		break;
 	case 0x30:
 		OC_sub17FD2();
@@ -629,7 +629,7 @@ static const OpCode opCodes2[] = {
 /* 0x13 */	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
 /* 0x14 */	{ "OC_callScript", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script
 /* 0x15 */	{ "OC_sub17BF2", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script then stop
-/* 0x16 */	{ "OC_sub17ACC", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },  
+/* 0x16 */	{ "OC_setCurrentScriptCharacterPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },  
 /* 0x17 */	{ "OC_resetByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x18 */	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
 /* 0x19 */	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
@@ -650,11 +650,11 @@ static const OpCode opCodes2[] = {
 /* 0x28 */	{ "OC_sub17E7E", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x29 */	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-/* 0x2b */	{ "OC_sub17EF4", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
+/* 0x2b */	{ "OC_setCharacterDirectionTowardsPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x2c */	{ "OC_sub17F08", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x2e */	{ "OC_sub17F68", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x2f */	{ "OC_getNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x2f */	{ "OC_skipNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x30 */	{ "OC_sub17FD2", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x32 */	{ "OC_setByte10B29", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
@@ -1386,8 +1386,8 @@ byte LilliputScript::OC_comparePos() {
 	debugC(2, kDebugScript, "OC_comparePos()");
 
 	int index = getValue1();
-	byte d1 = _array16123[index];
-	byte d2 = _array1614B[index];
+	byte d1 = _array16123PosX[index];
+	byte d2 = _array1614BPosY[index];
 	Common::Point var1 = getPosFromScript();
 
 	if (var1 == Common::Point(d1, d2))
@@ -1559,7 +1559,7 @@ byte LilliputScript::OC_compareCoords_2() {
 	debugC(1, kDebugScript, "OC_compareCoords_2()");
 
 	int index = getValue1();
-	Common::Point var1 = Common::Point(_array16123[index], _array1614B[index]);
+	Common::Point var1 = Common::Point(_array16123PosX[index], _array1614BPosY[index]);
 	uint16 var2 = _currScript->readUint16LE();
 	uint16 var3 = _vm->_rectXMinMax[var2];
 	uint16 var4 = _vm->_rectYMinMax[var2];
@@ -2274,8 +2274,8 @@ void LilliputScript::OC_sub17A8D() {
 	if (tmpVal == _vm->_word10804)
 		_viewportCharacterTarget = 0xFFFF;
 
-	_vm->_characterPositionX[tmpVal] = 0xFFFF;
-	_vm->_characterPositionY[tmpVal] = 0xFFFF;
+	_vm->_characterPositionX[tmpVal] = -1;
+	_vm->_characterPositionY[tmpVal] = -1;
 }
 
 void LilliputScript::OC_saveAndQuit() {
@@ -2360,14 +2360,13 @@ void LilliputScript::OC_sub17BF2() {
 	sub17B6C(0);
 }
 
-// TODO: rename arrays
-void LilliputScript::OC_sub17ACC() {
-	debugC(1, kDebugScript, "OC_sub17ACC()");
+void LilliputScript::OC_setCurrentScriptCharacterPos() {
+	debugC(1, kDebugScript, "OC_setCurrentScriptCharacterPos()");
 
-	Common::Point var = getPosFromScript();
-	_vm->_array10999PosX[_vm->_currentScriptCharacter] = var.x;
-	_vm->_array109C1PosY[_vm->_currentScriptCharacter] = var.y;
-	_vm->_array109E9[_vm->_currentScriptCharacter] = 0xFF;
+	Common::Point pos = getPosFromScript();
+	_vm->_array10999PosX[_vm->_currentScriptCharacter] = pos.x;
+	_vm->_array109C1PosY[_vm->_currentScriptCharacter] = pos.y;
+	_vm->_array109E9PosX[_vm->_currentScriptCharacter] = -1;
 }
 
 void LilliputScript::OC_resetByte16F04() {
@@ -2583,17 +2582,18 @@ void LilliputScript::OC_sub17EC5() {
 	computeOperation(compBuf, oper, var3);*/
 }
 
-Common::Point LilliputScript::sub17285(int index) {
+Common::Point LilliputScript::getCharacterTilePos(int index) {
+	debugC(2, kDebugScript, "getCharacterTilePos(%d)", index);
+
 	return Common::Point(_vm->_characterPositionX[index] >> 3, _vm->_characterPositionY[index] >> 3);
 }
 
-// TODO rename to set direction
-void LilliputScript::OC_sub17EF4() {
-	debugC(1, kDebugScript, "OC_sub17EF4()");
+void LilliputScript::OC_setCharacterDirectionTowardsPos() {
+	debugC(1, kDebugScript, "OC_setCharacterDirectionTowardsPos()");
 
 	Common::Point pos1 = getPosFromScript();
-	Common::Point tilePos = sub17285(_vm->_currentScriptCharacter);
-	int dir = _vm->sub16B0C(tilePos, pos1);
+	Common::Point tilePos = getCharacterTilePos(_vm->_currentScriptCharacter);
+	int dir = _vm->getDirection(tilePos, pos1);
 	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = dir;
 }
 
@@ -2627,8 +2627,8 @@ void LilliputScript::OC_sub17F4F() {
 	debugC(1, kDebugScript, "OC_sub17F4F()");
 
 	int var = getValue1();
-	_array10A39[_vm->_currentScriptCharacter] = var;
-	_vm->_array109E9[_vm->_currentScriptCharacter] = 0xFF;
+	_array10A39[_vm->_currentScriptCharacter] = var & 0xFF;
+	_vm->_array109E9PosX[_vm->_currentScriptCharacter] = -1;
 }
 
 void LilliputScript::OC_sub17F68() {
@@ -2643,7 +2643,7 @@ void LilliputScript::OC_sub17F68() {
 	int cx = _byte17F60[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
 	int cy = _byte17F64[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
 
-	Common::Point pos = sub17285(_vm->_currentScriptCharacter);
+	Common::Point pos = getCharacterTilePos(_vm->_currentScriptCharacter);
 
 	int newPosX = pos.x + cx;
 	int newPosY = pos.y + cy;
@@ -2665,10 +2665,13 @@ void LilliputScript::OC_sub17F68() {
 	_byte12A09 = 0;
 
 }
-void LilliputScript::OC_getNextVal() {
-	debugC(1, kDebugScript, "OC_getNextVal()");
+
+void LilliputScript::OC_skipNextVal() {
+	debugC(1, kDebugScript, "OC_skipNextVal()");
+
 	 _currScript->readUint16LE();
 }
+
 void LilliputScript::OC_sub17FD2() {
 	debugC(1, kDebugScript, "OC_sub17FD2()");
 	
@@ -3178,8 +3181,8 @@ void LilliputScript::OC_sub186E5_snd() {
 
 	byte var4h = 0xFF;
 	byte var4l = (index & 0xFF);
-	byte var3h = _array16123[index];
-	byte var3l = _array1614B[index];
+	byte var3h = _array16123PosX[index];
+	byte var3l = _array1614BPosY[index];
 	byte var2h = (_viewportPos.x & 0xFF);
 	byte var2l = (_viewportPos.y & 0xFF);
 	int var1 = _currScript->readUint16LE();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 0016312..2e62c1f 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -61,8 +61,8 @@ public:
 
 	byte _characterScriptEnabled[40];
 	byte _array122E9[20];
-	byte _array16123[40];
-	byte _array1614B[40];
+	char _array16123PosX[40];
+	char _array1614BPosY[40];
 	byte _array12811[40];
 	byte _array10AB1[40];
 	byte _array122FD[20];
@@ -136,7 +136,7 @@ private:
 	void sub18B7C(int var1, int var3);
 	void sub189B8();
 	void sub189F5();
-	Common::Point sub17285(int index);
+	Common::Point getCharacterTilePos(int index);
 	int sub18BB7(int index);
 
 	int16 getValue1();
@@ -221,7 +221,7 @@ private:
 	void OC_setByte18823();
 	void OC_callScript();
 	void OC_sub17BF2();
-	void OC_sub17ACC();
+	void OC_setCurrentScriptCharacterPos();
 	void OC_resetByte16F04();
 	void OC_sub17AE1();
 	void OC_sub17AEE();
@@ -242,11 +242,11 @@ private:
 	void OC_changeCurrentCharacterSprite();
 	void OC_sub17E99();
 	void OC_sub17EC5();
-	void OC_sub17EF4();
+	void OC_setCharacterDirectionTowardsPos();
 	void OC_sub17F08();
 	void OC_sub17F4F();
 	void OC_sub17F68();
-	void OC_getNextVal();
+	void OC_skipNextVal();
 	void OC_sub17FD2();
 	void OC_sub17FDD();
 	void OC_setByte10B29();


Commit: 6b7026256305dc07e9aac095c7f7d19296d7029e
    https://github.com/scummvm/scummvm/commit/6b7026256305dc07e9aac095c7f7d19296d7029e
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6373681..2a5f6db 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1424,8 +1424,8 @@ void LilliputEngine::sub167EF(int index) {
 
 	if (word167EB = 0xFFFF) {
 		int tmpVal = sub16901(_array10999PosX[index], _array109C1PosY[index]);
-		_array109E9PosX[index] = _rulesBuffer12Pos[tmpVal].x;
-		_array10A11PosY[index] = _rulesBuffer12Pos[tmpVal].y;
+		_array109E9PosX[index] = _rulesBuffer12Pos4[tmpVal].x;
+		_array10A11PosY[index] = _rulesBuffer12Pos4[tmpVal].y;
 		return;
 	}
 
@@ -1434,13 +1434,13 @@ void LilliputEngine::sub167EF(int index) {
 		  (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
 		  (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
 		  (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF)) ) {
-		_array109E9PosX[index] = _rulesBuffer12Pos[word167ED].x;
-		_array10A11PosY[index] = _rulesBuffer12Pos[word167ED].y;
+		_array109E9PosX[index] = _rulesBuffer12Pos4[word167ED].x;
+		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
 	}
 
-	_array109E9PosX[index] = _rulesBuffer12Pos[word167EB].x;
-	_array10A11PosY[index] = _rulesBuffer12Pos[word167EB].y;
+	_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
+	_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
 	int var4h = (_rectXMinMax[index] >> 8);
 	int var4l = (_rectXMinMax[index] & 0xFF);
 
@@ -1489,7 +1489,7 @@ void LilliputEngine::sub1693A(int index) {
 
 	int var1h = _scriptHandler->_array16123PosX[index];
 	int var1l = _scriptHandler->_array1614BPosY[index];
-	_word16937 = (var1h << 8) + var1l;
+	_word16937Pos = Common::Point(var1h, var1l);
 
 	sub16A08(index);
 
@@ -1532,15 +1532,14 @@ void LilliputEngine::sub1693A(int index) {
 	_characterDirectionArray[index] = retVal;
 }
 
-// TODO rename _word16937
 byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	debugC(2, kDebugEngine, "sub16A76(%d, %d)", indexb, indexs);
 
 	static const char _array16A6C[4] = {1, 0, 0, -1};
 	static const char _array16A70[4] = {0, -1, 1, 0};
 
-	char var1h = (_word16937 >> 8) + _array16A6C[indexb];
-	char var1l = (_word16937 & 0xFF) + _array16A70[indexs];
+	char var1h = _word16937Pos.x + _array16A6C[indexb];
+	char var1l = _word16937Pos.y + _array16A70[indexs];
 
 	int var2 = sub168DA(Common::Point(var1h, var1l));
 	if (var2 == 0xFFFF)
@@ -1548,8 +1547,8 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 
 	int _word16A74 = var2; // useless?
 
-	var1h = (_word16937 >> 8);
-	var1l = (_word16937 & 0xFF);
+	var1h = _word16937Pos.x;
+	var1l = _word16937Pos.y;
 
 	if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
 		return 0;
@@ -1593,8 +1592,8 @@ void LilliputEngine::sub16A08(int index) {
 	int _array16A00[4];
 
 	for (int i = 3; i >= 0; i--) {
-		byte var1h = (_word16937 >> 8) + _array169F8[i] - _array109E9PosX[index];
-		byte var1l = (_word16937 & 0xFF) + _array169FC[i] - _array10A11PosY[index];
+		int16 var1h = _word16937Pos.x + _array169F8[i] - _array109E9PosX[index];
+		int16 var1l = _word16937Pos.y + _array169FC[i] - _array10A11PosY[index];
 		_array16A00[i] = (var1l * var1l) + (var1h * var1h);
 	}
 	_array1692B[0] = 0;
@@ -2510,9 +2509,10 @@ void LilliputEngine::loadRules() {
 	for (int i = 0; i < _rulesChunk12_size; i++) {
 		_rectXMinMax[i] = f.readUint16LE();
 		_rectYMinMax[i] = f.readUint16LE();
-		_rulesBuffer12_3[i] = f.readUint16LE();
 		tmpVal = f.readUint16LE();
-		_rulesBuffer12Pos[i] = Common::Point(tmpVal >> 8, tmpVal & 0xFF);
+		_rulesBuffer12Pos3[i] = Common::Point(tmpVal >> 8, tmpVal & 0xFF);
+		tmpVal = f.readUint16LE();
+		_rulesBuffer12Pos4[i] = Common::Point(tmpVal >> 8, tmpVal & 0xFF);
 	}
 
 	// Chunk 13
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index f2b38ca..de36c19 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -142,7 +142,7 @@ public:
 	int _currentDisplayCharacter;
 	int _displayStringIndex;
 	int _word1289D;
-	int _word16937;
+	Common::Point _word16937Pos;
 
 	short _word15E5D[40];
 	byte _byte15E35[40];
@@ -186,8 +186,8 @@ public:
 	int _rulesChunk12_size;
 	int16 _rectXMinMax[40];
 	int16 _rectYMinMax[40];
-	int _rulesBuffer12_3[40];
-	Common::Point _rulesBuffer12Pos[40];
+	Common::Point _rulesBuffer12Pos3[40];
+	Common::Point _rulesBuffer12Pos4[40];
 	int _word12F68_ERULES;
 	byte _rulesBuffer13_1[20];
 	int _interfaceHotspotsX[20];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index c38bc8f..bd3791c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -768,7 +768,7 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 	case 0xF8: {
 		int index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
-		str = Common::String::format("_vm->_rulesBuffer12_3[%d]", index);
+		str = Common::String::format("_vm->_rulesBuffer12Pos3[%d]", index);
 	}
 	case 0xF7: {
 		str = Common::String::format("(_characterPositionTileX[_currentCharacterVariables[6]], _characterPositionTileY[_currentCharacterVariables[6]])");
@@ -1334,7 +1334,7 @@ Common::Point LilliputScript::getPosFromScript() {
 	case 0xF8: {
 		int8 index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
-		return Common::Point(_vm->_rulesBuffer12_3[index] >> 8, _vm->_rulesBuffer12_3[index] & 0xFF);
+		return _vm->_rulesBuffer12Pos3[index];
 		}
 	case 0xF7: {
 		int8 index = _vm->_currentCharacterVariables[6];


Commit: 23dc740de4b706a5285ef8e695c5e54ab2533555
    https://github.com/scummvm/scummvm/commit/23dc740de4b706a5285ef8e695c5e54ab2533555
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming, fix bug in reverseFindHotspot

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 2a5f6db..2d529fd 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -606,7 +606,7 @@ void LilliputEngine::displayFunction12() {
 
 void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3) {
 	debugC(1, kDebugEngine, "displayFunction13(buf, %d, %d, %d)", var1, var2, var3);
-
+	
 	byte tmpByte1 = ((7 + (var2 >> 8) - (var2 & 0xFF)) << 4) & 0xFF;
 	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >> 7) ) << 3) & 0xFF;
 
@@ -670,7 +670,7 @@ void LilliputEngine::displayCharactersOnMap() {
 			 int y = (3 * _scriptHandler->_array1614BPosY[index]) + 1;
 			 int x = (_scriptHandler->_array16123PosX[index] * 4) + 1;
 
-			 _word15E5D[index] = y * 320 + x;
+			 _word15E5D[index] = y * 320 + x; 
 			 _byte15E35[index] = buf[y * 320 + x];
 			 buf[y * 320 + x] = _scriptHandler->_array128EF[index];
 		}
@@ -732,7 +732,7 @@ void LilliputEngine::sub16217() {
 			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
 			_charactersToDisplay[_numCharactersToDisplay] = i;
 			++_numCharactersToDisplay;
-		}
+ 		}
 	}
 
 	sortCharacters();
@@ -864,7 +864,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	int dx = x2 - x1;
 	int dy = y2 - y1;
 
-	int word16DCB = 0;
+	int word16DCB = 0; 
 	int word16DCD = 0;
 	int word16DD1 = 0;
 	int word16DCF = 0;
@@ -903,7 +903,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	word16DCB += word16DCD;
 
 	int var1 = byte16DD4;
-	int count = 0;
+	int count = 0; 
 
 	while ( *isoMap == 0xFF ) {
 		if (var1 > 0) {
@@ -913,7 +913,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 			isoMap += word16DCF;
 			var1 += byte16DD4;
 		}
-
+		
 		count++;
 		if (count == dy) {
 			return 0;
@@ -932,7 +932,7 @@ void LilliputEngine::sub15F75() {
 
 	if ((newX >= 64) || (newY >= 64))
 		return;
-
+	
 	_savedMousePosDivided = Common::Point(newX, newY);
 	_byte16F07_menuId = 5;
 }
@@ -961,7 +961,7 @@ void LilliputEngine::sub15F31(bool &forceReturnFl) {
 
 	_mouseButton = 0;
 	sub15F75();
-
+	
 	_displayMap = 0;
 	paletteFadeOut();
 	_word15AC2 = 0;
@@ -985,20 +985,20 @@ void LilliputEngine::sub16CA0() {
 
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
-			if ((index != index2 ) &&
+			if ((index != index2 ) && 
 				(_rulesBuffer2_5[index] != index2) &&
 				(_rulesBuffer2_5[index2] != index) &&
 				(_rulesBuffer2_11[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_array16123PosX[index2];
 				int d2 = _scriptHandler->_array1614BPosY[index2];
-
+	
 				if (d1 != 0xFF) {
 					int x = c1 - d1;
 					if ((x > -6) && (x < 6)) {
 						int y = c2 - d2;
 						if ((y > -6) && (y < 6)) {
 							_byte16C9F = 1;
-
+	
 							if ((c1 == d1) && (c2 == d2)) {
 								_byte16C9F = 4;
 							} else if((_rulesBuffer2_11[index] & 4) != 0) {
@@ -1012,7 +1012,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;
+											_byte16C9F = 1;	
 									}
 								} else if (_characterDirectionArray[index] == 1) {
 									if (d2 < c2) {
@@ -1022,7 +1022,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;
+											_byte16C9F = 1;	
 									}
 								} else if (_characterDirectionArray[index] == 2) {
 									if (d2 > c2) {
@@ -1032,7 +1032,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;
+											_byte16C9F = 1;	
 									}
 								} else {
 									if (d1 < c1) {
@@ -1042,7 +1042,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;
+											_byte16C9F = 1;	
 									}
 								}
 							}
@@ -1057,7 +1057,7 @@ void LilliputEngine::sub16CA0() {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
 				val = (val & 0xFF00) | _byte16C9F;
 			}
-			_scriptHandler->_array10B51[index2 + index * 40] = val;
+			_scriptHandler->_array10B51[index2 + index * 40] = val;	
 
 		}
 
@@ -1078,13 +1078,13 @@ void LilliputEngine::displayFunction17() {
 
 void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
-
+	
 	displayFunction5();
-
+	
 	if ((var1 & 0xFF) == 0x2D) {
 		var2 += 35;
 		var3 -= 35;
-
+		
 		if (var3 < 0) {
 			var2 += var3;
 			var3 = -var3;
@@ -1094,17 +1094,17 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	byte *vgaBuf = (byte *)_mainSurface->getPixels();
 	int tmpVal = (var3 >> 8) + ((var3 & 0xFF) << 8);
 	int vgaIndex = var2 + tmpVal + (tmpVal >> 2);
-
+	
 	if (var3 == 0)
 		++var3;
-
+	
 	for (int i = 0; i < 4; i++) {
 		for (int j = 0; j < var3; j++) {
 			vgaBuf[vgaIndex + j] = 2;
 		}
 		vgaIndex += 320;
 	}
-
+	
 	displayFunction4();
 }
 
@@ -1244,7 +1244,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 	do {
 		_scriptHandler->_viewportPos.x += dx;
 		_scriptHandler->_viewportPos.y += dy;
-
+		
 		displayFunction9();
 		displayFunction15();
 		displayFunction14();
@@ -1288,7 +1288,7 @@ void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
 			frame += _scriptHandler->_array10AB1[index];
 			if ((flag & 1) == 1)
 				frame += _spriteSizeArray[index];
-
+			
 			if (_array12299[index] != 0xFF) {
 				frame = _array12299[index] + 82;
 				--_array12299[index];
@@ -1307,11 +1307,11 @@ void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
 
 void LilliputEngine::sub1546F(byte displayX, byte displayY) {
 	debugC(2, kDebugEngine, "sub1546F(%d, %d)", displayX, displayY);
-
+	
 	int orgX = displayX + 8;
 	int orgY = displayY;
 	int var2 = 0;
-
+	
 	int x = orgX;
 	int y = orgY;
 	do {
@@ -1319,10 +1319,10 @@ void LilliputEngine::sub1546F(byte displayX, byte displayY) {
 		--x;
 		y >>= 1;
 	} while (y != 0);
-
+	
 	x = orgX + 1;
 	y = orgY >> 1;
-
+	
 	while (y != 0) {
 		sub15498(x, y, var2);
 		++x;
@@ -1332,7 +1332,7 @@ void LilliputEngine::sub1546F(byte displayX, byte displayY) {
 
 void LilliputEngine::sub15498(byte x, byte y, int var2) {
 	debugC(2, kDebugEngine, "sub15498(%d, %d, %d)", x, y, var2);
-
+	
 	int index = x + ((var2 & 0xFF) << 8) + (var2 >> 8);
 	for (int i = 1 + y - var2; i > 0; i--) {
 		_buffer1_45k[index] = 17;
@@ -1412,24 +1412,24 @@ byte LilliputEngine::sub16799(int index, int param1) {
 //TODO rename arrays
 void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngine, "sub167EF(%d)", index);
-
-	int word167EB = sub168DA(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
-	int word167ED = sub168DA(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
-
+	
+	int word167EB = findHotspot(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
+	int word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
+	
 	if (word167EB == word167ED) {
 		_array109E9PosX[index] = _array10999PosX[index];
 		_array10A11PosY[index] = _array109C1PosY[index];
 		return;
 	}
-
-	if (word167EB = 0xFFFF) {
-		int tmpVal = sub16901(_array10999PosX[index], _array109C1PosY[index]);
+	
+	if (word167EB == -1) {
+		int tmpVal = reverseFindHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
 		_array109E9PosX[index] = _rulesBuffer12Pos4[tmpVal].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[tmpVal].y;
 		return;
 	}
-
-	if ((word167ED != 0xFFFF) &&
+	
+	if ((word167ED != -1) && 
 		  (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
 		  (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
 		  (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
@@ -1438,18 +1438,18 @@ void LilliputEngine::sub167EF(int index) {
 		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
 	}
-
+	
 	_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
 	_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
 	int var4h = (_rectXMinMax[index] >> 8);
 	int var4l = (_rectXMinMax[index] & 0xFF);
-
+	
 	if (var4h != var4l) {
 		if (_array109E9PosX[index] == var4h) {
 			--_array109E9PosX[index];
 			return;
 		}
-
+		
 		if (_array109E9PosX[index] == var4l) {
 			++_array109E9PosX[index];
 			return;
@@ -1466,7 +1466,7 @@ void LilliputEngine::sub167EF(int index) {
 			return;
 		}
 	}
-
+	
 	// var4h == var4l
 	int mapIndex = (((_array10A11PosY[index] >> 2) + _array109E9PosX[index]) << 2);
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
@@ -1476,28 +1476,26 @@ void LilliputEngine::sub167EF(int index) {
 		--_array10A11PosY[index];
 	else if ((tmpVal & 2) != 0)
 		++_array10A11PosY[index];
-	else
+	else 
 		--_array109E9PosX[index];
-
+	
 	return;
 }
 
 void LilliputEngine::sub1693A(int index) {
 	debugC(2, kDebugEngine, "sub1693A(%d)", index);
-
+	
 	static const uint16 _array1692F[4] = {4, 0xFF00, 0x100, 0xFFFC};
 
-	int var1h = _scriptHandler->_array16123PosX[index];
-	int var1l = _scriptHandler->_array1614BPosY[index];
-	_word16937Pos = Common::Point(var1h, var1l);
+	_word16937Pos = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
 
 	sub16A08(index);
-
+	
 	int var2 = (_characterDirectionArray[index] ^ 3);
 	_array1692B[var2] += 0xF8;
 	_byte16939 = 0;
-
-	int mapIndex = ((((var1l << 8) >> 2) + var1h) << 2);
+	
+	int mapIndex = ((((_word16937Pos.y << 8) >> 2) + _word16937Pos.x) << 2);
 	int subMapIndex = 0;
 	int retVal = 0;
 	for (int i = 3; i >= 0; i--) {
@@ -1506,7 +1504,7 @@ void LilliputEngine::sub1693A(int index) {
 			if ((_bufferIsoMap[mapIndex + subMapIndex + 3] & 0x80) != 0) {
 				if (sub16A76(i, index) != 0)
 					_array1692B[i] += 0xEC;
-
+				
 				int tmpVal = ((_rulesBuffer2_10[index] & 7) ^ 7);
 				retVal = _rulesChunk9[_bufferIsoMap[mapIndex + subMapIndex]];
 				tmpVal &= retVal;
@@ -1528,7 +1526,7 @@ void LilliputEngine::sub1693A(int index) {
 			tmpVal = _array1692B[i];
 		}
 	}
-
+	
 	_characterDirectionArray[index] = retVal;
 }
 
@@ -1537,12 +1535,12 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 
 	static const char _array16A6C[4] = {1, 0, 0, -1};
 	static const char _array16A70[4] = {0, -1, 1, 0};
-
+	   
 	char var1h = _word16937Pos.x + _array16A6C[indexb];
 	char var1l = _word16937Pos.y + _array16A70[indexs];
 
-	int var2 = sub168DA(Common::Point(var1h, var1l));
-	if (var2 == 0xFFFF)
+	int var2 = findHotspot(Common::Point(var1h, var1l));
+	if (var2 == -1)
 		return 1;
 
 	int _word16A74 = var2; // useless?
@@ -1562,24 +1560,24 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	return 1;
 }
 
-uint16 LilliputEngine::sub168DA(Common::Point pos) {
-	debugC(2, kDebugEngine, "sub168DA(%d, %d)", pos.x, pos.y);
+int LilliputEngine::findHotspot(Common::Point pos) {
+	debugC(2, kDebugEngine, "findHotspot(%d, %d)", pos.x, pos.y);
 
 	for (int i = 0; i < _rulesChunk12_size; i++) {
 		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
 			return i;
 	}
-	return 0xFFFF;
+	return -1;
 }
 
-uint16 LilliputEngine::sub16901(byte var1h, byte var1l) {
-	debugC(2, kDebugEngine, "sub16901(%d, %d)", var1h, var1l);
+int LilliputEngine::reverseFindHotspot(Common::Point pos) {
+	debugC(2, kDebugEngine, "reverseFindHotspot(%d, %d)", pos.x, pos.y);
 
-	for (int i = _rulesChunk12_size-1; i >= 0 ; i--) {
-		if ((var1h >= (_rectXMinMax[i] >> 8)) && (var1h <= (_rectXMinMax[i] & 0xFF)) && (var1h >= (_rectYMinMax[i] >> 8)) && (var1h <= (_rectYMinMax[i] & 0xFF)))
+	for (int i = _rulesChunk12_size - 1; i >= 0 ; i--) {
+		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y<= (_rectYMinMax[i] & 0xFF)))
 			return i;
 	}
-	return 0xFFFF;
+	return -1;
 }
 
 
@@ -1623,7 +1621,7 @@ void LilliputEngine::addCharToBuf(byte character) {
 
 void LilliputEngine::prepareGoldAmount(int param1) {
 	debugC(2, kDebugEngine, "prepareGoldAmount(%d)", param1);
-
+	
 	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
 
 	int count;
@@ -1639,7 +1637,7 @@ void LilliputEngine::prepareGoldAmount(int param1) {
 		--count;
 
 		byte tmpVal = count + 0x30;
-
+		
 		if (i == 4)
 			addCharToBuf(tmpVal);
 		else if ((count != 0) || (!hideZeros)) {
@@ -1746,7 +1744,7 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 
 byte LilliputEngine::sub166DD(int index, int var1) {
 	debugC(2, kDebugEngine, "sub166DD(%d, %d)", index, var1);
-
+	
 	_characterDirectionArray[index] = (var1 >> 8) & 3;
 	sub16685(index, var1 & 0xFF);
 	return 0;
@@ -1824,7 +1822,7 @@ void LilliputEngine::sub12F37() {
 				--varPtr[0];
 				if (varPtr[0] == 1)
 					_scriptHandler->_characterScriptEnabled[index2] = 1;
-			}
+			}			
 		}
 
 		index1 += 32;
@@ -1861,7 +1859,7 @@ void LilliputEngine::sub130EE() {
 
 	if ((posX < 0) || (posX > 255))
 		return;
-
+	
 	if ((posY < 0) || (posY > 176))
 		return;
 
@@ -1987,7 +1985,7 @@ byte LilliputEngine::sub16675(int idx, int var1) {
 	debugC(2, kDebugEngine, "sub16675(%d, %d)", idx, var1);
 
 	sub16685(idx, var1);
-	int index = (var1 & 0xFF);
+	int index = (var1 & 0xFF);	
 	switch (var1 >> 8) {
 	case 0:
 		break;
@@ -2155,7 +2153,7 @@ void LilliputEngine::sub17224(int var1, int var4) {
 		sub17264(var1, var4);
 		return;
 	}
-
+	
 	if (type == 3) {
 		for (int i = _numCharacters - 1; i >= 0; i--)
 			sub17264(i, var4);
@@ -2248,7 +2246,7 @@ void LilliputEngine::displayHeroismIndicator() {
 	}
 
 	_scriptHandler->_heroismLevel += var2;
-
+	
 	int index = _scriptHandler->_heroismBarX + _scriptHandler->_heroismBarBottomY * 320 ;
 
 	var2 = _scriptHandler->_heroismLevel & 0xFF;
@@ -2300,7 +2298,7 @@ void LilliputEngine::pollEvent() {
 			break;
 		}
 	}
-
+	
 	if (_mousePos != _oldMousePos) {
 		_oldMousePos = _mousePos;
 		if (_skipDisplayFlag1 != 0) {
@@ -2397,7 +2395,7 @@ void LilliputEngine::loadRules() {
 		error("Missing game file ERULES.PRG");
 
 	_word10800_ERULES = f.readUint16LE();
-
+	
 	// Chunk 1
 	int size = f.readUint16LE();
 	_rulesChunk1 = (byte *)malloc(sizeof(byte) * size);
@@ -2700,7 +2698,7 @@ Common::Error LilliputEngine::run() {
 
 	_lastTime = _system->getMillis();
 
-
+	
 
 	//TODO: Init sound/music player
 	_scriptHandler->runScript(ScriptStream(_initScript, _initScript_size));
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index de36c19..316a245 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -257,8 +257,8 @@ public:
 	byte sub16A76(int indexb, int indexs);
 	void sub17224(int var1, int var4);
 	void sub17264(int index, int var4);
-	uint16 sub168DA(Common::Point pos);
-	uint16 sub16901(byte var1h, byte var1l);
+	int findHotspot(Common::Point pos);
+	int reverseFindHotspot(Common::Point pos);
 	byte sub16722(int index, byte var1);
 	byte sub166EA(int index);
 	void sub167EF(int index);


Commit: 355f5985606bf214ba4f9895e57f69906b1a01e4
    https://github.com/scummvm/scummvm/commit/355f5985606bf214ba4f9895e57f69906b1a01e4
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Rename debug channel in order to doublecheck all function, some more renaming and bugfixing, fix some GCC warnings

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h
    engines/lilliput/sound.cpp
    engines/lilliput/sound.h
    engines/lilliput/stream.cpp
    engines/lilliput/stream.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 2d529fd..63edc9f 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -110,7 +110,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_system = syst;
 	DebugMan.addDebugChannel(kDebugEngine, "Engine", "Engine debug level");
 	DebugMan.addDebugChannel(kDebugScript, "Script", "Script debug level");
-	DebugMan.addDebugChannel(kDebugSound, "Sound", "Sound debug level");
+	DebugMan.addDebugChannel(kDebugSound,  "Sound",  "Sound debug level");
+	DebugMan.addDebugChannel(kDebugEngineTBC, "EngineTBC", "Engine debug level");
+	DebugMan.addDebugChannel(kDebugScriptTBC, "ScriptTBC", "Script debug level");
 
 	_console = new LilliputConsole(this);
 	_rnd = 0;
@@ -134,8 +136,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12FCE = 0;
 	_byte129A0 = 0xFF;
 	_numCharactersToDisplay = 0;
-	_nextDisplayCharacterX = 0;
-	_nextDisplayCharacterY = 0;
+	_nextDisplayCharacterPos = Common::Point(0, 0);
 	_byte12A04 = 0;
 	_byte12A05 = 10;
 	_byte12A06 = 2;
@@ -299,10 +300,10 @@ Common::Platform LilliputEngine::getPlatform() const {
 	return _platform;
 }
 
-void LilliputEngine::displayCharacter(int index, int x, int y, int flags) {
-	debugC(2, kDebugEngine, "displayCharacter(%d, %d, %d, %d)", index, x, y, flags);
+void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
+	debugC(2, kDebugEngineTBC, "displayCharacter(%d, %d - %d, %d)", index, pos.x, pos.y, flags);
 
-	byte *buf = _buffer1_45k + (y << 8) + x;
+	byte *buf = _buffer1_45k + (pos.y << 8) + pos.x;
 
 	byte *src = _bufferMen;
 	if (index < 0) {
@@ -340,7 +341,7 @@ void LilliputEngine::displayCharacter(int index, int x, int y, int flags) {
 
 // display mouse cursor, if any
 void LilliputEngine::displayFunction1(byte *buf, int var1, Common::Point pos) {
-	debugC(2, kDebugEngine, "displayFunction1(buf, %d, %d, %d)", var1, pos.x, pos.y);
+	debugC(2, kDebugEngineTBC, "displayFunction1(buf, %d, %d, %d)", var1, pos.x, pos.y);
 
 	int index1 = ((var1 & 0xFF) << 8) + (var1 >> 8);
 	byte *newBuf = &buf[index1];
@@ -361,14 +362,14 @@ void LilliputEngine::displayFunction1(byte *buf, int var1, Common::Point pos) {
 }
 
 void LilliputEngine::displayFunction1a(byte *buf, Common::Point pos) {
-	debugC(2, kDebugEngine, "displayFunction1a(buf, %d, %d)", pos.x, pos.y);
+	debugC(2, kDebugEngineTBC, "displayFunction1a(buf, %d, %d)", pos.x, pos.y);
 
 	displayFunction1(buf, 0, pos);
 }
 
 // save area under mouse cursor
 void LilliputEngine::displayFunction2(byte *buf, Common::Point pos) {
-	debugC(2, kDebugEngine, "displayFunction2(buf, %d, %d)", pos.x, pos.y);
+	debugC(2, kDebugEngineTBC, "displayFunction2(buf, %d, %d)", pos.x, pos.y);
 
 	int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
 	int index2 = pos.x + tmpVal + (tmpVal >> 2);
@@ -383,7 +384,7 @@ void LilliputEngine::displayFunction2(byte *buf, Common::Point pos) {
 
 // Fill 16x16 rect
 void LilliputEngine::displayFunction3(int var1, int var2, int var4) {
-	debugC(2, kDebugEngine, "displayFunction3(%d, %d, %d)", var1, var2, var4);
+	debugC(2, kDebugEngineTBC, "displayFunction3(%d, %d, %d)", var1, var2, var4);
 
 	int tmpVal = ((var4 >> 8) + (var4 & 0xFF));
 	int index = var2 + tmpVal + (tmpVal >> 2);
@@ -398,7 +399,7 @@ void LilliputEngine::displayFunction3(int var1, int var2, int var4) {
 
 // display mouse cursor
 void LilliputEngine::displayFunction4() {
-	debugC(2, kDebugEngine, "displayFunction4()");
+	debugC(2, kDebugEngineTBC, "displayFunction4()");
 
 	if ((_skipDisplayFlag1 != 1) && (_skipDisplayFlag2 != 1)) {
 		_skipDisplayFlag2 = 1;
@@ -413,7 +414,7 @@ void LilliputEngine::displayFunction4() {
 }
 
 void LilliputEngine::displayFunction5() {
-	debugC(2, kDebugEngine, "displayFunction5()");
+	debugC(2, kDebugEngineTBC, "displayFunction5()");
 
 	if ((_skipDisplayFlag1 != 0) && (_skipDisplayFlag2 != 1)) {
 		_skipDisplayFlag2 = 1;
@@ -425,7 +426,7 @@ void LilliputEngine::displayFunction5() {
 
 // save game area
 void LilliputEngine::displayFunction6() {
-	debugC(2, kDebugEngine, "displayFunction6()");
+	debugC(2, kDebugEngineTBC, "displayFunction6()");
 
 	displayFunction5();
 
@@ -441,7 +442,7 @@ void LilliputEngine::displayFunction6() {
 
 // save speech zone
 void LilliputEngine::displayFunction7() {
-	debugC(2, kDebugEngine, "displayFunction7()");
+	debugC(2, kDebugEngineTBC, "displayFunction7()");
 
 	displayFunction5();
 
@@ -456,7 +457,7 @@ void LilliputEngine::displayFunction7() {
 }
 
 void LilliputEngine::displayInterfaceHotspots() {
-	debugC(2, kDebugEngine, "displayInterfaceHotspots()");
+	debugC(2, kDebugEngineTBC, "displayInterfaceHotspots()");
 
 	if (_displayMap == 1)
 		return;
@@ -474,7 +475,7 @@ void LilliputEngine::displayInterfaceHotspots() {
 }
 
 void LilliputEngine::displayFunction9() {
-	debugC(2, kDebugEngine, "displayFunction9()");
+	debugC(2, kDebugEngineTBC, "displayFunction9()");
 
 	memcpy(_buffer2_45k, _buffer3_45k, 45056);
 
@@ -495,7 +496,7 @@ void LilliputEngine::displayFunction9() {
 
 // Display dialog bubble
 void LilliputEngine::displayFunction10() {
-	debugC(2, kDebugEngine, "displayFunction10()");
+	debugC(2, kDebugEngineTBC, "displayFunction10()");
 	static const byte _array15976[16] = {244, 248, 250, 250, 252, 252, 252, 252, 252, 252, 252, 252, 250, 250, 248, 244};
 
 	displayFunction5();
@@ -518,7 +519,7 @@ void LilliputEngine::displayFunction10() {
 }
 
 void LilliputEngine::sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex) {
-	debugC(2, kDebugEngine, "sub15A4C()");
+	debugC(2, kDebugEngineTBC, "sub15A4C()");
 
 	int var3 = 0;
 	int var1;
@@ -550,7 +551,7 @@ void LilliputEngine::sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex) {
 }
 
 void LilliputEngine::displayFunction11(byte *buf) {
-	debugC(2, kDebugEngine, "displayFunction11(%s)", buf);
+	debugC(2, kDebugEngineTBC, "displayFunction11(%s)", buf);
 
 	displayFunction5();
 
@@ -583,7 +584,7 @@ void LilliputEngine::displayFunction11(byte *buf) {
 }
 
 void LilliputEngine::displayFunction12() {
-	debugC(1, kDebugEngine, "displayFunction12()");
+	debugC(1, kDebugEngineTBC, "displayFunction12()");
 
 	displayFunction5();
 
@@ -605,7 +606,7 @@ void LilliputEngine::displayFunction12() {
 }
 
 void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3) {
-	debugC(1, kDebugEngine, "displayFunction13(buf, %d, %d, %d)", var1, var2, var3);
+	debugC(1, kDebugEngineTBC, "displayFunction13(buf, %d, %d, %d)", var1, var2, var3);
 	
 	byte tmpByte1 = ((7 + (var2 >> 8) - (var2 & 0xFF)) << 4) & 0xFF;
 	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >> 7) ) << 3) & 0xFF;
@@ -624,7 +625,7 @@ void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3)
 }
 
 void LilliputEngine::displayFunction14() {
-	debugC(2, kDebugEngine, "displayFunction14()");
+	debugC(2, kDebugEngineTBC, "displayFunction14()");
 
 	if (_displayMap == 1)
 		return;
@@ -646,7 +647,7 @@ void LilliputEngine::displayFunction14() {
 }
 
 void LilliputEngine::restoreMapPoints() {
-	debugC(2, kDebugEngine, "restoreMapPoints()");
+	debugC(2, kDebugEngineTBC, "restoreMapPoints()");
 
 	displayFunction5();
 
@@ -659,7 +660,7 @@ void LilliputEngine::restoreMapPoints() {
 }
 
 void LilliputEngine::displayCharactersOnMap() {
-	debugC(2, kDebugEngine, "displayCharactersOnMap()");
+	debugC(2, kDebugEngineTBC, "displayCharactersOnMap()");
 
 	sub16217();
 	displayFunction5();
@@ -679,7 +680,7 @@ void LilliputEngine::displayCharactersOnMap() {
 }
 
 void LilliputEngine::sub16217() {
-	debugC(2, kDebugEngine, "sub16217()");
+	debugC(2, kDebugEngineTBC, "sub16217()");
 
 	_numCharactersToDisplay = 0;
 	int index = _numCharacters - 1;
@@ -739,21 +740,19 @@ void LilliputEngine::sub16217() {
 }
 
 void LilliputEngine::setNextDisplayCharacter(int var1) {
-	debugC(2, kDebugEngine, "setNextDisplayCharacter(%d)", var1);
+	debugC(2, kDebugEngineTBC, "setNextDisplayCharacter(%d)", var1);
 
 	byte charNum = var1 & 0xFF;
 	if ( charNum < _numCharactersToDisplay) {
 		int index = _charactersToDisplay[charNum];
-		_nextDisplayCharacterX = _characterRelativePositionX[index];
-		_nextDisplayCharacterY = _characterRelativePositionY[index];
+		_nextDisplayCharacterPos = Common::Point(_characterRelativePositionX[index], _characterRelativePositionY[index]);
 	} else {
-		_nextDisplayCharacterX = 0xFF;
-		_nextDisplayCharacterY = 0xFF;
+		_nextDisplayCharacterPos = Common::Point(-1, -1);
 	}
 }
 
 void LilliputEngine::displayFunction15() {
-	debugC(2, kDebugEngine, "displayFunction15()");
+	debugC(2, kDebugEngineTBC, "displayFunction15()");
 
 	sub16217();
 	_currentDisplayCharacter = 0;
@@ -773,7 +772,7 @@ void LilliputEngine::displayFunction15() {
 					var1 += _scriptHandler->_byte12A04;
 				displayFunction13(_buffer1_45k, var1, tmpVal, 1 << 8);
 			}
-			renderCharacters(map, j, i);
+			renderCharacters(map, Common::Point(j, i));
 
 			if (map[2] != 0xFF) {
 				int var1 = map[2];
@@ -788,7 +787,7 @@ void LilliputEngine::displayFunction15() {
 }
 
 void LilliputEngine::displayFunction16() {
-	debugC(2, kDebugEngine, "displayFunction16()");
+	debugC(2, kDebugEngineTBC, "displayFunction16()");
 
 	if (_displayMap == 1) {
 		bool forceReturnFl = false;
@@ -828,7 +827,7 @@ void LilliputEngine::sub1863B() {
 }
 
 void LilliputEngine::paletteFadeOut() {
-	debugC(2, kDebugEngine, "paletteFadeOut()");
+	debugC(2, kDebugEngineTBC, "paletteFadeOut()");
 
 	sub1863B();
 	byte palette[768];
@@ -843,7 +842,7 @@ void LilliputEngine::paletteFadeOut() {
 }
 
 void LilliputEngine::paletteFadeIn() {
-	debugC(2, kDebugEngine, "paletteFadeIn()");
+	debugC(2, kDebugEngineTBC, "paletteFadeIn()");
 
 	byte palette[768];
 	for (int fade = 8; fade <= 256;	fade += 8) {
@@ -857,7 +856,7 @@ void LilliputEngine::paletteFadeIn() {
 }
 
 int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
-	debugC(2, kDebugEngine, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);
+	debugC(2, kDebugEngineTBC, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);
 
 	byte *isoMap = _bufferIsoMap + (x1 << 8) + (y1 << 2) + 1;
 
@@ -923,7 +922,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 }
 
 void LilliputEngine::sub15F75() {
-	debugC(2, kDebugEngine, "sub15F75()");
+	debugC(2, kDebugEngineTBC, "sub15F75()");
 
 	_byte129A0 = 0xFF;
 	_savedMousePosDivided = Common::Point(-1, -1);
@@ -938,7 +937,7 @@ void LilliputEngine::sub15F75() {
 }
 
 void LilliputEngine::sub130B6() {
-	debugC(2, kDebugEngine, "sub130B6()");
+	debugC(2, kDebugEngineTBC, "sub130B6()");
 
 	for (int index = 0; index < _word12F68_ERULES; index++) {
 		if (_scriptHandler->_array122E9[index] == 3)
@@ -947,7 +946,7 @@ void LilliputEngine::sub130B6() {
 }
 
 void LilliputEngine::sub15F31(bool &forceReturnFl) {
-	debugC(2, kDebugEngine, "sub15F31()");
+	debugC(2, kDebugEngineTBC, "sub15F31()");
 
 	forceReturnFl = false;
 	if (_displayMap != 1)
@@ -974,7 +973,7 @@ void LilliputEngine::sub15F31(bool &forceReturnFl) {
 }
 
 void LilliputEngine::sub16CA0() {
-	debugC(2, kDebugEngine, "sub16CA0()");
+	debugC(2, kDebugEngineTBC, "sub16CA0()");
 
 	for (int index = _numCharacters - 1; index >= 0; index--) {
 		if (_rulesBuffer2_11[index] & 1)
@@ -1065,7 +1064,7 @@ void LilliputEngine::sub16CA0() {
 }
 
 void LilliputEngine::displayFunction17() {
-	debugC(2, kDebugEngine, "displayFunction17()");
+	debugC(2, kDebugEngineTBC, "displayFunction17()");
 
 	displayFunction5();
 
@@ -1077,7 +1076,7 @@ void LilliputEngine::displayFunction17() {
 }
 
 void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
-	debugC(2, kDebugEngine, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
+	debugC(2, kDebugEngineTBC, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
 	
 	displayFunction5();
 	
@@ -1109,7 +1108,7 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 }
 
 void LilliputEngine::displayString(byte *buf, int var2, int var4) {
-	debugC(2, kDebugEngine, "displayString(buf, %d, %d)", var2, var4);
+	debugC(2, kDebugEngineTBC, "displayString(buf, %d, %d)", var2, var4);
 
 	int index = var2;
 	int tmpVar4 = (var4 >> 8) + ((var4 & 0xFF) << 8);
@@ -1124,7 +1123,7 @@ void LilliputEngine::displayString(byte *buf, int var2, int var4) {
 }
 
 void LilliputEngine::displayChar(int index, int var1) {
-	debugC(2, kDebugEngine, "displayChar(%d, %d)", index, var1);
+	debugC(2, kDebugEngineTBC, "displayChar(%d, %d)", index, var1);
 
 	int indexVga = index;
 	int indexChar = var1 << 5;
@@ -1139,7 +1138,7 @@ void LilliputEngine::displayChar(int index, int var1) {
 }
 
 void LilliputEngine::sortCharacters() {
-	debugC(2, kDebugEngine, "sortCharacters()");
+	debugC(2, kDebugEngineTBC, "sortCharacters()");
 
 	if (_numCharactersToDisplay <= 1)
 		return;
@@ -1183,7 +1182,7 @@ void LilliputEngine::sortCharacters() {
 
 // Move view port to x/y
 void LilliputEngine::scrollToViewportCharacterTarget() {
-	debugC(2, kDebugEngine, "scrollToViewportCharacterTarget()");
+	debugC(2, kDebugEngineTBC, "scrollToViewportCharacterTarget()");
 
 	if (_scriptHandler->_viewportCharacterTarget == 0xFFFF)
 		return;
@@ -1220,7 +1219,7 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 }
 
 void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
-	debugC(2, kDebugEngine, "viewportScrollTo(%d, %d)", goalPos.x, goalPos.y);
+	debugC(2, kDebugEngineTBC, "viewportScrollTo(%d, %d)", goalPos.x, goalPos.y);
 
 	if (goalPos == _scriptHandler->_viewportPos)
 		return;
@@ -1259,10 +1258,10 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 	_soundHandler->contentFct5();
 }
 
-void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
-	debugC(2, kDebugEngine, "renderCharacters(buf, %d, %d)", x, y);
+void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
+	debugC(2, kDebugEngineTBC, "renderCharacters(buf, %d - %d)", pos.x, pos.y);
 
-	if ((_nextDisplayCharacterX != x) || (_nextDisplayCharacterY != y))
+	if (_nextDisplayCharacterPos != pos)
 		return;
 
 	_byte16552 = 0;
@@ -1295,18 +1294,18 @@ void LilliputEngine::renderCharacters(byte *buf, byte x, byte y) {
 				frame = -frame;
 			}
 
-			displayCharacter(frame, displayX, displayY, flag);
+			displayCharacter(frame, Common::Point(displayX, displayY), flag);
 		}
 	}
 
 	++_currentDisplayCharacter;
 	setNextDisplayCharacter(_currentDisplayCharacter);
 
-	renderCharacters(buf, x, y);
+	renderCharacters(buf, pos);
 }
 
 void LilliputEngine::sub1546F(byte displayX, byte displayY) {
-	debugC(2, kDebugEngine, "sub1546F(%d, %d)", displayX, displayY);
+	debugC(2, kDebugEngineTBC, "sub1546F(%d, %d)", displayX, displayY);
 	
 	int orgX = displayX + 8;
 	int orgY = displayY;
@@ -1331,7 +1330,7 @@ void LilliputEngine::sub1546F(byte displayX, byte displayY) {
 }
 
 void LilliputEngine::sub15498(byte x, byte y, int var2) {
-	debugC(2, kDebugEngine, "sub15498(%d, %d, %d)", x, y, var2);
+	debugC(2, kDebugEngineTBC, "sub15498(%d, %d, %d)", x, y, var2);
 	
 	int index = x + ((var2 & 0xFF) << 8) + (var2 >> 8);
 	for (int i = 1 + y - var2; i > 0; i--) {
@@ -1341,7 +1340,7 @@ void LilliputEngine::sub15498(byte x, byte y, int var2) {
 }
 
 void LilliputEngine::sub189DE() {
-	debugC(2, kDebugEngine, "sub189DE()");
+	debugC(2, kDebugEngineTBC, "sub189DE()");
 
 	if (_byte1881D != 0) {
 		--_byte1881D;
@@ -1353,7 +1352,7 @@ void LilliputEngine::sub189DE() {
 }
 
 int LilliputEngine::getDirection(Common::Point param1, Common::Point param2) {
-	debugC(2, kDebugEngine, "getDirection(%d - %d, %d - %d)", param1.x, param1.y, param2.x, param2.y);
+	debugC(2, kDebugEngineTBC, "getDirection(%d - %d, %d - %d)", param1.x, param1.y, param2.x, param2.y);
 
 	static const char _directionsArray[8] = {0, 2, 0, 1, 3, 2, 3, 1};
 
@@ -1381,7 +1380,7 @@ int LilliputEngine::getDirection(Common::Point param1, Common::Point param2) {
 }
 
 byte LilliputEngine::sub16799(int index, int param1) {
-	debugC(2, kDebugEngine, "sub16799(%d, %d)", index, param1);
+	debugC(2, kDebugEngineTBC, "sub16799(%d, %d)", index, param1);
 
 	Common::Point var3 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
 
@@ -1411,7 +1410,7 @@ byte LilliputEngine::sub16799(int index, int param1) {
 
 //TODO rename arrays
 void LilliputEngine::sub167EF(int index) {
-	debugC(2, kDebugEngine, "sub167EF(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub167EF(%d)", index);
 	
 	int word167EB = findHotspot(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
 	int word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
@@ -1455,8 +1454,8 @@ void LilliputEngine::sub167EF(int index) {
 			return;
 		}
 
-		int var4h = (_rectYMinMax[index] >> 8);
-		int var4l = (_rectYMinMax[index] & 0xFF);
+		var4h = (_rectYMinMax[index] >> 8);
+		var4l = (_rectYMinMax[index] & 0xFF);
 
 		if (var4h != var4l) {
 			if (_array10A11PosY[index] == var4h)
@@ -1483,7 +1482,7 @@ void LilliputEngine::sub167EF(int index) {
 }
 
 void LilliputEngine::sub1693A(int index) {
-	debugC(2, kDebugEngine, "sub1693A(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub1693A(%d)", index);
 	
 	static const uint16 _array1692F[4] = {4, 0xFF00, 0x100, 0xFFFC};
 
@@ -1531,7 +1530,7 @@ void LilliputEngine::sub1693A(int index) {
 }
 
 byte LilliputEngine::sub16A76(int indexb, int indexs) {
-	debugC(2, kDebugEngine, "sub16A76(%d, %d)", indexb, indexs);
+	debugC(2, kDebugEngineTBC, "sub16A76(%d, %d)", indexb, indexs);
 
 	static const char _array16A6C[4] = {1, 0, 0, -1};
 	static const char _array16A70[4] = {0, -1, 1, 0};
@@ -1561,7 +1560,7 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 }
 
 int LilliputEngine::findHotspot(Common::Point pos) {
-	debugC(2, kDebugEngine, "findHotspot(%d, %d)", pos.x, pos.y);
+	debugC(2, kDebugEngineTBC, "findHotspot(%d, %d)", pos.x, pos.y);
 
 	for (int i = 0; i < _rulesChunk12_size; i++) {
 		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
@@ -1571,7 +1570,7 @@ int LilliputEngine::findHotspot(Common::Point pos) {
 }
 
 int LilliputEngine::reverseFindHotspot(Common::Point pos) {
-	debugC(2, kDebugEngine, "reverseFindHotspot(%d, %d)", pos.x, pos.y);
+	debugC(2, kDebugEngineTBC, "reverseFindHotspot(%d, %d)", pos.x, pos.y);
 
 	for (int i = _rulesChunk12_size - 1; i >= 0 ; i--) {
 		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y<= (_rectYMinMax[i] & 0xFF)))
@@ -1582,7 +1581,7 @@ int LilliputEngine::reverseFindHotspot(Common::Point pos) {
 
 
 void LilliputEngine::sub16A08(int index) {
-	debugC(2, kDebugEngine, "sub16A08(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub16A08(%d)", index);
 
 	static const byte _array169F8[4] = {1, 0, 0, 0xFF};
 	static const byte _array169FC[4] = {0, 0xFF, 1, 0};
@@ -1612,7 +1611,7 @@ void LilliputEngine::sub16A08(int index) {
 }
 
 void LilliputEngine::addCharToBuf(byte character) {
-	debugC(2, kDebugEngine, "addCharToBuf(%c)", character);
+	debugC(2, kDebugEngineTBC, "addCharToBuf(%c)", character);
 
 	_displayStringBuf[_displayStringIndex] = character;
 	if (_displayStringIndex < 158)
@@ -1620,7 +1619,7 @@ void LilliputEngine::addCharToBuf(byte character) {
 }
 
 void LilliputEngine::prepareGoldAmount(int param1) {
-	debugC(2, kDebugEngine, "prepareGoldAmount(%d)", param1);
+	debugC(2, kDebugEngineTBC, "prepareGoldAmount(%d)", param1);
 	
 	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
 
@@ -1648,7 +1647,7 @@ void LilliputEngine::prepareGoldAmount(int param1) {
 }
 
 void LilliputEngine::sub16626() {
-	debugC(2, kDebugEngine, "sub16626()");
+	debugC(2, kDebugEngineTBC, "sub16626()");
 
 	int index = _numCharacters - 1;
 	byte result;
@@ -1716,7 +1715,7 @@ void LilliputEngine::sub16626() {
 }
 
 byte LilliputEngine::sub166EA(int index) {
-	debugC(2, kDebugEngine, "sub166EA(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166EA(%d)", index);
 
 	_scriptHandler->_array12811[index] = 0x10;
 	_scriptHandler->_characterScriptEnabled[index] = 1;
@@ -1724,7 +1723,7 @@ byte LilliputEngine::sub166EA(int index) {
 }
 
 byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
-	debugC(2, kDebugEngine, "sub166F7(%d, %d - %d, %d)", index, var1.x, var1.y, tmpVal);
+	debugC(2, kDebugEngineTBC, "sub166F7(%d, %d - %d, %d)", index, var1.x, var1.y, tmpVal);
 
 	byte a2 = var1.y;
 	if (a2 != 0) {
@@ -1743,7 +1742,7 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 }
 
 byte LilliputEngine::sub166DD(int index, int var1) {
-	debugC(2, kDebugEngine, "sub166DD(%d, %d)", index, var1);
+	debugC(2, kDebugEngineTBC, "sub166DD(%d, %d)", index, var1);
 	
 	_characterDirectionArray[index] = (var1 >> 8) & 3;
 	sub16685(index, var1 & 0xFF);
@@ -1751,14 +1750,14 @@ byte LilliputEngine::sub166DD(int index, int var1) {
 }
 
 byte LilliputEngine::sub16722(int index, byte var1) {
-	debugC(2, kDebugEngine, "sub16722(%d, %d)", index, var1);
+	debugC(2, kDebugEngineTBC, "sub16722(%d, %d)", index, var1);
 
 	_rulesBuffer2_10[index] = var1;
 	return 2;
 }
 
 byte LilliputEngine::sub16729(int index) {
-	debugC(2, kDebugEngine, "sub16729(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub16729(%d)", index);
 
 	int arg1 = index | 0xFF00;
 	Common::Point pos1 = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
@@ -1768,7 +1767,7 @@ byte LilliputEngine::sub16729(int index) {
 }
 
 byte LilliputEngine::sub1675D(int index, int var1) {
-	debugC(2, kDebugEngine, "sub1675D(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub1675D(%d)", index);
 
 	int var2 = _scriptHandler->_array10A39[index];
 	int var1h = _scriptHandler->_array16123PosX[var2];
@@ -1790,7 +1789,7 @@ byte LilliputEngine::sub1675D(int index, int var1) {
 }
 
 void LilliputEngine::sub16EBC() {
-	debugC(2, kDebugEngine, "sub16EBC()");
+	debugC(2, kDebugEngineTBC, "sub16EBC()");
 
 	int index2 = 3;
 
@@ -1808,7 +1807,7 @@ void LilliputEngine::sub16EBC() {
 }
 
 void LilliputEngine::sub12F37() {
-	debugC(2, kDebugEngine, "sub12F37()");
+	debugC(2, kDebugEngineTBC, "sub12F37()");
 
 	int index1 = _byte12A04 + 2;
 	int index2 = 0;
@@ -1837,7 +1836,7 @@ void LilliputEngine::sub130EE() {
 //	warning("sub13156");
 
 	if (_mouseButton == 0)
-		// TODO: check _mouse_byte1299F
+		// TODO: check _mouse_clicked
 		return;
 
 	int button = _mouseButton;
@@ -1854,29 +1853,24 @@ void LilliputEngine::sub130EE() {
 	if (forceReturnFl)
 		return;
 
-	int posX = _mousePos.x - 64;
-	int posY = _mousePos.y - 16;
+	Common::Point pos = Common::Point(_mousePos.x - 64, _mousePos.y - 16);
 
-	if ((posX < 0) || (posX > 255))
-		return;
-	
-	if ((posY < 0) || (posY > 176))
+	if ((pos.x < 0) || (pos.x > 255) || (pos.y < 0) || (pos.y > 176))
 		return;
 
 	forceReturnFl = false;
-	sub131B2(posX, posY, forceReturnFl);
+	sub131B2(pos, forceReturnFl);
 	if (forceReturnFl)
 		return;
 
-	sub131FC(posX, posY);
+	sub131FC(pos);
 }
 
-// TODO use Common::Point
-void LilliputEngine::sub131FC(int var2, int var4) {
-	debugC(2, kDebugEngine, "sub131FC(%d, %d)", var2, var4);
+void LilliputEngine::sub131FC(Common::Point pos) {
+	debugC(2, kDebugEngine, "sub131FC(%d, %d)", pos.x, pos.y);
 
-	int x = var2 - 8;
-	int y = var4 - 4;
+	int x = pos.x - 8;
+	int y = pos.y - 4;
 
 	x = (x >> 4) - 7;
 	y = (y >> 3) - 4;
@@ -1892,13 +1886,13 @@ void LilliputEngine::sub131FC(int var2, int var4) {
 	}
 }
 
-void LilliputEngine::sub131B2(int var2, int var4, bool &forceReturnFl) {
-	debugC(2, kDebugEngine, "sub131B2(%d, %d)", var2, var4);
+void LilliputEngine::sub131B2(Common::Point pos, bool &forceReturnFl) {
+	debugC(2, kDebugEngine, "sub131B2(%d, %d)", pos.x, pos.y);
 
 	forceReturnFl = false;
 
 	for (int i = 0; i < _numCharacters; i++) {
-		if ((var2 >= _characterDisplayX[i]) && (var2 <= _characterDisplayX[i] + 17) && (var4 >= _characterDisplayY[i]) && (var4 <= _characterDisplayY[i] + 17) && (i != _word10804)) {
+		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_byte129A0 = i;
 			_byte16F07_menuId = 4;
 			if (_byte12FCE == 1)
@@ -1912,7 +1906,7 @@ void LilliputEngine::sub131B2(int var2, int var4, bool &forceReturnFl) {
 }
 
 void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {
-	debugC(2, kDebugEngine, "checkInterfaceHotspots()");
+	debugC(2, kDebugEngineTBC, "checkInterfaceHotspots()");
 
 	forceReturnFl = false;
 	for (int index = _word12F68_ERULES - 1; index >= 0; index--) {
@@ -1925,7 +1919,7 @@ void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {
 }
 
 int LilliputEngine::sub13240(Common::Point mousePos, int var3, int var4) {
-	debugC(2, kDebugEngine, "sub13240(%d, %d, %d, %d)", mousePos.x, mousePos.y, var3, var4);
+	debugC(2, kDebugEngineTBC, "sub13240(%d, %d, %d, %d)", mousePos.x, mousePos.y, var3, var4);
 
 	if ((mousePos.x < var3) || (mousePos.y < var4))
 		return -1;
@@ -1940,7 +1934,7 @@ int LilliputEngine::sub13240(Common::Point mousePos, int var3, int var4) {
 }
 
 void LilliputEngine::sub1305C(byte index, byte button) {
-	debugC(2, kDebugEngine, "sub1305C(%d, %d)", index, button);
+	debugC(2, kDebugEngineTBC, "sub1305C(%d, %d)", index, button);
 
 	if (_scriptHandler->_array122E9[index] < 2)
 		return;
@@ -1975,14 +1969,14 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 }
 
 void LilliputEngine::sub16685(int idx, int var1) {
-	debugC(2, kDebugEngine, "sub16685(%d, %d)", idx, var1);
+	debugC(2, kDebugEngineTBC, "sub16685(%d, %d)", idx, var1);
 
 	int index = (idx << 5) + (var1 & 0xFF);
 	_scriptHandler->_array10AB1[idx] = _rulesBuffer2_16[index];
 }
 
 byte LilliputEngine::sub16675(int idx, int var1) {
-	debugC(2, kDebugEngine, "sub16675(%d, %d)", idx, var1);
+	debugC(2, kDebugEngineTBC, "sub16675(%d, %d)", idx, var1);
 
 	sub16685(idx, var1);
 	int index = (var1 & 0xFF);	
@@ -2027,69 +2021,69 @@ byte LilliputEngine::sub16675(int idx, int var1) {
 }
 
 void LilliputEngine::sub16B63(int index) {
-	debugC(2, kDebugEngine, "sub16B63(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub16B63(%d)", index);
 
 	static const byte nextDirection[4] = {1, 3, 0, 2};
 	_characterDirectionArray[index] = nextDirection[_characterDirectionArray[index]];
 }
 
 void LilliputEngine::sub16B76(int index) {
-	debugC(2, kDebugEngine, "sub16B76(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub16B76(%d)", index);
 
 	static const byte nextDirection[4] = {2, 0, 3, 1};
 	_characterDirectionArray[index] = nextDirection[_characterDirectionArray[index]];
 }
 
 void LilliputEngine::sub166C0(int index) {
-	debugC(2, kDebugEngine, "sub166C0(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166C0(%d)", index);
 
 	_characterPositionAltitude[index] += 1;
 }
 
 void LilliputEngine::sub166C6(int index) {
-	debugC(2, kDebugEngine, "sub166C6(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166C6(%d)", index);
 
 	_characterPositionAltitude[index] += 2;
 }
 
 void LilliputEngine::sub166CC(int index) {
-	debugC(2, kDebugEngine, "sub166CC(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166CC(%d)", index);
 
 	_characterPositionAltitude[index] -= 1;
 }
 
 void LilliputEngine::sub166D2(int index) {
-	debugC(2, kDebugEngine, "sub166D2(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166D2(%d)", index);
 
 	_characterPositionAltitude[index] -= 2;
 }
 
 void LilliputEngine::sub166B1(int index) {
-	debugC(2, kDebugEngine, "sub166B1(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166B1(%d)", index);
 
 	sub16B31(index, 2);
 }
 
 void LilliputEngine::sub166B6(int index) {
-	debugC(2, kDebugEngine, "sub166B6(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166B6(%d)", index);
 
 	sub16B31(index, 4);
 }
 
 void LilliputEngine::sub166BB(int index) {
-	debugC(2, kDebugEngine, "sub166BB(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166BB(%d)", index);
 
 	sub16B31(index, 0xFE);
 }
 
 void LilliputEngine::sub166D8(int index) {
-	debugC(2, kDebugEngine, "sub166D8(%d)", index);
+	debugC(2, kDebugEngineTBC, "sub166D8(%d)", index);
 
 	sub16B31(index, 3);
 }
 
 void LilliputEngine::sub16B31(int index, int val) {
-	debugC(2, kDebugEngine, "sub16B31(%d, %d)", index, val);
+	debugC(2, kDebugEngineTBC, "sub16B31(%d, %d)", index, val);
 
 	int newX = _characterPositionX[index];
 	int newY = _characterPositionY[index];
@@ -2111,7 +2105,7 @@ void LilliputEngine::sub16B31(int index, int val) {
 }
 
 void LilliputEngine::sub16B8F(int index, int x, int y, int flag) {
-	debugC(2, kDebugEngine, "sub16B8F(%d, %d, %d)", index, x, y);
+	debugC(2, kDebugEngineTBC, "sub16B8F(%d, %d, %d)", index, x, y);
 
 	int diffX = x >> 3;
 	if (((diffX & 0xFF) == _scriptHandler->_array16123PosX[index]) && ((y >> 3) == _scriptHandler->_array1614BPosY[index])) {
@@ -2146,7 +2140,7 @@ void LilliputEngine::sub16B8F(int index, int x, int y, int flag) {
 }
 
 void LilliputEngine::sub17224(int var1, int var4) {
-	debugC(2, kDebugEngine, "sub17224(%d, %d)", var1, var4);
+	debugC(2, kDebugEngineTBC, "sub17224(%d, %d)", var1, var4);
 
 	byte type = (var1 >> 8);
 	if (type == 0) {
@@ -2169,7 +2163,7 @@ void LilliputEngine::sub17224(int var1, int var4) {
 }
 
 void LilliputEngine::sub17264(int index, int var4) {
-	debugC(2, kDebugEngine, "sub17264(%d, %d)", index, var4);
+	debugC(2, kDebugEngineTBC, "sub17264(%d, %d)", index, var4);
 
 	if (_array11D49[index] != 0xFFFF) {
 		_array1289F[index] = var4;
@@ -2180,7 +2174,7 @@ void LilliputEngine::sub17264(int index, int var4) {
 }
 
 void LilliputEngine::sub171CF() {
-	debugC(2, kDebugEngine, "sub171CF()");
+	debugC(2, kDebugEngineTBC, "sub171CF()");
 
 	for (int i = 0; i < _numCharacters; i++) {
 		if (_array1289F[i] != 0xFFFF) {
@@ -2204,7 +2198,7 @@ void LilliputEngine::sub171CF() {
 }
 
 void LilliputEngine::sub12FE5() {
-	debugC(2, kDebugEngine, "sub12FE5()");
+	debugC(2, kDebugEngineTBC, "sub12FE5()");
 
 	if (_byte12A04 != 1)
 		return;
@@ -2226,7 +2220,7 @@ void LilliputEngine::sub12FE5() {
 }
 
 void LilliputEngine::displayHeroismIndicator() {
-	debugC(2, kDebugEngine, "displayHeroismIndicator()");
+	debugC(2, kDebugEngineTBC, "displayHeroismIndicator()");
 
 	if (_scriptHandler->_savedBuffer215Ptr == NULL)
 		return;
@@ -2275,7 +2269,7 @@ void LilliputEngine::displayHeroismIndicator() {
 }
 
 void LilliputEngine::pollEvent() {
-	debugC(2, kDebugEngine, "pollEvent()");
+	debugC(2, kDebugEngineTBC, "pollEvent()");
 
 	Common::Event event;
 	while (_system->getEventManager()->pollEvent(event)) {
@@ -2548,7 +2542,7 @@ void LilliputEngine::loadRules() {
 }
 
 void LilliputEngine::displayVGAFile(Common::String fileName) {
-	debugC(1, kDebugEngine, "displayVGAFile(%s)", fileName.c_str());
+	debugC(1, kDebugEngineTBC, "displayVGAFile(%s)", fileName.c_str());
 
 	displayFunction4();
 
@@ -2585,7 +2579,7 @@ void LilliputEngine::initPalette() {
 }
 
 void LilliputEngine::sub170EE(int index) {
-	debugC(1, kDebugEngine, "sub170EE(%d)", index);
+	debugC(1, kDebugEngineTBC, "sub170EE(%d)", index);
 
 	_currentScriptCharacter = index;
 
@@ -2602,7 +2596,7 @@ void LilliputEngine::sub130DD() {
 }
 
 void LilliputEngine::handleMenu() {
-	debugC(1, kDebugEngine, "handleMenu()");
+	debugC(1, kDebugEngineTBC, "handleMenu()");
 
 	if (_byte16F07_menuId == 0)
 		return;
@@ -2611,9 +2605,9 @@ void LilliputEngine::handleMenu() {
 		return;
 
 	sub170EE(_word10804);
-	debugC(1, kDebugScript, "========================== Menu Script ==============================");
+	debugC(1, kDebugScriptTBC, "========================== Menu Script ==============================");
 	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScript_size));
-	debugC(1, kDebugScript, "========================== End of Menu Script==============================");
+	debugC(1, kDebugScriptTBC, "========================== End of Menu Script==============================");
 	_savedMousePosDivided = Common::Point(-1, -1);
 	_byte129A0 = 0xFF;
 
@@ -2624,7 +2618,7 @@ void LilliputEngine::handleMenu() {
 }
 
 void LilliputEngine::handleGameScripts() {
-	debugC(1, kDebugEngine, "handleGameScripts()");
+	debugC(1, kDebugEngineTBC, "handleGameScripts()");
 
 	int index = _word17081_nextIndex;
 	int i;
@@ -2654,23 +2648,23 @@ void LilliputEngine::handleGameScripts() {
 /*
 	for (int i = 0; i < _gameScriptIndexSize; i++) {
 		assert(tmpVal < _gameScriptIndexSize);
-		debugC(1, kDebugEngine, "================= Game Script %d ==================", i);
+		debugC(1, kDebugEngineTBC, "================= Game Script %d ==================", i);
 		ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[i]], _arrayGameScriptIndex[i + 1] - _arrayGameScriptIndex[i]);
 		_scriptHandler->disasmScript(script);
-		debugC(1, kDebugEngine, "============= End Game Script %d ==================", i);
+		debugC(1, kDebugEngineTBC, "============= End Game Script %d ==================", i);
 	}
 
 while(1);*/
 
 	assert(tmpVal < _gameScriptIndexSize);
-	debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index);
+	debugC(1, kDebugEngineTBC, "================= Game Script %d for character %d ==================", tmpVal, index);
 	_scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
-	debugC(1, kDebugEngine, "============= End Game Script %d for character %d ==================", tmpVal, index);
+	debugC(1, kDebugEngineTBC, "============= End Game Script %d for character %d ==================", tmpVal, index);
 
 
 	//warning("dump char stat");
 	i = index;
-	debugC(3, kDebugEngine, "char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), _scriptHandler->_characterScriptEnabled[i]);
+	debugC(3, kDebugEngineTBC, "char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), _scriptHandler->_characterScriptEnabled[i]);
 }
 
 Common::Error LilliputEngine::run() {
@@ -2684,6 +2678,7 @@ Common::Error LilliputEngine::run() {
 
 	// Setup mixer
 	syncSoundSettings();
+	//TODO: Init sound/music player
 
 	initPalette();
 
@@ -2695,14 +2690,15 @@ Common::Error LilliputEngine::run() {
 	_bufferIsoMap = loadRaw("ISOMAP.DTA");
 
 	loadRules();
+	// Hack: int8 should be installed at this point, but it's crashing during the
+	// rendering when the title screens are displayed
+	//_int8installed = true;
 
 	_lastTime = _system->getMillis();
 
-	
-
-	//TODO: Init sound/music player
 	_scriptHandler->runScript(ScriptStream(_initScript, _initScript_size));
 
+	// Hack, see above 
 	_int8installed = true;
 
 	while(!_shouldQuit) {
@@ -2732,7 +2728,7 @@ void LilliputEngine::initialize() {
 }
 
 byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
-	debugC(1, kDebugEngine, "getCharacterVariablesPtr(%d)", index);
+	debugC(1, kDebugEngineTBC, "getCharacterVariablesPtr(%d)", index);
 
 	assert((index > -3120) && (index < 1400));
 	if (index >= 0)
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 316a245..3892ff8 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -61,7 +61,9 @@ enum GameType {
 enum LilliputDebugChannels {
 	kDebugEngine    = 1 << 0,
 	kDebugScript    = 1 << 1,
-	kDebugSound     = 1 << 2
+	kDebugSound     = 1 << 2,
+	kDebugEngineTBC = 1 << 3,
+	kDebugScriptTBC = 1 << 4
 };
 
 struct LilliputGameDescription;
@@ -90,8 +92,7 @@ public:
 	struct18560 _arr18560[4];
 	byte _byte1714E;
 	byte _byte184F4;
-	byte _nextDisplayCharacterX;
-	byte _nextDisplayCharacterY;
+	Common::Point _nextDisplayCharacterPos;
 	byte _sound_byte16F06;
 	byte _byte16F09;
 	byte _keyboard_nextIndex;
@@ -239,7 +240,7 @@ public:
 	void displayFunction17();
 	void displayFunction18(int var1, int var2, int var3, int var4);
 
-	void displayCharacter(int index, int x, int y, int flags);
+	void displayCharacter(int index, Common::Point pos, int flags);
 	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
 	void sub130B6();
@@ -263,7 +264,7 @@ public:
 	byte sub166EA(int index);
 	void sub167EF(int index);
 
-	void renderCharacters(byte *buf, byte x, byte y);
+	void renderCharacters(byte *buf, Common::Point pos);
 
 	byte sub16799(int param1, int index);
 	int getDirection(Common::Point param1, Common::Point param2);
@@ -285,8 +286,8 @@ public:
 	void sub1305C(byte index, byte var2);
 	void checkInterfaceHotspots(bool &forceReturnFl);
 	int sub13240(Common::Point mousePos, int var3, int var4);
-	void sub131B2(int var2, int var4, bool &forceReturnFl);
-	void sub131FC(int var2, int var4);
+	void sub131B2(Common::Point pos, bool &forceReturnFl);
+	void sub131FC(Common::Point pos);
 	void sub1546F(byte displayX, byte displayY);
 	void sub15498(byte x, byte y, int var2);
 	void sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index bd3791c..8d1c750 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -42,13 +42,17 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte1881D = 0;
 	_word1855E = 0;
 	_word16F00 = -1;
+	_word129A3 = 0;
 	_viewportCharacterTarget = -1;
 	_heroismBarX = 0;
 	_heroismBarBottomY = 0;
 	_viewportPos.x = 0;
 	_viewportPos.y = 0;
 	_word18776 = 0;
-
+	_array129A5[0] = 0;
+	_array129A5[1] = 1;
+	_array129A5[2] = 2;
+	_array129A5[3] = 3;
 	_savedBuffer215Ptr = NULL;
 
 	for (int i = 0; i < 20; i++) {
@@ -79,7 +83,7 @@ LilliputScript::~LilliputScript() {
 }
 
 byte LilliputScript::handleOpcodeType1(int curWord) {
-	debugC(2, kDebugScript, "handleOpcodeType1(0x%x)", curWord);
+	debugC(2, kDebugScriptTBC, "handleOpcodeType1(0x%x)", curWord);
 	switch (curWord) {
 	case 0x0:
 		return OC_checkCharacterGoalPos();
@@ -238,7 +242,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 }
 
 void LilliputScript::handleOpcodeType2(int curWord) {
-	debugC(2, kDebugScript, "handleOpcodeType2(0x%x)", curWord);
+	debugC(2, kDebugScriptTBC, "handleOpcodeType2(0x%x)", curWord);
 	switch (curWord) {
 	case 0x0:
 		OC_setWord18821();
@@ -856,13 +860,10 @@ void LilliputScript::disasmScript( ScriptStream script) {
 				str += ")";
 			}
 
-
-			debugC(2, kDebugScript, str.c_str());
-
-			
+			debugC(2, kDebugScriptTBC, "%s", str.c_str());
 		}
 
-		debugC(2, kDebugScript,"{ ");
+		debugC(2, kDebugScriptTBC, "{ ");
 
 		val = script.readUint16LE();
 
@@ -890,19 +891,18 @@ void LilliputScript::disasmScript( ScriptStream script) {
 			}
 			str += ");";
 
-			debugC(2, kDebugScript, str.c_str());
-
+			debugC(2, kDebugScriptTBC, "%s", str.c_str());
 
 			val = script.readUint16LE();
 		}
 
-		debugC(2, kDebugScript,"} ");
-		debugC(2, kDebugScript," ");
+		debugC(2, kDebugScriptTBC, "} ");
+		debugC(2, kDebugScriptTBC, " ");
 	}
 }
 
 int LilliputScript::handleOpcode(ScriptStream *script) {
-	debugC(2, kDebugScript, "handleOpcode");
+	debugC(2, kDebugScriptTBC, "handleOpcode");
 
 	_currScript = script;
 	uint16 curWord = _currScript->readUint16LE();
@@ -936,7 +936,7 @@ int LilliputScript::handleOpcode(ScriptStream *script) {
 }
 
 void LilliputScript::runScript(ScriptStream script) {
-	debugC(1, kDebugScript, "runScript");
+	debugC(1, kDebugScriptTBC, "runScript");
 
 	_byte16F05_ScriptHandler = 1;
 	
@@ -945,7 +945,7 @@ void LilliputScript::runScript(ScriptStream script) {
 }
 
 void LilliputScript::runMenuScript(ScriptStream script) {
-	debugC(1, kDebugScript, "runMenuScript");
+	debugC(1, kDebugScriptTBC, "runMenuScript");
 
 	_byte16F05_ScriptHandler = 0;
 	
@@ -954,7 +954,7 @@ void LilliputScript::runMenuScript(ScriptStream script) {
 }
 
 void LilliputScript::sub185ED(byte index, byte subIndex) {
-	debugC(2, kDebugScript, "sub185ED");
+	debugC(2, kDebugScriptTBC, "sub185ED");
 
 	if (_vm->_arr18560[index]._field0 != 1)
 		return;
@@ -963,7 +963,7 @@ void LilliputScript::sub185ED(byte index, byte subIndex) {
 }
 
 byte LilliputScript::compareValues(byte var1, int oper, int var2) {
-	debugC(2, kDebugScript, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
+	debugC(2, kDebugScriptTBC, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
 
 	switch (oper & 0xFF) {
 	case '<':
@@ -977,7 +977,7 @@ byte LilliputScript::compareValues(byte var1, int oper, int var2) {
 }
 
 void LilliputScript::computeOperation(byte *bufPtr, int oper, int var3) {
-	debugC(1, kDebugScript, "computeOperation(bufPtr, %c, %d)", oper & 0xFF, var3 & 0xFF);
+	debugC(1, kDebugScriptTBC, "computeOperation(bufPtr, %c, %d)", oper & 0xFF, var3 & 0xFF);
 
 	switch (oper & 0xFF) {
 	case '=':
@@ -1045,7 +1045,7 @@ void LilliputScript::sub185B4_display() {
 }
 
 void LilliputScript::sub1823E(byte index, byte var1, byte *curBufPtr) {
-	debugC(1, kDebugScript, "sub1823E(%d, %d, curBufPtr)", index, var1);
+	debugC(1, kDebugScriptTBC, "sub1823E(%d, %d, curBufPtr)", index, var1);
 
 	assert (index < 40);
 	_characterScriptEnabled[index] = 1;
@@ -1056,7 +1056,7 @@ void LilliputScript::sub1823E(byte index, byte var1, byte *curBufPtr) {
 }
 
 void LilliputScript::sub17B6C(int var1) {
-	debugC(1, kDebugScript, "sub17B6C(%d)", var1);
+	debugC(1, kDebugScriptTBC, "sub17B6C(%d)", var1);
 
 	if (var1 == 0) {
 		int curWord = 0;
@@ -1080,7 +1080,7 @@ void LilliputScript::sub17B6C(int var1) {
 }
 
 void LilliputScript::sub16C86(int index, byte *buf) {
-	debugC(1, kDebugScript, "sub16C86()");
+	debugC(1, kDebugScriptTBC, "sub16C86()");
 
 	_array12811[index] = 0;
 
@@ -1090,7 +1090,7 @@ void LilliputScript::sub16C86(int index, byte *buf) {
 }
 
 void LilliputScript::sub16C5C(int index, byte var3) {
-	debugC(1, kDebugScript, "sub16C5C(%d, %d)", index, var3);
+	debugC(1, kDebugScriptTBC, "sub16C5C(%d, %d)", index, var3);
 
 	assert(index < 40);
 	_array12839[index] = var3;
@@ -1109,7 +1109,7 @@ void LilliputScript::sub16C5C(int index, byte var3) {
 }
 
 void LilliputScript::sub17D40(bool &forceReturnFl) {
-	debugC(1, kDebugScript, "sub17D40()");
+	debugC(1, kDebugScriptTBC, "sub17D40()");
 
 	forceReturnFl = false;
 	if ((_vm->_displayMap != 1) && (_vm->_characterRelativePositionX[_vm->_currentScriptCharacter] != 0xFF))
@@ -1120,7 +1120,7 @@ void LilliputScript::sub17D40(bool &forceReturnFl) {
 }
 
 void LilliputScript::sub189F5() {
-	debugC(2, kDebugScript, "sub189F5()");
+	debugC(2, kDebugScriptTBC, "sub189F5()");
 
 	int index = 0;
 	int var2 = 0x100;
@@ -1158,7 +1158,7 @@ void LilliputScript::sub189F5() {
 }
 
 void LilliputScript::sub189B8() {
-	debugC(2, kDebugScript, "sub189B8()");
+	debugC(2, kDebugScriptTBC, "sub189B8()");
 
 	sub189F5();
 	int index = 0;
@@ -1177,7 +1177,7 @@ void LilliputScript::sub189B8() {
 }
 
 void LilliputScript::sub18A56(byte *buf) {
-	debugC(2, kDebugScript, "sub18A56(buf)");
+	debugC(2, kDebugScriptTBC, "sub18A56(buf)");
 
 	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I''ve |can''t |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|''s |''t |re|gg|tt|pp|nn|ay|ar|wh|";
 
@@ -1232,7 +1232,7 @@ void LilliputScript::sub18A56(byte *buf) {
 }
 
 int LilliputScript::sub18BB7(int index) {
-	debugC(2, kDebugScript, "sub18BB7(%d)", index);
+	debugC(2, kDebugScriptTBC, "sub18BB7(%d)", index);
 	
 	int chunk4Index = _vm->_rulesChunk3[index];
 	int result = 0;
@@ -1243,7 +1243,7 @@ int LilliputScript::sub18BB7(int index) {
 }
 
 void LilliputScript::sub18B3C(int var) {
-	debugC(2, kDebugScript, "sub18B3C(%d)", var);
+	debugC(2, kDebugScriptTBC, "sub18B3C(%d)", var);
 
 	if (var == 0xFFFF)
 		return;
@@ -1259,7 +1259,6 @@ void LilliputScript::sub18B3C(int var) {
 	if (count != 0) {
 		int tmpVal = _vm->_rnd->getRandomNumber(count + 1);
 		if (tmpVal != 0) {
-			int i = 0;
 			for (int j = 0; j < tmpVal; j++) {
 				do
 					++i;
@@ -1272,7 +1271,7 @@ void LilliputScript::sub18B3C(int var) {
 }
 
 int16 LilliputScript::getValue1() {
-	debugC(2, kDebugScript, "getValue1()");
+	debugC(2, kDebugScriptTBC, "getValue1()");
 
 	int16 curWord = _currScript->readUint16LE();
 	if (curWord < 1000)
@@ -1296,7 +1295,7 @@ int16 LilliputScript::getValue1() {
 }
 
 Common::Point LilliputScript::getPosFromScript() {
-	debugC(2, kDebugScript, "getPosFromScript()");
+	debugC(2, kDebugScriptTBC, "getPosFromScript()");
 
 	int curWord = _currScript->readUint16LE();
 	int tmpVal = curWord >> 8;
@@ -1347,14 +1346,14 @@ Common::Point LilliputScript::getPosFromScript() {
 	case 0xF6:
 		return _vm->_savedMousePosDivided;
 	default:
-		Common::Point tmpVal = Common::Point(curWord >> 8, curWord & 0xFF);
-		warning("getPosFromScript - High value %d -> %d %d", curWord, tmpVal.x, tmpVal.y);
-		return tmpVal;
+		Common::Point pos = Common::Point(curWord >> 8, curWord & 0xFF);
+		warning("getPosFromScript - High value %d -> %d %d", curWord, pos.x, pos.y);
+		return pos;
 	}
 }
 
 void LilliputScript::sub130B6() {
-	debugC(1, kDebugScript, "sub130B6()");
+	debugC(1, kDebugScriptTBC, "sub130B6()");
 
 	assert(_vm->_word12F68_ERULES <= 20);
 	for (int i = 0; i < _vm->_word12F68_ERULES; i++) {
@@ -1364,7 +1363,7 @@ void LilliputScript::sub130B6() {
 }
 
 byte *LilliputScript::getCharacterVariablePtr() {
-	debugC(2, kDebugScript, "getCharacterVariablePtr()");
+	debugC(2, kDebugScriptTBC, "getCharacterVariablePtr()");
 
 	int8 tmpVal = (int8) (getValue1() & 0xFF);
 	int index = tmpVal * 32;
@@ -1374,7 +1373,7 @@ byte *LilliputScript::getCharacterVariablePtr() {
 }
 
 byte LilliputScript::OC_checkCharacterGoalPos() {
-	debugC(2, kDebugScript, "OC_checkCharacterGoalPos()");
+	debugC(2, kDebugScriptTBC, "OC_checkCharacterGoalPos()");
 
 	if (_vm->_currentScriptCharacterPos == getPosFromScript()) {
 		return 1;
@@ -1383,7 +1382,7 @@ byte LilliputScript::OC_checkCharacterGoalPos() {
 }
 
 byte LilliputScript::OC_comparePos() {
-	debugC(2, kDebugScript, "OC_comparePos()");
+	debugC(2, kDebugScriptTBC, "OC_comparePos()");
 
 	int index = getValue1();
 	byte d1 = _array16123PosX[index];
@@ -1397,7 +1396,7 @@ byte LilliputScript::OC_comparePos() {
 }
 
 byte LilliputScript::OC_sub1740A() {
-	debugC(1, kDebugScript, "OC_sub1740A()");
+	debugC(1, kDebugScriptTBC, "OC_sub1740A()");
 
 	Common::Point var = _vm->_currentScriptCharacterPos;
 	if (var == Common::Point(-1, -1)) {
@@ -1420,7 +1419,7 @@ byte LilliputScript::OC_sub1740A() {
 
 // Compare field0 with value -> character id?
 byte LilliputScript::OC_sub17434() {
-	debugC(1, kDebugScript, "OC_sub17434()");
+	debugC(1, kDebugScriptTBC, "OC_sub17434()");
 
 	byte *tmpArr = getCharacterVariablePtr();
 	byte var1 = tmpArr[0];
@@ -1431,7 +1430,7 @@ byte LilliputScript::OC_sub17434() {
 }
 
 byte LilliputScript::OC_sub17468() {
-	debugC(1, kDebugScript, "OC_sub17468()");
+	debugC(1, kDebugScriptTBC, "OC_sub17468()");
 
 	int operation = _currScript->readUint16LE();
 	int val2 = _currScript->readUint16LE();
@@ -1439,7 +1438,7 @@ byte LilliputScript::OC_sub17468() {
 }
 
 byte LilliputScript::OC_getRandom() {
-	debugC(1, kDebugScript, "OC_getRandom()");
+	debugC(1, kDebugScriptTBC, "OC_getRandom()");
 
 	int maxVal = _currScript->readUint16LE();
 	int rand = _vm->_rnd->getRandomNumber(maxVal);
@@ -1452,7 +1451,7 @@ byte LilliputScript::OC_getRandom() {
 }
 
 byte LilliputScript::OC_for() {
-	debugC(1, kDebugScript, "OC_for()");
+	debugC(1, kDebugScriptTBC, "OC_for()");
 
 	int var1 = _currScript->readUint16LE();
 	int tmpVal = _currScript->readUint16LE() + 1;
@@ -1467,7 +1466,7 @@ byte LilliputScript::OC_for() {
 }
 
 byte LilliputScript::OC_compWord18776() {
-	debugC(1, kDebugScript, "OC_compWord18776()");
+	debugC(1, kDebugScriptTBC, "OC_compWord18776()");
 
 	int var1 = _currScript->readUint16LE();
 
@@ -1478,7 +1477,7 @@ byte LilliputScript::OC_compWord18776() {
 }
 
 byte LilliputScript::OC_checkSaveFlag() {
-	debugC(1, kDebugScript, "OC_checkSaveFlag()");
+	debugC(1, kDebugScriptTBC, "OC_checkSaveFlag()");
 
 	if (_vm->_saveFlag)
 		return 1;
@@ -1497,7 +1496,7 @@ byte LilliputScript::OC_compByte16F04() {
 }
 
 byte LilliputScript::OC_sub174D8() {
-	debugC(1, kDebugScript, "OC_sub174D8()");
+	debugC(1, kDebugScriptTBC, "OC_sub174D8()");
 
 	byte tmpVal = getValue1() & 0xFF;
 	int curWord = _currScript->readUint16LE();
@@ -1524,7 +1523,7 @@ byte LilliputScript::OC_sub174D8() {
 }
 
 byte LilliputScript::OC_sub1750E() {
-	debugC(1, kDebugScript, "OC_sub1750E()");
+	debugC(1, kDebugScriptTBC, "OC_sub1750E()");
 
 	byte* buf1 = getCharacterVariablePtr();
 	int var1 = *buf1;
@@ -1539,7 +1538,7 @@ byte LilliputScript::OC_sub1750E() {
 
 // TODO Rename function to "Check if character pos in rectangle"
 byte LilliputScript::OC_compareCoords_1() {
-	debugC(1, kDebugScript, "OC_compareCoords_1()");
+	debugC(1, kDebugScriptTBC, "OC_compareCoords_1()");
 
 	int index = _currScript->readUint16LE();
 	assert(index < 40);
@@ -1556,7 +1555,7 @@ byte LilliputScript::OC_compareCoords_1() {
 
 // TODO Rename function to "Check if character pos in rectangle"
 byte LilliputScript::OC_compareCoords_2() {
-	debugC(1, kDebugScript, "OC_compareCoords_2()");
+	debugC(1, kDebugScriptTBC, "OC_compareCoords_2()");
 
 	int index = getValue1();
 	Common::Point var1 = Common::Point(_array16123PosX[index], _array1614BPosY[index]);
@@ -1579,7 +1578,7 @@ byte LilliputScript::OC_sub1759E() {
 }
 
 byte LilliputScript::OC_compWord16EF8() {
-	debugC(1, kDebugScript, "OC_compWord16EF8()");
+	debugC(1, kDebugScriptTBC, "OC_compWord16EF8()");
 	
 	int tmpVal = getValue1();
 	if (tmpVal == _vm->_currentScriptCharacter)
@@ -1588,7 +1587,7 @@ byte LilliputScript::OC_compWord16EF8() {
 }
 
 byte LilliputScript::OC_sub175C8() {
-	debugC(1, kDebugScript, "OC_sub175C8()");
+	debugC(1, kDebugScriptTBC, "OC_sub175C8()");
 	
 	byte var4 = _currScript->readUint16LE() & 0xFF;
 
@@ -1632,7 +1631,7 @@ byte LilliputScript::OC_sub175C8() {
 }
 
 byte LilliputScript::OC_sub17640() {
-	debugC(1, kDebugScript, "OC_sub176C4()");
+	debugC(1, kDebugScriptTBC, "OC_sub176C4()");
 
 	int var4 = _currScript->readUint16LE();
 	int index = _vm->_currentScriptCharacter * 40;
@@ -1683,7 +1682,7 @@ byte LilliputScript::OC_sub17640() {
 }
 
 byte LilliputScript::OC_sub176C4() {
-	debugC(1, kDebugScript, "OC_sub176C4()");
+	debugC(1, kDebugScriptTBC, "OC_sub176C4()");
 	
 	byte var4 = _currScript->readUint16LE() & 0xFF;
 
@@ -1727,7 +1726,7 @@ byte LilliputScript::OC_sub176C4() {
 }
 
 byte LilliputScript::OC_compWord10804() {
-	debugC(1, kDebugScript, "OC_compWord10804()");
+	debugC(1, kDebugScriptTBC, "OC_compWord10804()");
 	
 	byte tmpVal = getValue1();
 	if (tmpVal == _vm->_word10804)
@@ -1737,7 +1736,7 @@ byte LilliputScript::OC_compWord10804() {
 }
 
 byte LilliputScript::OC_sub17766() {
-	debugC(1, kDebugScript, "OC_sub17766()");
+	debugC(1, kDebugScriptTBC, "OC_sub17766()");
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
 	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] != 16))
@@ -1747,7 +1746,7 @@ byte LilliputScript::OC_sub17766() {
 }
 
 byte LilliputScript::OC_sub17782() {
-	debugC(1, kDebugScript, "OC_sub17782()");
+	debugC(1, kDebugScriptTBC, "OC_sub17782()");
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
 	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] == 16))
@@ -1757,13 +1756,13 @@ byte LilliputScript::OC_sub17782() {
 }
 
 byte *LilliputScript::getMapPtr(Common::Point val) {
-	debugC(1, kDebugScript, "getMapPtr(%d %d)", val.x, val.y);
+	debugC(1, kDebugScriptTBC, "getMapPtr(%d %d)", val.x, val.y);
 
 	return &_vm->_bufferIsoMap[(val.y * 64 + val.x) << 2];
 }
 
 byte LilliputScript::OC_sub1779E() {
-	debugC(1, kDebugScript, "OC_sub1779E()");
+	debugC(1, kDebugScriptTBC, "OC_sub1779E()");
 
 	Common::Point tmpVal = getPosFromScript();
 
@@ -1781,17 +1780,17 @@ byte LilliputScript::OC_sub1779E() {
 }
 
 byte LilliputScript::OC_sub177C6() {
-	debugC(1, kDebugScript, "OC_sub177C6()");
+	debugC(1, kDebugScriptTBC, "OC_sub177C6()");
 
 	int index = getValue1();
-	if (_vm->_characterPositionX[index] == 0xFFFF)
+	if (_vm->_characterPositionX[index] == -1)
 		return 0;
 
 	return 1;
 }
 
 byte LilliputScript::OC_compWord16EFE() {
-	debugC(1, kDebugScript, "OC_compWord16EFE()");
+	debugC(1, kDebugScriptTBC, "OC_compWord16EFE()");
 
 	byte curByte = _currScript->readUint16LE() & 0xFF;
 	byte tmpVal = _vm->_word16EFE >> 8;
@@ -1804,7 +1803,7 @@ byte LilliputScript::OC_compWord16EFE() {
 }
 
 byte LilliputScript::OC_sub177F5() {
-	debugC(1, kDebugScript, "OC_sub177F5()");
+	debugC(1, kDebugScriptTBC, "OC_sub177F5()");
 
 	byte var1 = _currScript->readUint16LE() & 0xFF;
 	byte var2 = _currScript->readUint16LE() & 0xFF;
@@ -1818,7 +1817,7 @@ byte LilliputScript::OC_sub177F5() {
 }
 
 byte LilliputScript::OC_sub17812() {
-	debugC(1, kDebugScript, "OC_sub17812()");
+	debugC(1, kDebugScriptTBC, "OC_sub17812()");
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 	assert(_vm->_currentCharacterVariables != NULL);
@@ -1828,7 +1827,7 @@ byte LilliputScript::OC_sub17812() {
 }
 
 byte LilliputScript::OC_sub17825() {
-	debugC(1, kDebugScript, "OC_sub17825()");
+	debugC(1, kDebugScriptTBC, "OC_sub17825()");
 
 	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
 	
@@ -1842,7 +1841,7 @@ byte LilliputScript::OC_sub17825() {
 }
 
 byte LilliputScript::OC_sub17844() {
-	debugC(1, kDebugScript, "OC_sub17844()");
+	debugC(1, kDebugScriptTBC, "OC_sub17844()");
 
 	int tmpVal = _currScript->readUint16LE();
 
@@ -1853,7 +1852,7 @@ byte LilliputScript::OC_sub17844() {
 }
 
 byte LilliputScript::OC_sub1785C() {
-	debugC(1, kDebugScript, "OC_sub1785C()");
+	debugC(1, kDebugScriptTBC, "OC_sub1785C()");
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 	int count = 0;
@@ -1870,7 +1869,7 @@ byte LilliputScript::OC_sub1785C() {
 }
 
 byte LilliputScript::OC_sub17886() {
-	debugC(1, kDebugScript, "OC_sub17886()");
+	debugC(1, kDebugScriptTBC, "OC_sub17886()");
 
 	Common::Point var1 = getPosFromScript();
 
@@ -1883,7 +1882,7 @@ byte LilliputScript::OC_sub17886() {
 }
 
 byte LilliputScript::OC_CompareGameVariables() {
-	debugC(1, kDebugScript, "OC_CompareGameVariables()");
+	debugC(1, kDebugScriptTBC, "OC_CompareGameVariables()");
 
 	int var1 = getValue1();
 	int var2 = getValue1();
@@ -1893,14 +1892,14 @@ byte LilliputScript::OC_CompareGameVariables() {
 }
 
 byte LilliputScript::OC_skipNextOpcode() {
-	debugC(1, kDebugScript, "OC_skipNextOpcode()");
+	debugC(1, kDebugScriptTBC, "OC_skipNextOpcode()");
 
 	_currScript->readUint16LE();
 	return 1;
 }
 
 byte LilliputScript::OC_sub178C2() {
-	debugC(1, kDebugScript, "OC_sub178C2()");
+	debugC(1, kDebugScriptTBC, "OC_sub178C2()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	if (_vm->_currentCharacterVariables[2] == 1)
@@ -1909,7 +1908,7 @@ byte LilliputScript::OC_sub178C2() {
 }
 
 byte LilliputScript::OC_sub178D2() {
-	debugC(1, kDebugScript, "OC_sub178D2()");
+	debugC(1, kDebugScriptTBC, "OC_sub178D2()");
 
 	int index = getValue1();
 	assert (index < 40);
@@ -1923,7 +1922,7 @@ byte LilliputScript::OC_sub178D2() {
 }
 
 byte LilliputScript::OC_sub178E8() {
-	debugC(1, kDebugScript, "OC_sub178E8()");
+	debugC(1, kDebugScriptTBC, "OC_sub178E8()");
 
 	byte *bufPtr = getCharacterVariablePtr();
 	byte var1 = bufPtr[0];
@@ -1936,7 +1935,7 @@ byte LilliputScript::OC_sub178E8() {
 }
 
 byte LilliputScript::OC_sub178FC() {
-	debugC(1, kDebugScript, "OC_sub178FC()");
+	debugC(1, kDebugScriptTBC, "OC_sub178FC()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
@@ -1947,7 +1946,7 @@ byte LilliputScript::OC_sub178FC() {
 }
 
 byte LilliputScript::OC_sub1790F() {
-	debugC(1, kDebugScript, "OC_sub1790F()");
+	debugC(1, kDebugScriptTBC, "OC_sub1790F()");
 
 	int index = getValue1();
 	assert(index < 40);
@@ -1960,7 +1959,7 @@ byte LilliputScript::OC_sub1790F() {
 }
 
 byte LilliputScript::OC_sub1792A() {
-	debugC(1, kDebugScript, "OC_sub1792A()");
+	debugC(1, kDebugScriptTBC, "OC_sub1792A()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
@@ -1972,7 +1971,7 @@ byte LilliputScript::OC_sub1792A() {
 }
 
 byte LilliputScript::OC_sub1793E() {
-	debugC(1, kDebugScript, "OC_sub1793E()");
+	debugC(1, kDebugScriptTBC, "OC_sub1793E()");
 
 	if (_vm->_currentScriptCharacterPos == Common::Point(-1, -1))
 		return 0;
@@ -1984,7 +1983,7 @@ byte LilliputScript::OC_sub1793E() {
 }
 
 byte LilliputScript::OC_sub1795E() {
-	debugC(1, kDebugScript, "OC_sub1795E()");
+	debugC(1, kDebugScriptTBC, "OC_sub1795E()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	if (_vm->_currentCharacterVariables[3] == 1)
@@ -1994,7 +1993,7 @@ byte LilliputScript::OC_sub1795E() {
 }
 
 byte LilliputScript::OC_checkCharacterDirection() {
-	debugC(1, kDebugScript, "OC_checkCharacterDirection()");
+	debugC(1, kDebugScriptTBC, "OC_checkCharacterDirection()");
 
 	int var1 = getValue1();
 	int var2 = _currScript->readUint16LE();
@@ -2005,7 +2004,7 @@ byte LilliputScript::OC_checkCharacterDirection() {
 }
 
 byte LilliputScript::OC_sub17984() {
-	debugC(1, kDebugScript, "OC_sub17984()");
+	debugC(1, kDebugScriptTBC, "OC_sub17984()");
 
 	int index = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
@@ -2019,7 +2018,7 @@ byte LilliputScript::OC_sub17984() {
 }
 
 byte LilliputScript::OC_checkSavedMousePos() {
-	debugC(1, kDebugScript, "OC_checkSavedMousePos()");
+	debugC(1, kDebugScriptTBC, "OC_checkSavedMousePos()");
 
 	if ((_byte129A0 != 0xFF) || (_vm->_savedMousePosDivided == Common::Point(-1, -1)))
 		return 0;
@@ -2028,7 +2027,7 @@ byte LilliputScript::OC_checkSavedMousePos() {
 }
 
 byte LilliputScript::OC_sub179AE() {
-	debugC(1, kDebugScript, "OC_sub179AE()");
+	debugC(1, kDebugScriptTBC, "OC_sub179AE()");
 
 	if ((_vm->_byte12FCE == 1) || (_byte129A0 == 0xFF))
 		return 0;
@@ -2037,7 +2036,7 @@ byte LilliputScript::OC_sub179AE() {
 }
 
 byte LilliputScript::OC_sub179C2() {
-	debugC(1, kDebugScript, "OC_sub179C2()");
+	debugC(1, kDebugScriptTBC, "OC_sub179C2()");
 	Common::Point var1 = getPosFromScript();
 
 	if ((_vm->_array10999PosX[_vm->_currentScriptCharacter] == var1.x)
@@ -2047,7 +2046,7 @@ byte LilliputScript::OC_sub179C2() {
 	return 0;
 }
 byte LilliputScript::OC_sub179E5() {
-	debugC(1, kDebugScript, "OC_sub17A07()");
+	debugC(1, kDebugScriptTBC, "OC_sub17A07()");
 
 	static const byte _byte179DB[10] = {0x44, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43};
 
@@ -2060,7 +2059,7 @@ byte LilliputScript::OC_sub179E5() {
 }
 
 byte LilliputScript::OC_sub17A07() {
-	debugC(1, kDebugScript, "OC_sub17A07()");
+	debugC(1, kDebugScriptTBC, "OC_sub17A07()");
 
 	static const byte _array179FD[10] = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 
@@ -2082,7 +2081,7 @@ byte LilliputScript::OC_sub17A07() {
 }
 
 byte LilliputScript::OC_sub17757() {
-	debugC(1, kDebugScript, "OC_sub17757()");
+	debugC(1, kDebugScriptTBC, "OC_sub17757()");
 
 	int var1 = getValue1();
 	if ( var1 == _viewportCharacterTarget )
@@ -2092,11 +2091,11 @@ byte LilliputScript::OC_sub17757() {
 }
 
 void LilliputScript::OC_setWord18821() {
-	debugC(1, kDebugScript, "OC_setWord18821()");
+	debugC(1, kDebugScriptTBC, "OC_setWord18821()");
 	_word18821 = getValue1();
 }
 void LilliputScript::OC_sub17A3E() {
-	debugC(1, kDebugScript, "OC_sub17A3E()");
+	debugC(1, kDebugScriptTBC, "OC_sub17A3E()");
 	Common::Point var1 = getPosFromScript();
 	int var2 = _currScript->readUint16LE();
 	int var3 = _currScript->readUint16LE();
@@ -2114,7 +2113,7 @@ void LilliputScript::OC_sub17A3E() {
 }
 
 void LilliputScript::OC_sub17D57() {
-	debugC(1, kDebugScript, "OC_sub17D57()");
+	debugC(1, kDebugScriptTBC, "OC_sub17D57()");
 
 	int curWord = _currScript->readUint16LE();
 
@@ -2129,7 +2128,7 @@ void LilliputScript::OC_sub17D57() {
 }
 
 void LilliputScript::sub18B7C(int var1, int var3) {
-	debugC(2, kDebugScript, "sub18B7C(%d, %d)", var1, var3);
+	debugC(2, kDebugScriptTBC, "sub18B7C(%d, %d)", var1, var3);
 
 	if (var1 == 0xFFFF) 
 		return;
@@ -2155,7 +2154,7 @@ void LilliputScript::sub18B7C(int var1, int var3) {
 }
 
 void LilliputScript::OC_sub17D7F() {
-	debugC(1, kDebugScript, "OC_sub17D7F()");
+	debugC(1, kDebugScriptTBC, "OC_sub17D7F()");
 
 	int var1 = getCharacterVariablePtr()[0];
 	int var2 = (_currScript->readUint16LE() & 0xFF);
@@ -2174,7 +2173,7 @@ void LilliputScript::OC_sub17D7F() {
 }
 
 void LilliputScript::OC_sub17DB9() {
-	debugC(1, kDebugScript, "OC_sub17DB9()");
+	debugC(1, kDebugScriptTBC, "OC_sub17DB9()");
 
 	int index = _currScript->readUint16LE();
 	int maxValue = sub18BB7(index);
@@ -2197,7 +2196,7 @@ void LilliputScript::OC_sub17DB9() {
 }
 
 void LilliputScript::OC_sub17DF9() {
-	debugC(1, kDebugScript, "OC_sub17DF9()");
+	debugC(1, kDebugScriptTBC, "OC_sub17DF9()");
 
 	if ((_word1881B & 0xFF) == 0xFF) {
 		OC_sub17D57();
@@ -2208,7 +2207,7 @@ void LilliputScript::OC_sub17DF9() {
 }
 
 void LilliputScript::OC_sub17E07() {
-	debugC(1, kDebugScript, "OC_sub17E07()");
+	debugC(1, kDebugScriptTBC, "OC_sub17E07()");
 
 	if ((_word1881B & 0xFF) == 0xFF) {
 		OC_sub17D7F();
@@ -2222,7 +2221,7 @@ void LilliputScript::OC_sub17E07() {
 }
 
 void LilliputScript::OC_sub17E15() {
-	debugC(1, kDebugScript, "OC_sub17E15()");
+	debugC(1, kDebugScriptTBC, "OC_sub17E15()");
 
 	if ((_word1881B & 0xFF) == 0xFF) {
 		OC_sub17DB9();
@@ -2233,7 +2232,7 @@ void LilliputScript::OC_sub17E15() {
 }
 
 void LilliputScript::OC_sub17B03() {
-	debugC(1, kDebugScript, "OC_sub17B03()");
+	debugC(1, kDebugScriptTBC, "OC_sub17B03()");
 
 	byte *bufPtr = getCharacterVariablePtr();
 	int oper = _currScript->readUint16LE();
@@ -2243,7 +2242,7 @@ void LilliputScript::OC_sub17B03() {
 }
 
 void LilliputScript::OC_getRandom_type2() {
-	debugC(1, kDebugScript, "OC_getRandom_type2()");
+	debugC(1, kDebugScriptTBC, "OC_getRandom_type2()");
 
 	byte* bufPtr = getCharacterVariablePtr();
 	int maxVal = _currScript->readUint16LE(); 
@@ -2252,7 +2251,7 @@ void LilliputScript::OC_getRandom_type2() {
 }
 
 void LilliputScript::OC_setCharacterPosition() {
-	debugC(1, kDebugScript, "OC_setCharacterPosition()");
+	debugC(1, kDebugScriptTBC, "OC_setCharacterPosition()");
 	
 	int index = getValue1();
 	Common::Point tmpVal = getPosFromScript();
@@ -2266,7 +2265,7 @@ void LilliputScript::OC_setCharacterPosition() {
 }
 
 void LilliputScript::OC_sub17A8D() {
-	debugC(1, kDebugScript, "OC_sub17A8D()");
+	debugC(1, kDebugScriptTBC, "OC_sub17A8D()");
 
 	int tmpVal = getValue1();
 	assert(tmpVal < 40);
@@ -2283,7 +2282,7 @@ void LilliputScript::OC_saveAndQuit() {
 }
 
 void LilliputScript::OC_sub17B93() {
-	debugC(1, kDebugScript, "OC_sub17B93()");
+	debugC(1, kDebugScriptTBC, "OC_sub17B93()");
 
 	int var1 = _currScript->readUint16LE();
 	sub17B6C(var1);
@@ -2294,7 +2293,7 @@ void LilliputScript::OC_sub17E37() {
 }
 
 void LilliputScript::OC_resetByte1714E() {
-	debugC(1, kDebugScript, "OC_resetByte1714E()");
+	debugC(1, kDebugScriptTBC, "OC_resetByte1714E()");
 
 	_vm->_byte1714E = 0;
 }
@@ -2304,13 +2303,13 @@ void LilliputScript::OC_deleteSavegameAndQuit() {
 }
 
 void LilliputScript::OC_incByte16F04() {
-	debugC(1, kDebugScript, "OC_incByte16F04()");
+	debugC(1, kDebugScriptTBC, "OC_incByte16F04()");
 
 	++_byte16F04;
 }
 
 void LilliputScript::OC_sub17BA5() {
-	debugC(1, kDebugScript, "OC_sub17BA5()");
+	debugC(1, kDebugScriptTBC, "OC_sub17BA5()");
 	
 	byte *tmpArr = getCharacterVariablePtr();
 	byte oper = (_currScript->readUint16LE() & 0xFF);
@@ -2319,14 +2318,14 @@ void LilliputScript::OC_sub17BA5() {
 }
 
 void LilliputScript::OC_setByte18823() {
-	debugC(1, kDebugScript, "OC_setByte18823()");
+	debugC(1, kDebugScriptTBC, "OC_setByte18823()");
 
 	byte *tmpArr = getCharacterVariablePtr();
 	_byte18823 = *tmpArr;
 }
 
 void LilliputScript::OC_callScript() {
-	debugC(1, kDebugScript, "OC_callScript()");
+	debugC(1, kDebugScriptTBC, "OC_callScript()");
 
 	int index = _currScript->readUint16LE();
 	int var1 = getValue1();
@@ -2341,9 +2340,9 @@ void LilliputScript::OC_callScript() {
 
 	if (_byte16F05_ScriptHandler == 0) {
 		_vm->_byte1714E = 0;
-		debugC(1, kDebugScript, "========================== Menu Script %d==============================", scriptIndex);
+		debugC(1, kDebugScriptTBC, "========================== Menu Script %d==============================", scriptIndex);
 		runMenuScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
-		debugC(1, kDebugScript, "========================== End of Menu Script==============================");
+		debugC(1, kDebugScriptTBC, "========================== End of Menu Script==============================");
 	} else {
 		runScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
 	}
@@ -2354,14 +2353,14 @@ void LilliputScript::OC_callScript() {
 }
 
 void LilliputScript::OC_sub17BF2() {
-	debugC(1, kDebugScript, "OC_sub17BF2()");
+	debugC(1, kDebugScriptTBC, "OC_sub17BF2()");
 
 	OC_callScript();
 	sub17B6C(0);
 }
 
 void LilliputScript::OC_setCurrentScriptCharacterPos() {
-	debugC(1, kDebugScript, "OC_setCurrentScriptCharacterPos()");
+	debugC(1, kDebugScriptTBC, "OC_setCurrentScriptCharacterPos()");
 
 	Common::Point pos = getPosFromScript();
 	_vm->_array10999PosX[_vm->_currentScriptCharacter] = pos.x;
@@ -2370,33 +2369,33 @@ void LilliputScript::OC_setCurrentScriptCharacterPos() {
 }
 
 void LilliputScript::OC_resetByte16F04() {
-	debugC(1, kDebugScript, "OC_resetByte16F04()");
+	debugC(1, kDebugScriptTBC, "OC_resetByte16F04()");
 
 	_byte16F04 = 0;
 }
 
 void LilliputScript::OC_sub17AE1() {
-	debugC(1, kDebugScript, "OC_sub17AE1()");
+	debugC(1, kDebugScriptTBC, "OC_sub17AE1()");
 
 	byte var3 = (_currScript->readUint16LE() & 0xFF);
 	sub16C5C(_vm->_currentScriptCharacter, var3);
 }
 
 void LilliputScript::OC_sub17AEE() {
-	debugC(1, kDebugScript, "OC_sub17AEE()");
+	debugC(1, kDebugScriptTBC, "OC_sub17AEE()");
 
 	byte var3 = (_currScript->readUint16LE() & 0xFF);
 	sub16C5C(_vm->_currentScriptCharacter + 1, var3);
 }
 
 void LilliputScript::OC_setWord10804() {
-	debugC(1, kDebugScript, "OC_setWord10804()");
+	debugC(1, kDebugScriptTBC, "OC_setWord10804()");
 
 	_vm->_word10804 = getValue1();
 }
 
 void LilliputScript::OC_sub17C0E() {
-	debugC(1, kDebugScript, "OC_sub17C0E()");
+	debugC(1, kDebugScriptTBC, "OC_sub17C0E()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	Common::Point var1 = Common::Point(_vm->_currentCharacterVariables[4], _vm->_currentCharacterVariables[5]);
@@ -2414,7 +2413,7 @@ void LilliputScript::OC_sub17C0E() {
 }
 
 void LilliputScript::OC_sub17C55() {
-	debugC(1, kDebugScript, "OC_sub17C55()");
+	debugC(1, kDebugScriptTBC, "OC_sub17C55()");
 
 	int var1 = getValue1();
 	int var2 = getValue1();
@@ -2427,7 +2426,7 @@ void LilliputScript::OC_sub17C55() {
 	_vm->_rulesBuffer2_7[var2] = var4 & 0xFF;
 }
 void LilliputScript::OC_sub17C76() {
-	debugC(1, kDebugScript, "OC_sub17C76()");
+	debugC(1, kDebugScriptTBC, "OC_sub17C76()");
 	
 	int var1 = getValue1();
 	_vm->_rulesBuffer2_5[var1] = 0xFF;
@@ -2436,13 +2435,13 @@ void LilliputScript::OC_sub17C76() {
 
 }
 void LilliputScript::OC_sub17AFC() {
-	debugC(1, kDebugScript, "OC_sub17AFC()");
+	debugC(1, kDebugScriptTBC, "OC_sub17AFC()");
 	int var1 = getValue1();
 	_vm->sub170EE(var1);
 }
 
 void LilliputScript::sub171AF(int var1, int var2, int var4) {
-	debugC(2, kDebugScript, "sub171AF()");
+	debugC(2, kDebugScriptTBC, "sub171AF()");
 
 	int index = 0;
 	for (int i = 0; i < 10; i++) {
@@ -2456,7 +2455,7 @@ void LilliputScript::sub171AF(int var1, int var2, int var4) {
 }
 
 void LilliputScript::OC_sub17C8B() {
-	debugC(1, kDebugScript, "OC_sub17C8B()");
+	debugC(1, kDebugScriptTBC, "OC_sub17C8B()");
 
 	int var1 = 2 << 8;
 	int var4 = _currScript->readUint16LE();
@@ -2467,7 +2466,7 @@ void LilliputScript::OC_sub17C8B() {
 }
 
 void LilliputScript::OC_sub17CA2() {
-	debugC(1, kDebugScript, "OC_sub17CA2()");
+	debugC(1, kDebugScriptTBC, "OC_sub17CA2()");
 
 	int var1 = 1 << 8;
 	int var4 = _currScript->readUint16LE();
@@ -2478,7 +2477,7 @@ void LilliputScript::OC_sub17CA2() {
 }
 
 void LilliputScript::OC_sub17CB9() {
-	debugC(1, kDebugScript, "OC_sub17CB9()");
+	debugC(1, kDebugScriptTBC, "OC_sub17CB9()");
 
 	int var4 = _currScript->readUint16LE();
 	int var1 = getValue1();
@@ -2489,7 +2488,7 @@ void LilliputScript::OC_sub17CB9() {
 }
 
 void LilliputScript::OC_sub17CD1() {
-	debugC(1, kDebugScript, "OC_sub17CD1()");
+	debugC(1, kDebugScriptTBC, "OC_sub17CD1()");
 
 	int var1 = 3 << 8;
 	int var4 = _currScript->readUint16LE();
@@ -2500,13 +2499,13 @@ void LilliputScript::OC_sub17CD1() {
 }
 
 void LilliputScript::OC_resetWord16EFE() {
-	debugC(1, kDebugScript, "OC_resetWord16EFE()");
+	debugC(1, kDebugScriptTBC, "OC_resetWord16EFE()");
 
 	_vm->_word16EFE = 0xFFFF;
 }
 
 void LilliputScript::OC_sub17CEF() {
-	debugC(1, kDebugScript, "OC_sub17CEF()");
+	debugC(1, kDebugScriptTBC, "OC_sub17CEF()");
 
 	int var1 = _currScript->readUint16LE();
 	sub1823E(_vm->_currentScriptCharacter , var1, _vm->_currentCharacterVariables);
@@ -2514,14 +2513,14 @@ void LilliputScript::OC_sub17CEF() {
 }
 
 void LilliputScript::OC_sub17D1B() {
-	debugC(1, kDebugScript, "OC_sub17D1B()");
+	debugC(1, kDebugScriptTBC, "OC_sub17D1B()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	++_vm->_currentCharacterVariables[1];
 }
 
 void LilliputScript::OC_sub17D23() {
-	debugC(1, kDebugScript, "OC_sub17D23()");
+	debugC(1, kDebugScriptTBC, "OC_sub17D23()");
 
 	int var1 = _currScript->readUint16LE();
 	Common::Point var2 = getPosFromScript();
@@ -2531,14 +2530,14 @@ void LilliputScript::OC_sub17D23() {
 }
 
 void LilliputScript::OC_sub17E6D() {
-	debugC(1, kDebugScript, "OC_sub17E6D()");
+	debugC(1, kDebugScriptTBC, "OC_sub17E6D()");
 	
 	int var1 = _currScript->readUint16LE();
 	_vm->_rulesBuffer2_12[_vm->_currentScriptCharacter] = (var1 - 2000) & 0xFF;
 }
 
 void LilliputScript::OC_changeCurrentCharacterSprite() {
-	debugC(2, kDebugScript, "OC_changeCurrentCharacterSprite()");
+	debugC(2, kDebugScriptTBC, "OC_changeCurrentCharacterSprite()");
 
 	int var1 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
@@ -2548,14 +2547,14 @@ void LilliputScript::OC_changeCurrentCharacterSprite() {
 }
 
 byte *LilliputScript::sub173D2() {
-	debugC(2, kDebugScript, "sub173D2()");
+	debugC(2, kDebugScriptTBC, "sub173D2()");
 
 	int index = _currScript->readUint16LE();	
 	return &_vm->_currentCharacterVariables[index];
 }
 
 void LilliputScript::OC_sub17E99() {
-	debugC(1, kDebugScript, "OC_sub17E99()");
+	debugC(1, kDebugScriptTBC, "OC_sub17E99()");
 
 	byte *compBuf = sub173D2();
 	int oper = _currScript->readUint16LE();
@@ -2569,7 +2568,7 @@ void LilliputScript::OC_sub17E99() {
 }
 
 void LilliputScript::OC_sub17EC5() {
-	//debugC(1, kDebugScript, "OC_sub17EC5()");
+	//debugC(1, kDebugScriptTBC, "OC_sub17EC5()");
 	warning("OC_sub17EC5");
 	/*byte *compBuf = sub173D2();
 	int oper = _currScript->readUint16LE();
@@ -2583,13 +2582,13 @@ void LilliputScript::OC_sub17EC5() {
 }
 
 Common::Point LilliputScript::getCharacterTilePos(int index) {
-	debugC(2, kDebugScript, "getCharacterTilePos(%d)", index);
+	debugC(2, kDebugScriptTBC, "getCharacterTilePos(%d)", index);
 
 	return Common::Point(_vm->_characterPositionX[index] >> 3, _vm->_characterPositionY[index] >> 3);
 }
 
 void LilliputScript::OC_setCharacterDirectionTowardsPos() {
-	debugC(1, kDebugScript, "OC_setCharacterDirectionTowardsPos()");
+	debugC(1, kDebugScriptTBC, "OC_setCharacterDirectionTowardsPos()");
 
 	Common::Point pos1 = getPosFromScript();
 	Common::Point tilePos = getCharacterTilePos(_vm->_currentScriptCharacter);
@@ -2598,7 +2597,7 @@ void LilliputScript::OC_setCharacterDirectionTowardsPos() {
 }
 
 void LilliputScript::OC_sub17F08() {
-	debugC(1, kDebugScript, "OC_sub17F08()");
+	debugC(1, kDebugScriptTBC, "OC_sub17F08()");
 	
 	int index = getValue1();
 
@@ -2624,7 +2623,7 @@ void LilliputScript::OC_sub17F08() {
 }
 
 void LilliputScript::OC_sub17F4F() {
-	debugC(1, kDebugScript, "OC_sub17F4F()");
+	debugC(1, kDebugScriptTBC, "OC_sub17F4F()");
 
 	int var = getValue1();
 	_array10A39[_vm->_currentScriptCharacter] = var & 0xFF;
@@ -2632,7 +2631,7 @@ void LilliputScript::OC_sub17F4F() {
 }
 
 void LilliputScript::OC_sub17F68() {
-	debugC(1, kDebugScript, "OC_sub17F68()");
+	debugC(1, kDebugScriptTBC, "OC_sub17F68()");
 
 	if (_vm->_currentScriptCharacter != _viewportCharacterTarget)
 		return;
@@ -2667,13 +2666,13 @@ void LilliputScript::OC_sub17F68() {
 }
 
 void LilliputScript::OC_skipNextVal() {
-	debugC(1, kDebugScript, "OC_skipNextVal()");
+	debugC(1, kDebugScriptTBC, "OC_skipNextVal()");
 
 	 _currScript->readUint16LE();
 }
 
 void LilliputScript::OC_sub17FD2() {
-	debugC(1, kDebugScript, "OC_sub17FD2()");
+	debugC(1, kDebugScriptTBC, "OC_sub17FD2()");
 	
 	int var1 = getValue1();
 	_vm->_currentCharacterVariables[6] = var1 & 0xFF;
@@ -2681,7 +2680,7 @@ void LilliputScript::OC_sub17FD2() {
 }
 
 void LilliputScript::OC_sub17FDD() {
-	debugC(1, kDebugScript, "OC_sub17FDD()");
+	debugC(1, kDebugScriptTBC, "OC_sub17FDD()");
 
 	int index = _currScript->readUint16LE();
 	
@@ -2692,13 +2691,13 @@ void LilliputScript::OC_sub17FDD() {
 }
 
 void LilliputScript::OC_setByte10B29() {
-	debugC(1, kDebugScript, "OC_setByte10B29()");
+	debugC(1, kDebugScriptTBC, "OC_setByte10B29()");
 	int var1 = getValue1();
 	_characterScriptEnabled[var1] = 1;
 }
 
 void LilliputScript::OC_sub18007() {
-	debugC(1, kDebugScript, "OC_sub18007()");
+	debugC(1, kDebugScriptTBC, "OC_sub18007()");
 
 	int curWord = _currScript->readUint16LE();
 	assert(_vm->_currentCharacterVariables != NULL);
@@ -2706,14 +2705,14 @@ void LilliputScript::OC_sub18007() {
 }
 
 void LilliputScript::OC_sub18014() {
-	debugC(1, kDebugScript, "OC_sub18014()");
+	debugC(1, kDebugScriptTBC, "OC_sub18014()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	_vm->_currentCharacterVariables[2] = 0;
 }
 
 void LilliputScript::OC_sub1801D() {
-	debugC(1, kDebugScript, "OC_sub18014()");
+	debugC(1, kDebugScriptTBC, "OC_sub18014()");
 
 	int var1 = getValue1();
 
@@ -2730,14 +2729,15 @@ void LilliputScript::OC_sub1801D() {
 
 }
 void LilliputScript::OC_sub1805D() {
-	debugC(1, kDebugScript, "OC_sub1805D()");
-	
-	int var1 = getValue1();
-	
+	debugC(1, kDebugScriptTBC, "OC_sub1805D()");
+
+	_word129A3 = getValue1();
+	for (int i = 0; i < 4; i++)
+		_array129A5[i] = _currScript->readUint16LE() & 0xFF;
 }
 
 void LilliputScript::OC_sub18074() {
-	debugC(1, kDebugScript, "OC_sub18074()");
+	debugC(1, kDebugScriptTBC, "OC_sub18074()");
 
 	int var2 = _currScript->readUint16LE();
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
@@ -2746,13 +2746,13 @@ void LilliputScript::OC_sub18074() {
 }
 
 void LilliputScript::OC_setCurrentCharacterDirection() {
-	debugC(1, kDebugScript, "OC_setCurrentCharacterDirection()");
+	debugC(1, kDebugScriptTBC, "OC_setCurrentCharacterDirection()");
 
 	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub18099() {
-	debugC(1, kDebugScript, "OC_sub18099()");
+	debugC(1, kDebugScriptTBC, "OC_sub18099()");
 
 	int index = _currScript->readUint16LE();
 	assert((index >= 0) && (index < 20));
@@ -2765,7 +2765,7 @@ void LilliputScript::OC_sub18099() {
 }
 
 void LilliputScript::OC_sub180C3() {
-	debugC(1, kDebugScript, "OC_sub180C3()");
+	debugC(1, kDebugScriptTBC, "OC_sub180C3()");
 	_viewportCharacterTarget = 0xFFFF;
 
 	int var1 = _currScript->readUint16LE();
@@ -2794,7 +2794,7 @@ void LilliputScript::OC_sub180C3() {
 }
 
 void LilliputScript::OC_sub1810A() {
-	debugC(1, kDebugScript, "OC_sub1810A()");
+	debugC(1, kDebugScriptTBC, "OC_sub1810A()");
 
 	_viewportCharacterTarget = 0xFFFF;
 	_viewportPos = getPosFromScript();
@@ -2804,13 +2804,13 @@ void LilliputScript::OC_sub1810A() {
 }
 
 void LilliputScript::OC_sub1812D() {
-	debugC(1, kDebugScript, "OC_sub1812D()");
+	debugC(1, kDebugScriptTBC, "OC_sub1812D()");
 
 	_vm->_characterPositionAltitude[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub1817F() {
-	debugC(1, kDebugScript, "OC_sub1817F()");
+	debugC(1, kDebugScriptTBC, "OC_sub1817F()");
 
 	int var1 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
@@ -2820,8 +2820,9 @@ void LilliputScript::OC_sub1817F() {
 	sub1818B(b1,b2);
 }
 
+//TODO checkme: parameter order is maybe wrong
 void LilliputScript::sub1818B(int b1, int b2) {
-	debugC(2, kDebugScript, "sub1818B(%d, %d)", b1, b2);
+	debugC(2, kDebugScriptTBC, "sub1818B(%d, %d)", b1, b2);
 	for (int i = 0; i <  _vm->_word1817B; i++) {
 		if ((_array1813B[i] >> 8) == b2 ) {
 			b2 += _array1813B[i] & 0xFF;
@@ -2837,8 +2838,9 @@ void LilliputScript::sub1818B(int b1, int b2) {
 	_array1813B[_vm->_word1817B++] = (b1 << 8) + b2;
 }
 
+//TODO checkme: case 0x2D is dubious
 void LilliputScript::OC_sub181BB() {
-	debugC(1, kDebugScript, "OC_sub181BB()");
+	debugC(1, kDebugScriptTBC, "OC_sub181BB()");
 	
 	int b = _currScript->readUint16LE();
 	int d = _currScript->readUint16LE() & 0xFF;
@@ -2861,14 +2863,14 @@ void LilliputScript::OC_sub181BB() {
 		c = c * 2;
 	}
 
-	int a = _currScript->readUint16LE() * c + (c & 0xFF);
-	b = b & 0xFF00 + a;
+	int a = (_currScript->readUint16LE() * c) + (c & 0xFF);
+	b = (b & 0xFF00) + a;
 	sub1818B(b & 0xFF, b >> 8);
 
 }
 
 void LilliputScript::OC_sub18213() {
-	debugC(1, kDebugScript, "OC_sub18213()");
+	debugC(1, kDebugScriptTBC, "OC_sub18213()");
 
 	int var1 = _currScript->readUint16LE();
 
@@ -2885,7 +2887,7 @@ void LilliputScript::OC_sub18213() {
 }
 
 void LilliputScript::OC_sub18252() {
-	debugC(1, kDebugScript, "OC_sub18252()");
+	debugC(1, kDebugScriptTBC, "OC_sub18252()");
 
 	int index = getValue1();
 	assert(index < 40);
@@ -2898,7 +2900,7 @@ void LilliputScript::OC_sub18260() {
 }
 
 void LilliputScript::OC_sub182EC() {
-	debugC(1, kDebugScript, "OC_sub182EC()");
+	debugC(1, kDebugScriptTBC, "OC_sub182EC()");
 
 	byte *tmpArr = getCharacterVariablePtr();
 
@@ -2912,7 +2914,7 @@ void LilliputScript::OC_sub182EC() {
 }
 
 void LilliputScript::OC_PaletteFadeOut() {
-	debugC(1, kDebugScript, "OC_PaletteFadeOut()");
+	debugC(1, kDebugScriptTBC, "OC_PaletteFadeOut()");
 
 	_byte12A09 = 1;
 	_vm->paletteFadeOut();
@@ -2920,7 +2922,7 @@ void LilliputScript::OC_PaletteFadeOut() {
 }
 
 void LilliputScript::OC_PaletteFadeIn() {
-	debugC(1, kDebugScript, "OC_PaletteFadeIn()");
+	debugC(1, kDebugScriptTBC, "OC_PaletteFadeIn()");
 
 	_byte12A09 = 1;
 	_vm->paletteFadeIn();
@@ -2928,7 +2930,7 @@ void LilliputScript::OC_PaletteFadeIn() {
 }
 
 void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
-	debugC(1, kDebugScript, "OC_loadAndDisplayCUBESx_GFX()");
+	debugC(1, kDebugScriptTBC, "OC_loadAndDisplayCUBESx_GFX()");
 
 	int curWord = _currScript->readUint16LE();
 	assert((curWord >= 0) && (curWord <= 9));
@@ -2941,7 +2943,7 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 }
 
 void LilliputScript::OC_sub1834C() {
-	debugC(1, kDebugScript, "OC_sub1834C()");
+	debugC(1, kDebugScriptTBC, "OC_sub1834C()");
 
 	byte curWord = _currScript->readUint16LE() & 0xFF;
 	assert(_vm->_currentCharacterVariables != NULL);
@@ -2950,14 +2952,14 @@ void LilliputScript::OC_sub1834C() {
 }
 
 void LilliputScript::OC_setArray122C1() {
-	debugC(1, kDebugScript, "OC_setArray122C1()");
+	debugC(1, kDebugScriptTBC, "OC_setArray122C1()");
 
 	int var1 = _currScript->readUint16LE();
 	_array122C1[_vm->_currentScriptCharacter] = var1;
 }
 
 void LilliputScript::OC_sub18367() {
-	debugC(1, kDebugScript, "OC_sub18367()");
+	debugC(1, kDebugScriptTBC, "OC_sub18367()");
 
 	_characterScriptEnabled[_vm->_currentScriptCharacter] = 1;
 	_vm->_currentCharacterVariables[0] = _array122C1[_vm->_currentScriptCharacter];
@@ -2967,7 +2969,7 @@ void LilliputScript::OC_sub18367() {
 }
 
 void LilliputScript::OC_sub17D04() {
-	debugC(1, kDebugScript, "OC_sub17D04()");
+	debugC(1, kDebugScriptTBC, "OC_sub17D04()");
 
 	int16 index = getValue1();
 	byte var2 = _currScript->readUint16LE() & 0xFF;
@@ -2976,7 +2978,7 @@ void LilliputScript::OC_sub17D04() {
 }
 
 void LilliputScript::OC_sub18387() {
-	debugC(1, kDebugScript, "OC_sub18387()");
+	debugC(1, kDebugScriptTBC, "OC_sub18387()");
 
 	int index = getValue1();
 	byte var1 = _currScript->readUint16LE() & 0xFF;
@@ -2986,13 +2988,13 @@ void LilliputScript::OC_sub18387() {
 }
 
 void LilliputScript::OC_setDebugFlag() {
-	debugC(1, kDebugScript, "OC_setDebugFlag()");
+	debugC(1, kDebugScriptTBC, "OC_setDebugFlag()");
 
 	_vm->_debugFlag = 1;
 }
 
 void LilliputScript::OC_setByte14837() {
-	debugC(1, kDebugScript, "OC_setByte14837()");
+	debugC(1, kDebugScriptTBC, "OC_setByte14837()");
 
 	_vm->_byte14837 = 1;
 }
@@ -3005,7 +3007,7 @@ void LilliputScript::OC_sub183C6() {
 }
 
 void LilliputScript::OC_loadFile_AERIAL_GFX() {
-	debugC(1, kDebugScript, "OC_loadFile_AERIAL_GFX()");
+	debugC(1, kDebugScriptTBC, "OC_loadFile_AERIAL_GFX()");
 	
 	int var1 = _currScript->readUint16LE() & 0xff;
 	_vm->_byte15EAD = var1;
@@ -3033,7 +3035,7 @@ void LilliputScript::OC_sub1844A() {
 }
 
 void LilliputScript::OC_sub1847F() {
-	debugC(1, kDebugScript, "OC_sub1847F()");
+	debugC(1, kDebugScriptTBC, "OC_sub1847F()");
 
 	byte *buf215Ptr = getCharacterVariablePtr();
 	byte tmpVal = buf215Ptr[0];
@@ -3051,7 +3053,7 @@ void LilliputScript::OC_sub1847F() {
 }
 
 void LilliputScript::sub18BE6(byte var1, int var2, int var4) {
-	debugC(1, kDebugScript, "sub18BE6(%d, %d, %d)", var1, var2, var4);
+	debugC(1, kDebugScriptTBC, "sub18BE6(%d, %d, %d)", var1, var2, var4);
 
 	_vm->_displayStringIndex = 0;
 	_vm->_displayStringBuf[0] = 32;
@@ -3064,7 +3066,7 @@ void LilliputScript::sub18BE6(byte var1, int var2, int var4) {
 }
 
 void LilliputScript::OC_displayVGAFile() {
-	debugC(1, kDebugScript, "OC_displayVGAFile()");
+	debugC(1, kDebugScriptTBC, "OC_displayVGAFile()");
 
 	_byte12A09 = 1;
 	OC_PaletteFadeOut();
@@ -3081,7 +3083,7 @@ void LilliputScript::OC_sub184D7() {
 }
 
 void LilliputScript::OC_displayTitleScreen() {
-	debugC(1, kDebugScript, "OC_displayTitleScreen()");
+	debugC(1, kDebugScriptTBC, "OC_displayTitleScreen()");
 
 	_vm->_byte184F4 = (_currScript->readUint16LE() & 0xFF);
 	_vm->_sound_byte16F06 = _vm->_byte184F4;
@@ -3113,7 +3115,7 @@ void LilliputScript::OC_displayTitleScreen() {
 }
 
 void LilliputScript::OC_sub1853B() {
-	debugC(1, kDebugScript, "OC_sub1853B()");
+	debugC(1, kDebugScriptTBC, "OC_sub1853B()");
 
 	OC_PaletteFadeOut();
 	_vm->_displayMap = 0;
@@ -3129,7 +3131,7 @@ void LilliputScript::OC_sub1853B() {
 }
 
 void LilliputScript::OC_sub1864D() {
-	debugC(1, kDebugScript, "OC_sub1864D()");
+	debugC(1, kDebugScriptTBC, "OC_sub1864D()");
 
 	byte *tmpArr = getCharacterVariablePtr();
 	int var1 = (_currScript->readUint16LE() & 0xFF);
@@ -3141,7 +3143,7 @@ void LilliputScript::OC_sub1864D() {
 }
 
 void LilliputScript::OC_initArr18560() {
-	debugC(1, kDebugScript, "OC_initArr18560()");
+	debugC(1, kDebugScriptTBC, "OC_initArr18560()");
 
 	int curWord = _currScript->readUint16LE();
 	assert (curWord < 4);
@@ -3154,7 +3156,7 @@ void LilliputScript::OC_initArr18560() {
 }
 
 void LilliputScript::OC_sub18678() {
-	debugC(1, kDebugScript, "OC_initArr18578()");
+	debugC(1, kDebugScriptTBC, "OC_initArr18578()");
 	_savedBuffer215Ptr = getCharacterVariablePtr();
 	_heroismBarX = _currScript->readUint16LE();
 	_heroismBarBottomY = _currScript->readUint16LE();
@@ -3165,7 +3167,7 @@ void LilliputScript::OC_sub18690() {
 }
 
 void LilliputScript::OC_setViewPortCharacterTarget() {
-	debugC(1, kDebugScript, "OC_setViewPortCharacterTarget()");
+	debugC(1, kDebugScriptTBC, "OC_setViewPortCharacterTarget()");
 
 	_viewportCharacterTarget = getValue1();
 }
@@ -3175,7 +3177,7 @@ void LilliputScript::OC_sub186A1() {
 }
 
 void LilliputScript::OC_sub186E5_snd() {
-	debugC(1, kDebugScript, "OC_sub186E5_snd()");
+	debugC(1, kDebugScriptTBC, "OC_sub186E5_snd()");
 	int index = getValue1();
 	assert(index < 40);
 
@@ -3191,7 +3193,7 @@ void LilliputScript::OC_sub186E5_snd() {
 }
 
 void LilliputScript::OC_sub1870A_snd() {
-	debugC(1, kDebugScript, "OC_sub1870A_snd()");
+	debugC(1, kDebugScriptTBC, "OC_sub1870A_snd()");
 
 	Common::Point var3 = getPosFromScript();
 	Common::Point var4 = var3;
@@ -3202,7 +3204,7 @@ void LilliputScript::OC_sub1870A_snd() {
 }
 
 void LilliputScript::OC_sub18725_snd() {
-	debugC(1, kDebugScript, "OC_sub18725_snd()");
+	debugC(1, kDebugScriptTBC, "OC_sub18725_snd()");
 
 	int var4 = getValue1() | 0xFF00;
 
@@ -3210,7 +3212,7 @@ void LilliputScript::OC_sub18725_snd() {
 }
 
 void LilliputScript::OC_sub18733_snd() {
-	debugC(1, kDebugScript, "OC_sub18733_snd()");
+	debugC(1, kDebugScriptTBC, "OC_sub18733_snd()");
 
 	Common::Point var4 = getPosFromScript();
 
@@ -3218,13 +3220,13 @@ void LilliputScript::OC_sub18733_snd() {
 }
 
 void LilliputScript::OC_sub1873F_snd() {
-	debugC(1, kDebugScript, "OC_sub1873F_snd()");
+	debugC(1, kDebugScriptTBC, "OC_sub1873F_snd()");
 
 	_vm->_soundHandler->contentFct4();
 }
 
 void LilliputScript::OC_sub18746_snd() {
-	debugC(1, kDebugScript, "OC_sub18746_snd()");
+	debugC(1, kDebugScriptTBC, "OC_sub18746_snd()");
 
 	int var4 = -1;
 	int var2 = (_viewportPos.x << 8) + _viewportPos.y;
@@ -3234,13 +3236,13 @@ void LilliputScript::OC_sub18746_snd() {
 }
 
 void LilliputScript::OC_sub1875D_snd() {
-	debugC(1, kDebugScript, "OC_sub1875D_snd()");
+	debugC(1, kDebugScriptTBC, "OC_sub1875D_snd()");
 
 	_vm->_soundHandler->contentFct6();
 }
 
 void LilliputScript::OC_sub18764() {
-	debugC(1, kDebugScript, "OC_sub18764()");
+	debugC(1, kDebugScriptTBC, "OC_sub18764()");
 
 	int index = getValue1();
 	int var1 = _currScript->readUint16LE();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 2e62c1f..8ef723e 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -40,7 +40,7 @@ enum KValueType {
 	kCompareOperation,
 	kComputeOperation,
 	kGetValue1,
-	kgetPosFromScript,
+	kgetPosFromScript
 };
 
 
@@ -115,6 +115,9 @@ private:
 	int _word16F00;
 	int _word18776;
 	int _word18821;
+	int _word129A3;
+
+	char _array129A5[4];
 
 	int handleOpcode(ScriptStream *script);
 	byte handleOpcodeType1(int curWord);
diff --git a/engines/lilliput/sound.cpp b/engines/lilliput/sound.cpp
index d5f37d7..571191f 100644
--- a/engines/lilliput/sound.cpp
+++ b/engines/lilliput/sound.cpp
@@ -33,6 +33,11 @@ LilliputSound::LilliputSound(LilliputEngine *vm) : _vm(vm) {
 LilliputSound::~LilliputSound() {
 }
 
+// Used during initialisation
+void LilliputSound::contentFct0() {
+	debugC(1, kDebugSound, "contentFct0()");
+}
+
 void LilliputSound::contentFct1() {
 	debugC(1, kDebugSound, "contentFct1()");
 }
diff --git a/engines/lilliput/sound.h b/engines/lilliput/sound.h
index 5fa84bf..c4f2126 100644
--- a/engines/lilliput/sound.h
+++ b/engines/lilliput/sound.h
@@ -32,6 +32,7 @@ public:
 	LilliputSound(LilliputEngine *vm);
 	~LilliputSound();
 
+	void contentFct0();
 	void contentFct1();
 	void contentFct2();
 	void contentFct3();
diff --git a/engines/lilliput/stream.cpp b/engines/lilliput/stream.cpp
index 03195dc..cd0b918 100644
--- a/engines/lilliput/stream.cpp
+++ b/engines/lilliput/stream.cpp
@@ -24,7 +24,7 @@
 
 namespace Lilliput {
 
-ScriptStream::ScriptStream(byte *buf, int size) : Common::MemoryReadStream(buf, size) {
+ScriptStream::ScriptStream(byte *buf, int bufSize) : Common::MemoryReadStream(buf, bufSize) {
 	_orgPtr = buf;
 }
 
diff --git a/engines/lilliput/stream.h b/engines/lilliput/stream.h
index d6b8c36..52b80e3 100644
--- a/engines/lilliput/stream.h
+++ b/engines/lilliput/stream.h
@@ -31,7 +31,7 @@ class ScriptStream : public Common::MemoryReadStream {
 private:
 	byte *_orgPtr;
 public:
-	ScriptStream(byte *buf, int size);
+	ScriptStream(byte *buf, int bufSize);
 	virtual ~ScriptStream();
 
 	void writeUint16LE(int value, int relativePos = 0);


Commit: 8871c440e5d53cb64e589870e777eb945357d73b
    https://github.com/scummvm/scummvm/commit/8871c440e5d53cb64e589870e777eb945357d73b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add a size parameter to loadVGA to fix Valgrind warnings and stick to the original

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 63edc9f..016dd6d 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -147,7 +147,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte16552 = 0;
 	_byte12FE4 = 0xFF;
 	_byte12FE3 = 0;
-	_byte16F08 = 0;
+	_byte16F08 = 0;	
 	_byte16C9F = 0;
 
 	_currentScriptCharacter = 0;
@@ -259,7 +259,7 @@ void LilliputEngine::newInt8() {
 	}
 	--_byte12A06;
 	// TODO: check 'out 20h, 20h'
-
+	
 	// hack for the title stars because _int8installed is not set at the good place for the moment
 	//if (!_int8installed)
 	//	return;
@@ -329,7 +329,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 		// Sprite mirror
 		for (int y = 0; y < 16; y++) {
 			for (int x = 0; x < 16; x++) {
-				// May need a hack of 1 pixel
+				// May need a hack of 1 pixel 
 				if (src[15 - x] != 0)
 					buf[x] = src[15 - x];
 			}
@@ -588,7 +588,7 @@ void LilliputEngine::displayFunction12() {
 
 	displayFunction5();
 
-	byte *tmpBuf = loadVGA("SCREEN.GFX", true);
+	byte *tmpBuf = loadVGA("SCREEN.GFX", 64000, true);
 	memcpy(_mainSurface->getPixels(), tmpBuf, 320*200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
@@ -1150,8 +1150,8 @@ void LilliputEngine::sortCharacters() {
 		for (int var2 = 0; var2 < var4; var2++) {
 			int index1 = _charactersToDisplay[var2];
 			int index2 = _charactersToDisplay[var2 + 1];
-
-			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2])
+		
+			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2]) 
 				continue;
 
 			if (_characterRelativePositionY[index1] == _characterRelativePositionY[index2]) {
@@ -1408,7 +1408,6 @@ byte LilliputEngine::sub16799(int index, int param1) {
 
 }
 
-//TODO rename arrays
 void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngineTBC, "sub167EF(%d)", index);
 	
@@ -2305,8 +2304,8 @@ void LilliputEngine::pollEvent() {
 	}
 }
 
-byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
-	debugC(1, kDebugEngine, "loadVGA(%s, %d)", filename.c_str(), (loadPal) ? 1 : 0);
+byte *LilliputEngine::loadVGA(Common::String filename, int expectedSize, bool loadPal) {
+	debugC(1, kDebugEngine, "loadVGA(%s, %d, %d)", filename.c_str(), expectedSize, (loadPal) ? 1 : 0);
 
 	Common::File f;
 
@@ -2323,10 +2322,10 @@ byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 	}
 
 	uint8 curByte;
-	byte decodeBuffer[100000];
+	byte *decodeBuffer = (byte *)malloc(expectedSize);
 	int size = 0;
 
-	for (;remainingSize > 0;) {
+	for (;(remainingSize > 0) && (size < expectedSize);) {
 		curByte = f.readByte();
 		--remainingSize;
 
@@ -2342,6 +2341,8 @@ byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 			for (int i = 0; i < compSize; ++i) {
 				decodeBuffer[size] = curByte;
 				++size;
+				if (size == expectedSize)
+					break;
 			}
 		} else {
 			// Not compressed
@@ -2350,15 +2351,17 @@ byte *LilliputEngine::loadVGA(Common::String filename, bool loadPal) {
 				decodeBuffer[size] = f.readByte();
 				--remainingSize;
 				++size;
+				if (size == expectedSize)
+					break;
 			}
 		}
 	}
-
 	f.close();
 
-	byte *res = (byte *)malloc(sizeof(byte) * size);
-	memcpy(res, decodeBuffer, size);
-	return res;
+	for (int i = size; i < expectedSize; i++)
+		decodeBuffer[i] = 0;
+
+	return decodeBuffer;
 }
 
 byte *LilliputEngine::loadRaw(Common::String filename) {
@@ -2546,7 +2549,7 @@ void LilliputEngine::displayVGAFile(Common::String fileName) {
 
 	displayFunction4();
 
-	byte *buffer = loadVGA(fileName, true);
+	byte *buffer = loadVGA(fileName, 64000, true);
 	memcpy(_mainSurface->getPixels(), buffer, 320*200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
@@ -2683,10 +2686,10 @@ Common::Error LilliputEngine::run() {
 	initPalette();
 
 	// Load files. In the original, the size was hardcoded
-	_bufferIdeogram = loadVGA("IDEOGRAM.VGA", false);
-	_bufferMen = loadVGA("MEN.VGA", false);
-	_bufferMen2 = loadVGA("MEN2.VGA", false);
-	_bufferIsoChars = loadVGA("ISOCHARS.VGA", false);
+	_bufferIdeogram = loadVGA("IDEOGRAM.VGA", 25600, false);
+	_bufferMen = loadVGA("MEN.VGA", 61440, false);
+	_bufferMen2 = loadVGA("MEN2.VGA", 61440, false);
+	_bufferIsoChars = loadVGA("ISOCHARS.VGA", 4096, false);
 	_bufferIsoMap = loadRaw("ISOMAP.DTA");
 
 	loadRules();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 3892ff8..9aa2924 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -310,7 +310,7 @@ public:
 	void sub1693A(int index);
 
 	void initGame(const LilliputGameDescription *gd);
-	byte *loadVGA(Common::String filename, bool loadPal);
+	byte *loadVGA(Common::String filename, int fileSize, bool loadPal);
 	byte *loadRaw(Common::String filename);
 	void loadRules();
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 8d1c750..573213d 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2937,7 +2937,7 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 	Common::String fileName = Common::String::format("CUBES%d.GFX", curWord);
 	_byte10806 = curWord + 0x30;
 
-	_vm->_bufferCubegfx = _vm->loadVGA(fileName, false);
+	_vm->_bufferCubegfx = _vm->loadVGA(fileName, 61440, false);
 	_vm->displayFunction9();
 	_vm->displayFunction15();
 }


Commit: 2575378f09305ca2bea7cebc988c9217d66b6463
    https://github.com/scummvm/scummvm/commit/2575378f09305ca2bea7cebc988c9217d66b6463
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix another Valgrind warning

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 573213d..7bfbc77 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -77,6 +77,9 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	for (int i = 0; i < 640; i++) {
 		_array12311[i] = 0xFFFF;
 	}
+
+	for (int i = 0; i < 1600; i++)
+		_array10B51[i] = 0;
 }
 
 LilliputScript::~LilliputScript() {


Commit: 6b9777cc9f2eb4c468fbc41dbfc09826236d5922
    https://github.com/scummvm/scummvm/commit/6b9777cc9f2eb4c468fbc41dbfc09826236d5922
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Turn _array12311 into a Common::Point, fix initialization of _array16C58,

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 016dd6d..bcfb514 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -38,6 +38,7 @@
 namespace Lilliput {
 
 LilliputEngine *LilliputEngine::s_Engine = 0;
+
 static const byte _basisPalette[768] = {
 	0,  0,  0,  0,  0,  42, 0,  42, 0,  0,  42, 42,
 	42, 0,  0,  42, 0,  42, 42, 21, 0,  42, 42, 42,
@@ -166,10 +167,10 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_saveFlag = false;
 	_byte16F07_menuId = 0;
 
-	_array16C54[0] = _array16C54[3] = 1;
-	_array16C54[1] = _array16C54[2] = 2;
-	_array16C54[2] = _array16C54[1] = 4;
-	_array16C54[3] = _array16C54[0] = 8;
+	_array16C54[0] = _array16C58[3] = 1;
+	_array16C54[1] = _array16C58[2] = 2;
+	_array16C54[2] = _array16C58[1] = 4;
+	_array16C54[3] = _array16C58[0] = 8;
 
 	for (int i = 0; i < 3; i++)
 		_array147D1[i] = 0;
@@ -1379,15 +1380,15 @@ int LilliputEngine::getDirection(Common::Point param1, Common::Point param2) {
 	return _directionsArray[var2l];
 }
 
-byte LilliputEngine::sub16799(int index, int param1) {
-	debugC(2, kDebugEngineTBC, "sub16799(%d, %d)", index, param1);
+byte LilliputEngine::sub16799(int index, Common::Point param1) {
+	debugC(2, kDebugEngineTBC, "sub16799(%d, %d - %d)", index, param1.x, param1.y);
 
 	Common::Point var3 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
 
 	if (var3.x != -1) {
 		if ((var3.x != _scriptHandler->_array16123PosX[index]) || (var3.y != _scriptHandler->_array1614BPosY[index])) {
 			sub1693A(index);
-			_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
+			_scriptHandler->_array12811[index] -= (param1.x & 0x0F);
 			return 3;
 		}
 
@@ -1403,7 +1404,7 @@ byte LilliputEngine::sub16799(int index, int param1) {
 	_characterDirectionArray[index] = getDirection(pos1, pos2);
 
 	sub1693A(index);
-	_scriptHandler->_array12811[index] -= (param1 >> 8) & 0x0F;
+	_scriptHandler->_array12811[index] -= (param1.x & 0x0F);
 	return 3;
 
 }
@@ -1466,7 +1467,7 @@ void LilliputEngine::sub167EF(int index) {
 	}
 	
 	// var4h == var4l
-	int mapIndex = (((_array10A11PosY[index] >> 2) + _array109E9PosX[index]) << 2);
+	int mapIndex = (((_array10A11PosY[index] << 8) >> 2) + _array109E9PosX[index]) << 2;
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
 	if ((tmpVal & 8) != 0)
 		++_array109E9PosX[index];
@@ -1658,9 +1659,9 @@ void LilliputEngine::sub16626() {
 				break;
 
 			var2 = (2 * (var2 & 0xFF)) + (index << 5);
-			uint16 var1 = _scriptHandler->_array12311[var2 / 2];
+			Common::Point var1 = _scriptHandler->_array12311[var2 / 2];
 			int tmpVal = var2;
-			var2 = ((var1 >> 8) >> 3);
+			var2 = (var1.x >> 3);
 			var2 &= 0xFE;
 
 			switch (var2 / 2) {
@@ -1693,7 +1694,7 @@ void LilliputEngine::sub16626() {
 				result = sub16722(index, var1);
 				break;
 			case 14:
-				result = sub166F7(index, Common::Point(var1 >> 8, var1 && 0xFF), tmpVal);
+				result = sub166F7(index, var1, tmpVal);
 				break;
 			case 15:
 				result = sub166EA(index);
@@ -1730,9 +1731,9 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 			a2 |= (a2 << 4);
 
 		a2 -= 16;
-		_scriptHandler->_array12311[tmpVal] = (var1.x << 8) + var1.y;
+		_scriptHandler->_array12311[tmpVal] = Common::Point(var1.x, a2);
 
-		if ((var1.y & 0xF0) == 0)
+		if ((a2 & 0xF0) == 0)
 			return 2;
 	}
 
@@ -1740,18 +1741,18 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 	return 3;
 }
 
-byte LilliputEngine::sub166DD(int index, int var1) {
-	debugC(2, kDebugEngineTBC, "sub166DD(%d, %d)", index, var1);
+byte LilliputEngine::sub166DD(int index, Common::Point var1) {
+	debugC(2, kDebugEngineTBC, "sub166DD(%d, %d - %d)", index, var1.x, var1.y);
 	
-	_characterDirectionArray[index] = (var1 >> 8) & 3;
-	sub16685(index, var1 & 0xFF);
+	_characterDirectionArray[index] = (var1.x & 3);
+	sub16685(index, var1);
 	return 0;
 }
 
-byte LilliputEngine::sub16722(int index, byte var1) {
-	debugC(2, kDebugEngineTBC, "sub16722(%d, %d)", index, var1);
+byte LilliputEngine::sub16722(int index, Common::Point var1) {
+	debugC(2, kDebugEngineTBC, "sub16722(%d, %d - %d)", index, var1.x, var1.y);
 
-	_rulesBuffer2_10[index] = var1;
+	_rulesBuffer2_10[index] = var1.y;
 	return 2;
 }
 
@@ -1765,8 +1766,8 @@ byte LilliputEngine::sub16729(int index) {
 	return 2;
 }
 
-byte LilliputEngine::sub1675D(int index, int var1) {
-	debugC(2, kDebugEngineTBC, "sub1675D(%d)", index);
+byte LilliputEngine::sub1675D(int index, Common::Point var1) {
+	debugC(2, kDebugEngineTBC, "sub1675D(%d, %d - %d)", index, var1.x, var1.y);
 
 	int var2 = _scriptHandler->_array10A39[index];
 	int var1h = _scriptHandler->_array16123PosX[var2];
@@ -1967,19 +1968,19 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	displayInterfaceHotspots();
 }
 
-void LilliputEngine::sub16685(int idx, int var1) {
-	debugC(2, kDebugEngineTBC, "sub16685(%d, %d)", idx, var1);
+void LilliputEngine::sub16685(int idx, Common::Point var1) {
+	debugC(2, kDebugEngineTBC, "sub16685(%d, %d - %d)", idx, var1.x, var1.y);
 
-	int index = (idx << 5) + (var1 & 0xFF);
+	int index = (idx << 5) + var1.y;
 	_scriptHandler->_array10AB1[idx] = _rulesBuffer2_16[index];
 }
 
-byte LilliputEngine::sub16675(int idx, int var1) {
-	debugC(2, kDebugEngineTBC, "sub16675(%d, %d)", idx, var1);
+byte LilliputEngine::sub16675(int idx, Common::Point var1) {
+	debugC(2, kDebugEngineTBC, "sub16675(%d, %d - %d)", idx, var1.x, var1.y);
 
 	sub16685(idx, var1);
-	int index = (var1 & 0xFF);	
-	switch (var1 >> 8) {
+	int index = var1.y;	
+	switch (var1.x) {
 	case 0:
 		break;
 	case 1:
@@ -2013,7 +2014,7 @@ byte LilliputEngine::sub16675(int idx, int var1) {
 		sub166D8(index);
 		break;
 	default:
-		warning("sub16675 - Unexpected value %d", var1 >> 8);
+		warning("sub16675 - Unexpected value %d", var1.x);
 	}
 
 	return 0;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 9aa2924..642069e 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -260,22 +260,22 @@ public:
 	void sub17264(int index, int var4);
 	int findHotspot(Common::Point pos);
 	int reverseFindHotspot(Common::Point pos);
-	byte sub16722(int index, byte var1);
+	byte sub16722(int index, Common::Point var1);
 	byte sub166EA(int index);
 	void sub167EF(int index);
 
 	void renderCharacters(byte *buf, Common::Point pos);
 
-	byte sub16799(int param1, int index);
+	byte sub16799(int index, Common::Point param1);
 	int getDirection(Common::Point param1, Common::Point param2);
 	void addCharToBuf(byte character);
 	void prepareGoldAmount(int param1);
 	void sub12F37();
-	byte sub16675(int idx, int var1);
-	void sub16685(int idx, int var1);
+	byte sub16675(int idx, Common::Point var1);
+	void sub16685(int idx, Common::Point var1);
 	void sub16EBC();
 	void sub16CA0();
-	byte sub166DD(int index, int var1);
+	byte sub166DD(int index, Common::Point var1);
 	void sub171CF();
 	void sub12FE5();
 	int sub16DD5(int x1, int y1, int x2, int y2);
@@ -304,7 +304,7 @@ public:
 	void sub166D8(int index);
 	void sub16B31(int index, int val);
 	void sub16B8F(int index, int x, int y, int flag);
-	byte sub1675D(int index, int var1);
+	byte sub1675D(int index, Common::Point var1);
 	byte sub16729(int index);
 	byte sub166F7(int index, Common::Point var1, int tmpVal);
 	void sub1693A(int index);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7bfbc77..6cd5738 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -75,7 +75,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	}
 
 	for (int i = 0; i < 640; i++) {
-		_array12311[i] = 0xFFFF;
+		_array12311[i] = Common::Point(-1, -1);
 	}
 
 	for (int i = 0; i < 1600; i++)
@@ -1088,7 +1088,7 @@ void LilliputScript::sub16C86(int index, byte *buf) {
 	_array12811[index] = 0;
 
 	for (int i = 0; i < 16; i++) {
-		_array12311[(index * 16) + i] = (buf[(2 * i) + 1] << 8) + buf[2 * i];
+		_array12311[(index * 16) + i] = Common::Point(buf[(2 * i) + 1], buf[2 * i]);
 	}
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 8ef723e..6699bb6 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -79,7 +79,7 @@ public:
 	int _heroismBarBottomY;
 	int _word1855E;
 
-	uint16 _array12311[640];
+	Common::Point _array12311[640];
 	byte _array128EF[40];
 	byte _array12839[40];
 	int _array1813B[32];


Commit: 59f6e304a2feb44b416308a4dd71354893687e7d
    https://github.com/scummvm/scummvm/commit/59f6e304a2feb44b416308a4dd71354893687e7d
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index bcfb514..0649289 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -157,7 +157,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word17081_nextIndex = 0;
 	_word16EFE = 0xFFFF;
 	_word1817B = 0;
-	_word15BC8Pos = Common::Point(0, 0);
+	_savedSurfaceUnderMousePos = Common::Point(0, 0);
 	_word15AC2 = 0;
 	_word15AC2 = 0;
 	_displayStringIndex = 0;
@@ -213,7 +213,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array12861[i] = 0xFFFF;
 
 	for (int i = 0; i < 256; i++)
-		_array15AC8[i] = 0;
+		_savedSurfaceUnderMouse[i] = 0;
 
 	for (int i = 0; i < 160; i++)
 		_displayStringBuf[i] = 0;
@@ -368,9 +368,8 @@ void LilliputEngine::displayFunction1a(byte *buf, Common::Point pos) {
 	displayFunction1(buf, 0, pos);
 }
 
-// save area under mouse cursor
-void LilliputEngine::displayFunction2(byte *buf, Common::Point pos) {
-	debugC(2, kDebugEngineTBC, "displayFunction2(buf, %d, %d)", pos.x, pos.y);
+void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
+	debugC(2, kDebugEngine, "SaveSurfaceUnderMouseCursor(buf, %d, %d)", pos.x, pos.y);
 
 	int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
 	int index2 = pos.x + tmpVal + (tmpVal >> 2);
@@ -398,15 +397,14 @@ void LilliputEngine::displayFunction3(int var1, int var2, int var4) {
 	}
 }
 
-// display mouse cursor
-void LilliputEngine::displayFunction4() {
-	debugC(2, kDebugEngineTBC, "displayFunction4()");
+void LilliputEngine::displayMousePointer() {
+	debugC(2, kDebugEngine, "displayMousePointer()");
 
 	if ((_skipDisplayFlag1 != 1) && (_skipDisplayFlag2 != 1)) {
 		_skipDisplayFlag2 = 1;
 
-		_word15BC8Pos = _mouseDisplayPos;
-		displayFunction2(_array15AC8, _mouseDisplayPos);
+		_savedSurfaceUnderMousePos = _mouseDisplayPos;
+		SaveSurfaceUnderMouseCursor(_savedSurfaceUnderMouse, _mouseDisplayPos);
 		displayFunction1(_bufferIdeogram, _word15AC2 + 80, _mouseDisplayPos);
 
 		_skipDisplayFlag1 = 1;
@@ -414,12 +412,12 @@ void LilliputEngine::displayFunction4() {
 	}
 }
 
-void LilliputEngine::displayFunction5() {
-	debugC(2, kDebugEngineTBC, "displayFunction5()");
+void LilliputEngine::restoreSurfaceUnderMousePointer() {
+	debugC(2, kDebugEngine, "restoreSurfaceUnderMousePointer()");
 
 	if ((_skipDisplayFlag1 != 0) && (_skipDisplayFlag2 != 1)) {
 		_skipDisplayFlag2 = 1;
-		displayFunction1a(_array15AC8, _word15BC8Pos);
+		displayFunction1a(_savedSurfaceUnderMouse, _savedSurfaceUnderMousePos);
 		_skipDisplayFlag1 = 0;
 		_skipDisplayFlag2 = 0;
 	}
@@ -429,7 +427,7 @@ void LilliputEngine::displayFunction5() {
 void LilliputEngine::displayFunction6() {
 	debugC(2, kDebugEngineTBC, "displayFunction6()");
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	int index = (16 * 320) + 64;
 	for (int i = 0; i < 176; i++) {
@@ -438,14 +436,14 @@ void LilliputEngine::displayFunction6() {
 		index += 320;
 	}
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 // save speech zone
 void LilliputEngine::displayFunction7() {
 	debugC(2, kDebugEngineTBC, "displayFunction7()");
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	int index = 66;
 	for (int i = 0; i < 16; i++) {
@@ -454,7 +452,7 @@ void LilliputEngine::displayFunction7() {
 		index += 320;
 	}
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::displayInterfaceHotspots() {
@@ -463,7 +461,7 @@ void LilliputEngine::displayInterfaceHotspots() {
 	if (_displayMap == 1)
 		return;
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	int index = 0;
 	int tmpVal;
@@ -472,7 +470,7 @@ void LilliputEngine::displayInterfaceHotspots() {
 		displayFunction1(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
 	}
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::displayFunction9() {
@@ -500,7 +498,7 @@ void LilliputEngine::displayFunction10() {
 	debugC(2, kDebugEngineTBC, "displayFunction10()");
 	static const byte _array15976[16] = {244, 248, 250, 250, 252, 252, 252, 252, 252, 252, 252, 252, 250, 250, 248, 244};
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	int index = 192;
 	int tmpIndex;
@@ -516,7 +514,7 @@ void LilliputEngine::displayFunction10() {
 		index += 320;
 	}
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex) {
@@ -554,7 +552,7 @@ void LilliputEngine::sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex) {
 void LilliputEngine::displayFunction11(byte *buf) {
 	debugC(2, kDebugEngineTBC, "displayFunction11(%s)", buf);
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	int vgaIndex = 70;
 	int bufIndex = 0;
@@ -581,13 +579,13 @@ void LilliputEngine::displayFunction11(byte *buf) {
 		sub15A4C(vgaIndex, buf, bufIndex);
 	}
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::displayFunction12() {
 	debugC(1, kDebugEngineTBC, "displayFunction12()");
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	byte *tmpBuf = loadVGA("SCREEN.GFX", 64000, true);
 	memcpy(_mainSurface->getPixels(), tmpBuf, 320*200);
@@ -602,7 +600,7 @@ void LilliputEngine::displayFunction12() {
 	displayFunction15();
 	displayFunction14();
 
-	displayFunction4();
+	displayMousePointer();
 	free(tmpBuf);
 }
 
@@ -632,7 +630,7 @@ void LilliputEngine::displayFunction14() {
 		return;
 
 	if (_mouseDisplayPos.x > 48)
-		displayFunction5();
+		restoreSurfaceUnderMousePointer();
 
 	int index = (16 * 320) + 64;
 	for (int i = 0; i < 176; i++) {
@@ -644,27 +642,27 @@ void LilliputEngine::displayFunction14() {
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::restoreMapPoints() {
 	debugC(2, kDebugEngineTBC, "restoreMapPoints()");
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = 0; index < _numCharacters; index++) {
 		buf[_word15E5D[index]] = _byte15E35[index];
 	}
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::displayCharactersOnMap() {
 	debugC(2, kDebugEngineTBC, "displayCharactersOnMap()");
 
 	sub16217();
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = _numCharacters - 1; index >=0; index--) {
@@ -677,7 +675,7 @@ void LilliputEngine::displayCharactersOnMap() {
 			 buf[y * 320 + x] = _scriptHandler->_array128EF[index];
 		}
 	}
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::sub16217() {
@@ -828,7 +826,7 @@ void LilliputEngine::sub1863B() {
 }
 
 void LilliputEngine::paletteFadeOut() {
-	debugC(2, kDebugEngineTBC, "paletteFadeOut()");
+	debugC(2, kDebugEngine, "paletteFadeOut()");
 
 	sub1863B();
 	byte palette[768];
@@ -1067,19 +1065,19 @@ void LilliputEngine::sub16CA0() {
 void LilliputEngine::displayFunction17() {
 	debugC(2, kDebugEngineTBC, "displayFunction17()");
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 
 	for (int i = 0; i < 16; i++)
 		for (int j = 0; j < 252; j++)
 			((byte *)_mainSurface->getPixels())[66 + (i * 320) + j] = _buffer10_4032[(252 * i) + j];
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	debugC(2, kDebugEngineTBC, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
 	
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 	
 	if ((var1 & 0xFF) == 0x2D) {
 		var2 += 35;
@@ -1105,7 +1103,7 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 		vgaIndex += 320;
 	}
 	
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::displayString(byte *buf, int var2, int var4) {
@@ -1347,7 +1345,7 @@ void LilliputEngine::sub189DE() {
 		--_byte1881D;
 		if (_byte1881D == 0) {
 			displayFunction17();
-			_scriptHandler->_word1881B = 0xFFFF;
+			_scriptHandler->_word1881B = -1;
 		}
 	}
 }
@@ -2230,7 +2228,7 @@ void LilliputEngine::displayHeroismIndicator() {
 	if (var1 == _scriptHandler->_heroismLevel)
 		return;
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 	int var2 = 1;
 	if (var1 > _scriptHandler->_heroismLevel)
 		var1 = 150;
@@ -2265,7 +2263,7 @@ void LilliputEngine::displayHeroismIndicator() {
 		}
 	}
 
-	displayFunction4();
+	displayMousePointer();
 }
 
 void LilliputEngine::pollEvent() {
@@ -2296,9 +2294,9 @@ void LilliputEngine::pollEvent() {
 	if (_mousePos != _oldMousePos) {
 		_oldMousePos = _mousePos;
 		if (_skipDisplayFlag1 != 0) {
-			displayFunction5();
+			restoreSurfaceUnderMousePointer();
 			_mouseDisplayPos = _mousePos;
-			displayFunction4();
+			displayMousePointer();
 		} else {
 			_mouseDisplayPos = _mousePos;
 		}
@@ -2435,33 +2433,33 @@ void LilliputEngine::loadRules() {
 			_rulesBuffer2_16[(j * 32) + k] = f.readByte();
 	}
 
-	// Chunk 3 & 4
-	_rulesChunk3_size = f.readSint16LE();
+	// Chunk 3 & 4 : Packed strings & associated indexes
+	_packedStringNumb = f.readSint16LE();
 	curWord = f.readSint16LE();
 
-	_rulesChunk3 = (int *)malloc(sizeof(int) * _rulesChunk3_size);
-	for (int i = 0; i < _rulesChunk3_size; ++i)
-		_rulesChunk3[i] = f.readUint16LE();
+	_packedStringIndex = (int *)malloc(sizeof(int) * _packedStringNumb);
+	for (int i = 0; i < _packedStringNumb; ++i)
+		_packedStringIndex[i] = f.readUint16LE();
 
-	_rulesChunk4 = (byte *)malloc(sizeof(byte) * curWord);
+	_packedStrings = (char *)malloc(curWord);
 	for (int i = 0; i < curWord; ++i)
-		_rulesChunk4[i] = f.readByte();
+		_packedStrings[i] = f.readByte();
 
 	// Chunk 5: Scripts
 	// Use byte instead of int, therefore multiply by two the size.
-	// This is for changing that into a memory read stream
-	_initScript_size = f.readUint16LE() * 2;
-	_initScript = (byte *)malloc(sizeof(byte) * _initScript_size);
-	for (int i = 0; i < _initScript_size; ++i)
+	// This is for converting it into a memory read stream
+	_initScriptSize = f.readUint16LE() * 2;
+	_initScript = (byte *)malloc(_initScriptSize);
+	for (int i = 0; i < _initScriptSize; ++i)
 		_initScript[i] = f.readByte();
 
-	// Chunk 6
-	_menuScript_size = f.readUint16LE() * 2;
-	_menuScript = (byte *)malloc(sizeof(byte) * _menuScript_size);
-	for (int i = 0; i < _menuScript_size; ++i)
+	// Chunk 6: Menu Script
+	_menuScriptSize = f.readUint16LE() * 2;
+	_menuScript = (byte *)malloc(sizeof(byte) * _menuScriptSize);
+	for (int i = 0; i < _menuScriptSize; ++i)
 		_menuScript[i] = f.readByte();
 
-	// Chunk 7 & 8
+	// Chunk 7 & 8: Game scripts and indexes
 	_gameScriptIndexSize = f.readUint16LE();
 	// Added one position to keep the total size too, as it's useful later
 	_arrayGameScriptIndex = (int *)malloc(sizeof(int) * (_gameScriptIndexSize + 1));
@@ -2546,16 +2544,16 @@ void LilliputEngine::loadRules() {
 }
 
 void LilliputEngine::displayVGAFile(Common::String fileName) {
-	debugC(1, kDebugEngineTBC, "displayVGAFile(%s)", fileName.c_str());
+	debugC(1, kDebugEngine, "displayVGAFile(%s)", fileName.c_str());
 
-	displayFunction4();
+	displayMousePointer();
 
 	byte *buffer = loadVGA(fileName, 64000, true);
 	memcpy(_mainSurface->getPixels(), buffer, 320*200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
 
-	displayFunction5();
+	restoreSurfaceUnderMousePointer();
 }
 
 void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
@@ -2610,7 +2608,7 @@ void LilliputEngine::handleMenu() {
 
 	sub170EE(_word10804);
 	debugC(1, kDebugScriptTBC, "========================== Menu Script ==============================");
-	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScript_size));
+	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScriptSize));
 	debugC(1, kDebugScriptTBC, "========================== End of Menu Script==============================");
 	_savedMousePosDivided = Common::Point(-1, -1);
 	_byte129A0 = 0xFF;
@@ -2700,7 +2698,7 @@ Common::Error LilliputEngine::run() {
 
 	_lastTime = _system->getMillis();
 
-	_scriptHandler->runScript(ScriptStream(_initScript, _initScript_size));
+	_scriptHandler->runScript(ScriptStream(_initScript, _initScriptSize));
 
 	// Hack, see above 
 	_int8installed = true;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 642069e..a1d683c 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -138,7 +138,7 @@ public:
 	int _word17081_nextIndex;
 	int _word16EFE;
 	int _word1817B;
-	Common::Point _word15BC8Pos;
+	Common::Point _savedSurfaceUnderMousePos;
 	int _word15AC2;
 	int _currentDisplayCharacter;
 	int _displayStringIndex;
@@ -170,13 +170,13 @@ public:
 	byte _characterVariables_[1400 + 3120];
 	byte *_currentCharacterVariables;
 	byte _rulesBuffer2_16[40 * 32];
-	int *_rulesChunk3;
-	int _rulesChunk3_size;
-	byte *_rulesChunk4;
+	int *_packedStringIndex;
+	int _packedStringNumb;
+	char *_packedStrings;
 	byte *_initScript;
-	int _initScript_size;
+	int _initScriptSize;
 	byte *_menuScript;
-	int _menuScript_size;
+	int _menuScriptSize;
 	int *_arrayGameScriptIndex;
 	int _gameScriptIndexSize;
 	byte *_arrayGameScripts;
@@ -196,7 +196,7 @@ public:
 	byte _rulesBuffer13_4[20];
 	int16 _array10999PosX[40];
 	int16 _array109C1PosY[40];
-	byte _array15AC8[256];
+	byte _savedSurfaceUnderMouse[16 * 16];
 	byte _charactersToDisplay[40];
 	int16 _characterRelativePositionX[40];
 	int16 _characterRelativePositionY[40];
@@ -222,10 +222,10 @@ public:
 
 	void displayFunction1(byte *buf, int var1, Common::Point pos);
 	void displayFunction1a(byte *buf, Common::Point pos);
-	void displayFunction2(byte *buf, Common::Point pos);
+	void SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos);
 	void displayFunction3(int var1, int var2, int var4);
-	void displayFunction4();
-	void displayFunction5();
+	void displayMousePointer();
+	void restoreSurfaceUnderMousePointer();
 	void displayFunction6();
 	void displayFunction7();
 	void displayInterfaceHotspots();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 6cd5738..17f6f6a 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -86,7 +86,7 @@ LilliputScript::~LilliputScript() {
 }
 
 byte LilliputScript::handleOpcodeType1(int curWord) {
-	debugC(2, kDebugScriptTBC, "handleOpcodeType1(0x%x)", curWord);
+	debugC(2, kDebugScript, "handleOpcodeType1(0x%x)", curWord);
 	switch (curWord) {
 	case 0x0:
 		return OC_checkCharacterGoalPos();
@@ -245,7 +245,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 }
 
 void LilliputScript::handleOpcodeType2(int curWord) {
-	debugC(2, kDebugScriptTBC, "handleOpcodeType2(0x%x)", curWord);
+	debugC(2, kDebugScript, "handleOpcodeType2(0x%x)", curWord);
 	switch (curWord) {
 	case 0x0:
 		OC_setWord18821();
@@ -905,7 +905,7 @@ void LilliputScript::disasmScript( ScriptStream script) {
 }
 
 int LilliputScript::handleOpcode(ScriptStream *script) {
-	debugC(2, kDebugScriptTBC, "handleOpcode");
+	debugC(2, kDebugScript, "handleOpcode");
 
 	_currScript = script;
 	uint16 curWord = _currScript->readUint16LE();
@@ -939,7 +939,7 @@ int LilliputScript::handleOpcode(ScriptStream *script) {
 }
 
 void LilliputScript::runScript(ScriptStream script) {
-	debugC(1, kDebugScriptTBC, "runScript");
+	debugC(1, kDebugScript, "runScript");
 
 	_byte16F05_ScriptHandler = 1;
 	
@@ -1179,8 +1179,8 @@ void LilliputScript::sub189B8() {
 	_vm->displayFunction11(_vm->_displayStringBuf);
 }
 
-void LilliputScript::sub18A56(byte *buf) {
-	debugC(2, kDebugScriptTBC, "sub18A56(buf)");
+void LilliputScript::decodePackedText(char *buf) {
+	debugC(2, kDebugScriptTBC, "decodePackedText(buf)");
 
 	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I''ve |can''t |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|''s |''t |re|gg|tt|pp|nn|ay|ar|wh|";
 
@@ -1237,9 +1237,9 @@ void LilliputScript::sub18A56(byte *buf) {
 int LilliputScript::sub18BB7(int index) {
 	debugC(2, kDebugScriptTBC, "sub18BB7(%d)", index);
 	
-	int chunk4Index = _vm->_rulesChunk3[index];
+	int chunk4Index = _vm->_packedStringIndex[index];
 	int result = 0;
-	while (_vm->_rulesChunk4[chunk4Index + result] == 0x5B)
+	while (_vm->_packedStrings[chunk4Index + result] == 0x5B)
 		++result;
 	
 	return result + 1;
@@ -1253,9 +1253,9 @@ void LilliputScript::sub18B3C(int var) {
 
 	_word18776 = var;
 
-	int index = _vm->_rulesChunk3[var];
+	int index = _vm->_packedStringIndex[var];
 	int count = 0;
-	while (_vm->_rulesChunk4[index + count] != 0x5B)
+	while (_vm->_packedStrings[index + count] != 0x5B)
 		++count;
 
 	int i = 0;
@@ -1265,12 +1265,12 @@ void LilliputScript::sub18B3C(int var) {
 			for (int j = 0; j < tmpVal; j++) {
 				do
 					++i;
-				while (_vm->_rulesChunk4[index + count + i] != 0x5B);
+				while (_vm->_packedStrings[index + count + i] != 0x5B);
 			}
 		}
 	}
 
-	sub18A56(&_vm->_rulesChunk4[index + count + i]);
+	decodePackedText(&_vm->_packedStrings[index + count + i]);
 }
 
 int16 LilliputScript::getValue1() {
@@ -1546,8 +1546,8 @@ byte LilliputScript::OC_compareCoords_1() {
 	int index = _currScript->readUint16LE();
 	assert(index < 40);
 
-	int var3 = _vm->_rectXMinMax[index];
-	int var4 = _vm->_rectYMinMax[index];
+	int16 var3 = _vm->_rectXMinMax[index];
+	int16 var4 = _vm->_rectYMinMax[index];
 	Common::Point var1 = _vm->_currentScriptCharacterPos;
 
 	if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
@@ -1560,11 +1560,11 @@ byte LilliputScript::OC_compareCoords_1() {
 byte LilliputScript::OC_compareCoords_2() {
 	debugC(1, kDebugScriptTBC, "OC_compareCoords_2()");
 
-	int index = getValue1();
+	int16 index = getValue1();
 	Common::Point var1 = Common::Point(_array16123PosX[index], _array1614BPosY[index]);
-	uint16 var2 = _currScript->readUint16LE();
-	uint16 var3 = _vm->_rectXMinMax[var2];
-	uint16 var4 = _vm->_rectYMinMax[var2];
+	index = _currScript->readUint16LE();
+	uint16 var3 = _vm->_rectXMinMax[index];
+	uint16 var4 = _vm->_rectYMinMax[index];
 
 	if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
 		return 0;
@@ -2137,23 +2137,23 @@ void LilliputScript::sub18B7C(int var1, int var3) {
 		return;
 
 	_word18776 = var1;
-	int index = _vm->_rulesChunk3[var1];
+	int index = _vm->_packedStringIndex[var1];
 
-	while (_vm->_rulesChunk4[index] == 91)
+	while (_vm->_packedStrings[index] == 91)
 		++index;
 
 	for (int i = 0; i < var3; i++) {
 		int tmpVal = 93;
 		while (tmpVal == 93) {
-			tmpVal = _vm->_rulesChunk4[index];
+			tmpVal = _vm->_packedStrings[index];
 			++index;
 		}
 	}
 	
-	if (_vm->_rulesChunk4[index] == 0)
+	if (_vm->_packedStrings[index] == 0)
 		return;
 
-	sub18A56(&_vm->_rulesChunk4[index]);
+	decodePackedText(&_vm->_packedStrings[index]);
 }
 
 void LilliputScript::OC_sub17D7F() {
@@ -2917,7 +2917,7 @@ void LilliputScript::OC_sub182EC() {
 }
 
 void LilliputScript::OC_PaletteFadeOut() {
-	debugC(1, kDebugScriptTBC, "OC_PaletteFadeOut()");
+	debugC(1, kDebugScript, "OC_PaletteFadeOut()");
 
 	_byte12A09 = 1;
 	_vm->paletteFadeOut();
@@ -2925,7 +2925,7 @@ void LilliputScript::OC_PaletteFadeOut() {
 }
 
 void LilliputScript::OC_PaletteFadeIn() {
-	debugC(1, kDebugScriptTBC, "OC_PaletteFadeIn()");
+	debugC(1, kDebugScript, "OC_PaletteFadeIn()");
 
 	_byte12A09 = 1;
 	_vm->paletteFadeIn();
@@ -3016,7 +3016,7 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	_vm->_byte15EAD = var1;
 
 	_byte12A09 = 1;
-	_word1881B = 0xFFFF;
+	_word1881B = -1;
 	OC_PaletteFadeOut();
 	_vm->_word15AC2 = 1;
 	_vm->displayVGAFile("AERIAL.GFX");
@@ -3049,9 +3049,9 @@ void LilliputScript::OC_sub1847F() {
 	int var4 = _currScript->readUint16LE();
 
 	if (_vm->_displayMap != 1) {
-		_vm->displayFunction5();
+		_vm->restoreSurfaceUnderMousePointer();
 		sub18BE6(var1 & 0xFF, var2, var4);
-		_vm->displayFunction4();
+		_vm->displayMousePointer();
 	}
 }
 
@@ -3069,16 +3069,16 @@ void LilliputScript::sub18BE6(byte var1, int var2, int var4) {
 }
 
 void LilliputScript::OC_displayVGAFile() {
-	debugC(1, kDebugScriptTBC, "OC_displayVGAFile()");
+	debugC(1, kDebugScript, "OC_displayVGAFile()");
 
 	_byte12A09 = 1;
-	OC_PaletteFadeOut();
+	_vm->paletteFadeOut();
 	int curWord = _currScript->readUint16LE();
-	int index = _vm->_rulesChunk3[curWord];
-	Common::String fileName = Common::String((const char *)&_vm->_rulesChunk4[index]);
-	_word1881B = 0xFFFF;
+	int index = _vm->_packedStringIndex[curWord];
+	Common::String fileName = Common::String((const char *)&_vm->_packedStrings[index]);
+	_word1881B = -1;
 	_vm->displayVGAFile(fileName);
-	OC_PaletteFadeIn();
+	_vm->paletteFadeIn();
 }
 
 void LilliputScript::OC_sub184D7() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 6699bb6..07db0a9 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -130,7 +130,7 @@ private:
 	void sub16C86(int index, byte *buf);
 	void sub16C5C(int index, byte var3);
 	void sub17D40(bool &forceReturnFl);
-	void sub18A56(byte *buf);
+	void decodePackedText(char *buf);
 	void sub18B3C(int var);
 	void sub18BE6(byte var1, int var2, int var4);
 	byte *getMapPtr(Common::Point val);


Commit: e1f6fe2226d4825e70025872c00054efbafee0c2
    https://github.com/scummvm/scummvm/commit/e1f6fe2226d4825e70025872c00054efbafee0c2
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/sound.cpp
    engines/lilliput/sound.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 0649289..ec45493 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -340,11 +340,10 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 	}
 }
 
-// display mouse cursor, if any
-void LilliputEngine::displayFunction1(byte *buf, int var1, Common::Point pos) {
-	debugC(2, kDebugEngineTBC, "displayFunction1(buf, %d, %d, %d)", var1, pos.x, pos.y);
+void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point pos) {
+	debugC(2, kDebugEngine, "display16x16IndexedBuf(buf, %d, %d, %d)", index, pos.x, pos.y);
 
-	int index1 = ((var1 & 0xFF) << 8) + (var1 >> 8);
+	int index1 = ((index & 0xFF) << 8) + (index >> 8);
 	byte *newBuf = &buf[index1];
 
 	int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
@@ -362,10 +361,10 @@ void LilliputEngine::displayFunction1(byte *buf, int var1, Common::Point pos) {
 	_system->updateScreen();
 }
 
-void LilliputEngine::displayFunction1a(byte *buf, Common::Point pos) {
-	debugC(2, kDebugEngineTBC, "displayFunction1a(buf, %d, %d)", pos.x, pos.y);
+void LilliputEngine::display16x16Buf(byte *buf, Common::Point pos) {
+	debugC(2, kDebugEngine, "display16x16Buf(buf, %d, %d)", pos.x, pos.y);
 
-	displayFunction1(buf, 0, pos);
+	display16x16IndexedBuf(buf, 0, pos);
 }
 
 void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
@@ -405,7 +404,7 @@ void LilliputEngine::displayMousePointer() {
 
 		_savedSurfaceUnderMousePos = _mouseDisplayPos;
 		SaveSurfaceUnderMouseCursor(_savedSurfaceUnderMouse, _mouseDisplayPos);
-		displayFunction1(_bufferIdeogram, _word15AC2 + 80, _mouseDisplayPos);
+		display16x16IndexedBuf(_bufferIdeogram, _word15AC2 + 80, _mouseDisplayPos);
 
 		_skipDisplayFlag1 = 1;
 		_skipDisplayFlag2 = 0;
@@ -417,7 +416,7 @@ void LilliputEngine::restoreSurfaceUnderMousePointer() {
 
 	if ((_skipDisplayFlag1 != 0) && (_skipDisplayFlag2 != 1)) {
 		_skipDisplayFlag2 = 1;
-		displayFunction1a(_savedSurfaceUnderMouse, _savedSurfaceUnderMousePos);
+		display16x16Buf(_savedSurfaceUnderMouse, _savedSurfaceUnderMousePos);
 		_skipDisplayFlag1 = 0;
 		_skipDisplayFlag2 = 0;
 	}
@@ -467,7 +466,7 @@ void LilliputEngine::displayInterfaceHotspots() {
 	int tmpVal;
 	for (index = 0; index < _word12F68_ERULES; index++) {
 		tmpVal = ((_scriptHandler->_array122E9[index] << 2) + (_scriptHandler->_array122E9[index] << 4)) & 0xFF;
-		displayFunction1(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
+		display16x16IndexedBuf(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
 	}
 
 	displayMousePointer();
@@ -841,7 +840,7 @@ void LilliputEngine::paletteFadeOut() {
 }
 
 void LilliputEngine::paletteFadeIn() {
-	debugC(2, kDebugEngineTBC, "paletteFadeIn()");
+	debugC(2, kDebugEngine, "paletteFadeIn()");
 
 	byte palette[768];
 	for (int fade = 8; fade <= 256;	fade += 8) {
@@ -1683,7 +1682,7 @@ void LilliputEngine::sub16626() {
 				result = sub1675D(index, var1);
 				break;
 			case 11:
-				result = sub16729(index);
+				result = sub16729(index, var1);
 				break;
 			case 12:
 				result = sub16799(index, var1);
@@ -1754,13 +1753,12 @@ byte LilliputEngine::sub16722(int index, Common::Point var1) {
 	return 2;
 }
 
-byte LilliputEngine::sub16729(int index) {
-	debugC(2, kDebugEngineTBC, "sub16729(%d)", index);
+byte LilliputEngine::sub16729(int index, Common::Point var1) {
+	debugC(2, kDebugEngineTBC, "sub16729(%d, %d - %d)", index, var1.x, var1.y);
 
-	int arg1 = index | 0xFF00;
-	Common::Point pos1 = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
-	Common::Point pos2 = _scriptHandler->_viewportPos;
-	_soundHandler->contentFct2(); // TODO: add arg pos1 and pos2
+	int param4x = ((index | 0xFF00) >> 8);
+	int param1 = var1.y;
+	_soundHandler->contentFct2(param1, _scriptHandler->_viewportPos, Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]), Common::Point(param4x, 0));
 	return 2;
 }
 
@@ -2267,7 +2265,7 @@ void LilliputEngine::displayHeroismIndicator() {
 }
 
 void LilliputEngine::pollEvent() {
-	debugC(2, kDebugEngineTBC, "pollEvent()");
+	debugC(2, kDebugEngine, "pollEvent()");
 
 	Common::Event event;
 	while (_system->getEventManager()->pollEvent(event)) {
@@ -2722,8 +2720,7 @@ void LilliputEngine::initialize() {
 
 	for (int i = 0; i < 4; i++) {
 		_arr18560[i]._field0 = 0;
-		_arr18560[i]._field1 = 0;
-		_arr18560[i]._field3 = 0;
+		_arr18560[i]._field1 = Common::Point(0, 0);
 		for (int j = 0; j < 8; j ++)
 			_arr18560[i]._field5[j] = 0;
 	}
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index a1d683c..b521c08 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -70,8 +70,7 @@ struct LilliputGameDescription;
 
 struct struct18560 {
 	byte _field0;
-	int16 _field1;
-	int16 _field3;
+	Common::Point _field1;
 	int16 _field5[8];
 };
 
@@ -220,8 +219,8 @@ public:
 	void newInt8();
 	void update();
 
-	void displayFunction1(byte *buf, int var1, Common::Point pos);
-	void displayFunction1a(byte *buf, Common::Point pos);
+	void display16x16IndexedBuf(byte *buf, int var1, Common::Point pos);
+	void display16x16Buf(byte *buf, Common::Point pos);
 	void SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos);
 	void displayFunction3(int var1, int var2, int var4);
 	void displayMousePointer();
@@ -305,7 +304,7 @@ public:
 	void sub16B31(int index, int val);
 	void sub16B8F(int index, int x, int y, int flag);
 	byte sub1675D(int index, Common::Point var1);
-	byte sub16729(int index);
+	byte sub16729(int index, Common::Point var1);
 	byte sub166F7(int index, Common::Point var1, int tmpVal);
 	void sub1693A(int index);
 
@@ -341,6 +340,8 @@ public:
 	byte _numCharactersToDisplay;
 	byte _byte16C9F;
 	int _word10804;
+	bool _shouldQuit;
+
 
 	void pollEvent();
 	void sub170EE(int index);
@@ -357,7 +358,6 @@ public:
 
 protected:
 	Common::EventManager *_eventMan;
-	bool _shouldQuit;
 	int _lastTime;
 
 	// Engine APIs
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 17f6f6a..2dfdf06 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -957,12 +957,12 @@ void LilliputScript::runMenuScript(ScriptStream script) {
 }
 
 void LilliputScript::sub185ED(byte index, byte subIndex) {
-	debugC(2, kDebugScriptTBC, "sub185ED");
+	debugC(2, kDebugScript, "sub185ED(%d, %d)", index, subIndex);
 
 	if (_vm->_arr18560[index]._field0 != 1)
 		return;
 
-	_vm->displayFunction1(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[subIndex], Common::Point(_vm->_arr18560[index]._field1, _vm->_arr18560[index]._field3));
+	_vm->display16x16IndexedBuf(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[subIndex], _vm->_arr18560[index]._field1);
 }
 
 byte LilliputScript::compareValues(byte var1, int oper, int var2) {
@@ -3086,7 +3086,7 @@ void LilliputScript::OC_sub184D7() {
 }
 
 void LilliputScript::OC_displayTitleScreen() {
-	debugC(1, kDebugScriptTBC, "OC_displayTitleScreen()");
+	debugC(1, kDebugScript, "OC_displayTitleScreen()");
 
 	_vm->_byte184F4 = (_currScript->readUint16LE() & 0xFF);
 	_vm->_sound_byte16F06 = _vm->_byte184F4;
@@ -3098,7 +3098,7 @@ void LilliputScript::OC_displayTitleScreen() {
 	_vm->_mouseButton = 0;
 	_vm->_byte16F09 = 0;
 
-	for (;;) {
+	while(!_vm->_shouldQuit) {
 		sub185B4_display();
 		_vm->update();
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
@@ -3146,16 +3146,16 @@ void LilliputScript::OC_sub1864D() {
 }
 
 void LilliputScript::OC_initArr18560() {
-	debugC(1, kDebugScriptTBC, "OC_initArr18560()");
+	debugC(1, kDebugScript, "OC_initArr18560()");
 
-	int curWord = _currScript->readUint16LE();
-	assert (curWord < 4);
-	_vm->_arr18560[curWord]._field0 = 1;
-	_vm->_arr18560[curWord]._field1 = _currScript->readUint16LE();
-	_vm->_arr18560[curWord]._field3 = _currScript->readUint16LE();
+	int index = _currScript->readUint16LE();
+	assert (index < 4);
+	_vm->_arr18560[index]._field0 = 1;
+	_vm->_arr18560[index]._field1.x = _currScript->readSint16LE();
+	_vm->_arr18560[index]._field1.y = _currScript->readSint16LE();
 
 	for (int i = 0; i < 8; i++)
-		_vm->_arr18560[curWord]._field5[i] = _currScript->readUint16LE();
+		_vm->_arr18560[index]._field5[i] = _currScript->readSint16LE();
 }
 
 void LilliputScript::OC_sub18678() {
@@ -3184,15 +3184,10 @@ void LilliputScript::OC_sub186E5_snd() {
 	int index = getValue1();
 	assert(index < 40);
 
-	byte var4h = 0xFF;
-	byte var4l = (index & 0xFF);
-	byte var3h = _array16123PosX[index];
-	byte var3l = _array1614BPosY[index];
-	byte var2h = (_viewportPos.x & 0xFF);
-	byte var2l = (_viewportPos.y & 0xFF);
-	int var1 = _currScript->readUint16LE();
-
-	_vm->_soundHandler->contentFct2();
+	Common::Point var4 = Common::Point(0xFF, index & 0xFF);
+	int var1 = (_currScript->readUint16LE() & 0xFF);
+	
+	_vm->_soundHandler->contentFct2(var1, _viewportPos, Common::Point(_array16123PosX[index], _array1614BPosY[index]), var4);
 }
 
 void LilliputScript::OC_sub1870A_snd() {
@@ -3203,7 +3198,7 @@ void LilliputScript::OC_sub1870A_snd() {
 	Common::Point var2 = _viewportPos;
 	int var1 = (_currScript->readUint16LE() & 0xFF);
 
-	_vm->_soundHandler->contentFct2();
+	_vm->_soundHandler->contentFct2(var1, var2, var3, var4);
 }
 
 void LilliputScript::OC_sub18725_snd() {
@@ -3229,13 +3224,15 @@ void LilliputScript::OC_sub1873F_snd() {
 }
 
 void LilliputScript::OC_sub18746_snd() {
-	debugC(1, kDebugScriptTBC, "OC_sub18746_snd()");
+	debugC(1, kDebugScript, "OC_sub18746_snd()");
 
-	int var4 = -1;
-	int var2 = (_viewportPos.x << 8) + _viewportPos.y;
-	int var1 = _currScript->readUint16LE() & 0xFF;
+	Common::Point var4 = Common::Point(-1, -1);
+	Common::Point var2 = _viewportPos;
+	int var1 = _currScript->readSint16LE() & 0xFF;
+	warning("OC_sub18746_snd: unknown value for var3");
+	Common::Point var3 = Common::Point(-1, -1);
 
-	_vm->_soundHandler->contentFct2();
+	_vm->_soundHandler->contentFct2(var1, var2, var3, var4);
 }
 
 void LilliputScript::OC_sub1875D_snd() {
diff --git a/engines/lilliput/sound.cpp b/engines/lilliput/sound.cpp
index 571191f..c96c05f 100644
--- a/engines/lilliput/sound.cpp
+++ b/engines/lilliput/sound.cpp
@@ -42,8 +42,8 @@ void LilliputSound::contentFct1() {
 	debugC(1, kDebugSound, "contentFct1()");
 }
 
-void LilliputSound::contentFct2() {
-	debugC(1, kDebugSound, "contentFct2()");
+void LilliputSound::contentFct2(int var1, Common::Point var2, Common::Point var3, Common::Point var4) {
+	debugC(1, kDebugSound, "contentFct2(%d, %d - %d, %d - %d, %d - %d)", var1, var2.x, var2.y, var3.x, var3.y, var4.x, var4.y);
 }
 
 void LilliputSound::contentFct3() {
diff --git a/engines/lilliput/sound.h b/engines/lilliput/sound.h
index c4f2126..756dad1 100644
--- a/engines/lilliput/sound.h
+++ b/engines/lilliput/sound.h
@@ -34,7 +34,7 @@ public:
 
 	void contentFct0();
 	void contentFct1();
-	void contentFct2();
+	void contentFct2(int var1, Common::Point var2, Common::Point var3, Common::Point var4);
 	void contentFct3();
 	void contentFct4();
 	void contentFct5();


Commit: aedc95231ddab06af6cb15d75c8cbccdcb80e0c4
    https://github.com/scummvm/scummvm/commit/aedc95231ddab06af6cb15d75c8cbccdcb80e0c4
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ec45493..f436466 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -472,8 +472,8 @@ void LilliputEngine::displayInterfaceHotspots() {
 	displayMousePointer();
 }
 
-void LilliputEngine::displayFunction9() {
-	debugC(2, kDebugEngineTBC, "displayFunction9()");
+void LilliputEngine::displayLandscape() {
+	debugC(2, kDebugEngine, "displayLandscape()");
 
 	memcpy(_buffer2_45k, _buffer3_45k, 45056);
 
@@ -484,12 +484,11 @@ void LilliputEngine::displayFunction9() {
 	for (int i = 0; i < 8; i++) {
 		for (int j = 0; j < 8 ; j++) {
 			var2 = (j << 8) + i;
-			displayFunction13(_buffer2_45k, _bufferIsoMap[var1 + index], var2, 0);
+			displayIsometricBlock(_buffer2_45k, _bufferIsoMap[var1 + index], var2, 0);
 			index += 4;
 		}
 		index += 224;
 	}
-
 }
 
 // Display dialog bubble
@@ -595,7 +594,7 @@ void LilliputEngine::displayFunction12() {
 	displayFunction6();
 	displayFunction7();
 	displayInterfaceHotspots();
-	displayFunction9();
+	displayLandscape();
 	displayFunction15();
 	displayFunction14();
 
@@ -603,9 +602,9 @@ void LilliputEngine::displayFunction12() {
 	free(tmpBuf);
 }
 
-void LilliputEngine::displayFunction13(byte *buf, int var1, int var2, int var3) {
-	debugC(1, kDebugEngineTBC, "displayFunction13(buf, %d, %d, %d)", var1, var2, var3);
-	
+void LilliputEngine::displayIsometricBlock(byte *buf, int var1, int var2, int var3) {
+	debugC(1, kDebugEngine, "displayIsometricBlock(buf, %d, %d, %d)", var1, var2, var3);
+
 	byte tmpByte1 = ((7 + (var2 >> 8) - (var2 & 0xFF)) << 4) & 0xFF;
 	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >> 7) ) << 3) & 0xFF;
 
@@ -768,7 +767,7 @@ void LilliputEngine::displayFunction15() {
 				int var1 = map[1];
 				if (_rulesChunk9[var1] != 128)
 					var1 += _scriptHandler->_byte12A04;
-				displayFunction13(_buffer1_45k, var1, tmpVal, 1 << 8);
+				displayIsometricBlock(_buffer1_45k, var1, tmpVal, 1 << 8);
 			}
 			renderCharacters(map, Common::Point(j, i));
 
@@ -776,7 +775,7 @@ void LilliputEngine::displayFunction15() {
 				int var1 = map[2];
 				if (_rulesChunk9[var1] != 128)
 					var1 += _scriptHandler->_byte12A04;
-				displayFunction13(_buffer1_45k, var1, tmpVal, 2 << 8);
+				displayIsometricBlock(_buffer1_45k, var1, tmpVal, 2 << 8);
 			}
 			map += 4;
 		}
@@ -1242,7 +1241,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 		_scriptHandler->_viewportPos.x += dx;
 		_scriptHandler->_viewportPos.y += dy;
 		
-		displayFunction9();
+		displayLandscape();
 		displayFunction15();
 		displayFunction14();
 
@@ -1271,17 +1270,16 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 	}
 
 	int index = _charactersToDisplay[_currentDisplayCharacter];
-	int displayX = _characterDisplayX[index];
-	int displayY = _characterDisplayY[index];
+	Common::Point characterPos = Common::Point(_characterDisplayX[index], _characterDisplayY[index]);
 
 	if (index == _scriptHandler->_word1881B)
-		sub1546F(displayX, displayY);
+		sub1546F(characterPos);
 
 	if (_byte16552 != 1) {
-		int flag = _characterDirectionArray[index];
-		int frame = _characterFrameArray[index];
+		byte flag = _characterDirectionArray[index];
+		int16 frame = _characterFrameArray[index];
 
-		if (frame != 0xFFFF) {
+		if (frame != -1) {
 			frame += _scriptHandler->_array10AB1[index];
 			if ((flag & 1) == 1)
 				frame += _spriteSizeArray[index];
@@ -1292,7 +1290,7 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 				frame = -frame;
 			}
 
-			displayCharacter(frame, Common::Point(displayX, displayY), flag);
+			displayCharacter(frame, characterPos, flag);
 		}
 	}
 
@@ -1302,11 +1300,11 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 	renderCharacters(buf, pos);
 }
 
-void LilliputEngine::sub1546F(byte displayX, byte displayY) {
-	debugC(2, kDebugEngineTBC, "sub1546F(%d, %d)", displayX, displayY);
+void LilliputEngine::sub1546F(Common::Point displayPos) {
+	debugC(2, kDebugEngineTBC, "sub1546F(%d, %d)", displayPos.x, displayPos.y);
 	
-	int orgX = displayX + 8;
-	int orgY = displayY;
+	int orgX = displayPos.x + 8;
+	int orgY = displayPos.y;
 	int var2 = 0;
 	
 	int x = orgX;
@@ -1539,7 +1537,7 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	if (var2 == -1)
 		return 1;
 
-	int _word16A74 = var2; // useless?
+//	int _word16A74 = var2; // useless?
 
 	var1h = _word16937Pos.x;
 	var1l = _word16937Pos.y;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index b521c08..870ebcb 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -155,7 +155,7 @@ public:
 	int16 _characterPositionX[40];
 	int16 _characterPositionY[40];
 	char _characterPositionAltitude[40];
-	int _characterFrameArray[40];
+	int16 _characterFrameArray[40];
 	byte _rulesBuffer2_5[40];
 	byte _rulesBuffer2_6[40];
 	byte _rulesBuffer2_7[40];
@@ -228,11 +228,11 @@ public:
 	void displayFunction6();
 	void displayFunction7();
 	void displayInterfaceHotspots();
-	void displayFunction9();
+	void displayLandscape();
 	void displayFunction10();
 	void displayFunction11(byte *buf);
 	void displayFunction12();
-	void displayFunction13(byte *buf, int var1, int var2, int var3);
+	void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
 	void displayFunction14();
 	void displayFunction15();
 	void displayFunction16();
@@ -287,7 +287,7 @@ public:
 	int sub13240(Common::Point mousePos, int var3, int var4);
 	void sub131B2(Common::Point pos, bool &forceReturnFl);
 	void sub131FC(Common::Point pos);
-	void sub1546F(byte displayX, byte displayY);
+	void sub1546F(Common::Point displayPos);
 	void sub15498(byte x, byte y, int var2);
 	void sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex);
 	void sub15F31(bool &forceReturnFl);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 2dfdf06..821d701 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -98,7 +98,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub1740A();
 		break;
 	case 0x3:
-		return OC_sub17434();
+		return OC_compareCharacterId();
 		break;
 	case 0x4:
 		return OC_sub17468();
@@ -563,7 +563,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_checkCharacterGoalPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_comparePos", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 	{ "OC_sub1740A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub17434", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
+	{ "OC_compareCharacterId", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
 	{ "OC_sub17468", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_getRandom", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_for", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
@@ -965,18 +965,25 @@ void LilliputScript::sub185ED(byte index, byte subIndex) {
 	_vm->display16x16IndexedBuf(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[subIndex], _vm->_arr18560[index]._field1);
 }
 
-byte LilliputScript::compareValues(byte var1, int oper, int var2) {
-	debugC(2, kDebugScriptTBC, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
+byte LilliputScript::compareValues(int var1, int oper, int var2) {
+	debugC(2, kDebugScript, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
 
 	switch (oper & 0xFF) {
 	case '<':
-		return (var1 < var2);
+		if (var1 < var2)
+			return 1;
+		break;
 	case '>':
-		return (var1 > var2);
+		if (var1 > var2)
+			return 1;
+		break;
 	default:
-		return (var1 == var2);
+		if (var1 == var2)
+			return 1;
 		break;
 	}
+
+	return 0;
 }
 
 void LilliputScript::computeOperation(byte *bufPtr, int oper, int var3) {
@@ -1274,7 +1281,7 @@ void LilliputScript::sub18B3C(int var) {
 }
 
 int16 LilliputScript::getValue1() {
-	debugC(2, kDebugScriptTBC, "getValue1()");
+	debugC(2, kDebugScript, "getValue1()");
 
 	int16 curWord = _currScript->readUint16LE();
 	if (curWord < 1000)
@@ -1366,7 +1373,7 @@ void LilliputScript::sub130B6() {
 }
 
 byte *LilliputScript::getCharacterVariablePtr() {
-	debugC(2, kDebugScriptTBC, "getCharacterVariablePtr()");
+	debugC(2, kDebugScript, "getCharacterVariablePtr()");
 
 	int8 tmpVal = (int8) (getValue1() & 0xFF);
 	int index = tmpVal * 32;
@@ -1420,9 +1427,8 @@ byte LilliputScript::OC_sub1740A() {
 	}
 }
 
-// Compare field0 with value -> character id?
-byte LilliputScript::OC_sub17434() {
-	debugC(1, kDebugScriptTBC, "OC_sub17434()");
+byte LilliputScript::OC_compareCharacterId() {
+	debugC(1, kDebugScript, "OC_compareCharacterId()");
 
 	byte *tmpArr = getCharacterVariablePtr();
 	byte var1 = tmpArr[0];
@@ -2410,7 +2416,7 @@ void LilliputScript::OC_sub17C0E() {
 
 	if (b2 == 0) {
 		_byte12A09 = 1;
-		_vm->displayFunction9();
+		_vm->displayLandscape();
 		_byte12A09 = 0;
 	}
 }
@@ -2802,7 +2808,7 @@ void LilliputScript::OC_sub1810A() {
 	_viewportCharacterTarget = 0xFFFF;
 	_viewportPos = getPosFromScript();
 
-	_vm->displayFunction9();
+	_vm->displayLandscape();
 	_vm->displayFunction15();
 }
 
@@ -2933,15 +2939,15 @@ void LilliputScript::OC_PaletteFadeIn() {
 }
 
 void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
-	debugC(1, kDebugScriptTBC, "OC_loadAndDisplayCUBESx_GFX()");
+	debugC(1, kDebugScript, "OC_loadAndDisplayCUBESx_GFX()");
 
-	int curWord = _currScript->readUint16LE();
+	int curWord = (_currScript->readUint16LE() & 0xFF);
 	assert((curWord >= 0) && (curWord <= 9));
 	Common::String fileName = Common::String::format("CUBES%d.GFX", curWord);
-	_byte10806 = curWord + 0x30;
+	_byte10806 = curWord + 0x30; // Useless?
 
 	_vm->_bufferCubegfx = _vm->loadVGA(fileName, 61440, false);
-	_vm->displayFunction9();
+	_vm->displayLandscape();
 	_vm->displayFunction15();
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 07db0a9..ca61d2b 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -64,7 +64,7 @@ public:
 	char _array16123PosX[40];
 	char _array1614BPosY[40];
 	byte _array12811[40];
-	byte _array10AB1[40];
+	char _array10AB1[40];
 	byte _array122FD[20];
 	byte _array122C1[40];
 	byte _array10A39[40];
@@ -146,14 +146,14 @@ private:
 	Common::Point getPosFromScript();
 
 	byte *getCharacterVariablePtr();
-	byte compareValues(byte var1, int oper, int var2);
+	byte compareValues(int var1, int oper, int var2);
 	void computeOperation(byte *bufPtr, int oper, int var2);
 
 	//Opcodes Type 1
 	byte OC_checkCharacterGoalPos();
 	byte OC_comparePos();
 	byte OC_sub1740A();
-	byte OC_sub17434();
+	byte OC_compareCharacterId();
 	byte OC_sub17468();
 	byte OC_getRandom();
 	byte OC_for();


Commit: 872c9ea2fc6caddde9753df545f3572b01ac5e81
    https://github.com/scummvm/scummvm/commit/872c9ea2fc6caddde9753df545f3572b01ac5e81
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: double check some more function, renaming

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index f436466..8d189cd 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -590,7 +590,6 @@ void LilliputEngine::displayFunction12() {
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
 
-
 	displayFunction6();
 	displayFunction7();
 	displayInterfaceHotspots();
@@ -659,7 +658,7 @@ void LilliputEngine::restoreMapPoints() {
 void LilliputEngine::displayCharactersOnMap() {
 	debugC(2, kDebugEngineTBC, "displayCharactersOnMap()");
 
-	sub16217();
+	moveCharacters();
 	restoreSurfaceUnderMousePointer();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
@@ -676,8 +675,8 @@ void LilliputEngine::displayCharactersOnMap() {
 	displayMousePointer();
 }
 
-void LilliputEngine::sub16217() {
-	debugC(2, kDebugEngineTBC, "sub16217()");
+void LilliputEngine::moveCharacters() {
+	debugC(2, kDebugEngine, "moveCharacters()");
 
 	_numCharactersToDisplay = 0;
 	int index = _numCharacters - 1;
@@ -711,8 +710,8 @@ void LilliputEngine::sub16217() {
 			_characterPositionY[i] = var4;
 		}
 
-		_scriptHandler->_array16123PosX[i] = _characterPositionX[i] >> 3;
-		_scriptHandler->_array1614BPosY[i] = _characterPositionY[i] >> 3;
+		_scriptHandler->_array16123PosX[i] = (_characterPositionX[i] >> 3);
+		_scriptHandler->_array1614BPosY[i] = (_characterPositionY[i] >> 3);
 		_characterRelativePositionX[i] = 0xFF;
 		_characterRelativePositionY[i] = 0xFF;
 		_characterDisplayX[i] = 0xFF;
@@ -737,7 +736,7 @@ void LilliputEngine::sub16217() {
 }
 
 void LilliputEngine::setNextDisplayCharacter(int var1) {
-	debugC(2, kDebugEngineTBC, "setNextDisplayCharacter(%d)", var1);
+	debugC(2, kDebugEngine, "setNextDisplayCharacter(%d)", var1);
 
 	byte charNum = var1 & 0xFF;
 	if ( charNum < _numCharactersToDisplay) {
@@ -751,7 +750,7 @@ void LilliputEngine::setNextDisplayCharacter(int var1) {
 void LilliputEngine::displayFunction15() {
 	debugC(2, kDebugEngineTBC, "displayFunction15()");
 
-	sub16217();
+	moveCharacters();
 	_currentDisplayCharacter = 0;
 	setNextDisplayCharacter(0);
 
@@ -964,7 +963,7 @@ void LilliputEngine::sub15F31(bool &forceReturnFl) {
 	sub130B6();
 	displayFunction12();
 	_scriptHandler->_heroismLevel = 0;
-	sub16217();
+	moveCharacters();
 	paletteFadeIn();
 	forceReturnFl = true;
 }
@@ -1135,14 +1134,13 @@ void LilliputEngine::displayChar(int index, int var1) {
 }
 
 void LilliputEngine::sortCharacters() {
-	debugC(2, kDebugEngineTBC, "sortCharacters()");
+	debugC(2, kDebugEngine, "sortCharacters()");
 
 	if (_numCharactersToDisplay <= 1)
 		return;
 
-	int var3;
-	for (int var4 = _numCharactersToDisplay - 1; var4 != 0; var4--) {
-		var3 = 0;
+	for (int var4 = _numCharactersToDisplay - 1; var4 > 0; var4--) {
+		bool found = false;
 
 		for (int var2 = 0; var2 < var4; var2++) {
 			int index1 = _charactersToDisplay[var2];
@@ -1169,10 +1167,10 @@ void LilliputEngine::sortCharacters() {
 			byte tmpVal = _charactersToDisplay[var2];
 			_charactersToDisplay[var2] = _charactersToDisplay[var2 + 1];
 			_charactersToDisplay[var2 + 1] = tmpVal;
-			++var3;
+			found = true;
 		}
 
-		if (var3 == 0)
+		if (!found)
 			return;
 	}
 }
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 870ebcb..62ed4ba 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -346,7 +346,7 @@ public:
 	void pollEvent();
 	void sub170EE(int index);
 	void sub130DD();
-	void sub16217();
+	void moveCharacters();
 	void setNextDisplayCharacter(int var1);
 	void handleGameScripts();
 


Commit: 48d59dfd2ea9086462740a728f8b877f875c5ff3
    https://github.com/scummvm/scummvm/commit/48d59dfd2ea9086462740a728f8b877f875c5ff3
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Rewrite sub1818B

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 821d701..fe09fac 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -61,7 +61,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	}
 
 	for (int i = 0; i < 32; i++)
-		_array1813B[i] = 0;
+		_array1813BPos[i] = Common::Point(0, 0);
 
 	for (int i = 0; i < 40; i++) {
 		_characterScriptEnabled[i] = 1;
@@ -2826,25 +2826,25 @@ void LilliputScript::OC_sub1817F() {
 	
 	int b1 = var1 & 0xFF;
 	int b2 = var2 & 0xFF;
-	sub1818B(b1,b2);
+	sub1818B(Common::Point(b1, b2));
 }
 
 //TODO checkme: parameter order is maybe wrong
-void LilliputScript::sub1818B(int b1, int b2) {
-	debugC(2, kDebugScriptTBC, "sub1818B(%d, %d)", b1, b2);
+void LilliputScript::sub1818B(Common::Point pos) {
+	debugC(2, kDebugScriptTBC, "sub1818B(%d - %d)", pos.x, pos.y);
 	for (int i = 0; i <  _vm->_word1817B; i++) {
-		if ((_array1813B[i] >> 8) == b2 ) {
-			b2 += _array1813B[i] & 0xFF;
-			if (b2 > 0xFF) {
-				b2 = 0xFF;
-				++b1;
-			}
-			_array1813B[i] = (b1 << 8) + b2;
+		if (_array1813BPos[i].x == pos.x) {
+			pos.y += _array1813BPos[i].y;
+			if (pos.y > 0xFF)
+				pos.y = 0xFF;
+
+			_array1813BPos[i] = pos;
 			return;
 		}
 	}
 
-	_array1813B[_vm->_word1817B++] = (b1 << 8) + b2;
+	_array1813BPos[_vm->_word1817B] = pos;
+	++_vm->_word1817B;
 }
 
 //TODO checkme: case 0x2D is dubious
@@ -2874,8 +2874,7 @@ void LilliputScript::OC_sub181BB() {
 
 	int a = (_currScript->readUint16LE() * c) + (c & 0xFF);
 	b = (b & 0xFF00) + a;
-	sub1818B(b & 0xFF, b >> 8);
-
+	sub1818B(Common::Point(b >> 8, b & 0xFF));
 }
 
 void LilliputScript::OC_sub18213() {
@@ -2887,9 +2886,9 @@ void LilliputScript::OC_sub18213() {
 	int maxItem = var1 & 0xFF;
 
 	for (int i = 0; i < _vm->_word1817B; i++) {
-		if ((_array1813B[i] & 0xFF) > maxValue) {
-			maxValue = _array1813B[i] & 0xFF;
-			maxItem = _array1813B[i] >> 8;
+		if (_array1813BPos[i].y > maxValue) {
+			maxValue = _array1813BPos[i].y;
+			maxItem = _array1813BPos[i].x;
 		}
 	}
 	sub1823E(_vm->_currentScriptCharacter, maxItem, _vm->_currentCharacterVariables);
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index ca61d2b..92e092a 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -82,7 +82,7 @@ public:
 	Common::Point _array12311[640];
 	byte _array128EF[40];
 	byte _array12839[40];
-	int _array1813B[32];
+	Common::Point _array1813BPos[32];
 
 	void sub130B6();
 
@@ -264,7 +264,7 @@ private:
 	void OC_sub1810A();
 	void OC_sub1812D();
 	void OC_sub1817F();
-	void sub1818B(int b1, int b2);
+	void sub1818B(Common::Point pos);
 	void OC_sub181BB();
 	void OC_sub18213();
 	void OC_sub18252();


Commit: f4732601ec7f7aeae40d76a89401ebd6f7348d46
    https://github.com/scummvm/scummvm/commit/f4732601ec7f7aeae40d76a89401ebd6f7348d46
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Remove useless buffers, renaming

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8d189cd..09721b6 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -148,7 +148,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte16552 = 0;
 	_byte12FE4 = 0xFF;
 	_byte12FE3 = 0;
-	_byte16F08 = 0;	
+	_byte16F08 = 0;
 	_byte16C9F = 0;
 
 	_currentScriptCharacter = 0;
@@ -260,7 +260,7 @@ void LilliputEngine::newInt8() {
 	}
 	--_byte12A06;
 	// TODO: check 'out 20h, 20h'
-	
+
 	// hack for the title stars because _int8installed is not set at the good place for the moment
 	//if (!_int8installed)
 	//	return;
@@ -304,7 +304,7 @@ Common::Platform LilliputEngine::getPlatform() const {
 void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 	debugC(2, kDebugEngineTBC, "displayCharacter(%d, %d - %d, %d)", index, pos.x, pos.y, flags);
 
-	byte *buf = _buffer1_45k + (pos.y << 8) + pos.x;
+	byte *buf = _savedSurfaceGameArea1 + (pos.y << 8) + pos.x;
 
 	byte *src = _bufferMen;
 	if (index < 0) {
@@ -330,7 +330,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 		// Sprite mirror
 		for (int y = 0; y < 16; y++) {
 			for (int x = 0; x < 16; x++) {
-				// May need a hack of 1 pixel 
+				// May need a hack of 1 pixel
 				if (src[15 - x] != 0)
 					buf[x] = src[15 - x];
 			}
@@ -422,38 +422,52 @@ void LilliputEngine::restoreSurfaceUnderMousePointer() {
 	}
 }
 
-// save game area
-void LilliputEngine::displayFunction6() {
-	debugC(2, kDebugEngineTBC, "displayFunction6()");
+void LilliputEngine::saveSurfaceGameArea() {
+	debugC(2, kDebugEngineTBC, "saveSurfaceGameArea()");
 
 	restoreSurfaceUnderMousePointer();
 
-	int index = (16 * 320) + 64;
+	int index = (16 * 320) + 64; // 5184
 	for (int i = 0; i < 176; i++) {
 		for (int j = 0; j < 256; j++)
-			_buffer3_45k[(i * 256) + j] = ((byte *)_mainSurface->getPixels())[index + j];
+			_savedSurfaceGameArea3[(i * 256) + j] = ((byte *)_mainSurface->getPixels())[index + j];
 		index += 320;
 	}
 
 	displayMousePointer();
 }
 
-// save speech zone
-void LilliputEngine::displayFunction7() {
-	debugC(2, kDebugEngineTBC, "displayFunction7()");
+void LilliputEngine::saveSurfaceSpeech() {
+	debugC(2, kDebugEngine, "saveSurfaceSpeech()");
 
 	restoreSurfaceUnderMousePointer();
 
 	int index = 66;
 	for (int i = 0; i < 16; i++) {
 		for (int j = 0; j < 252; j++)
-			_buffer10_4032[(i * 252) + j] = ((byte *)_mainSurface->getPixels())[index + j];
+			_savedSurfaceSpeech[(i * 252) + j] = ((byte *)_mainSurface->getPixels())[index + j];
 		index += 320;
 	}
 
 	displayMousePointer();
 }
 
+void LilliputEngine::restoreSurfaceSpeech() {
+	debugC(2, kDebugEngine, "restoreSurfaceSpeech()");
+
+	restoreSurfaceUnderMousePointer();
+
+	int index = 66;
+	for (int i = 0; i < 16; i++) {
+		for (int j = 0; j < 252; j++)
+			((byte *)_mainSurface->getPixels())[index + j] = _savedSurfaceSpeech[(i * 252) + j];
+		index += 320;
+	}
+
+	displayMousePointer();
+}
+
+
 void LilliputEngine::displayInterfaceHotspots() {
 	debugC(2, kDebugEngineTBC, "displayInterfaceHotspots()");
 
@@ -475,7 +489,7 @@ void LilliputEngine::displayInterfaceHotspots() {
 void LilliputEngine::displayLandscape() {
 	debugC(2, kDebugEngine, "displayLandscape()");
 
-	memcpy(_buffer2_45k, _buffer3_45k, 45056);
+	memcpy(_savedSurfaceGameArea2, _savedSurfaceGameArea3, 176 * 256); // 45056
 
 	int var1 = (_scriptHandler->_viewportPos.y >> 8) + ((_scriptHandler->_viewportPos.y & 0xFF) << 8) + (_scriptHandler->_viewportPos.x << 2);
 	int var2;
@@ -484,7 +498,7 @@ void LilliputEngine::displayLandscape() {
 	for (int i = 0; i < 8; i++) {
 		for (int j = 0; j < 8 ; j++) {
 			var2 = (j << 8) + i;
-			displayIsometricBlock(_buffer2_45k, _bufferIsoMap[var1 + index], var2, 0);
+			displayIsometricBlock(_savedSurfaceGameArea2, _bufferIsoMap[var1 + index], var2, 0);
 			index += 4;
 		}
 		index += 224;
@@ -585,17 +599,17 @@ void LilliputEngine::displayFunction12() {
 
 	restoreSurfaceUnderMousePointer();
 
-	byte *tmpBuf = loadVGA("SCREEN.GFX", 64000, true);
-	memcpy(_mainSurface->getPixels(), tmpBuf, 320*200);
+	byte *tmpBuf = loadVGA("SCREEN.GFX", 320 * 200, true);
+	memcpy(_mainSurface->getPixels(), tmpBuf, 320 * 200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
 
-	displayFunction6();
-	displayFunction7();
+	saveSurfaceGameArea();
+	saveSurfaceSpeech();
 	displayInterfaceHotspots();
 	displayLandscape();
 	displayFunction15();
-	displayFunction14();
+	displayGameArea();
 
 	displayMousePointer();
 	free(tmpBuf);
@@ -620,8 +634,8 @@ void LilliputEngine::displayIsometricBlock(byte *buf, int var1, int var2, int va
 	}
 }
 
-void LilliputEngine::displayFunction14() {
-	debugC(2, kDebugEngineTBC, "displayFunction14()");
+void LilliputEngine::displayGameArea() {
+	debugC(2, kDebugEngine, "displayGameArea()");
 
 	if (_displayMap == 1)
 		return;
@@ -629,10 +643,10 @@ void LilliputEngine::displayFunction14() {
 	if (_mouseDisplayPos.x > 48)
 		restoreSurfaceUnderMousePointer();
 
-	int index = (16 * 320) + 64;
+	int index = (16 * 320) + 64; // 5184
 	for (int i = 0; i < 176; i++) {
 		for (int j = 0; j < 256; j++)
-			((byte *)_mainSurface->getPixels())[index + j] = _buffer1_45k[(i * 256) + j];
+			((byte *)_mainSurface->getPixels())[index + j] = _savedSurfaceGameArea1[(i * 256) + j];
 		index += 320;
 	}
 
@@ -667,7 +681,7 @@ void LilliputEngine::displayCharactersOnMap() {
 			 int y = (3 * _scriptHandler->_array1614BPosY[index]) + 1;
 			 int x = (_scriptHandler->_array16123PosX[index] * 4) + 1;
 
-			 _word15E5D[index] = y * 320 + x; 
+			 _word15E5D[index] = y * 320 + x;
 			 _byte15E35[index] = buf[y * 320 + x];
 			 buf[y * 320 + x] = _scriptHandler->_array128EF[index];
 		}
@@ -729,7 +743,7 @@ void LilliputEngine::moveCharacters() {
 			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
 			_charactersToDisplay[_numCharactersToDisplay] = i;
 			++_numCharactersToDisplay;
- 		}
+		}
 	}
 
 	sortCharacters();
@@ -754,7 +768,7 @@ void LilliputEngine::displayFunction15() {
 	_currentDisplayCharacter = 0;
 	setNextDisplayCharacter(0);
 
-	memcpy(_buffer1_45k, _buffer2_45k, 45056);
+	memcpy(_savedSurfaceGameArea1, _savedSurfaceGameArea2, 176 * 256); // 45056;
 
 	int index1 = (_scriptHandler->_viewportPos.y >> 8) + ((_scriptHandler->_viewportPos.y & 0xFF) << 8) + (_scriptHandler->_viewportPos.x << 2);
 	byte *map = &_bufferIsoMap[index1];
@@ -766,7 +780,7 @@ void LilliputEngine::displayFunction15() {
 				int var1 = map[1];
 				if (_rulesChunk9[var1] != 128)
 					var1 += _scriptHandler->_byte12A04;
-				displayIsometricBlock(_buffer1_45k, var1, tmpVal, 1 << 8);
+				displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 1 << 8);
 			}
 			renderCharacters(map, Common::Point(j, i));
 
@@ -774,7 +788,7 @@ void LilliputEngine::displayFunction15() {
 				int var1 = map[2];
 				if (_rulesChunk9[var1] != 128)
 					var1 += _scriptHandler->_byte12A04;
-				displayIsometricBlock(_buffer1_45k, var1, tmpVal, 2 << 8);
+				displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 2 << 8);
 			}
 			map += 4;
 		}
@@ -802,7 +816,7 @@ void LilliputEngine::displayFunction16() {
 		scrollToViewportCharacterTarget();
 		sub189DE();
 		displayFunction15();
-		displayFunction14();
+		displayGameArea();
 		sub16626();
 		sub12F37();
 		sub16CA0();
@@ -815,6 +829,8 @@ void LilliputEngine::displayFunction16() {
 }
 
 void LilliputEngine::sub1863B() {
+	debugC(2, kDebugEngineTBC, "sub1863B()");
+
 	_arr18560[0]._field0 = 0;
 	_arr18560[1]._field0 = 0;
 	_arr18560[2]._field0 = 0;
@@ -859,7 +875,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	int dx = x2 - x1;
 	int dy = y2 - y1;
 
-	int word16DCB = 0; 
+	int word16DCB = 0;
 	int word16DCD = 0;
 	int word16DD1 = 0;
 	int word16DCF = 0;
@@ -898,7 +914,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	word16DCB += word16DCD;
 
 	int var1 = byte16DD4;
-	int count = 0; 
+	int count = 0;
 
 	while ( *isoMap == 0xFF ) {
 		if (var1 > 0) {
@@ -908,7 +924,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 			isoMap += word16DCF;
 			var1 += byte16DD4;
 		}
-		
+
 		count++;
 		if (count == dy) {
 			return 0;
@@ -922,12 +938,12 @@ void LilliputEngine::sub15F75() {
 
 	_byte129A0 = 0xFF;
 	_savedMousePosDivided = Common::Point(-1, -1);
-	byte newX = _mousePos.x >> 2; 
+	byte newX = _mousePos.x >> 2;
 	byte newY = _mousePos.y / 3;
 
 	if ((newX >= 64) || (newY >= 64))
 		return;
-	
+
 	_savedMousePosDivided = Common::Point(newX, newY);
 	_byte16F07_menuId = 5;
 }
@@ -956,7 +972,7 @@ void LilliputEngine::sub15F31(bool &forceReturnFl) {
 
 	_mouseButton = 0;
 	sub15F75();
-	
+
 	_displayMap = 0;
 	paletteFadeOut();
 	_word15AC2 = 0;
@@ -980,20 +996,20 @@ void LilliputEngine::sub16CA0() {
 
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
-			if ((index != index2 ) && 
+			if ((index != index2 ) &&
 				(_rulesBuffer2_5[index] != index2) &&
 				(_rulesBuffer2_5[index2] != index) &&
 				(_rulesBuffer2_11[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_array16123PosX[index2];
 				int d2 = _scriptHandler->_array1614BPosY[index2];
-	
+
 				if (d1 != 0xFF) {
 					int x = c1 - d1;
 					if ((x > -6) && (x < 6)) {
 						int y = c2 - d2;
 						if ((y > -6) && (y < 6)) {
 							_byte16C9F = 1;
-	
+
 							if ((c1 == d1) && (c2 == d2)) {
 								_byte16C9F = 4;
 							} else if((_rulesBuffer2_11[index] & 4) != 0) {
@@ -1007,7 +1023,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else if (_characterDirectionArray[index] == 1) {
 									if (d2 < c2) {
@@ -1017,7 +1033,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else if (_characterDirectionArray[index] == 2) {
 									if (d2 > c2) {
@@ -1027,7 +1043,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else {
 									if (d1 < c1) {
@@ -1037,7 +1053,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								}
 							}
@@ -1052,34 +1068,22 @@ void LilliputEngine::sub16CA0() {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
 				val = (val & 0xFF00) | _byte16C9F;
 			}
-			_scriptHandler->_array10B51[index2 + index * 40] = val;	
+			_scriptHandler->_array10B51[index2 + index * 40] = val;
 
 		}
 
 	}
 }
 
-void LilliputEngine::displayFunction17() {
-	debugC(2, kDebugEngineTBC, "displayFunction17()");
-
-	restoreSurfaceUnderMousePointer();
-
-	for (int i = 0; i < 16; i++)
-		for (int j = 0; j < 252; j++)
-			((byte *)_mainSurface->getPixels())[66 + (i * 320) + j] = _buffer10_4032[(252 * i) + j];
-
-	displayMousePointer();
-}
-
 void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	debugC(2, kDebugEngineTBC, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
-	
+
 	restoreSurfaceUnderMousePointer();
-	
+
 	if ((var1 & 0xFF) == 0x2D) {
 		var2 += 35;
 		var3 -= 35;
-		
+
 		if (var3 < 0) {
 			var2 += var3;
 			var3 = -var3;
@@ -1089,17 +1093,17 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	byte *vgaBuf = (byte *)_mainSurface->getPixels();
 	int tmpVal = (var3 >> 8) + ((var3 & 0xFF) << 8);
 	int vgaIndex = var2 + tmpVal + (tmpVal >> 2);
-	
+
 	if (var3 == 0)
 		++var3;
-	
+
 	for (int i = 0; i < 4; i++) {
 		for (int j = 0; j < var3; j++) {
 			vgaBuf[vgaIndex + j] = 2;
 		}
 		vgaIndex += 320;
 	}
-	
+
 	displayMousePointer();
 }
 
@@ -1145,8 +1149,8 @@ void LilliputEngine::sortCharacters() {
 		for (int var2 = 0; var2 < var4; var2++) {
 			int index1 = _charactersToDisplay[var2];
 			int index2 = _charactersToDisplay[var2 + 1];
-		
-			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2]) 
+
+			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2])
 				continue;
 
 			if (_characterRelativePositionY[index1] == _characterRelativePositionY[index2]) {
@@ -1238,10 +1242,10 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 	do {
 		_scriptHandler->_viewportPos.x += dx;
 		_scriptHandler->_viewportPos.y += dy;
-		
+
 		displayLandscape();
 		displayFunction15();
-		displayFunction14();
+		displayGameArea();
 
 		if (goalPos.x == _scriptHandler->_viewportPos.x)
 			dx = 0;
@@ -1281,7 +1285,7 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 			frame += _scriptHandler->_array10AB1[index];
 			if ((flag & 1) == 1)
 				frame += _spriteSizeArray[index];
-			
+
 			if (_array12299[index] != 0xFF) {
 				frame = _array12299[index] + 82;
 				--_array12299[index];
@@ -1300,11 +1304,11 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 
 void LilliputEngine::sub1546F(Common::Point displayPos) {
 	debugC(2, kDebugEngineTBC, "sub1546F(%d, %d)", displayPos.x, displayPos.y);
-	
+
 	int orgX = displayPos.x + 8;
 	int orgY = displayPos.y;
 	int var2 = 0;
-	
+
 	int x = orgX;
 	int y = orgY;
 	do {
@@ -1312,10 +1316,10 @@ void LilliputEngine::sub1546F(Common::Point displayPos) {
 		--x;
 		y >>= 1;
 	} while (y != 0);
-	
+
 	x = orgX + 1;
 	y = orgY >> 1;
-	
+
 	while (y != 0) {
 		sub15498(x, y, var2);
 		++x;
@@ -1325,10 +1329,10 @@ void LilliputEngine::sub1546F(Common::Point displayPos) {
 
 void LilliputEngine::sub15498(byte x, byte y, int var2) {
 	debugC(2, kDebugEngineTBC, "sub15498(%d, %d, %d)", x, y, var2);
-	
+
 	int index = x + ((var2 & 0xFF) << 8) + (var2 >> 8);
 	for (int i = 1 + y - var2; i > 0; i--) {
-		_buffer1_45k[index] = 17;
+		_savedSurfaceGameArea1[index] = 17;
 		index += 256;
 	}
 }
@@ -1339,7 +1343,7 @@ void LilliputEngine::sub189DE() {
 	if (_byte1881D != 0) {
 		--_byte1881D;
 		if (_byte1881D == 0) {
-			displayFunction17();
+			restoreSurfaceSpeech();
 			_scriptHandler->_word1881B = -1;
 		}
 	}
@@ -1404,24 +1408,24 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 
 void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngineTBC, "sub167EF(%d)", index);
-	
+
 	int word167EB = findHotspot(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
 	int word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
-	
+
 	if (word167EB == word167ED) {
 		_array109E9PosX[index] = _array10999PosX[index];
 		_array10A11PosY[index] = _array109C1PosY[index];
 		return;
 	}
-	
+
 	if (word167EB == -1) {
 		int tmpVal = reverseFindHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
 		_array109E9PosX[index] = _rulesBuffer12Pos4[tmpVal].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[tmpVal].y;
 		return;
 	}
-	
-	if ((word167ED != -1) && 
+
+	if ((word167ED != -1) &&
 		  (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
 		  (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
 		  (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
@@ -1430,18 +1434,18 @@ void LilliputEngine::sub167EF(int index) {
 		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
 	}
-	
+
 	_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
 	_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
 	int var4h = (_rectXMinMax[index] >> 8);
 	int var4l = (_rectXMinMax[index] & 0xFF);
-	
+
 	if (var4h != var4l) {
 		if (_array109E9PosX[index] == var4h) {
 			--_array109E9PosX[index];
 			return;
 		}
-		
+
 		if (_array109E9PosX[index] == var4l) {
 			++_array109E9PosX[index];
 			return;
@@ -1458,7 +1462,7 @@ void LilliputEngine::sub167EF(int index) {
 			return;
 		}
 	}
-	
+
 	// var4h == var4l
 	int mapIndex = (((_array10A11PosY[index] << 8) >> 2) + _array109E9PosX[index]) << 2;
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
@@ -1468,25 +1472,25 @@ void LilliputEngine::sub167EF(int index) {
 		--_array10A11PosY[index];
 	else if ((tmpVal & 2) != 0)
 		++_array10A11PosY[index];
-	else 
+	else
 		--_array109E9PosX[index];
-	
+
 	return;
 }
 
 void LilliputEngine::sub1693A(int index) {
 	debugC(2, kDebugEngineTBC, "sub1693A(%d)", index);
-	
+
 	static const uint16 _array1692F[4] = {4, 0xFF00, 0x100, 0xFFFC};
 
 	_word16937Pos = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
 
 	sub16A08(index);
-	
+
 	int var2 = (_characterDirectionArray[index] ^ 3);
 	_array1692B[var2] += 0xF8;
 	_byte16939 = 0;
-	
+
 	int mapIndex = ((((_word16937Pos.y << 8) >> 2) + _word16937Pos.x) << 2);
 	int subMapIndex = 0;
 	int retVal = 0;
@@ -1496,7 +1500,7 @@ void LilliputEngine::sub1693A(int index) {
 			if ((_bufferIsoMap[mapIndex + subMapIndex + 3] & 0x80) != 0) {
 				if (sub16A76(i, index) != 0)
 					_array1692B[i] += 0xEC;
-				
+
 				int tmpVal = ((_rulesBuffer2_10[index] & 7) ^ 7);
 				retVal = _rulesChunk9[_bufferIsoMap[mapIndex + subMapIndex]];
 				tmpVal &= retVal;
@@ -1518,7 +1522,7 @@ void LilliputEngine::sub1693A(int index) {
 			tmpVal = _array1692B[i];
 		}
 	}
-	
+
 	_characterDirectionArray[index] = retVal;
 }
 
@@ -1527,7 +1531,7 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 
 	static const char _array16A6C[4] = {1, 0, 0, -1};
 	static const char _array16A70[4] = {0, -1, 1, 0};
-	   
+
 	char var1h = _word16937Pos.x + _array16A6C[indexb];
 	char var1l = _word16937Pos.y + _array16A70[indexs];
 
@@ -1613,7 +1617,7 @@ void LilliputEngine::addCharToBuf(byte character) {
 
 void LilliputEngine::prepareGoldAmount(int param1) {
 	debugC(2, kDebugEngineTBC, "prepareGoldAmount(%d)", param1);
-	
+
 	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
 
 	int count;
@@ -1629,7 +1633,7 @@ void LilliputEngine::prepareGoldAmount(int param1) {
 		--count;
 
 		byte tmpVal = count + 0x30;
-		
+
 		if (i == 4)
 			addCharToBuf(tmpVal);
 		else if ((count != 0) || (!hideZeros)) {
@@ -1736,7 +1740,7 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 
 byte LilliputEngine::sub166DD(int index, Common::Point var1) {
 	debugC(2, kDebugEngineTBC, "sub166DD(%d, %d - %d)", index, var1.x, var1.y);
-	
+
 	_characterDirectionArray[index] = (var1.x & 3);
 	sub16685(index, var1);
 	return 0;
@@ -1786,7 +1790,7 @@ void LilliputEngine::sub16EBC() {
 	int index2 = 3;
 
 	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
-		int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2); 
+		int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2);
 		int var1 = (_bufferIsoMap[index2 + var2] & 0x40);
 
 		if (var1 == _array16E94[index1])
@@ -1813,7 +1817,7 @@ void LilliputEngine::sub12F37() {
 				--varPtr[0];
 				if (varPtr[0] == 1)
 					_scriptHandler->_characterScriptEnabled[index2] = 1;
-			}			
+			}
 		}
 
 		index1 += 32;
@@ -1971,7 +1975,7 @@ byte LilliputEngine::sub16675(int idx, Common::Point var1) {
 	debugC(2, kDebugEngineTBC, "sub16675(%d, %d - %d)", idx, var1.x, var1.y);
 
 	sub16685(idx, var1);
-	int index = var1.y;	
+	int index = var1.y;
 	switch (var1.x) {
 	case 0:
 		break;
@@ -2139,7 +2143,7 @@ void LilliputEngine::sub17224(int var1, int var4) {
 		sub17264(var1, var4);
 		return;
 	}
-	
+
 	if (type == 3) {
 		for (int i = _numCharacters - 1; i >= 0; i--)
 			sub17264(i, var4);
@@ -2232,7 +2236,7 @@ void LilliputEngine::displayHeroismIndicator() {
 	}
 
 	_scriptHandler->_heroismLevel += var2;
-	
+
 	int index = _scriptHandler->_heroismBarX + _scriptHandler->_heroismBarBottomY * 320 ;
 
 	var2 = _scriptHandler->_heroismLevel & 0xFF;
@@ -2284,7 +2288,7 @@ void LilliputEngine::pollEvent() {
 			break;
 		}
 	}
-	
+
 	if (_mousePos != _oldMousePos) {
 		_oldMousePos = _mousePos;
 		if (_skipDisplayFlag1 != 0) {
@@ -2385,7 +2389,7 @@ void LilliputEngine::loadRules() {
 		error("Missing game file ERULES.PRG");
 
 	_word10800_ERULES = f.readUint16LE();
-	
+
 	// Chunk 1
 	int size = f.readUint16LE();
 	_rulesChunk1 = (byte *)malloc(sizeof(byte) * size);
@@ -2694,7 +2698,7 @@ Common::Error LilliputEngine::run() {
 
 	_scriptHandler->runScript(ScriptStream(_initScript, _initScriptSize));
 
-	// Hack, see above 
+	// Hack, see above
 	_int8installed = true;
 
 	while(!_shouldQuit) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 62ed4ba..c70bab0 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -114,16 +114,12 @@ public:
 
 	byte _array147D1[3];
 	byte _array1692B[4];
-	byte _buffer1[45056];
-	byte _buffer2[45056];
-	byte _buffer3[45056];
 	byte *_bufferIsoMap;
 	byte *_bufferCubegfx;
 	byte *_bufferMen;
 	byte *_bufferMen2;
 	byte *_bufferIsoChars;
 	byte *_bufferIdeogram;
-	byte _buffer10[4032];
 	byte _curPalette[768];
 	byte _displayStringBuf[160];
 
@@ -207,10 +203,10 @@ public:
 	byte _array16E94[40];
 	byte _array16C54[4];
 	byte _array16C58[4];
-	byte _buffer1_45k[45056];
-	byte _buffer2_45k[45056];
-	byte _buffer3_45k[45056];
-	byte _buffer10_4032[4032];
+	byte _savedSurfaceGameArea1[176 * 256]; // 45056
+	byte _savedSurfaceGameArea2[176 * 256]; // 45056
+	byte _savedSurfaceGameArea3[176 * 256]; // 45056
+	byte _savedSurfaceSpeech[16 * 252];
 
 	const LilliputGameDescription *_gameDescription;
 	uint32 getFeatures() const;
@@ -225,18 +221,18 @@ public:
 	void displayFunction3(int var1, int var2, int var4);
 	void displayMousePointer();
 	void restoreSurfaceUnderMousePointer();
-	void displayFunction6();
-	void displayFunction7();
+	void saveSurfaceGameArea();
+	void saveSurfaceSpeech();
 	void displayInterfaceHotspots();
 	void displayLandscape();
 	void displayFunction10();
 	void displayFunction11(byte *buf);
 	void displayFunction12();
 	void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
-	void displayFunction14();
+	void displayGameArea();
 	void displayFunction15();
 	void displayFunction16();
-	void displayFunction17();
+	void restoreSurfaceSpeech();
 	void displayFunction18(int var1, int var2, int var3, int var4);
 
 	void displayCharacter(int index, Common::Point pos, int flags);


Commit: d32887f36715c953d45db6f6b4a5695ceef04926
    https://github.com/scummvm/scummvm/commit/d32887f36715c953d45db6f6b4a5695ceef04926
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 09721b6..ab41b98 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -138,7 +138,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte129A0 = 0xFF;
 	_numCharactersToDisplay = 0;
 	_nextDisplayCharacterPos = Common::Point(0, 0);
-	_byte12A04 = 0;
+	_animationTick = 0;
 	_byte12A05 = 10;
 	_byte12A06 = 2;
 	_byte12A07 = 0;
@@ -150,6 +150,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12FE3 = 0;
 	_byte16F08 = 0;
 	_byte16C9F = 0;
+	_lastAnimationTick = 0;
 
 	_currentScriptCharacter = 0;
 	_currentScriptCharacterPos = Common::Point(0, 0);
@@ -277,7 +278,7 @@ void LilliputEngine::newInt8() {
 			if (_sound_byte16F06 != 0)
 				--_sound_byte16F06;
 
-			_byte12A04 ^= 1;
+			_animationTick ^= 1;
 			if (_byte12A09 != 1 && _int8installed) // hack for the title stars because _int8installed is not set at the good place for the moment
 				displayFunction16();
 		}
@@ -779,7 +780,7 @@ void LilliputEngine::displayFunction15() {
 			if (map[1] != 0xFF) {
 				int var1 = map[1];
 				if (_rulesChunk9[var1] != 128)
-					var1 += _scriptHandler->_byte12A04;
+					var1 += _animationTick;
 				displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 1 << 8);
 			}
 			renderCharacters(map, Common::Point(j, i));
@@ -787,7 +788,7 @@ void LilliputEngine::displayFunction15() {
 			if (map[2] != 0xFF) {
 				int var1 = map[2];
 				if (_rulesChunk9[var1] != 128)
-					var1 += _scriptHandler->_byte12A04;
+					var1 += _animationTick;
 				displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 2 << 8);
 			}
 			map += 4;
@@ -828,20 +829,51 @@ void LilliputEngine::displayFunction16() {
 	}
 }
 
-void LilliputEngine::sub1863B() {
-	debugC(2, kDebugEngineTBC, "sub1863B()");
+void LilliputEngine::resetSmallAnims() {
+	debugC(2, kDebugEngine, "resetSmallAnims()");
 
-	_arr18560[0]._field0 = 0;
-	_arr18560[1]._field0 = 0;
-	_arr18560[2]._field0 = 0;
-	_arr18560[3]._field0 = 0;
-	_scriptHandler->_word1855E = 0;
+	_smallAnims[0]._active = false;
+	_smallAnims[1]._active = false;
+	_smallAnims[2]._active = false;
+	_smallAnims[3]._active = false;
+	_smallAnimsFrameIndex = 0;
+}
+
+void LilliputEngine::displaySmallIndexedAnim(byte index, byte subIndex) {
+	debugC(2, kDebugEngine, "displaySmallIndexedAnim(%d, %d)", index, subIndex);
+
+	if (!_smallAnims[index]._active)
+		return;
+
+	display16x16IndexedBuf(_bufferIdeogram, _smallAnims[index]._frameIndex[subIndex], _smallAnims[index]._pos);
+}
+
+void LilliputEngine::displaySmallAnims() {
+	debugC(2, kDebugEngineTBC, "displaySmallAnims()");
+
+	if (_animationTick == _lastAnimationTick)
+		return;
+
+	_lastAnimationTick = _animationTick;
+	
+	assert(_smallAnimsFrameIndex < 8);
+	int subIndex = _smallAnimsFrameIndex;
+	displaySmallIndexedAnim(0, subIndex);
+	displaySmallIndexedAnim(1, subIndex);
+	displaySmallIndexedAnim(2, subIndex);
+	displaySmallIndexedAnim(3, subIndex);
+
+	++subIndex;
+	if (subIndex == 8)
+		subIndex = 0;
+
+	_smallAnimsFrameIndex = subIndex;
 }
 
 void LilliputEngine::paletteFadeOut() {
 	debugC(2, kDebugEngine, "paletteFadeOut()");
 
-	sub1863B();
+	resetSmallAnims();
 	byte palette[768];
 	for (int fade = 256; fade >= 0;	fade -= 8) {
 		for (int i = 0; i < 768; i++) {
@@ -1805,7 +1837,7 @@ void LilliputEngine::sub16EBC() {
 void LilliputEngine::sub12F37() {
 	debugC(2, kDebugEngineTBC, "sub12F37()");
 
-	int index1 = _byte12A04 + 2;
+	int index1 = _animationTick + 2;
 	int index2 = 0;
 
 	for (int i = 0; i < _numCharacters; i++) {
@@ -2196,7 +2228,7 @@ void LilliputEngine::sub171CF() {
 void LilliputEngine::sub12FE5() {
 	debugC(2, kDebugEngineTBC, "sub12FE5()");
 
-	if (_byte12A04 != 1)
+	if (_animationTick != 1)
 		return;
 
 	int index = 0;
@@ -2587,7 +2619,7 @@ void LilliputEngine::sub170EE(int index) {
 	int var2 = _characterPositionX[index];
 	int var4 = _characterPositionY[index];
 
-	_currentScriptCharacterPos = Common::Point((var2 >> 3) & 0xFF, (var4 >> 3) & 0xFF);
+	_currentScriptCharacterPos = Common::Point(var2 >> 3, var4 >> 3);
 	_currentCharacterVariables = getCharacterVariablesPtr(_currentScriptCharacter * 32);
 }
 
@@ -2719,10 +2751,10 @@ void LilliputEngine::initialize() {
 	_shouldQuit = false;
 
 	for (int i = 0; i < 4; i++) {
-		_arr18560[i]._field0 = 0;
-		_arr18560[i]._field1 = Common::Point(0, 0);
+		_smallAnims[i]._active = false;
+		_smallAnims[i]._pos = Common::Point(0, 0);
 		for (int j = 0; j < 8; j ++)
-			_arr18560[i]._field5[j] = 0;
+			_smallAnims[i]._frameIndex[j] = 0;
 	}
 }
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index c70bab0..c107965 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -68,10 +68,10 @@ enum LilliputDebugChannels {
 
 struct LilliputGameDescription;
 
-struct struct18560 {
-	byte _field0;
-	Common::Point _field1;
-	int16 _field5[8];
+struct SmallAnim {
+	bool _active;
+	Common::Point _pos;
+	int16 _frameIndex[8];
 };
 
 class LilliputEngine : public Engine {
@@ -88,15 +88,18 @@ public:
 	LilliputSound *_soundHandler;
 	Graphics::Surface *_mainSurface;
 
-	struct18560 _arr18560[4];
+	SmallAnim _smallAnims[4];
+	int _smallAnimsFrameIndex;
+
 	byte _byte1714E;
 	byte _byte184F4;
+	byte _lastAnimationTick;
+	byte _animationTick;
 	Common::Point _nextDisplayCharacterPos;
 	byte _sound_byte16F06;
 	byte _byte16F09;
 	byte _keyboard_nextIndex;
 	byte _keyboard_oldIndex;
-	byte _byte12A04;
 	byte _byte12A05;
 	byte _byte12A06;
 	byte _byte12A07;
@@ -234,13 +237,15 @@ public:
 	void displayFunction16();
 	void restoreSurfaceSpeech();
 	void displayFunction18(int var1, int var2, int var3, int var4);
-
 	void displayCharacter(int index, Common::Point pos, int flags);
 	void displayString(byte *buf, int var2, int var4);
 	void displayChar(int index, int var1);
+	void displaySmallAnims();
+	void displaySmallIndexedAnim(byte index, byte subIndex);
+
 	void sub130B6();
 	void sub15F75();
-	void sub1863B();
+	void resetSmallAnims();
 	void paletteFadeOut();
 	void paletteFadeIn();
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index fe09fac..471484e 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -30,8 +30,6 @@ namespace Lilliput {
 
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 	_byte129A0 = 0xFF;
-	_byte1855D = 0;
-	_byte12A04 = 0;
 	_byte10806 = 0;
 	_byte12FE4 = 0xFF;
 	_byte16F02 = 0;
@@ -40,7 +38,6 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte18823 = 0;
 	_byte1881E = 3;
 	_byte1881D = 0;
-	_word1855E = 0;
 	_word16F00 = -1;
 	_word129A3 = 0;
 	_viewportCharacterTarget = -1;
@@ -512,7 +509,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1864D();
 		break;
 	case 0x58:
-		OC_initArr18560();
+		OC_initSmallAnim();
 		break;
 	case 0x59:
 		OC_sub18678();
@@ -702,7 +699,7 @@ static const OpCode opCodes2[] = {
 /* 0x55 */	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x56 */	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x57 */	{ "OC_sub1864D", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },  // TODO
-/* 0x58 */	{ "OC_initArr18560", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+/* 0x58 */	{ "OC_initSmallAnim", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x59 */	{ "OC_sub18678", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },  //TODO
 /* 0x5b */	{ "OC_setViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
@@ -956,15 +953,6 @@ void LilliputScript::runMenuScript(ScriptStream script) {
 		_vm->update();
 }
 
-void LilliputScript::sub185ED(byte index, byte subIndex) {
-	debugC(2, kDebugScript, "sub185ED(%d, %d)", index, subIndex);
-
-	if (_vm->_arr18560[index]._field0 != 1)
-		return;
-
-	_vm->display16x16IndexedBuf(_vm->_bufferIdeogram, _vm->_arr18560[index]._field5[subIndex], _vm->_arr18560[index]._field1);
-}
-
 byte LilliputScript::compareValues(int var1, int oper, int var2) {
 	debugC(2, kDebugScript, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
 
@@ -1033,27 +1021,6 @@ void LilliputScript::computeOperation(byte *bufPtr, int oper, int var3) {
 	}
 }
 
-void LilliputScript::sub185B4_display() {
-	if (_vm->_byte12A04 == _byte1855D)
-		return;
-
-	_byte1855D = _vm->_byte12A04;
-	
-	assert(_word1855E < 8);
-	int subIndex = _word1855E;
-	sub185ED(0, subIndex);
-	sub185ED(1, subIndex);
-	sub185ED(2, subIndex);
-	sub185ED(3, subIndex);
-
-	// In the original, increment by 2 as it's an array of words
-	++subIndex;
-	if (subIndex == 8)
-		subIndex = 0;
-
-	_word1855E = subIndex;
-}
-
 void LilliputScript::sub1823E(byte index, byte var1, byte *curBufPtr) {
 	debugC(1, kDebugScriptTBC, "sub1823E(%d, %d, curBufPtr)", index, var1);
 
@@ -3104,7 +3071,7 @@ void LilliputScript::OC_displayTitleScreen() {
 	_vm->_byte16F09 = 0;
 
 	while(!_vm->_shouldQuit) {
-		sub185B4_display();
+		_vm->displaySmallAnims();
 		_vm->update();
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
 			_vm->_byte16F09 = _vm->_keyboard_getch();
@@ -3150,17 +3117,17 @@ void LilliputScript::OC_sub1864D() {
 	_vm->displayFunction18(var1, var2, var3, var4);
 }
 
-void LilliputScript::OC_initArr18560() {
-	debugC(1, kDebugScript, "OC_initArr18560()");
+void LilliputScript::OC_initSmallAnim() {
+	debugC(1, kDebugScript, "OC_initSmallAnim()");
 
 	int index = _currScript->readUint16LE();
 	assert (index < 4);
-	_vm->_arr18560[index]._field0 = 1;
-	_vm->_arr18560[index]._field1.x = _currScript->readSint16LE();
-	_vm->_arr18560[index]._field1.y = _currScript->readSint16LE();
+	_vm->_smallAnims[index]._active = true;
+	_vm->_smallAnims[index]._pos.x = _currScript->readSint16LE();
+	_vm->_smallAnims[index]._pos.y = _currScript->readSint16LE();
 
 	for (int i = 0; i < 8; i++)
-		_vm->_arr18560[index]._field5[i] = _currScript->readSint16LE();
+		_vm->_smallAnims[index]._frameIndex[i] = _currScript->readUint16LE();
 }
 
 void LilliputScript::OC_sub18678() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 92e092a..a8875f4 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -56,7 +56,6 @@ struct OpCode {
 
 class LilliputScript {
 public:
-	byte _byte12A04;
 	byte _heroismLevel;
 
 	byte _characterScriptEnabled[40];
@@ -77,7 +76,6 @@ public:
 	int _word1881B;
 	int _heroismBarX;
 	int _heroismBarBottomY;
-	int _word1855E;
 
 	Common::Point _array12311[640];
 	byte _array128EF[40];
@@ -102,7 +100,6 @@ private:
 	byte _byte16F05_ScriptHandler;
 	byte _byte12A09;
 	byte _byte129A0;
-	byte _byte1855D;
 	byte _byte10806;
 	byte _byte12FE4;
 	byte _byte16F02;
@@ -123,8 +120,6 @@ private:
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 	
-	void sub185ED(byte index, byte subIndex);
-	void sub185B4_display();
 	void sub1823E(byte index, byte var1, byte *curBufPtr);
 	void sub17B6C(int var1);
 	void sub16C86(int index, byte *buf);
@@ -291,7 +286,7 @@ private:
 	void OC_displayTitleScreen();
 	void OC_sub1853B();
 	void OC_sub1864D();
-	void OC_initArr18560();
+	void OC_initSmallAnim();
 	void OC_sub18678();
 	void OC_sub18690();
 	void OC_setViewPortCharacterTarget();


Commit: 056541c5d98107dcd23202b6c8a262b9682936c0
    https://github.com/scummvm/scummvm/commit/056541c5d98107dcd23202b6c8a262b9682936c0
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in displayFunction15

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ab41b98..dee2481 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -779,7 +779,7 @@ void LilliputEngine::displayFunction15() {
 			int tmpVal = (j << 8) + i;
 			if (map[1] != 0xFF) {
 				int var1 = map[1];
-				if (_rulesChunk9[var1] != 128)
+				if ((_rulesChunk9[var1] & 128) != 0)
 					var1 += _animationTick;
 				displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 1 << 8);
 			}
@@ -787,7 +787,7 @@ void LilliputEngine::displayFunction15() {
 
 			if (map[2] != 0xFF) {
 				int var1 = map[2];
-				if (_rulesChunk9[var1] != 128)
+				if ((_rulesChunk9[var1] & 128) != 0)
 					var1 += _animationTick;
 				displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 2 << 8);
 			}
@@ -2243,7 +2243,7 @@ void LilliputEngine::sub12FE5() {
 		}
 	}
 
-	if (count !=0)
+	if (count != 0)
 		displayInterfaceHotspots();
 }
 


Commit: 72b99e99e46a3f7b69e3894ba6a552204f069638
    https://github.com/scummvm/scummvm/commit/72b99e99e46a3f7b69e3894ba6a552204f069638
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index dee2481..b9e5ded 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -609,7 +609,7 @@ void LilliputEngine::displayFunction12() {
 	saveSurfaceSpeech();
 	displayInterfaceHotspots();
 	displayLandscape();
-	displayFunction15();
+	prepareGameArea();
 	displayGameArea();
 
 	displayMousePointer();
@@ -762,8 +762,8 @@ void LilliputEngine::setNextDisplayCharacter(int var1) {
 	}
 }
 
-void LilliputEngine::displayFunction15() {
-	debugC(2, kDebugEngineTBC, "displayFunction15()");
+void LilliputEngine::prepareGameArea() {
+	debugC(2, kDebugEngineTBC, "prepareGameArea()");
 
 	moveCharacters();
 	_currentDisplayCharacter = 0;
@@ -816,7 +816,7 @@ void LilliputEngine::displayFunction16() {
 	} else {
 		scrollToViewportCharacterTarget();
 		sub189DE();
-		displayFunction15();
+		prepareGameArea();
 		displayGameArea();
 		sub16626();
 		sub12F37();
@@ -1211,11 +1211,10 @@ void LilliputEngine::sortCharacters() {
 	}
 }
 
-// Move view port to x/y
 void LilliputEngine::scrollToViewportCharacterTarget() {
 	debugC(2, kDebugEngineTBC, "scrollToViewportCharacterTarget()");
 
-	if (_scriptHandler->_viewportCharacterTarget == 0xFFFF)
+	if (_scriptHandler->_viewportCharacterTarget == -1)
 		return;
 
 	int var2 = (_characterPositionX[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportPos.x;
@@ -1276,7 +1275,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 		_scriptHandler->_viewportPos.y += dy;
 
 		displayLandscape();
-		displayFunction15();
+		prepareGameArea();
 		displayGameArea();
 
 		if (goalPos.x == _scriptHandler->_viewportPos.x)
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index c107965..efdbdbe 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -233,7 +233,7 @@ public:
 	void displayFunction12();
 	void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
 	void displayGameArea();
-	void displayFunction15();
+	void prepareGameArea();
 	void displayFunction16();
 	void restoreSurfaceSpeech();
 	void displayFunction18(int var1, int var2, int var3, int var4);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 471484e..74171e3 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -233,7 +233,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub17A07();
 		break;
 	case 0x31:
-		return OC_sub17757();
+		return OC_checkViewPortCharacterTarget();
 		break;
 	default:
 		error("Unexpected opcode %d", curWord);
@@ -422,10 +422,10 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub180C3();
 		break;
 	case 0x3B:
-		OC_sub1810A();
+		OC_setViewPortPos();
 		break;
 	case 0x3C:
-		OC_sub1812D();
+		OC_setCurrentCharacterAltitude();
 		break;
 	case 0x3D:
 		OC_sub1817F();
@@ -606,7 +606,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_sub179E5", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17A07", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
-	{ "OC_sub17757", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_checkViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
 };
 
 
@@ -670,8 +670,8 @@ static const OpCode opCodes2[] = {
 /* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x39 */	{ "OC_sub18099", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x3a */	{ "OC_sub180C3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x3b */	{ "OC_sub1810A", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
-/* 0x3c */	{ "OC_sub1812D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x3b */	{ "OC_setViewPortPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
+/* 0x3c */	{ "OC_setCurrentCharacterAltitude", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x3d */	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x3e */	{ "OC_sub181BB", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x3f */	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -2056,11 +2056,11 @@ byte LilliputScript::OC_sub17A07() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub17757() {
-	debugC(1, kDebugScriptTBC, "OC_sub17757()");
+byte LilliputScript::OC_checkViewPortCharacterTarget() {
+	debugC(1, kDebugScript, "OC_checkViewPortCharacterTarget()");
 
 	int var1 = getValue1();
-	if ( var1 == _viewportCharacterTarget )
+	if (var1 == _viewportCharacterTarget)
 		return 1;
 	
 	return 0;
@@ -2247,7 +2247,7 @@ void LilliputScript::OC_sub17A8D() {
 	assert(tmpVal < 40);
 
 	if (tmpVal == _vm->_word10804)
-		_viewportCharacterTarget = 0xFFFF;
+		_viewportCharacterTarget = -1;
 
 	_vm->_characterPositionX[tmpVal] = -1;
 	_vm->_characterPositionY[tmpVal] = -1;
@@ -2742,7 +2742,8 @@ void LilliputScript::OC_sub18099() {
 
 void LilliputScript::OC_sub180C3() {
 	debugC(1, kDebugScriptTBC, "OC_sub180C3()");
-	_viewportCharacterTarget = 0xFFFF;
+
+	_viewportCharacterTarget = -1;
 
 	int var1 = _currScript->readUint16LE();
 	
@@ -2769,18 +2770,18 @@ void LilliputScript::OC_sub180C3() {
 	_byte12A09 = 0;
 }
 
-void LilliputScript::OC_sub1810A() {
-	debugC(1, kDebugScriptTBC, "OC_sub1810A()");
+void LilliputScript::OC_setViewPortPos() {
+	debugC(1, kDebugScript, "OC_setViewPortPos()");
 
-	_viewportCharacterTarget = 0xFFFF;
+	_viewportCharacterTarget = -1;
 	_viewportPos = getPosFromScript();
 
 	_vm->displayLandscape();
-	_vm->displayFunction15();
+	_vm->prepareGameArea();
 }
 
-void LilliputScript::OC_sub1812D() {
-	debugC(1, kDebugScriptTBC, "OC_sub1812D()");
+void LilliputScript::OC_setCurrentCharacterAltitude() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterAltitude()");
 
 	_vm->_characterPositionAltitude[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
@@ -2914,7 +2915,7 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 
 	_vm->_bufferCubegfx = _vm->loadVGA(fileName, 61440, false);
 	_vm->displayLandscape();
-	_vm->displayFunction15();
+	_vm->prepareGameArea();
 }
 
 void LilliputScript::OC_sub1834C() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index a8875f4..bae66cc 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -194,7 +194,7 @@ private:
 	byte OC_sub179C2();
 	byte OC_sub179E5();
 	byte OC_sub17A07();
-	byte OC_sub17757();
+	byte OC_checkViewPortCharacterTarget();
 
 	// Opcodes Type 2
 	void OC_setWord18821();
@@ -256,8 +256,8 @@ private:
 	void OC_setCurrentCharacterDirection();
 	void OC_sub18099();
 	void OC_sub180C3();
-	void OC_sub1810A();
-	void OC_sub1812D();
+	void OC_setViewPortPos();
+	void OC_setCurrentCharacterAltitude();
 	void OC_sub1817F();
 	void sub1818B(Common::Point pos);
 	void OC_sub181BB();


Commit: 4fe3a02154c3563de5a07043a20b4863b5354b89
    https://github.com/scummvm/scummvm/commit/4fe3a02154c3563de5a07043a20b4863b5354b89
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index b9e5ded..b710d0b 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -144,11 +144,10 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12A07 = 0;
 	_byte12A08 = 0;
 	_byte12A09 = 0;
-	_byte1881D = 0;
 	_byte16552 = 0;
 	_byte12FE4 = 0xFF;
 	_byte12FE3 = 0;
-	_byte16F08 = 0;
+	_byte16F08 = 0;	
 	_byte16C9F = 0;
 	_lastAnimationTick = 0;
 
@@ -261,7 +260,7 @@ void LilliputEngine::newInt8() {
 	}
 	--_byte12A06;
 	// TODO: check 'out 20h, 20h'
-
+	
 	// hack for the title stars because _int8installed is not set at the good place for the moment
 	//if (!_int8installed)
 	//	return;
@@ -331,7 +330,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 		// Sprite mirror
 		for (int y = 0; y < 16; y++) {
 			for (int x = 0; x < 16; x++) {
-				// May need a hack of 1 pixel
+				// May need a hack of 1 pixel 
 				if (src[15 - x] != 0)
 					buf[x] = src[15 - x];
 			}
@@ -382,9 +381,8 @@ void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
 	}
 }
 
-// Fill 16x16 rect
-void LilliputEngine::displayFunction3(int var1, int var2, int var4) {
-	debugC(2, kDebugEngineTBC, "displayFunction3(%d, %d, %d)", var1, var2, var4);
+void LilliputEngine::fill16x16Rect(int var1, int var2, int var4) {
+	debugC(2, kDebugEngineTBC, "fill16x16Rect(%d, %d, %d)", var1, var2, var4);
 
 	int tmpVal = ((var4 >> 8) + (var4 & 0xFF));
 	int index = var2 + tmpVal + (tmpVal >> 2);
@@ -744,7 +742,7 @@ void LilliputEngine::moveCharacters() {
 			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
 			_charactersToDisplay[_numCharactersToDisplay] = i;
 			++_numCharactersToDisplay;
-		}
+ 		}
 	}
 
 	sortCharacters();
@@ -802,7 +800,7 @@ void LilliputEngine::displayFunction16() {
 
 	if (_displayMap == 1) {
 		bool forceReturnFl = false;
-		sub15F31(forceReturnFl);
+		checkMapClosing(forceReturnFl);
 		if (forceReturnFl)
 			return;
 
@@ -815,7 +813,7 @@ void LilliputEngine::displayFunction16() {
 		displayCharactersOnMap();
 	} else {
 		scrollToViewportCharacterTarget();
-		sub189DE();
+		checkSpeechClosing();
 		prepareGameArea();
 		displayGameArea();
 		sub16626();
@@ -907,7 +905,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	int dx = x2 - x1;
 	int dy = y2 - y1;
 
-	int word16DCB = 0;
+	int word16DCB = 0; 
 	int word16DCD = 0;
 	int word16DD1 = 0;
 	int word16DCF = 0;
@@ -946,7 +944,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	word16DCB += word16DCD;
 
 	int var1 = byte16DD4;
-	int count = 0;
+	int count = 0; 
 
 	while ( *isoMap == 0xFF ) {
 		if (var1 > 0) {
@@ -956,7 +954,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 			isoMap += word16DCF;
 			var1 += byte16DD4;
 		}
-
+		
 		count++;
 		if (count == dy) {
 			return 0;
@@ -970,12 +968,12 @@ void LilliputEngine::sub15F75() {
 
 	_byte129A0 = 0xFF;
 	_savedMousePosDivided = Common::Point(-1, -1);
-	byte newX = _mousePos.x >> 2;
+	byte newX = _mousePos.x >> 2; 
 	byte newY = _mousePos.y / 3;
 
 	if ((newX >= 64) || (newY >= 64))
 		return;
-
+	
 	_savedMousePosDivided = Common::Point(newX, newY);
 	_byte16F07_menuId = 5;
 }
@@ -989,22 +987,22 @@ void LilliputEngine::sub130B6() {
 	}
 }
 
-void LilliputEngine::sub15F31(bool &forceReturnFl) {
-	debugC(2, kDebugEngineTBC, "sub15F31()");
+void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
+	debugC(2, kDebugEngineTBC, "checkMapClosing()");
 
 	forceReturnFl = false;
 	if (_displayMap != 1)
 		return;
 
 	pollEvent();
-	warning("sub15F31- TODO: Check keyboard");
+	warning("checkMapClosing- TODO: Check keyboard");
 
 	if ((_mouseButton & 1) == 0)
 		return;
 
 	_mouseButton = 0;
 	sub15F75();
-
+	
 	_displayMap = 0;
 	paletteFadeOut();
 	_word15AC2 = 0;
@@ -1028,20 +1026,20 @@ void LilliputEngine::sub16CA0() {
 
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
-			if ((index != index2 ) &&
+			if ((index != index2 ) && 
 				(_rulesBuffer2_5[index] != index2) &&
 				(_rulesBuffer2_5[index2] != index) &&
 				(_rulesBuffer2_11[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_array16123PosX[index2];
 				int d2 = _scriptHandler->_array1614BPosY[index2];
-
+	
 				if (d1 != 0xFF) {
 					int x = c1 - d1;
 					if ((x > -6) && (x < 6)) {
 						int y = c2 - d2;
 						if ((y > -6) && (y < 6)) {
 							_byte16C9F = 1;
-
+	
 							if ((c1 == d1) && (c2 == d2)) {
 								_byte16C9F = 4;
 							} else if((_rulesBuffer2_11[index] & 4) != 0) {
@@ -1055,7 +1053,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;
+											_byte16C9F = 1;	
 									}
 								} else if (_characterDirectionArray[index] == 1) {
 									if (d2 < c2) {
@@ -1065,7 +1063,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;
+											_byte16C9F = 1;	
 									}
 								} else if (_characterDirectionArray[index] == 2) {
 									if (d2 > c2) {
@@ -1075,7 +1073,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;
+											_byte16C9F = 1;	
 									}
 								} else {
 									if (d1 < c1) {
@@ -1085,7 +1083,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;
+											_byte16C9F = 1;	
 									}
 								}
 							}
@@ -1100,7 +1098,7 @@ void LilliputEngine::sub16CA0() {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
 				val = (val & 0xFF00) | _byte16C9F;
 			}
-			_scriptHandler->_array10B51[index2 + index * 40] = val;
+			_scriptHandler->_array10B51[index2 + index * 40] = val;	
 
 		}
 
@@ -1109,13 +1107,13 @@ void LilliputEngine::sub16CA0() {
 
 void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	debugC(2, kDebugEngineTBC, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
-
+	
 	restoreSurfaceUnderMousePointer();
-
+	
 	if ((var1 & 0xFF) == 0x2D) {
 		var2 += 35;
 		var3 -= 35;
-
+		
 		if (var3 < 0) {
 			var2 += var3;
 			var3 = -var3;
@@ -1125,17 +1123,17 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	byte *vgaBuf = (byte *)_mainSurface->getPixels();
 	int tmpVal = (var3 >> 8) + ((var3 & 0xFF) << 8);
 	int vgaIndex = var2 + tmpVal + (tmpVal >> 2);
-
+	
 	if (var3 == 0)
 		++var3;
-
+	
 	for (int i = 0; i < 4; i++) {
 		for (int j = 0; j < var3; j++) {
 			vgaBuf[vgaIndex + j] = 2;
 		}
 		vgaIndex += 320;
 	}
-
+	
 	displayMousePointer();
 }
 
@@ -1181,8 +1179,8 @@ void LilliputEngine::sortCharacters() {
 		for (int var2 = 0; var2 < var4; var2++) {
 			int index1 = _charactersToDisplay[var2];
 			int index2 = _charactersToDisplay[var2 + 1];
-
-			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2])
+		
+			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2]) 
 				continue;
 
 			if (_characterRelativePositionY[index1] == _characterRelativePositionY[index2]) {
@@ -1273,7 +1271,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 	do {
 		_scriptHandler->_viewportPos.x += dx;
 		_scriptHandler->_viewportPos.y += dy;
-
+		
 		displayLandscape();
 		prepareGameArea();
 		displayGameArea();
@@ -1305,7 +1303,7 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 	int index = _charactersToDisplay[_currentDisplayCharacter];
 	Common::Point characterPos = Common::Point(_characterDisplayX[index], _characterDisplayY[index]);
 
-	if (index == _scriptHandler->_word1881B)
+	if (index == _scriptHandler->_talkingCharacter)
 		sub1546F(characterPos);
 
 	if (_byte16552 != 1) {
@@ -1316,7 +1314,7 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 			frame += _scriptHandler->_array10AB1[index];
 			if ((flag & 1) == 1)
 				frame += _spriteSizeArray[index];
-
+			
 			if (_array12299[index] != 0xFF) {
 				frame = _array12299[index] + 82;
 				--_array12299[index];
@@ -1335,47 +1333,47 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 
 void LilliputEngine::sub1546F(Common::Point displayPos) {
 	debugC(2, kDebugEngineTBC, "sub1546F(%d, %d)", displayPos.x, displayPos.y);
-
+	
 	int orgX = displayPos.x + 8;
 	int orgY = displayPos.y;
 	int var2 = 0;
-
+	
 	int x = orgX;
 	int y = orgY;
 	do {
-		sub15498(x, y, var2);
+		sub15498(Common::Point(x, y), var2);
 		--x;
 		y >>= 1;
 	} while (y != 0);
-
+	
 	x = orgX + 1;
 	y = orgY >> 1;
-
+	
 	while (y != 0) {
-		sub15498(x, y, var2);
+		sub15498(Common::Point(x, y), var2);
 		++x;
 		y >>= 1;
 	}
 }
 
-void LilliputEngine::sub15498(byte x, byte y, int var2) {
-	debugC(2, kDebugEngineTBC, "sub15498(%d, %d, %d)", x, y, var2);
-
-	int index = x + ((var2 & 0xFF) << 8) + (var2 >> 8);
-	for (int i = 1 + y - var2; i > 0; i--) {
+void LilliputEngine::sub15498(Common::Point pos, int var2) {
+	debugC(2, kDebugEngineTBC, "sub15498(%d - %d, %d)", pos.x, pos.y, var2);
+	
+	int index = pos.x + ((var2 & 0xFF) << 8) + (var2 >> 8);
+	for (int i = 1 + pos.y - var2; i > 0; i--) {
 		_savedSurfaceGameArea1[index] = 17;
 		index += 256;
 	}
 }
 
-void LilliputEngine::sub189DE() {
-	debugC(2, kDebugEngineTBC, "sub189DE()");
+void LilliputEngine::checkSpeechClosing() {
+	debugC(2, kDebugEngineTBC, "checkSpeechClosing()");
 
-	if (_byte1881D != 0) {
-		--_byte1881D;
-		if (_byte1881D == 0) {
+	if (_scriptHandler->_speechTimer != 0) {
+		--_scriptHandler->_speechTimer;
+		if (_scriptHandler->_speechTimer == 0) {
 			restoreSurfaceSpeech();
-			_scriptHandler->_word1881B = -1;
+			_scriptHandler->_talkingCharacter = -1;
 		}
 	}
 }
@@ -1439,24 +1437,24 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 
 void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngineTBC, "sub167EF(%d)", index);
-
+	
 	int word167EB = findHotspot(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
 	int word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
-
+	
 	if (word167EB == word167ED) {
 		_array109E9PosX[index] = _array10999PosX[index];
 		_array10A11PosY[index] = _array109C1PosY[index];
 		return;
 	}
-
+	
 	if (word167EB == -1) {
 		int tmpVal = reverseFindHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
 		_array109E9PosX[index] = _rulesBuffer12Pos4[tmpVal].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[tmpVal].y;
 		return;
 	}
-
-	if ((word167ED != -1) &&
+	
+	if ((word167ED != -1) && 
 		  (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
 		  (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
 		  (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
@@ -1465,18 +1463,18 @@ void LilliputEngine::sub167EF(int index) {
 		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
 	}
-
+	
 	_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
 	_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
 	int var4h = (_rectXMinMax[index] >> 8);
 	int var4l = (_rectXMinMax[index] & 0xFF);
-
+	
 	if (var4h != var4l) {
 		if (_array109E9PosX[index] == var4h) {
 			--_array109E9PosX[index];
 			return;
 		}
-
+		
 		if (_array109E9PosX[index] == var4l) {
 			++_array109E9PosX[index];
 			return;
@@ -1493,7 +1491,7 @@ void LilliputEngine::sub167EF(int index) {
 			return;
 		}
 	}
-
+	
 	// var4h == var4l
 	int mapIndex = (((_array10A11PosY[index] << 8) >> 2) + _array109E9PosX[index]) << 2;
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
@@ -1503,25 +1501,25 @@ void LilliputEngine::sub167EF(int index) {
 		--_array10A11PosY[index];
 	else if ((tmpVal & 2) != 0)
 		++_array10A11PosY[index];
-	else
+	else 
 		--_array109E9PosX[index];
-
+	
 	return;
 }
 
 void LilliputEngine::sub1693A(int index) {
 	debugC(2, kDebugEngineTBC, "sub1693A(%d)", index);
-
+	
 	static const uint16 _array1692F[4] = {4, 0xFF00, 0x100, 0xFFFC};
 
 	_word16937Pos = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
 
 	sub16A08(index);
-
+	
 	int var2 = (_characterDirectionArray[index] ^ 3);
 	_array1692B[var2] += 0xF8;
 	_byte16939 = 0;
-
+	
 	int mapIndex = ((((_word16937Pos.y << 8) >> 2) + _word16937Pos.x) << 2);
 	int subMapIndex = 0;
 	int retVal = 0;
@@ -1531,7 +1529,7 @@ void LilliputEngine::sub1693A(int index) {
 			if ((_bufferIsoMap[mapIndex + subMapIndex + 3] & 0x80) != 0) {
 				if (sub16A76(i, index) != 0)
 					_array1692B[i] += 0xEC;
-
+				
 				int tmpVal = ((_rulesBuffer2_10[index] & 7) ^ 7);
 				retVal = _rulesChunk9[_bufferIsoMap[mapIndex + subMapIndex]];
 				tmpVal &= retVal;
@@ -1553,7 +1551,7 @@ void LilliputEngine::sub1693A(int index) {
 			tmpVal = _array1692B[i];
 		}
 	}
-
+	
 	_characterDirectionArray[index] = retVal;
 }
 
@@ -1562,7 +1560,7 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 
 	static const char _array16A6C[4] = {1, 0, 0, -1};
 	static const char _array16A70[4] = {0, -1, 1, 0};
-
+	   
 	char var1h = _word16937Pos.x + _array16A6C[indexb];
 	char var1l = _word16937Pos.y + _array16A70[indexs];
 
@@ -1648,7 +1646,7 @@ void LilliputEngine::addCharToBuf(byte character) {
 
 void LilliputEngine::prepareGoldAmount(int param1) {
 	debugC(2, kDebugEngineTBC, "prepareGoldAmount(%d)", param1);
-
+	
 	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
 
 	int count;
@@ -1664,7 +1662,7 @@ void LilliputEngine::prepareGoldAmount(int param1) {
 		--count;
 
 		byte tmpVal = count + 0x30;
-
+		
 		if (i == 4)
 			addCharToBuf(tmpVal);
 		else if ((count != 0) || (!hideZeros)) {
@@ -1771,7 +1769,7 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 
 byte LilliputEngine::sub166DD(int index, Common::Point var1) {
 	debugC(2, kDebugEngineTBC, "sub166DD(%d, %d - %d)", index, var1.x, var1.y);
-
+	
 	_characterDirectionArray[index] = (var1.x & 3);
 	sub16685(index, var1);
 	return 0;
@@ -1821,7 +1819,7 @@ void LilliputEngine::sub16EBC() {
 	int index2 = 3;
 
 	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
-		int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2);
+		int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2); 
 		int var1 = (_bufferIsoMap[index2 + var2] & 0x40);
 
 		if (var1 == _array16E94[index1])
@@ -1848,7 +1846,7 @@ void LilliputEngine::sub12F37() {
 				--varPtr[0];
 				if (varPtr[0] == 1)
 					_scriptHandler->_characterScriptEnabled[index2] = 1;
-			}
+			}			
 		}
 
 		index1 += 32;
@@ -2006,7 +2004,7 @@ byte LilliputEngine::sub16675(int idx, Common::Point var1) {
 	debugC(2, kDebugEngineTBC, "sub16675(%d, %d - %d)", idx, var1.x, var1.y);
 
 	sub16685(idx, var1);
-	int index = var1.y;
+	int index = var1.y;	
 	switch (var1.x) {
 	case 0:
 		break;
@@ -2174,7 +2172,7 @@ void LilliputEngine::sub17224(int var1, int var4) {
 		sub17264(var1, var4);
 		return;
 	}
-
+	
 	if (type == 3) {
 		for (int i = _numCharacters - 1; i >= 0; i--)
 			sub17264(i, var4);
@@ -2267,7 +2265,7 @@ void LilliputEngine::displayHeroismIndicator() {
 	}
 
 	_scriptHandler->_heroismLevel += var2;
-
+	
 	int index = _scriptHandler->_heroismBarX + _scriptHandler->_heroismBarBottomY * 320 ;
 
 	var2 = _scriptHandler->_heroismLevel & 0xFF;
@@ -2319,7 +2317,7 @@ void LilliputEngine::pollEvent() {
 			break;
 		}
 	}
-
+	
 	if (_mousePos != _oldMousePos) {
 		_oldMousePos = _mousePos;
 		if (_skipDisplayFlag1 != 0) {
@@ -2420,7 +2418,7 @@ void LilliputEngine::loadRules() {
 		error("Missing game file ERULES.PRG");
 
 	_word10800_ERULES = f.readUint16LE();
-
+	
 	// Chunk 1
 	int size = f.readUint16LE();
 	_rulesChunk1 = (byte *)malloc(sizeof(byte) * size);
@@ -2729,7 +2727,7 @@ Common::Error LilliputEngine::run() {
 
 	_scriptHandler->runScript(ScriptStream(_initScript, _initScriptSize));
 
-	// Hack, see above
+	// Hack, see above 
 	_int8installed = true;
 
 	while(!_shouldQuit) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index efdbdbe..35d6915 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -105,7 +105,6 @@ public:
 	byte _byte12A07;
 	byte _byte12A08;
 	byte _byte12A09;
-	byte _byte1881D;
 	byte _byte16552;
 	byte _byte12FE4;
 	byte _byte12FE3;
@@ -221,7 +220,7 @@ public:
 	void display16x16IndexedBuf(byte *buf, int var1, Common::Point pos);
 	void display16x16Buf(byte *buf, Common::Point pos);
 	void SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos);
-	void displayFunction3(int var1, int var2, int var4);
+	void fill16x16Rect(int var1, int var2, int var4);
 	void displayMousePointer();
 	void restoreSurfaceUnderMousePointer();
 	void saveSurfaceGameArea();
@@ -252,7 +251,7 @@ public:
 	void sortCharacters();
 	void scrollToViewportCharacterTarget();
 	void viewportScrollTo(Common::Point goalPos);
-	void sub189DE();
+	void checkSpeechClosing();
 	void sub16626();
 	void sub16A08(int index);
 	byte sub16A76(int indexb, int indexs);
@@ -289,9 +288,9 @@ public:
 	void sub131B2(Common::Point pos, bool &forceReturnFl);
 	void sub131FC(Common::Point pos);
 	void sub1546F(Common::Point displayPos);
-	void sub15498(byte x, byte y, int var2);
+	void sub15498(Common::Point pos, int var2);
 	void sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex);
-	void sub15F31(bool &forceReturnFl);
+	void checkMapClosing(bool &forceReturnFl);
 	void sub16B63(int index);
 	void sub16B76(int index);
 	void sub166C0(int index);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 74171e3..bd5bb1e 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -36,8 +36,8 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte16F04 = 0;
 	_byte1881A = 0;
 	_byte18823 = 0;
-	_byte1881E = 3;
-	_byte1881D = 0;
+	_speechDisplaySpeed = 3;
+	_speechTimer = 0;
 	_word16F00 = -1;
 	_word129A3 = 0;
 	_viewportCharacterTarget = -1;
@@ -251,22 +251,22 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17A3E();
 		break;
 	case 0x2:
-		OC_sub17D57();
+		OC_sub17D57_speech1();
 		break;
 	case 0x3:
-		OC_sub17D7F();
+		OC_sub17D7F_speech2();
 		break;
 	case 0x4:
-		OC_sub17DB9();
+		OC_sub17DB9_speech3();
 		break;
 	case 0x5:
-		OC_sub17DF9();
+		OC_sub17DF9_speech1param();
 		break;
 	case 0x6:
-		OC_sub17E07();
+		OC_sub17E07_speech4param();
 		break;
 	case 0x7:
-		OC_sub17E15();
+		OC_sub17E15_speech2param();
 		break;
 	case 0x8:
 		OC_sub17B03();
@@ -287,7 +287,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17B93();
 		break;
 	case 0xE:
-		OC_sub17E37();
+		OC_sub17E37_speech4();
 		break;
 	case 0xF:
 		OC_resetByte1714E();
@@ -485,7 +485,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_loadFile_AERIAL_GFX();
 		break;
 	case 0x50:
-		OC_sub17E22();
+		OC_sub17E22_speech1IfSoundOff();
 		break;
 	case 0x51:
 		OC_sub1844A();
@@ -613,19 +613,19 @@ static const OpCode opCodes1[] = {
 static const OpCode opCodes2[] = {
 /* 0x00 */	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x01 */	{ "OC_sub17A3E", 3, kgetPosFromScript, kImmediateValue, kImmediateValue, kNone, kNone },
-/* 0x02 */	{ "OC_sub17D57", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x03 */	{ "OC_sub17D7F", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
-/* 0x04 */	{ "OC_sub17DB9", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
-/* 0x05 */	{ "OC_sub17DF9", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x06 */	{ "OC_sub17E07", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
-/* 0x07 */	{ "OC_sub17E15", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x02 */	{ "OC_sub17D57_speech1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x03 */	{ "OC_sub17D7F_speech2", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
+/* 0x04 */	{ "OC_sub17DB9_speech3", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
+/* 0x05 */	{ "OC_sub17DF9_speech1param", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x06 */	{ "OC_sub17E07_speech4param", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
+/* 0x07 */	{ "OC_sub17E15_speech2param", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x08 */	{ "OC_sub17B03", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
 /* 0x09 */	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 /* 0x0b */	{ "OC_sub17A8D", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x0d */	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
-/* 0x0e */	{ "OC_sub17E37", 0, kNone, kNone, kNone, kNone, kNone },  // todo
+/* 0x0e */	{ "OC_sub17E37_speech4", 0, kNone, kNone, kNone, kNone, kNone },  // todo
 /* 0x0f */	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x10 */	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x11 */	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
@@ -691,7 +691,7 @@ static const OpCode opCodes2[] = {
 /* 0x4d */	{ "OC_sub183A2", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4e */	{ "OC_sub183C6", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
 /* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x50 */	{ "OC_sub17E22", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x50 */	{ "OC_sub17E22_speech1IfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x52 */	{ "OC_sub1847F", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x53 */	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -1146,9 +1146,9 @@ void LilliputScript::sub189B8() {
 		++index;
 	}
 
-	index /= _byte1881E;
+	index /= _speechDisplaySpeed;
 	index += 4;
-	_byte1881D = index;
+	_speechTimer = index;
 	_vm->displayFunction10();
 	_vm->displayFunction11(_vm->_displayStringBuf);
 }
@@ -2068,8 +2068,10 @@ byte LilliputScript::OC_checkViewPortCharacterTarget() {
 
 void LilliputScript::OC_setWord18821() {
 	debugC(1, kDebugScriptTBC, "OC_setWord18821()");
+
 	_word18821 = getValue1();
 }
+
 void LilliputScript::OC_sub17A3E() {
 	debugC(1, kDebugScriptTBC, "OC_sub17A3E()");
 	Common::Point var1 = getPosFromScript();
@@ -2088,8 +2090,8 @@ void LilliputScript::OC_sub17A3E() {
 	}
 }
 
-void LilliputScript::OC_sub17D57() {
-	debugC(1, kDebugScriptTBC, "OC_sub17D57()");
+void LilliputScript::OC_sub17D57_speech1() {
+	debugC(1, kDebugScriptTBC, "OC_sub17D57_speech1()");
 
 	int curWord = _currScript->readUint16LE();
 
@@ -2098,7 +2100,7 @@ void LilliputScript::OC_sub17D57() {
 	if (forceReturnFl)
 		return;
 
-	_word1881B = _vm->_currentScriptCharacter;
+	_talkingCharacter = _vm->_currentScriptCharacter;
 	sub18B3C(curWord);
 
 }
@@ -2129,8 +2131,8 @@ void LilliputScript::sub18B7C(int var1, int var3) {
 	decodePackedText(&_vm->_packedStrings[index]);
 }
 
-void LilliputScript::OC_sub17D7F() {
-	debugC(1, kDebugScriptTBC, "OC_sub17D7F()");
+void LilliputScript::OC_sub17D7F_speech2() {
+	debugC(1, kDebugScriptTBC, "OC_sub17D7F_speech2()");
 
 	int var1 = getCharacterVariablePtr()[0];
 	int var2 = (_currScript->readUint16LE() & 0xFF);
@@ -2143,13 +2145,13 @@ void LilliputScript::OC_sub17D7F() {
 	if (forceReturnFl)
 		return;
 
-	_word1881B = _vm->_currentScriptCharacter;
+	_talkingCharacter = _vm->_currentScriptCharacter;
 
 	sub18B7C(var1, var3);
 }
 
-void LilliputScript::OC_sub17DB9() {
-	debugC(1, kDebugScriptTBC, "OC_sub17DB9()");
+void LilliputScript::OC_sub17DB9_speech3() {
+	debugC(1, kDebugScriptTBC, "OC_sub17DB9_speech3()");
 
 	int index = _currScript->readUint16LE();
 	int maxValue = sub18BB7(index);
@@ -2165,28 +2167,28 @@ void LilliputScript::OC_sub17DB9() {
 	if (forceReturnFl)
 		return;
 
-	_word1881B = _vm->_currentScriptCharacter;
+	_talkingCharacter = _vm->_currentScriptCharacter;
 
 	sub18B7C(index, oldVal);
 	
 }
 
-void LilliputScript::OC_sub17DF9() {
-	debugC(1, kDebugScriptTBC, "OC_sub17DF9()");
+void LilliputScript::OC_sub17DF9_speech1param() {
+	debugC(1, kDebugScriptTBC, "OC_sub17DF9_speech1param()");
 
-	if ((_word1881B & 0xFF) == 0xFF) {
-		OC_sub17D57();
+	if (_talkingCharacter == -1) {
+		OC_sub17D57_speech1();
 		return;
 	}
 
 	_currScript->readUint16LE();
 }
 
-void LilliputScript::OC_sub17E07() {
-	debugC(1, kDebugScriptTBC, "OC_sub17E07()");
+void LilliputScript::OC_sub17E07_speech4param() {
+	debugC(1, kDebugScriptTBC, "OC_sub17E07_speech4param()");
 
-	if ((_word1881B & 0xFF) == 0xFF) {
-		OC_sub17D7F();
+	if (_talkingCharacter == -1) {
+		OC_sub17D7F_speech2();
 		return;
 	}
 	_currScript->readUint16LE();
@@ -2196,11 +2198,11 @@ void LilliputScript::OC_sub17E07() {
 
 }
 
-void LilliputScript::OC_sub17E15() {
-	debugC(1, kDebugScriptTBC, "OC_sub17E15()");
+void LilliputScript::OC_sub17E15_speech2param() {
+	debugC(1, kDebugScriptTBC, "OC_sub17E15_speech2param()");
 
-	if ((_word1881B & 0xFF) == 0xFF) {
-		OC_sub17DB9();
+	if (_talkingCharacter == -1) {
+		OC_sub17DB9_speech3();
 		return;
 	}
 	_currScript->readUint16LE();
@@ -2264,8 +2266,8 @@ void LilliputScript::OC_sub17B93() {
 	sub17B6C(var1);
 }
 
-void LilliputScript::OC_sub17E37() {
-	warning("OC_sub17E37");
+void LilliputScript::OC_sub17E37_speech4() {
+	warning("OC_sub17E37_speech4");
 }
 
 void LilliputScript::OC_resetByte1714E() {
@@ -2989,7 +2991,7 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	_vm->_byte15EAD = var1;
 
 	_byte12A09 = 1;
-	_word1881B = -1;
+	_talkingCharacter = -1;
 	OC_PaletteFadeOut();
 	_vm->_word15AC2 = 1;
 	_vm->displayVGAFile("AERIAL.GFX");
@@ -3003,9 +3005,10 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	_vm->_byte12A09 = 0;
 }
 
-void LilliputScript::OC_sub17E22() {
-	warning("OC_sub17E22");
+void LilliputScript::OC_sub17E22_speech1IfSoundOff() {
+	warning("OC_sub17E22_speech1IfSoundOff");
 }
+
 void LilliputScript::OC_sub1844A() {
 	warning("OC_sub1844A");
 }
@@ -3049,7 +3052,7 @@ void LilliputScript::OC_displayVGAFile() {
 	int curWord = _currScript->readUint16LE();
 	int index = _vm->_packedStringIndex[curWord];
 	Common::String fileName = Common::String((const char *)&_vm->_packedStrings[index]);
-	_word1881B = -1;
+	_talkingCharacter = -1;
 	_vm->displayVGAFile(fileName);
 	_vm->paletteFadeIn();
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index bae66cc..1de19bf 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -57,6 +57,7 @@ struct OpCode {
 class LilliputScript {
 public:
 	byte _heroismLevel;
+	byte _speechTimer;
 
 	byte _characterScriptEnabled[40];
 	byte _array122E9[20];
@@ -73,7 +74,7 @@ public:
 
 	Common::Point _viewportPos;
 	int _viewportCharacterTarget;
-	int _word1881B;
+	int _talkingCharacter;
 	int _heroismBarX;
 	int _heroismBarBottomY;
 
@@ -106,8 +107,7 @@ private:
 	byte _byte16F04;
 	byte _byte1881A;
 	byte _byte18823;
-	byte _byte1881E;
-	byte _byte1881D;
+	byte _speechDisplaySpeed;
 
 	int _word16F00;
 	int _word18776;
@@ -199,19 +199,19 @@ private:
 	// Opcodes Type 2
 	void OC_setWord18821();
 	void OC_sub17A3E();
-	void OC_sub17D57();
-	void OC_sub17D7F();
-	void OC_sub17DB9();
-	void OC_sub17DF9();
-	void OC_sub17E07();
-	void OC_sub17E15();
+	void OC_sub17D57_speech1();
+	void OC_sub17D7F_speech2();
+	void OC_sub17DB9_speech3();
+	void OC_sub17DF9_speech1param();
+	void OC_sub17E07_speech4param();
+	void OC_sub17E15_speech2param();
 	void OC_sub17B03();
 	void OC_getRandom_type2();
 	void OC_setCharacterPosition();
 	void OC_sub17A8D();
 	void OC_saveAndQuit();
 	void OC_sub17B93();
-	void OC_sub17E37();
+	void OC_sub17E37_speech4();
 	void OC_resetByte1714E();
 	void OC_deleteSavegameAndQuit();
 	void OC_incByte16F04();
@@ -278,7 +278,7 @@ private:
 	void OC_sub183A2();
 	void OC_sub183C6();
 	void OC_loadFile_AERIAL_GFX();
-	void OC_sub17E22();
+	void OC_sub17E22_speech1IfSoundOff();
 	void OC_sub1844A();
 	void OC_sub1847F();
 	void OC_displayVGAFile();


Commit: 4c54e60be48a1f5cd21567fb0506485f7ac86415
    https://github.com/scummvm/scummvm/commit/4c54e60be48a1f5cd21567fb0506485f7ac86415
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in OC_sub17640

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index bd5bb1e..f0ab687 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1222,7 +1222,7 @@ int LilliputScript::sub18BB7(int index) {
 void LilliputScript::sub18B3C(int var) {
 	debugC(2, kDebugScriptTBC, "sub18B3C(%d)", var);
 
-	if (var == 0xFFFF)
+	if (var == -1)
 		return;
 
 	_word18776 = var;
@@ -1611,21 +1611,18 @@ byte LilliputScript::OC_sub17640() {
 
 	int var4 = _currScript->readUint16LE();
 	int index = _vm->_currentScriptCharacter * 40;
-	int subIndex = 0xFFFF;
-
 	int tmpVal = _currScript->readUint16LE();
 
 	if (tmpVal >= 2000) {
 		int var1 = tmpVal;
 
 		if (var1 == 3000) {
-			subIndex = 0;
 			for (int i = 0; i < _vm->_numCharacters; i++) {
 				tmpVal = _array10B51[index + i];
 				byte v1 = tmpVal & 0xFF;
 				byte v2 = tmpVal >> 8;
 				if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF))) {
-					_word16F00 = subIndex;
+					_word16F00 = i;
 					return 1;
 				}
 			}
@@ -1637,8 +1634,8 @@ byte LilliputScript::OC_sub17640() {
 				tmpVal = _array10B51[index + i];
 				byte v1 = tmpVal & 0xFF;
 				byte v2 = tmpVal >> 8;
-				if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF)) && (_vm->_rulesBuffer2_12[subIndex] != (var4 >> 8))) {
-					_word16F00 = subIndex;
+				if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF)) && (_vm->_rulesBuffer2_12[i] != (var4 >> 8))) {
+					_word16F00 = i;
 					return 1;
 				}
 			}
@@ -1646,7 +1643,7 @@ byte LilliputScript::OC_sub17640() {
 		}
 	} else {
 		_currScript->seek(_currScript->pos() - 2);
-		subIndex = getValue1();
+		int subIndex = getValue1();
 		tmpVal = _array10B51[index + subIndex];
 		byte v1 = tmpVal & 0xFF;
 		byte v2 = tmpVal >> 8;


Commit: 91cbbe27a7aecd935bed6631300245b63cb2afa9
    https://github.com/scummvm/scummvm/commit/91cbbe27a7aecd935bed6631300245b63cb2afa9
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Debug List texts + some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index b710d0b..348de38 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2675,6 +2675,8 @@ void LilliputEngine::handleGameScripts() {
 	if (tmpVal == 0xFF)
 		return;
 /*
+	_scriptHandler->listAllTexts();
+
 	for (int i = 0; i < _gameScriptIndexSize; i++) {
 		assert(tmpVal < _gameScriptIndexSize);
 		debugC(1, kDebugEngineTBC, "================= Game Script %d ==================", i);
@@ -2683,7 +2685,14 @@ void LilliputEngine::handleGameScripts() {
 		debugC(1, kDebugEngineTBC, "============= End Game Script %d ==================", i);
 	}
 
-while(1);*/
+while(1);
+
+	if(tmpVal == 6) {
+		warning("e");
+	}
+	*/
+	i = index;
+	//debugC(1, kDebugEngineTBC, "before char %d, pos %d %d, var0 %d, var1 %d, var2 %d var16 %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), *getCharacterVariablesPtr(i * 32 + 1), *getCharacterVariablesPtr(i * 32 + 2),  *getCharacterVariablesPtr(i * 32 + 22), _scriptHandler->_characterScriptEnabled[i]);
 
 	assert(tmpVal < _gameScriptIndexSize);
 	debugC(1, kDebugEngineTBC, "================= Game Script %d for character %d ==================", tmpVal, index);
@@ -2692,8 +2701,7 @@ while(1);*/
 
 
 	//warning("dump char stat");
-	i = index;
-	debugC(3, kDebugEngineTBC, "char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), _scriptHandler->_characterScriptEnabled[i]);
+	//debugC(1, kDebugEngineTBC, "after char %d, pos %d %d, var0 %d, var1 %d, var2 %d var16 %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), *getCharacterVariablesPtr(i * 32 + 1), *getCharacterVariablesPtr(i * 32 + 2),  *getCharacterVariablesPtr(i * 32 + 22), _scriptHandler->_characterScriptEnabled[i]);
 }
 
 Common::Error LilliputEngine::run() {
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f0ab687..4542b56 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -167,7 +167,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub177F5();
 		break;
 	case 0x1B:
-		return OC_sub17812();
+		return OC_CurrentCharacterVar0Equals();
 		break;
 	case 0x1C:
 		return OC_sub17825();
@@ -188,7 +188,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_skipNextOpcode();
 		break;
 	case 0x22:
-		return OC_sub178C2();
+		return OC_CurrentCharacterVar2Equals1();
 		break;
 	case 0x23:
 		return OC_sub178D2();
@@ -203,7 +203,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub1790F();
 		break;
 	case 0x27:
-		return OC_sub1792A();
+		return OC_CurrentCharacterVar1Equals();
 		break;
 	case 0x28:
 		return OC_sub1793E();
@@ -308,7 +308,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_callScript();
 		break;
 	case 0x15:
-		OC_sub17BF2();
+		OC_callScriptAndReturn();
 		break;
 	case 0x16:
 		OC_setCurrentScriptCharacterPos();
@@ -356,7 +356,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17CEF();
 		break;
 	case 0x25:
-		OC_sub17D1B();
+		OC_IncCurrentCharacterVar1();
 		break;
 	case 0x26:
 		OC_sub17D23();
@@ -398,10 +398,10 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setByte10B29();
 		break;
 	case 0x33:
-		OC_sub18007();
+		OC_setCurrentCharacterVar2();
 		break;
 	case 0x34:
-		OC_sub18014();
+		OC_SetCurrentCharacterVar2ToZero();
 		break;
 	case 0x35:
 		OC_sub1801D();
@@ -584,19 +584,19 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub177C6", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_compWord16EFE", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub177F5", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub17812", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_CurrentCharacterVar0Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17825", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17844", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1785C", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_sub17886", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_CompareGameVariables", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
 	{ "OC_skipNextOpcode", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub178C2", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_CurrentCharacterVar2Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub178D2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub178E8", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
 	{ "OC_sub178FC", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1790F", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_sub1792A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_CurrentCharacterVar1Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1793E", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub1795E", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
@@ -632,7 +632,7 @@ static const OpCode opCodes2[] = {
 /* 0x12 */	{ "OC_sub17BA5", 5, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
 /* 0x13 */	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
 /* 0x14 */	{ "OC_callScript", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script
-/* 0x15 */	{ "OC_sub17BF2", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script then stop
+/* 0x15 */	{ "OC_callScriptAndReturn", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script then stop
 /* 0x16 */	{ "OC_setCurrentScriptCharacterPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },  
 /* 0x17 */	{ "OC_resetByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x18 */	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
@@ -648,7 +648,7 @@ static const OpCode opCodes2[] = {
 /* 0x22 */	{ "OC_sub17CD1", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x24 */	{ "OC_sub17CEF", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
-/* 0x25 */	{ "OC_sub17D1B", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x25 */	{ "OC_IncCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone }, 
 /* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x28 */	{ "OC_sub17E7E", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
@@ -662,8 +662,8 @@ static const OpCode opCodes2[] = {
 /* 0x30 */	{ "OC_sub17FD2", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x32 */	{ "OC_setByte10B29", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x33 */	{ "OC_sub18007", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x34 */	{ "OC_sub18014", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x34 */	{ "OC_SetCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x35 */	{ "OC_sub1801D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x36 */	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
@@ -1219,6 +1219,36 @@ int LilliputScript::sub18BB7(int index) {
 	return result + 1;
 }
 
+void LilliputScript::listAllTexts() {
+	
+	debugC(1, kDebugScriptTBC, "All Game Texts :");
+
+	for (int i = 0; i < _vm->_packedStringNumb; i++) {
+		int index = _vm->_packedStringIndex[i];
+		int variantCount = 0;
+		while (_vm->_packedStrings[index + variantCount] == 0x5B)
+			++variantCount ;
+		int it = 0;
+	
+		/*if (variantCount != 0) {
+			for (int j = 0; j < variantCount; j++) {
+				decodePackedText(&_vm->_packedStrings[index + variantCount + it]);
+				warning("Text 0x%x variant %d : %s", i, j, _vm->_displayStringBuf);
+				do {
+					++it;
+				}
+				while (_vm->_packedStrings[index + variantCount + it] != 0x5B);
+			}
+		} else {*/
+			decodePackedText(&_vm->_packedStrings[index + variantCount]);
+			debugC(1, kDebugScriptTBC, "Text 0x%x variant 0 : %s", i, _vm->_displayStringBuf);
+		/* }*/ 
+
+
+
+	}
+}
+
 void LilliputScript::sub18B3C(int var) {
 	debugC(2, kDebugScriptTBC, "sub18B3C(%d)", var);
 
@@ -1229,7 +1259,7 @@ void LilliputScript::sub18B3C(int var) {
 
 	int index = _vm->_packedStringIndex[var];
 	int count = 0;
-	while (_vm->_packedStrings[index + count] != 0x5B)
+	while (_vm->_packedStrings[index + count] == 0x5B)
 		++count;
 
 	int i = 0;
@@ -1789,8 +1819,8 @@ byte LilliputScript::OC_sub177F5() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub17812() {
-	debugC(1, kDebugScriptTBC, "OC_sub17812()");
+byte LilliputScript::OC_CurrentCharacterVar0Equals() {
+	debugC(1, kDebugScriptTBC, "OC_CurrentCharacterVar0Equals()");
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 	assert(_vm->_currentCharacterVariables != NULL);
@@ -1871,8 +1901,8 @@ byte LilliputScript::OC_skipNextOpcode() {
 	return 1;
 }
 
-byte LilliputScript::OC_sub178C2() {
-	debugC(1, kDebugScriptTBC, "OC_sub178C2()");
+byte LilliputScript::OC_CurrentCharacterVar2Equals1() {
+	debugC(1, kDebugScriptTBC, "OC_CurrentCharacterVar2Equals1()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	if (_vm->_currentCharacterVariables[2] == 1)
@@ -1931,8 +1961,8 @@ byte LilliputScript::OC_sub1790F() {
 	return 1;
 }
 
-byte LilliputScript::OC_sub1792A() {
-	debugC(1, kDebugScriptTBC, "OC_sub1792A()");
+byte LilliputScript::OC_CurrentCharacterVar1Equals() {
+	debugC(1, kDebugScriptTBC, "OC_CurrentCharacterVar1Equals()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
@@ -2327,8 +2357,8 @@ void LilliputScript::OC_callScript() {
 	_vm->sub170EE(tmpIndex);
 }
 
-void LilliputScript::OC_sub17BF2() {
-	debugC(1, kDebugScriptTBC, "OC_sub17BF2()");
+void LilliputScript::OC_callScriptAndReturn() {
+	debugC(1, kDebugScriptTBC, "OC_callScriptAndReturn()");
 
 	OC_callScript();
 	sub17B6C(0);
@@ -2487,8 +2517,8 @@ void LilliputScript::OC_sub17CEF() {
 	sub17B6C(0);
 }
 
-void LilliputScript::OC_sub17D1B() {
-	debugC(1, kDebugScriptTBC, "OC_sub17D1B()");
+void LilliputScript::OC_IncCurrentCharacterVar1() {
+	debugC(1, kDebugScriptTBC, "OC_IncCurrentCharacterVar1()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	++_vm->_currentCharacterVariables[1];
@@ -2671,23 +2701,23 @@ void LilliputScript::OC_setByte10B29() {
 	_characterScriptEnabled[var1] = 1;
 }
 
-void LilliputScript::OC_sub18007() {
-	debugC(1, kDebugScriptTBC, "OC_sub18007()");
+void LilliputScript::OC_setCurrentCharacterVar2() {
+	debugC(1, kDebugScriptTBC, "OC_setCurrentCharacterVar2()");
 
 	int curWord = _currScript->readUint16LE();
 	assert(_vm->_currentCharacterVariables != NULL);
 	_vm->_currentCharacterVariables[2] = curWord & 0xFF;
 }
 
-void LilliputScript::OC_sub18014() {
-	debugC(1, kDebugScriptTBC, "OC_sub18014()");
+void LilliputScript::OC_SetCurrentCharacterVar2ToZero() {
+	debugC(1, kDebugScriptTBC, "OC_SetCurrentCharacterVar2ToZero()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	_vm->_currentCharacterVariables[2] = 0;
 }
 
 void LilliputScript::OC_sub1801D() {
-	debugC(1, kDebugScriptTBC, "OC_sub18014()");
+	debugC(1, kDebugScriptTBC, "OC_SetCurrentCharacterVar2ToZero()");
 
 	int var1 = getValue1();
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 1de19bf..f18619e 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -89,6 +89,7 @@ public:
 	~LilliputScript();
 
 	void disasmScript(ScriptStream script);
+	void listAllTexts();
 	static Common::String getArgumentString(KValueType type, ScriptStream& script);
 	void runScript(ScriptStream script);
 	void runMenuScript(ScriptStream script);
@@ -172,19 +173,19 @@ private:
 	byte OC_sub177C6();
 	byte OC_compWord16EFE();
 	byte OC_sub177F5();
-	byte OC_sub17812();
+	byte OC_CurrentCharacterVar0Equals();
 	byte OC_sub17825();
 	byte OC_sub17844();
 	byte OC_sub1785C();
 	byte OC_sub17886();
 	byte OC_CompareGameVariables();
 	byte OC_skipNextOpcode();
-	byte OC_sub178C2();
+	byte OC_CurrentCharacterVar2Equals1();
 	byte OC_sub178D2();
 	byte OC_sub178E8();
 	byte OC_sub178FC();
 	byte OC_sub1790F();
-	byte OC_sub1792A();
+	byte OC_CurrentCharacterVar1Equals();
 	byte OC_sub1793E();
 	byte OC_sub1795E();
 	byte OC_checkCharacterDirection();
@@ -218,7 +219,7 @@ private:
 	void OC_sub17BA5();
 	void OC_setByte18823();
 	void OC_callScript();
-	void OC_sub17BF2();
+	void OC_callScriptAndReturn();
 	void OC_setCurrentScriptCharacterPos();
 	void OC_resetByte16F04();
 	void OC_sub17AE1();
@@ -234,7 +235,7 @@ private:
 	void OC_sub17CD1();
 	void OC_resetWord16EFE();
 	void OC_sub17CEF();
-	void OC_sub17D1B();
+	void OC_IncCurrentCharacterVar1();
 	void OC_sub17D23();
 	void OC_sub17E6D();
 	void OC_changeCurrentCharacterSprite();
@@ -248,8 +249,8 @@ private:
 	void OC_sub17FD2();
 	void OC_sub17FDD();
 	void OC_setByte10B29();
-	void OC_sub18007();
-	void OC_sub18014();
+	void OC_setCurrentCharacterVar2();
+	void OC_SetCurrentCharacterVar2ToZero();
 	void OC_sub1801D();
 	void OC_sub1805D();
 	void OC_sub18074();


Commit: 95fa16564501014a47dee48d89d796d94f2904df
    https://github.com/scummvm/scummvm/commit/95fa16564501014a47dee48d89d796d94f2904df
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix some code formatting

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 348de38..2aaece1 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -847,7 +847,7 @@ void LilliputEngine::displaySmallIndexedAnim(byte index, byte subIndex) {
 }
 
 void LilliputEngine::displaySmallAnims() {
-	debugC(2, kDebugEngineTBC, "displaySmallAnims()");
+	debugC(2, kDebugEngine, "displaySmallAnims()");
 
 	if (_animationTick == _lastAnimationTick)
 		return;
@@ -2674,9 +2674,15 @@ void LilliputEngine::handleGameScripts() {
 	int tmpVal = _rulesBuffer2_12[index];
 	if (tmpVal == 0xFF)
 		return;
+
 /*
 	_scriptHandler->listAllTexts();
 
+	debugC(1, kDebugEngineTBC, "================= Menu Script ==================");
+	ScriptStream script = ScriptStream(_menuScript, _menuScriptSize);
+	_scriptHandler->disasmScript(script);
+	debugC(1, kDebugEngineTBC, "============= End Menu Script ==================");
+
 	for (int i = 0; i < _gameScriptIndexSize; i++) {
 		assert(tmpVal < _gameScriptIndexSize);
 		debugC(1, kDebugEngineTBC, "================= Game Script %d ==================", i);
@@ -2684,8 +2690,8 @@ void LilliputEngine::handleGameScripts() {
 		_scriptHandler->disasmScript(script);
 		debugC(1, kDebugEngineTBC, "============= End Game Script %d ==================", i);
 	}
-
-while(1);
+	
+	while(1);
 
 	if(tmpVal == 6) {
 		warning("e");
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 4542b56..5866081 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -807,10 +807,10 @@ void LilliputScript::disasmScript( ScriptStream script) {
 
 		bool hasIf = false;
 
-		if(val != 0xFFF8) {
+		if (val != 0xFFF8) {
 			hasIf = true;
-			
 		}
+
 		bool firstIf = true; 
 
 
@@ -827,25 +827,26 @@ void LilliputScript::disasmScript( ScriptStream script) {
 
 			// op code type 1
 			assert(val < sizeof(opCodes1)/sizeof(OpCode));
-			const OpCode* opCode = &opCodes1[val];
-			const KValueType* opArgType = &opCode->_arg1;
+			const OpCode *opCode = &opCodes1[val];
+			const KValueType *opArgType = &opCode->_arg1;
 
 			Common::String str;
 
-			if(firstIf) {
+			if (firstIf) {
 				str = "if (";
 				firstIf = false;
 			} else {
 				str = "    ";
 			}
-			if (neg) str += "not ";
+			if (neg)
+				str += "not ";
 			str += Common::String(opCode->_opName);
 			str += "(";
 
 			for (int p = 0; p < opCode->_numArgs; p++) {
 				
 				str += getArgumentString(*opArgType, script);
-				if(p != opCode->_numArgs - 1)
+				if (p != opCode->_numArgs - 1)
 					str += ", ";
 
 				opArgType++;
@@ -856,7 +857,7 @@ void LilliputScript::disasmScript( ScriptStream script) {
 
 			val = script.readUint16LE();
 
-			if(val == 0xFFF8) {
+			if (val == 0xFFF8) {
 				str += ")";
 			}
 
@@ -870,9 +871,9 @@ void LilliputScript::disasmScript( ScriptStream script) {
 		while (val != 0xFFF7) {
 			
 			// op code type 2 
-			assert(val < sizeof(opCodes2)/sizeof(OpCode));
-			const OpCode* opCode = &opCodes2[val];
-			const KValueType* opArgType = &opCode->_arg1;
+			assert(val < sizeof(opCodes2) / sizeof(OpCode));
+			const OpCode *opCode = &opCodes2[val];
+			const KValueType *opArgType = &opCode->_arg1;
 
 			Common::String str;
 


Commit: 91651f4090509e8263663127054af471127abaa2
    https://github.com/scummvm/scummvm/commit/91651f4090509e8263663127054af471127abaa2
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Intro is finally starting correctly

The game was not setting good character states because
the save flag was not set.

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 2aaece1..6cccd5c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -164,7 +164,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word1289D = 0;
 	_numCharacters = 0;
 
-	_saveFlag = false;
+	_saveFlag = true;
 	_byte16F07_menuId = 0;
 
 	_array16C54[0] = _array16C58[3] = 1;
@@ -528,7 +528,7 @@ void LilliputEngine::displayFunction10() {
 	displayMousePointer();
 }
 
-void LilliputEngine::sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex) {
+void LilliputEngine::sub15A4C(int vgaIndex, byte *srcBuf, int &bufIndex) {
 	debugC(2, kDebugEngineTBC, "sub15A4C()");
 
 	int var3 = 0;
@@ -544,7 +544,7 @@ void LilliputEngine::sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex) {
 		++var3;
 	}
 
-	var1 = (0x3D - var3) < 1;
+	var1 = (0x3D - var3) << 1;
 	vgaIndex += var1;
 
 	bufIndex = bckIndex;
@@ -554,7 +554,7 @@ void LilliputEngine::sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex) {
 		if ((var1 == 0) || (var1 == '|'))
 			break;
 
-		displayChar(vgaIndex, srcBuf[bufIndex]);
+		displayChar(vgaIndex, var1);
 		vgaIndex += 4;
 	}
 
@@ -680,7 +680,7 @@ void LilliputEngine::displayCharactersOnMap() {
 			 int y = (3 * _scriptHandler->_array1614BPosY[index]) + 1;
 			 int x = (_scriptHandler->_array16123PosX[index] * 4) + 1;
 
-			 _word15E5D[index] = y * 320 + x;
+			 _word15E5D[index] = y * 320 + x; 
 			 _byte15E35[index] = buf[y * 320 + x];
 			 buf[y * 320 + x] = _scriptHandler->_array128EF[index];
 		}
@@ -2004,7 +2004,7 @@ byte LilliputEngine::sub16675(int idx, Common::Point var1) {
 	debugC(2, kDebugEngineTBC, "sub16675(%d, %d - %d)", idx, var1.x, var1.y);
 
 	sub16685(idx, var1);
-	int index = var1.y;	
+	int index = idx;	
 	switch (var1.x) {
 	case 0:
 		break;
@@ -2674,15 +2674,17 @@ void LilliputEngine::handleGameScripts() {
 	int tmpVal = _rulesBuffer2_12[index];
 	if (tmpVal == 0xFF)
 		return;
-
 /*
 	_scriptHandler->listAllTexts();
 
+
+
 	debugC(1, kDebugEngineTBC, "================= Menu Script ==================");
 	ScriptStream script = ScriptStream(_menuScript, _menuScriptSize);
 	_scriptHandler->disasmScript(script);
 	debugC(1, kDebugEngineTBC, "============= End Menu Script ==================");
 
+
 	for (int i = 0; i < _gameScriptIndexSize; i++) {
 		assert(tmpVal < _gameScriptIndexSize);
 		debugC(1, kDebugEngineTBC, "================= Game Script %d ==================", i);
@@ -2692,11 +2694,8 @@ void LilliputEngine::handleGameScripts() {
 	}
 	
 	while(1);
-
-	if(tmpVal == 6) {
-		warning("e");
-	}
-	*/
+*/
+	
 	i = index;
 	//debugC(1, kDebugEngineTBC, "before char %d, pos %d %d, var0 %d, var1 %d, var2 %d var16 %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), *getCharacterVariablesPtr(i * 32 + 1), *getCharacterVariablesPtr(i * 32 + 2),  *getCharacterVariablesPtr(i * 32 + 22), _scriptHandler->_characterScriptEnabled[i]);
 
@@ -2705,7 +2704,6 @@ void LilliputEngine::handleGameScripts() {
 	_scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
 	debugC(1, kDebugEngineTBC, "============= End Game Script %d for character %d ==================", tmpVal, index);
 
-
 	//warning("dump char stat");
 	//debugC(1, kDebugEngineTBC, "after char %d, pos %d %d, var0 %d, var1 %d, var2 %d var16 %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), *getCharacterVariablesPtr(i * 32 + 1), *getCharacterVariablesPtr(i * 32 + 2),  *getCharacterVariablesPtr(i * 32 + 22), _scriptHandler->_characterScriptEnabled[i]);
 }
@@ -2772,6 +2770,11 @@ void LilliputEngine::initialize() {
 byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
 	debugC(1, kDebugEngineTBC, "getCharacterVariablesPtr(%d)", index);
 
+	if(index == 96 + 22) {	
+		int a = 0;
+	}
+
+
 	assert((index > -3120) && (index < 1400));
 	if (index >= 0)
 		return &_characterVariables_[index];
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 35d6915..03b2365 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -289,7 +289,7 @@ public:
 	void sub131FC(Common::Point pos);
 	void sub1546F(Common::Point displayPos);
 	void sub15498(Common::Point pos, int var2);
-	void sub15A4C(int &vgaIndex, byte *srcBuf, int &bufIndex);
+	void sub15A4C(int vgaIndex, byte *srcBuf, int &bufIndex);
 	void checkMapClosing(bool &forceReturnFl);
 	void sub16B63(int index);
 	void sub16B76(int index);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 5866081..1679298 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -887,7 +887,7 @@ void LilliputScript::disasmScript( ScriptStream script) {
 				if (p != opCode->_numArgs - 1)
 					str += ", ";
 
-				if ( p < 5 )
+				if ( p < 4 )
 					opArgType++;
 			}
 			str += ");";
@@ -1105,7 +1105,7 @@ void LilliputScript::sub189F5() {
 	int var1;
 
 	for (;;) {
-		var1 = _vm->_displayStringBuf[index];
+		var1 = _vm->_displayStringBuf[index++];
 		if (var1 == 0)
 			break;
 


Commit: 1f249aa23d8301b285261e5923cd5c1f55195772
    https://github.com/scummvm/scummvm/commit/1f249aa23d8301b285261e5923cd5c1f55195772
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming & 2 3 missing opcodes

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6cccd5c..1c865dc 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1510,7 +1510,7 @@ void LilliputEngine::sub167EF(int index) {
 void LilliputEngine::sub1693A(int index) {
 	debugC(2, kDebugEngineTBC, "sub1693A(%d)", index);
 	
-	static const uint16 _array1692F[4] = {4, 0xFF00, 0x100, 0xFFFC};
+	static const int16 _array1692F[4] = {4, -256, 256, -4};
 
 	_word16937Pos = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
 
@@ -1609,8 +1609,8 @@ int LilliputEngine::reverseFindHotspot(Common::Point pos) {
 void LilliputEngine::sub16A08(int index) {
 	debugC(2, kDebugEngineTBC, "sub16A08(%d)", index);
 
-	static const byte _array169F8[4] = {1, 0, 0, 0xFF};
-	static const byte _array169FC[4] = {0, 0xFF, 1, 0};
+	static const char _array169F8[4] = {1, 0, 0, -1};
+	static const char _array169FC[4] = {0, -1, 1, 0};
 
 	int _array16A00[4];
 
@@ -1684,12 +1684,19 @@ void LilliputEngine::sub16626() {
 			if (var2 == 16)
 				break;
 
+			/*if (index == 3)
+				debugC(1,"");
+			else
+				break;*/
+
 			var2 = (2 * (var2 & 0xFF)) + (index << 5);
 			Common::Point var1 = _scriptHandler->_array12311[var2 / 2];
 			int tmpVal = var2;
 			var2 = (var1.x >> 3);
 			var2 &= 0xFE;
 
+			//warning(" step %d : var1 x:%d y:%d  var:%d", _scriptHandler->_array12811[index], var1.x, var1.y, var2 / 2);
+
 			switch (var2 / 2) {
 			case 0:
 				result = sub16675(index, var1);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 1679298..5caae8a 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -98,7 +98,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_compareCharacterId();
 		break;
 	case 0x4:
-		return OC_sub17468();
+		return OC_CompareByte16F02With();
 		break;
 	case 0x5:
 		return OC_getRandom();
@@ -119,7 +119,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub174D8();
 		break;
 	case 0xB:
-		return OC_sub1750E();
+		return OC_CompareCharacterVariables();
 		break;
 	case 0xC:
 		return OC_compareCoords_1();
@@ -128,13 +128,13 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_compareCoords_2();
 		break;
 	case 0xE:
-		return OC_sub1757C();
+		return OC_CompareDistanceFromCharacterToPositionWith();
 		break;
 	case 0xF:
 		return OC_sub1759E();
 		break;
 	case 0x10:
-		return OC_compWord16EF8();
+		return OC_IsCurrentCharacterIndex();
 		break;
 	case 0x11:
 		return OC_sub175C8();
@@ -155,16 +155,16 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub17782();
 		break;
 	case 0x17:
-		return OC_sub1779E();
+		return OC_CompareMapValueWith();
 		break;
 	case 0x18:
-		return OC_sub177C6();
+		return OC_IsCharacterValid();
 		break;
 	case 0x19:
 		return OC_compWord16EFE();
 		break;
 	case 0x1A:
-		return OC_sub177F5();
+		return OC_AreCurrentCharacterVar0AndVar1EqualsTo();
 		break;
 	case 0x1B:
 		return OC_CurrentCharacterVar0Equals();
@@ -176,10 +176,10 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub17844();
 		break;
 	case 0x1E:
-		return OC_sub1785C();
+		return OC_CompareNumberOfCharacterWithVar0Equals();
 		break;
 	case 0x1F:
-		return OC_sub17886();
+		return OC_IsPositionInViewport();
 		break;
 	case 0x20:
 		return OC_CompareGameVariables();
@@ -194,10 +194,10 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub178D2();
 		break;
 	case 0x24:
-		return OC_sub178E8();
+		return OC_CharacterVariableAnd();
 		break;
 	case 0x25:
-		return OC_sub178FC();
+		return OC_IsCurrentCharacterVar0LessEqualThan();
 		break;
 	case 0x26:
 		return OC_sub1790F();
@@ -209,7 +209,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub1793E();
 		break;
 	case 0x29:
-		return OC_sub1795E();
+		return OC_CurrentCharacterVar3Equals1();
 		break;
 	case 0x2A:
 		return OC_checkCharacterDirection();
@@ -248,7 +248,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setWord18821();
 		break;
 	case 0x1:
-		OC_sub17A3E();
+		OC_ChangeIsoMap();
 		break;
 	case 0x2:
 		OC_sub17D57_speech1();
@@ -278,7 +278,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setCharacterPosition();
 		break;
 	case 0xB:
-		OC_sub17A8D();
+		OC_DisableCharacter();
 		break;
 	case 0xC:
 		OC_saveAndQuit();
@@ -561,44 +561,44 @@ static const OpCode opCodes1[] = {
 	{ "OC_comparePos", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 	{ "OC_sub1740A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_compareCharacterId", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
-	{ "OC_sub17468", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_CompareByte16F02With", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_getRandom", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_for", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_compWord18776", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_checkSaveFlag", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_compByte16F04", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub174D8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
-	{ "OC_sub1750E", 5, kGetValue1, kImmediateValue, kCompareOperation, kGetValue1, kImmediateValue },
+	{ "OC_CompareCharacterVariables", 5, kGetValue1, kImmediateValue, kCompareOperation, kGetValue1, kImmediateValue },
 	{ "OC_compareCoords_1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_compareCoords_2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub1757C", 3, kgetPosFromScript, kCompareOperation, kImmediateValue, kNone, kNone },
+	{ "OC_CompareDistanceFromCharacterToPositionWith", 3, kgetPosFromScript, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_sub1759E", 3, kGetValue1, kCompareOperation, kImmediateValue, kNone, kNone },
-	{ "OC_compWord16EF8", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_IsCurrentCharacterIndex", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_sub175C8", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
 	{ "OC_sub17640", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
 	{ "OC_sub176C4", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
 	{ "OC_compWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_sub17766", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17782", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub1779E", 4, kgetPosFromScript, kImmediateValue, kImmediateValue, kCompareOperation, kNone },
-	{ "OC_sub177C6", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_CompareMapValueWith", 4, kgetPosFromScript, kImmediateValue, kImmediateValue, kCompareOperation, kNone },
+	{ "OC_IsCharacterValid", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_compWord16EFE", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub177F5", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_AreCurrentCharacterVar0AndVar1EqualsTo", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_CurrentCharacterVar0Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17825", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17844", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub1785C", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
-	{ "OC_sub17886", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+	{ "OC_CompareNumberOfCharacterWithVar0Equals", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
+	{ "OC_IsPositionInViewport", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_CompareGameVariables", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
 	{ "OC_skipNextOpcode", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_CurrentCharacterVar2Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub178D2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub178E8", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
-	{ "OC_sub178FC", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_CharacterVariableAnd", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
+	{ "OC_IsCurrentCharacterVar0LessEqualThan", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1790F", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_CurrentCharacterVar1Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1793E", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_sub1795E", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_CurrentCharacterVar3Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub17984", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkSavedMousePos", 0, kNone, kNone, kNone, kNone, kNone },
@@ -612,7 +612,7 @@ static const OpCode opCodes1[] = {
 
 static const OpCode opCodes2[] = {
 /* 0x00 */	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x01 */	{ "OC_sub17A3E", 3, kgetPosFromScript, kImmediateValue, kImmediateValue, kNone, kNone },
+/* 0x01 */	{ "OC_ChangeIsoMap", 3, kgetPosFromScript, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x02 */	{ "OC_sub17D57_speech1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x03 */	{ "OC_sub17D7F_speech2", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x04 */	{ "OC_sub17DB9_speech3", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
@@ -622,7 +622,7 @@ static const OpCode opCodes2[] = {
 /* 0x08 */	{ "OC_sub17B03", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
 /* 0x09 */	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
-/* 0x0b */	{ "OC_sub17A8D", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x0b */	{ "OC_DisableCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x0d */	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
 /* 0x0e */	{ "OC_sub17E37_speech4", 0, kNone, kNone, kNone, kNone, kNone },  // todo
@@ -1079,7 +1079,7 @@ void LilliputScript::sub16C5C(int index, byte var3) {
 		while (count < var3) {
 			if ((buf[0] == 0xFF) && (buf[1] == 0xFF))
 				++count;
-			buf = &buf[2];
+			buf += 2;
 		}
 	}
 
@@ -1355,7 +1355,7 @@ Common::Point LilliputScript::getPosFromScript() {
 		return _vm->_savedMousePosDivided;
 	default:
 		Common::Point pos = Common::Point(curWord >> 8, curWord & 0xFF);
-		warning("getPosFromScript - High value %d -> %d %d", curWord, pos.x, pos.y);
+		//warning("getPosFromScript - High value %d -> %d %d", curWord, pos.x, pos.y);
 		return pos;
 	}
 }
@@ -1436,8 +1436,8 @@ byte LilliputScript::OC_compareCharacterId() {
 	return compareValues(var1, oper, var2);
 }
 
-byte LilliputScript::OC_sub17468() {
-	debugC(1, kDebugScriptTBC, "OC_sub17468()");
+byte LilliputScript::OC_CompareByte16F02With() {
+	debugC(1, kDebugScriptTBC, "OC_CompareByte16F02With()");
 
 	int operation = _currScript->readUint16LE();
 	int val2 = _currScript->readUint16LE();
@@ -1529,8 +1529,8 @@ byte LilliputScript::OC_sub174D8() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub1750E() {
-	debugC(1, kDebugScriptTBC, "OC_sub1750E()");
+byte LilliputScript::OC_CompareCharacterVariables() {
+	debugC(1, kDebugScriptTBC, "OC_CompareCharacterVariables()");
 
 	byte* buf1 = getCharacterVariablePtr();
 	int var1 = *buf1;
@@ -1575,17 +1575,31 @@ byte LilliputScript::OC_compareCoords_2() {
 	return 1;
 }
 
-byte LilliputScript::OC_sub1757C() {
-	warning("OC_sub1757C");
-	return 0;
+byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() {
+	debugC(1, kDebugScriptTBC, "OC_CompareDistanceFromCharacterToPositionWith()");
+	Common::Point var1 = getPosFromScript();
+	Common::Point pos = _vm->_currentScriptCharacterPos;
+	
+	int dx = var1.x - pos.x;
+	if (dx < 0) dx = -dx;
+
+	int dy = var1.y - pos.y;
+	if (dy < 0) dy = -dy;
+
+	int dist = dx + dy;
+		
+	uint16 operation = _currScript->readUint16LE();
+	int16 var2 = _currScript->readUint16LE();
+	
+	return compareValues(dist, operation, var2);
 }
 byte LilliputScript::OC_sub1759E() {
 	warning("OC_sub1759E");
 	return 0;
 }
 
-byte LilliputScript::OC_compWord16EF8() {
-	debugC(1, kDebugScriptTBC, "OC_compWord16EF8()");
+byte LilliputScript::OC_IsCurrentCharacterIndex() {
+	debugC(1, kDebugScriptTBC, "OC_IsCurrentCharacterIndex()");
 	
 	int tmpVal = getValue1();
 	if (tmpVal == _vm->_currentScriptCharacter)
@@ -1765,8 +1779,8 @@ byte *LilliputScript::getMapPtr(Common::Point val) {
 	return &_vm->_bufferIsoMap[(val.y * 64 + val.x) << 2];
 }
 
-byte LilliputScript::OC_sub1779E() {
-	debugC(1, kDebugScriptTBC, "OC_sub1779E()");
+byte LilliputScript::OC_CompareMapValueWith() {
+	debugC(1, kDebugScriptTBC, "OC_CompareMapValueWith()");
 
 	Common::Point tmpVal = getPosFromScript();
 
@@ -1777,14 +1791,14 @@ byte LilliputScript::OC_sub1779E() {
 	int var2 = _currScript->readUint16LE();
 	byte *buf = getMapPtr(tmpVal);
 	byte var1 = buf[var2];
-	var2 = _currScript->readUint16LE();
 	int oper = _currScript->readUint16LE();
+	var2 = _currScript->readUint16LE();
 	
 	return compareValues(var1, oper, var2);
 }
 
-byte LilliputScript::OC_sub177C6() {
-	debugC(1, kDebugScriptTBC, "OC_sub177C6()");
+byte LilliputScript::OC_IsCharacterValid() {
+	debugC(1, kDebugScriptTBC, "OC_IsCharacterValid()");
 
 	int index = getValue1();
 	if (_vm->_characterPositionX[index] == -1)
@@ -1806,8 +1820,8 @@ byte LilliputScript::OC_compWord16EFE() {
 	return 1;
 }
 
-byte LilliputScript::OC_sub177F5() {
-	debugC(1, kDebugScriptTBC, "OC_sub177F5()");
+byte LilliputScript::OC_AreCurrentCharacterVar0AndVar1EqualsTo() {
+	debugC(1, kDebugScriptTBC, "OC_AreCurrentCharacterVar0AndVar1EqualsTo()");
 
 	byte var1 = _currScript->readUint16LE() & 0xFF;
 	byte var2 = _currScript->readUint16LE() & 0xFF;
@@ -1855,8 +1869,8 @@ byte LilliputScript::OC_sub17844() {
 	return 1;
 }
 
-byte LilliputScript::OC_sub1785C() {
-	debugC(1, kDebugScriptTBC, "OC_sub1785C()");
+byte LilliputScript::OC_CompareNumberOfCharacterWithVar0Equals() {
+	debugC(1, kDebugScriptTBC, "OC_CompareNumberOfCharacterWithVar0Equals()");
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 	int count = 0;
@@ -1872,8 +1886,8 @@ byte LilliputScript::OC_sub1785C() {
 	return compareValues(count, oper, var2);
 }
 
-byte LilliputScript::OC_sub17886() {
-	debugC(1, kDebugScriptTBC, "OC_sub17886()");
+byte LilliputScript::OC_IsPositionInViewport() {
+	debugC(1, kDebugScriptTBC, "OC_IsPositionInViewport()");
 
 	Common::Point var1 = getPosFromScript();
 
@@ -1925,8 +1939,8 @@ byte LilliputScript::OC_sub178D2() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub178E8() {
-	debugC(1, kDebugScriptTBC, "OC_sub178E8()");
+byte LilliputScript::OC_CharacterVariableAnd() {
+	debugC(1, kDebugScriptTBC, "OC_CharacterVariableAnd()");
 
 	byte *bufPtr = getCharacterVariablePtr();
 	byte var1 = bufPtr[0];
@@ -1938,8 +1952,8 @@ byte LilliputScript::OC_sub178E8() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub178FC() {
-	debugC(1, kDebugScriptTBC, "OC_sub178FC()");
+byte LilliputScript::OC_IsCurrentCharacterVar0LessEqualThan() {
+	debugC(1, kDebugScriptTBC, "OC_IsCurrentCharacterVar0LessEqualThan()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
@@ -1986,8 +2000,8 @@ byte LilliputScript::OC_sub1793E() {
 	return 1;
 }
 
-byte LilliputScript::OC_sub1795E() {
-	debugC(1, kDebugScriptTBC, "OC_sub1795E()");
+byte LilliputScript::OC_CurrentCharacterVar3Equals1() {
+	debugC(1, kDebugScriptTBC, "OC_CurrentCharacterVar3Equals1()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	if (_vm->_currentCharacterVariables[3] == 1)
@@ -2100,8 +2114,8 @@ void LilliputScript::OC_setWord18821() {
 	_word18821 = getValue1();
 }
 
-void LilliputScript::OC_sub17A3E() {
-	debugC(1, kDebugScriptTBC, "OC_sub17A3E()");
+void LilliputScript::OC_ChangeIsoMap() {
+	debugC(1, kDebugScriptTBC, "OC_ChangeIsoMap()");
 	Common::Point var1 = getPosFromScript();
 	int var2 = _currScript->readUint16LE();
 	int var3 = _currScript->readUint16LE();
@@ -2270,17 +2284,17 @@ void LilliputScript::OC_setCharacterPosition() {
 	_vm->_characterPositionY[index] = var4;
 }
 
-void LilliputScript::OC_sub17A8D() {
-	debugC(1, kDebugScriptTBC, "OC_sub17A8D()");
+void LilliputScript::OC_DisableCharacter() {
+	debugC(1, kDebugScriptTBC, "OC_DisableCharacter()");
 
-	int tmpVal = getValue1();
-	assert(tmpVal < 40);
+	int characterIndex = getValue1();
+	assert(characterIndex < 40);
 
-	if (tmpVal == _vm->_word10804)
+	if (characterIndex == _vm->_word10804)
 		_viewportCharacterTarget = -1;
 
-	_vm->_characterPositionX[tmpVal] = -1;
-	_vm->_characterPositionY[tmpVal] = -1;
+	_vm->_characterPositionX[characterIndex] = -1;
+	_vm->_characterPositionY[characterIndex] = -1;
 }
 
 void LilliputScript::OC_saveAndQuit() {
@@ -3009,7 +3023,14 @@ void LilliputScript::OC_sub183A2() {
 	warning("OC_sub183A2");
 }
 void LilliputScript::OC_sub183C6() {
-	warning("OC_sub183C6");
+	debugC(1, kDebugScriptTBC, "OC_sub183C6()");
+		
+	int var1 = _currScript->readUint16LE();
+	int var2 = _currScript->readUint16LE();
+	_array122FD[var1] = (var2 & 0xff);
+	_array122E9[var1] = 1;
+
+	_vm->displayInterfaceHotspots();
 }
 
 void LilliputScript::OC_loadFile_AERIAL_GFX() {
@@ -3038,7 +3059,17 @@ void LilliputScript::OC_sub17E22_speech1IfSoundOff() {
 }
 
 void LilliputScript::OC_sub1844A() {
-	warning("OC_sub1844A");
+	debugC(1, kDebugScriptTBC, "OC_sub1847F()");
+	
+	int var1 = getValue1();
+	int var2 = _currScript->readUint16LE();
+
+	_vm->_rulesBuffer2_11[var1] = (var2 & 0xFF);
+
+	for (int i = 0; i < 40; i++) {
+		_array10B51[40 * var1 + i] = 0;
+		_array10B51[var1 + 40 * i] = 0;
+	}
 }
 
 void LilliputScript::OC_sub1847F() {
@@ -3180,7 +3211,25 @@ void LilliputScript::OC_setViewPortCharacterTarget() {
 }
 
 void LilliputScript::OC_sub186A1() {
-	warning("OC_sub186A1");
+	debugC(1, kDebugScriptTBC, "OC_sub186A1()");
+
+	int var1 = getValue1();
+	int var2 = _currScript->readUint16LE();
+	int var3 = _currScript->readUint16LE();
+	int var4 = 16;
+
+	_vm->fill16x16Rect(var4, var2, var3);
+
+	int frame = _vm->_characterFrameArray[var1];
+
+	byte* buf = _vm->_bufferMen;
+
+	if (frame > 0xF0) {
+		buf = _vm->_bufferMen2;
+		frame -= 0xF0;
+	}
+
+	_vm->display16x16IndexedBuf(buf, frame, Common::Point(var2, var3) );
 }
 
 void LilliputScript::OC_sub186E5_snd() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index f18619e..b93c26d 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -150,44 +150,44 @@ private:
 	byte OC_comparePos();
 	byte OC_sub1740A();
 	byte OC_compareCharacterId();
-	byte OC_sub17468();
+	byte OC_CompareByte16F02With();
 	byte OC_getRandom();
 	byte OC_for();
 	byte OC_compWord18776();
 	byte OC_checkSaveFlag();
 	byte OC_compByte16F04();
 	byte OC_sub174D8();
-	byte OC_sub1750E();
+	byte OC_CompareCharacterVariables();
 	byte OC_compareCoords_1();
 	byte OC_compareCoords_2();
-	byte OC_sub1757C();
+	byte OC_CompareDistanceFromCharacterToPositionWith();
 	byte OC_sub1759E();
-	byte OC_compWord16EF8();
+	byte OC_IsCurrentCharacterIndex();
 	byte OC_sub175C8();
 	byte OC_sub17640();
 	byte OC_sub176C4();
 	byte OC_compWord10804();
 	byte OC_sub17766();
 	byte OC_sub17782();
-	byte OC_sub1779E();
-	byte OC_sub177C6();
+	byte OC_CompareMapValueWith();
+	byte OC_IsCharacterValid();
 	byte OC_compWord16EFE();
-	byte OC_sub177F5();
+	byte OC_AreCurrentCharacterVar0AndVar1EqualsTo();
 	byte OC_CurrentCharacterVar0Equals();
 	byte OC_sub17825();
 	byte OC_sub17844();
-	byte OC_sub1785C();
-	byte OC_sub17886();
+	byte OC_CompareNumberOfCharacterWithVar0Equals();
+	byte OC_IsPositionInViewport();
 	byte OC_CompareGameVariables();
 	byte OC_skipNextOpcode();
 	byte OC_CurrentCharacterVar2Equals1();
 	byte OC_sub178D2();
-	byte OC_sub178E8();
-	byte OC_sub178FC();
+	byte OC_CharacterVariableAnd();
+	byte OC_IsCurrentCharacterVar0LessEqualThan();
 	byte OC_sub1790F();
 	byte OC_CurrentCharacterVar1Equals();
 	byte OC_sub1793E();
-	byte OC_sub1795E();
+	byte OC_CurrentCharacterVar3Equals1();
 	byte OC_checkCharacterDirection();
 	byte OC_sub17984();
 	byte OC_checkSavedMousePos();
@@ -199,7 +199,7 @@ private:
 
 	// Opcodes Type 2
 	void OC_setWord18821();
-	void OC_sub17A3E();
+	void OC_ChangeIsoMap();
 	void OC_sub17D57_speech1();
 	void OC_sub17D7F_speech2();
 	void OC_sub17DB9_speech3();
@@ -209,7 +209,7 @@ private:
 	void OC_sub17B03();
 	void OC_getRandom_type2();
 	void OC_setCharacterPosition();
-	void OC_sub17A8D();
+	void OC_DisableCharacter();
 	void OC_saveAndQuit();
 	void OC_sub17B93();
 	void OC_sub17E37_speech4();


Commit: 2d88b963a94cce11f94c1de1e37aebbb190b8a11
    https://github.com/scummvm/scummvm/commit/2d88b963a94cce11f94c1de1e37aebbb190b8a11
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a value in character move, some comments

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 1c865dc..26143e9 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1733,7 +1733,7 @@ void LilliputEngine::sub16626() {
 				result = sub166EA(index);
 				break;
 			default:
-				warning("sub16626 - unexpected value %d", var2 / 2);
+				error("sub16626 - unexpected value %d", var2 / 2);
 				break;
 			}
 
@@ -2011,6 +2011,7 @@ byte LilliputEngine::sub16675(int idx, Common::Point var1) {
 	debugC(2, kDebugEngineTBC, "sub16675(%d, %d - %d)", idx, var1.x, var1.y);
 
 	sub16685(idx, var1);
+
 	int index = idx;	
 	switch (var1.x) {
 	case 0:
@@ -2105,7 +2106,7 @@ void LilliputEngine::sub166B6(int index) {
 void LilliputEngine::sub166BB(int index) {
 	debugC(2, kDebugEngineTBC, "sub166BB(%d)", index);
 
-	sub16B31(index, 0xFE);
+	sub16B31(index, -2);
 }
 
 void LilliputEngine::sub166D8(int index) {
@@ -2681,10 +2682,10 @@ void LilliputEngine::handleGameScripts() {
 	int tmpVal = _rulesBuffer2_12[index];
 	if (tmpVal == 0xFF)
 		return;
-/*
-	_scriptHandler->listAllTexts();
 
+/* Decompiler follows
 
+	_scriptHandler->listAllTexts();
 
 	debugC(1, kDebugEngineTBC, "================= Menu Script ==================");
 	ScriptStream script = ScriptStream(_menuScript, _menuScriptSize);
@@ -2777,10 +2778,11 @@ void LilliputEngine::initialize() {
 byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
 	debugC(1, kDebugEngineTBC, "getCharacterVariablesPtr(%d)", index);
 
+/* used to debug
 	if(index == 96 + 22) {	
 		int a = 0;
 	}
-
+*/
 
 	assert((index > -3120) && (index < 1400));
 	if (index >= 0)
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 5caae8a..85bb07f 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1303,7 +1303,7 @@ int16 LilliputScript::getValue1() {
 }
 
 Common::Point LilliputScript::getPosFromScript() {
-	debugC(2, kDebugScriptTBC, "getPosFromScript()");
+	debugC(2, kDebugScript, "getPosFromScript()");
 
 	int curWord = _currScript->readUint16LE();
 	int tmpVal = curWord >> 8;
@@ -1355,7 +1355,7 @@ Common::Point LilliputScript::getPosFromScript() {
 		return _vm->_savedMousePosDivided;
 	default:
 		Common::Point pos = Common::Point(curWord >> 8, curWord & 0xFF);
-		//warning("getPosFromScript - High value %d -> %d %d", curWord, pos.x, pos.y);
+		// warning("getPosFromScript - High value %d -> %d %d", curWord, pos.x, pos.y);
 		return pos;
 	}
 }
@@ -3059,7 +3059,7 @@ void LilliputScript::OC_sub17E22_speech1IfSoundOff() {
 }
 
 void LilliputScript::OC_sub1844A() {
-	debugC(1, kDebugScriptTBC, "OC_sub1847F()");
+	debugC(1, kDebugScriptTBC, "OC_sub1844A()");
 	
 	int var1 = getValue1();
 	int var2 = _currScript->readUint16LE();


Commit: 127f73a1ec0b04640be1ecc8df987233de4e6a19
    https://github.com/scummvm/scummvm/commit/127f73a1ec0b04640be1ecc8df987233de4e6a19
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming, implement 3 missing opcodes

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 26143e9..48f0271 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -132,7 +132,6 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_scriptHandler = new LilliputScript(this);
 	_soundHandler = new LilliputSound(this);
 
-	_byte16939 = 0;
 	_byte1714E = 0;
 	_byte12FCE = 0;
 	_byte129A0 = 0xFF;
@@ -1510,38 +1509,39 @@ void LilliputEngine::sub167EF(int index) {
 void LilliputEngine::sub1693A(int index) {
 	debugC(2, kDebugEngineTBC, "sub1693A(%d)", index);
 	
-	static const int16 _array1692F[4] = {4, -256, 256, -4};
+	static const int16 mapArrayMove[4] = {4, -256, 256, -4};
 
 	_word16937Pos = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
 
 	sub16A08(index);
 	
 	int var2 = (_characterDirectionArray[index] ^ 3);
+	// initialized by sub16A08, values: [0, 6[
 	_array1692B[var2] += 0xF8;
-	_byte16939 = 0;
+	byte byte16939 = 0;
 	
 	int mapIndex = ((((_word16937Pos.y << 8) >> 2) + _word16937Pos.x) << 2);
-	int subMapIndex = 0;
+	int mapIndexDiff = 0;
 	int retVal = 0;
 	for (int i = 3; i >= 0; i--) {
-		subMapIndex = _array1692F[i];
-		if (((_bufferIsoMap[mapIndex + subMapIndex + 3] & _array16C54[i]) != 0) && ((_bufferIsoMap[mapIndex + 3] & _array16C58[i]) != 0)) {
-			if ((_bufferIsoMap[mapIndex + subMapIndex + 3] & 0x80) != 0) {
+		mapIndexDiff = mapArrayMove[i];
+		if (((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & _array16C54[i]) != 0) && ((_bufferIsoMap[mapIndex + 3] & _array16C58[i]) != 0)) {
+			if ((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & 0x80) != 0) {
 				if (sub16A76(i, index) != 0)
 					_array1692B[i] += 0xEC;
-				
+
 				int tmpVal = ((_rulesBuffer2_10[index] & 7) ^ 7);
-				retVal = _rulesChunk9[_bufferIsoMap[mapIndex + subMapIndex]];
+				retVal = _rulesChunk9[_bufferIsoMap[mapIndex + mapIndexDiff]];
 				tmpVal &= retVal;
 				if (tmpVal == 0)
 					continue;
 			}
 		}
 		_array1692B[i] = 0x9E;
-		++_byte16939;
+		++byte16939;
 	}
 
-	if (_byte16939 != 0)
+	if (byte16939 != 0)
 		_array1692B[_characterDirectionArray[index]] += 3;
 
 	int tmpVal = 0x9D;
@@ -1609,29 +1609,30 @@ int LilliputEngine::reverseFindHotspot(Common::Point pos) {
 void LilliputEngine::sub16A08(int index) {
 	debugC(2, kDebugEngineTBC, "sub16A08(%d)", index);
 
-	static const char _array169F8[4] = {1, 0, 0, -1};
-	static const char _array169FC[4] = {0, -1, 1, 0};
+	static const char arrayMoveX[4] = {1, 0, 0, -1};
+	static const char arrayMoveY[4] = {0, -1, 1, 0};
 
-	int _array16A00[4];
+	int arrayDistance[4];
 
 	for (int i = 3; i >= 0; i--) {
-		int16 var1h = _word16937Pos.x + _array169F8[i] - _array109E9PosX[index];
-		int16 var1l = _word16937Pos.y + _array169FC[i] - _array10A11PosY[index];
-		_array16A00[i] = (var1l * var1l) + (var1h * var1h);
+		int16 var1h = _word16937Pos.x + arrayMoveX[i] - _array109E9PosX[index];
+		int16 var1l = _word16937Pos.y + arrayMoveY[i] - _array10A11PosY[index];
+		arrayDistance[i] = (var1l * var1l) + (var1h * var1h);
 	}
-	_array1692B[0] = 0;
-	_array1692B[2] = 0;
+	
+	for (int i = 0; i < 4; i++)
+		_array1692B[i] = 0;
 
+	int8 tmpIndex = 0;
 	for (int i = 6; i > 0; i--) {
-		int tmpVal = 0x7FFF;
-		int tmpIndex = 0;
+		int16 tmpVal = 0x7FFF;
 		for (int j = 0; j < 4; j++) {
-			if (tmpVal > _array16A00[j]) {
-				tmpVal = _array16A00[j];
+			if (tmpVal > arrayDistance[j]) {
+				tmpVal = arrayDistance[j];
 				tmpIndex = j;
 			}
 		}
-		_array16A00[tmpIndex] = 0x7FFF;
+		arrayDistance[tmpIndex] = 0x7FFF;
 		_array1692B[tmpIndex] = i;
 	}
 }
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 03b2365..cc39187 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -112,7 +112,6 @@ public:
 	byte _byte15EAD;
 	byte _debugFlag; // Mostly useless, as the associated functions are empty
 	byte _byte14837; // Unused byte, set by an opcode
-	byte _byte16939;
 
 	byte _array147D1[3];
 	byte _array1692B[4];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 85bb07f..a41fde4 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -131,7 +131,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_CompareDistanceFromCharacterToPositionWith();
 		break;
 	case 0xF:
-		return OC_sub1759E();
+		return OC_compareRandomCharacterId();
 		break;
 	case 0x10:
 		return OC_IsCurrentCharacterIndex();
@@ -572,7 +572,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_compareCoords_1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_compareCoords_2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_CompareDistanceFromCharacterToPositionWith", 3, kgetPosFromScript, kCompareOperation, kImmediateValue, kNone, kNone },
-	{ "OC_sub1759E", 3, kGetValue1, kCompareOperation, kImmediateValue, kNone, kNone },
+	{ "OC_compareRandomCharacterId", 3, kGetValue1, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_IsCurrentCharacterIndex", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_sub175C8", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
 	{ "OC_sub17640", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
@@ -1493,13 +1493,12 @@ byte LilliputScript::OC_checkSaveFlag() {
 }
 
 byte LilliputScript::OC_compByte16F04() {
-	warning("OC_compByte16F04");
+	debugC(1, kDebugScriptTBC, "OC_compByte16F04()");
 
-	byte var1 = _byte16F04;
 	uint16 oper = _currScript->readUint16LE();
 	int16 var2 = _currScript->readUint16LE();
 
-	return compareValues(var1, oper, var2);
+	return compareValues(_byte16F04, oper, var2);
 }
 
 byte LilliputScript::OC_sub174D8() {
@@ -1577,6 +1576,7 @@ byte LilliputScript::OC_compareCoords_2() {
 
 byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() {
 	debugC(1, kDebugScriptTBC, "OC_CompareDistanceFromCharacterToPositionWith()");
+
 	Common::Point var1 = getPosFromScript();
 	Common::Point pos = _vm->_currentScriptCharacterPos;
 	
@@ -1589,13 +1589,19 @@ byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() {
 	int dist = dx + dy;
 		
 	uint16 operation = _currScript->readUint16LE();
-	int16 var2 = _currScript->readUint16LE();
+	int16 var2 = _currScript->readSint16LE();
 	
 	return compareValues(dist, operation, var2);
 }
-byte LilliputScript::OC_sub1759E() {
-	warning("OC_sub1759E");
-	return 0;
+byte LilliputScript::OC_compareRandomCharacterId() {
+	debugC(1, kDebugScriptTBC, "OC_compareRandomCharacterId()");
+
+	byte *tmpArr = getCharacterVariablePtr();
+	_byte16F02 = _vm->_rnd->getRandomNumber(tmpArr[0] + 1);
+	uint16 oper = _currScript->readUint16LE();
+	int16 var2 = _currScript->readSint16LE();
+
+	return compareValues(_byte16F02, oper, var2);
 }
 
 byte LilliputScript::OC_IsCurrentCharacterIndex() {
@@ -2309,7 +2315,15 @@ void LilliputScript::OC_sub17B93() {
 }
 
 void LilliputScript::OC_sub17E37_speech4() {
-	warning("OC_sub17E37_speech4");
+	debugC(1, kDebugScriptTBC, "OC_sub17E37_speech4()");
+
+	bool forceReturnFl = false;
+	sub17D40(forceReturnFl);
+	if (forceReturnFl)
+		return;
+
+	_talkingCharacter = _vm->_currentScriptCharacter;
+	sub18B3C(5);
 }
 
 void LilliputScript::OC_resetByte1714E() {
@@ -2588,17 +2602,19 @@ void LilliputScript::OC_sub17E99() {
 }
 
 void LilliputScript::OC_sub17EC5() {
-	//debugC(1, kDebugScriptTBC, "OC_sub17EC5()");
-	warning("OC_sub17EC5");
-	/*byte *compBuf = sub173D2();
-	int oper = _currScript->readUint16LE();
-	int index = _currScript->readUint16LE();	
+	debugC(1, kDebugScriptTBC, "OC_sub17EC5()");
 
-	byte *buf = sub173D2();
-	byte var1 = buf[0];
-	byte var3 = _vm->_rulesChunk11[var1 + _vm->_rulesChunk10[index]];
+	int indexChunk10 = _currScript->readUint16LE();
+
+	byte *compBuf = sub173D2();
+	int indexChunk11 = _vm->_rulesChunk10[indexChunk10] + compBuf[0];
 
-	computeOperation(compBuf, oper, var3);*/
+	int oper = _currScript->readUint16LE();
+
+	byte *tmpBuf = sub173D2();
+	int var3 = tmpBuf[0];
+	
+	computeOperation(&_vm->_rulesChunk11[indexChunk11], oper, var3);
 }
 
 Common::Point LilliputScript::getCharacterTilePos(int index) {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index b93c26d..4f63546 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -161,7 +161,7 @@ private:
 	byte OC_compareCoords_1();
 	byte OC_compareCoords_2();
 	byte OC_CompareDistanceFromCharacterToPositionWith();
-	byte OC_sub1759E();
+	byte OC_compareRandomCharacterId();
 	byte OC_IsCurrentCharacterIndex();
 	byte OC_sub175C8();
 	byte OC_sub17640();


Commit: 9752da62dfc86edb1d02599754034b5b33bf4465
    https://github.com/scummvm/scummvm/commit/9752da62dfc86edb1d02599754034b5b33bf4465
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming and refactoring

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 48f0271..e10a628 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1136,12 +1136,10 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	displayMousePointer();
 }
 
-void LilliputEngine::displayString(byte *buf, int var2, int var4) {
-	debugC(2, kDebugEngineTBC, "displayString(buf, %d, %d)", var2, var4);
+void LilliputEngine::displayString(byte *buf, Common::Point pos) {
+	debugC(2, kDebugEngineTBC, "displayString(buf, %d - %d)", pos.x, pos.y);
 
-	int index = var2;
-	int tmpVar4 = (var4 >> 8) + ((var4 & 0xFF) << 8);
-	index = index + tmpVar4 + (tmpVar4 >> 2);
+	int index = (pos.y * 320) + pos.x;
 
 	int i = 0;
 	while (buf[i] != 0) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index cc39187..8df04bc 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -236,7 +236,7 @@ public:
 	void restoreSurfaceSpeech();
 	void displayFunction18(int var1, int var2, int var3, int var4);
 	void displayCharacter(int index, Common::Point pos, int flags);
-	void displayString(byte *buf, int var2, int var4);
+	void displayString(byte *buf, Common::Point pos);
 	void displayChar(int index, int var1);
 	void displaySmallAnims();
 	void displaySmallIndexedAnim(byte index, byte subIndex);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a41fde4..db97600 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1244,9 +1244,6 @@ void LilliputScript::listAllTexts() {
 			decodePackedText(&_vm->_packedStrings[index + variantCount]);
 			debugC(1, kDebugScriptTBC, "Text 0x%x variant 0 : %s", i, _vm->_displayStringBuf);
 		/* }*/ 
-
-
-
 	}
 }
 
@@ -2712,7 +2709,6 @@ void LilliputScript::OC_sub17FD2() {
 	
 	int var1 = getValue1();
 	_vm->_currentCharacterVariables[6] = var1 & 0xFF;
-
 }
 
 void LilliputScript::OC_sub17FDD() {
@@ -2728,6 +2724,7 @@ void LilliputScript::OC_sub17FDD() {
 
 void LilliputScript::OC_setByte10B29() {
 	debugC(1, kDebugScriptTBC, "OC_setByte10B29()");
+
 	int var1 = getValue1();
 	_characterScriptEnabled[var1] = 1;
 }
@@ -2764,6 +2761,7 @@ void LilliputScript::OC_sub1801D() {
 	_vm->_characterDirectionArray[var1] = _currScript->readUint16LE();
 
 }
+
 void LilliputScript::OC_sub1805D() {
 	debugC(1, kDebugScriptTBC, "OC_sub1805D()");
 
@@ -3096,18 +3094,18 @@ void LilliputScript::OC_sub1847F() {
 	int curWord = _currScript->readUint16LE();
 	assert(curWord != 0);
 	int var1 = tmpVal / (curWord & 0xFF);
-	int var2 = _currScript->readUint16LE();
-	int var4 = _currScript->readUint16LE();
+	int var2 = _currScript->readSint16LE();
+	int var4 = _currScript->readSint16LE();
 
 	if (_vm->_displayMap != 1) {
 		_vm->restoreSurfaceUnderMousePointer();
-		sub18BE6(var1 & 0xFF, var2, var4);
+		displayNumber(var1 & 0xFF, Common::Point(var2, var4));
 		_vm->displayMousePointer();
 	}
 }
 
-void LilliputScript::sub18BE6(byte var1, int var2, int var4) {
-	debugC(1, kDebugScriptTBC, "sub18BE6(%d, %d, %d)", var1, var2, var4);
+void LilliputScript::displayNumber(byte var1, Common::Point pos) {
+	debugC(1, kDebugScriptTBC, "displayNumber(%d, %d - %d)", var1, pos.x, pos.y);
 
 	_vm->_displayStringIndex = 0;
 	_vm->_displayStringBuf[0] = 32;
@@ -3116,7 +3114,7 @@ void LilliputScript::sub18BE6(byte var1, int var2, int var4) {
 	_vm->_displayStringBuf[3] = 0;
 
 	_vm->prepareGoldAmount(var1);
-	_vm->displayString(_vm->_displayStringBuf, var2, var4);
+	_vm->displayString(_vm->_displayStringBuf, pos);
 }
 
 void LilliputScript::OC_displayVGAFile() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 4f63546..0509259 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -128,7 +128,7 @@ private:
 	void sub17D40(bool &forceReturnFl);
 	void decodePackedText(char *buf);
 	void sub18B3C(int var);
-	void sub18BE6(byte var1, int var2, int var4);
+	void displayNumber(byte var1, Common::Point pos);
 	byte *getMapPtr(Common::Point val);
 	byte *sub173D2();
 	void sub171AF(int var1, int var2, int var4);


Commit: c914fdb0b76999c350159e881e53769990cc4149
    https://github.com/scummvm/scummvm/commit/c914fdb0b76999c350159e881e53769990cc4149
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Janitorial: fix some code formatting

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index e10a628..ceff413 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -244,7 +244,7 @@ GUI::Debugger *LilliputEngine::getDebugger() {
 void LilliputEngine::update() {
 	// update every 20 ms.
 	int currentTime = _system->getMillis();
-	if(currentTime - _lastTime > 20) {
+	if (currentTime - _lastTime > 20) {
 		_lastTime += ((currentTime - _lastTime) / 20) * 20;
 		newInt8();
 		pollEvent();
@@ -316,7 +316,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 
 	src += ((index & 0xFF) << 8) + (index >> 8);
 
-	if ( (flags & 2) == 0 ) {
+	if ((flags & 2) == 0) {
 		for (int y = 0; y < 16; y++) {
 			for (int x = 0; x < 16; x++) {
 				if (src[x] != 0)
@@ -617,7 +617,7 @@ void LilliputEngine::displayIsometricBlock(byte *buf, int var1, int var2, int va
 	debugC(1, kDebugEngine, "displayIsometricBlock(buf, %d, %d, %d)", var1, var2, var3);
 
 	byte tmpByte1 = ((7 + (var2 >> 8) - (var2 & 0xFF)) << 4) & 0xFF;
-	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >> 7) ) << 3) & 0xFF;
+	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >> 7)) << 3) & 0xFF;
 
 	int index = (tmpByte2 << 8) + tmpByte1;
 	int index2 = var1 << 10;
@@ -751,7 +751,7 @@ void LilliputEngine::setNextDisplayCharacter(int var1) {
 	debugC(2, kDebugEngine, "setNextDisplayCharacter(%d)", var1);
 
 	byte charNum = var1 & 0xFF;
-	if ( charNum < _numCharactersToDisplay) {
+	if (charNum < _numCharactersToDisplay) {
 		int index = _charactersToDisplay[charNum];
 		_nextDisplayCharacterPos = Common::Point(_characterRelativePositionX[index], _characterRelativePositionY[index]);
 	} else {
@@ -912,21 +912,21 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	byte byte16DD4 = 0;
 	byte byte16DD3 = 0;
 
-	if(dx < 0) {
+	if (dx < 0) {
 		dx = -dx;
 		word16DCB = -4;
 	} else {
 		word16DCB = 4;
 	}
 
-	if(dy < 0) {
+	if (dy < 0) {
 		dy = -dy;
 		word16DCD = -256;
 	} else {
 		word16DCD = 256;
 	}
 
-	if(dy > dx) {
+	if (dy > dx) {
 		word16DD1 = 0;
 		word16DCF = word16DCB;
 	} else {
@@ -945,7 +945,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	int var1 = byte16DD4;
 	int count = 0; 
 
-	while ( *isoMap == 0xFF ) {
+	while (*isoMap == 0xFF) {
 		if (var1 > 0) {
 			isoMap += word16DCB;
 			var1 += byte16DD3;
@@ -1025,7 +1025,7 @@ void LilliputEngine::sub16CA0() {
 
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
-			if ((index != index2 ) && 
+			if ((index != index2) && 
 				(_rulesBuffer2_5[index] != index2) &&
 				(_rulesBuffer2_5[index2] != index) &&
 				(_rulesBuffer2_11[index2] & 2) == 0) {
@@ -1041,7 +1041,7 @@ void LilliputEngine::sub16CA0() {
 	
 							if ((c1 == d1) && (c2 == d2)) {
 								_byte16C9F = 4;
-							} else if((_rulesBuffer2_11[index] & 4) != 0) {
+							} else if ((_rulesBuffer2_11[index] & 4) != 0) {
 								_byte16C9F = 0;
 							} else {
 								if (_characterDirectionArray[index] == 0) {
@@ -1058,7 +1058,7 @@ void LilliputEngine::sub16CA0() {
 									if (d2 < c2) {
 										_byte16C9F = 2;
 
-										if(d1 == c1)
+										if (d1 == c1)
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
@@ -1068,7 +1068,7 @@ void LilliputEngine::sub16CA0() {
 									if (d2 > c2) {
 										_byte16C9F = 2;
 
-										if(d1 == c1)
+										if (d1 == c1)
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
@@ -1093,7 +1093,7 @@ void LilliputEngine::sub16CA0() {
 
 			int val = _scriptHandler->_array10B51[index2 + index * 40];
 			val = (val & 0xFF) + ((val & 0xFF) << 8);
-			if( (val & 0xFF) != _byte16C9F ) {
+			if ((val & 0xFF) != _byte16C9F) {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
 				val = (val & 0xFF00) | _byte16C9F;
 			}
@@ -1455,7 +1455,7 @@ void LilliputEngine::sub167EF(int index) {
 		  (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
 		  (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
 		  (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
-		  (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF)) ) {
+		  (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF))) {
 		_array109E9PosX[index] = _rulesBuffer12Pos4[word167ED].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
@@ -1845,7 +1845,7 @@ void LilliputEngine::sub12F37() {
 
 	for (int i = 0; i < _numCharacters; i++) {
 		byte *varPtr = getCharacterVariablesPtr(index1);
-		if (varPtr[0] != 0 ) {
+		if (varPtr[0] != 0) {
 			if (varPtr[0] == 1) {
 				varPtr[0] = 0;
 			} else {
@@ -2592,7 +2592,7 @@ void LilliputEngine::displayVGAFile(Common::String fileName) {
 
 void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
 	debugC(1, kDebugEngine, "fixPaletteEntries(palette, %d)", num);
-	// Color values are coded on 6bits ( for old 6bits DAC )
+	// Color values are coded on 6bits (for old 6bits DAC)
 	for (int32 i = 0; i < num * 3; i++) {
 		int32 a = palette[i];
 		assert(a < 64);
@@ -2700,7 +2700,7 @@ void LilliputEngine::handleGameScripts() {
 		debugC(1, kDebugEngineTBC, "============= End Game Script %d ==================", i);
 	}
 	
-	while(1);
+	while (1);
 */
 	
 	i = index;
@@ -2749,7 +2749,7 @@ Common::Error LilliputEngine::run() {
 	// Hack, see above 
 	_int8installed = true;
 
-	while(!_shouldQuit) {
+	while (!_shouldQuit) {
 		handleMenu();
 		handleGameScripts();
 		// To be removed when handled in the previous fonctions
@@ -2778,7 +2778,7 @@ byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
 	debugC(1, kDebugEngineTBC, "getCharacterVariablesPtr(%d)", index);
 
 /* used to debug
-	if(index == 96 + 22) {	
+	if (index == 96 + 22) {	
 		int a = 0;
 	}
 */
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index db97600..588223c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -718,23 +718,23 @@ static const OpCode opCodes2[] = {
 Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream& script) {
 	
 	Common::String str;
-	if(type == kImmediateValue) {
+	if (type == kImmediateValue) {
 		str =  Common::String::format("0x%x", script.readUint16LE());
 	} else if (type == kGetValue1) {
 		int val = script.readUint16LE();
-		if(val < 1000) { 
+		if (val < 1000) { 
 			str = Common::String::format("0x%x", val);
 		} else if (val > 1004) { 
 			str = Common::String::format("getValue1(0x%x)", val);
-		} else if ( val == 1000 ) {
+		} else if (val == 1000) {
 			str = Common::String("_byte129A0");
-		} else if( val == 1001 ) {
+		} else if (val == 1001) {
 			str = Common::String("characterIndex");
-		} else if( val == 1002 ) {
+		} else if (val == 1002) {
 			str = Common::String("_word16F00");
-		} else if( val == 1003 ) {
+		} else if (val == 1003) {
 			str = Common::String("_currentCharacterVariables[6]");
-		} else if( val == 1004 ) {
+		} else if (val == 1004) {
 			str = Common::String("_word10804");
 		}
 	} else if (type == kgetPosFromScript) {
@@ -787,20 +787,20 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 		}
 	} else if (type == kCompareOperation) {
 		int comp = script.readUint16LE();
-		if(comp != '<' && comp != '>')
+		if (comp != '<' && comp != '>')
 			comp = '=';
-		str = Common::String::format("%c", comp );
+		str = Common::String::format("%c", comp);
 	}
 	else if (type == kComputeOperation) {
 		int comp = script.readUint16LE();
-		str = Common::String::format("%c", comp );
+		str = Common::String::format("%c", comp);
 	}
 	return str;
 }
 
-void LilliputScript::disasmScript( ScriptStream script) {
+void LilliputScript::disasmScript(ScriptStream script) {
 	
-	while(!script.eos()) {
+	while (!script.eos()) {
 		uint16 val = script.readUint16LE();
 		if (val == 0xFFF6) // end of script
 			return;
@@ -887,7 +887,7 @@ void LilliputScript::disasmScript( ScriptStream script) {
 				if (p != opCode->_numArgs - 1)
 					str += ", ";
 
-				if ( p < 4 )
+				if (p < 4)
 					opArgType++;
 			}
 			str += ");";
@@ -1415,7 +1415,7 @@ byte LilliputScript::OC_sub1740A() {
 	int var3 = _currScript->readUint16LE();
 	int var4 = 8 >> var3;
 
-	if( var2 & var4 ) {
+	if (var2 & var4) {
 		return 1;
 	} else { 
 		return 0;
@@ -2491,7 +2491,7 @@ void LilliputScript::OC_sub17C8B() {
 	int var1 = 2 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->_currentScriptCharacter;
+	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2502,7 +2502,7 @@ void LilliputScript::OC_sub17CA2() {
 	int var1 = 1 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->_currentScriptCharacter;
+	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2513,7 +2513,7 @@ void LilliputScript::OC_sub17CB9() {
 	int var4 = _currScript->readUint16LE();
 	int var1 = getValue1();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->_currentScriptCharacter;
+	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2524,7 +2524,7 @@ void LilliputScript::OC_sub17CD1() {
 	int var1 = 3 << 8;
 	int var4 = _currScript->readUint16LE();
 	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8 ) + _vm->_currentScriptCharacter;
+	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2811,16 +2811,16 @@ void LilliputScript::OC_sub180C3() {
 	int x = _viewportPos.x + _byte180B3[var1];
 	int y = _viewportPos.y + _byte180BB[var1];
 
-	if ( x < 0 )
+	if (x < 0)
 		x = 0;
 
-	if ( y < 0 )
+	if (y < 0)
 		y = 0;
 	
-	if ( x > 56 )
+	if (x > 56)
 		x = 56;
 
-	if ( y > 56 )
+	if (y > 56)
 		y = 56;
 
 	_byte12A09 = 1;
@@ -2883,17 +2883,17 @@ void LilliputScript::OC_sub181BB() {
 	int c = _vm->_currentCharacterVariables[s];
 	int c2 = 0;
 
-	if ( d == 0x2D ) {
+	if (d == 0x2D) {
 		c = - 1 - c;
-	} else if ( d == 0x3E ) {
+	} else if (d == 0x3E) {
 		c = c - 0x80;
-		if ( c < 0 ) 
+		if (c < 0) 
 			c = 0;
 		c = c * 2;
-	} else if ( d == 0x3C ) {
+	} else if (d == 0x3C) {
 		c = -1 - c;
 		c = c - 0x80;
-		if ( c < 0 )
+		if (c < 0)
 			c = 0;
 		c = c * 2;
 	}
@@ -3147,7 +3147,7 @@ void LilliputScript::OC_displayTitleScreen() {
 	_vm->_mouseButton = 0;
 	_vm->_byte16F09 = 0;
 
-	while(!_vm->_shouldQuit) {
+	while (!_vm->_shouldQuit) {
 		_vm->displaySmallAnims();
 		_vm->update();
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
@@ -3243,7 +3243,7 @@ void LilliputScript::OC_sub186A1() {
 		frame -= 0xF0;
 	}
 
-	_vm->display16x16IndexedBuf(buf, frame, Common::Point(var2, var3) );
+	_vm->display16x16IndexedBuf(buf, frame, Common::Point(var2, var3));
 }
 
 void LilliputScript::OC_sub186E5_snd() {


Commit: 6dd3a1009d6203b79dd3c610fb25f924c0ee6d52
    https://github.com/scummvm/scummvm/commit/6dd3a1009d6203b79dd3c610fb25f924c0ee6d52
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix pathfinding & some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ceff413..455618e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1463,8 +1463,8 @@ void LilliputEngine::sub167EF(int index) {
 	
 	_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
 	_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
-	int var4h = (_rectXMinMax[index] >> 8);
-	int var4l = (_rectXMinMax[index] & 0xFF);
+	int var4h = (_rectXMinMax[word167EB] >> 8);
+	int var4l = (_rectXMinMax[word167EB] & 0xFF);
 	
 	if (var4h != var4l) {
 		if (_array109E9PosX[index] == var4h) {
@@ -1477,8 +1477,8 @@ void LilliputEngine::sub167EF(int index) {
 			return;
 		}
 
-		var4h = (_rectYMinMax[index] >> 8);
-		var4l = (_rectYMinMax[index] & 0xFF);
+		var4h = (_rectYMinMax[word167EB] >> 8);
+		var4l = (_rectYMinMax[word167EB] & 0xFF);
 
 		if (var4h != var4l) {
 			if (_array10A11PosY[index] == var4h)
@@ -1506,7 +1506,7 @@ void LilliputEngine::sub167EF(int index) {
 
 void LilliputEngine::sub1693A(int index) {
 	debugC(2, kDebugEngineTBC, "sub1693A(%d)", index);
-	
+
 	static const int16 mapArrayMove[4] = {4, -256, 256, -4};
 
 	_word16937Pos = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
@@ -1514,8 +1514,8 @@ void LilliputEngine::sub1693A(int index) {
 	sub16A08(index);
 	
 	int var2 = (_characterDirectionArray[index] ^ 3);
-	// initialized by sub16A08, values: [0, 6[
-	_array1692B[var2] += 0xF8;
+	// initialized by sub16A08, values: [0, 3[
+	_array1692B[var2] -= 8;
 	byte byte16939 = 0;
 	
 	int mapIndex = ((((_word16937Pos.y << 8) >> 2) + _word16937Pos.x) << 2);
@@ -1524,25 +1524,24 @@ void LilliputEngine::sub1693A(int index) {
 	for (int i = 3; i >= 0; i--) {
 		mapIndexDiff = mapArrayMove[i];
 		if (((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & _array16C54[i]) != 0) && ((_bufferIsoMap[mapIndex + 3] & _array16C58[i]) != 0)) {
-			if ((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & 0x80) != 0) {
-				if (sub16A76(i, index) != 0)
-					_array1692B[i] += 0xEC;
-
-				int tmpVal = ((_rulesBuffer2_10[index] & 7) ^ 7);
-				retVal = _rulesChunk9[_bufferIsoMap[mapIndex + mapIndexDiff]];
-				tmpVal &= retVal;
-				if (tmpVal == 0)
-					continue;
+			if ((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & 0x80) != 0 && (sub16A76(i, index) != 0)) {
+				_array1692B[i] -= 20;
 			}
+
+			int tmpVal = ((_rulesBuffer2_10[index] & 7) ^ 7);
+			retVal = _rulesChunk9[_bufferIsoMap[mapIndex + mapIndexDiff]];
+			tmpVal &= retVal;
+			if (tmpVal == 0)
+				continue;
 		}
-		_array1692B[i] = 0x9E;
+		_array1692B[i] = -98;
 		++byte16939;
 	}
 
 	if (byte16939 != 0)
 		_array1692B[_characterDirectionArray[index]] += 3;
 
-	int tmpVal = 0x9D;
+	int tmpVal = -97;
 	for (int i = 3; i >= 0; i--) {
 		if (tmpVal < _array1692B[i]) {
 			retVal = i;
@@ -1622,7 +1621,7 @@ void LilliputEngine::sub16A08(int index) {
 		_array1692B[i] = 0;
 
 	int8 tmpIndex = 0;
-	for (int i = 6; i > 0; i--) {
+	for (int i = 3; i > 0; i--) {
 		int16 tmpVal = 0x7FFF;
 		for (int j = 0; j < 4; j++) {
 			if (tmpVal > arrayDistance[j]) {
@@ -2684,7 +2683,7 @@ void LilliputEngine::handleGameScripts() {
 
 /* Decompiler follows
 
-	_scriptHandler->listAllTexts();
+	//_scriptHandler->listAllTexts();
 
 	debugC(1, kDebugEngineTBC, "================= Menu Script ==================");
 	ScriptStream script = ScriptStream(_menuScript, _menuScriptSize);
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8df04bc..2d803ce 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -114,7 +114,7 @@ public:
 	byte _byte14837; // Unused byte, set by an opcode
 
 	byte _array147D1[3];
-	byte _array1692B[4];
+	char _array1692B[4];
 	byte *_bufferIsoMap;
 	byte *_bufferCubegfx;
 	byte *_bufferMen;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 588223c..8cfa122 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -95,7 +95,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub1740A();
 		break;
 	case 0x3:
-		return OC_compareCharacterId();
+		return OC_compareCharacterVariable();
 		break;
 	case 0x4:
 		return OC_CompareByte16F02With();
@@ -269,7 +269,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17E15_speech2param();
 		break;
 	case 0x8:
-		OC_sub17B03();
+		OC_ComputeCharacterVariable();
 		break;
 	case 0x9:
 		OC_getRandom_type2();
@@ -443,7 +443,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub18260();
 		break;
 	case 0x42:
-		OC_sub182EC();
+		OC_CharacterVariableAddOrRemoveFlag();
 		break;
 	case 0x43:
 		OC_PaletteFadeOut();
@@ -560,7 +560,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_checkCharacterGoalPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_comparePos", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 	{ "OC_sub1740A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_compareCharacterId", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
+	{ "OC_compareCharacterVariable", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
 	{ "OC_CompareByte16F02With", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_getRandom", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_for", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
@@ -619,7 +619,7 @@ static const OpCode opCodes2[] = {
 /* 0x05 */	{ "OC_sub17DF9_speech1param", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x06 */	{ "OC_sub17E07_speech4param", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
 /* 0x07 */	{ "OC_sub17E15_speech2param", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-/* 0x08 */	{ "OC_sub17B03", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
+/* 0x08 */	{ "OC_ComputeCharacterVariable", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
 /* 0x09 */	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 /* 0x0b */	{ "OC_DisableCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
@@ -677,7 +677,7 @@ static const OpCode opCodes2[] = {
 /* 0x3f */	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x40 */	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x41 */	{ "OC_sub18260", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone }, // TODO
-/* 0x42 */	{ "OC_sub182EC", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x42 */	{ "OC_CharacterVariableAddOrRemoveFlag", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x43 */	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x44 */	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x45 */	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -698,7 +698,7 @@ static const OpCode opCodes2[] = {
 /* 0x54 */	{ "OC_sub184D7", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
 /* 0x55 */	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x56 */	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x57 */	{ "OC_sub1864D", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },  // TODO
+/* 0x57 */	{ "OC_sub1864D", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue}, 
 /* 0x58 */	{ "OC_initSmallAnim", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x59 */	{ "OC_sub18678", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },  //TODO
@@ -1422,8 +1422,8 @@ byte LilliputScript::OC_sub1740A() {
 	}
 }
 
-byte LilliputScript::OC_compareCharacterId() {
-	debugC(1, kDebugScript, "OC_compareCharacterId()");
+byte LilliputScript::OC_compareCharacterVariable() {
+	debugC(1, kDebugScript, "OC_compareCharacterVariable()");
 
 	byte *tmpArr = getCharacterVariablePtr();
 	byte var1 = tmpArr[0];
@@ -2254,8 +2254,8 @@ void LilliputScript::OC_sub17E15_speech2param() {
 	_currScript->readUint16LE();
 }
 
-void LilliputScript::OC_sub17B03() {
-	debugC(1, kDebugScriptTBC, "OC_sub17B03()");
+void LilliputScript::OC_ComputeCharacterVariable() {
+	debugC(1, kDebugScriptTBC, "OC_ComputeCharacterVariable()");
 
 	byte *bufPtr = getCharacterVariablePtr();
 	int oper = _currScript->readUint16LE();
@@ -2933,8 +2933,8 @@ void LilliputScript::OC_sub18260() {
 	warning("OC_sub18260()");
 }
 
-void LilliputScript::OC_sub182EC() {
-	debugC(1, kDebugScriptTBC, "OC_sub182EC()");
+void LilliputScript::OC_CharacterVariableAddOrRemoveFlag() {
+	debugC(1, kDebugScriptTBC, "OC_CharacterVariableAddOrRemoveFlag()");
 
 	byte *tmpArr = getCharacterVariablePtr();
 
@@ -2942,7 +2942,7 @@ void LilliputScript::OC_sub182EC() {
 	byte var2 = (_currScript->readUint16LE() & 0xFF);
 
 	if (var2 == 0)
-		tmpArr[0] = (0xFF ^ var1);
+		tmpArr[0] &= ~var1;
 	else
 		tmpArr[0] |= var1;
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 0509259..08ed983 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -149,7 +149,7 @@ private:
 	byte OC_checkCharacterGoalPos();
 	byte OC_comparePos();
 	byte OC_sub1740A();
-	byte OC_compareCharacterId();
+	byte OC_compareCharacterVariable();
 	byte OC_CompareByte16F02With();
 	byte OC_getRandom();
 	byte OC_for();
@@ -206,7 +206,7 @@ private:
 	void OC_sub17DF9_speech1param();
 	void OC_sub17E07_speech4param();
 	void OC_sub17E15_speech2param();
-	void OC_sub17B03();
+	void OC_ComputeCharacterVariable();
 	void OC_getRandom_type2();
 	void OC_setCharacterPosition();
 	void OC_DisableCharacter();
@@ -265,7 +265,7 @@ private:
 	void OC_sub18213();
 	void OC_sub18252();
 	void OC_sub18260();
-	void OC_sub182EC();
+	void OC_CharacterVariableAddOrRemoveFlag();
 	void OC_PaletteFadeOut();
 	void OC_PaletteFadeIn();
 	void OC_loadAndDisplayCUBESx_GFX();


Commit: 29b476fc565afbbffba860a37103e66a5c2410d5
    https://github.com/scummvm/scummvm/commit/29b476fc565afbbffba860a37103e66a5c2410d5
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some refactoring, fix a bug in fixx16x16Rect

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 455618e..de10000 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -289,7 +289,7 @@ bool LilliputEngine::hasFeature(EngineFeature f) const {
 }
 
 const char *LilliputEngine::getCopyrightString() const {
-	return "copyright S.L.Grand, Brainware, 1991";
+	return "copyright S.L.Grand, Brainware, 1991 - 1992";
 }
 
 GameType LilliputEngine::getGameType() const {
@@ -301,9 +301,9 @@ Common::Platform LilliputEngine::getPlatform() const {
 }
 
 void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
-	debugC(2, kDebugEngineTBC, "displayCharacter(%d, %d - %d, %d)", index, pos.x, pos.y, flags);
+	debugC(2, kDebugEngine, "displayCharacter(%d, %d - %d, %d)", index, pos.x, pos.y, flags);
 
-	byte *buf = _savedSurfaceGameArea1 + (pos.y << 8) + pos.x;
+	byte *buf = _savedSurfaceGameArea1 + (pos.y * 256) + pos.x;
 
 	byte *src = _bufferMen;
 	if (index < 0) {
@@ -314,7 +314,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 		index -= 0xF0;
 	}
 
-	src += ((index & 0xFF) << 8) + (index >> 8);
+	src += (index * 256);
 
 	if ((flags & 2) == 0) {
 		for (int y = 0; y < 16; y++) {
@@ -342,11 +342,10 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point pos) {
 	debugC(2, kDebugEngine, "display16x16IndexedBuf(buf, %d, %d, %d)", index, pos.x, pos.y);
 
-	int index1 = ((index & 0xFF) << 8) + (index >> 8);
+	int index1 = index * 16 * 16;
 	byte *newBuf = &buf[index1];
 
-	int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
-	int index2 = pos.x + tmpVal + (tmpVal >> 2);
+	int index2 = pos.x + (pos.y * 320);
 
 	for (int i = 0; i < 16; i++) {
 		for (int j = 0; j < 16; j++) {
@@ -369,8 +368,7 @@ void LilliputEngine::display16x16Buf(byte *buf, Common::Point pos) {
 void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
 	debugC(2, kDebugEngine, "SaveSurfaceUnderMouseCursor(buf, %d, %d)", pos.x, pos.y);
 
-	int tmpVal = ((pos.y & 0xFF) << 8) + (pos.y >> 8);
-	int index2 = pos.x + tmpVal + (tmpVal >> 2);
+	int index2 = pos.x + (pos.y * 320);
 
 	for (int i = 0; i < 16; i++) {
 		for (int j = 0; j < 16; j++) {
@@ -380,12 +378,10 @@ void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
 	}
 }
 
-void LilliputEngine::fill16x16Rect(int var1, int var2, int var4) {
-	debugC(2, kDebugEngineTBC, "fill16x16Rect(%d, %d, %d)", var1, var2, var4);
+void LilliputEngine::fill16x16Rect(byte col, Common::Point pos) {
+	debugC(2, kDebugEngineTBC, "fill16x16Rect(%d, %d - %d)", col, pos.x, pos.y);
 
-	int tmpVal = ((var4 >> 8) + (var4 & 0xFF));
-	int index = var2 + tmpVal + (tmpVal >> 2);
-	int col = var1 & 0xFF;
+	int index = pos.x + (pos.y * 320);
 	for (int i = 0; i < 16; i++) {
 		for (int j = 0; j < 16; j++) {
 			((byte *)_mainSurface->getPixels())[index + j] = col;
@@ -421,7 +417,7 @@ void LilliputEngine::restoreSurfaceUnderMousePointer() {
 }
 
 void LilliputEngine::saveSurfaceGameArea() {
-	debugC(2, kDebugEngineTBC, "saveSurfaceGameArea()");
+	debugC(2, kDebugEngine, "saveSurfaceGameArea()");
 
 	restoreSurfaceUnderMousePointer();
 
@@ -467,17 +463,16 @@ void LilliputEngine::restoreSurfaceSpeech() {
 
 
 void LilliputEngine::displayInterfaceHotspots() {
-	debugC(2, kDebugEngineTBC, "displayInterfaceHotspots()");
+	debugC(2, kDebugEngine, "displayInterfaceHotspots()");
 
 	if (_displayMap == 1)
 		return;
 
 	restoreSurfaceUnderMousePointer();
 
-	int index = 0;
 	int tmpVal;
-	for (index = 0; index < _word12F68_ERULES; index++) {
-		tmpVal = ((_scriptHandler->_array122E9[index] << 2) + (_scriptHandler->_array122E9[index] << 4)) & 0xFF;
+	for (int index = 0; index < _word12F68_ERULES; index++) {
+		tmpVal = _scriptHandler->_array122E9[index] * 20;
 		display16x16IndexedBuf(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
 	}
 
@@ -592,16 +587,18 @@ void LilliputEngine::displayFunction11(byte *buf) {
 	displayMousePointer();
 }
 
-void LilliputEngine::displayFunction12() {
-	debugC(1, kDebugEngineTBC, "displayFunction12()");
+void LilliputEngine::initGameAreaDisplay() {
+	debugC(1, kDebugEngine, "initGameAreaDisplay()");
 
 	restoreSurfaceUnderMousePointer();
 
+	// display background
 	byte *tmpBuf = loadVGA("SCREEN.GFX", 320 * 200, true);
 	memcpy(_mainSurface->getPixels(), tmpBuf, 320 * 200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
 
+	// display game area on top of background
 	saveSurfaceGameArea();
 	saveSurfaceSpeech();
 	displayInterfaceHotspots();
@@ -609,6 +606,7 @@ void LilliputEngine::displayFunction12() {
 	prepareGameArea();
 	displayGameArea();
 
+	// display mouse pointer on top of the rest
 	displayMousePointer();
 	free(tmpBuf);
 }
@@ -760,7 +758,7 @@ void LilliputEngine::setNextDisplayCharacter(int var1) {
 }
 
 void LilliputEngine::prepareGameArea() {
-	debugC(2, kDebugEngineTBC, "prepareGameArea()");
+	debugC(2, kDebugEngine, "prepareGameArea()");
 
 	moveCharacters();
 	_currentDisplayCharacter = 0;
@@ -1006,7 +1004,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 	paletteFadeOut();
 	_word15AC2 = 0;
 	sub130B6();
-	displayFunction12();
+	initGameAreaDisplay();
 	_scriptHandler->_heroismLevel = 0;
 	moveCharacters();
 	paletteFadeIn();
@@ -1284,7 +1282,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 }
 
 void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
-	debugC(2, kDebugEngineTBC, "renderCharacters(buf, %d - %d)", pos.x, pos.y);
+	debugC(2, kDebugEngine, "renderCharacters(buf, %d - %d)", pos.x, pos.y);
 
 	if (_nextDisplayCharacterPos != pos)
 		return;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 2d803ce..93b1ff1 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -219,7 +219,7 @@ public:
 	void display16x16IndexedBuf(byte *buf, int var1, Common::Point pos);
 	void display16x16Buf(byte *buf, Common::Point pos);
 	void SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos);
-	void fill16x16Rect(int var1, int var2, int var4);
+	void fill16x16Rect(byte col, Common::Point pos);
 	void displayMousePointer();
 	void restoreSurfaceUnderMousePointer();
 	void saveSurfaceGameArea();
@@ -228,7 +228,7 @@ public:
 	void displayLandscape();
 	void displayFunction10();
 	void displayFunction11(byte *buf);
-	void displayFunction12();
+	void initGameAreaDisplay();
 	void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
 	void displayGameArea();
 	void prepareGameArea();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 8cfa122..f0f0aa5 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1358,7 +1358,7 @@ Common::Point LilliputScript::getPosFromScript() {
 }
 
 void LilliputScript::sub130B6() {
-	debugC(1, kDebugScriptTBC, "sub130B6()");
+	debugC(1, kDebugScript, "sub130B6()");
 
 	assert(_vm->_word12F68_ERULES <= 20);
 	for (int i = 0; i < _vm->_word12F68_ERULES; i++) {
@@ -3174,7 +3174,7 @@ void LilliputScript::OC_sub1853B() {
 	_heroismLevel = 0;
 	sub130B6();
 
-	_vm->displayFunction12();
+	_vm->initGameAreaDisplay();
 
 	OC_PaletteFadeIn();
 	_byte12A09 = 0;
@@ -3228,14 +3228,13 @@ void LilliputScript::OC_sub186A1() {
 	debugC(1, kDebugScriptTBC, "OC_sub186A1()");
 
 	int var1 = getValue1();
-	int var2 = _currScript->readUint16LE();
-	int var3 = _currScript->readUint16LE();
-	int var4 = 16;
+	int posX = _currScript->readUint16LE();
+	int posY = _currScript->readUint16LE();
+	Common::Point pos = Common::Point(posX, posY);
 
-	_vm->fill16x16Rect(var4, var2, var3);
+	_vm->fill16x16Rect(16, pos);
 
 	int frame = _vm->_characterFrameArray[var1];
-
 	byte* buf = _vm->_bufferMen;
 
 	if (frame > 0xF0) {
@@ -3243,7 +3242,7 @@ void LilliputScript::OC_sub186A1() {
 		frame -= 0xF0;
 	}
 
-	_vm->display16x16IndexedBuf(buf, frame, Common::Point(var2, var3));
+	_vm->display16x16IndexedBuf(buf, frame, pos);
 }
 
 void LilliputScript::OC_sub186E5_snd() {


Commit: 1c0efa5581b7ed86fcff12f9431a8daba465493c
    https://github.com/scummvm/scummvm/commit/1c0efa5581b7ed86fcff12f9431a8daba465493c
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index de10000..d5700be 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2772,13 +2772,7 @@ void LilliputEngine::initialize() {
 }
 
 byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
-	debugC(1, kDebugEngineTBC, "getCharacterVariablesPtr(%d)", index);
-
-/* used to debug
-	if (index == 96 + 22) {	
-		int a = 0;
-	}
-*/
+	debugC(1, kDebugEngine, "getCharacterVariablesPtr(%d)", index);
 
 	assert((index > -3120) && (index < 1400));
 	if (index >= 0)
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f0f0aa5..2e43114 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -491,7 +491,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1844A();
 		break;
 	case 0x52:
-		OC_sub1847F();
+		OC_displayNumericCharacterVariable();
 		break;
 	case 0x53:
 		OC_displayVGAFile();
@@ -503,7 +503,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_displayTitleScreen();
 		break;
 	case 0x56:
-		OC_sub1853B();
+		OC_initGameAreaDisplay();
 		break;
 	case 0x57:
 		OC_sub1864D();
@@ -548,7 +548,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub18764();
 		break;
 	case 0x65:
-		OC_sub1853B();
+		OC_initGameAreaDisplay();
 		break;
 	default:
 		error("Unknown opcode %d", curWord);
@@ -693,11 +693,11 @@ static const OpCode opCodes2[] = {
 /* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x50 */	{ "OC_sub17E22_speech1IfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x52 */	{ "OC_sub1847F", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+/* 0x52 */	{ "OC_displayNumericCharacterVariable", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x53 */	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x54 */	{ "OC_sub184D7", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
 /* 0x55 */	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x56 */	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x56 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x57 */	{ "OC_sub1864D", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue}, 
 /* 0x58 */	{ "OC_initSmallAnim", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x59 */	{ "OC_sub18678", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
@@ -712,7 +712,7 @@ static const OpCode opCodes2[] = {
 /* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x63 */	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x64 */	{ "OC_sub18764", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x65 */	{ "OC_sub1853B", 0, kNone, kNone, kNone, kNone, kNone }
+/* 0x65 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
 Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream& script) {
@@ -3086,26 +3086,26 @@ void LilliputScript::OC_sub1844A() {
 	}
 }
 
-void LilliputScript::OC_sub1847F() {
-	debugC(1, kDebugScriptTBC, "OC_sub1847F()");
+void LilliputScript::OC_displayNumericCharacterVariable() {
+	debugC(1, kDebugScript, "OC_displayNumericCharacterVariable()");
 
 	byte *buf215Ptr = getCharacterVariablePtr();
 	byte tmpVal = buf215Ptr[0];
 	int curWord = _currScript->readUint16LE();
 	assert(curWord != 0);
-	int var1 = tmpVal / (curWord & 0xFF);
-	int var2 = _currScript->readSint16LE();
-	int var4 = _currScript->readSint16LE();
+	int displayVal = tmpVal / (curWord & 0xFF);
+	int posX = _currScript->readSint16LE();
+	int posY = _currScript->readSint16LE();
 
 	if (_vm->_displayMap != 1) {
 		_vm->restoreSurfaceUnderMousePointer();
-		displayNumber(var1 & 0xFF, Common::Point(var2, var4));
+		displayNumber(displayVal, Common::Point(posX, posY));
 		_vm->displayMousePointer();
 	}
 }
 
 void LilliputScript::displayNumber(byte var1, Common::Point pos) {
-	debugC(1, kDebugScriptTBC, "displayNumber(%d, %d - %d)", var1, pos.x, pos.y);
+	debugC(1, kDebugScript, "displayNumber(%d, %d - %d)", var1, pos.x, pos.y);
 
 	_vm->_displayStringIndex = 0;
 	_vm->_displayStringBuf[0] = 32;
@@ -3166,8 +3166,8 @@ void LilliputScript::OC_displayTitleScreen() {
 	_vm->_mouseButton = 0;
 }
 
-void LilliputScript::OC_sub1853B() {
-	debugC(1, kDebugScriptTBC, "OC_sub1853B()");
+void LilliputScript::OC_initGameAreaDisplay() {
+	debugC(1, kDebugScript, "OC_initGameAreaDisplay()");
 
 	OC_PaletteFadeOut();
 	_vm->_displayMap = 0;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 08ed983..f73121a 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -281,11 +281,11 @@ private:
 	void OC_loadFile_AERIAL_GFX();
 	void OC_sub17E22_speech1IfSoundOff();
 	void OC_sub1844A();
-	void OC_sub1847F();
+	void OC_displayNumericCharacterVariable();
 	void OC_displayVGAFile();
 	void OC_sub184D7();
 	void OC_displayTitleScreen();
-	void OC_sub1853B();
+	void OC_initGameAreaDisplay();
 	void OC_sub1864D();
 	void OC_initSmallAnim();
 	void OC_sub18678();


Commit: 3a102e6f24f756d7dad15c709dd32be8c46f19c1
    https://github.com/scummvm/scummvm/commit/3a102e6f24f756d7dad15c709dd32be8c46f19c1
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming, fix issue in OC_sub17640, implement OC_sub18690

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index d5700be..97f7239 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -203,8 +203,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_rulesBuffer2_10[i] = 0;
 		_rulesBuffer2_11[i] = 0;
 		_rulesBuffer2_12[i] = 0;
-		_rulesBuffer2_13[i] = 0;
-		_rulesBuffer2_14[i] = 0;
+		_rulesBuffer2_13_posX[i] = 0;
+		_rulesBuffer2_14_posY[i] = 0;
 		_array1289F[i] = 0xFFFF;
 	}
 
@@ -1135,7 +1135,7 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 }
 
 void LilliputEngine::displayString(byte *buf, Common::Point pos) {
-	debugC(2, kDebugEngineTBC, "displayString(buf, %d - %d)", pos.x, pos.y);
+	debugC(2, kDebugEngine, "displayString(%s, %d - %d)", buf, pos.x, pos.y);
 
 	int index = (pos.y * 320) + pos.x;
 
@@ -1148,7 +1148,7 @@ void LilliputEngine::displayString(byte *buf, Common::Point pos) {
 }
 
 void LilliputEngine::displayChar(int index, int var1) {
-	debugC(2, kDebugEngineTBC, "displayChar(%d, %d)", index, var1);
+	debugC(2, kDebugEngine, "displayChar(%d, %d)", index, var1);
 
 	int indexVga = index;
 	int indexChar = var1 << 5;
@@ -1633,15 +1633,15 @@ void LilliputEngine::sub16A08(int index) {
 }
 
 void LilliputEngine::addCharToBuf(byte character) {
-	debugC(2, kDebugEngineTBC, "addCharToBuf(%c)", character);
+	debugC(2, kDebugEngine, "addCharToBuf(%c)", character);
 
 	_displayStringBuf[_displayStringIndex] = character;
 	if (_displayStringIndex < 158)
 		++_displayStringIndex;
 }
 
-void LilliputEngine::prepareGoldAmount(int param1) {
-	debugC(2, kDebugEngineTBC, "prepareGoldAmount(%d)", param1);
+void LilliputEngine::numberToString(int param1) {
+	debugC(2, kDebugEngine, "numberToString(%d)", param1);
 	
 	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
 
@@ -2454,8 +2454,8 @@ void LilliputEngine::loadRules() {
 		_rulesBuffer2_10[j] = f.readByte();
 		_rulesBuffer2_11[j] = f.readByte();
 		_rulesBuffer2_12[j] = f.readByte();
-		_rulesBuffer2_13[j] = f.readByte();
-		_rulesBuffer2_14[j] = f.readByte();
+		_rulesBuffer2_13_posX[j] = f.readByte();
+		_rulesBuffer2_14_posY[j] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
 			_characterVariables_[(j * 32) + k] = f.readByte();
@@ -2546,10 +2546,10 @@ void LilliputEngine::loadRules() {
 		_rulesBuffer13_1[i] = f.readByte();
 
 	for (int i = 0 ; i < 20; i++)
-		_interfaceHotspotsX[i] = f.readUint16LE();
+		_interfaceHotspotsX[i] = f.readSint16LE();
 
 	for (int i = 0 ; i < 20; i++)
-		_interfaceHotspotsY[i] = f.readUint16LE();
+		_interfaceHotspotsY[i] = f.readSint16LE();
 
 	for (int i = 0; i < 20; i++) {
 		byte curByte = f.readByte();
@@ -2611,16 +2611,16 @@ void LilliputEngine::initPalette() {
 	_system->getPaletteManager()->setPalette(_curPalette, 0, 256);
 }
 
-void LilliputEngine::sub170EE(int index) {
-	debugC(1, kDebugEngineTBC, "sub170EE(%d)", index);
+void LilliputEngine::setCurrentCharacter(int index) {
+	debugC(1, kDebugEngine, "setCurrentCharacter(%d)", index);
 
 	_currentScriptCharacter = index;
 
 	assert (index < 40);
-	int var2 = _characterPositionX[index];
-	int var4 = _characterPositionY[index];
+	int posX = _characterPositionX[index];
+	int posY = _characterPositionY[index];
 
-	_currentScriptCharacterPos = Common::Point(var2 >> 3, var4 >> 3);
+	_currentScriptCharacterPos = Common::Point(posX >> 3, posY >> 3);
 	_currentCharacterVariables = getCharacterVariablesPtr(_currentScriptCharacter * 32);
 }
 
@@ -2637,7 +2637,7 @@ void LilliputEngine::handleMenu() {
 	if ((_byte12FCE == 1) && (_byte16F07_menuId != 3))
 		return;
 
-	sub170EE(_word10804);
+	setCurrentCharacter(_word10804);
 	debugC(1, kDebugScriptTBC, "========================== Menu Script ==============================");
 	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScriptSize));
 	debugC(1, kDebugScriptTBC, "========================== End of Menu Script==============================");
@@ -2668,7 +2668,7 @@ void LilliputEngine::handleGameScripts() {
 
 
 	_scriptHandler->_characterScriptEnabled[index] = 0;
-	sub170EE(index);
+	setCurrentCharacter(index);
 
 
 	_word16EFE = _array11D49[index];
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 93b1ff1..84b1a60 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -161,8 +161,8 @@ public:
 	byte _rulesBuffer2_10[40];
 	byte _rulesBuffer2_11[40];
 	byte _rulesBuffer2_12[40];
-	byte _rulesBuffer2_13[40];
-	byte _rulesBuffer2_14[40];
+	byte _rulesBuffer2_13_posX[40];
+	byte _rulesBuffer2_14_posY[40];
 	byte _characterVariables_[1400 + 3120];
 	byte *_currentCharacterVariables;
 	byte _rulesBuffer2_16[40 * 32];
@@ -187,8 +187,8 @@ public:
 	Common::Point _rulesBuffer12Pos4[40];
 	int _word12F68_ERULES;
 	byte _rulesBuffer13_1[20];
-	int _interfaceHotspotsX[20];
-	int _interfaceHotspotsY[20];
+	int16 _interfaceHotspotsX[20];
+	int16 _interfaceHotspotsY[20];
 	byte _rulesBuffer13_4[20];
 	int16 _array10999PosX[40];
 	int16 _array109C1PosY[40];
@@ -216,7 +216,7 @@ public:
 	void newInt8();
 	void update();
 
-	void display16x16IndexedBuf(byte *buf, int var1, Common::Point pos);
+	void display16x16IndexedBuf(byte *buf, int index, Common::Point pos);
 	void display16x16Buf(byte *buf, Common::Point pos);
 	void SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos);
 	void fill16x16Rect(byte col, Common::Point pos);
@@ -267,7 +267,7 @@ public:
 	byte sub16799(int index, Common::Point param1);
 	int getDirection(Common::Point param1, Common::Point param2);
 	void addCharToBuf(byte character);
-	void prepareGoldAmount(int param1);
+	void numberToString(int param1);
 	void sub12F37();
 	byte sub16675(int idx, Common::Point var1);
 	void sub16685(int idx, Common::Point var1);
@@ -343,7 +343,7 @@ public:
 
 
 	void pollEvent();
-	void sub170EE(int index);
+	void setCurrentCharacter(int index);
 	void sub130DD();
 	void moveCharacters();
 	void setNextDisplayCharacter(int var1);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 2e43114..2f784f8 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -353,7 +353,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_resetWord16EFE();
 		break;
 	case 0x24:
-		OC_sub17CEF();
+		OC_enableCurrentCharacterScript();
 		break;
 	case 0x25:
 		OC_IncCurrentCharacterVar1();
@@ -464,7 +464,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub18367();
 		break;
 	case 0x49:
-		OC_sub17D04();
+		OC_enableCharacterScript();
 		break;
 	case 0x4A:
 		OC_sub18387();
@@ -512,7 +512,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_initSmallAnim();
 		break;
 	case 0x59:
-		OC_sub18678();
+		OC_setCharacterHeroismBar();
 		break;
 	case 0x5A:
 		OC_sub18690();
@@ -545,7 +545,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1875D_snd();
 		break;
 	case 0x64:
-		OC_sub18764();
+		OC_setArray128E();
 		break;
 	case 0x65:
 		OC_initGameAreaDisplay();
@@ -647,7 +647,7 @@ static const OpCode opCodes2[] = {
 /* 0x21 */	{ "OC_sub17CB9", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone }, 
 /* 0x22 */	{ "OC_sub17CD1", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x24 */	{ "OC_sub17CEF", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
+/* 0x24 */	{ "OC_enableCurrentCharacterScript", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
 /* 0x25 */	{ "OC_IncCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone }, 
 /* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -684,7 +684,7 @@ static const OpCode opCodes2[] = {
 /* 0x46 */	{ "OC_sub1834C", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x47 */	{ "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x48 */	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x49 */	{ "OC_sub17D04", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x49 */	{ "OC_enableCharacterScript", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x4a */	{ "OC_sub18387", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x4b */	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
@@ -700,7 +700,7 @@ static const OpCode opCodes2[] = {
 /* 0x56 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x57 */	{ "OC_sub1864D", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue}, 
 /* 0x58 */	{ "OC_initSmallAnim", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
-/* 0x59 */	{ "OC_sub18678", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x59 */	{ "OC_setCharacterHeroismBar", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },  //TODO
 /* 0x5b */	{ "OC_setViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x5c */	{ "OC_sub186A1", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },  //TODO
@@ -711,7 +711,7 @@ static const OpCode opCodes2[] = {
 /* 0x61 */	{ "OC_sub1873F_snd", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x63 */	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x64 */	{ "OC_sub18764", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x64 */	{ "OC_setArray128E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x65 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
@@ -1022,8 +1022,8 @@ void LilliputScript::computeOperation(byte *bufPtr, int oper, int var3) {
 	}
 }
 
-void LilliputScript::sub1823E(byte index, byte var1, byte *curBufPtr) {
-	debugC(1, kDebugScriptTBC, "sub1823E(%d, %d, curBufPtr)", index, var1);
+void LilliputScript::enableCharacterScript(byte index, byte var1, byte *curBufPtr) {
+	debugC(1, kDebugScript, "enableCharacterScript(%d, %d, curBufPtr)", index, var1);
 
 	assert (index < 40);
 	_characterScriptEnabled[index] = 1;
@@ -1174,7 +1174,7 @@ void LilliputScript::decodePackedText(char *buf) {
 				var1 = buf[index];
 				++index;
 				if (var1 == '#') {
-					_vm->prepareGoldAmount(_byte18823);
+					_vm->numberToString(_byte18823);
 				}
 			} else {
 				_vm->addCharToBuf(var1);
@@ -1307,11 +1307,11 @@ Common::Point LilliputScript::getPosFromScript() {
 	switch(tmpVal) {
 	case 0xFF:
 		assert((_vm->_currentScriptCharacter >= 0) && (_vm->_currentScriptCharacter < 40));
-		return Common::Point(_vm->_rulesBuffer2_13[_vm->_currentScriptCharacter], _vm->_rulesBuffer2_14[_vm->_currentScriptCharacter]);
+		return Common::Point(_vm->_rulesBuffer2_13_posX[_vm->_currentScriptCharacter], _vm->_rulesBuffer2_14_posY[_vm->_currentScriptCharacter]);
 	case 0xFE: {
 		int8 index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
-		return Common::Point(_vm->_rulesBuffer2_13[index], _vm->_rulesBuffer2_14[index]);
+		return Common::Point(_vm->_rulesBuffer2_13_posX[index], _vm->_rulesBuffer2_14_posY[index]);
 		}
 	case 0xFD:
 		return _vm->_currentScriptCharacterPos;
@@ -1481,7 +1481,7 @@ byte LilliputScript::OC_compWord18776() {
 }
 
 byte LilliputScript::OC_checkSaveFlag() {
-	debugC(1, kDebugScriptTBC, "OC_checkSaveFlag()");
+	debugC(1, kDebugScript, "OC_checkSaveFlag()");
 
 	if (_vm->_saveFlag)
 		return 1;
@@ -1602,7 +1602,7 @@ byte LilliputScript::OC_compareRandomCharacterId() {
 }
 
 byte LilliputScript::OC_IsCurrentCharacterIndex() {
-	debugC(1, kDebugScriptTBC, "OC_IsCurrentCharacterIndex()");
+	debugC(1, kDebugScript, "OC_IsCurrentCharacterIndex()");
 	
 	int tmpVal = getValue1();
 	if (tmpVal == _vm->_currentScriptCharacter)
@@ -1611,10 +1611,9 @@ byte LilliputScript::OC_IsCurrentCharacterIndex() {
 }
 
 byte LilliputScript::OC_sub175C8() {
-	debugC(1, kDebugScriptTBC, "OC_sub175C8()");
+	debugC(1, kDebugScript, "OC_sub175C8()");
 	
 	byte var4 = _currScript->readUint16LE() & 0xFF;
-
 	int tmpVal = _currScript->readUint16LE();
 	
 	if (tmpVal < 2000) {
@@ -1643,11 +1642,9 @@ byte LilliputScript::OC_sub175C8() {
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
 		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
-		if ((var1 & 0xFF) >= var4) {
-			if (_vm->_rulesBuffer2_12[i] == var4b) {
-				_word16F00 = i;
-				return 1;
-			}
+		if (((var1 & 0xFF) >= var4) && (_vm->_rulesBuffer2_12[i] == var4b)) {
+			_word16F00 = i;
+			return 1;
 		}
 	}	
 	
@@ -1655,41 +1652,13 @@ byte LilliputScript::OC_sub175C8() {
 }
 
 byte LilliputScript::OC_sub17640() {
-	debugC(1, kDebugScriptTBC, "OC_sub176C4()");
+	debugC(1, kDebugScript, "OC_sub176C4()");
 
 	int var4 = _currScript->readUint16LE();
 	int index = _vm->_currentScriptCharacter * 40;
 	int tmpVal = _currScript->readUint16LE();
 
-	if (tmpVal >= 2000) {
-		int var1 = tmpVal;
-
-		if (var1 == 3000) {
-			for (int i = 0; i < _vm->_numCharacters; i++) {
-				tmpVal = _array10B51[index + i];
-				byte v1 = tmpVal & 0xFF;
-				byte v2 = tmpVal >> 8;
-				if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF))) {
-					_word16F00 = i;
-					return 1;
-				}
-			}
-			return 0;
-		} else {
-			var1 -= 2000;
-			var4 &= ((var1 & 0xFF) << 8);
-			for (int i = 0; i < _vm->_numCharacters; i++) {
-				tmpVal = _array10B51[index + i];
-				byte v1 = tmpVal & 0xFF;
-				byte v2 = tmpVal >> 8;
-				if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF)) && (_vm->_rulesBuffer2_12[i] != (var4 >> 8))) {
-					_word16F00 = i;
-					return 1;
-				}
-			}
-			return 0;
-		}
-	} else {
+	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int subIndex = getValue1();
 		tmpVal = _array10B51[index + subIndex];
@@ -1700,6 +1669,33 @@ byte LilliputScript::OC_sub17640() {
 		_word16F00 = subIndex;
 		return 1;
 	}
+
+	int var1 = tmpVal;
+	if (var1 == 3000) {
+		for (int i = 0; i < _vm->_numCharacters; i++) {
+			tmpVal = _array10B51[index + i];
+			byte v1 = tmpVal & 0xFF;
+			byte v2 = tmpVal >> 8;
+			if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF))) {
+				_word16F00 = i;
+				return 1;
+			}
+		}
+		return 0;
+	} 
+
+	var1 -= 2000;
+	var4 = ((var1 & 0xFF) << 8) + (var4 & 0xFF);
+	for (int i = 0; i < _vm->_numCharacters; i++) {
+		tmpVal = _array10B51[index + i];
+		byte v1 = tmpVal & 0xFF;
+		byte v2 = tmpVal >> 8;
+		if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF)) && (_vm->_rulesBuffer2_12[i] == (var4 >> 8))) {
+			_word16F00 = i;
+			return 1;
+		}
+	}
+	return 0;
 }
 
 byte LilliputScript::OC_sub176C4() {
@@ -1811,7 +1807,7 @@ byte LilliputScript::OC_IsCharacterValid() {
 }
 
 byte LilliputScript::OC_compWord16EFE() {
-	debugC(1, kDebugScriptTBC, "OC_compWord16EFE()");
+	debugC(1, kDebugScript, "OC_compWord16EFE()");
 
 	byte curByte = _currScript->readUint16LE() & 0xFF;
 	byte tmpVal = _vm->_word16EFE >> 8;
@@ -1824,7 +1820,7 @@ byte LilliputScript::OC_compWord16EFE() {
 }
 
 byte LilliputScript::OC_AreCurrentCharacterVar0AndVar1EqualsTo() {
-	debugC(1, kDebugScriptTBC, "OC_AreCurrentCharacterVar0AndVar1EqualsTo()");
+	debugC(1, kDebugScript, "OC_AreCurrentCharacterVar0AndVar1EqualsTo()");
 
 	byte var1 = _currScript->readUint16LE() & 0xFF;
 	byte var2 = _currScript->readUint16LE() & 0xFF;
@@ -1838,7 +1834,7 @@ byte LilliputScript::OC_AreCurrentCharacterVar0AndVar1EqualsTo() {
 }
 
 byte LilliputScript::OC_CurrentCharacterVar0Equals() {
-	debugC(1, kDebugScriptTBC, "OC_CurrentCharacterVar0Equals()");
+	debugC(1, kDebugScript, "OC_CurrentCharacterVar0Equals()");
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 	assert(_vm->_currentCharacterVariables != NULL);
@@ -1920,7 +1916,7 @@ byte LilliputScript::OC_skipNextOpcode() {
 }
 
 byte LilliputScript::OC_CurrentCharacterVar2Equals1() {
-	debugC(1, kDebugScriptTBC, "OC_CurrentCharacterVar2Equals1()");
+	debugC(1, kDebugScript, "OC_CurrentCharacterVar2Equals1()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	if (_vm->_currentCharacterVariables[2] == 1)
@@ -1980,7 +1976,7 @@ byte LilliputScript::OC_sub1790F() {
 }
 
 byte LilliputScript::OC_CurrentCharacterVar1Equals() {
-	debugC(1, kDebugScriptTBC, "OC_CurrentCharacterVar1Equals()");
+	debugC(1, kDebugScript, "OC_CurrentCharacterVar1Equals()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
@@ -2004,7 +2000,7 @@ byte LilliputScript::OC_sub1793E() {
 }
 
 byte LilliputScript::OC_CurrentCharacterVar3Equals1() {
-	debugC(1, kDebugScriptTBC, "OC_CurrentCharacterVar3Equals1()");
+	debugC(1, kDebugScript, "OC_CurrentCharacterVar3Equals1()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	if (_vm->_currentCharacterVariables[3] == 1)
@@ -2361,7 +2357,7 @@ void LilliputScript::OC_callScript() {
 	int index = _currScript->readUint16LE();
 	int var1 = getValue1();
 
-	_vm->sub170EE(var1);
+	_vm->setCurrentCharacter(var1);
 	int tmpIndex = _vm->_currentScriptCharacter;
 
 	assert(index < _vm->_gameScriptIndexSize);
@@ -2380,11 +2376,11 @@ void LilliputScript::OC_callScript() {
 
 	_currScript = _scriptStack.pop();
 
-	_vm->sub170EE(tmpIndex);
+	_vm->setCurrentCharacter(tmpIndex);
 }
 
 void LilliputScript::OC_callScriptAndReturn() {
-	debugC(1, kDebugScriptTBC, "OC_callScriptAndReturn()");
+	debugC(1, kDebugScript, "OC_callScriptAndReturn()");
 
 	OC_callScript();
 	sub17B6C(0);
@@ -2468,7 +2464,7 @@ void LilliputScript::OC_sub17C76() {
 void LilliputScript::OC_sub17AFC() {
 	debugC(1, kDebugScriptTBC, "OC_sub17AFC()");
 	int var1 = getValue1();
-	_vm->sub170EE(var1);
+	_vm->setCurrentCharacter(var1);
 }
 
 void LilliputScript::sub171AF(int var1, int var2, int var4) {
@@ -2535,11 +2531,11 @@ void LilliputScript::OC_resetWord16EFE() {
 	_vm->_word16EFE = 0xFFFF;
 }
 
-void LilliputScript::OC_sub17CEF() {
-	debugC(1, kDebugScriptTBC, "OC_sub17CEF()");
+void LilliputScript::OC_enableCurrentCharacterScript() {
+	debugC(1, kDebugScriptTBC, "OC_enableCurrentCharacterScript()");
 
 	int var1 = _currScript->readUint16LE();
-	sub1823E(_vm->_currentScriptCharacter , var1, _vm->_currentCharacterVariables);
+	enableCharacterScript(_vm->_currentScriptCharacter , var1, _vm->_currentCharacterVariables);
 	sub17B6C(0);
 }
 
@@ -2917,7 +2913,7 @@ void LilliputScript::OC_sub18213() {
 			maxItem = _array1813BPos[i].x;
 		}
 	}
-	sub1823E(_vm->_currentScriptCharacter, maxItem, _vm->_currentCharacterVariables);
+	enableCharacterScript(_vm->_currentScriptCharacter, maxItem, _vm->_currentCharacterVariables);
 }
 
 void LilliputScript::OC_sub18252() {
@@ -3002,13 +2998,13 @@ void LilliputScript::OC_sub18367() {
 	_vm->_currentCharacterVariables[3] = 0;
 }
 
-void LilliputScript::OC_sub17D04() {
-	debugC(1, kDebugScriptTBC, "OC_sub17D04()");
+void LilliputScript::OC_enableCharacterScript() {
+	debugC(1, kDebugScript, "OC_enableCharacterScript()");
 
 	int16 index = getValue1();
 	byte var2 = _currScript->readUint16LE() & 0xFF;
 	
-	sub1823E(index, var2, _vm->getCharacterVariablesPtr(index * 32));
+	enableCharacterScript(index, var2, _vm->getCharacterVariablesPtr(index * 32));
 }
 
 void LilliputScript::OC_sub18387() {
@@ -3036,13 +3032,13 @@ void LilliputScript::OC_setByte14837() {
 void LilliputScript::OC_sub183A2() {
 	warning("OC_sub183A2");
 }
+
 void LilliputScript::OC_sub183C6() {
 	debugC(1, kDebugScriptTBC, "OC_sub183C6()");
 		
-	int var1 = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
-	_array122FD[var1] = (var2 & 0xff);
-	_array122E9[var1] = 1;
+	int index = _currScript->readUint16LE();
+	_array122FD[index] = (_currScript->readUint16LE() & 0xff);
+	_array122E9[index] = 1;
 
 	_vm->displayInterfaceHotspots();
 }
@@ -3113,7 +3109,7 @@ void LilliputScript::displayNumber(byte var1, Common::Point pos) {
 	_vm->_displayStringBuf[2] = 32;
 	_vm->_displayStringBuf[3] = 0;
 
-	_vm->prepareGoldAmount(var1);
+	_vm->numberToString(var1);
 	_vm->displayString(_vm->_displayStringBuf, pos);
 }
 
@@ -3207,15 +3203,21 @@ void LilliputScript::OC_initSmallAnim() {
 		_vm->_smallAnims[index]._frameIndex[i] = _currScript->readUint16LE();
 }
 
-void LilliputScript::OC_sub18678() {
-	debugC(1, kDebugScriptTBC, "OC_initArr18578()");
+void LilliputScript::OC_setCharacterHeroismBar() {
+	debugC(1, kDebugScript, "OC_setCharacterHeroismBar()");
+
 	_savedBuffer215Ptr = getCharacterVariablePtr();
 	_heroismBarX = _currScript->readUint16LE();
 	_heroismBarBottomY = _currScript->readUint16LE();
 }
 
 void LilliputScript::OC_sub18690() {
-	warning("OC_sub18690");
+	debugC(1, kDebugScriptTBC, "OC_sub18690()");
+
+	int index = getValue1();
+	Common::Point pos = getPosFromScript();
+	_vm->_rulesBuffer2_13_posX[index] = pos.x;
+	_vm->_rulesBuffer2_14_posY[index] = pos.y;
 }
 
 void LilliputScript::OC_setViewPortCharacterTarget() {
@@ -3257,7 +3259,7 @@ void LilliputScript::OC_sub186E5_snd() {
 }
 
 void LilliputScript::OC_sub1870A_snd() {
-	debugC(1, kDebugScriptTBC, "OC_sub1870A_snd()");
+	debugC(1, kDebugScript, "OC_sub1870A_snd()");
 
 	Common::Point var3 = getPosFromScript();
 	Common::Point var4 = var3;
@@ -3302,19 +3304,19 @@ void LilliputScript::OC_sub18746_snd() {
 }
 
 void LilliputScript::OC_sub1875D_snd() {
-	debugC(1, kDebugScriptTBC, "OC_sub1875D_snd()");
+	debugC(1, kDebugScript, "OC_sub1875D_snd()");
 
 	_vm->_soundHandler->contentFct6();
 }
 
-void LilliputScript::OC_sub18764() {
-	debugC(1, kDebugScriptTBC, "OC_sub18764()");
+void LilliputScript::OC_setArray128E() {
+	debugC(1, kDebugScript, "OC_setArray128E()");
 
 	int index = getValue1();
-	int var1 = _currScript->readUint16LE();
+	int val = _currScript->readUint16LE();
 
 	assert(index < 40);
-	_array128EF[index] = var1 & 0xFF;
+	_array128EF[index] = val & 0xFF;
 }
 
 } // End of namespace
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index f73121a..4bd8ad3 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -121,7 +121,7 @@ private:
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
 	
-	void sub1823E(byte index, byte var1, byte *curBufPtr);
+	void enableCharacterScript(byte index, byte var1, byte *curBufPtr);
 	void sub17B6C(int var1);
 	void sub16C86(int index, byte *buf);
 	void sub16C5C(int index, byte var3);
@@ -234,7 +234,7 @@ private:
 	void OC_sub17CB9();
 	void OC_sub17CD1();
 	void OC_resetWord16EFE();
-	void OC_sub17CEF();
+	void OC_enableCurrentCharacterScript();
 	void OC_IncCurrentCharacterVar1();
 	void OC_sub17D23();
 	void OC_sub17E6D();
@@ -272,7 +272,7 @@ private:
 	void OC_sub1834C();
 	void OC_setArray122C1();
 	void OC_sub18367();
-	void OC_sub17D04();
+	void OC_enableCharacterScript();
 	void OC_sub18387();
 	void OC_setDebugFlag();
 	void OC_setByte14837();
@@ -288,7 +288,7 @@ private:
 	void OC_initGameAreaDisplay();
 	void OC_sub1864D();
 	void OC_initSmallAnim();
-	void OC_sub18678();
+	void OC_setCharacterHeroismBar();
 	void OC_sub18690();
 	void OC_setViewPortCharacterTarget();
 	void OC_sub186A1();
@@ -299,7 +299,7 @@ private:
 	void OC_sub1873F_snd();
 	void OC_sub18746_snd();
 	void OC_sub1875D_snd();
-	void OC_sub18764();
+	void OC_setArray128E();
 };
 
 } // End of namespace Lilliput


Commit: 9ecbc0e327f6634df5173f706de24f28d18c71af
    https://github.com/scummvm/scummvm/commit/9ecbc0e327f6634df5173f706de24f28d18c71af
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in OC_compWord10804

Changed paths:
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 84b1a60..5ec93e1 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -337,8 +337,8 @@ public:
 	byte _byte12FCE;
 	byte _byte129A0;
 	byte _numCharactersToDisplay;
-	byte _byte16C9F;
-	int _word10804;
+	byte _byte16C9F; 
+	int16 _word10804;
 	bool _shouldQuit;
 
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 2f784f8..32ee332 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1743,9 +1743,9 @@ byte LilliputScript::OC_sub176C4() {
 }
 
 byte LilliputScript::OC_compWord10804() {
-	debugC(1, kDebugScriptTBC, "OC_compWord10804()");
+	debugC(1, kDebugScript, "OC_compWord10804()");
 	
-	byte tmpVal = getValue1();
+	int tmpVal = getValue1();
 	if (tmpVal == _vm->_word10804)
 		return 1;
 
@@ -2284,7 +2284,7 @@ void LilliputScript::OC_setCharacterPosition() {
 }
 
 void LilliputScript::OC_DisableCharacter() {
-	debugC(1, kDebugScriptTBC, "OC_DisableCharacter()");
+	debugC(1, kDebugScript, "OC_DisableCharacter()");
 
 	int characterIndex = getValue1();
 	assert(characterIndex < 40);
@@ -2352,7 +2352,7 @@ void LilliputScript::OC_setByte18823() {
 }
 
 void LilliputScript::OC_callScript() {
-	debugC(1, kDebugScriptTBC, "OC_callScript()");
+	debugC(1, kDebugScript, "OC_callScript()");
 
 	int index = _currScript->readUint16LE();
 	int var1 = getValue1();
@@ -2416,7 +2416,7 @@ void LilliputScript::OC_sub17AEE() {
 }
 
 void LilliputScript::OC_setWord10804() {
-	debugC(1, kDebugScriptTBC, "OC_setWord10804()");
+	debugC(1, kDebugScript, "OC_setWord10804()");
 
 	_vm->_word10804 = getValue1();
 }


Commit: e6983de0d074db34ff04e6b67319ce987350fd53
    https://github.com/scummvm/scummvm/commit/e6983de0d074db34ff04e6b67319ce987350fd53
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Renaming, fix interface hotspots: it's now possible to skip the intro

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 97f7239..3e6b210 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -144,8 +144,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12A08 = 0;
 	_byte12A09 = 0;
 	_byte16552 = 0;
-	_byte12FE4 = 0xFF;
-	_byte12FE3 = 0;
+	_lastInterfaceHotspotIndex = -1;
+	_lastInterfaceHotspotButton = 0;
 	_byte16F08 = 0;	
 	_byte16C9F = 0;
 	_lastAnimationTick = 0;
@@ -340,7 +340,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 }
 
 void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point pos) {
-	debugC(2, kDebugEngine, "display16x16IndexedBuf(buf, %d, %d, %d)", index, pos.x, pos.y);
+	debugC(2, kDebugEngine, "display16x16IndexedBuf(buf, %d, %d - %d)", index, pos.x, pos.y);
 
 	int index1 = index * 16 * 16;
 	byte *newBuf = &buf[index1];
@@ -471,8 +471,8 @@ void LilliputEngine::displayInterfaceHotspots() {
 	restoreSurfaceUnderMousePointer();
 
 	int tmpVal;
-	for (int index = 0; index < _word12F68_ERULES; index++) {
-		tmpVal = _scriptHandler->_array122E9[index] * 20;
+	for (int index = 0; index < _interfaceHotspotNumb; index++) {
+		tmpVal = _scriptHandler->_interfaceHotspotStatus[index] * 20;
 		display16x16IndexedBuf(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
 	}
 
@@ -975,12 +975,12 @@ void LilliputEngine::sub15F75() {
 	_byte16F07_menuId = 5;
 }
 
-void LilliputEngine::sub130B6() {
-	debugC(2, kDebugEngineTBC, "sub130B6()");
+void LilliputEngine::unselectInterfaceHotspots() {
+	debugC(2, kDebugEngine, "unselectInterfaceHotspots()");
 
-	for (int index = 0; index < _word12F68_ERULES; index++) {
-		if (_scriptHandler->_array122E9[index] == 3)
-			_scriptHandler->_array122E9[index] = 2;
+	for (int index = 0; index < _interfaceHotspotNumb; index++) {
+		if (_scriptHandler->_interfaceHotspotStatus[index] == kHotspotSelected)
+			_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
 	}
 }
 
@@ -1003,7 +1003,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 	_displayMap = 0;
 	paletteFadeOut();
 	_word15AC2 = 0;
-	sub130B6();
+	unselectInterfaceHotspots();
 	initGameAreaDisplay();
 	_scriptHandler->_heroismLevel = 0;
 	moveCharacters();
@@ -1871,8 +1871,8 @@ void LilliputEngine::sub130EE() {
 	_mouseButton = 0;
 
 	if (button & 2) {
-		if (_byte12FE4 != 0xFF)
-			sub1305C(_byte12FE4, button);
+		if (_lastInterfaceHotspotIndex != -1)
+			sub1305C(_lastInterfaceHotspotIndex, button);
 		return;
 	}
 
@@ -1937,7 +1937,7 @@ void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {
 	debugC(2, kDebugEngineTBC, "checkInterfaceHotspots()");
 
 	forceReturnFl = false;
-	for (int index = _word12F68_ERULES - 1; index >= 0; index--) {
+	for (int index = _interfaceHotspotNumb - 1; index >= 0; index--) {
 		if (sub13240(_mousePos, _interfaceHotspotsX[index], _interfaceHotspotsY[index]) == 0) {
 			sub1305C(index, 1);
 			forceReturnFl = true;
@@ -1964,15 +1964,15 @@ int LilliputEngine::sub13240(Common::Point mousePos, int var3, int var4) {
 void LilliputEngine::sub1305C(byte index, byte button) {
 	debugC(2, kDebugEngineTBC, "sub1305C(%d, %d)", index, button);
 
-	if (_scriptHandler->_array122E9[index] < 2)
+	if (_scriptHandler->_interfaceHotspotStatus[index] < kHotspotEnabled)
 		return;
 
-	_byte12FE4 = index;
-	_byte12FE3 = button;
+	_lastInterfaceHotspotIndex = index;
+	_lastInterfaceHotspotButton = button;
 
-	if (button == 2) {
+	if (button &= 2) {
 		if (_byte12FCE != 1) {
-			_scriptHandler->_array122E9[index] = 2;
+			_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
 			_byte16F07_menuId = 2;
 			displayInterfaceHotspots();
 		}
@@ -1984,8 +1984,8 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 		return;
 	}
 
-	_scriptHandler->sub130B6();
-	_scriptHandler->_array122E9[index] = 3;
+	unselectInterfaceHotspots();
+	_scriptHandler->_interfaceHotspotStatus[index] = kHotspotSelected;
 	if (_rulesBuffer13_1[index] == 1) {
 		_byte12FCE = 1;
 		_word15AC2 = 1;
@@ -2234,11 +2234,11 @@ void LilliputEngine::sub12FE5() {
 
 	int index = 0;
 	int count = 0;
-	for (int i = 0; i < _word12F68_ERULES; i++) {
+	for (int i = 0; i < _interfaceHotspotNumb; i++) {
 		if (_scriptHandler->_array122FD[index] != 0) {
 			--_scriptHandler->_array122FD[index];
 			if (_scriptHandler->_array122FD[index] == 0) {
-				_scriptHandler->_array122E9[index] = 2;
+				_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
 				++count;
 			}
 		}
@@ -2513,7 +2513,7 @@ void LilliputEngine::loadRules() {
 	assert(_rulesChunk10_size <= 20);
 
 	if (_rulesChunk10_size != 0) {
-		_rulesChunk10 = (int *)malloc(sizeof(int) * _rulesChunk10_size);
+		_rulesChunk10 = (int16 *)malloc(sizeof(int16) * _rulesChunk10_size);
 		int totalSize = 0;
 		for (int i = 0; i < _rulesChunk10_size; ++i) {
 			_rulesChunk10[i] = totalSize;
@@ -2541,7 +2541,7 @@ void LilliputEngine::loadRules() {
 	}
 
 	// Chunk 13
-	_word12F68_ERULES = f.readUint16LE();
+	_interfaceHotspotNumb = f.readUint16LE();
 	for (int i = 0 ; i < 20; i++)
 		_rulesBuffer13_1[i] = f.readByte();
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 5ec93e1..f37c896 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -66,6 +66,13 @@ enum LilliputDebugChannels {
 	kDebugScriptTBC = 1 << 4
 };
 
+enum InterfaceHotspotStatus {
+	kHotspotOff      = 0,
+	kHotspotDisabled = 1,
+	kHotspotEnabled  = 2,
+	kHotspotSelected = 3
+};
+
 struct LilliputGameDescription;
 
 struct SmallAnim {
@@ -106,8 +113,8 @@ public:
 	byte _byte12A08;
 	byte _byte12A09;
 	byte _byte16552;
-	byte _byte12FE4;
-	byte _byte12FE3;
+	int8 _lastInterfaceHotspotIndex;
+	byte _lastInterfaceHotspotButton; // Unused: set by 2 functions, but never used elsewhere
 	byte _byte16F08;
 	byte _byte15EAD;
 	byte _debugFlag; // Mostly useless, as the associated functions are empty
@@ -177,15 +184,15 @@ public:
 	int _gameScriptIndexSize;
 	byte *_arrayGameScripts;
 	byte _rulesChunk9[60];
-	int _rulesChunk10_size;
-	int *_rulesChunk10;
+	byte _rulesChunk10_size;
+	int16 *_rulesChunk10;
 	byte *_rulesChunk11;
-	int _rulesChunk12_size;
+	int16 _rulesChunk12_size;
 	int16 _rectXMinMax[40];
 	int16 _rectYMinMax[40];
 	Common::Point _rulesBuffer12Pos3[40];
 	Common::Point _rulesBuffer12Pos4[40];
-	int _word12F68_ERULES;
+	int _interfaceHotspotNumb;
 	byte _rulesBuffer13_1[20];
 	int16 _interfaceHotspotsX[20];
 	int16 _interfaceHotspotsY[20];
@@ -241,7 +248,7 @@ public:
 	void displaySmallAnims();
 	void displaySmallIndexedAnim(byte index, byte subIndex);
 
-	void sub130B6();
+	void unselectInterfaceHotspots();
 	void sub15F75();
 	void resetSmallAnims();
 	void paletteFadeOut();
@@ -341,7 +348,6 @@ public:
 	int16 _word10804;
 	bool _shouldQuit;
 
-
 	void pollEvent();
 	void setCurrentCharacter(int index);
 	void sub130DD();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 32ee332..390ef70 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -31,7 +31,6 @@ namespace Lilliput {
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 	_byte129A0 = 0xFF;
 	_byte10806 = 0;
-	_byte12FE4 = 0xFF;
 	_byte16F02 = 0;
 	_byte16F04 = 0;
 	_byte1881A = 0;
@@ -53,7 +52,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_savedBuffer215Ptr = NULL;
 
 	for (int i = 0; i < 20; i++) {
-		_array122E9[i] = 0;
+		_interfaceHotspotStatus[i] = kHotspotOff;
 		_array122FD[i] = 0;
 	}
 
@@ -170,10 +169,10 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_CurrentCharacterVar0Equals();
 		break;
 	case 0x1C:
-		return OC_sub17825();
+		return OC_checkLastInterfaceHotspotIndexMenu13();
 		break;
 	case 0x1D:
-		return OC_sub17844();
+		return OC_checkLastInterfaceHotspotIndexMenu2();
 		break;
 	case 0x1E:
 		return OC_CompareNumberOfCharacterWithVar0Equals();
@@ -215,7 +214,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_checkCharacterDirection();
 		break;
 	case 0x2B:
-		return OC_sub17984();
+		return OC_checkLastInterfaceHotspotIndex();
 		break;
 	case 0x2C:
 		return OC_checkSavedMousePos();
@@ -416,7 +415,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setCurrentCharacterDirection();
 		break;
 	case 0x39:
-		OC_sub18099();
+		OC_setInterfaceHotspot();
 		break;
 	case 0x3A:
 		OC_sub180C3();
@@ -479,7 +478,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub183A2();
 		break;
 	case 0x4E:
-		OC_sub183C6();
+		OC_disableInterfaceHotspot();
 		break;
 	case 0x4F:
 		OC_loadFile_AERIAL_GFX();
@@ -585,8 +584,8 @@ static const OpCode opCodes1[] = {
 	{ "OC_compWord16EFE", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_AreCurrentCharacterVar0AndVar1EqualsTo", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_CurrentCharacterVar0Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub17825", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub17844", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_checkLastInterfaceHotspotIndexMenu13", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_checkLastInterfaceHotspotIndexMenu2", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_CompareNumberOfCharacterWithVar0Equals", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_IsPositionInViewport", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_CompareGameVariables", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
@@ -600,7 +599,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub1793E", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_CurrentCharacterVar3Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub17984", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_checkLastInterfaceHotspotIndex", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkSavedMousePos", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179AE", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
@@ -668,7 +667,7 @@ static const OpCode opCodes2[] = {
 /* 0x36 */	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x39 */	{ "OC_sub18099", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x39 */	{ "OC_setInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x3a */	{ "OC_sub180C3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x3b */	{ "OC_setViewPortPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x3c */	{ "OC_setCurrentCharacterAltitude", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -689,7 +688,7 @@ static const OpCode opCodes2[] = {
 /* 0x4b */	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4d */	{ "OC_sub183A2", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x4e */	{ "OC_sub183C6", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
+/* 0x4e */	{ "OC_disableInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
 /* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x50 */	{ "OC_sub17E22_speech1IfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
@@ -1357,16 +1356,6 @@ Common::Point LilliputScript::getPosFromScript() {
 	}
 }
 
-void LilliputScript::sub130B6() {
-	debugC(1, kDebugScript, "sub130B6()");
-
-	assert(_vm->_word12F68_ERULES <= 20);
-	for (int i = 0; i < _vm->_word12F68_ERULES; i++) {
-		if (_array122E9[i] == 3)
-			_array122E9[i] = 2;
-	}
-}
-
 byte *LilliputScript::getCharacterVariablePtr() {
 	debugC(2, kDebugScript, "getCharacterVariablePtr()");
 
@@ -1843,29 +1832,29 @@ byte LilliputScript::OC_CurrentCharacterVar0Equals() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub17825() {
-	debugC(1, kDebugScriptTBC, "OC_sub17825()");
+byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu13() {
+	debugC(1, kDebugScript, "OC_checkLastInterfaceHotspotIndexMenu13()");
 
 	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
 	
 	if ((_vm->_byte16F07_menuId != 1) && (_vm->_byte16F07_menuId != 3))
 		return 0;
 
-	if (tmpVal == _byte12FE4)
+	if (tmpVal == _vm->_lastInterfaceHotspotIndex)
 		return 1;
 
 	return 0;
 }
 
-byte LilliputScript::OC_sub17844() {
-	debugC(1, kDebugScriptTBC, "OC_sub17844()");
+byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu2() {
+	debugC(1, kDebugScriptTBC, "OC_checkLastInterfaceHotspotIndexMenu2()");
 
-	int tmpVal = _currScript->readUint16LE();
+	int8 hotspotIndex = (_currScript->readUint16LE() & 0xFF);
 
-	if ((_vm->_byte16F07_menuId == 2) || ((tmpVal & 0xFF) != _byte12FE4))
-		return 0;
+	if ((_vm->_byte16F07_menuId == 2) || (hotspotIndex == _vm->_lastInterfaceHotspotIndex))
+		return 1;
 
-	return 1;
+	return 0;
 }
 
 byte LilliputScript::OC_CompareNumberOfCharacterWithVar0Equals() {
@@ -2020,15 +2009,15 @@ byte LilliputScript::OC_checkCharacterDirection() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub17984() {
-	debugC(1, kDebugScriptTBC, "OC_sub17984()");
+byte LilliputScript::OC_checkLastInterfaceHotspotIndex() {
+	debugC(1, kDebugScriptTBC, "OC_checkLastInterfaceHotspotIndex()");
 
 	int index = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
+	int8 var2 = (_currScript->readUint16LE() & 0xFF);
 
 	assert(index < 20);
 
-	if (_array122E9[index] == (var2 & 0xFF))
+	if (_interfaceHotspotStatus[index] == var2)
 		return 1;
 
 	return 0;
@@ -2573,21 +2562,21 @@ void LilliputScript::OC_changeCurrentCharacterSprite() {
 
 }
 
-byte *LilliputScript::sub173D2() {
-	debugC(2, kDebugScriptTBC, "sub173D2()");
+byte *LilliputScript::getCurrentCharacterVarFromScript() {
+	debugC(2, kDebugScript, "getCurrentCharacterVarFromScript()");
 
 	int index = _currScript->readUint16LE();	
 	return &_vm->_currentCharacterVariables[index];
 }
 
 void LilliputScript::OC_sub17E99() {
-	debugC(1, kDebugScriptTBC, "OC_sub17E99()");
+	debugC(1, kDebugScript, "OC_sub17E99()");
 
-	byte *compBuf = sub173D2();
+	byte *compBuf = getCurrentCharacterVarFromScript();
 	int oper = _currScript->readUint16LE();
 	int index = _currScript->readUint16LE();	
 
-	byte *buf = sub173D2();
+	byte *buf = getCurrentCharacterVarFromScript();
 	byte var1 = buf[0];
 	byte var3 = _vm->_rulesChunk11[var1 + _vm->_rulesChunk10[index]];
 
@@ -2599,12 +2588,12 @@ void LilliputScript::OC_sub17EC5() {
 
 	int indexChunk10 = _currScript->readUint16LE();
 
-	byte *compBuf = sub173D2();
+	byte *compBuf = getCurrentCharacterVarFromScript();
 	int indexChunk11 = _vm->_rulesChunk10[indexChunk10] + compBuf[0];
 
 	int oper = _currScript->readUint16LE();
 
-	byte *tmpBuf = sub173D2();
+	byte *tmpBuf = getCurrentCharacterVarFromScript();
 	int var3 = tmpBuf[0];
 	
 	computeOperation(&_vm->_rulesChunk11[indexChunk11], oper, var3);
@@ -2781,14 +2770,14 @@ void LilliputScript::OC_setCurrentCharacterDirection() {
 	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
 
-void LilliputScript::OC_sub18099() {
-	debugC(1, kDebugScriptTBC, "OC_sub18099()");
+void LilliputScript::OC_setInterfaceHotspot() {
+	debugC(1, kDebugScript, "OC_setInterfaceHotspot()");
 
-	int index = _currScript->readUint16LE();
-	assert((index >= 0) && (index < 20));
-	int curWord = _currScript->readUint16LE();
+	int16 index = _currScript->readSint16LE();
+	uint16 curWord = _currScript->readUint16LE();
 
-	_array122E9[index] = (curWord & 0xFF);
+	assert((index >= 0) && (index < 20));
+	_interfaceHotspotStatus[index] = (curWord & 0xFF);
 	_array122FD[index] = (curWord >> 8);
 
 	_vm->displayInterfaceHotspots();
@@ -3033,12 +3022,12 @@ void LilliputScript::OC_sub183A2() {
 	warning("OC_sub183A2");
 }
 
-void LilliputScript::OC_sub183C6() {
-	debugC(1, kDebugScriptTBC, "OC_sub183C6()");
-		
+void LilliputScript::OC_disableInterfaceHotspot() {
+	debugC(1, kDebugScriptTBC, "OC_disableInterfaceHotspot()");
+
 	int index = _currScript->readUint16LE();
 	_array122FD[index] = (_currScript->readUint16LE() & 0xff);
-	_array122E9[index] = 1;
+	_interfaceHotspotStatus[index] = kHotspotDisabled;
 
 	_vm->displayInterfaceHotspots();
 }
@@ -3168,7 +3157,7 @@ void LilliputScript::OC_initGameAreaDisplay() {
 	OC_PaletteFadeOut();
 	_vm->_displayMap = 0;
 	_heroismLevel = 0;
-	sub130B6();
+	_vm->unselectInterfaceHotspots();
 
 	_vm->initGameAreaDisplay();
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 4bd8ad3..82b2be4 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -60,7 +60,7 @@ public:
 	byte _speechTimer;
 
 	byte _characterScriptEnabled[40];
-	byte _array122E9[20];
+	int8 _interfaceHotspotStatus[20];
 	char _array16123PosX[40];
 	char _array1614BPosY[40];
 	byte _array12811[40];
@@ -83,8 +83,6 @@ public:
 	byte _array12839[40];
 	Common::Point _array1813BPos[32];
 
-	void sub130B6();
-
 	LilliputScript(LilliputEngine *vm);
 	~LilliputScript();
 
@@ -103,7 +101,6 @@ private:
 	byte _byte12A09;
 	byte _byte129A0;
 	byte _byte10806;
-	byte _byte12FE4;
 	byte _byte16F02;
 	byte _byte16F04;
 	byte _byte1881A;
@@ -130,7 +127,7 @@ private:
 	void sub18B3C(int var);
 	void displayNumber(byte var1, Common::Point pos);
 	byte *getMapPtr(Common::Point val);
-	byte *sub173D2();
+	byte *getCurrentCharacterVarFromScript();
 	void sub171AF(int var1, int var2, int var4);
 	void sub18B7C(int var1, int var3);
 	void sub189B8();
@@ -174,8 +171,8 @@ private:
 	byte OC_compWord16EFE();
 	byte OC_AreCurrentCharacterVar0AndVar1EqualsTo();
 	byte OC_CurrentCharacterVar0Equals();
-	byte OC_sub17825();
-	byte OC_sub17844();
+	byte OC_checkLastInterfaceHotspotIndexMenu13();
+	byte OC_checkLastInterfaceHotspotIndexMenu2();
 	byte OC_CompareNumberOfCharacterWithVar0Equals();
 	byte OC_IsPositionInViewport();
 	byte OC_CompareGameVariables();
@@ -189,7 +186,7 @@ private:
 	byte OC_sub1793E();
 	byte OC_CurrentCharacterVar3Equals1();
 	byte OC_checkCharacterDirection();
-	byte OC_sub17984();
+	byte OC_checkLastInterfaceHotspotIndex();
 	byte OC_checkSavedMousePos();
 	byte OC_sub179AE();
 	byte OC_sub179C2();
@@ -255,7 +252,7 @@ private:
 	void OC_sub1805D();
 	void OC_sub18074();
 	void OC_setCurrentCharacterDirection();
-	void OC_sub18099();
+	void OC_setInterfaceHotspot();
 	void OC_sub180C3();
 	void OC_setViewPortPos();
 	void OC_setCurrentCharacterAltitude();
@@ -277,7 +274,7 @@ private:
 	void OC_setDebugFlag();
 	void OC_setByte14837();
 	void OC_sub183A2();
-	void OC_sub183C6();
+	void OC_disableInterfaceHotspot();
 	void OC_loadFile_AERIAL_GFX();
 	void OC_sub17E22_speech1IfSoundOff();
 	void OC_sub1844A();


Commit: cdfac3cadc6222f2e518f85a495996c49629d152
    https://github.com/scummvm/scummvm/commit/cdfac3cadc6222f2e518f85a495996c49629d152
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more code validation and renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3e6b210..21b18f9 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -153,7 +153,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_currentScriptCharacter = 0;
 	_currentScriptCharacterPos = Common::Point(0, 0);
 	_word10804 = 0;
-	_word17081_nextIndex = 0;
+	_nextCharacterIndex = 0;
 	_word16EFE = 0xFFFF;
 	_word1817B = 0;
 	_savedSurfaceUnderMousePos = Common::Point(0, 0);
@@ -2629,7 +2629,7 @@ void LilliputEngine::sub130DD() {
 }
 
 void LilliputEngine::handleMenu() {
-	debugC(1, kDebugEngineTBC, "handleMenu()");
+	debugC(1, kDebugEngine, "handleMenu()");
 
 	if (_byte16F07_menuId == 0)
 		return;
@@ -2651,9 +2651,9 @@ void LilliputEngine::handleMenu() {
 }
 
 void LilliputEngine::handleGameScripts() {
-	debugC(1, kDebugEngineTBC, "handleGameScripts()");
+	debugC(1, kDebugEngine, "handleGameScripts()");
 
-	int index = _word17081_nextIndex;
+	int index = _nextCharacterIndex;
 	int i;
 	for (i = 0; (_scriptHandler->_characterScriptEnabled[index] == 0) && (i < _numCharacters); i++) {
 		++index;
@@ -2664,7 +2664,7 @@ void LilliputEngine::handleGameScripts() {
 	if (i > _numCharacters)
 		return;
 
-	_word17081_nextIndex = (index + 1) % _numCharacters;
+	_nextCharacterIndex = (index + 1) % _numCharacters;
 
 
 	_scriptHandler->_characterScriptEnabled[index] = 0;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index f37c896..322e34a 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -138,7 +138,7 @@ public:
 	int _word10800_ERULES;
 	int _numCharacters;
 	Common::Point _currentScriptCharacterPos;
-	int _word17081_nextIndex;
+	int _nextCharacterIndex;
 	int _word16EFE;
 	int _word1817B;
 	Common::Point _savedSurfaceUnderMousePos;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 390ef70..6cc9fd5 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -334,7 +334,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17C76();
 		break;
 	case 0x1E:
-		OC_sub17AFC();
+		OC_setCurrentCharacter();
 		break;
 	case 0x1F:
 		OC_sub17C8B();
@@ -640,7 +640,7 @@ static const OpCode opCodes2[] = {
 /* 0x1b */	{ "OC_sub17C0E", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x1c */ 	{ "OC_sub17C55", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x1d */	{ "OC_sub17C76", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x1e */	{ "OC_sub17AFC", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x1e */	{ "OC_setCurrentCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x1f */	{ "OC_sub17C8B", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x20 */	{ "OC_sub17CA2", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x21 */	{ "OC_sub17CB9", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone }, 
@@ -975,7 +975,7 @@ byte LilliputScript::compareValues(int var1, int oper, int var2) {
 }
 
 void LilliputScript::computeOperation(byte *bufPtr, int oper, int var3) {
-	debugC(1, kDebugScriptTBC, "computeOperation(bufPtr, %c, %d)", oper & 0xFF, var3 & 0xFF);
+	debugC(1, kDebugScript, "computeOperation(bufPtr, %c, %d)", oper & 0xFF, var3 & 0xFF);
 
 	switch (oper & 0xFF) {
 	case '=':
@@ -1515,7 +1515,7 @@ byte LilliputScript::OC_sub174D8() {
 }
 
 byte LilliputScript::OC_CompareCharacterVariables() {
-	debugC(1, kDebugScriptTBC, "OC_CompareCharacterVariables()");
+	debugC(1, kDebugScript, "OC_CompareCharacterVariables()");
 
 	byte* buf1 = getCharacterVariablePtr();
 	int var1 = *buf1;
@@ -1786,7 +1786,7 @@ byte LilliputScript::OC_CompareMapValueWith() {
 }
 
 byte LilliputScript::OC_IsCharacterValid() {
-	debugC(1, kDebugScriptTBC, "OC_IsCharacterValid()");
+	debugC(1, kDebugScript, "OC_IsCharacterValid()");
 
 	int index = getValue1();
 	if (_vm->_characterPositionX[index] == -1)
@@ -2240,26 +2240,26 @@ void LilliputScript::OC_sub17E15_speech2param() {
 }
 
 void LilliputScript::OC_ComputeCharacterVariable() {
-	debugC(1, kDebugScriptTBC, "OC_ComputeCharacterVariable()");
+	debugC(1, kDebugScript, "OC_ComputeCharacterVariable()");
 
 	byte *bufPtr = getCharacterVariablePtr();
-	int oper = _currScript->readUint16LE();
-	int var3 = _currScript->readUint16LE();
+	int16 oper = _currScript->readUint16LE();
+	int16 var3 = _currScript->readSint16LE();
 
 	computeOperation(bufPtr, oper, var3);
 }
 
 void LilliputScript::OC_getRandom_type2() {
-	debugC(1, kDebugScriptTBC, "OC_getRandom_type2()");
+	debugC(1, kDebugScript, "OC_getRandom_type2()");
 
-	byte* bufPtr = getCharacterVariablePtr();
+	byte *bufPtr = getCharacterVariablePtr();
 	int maxVal = _currScript->readUint16LE(); 
 	int randomVal = _vm->_rnd->getRandomNumber(maxVal);
 	*bufPtr = randomVal;
 }
 
 void LilliputScript::OC_setCharacterPosition() {
-	debugC(1, kDebugScriptTBC, "OC_setCharacterPosition()");
+	debugC(1, kDebugScript, "OC_setCharacterPosition()");
 	
 	int index = getValue1();
 	Common::Point tmpVal = getPosFromScript();
@@ -2441,6 +2441,7 @@ void LilliputScript::OC_sub17C55() {
 	_vm->_rulesBuffer2_6[var2] = var3 & 0xFF;
 	_vm->_rulesBuffer2_7[var2] = var4 & 0xFF;
 }
+
 void LilliputScript::OC_sub17C76() {
 	debugC(1, kDebugScriptTBC, "OC_sub17C76()");
 	
@@ -2450,8 +2451,9 @@ void LilliputScript::OC_sub17C76() {
 	_characterScriptEnabled[var1] = 1;
 
 }
-void LilliputScript::OC_sub17AFC() {
-	debugC(1, kDebugScriptTBC, "OC_sub17AFC()");
+
+void LilliputScript::OC_setCurrentCharacter() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacter()");
 	int var1 = getValue1();
 	_vm->setCurrentCharacter(var1);
 }
@@ -2715,7 +2717,7 @@ void LilliputScript::OC_setByte10B29() {
 }
 
 void LilliputScript::OC_setCurrentCharacterVar2() {
-	debugC(1, kDebugScriptTBC, "OC_setCurrentCharacterVar2()");
+	debugC(1, kDebugScript, "OC_setCurrentCharacterVar2()");
 
 	int curWord = _currScript->readUint16LE();
 	assert(_vm->_currentCharacterVariables != NULL);
@@ -3210,7 +3212,7 @@ void LilliputScript::OC_sub18690() {
 }
 
 void LilliputScript::OC_setViewPortCharacterTarget() {
-	debugC(1, kDebugScriptTBC, "OC_setViewPortCharacterTarget()");
+	debugC(1, kDebugScript, "OC_setViewPortCharacterTarget()");
 
 	_viewportCharacterTarget = getValue1();
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 82b2be4..87db1e7 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -225,7 +225,7 @@ private:
 	void OC_sub17C0E();
 	void OC_sub17C55();
 	void OC_sub17C76();
-	void OC_sub17AFC();
+	void OC_setCurrentCharacter();
 	void OC_sub17C8B();
 	void OC_sub17CA2();
 	void OC_sub17CB9();


Commit: dc45e2b791a3c3c6390b78d7aa0625e16bdef1c7
    https://github.com/scummvm/scummvm/commit/dc45e2b791a3c3c6390b78d7aa0625e16bdef1c7
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 6cc9fd5..3187b20 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -31,7 +31,7 @@ namespace Lilliput {
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 	_byte129A0 = 0xFF;
 	_byte10806 = 0;
-	_byte16F02 = 0;
+	_lastRandomValue = 0;
 	_byte16F04 = 0;
 	_byte1881A = 0;
 	_byte18823 = 0;
@@ -97,7 +97,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_compareCharacterVariable();
 		break;
 	case 0x4:
-		return OC_CompareByte16F02With();
+		return OC_CompareLastRandomValue();
 		break;
 	case 0x5:
 		return OC_getRandom();
@@ -205,7 +205,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_CurrentCharacterVar1Equals();
 		break;
 	case 0x28:
-		return OC_sub1793E();
+		return OC_isCurrentCharacterActive();
 		break;
 	case 0x29:
 		return OC_CurrentCharacterVar3Equals1();
@@ -454,7 +454,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_loadAndDisplayCUBESx_GFX();
 		break;
 	case 0x46:
-		OC_sub1834C();
+		OC_setCurrentCharacterVar3();
 		break;
 	case 0x47:
 		OC_setArray122C1();
@@ -560,7 +560,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_comparePos", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 	{ "OC_sub1740A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_compareCharacterVariable", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
-	{ "OC_CompareByte16F02With", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_CompareLastRandomValue", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_getRandom", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_for", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_compWord18776", 1, kImmediateValue, kNone, kNone, kNone, kNone },
@@ -596,7 +596,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_IsCurrentCharacterVar0LessEqualThan", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1790F", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_CurrentCharacterVar1Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub1793E", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_isCurrentCharacterActive", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_CurrentCharacterVar3Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkLastInterfaceHotspotIndex", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
@@ -680,7 +680,7 @@ static const OpCode opCodes2[] = {
 /* 0x43 */	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x44 */	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x45 */	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x46 */	{ "OC_sub1834C", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x46 */	{ "OC_setCurrentCharacterVar3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x47 */	{ "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x48 */	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x49 */	{ "OC_enableCharacterScript", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
@@ -953,7 +953,7 @@ void LilliputScript::runMenuScript(ScriptStream script) {
 		_vm->update();
 }
 
-byte LilliputScript::compareValues(int var1, int oper, int var2) {
+byte LilliputScript::compareValues(int16 var1, uint16 oper, int16 var2) {
 	debugC(2, kDebugScript, "compareValues(%d, %c, %d)", var1, oper & 0xFF, var2);
 
 	switch (oper & 0xFF) {
@@ -974,7 +974,7 @@ byte LilliputScript::compareValues(int var1, int oper, int var2) {
 	return 0;
 }
 
-void LilliputScript::computeOperation(byte *bufPtr, int oper, int var3) {
+void LilliputScript::computeOperation(byte *bufPtr, uint16 oper, int16 var3) {
 	debugC(1, kDebugScript, "computeOperation(bufPtr, %c, %d)", oper & 0xFF, var3 & 0xFF);
 
 	switch (oper & 0xFF) {
@@ -1033,7 +1033,7 @@ void LilliputScript::enableCharacterScript(byte index, byte var1, byte *curBufPt
 }
 
 void LilliputScript::sub17B6C(int var1) {
-	debugC(1, kDebugScriptTBC, "sub17B6C(%d)", var1);
+	debugC(1, kDebugScript, "sub17B6C(%d)", var1);
 
 	if (var1 == 0) {
 		int curWord = 0;
@@ -1367,7 +1367,7 @@ byte *LilliputScript::getCharacterVariablePtr() {
 }
 
 byte LilliputScript::OC_checkCharacterGoalPos() {
-	debugC(2, kDebugScriptTBC, "OC_checkCharacterGoalPos()");
+	debugC(2, kDebugScript, "OC_checkCharacterGoalPos()");
 
 	if (_vm->_currentScriptCharacterPos == getPosFromScript()) {
 		return 1;
@@ -1422,20 +1422,20 @@ byte LilliputScript::OC_compareCharacterVariable() {
 	return compareValues(var1, oper, var2);
 }
 
-byte LilliputScript::OC_CompareByte16F02With() {
-	debugC(1, kDebugScriptTBC, "OC_CompareByte16F02With()");
+byte LilliputScript::OC_CompareLastRandomValue() {
+	debugC(1, kDebugScript, "OC_CompareLastRandomValue()");
 
-	int operation = _currScript->readUint16LE();
-	int val2 = _currScript->readUint16LE();
-	return compareValues(_byte16F02, operation, val2);
+	uint16 operation = _currScript->readUint16LE();
+	int16 val2 = _currScript->readSint16LE();
+	return compareValues(_lastRandomValue, operation, val2);
 }
 
 byte LilliputScript::OC_getRandom() {
-	debugC(1, kDebugScriptTBC, "OC_getRandom()");
+	debugC(1, kDebugScript, "OC_getRandom()");
 
 	int maxVal = _currScript->readUint16LE();
 	int rand = _vm->_rnd->getRandomNumber(maxVal);
-	_byte16F02 = (rand & 0xFF);
+	_lastRandomValue = (rand & 0xFF);
 	
 	if (rand == 0)
 		return 1;
@@ -1488,14 +1488,13 @@ byte LilliputScript::OC_compByte16F04() {
 }
 
 byte LilliputScript::OC_sub174D8() {
-	debugC(1, kDebugScriptTBC, "OC_sub174D8()");
+	debugC(1, kDebugScript, "OC_sub174D8()");
 
 	byte tmpVal = getValue1() & 0xFF;
-	int curWord = _currScript->readUint16LE();
+	uint16 curWord = _currScript->readUint16LE();
 	
 	if (curWord == 3000) {
-		int index;
-		for (index = 0; index < _vm->_numCharacters; index++) {
+		for (int index = 0; index < _vm->_numCharacters; index++) {
 			if (_vm->_rulesBuffer2_5[index] == tmpVal) {
 				_word16F00 = index;
 				return 1;
@@ -1530,7 +1529,7 @@ byte LilliputScript::OC_CompareCharacterVariables() {
 
 // TODO Rename function to "Check if character pos in rectangle"
 byte LilliputScript::OC_compareCoords_1() {
-	debugC(1, kDebugScriptTBC, "OC_compareCoords_1()");
+	debugC(1, kDebugScript, "OC_compareCoords_1()");
 
 	int index = _currScript->readUint16LE();
 	assert(index < 40);
@@ -1583,11 +1582,11 @@ byte LilliputScript::OC_compareRandomCharacterId() {
 	debugC(1, kDebugScriptTBC, "OC_compareRandomCharacterId()");
 
 	byte *tmpArr = getCharacterVariablePtr();
-	_byte16F02 = _vm->_rnd->getRandomNumber(tmpArr[0] + 1);
+	_lastRandomValue = _vm->_rnd->getRandomNumber(tmpArr[0] + 1);
 	uint16 oper = _currScript->readUint16LE();
 	int16 var2 = _currScript->readSint16LE();
 
-	return compareValues(_byte16F02, oper, var2);
+	return compareValues(_lastRandomValue, oper, var2);
 }
 
 byte LilliputScript::OC_IsCurrentCharacterIndex() {
@@ -1641,7 +1640,7 @@ byte LilliputScript::OC_sub175C8() {
 }
 
 byte LilliputScript::OC_sub17640() {
-	debugC(1, kDebugScript, "OC_sub176C4()");
+	debugC(1, kDebugScript, "OC_sub17640()");
 
 	int var4 = _currScript->readUint16LE();
 	int index = _vm->_currentScriptCharacter * 40;
@@ -1688,7 +1687,7 @@ byte LilliputScript::OC_sub17640() {
 }
 
 byte LilliputScript::OC_sub176C4() {
-	debugC(1, kDebugScriptTBC, "OC_sub176C4()");
+	debugC(1, kDebugScript, "OC_sub176C4()");
 	
 	byte var4 = _currScript->readUint16LE() & 0xFF;
 
@@ -1752,7 +1751,7 @@ byte LilliputScript::OC_sub17766() {
 }
 
 byte LilliputScript::OC_sub17782() {
-	debugC(1, kDebugScriptTBC, "OC_sub17782()");
+	debugC(1, kDebugScript, "OC_sub17782()");
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
 	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] == 16))
@@ -1858,18 +1857,18 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu2() {
 }
 
 byte LilliputScript::OC_CompareNumberOfCharacterWithVar0Equals() {
-	debugC(1, kDebugScriptTBC, "OC_CompareNumberOfCharacterWithVar0Equals()");
+	debugC(1, kDebugScript, "OC_CompareNumberOfCharacterWithVar0Equals()");
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
-	int count = 0;
+	int16 count = 0;
 
 	for (int i = 0; i < _vm->_numCharacters; i++) {
 		if (curByte == *_vm->getCharacterVariablesPtr(32 * i))
 			++count;
 	}
 
-	int oper = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
+	uint16 oper = _currScript->readUint16LE();
+	int16 var2 = _currScript->readSint16LE();
 
 	return compareValues(count, oper, var2);
 }
@@ -1928,7 +1927,7 @@ byte LilliputScript::OC_sub178D2() {
 }
 
 byte LilliputScript::OC_CharacterVariableAnd() {
-	debugC(1, kDebugScriptTBC, "OC_CharacterVariableAnd()");
+	debugC(1, kDebugScript, "OC_CharacterVariableAnd()");
 
 	byte *bufPtr = getCharacterVariablePtr();
 	byte var1 = bufPtr[0];
@@ -1976,8 +1975,8 @@ byte LilliputScript::OC_CurrentCharacterVar1Equals() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub1793E() {
-	debugC(1, kDebugScriptTBC, "OC_sub1793E()");
+byte LilliputScript::OC_isCurrentCharacterActive() {
+	debugC(1, kDebugScript, "OC_isCurrentCharacterActive()");
 
 	if (_vm->_currentScriptCharacterPos == Common::Point(-1, -1))
 		return 0;
@@ -2010,9 +2009,9 @@ byte LilliputScript::OC_checkCharacterDirection() {
 }
 
 byte LilliputScript::OC_checkLastInterfaceHotspotIndex() {
-	debugC(1, kDebugScriptTBC, "OC_checkLastInterfaceHotspotIndex()");
+	debugC(1, kDebugScript, "OC_checkLastInterfaceHotspotIndex()");
 
-	int index = _currScript->readUint16LE();
+	uint16 index = _currScript->readUint16LE();
 	int8 var2 = (_currScript->readUint16LE() & 0xFF);
 
 	assert(index < 20);
@@ -2243,7 +2242,7 @@ void LilliputScript::OC_ComputeCharacterVariable() {
 	debugC(1, kDebugScript, "OC_ComputeCharacterVariable()");
 
 	byte *bufPtr = getCharacterVariablePtr();
-	int16 oper = _currScript->readUint16LE();
+	uint16 oper = _currScript->readUint16LE();
 	int16 var3 = _currScript->readSint16LE();
 
 	computeOperation(bufPtr, oper, var3);
@@ -2290,7 +2289,7 @@ void LilliputScript::OC_saveAndQuit() {
 }
 
 void LilliputScript::OC_sub17B93() {
-	debugC(1, kDebugScriptTBC, "OC_sub17B93()");
+	debugC(1, kDebugScript, "OC_sub17B93()");
 
 	int var1 = _currScript->readUint16LE();
 	sub17B6C(var1);
@@ -2325,11 +2324,11 @@ void LilliputScript::OC_incByte16F04() {
 }
 
 void LilliputScript::OC_sub17BA5() {
-	debugC(1, kDebugScriptTBC, "OC_sub17BA5()");
+	debugC(1, kDebugScript, "OC_sub17BA5()");
 	
 	byte *tmpArr = getCharacterVariablePtr();
-	byte oper = (_currScript->readUint16LE() & 0xFF);
-	byte var3 = getCharacterVariablePtr()[0];
+	uint16 oper = _currScript->readUint16LE();
+	int16 var3 = getCharacterVariablePtr()[0];
 	computeOperation(tmpArr, oper, var3);
 }
 
@@ -2376,7 +2375,7 @@ void LilliputScript::OC_callScriptAndReturn() {
 }
 
 void LilliputScript::OC_setCurrentScriptCharacterPos() {
-	debugC(1, kDebugScriptTBC, "OC_setCurrentScriptCharacterPos()");
+	debugC(1, kDebugScript, "OC_setCurrentScriptCharacterPos()");
 
 	Common::Point pos = getPosFromScript();
 	_vm->_array10999PosX[_vm->_currentScriptCharacter] = pos.x;
@@ -2531,7 +2530,7 @@ void LilliputScript::OC_enableCurrentCharacterScript() {
 }
 
 void LilliputScript::OC_IncCurrentCharacterVar1() {
-	debugC(1, kDebugScriptTBC, "OC_IncCurrentCharacterVar1()");
+	debugC(1, kDebugScript, "OC_IncCurrentCharacterVar1()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	++_vm->_currentCharacterVariables[1];
@@ -2540,7 +2539,7 @@ void LilliputScript::OC_IncCurrentCharacterVar1() {
 void LilliputScript::OC_sub17D23() {
 	debugC(1, kDebugScriptTBC, "OC_sub17D23()");
 
-	int var1 = _currScript->readUint16LE();
+	uint16 var1 = _currScript->readUint16LE();
 	Common::Point var2 = getPosFromScript();
 	byte* buf = _vm->_currentCharacterVariables + 4;
 	computeOperation(buf, var1, var2.x);
@@ -2575,7 +2574,7 @@ void LilliputScript::OC_sub17E99() {
 	debugC(1, kDebugScript, "OC_sub17E99()");
 
 	byte *compBuf = getCurrentCharacterVarFromScript();
-	int oper = _currScript->readUint16LE();
+	uint16 oper = _currScript->readUint16LE();
 	int index = _currScript->readUint16LE();	
 
 	byte *buf = getCurrentCharacterVarFromScript();
@@ -2593,10 +2592,10 @@ void LilliputScript::OC_sub17EC5() {
 	byte *compBuf = getCurrentCharacterVarFromScript();
 	int indexChunk11 = _vm->_rulesChunk10[indexChunk10] + compBuf[0];
 
-	int oper = _currScript->readUint16LE();
+	uint16 oper = _currScript->readUint16LE();
 
 	byte *tmpBuf = getCurrentCharacterVarFromScript();
-	int var3 = tmpBuf[0];
+	int16 var3 = tmpBuf[0];
 	
 	computeOperation(&_vm->_rulesChunk11[indexChunk11], oper, var3);
 }
@@ -2699,7 +2698,7 @@ void LilliputScript::OC_sub17FD2() {
 }
 
 void LilliputScript::OC_sub17FDD() {
-	debugC(1, kDebugScriptTBC, "OC_sub17FDD()");
+	debugC(1, kDebugScript, "OC_sub17FDD()");
 
 	int index = _currScript->readUint16LE();
 	
@@ -2725,7 +2724,7 @@ void LilliputScript::OC_setCurrentCharacterVar2() {
 }
 
 void LilliputScript::OC_SetCurrentCharacterVar2ToZero() {
-	debugC(1, kDebugScriptTBC, "OC_SetCurrentCharacterVar2ToZero()");
+	debugC(1, kDebugScript, "OC_SetCurrentCharacterVar2ToZero()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	_vm->_currentCharacterVariables[2] = 0;
@@ -2891,9 +2890,9 @@ void LilliputScript::OC_sub181BB() {
 }
 
 void LilliputScript::OC_sub18213() {
-	debugC(1, kDebugScriptTBC, "OC_sub18213()");
+	debugC(1, kDebugScript, "OC_sub18213()");
 
-	int var1 = _currScript->readUint16LE();
+	uint16 var1 = _currScript->readUint16LE();
 
 	int maxValue = 0;
 	int maxItem = var1 & 0xFF;
@@ -2963,19 +2962,19 @@ void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
 	_vm->prepareGameArea();
 }
 
-void LilliputScript::OC_sub1834C() {
-	debugC(1, kDebugScriptTBC, "OC_sub1834C()");
+void LilliputScript::OC_setCurrentCharacterVar3() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterVar3()");
 
-	byte curWord = _currScript->readUint16LE() & 0xFF;
+	byte var1 = _currScript->readUint16LE() & 0xFF;
 	assert(_vm->_currentCharacterVariables != NULL);
 
-	_vm->_currentCharacterVariables[3] = curWord;
+	_vm->_currentCharacterVariables[3] = var1;
 }
 
 void LilliputScript::OC_setArray122C1() {
-	debugC(1, kDebugScriptTBC, "OC_setArray122C1()");
+	debugC(1, kDebugScript, "OC_setArray122C1()");
 
-	int var1 = _currScript->readUint16LE();
+	byte var1 = (_currScript->readUint16LE() & 0xFF);
 	_array122C1[_vm->_currentScriptCharacter] = var1;
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 87db1e7..5fdca27 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -101,7 +101,7 @@ private:
 	byte _byte12A09;
 	byte _byte129A0;
 	byte _byte10806;
-	byte _byte16F02;
+	byte _lastRandomValue;
 	byte _byte16F04;
 	byte _byte1881A;
 	byte _byte18823;
@@ -139,15 +139,15 @@ private:
 	Common::Point getPosFromScript();
 
 	byte *getCharacterVariablePtr();
-	byte compareValues(int var1, int oper, int var2);
-	void computeOperation(byte *bufPtr, int oper, int var2);
+	byte compareValues(int16 var1, uint16 oper, int16 var2);
+	void computeOperation(byte *bufPtr, uint16 oper, int16 var2);
 
 	//Opcodes Type 1
 	byte OC_checkCharacterGoalPos();
 	byte OC_comparePos();
 	byte OC_sub1740A();
 	byte OC_compareCharacterVariable();
-	byte OC_CompareByte16F02With();
+	byte OC_CompareLastRandomValue();
 	byte OC_getRandom();
 	byte OC_for();
 	byte OC_compWord18776();
@@ -183,7 +183,7 @@ private:
 	byte OC_IsCurrentCharacterVar0LessEqualThan();
 	byte OC_sub1790F();
 	byte OC_CurrentCharacterVar1Equals();
-	byte OC_sub1793E();
+	byte OC_isCurrentCharacterActive();
 	byte OC_CurrentCharacterVar3Equals1();
 	byte OC_checkCharacterDirection();
 	byte OC_checkLastInterfaceHotspotIndex();
@@ -266,7 +266,7 @@ private:
 	void OC_PaletteFadeOut();
 	void OC_PaletteFadeIn();
 	void OC_loadAndDisplayCUBESx_GFX();
-	void OC_sub1834C();
+	void OC_setCurrentCharacterVar3();
 	void OC_setArray122C1();
 	void OC_sub18367();
 	void OC_enableCharacterScript();


Commit: 03e0d5927f57956a29b5c858d203b3272311d4db
    https://github.com/scummvm/scummvm/commit/03e0d5927f57956a29b5c858d203b3272311d4db
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming, fix two bugs

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 21b18f9..dcf572f 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1205,7 +1205,7 @@ void LilliputEngine::sortCharacters() {
 }
 
 void LilliputEngine::scrollToViewportCharacterTarget() {
-	debugC(2, kDebugEngineTBC, "scrollToViewportCharacterTarget()");
+	debugC(2, kDebugEngine, "scrollToViewportCharacterTarget()");
 
 	if (_scriptHandler->_viewportCharacterTarget == -1)
 		return;
@@ -1215,7 +1215,7 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 	Common::Point newPos = _scriptHandler->_viewportPos;
 
 	if (var2 >= 1) {
-		if (var2 >= 6) {
+		if (var2 > 6) {
 			newPos.x += 4;
 			if (newPos.x > 56)
 				newPos.x = 56;
@@ -1226,16 +1226,17 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 			newPos.x = 0;
 	}
 
-	if (var4 >= 1) {
+	if ((var4 < 1) && (newPos.y < 4))
+		newPos.y = 0;
+	else {
+		if (var4 < 1)
+			newPos.y -= 4;
+
 		if (var4 > 6) {
 			newPos.y += 4;
 			if (newPos.y >= 56)
 				newPos.y = 56;
 		}
-	} else {
-		newPos.y -= 4;
-		if (newPos.y < 0)
-			newPos.y = 0;
 	}
 
 	viewportScrollTo(newPos);
@@ -1362,7 +1363,7 @@ void LilliputEngine::sub15498(Common::Point pos, int var2) {
 }
 
 void LilliputEngine::checkSpeechClosing() {
-	debugC(2, kDebugEngineTBC, "checkSpeechClosing()");
+	debugC(2, kDebugEngine, "checkSpeechClosing()");
 
 	if (_scriptHandler->_speechTimer != 0) {
 		--_scriptHandler->_speechTimer;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 322e34a..b980333 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -155,7 +155,7 @@ public:
 	int _array12861[30];
 
 	byte *_rulesChunk1;
-	int _currentScriptCharacter;
+	int16 _currentScriptCharacter;
 	int16 _characterPositionX[40];
 	int16 _characterPositionY[40];
 	char _characterPositionAltitude[40];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 3187b20..04b8311 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -44,7 +44,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_heroismBarBottomY = 0;
 	_viewportPos.x = 0;
 	_viewportPos.y = 0;
-	_word18776 = 0;
+	_currentSpeechId = 0;
 	_array129A5[0] = 0;
 	_array129A5[1] = 1;
 	_array129A5[2] = 2;
@@ -106,7 +106,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_for();
 		break;
 	case 0x7:
-		return OC_compWord18776();
+		return OC_compCurrentSpeechId();
 		break;
 	case 0x8:
 		return OC_checkSaveFlag();
@@ -250,7 +250,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_ChangeIsoMap();
 		break;
 	case 0x2:
-		OC_sub17D57_speech1();
+		OC_startSpeech();
 		break;
 	case 0x3:
 		OC_sub17D7F_speech2();
@@ -259,7 +259,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17DB9_speech3();
 		break;
 	case 0x5:
-		OC_sub17DF9_speech1param();
+		OC_startSpeechIfMute();
 		break;
 	case 0x6:
 		OC_sub17E07_speech4param();
@@ -563,7 +563,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_CompareLastRandomValue", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_getRandom", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_for", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_compWord18776", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_compCurrentSpeechId", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_checkSaveFlag", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_compByte16F04", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub174D8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
@@ -612,10 +612,10 @@ static const OpCode opCodes1[] = {
 static const OpCode opCodes2[] = {
 /* 0x00 */	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x01 */	{ "OC_ChangeIsoMap", 3, kgetPosFromScript, kImmediateValue, kImmediateValue, kNone, kNone },
-/* 0x02 */	{ "OC_sub17D57_speech1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x02 */	{ "OC_startSpeech", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x03 */	{ "OC_sub17D7F_speech2", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x04 */	{ "OC_sub17DB9_speech3", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
-/* 0x05 */	{ "OC_sub17DF9_speech1param", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x05 */	{ "OC_startSpeechIfMute", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x06 */	{ "OC_sub17E07_speech4param", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
 /* 0x07 */	{ "OC_sub17E15_speech2param", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x08 */	{ "OC_ComputeCharacterVariable", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
@@ -1067,7 +1067,7 @@ void LilliputScript::sub16C86(int index, byte *buf) {
 }
 
 void LilliputScript::sub16C5C(int index, byte var3) {
-	debugC(1, kDebugScriptTBC, "sub16C5C(%d, %d)", index, var3);
+	debugC(1, kDebugScript, "sub16C5C(%d, %d)", index, var3);
 
 	assert(index < 40);
 	_array12839[index] = var3;
@@ -1085,8 +1085,8 @@ void LilliputScript::sub16C5C(int index, byte var3) {
 	sub16C86(index, buf);
 }
 
-void LilliputScript::sub17D40(bool &forceReturnFl) {
-	debugC(1, kDebugScriptTBC, "sub17D40()");
+void LilliputScript::checkSpeechAllowed(bool &forceReturnFl) {
+	debugC(1, kDebugScript, "checkSpeechAllowed()");
 
 	forceReturnFl = false;
 	if ((_vm->_displayMap != 1) && (_vm->_characterRelativePositionX[_vm->_currentScriptCharacter] != 0xFF))
@@ -1246,15 +1246,15 @@ void LilliputScript::listAllTexts() {
 	}
 }
 
-void LilliputScript::sub18B3C(int var) {
-	debugC(2, kDebugScriptTBC, "sub18B3C(%d)", var);
+void LilliputScript::startSpeech(int speechId) {
+	debugC(2, kDebugScriptTBC, "startSpeech(%d)", speechId);
 
-	if (var == -1)
+	if (speechId == -1)
 		return;
 
-	_word18776 = var;
+	_currentSpeechId = speechId;
 
-	int index = _vm->_packedStringIndex[var];
+	int index = _vm->_packedStringIndex[speechId];
 	int count = 0;
 	while (_vm->_packedStrings[index + count] == 0x5B)
 		++count;
@@ -1458,12 +1458,12 @@ byte LilliputScript::OC_for() {
 	return 1;
 }
 
-byte LilliputScript::OC_compWord18776() {
-	debugC(1, kDebugScriptTBC, "OC_compWord18776()");
+byte LilliputScript::OC_compCurrentSpeechId() {
+	debugC(1, kDebugScriptTBC, "OC_compCurrentSpeechId()");
 
 	int var1 = _currScript->readUint16LE();
 
-	if (var1 == _word18776)
+	if (var1 == _currentSpeechId)
 		return 1;
 
 	return 0;
@@ -2119,19 +2119,18 @@ void LilliputScript::OC_ChangeIsoMap() {
 	}
 }
 
-void LilliputScript::OC_sub17D57_speech1() {
-	debugC(1, kDebugScriptTBC, "OC_sub17D57_speech1()");
+void LilliputScript::OC_startSpeech() {
+	debugC(1, kDebugScript, "OC_startSpeech()");
 
 	int curWord = _currScript->readUint16LE();
 
 	bool forceReturnFl = false;
-	sub17D40(forceReturnFl);
+	checkSpeechAllowed(forceReturnFl);
 	if (forceReturnFl)
 		return;
 
 	_talkingCharacter = _vm->_currentScriptCharacter;
-	sub18B3C(curWord);
-
+	startSpeech(curWord);
 }
 
 void LilliputScript::sub18B7C(int var1, int var3) {
@@ -2140,15 +2139,15 @@ void LilliputScript::sub18B7C(int var1, int var3) {
 	if (var1 == 0xFFFF) 
 		return;
 
-	_word18776 = var1;
+	_currentSpeechId = var1;
 	int index = _vm->_packedStringIndex[var1];
 
-	while (_vm->_packedStrings[index] == 91)
+	while (_vm->_packedStrings[index] == '[')
 		++index;
 
 	for (int i = 0; i < var3; i++) {
-		int tmpVal = 93;
-		while (tmpVal == 93) {
+		byte tmpVal = ' ';
+		while (tmpVal != ']') {
 			tmpVal = _vm->_packedStrings[index];
 			++index;
 		}
@@ -2170,7 +2169,7 @@ void LilliputScript::OC_sub17D7F_speech2() {
 	var1 = _currScript->readUint16LE();
 
 	bool forceReturnFl = false;
-	sub17D40(forceReturnFl);
+	checkSpeechAllowed(forceReturnFl);
 	if (forceReturnFl)
 		return;
 
@@ -2192,7 +2191,7 @@ void LilliputScript::OC_sub17DB9_speech3() {
 	_currScript->writeUint16LE(tmpVal, -2); 
 
 	bool forceReturnFl = false;
-	sub17D40(forceReturnFl);
+	checkSpeechAllowed(forceReturnFl);
 	if (forceReturnFl)
 		return;
 
@@ -2202,11 +2201,11 @@ void LilliputScript::OC_sub17DB9_speech3() {
 	
 }
 
-void LilliputScript::OC_sub17DF9_speech1param() {
-	debugC(1, kDebugScriptTBC, "OC_sub17DF9_speech1param()");
+void LilliputScript::OC_startSpeechIfMute() {
+	debugC(1, kDebugScript, "OC_startSpeechIfMute()");
 
 	if (_talkingCharacter == -1) {
-		OC_sub17D57_speech1();
+		OC_startSpeech();
 		return;
 	}
 
@@ -2299,12 +2298,12 @@ void LilliputScript::OC_sub17E37_speech4() {
 	debugC(1, kDebugScriptTBC, "OC_sub17E37_speech4()");
 
 	bool forceReturnFl = false;
-	sub17D40(forceReturnFl);
+	checkSpeechAllowed(forceReturnFl);
 	if (forceReturnFl)
 		return;
 
 	_talkingCharacter = _vm->_currentScriptCharacter;
-	sub18B3C(5);
+	startSpeech(5);
 }
 
 void LilliputScript::OC_resetByte1714E() {
@@ -2390,14 +2389,14 @@ void LilliputScript::OC_resetByte16F04() {
 }
 
 void LilliputScript::OC_sub17AE1() {
-	debugC(1, kDebugScriptTBC, "OC_sub17AE1()");
+	debugC(1, kDebugScript, "OC_sub17AE1()");
 
 	byte var3 = (_currScript->readUint16LE() & 0xFF);
 	sub16C5C(_vm->_currentScriptCharacter, var3);
 }
 
 void LilliputScript::OC_sub17AEE() {
-	debugC(1, kDebugScriptTBC, "OC_sub17AEE()");
+	debugC(1, kDebugScript, "OC_sub17AEE()");
 
 	byte var3 = (_currScript->readUint16LE() & 0xFF);
 	sub16C5C(_vm->_currentScriptCharacter + 1, var3);
@@ -2766,7 +2765,7 @@ void LilliputScript::OC_sub18074() {
 }
 
 void LilliputScript::OC_setCurrentCharacterDirection() {
-	debugC(1, kDebugScriptTBC, "OC_setCurrentCharacterDirection()");
+	debugC(1, kDebugScript, "OC_setCurrentCharacterDirection()");
 
 	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
@@ -3238,7 +3237,7 @@ void LilliputScript::OC_sub186A1() {
 }
 
 void LilliputScript::OC_sub186E5_snd() {
-	debugC(1, kDebugScriptTBC, "OC_sub186E5_snd()");
+	debugC(1, kDebugScript, "OC_sub186E5_snd()");
 	int index = getValue1();
 	assert(index < 40);
 
@@ -3260,7 +3259,7 @@ void LilliputScript::OC_sub1870A_snd() {
 }
 
 void LilliputScript::OC_sub18725_snd() {
-	debugC(1, kDebugScriptTBC, "OC_sub18725_snd()");
+	debugC(1, kDebugScript, "OC_sub18725_snd()");
 
 	int var4 = getValue1() | 0xFF00;
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 5fdca27..de15fe1 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -73,8 +73,8 @@ public:
 	byte *_savedBuffer215Ptr;
 
 	Common::Point _viewportPos;
-	int _viewportCharacterTarget;
-	int _talkingCharacter;
+	int16 _viewportCharacterTarget;
+	int16 _talkingCharacter;
 	int _heroismBarX;
 	int _heroismBarBottomY;
 
@@ -108,7 +108,7 @@ private:
 	byte _speechDisplaySpeed;
 
 	int _word16F00;
-	int _word18776;
+	int _currentSpeechId;
 	int _word18821;
 	int _word129A3;
 
@@ -122,9 +122,9 @@ private:
 	void sub17B6C(int var1);
 	void sub16C86(int index, byte *buf);
 	void sub16C5C(int index, byte var3);
-	void sub17D40(bool &forceReturnFl);
+	void checkSpeechAllowed(bool &forceReturnFl);
 	void decodePackedText(char *buf);
-	void sub18B3C(int var);
+	void startSpeech(int var);
 	void displayNumber(byte var1, Common::Point pos);
 	byte *getMapPtr(Common::Point val);
 	byte *getCurrentCharacterVarFromScript();
@@ -150,7 +150,7 @@ private:
 	byte OC_CompareLastRandomValue();
 	byte OC_getRandom();
 	byte OC_for();
-	byte OC_compWord18776();
+	byte OC_compCurrentSpeechId();
 	byte OC_checkSaveFlag();
 	byte OC_compByte16F04();
 	byte OC_sub174D8();
@@ -197,10 +197,10 @@ private:
 	// Opcodes Type 2
 	void OC_setWord18821();
 	void OC_ChangeIsoMap();
-	void OC_sub17D57_speech1();
+	void OC_startSpeech();
 	void OC_sub17D7F_speech2();
 	void OC_sub17DB9_speech3();
-	void OC_sub17DF9_speech1param();
+	void OC_startSpeechIfMute();
 	void OC_sub17E07_speech4param();
 	void OC_sub17E15_speech2param();
 	void OC_ComputeCharacterVariable();


Commit: b3819ede5e91c89ff6518f66856596b03bbb15ca
    https://github.com/scummvm/scummvm/commit/b3819ede5e91c89ff6518f66856596b03bbb15ca
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More verifications and renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index dcf572f..9751057 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -209,7 +209,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	}
 
 	for (int i = 0; i < 30; i++)
-		_array12861[i] = 0xFFFF;
+		_array12861[i] = -1;
 
 	for (int i = 0; i < 256; i++)
 		_savedSurfaceUnderMouse[i] = 0;
@@ -1374,10 +1374,10 @@ void LilliputEngine::checkSpeechClosing() {
 	}
 }
 
-int LilliputEngine::getDirection(Common::Point param1, Common::Point param2) {
-	debugC(2, kDebugEngineTBC, "getDirection(%d - %d, %d - %d)", param1.x, param1.y, param2.x, param2.y);
+byte LilliputEngine::getDirection(Common::Point param1, Common::Point param2) {
+	debugC(2, kDebugEngine, "getDirection(%d - %d, %d - %d)", param1.x, param1.y, param2.x, param2.y);
 
-	static const char _directionsArray[8] = {0, 2, 0, 1, 3, 2, 3, 1};
+	static const byte _directionsArray[8] = {0, 2, 0, 1, 3, 2, 3, 1};
 
 	Common::Point var1 = param2;
 	Common::Point var2 = param1;
@@ -1581,21 +1581,21 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	return 1;
 }
 
-int LilliputEngine::findHotspot(Common::Point pos) {
-	debugC(2, kDebugEngineTBC, "findHotspot(%d, %d)", pos.x, pos.y);
+int16 LilliputEngine::findHotspot(Common::Point pos) {
+	debugC(2, kDebugEngine, "findHotspot(%d, %d)", pos.x, pos.y);
 
-	for (int i = 0; i < _rulesChunk12_size; i++) {
+	for (int i = 0; i < _rectNumb; i++) {
 		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
 			return i;
 	}
 	return -1;
 }
 
-int LilliputEngine::reverseFindHotspot(Common::Point pos) {
-	debugC(2, kDebugEngineTBC, "reverseFindHotspot(%d, %d)", pos.x, pos.y);
+int16 LilliputEngine::reverseFindHotspot(Common::Point pos) {
+	debugC(2, kDebugEngine, "reverseFindHotspot(%d, %d)", pos.x, pos.y);
 
-	for (int i = _rulesChunk12_size - 1; i >= 0 ; i--) {
-		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y<= (_rectYMinMax[i] & 0xFF)))
+	for (int i = _rectNumb - 1; i >= 0 ; i--) {
+		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
 			return i;
 	}
 	return -1;
@@ -2014,13 +2014,13 @@ byte LilliputEngine::sub16675(int idx, Common::Point var1) {
 	case 0:
 		break;
 	case 1:
-		sub166B1(index);
+		moveCharacterSpeed2(index);
 		break;
 	case 2:
-		sub166B6(index);
+		moveCharacterSpeed4(index);
 		break;
 	case 3:
-		sub166BB(index);
+		moveCharacterBack2(index);
 		break;
 	case 4:
 		sub16B63(index);
@@ -2029,19 +2029,19 @@ byte LilliputEngine::sub16675(int idx, Common::Point var1) {
 		sub16B76(index);
 		break;
 	case 6:
-		sub166C0(index);
+		moveCharacterUp1(index);
 		break;
 	case 7:
-		sub166C6(index);
+		moveCharacterUp2(index);
 		break;
 	case 8:
-		sub166CC(index);
+		moveCharacterDown1(index);
 		break;
 	case 9:
-		sub166D2(index);
+		moveCharacterDown2(index);
 		break;
 	case 10:
-		sub166D8(index);
+		moveCharacterSpeed3(index);
 		break;
 	default:
 		warning("sub16675 - Unexpected value %d", var1.x);
@@ -2064,109 +2064,110 @@ void LilliputEngine::sub16B76(int index) {
 	_characterDirectionArray[index] = nextDirection[_characterDirectionArray[index]];
 }
 
-void LilliputEngine::sub166C0(int index) {
-	debugC(2, kDebugEngineTBC, "sub166C0(%d)", index);
+void LilliputEngine::moveCharacterUp1(int index) {
+	debugC(2, kDebugEngine, "moveCharacterUp1(%d)", index);
 
 	_characterPositionAltitude[index] += 1;
 }
 
-void LilliputEngine::sub166C6(int index) {
-	debugC(2, kDebugEngineTBC, "sub166C6(%d)", index);
+void LilliputEngine::moveCharacterUp2(int index) {
+	debugC(2, kDebugEngine, "moveCharacterUp2(%d)", index);
 
 	_characterPositionAltitude[index] += 2;
 }
 
-void LilliputEngine::sub166CC(int index) {
-	debugC(2, kDebugEngineTBC, "sub166CC(%d)", index);
+void LilliputEngine::moveCharacterDown1(int index) {
+	debugC(2, kDebugEngine, "moveCharacterDown1(%d)", index);
 
 	_characterPositionAltitude[index] -= 1;
 }
 
-void LilliputEngine::sub166D2(int index) {
-	debugC(2, kDebugEngineTBC, "sub166D2(%d)", index);
+void LilliputEngine::moveCharacterDown2(int index) {
+	debugC(2, kDebugEngine, "moveCharacterDown2(%d)", index);
 
 	_characterPositionAltitude[index] -= 2;
 }
 
-void LilliputEngine::sub166B1(int index) {
-	debugC(2, kDebugEngineTBC, "sub166B1(%d)", index);
+void LilliputEngine::moveCharacterSpeed2(int index) {
+	debugC(2, kDebugEngine, "moveCharacterSpeed2(%d)", index);
 
-	sub16B31(index, 2);
+	sub16B31_moveCharacter(index, 2);
 }
 
-void LilliputEngine::sub166B6(int index) {
-	debugC(2, kDebugEngineTBC, "sub166B6(%d)", index);
+void LilliputEngine::moveCharacterSpeed4(int index) {
+	debugC(2, kDebugEngine, "moveCharacterSpeed4(%d)", index);
 
-	sub16B31(index, 4);
+	sub16B31_moveCharacter(index, 4);
 }
 
-void LilliputEngine::sub166BB(int index) {
-	debugC(2, kDebugEngineTBC, "sub166BB(%d)", index);
+void LilliputEngine::moveCharacterBack2(int index) {
+	debugC(2, kDebugEngine, "moveCharacterBack2(%d)", index);
 
-	sub16B31(index, -2);
+	sub16B31_moveCharacter(index, -2);
 }
 
-void LilliputEngine::sub166D8(int index) {
-	debugC(2, kDebugEngineTBC, "sub166D8(%d)", index);
+void LilliputEngine::moveCharacterSpeed3(int index) {
+	debugC(2, kDebugEngine, "moveCharacterSpeed3(%d)", index);
 
-	sub16B31(index, 3);
+	sub16B31_moveCharacter(index, 3);
 }
 
-void LilliputEngine::sub16B31(int index, int val) {
-	debugC(2, kDebugEngineTBC, "sub16B31(%d, %d)", index, val);
+void LilliputEngine::sub16B31_moveCharacter(int index, int16 speed) {
+	debugC(2, kDebugEngine, "sub16B31_moveCharacter(%d, %d)", index, speed);
 
-	int newX = _characterPositionX[index];
-	int newY = _characterPositionY[index];
+	int16 newX = _characterPositionX[index];
+	int16 newY = _characterPositionY[index];
 	switch (_characterDirectionArray[index]) {
 	case 0:
-		newX += val;
+		newX += speed;
 		break;
 	case 1:
-		newY -= val;
+		newY -= speed;
 		break;
 	case 2:
-		newY += val;
+		newY += speed;
 		break;
 	default:
-		newX -= val;
+		newX -= speed;
 		break;
 	}
-	sub16B8F(index, newX, newY, _characterDirectionArray[index]);
+	sub16B8F_moveCharacter(index, Common::Point(newX, newY), _characterDirectionArray[index]);
 }
 
-void LilliputEngine::sub16B8F(int index, int x, int y, int flag) {
-	debugC(2, kDebugEngineTBC, "sub16B8F(%d, %d, %d)", index, x, y);
+void LilliputEngine::sub16B8F_moveCharacter(int index, Common::Point pos, int direction) {
+	debugC(2, kDebugEngine, "sub16B8F_moveCharacter(%d, %d - %d, %d)", index, pos.x, pos.y, direction);
 
-	int diffX = x >> 3;
-	if (((diffX & 0xFF) == _scriptHandler->_array16123PosX[index]) && ((y >> 3) == _scriptHandler->_array1614BPosY[index])) {
-		_characterPositionX[index] = x;
-		_characterPositionY[index] = y;
+	int16 diffX = pos.x >> 3;
+	if (((diffX & 0xFF) == _scriptHandler->_array16123PosX[index]) && ((pos.y >> 3) == _scriptHandler->_array1614BPosY[index])) {
+		_characterPositionX[index] = pos.x;
+		_characterPositionY[index] = pos.y;
+		return;
 	}
 
-	if ((x < 0) || (x >= 512) || (y < 0) || (y >= 512))
+	if ((pos.x < 0) || (pos.x >= 512) || (pos.y < 0) || (pos.y >= 512))
 		return;
 
 	int mapIndex = (_scriptHandler->_array1614BPosY[index] << 6) + _scriptHandler->_array16123PosX[index];
 	mapIndex <<= 2;
 
-	if ((_bufferIsoMap[mapIndex + 3] & _array16C58[flag]) == 0)
+	if ((_bufferIsoMap[mapIndex + 3] & _array16C58[direction]) == 0)
 		return;
 
-	mapIndex = ((y & 0xFFF8) << 3) + diffX;
+	mapIndex = ((pos.y & 0xFFF8) << 3) + diffX;
 	mapIndex <<= 2;
 
-	if ((_bufferIsoMap[mapIndex + 3] & _array16C54[flag]) == 0)
+	if ((_bufferIsoMap[mapIndex + 3] & _array16C54[direction]) == 0)
 		return;
 
-	int var1 = _rulesBuffer2_10[index];
+	byte var1 = _rulesBuffer2_10[index];
 	var1 &= 7;
 	var1 ^= 7;
 
 	if ((var1 & _rulesChunk9[_bufferIsoMap[mapIndex]]) != 0)
 		return;
 
-	_characterPositionX[index] = x;
-	_characterPositionY[index] = y;
+	_characterPositionX[index] = pos.x;
+	_characterPositionY[index] = pos.y;
 }
 
 void LilliputEngine::sub17224(int var1, int var4) {
@@ -2217,10 +2218,10 @@ void LilliputEngine::sub171CF() {
 	++_word1289D;
 
 	for (int i = 0; i < 10; i++) {
-		if ((_array12861[(3 * i) + 1] != 0xFFFF) && (_array12861[3 * i] == _word1289D)) {
+		if ((_array12861[(3 * i) + 1] != -1) && (_array12861[3 * i] == _word1289D)) {
 			int var1 = _array12861[(3 * i) + 1];
 			int var4 = _array12861[(3 * i) + 2];
-			_array12861[(3 * i) + 1] = 0xFFFF;
+			_array12861[(3 * i) + 1] = -1;
 
 			sub17224(var1, var4);
 		}
@@ -2528,11 +2529,11 @@ void LilliputEngine::loadRules() {
 	}
 
 	// Chunk 12
-	_rulesChunk12_size = f.readUint16LE();
-	assert(_rulesChunk12_size <= 40);
+	_rectNumb = f.readUint16LE();
+	assert(_rectNumb <= 40);
 	uint16 tmpVal;
 
-	for (int i = 0; i < _rulesChunk12_size; i++) {
+	for (int i = 0; i < _rectNumb; i++) {
 		_rectXMinMax[i] = f.readUint16LE();
 		_rectYMinMax[i] = f.readUint16LE();
 		tmpVal = f.readUint16LE();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index b980333..a13dc41 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -152,7 +152,7 @@ public:
 	byte _byte15E35[40];
 	int _array11D49[40];
 	int _array1289F[40];
-	int _array12861[30];
+	int16 _array12861[30];
 
 	byte *_rulesChunk1;
 	int16 _currentScriptCharacter;
@@ -187,7 +187,7 @@ public:
 	byte _rulesChunk10_size;
 	int16 *_rulesChunk10;
 	byte *_rulesChunk11;
-	int16 _rulesChunk12_size;
+	int16 _rectNumb;
 	int16 _rectXMinMax[40];
 	int16 _rectYMinMax[40];
 	Common::Point _rulesBuffer12Pos3[40];
@@ -263,8 +263,8 @@ public:
 	byte sub16A76(int indexb, int indexs);
 	void sub17224(int var1, int var4);
 	void sub17264(int index, int var4);
-	int findHotspot(Common::Point pos);
-	int reverseFindHotspot(Common::Point pos);
+	int16 findHotspot(Common::Point pos);
+	int16 reverseFindHotspot(Common::Point pos);
 	byte sub16722(int index, Common::Point var1);
 	byte sub166EA(int index);
 	void sub167EF(int index);
@@ -272,7 +272,7 @@ public:
 	void renderCharacters(byte *buf, Common::Point pos);
 
 	byte sub16799(int index, Common::Point param1);
-	int getDirection(Common::Point param1, Common::Point param2);
+	byte getDirection(Common::Point param1, Common::Point param2);
 	void addCharToBuf(byte character);
 	void numberToString(int param1);
 	void sub12F37();
@@ -299,16 +299,16 @@ public:
 	void checkMapClosing(bool &forceReturnFl);
 	void sub16B63(int index);
 	void sub16B76(int index);
-	void sub166C0(int index);
-	void sub166C6(int index);
-	void sub166CC(int index);
-	void sub166D2(int index);
-	void sub166B1(int index);
-	void sub166B6(int index);
-	void sub166BB(int index);
-	void sub166D8(int index);
-	void sub16B31(int index, int val);
-	void sub16B8F(int index, int x, int y, int flag);
+	void moveCharacterUp1(int index);
+	void moveCharacterUp2(int index);
+	void moveCharacterDown1(int index);
+	void moveCharacterDown2(int index);
+	void moveCharacterSpeed2(int index);
+	void moveCharacterSpeed4(int index);
+	void moveCharacterBack2(int index);
+	void moveCharacterSpeed3(int index);
+	void sub16B31_moveCharacter(int index, int16 speed);
+	void sub16B8F_moveCharacter(int index, Common::Point pos, int direction);
 	byte sub1675D(int index, Common::Point var1);
 	byte sub16729(int index, Common::Point var1);
 	byte sub166F7(int index, Common::Point var1, int tmpVal);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 04b8311..d18abd7 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2456,12 +2456,12 @@ void LilliputScript::OC_setCurrentCharacter() {
 	_vm->setCurrentCharacter(var1);
 }
 
-void LilliputScript::sub171AF(int var1, int var2, int var4) {
-	debugC(2, kDebugScriptTBC, "sub171AF()");
+void LilliputScript::sub171AF(int16 var1, int16 var2, int16 var4) {
+	debugC(2, kDebugScript, "sub171AF()");
 
 	int index = 0;
 	for (int i = 0; i < 10; i++) {
-		if (_vm->_array12861[index + 1] == 0xFFFF) {
+		if (_vm->_array12861[index + 1] == -1) {
 			_vm->_array12861[index + 1] = var1;
 			_vm->_array12861[index + 2] = var2;
 			_vm->_array12861[index + 0] = _vm->_word1289D + var4;
@@ -2493,11 +2493,11 @@ void LilliputScript::OC_sub17CA2() {
 }
 
 void LilliputScript::OC_sub17CB9() {
-	debugC(1, kDebugScriptTBC, "OC_sub17CB9()");
+	debugC(1, kDebugScript, "OC_sub17CB9()");
 
-	int var4 = _currScript->readUint16LE();
-	int var1 = getValue1();
-	int var2 = _currScript->readUint16LE();
+	int16 var4 = _currScript->readSint16LE();
+	int16 var1 = getValue1();
+	int16 var2 = _currScript->readSint16LE();
 	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index de15fe1..580049b 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -128,7 +128,7 @@ private:
 	void displayNumber(byte var1, Common::Point pos);
 	byte *getMapPtr(Common::Point val);
 	byte *getCurrentCharacterVarFromScript();
-	void sub171AF(int var1, int var2, int var4);
+	void sub171AF(int16 var1, int16 var2, int16 var4);
 	void sub18B7C(int var1, int var3);
 	void sub189B8();
 	void sub189F5();


Commit: 742425f9a925ca985c39b327f0540c7598a39050
    https://github.com/scummvm/scummvm/commit/742425f9a925ca985c39b327f0540c7598a39050
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming, fix a couple of glitches in sub16DD5

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 9751057..c0c18ef 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -897,63 +897,64 @@ void LilliputEngine::paletteFadeIn() {
 int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	debugC(2, kDebugEngineTBC, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);
 
-	byte *isoMap = _bufferIsoMap + (x1 << 8) + (y1 << 2) + 1;
+	byte *isoMap = _bufferIsoMap + (y1 << 8) + (x1 << 2) + 1;
 
 	int dx = x2 - x1;
 	int dy = y2 - y1;
 
-	int word16DCB = 0; 
-	int word16DCD = 0;
-	int word16DD1 = 0;
-	int word16DCF = 0;
+	int16 tmpMapMoveX = 0; 
+	int16 tmpMapMoveY = 0;
+	int16 mapMoveY = 0;
+	int16 mapMoveX = 0;
 
-	byte byte16DD4 = 0;
-	byte byte16DD3 = 0;
+	int8 byte16DD4 = 0;
+	int8 byte16DD3 = 0;
 
 	if (dx < 0) {
 		dx = -dx;
-		word16DCB = -4;
+		tmpMapMoveX = -4;
 	} else {
-		word16DCB = 4;
+		tmpMapMoveX = 4;
 	}
 
 	if (dy < 0) {
 		dy = -dy;
-		word16DCD = -256;
+		tmpMapMoveY = -256;
 	} else {
-		word16DCD = 256;
+		tmpMapMoveY = 256;
 	}
 
-	if (dy > dx) {
-		word16DD1 = 0;
-		word16DCF = word16DCB;
+	if (dx >= dy) {
+		mapMoveY = 0;
+		mapMoveX = tmpMapMoveX;
 	} else {
-		int tmp = dx;
+		int tmp = dy;
 		dy = dx;
 		dx = tmp;
-		word16DCF = 0;
-		word16DD1 = word16DCD;
+		mapMoveX = 0;
+		mapMoveY = tmpMapMoveY;
 	}
 
-	byte16DD4 = (dx << 1) - dy;
-	byte16DD3 = (dx << 1) - 2 * dy;
-	word16DCF += word16DD1;
-	word16DCB += word16DCD;
+	byte16DD4 = dy << 1;
+	int var1 = byte16DD4 - dx;
+	byte16DD3 = byte16DD4 - (dx * 2);
+
+	mapMoveX += mapMoveY;
+	tmpMapMoveX += tmpMapMoveY;
 
-	int var1 = byte16DD4;
 	int count = 0; 
 
 	while (*isoMap == 0xFF) {
-		if (var1 > 0) {
-			isoMap += word16DCB;
+		if (var1 >= 0) {
+			isoMap += tmpMapMoveX;
 			var1 += byte16DD3;
 		} else {
-			isoMap += word16DCF;
+			isoMap += mapMoveX;
 			var1 += byte16DD4;
 		}
 		
 		count++;
-		if (count == dy) {
+		if (count > dx) {
 			return 0;
 		}
 	}
@@ -1030,7 +1031,7 @@ void LilliputEngine::sub16CA0() {
 				int d1 = _scriptHandler->_array16123PosX[index2];
 				int d2 = _scriptHandler->_array1614BPosY[index2];
 	
-				if (d1 != 0xFF) {
+				if (d1 != -1) {
 					int x = c1 - d1;
 					if ((x > -6) && (x < 6)) {
 						int y = c2 - d2;
@@ -1096,9 +1097,7 @@ void LilliputEngine::sub16CA0() {
 				val = (val & 0xFF00) | _byte16C9F;
 			}
 			_scriptHandler->_array10B51[index2 + index * 40] = val;	
-
 		}
-
 	}
 }
 
@@ -1696,7 +1695,7 @@ void LilliputEngine::sub16626() {
 
 			switch (var2 / 2) {
 			case 0:
-				result = sub16675(index, var1);
+				result = sub16675_moveCharacter(index, var1);
 				break;
 			case 1:
 				result = sub166DD(index, var1);
@@ -1745,15 +1744,15 @@ void LilliputEngine::sub16626() {
 }
 
 byte LilliputEngine::sub166EA(int index) {
-	debugC(2, kDebugEngineTBC, "sub166EA(%d)", index);
+	debugC(2, kDebugEngine, "sub166EA(%d)", index);
 
-	_scriptHandler->_array12811[index] = 0x10;
+	_scriptHandler->_array12811[index] = 16;
 	_scriptHandler->_characterScriptEnabled[index] = 1;
 	return 1;
 }
 
 byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
-	debugC(2, kDebugEngineTBC, "sub166F7(%d, %d - %d, %d)", index, var1.x, var1.y, tmpVal);
+	debugC(2, kDebugEngine, "sub166F7(%d, %d - %d, %d)", index, var1.x, var1.y, tmpVal);
 
 	byte a2 = var1.y;
 	if (a2 != 0) {
@@ -1772,10 +1771,11 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 }
 
 byte LilliputEngine::sub166DD(int index, Common::Point var1) {
-	debugC(2, kDebugEngineTBC, "sub166DD(%d, %d - %d)", index, var1.x, var1.y);
+	debugC(2, kDebugEngine, "sub166DD(%d, %d - %d)", index, var1.x, var1.y);
 	
-	_characterDirectionArray[index] = (var1.x & 3);
-	sub16685(index, var1);
+	char var1h = var1.x & 3;
+	_characterDirectionArray[index] = var1h;
+	sub16685(index, Common::Point(var1h, var1.y));
 	return 0;
 }
 
@@ -1998,14 +1998,14 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 }
 
 void LilliputEngine::sub16685(int idx, Common::Point var1) {
-	debugC(2, kDebugEngineTBC, "sub16685(%d, %d - %d)", idx, var1.x, var1.y);
+	debugC(2, kDebugEngine, "sub16685(%d, %d - %d)", idx, var1.x, var1.y);
 
 	int index = (idx << 5) + var1.y;
 	_scriptHandler->_array10AB1[idx] = _rulesBuffer2_16[index];
 }
 
-byte LilliputEngine::sub16675(int idx, Common::Point var1) {
-	debugC(2, kDebugEngineTBC, "sub16675(%d, %d - %d)", idx, var1.x, var1.y);
+byte LilliputEngine::sub16675_moveCharacter(int idx, Common::Point var1) {
+	debugC(2, kDebugEngine, "sub16675_moveCharacter(%d, %d - %d)", idx, var1.x, var1.y);
 
 	sub16685(idx, var1);
 
@@ -2023,10 +2023,10 @@ byte LilliputEngine::sub16675(int idx, Common::Point var1) {
 		moveCharacterBack2(index);
 		break;
 	case 4:
-		sub16B63(index);
+		turnCharacter1(index);
 		break;
 	case 5:
-		sub16B76(index);
+		turnCharacter2(index);
 		break;
 	case 6:
 		moveCharacterUp1(index);
@@ -2044,21 +2044,21 @@ byte LilliputEngine::sub16675(int idx, Common::Point var1) {
 		moveCharacterSpeed3(index);
 		break;
 	default:
-		warning("sub16675 - Unexpected value %d", var1.x);
+		warning("sub16675_moveCharacter - Unexpected value %d", var1.x);
 	}
 
 	return 0;
 }
 
-void LilliputEngine::sub16B63(int index) {
-	debugC(2, kDebugEngineTBC, "sub16B63(%d)", index);
+void LilliputEngine::turnCharacter1(int index) {
+	debugC(2, kDebugEngine, "turnCharacter1(%d)", index);
 
 	static const byte nextDirection[4] = {1, 3, 0, 2};
 	_characterDirectionArray[index] = nextDirection[_characterDirectionArray[index]];
 }
 
-void LilliputEngine::sub16B76(int index) {
-	debugC(2, kDebugEngineTBC, "sub16B76(%d)", index);
+void LilliputEngine::turnCharacter2(int index) {
+	debugC(2, kDebugEngine, "turnCharacter2(%d)", index);
 
 	static const byte nextDirection[4] = {2, 0, 3, 1};
 	_characterDirectionArray[index] = nextDirection[_characterDirectionArray[index]];
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index a13dc41..09c9614 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -276,7 +276,7 @@ public:
 	void addCharToBuf(byte character);
 	void numberToString(int param1);
 	void sub12F37();
-	byte sub16675(int idx, Common::Point var1);
+	byte sub16675_moveCharacter(int idx, Common::Point var1);
 	void sub16685(int idx, Common::Point var1);
 	void sub16EBC();
 	void sub16CA0();
@@ -297,8 +297,8 @@ public:
 	void sub15498(Common::Point pos, int var2);
 	void sub15A4C(int vgaIndex, byte *srcBuf, int &bufIndex);
 	void checkMapClosing(bool &forceReturnFl);
-	void sub16B63(int index);
-	void sub16B76(int index);
+	void turnCharacter1(int index);
+	void turnCharacter2(int index);
 	void moveCharacterUp1(int index);
 	void moveCharacterUp2(int index);
 	void moveCharacterDown1(int index);
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 580049b..07c4dec 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -63,7 +63,7 @@ public:
 	int8 _interfaceHotspotStatus[20];
 	char _array16123PosX[40];
 	char _array1614BPosY[40];
-	byte _array12811[40];
+	char _array12811[40];
 	char _array10AB1[40];
 	byte _array122FD[20];
 	byte _array122C1[40];


Commit: 2ea4cc178b47b5d49c5236dc91ddeccf60bfbefc
    https://github.com/scummvm/scummvm/commit/2ea4cc178b47b5d49c5236dc91ddeccf60bfbefc
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Verifications and renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index c0c18ef..9a66fea 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1818,7 +1818,7 @@ byte LilliputEngine::sub1675D(int index, Common::Point var1) {
 }
 
 void LilliputEngine::sub16EBC() {
-	debugC(2, kDebugEngineTBC, "sub16EBC()");
+	debugC(2, kDebugEngine, "sub16EBC()");
 
 	int index2 = 3;
 
@@ -1836,7 +1836,7 @@ void LilliputEngine::sub16EBC() {
 }
 
 void LilliputEngine::sub12F37() {
-	debugC(2, kDebugEngineTBC, "sub12F37()");
+	debugC(2, kDebugEngine, "sub12F37()");
 
 	int index1 = _animationTick + 2;
 	int index2 = 0;
@@ -2171,7 +2171,7 @@ void LilliputEngine::sub16B8F_moveCharacter(int index, Common::Point pos, int di
 }
 
 void LilliputEngine::sub17224(int var1, int var4) {
-	debugC(2, kDebugEngineTBC, "sub17224(%d, %d)", var1, var4);
+	debugC(2, kDebugEngine, "sub17224(%d, %d)", var1, var4);
 
 	byte type = (var1 >> 8);
 	if (type == 0) {
@@ -2187,16 +2187,16 @@ void LilliputEngine::sub17224(int var1, int var4) {
 
 	int index = var4 & 0xFF;
 	for (int i = 0; i < _numCharacters; i++) {
-		if (_scriptHandler->_array10B51[index] >= type)
+		if ((_scriptHandler->_array10B51[index] & 0xFF) >= type)
 			sub17264(i, var4);
 		index += 40;
 	}
 }
 
 void LilliputEngine::sub17264(int index, int var4) {
-	debugC(2, kDebugEngineTBC, "sub17264(%d, %d)", index, var4);
+	debugC(2, kDebugEngine, "sub17264(%d, %d)", index, var4);
 
-	if (_array11D49[index] != 0xFFFF) {
+	if (_array11D49[index] != -1) {
 		_array1289F[index] = var4;
 	} else {
 		_scriptHandler->_characterScriptEnabled[index] = 1;
@@ -2205,12 +2205,12 @@ void LilliputEngine::sub17264(int index, int var4) {
 }
 
 void LilliputEngine::sub171CF() {
-	debugC(2, kDebugEngineTBC, "sub171CF()");
+	debugC(2, kDebugEngine, "sub171CF()");
 
 	for (int i = 0; i < _numCharacters; i++) {
-		if (_array1289F[i] != 0xFFFF) {
+		if (_array1289F[i] != -1) {
 			_array11D49[i] = _array1289F[i];
-			_array1289F[i] = 0xFFFF;
+			_array1289F[i] = -1;
 			_scriptHandler->_characterScriptEnabled[i] = 1;
 		}
 	}
@@ -2229,7 +2229,7 @@ void LilliputEngine::sub171CF() {
 }
 
 void LilliputEngine::sub12FE5() {
-	debugC(2, kDebugEngineTBC, "sub12FE5()");
+	debugC(2, kDebugEngine, "sub12FE5()");
 
 	if (_animationTick != 1)
 		return;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 09c9614..a06890a 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -150,8 +150,8 @@ public:
 
 	short _word15E5D[40];
 	byte _byte15E35[40];
-	int _array11D49[40];
-	int _array1289F[40];
+	int16 _array11D49[40];
+	int16 _array1289F[40];
 	int16 _array12861[30];
 
 	byte *_rulesChunk1;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index d18abd7..22f11f6 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1057,7 +1057,7 @@ void LilliputScript::sub17B6C(int var1) {
 }
 
 void LilliputScript::sub16C86(int index, byte *buf) {
-	debugC(1, kDebugScriptTBC, "sub16C86()");
+	debugC(1, kDebugScript, "sub16C86()");
 
 	_array12811[index] = 0;
 
@@ -1399,10 +1399,10 @@ byte LilliputScript::OC_sub1740A() {
 	}
 
 	byte *isoMapBuf = getMapPtr(var);
-	int var2 = isoMapBuf[3];
+	uint16 var2 = isoMapBuf[3];
 
-	int var3 = _currScript->readUint16LE();
-	int var4 = 8 >> var3;
+	int16 var3 = _currScript->readUint16LE();
+	uint16 var4 = 8 >> var3;
 
 	if (var2 & var4) {
 		return 1;
@@ -1444,7 +1444,7 @@ byte LilliputScript::OC_getRandom() {
 }
 
 byte LilliputScript::OC_for() {
-	debugC(1, kDebugScriptTBC, "OC_for()");
+	debugC(1, kDebugScript, "OC_for()");
 
 	int var1 = _currScript->readUint16LE();
 	int tmpVal = _currScript->readUint16LE() + 1;
@@ -1560,24 +1560,27 @@ byte LilliputScript::OC_compareCoords_2() {
 }
 
 byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() {
-	debugC(1, kDebugScriptTBC, "OC_CompareDistanceFromCharacterToPositionWith()");
+	debugC(1, kDebugScript, "OC_CompareDistanceFromCharacterToPositionWith()");
 
 	Common::Point var1 = getPosFromScript();
 	Common::Point pos = _vm->_currentScriptCharacterPos;
 	
 	int dx = var1.x - pos.x;
-	if (dx < 0) dx = -dx;
+	if (dx < 0)
+		dx = -dx;
 
 	int dy = var1.y - pos.y;
-	if (dy < 0) dy = -dy;
+	if (dy < 0)
+		dy = -dy;
 
-	int dist = dx + dy;
+	int16 dist = dx + dy;
 		
 	uint16 operation = _currScript->readUint16LE();
 	int16 var2 = _currScript->readSint16LE();
 	
 	return compareValues(dist, operation, var2);
 }
+
 byte LilliputScript::OC_compareRandomCharacterId() {
 	debugC(1, kDebugScriptTBC, "OC_compareRandomCharacterId()");
 
@@ -1761,13 +1764,13 @@ byte LilliputScript::OC_sub17782() {
 }
 
 byte *LilliputScript::getMapPtr(Common::Point val) {
-	debugC(1, kDebugScriptTBC, "getMapPtr(%d %d)", val.x, val.y);
+	debugC(1, kDebugScript, "getMapPtr(%d %d)", val.x, val.y);
 
 	return &_vm->_bufferIsoMap[(val.y * 64 + val.x) << 2];
 }
 
 byte LilliputScript::OC_CompareMapValueWith() {
-	debugC(1, kDebugScriptTBC, "OC_CompareMapValueWith()");
+	debugC(1, kDebugScript, "OC_CompareMapValueWith()");
 
 	Common::Point tmpVal = getPosFromScript();
 
@@ -1775,11 +1778,11 @@ byte LilliputScript::OC_CompareMapValueWith() {
 		_currScript->seek(_currScript->pos() + 6);
 		return 0;
 	}
-	int var2 = _currScript->readUint16LE();
+	int16 var2 = _currScript->readUint16LE();
 	byte *buf = getMapPtr(tmpVal);
-	byte var1 = buf[var2];
-	int oper = _currScript->readUint16LE();
-	var2 = _currScript->readUint16LE();
+	int16 var1 = buf[var2];
+	uint16 oper = _currScript->readUint16LE();
+	var2 = _currScript->readSint16LE();
 	
 	return compareValues(var1, oper, var2);
 }
@@ -2553,10 +2556,10 @@ void LilliputScript::OC_sub17E6D() {
 }
 
 void LilliputScript::OC_changeCurrentCharacterSprite() {
-	debugC(2, kDebugScriptTBC, "OC_changeCurrentCharacterSprite()");
+	debugC(2, kDebugScript, "OC_changeCurrentCharacterSprite()");
 
-	int var1 = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
+	int16 var1 = _currScript->readSint16LE();
+	byte var2 = (_currScript->readUint16LE() & 0xFF);
 	_vm->_characterFrameArray[_vm->_currentScriptCharacter] = var1;
 	_vm->_spriteSizeArray[_vm->_currentScriptCharacter] = var2;
 
@@ -2919,7 +2922,7 @@ void LilliputScript::OC_sub18260() {
 }
 
 void LilliputScript::OC_CharacterVariableAddOrRemoveFlag() {
-	debugC(1, kDebugScriptTBC, "OC_CharacterVariableAddOrRemoveFlag()");
+	debugC(1, kDebugScript, "OC_CharacterVariableAddOrRemoveFlag()");
 
 	byte *tmpArr = getCharacterVariablePtr();
 


Commit: aa8ecc24931f2796f7b0a7d39a5ea3eeff0e7262
    https://github.com/scummvm/scummvm/commit/aa8ecc24931f2796f7b0a7d39a5ea3eeff0e7262
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Renaming, fix bug in startSpeech

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 9a66fea..20ecde2 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -190,7 +190,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array10A11PosY[i] = -1;
 		_array16E94[i] = 0;
 
-		_array11D49[i] = 0xFFFF;
+		_array11D49[i] = -1;
 		_characterPositionX[i] = -1;
 		_characterPositionY[i] = -1;
 		_characterPositionAltitude[i] = 0;
@@ -205,7 +205,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_rulesBuffer2_12[i] = 0;
 		_rulesBuffer2_13_posX[i] = 0;
 		_rulesBuffer2_14_posY[i] = 0;
-		_array1289F[i] = 0xFFFF;
+		_array1289F[i] = -1;
 	}
 
 	for (int i = 0; i < 30; i++)
@@ -522,8 +522,8 @@ void LilliputEngine::displayFunction10() {
 	displayMousePointer();
 }
 
-void LilliputEngine::sub15A4C(int vgaIndex, byte *srcBuf, int &bufIndex) {
-	debugC(2, kDebugEngineTBC, "sub15A4C()");
+void LilliputEngine::displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex) {
+	debugC(2, kDebugEngineTBC, "displaySpeechLine()");
 
 	int var3 = 0;
 	int var1;
@@ -554,16 +554,16 @@ void LilliputEngine::sub15A4C(int vgaIndex, byte *srcBuf, int &bufIndex) {
 
 }
 
-void LilliputEngine::displayFunction11(byte *buf) {
-	debugC(2, kDebugEngineTBC, "displayFunction11(%s)", buf);
+void LilliputEngine::displaySpeech(byte *buf) {
+	debugC(2, kDebugEngine, "displaySpeech(%s)", buf);
 
 	restoreSurfaceUnderMousePointer();
 
 	int vgaIndex = 70;
 	int bufIndex = 0;
 
-	byte _byte15A0C = 0;
-	int var1;
+	bool multiLineFlag = false;
+	byte var1;
 
 	for (;;) {
 		var1 = buf[bufIndex];
@@ -571,17 +571,17 @@ void LilliputEngine::displayFunction11(byte *buf) {
 		if (var1 == 0) {
 			vgaIndex += (4 * 320);
 			break;
-		} else if (var1 == 0x7C) {
-			_byte15A0C = 1;
+		} else if (var1 == '|') {
+			multiLineFlag = true;
 			break;
 		}
 	}
 
 	bufIndex = 0;
-	sub15A4C(vgaIndex, buf, bufIndex);
-	if (_byte15A0C == 1) {
+	displaySpeechLine(vgaIndex, buf, bufIndex);
+	if (multiLineFlag) {
 		vgaIndex += (8 * 320);
-		sub15A4C(vgaIndex, buf, bufIndex);
+		displaySpeechLine(vgaIndex, buf, bufIndex);
 	}
 
 	displayMousePointer();
@@ -2674,7 +2674,7 @@ void LilliputEngine::handleGameScripts() {
 
 
 	_word16EFE = _array11D49[index];
-	_array11D49[index] = 0xFFFF;
+	_array11D49[index] = -1;
 	_word1817B = 0;
 
 	int tmpVal = _rulesBuffer2_12[index];
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index a06890a..58e97ae 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -234,7 +234,7 @@ public:
 	void displayInterfaceHotspots();
 	void displayLandscape();
 	void displayFunction10();
-	void displayFunction11(byte *buf);
+	void displaySpeech(byte *buf);
 	void initGameAreaDisplay();
 	void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
 	void displayGameArea();
@@ -295,7 +295,7 @@ public:
 	void sub131FC(Common::Point pos);
 	void sub1546F(Common::Point displayPos);
 	void sub15498(Common::Point pos, int var2);
-	void sub15A4C(int vgaIndex, byte *srcBuf, int &bufIndex);
+	void displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex);
 	void checkMapClosing(bool &forceReturnFl);
 	void turnCharacter1(int index);
 	void turnCharacter2(int index);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 22f11f6..291091b 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1096,8 +1096,8 @@ void LilliputScript::checkSpeechAllowed(bool &forceReturnFl) {
 	return;
 }
 
-void LilliputScript::sub189F5() {
-	debugC(2, kDebugScriptTBC, "sub189F5()");
+void LilliputScript::formatSpeechString() {
+	debugC(2, kDebugScript, "formatSpeechString()");
 
 	int index = 0;
 	int var2 = 0x100;
@@ -1135,9 +1135,9 @@ void LilliputScript::sub189F5() {
 }
 
 void LilliputScript::sub189B8() {
-	debugC(2, kDebugScriptTBC, "sub189B8()");
+	debugC(2, kDebugScript, "sub189B8()");
 
-	sub189F5();
+	formatSpeechString();
 	int index = 0;
 
 	for (;;) {
@@ -1150,11 +1150,11 @@ void LilliputScript::sub189B8() {
 	index += 4;
 	_speechTimer = index;
 	_vm->displayFunction10();
-	_vm->displayFunction11(_vm->_displayStringBuf);
+	_vm->displaySpeech(_vm->_displayStringBuf);
 }
 
 void LilliputScript::decodePackedText(char *buf) {
-	debugC(2, kDebugScriptTBC, "decodePackedText(buf)");
+	debugC(2, kDebugScript, "decodePackedText(buf)");
 
 	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I''ve |can''t |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|''s |''t |re|gg|tt|pp|nn|ay|ar|wh|";
 
@@ -1247,7 +1247,7 @@ void LilliputScript::listAllTexts() {
 }
 
 void LilliputScript::startSpeech(int speechId) {
-	debugC(2, kDebugScriptTBC, "startSpeech(%d)", speechId);
+	debugC(2, kDebugScript, "startSpeech(%d)", speechId);
 
 	if (speechId == -1)
 		return;
@@ -1256,7 +1256,7 @@ void LilliputScript::startSpeech(int speechId) {
 
 	int index = _vm->_packedStringIndex[speechId];
 	int count = 0;
-	while (_vm->_packedStrings[index + count] == 0x5B)
+	while (_vm->_packedStrings[index + count] == '[')
 		++count;
 
 	int i = 0;
@@ -1266,7 +1266,7 @@ void LilliputScript::startSpeech(int speechId) {
 			for (int j = 0; j < tmpVal; j++) {
 				do
 					++i;
-				while (_vm->_packedStrings[index + count + i] != 0x5B);
+				while (_vm->_packedStrings[index + count + i] != ']');
 			}
 		}
 	}
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 07c4dec..fd4c239 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -131,7 +131,7 @@ private:
 	void sub171AF(int16 var1, int16 var2, int16 var4);
 	void sub18B7C(int var1, int var3);
 	void sub189B8();
-	void sub189F5();
+	void formatSpeechString();
 	Common::Point getCharacterTilePos(int index);
 	int sub18BB7(int index);
 


Commit: 0270cd311ae2a5f513df2a08f4b94d94a8a17805
    https://github.com/scummvm/scummvm/commit/0270cd311ae2a5f513df2a08f4b94d94a8a17805
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a bug in decodePackedText, some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 20ecde2..af41e43 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -499,8 +499,8 @@ void LilliputEngine::displayLandscape() {
 }
 
 // Display dialog bubble
-void LilliputEngine::displayFunction10() {
-	debugC(2, kDebugEngineTBC, "displayFunction10()");
+void LilliputEngine::displaySpeechBubble() {
+	debugC(2, kDebugEngine, "displaySpeechBubble()");
 	static const byte _array15976[16] = {244, 248, 250, 250, 252, 252, 252, 252, 252, 252, 252, 252, 250, 250, 248, 244};
 
 	restoreSurfaceUnderMousePointer();
@@ -523,7 +523,7 @@ void LilliputEngine::displayFunction10() {
 }
 
 void LilliputEngine::displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex) {
-	debugC(2, kDebugEngineTBC, "displaySpeechLine()");
+	debugC(2, kDebugEngine, "displaySpeechLine()");
 
 	int var3 = 0;
 	int var1;
@@ -551,7 +551,6 @@ void LilliputEngine::displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex
 		displayChar(vgaIndex, var1);
 		vgaIndex += 4;
 	}
-
 }
 
 void LilliputEngine::displaySpeech(byte *buf) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 58e97ae..a3bad2b 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -233,7 +233,7 @@ public:
 	void saveSurfaceSpeech();
 	void displayInterfaceHotspots();
 	void displayLandscape();
-	void displayFunction10();
+	void displaySpeechBubble();
 	void displaySpeech(byte *buf);
 	void initGameAreaDisplay();
 	void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 291091b..6cee72d 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1149,14 +1149,14 @@ void LilliputScript::sub189B8() {
 	index /= _speechDisplaySpeed;
 	index += 4;
 	_speechTimer = index;
-	_vm->displayFunction10();
+	_vm->displaySpeechBubble();
 	_vm->displaySpeech(_vm->_displayStringBuf);
 }
 
 void LilliputScript::decodePackedText(char *buf) {
 	debugC(2, kDebugScript, "decodePackedText(buf)");
 
-	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I''ve |can''t |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|''s |''t |re|gg|tt|pp|nn|ay|ar|wh|";
+	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I've |can't |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|'s |'t |re|gg|tt|pp|nn|ay|ar|wh|";
 
 	_vm->_displayStringIndex = 0;
 	_byte1881A = 0;
@@ -2412,17 +2412,17 @@ void LilliputScript::OC_setWord10804() {
 }
 
 void LilliputScript::OC_sub17C0E() {
-	debugC(1, kDebugScriptTBC, "OC_sub17C0E()");
+	debugC(1, kDebugScript, "OC_sub17C0E()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	Common::Point var1 = Common::Point(_vm->_currentCharacterVariables[4], _vm->_currentCharacterVariables[5]);
-	byte b2 = _vm->_currentCharacterVariables[6];
+	byte var2 = _vm->_currentCharacterVariables[6];
 
 	byte *mapPtr = getMapPtr(var1);
-	mapPtr[b2] = _vm->_currentCharacterVariables[7];
+	mapPtr[var2] = _vm->_currentCharacterVariables[7];
 	mapPtr[3] = _vm->_currentCharacterVariables[8];
 
-	if (b2 == 0) {
+	if (var2 == 0) {
 		_byte12A09 = 1;
 		_vm->displayLandscape();
 		_byte12A09 = 0;
@@ -2485,11 +2485,11 @@ void LilliputScript::OC_sub17C8B() {
 }
 
 void LilliputScript::OC_sub17CA2() {
-	debugC(1, kDebugScriptTBC, "OC_sub17CA2()");
+	debugC(1, kDebugScript, "OC_sub17CA2()");
 
-	int var1 = 1 << 8;
-	int var4 = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
+	int16 var1 = 1 << 8;
+	int16 var4 = _currScript->readSint16LE();
+	uint16 var2 = _currScript->readUint16LE();
 	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
@@ -2539,13 +2539,13 @@ void LilliputScript::OC_IncCurrentCharacterVar1() {
 }
 
 void LilliputScript::OC_sub17D23() {
-	debugC(1, kDebugScriptTBC, "OC_sub17D23()");
+	debugC(1, kDebugScript, "OC_sub17D23()");
 
-	uint16 var1 = _currScript->readUint16LE();
-	Common::Point var2 = getPosFromScript();
+	uint16 oper = _currScript->readUint16LE();
+	Common::Point var1 = getPosFromScript();
 	byte* buf = _vm->_currentCharacterVariables + 4;
-	computeOperation(buf, var1, var2.x);
-	computeOperation(buf + 1, var1, var2.y);
+	computeOperation(buf, oper, var1.x);
+	computeOperation(buf + 1, oper, var1.y);
 }
 
 void LilliputScript::OC_sub17E6D() {


Commit: e1bc0469defe2cb3a225e91767d2f3b765390314
    https://github.com/scummvm/scummvm/commit/e1bc0469defe2cb3a225e91767d2f3b765390314
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Janitorial: fix code formatting

Changed paths:
    engines/lilliput/detection.cpp
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h


diff --git a/engines/lilliput/detection.cpp b/engines/lilliput/detection.cpp
index bd31de1..f42221d 100644
--- a/engines/lilliput/detection.cpp
+++ b/engines/lilliput/detection.cpp
@@ -161,7 +161,9 @@ bool LilliputMetaEngine::hasFeature(MetaEngineFeature f) const {
 		(f == kSavesSupportCreationDate);
 }
 
-int LilliputMetaEngine::getMaximumSaveSlot() const { return 99; }
+int LilliputMetaEngine::getMaximumSaveSlot() const {
+	return 99;
+}
 
 SaveStateList LilliputMetaEngine::listSaves(const char *target) const {
 	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index af41e43..c67eb6b 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -106,8 +106,7 @@ static const byte _basisPalette[768] = {
 	63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63
 };
 
-LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) : Engine(syst), _gameDescription(gd)
-{
+LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) : Engine(syst), _gameDescription(gd) {
 	_system = syst;
 	DebugMan.addDebugChannel(kDebugEngine, "Engine", "Engine debug level");
 	DebugMan.addDebugChannel(kDebugScript, "Script", "Script debug level");
@@ -673,12 +672,12 @@ void LilliputEngine::displayCharactersOnMap() {
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = _numCharacters - 1; index >=0; index--) {
 		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614BPosY[index] != -1)) {
-			 int y = (3 * _scriptHandler->_array1614BPosY[index]) + 1;
-			 int x = (_scriptHandler->_array16123PosX[index] * 4) + 1;
+			int y = (3 * _scriptHandler->_array1614BPosY[index]) + 1;
+			int x = (_scriptHandler->_array16123PosX[index] * 4) + 1;
 
-			 _word15E5D[index] = y * 320 + x; 
-			 _byte15E35[index] = buf[y * 320 + x];
-			 buf[y * 320 + x] = _scriptHandler->_array128EF[index];
+			_word15E5D[index] = y * 320 + x;
+			_byte15E35[index] = buf[y * 320 + x];
+			buf[y * 320 + x] = _scriptHandler->_array128EF[index];
 		}
 	}
 	displayMousePointer();
@@ -869,7 +868,7 @@ void LilliputEngine::paletteFadeOut() {
 
 	resetSmallAnims();
 	byte palette[768];
-	for (int fade = 256; fade >= 0;	fade -= 8) {
+	for (int fade = 256; fade >= 0; fade -= 8) {
 		for (int i = 0; i < 768; i++) {
 			palette[i] = (_curPalette[i] * fade) >> 8;
 		}
@@ -883,7 +882,7 @@ void LilliputEngine::paletteFadeIn() {
 	debugC(2, kDebugEngine, "paletteFadeIn()");
 
 	byte palette[768];
-	for (int fade = 8; fade <= 256;	fade += 8) {
+	for (int fade = 8; fade <= 256; fade += 8) {
 		for (int i = 0; i < 768; i++) {
 			palette[i] = (_curPalette[i] * fade) >> 8;
 		}
@@ -901,7 +900,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	int dx = x2 - x1;
 	int dy = y2 - y1;
 
-	int16 tmpMapMoveX = 0; 
+	int16 tmpMapMoveX = 0;
 	int16 tmpMapMoveY = 0;
 	int16 mapMoveY = 0;
 	int16 mapMoveX = 0;
@@ -941,7 +940,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	mapMoveX += mapMoveY;
 	tmpMapMoveX += tmpMapMoveY;
 
-	int count = 0; 
+	int count = 0;
 
 	while (*isoMap == 0xFF) {
 		if (var1 >= 0) {
@@ -951,7 +950,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 			isoMap += mapMoveX;
 			var1 += byte16DD4;
 		}
-		
+
 		count++;
 		if (count > dx) {
 			return 0;
@@ -965,12 +964,12 @@ void LilliputEngine::sub15F75() {
 
 	_byte129A0 = 0xFF;
 	_savedMousePosDivided = Common::Point(-1, -1);
-	byte newX = _mousePos.x >> 2; 
+	byte newX = _mousePos.x >> 2;
 	byte newY = _mousePos.y / 3;
 
 	if ((newX >= 64) || (newY >= 64))
 		return;
-	
+
 	_savedMousePosDivided = Common::Point(newX, newY);
 	_byte16F07_menuId = 5;
 }
@@ -999,7 +998,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 
 	_mouseButton = 0;
 	sub15F75();
-	
+
 	_displayMap = 0;
 	paletteFadeOut();
 	_word15AC2 = 0;
@@ -1023,20 +1022,20 @@ void LilliputEngine::sub16CA0() {
 
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			_byte16C9F = 0;
-			if ((index != index2) && 
-				(_rulesBuffer2_5[index] != index2) &&
-				(_rulesBuffer2_5[index2] != index) &&
-				(_rulesBuffer2_11[index2] & 2) == 0) {
+			if ((index != index2) &&
+			        (_rulesBuffer2_5[index] != index2) &&
+			        (_rulesBuffer2_5[index2] != index) &&
+			        (_rulesBuffer2_11[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_array16123PosX[index2];
 				int d2 = _scriptHandler->_array1614BPosY[index2];
-	
+
 				if (d1 != -1) {
 					int x = c1 - d1;
 					if ((x > -6) && (x < 6)) {
 						int y = c2 - d2;
 						if ((y > -6) && (y < 6)) {
 							_byte16C9F = 1;
-	
+
 							if ((c1 == d1) && (c2 == d2)) {
 								_byte16C9F = 4;
 							} else if ((_rulesBuffer2_11[index] & 4) != 0) {
@@ -1050,7 +1049,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else if (_characterDirectionArray[index] == 1) {
 									if (d2 < c2) {
@@ -1060,7 +1059,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else if (_characterDirectionArray[index] == 2) {
 									if (d2 > c2) {
@@ -1070,7 +1069,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								} else {
 									if (d1 < c1) {
@@ -1080,7 +1079,7 @@ void LilliputEngine::sub16CA0() {
 											_byte16C9F = 3;
 
 										if (sub16DD5(c1, d1, c2, d2) != 0)
-											_byte16C9F = 1;	
+											_byte16C9F = 1;
 									}
 								}
 							}
@@ -1095,20 +1094,20 @@ void LilliputEngine::sub16CA0() {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
 				val = (val & 0xFF00) | _byte16C9F;
 			}
-			_scriptHandler->_array10B51[index2 + index * 40] = val;	
+			_scriptHandler->_array10B51[index2 + index * 40] = val;
 		}
 	}
 }
 
 void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	debugC(2, kDebugEngineTBC, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
-	
+
 	restoreSurfaceUnderMousePointer();
-	
+
 	if ((var1 & 0xFF) == 0x2D) {
 		var2 += 35;
 		var3 -= 35;
-		
+
 		if (var3 < 0) {
 			var2 += var3;
 			var3 = -var3;
@@ -1118,17 +1117,17 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	byte *vgaBuf = (byte *)_mainSurface->getPixels();
 	int tmpVal = (var3 >> 8) + ((var3 & 0xFF) << 8);
 	int vgaIndex = var2 + tmpVal + (tmpVal >> 2);
-	
+
 	if (var3 == 0)
 		++var3;
-	
+
 	for (int i = 0; i < 4; i++) {
 		for (int j = 0; j < var3; j++) {
 			vgaBuf[vgaIndex + j] = 2;
 		}
 		vgaIndex += 320;
 	}
-	
+
 	displayMousePointer();
 }
 
@@ -1172,8 +1171,8 @@ void LilliputEngine::sortCharacters() {
 		for (int var2 = 0; var2 < var4; var2++) {
 			int index1 = _charactersToDisplay[var2];
 			int index2 = _charactersToDisplay[var2 + 1];
-		
-			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2]) 
+
+			if (_characterRelativePositionY[index1] < _characterRelativePositionY[index2])
 				continue;
 
 			if (_characterRelativePositionY[index1] == _characterRelativePositionY[index2]) {
@@ -1255,7 +1254,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 	}
 
 	int dy = 0;
-	if (goalPos.y!= _scriptHandler->_viewportPos.y) {
+	if (goalPos.y != _scriptHandler->_viewportPos.y) {
 		if (goalPos.y < _scriptHandler->_viewportPos.y)
 			--dy;
 		else
@@ -1265,7 +1264,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 	do {
 		_scriptHandler->_viewportPos.x += dx;
 		_scriptHandler->_viewportPos.y += dy;
-		
+
 		displayLandscape();
 		prepareGameArea();
 		displayGameArea();
@@ -1308,7 +1307,7 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 			frame += _scriptHandler->_array10AB1[index];
 			if ((flag & 1) == 1)
 				frame += _spriteSizeArray[index];
-			
+
 			if (_array12299[index] != 0xFF) {
 				frame = _array12299[index] + 82;
 				--_array12299[index];
@@ -1327,11 +1326,11 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 
 void LilliputEngine::sub1546F(Common::Point displayPos) {
 	debugC(2, kDebugEngineTBC, "sub1546F(%d, %d)", displayPos.x, displayPos.y);
-	
+
 	int orgX = displayPos.x + 8;
 	int orgY = displayPos.y;
 	int var2 = 0;
-	
+
 	int x = orgX;
 	int y = orgY;
 	do {
@@ -1339,10 +1338,10 @@ void LilliputEngine::sub1546F(Common::Point displayPos) {
 		--x;
 		y >>= 1;
 	} while (y != 0);
-	
+
 	x = orgX + 1;
 	y = orgY >> 1;
-	
+
 	while (y != 0) {
 		sub15498(Common::Point(x, y), var2);
 		++x;
@@ -1352,7 +1351,7 @@ void LilliputEngine::sub1546F(Common::Point displayPos) {
 
 void LilliputEngine::sub15498(Common::Point pos, int var2) {
 	debugC(2, kDebugEngineTBC, "sub15498(%d - %d, %d)", pos.x, pos.y, var2);
-	
+
 	int index = pos.x + ((var2 & 0xFF) << 8) + (var2 >> 8);
 	for (int i = 1 + pos.y - var2; i > 0; i--) {
 		_savedSurfaceGameArea1[index] = 17;
@@ -1431,44 +1430,44 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 
 void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngineTBC, "sub167EF(%d)", index);
-	
+
 	int word167EB = findHotspot(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
 	int word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
-	
+
 	if (word167EB == word167ED) {
 		_array109E9PosX[index] = _array10999PosX[index];
 		_array10A11PosY[index] = _array109C1PosY[index];
 		return;
 	}
-	
+
 	if (word167EB == -1) {
 		int tmpVal = reverseFindHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
 		_array109E9PosX[index] = _rulesBuffer12Pos4[tmpVal].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[tmpVal].y;
 		return;
 	}
-	
-	if ((word167ED != -1) && 
-		  (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
-		  (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
-		  (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
-		  (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF))) {
+
+	if ((word167ED != -1) &&
+	        (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
+	        (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
+	        (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
+	        (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF))) {
 		_array109E9PosX[index] = _rulesBuffer12Pos4[word167ED].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
 	}
-	
+
 	_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
 	_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
 	int var4h = (_rectXMinMax[word167EB] >> 8);
 	int var4l = (_rectXMinMax[word167EB] & 0xFF);
-	
+
 	if (var4h != var4l) {
 		if (_array109E9PosX[index] == var4h) {
 			--_array109E9PosX[index];
 			return;
 		}
-		
+
 		if (_array109E9PosX[index] == var4l) {
 			++_array109E9PosX[index];
 			return;
@@ -1485,7 +1484,7 @@ void LilliputEngine::sub167EF(int index) {
 			return;
 		}
 	}
-	
+
 	// var4h == var4l
 	int mapIndex = (((_array10A11PosY[index] << 8) >> 2) + _array109E9PosX[index]) << 2;
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
@@ -1495,9 +1494,9 @@ void LilliputEngine::sub167EF(int index) {
 		--_array10A11PosY[index];
 	else if ((tmpVal & 2) != 0)
 		++_array10A11PosY[index];
-	else 
+	else
 		--_array109E9PosX[index];
-	
+
 	return;
 }
 
@@ -1509,12 +1508,12 @@ void LilliputEngine::sub1693A(int index) {
 	_word16937Pos = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
 
 	sub16A08(index);
-	
+
 	int var2 = (_characterDirectionArray[index] ^ 3);
 	// initialized by sub16A08, values: [0, 3[
 	_array1692B[var2] -= 8;
 	byte byte16939 = 0;
-	
+
 	int mapIndex = ((((_word16937Pos.y << 8) >> 2) + _word16937Pos.x) << 2);
 	int mapIndexDiff = 0;
 	int retVal = 0;
@@ -1545,7 +1544,7 @@ void LilliputEngine::sub1693A(int index) {
 			tmpVal = _array1692B[i];
 		}
 	}
-	
+
 	_characterDirectionArray[index] = retVal;
 }
 
@@ -1554,7 +1553,7 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 
 	static const char _array16A6C[4] = {1, 0, 0, -1};
 	static const char _array16A70[4] = {0, -1, 1, 0};
-	   
+
 	char var1h = _word16937Pos.x + _array16A6C[indexb];
 	char var1l = _word16937Pos.y + _array16A70[indexs];
 
@@ -1613,7 +1612,7 @@ void LilliputEngine::sub16A08(int index) {
 		int16 var1l = _word16937Pos.y + arrayMoveY[i] - _array10A11PosY[index];
 		arrayDistance[i] = (var1l * var1l) + (var1h * var1h);
 	}
-	
+
 	for (int i = 0; i < 4; i++)
 		_array1692B[i] = 0;
 
@@ -1641,7 +1640,7 @@ void LilliputEngine::addCharToBuf(byte character) {
 
 void LilliputEngine::numberToString(int param1) {
 	debugC(2, kDebugEngine, "numberToString(%d)", param1);
-	
+
 	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
 
 	int count;
@@ -1657,7 +1656,7 @@ void LilliputEngine::numberToString(int param1) {
 		--count;
 
 		byte tmpVal = count + 0x30;
-		
+
 		if (i == 4)
 			addCharToBuf(tmpVal);
 		else if ((count != 0) || (!hideZeros)) {
@@ -1771,7 +1770,7 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 
 byte LilliputEngine::sub166DD(int index, Common::Point var1) {
 	debugC(2, kDebugEngine, "sub166DD(%d, %d - %d)", index, var1.x, var1.y);
-	
+
 	char var1h = var1.x & 3;
 	_characterDirectionArray[index] = var1h;
 	sub16685(index, Common::Point(var1h, var1.y));
@@ -1822,7 +1821,7 @@ void LilliputEngine::sub16EBC() {
 	int index2 = 3;
 
 	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
-		int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2); 
+		int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2);
 		int var1 = (_bufferIsoMap[index2 + var2] & 0x40);
 
 		if (var1 == _array16E94[index1])
@@ -1849,7 +1848,7 @@ void LilliputEngine::sub12F37() {
 				--varPtr[0];
 				if (varPtr[0] == 1)
 					_scriptHandler->_characterScriptEnabled[index2] = 1;
-			}			
+			}
 		}
 
 		index1 += 32;
@@ -2008,7 +2007,7 @@ byte LilliputEngine::sub16675_moveCharacter(int idx, Common::Point var1) {
 
 	sub16685(idx, var1);
 
-	int index = idx;	
+	int index = idx;
 	switch (var1.x) {
 	case 0:
 		break;
@@ -2177,7 +2176,7 @@ void LilliputEngine::sub17224(int var1, int var4) {
 		sub17264(var1, var4);
 		return;
 	}
-	
+
 	if (type == 3) {
 		for (int i = _numCharacters - 1; i >= 0; i--)
 			sub17264(i, var4);
@@ -2270,7 +2269,7 @@ void LilliputEngine::displayHeroismIndicator() {
 	}
 
 	_scriptHandler->_heroismLevel += var2;
-	
+
 	int index = _scriptHandler->_heroismBarX + _scriptHandler->_heroismBarBottomY * 320 ;
 
 	var2 = _scriptHandler->_heroismLevel & 0xFF;
@@ -2322,7 +2321,7 @@ void LilliputEngine::pollEvent() {
 			break;
 		}
 	}
-	
+
 	if (_mousePos != _oldMousePos) {
 		_oldMousePos = _mousePos;
 		if (_skipDisplayFlag1 != 0) {
@@ -2356,7 +2355,7 @@ byte *LilliputEngine::loadVGA(Common::String filename, int expectedSize, bool lo
 	byte *decodeBuffer = (byte *)malloc(expectedSize);
 	int size = 0;
 
-	for (;(remainingSize > 0) && (size < expectedSize);) {
+	for (; (remainingSize > 0) && (size < expectedSize);) {
 		curByte = f.readByte();
 		--remainingSize;
 
@@ -2423,7 +2422,7 @@ void LilliputEngine::loadRules() {
 		error("Missing game file ERULES.PRG");
 
 	_word10800_ERULES = f.readUint16LE();
-	
+
 	// Chunk 1
 	int size = f.readUint16LE();
 	_rulesChunk1 = (byte *)malloc(sizeof(byte) * size);
@@ -2595,7 +2594,7 @@ void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
 		int32 a = palette[i];
 		assert(a < 64);
 
-		a =  (a << 2) | (a >> 4);
+		a = (a << 2) | (a >> 4);
 		if (a > 255)
 			a = 255;
 		palette[i] = a;
@@ -2617,7 +2616,7 @@ void LilliputEngine::setCurrentCharacter(int index) {
 
 	_currentScriptCharacter = index;
 
-	assert (index < 40);
+	assert(index < 40);
 	int posX = _characterPositionX[index];
 	int posY = _characterPositionY[index];
 
@@ -2680,27 +2679,27 @@ void LilliputEngine::handleGameScripts() {
 	if (tmpVal == 0xFF)
 		return;
 
-/* Decompiler follows
+	/* Decompiler follows
 
-	//_scriptHandler->listAllTexts();
+	    //_scriptHandler->listAllTexts();
 
-	debugC(1, kDebugEngineTBC, "================= Menu Script ==================");
-	ScriptStream script = ScriptStream(_menuScript, _menuScriptSize);
-	_scriptHandler->disasmScript(script);
-	debugC(1, kDebugEngineTBC, "============= End Menu Script ==================");
+		debugC(1, kDebugEngineTBC, "================= Menu Script ==================");
+		ScriptStream script = ScriptStream(_menuScript, _menuScriptSize);
+		_scriptHandler->disasmScript(script);
+		debugC(1, kDebugEngineTBC, "============= End Menu Script ==================");
 
 
-	for (int i = 0; i < _gameScriptIndexSize; i++) {
-		assert(tmpVal < _gameScriptIndexSize);
-		debugC(1, kDebugEngineTBC, "================= Game Script %d ==================", i);
-		ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[i]], _arrayGameScriptIndex[i + 1] - _arrayGameScriptIndex[i]);
-		_scriptHandler->disasmScript(script);
-		debugC(1, kDebugEngineTBC, "============= End Game Script %d ==================", i);
-	}
-	
-	while (1);
-*/
-	
+		for (int i = 0; i < _gameScriptIndexSize; i++) {
+			assert(tmpVal < _gameScriptIndexSize);
+			debugC(1, kDebugEngineTBC, "================= Game Script %d ==================", i);
+			ScriptStream script = ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[i]], _arrayGameScriptIndex[i + 1] - _arrayGameScriptIndex[i]);
+			_scriptHandler->disasmScript(script);
+			debugC(1, kDebugEngineTBC, "============= End Game Script %d ==================", i);
+		}
+
+		while (1);
+	*/
+
 	i = index;
 	//debugC(1, kDebugEngineTBC, "before char %d, pos %d %d, var0 %d, var1 %d, var2 %d var16 %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), *getCharacterVariablesPtr(i * 32 + 1), *getCharacterVariablesPtr(i * 32 + 2),  *getCharacterVariablesPtr(i * 32 + 22), _scriptHandler->_characterScriptEnabled[i]);
 
@@ -2744,7 +2743,7 @@ Common::Error LilliputEngine::run() {
 
 	_scriptHandler->runScript(ScriptStream(_initScript, _initScriptSize));
 
-	// Hack, see above 
+	// Hack, see above
 	_int8installed = true;
 
 	while (!_shouldQuit) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index a3bad2b..3932630 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -344,7 +344,7 @@ public:
 	byte _byte12FCE;
 	byte _byte129A0;
 	byte _numCharactersToDisplay;
-	byte _byte16C9F; 
+	byte _byte16C9F;
 	int16 _word10804;
 	bool _shouldQuit;
 


Commit: aac437d3cb8b6f1c62862ac98223c44c44a4f0a9
    https://github.com/scummvm/scummvm/commit/aac437d3cb8b6f1c62862ac98223c44c44a4f0a9
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix display/menu bug, Some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index c67eb6b..3d06b43 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -141,11 +141,11 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_byte12A06 = 2;
 	_byte12A07 = 0;
 	_byte12A08 = 0;
-	_byte12A09 = 0;
+	_refreshScreenFlag = false;
 	_byte16552 = 0;
 	_lastInterfaceHotspotIndex = -1;
 	_lastInterfaceHotspotButton = 0;
-	_byte16F08 = 0;	
+	_byte16F08 = 0;
 	_byte16C9F = 0;
 	_lastAnimationTick = 0;
 
@@ -258,10 +258,9 @@ void LilliputEngine::newInt8() {
 	}
 	--_byte12A06;
 	// TODO: check 'out 20h, 20h'
-	
-	// hack for the title stars because _int8installed is not set at the good place for the moment
-	//if (!_int8installed)
-	//	return;
+
+	if (!_int8installed)
+	  return;
 
 	// if (_soundEnabled)
 	_soundHandler->contentFct1();
@@ -276,8 +275,8 @@ void LilliputEngine::newInt8() {
 				--_sound_byte16F06;
 
 			_animationTick ^= 1;
-			if (_byte12A09 != 1 && _int8installed) // hack for the title stars because _int8installed is not set at the good place for the moment
-				displayFunction16();
+			if (!_refreshScreenFlag)
+				displayRefreshScreen();
 		}
 		_byte12A08 = 0;
 	}
@@ -328,7 +327,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 		// Sprite mirror
 		for (int y = 0; y < 16; y++) {
 			for (int x = 0; x < 16; x++) {
-				// May need a hack of 1 pixel 
+				// May need a hack of 1 pixel
 				if (src[15 - x] != 0)
 					buf[x] = src[15 - x];
 			}
@@ -737,7 +736,7 @@ void LilliputEngine::moveCharacters() {
 			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
 			_charactersToDisplay[_numCharactersToDisplay] = i;
 			++_numCharactersToDisplay;
- 		}
+		}
 	}
 
 	sortCharacters();
@@ -790,8 +789,8 @@ void LilliputEngine::prepareGameArea() {
 	}
 }
 
-void LilliputEngine::displayFunction16() {
-	debugC(2, kDebugEngineTBC, "displayFunction16()");
+void LilliputEngine::displayRefreshScreen() {
+	debugC(2, kDebugEngineTBC, "displayRefreshScreen()");
 
 	if (_displayMap == 1) {
 		bool forceReturnFl = false;
@@ -848,7 +847,7 @@ void LilliputEngine::displaySmallAnims() {
 		return;
 
 	_lastAnimationTick = _animationTick;
-	
+
 	assert(_smallAnimsFrameIndex < 8);
 	int subIndex = _smallAnimsFrameIndex;
 	displaySmallIndexedAnim(0, subIndex);
@@ -2316,7 +2315,7 @@ void LilliputEngine::pollEvent() {
 		case Common::EVENT_QUIT:
 			_shouldQuit = true;
 			break;
-		// TODO: handle keyboard
+			// TODO: handle keyboard
 		default:
 			break;
 		}
@@ -2735,17 +2734,12 @@ Common::Error LilliputEngine::run() {
 	_bufferIsoMap = loadRaw("ISOMAP.DTA");
 
 	loadRules();
-	// Hack: int8 should be installed at this point, but it's crashing during the
-	// rendering when the title screens are displayed
-	//_int8installed = true;
+	_int8installed = true;
 
 	_lastTime = _system->getMillis();
 
 	_scriptHandler->runScript(ScriptStream(_initScript, _initScriptSize));
 
-	// Hack, see above
-	_int8installed = true;
-
 	while (!_shouldQuit) {
 		handleMenu();
 		handleGameScripts();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 3932630..32604d7 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -111,7 +111,7 @@ public:
 	byte _byte12A06;
 	byte _byte12A07;
 	byte _byte12A08;
-	byte _byte12A09;
+	bool _refreshScreenFlag;
 	byte _byte16552;
 	int8 _lastInterfaceHotspotIndex;
 	byte _lastInterfaceHotspotButton; // Unused: set by 2 functions, but never used elsewhere
@@ -239,7 +239,7 @@ public:
 	void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
 	void displayGameArea();
 	void prepareGameArea();
-	void displayFunction16();
+	void displayRefreshScreen();
 	void restoreSurfaceSpeech();
 	void displayFunction18(int var1, int var2, int var3, int var4);
 	void displayCharacter(int index, Common::Point pos, int flags);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 6cee72d..f097059 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2423,9 +2423,9 @@ void LilliputScript::OC_sub17C0E() {
 	mapPtr[3] = _vm->_currentCharacterVariables[8];
 
 	if (var2 == 0) {
-		_byte12A09 = 1;
+		_vm->_refreshScreenFlag = true;
 		_vm->displayLandscape();
-		_byte12A09 = 0;
+		_vm->_refreshScreenFlag = false;
 	}
 }
 
@@ -2680,9 +2680,9 @@ void LilliputScript::OC_sub17F68() {
 	if (newPosY > 56)
 		newPosY = 56;
 
-	_byte12A09 = 1;
+	_vm->_refreshScreenFlag = true;
 	_vm->viewportScrollTo(Common::Point(newPosX, newPosY));
-	_byte12A09 = 0;
+	_vm->_refreshScreenFlag = false;
 
 }
 
@@ -2811,9 +2811,9 @@ void LilliputScript::OC_sub180C3() {
 	if (y > 56)
 		y = 56;
 
-	_byte12A09 = 1;
+	_vm->_refreshScreenFlag = true;
 	_vm->viewportScrollTo(Common::Point(x, y));
-	_byte12A09 = 0;
+	_vm->_refreshScreenFlag = false;
 }
 
 void LilliputScript::OC_setViewPortPos() {
@@ -2833,19 +2833,20 @@ void LilliputScript::OC_setCurrentCharacterAltitude() {
 }
 
 void LilliputScript::OC_sub1817F() {
-	debugC(1, kDebugScriptTBC, "OC_sub1817F()");
+	debugC(1, kDebugScript, "OC_sub1817F()");
 
-	int var1 = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
+	int16 var1 = _currScript->readUint16LE();
+	int16 var2 = _currScript->readUint16LE();
 	
-	int b1 = var1 & 0xFF;
-	int b2 = var2 & 0xFF;
-	sub1818B(Common::Point(b1, b2));
+	int16 x = var1 & 0xFF;
+	int16 y = var2 & 0xFF;
+	sub1818B(Common::Point(x, y));
 }
 
-//TODO checkme: parameter order is maybe wrong
-void LilliputScript::sub1818B(Common::Point pos) {
-	debugC(2, kDebugScriptTBC, "sub1818B(%d - %d)", pos.x, pos.y);
+void LilliputScript::sub1818B(Common::Point point) {
+	debugC(2, kDebugScriptTBC, "sub1818B(%d - %d)", point.x, point.y);
+
+	Common::Point pos = point;
 	for (int i = 0; i <  _vm->_word1817B; i++) {
 		if (_array1813BPos[i].x == pos.x) {
 			pos.y += _array1813BPos[i].y;
@@ -2861,34 +2862,38 @@ void LilliputScript::sub1818B(Common::Point pos) {
 	++_vm->_word1817B;
 }
 
-//TODO checkme: case 0x2D is dubious
 void LilliputScript::OC_sub181BB() {
 	debugC(1, kDebugScriptTBC, "OC_sub181BB()");
 	
-	int b = _currScript->readUint16LE();
-	int d = _currScript->readUint16LE() & 0xFF;
-	int s = _currScript->readUint16LE();
-	int c = _vm->_currentCharacterVariables[s];
-	int c2 = 0;
+	int16 x = _currScript->readUint16LE() & 0xFF;
+	int8 oper = _currScript->readUint16LE() & 0xFF;
+	int16 index = _currScript->readSint16LE();
+	int16 c = _vm->_currentCharacterVariables[index];
 
-	if (d == 0x2D) {
+	switch (oper) {
+	case '-':
 		c = - 1 - c;
-	} else if (d == 0x3E) {
-		c = c - 0x80;
+		break;
+	case '>':
+		c -= 128;
 		if (c < 0) 
 			c = 0;
-		c = c * 2;
-	} else if (d == 0x3C) {
-		c = -1 - c;
-		c = c - 0x80;
+		c *= 2;
+		break;
+	case '<':
+		c = -1 - c - 128;
 		if (c < 0)
 			c = 0;
-		c = c * 2;
+		c *= 2;
+		break;
+	default:
+		warning("OC_sub181BB: skipped oper 0x%x", oper);
+		break;
 	}
-
-	int a = (_currScript->readUint16LE() * c) + (c & 0xFF);
-	b = (b & 0xFF00) + a;
-	sub1818B(Common::Point(b >> 8, b & 0xFF));
+	c &= 0xFF;
+	int y = (_currScript->readSint16LE() * c) + c;
+	y >>= 8;
+	sub1818B(Common::Point(x, y));
 }
 
 void LilliputScript::OC_sub18213() {
@@ -2938,17 +2943,17 @@ void LilliputScript::OC_CharacterVariableAddOrRemoveFlag() {
 void LilliputScript::OC_PaletteFadeOut() {
 	debugC(1, kDebugScript, "OC_PaletteFadeOut()");
 
-	_byte12A09 = 1;
+	_vm->_refreshScreenFlag = true;
 	_vm->paletteFadeOut();
-	_byte12A09 = 0;
+	_vm->_refreshScreenFlag = false;
 }
 
 void LilliputScript::OC_PaletteFadeIn() {
 	debugC(1, kDebugScript, "OC_PaletteFadeIn()");
 
-	_byte12A09 = 1;
+	_vm->_refreshScreenFlag = true;
 	_vm->paletteFadeIn();
-	_byte12A09 = 0;
+	_vm->_refreshScreenFlag = false;
 }
 
 void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
@@ -3041,7 +3046,7 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	int var1 = _currScript->readUint16LE() & 0xff;
 	_vm->_byte15EAD = var1;
 
-	_byte12A09 = 1;
+	_vm->_refreshScreenFlag = true;
 	_talkingCharacter = -1;
 	OC_PaletteFadeOut();
 	_vm->_word15AC2 = 1;
@@ -3053,7 +3058,7 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	_vm->_keyboard_oldIndex = 0;
 	_vm->_keyboard_nextIndex = 0;
 
-	_vm->_byte12A09 = 0;
+	_vm->_refreshScreenFlag = false;
 }
 
 void LilliputScript::OC_sub17E22_speech1IfSoundOff() {
@@ -3108,7 +3113,7 @@ void LilliputScript::displayNumber(byte var1, Common::Point pos) {
 void LilliputScript::OC_displayVGAFile() {
 	debugC(1, kDebugScript, "OC_displayVGAFile()");
 
-	_byte12A09 = 1;
+	_vm->_refreshScreenFlag = true;
 	_vm->paletteFadeOut();
 	int curWord = _currScript->readUint16LE();
 	int index = _vm->_packedStringIndex[curWord];
@@ -3165,7 +3170,7 @@ void LilliputScript::OC_initGameAreaDisplay() {
 	_vm->initGameAreaDisplay();
 
 	OC_PaletteFadeIn();
-	_byte12A09 = 0;
+	_vm->_refreshScreenFlag = false;
 	
 	_vm->_soundHandler->contentFct5();
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index fd4c239..b65751d 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -98,7 +98,6 @@ private:
 	Common::Stack<ScriptStream *> _scriptStack;
 
 	byte _byte16F05_ScriptHandler;
-	byte _byte12A09;
 	byte _byte129A0;
 	byte _byte10806;
 	byte _lastRandomValue;
@@ -257,7 +256,7 @@ private:
 	void OC_setViewPortPos();
 	void OC_setCurrentCharacterAltitude();
 	void OC_sub1817F();
-	void sub1818B(Common::Point pos);
+	void sub1818B(Common::Point point);
 	void OC_sub181BB();
 	void OC_sub18213();
 	void OC_sub18252();


Commit: c8589eb488d20f893481fd7c8e4f4d9fa82bec72
    https://github.com/scummvm/scummvm/commit/c8589eb488d20f893481fd7c8e4f4d9fa82bec72
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix display of horizontal bars in character stats menu, some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3d06b43..7ed864a 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -669,7 +669,7 @@ void LilliputEngine::displayCharactersOnMap() {
 	restoreSurfaceUnderMousePointer();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
-	for (int index = _numCharacters - 1; index >=0; index--) {
+	for (int index = _numCharacters - 1; index >= 0; index--) {
 		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614BPosY[index] != -1)) {
 			int y = (3 * _scriptHandler->_array1614BPosY[index]) + 1;
 			int x = (_scriptHandler->_array16123PosX[index] * 4) + 1;
@@ -1098,12 +1098,12 @@ void LilliputEngine::sub16CA0() {
 	}
 }
 
-void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
-	debugC(2, kDebugEngineTBC, "displayFunction18(%d, %d, %d, %d)", var1, var2, var3, var4);
+void LilliputEngine::displayCharacterStatBar(int8 var1, int16 var2, int8 var3, int16 var4) {
+	debugC(2, kDebugEngineTBC, "displayCharacterStatBar(%d, %d, %d, %d)", var1, var2, var3, var4);
 
 	restoreSurfaceUnderMousePointer();
 
-	if ((var1 & 0xFF) == 0x2D) {
+	if (var1 == 45) {
 		var2 += 35;
 		var3 -= 35;
 
@@ -1114,8 +1114,7 @@ void LilliputEngine::displayFunction18(int var1, int var2, int var3, int var4) {
 	}
 
 	byte *vgaBuf = (byte *)_mainSurface->getPixels();
-	int tmpVal = (var3 >> 8) + ((var3 & 0xFF) << 8);
-	int vgaIndex = var2 + tmpVal + (tmpVal >> 2);
+	int vgaIndex = var2 + (320 * var4);
 
 	if (var3 == 0)
 		++var3;
@@ -2248,7 +2247,7 @@ void LilliputEngine::sub12FE5() {
 }
 
 void LilliputEngine::displayHeroismIndicator() {
-	debugC(2, kDebugEngineTBC, "displayHeroismIndicator()");
+	debugC(2, kDebugEngine, "displayHeroismIndicator()");
 
 	if (_scriptHandler->_savedBuffer215Ptr == NULL)
 		return;
@@ -2269,7 +2268,7 @@ void LilliputEngine::displayHeroismIndicator() {
 
 	_scriptHandler->_heroismLevel += var2;
 
-	int index = _scriptHandler->_heroismBarX + _scriptHandler->_heroismBarBottomY * 320 ;
+	int index = _scriptHandler->_heroismBarX + (_scriptHandler->_heroismBarBottomY * 320);
 
 	var2 = _scriptHandler->_heroismLevel & 0xFF;
 	if (var2 != 0) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 32604d7..3860d51 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -241,7 +241,7 @@ public:
 	void prepareGameArea();
 	void displayRefreshScreen();
 	void restoreSurfaceSpeech();
-	void displayFunction18(int var1, int var2, int var3, int var4);
+	void displayCharacterStatBar(int8 var1, int16 var2, int8 var3, int16 var4);
 	void displayCharacter(int index, Common::Point pos, int flags);
 	void displayString(byte *buf, Common::Point pos);
 	void displayChar(int index, int var1);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f097059..77063f8 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -505,7 +505,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_initGameAreaDisplay();
 		break;
 	case 0x57:
-		OC_sub1864D();
+		OC_displayCharacterStatBar();
 		break;
 	case 0x58:
 		OC_initSmallAnim();
@@ -697,7 +697,7 @@ static const OpCode opCodes2[] = {
 /* 0x54 */	{ "OC_sub184D7", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
 /* 0x55 */	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x56 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x57 */	{ "OC_sub1864D", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue}, 
+/* 0x57 */	{ "OC_displayCharacterStatBar", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue}, 
 /* 0x58 */	{ "OC_initSmallAnim", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x59 */	{ "OC_setCharacterHeroismBar", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },  //TODO
@@ -1943,7 +1943,7 @@ byte LilliputScript::OC_CharacterVariableAnd() {
 }
 
 byte LilliputScript::OC_IsCurrentCharacterVar0LessEqualThan() {
-	debugC(1, kDebugScriptTBC, "OC_IsCurrentCharacterVar0LessEqualThan()");
+	debugC(1, kDebugScript, "OC_IsCurrentCharacterVar0LessEqualThan()");
 
 	assert(_vm->_currentCharacterVariables != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
@@ -3175,16 +3175,16 @@ void LilliputScript::OC_initGameAreaDisplay() {
 	_vm->_soundHandler->contentFct5();
 }
 
-void LilliputScript::OC_sub1864D() {
-	debugC(1, kDebugScriptTBC, "OC_sub1864D()");
+void LilliputScript::OC_displayCharacterStatBar() {
+	debugC(1, kDebugScriptTBC, "OC_displayCharacterStatBar()");
 
 	byte *tmpArr = getCharacterVariablePtr();
-	int var1 = (_currScript->readUint16LE() & 0xFF);
-	int var3 = ((70 * tmpArr[0]) / (_currScript->readUint16LE() & 0xFF) & 0xFF);
-	int var2 = _currScript->readUint16LE();
-	int var4 = _currScript->readUint16LE();
+	int8 var1 = (_currScript->readUint16LE() & 0xFF);
+	int8 var3 = (((70 * tmpArr[0]) / (_currScript->readUint16LE() & 0xFF)) & 0xFF);
+	int16 var2 = _currScript->readSint16LE();
+	int16 var4 = _currScript->readSint16LE();
 	
-	_vm->displayFunction18(var1, var2, var3, var4);
+	_vm->displayCharacterStatBar(var1, var2, var3, var4);
 }
 
 void LilliputScript::OC_initSmallAnim() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index b65751d..d858fe5 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -282,7 +282,7 @@ private:
 	void OC_sub184D7();
 	void OC_displayTitleScreen();
 	void OC_initGameAreaDisplay();
-	void OC_sub1864D();
+	void OC_displayCharacterStatBar();
 	void OC_initSmallAnim();
 	void OC_setCharacterHeroismBar();
 	void OC_sub18690();


Commit: 8c7395b947f8b729d29c01637d97540a5f955129
    https://github.com/scummvm/scummvm/commit/8c7395b947f8b729d29c01637d97540a5f955129
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7ed864a..8ab326e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1098,29 +1098,32 @@ void LilliputEngine::sub16CA0() {
 	}
 }
 
-void LilliputEngine::displayCharacterStatBar(int8 var1, int16 var2, int8 var3, int16 var4) {
-	debugC(2, kDebugEngineTBC, "displayCharacterStatBar(%d, %d, %d, %d)", var1, var2, var3, var4);
+void LilliputEngine::displayCharacterStatBar(int8 type, int16 averagePosX, int8 score, int16 posY) {
+	debugC(2, kDebugEngine, "displayCharacterStatBar(%d, %d, %d, %d)", type, averagePosX, score, posY);
 
 	restoreSurfaceUnderMousePointer();
 
-	if (var1 == 45) {
-		var2 += 35;
-		var3 -= 35;
+	int16 posX = averagePosX;
 
-		if (var3 < 0) {
-			var2 += var3;
-			var3 = -var3;
+	// If var equals 45 ('-'), score bar from -x to +x. If not (usually 43 '+'), score bar from 0 to x.
+	if (type == 45) {
+		posX += 35;
+		score -= 35;
+
+		if (score < 0) {
+			posX += score;
+			score = -score;
 		}
 	}
 
 	byte *vgaBuf = (byte *)_mainSurface->getPixels();
-	int vgaIndex = var2 + (320 * var4);
+	int vgaIndex = posX + (320 * posY);
 
-	if (var3 == 0)
-		++var3;
+	if (score == 0)
+		++score;
 
 	for (int i = 0; i < 4; i++) {
-		for (int j = 0; j < var3; j++) {
+		for (int j = 0; j < score; j++) {
 			vgaBuf[vgaIndex + j] = 2;
 		}
 		vgaIndex += 320;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 3860d51..5bcc229 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -241,7 +241,7 @@ public:
 	void prepareGameArea();
 	void displayRefreshScreen();
 	void restoreSurfaceSpeech();
-	void displayCharacterStatBar(int8 var1, int16 var2, int8 var3, int16 var4);
+	void displayCharacterStatBar(int8 type, int16 averagePosX, int8 score, int16 posY);
 	void displayCharacter(int index, Common::Point pos, int flags);
 	void displayString(byte *buf, Common::Point pos);
 	void displayChar(int index, int var1);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 77063f8..a6dd51c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -3176,15 +3176,15 @@ void LilliputScript::OC_initGameAreaDisplay() {
 }
 
 void LilliputScript::OC_displayCharacterStatBar() {
-	debugC(1, kDebugScriptTBC, "OC_displayCharacterStatBar()");
+	debugC(1, kDebugScript, "OC_displayCharacterStatBar()");
 
 	byte *tmpArr = getCharacterVariablePtr();
-	int8 var1 = (_currScript->readUint16LE() & 0xFF);
-	int8 var3 = (((70 * tmpArr[0]) / (_currScript->readUint16LE() & 0xFF)) & 0xFF);
-	int16 var2 = _currScript->readSint16LE();
-	int16 var4 = _currScript->readSint16LE();
+	int8 type = (_currScript->readUint16LE() & 0xFF);
+	int8 score = (((70 * tmpArr[0]) / (_currScript->readUint16LE() & 0xFF)) & 0xFF);
+	int16 posX = _currScript->readSint16LE();
+	int16 posY = _currScript->readSint16LE();
 	
-	_vm->displayCharacterStatBar(var1, var2, var3, var4);
+	_vm->displayCharacterStatBar(type, posX, score, posY);
 }
 
 void LilliputScript::OC_initSmallAnim() {


Commit: f0a4290385343bf8c87bc03a2ec2f2a74a52572a
    https://github.com/scummvm/scummvm/commit/f0a4290385343bf8c87bc03a2ec2f2a74a52572a
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement unselectInterfaceButton, some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8ab326e..f2ba0ce 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1122,6 +1122,7 @@ void LilliputEngine::displayCharacterStatBar(int8 type, int16 averagePosX, int8
 	if (score == 0)
 		++score;
 
+	// Draw bar, color green, high = 4, width = score
 	for (int i = 0; i < 4; i++) {
 		for (int j = 0; j < score; j++) {
 			vgaBuf[vgaIndex + j] = 2;
@@ -1980,7 +1981,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	}
 
 	if (_byte12FCE == 1) {
-		sub130DD();
+		unselectInterfaceButton();
 		return;
 	}
 
@@ -2169,12 +2170,11 @@ void LilliputEngine::sub16B8F_moveCharacter(int index, Common::Point pos, int di
 	_characterPositionY[index] = pos.y;
 }
 
-void LilliputEngine::sub17224(int var1, int var4) {
-	debugC(2, kDebugEngine, "sub17224(%d, %d)", var1, var4);
+void LilliputEngine::sub17224(byte type, byte index, int var4) {
+	debugC(2, kDebugEngine, "sub17224(%d, %d, %d)", type, index, var4);
 
-	byte type = (var1 >> 8);
 	if (type == 0) {
-		sub17264(var1, var4);
+		sub17264(index, var4);
 		return;
 	}
 
@@ -2184,15 +2184,15 @@ void LilliputEngine::sub17224(int var1, int var4) {
 		return;
 	}
 
-	int index = var4 & 0xFF;
+	int index2 = var4 & 0xFF;
 	for (int i = 0; i < _numCharacters; i++) {
-		if ((_scriptHandler->_array10B51[index] & 0xFF) >= type)
+		if ((_scriptHandler->_array10B51[index2] & 0xFF) >= type)
 			sub17264(i, var4);
-		index += 40;
+		index2 += 40;
 	}
 }
 
-void LilliputEngine::sub17264(int index, int var4) {
+void LilliputEngine::sub17264(byte index, int var4) {
 	debugC(2, kDebugEngine, "sub17264(%d, %d)", index, var4);
 
 	if (_array11D49[index] != -1) {
@@ -2218,11 +2218,14 @@ void LilliputEngine::sub171CF() {
 
 	for (int i = 0; i < 10; i++) {
 		if ((_array12861[(3 * i) + 1] != -1) && (_array12861[3 * i] == _word1289D)) {
-			int var1 = _array12861[(3 * i) + 1];
+			int16 var1 = _array12861[(3 * i) + 1];
 			int var4 = _array12861[(3 * i) + 2];
 			_array12861[(3 * i) + 1] = -1;
 
-			sub17224(var1, var4);
+			byte type = var1 >> 8;
+			byte index = var1 & 0xFF;
+
+			sub17224(type, index, var4);
 		}
 	}
 }
@@ -2625,8 +2628,14 @@ void LilliputEngine::setCurrentCharacter(int index) {
 	_currentCharacterVariables = getCharacterVariablesPtr(_currentScriptCharacter * 32);
 }
 
-void LilliputEngine::sub130DD() {
-	warning("sub130DD()");
+void LilliputEngine::unselectInterfaceButton() {
+	debugC(1, kDebugEngine, "unselectInterfaceButton()");
+
+	_byte12FCE = 0;
+	_word15AC2 = 0;
+	_lastInterfaceHotspotButton = 0;
+	unselectInterfaceHotspots();
+	displayInterfaceHotspots();
 }
 
 void LilliputEngine::handleMenu() {
@@ -2646,7 +2655,7 @@ void LilliputEngine::handleMenu() {
 	_byte129A0 = 0xFF;
 
 	if (_byte16F07_menuId == 3)
-		sub130DD();
+		unselectInterfaceButton();
 
 	_byte16F07_menuId = 0;
 }
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 5bcc229..ea6159c 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -261,8 +261,8 @@ public:
 	void sub16626();
 	void sub16A08(int index);
 	byte sub16A76(int indexb, int indexs);
-	void sub17224(int var1, int var4);
-	void sub17264(int index, int var4);
+	void sub17224(byte type, byte index, int var4);
+	void sub17264(byte index, int var4);
 	int16 findHotspot(Common::Point pos);
 	int16 reverseFindHotspot(Common::Point pos);
 	byte sub16722(int index, Common::Point var1);
@@ -350,7 +350,7 @@ public:
 
 	void pollEvent();
 	void setCurrentCharacter(int index);
-	void sub130DD();
+	void unselectInterfaceButton();
 	void moveCharacters();
 	void setNextDisplayCharacter(int var1);
 	void handleGameScripts();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a6dd51c..68352ed 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2460,7 +2460,7 @@ void LilliputScript::OC_setCurrentCharacter() {
 }
 
 void LilliputScript::sub171AF(int16 var1, int16 var2, int16 var4) {
-	debugC(2, kDebugScript, "sub171AF()");
+	debugC(2, kDebugScriptTBC, "sub171AF()");
 
 	int index = 0;
 	for (int i = 0; i < 10; i++) {
@@ -2476,23 +2476,23 @@ void LilliputScript::sub171AF(int16 var1, int16 var2, int16 var4) {
 void LilliputScript::OC_sub17C8B() {
 	debugC(1, kDebugScriptTBC, "OC_sub17C8B()");
 
-	int var1 = 2 << 8;
-	int var4 = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
+	int16 type = 2 << 8;
+	int16 var4 = _currScript->readSint16LE();
+	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
+	uint16 var2 = (tmpVal << 8) + _vm->_currentScriptCharacter;
 	
-	sub171AF(var1, var2, var4);
+	sub171AF(type, var2, var4);
 }
 
 void LilliputScript::OC_sub17CA2() {
 	debugC(1, kDebugScript, "OC_sub17CA2()");
 
-	int16 var1 = 1 << 8;
+	int16 type = 1 << 8;
 	int16 var4 = _currScript->readSint16LE();
-	uint16 var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
+	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
+	uint16 var2 = (tmpVal << 8) + _vm->_currentScriptCharacter;
 	
-	sub171AF(var1, var2, var4);
+	sub171AF(type, var2, var4);
 }
 
 void LilliputScript::OC_sub17CB9() {
@@ -2500,8 +2500,8 @@ void LilliputScript::OC_sub17CB9() {
 
 	int16 var4 = _currScript->readSint16LE();
 	int16 var1 = getValue1();
-	int16 var2 = _currScript->readSint16LE();
-	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
+	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
+	uint16 var2 = (tmpVal << 8) + _vm->_currentScriptCharacter;
 	
 	sub171AF(var1, var2, var4);
 }
@@ -2509,12 +2509,12 @@ void LilliputScript::OC_sub17CB9() {
 void LilliputScript::OC_sub17CD1() {
 	debugC(1, kDebugScriptTBC, "OC_sub17CD1()");
 
-	int var1 = 3 << 8;
-	int var4 = _currScript->readUint16LE();
-	int var2 = _currScript->readUint16LE();
-	var2 = ((var2 & 0xFF) << 8) + _vm->_currentScriptCharacter;
+	int16 type = 3 << 8;
+	int16 var4 = _currScript->readSint16LE();
+	int tmpVal = (_currScript->readUint16LE() & 0xFF);
+	uint16 var2 = (tmpVal << 8) + _vm->_currentScriptCharacter;
 	
-	sub171AF(var1, var2, var4);
+	sub171AF(type, var2, var4);
 }
 
 void LilliputScript::OC_resetWord16EFE() {


Commit: f602ca7408fb35d8c18330e9e53c20a9fdb78898
    https://github.com/scummvm/scummvm/commit/f602ca7408fb35d8c18330e9e53c20a9fdb78898
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix mouse icon clipping, rework map Index formula, some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index f2ba0ce..68a4e32 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -346,9 +346,13 @@ void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point
 	int index2 = pos.x + (pos.y * 320);
 
 	for (int i = 0; i < 16; i++) {
-		for (int j = 0; j < 16; j++) {
-			if (newBuf[j] != 0)
-				((byte *)_mainSurface->getPixels())[index2 + j] = newBuf[j];
+		// clip on y
+		if (pos.y + i < 200) {
+			for (int j = 0; j < 16; j++) {
+				// clip on x
+				if ((newBuf[j] != 0) && (pos.x + j < 320))
+					((byte *)_mainSurface->getPixels())[index2 + j] = newBuf[j];
+			}
 		}
 		index2 += 320;
 		newBuf += 16;
@@ -482,14 +486,12 @@ void LilliputEngine::displayLandscape() {
 
 	memcpy(_savedSurfaceGameArea2, _savedSurfaceGameArea3, 176 * 256); // 45056
 
-	int var1 = (_scriptHandler->_viewportPos.y >> 8) + ((_scriptHandler->_viewportPos.y & 0xFF) << 8) + (_scriptHandler->_viewportPos.x << 2);
-	int var2;
-	int index = 0;
+	int index = (_scriptHandler->_viewportPos.y * 64 + _scriptHandler->_viewportPos.x) * 4;
 
-	for (int i = 0; i < 8; i++) {
-		for (int j = 0; j < 8 ; j++) {
-			var2 = (j << 8) + i;
-			displayIsometricBlock(_savedSurfaceGameArea2, _bufferIsoMap[var1 + index], var2, 0);
+	for (int posY = 0; posY < 8; posY++) {
+		for (int posX = 0; posX < 8 ; posX++) {
+			assert (index < 16384);
+			displayIsometricBlock(_savedSurfaceGameArea2, _bufferIsoMap[index], posX, posY, 0);
 			index += 4;
 		}
 		index += 224;
@@ -608,11 +610,11 @@ void LilliputEngine::initGameAreaDisplay() {
 	free(tmpBuf);
 }
 
-void LilliputEngine::displayIsometricBlock(byte *buf, int var1, int var2, int var3) {
-	debugC(1, kDebugEngine, "displayIsometricBlock(buf, %d, %d, %d)", var1, var2, var3);
+void LilliputEngine::displayIsometricBlock(byte *buf, int var1, int posX, int posY, int var3) {
+	debugC(1, kDebugEngine, "displayIsometricBlock(buf, %d, %d - %d, %d)", var1, posX, posY, var3);
 
-	byte tmpByte1 = ((7 + (var2 >> 8) - (var2 & 0xFF)) << 4) & 0xFF;
-	byte tmpByte2 = ((4 + (var2 >> 8) + (var2 & 0xFF) - (var3 >> 7)) << 3) & 0xFF;
+	byte tmpByte1 = ((7 + posX - posY) << 4) & 0xFF;
+	byte tmpByte2 = ((4 + posX + posY - (var3 >> 7)) << 3) & 0xFF;
 
 	int index = (tmpByte2 << 8) + tmpByte1;
 	int index2 = var1 << 10;
@@ -763,25 +765,25 @@ void LilliputEngine::prepareGameArea() {
 
 	memcpy(_savedSurfaceGameArea1, _savedSurfaceGameArea2, 176 * 256); // 45056;
 
-	int index1 = (_scriptHandler->_viewportPos.y >> 8) + ((_scriptHandler->_viewportPos.y & 0xFF) << 8) + (_scriptHandler->_viewportPos.x << 2);
+	int index1 = (_scriptHandler->_viewportPos.y * 64 + _scriptHandler->_viewportPos.x) * 4;
+	assert(index1 < 16384);
 	byte *map = &_bufferIsoMap[index1];
 
-	for (int i = 0; i < 8; i++) {
-		for (int j = 0; j < 8; j++) {
-			int tmpVal = (j << 8) + i;
+	for (int posY = 0; posY < 8; posY++) {
+		for (int posX = 0; posX < 8; posX++) {
 			if (map[1] != 0xFF) {
 				int var1 = map[1];
 				if ((_rulesChunk9[var1] & 128) != 0)
 					var1 += _animationTick;
-				displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 1 << 8);
+				displayIsometricBlock(_savedSurfaceGameArea1, var1, posX, posY, 1 << 8);
 			}
-			renderCharacters(map, Common::Point(j, i));
+			renderCharacters(map, Common::Point(posX, posY));
 
 			if (map[2] != 0xFF) {
 				int var1 = map[2];
 				if ((_rulesChunk9[var1] & 128) != 0)
 					var1 += _animationTick;
-				displayIsometricBlock(_savedSurfaceGameArea1, var1, tmpVal, 2 << 8);
+				displayIsometricBlock(_savedSurfaceGameArea1, var1, posX, posY, 2 << 8);
 			}
 			map += 4;
 		}
@@ -894,7 +896,9 @@ void LilliputEngine::paletteFadeIn() {
 int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	debugC(2, kDebugEngineTBC, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);
 
-	byte *isoMap = _bufferIsoMap + (y1 << 8) + (x1 << 2) + 1;
+	int index = (y1 * 64 + x1) * 4;
+	assert(index < 16384);
+	byte *isoMap = &_bufferIsoMap[1];
 
 	int dx = x2 - x1;
 	int dy = y2 - y1;
@@ -1488,7 +1492,9 @@ void LilliputEngine::sub167EF(int index) {
 	}
 
 	// var4h == var4l
-	int mapIndex = (((_array10A11PosY[index] << 8) >> 2) + _array109E9PosX[index]) << 2;
+	int mapIndex = (_array10A11PosY[index] * 64 + _array109E9PosX[index]) * 4;
+	assert(mapIndex < 16384);
+
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
 	if ((tmpVal & 8) != 0)
 		++_array109E9PosX[index];
@@ -1521,6 +1527,7 @@ void LilliputEngine::sub1693A(int index) {
 	int retVal = 0;
 	for (int i = 3; i >= 0; i--) {
 		mapIndexDiff = mapArrayMove[i];
+		assert(mapIndex + mapIndexDiff + 3 < 16384);
 		if (((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & _array16C54[i]) != 0) && ((_bufferIsoMap[mapIndex + 3] & _array16C58[i]) != 0)) {
 			if ((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & 0x80) != 0 && (sub16A76(i, index) != 0)) {
 				_array1692B[i] -= 20;
@@ -1820,13 +1827,12 @@ byte LilliputEngine::sub1675D(int index, Common::Point var1) {
 void LilliputEngine::sub16EBC() {
 	debugC(2, kDebugEngine, "sub16EBC()");
 
-	int index2 = 3;
-
 	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
-		int var2 = (_scriptHandler->_array1614BPosY[index1] << 8) + (_scriptHandler->_array16123PosX[index1] << 2);
-		int var1 = (_bufferIsoMap[index2 + var2] & 0x40);
+		int mapIndex = (_scriptHandler->_array1614BPosY[index1] * 64 + _scriptHandler->_array16123PosX[index1]) * 4;
+		assert(mapIndex < 16384);
+		byte var1 = _bufferIsoMap[mapIndex + 3];
 
-		if (var1 == _array16E94[index1])
+		if ((var1 & 0x40) == _array16E94[index1])
 			continue;
 
 		_array16E94[index1] = var1;
@@ -1935,11 +1941,11 @@ void LilliputEngine::sub131B2(Common::Point pos, bool &forceReturnFl) {
 }
 
 void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {
-	debugC(2, kDebugEngineTBC, "checkInterfaceHotspots()");
+	debugC(2, kDebugEngine, "checkInterfaceHotspots()");
 
 	forceReturnFl = false;
 	for (int index = _interfaceHotspotNumb - 1; index >= 0; index--) {
-		if (sub13240(_mousePos, _interfaceHotspotsX[index], _interfaceHotspotsY[index]) == 0) {
+		if (isMouseOverHotspot(_mousePos, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]))) {
 			sub1305C(index, 1);
 			forceReturnFl = true;
 			return;
@@ -1947,19 +1953,13 @@ void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {
 	}
 }
 
-int LilliputEngine::sub13240(Common::Point mousePos, int var3, int var4) {
-	debugC(2, kDebugEngineTBC, "sub13240(%d, %d, %d, %d)", mousePos.x, mousePos.y, var3, var4);
-
-	if ((mousePos.x < var3) || (mousePos.y < var4))
-		return -1;
-
-	var3 += 16;
-	var4 += 16;
+bool LilliputEngine::isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos) {
+	debugC(2, kDebugEngine, "isMouseOverHotspot(%d - %d, %d - %d)", mousePos.x, mousePos.y, hotspotPos.x, hotspotPos.y);
 
-	if ((mousePos.x > var3) || (mousePos.y > var4))
-		return -1;
+	if ((mousePos.x < hotspotPos.x) || (mousePos.y < hotspotPos.y) || (mousePos.x > hotspotPos.x + 16) || (mousePos.y > hotspotPos.y + 16))
+		return false;
 
-	return 0;
+	return true;
 }
 
 void LilliputEngine::sub1305C(byte index, byte button) {
@@ -2147,8 +2147,8 @@ void LilliputEngine::sub16B8F_moveCharacter(int index, Common::Point pos, int di
 	if ((pos.x < 0) || (pos.x >= 512) || (pos.y < 0) || (pos.y >= 512))
 		return;
 
-	int mapIndex = (_scriptHandler->_array1614BPosY[index] << 6) + _scriptHandler->_array16123PosX[index];
-	mapIndex <<= 2;
+	int mapIndex = (_scriptHandler->_array1614BPosY[index] * 64 + _scriptHandler->_array16123PosX[index]) * 4;
+	assert(mapIndex < 16384);
 
 	if ((_bufferIsoMap[mapIndex + 3] & _array16C58[direction]) == 0)
 		return;
@@ -2398,7 +2398,7 @@ byte *LilliputEngine::loadVGA(Common::String filename, int expectedSize, bool lo
 	return decodeBuffer;
 }
 
-byte *LilliputEngine::loadRaw(Common::String filename) {
+byte *LilliputEngine::loadRaw(Common::String filename, int filesize) {
 	debugC(1, kDebugEngine, "loadRaw(%s)", filename.c_str());
 
 	Common::File f;
@@ -2406,9 +2406,8 @@ byte *LilliputEngine::loadRaw(Common::String filename) {
 	if (!f.open(filename))
 		error("Missing game file %s", filename.c_str());
 
-	int size = f.size();
-	byte *res = (byte *)malloc(sizeof(byte) * size);
-	for (int i = 0; i < size; ++i)
+	byte *res = (byte *)malloc(sizeof(byte) * filesize);
+	for (int i = 0; i < filesize; ++i)
 		res[i] = f.readByte();
 
 	f.close();
@@ -2742,7 +2741,7 @@ Common::Error LilliputEngine::run() {
 	_bufferMen = loadVGA("MEN.VGA", 61440, false);
 	_bufferMen2 = loadVGA("MEN2.VGA", 61440, false);
 	_bufferIsoChars = loadVGA("ISOCHARS.VGA", 4096, false);
-	_bufferIsoMap = loadRaw("ISOMAP.DTA");
+	_bufferIsoMap = loadRaw("ISOMAP.DTA", 16384);
 
 	loadRules();
 	_int8installed = true;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index ea6159c..0f7ae06 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -236,7 +236,7 @@ public:
 	void displaySpeechBubble();
 	void displaySpeech(byte *buf);
 	void initGameAreaDisplay();
-	void displayIsometricBlock(byte *buf, int var1, int var2, int var3);
+	void displayIsometricBlock(byte *buf, int var1, int posX, int posY, int var3);
 	void displayGameArea();
 	void prepareGameArea();
 	void displayRefreshScreen();
@@ -290,7 +290,7 @@ public:
 	void sub130EE();
 	void sub1305C(byte index, byte var2);
 	void checkInterfaceHotspots(bool &forceReturnFl);
-	int sub13240(Common::Point mousePos, int var3, int var4);
+	bool isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos);
 	void sub131B2(Common::Point pos, bool &forceReturnFl);
 	void sub131FC(Common::Point pos);
 	void sub1546F(Common::Point displayPos);
@@ -316,7 +316,7 @@ public:
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, int fileSize, bool loadPal);
-	byte *loadRaw(Common::String filename);
+	byte *loadRaw(Common::String filename, int filesize);
 	void loadRules();
 
 	void displayVGAFile(Common::String fileName);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 68352ed..1eda423 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2777,11 +2777,13 @@ void LilliputScript::OC_setInterfaceHotspot() {
 	debugC(1, kDebugScript, "OC_setInterfaceHotspot()");
 
 	int16 index = _currScript->readSint16LE();
-	uint16 curWord = _currScript->readUint16LE();
-
 	assert((index >= 0) && (index < 20));
+
+	uint16 curWord = _currScript->readUint16LE();
 	_interfaceHotspotStatus[index] = (curWord & 0xFF);
 	_array122FD[index] = (curWord >> 8);
+	if (_array122FD[index] != 0)
+		warning("debug - OC_setInterfaceHotspot - _array122FD[index] = %d", _array122FD[index]);
 
 	_vm->displayInterfaceHotspots();
 }


Commit: 3103cf448a586045469e328a11e680d2cb3ace48
    https://github.com/scummvm/scummvm/commit/3103cf448a586045469e328a11e680d2cb3ace48
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a bug in sub171AF

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 68a4e32..ee37f02 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -343,7 +343,7 @@ void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point
 	int index1 = index * 16 * 16;
 	byte *newBuf = &buf[index1];
 
-	int index2 = pos.x + (pos.y * 320);
+	int vgaIndex = pos.x + (pos.y * 320);
 
 	for (int i = 0; i < 16; i++) {
 		// clip on y
@@ -351,10 +351,10 @@ void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point
 			for (int j = 0; j < 16; j++) {
 				// clip on x
 				if ((newBuf[j] != 0) && (pos.x + j < 320))
-					((byte *)_mainSurface->getPixels())[index2 + j] = newBuf[j];
+					((byte *)_mainSurface->getPixels())[vgaIndex + j] = newBuf[j];
 			}
 		}
-		index2 += 320;
+		vgaIndex += 320;
 		newBuf += 16;
 	}
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 1eda423..ecdf1ac 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -64,7 +64,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array128EF[i] = 15;
 		_array10AB1[i] = 0;
 		_array12811[i] = 16;
-		_array12839[i] = 0xFF;
+		_array12839[i] = -1;
 		_array16123PosX[i] = 0;
 		_array1614BPosY[i] = 0;
 		_array122C1[i] = 0;
@@ -1066,7 +1066,7 @@ void LilliputScript::sub16C86(int index, byte *buf) {
 	}
 }
 
-void LilliputScript::sub16C5C(int index, byte var3) {
+void LilliputScript::sub16C5C(int index, int8 var3) {
 	debugC(1, kDebugScript, "sub16C5C(%d, %d)", index, var3);
 
 	assert(index < 40);
@@ -1744,9 +1744,9 @@ byte LilliputScript::OC_compWord10804() {
 }
 
 byte LilliputScript::OC_sub17766() {
-	debugC(1, kDebugScriptTBC, "OC_sub17766()");
+	debugC(1, kDebugScript, "OC_sub17766()");
 
-	byte var1 = (_currScript->readUint16LE() & 0xFF);
+	int8 var1 = (_currScript->readUint16LE() & 0xFF);
 	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] != 16))
 		return 1;
 
@@ -1756,7 +1756,7 @@ byte LilliputScript::OC_sub17766() {
 byte LilliputScript::OC_sub17782() {
 	debugC(1, kDebugScript, "OC_sub17782()");
 
-	byte var1 = (_currScript->readUint16LE() & 0xFF);
+	int8 var1 = (_currScript->readUint16LE() & 0xFF);
 	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] == 16))
 		return 1;
 
@@ -2394,14 +2394,14 @@ void LilliputScript::OC_resetByte16F04() {
 void LilliputScript::OC_sub17AE1() {
 	debugC(1, kDebugScript, "OC_sub17AE1()");
 
-	byte var3 = (_currScript->readUint16LE() & 0xFF);
+	int8 var3 = (_currScript->readUint16LE() & 0xFF);
 	sub16C5C(_vm->_currentScriptCharacter, var3);
 }
 
 void LilliputScript::OC_sub17AEE() {
 	debugC(1, kDebugScript, "OC_sub17AEE()");
 
-	byte var3 = (_currScript->readUint16LE() & 0xFF);
+	int8 var3 = (_currScript->readUint16LE() & 0xFF);
 	sub16C5C(_vm->_currentScriptCharacter + 1, var3);
 }
 
@@ -2460,7 +2460,7 @@ void LilliputScript::OC_setCurrentCharacter() {
 }
 
 void LilliputScript::sub171AF(int16 var1, int16 var2, int16 var4) {
-	debugC(2, kDebugScriptTBC, "sub171AF()");
+	debugC(2, kDebugScript, "sub171AF()");
 
 	int index = 0;
 	for (int i = 0; i < 10; i++) {
@@ -2468,6 +2468,7 @@ void LilliputScript::sub171AF(int16 var1, int16 var2, int16 var4) {
 			_vm->_array12861[index + 1] = var1;
 			_vm->_array12861[index + 2] = var2;
 			_vm->_array12861[index + 0] = _vm->_word1289D + var4;
+			return;
 		}
 		index += 3;
 	}
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index d858fe5..1196035 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -80,7 +80,7 @@ public:
 
 	Common::Point _array12311[640];
 	byte _array128EF[40];
-	byte _array12839[40];
+	int8 _array12839[40];
 	Common::Point _array1813BPos[32];
 
 	LilliputScript(LilliputEngine *vm);
@@ -120,7 +120,7 @@ private:
 	void enableCharacterScript(byte index, byte var1, byte *curBufPtr);
 	void sub17B6C(int var1);
 	void sub16C86(int index, byte *buf);
-	void sub16C5C(int index, byte var3);
+	void sub16C5C(int index, int8 var3);
 	void checkSpeechAllowed(bool &forceReturnFl);
 	void decodePackedText(char *buf);
 	void startSpeech(int var);


Commit: e1c783d6a2f8abb35659f40c080c42ef4a0beaa3
    https://github.com/scummvm/scummvm/commit/e1c783d6a2f8abb35659f40c080c42ef4a0beaa3
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming, fix a bug in intro

Changed paths:
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 0f7ae06..28f5a4b 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -104,7 +104,7 @@ public:
 	byte _animationTick;
 	Common::Point _nextDisplayCharacterPos;
 	byte _sound_byte16F06;
-	byte _byte16F09;
+	byte _lastKeyPressed;
 	byte _keyboard_nextIndex;
 	byte _keyboard_oldIndex;
 	byte _byte12A05;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index ecdf1ac..7cdefdd 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -91,7 +91,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_comparePos();
 		break;
 	case 0x2:
-		return OC_sub1740A();
+		return OC_checkIsoMap3();
 		break;
 	case 0x3:
 		return OC_compareCharacterVariable();
@@ -226,7 +226,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub179C2();
 		break;
 	case 0x2F:
-		return OC_sub179E5();
+		return OC_checkKeyPressed();
 		break;
 	case 0x30:
 		return OC_sub17A07();
@@ -382,7 +382,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17F4F();
 		break;
 	case 0x2E:
-		OC_sub17F68();
+		OC_scrollAwayFromCharacter();
 		break;
 	case 0x2F:
 		OC_skipNextVal();
@@ -558,7 +558,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 static const OpCode opCodes1[] = {
 	{ "OC_checkCharacterGoalPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_comparePos", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
-	{ "OC_sub1740A", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_checkIsoMap3", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_compareCharacterVariable", 4, kGetValue1, kImmediateValue, kCompareOperation, kImmediateValue, kNone },
 	{ "OC_CompareLastRandomValue", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_getRandom", 1, kImmediateValue, kNone, kNone, kNone, kNone },
@@ -603,7 +603,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_checkSavedMousePos", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179AE", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
-	{ "OC_sub179E5", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_checkKeyPressed", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17A07", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
 	{ "OC_checkViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
 };
@@ -656,7 +656,7 @@ static const OpCode opCodes2[] = {
 /* 0x2b */	{ "OC_setCharacterDirectionTowardsPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x2c */	{ "OC_sub17F08", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x2e */	{ "OC_sub17F68", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x2e */	{ "OC_scrollAwayFromCharacter", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x2f */	{ "OC_skipNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x30 */	{ "OC_sub17FD2", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -1389,8 +1389,8 @@ byte LilliputScript::OC_comparePos() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub1740A() {
-	debugC(1, kDebugScriptTBC, "OC_sub1740A()");
+byte LilliputScript::OC_checkIsoMap3() {
+	debugC(1, kDebugScript, "OC_checkIsoMap3()");
 
 	Common::Point var = _vm->_currentScriptCharacterPos;
 	if (var == Common::Point(-1, -1)) {
@@ -1399,16 +1399,16 @@ byte LilliputScript::OC_sub1740A() {
 	}
 
 	byte *isoMapBuf = getMapPtr(var);
-	uint16 var2 = isoMapBuf[3];
+	byte var2 = isoMapBuf[3];
 
 	int16 var3 = _currScript->readUint16LE();
-	uint16 var4 = 8 >> var3;
+	byte var4 = 8 >> var3;
 
-	if (var2 & var4) {
+	if ((var2 & var4) != 0) {
 		return 1;
-	} else { 
-		return 0;
 	}
+
+	return 0;
 }
 
 byte LilliputScript::OC_compareCharacterVariable() {
@@ -2053,14 +2053,14 @@ byte LilliputScript::OC_sub179C2() {
 
 	return 0;
 }
-byte LilliputScript::OC_sub179E5() {
-	debugC(1, kDebugScriptTBC, "OC_sub17A07()");
+byte LilliputScript::OC_checkKeyPressed() {
+	debugC(1, kDebugScript, "OC_checkKeyPressed()");
 
-	static const byte _byte179DB[10] = {0x44, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43};
+	static const byte specialKeys[10] = {0x44, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43};
 
-	int var1 = (_currScript->readUint16LE() & 0xFF) - 0x30;
+	int8 index = (_currScript->readUint16LE() & 0xFF) - 0x30;
 	
-	if (_byte179DB[var1] == _vm->_byte16F09)
+	if (specialKeys[index] == _vm->_lastKeyPressed)
 		return 1;
 
 	return 0;
@@ -2508,7 +2508,7 @@ void LilliputScript::OC_sub17CB9() {
 }
 
 void LilliputScript::OC_sub17CD1() {
-	debugC(1, kDebugScriptTBC, "OC_sub17CD1()");
+	debugC(1, kDebugScript, "OC_sub17CD1()");
 
 	int16 type = 3 << 8;
 	int16 var4 = _currScript->readSint16LE();
@@ -2604,9 +2604,9 @@ void LilliputScript::OC_sub17EC5() {
 }
 
 Common::Point LilliputScript::getCharacterTilePos(int index) {
-	debugC(2, kDebugScriptTBC, "getCharacterTilePos(%d)", index);
+	debugC(2, kDebugScript, "getCharacterTilePos(%d)", index);
 
-	return Common::Point(_vm->_characterPositionX[index] >> 3, _vm->_characterPositionY[index] >> 3);
+	return Common::Point(_vm->_characterPositionX[index] / 8, _vm->_characterPositionY[index] / 8);
 }
 
 void LilliputScript::OC_setCharacterDirectionTowardsPos() {
@@ -2652,17 +2652,17 @@ void LilliputScript::OC_sub17F4F() {
 	_vm->_array109E9PosX[_vm->_currentScriptCharacter] = -1;
 }
 
-void LilliputScript::OC_sub17F68() {
-	debugC(1, kDebugScriptTBC, "OC_sub17F68()");
+void LilliputScript::OC_scrollAwayFromCharacter() {
+	debugC(1, kDebugScript, "OC_scrollAwayFromCharacter()");
 
 	if (_vm->_currentScriptCharacter != _viewportCharacterTarget)
 		return;
 
-	static const char _byte17F60[] = {-1, -3, -3, -6};
-	static const char _byte17F64[] = {-3, -6, -1, -3};
+	static const char speedX[] = {-1, -3, -3, -6};
+	static const char speedY[] = {-3, -6, -1, -3};
 	
-	int cx = _byte17F60[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
-	int cy = _byte17F64[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
+	int cx = speedX[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
+	int cy = speedY[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
 
 	Common::Point pos = getCharacterTilePos(_vm->_currentScriptCharacter);
 
@@ -3141,13 +3141,13 @@ void LilliputScript::OC_displayTitleScreen() {
 	_vm->_keyboard_oldIndex = 0;
 	//
 	_vm->_mouseButton = 0;
-	_vm->_byte16F09 = 0;
+	_vm->_lastKeyPressed = 0;
 
 	while (!_vm->_shouldQuit) {
 		_vm->displaySmallAnims();
 		_vm->update();
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
-			_vm->_byte16F09 = _vm->_keyboard_getch();
+			_vm->_lastKeyPressed = _vm->_keyboard_getch();
 			_vm->_keyboard_getch();
 			break;
 		}
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 1196035..39f8364 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -144,7 +144,7 @@ private:
 	//Opcodes Type 1
 	byte OC_checkCharacterGoalPos();
 	byte OC_comparePos();
-	byte OC_sub1740A();
+	byte OC_checkIsoMap3();
 	byte OC_compareCharacterVariable();
 	byte OC_CompareLastRandomValue();
 	byte OC_getRandom();
@@ -189,7 +189,7 @@ private:
 	byte OC_checkSavedMousePos();
 	byte OC_sub179AE();
 	byte OC_sub179C2();
-	byte OC_sub179E5();
+	byte OC_checkKeyPressed();
 	byte OC_sub17A07();
 	byte OC_checkViewPortCharacterTarget();
 
@@ -240,7 +240,7 @@ private:
 	void OC_setCharacterDirectionTowardsPos();
 	void OC_sub17F08();
 	void OC_sub17F4F();
-	void OC_sub17F68();
+	void OC_scrollAwayFromCharacter();
 	void OC_skipNextVal();
 	void OC_sub17FD2();
 	void OC_sub17FDD();


Commit: 850017581154a9ce691f9583ed1a51d1b2feffd0
    https://github.com/scummvm/scummvm/commit/850017581154a9ce691f9583ed1a51d1b2feffd0
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ee37f02..a97f77c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -217,7 +217,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_displayStringBuf[i] = 0;
 
 	for (int i = 0; i < 1400 + 3120; i++) {
-		_characterVariables_[i] = 0;
+		_characterVariables[i] = 0;
 	}
 
 	_currentCharacterVariables = NULL;
@@ -2461,7 +2461,7 @@ void LilliputEngine::loadRules() {
 		_rulesBuffer2_14_posY[j] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
-			_characterVariables_[(j * 32) + k] = f.readByte();
+			_characterVariables[(j * 32) + k] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
 			_rulesBuffer2_16[(j * 32) + k] = f.readByte();
@@ -2780,9 +2780,9 @@ byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
 
 	assert((index > -3120) && (index < 1400));
 	if (index >= 0)
-		return &_characterVariables_[index];
+		return &_characterVariables[index];
 	else
-		return &_characterVariables_[1400 - index];
+		return &_characterVariables[1400 - index];
 }
 
 void LilliputEngine::syncSoundSettings() {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 28f5a4b..8ae4691 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -140,7 +140,7 @@ public:
 	Common::Point _currentScriptCharacterPos;
 	int _nextCharacterIndex;
 	int _word16EFE;
-	int _word1817B;
+	uint16 _word1817B;
 	Common::Point _savedSurfaceUnderMousePos;
 	int _word15AC2;
 	int _currentDisplayCharacter;
@@ -158,7 +158,7 @@ public:
 	int16 _currentScriptCharacter;
 	int16 _characterPositionX[40];
 	int16 _characterPositionY[40];
-	char _characterPositionAltitude[40];
+	int8 _characterPositionAltitude[40];
 	int16 _characterFrameArray[40];
 	byte _rulesBuffer2_5[40];
 	byte _rulesBuffer2_6[40];
@@ -170,7 +170,7 @@ public:
 	byte _rulesBuffer2_12[40];
 	byte _rulesBuffer2_13_posX[40];
 	byte _rulesBuffer2_14_posY[40];
-	byte _characterVariables_[1400 + 3120];
+	byte _characterVariables[1400 + 3120];
 	byte *_currentCharacterVariables;
 	byte _rulesBuffer2_16[40 * 32];
 	int *_packedStringIndex;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7cdefdd..f223a0c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -403,7 +403,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_SetCurrentCharacterVar2ToZero();
 		break;
 	case 0x35:
-		OC_sub1801D();
+		OC_setCharacterProperties();
 		break;
 	case 0x36:
 		OC_sub1805D();
@@ -663,7 +663,7 @@ static const OpCode opCodes2[] = {
 /* 0x32 */	{ "OC_setByte10B29", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x34 */	{ "OC_SetCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x35 */	{ "OC_sub1801D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
+/* 0x35 */	{ "OC_setCharacterProperties", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x36 */	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -1877,12 +1877,12 @@ byte LilliputScript::OC_CompareNumberOfCharacterWithVar0Equals() {
 }
 
 byte LilliputScript::OC_IsPositionInViewport() {
-	debugC(1, kDebugScriptTBC, "OC_IsPositionInViewport()");
+	debugC(1, kDebugScript, "OC_IsPositionInViewport()");
 
 	Common::Point var1 = getPosFromScript();
 
-	int dx = var1.x - _viewportPos.x;
-	int dy = var1.y - _viewportPos.y;
+	int16 dx = var1.x - _viewportPos.x;
+	int16 dy = var1.y - _viewportPos.y;
 
 	if ((dx >= 0) && (dx < 8) && (dy >= 0) && (dy < 8))
 		return 1;
@@ -2525,9 +2525,9 @@ void LilliputScript::OC_resetWord16EFE() {
 }
 
 void LilliputScript::OC_enableCurrentCharacterScript() {
-	debugC(1, kDebugScriptTBC, "OC_enableCurrentCharacterScript()");
+	debugC(1, kDebugScript, "OC_enableCurrentCharacterScript()");
 
-	int var1 = _currScript->readUint16LE();
+	uint8 var1 = (_currScript->readUint16LE() & 0xFF);
 	enableCharacterScript(_vm->_currentScriptCharacter , var1, _vm->_currentCharacterVariables);
 	sub17B6C(0);
 }
@@ -2610,12 +2610,12 @@ Common::Point LilliputScript::getCharacterTilePos(int index) {
 }
 
 void LilliputScript::OC_setCharacterDirectionTowardsPos() {
-	debugC(1, kDebugScriptTBC, "OC_setCharacterDirectionTowardsPos()");
+	debugC(1, kDebugScript, "OC_setCharacterDirectionTowardsPos()");
 
 	Common::Point pos1 = getPosFromScript();
 	Common::Point tilePos = getCharacterTilePos(_vm->_currentScriptCharacter);
-	int dir = _vm->getDirection(tilePos, pos1);
-	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = dir;
+
+	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = _vm->getDirection(tilePos, pos1);
 }
 
 void LilliputScript::OC_sub17F08() {
@@ -2733,22 +2733,21 @@ void LilliputScript::OC_SetCurrentCharacterVar2ToZero() {
 	_vm->_currentCharacterVariables[2] = 0;
 }
 
-void LilliputScript::OC_sub1801D() {
-	debugC(1, kDebugScriptTBC, "OC_SetCurrentCharacterVar2ToZero()");
-
-	int var1 = getValue1();
+void LilliputScript::OC_setCharacterProperties() {
+	debugC(1, kDebugScript, "OC_setCharacterProperties()");
 
-	int x = _vm->_characterPositionX[var1] & 0xFFF8;
-	x += _currScript->readUint16LE();
-	_vm->_characterPositionX[var1] = x;
+	int16 index = getValue1();
 
-	int y = _vm->_characterPositionY[var1] & 0xFFF8;
-	y += _currScript->readUint16LE();
-	_vm->_characterPositionY[var1] = y;
+	int16 x = _vm->_characterPositionX[index] & 0xFFF8;
+	x += _currScript->readSint16LE();
+	_vm->_characterPositionX[index] = x;
 
-	_vm->_characterPositionAltitude[var1]  = _currScript->readUint16LE();
-	_vm->_characterDirectionArray[var1] = _currScript->readUint16LE();
+	int16 y = _vm->_characterPositionY[index] & 0xFFF8;
+	y += _currScript->readSint16LE();
+	_vm->_characterPositionY[index] = y;
 
+	_vm->_characterPositionAltitude[index]  = (int8)(_currScript->readUint16LE() & 0xFF);
+	_vm->_characterDirectionArray[index] = _currScript->readUint16LE() & 0xFF;
 }
 
 void LilliputScript::OC_sub1805D() {
@@ -2838,16 +2837,14 @@ void LilliputScript::OC_setCurrentCharacterAltitude() {
 void LilliputScript::OC_sub1817F() {
 	debugC(1, kDebugScript, "OC_sub1817F()");
 
-	int16 var1 = _currScript->readUint16LE();
-	int16 var2 = _currScript->readUint16LE();
-	
-	int16 x = var1 & 0xFF;
-	int16 y = var2 & 0xFF;
+	int8 x = (int8)(_currScript->readUint16LE() & 0xFF);
+	int8 y = (int8)(_currScript->readUint16LE() & 0xFF);
+
 	sub1818B(Common::Point(x, y));
 }
 
 void LilliputScript::sub1818B(Common::Point point) {
-	debugC(2, kDebugScriptTBC, "sub1818B(%d - %d)", point.x, point.y);
+	debugC(2, kDebugScript, "sub1818B(%d - %d)", point.x, point.y);
 
 	Common::Point pos = point;
 	for (int i = 0; i <  _vm->_word1817B; i++) {
@@ -2866,11 +2863,11 @@ void LilliputScript::sub1818B(Common::Point point) {
 }
 
 void LilliputScript::OC_sub181BB() {
-	debugC(1, kDebugScriptTBC, "OC_sub181BB()");
+	debugC(1, kDebugScript, "OC_sub181BB()");
 	
-	int16 x = _currScript->readUint16LE() & 0xFF;
-	int8 oper = _currScript->readUint16LE() & 0xFF;
-	int16 index = _currScript->readSint16LE();
+	int8 x = (int8)(_currScript->readUint16LE() & 0xFF);
+	byte oper = _currScript->readUint16LE() & 0xFF;
+	uint16 index = _currScript->readUint16LE();
 	int16 c = _vm->_currentCharacterVariables[index];
 
 	switch (oper) {
@@ -2889,11 +2886,15 @@ void LilliputScript::OC_sub181BB() {
 			c = 0;
 		c *= 2;
 		break;
+	case '+':
+		break;
 	default:
-		warning("OC_sub181BB: skipped oper 0x%x", oper);
+		warning("OC_sub181BB: skipped oper %c", oper);
 		break;
 	}
-	c &= 0xFF;
+	if (c > 0xFF)
+		warning("OC_sub181BB- Abnormal value c = %d, should put back c &= 0xFF;", c);
+
 	int y = (_currScript->readSint16LE() * c) + c;
 	y >>= 8;
 	sub1818B(Common::Point(x, y));
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 39f8364..fa575cf 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -247,7 +247,7 @@ private:
 	void OC_setByte10B29();
 	void OC_setCurrentCharacterVar2();
 	void OC_SetCurrentCharacterVar2ToZero();
-	void OC_sub1801D();
+	void OC_setCharacterProperties();
 	void OC_sub1805D();
 	void OC_sub18074();
 	void OC_setCurrentCharacterDirection();


Commit: 5498523326c804ac042e3daa4a91c74aaee56e45
    https://github.com/scummvm/scummvm/commit/5498523326c804ac042e3daa4a91c74aaee56e45
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in OC_turnCharacterTowardsAnother()

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f223a0c..a7c0740 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -376,7 +376,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setCharacterDirectionTowardsPos();
 		break;
 	case 0x2C:
-		OC_sub17F08();
+		OC_turnCharacterTowardsAnother();
 		break;
 	case 0x2D:
 		OC_sub17F4F();
@@ -654,7 +654,7 @@ static const OpCode opCodes2[] = {
 /* 0x29 */	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x2b */	{ "OC_setCharacterDirectionTowardsPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
-/* 0x2c */	{ "OC_sub17F08", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x2c */	{ "OC_turnCharacterTowardsAnother", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x2e */	{ "OC_scrollAwayFromCharacter", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x2f */	{ "OC_skipNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
@@ -2618,15 +2618,15 @@ void LilliputScript::OC_setCharacterDirectionTowardsPos() {
 	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = _vm->getDirection(tilePos, pos1);
 }
 
-void LilliputScript::OC_sub17F08() {
-	debugC(1, kDebugScriptTBC, "OC_sub17F08()");
+void LilliputScript::OC_turnCharacterTowardsAnother() {
+	debugC(1, kDebugScript, "OC_turnCharacterTowardsAnother()");
 	
 	int index = getValue1();
 
 	static const byte _directionsArray[] = { 0, 2, 0, 1, 3, 2, 3, 1 };
 
-	int dx = _vm->_characterPositionX[index] - _vm->_characterDisplayX[_vm->_currentScriptCharacter];
-	int dy = _vm->_characterPositionY[index] - _vm->_characterDisplayY[_vm->_currentScriptCharacter];
+	int dx = _vm->_characterPositionX[index] - _vm->_characterPositionX[_vm->_currentScriptCharacter];
+	int dy = _vm->_characterPositionY[index] - _vm->_characterPositionY[_vm->_currentScriptCharacter];
 
 	int flag = 0;
 	if (dx < 0) {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index fa575cf..68a4948 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -238,7 +238,7 @@ private:
 	void OC_sub17E99();
 	void OC_sub17EC5();
 	void OC_setCharacterDirectionTowardsPos();
-	void OC_sub17F08();
+	void OC_turnCharacterTowardsAnother();
 	void OC_sub17F4F();
 	void OC_scrollAwayFromCharacter();
 	void OC_skipNextVal();


Commit: 4d36343b0c9cc5f0789507f732a66e1742acfb4f
    https://github.com/scummvm/scummvm/commit/4d36343b0c9cc5f0789507f732a66e1742acfb4f
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in viewportScrollTo(), some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index a97f77c..fb05e1c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1246,12 +1246,12 @@ void LilliputEngine::scrollToViewportCharacterTarget() {
 }
 
 void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
-	debugC(2, kDebugEngineTBC, "viewportScrollTo(%d, %d)", goalPos.x, goalPos.y);
+	debugC(2, kDebugEngine, "viewportScrollTo(%d, %d)", goalPos.x, goalPos.y);
 
 	if (goalPos == _scriptHandler->_viewportPos)
 		return;
 
-	int dx = 0;
+	int16 dx = 0;
 	if (goalPos.x != _scriptHandler->_viewportPos.x) {
 		if (goalPos.x < _scriptHandler->_viewportPos.x)
 			--dx;
@@ -1259,7 +1259,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 			++dx;
 	}
 
-	int dy = 0;
+	int16 dy = 0;
 	if (goalPos.y != _scriptHandler->_viewportPos.y) {
 		if (goalPos.y < _scriptHandler->_viewportPos.y)
 			--dy;
@@ -1280,7 +1280,7 @@ void LilliputEngine::viewportScrollTo(Common::Point goalPos) {
 
 		if (goalPos.y == _scriptHandler->_viewportPos.y)
 			dy = 0;
-	} while ((dx != 0) && (dy != 0));
+	} while ((dx != 0) || (dy != 0));
 
 	_soundHandler->contentFct5();
 }
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a7c0740..0b73033 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1376,16 +1376,17 @@ byte LilliputScript::OC_checkCharacterGoalPos() {
 }
 
 byte LilliputScript::OC_comparePos() {
-	debugC(2, kDebugScriptTBC, "OC_comparePos()");
+	debugC(2, kDebugScript, "OC_comparePos()");
 
 	int index = getValue1();
-	byte d1 = _array16123PosX[index];
-	byte d2 = _array1614BPosY[index];
+	int8 d1 = _array16123PosX[index];
+	int8 d2 = _array1614BPosY[index];
 	Common::Point var1 = getPosFromScript();
 
 	if (var1 == Common::Point(d1, d2))
 		return 1;
 
+	warning("OC_comparePos - debug: %d-%d %d-%d", var1.x, var1.y, d1, d2);
 	return 0;
 }
 
@@ -2459,7 +2460,7 @@ void LilliputScript::OC_setCurrentCharacter() {
 	_vm->setCurrentCharacter(var1);
 }
 
-void LilliputScript::sub171AF(int16 var1, int16 var2, int16 var4) {
+void LilliputScript::sub171AF(int16 var1, uint16 var2, int16 var4) {
 	debugC(2, kDebugScript, "sub171AF()");
 
 	int index = 0;
@@ -2475,7 +2476,7 @@ void LilliputScript::sub171AF(int16 var1, int16 var2, int16 var4) {
 }
 
 void LilliputScript::OC_sub17C8B() {
-	debugC(1, kDebugScriptTBC, "OC_sub17C8B()");
+	debugC(1, kDebugScript, "OC_sub17C8B()");
 
 	int16 type = 2 << 8;
 	int16 var4 = _currScript->readSint16LE();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 68a4948..722ae60 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -61,14 +61,14 @@ public:
 
 	byte _characterScriptEnabled[40];
 	int8 _interfaceHotspotStatus[20];
-	char _array16123PosX[40];
-	char _array1614BPosY[40];
-	char _array12811[40];
-	char _array10AB1[40];
+	int8 _array16123PosX[40];
+	int8 _array1614BPosY[40];
+	int8 _array12811[40];
+	int8 _array10AB1[40];
 	byte _array122FD[20];
 	byte _array122C1[40];
 	byte _array10A39[40];
-	short _array10B51[40 * 40];
+	int16 _array10B51[40 * 40];
 
 	byte *_savedBuffer215Ptr;
 
@@ -127,7 +127,7 @@ private:
 	void displayNumber(byte var1, Common::Point pos);
 	byte *getMapPtr(Common::Point val);
 	byte *getCurrentCharacterVarFromScript();
-	void sub171AF(int16 var1, int16 var2, int16 var4);
+	void sub171AF(int16 var1, uint16 var2, int16 var4);
 	void sub18B7C(int var1, int var3);
 	void sub189B8();
 	void formatSpeechString();


Commit: e8525da958f924d49850ce96cd412d11ff99b22a
    https://github.com/scummvm/scummvm/commit/e8525da958f924d49850ce96cd412d11ff99b22a
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a bug in sub16626. The people are now dancing in the intro

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index fb05e1c..a59e800 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -657,7 +657,7 @@ void LilliputEngine::restoreMapPoints() {
 	restoreSurfaceUnderMousePointer();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
-	for (int index = 0; index < _numCharacters; index++) {
+	for (byte index = 0; index < _numCharacters; index++) {
 		buf[_word15E5D[index]] = _byte15E35[index];
 	}
 
@@ -688,7 +688,7 @@ void LilliputEngine::moveCharacters() {
 	debugC(2, kDebugEngine, "moveCharacters()");
 
 	_numCharactersToDisplay = 0;
-	int index = _numCharacters - 1;
+	byte index = _numCharacters - 1;
 	Common::Point _pos16213 = Common::Point(_scriptHandler->_viewportPos.x << 3, _scriptHandler->_viewportPos.y << 3);
 
 	for (int i = index; i >= 0; i--) {
@@ -1683,19 +1683,12 @@ void LilliputEngine::sub16626() {
 	while (index >= 0) {
 		result = 2;
 		while (result & 2) {
-			int var2 = _scriptHandler->_array12811[index];
-			if (var2 == 16)
+			if (_scriptHandler->_array12811[index] == 16)
 				break;
 
-			/*if (index == 3)
-				debugC(1,"");
-			else
-				break;*/
-
-			var2 = (2 * (var2 & 0xFF)) + (index << 5);
-			Common::Point var1 = _scriptHandler->_array12311[var2 / 2];
-			int tmpVal = var2;
-			var2 = (var1.x >> 3);
+			uint16 index2 = _scriptHandler->_array12811[index] + (index * 16);
+			Common::Point var1 = _scriptHandler->_array12311[index2];
+			int16 var2 = (var1.x >> 3);
 			var2 &= 0xFE;
 
 			//warning(" step %d : var1 x:%d y:%d  var:%d", _scriptHandler->_array12811[index], var1.x, var1.y, var2 / 2);
@@ -1730,7 +1723,7 @@ void LilliputEngine::sub16626() {
 				result = sub16722(index, var1);
 				break;
 			case 14:
-				result = sub166F7(index, var1, tmpVal);
+				result = sub166F7(index, var1, index2);
 				break;
 			case 15:
 				result = sub166EA(index);
@@ -1847,7 +1840,7 @@ void LilliputEngine::sub12F37() {
 	int index1 = _animationTick + 2;
 	int index2 = 0;
 
-	for (int i = 0; i < _numCharacters; i++) {
+	for (byte i = 0; i < _numCharacters; i++) {
 		byte *varPtr = getCharacterVariablesPtr(index1);
 		if (varPtr[0] != 0) {
 			if (varPtr[0] == 1) {
@@ -1926,7 +1919,7 @@ void LilliputEngine::sub131B2(Common::Point pos, bool &forceReturnFl) {
 
 	forceReturnFl = false;
 
-	for (int i = 0; i < _numCharacters; i++) {
+	for (byte i = 0; i < _numCharacters; i++) {
 		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_byte129A0 = i;
 			_byte16F07_menuId = 4;
@@ -2185,7 +2178,7 @@ void LilliputEngine::sub17224(byte type, byte index, int var4) {
 	}
 
 	int index2 = var4 & 0xFF;
-	for (int i = 0; i < _numCharacters; i++) {
+	for (byte i = 0; i < _numCharacters; i++) {
 		if ((_scriptHandler->_array10B51[index2] & 0xFF) >= type)
 			sub17264(i, var4);
 		index2 += 40;
@@ -2206,7 +2199,7 @@ void LilliputEngine::sub17264(byte index, int var4) {
 void LilliputEngine::sub171CF() {
 	debugC(2, kDebugEngine, "sub171CF()");
 
-	for (int i = 0; i < _numCharacters; i++) {
+	for (byte i = 0; i < _numCharacters; i++) {
 		if (_array1289F[i] != -1) {
 			_array11D49[i] = _array1289F[i];
 			_array1289F[i] = -1;
@@ -2433,8 +2426,8 @@ void LilliputEngine::loadRules() {
 		_rulesChunk1[i] = f.readByte();
 
 	// Chunk 2
-	_numCharacters = f.readSint16LE();
-	assert(_numCharacters <= 40);
+	_numCharacters = (f.readUint16LE() & 0xFF);
+	assert((_numCharacters > 0) && (_numCharacters <= 40));
 
 	for (int i = _numCharacters, j = 0; i != 0; i--, j++) {
 		curWord = f.readUint16LE();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8ae4691..94b541b 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -136,7 +136,7 @@ public:
 	byte _displayMap;
 
 	int _word10800_ERULES;
-	int _numCharacters;
+	byte _numCharacters;
 	Common::Point _currentScriptCharacterPos;
 	int _nextCharacterIndex;
 	int _word16EFE;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 0b73033..b931b87 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2646,10 +2646,11 @@ void LilliputScript::OC_turnCharacterTowardsAnother() {
 }
 
 void LilliputScript::OC_sub17F4F() {
-	debugC(1, kDebugScriptTBC, "OC_sub17F4F()");
+	debugC(1, kDebugScript, "OC_sub17F4F()");
 
-	int var = getValue1();
-	_array10A39[_vm->_currentScriptCharacter] = var & 0xFF;
+	int16 var = getValue1();
+	_array10A39[_vm->_currentScriptCharacter] = (byte)(var & 0xFF);
+	warning("debug - OC_sub17F4F: _array10A39[%d] = %d", _vm->_currentScriptCharacter, var);
 	_vm->_array109E9PosX[_vm->_currentScriptCharacter] = -1;
 }
 


Commit: a468ebc32e57516f8a8e69c7017d1801b644f3f1
    https://github.com/scummvm/scummvm/commit/a468ebc32e57516f8a8e69c7017d1801b644f3f1
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Change type of _rulesBuffer2_5 and _rulesBuffer2_6

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index a59e800..350490c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -194,7 +194,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_characterPositionY[i] = -1;
 		_characterPositionAltitude[i] = 0;
 		_characterFrameArray[i] = 0;
-		_rulesBuffer2_5[i] = 0xFF;
+		_rulesBuffer2_5[i] = -1;
 		_rulesBuffer2_6[i] = 4;
 		_rulesBuffer2_7[i] = 0;
 		_spriteSizeArray[i] = 20;
@@ -692,10 +692,10 @@ void LilliputEngine::moveCharacters() {
 	Common::Point _pos16213 = Common::Point(_scriptHandler->_viewportPos.x << 3, _scriptHandler->_viewportPos.y << 3);
 
 	for (int i = index; i >= 0; i--) {
-		if (_rulesBuffer2_5[i] != 0xFF) {
+		if (_rulesBuffer2_5[i] != -1) {
 			int index2 = _rulesBuffer2_5[i];
 			_characterPositionAltitude[i] = _characterPositionAltitude[index2] + _rulesBuffer2_7[i];
-			int tmpVal = _rulesBuffer2_6[i];
+			int8 tmpVal = _rulesBuffer2_6[i];
 			_characterDirectionArray[i] = _characterDirectionArray[index2];
 			int var3 = _characterPositionX[index2];
 			int var4 = _characterPositionY[index2];
@@ -1688,12 +1688,11 @@ void LilliputEngine::sub16626() {
 
 			uint16 index2 = _scriptHandler->_array12811[index] + (index * 16);
 			Common::Point var1 = _scriptHandler->_array12311[index2];
-			int16 var2 = (var1.x >> 3);
-			var2 &= 0xFE;
+			int16 var2 = var1.x / 16;
 
 			//warning(" step %d : var1 x:%d y:%d  var:%d", _scriptHandler->_array12811[index], var1.x, var1.y, var2 / 2);
 
-			switch (var2 / 2) {
+			switch (var2) {
 			case 0:
 				result = sub16675_moveCharacter(index, var1);
 				break;
@@ -1729,7 +1728,7 @@ void LilliputEngine::sub16626() {
 				result = sub166EA(index);
 				break;
 			default:
-				error("sub16626 - unexpected value %d", var2 / 2);
+				error("sub16626 - unexpected value %d", var2);
 				break;
 			}
 
@@ -2442,8 +2441,8 @@ void LilliputEngine::loadRules() {
 
 		_characterPositionAltitude[j] = (f.readUint16LE() & 0xFF);
 		_characterFrameArray[j] = f.readUint16LE();
-		_rulesBuffer2_5[j] = f.readByte();
-		_rulesBuffer2_6[j] = f.readByte();
+		_rulesBuffer2_5[j] = (int8)f.readByte();
+		_rulesBuffer2_6[j] = (int8)f.readByte();
 		_rulesBuffer2_7[j] = f.readByte();
 		_spriteSizeArray[j] = f.readByte();
 		_characterDirectionArray[j] = f.readByte();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 94b541b..5f856b2 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -160,8 +160,8 @@ public:
 	int16 _characterPositionY[40];
 	int8 _characterPositionAltitude[40];
 	int16 _characterFrameArray[40];
-	byte _rulesBuffer2_5[40];
-	byte _rulesBuffer2_6[40];
+	int8 _rulesBuffer2_5[40];
+	int8 _rulesBuffer2_6[40];
 	byte _rulesBuffer2_7[40];
 	byte _spriteSizeArray[40];
 	byte _characterDirectionArray[40];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b931b87..67a9748 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1491,7 +1491,7 @@ byte LilliputScript::OC_compByte16F04() {
 byte LilliputScript::OC_sub174D8() {
 	debugC(1, kDebugScript, "OC_sub174D8()");
 
-	byte tmpVal = getValue1() & 0xFF;
+	int8 tmpVal = getValue1() & 0xFF;
 	uint16 curWord = _currScript->readUint16LE();
 	
 	if (curWord == 3000) {
@@ -1646,9 +1646,9 @@ byte LilliputScript::OC_sub175C8() {
 byte LilliputScript::OC_sub17640() {
 	debugC(1, kDebugScript, "OC_sub17640()");
 
-	int var4 = _currScript->readUint16LE();
+	uint16 var4 = _currScript->readUint16LE();
 	int index = _vm->_currentScriptCharacter * 40;
-	int tmpVal = _currScript->readUint16LE();
+	uint16 tmpVal = _currScript->readUint16LE();
 
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
@@ -1917,13 +1917,12 @@ byte LilliputScript::OC_CurrentCharacterVar2Equals1() {
 }
 
 byte LilliputScript::OC_sub178D2() {
-	debugC(1, kDebugScriptTBC, "OC_sub178D2()");
+	debugC(1, kDebugScript, "OC_sub178D2()");
 
 	int index = getValue1();
 	assert (index < 40);
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
-
 	if (curByte == _vm->_rulesBuffer2_12[index])
 		return 1;
 
@@ -1959,7 +1958,7 @@ byte LilliputScript::OC_sub1790F() {
 
 	int index = getValue1();
 	assert(index < 40);
-	if (_vm->_rulesBuffer2_5[index] == 0xFF)
+	if (_vm->_rulesBuffer2_5[index] == -1)
 		return 0;
 
 	_word16F00 = _vm->_rulesBuffer2_5[index];
@@ -2433,15 +2432,18 @@ void LilliputScript::OC_sub17C0E() {
 void LilliputScript::OC_sub17C55() {
 	debugC(1, kDebugScriptTBC, "OC_sub17C55()");
 
-	int var1 = getValue1();
-	int var2 = getValue1();
+	byte var1 = ((uint16)getValue1()) & 0xFF;
+	int16 index = getValue1();
 
-	int var3 = _currScript->readUint16LE();
-	int var4 = _currScript->readUint16LE();
+	int8 var3 = (_currScript->readUint16LE() & 0xFF);
+	byte var4 = (_currScript->readUint16LE() & 0xFF);
+
+	assert((index >= 0) && (index < 40));
+	_vm->_rulesBuffer2_5[index] = var1;
+	_vm->_rulesBuffer2_6[index] = var3;
+	_vm->_rulesBuffer2_7[index] = var4;
 
-	_vm->_rulesBuffer2_5[var2] = var1 & 0xFF;
-	_vm->_rulesBuffer2_6[var2] = var3 & 0xFF;
-	_vm->_rulesBuffer2_7[var2] = var4 & 0xFF;
+	warning("debug - OC_sub17C55 index %d, var1 0x%x var3 0x%x var4 0x%x", index, var1, var3, var4);
 }
 
 void LilliputScript::OC_sub17C76() {
@@ -2553,7 +2555,7 @@ void LilliputScript::OC_sub17D23() {
 void LilliputScript::OC_sub17E6D() {
 	debugC(1, kDebugScriptTBC, "OC_sub17E6D()");
 	
-	int var1 = _currScript->readUint16LE();
+	uint16 var1 = _currScript->readUint16LE();
 	_vm->_rulesBuffer2_12[_vm->_currentScriptCharacter] = (var1 - 2000) & 0xFF;
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 722ae60..b5a9916 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -106,7 +106,7 @@ private:
 	byte _byte18823;
 	byte _speechDisplaySpeed;
 
-	int _word16F00;
+	int16 _word16F00;
 	int _currentSpeechId;
 	int _word18821;
 	int _word129A3;


Commit: 82fb9e3c23ee420b744d3b321d74e4f1d045eefb
    https://github.com/scummvm/scummvm/commit/82fb9e3c23ee420b744d3b321d74e4f1d045eefb
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in sub16A76. This fixes the dance a bit more.

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 350490c..217c3ca 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -893,23 +893,23 @@ void LilliputEngine::paletteFadeIn() {
 	}
 }
 
-int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
-	debugC(2, kDebugEngineTBC, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);
+int16 LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
+	debugC(2, kDebugEngine, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);
 
 	int index = (y1 * 64 + x1) * 4;
-	assert(index < 16384);
+	assert(index <= 16380);
 	byte *isoMap = &_bufferIsoMap[1];
 
-	int dx = x2 - x1;
-	int dy = y2 - y1;
+	int16 dx = x2 - x1;
+	int16 dy = y2 - y1;
 
 	int16 tmpMapMoveX = 0;
 	int16 tmpMapMoveY = 0;
 	int16 mapMoveY = 0;
 	int16 mapMoveX = 0;
 
-	int8 byte16DD4 = 0;
-	int8 byte16DD3 = 0;
+	int16 byte16DD4 = 0;
+	int16 byte16DD3 = 0;
 
 	if (dx < 0) {
 		dx = -dx;
@@ -929,15 +929,15 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 		mapMoveY = 0;
 		mapMoveX = tmpMapMoveX;
 	} else {
-		int tmp = dy;
+		int16 tmp = dy;
 		dy = dx;
 		dx = tmp;
 		mapMoveX = 0;
 		mapMoveY = tmpMapMoveY;
 	}
 
-	byte16DD4 = dy << 1;
-	int var1 = byte16DD4 - dx;
+	byte16DD4 = dy * 2;
+	int16 var1 = byte16DD4 - dx;
 	byte16DD3 = byte16DD4 - (dx * 2);
 
 	mapMoveX += mapMoveY;
@@ -959,7 +959,7 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 			return 0;
 		}
 	}
-	return 1;
+	return tmpMapMoveY;
 }
 
 void LilliputEngine::sub15F75() {
@@ -1091,7 +1091,7 @@ void LilliputEngine::sub16CA0() {
 				}
 			}
 
-			int val = _scriptHandler->_array10B51[index2 + index * 40];
+			int16 val = _scriptHandler->_array10B51[index2 + index * 40];
 			val = (val & 0xFF) + ((val & 0xFF) << 8);
 			if ((val & 0xFF) != _byte16C9F) {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
@@ -1406,7 +1406,7 @@ byte LilliputEngine::getDirection(Common::Point param1, Common::Point param2) {
 }
 
 byte LilliputEngine::sub16799(int index, Common::Point param1) {
-	debugC(2, kDebugEngineTBC, "sub16799(%d, %d - %d)", index, param1.x, param1.y);
+	debugC(2, kDebugEngine, "sub16799(%d, %d - %d)", index, param1.x, param1.y);
 
 	Common::Point var3 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
 
@@ -1558,15 +1558,15 @@ void LilliputEngine::sub1693A(int index) {
 }
 
 byte LilliputEngine::sub16A76(int indexb, int indexs) {
-	debugC(2, kDebugEngineTBC, "sub16A76(%d, %d)", indexb, indexs);
+	debugC(2, kDebugEngine, "sub16A76(%d, %d)", indexb, indexs);
 
 	static const char _array16A6C[4] = {1, 0, 0, -1};
 	static const char _array16A70[4] = {0, -1, 1, 0};
 
 	char var1h = _word16937Pos.x + _array16A6C[indexb];
-	char var1l = _word16937Pos.y + _array16A70[indexs];
+	char var1l = _word16937Pos.y + _array16A70[indexb];
 
-	int var2 = findHotspot(Common::Point(var1h, var1l));
+	int16 var2 = findHotspot(Common::Point(var1h, var1l));
 	if (var2 == -1)
 		return 1;
 
@@ -1609,12 +1609,12 @@ int16 LilliputEngine::reverseFindHotspot(Common::Point pos) {
 
 
 void LilliputEngine::sub16A08(int index) {
-	debugC(2, kDebugEngineTBC, "sub16A08(%d)", index);
+	debugC(2, kDebugEngine, "sub16A08(%d)", index);
 
-	static const char arrayMoveX[4] = {1, 0, 0, -1};
-	static const char arrayMoveY[4] = {0, -1, 1, 0};
+	static const int8 arrayMoveX[4] = {1, 0, 0, -1};
+	static const int8 arrayMoveY[4] = {0, -1, 1, 0};
 
-	int arrayDistance[4];
+	int16 arrayDistance[4];
 
 	for (int i = 3; i >= 0; i--) {
 		int16 var1h = _word16937Pos.x + arrayMoveX[i] - _array109E9PosX[index];
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 5f856b2..4027cdf 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -283,7 +283,7 @@ public:
 	byte sub166DD(int index, Common::Point var1);
 	void sub171CF();
 	void sub12FE5();
-	int sub16DD5(int x1, int y1, int x2, int y2);
+	int16 sub16DD5(int x1, int y1, int x2, int y2);
 	void displayCharactersOnMap();
 	void restoreMapPoints();
 	void displayHeroismIndicator();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 67a9748..747ab44 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1954,10 +1954,10 @@ byte LilliputScript::OC_IsCurrentCharacterVar0LessEqualThan() {
 }
 
 byte LilliputScript::OC_sub1790F() {
-	debugC(1, kDebugScriptTBC, "OC_sub1790F()");
+	debugC(1, kDebugScript, "OC_sub1790F()");
 
-	int index = getValue1();
-	assert(index < 40);
+	int16 index = getValue1();
+	assert((index >= 0) && (index < 40));
 	if (_vm->_rulesBuffer2_5[index] == -1)
 		return 0;
 


Commit: 23f2fd8f3e8e4f292c8c8e7a8b73a223f8e69eba
    https://github.com/scummvm/scummvm/commit/23f2fd8f3e8e4f292c8c8e7a8b73a223f8e69eba
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a bug in pathfinding, some renaming

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 217c3ca..4699d02 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -792,7 +792,7 @@ void LilliputEngine::prepareGameArea() {
 }
 
 void LilliputEngine::displayRefreshScreen() {
-	debugC(2, kDebugEngineTBC, "displayRefreshScreen()");
+	debugC(2, kDebugEngine, "displayRefreshScreen()");
 
 	if (_displayMap == 1) {
 		bool forceReturnFl = false;
@@ -1303,7 +1303,7 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 	Common::Point characterPos = Common::Point(_characterDisplayX[index], _characterDisplayY[index]);
 
 	if (index == _scriptHandler->_talkingCharacter)
-		sub1546F(characterPos);
+		displaySpeechBubbleTail(characterPos);
 
 	if (_byte16552 != 1) {
 		byte flag = _characterDirectionArray[index];
@@ -1330,8 +1330,8 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 	renderCharacters(buf, pos);
 }
 
-void LilliputEngine::sub1546F(Common::Point displayPos) {
-	debugC(2, kDebugEngineTBC, "sub1546F(%d, %d)", displayPos.x, displayPos.y);
+void LilliputEngine::displaySpeechBubbleTail(Common::Point displayPos) {
+	debugC(2, kDebugEngine, "displaySpeechBubbleTail(%d, %d)", displayPos.x, displayPos.y);
 
 	int orgX = displayPos.x + 8;
 	int orgY = displayPos.y;
@@ -1340,25 +1340,25 @@ void LilliputEngine::sub1546F(Common::Point displayPos) {
 	int x = orgX;
 	int y = orgY;
 	do {
-		sub15498(Common::Point(x, y), var2);
+		displaySpeechBubbleTailLine(Common::Point(x, y), var2);
 		--x;
-		y >>= 1;
+		y /= 2;
 	} while (y != 0);
 
 	x = orgX + 1;
-	y = orgY >> 1;
+	y = orgY / 2;
 
 	while (y != 0) {
-		sub15498(Common::Point(x, y), var2);
+		displaySpeechBubbleTailLine(Common::Point(x, y), var2);
 		++x;
-		y >>= 1;
+		y /= 2;
 	}
 }
 
-void LilliputEngine::sub15498(Common::Point pos, int var2) {
-	debugC(2, kDebugEngineTBC, "sub15498(%d - %d, %d)", pos.x, pos.y, var2);
+void LilliputEngine::displaySpeechBubbleTailLine(Common::Point pos, int var2) {
+	debugC(2, kDebugEngine, "displaySpeechBubbleTailLine(%d - %d, %d)", pos.x, pos.y, var2);
 
-	int index = pos.x + ((var2 & 0xFF) << 8) + (var2 >> 8);
+	int index = pos.x + (var2 * 256);
 	for (int i = 1 + pos.y - var2; i > 0; i--) {
 		_savedSurfaceGameArea1[index] = 17;
 		index += 256;
@@ -1412,7 +1412,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 
 	if (var3.x != -1) {
 		if ((var3.x != _scriptHandler->_array16123PosX[index]) || (var3.y != _scriptHandler->_array1614BPosY[index])) {
-			sub1693A(index);
+			sub1693A_chooseDirections(index);
 			_scriptHandler->_array12811[index] -= (param1.x & 0x0F);
 			return 3;
 		}
@@ -1428,7 +1428,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 
 	_characterDirectionArray[index] = getDirection(pos1, pos2);
 
-	sub1693A(index);
+	sub1693A_chooseDirections(index);
 	_scriptHandler->_array12811[index] -= (param1.x & 0x0F);
 	return 3;
 
@@ -1508,8 +1508,8 @@ void LilliputEngine::sub167EF(int index) {
 	return;
 }
 
-void LilliputEngine::sub1693A(int index) {
-	debugC(2, kDebugEngineTBC, "sub1693A(%d)", index);
+void LilliputEngine::sub1693A_chooseDirections(int index) {
+	debugC(2, kDebugEngine, "sub1693A_chooseDirections(%d)", index);
 
 	static const int16 mapArrayMove[4] = {4, -256, 256, -4};
 
@@ -1522,7 +1522,7 @@ void LilliputEngine::sub1693A(int index) {
 	_array1692B[var2] -= 8;
 	byte byte16939 = 0;
 
-	int mapIndex = ((((_word16937Pos.y << 8) >> 2) + _word16937Pos.x) << 2);
+	int mapIndex = ((_word16937Pos.y * 64) + _word16937Pos.x) * 4;
 	int mapIndexDiff = 0;
 	int retVal = 0;
 	for (int i = 3; i >= 0; i--) {
@@ -1546,7 +1546,7 @@ void LilliputEngine::sub1693A(int index) {
 	if (byte16939 != 0)
 		_array1692B[_characterDirectionArray[index]] += 3;
 
-	int tmpVal = -97;
+	int tmpVal = -99;
 	for (int i = 3; i >= 0; i--) {
 		if (tmpVal < _array1692B[i]) {
 			retVal = i;
@@ -1676,7 +1676,7 @@ void LilliputEngine::numberToString(int param1) {
 }
 
 void LilliputEngine::sub16626() {
-	debugC(2, kDebugEngineTBC, "sub16626()");
+	debugC(2, kDebugEngine, "sub16626()");
 
 	int index = _numCharacters - 1;
 	byte result;
@@ -1688,9 +1688,9 @@ void LilliputEngine::sub16626() {
 
 			uint16 index2 = _scriptHandler->_array12811[index] + (index * 16);
 			Common::Point var1 = _scriptHandler->_array12311[index2];
-			int16 var2 = var1.x / 16;
 
-			//warning(" step %d : var1 x:%d y:%d  var:%d", _scriptHandler->_array12811[index], var1.x, var1.y, var2 / 2);
+			// /8, then /2 as the function array is a word array 
+			int16 var2 = var1.x / 16;
 
 			switch (var2) {
 			case 0:
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 4027cdf..1ac14a0 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -293,8 +293,8 @@ public:
 	bool isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos);
 	void sub131B2(Common::Point pos, bool &forceReturnFl);
 	void sub131FC(Common::Point pos);
-	void sub1546F(Common::Point displayPos);
-	void sub15498(Common::Point pos, int var2);
+	void displaySpeechBubbleTail(Common::Point displayPos);
+	void displaySpeechBubbleTailLine(Common::Point pos, int var2);
 	void displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex);
 	void checkMapClosing(bool &forceReturnFl);
 	void turnCharacter1(int index);
@@ -312,7 +312,7 @@ public:
 	byte sub1675D(int index, Common::Point var1);
 	byte sub16729(int index, Common::Point var1);
 	byte sub166F7(int index, Common::Point var1, int tmpVal);
-	void sub1693A(int index);
+	void sub1693A_chooseDirections(int index);
 
 	void initGame(const LilliputGameDescription *gd);
 	byte *loadVGA(Common::String filename, int fileSize, bool loadPal);


Commit: c5e4fe1e22492892e8212502bf49c9d6d129ff2f
    https://github.com/scummvm/scummvm/commit/c5e4fe1e22492892e8212502bf49c9d6d129ff2f
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix mouse display in title screens

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 4699d02..4de8e73 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -337,7 +337,7 @@ void LilliputEngine::displayCharacter(int index, Common::Point pos, int flags) {
 	}
 }
 
-void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point pos) {
+void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point pos, bool transparent, bool updateScreen) {
 	debugC(2, kDebugEngine, "display16x16IndexedBuf(buf, %d, %d - %d)", index, pos.x, pos.y);
 
 	int index1 = index * 16 * 16;
@@ -350,21 +350,24 @@ void LilliputEngine::display16x16IndexedBuf(byte *buf, int index, Common::Point
 		if (pos.y + i < 200) {
 			for (int j = 0; j < 16; j++) {
 				// clip on x
-				if ((newBuf[j] != 0) && (pos.x + j < 320))
+				if ((newBuf[j] != 0 || !transparent) && (pos.x + j < 320))
 					((byte *)_mainSurface->getPixels())[vgaIndex + j] = newBuf[j];
 			}
 		}
 		vgaIndex += 320;
 		newBuf += 16;
 	}
-	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
-	_system->updateScreen();
+
+	if (updateScreen) {
+		_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
+		_system->updateScreen();
+	}
 }
 
-void LilliputEngine::display16x16Buf(byte *buf, Common::Point pos) {
+void LilliputEngine::display16x16Buf(byte *buf, Common::Point pos, bool transparent, bool updateScreen) {
 	debugC(2, kDebugEngine, "display16x16Buf(buf, %d, %d)", pos.x, pos.y);
 
-	display16x16IndexedBuf(buf, 0, pos);
+	display16x16IndexedBuf(buf, 0, pos, transparent, updateScreen);
 }
 
 void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
@@ -412,7 +415,7 @@ void LilliputEngine::restoreSurfaceUnderMousePointer() {
 
 	if ((_skipDisplayFlag1 != 0) && (_skipDisplayFlag2 != 1)) {
 		_skipDisplayFlag2 = 1;
-		display16x16Buf(_savedSurfaceUnderMouse, _savedSurfaceUnderMousePos);
+		display16x16Buf(_savedSurfaceUnderMouse, _savedSurfaceUnderMousePos, false, false);
 		_skipDisplayFlag1 = 0;
 		_skipDisplayFlag2 = 0;
 	}
@@ -839,7 +842,7 @@ void LilliputEngine::displaySmallIndexedAnim(byte index, byte subIndex) {
 	if (!_smallAnims[index]._active)
 		return;
 
-	display16x16IndexedBuf(_bufferIdeogram, _smallAnims[index]._frameIndex[subIndex], _smallAnims[index]._pos);
+	display16x16IndexedBuf(_bufferIdeogram, _smallAnims[index]._frameIndex[subIndex], _smallAnims[index]._pos, false);
 }
 
 void LilliputEngine::displaySmallAnims() {
@@ -848,6 +851,8 @@ void LilliputEngine::displaySmallAnims() {
 	if (_animationTick == _lastAnimationTick)
 		return;
 
+	restoreSurfaceUnderMousePointer();
+
 	_lastAnimationTick = _animationTick;
 
 	assert(_smallAnimsFrameIndex < 8);
@@ -862,6 +867,8 @@ void LilliputEngine::displaySmallAnims() {
 		subIndex = 0;
 
 	_smallAnimsFrameIndex = subIndex;
+
+	displayMousePointer();
 }
 
 void LilliputEngine::paletteFadeOut() {
@@ -876,6 +883,7 @@ void LilliputEngine::paletteFadeOut() {
 		_system->getPaletteManager()->setPalette(palette, 0, 256);
 		_system->updateScreen();
 		_system->delayMillis(20);
+		pollEvent();
 	}
 }
 
@@ -890,6 +898,7 @@ void LilliputEngine::paletteFadeIn() {
 		_system->getPaletteManager()->setPalette(palette, 0, 256);
 		_system->updateScreen();
 		_system->delayMillis(20);
+		pollEvent();
 	}
 }
 
@@ -2572,14 +2581,15 @@ void LilliputEngine::loadRules() {
 void LilliputEngine::displayVGAFile(Common::String fileName) {
 	debugC(1, kDebugEngine, "displayVGAFile(%s)", fileName.c_str());
 
-	displayMousePointer();
+	restoreSurfaceUnderMousePointer();
 
 	byte *buffer = loadVGA(fileName, 64000, true);
 	memcpy(_mainSurface->getPixels(), buffer, 320*200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
+	
+	displayMousePointer();
 
-	restoreSurfaceUnderMousePointer();
 }
 
 void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 1ac14a0..7ee1a26 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -223,8 +223,8 @@ public:
 	void newInt8();
 	void update();
 
-	void display16x16IndexedBuf(byte *buf, int index, Common::Point pos);
-	void display16x16Buf(byte *buf, Common::Point pos);
+	void display16x16IndexedBuf(byte *buf, int index, Common::Point pos, bool transparent = true, bool updateScreen = true);
+	void display16x16Buf(byte *buf, Common::Point pos, bool transparent = true, bool updateScreen = true);
 	void SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos);
 	void fill16x16Rect(byte col, Common::Point pos);
 	void displayMousePointer();


Commit: 2e9867086cf5f40742c0447fcee970c66e4f854a
    https://github.com/scummvm/scummvm/commit/2e9867086cf5f40742c0447fcee970c66e4f854a
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix one more double variable, some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 4de8e73..e34dfd6 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -133,7 +133,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 
 	_byte1714E = 0;
 	_byte12FCE = 0;
-	_byte129A0 = 0xFF;
+	_byte129A0 = -1;
 	_numCharactersToDisplay = 0;
 	_nextDisplayCharacterPos = Common::Point(0, 0);
 	_animationTick = 0;
@@ -974,7 +974,7 @@ int16 LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 void LilliputEngine::sub15F75() {
 	debugC(2, kDebugEngineTBC, "sub15F75()");
 
-	_byte129A0 = 0xFF;
+	_byte129A0 = -1;
 	_savedMousePosDivided = Common::Point(-1, -1);
 	byte newX = _mousePos.x >> 2;
 	byte newY = _mousePos.y / 3;
@@ -1927,7 +1927,7 @@ void LilliputEngine::sub131B2(Common::Point pos, bool &forceReturnFl) {
 
 	forceReturnFl = false;
 
-	for (byte i = 0; i < _numCharacters; i++) {
+	for (int8 i = 0; i < _numCharacters; i++) {
 		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_byte129A0 = i;
 			_byte16F07_menuId = 4;
@@ -2653,7 +2653,7 @@ void LilliputEngine::handleMenu() {
 	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScriptSize));
 	debugC(1, kDebugScriptTBC, "========================== End of Menu Script==============================");
 	_savedMousePosDivided = Common::Point(-1, -1);
-	_byte129A0 = 0xFF;
+	_byte129A0 = -1;
 
 	if (_byte16F07_menuId == 3)
 		unselectInterfaceButton();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 7ee1a26..49892d8 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -342,7 +342,7 @@ public:
 
 	byte _byte16F07_menuId;
 	byte _byte12FCE;
-	byte _byte129A0;
+	int8 _byte129A0;
 	byte _numCharactersToDisplay;
 	byte _byte16C9F;
 	int16 _word10804;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 747ab44..b9286da 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -29,7 +29,6 @@
 namespace Lilliput {
 
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
-	_byte129A0 = 0xFF;
 	_byte10806 = 0;
 	_lastRandomValue = 0;
 	_byte16F04 = 0;
@@ -388,7 +387,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_skipNextVal();
 		break;
 	case 0x30:
-		OC_sub17FD2();
+		OC_setCurrentCharacterVar6();
 		break;
 	case 0x31:
 		OC_sub17FDD();
@@ -658,7 +657,7 @@ static const OpCode opCodes2[] = {
 /* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x2e */	{ "OC_scrollAwayFromCharacter", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x2f */	{ "OC_skipNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x30 */	{ "OC_sub17FD2", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x30 */	{ "OC_setCurrentCharacterVar6", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x32 */	{ "OC_setByte10B29", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -1283,13 +1282,13 @@ int16 LilliputScript::getValue1() {
 
 	switch (curWord) {
 	case 1000:
-		return (int)_byte129A0;
+		return _vm->_byte129A0;
 	case 1001:
 		return _vm->_currentScriptCharacter;
 	case 1002:
 		return _word16F00;
 	case 1003:
-		return (int)_vm->_currentCharacterVariables[6];
+		return (int16)_vm->_currentCharacterVariables[6];
 	case 1004:
 		return _vm->_word10804;
 	default:
@@ -1891,10 +1890,10 @@ byte LilliputScript::OC_IsPositionInViewport() {
 }
 
 byte LilliputScript::OC_CompareGameVariables() {
-	debugC(1, kDebugScriptTBC, "OC_CompareGameVariables()");
+	debugC(1, kDebugScript, "OC_CompareGameVariables()");
 
-	int var1 = getValue1();
-	int var2 = getValue1();
+	int16 var1 = getValue1();
+	int16 var2 = getValue1();
 	if (var1 == var2)
 		return 1;
 	return 0;
@@ -2028,16 +2027,16 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndex() {
 byte LilliputScript::OC_checkSavedMousePos() {
 	debugC(1, kDebugScriptTBC, "OC_checkSavedMousePos()");
 
-	if ((_byte129A0 != 0xFF) || (_vm->_savedMousePosDivided == Common::Point(-1, -1)))
+	if ((_vm->_byte129A0 != -1) || (_vm->_savedMousePosDivided == Common::Point(-1, -1)))
 		return 0;
 
 	return 1;
 }
 
 byte LilliputScript::OC_sub179AE() {
-	debugC(1, kDebugScriptTBC, "OC_sub179AE()");
+	debugC(1, kDebugScript, "OC_sub179AE()");
 
-	if ((_vm->_byte12FCE == 1) || (_byte129A0 == 0xFF))
+	if ((_vm->_byte12FCE == 1) || (_vm->_byte129A0 == -1))
 		return 0;
 
 	return 1;
@@ -2430,12 +2429,12 @@ void LilliputScript::OC_sub17C0E() {
 }
 
 void LilliputScript::OC_sub17C55() {
-	debugC(1, kDebugScriptTBC, "OC_sub17C55()");
+	debugC(1, kDebugScript, "OC_sub17C55()");
 
-	byte var1 = ((uint16)getValue1()) & 0xFF;
+	int8 var1 = (getValue1() & 0xFF);
 	int16 index = getValue1();
 
-	int8 var3 = (_currScript->readUint16LE() & 0xFF);
+	int8 var3 = (_currScript->readSint16LE() & 0xFF);
 	byte var4 = (_currScript->readUint16LE() & 0xFF);
 
 	assert((index >= 0) && (index < 40));
@@ -2450,7 +2449,7 @@ void LilliputScript::OC_sub17C76() {
 	debugC(1, kDebugScriptTBC, "OC_sub17C76()");
 	
 	int var1 = getValue1();
-	_vm->_rulesBuffer2_5[var1] = 0xFF;
+	_vm->_rulesBuffer2_5[var1] = -1;
 	_vm->_characterPositionAltitude[var1] = 0;
 	_characterScriptEnabled[var1] = 1;
 
@@ -2697,10 +2696,11 @@ void LilliputScript::OC_skipNextVal() {
 	 _currScript->readUint16LE();
 }
 
-void LilliputScript::OC_sub17FD2() {
-	debugC(1, kDebugScriptTBC, "OC_sub17FD2()");
+void LilliputScript::OC_setCurrentCharacterVar6() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterVar6()");
 	
-	int var1 = getValue1();
+	uint16 var1 = (uint16)getValue1();
+	warning("debug - OC_setCurrentCharacterVar6 %d", var1);
 	_vm->_currentCharacterVariables[6] = var1 & 0xFF;
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index b5a9916..ca20876 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -98,7 +98,6 @@ private:
 	Common::Stack<ScriptStream *> _scriptStack;
 
 	byte _byte16F05_ScriptHandler;
-	byte _byte129A0;
 	byte _byte10806;
 	byte _lastRandomValue;
 	byte _byte16F04;
@@ -242,7 +241,7 @@ private:
 	void OC_sub17F4F();
 	void OC_scrollAwayFromCharacter();
 	void OC_skipNextVal();
-	void OC_sub17FD2();
+	void OC_setCurrentCharacterVar6();
 	void OC_sub17FDD();
 	void OC_setByte10B29();
 	void OC_setCurrentCharacterVar2();


Commit: 21d38e3b4c7725c99a5b2da755c0a7ffb2dc696d
    https://github.com/scummvm/scummvm/commit/21d38e3b4c7725c99a5b2da755c0a7ffb2dc696d
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: bugfix: Intro is now completable

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index e34dfd6..a31688c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -907,7 +907,7 @@ int16 LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 
 	int index = (y1 * 64 + x1) * 4;
 	assert(index <= 16380);
-	byte *isoMap = &_bufferIsoMap[1];
+	byte *isoMap = &_bufferIsoMap[index + 1];
 
 	int16 dx = x2 - x1;
 	int16 dy = y2 - y1;
@@ -1023,7 +1023,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 }
 
 void LilliputEngine::sub16CA0() {
-	debugC(2, kDebugEngineTBC, "sub16CA0()");
+	debugC(2, kDebugEngine, "sub16CA0()");
 
 	for (int index = _numCharacters - 1; index >= 0; index--) {
 		if (_rulesBuffer2_11[index] & 1)
@@ -1053,46 +1053,51 @@ void LilliputEngine::sub16CA0() {
 							} else if ((_rulesBuffer2_11[index] & 4) != 0) {
 								_byte16C9F = 0;
 							} else {
-								if (_characterDirectionArray[index] == 0) {
+								switch (_characterDirectionArray[index]) {
+								case 0:
 									if (d1 > c1) {
 										_byte16C9F = 2;
 
 										if (d2 == c2)
 											_byte16C9F = 3;
 
-										if (sub16DD5(c1, d1, c2, d2) != 0)
+										if (sub16DD5(c1, c2, d1, d2) != 0)
 											_byte16C9F = 1;
 									}
-								} else if (_characterDirectionArray[index] == 1) {
+									break;
+								case 1:
 									if (d2 < c2) {
 										_byte16C9F = 2;
 
 										if (d1 == c1)
 											_byte16C9F = 3;
 
-										if (sub16DD5(c1, d1, c2, d2) != 0)
+										if (sub16DD5(c1, c2, d1, d2) != 0)
 											_byte16C9F = 1;
 									}
-								} else if (_characterDirectionArray[index] == 2) {
+									break;
+								case 2:
 									if (d2 > c2) {
 										_byte16C9F = 2;
 
 										if (d1 == c1)
 											_byte16C9F = 3;
 
-										if (sub16DD5(c1, d1, c2, d2) != 0)
+										if (sub16DD5(c1, c2, d1, d2) != 0)
 											_byte16C9F = 1;
 									}
-								} else {
+									break;
+								default:
 									if (d1 < c1) {
 										_byte16C9F = 2;
 
 										if (d2 == c2)
 											_byte16C9F = 3;
 
-										if (sub16DD5(c1, d1, c2, d2) != 0)
+										if (sub16DD5(c1, c2, d1, d2) != 0)
 											_byte16C9F = 1;
 									}
+									break;
 								}
 							}
 						}
@@ -1100,13 +1105,14 @@ void LilliputEngine::sub16CA0() {
 				}
 			}
 
-			int16 val = _scriptHandler->_array10B51[index2 + index * 40];
-			val = (val & 0xFF) + ((val & 0xFF) << 8);
-			if ((val & 0xFF) != _byte16C9F) {
+			int8 v2 = _scriptHandler->_array10B51[index2 + (index * 40)] & 0xFF;
+			int8 v1 = v2;
+
+			if (v2 != _byte16C9F) {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
-				val = (val & 0xFF00) | _byte16C9F;
+				v2 =  _byte16C9F;
 			}
-			_scriptHandler->_array10B51[index2 + index * 40] = val;
+			_scriptHandler->_array10B51[index2 + (index * 40)] = (v1 << 8) + v2;
 		}
 	}
 }
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b9286da..de250c8 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1546,7 +1546,7 @@ byte LilliputScript::OC_compareCoords_1() {
 
 // TODO Rename function to "Check if character pos in rectangle"
 byte LilliputScript::OC_compareCoords_2() {
-	debugC(1, kDebugScriptTBC, "OC_compareCoords_2()");
+	debugC(1, kDebugScript, "OC_compareCoords_2()");
 
 	int16 index = getValue1();
 	Common::Point var1 = Common::Point(_array16123PosX[index], _array1614BPosY[index]);


Commit: bcfbf5df47664f8caae8a1fbfcb8ffc831a2d8e0
    https://github.com/scummvm/scummvm/commit/bcfbf5df47664f8caae8a1fbfcb8ffc831a2d8e0
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in OC_sub17A07 and renderCharacters, implement OC_startSpeechWithoutSpeeker

Some renaming, too

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index a31688c..55de37e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -184,7 +184,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_characterRelativePositionY[i] = -1;
 		_characterDisplayX[i] = 0;
 		_characterDisplayY[i] = 0;
-		_array12299[i] = 0xFF;
+		_array12299[i] = -1;
 		_array109E9PosX[i] = -1;
 		_array10A11PosY[i] = -1;
 		_array16E94[i] = 0;
@@ -1329,7 +1329,7 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 			if ((flag & 1) == 1)
 				frame += _spriteSizeArray[index];
 
-			if (_array12299[index] != 0xFF) {
+			if (_array12299[index] != -1) {
 				frame = _array12299[index] + 82;
 				--_array12299[index];
 				frame = -frame;
@@ -1801,7 +1801,7 @@ byte LilliputEngine::sub16722(int index, Common::Point var1) {
 }
 
 byte LilliputEngine::sub16729(int index, Common::Point var1) {
-	debugC(2, kDebugEngineTBC, "sub16729(%d, %d - %d)", index, var1.x, var1.y);
+	debugC(2, kDebugEngine, "sub16729(%d, %d - %d)", index, var1.x, var1.y);
 
 	int param4x = ((index | 0xFF00) >> 8);
 	int param1 = var1.y;
@@ -1810,19 +1810,15 @@ byte LilliputEngine::sub16729(int index, Common::Point var1) {
 }
 
 byte LilliputEngine::sub1675D(int index, Common::Point var1) {
-	debugC(2, kDebugEngineTBC, "sub1675D(%d, %d - %d)", index, var1.x, var1.y);
+	debugC(2, kDebugEngine, "sub1675D(%d, %d - %d)", index, var1.x, var1.y);
 
 	int var2 = _scriptHandler->_array10A39[index];
-	int var1h = _scriptHandler->_array16123PosX[var2];
-	int var1l = _scriptHandler->_array1614BPosY[var2];
-	int var3 = _array109E9PosX[index];
-
-	if ((var3 != 0xFF) && (var3 == _array10999PosX[index])) {
-		var3 = _array10A11PosY[index];
-		if (var3 == _array109C1PosY[index]) {
-			_array109E9PosX[index] = var1h;
-			_array10A11PosY[index] = var1l;
-		}
+	int8 var1h = _scriptHandler->_array16123PosX[var2];
+	int8 var1l = _scriptHandler->_array1614BPosY[var2];
+
+	if ((_array109E9PosX[index] != -1) && (_array109E9PosX[index] == _array10999PosX[index]) && (_array10A11PosY[index] == _array109C1PosY[index])) {
+		_array109E9PosX[index] = var1h;
+		_array10A11PosY[index] = var1l;
 	}
 
 	_array10999PosX[index] = var1h;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 49892d8..1006c34 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -205,7 +205,7 @@ public:
 	int16 _characterRelativePositionY[40];
 	int16 _characterDisplayX[40];
 	int16 _characterDisplayY[40];
-	byte _array12299[40];
+	int8 _array12299[40];
 	int16 _array109E9PosX[40];
 	int16 _array10A11PosY[40];
 	byte _array16E94[40];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index de250c8..b34acde 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -264,7 +264,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17E07_speech4param();
 		break;
 	case 0x7:
-		OC_sub17E15_speech2param();
+		OC_startSpeechIfSilent();
 		break;
 	case 0x8:
 		OC_ComputeCharacterVariable();
@@ -393,7 +393,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17FDD();
 		break;
 	case 0x32:
-		OC_setByte10B29();
+		OC_setCharacterScriptEnabled();
 		break;
 	case 0x33:
 		OC_setCurrentCharacterVar2();
@@ -495,7 +495,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_displayVGAFile();
 		break;
 	case 0x54:
-		OC_sub184D7();
+		OC_startSpeechWithoutSpeeker();
 		break;
 	case 0x55:
 		OC_displayTitleScreen();
@@ -543,7 +543,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1875D_snd();
 		break;
 	case 0x64:
-		OC_setArray128E();
+		OC_setArray128EF();
 		break;
 	case 0x65:
 		OC_initGameAreaDisplay();
@@ -616,7 +616,7 @@ static const OpCode opCodes2[] = {
 /* 0x04 */	{ "OC_sub17DB9_speech3", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
 /* 0x05 */	{ "OC_startSpeechIfMute", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x06 */	{ "OC_sub17E07_speech4param", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
-/* 0x07 */	{ "OC_sub17E15_speech2param", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x07 */	{ "OC_startSpeechIfSilent", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x08 */	{ "OC_ComputeCharacterVariable", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
 /* 0x09 */	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
@@ -659,7 +659,7 @@ static const OpCode opCodes2[] = {
 /* 0x2f */	{ "OC_skipNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x30 */	{ "OC_setCurrentCharacterVar6", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x32 */	{ "OC_setByte10B29", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x32 */	{ "OC_setCharacterScriptEnabled", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
 /* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x34 */	{ "OC_SetCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x35 */	{ "OC_setCharacterProperties", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
@@ -693,7 +693,7 @@ static const OpCode opCodes2[] = {
 /* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x52 */	{ "OC_displayNumericCharacterVariable", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x53 */	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x54 */	{ "OC_sub184D7", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
+/* 0x54 */	{ "OC_startSpeechWithoutSpeeker", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
 /* 0x55 */	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x56 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x57 */	{ "OC_displayCharacterStatBar", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue}, 
@@ -709,7 +709,7 @@ static const OpCode opCodes2[] = {
 /* 0x61 */	{ "OC_sub1873F_snd", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x63 */	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x64 */	{ "OC_setArray128E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x64 */	{ "OC_setArray128EF", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x65 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
@@ -1849,7 +1849,7 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu13() {
 }
 
 byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu2() {
-	debugC(1, kDebugScriptTBC, "OC_checkLastInterfaceHotspotIndexMenu2()");
+	debugC(1, kDebugScript, "OC_checkLastInterfaceHotspotIndexMenu2()");
 
 	int8 hotspotIndex = (_currScript->readUint16LE() & 0xFF);
 
@@ -2000,12 +2000,12 @@ byte LilliputScript::OC_CurrentCharacterVar3Equals1() {
 }
 
 byte LilliputScript::OC_checkCharacterDirection() {
-	debugC(1, kDebugScriptTBC, "OC_checkCharacterDirection()");
+	debugC(1, kDebugScript, "OC_checkCharacterDirection()");
 
-	int var1 = getValue1();
-	int var2 = _currScript->readUint16LE();
+	int16 index = getValue1();
+	byte expectedVal = (_currScript->readUint16LE() & 0xFF);
 
-	if (_vm->_characterDirectionArray[var1] == var2)
+	if (_vm->_characterDirectionArray[index] == expectedVal)
 		return 1;
 	return 0;
 }
@@ -2025,7 +2025,7 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndex() {
 }
 
 byte LilliputScript::OC_checkSavedMousePos() {
-	debugC(1, kDebugScriptTBC, "OC_checkSavedMousePos()");
+	debugC(1, kDebugScript, "OC_checkSavedMousePos()");
 
 	if ((_vm->_byte129A0 != -1) || (_vm->_savedMousePosDivided == Common::Point(-1, -1)))
 		return 0;
@@ -2066,24 +2066,29 @@ byte LilliputScript::OC_checkKeyPressed() {
 }
 
 byte LilliputScript::OC_sub17A07() {
-	debugC(1, kDebugScriptTBC, "OC_sub17A07()");
+	debugC(1, kDebugScript, "OC_sub17A07()");
 
-	static const byte _array179FD[10] = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+	static const byte array179FD[10] = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 
 	if (_vm->_byte16F07_menuId == 6) {
-		int index = _currScript->readUint16LE();
-		if (_array179FD[index] == _vm->_array147D1[0]) {
+		uint16 index = _currScript->readUint16LE();
+		if (array179FD[index] == _vm->_array147D1[0]) {
 			index = _currScript->readUint16LE();
-			if (_array179FD[index] == _vm->_array147D1[1]) {
+			if (array179FD[index] == _vm->_array147D1[1]) {
 				index = _currScript->readUint16LE();
-				if (_array179FD[index] == _vm->_array147D1[2]) {
+				if (array179FD[index] == _vm->_array147D1[2]) {
 					return 1;
 				}
-			}
-		}
-	}
-	
-	_currScript->seek(_currScript->pos() + 6);
+			} else
+				// skip last index check
+				_currScript->seek(_currScript->pos() + 2);
+		} else
+			// skip two last index checks
+			_currScript->seek(_currScript->pos() + 4);
+	} else
+		// skip the three index checks
+		_currScript->seek(_currScript->pos() + 6);
+
 	return 0;
 }
 
@@ -2228,8 +2233,8 @@ void LilliputScript::OC_sub17E07_speech4param() {
 
 }
 
-void LilliputScript::OC_sub17E15_speech2param() {
-	debugC(1, kDebugScriptTBC, "OC_sub17E15_speech2param()");
+void LilliputScript::OC_startSpeechIfSilent() {
+	debugC(1, kDebugScript, "OC_startSpeechIfSilent()");
 
 	if (_talkingCharacter == -1) {
 		OC_sub17DB9_speech3();
@@ -2446,12 +2451,12 @@ void LilliputScript::OC_sub17C55() {
 }
 
 void LilliputScript::OC_sub17C76() {
-	debugC(1, kDebugScriptTBC, "OC_sub17C76()");
+	debugC(1, kDebugScript, "OC_sub17C76()");
 	
-	int var1 = getValue1();
-	_vm->_rulesBuffer2_5[var1] = -1;
-	_vm->_characterPositionAltitude[var1] = 0;
-	_characterScriptEnabled[var1] = 1;
+	int index = getValue1();
+	_vm->_rulesBuffer2_5[index] = -1;
+	_vm->_characterPositionAltitude[index] = 0;
+	_characterScriptEnabled[index] = 1;
 
 }
 
@@ -2715,11 +2720,11 @@ void LilliputScript::OC_sub17FDD() {
 	_array12811[_vm->_currentScriptCharacter] = 16;
 }
 
-void LilliputScript::OC_setByte10B29() {
-	debugC(1, kDebugScriptTBC, "OC_setByte10B29()");
+void LilliputScript::OC_setCharacterScriptEnabled() {
+	debugC(1, kDebugScript, "OC_setCharacterScriptEnabled()");
 
-	int var1 = getValue1();
-	_characterScriptEnabled[var1] = 1;
+	int16 index = getValue1();
+	_characterScriptEnabled[index] = 1;
 }
 
 void LilliputScript::OC_setCurrentCharacterVar2() {
@@ -2922,10 +2927,10 @@ void LilliputScript::OC_sub18213() {
 }
 
 void LilliputScript::OC_sub18252() {
-	debugC(1, kDebugScriptTBC, "OC_sub18252()");
+	debugC(1, kDebugScript, "OC_sub18252()");
 
-	int index = getValue1();
-	assert(index < 40);
+	int16 index = getValue1();
+	assert((index >0) && (index < 40));
 
 	_vm->_array12299[index] = 4;
 }
@@ -3039,10 +3044,10 @@ void LilliputScript::OC_sub183A2() {
 }
 
 void LilliputScript::OC_disableInterfaceHotspot() {
-	debugC(1, kDebugScriptTBC, "OC_disableInterfaceHotspot()");
+	debugC(1, kDebugScript, "OC_disableInterfaceHotspot()");
 
 	int index = _currScript->readUint16LE();
-	_array122FD[index] = (_currScript->readUint16LE() & 0xff);
+	_array122FD[index] = (_currScript->readUint16LE() & 0xFF);
 	_interfaceHotspotStatus[index] = kHotspotDisabled;
 
 	_vm->displayInterfaceHotspots();
@@ -3051,7 +3056,7 @@ void LilliputScript::OC_disableInterfaceHotspot() {
 void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	debugC(1, kDebugScriptTBC, "OC_loadFile_AERIAL_GFX()");
 	
-	int var1 = _currScript->readUint16LE() & 0xff;
+	int var1 = _currScript->readUint16LE() & 0xFF;
 	_vm->_byte15EAD = var1;
 
 	_vm->_refreshScreenFlag = true;
@@ -3131,8 +3136,11 @@ void LilliputScript::OC_displayVGAFile() {
 	_vm->paletteFadeIn();
 }
 
-void LilliputScript::OC_sub184D7() {
-	warning("OC_sub184D7");
+void LilliputScript::OC_startSpeechWithoutSpeeker() {
+	debugC(1, kDebugScript, "OC_startSpeechWithoutSpeeker()");
+
+	int16 speechId = _currScript->readUint16LE();
+	startSpeech(speechId);
 }
 
 void LilliputScript::OC_displayTitleScreen() {
@@ -3314,8 +3322,8 @@ void LilliputScript::OC_sub1875D_snd() {
 	_vm->_soundHandler->contentFct6();
 }
 
-void LilliputScript::OC_setArray128E() {
-	debugC(1, kDebugScript, "OC_setArray128E()");
+void LilliputScript::OC_setArray128EF() {
+	debugC(1, kDebugScript, "OC_setArray128EF()");
 
 	int index = getValue1();
 	int val = _currScript->readUint16LE();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index ca20876..757ce91 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -200,7 +200,7 @@ private:
 	void OC_sub17DB9_speech3();
 	void OC_startSpeechIfMute();
 	void OC_sub17E07_speech4param();
-	void OC_sub17E15_speech2param();
+	void OC_startSpeechIfSilent();
 	void OC_ComputeCharacterVariable();
 	void OC_getRandom_type2();
 	void OC_setCharacterPosition();
@@ -243,7 +243,7 @@ private:
 	void OC_skipNextVal();
 	void OC_setCurrentCharacterVar6();
 	void OC_sub17FDD();
-	void OC_setByte10B29();
+	void OC_setCharacterScriptEnabled();
 	void OC_setCurrentCharacterVar2();
 	void OC_SetCurrentCharacterVar2ToZero();
 	void OC_setCharacterProperties();
@@ -278,7 +278,7 @@ private:
 	void OC_sub1844A();
 	void OC_displayNumericCharacterVariable();
 	void OC_displayVGAFile();
-	void OC_sub184D7();
+	void OC_startSpeechWithoutSpeeker();
 	void OC_displayTitleScreen();
 	void OC_initGameAreaDisplay();
 	void OC_displayCharacterStatBar();
@@ -294,7 +294,7 @@ private:
 	void OC_sub1873F_snd();
 	void OC_sub18746_snd();
 	void OC_sub1875D_snd();
-	void OC_setArray128E();
+	void OC_setArray128EF();
 };
 
 } // End of namespace Lilliput


Commit: 3ea95583a2cd2e8b6f8bb501a97ce9167e514776
    https://github.com/scummvm/scummvm/commit/3ea95583a2cd2e8b6f8bb501a97ce9167e514776
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in sub167EF

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/sound.cpp
    engines/lilliput/sound.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 55de37e..3af5fdd 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1450,10 +1450,10 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 }
 
 void LilliputEngine::sub167EF(int index) {
-	debugC(2, kDebugEngineTBC, "sub167EF(%d)", index);
+	debugC(2, kDebugEngine, "sub167EF(%d)", index);
 
-	int word167EB = findHotspot(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
-	int word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
+	int16 word167EB = findHotspot(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
+	int16 word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
 
 	if (word167EB == word167ED) {
 		_array109E9PosX[index] = _array10999PosX[index];
@@ -1484,13 +1484,15 @@ void LilliputEngine::sub167EF(int index) {
 	int var4l = (_rectXMinMax[word167EB] & 0xFF);
 
 	if (var4h != var4l) {
-		if (_array109E9PosX[index] == var4h) {
-			--_array109E9PosX[index];
+		if (_rulesBuffer12Pos4[word167EB].x == var4h) {
+			_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x - 1;
+			_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
 			return;
 		}
 
-		if (_array109E9PosX[index] == var4l) {
-			++_array109E9PosX[index];
+		if (_rulesBuffer12Pos4[word167EB].x == var4l) {
+			_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x + 1;
+			_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
 			return;
 		}
 
@@ -1498,28 +1500,35 @@ void LilliputEngine::sub167EF(int index) {
 		var4l = (_rectYMinMax[word167EB] & 0xFF);
 
 		if (var4h != var4l) {
-			if (_array10A11PosY[index] == var4h)
-				--_array10A11PosY[index];
-			else
-				++_array10A11PosY[index];
+			if (_rulesBuffer12Pos4[word167EB].y == var4h) {
+				_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
+				_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y - 1;
+			} else {
+				_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
+				_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y + 1;
+			}
 			return;
 		}
 	}
 
 	// var4h == var4l
-	int mapIndex = (_array10A11PosY[index] * 64 + _array109E9PosX[index]) * 4;
+	int mapIndex = (_rulesBuffer12Pos4[word167EB].y * 64 + _rulesBuffer12Pos4[word167EB].x) * 4;
 	assert(mapIndex < 16384);
 
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
-	if ((tmpVal & 8) != 0)
-		++_array109E9PosX[index];
-	else if ((tmpVal & 4) != 0)
-		--_array10A11PosY[index];
-	else if ((tmpVal & 2) != 0)
-		++_array10A11PosY[index];
-	else
-		--_array109E9PosX[index];
-
+	if ((tmpVal & 8) != 0) {
+		_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x + 1;
+		_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
+	} else if ((tmpVal & 4) != 0) {
+		_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
+		_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y - 1;
+	} else if ((tmpVal & 2) != 0) {
+		_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
+		_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y + 1;
+	} else {
+		_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x - 1;
+		_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
+	}
 	return;
 }
 
@@ -1966,7 +1975,7 @@ bool LilliputEngine::isMouseOverHotspot(Common::Point mousePos, Common::Point ho
 }
 
 void LilliputEngine::sub1305C(byte index, byte button) {
-	debugC(2, kDebugEngineTBC, "sub1305C(%d, %d)", index, button);
+	debugC(2, kDebugEngine, "sub1305C(%d, %d)", index, button);
 
 	if (_scriptHandler->_interfaceHotspotStatus[index] < kHotspotEnabled)
 		return;
@@ -2717,9 +2726,9 @@ void LilliputEngine::handleGameScripts() {
 	//debugC(1, kDebugEngineTBC, "before char %d, pos %d %d, var0 %d, var1 %d, var2 %d var16 %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), *getCharacterVariablesPtr(i * 32 + 1), *getCharacterVariablesPtr(i * 32 + 2),  *getCharacterVariablesPtr(i * 32 + 22), _scriptHandler->_characterScriptEnabled[i]);
 
 	assert(tmpVal < _gameScriptIndexSize);
-	debugC(1, kDebugEngineTBC, "================= Game Script %d for character %d ==================", tmpVal, index);
+	debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index);
 	_scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal]));
-	debugC(1, kDebugEngineTBC, "============= End Game Script %d for character %d ==================", tmpVal, index);
+	debugC(1, kDebugEngine, "============= End Game Script %d for character %d ==================", tmpVal, index);
 
 	//warning("dump char stat");
 	//debugC(1, kDebugEngineTBC, "after char %d, pos %d %d, var0 %d, var1 %d, var2 %d var16 %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), *getCharacterVariablesPtr(i * 32 + 1), *getCharacterVariablesPtr(i * 32 + 2),  *getCharacterVariablesPtr(i * 32 + 22), _scriptHandler->_characterScriptEnabled[i]);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b34acde..967486e 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -3285,17 +3285,17 @@ void LilliputScript::OC_sub1870A_snd() {
 void LilliputScript::OC_sub18725_snd() {
 	debugC(1, kDebugScript, "OC_sub18725_snd()");
 
-	int var4 = getValue1() | 0xFF00;
+	Common::Point var4 = Common::Point(-1, getValue1() & 0xFF);
 
-	_vm->_soundHandler->contentFct3();
+	_vm->_soundHandler->contentFct3(var4);
 }
 
 void LilliputScript::OC_sub18733_snd() {
-	debugC(1, kDebugScriptTBC, "OC_sub18733_snd()");
+	debugC(1, kDebugScript, "OC_sub18733_snd()");
 
 	Common::Point var4 = getPosFromScript();
 
-	_vm->_soundHandler->contentFct3();
+	_vm->_soundHandler->contentFct3(var4);
 }
 
 void LilliputScript::OC_sub1873F_snd() {
diff --git a/engines/lilliput/sound.cpp b/engines/lilliput/sound.cpp
index c96c05f..d94cf1e 100644
--- a/engines/lilliput/sound.cpp
+++ b/engines/lilliput/sound.cpp
@@ -46,8 +46,8 @@ void LilliputSound::contentFct2(int var1, Common::Point var2, Common::Point var3
 	debugC(1, kDebugSound, "contentFct2(%d, %d - %d, %d - %d, %d - %d)", var1, var2.x, var2.y, var3.x, var3.y, var4.x, var4.y);
 }
 
-void LilliputSound::contentFct3() {
-	debugC(1, kDebugSound, "contentFct3()");
+void LilliputSound::contentFct3(Common::Point pos) {
+	debugC(1, kDebugSound, "contentFct3(%d - %d)", pos.x, pos.y);
 }
 
 void LilliputSound::contentFct4() {
diff --git a/engines/lilliput/sound.h b/engines/lilliput/sound.h
index 756dad1..6d5bf6f 100644
--- a/engines/lilliput/sound.h
+++ b/engines/lilliput/sound.h
@@ -35,7 +35,7 @@ public:
 	void contentFct0();
 	void contentFct1();
 	void contentFct2(int var1, Common::Point var2, Common::Point var3, Common::Point var4);
-	void contentFct3();
+	void contentFct3(Common::Point pos);
 	void contentFct4();
 	void contentFct5();
 	void contentFct6();


Commit: 8ce9bac02aadf45b2b96b05b1b70186ed28e8559
    https://github.com/scummvm/scummvm/commit/8ce9bac02aadf45b2b96b05b1b70186ed28e8559
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Set _shouldQuit in OC_saveAndQUIT and OC_deleteSavegameAndQuit

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 967486e..f885874 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2292,6 +2292,7 @@ void LilliputScript::OC_DisableCharacter() {
 
 void LilliputScript::OC_saveAndQuit() {
 	warning("OC_saveAndQuit");
+    _vm->_shouldQuit = true;
 }
 
 void LilliputScript::OC_sub17B93() {
@@ -2321,6 +2322,7 @@ void LilliputScript::OC_resetByte1714E() {
 
 void LilliputScript::OC_deleteSavegameAndQuit() {
 	warning("OC_deleteSavegameAndQuit");
+    _vm->_shouldQuit = true;
 }
 
 void LilliputScript::OC_incByte16F04() {


Commit: f625b6011700b059b5a4a0155025a7954c352cb6
    https://github.com/scummvm/scummvm/commit/f625b6011700b059b5a4a0155025a7954c352cb6
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Start implementing keyboard handling

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 3af5fdd..6f15d02 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2332,7 +2332,18 @@ void LilliputEngine::pollEvent() {
 		case Common::EVENT_QUIT:
 			_shouldQuit = true;
 			break;
-			// TODO: handle keyboard
+		case Common::EVENT_KEYDOWN: {
+			if (event.kbd == _lastKeyPressed)
+				break;
+
+			_lastKeyPressed = event.kbd;
+			int nextIndex = (_keyboard_nextIndex + 1) % 8;
+			if (_keyboard_oldIndex != nextIndex) {
+				_keyboard_buffer[_keyboard_nextIndex] = event.kbd;
+				_keyboard_nextIndex = nextIndex;
+			}
+			}
+			break;
 		default:
 			break;
 		}
@@ -2808,9 +2819,15 @@ Common::String LilliputEngine::getSavegameFilename(int slot) {
 	return _targetName + Common::String::format("-%02d.SAV", slot);
 }
 
-byte LilliputEngine::_keyboard_getch() {
+Common::KeyState LilliputEngine::_keyboard_getch() {
 	warning("getch()");
-	return ' ';
+	while(_keyboard_nextIndex == _keyboard_oldIndex)
+		pollEvent();
+
+	Common::KeyState tmpEvent = _keyboard_buffer[_keyboard_oldIndex];
+	_keyboard_oldIndex = (_keyboard_oldIndex + 1) % 8;
+
+	return tmpEvent;
 }
 
 } // End of namespace Lilliput
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 1006c34..2aa952b 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -30,6 +30,7 @@
 
 #include "common/file.h"
 #include "common/rect.h"
+#include "common/events.h"
 
 #include "engines/engine.h"
 #include "graphics/palette.h"
@@ -104,9 +105,10 @@ public:
 	byte _animationTick;
 	Common::Point _nextDisplayCharacterPos;
 	byte _sound_byte16F06;
-	byte _lastKeyPressed;
+	Common::KeyState _lastKeyPressed;
 	byte _keyboard_nextIndex;
 	byte _keyboard_oldIndex;
+	Common::KeyState _keyboard_buffer[8];
 	byte _byte12A05;
 	byte _byte12A06;
 	byte _byte12A07;
@@ -359,7 +361,7 @@ public:
 	byte *getCharacterVariablesPtr(int16 index);
 
 	// Temporary stubs
-	byte _keyboard_getch();
+	Common::KeyState _keyboard_getch();
 
 protected:
 	Common::EventManager *_eventMan;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f885874..71396fb 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2059,7 +2059,7 @@ byte LilliputScript::OC_checkKeyPressed() {
 
 	int8 index = (_currScript->readUint16LE() & 0xFF) - 0x30;
 	
-	if (specialKeys[index] == _vm->_lastKeyPressed)
+	if (specialKeys[index] == _vm->_lastKeyPressed.keycode)
 		return 1;
 
 	return 0;
@@ -2292,7 +2292,7 @@ void LilliputScript::OC_DisableCharacter() {
 
 void LilliputScript::OC_saveAndQuit() {
 	warning("OC_saveAndQuit");
-    _vm->_shouldQuit = true;
+	_vm->_shouldQuit = true;
 }
 
 void LilliputScript::OC_sub17B93() {
@@ -2322,7 +2322,7 @@ void LilliputScript::OC_resetByte1714E() {
 
 void LilliputScript::OC_deleteSavegameAndQuit() {
 	warning("OC_deleteSavegameAndQuit");
-    _vm->_shouldQuit = true;
+	_vm->_shouldQuit = true;
 }
 
 void LilliputScript::OC_incByte16F04() {
@@ -3156,11 +3156,12 @@ void LilliputScript::OC_displayTitleScreen() {
 	_vm->_keyboard_oldIndex = 0;
 	//
 	_vm->_mouseButton = 0;
-	_vm->_lastKeyPressed = 0;
+//	_vm->_lastKeyPressed = 0;
 
 	while (!_vm->_shouldQuit) {
 		_vm->displaySmallAnims();
 		_vm->update();
+		_vm->pollEvent();
 		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
 			_vm->_lastKeyPressed = _vm->_keyboard_getch();
 			_vm->_keyboard_getch();


Commit: 147a450834cd4a89b7dcf004eb098ef3558d6b18
    https://github.com/scummvm/scummvm/commit/147a450834cd4a89b7dcf004eb098ef3558d6b18
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in OC_loadFile_AERIAL_GFX, implement OC_waitForEvent

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 6f15d02..7a99fd6 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -124,7 +124,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_savedMousePosDivided = Common::Point(-1, -1);
 	_skipDisplayFlag1 = 1;
 	_skipDisplayFlag2 = 0;
-	_displayMap = 0;
+	_displayMap = false;
 	_debugFlag = 0;
 	_byte14837 = 0;
 
@@ -470,7 +470,7 @@ void LilliputEngine::restoreSurfaceSpeech() {
 void LilliputEngine::displayInterfaceHotspots() {
 	debugC(2, kDebugEngine, "displayInterfaceHotspots()");
 
-	if (_displayMap == 1)
+	if (_displayMap)
 		return;
 
 	restoreSurfaceUnderMousePointer();
@@ -635,7 +635,7 @@ void LilliputEngine::displayIsometricBlock(byte *buf, int var1, int posX, int po
 void LilliputEngine::displayGameArea() {
 	debugC(2, kDebugEngine, "displayGameArea()");
 
-	if (_displayMap == 1)
+	if (_displayMap)
 		return;
 
 	if (_mouseDisplayPos.x > 48)
@@ -797,7 +797,7 @@ void LilliputEngine::prepareGameArea() {
 void LilliputEngine::displayRefreshScreen() {
 	debugC(2, kDebugEngine, "displayRefreshScreen()");
 
-	if (_displayMap == 1) {
+	if (_displayMap) {
 		bool forceReturnFl = false;
 		checkMapClosing(forceReturnFl);
 		if (forceReturnFl)
@@ -999,19 +999,22 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 	debugC(2, kDebugEngineTBC, "checkMapClosing()");
 
 	forceReturnFl = false;
-	if (_displayMap != 1)
+	if (_displayMap)
 		return;
 
 	pollEvent();
-	warning("checkMapClosing- TODO: Check keyboard");
-
-	if ((_mouseButton & 1) == 0)
+	if (_keyboard_checkKeyboard()) {
+		_keyboard_getch();
 		return;
+	} else {
+		if ((_mouseButton & 1) == 0)
+			return;
 
-	_mouseButton = 0;
-	sub15F75();
+		_mouseButton = 0;
+		sub15F75();
+	}
 
-	_displayMap = 0;
+	_displayMap = false;
 	paletteFadeOut();
 	_word15AC2 = 0;
 	unselectInterfaceHotspots();
@@ -2830,4 +2833,12 @@ Common::KeyState LilliputEngine::_keyboard_getch() {
 	return tmpEvent;
 }
 
+bool LilliputEngine::_keyboard_checkKeyboard() {
+	return (_keyboard_nextIndex != _keyboard_oldIndex);
+}
+
+void LilliputEngine::_keyboard_resetKeyboardBuffer() {
+	_keyboard_nextIndex = _keyboard_oldIndex = 0;
+}
+
 } // End of namespace Lilliput
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 2aa952b..5cf5770 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -118,7 +118,6 @@ public:
 	int8 _lastInterfaceHotspotIndex;
 	byte _lastInterfaceHotspotButton; // Unused: set by 2 functions, but never used elsewhere
 	byte _byte16F08;
-	byte _byte15EAD;
 	byte _debugFlag; // Mostly useless, as the associated functions are empty
 	byte _byte14837; // Unused byte, set by an opcode
 
@@ -135,7 +134,7 @@ public:
 
 	bool _saveFlag;
 	bool _int8installed;
-	byte _displayMap;
+	bool _displayMap;
 
 	int _word10800_ERULES;
 	byte _numCharacters;
@@ -362,6 +361,8 @@ public:
 
 	// Temporary stubs
 	Common::KeyState _keyboard_getch();
+	bool _keyboard_checkKeyboard();
+	void _keyboard_resetKeyboardBuffer();
 
 protected:
 	Common::EventManager *_eventMan;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 71396fb..3138779 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -474,7 +474,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setByte14837();
 		break;
 	case 0x4D:
-		OC_sub183A2();
+		OC_waitForEvent();
 		break;
 	case 0x4E:
 		OC_disableInterfaceHotspot();
@@ -686,7 +686,7 @@ static const OpCode opCodes2[] = {
 /* 0x4a */	{ "OC_sub18387", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x4b */	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x4d */	{ "OC_sub183A2", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x4d */	{ "OC_waitForEvent", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4e */	{ "OC_disableInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
 /* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x50 */	{ "OC_sub17E22_speech1IfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -1088,7 +1088,7 @@ void LilliputScript::checkSpeechAllowed(bool &forceReturnFl) {
 	debugC(1, kDebugScript, "checkSpeechAllowed()");
 
 	forceReturnFl = false;
-	if ((_vm->_displayMap != 1) && (_vm->_characterRelativePositionX[_vm->_currentScriptCharacter] != 0xFF))
+	if ((!_vm->_displayMap) && (_vm->_characterRelativePositionX[_vm->_currentScriptCharacter] != 0xFF))
 		return;
 
 	forceReturnFl = true;
@@ -3041,8 +3041,23 @@ void LilliputScript::OC_setByte14837() {
 	_vm->_byte14837 = 1;
 }
 
-void LilliputScript::OC_sub183A2() {
-	warning("OC_sub183A2");
+void LilliputScript::OC_waitForEvent() {
+	debugC(1, kDebugScriptTBC, "OC_waitForEvent()");
+
+	_vm->_refreshScreenFlag = true;
+	while (true) {
+		if (_vm->_keyboard_checkKeyboard()) {
+			_vm->_keyboard_getch();
+			break;;
+		}
+		if (_vm->_mouseButton & 1)
+			break;
+
+		_vm->update();
+	}
+
+	_vm->_mouseButton = 0;
+	_vm->_refreshScreenFlag = false;
 }
 
 void LilliputScript::OC_disableInterfaceHotspot() {
@@ -3059,7 +3074,8 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	debugC(1, kDebugScriptTBC, "OC_loadFile_AERIAL_GFX()");
 	
 	int var1 = _currScript->readUint16LE() & 0xFF;
-	_vm->_byte15EAD = var1;
+//	unused variable
+//	byte _byte15EAD = var1;
 
 	_vm->_refreshScreenFlag = true;
 	_talkingCharacter = -1;
@@ -3069,9 +3085,9 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	OC_PaletteFadeIn();
 
 	_vm->displayCharactersOnMap();
-	_vm->_byte16F08 = 1;
-	_vm->_keyboard_oldIndex = 0;
-	_vm->_keyboard_nextIndex = 0;
+	_vm->_displayMap = true;
+
+	_vm->_keyboard_resetKeyboardBuffer();
 
 	_vm->_refreshScreenFlag = false;
 }
@@ -3105,7 +3121,7 @@ void LilliputScript::OC_displayNumericCharacterVariable() {
 	int posX = _currScript->readSint16LE();
 	int posY = _currScript->readSint16LE();
 
-	if (_vm->_displayMap != 1) {
+	if (!_vm->_displayMap) {
 		_vm->restoreSurfaceUnderMousePointer();
 		displayNumber(displayVal, Common::Point(posX, posY));
 		_vm->displayMousePointer();
@@ -3151,20 +3167,19 @@ void LilliputScript::OC_displayTitleScreen() {
 	_vm->_byte184F4 = (_currScript->readUint16LE() & 0xFF);
 	_vm->_sound_byte16F06 = _vm->_byte184F4;
 
-	// TODO: Rewrite keyboard handling (this code was in a separated function)
-	_vm->_keyboard_nextIndex = 0;
-	_vm->_keyboard_oldIndex = 0;
-	//
+	_vm->_keyboard_resetKeyboardBuffer();
+
 	_vm->_mouseButton = 0;
-//	_vm->_lastKeyPressed = 0;
+	_vm->_lastKeyPressed = Common::KeyState();
 
 	while (!_vm->_shouldQuit) {
 		_vm->displaySmallAnims();
 		_vm->update();
 		_vm->pollEvent();
-		if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
+		if (_vm->_keyboard_checkKeyboard()) {
 			_vm->_lastKeyPressed = _vm->_keyboard_getch();
-			_vm->_keyboard_getch();
+			// Removed: why asking for 2 keystrikes?
+			// _vm->_keyboard_getch();
 			break;
 		}
 		
@@ -3182,7 +3197,7 @@ void LilliputScript::OC_initGameAreaDisplay() {
 	debugC(1, kDebugScript, "OC_initGameAreaDisplay()");
 
 	OC_PaletteFadeOut();
-	_vm->_displayMap = 0;
+	_vm->_displayMap = false;
 	_heroismLevel = 0;
 	_vm->unselectInterfaceHotspots();
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 757ce91..bc5fc97 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -271,7 +271,7 @@ private:
 	void OC_sub18387();
 	void OC_setDebugFlag();
 	void OC_setByte14837();
-	void OC_sub183A2();
+	void OC_waitForEvent();
 	void OC_disableInterfaceHotspot();
 	void OC_loadFile_AERIAL_GFX();
 	void OC_sub17E22_speech1IfSoundOff();


Commit: 747734a6975dcdabb703d994a3210762d733721b
    https://github.com/scummvm/scummvm/commit/747734a6975dcdabb703d994a3210762d733721b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix regression in checkMapClosing, handle properly other languages

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7a99fd6..7191b10 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -999,7 +999,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 	debugC(2, kDebugEngineTBC, "checkMapClosing()");
 
 	forceReturnFl = false;
-	if (_displayMap)
+	if (!_displayMap)
 		return;
 
 	pollEvent();
@@ -2447,8 +2447,25 @@ void LilliputEngine::loadRules() {
 	Common::File f;
 	uint16 curWord;
 
-	if (!f.open("ERULES.PRG"))
-		error("Missing game file ERULES.PRG");
+	Common::String filename = "ERULES.PRG";
+	Common::Language lang = Common::parseLanguage(ConfMan.get("language"));
+
+	switch (lang) {
+	case Common::FR_FRA:
+		filename = "FRULES.PRG";
+		break;
+	case Common::IT_ITA:
+		filename = "IRULES.PRG";
+		break;
+	case Common::DE_DEU:
+		filename = "GRULES.PRG";
+		break;
+	default:
+		warning("unsupported language, switching back to English");
+	}
+
+	if (!f.open(filename))
+		error("Missing game file %s", filename.c_str());
 
 	_word10800_ERULES = f.readUint16LE();
 


Commit: 5f3a3039512c60b6a664c83da03c478d54ffd400
    https://github.com/scummvm/scummvm/commit/5f3a3039512c60b6a664c83da03c478d54ffd400
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Modify mouse handling to stick to original behavior

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7191b10..d0b7701 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -121,7 +121,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_oldMousePos = Common::Point(0, 0);
 	_mouseDisplayPos = Common::Point(0, 0);
 	_mouseButton = 0;
+	_mouseClicked = false;
 	_savedMousePosDivided = Common::Point(-1, -1);
+	_mousePreviousEventType = Common::EVENT_INVALID;
 	_skipDisplayFlag1 = 1;
 	_skipDisplayFlag2 = 0;
 	_displayMap = false;
@@ -1007,7 +1009,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 		_keyboard_getch();
 		return;
 	} else {
-		if ((_mouseButton & 1) == 0)
+		if (_mouseButton != 1)
 			return;
 
 		_mouseButton = 0;
@@ -1879,26 +1881,53 @@ void LilliputEngine::sub12F37() {
 	}
 }
 
+void LilliputEngine::sub13156(bool &forceReturnFl) {
+	debugC(2, kDebugEngine, "sub13156()");
+
+	forceReturnFl = false;
+
+	if (!_keyboard_checkKeyboard())
+		return;
+
+	Common::KeyState state = _keyboard_getch();
+	uint16 var1 = state.ascii;
+	for (int i = 0; i < 20; i++) {
+		warning("%d - 0x%x", i, _rulesBuffer13_4[i]);
+	}
+
+	// TODO: Very incomplete!
+
+	// sub1305C();
+	forceReturnFl = true;
+
+}
+
 void LilliputEngine::sub130EE() {
 	debugC(2, kDebugEngine, "sub130EE()");
 
 //	warning("sub147D7");
-//	warning("sub13156");
-
-	if (_mouseButton == 0)
-		// TODO: check _mouse_clicked
+	bool forceReturnFl = false;
+	sub13156(forceReturnFl);
+	if (forceReturnFl)
 		return;
 
+	if (_mouseButton == 0) {
+		if (!_mouseClicked)
+			return;
+		_mouseClicked = false;
+		_mouseButton = 2;
+	}
+
 	int button = _mouseButton;
 	_mouseButton = 0;
 
-	if (button & 2) {
+	if (button == 2) {
 		if (_lastInterfaceHotspotIndex != -1)
 			sub1305C(_lastInterfaceHotspotIndex, button);
 		return;
 	}
 
-	bool forceReturnFl = false;
+	forceReturnFl = false;
 	checkInterfaceHotspots(forceReturnFl);
 	if (forceReturnFl)
 		return;
@@ -1986,7 +2015,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	_lastInterfaceHotspotIndex = index;
 	_lastInterfaceHotspotButton = button;
 
-	if (button &= 2) {
+	if (button == 2) {
 		if (_byte12FCE != 1) {
 			_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
 			_byte16F07_menuId = 2;
@@ -2323,14 +2352,34 @@ void LilliputEngine::pollEvent() {
 	while (_system->getEventManager()->pollEvent(event)) {
 		switch (event.type) {
 		case Common::EVENT_MOUSEMOVE:
-			_mousePos.x = CLIP<int>(event.mouse.x, 0, 304) + 5;
-			_mousePos.y = CLIP<int>(event.mouse.y, 0, 184) + 1;
-			break;
-		case Common::EVENT_LBUTTONUP:
-			_mouseButton |= 1;
-			break;
-		case Common::EVENT_RBUTTONUP:
-			_mouseButton |= 2;
+		case Common::EVENT_LBUTTONDOWN:
+		case Common::EVENT_LBUTTONUP: {
+			Common::Point newMousePos = Common::Point(CLIP<int>(event.mouse.x, 0, 304), CLIP<int>(event.mouse.y, 0, 184));
+
+			if (_mousePreviousEventType != event.type) {
+				_mousePreviousEventType = event.type;
+				if (_mouseButton != 1) {
+					_mouseButton = 2;
+					if (event.type != Common::EVENT_MOUSEMOVE) {
+						_mouseButton = 1;
+						_mousePos = Common::Point(newMousePos.x + 5, newMousePos.y + 1);
+					}
+				} else {
+					_mouseClicked = true;
+				}
+			}
+
+			if (newMousePos != _oldMousePos) {
+				_oldMousePos = newMousePos;
+				if (_skipDisplayFlag1 != 0) {
+					restoreSurfaceUnderMousePointer();
+					_mouseDisplayPos = newMousePos;
+					displayMousePointer();
+				} else {
+					_mouseDisplayPos = newMousePos;
+				}
+			}
+			}
 			break;
 		case Common::EVENT_QUIT:
 			_shouldQuit = true;
@@ -2351,17 +2400,6 @@ void LilliputEngine::pollEvent() {
 			break;
 		}
 	}
-
-	if (_mousePos != _oldMousePos) {
-		_oldMousePos = _mousePos;
-		if (_skipDisplayFlag1 != 0) {
-			restoreSurfaceUnderMousePointer();
-			_mouseDisplayPos = _mousePos;
-			displayMousePointer();
-		} else {
-			_mouseDisplayPos = _mousePos;
-		}
-	}
 }
 
 byte *LilliputEngine::loadVGA(Common::String filename, int expectedSize, bool loadPal) {
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 5cf5770..d1878e8 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -272,6 +272,7 @@ public:
 
 	void renderCharacters(byte *buf, Common::Point pos);
 
+	void sub13156(bool &forceReturnFl);
 	byte sub16799(int index, Common::Point param1);
 	byte getDirection(Common::Point param1, Common::Point param2);
 	void addCharToBuf(byte character);
@@ -337,6 +338,8 @@ public:
 	Common::Point _oldMousePos;
 	Common::Point _mouseDisplayPos;
 	int _mouseButton;
+	bool _mouseClicked;
+	Common::EventType _mousePreviousEventType;
 	Common::Point _savedMousePosDivided;
 	int _skipDisplayFlag1;
 	int _skipDisplayFlag2;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 3138779..42679b0 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -3050,7 +3050,7 @@ void LilliputScript::OC_waitForEvent() {
 			_vm->_keyboard_getch();
 			break;;
 		}
-		if (_vm->_mouseButton & 1)
+		if (_vm->_mouseButton == 1)
 			break;
 
 		_vm->update();
@@ -3183,7 +3183,7 @@ void LilliputScript::OC_displayTitleScreen() {
 			break;
 		}
 		
-		if (_vm->_mouseButton & 1)
+		if (_vm->_mouseButton == 1)
 			break;
 		
 		if ((_vm->_byte184F4 != 0) && (_vm->_sound_byte16F06 == 0))


Commit: de94c907208c61ea33495ad56f9760425af742bf
    https://github.com/scummvm/scummvm/commit/de94c907208c61ea33495ad56f9760425af742bf
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Improve keyboard handling. F keys are now working in the menu

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index d0b7701..88f0e57 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -134,7 +134,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_soundHandler = new LilliputSound(this);
 
 	_byte1714E = 0;
-	_byte12FCE = 0;
+	_byte12FCE = false;
 	_byte129A0 = -1;
 	_numCharactersToDisplay = 0;
 	_nextDisplayCharacterPos = Common::Point(0, 0);
@@ -1889,10 +1889,10 @@ void LilliputEngine::sub13156(bool &forceReturnFl) {
 	if (!_keyboard_checkKeyboard())
 		return;
 
-	Common::KeyState state = _keyboard_getch();
-	uint16 var1 = state.ascii;
+	Common::Event event = _keyboard_getch();
+	uint16 var1 = event.kbd.ascii;
 	for (int i = 0; i < 20; i++) {
-		warning("%d - 0x%x", i, _rulesBuffer13_4[i]);
+		warning("%d - 0x%x", i, _keyboardMapping[i]);
 	}
 
 	// TODO: Very incomplete!
@@ -1902,10 +1902,68 @@ void LilliputEngine::sub13156(bool &forceReturnFl) {
 
 }
 
+void LilliputEngine::sub147D7() {
+	debugC(2, kDebugEngine, "sub147D7()");
+
+	static bool altKeyFl = false;
+	static int16 keyCount = 0;
+
+	if (_keyboard_oldIndex == _keyboard_nextIndex)
+		return;
+
+	Common::Event oldEvent = _keyboard_buffer[_keyboard_oldIndex];
+	if ((oldEvent.kbd.keycode == Common::KEYCODE_LALT) || (oldEvent.kbd.keycode == Common::KEYCODE_RALT)) {
+		if (oldEvent.type == Common::EVENT_KEYDOWN) {
+			altKeyFl = true;
+			keyCount = 0;
+			return;
+		} else if (oldEvent.type == Common::EVENT_KEYUP) {
+			altKeyFl = false;
+			if (keyCount == 3)
+				_byte16F07_menuId = 6;
+			return;
+		}
+	}
+
+	if (keyCount >= 3)
+		return;
+
+	if ((altKeyFl) && (oldEvent.type == Common::EVENT_KEYDOWN)) {
+		switch (oldEvent.kbd.keycode) {
+		case Common::KEYCODE_KP0:
+		case Common::KEYCODE_KP1:
+		case Common::KEYCODE_KP2:
+		case Common::KEYCODE_KP3:
+		case Common::KEYCODE_KP4:
+		case Common::KEYCODE_KP5:
+		case Common::KEYCODE_KP6:
+		case Common::KEYCODE_KP7:
+		case Common::KEYCODE_KP8:
+		case Common::KEYCODE_KP9:
+		case Common::KEYCODE_0:
+		case Common::KEYCODE_1:
+		case Common::KEYCODE_2:
+		case Common::KEYCODE_3:
+		case Common::KEYCODE_4:
+		case Common::KEYCODE_5:
+		case Common::KEYCODE_6:
+		case Common::KEYCODE_7:
+		case Common::KEYCODE_8:
+		case Common::KEYCODE_9:
+			_array147D1[keyCount] = oldEvent.kbd.keycode - Common::KEYCODE_0;
+			++keyCount;
+			break;
+		default:
+			break;
+		}
+	}
+}
+
 void LilliputEngine::sub130EE() {
 	debugC(2, kDebugEngine, "sub130EE()");
 
-//	warning("sub147D7");
+	sub147D7();
+
 	bool forceReturnFl = false;
 	sub13156(forceReturnFl);
 	if (forceReturnFl)
@@ -1974,7 +2032,7 @@ void LilliputEngine::sub131B2(Common::Point pos, bool &forceReturnFl) {
 		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_byte129A0 = i;
 			_byte16F07_menuId = 4;
-			if (_byte12FCE == 1)
+			if (_byte12FCE)
 				_byte16F07_menuId = 3;
 
 			return;
@@ -2016,7 +2074,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	_lastInterfaceHotspotButton = button;
 
 	if (button == 2) {
-		if (_byte12FCE != 1) {
+		if (!_byte12FCE) {
 			_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
 			_byte16F07_menuId = 2;
 			displayInterfaceHotspots();
@@ -2024,7 +2082,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 		return;
 	}
 
-	if (_byte12FCE == 1) {
+	if (_byte12FCE) {
 		unselectInterfaceButton();
 		return;
 	}
@@ -2032,7 +2090,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	unselectInterfaceHotspots();
 	_scriptHandler->_interfaceHotspotStatus[index] = kHotspotSelected;
 	if (_rulesBuffer13_1[index] == 1) {
-		_byte12FCE = 1;
+		_byte12FCE = true;
 		_word15AC2 = 1;
 	} else {
 		_byte16F07_menuId = 1;
@@ -2379,21 +2437,25 @@ void LilliputEngine::pollEvent() {
 					_mouseDisplayPos = newMousePos;
 				}
 			}
+			_lastEventType = event.type;
 			}
 			break;
 		case Common::EVENT_QUIT:
 			_shouldQuit = true;
 			break;
+		case Common::EVENT_KEYUP:
 		case Common::EVENT_KEYDOWN: {
-			if (event.kbd == _lastKeyPressed)
+			if ((event.type == _lastKeyPressed.type) && (event.kbd == _lastKeyPressed.kbd))
 				break;
 
-			_lastKeyPressed = event.kbd;
+			_lastKeyPressed = event;
 			int nextIndex = (_keyboard_nextIndex + 1) % 8;
 			if (_keyboard_oldIndex != nextIndex) {
-				_keyboard_buffer[_keyboard_nextIndex] = event.kbd;
+				_keyboard_buffer[_keyboard_nextIndex] = event;
 				_keyboard_nextIndex = nextIndex;
 			}
+
+			_lastEventType = event.type;
 			}
 			break;
 		default:
@@ -2639,18 +2701,18 @@ void LilliputEngine::loadRules() {
 		byte curByte = f.readByte();
 
 		if (curByte == 0x20)
-			_rulesBuffer13_4[i] = 0x39;
+			_keyboardMapping[i] = 0x39;
 		else if (curByte == 0xD)
-			_rulesBuffer13_4[i] = 0x1C;
+			_keyboardMapping[i] = 0x1C;
 		// Hack to avoid xlat out of bounds
 		else if (curByte == 0xFF)
-			_rulesBuffer13_4[i] = 0x21;
+			_keyboardMapping[i] = 0x21;
 		// Hack to avoid xlat out of bounds
 		else if (curByte == 0x00)
-			_rulesBuffer13_4[i] = 0xB4;
+			_keyboardMapping[i] = 0xB4;
 		else {
 			assert((curByte > 0x40) && (curByte <= 0x41 + 26));
-			_rulesBuffer13_4[i] = _rulesXlatArray[curByte - 0x41];
+			_keyboardMapping[i] = _rulesXlatArray[curByte - 0x41];
 		}
 	}
 	f.close();
@@ -2712,7 +2774,7 @@ void LilliputEngine::setCurrentCharacter(int index) {
 void LilliputEngine::unselectInterfaceButton() {
 	debugC(1, kDebugEngine, "unselectInterfaceButton()");
 
-	_byte12FCE = 0;
+	_byte12FCE = false;
 	_word15AC2 = 0;
 	_lastInterfaceHotspotButton = 0;
 	unselectInterfaceHotspots();
@@ -2725,7 +2787,7 @@ void LilliputEngine::handleMenu() {
 	if (_byte16F07_menuId == 0)
 		return;
 
-	if ((_byte12FCE == 1) && (_byte16F07_menuId != 3))
+	if (_byte12FCE && (_byte16F07_menuId != 3))
 		return;
 
 	setCurrentCharacter(_word10804);
@@ -2877,12 +2939,12 @@ Common::String LilliputEngine::getSavegameFilename(int slot) {
 	return _targetName + Common::String::format("-%02d.SAV", slot);
 }
 
-Common::KeyState LilliputEngine::_keyboard_getch() {
+Common::Event LilliputEngine::_keyboard_getch() {
 	warning("getch()");
 	while(_keyboard_nextIndex == _keyboard_oldIndex)
 		pollEvent();
 
-	Common::KeyState tmpEvent = _keyboard_buffer[_keyboard_oldIndex];
+	Common::Event tmpEvent = _keyboard_buffer[_keyboard_oldIndex];
 	_keyboard_oldIndex = (_keyboard_oldIndex + 1) % 8;
 
 	return tmpEvent;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index d1878e8..74f66ac 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -105,10 +105,11 @@ public:
 	byte _animationTick;
 	Common::Point _nextDisplayCharacterPos;
 	byte _sound_byte16F06;
-	Common::KeyState _lastKeyPressed;
+	Common::Event _lastKeyPressed;
+	Common::EventType _lastEventType;
 	byte _keyboard_nextIndex;
 	byte _keyboard_oldIndex;
-	Common::KeyState _keyboard_buffer[8];
+	Common::Event _keyboard_buffer[8];
 	byte _byte12A05;
 	byte _byte12A06;
 	byte _byte12A07;
@@ -197,7 +198,7 @@ public:
 	byte _rulesBuffer13_1[20];
 	int16 _interfaceHotspotsX[20];
 	int16 _interfaceHotspotsY[20];
-	byte _rulesBuffer13_4[20];
+	byte _keyboardMapping[20];
 	int16 _array10999PosX[40];
 	int16 _array109C1PosY[40];
 	byte _savedSurfaceUnderMouse[16 * 16];
@@ -272,6 +273,7 @@ public:
 
 	void renderCharacters(byte *buf, Common::Point pos);
 
+	void sub147D7();
 	void sub13156(bool &forceReturnFl);
 	byte sub16799(int index, Common::Point param1);
 	byte getDirection(Common::Point param1, Common::Point param2);
@@ -345,7 +347,7 @@ public:
 	int _skipDisplayFlag2;
 
 	byte _byte16F07_menuId;
-	byte _byte12FCE;
+	bool _byte12FCE;
 	int8 _byte129A0;
 	byte _numCharactersToDisplay;
 	byte _byte16C9F;
@@ -363,7 +365,7 @@ public:
 	byte *getCharacterVariablesPtr(int16 index);
 
 	// Temporary stubs
-	Common::KeyState _keyboard_getch();
+	Common::Event _keyboard_getch();
 	bool _keyboard_checkKeyboard();
 	void _keyboard_resetKeyboardBuffer();
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 42679b0..aff323b 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2036,7 +2036,7 @@ byte LilliputScript::OC_checkSavedMousePos() {
 byte LilliputScript::OC_sub179AE() {
 	debugC(1, kDebugScript, "OC_sub179AE()");
 
-	if ((_vm->_byte12FCE == 1) || (_vm->_byte129A0 == -1))
+	if (_vm->_byte12FCE || (_vm->_byte129A0 == -1))
 		return 0;
 
 	return 1;
@@ -2055,11 +2055,13 @@ byte LilliputScript::OC_sub179C2() {
 byte LilliputScript::OC_checkKeyPressed() {
 	debugC(1, kDebugScript, "OC_checkKeyPressed()");
 
-	static const byte specialKeys[10] = {0x44, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43};
+	static const Common::KeyCode specialKeys[10] = {
+		Common::KEYCODE_F10, Common::KEYCODE_F1, Common::KEYCODE_F2, Common::KEYCODE_F3, Common::KEYCODE_F4,
+		Common::KEYCODE_F5,  Common::KEYCODE_F6, Common::KEYCODE_F7, Common::KEYCODE_F8, Common::KEYCODE_F9};
 
 	int8 index = (_currScript->readUint16LE() & 0xFF) - 0x30;
 	
-	if (specialKeys[index] == _vm->_lastKeyPressed.keycode)
+	if (specialKeys[index] == _vm->_lastKeyPressed.kbd.keycode)
 		return 1;
 
 	return 0;
@@ -3170,16 +3172,17 @@ void LilliputScript::OC_displayTitleScreen() {
 	_vm->_keyboard_resetKeyboardBuffer();
 
 	_vm->_mouseButton = 0;
-	_vm->_lastKeyPressed = Common::KeyState();
+	_vm->_lastKeyPressed = Common::Event();
 
 	while (!_vm->_shouldQuit) {
 		_vm->displaySmallAnims();
 		_vm->update();
 		_vm->pollEvent();
 		if (_vm->_keyboard_checkKeyboard()) {
-			_vm->_lastKeyPressed = _vm->_keyboard_getch();
-			// Removed: why asking for 2 keystrikes?
-			// _vm->_keyboard_getch();
+			Common::Event event = _vm->_keyboard_getch();
+			_vm->_lastKeyPressed = event;
+			if (event.type == Common::EVENT_KEYDOWN)
+				_vm->_keyboard_getch();
 			break;
 		}
 		


Commit: 4dda4abbea3c0bf2236625bbfeff7bb62f202ede
    https://github.com/scummvm/scummvm/commit/4dda4abbea3c0bf2236625bbfeff7bb62f202ede
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: rename OC_checkFunctionKeyPressed

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index aff323b..5020f3c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -225,7 +225,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_sub179C2();
 		break;
 	case 0x2F:
-		return OC_checkKeyPressed();
+		return OC_checkFunctionKeyPressed();
 		break;
 	case 0x30:
 		return OC_sub17A07();
@@ -602,7 +602,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_checkSavedMousePos", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179AE", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
-	{ "OC_checkKeyPressed", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_checkFunctionKeyPressed", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17A07", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
 	{ "OC_checkViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
 };
@@ -2052,8 +2052,8 @@ byte LilliputScript::OC_sub179C2() {
 
 	return 0;
 }
-byte LilliputScript::OC_checkKeyPressed() {
-	debugC(1, kDebugScript, "OC_checkKeyPressed()");
+byte LilliputScript::OC_checkFunctionKeyPressed() {
+	debugC(1, kDebugScript, "OC_checkFunctionKeyPressed()");
 
 	static const Common::KeyCode specialKeys[10] = {
 		Common::KEYCODE_F10, Common::KEYCODE_F1, Common::KEYCODE_F2, Common::KEYCODE_F3, Common::KEYCODE_F4,
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index bc5fc97..bc7fb15 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -188,7 +188,7 @@ private:
 	byte OC_checkSavedMousePos();
 	byte OC_sub179AE();
 	byte OC_sub179C2();
-	byte OC_checkKeyPressed();
+	byte OC_checkFunctionKeyPressed();
 	byte OC_sub17A07();
 	byte OC_checkViewPortCharacterTarget();
 


Commit: 5964316074d162f0cc1b36537d138d804dcf8391
    https://github.com/scummvm/scummvm/commit/5964316074d162f0cc1b36537d138d804dcf8391
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Finish the implementation of sub13156, fix keyboard mapping

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 88f0e57..442faff 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1890,16 +1890,22 @@ void LilliputEngine::sub13156(bool &forceReturnFl) {
 		return;
 
 	Common::Event event = _keyboard_getch();
-	uint16 var1 = event.kbd.ascii;
-	for (int i = 0; i < 20; i++) {
-		warning("%d - 0x%x", i, _keyboardMapping[i]);
-	}
 
-	// TODO: Very incomplete!
-
-	// sub1305C();
-	forceReturnFl = true;
+	int8 index = -1;
+	for (int8 i = 0; i < _interfaceHotspotNumb; i++) {
+		if (event.kbd.keycode == _keyboardMapping[i]) {
+			index = i;
+			break;
+		}
+	}
 
+	if (index != -1) {
+		byte button = 1;
+		if (event.type == Common::EVENT_KEYUP)
+			button = 2;
+		sub1305C(index, button);
+		forceReturnFl = true;
+	}
 }
 
 void LilliputEngine::sub147D7() {
@@ -2543,7 +2549,14 @@ byte *LilliputEngine::loadRaw(Common::String filename, int filesize) {
 void LilliputEngine::loadRules() {
 	debugC(1, kDebugEngine, "loadRules()");
 
-	static const byte _rulesXlatArray[26] = {30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44};
+//	static const byte _rulesXlatArray[26] = {30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44};
+	static const Common::KeyCode _rulesXlatArray[26] = {
+		Common::KEYCODE_a, Common::KEYCODE_b, Common::KEYCODE_c, Common::KEYCODE_d, Common::KEYCODE_e,
+		Common::KEYCODE_f, Common::KEYCODE_g, Common::KEYCODE_h, Common::KEYCODE_i, Common::KEYCODE_j,
+		Common::KEYCODE_k, Common::KEYCODE_l, Common::KEYCODE_m, Common::KEYCODE_n, Common::KEYCODE_o, 
+		Common::KEYCODE_p, Common::KEYCODE_q, Common::KEYCODE_r, Common::KEYCODE_s, Common::KEYCODE_t,
+		Common::KEYCODE_u, Common::KEYCODE_v, Common::KEYCODE_w, Common::KEYCODE_x, Common::KEYCODE_y, 
+		Common::KEYCODE_z};
 	Common::File f;
 	uint16 curWord;
 
@@ -2701,15 +2714,15 @@ void LilliputEngine::loadRules() {
 		byte curByte = f.readByte();
 
 		if (curByte == 0x20)
-			_keyboardMapping[i] = 0x39;
+			_keyboardMapping[i] = Common::KEYCODE_SPACE;
 		else if (curByte == 0xD)
-			_keyboardMapping[i] = 0x1C;
+			_keyboardMapping[i] = Common::KEYCODE_RETURN;
 		// Hack to avoid xlat out of bounds
 		else if (curByte == 0xFF)
-			_keyboardMapping[i] = 0x21;
+			_keyboardMapping[i] = Common::KEYCODE_INVALID; // 0x21; ?
 		// Hack to avoid xlat out of bounds
 		else if (curByte == 0x00)
-			_keyboardMapping[i] = 0xB4;
+			_keyboardMapping[i] = Common::KEYCODE_INVALID; // 0xB4; ?
 		else {
 			assert((curByte > 0x40) && (curByte <= 0x41 + 26));
 			_keyboardMapping[i] = _rulesXlatArray[curByte - 0x41];
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 74f66ac..81a3a62 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -198,7 +198,7 @@ public:
 	byte _rulesBuffer13_1[20];
 	int16 _interfaceHotspotsX[20];
 	int16 _interfaceHotspotsY[20];
-	byte _keyboardMapping[20];
+	Common::KeyCode _keyboardMapping[20];
 	int16 _array10999PosX[40];
 	int16 _array109C1PosY[40];
 	byte _savedSurfaceUnderMouse[16 * 16];


Commit: a56a10d6eac570f819b90d4a5eabf44218ac225e
    https://github.com/scummvm/scummvm/commit/a56a10d6eac570f819b90d4a5eabf44218ac225e
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Silent warning in language check

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 442faff..5b6f6a5 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2564,6 +2564,8 @@ void LilliputEngine::loadRules() {
 	Common::Language lang = Common::parseLanguage(ConfMan.get("language"));
 
 	switch (lang) {
+	case Common::EN_ANY:
+		break;
 	case Common::FR_FRA:
 		filename = "FRULES.PRG";
 		break;


Commit: fe906b9dad83896ba856412c5e6a0d6242aaed57
    https://github.com/scummvm/scummvm/commit/fe906b9dad83896ba856412c5e6a0d6242aaed57
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Add a couple of hacks to avoid working on disabled character

This silents the two warnings reported by Valgrind

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 5b6f6a5..e317cec 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -148,7 +148,6 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_lastInterfaceHotspotIndex = -1;
 	_lastInterfaceHotspotButton = 0;
 	_byte16F08 = 0;
-	_byte16C9F = 0;
 	_lastAnimationTick = 0;
 
 	_currentScriptCharacter = 0;
@@ -907,8 +906,8 @@ void LilliputEngine::paletteFadeIn() {
 int16 LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 	debugC(2, kDebugEngine, "sub16DD5(%d, %d, %d, %d)", x1, y1, x2, y2);
 
-	int index = (y1 * 64 + x1) * 4;
-	assert(index <= 16380);
+	int index = ((y1 * 64) + x1) * 4;
+	assert((index > 0) && (index <= 16380));
 	byte *isoMap = &_bufferIsoMap[index + 1];
 
 	int16 dx = x2 - x1;
@@ -1037,8 +1036,13 @@ void LilliputEngine::sub16CA0() {
 		int c1 = _scriptHandler->_array16123PosX[index];
 		int c2 = _scriptHandler->_array1614BPosY[index];
 
+		// Hack: Skip if disabled (c2 negative)
+		if (c2 == -1)
+			continue;
+		//
+
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
-			_byte16C9F = 0;
+			byte byte16C9F = 0;
 			if ((index != index2) &&
 			        (_rulesBuffer2_5[index] != index2) &&
 			        (_rulesBuffer2_5[index2] != index) &&
@@ -1051,56 +1055,56 @@ void LilliputEngine::sub16CA0() {
 					if ((x > -6) && (x < 6)) {
 						int y = c2 - d2;
 						if ((y > -6) && (y < 6)) {
-							_byte16C9F = 1;
+							byte16C9F = 1;
 
 							if ((c1 == d1) && (c2 == d2)) {
-								_byte16C9F = 4;
+								byte16C9F = 4;
 							} else if ((_rulesBuffer2_11[index] & 4) != 0) {
-								_byte16C9F = 0;
+								byte16C9F = 0;
 							} else {
 								switch (_characterDirectionArray[index]) {
 								case 0:
 									if (d1 > c1) {
-										_byte16C9F = 2;
+										byte16C9F = 2;
 
 										if (d2 == c2)
-											_byte16C9F = 3;
+											byte16C9F = 3;
 
 										if (sub16DD5(c1, c2, d1, d2) != 0)
-											_byte16C9F = 1;
+											byte16C9F = 1;
 									}
 									break;
 								case 1:
 									if (d2 < c2) {
-										_byte16C9F = 2;
+										byte16C9F = 2;
 
 										if (d1 == c1)
-											_byte16C9F = 3;
+											byte16C9F = 3;
 
 										if (sub16DD5(c1, c2, d1, d2) != 0)
-											_byte16C9F = 1;
+											byte16C9F = 1;
 									}
 									break;
 								case 2:
 									if (d2 > c2) {
-										_byte16C9F = 2;
+										byte16C9F = 2;
 
 										if (d1 == c1)
-											_byte16C9F = 3;
+											byte16C9F = 3;
 
 										if (sub16DD5(c1, c2, d1, d2) != 0)
-											_byte16C9F = 1;
+											byte16C9F = 1;
 									}
 									break;
 								default:
 									if (d1 < c1) {
-										_byte16C9F = 2;
+										byte16C9F = 2;
 
 										if (d2 == c2)
-											_byte16C9F = 3;
+											byte16C9F = 3;
 
 										if (sub16DD5(c1, c2, d1, d2) != 0)
-											_byte16C9F = 1;
+											byte16C9F = 1;
 									}
 									break;
 								}
@@ -1113,9 +1117,9 @@ void LilliputEngine::sub16CA0() {
 			int8 v2 = _scriptHandler->_array10B51[index2 + (index * 40)] & 0xFF;
 			int8 v1 = v2;
 
-			if (v2 != _byte16C9F) {
+			if (v2 != byte16C9F) {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
-				v2 =  _byte16C9F;
+				v2 =  byte16C9F;
 			}
 			_scriptHandler->_array10B51[index2 + (index * 40)] = (v1 << 8) + v2;
 		}
@@ -1845,11 +1849,16 @@ void LilliputEngine::sub16EBC() {
 	debugC(2, kDebugEngine, "sub16EBC()");
 
 	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
-		int mapIndex = (_scriptHandler->_array1614BPosY[index1] * 64 + _scriptHandler->_array16123PosX[index1]) * 4;
-		assert(mapIndex < 16384);
-		byte var1 = _bufferIsoMap[mapIndex + 3];
+		// Hack: The original doesn't check if it's disabled, which looks wrong
+		if (_scriptHandler->_array1614BPosY[index1] == -1)
+			continue;
+		//
+
+		int mapIndex = 3 + (_scriptHandler->_array1614BPosY[index1] * 64 + _scriptHandler->_array16123PosX[index1]) * 4;
+		assert((mapIndex >= 0) && (mapIndex < 16384));
+		byte var1 = _bufferIsoMap[mapIndex] & 0x40;
 
-		if ((var1 & 0x40) == _array16E94[index1])
+		if (var1 == _array16E94[index1])
 			continue;
 
 		_array16E94[index1] = var1;
@@ -2549,7 +2558,6 @@ byte *LilliputEngine::loadRaw(Common::String filename, int filesize) {
 void LilliputEngine::loadRules() {
 	debugC(1, kDebugEngine, "loadRules()");
 
-//	static const byte _rulesXlatArray[26] = {30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44};
 	static const Common::KeyCode _rulesXlatArray[26] = {
 		Common::KEYCODE_a, Common::KEYCODE_b, Common::KEYCODE_c, Common::KEYCODE_d, Common::KEYCODE_e,
 		Common::KEYCODE_f, Common::KEYCODE_g, Common::KEYCODE_h, Common::KEYCODE_i, Common::KEYCODE_j,
@@ -2592,7 +2600,7 @@ void LilliputEngine::loadRules() {
 
 	// Chunk 2
 	_numCharacters = (f.readUint16LE() & 0xFF);
-	assert((_numCharacters > 0) && (_numCharacters <= 40));
+	assert(_numCharacters <= 40);
 
 	for (int i = _numCharacters, j = 0; i != 0; i--, j++) {
 		curWord = f.readUint16LE();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 81a3a62..02ed0c6 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -350,7 +350,6 @@ public:
 	bool _byte12FCE;
 	int8 _byte129A0;
 	byte _numCharactersToDisplay;
-	byte _byte16C9F;
 	int16 _word10804;
 	bool _shouldQuit;
 


Commit: 686b59e53e6f2c39647e2967b7398d5d41ad6e41
    https://github.com/scummvm/scummvm/commit/686b59e53e6f2c39647e2967b7398d5d41ad6e41
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement OC_sub18260

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 5020f3c..2b54e20 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -49,6 +49,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_array129A5[2] = 2;
 	_array129A5[3] = 3;
 	_savedBuffer215Ptr = NULL;
+	_word1825E = Common::Point(0, 0);
 
 	for (int i = 0; i < 20; i++) {
 		_interfaceHotspotStatus[i] = kHotspotOff;
@@ -2940,7 +2941,36 @@ void LilliputScript::OC_sub18252() {
 }
 
 void LilliputScript::OC_sub18260() {
-	warning("OC_sub18260()");
+	debugC(1, kDebugScriptTBC, "OC_sub18260()");
+	
+	int index = getValue1();
+	Common::Point var4 = getPosFromScript();
+
+	Common::Point pt = var4 + _viewportPos;
+	byte *isoMapBuf = getMapPtr(pt);
+
+	if (isoMapBuf[1] != 0xFF) {
+		int byte1825D = 255;
+		for (int var2 = 7; var2 >= 0; var2--) {
+			for (int var3 = 7; var3 >= 0; var3--) {
+				Common::Point(_viewportPos.x + var2, _viewportPos.y + var3);
+				isoMapBuf = getMapPtr(pt);
+
+				if (isoMapBuf[1] == 0xFF) {
+					int x = abs(var2 - var4.x);
+					int y = abs(var3 - var4.y);
+					if (x + y < byte1825D) {
+						byte1825D = x + y;
+						_word1825E = Common::Point(var2, var3);
+					}
+				}
+			}
+		}
+		var4 = _word1825E;
+	}
+
+	_vm->_characterPositionX[index] = (var4.x + _viewportPos.x) * 8;
+	_vm->_characterPositionY[index] = (var4.y + _viewportPos.y) * 8;
 }
 
 void LilliputScript::OC_CharacterVariableAddOrRemoveFlag() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index bc7fb15..96bd837 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -109,6 +109,7 @@ private:
 	int _currentSpeechId;
 	int _word18821;
 	int _word129A3;
+	Common::Point _word1825E;
 
 	char _array129A5[4];
 


Commit: 7084803a7a7d16cd8e9027a59d67447806f0911b
    https://github.com/scummvm/scummvm/commit/7084803a7a7d16cd8e9027a59d67447806f0911b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Implement OC_sub17E22_speech1IfSoundOff, silent warnings in OC_loadFile_AERIAL_GFX

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 2b54e20..e3fd70a 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -3105,9 +3105,11 @@ void LilliputScript::OC_disableInterfaceHotspot() {
 void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	debugC(1, kDebugScriptTBC, "OC_loadFile_AERIAL_GFX()");
 	
-	int var1 = _currScript->readUint16LE() & 0xFF;
-//	unused variable
+//	Unused variable
+//	int var1 = _currScript->readUint16LE() & 0xFF;
 //	byte _byte15EAD = var1;
+	_currScript->readUint16LE();
+//
 
 	_vm->_refreshScreenFlag = true;
 	_talkingCharacter = -1;
@@ -3125,7 +3127,12 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 }
 
 void LilliputScript::OC_sub17E22_speech1IfSoundOff() {
-	warning("OC_sub17E22_speech1IfSoundOff");
+	debugC(1, kDebugScriptTBC, "OC_sub17E22_speech1IfSoundOff()");
+
+	// HACK: In the original, OC_sub17E22_speech1IfSoundOff() only calls 
+	// OC_startSpeech if sound is off. For the moment, it's always called
+
+	OC_startSpeech();
 }
 
 void LilliputScript::OC_sub1844A() {


Commit: e70d3c4979ac6c87a88b259bddfc134da92b4d6b
    https://github.com/scummvm/scummvm/commit/e70d3c4979ac6c87a88b259bddfc134da92b4d6b
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix display of variable speeches

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index e3fd70a..58e96a0 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1261,12 +1261,13 @@ void LilliputScript::startSpeech(int speechId) {
 
 	int i = 0;
 	if (count != 0) {
-		int tmpVal = _vm->_rnd->getRandomNumber(count + 1);
+		int tmpVal = _vm->_rnd->getRandomNumber(count);
 		if (tmpVal != 0) {
 			for (int j = 0; j < tmpVal; j++) {
 				do
 					++i;
 				while (_vm->_packedStrings[index + count + i] != ']');
+				++i;
 			}
 		}
 	}


Commit: 479eaaaa9e354ff7f84599ea8ff44250e6bc4feb
    https://github.com/scummvm/scummvm/commit/479eaaaa9e354ff7f84599ea8ff44250e6bc4feb
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix walking on click

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index e317cec..7bec9ba 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2050,11 +2050,10 @@ void LilliputEngine::sub131B2(Common::Point pos, bool &forceReturnFl) {
 			if (_byte12FCE)
 				_byte16F07_menuId = 3;
 
+			forceReturnFl = true;
 			return;
 		}
 	}
-	forceReturnFl = true;
-	return;
 }
 
 void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {


Commit: f03571ccb1bd3b61eca01ef06680e8315179826b
    https://github.com/scummvm/scummvm/commit/f03571ccb1bd3b61eca01ef06680e8315179826b
Author: sylvaintv (sylvaintv at gmail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bad opcode definition for display aerial map

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 58e96a0..f8c3dc0 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -689,7 +689,7 @@ static const OpCode opCodes2[] = {
 /* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4d */	{ "OC_waitForEvent", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4e */	{ "OC_disableInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
-/* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x50 */	{ "OC_sub17E22_speech1IfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x52 */	{ "OC_displayNumericCharacterVariable", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
@@ -3109,7 +3109,7 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 //	Unused variable
 //	int var1 = _currScript->readUint16LE() & 0xFF;
 //	byte _byte15EAD = var1;
-	_currScript->readUint16LE();
+//	_currScript->readUint16LE();   // di is restored afterwards so do nothing
 //
 
 	_vm->_refreshScreenFlag = true;


Commit: 653c27f93016bc150ccfbfd0bafdcb649e32df74
    https://github.com/scummvm/scummvm/commit/653c27f93016bc150ccfbfd0bafdcb649e32df74
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Cleanup of previous fix, add TODO comment

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f8c3dc0..5505645 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -3105,12 +3105,11 @@ void LilliputScript::OC_disableInterfaceHotspot() {
 
 void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	debugC(1, kDebugScriptTBC, "OC_loadFile_AERIAL_GFX()");
-	
-//	Unused variable
-//	int var1 = _currScript->readUint16LE() & 0xFF;
-//	byte _byte15EAD = var1;
-//	_currScript->readUint16LE();   // di is restored afterwards so do nothing
-//
+
+	// Unused variable, and the script position is restored afterwards
+	// TODO: Check if this part of the code is present in Rome, else remove it
+	// int var1 = _currScript->readUint16LE() & 0xFF;
+	// byte _byte15EAD = var1;
 
 	_vm->_refreshScreenFlag = true;
 	_talkingCharacter = -1;


Commit: e6dce6ed8ae860e0fb75811640272da78dc394cf
    https://github.com/scummvm/scummvm/commit/e6dce6ed8ae860e0fb75811640272da78dc394cf
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix name of OC_changeCurrentCharacterSprite in script decompiler

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 5505645..72d1306 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -650,7 +650,7 @@ static const OpCode opCodes2[] = {
 /* 0x25 */	{ "OC_IncCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone }, 
 /* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x28 */	{ "OC_sub17E7E", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x28 */	{ "OC_changeCurrentCharacterSprite", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x29 */	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
 /* 0x2b */	{ "OC_setCharacterDirectionTowardsPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 


Commit: 7e55ed492c5313edc7b2a39b36ee495e5a23f34d
    https://github.com/scummvm/scummvm/commit/7e55ed492c5313edc7b2a39b36ee495e5a23f34d
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7bec9ba..9b1b2fd 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -135,7 +135,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 
 	_byte1714E = 0;
 	_byte12FCE = false;
-	_byte129A0 = -1;
+	_selectedCharacterId = -1;
 	_numCharactersToDisplay = 0;
 	_nextDisplayCharacterPos = Common::Point(0, 0);
 	_animationTick = 0;
@@ -975,9 +975,9 @@ int16 LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) {
 void LilliputEngine::sub15F75() {
 	debugC(2, kDebugEngineTBC, "sub15F75()");
 
-	_byte129A0 = -1;
+	_selectedCharacterId = -1;
 	_savedMousePosDivided = Common::Point(-1, -1);
-	byte newX = _mousePos.x >> 2;
+	byte newX = _mousePos.x / 4;
 	byte newY = _mousePos.y / 3;
 
 	if ((newX >= 64) || (newY >= 64))
@@ -2011,7 +2011,7 @@ void LilliputEngine::sub130EE() {
 		return;
 
 	forceReturnFl = false;
-	sub131B2(pos, forceReturnFl);
+	checkClickOnCharacter(pos, forceReturnFl);
 	if (forceReturnFl)
 		return;
 
@@ -2038,14 +2038,14 @@ void LilliputEngine::sub131FC(Common::Point pos) {
 	}
 }
 
-void LilliputEngine::sub131B2(Common::Point pos, bool &forceReturnFl) {
-	debugC(2, kDebugEngine, "sub131B2(%d, %d)", pos.x, pos.y);
+void LilliputEngine::checkClickOnCharacter(Common::Point pos, bool &forceReturnFl) {
+	debugC(2, kDebugEngine, "checkClickOnCharacter(%d, %d)", pos.x, pos.y);
 
 	forceReturnFl = false;
 
 	for (int8 i = 0; i < _numCharacters; i++) {
 		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
-			_byte129A0 = i;
+			_selectedCharacterId = i;
 			_byte16F07_menuId = 4;
 			if (_byte12FCE)
 				_byte16F07_menuId = 3;
@@ -2817,7 +2817,7 @@ void LilliputEngine::handleMenu() {
 	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScriptSize));
 	debugC(1, kDebugScriptTBC, "========================== End of Menu Script==============================");
 	_savedMousePosDivided = Common::Point(-1, -1);
-	_byte129A0 = -1;
+	_selectedCharacterId = -1;
 
 	if (_byte16F07_menuId == 3)
 		unselectInterfaceButton();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 02ed0c6..190d8bc 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -295,7 +295,7 @@ public:
 	void sub1305C(byte index, byte var2);
 	void checkInterfaceHotspots(bool &forceReturnFl);
 	bool isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos);
-	void sub131B2(Common::Point pos, bool &forceReturnFl);
+	void checkClickOnCharacter(Common::Point pos, bool &forceReturnFl);
 	void sub131FC(Common::Point pos);
 	void displaySpeechBubbleTail(Common::Point displayPos);
 	void displaySpeechBubbleTailLine(Common::Point pos, int var2);
@@ -348,7 +348,7 @@ public:
 
 	byte _byte16F07_menuId;
 	bool _byte12FCE;
-	int8 _byte129A0;
+	int8 _selectedCharacterId;
 	byte _numCharactersToDisplay;
 	int16 _word10804;
 	bool _shouldQuit;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 72d1306..c842331 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -217,7 +217,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_checkLastInterfaceHotspotIndex();
 		break;
 	case 0x2C:
-		return OC_checkSavedMousePos();
+		return OC_checkSelectedCharacter();
 		break;
 	case 0x2D:
 		return OC_sub179AE();
@@ -600,7 +600,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_CurrentCharacterVar3Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkLastInterfaceHotspotIndex", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_checkSavedMousePos", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_checkSelectedCharacter", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179AE", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_checkFunctionKeyPressed", 1, kImmediateValue, kNone, kNone, kNone, kNone },
@@ -726,7 +726,7 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 		} else if (val > 1004) { 
 			str = Common::String::format("getValue1(0x%x)", val);
 		} else if (val == 1000) {
-			str = Common::String("_byte129A0");
+			str = Common::String("_selectedCharacterId");
 		} else if (val == 1001) {
 			str = Common::String("characterIndex");
 		} else if (val == 1002) {
@@ -1284,7 +1284,7 @@ int16 LilliputScript::getValue1() {
 
 	switch (curWord) {
 	case 1000:
-		return _vm->_byte129A0;
+		return _vm->_selectedCharacterId;
 	case 1001:
 		return _vm->_currentScriptCharacter;
 	case 1002:
@@ -2026,10 +2026,10 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndex() {
 	return 0;
 }
 
-byte LilliputScript::OC_checkSavedMousePos() {
-	debugC(1, kDebugScript, "OC_checkSavedMousePos()");
+byte LilliputScript::OC_checkSelectedCharacter() {
+	debugC(1, kDebugScript, "OC_checkSelectedCharacter()");
 
-	if ((_vm->_byte129A0 != -1) || (_vm->_savedMousePosDivided == Common::Point(-1, -1)))
+	if ((_vm->_selectedCharacterId != -1) || (_vm->_savedMousePosDivided == Common::Point(-1, -1)))
 		return 0;
 
 	return 1;
@@ -2038,7 +2038,7 @@ byte LilliputScript::OC_checkSavedMousePos() {
 byte LilliputScript::OC_sub179AE() {
 	debugC(1, kDebugScript, "OC_sub179AE()");
 
-	if (_vm->_byte12FCE || (_vm->_byte129A0 == -1))
+	if (_vm->_byte12FCE || (_vm->_selectedCharacterId == -1))
 		return 0;
 
 	return 1;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 96bd837..b796e85 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -186,7 +186,7 @@ private:
 	byte OC_CurrentCharacterVar3Equals1();
 	byte OC_checkCharacterDirection();
 	byte OC_checkLastInterfaceHotspotIndex();
-	byte OC_checkSavedMousePos();
+	byte OC_checkSelectedCharacter();
 	byte OC_sub179AE();
 	byte OC_sub179C2();
 	byte OC_checkFunctionKeyPressed();


Commit: 802f132f02e5b0d9cb603eb4e19e610f13d27890
    https://github.com/scummvm/scummvm/commit/802f132f02e5b0d9cb603eb4e19e610f13d27890
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: One more renaming

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index c842331..b555bd1 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -418,7 +418,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setInterfaceHotspot();
 		break;
 	case 0x3A:
-		OC_sub180C3();
+		OC_scrollViewPort();
 		break;
 	case 0x3B:
 		OC_setViewPortPos();
@@ -668,7 +668,7 @@ static const OpCode opCodes2[] = {
 /* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x39 */	{ "OC_setInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x3a */	{ "OC_sub180C3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x3a */	{ "OC_scrollViewPort", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x3b */	{ "OC_setViewPortPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x3c */	{ "OC_setCurrentCharacterAltitude", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x3d */	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
@@ -2803,30 +2803,21 @@ void LilliputScript::OC_setInterfaceHotspot() {
 	_vm->displayInterfaceHotspots();
 }
 
-void LilliputScript::OC_sub180C3() {
-	debugC(1, kDebugScriptTBC, "OC_sub180C3()");
+void LilliputScript::OC_scrollViewPort() {
+	debugC(1, kDebugScriptTBC, "OC_scrollViewPort()");
 
 	_viewportCharacterTarget = -1;
 
-	int var1 = _currScript->readUint16LE();
-	
-	static const char _byte180B3[] = { 6, 0, 0, -6 };
-	static const char _byte180BB[] = { 0, -6, 6, 0 };
+	int direction = _currScript->readUint16LE();
 	
-	int x = _viewportPos.x + _byte180B3[var1];
-	int y = _viewportPos.y + _byte180BB[var1];
-
-	if (x < 0)
-		x = 0;
-
-	if (y < 0)
-		y = 0;
+	static const char scrollValX[] = { 6, 0, 0, -6 };
+	static const char scrollValY[] = { 0, -6, 6, 0 };
 	
-	if (x > 56)
-		x = 56;
+	int x = _viewportPos.x + scrollValX[direction];
+	int y = _viewportPos.y + scrollValY[direction];
 
-	if (y > 56)
-		y = 56;
+	CLIP(x, 0, 56);
+	CLIP(y, 0, 56);
 
 	_vm->_refreshScreenFlag = true;
 	_vm->viewportScrollTo(Common::Point(x, y));
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index b796e85..5969ec1 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -252,7 +252,7 @@ private:
 	void OC_sub18074();
 	void OC_setCurrentCharacterDirection();
 	void OC_setInterfaceHotspot();
-	void OC_sub180C3();
+	void OC_scrollViewPort();
 	void OC_setViewPortPos();
 	void OC_setCurrentCharacterAltitude();
 	void OC_sub1817F();


Commit: a1c5e27b77ace733716e9a389e77588ab2f7d6f0
    https://github.com/scummvm/scummvm/commit/a1c5e27b77ace733716e9a389e77588ab2f7d6f0
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Rename some functions, fix a bug in OC_getComputedVariantSpeech()

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b555bd1..f82e073 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -253,16 +253,16 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_startSpeech();
 		break;
 	case 0x3:
-		OC_sub17D7F_speech2();
+		OC_getComputedVariantSpeech();
 		break;
 	case 0x4:
-		OC_sub17DB9_speech3();
+		OC_getRotatingVariantSpeech();
 		break;
 	case 0x5:
 		OC_startSpeechIfMute();
 		break;
 	case 0x6:
-		OC_sub17E07_speech4param();
+		OC_getComputedVariantSpeechIfMute();
 		break;
 	case 0x7:
 		OC_startSpeechIfSilent();
@@ -286,7 +286,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub17B93();
 		break;
 	case 0xE:
-		OC_sub17E37_speech4();
+		OC_startSpeech5();
 		break;
 	case 0xF:
 		OC_resetByte1714E();
@@ -484,7 +484,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_loadFile_AERIAL_GFX();
 		break;
 	case 0x50:
-		OC_sub17E22_speech1IfSoundOff();
+		OC_startSpeechIfSoundOff();
 		break;
 	case 0x51:
 		OC_sub1844A();
@@ -613,10 +613,10 @@ static const OpCode opCodes2[] = {
 /* 0x00 */	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x01 */	{ "OC_ChangeIsoMap", 3, kgetPosFromScript, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x02 */	{ "OC_startSpeech", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x03 */	{ "OC_sub17D7F_speech2", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
-/* 0x04 */	{ "OC_sub17DB9_speech3", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
+/* 0x03 */	{ "OC_getComputedVariantSpeech", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
+/* 0x04 */	{ "OC_getRotatingVariantSpeech", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
 /* 0x05 */	{ "OC_startSpeechIfMute", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x06 */	{ "OC_sub17E07_speech4param", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
+/* 0x06 */	{ "OC_getComputedVariantSpeechIfMute", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
 /* 0x07 */	{ "OC_startSpeechIfSilent", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x08 */	{ "OC_ComputeCharacterVariable", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
 /* 0x09 */	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
@@ -624,7 +624,7 @@ static const OpCode opCodes2[] = {
 /* 0x0b */	{ "OC_DisableCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x0d */	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
-/* 0x0e */	{ "OC_sub17E37_speech4", 0, kNone, kNone, kNone, kNone, kNone },  // todo
+/* 0x0e */	{ "OC_startSpeech5", 0, kNone, kNone, kNone, kNone, kNone },  // todo
 /* 0x0f */	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x10 */	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x11 */	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
@@ -690,7 +690,7 @@ static const OpCode opCodes2[] = {
 /* 0x4d */	{ "OC_waitForEvent", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4e */	{ "OC_disableInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
 /* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x50 */	{ "OC_sub17E22_speech1IfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x50 */	{ "OC_startSpeechIfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x52 */	{ "OC_displayNumericCharacterVariable", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
 /* 0x53 */	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
@@ -1156,6 +1156,7 @@ void LilliputScript::sub189B8() {
 void LilliputScript::decodePackedText(char *buf) {
 	debugC(2, kDebugScript, "decodePackedText(buf)");
 
+	// All the languages use the English dictionnary
 	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I've |can't |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|'s |'t |re|gg|tt|pp|nn|ay|ar|wh|";
 
 	_vm->_displayStringIndex = 0;
@@ -1208,8 +1209,8 @@ void LilliputScript::decodePackedText(char *buf) {
 	sub189B8();
 }
 
-int LilliputScript::sub18BB7(int index) {
-	debugC(2, kDebugScriptTBC, "sub18BB7(%d)", index);
+int LilliputScript::getPackedStringStartRelativeIndex(int index) {
+	debugC(2, kDebugScript, "getPackedStringStartRelativeIndex(%d)", index);
 	
 	int chunk4Index = _vm->_packedStringIndex[index];
 	int result = 0;
@@ -1219,9 +1220,9 @@ int LilliputScript::sub18BB7(int index) {
 	return result + 1;
 }
 
+// Part of the script decompiler
 void LilliputScript::listAllTexts() {
-	
-	debugC(1, kDebugScriptTBC, "All Game Texts :");
+	debugC(1, kDebugScript, "listAllTexts");
 
 	for (int i = 0; i < _vm->_packedStringNumb; i++) {
 		int index = _vm->_packedStringIndex[i];
@@ -2144,20 +2145,29 @@ void LilliputScript::OC_startSpeech() {
 	startSpeech(curWord);
 }
 
-void LilliputScript::sub18B7C(int var1, int var3) {
-	debugC(2, kDebugScriptTBC, "sub18B7C(%d, %d)", var1, var3);
+void LilliputScript::getSpeechVariant(int speechIndex, int speechVariant) {
+	debugC(2, kDebugScriptTBC, "getSpeechVariant(%d, %d)", speechIndex, speechVariant);
+
+	// The packed strings are stored by variants, enclosed by imbricated brackets.
+	// So the different possibilities are:
+	// text
+	// [text1]text2
+	// [[text1]text2]text3
+	// etc etc
 
-	if (var1 == 0xFFFF) 
+	if (speechIndex == -1) 
 		return;
 
-	_currentSpeechId = var1;
-	int index = _vm->_packedStringIndex[var1];
+	_currentSpeechId = speechIndex;
+	int index = _vm->_packedStringIndex[speechIndex];
 
+	// Skip the speech variant opening characters
 	while (_vm->_packedStrings[index] == '[')
 		++index;
 
-	for (int i = 0; i < var3; i++) {
+	for (int i = 0; i < speechVariant; i++) {
 		byte tmpVal = ' ';
+		// Skip a speech variant
 		while (tmpVal != ']') {
 			tmpVal = _vm->_packedStrings[index];
 			++index;
@@ -2170,14 +2180,14 @@ void LilliputScript::sub18B7C(int var1, int var3) {
 	decodePackedText(&_vm->_packedStrings[index]);
 }
 
-void LilliputScript::OC_sub17D7F_speech2() {
-	debugC(1, kDebugScriptTBC, "OC_sub17D7F_speech2()");
+void LilliputScript::OC_getComputedVariantSpeech() {
+	debugC(1, kDebugScriptTBC, "OC_getComputedVariantSpeech()");
 
-	int var1 = getCharacterVariablePtr()[0];
-	int var2 = (_currScript->readUint16LE() & 0xFF);
-	int var3 = var1 / var2;
+	int tmpVal1 = getCharacterVariablePtr()[0];
+	int tmpVal2 = (_currScript->readUint16LE() & 0xFF);
+	int speechVariant = tmpVal1 / tmpVal2;
 	
-	var1 = _currScript->readUint16LE();
+	int speechIndex = _currScript->readUint16LE();
 
 	bool forceReturnFl = false;
 	checkSpeechAllowed(forceReturnFl);
@@ -2185,21 +2195,20 @@ void LilliputScript::OC_sub17D7F_speech2() {
 		return;
 
 	_talkingCharacter = _vm->_currentScriptCharacter;
-
-	sub18B7C(var1, var3);
+	getSpeechVariant(speechIndex, speechVariant);
 }
 
-void LilliputScript::OC_sub17DB9_speech3() {
-	debugC(1, kDebugScriptTBC, "OC_sub17DB9_speech3()");
+void LilliputScript::OC_getRotatingVariantSpeech() {
+	debugC(1, kDebugScriptTBC, "OC_getRotatingVariantSpeech()");
 
 	int index = _currScript->readUint16LE();
-	int maxValue = sub18BB7(index);
+	int maxValue = getPackedStringStartRelativeIndex(index);
 	
-	int tmpVal = _currScript->readUint16LE() + 1;
-	int oldVal = tmpVal;
-	if (tmpVal >= maxValue)
-		tmpVal = 0;
-	_currScript->writeUint16LE(tmpVal, -2); 
+	int currVariant = _currScript->readUint16LE();
+	int nextVariant = currVariant + 1;
+	if (nextVariant >= maxValue)
+		nextVariant = 0;
+	_currScript->writeUint16LE(nextVariant, -2); 
 
 	bool forceReturnFl = false;
 	checkSpeechAllowed(forceReturnFl);
@@ -2208,7 +2217,7 @@ void LilliputScript::OC_sub17DB9_speech3() {
 
 	_talkingCharacter = _vm->_currentScriptCharacter;
 
-	sub18B7C(index, oldVal);
+	getSpeechVariant(index, currVariant);
 	
 }
 
@@ -2223,11 +2232,11 @@ void LilliputScript::OC_startSpeechIfMute() {
 	_currScript->readUint16LE();
 }
 
-void LilliputScript::OC_sub17E07_speech4param() {
-	debugC(1, kDebugScriptTBC, "OC_sub17E07_speech4param()");
+void LilliputScript::OC_getComputedVariantSpeechIfMute() {
+	debugC(1, kDebugScriptTBC, "OC_getComputedVariantSpeechIfMute()");
 
 	if (_talkingCharacter == -1) {
-		OC_sub17D7F_speech2();
+		OC_getComputedVariantSpeech();
 		return;
 	}
 	_currScript->readUint16LE();
@@ -2241,7 +2250,7 @@ void LilliputScript::OC_startSpeechIfSilent() {
 	debugC(1, kDebugScript, "OC_startSpeechIfSilent()");
 
 	if (_talkingCharacter == -1) {
-		OC_sub17DB9_speech3();
+		OC_getRotatingVariantSpeech();
 		return;
 	}
 	_currScript->readUint16LE();
@@ -2306,8 +2315,8 @@ void LilliputScript::OC_sub17B93() {
 	sub17B6C(var1);
 }
 
-void LilliputScript::OC_sub17E37_speech4() {
-	debugC(1, kDebugScriptTBC, "OC_sub17E37_speech4()");
+void LilliputScript::OC_startSpeech5() {
+	debugC(1, kDebugScriptTBC, "OC_startSpeech5()");
 
 	bool forceReturnFl = false;
 	checkSpeechAllowed(forceReturnFl);
@@ -3117,10 +3126,10 @@ void LilliputScript::OC_loadFile_AERIAL_GFX() {
 	_vm->_refreshScreenFlag = false;
 }
 
-void LilliputScript::OC_sub17E22_speech1IfSoundOff() {
-	debugC(1, kDebugScriptTBC, "OC_sub17E22_speech1IfSoundOff()");
+void LilliputScript::OC_startSpeechIfSoundOff() {
+	debugC(1, kDebugScriptTBC, "OC_startSpeechIfSoundOff()");
 
-	// HACK: In the original, OC_sub17E22_speech1IfSoundOff() only calls 
+	// HACK: In the original, OC_startSpeechIfSoundOff() only calls 
 	// OC_startSpeech if sound is off. For the moment, it's always called
 
 	OC_startSpeech();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 5969ec1..0311632 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -128,11 +128,11 @@ private:
 	byte *getMapPtr(Common::Point val);
 	byte *getCurrentCharacterVarFromScript();
 	void sub171AF(int16 var1, uint16 var2, int16 var4);
-	void sub18B7C(int var1, int var3);
+	void getSpeechVariant(int speechIndex, int speechVariant);
 	void sub189B8();
 	void formatSpeechString();
 	Common::Point getCharacterTilePos(int index);
-	int sub18BB7(int index);
+	int getPackedStringStartRelativeIndex(int index);
 
 	int16 getValue1();
 	Common::Point getPosFromScript();
@@ -197,10 +197,10 @@ private:
 	void OC_setWord18821();
 	void OC_ChangeIsoMap();
 	void OC_startSpeech();
-	void OC_sub17D7F_speech2();
-	void OC_sub17DB9_speech3();
+	void OC_getComputedVariantSpeech();
+	void OC_getRotatingVariantSpeech();
 	void OC_startSpeechIfMute();
-	void OC_sub17E07_speech4param();
+	void OC_getComputedVariantSpeechIfMute();
 	void OC_startSpeechIfSilent();
 	void OC_ComputeCharacterVariable();
 	void OC_getRandom_type2();
@@ -208,7 +208,7 @@ private:
 	void OC_DisableCharacter();
 	void OC_saveAndQuit();
 	void OC_sub17B93();
-	void OC_sub17E37_speech4();
+	void OC_startSpeech5();
 	void OC_resetByte1714E();
 	void OC_deleteSavegameAndQuit();
 	void OC_incByte16F04();
@@ -275,7 +275,7 @@ private:
 	void OC_waitForEvent();
 	void OC_disableInterfaceHotspot();
 	void OC_loadFile_AERIAL_GFX();
-	void OC_sub17E22_speech1IfSoundOff();
+	void OC_startSpeechIfSoundOff();
 	void OC_sub1844A();
 	void OC_displayNumericCharacterVariable();
 	void OC_displayVGAFile();


Commit: 7fa6dea35585a654caf52302e6c5512513c43cf1
    https://github.com/scummvm/scummvm/commit/7fa6dea35585a654caf52302e6c5512513c43cf1
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Improve hack in sub16EBC() to avoid checking inactive characters

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 9b1b2fd..5047dc0 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1850,7 +1850,7 @@ void LilliputEngine::sub16EBC() {
 
 	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
 		// Hack: The original doesn't check if it's disabled, which looks wrong
-		if (_scriptHandler->_array1614BPosY[index1] == -1)
+		if ((_scriptHandler->_array16123PosX[index1] == -1) || (_scriptHandler->_array1614BPosY[index1] == -1))
 			continue;
 		//
 


Commit: 10edaf6bc4d8833007dab0008440c31970b8267a
    https://github.com/scummvm/scummvm/commit/10edaf6bc4d8833007dab0008440c31970b8267a
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming, start fixing the map display

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 5047dc0..01716a3 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -662,7 +662,7 @@ void LilliputEngine::restoreMapPoints() {
 
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (byte index = 0; index < _numCharacters; index++) {
-		buf[_word15E5D[index]] = _byte15E35[index];
+		buf[_mapSavedPixelIndex[index]] = _mapSavedPixel[index];
 	}
 
 	displayMousePointer();
@@ -677,12 +677,12 @@ void LilliputEngine::displayCharactersOnMap() {
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = _numCharacters - 1; index >= 0; index--) {
 		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614BPosY[index] != -1)) {
-			int y = (3 * _scriptHandler->_array1614BPosY[index]) + 1;
-			int x = (_scriptHandler->_array16123PosX[index] * 4) + 1;
+			// FIXME: This is still wrong, but less. The values in both arrays should be verified now!
+			int pixIndex = 320 + ((15 * _scriptHandler->_array1614BPosY[index]) / 4) + (_scriptHandler->_array16123PosX[index] * 4) + 1;
 
-			_word15E5D[index] = y * 320 + x;
-			_byte15E35[index] = buf[y * 320 + x];
-			buf[y * 320 + x] = _scriptHandler->_array128EF[index];
+			_mapSavedPixelIndex[index] = pixIndex;
+			_mapSavedPixel[index] = buf[pixIndex];
+			buf[pixIndex] = _scriptHandler->_characterMapPixelColor[index];
 		}
 	}
 	displayMousePointer();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 190d8bc..c58c37f 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -150,8 +150,8 @@ public:
 	int _word1289D;
 	Common::Point _word16937Pos;
 
-	short _word15E5D[40];
-	byte _byte15E35[40];
+	int16 _mapSavedPixelIndex[40];
+	byte _mapSavedPixel[40];
 	int16 _array11D49[40];
 	int16 _array1289F[40];
 	int16 _array12861[30];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f82e073..a55e24a 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -61,7 +61,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 
 	for (int i = 0; i < 40; i++) {
 		_characterScriptEnabled[i] = 1;
-		_array128EF[i] = 15;
+		_characterMapPixelColor[i] = 15;
 		_array10AB1[i] = 0;
 		_array12811[i] = 16;
 		_array12839[i] = -1;
@@ -481,7 +481,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_disableInterfaceHotspot();
 		break;
 	case 0x4F:
-		OC_loadFile_AERIAL_GFX();
+		OC_loadFileAerial();
 		break;
 	case 0x50:
 		OC_startSpeechIfSoundOff();
@@ -689,7 +689,7 @@ static const OpCode opCodes2[] = {
 /* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4d */	{ "OC_waitForEvent", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4e */	{ "OC_disableInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
-/* 0x4f */	{ "OC_loadFile_AERIAL_GFX", 1, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x4f */	{ "OC_loadFileAerial", 1, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x50 */	{ "OC_startSpeechIfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x52 */	{ "OC_displayNumericCharacterVariable", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
@@ -2146,7 +2146,7 @@ void LilliputScript::OC_startSpeech() {
 }
 
 void LilliputScript::getSpeechVariant(int speechIndex, int speechVariant) {
-	debugC(2, kDebugScriptTBC, "getSpeechVariant(%d, %d)", speechIndex, speechVariant);
+	debugC(2, kDebugScript, "getSpeechVariant(%d, %d)", speechIndex, speechVariant);
 
 	// The packed strings are stored by variants, enclosed by imbricated brackets.
 	// So the different possibilities are:
@@ -2199,7 +2199,7 @@ void LilliputScript::OC_getComputedVariantSpeech() {
 }
 
 void LilliputScript::OC_getRotatingVariantSpeech() {
-	debugC(1, kDebugScriptTBC, "OC_getRotatingVariantSpeech()");
+	debugC(1, kDebugScript, "OC_getRotatingVariantSpeech()");
 
 	int index = _currScript->readUint16LE();
 	int maxValue = getPackedStringStartRelativeIndex(index);
@@ -3103,8 +3103,8 @@ void LilliputScript::OC_disableInterfaceHotspot() {
 	_vm->displayInterfaceHotspots();
 }
 
-void LilliputScript::OC_loadFile_AERIAL_GFX() {
-	debugC(1, kDebugScriptTBC, "OC_loadFile_AERIAL_GFX()");
+void LilliputScript::OC_loadFileAerial() {
+	debugC(1, kDebugScript, "OC_loadFileAerial()");
 
 	// Unused variable, and the script position is restored afterwards
 	// TODO: Check if this part of the code is present in Rome, else remove it
@@ -3387,7 +3387,7 @@ void LilliputScript::OC_setArray128EF() {
 	int val = _currScript->readUint16LE();
 
 	assert(index < 40);
-	_array128EF[index] = val & 0xFF;
+	_characterMapPixelColor[index] = val & 0xFF;
 }
 
 } // End of namespace
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 0311632..b902787 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -79,7 +79,7 @@ public:
 	int _heroismBarBottomY;
 
 	Common::Point _array12311[640];
-	byte _array128EF[40];
+	byte _characterMapPixelColor[40];
 	int8 _array12839[40];
 	Common::Point _array1813BPos[32];
 
@@ -274,7 +274,7 @@ private:
 	void OC_setByte14837();
 	void OC_waitForEvent();
 	void OC_disableInterfaceHotspot();
-	void OC_loadFile_AERIAL_GFX();
+	void OC_loadFileAerial();
 	void OC_startSpeechIfSoundOff();
 	void OC_sub1844A();
 	void OC_displayNumericCharacterVariable();


Commit: 98032809dd9a5ac659f2ef84398e9dab482d3b77
    https://github.com/scummvm/scummvm/commit/98032809dd9a5ac659f2ef84398e9dab482d3b77
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 01716a3..2b9f579 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -676,9 +676,9 @@ void LilliputEngine::displayCharactersOnMap() {
 
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = _numCharacters - 1; index >= 0; index--) {
-		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614BPosY[index] != -1)) {
+		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_characterTilePosY[index] != -1)) {
 			// FIXME: This is still wrong, but less. The values in both arrays should be verified now!
-			int pixIndex = 320 + ((15 * _scriptHandler->_array1614BPosY[index]) / 4) + (_scriptHandler->_array16123PosX[index] * 4) + 1;
+			int pixIndex = 320 + ((15 * _scriptHandler->_characterTilePosY[index]) / 4) + (_scriptHandler->_characterTilePosX[index] * 4) + 1;
 
 			_mapSavedPixelIndex[index] = pixIndex;
 			_mapSavedPixel[index] = buf[pixIndex];
@@ -723,8 +723,8 @@ void LilliputEngine::moveCharacters() {
 			_characterPositionY[i] = var4;
 		}
 
-		_scriptHandler->_array16123PosX[i] = (_characterPositionX[i] >> 3);
-		_scriptHandler->_array1614BPosY[i] = (_characterPositionY[i] >> 3);
+		_scriptHandler->_characterTilePosX[i] = (_characterPositionX[i] >> 3);
+		_scriptHandler->_characterTilePosY[i] = (_characterPositionY[i] >> 3);
 		_characterRelativePositionX[i] = 0xFF;
 		_characterRelativePositionY[i] = 0xFF;
 		_characterDisplayX[i] = 0xFF;
@@ -1033,8 +1033,8 @@ void LilliputEngine::sub16CA0() {
 		if (_rulesBuffer2_11[index] & 1)
 			continue;
 
-		int c1 = _scriptHandler->_array16123PosX[index];
-		int c2 = _scriptHandler->_array1614BPosY[index];
+		int c1 = _scriptHandler->_characterTilePosX[index];
+		int c2 = _scriptHandler->_characterTilePosY[index];
 
 		// Hack: Skip if disabled (c2 negative)
 		if (c2 == -1)
@@ -1047,8 +1047,8 @@ void LilliputEngine::sub16CA0() {
 			        (_rulesBuffer2_5[index] != index2) &&
 			        (_rulesBuffer2_5[index2] != index) &&
 			        (_rulesBuffer2_11[index2] & 2) == 0) {
-				int d1 = _scriptHandler->_array16123PosX[index2];
-				int d2 = _scriptHandler->_array1614BPosY[index2];
+				int d1 = _scriptHandler->_characterTilePosX[index2];
+				int d2 = _scriptHandler->_characterTilePosY[index2];
 
 				if (d1 != -1) {
 					int x = c1 - d1;
@@ -1435,7 +1435,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 	Common::Point var3 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
 
 	if (var3.x != -1) {
-		if ((var3.x != _scriptHandler->_array16123PosX[index]) || (var3.y != _scriptHandler->_array1614BPosY[index])) {
+		if ((var3.x != _scriptHandler->_characterTilePosX[index]) || (var3.y != _scriptHandler->_characterTilePosY[index])) {
 			sub1693A_chooseDirections(index);
 			_scriptHandler->_array12811[index] -= (param1.x & 0x0F);
 			return 3;
@@ -1447,7 +1447,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 
 	sub167EF(index);
 
-	Common::Point pos1 = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
+	Common::Point pos1 = Common::Point(_scriptHandler->_characterTilePosX[index], _scriptHandler->_characterTilePosY[index]);
 	Common::Point pos2 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
 
 	_characterDirectionArray[index] = getDirection(pos1, pos2);
@@ -1461,7 +1461,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngine, "sub167EF(%d)", index);
 
-	int16 word167EB = findHotspot(Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]));
+	int16 word167EB = findHotspot(Common::Point(_scriptHandler->_characterTilePosX[index], _scriptHandler->_characterTilePosY[index]));
 	int16 word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
 
 	if (word167EB == word167ED) {
@@ -1546,7 +1546,7 @@ void LilliputEngine::sub1693A_chooseDirections(int index) {
 
 	static const int16 mapArrayMove[4] = {4, -256, 256, -4};
 
-	_word16937Pos = Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]);
+	_word16937Pos = Common::Point(_scriptHandler->_characterTilePosX[index], _scriptHandler->_characterTilePosY[index]);
 
 	sub16A08(index);
 
@@ -1823,24 +1823,23 @@ byte LilliputEngine::sub16729(int index, Common::Point var1) {
 
 	int param4x = ((index | 0xFF00) >> 8);
 	int param1 = var1.y;
-	_soundHandler->contentFct2(param1, _scriptHandler->_viewportPos, Common::Point(_scriptHandler->_array16123PosX[index], _scriptHandler->_array1614BPosY[index]), Common::Point(param4x, 0));
+	_soundHandler->contentFct2(param1, _scriptHandler->_viewportPos, Common::Point(_scriptHandler->_characterTilePosX[index], _scriptHandler->_characterTilePosY[index]), Common::Point(param4x, 0));
 	return 2;
 }
 
 byte LilliputEngine::sub1675D(int index, Common::Point var1) {
 	debugC(2, kDebugEngine, "sub1675D(%d, %d - %d)", index, var1.x, var1.y);
 
-	int var2 = _scriptHandler->_array10A39[index];
-	int8 var1h = _scriptHandler->_array16123PosX[var2];
-	int8 var1l = _scriptHandler->_array1614BPosY[var2];
+	int charIndex = _scriptHandler->_array10A39[index];
+	Common::Point charPos = Common::Point(_scriptHandler->_characterTilePosX[charIndex], _scriptHandler->_characterTilePosY[charIndex]);
 
 	if ((_array109E9PosX[index] != -1) && (_array109E9PosX[index] == _array10999PosX[index]) && (_array10A11PosY[index] == _array109C1PosY[index])) {
-		_array109E9PosX[index] = var1h;
-		_array10A11PosY[index] = var1l;
+		_array109E9PosX[index] = charPos.x;
+		_array10A11PosY[index] = charPos.y;
 	}
 
-	_array10999PosX[index] = var1h;
-	_array109C1PosY[index] = var1l;
+	_array10999PosX[index] = charPos.x;
+	_array109C1PosY[index] = charPos.y;
 
 	return sub16799(index, var1);
 }
@@ -1850,11 +1849,11 @@ void LilliputEngine::sub16EBC() {
 
 	for (int index1 = _numCharacters - 1; index1 >= 0; index1--) {
 		// Hack: The original doesn't check if it's disabled, which looks wrong
-		if ((_scriptHandler->_array16123PosX[index1] == -1) || (_scriptHandler->_array1614BPosY[index1] == -1))
+		if ((_scriptHandler->_characterTilePosX[index1] == -1) || (_scriptHandler->_characterTilePosY[index1] == -1))
 			continue;
 		//
 
-		int mapIndex = 3 + (_scriptHandler->_array1614BPosY[index1] * 64 + _scriptHandler->_array16123PosX[index1]) * 4;
+		int mapIndex = 3 + (_scriptHandler->_characterTilePosY[index1] * 64 + _scriptHandler->_characterTilePosX[index1]) * 4;
 		assert((mapIndex >= 0) && (mapIndex < 16384));
 		byte var1 = _bufferIsoMap[mapIndex] & 0x40;
 
@@ -2254,7 +2253,7 @@ void LilliputEngine::sub16B8F_moveCharacter(int index, Common::Point pos, int di
 	debugC(2, kDebugEngine, "sub16B8F_moveCharacter(%d, %d - %d, %d)", index, pos.x, pos.y, direction);
 
 	int16 diffX = pos.x >> 3;
-	if (((diffX & 0xFF) == _scriptHandler->_array16123PosX[index]) && ((pos.y >> 3) == _scriptHandler->_array1614BPosY[index])) {
+	if (((diffX & 0xFF) == _scriptHandler->_characterTilePosX[index]) && ((pos.y >> 3) == _scriptHandler->_characterTilePosY[index])) {
 		_characterPositionX[index] = pos.x;
 		_characterPositionY[index] = pos.y;
 		return;
@@ -2263,7 +2262,7 @@ void LilliputEngine::sub16B8F_moveCharacter(int index, Common::Point pos, int di
 	if ((pos.x < 0) || (pos.x >= 512) || (pos.y < 0) || (pos.y >= 512))
 		return;
 
-	int mapIndex = (_scriptHandler->_array1614BPosY[index] * 64 + _scriptHandler->_array16123PosX[index]) * 4;
+	int mapIndex = (_scriptHandler->_characterTilePosY[index] * 64 + _scriptHandler->_characterTilePosX[index]) * 4;
 	assert(mapIndex < 16384);
 
 	if ((_bufferIsoMap[mapIndex + 3] & _array16C58[direction]) == 0)
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a55e24a..7b461af 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -65,8 +65,8 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_array10AB1[i] = 0;
 		_array12811[i] = 16;
 		_array12839[i] = -1;
-		_array16123PosX[i] = 0;
-		_array1614BPosY[i] = 0;
+		_characterTilePosX[i] = 0;
+		_characterTilePosY[i] = 0;
 		_array122C1[i] = 0;
 	}
 
@@ -544,7 +544,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1875D_snd();
 		break;
 	case 0x64:
-		OC_setArray128EF();
+		OC_setCharacterMapColor();
 		break;
 	case 0x65:
 		OC_initGameAreaDisplay();
@@ -710,7 +710,7 @@ static const OpCode opCodes2[] = {
 /* 0x61 */	{ "OC_sub1873F_snd", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
 /* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x63 */	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x64 */	{ "OC_setArray128EF", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x64 */	{ "OC_setCharacterMapColor", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x65 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
@@ -1381,8 +1381,8 @@ byte LilliputScript::OC_comparePos() {
 	debugC(2, kDebugScript, "OC_comparePos()");
 
 	int index = getValue1();
-	int8 d1 = _array16123PosX[index];
-	int8 d2 = _array1614BPosY[index];
+	int8 d1 = _characterTilePosX[index];
+	int8 d2 = _characterTilePosY[index];
 	Common::Point var1 = getPosFromScript();
 
 	if (var1 == Common::Point(d1, d2))
@@ -1552,7 +1552,7 @@ byte LilliputScript::OC_compareCoords_2() {
 	debugC(1, kDebugScript, "OC_compareCoords_2()");
 
 	int16 index = getValue1();
-	Common::Point var1 = Common::Point(_array16123PosX[index], _array1614BPosY[index]);
+	Common::Point var1 = Common::Point(_characterTilePosX[index], _characterTilePosY[index]);
 	index = _currScript->readUint16LE();
 	uint16 var3 = _vm->_rectXMinMax[index];
 	uint16 var4 = _vm->_rectYMinMax[index];
@@ -3326,7 +3326,7 @@ void LilliputScript::OC_sub186E5_snd() {
 	Common::Point var4 = Common::Point(0xFF, index & 0xFF);
 	int var1 = (_currScript->readUint16LE() & 0xFF);
 	
-	_vm->_soundHandler->contentFct2(var1, _viewportPos, Common::Point(_array16123PosX[index], _array1614BPosY[index]), var4);
+	_vm->_soundHandler->contentFct2(var1, _viewportPos, Common::Point(_characterTilePosX[index], _characterTilePosY[index]), var4);
 }
 
 void LilliputScript::OC_sub1870A_snd() {
@@ -3380,14 +3380,14 @@ void LilliputScript::OC_sub1875D_snd() {
 	_vm->_soundHandler->contentFct6();
 }
 
-void LilliputScript::OC_setArray128EF() {
-	debugC(1, kDebugScript, "OC_setArray128EF()");
+void LilliputScript::OC_setCharacterMapColor() {
+	debugC(1, kDebugScript, "OC_setCharacterMapColor()");
 
-	int index = getValue1();
-	int val = _currScript->readUint16LE();
+	byte index = (getValue1() & 0xFF);
+	int color = _currScript->readUint16LE();
 
 	assert(index < 40);
-	_characterMapPixelColor[index] = val & 0xFF;
+	_characterMapPixelColor[index] = (color & 0xFF);
 }
 
 } // End of namespace
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index b902787..59ffb4d 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -61,8 +61,8 @@ public:
 
 	byte _characterScriptEnabled[40];
 	int8 _interfaceHotspotStatus[20];
-	int8 _array16123PosX[40];
-	int8 _array1614BPosY[40];
+	int8 _characterTilePosX[40];
+	int8 _characterTilePosY[40];
 	int8 _array12811[40];
 	int8 _array10AB1[40];
 	byte _array122FD[20];
@@ -295,7 +295,7 @@ private:
 	void OC_sub1873F_snd();
 	void OC_sub18746_snd();
 	void OC_sub1875D_snd();
-	void OC_setArray128EF();
+	void OC_setCharacterMapColor();
 };
 
 } // End of namespace Lilliput


Commit: f68712fbadfb23801693110c65f8ea3e9c14c6e4
    https://github.com/scummvm/scummvm/commit/f68712fbadfb23801693110c65f8ea3e9c14c6e4
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Partially fix map closing

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 2b9f579..14b0e1c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1004,9 +1004,8 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 		return;
 
 	pollEvent();
-	if (_keyboard_checkKeyboard()) {
+	if (!_keyboard_checkKeyboard()) {
 		_keyboard_getch();
-		return;
 	} else {
 		if (_mouseButton != 1)
 			return;


Commit: 1d897d7be26105d28d95ee66b2532f5433b42338
    https://github.com/scummvm/scummvm/commit/1d897d7be26105d28d95ee66b2532f5433b42338
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a couple of errors related to the use of 0xFF instead of -1

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 14b0e1c..23d9645 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -656,7 +656,7 @@ void LilliputEngine::displayGameArea() {
 }
 
 void LilliputEngine::restoreMapPoints() {
-	debugC(2, kDebugEngineTBC, "restoreMapPoints()");
+	debugC(2, kDebugEngine, "restoreMapPoints()");
 
 	restoreSurfaceUnderMousePointer();
 
@@ -725,10 +725,10 @@ void LilliputEngine::moveCharacters() {
 
 		_scriptHandler->_characterTilePosX[i] = (_characterPositionX[i] >> 3);
 		_scriptHandler->_characterTilePosY[i] = (_characterPositionY[i] >> 3);
-		_characterRelativePositionX[i] = 0xFF;
-		_characterRelativePositionY[i] = 0xFF;
-		_characterDisplayX[i] = 0xFF;
-		_characterDisplayY[i] = 0xFF;
+		_characterRelativePositionX[i] = -1;
+		_characterRelativePositionY[i] = -1;
+		_characterDisplayX[i] = -1;
+		_characterDisplayY[i] = -1;
 
 		int tmpVal2 = (_characterPositionX[i] >> 3) - _scriptHandler->_viewportPos.x;
 		int tmpVal3 = (_characterPositionY[i] >> 3) - _scriptHandler->_viewportPos.y;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7b461af..8b5ebe3 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1089,7 +1089,7 @@ void LilliputScript::checkSpeechAllowed(bool &forceReturnFl) {
 	debugC(1, kDebugScript, "checkSpeechAllowed()");
 
 	forceReturnFl = false;
-	if ((!_vm->_displayMap) && (_vm->_characterRelativePositionX[_vm->_currentScriptCharacter] != 0xFF))
+	if ((!_vm->_displayMap) && (_vm->_characterRelativePositionX[_vm->_currentScriptCharacter] != -1))
 		return;
 
 	forceReturnFl = true;


Commit: d011a68d4f193da18dcc4da0416b0ea7d25b7614
    https://github.com/scummvm/scummvm/commit/d011a68d4f193da18dcc4da0416b0ea7d25b7614
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Start reworking _word16EFE

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 23d9645..8904b86 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -154,7 +154,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_currentScriptCharacterPos = Common::Point(0, 0);
 	_word10804 = 0;
 	_nextCharacterIndex = 0;
-	_word16EFE = 0xFFFF;
+	_word16EFE = -1;
 	_word1817B = 0;
 	_savedSurfaceUnderMousePos = Common::Point(0, 0);
 	_word15AC2 = 0;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index c58c37f..43ac74b 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -141,7 +141,7 @@ public:
 	byte _numCharacters;
 	Common::Point _currentScriptCharacterPos;
 	int _nextCharacterIndex;
-	int _word16EFE;
+	int16 _word16EFE;
 	uint16 _word1817B;
 	Common::Point _savedSurfaceUnderMousePos;
 	int _word15AC2;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 8b5ebe3..fd30b96 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2481,14 +2481,14 @@ void LilliputScript::OC_setCurrentCharacter() {
 	_vm->setCurrentCharacter(var1);
 }
 
-void LilliputScript::sub171AF(int16 var1, uint16 var2, int16 var4) {
-	debugC(2, kDebugScript, "sub171AF()");
+void LilliputScript::sub171AF(int16 var1, byte var2h, byte characterId, int16 var4) {
+	debugC(2, kDebugScript, "sub171AF(%d, %d, %d, %d)", var1, var2h, characterId, var4);
 
 	int index = 0;
 	for (int i = 0; i < 10; i++) {
 		if (_vm->_array12861[index + 1] == -1) {
 			_vm->_array12861[index + 1] = var1;
-			_vm->_array12861[index + 2] = var2;
+			_vm->_array12861[index + 2] = (var2h << 8) + characterId;
 			_vm->_array12861[index + 0] = _vm->_word1289D + var4;
 			return;
 		}
@@ -2501,10 +2501,9 @@ void LilliputScript::OC_sub17C8B() {
 
 	int16 type = 2 << 8;
 	int16 var4 = _currScript->readSint16LE();
-	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
-	uint16 var2 = (tmpVal << 8) + _vm->_currentScriptCharacter;
+	byte var2h = (_currScript->readUint16LE() & 0xFF);
 	
-	sub171AF(type, var2, var4);
+	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
 void LilliputScript::OC_sub17CA2() {
@@ -2512,21 +2511,19 @@ void LilliputScript::OC_sub17CA2() {
 
 	int16 type = 1 << 8;
 	int16 var4 = _currScript->readSint16LE();
-	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
-	uint16 var2 = (tmpVal << 8) + _vm->_currentScriptCharacter;
+	byte var2h = (_currScript->readUint16LE() & 0xFF);
 	
-	sub171AF(type, var2, var4);
+	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
 void LilliputScript::OC_sub17CB9() {
-	debugC(1, kDebugScript, "OC_sub17CB9()");
+	debugC(1, kDebugScriptTBC, "OC_sub17CB9()");
 
 	int16 var4 = _currScript->readSint16LE();
-	int16 var1 = getValue1();
-	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
-	uint16 var2 = (tmpVal << 8) + _vm->_currentScriptCharacter;
+	int16 type = getValue1();
+	byte var2h = (_currScript->readUint16LE() & 0xFF);
 	
-	sub171AF(var1, var2, var4);
+	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
 void LilliputScript::OC_sub17CD1() {
@@ -2534,16 +2531,15 @@ void LilliputScript::OC_sub17CD1() {
 
 	int16 type = 3 << 8;
 	int16 var4 = _currScript->readSint16LE();
-	int tmpVal = (_currScript->readUint16LE() & 0xFF);
-	uint16 var2 = (tmpVal << 8) + _vm->_currentScriptCharacter;
+	byte var2h = (_currScript->readUint16LE() & 0xFF);
 	
-	sub171AF(type, var2, var4);
+	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
 void LilliputScript::OC_resetWord16EFE() {
 	debugC(1, kDebugScriptTBC, "OC_resetWord16EFE()");
 
-	_vm->_word16EFE = 0xFFFF;
+	_vm->_word16EFE = -1;
 }
 
 void LilliputScript::OC_enableCurrentCharacterScript() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 59ffb4d..9500531 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -127,7 +127,7 @@ private:
 	void displayNumber(byte var1, Common::Point pos);
 	byte *getMapPtr(Common::Point val);
 	byte *getCurrentCharacterVarFromScript();
-	void sub171AF(int16 var1, uint16 var2, int16 var4);
+	void sub171AF(int16 var1, byte var2h, byte characterId, int16 var4);
 	void getSpeechVariant(int speechIndex, int speechVariant);
 	void sub189B8();
 	void formatSpeechString();


Commit: 22b3a24e5fd2e036976014840014b062a31acdae
    https://github.com/scummvm/scummvm/commit/22b3a24e5fd2e036976014840014b062a31acdae
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Renaming, fix a bug in OC_checkLastInterfaceHotspotIndexMenu2

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8904b86..2d4db24 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -134,7 +134,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_soundHandler = new LilliputSound(this);
 
 	_byte1714E = 0;
-	_byte12FCE = false;
+	_bool12FCE = false;
 	_selectedCharacterId = -1;
 	_numCharactersToDisplay = 0;
 	_nextDisplayCharacterPos = Common::Point(0, 0);
@@ -154,17 +154,17 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_currentScriptCharacterPos = Common::Point(0, 0);
 	_word10804 = 0;
 	_nextCharacterIndex = 0;
-	_word16EFE = -1;
+	_word16EFEh = -1;
+	_word16EFEl_characterId = -1;
 	_word1817B = 0;
 	_savedSurfaceUnderMousePos = Common::Point(0, 0);
-	_word15AC2 = 0;
-	_word15AC2 = 0;
+	_bool15AC2 = false;
 	_displayStringIndex = 0;
 	_word1289D = 0;
 	_numCharacters = 0;
 
 	_saveFlag = true;
-	_byte16F07_menuId = 0;
+	_actionType = kActionNone;
 
 	_array16C54[0] = _array16C58[3] = 1;
 	_array16C54[1] = _array16C58[2] = 2;
@@ -172,7 +172,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_array16C54[3] = _array16C58[0] = 8;
 
 	for (int i = 0; i < 3; i++)
-		_array147D1[i] = 0;
+		_codeEntered[i] = 0;
 
 	for (int i = 0; i < 4; i++)
 		_array1692B[i] = 0;
@@ -404,7 +404,7 @@ void LilliputEngine::displayMousePointer() {
 
 		_savedSurfaceUnderMousePos = _mouseDisplayPos;
 		SaveSurfaceUnderMouseCursor(_savedSurfaceUnderMouse, _mouseDisplayPos);
-		display16x16IndexedBuf(_bufferIdeogram, _word15AC2 + 80, _mouseDisplayPos);
+		display16x16IndexedBuf(_bufferIdeogram, _bool15AC2 ? 81 : 80, _mouseDisplayPos);
 
 		_skipDisplayFlag1 = 1;
 		_skipDisplayFlag2 = 0;
@@ -821,7 +821,7 @@ void LilliputEngine::displayRefreshScreen() {
 		sub16CA0();
 		sub16EBC();
 		sub171CF();
-		sub130EE();
+		handleGameMouseClick();
 		sub12FE5();
 		displayHeroismIndicator();
 	}
@@ -984,7 +984,7 @@ void LilliputEngine::sub15F75() {
 		return;
 
 	_savedMousePosDivided = Common::Point(newX, newY);
-	_byte16F07_menuId = 5;
+	_actionType = kActionGoto;
 }
 
 void LilliputEngine::unselectInterfaceHotspots() {
@@ -1016,7 +1016,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 
 	_displayMap = false;
 	paletteFadeOut();
-	_word15AC2 = 0;
+	_bool15AC2 = false;
 	unselectInterfaceHotspots();
 	initGameAreaDisplay();
 	_scriptHandler->_heroismLevel = 0;
@@ -1933,7 +1933,7 @@ void LilliputEngine::sub147D7() {
 		} else if (oldEvent.type == Common::EVENT_KEYUP) {
 			altKeyFl = false;
 			if (keyCount == 3)
-				_byte16F07_menuId = 6;
+				_actionType = kCodeEntered;
 			return;
 		}
 	}
@@ -1963,7 +1963,7 @@ void LilliputEngine::sub147D7() {
 		case Common::KEYCODE_7:
 		case Common::KEYCODE_8:
 		case Common::KEYCODE_9:
-			_array147D1[keyCount] = oldEvent.kbd.keycode - Common::KEYCODE_0;
+			_codeEntered[keyCount] = oldEvent.kbd.keycode - Common::KEYCODE_0;
 			++keyCount;
 			break;
 		default:
@@ -1972,8 +1972,8 @@ void LilliputEngine::sub147D7() {
 	}
 }
 
-void LilliputEngine::sub130EE() {
-	debugC(2, kDebugEngine, "sub130EE()");
+void LilliputEngine::handleGameMouseClick() {
+	debugC(2, kDebugEngine, "handleGameMouseClick()");
 
 	sub147D7();
 
@@ -2013,26 +2013,27 @@ void LilliputEngine::sub130EE() {
 	if (forceReturnFl)
 		return;
 
-	sub131FC(pos);
+	checkClickOnGameArea(pos);
 }
 
-void LilliputEngine::sub131FC(Common::Point pos) {
-	debugC(2, kDebugEngine, "sub131FC(%d, %d)", pos.x, pos.y);
+void LilliputEngine::checkClickOnGameArea(Common::Point pos) {
+	debugC(2, kDebugEngine, "checkClickOnGameArea(%d, %d)", pos.x, pos.y);
 
 	int x = pos.x - 8;
 	int y = pos.y - 4;
 
-	x = (x >> 4) - 7;
-	y = (y >> 3) - 4;
+	x = (x / 16) - 7;
+	y = (y / 8) - 4;
 
-	int diff = (y - x) >> 1;
-	y = y - diff;
+	int arrowY = (y - x) >> 1;
+	int arrowX = y - arrowY;
 
-	if ((y >= 0) && (diff >= 0) && (y < 8) && (diff < 8)) {
-		y += _scriptHandler->_viewportPos.x;
-		diff += _scriptHandler->_viewportPos.y;
-		_savedMousePosDivided = Common::Point(y, diff);
-		_byte16F07_menuId = 5;
+	// Set the arrow coordinates 
+	if ((arrowX >= 0) && (arrowY >= 0) && (arrowX < 8) && (arrowY < 8)) {
+		arrowX += _scriptHandler->_viewportPos.x;
+		arrowY += _scriptHandler->_viewportPos.y;
+		_savedMousePosDivided = Common::Point(arrowX, arrowY);
+		_actionType = kActionGoto;
 	}
 }
 
@@ -2042,11 +2043,12 @@ void LilliputEngine::checkClickOnCharacter(Common::Point pos, bool &forceReturnF
 	forceReturnFl = false;
 
 	for (int8 i = 0; i < _numCharacters; i++) {
+		// check if position is over a character
 		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_selectedCharacterId = i;
-			_byte16F07_menuId = 4;
-			if (_byte12FCE)
-				_byte16F07_menuId = 3;
+			_actionType = 4;
+			if (_bool12FCE)
+				_actionType = 3;
 
 			forceReturnFl = true;
 			return;
@@ -2086,15 +2088,15 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	_lastInterfaceHotspotButton = button;
 
 	if (button == 2) {
-		if (!_byte12FCE) {
+		if (!_bool12FCE) {
 			_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
-			_byte16F07_menuId = 2;
+			_actionType = 2;
 			displayInterfaceHotspots();
 		}
 		return;
 	}
 
-	if (_byte12FCE) {
+	if (_bool12FCE) {
 		unselectInterfaceButton();
 		return;
 	}
@@ -2102,10 +2104,10 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	unselectInterfaceHotspots();
 	_scriptHandler->_interfaceHotspotStatus[index] = kHotspotSelected;
 	if (_rulesBuffer13_1[index] == 1) {
-		_byte12FCE = true;
-		_word15AC2 = 1;
+		_bool12FCE = true;
+		_bool15AC2 = true;
 	} else {
-		_byte16F07_menuId = 1;
+		_actionType = 1;
 	}
 
 	displayInterfaceHotspots();
@@ -2794,8 +2796,8 @@ void LilliputEngine::setCurrentCharacter(int index) {
 void LilliputEngine::unselectInterfaceButton() {
 	debugC(1, kDebugEngine, "unselectInterfaceButton()");
 
-	_byte12FCE = false;
-	_word15AC2 = 0;
+	_bool12FCE = false;
+	_bool15AC2 = false;
 	_lastInterfaceHotspotButton = 0;
 	unselectInterfaceHotspots();
 	displayInterfaceHotspots();
@@ -2804,10 +2806,10 @@ void LilliputEngine::unselectInterfaceButton() {
 void LilliputEngine::handleMenu() {
 	debugC(1, kDebugEngine, "handleMenu()");
 
-	if (_byte16F07_menuId == 0)
+	if (_actionType == kActionNone)
 		return;
 
-	if (_byte12FCE && (_byte16F07_menuId != 3))
+	if (_bool12FCE && (_actionType != 3))
 		return;
 
 	setCurrentCharacter(_word10804);
@@ -2817,10 +2819,10 @@ void LilliputEngine::handleMenu() {
 	_savedMousePosDivided = Common::Point(-1, -1);
 	_selectedCharacterId = -1;
 
-	if (_byte16F07_menuId == 3)
+	if (_actionType == 3)
 		unselectInterfaceButton();
 
-	_byte16F07_menuId = 0;
+	_actionType = kActionNone;
 }
 
 void LilliputEngine::handleGameScripts() {
@@ -2844,7 +2846,8 @@ void LilliputEngine::handleGameScripts() {
 	setCurrentCharacter(index);
 
 
-	_word16EFE = _array11D49[index];
+	_word16EFEh = _array11D49[index] >> 8;
+	_word16EFEl_characterId = _array11D49[index] & 0xFF;
 	_array11D49[index] = -1;
 	_word1817B = 0;
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 43ac74b..27f123c 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -122,7 +122,7 @@ public:
 	byte _debugFlag; // Mostly useless, as the associated functions are empty
 	byte _byte14837; // Unused byte, set by an opcode
 
-	byte _array147D1[3];
+	byte _codeEntered[3];
 	char _array1692B[4];
 	byte *_bufferIsoMap;
 	byte *_bufferCubegfx;
@@ -141,10 +141,11 @@ public:
 	byte _numCharacters;
 	Common::Point _currentScriptCharacterPos;
 	int _nextCharacterIndex;
-	int16 _word16EFE;
+	int8 _word16EFEh;
+	int8 _word16EFEl_characterId;
 	uint16 _word1817B;
 	Common::Point _savedSurfaceUnderMousePos;
-	int _word15AC2;
+	bool _bool15AC2;
 	int _currentDisplayCharacter;
 	int _displayStringIndex;
 	int _word1289D;
@@ -291,12 +292,12 @@ public:
 	void displayCharactersOnMap();
 	void restoreMapPoints();
 	void displayHeroismIndicator();
-	void sub130EE();
+	void handleGameMouseClick();
 	void sub1305C(byte index, byte var2);
 	void checkInterfaceHotspots(bool &forceReturnFl);
 	bool isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos);
 	void checkClickOnCharacter(Common::Point pos, bool &forceReturnFl);
-	void sub131FC(Common::Point pos);
+	void checkClickOnGameArea(Common::Point pos);
 	void displaySpeechBubbleTail(Common::Point displayPos);
 	void displaySpeechBubbleTailLine(Common::Point pos, int var2);
 	void displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex);
@@ -346,8 +347,8 @@ public:
 	int _skipDisplayFlag1;
 	int _skipDisplayFlag2;
 
-	byte _byte16F07_menuId;
-	bool _byte12FCE;
+	byte _actionType;
+	bool _bool12FCE;
 	int8 _selectedCharacterId;
 	byte _numCharactersToDisplay;
 	int16 _word10804;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index fd30b96..a4eae7f 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -36,7 +36,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	_byte18823 = 0;
 	_speechDisplaySpeed = 3;
 	_speechTimer = 0;
-	_word16F00 = -1;
+	_word16F00_characterId = -1;
 	_word129A3 = 0;
 	_viewportCharacterTarget = -1;
 	_heroismBarX = 0;
@@ -229,7 +229,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_checkFunctionKeyPressed();
 		break;
 	case 0x30:
-		return OC_sub17A07();
+		return OC_checkCodeEntered();
 		break;
 	case 0x31:
 		return OC_checkViewPortCharacterTarget();
@@ -604,7 +604,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub179AE", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_checkFunctionKeyPressed", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub17A07", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
+	{ "OC_checkCodeEntered", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
 	{ "OC_checkViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
 };
 
@@ -730,7 +730,7 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 		} else if (val == 1001) {
 			str = Common::String("characterIndex");
 		} else if (val == 1002) {
-			str = Common::String("_word16F00");
+			str = Common::String("_word16F00_characterId");
 		} else if (val == 1003) {
 			str = Common::String("_currentCharacterVariables[6]");
 		} else if (val == 1004) {
@@ -759,7 +759,7 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 		break;
 			   }
 	case 0xFB: {
-		str = "(characterPositionTileX[_word16F00], characterPositionTileY[_word16F00])";
+		str = "(characterPositionTileX[_word16F00_characterId], characterPositionTileY[_word16F00_characterId])";
 		break;
 			   }
 	case 0xFA:
@@ -1289,7 +1289,7 @@ int16 LilliputScript::getValue1() {
 	case 1001:
 		return _vm->_currentScriptCharacter;
 	case 1002:
-		return _word16F00;
+		return _word16F00_characterId;
 	case 1003:
 		return (int16)_vm->_currentCharacterVariables[6];
 	case 1004:
@@ -1325,7 +1325,7 @@ Common::Point LilliputScript::getPosFromScript() {
 		return Common::Point(x, y);
 		}
 	case 0xFB: {
-		int index = _word16F00;
+		int index = _word16F00_characterId;
 		assert((index >= 0) && (index < 40));
 		int16 x = _vm->_characterPositionX[index] >> 3;
 		int16 y = _vm->_characterPositionY[index] >> 3;
@@ -1499,7 +1499,7 @@ byte LilliputScript::OC_sub174D8() {
 	if (curWord == 3000) {
 		for (int index = 0; index < _vm->_numCharacters; index++) {
 			if (_vm->_rulesBuffer2_5[index] == tmpVal) {
-				_word16F00 = index;
+				_word16F00_characterId = index;
 				return 1;
 			}
 		}
@@ -1508,7 +1508,7 @@ byte LilliputScript::OC_sub174D8() {
 		int index = getValue1();
 		assert(index < 40);
 		if (_vm->_rulesBuffer2_5[index] == tmpVal) {
-			_word16F00 = index;
+			_word16F00_characterId = index;
 			return 1;
 		}
 	}
@@ -1617,7 +1617,7 @@ byte LilliputScript::OC_sub175C8() {
 		if ((var1 & 0xFF) < var4)
 			return 0;
 		
-		_word16F00 = index;
+		_word16F00_characterId = index;
 		return 1;
 	}
 
@@ -1625,7 +1625,7 @@ byte LilliputScript::OC_sub175C8() {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
 			int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
 			if ((var1 & 0xFF) >= var4) {
-				_word16F00 = i;
+				_word16F00_characterId = i;
 				return 1;
 			}
 		}
@@ -1637,7 +1637,7 @@ byte LilliputScript::OC_sub175C8() {
 	for (int i = 0; i < _vm->_numCharacters; i++) {
 		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
 		if (((var1 & 0xFF) >= var4) && (_vm->_rulesBuffer2_12[i] == var4b)) {
-			_word16F00 = i;
+			_word16F00_characterId = i;
 			return 1;
 		}
 	}	
@@ -1660,7 +1660,7 @@ byte LilliputScript::OC_sub17640() {
 		byte v2 = tmpVal >> 8;
 		if ((v1 < (var4 & 0xFF)) || (v2 >= (var4 & 0xFF)))
 			return 0;
-		_word16F00 = subIndex;
+		_word16F00_characterId = subIndex;
 		return 1;
 	}
 
@@ -1671,7 +1671,7 @@ byte LilliputScript::OC_sub17640() {
 			byte v1 = tmpVal & 0xFF;
 			byte v2 = tmpVal >> 8;
 			if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF))) {
-				_word16F00 = i;
+				_word16F00_characterId = i;
 				return 1;
 			}
 		}
@@ -1685,7 +1685,7 @@ byte LilliputScript::OC_sub17640() {
 		byte v1 = tmpVal & 0xFF;
 		byte v2 = tmpVal >> 8;
 		if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF)) && (_vm->_rulesBuffer2_12[i] == (var4 >> 8))) {
-			_word16F00 = i;
+			_word16F00_characterId = i;
 			return 1;
 		}
 	}
@@ -1706,7 +1706,7 @@ byte LilliputScript::OC_sub176C4() {
 		if (((var1 & 0xFF) >= var4) || ((var1 >> 8) < var4))
 			return 0;
 		
-		_word16F00 = index;
+		_word16F00_characterId = index;
 		return 1;
 	}
 
@@ -1714,7 +1714,7 @@ byte LilliputScript::OC_sub176C4() {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
 			int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
 			if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
-				_word16F00 = i;
+				_word16F00_characterId = i;
 				return 1;
 			}
 		}
@@ -1727,7 +1727,7 @@ byte LilliputScript::OC_sub176C4() {
 		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
 		if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
 			if (_vm->_rulesBuffer2_12[i] == var4b) {
-				_word16F00 = i;
+				_word16F00_characterId = i;
 				return 1;
 			}
 		}
@@ -1804,12 +1804,12 @@ byte LilliputScript::OC_compWord16EFE() {
 	debugC(1, kDebugScript, "OC_compWord16EFE()");
 
 	byte curByte = _currScript->readUint16LE() & 0xFF;
-	byte tmpVal = _vm->_word16EFE >> 8;
+	byte tmpVal = _vm->_word16EFEh;
 
 	if (curByte != tmpVal)
 		return 0;
 
-	_word16F00 = (_vm->_word16EFE & 0xFF);
+	_word16F00_characterId = _vm->_word16EFEl_characterId;
 	return 1;
 }
 
@@ -1842,7 +1842,7 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu13() {
 
 	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
 	
-	if ((_vm->_byte16F07_menuId != 1) && (_vm->_byte16F07_menuId != 3))
+	if ((_vm->_actionType != 1) && (_vm->_actionType != 3))
 		return 0;
 
 	if (tmpVal == _vm->_lastInterfaceHotspotIndex)
@@ -1856,7 +1856,7 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu2() {
 
 	int8 hotspotIndex = (_currScript->readUint16LE() & 0xFF);
 
-	if ((_vm->_byte16F07_menuId == 2) || (hotspotIndex == _vm->_lastInterfaceHotspotIndex))
+	if ((_vm->_actionType == 2) && (hotspotIndex == _vm->_lastInterfaceHotspotIndex))
 		return 1;
 
 	return 0;
@@ -1963,7 +1963,7 @@ byte LilliputScript::OC_sub1790F() {
 	if (_vm->_rulesBuffer2_5[index] == -1)
 		return 0;
 
-	_word16F00 = _vm->_rulesBuffer2_5[index];
+	_word16F00_characterId = _vm->_rulesBuffer2_5[index];
 
 	return 1;
 }
@@ -2039,7 +2039,7 @@ byte LilliputScript::OC_checkSelectedCharacter() {
 byte LilliputScript::OC_sub179AE() {
 	debugC(1, kDebugScript, "OC_sub179AE()");
 
-	if (_vm->_byte12FCE || (_vm->_selectedCharacterId == -1))
+	if (_vm->_bool12FCE || (_vm->_selectedCharacterId == -1))
 		return 0;
 
 	return 1;
@@ -2070,18 +2070,18 @@ byte LilliputScript::OC_checkFunctionKeyPressed() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub17A07() {
-	debugC(1, kDebugScript, "OC_sub17A07()");
+byte LilliputScript::OC_checkCodeEntered() {
+	debugC(1, kDebugScript, "OC_checkCodeEntered()");
 
-	static const byte array179FD[10] = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+	static const byte solutionArr[10] = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 
-	if (_vm->_byte16F07_menuId == 6) {
+	if (_vm->_actionType == kCodeEntered) {
 		uint16 index = _currScript->readUint16LE();
-		if (array179FD[index] == _vm->_array147D1[0]) {
+		if (solutionArr[index] == _vm->_codeEntered[0]) {
 			index = _currScript->readUint16LE();
-			if (array179FD[index] == _vm->_array147D1[1]) {
+			if (solutionArr[index] == _vm->_codeEntered[1]) {
 				index = _currScript->readUint16LE();
-				if (array179FD[index] == _vm->_array147D1[2]) {
+				if (solutionArr[index] == _vm->_codeEntered[2]) {
 					return 1;
 				}
 			} else
@@ -2537,9 +2537,10 @@ void LilliputScript::OC_sub17CD1() {
 }
 
 void LilliputScript::OC_resetWord16EFE() {
-	debugC(1, kDebugScriptTBC, "OC_resetWord16EFE()");
+	debugC(1, kDebugScript, "OC_resetWord16EFE()");
 
-	_vm->_word16EFE = -1;
+	_vm->_word16EFEh = -1;
+	_vm->_word16EFEl_characterId = -1;
 }
 
 void LilliputScript::OC_enableCurrentCharacterScript() {
@@ -3110,7 +3111,7 @@ void LilliputScript::OC_loadFileAerial() {
 	_vm->_refreshScreenFlag = true;
 	_talkingCharacter = -1;
 	OC_PaletteFadeOut();
-	_vm->_word15AC2 = 1;
+	_vm->_bool15AC2 = true;
 	_vm->displayVGAFile("AERIAL.GFX");
 	OC_PaletteFadeIn();
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 9500531..1c02021 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -34,6 +34,12 @@ namespace Lilliput {
 
 class LilliputEngine;
 
+enum kActionType {
+	kActionNone = 0,
+	kActionGoto = 5,
+	kCodeEntered = 6
+};
+
 enum KValueType {
 	kNone,
 	kImmediateValue,
@@ -105,7 +111,7 @@ private:
 	byte _byte18823;
 	byte _speechDisplaySpeed;
 
-	int16 _word16F00;
+	int16 _word16F00_characterId;
 	int _currentSpeechId;
 	int _word18821;
 	int _word129A3;
@@ -190,7 +196,7 @@ private:
 	byte OC_sub179AE();
 	byte OC_sub179C2();
 	byte OC_checkFunctionKeyPressed();
-	byte OC_sub17A07();
+	byte OC_checkCodeEntered();
 	byte OC_checkViewPortCharacterTarget();
 
 	// Opcodes Type 2


Commit: 2832980e9290a4d0e2142576372cf2ed3962d7b6
    https://github.com/scummvm/scummvm/commit/2832980e9290a4d0e2142576372cf2ed3962d7b6
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming, remove double variable

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 2d4db24..bb220ca 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -133,21 +133,20 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_scriptHandler = new LilliputScript(this);
 	_soundHandler = new LilliputSound(this);
 
-	_byte1714E = 0;
+	_handleOpcodeReturnCode = 0;
 	_bool12FCE = false;
 	_selectedCharacterId = -1;
 	_numCharactersToDisplay = 0;
 	_nextDisplayCharacterPos = Common::Point(0, 0);
 	_animationTick = 0;
-	_byte12A05 = 10;
-	_byte12A06 = 2;
-	_byte12A07 = 0;
-	_byte12A08 = 0;
+	_byte12A05 = 10; // Used to trigger sound and animations in int8, 1 time out of 10
+	_byte12A06 = 2;  // Used to switch _byte12A07 between true and false, 1 time our of 3
+	_byte12A07 = 0;  // Set but never used
+	_byte12A08 = 0;  // Used to avoid two executions of int8 at the same time. Useless in ScummVM
 	_refreshScreenFlag = false;
 	_byte16552 = 0;
 	_lastInterfaceHotspotIndex = -1;
 	_lastInterfaceHotspotButton = 0;
-	_byte16F08 = 0;
 	_lastAnimationTick = 0;
 
 	_currentScriptCharacter = 0;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 27f123c..534a438 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -99,7 +99,7 @@ public:
 	SmallAnim _smallAnims[4];
 	int _smallAnimsFrameIndex;
 
-	byte _byte1714E;
+	byte _handleOpcodeReturnCode;
 	byte _byte184F4;
 	byte _lastAnimationTick;
 	byte _animationTick;
@@ -118,7 +118,6 @@ public:
 	byte _byte16552;
 	int8 _lastInterfaceHotspotIndex;
 	byte _lastInterfaceHotspotButton; // Unused: set by 2 functions, but never used elsewhere
-	byte _byte16F08;
 	byte _debugFlag; // Mostly useless, as the associated functions are empty
 	byte _byte14837; // Unused byte, set by an opcode
 
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a4eae7f..ce4d9b1 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -31,7 +31,7 @@ namespace Lilliput {
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
 	_byte10806 = 0;
 	_lastRandomValue = 0;
-	_byte16F04 = 0;
+	_scriptForVal = 0;
 	_byte1881A = 0;
 	_byte18823 = 0;
 	_speechDisplaySpeed = 3;
@@ -112,7 +112,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_checkSaveFlag();
 		break;
 	case 0x9:
-		return OC_compByte16F04();
+		return OC_compScriptForVal();
 		break;
 	case 0xA:
 		return OC_sub174D8();
@@ -295,7 +295,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_deleteSavegameAndQuit();
 		break;
 	case 0x11:
-		OC_incByte16F04();
+		OC_incScriptForVal();
 		break;
 	case 0x12:
 		OC_sub17BA5();
@@ -313,7 +313,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setCurrentScriptCharacterPos();
 		break;
 	case 0x17:
-		OC_resetByte16F04();
+		OC_initScriptFor();
 		break;
 	case 0x18:
 		OC_sub17AE1();
@@ -565,7 +565,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_for", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_compCurrentSpeechId", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_checkSaveFlag", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_compByte16F04", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_compScriptForVal", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_sub174D8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
 	{ "OC_CompareCharacterVariables", 5, kGetValue1, kImmediateValue, kCompareOperation, kGetValue1, kImmediateValue },
 	{ "OC_compareCoords_1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
@@ -627,13 +627,13 @@ static const OpCode opCodes2[] = {
 /* 0x0e */	{ "OC_startSpeech5", 0, kNone, kNone, kNone, kNone, kNone },  // todo
 /* 0x0f */	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x10 */	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },  
-/* 0x11 */	{ "OC_incByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
+/* 0x11 */	{ "OC_incScriptForVal", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x12 */	{ "OC_sub17BA5", 5, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
 /* 0x13 */	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
 /* 0x14 */	{ "OC_callScript", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script
 /* 0x15 */	{ "OC_callScriptAndReturn", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script then stop
 /* 0x16 */	{ "OC_setCurrentScriptCharacterPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },  
-/* 0x17 */	{ "OC_resetByte16F04", 0, kNone, kNone, kNone, kNone, kNone },  
+/* 0x17 */	{ "OC_initScriptFor", 0, kNone, kNone, kNone, kNone, kNone },  
 /* 0x18 */	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
 /* 0x19 */	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
 /* 0x1a */	{ "OC_setWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },  
@@ -860,10 +860,10 @@ void LilliputScript::disasmScript(ScriptStream script) {
 				str += ")";
 			}
 
-			debugC(2, kDebugScriptTBC, "%s", str.c_str());
+			debugC(2, kDebugScript, "%s", str.c_str());
 		}
 
-		debugC(2, kDebugScriptTBC, "{ ");
+		debugC(2, kDebugScript, "{ ");
 
 		val = script.readUint16LE();
 
@@ -891,13 +891,13 @@ void LilliputScript::disasmScript(ScriptStream script) {
 			}
 			str += ");";
 
-			debugC(2, kDebugScriptTBC, "%s", str.c_str());
+			debugC(2, kDebugScript, "%s", str.c_str());
 
 			val = script.readUint16LE();
 		}
 
-		debugC(2, kDebugScriptTBC, "} ");
-		debugC(2, kDebugScriptTBC, " ");
+		debugC(2, kDebugScript, "} ");
+		debugC(2, kDebugScript, " ");
 	}
 }
 
@@ -924,12 +924,12 @@ int LilliputScript::handleOpcode(ScriptStream *script) {
 		}
 	}
 
-	_vm->_byte1714E = 1;
+	_vm->_handleOpcodeReturnCode = 1;
 
 	for (;;) {
 		curWord = _currScript->readUint16LE();
 		if (curWord == 0xFFF7)
-			return _vm->_byte1714E;
+			return _vm->_handleOpcodeReturnCode;
 
 		handleOpcodeType2(curWord);
 	}
@@ -1481,13 +1481,13 @@ byte LilliputScript::OC_checkSaveFlag() {
 	return 0;
 }
 
-byte LilliputScript::OC_compByte16F04() {
-	debugC(1, kDebugScriptTBC, "OC_compByte16F04()");
+byte LilliputScript::OC_compScriptForVal() {
+	debugC(1, kDebugScriptTBC, "OC_compScriptForVal()");
 
 	uint16 oper = _currScript->readUint16LE();
 	int16 var2 = _currScript->readUint16LE();
 
-	return compareValues(_byte16F04, oper, var2);
+	return compareValues(_scriptForVal, oper, var2);
 }
 
 byte LilliputScript::OC_sub174D8() {
@@ -2330,7 +2330,7 @@ void LilliputScript::OC_startSpeech5() {
 void LilliputScript::OC_resetByte1714E() {
 	debugC(1, kDebugScriptTBC, "OC_resetByte1714E()");
 
-	_vm->_byte1714E = 0;
+	_vm->_handleOpcodeReturnCode = 0;
 }
 
 void LilliputScript::OC_deleteSavegameAndQuit() {
@@ -2338,10 +2338,10 @@ void LilliputScript::OC_deleteSavegameAndQuit() {
 	_vm->_shouldQuit = true;
 }
 
-void LilliputScript::OC_incByte16F04() {
-	debugC(1, kDebugScriptTBC, "OC_incByte16F04()");
+void LilliputScript::OC_incScriptForVal() {
+	debugC(1, kDebugScriptTBC, "OC_incScriptForVal()");
 
-	++_byte16F04;
+	++_scriptForVal;
 }
 
 void LilliputScript::OC_sub17BA5() {
@@ -2364,9 +2364,10 @@ void LilliputScript::OC_callScript() {
 	debugC(1, kDebugScript, "OC_callScript()");
 
 	int index = _currScript->readUint16LE();
-	int var1 = getValue1();
 
-	_vm->setCurrentCharacter(var1);
+	int charIndex = getValue1();
+	_vm->setCurrentCharacter(charIndex);
+
 	int tmpIndex = _vm->_currentScriptCharacter;
 
 	assert(index < _vm->_gameScriptIndexSize);
@@ -2375,10 +2376,10 @@ void LilliputScript::OC_callScript() {
 	_scriptStack.push(_currScript);
 
 	if (_byte16F05_ScriptHandler == 0) {
-		_vm->_byte1714E = 0;
-		debugC(1, kDebugScriptTBC, "========================== Menu Script %d==============================", scriptIndex);
+		_vm->_handleOpcodeReturnCode = 0;
+		debugC(1, kDebugScript, "========================== Menu Script %d==============================", scriptIndex);
 		runMenuScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
-		debugC(1, kDebugScriptTBC, "========================== End of Menu Script==============================");
+		debugC(1, kDebugScript, "========================== End of Menu Script==============================");
 	} else {
 		runScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index]));
 	}
@@ -2404,10 +2405,10 @@ void LilliputScript::OC_setCurrentScriptCharacterPos() {
 	_vm->_array109E9PosX[_vm->_currentScriptCharacter] = -1;
 }
 
-void LilliputScript::OC_resetByte16F04() {
-	debugC(1, kDebugScriptTBC, "OC_resetByte16F04()");
+void LilliputScript::OC_initScriptFor() {
+	debugC(1, kDebugScriptTBC, "OC_initScriptFor()");
 
-	_byte16F04 = 0;
+	_scriptForVal = 0;
 }
 
 void LilliputScript::OC_sub17AE1() {
@@ -2477,8 +2478,8 @@ void LilliputScript::OC_sub17C76() {
 
 void LilliputScript::OC_setCurrentCharacter() {
 	debugC(1, kDebugScript, "OC_setCurrentCharacter()");
-	int var1 = getValue1();
-	_vm->setCurrentCharacter(var1);
+	int index = getValue1();
+	_vm->setCurrentCharacter(index);
 }
 
 void LilliputScript::sub171AF(int16 var1, byte var2h, byte characterId, int16 var4) {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 1c02021..c606494 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -106,7 +106,7 @@ private:
 	byte _byte16F05_ScriptHandler;
 	byte _byte10806;
 	byte _lastRandomValue;
-	byte _byte16F04;
+	byte _scriptForVal;
 	byte _byte1881A;
 	byte _byte18823;
 	byte _speechDisplaySpeed;
@@ -157,7 +157,7 @@ private:
 	byte OC_for();
 	byte OC_compCurrentSpeechId();
 	byte OC_checkSaveFlag();
-	byte OC_compByte16F04();
+	byte OC_compScriptForVal();
 	byte OC_sub174D8();
 	byte OC_CompareCharacterVariables();
 	byte OC_compareCoords_1();
@@ -217,13 +217,13 @@ private:
 	void OC_startSpeech5();
 	void OC_resetByte1714E();
 	void OC_deleteSavegameAndQuit();
-	void OC_incByte16F04();
+	void OC_incScriptForVal();
 	void OC_sub17BA5();
 	void OC_setByte18823();
 	void OC_callScript();
 	void OC_callScriptAndReturn();
 	void OC_setCurrentScriptCharacterPos();
-	void OC_resetByte16F04();
+	void OC_initScriptFor();
 	void OC_sub17AE1();
 	void OC_sub17AEE();
 	void OC_setWord10804();


Commit: b2d49cef83d88769eb80df02171be49e0adeec75
    https://github.com/scummvm/scummvm/commit/b2d49cef83d88769eb80df02171be49e0adeec75
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index bb220ca..be9f42e 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -134,7 +134,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_soundHandler = new LilliputSound(this);
 
 	_handleOpcodeReturnCode = 0;
-	_bool12FCE = false;
+	_mouthSelected = false;
 	_selectedCharacterId = -1;
 	_numCharactersToDisplay = 0;
 	_nextDisplayCharacterPos = Common::Point(0, 0);
@@ -983,7 +983,7 @@ void LilliputEngine::sub15F75() {
 		return;
 
 	_savedMousePosDivided = Common::Point(newX, newY);
-	_actionType = kActionGoto;
+	_actionType = 5;
 }
 
 void LilliputEngine::unselectInterfaceHotspots() {
@@ -2027,12 +2027,11 @@ void LilliputEngine::checkClickOnGameArea(Common::Point pos) {
 	int arrowY = (y - x) >> 1;
 	int arrowX = y - arrowY;
 
-	// Set the arrow coordinates 
 	if ((arrowX >= 0) && (arrowY >= 0) && (arrowX < 8) && (arrowY < 8)) {
 		arrowX += _scriptHandler->_viewportPos.x;
 		arrowY += _scriptHandler->_viewportPos.y;
 		_savedMousePosDivided = Common::Point(arrowX, arrowY);
-		_actionType = kActionGoto;
+		_actionType = 5;
 	}
 }
 
@@ -2045,9 +2044,9 @@ void LilliputEngine::checkClickOnCharacter(Common::Point pos, bool &forceReturnF
 		// check if position is over a character
 		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_selectedCharacterId = i;
-			_actionType = 4;
-			if (_bool12FCE)
-				_actionType = 3;
+			_actionType = kActionGoto;
+			if (_mouthSelected)
+				_actionType = kActionTalk;
 
 			forceReturnFl = true;
 			return;
@@ -2087,7 +2086,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	_lastInterfaceHotspotButton = button;
 
 	if (button == 2) {
-		if (!_bool12FCE) {
+		if (!_mouthSelected) {
 			_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
 			_actionType = 2;
 			displayInterfaceHotspots();
@@ -2095,7 +2094,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 		return;
 	}
 
-	if (_bool12FCE) {
+	if (_mouthSelected) {
 		unselectInterfaceButton();
 		return;
 	}
@@ -2103,7 +2102,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	unselectInterfaceHotspots();
 	_scriptHandler->_interfaceHotspotStatus[index] = kHotspotSelected;
 	if (_rulesBuffer13_1[index] == 1) {
-		_bool12FCE = true;
+		_mouthSelected = true;
 		_bool15AC2 = true;
 	} else {
 		_actionType = 1;
@@ -2795,7 +2794,7 @@ void LilliputEngine::setCurrentCharacter(int index) {
 void LilliputEngine::unselectInterfaceButton() {
 	debugC(1, kDebugEngine, "unselectInterfaceButton()");
 
-	_bool12FCE = false;
+	_mouthSelected = false;
 	_bool15AC2 = false;
 	_lastInterfaceHotspotButton = 0;
 	unselectInterfaceHotspots();
@@ -2808,7 +2807,7 @@ void LilliputEngine::handleMenu() {
 	if (_actionType == kActionNone)
 		return;
 
-	if (_bool12FCE && (_actionType != 3))
+	if (_mouthSelected && (_actionType != kActionTalk))
 		return;
 
 	setCurrentCharacter(_word10804);
@@ -2818,7 +2817,7 @@ void LilliputEngine::handleMenu() {
 	_savedMousePosDivided = Common::Point(-1, -1);
 	_selectedCharacterId = -1;
 
-	if (_actionType == 3)
+	if (_actionType == kActionTalk)
 		unselectInterfaceButton();
 
 	_actionType = kActionNone;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 534a438..ca2d3fd 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -347,7 +347,7 @@ public:
 	int _skipDisplayFlag2;
 
 	byte _actionType;
-	bool _bool12FCE;
+	bool _mouthSelected;
 	int8 _selectedCharacterId;
 	byte _numCharactersToDisplay;
 	int16 _word10804;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index ce4d9b1..f868d86 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1842,7 +1842,7 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu13() {
 
 	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
 	
-	if ((_vm->_actionType != 1) && (_vm->_actionType != 3))
+	if ((_vm->_actionType != 1) && (_vm->_actionType != kActionTalk))
 		return 0;
 
 	if (tmpVal == _vm->_lastInterfaceHotspotIndex)
@@ -2039,7 +2039,7 @@ byte LilliputScript::OC_checkSelectedCharacter() {
 byte LilliputScript::OC_sub179AE() {
 	debugC(1, kDebugScript, "OC_sub179AE()");
 
-	if (_vm->_bool12FCE || (_vm->_selectedCharacterId == -1))
+	if (_vm->_mouthSelected || (_vm->_selectedCharacterId == -1))
 		return 0;
 
 	return 1;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index c606494..c8744a5 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -36,7 +36,8 @@ class LilliputEngine;
 
 enum kActionType {
 	kActionNone = 0,
-	kActionGoto = 5,
+	kActionTalk = 3,
+	kActionGoto = 4,
 	kCodeEntered = 6
 };
 


Commit: f0abb4f6560aadd824855f97ca31186f6df94023
    https://github.com/scummvm/scummvm/commit/f0abb4f6560aadd824855f97ca31186f6df94023
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index be9f42e..945fa87 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -134,7 +134,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_soundHandler = new LilliputSound(this);
 
 	_handleOpcodeReturnCode = 0;
-	_mouthSelected = false;
+	_delayedReactivationAction = false;
 	_selectedCharacterId = -1;
 	_numCharactersToDisplay = 0;
 	_nextDisplayCharacterPos = Common::Point(0, 0);
@@ -1914,8 +1914,8 @@ void LilliputEngine::sub13156(bool &forceReturnFl) {
 	}
 }
 
-void LilliputEngine::sub147D7() {
-	debugC(2, kDebugEngine, "sub147D7()");
+void LilliputEngine::checkNumericCode() {
+	debugC(2, kDebugEngine, "checkNumericCode()");
 
 	static bool altKeyFl = false;
 	static int16 keyCount = 0;
@@ -1974,7 +1974,7 @@ void LilliputEngine::sub147D7() {
 void LilliputEngine::handleGameMouseClick() {
 	debugC(2, kDebugEngine, "handleGameMouseClick()");
 
-	sub147D7();
+	checkNumericCode();
 
 	bool forceReturnFl = false;
 	sub13156(forceReturnFl);
@@ -2045,7 +2045,7 @@ void LilliputEngine::checkClickOnCharacter(Common::Point pos, bool &forceReturnF
 		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
 			_selectedCharacterId = i;
 			_actionType = kActionGoto;
-			if (_mouthSelected)
+			if (_delayedReactivationAction)
 				_actionType = kActionTalk;
 
 			forceReturnFl = true;
@@ -2086,7 +2086,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	_lastInterfaceHotspotButton = button;
 
 	if (button == 2) {
-		if (!_mouthSelected) {
+		if (!_delayedReactivationAction) {
 			_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
 			_actionType = 2;
 			displayInterfaceHotspots();
@@ -2094,7 +2094,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 		return;
 	}
 
-	if (_mouthSelected) {
+	if (_delayedReactivationAction) {
 		unselectInterfaceButton();
 		return;
 	}
@@ -2102,7 +2102,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	unselectInterfaceHotspots();
 	_scriptHandler->_interfaceHotspotStatus[index] = kHotspotSelected;
 	if (_rulesBuffer13_1[index] == 1) {
-		_mouthSelected = true;
+		_delayedReactivationAction = true;
 		_bool15AC2 = true;
 	} else {
 		_actionType = 1;
@@ -2555,7 +2555,7 @@ byte *LilliputEngine::loadRaw(Common::String filename, int filesize) {
 void LilliputEngine::loadRules() {
 	debugC(1, kDebugEngine, "loadRules()");
 
-	static const Common::KeyCode _rulesXlatArray[26] = {
+	static const Common::KeyCode keybMappingArray[26] = {
 		Common::KEYCODE_a, Common::KEYCODE_b, Common::KEYCODE_c, Common::KEYCODE_d, Common::KEYCODE_e,
 		Common::KEYCODE_f, Common::KEYCODE_g, Common::KEYCODE_h, Common::KEYCODE_i, Common::KEYCODE_j,
 		Common::KEYCODE_k, Common::KEYCODE_l, Common::KEYCODE_m, Common::KEYCODE_n, Common::KEYCODE_o, 
@@ -2732,7 +2732,7 @@ void LilliputEngine::loadRules() {
 			_keyboardMapping[i] = Common::KEYCODE_INVALID; // 0xB4; ?
 		else {
 			assert((curByte > 0x40) && (curByte <= 0x41 + 26));
-			_keyboardMapping[i] = _rulesXlatArray[curByte - 0x41];
+			_keyboardMapping[i] = keybMappingArray[curByte - 0x41];
 		}
 	}
 	f.close();
@@ -2794,7 +2794,7 @@ void LilliputEngine::setCurrentCharacter(int index) {
 void LilliputEngine::unselectInterfaceButton() {
 	debugC(1, kDebugEngine, "unselectInterfaceButton()");
 
-	_mouthSelected = false;
+	_delayedReactivationAction = false;
 	_bool15AC2 = false;
 	_lastInterfaceHotspotButton = 0;
 	unselectInterfaceHotspots();
@@ -2807,7 +2807,7 @@ void LilliputEngine::handleMenu() {
 	if (_actionType == kActionNone)
 		return;
 
-	if (_mouthSelected && (_actionType != kActionTalk))
+	if (_delayedReactivationAction && (_actionType != kActionTalk))
 		return;
 
 	setCurrentCharacter(_word10804);
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index ca2d3fd..2ea4a57 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -273,7 +273,7 @@ public:
 
 	void renderCharacters(byte *buf, Common::Point pos);
 
-	void sub147D7();
+	void checkNumericCode();
 	void sub13156(bool &forceReturnFl);
 	byte sub16799(int index, Common::Point param1);
 	byte getDirection(Common::Point param1, Common::Point param2);
@@ -347,7 +347,7 @@ public:
 	int _skipDisplayFlag2;
 
 	byte _actionType;
-	bool _mouthSelected;
+	bool _delayedReactivationAction;
 	int8 _selectedCharacterId;
 	byte _numCharactersToDisplay;
 	int16 _word10804;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index f868d86..e6e4df2 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -220,7 +220,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_checkSelectedCharacter();
 		break;
 	case 0x2D:
-		return OC_sub179AE();
+		return OC_checkDelayedReactivation();
 		break;
 	case 0x2E:
 		return OC_sub179C2();
@@ -601,7 +601,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkLastInterfaceHotspotIndex", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkSelectedCharacter", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_sub179AE", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_checkDelayedReactivation", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_checkFunctionKeyPressed", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_checkCodeEntered", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
@@ -2036,10 +2036,10 @@ byte LilliputScript::OC_checkSelectedCharacter() {
 	return 1;
 }
 
-byte LilliputScript::OC_sub179AE() {
-	debugC(1, kDebugScript, "OC_sub179AE()");
+byte LilliputScript::OC_checkDelayedReactivation() {
+	debugC(1, kDebugScript, "OC_checkDelayedReactivation()");
 
-	if (_vm->_mouthSelected || (_vm->_selectedCharacterId == -1))
+	if (_vm->_delayedReactivationAction || (_vm->_selectedCharacterId == -1))
 		return 0;
 
 	return 1;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index c8744a5..240da58 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -194,7 +194,7 @@ private:
 	byte OC_checkCharacterDirection();
 	byte OC_checkLastInterfaceHotspotIndex();
 	byte OC_checkSelectedCharacter();
-	byte OC_sub179AE();
+	byte OC_checkDelayedReactivation();
 	byte OC_sub179C2();
 	byte OC_checkFunctionKeyPressed();
 	byte OC_checkCodeEntered();


Commit: 9f93ceb8aa9e05f85b547326601d619aa572ce44
    https://github.com/scummvm/scummvm/commit/9f93ceb8aa9e05f85b547326601d619aa572ce44
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in interface button re-activation

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 945fa87..21790c5 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2350,13 +2350,12 @@ void LilliputEngine::sub12FE5() {
 	if (_animationTick != 1)
 		return;
 
-	int index = 0;
 	int count = 0;
 	for (int i = 0; i < _interfaceHotspotNumb; i++) {
-		if (_scriptHandler->_array122FD[index] != 0) {
-			--_scriptHandler->_array122FD[index];
-			if (_scriptHandler->_array122FD[index] == 0) {
-				_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
+		if (_scriptHandler->_array122FD[i] != 0) {
+			--_scriptHandler->_array122FD[i];
+			if (_scriptHandler->_array122FD[i] == 0) {
+				_scriptHandler->_interfaceHotspotStatus[i] = kHotspotEnabled;
 				++count;
 			}
 		}


Commit: 4efebbbeee94e24ecc9a95588a3c21b15d9b14d6
    https://github.com/scummvm/scummvm/commit/4efebbbeee94e24ecc9a95588a3c21b15d9b14d6
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 21790c5..773f09b 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -821,7 +821,7 @@ void LilliputEngine::displayRefreshScreen() {
 		sub16EBC();
 		sub171CF();
 		handleGameMouseClick();
-		sub12FE5();
+		checkInterfaceActivationDelay();
 		displayHeroismIndicator();
 	}
 }
@@ -2344,24 +2344,24 @@ void LilliputEngine::sub171CF() {
 	}
 }
 
-void LilliputEngine::sub12FE5() {
-	debugC(2, kDebugEngine, "sub12FE5()");
+void LilliputEngine::checkInterfaceActivationDelay() {
+	debugC(2, kDebugEngine, "checkInterfaceActivationDelay()");
 
 	if (_animationTick != 1)
 		return;
 
-	int count = 0;
+	bool needRedraw = false;
 	for (int i = 0; i < _interfaceHotspotNumb; i++) {
-		if (_scriptHandler->_array122FD[i] != 0) {
-			--_scriptHandler->_array122FD[i];
-			if (_scriptHandler->_array122FD[i] == 0) {
+		if (_scriptHandler->_interfaceButtonActivationDelay[i] != 0) {
+			--_scriptHandler->_interfaceButtonActivationDelay[i];
+			if (_scriptHandler->_interfaceButtonActivationDelay[i] == 0) {
 				_scriptHandler->_interfaceHotspotStatus[i] = kHotspotEnabled;
-				++count;
+				needRedraw = true;
 			}
 		}
 	}
 
-	if (count != 0)
+	if (needRedraw)
 		displayInterfaceHotspots();
 }
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 2ea4a57..8d15400 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -286,7 +286,7 @@ public:
 	void sub16CA0();
 	byte sub166DD(int index, Common::Point var1);
 	void sub171CF();
-	void sub12FE5();
+	void checkInterfaceActivationDelay();
 	int16 sub16DD5(int x1, int y1, int x2, int y2);
 	void displayCharactersOnMap();
 	void restoreMapPoints();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index e6e4df2..af0879f 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -53,7 +53,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 
 	for (int i = 0; i < 20; i++) {
 		_interfaceHotspotStatus[i] = kHotspotOff;
-		_array122FD[i] = 0;
+		_interfaceButtonActivationDelay[i] = 0;
 	}
 
 	for (int i = 0; i < 32; i++)
@@ -2803,9 +2803,7 @@ void LilliputScript::OC_setInterfaceHotspot() {
 
 	uint16 curWord = _currScript->readUint16LE();
 	_interfaceHotspotStatus[index] = (curWord & 0xFF);
-	_array122FD[index] = (curWord >> 8);
-	if (_array122FD[index] != 0)
-		warning("debug - OC_setInterfaceHotspot - _array122FD[index] = %d", _array122FD[index]);
+	_interfaceButtonActivationDelay[index] = (curWord >> 8);
 
 	_vm->displayInterfaceHotspots();
 }
@@ -3095,7 +3093,7 @@ void LilliputScript::OC_disableInterfaceHotspot() {
 	debugC(1, kDebugScript, "OC_disableInterfaceHotspot()");
 
 	int index = _currScript->readUint16LE();
-	_array122FD[index] = (_currScript->readUint16LE() & 0xFF);
+	_interfaceButtonActivationDelay[index] = (_currScript->readUint16LE() & 0xFF);
 	_interfaceHotspotStatus[index] = kHotspotDisabled;
 
 	_vm->displayInterfaceHotspots();
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 240da58..51b06ec 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -72,7 +72,7 @@ public:
 	int8 _characterTilePosY[40];
 	int8 _array12811[40];
 	int8 _array10AB1[40];
-	byte _array122FD[20];
+	byte _interfaceButtonActivationDelay[20];
 	byte _array122C1[40];
 	byte _array10A39[40];
 	int16 _array10B51[40 * 40];


Commit: ed9daf2ed649878a8a3eafcbbae4e60989e039ca
    https://github.com/scummvm/scummvm/commit/ed9daf2ed649878a8a3eafcbbae4e60989e039ca
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Rework _rectXMinMax and _rectYMinMax

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 773f09b..b377d6c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1476,10 +1476,10 @@ void LilliputEngine::sub167EF(int index) {
 	}
 
 	if ((word167ED != -1) &&
-	        (_array10999PosX[index] >= (_rectXMinMax[word167EB] >> 8)) &&
-	        (_array10999PosX[index] <= (_rectXMinMax[word167EB] & 0xFF)) &&
-	        (_array109C1PosY[index] >= (_rectYMinMax[word167EB] >> 8)) &&
-	        (_array109C1PosY[index] <= (_rectYMinMax[word167EB] & 0xFF))) {
+		(_array10999PosX[index] >= _rectXMinMax[word167EB].min) &&
+		(_array10999PosX[index] <= _rectXMinMax[word167EB].max) &&
+		(_array109C1PosY[index] >= _rectYMinMax[word167EB].min) &&
+		(_array109C1PosY[index] <= _rectYMinMax[word167EB].max)) {
 		_array109E9PosX[index] = _rulesBuffer12Pos4[word167ED].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
@@ -1487,8 +1487,8 @@ void LilliputEngine::sub167EF(int index) {
 
 	_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
 	_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
-	int var4h = (_rectXMinMax[word167EB] >> 8);
-	int var4l = (_rectXMinMax[word167EB] & 0xFF);
+	int var4h = _rectXMinMax[word167EB].min;
+	int var4l = _rectXMinMax[word167EB].max;
 
 	if (var4h != var4l) {
 		if (_rulesBuffer12Pos4[word167EB].x == var4h) {
@@ -1503,8 +1503,8 @@ void LilliputEngine::sub167EF(int index) {
 			return;
 		}
 
-		var4h = (_rectYMinMax[word167EB] >> 8);
-		var4l = (_rectYMinMax[word167EB] & 0xFF);
+		var4h = (_rectYMinMax[word167EB].min);
+		var4l = (_rectYMinMax[word167EB].max);
 
 		if (var4h != var4l) {
 			if (_rulesBuffer12Pos4[word167EB].y == var4h) {
@@ -1606,13 +1606,13 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	var1h = _word16937Pos.x;
 	var1l = _word16937Pos.y;
 
-	if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
+	if ((var1h >= _rectXMinMax[var2].min) && (var1h <= _rectXMinMax[var2].max) && (var1l >= _rectYMinMax[var2].min) && (var1l <= _rectYMinMax[var2].max))
 		return 0;
 
 	var1h = _array109E9PosX[indexs];
 	var1l = _array10A11PosY[indexs];
 
-	if ((var1h >= (_rectXMinMax[var2] >> 8)) && (var1h <= (_rectXMinMax[var2] & 0xFF)) && (var1l >= (_rectYMinMax[var2] >> 8)) && (var1l <= (_rectYMinMax[var2] & 0xFF)))
+	if ((var1h >= _rectXMinMax[var2].min) && (var1h <= _rectXMinMax[var2].max) && (var1l >= _rectYMinMax[var2].min) && (var1l <= _rectYMinMax[var2].max))
 		return 0;
 
 	return 1;
@@ -1622,7 +1622,7 @@ int16 LilliputEngine::findHotspot(Common::Point pos) {
 	debugC(2, kDebugEngine, "findHotspot(%d, %d)", pos.x, pos.y);
 
 	for (int i = 0; i < _rectNumb; i++) {
-		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
+		if ((pos.x >= _rectXMinMax[i].min) && (pos.x <= _rectXMinMax[i].max) && (pos.y >= _rectYMinMax[i].min) && (pos.y <= _rectYMinMax[i].max))
 			return i;
 	}
 	return -1;
@@ -1632,7 +1632,7 @@ int16 LilliputEngine::reverseFindHotspot(Common::Point pos) {
 	debugC(2, kDebugEngine, "reverseFindHotspot(%d, %d)", pos.x, pos.y);
 
 	for (int i = _rectNumb - 1; i >= 0 ; i--) {
-		if ((pos.x >= (_rectXMinMax[i] >> 8)) && (pos.x <= (_rectXMinMax[i] & 0xFF)) && (pos.y >= (_rectYMinMax[i] >> 8)) && (pos.y <= (_rectYMinMax[i] & 0xFF)))
+		if ((pos.x >= _rectXMinMax[i].min) && (pos.x <= _rectXMinMax[i].max) && (pos.y >= _rectYMinMax[i].min) && (pos.y <= _rectYMinMax[i].max))
 			return i;
 	}
 	return -1;
@@ -1658,10 +1658,10 @@ void LilliputEngine::sub16A08(int index) {
 
 	int8 tmpIndex = 0;
 	for (int i = 3; i > 0; i--) {
-		int16 tmpVal = 0x7FFF;
+		int16 smallestDistance = 0x7FFF;
 		for (int j = 0; j < 4; j++) {
-			if (tmpVal > arrayDistance[j]) {
-				tmpVal = arrayDistance[j];
+			if (smallestDistance > arrayDistance[j]) {
+				smallestDistance = arrayDistance[j];
 				tmpIndex = j;
 			}
 		}
@@ -2697,8 +2697,10 @@ void LilliputEngine::loadRules() {
 	uint16 tmpVal;
 
 	for (int i = 0; i < _rectNumb; i++) {
-		_rectXMinMax[i] = f.readUint16LE();
-		_rectYMinMax[i] = f.readUint16LE();
+		_rectXMinMax[i].min = (int16)f.readByte();
+		_rectXMinMax[i].max = (int16)f.readByte();
+		_rectYMinMax[i].min = (int16)f.readByte();
+		_rectYMinMax[i].max = (int16)f.readByte();
 		tmpVal = f.readUint16LE();
 		_rulesBuffer12Pos3[i] = Common::Point(tmpVal >> 8, tmpVal & 0xFF);
 		tmpVal = f.readUint16LE();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 8d15400..7f26b05 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -82,6 +82,11 @@ struct SmallAnim {
 	int16 _frameIndex[8];
 };
 
+struct MinMax {
+	int16 min;
+	int16 max;
+};
+
 class LilliputEngine : public Engine {
 public:
 	LilliputEngine(OSystem *syst, const LilliputGameDescription *gd);
@@ -190,8 +195,8 @@ public:
 	int16 *_rulesChunk10;
 	byte *_rulesChunk11;
 	int16 _rectNumb;
-	int16 _rectXMinMax[40];
-	int16 _rectYMinMax[40];
+	MinMax _rectXMinMax[40];
+	MinMax _rectYMinMax[40];
 	Common::Point _rulesBuffer12Pos3[40];
 	Common::Point _rulesBuffer12Pos4[40];
 	int _interfaceHotspotNumb;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index af0879f..89b414a 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -25,6 +25,7 @@
 #include "common/debug.h"
 
 #include "common/system.h"
+#include <climits>
 
 namespace Lilliput {
 
@@ -466,7 +467,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_enableCharacterScript();
 		break;
 	case 0x4A:
-		OC_sub18387();
+		OC_setRulesBuffer2Element();
 		break;
 	case 0x4B:
 		OC_setDebugFlag();
@@ -684,7 +685,7 @@ static const OpCode opCodes2[] = {
 /* 0x47 */	{ "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
 /* 0x48 */	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x49 */	{ "OC_enableCharacterScript", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x4a */	{ "OC_sub18387", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x4a */	{ "OC_setRulesBuffer2Element", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
 /* 0x4b */	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
 /* 0x4d */	{ "OC_waitForEvent", 0, kNone, kNone, kNone, kNone, kNone }, 
@@ -1537,11 +1538,11 @@ byte LilliputScript::OC_compareCoords_1() {
 	int index = _currScript->readUint16LE();
 	assert(index < 40);
 
-	int16 var3 = _vm->_rectXMinMax[index];
-	int16 var4 = _vm->_rectYMinMax[index];
+	MinMax xMinMax = _vm->_rectXMinMax[index];
+	MinMax yMinMax = _vm->_rectYMinMax[index];
 	Common::Point var1 = _vm->_currentScriptCharacterPos;
 
-	if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
+	if ((var1.x < xMinMax.min) || (var1.x > xMinMax.max) || (var1.y < yMinMax.min) || (var1.y > yMinMax.max))
 		return 0;
 
 	return 1;
@@ -1554,10 +1555,10 @@ byte LilliputScript::OC_compareCoords_2() {
 	int16 index = getValue1();
 	Common::Point var1 = Common::Point(_characterTilePosX[index], _characterTilePosY[index]);
 	index = _currScript->readUint16LE();
-	uint16 var3 = _vm->_rectXMinMax[index];
-	uint16 var4 = _vm->_rectYMinMax[index];
+	MinMax xMinMax = _vm->_rectXMinMax[index];
+	MinMax yMinMax = _vm->_rectYMinMax[index];
 
-	if ((var1.x < (var3 >> 8)) || (var1.x > (var3 & 0xFF)) || (var1.y < (var4 >> 8)) || (var1.y > (var4 & 0xFF)))
+	if ((var1.x < xMinMax.min) || (var1.x > xMinMax.max) || (var1.y < yMinMax.min) || (var1.y > yMinMax.max))
 		return 0;
 	return 1;
 }
@@ -2947,7 +2948,7 @@ void LilliputScript::OC_sub18260() {
 	byte *isoMapBuf = getMapPtr(pt);
 
 	if (isoMapBuf[1] != 0xFF) {
-		int byte1825D = 255;
+        int minVal = INT_MAX;
 		for (int var2 = 7; var2 >= 0; var2--) {
 			for (int var3 = 7; var3 >= 0; var3--) {
 				Common::Point(_viewportPos.x + var2, _viewportPos.y + var3);
@@ -2956,8 +2957,8 @@ void LilliputScript::OC_sub18260() {
 				if (isoMapBuf[1] == 0xFF) {
 					int x = abs(var2 - var4.x);
 					int y = abs(var3 - var4.y);
-					if (x + y < byte1825D) {
-						byte1825D = x + y;
+					if (x + y < minVal) {
+						minVal = x + y;
 						_word1825E = Common::Point(var2, var3);
 					}
 				}
@@ -3048,13 +3049,13 @@ void LilliputScript::OC_enableCharacterScript() {
 	enableCharacterScript(index, var2, _vm->getCharacterVariablesPtr(index * 32));
 }
 
-void LilliputScript::OC_sub18387() {
-	debugC(1, kDebugScriptTBC, "OC_sub18387()");
+void LilliputScript::OC_setRulesBuffer2Element() {
+	debugC(1, kDebugScript, "OC_setRulesBuffer2Element()");
 
 	int index = getValue1();
 	byte var1 = _currScript->readUint16LE() & 0xFF;
 
-	assert(index < 40);
+	assert((index >= 0) && (index < 40));
 	_vm->_rulesBuffer2_10[index] = var1;
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 51b06ec..bb01f80 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -276,7 +276,7 @@ private:
 	void OC_setArray122C1();
 	void OC_sub18367();
 	void OC_enableCharacterScript();
-	void OC_sub18387();
+	void OC_setRulesBuffer2Element();
 	void OC_setDebugFlag();
 	void OC_setByte14837();
 	void OC_waitForEvent();


Commit: 7554c07be1883e54ab1946cbda881bef272e57f5
    https://github.com/scummvm/scummvm/commit/7554c07be1883e54ab1946cbda881bef272e57f5
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index b377d6c..4af671c 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -157,7 +157,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word16EFEl_characterId = -1;
 	_word1817B = 0;
 	_savedSurfaceUnderMousePos = Common::Point(0, 0);
-	_bool15AC2 = false;
+	_displayGreenHand = false;
 	_displayStringIndex = 0;
 	_word1289D = 0;
 	_numCharacters = 0;
@@ -403,7 +403,7 @@ void LilliputEngine::displayMousePointer() {
 
 		_savedSurfaceUnderMousePos = _mouseDisplayPos;
 		SaveSurfaceUnderMouseCursor(_savedSurfaceUnderMouse, _mouseDisplayPos);
-		display16x16IndexedBuf(_bufferIdeogram, _bool15AC2 ? 81 : 80, _mouseDisplayPos);
+		display16x16IndexedBuf(_bufferIdeogram, _displayGreenHand ? 81 : 80, _mouseDisplayPos);
 
 		_skipDisplayFlag1 = 1;
 		_skipDisplayFlag2 = 0;
@@ -1015,7 +1015,7 @@ void LilliputEngine::checkMapClosing(bool &forceReturnFl) {
 
 	_displayMap = false;
 	paletteFadeOut();
-	_bool15AC2 = false;
+	_displayGreenHand = false;
 	unselectInterfaceHotspots();
 	initGameAreaDisplay();
 	_scriptHandler->_heroismLevel = 0;
@@ -2103,7 +2103,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 	_scriptHandler->_interfaceHotspotStatus[index] = kHotspotSelected;
 	if (_rulesBuffer13_1[index] == 1) {
 		_delayedReactivationAction = true;
-		_bool15AC2 = true;
+		_displayGreenHand = true;
 	} else {
 		_actionType = 1;
 	}
@@ -2693,18 +2693,19 @@ void LilliputEngine::loadRules() {
 
 	// Chunk 12
 	_rectNumb = f.readUint16LE();
-	assert(_rectNumb <= 40);
-	uint16 tmpVal;
+	assert((_rectNumb >= 0) && (_rectNumb <= 40));
 
 	for (int i = 0; i < _rectNumb; i++) {
 		_rectXMinMax[i].min = (int16)f.readByte();
 		_rectXMinMax[i].max = (int16)f.readByte();
 		_rectYMinMax[i].min = (int16)f.readByte();
 		_rectYMinMax[i].max = (int16)f.readByte();
-		tmpVal = f.readUint16LE();
-		_rulesBuffer12Pos3[i] = Common::Point(tmpVal >> 8, tmpVal & 0xFF);
-		tmpVal = f.readUint16LE();
-		_rulesBuffer12Pos4[i] = Common::Point(tmpVal >> 8, tmpVal & 0xFF);
+		int16 tmpValX = (int16)f.readByte();
+		int16 tmpValY = (int16)f.readByte();
+		_rulesBuffer12Pos3[i] = Common::Point(tmpValX, tmpValY);
+		tmpValX = (int16)f.readByte();
+		tmpValY = (int16)f.readByte();
+		_rulesBuffer12Pos4[i] = Common::Point(tmpValX, tmpValY);
 	}
 
 	// Chunk 13
@@ -2796,7 +2797,7 @@ void LilliputEngine::unselectInterfaceButton() {
 	debugC(1, kDebugEngine, "unselectInterfaceButton()");
 
 	_delayedReactivationAction = false;
-	_bool15AC2 = false;
+	_displayGreenHand = false;
 	_lastInterfaceHotspotButton = 0;
 	unselectInterfaceHotspots();
 	displayInterfaceHotspots();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 7f26b05..5713ab2 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -149,7 +149,7 @@ public:
 	int8 _word16EFEl_characterId;
 	uint16 _word1817B;
 	Common::Point _savedSurfaceUnderMousePos;
-	bool _bool15AC2;
+	bool _displayGreenHand;
 	int _currentDisplayCharacter;
 	int _displayStringIndex;
 	int _word1289D;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 89b414a..bf616d8 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -3111,7 +3111,7 @@ void LilliputScript::OC_loadFileAerial() {
 	_vm->_refreshScreenFlag = true;
 	_talkingCharacter = -1;
 	OC_PaletteFadeOut();
-	_vm->_bool15AC2 = true;
+	_vm->_displayGreenHand = true;
 	_vm->displayVGAFile("AERIAL.GFX");
 	OC_PaletteFadeIn();
 


Commit: b387257138ccb19eee1ae0fd264567a8c40f1f5d
    https://github.com/scummvm/scummvm/commit/b387257138ccb19eee1ae0fd264567a8c40f1f5d
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming, fix regression in intro introduced in the two previous commits

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 4af671c..7c6cd8f 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -541,7 +541,7 @@ void LilliputEngine::displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex
 		++var3;
 	}
 
-	var1 = (0x3D - var3) << 1;
+	var1 = (0x3D - var3) * 2;
 	vgaIndex += var1;
 
 	bufIndex = bckIndex;
@@ -1909,7 +1909,7 @@ void LilliputEngine::sub13156(bool &forceReturnFl) {
 		byte button = 1;
 		if (event.type == Common::EVENT_KEYUP)
 			button = 2;
-		sub1305C(index, button);
+		handleInterfaceHotspot(index, button);
 		forceReturnFl = true;
 	}
 }
@@ -1993,7 +1993,7 @@ void LilliputEngine::handleGameMouseClick() {
 
 	if (button == 2) {
 		if (_lastInterfaceHotspotIndex != -1)
-			sub1305C(_lastInterfaceHotspotIndex, button);
+			handleInterfaceHotspot(_lastInterfaceHotspotIndex, button);
 		return;
 	}
 
@@ -2060,7 +2060,7 @@ void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) {
 	forceReturnFl = false;
 	for (int index = _interfaceHotspotNumb - 1; index >= 0; index--) {
 		if (isMouseOverHotspot(_mousePos, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]))) {
-			sub1305C(index, 1);
+			handleInterfaceHotspot(index, 1);
 			forceReturnFl = true;
 			return;
 		}
@@ -2076,8 +2076,8 @@ bool LilliputEngine::isMouseOverHotspot(Common::Point mousePos, Common::Point ho
 	return true;
 }
 
-void LilliputEngine::sub1305C(byte index, byte button) {
-	debugC(2, kDebugEngine, "sub1305C(%d, %d)", index, button);
+void LilliputEngine::handleInterfaceHotspot(byte index, byte button) {
+	debugC(2, kDebugEngine, "handleInterfaceHotspot(%d, %d)", index, button);
 
 	if (_scriptHandler->_interfaceHotspotStatus[index] < kHotspotEnabled)
 		return;
@@ -2101,7 +2101,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 
 	unselectInterfaceHotspots();
 	_scriptHandler->_interfaceHotspotStatus[index] = kHotspotSelected;
-	if (_rulesBuffer13_1[index] == 1) {
+	if (_interfaceTwoStepAction[index] == 1) {
 		_delayedReactivationAction = true;
 		_displayGreenHand = true;
 	} else {
@@ -2114,7 +2114,7 @@ void LilliputEngine::sub1305C(byte index, byte button) {
 void LilliputEngine::sub16685(int idx, Common::Point var1) {
 	debugC(2, kDebugEngine, "sub16685(%d, %d - %d)", idx, var1.x, var1.y);
 
-	int index = (idx << 5) + var1.y;
+	int index = (idx * 32) + var1.y;
 	_scriptHandler->_array10AB1[idx] = _rulesBuffer2_16[index];
 }
 
@@ -2696,22 +2696,23 @@ void LilliputEngine::loadRules() {
 	assert((_rectNumb >= 0) && (_rectNumb <= 40));
 
 	for (int i = 0; i < _rectNumb; i++) {
-		_rectXMinMax[i].min = (int16)f.readByte();
 		_rectXMinMax[i].max = (int16)f.readByte();
-		_rectYMinMax[i].min = (int16)f.readByte();
+		_rectXMinMax[i].min = (int16)f.readByte();
 		_rectYMinMax[i].max = (int16)f.readByte();
-		int16 tmpValX = (int16)f.readByte();
+		_rectYMinMax[i].min = (int16)f.readByte();
 		int16 tmpValY = (int16)f.readByte();
+		int16 tmpValX = (int16)f.readByte();
 		_rulesBuffer12Pos3[i] = Common::Point(tmpValX, tmpValY);
-		tmpValX = (int16)f.readByte();
 		tmpValY = (int16)f.readByte();
+		tmpValX = (int16)f.readByte();
+		// _rulesBuffer12Pos4 is used by the into
 		_rulesBuffer12Pos4[i] = Common::Point(tmpValX, tmpValY);
 	}
 
 	// Chunk 13
 	_interfaceHotspotNumb = f.readUint16LE();
 	for (int i = 0 ; i < 20; i++)
-		_rulesBuffer13_1[i] = f.readByte();
+		_interfaceTwoStepAction[i] = f.readByte();
 
 	for (int i = 0 ; i < 20; i++)
 		_interfaceHotspotsX[i] = f.readSint16LE();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 5713ab2..eca4679 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -200,7 +200,7 @@ public:
 	Common::Point _rulesBuffer12Pos3[40];
 	Common::Point _rulesBuffer12Pos4[40];
 	int _interfaceHotspotNumb;
-	byte _rulesBuffer13_1[20];
+	byte _interfaceTwoStepAction[20];
 	int16 _interfaceHotspotsX[20];
 	int16 _interfaceHotspotsY[20];
 	Common::KeyCode _keyboardMapping[20];
@@ -297,7 +297,7 @@ public:
 	void restoreMapPoints();
 	void displayHeroismIndicator();
 	void handleGameMouseClick();
-	void sub1305C(byte index, byte var2);
+	void handleInterfaceHotspot(byte index, byte button);
 	void checkInterfaceHotspots(bool &forceReturnFl);
 	bool isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos);
 	void checkClickOnCharacter(Common::Point pos, bool &forceReturnFl);


Commit: e059e81babcb6d0e4eb33382998f59e16e096deb
    https://github.com/scummvm/scummvm/commit/e059e81babcb6d0e4eb33382998f59e16e096deb
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming, fix a warning

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 7c6cd8f..b191f2a 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -692,7 +692,7 @@ void LilliputEngine::moveCharacters() {
 
 	_numCharactersToDisplay = 0;
 	byte index = _numCharacters - 1;
-	Common::Point _pos16213 = Common::Point(_scriptHandler->_viewportPos.x << 3, _scriptHandler->_viewportPos.y << 3);
+	Common::Point pos16213 = Common::Point(_scriptHandler->_viewportPos.x << 3, _scriptHandler->_viewportPos.y << 3);
 
 	for (int i = index; i >= 0; i--) {
 		if (_rulesBuffer2_5[i] != -1) {
@@ -734,8 +734,8 @@ void LilliputEngine::moveCharacters() {
 		if ((tmpVal2 >= 0) && (tmpVal2 <= 7) && (tmpVal3 >= 0) && (tmpVal3 <= 7)) {
 			_characterRelativePositionX[i] = tmpVal2;
 			_characterRelativePositionY[i] = tmpVal3;
-			tmpVal2 = _characterPositionX[i] - _pos16213.x;
-			tmpVal3 = _characterPositionY[i] - _pos16213.y;
+			tmpVal2 = _characterPositionX[i] - pos16213.x;
+			tmpVal3 = _characterPositionY[i] - pos16213.y;
 			int tmpVal4 = _characterPositionAltitude[i];
 			_characterDisplayX[i] = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF;
 			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
@@ -1887,8 +1887,8 @@ void LilliputEngine::sub12F37() {
 	}
 }
 
-void LilliputEngine::sub13156(bool &forceReturnFl) {
-	debugC(2, kDebugEngine, "sub13156()");
+void LilliputEngine::keyboard_handleInterfaceShortcuts(bool &forceReturnFl) {
+	debugC(2, kDebugEngine, "keyboard_handleInterfaceShortcuts()");
 
 	forceReturnFl = false;
 
@@ -1977,7 +1977,7 @@ void LilliputEngine::handleGameMouseClick() {
 	checkNumericCode();
 
 	bool forceReturnFl = false;
-	sub13156(forceReturnFl);
+	keyboard_handleInterfaceShortcuts(forceReturnFl);
 	if (forceReturnFl)
 		return;
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index eca4679..6f035d8 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -279,7 +279,7 @@ public:
 	void renderCharacters(byte *buf, Common::Point pos);
 
 	void checkNumericCode();
-	void sub13156(bool &forceReturnFl);
+	void keyboard_handleInterfaceShortcuts(bool &forceReturnFl);
 	byte sub16799(int index, Common::Point param1);
 	byte getDirection(Common::Point param1, Common::Point param2);
 	void addCharToBuf(byte character);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index bf616d8..853f763 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1230,9 +1230,9 @@ void LilliputScript::listAllTexts() {
 		int variantCount = 0;
 		while (_vm->_packedStrings[index + variantCount] == 0x5B)
 			++variantCount ;
-		int it = 0;
-	
-		/*if (variantCount != 0) {
+		/*
+		int it = 0;	
+		if (variantCount != 0) {
 			for (int j = 0; j < variantCount; j++) {
 				decodePackedText(&_vm->_packedStrings[index + variantCount + it]);
 				warning("Text 0x%x variant %d : %s", i, j, _vm->_displayStringBuf);


Commit: cf29d9ceeca629322aebcfcc924099f1b8054403
    https://github.com/scummvm/scummvm/commit/cf29d9ceeca629322aebcfcc924099f1b8054403
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Removes redundant mouse cursor redraws

update() and pollEvent() are called multiple times over
the course of one game loop, thus restoreSurfaceUnderMousePointer()
and displayMousePointer() are called multiple times as well. This caused
massive lag and froze the script system when the mouse was moved.
While this commit doesn't fix the cursor flickering, it is now responsive
at all times.

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index b191f2a..dde53f0 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -247,6 +247,7 @@ void LilliputEngine::update() {
 		_lastTime += ((currentTime - _lastTime) / 20) * 20;
 		newInt8();
 		pollEvent();
+		displayMousePointer();
 	}
 }
 
@@ -432,8 +433,6 @@ void LilliputEngine::saveSurfaceGameArea() {
 			_savedSurfaceGameArea3[(i * 256) + j] = ((byte *)_mainSurface->getPixels())[index + j];
 		index += 320;
 	}
-
-	displayMousePointer();
 }
 
 void LilliputEngine::saveSurfaceSpeech() {
@@ -447,8 +446,6 @@ void LilliputEngine::saveSurfaceSpeech() {
 			_savedSurfaceSpeech[(i * 252) + j] = ((byte *)_mainSurface->getPixels())[index + j];
 		index += 320;
 	}
-
-	displayMousePointer();
 }
 
 void LilliputEngine::restoreSurfaceSpeech() {
@@ -462,8 +459,6 @@ void LilliputEngine::restoreSurfaceSpeech() {
 			((byte *)_mainSurface->getPixels())[index + j] = _savedSurfaceSpeech[(i * 252) + j];
 		index += 320;
 	}
-
-	displayMousePointer();
 }
 
 
@@ -480,8 +475,6 @@ void LilliputEngine::displayInterfaceHotspots() {
 		tmpVal = _scriptHandler->_interfaceHotspotStatus[index] * 20;
 		display16x16IndexedBuf(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
 	}
-
-	displayMousePointer();
 }
 
 void LilliputEngine::displayLandscape() {
@@ -521,8 +514,6 @@ void LilliputEngine::displaySpeechBubble() {
 		}
 		index += 320;
 	}
-
-	displayMousePointer();
 }
 
 void LilliputEngine::displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex) {
@@ -585,8 +576,6 @@ void LilliputEngine::displaySpeech(byte *buf) {
 		vgaIndex += (8 * 320);
 		displaySpeechLine(vgaIndex, buf, bufIndex);
 	}
-
-	displayMousePointer();
 }
 
 void LilliputEngine::initGameAreaDisplay() {
@@ -608,8 +597,6 @@ void LilliputEngine::initGameAreaDisplay() {
 	prepareGameArea();
 	displayGameArea();
 
-	// display mouse pointer on top of the rest
-	displayMousePointer();
 	free(tmpBuf);
 }
 
@@ -650,8 +637,6 @@ void LilliputEngine::displayGameArea() {
 
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
-
-	displayMousePointer();
 }
 
 void LilliputEngine::restoreMapPoints() {
@@ -663,8 +648,6 @@ void LilliputEngine::restoreMapPoints() {
 	for (byte index = 0; index < _numCharacters; index++) {
 		buf[_mapSavedPixelIndex[index]] = _mapSavedPixel[index];
 	}
-
-	displayMousePointer();
 }
 
 void LilliputEngine::displayCharactersOnMap() {
@@ -684,7 +667,6 @@ void LilliputEngine::displayCharactersOnMap() {
 			buf[pixIndex] = _scriptHandler->_characterMapPixelColor[index];
 		}
 	}
-	displayMousePointer();
 }
 
 void LilliputEngine::moveCharacters() {
@@ -867,8 +849,6 @@ void LilliputEngine::displaySmallAnims() {
 		subIndex = 0;
 
 	_smallAnimsFrameIndex = subIndex;
-
-	displayMousePointer();
 }
 
 void LilliputEngine::paletteFadeOut() {
@@ -1155,8 +1135,6 @@ void LilliputEngine::displayCharacterStatBar(int8 type, int16 averagePosX, int8
 		}
 		vgaIndex += 320;
 	}
-
-	displayMousePointer();
 }
 
 void LilliputEngine::displayString(byte *buf, Common::Point pos) {
@@ -2410,8 +2388,6 @@ void LilliputEngine::displayHeroismIndicator() {
 			index -= 320;
 		}
 	}
-
-	displayMousePointer();
 }
 
 void LilliputEngine::pollEvent() {
@@ -2443,7 +2419,6 @@ void LilliputEngine::pollEvent() {
 				if (_skipDisplayFlag1 != 0) {
 					restoreSurfaceUnderMousePointer();
 					_mouseDisplayPos = newMousePos;
-					displayMousePointer();
 				} else {
 					_mouseDisplayPos = newMousePos;
 				}
@@ -2752,9 +2727,6 @@ void LilliputEngine::displayVGAFile(Common::String fileName) {
 	memcpy(_mainSurface->getPixels(), buffer, 320*200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 	_system->updateScreen();
-	
-	displayMousePointer();
-
 }
 
 void LilliputEngine::fixPaletteEntries(uint8 *palette, int num) {
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 853f763..812998d 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -3158,9 +3158,7 @@ void LilliputScript::OC_displayNumericCharacterVariable() {
 	int posY = _currScript->readSint16LE();
 
 	if (!_vm->_displayMap) {
-		_vm->restoreSurfaceUnderMousePointer();
 		displayNumber(displayVal, Common::Point(posX, posY));
-		_vm->displayMousePointer();
 	}
 }
 


Commit: a5b4be63275d5537c351ad5c772c1645ed0959dd
    https://github.com/scummvm/scummvm/commit/a5b4be63275d5537c351ad5c772c1645ed0959dd
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Substitues custom cursor handling with CursorMan

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


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index dde53f0..74dff08 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -29,6 +29,7 @@
 #include "common/memstream.h"
 #include "common/events.h"
 #include "engines/util.h"
+#include "graphics/cursorman.h"
 
 #include "lilliput/lilliput.h"
 #include "engines/util.h"
@@ -158,6 +159,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_word1817B = 0;
 	_savedSurfaceUnderMousePos = Common::Point(0, 0);
 	_displayGreenHand = false;
+	_isCursorGreenHand = false;
 	_displayStringIndex = 0;
 	_word1289D = 0;
 	_numCharacters = 0;
@@ -247,7 +249,15 @@ void LilliputEngine::update() {
 		_lastTime += ((currentTime - _lastTime) / 20) * 20;
 		newInt8();
 		pollEvent();
-		displayMousePointer();
+		if (_displayGreenHand == true && _isCursorGreenHand == false) {
+			_isCursorGreenHand = true;
+			CursorMan.pushCursor(_greenCursor, 16, 16, 0, 0, 0);
+		} else if (_displayGreenHand == false && _isCursorGreenHand == true) {
+			_isCursorGreenHand = false;
+			CursorMan.popCursor();
+		}
+
+		_system->updateScreen();
 	}
 }
 
@@ -371,19 +381,6 @@ void LilliputEngine::display16x16Buf(byte *buf, Common::Point pos, bool transpar
 	display16x16IndexedBuf(buf, 0, pos, transparent, updateScreen);
 }
 
-void LilliputEngine::SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos) {
-	debugC(2, kDebugEngine, "SaveSurfaceUnderMouseCursor(buf, %d, %d)", pos.x, pos.y);
-
-	int index2 = pos.x + (pos.y * 320);
-
-	for (int i = 0; i < 16; i++) {
-		for (int j = 0; j < 16; j++) {
-			buf[(i * 16) + j] = ((byte *)_mainSurface->getPixels())[index2 + j];
-		}
-		index2 += 320;
-	}
-}
-
 void LilliputEngine::fill16x16Rect(byte col, Common::Point pos) {
 	debugC(2, kDebugEngineTBC, "fill16x16Rect(%d, %d - %d)", col, pos.x, pos.y);
 
@@ -396,37 +393,9 @@ void LilliputEngine::fill16x16Rect(byte col, Common::Point pos) {
 	}
 }
 
-void LilliputEngine::displayMousePointer() {
-	debugC(2, kDebugEngine, "displayMousePointer()");
-
-	if ((_skipDisplayFlag1 != 1) && (_skipDisplayFlag2 != 1)) {
-		_skipDisplayFlag2 = 1;
-
-		_savedSurfaceUnderMousePos = _mouseDisplayPos;
-		SaveSurfaceUnderMouseCursor(_savedSurfaceUnderMouse, _mouseDisplayPos);
-		display16x16IndexedBuf(_bufferIdeogram, _displayGreenHand ? 81 : 80, _mouseDisplayPos);
-
-		_skipDisplayFlag1 = 1;
-		_skipDisplayFlag2 = 0;
-	}
-}
-
-void LilliputEngine::restoreSurfaceUnderMousePointer() {
-	debugC(2, kDebugEngine, "restoreSurfaceUnderMousePointer()");
-
-	if ((_skipDisplayFlag1 != 0) && (_skipDisplayFlag2 != 1)) {
-		_skipDisplayFlag2 = 1;
-		display16x16Buf(_savedSurfaceUnderMouse, _savedSurfaceUnderMousePos, false, false);
-		_skipDisplayFlag1 = 0;
-		_skipDisplayFlag2 = 0;
-	}
-}
-
 void LilliputEngine::saveSurfaceGameArea() {
 	debugC(2, kDebugEngine, "saveSurfaceGameArea()");
 
-	restoreSurfaceUnderMousePointer();
-
 	int index = (16 * 320) + 64; // 5184
 	for (int i = 0; i < 176; i++) {
 		for (int j = 0; j < 256; j++)
@@ -438,8 +407,6 @@ void LilliputEngine::saveSurfaceGameArea() {
 void LilliputEngine::saveSurfaceSpeech() {
 	debugC(2, kDebugEngine, "saveSurfaceSpeech()");
 
-	restoreSurfaceUnderMousePointer();
-
 	int index = 66;
 	for (int i = 0; i < 16; i++) {
 		for (int j = 0; j < 252; j++)
@@ -451,8 +418,6 @@ void LilliputEngine::saveSurfaceSpeech() {
 void LilliputEngine::restoreSurfaceSpeech() {
 	debugC(2, kDebugEngine, "restoreSurfaceSpeech()");
 
-	restoreSurfaceUnderMousePointer();
-
 	int index = 66;
 	for (int i = 0; i < 16; i++) {
 		for (int j = 0; j < 252; j++)
@@ -468,8 +433,6 @@ void LilliputEngine::displayInterfaceHotspots() {
 	if (_displayMap)
 		return;
 
-	restoreSurfaceUnderMousePointer();
-
 	int tmpVal;
 	for (int index = 0; index < _interfaceHotspotNumb; index++) {
 		tmpVal = _scriptHandler->_interfaceHotspotStatus[index] * 20;
@@ -499,8 +462,6 @@ void LilliputEngine::displaySpeechBubble() {
 	debugC(2, kDebugEngine, "displaySpeechBubble()");
 	static const byte _array15976[16] = {244, 248, 250, 250, 252, 252, 252, 252, 252, 252, 252, 252, 250, 250, 248, 244};
 
-	restoreSurfaceUnderMousePointer();
-
 	int index = 192;
 	int tmpIndex;
 	int var3;
@@ -550,8 +511,6 @@ void LilliputEngine::displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex
 void LilliputEngine::displaySpeech(byte *buf) {
 	debugC(2, kDebugEngine, "displaySpeech(%s)", buf);
 
-	restoreSurfaceUnderMousePointer();
-
 	int vgaIndex = 70;
 	int bufIndex = 0;
 
@@ -581,8 +540,6 @@ void LilliputEngine::displaySpeech(byte *buf) {
 void LilliputEngine::initGameAreaDisplay() {
 	debugC(1, kDebugEngine, "initGameAreaDisplay()");
 
-	restoreSurfaceUnderMousePointer();
-
 	// display background
 	byte *tmpBuf = loadVGA("SCREEN.GFX", 320 * 200, true);
 	memcpy(_mainSurface->getPixels(), tmpBuf, 320 * 200);
@@ -625,9 +582,6 @@ void LilliputEngine::displayGameArea() {
 	if (_displayMap)
 		return;
 
-	if (_mouseDisplayPos.x > 48)
-		restoreSurfaceUnderMousePointer();
-
 	int index = (16 * 320) + 64; // 5184
 	for (int i = 0; i < 176; i++) {
 		for (int j = 0; j < 256; j++)
@@ -642,8 +596,6 @@ void LilliputEngine::displayGameArea() {
 void LilliputEngine::restoreMapPoints() {
 	debugC(2, kDebugEngine, "restoreMapPoints()");
 
-	restoreSurfaceUnderMousePointer();
-
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (byte index = 0; index < _numCharacters; index++) {
 		buf[_mapSavedPixelIndex[index]] = _mapSavedPixel[index];
@@ -654,7 +606,6 @@ void LilliputEngine::displayCharactersOnMap() {
 	debugC(2, kDebugEngineTBC, "displayCharactersOnMap()");
 
 	moveCharacters();
-	restoreSurfaceUnderMousePointer();
 
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = _numCharacters - 1; index >= 0; index--) {
@@ -833,8 +784,6 @@ void LilliputEngine::displaySmallAnims() {
 	if (_animationTick == _lastAnimationTick)
 		return;
 
-	restoreSurfaceUnderMousePointer();
-
 	_lastAnimationTick = _animationTick;
 
 	assert(_smallAnimsFrameIndex < 8);
@@ -1107,8 +1056,6 @@ void LilliputEngine::sub16CA0() {
 void LilliputEngine::displayCharacterStatBar(int8 type, int16 averagePosX, int8 score, int16 posY) {
 	debugC(2, kDebugEngine, "displayCharacterStatBar(%d, %d, %d, %d)", type, averagePosX, score, posY);
 
-	restoreSurfaceUnderMousePointer();
-
 	int16 posX = averagePosX;
 
 	// If var equals 45 ('-'), score bar from -x to +x. If not (usually 43 '+'), score bar from 0 to x.
@@ -2354,7 +2301,6 @@ void LilliputEngine::displayHeroismIndicator() {
 	if (var1 == _scriptHandler->_heroismLevel)
 		return;
 
-	restoreSurfaceUnderMousePointer();
 	int var2 = 1;
 	if (var1 > _scriptHandler->_heroismLevel)
 		var1 = 150;
@@ -2416,12 +2362,7 @@ void LilliputEngine::pollEvent() {
 
 			if (newMousePos != _oldMousePos) {
 				_oldMousePos = newMousePos;
-				if (_skipDisplayFlag1 != 0) {
-					restoreSurfaceUnderMousePointer();
-					_mouseDisplayPos = newMousePos;
-				} else {
-					_mouseDisplayPos = newMousePos;
-				}
+				_mouseDisplayPos = newMousePos;
 			}
 			_lastEventType = event.type;
 			}
@@ -2721,8 +2662,6 @@ void LilliputEngine::loadRules() {
 void LilliputEngine::displayVGAFile(Common::String fileName) {
 	debugC(1, kDebugEngine, "displayVGAFile(%s)", fileName.c_str());
 
-	restoreSurfaceUnderMousePointer();
-
 	byte *buffer = loadVGA(fileName, 64000, true);
 	memcpy(_mainSurface->getPixels(), buffer, 320*200);
 	_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
@@ -2882,6 +2821,11 @@ Common::Error LilliputEngine::run() {
 	_bufferMen2 = loadVGA("MEN2.VGA", 61440, false);
 	_bufferIsoChars = loadVGA("ISOCHARS.VGA", 4096, false);
 	_bufferIsoMap = loadRaw("ISOMAP.DTA", 16384);
+	_normalCursor = &_bufferIdeogram[80 * 16 * 16];
+	_greenCursor = &_bufferIdeogram[81 * 16 * 16];
+
+	CursorMan.replaceCursor(_normalCursor, 16, 16, 0, 0, 0);
+	CursorMan.showMouse(true);
 
 	loadRules();
 	_int8installed = true;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 6f035d8..b970c5e 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -134,6 +134,8 @@ public:
 	byte *_bufferMen2;
 	byte *_bufferIsoChars;
 	byte *_bufferIdeogram;
+	byte *_normalCursor;
+	byte *_greenCursor;
 	byte _curPalette[768];
 	byte _displayStringBuf[160];
 
@@ -150,6 +152,7 @@ public:
 	uint16 _word1817B;
 	Common::Point _savedSurfaceUnderMousePos;
 	bool _displayGreenHand;
+	bool _isCursorGreenHand;
 	int _currentDisplayCharacter;
 	int _displayStringIndex;
 	int _word1289D;
@@ -232,10 +235,7 @@ public:
 
 	void display16x16IndexedBuf(byte *buf, int index, Common::Point pos, bool transparent = true, bool updateScreen = true);
 	void display16x16Buf(byte *buf, Common::Point pos, bool transparent = true, bool updateScreen = true);
-	void SaveSurfaceUnderMouseCursor(byte *buf, Common::Point pos);
 	void fill16x16Rect(byte col, Common::Point pos);
-	void displayMousePointer();
-	void restoreSurfaceUnderMousePointer();
 	void saveSurfaceGameArea();
 	void saveSurfaceSpeech();
 	void displayInterfaceHotspots();


Commit: d9aa76796d1eed5a4ce6f5b0b1f2d09a28290555
    https://github.com/scummvm/scummvm/commit/d9aa76796d1eed5a4ce6f5b0b1f2d09a28290555
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Adds delay during title screens

At least during the title screens when the game is just waiting for
user input it shouldn't use a full CPU core.

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 812998d..46f8938 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -3223,6 +3223,8 @@ void LilliputScript::OC_displayTitleScreen() {
 		
 		if ((_vm->_byte184F4 != 0) && (_vm->_sound_byte16F06 == 0))
 			break;
+
+		_vm->_system->delayMillis(1);
 	}
 	
 	_vm->_mouseButton = 0;


Commit: 399d1e26cbf06ed41edd9f76f92115381ed3e095
    https://github.com/scummvm/scummvm/commit/399d1e26cbf06ed41edd9f76f92115381ed3e095
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fixes rendering by blitting mainSurface to screen

Before displayMousePointer() that calls display16x16IndexedBuf() did the
blit and I forgot to add it when removing the custom cursor handling in
38cd5b2ac3.

Changed paths:
    engines/lilliput/lilliput.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 74dff08..89a5472 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -257,6 +257,7 @@ void LilliputEngine::update() {
 			CursorMan.popCursor();
 		}
 
+		_system->copyRectToScreen((byte *)_mainSurface->getPixels(), 320, 0, 0, 320, 200);
 		_system->updateScreen();
 	}
 }


Commit: de7c3d345ed7fd0186a00b8605b333ecfde99330
    https://github.com/scummvm/scummvm/commit/de7c3d345ed7fd0186a00b8605b333ecfde99330
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Marks game as unstable

Changed paths:
    engines/lilliput/detection.cpp


diff --git a/engines/lilliput/detection.cpp b/engines/lilliput/detection.cpp
index f42221d..e0841b8 100644
--- a/engines/lilliput/detection.cpp
+++ b/engines/lilliput/detection.cpp
@@ -65,7 +65,7 @@ static const LilliputGameDescription gameDescriptions[] = {
 			},
 			Common::EN_ANY,
 			Common::kPlatformDOS,
-			ADGF_NO_FLAGS,
+			ADGF_UNSTABLE,
 			GUIO0()
 		},
 		kGameTypeRobin
@@ -81,7 +81,7 @@ static const LilliputGameDescription gameDescriptions[] = {
 			},
 			Common::FR_FRA,
 			Common::kPlatformDOS,
-			ADGF_NO_FLAGS,
+			ADGF_UNSTABLE,
 			GUIO0()
 		},
 		kGameTypeRobin
@@ -97,7 +97,7 @@ static const LilliputGameDescription gameDescriptions[] = {
 			},
 			Common::DE_DEU,
 			Common::kPlatformDOS,
-			ADGF_NO_FLAGS,
+			ADGF_UNSTABLE,
 			GUIO0()
 		},
 		kGameTypeRobin
@@ -113,7 +113,7 @@ static const LilliputGameDescription gameDescriptions[] = {
 			},
 			Common::IT_ITA,
 			Common::kPlatformDOS,
-			ADGF_NO_FLAGS,
+			ADGF_UNSTABLE,
 			GUIO0()
 		},
 		kGameTypeRobin


Commit: 2aa505fcc8e94bb23169271c5bdad686d800a208
    https://github.com/scummvm/scummvm/commit/2aa505fcc8e94bb23169271c5bdad686d800a208
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix bug in OC_scrollViewPort

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 46f8938..fb08869 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -2822,8 +2822,8 @@ void LilliputScript::OC_scrollViewPort() {
 	int x = _viewportPos.x + scrollValX[direction];
 	int y = _viewportPos.y + scrollValY[direction];
 
-	CLIP(x, 0, 56);
-	CLIP(y, 0, 56);
+	x = CLIP(x, 0, 56);
+	y = CLIP(y, 0, 56);
 
 	_vm->_refreshScreenFlag = true;
 	_vm->viewportScrollTo(Common::Point(x, y));


Commit: c8495aa457daa9ab22e931d0479c1984e9de7162
    https://github.com/scummvm/scummvm/commit/c8495aa457daa9ab22e931d0479c1984e9de7162
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix a couple of remaining 'Robin' engine strings

Changed paths:
    engines/lilliput/detection.cpp
    engines/lilliput/lilliput.h


diff --git a/engines/lilliput/detection.cpp b/engines/lilliput/detection.cpp
index e0841b8..afa118d 100644
--- a/engines/lilliput/detection.cpp
+++ b/engines/lilliput/detection.cpp
@@ -127,11 +127,11 @@ public:
 	}
 
 	const char *getName() const {
-		return "Robin Hood";
+		return "Lilliput";
 	}
 
 	const char *getOriginalCopyright() const {
-		return "Robin Hood Engine copyright S.L.Grand, Brainware, 1991-1992";
+		return "Lilliput Engine copyright S.L.Grand, Brainware, 1991-1992";
 	}
 
 	bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index b970c5e..e05f972 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -41,9 +41,10 @@ class RandomSource;
 }
 
 /**
- * This is the namespace of the Robin engine.
+ * This is the namespace of the Lilliput engine.
  *
- * Status of this engine: ???
+ * Status of this engine:
+ * - Adventures of Robin Hood is mostly working without sound
  *
  * Games using this engine:
  * - Adventures of Robin Hood


Commit: d6092b4cbff3b623e4768c1f34d5d2729bda85b6
    https://github.com/scummvm/scummvm/commit/d6092b4cbff3b623e4768c1f34d5d2729bda85b6
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fix missing break in getArgumentString

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index fb08869..16662e8 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -773,6 +773,7 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 		int index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
 		str = Common::String::format("_vm->_rulesBuffer12Pos3[%d]", index);
+		break;
 	}
 	case 0xF7: {
 		str = Common::String::format("(_characterPositionTileX[_currentCharacterVariables[6]], _characterPositionTileY[_currentCharacterVariables[6]])");


Commit: 616a8291a4892f183b5572d2a949c179200337d6
    https://github.com/scummvm/scummvm/commit/616a8291a4892f183b5572d2a949c179200337d6
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 89a5472..050f65d 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -152,7 +152,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 
 	_currentScriptCharacter = 0;
 	_currentScriptCharacterPos = Common::Point(0, 0);
-	_word10804 = 0;
+	_host = 0;
 	_nextCharacterIndex = 0;
 	_word16EFEh = -1;
 	_word16EFEl_characterId = -1;
@@ -196,14 +196,14 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_characterPositionY[i] = -1;
 		_characterPositionAltitude[i] = 0;
 		_characterFrameArray[i] = 0;
-		_rulesBuffer2_5[i] = -1;
+		_characterCarried[i] = -1;
 		_rulesBuffer2_6[i] = 4;
 		_rulesBuffer2_7[i] = 0;
 		_spriteSizeArray[i] = 20;
 		_characterDirectionArray[i] = 0;
 		_rulesBuffer2_10[i] = 0;
 		_rulesBuffer2_11[i] = 0;
-		_rulesBuffer2_12[i] = 0;
+		_characterBehaviour[i] = 0;
 		_rulesBuffer2_13_posX[i] = 0;
 		_rulesBuffer2_14_posY[i] = 0;
 		_array1289F[i] = -1;
@@ -629,8 +629,8 @@ void LilliputEngine::moveCharacters() {
 	Common::Point pos16213 = Common::Point(_scriptHandler->_viewportPos.x << 3, _scriptHandler->_viewportPos.y << 3);
 
 	for (int i = index; i >= 0; i--) {
-		if (_rulesBuffer2_5[i] != -1) {
-			int index2 = _rulesBuffer2_5[i];
+		if (_characterCarried[i] != -1) {
+			int index2 = _characterCarried[i];
 			_characterPositionAltitude[i] = _characterPositionAltitude[index2] + _rulesBuffer2_7[i];
 			int8 tmpVal = _rulesBuffer2_6[i];
 			_characterDirectionArray[i] = _characterDirectionArray[index2];
@@ -972,8 +972,8 @@ void LilliputEngine::sub16CA0() {
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			byte byte16C9F = 0;
 			if ((index != index2) &&
-			        (_rulesBuffer2_5[index] != index2) &&
-			        (_rulesBuffer2_5[index2] != index) &&
+			        (_characterCarried[index] != index2) &&
+			        (_characterCarried[index2] != index) &&
 			        (_rulesBuffer2_11[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_characterTilePosX[index2];
 				int d2 = _scriptHandler->_characterTilePosY[index2];
@@ -1042,14 +1042,14 @@ void LilliputEngine::sub16CA0() {
 				}
 			}
 
-			int8 v2 = _scriptHandler->_array10B51[index2 + (index * 40)] & 0xFF;
+			int8 v2 = _scriptHandler->_interactions[index2 + (index * 40)] & 0xFF;
 			int8 v1 = v2;
 
 			if (v2 != byte16C9F) {
 				_scriptHandler->_characterScriptEnabled[index] = 1;
 				v2 =  byte16C9F;
 			}
-			_scriptHandler->_array10B51[index2 + (index * 40)] = (v1 << 8) + v2;
+			_scriptHandler->_interactions[index2 + (index * 40)] = (v1 << 8) + v2;
 		}
 	}
 }
@@ -1968,7 +1968,7 @@ void LilliputEngine::checkClickOnCharacter(Common::Point pos, bool &forceReturnF
 
 	for (int8 i = 0; i < _numCharacters; i++) {
 		// check if position is over a character
-		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _word10804)) {
+		if ((pos.x >= _characterDisplayX[i]) && (pos.x <= _characterDisplayX[i] + 17) && (pos.y >= _characterDisplayY[i]) && (pos.y <= _characterDisplayY[i] + 17) && (i != _host)) {
 			_selectedCharacterId = i;
 			_actionType = kActionGoto;
 			if (_delayedReactivationAction)
@@ -2226,7 +2226,7 @@ void LilliputEngine::sub17224(byte type, byte index, int var4) {
 
 	int index2 = var4 & 0xFF;
 	for (byte i = 0; i < _numCharacters; i++) {
-		if ((_scriptHandler->_array10B51[index2] & 0xFF) >= type)
+		if ((_scriptHandler->_interactions[index2] & 0xFF) >= type)
 			sub17264(i, var4);
 		index2 += 40;
 	}
@@ -2528,14 +2528,14 @@ void LilliputEngine::loadRules() {
 
 		_characterPositionAltitude[j] = (f.readUint16LE() & 0xFF);
 		_characterFrameArray[j] = f.readUint16LE();
-		_rulesBuffer2_5[j] = (int8)f.readByte();
+		_characterCarried[j] = (int8)f.readByte();
 		_rulesBuffer2_6[j] = (int8)f.readByte();
 		_rulesBuffer2_7[j] = f.readByte();
 		_spriteSizeArray[j] = f.readByte();
 		_characterDirectionArray[j] = f.readByte();
 		_rulesBuffer2_10[j] = f.readByte();
 		_rulesBuffer2_11[j] = f.readByte();
-		_rulesBuffer2_12[j] = f.readByte();
+		_characterBehaviour[j] = f.readByte();
 		_rulesBuffer2_13_posX[j] = f.readByte();
 		_rulesBuffer2_14_posY[j] = f.readByte();
 
@@ -2725,7 +2725,7 @@ void LilliputEngine::handleMenu() {
 	if (_delayedReactivationAction && (_actionType != kActionTalk))
 		return;
 
-	setCurrentCharacter(_word10804);
+	setCurrentCharacter(_host);
 	debugC(1, kDebugScriptTBC, "========================== Menu Script ==============================");
 	_scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScriptSize));
 	debugC(1, kDebugScriptTBC, "========================== End of Menu Script==============================");
@@ -2764,7 +2764,7 @@ void LilliputEngine::handleGameScripts() {
 	_array11D49[index] = -1;
 	_word1817B = 0;
 
-	int tmpVal = _rulesBuffer2_12[index];
+	int tmpVal = _characterBehaviour[index];
 	if (tmpVal == 0xFF)
 		return;
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index e05f972..88b50d0 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -171,14 +171,14 @@ public:
 	int16 _characterPositionY[40];
 	int8 _characterPositionAltitude[40];
 	int16 _characterFrameArray[40];
-	int8 _rulesBuffer2_5[40];
+	int8 _characterCarried[40];
 	int8 _rulesBuffer2_6[40];
 	byte _rulesBuffer2_7[40];
 	byte _spriteSizeArray[40];
 	byte _characterDirectionArray[40];
 	byte _rulesBuffer2_10[40];
 	byte _rulesBuffer2_11[40];
-	byte _rulesBuffer2_12[40];
+	byte _characterBehaviour[40];
 	byte _rulesBuffer2_13_posX[40];
 	byte _rulesBuffer2_14_posY[40];
 	byte _characterVariables[1400 + 3120];
@@ -356,7 +356,7 @@ public:
 	bool _delayedReactivationAction;
 	int8 _selectedCharacterId;
 	byte _numCharactersToDisplay;
-	int16 _word10804;
+	int16 _host;
 	bool _shouldQuit;
 
 	void pollEvent();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 16662e8..a39267b 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -76,7 +76,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	}
 
 	for (int i = 0; i < 1600; i++)
-		_array10B51[i] = 0;
+		_interactions[i] = 0;
 }
 
 LilliputScript::~LilliputScript() {
@@ -116,7 +116,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_compScriptForVal();
 		break;
 	case 0xA:
-		return OC_sub174D8();
+		return OC_isCarrying();
 		break;
 	case 0xB:
 		return OC_CompareCharacterVariables();
@@ -137,16 +137,16 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_IsCurrentCharacterIndex();
 		break;
 	case 0x11:
-		return OC_sub175C8();
+		return OC_hasVisibilityLevel();
 		break;
 	case 0x12:
-		return OC_sub17640();
+		return OC_hasGainedVisibilityLevel();
 		break;
 	case 0x13:
-		return OC_sub176C4();
+		return OC_hasReducedVisibilityLevel();
 		break;
 	case 0x14:
-		return OC_compWord10804();
+		return OC_isHost();
 		break;
 	case 0x15:
 		return OC_sub17766();
@@ -567,17 +567,17 @@ static const OpCode opCodes1[] = {
 	{ "OC_compCurrentSpeechId", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_checkSaveFlag", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_compScriptForVal", 2, kCompareOperation, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_sub174D8", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
+	{ "OC_isCarrying", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
 	{ "OC_CompareCharacterVariables", 5, kGetValue1, kImmediateValue, kCompareOperation, kGetValue1, kImmediateValue },
 	{ "OC_compareCoords_1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_compareCoords_2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_CompareDistanceFromCharacterToPositionWith", 3, kgetPosFromScript, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_compareRandomCharacterId", 3, kGetValue1, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_IsCurrentCharacterIndex", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_sub175C8", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
-	{ "OC_sub17640", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
-	{ "OC_sub176C4", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
-	{ "OC_compWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_hasVisibilityLevel", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
+	{ "OC_hasGainedVisibilityLevel", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
+	{ "OC_hasReducedVisibilityLevel", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
+	{ "OC_isHost", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_sub17766", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub17782", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_CompareMapValueWith", 4, kgetPosFromScript, kImmediateValue, kImmediateValue, kCompareOperation, kNone },
@@ -1295,7 +1295,7 @@ int16 LilliputScript::getValue1() {
 	case 1003:
 		return (int16)_vm->_currentCharacterVariables[6];
 	case 1004:
-		return _vm->_word10804;
+		return _vm->_host;
 	default:
 		warning("getValue1: Unexpected large value %d", curWord);
 		return curWord;
@@ -1492,15 +1492,15 @@ byte LilliputScript::OC_compScriptForVal() {
 	return compareValues(_scriptForVal, oper, var2);
 }
 
-byte LilliputScript::OC_sub174D8() {
-	debugC(1, kDebugScript, "OC_sub174D8()");
+byte LilliputScript::OC_isCarrying() {
+	debugC(1, kDebugScript, "OC_isCarrying()");
 
 	int8 tmpVal = getValue1() & 0xFF;
 	uint16 curWord = _currScript->readUint16LE();
 	
 	if (curWord == 3000) {
 		for (int index = 0; index < _vm->_numCharacters; index++) {
-			if (_vm->_rulesBuffer2_5[index] == tmpVal) {
+			if (_vm->_characterCarried[index] == tmpVal) {
 				_word16F00_characterId = index;
 				return 1;
 			}
@@ -1509,7 +1509,7 @@ byte LilliputScript::OC_sub174D8() {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
 		assert(index < 40);
-		if (_vm->_rulesBuffer2_5[index] == tmpVal) {
+		if (_vm->_characterCarried[index] == tmpVal) {
 			_word16F00_characterId = index;
 			return 1;
 		}
@@ -1606,8 +1606,8 @@ byte LilliputScript::OC_IsCurrentCharacterIndex() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub175C8() {
-	debugC(1, kDebugScript, "OC_sub175C8()");
+byte LilliputScript::OC_hasVisibilityLevel() {
+	debugC(1, kDebugScript, "OC_hasVisibilityLevel()");
 	
 	byte var4 = _currScript->readUint16LE() & 0xFF;
 	int tmpVal = _currScript->readUint16LE();
@@ -1615,7 +1615,7 @@ byte LilliputScript::OC_sub175C8() {
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
-		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + index];
+		int var1 = _interactions[(_vm->_currentScriptCharacter * 40) + index];
 		if ((var1 & 0xFF) < var4)
 			return 0;
 		
@@ -1625,7 +1625,7 @@ byte LilliputScript::OC_sub175C8() {
 
 	if (tmpVal == 3000) {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
-			int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
+			int var1 = _interactions[(_vm->_currentScriptCharacter * 40) + i];
 			if ((var1 & 0xFF) >= var4) {
 				_word16F00_characterId = i;
 				return 1;
@@ -1637,8 +1637,8 @@ byte LilliputScript::OC_sub175C8() {
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
-		if (((var1 & 0xFF) >= var4) && (_vm->_rulesBuffer2_12[i] == var4b)) {
+		int var1 = _interactions[(_vm->_currentScriptCharacter * 40) + i];
+		if (((var1 & 0xFF) >= var4) && (_vm->_characterBehaviour[i] == var4b)) {
 			_word16F00_characterId = i;
 			return 1;
 		}
@@ -1647,8 +1647,8 @@ byte LilliputScript::OC_sub175C8() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub17640() {
-	debugC(1, kDebugScript, "OC_sub17640()");
+byte LilliputScript::OC_hasGainedVisibilityLevel() {
+	debugC(1, kDebugScript, "OC_hasGainedVisibilityLevel()");
 
 	uint16 var4 = _currScript->readUint16LE();
 	int index = _vm->_currentScriptCharacter * 40;
@@ -1657,7 +1657,7 @@ byte LilliputScript::OC_sub17640() {
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int subIndex = getValue1();
-		tmpVal = _array10B51[index + subIndex];
+		tmpVal = _interactions[index + subIndex];
 		byte v1 = tmpVal & 0xFF;
 		byte v2 = tmpVal >> 8;
 		if ((v1 < (var4 & 0xFF)) || (v2 >= (var4 & 0xFF)))
@@ -1669,7 +1669,7 @@ byte LilliputScript::OC_sub17640() {
 	int var1 = tmpVal;
 	if (var1 == 3000) {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
-			tmpVal = _array10B51[index + i];
+			tmpVal = _interactions[index + i];
 			byte v1 = tmpVal & 0xFF;
 			byte v2 = tmpVal >> 8;
 			if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF))) {
@@ -1683,10 +1683,10 @@ byte LilliputScript::OC_sub17640() {
 	var1 -= 2000;
 	var4 = ((var1 & 0xFF) << 8) + (var4 & 0xFF);
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		tmpVal = _array10B51[index + i];
+		tmpVal = _interactions[index + i];
 		byte v1 = tmpVal & 0xFF;
 		byte v2 = tmpVal >> 8;
-		if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF)) && (_vm->_rulesBuffer2_12[i] == (var4 >> 8))) {
+		if ((v1 >= (var4 & 0xFF)) && (v2 < (var4 & 0xFF)) && (_vm->_characterBehaviour[i] == (var4 >> 8))) {
 			_word16F00_characterId = i;
 			return 1;
 		}
@@ -1694,8 +1694,8 @@ byte LilliputScript::OC_sub17640() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub176C4() {
-	debugC(1, kDebugScript, "OC_sub176C4()");
+byte LilliputScript::OC_hasReducedVisibilityLevel() {
+	debugC(1, kDebugScript, "OC_hasReducedVisibilityLevel()");
 	
 	byte var4 = _currScript->readUint16LE() & 0xFF;
 
@@ -1704,7 +1704,7 @@ byte LilliputScript::OC_sub176C4() {
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
-		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + index];
+		int var1 = _interactions[(_vm->_currentScriptCharacter * 40) + index];
 		if (((var1 & 0xFF) >= var4) || ((var1 >> 8) < var4))
 			return 0;
 		
@@ -1714,7 +1714,7 @@ byte LilliputScript::OC_sub176C4() {
 
 	if (tmpVal == 3000) {
 		for (int i = 0; i < _vm->_numCharacters; i++) {
-			int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
+			int var1 = _interactions[(_vm->_currentScriptCharacter * 40) + i];
 			if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
 				_word16F00_characterId = i;
 				return 1;
@@ -1726,9 +1726,9 @@ byte LilliputScript::OC_sub176C4() {
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		int var1 = _array10B51[(_vm->_currentScriptCharacter * 40) + i];
+		int var1 = _interactions[(_vm->_currentScriptCharacter * 40) + i];
 		if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) {
-			if (_vm->_rulesBuffer2_12[i] == var4b) {
+			if (_vm->_characterBehaviour[i] == var4b) {
 				_word16F00_characterId = i;
 				return 1;
 			}
@@ -1738,11 +1738,11 @@ byte LilliputScript::OC_sub176C4() {
 	return 0;
 }
 
-byte LilliputScript::OC_compWord10804() {
-	debugC(1, kDebugScript, "OC_compWord10804()");
+byte LilliputScript::OC_isHost() {
+	debugC(1, kDebugScript, "OC_isHost()");
 	
 	int tmpVal = getValue1();
-	if (tmpVal == _vm->_word10804)
+	if (tmpVal == _vm->_host)
 		return 1;
 
 	return 0;
@@ -1927,7 +1927,7 @@ byte LilliputScript::OC_sub178D2() {
 	assert (index < 40);
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
-	if (curByte == _vm->_rulesBuffer2_12[index])
+	if (curByte == _vm->_characterBehaviour[index])
 		return 1;
 
 	return 0;
@@ -1962,10 +1962,10 @@ byte LilliputScript::OC_sub1790F() {
 
 	int16 index = getValue1();
 	assert((index >= 0) && (index < 40));
-	if (_vm->_rulesBuffer2_5[index] == -1)
+	if (_vm->_characterCarried[index] == -1)
 		return 0;
 
-	_word16F00_characterId = _vm->_rulesBuffer2_5[index];
+	_word16F00_characterId = _vm->_characterCarried[index];
 
 	return 1;
 }
@@ -2298,7 +2298,7 @@ void LilliputScript::OC_DisableCharacter() {
 	int characterIndex = getValue1();
 	assert(characterIndex < 40);
 
-	if (characterIndex == _vm->_word10804)
+	if (characterIndex == _vm->_host)
 		_viewportCharacterTarget = -1;
 
 	_vm->_characterPositionX[characterIndex] = -1;
@@ -2430,7 +2430,7 @@ void LilliputScript::OC_sub17AEE() {
 void LilliputScript::OC_setWord10804() {
 	debugC(1, kDebugScript, "OC_setWord10804()");
 
-	_vm->_word10804 = getValue1();
+	_vm->_host = getValue1();
 }
 
 void LilliputScript::OC_sub17C0E() {
@@ -2461,7 +2461,7 @@ void LilliputScript::OC_sub17C55() {
 	byte var4 = (_currScript->readUint16LE() & 0xFF);
 
 	assert((index >= 0) && (index < 40));
-	_vm->_rulesBuffer2_5[index] = var1;
+	_vm->_characterCarried[index] = var1;
 	_vm->_rulesBuffer2_6[index] = var3;
 	_vm->_rulesBuffer2_7[index] = var4;
 
@@ -2472,7 +2472,7 @@ void LilliputScript::OC_sub17C76() {
 	debugC(1, kDebugScript, "OC_sub17C76()");
 	
 	int index = getValue1();
-	_vm->_rulesBuffer2_5[index] = -1;
+	_vm->_characterCarried[index] = -1;
 	_vm->_characterPositionAltitude[index] = 0;
 	_characterScriptEnabled[index] = 1;
 
@@ -2575,7 +2575,7 @@ void LilliputScript::OC_sub17E6D() {
 	debugC(1, kDebugScriptTBC, "OC_sub17E6D()");
 	
 	uint16 var1 = _currScript->readUint16LE();
-	_vm->_rulesBuffer2_12[_vm->_currentScriptCharacter] = (var1 - 2000) & 0xFF;
+	_vm->_characterBehaviour[_vm->_currentScriptCharacter] = (var1 - 2000) & 0xFF;
 }
 
 void LilliputScript::OC_changeCurrentCharacterSprite() {
@@ -3142,8 +3142,8 @@ void LilliputScript::OC_sub1844A() {
 	_vm->_rulesBuffer2_11[var1] = (var2 & 0xFF);
 
 	for (int i = 0; i < 40; i++) {
-		_array10B51[40 * var1 + i] = 0;
-		_array10B51[var1 + 40 * i] = 0;
+		_interactions[40 * var1 + i] = 0;
+		_interactions[var1 + 40 * i] = 0;
 	}
 }
 
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index bb01f80..0bb3efc 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -75,7 +75,7 @@ public:
 	byte _interfaceButtonActivationDelay[20];
 	byte _array122C1[40];
 	byte _array10A39[40];
-	int16 _array10B51[40 * 40];
+	int16 _interactions[40 * 40];
 
 	byte *_savedBuffer215Ptr;
 
@@ -159,17 +159,17 @@ private:
 	byte OC_compCurrentSpeechId();
 	byte OC_checkSaveFlag();
 	byte OC_compScriptForVal();
-	byte OC_sub174D8();
+	byte OC_isCarrying();
 	byte OC_CompareCharacterVariables();
 	byte OC_compareCoords_1();
 	byte OC_compareCoords_2();
 	byte OC_CompareDistanceFromCharacterToPositionWith();
 	byte OC_compareRandomCharacterId();
 	byte OC_IsCurrentCharacterIndex();
-	byte OC_sub175C8();
-	byte OC_sub17640();
-	byte OC_sub176C4();
-	byte OC_compWord10804();
+	byte OC_hasVisibilityLevel();
+	byte OC_hasGainedVisibilityLevel();
+	byte OC_hasReducedVisibilityLevel();
+	byte OC_isHost();
 	byte OC_sub17766();
 	byte OC_sub17782();
 	byte OC_CompareMapValueWith();


Commit: e92e7d5bf6c18453406445788d2b6810d5296ad7
    https://github.com/scummvm/scummvm/commit/e92e7d5bf6c18453406445788d2b6810d5296ad7
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fixes formatting

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/stream.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 050f65d..dcb4c7f 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -232,7 +232,6 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 }
 
 LilliputEngine::~LilliputEngine() {
-
 	DebugMan.clearAllDebugChannels();
 	delete _console;
 	delete _rnd;
@@ -263,7 +262,6 @@ void LilliputEngine::update() {
 }
 
 void LilliputEngine::newInt8() {
-
 	if (_byte12A06 == 0) {
 		_byte12A06 = 2;
 		_byte12A07 ^= 1;
@@ -967,14 +965,13 @@ void LilliputEngine::sub16CA0() {
 		// Hack: Skip if disabled (c2 negative)
 		if (c2 == -1)
 			continue;
-		//
 
 		for (int index2 = _numCharacters - 1; index2 >= 0; index2--) {
 			byte byte16C9F = 0;
 			if ((index != index2) &&
-			        (_characterCarried[index] != index2) &&
-			        (_characterCarried[index2] != index) &&
-			        (_rulesBuffer2_11[index2] & 2) == 0) {
+				(_characterCarried[index] != index2) &&
+				(_characterCarried[index2] != index) &&
+				(_rulesBuffer2_11[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_characterTilePosX[index2];
 				int d2 = _scriptHandler->_characterTilePosY[index2];
 
@@ -1646,7 +1643,7 @@ void LilliputEngine::sub16626() {
 			uint16 index2 = _scriptHandler->_array12811[index] + (index * 16);
 			Common::Point var1 = _scriptHandler->_array12311[index2];
 
-			// /8, then /2 as the function array is a word array 
+			// /8, then /2 as the function array is a word array
 			int16 var2 = var1.x / 16;
 
 			switch (var2) {
@@ -2474,9 +2471,9 @@ void LilliputEngine::loadRules() {
 	static const Common::KeyCode keybMappingArray[26] = {
 		Common::KEYCODE_a, Common::KEYCODE_b, Common::KEYCODE_c, Common::KEYCODE_d, Common::KEYCODE_e,
 		Common::KEYCODE_f, Common::KEYCODE_g, Common::KEYCODE_h, Common::KEYCODE_i, Common::KEYCODE_j,
-		Common::KEYCODE_k, Common::KEYCODE_l, Common::KEYCODE_m, Common::KEYCODE_n, Common::KEYCODE_o, 
+		Common::KEYCODE_k, Common::KEYCODE_l, Common::KEYCODE_m, Common::KEYCODE_n, Common::KEYCODE_o,
 		Common::KEYCODE_p, Common::KEYCODE_q, Common::KEYCODE_r, Common::KEYCODE_s, Common::KEYCODE_t,
-		Common::KEYCODE_u, Common::KEYCODE_v, Common::KEYCODE_w, Common::KEYCODE_x, Common::KEYCODE_y, 
+		Common::KEYCODE_u, Common::KEYCODE_v, Common::KEYCODE_w, Common::KEYCODE_x, Common::KEYCODE_y,
 		Common::KEYCODE_z};
 	Common::File f;
 	uint16 curWord;
@@ -2754,11 +2751,9 @@ void LilliputEngine::handleGameScripts() {
 
 	_nextCharacterIndex = (index + 1) % _numCharacters;
 
-
 	_scriptHandler->_characterScriptEnabled[index] = 0;
 	setCurrentCharacter(index);
 
-
 	_word16EFEh = _array11D49[index] >> 8;
 	_word16EFEl_characterId = _array11D49[index] & 0xFF;
 	_array11D49[index] = -1;
@@ -2770,7 +2765,7 @@ void LilliputEngine::handleGameScripts() {
 
 	/* Decompiler follows
 
-	    //_scriptHandler->listAllTexts();
+		//_scriptHandler->listAllTexts();
 
 		debugC(1, kDebugEngineTBC, "================= Menu Script ==================");
 		ScriptStream script = ScriptStream(_menuScript, _menuScriptSize);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a39267b..33ca6b1 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -626,105 +626,105 @@ static const OpCode opCodes2[] = {
 /* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x0d */	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
 /* 0x0e */	{ "OC_startSpeech5", 0, kNone, kNone, kNone, kNone, kNone },  // todo
-/* 0x0f */	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },  
-/* 0x10 */	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },  
-/* 0x11 */	{ "OC_incScriptForVal", 0, kNone, kNone, kNone, kNone, kNone },  
+/* 0x0f */	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x10 */	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x11 */	{ "OC_incScriptForVal", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x12 */	{ "OC_sub17BA5", 5, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
-/* 0x13 */	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },  
+/* 0x13 */	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 /* 0x14 */	{ "OC_callScript", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script
 /* 0x15 */	{ "OC_callScriptAndReturn", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script then stop
-/* 0x16 */	{ "OC_setCurrentScriptCharacterPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },  
-/* 0x17 */	{ "OC_initScriptFor", 0, kNone, kNone, kNone, kNone, kNone },  
-/* 0x18 */	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
-/* 0x19 */	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },  
-/* 0x1a */	{ "OC_setWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },  
-/* 0x1b */	{ "OC_sub17C0E", 0, kNone, kNone, kNone, kNone, kNone },  
-/* 0x1c */ 	{ "OC_sub17C55", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone }, 
-/* 0x1d */	{ "OC_sub17C76", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x1e */	{ "OC_setCurrentCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x16 */	{ "OC_setCurrentScriptCharacterPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+/* 0x17 */	{ "OC_initScriptFor", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x18 */	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x19 */	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x1a */	{ "OC_setWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x1b */	{ "OC_sub17C0E", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x1c */ 	{ "OC_sub17C55", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone },
+/* 0x1d */	{ "OC_sub17C76", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x1e */	{ "OC_setCurrentCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x1f */	{ "OC_sub17C8B", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-/* 0x20 */	{ "OC_sub17CA2", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x21 */	{ "OC_sub17CB9", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone }, 
+/* 0x20 */	{ "OC_sub17CA2", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x21 */	{ "OC_sub17CB9", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone },
 /* 0x22 */	{ "OC_sub17CD1", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-/* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x24 */	{ "OC_enableCurrentCharacterScript", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
-/* 0x25 */	{ "OC_IncCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone }, 
-/* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x28 */	{ "OC_changeCurrentCharacterSprite", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x29 */	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-/* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-/* 0x2b */	{ "OC_setCharacterDirectionTowardsPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
-/* 0x2c */	{ "OC_turnCharacterTowardsAnother", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x2e */	{ "OC_scrollAwayFromCharacter", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x25 */	{ "OC_IncCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone },
+/* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x28 */	{ "OC_changeCurrentCharacterSprite", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x29 */	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
+/* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
+/* 0x2b */	{ "OC_setCharacterDirectionTowardsPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+/* 0x2c */	{ "OC_turnCharacterTowardsAnother", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x2e */	{ "OC_scrollAwayFromCharacter", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x2f */	{ "OC_skipNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x30 */	{ "OC_setCurrentCharacterVar6", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x32 */	{ "OC_setCharacterScriptEnabled", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x34 */	{ "OC_SetCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x35 */	{ "OC_setCharacterProperties", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
-/* 0x36 */	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
-/* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x39 */	{ "OC_setInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x3a */	{ "OC_scrollViewPort", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x3b */	{ "OC_setViewPortPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
-/* 0x3c */	{ "OC_setCurrentCharacterAltitude", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x3d */	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x3e */	{ "OC_sub181BB", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-/* 0x3f */	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x40 */	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
+/* 0x30 */	{ "OC_setCurrentCharacterVar6", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x32 */	{ "OC_setCharacterScriptEnabled", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x34 */	{ "OC_SetCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x35 */	{ "OC_setCharacterProperties", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
+/* 0x36 */	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
+/* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x39 */	{ "OC_setInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x3a */	{ "OC_scrollViewPort", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x3b */	{ "OC_setViewPortPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+/* 0x3c */	{ "OC_setCurrentCharacterAltitude", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x3d */	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x3e */	{ "OC_sub181BB", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
+/* 0x3f */	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x40 */	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x41 */	{ "OC_sub18260", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone }, // TODO
-/* 0x42 */	{ "OC_CharacterVariableAddOrRemoveFlag", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
-/* 0x43 */	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x44 */	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x45 */	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x46 */	{ "OC_setCurrentCharacterVar3", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x47 */	{ "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x48 */	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x49 */	{ "OC_enableCharacterScript", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x4a */	{ "OC_setRulesBuffer2Element", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x4b */	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x4d */	{ "OC_waitForEvent", 0, kNone, kNone, kNone, kNone, kNone }, 
+/* 0x42 */	{ "OC_CharacterVariableAddOrRemoveFlag", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
+/* 0x43 */	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x44 */	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x45 */	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x46 */	{ "OC_setCurrentCharacterVar3", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x47 */	{ "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x48 */	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x49 */	{ "OC_enableCharacterScript", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+/* 0x4a */	{ "OC_setRulesBuffer2Element", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+/* 0x4b */	{ "OC_setDebugFlag", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x4c */	{ "OC_setByte14837", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x4d */	{ "OC_waitForEvent", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x4e */	{ "OC_disableInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },  // TODO
-/* 0x4f */	{ "OC_loadFileAerial", 1, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x50 */	{ "OC_startSpeechIfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x52 */	{ "OC_displayNumericCharacterVariable", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
-/* 0x53 */	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
+/* 0x4f */	{ "OC_loadFileAerial", 1, kNone, kNone, kNone, kNone, kNone },
+/* 0x50 */	{ "OC_startSpeechIfSoundOff", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x51 */	{ "OC_sub1844A", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+/* 0x52 */	{ "OC_displayNumericCharacterVariable", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
+/* 0x53 */	{ "OC_displayVGAFile", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x54 */	{ "OC_startSpeechWithoutSpeeker", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // TODO
-/* 0x55 */	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x56 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x57 */	{ "OC_displayCharacterStatBar", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue}, 
-/* 0x58 */	{ "OC_initSmallAnim", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue }, 
-/* 0x59 */	{ "OC_setCharacterHeroismBar", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, 
+/* 0x55 */	{ "OC_displayTitleScreen", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x56 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x57 */	{ "OC_displayCharacterStatBar", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue},
+/* 0x58 */	{ "OC_initSmallAnim", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
+/* 0x59 */	{ "OC_setCharacterHeroismBar", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },  //TODO
 /* 0x5b */	{ "OC_setViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x5c */	{ "OC_sub186A1", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },  //TODO
-/* 0x5d */	{ "OC_sub186E5_snd", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x5e */	{ "OC_sub1870A_snd", 2, kgetPosFromScript, kImmediateValue, kNone, kNone, kNone }, 
-/* 0x5f */	{ "OC_sub18725_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x60 */	{ "OC_sub18733_snd", 1, kGetValue1, kNone, kNone, kNone, kNone }, 
-/* 0x61 */	{ "OC_sub1873F_snd", 1, kgetPosFromScript, kNone, kNone, kNone, kNone }, 
-/* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone }, 
-/* 0x63 */	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone }, 
-/* 0x64 */	{ "OC_setCharacterMapColor", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone }, 
+/* 0x5d */	{ "OC_sub186E5_snd", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+/* 0x5e */	{ "OC_sub1870A_snd", 2, kgetPosFromScript, kImmediateValue, kNone, kNone, kNone },
+/* 0x5f */	{ "OC_sub18725_snd", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x60 */	{ "OC_sub18733_snd", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x61 */	{ "OC_sub1873F_snd", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+/* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x63 */	{ "OC_sub1875D_snd", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x64 */	{ "OC_setCharacterMapColor", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 /* 0x65 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
 Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream& script) {
-	
+
 	Common::String str;
 	if (type == kImmediateValue) {
 		str =  Common::String::format("0x%x", script.readUint16LE());
 	} else if (type == kGetValue1) {
 		int val = script.readUint16LE();
-		if (val < 1000) { 
+		if (val < 1000) {
 			str = Common::String::format("0x%x", val);
-		} else if (val > 1004) { 
+		} else if (val > 1004) {
 			str = Common::String::format("getValue1(0x%x)", val);
 		} else if (val == 1000) {
 			str = Common::String("_selectedCharacterId");
@@ -777,7 +777,7 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 	}
 	case 0xF7: {
 		str = Common::String::format("(_characterPositionTileX[_currentCharacterVariables[6]], _characterPositionTileY[_currentCharacterVariables[6]])");
-		break;			 
+		break;
 	}
 	case 0xF6:
 		str = "_savedMousePosDivided";
@@ -800,7 +800,6 @@ Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream&
 }
 
 void LilliputScript::disasmScript(ScriptStream script) {
-	
 	while (!script.eos()) {
 		uint16 val = script.readUint16LE();
 		if (val == 0xFFF6) // end of script
@@ -812,12 +811,10 @@ void LilliputScript::disasmScript(ScriptStream script) {
 			hasIf = true;
 		}
 
-		bool firstIf = true; 
-
+		bool firstIf = true;
 
 		// check the conditions.
 		while (val != 0xFFF8) {
-
 			bool neg = false;
 
 			if (val >= 1000) {
@@ -845,7 +842,6 @@ void LilliputScript::disasmScript(ScriptStream script) {
 			str += "(";
 
 			for (int p = 0; p < opCode->_numArgs; p++) {
-				
 				str += getArgumentString(*opArgType, script);
 				if (p != opCode->_numArgs - 1)
 					str += ", ";
@@ -854,8 +850,6 @@ void LilliputScript::disasmScript(ScriptStream script) {
 			}
 			str += ")";
 
-			
-
 			val = script.readUint16LE();
 
 			if (val == 0xFFF8) {
@@ -870,24 +864,20 @@ void LilliputScript::disasmScript(ScriptStream script) {
 		val = script.readUint16LE();
 
 		while (val != 0xFFF7) {
-			
-			// op code type 2 
+			// op code type 2
 			assert(val < sizeof(opCodes2) / sizeof(OpCode));
 			const OpCode *opCode = &opCodes2[val];
 			const KValueType *opArgType = &opCode->_arg1;
 
 			Common::String str;
-
 			str = "    ";
 			str += Common::String(opCode->_opName);
 			str += "(";
 
 			for (int p = 0; p < opCode->_numArgs; p++) {
 				str += getArgumentString(*opArgType, script);
-
 				if (p != opCode->_numArgs - 1)
 					str += ", ";
-
 				if (p < 4)
 					opArgType++;
 			}
@@ -912,7 +902,7 @@ int LilliputScript::handleOpcode(ScriptStream *script) {
 		return 0xFF;
 
 	for (; curWord != 0xFFF8; curWord = _currScript->readUint16LE()) {
-		byte mask = 0; 
+		byte mask = 0;
 		if (curWord > 1000) {
 			curWord -= 1000;
 			mask = 1;
@@ -941,7 +931,7 @@ void LilliputScript::runScript(ScriptStream script) {
 	debugC(1, kDebugScript, "runScript");
 
 	_byte16F05_ScriptHandler = 1;
-	
+
 	while (handleOpcode(&script) != 0xFF)
 		_vm->update();
 }
@@ -950,7 +940,7 @@ void LilliputScript::runMenuScript(ScriptStream script) {
 	debugC(1, kDebugScriptTBC, "runMenuScript");
 
 	_byte16F05_ScriptHandler = 0;
-	
+
 	while (handleOpcode(&script) == 0)
 		_vm->update();
 }
@@ -1015,7 +1005,7 @@ void LilliputScript::computeOperation(byte *bufPtr, uint16 oper, int16 var3) {
 			int tmpVal = bufPtr[0] / var3;
 			if (tmpVal < 0)
 				bufPtr[0] = 0xFF;
-			else 
+			else
 				bufPtr[0] = 0;
 		}
 		break;
@@ -1041,7 +1031,7 @@ void LilliputScript::sub17B6C(int var1) {
 		int curWord = 0;
 		while (curWord != 0xFFF6)
 			curWord = _currScript->readUint16LE();
-		
+
 		_currScript->seek(_currScript->pos() - 4);
 		return;
 	}
@@ -1213,12 +1203,12 @@ void LilliputScript::decodePackedText(char *buf) {
 
 int LilliputScript::getPackedStringStartRelativeIndex(int index) {
 	debugC(2, kDebugScript, "getPackedStringStartRelativeIndex(%d)", index);
-	
+
 	int chunk4Index = _vm->_packedStringIndex[index];
 	int result = 0;
 	while (_vm->_packedStrings[chunk4Index + result] == 0x5B)
 		++result;
-	
+
 	return result + 1;
 }
 
@@ -1232,7 +1222,7 @@ void LilliputScript::listAllTexts() {
 		while (_vm->_packedStrings[index + variantCount] == 0x5B)
 			++variantCount ;
 		/*
-		int it = 0;	
+		int it = 0;
 		if (variantCount != 0) {
 			for (int j = 0; j < variantCount; j++) {
 				decodePackedText(&_vm->_packedStrings[index + variantCount + it]);
@@ -1245,7 +1235,7 @@ void LilliputScript::listAllTexts() {
 		} else {*/
 			decodePackedText(&_vm->_packedStrings[index + variantCount]);
 			debugC(1, kDebugScriptTBC, "Text 0x%x variant 0 : %s", i, _vm->_displayStringBuf);
-		/* }*/ 
+		/* }*/
 	}
 }
 
@@ -1441,7 +1431,7 @@ byte LilliputScript::OC_getRandom() {
 	int maxVal = _currScript->readUint16LE();
 	int rand = _vm->_rnd->getRandomNumber(maxVal);
 	_lastRandomValue = (rand & 0xFF);
-	
+
 	if (rand == 0)
 		return 1;
 
@@ -1497,7 +1487,7 @@ byte LilliputScript::OC_isCarrying() {
 
 	int8 tmpVal = getValue1() & 0xFF;
 	uint16 curWord = _currScript->readUint16LE();
-	
+
 	if (curWord == 3000) {
 		for (int index = 0; index < _vm->_numCharacters; index++) {
 			if (_vm->_characterCarried[index] == tmpVal) {
@@ -1569,7 +1559,7 @@ byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() {
 
 	Common::Point var1 = getPosFromScript();
 	Common::Point pos = _vm->_currentScriptCharacterPos;
-	
+
 	int dx = var1.x - pos.x;
 	if (dx < 0)
 		dx = -dx;
@@ -1579,10 +1569,10 @@ byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() {
 		dy = -dy;
 
 	int16 dist = dx + dy;
-		
+
 	uint16 operation = _currScript->readUint16LE();
 	int16 var2 = _currScript->readSint16LE();
-	
+
 	return compareValues(dist, operation, var2);
 }
 
@@ -1599,7 +1589,7 @@ byte LilliputScript::OC_compareRandomCharacterId() {
 
 byte LilliputScript::OC_IsCurrentCharacterIndex() {
 	debugC(1, kDebugScript, "OC_IsCurrentCharacterIndex()");
-	
+
 	int tmpVal = getValue1();
 	if (tmpVal == _vm->_currentScriptCharacter)
 		return 1;
@@ -1608,17 +1598,17 @@ byte LilliputScript::OC_IsCurrentCharacterIndex() {
 
 byte LilliputScript::OC_hasVisibilityLevel() {
 	debugC(1, kDebugScript, "OC_hasVisibilityLevel()");
-	
+
 	byte var4 = _currScript->readUint16LE() & 0xFF;
 	int tmpVal = _currScript->readUint16LE();
-	
+
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
 		int var1 = _interactions[(_vm->_currentScriptCharacter * 40) + index];
 		if ((var1 & 0xFF) < var4)
 			return 0;
-		
+
 		_word16F00_characterId = index;
 		return 1;
 	}
@@ -1633,7 +1623,7 @@ byte LilliputScript::OC_hasVisibilityLevel() {
 		}
 		return 0;
 	}
-	
+
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
@@ -1642,8 +1632,8 @@ byte LilliputScript::OC_hasVisibilityLevel() {
 			_word16F00_characterId = i;
 			return 1;
 		}
-	}	
-	
+	}
+
 	return 0;
 }
 
@@ -1678,7 +1668,7 @@ byte LilliputScript::OC_hasGainedVisibilityLevel() {
 			}
 		}
 		return 0;
-	} 
+	}
 
 	var1 -= 2000;
 	var4 = ((var1 & 0xFF) << 8) + (var4 & 0xFF);
@@ -1696,18 +1686,18 @@ byte LilliputScript::OC_hasGainedVisibilityLevel() {
 
 byte LilliputScript::OC_hasReducedVisibilityLevel() {
 	debugC(1, kDebugScript, "OC_hasReducedVisibilityLevel()");
-	
+
 	byte var4 = _currScript->readUint16LE() & 0xFF;
 
 	int tmpVal = _currScript->readUint16LE();
-	
+
 	if (tmpVal < 2000) {
 		_currScript->seek(_currScript->pos() - 2);
 		int index = getValue1();
 		int var1 = _interactions[(_vm->_currentScriptCharacter * 40) + index];
 		if (((var1 & 0xFF) >= var4) || ((var1 >> 8) < var4))
 			return 0;
-		
+
 		_word16F00_characterId = index;
 		return 1;
 	}
@@ -1722,7 +1712,7 @@ byte LilliputScript::OC_hasReducedVisibilityLevel() {
 		}
 		return 0;
 	}
-	
+
 	tmpVal -= 2000;
 	byte var4b = tmpVal & 0xFF;
 	for (int i = 0; i < _vm->_numCharacters; i++) {
@@ -1733,14 +1723,14 @@ byte LilliputScript::OC_hasReducedVisibilityLevel() {
 				return 1;
 			}
 		}
-	}	
-	
+	}
+
 	return 0;
 }
 
 byte LilliputScript::OC_isHost() {
 	debugC(1, kDebugScript, "OC_isHost()");
-	
+
 	int tmpVal = getValue1();
 	if (tmpVal == _vm->_host)
 		return 1;
@@ -1788,7 +1778,7 @@ byte LilliputScript::OC_CompareMapValueWith() {
 	int16 var1 = buf[var2];
 	uint16 oper = _currScript->readUint16LE();
 	var2 = _currScript->readSint16LE();
-	
+
 	return compareValues(var1, oper, var2);
 }
 
@@ -1843,7 +1833,7 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu13() {
 	debugC(1, kDebugScript, "OC_checkLastInterfaceHotspotIndexMenu13()");
 
 	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
-	
+
 	if ((_vm->_actionType != 1) && (_vm->_actionType != kActionTalk))
 		return 0;
 
@@ -2065,7 +2055,7 @@ byte LilliputScript::OC_checkFunctionKeyPressed() {
 		Common::KEYCODE_F5,  Common::KEYCODE_F6, Common::KEYCODE_F7, Common::KEYCODE_F8, Common::KEYCODE_F9};
 
 	int8 index = (_currScript->readUint16LE() & 0xFF) - 0x30;
-	
+
 	if (specialKeys[index] == _vm->_lastKeyPressed.kbd.keycode)
 		return 1;
 
@@ -2105,7 +2095,7 @@ byte LilliputScript::OC_checkViewPortCharacterTarget() {
 	int var1 = getValue1();
 	if (var1 == _viewportCharacterTarget)
 		return 1;
-	
+
 	return 0;
 }
 
@@ -2117,12 +2107,12 @@ void LilliputScript::OC_setWord18821() {
 
 void LilliputScript::OC_ChangeIsoMap() {
 	debugC(1, kDebugScriptTBC, "OC_ChangeIsoMap()");
+
 	Common::Point var1 = getPosFromScript();
 	int var2 = _currScript->readUint16LE();
 	int var3 = _currScript->readUint16LE();
-
 	byte* mapPtr = getMapPtr(var1);
-	
+
 	int mask = 8 >> var2;
 	mask = ~mask;
 	mapPtr[3] &= mask;
@@ -2157,7 +2147,7 @@ void LilliputScript::getSpeechVariant(int speechIndex, int speechVariant) {
 	// [[text1]text2]text3
 	// etc etc
 
-	if (speechIndex == -1) 
+	if (speechIndex == -1)
 		return;
 
 	_currentSpeechId = speechIndex;
@@ -2175,7 +2165,7 @@ void LilliputScript::getSpeechVariant(int speechIndex, int speechVariant) {
 			++index;
 		}
 	}
-	
+
 	if (_vm->_packedStrings[index] == 0)
 		return;
 
@@ -2188,7 +2178,7 @@ void LilliputScript::OC_getComputedVariantSpeech() {
 	int tmpVal1 = getCharacterVariablePtr()[0];
 	int tmpVal2 = (_currScript->readUint16LE() & 0xFF);
 	int speechVariant = tmpVal1 / tmpVal2;
-	
+
 	int speechIndex = _currScript->readUint16LE();
 
 	bool forceReturnFl = false;
@@ -2205,12 +2195,12 @@ void LilliputScript::OC_getRotatingVariantSpeech() {
 
 	int index = _currScript->readUint16LE();
 	int maxValue = getPackedStringStartRelativeIndex(index);
-	
+
 	int currVariant = _currScript->readUint16LE();
 	int nextVariant = currVariant + 1;
 	if (nextVariant >= maxValue)
 		nextVariant = 0;
-	_currScript->writeUint16LE(nextVariant, -2); 
+	_currScript->writeUint16LE(nextVariant, -2);
 
 	bool forceReturnFl = false;
 	checkSpeechAllowed(forceReturnFl);
@@ -2220,7 +2210,7 @@ void LilliputScript::OC_getRotatingVariantSpeech() {
 	_talkingCharacter = _vm->_currentScriptCharacter;
 
 	getSpeechVariant(index, currVariant);
-	
+
 }
 
 void LilliputScript::OC_startSpeechIfMute() {
@@ -2273,14 +2263,14 @@ void LilliputScript::OC_getRandom_type2() {
 	debugC(1, kDebugScript, "OC_getRandom_type2()");
 
 	byte *bufPtr = getCharacterVariablePtr();
-	int maxVal = _currScript->readUint16LE(); 
+	int maxVal = _currScript->readUint16LE();
 	int randomVal = _vm->_rnd->getRandomNumber(maxVal);
 	*bufPtr = randomVal;
 }
 
 void LilliputScript::OC_setCharacterPosition() {
 	debugC(1, kDebugScript, "OC_setCharacterPosition()");
-	
+
 	int index = getValue1();
 	Common::Point tmpVal = getPosFromScript();
 
@@ -2348,7 +2338,7 @@ void LilliputScript::OC_incScriptForVal() {
 
 void LilliputScript::OC_sub17BA5() {
 	debugC(1, kDebugScript, "OC_sub17BA5()");
-	
+
 	byte *tmpArr = getCharacterVariablePtr();
 	uint16 oper = _currScript->readUint16LE();
 	int16 var3 = getCharacterVariablePtr()[0];
@@ -2470,7 +2460,7 @@ void LilliputScript::OC_sub17C55() {
 
 void LilliputScript::OC_sub17C76() {
 	debugC(1, kDebugScript, "OC_sub17C76()");
-	
+
 	int index = getValue1();
 	_vm->_characterCarried[index] = -1;
 	_vm->_characterPositionAltitude[index] = 0;
@@ -2505,7 +2495,7 @@ void LilliputScript::OC_sub17C8B() {
 	int16 type = 2 << 8;
 	int16 var4 = _currScript->readSint16LE();
 	byte var2h = (_currScript->readUint16LE() & 0xFF);
-	
+
 	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
@@ -2515,7 +2505,7 @@ void LilliputScript::OC_sub17CA2() {
 	int16 type = 1 << 8;
 	int16 var4 = _currScript->readSint16LE();
 	byte var2h = (_currScript->readUint16LE() & 0xFF);
-	
+
 	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
@@ -2525,7 +2515,7 @@ void LilliputScript::OC_sub17CB9() {
 	int16 var4 = _currScript->readSint16LE();
 	int16 type = getValue1();
 	byte var2h = (_currScript->readUint16LE() & 0xFF);
-	
+
 	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
@@ -2535,7 +2525,7 @@ void LilliputScript::OC_sub17CD1() {
 	int16 type = 3 << 8;
 	int16 var4 = _currScript->readSint16LE();
 	byte var2h = (_currScript->readUint16LE() & 0xFF);
-	
+
 	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
@@ -2573,7 +2563,7 @@ void LilliputScript::OC_sub17D23() {
 
 void LilliputScript::OC_sub17E6D() {
 	debugC(1, kDebugScriptTBC, "OC_sub17E6D()");
-	
+
 	uint16 var1 = _currScript->readUint16LE();
 	_vm->_characterBehaviour[_vm->_currentScriptCharacter] = (var1 - 2000) & 0xFF;
 }
@@ -2591,7 +2581,7 @@ void LilliputScript::OC_changeCurrentCharacterSprite() {
 byte *LilliputScript::getCurrentCharacterVarFromScript() {
 	debugC(2, kDebugScript, "getCurrentCharacterVarFromScript()");
 
-	int index = _currScript->readUint16LE();	
+	int index = _currScript->readUint16LE();
 	return &_vm->_currentCharacterVariables[index];
 }
 
@@ -2600,7 +2590,7 @@ void LilliputScript::OC_sub17E99() {
 
 	byte *compBuf = getCurrentCharacterVarFromScript();
 	uint16 oper = _currScript->readUint16LE();
-	int index = _currScript->readUint16LE();	
+	int index = _currScript->readUint16LE();
 
 	byte *buf = getCurrentCharacterVarFromScript();
 	byte var1 = buf[0];
@@ -2621,7 +2611,7 @@ void LilliputScript::OC_sub17EC5() {
 
 	byte *tmpBuf = getCurrentCharacterVarFromScript();
 	int16 var3 = tmpBuf[0];
-	
+
 	computeOperation(&_vm->_rulesChunk11[indexChunk11], oper, var3);
 }
 
@@ -2642,7 +2632,7 @@ void LilliputScript::OC_setCharacterDirectionTowardsPos() {
 
 void LilliputScript::OC_turnCharacterTowardsAnother() {
 	debugC(1, kDebugScript, "OC_turnCharacterTowardsAnother()");
-	
+
 	int index = getValue1();
 
 	static const byte _directionsArray[] = { 0, 2, 0, 1, 3, 2, 3, 1 };
@@ -2658,7 +2648,7 @@ void LilliputScript::OC_turnCharacterTowardsAnother() {
 	if (dy < 0) {
 		dy = -dy;
 		flag |= 2;
-	} 
+	}
 	if (dx < dy) {
 		flag |= 1;
 	}
@@ -2683,7 +2673,7 @@ void LilliputScript::OC_scrollAwayFromCharacter() {
 
 	static const char speedX[] = {-1, -3, -3, -6};
 	static const char speedY[] = {-3, -6, -1, -3};
-	
+
 	int cx = speedX[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
 	int cy = speedY[_vm->_characterDirectionArray[_vm->_currentScriptCharacter]];
 
@@ -2718,7 +2708,7 @@ void LilliputScript::OC_skipNextVal() {
 
 void LilliputScript::OC_setCurrentCharacterVar6() {
 	debugC(1, kDebugScript, "OC_setCurrentCharacterVar6()");
-	
+
 	uint16 var1 = (uint16)getValue1();
 	warning("debug - OC_setCurrentCharacterVar6 %d", var1);
 	_vm->_currentCharacterVariables[6] = var1 & 0xFF;
@@ -2728,7 +2718,7 @@ void LilliputScript::OC_sub17FDD() {
 	debugC(1, kDebugScript, "OC_sub17FDD()");
 
 	int index = _currScript->readUint16LE();
-	
+
 	int tmpVal = (_vm->_currentScriptCharacter * 32) + index;
 	assert (tmpVal < 40 * 32);
 	_array10AB1[_vm->_currentScriptCharacter] = _vm->_rulesBuffer2_16[tmpVal];
@@ -2816,10 +2806,10 @@ void LilliputScript::OC_scrollViewPort() {
 	_viewportCharacterTarget = -1;
 
 	int direction = _currScript->readUint16LE();
-	
+
 	static const char scrollValX[] = { 6, 0, 0, -6 };
 	static const char scrollValY[] = { 0, -6, 6, 0 };
-	
+
 	int x = _viewportPos.x + scrollValX[direction];
 	int y = _viewportPos.y + scrollValY[direction];
 
@@ -2877,7 +2867,7 @@ void LilliputScript::sub1818B(Common::Point point) {
 
 void LilliputScript::OC_sub181BB() {
 	debugC(1, kDebugScript, "OC_sub181BB()");
-	
+
 	int8 x = (int8)(_currScript->readUint16LE() & 0xFF);
 	byte oper = _currScript->readUint16LE() & 0xFF;
 	uint16 index = _currScript->readUint16LE();
@@ -2889,7 +2879,7 @@ void LilliputScript::OC_sub181BB() {
 		break;
 	case '>':
 		c -= 128;
-		if (c < 0) 
+		if (c < 0)
 			c = 0;
 		c *= 2;
 		break;
@@ -2941,7 +2931,7 @@ void LilliputScript::OC_sub18252() {
 
 void LilliputScript::OC_sub18260() {
 	debugC(1, kDebugScriptTBC, "OC_sub18260()");
-	
+
 	int index = getValue1();
 	Common::Point var4 = getPosFromScript();
 
@@ -2949,7 +2939,7 @@ void LilliputScript::OC_sub18260() {
 	byte *isoMapBuf = getMapPtr(pt);
 
 	if (isoMapBuf[1] != 0xFF) {
-        int minVal = INT_MAX;
+		int minVal = INT_MAX;
 		for (int var2 = 7; var2 >= 0; var2--) {
 			for (int var3 = 7; var3 >= 0; var3--) {
 				Common::Point(_viewportPos.x + var2, _viewportPos.y + var3);
@@ -3046,7 +3036,7 @@ void LilliputScript::OC_enableCharacterScript() {
 
 	int16 index = getValue1();
 	byte var2 = _currScript->readUint16LE() & 0xFF;
-	
+
 	enableCharacterScript(index, var2, _vm->getCharacterVariablesPtr(index * 32));
 }
 
@@ -3127,7 +3117,7 @@ void LilliputScript::OC_loadFileAerial() {
 void LilliputScript::OC_startSpeechIfSoundOff() {
 	debugC(1, kDebugScriptTBC, "OC_startSpeechIfSoundOff()");
 
-	// HACK: In the original, OC_startSpeechIfSoundOff() only calls 
+	// HACK: In the original, OC_startSpeechIfSoundOff() only calls
 	// OC_startSpeech if sound is off. For the moment, it's always called
 
 	OC_startSpeech();
@@ -3135,7 +3125,7 @@ void LilliputScript::OC_startSpeechIfSoundOff() {
 
 void LilliputScript::OC_sub1844A() {
 	debugC(1, kDebugScriptTBC, "OC_sub1844A()");
-	
+
 	int var1 = getValue1();
 	int var2 = _currScript->readUint16LE();
 
@@ -3218,16 +3208,16 @@ void LilliputScript::OC_displayTitleScreen() {
 				_vm->_keyboard_getch();
 			break;
 		}
-		
+
 		if (_vm->_mouseButton == 1)
 			break;
-		
+
 		if ((_vm->_byte184F4 != 0) && (_vm->_sound_byte16F06 == 0))
 			break;
 
 		_vm->_system->delayMillis(1);
 	}
-	
+
 	_vm->_mouseButton = 0;
 }
 
@@ -3243,7 +3233,7 @@ void LilliputScript::OC_initGameAreaDisplay() {
 
 	OC_PaletteFadeIn();
 	_vm->_refreshScreenFlag = false;
-	
+
 	_vm->_soundHandler->contentFct5();
 }
 
@@ -3255,7 +3245,7 @@ void LilliputScript::OC_displayCharacterStatBar() {
 	int8 score = (((70 * tmpArr[0]) / (_currScript->readUint16LE() & 0xFF)) & 0xFF);
 	int16 posX = _currScript->readSint16LE();
 	int16 posY = _currScript->readSint16LE();
-	
+
 	_vm->displayCharacterStatBar(type, posX, score, posY);
 }
 
@@ -3323,7 +3313,7 @@ void LilliputScript::OC_sub186E5_snd() {
 
 	Common::Point var4 = Common::Point(0xFF, index & 0xFF);
 	int var1 = (_currScript->readUint16LE() & 0xFF);
-	
+
 	_vm->_soundHandler->contentFct2(var1, _viewportPos, Common::Point(_characterTilePosX[index], _characterTilePosY[index]), var4);
 }
 
diff --git a/engines/lilliput/stream.cpp b/engines/lilliput/stream.cpp
index cd0b918..6b33c9d 100644
--- a/engines/lilliput/stream.cpp
+++ b/engines/lilliput/stream.cpp
@@ -32,7 +32,6 @@ ScriptStream::~ScriptStream() {
 }
 
 void ScriptStream::writeUint16LE(int value, int relativePos) {
-	
 	int writePos = pos() + relativePos;
 	assert((writePos >= 0) && (writePos + 2 < size()));
 


Commit: 1552128291f047fc10082642650ea202b17923a2
    https://github.com/scummvm/scummvm/commit/1552128291f047fc10082642650ea202b17923a2
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Changes KValueType to kValueType

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 33ca6b1..61dabc1 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -715,7 +715,7 @@ static const OpCode opCodes2[] = {
 /* 0x65 */	{ "OC_initGameAreaDisplay", 0, kNone, kNone, kNone, kNone, kNone }
 };
 
-Common::String LilliputScript::getArgumentString(KValueType type, ScriptStream& script) {
+Common::String LilliputScript::getArgumentString(kValueType type, ScriptStream& script) {
 
 	Common::String str;
 	if (type == kImmediateValue) {
@@ -826,7 +826,7 @@ void LilliputScript::disasmScript(ScriptStream script) {
 			// op code type 1
 			assert(val < sizeof(opCodes1)/sizeof(OpCode));
 			const OpCode *opCode = &opCodes1[val];
-			const KValueType *opArgType = &opCode->_arg1;
+			const kValueType *opArgType = &opCode->_arg1;
 
 			Common::String str;
 
@@ -867,7 +867,7 @@ void LilliputScript::disasmScript(ScriptStream script) {
 			// op code type 2
 			assert(val < sizeof(opCodes2) / sizeof(OpCode));
 			const OpCode *opCode = &opCodes2[val];
-			const KValueType *opArgType = &opCode->_arg1;
+			const kValueType *opArgType = &opCode->_arg1;
 
 			Common::String str;
 			str = "    ";
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 0bb3efc..ae0c8d8 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -41,7 +41,7 @@ enum kActionType {
 	kCodeEntered = 6
 };
 
-enum KValueType {
+enum kValueType {
 	kNone,
 	kImmediateValue,
 	kCompareOperation,
@@ -54,11 +54,11 @@ enum KValueType {
 struct OpCode {
 	const char* _opName;
 	int _numArgs;
-	KValueType _arg1;
-	KValueType _arg2;
-	KValueType _arg3;
-	KValueType _arg4;
-	KValueType _arg5;
+	kValueType _arg1;
+	kValueType _arg2;
+	kValueType _arg3;
+	kValueType _arg4;
+	kValueType _arg5;
 };
 
 class LilliputScript {
@@ -95,7 +95,7 @@ public:
 
 	void disasmScript(ScriptStream script);
 	void listAllTexts();
-	static Common::String getArgumentString(KValueType type, ScriptStream& script);
+	static Common::String getArgumentString(kValueType type, ScriptStream& script);
 	void runScript(ScriptStream script);
 	void runMenuScript(ScriptStream script);
 private:
@@ -123,7 +123,7 @@ private:
 	int handleOpcode(ScriptStream *script);
 	byte handleOpcodeType1(int curWord);
 	void handleOpcodeType2(int curWord);
-	
+
 	void enableCharacterScript(byte index, byte var1, byte *curBufPtr);
 	void sub17B6C(int var1);
 	void sub16C86(int index, byte *buf);


Commit: 7abc364a4ae635ac90420942cb8bb191e657379b
    https://github.com/scummvm/scummvm/commit/7abc364a4ae635ac90420942cb8bb191e657379b
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Fixes typo

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 61dabc1..7197571 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1148,7 +1148,7 @@ void LilliputScript::sub189B8() {
 void LilliputScript::decodePackedText(char *buf) {
 	debugC(2, kDebugScript, "decodePackedText(buf)");
 
-	// All the languages use the English dictionnary
+	// All the languages use the English dictionary
 	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I've |can't |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|'s |'t |re|gg|tt|pp|nn|ay|ar|wh|";
 
 	_vm->_displayStringIndex = 0;


Commit: 40dc39d01d7143d6622456fa0e6efb4a68385c5e
    https://github.com/scummvm/scummvm/commit/40dc39d01d7143d6622456fa0e6efb4a68385c5e
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Reformats string

Changed paths:
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 7197571..a5df4a6 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1149,7 +1149,13 @@ void LilliputScript::decodePackedText(char *buf) {
 	debugC(2, kDebugScript, "decodePackedText(buf)");
 
 	// All the languages use the English dictionary
-	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |is the |is a |in a |To the |to the |by |going |here |The|the|and |some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|have |you|I've |can't |up |to |he |she |down |what|What|with|are |and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|'s |'t |re|gg|tt|pp|nn|ay|ar|wh|";
+	static const char *nounsArrayPtr = "I am |You are |you are |hou art |in the |"
+		"is the |is a |in a |To the |to the |by |going |here |The|the|and |"
+		"some |build|not |way|I |a |an |from |of |him|her|by |his |ing |tion|"
+		"have |you|I've |can't |up |to |he |she |down |what|What|with|are |"
+		"and|ent|ian|ome|ed |me|my|ai|it|is|of|oo|ea|er|es|th|we|ou|ow|or|"
+		"gh|go|er|st|ee|th|sh|ch|ct|on|ly|ng|nd|nt|ty|ll|le|de|as|ie|in|ss|"
+		"'s |'t |re|gg|tt|pp|nn|ay|ar|wh|";
 
 	_vm->_displayStringIndex = 0;
 	_byte1881A = 0;


Commit: 132fa2fdabffcbfbd49ea90abff354296ff306e3
    https://github.com/scummvm/scummvm/commit/132fa2fdabffcbfbd49ea90abff354296ff306e3
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Updates savefile pattern for numeric wildcard

Changed paths:
    engines/lilliput/detection.cpp


diff --git a/engines/lilliput/detection.cpp b/engines/lilliput/detection.cpp
index afa118d..5a114bc 100644
--- a/engines/lilliput/detection.cpp
+++ b/engines/lilliput/detection.cpp
@@ -169,7 +169,7 @@ SaveStateList LilliputMetaEngine::listSaves(const char *target) const {
 	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
 	Common::StringArray filenames;
 	Common::String pattern = target;
-	pattern += "-??.SAV";
+	pattern += "-##.SAV";
 
 	filenames = saveFileMan->listSavefiles(pattern);
 	sort(filenames.begin(), filenames.end());   // Sort (hopefully ensuring we are sorted numerically..)


Commit: 157e69b8b182b46e54a38ab36fdba8ea909ffa7c
    https://github.com/scummvm/scummvm/commit/157e69b8b182b46e54a38ab36fdba8ea909ffa7c
Author: Joseph-Eugene Winzer (joewinzer at googlemail.com)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Sorts SaveStateList instead of file names

This ensures that the save files are sorted numerically instead of
'hoping' for it.

Changed paths:
    engines/lilliput/detection.cpp


diff --git a/engines/lilliput/detection.cpp b/engines/lilliput/detection.cpp
index 5a114bc..a09e5f0 100644
--- a/engines/lilliput/detection.cpp
+++ b/engines/lilliput/detection.cpp
@@ -172,7 +172,6 @@ SaveStateList LilliputMetaEngine::listSaves(const char *target) const {
 	pattern += "-##.SAV";
 
 	filenames = saveFileMan->listSavefiles(pattern);
-	sort(filenames.begin(), filenames.end());   // Sort (hopefully ensuring we are sorted numerically..)
 
 	SaveStateList saveList;
 	char slot[3];
@@ -210,6 +209,7 @@ SaveStateList LilliputMetaEngine::listSaves(const char *target) const {
 		}
 	}
 
+	Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
 	return saveList;
 }
 


Commit: bda21673e800702db29b8a8a8359a49aa1c8a33e
    https://github.com/scummvm/scummvm/commit/bda21673e800702db29b8a8a8359a49aa1c8a33e
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index dcb4c7f..8275cac 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -154,8 +154,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	_currentScriptCharacterPos = Common::Point(0, 0);
 	_host = 0;
 	_nextCharacterIndex = 0;
-	_word16EFEh = -1;
-	_word16EFEl_characterId = -1;
+	_waitingSignal = -1;
+	_waitingSignalCharacterId = -1;
 	_word1817B = 0;
 	_savedSurfaceUnderMousePos = Common::Point(0, 0);
 	_displayGreenHand = false;
@@ -1358,7 +1358,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 	if (var3.x != -1) {
 		if ((var3.x != _scriptHandler->_characterTilePosX[index]) || (var3.y != _scriptHandler->_characterTilePosY[index])) {
 			sub1693A_chooseDirections(index);
-			_scriptHandler->_array12811[index] -= (param1.x & 0x0F);
+			_scriptHandler->_characterNextSequence[index] -= (param1.x & 0x0F);
 			return 3;
 		}
 
@@ -1374,7 +1374,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 	_characterDirectionArray[index] = getDirection(pos1, pos2);
 
 	sub1693A_chooseDirections(index);
-	_scriptHandler->_array12811[index] -= (param1.x & 0x0F);
+	_scriptHandler->_characterNextSequence[index] -= (param1.x & 0x0F);
 	return 3;
 
 }
@@ -1637,10 +1637,10 @@ void LilliputEngine::sub16626() {
 	while (index >= 0) {
 		result = 2;
 		while (result & 2) {
-			if (_scriptHandler->_array12811[index] == 16)
+			if (_scriptHandler->_characterNextSequence[index] == 16)
 				break;
 
-			uint16 index2 = _scriptHandler->_array12811[index] + (index * 16);
+			uint16 index2 = _scriptHandler->_characterNextSequence[index] + (index * 16);
 			Common::Point var1 = _scriptHandler->_array12311[index2];
 
 			// /8, then /2 as the function array is a word array
@@ -1687,8 +1687,8 @@ void LilliputEngine::sub16626() {
 			}
 
 			if ((result & 1) == 0) {
-				++_scriptHandler->_array12811[index];
-				if (_scriptHandler->_array12811[index] == 16)
+				++_scriptHandler->_characterNextSequence[index];
+				if (_scriptHandler->_characterNextSequence[index] == 16)
 					_scriptHandler->_characterScriptEnabled[index] = 1;
 			}
 		}
@@ -1699,7 +1699,7 @@ void LilliputEngine::sub16626() {
 byte LilliputEngine::sub166EA(int index) {
 	debugC(2, kDebugEngine, "sub166EA(%d)", index);
 
-	_scriptHandler->_array12811[index] = 16;
+	_scriptHandler->_characterNextSequence[index] = 16;
 	_scriptHandler->_characterScriptEnabled[index] = 1;
 	return 1;
 }
@@ -1719,7 +1719,7 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 			return 2;
 	}
 
-	_scriptHandler->_array12811[index] -= (var1.x & 0x0F);
+	_scriptHandler->_characterNextSequence[index] -= (var1.x & 0x0F);
 	return 3;
 }
 
@@ -2754,8 +2754,8 @@ void LilliputEngine::handleGameScripts() {
 	_scriptHandler->_characterScriptEnabled[index] = 0;
 	setCurrentCharacter(index);
 
-	_word16EFEh = _array11D49[index] >> 8;
-	_word16EFEl_characterId = _array11D49[index] & 0xFF;
+	_waitingSignal = _array11D49[index] >> 8;
+	_waitingSignalCharacterId = _array11D49[index] & 0xFF;
 	_array11D49[index] = -1;
 	_word1817B = 0;
 
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 88b50d0..0e87847 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -148,8 +148,8 @@ public:
 	byte _numCharacters;
 	Common::Point _currentScriptCharacterPos;
 	int _nextCharacterIndex;
-	int8 _word16EFEh;
-	int8 _word16EFEl_characterId;
+	int8 _waitingSignal;
+	int8 _waitingSignalCharacterId;
 	uint16 _word1817B;
 	Common::Point _savedSurfaceUnderMousePos;
 	bool _displayGreenHand;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index a5df4a6..255f130 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -64,8 +64,8 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 		_characterScriptEnabled[i] = 1;
 		_characterMapPixelColor[i] = 15;
 		_array10AB1[i] = 0;
-		_array12811[i] = 16;
-		_array12839[i] = -1;
+		_characterNextSequence[i] = 16;
+		_characterLastSequence[i] = -1;
 		_characterTilePosX[i] = 0;
 		_characterTilePosY[i] = 0;
 		_array122C1[i] = 0;
@@ -149,10 +149,10 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_isHost();
 		break;
 	case 0x15:
-		return OC_sub17766();
+		return OC_isSequenceActive();
 		break;
 	case 0x16:
-		return OC_sub17782();
+		return OC_isSequenceFinished();
 		break;
 	case 0x17:
 		return OC_CompareMapValueWith();
@@ -161,10 +161,10 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_IsCharacterValid();
 		break;
 	case 0x19:
-		return OC_compWord16EFE();
+		return OC_CheckWaitingSignal();
 		break;
 	case 0x1A:
-		return OC_AreCurrentCharacterVar0AndVar1EqualsTo();
+		return OC_CurrentCharacterVar0AndVar1Equals();
 		break;
 	case 0x1B:
 		return OC_CurrentCharacterVar0Equals();
@@ -573,32 +573,32 @@ static const OpCode opCodes1[] = {
 	{ "OC_compareCoords_2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_CompareDistanceFromCharacterToPositionWith", 3, kgetPosFromScript, kCompareOperation, kImmediateValue, kNone, kNone },
 	{ "OC_compareRandomCharacterId", 3, kGetValue1, kCompareOperation, kImmediateValue, kNone, kNone },
-	{ "OC_IsCurrentCharacterIndex", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_isCurrentCharacterIndex", 1, kGetValue1, kNone, kNone, kNone, kNone },
 	{ "OC_hasVisibilityLevel", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
 	{ "OC_hasGainedVisibilityLevel", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
 	{ "OC_hasReducedVisibilityLevel", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },
 	{ "OC_isHost", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_sub17766", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub17782", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_CompareMapValueWith", 4, kgetPosFromScript, kImmediateValue, kImmediateValue, kCompareOperation, kNone },
-	{ "OC_IsCharacterValid", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_compWord16EFE", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_AreCurrentCharacterVar0AndVar1EqualsTo", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_CurrentCharacterVar0Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_isSequenceActive", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_isSequenceFinished", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_compareMapValueWith", 4, kgetPosFromScript, kImmediateValue, kImmediateValue, kCompareOperation, kNone },
+	{ "OC_isCharacterValid", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_checkWaitingSignal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_currentCharacterVar0AndVar1Equals", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_currentCharacterVar0Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_checkLastInterfaceHotspotIndexMenu13", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_checkLastInterfaceHotspotIndexMenu2", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_CompareNumberOfCharacterWithVar0Equals", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
-	{ "OC_IsPositionInViewport", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
-	{ "OC_CompareGameVariables", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
+	{ "OC_compareNumberOfCharacterWithVar0Equals", 3, kImmediateValue, kCompareOperation, kImmediateValue, kNone, kNone },
+	{ "OC_isPositionInViewport", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+	{ "OC_compareGameVariables", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
 	{ "OC_skipNextOpcode", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_CurrentCharacterVar2Equals1", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_currentCharacterVar2Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub178D2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_CharacterVariableAnd", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
-	{ "OC_IsCurrentCharacterVar0LessEqualThan", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_characterVariableAnd", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
+	{ "OC_isCurrentCharacterVar0LessEqualThan", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_sub1790F", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_CurrentCharacterVar1Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_currentCharacterVar1Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_isCurrentCharacterActive", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_CurrentCharacterVar3Equals1", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_currentCharacterVar3Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkLastInterfaceHotspotIndex", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkSelectedCharacter", 0, kNone, kNone, kNone, kNone, kNone },
@@ -612,17 +612,17 @@ static const OpCode opCodes1[] = {
 
 static const OpCode opCodes2[] = {
 /* 0x00 */	{ "OC_setWord18821", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x01 */	{ "OC_ChangeIsoMap", 3, kgetPosFromScript, kImmediateValue, kImmediateValue, kNone, kNone },
+/* 0x01 */	{ "OC_changeIsoMap", 3, kgetPosFromScript, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x02 */	{ "OC_startSpeech", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x03 */	{ "OC_getComputedVariantSpeech", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x04 */	{ "OC_getRotatingVariantSpeech", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone }, // todo
 /* 0x05 */	{ "OC_startSpeechIfMute", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x06 */	{ "OC_getComputedVariantSpeechIfMute", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone }, // pb
 /* 0x07 */	{ "OC_startSpeechIfSilent", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-/* 0x08 */	{ "OC_ComputeCharacterVariable", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
+/* 0x08 */	{ "OC_computeCharacterVariable", 4, kGetValue1, kImmediateValue, kComputeOperation, kImmediateValue, kNone },
 /* 0x09 */	{ "OC_getRandom_type2", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
 /* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
-/* 0x0b */	{ "OC_DisableCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x0b */	{ "OC_disableCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x0d */	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
 /* 0x0e */	{ "OC_startSpeech5", 0, kNone, kNone, kNone, kNone, kNone },  // todo
@@ -648,7 +648,7 @@ static const OpCode opCodes2[] = {
 /* 0x22 */	{ "OC_sub17CD1", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x24 */	{ "OC_enableCurrentCharacterScript", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
-/* 0x25 */	{ "OC_IncCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x25 */	{ "OC_incCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone },
 /* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x28 */	{ "OC_changeCurrentCharacterSprite", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
@@ -663,7 +663,7 @@ static const OpCode opCodes2[] = {
 /* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x32 */	{ "OC_setCharacterScriptEnabled", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x34 */	{ "OC_SetCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x34 */	{ "OC_setCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x35 */	{ "OC_setCharacterProperties", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
 /* 0x36 */	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
 /* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
@@ -677,9 +677,9 @@ static const OpCode opCodes2[] = {
 /* 0x3f */	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x40 */	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x41 */	{ "OC_sub18260", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone }, // TODO
-/* 0x42 */	{ "OC_CharacterVariableAddOrRemoveFlag", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
-/* 0x43 */	{ "OC_PaletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone },
-/* 0x44 */	{ "OC_PaletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x42 */	{ "OC_characterVariableAddOrRemoveFlag", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
+/* 0x43 */	{ "OC_paletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x44 */	{ "OC_paletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x45 */	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x46 */	{ "OC_setCurrentCharacterVar3", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x47 */	{ "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
@@ -729,13 +729,13 @@ Common::String LilliputScript::getArgumentString(kValueType type, ScriptStream&
 		} else if (val == 1000) {
 			str = Common::String("_selectedCharacterId");
 		} else if (val == 1001) {
-			str = Common::String("characterIndex");
+			str = Common::String("_characterIndex");
 		} else if (val == 1002) {
 			str = Common::String("_word16F00_characterId");
 		} else if (val == 1003) {
 			str = Common::String("_currentCharacterVariables[6]");
 		} else if (val == 1004) {
-			str = Common::String("_word10804");
+			str = Common::String("_host");
 		}
 	} else if (type == kgetPosFromScript) {
 		int curWord = script.readUint16LE();
@@ -1051,7 +1051,7 @@ void LilliputScript::sub17B6C(int var1) {
 void LilliputScript::sub16C86(int index, byte *buf) {
 	debugC(1, kDebugScript, "sub16C86()");
 
-	_array12811[index] = 0;
+	_characterNextSequence[index] = 0;
 
 	for (int i = 0; i < 16; i++) {
 		_array12311[(index * 16) + i] = Common::Point(buf[(2 * i) + 1], buf[2 * i]);
@@ -1062,7 +1062,7 @@ void LilliputScript::sub16C5C(int index, int8 var3) {
 	debugC(1, kDebugScript, "sub16C5C(%d, %d)", index, var3);
 
 	assert(index < 40);
-	_array12839[index] = var3;
+	_characterLastSequence[index] = var3;
 
 	byte *buf = _vm->_rulesChunk1;
 	if (var3 != 0) {
@@ -1744,21 +1744,21 @@ byte LilliputScript::OC_isHost() {
 	return 0;
 }
 
-byte LilliputScript::OC_sub17766() {
-	debugC(1, kDebugScript, "OC_sub17766()");
+byte LilliputScript::OC_isSequenceActive() {
+	debugC(1, kDebugScript, "OC_isSequenceActive()");
 
 	int8 var1 = (_currScript->readUint16LE() & 0xFF);
-	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] != 16))
+	if ((var1 == _characterLastSequence[_vm->_currentScriptCharacter]) && (_characterNextSequence[_vm->_currentScriptCharacter] != 16))
 		return 1;
 
 	return 0;
 }
 
-byte LilliputScript::OC_sub17782() {
-	debugC(1, kDebugScript, "OC_sub17782()");
+byte LilliputScript::OC_isSequenceFinished() {
+	debugC(1, kDebugScript, "OC_isSequenceFinished()");
 
 	int8 var1 = (_currScript->readUint16LE() & 0xFF);
-	if ((var1 == _array12839[_vm->_currentScriptCharacter]) && (_array12811[_vm->_currentScriptCharacter] == 16))
+	if ((var1 == _characterLastSequence[_vm->_currentScriptCharacter]) && (_characterNextSequence[_vm->_currentScriptCharacter] == 16))
 		return 1;
 
 	return 0;
@@ -1798,21 +1798,21 @@ byte LilliputScript::OC_IsCharacterValid() {
 	return 1;
 }
 
-byte LilliputScript::OC_compWord16EFE() {
-	debugC(1, kDebugScript, "OC_compWord16EFE()");
+byte LilliputScript::OC_CheckWaitingSignal() {
+	debugC(1, kDebugScript, "OC_CheckWaitingSignal()");
 
 	byte curByte = _currScript->readUint16LE() & 0xFF;
-	byte tmpVal = _vm->_word16EFEh;
+	byte tmpVal = _vm->_waitingSignal;
 
 	if (curByte != tmpVal)
 		return 0;
 
-	_word16F00_characterId = _vm->_word16EFEl_characterId;
+	_word16F00_characterId = _vm->_waitingSignalCharacterId;
 	return 1;
 }
 
-byte LilliputScript::OC_AreCurrentCharacterVar0AndVar1EqualsTo() {
-	debugC(1, kDebugScript, "OC_AreCurrentCharacterVar0AndVar1EqualsTo()");
+byte LilliputScript::OC_CurrentCharacterVar0AndVar1Equals() {
+	debugC(1, kDebugScript, "OC_CurrentCharacterVar0AndVar1Equals()");
 
 	byte var1 = _currScript->readUint16LE() & 0xFF;
 	byte var2 = _currScript->readUint16LE() & 0xFF;
@@ -2538,8 +2538,8 @@ void LilliputScript::OC_sub17CD1() {
 void LilliputScript::OC_resetWord16EFE() {
 	debugC(1, kDebugScript, "OC_resetWord16EFE()");
 
-	_vm->_word16EFEh = -1;
-	_vm->_word16EFEl_characterId = -1;
+	_vm->_waitingSignal = -1;
+	_vm->_waitingSignalCharacterId = -1;
 }
 
 void LilliputScript::OC_enableCurrentCharacterScript() {
@@ -2728,7 +2728,7 @@ void LilliputScript::OC_sub17FDD() {
 	int tmpVal = (_vm->_currentScriptCharacter * 32) + index;
 	assert (tmpVal < 40 * 32);
 	_array10AB1[_vm->_currentScriptCharacter] = _vm->_rulesBuffer2_16[tmpVal];
-	_array12811[_vm->_currentScriptCharacter] = 16;
+	_characterNextSequence[_vm->_currentScriptCharacter] = 16;
 }
 
 void LilliputScript::OC_setCharacterScriptEnabled() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index ae0c8d8..51f313e 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -70,7 +70,7 @@ public:
 	int8 _interfaceHotspotStatus[20];
 	int8 _characterTilePosX[40];
 	int8 _characterTilePosY[40];
-	int8 _array12811[40];
+	int8 _characterNextSequence[40];
 	int8 _array10AB1[40];
 	byte _interfaceButtonActivationDelay[20];
 	byte _array122C1[40];
@@ -87,7 +87,7 @@ public:
 
 	Common::Point _array12311[640];
 	byte _characterMapPixelColor[40];
-	int8 _array12839[40];
+	int8 _characterLastSequence[40];
 	Common::Point _array1813BPos[32];
 
 	LilliputScript(LilliputEngine *vm);
@@ -170,12 +170,12 @@ private:
 	byte OC_hasGainedVisibilityLevel();
 	byte OC_hasReducedVisibilityLevel();
 	byte OC_isHost();
-	byte OC_sub17766();
-	byte OC_sub17782();
+	byte OC_isSequenceActive();
+	byte OC_isSequenceFinished();
 	byte OC_CompareMapValueWith();
 	byte OC_IsCharacterValid();
-	byte OC_compWord16EFE();
-	byte OC_AreCurrentCharacterVar0AndVar1EqualsTo();
+	byte OC_CheckWaitingSignal();
+	byte OC_CurrentCharacterVar0AndVar1Equals();
 	byte OC_CurrentCharacterVar0Equals();
 	byte OC_checkLastInterfaceHotspotIndexMenu13();
 	byte OC_checkLastInterfaceHotspotIndexMenu2();


Commit: 491dd07e6812074a960ec81e12752eb12a1a6f51
    https://github.com/scummvm/scummvm/commit/491dd07e6812074a960ec81e12752eb12a1a6f51
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLUPUT: Add missing kActionType values

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 8275cac..2e3ff0a 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -911,7 +911,7 @@ void LilliputEngine::sub15F75() {
 		return;
 
 	_savedMousePosDivided = Common::Point(newX, newY);
-	_actionType = 5;
+	_actionType = kCubeSelected;
 }
 
 void LilliputEngine::unselectInterfaceHotspots() {
@@ -1954,7 +1954,7 @@ void LilliputEngine::checkClickOnGameArea(Common::Point pos) {
 		arrowX += _scriptHandler->_viewportPos.x;
 		arrowY += _scriptHandler->_viewportPos.y;
 		_savedMousePosDivided = Common::Point(arrowX, arrowY);
-		_actionType = 5;
+		_actionType = kCubeSelected;
 	}
 }
 
@@ -2011,7 +2011,7 @@ void LilliputEngine::handleInterfaceHotspot(byte index, byte button) {
 	if (button == 2) {
 		if (!_delayedReactivationAction) {
 			_scriptHandler->_interfaceHotspotStatus[index] = kHotspotEnabled;
-			_actionType = 2;
+			_actionType = kButtonReleased;
 			displayInterfaceHotspots();
 		}
 		return;
@@ -2028,7 +2028,7 @@ void LilliputEngine::handleInterfaceHotspot(byte index, byte button) {
 		_delayedReactivationAction = true;
 		_displayGreenHand = true;
 	} else {
-		_actionType = 1;
+		_actionType = kButtonPressed;
 	}
 
 	displayInterfaceHotspots();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 255f130..4721f0e 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -1840,7 +1840,7 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu13() {
 
 	byte tmpVal = (_currScript->readUint16LE() & 0xFF);
 
-	if ((_vm->_actionType != 1) && (_vm->_actionType != kActionTalk))
+	if ((_vm->_actionType != kButtonPressed) && (_vm->_actionType != kActionTalk))
 		return 0;
 
 	if (tmpVal == _vm->_lastInterfaceHotspotIndex)
@@ -1854,7 +1854,7 @@ byte LilliputScript::OC_checkLastInterfaceHotspotIndexMenu2() {
 
 	int8 hotspotIndex = (_currScript->readUint16LE() & 0xFF);
 
-	if ((_vm->_actionType == 2) && (hotspotIndex == _vm->_lastInterfaceHotspotIndex))
+	if ((_vm->_actionType == kButtonReleased) && (hotspotIndex == _vm->_lastInterfaceHotspotIndex))
 		return 1;
 
 	return 0;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 51f313e..ad40806 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -36,8 +36,11 @@ class LilliputEngine;
 
 enum kActionType {
 	kActionNone = 0,
+	kButtonPressed = 1,
+	kButtonReleased = 2,
 	kActionTalk = 3,
 	kActionGoto = 4,
+	kCubeSelected = 5,
 	kCodeEntered = 6
 };
 


Commit: b17dfaad10c58b5683b67945f7b3d7054456de39
    https://github.com/scummvm/scummvm/commit/b17dfaad10c58b5683b67945f7b3d7054456de39
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 2e3ff0a..17ca425 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -189,7 +189,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array12299[i] = -1;
 		_array109E9PosX[i] = -1;
 		_array10A11PosY[i] = -1;
-		_array16E94[i] = 0;
+		_stingArray[i] = 0;
 
 		_array11D49[i] = -1;
 		_characterPositionX[i] = -1;
@@ -222,7 +222,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_characterVariables[i] = 0;
 	}
 
-	_currentCharacterVariables = NULL;
+	_currentCharacterAttributes = NULL;
 	_bufferIdeogram = NULL;
 	_bufferMen = NULL;
 	_bufferMen2 = NULL;
@@ -1778,10 +1778,10 @@ void LilliputEngine::sub16EBC() {
 		assert((mapIndex >= 0) && (mapIndex < 16384));
 		byte var1 = _bufferIsoMap[mapIndex] & 0x40;
 
-		if (var1 == _array16E94[index1])
+		if (var1 == _stingArray[index1])
 			continue;
 
-		_array16E94[index1] = var1;
+		_stingArray[index1] = var1;
 		if (var1 != 0)
 			_scriptHandler->_characterScriptEnabled[index1] = 1;
 	}
@@ -1794,7 +1794,7 @@ void LilliputEngine::sub12F37() {
 	int index2 = 0;
 
 	for (byte i = 0; i < _numCharacters; i++) {
-		byte *varPtr = getCharacterVariablesPtr(index1);
+		byte *varPtr = getCharacterAttributesPtr(index1);
 		if (varPtr[0] != 0) {
 			if (varPtr[0] == 1) {
 				varPtr[0] = 0;
@@ -2700,7 +2700,7 @@ void LilliputEngine::setCurrentCharacter(int index) {
 	int posY = _characterPositionY[index];
 
 	_currentScriptCharacterPos = Common::Point(posX >> 3, posY >> 3);
-	_currentCharacterVariables = getCharacterVariablesPtr(_currentScriptCharacter * 32);
+	_currentCharacterAttributes = getCharacterAttributesPtr(_currentScriptCharacter * 32);
 }
 
 void LilliputEngine::unselectInterfaceButton() {
@@ -2855,7 +2855,7 @@ void LilliputEngine::initialize() {
 	}
 }
 
-byte *LilliputEngine::getCharacterVariablesPtr(int16 index) {
+byte *LilliputEngine::getCharacterAttributesPtr(int16 index) {
 	debugC(1, kDebugEngine, "getCharacterVariablesPtr(%d)", index);
 
 	assert((index > -3120) && (index < 1400));
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 0e87847..278c973 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -182,7 +182,7 @@ public:
 	byte _rulesBuffer2_13_posX[40];
 	byte _rulesBuffer2_14_posY[40];
 	byte _characterVariables[1400 + 3120];
-	byte *_currentCharacterVariables;
+	byte *_currentCharacterAttributes;
 	byte _rulesBuffer2_16[40 * 32];
 	int *_packedStringIndex;
 	int _packedStringNumb;
@@ -219,7 +219,7 @@ public:
 	int8 _array12299[40];
 	int16 _array109E9PosX[40];
 	int16 _array10A11PosY[40];
-	byte _array16E94[40];
+	byte _stingArray[40];
 	byte _array16C54[4];
 	byte _array16C58[4];
 	byte _savedSurfaceGameArea1[176 * 256]; // 45056
@@ -367,7 +367,7 @@ public:
 	void handleGameScripts();
 
 	// Added by Strangerke
-	byte *getCharacterVariablesPtr(int16 index);
+	byte *getCharacterAttributesPtr(int16 index);
 
 	// Temporary stubs
 	Common::Event _keyboard_getch();
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 4721f0e..34c76e4 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -188,28 +188,28 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_skipNextOpcode();
 		break;
 	case 0x22:
-		return OC_CurrentCharacterVar2Equals1();
+		return OC_CheckCurrentCharacterAttr2();
 		break;
 	case 0x23:
-		return OC_sub178D2();
+		return OC_CheckCurrentCharacterType();
 		break;
 	case 0x24:
-		return OC_CharacterVariableAnd();
+		return OC_CheckCurrentCharacterAttr0And();
 		break;
 	case 0x25:
-		return OC_IsCurrentCharacterVar0LessEqualThan();
+		return OC_IsCurrentCharacterAttr0LessEqualThan();
 		break;
 	case 0x26:
-		return OC_sub1790F();
+		return OC_isCarried();
 		break;
 	case 0x27:
-		return OC_CurrentCharacterVar1Equals();
+		return OC_CheckCurrentCharacterAttr1();
 		break;
 	case 0x28:
-		return OC_isCurrentCharacterActive();
+		return OC_isCurrentCharacterStung();
 		break;
 	case 0x29:
-		return OC_CurrentCharacterVar3Equals1();
+		return OC_CurrentCharacterAttr3Equals1();
 		break;
 	case 0x2A:
 		return OC_checkCharacterDirection();
@@ -591,14 +591,14 @@ static const OpCode opCodes1[] = {
 	{ "OC_isPositionInViewport", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_compareGameVariables", 2, kGetValue1, kGetValue1, kNone, kNone, kNone },
 	{ "OC_skipNextOpcode", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_currentCharacterVar2Equals1", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_sub178D2", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
-	{ "OC_characterVariableAnd", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
-	{ "OC_isCurrentCharacterVar0LessEqualThan", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_sub1790F", 1, kGetValue1, kNone, kNone, kNone, kNone },
-	{ "OC_currentCharacterVar1Equals", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-	{ "OC_isCurrentCharacterActive", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_currentCharacterVar3Equals1", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_CheckCurrentCharacterAttr2", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_CheckCurrentCharacterType", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
+	{ "OC_CheckCurrentCharacterAttr0And", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },
+	{ "OC_IsCurrentCharacterAttr0LessEqualThan", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_isCarried", 1, kGetValue1, kNone, kNone, kNone, kNone },
+	{ "OC_CheckCurrentCharacterAttr1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+	{ "OC_isCurrentCharacterStung", 0, kNone, kNone, kNone, kNone, kNone },
+	{ "OC_CurrentCharacterAttr3Equals1", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_sub1796E", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkLastInterfaceHotspotIndex", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkSelectedCharacter", 0, kNone, kNone, kNone, kNone, kNone },
@@ -1289,7 +1289,7 @@ int16 LilliputScript::getValue1() {
 	case 1002:
 		return _word16F00_characterId;
 	case 1003:
-		return (int16)_vm->_currentCharacterVariables[6];
+		return (int16)_vm->_currentCharacterAttributes[6];
 	case 1004:
 		return _vm->_host;
 	default:
@@ -1333,14 +1333,14 @@ Common::Point LilliputScript::getPosFromScript() {
 	case 0xFA:
 		return Common::Point(_vm->_array10999PosX[_vm->_currentScriptCharacter], _vm->_array109C1PosY[_vm->_currentScriptCharacter]);
 	case 0xF9:
-		return Common::Point(_vm->_currentCharacterVariables[4], _vm->_currentCharacterVariables[5]);
+		return Common::Point(_vm->_currentCharacterAttributes[4], _vm->_currentCharacterAttributes[5]);
 	case 0xF8: {
 		int8 index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
 		return _vm->_rulesBuffer12Pos3[index];
 		}
 	case 0xF7: {
-		int8 index = _vm->_currentCharacterVariables[6];
+		int8 index = _vm->_currentCharacterAttributes[6];
 		assert((index >= 0) && (index < 40));
 		int16 x = _vm->_characterPositionX[index] >> 3;
 		int16 y = _vm->_characterPositionY[index] >> 3;
@@ -1356,14 +1356,14 @@ Common::Point LilliputScript::getPosFromScript() {
 	}
 }
 
-byte *LilliputScript::getCharacterVariablePtr() {
+byte *LilliputScript::getCharacterAttributesPtr() {
 	debugC(2, kDebugScript, "getCharacterVariablePtr()");
 
 	int8 tmpVal = (int8) (getValue1() & 0xFF);
 	int index = tmpVal * 32;
 	index += _currScript->readUint16LE();
 
-	return _vm->getCharacterVariablesPtr(index);
+	return _vm->getCharacterAttributesPtr(index);
 }
 
 byte LilliputScript::OC_checkCharacterGoalPos() {
@@ -1415,7 +1415,7 @@ byte LilliputScript::OC_checkIsoMap3() {
 byte LilliputScript::OC_compareCharacterVariable() {
 	debugC(1, kDebugScript, "OC_compareCharacterVariable()");
 
-	byte *tmpArr = getCharacterVariablePtr();
+	byte *tmpArr = getCharacterAttributesPtr();
 	byte var1 = tmpArr[0];
 	uint16 oper = _currScript->readUint16LE();
 	int16 var2 = _currScript->readUint16LE();
@@ -1517,12 +1517,12 @@ byte LilliputScript::OC_isCarrying() {
 byte LilliputScript::OC_CompareCharacterVariables() {
 	debugC(1, kDebugScript, "OC_CompareCharacterVariables()");
 
-	byte* buf1 = getCharacterVariablePtr();
+	byte* buf1 = getCharacterAttributesPtr();
 	int var1 = *buf1;
 
 	int operation = _currScript->readUint16LE();
 
-	byte* buf2 = getCharacterVariablePtr();
+	byte* buf2 = getCharacterAttributesPtr();
 	int var2 = *buf2;
 
 	return compareValues(var1, operation, var2);
@@ -1585,7 +1585,7 @@ byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() {
 byte LilliputScript::OC_compareRandomCharacterId() {
 	debugC(1, kDebugScriptTBC, "OC_compareRandomCharacterId()");
 
-	byte *tmpArr = getCharacterVariablePtr();
+	byte *tmpArr = getCharacterAttributesPtr();
 	_lastRandomValue = _vm->_rnd->getRandomNumber(tmpArr[0] + 1);
 	uint16 oper = _currScript->readUint16LE();
 	int16 var2 = _currScript->readSint16LE();
@@ -1817,9 +1817,9 @@ byte LilliputScript::OC_CurrentCharacterVar0AndVar1Equals() {
 	byte var1 = _currScript->readUint16LE() & 0xFF;
 	byte var2 = _currScript->readUint16LE() & 0xFF;
 
-	assert(_vm->_currentCharacterVariables != NULL);
+	assert(_vm->_currentCharacterAttributes != NULL);
 
-	if ((var1 == _vm->_currentCharacterVariables[0]) && (var2 == _vm->_currentCharacterVariables[1]))
+	if ((var1 == _vm->_currentCharacterAttributes[0]) && (var2 == _vm->_currentCharacterAttributes[1]))
 		return 1;
 
 	return 0;
@@ -1829,8 +1829,8 @@ byte LilliputScript::OC_CurrentCharacterVar0Equals() {
 	debugC(1, kDebugScript, "OC_CurrentCharacterVar0Equals()");
 
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
-	assert(_vm->_currentCharacterVariables != NULL);
-	if (_vm->_currentCharacterVariables[0] == curByte)
+	assert(_vm->_currentCharacterAttributes != NULL);
+	if (_vm->_currentCharacterAttributes[0] == curByte)
 		return 1;
 	return 0;
 }
@@ -1867,7 +1867,7 @@ byte LilliputScript::OC_CompareNumberOfCharacterWithVar0Equals() {
 	int16 count = 0;
 
 	for (int i = 0; i < _vm->_numCharacters; i++) {
-		if (curByte == *_vm->getCharacterVariablesPtr(32 * i))
+		if (curByte == *_vm->getCharacterAttributesPtr(32 * i))
 			++count;
 	}
 
@@ -1907,17 +1907,17 @@ byte LilliputScript::OC_skipNextOpcode() {
 	return 1;
 }
 
-byte LilliputScript::OC_CurrentCharacterVar2Equals1() {
-	debugC(1, kDebugScript, "OC_CurrentCharacterVar2Equals1()");
+byte LilliputScript::OC_CheckCurrentCharacterAttr2() {
+	debugC(1, kDebugScript, "OC_CheckCurrentCharacterAttr2()");
 
-	assert(_vm->_currentCharacterVariables != NULL);
-	if (_vm->_currentCharacterVariables[2] == 1)
+	assert(_vm->_currentCharacterAttributes != NULL);
+	if (_vm->_currentCharacterAttributes[2] == 1)
 		return 1;
 	return 0;
 }
 
-byte LilliputScript::OC_sub178D2() {
-	debugC(1, kDebugScript, "OC_sub178D2()");
+byte LilliputScript::OC_CheckCurrentCharacterType() {
+	debugC(1, kDebugScript, "OC_CheckCurrentCharacterType()");
 
 	int index = getValue1();
 	assert (index < 40);
@@ -1929,10 +1929,10 @@ byte LilliputScript::OC_sub178D2() {
 	return 0;
 }
 
-byte LilliputScript::OC_CharacterVariableAnd() {
-	debugC(1, kDebugScript, "OC_CharacterVariableAnd()");
+byte LilliputScript::OC_CheckCurrentCharacterAttr0And() {
+	debugC(1, kDebugScript, "OC_CheckCurrentCharacterAttr0And()");
 
-	byte *bufPtr = getCharacterVariablePtr();
+	byte *bufPtr = getCharacterAttributesPtr();
 	byte var1 = bufPtr[0];
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 
@@ -1942,19 +1942,19 @@ byte LilliputScript::OC_CharacterVariableAnd() {
 	return 0;
 }
 
-byte LilliputScript::OC_IsCurrentCharacterVar0LessEqualThan() {
-	debugC(1, kDebugScript, "OC_IsCurrentCharacterVar0LessEqualThan()");
+byte LilliputScript::OC_IsCurrentCharacterAttr0LessEqualThan() {
+	debugC(1, kDebugScript, "OC_IsCurrentCharacterAttr0LessEqualThan()");
 
-	assert(_vm->_currentCharacterVariables != NULL);
+	assert(_vm->_currentCharacterAttributes != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 
-	if (curByte <= _vm->_currentCharacterVariables[0])
+	if (curByte <= _vm->_currentCharacterAttributes[0])
 		return 1;
 	return 0;
 }
 
-byte LilliputScript::OC_sub1790F() {
-	debugC(1, kDebugScript, "OC_sub1790F()");
+byte LilliputScript::OC_isCarried() {
+	debugC(1, kDebugScript, "OC_isCarried()");
 
 	int16 index = getValue1();
 	assert((index >= 0) && (index < 40));
@@ -1966,35 +1966,35 @@ byte LilliputScript::OC_sub1790F() {
 	return 1;
 }
 
-byte LilliputScript::OC_CurrentCharacterVar1Equals() {
-	debugC(1, kDebugScript, "OC_CurrentCharacterVar1Equals()");
+byte LilliputScript::OC_CheckCurrentCharacterAttr1() {
+	debugC(1, kDebugScript, "OC_CheckCurrentCharacterAttr1()");
 
-	assert(_vm->_currentCharacterVariables != NULL);
+	assert(_vm->_currentCharacterAttributes != NULL);
 	byte curByte = (_currScript->readUint16LE() & 0xFF);
 
-	if (_vm->_currentCharacterVariables[1] == curByte)
+	if (_vm->_currentCharacterAttributes[1] == curByte)
 		return 1;
 
 	return 0;
 }
 
-byte LilliputScript::OC_isCurrentCharacterActive() {
-	debugC(1, kDebugScript, "OC_isCurrentCharacterActive()");
+byte LilliputScript::OC_isCurrentCharacterStung() {
+	debugC(1, kDebugScript, "OC_isCurrentCharacterStung()");
 
 	if (_vm->_currentScriptCharacterPos == Common::Point(-1, -1))
 		return 0;
 
-	if (_vm->_array16E94[_vm->_currentScriptCharacter] == 0)
+	if (_vm->_stingArray[_vm->_currentScriptCharacter] == 0)
 		return 0;
 
 	return 1;
 }
 
-byte LilliputScript::OC_CurrentCharacterVar3Equals1() {
-	debugC(1, kDebugScript, "OC_CurrentCharacterVar3Equals1()");
+byte LilliputScript::OC_CurrentCharacterAttr3Equals1() {
+	debugC(1, kDebugScript, "OC_CurrentCharacterAttr3Equals1()");
 
-	assert(_vm->_currentCharacterVariables != NULL);
-	if (_vm->_currentCharacterVariables[3] == 1)
+	assert(_vm->_currentCharacterAttributes != NULL);
+	if (_vm->_currentCharacterAttributes[3] == 1)
 		return 1;
 
 	return 0;
@@ -2181,7 +2181,7 @@ void LilliputScript::getSpeechVariant(int speechIndex, int speechVariant) {
 void LilliputScript::OC_getComputedVariantSpeech() {
 	debugC(1, kDebugScriptTBC, "OC_getComputedVariantSpeech()");
 
-	int tmpVal1 = getCharacterVariablePtr()[0];
+	int tmpVal1 = getCharacterAttributesPtr()[0];
 	int tmpVal2 = (_currScript->readUint16LE() & 0xFF);
 	int speechVariant = tmpVal1 / tmpVal2;
 
@@ -2258,7 +2258,7 @@ void LilliputScript::OC_startSpeechIfSilent() {
 void LilliputScript::OC_ComputeCharacterVariable() {
 	debugC(1, kDebugScript, "OC_ComputeCharacterVariable()");
 
-	byte *bufPtr = getCharacterVariablePtr();
+	byte *bufPtr = getCharacterAttributesPtr();
 	uint16 oper = _currScript->readUint16LE();
 	int16 var3 = _currScript->readSint16LE();
 
@@ -2268,7 +2268,7 @@ void LilliputScript::OC_ComputeCharacterVariable() {
 void LilliputScript::OC_getRandom_type2() {
 	debugC(1, kDebugScript, "OC_getRandom_type2()");
 
-	byte *bufPtr = getCharacterVariablePtr();
+	byte *bufPtr = getCharacterAttributesPtr();
 	int maxVal = _currScript->readUint16LE();
 	int randomVal = _vm->_rnd->getRandomNumber(maxVal);
 	*bufPtr = randomVal;
@@ -2345,16 +2345,16 @@ void LilliputScript::OC_incScriptForVal() {
 void LilliputScript::OC_sub17BA5() {
 	debugC(1, kDebugScript, "OC_sub17BA5()");
 
-	byte *tmpArr = getCharacterVariablePtr();
+	byte *tmpArr = getCharacterAttributesPtr();
 	uint16 oper = _currScript->readUint16LE();
-	int16 var3 = getCharacterVariablePtr()[0];
+	int16 var3 = getCharacterAttributesPtr()[0];
 	computeOperation(tmpArr, oper, var3);
 }
 
 void LilliputScript::OC_setByte18823() {
 	debugC(1, kDebugScriptTBC, "OC_setByte18823()");
 
-	byte *tmpArr = getCharacterVariablePtr();
+	byte *tmpArr = getCharacterAttributesPtr();
 	_byte18823 = *tmpArr;
 }
 
@@ -2432,13 +2432,13 @@ void LilliputScript::OC_setWord10804() {
 void LilliputScript::OC_sub17C0E() {
 	debugC(1, kDebugScript, "OC_sub17C0E()");
 
-	assert(_vm->_currentCharacterVariables != NULL);
-	Common::Point var1 = Common::Point(_vm->_currentCharacterVariables[4], _vm->_currentCharacterVariables[5]);
-	byte var2 = _vm->_currentCharacterVariables[6];
+	assert(_vm->_currentCharacterAttributes != NULL);
+	Common::Point var1 = Common::Point(_vm->_currentCharacterAttributes[4], _vm->_currentCharacterAttributes[5]);
+	byte var2 = _vm->_currentCharacterAttributes[6];
 
 	byte *mapPtr = getMapPtr(var1);
-	mapPtr[var2] = _vm->_currentCharacterVariables[7];
-	mapPtr[3] = _vm->_currentCharacterVariables[8];
+	mapPtr[var2] = _vm->_currentCharacterAttributes[7];
+	mapPtr[3] = _vm->_currentCharacterAttributes[8];
 
 	if (var2 == 0) {
 		_vm->_refreshScreenFlag = true;
@@ -2546,15 +2546,15 @@ void LilliputScript::OC_enableCurrentCharacterScript() {
 	debugC(1, kDebugScript, "OC_enableCurrentCharacterScript()");
 
 	uint8 var1 = (_currScript->readUint16LE() & 0xFF);
-	enableCharacterScript(_vm->_currentScriptCharacter , var1, _vm->_currentCharacterVariables);
+	enableCharacterScript(_vm->_currentScriptCharacter , var1, _vm->_currentCharacterAttributes);
 	sub17B6C(0);
 }
 
 void LilliputScript::OC_IncCurrentCharacterVar1() {
 	debugC(1, kDebugScript, "OC_IncCurrentCharacterVar1()");
 
-	assert(_vm->_currentCharacterVariables != NULL);
-	++_vm->_currentCharacterVariables[1];
+	assert(_vm->_currentCharacterAttributes != NULL);
+	++_vm->_currentCharacterAttributes[1];
 }
 
 void LilliputScript::OC_sub17D23() {
@@ -2562,7 +2562,7 @@ void LilliputScript::OC_sub17D23() {
 
 	uint16 oper = _currScript->readUint16LE();
 	Common::Point var1 = getPosFromScript();
-	byte* buf = _vm->_currentCharacterVariables + 4;
+	byte* buf = _vm->_currentCharacterAttributes + 4;
 	computeOperation(buf, oper, var1.x);
 	computeOperation(buf + 1, oper, var1.y);
 }
@@ -2588,7 +2588,7 @@ byte *LilliputScript::getCurrentCharacterVarFromScript() {
 	debugC(2, kDebugScript, "getCurrentCharacterVarFromScript()");
 
 	int index = _currScript->readUint16LE();
-	return &_vm->_currentCharacterVariables[index];
+	return &_vm->_currentCharacterAttributes[index];
 }
 
 void LilliputScript::OC_sub17E99() {
@@ -2717,7 +2717,7 @@ void LilliputScript::OC_setCurrentCharacterVar6() {
 
 	uint16 var1 = (uint16)getValue1();
 	warning("debug - OC_setCurrentCharacterVar6 %d", var1);
-	_vm->_currentCharacterVariables[6] = var1 & 0xFF;
+	_vm->_currentCharacterAttributes[6] = var1 & 0xFF;
 }
 
 void LilliputScript::OC_sub17FDD() {
@@ -2742,15 +2742,15 @@ void LilliputScript::OC_setCurrentCharacterVar2() {
 	debugC(1, kDebugScript, "OC_setCurrentCharacterVar2()");
 
 	int curWord = _currScript->readUint16LE();
-	assert(_vm->_currentCharacterVariables != NULL);
-	_vm->_currentCharacterVariables[2] = curWord & 0xFF;
+	assert(_vm->_currentCharacterAttributes != NULL);
+	_vm->_currentCharacterAttributes[2] = curWord & 0xFF;
 }
 
 void LilliputScript::OC_SetCurrentCharacterVar2ToZero() {
 	debugC(1, kDebugScript, "OC_SetCurrentCharacterVar2ToZero()");
 
-	assert(_vm->_currentCharacterVariables != NULL);
-	_vm->_currentCharacterVariables[2] = 0;
+	assert(_vm->_currentCharacterAttributes != NULL);
+	_vm->_currentCharacterAttributes[2] = 0;
 }
 
 void LilliputScript::OC_setCharacterProperties() {
@@ -2877,7 +2877,7 @@ void LilliputScript::OC_sub181BB() {
 	int8 x = (int8)(_currScript->readUint16LE() & 0xFF);
 	byte oper = _currScript->readUint16LE() & 0xFF;
 	uint16 index = _currScript->readUint16LE();
-	int16 c = _vm->_currentCharacterVariables[index];
+	int16 c = _vm->_currentCharacterAttributes[index];
 
 	switch (oper) {
 	case '-':
@@ -2923,7 +2923,7 @@ void LilliputScript::OC_sub18213() {
 			maxItem = _array1813BPos[i].x;
 		}
 	}
-	enableCharacterScript(_vm->_currentScriptCharacter, maxItem, _vm->_currentCharacterVariables);
+	enableCharacterScript(_vm->_currentScriptCharacter, maxItem, _vm->_currentCharacterAttributes);
 }
 
 void LilliputScript::OC_sub18252() {
@@ -2971,7 +2971,7 @@ void LilliputScript::OC_sub18260() {
 void LilliputScript::OC_CharacterVariableAddOrRemoveFlag() {
 	debugC(1, kDebugScript, "OC_CharacterVariableAddOrRemoveFlag()");
 
-	byte *tmpArr = getCharacterVariablePtr();
+	byte *tmpArr = getCharacterAttributesPtr();
 
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
 	byte var2 = (_currScript->readUint16LE() & 0xFF);
@@ -3015,9 +3015,9 @@ void LilliputScript::OC_setCurrentCharacterVar3() {
 	debugC(1, kDebugScript, "OC_setCurrentCharacterVar3()");
 
 	byte var1 = _currScript->readUint16LE() & 0xFF;
-	assert(_vm->_currentCharacterVariables != NULL);
+	assert(_vm->_currentCharacterAttributes != NULL);
 
-	_vm->_currentCharacterVariables[3] = var1;
+	_vm->_currentCharacterAttributes[3] = var1;
 }
 
 void LilliputScript::OC_setArray122C1() {
@@ -3031,10 +3031,10 @@ void LilliputScript::OC_sub18367() {
 	debugC(1, kDebugScriptTBC, "OC_sub18367()");
 
 	_characterScriptEnabled[_vm->_currentScriptCharacter] = 1;
-	_vm->_currentCharacterVariables[0] = _array122C1[_vm->_currentScriptCharacter];
-	_vm->_currentCharacterVariables[1] = 0;
-	_vm->_currentCharacterVariables[2] = 0;
-	_vm->_currentCharacterVariables[3] = 0;
+	_vm->_currentCharacterAttributes[0] = _array122C1[_vm->_currentScriptCharacter];
+	_vm->_currentCharacterAttributes[1] = 0;
+	_vm->_currentCharacterAttributes[2] = 0;
+	_vm->_currentCharacterAttributes[3] = 0;
 }
 
 void LilliputScript::OC_enableCharacterScript() {
@@ -3043,7 +3043,7 @@ void LilliputScript::OC_enableCharacterScript() {
 	int16 index = getValue1();
 	byte var2 = _currScript->readUint16LE() & 0xFF;
 
-	enableCharacterScript(index, var2, _vm->getCharacterVariablesPtr(index * 32));
+	enableCharacterScript(index, var2, _vm->getCharacterAttributesPtr(index * 32));
 }
 
 void LilliputScript::OC_setRulesBuffer2Element() {
@@ -3146,7 +3146,7 @@ void LilliputScript::OC_sub1844A() {
 void LilliputScript::OC_displayNumericCharacterVariable() {
 	debugC(1, kDebugScript, "OC_displayNumericCharacterVariable()");
 
-	byte *buf215Ptr = getCharacterVariablePtr();
+	byte *buf215Ptr = getCharacterAttributesPtr();
 	byte tmpVal = buf215Ptr[0];
 	int curWord = _currScript->readUint16LE();
 	assert(curWord != 0);
@@ -3246,7 +3246,7 @@ void LilliputScript::OC_initGameAreaDisplay() {
 void LilliputScript::OC_displayCharacterStatBar() {
 	debugC(1, kDebugScript, "OC_displayCharacterStatBar()");
 
-	byte *tmpArr = getCharacterVariablePtr();
+	byte *tmpArr = getCharacterAttributesPtr();
 	int8 type = (_currScript->readUint16LE() & 0xFF);
 	int8 score = (((70 * tmpArr[0]) / (_currScript->readUint16LE() & 0xFF)) & 0xFF);
 	int16 posX = _currScript->readSint16LE();
@@ -3271,7 +3271,7 @@ void LilliputScript::OC_initSmallAnim() {
 void LilliputScript::OC_setCharacterHeroismBar() {
 	debugC(1, kDebugScript, "OC_setCharacterHeroismBar()");
 
-	_savedBuffer215Ptr = getCharacterVariablePtr();
+	_savedBuffer215Ptr = getCharacterAttributesPtr();
 	_heroismBarX = _currScript->readUint16LE();
 	_heroismBarBottomY = _currScript->readUint16LE();
 }
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index ad40806..d3fb240 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -147,7 +147,7 @@ private:
 	int16 getValue1();
 	Common::Point getPosFromScript();
 
-	byte *getCharacterVariablePtr();
+	byte *getCharacterAttributesPtr();
 	byte compareValues(int16 var1, uint16 oper, int16 var2);
 	void computeOperation(byte *bufPtr, uint16 oper, int16 var2);
 
@@ -186,14 +186,14 @@ private:
 	byte OC_IsPositionInViewport();
 	byte OC_CompareGameVariables();
 	byte OC_skipNextOpcode();
-	byte OC_CurrentCharacterVar2Equals1();
-	byte OC_sub178D2();
-	byte OC_CharacterVariableAnd();
-	byte OC_IsCurrentCharacterVar0LessEqualThan();
-	byte OC_sub1790F();
-	byte OC_CurrentCharacterVar1Equals();
-	byte OC_isCurrentCharacterActive();
-	byte OC_CurrentCharacterVar3Equals1();
+	byte OC_CheckCurrentCharacterAttr2();
+	byte OC_CheckCurrentCharacterType();
+	byte OC_CheckCurrentCharacterAttr0And();
+	byte OC_IsCurrentCharacterAttr0LessEqualThan();
+	byte OC_isCarried();
+	byte OC_CheckCurrentCharacterAttr1();
+	byte OC_isCurrentCharacterStung();
+	byte OC_CurrentCharacterAttr3Equals1();
 	byte OC_checkCharacterDirection();
 	byte OC_checkLastInterfaceHotspotIndex();
 	byte OC_checkSelectedCharacter();


Commit: 37067dd6e9cc329da50aaa213e2a2acee430542c
    https://github.com/scummvm/scummvm/commit/37067dd6e9cc329da50aaa213e2a2acee430542c
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Silent some CppCheck warnings

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/script.cpp


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 17ca425..eaca15d 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -432,9 +432,8 @@ void LilliputEngine::displayInterfaceHotspots() {
 	if (_displayMap)
 		return;
 
-	int tmpVal;
 	for (int index = 0; index < _interfaceHotspotNumb; index++) {
-		tmpVal = _scriptHandler->_interfaceHotspotStatus[index] * 20;
+		int tmpVal = _scriptHandler->_interfaceHotspotStatus[index] * 20;
 		display16x16IndexedBuf(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]));
 	}
 }
@@ -462,12 +461,10 @@ void LilliputEngine::displaySpeechBubble() {
 	static const byte _array15976[16] = {244, 248, 250, 250, 252, 252, 252, 252, 252, 252, 252, 252, 250, 250, 248, 244};
 
 	int index = 192;
-	int tmpIndex;
-	int var3;
 
 	for (int i = 0; i < 16; i++) {
-		var3 = _array15976[i];
-		tmpIndex = index - (var3 / 2);
+		int var3 = _array15976[i];
+		int tmpIndex = index - (var3 / 2);
 		var3 &= 0xFE;
 		for (int j = 0; j < var3; j++) {
 			((byte *)_mainSurface->getPixels())[tmpIndex + j] = 17;
@@ -1477,10 +1474,9 @@ void LilliputEngine::sub1693A_chooseDirections(int index) {
 	byte byte16939 = 0;
 
 	int mapIndex = ((_word16937Pos.y * 64) + _word16937Pos.x) * 4;
-	int mapIndexDiff = 0;
 	int retVal = 0;
 	for (int i = 3; i >= 0; i--) {
-		mapIndexDiff = mapArrayMove[i];
+		int mapIndexDiff = mapArrayMove[i];
 		assert(mapIndex + mapIndexDiff + 3 < 16384);
 		if (((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & _array16C54[i]) != 0) && ((_bufferIsoMap[mapIndex + 3] & _array16C58[i]) != 0)) {
 			if ((_bufferIsoMap[mapIndex + mapIndexDiff + 3] & 0x80) != 0 && (sub16A76(i, index) != 0)) {
@@ -1606,11 +1602,10 @@ void LilliputEngine::numberToString(int param1) {
 
 	static const int _array18AE3[6] = {10000, 1000, 100, 10, 1};
 
-	int count;
 	int var1 = param1;
 	bool hideZeros = true;
 	for (int i = 0; i < 5; i++) {
-		count = 0;
+		int count = 0;
 		while (var1 >= 0) {
 			++count;
 			var1 -= _array18AE3[i];
@@ -2784,7 +2779,7 @@ void LilliputEngine::handleGameScripts() {
 		while (1);
 	*/
 
-	i = index;
+	//i = index;
 	//debugC(1, kDebugEngineTBC, "before char %d, pos %d %d, var0 %d, var1 %d, var2 %d var16 %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), *getCharacterVariablesPtr(i * 32 + 1), *getCharacterVariablesPtr(i * 32 + 2),  *getCharacterVariablesPtr(i * 32 + 22), _scriptHandler->_characterScriptEnabled[i]);
 
 	assert(tmpVal < _gameScriptIndexSize);
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 34c76e4..24572e9 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -805,12 +805,6 @@ void LilliputScript::disasmScript(ScriptStream script) {
 		if (val == 0xFFF6) // end of script
 			return;
 
-		bool hasIf = false;
-
-		if (val != 0xFFF8) {
-			hasIf = true;
-		}
-
 		bool firstIf = true;
 
 		// check the conditions.
@@ -824,7 +818,7 @@ void LilliputScript::disasmScript(ScriptStream script) {
 			}
 
 			// op code type 1
-			assert(val < sizeof(opCodes1)/sizeof(OpCode));
+			assert(val < sizeof(opCodes1) / sizeof(OpCode));
 			const OpCode *opCode = &opCodes1[val];
 			const kValueType *opArgType = &opCode->_arg1;
 
@@ -1038,9 +1032,8 @@ void LilliputScript::sub17B6C(int var1) {
 
 	++var1;
 	int curVal = 0;
-	int tmpVal;
 	while (curVal < var1) {
-		tmpVal = _currScript->readUint16LE();
+		int tmpVal = _currScript->readUint16LE();
 		if (tmpVal == 0xFFF7)
 			++curVal;
 	}
@@ -1093,10 +1086,9 @@ void LilliputScript::formatSpeechString() {
 
 	int index = 0;
 	int var2 = 0x100;
-	int var1;
 
 	for (;;) {
-		var1 = _vm->_displayStringBuf[index++];
+		int var1 = _vm->_displayStringBuf[index++];
 		if (var1 == 0)
 			break;
 


Commit: 81a16b0c8eeac517d3c74b360096dd829c080e54
    https://github.com/scummvm/scummvm/commit/81a16b0c8eeac517d3c74b360096dd829c080e54
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index eaca15d..ae6b298 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -179,8 +179,8 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_array1692B[i] = 0;
 
 	for (int i = 0; i < 40; i++) {
-		_array10999PosX[i] = 0;
-		_array109C1PosY[i] = 0;
+		_characterTargetPosX[i] = 0;
+		_characterTargetPosY[i] = 0;
 		_charactersToDisplay[i] = 0;
 		_characterRelativePositionX[i] = -1;
 		_characterRelativePositionY[i] = -1;
@@ -1359,7 +1359,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 			return 3;
 		}
 
-		if ((var3.x == _array10999PosX[index]) && (var3.y == _array109C1PosY[index]))
+		if ((var3.x == _characterTargetPosX[index]) && (var3.y == _characterTargetPosY[index]))
 			return 2;
 	}
 
@@ -1380,26 +1380,26 @@ void LilliputEngine::sub167EF(int index) {
 	debugC(2, kDebugEngine, "sub167EF(%d)", index);
 
 	int16 word167EB = findHotspot(Common::Point(_scriptHandler->_characterTilePosX[index], _scriptHandler->_characterTilePosY[index]));
-	int16 word167ED = findHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
+	int16 word167ED = findHotspot(Common::Point(_characterTargetPosX[index], _characterTargetPosY[index]));
 
 	if (word167EB == word167ED) {
-		_array109E9PosX[index] = _array10999PosX[index];
-		_array10A11PosY[index] = _array109C1PosY[index];
+		_array109E9PosX[index] = _characterTargetPosX[index];
+		_array10A11PosY[index] = _characterTargetPosY[index];
 		return;
 	}
 
 	if (word167EB == -1) {
-		int tmpVal = reverseFindHotspot(Common::Point(_array10999PosX[index], _array109C1PosY[index]));
+		int tmpVal = reverseFindHotspot(Common::Point(_characterTargetPosX[index], _characterTargetPosY[index]));
 		_array109E9PosX[index] = _rulesBuffer12Pos4[tmpVal].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[tmpVal].y;
 		return;
 	}
 
 	if ((word167ED != -1) &&
-		(_array10999PosX[index] >= _rectXMinMax[word167EB].min) &&
-		(_array10999PosX[index] <= _rectXMinMax[word167EB].max) &&
-		(_array109C1PosY[index] >= _rectYMinMax[word167EB].min) &&
-		(_array109C1PosY[index] <= _rectYMinMax[word167EB].max)) {
+		(_characterTargetPosX[index] >= _rectXMinMax[word167EB].min) &&
+		(_characterTargetPosX[index] <= _rectXMinMax[word167EB].max) &&
+		(_characterTargetPosY[index] >= _rectYMinMax[word167EB].min) &&
+		(_characterTargetPosY[index] <= _rectYMinMax[word167EB].max)) {
 		_array109E9PosX[index] = _rulesBuffer12Pos4[word167ED].x;
 		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
@@ -1749,13 +1749,13 @@ byte LilliputEngine::sub1675D(int index, Common::Point var1) {
 	int charIndex = _scriptHandler->_array10A39[index];
 	Common::Point charPos = Common::Point(_scriptHandler->_characterTilePosX[charIndex], _scriptHandler->_characterTilePosY[charIndex]);
 
-	if ((_array109E9PosX[index] != -1) && (_array109E9PosX[index] == _array10999PosX[index]) && (_array10A11PosY[index] == _array109C1PosY[index])) {
+	if ((_array109E9PosX[index] != -1) && (_array109E9PosX[index] == _characterTargetPosX[index]) && (_array10A11PosY[index] == _characterTargetPosY[index])) {
 		_array109E9PosX[index] = charPos.x;
 		_array10A11PosY[index] = charPos.y;
 	}
 
-	_array10999PosX[index] = charPos.x;
-	_array109C1PosY[index] = charPos.y;
+	_characterTargetPosX[index] = charPos.x;
+	_characterTargetPosY[index] = charPos.y;
 
 	return sub16799(index, var1);
 }
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 278c973..024994d 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -208,8 +208,8 @@ public:
 	int16 _interfaceHotspotsX[20];
 	int16 _interfaceHotspotsY[20];
 	Common::KeyCode _keyboardMapping[20];
-	int16 _array10999PosX[40];
-	int16 _array109C1PosY[40];
+	int16 _characterTargetPosX[40];
+	int16 _characterTargetPosY[40];
 	byte _savedSurfaceUnderMouse[16 * 16];
 	byte _charactersToDisplay[40];
 	int16 _characterRelativePositionX[40];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 24572e9..32de831 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -224,7 +224,7 @@ byte LilliputScript::handleOpcodeType1(int curWord) {
 		return OC_checkDelayedReactivation();
 		break;
 	case 0x2E:
-		return OC_sub179C2();
+		return OC_checkTargetReached();
 		break;
 	case 0x2F:
 		return OC_checkFunctionKeyPressed();
@@ -284,7 +284,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_saveAndQuit();
 		break;
 	case 0xD:
-		OC_sub17B93();
+		OC_nSkipOpcodes();
 		break;
 	case 0xE:
 		OC_startSpeech5();
@@ -603,7 +603,7 @@ static const OpCode opCodes1[] = {
 	{ "OC_checkLastInterfaceHotspotIndex", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 	{ "OC_checkSelectedCharacter", 0, kNone, kNone, kNone, kNone, kNone },
 	{ "OC_checkDelayedReactivation", 0, kNone, kNone, kNone, kNone, kNone },
-	{ "OC_sub179C2", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
+	{ "OC_checkTargetReached", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 	{ "OC_checkFunctionKeyPressed", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 	{ "OC_checkCodeEntered", 3, kImmediateValue, kImmediateValue, kImmediateValue, kNone, kNone },
 	{ "OC_checkViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
@@ -624,7 +624,7 @@ static const OpCode opCodes2[] = {
 /* 0x0a */	{ "OC_setCharacterPosition", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },
 /* 0x0b */	{ "OC_disableCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
-/* 0x0d */	{ "OC_sub17B93", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
+/* 0x0d */	{ "OC_nSkipOpcodes", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
 /* 0x0e */	{ "OC_startSpeech5", 0, kNone, kNone, kNone, kNone, kNone },  // todo
 /* 0x0f */	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x10 */	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
@@ -764,7 +764,7 @@ Common::String LilliputScript::getArgumentString(kValueType type, ScriptStream&
 		break;
 			   }
 	case 0xFA:
-		str = Common::String::format("(_array10999PosX[currentCharacter], _array109C1PosY[currentCharacter])");
+		str = Common::String::format("(_characterTargetPosX[currentCharacter], _characterTargetPosY[currentCharacter])");
 		break;
 	case 0xF9:
 		str = Common::String::format("(_currentCharacterVariables[4], _currentCharacterVariables[5])");
@@ -1018,8 +1018,8 @@ void LilliputScript::enableCharacterScript(byte index, byte var1, byte *curBufPt
 	curBufPtr[3] = 0;
 }
 
-void LilliputScript::sub17B6C(int var1) {
-	debugC(1, kDebugScript, "sub17B6C(%d)", var1);
+void LilliputScript::skipOpcodes(int var1) {
+	debugC(1, kDebugScript, "skipOpcodes(%d)", var1);
 
 	if (var1 == 0) {
 		int curWord = 0;
@@ -1323,7 +1323,7 @@ Common::Point LilliputScript::getPosFromScript() {
 		return Common::Point(x, y);
 		}
 	case 0xFA:
-		return Common::Point(_vm->_array10999PosX[_vm->_currentScriptCharacter], _vm->_array109C1PosY[_vm->_currentScriptCharacter]);
+		return Common::Point(_vm->_characterTargetPosX[_vm->_currentScriptCharacter], _vm->_characterTargetPosY[_vm->_currentScriptCharacter]);
 	case 0xF9:
 		return Common::Point(_vm->_currentCharacterAttributes[4], _vm->_currentCharacterAttributes[5]);
 	case 0xF8: {
@@ -2035,16 +2035,17 @@ byte LilliputScript::OC_checkDelayedReactivation() {
 	return 1;
 }
 
-byte LilliputScript::OC_sub179C2() {
-	debugC(1, kDebugScriptTBC, "OC_sub179C2()");
+byte LilliputScript::OC_checkTargetReached() {
+	debugC(1, kDebugScriptTBC, "OC_checkTargetReached()");
 	Common::Point var1 = getPosFromScript();
 
-	if ((_vm->_array10999PosX[_vm->_currentScriptCharacter] == var1.x)
-		 && (_vm->_array109C1PosY[_vm->_currentScriptCharacter] == var1.y))
+	if ((_vm->_characterTargetPosX[_vm->_currentScriptCharacter] == var1.x)
+		 && (_vm->_characterTargetPosY[_vm->_currentScriptCharacter] == var1.y))
 		return 1;
 
 	return 0;
 }
+
 byte LilliputScript::OC_checkFunctionKeyPressed() {
 	debugC(1, kDebugScript, "OC_checkFunctionKeyPressed()");
 
@@ -2294,15 +2295,17 @@ void LilliputScript::OC_DisableCharacter() {
 }
 
 void LilliputScript::OC_saveAndQuit() {
-	warning("OC_saveAndQuit");
+	warning("TODO: OC_saveAndQuit");
+	_vm->_soundHandler.contentFct6(); // Kill music
+	// TODO: Save game
 	_vm->_shouldQuit = true;
 }
 
-void LilliputScript::OC_sub17B93() {
-	debugC(1, kDebugScript, "OC_sub17B93()");
+void LilliputScript::OC_nSkipOpcodes() {
+	debugC(1, kDebugScript, "OC_nSkipOpcodes()");
 
 	int var1 = _currScript->readUint16LE();
-	sub17B6C(var1);
+	skipOpcodes(var1);
 }
 
 void LilliputScript::OC_startSpeech5() {
@@ -2383,15 +2386,15 @@ void LilliputScript::OC_callScriptAndReturn() {
 	debugC(1, kDebugScript, "OC_callScriptAndReturn()");
 
 	OC_callScript();
-	sub17B6C(0);
+	skipOpcodes(0);
 }
 
 void LilliputScript::OC_setCurrentScriptCharacterPos() {
 	debugC(1, kDebugScript, "OC_setCurrentScriptCharacterPos()");
 
 	Common::Point pos = getPosFromScript();
-	_vm->_array10999PosX[_vm->_currentScriptCharacter] = pos.x;
-	_vm->_array109C1PosY[_vm->_currentScriptCharacter] = pos.y;
+	_vm->_characterTargetPosX[_vm->_currentScriptCharacter] = pos.x;
+	_vm->_characterTargetPosY[_vm->_currentScriptCharacter] = pos.y;
 	_vm->_array109E9PosX[_vm->_currentScriptCharacter] = -1;
 }
 
@@ -2539,7 +2542,7 @@ void LilliputScript::OC_enableCurrentCharacterScript() {
 
 	uint8 var1 = (_currScript->readUint16LE() & 0xFF);
 	enableCharacterScript(_vm->_currentScriptCharacter , var1, _vm->_currentCharacterAttributes);
-	sub17B6C(0);
+	skipOpcodes(0);
 }
 
 void LilliputScript::OC_IncCurrentCharacterVar1() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index d3fb240..c292e12 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -128,7 +128,7 @@ private:
 	void handleOpcodeType2(int curWord);
 
 	void enableCharacterScript(byte index, byte var1, byte *curBufPtr);
-	void sub17B6C(int var1);
+	void skipOpcodes(int var1);
 	void sub16C86(int index, byte *buf);
 	void sub16C5C(int index, int8 var3);
 	void checkSpeechAllowed(bool &forceReturnFl);
@@ -198,7 +198,7 @@ private:
 	byte OC_checkLastInterfaceHotspotIndex();
 	byte OC_checkSelectedCharacter();
 	byte OC_checkDelayedReactivation();
-	byte OC_sub179C2();
+	byte OC_checkTargetReached();
 	byte OC_checkFunctionKeyPressed();
 	byte OC_checkCodeEntered();
 	byte OC_checkViewPortCharacterTarget();
@@ -217,7 +217,7 @@ private:
 	void OC_setCharacterPosition();
 	void OC_DisableCharacter();
 	void OC_saveAndQuit();
-	void OC_sub17B93();
+	void OC_nSkipOpcodes();
 	void OC_startSpeech5();
 	void OC_resetByte1714E();
 	void OC_deleteSavegameAndQuit();


Commit: 2ea8d71a5a45a885bd0026ea291a49d7850294e4
    https://github.com/scummvm/scummvm/commit/2ea8d71a5a45a885bd0026ea291a49d7850294e4
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: More renaming

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index ae6b298..e475a34 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -187,18 +187,18 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_characterDisplayX[i] = 0;
 		_characterDisplayY[i] = 0;
 		_array12299[i] = -1;
-		_array109E9PosX[i] = -1;
-		_array10A11PosY[i] = -1;
+		_characterSubTargetPosX[i] = -1;
+		_characterSubTargetPosY[i] = -1;
 		_stingArray[i] = 0;
 
 		_array11D49[i] = -1;
 		_characterPositionX[i] = -1;
 		_characterPositionY[i] = -1;
-		_characterPositionAltitude[i] = 0;
+		_characterPosAltitude[i] = 0;
 		_characterFrameArray[i] = 0;
 		_characterCarried[i] = -1;
-		_rulesBuffer2_6[i] = 4;
-		_rulesBuffer2_7[i] = 0;
+		_characterBehindDist[i] = 4;
+		_characterAboveDist[i] = 0;
 		_spriteSizeArray[i] = 20;
 		_characterDirectionArray[i] = 0;
 		_rulesBuffer2_10[i] = 0;
@@ -626,8 +626,8 @@ void LilliputEngine::moveCharacters() {
 	for (int i = index; i >= 0; i--) {
 		if (_characterCarried[i] != -1) {
 			int index2 = _characterCarried[i];
-			_characterPositionAltitude[i] = _characterPositionAltitude[index2] + _rulesBuffer2_7[i];
-			int8 tmpVal = _rulesBuffer2_6[i];
+			_characterPosAltitude[i] = _characterPosAltitude[index2] + _characterAboveDist[i];
+			int8 tmpVal = _characterBehindDist[i];
 			_characterDirectionArray[i] = _characterDirectionArray[index2];
 			int var3 = _characterPositionX[index2];
 			int var4 = _characterPositionY[index2];
@@ -665,7 +665,7 @@ void LilliputEngine::moveCharacters() {
 			_characterRelativePositionY[i] = tmpVal3;
 			tmpVal2 = _characterPositionX[i] - pos16213.x;
 			tmpVal3 = _characterPositionY[i] - pos16213.y;
-			int tmpVal4 = _characterPositionAltitude[i];
+			int tmpVal4 = _characterPosAltitude[i];
 			_characterDisplayX[i] = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF;
 			_characterDisplayY[i] = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF;
 			_charactersToDisplay[_numCharactersToDisplay] = i;
@@ -1128,10 +1128,10 @@ void LilliputEngine::sortCharacters() {
 					continue;
 
 				if (_characterRelativePositionX[index1] == _characterRelativePositionX[index2]) {
-					if (_characterPositionAltitude[index1] < _characterPositionAltitude[index2])
+					if (_characterPosAltitude[index1] < _characterPosAltitude[index2])
 						continue;
 
-					if (_characterPositionAltitude[index1] == _characterPositionAltitude[index2]) {
+					if (_characterPosAltitude[index1] == _characterPosAltitude[index2]) {
 						if (_characterDisplayY[index1] < _characterDisplayY[index2])
 							continue;
 					}
@@ -1350,7 +1350,7 @@ byte LilliputEngine::getDirection(Common::Point param1, Common::Point param2) {
 byte LilliputEngine::sub16799(int index, Common::Point param1) {
 	debugC(2, kDebugEngine, "sub16799(%d, %d - %d)", index, param1.x, param1.y);
 
-	Common::Point var3 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
+	Common::Point var3 = Common::Point(_characterSubTargetPosX[index], _characterSubTargetPosY[index]);
 
 	if (var3.x != -1) {
 		if ((var3.x != _scriptHandler->_characterTilePosX[index]) || (var3.y != _scriptHandler->_characterTilePosY[index])) {
@@ -1366,7 +1366,7 @@ byte LilliputEngine::sub16799(int index, Common::Point param1) {
 	sub167EF(index);
 
 	Common::Point pos1 = Common::Point(_scriptHandler->_characterTilePosX[index], _scriptHandler->_characterTilePosY[index]);
-	Common::Point pos2 = Common::Point(_array109E9PosX[index], _array10A11PosY[index]);
+	Common::Point pos2 = Common::Point(_characterSubTargetPosX[index], _characterSubTargetPosY[index]);
 
 	_characterDirectionArray[index] = getDirection(pos1, pos2);
 
@@ -1383,15 +1383,15 @@ void LilliputEngine::sub167EF(int index) {
 	int16 word167ED = findHotspot(Common::Point(_characterTargetPosX[index], _characterTargetPosY[index]));
 
 	if (word167EB == word167ED) {
-		_array109E9PosX[index] = _characterTargetPosX[index];
-		_array10A11PosY[index] = _characterTargetPosY[index];
+		_characterSubTargetPosX[index] = _characterTargetPosX[index];
+		_characterSubTargetPosY[index] = _characterTargetPosY[index];
 		return;
 	}
 
 	if (word167EB == -1) {
 		int tmpVal = reverseFindHotspot(Common::Point(_characterTargetPosX[index], _characterTargetPosY[index]));
-		_array109E9PosX[index] = _rulesBuffer12Pos4[tmpVal].x;
-		_array10A11PosY[index] = _rulesBuffer12Pos4[tmpVal].y;
+		_characterSubTargetPosX[index] = _rulesBuffer12Pos4[tmpVal].x;
+		_characterSubTargetPosY[index] = _rulesBuffer12Pos4[tmpVal].y;
 		return;
 	}
 
@@ -1400,26 +1400,26 @@ void LilliputEngine::sub167EF(int index) {
 		(_characterTargetPosX[index] <= _rectXMinMax[word167EB].max) &&
 		(_characterTargetPosY[index] >= _rectYMinMax[word167EB].min) &&
 		(_characterTargetPosY[index] <= _rectYMinMax[word167EB].max)) {
-		_array109E9PosX[index] = _rulesBuffer12Pos4[word167ED].x;
-		_array10A11PosY[index] = _rulesBuffer12Pos4[word167ED].y;
+		_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167ED].x;
+		_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167ED].y;
 		return;
 	}
 
-	_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
-	_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
+	_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x;
+	_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y;
 	int var4h = _rectXMinMax[word167EB].min;
 	int var4l = _rectXMinMax[word167EB].max;
 
 	if (var4h != var4l) {
 		if (_rulesBuffer12Pos4[word167EB].x == var4h) {
-			_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x - 1;
-			_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
+			_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x - 1;
+			_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y;
 			return;
 		}
 
 		if (_rulesBuffer12Pos4[word167EB].x == var4l) {
-			_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x + 1;
-			_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
+			_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x + 1;
+			_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y;
 			return;
 		}
 
@@ -1428,11 +1428,11 @@ void LilliputEngine::sub167EF(int index) {
 
 		if (var4h != var4l) {
 			if (_rulesBuffer12Pos4[word167EB].y == var4h) {
-				_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
-				_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y - 1;
+				_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x;
+				_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y - 1;
 			} else {
-				_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
-				_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y + 1;
+				_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x;
+				_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y + 1;
 			}
 			return;
 		}
@@ -1444,17 +1444,17 @@ void LilliputEngine::sub167EF(int index) {
 
 	int tmpVal = _bufferIsoMap[mapIndex + 3];
 	if ((tmpVal & 8) != 0) {
-		_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x + 1;
-		_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
+		_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x + 1;
+		_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y;
 	} else if ((tmpVal & 4) != 0) {
-		_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
-		_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y - 1;
+		_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x;
+		_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y - 1;
 	} else if ((tmpVal & 2) != 0) {
-		_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x;
-		_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y + 1;
+		_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x;
+		_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y + 1;
 	} else {
-		_array109E9PosX[index] = _rulesBuffer12Pos4[word167EB].x - 1;
-		_array10A11PosY[index] = _rulesBuffer12Pos4[word167EB].y;
+		_characterSubTargetPosX[index] = _rulesBuffer12Pos4[word167EB].x - 1;
+		_characterSubTargetPosY[index] = _rulesBuffer12Pos4[word167EB].y;
 	}
 	return;
 }
@@ -1528,8 +1528,8 @@ byte LilliputEngine::sub16A76(int indexb, int indexs) {
 	if ((var1h >= _rectXMinMax[var2].min) && (var1h <= _rectXMinMax[var2].max) && (var1l >= _rectYMinMax[var2].min) && (var1l <= _rectYMinMax[var2].max))
 		return 0;
 
-	var1h = _array109E9PosX[indexs];
-	var1l = _array10A11PosY[indexs];
+	var1h = _characterSubTargetPosX[indexs];
+	var1l = _characterSubTargetPosY[indexs];
 
 	if ((var1h >= _rectXMinMax[var2].min) && (var1h <= _rectXMinMax[var2].max) && (var1l >= _rectYMinMax[var2].min) && (var1l <= _rectYMinMax[var2].max))
 		return 0;
@@ -1567,8 +1567,8 @@ void LilliputEngine::sub16A08(int index) {
 	int16 arrayDistance[4];
 
 	for (int i = 3; i >= 0; i--) {
-		int16 var1h = _word16937Pos.x + arrayMoveX[i] - _array109E9PosX[index];
-		int16 var1l = _word16937Pos.y + arrayMoveY[i] - _array10A11PosY[index];
+		int16 var1h = _word16937Pos.x + arrayMoveX[i] - _characterSubTargetPosX[index];
+		int16 var1l = _word16937Pos.y + arrayMoveY[i] - _characterSubTargetPosY[index];
 		arrayDistance[i] = (var1l * var1l) + (var1h * var1h);
 	}
 
@@ -1636,7 +1636,7 @@ void LilliputEngine::sub16626() {
 				break;
 
 			uint16 index2 = _scriptHandler->_characterNextSequence[index] + (index * 16);
-			Common::Point var1 = _scriptHandler->_array12311[index2];
+			Common::Point var1 = _scriptHandler->_sequenceArr[index2];
 
 			// /8, then /2 as the function array is a word array
 			int16 var2 = var1.x / 16;
@@ -1708,7 +1708,7 @@ byte LilliputEngine::sub166F7(int index, Common::Point var1, int tmpVal) {
 			a2 |= (a2 << 4);
 
 		a2 -= 16;
-		_scriptHandler->_array12311[tmpVal] = Common::Point(var1.x, a2);
+		_scriptHandler->_sequenceArr[tmpVal] = Common::Point(var1.x, a2);
 
 		if ((a2 & 0xF0) == 0)
 			return 2;
@@ -1749,9 +1749,9 @@ byte LilliputEngine::sub1675D(int index, Common::Point var1) {
 	int charIndex = _scriptHandler->_array10A39[index];
 	Common::Point charPos = Common::Point(_scriptHandler->_characterTilePosX[charIndex], _scriptHandler->_characterTilePosY[charIndex]);
 
-	if ((_array109E9PosX[index] != -1) && (_array109E9PosX[index] == _characterTargetPosX[index]) && (_array10A11PosY[index] == _characterTargetPosY[index])) {
-		_array109E9PosX[index] = charPos.x;
-		_array10A11PosY[index] = charPos.y;
+	if ((_characterSubTargetPosX[index] != -1) && (_characterSubTargetPosX[index] == _characterTargetPosX[index]) && (_characterSubTargetPosY[index] == _characterTargetPosY[index])) {
+		_characterSubTargetPosX[index] = charPos.x;
+		_characterSubTargetPosY[index] = charPos.y;
 	}
 
 	_characterTargetPosX[index] = charPos.x;
@@ -2099,25 +2099,25 @@ void LilliputEngine::turnCharacter2(int index) {
 void LilliputEngine::moveCharacterUp1(int index) {
 	debugC(2, kDebugEngine, "moveCharacterUp1(%d)", index);
 
-	_characterPositionAltitude[index] += 1;
+	_characterPosAltitude[index] += 1;
 }
 
 void LilliputEngine::moveCharacterUp2(int index) {
 	debugC(2, kDebugEngine, "moveCharacterUp2(%d)", index);
 
-	_characterPositionAltitude[index] += 2;
+	_characterPosAltitude[index] += 2;
 }
 
 void LilliputEngine::moveCharacterDown1(int index) {
 	debugC(2, kDebugEngine, "moveCharacterDown1(%d)", index);
 
-	_characterPositionAltitude[index] -= 1;
+	_characterPosAltitude[index] -= 1;
 }
 
 void LilliputEngine::moveCharacterDown2(int index) {
 	debugC(2, kDebugEngine, "moveCharacterDown2(%d)", index);
 
-	_characterPositionAltitude[index] -= 2;
+	_characterPosAltitude[index] -= 2;
 }
 
 void LilliputEngine::moveCharacterSpeed2(int index) {
@@ -2518,11 +2518,11 @@ void LilliputEngine::loadRules() {
 			curWord = (curWord << 3) + 4;
 		_characterPositionY[j] = curWord;
 
-		_characterPositionAltitude[j] = (f.readUint16LE() & 0xFF);
+		_characterPosAltitude[j] = (f.readUint16LE() & 0xFF);
 		_characterFrameArray[j] = f.readUint16LE();
 		_characterCarried[j] = (int8)f.readByte();
-		_rulesBuffer2_6[j] = (int8)f.readByte();
-		_rulesBuffer2_7[j] = f.readByte();
+		_characterBehindDist[j] = (int8)f.readByte();
+		_characterAboveDist[j] = f.readByte();
 		_spriteSizeArray[j] = f.readByte();
 		_characterDirectionArray[j] = f.readByte();
 		_rulesBuffer2_10[j] = f.readByte();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 024994d..4817a2d 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -169,11 +169,11 @@ public:
 	int16 _currentScriptCharacter;
 	int16 _characterPositionX[40];
 	int16 _characterPositionY[40];
-	int8 _characterPositionAltitude[40];
+	int8 _characterPosAltitude[40];
 	int16 _characterFrameArray[40];
 	int8 _characterCarried[40];
-	int8 _rulesBuffer2_6[40];
-	byte _rulesBuffer2_7[40];
+	int8 _characterBehindDist[40];
+	byte _characterAboveDist[40];
 	byte _spriteSizeArray[40];
 	byte _characterDirectionArray[40];
 	byte _rulesBuffer2_10[40];
@@ -217,8 +217,8 @@ public:
 	int16 _characterDisplayX[40];
 	int16 _characterDisplayY[40];
 	int8 _array12299[40];
-	int16 _array109E9PosX[40];
-	int16 _array10A11PosY[40];
+	int16 _characterSubTargetPosX[40];
+	int16 _characterSubTargetPosY[40];
 	byte _stingArray[40];
 	byte _array16C54[4];
 	byte _array16C58[4];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 32de831..6dc6ee0 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -72,7 +72,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	}
 
 	for (int i = 0; i < 640; i++) {
-		_array12311[i] = Common::Point(-1, -1);
+		_sequenceArr[i] = Common::Point(-1, -1);
 	}
 
 	for (int i = 0; i < 1600; i++)
@@ -290,7 +290,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_startSpeech5();
 		break;
 	case 0xF:
-		OC_resetByte1714E();
+		OC_resetHandleOpcodeFlag();
 		break;
 	case 0x10:
 		OC_deleteSavegameAndQuit();
@@ -299,7 +299,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_incScriptForVal();
 		break;
 	case 0x12:
-		OC_sub17BA5();
+		OC_computeChararacterAttr();
 		break;
 	case 0x13:
 		OC_setByte18823();
@@ -317,22 +317,22 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_initScriptFor();
 		break;
 	case 0x18:
-		OC_sub17AE1();
+		OC_setCurrentCharacterSequence();
 		break;
 	case 0x19:
-		OC_sub17AEE();
+		OC_setNextCharacterSequence();
 		break;
 	case 0x1A:
-		OC_setWord10804();
+		OC_setHost();
 		break;
 	case 0x1B:
-		OC_sub17C0E();
+		OC_changeMapCube();
 		break;
 	case 0x1C:
-		OC_sub17C55();
+		OC_setCharacterCarry();
 		break;
 	case 0x1D:
-		OC_sub17C76();
+		OC_dropCarried();
 		break;
 	case 0x1E:
 		OC_setCurrentCharacter();
@@ -626,21 +626,21 @@ static const OpCode opCodes2[] = {
 /* 0x0c */	{ "OC_saveAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x0d */	{ "OC_nSkipOpcodes", 1, kImmediateValue, kNone, kNone, kNone, kNone }, // todo : jump to other opcode
 /* 0x0e */	{ "OC_startSpeech5", 0, kNone, kNone, kNone, kNone, kNone },  // todo
-/* 0x0f */	{ "OC_resetByte1714E", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x0f */	{ "OC_resetHandleOpcodeFlag", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x10 */	{ "OC_deleteSavegameAndQuit", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x11 */	{ "OC_incScriptForVal", 0, kNone, kNone, kNone, kNone, kNone },
-/* 0x12 */	{ "OC_sub17BA5", 5, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
+/* 0x12 */	{ "OC_ComputeChararacterAttr", 5, kGetValue1, kImmediateValue,kComputeOperation, kGetValue1, kImmediateValue },
 /* 0x13 */	{ "OC_setByte18823", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 /* 0x14 */	{ "OC_callScript", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script
 /* 0x15 */	{ "OC_callScriptAndReturn", 2, kImmediateValue, kGetValue1, kNone, kNone, kNone },  // run script then stop
 /* 0x16 */	{ "OC_setCurrentScriptCharacterPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 /* 0x17 */	{ "OC_initScriptFor", 0, kNone, kNone, kNone, kNone, kNone },
-/* 0x18 */	{ "OC_sub17AE1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x19 */	{ "OC_sub17AEE", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x1a */	{ "OC_setWord10804", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x1b */	{ "OC_sub17C0E", 0, kNone, kNone, kNone, kNone, kNone },
-/* 0x1c */ 	{ "OC_sub17C55", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone },
-/* 0x1d */	{ "OC_sub17C76", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x18 */	{ "OC_setCurrentCharacterSequence", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x19 */	{ "OC_setNextCharacterSequence", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x1a */	{ "OC_setHost", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x1b */	{ "OC_changeMapCube", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x1c */ 	{ "OC_setCharacterCarry", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone },
+/* 0x1d */	{ "OC_dropCarried", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x1e */	{ "OC_setCurrentCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x1f */	{ "OC_sub17C8B", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x20 */	{ "OC_sub17CA2", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
@@ -1041,33 +1041,33 @@ void LilliputScript::skipOpcodes(int var1) {
 	_currScript->seek(_currScript->pos() - 2);
 }
 
-void LilliputScript::sub16C86(int index, byte *buf) {
-	debugC(1, kDebugScript, "sub16C86()");
+void LilliputScript::copySequence(int index, byte *buf) {
+	debugC(1, kDebugScript, "copySequence()");
 
 	_characterNextSequence[index] = 0;
 
 	for (int i = 0; i < 16; i++) {
-		_array12311[(index * 16) + i] = Common::Point(buf[(2 * i) + 1], buf[2 * i]);
+		_sequenceArr[(index * 16) + i] = Common::Point(buf[(2 * i) + 1], buf[2 * i]);
 	}
 }
 
-void LilliputScript::sub16C5C(int index, int8 var3) {
-	debugC(1, kDebugScript, "sub16C5C(%d, %d)", index, var3);
+void LilliputScript::setSequence(int charIdx, int8 seqIdx) {
+	debugC(1, kDebugScript, "setSequence(%d, %d)", charIdx, seqIdx);
 
-	assert(index < 40);
-	_characterLastSequence[index] = var3;
+	assert(charIdx < 40);
+	_characterLastSequence[charIdx] = seqIdx;
 
 	byte *buf = _vm->_rulesChunk1;
-	if (var3 != 0) {
+	if (seqIdx != 0) {
 		int count = 0;
-		while (count < var3) {
+		while (count < seqIdx) {
 			if ((buf[0] == 0xFF) && (buf[1] == 0xFF))
 				++count;
 			buf += 2;
 		}
 	}
 
-	sub16C86(index, buf);
+	copySequence(charIdx, buf);
 }
 
 void LilliputScript::checkSpeechAllowed(bool &forceReturnFl) {
@@ -2296,7 +2296,7 @@ void LilliputScript::OC_DisableCharacter() {
 
 void LilliputScript::OC_saveAndQuit() {
 	warning("TODO: OC_saveAndQuit");
-	_vm->_soundHandler.contentFct6(); // Kill music
+	_vm->_soundHandler->contentFct6(); // Kill music
 	// TODO: Save game
 	_vm->_shouldQuit = true;
 }
@@ -2320,8 +2320,8 @@ void LilliputScript::OC_startSpeech5() {
 	startSpeech(5);
 }
 
-void LilliputScript::OC_resetByte1714E() {
-	debugC(1, kDebugScriptTBC, "OC_resetByte1714E()");
+void LilliputScript::OC_resetHandleOpcodeFlag() {
+	debugC(1, kDebugScriptTBC, "OC_resetHandleOpcodeFlag()");
 
 	_vm->_handleOpcodeReturnCode = 0;
 }
@@ -2337,8 +2337,8 @@ void LilliputScript::OC_incScriptForVal() {
 	++_scriptForVal;
 }
 
-void LilliputScript::OC_sub17BA5() {
-	debugC(1, kDebugScript, "OC_sub17BA5()");
+void LilliputScript::OC_computeChararacterAttr() {
+	debugC(1, kDebugScript, "OC_ComputeChararacterAttr()");
 
 	byte *tmpArr = getCharacterAttributesPtr();
 	uint16 oper = _currScript->readUint16LE();
@@ -2395,7 +2395,7 @@ void LilliputScript::OC_setCurrentScriptCharacterPos() {
 	Common::Point pos = getPosFromScript();
 	_vm->_characterTargetPosX[_vm->_currentScriptCharacter] = pos.x;
 	_vm->_characterTargetPosY[_vm->_currentScriptCharacter] = pos.y;
-	_vm->_array109E9PosX[_vm->_currentScriptCharacter] = -1;
+	_vm->_characterSubTargetPosX[_vm->_currentScriptCharacter] = -1;
 }
 
 void LilliputScript::OC_initScriptFor() {
@@ -2404,28 +2404,28 @@ void LilliputScript::OC_initScriptFor() {
 	_scriptForVal = 0;
 }
 
-void LilliputScript::OC_sub17AE1() {
-	debugC(1, kDebugScript, "OC_sub17AE1()");
+void LilliputScript::OC_setCurrentCharacterSequence() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterSequence()");
 
-	int8 var3 = (_currScript->readUint16LE() & 0xFF);
-	sub16C5C(_vm->_currentScriptCharacter, var3);
+	int8 seqIdx = (_currScript->readUint16LE() & 0xFF);
+	setSequence(_vm->_currentScriptCharacter, seqIdx);
 }
 
-void LilliputScript::OC_sub17AEE() {
-	debugC(1, kDebugScript, "OC_sub17AEE()");
+void LilliputScript::OC_setNextCharacterSequence() {
+	debugC(1, kDebugScript, "OC_setNextCharacterSequence()");
 
-	int8 var3 = (_currScript->readUint16LE() & 0xFF);
-	sub16C5C(_vm->_currentScriptCharacter + 1, var3);
+	int8 seqIdx = (_currScript->readUint16LE() & 0xFF);
+	setSequence(_vm->_currentScriptCharacter + 1, seqIdx);
 }
 
-void LilliputScript::OC_setWord10804() {
-	debugC(1, kDebugScript, "OC_setWord10804()");
+void LilliputScript::OC_setHost() {
+	debugC(1, kDebugScript, "OC_setHost()");
 
 	_vm->_host = getValue1();
 }
 
-void LilliputScript::OC_sub17C0E() {
-	debugC(1, kDebugScript, "OC_sub17C0E()");
+void LilliputScript::OC_changeMapCube() {
+	debugC(1, kDebugScript, "OC_changeMapCube()");
 
 	assert(_vm->_currentCharacterAttributes != NULL);
 	Common::Point var1 = Common::Point(_vm->_currentCharacterAttributes[4], _vm->_currentCharacterAttributes[5]);
@@ -2442,31 +2442,30 @@ void LilliputScript::OC_sub17C0E() {
 	}
 }
 
-void LilliputScript::OC_sub17C55() {
-	debugC(1, kDebugScript, "OC_sub17C55()");
+void LilliputScript::OC_setCharacterCarry() {
+	debugC(1, kDebugScript, "OC_setCharacterCarry()");
 
-	int8 var1 = (getValue1() & 0xFF);
+	int8 carriedIdx = (getValue1() & 0xFF);
 	int16 index = getValue1();
 
-	int8 var3 = (_currScript->readSint16LE() & 0xFF);
-	byte var4 = (_currScript->readUint16LE() & 0xFF);
+	int8 distBehind = (_currScript->readSint16LE() & 0xFF);
+	byte distAbove = (_currScript->readUint16LE() & 0xFF);
 
 	assert((index >= 0) && (index < 40));
-	_vm->_characterCarried[index] = var1;
-	_vm->_rulesBuffer2_6[index] = var3;
-	_vm->_rulesBuffer2_7[index] = var4;
+	_vm->_characterCarried[index] = carriedIdx;
+	_vm->_characterBehindDist[index] = distBehind;
+	_vm->_characterAboveDist[index] = distAbove;
 
-	warning("debug - OC_sub17C55 index %d, var1 0x%x var3 0x%x var4 0x%x", index, var1, var3, var4);
+	warning("debug - OC_setCharacterCarry index %d, var1 0x%x var3 0x%x var4 0x%x", index, carriedIdx, distBehind, distAbove);
 }
 
-void LilliputScript::OC_sub17C76() {
-	debugC(1, kDebugScript, "OC_sub17C76()");
+void LilliputScript::OC_dropCarried() {
+	debugC(1, kDebugScript, "OC_dropCarried()");
 
 	int index = getValue1();
 	_vm->_characterCarried[index] = -1;
-	_vm->_characterPositionAltitude[index] = 0;
+	_vm->_characterPosAltitude[index] = 0;
 	_characterScriptEnabled[index] = 1;
-
 }
 
 void LilliputScript::OC_setCurrentCharacter() {
@@ -2663,7 +2662,7 @@ void LilliputScript::OC_sub17F4F() {
 	int16 var = getValue1();
 	_array10A39[_vm->_currentScriptCharacter] = (byte)(var & 0xFF);
 	warning("debug - OC_sub17F4F: _array10A39[%d] = %d", _vm->_currentScriptCharacter, var);
-	_vm->_array109E9PosX[_vm->_currentScriptCharacter] = -1;
+	_vm->_characterSubTargetPosX[_vm->_currentScriptCharacter] = -1;
 }
 
 void LilliputScript::OC_scrollAwayFromCharacter() {
@@ -2761,7 +2760,7 @@ void LilliputScript::OC_setCharacterProperties() {
 	y += _currScript->readSint16LE();
 	_vm->_characterPositionY[index] = y;
 
-	_vm->_characterPositionAltitude[index]  = (int8)(_currScript->readUint16LE() & 0xFF);
+	_vm->_characterPosAltitude[index]  = (int8)(_currScript->readUint16LE() & 0xFF);
 	_vm->_characterDirectionArray[index] = _currScript->readUint16LE() & 0xFF;
 }
 
@@ -2835,7 +2834,7 @@ void LilliputScript::OC_setViewPortPos() {
 void LilliputScript::OC_setCurrentCharacterAltitude() {
 	debugC(1, kDebugScript, "OC_setCurrentCharacterAltitude()");
 
-	_vm->_characterPositionAltitude[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
+	_vm->_characterPosAltitude[_vm->_currentScriptCharacter] = (_currScript->readUint16LE() & 0xFF);
 }
 
 void LilliputScript::OC_sub1817F() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index c292e12..4261b69 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -88,7 +88,7 @@ public:
 	int _heroismBarX;
 	int _heroismBarBottomY;
 
-	Common::Point _array12311[640];
+	Common::Point _sequenceArr[640];
 	byte _characterMapPixelColor[40];
 	int8 _characterLastSequence[40];
 	Common::Point _array1813BPos[32];
@@ -129,8 +129,8 @@ private:
 
 	void enableCharacterScript(byte index, byte var1, byte *curBufPtr);
 	void skipOpcodes(int var1);
-	void sub16C86(int index, byte *buf);
-	void sub16C5C(int index, int8 var3);
+	void copySequence(int index, byte *buf);
+	void setSequence(int charIdx, int8 seqIdx);
 	void checkSpeechAllowed(bool &forceReturnFl);
 	void decodePackedText(char *buf);
 	void startSpeech(int var);
@@ -219,21 +219,21 @@ private:
 	void OC_saveAndQuit();
 	void OC_nSkipOpcodes();
 	void OC_startSpeech5();
-	void OC_resetByte1714E();
+	void OC_resetHandleOpcodeFlag();
 	void OC_deleteSavegameAndQuit();
 	void OC_incScriptForVal();
-	void OC_sub17BA5();
+	void OC_computeChararacterAttr();
 	void OC_setByte18823();
 	void OC_callScript();
 	void OC_callScriptAndReturn();
 	void OC_setCurrentScriptCharacterPos();
 	void OC_initScriptFor();
-	void OC_sub17AE1();
-	void OC_sub17AEE();
-	void OC_setWord10804();
-	void OC_sub17C0E();
-	void OC_sub17C55();
-	void OC_sub17C76();
+	void OC_setCurrentCharacterSequence();
+	void OC_setNextCharacterSequence();
+	void OC_setHost();
+	void OC_changeMapCube();
+	void OC_setCharacterCarry();
+	void OC_dropCarried();
 	void OC_setCurrentCharacter();
 	void OC_sub17C8B();
 	void OC_sub17CA2();


Commit: fedbb3d7fefaa5177b191c90341a8c80037d3dee
    https://github.com/scummvm/scummvm/commit/fedbb3d7fefaa5177b191c90341a8c80037d3dee
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Rename some more opcodes

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index e475a34..663bda4 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -210,7 +210,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 	}
 
 	for (int i = 0; i < 30; i++)
-		_array12861[i] = -1;
+		_signalArray[i] = -1;
 
 	for (int i = 0; i < 256; i++)
 		_savedSurfaceUnderMouse[i] = 0;
@@ -2249,10 +2249,10 @@ void LilliputEngine::sub171CF() {
 	++_word1289D;
 
 	for (int i = 0; i < 10; i++) {
-		if ((_array12861[(3 * i) + 1] != -1) && (_array12861[3 * i] == _word1289D)) {
-			int16 var1 = _array12861[(3 * i) + 1];
-			int var4 = _array12861[(3 * i) + 2];
-			_array12861[(3 * i) + 1] = -1;
+		if ((_signalArray[(3 * i) + 1] != -1) && (_signalArray[3 * i] == _word1289D)) {
+			int16 var1 = _signalArray[(3 * i) + 1];
+			int var4 = _signalArray[(3 * i) + 2];
+			_signalArray[(3 * i) + 1] = -1;
 
 			byte type = var1 >> 8;
 			byte index = var1 & 0xFF;
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 4817a2d..fd71630 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -163,7 +163,7 @@ public:
 	byte _mapSavedPixel[40];
 	int16 _array11D49[40];
 	int16 _array1289F[40];
-	int16 _array12861[30];
+	int16 _signalArray[30];
 
 	byte *_rulesChunk1;
 	int16 _currentScriptCharacter;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 6dc6ee0..4234ff2 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -338,16 +338,16 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setCurrentCharacter();
 		break;
 	case 0x1F:
-		OC_sub17C8B();
+		OC_sendSeeSignal();
 		break;
 	case 0x20:
-		OC_sub17CA2();
+		OC_sendHearSignal();
 		break;
 	case 0x21:
-		OC_sub17CB9();
+		OC_sendVarSignal();
 		break;
 	case 0x22:
-		OC_sub17CD1();
+		OC_sendBroadcastSignal();
 		break;
 	case 0x23:
 		OC_resetWord16EFE();
@@ -642,10 +642,10 @@ static const OpCode opCodes2[] = {
 /* 0x1c */ 	{ "OC_setCharacterCarry", 4, kGetValue1, kGetValue1, kImmediateValue, kImmediateValue, kNone },
 /* 0x1d */	{ "OC_dropCarried", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x1e */	{ "OC_setCurrentCharacter", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x1f */	{ "OC_sub17C8B", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-/* 0x20 */	{ "OC_sub17CA2", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-/* 0x21 */	{ "OC_sub17CB9", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone },
-/* 0x22 */	{ "OC_sub17CD1", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x1f */	{ "OC_sendSeeSignal", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x20 */	{ "OC_sendHearSignal", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x21 */	{ "OC_sendVarSignal", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone },
+/* 0x22 */	{ "OC_sendBroadcastSignal", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x24 */	{ "OC_enableCurrentCharacterScript", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
 /* 0x25 */	{ "OC_incCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone },
@@ -2474,59 +2474,59 @@ void LilliputScript::OC_setCurrentCharacter() {
 	_vm->setCurrentCharacter(index);
 }
 
-void LilliputScript::sub171AF(int16 var1, byte var2h, byte characterId, int16 var4) {
-	debugC(2, kDebugScript, "sub171AF(%d, %d, %d, %d)", var1, var2h, characterId, var4);
+void LilliputScript::sendSignal(int16 var1, byte var2h, byte characterId, int16 var4) {
+	debugC(2, kDebugScript, "sendSignal(%d, %d, %d, %d)", var1, var2h, characterId, var4);
 
 	int index = 0;
 	for (int i = 0; i < 10; i++) {
-		if (_vm->_array12861[index + 1] == -1) {
-			_vm->_array12861[index + 1] = var1;
-			_vm->_array12861[index + 2] = (var2h << 8) + characterId;
-			_vm->_array12861[index + 0] = _vm->_word1289D + var4;
+		if (_vm->_signalArray[index + 1] == -1) {
+			_vm->_signalArray[index + 1] = var1;
+			_vm->_signalArray[index + 2] = (var2h << 8) + characterId; 
+			_vm->_signalArray[index + 0] = _vm->_word1289D + var4;
 			return;
 		}
 		index += 3;
 	}
 }
 
-void LilliputScript::OC_sub17C8B() {
-	debugC(1, kDebugScript, "OC_sub17C8B()");
+void LilliputScript::OC_sendSeeSignal() {
+	debugC(1, kDebugScript, "OC_sendSeeSignal()");
 
-	int16 type = 2 << 8;
+	int16 type = 2 << 8; // SEE
 	int16 var4 = _currScript->readSint16LE();
 	byte var2h = (_currScript->readUint16LE() & 0xFF);
 
-	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
+	sendSignal(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
-void LilliputScript::OC_sub17CA2() {
-	debugC(1, kDebugScript, "OC_sub17CA2()");
+void LilliputScript::OC_sendHearSignal() {
+	debugC(1, kDebugScript, "OC_sendHearSignal()");
 
-	int16 type = 1 << 8;
+	int16 type = 1 << 8; // HEAR
 	int16 var4 = _currScript->readSint16LE();
 	byte var2h = (_currScript->readUint16LE() & 0xFF);
 
-	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
+	sendSignal(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
-void LilliputScript::OC_sub17CB9() {
-	debugC(1, kDebugScriptTBC, "OC_sub17CB9()");
+void LilliputScript::OC_sendVarSignal() {
+	debugC(1, kDebugScriptTBC, "OC_sendVarSignal()");
 
 	int16 var4 = _currScript->readSint16LE();
-	int16 type = getValue1();
+	int16 type = getValue1(); // CHECKME- dubious
 	byte var2h = (_currScript->readUint16LE() & 0xFF);
 
-	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
+	sendSignal(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
-void LilliputScript::OC_sub17CD1() {
-	debugC(1, kDebugScript, "OC_sub17CD1()");
+void LilliputScript::OC_sendBroadcastSignal() {
+	debugC(1, kDebugScript, "OC_sendBroadcastSignal()");
 
 	int16 type = 3 << 8;
 	int16 var4 = _currScript->readSint16LE();
 	byte var2h = (_currScript->readUint16LE() & 0xFF);
 
-	sub171AF(type, var2h, _vm->_currentScriptCharacter, var4);
+	sendSignal(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
 void LilliputScript::OC_resetWord16EFE() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 4261b69..213b1d2 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -137,7 +137,7 @@ private:
 	void displayNumber(byte var1, Common::Point pos);
 	byte *getMapPtr(Common::Point val);
 	byte *getCurrentCharacterVarFromScript();
-	void sub171AF(int16 var1, byte var2h, byte characterId, int16 var4);
+	void sendSignal(int16 var1, byte var2h, byte characterId, int16 var4);
 	void getSpeechVariant(int speechIndex, int speechVariant);
 	void sub189B8();
 	void formatSpeechString();
@@ -235,9 +235,9 @@ private:
 	void OC_setCharacterCarry();
 	void OC_dropCarried();
 	void OC_setCurrentCharacter();
-	void OC_sub17C8B();
-	void OC_sub17CA2();
-	void OC_sub17CB9();
+	void OC_sendSeeSignal();
+	void OC_sendHearSignal();
+	void OC_setVarSignal();
 	void OC_sub17CD1();
 	void OC_resetWord16EFE();
 	void OC_enableCurrentCharacterScript();


Commit: 5bc90c0a4beb9dddb09f6893f13ffe310585b61b
    https://github.com/scummvm/scummvm/commit/5bc90c0a4beb9dddb09f6893f13ffe310585b61b
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming

Changed paths:
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 4234ff2..95b8f4c 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -350,7 +350,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sendBroadcastSignal();
 		break;
 	case 0x23:
-		OC_resetWord16EFE();
+		OC_resetWaitingSignal();
 		break;
 	case 0x24:
 		OC_enableCurrentCharacterScript();
@@ -359,10 +359,10 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_IncCurrentCharacterVar1();
 		break;
 	case 0x26:
-		OC_sub17D23();
+		OC_setCurrentCharacterPos();
 		break;
 	case 0x27:
-		OC_sub17E6D();
+		OC_setCurrentCharacterBehavior();
 		break;
 	case 0x28:
 		OC_changeCurrentCharacterSprite();
@@ -646,11 +646,11 @@ static const OpCode opCodes2[] = {
 /* 0x20 */	{ "OC_sendHearSignal", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x21 */	{ "OC_sendVarSignal", 3, kImmediateValue, kGetValue1, kImmediateValue, kNone, kNone },
 /* 0x22 */	{ "OC_sendBroadcastSignal", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
-/* 0x23 */	{ "OC_resetWord16EFE", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x23 */	{ "OC_resetWaitingSignal", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x24 */	{ "OC_enableCurrentCharacterScript", 1, kImmediateValue, kNone, kNone, kNone, kNone },   // stop script
 /* 0x25 */	{ "OC_incCurrentCharacterVar1", 0, kNone, kNone, kNone, kNone, kNone },
-/* 0x26 */	{ "OC_sub17D23", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone },
-/* 0x27 */	{ "OC_sub17E6D", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x26 */	{ "OC_setCurrentCharacterPos", 2, kImmediateValue, kgetPosFromScript, kNone, kNone, kNone },
+/* 0x27 */	{ "OC_setCurrentCharacterBehavior", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x28 */	{ "OC_changeCurrentCharacterSprite", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x29 */	{ "OC_sub17E99", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
@@ -2529,8 +2529,8 @@ void LilliputScript::OC_sendBroadcastSignal() {
 	sendSignal(type, var2h, _vm->_currentScriptCharacter, var4);
 }
 
-void LilliputScript::OC_resetWord16EFE() {
-	debugC(1, kDebugScript, "OC_resetWord16EFE()");
+void LilliputScript::OC_resetWaitingSignal() {
+	debugC(1, kDebugScript, "OC_resetWaitingSignal()");
 
 	_vm->_waitingSignal = -1;
 	_vm->_waitingSignalCharacterId = -1;
@@ -2551,8 +2551,8 @@ void LilliputScript::OC_IncCurrentCharacterVar1() {
 	++_vm->_currentCharacterAttributes[1];
 }
 
-void LilliputScript::OC_sub17D23() {
-	debugC(1, kDebugScript, "OC_sub17D23()");
+void LilliputScript::OC_setCurrentCharacterPos() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterPos()");
 
 	uint16 oper = _currScript->readUint16LE();
 	Common::Point var1 = getPosFromScript();
@@ -2561,8 +2561,8 @@ void LilliputScript::OC_sub17D23() {
 	computeOperation(buf + 1, oper, var1.y);
 }
 
-void LilliputScript::OC_sub17E6D() {
-	debugC(1, kDebugScriptTBC, "OC_sub17E6D()");
+void LilliputScript::OC_setCurrentCharacterBehavior() {
+	debugC(1, kDebugScriptTBC, "OC_setCurrentCharacterBehavior()");
 
 	uint16 var1 = _currScript->readUint16LE();
 	_vm->_characterBehaviour[_vm->_currentScriptCharacter] = (var1 - 2000) & 0xFF;
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 213b1d2..35aa734 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -237,13 +237,13 @@ private:
 	void OC_setCurrentCharacter();
 	void OC_sendSeeSignal();
 	void OC_sendHearSignal();
-	void OC_setVarSignal();
-	void OC_sub17CD1();
-	void OC_resetWord16EFE();
+	void OC_sendVarSignal();
+	void OC_sendBroadcastSignal();
+	void OC_resetWaitingSignal();
 	void OC_enableCurrentCharacterScript();
 	void OC_IncCurrentCharacterVar1();
-	void OC_sub17D23();
-	void OC_sub17E6D();
+	void OC_setCurrentCharacterPos();
+	void OC_setCurrentCharacterBehavior();
 	void OC_changeCurrentCharacterSprite();
 	void OC_sub17E99();
 	void OC_sub17EC5();


Commit: 96f35b1740138739189358f4cbbca4690ae55ab4
    https://github.com/scummvm/scummvm/commit/96f35b1740138739189358f4cbbca4690ae55ab4
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: Some more renaming, use CLIP in OC_scrollAwayFromCharacter

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 663bda4..598452f 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -1252,7 +1252,7 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 		int16 frame = _characterFrameArray[index];
 
 		if (frame != -1) {
-			frame += _scriptHandler->_array10AB1[index];
+			frame += _scriptHandler->_characterPose[index];
 			if ((flag & 1) == 1)
 				frame += _spriteSizeArray[index];
 
@@ -1746,7 +1746,7 @@ byte LilliputEngine::sub16729(int index, Common::Point var1) {
 byte LilliputEngine::sub1675D(int index, Common::Point var1) {
 	debugC(2, kDebugEngine, "sub1675D(%d, %d - %d)", index, var1.x, var1.y);
 
-	int charIndex = _scriptHandler->_array10A39[index];
+	int charIndex = _scriptHandler->_characterSeek[index];
 	Common::Point charPos = Common::Point(_scriptHandler->_characterTilePosX[charIndex], _scriptHandler->_characterTilePosY[charIndex]);
 
 	if ((_characterSubTargetPosX[index] != -1) && (_characterSubTargetPosX[index] == _characterTargetPosX[index]) && (_characterSubTargetPosY[index] == _characterTargetPosY[index])) {
@@ -2033,7 +2033,7 @@ void LilliputEngine::sub16685(int idx, Common::Point var1) {
 	debugC(2, kDebugEngine, "sub16685(%d, %d - %d)", idx, var1.x, var1.y);
 
 	int index = (idx * 32) + var1.y;
-	_scriptHandler->_array10AB1[idx] = _rulesBuffer2_16[index];
+	_scriptHandler->_characterPose[idx] = _poseArray[index];
 }
 
 byte LilliputEngine::sub16675_moveCharacter(int idx, Common::Point var1) {
@@ -2535,7 +2535,7 @@ void LilliputEngine::loadRules() {
 			_characterVariables[(j * 32) + k] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
-			_rulesBuffer2_16[(j * 32) + k] = f.readByte();
+			_poseArray[(j * 32) + k] = f.readByte();
 	}
 
 	// Chunk 3 & 4 : Packed strings & associated indexes
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index fd71630..6c30fe8 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -183,7 +183,7 @@ public:
 	byte _rulesBuffer2_14_posY[40];
 	byte _characterVariables[1400 + 3120];
 	byte *_currentCharacterAttributes;
-	byte _rulesBuffer2_16[40 * 32];
+	byte _poseArray[40 * 32];
 	int *_packedStringIndex;
 	int _packedStringNumb;
 	char *_packedStrings;
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index 95b8f4c..b93000d 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -63,7 +63,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL)
 	for (int i = 0; i < 40; i++) {
 		_characterScriptEnabled[i] = 1;
 		_characterMapPixelColor[i] = 15;
-		_array10AB1[i] = 0;
+		_characterPose[i] = 0;
 		_characterNextSequence[i] = 16;
 		_characterLastSequence[i] = -1;
 		_characterTilePosX[i] = 0;
@@ -380,7 +380,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_turnCharacterTowardsAnother();
 		break;
 	case 0x2D:
-		OC_sub17F4F();
+		OC_setSeek();
 		break;
 	case 0x2E:
 		OC_scrollAwayFromCharacter();
@@ -389,10 +389,10 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_skipNextVal();
 		break;
 	case 0x30:
-		OC_setCurrentCharacterVar6();
+		OC_setCurrentCharacterAttr6();
 		break;
 	case 0x31:
-		OC_sub17FDD();
+		OC_setCurrentCharacterPose();
 		break;
 	case 0x32:
 		OC_setCharacterScriptEnabled();
@@ -656,11 +656,11 @@ static const OpCode opCodes2[] = {
 /* 0x2a */	{ "OC_sub17EC5", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x2b */	{ "OC_setCharacterDirectionTowardsPos", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 /* 0x2c */	{ "OC_turnCharacterTowardsAnother", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x2d */	{ "OC_sub17F4F", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x2d */	{ "OC_setSeek", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x2e */	{ "OC_scrollAwayFromCharacter", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x2f */	{ "OC_skipNextVal", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x30 */	{ "OC_setCurrentCharacterVar6", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x31 */	{ "OC_sub17FDD", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x30 */	{ "OC_setCurrentCharacterAttr6", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x31 */	{ "OC_setCurrentCharacterPose", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x32 */	{ "OC_setCharacterScriptEnabled", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x34 */	{ "OC_setCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone },
@@ -2656,12 +2656,12 @@ void LilliputScript::OC_turnCharacterTowardsAnother() {
 	_vm->_characterDirectionArray[_vm->_currentScriptCharacter] = _directionsArray[flag];
 }
 
-void LilliputScript::OC_sub17F4F() {
-	debugC(1, kDebugScript, "OC_sub17F4F()");
+void LilliputScript::OC_setSeek() {
+	debugC(1, kDebugScript, "OC_setSeek()");
 
 	int16 var = getValue1();
-	_array10A39[_vm->_currentScriptCharacter] = (byte)(var & 0xFF);
-	warning("debug - OC_sub17F4F: _array10A39[%d] = %d", _vm->_currentScriptCharacter, var);
+	_characterSeek[_vm->_currentScriptCharacter] = (byte)(var & 0xFF);
+	warning("debug - OC_setSeek: _characterSeek[%d] = %d", _vm->_currentScriptCharacter, var);
 	_vm->_characterSubTargetPosX[_vm->_currentScriptCharacter] = -1;
 }
 
@@ -2682,17 +2682,8 @@ void LilliputScript::OC_scrollAwayFromCharacter() {
 	int newPosX = pos.x + cx;
 	int newPosY = pos.y + cy;
 
-	if (newPosX < 0)
-		newPosX = 0;
-
-	if (newPosX > 56)
-		newPosX = 56;
-
-	if (newPosY < 0)
-		newPosY = 0;
-
-	if (newPosY > 56)
-		newPosY = 56;
+	newPosX = CLIP(newPosX, 0, 56);
+	newPosY = CLIP(newPosY, 0, 56);
 
 	_vm->_refreshScreenFlag = true;
 	_vm->viewportScrollTo(Common::Point(newPosX, newPosY));
@@ -2706,22 +2697,21 @@ void LilliputScript::OC_skipNextVal() {
 	 _currScript->readUint16LE();
 }
 
-void LilliputScript::OC_setCurrentCharacterVar6() {
-	debugC(1, kDebugScript, "OC_setCurrentCharacterVar6()");
+void LilliputScript::OC_setCurrentCharacterAttr6() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterAttr6()");
 
 	uint16 var1 = (uint16)getValue1();
-	warning("debug - OC_setCurrentCharacterVar6 %d", var1);
 	_vm->_currentCharacterAttributes[6] = var1 & 0xFF;
 }
 
-void LilliputScript::OC_sub17FDD() {
-	debugC(1, kDebugScript, "OC_sub17FDD()");
+void LilliputScript::OC_setCurrentCharacterPose() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterPose()");
 
 	int index = _currScript->readUint16LE();
 
 	int tmpVal = (_vm->_currentScriptCharacter * 32) + index;
 	assert (tmpVal < 40 * 32);
-	_array10AB1[_vm->_currentScriptCharacter] = _vm->_rulesBuffer2_16[tmpVal];
+	_characterPose[_vm->_currentScriptCharacter] = _vm->_poseArray[tmpVal];
 	_characterNextSequence[_vm->_currentScriptCharacter] = 16;
 }
 
@@ -2778,7 +2768,7 @@ void LilliputScript::OC_sub18074() {
 	int var2 = _currScript->readUint16LE();
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
 
-	_vm->_rulesBuffer2_16[(_vm->_currentScriptCharacter * 32) + var2] = var1;
+	_vm->_poseArray[(_vm->_currentScriptCharacter * 32) + var2] = var1;
 }
 
 void LilliputScript::OC_setCurrentCharacterDirection() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 35aa734..5ec3ba8 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -74,10 +74,10 @@ public:
 	int8 _characterTilePosX[40];
 	int8 _characterTilePosY[40];
 	int8 _characterNextSequence[40];
-	int8 _array10AB1[40];
+	int8 _characterPose[40];
 	byte _interfaceButtonActivationDelay[20];
 	byte _array122C1[40];
-	byte _array10A39[40];
+	byte _characterSeek[40];
 	int16 _interactions[40 * 40];
 
 	byte *_savedBuffer215Ptr;
@@ -249,11 +249,11 @@ private:
 	void OC_sub17EC5();
 	void OC_setCharacterDirectionTowardsPos();
 	void OC_turnCharacterTowardsAnother();
-	void OC_sub17F4F();
+	void OC_setSeek();
 	void OC_scrollAwayFromCharacter();
 	void OC_skipNextVal();
-	void OC_setCurrentCharacterVar6();
-	void OC_sub17FDD();
+	void OC_setCurrentCharacterAttr6();
+	void OC_setCurrentCharacterPose();
 	void OC_setCharacterScriptEnabled();
 	void OC_setCurrentCharacterVar2();
 	void OC_SetCurrentCharacterVar2ToZero();


Commit: 74ce6af22e6916179f426a180a69cc0031ac8e05
    https://github.com/scummvm/scummvm/commit/74ce6af22e6916179f426a180a69cc0031ac8e05
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-03-28T17:36:57+02:00

Commit Message:
LILLIPUT: more renaming and refactoring

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/lilliput.h
    engines/lilliput/script.cpp
    engines/lilliput/script.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 598452f..a37f02d 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -186,7 +186,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_characterRelativePositionY[i] = -1;
 		_characterDisplayX[i] = 0;
 		_characterDisplayY[i] = 0;
-		_array12299[i] = -1;
+		_characterMagicPuffFrame[i] = -1;
 		_characterSubTargetPosX[i] = -1;
 		_characterSubTargetPosY[i] = -1;
 		_stingArray[i] = 0;
@@ -202,10 +202,10 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd)
 		_spriteSizeArray[i] = 20;
 		_characterDirectionArray[i] = 0;
 		_rulesBuffer2_10[i] = 0;
-		_rulesBuffer2_11[i] = 0;
+		_characterTypes[i] = 0;
 		_characterBehaviour[i] = 0;
-		_rulesBuffer2_13_posX[i] = 0;
-		_rulesBuffer2_14_posY[i] = 0;
+		_characterHomePosX[i] = 0;
+		_characterHomePosY[i] = 0;
 		_array1289F[i] = -1;
 	}
 
@@ -281,8 +281,8 @@ void LilliputEngine::newInt8() {
 			--_byte12A05;
 		else {
 			_byte12A05 = 10;
-			if (_sound_byte16F06 != 0)
-				--_sound_byte16F06;
+			if (_int8Timer != 0)
+				--_int8Timer;
 
 			_animationTick ^= 1;
 			if (!_refreshScreenFlag)
@@ -605,7 +605,7 @@ void LilliputEngine::displayCharactersOnMap() {
 
 	byte *buf = (byte *)_mainSurface->getPixels();
 	for (int index = _numCharacters - 1; index >= 0; index--) {
-		if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_characterTilePosY[index] != -1)) {
+		if (((_characterTypes[index] & 2) == 0) && (_scriptHandler->_characterTilePosY[index] != -1)) {
 			// FIXME: This is still wrong, but less. The values in both arrays should be verified now!
 			int pixIndex = 320 + ((15 * _scriptHandler->_characterTilePosY[index]) / 4) + (_scriptHandler->_characterTilePosX[index] * 4) + 1;
 
@@ -953,7 +953,7 @@ void LilliputEngine::sub16CA0() {
 	debugC(2, kDebugEngine, "sub16CA0()");
 
 	for (int index = _numCharacters - 1; index >= 0; index--) {
-		if (_rulesBuffer2_11[index] & 1)
+		if (_characterTypes[index] & 1)
 			continue;
 
 		int c1 = _scriptHandler->_characterTilePosX[index];
@@ -968,7 +968,7 @@ void LilliputEngine::sub16CA0() {
 			if ((index != index2) &&
 				(_characterCarried[index] != index2) &&
 				(_characterCarried[index2] != index) &&
-				(_rulesBuffer2_11[index2] & 2) == 0) {
+				(_characterTypes[index2] & 2) == 0) {
 				int d1 = _scriptHandler->_characterTilePosX[index2];
 				int d2 = _scriptHandler->_characterTilePosY[index2];
 
@@ -981,7 +981,7 @@ void LilliputEngine::sub16CA0() {
 
 							if ((c1 == d1) && (c2 == d2)) {
 								byte16C9F = 4;
-							} else if ((_rulesBuffer2_11[index] & 4) != 0) {
+							} else if ((_characterTypes[index] & 4) != 0) {
 								byte16C9F = 0;
 							} else {
 								switch (_characterDirectionArray[index]) {
@@ -1256,9 +1256,9 @@ void LilliputEngine::renderCharacters(byte *buf, Common::Point pos) {
 			if ((flag & 1) == 1)
 				frame += _spriteSizeArray[index];
 
-			if (_array12299[index] != -1) {
-				frame = _array12299[index] + 82;
-				--_array12299[index];
+			if (_characterMagicPuffFrame[index] != -1) {
+				frame = _characterMagicPuffFrame[index] + 82;
+				--_characterMagicPuffFrame[index];
 				frame = -frame;
 			}
 
@@ -2526,10 +2526,10 @@ void LilliputEngine::loadRules() {
 		_spriteSizeArray[j] = f.readByte();
 		_characterDirectionArray[j] = f.readByte();
 		_rulesBuffer2_10[j] = f.readByte();
-		_rulesBuffer2_11[j] = f.readByte();
+		_characterTypes[j] = f.readByte();
 		_characterBehaviour[j] = f.readByte();
-		_rulesBuffer2_13_posX[j] = f.readByte();
-		_rulesBuffer2_14_posY[j] = f.readByte();
+		_characterHomePosX[j] = f.readByte();
+		_characterHomePosY[j] = f.readByte();
 
 		for (int k = 0; k < 32; k++)
 			_characterVariables[(j * 32) + k] = f.readByte();
diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h
index 6c30fe8..17a2da1 100644
--- a/engines/lilliput/lilliput.h
+++ b/engines/lilliput/lilliput.h
@@ -106,11 +106,11 @@ public:
 	int _smallAnimsFrameIndex;
 
 	byte _handleOpcodeReturnCode;
-	byte _byte184F4;
+	byte _keyDelay;
 	byte _lastAnimationTick;
 	byte _animationTick;
 	Common::Point _nextDisplayCharacterPos;
-	byte _sound_byte16F06;
+	byte _int8Timer;
 	Common::Event _lastKeyPressed;
 	Common::EventType _lastEventType;
 	byte _keyboard_nextIndex;
@@ -177,10 +177,10 @@ public:
 	byte _spriteSizeArray[40];
 	byte _characterDirectionArray[40];
 	byte _rulesBuffer2_10[40];
-	byte _rulesBuffer2_11[40];
+	byte _characterTypes[40];
 	byte _characterBehaviour[40];
-	byte _rulesBuffer2_13_posX[40];
-	byte _rulesBuffer2_14_posY[40];
+	byte _characterHomePosX[40];
+	byte _characterHomePosY[40];
 	byte _characterVariables[1400 + 3120];
 	byte *_currentCharacterAttributes;
 	byte _poseArray[40 * 32];
@@ -216,7 +216,7 @@ public:
 	int16 _characterRelativePositionY[40];
 	int16 _characterDisplayX[40];
 	int16 _characterDisplayY[40];
-	int8 _array12299[40];
+	int8 _characterMagicPuffFrame[40];
 	int16 _characterSubTargetPosX[40];
 	int16 _characterSubTargetPosY[40];
 	byte _stingArray[40];
diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp
index b93000d..03d5f3f 100644
--- a/engines/lilliput/script.cpp
+++ b/engines/lilliput/script.cpp
@@ -30,7 +30,7 @@
 namespace Lilliput {
 
 LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) {
-	_byte10806 = 0;
+	_cubeSet = 0;
 	_lastRandomValue = 0;
 	_scriptForVal = 0;
 	_byte1881A = 0;
@@ -398,10 +398,10 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setCharacterScriptEnabled();
 		break;
 	case 0x33:
-		OC_setCurrentCharacterVar2();
+		OC_setCurrentCharacterAttr2();
 		break;
 	case 0x34:
-		OC_SetCurrentCharacterVar2ToZero();
+		OC_clearCurrentCharacterAttr2();
 		break;
 	case 0x35:
 		OC_setCharacterProperties();
@@ -410,7 +410,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1805D();
 		break;
 	case 0x37:
-		OC_sub18074();
+		OC_setNewPose();
 		break;
 	case 0x38:
 		OC_setCurrentCharacterDirection();
@@ -437,7 +437,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub18213();
 		break;
 	case 0x40:
-		OC_sub18252();
+		OC_magicPuffEntrance();
 		break;
 	case 0x41:
 		OC_sub18260();
@@ -452,10 +452,10 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_PaletteFadeIn();
 		break;
 	case 0x45:
-		OC_loadAndDisplayCUBESx_GFX();
+		OC_loadAndDisplayCubesGfx();
 		break;
 	case 0x46:
-		OC_setCurrentCharacterVar3();
+		OC_setCurrentCharacterAttr3();
 		break;
 	case 0x47:
 		OC_setArray122C1();
@@ -515,13 +515,13 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_setCharacterHeroismBar();
 		break;
 	case 0x5A:
-		OC_sub18690();
+		OC_setCharacterHome();
 		break;
 	case 0x5B:
 		OC_setViewPortCharacterTarget();
 		break;
 	case 0x5C:
-		OC_sub186A1();
+		OC_showObject();
 		break;
 	case 0x5D:
 		OC_sub186E5_snd();
@@ -530,7 +530,7 @@ void LilliputScript::handleOpcodeType2(int curWord) {
 		OC_sub1870A_snd();
 		break;
 	case 0x5F:
-		OC_sub18725_snd();
+		OC_stopSound();
 		break;
 	case 0x60:
 		OC_sub18733_snd();
@@ -662,11 +662,11 @@ static const OpCode opCodes2[] = {
 /* 0x30 */	{ "OC_setCurrentCharacterAttr6", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x31 */	{ "OC_setCurrentCharacterPose", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x32 */	{ "OC_setCharacterScriptEnabled", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x33 */	{ "OC_setCurrentCharacterVar2", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x34 */	{ "OC_setCurrentCharacterVar2ToZero", 0, kNone, kNone, kNone, kNone, kNone },
+/* 0x33 */	{ "OC_setCurrentCharacterAttr2", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x34 */	{ "OC_ClearCurrentCharacterAttr2", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x35 */	{ "OC_setCharacterProperties", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
 /* 0x36 */	{ "OC_sub1805D", 5, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
-/* 0x37 */	{ "OC_sub18074", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
+/* 0x37 */	{ "OC_setNewPose", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x38 */	{ "OC_setCurrentCharacterDirection", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x39 */	{ "OC_setInterfaceHotspot", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x3a */	{ "OC_scrollViewPort", 1, kImmediateValue, kNone, kNone, kNone, kNone },
@@ -675,13 +675,13 @@ static const OpCode opCodes2[] = {
 /* 0x3d */	{ "OC_sub1817F", 2, kImmediateValue, kImmediateValue, kNone, kNone, kNone },
 /* 0x3e */	{ "OC_sub181BB", 4, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x3f */	{ "OC_sub18213", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x40 */	{ "OC_sub18252", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x40 */	{ "OC_magicPuffEntrance", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x41 */	{ "OC_sub18260", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone }, // TODO
 /* 0x42 */	{ "OC_characterVariableAddOrRemoveFlag", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
 /* 0x43 */	{ "OC_paletteFadeOut", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x44 */	{ "OC_paletteFadeIn", 0, kNone, kNone, kNone, kNone, kNone },
-/* 0x45 */	{ "OC_loadAndDisplayCUBESx_GFX", 1, kImmediateValue, kNone, kNone, kNone, kNone },
-/* 0x46 */	{ "OC_setCurrentCharacterVar3", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x45 */	{ "OC_loadAndDisplayCubesGfx", 1, kImmediateValue, kNone, kNone, kNone, kNone },
+/* 0x46 */	{ "OC_setCurrentCharacterAttr3", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x47 */	{ "OC_setArray122C1", 1, kImmediateValue, kNone, kNone, kNone, kNone },
 /* 0x48 */	{ "OC_sub18367", 0, kNone, kNone, kNone, kNone, kNone },
 /* 0x49 */	{ "OC_enableCharacterScript", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
@@ -701,12 +701,12 @@ static const OpCode opCodes2[] = {
 /* 0x57 */	{ "OC_displayCharacterStatBar", 6, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue},
 /* 0x58 */	{ "OC_initSmallAnim", 11, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue, kImmediateValue },
 /* 0x59 */	{ "OC_setCharacterHeroismBar", 4, kGetValue1, kImmediateValue, kImmediateValue, kImmediateValue, kNone },
-/* 0x5a */	{ "OC_sub18690", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },  //TODO
+/* 0x5a */	{ "OC_setCharacterHome", 2, kGetValue1, kgetPosFromScript, kNone, kNone, kNone },  //TODO
 /* 0x5b */	{ "OC_setViewPortCharacterTarget", 1, kGetValue1, kNone, kNone, kNone, kNone },
-/* 0x5c */	{ "OC_sub186A1", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },  //TODO
+/* 0x5c */	{ "OC_showObject", 3, kGetValue1, kImmediateValue, kImmediateValue, kNone, kNone },  //TODO
 /* 0x5d */	{ "OC_sub186E5_snd", 2, kGetValue1, kImmediateValue, kNone, kNone, kNone },
 /* 0x5e */	{ "OC_sub1870A_snd", 2, kgetPosFromScript, kImmediateValue, kNone, kNone, kNone },
-/* 0x5f */	{ "OC_sub18725_snd", 1, kGetValue1, kNone, kNone, kNone, kNone },
+/* 0x5f */	{ "OC_stopSound", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x60 */	{ "OC_sub18733_snd", 1, kGetValue1, kNone, kNone, kNone, kNone },
 /* 0x61 */	{ "OC_sub1873F_snd", 1, kgetPosFromScript, kNone, kNone, kNone, kNone },
 /* 0x62 */	{ "OC_sub18746_snd", 1, kImmediateValue, kNone, kNone, kNone, kNone },
@@ -1298,11 +1298,11 @@ Common::Point LilliputScript::getPosFromScript() {
 	switch(tmpVal) {
 	case 0xFF:
 		assert((_vm->_currentScriptCharacter >= 0) && (_vm->_currentScriptCharacter < 40));
-		return Common::Point(_vm->_rulesBuffer2_13_posX[_vm->_currentScriptCharacter], _vm->_rulesBuffer2_14_posY[_vm->_currentScriptCharacter]);
+		return Common::Point(_vm->_characterHomePosX[_vm->_currentScriptCharacter], _vm->_characterHomePosY[_vm->_currentScriptCharacter]);
 	case 0xFE: {
 		int8 index = curWord & 0xFF;
 		assert((index >= 0) && (index < 40));
-		return Common::Point(_vm->_rulesBuffer2_13_posX[index], _vm->_rulesBuffer2_14_posY[index]);
+		return Common::Point(_vm->_characterHomePosX[index], _vm->_characterHomePosY[index]);
 		}
 	case 0xFD:
 		return _vm->_currentScriptCharacterPos;
@@ -2722,16 +2722,16 @@ void LilliputScript::OC_setCharacterScriptEnabled() {
 	_characterScriptEnabled[index] = 1;
 }
 
-void LilliputScript::OC_setCurrentCharacterVar2() {
-	debugC(1, kDebugScript, "OC_setCurrentCharacterVar2()");
+void LilliputScript::OC_setCurrentCharacterAttr2() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterAttr2()");
 
 	int curWord = _currScript->readUint16LE();
 	assert(_vm->_currentCharacterAttributes != NULL);
 	_vm->_currentCharacterAttributes[2] = curWord & 0xFF;
 }
 
-void LilliputScript::OC_SetCurrentCharacterVar2ToZero() {
-	debugC(1, kDebugScript, "OC_SetCurrentCharacterVar2ToZero()");
+void LilliputScript::OC_clearCurrentCharacterAttr2() {
+	debugC(1, kDebugScript, "OC_clearCurrentCharacterAttr2()");
 
 	assert(_vm->_currentCharacterAttributes != NULL);
 	_vm->_currentCharacterAttributes[2] = 0;
@@ -2762,8 +2762,8 @@ void LilliputScript::OC_sub1805D() {
 		_array129A5[i] = _currScript->readUint16LE() & 0xFF;
 }
 
-void LilliputScript::OC_sub18074() {
-	debugC(1, kDebugScriptTBC, "OC_sub18074()");
+void LilliputScript::OC_setNewPose() {
+	debugC(1, kDebugScriptTBC, "OC_setNewPose()");
 
 	int var2 = _currScript->readUint16LE();
 	byte var1 = (_currScript->readUint16LE() & 0xFF);
@@ -2910,13 +2910,13 @@ void LilliputScript::OC_sub18213() {
 	enableCharacterScript(_vm->_currentScriptCharacter, maxItem, _vm->_currentCharacterAttributes);
 }
 
-void LilliputScript::OC_sub18252() {
-	debugC(1, kDebugScript, "OC_sub18252()");
+void LilliputScript::OC_magicPuffEntrance() {
+	debugC(1, kDebugScript, "OC_magicPuffEntrance()");
 
 	int16 index = getValue1();
 	assert((index >0) && (index < 40));
 
-	_vm->_array12299[index] = 4;
+	_vm->_characterMagicPuffFrame[index] = 4;
 }
 
 void LilliputScript::OC_sub18260() {
@@ -2982,21 +2982,21 @@ void LilliputScript::OC_PaletteFadeIn() {
 	_vm->_refreshScreenFlag = false;
 }
 
-void LilliputScript::OC_loadAndDisplayCUBESx_GFX() {
-	debugC(1, kDebugScript, "OC_loadAndDisplayCUBESx_GFX()");
+void LilliputScript::OC_loadAndDisplayCubesGfx() {
+	debugC(1, kDebugScript, "OC_loadAndDisplayCubesGfx()");
 
-	int curWord = (_currScript->readUint16LE() & 0xFF);
-	assert((curWord >= 0) && (curWord <= 9));
-	Common::String fileName = Common::String::format("CUBES%d.GFX", curWord);
-	_byte10806 = curWord + 0x30; // Useless?
+	int setNumb = (_currScript->readUint16LE() & 0xFF);
+	assert((setNumb >= 0) && (setNumb <= 9));
+	Common::String fileName = Common::String::format("CUBES%d.GFX", setNumb);
+	_cubeSet = setNumb; // Useless in this variant, keep for the moment for Rome
 
 	_vm->_bufferCubegfx = _vm->loadVGA(fileName, 61440, false);
 	_vm->displayLandscape();
 	_vm->prepareGameArea();
 }
 
-void LilliputScript::OC_setCurrentCharacterVar3() {
-	debugC(1, kDebugScript, "OC_setCurrentCharacterVar3()");
+void LilliputScript::OC_setCurrentCharacterAttr3() {
+	debugC(1, kDebugScript, "OC_setCurrentCharacterAttr3()");
 
 	byte var1 = _currScript->readUint16LE() & 0xFF;
 	assert(_vm->_currentCharacterAttributes != NULL);
@@ -3116,31 +3116,30 @@ void LilliputScript::OC_startSpeechIfSoundOff() {
 void LilliputScript::OC_sub1844A() {
 	debugC(1, kDebugScriptTBC, "OC_sub1844A()");
 
-	int var1 = getValue1();
+	int characterIndex = getValue1();
 	int var2 = _currScript->readUint16LE();
 
-	_vm->_rulesBuffer2_11[var1] = (var2 & 0xFF);
+	_vm->_characterTypes[characterIndex] = (var2 & 0xFF);
 
 	for (int i = 0; i < 40; i++) {
-		_interactions[40 * var1 + i] = 0;
-		_interactions[var1 + 40 * i] = 0;
+		_interactions[40 * characterIndex + i] = 0;
+		_interactions[characterIndex + 40 * i] = 0;
 	}
 }
 
 void LilliputScript::OC_displayNumericCharacterVariable() {
 	debugC(1, kDebugScript, "OC_displayNumericCharacterVariable()");
 
-	byte *buf215Ptr = getCharacterAttributesPtr();
-	byte tmpVal = buf215Ptr[0];
-	int curWord = _currScript->readUint16LE();
-	assert(curWord != 0);
-	int displayVal = tmpVal / (curWord & 0xFF);
+	byte *charAttrArr = getCharacterAttributesPtr();
+	byte attr = charAttrArr[0];
+	int divisor = _currScript->readUint16LE();
+	assert(divisor != 0);
+	int displayVal = attr / (divisor & 0xFF);
 	int posX = _currScript->readSint16LE();
 	int posY = _currScript->readSint16LE();
 
-	if (!_vm->_displayMap) {
+	if (!_vm->_displayMap)
 		displayNumber(displayVal, Common::Point(posX, posY));
-	}
 }
 
 void LilliputScript::displayNumber(byte var1, Common::Point pos) {
@@ -3179,8 +3178,8 @@ void LilliputScript::OC_startSpeechWithoutSpeeker() {
 void LilliputScript::OC_displayTitleScreen() {
 	debugC(1, kDebugScript, "OC_displayTitleScreen()");
 
-	_vm->_byte184F4 = (_currScript->readUint16LE() & 0xFF);
-	_vm->_sound_byte16F06 = _vm->_byte184F4;
+	_vm->_keyDelay = (_currScript->readUint16LE() & 0xFF);
+	_vm->_int8Timer = _vm->_keyDelay;
 
 	_vm->_keyboard_resetKeyboardBuffer();
 
@@ -3202,7 +3201,7 @@ void LilliputScript::OC_displayTitleScreen() {
 		if (_vm->_mouseButton == 1)
 			break;
 
-		if ((_vm->_byte184F4 != 0) && (_vm->_sound_byte16F06 == 0))
+		if ((_vm->_keyDelay != 0) && (_vm->_int8Timer == 0))
 			break;
 
 		_vm->_system->delayMillis(1);
@@ -3260,13 +3259,13 @@ void LilliputScript::OC_setCharacterHeroismBar() {
 	_heroismBarBottomY = _currScript->readUint16LE();
 }
 
-void LilliputScript::OC_sub18690() {
-	debugC(1, kDebugScriptTBC, "OC_sub18690()");
+void LilliputScript::OC_setCharacterHome() {
+	debugC(1, kDebugScriptTBC, "OC_setCharacterHome()");
 
 	int index = getValue1();
 	Common::Point pos = getPosFromScript();
-	_vm->_rulesBuffer2_13_posX[index] = pos.x;
-	_vm->_rulesBuffer2_14_posY[index] = pos.y;
+	_vm->_characterHomePosX[index] = pos.x;
+	_vm->_characterHomePosY[index] = pos.y;
 }
 
 void LilliputScript::OC_setViewPortCharacterTarget() {
@@ -3275,8 +3274,8 @@ void LilliputScript::OC_setViewPortCharacterTarget() {
 	_viewportCharacterTarget = getValue1();
 }
 
-void LilliputScript::OC_sub186A1() {
-	debugC(1, kDebugScriptTBC, "OC_sub186A1()");
+void LilliputScript::OC_showObject() {
+	debugC(1, kDebugScriptTBC, "OC_showObject()");
 
 	int var1 = getValue1();
 	int posX = _currScript->readUint16LE();
@@ -3288,9 +3287,9 @@ void LilliputScript::OC_sub186A1() {
 	int frame = _vm->_characterFrameArray[var1];
 	byte* buf = _vm->_bufferMen;
 
-	if (frame > 0xF0) {
+	if (frame > 240) {
 		buf = _vm->_bufferMen2;
-		frame -= 0xF0;
+		frame -= 240;
 	}
 
 	_vm->display16x16IndexedBuf(buf, frame, pos);
@@ -3302,9 +3301,9 @@ void LilliputScript::OC_sub186E5_snd() {
 	assert(index < 40);
 
 	Common::Point var4 = Common::Point(0xFF, index & 0xFF);
-	int var1 = (_currScript->readUint16LE() & 0xFF);
+	int soundId = (_currScript->readUint16LE() & 0xFF);
 
-	_vm->_soundHandler->contentFct2(var1, _viewportPos, Common::Point(_characterTilePosX[index], _characterTilePosY[index]), var4);
+	_vm->_soundHandler->contentFct2(soundId, _viewportPos, Common::Point(_characterTilePosX[index], _characterTilePosY[index]), var4);
 }
 
 void LilliputScript::OC_sub1870A_snd() {
@@ -3318,12 +3317,12 @@ void LilliputScript::OC_sub1870A_snd() {
 	_vm->_soundHandler->contentFct2(var1, var2, var3, var4);
 }
 
-void LilliputScript::OC_sub18725_snd() {
-	debugC(1, kDebugScript, "OC_sub18725_snd()");
+void LilliputScript::OC_stopSound() {
+	debugC(1, kDebugScript, "OC_stopSound()");
 
-	Common::Point var4 = Common::Point(-1, getValue1() & 0xFF);
+	Common::Point var4 = Common::Point(-1, getValue1() & 0xFF); // should be split in 2 parameters
 
-	_vm->_soundHandler->contentFct3(var4);
+	_vm->_soundHandler->contentFct3(var4); // Stop Sound
 }
 
 void LilliputScript::OC_sub18733_snd() {
diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h
index 5ec3ba8..e9810cc 100644
--- a/engines/lilliput/script.h
+++ b/engines/lilliput/script.h
@@ -108,7 +108,7 @@ private:
 	Common::Stack<ScriptStream *> _scriptStack;
 
 	byte _byte16F05_ScriptHandler;
-	byte _byte10806;
+	byte _cubeSet;
 	byte _lastRandomValue;
 	byte _scriptForVal;
 	byte _byte1881A;
@@ -255,11 +255,11 @@ private:
 	void OC_setCurrentCharacterAttr6();
 	void OC_setCurrentCharacterPose();
 	void OC_setCharacterScriptEnabled();
-	void OC_setCurrentCharacterVar2();
-	void OC_SetCurrentCharacterVar2ToZero();
+	void OC_setCurrentCharacterAttr2();
+	void OC_clearCurrentCharacterAttr2();
 	void OC_setCharacterProperties();
 	void OC_sub1805D();
-	void OC_sub18074();
+	void OC_setNewPose();
 	void OC_setCurrentCharacterDirection();
 	void OC_setInterfaceHotspot();
 	void OC_scrollViewPort();
@@ -269,13 +269,13 @@ private:
 	void sub1818B(Common::Point point);
 	void OC_sub181BB();
 	void OC_sub18213();
-	void OC_sub18252();
+	void OC_magicPuffEntrance();
 	void OC_sub18260();
 	void OC_CharacterVariableAddOrRemoveFlag();
 	void OC_PaletteFadeOut();
 	void OC_PaletteFadeIn();
-	void OC_loadAndDisplayCUBESx_GFX();
-	void OC_setCurrentCharacterVar3();
+	void OC_loadAndDisplayCubesGfx();
+	void OC_setCurrentCharacterAttr3();
 	void OC_setArray122C1();
 	void OC_sub18367();
 	void OC_enableCharacterScript();
@@ -295,12 +295,12 @@ private:
 	void OC_displayCharacterStatBar();
 	void OC_initSmallAnim();
 	void OC_setCharacterHeroismBar();
-	void OC_sub18690();
+	void OC_setCharacterHome();
 	void OC_setViewPortCharacterTarget();
-	void OC_sub186A1();
+	void OC_showObject();
 	void OC_sub186E5_snd();
 	void OC_sub1870A_snd();
-	void OC_sub18725_snd();
+	void OC_stopSound();
 	void OC_sub18733_snd();
 	void OC_sub1873F_snd();
 	void OC_sub18746_snd();





More information about the Scummvm-git-logs mailing list