diff options
Diffstat (limited to 'engines/fullpipe/motion.cpp')
-rw-r--r-- | engines/fullpipe/motion.cpp | 567 |
1 files changed, 286 insertions, 281 deletions
diff --git a/engines/fullpipe/motion.cpp b/engines/fullpipe/motion.cpp index fbfa602e62..81d92ccac8 100644 --- a/engines/fullpipe/motion.cpp +++ b/engines/fullpipe/motion.cpp @@ -132,11 +132,11 @@ int MctlCompound::detachObject(StaticANIObject *obj) { return 1; } -void MctlCompound::initMovGraph2() { +void MctlCompound::initMctlGraph() { if (_objtype != kObjTypeMctlCompound) return; - debugC(4, kDebugPathfinding, "MctlCompound::initMovGraph2()"); + debugC(4, kDebugPathfinding, "MctlCompound::initMctlGraph()"); for (uint i = 0; i < _motionControllers.size(); i++) { if (_motionControllers[i]->_motionControllerObj->_objtype != kObjTypeMovGraph) @@ -144,7 +144,7 @@ void MctlCompound::initMovGraph2() { MovGraph *gr = (MovGraph *)_motionControllers[i]->_motionControllerObj; - MovGraph2 *newgr = new MovGraph2(); + MctlGraph *newgr = new MctlGraph(); newgr->_links = gr->_links; newgr->_nodes = gr->_nodes; @@ -208,7 +208,7 @@ MessageQueue *MctlCompound::startMove(StaticANIObject *ani, int sourceX, int sou if (!cp) return 0; - MessageQueue *mq = _motionControllers[idx]->_motionControllerObj->doWalkTo(ani, cp->_connectionX, cp->_connectionY, 1, cp->_mctlmirror); + MessageQueue *mq = _motionControllers[idx]->_motionControllerObj->makeQueue(ani, cp->_connectionX, cp->_connectionY, 1, cp->_mctlmirror); if (!mq) return 0; @@ -237,11 +237,11 @@ MessageQueue *MctlCompound::startMove(StaticANIObject *ani, int sourceX, int sou return mq; } -MessageQueue *MctlCompound::doWalkTo(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) { +MessageQueue *MctlCompound::makeQueue(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) { int match1 = -1; int match2 = -1; - debugC(1, kDebugPathfinding, "MctlCompound::doWalkTo(*%d, %d, %d, %d, %d)", (subj ? subj->_id : -1), xpos, ypos, fuzzyMatch, staticsId); + debugC(1, kDebugPathfinding, "MctlCompound::makeQueue(*%d, %d, %d, %d, %d)", (subj ? subj->_id : -1), xpos, ypos, fuzzyMatch, staticsId); if (!subj) return 0; @@ -271,7 +271,7 @@ MessageQueue *MctlCompound::doWalkTo(StaticANIObject *subj, int xpos, int ypos, return 0; if (match1 == match2) - return _motionControllers[match1]->_motionControllerObj->doWalkTo(subj, xpos, ypos, fuzzyMatch, staticsId); + return _motionControllers[match1]->_motionControllerObj->makeQueue(subj, xpos, ypos, fuzzyMatch, staticsId); double dist; MctlConnectionPoint *closestP = findClosestConnectionPoint(subj->_ox, subj->_oy, match1, xpos, ypos, match2, &dist); @@ -279,7 +279,7 @@ MessageQueue *MctlCompound::doWalkTo(StaticANIObject *subj, int xpos, int ypos, if (!closestP) return 0; - MessageQueue *mq = _motionControllers[match1]->_motionControllerObj->doWalkTo(subj, closestP->_connectionX, closestP->_connectionY, 1, closestP->_mctlmirror); + MessageQueue *mq = _motionControllers[match1]->_motionControllerObj->makeQueue(subj, closestP->_connectionX, closestP->_connectionY, 1, closestP->_mctlmirror); ExCommand *ex; @@ -348,7 +348,7 @@ void MctlLadder::attachObject(StaticANIObject *obj) { MctlLadderMovement *movement = new MctlLadderMovement; if (initMovement(obj, movement)) { - _mgm.addItem(obj->_id); + _aniHandler.attachObject(obj->_id); _ladmovements.push_back(movement); } else { delete movement; @@ -372,16 +372,16 @@ bool MctlLadder::initMovement(StaticANIObject *ani, MctlLadderMovement *movement if (!v) return false; - v = v->getSubVarByName("Test_Ladder"); + GameVar *l = v->getSubVarByName("Test_Ladder"); - if (!v) + if (!l) return false; movement->staticIdsSize = 6; movement->movVars = new MctlLadderMovementVars; movement->staticIds = new int[movement->staticIdsSize]; - v = v->getSubVarByName("Up"); + v = l->getSubVarByName("Up"); if (!v) return false; @@ -393,7 +393,7 @@ bool MctlLadder::initMovement(StaticANIObject *ani, MctlLadderMovement *movement movement->staticIds[0] = ani->getMovementById(movement->movVars->varUpStart)->_staticsObj1->_staticsId; movement->staticIds[2] = ani->getMovementById(movement->movVars->varUpGo)->_staticsObj1->_staticsId; - v = v->getSubVarByName("Down"); + v = l->getSubVarByName("Down"); if (!v) return false; @@ -413,7 +413,7 @@ bool MctlLadder::initMovement(StaticANIObject *ani, MctlLadderMovement *movement void MctlLadder::detachAllObjects() { debugC(4, kDebugPathfinding, "MctlLadder::detachAllObjects()"); - _mgm.clear(); + _aniHandler.detachAllObjects(); for (uint i = 0; i < _ladmovements.size(); i++) { delete _ladmovements[i]->movVars; @@ -426,7 +426,7 @@ void MctlLadder::detachAllObjects() { MessageQueue *MctlLadder::startMove(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) { debugC(4, kDebugPathfinding, "MctlLadder::startMove(*%d, %d, %d, %d, %d)", (subj ? subj->_id : -1), xpos, ypos, fuzzyMatch, staticsId); - MessageQueue *mq = doWalkTo(subj, xpos, ypos, fuzzyMatch, staticsId); + MessageQueue *mq = makeQueue(subj, xpos, ypos, fuzzyMatch, staticsId); if (mq) { if (mq->chain(subj)) @@ -436,8 +436,8 @@ MessageQueue *MctlLadder::startMove(StaticANIObject *subj, int xpos, int ypos, i return 0; } -MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int fuzzyMatch, int staticsId) { - debugC(1, kDebugPathfinding, "MctlLadder::doWalkTo(*%d, %d, %d, %d, %d)", (ani ? ani->_id : -1), xpos, ypos, fuzzyMatch, staticsId); +MessageQueue *MctlLadder::makeQueue(StaticANIObject *ani, int xpos, int ypos, int fuzzyMatch, int staticsId) { + debugC(1, kDebugPathfinding, "MctlLadder::makeQueue(*%d, %d, %d, %d, %d)", (ani ? ani->_id : -1), xpos, ypos, fuzzyMatch, staticsId); int pos = findObjectPos(ani); @@ -459,7 +459,7 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int int direction = (normy - ani->_oy) < 0 ? 0 : 1; - MGMInfo mgminfo; + MakeQueueStruct mkQueue; PicAniInfo picinfo; MessageQueue *mq; ExCommand *ex; @@ -476,7 +476,7 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int ani->_movement = 0; ani->setOXY(point.x + ox, point.y + oy); - mq = doWalkTo(ani, normx, normy, fuzzyMatch, staticsId); + mq = makeQueue(ani, normx, normy, fuzzyMatch, staticsId); ani->setPicAniInfo(&picinfo); @@ -484,38 +484,38 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int } if (ani->_statics->_staticsId == _ladmovements[pos]->staticIds[0]) { - mgminfo.ani = ani; + mkQueue.ani = ani; if (staticsId) - mgminfo.staticsId2 = staticsId; + mkQueue.staticsId2 = staticsId; else - mgminfo.staticsId2 = _ladmovements[pos]->staticIds[direction]; + mkQueue.staticsId2 = _ladmovements[pos]->staticIds[direction]; - mgminfo.x1 = normx; - mgminfo.y1 = normy; - mgminfo.field_1C = _ladder_field_14; - mgminfo.flags = 14; - mgminfo.movementId = direction ? _ladmovements[pos]->movVars->varDownGo : _ladmovements[pos]->movVars->varUpGo; + mkQueue.x1 = normx; + mkQueue.y1 = normy; + mkQueue.field_1C = _ladder_field_14; + mkQueue.flags = 14; + mkQueue.movementId = direction ? _ladmovements[pos]->movVars->varDownGo : _ladmovements[pos]->movVars->varUpGo; - return _mgm.genMovement(&mgminfo); + return _aniHandler.makeRunQueue(&mkQueue); } if (ani->_statics->_staticsId == _ladmovements[pos]->staticIds[2]) { if (!direction) { - mgminfo.ani = ani; + mkQueue.ani = ani; if (staticsId) - mgminfo.staticsId2 = staticsId; + mkQueue.staticsId2 = staticsId; else - mgminfo.staticsId2 = _ladmovements[pos]->staticIds[0]; + mkQueue.staticsId2 = _ladmovements[pos]->staticIds[0]; - mgminfo.x1 = normx; - mgminfo.y1 = normy; - mgminfo.field_1C = _ladder_field_14; - mgminfo.flags = 14; - mgminfo.movementId = _ladmovements[pos]->movVars->varUpGo; + mkQueue.x1 = normx; + mkQueue.y1 = normy; + mkQueue.field_1C = _ladder_field_14; + mkQueue.flags = 14; + mkQueue.movementId = _ladmovements[pos]->movVars->varUpGo; - return _mgm.genMovement(&mgminfo); + return _aniHandler.makeRunQueue(&mkQueue); } int ox = ani->_ox; @@ -523,23 +523,23 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int ani->getMovementById(_ladmovements[pos]->movVars->varUpStop)->calcSomeXY(point, 0, -1); - mgminfo.ani = ani; + mkQueue.ani = ani; if (staticsId) - mgminfo.staticsId2 = staticsId; + mkQueue.staticsId2 = staticsId; else - mgminfo.staticsId2 = _ladmovements[pos]->staticIds[1]; + mkQueue.staticsId2 = _ladmovements[pos]->staticIds[1]; - mgminfo.field_1C = _ladder_field_14; - mgminfo.x1 = normx; - mgminfo.y1 = normy; - mgminfo.y2 = point.y + oy; - mgminfo.x2 = point.x + ox; - mgminfo.flags = 63; - mgminfo.staticsId1 = _ladmovements[pos]->staticIds[0]; - mgminfo.movementId = _ladmovements[pos]->movVars->varDownGo; + mkQueue.field_1C = _ladder_field_14; + mkQueue.x1 = normx; + mkQueue.y1 = normy; + mkQueue.y2 = point.y + oy; + mkQueue.x2 = point.x + ox; + mkQueue.flags = 63; + mkQueue.staticsId1 = _ladmovements[pos]->staticIds[0]; + mkQueue.movementId = _ladmovements[pos]->movVars->varDownGo; - mq = _mgm.genMovement(&mgminfo); + mq = _aniHandler.makeRunQueue(&mkQueue); ex = new ExCommand(ani->_id, 1, _ladmovements[pos]->movVars->varUpStop, 0, 0, 0, 1, 0, 0, 0); ex->_keyCode = ani->_okeyCode; @@ -551,7 +551,7 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int } if (ani->_statics->_staticsId != _ladmovements[pos]->staticIds[3]) { - mq = _mgm.genMQ(ani, _ladmovements[pos]->staticIds[0], 0, 0, 0); + mq = _aniHandler.makeQueue(ani, _ladmovements[pos]->staticIds[0], 0, 0, 0); if (!mq) return 0; @@ -559,7 +559,7 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int int nx = ani->_ox; int ny = ani->_oy; - _mgm.getPoint(&point, ani->_id, ani->_statics->_staticsId, _ladmovements[pos]->staticIds[0]); + _aniHandler.getTransitionSize(&point, ani->_id, ani->_statics->_staticsId, _ladmovements[pos]->staticIds[0]); nx += point.x; ny += point.y; @@ -570,9 +570,9 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int ani->_movement = 0; ani->setOXY(nx, ny); - MessageQueue *newmq = doWalkTo(ani, normx, normy, fuzzyMatch, staticsId); + MessageQueue *newmq = makeQueue(ani, normx, normy, fuzzyMatch, staticsId); - mq->transferExCommands(newmq); + mq->mergeQueue(newmq); delete newmq; @@ -590,22 +590,22 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int nx += point.x; ny += point.y; - mgminfo.ani = ani; + mkQueue.ani = ani; if (staticsId) - mgminfo.staticsId2 = staticsId; + mkQueue.staticsId2 = staticsId; else - mgminfo.staticsId2 = _ladmovements[pos]->staticIds[0]; + mkQueue.staticsId2 = _ladmovements[pos]->staticIds[0]; - mgminfo.field_1C = _ladder_field_14; - mgminfo.x1 = normx; - mgminfo.y1 = normy; - mgminfo.y2 = ny; - mgminfo.x2 = nx; - mgminfo.flags = 63; - mgminfo.staticsId1 = _ladmovements[pos]->staticIds[1]; - mgminfo.movementId = _ladmovements[pos]->movVars->varUpGo; + mkQueue.field_1C = _ladder_field_14; + mkQueue.x1 = normx; + mkQueue.y1 = normy; + mkQueue.y2 = ny; + mkQueue.x2 = nx; + mkQueue.flags = 63; + mkQueue.staticsId1 = _ladmovements[pos]->staticIds[1]; + mkQueue.movementId = _ladmovements[pos]->movVars->varUpGo; - mq = _mgm.genMovement(&mgminfo); + mq = _aniHandler.makeRunQueue(&mkQueue); ex = new ExCommand(ani->_id, 1, _ladmovements[pos]->movVars->varDownStop, 0, 0, 0, 1, 0, 0, 0); ex->_keyCode = ani->_okeyCode; @@ -617,24 +617,24 @@ MessageQueue *MctlLadder::doWalkTo(StaticANIObject *ani, int xpos, int ypos, int } - mgminfo.ani = ani; + mkQueue.ani = ani; if (staticsId) - mgminfo.staticsId2 = staticsId; + mkQueue.staticsId2 = staticsId; else - mgminfo.staticsId2 = _ladmovements[pos]->staticIds[1]; + mkQueue.staticsId2 = _ladmovements[pos]->staticIds[1]; - mgminfo.x1 = normx; - mgminfo.y1 = normy; - mgminfo.field_1C = _ladder_field_14; - mgminfo.flags = 14; - mgminfo.movementId = _ladmovements[pos]->movVars->varDownGo; + mkQueue.x1 = normx; + mkQueue.y1 = normy; + mkQueue.field_1C = _ladder_field_14; + mkQueue.flags = 14; + mkQueue.movementId = _ladmovements[pos]->movVars->varDownGo; - return _mgm.genMovement(&mgminfo); + return _aniHandler.makeRunQueue(&mkQueue); } MessageQueue *MctlLadder::controllerWalkTo(StaticANIObject *ani, int off) { - return doWalkTo(ani, _ladderX + off * _width, _ladderY + off * _height, 1, 0); + return makeQueue(ani, _ladderX + off * _width, _ladderY + off * _height, 1, 0); } MctlConnectionPoint *MctlCompound::findClosestConnectionPoint(int ox, int oy, int destIndex, int connectionX, int connectionY, int sourceIdx, double *minDistancePtr) { @@ -705,7 +705,7 @@ MctlConnectionPoint::~MctlConnectionPoint() { delete _messageQueueObj; } -MovInfo1::MovInfo1(MovInfo1 *src) { +MctlMQ::MctlMQ(MctlMQ *src) { index = src->index; pt1 = src->pt1; pt2 = src->pt2; @@ -718,7 +718,7 @@ MovInfo1::MovInfo1(MovInfo1 *src) { flags = src->flags; } -void MovInfo1::clear() { +void MctlMQ::clear() { index = 0; pt1.x = pt1.y = 0; pt2.x = pt2.y = 0; @@ -806,8 +806,8 @@ bool MovGraph::load(MfcArchive &file) { void MovGraph::attachObject(StaticANIObject *obj) { debugC(4, kDebugPathfinding, "MovGraph::attachObject(*%d)", obj->_id); - _mgm.clear(); - _mgm.addItem(obj->_id); + _aniHandler.detachAllObjects(); + _aniHandler.attachObject(obj->_id); for (uint i = 0; i < _items.size(); i++) if (_items[i]->ani == obj) @@ -819,7 +819,7 @@ void MovGraph::attachObject(StaticANIObject *obj) { _items.push_back(item); - _mgm.addItem(obj->_id); // FIXME: Is it really needed? + _aniHandler.attachObject(obj->_id); // FIXME: Is it really needed? } int MovGraph::detachObject(StaticANIObject *obj) { @@ -1008,8 +1008,8 @@ bool MovGraph::resetPosition(StaticANIObject *ani, int flag) { Statics *st; if (ani->_statics) { - int t = _mgm.refreshOffsets(ani->_id, ani->_statics->_staticsId, movarr._link->_dwordArray2[_field_44]); - if (t > _mgm.refreshOffsets(ani->_id, ani->_statics->_staticsId, movarr._link->_dwordArray2[_field_44 + 1])) + int t = _aniHandler.getNumMovements(ani->_id, ani->_statics->_staticsId, movarr._link->_dwordArray2[_field_44]); + if (t > _aniHandler.getNumMovements(ani->_id, ani->_statics->_staticsId, movarr._link->_dwordArray2[_field_44 + 1])) st = ani->getStaticsById(movarr._link->_dwordArray2[_field_44 + 1]); else st = ani->getStaticsById(movarr._link->_dwordArray2[_field_44]); @@ -1051,8 +1051,8 @@ bool MovGraph::canDropInventory(StaticANIObject *ani, int x, int y) { return false; } -MessageQueue *MovGraph::doWalkTo(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) { - debugC(1, kDebugPathfinding, "MovGraph::doWalkTo(*%d, %d, %d, %d, %d)", (subj ? subj->_id : -1), xpos, ypos, fuzzyMatch, staticsId); +MessageQueue *MovGraph::makeQueue(StaticANIObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) { + debugC(1, kDebugPathfinding, "MovGraph::makeQueue(*%d, %d, %d, %d, %d)", (subj ? subj->_id : -1), xpos, ypos, fuzzyMatch, staticsId); PicAniInfo picAniInfo; int ss; @@ -1230,28 +1230,28 @@ MessageQueue *MovGraph::makeWholeQueue(StaticANIObject *ani, MovArr *movarr, int } } - MGMInfo mgminfo; + MakeQueueStruct mkQueue; - memset(&mgminfo, 0, sizeof(mgminfo)); - mgminfo.ani = ani; - mgminfo.staticsId2 = id2; - mgminfo.staticsId1 = id1; - mgminfo.x1 = nx; - mgminfo.x2 = ox; - mgminfo.y2 = oy; - mgminfo.y1 = ny; - mgminfo.field_1C = nd; - mgminfo.movementId = st->link->_dwordArray1[_field_44 + st->sfield_0]; + memset(&mkQueue, 0, sizeof(mkQueue)); + mkQueue.ani = ani; + mkQueue.staticsId2 = id2; + mkQueue.staticsId1 = id1; + mkQueue.x1 = nx; + mkQueue.x2 = ox; + mkQueue.y2 = oy; + mkQueue.y1 = ny; + mkQueue.field_1C = nd; + mkQueue.movementId = st->link->_dwordArray1[_field_44 + st->sfield_0]; - mgminfo.flags = 0xe; + mkQueue.flags = 0xe; if (mq) - mgminfo.flags |= 0x31; + mkQueue.flags |= 0x31; - MessageQueue *newmq = _mgm.genMovement(&mgminfo); + MessageQueue *newmq = _aniHandler.makeRunQueue(&mkQueue); if (mq) { if (newmq) { - mq->transferExCommands(newmq); + mq->mergeQueue(newmq); delete newmq; } @@ -1332,9 +1332,9 @@ double MovGraph::putToLink(Common::Point *point, MovGraphLink *link, int fuzzyMa int n2x = link->_graphDst->_x; int n2y = link->_graphDst->_y; double dist1x = (double)(point->x - n1x); - double dist1y = (double)(point->y - n1y); + double dist1y = (double)(n1y - point->y); double dist2x = (double)(n2x - n1x); - double dist2y = (double)(n2y - n1y); + double dist2y = (double)(n1y - n2y); double dist1 = sqrt(dist1x * dist1x + dist1y * dist1y); double dist2 = (dist2y * dist1y + dist2x * dist1x) / link->_length / dist1; double distm = dist2 * dist1; @@ -1355,8 +1355,8 @@ double MovGraph::putToLink(Common::Point *point, MovGraphLink *link, int fuzzyMa return -1.0; } } else { - point->x = (int)(n1x + (dist2x * distm / link->_length)); - point->y = (int)(n1y + (dist2y * distm / link->_length)); + point->x = n1x + (int)((double)(n2x - n1x) * distm / link->_length); + point->y = n1y + (int)((double)(n2y - n1y) * distm / link->_length); } return res; @@ -1608,14 +1608,14 @@ bool MovGraph::getHitPoint(int idx, int x, int y, MovArr *arr, int a6) { int offmin = 100; for (int i = 0; i < arrSize; i++) { - int off = _mgm.refreshOffsets(_items[idx]->ani->_id, staticsId, (*movarr)[i]->_link->_dwordArray2[_field_44]); + int off = _aniHandler.getNumMovements(_items[idx]->ani->_id, staticsId, (*movarr)[i]->_link->_dwordArray2[_field_44]); if (off < offmin) { offmin = off; idxmin = i; } - off = _mgm.refreshOffsets(_items[idx]->ani->_id, staticsId, (*movarr)[i]->_link->_dwordArray2[_field_44 + 1]); + off = _aniHandler.getNumMovements(_items[idx]->ani->_id, staticsId, (*movarr)[i]->_link->_dwordArray2[_field_44 + 1]); if (off < offmin) { offmin = off; idxmin = i; @@ -1657,7 +1657,7 @@ void MovGraph::setEnds(MovStep *step1, MovStep *step2) { } } -int MovGraph2::getItemIndexByGameObjectId(int objectId) { +int MctlGraph::getObjIndex(int objectId) { for (uint i = 0; i < _items2.size(); i++) if (_items2[i]->_objectId == objectId) return i; @@ -1665,7 +1665,7 @@ int MovGraph2::getItemIndexByGameObjectId(int objectId) { return -1; } -int MovGraph2::getItemSubIndexByStaticsId(int idx, int staticsId) { +int MctlGraph::getDirByStatics(int idx, int staticsId) { for (int i = 0; i < 4; i++) if (_items2[idx]->_subItems[i]._staticsId1 == staticsId || _items2[idx]->_subItems[i]._staticsId2 == staticsId) return i; @@ -1673,7 +1673,7 @@ int MovGraph2::getItemSubIndexByStaticsId(int idx, int staticsId) { return -1; } -int MovGraph2::getItemSubIndexByMovementId(int idx, int movId) { +int MctlGraph::getDirByMovement(int idx, int movId) { for (int i = 0; i < 4; i++) if (_items2[idx]->_subItems[i]._walk[0]._movementId == movId || _items2[idx]->_subItems[i]._turn[0]._movementId == movId || _items2[idx]->_subItems[i]._turnS[0]._movementId == movId) @@ -1682,14 +1682,14 @@ int MovGraph2::getItemSubIndexByMovementId(int idx, int movId) { return -1; } -int MovGraph2::getItemSubIndexByMGM(int index, StaticANIObject *ani) { - if (findNode(ani->_ox, ani->_oy, 0) || findLink1(ani->_ox, ani->_oy, -1, 0) || findLink2(ani->_ox, ani->_oy)) { +int MctlGraph::getDirByPoint(int index, StaticANIObject *ani) { + if (getHitNode(ani->_ox, ani->_oy, 0) || getHitLink(ani->_ox, ani->_oy, -1, 0) || getNearestLink(ani->_ox, ani->_oy)) { int minidx = -1; int min = 0; for (int i = 0; i < 4; i++) { debugC(1, kDebugPathfinding, "WWW 5"); - int tmp = _mgm.refreshOffsets(ani->_id, ani->_statics->_staticsId, _items2[index]->_subItems[i]._staticsId1); + int tmp = _aniHandler.getNumMovements(ani->_id, ani->_statics->_staticsId, _items2[index]->_subItems[i]._staticsId1); if (tmp >= 0 && (minidx == -1 || tmp < min)) { minidx = i; @@ -1703,8 +1703,8 @@ int MovGraph2::getItemSubIndexByMGM(int index, StaticANIObject *ani) { return -1; } -bool MovGraph2::initDirections(StaticANIObject *obj, MovGraph2Item *item) { - debugC(4, kDebugPathfinding, "MovGraph::initDirections(%d, ...)", obj->_id); +bool MctlGraph::fillData(StaticANIObject *obj, MctlAni *item) { + debugC(4, kDebugPathfinding, "MovGraph::fillData(%d, ...)", obj->_id); item->_obj = obj; item->_objectId = obj->_id; @@ -1834,19 +1834,19 @@ bool MovGraph2::initDirections(StaticANIObject *obj, MovGraph2Item *item) { return true; } -void MovGraph2::attachObject(StaticANIObject *obj) { - debugC(4, kDebugPathfinding, "MovGraph2::attachObject(*%d)", obj->_id); +void MctlGraph::attachObject(StaticANIObject *obj) { + debugC(4, kDebugPathfinding, "MctlGraph::attachObject(*%d)", obj->_id); MovGraph::attachObject(obj); - int id = getItemIndexByGameObjectId(obj->_id); + int id = getObjIndex(obj->_id); if (id >= 0) { _items2[id]->_obj = obj; } else { - MovGraph2Item *item = new MovGraph2Item; + MctlAni *item = new MctlAni; - if (initDirections(obj, item)) { + if (fillData(obj, item)) { _items2.push_back(item); } else { delete item; @@ -1854,10 +1854,10 @@ void MovGraph2::attachObject(StaticANIObject *obj) { } } -void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphLink *> *linkList, LinkInfo *lnkSrc, LinkInfo *lnkDst) { - debugC(4, kDebugPathfinding, "MovGraph2::buildMovInfo1SubItems(...)"); +void MctlGraph::generateList(MctlMQ *movinfo, Common::Array<MovGraphLink *> *linkList, LinkInfo *lnkSrc, LinkInfo *lnkDst) { + debugC(4, kDebugPathfinding, "MctlGraph::generateList(...)"); - MovInfo1Sub *elem; + MctlMQSub *elem; Common::Point point; Common::Rect rect; @@ -1865,7 +1865,7 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL movinfo->items.clear(); - elem = new MovInfo1Sub; + elem = new MctlMQSub; elem->subIndex = subIndex; elem->x = movinfo->pt1.x; elem->y = movinfo->pt1.y; @@ -1880,9 +1880,9 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL if (linkList->size() <= 1) { if (linkList->size() == 1) - idx1 = getShortSide((*linkList)[0], movinfo->pt2.x - movinfo->pt1.x, movinfo->pt2.y - movinfo->pt1.y); + idx1 = getDirBySize((*linkList)[0], movinfo->pt2.x - movinfo->pt1.x, movinfo->pt2.y - movinfo->pt1.y); else - idx1 = getShortSide(0, movinfo->pt2.x - movinfo->pt1.x, movinfo->pt2.y - movinfo->pt1.y); + idx1 = getDirBySize(0, movinfo->pt2.x - movinfo->pt1.x, movinfo->pt2.y - movinfo->pt1.y); point.y = -1; rect.bottom = -1; @@ -1890,14 +1890,14 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL rect.top = -1; rect.left = -1; } else { - idx1 = findLink(linkList, i, &rect, &point); + idx1 = getLinkDir(linkList, i, &rect, &point); } if (idx1 != prevSubIndex) { prevSubIndex = idx1; subIndex = idx1; - elem = new MovInfo1Sub; + elem = new MctlMQSub; elem->subIndex = subIndex; elem->x = rect.left; elem->y = rect.top; @@ -1909,9 +1909,9 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL if (i != linkList->size() - 1) { while (1) { i++; - if (findLink(linkList, i, &rect, 0) != prevSubIndex) { + if (getLinkDir(linkList, i, &rect, 0) != prevSubIndex) { i--; - findLink(linkList, i, &rect, &point); + getLinkDir(linkList, i, &rect, &point); break; } @@ -1924,7 +1924,7 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL if (movinfo->items.back()->subIndex != 10) { subIndex = prevSubIndex; - elem = new MovInfo1Sub; + elem = new MctlMQSub; elem->subIndex = 10; elem->x = -1; elem->y = -1; @@ -1932,8 +1932,8 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL movinfo->items.push_back(elem); - if (i == linkList->size()) { - elem = new MovInfo1Sub; + if (i == linkList->size() - 1) { + elem = new MctlMQSub; elem->subIndex = prevSubIndex; elem->x = movinfo->pt2.x; elem->y = movinfo->pt2.y; @@ -1941,7 +1941,7 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL movinfo->items.push_back(elem); } else { - elem = new MovInfo1Sub; + elem = new MctlMQSub; elem->subIndex = prevSubIndex; elem->x = rect.right; elem->y = rect.bottom; @@ -1953,7 +1953,7 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL } if (subIndex != movinfo->item1Index) { - elem = new MovInfo1Sub; + elem = new MctlMQSub; elem->subIndex = movinfo->item1Index; elem->x = movinfo->pt2.x; elem->y = movinfo->pt2.y; @@ -1965,40 +1965,40 @@ void MovGraph2::buildMovInfo1SubItems(MovInfo1 *movinfo, Common::Array<MovGraphL movinfo->itemsCount = movinfo->items.size(); } -MessageQueue *MovGraph2::buildMovInfo1MessageQueue(MovInfo1 *movInfo) { - debugC(4, kDebugPathfinding, "MovGraph2::buildMovInfo1MessageQueue(...)"); +MessageQueue *MctlGraph::makeWholeQueue(MctlMQ *mctlMQ) { + debugC(4, kDebugPathfinding, "MctlGraph::makeWholeQueue(...)"); - MovInfo1 movinfo(movInfo); + MctlMQ movinfo(mctlMQ); - int curX = movInfo->pt1.x; - int curY = movInfo->pt1.y; - int curDistance = movInfo->distance1; + int curX = mctlMQ->pt1.x; + int curY = mctlMQ->pt1.y; + int curDistance = mctlMQ->distance1; MessageQueue *mq = new MessageQueue(g_fp->_globalMessageQueueList->compact()); - for (int i = 0; i < movInfo->itemsCount - 1; i++) { - if (movInfo->items[i + 1]->subIndex != 10) { + for (int i = 0; i < mctlMQ->itemsCount - 1; i++) { + if (mctlMQ->items[i + 1]->subIndex != 10) { MG2I *mg2i; - if (i >= movInfo->itemsCount - 2 || movInfo->items[i + 2]->subIndex != 10) { + if (i >= mctlMQ->itemsCount - 2 || mctlMQ->items[i + 2]->subIndex != 10) { movinfo.flags = 0; - mg2i = &_items2[movInfo->index]->_subItems[movInfo->items[i]->subIndex]._turnS[movInfo->items[i + 1]->subIndex]; + mg2i = &_items2[mctlMQ->index]->_subItems[mctlMQ->items[i]->subIndex]._turnS[mctlMQ->items[i + 1]->subIndex]; } else { movinfo.flags = 2; - mg2i = &_items2[movInfo->index]->_subItems[movInfo->items[i]->subIndex]._turn[movInfo->items[i + 1]->subIndex]; + mg2i = &_items2[mctlMQ->index]->_subItems[mctlMQ->items[i]->subIndex]._turn[mctlMQ->items[i + 1]->subIndex]; } - if (i < movInfo->itemsCount - 2 - || (movInfo->items[i]->x == movInfo->items[i + 1]->x - && movInfo->items[i]->y == movInfo->items[i + 1]->y) - || movInfo->items[i]->x == -1 - || movInfo->items[i]->y == -1 - || movInfo->items[i + 1]->x == -1 - || movInfo->items[i + 1]->y == -1) { + if (i < mctlMQ->itemsCount - 2 + || (mctlMQ->items[i]->x == mctlMQ->items[i + 1]->x + && mctlMQ->items[i]->y == mctlMQ->items[i + 1]->y) + || mctlMQ->items[i]->x == -1 + || mctlMQ->items[i]->y == -1 + || mctlMQ->items[i + 1]->x == -1 + || mctlMQ->items[i + 1]->y == -1) { - ExCommand *ex = new ExCommand(_items2[movInfo->index]->_objectId, 1, mg2i->_movementId, 0, 0, 0, 1, 0, 0, 0); + ExCommand *ex = new ExCommand(_items2[mctlMQ->index]->_objectId, 1, mg2i->_movementId, 0, 0, 0, 1, 0, 0, 0); ex->_excFlags |= 2; - ex->_keyCode = _items2[movInfo->index]->_obj->_okeyCode; + ex->_keyCode = _items2[mctlMQ->index]->_obj->_okeyCode; ex->_field_24 = 1; ex->_field_14 = -1; mq->addExCommandToEnd(ex); @@ -2006,60 +2006,49 @@ MessageQueue *MovGraph2::buildMovInfo1MessageQueue(MovInfo1 *movInfo) { curX += mg2i->_mx; curY += mg2i->_my; } else { - MGMInfo mgminfo; + MakeQueueStruct mkQueue; - memset(&mgminfo, 0, sizeof(mgminfo)); + memset(&mkQueue, 0, sizeof(mkQueue)); - mgminfo.ani = _items2[movInfo->index]->_obj; - mgminfo.staticsId2 = mg2i->_mov->_staticsObj2->_staticsId; - mgminfo.x1 = movInfo->items[i + 1]->x; - mgminfo.y1 = movInfo->items[i + 1]->y; - mgminfo.field_1C = movInfo->items[i + 1]->distance; - mgminfo.staticsId1 = mg2i->_mov->_staticsObj1->_staticsId; + mkQueue.ani = _items2[mctlMQ->index]->_obj; + mkQueue.staticsId2 = mg2i->_mov->_staticsObj2->_staticsId; + mkQueue.x1 = mctlMQ->items[i + 1]->x; + mkQueue.y1 = mctlMQ->items[i + 1]->y; + mkQueue.field_1C = mctlMQ->items[i + 1]->distance; + mkQueue.staticsId1 = mg2i->_mov->_staticsObj1->_staticsId; - mgminfo.x2 = movInfo->items[i]->x; - mgminfo.y2 = movInfo->items[i]->y; - mgminfo.field_10 = 1; - mgminfo.flags = 0x7f; - mgminfo.movementId = mg2i->_movementId; + mkQueue.x2 = mctlMQ->items[i]->x; + mkQueue.y2 = mctlMQ->items[i]->y; + mkQueue.field_10 = 1; + mkQueue.flags = 0x7f; + mkQueue.movementId = mg2i->_movementId; - MessageQueue *mq2 = _mgm.genMovement(&mgminfo); - mq->transferExCommands(mq2); + MessageQueue *mq2 = _aniHandler.makeRunQueue(&mkQueue); + mq->mergeQueue(mq2); delete mq2; - curX = movInfo->items[i + 1]->x; - curY = movInfo->items[i + 1]->y; + curX = mctlMQ->items[i + 1]->x; + curY = mctlMQ->items[i + 1]->y; } } else { - movinfo.item1Index = movInfo->items[i]->subIndex; + movinfo.item1Index = mctlMQ->items[i]->subIndex; movinfo.subIndex = movinfo.item1Index; movinfo.pt1.y = curY; movinfo.pt1.x = curX; movinfo.distance1 = curDistance; - movinfo.pt2.x = movInfo->items[i + 2]->x; - movinfo.pt2.y = movInfo->items[i + 2]->y; - movinfo.distance2 = movInfo->items[i + 2]->distance; - - if (i >= movInfo->itemsCount - 4 - || movInfo->items[i + 2]->subIndex == 10 - || movInfo->items[i + 3]->subIndex == 10 - || movInfo->items[i + 2]->subIndex == movInfo->items[i + 3]->subIndex - || movInfo->items[i + 4]->subIndex != 10) { - if (i >= movInfo->itemsCount - 3 - || movInfo->items[i + 2]->subIndex == 10 - || movInfo->items[i + 3]->subIndex == 10 - || movInfo->items[i + 2]->subIndex == movInfo->items[i + 3]->subIndex) { - movinfo.flags &= 3; - } else { - MG2I *m = &_items2[movInfo->index]->_subItems[movInfo->items[i + 2]->subIndex]._turnS[movInfo->items[i + 3]->subIndex]; - movinfo.pt2.x -= m->_mx; - movinfo.pt2.y -= m->_my; - movinfo.flags &= 3; - } - } else { - MG2I *m = &_items2[movInfo->index]->_subItems[movInfo->items[i + 2]->subIndex]._turn[movInfo->items[i + 3]->subIndex]; + movinfo.pt2.x = mctlMQ->items[i + 2]->x; + movinfo.pt2.y = mctlMQ->items[i + 2]->y; + movinfo.distance2 = mctlMQ->items[i + 2]->distance; + + if (i < mctlMQ->itemsCount - 4 + && mctlMQ->items[i + 2]->subIndex != 10 + && mctlMQ->items[i + 3]->subIndex != 10 + && mctlMQ->items[i + 2]->subIndex != mctlMQ->items[i + 3]->subIndex + && mctlMQ->items[i + 4]->subIndex == 10) { + + MG2I *m = &_items2[mctlMQ->index]->_subItems[mctlMQ->items[i + 2]->subIndex]._turn[mctlMQ->items[i + 3]->subIndex]; if (movinfo.item1Index && movinfo.item1Index != 1) { movinfo.pt2.y -= m->_my; @@ -2068,17 +2057,31 @@ MessageQueue *MovGraph2::buildMovInfo1MessageQueue(MovInfo1 *movInfo) { movinfo.pt2.x -= m->_mx; movinfo.flags = (movinfo.flags & 2) | 1; } + + } else if (i < mctlMQ->itemsCount - 3 + && mctlMQ->items[i + 2]->subIndex != 10 + && mctlMQ->items[i + 3]->subIndex != 10 + && mctlMQ->items[i + 2]->subIndex != mctlMQ->items[i + 3]->subIndex) { + + MG2I *m = &_items2[mctlMQ->index]->_subItems[mctlMQ->items[i + 2]->subIndex]._turnS[mctlMQ->items[i + 3]->subIndex]; + movinfo.pt2.x -= m->_mx; + movinfo.pt2.y -= m->_my; + movinfo.flags = (movinfo.flags & 2) | (mctlMQ->flags & 1); + + } else { + movinfo.flags = (movinfo.flags & 2) | (mctlMQ->flags & 1); } + i++; // intentional - MessageQueue *mq2 = genMovement(&movinfo); + MessageQueue *mq2 = makeLineQueue(&movinfo); if (!mq2) { delete mq; return 0; } - mq->transferExCommands(mq2); + mq->mergeQueue(mq2); delete mq2; @@ -2088,20 +2091,20 @@ MessageQueue *MovGraph2::buildMovInfo1MessageQueue(MovInfo1 *movInfo) { } } - movInfo->pt2.x = movinfo.pt2.x; - movInfo->pt2.y = movinfo.pt2.y; + mctlMQ->pt2.x = movinfo.pt2.x; + mctlMQ->pt2.y = movinfo.pt2.y; return mq; } -int MovGraph2::detachObject(StaticANIObject *obj) { - warning("STUB: MovGraph2::detachObject()"); +int MctlGraph::detachObject(StaticANIObject *obj) { + warning("STUB: MctlGraph::detachObject()"); return 0; } -void MovGraph2::detachAllObjects() { - debugC(4, kDebugPathfinding, "MovGraph2::detachAllObjects()"); +void MctlGraph::detachAllObjects() { + debugC(4, kDebugPathfinding, "MctlGraph::detachAllObjects()"); for (uint i = 0; i < _items2.size(); i++) delete _items2[i]; @@ -2109,8 +2112,8 @@ void MovGraph2::detachAllObjects() { _items2.clear(); } -MessageQueue *MovGraph2::startMove(StaticANIObject *ani, int xpos, int ypos, int fuzzyMatch, int staticsId) { - debugC(4, kDebugPathfinding, "MovGraph2::startMove(*%d, %d, %d, %d, %d)", ani->_id, xpos, ypos, fuzzyMatch, staticsId); +MessageQueue *MctlGraph::startMove(StaticANIObject *ani, int xpos, int ypos, int fuzzyMatch, int staticsId) { + debugC(4, kDebugPathfinding, "MctlGraph::startMove(*%d, %d, %d, %d, %d)", ani->_id, xpos, ypos, fuzzyMatch, staticsId); if (!ani->isIdle()) return 0; @@ -2119,7 +2122,7 @@ MessageQueue *MovGraph2::startMove(StaticANIObject *ani, int xpos, int ypos, int return 0; debugC(1, kDebugPathfinding, "WWW 3"); - MessageQueue *mq = doWalkTo(ani, xpos, ypos, fuzzyMatch, staticsId); + MessageQueue *mq = makeQueue(ani, xpos, ypos, fuzzyMatch, staticsId); if (!mq) return 0; @@ -2130,7 +2133,7 @@ MessageQueue *MovGraph2::startMove(StaticANIObject *ani, int xpos, int ypos, int ani->getPicAniInfo(&picAniInfo); ani->updateStepPos(); - MessageQueue *mq1 = doWalkTo(ani, xpos, ypos, fuzzyMatch, staticsId); + MessageQueue *mq1 = makeQueue(ani, xpos, ypos, fuzzyMatch, staticsId); ani->setPicAniInfo(&picAniInfo); @@ -2153,16 +2156,16 @@ MessageQueue *MovGraph2::startMove(StaticANIObject *ani, int xpos, int ypos, int return mq; } -MessageQueue *MovGraph2::doWalkTo(StaticANIObject *obj, int xpos, int ypos, int fuzzyMatch, int staticsId) { +MessageQueue *MctlGraph::makeQueue(StaticANIObject *obj, int xpos, int ypos, int fuzzyMatch, int staticsId) { LinkInfo linkInfoDest; LinkInfo linkInfoSource; - MovInfo1 movInfo1; + MctlMQ mctlMQ1; PicAniInfo picAniInfo; Common::Point point; - debugC(1, kDebugPathfinding, "MovGraph2::doWalkTo(%d, %d, %d, %d, %d)", obj->_id, xpos, ypos, fuzzyMatch, staticsId); + debugC(1, kDebugPathfinding, "MctlGraph::makeQueue(%d, %d, %d, %d, %d)", obj->_id, xpos, ypos, fuzzyMatch, staticsId); - int idx = getItemIndexByGameObjectId(obj->_id); + int idx = getObjIndex(obj->_id); if (idx < 0) return 0; @@ -2180,15 +2183,15 @@ MessageQueue *MovGraph2::doWalkTo(StaticANIObject *obj, int xpos, int ypos, int int idxsub; if (obj->_movement) - idxsub = getItemSubIndexByMovementId(idx, obj->_movement->_id); + idxsub = getDirByMovement(idx, obj->_movement->_id); else - idxsub = getItemSubIndexByStaticsId(idx, obj->_statics->_staticsId); + idxsub = getDirByStatics(idx, obj->_statics->_staticsId); bool subMgm = false; if (idxsub == -1) { debugC(1, kDebugPathfinding, "WWW 4"); - idxsub = getItemSubIndexByMGM(idx, obj); + idxsub = getDirByPoint(idx, obj); subMgm = true; if (idxsub == -1) @@ -2226,7 +2229,7 @@ MessageQueue *MovGraph2::doWalkTo(StaticANIObject *obj, int xpos, int ypos, int MessageQueue *mq = new MessageQueue(); if (staticsId && obj->_statics->_staticsId != staticsId) { - int idxwalk = getItemSubIndexByStaticsId(idx, staticsId); + int idxwalk = getDirByStatics(idx, staticsId); if (idxwalk == -1) { obj->setPicAniInfo(&picAniInfo); @@ -2262,13 +2265,13 @@ MessageQueue *MovGraph2::doWalkTo(StaticANIObject *obj, int xpos, int ypos, int return mq; } - linkInfoSource.node = findNode(obj->_ox, obj->_oy, 0); + linkInfoSource.node = getHitNode(obj->_ox, obj->_oy, 0); if (!linkInfoSource.node) { - linkInfoSource.link = findLink1(obj->_ox, obj->_oy, idxsub, 0); + linkInfoSource.link = getHitLink(obj->_ox, obj->_oy, idxsub, 0); if (!linkInfoSource.link) { - linkInfoSource.link = findLink2(obj->_ox, obj->_oy); + linkInfoSource.link = getNearestLink(obj->_ox, obj->_oy); if (!linkInfoSource.link) { obj->setPicAniInfo(&picAniInfo); @@ -2278,10 +2281,10 @@ MessageQueue *MovGraph2::doWalkTo(StaticANIObject *obj, int xpos, int ypos, int } } - linkInfoDest.node = findNode(xpos, ypos, fuzzyMatch); + linkInfoDest.node = getHitNode(xpos, ypos, fuzzyMatch); if (!linkInfoDest.node) { - linkInfoDest.link = findLink1(xpos, ypos, idxsub, fuzzyMatch); + linkInfoDest.link = getHitLink(xpos, ypos, idxsub, fuzzyMatch); if (!linkInfoDest.link) { obj->setPicAniInfo(&picAniInfo); @@ -2291,78 +2294,78 @@ MessageQueue *MovGraph2::doWalkTo(StaticANIObject *obj, int xpos, int ypos, int } Common::Array<MovGraphLink *> tempLinkList; - double minPath = findMinPath(&linkInfoSource, &linkInfoDest, &tempLinkList); + double minPath = iterate(&linkInfoSource, &linkInfoDest, &tempLinkList); - debugC(0, kDebugPathfinding, "MovGraph2::doWalkTo(): path: %g parts: %d", minPath, tempLinkList.size()); + debugC(0, kDebugPathfinding, "MctlGraph::makeQueue(): path: %g parts: %d", minPath, tempLinkList.size()); if (minPath < 0.0 || ((linkInfoSource.node != linkInfoDest.node || !linkInfoSource.node) && !tempLinkList.size())) return 0; - movInfo1.clear(); + mctlMQ1.clear(); - movInfo1.subIndex = idxsub; - movInfo1.pt1.x = obj->_ox; - movInfo1.pt1.y = obj->_oy; + mctlMQ1.subIndex = idxsub; + mctlMQ1.pt1.x = obj->_ox; + mctlMQ1.pt1.y = obj->_oy; int dx1 = obj->_ox; int dy1 = obj->_oy; int dx2, dy2; if (linkInfoSource.node) - movInfo1.distance1 = linkInfoSource.node->_z; + mctlMQ1.distance1 = linkInfoSource.node->_z; else - movInfo1.distance1 = linkInfoSource.link->_graphSrc->_z; + mctlMQ1.distance1 = linkInfoSource.link->_graphSrc->_z; if (linkInfoDest.node) { dx2 = linkInfoDest.node->_x; dy2 = linkInfoDest.node->_y; - movInfo1.pt2.x = linkInfoDest.node->_x; - movInfo1.pt2.y = linkInfoDest.node->_y; + mctlMQ1.pt2.x = linkInfoDest.node->_x; + mctlMQ1.pt2.y = linkInfoDest.node->_y; - movInfo1.distance2 = linkInfoDest.node->_z; + mctlMQ1.distance2 = linkInfoDest.node->_z; } else { - movInfo1.pt2.x = xpos; - movInfo1.pt2.y = ypos; + mctlMQ1.pt2.x = xpos; + mctlMQ1.pt2.y = ypos; MovGraphNode *nod = linkInfoDest.link->_graphSrc; double dst1 = sqrt((double)((ypos - nod->_y) * (ypos - nod->_y) + (xpos - nod->_x) * (xpos - nod->_x))); int dst = linkInfoDest.link->_graphDst->_z - nod->_z; - movInfo1.distance2 = (int)(nod->_z + (dst1 * (double)dst / linkInfoDest.link->_length)); + mctlMQ1.distance2 = (int)(nod->_z + (dst1 * (double)dst / linkInfoDest.link->_length)); - putToLink(&movInfo1.pt2, linkInfoDest.link, 1); + putToLink(&mctlMQ1.pt2, linkInfoDest.link, 1); - dx1 = movInfo1.pt1.x; - dy1 = movInfo1.pt1.y; - dx2 = movInfo1.pt2.x; - dy2 = movInfo1.pt2.y; + dx1 = mctlMQ1.pt1.x; + dy1 = mctlMQ1.pt1.y; + dx2 = mctlMQ1.pt2.x; + dy2 = mctlMQ1.pt2.y; } if (staticsId) { - movInfo1.item1Index = getItemSubIndexByStaticsId(idx, staticsId); + mctlMQ1.item1Index = getDirByStatics(idx, staticsId); } else if (tempLinkList.size() <= 1) { if (tempLinkList.size() == 1) - movInfo1.item1Index = getShortSide(tempLinkList[0], dx2 - dx1, dy2 - dy1); + mctlMQ1.item1Index = getDirBySize(tempLinkList[0], dx2 - dx1, dy2 - dy1); else - movInfo1.item1Index = getShortSide(0, dx2 - dx1, dy2 - dy1); + mctlMQ1.item1Index = getDirBySize(0, dx2 - dx1, dy2 - dy1); } else { - movInfo1.item1Index = findLink(&tempLinkList, tempLinkList.size() - 1, 0, 0); + mctlMQ1.item1Index = getLinkDir(&tempLinkList, tempLinkList.size() - 1, 0, 0); } - movInfo1.flags = fuzzyMatch != 0; + mctlMQ1.flags = fuzzyMatch != 0; if (_items2[idx]->_subItems[idxsub]._staticsId1 != obj->_statics->_staticsId) - movInfo1.flags |= 2; + mctlMQ1.flags |= 2; - buildMovInfo1SubItems(&movInfo1, &tempLinkList, &linkInfoSource, &linkInfoDest); + generateList(&mctlMQ1, &tempLinkList, &linkInfoSource, &linkInfoDest); - MessageQueue *mq = buildMovInfo1MessageQueue(&movInfo1); + MessageQueue *mq = makeWholeQueue(&mctlMQ1); - linkInfoDest.node = findNode(movInfo1.pt2.x, movInfo1.pt2.y, fuzzyMatch); + linkInfoDest.node = getHitNode(mctlMQ1.pt2.x, mctlMQ1.pt2.y, fuzzyMatch); if (!linkInfoDest.node) - linkInfoDest.link = findLink1(movInfo1.pt2.x, movInfo1.pt2.y, movInfo1.item1Index, fuzzyMatch); + linkInfoDest.link = getHitLink(mctlMQ1.pt2.x, mctlMQ1.pt2.y, mctlMQ1.item1Index, fuzzyMatch); if (fuzzyMatch || linkInfoDest.link || linkInfoDest.node) { if (mq && mq->getCount() > 0 && picAniInfo.movementId) { @@ -2397,13 +2400,13 @@ MessageQueue *MovGraph2::doWalkTo(StaticANIObject *obj, int xpos, int ypos, int return mq; } -MovGraphNode *MovGraph2::findNode(int x, int y, int fuzzyMatch) { +MovGraphNode *MctlGraph::getHitNode(int x, int y, int strictMatch) { for (ObList::iterator i = _nodes.begin(); i != _nodes.end(); ++i) { assert(((CObject *)*i)->_objtype == kObjTypeMovGraphNode); MovGraphNode *node = (MovGraphNode *)*i; - if (fuzzyMatch) { + if (!strictMatch) { if (abs(node->_x - x) < 15 && abs(node->_y - y) < 15) return node; } else { @@ -2415,7 +2418,7 @@ MovGraphNode *MovGraph2::findNode(int x, int y, int fuzzyMatch) { return 0; } -int MovGraph2::getShortSide(MovGraphLink *lnk, int x, int y) { +int MctlGraph::getDirBySize(MovGraphLink *lnk, int x, int y) { bool cond; if (lnk) @@ -2429,8 +2432,8 @@ int MovGraph2::getShortSide(MovGraphLink *lnk, int x, int y) { return ((y > 0) + 2); } -int MovGraph2::findLink(Common::Array<MovGraphLink *> *linkList, int idx, Common::Rect *rect, Common::Point *point) { - debugC(4, kDebugPathfinding, "MovGraph2::findLink(...)"); +int MctlGraph::getLinkDir(Common::Array<MovGraphLink *> *linkList, int idx, Common::Rect *rect, Common::Point *point) { + debugC(4, kDebugPathfinding, "MctlGraph::getLinkDir(...)"); MovGraphNode *node1 = (*linkList)[idx]->_graphSrc; MovGraphNode *node2 = (*linkList)[idx]->_graphDst; @@ -2473,13 +2476,13 @@ int MovGraph2::findLink(Common::Array<MovGraphLink *> *linkList, int idx, Common } if (abs(node3->_x - node2->_x) <= abs(node3->_y - node2->_y)) - return (node3->_y < node2->_x) + 2; + return (node3->_y < node2->_y) + 2; else return node3->_x >= node2->_x; } -MessageQueue *MovGraph2::genMovement(MovInfo1 *info) { - debugC(4, kDebugPathfinding, "MovGraph2::genMovement(...)"); +MessageQueue *MctlGraph::makeLineQueue(MctlMQ *info) { + debugC(4, kDebugPathfinding, "MctlGraph::makeLineQueue(...)"); int mx1 = 0; int my1 = 0; @@ -2504,7 +2507,7 @@ MessageQueue *MovGraph2::genMovement(MovInfo1 *info) { int a2 = 0; int mgmLen; - _mgm.calcLength(&point, _items2[info->index]->_subItems[info->subIndex]._walk[1]._mov, x, y, &mgmLen, &a2, info->flags & 1); + _aniHandler.getNumCycles(&point, _items2[info->index]->_subItems[info->subIndex]._walk[1]._mov, x, y, &mgmLen, &a2, info->flags & 1); int x1 = point.x; int y1 = point.y; @@ -2619,7 +2622,7 @@ MessageQueue *MovGraph2::genMovement(MovInfo1 *info) { ex->_excFlags |= 2; mq->addExCommandToEnd(ex); - ex = _mgm.buildExCommand2( + ex = _aniHandler.createCommand( _items2[info->index]->_subItems[info->subIndex]._walk[0]._mov, _items2[info->index]->_objectId, x1, @@ -2641,7 +2644,7 @@ MessageQueue *MovGraph2::genMovement(MovInfo1 *info) { else par = -1; - ex = _mgm.buildExCommand2( + ex = _aniHandler.createCommand( _items2[info->index]->_subItems[info->subIndex]._walk[1]._mov, _items2[info->index]->_objectId, x1, @@ -2655,7 +2658,7 @@ MessageQueue *MovGraph2::genMovement(MovInfo1 *info) { } if (!(info->flags & 4)) { - ex = _mgm.buildExCommand2( + ex = _aniHandler.createCommand( _items2[info->index]->_subItems[info->subIndex]._walk[2]._mov, _items2[info->index]->_objectId, x1, @@ -2681,8 +2684,8 @@ MessageQueue *MovGraph2::genMovement(MovInfo1 *info) { return mq; } -MovGraphLink *MovGraph2::findLink1(int x, int y, int idx, int fuzzyMatch) { - debugC(4, kDebugPathfinding, "MovGraph2::findLink1(...)"); +MovGraphLink *MctlGraph::getHitLink(int x, int y, int idx, int fuzzyMatch) { + debugC(4, kDebugPathfinding, "MctlGraph::getHitLink(...)"); Common::Point point; MovGraphLink *res = 0; @@ -2717,8 +2720,8 @@ MovGraphLink *MovGraph2::findLink1(int x, int y, int idx, int fuzzyMatch) { return res; } -MovGraphLink *MovGraph2::findLink2(int x, int y) { - debugC(4, kDebugPathfinding, "MovGraph2::findLink2(...)"); +MovGraphLink *MctlGraph::getNearestLink(int x, int y) { + debugC(4, kDebugPathfinding, "MctlGraph::getNearestLink(...)"); double mindist = 1.0e20; MovGraphLink *res = 0; @@ -2761,8 +2764,8 @@ MovGraphLink *MovGraph2::findLink2(int x, int y) { return 0; } -double MovGraph2::findMinPath(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, Common::Array<MovGraphLink *> *listObj) { - debugC(4, kDebugPathfinding, "MovGraph2::findMinPath(...)"); +double MctlGraph::iterate(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, Common::Array<MovGraphLink *> *listObj) { + debugC(4, kDebugPathfinding, "MctlGraph::iterate(...)"); LinkInfo linkInfoWorkSource; @@ -2781,7 +2784,7 @@ double MovGraph2::findMinPath(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, lnk->_flags |= 0x80000000; - double newDistance = findMinPath(&linkInfoWorkSource, linkInfoDest, &tmpList); + double newDistance = iterate(&linkInfoWorkSource, linkInfoDest, &tmpList); if (newDistance >= 0.0 && (minDistance < 0.0 || newDistance + lnk->_length < minDistance)) { listObj->clear(); @@ -2799,7 +2802,7 @@ double MovGraph2::findMinPath(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, Common::Array<MovGraphLink *> tmpList; - double newDistance = findMinPath(&linkInfoWorkSource, linkInfoDest, &tmpList); + double newDistance = iterate(&linkInfoWorkSource, linkInfoDest, &tmpList); if (newDistance >= 0.0) { listObj->clear(); @@ -2815,9 +2818,11 @@ double MovGraph2::findMinPath(LinkInfo *linkInfoSource, LinkInfo *linkInfoDest, tmpList.clear(); - newDistance = findMinPath(&linkInfoWorkSource, linkInfoDest, &tmpList); + newDistance = iterate(&linkInfoWorkSource, linkInfoDest, &tmpList); if (newDistance >= 0 && (minDistance < 0.0 || newDistance < minDistance)) { + listObj->clear(); + listObj->push_back(linkInfoSource->link); listObj->push_back(tmpList); @@ -2905,7 +2910,7 @@ void MovGraphLink::recalcLength() { double dy = _graphDst->_y - _graphSrc->_y; _length = sqrt(dy * dy + dx * dx); - _angle = atan2(dx, dy); + _angle = atan2(dy, dx); } } @@ -2913,9 +2918,9 @@ bool MovGraphNode::load(MfcArchive &file) { debugC(5, kDebugLoading, "MovGraphNode::load()"); _field_14 = file.readUint32LE(); - _x = file.readUint32LE(); - _y = file.readUint32LE(); - _z = file.readUint32LE(); + _x = file.readSint32LE(); + _y = file.readSint32LE(); + _z = file.readSint32LE(); return true; } @@ -2932,12 +2937,12 @@ ReactParallel::ReactParallel() { bool ReactParallel::load(MfcArchive &file) { debugC(5, kDebugLoading, "ReactParallel::load()"); - _x1 = file.readUint32LE(); - _y1 = file.readUint32LE(); - _x2 = file.readUint32LE(); - _y2 = file.readUint32LE(); - _dx = file.readUint32LE(); - _dy = file.readUint32LE(); + _x1 = file.readSint32LE(); + _y1 = file.readSint32LE(); + _x2 = file.readSint32LE(); + _y2 = file.readSint32LE(); + _dx = file.readSint32LE(); + _dy = file.readSint32LE(); createRegion(); @@ -2950,7 +2955,7 @@ void ReactParallel::createRegion() { for (int i = 0; i < 4; i++) _points[i] = new Common::Point; - double at = atan2((double)(_x1 - _x2), (double)(_y1 - _y2)) + 1.570796; // pi/2 + double at = atan2((double)(_y1 - _y2), (double)(_x1 - _x2)) + 1.570796; // pi/2 double sn = sin(at); double cs = cos(at); @@ -2990,8 +2995,8 @@ ReactPolygonal::~ReactPolygonal() { bool ReactPolygonal::load(MfcArchive &file) { debugC(5, kDebugLoading, "ReactPolygonal::load()"); - _centerX = file.readUint32LE(); - _centerY = file.readUint32LE(); + _centerX = file.readSint32LE(); + _centerY = file.readSint32LE(); _pointCount = file.readUint32LE(); if (_pointCount > 0) { |