diff options
Diffstat (limited to 'engines/fullpipe/mgm.cpp')
-rw-r--r-- | engines/fullpipe/mgm.cpp | 132 |
1 files changed, 88 insertions, 44 deletions
diff --git a/engines/fullpipe/mgm.cpp b/engines/fullpipe/mgm.cpp index 1c8ca2a7b1..c9eeebb224 100644 --- a/engines/fullpipe/mgm.cpp +++ b/engines/fullpipe/mgm.cpp @@ -34,6 +34,8 @@ void MGM::clear() { } MessageQueue *MGM::genMQ(StaticANIObject *ani, int staticsIndex, int staticsId, int *resStatId, Common::Point **pointArr) { + debugC(4, kDebugPathfinding, "MGM::genMQ(*%d, %d, %d, res, point)", ani->_id, staticsIndex, staticsId); + int idx = getItemIndexById(ani->_id); if (idx == -1) @@ -130,6 +132,8 @@ MGMSubItem::MGMSubItem() { } void MGM::addItem(int objId) { + debugC(4, kDebugPathfinding, "MGM::addItem(%d)", objId); + if (getItemIndexById(objId) == -1) { MGMItem *item = new MGMItem(); @@ -145,6 +149,8 @@ void MGM::rebuildTables(int objId) { if (idx == -1) return; + debugC(3, kDebugPathfinding, "MGM::rebuildTables. (1) movements1 sz: %d movements2 sz: %d", _items[idx]->movements1.size(), _items[idx]->movements2.size()); + _items[idx]->subItems.clear(); _items[idx]->statics.clear(); _items[idx]->movements1.clear(); @@ -155,14 +161,20 @@ void MGM::rebuildTables(int objId) { if (!obj) return; + debugC(1, kDebugPathfinding, "WWW rebuild. idx: %d, size: %d", idx, obj->_staticsList.size() * obj->_staticsList.size()); for (uint i = 0; i < obj->_staticsList.size(); i++) { _items[idx]->statics.push_back((Statics *)obj->_staticsList[i]); - _items[idx]->subItems.push_back(new MGMSubItem); + for (uint j = 0; j < obj->_staticsList.size(); j++) // Yes, square + _items[idx]->subItems.push_back(new MGMSubItem); } - for (uint i = 0; i < obj->_movements.size(); i++) + for (uint i = 0; i < obj->_movements.size(); i++) { _items[idx]->movements1.push_back((Movement *)obj->_movements[i]); + _items[idx]->movements2.push_back(0); + } + + debugC(3, kDebugPathfinding, "MGM::rebuildTables. (2) movements1 sz: %d movements2 sz: %d", _items[idx]->movements1.size(), _items[idx]->movements2.size()); } int MGM::getItemIndexById(int objId) { @@ -174,6 +186,8 @@ int MGM::getItemIndexById(int objId) { } MessageQueue *MGM::genMovement(MGMInfo *mgminfo) { + debugC(4, kDebugPathfinding, "MGM::genMovement(*%d)", mgminfo->ani ? mgminfo->ani->_id : -1); + if (!mgminfo->ani) return 0; @@ -214,12 +228,15 @@ MessageQueue *MGM::genMovement(MGMInfo *mgminfo) { if (!mov) return 0; + int itemIdx = getItemIndexById(mgminfo->ani->_id); int subIdx = getStaticsIndexById(itemIdx, mgminfo->staticsId1); int st2idx = getStaticsIndexById(itemIdx, mov->_staticsObj1->_staticsId); int st1idx = getStaticsIndexById(itemIdx, mov->_staticsObj2->_staticsId); int subOffset = getStaticsIndexById(itemIdx, mgminfo->staticsId2); + debugC(3, kDebugPathfinding, "MGM::genMovement. (1) movements1 sz: %d movements2 sz: %d", _items[itemIdx]->movements1.size(), _items[itemIdx]->movements2.size()); + clearMovements2(itemIdx); recalcOffsets(itemIdx, subIdx, st2idx, 0, 1); clearMovements2(itemIdx); @@ -376,6 +393,8 @@ MessageQueue *MGM::genMovement(MGMInfo *mgminfo) { mq->addExCommandToEnd(ex); + debugC(3, kDebugPathfinding, "MGM::genMovement. (2) movements1 sz: %d movements2 sz: %d", _items[itemIdx]->movements1.size(), _items[itemIdx]->movements2.size()); + return mq; } @@ -389,14 +408,16 @@ int MGM::countPhases(int idx, int subIdx, int endIdx, int flag) { if (subIdx < 0) break; - res += _items[idx]->subItems[subIdx + endIdx * _items[idx]->statics.size()]->movement->countPhasesWithFlag(-1, flag); + res += _items[idx]->subItems[subIdx + endIdx * _items[idx]->statics.size()]->movement->countPhasesWithFlag(0xffffffff, flag); - subIdx = _items[idx]->subItems[subIdx + 6 * endIdx * _items[idx]->statics.size()]->staticsIndex; + subIdx = _items[idx]->subItems[subIdx + endIdx * _items[idx]->statics.size()]->staticsIndex; } return res; } void MGM::updateAnimStatics(StaticANIObject *ani, int staticsId) { + debugC(4, kDebugPathfinding, "MGM::updateAnimStatics(*%d, %d)", ani->_id, staticsId); + if (getItemIndexById(ani->_id) == -1) return; @@ -425,6 +446,8 @@ void MGM::updateAnimStatics(StaticANIObject *ani, int staticsId) { } Common::Point *MGM::getPoint(Common::Point *point, int objectId, int staticsId1, int staticsId2) { + debugC(4, kDebugPathfinding, "MGM::getPoint([%d, %d], %d, %d, %d)", point->x, point->y, objectId, staticsId1, staticsId2); + int idx = getItemIndexById(objectId); if (idx == -1) { @@ -474,7 +497,7 @@ int MGM::getStaticsIndexById(int idx, int16 id) { return i; } - return 0; + return -1; } int MGM::getStaticsIndex(int idx, Statics *st) { @@ -486,79 +509,95 @@ int MGM::getStaticsIndex(int idx, Statics *st) { return i; } - return 0; + return -1; } void MGM::clearMovements2(int idx) { - _items[idx]->movements2.clear(); + debugC(2, kDebugPathfinding, "MGM::clearMovements2(%d)", idx); + + for (uint i = 0; i < _items[idx]->movements2.size(); i++) + _items[idx]->movements2[i] = 0; + + debugC(3, kDebugPathfinding, "MGM::clearMovements2. movements1 sz: %d movements2 sz: %d", _items[idx]->movements1.size(), _items[idx]->movements2.size()); } int MGM::recalcOffsets(int idx, int st1idx, int st2idx, bool flip, bool flop) { MGMItem *item = _items[idx]; int subIdx = st1idx + st2idx * item->statics.size(); + debugC(2, kDebugPathfinding, "MGM::recalcOffsets(%d, %d, %d, %d, %d)", idx, st1idx, st2idx, flip, flop); + if (st1idx == st2idx) { memset(&item->subItems[subIdx], 0, sizeof(item->subItems[subIdx])); return 0; } - if (item->subItems[subIdx]) + if (item->subItems[subIdx]->movement) return item->subItems[subIdx]->field_8; Common::Point point; + debugC(3, kDebugPathfinding, "MGM::recalcOffsets. movements1 sz: %d movements2 sz: %d", item->movements1.size(), item->movements2.size()); + for (uint i = 0; i < item->movements1.size(); i++) { Movement *mov = item->movements1[i]; if (mov->_staticsObj1 == item->statics[st1idx]) { - if (!item->movements2[i] && (!flop || mov->_field_50)) { - item->movements2[i] = 1; + if (item->movements2[i] || (flop && !mov->_field_50)) + continue; - int stidx = getStaticsIndex(idx, item->movements1[i]->_staticsObj2); - int recalc = recalcOffsets(idx, stidx, st2idx, flip, flop); - int sz = mov->_currMovement ? mov->_currMovement->_dynamicPhases.size() : mov->_dynamicPhases.size(); - int newsz = sz + item->subItems[stidx + 6 * st2idx * _items[idx]->statics.size()]->field_C; + item->movements2[i] = 1; - if (recalc >= 0) { - if (!item->subItems[subIdx]->movement || item->subItems[subIdx]->field_8 > recalc + 1 || - (item->subItems[subIdx]->field_8 == recalc + 1 && item->subItems[subIdx]->field_C > newsz)) { - item->subItems[subIdx]->movement = mov; - item->subItems[subIdx]->staticsIndex = stidx; - item->subItems[subIdx]->field_8 = recalc + 1; - item->subItems[subIdx]->field_C = newsz; + int stidx = getStaticsIndex(idx, mov->_staticsObj2); + int recalc = recalcOffsets(idx, stidx, st2idx, flip, flop); + int sz = mov->_currMovement ? mov->_currMovement->_dynamicPhases.size() : mov->_dynamicPhases.size(); + debugC(1, kDebugPathfinding, "MGM::recalcOffsets, want idx: %d, off: %d (%d + %d), sz: %d", idx, stidx + st2idx * _items[idx]->statics.size(), stidx, st2idx, item->subItems.size()); - mov->calcSomeXY(point, 0, -1); + int newsz = sz + item->subItems[stidx + st2idx * _items[idx]->statics.size()]->field_C; - item->subItems[subIdx]->x = item->subItems[stidx + 6 * st2idx * _items[idx]->statics.size()]->x + point.x; - item->subItems[subIdx]->y = item->subItems[stidx + 6 * st2idx * _items[idx]->statics.size()]->y + point.y; - } - } + if (recalc < 0) + continue; + + if (!item->subItems[subIdx]->movement || item->subItems[subIdx]->field_8 > recalc + 1 || + (item->subItems[subIdx]->field_8 == recalc + 1 && item->subItems[subIdx]->field_C > newsz)) { + item->subItems[subIdx]->movement = mov; + item->subItems[subIdx]->staticsIndex = stidx; + item->subItems[subIdx]->field_8 = recalc + 1; + item->subItems[subIdx]->field_C = newsz; + + mov->calcSomeXY(point, 0, -1); + + item->subItems[subIdx]->x = item->subItems[stidx + st2idx * _items[idx]->statics.size()]->x + point.x; + item->subItems[subIdx]->y = item->subItems[stidx + st2idx * _items[idx]->statics.size()]->y + point.y; } } else if (flip) { - if (mov->_staticsObj2 == item->statics[st1idx]) { - if (!item->movements2[i] && (!flop || mov->_field_50)) { - item->movements2[i] = 1; + if (mov->_staticsObj2 != item->statics[st1idx]) + continue; - int stidx = getStaticsIndex(idx, mov->_staticsObj1); - int recalc = recalcOffsets(idx, stidx, st2idx, flip, flop); + if (item->movements2[i] || (flop && !mov->_field_50)) + continue; - if (recalc >= 0) { - if (!item->subItems[subIdx]->movement || item->subItems[subIdx]->field_8 > recalc + 1) { - item->subItems[subIdx]->movement = mov; - item->subItems[subIdx]->staticsIndex = stidx; - item->subItems[subIdx]->field_8 = recalc + 1; + item->movements2[i] = 1; - int sz = mov->_currMovement ? mov->_currMovement->_dynamicPhases.size() : mov->_dynamicPhases.size(); + int stidx = getStaticsIndex(idx, mov->_staticsObj1); + int recalc = recalcOffsets(idx, stidx, st2idx, flip, flop); - item->subItems[subIdx]->field_C = sz + item->subItems[stidx + 6 * st2idx * _items[idx]->statics.size()]->field_C; + if (recalc < 0) + continue; - mov->calcSomeXY(point, 0, -1); + if (!item->subItems[subIdx]->movement || item->subItems[subIdx]->field_8 > recalc + 1) { + item->subItems[subIdx]->movement = mov; + item->subItems[subIdx]->staticsIndex = stidx; + item->subItems[subIdx]->field_8 = recalc + 1; - item->subItems[subIdx]->x = item->subItems[stidx + 6 * st2idx * _items[idx]->statics.size()]->x - point.x; - item->subItems[subIdx]->y = item->subItems[stidx + 6 * st2idx * _items[idx]->statics.size()]->y - point.y; - } - } - } + int sz = mov->_currMovement ? mov->_currMovement->_dynamicPhases.size() : mov->_dynamicPhases.size(); + + item->subItems[subIdx]->field_C = sz + item->subItems[stidx + st2idx * _items[idx]->statics.size()]->field_C; + + mov->calcSomeXY(point, 0, -1); + + item->subItems[subIdx]->x = item->subItems[stidx + st2idx * _items[idx]->statics.size()]->x - point.x; + item->subItems[subIdx]->y = item->subItems[stidx + st2idx * _items[idx]->statics.size()]->y - point.y; } } } @@ -570,12 +609,15 @@ int MGM::recalcOffsets(int idx, int st1idx, int st2idx, bool flip, bool flop) { } int MGM::refreshOffsets(int objectId, int idx1, int idx2) { + debugC(4, kDebugPathfinding, "MGM::refreshOffsets(%d, %d, %d)", objectId, idx1, idx2); + int idx = getItemIndexById(objectId); if (idx != -1) { int from = getStaticsIndexById(idx, idx1); int to = getStaticsIndexById(idx, idx2); + debugC(1, kDebugPathfinding, "WWW 6, want idx: %d, off: %d", idx, from + to * _items[idx]->statics.size()); MGMSubItem *sub = _items[idx]->subItems[from + to * _items[idx]->statics.size()]; if (sub->movement) { @@ -666,6 +708,8 @@ Common::Point *MGM::calcLength(Common::Point *pRes, Movement *mov, int x, int y, } ExCommand2 *MGM::buildExCommand2(Movement *mov, int objId, int x1, int y1, Common::Point *x2, Common::Point *y2, int len) { + debugC(2, kDebugPathfinding, "MGM::buildExCommand2(mov, %d, %d, %d, [%d, %d], [%d, %d], %d)", objId, x1, y1, x2->x, x2->y, y2->x, y2->y, len); + uint cnt; if (mov->_currMovement) |