2007-05-30 21:56:52 +00: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.
|
2006-10-04 03:29:14 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-04 03:29:14 +00:00
|
|
|
|
|
|
|
#include "agos/agos.h"
|
|
|
|
#include "agos/intern.h"
|
|
|
|
|
|
|
|
namespace AGOS {
|
|
|
|
|
|
|
|
int AGOSEngine::canPlace(Item *x, Item *y) {
|
|
|
|
Item *z = derefItem(x->parent);
|
|
|
|
|
2006-11-06 12:02:28 +00:00
|
|
|
if (getGameType() == GType_ELVIRA1) {
|
2007-06-30 16:25:59 +00:00
|
|
|
SubPlayer *p = (SubPlayer *)findChildOfType(y, kPlayerType);
|
|
|
|
SubContainer *c = (SubContainer *)findChildOfType(y, kContainerType);
|
2006-11-22 15:50:30 +00:00
|
|
|
int cap = 0;
|
2006-11-06 12:02:28 +00:00
|
|
|
int wt;
|
|
|
|
|
|
|
|
if ((c == NULL) && (p == NULL))
|
|
|
|
return 0; /* Fits Fine */
|
|
|
|
|
|
|
|
xPlace(x, NULL); /* Avoid disturbing figures */
|
|
|
|
if (c)
|
|
|
|
cap = sizeContents(y);
|
|
|
|
|
|
|
|
wt = weightOf(y);
|
|
|
|
xPlace(x, z);
|
|
|
|
if (c) {
|
|
|
|
cap = c->volume - cap;
|
|
|
|
cap -= sizeOfRec(x, 0); /* - size of item going in */
|
|
|
|
if (cap < 0)
|
|
|
|
return -1; /* Too big to fit */
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
if (wt + weightOf(x) > p->strength * 10)
|
|
|
|
return -2; /* Too heavy */
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-30 16:25:59 +00:00
|
|
|
SubObject *o = (SubObject *)findChildOfType(y, kObjectType);
|
2006-11-06 12:02:28 +00:00
|
|
|
int ct;
|
|
|
|
int cap = 0;
|
|
|
|
|
|
|
|
if (o == NULL)
|
|
|
|
return 0; /* Fits Fine */
|
|
|
|
|
|
|
|
xPlace(x,NULL); /* Avoid disturbing figures */
|
|
|
|
if (o)
|
|
|
|
cap = sizeContents(y);
|
|
|
|
|
|
|
|
xPlace(x, z);
|
|
|
|
if ((o) && (o->objectFlags & kOFVolume)) {
|
|
|
|
ct = getOffsetOfChild2Param(o, kOFVolume);
|
|
|
|
cap = o->objectFlagValue[ct] - cap;
|
|
|
|
cap -= sizeOfRec(x, 0); /* - size of item going in */
|
|
|
|
if (cap < 0)
|
|
|
|
return -1; /* Too big to fit */
|
|
|
|
}
|
|
|
|
}
|
2006-10-04 03:29:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AGOSEngine::xPlace(Item *x, Item *y) {
|
2006-11-06 13:59:11 +00:00
|
|
|
if (derefItem(x->parent))
|
2006-10-04 03:29:14 +00:00
|
|
|
unlinkItem(x);
|
|
|
|
|
|
|
|
linkItem(x, y);
|
|
|
|
}
|
|
|
|
|
2006-10-10 11:44:58 +00:00
|
|
|
int AGOSEngine::contains(Item *a, Item *b) {
|
|
|
|
while (derefItem(b->parent)) {
|
|
|
|
if (derefItem(b->parent) == a)
|
|
|
|
return 1;
|
|
|
|
b = derefItem(b->parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-04 03:29:14 +00:00
|
|
|
int AGOSEngine::sizeContents(Item *x) {
|
|
|
|
return sizeRec(x, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int AGOSEngine::sizeRec(Item *x, int d) {
|
|
|
|
Item *o;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
o = derefItem(x->child);
|
|
|
|
|
|
|
|
if (d > 32)
|
|
|
|
return(0);
|
|
|
|
while (o) {
|
|
|
|
n += sizeOfRec(o,d);
|
|
|
|
o = derefItem(o->child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2006-11-06 12:02:28 +00:00
|
|
|
int AGOSEngine::sizeOfRec(Item *i, int d) {
|
2007-06-30 16:25:59 +00:00
|
|
|
SubObject *o = (SubObject *)findChildOfType(i, kObjectType);
|
2006-11-06 12:02:28 +00:00
|
|
|
|
|
|
|
if (getGameType() == GType_ELVIRA1) {
|
2007-06-30 16:25:59 +00:00
|
|
|
SubPlayer *p = (SubPlayer *)findChildOfType(i, kPlayerType);
|
|
|
|
SubContainer *c = (SubContainer *)findChildOfType(i, kContainerType);
|
2006-10-04 03:29:14 +00:00
|
|
|
|
2006-11-06 12:02:28 +00:00
|
|
|
if ((c) && (c->flags & 1)) {
|
|
|
|
if (o)
|
|
|
|
return (o->objectSize + sizeRec(i, d + 1));
|
|
|
|
if (p)
|
|
|
|
return (p->size + sizeRec(i, d + 1));
|
|
|
|
return (sizeRec(i, d + 1));
|
|
|
|
}
|
|
|
|
if (o)
|
|
|
|
return (o->objectWeight);
|
|
|
|
if (p)
|
|
|
|
return (p->weight);
|
|
|
|
} else {
|
|
|
|
int ct;
|
|
|
|
if ((o) && (o->objectFlags & kOFSoft)) {
|
|
|
|
if (o->objectFlags & kOFSize) {
|
|
|
|
ct = getOffsetOfChild2Param(o, kOFSize);
|
|
|
|
return o->objectFlagValue[ct] + sizeRec(i, d + 1);
|
|
|
|
}
|
|
|
|
return sizeRec(i, d + 1);
|
|
|
|
}
|
|
|
|
if ((o) && (o->objectFlags & kOFSize)) {
|
|
|
|
ct = getOffsetOfChild2Param(o, kOFSize);
|
|
|
|
return o->objectFlagValue[ct];
|
2006-10-04 03:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-10 11:25:45 +00:00
|
|
|
int AGOSEngine::weighUp(Item *x) {
|
|
|
|
return weightRec(x, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int AGOSEngine::weightRec(Item *x, int d) {
|
|
|
|
int n = weightOf(x);
|
|
|
|
Item *o;
|
|
|
|
|
|
|
|
if (d > 32)
|
|
|
|
return 0;
|
|
|
|
o = derefItem(x->child);
|
|
|
|
while (o) {
|
|
|
|
n += weightRec(o, d + 1);
|
|
|
|
o = derefItem(o->next);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AGOSEngine::weightOf(Item *x) {
|
2007-06-30 16:25:59 +00:00
|
|
|
SubObject *o = (SubObject *)findChildOfType(x, kObjectType);
|
2006-11-06 12:02:28 +00:00
|
|
|
|
|
|
|
if (getGameType() == GType_ELVIRA1) {
|
2007-06-30 16:25:59 +00:00
|
|
|
SubPlayer *p = (SubPlayer *)findChildOfType(x, kPlayerType);
|
2006-11-06 12:02:28 +00:00
|
|
|
if (o)
|
|
|
|
return o->objectWeight;
|
|
|
|
if (p)
|
|
|
|
return p->weight;
|
|
|
|
} else {
|
|
|
|
if ((o) && (o->objectFlags & kOFWeight)) {
|
|
|
|
int ct = getOffsetOfChild2Param(o, kOFWeight);
|
|
|
|
return (o->objectFlagValue[ct]);
|
|
|
|
}
|
|
|
|
}
|
2006-10-10 11:25:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-04 03:29:14 +00:00
|
|
|
} // End of namespace AGOS
|