2005-04-05 18:08:02 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004 Ivan Dubrov
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2004-2006 The ScummVM project
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-04-09 19:19:54 +00:00
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
2006-02-11 10:11:37 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-03-29 15:59:37 +00:00
|
|
|
|
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/endian.h"
|
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/gob.h"
|
|
|
|
#include "gob/global.h"
|
|
|
|
#include "gob/inter.h"
|
|
|
|
#include "gob/util.h"
|
2005-04-09 19:32:29 +00:00
|
|
|
#include "gob/scenery.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/parse.h"
|
|
|
|
#include "gob/game.h"
|
|
|
|
#include "gob/draw.h"
|
|
|
|
#include "gob/mult.h"
|
|
|
|
#include "gob/goblin.h"
|
2005-04-13 18:27:29 +00:00
|
|
|
#include "gob/cdrom.h"
|
2006-01-10 11:30:23 +00:00
|
|
|
#include "gob/map.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
Inter::Inter(GobEngine *vm) : _vm(vm) {
|
2006-05-11 19:43:30 +00:00
|
|
|
int i;
|
|
|
|
|
2007-01-31 16:23:34 +00:00
|
|
|
_noBusyWait = false;
|
2006-01-04 01:23:20 +00:00
|
|
|
_terminate = false;
|
|
|
|
_breakFlag = false;
|
2006-05-11 19:43:30 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
_animPalLowIndex[i] = 0;
|
|
|
|
_animPalHighIndex[i] = 0;
|
|
|
|
_animPalDir[i] = 0;
|
|
|
|
}
|
|
|
|
|
2006-01-04 01:23:20 +00:00
|
|
|
_soundEndTimeKey = 0;
|
|
|
|
_soundStopVal = 0;
|
|
|
|
_breakFromLevel = 0;
|
|
|
|
_nestLevel = 0;
|
2006-11-20 13:03:30 +00:00
|
|
|
|
|
|
|
memset(_pasteBuf, 0, 300);
|
2006-11-27 14:19:30 +00:00
|
|
|
memset(_pasteSizeBuf, 0, 300);
|
2006-11-20 13:03:30 +00:00
|
|
|
_pastePos = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int16 Inter::load16(void) {
|
2006-01-04 01:48:15 +00:00
|
|
|
int16 tmp = (int16)READ_LE_UINT16(_vm->_global->_inter_execPtr);
|
|
|
|
_vm->_global->_inter_execPtr += 2;
|
2005-04-05 15:07:40 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
char Inter::evalExpr(int16 *pRes) {
|
2005-04-05 15:07:40 +00:00
|
|
|
byte token;
|
|
|
|
|
|
|
|
//
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_parse->printExpr(99);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_parse->parseExpr(99, &token);
|
2005-04-05 15:07:40 +00:00
|
|
|
if (pRes == 0)
|
|
|
|
return token;
|
|
|
|
|
|
|
|
switch (token) {
|
|
|
|
case 20:
|
2006-01-04 01:48:15 +00:00
|
|
|
*pRes = _vm->_global->_inter_resVal;
|
2005-04-05 15:07:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 22:
|
|
|
|
case 23:
|
|
|
|
*pRes = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
*pRes = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
char Inter::evalBoolResult() {
|
2005-04-05 15:07:40 +00:00
|
|
|
byte token;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_parse->printExpr(99);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_parse->parseExpr(99, &token);
|
2006-01-04 01:48:15 +00:00
|
|
|
if (token == 24 || (token == 20 && _vm->_global->_inter_resVal != 0))
|
2005-04-05 15:07:40 +00:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
void Inter::funcBlock(int16 retFlag) {
|
|
|
|
char cmdCount;
|
|
|
|
int16 counter;
|
|
|
|
byte cmd;
|
|
|
|
byte cmd2;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
if (_vm->_global->_inter_execPtr == 0)
|
|
|
|
return;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
_breakFlag = false;
|
|
|
|
_vm->_global->_inter_execPtr++;
|
|
|
|
cmdCount = *_vm->_global->_inter_execPtr++;
|
|
|
|
_vm->_global->_inter_execPtr += 2;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
if (cmdCount == 0) {
|
|
|
|
_vm->_global->_inter_execPtr = 0;
|
|
|
|
return;
|
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-03-18 13:44:57 +00:00
|
|
|
int startaddr = _vm->_global->_inter_execPtr-_vm->_game->_totFileData;
|
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
counter = 0;
|
|
|
|
do {
|
|
|
|
if (_terminate)
|
|
|
|
break;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-03-18 13:44:57 +00:00
|
|
|
// WORKAROUND:
|
|
|
|
// The EGA version of gob1 doesn't add a delay after showing
|
|
|
|
// images between levels. We manually add it here.
|
|
|
|
if ((_vm->_features & GF_GOB1) && (_vm->_features & GF_EGA)) {
|
|
|
|
int addr = _vm->_global->_inter_execPtr-_vm->_game->_totFileData;
|
|
|
|
if ((startaddr == 0x18B4 && addr == 0x1A7F && // Zombie
|
|
|
|
!strncmp(_vm->_game->_curTotFile, "avt005.tot", 10)) ||
|
|
|
|
(startaddr == 0x1299 && addr == 0x139A && // Dungeon
|
|
|
|
!strncmp(_vm->_game->_curTotFile, "avt006.tot", 10)) ||
|
|
|
|
(startaddr == 0x11C0 && addr == 0x12C9 && // Cauldron
|
|
|
|
!strncmp(_vm->_game->_curTotFile, "avt012.tot", 10)) ||
|
|
|
|
(startaddr == 0x09F2 && addr == 0x0AF3 && // Statue
|
|
|
|
!strncmp(_vm->_game->_curTotFile, "avt016.tot", 10)) ||
|
|
|
|
(startaddr == 0x0B92 && addr == 0x0C93 && // Castle
|
|
|
|
!strncmp(_vm->_game->_curTotFile, "avt019.tot", 10)) ||
|
|
|
|
(startaddr == 0x17D9 && addr == 0x18DA && // Finale
|
|
|
|
!strncmp(_vm->_game->_curTotFile, "avt022.tot", 10)))
|
|
|
|
{
|
|
|
|
_vm->_util->longDelay(5000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// (end workaround)
|
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
cmd = (byte)*_vm->_global->_inter_execPtr;
|
|
|
|
if ((cmd >> 4) >= 12) {
|
|
|
|
cmd2 = 16 - (cmd >> 4);
|
|
|
|
cmd &= 0xf;
|
|
|
|
} else
|
|
|
|
cmd2 = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
_vm->_global->_inter_execPtr++;
|
|
|
|
counter++;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-08 20:03:20 +00:00
|
|
|
if (cmd2 == 0)
|
2006-01-05 16:06:55 +00:00
|
|
|
cmd >>= 4;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-08 20:03:20 +00:00
|
|
|
if (executeFuncOpcode(cmd2, cmd, cmdCount, counter, retFlag))
|
2006-01-05 16:06:55 +00:00
|
|
|
return;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-05-31 08:44:14 +00:00
|
|
|
if (_vm->_quitRequested)
|
|
|
|
break;
|
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
if (_breakFlag) {
|
|
|
|
if (retFlag != 2)
|
|
|
|
break;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
if (*_breakFromLevel == -1)
|
|
|
|
_breakFlag = false;
|
|
|
|
break;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
2006-01-05 16:06:55 +00:00
|
|
|
} while (counter != cmdCount);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
_vm->_global->_inter_execPtr = 0;
|
|
|
|
return;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
void Inter::callSub(int16 retFlag) {
|
|
|
|
int16 block;
|
2006-05-31 08:44:14 +00:00
|
|
|
while (!_vm->_quitRequested && _vm->_global->_inter_execPtr != 0 && (char *)_vm->_global->_inter_execPtr != _vm->_game->_totFileData) {
|
2006-01-05 16:06:55 +00:00
|
|
|
block = *_vm->_global->_inter_execPtr;
|
|
|
|
if (block == 1) {
|
|
|
|
funcBlock(retFlag);
|
|
|
|
} else if (block == 2) {
|
|
|
|
_vm->_game->collisionsBlock();
|
2005-07-19 09:10:05 +00:00
|
|
|
}
|
2006-01-05 16:06:55 +00:00
|
|
|
}
|
2005-07-19 09:10:05 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
if ((char *)_vm->_global->_inter_execPtr == _vm->_game->_totFileData)
|
2006-01-05 16:06:55 +00:00
|
|
|
_terminate = true;
|
|
|
|
}
|
2005-07-19 09:10:05 +00:00
|
|
|
|
2006-06-29 12:55:57 +00:00
|
|
|
void Inter::initControlVars(char full) {
|
|
|
|
int i;
|
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
*_nestLevel = 0;
|
|
|
|
*_breakFromLevel = -1;
|
2005-07-19 09:10:05 +00:00
|
|
|
|
2006-01-09 16:10:22 +00:00
|
|
|
*_vm->_scenery->_pCaptureCounter = 0;
|
2005-07-19 09:10:05 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
_breakFlag = false;
|
|
|
|
_terminate = false;
|
2006-06-29 12:55:57 +00:00
|
|
|
|
|
|
|
if (full == 1) {
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
_animPalDir[i] = 0;
|
|
|
|
_soundEndTimeKey = 0;
|
|
|
|
}
|
2006-01-05 16:06:55 +00:00
|
|
|
}
|
2005-07-19 09:10:05 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
void Inter::renewTimeInVars(void) {
|
|
|
|
struct tm *t;
|
|
|
|
time_t now = time(NULL);
|
2005-07-19 09:10:05 +00:00
|
|
|
|
2006-01-05 16:06:55 +00:00
|
|
|
t = localtime(&now);
|
2005-04-12 23:45:15 +00:00
|
|
|
|
|
|
|
WRITE_VAR(5, 1900 + t->tm_year);
|
2007-02-01 20:19:21 +00:00
|
|
|
WRITE_VAR(6, t->tm_mon + 1);
|
2005-04-12 23:45:15 +00:00
|
|
|
WRITE_VAR(7, 0);
|
|
|
|
WRITE_VAR(8, t->tm_mday);
|
|
|
|
WRITE_VAR(9, t->tm_hour);
|
|
|
|
WRITE_VAR(10, t->tm_min);
|
|
|
|
WRITE_VAR(11, t->tm_sec);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-10 11:30:23 +00:00
|
|
|
void Inter::manipulateMap(int16 xPos, int16 yPos, int16 item) {
|
2006-05-29 18:24:52 +00:00
|
|
|
for (int16 y = 0; y < _vm->_map->_mapHeight; y++) {
|
|
|
|
for (int16 x = 0; x < _vm->_map->_mapWidth; x++) {
|
2006-01-10 11:30:23 +00:00
|
|
|
if ((_vm->_map->_itemsMap[y][x] & 0xff) == item) {
|
|
|
|
_vm->_map->_itemsMap[y][x] &= 0xff00;
|
|
|
|
} else if (((_vm->_map->_itemsMap[y][x] & 0xff00) >> 8)
|
|
|
|
== item) {
|
|
|
|
_vm->_map->_itemsMap[y][x] &= 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-29 18:24:52 +00:00
|
|
|
if (xPos < _vm->_map->_mapWidth - 1) {
|
2006-01-10 11:30:23 +00:00
|
|
|
if (yPos > 0) {
|
|
|
|
if ((_vm->_map->_itemsMap[yPos][xPos] & 0xff00) != 0 ||
|
|
|
|
(_vm->_map->_itemsMap[yPos - 1][xPos] & 0xff00) !=
|
|
|
|
0
|
|
|
|
|| (_vm->_map->_itemsMap[yPos][xPos +
|
|
|
|
1] & 0xff00) != 0
|
|
|
|
|| (_vm->_map->_itemsMap[yPos - 1][xPos +
|
|
|
|
1] & 0xff00) != 0) {
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos] & 0xff00)
|
|
|
|
+ item;
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos - 1][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos -
|
|
|
|
1][xPos] & 0xff00) + item;
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos + 1] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos +
|
|
|
|
1] & 0xff00) + item;
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos - 1][xPos + 1] =
|
|
|
|
(_vm->_map->_itemsMap[yPos - 1][xPos +
|
|
|
|
1] & 0xff00) + item;
|
|
|
|
} else {
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos] & 0xff) +
|
|
|
|
(item << 8);
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos - 1][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos -
|
|
|
|
1][xPos] & 0xff) + (item << 8);
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos + 1] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos +
|
|
|
|
1] & 0xff) + (item << 8);
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos - 1][xPos + 1] =
|
|
|
|
(_vm->_map->_itemsMap[yPos - 1][xPos +
|
|
|
|
1] & 0xff) + (item << 8);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((_vm->_map->_itemsMap[yPos][xPos] & 0xff00) != 0 ||
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos + 1] & 0xff00) !=
|
|
|
|
0) {
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos] & 0xff00)
|
|
|
|
+ item;
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos + 1] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos +
|
|
|
|
1] & 0xff00) + item;
|
|
|
|
} else {
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos] & 0xff) +
|
|
|
|
(item << 8);
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos + 1] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos +
|
|
|
|
1] & 0xff) + (item << 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (yPos > 0) {
|
|
|
|
if ((_vm->_map->_itemsMap[yPos][xPos] & 0xff00) != 0 ||
|
|
|
|
(_vm->_map->_itemsMap[yPos - 1][xPos] & 0xff00) !=
|
|
|
|
0) {
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos] & 0xff00)
|
|
|
|
+ item;
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos - 1][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos -
|
|
|
|
1][xPos] & 0xff00) + item;
|
|
|
|
} else {
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos] & 0xff) +
|
|
|
|
(item << 8);
|
|
|
|
|
|
|
|
_vm->_map->_itemsMap[yPos - 1][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos -
|
|
|
|
1][xPos] & 0xff) + (item << 8);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((_vm->_map->_itemsMap[yPos][xPos] & 0xff00) != 0) {
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos] & 0xff00)
|
|
|
|
+ item;
|
|
|
|
} else {
|
|
|
|
_vm->_map->_itemsMap[yPos][xPos] =
|
|
|
|
(_vm->_map->_itemsMap[yPos][xPos] & 0xff) +
|
|
|
|
(item << 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item < 0 || item >= 20)
|
|
|
|
return;
|
|
|
|
|
2006-05-29 18:24:52 +00:00
|
|
|
if (xPos > 1 && _vm->_map->getPass(xPos - 2, yPos) == 1) {
|
2006-01-10 11:30:23 +00:00
|
|
|
_vm->_map->_itemPoses[item].x = xPos - 2;
|
|
|
|
_vm->_map->_itemPoses[item].y = yPos;
|
|
|
|
_vm->_map->_itemPoses[item].orient = 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-29 18:24:52 +00:00
|
|
|
if (xPos < _vm->_map->_mapWidth - 2 && _vm->_map->getPass(xPos + 2, yPos) == 1) {
|
2006-01-10 11:30:23 +00:00
|
|
|
_vm->_map->_itemPoses[item].x = xPos + 2;
|
|
|
|
_vm->_map->_itemPoses[item].y = yPos;
|
|
|
|
_vm->_map->_itemPoses[item].orient = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-29 18:24:52 +00:00
|
|
|
if (xPos < _vm->_map->_mapWidth - 1 && _vm->_map->getPass(xPos + 1, yPos) == 1) {
|
2006-01-10 11:30:23 +00:00
|
|
|
_vm->_map->_itemPoses[item].x = xPos + 1;
|
|
|
|
_vm->_map->_itemPoses[item].y = yPos;
|
|
|
|
_vm->_map->_itemPoses[item].orient = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-29 18:24:52 +00:00
|
|
|
if (xPos > 0 && _vm->_map->getPass(xPos - 1, yPos) == 1) {
|
2006-01-10 11:30:23 +00:00
|
|
|
_vm->_map->_itemPoses[item].x = xPos - 1;
|
|
|
|
_vm->_map->_itemPoses[item].y = yPos;
|
|
|
|
_vm->_map->_itemPoses[item].orient = 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
} // End of namespace Gob
|