[Scummvm-cvs-logs] CVS: scummvm/sword1 control.cpp,1.12,1.13 control.h,1.4,1.5 music.cpp,1.9,1.10 sound.h,1.8,1.9 sword1.cpp,1.24,1.25 sword1.h,1.9,1.10

Robert G?ffringmann lavosspawn at users.sourceforge.net
Tue Dec 30 14:58:01 CET 2003


Update of /cvsroot/scummvm/scummvm/sword1
In directory sc8-pr-cvs1:/tmp/cvs-serv12854/sword1

Modified Files:
	control.cpp control.h music.cpp sound.h sword1.cpp sword1.h 
Log Message:
cd changing code and checking for savegames on startup

Index: control.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/control.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- control.cpp	29 Dec 2003 16:01:47 -0000	1.12
+++ control.cpp	30 Dec 2003 22:57:52 -0000	1.13
@@ -153,11 +153,61 @@
 	_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
@@ -460,6 +510,18 @@
 	}
 	delete outf;
 	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) {

Index: control.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/control.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- control.h	29 Dec 2003 15:38:16 -0000	1.4
+++ control.h	30 Dec 2003 22:57:52 -0000	1.5
@@ -67,6 +67,8 @@
 	~SwordControl(void);
 	uint8 runPanel(void);
 	void doRestore(void);
+	void askForCd(void);
+	bool savegamesExist(void);
 private:
 	void initData(void);
 	void closeData(void);

Index: music.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/music.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- music.cpp	28 Dec 2003 23:24:03 -0000	1.9
+++ music.cpp	30 Dec 2003 22:57:52 -0000	1.10
@@ -189,8 +189,12 @@
 				_fadeBuf = NULL;
 			}
 		}
-	} else if (_playing)
-		fadeDown();
+	} else {
+		if (_playing)
+			fadeDown();
+		if (_musicFile.isOpen())
+			_musicFile.close();
+	}
 	_system->unlock_mutex(_mutex);
 	stream();
 }

Index: sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/sound.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sound.h	28 Dec 2003 23:24:03 -0000	1.8
+++ sound.h	30 Dec 2003 22:57:52 -0000	1.9
@@ -61,6 +61,7 @@
 	~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 @@
 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);

Index: sword1.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/sword1.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- sword1.cpp	28 Dec 2003 23:24:03 -0000	1.24
+++ sword1.cpp	30 Dec 2003 22:57:52 -0000	1.25
@@ -58,7 +58,9 @@
 	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 @@
 	_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 @@
 	_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 @@
 	_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::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) {

Index: sword1.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword1/sword1.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- sword1.h	24 Dec 2003 00:25:18 -0000	1.9
+++ sword1.h	30 Dec 2003 22:57:52 -0000	1.10
@@ -37,11 +37,10 @@
 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 @@
 	void delay(uint amount);
 	void initialize(void);
 
+	void checkCdFiles(void);
 	void checkCd(void);
 	uint8 mainLoop(void);
 	void startPositions(int32 startNumber);





More information about the Scummvm-git-logs mailing list