Skip to content

Commit

Permalink
PRINCE: get/set mob data added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Zbróg committed Nov 14, 2013
1 parent 8cffaaa commit 7b1fed7
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 18 deletions.
47 changes: 47 additions & 0 deletions engines/prince/common.h
@@ -0,0 +1,47 @@
/* 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 PRINCE_COMMON_H
#define PRINCE_COMMON_H

namespace Prince {

enum Direction {
LD = 0,
L = 1,
LG = 2,
PD = 3,
P = 4,
PG = 5,
GL = 6,
G = 7,
GP = 8,
DL = 9,
D = 10,
DP = 11
};

}

#endif

/* vim: set tabstop=4 noexpandtab: */
38 changes: 37 additions & 1 deletion engines/prince/mob.cpp
Expand Up @@ -41,7 +41,16 @@ bool Mob::loadFromStream(Common::SeekableReadStream &stream) {
_rect.right = stream.readUint16LE();
_rect.bottom = stream.readUint16LE();

stream.skip(6 * sizeof(uint16));
_mask = stream.readUint16LE();

_examPosition.x = stream.readUint16LE();
_examPosition.y = stream.readUint16LE();
_examDirection = (Direction)stream.readUint16LE();

_usePosition.x = stream.readByte();
_usePosition.y = stream.readByte();
_useDirection = (Direction)stream.readUint16LE();

uint32 nameOffset = stream.readUint32LE();
uint32 examTextOffset = stream.readUint32LE();

Expand All @@ -60,6 +69,33 @@ bool Mob::loadFromStream(Common::SeekableReadStream &stream) {
return true;
}

void Mob::setData(AttrId dataId, uint16 value) {
switch (dataId) {
case ExamDir:
_examDirection = (Direction)value;
break;
case ExamX:
_examPosition.x = value;
break;
case ExamY:
_examPosition.y = value;
break;
default:
assert(false);
}
}

uint16 Mob::getData(AttrId dataId) {
switch (dataId) {
case Visible: return _visible;
case ExamDir: return _examDirection;
case ExamX: return _examPosition.x;
case ExamY: return _examPosition.y;
default:
assert(false);
}
}

}

/* vim: set tabstop=4 noexpandtab: */
32 changes: 32 additions & 0 deletions engines/prince/mob.h
Expand Up @@ -27,6 +27,8 @@
#include "common/rect.h"
#include "common/str.h"

#include "prince/common.h"

namespace Common {
class SeekableReadStream;
}
Expand All @@ -40,9 +42,39 @@ class Mob {

bool loadFromStream(Common::SeekableReadStream &stream);

// Used instead of offset in setData and getData
enum AttrId {
Visible = 0,
Type = 2,
X1 = 4,
Y1 = 6,
X2 = 8,
Y2 = 10,
Mask = 12,
ExamX = 14,
ExamY = 16,
ExamDir = 18,
UseX = 20,
UseY = 21,
UseDir = 22,
Name = 24,
ExamText = 28
};

void setData(AttrId dataId, uint16 value);
uint16 getData(AttrId dataId);

bool _visible;
uint16 _type;
uint16 _mask;
Common::Rect _rect;

Common::Point _examPosition;
Direction _examDirection;

Common::Point _usePosition;
Direction _useDirection;

Common::String _name;
Common::String _examText;
};
Expand Down
8 changes: 5 additions & 3 deletions engines/prince/object.cpp
Expand Up @@ -36,9 +36,11 @@ Object::Object() : _surface(NULL), _x(0), _y(0), _z(0) {
}

Object::~Object() {
_surface->free();
delete _surface;
_surface = NULL;
if (_surface) {
_surface->free();
delete _surface;
_surface = NULL;
}
}

void Object::loadSurface(Common::SeekableReadStream &stream) {
Expand Down
31 changes: 25 additions & 6 deletions engines/prince/prince.cpp
Expand Up @@ -74,7 +74,7 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc)
Engine(syst), _gameDescription(gameDesc), _graph(NULL), _script(NULL),
_locationNr(0), _debugger(NULL), _midiPlayer(NULL),
_cameraX(0), _newCameraX(0), _frameNr(0), _cursor1(NULL), _cursor2(NULL), _font(NULL),
_walizkaBmp(NULL), _roomBmp(NULL), _voiceStream(NULL) {
_walizkaBmp(NULL), _roomBmp(NULL), _voiceStream(NULL), _cursorNr(0) {

// Debug/console setup
DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
Expand Down Expand Up @@ -141,19 +141,36 @@ template <typename T>
bool loadResource(Common::Array<T> &array, const char *resourceName, bool required = true) {
Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
if (!stream) {
if (required) {
if (required)
error("Can't load %s", resourceName);
}
return false;
}

typename Common::Array<T>::value_type t;
T t;
while (t.loadFromStream(*stream))
array.push_back(t);

delete stream;
return true;
}
#if 0
template <typename T>
bool loadResource(T * array[], const char *resourceName, bool required = true) {
Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(resourceName);
if (!stream) {
if (required)
error("Can't load %s", resourceName);
return false;
}

T* t = new T();
while (t->loadFromStream(*stream))
array.push_back(t);

delete stream;
return true;
}
#endif

void PrinceEngine::init() {

Expand Down Expand Up @@ -539,8 +556,8 @@ void PrinceEngine::drawScreen() {

void PrinceEngine::mainLoop() {

loadLocation(2);
changeCursor(1);
loadLocation(4);
changeCursor(0);

while (!shouldQuit()) {
uint32 currentTime = _system->getMillis();
Expand Down Expand Up @@ -572,6 +589,8 @@ void PrinceEngine::mainLoop() {
if (shouldQuit())
return;

// TODO: Update all structures, animations, naks, heros etc.

//_script->step();
drawScreen();

Expand Down
2 changes: 1 addition & 1 deletion engines/prince/prince.h
Expand Up @@ -149,7 +149,7 @@ class PrinceEngine : public Engine {
Audio::SoundHandle _soundHandle;
Common::SeekableReadStream *_voiceStream;
Common::Array<Mob> _mobList;
Common::Array<Object *> _objectList;
Common::Array<Object *> _objList;

uint16 _cameraX;
uint16 _newCameraX;
Expand Down
14 changes: 7 additions & 7 deletions engines/prince/script.cpp
Expand Up @@ -492,9 +492,9 @@ void Script::O_ORFLAG() {
}

void Script::O_SETMOBDATA() {
uint16 mobId = readScript16bits();
uint16 mobOffset = readScript16bits();
uint16 value = readScript16bits();
uint16 mobId = readScriptValue();
uint16 mobOffset = readScriptValue();
uint16 value = readScriptValue();

debugScript("O_SETMOBDATA mobId %d, mobOffset %d, value %d", mobId, mobOffset, value);
}
Expand Down Expand Up @@ -537,10 +537,10 @@ void Script::O_WALKHERO() {
}

void Script::O_SETHERO() {
uint16 hero = readScript16bits();
uint16 x = readScript16bits();
uint16 y = readScript16bits();
uint16 dir = readScript16bits();
uint16 hero = readScriptValue();
uint16 x = readScriptValue();
uint16 y = readScriptValue();
uint16 dir = readScriptValue();
debugScript("O_SETHERO hero %d, x %d, y %d, dir %d", hero, x, y, dir);
}

Expand Down

0 comments on commit 7b1fed7

Please sign in to comment.