diff options
-rw-r--r-- | engines/parallaction/menu.cpp | 10 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 42 | ||||
-rw-r--r-- | engines/parallaction/parallaction_ns.cpp | 142 |
4 files changed, 136 insertions, 60 deletions
diff --git a/engines/parallaction/menu.cpp b/engines/parallaction/menu.cpp index 62f9bd98e5..96a366bd9e 100644 --- a/engines/parallaction/menu.cpp +++ b/engines/parallaction/menu.cpp @@ -142,7 +142,7 @@ void Menu::newGame() { if (_vm->getFeatures() & GF_DEMO) { // character screen is not shown on demo // so user warps to the playable intro - strcpy(_vm->_location._name, "fognedemo"); + strcpy(_vm->_location._name, "fognedemo.dough"); return; } @@ -171,15 +171,12 @@ void Menu::newGame() { _vm->showCursor(true); if (_mouseButtons != kMouseRightUp) { - strcpy(_vm->_location._name, "fogne"); + strcpy(_vm->_location._name, "fogne.dough"); return; // show intro } selectCharacter(); - char *v4 = strchr(_vm->_location._name, '.') + 1; - _vm->_char.setName(v4); - return; // start game } @@ -290,8 +287,7 @@ uint16 Menu::selectGame() { // game window without picking a savegame. // The 2 strcpy's below act as workaround to prevent crashes for // time being. - strcpy(_vm->_location._name, "fogne"); - _vm->_char.setName("dough"); + strcpy(_vm->_location._name, "fogne.dough"); _vm->loadGame(); return 1; // load game diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index bc41f9f341..e7223d2386 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -172,8 +172,6 @@ int Parallaction::init() { _backgroundInfo = new BackgroundInfo; strcpy(_characterName1, "null"); -// strcpy(_char._name, "dough"); - _char.setName("dough"); memset(_locationNames, 0, NUM_LOCATIONS * 32); diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index dc4e7fcb5e..0f4cd12253 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -597,6 +597,48 @@ public: }; +class LocationName { + + Common::String _slide; + Common::String _character; + Common::String _location; + + bool _hasCharacter; + bool _hasSlide; + char *_buf; + +public: + LocationName(); + ~LocationName(); + + void bind(const char*); + + const char *location() const { + return _location.c_str(); + } + + bool hasCharacter() const { + return _hasCharacter; + } + + const char *character() const { + return _character.c_str(); + } + + bool hasSlide() const { + return _hasSlide; + } + + const char *slide() const { + return _slide.c_str(); + } + + const char *c_str() const { + return _buf; + } +}; + + class Parallaction_ns : public Parallaction { public: diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index d5b59ff496..fd717a11b6 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -40,6 +40,76 @@ namespace Parallaction { #define MOUSECOMBO_WIDTH 32 // sizes for cursor + selected inventory item #define MOUSECOMBO_HEIGHT 32 +LocationName::LocationName() { + _buf = 0; + _hasSlide = false; + _hasCharacter = false; +} + +LocationName::~LocationName() { + if (_buf) + free(_buf); +} + + +/* + bind accept the following input formats: + + 1 - [S].slide.[L]{.[C]} + 2 - [L]{.[C]} + + where: + + [S] is the slide to be shown + [L] is the location to switch to (immediately in case 2, or right after slide [S] in case 1) + [C] is the character to be selected, and is optional + + The routine tells one form from the other by searching for the '.slide.' + + NOTE: there exists one script in which [L] is not used in the case 1, but its use + is commented out, and would definitely crash the current implementation. +*/ +void LocationName::bind(const char *s) { + + if (_buf) + free(_buf); + + _buf = strdup(s); + _hasSlide = false; + _hasCharacter = false; + + Common::StringList list; + char *tok = strtok(_buf, "."); + while (tok) { + list.push_back(tok); + tok = strtok(NULL, "."); + } + + if (list.size() < 1 || list.size() > 4) + error("changeLocation: ill-formed location name '%s'", s); + + if (list.size() > 1) { + if (list[1] == "slide") { + _hasSlide = true; + _slide = list[0]; + + list.remove_at(0); // removes slide name + list.remove_at(0); // removes 'slide' + } + + if (list.size() == 2) { + _hasCharacter = true; + _character = list[1]; + } + } + + _location = list[0]; + + strcpy(_buf, s); // kept as reference +} + + + int Parallaction_ns::init() { // Detect game @@ -193,10 +263,11 @@ int Parallaction_ns::go() { _menu = new Menu(this); _menu->start(); - char *v4 = strchr(_location._name, '.'); - if (v4) { - *v4 = '\0'; - } + LocationName locname; + locname.bind(_location._name); + + _char.setName(locname.character()); + strcpy(_location._name, locname.location()); _globalTable = _disk->loadTable("global"); @@ -221,25 +292,9 @@ int Parallaction_ns::go() { return 0; } - -/* - changeLocation handles transitions between locations, and is able to display slides - between one and the other. The input parameter 'location' exists in some flavours: - - 1 - [S].slide.[L]{.[C]} - 2 - [L]{.[C]} - - where: - - [S] is the slide to be shown - [L] is the location to switch to (immediately in case 2, or right after slide [S] in case 1) - [C] is the character to be selected, and is optional - - The routine tells one form from the other by searching for the '.slide.' - - NOTE: there exists one script in which [L] is not used in the case 1, but its use - is commented out, and would definitely crash the current implementation. -*/ +// changeLocation handles transitions between locations, and is able to display slides +// between one and the other. +// void Parallaction_ns::changeLocation(char *location) { debugC(1, kDebugExec, "changeLocation(%s)", location); @@ -264,41 +319,26 @@ void Parallaction_ns::changeLocation(char *location) { runJobs(); freeLocation(); - char buf[100]; - strcpy(buf, location); - - Common::StringList list; - char *tok = strtok(location, "."); - while (tok) { - list.push_back(tok); - tok = strtok(NULL, "."); - } - if (list.size() < 1 || list.size() > 4) - error("changeLocation: ill-formed location string '%s'", location); + LocationName locname; + locname.bind(location); - if (list.size() > 1) { - if (list[1] == "slide") { - showSlide(list[0].c_str()); - _gfx->setFont(_menuFont); - _gfx->displayCenteredString(14, _slideText[0]); // displays text on screen - _gfx->updateScreen(); - waitUntilLeftClick(); - - list.remove_at(0); // removes slide name - list.remove_at(0); // removes 'slide' - } + if (locname.hasSlide()) { + showSlide(locname.slide()); + _gfx->setFont(_menuFont); + _gfx->displayCenteredString(14, _slideText[0]); // displays text on screen + _gfx->updateScreen(); + waitUntilLeftClick(); + } - // list is now only [L].{[C]} (see above comment) - if (list.size() == 2) { - changeCharacter(list[1].c_str()); - } + if (locname.hasCharacter()) { + changeCharacter(locname.character()); } _animations.push_front(&_char._ani); - strcpy(_saveData1, list[0].c_str()); - parseLocation(list[0].c_str()); + strcpy(_saveData1, locname.location()); + parseLocation(_saveData1); _char._ani._oldPos.x = -1000; _char._ani._oldPos.y = -1000; |