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