diff --git a/engines/ultima/ultima8/usecode/uc_list.h b/engines/ultima/ultima8/usecode/uc_list.h index fbba166f89c..c3231925362 100644 --- a/engines/ultima/ultima8/usecode/uc_list.h +++ b/engines/ultima/ultima8/usecode/uc_list.h @@ -77,6 +77,14 @@ public: _size++; } + void appenduint16(uint16 val) { + assert(_elementSize == 2); + uint8 buf[2]; + buf[0] = static_cast(val); + buf[1] = static_cast(val >> 8); + append(buf); + } + void remove(const uint8 *e) { // do we need to erase all occurences of e or just the first one? // (deleting all, currently) @@ -105,20 +113,23 @@ public: } void appendList(const UCList &l) { - // need to check if elementsizes match... + // elementsizes should match... + assert(_elementSize == l.getElementSize()); _elements.reserve(_elementSize * (_size + l._size)); - unsigned int lsize = l._size; - for (unsigned int i = 0; i < lsize; i++) + for (unsigned int i = 0; i < l._size; i++) append(l[i]); } void unionList(const UCList &l) { // like append, but remove duplicates - // need to check if elementsizes match... + // elementsizes should match... + assert(_elementSize == l.getElementSize()); _elements.reserve(_elementSize * (_size + l._size)); for (unsigned int i = 0; i < l._size; i++) if (!inList(l[i])) append(l[i]); } void subtractList(const UCList &l) { + // elementsizes should match... + assert(_elementSize == l.getElementSize()); for (unsigned int i = 0; i < l._size; i++) remove(l[i]); } diff --git a/engines/ultima/ultima8/world/container.cpp b/engines/ultima/ultima8/world/container.cpp index 7a65f93b356..49c46100b76 100644 --- a/engines/ultima/ultima8/world/container.cpp +++ b/engines/ultima/ultima8/world/container.cpp @@ -275,10 +275,7 @@ void Container::containerSearch(UCList *itemlist, const uint8 *loopscript, if ((*iter)->checkLoopScript(loopscript, scriptsize)) { assert(itemlist->getElementSize() == 2); uint16 oId = (*iter)->getObjId(); - uint8 buf[2]; - buf[0] = static_cast(oId); - buf[1] = static_cast(oId >> 8); - itemlist->append(buf); + itemlist->appenduint16(oId); } if (recurse) { diff --git a/engines/ultima/ultima8/world/current_map.cpp b/engines/ultima/ultima8/world/current_map.cpp index ad342033ed5..46c27da22cf 100644 --- a/engines/ultima/ultima8/world/current_map.cpp +++ b/engines/ultima/ultima8/world/current_map.cpp @@ -607,11 +607,7 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript, // check item against loopscript if (item->checkLoopScript(loopscript, scriptsize)) { assert(itemlist->getElementSize() == 2); - const uint16 objid = item->getObjId(); - uint8 buf[2]; - buf[0] = static_cast(objid); - buf[1] = static_cast(objid >> 8); - itemlist->append(buf); + itemlist->appenduint16(item->getObjId()); } if (recurse) { @@ -696,11 +692,7 @@ void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript, // check item against loopscript if (item->checkLoopScript(loopscript, scriptsize)) { assert(itemlist->getElementSize() == 2); - uint16 objid = item->getObjId(); - uint8 buf[2]; - buf[0] = static_cast(objid); - buf[1] = static_cast(objid >> 8); - itemlist->append(buf); + itemlist->appenduint16(item->getObjId()); } } }