Updated IsSameCellPackage

This commit is contained in:
Eddoursul 2023-10-24 17:06:00 +02:00
parent ce2345d7aa
commit fae731a9dd

View File

@ -34,8 +34,8 @@ begin
sig := Signature(referencingRecord);
// Locational links are bi-directional, this script does not process them. To fix them, resave plugin in CK.
// WRLD records may refer to REFRs if they are large references. Being a large reference does not imply necessity of the persistence flag.
// TES4 may refer to REFRs if they are listed in ONAM. To keep ONAM up to date, enable "Always save ONAM" in xEdit.
// WRLD records usually refer to large reference REFRs. Being a large reference does not imply necessity of the persistence flag.
// TES4 refers to REFRs if they are listed in ONAM. To keep ONAM up to date, enable "Always save ONAM" in xEdit.
if (sig = 'LCTN') or (sig = 'WRLD') or (sig = 'TES4') then
continue;
@ -45,7 +45,6 @@ begin
if GetLoadOrder(GetFile(referencingRecord)) <= GetLoadOrder(GetFile(rec)) then begin
// When referencing record is not referenced and it's in the same cell, the ref does not need persistence.
// Does not cover long chains of linked refs.
if (ReferencedByCount(referencingRecord) = 0) then begin
if (sig = 'REFR') then begin
if InSameCell(rec, referencingRecord) then continue;
@ -181,45 +180,55 @@ begin
end;
end;
function IsSameCellPackage(package: IwbMainRecord): boolean;
function IsSameCellPackage(inputValues: IwbElement): boolean;
var
packageLoc, packageType: string;
packageLoc: string;
inputVal: IwbElement;
refCell, linkedRefKeyword, linkedRef: IwbMainRecord;
i: integer;
begin
packageLoc := GetElementEditValues(ElementByIndex(ElementByPath(package, 'Package Data\Data Input Values'), 0), 'PLDT\Type');
result := True;
if packageLoc <> '' then begin
for i := 0 to Pred(ElementCount(inputValues)) do begin
inputVal := ElementByIndex(inputValues, i);
packageLoc := GetElementEditValues(inputVal, 'PLDT\Type');
if (packageLoc = 'Near editor location') or (packageLoc = 'Near self') then begin
//AddMessage(' Skipping editor location actor: ' + GetElementEditValues(e, 'NAME') + ' - (' + Name(e) + ')');
continue;
end
else if (packageLoc = 'In cell') then begin
refCell := LinksTo(ElementByPath(ElementByIndex(ElementByPath(package, 'Package Data\Data Input Values'), 0), 'PLDT\Cell'));
if Assigned(refCell) then begin
if SameRecord(refCell, LinksTo(ElementByPath(e, 'Cell'))) then continue;
if packageLoc <> '' then begin
if (packageLoc = 'Near editor location') or (packageLoc = 'Near self') then begin
//AddMessage(' Skipping editor location actor: ' + GetElementEditValues(e, 'NAME') + ' - (' + Name(e) + ')');
continue;
end
else if (packageLoc = 'In cell') then begin
refCell := LinksTo(ElementByPath(inputVal, 'PLDT\Cell'));
if Assigned(refCell) then begin
if SameRecord(refCell, LinksTo(ElementByPath(e, 'Cell'))) then continue;
end;
end
else if (packageLoc = 'Near linked reference') then begin
linkedRefKeyword := LinksTo(ElementByPath(inputVal, 'PLDT\Keyword'));
if not IsLinkedRefRemote(e, linkedRefKeyword) then continue;
end
else if (packageLoc = 'Near reference') then begin
if InSameCell(e, LinksTo(ElementByPath(inputVal, 'PLDT\Reference'))) then continue;
end;
end
else if (packageLoc = 'Near linked reference') then begin
linkedRefKeyword := LinksTo(ElementByPath(ElementByIndex(ElementByPath(package, 'Package Data\Data Input Values'), 0), 'PLDT\Keyword'));
if not IsLinkedRefRemote(e, linkedRefKeyword) then continue;
end
else if (packageLoc = 'Near reference') then begin
if InSameCell(e, LinksTo(ElementByPath(ElementByIndex(ElementByPath(package, 'Package Data\Data Input Values'), 0), 'PLDT\Reference'))) then continue;
else begin
packageLoc := GetElementEditValues(inputVal, 'PTDA\Target Data\Type');
if (packageLoc = 'Linked Reference') then begin
linkedRefKeyword := LinksTo(ElementByPath(inputVal, 'PTDA\Target Data\Reference'));
if not IsLinkedRefRemote(e, linkedRefKeyword) then continue;
end
else if (packageLoc = 'Specific Reference') then begin
linkedRef := LinksTo(ElementByPath(inputVal, 'PTDA\Target Data\Reference'));
if InSameCell(e, linkedRef) then continue;
end;
end;
end
else begin
packageLoc := GetElementEditValues(ElementByIndex(ElementByPath(package, 'Package Data\Data Input Values'), 0), 'PTDA\Target Data\Type');
if (packageLoc = 'Linked Reference') then begin
linkedRefKeyword := LinksTo(ElementByPath(ElementByIndex(ElementByPath(package, 'Package Data\Data Input Values'), 0), 'PTDA\Target Data\Reference'));
if not IsLinkedRefRemote(e, linkedRefKeyword) then continue;
end
else if (packageLoc = 'Specific Reference') then begin
linkedRef := LinksTo(ElementByPath(ElementByIndex(ElementByPath(package, 'Package Data\Data Input Values'), 0), 'PTDA\Target Data\Reference'));
if InSameCell(e, linkedRef) then continue;
end;
result := False;
break;
end;
end;
@ -240,7 +249,7 @@ begin
// DLZM and DCZM Default Objects.
// For simplicity sake, I assume they are unchanged, which is true in 99.999% cases.
// If you ever find a mod, changing these objects, I will update this to retrieve actual values.
// If you ever find a mod, changing these objects, update this to retrieve actual values.
hardcodedStatForms.Add($138C0); // DragonMarker
hardcodedStatForms.Add($3DF55); // DragonMarkerCrashStrip
end;
@ -250,7 +259,7 @@ var
currentPlugin: IwbFile;
baseRefRecord, package, actorLocation: IwbMainRecord;
packages: IwbElement;
i, baseID, packageCount, typeId: integer;
i, j, baseID, packageCount, typeId: integer;
sig, baseSig: string;
isREFR, isACHR, skip: boolean;
begin
@ -388,7 +397,7 @@ begin
continue;
end;
if (IsSameCellPackage(package)) then continue;
if (IsSameCellPackage(ElementByPath(package, 'Package Data\Data Input Values'))) then continue;
skip := false;
break;