2009-06-08 22:18:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
#include "common/array.h"
|
2009-06-08 22:18:52 +00:00
|
|
|
#include "common/debug.h"
|
2010-11-19 17:03:07 +00:00
|
|
|
#include "common/memstream.h"
|
2009-06-10 02:59:53 +00:00
|
|
|
#include "common/stack.h"
|
2009-06-08 22:18:52 +00:00
|
|
|
|
|
|
|
#include "draci/draci.h"
|
2009-12-09 21:03:22 +00:00
|
|
|
#include "draci/animation.h"
|
|
|
|
#include "draci/barchive.h"
|
2009-07-04 14:48:36 +00:00
|
|
|
#include "draci/game.h"
|
2009-12-09 21:03:22 +00:00
|
|
|
#include "draci/mouse.h"
|
|
|
|
#include "draci/music.h"
|
|
|
|
#include "draci/screen.h"
|
|
|
|
#include "draci/script.h"
|
|
|
|
#include "draci/sound.h"
|
|
|
|
#include "draci/surface.h"
|
2009-06-08 22:18:52 +00:00
|
|
|
|
|
|
|
namespace Draci {
|
|
|
|
|
2009-07-04 14:48:36 +00:00
|
|
|
void Script::setupCommandList() {
|
|
|
|
/** A table of all the commands the game player uses */
|
|
|
|
static const GPL2Command gplCommands[] = {
|
2009-11-08 21:26:04 +00:00
|
|
|
{ 0, 0, "gplend", 0, { }, NULL },
|
|
|
|
{ 0, 1, "exit", 0, { }, NULL },
|
|
|
|
{ 1, 1, "goto", 1, { kGPL2Ident }, &Script::c_Goto },
|
|
|
|
{ 2, 1, "Let", 2, { kGPL2Ident, kGPL2Math }, &Script::c_Let },
|
|
|
|
{ 3, 1, "if", 2, { kGPL2Math, kGPL2Ident }, &Script::c_If },
|
|
|
|
{ 4, 1, "Start", 2, { kGPL2Ident, kGPL2Str }, &Script::start },
|
|
|
|
{ 5, 1, "Load", 2, { kGPL2Ident, kGPL2Str }, &Script::load },
|
|
|
|
{ 5, 2, "StartPlay", 2, { kGPL2Ident, kGPL2Str }, &Script::startPlay },
|
|
|
|
{ 5, 3, "JustTalk", 0, { }, &Script::justTalk },
|
|
|
|
{ 5, 4, "JustStay", 0, { }, &Script::justStay },
|
|
|
|
{ 6, 1, "Talk", 2, { kGPL2Ident, kGPL2Str }, &Script::talk },
|
|
|
|
{ 7, 1, "ObjStat", 2, { kGPL2Ident, kGPL2Ident }, &Script::objStat },
|
|
|
|
{ 7, 2, "ObjStat_On", 2, { kGPL2Ident, kGPL2Ident }, &Script::objStatOn },
|
|
|
|
{ 8, 1, "IcoStat", 2, { kGPL2Ident, kGPL2Ident }, &Script::icoStat },
|
|
|
|
{ 9, 1, "Dialogue", 1, { kGPL2Str }, &Script::dialogue },
|
|
|
|
{ 9, 2, "ExitDialogue", 0, { }, &Script::exitDialogue },
|
|
|
|
{ 9, 3, "ResetDialogue", 0, { }, &Script::resetDialogue },
|
|
|
|
{ 9, 4, "ResetDialogueFrom", 0, { }, &Script::resetDialogueFrom },
|
|
|
|
{ 9, 5, "ResetBlock", 1, { kGPL2Ident }, &Script::resetBlock },
|
|
|
|
{ 10, 1, "WalkOn", 3, { kGPL2Num, kGPL2Num, kGPL2Ident }, &Script::walkOn },
|
|
|
|
{ 10, 2, "StayOn", 3, { kGPL2Num, kGPL2Num, kGPL2Ident }, &Script::stayOn },
|
|
|
|
{ 10, 3, "WalkOnPlay", 3, { kGPL2Num, kGPL2Num, kGPL2Ident }, &Script::walkOnPlay },
|
|
|
|
{ 11, 1, "LoadPalette", 1, { kGPL2Str }, &Script::loadPalette },
|
|
|
|
{ 12, 1, "SetPalette", 0, { }, &Script::setPalette },
|
|
|
|
{ 12, 2, "BlackPalette", 0, { }, &Script::blackPalette },
|
|
|
|
{ 13, 1, "FadePalette", 3, { kGPL2Num, kGPL2Num, kGPL2Num }, &Script::fadePalette },
|
|
|
|
{ 13, 2, "FadePalettePlay", 3, { kGPL2Num, kGPL2Num, kGPL2Num }, &Script::fadePalettePlay },
|
|
|
|
{ 14, 1, "NewRoom", 2, { kGPL2Ident, kGPL2Num }, &Script::newRoom },
|
|
|
|
{ 15, 1, "ExecInit", 1, { kGPL2Ident }, &Script::execInit },
|
|
|
|
{ 15, 2, "ExecLook", 1, { kGPL2Ident }, &Script::execLook },
|
|
|
|
{ 15, 3, "ExecUse", 1, { kGPL2Ident }, &Script::execUse },
|
|
|
|
{ 18, 1, "LoadMusic", 1, { kGPL2Str }, &Script::loadMusic },
|
|
|
|
{ 18, 2, "StartMusic", 0, { }, &Script::startMusic },
|
|
|
|
{ 18, 3, "StopMusic", 0, { }, &Script::stopMusic },
|
|
|
|
{ 19, 1, "Mark", 0, { }, &Script::mark },
|
|
|
|
{ 19, 2, "Release", 0, { }, &Script::release },
|
|
|
|
{ 20, 1, "Play", 0, { }, &Script::play },
|
|
|
|
{ 21, 1, "LoadMap", 1, { kGPL2Str }, &Script::loadMap },
|
|
|
|
{ 21, 2, "RoomMap", 0, { }, &Script::roomMap },
|
|
|
|
{ 22, 1, "DisableQuickHero", 0, { }, &Script::disableQuickHero },
|
|
|
|
{ 22, 2, "EnableQuickHero", 0, { }, &Script::enableQuickHero },
|
|
|
|
{ 23, 1, "DisableSpeedText", 0, { }, &Script::disableSpeedText },
|
|
|
|
{ 23, 2, "EnableSpeedText", 0, { }, &Script::enableSpeedText },
|
|
|
|
{ 24, 1, "QuitGame", 0, { }, &Script::quitGame },
|
|
|
|
{ 25, 1, "PushNewRoom", 0, { }, &Script::pushNewRoom },
|
|
|
|
{ 25, 2, "PopNewRoom", 0, { }, &Script::popNewRoom },
|
2009-10-29 15:26:48 +00:00
|
|
|
// The following commands are not used in the original game files.
|
2009-11-08 21:26:04 +00:00
|
|
|
{ 16, 1, "RepaintInventory", 0, { }, NULL },
|
|
|
|
{ 16, 2, "ExitInventory", 0, { }, NULL },
|
|
|
|
{ 17, 1, "ExitMap", 0, { }, NULL },
|
|
|
|
{ 18, 4, "FadeOutMusic", 1, { kGPL2Num }, NULL },
|
|
|
|
{ 18, 5, "FadeInMusic", 1, { kGPL2Num }, NULL },
|
2009-10-11 23:28:40 +00:00
|
|
|
// The following commands are not even defined in the game
|
|
|
|
// sources, but their numbers are allocated for internal
|
|
|
|
// purposes of the old player.
|
2009-11-08 21:26:04 +00:00
|
|
|
{ 26, 1, "ShowCheat", 0, { }, NULL },
|
|
|
|
{ 26, 2, "HideCheat", 0, { }, NULL },
|
|
|
|
{ 26, 3, "ClearCheat", 1, { kGPL2Num }, NULL },
|
|
|
|
{ 27, 1, "FeedPassword", 3, { kGPL2Num, kGPL2Num, kGPL2Num }, NULL }
|
2009-07-04 14:48:36 +00:00
|
|
|
};
|
|
|
|
|
2009-07-06 17:25:34 +00:00
|
|
|
/** Operators used by the mathematical evaluator */
|
|
|
|
static const GPL2Operator gplOperators[] = {
|
2009-12-08 22:07:17 +00:00
|
|
|
{ &Script::operAnd, "&" },
|
|
|
|
{ &Script::operOr, "|" },
|
|
|
|
{ &Script::operXor, "^" },
|
|
|
|
{ &Script::operEqual, "==" },
|
|
|
|
{ &Script::operNotEqual, "!=" },
|
|
|
|
{ &Script::operLess, "<" },
|
|
|
|
{ &Script::operGreater, ">" },
|
|
|
|
{ &Script::operLessOrEqual, "<=" },
|
|
|
|
{ &Script::operGreaterOrEqual, ">=" },
|
|
|
|
{ &Script::operMul, "*" },
|
|
|
|
{ &Script::operDiv, "/" },
|
|
|
|
{ &Script::operMod, "%" },
|
|
|
|
{ &Script::operAdd, "+" },
|
|
|
|
{ &Script::operSub, "-" }
|
2009-07-06 17:25:34 +00:00
|
|
|
};
|
|
|
|
|
2009-07-06 18:49:51 +00:00
|
|
|
/** Functions used by the mathematical evaluator */
|
|
|
|
static const GPL2Function gplFunctions[] = {
|
2009-12-08 22:07:17 +00:00
|
|
|
{ &Script::funcNot, "Not" },
|
|
|
|
{ &Script::funcRandom, "Random" },
|
|
|
|
{ &Script::funcIsIcoOn, "IsIcoOn" },
|
|
|
|
{ &Script::funcIsIcoAct, "IsIcoAct" },
|
|
|
|
{ &Script::funcIcoStat, "IcoStat" },
|
|
|
|
{ &Script::funcActIco, "ActIco" },
|
|
|
|
{ &Script::funcIsObjOn, "IsObjOn" },
|
|
|
|
{ &Script::funcIsObjOff, "IsObjOff" },
|
|
|
|
{ &Script::funcIsObjAway, "IsObjAway" },
|
|
|
|
{ &Script::funcObjStat, "ObjStat" },
|
|
|
|
{ &Script::funcLastBlock, "LastBlock" },
|
|
|
|
{ &Script::funcAtBegin, "AtBegin" },
|
|
|
|
{ &Script::funcBlockVar, "BlockVar" },
|
|
|
|
{ &Script::funcHasBeen, "HasBeen" },
|
|
|
|
{ &Script::funcMaxLine, "MaxLine" },
|
|
|
|
{ &Script::funcActPhase, "ActPhase" },
|
2009-11-03 21:34:38 +00:00
|
|
|
// The following function is not even defined in the game
|
|
|
|
// sources, but its number is allocated for internal purposes
|
|
|
|
// of the old player.
|
2009-12-08 22:07:17 +00:00
|
|
|
{ NULL, "Cheat" },
|
2009-07-06 18:49:51 +00:00
|
|
|
};
|
|
|
|
|
2009-07-04 14:48:36 +00:00
|
|
|
_commandList = gplCommands;
|
2009-07-06 17:25:34 +00:00
|
|
|
_operatorList = gplOperators;
|
2009-07-06 18:49:51 +00:00
|
|
|
_functionList = gplFunctions;
|
2009-07-04 14:48:36 +00:00
|
|
|
}
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-06-12 09:45:12 +00:00
|
|
|
/** Type of mathematical object */
|
2009-06-10 02:59:53 +00:00
|
|
|
enum mathExpressionObject {
|
|
|
|
kMathEnd,
|
|
|
|
kMathNumber,
|
|
|
|
kMathOperator,
|
|
|
|
kMathFunctionCall,
|
|
|
|
kMathVariable
|
|
|
|
};
|
|
|
|
|
2009-07-06 17:25:34 +00:00
|
|
|
/* GPL operators */
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operAnd(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 & op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operOr(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 | op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operXor(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 ^ op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operEqual(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 == op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operNotEqual(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 != op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operLess(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 < op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operGreater(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 > op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operGreaterOrEqual(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 >= op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operLessOrEqual(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 <= op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operMul(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 * op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operAdd(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 + op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operSub(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 - op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operDiv(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 / op2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::operMod(int op1, int op2) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
return op1 % op2;
|
|
|
|
}
|
|
|
|
|
2009-07-06 19:26:53 +00:00
|
|
|
/* GPL functions */
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcRandom(int n) const {
|
2009-07-06 19:26:53 +00:00
|
|
|
// The function needs to return numbers in the [0..n-1] range so we need to deduce 1
|
|
|
|
// (RandomSource::getRandomNumber returns a number in the range [0..n])
|
|
|
|
|
|
|
|
n -= 1;
|
|
|
|
return _vm->_rnd.getRandomNumber(n);
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcAtBegin(int yesno) const {
|
2009-09-25 07:06:55 +00:00
|
|
|
return _vm->_game->isDialogueBegin() == (bool)yesno;
|
2009-09-30 10:45:14 +00:00
|
|
|
}
|
2009-08-11 04:03:22 +00:00
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcLastBlock(int blockID) const {
|
2009-08-12 07:34:31 +00:00
|
|
|
blockID -= 1;
|
2009-08-11 04:03:22 +00:00
|
|
|
|
2009-08-17 19:37:55 +00:00
|
|
|
return _vm->_game->getDialogueLastBlock() == blockID;
|
2009-08-11 04:03:22 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcBlockVar(int blockID) const {
|
2009-08-12 07:34:31 +00:00
|
|
|
blockID -= 1;
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-08-17 19:37:55 +00:00
|
|
|
const int currentOffset = _vm->_game->getCurrentDialogueOffset();
|
|
|
|
return _vm->_game->getDialogueVar(currentOffset + blockID);
|
2009-08-11 04:03:22 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcHasBeen(int blockID) const {
|
2009-08-12 07:34:31 +00:00
|
|
|
blockID -= 1;
|
|
|
|
|
2009-08-17 19:37:55 +00:00
|
|
|
const int currentOffset = _vm->_game->getCurrentDialogueOffset();
|
|
|
|
return _vm->_game->getDialogueVar(currentOffset + blockID) > 0;
|
2009-08-11 04:03:22 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcMaxLine(int lines) const {
|
2009-08-17 19:37:55 +00:00
|
|
|
return _vm->_game->getDialogueLinesNum() < lines;
|
2009-08-11 04:03:22 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcNot(int n) const {
|
2009-07-07 21:24:39 +00:00
|
|
|
return !n;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcIsIcoOn(int itemID) const {
|
2009-08-17 18:50:38 +00:00
|
|
|
itemID -= 1;
|
2009-07-13 19:53:53 +00:00
|
|
|
|
2009-08-17 18:50:38 +00:00
|
|
|
return _vm->_game->getItemStatus(itemID) == 1;
|
2009-09-30 16:04:21 +00:00
|
|
|
}
|
2009-07-13 19:53:53 +00:00
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcIcoStat(int itemID) const {
|
2009-08-17 18:50:38 +00:00
|
|
|
itemID -= 1;
|
2009-07-13 19:53:53 +00:00
|
|
|
|
2009-08-17 18:50:38 +00:00
|
|
|
int status = _vm->_game->getItemStatus(itemID);
|
2009-07-13 19:53:53 +00:00
|
|
|
return (status == 1) ? 1 : 2;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcIsIcoAct(int itemID) const {
|
2009-08-17 18:50:38 +00:00
|
|
|
itemID -= 1;
|
2009-08-09 04:12:36 +00:00
|
|
|
|
2009-11-12 03:09:15 +00:00
|
|
|
return _vm->_game->getCurrentItem() == _vm->_game->getItem(itemID);
|
2009-08-09 04:12:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcActIco(int itemID) const {
|
2009-08-09 04:12:36 +00:00
|
|
|
// The parameter seems to be an omission in the original player since it's not
|
|
|
|
// used in the implementation of the function. It's possible that the functions were
|
|
|
|
// implemented in such a way that they had to have a single parameter so this is only
|
|
|
|
// passed as a dummy.
|
|
|
|
|
2009-11-10 05:16:34 +00:00
|
|
|
const GameItem *item = _vm->_game->getCurrentItem();
|
|
|
|
return item ? item->_absNum + 1 : 0;
|
2009-08-09 04:12:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcIsObjOn(int objID) const {
|
2009-07-13 19:53:53 +00:00
|
|
|
objID -= 1;
|
|
|
|
|
2009-09-28 04:09:03 +00:00
|
|
|
const GameObject *obj = _vm->_game->getObject(objID);
|
2009-07-13 19:53:53 +00:00
|
|
|
|
|
|
|
return obj->_visible;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcIsObjOff(int objID) const {
|
2009-07-13 19:53:53 +00:00
|
|
|
objID -= 1;
|
|
|
|
|
2009-09-28 04:09:03 +00:00
|
|
|
const GameObject *obj = _vm->_game->getObject(objID);
|
2009-07-13 19:53:53 +00:00
|
|
|
|
|
|
|
// We index locations from 0 (as opposed to the original player where it was from 1)
|
2009-07-25 02:23:00 +00:00
|
|
|
// That's why the "away" location 0 from the data files is converted to -1
|
2009-07-13 19:53:53 +00:00
|
|
|
return !obj->_visible && obj->_location != -1;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcObjStat(int objID) const {
|
2009-08-09 16:58:04 +00:00
|
|
|
objID -= 1;
|
|
|
|
|
2009-09-28 04:09:03 +00:00
|
|
|
const GameObject *obj = _vm->_game->getObject(objID);
|
2009-08-09 16:58:04 +00:00
|
|
|
|
|
|
|
if (obj->_location == _vm->_game->getRoomNum()) {
|
|
|
|
if (obj->_visible) {
|
2009-09-30 10:45:14 +00:00
|
|
|
return 1; // object is ON (in the room and visible)
|
2009-08-09 16:58:04 +00:00
|
|
|
} else {
|
2009-09-30 10:45:14 +00:00
|
|
|
return 2; // object is OFF (in the room, not visible)
|
2009-08-09 16:58:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-09-30 10:45:14 +00:00
|
|
|
return 3; // object is AWAY (not in the room)
|
2009-08-09 16:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcIsObjAway(int objID) const {
|
2009-07-13 19:53:53 +00:00
|
|
|
objID -= 1;
|
|
|
|
|
2009-09-28 04:09:03 +00:00
|
|
|
const GameObject *obj = _vm->_game->getObject(objID);
|
2009-07-13 19:53:53 +00:00
|
|
|
|
|
|
|
// see Script::funcIsObjOff
|
|
|
|
return !obj->_visible && obj->_location == -1;
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:13:39 +00:00
|
|
|
int Script::funcActPhase(int objID) const {
|
2009-09-30 10:45:14 +00:00
|
|
|
objID -= 1;
|
2009-07-29 01:02:50 +00:00
|
|
|
|
|
|
|
// Default return value
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-28 04:09:03 +00:00
|
|
|
const GameObject *obj = _vm->_game->getObject(objID);
|
2009-07-29 01:02:50 +00:00
|
|
|
|
2009-11-22 05:10:31 +00:00
|
|
|
const bool visible = (obj->_location == _vm->_game->getRoomNum() && obj->_visible);
|
2009-07-29 20:41:53 +00:00
|
|
|
if (objID == kDragonObject || visible) {
|
2009-11-10 05:16:34 +00:00
|
|
|
const int i = obj->playingAnim();
|
2009-10-12 01:16:13 +00:00
|
|
|
if (i >= 0) {
|
2009-11-10 05:16:34 +00:00
|
|
|
Animation *anim = obj->_anim[i];
|
2009-10-12 01:16:13 +00:00
|
|
|
ret = anim->currentFrameNum();
|
2009-10-12 00:39:49 +00:00
|
|
|
}
|
2009-07-29 01:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-06 17:25:34 +00:00
|
|
|
/* GPL commands */
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::play(const Common::Array<int> ¶ms) {
|
2009-07-29 19:41:30 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-01 23:04:56 +00:00
|
|
|
// Runs just one phase of the loop and exits. Used when waiting for a
|
|
|
|
// particular animation phase to come.
|
2009-11-02 02:28:43 +00:00
|
|
|
_vm->_game->loop(kInnerUntilExit, true);
|
2009-07-29 01:02:50 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::load(const Common::Array<int> ¶ms) {
|
2009-07-25 03:28:04 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int objID = params[0] - 1;
|
|
|
|
int animID = params[1] - 1;
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-07-29 01:02:50 +00:00
|
|
|
// If the animation is already loaded, return
|
2009-11-10 05:16:34 +00:00
|
|
|
GameObject *obj = _vm->_game->getObject(objID);
|
|
|
|
if (obj->getAnim(animID) >= 0) {
|
|
|
|
return;
|
2009-07-29 01:02:50 +00:00
|
|
|
}
|
|
|
|
|
2009-11-07 00:36:23 +00:00
|
|
|
// We don't test here whether an animation is loaded in the
|
|
|
|
// AnimationManager while not being registered in the object's array of
|
|
|
|
// animations. This cannot legally happen and an assertion will be
|
2009-11-10 05:16:34 +00:00
|
|
|
// thrown by AnimationManager::load().
|
|
|
|
obj->addAnim(_vm->_anims->load(animID));
|
2009-07-04 18:36:45 +00:00
|
|
|
}
|
2009-06-12 09:45:12 +00:00
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::start(const Common::Array<int> ¶ms) {
|
2009-07-25 03:28:04 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int objID = params[0] - 1;
|
|
|
|
int animID = params[1] - 1;
|
2009-07-06 17:27:12 +00:00
|
|
|
|
2009-10-04 22:55:54 +00:00
|
|
|
GameObject *obj = _vm->_game->getObject(objID);
|
2009-11-10 05:16:34 +00:00
|
|
|
obj->stopAnim();
|
2009-07-29 19:41:30 +00:00
|
|
|
|
2009-11-10 05:16:34 +00:00
|
|
|
int index = obj->getAnim(animID);
|
|
|
|
if (index < 0) {
|
2009-11-08 21:35:19 +00:00
|
|
|
// WORKAROUND:
|
|
|
|
//
|
2009-10-04 22:55:54 +00:00
|
|
|
// The original game files seem to contain errors, which I have
|
|
|
|
// verified by inspecting their source code. They try to load
|
|
|
|
// each animation before starting it, but fail to anticipate
|
|
|
|
// all possible code paths when game loading comes into play.
|
|
|
|
//
|
|
|
|
// In particular, if I load the game at the stump location,
|
|
|
|
// apply a hedgehog on them, and then talk to them, one of the
|
|
|
|
// animations is not loaded. This animation would have been
|
|
|
|
// loaded had I talked to them before applying the hedgehog
|
|
|
|
// (because a different dialog init code is run before the
|
|
|
|
// application). Talking to the stumps is necessary to be able
|
|
|
|
// to apply the hedgehog, so normal game-play is safe.
|
|
|
|
// However, if I save the game after talking to them and load
|
|
|
|
// it later, then the game variables are set so as to allow me
|
|
|
|
// to apply the hedgehog, but there is no way that the game
|
|
|
|
// player would load the requested animation by itself.
|
|
|
|
// See objekty:5077 and parezy.txt:27.
|
2009-11-10 05:16:34 +00:00
|
|
|
index = obj->addAnim(_vm->_anims->load(animID));
|
2009-10-04 22:55:54 +00:00
|
|
|
debugC(1, kDraciBytecodeDebugLevel, "start(%d=%s) cannot find animation %d. Loading.",
|
|
|
|
objID, obj->_title.c_str(), animID);
|
|
|
|
}
|
2009-11-10 05:16:34 +00:00
|
|
|
Animation *anim = obj->_anim[index];
|
|
|
|
anim->registerCallback(&Animation::stop);
|
2009-07-29 19:41:30 +00:00
|
|
|
|
2009-11-22 05:10:31 +00:00
|
|
|
if (objID == kDragonObject) {
|
|
|
|
_vm->_game->playHeroAnimation(index);
|
|
|
|
} else {
|
|
|
|
const bool visible = (obj->_location == _vm->_game->getRoomNum() && obj->_visible);
|
|
|
|
if (visible) {
|
|
|
|
obj->playAnim(index);
|
|
|
|
}
|
2009-07-29 19:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::startPlay(const Common::Array<int> ¶ms) {
|
2009-07-29 19:41:30 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int objID = params[0] - 1;
|
|
|
|
int animID = params[1] - 1;
|
2009-07-29 19:41:30 +00:00
|
|
|
|
2009-10-04 22:55:54 +00:00
|
|
|
GameObject *obj = _vm->_game->getObject(objID);
|
2009-11-10 05:16:34 +00:00
|
|
|
obj->stopAnim();
|
2009-07-29 19:41:30 +00:00
|
|
|
|
2009-11-10 05:16:34 +00:00
|
|
|
int index = obj->getAnim(animID);
|
|
|
|
if (index < 0) {
|
|
|
|
index = obj->addAnim(_vm->_anims->load(animID));
|
2009-10-04 22:55:54 +00:00
|
|
|
debugC(1, kDraciBytecodeDebugLevel, "startPlay(%d=%s) cannot find animation %d. Loading.",
|
|
|
|
objID, obj->_title.c_str(), animID);
|
|
|
|
}
|
2009-11-10 05:16:34 +00:00
|
|
|
Animation *anim = obj->_anim[index];
|
2009-09-30 10:45:14 +00:00
|
|
|
anim->registerCallback(&Animation::exitGameLoop);
|
2009-07-29 19:41:30 +00:00
|
|
|
|
2009-11-22 05:10:31 +00:00
|
|
|
if (objID == kDragonObject) {
|
|
|
|
_vm->_game->playHeroAnimation(index);
|
|
|
|
} else {
|
|
|
|
const bool visible = (obj->_location == _vm->_game->getRoomNum() && obj->_visible);
|
|
|
|
if (visible) {
|
|
|
|
obj->playAnim(index);
|
|
|
|
}
|
2009-09-30 10:45:14 +00:00
|
|
|
}
|
2009-07-29 20:41:53 +00:00
|
|
|
|
2009-11-01 23:04:56 +00:00
|
|
|
// Runs an inner loop until the animation ends.
|
2009-11-02 02:28:43 +00:00
|
|
|
_vm->_game->loop(kInnerUntilExit, false);
|
2009-11-10 05:16:34 +00:00
|
|
|
obj->stopAnim();
|
2009-07-29 19:41:30 +00:00
|
|
|
|
|
|
|
anim->registerCallback(&Animation::doNothing);
|
2009-07-06 17:27:12 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::justTalk(const Common::Array<int> ¶ms) {
|
2009-10-12 01:16:13 +00:00
|
|
|
const GameObject *dragon = _vm->_game->getObject(kDragonObject);
|
2009-11-10 05:16:34 +00:00
|
|
|
const int last_anim = static_cast<Movement> (dragon->playingAnim());
|
|
|
|
const int new_anim = (last_anim == kSpeakRight || last_anim == kStopRight) ? kSpeakRight : kSpeakLeft;
|
2009-10-12 03:08:28 +00:00
|
|
|
_vm->_game->playHeroAnimation(new_anim);
|
2009-10-12 01:16:13 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::justStay(const Common::Array<int> ¶ms) {
|
2009-10-12 01:16:13 +00:00
|
|
|
const GameObject *dragon = _vm->_game->getObject(kDragonObject);
|
2009-11-10 05:16:34 +00:00
|
|
|
const int last_anim = static_cast<Movement> (dragon->playingAnim());
|
|
|
|
const int new_anim = (last_anim == kSpeakRight || last_anim == kStopRight) ? kStopRight : kStopLeft;
|
2009-10-12 03:08:28 +00:00
|
|
|
_vm->_game->playHeroAnimation(new_anim);
|
2009-10-12 01:16:13 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::c_If(const Common::Array<int> ¶ms) {
|
|
|
|
int expression = params[0];
|
|
|
|
int jump = params[1];
|
2009-07-08 00:34:53 +00:00
|
|
|
|
|
|
|
if (expression)
|
|
|
|
_jump = jump;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::c_Goto(const Common::Array<int> ¶ms) {
|
|
|
|
int jump = params[0];
|
2009-07-08 00:34:53 +00:00
|
|
|
|
|
|
|
_jump = jump;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::c_Let(const Common::Array<int> ¶ms) {
|
|
|
|
int var = params[0] - 1;
|
|
|
|
int value = params[1];
|
2009-07-08 00:34:53 +00:00
|
|
|
|
|
|
|
_vm->_game->setVariable(var, value);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::loadMusic(const Common::Array<int> ¶ms) {
|
|
|
|
int track = params[0];
|
2009-10-22 07:34:43 +00:00
|
|
|
_vm->_game->setMusicTrack(track);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::startMusic(const Common::Array<int> ¶ms) {
|
2009-10-22 07:34:43 +00:00
|
|
|
// If already playing this track, nothing happens.
|
|
|
|
_vm->_music->playSMF(_vm->_game->getMusicTrack(), true);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::stopMusic(const Common::Array<int> ¶ms) {
|
2009-10-22 07:34:43 +00:00
|
|
|
_vm->_music->stop();
|
|
|
|
_vm->_game->setMusicTrack(0);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::mark(const Common::Array<int> ¶ms) {
|
2009-07-24 05:00:53 +00:00
|
|
|
_vm->_game->setMarkedAnimationIndex(_vm->_anims->getLastIndex());
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::release(const Common::Array<int> ¶ms) {
|
2009-07-24 05:00:53 +00:00
|
|
|
int markedIndex = _vm->_game->getMarkedAnimationIndex();
|
|
|
|
|
2009-10-11 23:54:44 +00:00
|
|
|
_vm->_game->deleteAnimationsAfterIndex(markedIndex);
|
2009-07-24 05:00:53 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::icoStat(const Common::Array<int> ¶ms) {
|
|
|
|
int status = params[0];
|
|
|
|
int itemID = params[1] - 1;
|
2009-11-10 05:16:34 +00:00
|
|
|
GameItem *item = _vm->_game->getItem(itemID);
|
2009-08-17 18:50:38 +00:00
|
|
|
|
|
|
|
_vm->_game->setItemStatus(itemID, status == 1);
|
|
|
|
|
2009-11-12 03:09:15 +00:00
|
|
|
if (!_vm->_game->getItemStatus(itemID)) {
|
|
|
|
// Remove the item from the inventory and release its animations.
|
2009-11-10 05:16:34 +00:00
|
|
|
_vm->_game->removeItem(item);
|
2009-11-12 03:09:15 +00:00
|
|
|
item->_anim->del();
|
|
|
|
item->_anim = NULL;
|
2009-08-17 18:50:38 +00:00
|
|
|
|
2009-11-12 03:09:15 +00:00
|
|
|
// If the item was in the hand, remove it from the hands and,
|
|
|
|
// if the cursor was set to this item (as opposed to, say, an
|
|
|
|
// arrow leading outside a location), set it to standard.
|
2009-11-10 05:16:34 +00:00
|
|
|
if (_vm->_game->getCurrentItem() == item) {
|
|
|
|
_vm->_game->setCurrentItem(NULL);
|
2010-06-28 04:04:16 +00:00
|
|
|
_vm->_game->setPreviousItemPosition(-1);
|
2009-11-12 03:09:15 +00:00
|
|
|
if (_vm->_mouse->getCursorType() >= kItemCursor) {
|
|
|
|
_vm->_mouse->setCursorType(kNormalCursor);
|
2009-08-17 18:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 03:09:15 +00:00
|
|
|
} else {
|
|
|
|
_vm->_game->loadItemAnimation(item);
|
2009-11-10 05:16:34 +00:00
|
|
|
_vm->_game->setCurrentItem(item);
|
2010-06-28 04:04:16 +00:00
|
|
|
_vm->_game->setPreviousItemPosition(0); // next time, try to place the item from the beginning
|
2009-11-10 05:16:34 +00:00
|
|
|
_vm->_mouse->loadItemCursor(item, false);
|
2009-08-17 18:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::objStatOn(const Common::Array<int> ¶ms) {
|
|
|
|
int objID = params[0] - 1;
|
|
|
|
int roomID = params[1] - 1;
|
2009-07-25 02:23:00 +00:00
|
|
|
|
|
|
|
GameObject *obj = _vm->_game->getObject(objID);
|
|
|
|
|
|
|
|
obj->_location = roomID;
|
|
|
|
obj->_visible = true;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::objStat(const Common::Array<int> ¶ms) {
|
|
|
|
int status = params[0];
|
|
|
|
int objID = params[1] - 1;
|
2009-07-25 02:23:00 +00:00
|
|
|
|
|
|
|
GameObject *obj = _vm->_game->getObject(objID);
|
|
|
|
|
|
|
|
if (status == 1) {
|
|
|
|
return;
|
|
|
|
} else if (status == 2) {
|
|
|
|
obj->_visible = false;
|
|
|
|
} else {
|
|
|
|
obj->_visible = false;
|
|
|
|
obj->_location = -1;
|
|
|
|
}
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-11-10 05:16:34 +00:00
|
|
|
obj->stopAnim();
|
2009-07-25 02:23:00 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::execInit(const Common::Array<int> ¶ms) {
|
2009-07-25 03:37:22 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int objID = params[0] - 1;
|
2009-07-25 03:37:22 +00:00
|
|
|
|
2009-09-28 04:09:03 +00:00
|
|
|
const GameObject *obj = _vm->_game->getObject(objID);
|
2009-07-25 03:37:22 +00:00
|
|
|
run(obj->_program, obj->_init);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::execLook(const Common::Array<int> ¶ms) {
|
2009-07-25 03:37:22 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int objID = params[0] - 1;
|
2009-07-25 03:37:22 +00:00
|
|
|
|
2009-09-28 04:09:03 +00:00
|
|
|
const GameObject *obj = _vm->_game->getObject(objID);
|
2009-11-12 00:45:28 +00:00
|
|
|
|
|
|
|
// We don't have to use runWrapper(), because the has already been
|
|
|
|
// wrapped due to the fact that these commands are only run from a GPL2
|
|
|
|
// program but never from the core player.
|
2009-07-25 03:37:22 +00:00
|
|
|
run(obj->_program, obj->_look);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::execUse(const Common::Array<int> ¶ms) {
|
2009-07-25 03:37:22 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int objID = params[0] - 1;
|
2009-07-25 03:37:22 +00:00
|
|
|
|
2009-09-28 04:09:03 +00:00
|
|
|
const GameObject *obj = _vm->_game->getObject(objID);
|
2009-07-25 03:37:22 +00:00
|
|
|
run(obj->_program, obj->_use);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::stayOn(const Common::Array<int> ¶ms) {
|
2009-11-03 21:30:24 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int x = params[0];
|
|
|
|
int y = params[1];
|
|
|
|
SightDirection dir = static_cast<SightDirection> (params[2]);
|
2009-11-03 21:30:24 +00:00
|
|
|
|
|
|
|
// Jumps into the given position regardless of the walking map.
|
2009-11-07 11:45:13 +00:00
|
|
|
Common::Point heroPos(_vm->_game->findNearestWalkable(x, y));
|
|
|
|
Common::Point mousePos(_vm->_mouse->getPosX(), _vm->_mouse->getPosY());
|
2009-11-08 03:16:22 +00:00
|
|
|
const GameObject *dragon = _vm->_game->getObject(kDragonObject);
|
2009-11-10 05:16:34 +00:00
|
|
|
Movement startingDirection = static_cast<Movement> (dragon->playingAnim());
|
2009-11-07 11:45:13 +00:00
|
|
|
|
2009-11-04 00:42:37 +00:00
|
|
|
_vm->_game->stopWalking();
|
2009-11-07 11:45:13 +00:00
|
|
|
_vm->_game->setHeroPosition(heroPos);
|
|
|
|
_vm->_game->playHeroAnimation(WalkingState::animationForSightDirection(
|
2009-11-08 03:16:22 +00:00
|
|
|
dir, heroPos, mousePos, WalkingPath(), startingDirection));
|
2009-11-03 21:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::walkOn(const Common::Array<int> ¶ms) {
|
2009-07-25 04:36:43 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int x = params[0];
|
|
|
|
int y = params[1];
|
|
|
|
SightDirection dir = static_cast<SightDirection> (params[2]);
|
2009-07-25 04:36:43 +00:00
|
|
|
|
2009-11-03 21:30:24 +00:00
|
|
|
// Constructs an optimal path and starts walking there. No callback
|
|
|
|
// will be called at the end nor will the loop-body exit.
|
2009-11-04 00:42:37 +00:00
|
|
|
_vm->_game->stopWalking();
|
2009-10-12 03:08:28 +00:00
|
|
|
_vm->_game->walkHero(x, y, dir);
|
2009-07-25 04:36:43 +00:00
|
|
|
}
|
2009-07-31 04:32:33 +00:00
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::walkOnPlay(const Common::Array<int> ¶ms) {
|
2009-08-11 04:18:14 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int x = params[0];
|
|
|
|
int y = params[1];
|
|
|
|
SightDirection dir = static_cast<SightDirection> (params[2]);
|
2009-08-11 04:18:14 +00:00
|
|
|
|
2009-11-04 00:42:37 +00:00
|
|
|
_vm->_game->stopWalking();
|
2009-10-12 03:08:28 +00:00
|
|
|
_vm->_game->walkHero(x, y, dir);
|
2009-08-11 04:18:14 +00:00
|
|
|
|
2009-11-04 00:42:37 +00:00
|
|
|
// Walk in an inner loop until the hero has arrived at the target
|
|
|
|
// point. Then the loop-body will exit.
|
|
|
|
_vm->_game->loop(kInnerUntilExit, false);
|
2009-08-11 04:18:14 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::newRoom(const Common::Array<int> ¶ms) {
|
2009-07-31 04:32:33 +00:00
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
int room = params[0] - 1;
|
|
|
|
int gate = params[1] - 1;
|
2009-07-31 04:32:33 +00:00
|
|
|
|
2009-10-01 08:32:35 +00:00
|
|
|
_vm->_game->scheduleEnteringRoomUsingGate(room, gate);
|
2009-07-31 04:32:33 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::talk(const Common::Array<int> ¶ms) {
|
|
|
|
int personID = params[0] - 1;
|
|
|
|
int sentenceID = params[1] - 1;
|
2009-08-02 05:12:42 +00:00
|
|
|
|
2009-08-04 19:09:41 +00:00
|
|
|
Surface *surface = _vm->_screen->getSurface();
|
|
|
|
|
2009-08-02 05:12:42 +00:00
|
|
|
// Fetch string
|
2009-09-28 03:51:23 +00:00
|
|
|
const BAFile *f = _vm->_stringsArchive->getFile(sentenceID);
|
2009-08-02 05:12:42 +00:00
|
|
|
|
|
|
|
// Fetch frame for the speech text
|
|
|
|
Animation *speechAnim = _vm->_anims->getAnimation(kSpeechText);
|
2009-10-30 01:56:52 +00:00
|
|
|
Text *speechFrame = reinterpret_cast<Text *>(speechAnim->getCurrentFrame());
|
2009-08-02 05:12:42 +00:00
|
|
|
|
|
|
|
// Fetch person info
|
2009-09-25 08:13:39 +00:00
|
|
|
const Person *person = _vm->_game->getPerson(personID);
|
2009-08-02 05:12:42 +00:00
|
|
|
|
2009-10-13 05:38:45 +00:00
|
|
|
// Fetch the dubbing
|
|
|
|
SoundSample *sample = _vm->_sound->isMutedVoice()
|
|
|
|
? NULL : _vm->_dubbingArchive->getSample(sentenceID, 0);
|
|
|
|
|
2011-04-14 12:12:27 +00:00
|
|
|
// Set the string and text color
|
2009-10-30 01:41:57 +00:00
|
|
|
surface->markDirtyRect(speechFrame->getRect(kNoDisplacement));
|
2009-10-13 05:38:45 +00:00
|
|
|
if (_vm->_sound->showSubtitles() || !sample) {
|
|
|
|
speechFrame->setText(Common::String((const char *)f->_data+1, f->_length-1));
|
|
|
|
} else {
|
|
|
|
speechFrame->setText("");
|
|
|
|
}
|
2011-04-14 12:12:27 +00:00
|
|
|
speechFrame->setColor(person->_fontColor);
|
2009-11-23 06:44:40 +00:00
|
|
|
speechFrame->repeatedlySplitLongLines(kScreenWidth);
|
2009-08-09 04:12:36 +00:00
|
|
|
|
2009-10-13 04:44:22 +00:00
|
|
|
// Speak the dubbing if possible
|
|
|
|
uint dubbingDuration = 0;
|
|
|
|
if (sample) {
|
2010-07-03 05:05:28 +00:00
|
|
|
dubbingDuration = _vm->_sound->playVoice(sample);
|
2009-10-13 04:44:22 +00:00
|
|
|
debugC(3, kDraciSoundDebugLevel, "Playing sentence %d: %d+%d with duration %dms",
|
|
|
|
sentenceID, sample->_offset, sample->_length, dubbingDuration);
|
2010-07-03 05:05:28 +00:00
|
|
|
dubbingDuration += 500;
|
2009-10-13 04:44:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 05:12:42 +00:00
|
|
|
// Record time
|
2009-10-29 15:26:48 +00:00
|
|
|
int talkSpeed = _vm->_sound->talkSpeed();
|
|
|
|
if (!_vm->_game->getEnableSpeedText() && talkSpeed > kStandardSpeed) {
|
|
|
|
talkSpeed = kStandardSpeed;
|
|
|
|
}
|
|
|
|
if (talkSpeed <= 0) {
|
|
|
|
talkSpeed = 1;
|
|
|
|
}
|
|
|
|
uint subtitleDuration;
|
|
|
|
if (talkSpeed >= 255) {
|
|
|
|
subtitleDuration = 0;
|
|
|
|
} else {
|
|
|
|
subtitleDuration = (kBaseSpeechDuration + speechFrame->getLength() * kSpeechTimeUnit) / talkSpeed;
|
|
|
|
}
|
2009-10-13 05:38:45 +00:00
|
|
|
const uint duration = MAX(subtitleDuration, dubbingDuration);
|
2009-10-13 04:44:22 +00:00
|
|
|
_vm->_game->setSpeechTiming(_vm->_system->getMillis(), duration);
|
2009-08-02 05:12:42 +00:00
|
|
|
|
|
|
|
// Set speech text coordinates
|
2009-11-12 00:57:38 +00:00
|
|
|
int x, y;
|
|
|
|
if (_vm->_game->getLoopStatus() == kStatusInventory) {
|
|
|
|
x = surface->centerOnX(160, speechFrame->getWidth());
|
|
|
|
y = 4;
|
|
|
|
} else {
|
|
|
|
x = surface->centerOnX(person->_x, speechFrame->getWidth());
|
|
|
|
y = surface->putAboveY(person->_y, speechFrame->getHeight());
|
|
|
|
}
|
2009-08-02 05:12:42 +00:00
|
|
|
|
2009-08-04 19:09:41 +00:00
|
|
|
speechFrame->setX(x);
|
|
|
|
speechFrame->setY(y);
|
2009-08-02 05:12:42 +00:00
|
|
|
|
2009-11-01 23:04:56 +00:00
|
|
|
// Call the game loop to enable interactivity until the text expires.
|
2009-11-02 02:28:43 +00:00
|
|
|
_vm->_game->loop(kInnerWhileTalk, false);
|
2009-08-02 05:12:42 +00:00
|
|
|
|
|
|
|
// Delete the text
|
2009-10-30 01:41:57 +00:00
|
|
|
_vm->_screen->getSurface()->markDirtyRect(speechFrame->getRect(kNoDisplacement));
|
2009-08-02 05:12:42 +00:00
|
|
|
speechFrame->setText("");
|
|
|
|
|
2009-10-13 04:44:22 +00:00
|
|
|
// Stop the playing sample and deallocate it. Stopping should only be
|
|
|
|
// necessary if the user interrupts the playback.
|
|
|
|
if (sample) {
|
|
|
|
_vm->_sound->stopVoice();
|
|
|
|
sample->close();
|
|
|
|
}
|
2009-08-02 05:12:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::dialogue(const Common::Array<int> ¶ms) {
|
|
|
|
int dialogueID = params[0] - 1;
|
2009-08-11 04:03:22 +00:00
|
|
|
|
|
|
|
_vm->_game->dialogueMenu(dialogueID);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::loadMap(const Common::Array<int> ¶ms) {
|
|
|
|
int mapID = params[0] - 1;
|
2009-08-09 04:12:36 +00:00
|
|
|
|
|
|
|
_vm->_game->loadWalkingMap(mapID);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::resetDialogue(const Common::Array<int> ¶ms) {
|
2009-08-17 19:37:55 +00:00
|
|
|
const int currentOffset = _vm->_game->getCurrentDialogueOffset();
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-08-17 19:37:55 +00:00
|
|
|
for (int i = 0; i < _vm->_game->getDialogueBlockNum(); ++i) {
|
|
|
|
_vm->_game->setDialogueVar(currentOffset + i, 0);
|
2009-08-11 04:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::resetDialogueFrom(const Common::Array<int> ¶ms) {
|
2009-08-17 19:37:55 +00:00
|
|
|
const int currentOffset = _vm->_game->getCurrentDialogueOffset();
|
|
|
|
|
|
|
|
for (int i = _vm->_game->getDialogueCurrentBlock(); i < _vm->_game->getDialogueBlockNum(); ++i) {
|
|
|
|
_vm->_game->setDialogueVar(currentOffset + i, 0);
|
2009-08-11 04:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::resetBlock(const Common::Array<int> ¶ms) {
|
|
|
|
int blockID = params[0] - 1;
|
2009-08-11 04:03:22 +00:00
|
|
|
|
2009-08-17 19:37:55 +00:00
|
|
|
const int currentOffset = _vm->_game->getCurrentDialogueOffset();
|
|
|
|
|
|
|
|
_vm->_game->setDialogueVar(currentOffset + blockID, 0);
|
2009-08-11 04:03:22 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::exitDialogue(const Common::Array<int> ¶ms) {
|
2009-08-17 19:37:55 +00:00
|
|
|
_vm->_game->setDialogueExit(true);
|
2009-08-11 04:03:22 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::roomMap(const Common::Array<int> ¶ms) {
|
2009-08-09 04:12:36 +00:00
|
|
|
// Load the default walking map for the room
|
2009-10-30 02:15:41 +00:00
|
|
|
_vm->_game->loadWalkingMap(_vm->_game->getMapID());
|
2009-08-09 04:12:36 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::disableQuickHero(const Common::Array<int> ¶ms) {
|
2009-10-29 15:26:48 +00:00
|
|
|
_vm->_game->setEnableQuickHero(false);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::enableQuickHero(const Common::Array<int> ¶ms) {
|
2009-10-29 15:26:48 +00:00
|
|
|
_vm->_game->setEnableQuickHero(true);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::disableSpeedText(const Common::Array<int> ¶ms) {
|
2009-10-29 15:26:48 +00:00
|
|
|
_vm->_game->setEnableSpeedText(false);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::enableSpeedText(const Common::Array<int> ¶ms) {
|
2009-10-29 15:26:48 +00:00
|
|
|
_vm->_game->setEnableSpeedText(true);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::loadPalette(const Common::Array<int> ¶ms) {
|
|
|
|
int palette = params[0] - 1;
|
2009-08-15 02:42:34 +00:00
|
|
|
|
|
|
|
_vm->_game->schedulePalette(palette);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::blackPalette(const Common::Array<int> ¶ms) {
|
2009-08-15 02:42:34 +00:00
|
|
|
|
|
|
|
_vm->_game->schedulePalette(kBlackPalette);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::fadePalette(const Common::Array<int> ¶ms) {
|
|
|
|
// Unused first and last
|
|
|
|
int phases = params[2];
|
2009-11-01 23:04:56 +00:00
|
|
|
|
|
|
|
// Let the palette fade in the background while the game continues.
|
2009-11-02 02:28:43 +00:00
|
|
|
// Since we don't set substatus to kInnerWhileFade, the outer loop will
|
2009-11-01 23:04:56 +00:00
|
|
|
// just continue rather than exit.
|
2009-10-28 07:34:17 +00:00
|
|
|
_vm->_game->initializeFading(phases);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::fadePalettePlay(const Common::Array<int> ¶ms) {
|
|
|
|
// Unused first and last
|
|
|
|
int phases = params[2];
|
2009-10-28 07:34:17 +00:00
|
|
|
_vm->_game->initializeFading(phases);
|
|
|
|
|
2009-11-01 23:04:56 +00:00
|
|
|
// Call the game loop to enable interactivity until the fading is done.
|
2009-11-02 02:28:43 +00:00
|
|
|
_vm->_game->loop(kInnerWhileFade, false);
|
2009-10-28 07:34:17 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::setPalette(const Common::Array<int> ¶ms) {
|
2009-08-15 02:42:34 +00:00
|
|
|
if (_vm->_game->getScheduledPalette() == -1) {
|
2011-04-14 12:12:27 +00:00
|
|
|
_vm->_screen->setPalette(NULL, 0, kNumColors);
|
2009-08-15 02:42:34 +00:00
|
|
|
} else {
|
2009-09-30 10:45:14 +00:00
|
|
|
const BAFile *f;
|
2009-08-15 02:42:34 +00:00
|
|
|
f = _vm->_paletteArchive->getFile(_vm->_game->getScheduledPalette());
|
2011-04-14 12:12:27 +00:00
|
|
|
_vm->_screen->setPalette(f->_data, 0, kNumColors);
|
2009-08-15 02:42:34 +00:00
|
|
|
}
|
2009-10-28 07:34:17 +00:00
|
|
|
// Immediately update the palette
|
|
|
|
_vm->_screen->copyToScreen();
|
2010-06-28 04:59:13 +00:00
|
|
|
_vm->_system->delayMillis(kTimeUnit);
|
2009-08-15 02:42:34 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::quitGame(const Common::Array<int> ¶ms) {
|
2009-10-11 23:28:40 +00:00
|
|
|
_vm->_game->setQuit(true);
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::pushNewRoom(const Common::Array<int> ¶ms) {
|
2009-10-11 23:28:40 +00:00
|
|
|
_vm->_game->pushNewRoom();
|
|
|
|
}
|
|
|
|
|
2009-11-09 04:27:08 +00:00
|
|
|
void Script::popNewRoom(const Common::Array<int> ¶ms) {
|
2009-10-11 23:28:40 +00:00
|
|
|
_vm->_game->popNewRoom();
|
|
|
|
}
|
|
|
|
|
2009-06-12 09:45:12 +00:00
|
|
|
/**
|
|
|
|
* @brief Evaluates mathematical expressions
|
|
|
|
* @param reader Stream reader set to the beginning of the expression
|
|
|
|
*/
|
2010-11-18 16:38:03 +00:00
|
|
|
int Script::handleMathExpression(Common::ReadStream *reader) const {
|
2009-07-06 17:25:34 +00:00
|
|
|
Common::Stack<int> stk;
|
2009-06-10 02:59:53 +00:00
|
|
|
mathExpressionObject obj;
|
2009-07-06 17:25:34 +00:00
|
|
|
GPL2Operator oper;
|
2009-07-06 18:49:51 +00:00
|
|
|
GPL2Function func;
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-08-17 18:50:38 +00:00
|
|
|
debugC(4, kDraciBytecodeDebugLevel, "\t<MATHEXPR>");
|
2009-08-08 15:55:19 +00:00
|
|
|
|
2009-06-10 02:59:53 +00:00
|
|
|
// Read in initial math object
|
2009-09-27 18:11:06 +00:00
|
|
|
obj = (mathExpressionObject)reader->readSint16LE();
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-07-06 17:25:34 +00:00
|
|
|
int value;
|
2009-07-06 18:49:51 +00:00
|
|
|
int arg1, arg2, res;
|
2009-07-06 17:25:34 +00:00
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
while (1) {
|
2009-06-10 02:59:53 +00:00
|
|
|
if (obj == kMathEnd) {
|
2009-06-12 11:32:44 +00:00
|
|
|
// Check whether the expression was evaluated correctly
|
|
|
|
// The stack should contain only one value after the evaluation
|
|
|
|
// i.e. the result of the expression
|
2009-09-30 10:45:14 +00:00
|
|
|
assert(stk.size() == 1 && "Mathematical expression error");
|
2009-06-10 02:59:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (obj) {
|
|
|
|
|
|
|
|
// If the object type is not known, assume that it's a number
|
|
|
|
default:
|
|
|
|
case kMathNumber:
|
2009-09-27 18:11:06 +00:00
|
|
|
value = reader->readSint16LE();
|
2009-06-10 02:59:53 +00:00
|
|
|
stk.push(value);
|
2009-08-17 18:50:38 +00:00
|
|
|
debugC(4, kDraciBytecodeDebugLevel, "\t\tnumber: %d", value);
|
2009-06-10 02:59:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kMathOperator:
|
2009-09-27 18:11:06 +00:00
|
|
|
value = reader->readSint16LE();
|
2009-07-06 18:49:51 +00:00
|
|
|
arg2 = stk.pop();
|
2009-08-03 01:06:13 +00:00
|
|
|
arg1 = stk.pop();
|
2009-06-12 11:32:44 +00:00
|
|
|
|
2009-07-06 17:25:34 +00:00
|
|
|
// Fetch operator
|
|
|
|
oper = _operatorList[value-1];
|
2009-06-12 11:32:44 +00:00
|
|
|
|
2009-07-06 17:25:34 +00:00
|
|
|
// Calculate result
|
2009-07-06 18:49:51 +00:00
|
|
|
res = (this->*(oper._handler))(arg1, arg2);
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-07-06 17:25:34 +00:00
|
|
|
// Push result
|
|
|
|
stk.push(res);
|
|
|
|
|
2009-08-17 18:50:38 +00:00
|
|
|
debugC(4, kDraciBytecodeDebugLevel, "\t\t%d %s %d (res: %d)",
|
2009-09-28 02:54:38 +00:00
|
|
|
arg1, oper._name, arg2, res);
|
2009-06-10 02:59:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kMathVariable:
|
2009-09-27 18:11:06 +00:00
|
|
|
value = reader->readSint16LE() - 1;
|
2009-07-07 20:57:14 +00:00
|
|
|
|
2009-08-12 05:20:25 +00:00
|
|
|
stk.push(_vm->_game->getVariable(value));
|
2009-07-07 20:57:14 +00:00
|
|
|
|
2009-08-17 18:50:38 +00:00
|
|
|
debugC(4, kDraciBytecodeDebugLevel, "\t\tvariable: %d (%d)", value,
|
2009-08-12 05:20:25 +00:00
|
|
|
_vm->_game->getVariable(value));
|
2009-06-10 02:59:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kMathFunctionCall:
|
2009-09-27 18:11:06 +00:00
|
|
|
value = reader->readSint16LE();
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-07-06 18:49:51 +00:00
|
|
|
// Fetch function
|
|
|
|
func = _functionList[value-1];
|
2009-09-30 10:45:14 +00:00
|
|
|
|
|
|
|
// If not yet implemented
|
2010-08-17 10:59:11 +00:00
|
|
|
if (func._handler == 0) {
|
2009-07-06 18:49:51 +00:00
|
|
|
stk.pop();
|
|
|
|
|
2009-11-03 21:34:38 +00:00
|
|
|
// Pushing dummy value
|
2009-07-06 18:49:51 +00:00
|
|
|
stk.push(0);
|
|
|
|
|
2009-08-17 18:50:38 +00:00
|
|
|
debugC(4, kDraciBytecodeDebugLevel, "\t\tcall: %s (not implemented)",
|
2009-09-30 10:45:14 +00:00
|
|
|
func._name);
|
2009-07-06 18:49:51 +00:00
|
|
|
} else {
|
|
|
|
arg1 = stk.pop();
|
|
|
|
|
|
|
|
// Calculate result
|
|
|
|
res = (this->*(func._handler))(arg1);
|
2009-07-12 18:55:44 +00:00
|
|
|
|
|
|
|
// Push the result on the evaluation stack
|
|
|
|
stk.push(res);
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-08-17 18:50:38 +00:00
|
|
|
debugC(4, kDraciBytecodeDebugLevel, "\t\tcall: %s(%d) (res: %d)",
|
2009-09-30 10:45:14 +00:00
|
|
|
func._name, arg1, res);
|
2009-07-06 18:49:51 +00:00
|
|
|
}
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-09-27 18:11:06 +00:00
|
|
|
obj = (mathExpressionObject) reader->readSint16LE();
|
2009-06-08 22:18:52 +00:00
|
|
|
}
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-07-04 14:48:36 +00:00
|
|
|
return stk.pop();
|
2009-06-08 22:18:52 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 15:55:19 +00:00
|
|
|
/**
|
2009-09-30 16:04:21 +00:00
|
|
|
* @brief Evaluates a GPL mathematical expression on a given offset and returns
|
2009-08-08 15:55:19 +00:00
|
|
|
* the result (which is normally a boolean-like value)
|
2009-09-30 16:04:21 +00:00
|
|
|
*
|
2009-09-30 10:45:14 +00:00
|
|
|
* @param program A GPL2Program instance of the program containing the expression
|
|
|
|
* @param offset Offset of the expression inside the program (in multiples of 2 bytes)
|
2009-09-30 16:04:21 +00:00
|
|
|
*
|
2009-08-08 15:55:19 +00:00
|
|
|
* @return The result of the expression converted to a bool.
|
|
|
|
*
|
|
|
|
* Reference: the function equivalent to this one is called "Can()" in the original engine.
|
|
|
|
*/
|
2009-09-25 17:33:00 +00:00
|
|
|
bool Script::testExpression(const GPL2Program &program, uint16 offset) const {
|
2009-08-08 15:55:19 +00:00
|
|
|
// Initialize program reader
|
|
|
|
Common::MemoryReadStream reader(program._bytecode, program._length);
|
|
|
|
|
|
|
|
// Offset is given as number of 16-bit integers so we need to convert
|
2009-09-30 16:04:21 +00:00
|
|
|
// it to a number of bytes
|
2009-08-08 15:55:19 +00:00
|
|
|
offset -= 1;
|
|
|
|
offset *= 2;
|
|
|
|
|
|
|
|
// Seek to the expression
|
|
|
|
reader.seek(offset);
|
|
|
|
|
2009-09-30 16:04:21 +00:00
|
|
|
debugC(4, kDraciBytecodeDebugLevel,
|
2009-09-30 10:45:14 +00:00
|
|
|
"Evaluating (standalone) GPL expression at offset %d:", offset);
|
2009-08-08 15:55:19 +00:00
|
|
|
|
2009-09-27 18:11:06 +00:00
|
|
|
return (bool)handleMathExpression(&reader);
|
2009-08-08 15:55:19 +00:00
|
|
|
}
|
|
|
|
|
2009-06-12 09:45:12 +00:00
|
|
|
/**
|
|
|
|
* @brief Find the current command in the internal table
|
|
|
|
*
|
2009-09-30 10:45:14 +00:00
|
|
|
* @param num Command number
|
|
|
|
* @param subnum Command subnumer
|
2009-06-12 09:45:12 +00:00
|
|
|
*
|
|
|
|
* @return NULL if command is not found. Otherwise, a pointer to a GPL2Command
|
|
|
|
* struct representing the command.
|
|
|
|
*/
|
2009-09-25 08:13:39 +00:00
|
|
|
const GPL2Command *Script::findCommand(byte num, byte subnum) const {
|
2009-09-30 10:45:14 +00:00
|
|
|
uint i = 0;
|
2009-06-10 01:35:47 +00:00
|
|
|
while (1) {
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-06-10 01:35:47 +00:00
|
|
|
// Command not found
|
|
|
|
if (i >= kNumCommands) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return found command
|
2009-07-04 14:48:36 +00:00
|
|
|
if (_commandList[i]._number == num &&
|
|
|
|
_commandList[i]._subNumber == subnum) {
|
|
|
|
return &_commandList[i];
|
2009-06-10 01:35:47 +00:00
|
|
|
}
|
2009-06-10 02:59:53 +00:00
|
|
|
|
|
|
|
++i;
|
2009-06-10 01:35:47 +00:00
|
|
|
}
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-06-10 01:35:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-12 09:45:12 +00:00
|
|
|
/**
|
2009-07-08 00:34:53 +00:00
|
|
|
* @brief GPL2 bytecode interpreter
|
2009-06-28 16:19:10 +00:00
|
|
|
* @param program GPL program in the form of a GPL2Program struct
|
2009-06-28 16:28:16 +00:00
|
|
|
* offset Offset into the program where execution should begin
|
2009-06-12 09:45:12 +00:00
|
|
|
*
|
|
|
|
* GPL2 is short for Game Programming Language 2 which is the script language
|
2009-07-08 00:34:53 +00:00
|
|
|
* used by Draci Historie. This is the interpreter for the language.
|
2009-06-12 09:45:12 +00:00
|
|
|
*
|
|
|
|
* A compiled GPL2 program consists of a stream of bytes representing commands
|
|
|
|
* and their parameters. The syntax is as follows:
|
|
|
|
*
|
|
|
|
* Syntax of a command:
|
2009-09-30 10:45:14 +00:00
|
|
|
* <name of the command> <number> <sub-number> <list of parameters...>
|
2009-06-12 09:45:12 +00:00
|
|
|
*
|
2009-09-30 10:45:14 +00:00
|
|
|
* Syntax of a parameter:
|
|
|
|
* - 1: integer number literally passed to the program
|
|
|
|
* - 2-1: string stored in the reservouir of game strings (i.e. something to be
|
|
|
|
* displayed) and stored as an index in this list
|
|
|
|
* - 2-2: string resolved by the compiler (i.e., a path to another file) and
|
|
|
|
* replaced by an integer index of this entity in the appropriate namespace
|
|
|
|
* (e.g., the index of the palette, location, ...)
|
|
|
|
* - 3-0: relative jump to a label defined in this code. Each label must be
|
|
|
|
* first declared in the beginning of the program.
|
|
|
|
* - 3-1 .. 3-9: index of an entity in several namespaces, defined in file ident
|
|
|
|
* - 4: mathematical expression compiled into a postfix format
|
2009-06-12 09:45:12 +00:00
|
|
|
*
|
2009-09-30 10:45:14 +00:00
|
|
|
* In the compiled program, parameters of type 1..3 are represented by a single
|
|
|
|
* 16-bit integer. The called command knows by its definition what namespace the
|
|
|
|
* value comes from.
|
2009-06-12 09:45:12 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-26 04:59:52 +00:00
|
|
|
void Script::run(const GPL2Program &program, uint16 offset) {
|
|
|
|
if (shouldEndProgram()) {
|
|
|
|
// This might get set by some GPL commands via Script::endCurrentProgram()
|
|
|
|
// if they need a program to stop midway. This flag is sticky until cleared
|
|
|
|
// at the top level.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-31 04:32:33 +00:00
|
|
|
int oldJump = _jump;
|
|
|
|
|
2009-07-25 03:41:28 +00:00
|
|
|
// Mark the last animation index before we do anything so a Release command
|
|
|
|
// doesn't unload too many animations if we forget to use a Mark command first
|
|
|
|
_vm->_game->setMarkedAnimationIndex(_vm->_anims->getLastIndex());
|
|
|
|
|
2009-07-04 14:48:36 +00:00
|
|
|
// Stream reader for the whole program
|
2009-06-28 16:19:10 +00:00
|
|
|
Common::MemoryReadStream reader(program._bytecode, program._length);
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-07-04 14:48:36 +00:00
|
|
|
// Parameter queue that is passed to each command
|
2009-11-09 04:27:08 +00:00
|
|
|
Common::Array<int> params;
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-06-28 16:28:16 +00:00
|
|
|
// Offset is given as number of 16-bit integers so we need to convert
|
2009-09-30 16:04:21 +00:00
|
|
|
// it to a number of bytes
|
2009-06-28 16:28:16 +00:00
|
|
|
offset -= 1;
|
|
|
|
offset *= 2;
|
|
|
|
|
|
|
|
// Seek to the requested part of the program
|
|
|
|
reader.seek(offset);
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-09-30 16:04:21 +00:00
|
|
|
debugC(3, kDraciBytecodeDebugLevel,
|
2009-07-15 19:06:24 +00:00
|
|
|
"Starting GPL program at offset %d (program length: %d)", offset, program._length);
|
|
|
|
|
2009-07-04 14:48:36 +00:00
|
|
|
const GPL2Command *cmd;
|
2009-06-28 16:19:10 +00:00
|
|
|
do {
|
2009-07-06 17:29:44 +00:00
|
|
|
|
2009-07-08 00:34:53 +00:00
|
|
|
// Account for GPL jump that some commands set
|
2009-09-30 10:45:14 +00:00
|
|
|
if (_jump != 0) {
|
2009-09-30 16:04:21 +00:00
|
|
|
debugC(3, kDraciBytecodeDebugLevel,
|
|
|
|
"Jumping from offset %d to %d (%d bytes)",
|
2009-09-30 10:45:14 +00:00
|
|
|
reader.pos(), reader.pos() + _jump, _jump);
|
2009-07-08 06:14:17 +00:00
|
|
|
reader.seek(_jump, SEEK_CUR);
|
2009-07-15 19:06:24 +00:00
|
|
|
}
|
2009-07-08 00:34:53 +00:00
|
|
|
|
|
|
|
// Reset jump
|
|
|
|
_jump = 0;
|
|
|
|
|
2009-07-06 17:29:44 +00:00
|
|
|
// Clear any parameters left on the stack from the previous command
|
|
|
|
// This likely won't be needed once all commands are implemented
|
|
|
|
params.clear();
|
2009-07-06 17:25:34 +00:00
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
// read in command pair
|
|
|
|
uint16 cmdpair = reader.readUint16BE();
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-06-10 01:35:47 +00:00
|
|
|
// extract high byte, i.e. the command number
|
|
|
|
byte num = (cmdpair >> 8) & 0xFF;
|
2009-06-10 02:59:53 +00:00
|
|
|
|
2009-06-10 01:35:47 +00:00
|
|
|
// extract low byte, i.e. the command subnumber
|
|
|
|
byte subnum = cmdpair & 0xFF;
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-06-10 01:35:47 +00:00
|
|
|
if ((cmd = findCommand(num, subnum))) {
|
2009-07-04 14:48:36 +00:00
|
|
|
int tmp;
|
2009-06-10 02:59:53 +00:00
|
|
|
|
|
|
|
// Print command name
|
2009-09-28 02:54:38 +00:00
|
|
|
debugC(1, kDraciBytecodeDebugLevel, "%s", cmd->_name);
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-07-04 14:48:36 +00:00
|
|
|
for (int i = 0; i < cmd->_numParams; ++i) {
|
2009-11-08 21:26:04 +00:00
|
|
|
if (cmd->_paramTypes[i] == kGPL2Math) {
|
2009-09-30 16:04:21 +00:00
|
|
|
debugC(3, kDraciBytecodeDebugLevel,
|
2009-09-30 10:45:14 +00:00
|
|
|
"Evaluating (in-script) GPL expression at offset %d: ", offset);
|
2009-11-09 04:27:08 +00:00
|
|
|
params.push_back(handleMathExpression(&reader));
|
2009-09-30 10:45:14 +00:00
|
|
|
} else {
|
2009-07-08 00:34:53 +00:00
|
|
|
tmp = reader.readSint16LE();
|
2009-11-09 04:27:08 +00:00
|
|
|
params.push_back(tmp);
|
2009-07-08 00:34:53 +00:00
|
|
|
debugC(2, kDraciBytecodeDebugLevel, "\t%d", tmp);
|
2009-06-10 01:35:47 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-30 10:45:14 +00:00
|
|
|
} else {
|
2011-06-03 18:53:14 +00:00
|
|
|
error("Unknown opcode %d, %d", num, subnum);
|
2009-06-08 22:18:52 +00:00
|
|
|
}
|
2009-07-04 14:48:36 +00:00
|
|
|
|
|
|
|
GPLHandler handler = cmd->_handler;
|
|
|
|
|
2010-08-17 10:59:11 +00:00
|
|
|
if (handler != 0) {
|
2009-07-04 14:48:36 +00:00
|
|
|
// Call the handler for the current command
|
|
|
|
(this->*(cmd->_handler))(params);
|
|
|
|
}
|
|
|
|
|
2009-10-26 04:59:52 +00:00
|
|
|
} while (cmd->_number != 0 && !shouldEndProgram()); // 0 = gplend and exit
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-07-31 04:32:33 +00:00
|
|
|
_jump = oldJump;
|
2009-10-29 15:26:48 +00:00
|
|
|
|
|
|
|
// Reset the flags which may have temporarily been altered inside the script.
|
|
|
|
_vm->_game->setEnableQuickHero(true);
|
|
|
|
_vm->_game->setEnableSpeedText(true);
|
2009-06-08 22:18:52 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 00:45:28 +00:00
|
|
|
void Script::runWrapper(const GPL2Program &program, uint16 offset, bool disableCursor, bool releaseAnims) {
|
|
|
|
if (disableCursor) {
|
|
|
|
// Fetch the dedicated objects' title animation / current frame
|
|
|
|
Animation *titleAnim = _vm->_anims->getAnimation(kTitleText);
|
|
|
|
titleAnim->markDirtyRect(_vm->_screen->getSurface());
|
|
|
|
Text *title = reinterpret_cast<Text *>(titleAnim->getCurrentFrame());
|
|
|
|
title->setText("");
|
|
|
|
|
|
|
|
_vm->_mouse->cursorOff();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark last animation
|
|
|
|
int lastAnimIndex = _vm->_anims->getLastIndex();
|
|
|
|
|
|
|
|
run(program, offset);
|
|
|
|
|
|
|
|
if (releaseAnims) {
|
|
|
|
_vm->_game->deleteAnimationsAfterIndex(lastAnimIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disableCursor) {
|
|
|
|
_vm->_mouse->cursorOn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Draci
|