scummvm/engines/sludge/objtypes.cpp

144 lines
3.8 KiB
C++
Raw Permalink Normal View History

/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
2017-06-05 19:10:47 +02:00
2017-12-19 22:15:55 +01:00
#include "sludge/fileset.h"
2017-06-05 19:10:47 +02:00
#include "sludge/moreio.h"
2017-12-19 22:15:55 +01:00
#include "sludge/newfatal.h"
#include "sludge/objtypes.h"
2017-07-18 19:03:45 +02:00
#include "sludge/sludge.h"
#include "sludge/version.h"
2017-05-26 21:25:11 +02:00
namespace Sludge {
2017-07-18 19:50:45 +02:00
ObjectManager::~ObjectManager() {
kill();
}
bool ObjectManager::init() {
_allObjectTypes.clear();
return true;
}
void ObjectManager::kill() {
2017-07-18 19:50:45 +02:00
ObjectTypeList::iterator it;
for (it = _allObjectTypes.begin(); it != _allObjectTypes.end(); ++it) {
delete [](*it)->allCombis;
delete (*it);
(*it) = nullptr;
}
_allObjectTypes.clear();
}
2017-07-18 19:50:45 +02:00
ObjectType *ObjectManager::findObjectType(int i) {
ObjectTypeList::iterator it;
for (it = _allObjectTypes.begin(); it != _allObjectTypes.end(); ++it) {
if ((*it)->objectNum == i) {
return (*it);
}
}
return loadObjectType(i);
}
2017-07-18 19:50:45 +02:00
ObjectType *ObjectManager::loadObjectType(int i) {
int a, nameNum;
2017-07-18 19:50:45 +02:00
ObjectType *newType = new ObjectType;
ResourceManager *rm = _vm->_resMan;
if (checkNew(newType)) {
2017-07-18 19:50:45 +02:00
if (rm->openObjectSlice(i)) {
Common::SeekableReadStream *readStream = rm->getData();
2017-07-18 19:03:45 +02:00
nameNum = readStream->readUint16BE();
newType->r = (byte)readStream->readByte();
newType->g = (byte)readStream->readByte();
newType->b = (byte)readStream->readByte();
newType->speechGap = readStream->readByte();
newType->walkSpeed = readStream->readByte();
newType->wrapSpeech = readStream->readUint32LE();
newType->spinSpeed = readStream->readUint16BE();
if (gameVersion >= VERSION(1, 6)) {
// aaLoad
2017-07-18 19:03:45 +02:00
readStream->readByte();
readStream->readFloatLE();
readStream->readFloatLE();
}
if (gameVersion >= VERSION(1, 4)) {
2017-07-18 19:03:45 +02:00
newType->flags = readStream->readUint16BE();
} else {
2017-05-29 08:02:59 +02:00
newType->flags = 0;
}
2017-07-18 19:03:45 +02:00
newType->numCom = readStream->readUint16BE();
2017-07-18 19:50:45 +02:00
newType->allCombis = (newType->numCom) ? new Combination[newType->numCom] : nullptr;
2017-05-29 08:02:59 +02:00
for (a = 0; a < newType->numCom; a++) {
2017-07-18 19:03:45 +02:00
newType->allCombis[a].withObj = readStream->readUint16BE();
newType->allCombis[a].funcNum = readStream->readUint16BE();
}
2017-07-15 17:33:10 +02:00
2017-07-18 19:50:45 +02:00
rm->finishAccess();
newType->screenName = rm->getNumberedString(nameNum);
2017-05-29 08:02:59 +02:00
newType->objectNum = i;
2017-07-18 19:50:45 +02:00
_allObjectTypes.push_back(newType);
return newType;
}
}
2017-07-18 19:50:45 +02:00
return nullptr;
}
2017-07-18 19:50:45 +02:00
ObjectType *ObjectManager::loadObjectRef(Common::SeekableReadStream *stream) {
ObjectType *r = loadObjectType(stream->readUint16BE());
r->screenName.clear();
2017-05-29 08:02:59 +02:00
r->screenName = readString(stream);
return r;
}
2017-07-18 19:50:45 +02:00
void ObjectManager::saveObjectRef(ObjectType *r, Common::WriteStream *stream) {
stream->writeUint16BE(r->objectNum);
2017-05-29 08:02:59 +02:00
writeString(r->screenName, stream);
}
2017-07-18 19:50:45 +02:00
int ObjectManager::getCombinationFunction(int withThis, int thisObject) {
int i, num = 0;
2017-07-18 19:50:45 +02:00
ObjectType *obj = findObjectType(thisObject);
2017-05-29 08:02:59 +02:00
for (i = 0; i < obj->numCom; i++) {
if (obj->allCombis[i].withObj == withThis) {
num = obj->allCombis[i].funcNum;
break;
}
}
return num;
}
2017-07-18 19:50:45 +02:00
void ObjectManager::removeObjectType(ObjectType *oT) {
_allObjectTypes.remove(oT);
delete []oT->allCombis;
delete oT;
oT = nullptr;
}
2017-05-26 21:25:11 +02:00
} // End of namespace Sludge