Skip to content

WIP: Ensure Unique Instance RefNums after clone, add, or move

Michael Stopa requested to merge Stomy/openmw:master into master

A quick hack for #4748 (closed)

Cloning or adding new records on the Instances table can (and does in the case of clone) result in multiple Instances within a single cell having the same RefNum/FRMR index, result in both OpenMW and OpenCS ignoring the duplicates when loading the .omwaddon.

To prevent this, I've added a check in Collection::cloneRecordImp that hard-casts the Record into a CSMWorld::CellRef to clear its ref number, then CSMDoc::WriteCellCollectionStage::perform assigns new refnums to clones and additions by starting at the highest detected index in the cell (rather than relying on the cell's own mRefNumCounter) as indices don't actually need to be contiguous, just unique.

I'm sure this is not the preferred way to do this, but I'm a die-hard C-style programmer so templates are considered unknown territory for me. I'd appreciate someone much more acclimatized to modern OOP pointing out how this is supposed to look.

EDIT: I've also modified this pull request to clear the refnum indices when an instance is moved to a new cell, as well as checking at the same time whether a cell update and refnum clear are necessary. The check however assumes that cells are always 7168 units square which I'm not 100% sure about and would rather not leave hard-coded, is there an internal setting or constant that can be relied upon to retrieve the size of an exterior cell?

Edited by Michael Stopa

Merge request reports