From 8e6708e6008b3ac1132f84923ebc766d1b199679 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 1 Mar 2015 21:58:58 -0500 Subject: XEEN: Hook up debugger properly and implement spell command --- engines/xeen/debugger.cpp | 35 +++++++++++++++++++++++++++++++---- engines/xeen/debugger.h | 7 +++++-- engines/xeen/dialogs_error.cpp | 5 ++++- engines/xeen/dialogs_spells.cpp | 1 - engines/xeen/events.cpp | 14 +++++++++++++- engines/xeen/resources.cpp | 16 ++++++++-------- 6 files changed, 61 insertions(+), 17 deletions(-) diff --git a/engines/xeen/debugger.cpp b/engines/xeen/debugger.cpp index a83af9f99d..35cbaeb58c 100644 --- a/engines/xeen/debugger.cpp +++ b/engines/xeen/debugger.cpp @@ -25,7 +25,7 @@ #include "xeen/debugger.h" namespace Xeen { -/* + static int strToInt(const char *s) { if (!*s) // No string at all @@ -41,16 +41,43 @@ static int strToInt(const char *s) { error("strToInt failed on string \"%s\"", s); return (int)tmp; } -*/ /*------------------------------------------------------------------------*/ Debugger::Debugger(XeenEngine *vm) : GUI::Debugger(), _vm(vm) { registerCmd("continue", WRAP_METHOD(Debugger, cmdExit)); - registerCmd("scene", WRAP_METHOD(Debugger, Cmd_LoadScene)); + registerCmd("spell", WRAP_METHOD(Debugger, cmdSpell)); + + _spellId = -1; } -bool Debugger::Cmd_LoadScene(int argc, const char **argv) { +void Debugger::update() { + Combat &combat = *_vm->_combat; + Party &party = *_vm->_party; + Spells &spells = *_vm->_spells; + + if (_spellId != -1) { + // Cast any specified spell + MagicSpell spellId = (MagicSpell)_spellId; + _spellId = -1; + spells.castSpell(&party._activeParty[0], spellId); + } + + onFrame(); +} + +bool Debugger::cmdSpell(int argc, const char **argv) { + if (argc != 2) { + debugPrintf("Format: spell "); + return true; + } else { + int spellId = strToInt(argv[1]); + if (spellId >= MS_AcidSpray && spellId <= MS_WizardEye) { + _spellId = spellId; + return false; + } + } + return true; } diff --git a/engines/xeen/debugger.h b/engines/xeen/debugger.h index 6a1ec12e80..e7f8ef6b7d 100644 --- a/engines/xeen/debugger.h +++ b/engines/xeen/debugger.h @@ -31,12 +31,15 @@ namespace Xeen { class XeenEngine; class Debugger : public GUI::Debugger { -protected: +private: XeenEngine *_vm; + int _spellId; - bool Cmd_LoadScene(int argc, const char **argv); + bool cmdSpell(int argc, const char **argv); public: Debugger(XeenEngine *vm); + + void update(); }; } // End of namespace Xeen diff --git a/engines/xeen/dialogs_error.cpp b/engines/xeen/dialogs_error.cpp index 7f649afd86..7204bad8fe 100644 --- a/engines/xeen/dialogs_error.cpp +++ b/engines/xeen/dialogs_error.cpp @@ -93,6 +93,7 @@ void CantCast::show(XeenEngine *vm, int spellId, int componentNum) { void CantCast::execute(int spellId, int componentNum) { EventsManager &events = *_vm->_events; SoundManager &sound = *_vm->_sound; + Spells &spells = *_vm->_spells; Window &w = _vm->_screen->_windows[6]; Mode oldMode = _vm->_mode; _vm->_mode = MODE_FF; @@ -100,7 +101,9 @@ void CantCast::execute(int spellId, int componentNum) { sound.playFX(21); w.open(); w.writeString(Common::String::format(NOT_ENOUGH_TO_CAST, - SPELL_CAST_COMPONENTS[componentNum - 1])); + SPELL_CAST_COMPONENTS[componentNum - 1], + spells._spellNames[spellId].c_str() + )); w.update(); do { diff --git a/engines/xeen/dialogs_spells.cpp b/engines/xeen/dialogs_spells.cpp index f49dca66b1..7cde5f37ef 100644 --- a/engines/xeen/dialogs_spells.cpp +++ b/engines/xeen/dialogs_spells.cpp @@ -988,7 +988,6 @@ void IdentifyMonster::execute() { Map &map = *_vm->_map; Screen &screen = *_vm->_screen; SoundManager &sound = *_vm->_sound; - Spells &spells = *_vm->_spells; Window &w = screen._windows[17]; Common::String monsterDesc[3]; diff --git a/engines/xeen/events.cpp b/engines/xeen/events.cpp index 9f13861dd2..92dc8b487f 100644 --- a/engines/xeen/events.cpp +++ b/engines/xeen/events.cpp @@ -94,7 +94,14 @@ void EventsManager::pollEvents() { case Common::EVENT_RTL: return; case Common::EVENT_KEYDOWN: - _keyCode = event.kbd.keycode; + // Check for debugger + if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) { + // Attach to the debugger + _vm->_debugger->attach(); + _vm->_debugger->onFrame(); + } else { + _keyCode = event.kbd.keycode; + } break; case Common::EVENT_MOUSEMOVE: _mousePos = event.mouse; @@ -181,6 +188,11 @@ void EventsManager::ipause(uint amount) { */ void EventsManager::nextFrame() { ++_frameCounter; + + // Allow debugger to update + _vm->_debugger->update(); + + // Update the screen _vm->_screen->update(); } diff --git a/engines/xeen/resources.cpp b/engines/xeen/resources.cpp index 8bc99f6579..544db24385 100644 --- a/engines/xeen/resources.cpp +++ b/engines/xeen/resources.cpp @@ -1315,7 +1315,7 @@ const char *const USE_ITEM_IN_COMBAT = const char *const NO_SPECIAL_ABILITIES = "\v005\x3""c%s\fdhas no special abilities!"; -const char *const CANT_CAST_WHILE_ENGAGED = "\x03c\v007Can't cast %s while engaged!"; +const char *const CANT_CAST_WHILE_ENGAGED = "\x3""c\v007Can't cast %s while engaged!"; const char *const EQUIPPED_ALL_YOU_CAN = "\x3""c\v007You have equipped all the %ss you can!"; const char *const REMOVE_X_TO_EQUIP_Y = "\x3""c\v007You must remove %sto equip %s\x8!"; @@ -1328,7 +1328,7 @@ const char *const CANNOT_DISCARD_CURSED_ITEM = "\3x""cYou cannot discard a curse const char *const PERMANENTLY_DISCARD = "\v000\t000\x03lPermanently discard %s\fd?"; -const char *const BACKPACK_IS_FULL = "\v005\x03c\fd%s's backpack is full."; +const char *const BACKPACK_IS_FULL = "\v005\x3""c\fd%s's backpack is full."; const char *const CATEGORY_BACKPACK_IS_FULL[4] = { "\v010\t000\x3""c%s's weapons backpack is full.", @@ -1341,11 +1341,11 @@ const char *const BUY_X_FOR_Y_GOLD = "\x3l\v000\t000\fdBuy %s\fd for %lu gold?"; const char *const SELL_X_FOR_Y_GOLD = "\x3l\v000\t000\fdSell %s\fd for %lu gold?"; -const char *const NO_NEED_OF_THIS = "\v005\x03c\fdWe have no need of this %s\f!"; +const char *const NO_NEED_OF_THIS = "\v005\x3""c\fdWe have no need of this %s\f!"; -const char *const NOT_RECHARGABLE = "\v012\x03c\fdNot Rechargeable. %s"; +const char *const NOT_RECHARGABLE = "\v012\x3""c\fdNot Rechargeable. %s"; -const char *const NOT_ENCHANTABLE = "\v012\t000\x03cNot Enchantable. %s"; +const char *const NOT_ENCHANTABLE = "\v012\t000\x3""cNot Enchantable. %s"; const char *const SPELL_FAILED = "Spell Failed!"; @@ -1495,7 +1495,7 @@ const int NEW_CHARACTER_SPELLS[10][4] = { const char *const COMBAT_DETAILS = "\r\f00\x3""c\v000\t000\x2""Combat%s%s%s\x1"; -const char *NOT_ENOUGH_TO_CAST = "\x03c\v010Not enough %s to Cast %s"; +const char *NOT_ENOUGH_TO_CAST = "\x3""c\v010Not enough %s to Cast %s"; const char *SPELL_CAST_COMPONENTS[2] = { "Spell Points", "Gems" }; const char *const CAST_SPELL_DETAILS = @@ -1530,7 +1530,7 @@ const char *const GIVE_TREASURE_FORMATTING = "\x4""077\n" "\x4""077"; -const char *const X_FOUND_Y = "\v060\t000\x03c%s found: %s"; +const char *const X_FOUND_Y = "\v060\t000\x3""c%s found: %s"; const char *const ON_WHO = "\x3""c\v009On Who?"; @@ -1554,7 +1554,7 @@ const char *const LLOYDS_BEACON = "%s\x3l\n" "x = %d\x3r\t000y = %d\x3""c\x2\v122\t021\f15S\fdet\t060\f15R\fdeturn\x1"; -const char *const HOW_MANY_SQUARES = "\x03cTeleport\nHow many squares %s (1-9)"; +const char *const HOW_MANY_SQUARES = "\x3""cTeleport\nHow many squares %s (1-9)"; const char *const TOWN_PORTAL = "\x3""cTown Portal\x3l\n" -- cgit v1.2.3