2010-01-07 21:22:41 +02: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.
|
|
|
|
*
|
2010-01-14 12:24:12 +02:00
|
|
|
* MIT License:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
* conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
2010-01-07 21:22:41 +02:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wage/wage.h"
|
2010-01-11 00:44:27 +02:00
|
|
|
#include "wage/entities.h"
|
2010-01-07 23:52:31 +02:00
|
|
|
#include "wage/script.h"
|
|
|
|
#include "wage/world.h"
|
2010-01-07 21:22:41 +02:00
|
|
|
|
2011-05-30 04:37:50 +01:00
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/macresman.h"
|
|
|
|
#include "common/memstream.h"
|
2010-01-07 21:22:41 +02:00
|
|
|
|
|
|
|
namespace Wage {
|
|
|
|
|
2010-01-07 23:52:31 +02:00
|
|
|
World::World() {
|
2010-01-09 01:13:54 +02:00
|
|
|
_storageScene._name = STORAGESCENE;
|
2010-01-09 01:42:28 +02:00
|
|
|
_orderedScenes.push_back(&_storageScene);
|
|
|
|
_scenes[STORAGESCENE] = &_storageScene;
|
2010-01-07 23:52:31 +02:00
|
|
|
}
|
|
|
|
|
2010-01-11 22:46:24 +02:00
|
|
|
bool World::loadWorld(Common::MacResManager *resMan) {
|
|
|
|
Common::MacResIDArray resArray;
|
2011-05-30 17:37:27 +01:00
|
|
|
Common::SeekableReadStream *res;
|
2010-01-11 22:46:24 +02:00
|
|
|
Common::MacResIDArray::const_iterator iter;
|
2010-01-07 21:22:41 +02:00
|
|
|
|
2011-05-30 17:05:26 +01:00
|
|
|
if ((resArray = resMan->getResIDArray(MKTAG('G','C','O','D'))).size() == 0)
|
2010-01-07 23:52:31 +02:00
|
|
|
return false;
|
|
|
|
|
2010-01-09 01:42:28 +02:00
|
|
|
// Load global script
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('G','C','O','D'), resArray[0]);
|
2011-06-01 02:16:39 +01:00
|
|
|
_globalScript = new Script(res);
|
2010-01-07 23:52:31 +02:00
|
|
|
|
2010-01-09 01:42:28 +02:00
|
|
|
// Load main configuration
|
2011-05-30 17:05:26 +01:00
|
|
|
if ((resArray = resMan->getResIDArray(MKTAG('V','E','R','S'))).size() == 0)
|
2010-01-07 21:22:41 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (resArray.size() > 1)
|
|
|
|
warning("Too many VERS resources");
|
|
|
|
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('V','E','R','S'), resArray[0]);
|
2010-01-07 21:22:41 +02:00
|
|
|
|
2011-06-01 02:16:39 +01:00
|
|
|
res->skip(10);
|
|
|
|
byte b = res->readByte();
|
2010-01-07 21:22:41 +02:00
|
|
|
_weaponMenuDisabled = (b != 0);
|
|
|
|
if (b != 0 && b != 1)
|
|
|
|
error("Unexpected value for weapons menu");
|
|
|
|
|
2011-06-01 02:16:39 +01:00
|
|
|
res->skip(3);
|
|
|
|
_aboutMessage = readPascalString(res);
|
2010-01-07 21:22:41 +02:00
|
|
|
|
2010-01-17 14:24:46 +02:00
|
|
|
if (!scumm_stricmp(resMan->getFileName().c_str(), "Scepters"))
|
2011-06-01 02:16:39 +01:00
|
|
|
res->skip(1); // ????
|
2010-01-07 21:22:41 +02:00
|
|
|
|
2011-06-01 02:16:39 +01:00
|
|
|
_soundLibrary1 = readPascalString(res);
|
|
|
|
_soundLibrary2 = readPascalString(res);
|
2010-01-07 21:22:41 +02:00
|
|
|
|
2011-06-01 02:16:39 +01:00
|
|
|
delete res;
|
2010-01-11 00:26:01 +02:00
|
|
|
|
2010-01-09 01:42:28 +02:00
|
|
|
// Load scenes
|
2011-05-30 17:05:26 +01:00
|
|
|
resArray = resMan->getResIDArray(MKTAG('A','S','C','N'));
|
2010-01-09 01:42:28 +02:00
|
|
|
for (iter = resArray.begin(); iter != resArray.end(); ++iter) {
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('A','S','C','N'), *iter);
|
|
|
|
Scene *scene = new Scene(resMan->getResName(MKTAG('A','S','C','N'), *iter), res, res->size());
|
2010-01-09 02:01:58 +02:00
|
|
|
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('A','C','O','D'), *iter);
|
2010-01-09 02:01:58 +02:00
|
|
|
if (res != NULL)
|
2011-05-30 17:37:27 +01:00
|
|
|
scene->_script = new Script(res, res->size());
|
2010-01-11 00:26:01 +02:00
|
|
|
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('A','T','X','T'), *iter);
|
2010-01-11 00:26:01 +02:00
|
|
|
if (res != NULL) {
|
2011-06-01 02:16:39 +01:00
|
|
|
scene->_textBounds = readRect(res);
|
|
|
|
scene->_fontType = res->readUint16BE();
|
|
|
|
scene->_fontSize = res->readUint16BE();
|
2010-01-11 00:26:01 +02:00
|
|
|
|
2011-05-30 17:37:27 +01:00
|
|
|
for (int i = 12; i < res->size(); i++)
|
2010-01-11 00:26:01 +02:00
|
|
|
if (res[i] == 0x0d)
|
|
|
|
res[i] = '\n';
|
2011-05-30 17:37:27 +01:00
|
|
|
String text(&((char*)res)[12], res->size() - 12);
|
2010-01-11 00:26:01 +02:00
|
|
|
scene->_text = text;
|
|
|
|
|
2011-05-30 17:37:27 +01:00
|
|
|
delete res;
|
2010-01-11 00:26:01 +02:00
|
|
|
}
|
|
|
|
addScene(scene);
|
2010-01-09 01:42:28 +02:00
|
|
|
}
|
|
|
|
|
2010-01-11 00:26:01 +02:00
|
|
|
// Load Objects
|
2011-05-30 17:05:26 +01:00
|
|
|
resArray = resMan->getResIDArray(MKTAG('A','O','B','J'));
|
2010-01-11 00:26:01 +02:00
|
|
|
for (iter = resArray.begin(); iter != resArray.end(); ++iter) {
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('A','O','B','J'), *iter);
|
|
|
|
addObj(new Obj(resMan->getResName(MKTAG('A','O','B','J'), *iter), res, res->size()));
|
2010-01-11 00:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load Characters
|
2011-05-30 17:05:26 +01:00
|
|
|
resArray = resMan->getResIDArray(MKTAG('A','C','H','R'));
|
2010-01-11 00:26:01 +02:00
|
|
|
for (iter = resArray.begin(); iter != resArray.end(); ++iter) {
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('A','C','H','R'), *iter);
|
|
|
|
Chr *chr = new Chr(resMan->getResName(MKTAG('A','C','H','R'), *iter), res, res->size());
|
2010-01-11 00:26:01 +02:00
|
|
|
|
|
|
|
addChr(chr);
|
|
|
|
// TODO: What if there's more than one player character?
|
|
|
|
if (chr->_playerCharacter)
|
|
|
|
_player = chr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load Sounds
|
2011-05-30 17:05:26 +01:00
|
|
|
resArray = resMan->getResIDArray(MKTAG('A','S','N','D'));
|
2010-01-11 00:26:01 +02:00
|
|
|
for (iter = resArray.begin(); iter != resArray.end(); ++iter) {
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('A','S','N','D'), *iter);
|
|
|
|
addSound(new Sound(resMan->getResName(MKTAG('A','S','N','D')), *iter), res, res->size()));
|
2010-01-11 00:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_soundLibrary1.size() > 0) {
|
|
|
|
loadExternalSounds(_soundLibrary1);
|
|
|
|
}
|
|
|
|
if (_soundLibrary2.size() > 0) {
|
|
|
|
loadExternalSounds(_soundLibrary2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load Patterns
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('P','A','T','#'), 900);
|
2010-01-11 00:26:01 +02:00
|
|
|
if (res != NULL) {
|
2011-06-01 02:16:39 +01:00
|
|
|
int count = res->readUint16BE();
|
2010-01-11 00:26:01 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
byte *pattern = (byte *)malloc(8);
|
|
|
|
for (int j = 0; j < 8; j++) {
|
2011-06-01 02:16:39 +01:00
|
|
|
pattern[j] = res->readByte();
|
2010-01-11 00:26:01 +02:00
|
|
|
_patterns.push_back(pattern);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-30 17:37:27 +01:00
|
|
|
delete res;
|
2010-01-11 00:26:01 +02:00
|
|
|
}
|
2010-01-07 21:22:41 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-11 00:44:27 +02:00
|
|
|
void World::loadExternalSounds(String fname) {
|
2010-01-11 21:30:48 +02:00
|
|
|
Common::File in;
|
|
|
|
|
|
|
|
in.open(fname);
|
|
|
|
if (!in.isOpen()) {
|
|
|
|
warning("Cannot load sound file <%s>", fname.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
|
2010-01-11 22:46:24 +02:00
|
|
|
Common::MacResManager *resMan;
|
|
|
|
resMan = new Common::MacResManager(fname);
|
2010-01-11 21:30:48 +02:00
|
|
|
|
2010-01-11 22:46:24 +02:00
|
|
|
Common::MacResIDArray resArray;
|
2011-05-30 17:37:27 +01:00
|
|
|
Common::SeekableReadStream *res;
|
2010-01-11 22:46:24 +02:00
|
|
|
Common::MacResIDArray::const_iterator iter;
|
2010-01-11 21:30:48 +02:00
|
|
|
|
2011-05-30 17:05:26 +01:00
|
|
|
resArray = resMan->getResIDArray(MKTAG('A','S','N','D'));
|
2010-01-11 21:30:48 +02:00
|
|
|
for (iter = resArray.begin(); iter != resArray.end(); ++iter) {
|
2011-05-30 17:37:27 +01:00
|
|
|
res = resMan->getResource(MKTAG('A','S','N','D'), *iter);
|
|
|
|
addSound(new Sound(resMan->getResName(MKTAG('A','S','N','D'), *iter), res, res->size()));
|
2010-01-11 21:30:48 +02:00
|
|
|
}
|
2010-01-11 00:44:27 +02:00
|
|
|
}
|
|
|
|
|
2010-01-07 21:22:41 +02:00
|
|
|
} // End of namespace Wage
|