2018-10-19 23:22:30 +11: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "engines/util.h"
|
|
|
|
#include "graphics/thumbnail.h"
|
2018-11-07 22:27:05 +11:00
|
|
|
#include "graphics/surface.h"
|
2018-10-19 23:22:30 +11:00
|
|
|
#include "common/error.h"
|
2018-12-03 18:06:01 +11:00
|
|
|
#include "actor.h"
|
|
|
|
#include "actorresource.h"
|
2019-01-15 07:19:54 +11:00
|
|
|
#include "background.h"
|
2018-11-07 22:27:05 +11:00
|
|
|
#include "bigfile.h"
|
2019-03-05 21:39:44 +11:00
|
|
|
#include "cursor.h"
|
2019-01-26 22:36:45 +11:00
|
|
|
#include "dragonflg.h"
|
2019-01-29 22:44:53 +11:00
|
|
|
#include "dragonimg.h"
|
2018-11-07 22:27:05 +11:00
|
|
|
#include "dragonini.h"
|
2019-01-22 22:11:00 +11:00
|
|
|
#include "dragonobd.h"
|
|
|
|
#include "dragonrms.h"
|
2019-01-26 22:36:45 +11:00
|
|
|
#include "dragonvar.h"
|
2018-10-19 23:22:30 +11:00
|
|
|
#include "dragons.h"
|
2019-03-03 22:25:00 +11:00
|
|
|
#include "inventory.h"
|
2018-11-07 22:27:05 +11:00
|
|
|
#include "scene.h"
|
|
|
|
#include "screen.h"
|
2018-12-18 22:52:18 +11:00
|
|
|
#include "sequenceopcodes.h"
|
2019-01-22 22:11:00 +11:00
|
|
|
#include "scriptopcodes.h"
|
2018-10-19 23:22:30 +11:00
|
|
|
|
|
|
|
namespace Dragons {
|
|
|
|
|
2018-12-13 22:30:30 +11:00
|
|
|
#define DRAGONS_TICK_INTERVAL 17
|
|
|
|
|
2019-01-15 07:19:54 +11:00
|
|
|
static DragonsEngine *_engine = nullptr;
|
|
|
|
|
|
|
|
DragonsEngine *getEngine() {
|
|
|
|
return _engine;
|
|
|
|
}
|
|
|
|
|
2018-10-19 23:22:30 +11:00
|
|
|
DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
|
2018-11-07 22:27:05 +11:00
|
|
|
_bigfileArchive = NULL;
|
|
|
|
_dragonRMS = NULL;
|
|
|
|
_backgroundResourceLoader = NULL;
|
|
|
|
_screen = NULL;
|
2018-12-13 22:30:30 +11:00
|
|
|
_nextUpdatetime = 0;
|
|
|
|
_flags = 0;
|
2019-01-05 13:26:55 +11:00
|
|
|
_unkFlags1 = 0;
|
2018-12-18 22:52:18 +11:00
|
|
|
_sequenceOpcodes = new SequenceOpcodes(this);
|
2019-01-26 22:36:45 +11:00
|
|
|
_scriptOpcodes = NULL;
|
2019-01-15 07:19:54 +11:00
|
|
|
_engine = this;
|
|
|
|
_cursorPosition = Common::Point();
|
2019-02-01 23:07:04 +11:00
|
|
|
_cursorSequenceID = 0;
|
2019-02-02 23:42:01 +11:00
|
|
|
run_func_ptr_unk_countdown_timer = 0;
|
2019-03-03 22:25:00 +11:00
|
|
|
data_8006a3a0_flag = 0;
|
|
|
|
data_800633fa = 0;
|
2019-03-10 08:59:10 +11:00
|
|
|
data_8006f3a8 = 0;
|
2019-03-03 22:25:00 +11:00
|
|
|
_inventory = new Inventory(this);
|
2019-03-05 21:39:44 +11:00
|
|
|
_cursor = new Cursor(this);
|
2018-10-19 23:22:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
DragonsEngine::~DragonsEngine() {
|
2018-12-18 22:52:18 +11:00
|
|
|
delete _sequenceOpcodes;
|
2019-01-22 22:11:00 +11:00
|
|
|
delete _scriptOpcodes;
|
2018-10-19 23:22:30 +11:00
|
|
|
}
|
|
|
|
|
2018-11-07 22:27:05 +11:00
|
|
|
void DragonsEngine::updateEvents() {
|
|
|
|
Common::Event event;
|
|
|
|
while (_eventMan->pollEvent(event)) {
|
|
|
|
// _input->processEvent(event);
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
quitGame();
|
|
|
|
break;
|
2019-03-05 23:17:40 +11:00
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
_cursor->updatePosition(event.mouse.x, event.mouse.y);
|
|
|
|
break;
|
2018-11-07 22:27:05 +11:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-02 23:42:01 +11:00
|
|
|
|
2018-10-19 23:22:30 +11:00
|
|
|
Common::Error DragonsEngine::run() {
|
2018-11-07 22:27:05 +11:00
|
|
|
_screen = new Screen();
|
|
|
|
_bigfileArchive = new BigfileArchive("bigfile.dat", Common::Language::EN_ANY);
|
2019-01-26 22:36:45 +11:00
|
|
|
_dragonFLG = new DragonFLG(_bigfileArchive);
|
2019-01-29 22:44:53 +11:00
|
|
|
_dragonIMG = new DragonIMG(_bigfileArchive);
|
2019-01-22 22:11:00 +11:00
|
|
|
_dragonOBD = new DragonOBD(_bigfileArchive);
|
|
|
|
_dragonRMS = new DragonRMS(_bigfileArchive, _dragonOBD);
|
2019-01-26 22:36:45 +11:00
|
|
|
_dragonVAR = new DragonVAR(_bigfileArchive);
|
2018-11-07 22:27:05 +11:00
|
|
|
_dragonINIResource = new DragonINIResource(_bigfileArchive);
|
2018-12-03 18:06:01 +11:00
|
|
|
ActorResourceLoader *actorResourceLoader = new ActorResourceLoader(_bigfileArchive);
|
2018-12-18 10:28:15 +11:00
|
|
|
_actorManager = new ActorManager(actorResourceLoader);
|
2019-01-26 22:36:45 +11:00
|
|
|
_scriptOpcodes = new ScriptOpcodes(this, _dragonFLG);
|
2019-01-22 22:11:00 +11:00
|
|
|
_scene = new Scene(this, _screen, _scriptOpcodes, _bigfileArchive, _actorManager, _dragonRMS, _dragonINIResource);
|
2018-12-18 10:28:15 +11:00
|
|
|
_flags = 0x1046;
|
2019-02-02 23:42:01 +11:00
|
|
|
_flags &= 0x1c07040;
|
|
|
|
_flags |= 0x26;
|
2018-11-07 22:27:05 +11:00
|
|
|
|
2019-03-05 21:39:44 +11:00
|
|
|
_cursor->init(_actorManager, _dragonINIResource);
|
2019-03-03 22:25:00 +11:00
|
|
|
_inventory->init(_actorManager);
|
2019-01-15 07:19:54 +11:00
|
|
|
|
2019-02-01 23:07:04 +11:00
|
|
|
uint16 sceneId = 0x12;
|
|
|
|
_dragonINIResource->getFlickerRecord()->sceneId = sceneId; //TODO
|
|
|
|
_sceneId1 = sceneId;
|
|
|
|
_scene->loadScene(sceneId, 0x1e);
|
2018-11-07 22:27:05 +11:00
|
|
|
|
|
|
|
_scene->draw();
|
|
|
|
_screen->updateScreen();
|
2018-12-13 22:30:30 +11:00
|
|
|
|
|
|
|
gameLoop();
|
2018-11-07 22:27:05 +11:00
|
|
|
|
2018-12-18 10:28:15 +11:00
|
|
|
delete _scene;
|
|
|
|
delete _actorManager;
|
2018-11-07 22:27:05 +11:00
|
|
|
delete _backgroundResourceLoader;
|
2019-01-26 22:36:45 +11:00
|
|
|
delete _dragonFLG;
|
2019-01-29 22:44:53 +11:00
|
|
|
delete _dragonIMG;
|
2018-11-07 22:27:05 +11:00
|
|
|
delete _dragonRMS;
|
2019-01-26 22:36:45 +11:00
|
|
|
delete _dragonVAR;
|
2018-11-07 22:27:05 +11:00
|
|
|
delete _bigfileArchive;
|
|
|
|
delete _screen;
|
|
|
|
|
2018-10-19 23:22:30 +11:00
|
|
|
debug("Ok");
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2018-12-13 22:30:30 +11:00
|
|
|
void DragonsEngine::gameLoop() {
|
2019-01-28 21:20:54 +11:00
|
|
|
_counter = 0;
|
|
|
|
bit_flags_8006fbd8 = 0;
|
2018-12-13 22:30:30 +11:00
|
|
|
while (!shouldQuit()) {
|
2018-12-18 10:28:15 +11:00
|
|
|
updateHandler();
|
2018-12-13 22:30:30 +11:00
|
|
|
updateEvents();
|
2019-01-28 21:20:54 +11:00
|
|
|
|
|
|
|
if (getCurrentSceneId() != 2) {
|
|
|
|
_sceneId1 = getCurrentSceneId();
|
|
|
|
}
|
|
|
|
|
|
|
|
_counter++;
|
|
|
|
DragonINI *flickerIni = _dragonINIResource->getFlickerRecord();
|
|
|
|
if (_counter >= 1200 && flickerIni->actor->resourceID == 0xe) { // 0xe == flicker.act
|
|
|
|
Actor *actor = flickerIni->actor;
|
|
|
|
actor->_sequenceID2 = 2;
|
|
|
|
flickerIni->field_20_actor_field_14 = 2;
|
|
|
|
|
|
|
|
actor->updateSequence(getINI(0xc2)->sceneId == 1 ? 0x30 : 2);
|
|
|
|
_counter = 0;
|
|
|
|
setFlags(Dragons::ENGINE_FLAG_80000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_flags & Dragons::ENGINE_FLAG_80000000) {
|
|
|
|
if (flickerIni->actor->flags & Dragons::ACTOR_FLAG_4) {
|
|
|
|
_counter = 0;
|
|
|
|
clearFlags(Dragons::ENGINE_FLAG_80000000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bit_flags_8006fbd8 == 0) {
|
|
|
|
setFlags(Dragons::ENGINE_FLAG_8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flickerIni->sceneId == getCurrentSceneId()) {
|
2019-01-29 22:44:53 +11:00
|
|
|
uint16 id = getIniFromImg();
|
|
|
|
if (id != 0) {
|
2019-03-07 21:24:10 +11:00
|
|
|
// 0x80026cac
|
|
|
|
error("todo 0x80026cac run script");
|
|
|
|
} else {
|
|
|
|
// 0x80026d34
|
|
|
|
// $s4_1 = 0;
|
2019-01-29 22:44:53 +11:00
|
|
|
}
|
2019-03-07 21:24:10 +11:00
|
|
|
} else {
|
|
|
|
// 0x80026d34
|
|
|
|
// $s4_1 = 0;
|
2019-01-28 21:20:54 +11:00
|
|
|
}
|
2019-02-02 23:42:01 +11:00
|
|
|
|
2019-03-07 21:24:10 +11:00
|
|
|
// 0x80026d38
|
|
|
|
_cursor->updateINIUnderCursor();
|
|
|
|
|
2019-02-02 23:42:01 +11:00
|
|
|
runINIScripts();
|
|
|
|
|
2019-01-05 13:26:55 +11:00
|
|
|
_scene->draw();
|
|
|
|
_screen->updateScreen();
|
2018-12-13 22:30:30 +11:00
|
|
|
wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::updateHandler() {
|
2019-03-03 22:25:00 +11:00
|
|
|
data_8006a3a0_flag |= 0x40;
|
2019-02-24 23:18:30 +11:00
|
|
|
//TODO logic here
|
|
|
|
|
2018-12-18 10:28:15 +11:00
|
|
|
updateActorSequences();
|
2019-01-05 13:26:55 +11:00
|
|
|
|
2019-03-05 21:39:44 +11:00
|
|
|
_cursor->updateVisibility();
|
|
|
|
_inventory->updateVisibility();
|
|
|
|
|
2019-01-05 13:26:55 +11:00
|
|
|
//TODO logic here
|
|
|
|
for (uint16 i = 0; i < 0x17; i++) {
|
|
|
|
Actor *actor = _actorManager->getActor(i);
|
|
|
|
if (actor->flags & Dragons::ACTOR_FLAG_40) {
|
|
|
|
if (!(actor->flags & Dragons::ACTOR_FLAG_100)) {
|
|
|
|
int16 priority = _scene->getPriorityAtPosition(Common::Point(actor->x_pos, actor->y_pos));
|
|
|
|
DragonINI *flicker = _dragonINIResource->getFlickerRecord();
|
|
|
|
if (flicker && _scene->contains(flicker) && flicker->actor->_actorID == i) {
|
|
|
|
if (priority < 8 || priority == 0x10) {
|
2019-01-15 07:19:54 +11:00
|
|
|
actor->priorityLayer = priority;
|
2019-01-05 13:26:55 +11:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (priority != -1) {
|
2019-01-15 07:19:54 +11:00
|
|
|
actor->priorityLayer = priority;
|
2019-01-05 13:26:55 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 07:19:54 +11:00
|
|
|
if (actor->priorityLayer >= 0x11) {
|
|
|
|
actor->priorityLayer = 0;
|
2019-01-05 13:26:55 +11:00
|
|
|
}
|
|
|
|
|
2019-01-15 07:19:54 +11:00
|
|
|
if (actor->priorityLayer >= 9) {
|
|
|
|
actor->priorityLayer -= 8;
|
2019-01-05 13:26:55 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actor->sequenceTimer != 0) {
|
|
|
|
actor->sequenceTimer--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_flags & Dragons::ENGINE_FLAG_80) {
|
|
|
|
for (uint16 i = 0x17; i < DRAGONS_ENGINE_NUM_ACTORS; i++) {
|
|
|
|
Actor *actor = _actorManager->getActor(i);
|
|
|
|
if (actor->sequenceTimer != 0) {
|
|
|
|
actor->sequenceTimer--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-02 23:42:01 +11:00
|
|
|
|
2019-02-24 23:18:30 +11:00
|
|
|
if (isFlagSet(ENGINE_FLAG_4)) {
|
|
|
|
updatePathfindingActors();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO 0x8001bed0
|
|
|
|
|
|
|
|
// 0x8001c294
|
|
|
|
if (!(_unkFlags1 & ENGINE_UNK1_FLAG_8)) {
|
|
|
|
//TODO ReadPad();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isFlagSet(ENGINE_FLAG_20)) {
|
2019-02-02 23:42:01 +11:00
|
|
|
engineFlag0x20UpdateFunction();
|
|
|
|
}
|
2019-02-23 23:51:03 +11:00
|
|
|
|
2019-02-24 23:18:30 +11:00
|
|
|
//TODO vsync update function
|
|
|
|
|
|
|
|
// TODO data_8006a3a0 logic. @ 0x8001c2f4
|
2019-03-03 22:25:00 +11:00
|
|
|
|
|
|
|
data_8006a3a0_flag &= ~0x40;
|
2018-12-13 22:30:30 +11:00
|
|
|
}
|
|
|
|
|
2018-10-19 23:22:30 +11:00
|
|
|
const char *DragonsEngine::getSavegameFilename(int num) {
|
|
|
|
static Common::String filename;
|
|
|
|
filename = getSavegameFilename(_targetName, num);
|
|
|
|
return filename.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String DragonsEngine::getSavegameFilename(const Common::String &target, int num) {
|
|
|
|
assert(num >= 0 && num <= 999);
|
|
|
|
return Common::String::format("%s.%03d", target.c_str(), num);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DRAGONS_SAVEGAME_VERSION 0
|
|
|
|
|
2019-02-02 23:42:01 +11:00
|
|
|
kReadSaveHeaderError
|
|
|
|
DragonsEngine::readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail) {
|
2018-10-19 23:22:30 +11:00
|
|
|
|
|
|
|
header.version = in->readUint32LE();
|
|
|
|
if (header.version > DRAGONS_SAVEGAME_VERSION)
|
|
|
|
return kRSHEInvalidVersion;
|
|
|
|
|
|
|
|
byte descriptionLen = in->readByte();
|
|
|
|
header.description = "";
|
|
|
|
while (descriptionLen--) {
|
2019-02-02 23:42:01 +11:00
|
|
|
header.description += (char) in->readByte();
|
2018-10-19 23:22:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!Graphics::loadThumbnail(*in, header.thumbnail, skipThumbnail)) {
|
|
|
|
return kRSHEIoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
header.flags = in->readUint32LE();
|
|
|
|
|
|
|
|
header.saveDate = in->readUint32LE();
|
|
|
|
header.saveTime = in->readUint32LE();
|
|
|
|
header.playTime = in->readUint32LE();
|
|
|
|
|
|
|
|
return ((in->eos() || in->err()) ? kRSHEIoError : kRSHENoError);
|
|
|
|
}
|
|
|
|
|
2018-12-13 22:30:30 +11:00
|
|
|
uint32 DragonsEngine::calulateTimeLeft() {
|
|
|
|
uint32 now;
|
|
|
|
|
|
|
|
now = _system->getMillis();
|
|
|
|
|
2019-02-02 23:42:01 +11:00
|
|
|
if (_nextUpdatetime <= now) {
|
2018-12-13 22:30:30 +11:00
|
|
|
_nextUpdatetime = now + DRAGONS_TICK_INTERVAL;
|
2019-02-02 23:42:01 +11:00
|
|
|
return (0);
|
2018-12-13 22:30:30 +11:00
|
|
|
}
|
|
|
|
uint32 delay = _nextUpdatetime - now;
|
|
|
|
_nextUpdatetime += DRAGONS_TICK_INTERVAL;
|
2019-02-02 23:42:01 +11:00
|
|
|
return (delay);
|
2018-12-13 22:30:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::wait() {
|
|
|
|
_system->delayMillis(calulateTimeLeft());
|
|
|
|
}
|
|
|
|
|
2018-12-18 10:28:15 +11:00
|
|
|
void DragonsEngine::updateActorSequences() {
|
|
|
|
if (!(_flags & Dragons::ENGINE_FLAG_4)) {
|
2019-01-28 21:20:54 +11:00
|
|
|
return;
|
2018-12-18 10:28:15 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO ResetRCnt(0xf2000001);
|
|
|
|
|
2019-02-02 23:42:01 +11:00
|
|
|
int16 actorId = _flags & Dragons::ENGINE_FLAG_80 ? (int16) 64 : (int16) 23;
|
2018-12-18 10:28:15 +11:00
|
|
|
|
2019-01-05 13:26:55 +11:00
|
|
|
while (actorId > 0) {
|
2018-12-18 10:28:15 +11:00
|
|
|
actorId--;
|
2019-02-02 23:42:01 +11:00
|
|
|
Actor *actor = _actorManager->getActor((uint16) actorId);
|
2018-12-18 10:28:15 +11:00
|
|
|
if (actorId < 2 && _flags & Dragons::ENGINE_FLAG_40) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actor->flags & Dragons::ACTOR_FLAG_40 &&
|
2019-02-02 23:42:01 +11:00
|
|
|
!(actor->flags & Dragons::ACTOR_FLAG_4) &&
|
|
|
|
!(actor->flags & Dragons::ACTOR_FLAG_400) &&
|
|
|
|
(actor->sequenceTimer == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
|
2018-12-18 10:28:15 +11:00
|
|
|
debug("Actor[%d] execute sequenceOp", actorId);
|
2018-12-18 22:52:18 +11:00
|
|
|
|
|
|
|
if (actor->flags & Dragons::ACTOR_FLAG_1) {
|
|
|
|
actor->resetSequenceIP();
|
|
|
|
actor->flags &= 0xeff6; //TODO rewrite using ACTOR_FLAG_nnn
|
|
|
|
actor->field_7a = 0;
|
|
|
|
}
|
2018-12-18 10:28:15 +11:00
|
|
|
//TODO execute sequence Opcode here.
|
2018-12-18 22:52:18 +11:00
|
|
|
OpCall opCall;
|
2019-01-05 13:26:55 +11:00
|
|
|
opCall._result = 1;
|
|
|
|
while (opCall._result == 1) {
|
|
|
|
opCall._op = (byte) READ_LE_UINT16(actor->_seqCodeIp);
|
|
|
|
opCall._code = actor->_seqCodeIp + 2;
|
|
|
|
_sequenceOpcodes->execOpcode(actor, opCall);
|
|
|
|
actor->_seqCodeIp += opCall._deltaOfs;
|
|
|
|
}
|
2018-12-18 10:28:15 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 13:26:55 +11:00
|
|
|
void DragonsEngine::setFlags(uint32 flags) {
|
|
|
|
_flags |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::clearFlags(uint32 flags) {
|
|
|
|
_flags &= ~flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::setUnkFlags(uint32 flags) {
|
|
|
|
_unkFlags1 |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::clearUnkFlags(uint32 flags) {
|
|
|
|
_unkFlags1 &= ~flags;
|
|
|
|
}
|
|
|
|
|
2019-01-15 07:19:54 +11:00
|
|
|
byte *DragonsEngine::getBackgroundPalette() {
|
|
|
|
assert(_scene);
|
|
|
|
return _scene->getPalette();
|
|
|
|
}
|
|
|
|
|
2019-01-22 22:11:00 +11:00
|
|
|
bool DragonsEngine::isFlagSet(uint32 flag) {
|
2019-02-02 23:42:01 +11:00
|
|
|
return (bool) (_flags & flag);
|
2019-01-22 22:11:00 +11:00
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:00 +11:00
|
|
|
bool DragonsEngine::isUnkFlagSet(uint32 flag) {
|
|
|
|
return (bool) (_unkFlags1 & flag);
|
|
|
|
}
|
|
|
|
|
2019-01-26 22:36:45 +11:00
|
|
|
DragonINI *DragonsEngine::getINI(uint32 index) {
|
|
|
|
return _dragonINIResource->getRecord(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 DragonsEngine::getVar(uint16 offset) {
|
|
|
|
return _dragonVAR->getVar(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 DragonsEngine::getCurrentSceneId() {
|
|
|
|
return _scene->getSceneId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::setVar(uint16 offset, uint16 value) {
|
|
|
|
return _dragonVAR->setVar(offset, value);
|
|
|
|
}
|
|
|
|
|
2019-01-29 22:44:53 +11:00
|
|
|
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();
|
|
|
|
|
2019-02-02 23:42:01 +11:00
|
|
|
for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
|
2019-01-29 22:44:53 +11:00
|
|
|
DragonINI *ini = getINI(i);
|
|
|
|
if (ini->sceneId == currentSceneId && ini->field_1a_flags_maybe == 0) {
|
|
|
|
IMG *img = _dragonIMG->getIMG(ini->field_2);
|
2019-03-03 22:25:00 +11:00
|
|
|
if (x >= img->x &&
|
|
|
|
img->x + img->w >= x &&
|
|
|
|
y >= img->y &&
|
|
|
|
img->h + img->y >= y) {
|
2019-01-29 22:44:53 +11:00
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-01 23:07:04 +11:00
|
|
|
uint16 DragonsEngine::updateINIUnderCursor() {
|
|
|
|
int32 x = (_cursorPosition.x + _scene->_camera.x) / 32;
|
|
|
|
int32 y = (_cursorPosition.y + _scene->_camera.y) / 8;
|
|
|
|
|
|
|
|
if (_flags & Dragons::ENGINE_FLAG_10) {
|
|
|
|
|
2019-03-03 22:25:00 +11:00
|
|
|
if (_inventory->getSequenceId() == 0 || _inventory->getSequenceId() == 2) {
|
2019-02-01 23:07:04 +11:00
|
|
|
//TODO
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-02 23:42:01 +11:00
|
|
|
void DragonsEngine::runINIScripts() {
|
|
|
|
for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
|
|
|
|
DragonINI *ini = getINI(i);
|
|
|
|
if (ini->field_1a_flags_maybe & Dragons::INI_FLAG_10) {
|
|
|
|
ini->field_1a_flags_maybe &= ~Dragons::INI_FLAG_10;
|
|
|
|
byte *data = _dragonOBD->getFromOpt(i);
|
|
|
|
ScriptOpCall scriptOpCall;
|
|
|
|
scriptOpCall._code = data + 8;
|
|
|
|
scriptOpCall._codeEnd = scriptOpCall._code + READ_LE_UINT32(data);
|
|
|
|
uint32 currentFlags = _flags;
|
|
|
|
clearFlags(Dragons::ENGINE_FLAG_8);
|
|
|
|
_scriptOpcodes->runScript3(scriptOpCall);
|
|
|
|
_flags = currentFlags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::engineFlag0x20UpdateFunction() {
|
|
|
|
if (_flags & Dragons::ENGINE_FLAG_20) {
|
|
|
|
if ((_flags & (Dragons::ENGINE_FLAG_80000000 | Dragons::ENGINE_FLAG_8)) == 8) {
|
2019-03-05 21:39:44 +11:00
|
|
|
_cursor->update();
|
2019-02-02 23:42:01 +11:00
|
|
|
}
|
2019-03-07 21:24:10 +11:00
|
|
|
//TODO 0x80027be4
|
|
|
|
|
2019-02-02 23:42:01 +11:00
|
|
|
uint16 currentSceneId = _scene->getSceneId();
|
|
|
|
|
2019-03-07 21:24:10 +11:00
|
|
|
// 0x80027db8
|
2019-03-03 22:25:00 +11:00
|
|
|
if (!_inventory->isVisible()) {
|
2019-02-02 23:42:01 +11:00
|
|
|
for (uint16 i = 0; i < _dragonINIResource->totalRecords(); i++) {
|
|
|
|
DragonINI *ini = getINI(i);
|
|
|
|
if (ini->field_10 >= 0 && ini->sceneId == currentSceneId) {
|
|
|
|
ini->field_10--;
|
|
|
|
if (ini->field_10 < 0) {
|
|
|
|
ini->field_1a_flags_maybe |= Dragons::INI_FLAG_10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-07 21:24:10 +11:00
|
|
|
|
|
|
|
if (run_func_ptr_unk_countdown_timer != 0) {
|
|
|
|
run_func_ptr_unk_countdown_timer--;
|
|
|
|
}
|
2019-02-02 23:42:01 +11:00
|
|
|
} else {
|
|
|
|
run_func_ptr_unk_countdown_timer = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::waitForFrames(uint16 numFrames) {
|
|
|
|
for (uint16 i = 0; i < numFrames; i++) {
|
|
|
|
wait();
|
|
|
|
updateHandler();
|
|
|
|
|
|
|
|
_scene->draw();
|
|
|
|
_screen->updateScreen();
|
2019-02-23 23:51:03 +11:00
|
|
|
updateEvents();
|
2019-02-02 23:42:01 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-03 15:23:41 +11:00
|
|
|
void DragonsEngine::playSound(uint16 soundId) {
|
|
|
|
debug(3, "TODO: play sound %d", soundId);
|
|
|
|
}
|
|
|
|
|
2019-02-23 23:51:03 +11:00
|
|
|
void DragonsEngine::updatePathfindingActors() {
|
|
|
|
for (uint16 i = 0; i < 0x17; i++) {
|
|
|
|
Actor *actor = _actorManager->getActor(i);
|
|
|
|
actor->walkPath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 23:17:40 +11:00
|
|
|
void DragonsEngine::fade_related(uint32 flags) {
|
|
|
|
if (!isFlagSet(ENGINE_FLAG_40)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setUnkFlags(ENGINE_UNK1_FLAG_2);
|
|
|
|
clearFlags(ENGINE_FLAG_40);
|
|
|
|
|
|
|
|
//TODO 0x80015a1c
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragonsEngine::call_fade_related_1f() {
|
|
|
|
fade_related(0x1f);
|
|
|
|
}
|
|
|
|
|
2018-10-19 23:22:30 +11:00
|
|
|
} // End of namespace Dragons
|