aboutsummaryrefslogtreecommitdiff
path: root/sword1
diff options
context:
space:
mode:
Diffstat (limited to 'sword1')
-rw-r--r--sword1/control.cpp64
-rw-r--r--sword1/control.h2
-rw-r--r--sword1/music.cpp8
-rw-r--r--sword1/sound.h2
-rw-r--r--sword1/sword1.cpp75
-rw-r--r--sword1/sword1.h4
6 files changed, 127 insertions, 28 deletions
diff --git a/sword1/control.cpp b/sword1/control.cpp
index d7c69050d3..8a0b0207f1 100644
--- a/sword1/control.cpp
+++ b/sword1/control.cpp
@@ -153,11 +153,61 @@ SwordControl::SwordControl(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system,
_mouse = pMouse;
_music = pMusic;
strcpy(_savePath, savePath);
+ _lStrings = _languageStrings + MIN(SwordEngine::_systemVars.language, (uint8)BS1_SPANISH) * 20;
+}
+
+void SwordControl::askForCd(void) {
+ _screenBuf = (uint8*)malloc(640 * 480);
+ _font = (uint8*)_resMan->openFetchRes(SR_FONT);
+ uint8 *pal = (uint8*)_resMan->openFetchRes(SR_PALETTE);
+ uint8 *palOut = (uint8*)malloc(256 * 4);
+ for (uint16 cnt = 1; cnt < 256; cnt++) {
+ palOut[cnt * 4 + 0] = pal[cnt * 3 + 0] << 2;
+ palOut[cnt * 4 + 1] = pal[cnt * 3 + 1] << 2;
+ palOut[cnt * 4 + 2] = pal[cnt * 3 + 2] << 2;
+ }
+ palOut[0] = palOut[1] = palOut[2] = palOut[3] = 0;
+ _resMan->resClose(SR_PALETTE);
+ _system->set_palette(palOut, 0, 256);
+ free(palOut);
+
+ File test;
+ char fName[10], textA[50];
+ sprintf(fName, "cd%d.id", SwordEngine::_systemVars.currentCD);
+ sprintf(textA, "%s%d", _lStrings[STR_INSERT_CD_A], SwordEngine::_systemVars.currentCD);
+ bool notAccepted = true;
+ bool refreshText = true;
+ do {
+ if (refreshText) {
+ memset(_screenBuf, 0, 640 * 480);
+ renderText(textA, 320, 220, TEXT_CENTER);
+ renderText(_lStrings[STR_INSERT_CD_B], 320, 240, TEXT_CENTER);
+ _system->copy_rect(_screenBuf, 640, 0, 0, 640, 480);
+ _system->update_screen();
+ }
+ delay(300);
+ if (_keyPressed) {
+ test.open(fName);
+ if (!test.isOpen()) {
+ memset(_screenBuf, 0, 640 * 480);
+ renderText(_lStrings[STR_INCORRECT_CD], 320, 230, TEXT_CENTER);
+ _system->copy_rect(_screenBuf, 640, 0, 0, 640, 480);
+ _system->update_screen();
+ delay(2000);
+ refreshText = true;
+ } else {
+ test.close();
+ notAccepted = false;
+ }
+ }
+ } while (notAccepted);
+
+ _resMan->resClose(SR_FONT);
+ free(_screenBuf);
}
uint8 SwordControl::runPanel(void) {
_restoreBuf = NULL;
- _lStrings = _languageStrings + MIN(SwordEngine::_systemVars.language, (uint8)BS1_SPANISH) * 20;
_keyPressed = _numButtons = 0;
_screenBuf = (uint8*)malloc(640 * 480);
_font = (uint8*)_resMan->openFetchRes(SR_FONT); // todo: czech support
@@ -462,6 +512,18 @@ void SwordControl::writeSavegameDescriptions(void) {
delete mgr;
}
+bool SwordControl::savegamesExist(void) {
+ bool retVal = false;
+ SaveFileManager *mgr = _system->get_savefile_manager();
+ SaveFile *inf;
+ inf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_READ);
+ if (inf->isOpen())
+ retVal = true;
+ delete inf;
+ delete mgr;
+ return retVal;
+}
+
void SwordControl::showSavegameNames(void) {
for (uint8 cnt = 0; cnt < 8; cnt++) {
_buttons[cnt]->draw();
diff --git a/sword1/control.h b/sword1/control.h
index 693ffaffb5..8c844fac82 100644
--- a/sword1/control.h
+++ b/sword1/control.h
@@ -67,6 +67,8 @@ public:
~SwordControl(void);
uint8 runPanel(void);
void doRestore(void);
+ void askForCd(void);
+ bool savegamesExist(void);
private:
void initData(void);
void closeData(void);
diff --git a/sword1/music.cpp b/sword1/music.cpp
index 154cf2f6e9..4f76dc21db 100644
--- a/sword1/music.cpp
+++ b/sword1/music.cpp
@@ -189,8 +189,12 @@ void SwordMusic::startMusic(int32 tuneId, int32 loopFlag) {
_fadeBuf = NULL;
}
}
- } else if (_playing)
- fadeDown();
+ } else {
+ if (_playing)
+ fadeDown();
+ if (_musicFile.isOpen())
+ _musicFile.close();
+ }
_system->unlock_mutex(_mutex);
stream();
}
diff --git a/sword1/sound.h b/sword1/sound.h
index 975d3df256..c249493dd5 100644
--- a/sword1/sound.h
+++ b/sword1/sound.h
@@ -61,6 +61,7 @@ public:
~SwordSound(void);
void newScreen(uint32 screen);
void quitScreen(void);
+ void closeCowSystem(void);
bool startSpeech(uint16 roomNo, uint16 localNo);
bool speechFinished(void);
@@ -75,7 +76,6 @@ public:
private:
void playSample(QueueElement *elem);
void initCowSystem(void);
- void closeCowSystem(void);
int16 *uncompressSpeech(uint32 index, uint32 cSize, uint32 *size);
void calcWaveVolume(int16 *data, uint32 length);
diff --git a/sword1/sword1.cpp b/sword1/sword1.cpp
index 21c4287364..19bbe51a03 100644
--- a/sword1/sword1.cpp
+++ b/sword1/sword1.cpp
@@ -58,7 +58,9 @@ DetectedGameList Engine_SWORD1_detectGames(const FSList &fslist) {
for (FSList::ConstIterator file = fslist.begin(); file != fslist.end(); ++file) {
const char *gameName = file->displayName().c_str();
- if (0 == scumm_stricmp("swordres.rif", gameName)) {
+ if ((0 == scumm_stricmp("swordres.rif", gameName)) ||
+ (0 == scumm_stricmp("cd1.id", gameName)) ||
+ (0 == scumm_stricmp("cd2.id", gameName))) {
// Match found, add to list of candidates, then abort inner loop.
detectedGames.push_back(sword1_setting);
break;
@@ -116,7 +118,6 @@ void SwordEngine::initialize(void) {
_systemVars.justRestoredGame = _systemVars.currentCD =
_systemVars.gamePaused = 0;
_systemVars.deathScreenFlag = 3;
- _systemVars.rate = 8;
_systemVars.forceRestart = false;
switch (Common::parseLanguage(ConfMan.get("language"))) {
@@ -158,7 +159,7 @@ void SwordEngine::reinitialize(void) {
_logic->initialize(); // now reinitialize these objects as they (may) have locked
_objectMan->initialize(); // resources which have just been wiped.
_mouse->initialize();
- // todo: reinitialize swordmenu.
+ _system->warp_mouse(320, 240);
_systemVars.wantFade = true;
}
@@ -1026,28 +1027,53 @@ void SwordEngine::startPositions(int32 startNumber) {
_systemVars.wantFade = true;
}
+void SwordEngine::checkCdFiles(void) { // check if we're running from cd, hdd or what...
+ File test;
+
+ _systemVars.playSpeech = true;
+ if (test.open("SPEECH1.CLU")) {
+ test.close();
+ if (test.open("SPEECH2.CLU")) {
+ // both files exist, assume running from HDD and everything's fine.
+ test.close();
+ _systemVars.runningFromCd = false;
+ _systemVars.playSpeech = true;
+ return ;
+ } else
+ error("SPEECH2.CLU not found.\nPlease copy the SPEECH.CLU from CD2 and rename it to SPEECH2.CLU");
+ } else { // speech1.clu & speech2.clu not present. are we running from cd?
+ if (test.open("cd1.id")) {
+ _systemVars.runningFromCd = true;
+ _systemVars.currentCD = 1;
+ test.close();
+ } else if (test.open("cd2.id")) {
+ _systemVars.runningFromCd = true;
+ _systemVars.currentCD = 2;
+ test.close();
+ } else
+ error("Unable to find files.\nPlease read the instructions again");
+ }
+}
+
void SwordEngine::go(void) {
initialize();
- _systemVars.deathScreenFlag = 3;
- // check if we have savegames. if we do, show control panel, else start intro.
- /* death flags:
- 0 = not dead, normal game
- 1 = dead
- 2 = game won
- 3 = game was just started */
+ checkCdFiles();
uint8 startPos = ConfMan.getInt("boot_param");
- if (startPos) {
+ if (startPos)
startPositions(startPos);
- _systemVars.deathScreenFlag = 0;
- } else {
- // Temporary:
- startPositions(0);
- _systemVars.deathScreenFlag = 0;
- //todo: check if we have savegames. if we do, show control panel, else start intro.
- //control->runPanel();
+ else {
+ if (_control->savegamesExist()) {
+ _systemVars.deathScreenFlag = 3;
+ if (_control->runPanel() == CONTROL_GAME_RESTORED)
+ _control->doRestore();
+ else
+ startPositions(0);
+ } else // no savegames, start new game.
+ startPositions(0);
}
+ _systemVars.deathScreenFlag = 0;
do {
uint8 action = mainLoop();
@@ -1065,11 +1091,16 @@ void SwordEngine::go(void) {
void SwordEngine::checkCd(void) {
uint8 needCd = _cdList[SwordLogic::_scriptVars[NEW_SCREEN]];
- if (needCd == 0) {
- if (_systemVars.currentCD == 0)
- _systemVars.currentCD = 1;
- } else
+ if ((needCd == 0) && (_systemVars.currentCD == 0))
+ needCd = 1;
+ if (needCd != _systemVars.currentCD) {
_systemVars.currentCD = needCd;
+ if (_systemVars.runningFromCd) {
+ _music->startMusic(0, 0);
+ _sound->closeCowSystem();
+ _control->askForCd();
+ }
+ }
}
uint8 SwordEngine::mainLoop(void) {
diff --git a/sword1/sword1.h b/sword1/sword1.h
index b169ad861c..aea5252d0f 100644
--- a/sword1/sword1.h
+++ b/sword1/sword1.h
@@ -37,11 +37,10 @@ class SwordMusic;
class SwordControl;
struct SystemVars {
- // todo: move these to a better place
+ bool runningFromCd;
uint32 currentCD; // starts at zero, then either 1 or 2 depending on section being played
uint32 justRestoredGame; // see main() in sword.c & New_screen() in gtm_core.c
uint32 gamePaused; // 1 when paused
- uint32 rate; // game rate => what's this for?
uint8 deathScreenFlag; // 1 death screen version of the control panel, 2 = successful end of game, 3 = force restart
bool forceRestart;
@@ -64,6 +63,7 @@ private:
void delay(uint amount);
void initialize(void);
+ void checkCdFiles(void);
void checkCd(void);
uint8 mainLoop(void);
void startPositions(int32 startNumber);