2003-03-05 19:04:34 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2003 The ScummVM project
|
|
|
|
*
|
|
|
|
* 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
|
2003-03-06 02:37:37 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-03-05 19:04:34 +00:00
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-03-05 21:34:46 +00:00
|
|
|
#include "stdafx.h"
|
2003-03-05 19:04:34 +00:00
|
|
|
#include "sky/sky.h"
|
|
|
|
#include "sky/skydefs.h" //game specific defines
|
2003-04-25 15:17:53 +00:00
|
|
|
#include "sky/compact.h"
|
|
|
|
#include "sky/logic.h"
|
|
|
|
#include "sky/debug.h"
|
2003-05-05 13:19:59 +00:00
|
|
|
#include "sky/mouse.h"
|
2003-03-05 19:04:34 +00:00
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/gameDetector.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
|
|
|
|
extern bool toolbar_drawn;
|
|
|
|
extern bool draw_keyboard;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const VersionSettings sky_settings[] = {
|
|
|
|
/* Beneath a Steel Sky */
|
|
|
|
{"sky", "Beneath a Steel Sky", GID_SKY_FIRST, 99, 99, 99, 0, "sky.dsk" },
|
|
|
|
{NULL, NULL, 0, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2003-03-07 14:52:24 +00:00
|
|
|
const VersionSettings *Engine_SKY_targetList() {
|
2003-03-05 19:04:34 +00:00
|
|
|
return sky_settings;
|
|
|
|
}
|
|
|
|
|
2003-03-07 14:52:24 +00:00
|
|
|
Engine *Engine_SKY_create(GameDetector *detector, OSystem *syst) {
|
2003-03-05 19:04:34 +00:00
|
|
|
return new SkyState(detector, syst);
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:17:53 +00:00
|
|
|
void **SkyState::_itemList[300];
|
|
|
|
|
2003-06-02 06:42:42 +00:00
|
|
|
SystemVars SkyState::_systemVars = {0, 0, 0, 0, 4316};
|
2003-06-01 21:21:10 +00:00
|
|
|
|
2003-03-05 19:04:34 +00:00
|
|
|
SkyState::SkyState(GameDetector *detector, OSystem *syst)
|
2003-03-07 14:52:24 +00:00
|
|
|
: Engine(detector, syst) {
|
|
|
|
|
2003-03-05 19:04:34 +00:00
|
|
|
_game = detector->_gameId;
|
|
|
|
|
2003-03-08 12:46:51 +00:00
|
|
|
if (!_mixer->bindToSystem(syst))
|
2003-03-12 16:54:30 +00:00
|
|
|
warning("Sound initialisation failed.");
|
2003-03-08 12:46:51 +00:00
|
|
|
|
|
|
|
_mixer->setVolume(detector->_sfx_volume); //unnecessary?
|
|
|
|
|
2003-03-05 19:04:34 +00:00
|
|
|
_debugMode = detector->_debugMode;
|
2003-06-06 18:08:16 +00:00
|
|
|
_debugLevel = detector->_debugLevel;
|
2003-06-01 21:21:10 +00:00
|
|
|
_systemVars.language = detector->_language;
|
2003-05-03 02:59:45 +00:00
|
|
|
_detector = detector;
|
2003-05-21 21:01:12 +00:00
|
|
|
|
|
|
|
_introTextSpace = 0;
|
|
|
|
_introTextSave = 0;
|
2003-03-05 19:04:34 +00:00
|
|
|
}
|
|
|
|
|
2003-05-27 16:42:20 +00:00
|
|
|
void SkyState::showQuitMsg(void) {
|
|
|
|
|
|
|
|
uint8 *textBuf1 = (uint8*)calloc(GAME_SCREEN_WIDTH * 14 + sizeof(struct dataFileHeader),1);
|
|
|
|
uint8 *textBuf2 = (uint8*)calloc(GAME_SCREEN_WIDTH * 14 + sizeof(struct dataFileHeader),1);
|
|
|
|
char *vText1, *vText2;
|
|
|
|
uint8 *screenData = _skyScreen->giveCurrent();
|
2003-06-01 21:21:10 +00:00
|
|
|
switch (_systemVars.language) {
|
2003-05-27 16:42:20 +00:00
|
|
|
case DE_DEU: vText1 = VIG_DE1; vText2 = VIG_DE2; break;
|
|
|
|
case FR_FRA: vText1 = VIG_FR1; vText2 = VIG_FR2; break;
|
|
|
|
case IT_ITA: vText1 = VIG_IT1; vText2 = VIG_IT2; break;
|
|
|
|
case PT_BRA: vText1 = VIG_PT1; vText2 = VIG_PT2; break;
|
|
|
|
default: vText1 = VIG_EN1; vText2 = VIG_EN2; break;
|
|
|
|
}
|
|
|
|
_skyText->displayText(vText1, textBuf1, true, 320, 255);
|
|
|
|
_skyText->displayText(vText2, textBuf2, true, 320, 255);
|
|
|
|
uint8 *curLine1 = textBuf1 + sizeof(struct dataFileHeader);
|
|
|
|
uint8 *curLine2 = textBuf2 + sizeof(struct dataFileHeader);
|
|
|
|
uint8 *targetLine = screenData + GAME_SCREEN_WIDTH * 80;
|
|
|
|
for (uint8 cnty = 0; cnty < 14; cnty++) {
|
|
|
|
for (uint16 cntx = 0; cntx < GAME_SCREEN_WIDTH; cntx++) {
|
|
|
|
if (curLine1[cntx])
|
|
|
|
targetLine[cntx] = curLine1[cntx];
|
|
|
|
if (curLine2[cntx])
|
|
|
|
(targetLine + 24 * GAME_SCREEN_WIDTH)[cntx] = curLine2[cntx];
|
|
|
|
}
|
|
|
|
curLine1 += GAME_SCREEN_WIDTH;
|
|
|
|
curLine2 += GAME_SCREEN_WIDTH;
|
|
|
|
targetLine += GAME_SCREEN_WIDTH;
|
|
|
|
}
|
|
|
|
_skyScreen->halvePalette();
|
|
|
|
_skyScreen->showScreen(screenData);
|
|
|
|
free(textBuf1); free(textBuf2);
|
|
|
|
}
|
|
|
|
|
2003-03-07 14:52:24 +00:00
|
|
|
SkyState::~SkyState() {
|
2003-05-27 16:42:20 +00:00
|
|
|
|
|
|
|
delete _skyLogic;
|
|
|
|
delete _skySound;
|
|
|
|
delete _skyMusic;
|
2003-06-01 12:49:39 +00:00
|
|
|
showQuitMsg();
|
2003-05-27 16:42:20 +00:00
|
|
|
delete _skyText;
|
|
|
|
delete _skyMouse;
|
|
|
|
delete _skyScreen;
|
|
|
|
delay(1500);
|
2003-03-05 19:04:34 +00:00
|
|
|
}
|
|
|
|
|
2003-03-07 15:38:11 +00:00
|
|
|
void SkyState::errorString(const char *buf1, char *buf2) {
|
|
|
|
strcpy(buf2, buf1);
|
|
|
|
}
|
|
|
|
|
2003-03-07 14:52:24 +00:00
|
|
|
void SkyState::go() {
|
|
|
|
|
2003-03-05 19:04:34 +00:00
|
|
|
if (!_dump_file)
|
|
|
|
_dump_file = stdout;
|
|
|
|
|
|
|
|
initialise();
|
2003-04-25 15:17:53 +00:00
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
if (!isDemo() || isCDVersion())
|
2003-04-25 15:41:14 +00:00
|
|
|
intro();
|
2003-04-25 15:17:53 +00:00
|
|
|
|
2003-06-01 03:44:07 +00:00
|
|
|
_skyDisk->flushPrefetched();
|
|
|
|
|
2003-05-01 14:10:42 +00:00
|
|
|
loadBase0();
|
2003-05-27 16:42:20 +00:00
|
|
|
|
2003-03-05 19:04:34 +00:00
|
|
|
while (1) {
|
2003-06-01 03:44:07 +00:00
|
|
|
delay(50);
|
2003-06-05 18:54:26 +00:00
|
|
|
_skyMouse->mouseEngine((uint16)_sdl_mouse_x, (uint16)_sdl_mouse_y);
|
2003-04-25 15:17:53 +00:00
|
|
|
_skyLogic->engine();
|
2003-05-29 03:51:05 +00:00
|
|
|
_skyScreen->recreate();
|
2003-05-28 21:29:50 +00:00
|
|
|
_skyScreen->spriteEngine();
|
|
|
|
_skyScreen->flip();
|
2003-06-01 22:53:44 +00:00
|
|
|
_system->update_screen();
|
2003-03-05 19:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-07 14:52:24 +00:00
|
|
|
void SkyState::initialise(void) {
|
|
|
|
|
2003-03-06 02:37:37 +00:00
|
|
|
//initialise_memory();
|
2003-03-08 12:46:51 +00:00
|
|
|
|
2003-04-07 20:44:52 +00:00
|
|
|
_skyDisk = new SkyDisk(_gameDataPath);
|
2003-05-16 15:33:18 +00:00
|
|
|
_skySound = new SkySound(_mixer, _skyDisk);
|
2003-05-03 02:59:45 +00:00
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
_systemVars.gameVersion = _skyDisk->determineGameVersion();
|
2003-05-28 23:31:43 +00:00
|
|
|
|
2003-05-12 23:25:54 +00:00
|
|
|
if (_detector->getMidiDriverType() == MD_ADLIB) {
|
2003-06-01 21:21:10 +00:00
|
|
|
_systemVars.systemFlags |= SF_SBLASTER;
|
|
|
|
_skyMusic = new SkyAdlibMusic(_mixer, _skyDisk);
|
2003-05-03 02:59:45 +00:00
|
|
|
} else {
|
2003-06-01 21:21:10 +00:00
|
|
|
_systemVars.systemFlags |= SF_ROLAND;
|
|
|
|
_skyMusic = new SkyGmMusic(_detector->createMidi(), _skyDisk);
|
2003-05-03 02:59:45 +00:00
|
|
|
}
|
2003-06-02 03:30:41 +00:00
|
|
|
_systemVars.systemFlags |= SF_PLAY_VOCS;
|
2003-05-03 02:59:45 +00:00
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
_skyText = new SkyText(_skyDisk);
|
2003-06-05 18:54:26 +00:00
|
|
|
_skyMouse = new SkyMouse(_system, _skyDisk);
|
2003-05-14 22:33:39 +00:00
|
|
|
_skyScreen = new SkyScreen(_system, _skyDisk);
|
2003-05-27 16:42:20 +00:00
|
|
|
|
2003-03-07 14:52:24 +00:00
|
|
|
initVirgin();
|
2003-04-05 18:01:29 +00:00
|
|
|
initItemList();
|
|
|
|
//initScript();
|
|
|
|
//initialiseRouter();
|
2003-05-01 14:10:42 +00:00
|
|
|
loadFixedItems();
|
2003-06-02 06:42:42 +00:00
|
|
|
_skyLogic = new SkyLogic(_skyScreen, _skyDisk, _skyText, _skyMusic, _skyMouse, _skySound);
|
2003-06-05 18:54:26 +00:00
|
|
|
_skyMouse->useLogicInstance(_skyLogic);
|
2003-05-14 22:33:39 +00:00
|
|
|
|
|
|
|
_timer = Engine::_timer; // initialize timer *after* _skyScreen has been initialized.
|
|
|
|
_timer->installProcedure(&timerHandler, 1000000 / 50); //call 50 times per second
|
2003-04-05 18:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkyState::initItemList() {
|
|
|
|
|
|
|
|
//See List.asm for (cryptic) item # descriptions
|
|
|
|
|
|
|
|
for (int i = 0; i < 300; i++)
|
2003-04-25 15:17:53 +00:00
|
|
|
_itemList[i] = (void **)NULL;
|
2003-04-05 18:01:29 +00:00
|
|
|
|
|
|
|
//init the non-null items
|
2003-04-25 15:17:53 +00:00
|
|
|
_itemList[119] = (void **)SkyCompact::data_0; // Compacts - Section 0
|
|
|
|
_itemList[120] = (void **)SkyCompact::data_1; // Compacts - Section 1
|
2003-04-05 18:01:29 +00:00
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
if (isDemo()) {
|
2003-04-25 15:17:53 +00:00
|
|
|
_itemList[121] = _itemList[122] = _itemList[123] = _itemList[124] = _itemList[125] = (void **)SkyCompact::data_0;
|
2003-04-05 18:01:29 +00:00
|
|
|
} else {
|
2003-04-25 15:17:53 +00:00
|
|
|
_itemList[121] = (void **)SkyCompact::data_2; // Compacts - Section 2
|
|
|
|
_itemList[122] = (void **)SkyCompact::data_3; // Compacts - Section 3
|
|
|
|
_itemList[123] = (void **)SkyCompact::data_4; // Compacts - Section 4
|
|
|
|
_itemList[124] = (void **)SkyCompact::data_5; // Compacts - Section 5
|
|
|
|
_itemList[125] = (void **)SkyCompact::data_6; // Compacts - Section 6
|
2003-04-05 18:01:29 +00:00
|
|
|
}
|
2003-04-25 15:17:53 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 14:10:42 +00:00
|
|
|
void SkyState::loadBase0(void) {
|
|
|
|
|
2003-05-28 20:55:25 +00:00
|
|
|
_skyLogic->fnEnterSection(0, 0, 0);
|
2003-05-01 14:10:42 +00:00
|
|
|
_skyMusic->startMusic(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkyState::loadFixedItems(void) {
|
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
if (!isDemo())
|
2003-05-01 14:10:42 +00:00
|
|
|
_itemList[36] = (void **)_skyDisk->loadFile(26, NULL);
|
|
|
|
|
|
|
|
_itemList[49] = (void **)_skyDisk->loadFile(49, NULL);
|
|
|
|
_itemList[50] = (void **)_skyDisk->loadFile(50, NULL);
|
|
|
|
_itemList[73] = (void **)_skyDisk->loadFile(73, NULL);
|
|
|
|
_itemList[262] = (void **)_skyDisk->loadFile(262, NULL);
|
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
if (isDemo())
|
2003-05-01 14:10:42 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
_itemList[263] = (void **)_skyDisk->loadFile(263, NULL);
|
|
|
|
_itemList[264] = (void **)_skyDisk->loadFile(264, NULL);
|
|
|
|
_itemList[265] = (void **)_skyDisk->loadFile(265, NULL);
|
|
|
|
_itemList[266] = (void **)_skyDisk->loadFile(266, NULL);
|
|
|
|
_itemList[267] = (void **)_skyDisk->loadFile(267, NULL);
|
|
|
|
_itemList[269] = (void **)_skyDisk->loadFile(269, NULL);
|
|
|
|
_itemList[271] = (void **)_skyDisk->loadFile(271, NULL);
|
|
|
|
_itemList[272] = (void **)_skyDisk->loadFile(272, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-05-27 16:42:20 +00:00
|
|
|
void **SkyState::fetchItem(uint32 num) {
|
|
|
|
|
|
|
|
return _itemList[num];
|
|
|
|
}
|
|
|
|
|
2003-05-14 22:33:39 +00:00
|
|
|
void SkyState::timerHandler(void *ptr) {
|
|
|
|
|
|
|
|
((SkyState*)ptr)->gotTimerTick();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkyState::gotTimerTick(void) {
|
|
|
|
|
|
|
|
_skyScreen->handleTimer();
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:17:53 +00:00
|
|
|
Compact *SkyState::fetchCompact(uint32 a) {
|
|
|
|
SkyDebug::fetchCompact(a);
|
|
|
|
uint32 sectionNum = (a & 0xf000) >> 12;
|
|
|
|
uint32 compactNum = (a & 0x0fff);
|
|
|
|
|
|
|
|
return (Compact *)(_itemList[119 + sectionNum][compactNum]);
|
2003-03-05 19:04:34 +00:00
|
|
|
}
|
|
|
|
|
2003-03-07 14:52:24 +00:00
|
|
|
void SkyState::delay(uint amount) { //copied and mutilated from Simon.cpp
|
|
|
|
|
2003-03-05 19:04:34 +00:00
|
|
|
OSystem::Event event;
|
|
|
|
|
|
|
|
uint32 start = _system->get_msecs();
|
|
|
|
uint32 cur = start;
|
2003-04-29 20:42:47 +00:00
|
|
|
_key_pressed = 0; //reset
|
2003-03-05 19:04:34 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
while (_system->poll_event(&event)) {
|
|
|
|
switch (event.event_code) {
|
|
|
|
case OSystem::EVENT_KEYDOWN:
|
|
|
|
// Make sure backspace works right (this fixes a small issue on OS X)
|
|
|
|
if (event.kbd.keycode == 8)
|
|
|
|
_key_pressed = 8;
|
|
|
|
else
|
|
|
|
_key_pressed = (byte)event.kbd.ascii;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
|
|
|
_sdl_mouse_x = event.mouse.x;
|
|
|
|
_sdl_mouse_y = event.mouse.y;
|
2003-06-01 12:49:39 +00:00
|
|
|
_system->set_mouse_pos(_sdl_mouse_x, _sdl_mouse_y);
|
2003-03-05 19:04:34 +00:00
|
|
|
break;
|
|
|
|
|
2003-06-05 18:54:26 +00:00
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
2003-06-06 01:14:17 +00:00
|
|
|
_skyMouse->buttonPressed(1);
|
2003-03-05 19:04:34 +00:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
_sdl_mouse_x = event.mouse.x;
|
|
|
|
_sdl_mouse_y = event.mouse.y;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OSystem::EVENT_RBUTTONDOWN:
|
2003-06-06 01:14:17 +00:00
|
|
|
_skyMouse->buttonPressed(2);
|
2003-03-05 19:04:34 +00:00
|
|
|
break;
|
2003-05-29 21:45:26 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2003-03-05 19:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (amount == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
{
|
|
|
|
uint this_delay = 20; // 1?
|
|
|
|
if (this_delay > amount)
|
|
|
|
this_delay = amount;
|
|
|
|
_system->delay_msecs(this_delay);
|
|
|
|
}
|
|
|
|
cur = _system->get_msecs();
|
|
|
|
} while (cur < start + amount);
|
|
|
|
}
|
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
bool SkyState::isDemo(void) {
|
|
|
|
switch (_systemVars.gameVersion) {
|
2003-04-07 20:44:52 +00:00
|
|
|
case 267:
|
|
|
|
return true;
|
|
|
|
case 288:
|
|
|
|
return false;
|
2003-04-21 14:12:19 +00:00
|
|
|
case 303:
|
|
|
|
return false;
|
2003-04-07 20:44:52 +00:00
|
|
|
case 331:
|
|
|
|
return false;
|
|
|
|
case 365:
|
|
|
|
return true;
|
|
|
|
case 368:
|
|
|
|
return false;
|
2003-04-08 12:19:15 +00:00
|
|
|
case 372:
|
|
|
|
return false;
|
2003-04-07 20:44:52 +00:00
|
|
|
default:
|
2003-04-20 22:01:57 +00:00
|
|
|
error("Unknown game version");
|
2003-04-07 20:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
bool SkyState::isCDVersion(void) {
|
2003-05-29 03:26:28 +00:00
|
|
|
|
2003-06-01 21:21:10 +00:00
|
|
|
switch (_systemVars.gameVersion) {
|
2003-04-07 20:44:52 +00:00
|
|
|
case 267:
|
|
|
|
return false;
|
|
|
|
case 288:
|
|
|
|
return false;
|
2003-04-21 14:12:19 +00:00
|
|
|
case 303:
|
|
|
|
return false;
|
2003-04-07 20:44:52 +00:00
|
|
|
case 331:
|
|
|
|
return false;
|
|
|
|
case 365:
|
|
|
|
return true;
|
|
|
|
case 368:
|
|
|
|
return true;
|
2003-04-08 12:19:15 +00:00
|
|
|
case 372:
|
|
|
|
return true;
|
2003-04-07 20:44:52 +00:00
|
|
|
default:
|
2003-04-20 22:01:57 +00:00
|
|
|
error("Unknown game version");
|
2003-04-07 20:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|