2003-09-28 15:50:47 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2003 The ScummVM project
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "queen/logic.h"
|
2003-10-09 09:09:40 +00:00
|
|
|
#include "queen/defs.h"
|
2003-10-11 10:09:23 +00:00
|
|
|
#include "queen/graphics.h"
|
|
|
|
#include "queen/walk.h"
|
|
|
|
#include "common/str.h"
|
2003-09-28 15:50:47 +00:00
|
|
|
|
2003-10-03 19:47:41 +00:00
|
|
|
namespace Queen {
|
|
|
|
|
2003-10-10 20:03:34 +00:00
|
|
|
Logic::Logic(Resource *resource, Graphics *graphics)
|
2003-10-11 10:09:23 +00:00
|
|
|
: _resource(resource), _graphics(graphics) {
|
2003-09-29 22:27:08 +00:00
|
|
|
_jas = _resource->loadFile("QUEEN.JAS", 20);
|
2003-10-10 09:19:52 +00:00
|
|
|
_joe.x = _joe.y = 0;
|
2003-10-11 10:09:23 +00:00
|
|
|
_walk = new Walk(this, _graphics);
|
2003-09-28 15:50:47 +00:00
|
|
|
initialise();
|
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
Logic::~Logic() {
|
2003-10-03 19:59:19 +00:00
|
|
|
delete[] _jas;
|
2003-10-11 10:09:23 +00:00
|
|
|
delete _walk;
|
2003-09-28 15:50:47 +00:00
|
|
|
//free(_graphicData);
|
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
void Logic::initialise() {
|
2003-10-09 09:09:40 +00:00
|
|
|
int16 i, j;
|
2003-09-28 15:50:47 +00:00
|
|
|
uint8 *ptr = _jas;
|
|
|
|
|
|
|
|
//_display->loadFont();
|
|
|
|
|
|
|
|
_numRooms = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_numNames = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_numObjects = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_numDescriptions = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
|
|
|
//Object data
|
2003-10-02 14:44:51 +00:00
|
|
|
_objectData = new ObjectData[_numObjects + 1];
|
|
|
|
//clear first object
|
|
|
|
_objectData[0].name = 0;
|
|
|
|
_objectData[0].x = 0;
|
|
|
|
_objectData[0].y = 0;
|
|
|
|
_objectData[0].description = 0;
|
|
|
|
_objectData[0].entryObj = 0;
|
|
|
|
_objectData[0].room = 0;
|
|
|
|
_objectData[0].state = 0;
|
|
|
|
_objectData[0].image = 0;
|
2003-10-06 13:20:29 +00:00
|
|
|
for (i = 1; i <= _numObjects; i++) {
|
2003-10-02 19:20:00 +00:00
|
|
|
_objectData[i].name = (int16)READ_BE_UINT16(ptr);
|
2003-10-02 14:44:51 +00:00
|
|
|
ptr += 2;
|
2003-10-02 19:20:00 +00:00
|
|
|
_objectData[i].x = READ_BE_UINT16(ptr);
|
2003-10-02 14:44:51 +00:00
|
|
|
ptr += 2;
|
2003-10-02 19:20:00 +00:00
|
|
|
_objectData[i].y = READ_BE_UINT16(ptr);
|
2003-10-02 14:44:51 +00:00
|
|
|
ptr += 2;
|
2003-10-02 19:20:00 +00:00
|
|
|
_objectData[i].description = READ_BE_UINT16(ptr);
|
2003-10-02 14:44:51 +00:00
|
|
|
ptr += 2;
|
2003-10-02 19:20:00 +00:00
|
|
|
_objectData[i].entryObj = (int16)READ_BE_UINT16(ptr);
|
2003-10-02 14:44:51 +00:00
|
|
|
ptr += 2;
|
2003-10-02 19:20:00 +00:00
|
|
|
_objectData[i].room = READ_BE_UINT16(ptr);
|
2003-10-02 14:44:51 +00:00
|
|
|
ptr += 2;
|
2003-10-02 19:20:00 +00:00
|
|
|
_objectData[i].state = (int16)READ_BE_UINT16(ptr);
|
2003-10-02 14:44:51 +00:00
|
|
|
ptr += 2;
|
2003-10-02 19:20:00 +00:00
|
|
|
_objectData[i].image = (int16)READ_BE_UINT16(ptr);
|
2003-10-02 14:44:51 +00:00
|
|
|
ptr += 2;
|
|
|
|
}
|
2003-09-28 15:50:47 +00:00
|
|
|
|
|
|
|
//Room data
|
2003-09-28 19:57:01 +00:00
|
|
|
_roomData = new uint16[_numRooms + 2];
|
2003-10-06 13:20:29 +00:00
|
|
|
for (i = 1; i <= (_numRooms + 1); i++) {
|
2003-09-28 15:50:47 +00:00
|
|
|
_roomData[i] = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
_roomData[_numRooms + 1] = _numObjects;
|
|
|
|
|
|
|
|
//SFX Name
|
2003-10-02 14:55:28 +00:00
|
|
|
// the following table isn't available in demo version
|
|
|
|
if (_resource->isDemo()) {
|
|
|
|
_sfxName = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_sfxName = new uint16[_numRooms + 1];
|
2003-10-02 14:44:51 +00:00
|
|
|
|
2003-10-06 13:20:29 +00:00
|
|
|
for (i = 1; i <= _numRooms; i++) {
|
2003-10-02 14:55:28 +00:00
|
|
|
_sfxName[i] = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
}
|
|
|
|
}
|
2003-09-28 15:50:47 +00:00
|
|
|
|
|
|
|
//Item information
|
|
|
|
_numItems = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
2003-10-08 08:55:07 +00:00
|
|
|
_itemData = new ItemData[_numItems + 1];
|
2003-10-06 13:20:29 +00:00
|
|
|
|
|
|
|
for (i = 1; i <= _numItems; i++) {
|
2003-10-08 08:55:07 +00:00
|
|
|
_itemData[i].item = (int16)READ_BE_UINT16(ptr);
|
2003-10-06 13:20:29 +00:00
|
|
|
ptr += 2;
|
|
|
|
_itemData[i].description = (int16)READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_itemData[i].state = (int16)READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_itemData[i].bobFrame = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_itemData[i].sfxDescription = READ_BE_UINT16(ptr);
|
2003-09-28 15:50:47 +00:00
|
|
|
ptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Graphic Image Data
|
|
|
|
|
|
|
|
_numGraphics = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
2003-10-02 14:44:51 +00:00
|
|
|
_graphicData = new GraphicData[_numGraphics + 1];
|
2003-09-28 15:50:47 +00:00
|
|
|
|
2003-10-06 13:20:29 +00:00
|
|
|
for (i = 1; i <= _numGraphics; i++) {
|
2003-10-02 14:44:51 +00:00
|
|
|
_graphicData[i].x = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_graphicData[i].y = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_graphicData[i].firstFrame = (int16)READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_graphicData[i].lastFrame = (int16)READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_graphicData[i].speed = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
}
|
2003-09-28 15:50:47 +00:00
|
|
|
|
2003-10-06 08:24:38 +00:00
|
|
|
_objMax = new int16[_numRooms + 1];
|
|
|
|
_areaMax = new int16[_numRooms + 1];
|
2003-10-09 09:09:40 +00:00
|
|
|
_area = new Area[_numRooms + 1][11];
|
2003-10-05 16:07:07 +00:00
|
|
|
|
2003-10-06 13:20:29 +00:00
|
|
|
for (i = 1; i <= _numRooms; i++) {
|
2003-10-05 16:07:07 +00:00
|
|
|
_objMax[i] = (int16)READ_BE_UINT16(ptr);
|
2003-09-28 15:50:47 +00:00
|
|
|
ptr += 2;
|
2003-10-05 16:07:07 +00:00
|
|
|
_areaMax[i] = (int16)READ_BE_UINT16(ptr);
|
2003-09-28 15:50:47 +00:00
|
|
|
ptr += 2;
|
|
|
|
|
2003-10-09 09:09:40 +00:00
|
|
|
for (j = 1; j <= _areaMax[i]; j++) {
|
|
|
|
assert(j < 11);
|
|
|
|
_area[i][j].mapNeighbours = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_area[i][j].box.x1 = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_area[i][j].box.y1 = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_area[i][j].box.x2 = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_area[i][j].box.y2 = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_area[i][j].bottomScaleFactor = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_area[i][j].topScaleFactor = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
_area[i][j].object = READ_BE_UINT16(ptr); ptr += 2;
|
|
|
|
}
|
2003-10-07 08:22:53 +00:00
|
|
|
}
|
|
|
|
|
2003-10-06 13:20:29 +00:00
|
|
|
_objectBox = new Box[_numObjects + 1];
|
|
|
|
for (i = 1; i <= _numObjects; i++) {
|
|
|
|
_objectBox[i].x1 = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_objectBox[i].y1 = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_objectBox[i].x2 = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_objectBox[i].y2 = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
}
|
2003-10-07 08:22:53 +00:00
|
|
|
|
2003-10-06 13:20:29 +00:00
|
|
|
//Walk OFF Data
|
|
|
|
|
|
|
|
_numWalkOffs = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
|
|
|
_walkOffData = new WalkOffData[_numWalkOffs + 1];
|
|
|
|
for (i = 1; i <= _numWalkOffs; i++) {
|
|
|
|
_walkOffData[i].entryObj = (int16)READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_walkOffData[i].x = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
_walkOffData[i].y = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Special Object Descriptions
|
|
|
|
|
|
|
|
_numObjDesc = READ_BE_UINT16(ptr);
|
|
|
|
ptr += 2;
|
|
|
|
|
|
|
|
_objectDescription = new ObjectDescription[_numObjDesc + 1];
|
|
|
|
for (i = 1; i <= _numObjDesc; i++) {
|
2003-10-08 08:55:07 +00:00
|
|
|
_objectDescription[i].object = READ_BE_UINT16(ptr);
|
2003-10-06 13:20:29 +00:00
|
|
|
ptr += 2;
|
2003-10-08 08:55:07 +00:00
|
|
|
_objectDescription[i].type = READ_BE_UINT16(ptr);
|
2003-10-06 13:20:29 +00:00
|
|
|
ptr += 2;
|
2003-10-08 08:55:07 +00:00
|
|
|
_objectDescription[i].lastDescription = READ_BE_UINT16(ptr);
|
2003-10-06 13:20:29 +00:00
|
|
|
ptr += 2;
|
2003-10-08 08:55:07 +00:00
|
|
|
_objectDescription[i].seenCount = READ_BE_UINT16(ptr);
|
2003-10-06 13:20:29 +00:00
|
|
|
ptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Command List Data
|
2003-09-28 15:50:47 +00:00
|
|
|
|
2003-10-09 09:09:40 +00:00
|
|
|
|
|
|
|
memset(_zones, 0, sizeof(_zones));
|
2003-10-11 10:09:23 +00:00
|
|
|
_oldRoom = 0;
|
2003-10-12 13:16:35 +00:00
|
|
|
_entryObj = 0;
|
2003-09-28 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
uint16 Logic::currentRoom() {
|
2003-09-28 15:50:47 +00:00
|
|
|
return _currentRoom;
|
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
void Logic::currentRoom(uint16 room) {
|
2003-10-02 08:49:38 +00:00
|
|
|
_currentRoom = room;
|
2003-10-02 06:38:58 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
void Logic::oldRoom(uint16 room) {
|
2003-10-02 11:03:34 +00:00
|
|
|
_oldRoom = room;
|
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
ObjectData* Logic::objectData(int index) {
|
2003-10-02 14:44:51 +00:00
|
|
|
return &_objectData[index];
|
|
|
|
}
|
2003-10-02 06:38:58 +00:00
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
uint16 Logic::roomData(int room) {
|
2003-10-02 08:49:38 +00:00
|
|
|
return _roomData[room];
|
2003-10-02 06:38:58 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
uint16 Logic::objMax(int room) {
|
2003-10-02 08:49:38 +00:00
|
|
|
return _objMax[room];
|
2003-10-02 06:38:58 +00:00
|
|
|
}
|
|
|
|
|
2003-10-09 13:14:16 +00:00
|
|
|
Area *Logic::area(int room, int num) {
|
|
|
|
return &_area[room][num];
|
|
|
|
}
|
|
|
|
|
|
|
|
Area *Logic::currentRoomArea(int num) {
|
|
|
|
return &_area[_currentRoom][num];
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 Logic::areaMax(int room) {
|
|
|
|
return _areaMax[room];
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 Logic::currentRoomAreaMax() {
|
|
|
|
return _areaMax[_currentRoom];
|
2003-10-02 11:03:34 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
uint16 Logic::walkOffCount() {
|
2003-10-02 08:49:38 +00:00
|
|
|
return _numWalkOffs;
|
|
|
|
}
|
|
|
|
|
2003-10-06 13:20:29 +00:00
|
|
|
WalkOffData *Logic::walkOffData(int index) {
|
|
|
|
return &_walkOffData[index];
|
2003-10-02 08:49:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-10 20:03:34 +00:00
|
|
|
GraphicData *Logic::graphicData(int index) {
|
2003-10-02 14:44:51 +00:00
|
|
|
return &_graphicData[index];
|
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
uint16 Logic::findBob(uint16 obj) {
|
2003-10-02 14:44:51 +00:00
|
|
|
|
|
|
|
uint16 i;
|
|
|
|
uint16 bobnum = 0;
|
|
|
|
uint16 bobtype = 0; // 1 for animated, 0 for static
|
|
|
|
|
2003-10-02 19:37:51 +00:00
|
|
|
if (obj > _numObjects)
|
|
|
|
error("Object index (%i) > _numObjects (%i)", obj, _numObjects);
|
2003-10-02 19:20:00 +00:00
|
|
|
|
2003-10-02 14:44:51 +00:00
|
|
|
uint16 room = _objectData[obj].room;
|
2003-10-02 19:20:00 +00:00
|
|
|
|
|
|
|
if (room >= _numRooms) {
|
|
|
|
warning("room (%i) > _numRooms (%i)", room, _numRooms);
|
|
|
|
}
|
|
|
|
|
2003-10-02 14:44:51 +00:00
|
|
|
int16 img = _objectData[obj].image;
|
|
|
|
if(img != 0) {
|
|
|
|
if(img == -3 || img == -4) {
|
|
|
|
// a person object
|
|
|
|
for(i = _roomData[room] + 1; i <= obj; ++i) {
|
|
|
|
img = _objectData[i].image;
|
|
|
|
if(img == -3 || img == -4) {
|
|
|
|
++bobnum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(img <= -10) {
|
|
|
|
// object has been turned off, but the image order hasn't been updated
|
|
|
|
if(_graphicData[-(img + 10)].lastFrame != 0) {
|
|
|
|
bobtype = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(img == -2) {
|
|
|
|
// -1 static, -2 animated
|
|
|
|
bobtype = 1;
|
|
|
|
}
|
|
|
|
else if(img > 0) {
|
|
|
|
if(_graphicData[img].lastFrame != 0) {
|
|
|
|
bobtype = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 idxAnimated = 0;
|
|
|
|
uint16 idxStatic = 0;
|
|
|
|
for(i = _roomData[room] + 1; i <= obj; ++i) {
|
|
|
|
img = _objectData[i].image;
|
|
|
|
if(img <= -10) {
|
|
|
|
if(_graphicData[-(img + 10)].lastFrame != 0) {
|
|
|
|
++idxAnimated;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++idxStatic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(img > 0) {
|
|
|
|
if(img > 5000) {
|
|
|
|
img -= 5000;
|
|
|
|
}
|
2003-10-02 19:20:00 +00:00
|
|
|
|
|
|
|
if (img >= _numGraphics)
|
|
|
|
warning("img (%i) >= _numGraphics (%i)", img, _numGraphics);
|
|
|
|
|
2003-10-02 14:44:51 +00:00
|
|
|
if(_graphicData[img].lastFrame != 0) {
|
|
|
|
++idxAnimated;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++idxStatic;
|
|
|
|
}
|
|
|
|
}
|
2003-10-03 19:59:19 +00:00
|
|
|
else if(img == -1) {
|
|
|
|
++idxStatic;
|
|
|
|
}
|
|
|
|
else if(img == -2) {
|
|
|
|
++idxAnimated;
|
|
|
|
}
|
2003-10-02 14:44:51 +00:00
|
|
|
}
|
|
|
|
if(bobtype == 0) {
|
|
|
|
// static bob
|
2003-10-03 19:59:19 +00:00
|
|
|
if(idxStatic > 0) {
|
2003-10-11 10:09:23 +00:00
|
|
|
bobnum = 19 + _numFurnitureStatic + idxStatic;
|
2003-10-03 19:59:19 +00:00
|
|
|
}
|
2003-10-02 14:44:51 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// animated bob
|
2003-10-03 19:59:19 +00:00
|
|
|
if(idxAnimated > 0) {
|
2003-10-12 13:16:35 +00:00
|
|
|
bobnum = 4 + _numFurnitureAnimated + idxAnimated;
|
2003-10-03 19:59:19 +00:00
|
|
|
}
|
2003-10-02 14:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bobnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
uint16 Logic::findFrame(uint16 obj) {
|
2003-10-02 14:44:51 +00:00
|
|
|
|
|
|
|
uint16 i;
|
|
|
|
uint16 framenum = 0;
|
|
|
|
|
|
|
|
uint16 room = _objectData[obj].room;
|
|
|
|
int16 img = _objectData[obj].image;
|
|
|
|
if(img == -3 || img == -4) {
|
|
|
|
uint16 bobnum = 0;
|
|
|
|
for(i = _roomData[room] + 1; i <= obj; ++i) {
|
|
|
|
img = _objectData[i].image;
|
|
|
|
if(img == -3 || img == -4) {
|
|
|
|
++bobnum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(bobnum <= 3) {
|
2003-10-12 13:16:35 +00:00
|
|
|
framenum = 29 + FRAMES_JOE_XTRA + bobnum;
|
2003-10-02 14:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uint16 idx = 0;
|
|
|
|
for(i = _roomData[room] + 1; i < obj; ++i) {
|
|
|
|
img = _objectData[i].image;
|
|
|
|
if(img <= -10) {
|
|
|
|
GraphicData* pgd = &_graphicData[-(img + 10)];
|
|
|
|
if(pgd->lastFrame != 0) {
|
|
|
|
// skip all the frames of the animation
|
|
|
|
idx += ABS(pgd->lastFrame) - pgd->firstFrame + 1;
|
|
|
|
}
|
|
|
|
else {
|
2003-10-12 13:16:35 +00:00
|
|
|
// static bob, skip one frame
|
2003-10-02 14:44:51 +00:00
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(img == -1) {
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
else if(img > 0) {
|
|
|
|
if(img > 5000) {
|
|
|
|
img -= 5000;
|
|
|
|
}
|
|
|
|
GraphicData* pgd = &_graphicData[img];
|
|
|
|
uint16 lastFrame = ABS(pgd->lastFrame);
|
|
|
|
if(pgd->firstFrame < 0) {
|
|
|
|
idx += lastFrame;
|
|
|
|
}
|
|
|
|
else if(lastFrame != 0) {
|
|
|
|
idx += (lastFrame - pgd->firstFrame) + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
img = _objectData[obj].image;
|
|
|
|
if(img <= -10) {
|
|
|
|
GraphicData* pgd = &_graphicData[-(img + 10)];
|
|
|
|
if(pgd->lastFrame != 0) {
|
2003-10-03 19:59:19 +00:00
|
|
|
idx += ABS(pgd->lastFrame) - pgd->firstFrame + 1;
|
2003-10-02 14:44:51 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(img == -1 || img > 0) {
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate only if there are person frames
|
|
|
|
if(idx > 0) {
|
2003-10-12 13:16:35 +00:00
|
|
|
framenum = 36 + FRAMES_JOE_XTRA + _numFurnitureStatic + _numFurnitureAnimatedLen + idx;
|
2003-10-02 14:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return framenum;
|
|
|
|
}
|
2003-10-03 19:47:41 +00:00
|
|
|
|
2003-10-10 09:19:52 +00:00
|
|
|
|
|
|
|
uint16 Logic::objectForPerson(uint16 bobNum) {
|
|
|
|
|
|
|
|
uint16 bobcur = 0;
|
|
|
|
// first object number in the room
|
|
|
|
uint16 cur = _roomData[_currentRoom] + 1;
|
|
|
|
// last object number in the room
|
|
|
|
uint16 last = _roomData[_currentRoom + 1];
|
|
|
|
while (cur <= last) {
|
|
|
|
int16 image = _objectData[cur].image;
|
|
|
|
if (image == -3 || image == -4) {
|
|
|
|
// the object is a bob
|
|
|
|
++bobcur;
|
|
|
|
}
|
|
|
|
if (bobcur == bobNum) {
|
|
|
|
return cur;
|
|
|
|
}
|
2003-10-10 20:03:34 +00:00
|
|
|
++cur;
|
2003-10-10 09:19:52 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WalkOffData *Logic::walkOffPointForObject(uint16 obj) {
|
|
|
|
|
|
|
|
uint16 i;
|
|
|
|
for (i = 1; i <= _numWalkOffs; ++i) {
|
|
|
|
if (_walkOffData[i].entryObj == obj) {
|
|
|
|
return &_walkOffData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-07 00:26:04 +00:00
|
|
|
void Logic::joeFacing(uint16 dir) {
|
|
|
|
_joe.facing = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Logic::joeX(uint16 x) {
|
|
|
|
_joe.x = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Logic::joeY(uint16 y) {
|
|
|
|
_joe.y = y;
|
|
|
|
}
|
|
|
|
|
2003-10-09 09:09:40 +00:00
|
|
|
void Logic::joeWalk(uint16 walk) {
|
|
|
|
_joe.walk = walk;
|
|
|
|
}
|
|
|
|
|
2003-10-09 13:14:16 +00:00
|
|
|
void Logic::joeScale(uint16 scale) {
|
|
|
|
_joe.scale = scale;
|
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
int16 Logic::gameState(int index) {
|
2003-10-04 08:50:48 +00:00
|
|
|
if (index >= 0 && index < GAME_STATE_COUNT)
|
|
|
|
return _gameState[index];
|
|
|
|
else
|
|
|
|
error("[QueenLogic::gameState] invalid index: %i", index);
|
|
|
|
}
|
|
|
|
|
2003-10-05 16:07:07 +00:00
|
|
|
void Logic::gameState(int index, int16 newValue) {
|
2003-10-04 08:50:48 +00:00
|
|
|
if (index >= 0 && index < GAME_STATE_COUNT)
|
|
|
|
_gameState[index] = newValue;
|
|
|
|
else
|
|
|
|
error("[QueenLogic::gameState] invalid index: %i", index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-09 09:09:40 +00:00
|
|
|
void Logic::zoneSet(uint16 screen, uint16 zone, uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
|
|
|
|
|
|
|
|
ZoneSlot *pzs = &_zones[screen][zone];
|
|
|
|
pzs->valid = true;
|
|
|
|
pzs->box.x1 = x1;
|
|
|
|
pzs->box.y1 = y1;
|
|
|
|
pzs->box.x2 = x2;
|
|
|
|
pzs->box.y2 = y2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logic::zoneSet(uint16 screen, uint16 zone, const Box& box) {
|
|
|
|
|
|
|
|
debug(9, "Logic::zoneSet(%d, %d, (%d,%d), (%d,%d))", screen, zone, box.x1, box.y1, box.x2, box.y2);
|
|
|
|
|
|
|
|
ZoneSlot *pzs = &_zones[screen][zone];
|
|
|
|
pzs->valid = true;
|
|
|
|
pzs->box = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16 Logic::zoneIn(uint16 screen, uint16 x, uint16 y) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
if (screen == ZONE_PANEL) {
|
|
|
|
y -= ROOM_ZONE_HEIGHT;
|
|
|
|
}
|
|
|
|
for(i = 1; i < MAX_ZONES_NUMBER; ++i) {
|
|
|
|
ZoneSlot *pzs = &_zones[screen][i];
|
|
|
|
if (pzs->valid && pzs->box.contains(x, y)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16 Logic::zoneInArea(uint16 screen, uint16 x, uint16 y) {
|
|
|
|
uint16 zone = zoneIn(screen, x, y);
|
|
|
|
if (zone <= _objMax[_currentRoom]) {
|
|
|
|
zone = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
zone -= _objMax[_currentRoom];
|
|
|
|
}
|
|
|
|
return zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logic::zoneClearAll(uint16 screen) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 1; i < MAX_ZONES_NUMBER; ++i) {
|
|
|
|
_zones[screen][i].valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logic::zoneSetup() {
|
|
|
|
|
|
|
|
zoneClearAll(ZONE_ROOM);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int zoneNum;
|
|
|
|
|
|
|
|
// setup objects zones
|
|
|
|
uint16 maxObjRoom = _objMax[_currentRoom];
|
|
|
|
uint16 objRoomNum = _roomData[_currentRoom];
|
|
|
|
zoneNum = 1;
|
|
|
|
for (i = objRoomNum + 1; i <= objRoomNum + maxObjRoom; ++i) {
|
|
|
|
if (_objectData[i].name != 0) {
|
|
|
|
zoneSet(ZONE_ROOM, zoneNum, _objectBox[i]);
|
|
|
|
}
|
|
|
|
++zoneNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup room zones (areas)
|
|
|
|
uint16 maxAreaRoom = _areaMax[_currentRoom];
|
|
|
|
for (zoneNum = 1; zoneNum <= maxAreaRoom; ++zoneNum) {
|
|
|
|
zoneSet(ZONE_ROOM, maxObjRoom + zoneNum, _area[_currentRoom][zoneNum].box);
|
2003-10-11 10:09:23 +00:00
|
|
|
_graphics->boxDraw(_area[_currentRoom][zoneNum].box, 18);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logic::roomErase() {
|
|
|
|
|
|
|
|
_graphics->frameEraseAll(false);
|
|
|
|
_graphics->bankErase(15);
|
|
|
|
_graphics->bankErase(11);
|
|
|
|
_graphics->bankErase(10);
|
|
|
|
_graphics->bankErase(12);
|
|
|
|
|
|
|
|
// TODO: TALKHEAD=0;
|
|
|
|
// TODO: _display->fadeOut();
|
|
|
|
// TODO: credits system
|
|
|
|
// TODO: person animations
|
|
|
|
|
|
|
|
uint16 cur = _roomData[_oldRoom] + 1;
|
|
|
|
uint16 last = _roomData[_oldRoom + 1];
|
|
|
|
while (cur <= last) {
|
|
|
|
ObjectData *pod = &_objectData[cur];
|
|
|
|
if (pod->name == 0) {
|
|
|
|
// object has been deleted, invalidate image
|
|
|
|
pod->image = 0;
|
|
|
|
}
|
|
|
|
else if (pod->image > -4000 && pod->image <= -10) {
|
|
|
|
if (_graphicData[ABS(pod->image + 10)].lastFrame == 0) {
|
|
|
|
// static Bob
|
|
|
|
pod->image = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// animated Bob
|
|
|
|
pod->image = -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-12 13:16:35 +00:00
|
|
|
void Logic::roomSetupFurniture() {
|
2003-10-11 10:09:23 +00:00
|
|
|
_numFurnitureStatic = 0;
|
|
|
|
_numFurnitureAnimated = 0;
|
|
|
|
_numFurnitureAnimatedLen = 0;
|
|
|
|
uint16 curImage = 36 + FRAMES_JOE_XTRA;
|
|
|
|
|
|
|
|
// count the furniture and update gameState
|
|
|
|
uint16 furnitureTotal = 0;
|
|
|
|
uint16 i;
|
|
|
|
// FIXME: uncomment when Array< FurnitureData > available in Logic
|
|
|
|
// for (i = 1; i <= _numFurnitureData; ++i) {
|
|
|
|
// if (_furnitureData[i].room == _currentRoom) {
|
|
|
|
// ++furnitureTotal;
|
|
|
|
// _gameState[furnitureTotal] = _furnitureData[i].gameStateValue;
|
|
|
|
// }
|
|
|
|
// }
|
2003-10-12 13:16:35 +00:00
|
|
|
if (furnitureTotal == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2003-10-11 10:09:23 +00:00
|
|
|
|
|
|
|
// unpack the furniture from the bank 15
|
|
|
|
// there are 3 kinds :
|
2003-10-12 13:16:35 +00:00
|
|
|
// - static (bobs), gamestate range = ]0;5000]
|
2003-10-11 10:09:23 +00:00
|
|
|
// - animated (bobs), gamestate range = ]0;5000]
|
2003-10-12 13:16:35 +00:00
|
|
|
// - static (paste downs), gamestate range = [5000; [
|
2003-10-11 10:09:23 +00:00
|
|
|
|
2003-10-12 13:16:35 +00:00
|
|
|
// unpack the static bobs
|
2003-10-11 10:09:23 +00:00
|
|
|
for (i = 1; i <= furnitureTotal; ++i) {
|
|
|
|
int16 obj = _gameState[i];
|
|
|
|
if (obj > 0 && obj <= 5000) {
|
|
|
|
GraphicData *pgd = &_graphicData[obj];
|
|
|
|
if (pgd->lastFrame == 0) {
|
|
|
|
++_numFurnitureStatic;
|
|
|
|
++curImage;
|
|
|
|
_graphics->bankUnpack(pgd->firstFrame, curImage, 15);
|
2003-10-12 13:16:35 +00:00
|
|
|
++_numFrames;
|
2003-10-11 10:09:23 +00:00
|
|
|
BobSlot *pbs = _graphics->bob(19 + _numFurnitureStatic);
|
|
|
|
pbs->active = true;
|
|
|
|
pbs->x = pgd->x;
|
|
|
|
pbs->y = pgd->y;
|
|
|
|
pbs->frameNum = curImage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// unpack the animated bobs
|
|
|
|
uint16 curBob = 0;
|
|
|
|
for (i = 1; i <= furnitureTotal; ++i) {
|
|
|
|
int16 obj = _gameState[i];
|
|
|
|
if (obj > 0 && obj <= 5000) {
|
|
|
|
GraphicData *pgd = &_graphicData[obj];
|
|
|
|
|
|
|
|
bool rebound = false;
|
|
|
|
int16 lastFrame = pgd->lastFrame;
|
|
|
|
if (lastFrame < 0) {
|
|
|
|
rebound = true;
|
|
|
|
lastFrame = -lastFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastFrame > 0) {
|
|
|
|
_numFurnitureAnimatedLen += lastFrame - pgd->firstFrame + 1;
|
|
|
|
++_numFurnitureAnimated;
|
|
|
|
uint16 image = curImage + 1;
|
|
|
|
int k;
|
|
|
|
for (k = pgd->firstFrame; k <= pgd->lastFrame; ++k) {
|
|
|
|
++curImage;
|
|
|
|
_graphics->bankUnpack(k, curImage, 15);
|
2003-10-12 13:16:35 +00:00
|
|
|
++_numFrames;
|
2003-10-11 10:09:23 +00:00
|
|
|
}
|
|
|
|
_graphics->bobAnimNormal(5 + curBob, image, curImage, pgd->speed / 4, rebound, false);
|
|
|
|
BobSlot *pbs = _graphics->bob(5 + curBob);
|
|
|
|
pbs->x = pgd->x;
|
|
|
|
pbs->y = pgd->y;
|
|
|
|
++curBob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-12 13:16:35 +00:00
|
|
|
// unpack the paste downs
|
2003-10-11 10:09:23 +00:00
|
|
|
++curImage;
|
|
|
|
for (i = 1; i <= furnitureTotal; ++i) {
|
|
|
|
int16 obj = _gameState[i];
|
|
|
|
if (obj > 5000) {
|
|
|
|
obj -= 5000;
|
|
|
|
GraphicData *pgd = &_graphicData[obj];
|
|
|
|
_graphics->bankUnpack(pgd->firstFrame, curImage, 15);
|
|
|
|
_graphics->bobPaste(curImage, pgd->x, pgd->y);
|
2003-10-12 13:16:35 +00:00
|
|
|
// no need to increment curImage here, as bobPaste() destroys the
|
|
|
|
// unpacked frame after blitting it
|
2003-10-11 10:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logic::roomSetupObjects() {
|
2003-10-12 13:16:35 +00:00
|
|
|
warning("Logic::roomSetupObjects() not fully implemented");
|
|
|
|
|
|
|
|
uint16 i;
|
|
|
|
uint16 curImage = 36 + FRAMES_JOE_XTRA + _numFurnitureStatic + _numFurnitureAnimatedLen;
|
|
|
|
uint16 firstRoomObj = _roomData[_currentRoom] + 1;
|
|
|
|
uint16 lastRoomObj = _roomData[_currentRoom + 1];
|
|
|
|
|
|
|
|
for (i = 1; i <= 3; ++i) {
|
|
|
|
_graphics->bob(i)->active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: bobs static/animated
|
|
|
|
// TODO: bobs persons
|
|
|
|
|
|
|
|
// paste downs list
|
|
|
|
++curImage;
|
|
|
|
_numFrames = curImage;
|
|
|
|
for (i = firstRoomObj; i <= lastRoomObj; ++i) {
|
|
|
|
int16 obj = _objectData[i].image;
|
|
|
|
if (obj > 5000) {
|
|
|
|
obj -= 5000;
|
|
|
|
GraphicData *pgd = &_graphicData[obj];
|
|
|
|
_graphics->bankUnpack(pgd->firstFrame, curImage, 15);
|
|
|
|
_graphics->bobPaste(curImage, pgd->x, pgd->y);
|
|
|
|
}
|
|
|
|
}
|
2003-10-11 10:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logic::roomSetup(const char* room, int comPanel, bool inCutaway) {
|
|
|
|
|
|
|
|
// loads background image
|
|
|
|
Common::String bdFile(room);
|
|
|
|
bdFile += ".PCX";
|
|
|
|
_graphics->backdropLoad(bdFile.c_str(), _currentRoom);
|
|
|
|
|
|
|
|
// setup graphics to enter fullscreen/panel mode
|
|
|
|
_graphics->setScreenMode(comPanel, inCutaway);
|
|
|
|
|
|
|
|
// reset sprites table (bounding box...)
|
|
|
|
_graphics->bobClearAll();
|
|
|
|
|
|
|
|
// setup any hard-coded palette effect
|
|
|
|
// TODO: graphics->check_colors(_currentRoom);
|
|
|
|
|
|
|
|
// load/setup objects associated to this room
|
|
|
|
Common::String bkFile(room);
|
|
|
|
bkFile += ".BBK";
|
|
|
|
_graphics->bankLoad(bkFile.c_str(), 15);
|
2003-10-12 13:16:35 +00:00
|
|
|
_numFrames = 37 + FRAMES_JOE_XTRA;
|
|
|
|
roomSetupFurniture();
|
2003-10-11 10:09:23 +00:00
|
|
|
roomSetupObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-12 13:16:35 +00:00
|
|
|
void Logic::roomDisplay(const char* room, RoomDisplayMode mode, uint16 scale, int comPanel, bool inCutaway) {
|
|
|
|
|
|
|
|
debug(9, "Logic::roomDisplay(%s, %d, %d, %d, %d)", room, mode, scale, comPanel, inCutaway);
|
2003-10-11 10:09:23 +00:00
|
|
|
|
|
|
|
roomErase();
|
|
|
|
// TODO: _sound->loadSFX(SFXNAME[_currentRoom]);
|
|
|
|
roomSetup(room, comPanel, inCutaway);
|
|
|
|
zoneSetup();
|
|
|
|
ObjectData *pod = NULL;
|
2003-10-12 13:16:35 +00:00
|
|
|
if (mode != RDM_FADE_NOJOE) {
|
|
|
|
pod = _walk->joeSetupInRoom(mode != RDM_FADE_JOE_XY, scale);
|
2003-10-11 10:09:23 +00:00
|
|
|
}
|
2003-10-12 13:16:35 +00:00
|
|
|
if (mode != RDM_NOFADE_JOE) {
|
2003-10-11 10:09:23 +00:00
|
|
|
_graphics->update();
|
|
|
|
// TODO: _display->fadeIn();
|
|
|
|
}
|
|
|
|
if (pod != NULL) {
|
|
|
|
_walk->joeMove(0, pod->x, pod->y, inCutaway);
|
2003-10-09 09:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16 Logic::findScale(uint16 x, uint16 y) {
|
|
|
|
uint16 scale = 100;
|
|
|
|
uint16 areaNum = zoneInArea(ZONE_ROOM, x, y);
|
|
|
|
if(areaNum != 0) {
|
|
|
|
scale = _area[_currentRoom][areaNum].calcScale(y);
|
|
|
|
}
|
|
|
|
return scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-03 19:47:41 +00:00
|
|
|
} // End of namespace Queen
|
2003-10-05 16:07:07 +00:00
|
|
|
|