DRAGONS: Adding class for loading dragon.img file data

This commit is contained in:
Eric Fry 2019-01-29 22:44:53 +11:00 committed by Eugene Sandulenko
parent a25ee6f255
commit 22d15cc7ca
5 changed files with 150 additions and 1 deletions

View File

@ -0,0 +1,62 @@
/* 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.
*
*/
#include <common/memstream.h>
#include "dragonimg.h"
#include "bigfile.h"
namespace Dragons {
DragonIMG::DragonIMG(BigfileArchive *bigfileArchive) {
uint32 fileSize;
byte *iptData = bigfileArchive->load("dragon.ipt", fileSize);
Common::SeekableReadStream *iptReadStream = new Common::MemoryReadStream(iptData, fileSize, DisposeAfterUse::YES);
_count = fileSize / 4;
byte *imgData = bigfileArchive->load("dragon.img", fileSize);
Common::SeekableReadStream *imgReadStream = new Common::MemoryReadStream(imgData, fileSize, DisposeAfterUse::YES);
_imgObjects = new IMG[_count];
for(int i=0; i < _count; i++) {
imgReadStream->seek(iptReadStream->readUint32LE());
_imgObjects[i].field_0 = imgReadStream->readUint16LE();
_imgObjects[i].field_2 = imgReadStream->readUint16LE();
_imgObjects[i].field_4 = imgReadStream->readUint16LE();
_imgObjects[i].field_6 = imgReadStream->readUint16LE();
_imgObjects[i].field_8 = imgReadStream->readUint16LE();
_imgObjects[i].field_a = imgReadStream->readUint16LE();
_imgObjects[i].field_c = imgReadStream->readUint16LE();
_imgObjects[i].field_e = imgReadStream->readUint16LE();
}
}
IMG *DragonIMG::getIMG(uint32 iptId) {
iptId &= 0xffff;
assert(iptId > 1);
assert(iptId < _count);
return &_imgObjects[iptId];
}
} // End of namespace Dragons

View File

@ -0,0 +1,53 @@
/* 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.
*
*/
#ifndef SCUMMVM_DRAGONIMG_H
#define SCUMMVM_DRAGONIMG_H
#include "common/system.h"
namespace Dragons {
struct IMG {
uint16 field_0;
uint16 field_2;
uint16 field_4;
uint16 field_6;
uint16 field_8;
uint16 field_a;
uint16 field_c;
uint16 field_e;
};
class BigfileArchive;
class DragonIMG {
private:
int16 _count;
IMG *_imgObjects;
public:
DragonIMG(BigfileArchive *bigfileArchive);
IMG *getIMG(uint32 iptId);
};
} // End of namespace Dragons
#endif //SCUMMVM_DRAGONIMG_H

View File

@ -28,6 +28,7 @@
#include "background.h"
#include "bigfile.h"
#include "dragonflg.h"
#include "dragonimg.h"
#include "dragonini.h"
#include "dragonobd.h"
#include "dragonrms.h"
@ -84,6 +85,7 @@ Common::Error DragonsEngine::run() {
_screen = new Screen();
_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
_dragonFLG = new DragonFLG(_bigfileArchive);
_dragonIMG = new DragonIMG(_bigfileArchive);
_dragonOBD = new DragonOBD(_bigfileArchive);
_dragonRMS = new DragonRMS(_bigfileArchive, _dragonOBD);
_dragonVAR = new DragonVAR(_bigfileArchive);
@ -127,6 +129,7 @@ Common::Error DragonsEngine::run() {
delete _actorManager;
delete _backgroundResourceLoader;
delete _dragonFLG;
delete _dragonIMG;
delete _dragonRMS;
delete _dragonVAR;
delete _bigfileArchive;
@ -171,7 +174,10 @@ void DragonsEngine::gameLoop() {
}
if (flickerIni->sceneId == getCurrentSceneId()) {
debug("get here");
uint16 id = getIniFromImg();
if (id != 0) {
error("todo 0x80026cb0 run script");
}
}
_scene->draw();
_screen->updateScreen();
@ -361,4 +367,28 @@ void DragonsEngine::setVar(uint16 offset, uint16 value) {
return _dragonVAR->setVar(offset, value);
}
uint16 DragonsEngine::getIniFromImg() {
DragonINI *flicker = _dragonINIResource->getFlickerRecord();
int16 x = flicker->actor->x_pos / 32;
int16 y = flicker->actor->y_pos / 8;
uint16 currentSceneId = _scene->getSceneId();
for(uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
DragonINI *ini = getINI(i);
if (ini->sceneId == currentSceneId && ini->field_1a_flags_maybe == 0) {
IMG *img = _dragonIMG->getIMG(ini->field_2);
if (x >= img->field_0 &&
img->field_0 + img->field_4 >= x &&
y >= img->field_2 &&
img->field_6 + img->field_2 >= y) {
return i + 1;
}
}
}
return 0;
}
} // End of namespace Dragons

View File

@ -82,6 +82,7 @@ enum UnkFlags {
class BigfileArchive;
class BackgroundResourceLoader;
class DragonFLG;
class DragonIMG;
class DragonOBD;
class DragonRMS;
class DragonVAR;
@ -96,6 +97,7 @@ struct DragonINI;
class DragonsEngine : public Engine {
public:
DragonOBD *_dragonOBD;
DragonIMG *_dragonIMG;
ActorManager *_actorManager;
DragonINIResource *_dragonINIResource;
private:
@ -146,6 +148,7 @@ private:
void updateHandler();
uint32 calulateTimeLeft();
void wait();
uint16 getIniFromImg();
};
DragonsEngine *getEngine();

View File

@ -7,6 +7,7 @@ MODULE_OBJS := \
bigfile.o \
detection.o \
dragonflg.o \
dragonimg.o \
dragonini.o \
dragonobd.o \
dragonrms.o \