2007-09-18 16:20:44 +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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "agi/preagi.h"
|
|
|
|
#include "agi/preagi_troll.h"
|
|
|
|
#include "agi/graphics.h"
|
|
|
|
|
2008-10-06 12:48:52 +00:00
|
|
|
#include "common/events.h"
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
#include "graphics/cursorman.h"
|
|
|
|
|
|
|
|
namespace Agi {
|
|
|
|
|
|
|
|
Troll::Troll(PreAgiEngine* vm) : _vm(vm) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// User Interface
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
void Troll::pressAnyKey(int col) {
|
|
|
|
_vm->drawStr(24, col, kColorDefault, IDS_TRO_PRESSANYKEY);
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->_gfx->doUpdate();
|
2007-09-19 09:54:42 +00:00
|
|
|
_vm->getSelection(kSelAnyKey);
|
2007-09-18 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Troll::drawMenu(const char *szMenu, int iSel) {
|
|
|
|
_vm->clearTextArea();
|
2007-09-18 17:01:45 +00:00
|
|
|
_vm->drawStr(21, 0, kColorDefault, szMenu);
|
|
|
|
_vm->drawStr(22 + iSel, 0, kColorDefault, " *");
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
}
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
bool Troll::getMenuSel(const char *szMenu, int *iSel, int nSel) {
|
2007-09-18 16:20:44 +00:00
|
|
|
Common::Event event;
|
|
|
|
int y;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
drawMenu(szMenu, *iSel);
|
|
|
|
|
2008-09-30 12:27:38 +00:00
|
|
|
while (!_vm->shouldQuit()) {
|
2007-09-18 16:20:44 +00:00
|
|
|
while (_vm->_system->getEventManager()->pollEvent(event)) {
|
2009-09-30 16:16:53 +00:00
|
|
|
switch (event.type) {
|
2008-07-16 04:22:56 +00:00
|
|
|
case Common::EVENT_RTL:
|
2007-09-18 16:20:44 +00:00
|
|
|
case Common::EVENT_QUIT:
|
2008-07-08 01:33:57 +00:00
|
|
|
return 0;
|
2007-09-18 16:20:44 +00:00
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
y = event.mouse.y / 8;
|
|
|
|
|
2007-09-18 17:01:45 +00:00
|
|
|
if (y >= 22)
|
|
|
|
if (nSel > y - 22)
|
|
|
|
*iSel = y - 22;
|
2007-09-18 16:20:44 +00:00
|
|
|
|
|
|
|
drawMenu(szMenu, *iSel);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
2007-09-20 18:18:10 +00:00
|
|
|
return true;
|
2007-09-18 16:20:44 +00:00
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
switch (event.kbd.keycode) {
|
|
|
|
case Common::KEYCODE_t:
|
|
|
|
case Common::KEYCODE_f:
|
|
|
|
inventory();
|
2009-06-06 17:39:13 +00:00
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
return false;
|
2009-06-06 17:39:13 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
break;
|
2007-09-20 22:44:48 +00:00
|
|
|
case Common::KEYCODE_DOWN:
|
2007-09-18 16:20:44 +00:00
|
|
|
case Common::KEYCODE_SPACE:
|
|
|
|
*iSel += 1;
|
|
|
|
|
|
|
|
if (*iSel == nSel)
|
|
|
|
*iSel = IDI_TRO_SEL_OPTION_1;
|
|
|
|
|
2007-09-20 22:44:48 +00:00
|
|
|
drawMenu(szMenu, *iSel);
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_UP:
|
|
|
|
*iSel -= 1;
|
|
|
|
|
|
|
|
if (*iSel == IDI_TRO_SEL_OPTION_1 - 1)
|
|
|
|
*iSel = nSel - 1;
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
drawMenu(szMenu, *iSel);
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_RETURN:
|
|
|
|
case Common::KEYCODE_KP_ENTER:
|
2007-09-20 18:18:10 +00:00
|
|
|
return true;
|
2007-09-20 21:55:15 +00:00
|
|
|
case Common::KEYCODE_s:
|
|
|
|
if (event.kbd.flags == Common::KBD_CTRL) {
|
|
|
|
if (_soundOn) {
|
|
|
|
playTune(2, 1);
|
|
|
|
_soundOn = !_soundOn;
|
|
|
|
} else {
|
|
|
|
_soundOn = !_soundOn;
|
|
|
|
playTune(3, 1);
|
|
|
|
}
|
|
|
|
}
|
2007-09-18 16:20:44 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_vm->_system->updateScreen();
|
|
|
|
_vm->_system->delayMillis(10);
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
return true;
|
2007-09-18 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Graphics
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
void Troll::drawPic(int iPic, bool f3IsCont, bool clr, bool troll) {
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->_picture->setDimensions(IDI_TRO_PIC_WIDTH, IDI_TRO_PIC_HEIGHT);
|
|
|
|
|
2007-09-18 20:23:06 +00:00
|
|
|
if (clr) {
|
|
|
|
_vm->clearScreen(0x0f, false);
|
|
|
|
_vm->_picture->clear();
|
|
|
|
}
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
_vm->_picture->setPictureData(_gameData + IDO_TRO_FRAMEPIC);
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->_picture->drawPicture();
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
_vm->_picture->setPictureData(_gameData + _pictureOffsets[iPic]);
|
2007-09-18 16:20:44 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
int addFlag = 0;
|
|
|
|
|
|
|
|
if (troll)
|
|
|
|
addFlag = kPicFTrollMode;
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
if (f3IsCont) {
|
2007-09-20 21:55:15 +00:00
|
|
|
_vm->_picture->setPictureFlags(kPicFf3Cont | addFlag);
|
2007-09-20 18:18:10 +00:00
|
|
|
} else {
|
2007-09-20 21:55:15 +00:00
|
|
|
_vm->_picture->setPictureFlags(kPicFf3Stop | addFlag);
|
2007-09-20 18:18:10 +00:00
|
|
|
}
|
2007-09-18 16:20:44 +00:00
|
|
|
|
|
|
|
_vm->_picture->drawPicture();
|
|
|
|
|
|
|
|
_vm->_picture->showPic();
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Game Logic
|
|
|
|
|
|
|
|
void Troll::inventory() {
|
2007-09-20 18:18:10 +00:00
|
|
|
char tmp[40];
|
|
|
|
int n;
|
2007-09-18 16:20:44 +00:00
|
|
|
|
|
|
|
_vm->clearScreen(0x07);
|
|
|
|
_vm->drawStr(1, 12, kColorDefault, IDS_TRO_TREASURE_0);
|
|
|
|
_vm->drawStr(2, 12, kColorDefault, IDS_TRO_TREASURE_1);
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < IDI_TRO_MAX_TREASURE - _treasuresLeft; i++) {
|
|
|
|
n = _inventory[i] - 1;
|
|
|
|
|
|
|
|
sprintf(tmp, " %2d ", i + 1);
|
|
|
|
|
|
|
|
_vm->drawStr(2 + i, 10, _items[n].bg << 4 | 0x0f, tmp);
|
|
|
|
_vm->drawStr(2 + i, 14, _items[n].bg << 4 | _items[n].fg, _items[n].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
switch (_treasuresLeft) {
|
|
|
|
case 1:
|
2007-09-20 18:18:10 +00:00
|
|
|
sprintf(tmp, IDS_TRO_TREASURE_5, _treasuresLeft);
|
|
|
|
_vm->drawStr(20, 10, kColorDefault, tmp);
|
2007-09-18 16:20:44 +00:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
_vm->drawStr(20, 1, kColorDefault, IDS_TRO_TREASURE_6);
|
|
|
|
break;
|
|
|
|
case IDI_TRO_MAX_TREASURE:
|
|
|
|
_vm->drawStr(3, 17, kColorDefault, IDS_TRO_TREASURE_2);
|
|
|
|
default:
|
2007-09-20 18:18:10 +00:00
|
|
|
sprintf(tmp, IDS_TRO_TREASURE_4, _treasuresLeft);
|
|
|
|
_vm->drawStr(20, 10, kColorDefault, tmp);
|
2007-09-18 16:20:44 +00:00
|
|
|
break;
|
2008-01-27 19:47:41 +00:00
|
|
|
}
|
2007-09-18 16:20:44 +00:00
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
pressAnyKey(6);
|
2007-09-18 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Troll::waitAnyKeyIntro() {
|
|
|
|
Common::Event event;
|
|
|
|
int iMsg = 0;
|
|
|
|
|
2009-01-05 00:51:54 +00:00
|
|
|
while (!_vm->shouldQuit()) {
|
2007-09-18 16:20:44 +00:00
|
|
|
while (_vm->_system->getEventManager()->pollEvent(event)) {
|
2009-09-30 16:16:53 +00:00
|
|
|
switch (event.type) {
|
2008-07-16 04:22:56 +00:00
|
|
|
case Common::EVENT_RTL:
|
2007-09-18 16:20:44 +00:00
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (iMsg) {
|
|
|
|
case 200:
|
|
|
|
iMsg = 0;
|
|
|
|
case 0:
|
|
|
|
_vm->drawStr(22, 3, kColorDefault, IDS_TRO_INTRO_2);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
break;
|
|
|
|
case 100:
|
|
|
|
_vm->drawStr(22, 3, kColorDefault, IDS_TRO_INTRO_3);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iMsg++;
|
|
|
|
|
|
|
|
_vm->_system->updateScreen();
|
|
|
|
_vm->_system->delayMillis(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Troll::credits() {
|
|
|
|
_vm->clearScreen(0x07);
|
|
|
|
|
|
|
|
_vm->drawStr(1, 2, kColorDefault, IDS_TRO_CREDITS_0);
|
|
|
|
|
2007-09-18 19:06:05 +00:00
|
|
|
int color = 10;
|
|
|
|
char str[2];
|
|
|
|
|
|
|
|
str[1] = 0;
|
|
|
|
|
|
|
|
for (uint i = 0; i < strlen(IDS_TRO_CREDITS_1); i++) {
|
|
|
|
str[0] = IDS_TRO_CREDITS_1[i];
|
|
|
|
_vm->drawStr(7, 19 + i, color++, str);
|
|
|
|
if (color > 15)
|
|
|
|
color = 9;
|
|
|
|
}
|
2007-09-18 16:20:44 +00:00
|
|
|
|
|
|
|
_vm->drawStr(8, 19, kColorDefault, IDS_TRO_CREDITS_2);
|
|
|
|
|
|
|
|
_vm->drawStr(13, 11, 9, IDS_TRO_CREDITS_3);
|
|
|
|
_vm->drawStr(15, 8, 10, IDS_TRO_CREDITS_4);
|
|
|
|
_vm->drawStr(17, 7, 12, IDS_TRO_CREDITS_5);
|
|
|
|
_vm->drawStr(19, 2, 14, IDS_TRO_CREDITS_6);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
|
|
|
|
pressAnyKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Troll::tutorial() {
|
|
|
|
bool done = false;
|
|
|
|
int iSel = 0;
|
|
|
|
//char szTreasure[16] = {0};
|
|
|
|
|
2008-09-30 12:27:38 +00:00
|
|
|
while (!_vm->shouldQuit()) {
|
2007-09-18 17:01:45 +00:00
|
|
|
_vm->clearScreen(0xFF);
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->printStr(IDS_TRO_TUTORIAL_0);
|
|
|
|
_vm->getSelection(kSelSpace);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 17:01:45 +00:00
|
|
|
_vm->clearScreen(0x55);
|
|
|
|
_vm->setDefaultTextColor(0x0F);
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
done = false;
|
2009-01-05 00:51:54 +00:00
|
|
|
while (!done && !_vm->shouldQuit()) {
|
2007-09-18 16:20:44 +00:00
|
|
|
getMenuSel(IDS_TRO_TUTORIAL_1, &iSel, IDI_TRO_MAX_OPTION);
|
2009-06-06 17:39:13 +00:00
|
|
|
|
2009-09-30 16:16:53 +00:00
|
|
|
switch (iSel) {
|
2007-09-18 16:20:44 +00:00
|
|
|
case IDI_TRO_SEL_OPTION_1:
|
2007-09-18 17:01:45 +00:00
|
|
|
_vm->clearScreen(0x22, false);
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
break;
|
|
|
|
case IDI_TRO_SEL_OPTION_2:
|
2007-09-18 17:01:45 +00:00
|
|
|
_vm->clearScreen(0x00, false);
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
break;
|
|
|
|
case IDI_TRO_SEL_OPTION_3:
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do you need more practice ?
|
|
|
|
_vm->clearScreen(0x4F);
|
|
|
|
_vm->drawStr(7, 4, kColorDefault, IDS_TRO_TUTORIAL_5);
|
|
|
|
_vm->drawStr(9, 4, kColorDefault, IDS_TRO_TUTORIAL_6);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
|
|
|
|
if (!_vm->getSelection(kSelYesNo))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// show info texts
|
|
|
|
_vm->clearScreen(0x5F);
|
|
|
|
_vm->drawStr(4, 1, kColorDefault, IDS_TRO_TUTORIAL_7);
|
|
|
|
_vm->drawStr(5, 1, kColorDefault, IDS_TRO_TUTORIAL_8);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
pressAnyKey();
|
|
|
|
|
|
|
|
_vm->clearScreen(0x2F);
|
|
|
|
_vm->drawStr(6, 1, kColorDefault, IDS_TRO_TUTORIAL_9);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
pressAnyKey();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->clearScreen(0x19);
|
|
|
|
_vm->drawStr(7, 1, kColorDefault, IDS_TRO_TUTORIAL_10);
|
|
|
|
_vm->drawStr(8, 1, kColorDefault, IDS_TRO_TUTORIAL_11);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
pressAnyKey();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->clearScreen(0x6E);
|
|
|
|
_vm->drawStr(9, 1, kColorDefault, IDS_TRO_TUTORIAL_12);
|
|
|
|
_vm->drawStr(10, 1, kColorDefault, IDS_TRO_TUTORIAL_13);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
pressAnyKey();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->clearScreen(0x4C);
|
|
|
|
_vm->drawStr(11, 1, kColorDefault, IDS_TRO_TUTORIAL_14);
|
|
|
|
_vm->drawStr(12, 1, kColorDefault, IDS_TRO_TUTORIAL_15);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
pressAnyKey();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
_vm->clearScreen(0x5D);
|
|
|
|
_vm->drawStr(13, 1, kColorDefault, IDS_TRO_TUTORIAL_16);
|
|
|
|
_vm->drawStr(14, 1, kColorDefault, IDS_TRO_TUTORIAL_17);
|
|
|
|
_vm->drawStr(15, 1, kColorDefault, IDS_TRO_TUTORIAL_18);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
pressAnyKey();
|
|
|
|
|
|
|
|
// show treasures
|
|
|
|
_vm->clearScreen(0x2A);
|
|
|
|
_vm->drawStr(2, 1, kColorDefault, IDS_TRO_TUTORIAL_19);
|
|
|
|
for (int i = 0; i < IDI_TRO_MAX_TREASURE; i++)
|
2007-09-20 18:18:10 +00:00
|
|
|
_vm->drawStr(19 - i, 11, kColorDefault, _items[i].name);
|
2007-09-18 16:20:44 +00:00
|
|
|
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
|
|
|
|
pressAnyKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Troll::intro() {
|
|
|
|
// sierra on-line presents
|
|
|
|
_vm->clearScreen(0x2F);
|
|
|
|
_vm->drawStr(9, 10, kColorDefault, IDS_TRO_INTRO_0);
|
|
|
|
_vm->drawStr(14, 15, kColorDefault, IDS_TRO_INTRO_1);
|
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
_vm->_system->updateScreen();
|
2007-09-18 19:06:05 +00:00
|
|
|
_vm->_system->delayMillis(3200);
|
2007-09-18 16:20:44 +00:00
|
|
|
|
2007-09-19 21:24:27 +00:00
|
|
|
CursorMan.showMouse(true);
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
// Draw logo
|
2007-09-18 20:23:06 +00:00
|
|
|
_vm->setDefaultTextColor(0x0f);
|
2007-09-18 16:20:44 +00:00
|
|
|
drawPic(45, false, true);
|
|
|
|
_vm->_gfx->doUpdate();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
// wait for keypress and alternate message
|
|
|
|
waitAnyKeyIntro();
|
|
|
|
|
|
|
|
// have you played this game before?
|
|
|
|
_vm->drawStr(22, 3, kColorDefault, IDS_TRO_INTRO_4);
|
|
|
|
_vm->drawStr(23, 6, kColorDefault, IDS_TRO_INTRO_5);
|
|
|
|
_vm->_gfx->doUpdate();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
if (!_vm->getSelection(kSelYesNo))
|
|
|
|
tutorial();
|
|
|
|
|
|
|
|
credits();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Troll::gameOver() {
|
2009-01-05 00:51:54 +00:00
|
|
|
// We do a check to see if the game should quit. Without this, the game show the picture, plays the
|
|
|
|
// music, and then quits. So if the game is quitting, we shouldn't run the "game over" part.
|
|
|
|
if (_vm->shouldQuit())
|
|
|
|
return;
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
char szMoves[40];
|
|
|
|
|
|
|
|
_vm->clearTextArea();
|
2007-09-20 21:55:15 +00:00
|
|
|
drawPic(42, true, true);
|
|
|
|
|
|
|
|
playTune(4, 25);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
printUserMessage(16);
|
|
|
|
|
|
|
|
printUserMessage(33);
|
2007-09-18 16:20:44 +00:00
|
|
|
|
|
|
|
_vm->clearTextArea();
|
2007-09-20 21:55:15 +00:00
|
|
|
|
|
|
|
drawPic(46, true, true);
|
2007-09-18 16:20:44 +00:00
|
|
|
|
|
|
|
sprintf(szMoves, IDS_TRO_GAMEOVER_0, _moves);
|
|
|
|
_vm->drawStr(21, 1, kColorDefault, szMoves);
|
|
|
|
_vm->drawStr(22, 1, kColorDefault, IDS_TRO_GAMEOVER_1);
|
|
|
|
_vm->_gfx->doUpdate();
|
2009-06-06 17:39:13 +00:00
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
pressAnyKey();
|
|
|
|
}
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
void Troll::drawTroll() {
|
2007-09-20 21:55:15 +00:00
|
|
|
for (int i = 0; i < IDI_TRO_NUM_NONTROLL; i++)
|
|
|
|
if (_currentRoom == _nonTrollRooms[i]) {
|
|
|
|
_isTrollAway = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
drawPic(43, false, false, true);
|
2007-09-20 18:18:10 +00:00
|
|
|
}
|
|
|
|
|
2007-09-18 19:06:05 +00:00
|
|
|
int Troll::drawRoom(char *menu) {
|
2008-01-03 23:55:42 +00:00
|
|
|
int n = 0;
|
2007-09-20 18:18:10 +00:00
|
|
|
bool contFlag = false;
|
2007-09-18 19:06:05 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
if (_currentRoom == 1) {
|
2007-09-20 18:18:10 +00:00
|
|
|
_vm->_picture->setDimensions(IDI_TRO_PIC_WIDTH, IDI_TRO_PIC_HEIGHT);
|
|
|
|
_vm->clearScreen(0x00, false);
|
|
|
|
_vm->_picture->clear();
|
|
|
|
} else {
|
2007-09-18 19:06:05 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
if (_currentRoom != 42) {
|
|
|
|
if (_roomPicDeltas[_currentRoom]) {
|
2007-09-20 18:18:10 +00:00
|
|
|
contFlag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
drawPic(_currentRoom, contFlag, true);
|
|
|
|
_vm->_gfx->doUpdate();
|
2007-09-20 18:18:10 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
if (_currentRoom == 42) {
|
2007-09-20 18:18:10 +00:00
|
|
|
drawPic(44, false, false); // don't clear
|
|
|
|
} else {
|
|
|
|
if (!_isTrollAway) {
|
|
|
|
drawTroll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_gfx->doUpdate();
|
2007-09-18 19:06:05 +00:00
|
|
|
|
|
|
|
char tmp[10];
|
2007-09-20 21:55:15 +00:00
|
|
|
strncat(menu, (char*)_gameData + _locMessagesIdx[_currentRoom], 39);
|
2007-09-18 19:06:05 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2007-09-20 21:55:15 +00:00
|
|
|
if (_roomDescs[_roomPicture - 1].options[i]) {
|
2007-09-18 19:06:05 +00:00
|
|
|
sprintf(tmp, "\n %d.", i);
|
|
|
|
strcat(menu, tmp);
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
strncat(menu, (char *)_gameData + _options[_roomDescs[_roomPicture - 1].options[i]- 1], 35);
|
2007-09-18 19:06:05 +00:00
|
|
|
|
|
|
|
n = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
void Troll::playTune(int tune, int len) {
|
2007-09-20 21:55:15 +00:00
|
|
|
if (!_soundOn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int freq, duration;
|
|
|
|
int ptr = _tunes[tune - 1];
|
|
|
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
freq = READ_LE_UINT16(_gameData + ptr);
|
|
|
|
ptr += 2;
|
|
|
|
duration = READ_LE_UINT16(_gameData + ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
2007-11-19 20:34:26 +00:00
|
|
|
_vm->playNote(freq, duration);
|
2007-09-20 21:55:15 +00:00
|
|
|
}
|
2007-09-20 18:18:10 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
void Troll::pickupTreasure(int treasureId) {
|
2007-09-20 18:18:10 +00:00
|
|
|
char tmp[40];
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
_inventory[IDI_TRO_MAX_TREASURE - _treasuresLeft] = treasureId;
|
2007-09-20 18:18:10 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
if (_currentRoom != 24) {
|
2007-09-20 18:18:10 +00:00
|
|
|
_vm->clearTextArea();
|
2007-09-20 21:55:15 +00:00
|
|
|
drawPic(_currentRoom, false, true);
|
2007-09-20 18:18:10 +00:00
|
|
|
_vm->_gfx->doUpdate();
|
|
|
|
}
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
printUserMessage(treasureId + 16);
|
2007-09-20 18:18:10 +00:00
|
|
|
|
|
|
|
_vm->clearTextArea();
|
|
|
|
|
|
|
|
_treasuresLeft--;
|
|
|
|
|
|
|
|
switch (_treasuresLeft) {
|
|
|
|
case 1:
|
|
|
|
_vm->drawStr(22, 1, kColorDefault, IDS_TRO_TREASURE_7);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
_vm->drawStr(22, 1, kColorDefault, IDS_TRO_TREASURE_8);
|
|
|
|
_vm->drawStr(23, 4, kColorDefault, IDS_TRO_TREASURE_9);
|
|
|
|
|
|
|
|
_roomStates[6] = 1;
|
|
|
|
|
|
|
|
_locMessagesIdx[6] = IDO_TRO_ALLTREASURES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(tmp, IDS_TRO_TREASURE_3, _treasuresLeft);
|
|
|
|
_vm->drawStr(22, 1, kColorDefault, tmp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pressAnyKey();
|
|
|
|
}
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
void Troll::printUserMessage(int msgId) {
|
2007-09-20 18:18:10 +00:00
|
|
|
int i;
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
_vm->clearTextArea();
|
|
|
|
|
|
|
|
for (i = 0; i < _userMessages[msgId - 1].num; i++) {
|
|
|
|
_vm->drawStr(21 + i, 1, kColorDefault, _userMessages[msgId - 1].msg[i]);
|
2007-09-20 18:18:10 +00:00
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
if (msgId == 34) {
|
2007-09-20 18:18:10 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
playTune(5, 11);
|
|
|
|
}
|
|
|
|
pressAnyKey();
|
|
|
|
}
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
void Troll::gameLoop() {
|
|
|
|
bool done = false;
|
2007-09-18 19:06:05 +00:00
|
|
|
char menu[160+5];
|
|
|
|
int currentOption, numberOfOptions;
|
2007-09-20 21:55:15 +00:00
|
|
|
int roomParam;
|
|
|
|
int haveFlashlight;
|
2007-09-18 19:06:05 +00:00
|
|
|
|
|
|
|
_moves = 0;
|
2007-09-20 21:55:15 +00:00
|
|
|
_roomPicture = 1;
|
2007-09-18 19:06:05 +00:00
|
|
|
_treasuresLeft = IDI_TRO_MAX_TREASURE;
|
2007-09-20 21:55:15 +00:00
|
|
|
haveFlashlight = false;
|
|
|
|
_currentRoom = 0;
|
2007-09-20 18:18:10 +00:00
|
|
|
_isTrollAway = true;
|
2007-09-20 21:55:15 +00:00
|
|
|
_soundOn = true;
|
2007-09-18 20:23:06 +00:00
|
|
|
|
|
|
|
memset(_roomStates, 0, sizeof(_roomStates));
|
2007-09-20 18:18:10 +00:00
|
|
|
|
|
|
|
memset(_inventory, 0, sizeof(_inventory));
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-01-05 00:51:54 +00:00
|
|
|
while (!done && !_vm->shouldQuit()) {
|
2007-09-18 19:06:05 +00:00
|
|
|
*menu = 0;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-09-18 19:06:05 +00:00
|
|
|
currentOption = 0;
|
2007-09-18 16:20:44 +00:00
|
|
|
|
2007-09-18 19:06:05 +00:00
|
|
|
numberOfOptions = drawRoom(menu);
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
if (getMenuSel(menu, ¤tOption, numberOfOptions)) {
|
|
|
|
_moves++;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
roomParam = _roomDescs[_roomPicture - 1].roomDescIndex[currentOption];
|
2007-09-18 16:20:44 +00:00
|
|
|
|
2009-09-30 16:16:53 +00:00
|
|
|
switch (_roomDescs[_roomPicture - 1].optionTypes[currentOption]) {
|
2007-09-20 21:55:15 +00:00
|
|
|
case OT_FLASHLIGHT:
|
|
|
|
if (!haveFlashlight) {
|
|
|
|
printUserMessage(13);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall down
|
2007-09-18 20:23:06 +00:00
|
|
|
case OT_GO:
|
2007-09-20 21:55:15 +00:00
|
|
|
_currentRoom = roomParam;
|
|
|
|
_roomPicture = _roomPicStartIdx[_currentRoom];
|
|
|
|
_roomPicture += _roomStates[_currentRoom];
|
|
|
|
|
|
|
|
if (_currentRoom < 6 || _treasuresLeft == 0) {
|
|
|
|
_isTrollAway = true;
|
|
|
|
} else { // make odd 1:3
|
|
|
|
_isTrollAway = (_vm->rnd(3) != 2);
|
|
|
|
}
|
2007-09-18 16:20:44 +00:00
|
|
|
break;
|
2007-09-20 18:18:10 +00:00
|
|
|
case OT_GET:
|
|
|
|
if (!_isTrollAway) {
|
2007-09-20 21:55:15 +00:00
|
|
|
printUserMessage(34);
|
2007-09-20 18:18:10 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
playTune(1, 3);
|
|
|
|
// delayMillis()
|
|
|
|
}
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
_roomStates[_currentRoom] = 1;
|
|
|
|
_roomPicDeltas[_currentRoom] = 0;
|
2007-09-20 18:18:10 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
_roomPicture++;
|
2007-09-20 18:18:10 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
if (_roomConnects[roomParam - 1] != 0xff) {
|
|
|
|
_roomStates[_roomConnects[roomParam - 1]] = 1;
|
2007-09-20 18:18:10 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
if (roomParam == 1)
|
|
|
|
haveFlashlight = true;
|
2007-09-20 18:18:10 +00:00
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
_locMessagesIdx[_currentRoom] = IDO_TRO_LOCMESSAGES +
|
2007-09-20 21:55:15 +00:00
|
|
|
(roomParam + 42) * 39;
|
2007-09-20 18:18:10 +00:00
|
|
|
|
2007-09-20 21:55:15 +00:00
|
|
|
pickupTreasure(roomParam);
|
2007-09-20 18:18:10 +00:00
|
|
|
}
|
2007-09-20 21:55:15 +00:00
|
|
|
break;
|
|
|
|
case OT_DO:
|
|
|
|
if (roomParam != 16) {
|
|
|
|
printUserMessage(roomParam);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done = true;
|
|
|
|
break;
|
2007-09-18 20:23:06 +00:00
|
|
|
default:
|
2007-09-18 19:33:05 +00:00
|
|
|
break;
|
2007-09-18 16:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-18 19:06:05 +00:00
|
|
|
void Troll::fillOffsets() {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < IDI_TRO_PICNUM; i++)
|
|
|
|
_pictureOffsets[i] = READ_LE_UINT16(_gameData + IDO_TRO_PIC_START + i * 2);
|
|
|
|
|
|
|
|
for (i = 0; i < IDI_TRO_NUM_OPTIONS; i++)
|
|
|
|
_options[i] = READ_LE_UINT16(_gameData + IDO_TRO_OPTIONS + i * 2);
|
2007-09-18 20:23:06 +00:00
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
for (i = 0; i < IDI_TRO_NUM_NUMROOMS; i++) {
|
2007-09-18 20:23:06 +00:00
|
|
|
_roomPicStartIdx[i] = _gameData[IDO_TRO_PICSTARTIDX + i];
|
2007-09-20 18:18:10 +00:00
|
|
|
_roomPicDeltas[i] = _gameData[IDO_TRO_ROOMPICDELTAS + i];
|
|
|
|
_roomConnects[i] = _gameData[IDO_TRO_ROOMCONNECTS + i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < IDI_TRO_NUM_LOCDESCS; i++)
|
|
|
|
_locMessagesIdx[i] = IDO_TRO_LOCMESSAGES + i * 39;
|
2007-09-18 19:06:05 +00:00
|
|
|
|
|
|
|
int start = READ_LE_UINT16(_gameData + IDO_TRO_ROOMDESCS);
|
|
|
|
int ptr;
|
|
|
|
int j;
|
|
|
|
|
2007-09-20 18:18:10 +00:00
|
|
|
for (i = 0; i < IDI_TRO_NUM_ROOMDESCS; i++, start += 2) {
|
2007-09-18 19:06:05 +00:00
|
|
|
ptr = READ_LE_UINT16(_gameData + start);
|
|
|
|
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
_roomDescs[i].options[j] = _gameData[ptr++];
|
|
|
|
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
switch (_gameData[ptr++]) {
|
|
|
|
case 0:
|
|
|
|
_roomDescs[i].optionTypes[j] = OT_GO;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_roomDescs[i].optionTypes[j] = OT_GET;
|
|
|
|
break;
|
|
|
|
case 2:
|
2007-09-20 21:55:15 +00:00
|
|
|
_roomDescs[i].optionTypes[j] = OT_DO;
|
2007-09-18 19:06:05 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2007-09-20 21:55:15 +00:00
|
|
|
_roomDescs[i].optionTypes[j] = OT_FLASHLIGHT;
|
2007-09-18 19:06:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Bad data @ (%x) %d", ptr - 1, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
_roomDescs[i].roomDescIndex[j] = _gameData[ptr++];
|
2007-09-20 18:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start = IDO_TRO_USERMESSAGES;
|
|
|
|
|
|
|
|
for (i = 0; i < IDI_TRO_NUM_USERMSGS; i++, start += 2) {
|
|
|
|
ptr = READ_LE_UINT16(_gameData + start);
|
|
|
|
|
|
|
|
_userMessages[i].num = _gameData[ptr++];
|
|
|
|
|
|
|
|
for (j = 0; j < _userMessages[i].num; j++, ptr += 39) {
|
|
|
|
memcpy(_userMessages[i].msg[j], _gameData + ptr, 39);
|
|
|
|
_userMessages[i].msg[j][39] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
start = IDO_TRO_ITEMS;
|
|
|
|
|
|
|
|
for (i = 0; i < IDI_TRO_MAX_TREASURE; i++, start += 2) {
|
|
|
|
ptr = READ_LE_UINT16(_gameData + start);
|
|
|
|
_items[i].bg = _gameData[ptr++];
|
|
|
|
_items[i].fg = _gameData[ptr++];
|
|
|
|
memcpy(_items[i].name, _gameData + ptr, 15);
|
|
|
|
_items[i].name[15] = 0;
|
2007-09-18 19:06:05 +00:00
|
|
|
}
|
2007-09-20 21:55:15 +00:00
|
|
|
|
|
|
|
for (i = 0; i < IDO_TRO_NONTROLLROOMS; i++)
|
|
|
|
_nonTrollRooms[i] = _gameData[IDO_TRO_NONTROLLROOMS + i];
|
|
|
|
|
|
|
|
_tunes[0] = 0x3BFD;
|
|
|
|
_tunes[1] = 0x3C09;
|
|
|
|
_tunes[2] = 0x3C0D;
|
|
|
|
_tunes[3] = 0x3C11;
|
|
|
|
_tunes[4] = 0x3C79;
|
|
|
|
_tunes[5] = 0x3CA5;
|
2007-09-18 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init
|
|
|
|
|
|
|
|
void Troll::init() {
|
2008-01-28 00:14:17 +00:00
|
|
|
_vm->_picture->setPictureVersion(AGIPIC_V15);
|
2007-09-18 16:20:44 +00:00
|
|
|
//SetScreenPar(320, 200, (char*)ibm_fontdata);
|
|
|
|
|
2007-09-22 20:19:55 +00:00
|
|
|
const int gaps[] = { 0x3A40, 0x4600, 0x4800, 0x5800, 0x5a00, 0x6a00,
|
|
|
|
0x6c00, 0x7400, 0x7600, 0x7c00, 0x7e00, 0x8e00,
|
|
|
|
0x9000, 0xa000, 0xa200, 0xb200, 0xb400, 0xc400,
|
|
|
|
0xc600, 0xd600, 0xd800, 0xe800, 0xea00, 0xfa00,
|
|
|
|
0xfc00, 0x10c00, 0x10e00, 0x11e00, 0x12000, 0x13000 };
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
Common::File infile;
|
|
|
|
if (!infile.open(IDA_TRO_BINNAME))
|
|
|
|
return;
|
|
|
|
|
2007-09-22 20:19:55 +00:00
|
|
|
_gameData = (byte *)malloc(0xD9C0);
|
|
|
|
|
|
|
|
bool flip = true;
|
|
|
|
byte *ptr = _gameData;
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
for (int i = 0; i < ARRAYSIZE(gaps) - 1; i++) {
|
|
|
|
diff = gaps[i + 1] - gaps[i];
|
|
|
|
|
|
|
|
if (flip) {
|
|
|
|
infile.seek(gaps[i]);
|
|
|
|
infile.read(ptr, diff);
|
|
|
|
ptr += diff;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
flip = !flip;
|
|
|
|
}
|
|
|
|
|
|
|
|
// One sector is off
|
|
|
|
infile.seek(0x18470);
|
|
|
|
infile.read(_gameData + 15632, 592);
|
|
|
|
|
2007-09-18 16:20:44 +00:00
|
|
|
infile.close();
|
|
|
|
|
2007-09-18 19:06:05 +00:00
|
|
|
fillOffsets();
|
2007-09-18 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Troll::run() {
|
2009-01-05 00:51:54 +00:00
|
|
|
while (!_vm->shouldQuit()) {
|
2007-09-20 21:55:15 +00:00
|
|
|
intro();
|
|
|
|
gameLoop();
|
|
|
|
gameOver();
|
|
|
|
}
|
2007-09-18 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Agi
|