aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/kyra/gui_v2.cpp17
-rw-r--r--engines/kyra/kyra_v2.cpp24
-rw-r--r--engines/kyra/kyra_v2.h10
-rw-r--r--engines/kyra/script_v2.cpp95
4 files changed, 141 insertions, 5 deletions
diff --git a/engines/kyra/gui_v2.cpp b/engines/kyra/gui_v2.cpp
index 476f819cd7..6c6ebf73a4 100644
--- a/engines/kyra/gui_v2.cpp
+++ b/engines/kyra/gui_v2.cpp
@@ -642,6 +642,23 @@ int KyraEngine_v2::scrollInventory(Button *button) {
return 0;
}
+int KyraEngine_v2::getInventoryItemSlot(uint16 item) {
+ for (int i = 0; i < 20; ++i) {
+ if (_mainCharacter.inventory[i] == item)
+ return i;
+ }
+ return -1;
+}
+
+void KyraEngine_v2::removeItemFromInventory(int slot) {
+ _mainCharacter.inventory[slot] = 0xFFFF;
+ if (slot < 10) {
+ _screen->hideMouse();
+ clearInventorySlot(slot, 0);
+ _screen->showMouse();
+ }
+}
+
bool KyraEngine_v2::checkInventoryItemExchange(uint16 handItem, int slot) {
bool removeItem = false;
uint16 newItem = 0xFFFF;
diff --git a/engines/kyra/kyra_v2.cpp b/engines/kyra/kyra_v2.cpp
index b0082e8db1..d0af3210a8 100644
--- a/engines/kyra/kyra_v2.cpp
+++ b/engines/kyra/kyra_v2.cpp
@@ -1210,6 +1210,20 @@ void KyraEngine_v2::restorePage3() {
_screen->copyBlockToPage(2, 0, 0, 320, 144, _gamePlayBuffer);
}
+void KyraEngine_v2::backUpPage0() {
+ if (_screenBuffer) {
+ _screen->hideMouse();
+ memcpy(_screenBuffer, _screen->getCPagePtr(0), 64000);
+ _screen->showMouse();
+ }
+}
+
+void KyraEngine_v2::restorePage0() {
+ restorePage3();
+ if (_screenBuffer)
+ _screen->copyBlockToPage(0, 0, 0, 320, 200, _screenBuffer);
+}
+
void KyraEngine_v2::updateCharPal(int unk1) {
static bool unkVar1 = false;
@@ -2112,7 +2126,7 @@ void KyraEngine_v2::setupOpcodeTable() {
OpcodeUnImpl(),
Opcode(o2_defineItem),
// 0x24
- OpcodeUnImpl(),
+ Opcode(o2_removeItemFromInventory),
Opcode(o2_countItemInInventory),
OpcodeUnImpl(),
Opcode(o2_queryGameFlag),
@@ -2147,8 +2161,8 @@ void KyraEngine_v2::setupOpcodeTable() {
Opcode(o2_drawSceneShape),
Opcode(o2_drawSceneShapeOnPage),
// 0x40
- OpcodeUnImpl(),
- OpcodeUnImpl(),
+ Opcode(o2_disableAnimObject),
+ Opcode(o2_enableAnimObject),
Opcode(o2_dummy),
OpcodeUnImpl(),
// 0x44
@@ -2193,7 +2207,7 @@ void KyraEngine_v2::setupOpcodeTable() {
OpcodeUnImpl(),
// 0x64
OpcodeUnImpl(),
- OpcodeUnImpl(),
+ Opcode(o2_showLetter),
OpcodeUnImpl(),
Opcode(o2_fillRect),
// 0x68
@@ -2210,7 +2224,7 @@ void KyraEngine_v2::setupOpcodeTable() {
Opcode(o2_defineSceneAnim),
Opcode(o2_updateSceneAnim),
Opcode(o2_updateSceneAnim),
- OpcodeUnImpl(),
+ Opcode(o2_setSceneAnimPosAndUpdate),
// 0x74
Opcode(o2_useItemOnMainChar),
Opcode(o2_startDialogue),
diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h
index 4f2f696305..d3f503bc2b 100644
--- a/engines/kyra/kyra_v2.h
+++ b/engines/kyra/kyra_v2.h
@@ -327,6 +327,9 @@ protected:
void restorePage3();
uint8 *_screenBuffer;
+ void backUpPage0();
+ void restorePage0();
+
uint8 *_maskPage;
uint8 *_gfxBackUpRect;
@@ -567,6 +570,8 @@ protected:
static const int _inventoryY[];
static const uint16 _itemMagicTable[];
+ int getInventoryItemSlot(uint16 item);
+ void removeItemFromInventory(int slot);
bool checkInventoryItemExchange(uint16 item, int slot);
void drawInventoryShape(int page, uint16 item, int slot);
void clearInventorySlot(int slot, int page);
@@ -946,6 +951,7 @@ protected:
int o2_wsaOpen(ScriptState *script);
int o2_checkForItem(ScriptState *script);
int o2_defineItem(ScriptState *script);
+ int o2_removeItemFromInventory(ScriptState *script);
int o2_countItemInInventory(ScriptState *script);
int o2_queryGameFlag(ScriptState *script);
int o2_resetGameFlag(ScriptState *script);
@@ -965,6 +971,8 @@ protected:
int o2_setCharPalEntry(ScriptState *script);
int o2_drawSceneShape(ScriptState *script);
int o2_drawSceneShapeOnPage(ScriptState *script);
+ int o2_disableAnimObject(ScriptState *script);
+ int o2_enableAnimObject(ScriptState *script);
int o2_restoreBackBuffer(ScriptState *script);
int o2_update(ScriptState *script);
int o2_fadeScenePal(ScriptState *script);
@@ -977,6 +985,7 @@ protected:
int o2_playWanderScoreViaMap(ScriptState *script);
int o2_playSoundEffect(ScriptState *script);
int o2_getRand(ScriptState *script);
+ int o2_showLetter(ScriptState *script);
int o2_fillRect(ScriptState *script);
int o2_encodeShape(ScriptState *script);
int o2_defineRoomEntrance(ScriptState *script);
@@ -984,6 +993,7 @@ protected:
int o2_setSpecialSceneScriptRunTime(ScriptState *script);
int o2_defineSceneAnim(ScriptState *script);
int o2_updateSceneAnim(ScriptState *script);
+ int o2_setSceneAnimPosAndUpdate(ScriptState *script);
int o2_useItemOnMainChar(ScriptState *script);
int o2_startDialogue(ScriptState *script);
int o2_zanthRandomChat(ScriptState *script);
diff --git a/engines/kyra/script_v2.cpp b/engines/kyra/script_v2.cpp
index 1f1275547a..1e2d1a76d0 100644
--- a/engines/kyra/script_v2.cpp
+++ b/engines/kyra/script_v2.cpp
@@ -273,6 +273,15 @@ int KyraEngine_v2::o2_defineItem(ScriptState *script) {
return freeItem;
}
+int KyraEngine_v2::o2_removeItemFromInventory(ScriptState *script) {
+ debugC(3, kDebugLevelScriptFuncs, "o2_removeItemFromInventory(%p) (%d)", (const void *)script, stackPos(0));
+ uint16 item = stackPos(0);
+ int slot = -1;
+ while ((slot = getInventoryItemSlot(stackPos(0))) != -1)
+ removeItemFromInventory(slot);
+ return 0;
+}
+
int KyraEngine_v2::o2_countItemInInventory(ScriptState *script) {
debugC(3, kDebugLevelScriptFuncs, "o2_countItemInInventory(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1));
uint16 item = stackPos(1);
@@ -424,6 +433,18 @@ int KyraEngine_v2::o2_drawSceneShapeOnPage(ScriptState *script) {
return 0;
}
+int KyraEngine_v2::o2_disableAnimObject(ScriptState *script) {
+ debugC(3, kDebugLevelScriptFuncs, "o2_disableAnimObject(%p) (%d)", (const void *)script, stackPos(0));
+ _animObjects[stackPos(0)+1].enabled = false;
+ return 0;
+}
+
+int KyraEngine_v2::o2_enableAnimObject(ScriptState *script) {
+ debugC(3, kDebugLevelScriptFuncs, "o2_enableAnimObject(%p) (%d)", (const void *)script, stackPos(0));
+ _animObjects[stackPos(0)+1].enabled = true;
+ return 0;
+}
+
int KyraEngine_v2::o2_restoreBackBuffer(ScriptState *script) {
debugC(3, kDebugLevelScriptFuncs, "o2_restoreBackBuffer(%p) (%d)", (const void *)script, stackPos(0));
int disable = stackPos(0);
@@ -543,6 +564,66 @@ int KyraEngine_v2::o2_getRand(ScriptState *script) {
return _rnd.getRandomNumberRng(stackPos(0), stackPos(1));
}
+int KyraEngine_v2::o2_showLetter(ScriptState *script) {
+ debugC(3, kDebugLevelScriptFuncs, "o2_showLetter(%p) (%d)", (const void *)script, stackPos(0));
+ const int letter = stackPos(0);
+ char filename[16];
+
+ _screen->hideMouse();
+
+ showMessage(0, 0xCF);
+ displayInvWsaLastFrame();
+ backUpPage0();
+
+ memcpy(_screen->getPalette(2), _screen->getPalette(0), 768);
+
+ _screen->clearPage(3);
+ _screen->loadBitmap("_NOTE.CPS", 3, 3, 0);
+
+ sprintf(filename, "_NTEPAL%.1d.COL", letter+1);
+ _res->loadFileToBuf(filename, _screen->getPalette(0), 768);
+
+ _screen->fadeToBlack(0x14);
+
+ sprintf(filename, "LETTER%.1d.", letter);
+ strcat(filename, _languageExtension[_lang]);
+
+ uint8 *letterBuffer = _res->fileData(filename, 0);
+ if (letterBuffer) {
+ bookDecodeText(letterBuffer);
+ bookPrintText(2, letterBuffer, 0xC, 0xA, 0x20);
+ }
+
+ _screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 0);
+ _screen->fadePalette(_screen->getPalette(0), 0x14);
+ _screen->setMouseCursor(0, 0, getShapePtr(0));
+ _system->warpMouse(280, 160);
+
+ _screen->showMouse();
+
+ bool running = true;
+ while (running) {
+ int inputFlag = checkInput(0);
+ removeInputTop();
+
+ if (inputFlag == 198 || inputFlag == 199)
+ running = false;
+
+ _screen->updateScreen();
+ _system->delayMillis(10);
+ }
+
+ _screen->hideMouse();
+ _screen->fadeToBlack(0x14);
+ restorePage0();
+ memcpy(_screen->getPalette(0), _screen->getPalette(2), 768);
+ _screen->fadePalette(_screen->getPalette(0), 0x14);
+ setHandItem(_itemInHand);
+ _screen->showMouse();
+
+ return 0;
+}
+
int KyraEngine_v2::o2_fillRect(ScriptState *script) {
debugC(3, kDebugLevelScriptFuncs, "o2_fillRect(%p) (%d, %d, %d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3), stackPos(4), stackPos(5));
_screen->fillRect(stackPos(1), stackPos(2), stackPos(1)+stackPos(3), stackPos(2)+stackPos(4), stackPos(5), stackPos(0));
@@ -640,6 +721,20 @@ int KyraEngine_v2::o2_updateSceneAnim(ScriptState *script) {
return 0;
}
+int KyraEngine_v2::o2_setSceneAnimPosAndUpdate(ScriptState *script) {
+ debugC(3, kDebugLevelScriptFuncs, "o2_updateSceneAnim(%p) (%d, %d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2), stackPos(3));
+ const int anim = stackPos(0);
+ _sceneAnims[anim].x2 = stackPos(1);
+ _sceneAnims[anim].y2 = stackPos(2);
+ if (_sceneAnims[anim].flags & 2) {
+ _sceneAnims[anim].x = stackPos(1);
+ _sceneAnims[anim].y = stackPos(2);
+ }
+ updateSceneAnim(anim, stackPos(3));
+ _specialSceneScriptRunFlag = false;
+ return 0;
+}
+
int KyraEngine_v2::o2_useItemOnMainChar(ScriptState *script) {
ScriptState tmpScript;
_scriptInterpreter->initScript(&tmpScript, &_npcScriptData);