aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Mettifogo2009-04-06 17:21:23 +0000
committerNicola Mettifogo2009-04-06 17:21:23 +0000
commit0e05ec8cc8122e92400925496e3a21e3980fe20d (patch)
treed09d738a8032ef479f351474db96c3de23ac678d
parent2ab995557723d87c2e616973179cc712896bcf6a (diff)
downloadscummvm-rg350-0e05ec8cc8122e92400925496e3a21e3980fe20d.tar.gz
scummvm-rg350-0e05ec8cc8122e92400925496e3a21e3980fe20d.tar.bz2
scummvm-rg350-0e05ec8cc8122e92400925496e3a21e3980fe20d.zip
Cleanup of Balloon and Dialogue code:
* moved version-specific code into DialogueManager's derivatives * reworked construction of BalloonManager's derivatives * moved a couple of globals used in dialogues (NS specific) to engine svn-id: r39878
-rw-r--r--engines/parallaction/balloons.cpp118
-rw-r--r--engines/parallaction/dialogue.cpp319
-rw-r--r--engines/parallaction/parallaction.cpp7
-rw-r--r--engines/parallaction/parallaction.h12
-rw-r--r--engines/parallaction/parallaction_br.cpp1
-rw-r--r--engines/parallaction/parallaction_ns.cpp3
-rw-r--r--engines/parallaction/saveload.cpp4
7 files changed, 242 insertions, 222 deletions
diff --git a/engines/parallaction/balloons.cpp b/engines/parallaction/balloons.cpp
index 5329c16915..558d02341e 100644
--- a/engines/parallaction/balloons.cpp
+++ b/engines/parallaction/balloons.cpp
@@ -147,6 +147,7 @@ public:
class StringWriter_NS : public WrappedLineFormatter {
+ Parallaction_ns *_vm;
uint _width, _height;
byte _color;
@@ -156,15 +157,15 @@ class StringWriter_NS : public WrappedLineFormatter {
protected:
virtual Common::String expand(const Common::String& token) {
if (token.compareToIgnoreCase("%p") == 0) {
- Common::String t(".......");
- for (int i = 0; _password[i]; i++) {
- t.setChar(_password[i], i);
+ Common::String t(_vm->_password);
+ for (int i = t.size(); i < 7; i++) {
+ t += '.';
}
return Common::String("> ") + t;
} else
if (token.compareToIgnoreCase("%s") == 0) {
char buf[20];
- sprintf(buf, "%i", _score);
+ sprintf(buf, "%i", _vm->_score);
return Common::String(buf);
}
@@ -191,7 +192,7 @@ protected:
}
public:
- StringWriter_NS(Font *font) : WrappedLineFormatter(font) { }
+ StringWriter_NS(Parallaction_ns *vm, Font *font) : WrappedLineFormatter(font), _vm(vm) { }
void write(const char *text, uint maxWidth, byte color, Graphics::Surface *surf) {
StringExtent_NS se(_font);
@@ -244,6 +245,7 @@ byte _resBalloonTail[2][BALLOON_TAIL_WIDTH*BALLOON_TAIL_HEIGHT] = {
class BalloonManager_ns : public BalloonManager {
+ Parallaction_ns *_vm;
static int16 _dialogueBalloonX[5];
byte _textColors[2];
@@ -260,11 +262,11 @@ class BalloonManager_ns : public BalloonManager {
int createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness);
Balloon *getBalloon(uint id);
- Gfx *_gfx;
- Font *_font;
+ StringWriter_NS _sw;
+ StringExtent_NS _se;
public:
- BalloonManager_ns(Gfx *gfx, Font *font);
+ BalloonManager_ns(Parallaction_ns *vm, Font *font);
~BalloonManager_ns();
void reset();
@@ -277,7 +279,7 @@ public:
int16 BalloonManager_ns::_dialogueBalloonX[5] = { 80, 120, 150, 150, 150 };
-BalloonManager_ns::BalloonManager_ns(Gfx *gfx, Font *font) : _numBalloons(0), _gfx(gfx), _font(font) {
+BalloonManager_ns::BalloonManager_ns(Parallaction_ns *vm, Font *font) : _vm(vm), _numBalloons(0), _sw(vm, font), _se(font) {
_textColors[kSelectedColor] = 0;
_textColors[kUnselectedColor] = 3;
_textColors[kNormalColor] = 0;
@@ -319,7 +321,7 @@ int BalloonManager_ns::createBalloon(int16 w, int16 h, int16 winding, uint16 bor
winding = (winding == 0 ? 1 : 0);
Common::Rect s(BALLOON_TAIL_WIDTH, BALLOON_TAIL_HEIGHT);
s.moveTo(r.width()/2 - 5, r.bottom - 1);
- _gfx->blt(s, _resBalloonTail[winding], balloon->surface, LAYER_FOREGROUND, 100, BALLOON_TRANSPARENT_COLOR_NS);
+ _vm->_gfx->blt(s, _resBalloonTail[winding], balloon->surface, LAYER_FOREGROUND, 100, BALLOON_TRANSPARENT_COLOR_NS);
}
_numBalloons++;
@@ -332,19 +334,17 @@ int BalloonManager_ns::setSingleBalloon(const char *text, uint16 x, uint16 y, ui
int16 w, h;
- StringExtent_NS se(_font);
- se.calc(text, MAX_BALLOON_WIDTH);
- w = se.width() + 14;
- h = se.height() + 20;
+ _se.calc(text, MAX_BALLOON_WIDTH);
+ w = _se.width() + 14;
+ h = _se.height() + 20;
int id = createBalloon(w+5, h, winding, 1);
Balloon *balloon = &_intBalloons[id];
- StringWriter_NS sw(_font);
- sw.write(text, MAX_BALLOON_WIDTH, _textColors[textColor], balloon->surface);
+ _sw.write(text, MAX_BALLOON_WIDTH, _textColors[textColor], balloon->surface);
// TODO: extract some text to make a name for obj
- balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+ balloon->obj = _vm->_gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
balloon->obj->x = x;
balloon->obj->y = y;
balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_NS;
@@ -356,20 +356,18 @@ int BalloonManager_ns::setDialogueBalloon(const char *text, uint16 winding, Text
int16 w, h;
- StringExtent_NS se(_font);
- se.calc(text, MAX_BALLOON_WIDTH);
- w = se.width() + 14;
- h = se.height() + 20;
+ _se.calc(text, MAX_BALLOON_WIDTH);
+ w = _se.width() + 14;
+ h = _se.height() + 20;
int id = createBalloon(w+5, h, winding, 1);
Balloon *balloon = &_intBalloons[id];
- StringWriter_NS sw(_font);
- sw.write(text, MAX_BALLOON_WIDTH, _textColors[textColor], balloon->surface);
+ _sw.write(text, MAX_BALLOON_WIDTH, _textColors[textColor], balloon->surface);
// TODO: extract some text to make a name for obj
- balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+ balloon->obj = _vm->_gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
balloon->obj->x = _dialogueBalloonX[id];
balloon->obj->y = 10;
balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_NS;
@@ -386,8 +384,7 @@ void BalloonManager_ns::setBalloonText(uint id, const char *text, TextColor text
Balloon *balloon = getBalloon(id);
balloon->surface->fillRect(balloon->innerBox, 1);
- StringWriter_NS sw(_font);
- sw.write(text, MAX_BALLOON_WIDTH, _textColors[textColor], balloon->surface);
+ _sw.write(text, MAX_BALLOON_WIDTH, _textColors[textColor], balloon->surface);
}
@@ -395,18 +392,16 @@ int BalloonManager_ns::setLocationBalloon(const char *text, bool endGame) {
int16 w, h;
- StringExtent_NS se(_font);
- se.calc(text, MAX_BALLOON_WIDTH);
- w = se.width() + 14;
- h = se.height() + 20;
+ _se.calc(text, MAX_BALLOON_WIDTH);
+ w = _se.width() + 14;
+ h = _se.height() + 20;
int id = createBalloon(w+(endGame ? 5 : 10), h+5, -1, BALLOON_TRANSPARENT_COLOR_NS);
Balloon *balloon = &_intBalloons[id];
- StringWriter_NS sw(_font);
- sw.write(text, MAX_BALLOON_WIDTH, _textColors[kNormalColor], balloon->surface);
+ _sw.write(text, MAX_BALLOON_WIDTH, _textColors[kNormalColor], balloon->surface);
// TODO: extract some text to make a name for obj
- balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+ balloon->obj = _vm->_gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
balloon->obj->x = 5;
balloon->obj->y = 5;
balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_NS;
@@ -534,6 +529,7 @@ public:
class BalloonManager_br : public BalloonManager {
+ Parallaction_br *_vm;
byte _textColors[2];
struct Balloon {
@@ -544,10 +540,6 @@ class BalloonManager_br : public BalloonManager {
uint _numBalloons;
- Disk *_disk;
- Gfx *_gfx;
- Font *_font;
-
Frames *_leftBalloon;
Frames *_rightBalloon;
@@ -557,10 +549,11 @@ class BalloonManager_br : public BalloonManager {
Balloon *getBalloon(uint id);
Graphics::Surface *expandBalloon(Frames *data, int frameNum);
- StringWriter_BR _writer;
+ StringWriter_BR _sw;
+ StringExtent_BR _se;
public:
- BalloonManager_br(Disk *disk, Gfx *gfx, Font *font);
+ BalloonManager_br(Parallaction_br *vm, Font *font);
~BalloonManager_br();
void reset();
@@ -588,7 +581,7 @@ Graphics::Surface *BalloonManager_br::expandBalloon(Frames *data, int frameNum)
Graphics::Surface *surf = new Graphics::Surface;
surf->create(rect.width(), rect.height(), 1);
- _gfx->unpackBlt(rect, data->getData(frameNum), data->getRawSize(frameNum), surf, LAYER_FOREGROUND, 100, BALLOON_TRANSPARENT_COLOR_BR);
+ _vm->_gfx->unpackBlt(rect, data->getData(frameNum), data->getRawSize(frameNum), surf, LAYER_FOREGROUND, 100, BALLOON_TRANSPARENT_COLOR_BR);
return surf;
}
@@ -616,10 +609,10 @@ int BalloonManager_br::setSingleBalloon(const char *text, uint16 x, uint16 y, ui
balloon->surface = expandBalloon(src, srcFrame);
src->getRect(srcFrame, balloon->box);
- _writer.write(text, 216, _textColors[textColor], balloon->surface);
+ _sw.write(text, 216, _textColors[textColor], balloon->surface);
// TODO: extract some text to make a name for obj
- balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+ balloon->obj = _vm->_gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
balloon->obj->x = x + balloon->box.left;
balloon->obj->y = y + balloon->box.top;
balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_BR;
@@ -653,10 +646,10 @@ int BalloonManager_br::setDialogueBalloon(const char *text, uint16 winding, Text
src->getRect(srcFrame, balloon->box);
// TODO: fix text positioning in the Amiga version
- _writer.write(text, 216, _textColors[textColor], balloon->surface);
+ _sw.write(text, 216, _textColors[textColor], balloon->surface);
// TODO: extract some text to make a name for obj
- balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+ balloon->obj = _vm->_gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
balloon->obj->x = balloon->box.left;
balloon->obj->y = balloon->box.top;
balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_BR;
@@ -668,9 +661,7 @@ int BalloonManager_br::setDialogueBalloon(const char *text, uint16 winding, Text
void BalloonManager_br::setBalloonText(uint id, const char *text, TextColor textColor) {
Balloon *balloon = getBalloon(id);
-
- StringWriter_BR sw(_font);
- sw.write(text, 216, _textColors[textColor], balloon->surface);
+ _sw.write(text, 216, _textColors[textColor], balloon->surface);
}
int BalloonManager_br::createBalloon(int16 w, int16 h, uint16 borderThickness) {
@@ -693,16 +684,14 @@ int BalloonManager_br::createBalloon(int16 w, int16 h, uint16 borderThickness) {
}
int BalloonManager_br::setLocationBalloon(const char *text, bool endGame) {
- StringExtent_BR se(_font);
-
- se.calc(text, 240);
+ _se.calc(text, 240);
- int id = createBalloon(se.width() + 20, se.height() + 30, 2);
+ int id = createBalloon(_se.width() + 20, _se.height() + 30, 2);
Balloon *balloon = &_intBalloons[id];
- _writer.write(text, 240, kNormalColor, balloon->surface);
+ _sw.write(text, 240, kNormalColor, balloon->surface);
- balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+ balloon->obj = _vm->_gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
balloon->obj->x = 5;
balloon->obj->y = 5;
@@ -733,15 +722,15 @@ void BalloonManager_br::reset() {
void BalloonManager_br::cacheAnims() {
if (!_leftBalloon) {
- _leftBalloon = _disk->loadFrames("fumetto.ani");
- _rightBalloon = _disk->loadFrames("fumdx.ani");
+ _leftBalloon = _vm->_disk->loadFrames("fumetto.ani");
+ _rightBalloon = _vm->_disk->loadFrames("fumdx.ani");
}
}
-BalloonManager_br::BalloonManager_br(Disk *disk, Gfx *gfx, Font *font) : _numBalloons(0), _disk(disk), _gfx(gfx), _font(font),
- _leftBalloon(0), _rightBalloon(0), _writer(_font) {
+BalloonManager_br::BalloonManager_br(Parallaction_br *vm, Font *font) : _vm(vm), _numBalloons(0),
+ _leftBalloon(0), _rightBalloon(0), _sw(font), _se(font) {
if (_vm->getPlatform() == Common::kPlatformPC) {
_textColors[kSelectedColor] = 12;
@@ -759,17 +748,12 @@ BalloonManager_br::~BalloonManager_br() {
delete _rightBalloon;
}
-void Parallaction::setupBalloonManager() {
- _balloonMan = 0;
+void Parallaction_ns::setupBalloonManager() {
+ _balloonMan = new BalloonManager_ns(this, _dialogueFont);
+}
- if (getGameType() == GType_Nippon) {
- _balloonMan = new BalloonManager_ns(_gfx, _dialogueFont);
- } else
- if (getGameType() == GType_BRA) {
- _balloonMan = new BalloonManager_br(_disk, _gfx, _dialogueFont);
- } else {
- error("Unknown game type");
- }
+void Parallaction_br::setupBalloonManager() {
+ _balloonMan = new BalloonManager_br(this, _dialogueFont);
}
diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp
index 6596a09bda..a937d91be6 100644
--- a/engines/parallaction/dialogue.cpp
+++ b/engines/parallaction/dialogue.cpp
@@ -75,10 +75,6 @@ class DialogueManager {
Parallaction *_vm;
Dialogue *_dialogue;
- bool _askPassword;
- int _passwordLen;
- bool _passwordChanged;
-
bool isNpc;
GfxObj *_questioner;
GfxObj *_answerer;
@@ -86,20 +82,22 @@ class DialogueManager {
Question *_q;
- uint16 _visAnswers[5];
- int _numVisAnswers;
-
int _answerId;
int _selection, _oldSelection;
uint32 _mouseButtons;
Common::Point _mousePos;
- bool _isKeyDown;
- uint16 _downKey;
protected:
BalloonPositions _ballonPos;
+ struct VisibleAnswer {
+ Answer *_a;
+ int _balloon;
+ } _visAnswers[5];
+ int _numVisAnswers;
+ bool _isKeyDown;
+ uint16 _downKey;
public:
DialogueManager(Parallaction *vm, ZonePtr z);
@@ -119,66 +117,25 @@ protected:
bool displayQuestion();
bool displayAnswers();
bool testAnswerFlags(Answer *a);
- virtual bool canDisplayAnswer(Answer *a) = 0;
+ virtual void addVisibleAnswers(Question *q) = 0;
+ virtual int16 selectAnswer() = 0;
int16 selectAnswer1();
int16 selectAnswerN();
- int16 askPassword();
int16 getHoverAnswer(int16 x, int16 y);
void runQuestion();
void runAnswer();
void nextQuestion();
void nextAnswer();
-
- bool checkPassword();
- void resetPassword();
- void accumPassword(uint16 ascii);
-};
-
-class DialogueManager_ns : public DialogueManager {
- Parallaction_ns *_vm;
-
-public:
- DialogueManager_ns(Parallaction_ns *vm, ZonePtr z) : DialogueManager(vm, z), _vm(vm) {
- _ballonPos = _balloonPositions_NS;
- }
-
- virtual bool canDisplayAnswer(Answer *a) {
- return testAnswerFlags(a);
- }
-};
-
-class DialogueManager_br : public DialogueManager {
- Parallaction_br *_vm;
-
-public:
- DialogueManager_br(Parallaction_br *vm, ZonePtr z) : DialogueManager(vm, z), _vm(vm) {
- _ballonPos = _balloonPositions_BR;
- }
-
- virtual bool canDisplayAnswer(Answer *a) {
- if (!a)
- return false;
-
- if (a->_hasCounterCondition) {
- _vm->testCounterCondition(a->_counterName, a->_counterOp, a->_counterValue);
- return (_vm->getLocationFlags() & kFlagsTestTrue) != 0;
- }
-
- return testAnswerFlags(a);
- }
};
-
DialogueManager::DialogueManager(Parallaction *vm, ZonePtr z) : _vm(vm), _z(z) {
_dialogue = _z->u._speakDialogue;
isNpc = !_z->u._filename.empty() && _z->u._filename.compareToIgnoreCase("yourself");
_questioner = isNpc ? _vm->_disk->loadTalk(_z->u._filename.c_str()) : _vm->_char._talk;
_answerer = _vm->_char._talk;
- _askPassword = false;
-
_cmdList = 0;
_answerId = 0;
}
@@ -207,35 +164,27 @@ bool DialogueManager::testAnswerFlags(Answer *a) {
bool DialogueManager::displayAnswers() {
- _numVisAnswers = 0;
-
- Answer *a;
- for (int i = 0; i < NUM_ANSWERS && _q->_answers[i]; i++) {
- a = _q->_answers[i];
- if (!canDisplayAnswer(a)) {
- continue;
- }
+ addVisibleAnswers(_q);
+ if (_numVisAnswers == 0) {
+ return false;
+ }
- int id = _vm->_balloonMan->setDialogueBalloon(a->_text.c_str(), 1, BalloonManager::kUnselectedColor);
+ // create balloons
+ int id;
+ for (int i = 0; i < _numVisAnswers; ++i) {
+ id = _vm->_balloonMan->setDialogueBalloon(_visAnswers[i]._a->_text.c_str(), 1, BalloonManager::kUnselectedColor);
assert(id >= 0);
- _visAnswers[id] = i;
- _askPassword = a->_text.contains("%P");
+ _visAnswers[i]._balloon = id;
- _numVisAnswers++;
}
int mood = 0;
-
- if (_askPassword) {
- resetPassword();
- } else
if (_numVisAnswers == 1) {
- a = _q->_answers[_visAnswers[0]];
- mood = a->_mood & 0xF;
- _vm->_balloonMan->setBalloonText(0, a->_text.c_str(), BalloonManager::kNormalColor);
+ mood = _visAnswers[0]._a->_mood & 0xF;
+ _vm->_balloonMan->setBalloonText(_visAnswers[0]._balloon, _visAnswers[0]._a->_text.c_str(), BalloonManager::kNormalColor);
} else
if (_numVisAnswers > 1) {
- mood = _q->_answers[_visAnswers[0]]->_mood & 0xF;
+ mood = _visAnswers[0]._a->_mood & 0xF;
_oldSelection = -1;
_selection = 0;
}
@@ -243,72 +192,16 @@ bool DialogueManager::displayAnswers() {
_faceId = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y);
_vm->_gfx->setItemFrame(_faceId, mood);
- return _numVisAnswers > 0;
-}
-
-bool DialogueManager::displayQuestion() {
- if (!_q->_text.compareToIgnoreCase("NULL")) return false;
-
- _vm->_balloonMan->setSingleBalloon(_q->_text.c_str(), _ballonPos._questionBalloon.x, _ballonPos._questionBalloon.y, _q->_mood & 0x10, BalloonManager::kNormalColor);
- _faceId = _vm->_gfx->setItem(_questioner, _ballonPos._questionChar.x, _ballonPos._questionChar.y);
- _vm->_gfx->setItemFrame(_faceId, _q->_mood & 0xF);
-
return true;
}
-
-bool DialogueManager::checkPassword() {
- return ((!scumm_stricmp(_vm->_char.getBaseName(), _doughName) && !scumm_strnicmp(_password, "1732461", 7)) ||
- (!scumm_stricmp(_vm->_char.getBaseName(), _donnaName) && !scumm_strnicmp(_password, "1622", 4)) ||
- (!scumm_stricmp(_vm->_char.getBaseName(), _dinoName) && !scumm_strnicmp(_password, "179", 3)));
-}
-
-void DialogueManager::resetPassword() {
- _passwordLen = 0;
- _password[0] = '\0';
- _passwordChanged = true;
-}
-
-void DialogueManager::accumPassword(uint16 ascii) {
- if (!isdigit(ascii)) {
- return;
- }
-
- _password[_passwordLen] = ascii;
- _passwordLen++;
- _password[_passwordLen] = '\0';
- _passwordChanged = true;
-}
-
-int16 DialogueManager::askPassword() {
-
- if (_isKeyDown) {
- accumPassword(_downKey);
- }
-
- if (_passwordChanged) {
- _vm->_balloonMan->setBalloonText(0, _q->_answers[0]->_text.c_str(), BalloonManager::kNormalColor);
- _passwordChanged = false;
- }
-
- if ((_passwordLen == MAX_PASSWORD_LENGTH) || ((_isKeyDown) && (_downKey == Common::KEYCODE_RETURN))) {
- if (checkPassword()) {
- return 0;
- } else {
- resetPassword();
- }
- }
-
- return -1;
-}
-
int16 DialogueManager::selectAnswer1() {
- if (!_q->_answers[_visAnswers[0]]->_text.compareToIgnoreCase("null")) {
- return _visAnswers[0];
+ if (!_visAnswers[0]._a->_text.compareToIgnoreCase("null")) {
+ return 0;
}
if (_mouseButtons == kMouseLeftUp) {
- return _visAnswers[0];
+ return 0;
}
return -1;
@@ -320,24 +213,34 @@ int16 DialogueManager::selectAnswerN() {
if (_selection != _oldSelection) {
if (_oldSelection != -1) {
- _vm->_balloonMan->setBalloonText(_oldSelection, _q->_answers[_visAnswers[_oldSelection]]->_text.c_str(), BalloonManager::kUnselectedColor);
+ _vm->_balloonMan->setBalloonText(_visAnswers[_oldSelection]._balloon, _visAnswers[_oldSelection]._a->_text.c_str(), BalloonManager::kUnselectedColor);
}
if (_selection != -1) {
- _vm->_balloonMan->setBalloonText(_selection, _q->_answers[_visAnswers[_selection]]->_text.c_str(), BalloonManager::kSelectedColor);
- _vm->_gfx->setItemFrame(_faceId, _q->_answers[_visAnswers[_selection]]->_mood & 0xF);
+ _vm->_balloonMan->setBalloonText(_visAnswers[_selection]._balloon, _visAnswers[_selection]._a->_text.c_str(), BalloonManager::kSelectedColor);
+ _vm->_gfx->setItemFrame(_faceId, _visAnswers[_selection]._a->_mood & 0xF);
}
}
_oldSelection = _selection;
if ((_mouseButtons == kMouseLeftUp) && (_selection != -1)) {
- return _visAnswers[_selection];
+ return _selection;
}
return -1;
}
+bool DialogueManager::displayQuestion() {
+ if (!_q->_text.compareToIgnoreCase("NULL")) return false;
+
+ _vm->_balloonMan->setSingleBalloon(_q->_text.c_str(), _ballonPos._questionBalloon.x, _ballonPos._questionBalloon.y, _q->_mood & 0x10, BalloonManager::kNormalColor);
+ _faceId = _vm->_gfx->setItem(_questioner, _ballonPos._questionChar.x, _ballonPos._questionChar.y);
+ _vm->_gfx->setItemFrame(_faceId, _q->_mood & 0xF);
+
+ return true;
+}
+
void DialogueManager::runQuestion() {
debugC(9, kDebugDialogue, "runQuestion\n");
@@ -369,14 +272,7 @@ void DialogueManager::nextAnswer() {
void DialogueManager::runAnswer() {
debugC(9, kDebugDialogue, "runAnswer\n");
- if (_askPassword) {
- _answerId = askPassword();
- } else
- if (_numVisAnswers == 1) {
- _answerId = selectAnswer1();
- } else {
- _answerId = selectAnswerN();
- }
+ _answerId = selectAnswer();
if (_answerId != -1) {
_cmdList = &_q->_answers[_answerId]->_commands;
@@ -431,6 +327,143 @@ void DialogueManager::run() {
}
+
+
+class DialogueManager_ns : public DialogueManager {
+protected:
+ Parallaction_ns *_vm;
+ bool _passwordChanged;
+ bool _askPassword;
+
+ bool checkPassword() {
+ return ((!scumm_stricmp(_vm->_char.getBaseName(), _doughName) && _vm->_password.hasPrefix("1732461")) ||
+ (!scumm_stricmp(_vm->_char.getBaseName(), _donnaName) && _vm->_password.hasPrefix("1622")) ||
+ (!scumm_stricmp(_vm->_char.getBaseName(), _dinoName) && _vm->_password.hasPrefix("179")));
+ }
+
+ void resetPassword() {
+ _vm->_password.clear();
+ _passwordChanged = true;
+ }
+
+ void accumPassword(uint16 ascii) {
+ if (!isdigit(ascii)) {
+ return;
+ }
+
+ _vm->_password += ascii;
+ _passwordChanged = true;
+ }
+
+ int16 askPassword() {
+
+ if (_isKeyDown) {
+ accumPassword(_downKey);
+ }
+
+ if (_passwordChanged) {
+ _vm->_balloonMan->setBalloonText(_visAnswers[0]._balloon, _visAnswers[0]._a->_text.c_str(), BalloonManager::kNormalColor);
+ _passwordChanged = false;
+ }
+
+ if ((_vm->_password.size() == MAX_PASSWORD_LENGTH) || ((_isKeyDown) && (_downKey == Common::KEYCODE_RETURN))) {
+ if (checkPassword()) {
+ return 0;
+ } else {
+ resetPassword();
+ }
+ }
+
+ return -1;
+ }
+
+public:
+ DialogueManager_ns(Parallaction_ns *vm, ZonePtr z) : DialogueManager(vm, z), _vm(vm) {
+ _ballonPos = _balloonPositions_NS;
+ }
+
+ bool canDisplayAnswer(Answer *a) {
+ return testAnswerFlags(a);
+ }
+
+ virtual void addVisibleAnswers(Question *q) {
+ _askPassword = false;
+ _numVisAnswers = 0;
+ for (int i = 0; i < NUM_ANSWERS && q->_answers[i]; i++) {
+ Answer *a = q->_answers[i];
+ if (!canDisplayAnswer(a)) {
+ continue;
+ }
+
+ if (a->_text.contains("%P")) {
+ _askPassword = true;
+ }
+
+ _visAnswers[_numVisAnswers]._a = a;
+ _numVisAnswers++;
+ }
+
+ resetPassword();
+ }
+
+ virtual int16 selectAnswer() {
+ int ans = -1;
+ if (_askPassword) {
+ ans = askPassword();
+ } else
+ if (_numVisAnswers == 1) {
+ ans = selectAnswer1();
+ } else {
+ ans = selectAnswerN();
+ }
+ return ans;
+ }
+};
+
+class DialogueManager_br : public DialogueManager {
+ Parallaction_br *_vm;
+
+public:
+ DialogueManager_br(Parallaction_br *vm, ZonePtr z) : DialogueManager(vm, z), _vm(vm) {
+ _ballonPos = _balloonPositions_BR;
+ }
+
+ bool canDisplayAnswer(Answer *a) {
+ if (!a)
+ return false;
+
+ if (a->_hasCounterCondition) {
+ _vm->testCounterCondition(a->_counterName, a->_counterOp, a->_counterValue);
+ return (_vm->getLocationFlags() & kFlagsTestTrue) != 0;
+ }
+
+ return testAnswerFlags(a);
+ }
+
+ virtual void addVisibleAnswers(Question *q) {
+ _numVisAnswers = 0;
+ for (int i = 0; i < NUM_ANSWERS && q->_answers[i]; i++) {
+ Answer *a = q->_answers[i];
+ if (!canDisplayAnswer(a)) {
+ continue;
+ }
+ _visAnswers[_numVisAnswers]._a = a;
+ _numVisAnswers++;
+ }
+ }
+
+ virtual int16 selectAnswer() {
+ int16 ans = -1;
+ if (_numVisAnswers == 1) {
+ ans = selectAnswer1();
+ } else {
+ ans = selectAnswerN();
+ }
+ return ans;
+ }
+};
+
+
void Parallaction::enterDialogueMode(ZonePtr z) {
debugC(1, kDebugDialogue, "Parallaction::enterDialogueMode(%s)", z->u._filename.c_str());
_dialogueMan = _vm->createDialogueManager(z);
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp
index fcd162f9a9..d9673f9002 100644
--- a/engines/parallaction/parallaction.cpp
+++ b/engines/parallaction/parallaction.cpp
@@ -32,7 +32,6 @@
#include "sound/mididrv.h"
#include "sound/mixer.h"
-
#include "parallaction/exec.h"
#include "parallaction/input.h"
#include "parallaction/parallaction.h"
@@ -51,9 +50,6 @@ Parallaction *_vm = NULL;
char _saveData1[30] = { '\0' };
uint32 _engineFlags = 0;
-uint16 _score = 1;
-char _password[8];
-
uint32 _globalFlags = 0;
// private stuff
@@ -131,8 +127,6 @@ Common::Error Parallaction::init() {
_menuHelper = 0;
- setupBalloonManager();
-
return Common::kNoError;
}
@@ -900,6 +894,7 @@ CharacterName::CharacterName(const char *name) {
bind(name);
}
+
void CharacterName::bind(const char *name) {
const char *begin = name;
const char *end = begin + strlen(name);
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 988a16a297..4e799a048e 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -94,8 +94,6 @@ struct PARALLACTIONGameDescription;
-extern char _password[8];
-extern uint16 _score;
extern uint32 _engineFlags;
extern char _saveData1[];
extern uint32 _globalFlags;
@@ -129,7 +127,7 @@ class LocationParser_ns;
class LocationParser_br;
class ProgramParser_ns;
class ProgramParser_br;
-
+class BalloonManager;
struct Location {
@@ -331,7 +329,6 @@ protected:
void allocateLocationSlot(const char *name);
void finalizeLocationParsing();
void showLocationComment(const Common::String &text, bool end);
- void setupBalloonManager();
public:
void beep();
@@ -394,6 +391,10 @@ public:
SoundMan_ns* _soundManI;
+ uint16 _score;
+ Common::String _password;
+
+
public:
virtual void parseLocation(const char *filename);
virtual void changeLocation();
@@ -419,6 +420,7 @@ private:
void initResources();
void initInventory();
void destroyInventory();
+ void setupBalloonManager();
void startGui();
void startCreditSequence();
void startEndPartSequence();
@@ -437,6 +439,7 @@ private:
ZonePtr _moveSarcGetZones[5];
ZonePtr _moveSarcExaZones[5];
uint16 num_foglie;
+
int16 _sarcophagusDeltaX;
bool _movingSarcophagus; // sarcophagus stuff to be saved
uint16 _freeSarcophagusSlotX; // sarcophagus stuff to be saved
@@ -544,6 +547,7 @@ private:
void initResources();
void initInventory();
void destroyInventory();
+ void setupBalloonManager();
void initFonts();
void freeFonts();
void freeLocation(bool removeAll);
diff --git a/engines/parallaction/parallaction_br.cpp b/engines/parallaction/parallaction_br.cpp
index e31fe1c7f7..9359796f2d 100644
--- a/engines/parallaction/parallaction_br.cpp
+++ b/engines/parallaction/parallaction_br.cpp
@@ -97,6 +97,7 @@ Common::Error Parallaction_br::init() {
_saveLoad = new SaveLoad_br(this, _saveFileMan);
initInventory();
+ setupBalloonManager();
Parallaction::init();
diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp
index 364123e641..d229da0d08 100644
--- a/engines/parallaction/parallaction_ns.cpp
+++ b/engines/parallaction/parallaction_ns.cpp
@@ -203,6 +203,9 @@ Common::Error Parallaction_ns::init() {
_saveLoad = new SaveLoad_ns(this, _saveFileMan);
initInventory();
+ setupBalloonManager();
+
+ _score = 1;
Parallaction::init();
diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp
index f20cb93779..70da931fbb 100644
--- a/engines/parallaction/saveload.cpp
+++ b/engines/parallaction/saveload.cpp
@@ -125,7 +125,7 @@ void SaveLoad_ns::doLoadGame(uint16 slot) {
_vm->_location._startPosition.y = atoi(s.c_str());
s = f->readLine();
- _score = atoi(s.c_str());
+ _vm->_score = atoi(s.c_str());
s = f->readLine();
_globalFlags = atoi(s.c_str());
@@ -202,7 +202,7 @@ void SaveLoad_ns::doSaveGame(uint16 slot, const char* name) {
f->writeString(s);
sprintf(s, "%d\n", _vm->_char._ani->getY());
f->writeString(s);
- sprintf(s, "%d\n", _score);
+ sprintf(s, "%d\n", _vm->_score);
f->writeString(s);
sprintf(s, "%u\n", _globalFlags);
f->writeString(s);