From dc8a9487ecc956ea483f97fffebfe6d362fc0cc8 Mon Sep 17 00:00:00 2001 From: Matthew Duggan Date: Fri, 7 May 2021 12:41:51 +0900 Subject: [PATCH] ULTIMA8: Return area search items in same order as original For most situations this should make no difference, but Crusader: No Remorse has some behavior where it relies on the items being returned in x/y scan order, not y/x. Particularly, in Mission 2 there is a camera which searches for an event trigger with qlo == 5. There are 2 triggers on the map with that qlo, but the code previously returned them in the wrong order so the correct event would not be triggered and the game could not be continued. This may have previously caused other subtle bugs too. --- engines/ultima/ultima8/world/current_map.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/engines/ultima/ultima8/world/current_map.cpp b/engines/ultima/ultima8/world/current_map.cpp index 696690053b8..20bcc75a6f7 100644 --- a/engines/ultima/ultima8/world/current_map.cpp +++ b/engines/ultima/ultima8/world/current_map.cpp @@ -572,8 +572,8 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript, int maxy = ((y + range) / _mapChunkSize) + 1; clipMapChunks(minx, maxx, miny, maxy); - for (int cx = minx; cx <= maxx; cx++) { - for (int cy = miny; cy <= maxy; cy++) { + for (int cy = miny; cy <= maxy; cy++) { + for (int cx = minx; cx <= maxx; cx++) { item_list::const_iterator iter; for (iter = _items[cx][cy].begin(); iter != _items[cx][cy].end(); ++iter) { @@ -598,7 +598,7 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript, // check item against loopscript if (item->checkLoopScript(loopscript, scriptsize)) { assert(itemlist->getElementSize() == 2); - uint16 objid = item->getObjId(); + const uint16 objid = item->getObjId(); uint8 buf[2]; buf[0] = static_cast(objid); buf[1] = static_cast(objid >> 8); @@ -641,8 +641,8 @@ void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript, int maxy = ((origin[1]) / _mapChunkSize) + 1; clipMapChunks(minx, maxx, miny, maxy); - for (int cx = minx; cx <= maxx; cx++) { - for (int cy = miny; cy <= maxy; cy++) { + for (int cy = miny; cy <= maxy; cy++) { + for (int cx = minx; cx <= maxx; cx++) { item_list::const_iterator iter; for (iter = _items[cx][cy].begin(); iter != _items[cx][cy].end(); ++iter) {