got rid of _xPos, _yPos, _dir members in class Scumm

svn-id: r4578
This commit is contained in:
Max Horn 2002-07-16 18:51:27 +00:00
parent 0d943903c7
commit 32e81beb45
8 changed files with 61 additions and 72 deletions

View file

@ -548,15 +548,13 @@ void Scumm::putActor(Actor *a, int dstX, int dstY, byte room)
}
}
int Scumm::getActorXYPos(Actor *a)
int Actor::getActorXYPos(int &xPos, int &yPos)
{
if (!a)
if (!isInCurrentRoom())
return -1;
if (!a->isInCurrentRoom())
return -1;
_xPos = a->x;
_yPos = a->y;
xPos = x;
yPos = y;
return 0;
}

View file

@ -131,6 +131,7 @@ public:
int updateActorDirection();
void setActorDirection(int direction);
int getActorXYPos(int &x, int &y);
AdjustBoxResult adjustXYToBeInBox(int dstX, int dstY, int pathfrom);
void adjustActorPos();

View file

@ -135,34 +135,33 @@ int Scumm::whereIsObject(int object)
return WIO_NOT_FOUND;
}
int Scumm::getObjectOrActorXY(int object)
int Scumm::getObjectOrActorXY(int object, int &x, int &y)
{
if (object < NUM_ACTORS)
return getActorXYPos(derefActorSafe(object, "getObjectOrActorXY"));
return derefActorSafe(object, "getObjectOrActorXY")->getActorXYPos(x, y);
switch (whereIsObject(object)) {
case WIO_NOT_FOUND:
return -1;
case WIO_INVENTORY:
if (_objectOwnerTable[object] < NUM_ACTORS)
return getActorXYPos(derefActorSafe(_objectOwnerTable[object], "getObjectOrActorXY(2)"));
return derefActorSafe(_objectOwnerTable[object], "getObjectOrActorXY(2)")->getActorXYPos(x, y);
else
return 0xFF;
}
getObjectXYPos(object);
getObjectXYPos(object, x, y);
return 0;
}
/* Return the position of an object.
Returns X, Y and direction in angles
*/
void Scumm::getObjectXYPos(int object)
void Scumm::getObjectXYPos(int object, int &x, int &y, int &dir)
{
ObjectData *od = &_objs[getObjectIndex(object)];
int state;
byte *ptr;
ImageHeader *imhd;
int x, y;
if (!(_features & GF_SMALL_HEADER)) {
if (_features & GF_AFTER_V6) {
@ -190,22 +189,17 @@ void Scumm::getObjectXYPos(int object)
x = od->walk_x;
y = od->walk_y;
}
_xPos = x;
_yPos = y;
_dir = oldDirToNewDir(od->actordir & 3);
dir = oldDirToNewDir(od->actordir & 3);
} else {
x = od->walk_x;
y = od->walk_y;
_xPos = x;
_yPos = y;
_dir = oldDirToNewDir(od->actordir & 3);
dir = oldDirToNewDir(od->actordir & 3);
}
}
int Scumm::getObjActToObjActDist(int a, int b)
{
int x, y;
int x, y, x2, y2;
Actor *acta = NULL;
Actor *actb = NULL;
@ -218,23 +212,20 @@ int Scumm::getObjActToObjActDist(int a, int b)
if (acta && actb && acta->getRoom() == actb->getRoom() && acta->getRoom() && !acta->isInCurrentRoom())
return 0;
if (getObjectOrActorXY(a) == -1)
if (getObjectOrActorXY(a, x, y) == -1)
return 0xFF;
x = _xPos;
y = _yPos;
if (getObjectOrActorXY(b) == -1)
if (getObjectOrActorXY(b, x2, y2) == -1)
return 0xFF;
if (acta) {
AdjustBoxResult r = acta->adjustXYToBeInBox(_xPos, _yPos, -1);
_xPos = r.x;
_yPos = r.y;
AdjustBoxResult r = acta->adjustXYToBeInBox(x2, y2, -1);
x2 = r.x;
y2 = r.y;
}
y = abs(y - _yPos);
x = abs(x - _xPos);
y = abs(y - y2);
x = abs(x - x2);
if (y > x)
x = y;
@ -965,8 +956,9 @@ int Scumm::getObjX(int obj)
} else {
if (whereIsObject(obj) == WIO_NOT_FOUND)
return -1;
getObjectOrActorXY(obj);
return _xPos;
int x, y;
getObjectOrActorXY(obj, x, y);
return x;
}
}
@ -979,8 +971,9 @@ int Scumm::getObjY(int obj)
} else {
if (whereIsObject(obj) == WIO_NOT_FOUND)
return -1;
getObjectOrActorXY(obj);
return _yPos;
int x, y;
getObjectOrActorXY(obj, x, y);
return y;
}
}
@ -989,8 +982,9 @@ int Scumm::getObjOldDir(int obj)
if (obj < NUM_ACTORS) {
return newDirToOldDir(derefActorSafe(obj, "getObjOldDir")->facing);
} else {
getObjectXYPos(obj);
return _dir;
int x, y, dir;
getObjectXYPos(obj, x, y, dir);
return dir;
}
}
@ -999,8 +993,9 @@ int Scumm::getObjNewDir(int obj)
if (obj < NUM_ACTORS) {
return derefActorSafe(obj, "getObjNewDir")->facing;
} else {
getObjectXYPos(obj);
return oldDirToNewDir(_dir);
int x, y, dir;
getObjectXYPos(obj, x, y, dir);
return oldDirToNewDir(dir);
}
}
@ -1064,24 +1059,20 @@ int Scumm::getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2, int e,
j = i = 0xFF;
if (is_obj_1) {
if (getObjectOrActorXY(b) == -1)
if (getObjectOrActorXY(b, x, y) == -1)
return -1;
if (b < NUM_ACTORS)
i = derefActorSafe(b, "unkObjProc1")->scalex;
x = _xPos;
y = _yPos;
} else {
x = b;
y = c;
}
if (is_obj_2) {
if (getObjectOrActorXY(e) == -1)
if (getObjectOrActorXY(e, x2, y2) == -1)
return -1;
if (e < NUM_ACTORS)
j = derefActorSafe(e, "unkObjProc1(2)")->scalex;
x2 = _xPos;
y2 = _yPos;
} else {
x2 = e;
y2 = f;

View file

@ -855,17 +855,15 @@ void Scumm::cutscene(int16 *args)
void Scumm::faceActorToObj(int act, int obj)
{
int x, dir;
int x, x2, y, dir;
if (getObjectOrActorXY(act) == -1)
if (getObjectOrActorXY(act, x, y) == -1)
return;
x = _xPos;
if (getObjectOrActorXY(obj) == -1)
if (getObjectOrActorXY(obj, x2, y) == -1)
return;
dir = (_xPos > x) ? 90 : 270;
dir = (x2 > x) ? 90 : 270;
derefActorSafe(act, "faceActorToObj")->turnToDirection(dir);
}

View file

@ -1732,18 +1732,18 @@ void Scumm::o5_putActor()
void Scumm::o5_putActorAtObject()
{
int obj;
int obj, x, y;
Actor *a;
a = derefActorSafe(getVarOrDirectByte(0x80), "o5_putActorAtObject");
obj = getVarOrDirectWord(0x40);
if (whereIsObject(obj) != WIO_NOT_FOUND)
getObjectXYPos(obj);
getObjectXYPos(obj, x, y);
else {
_xPos = 240;
_yPos = 120;
x = 240;
y = 120;
}
putActor(a, _xPos, _yPos, a->room);
putActor(a, x, y, a->room);
}
void Scumm::o5_putActorInRoom()
@ -2611,8 +2611,9 @@ void Scumm::o5_walkActorToObject()
a = derefActorSafe(getVarOrDirectByte(0x80), "o5_walkActorToObject");
obj = getVarOrDirectWord(0x40);
if (whereIsObject(obj) != WIO_NOT_FOUND) {
getObjectXYPos(obj);
a->startWalkActor(_xPos, _yPos, _dir);
int x, y, dir;
getObjectXYPos(obj, x, y, dir);
a->startWalkActor(x, y, dir);
}
}

View file

@ -1341,8 +1341,9 @@ void Scumm::o6_walkActorToObj()
if (obj >= NUM_ACTORS) {
if (whereIsObject(obj) == WIO_NOT_FOUND)
return;
getObjectXYPos(obj);
a->startWalkActor(_xPos, _yPos, _dir);
int x, y, dir;
getObjectXYPos(obj, x, y, dir);
a->startWalkActor(x, y, dir);
} else {
a2 = derefActorSafe(obj, "o6_walkActorToObj(2)");
if (!a2)
@ -1397,16 +1398,14 @@ void Scumm::o6_putActorInRoom()
void Scumm::o6_putActorAtObject()
{
int room, obj, x, y;
int room, obj, x, y, dir;
Actor *a;
obj = popRoomAndObj(&room);
a = derefActorSafe(pop(), "o6_putActorAtObject");
if (whereIsObject(obj) != WIO_NOT_FOUND) {
getObjectXYPos(obj);
x = _xPos;
y = _yPos;
getObjectXYPos(obj, x, y);
} else {
x = 160;
y = 120;

View file

@ -565,7 +565,6 @@ public:
VirtScreen *_curVirtScreen;
bool _egoPositioned;
int _xPos, _yPos, _dir;
int _keyPressed;
uint16 _lastKeyHit;
uint16 _mouseButStat;
@ -788,14 +787,15 @@ public:
int getObjectRoom(int obj);
int getObjX(int obj);
int getObjY(int obj);
void getObjectXYPos(int object);
void getObjectXYPos(int object, int &x, int &y) { int dir; getObjectXYPos(object, x, y, dir); }
void getObjectXYPos(int object, int &x, int &y, int &dir);
int getObjOldDir(int obj);
int getObjNewDir(int obj);
int getObjectIndex(int object);
int whereIsObject(int object);
int findObject(int x, int y);
void findObjectInRoom(FindObjectInRoom *fo, byte findWhat, uint object, uint room);
int getObjectOrActorXY(int object); // Object and Actor...
int getObjectOrActorXY(int object, int &x, int &y); // Object and Actor...
int getObjActToObjActDist(int a, int b); // Not sure how to handle
byte *getObjOrActorName(int obj); // these three..
@ -935,7 +935,6 @@ public:
void startAnimActorEx(Actor *a, int frame, int direction);
int getProgrDirChange(Actor *a, int mode);
int getActorXYPos(Actor *a);
void walkActors();
void playActorSounds();
void setActorRedrawFlags();

View file

@ -489,9 +489,10 @@ void Scumm::startScene(int room, Actor * a, int objectNr)
if (where != WIO_ROOM && where != WIO_FLOBJECT)
error("startScene: Object %d is not in room %d", objectNr,
_currentRoom);
getObjectXYPos(objectNr);
putActor(a, _xPos, _yPos, _currentRoom);
a->setActorDirection(_dir + 180);
int x, y, dir;
getObjectXYPos(objectNr, x, y, dir);
putActor(a, x, y, _currentRoom);
a->setActorDirection(dir + 180);
a->moving = 0;
}
@ -502,8 +503,9 @@ void Scumm::startScene(int room, Actor * a, int objectNr)
if (!(_features & GF_AFTER_V7)) {
if (a && !_egoPositioned) {
getObjectXYPos(objectNr);
putActor(a, _xPos, _yPos, _currentRoom);
int x, y;
getObjectXYPos(objectNr, x, y);
putActor(a, x, y, _currentRoom);
a->moving = 0;
}
} else {