SAGA2: Move globalContainerList to Saga2Engine

This commit is contained in:
Eugene Sandulenko 2021-07-06 21:34:48 +02:00
parent 2223717753
commit 55a9867755
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
10 changed files with 60 additions and 62 deletions

View File

@ -202,7 +202,7 @@ bool ActorProto::closeAction(ObjectID dObj, ObjectID) {
assert(isActor(dObj));
GameObject *dObjPtr = GameObject::objectAddress(dObj);
ContainerNode *cn = globalContainerList.find(dObj, ContainerNode::deadType);
ContainerNode *cn = g_vm->_containerList->find(dObj, ContainerNode::deadType);
assert(dObjPtr->isOpen());
assert(cn);
@ -2189,7 +2189,9 @@ void Actor::holdInRightHand(ObjectID objID) {
assert(isObject(objID));
rightHandObject = objID;
if (isPlayerActor(this)) globalContainerList.setUpdate(thisID());
if (isPlayerActor(this))
g_vm->_containerList->setUpdate(thisID());
evalActorEnchantments(this);
}
@ -2197,7 +2199,9 @@ void Actor::holdInLeftHand(ObjectID objID) {
assert(isObject(objID));
leftHandObject = objID;
if (isPlayerActor(this)) globalContainerList.setUpdate(thisID());
if (isPlayerActor(this))
g_vm->_containerList->setUpdate(thisID());
evalActorEnchantments(this);
}
@ -2221,7 +2225,9 @@ void Actor::wear(ObjectID objID, uint8 where) {
armorObjects[where] = objID;
if (isPlayerActor(this)) globalContainerList.setUpdate(thisID());
if (isPlayerActor(this))
g_vm->_containerList->setUpdate(thisID());
evalActorEnchantments(this);
if (actorToPlayerID(this, playerID)) {

View File

@ -109,8 +109,6 @@ GameObject *ContainerView::objToGet;
int32 ContainerView::amountAccumulator = 0;
int16 ContainerView::amountIndY = -1;
ContainerList globalContainerList;
//-----------------------------------------------------------------------
// Physical container appearance
@ -1431,7 +1429,7 @@ ContainerNode::~ContainerNode() {
hide();
// Remove from container list
globalContainerList.remove(this);
g_vm->_containerList->remove(this);
}
// Restore the state of this ContainerNode from archive buffer
@ -1680,12 +1678,9 @@ ContainerNode *CreateContainerNode(ObjectID id, bool open, int16) {
if (((Actor *)obj)->isDead()) {
// Open dead container for dead actor
if (!(cn = globalContainerList.find(owner, ContainerNode::deadType)))
cn = new ContainerNode(globalContainerList, id, ContainerNode::deadType);
if (!(cn = g_vm->_containerList->find(owner, ContainerNode::deadType)))
cn = new ContainerNode(*g_vm->_containerList, id, ContainerNode::deadType);
} else if (owner != ContainerNode::nobody) {
// Open mental container for living player actor.
// if (!(cn = globalContainerList.find( owner, ContainerNode::mentalType )))
// cn = new ContainerNode( globalContainerList, id, ContainerNode::mentalType );
return OpenMindContainer(owner, open, /*mType*/ openMindType);
}
#if DEBUG
@ -1695,8 +1690,8 @@ ContainerNode *CreateContainerNode(ObjectID id, bool open, int16) {
if (actorIDToPlayerID(obj->possessor(), owner) == false)
owner = ContainerNode::nobody;
if (!(cn = globalContainerList.find(id, ContainerNode::physicalType)))
cn = new ContainerNode(globalContainerList, id, ContainerNode::physicalType);
if (!(cn = g_vm->_containerList->find(id, ContainerNode::physicalType)))
cn = new ContainerNode(*g_vm->_containerList, id, ContainerNode::physicalType);
}
// If node was successfull created, and we wanted it open, and the owner
@ -1711,7 +1706,7 @@ ContainerNode *CreateContainerNode(ObjectID id, bool open, int16) {
}
ContainerNode *CreateReadyContainerNode(PlayerActorID player) {
return new ContainerNode(globalContainerList,
return new ContainerNode(*g_vm->_containerList,
getPlayerActorAddress(player)->getActorID(),
ContainerNode::readyType);
}
@ -1720,8 +1715,8 @@ ContainerNode *OpenMindContainer(PlayerActorID player, int16 open, int16 type) {
ContainerNode *cn;
ObjectID id = getPlayerActorAddress(player)->getActorID();
if (!(cn = globalContainerList.find(id, ContainerNode::mentalType))) {
cn = new ContainerNode(globalContainerList, id, ContainerNode::mentalType);
if (!(cn = g_vm->_containerList->find(id, ContainerNode::mentalType))) {
cn = new ContainerNode(*g_vm->_containerList, id, ContainerNode::mentalType);
cn->mindType = type;
// If node was successfull created, and we wanted it open, and the owner
@ -1755,11 +1750,14 @@ void initContainers(void) {
}
void cleanupContainers(void) {
if (selImage) g_vm->_imageCache->releaseImage(selImage);
if (containerRes) resFile->disposeContext(containerRes);
if (selImage)
g_vm->_imageCache->releaseImage(selImage);
if (containerRes)
resFile->disposeContext(containerRes);
selImage = NULL;
containerRes = NULL;
delete g_vm->_containerList;
}
void initContainerNodes(void) {
@ -1769,9 +1767,7 @@ void initContainerNodes(void) {
ContainerNode *node;
bool onlyReady = true;
for (node = (ContainerNode *)globalContainerList.first();
node != NULL;
node = (ContainerNode *)node->next()) {
for (node = g_vm->_containerList->first(); node != NULL; node = node->next()) {
if (node->getType() != ContainerNode::readyType) {
onlyReady = false;
break;
@ -1789,12 +1785,12 @@ void saveContainerNodes(SaveFileConstructor &saveGame) {
int32 archiveBufSize;
// Make sure there are no pending container view actions
globalContainerList.doDeferredActions();
g_vm->_containerList->doDeferredActions();
archiveBufSize = sizeof(numNodes);
// Count the number of nodes to save
for (Common::List<ContainerNode *>::iterator it = globalContainerList._list.begin(); it != globalContainerList._list.end(); ++it) {
for (Common::List<ContainerNode *>::iterator it = g_vm->_containerList->_list.begin(); it != g_vm->_containerList->_list.end(); ++it) {
ContainerNode *n = *it;
if (n->getType() != ContainerNode::readyType)
@ -1816,7 +1812,7 @@ void saveContainerNodes(SaveFileConstructor &saveGame) {
bufferPtr = (int16 *)bufferPtr + 1;
// Store the nodes
for (Common::List<ContainerNode *>::iterator it = globalContainerList._list.begin(); it != globalContainerList._list.end(); ++it) {
for (Common::List<ContainerNode *>::iterator it = g_vm->_containerList->_list.begin(); it != g_vm->_containerList->_list.end(); ++it) {
ContainerNode *n = *it;
if (n->getType() != ContainerNode::readyType)
@ -1863,7 +1859,7 @@ void loadContainerNodes(SaveFileReader &saveGame) {
bufferPtr = node->restore(bufferPtr);
// Add it back to the container list
globalContainerList.add(node);
g_vm->_containerList->add(node);
}
assert(tempList.empty());
@ -1873,7 +1869,7 @@ void loadContainerNodes(SaveFileReader &saveGame) {
}
void cleanupContainerNodes(void) {
for (Common::List<ContainerNode *>::iterator it = globalContainerList._list.begin(); it != globalContainerList._list.end(); ++it) {
for (Common::List<ContainerNode *>::iterator it = g_vm->_containerList->_list.begin(); it != g_vm->_containerList->_list.end(); ++it) {
ContainerNode *n = *it;
if (n->getType() != ContainerNode::readyType)
@ -1882,7 +1878,7 @@ void cleanupContainerNodes(void) {
}
void updateContainerWindows(void) {
globalContainerList.doDeferredActions();
g_vm->_containerList->doDeferredActions();
}
void setMindContainer(int index, IntangibleContainerWindow &cw) {

View File

@ -522,8 +522,6 @@ public:
void setUpdate(ObjectID id);
};
extern ContainerList globalContainerList;
ContainerNode *CreateContainerNode(ObjectID id, bool open = true, int16 mindType = 0);
ContainerNode *CreateReadyContainerNode(PlayerActorID player);
ContainerNode *OpenMindContainer(PlayerActorID player, int16 open, int16 type);

View File

@ -3582,11 +3582,8 @@ void MotionTask::fireBowAction(void) {
* (actorCrossSection + projCrossSection);
actorLoc.z += a->proto()->height * 7 / 8;
if ((projID = proj->extractMerged(
Location(actorLoc, a->IDParent()),
1))
!= Nothing) {
globalContainerList.setUpdate(a->thisID());
if ((projID = proj->extractMerged(Location(actorLoc, a->IDParent()), 1)) != Nothing) {
g_vm->_containerList->setUpdate(a->thisID());
proj = GameObject::objectAddress(projID);
shootObject(*proj, *a, *targetObj, 16);
}

View File

@ -933,7 +933,7 @@ void GameObject::updateImage(ObjectID oldParentID) {
&& isPlayerActor((Actor *)oldParent))
|| (isObject(oldParentID)
&& oldParent->isOpen())) {
globalContainerList.setUpdate(oldParentID);
g_vm->_containerList->setUpdate(oldParentID);
}
if (_data.parentID != oldParentID && isActor(oldParentID)) {
@ -982,7 +982,7 @@ void GameObject::updateImage(ObjectID oldParentID) {
&& isPlayerActor((Actor *)parent))
|| (isObject(_data.parentID) && parent->isOpen())
) {
globalContainerList.setUpdate(_data.parentID);
g_vm->_containerList->setUpdate(_data.parentID);
}
}
}
@ -1223,7 +1223,7 @@ void GameObject::deleteObject(void) {
removeAllSensors();
// Delete any container nodes for this object
while ((cn = globalContainerList.find(dObj)) != nullptr)
while ((cn = g_vm->_containerList->find(dObj)) != nullptr)
delete cn;
if (isActor(_data.parentID)) {
@ -2143,7 +2143,8 @@ void GameObject::setProtoNum(int32 nProto) {
}
// If this object is in a container, then redraw the container window
if (!isWorld(oldParentID)) globalContainerList.setUpdate(oldParentID);
if (!isWorld(oldParentID))
g_vm->_containerList->setUpdate(oldParentID);
}
}
@ -2214,7 +2215,7 @@ void GameObject::mergeWith(GameObject *dropObj, GameObject *target, int16 count)
dropObj->deleteObject();
}
globalContainerList.setUpdate(target->IDParent());
g_vm->_containerList->setUpdate(target->IDParent());
}
@ -2243,7 +2244,7 @@ bool GameObject::stack(ObjectID enactor, ObjectID objToStackID) {
if (!objToStack->isMoving()) {
// Increase the stack count
_data.location.z++;
globalContainerList.setUpdate(IDParent());
g_vm->_containerList->setUpdate(IDParent());
}
return true;

View File

@ -1260,13 +1260,14 @@ bool PhysicalContainerProto::openAction(ObjectID dObj, ObjectID) {
cn = CreateContainerNode(dObj, false);
cn->markForShow(); // Deferred open
dObjPtr->_data.objectFlags |= objectOpen; // Set open bit;
globalContainerList.setUpdate(dObjPtr->IDParent());
g_vm->_containerList->setUpdate(dObjPtr->IDParent());
return true;
}
bool PhysicalContainerProto::closeAction(ObjectID dObj, ObjectID) {
GameObject *dObjPtr = GameObject::objectAddress(dObj);
ContainerNode *cn = globalContainerList.find(dObj, ContainerNode::physicalType);
ContainerNode *cn = g_vm->_containerList->find(dObj, ContainerNode::physicalType);
assert(dObjPtr->isOpen());
assert(cn);
@ -1276,7 +1277,8 @@ bool PhysicalContainerProto::closeAction(ObjectID dObj, ObjectID) {
// Clear open bit
dObjPtr->_data.objectFlags &= ~objectOpen;
globalContainerList.setUpdate(dObjPtr->IDParent());
g_vm->_containerList->setUpdate(dObjPtr->IDParent());
return true;
}
@ -1325,13 +1327,6 @@ bool PhysicalContainerProto::acceptInsertionAction(
}
}
// If we extracted the dropped objects from a pile, then make sure
// the old pile gets redrawn. PlaceObject already takes care of
// redrawing the target container; But because extractMerged creates
// the extracted portion inside of "Nothing" the source container might
// not be redrawn in this case.
// if (prevItemPtr) globalContainerList.setUpdate( prevItemPtr->IDParent() );
return true;
}
@ -2244,7 +2239,7 @@ bool ArmorProto::useAction(ObjectID dObj, ObjectID enactor) {
else
a->wear(dObj, slot);
globalContainerList.setUpdate(obj->IDParent());
g_vm->_containerList->setUpdate(obj->IDParent());
return true;
}
@ -2934,7 +2929,7 @@ bool IntangibleContainerProto::openAction(ObjectID dObj, ObjectID enactor) {
}
bool IntangibleContainerProto::closeAction(ObjectID dObj, ObjectID) {
ContainerNode *cn = globalContainerList.find(dObj, ContainerNode::mentalType);
ContainerNode *cn = g_vm->_containerList->find(dObj, ContainerNode::mentalType);
assert(cn);

View File

@ -570,7 +570,7 @@ void setCenterActor(PlayerActorID newCenter) {
viewCenterObject = playerList[centerActor].getActorID();
indivReadyNode->changeOwner(newCenter);
globalContainerList.setPlayerNum(newCenter);
g_vm->_containerList->setPlayerNum(newCenter);
setEnchantmentDisplay();
if (a->curTask != NULL) {

View File

@ -36,6 +36,7 @@
#include "saga2/gdraw.h"
#include "saga2/mouseimg.h"
#include "saga2/contain.h"
namespace Saga2 {
@ -79,6 +80,8 @@ Common::Error Saga2Engine::run() {
// Initialize graphics using following:
initGraphics(640, 480);
_containerList = new ContainerList;
readConfig();
loadExeResources();

View File

@ -40,6 +40,7 @@ class SmackerDecoder;
namespace Saga2 {
class ContainerList;
class Timer;
class TimerList;
class BandList;
@ -116,7 +117,7 @@ public:
GrabInfo *_mouseInfo;
EffectDisplayPrototypeList *_edpList;
SpellDisplayPrototypeList *_sdpList;
ContainerList *_containerList;
gDisplayPort _mainPort;

View File

@ -248,7 +248,7 @@ int16 scriptActorTransfer(int16 *args) {
obj->move(Location(targetSlot, targetID));
if ((cSet & (ProtoObj::isIntangible | ProtoObj::isContainer))
== (ProtoObj::isIntangible | ProtoObj::isContainer))
globalContainerList.setUpdate(targetID);
g_vm->_containerList->setUpdate(targetID);
}
} else {
obj->move(Location(args[1], args[2], args[3], args[0]));
@ -984,7 +984,7 @@ int16 scriptGameObjectSetMass(int16 *args) {
if (obj->proto()->flags & ResourceObjectPrototype::objPropMergeable) {
obj->setExtra(args[0]);
if (obj->proto()->flags & ResourceObjectPrototype::objPropMergeable) {
globalContainerList.setUpdate(obj->IDParent());
g_vm->_containerList->setUpdate(obj->IDParent());
}
return true;
} else return false;
@ -2096,13 +2096,13 @@ int16 scriptActorDeductPayment(int16 *args) {
if (massCount > paymentAmount) {
obj->setExtra(massCount - paymentAmount);
globalContainerList.setUpdate(obj->IDParent());
g_vm->_containerList->setUpdate(obj->IDParent());
break;
} else {
if (delObj) {
ObjectID dParent = delObj->IDParent();
delObj->deleteObject();
globalContainerList.setUpdate(dParent);
g_vm->_containerList->setUpdate(dParent);
}
paymentAmount -= massCount;
delObj = obj;
@ -2115,7 +2115,7 @@ int16 scriptActorDeductPayment(int16 *args) {
if (delObj) {
ObjectID dParent = delObj->IDParent();
delObj->deleteObject();
globalContainerList.setUpdate(dParent);
g_vm->_containerList->setUpdate(dParent);
}
delObj = obj;
}
@ -2125,7 +2125,7 @@ int16 scriptActorDeductPayment(int16 *args) {
if (delObj) {
ObjectID dParent = delObj->IDParent();
delObj->deleteObject();
globalContainerList.setUpdate(dParent);
g_vm->_containerList->setUpdate(dParent);
}
// Payment succeeded!
@ -2989,7 +2989,8 @@ int16 scriptDeleteObject(int16 *args) {
assert(obj);
oldParentID = obj->IDParent();
obj->deleteObjectRecursive();
globalContainerList.setUpdate(oldParentID);
g_vm->_containerList->setUpdate(oldParentID);
return 0;
}