ILLUSIONS: Move Duckman inventory code to own class and file

This commit is contained in:
johndoe123 2014-12-03 21:52:52 +01:00 committed by Eugene Sandulenko
parent 18553cb17a
commit dec9ef3123
8 changed files with 260 additions and 172 deletions

View File

@ -0,0 +1,182 @@
/* 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 "illusions/duckman/illusions_duckman.h"
#include "illusions/duckman/duckman_inventory.h"
#include "illusions/actor.h"
#include "illusions/cursor.h"
#include "illusions/input.h"
#include "illusions/resources/scriptresource.h"
#include "engines/util.h"
namespace Illusions {
// DuckmanInventory
DuckmanInventory::DuckmanInventory(IllusionsEngine_Duckman *vm)
: _vm(vm) {
initInventory();
}
DuckmanInventory::~DuckmanInventory() {
}
void DuckmanInventory::initInventory() {
_inventorySlots.push_back(DMInventorySlot( 64, 52));
_inventorySlots.push_back(DMInventorySlot(112, 52));
_inventorySlots.push_back(DMInventorySlot(160, 52));
_inventorySlots.push_back(DMInventorySlot(208, 52));
_inventorySlots.push_back(DMInventorySlot(255, 52));
_inventorySlots.push_back(DMInventorySlot( 64, 84));
_inventorySlots.push_back(DMInventorySlot(112, 84));
_inventorySlots.push_back(DMInventorySlot(160, 84));
_inventorySlots.push_back(DMInventorySlot(208, 84));
_inventorySlots.push_back(DMInventorySlot(255, 84));
_inventorySlots.push_back(DMInventorySlot( 64, 116));
_inventorySlots.push_back(DMInventorySlot(112, 116));
_inventorySlots.push_back(DMInventorySlot(160, 116));
_inventorySlots.push_back(DMInventorySlot(208, 116));
_inventorySlots.push_back(DMInventorySlot(255, 116));
_inventorySlots.push_back(DMInventorySlot( 64, 148));
_inventorySlots.push_back(DMInventorySlot(112, 148));
_inventorySlots.push_back(DMInventorySlot(160, 148));
_inventorySlots.push_back(DMInventorySlot(208, 148));
_inventorySlots.push_back(DMInventorySlot(255, 148));
_inventoyItems.push_back(DMInventoryItem(0x40011, 0xE005B));
_inventoyItems.push_back(DMInventoryItem(0x40099, 0xE001B));
_inventoyItems.push_back(DMInventoryItem(0x4000F, 0xE000C));
_inventoyItems.push_back(DMInventoryItem(0x40042, 0xE0012));
_inventoyItems.push_back(DMInventoryItem(0x40044, 0xE000F));
_inventoyItems.push_back(DMInventoryItem(0x40029, 0xE000D));
_inventoyItems.push_back(DMInventoryItem(0x400A7, 0xE005D));
_inventoyItems.push_back(DMInventoryItem(0x40096, 0xE001C));
_inventoyItems.push_back(DMInventoryItem(0x40077, 0xE0010));
_inventoyItems.push_back(DMInventoryItem(0x4008A, 0xE0033));
_inventoyItems.push_back(DMInventoryItem(0x4004B, 0xE0045));
_inventoyItems.push_back(DMInventoryItem(0x40054, 0xE0021));
_inventoyItems.push_back(DMInventoryItem(0x400C6, 0xE005A));
_inventoyItems.push_back(DMInventoryItem(0x4000B, 0xE005E));
_inventoyItems.push_back(DMInventoryItem(0x4005F, 0xE0016));
_inventoyItems.push_back(DMInventoryItem(0x40072, 0xE0017));
_inventoyItems.push_back(DMInventoryItem(0x400AA, 0xE005F));
_inventoyItems.push_back(DMInventoryItem(0x400B8, 0xE0050));
_inventoyItems.push_back(DMInventoryItem(0x4001F, 0xE001A));
_inventoyItems.push_back(DMInventoryItem(0x40095, 0xE0060));
_inventoyItems.push_back(DMInventoryItem(0x40041, 0xE0053));
}
void DuckmanInventory::openInventory() {
for (uint i = 0; i < _inventorySlots.size(); ++i) {
DMInventorySlot *inventorySlot = &_inventorySlots[i];
if (inventorySlot->_objectId) {
DMInventoryItem *inventoryItem = findInventoryItem(inventorySlot->_objectId);
if (!_vm->_scriptResource->_properties.get(inventoryItem->_propertyId))
inventorySlot->_objectId = 0;
}
}
for (uint i = 0; i < _inventoyItems.size(); ++i) {
DMInventoryItem *inventoryItem = &_inventoyItems[i];
if (_vm->_scriptResource->_properties.get(inventoryItem->_propertyId)) {
DMInventorySlot *inventorySlot = findInventorySlot(inventoryItem->_objectId);
if (inventorySlot) {
Control *control = _vm->getObjectControl(inventoryItem->_objectId);
control->setActorPosition(inventorySlot->_position);
control->appearActor();
} else {
addInventoryItem(inventoryItem->_objectId);
}
}
}
}
void DuckmanInventory::addInventoryItem(uint32 objectId) {
DMInventorySlot *DMInventorySlot = findInventorySlot(0);
DMInventorySlot->_objectId = objectId;
Control *control = _vm->getObjectControl(objectId);
control->setActorPosition(DMInventorySlot->_position);
control->appearActor();
}
void DuckmanInventory::clearInventorySlot(uint32 objectId) {
for (uint i = 0; i < _inventorySlots.size(); ++i)
if (_inventorySlots[i]._objectId == objectId)
_inventorySlots[i]._objectId = 0;
}
void DuckmanInventory::putBackInventoryItem() {
Common::Point mousePos = _vm->_input->getCursorPosition();
if (_vm->_cursor._objectId) {
DMInventorySlot *inventorySlot = findInventorySlot(_vm->_cursor._objectId);
if (inventorySlot)
inventorySlot->_objectId = 0;
inventorySlot = findClosestInventorySlot(mousePos);
inventorySlot->_objectId = _vm->_cursor._objectId;
Control *control = _vm->getObjectControl(_vm->_cursor._objectId);
control->setActorPosition(inventorySlot->_position);
control->appearActor();
_vm->_cursor._actorIndex = 7;
_vm->stopCursorHoldingObject();
_vm->_cursor._actorIndex = 2;
_vm->_cursor._control->startSequenceActor(_vm->_cursor._sequenceId1, 2, 0);
if (_vm->_cursor._currOverlappedControl)
_vm->setCursorActorIndex(_vm->_cursor._actorIndex, 2, 0);
else
_vm->setCursorActorIndex(_vm->_cursor._actorIndex, 1, 0);
}
}
DMInventorySlot *DuckmanInventory::findInventorySlot(uint32 objectId) {
for (uint i = 0; i < _inventorySlots.size(); ++i)
if (_inventorySlots[i]._objectId == objectId)
return &_inventorySlots[i];
return 0;
}
DMInventoryItem *DuckmanInventory::findInventoryItem(uint32 objectId) {
for (uint i = 0; i < _inventoyItems.size(); ++i)
if (_inventoyItems[i]._objectId == objectId)
return &_inventoyItems[i];
return 0;
}
DMInventorySlot *DuckmanInventory::findClosestInventorySlot(Common::Point pos) {
int minDistance = 0xFFFFFF;
DMInventorySlot *minInventorySlot = 0;
for (uint i = 0; i < _inventorySlots.size(); ++i) {
DMInventorySlot *inventorySlot = &_inventorySlots[i];
if (inventorySlot->_objectId == 0) {
int16 deltaX = ABS(inventorySlot->_position.x - pos.x);
int16 deltaY = ABS(inventorySlot->_position.y - pos.y);
int distance = deltaX * deltaX + deltaY * deltaY;
if (inventorySlot->_objectId == 0 && distance < minDistance) {
minDistance = distance;
minInventorySlot = inventorySlot;
}
}
}
return minInventorySlot;
}
} // End of namespace Illusions

View File

@ -0,0 +1,65 @@
/* 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 ILLUSIONS_DUCKMAN_DUCKMAN_INVENTORY_H
#define ILLUSIONS_DUCKMAN_DUCKMAN_INVENTORY_H
#include "illusions/illusions.h"
namespace Illusions {
struct DMInventorySlot {
Common::Point _position;
uint32 _objectId;
DMInventorySlot() : _objectId(0) {}
DMInventorySlot(int16 x, int16 y) : _objectId(0), _position(x, y) {}
};
struct DMInventoryItem {
uint32 _objectId;
uint32 _propertyId;
DMInventoryItem() : _objectId(0) {}
DMInventoryItem(uint32 objectId, uint32 propertyId)
: _objectId(objectId), _propertyId(propertyId) {}
};
class DuckmanInventory {
public:
DuckmanInventory(IllusionsEngine_Duckman *vm);
~DuckmanInventory();
public:
IllusionsEngine_Duckman *_vm;
Common::Array<DMInventorySlot> _inventorySlots;
Common::Array<DMInventoryItem> _inventoyItems;
void initInventory();
void openInventory();
void addInventoryItem(uint32 objectId);
void clearInventorySlot(uint32 objectId);
void putBackInventoryItem();
DMInventorySlot *findInventorySlot(uint32 objectId);
DMInventoryItem *findInventoryItem(uint32 objectId);
DMInventorySlot *findClosestInventorySlot(Common::Point pos);
};
} // End of namespace Illusions
#endif // ILLUSIONS_DUCKMAN_DUCKMAN_INVENTORY_H

View File

@ -22,6 +22,7 @@
#include "illusions/duckman/illusions_duckman.h"
#include "illusions/duckman/duckman_specialcode.h"
#include "illusions/duckman/duckman_inventory.h"
#include "illusions/duckman/propertytimers.h"
#include "illusions/actor.h"
#include "illusions/resources/scriptresource.h"
@ -38,10 +39,12 @@ DuckmanSpecialCode::DuckmanSpecialCode(IllusionsEngine_Duckman *vm)
: _vm(vm) {
_propertyTimers = new PropertyTimers(_vm);
_inventory = new DuckmanInventory(_vm);
}
DuckmanSpecialCode::~DuckmanSpecialCode() {
delete _propertyTimers;
delete _inventory;
}
typedef Common::Functor1Mem<OpCall&, void, DuckmanSpecialCode> SpecialCodeFunctionDM;
@ -175,18 +178,18 @@ void DuckmanSpecialCode::spcAddChinesePuzzleAnswer(OpCall &opCall) {
}
void DuckmanSpecialCode::spcOpenInventory(OpCall &opCall) {
_vm->openInventory();
_inventory->openInventory();
_vm->notifyThreadId(opCall._threadId);
}
void DuckmanSpecialCode::spcPutBackInventoryItem(OpCall &opCall) {
_vm->putBackInventoryItem();
_inventory->putBackInventoryItem();
_vm->notifyThreadId(opCall._threadId);
}
void DuckmanSpecialCode::spcClearInventorySlot(OpCall &opCall) {
ARG_UINT32(objectId);
_vm->clearInventorySlot(objectId);
_inventory->clearInventorySlot(objectId);
_vm->notifyThreadId(opCall._threadId);
}

View File

@ -30,6 +30,7 @@
namespace Illusions {
class IllusionsEngine_Duckman;
class DuckmanInventory;
class PropertyTimers;
typedef Common::Functor1<OpCall&, void> SpecialCodeFunction;
@ -51,6 +52,7 @@ public:
byte _chinesePuzzleAnswers[3];
PropertyTimers *_propertyTimers;
DuckmanInventory *_inventory;
// Special code interface functions
void runSpecialCode(uint32 specialCodeId, OpCall &opCall);

View File

@ -130,7 +130,8 @@ Common::Error IllusionsEngine_Duckman::run() {
_globalSceneId = 0x00010003;
initInventory();
_savedInventoryActorIndex = 0;
loadSpecialCode(0);
setDefaultTextCoords();
initCursor();
@ -1132,144 +1133,4 @@ void IllusionsEngine_Duckman::updateDialogState() {
}
void IllusionsEngine_Duckman::initInventory() {
_inventorySlots.push_back(DMInventorySlot( 64, 52));
_inventorySlots.push_back(DMInventorySlot(112, 52));
_inventorySlots.push_back(DMInventorySlot(160, 52));
_inventorySlots.push_back(DMInventorySlot(208, 52));
_inventorySlots.push_back(DMInventorySlot(255, 52));
_inventorySlots.push_back(DMInventorySlot( 64, 84));
_inventorySlots.push_back(DMInventorySlot(112, 84));
_inventorySlots.push_back(DMInventorySlot(160, 84));
_inventorySlots.push_back(DMInventorySlot(208, 84));
_inventorySlots.push_back(DMInventorySlot(255, 84));
_inventorySlots.push_back(DMInventorySlot( 64, 116));
_inventorySlots.push_back(DMInventorySlot(112, 116));
_inventorySlots.push_back(DMInventorySlot(160, 116));
_inventorySlots.push_back(DMInventorySlot(208, 116));
_inventorySlots.push_back(DMInventorySlot(255, 116));
_inventorySlots.push_back(DMInventorySlot( 64, 148));
_inventorySlots.push_back(DMInventorySlot(112, 148));
_inventorySlots.push_back(DMInventorySlot(160, 148));
_inventorySlots.push_back(DMInventorySlot(208, 148));
_inventorySlots.push_back(DMInventorySlot(255, 148));
_inventoyItems.push_back(DMInventoryItem(0x40011, 0xE005B));
_inventoyItems.push_back(DMInventoryItem(0x40099, 0xE001B));
_inventoyItems.push_back(DMInventoryItem(0x4000F, 0xE000C));
_inventoyItems.push_back(DMInventoryItem(0x40042, 0xE0012));
_inventoyItems.push_back(DMInventoryItem(0x40044, 0xE000F));
_inventoyItems.push_back(DMInventoryItem(0x40029, 0xE000D));
_inventoyItems.push_back(DMInventoryItem(0x400A7, 0xE005D));
_inventoyItems.push_back(DMInventoryItem(0x40096, 0xE001C));
_inventoyItems.push_back(DMInventoryItem(0x40077, 0xE0010));
_inventoyItems.push_back(DMInventoryItem(0x4008A, 0xE0033));
_inventoyItems.push_back(DMInventoryItem(0x4004B, 0xE0045));
_inventoyItems.push_back(DMInventoryItem(0x40054, 0xE0021));
_inventoyItems.push_back(DMInventoryItem(0x400C6, 0xE005A));
_inventoyItems.push_back(DMInventoryItem(0x4000B, 0xE005E));
_inventoyItems.push_back(DMInventoryItem(0x4005F, 0xE0016));
_inventoyItems.push_back(DMInventoryItem(0x40072, 0xE0017));
_inventoyItems.push_back(DMInventoryItem(0x400AA, 0xE005F));
_inventoyItems.push_back(DMInventoryItem(0x400B8, 0xE0050));
_inventoyItems.push_back(DMInventoryItem(0x4001F, 0xE001A));
_inventoyItems.push_back(DMInventoryItem(0x40095, 0xE0060));
_inventoyItems.push_back(DMInventoryItem(0x40041, 0xE0053));
_savedInventoryActorIndex = 0;
}
void IllusionsEngine_Duckman::openInventory() {
for (uint i = 0; i < _inventorySlots.size(); ++i) {
DMInventorySlot *inventorySlot = &_inventorySlots[i];
if (inventorySlot->_objectId) {
DMInventoryItem *inventoryItem = findInventoryItem(inventorySlot->_objectId);
if (!_scriptResource->_properties.get(inventoryItem->_propertyId))
inventorySlot->_objectId = 0;
}
}
for (uint i = 0; i < _inventoyItems.size(); ++i) {
DMInventoryItem *inventoryItem = &_inventoyItems[i];
if (_scriptResource->_properties.get(inventoryItem->_propertyId)) {
DMInventorySlot *inventorySlot = findInventorySlot(inventoryItem->_objectId);
if (inventorySlot) {
Control *control = getObjectControl(inventoryItem->_objectId);
control->setActorPosition(inventorySlot->_position);
control->appearActor();
} else {
addInventoryItem(inventoryItem->_objectId);
}
}
}
}
void IllusionsEngine_Duckman::addInventoryItem(uint32 objectId) {
DMInventorySlot *DMInventorySlot = findInventorySlot(0);
DMInventorySlot->_objectId = objectId;
Control *control = getObjectControl(objectId);
control->setActorPosition(DMInventorySlot->_position);
control->appearActor();
}
void IllusionsEngine_Duckman::clearInventorySlot(uint32 objectId) {
for (uint i = 0; i < _inventorySlots.size(); ++i)
if (_inventorySlots[i]._objectId == objectId)
_inventorySlots[i]._objectId = 0;
}
void IllusionsEngine_Duckman::putBackInventoryItem() {
Common::Point mousePos = _input->getCursorPosition();
if (_cursor._objectId) {
DMInventorySlot *inventorySlot = findInventorySlot(_cursor._objectId);
if (inventorySlot)
inventorySlot->_objectId = 0;
inventorySlot = findClosestInventorySlot(mousePos);
inventorySlot->_objectId = _cursor._objectId;
Control *control = getObjectControl(_cursor._objectId);
control->setActorPosition(inventorySlot->_position);
control->appearActor();
_cursor._actorIndex = 7;
stopCursorHoldingObject();
_cursor._actorIndex = 2;
_cursor._control->startSequenceActor(_cursor._sequenceId1, 2, 0);
if (_cursor._currOverlappedControl)
setCursorActorIndex(_cursor._actorIndex, 2, 0);
else
setCursorActorIndex(_cursor._actorIndex, 1, 0);
}
}
DMInventorySlot *IllusionsEngine_Duckman::findInventorySlot(uint32 objectId) {
for (uint i = 0; i < _inventorySlots.size(); ++i)
if (_inventorySlots[i]._objectId == objectId)
return &_inventorySlots[i];
return 0;
}
DMInventoryItem *IllusionsEngine_Duckman::findInventoryItem(uint32 objectId) {
for (uint i = 0; i < _inventoyItems.size(); ++i)
if (_inventoyItems[i]._objectId == objectId)
return &_inventoyItems[i];
return 0;
}
DMInventorySlot *IllusionsEngine_Duckman::findClosestInventorySlot(Common::Point pos) {
int minDistance = 0xFFFFFF;
DMInventorySlot *minInventorySlot = 0;
for (uint i = 0; i < _inventorySlots.size(); ++i) {
DMInventorySlot *inventorySlot = &_inventorySlots[i];
if (inventorySlot->_objectId == 0) {
int16 deltaX = ABS(inventorySlot->_position.x - pos.x);
int16 deltaY = ABS(inventorySlot->_position.y - pos.y);
int distance = deltaX * deltaX + deltaY * deltaY;
if (inventorySlot->_objectId == 0 && distance < minDistance) {
minDistance = distance;
minInventorySlot = inventorySlot;
}
}
}
return minInventorySlot;
}
} // End of namespace Illusions

View File

@ -56,21 +56,6 @@ struct DialogItem {
uint32 _sequenceId;
};
struct DMInventorySlot {
Common::Point _position;
uint32 _objectId;
DMInventorySlot() : _objectId(0) {}
DMInventorySlot(int16 x, int16 y) : _objectId(0), _position(x, y) {}
};
struct DMInventoryItem {
uint32 _objectId;
uint32 _propertyId;
DMInventoryItem() : _objectId(0) {}
DMInventoryItem(uint32 objectId, uint32 propertyId)
: _objectId(objectId), _propertyId(propertyId) {}
};
struct ScreenShakerPoint {
int16 x, y;
};
@ -116,8 +101,6 @@ public:
Common::Array<DialogItem> _dialogItems;
int _savedInventoryActorIndex;
Common::Array<DMInventorySlot> _inventorySlots;
Common::Array<DMInventoryItem> _inventoyItems;
ScreenShaker *_screenShaker;
@ -202,15 +185,6 @@ public:
void startDialog(int16 *choiceOfsPtr, uint32 actorTypeId, uint32 callerThreadId);
void updateDialogState();
void initInventory();
void openInventory();
void addInventoryItem(uint32 objectId);
void clearInventorySlot(uint32 objectId);
void putBackInventoryItem();
DMInventorySlot *findInventorySlot(uint32 objectId);
DMInventoryItem *findInventoryItem(uint32 objectId);
DMInventorySlot *findClosestInventorySlot(Common::Point pos);
};
} // End of namespace Illusions

View File

@ -11,6 +11,7 @@ MODULE_OBJS := \
cursor.o \
detection.o \
dictionary.o \
duckman/duckman_inventory.o \
duckman/duckman_specialcode.o \
duckman/illusions_duckman.o \
duckman/propertytimers.o \

View File

@ -247,7 +247,7 @@ void ScriptOpcodes_Duckman::opEnterScene18(ScriptThread *scriptThread, OpCall &o
_vm->enterScene(sceneId, 0);
}
static uint dsceneId = 0, dthreadId = 0;
//static uint dsceneId = 0, dthreadId = 0;
//static uint dsceneId = 0x00010008, dthreadId = 0x00020029;//Beginning in Jac
//static uint dsceneId = 0x0001000A, dthreadId = 0x00020043;//Home front
//static uint dsceneId = 0x0001000E, dthreadId = 0x0002007C;
@ -260,7 +260,7 @@ static uint dsceneId = 0, dthreadId = 0;
//static uint dsceneId = 0x00010036, dthreadId = 0x000201B5;
//static uint dsceneId = 0x00010039, dthreadId = 0x00020089;//Map
//static uint dsceneId = 0x0001003D, dthreadId = 0x000201E0;
//static uint dsceneId = 0x0001004B, dthreadId = 0x0002029B;
static uint dsceneId = 0x0001004B, dthreadId = 0x0002029B;
//static uint dsceneId = 0x0001005B, dthreadId = 0x00020341;
//static uint dsceneId = 0x00010010, dthreadId = 0x0002008A;