-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFind Precombine Breakers.pas
126 lines (102 loc) · 4.05 KB
/
Find Precombine Breakers.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{
This script, should, in theory, find objects which break precombines.
}
unit userscript;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
begin
Result := 0;
end;
procedure outputError(e: IInterface);
var
curMaster, cell, winner: IInterface;
begin
curMaster := MasterOrSelf(e);
winner := HighestOverrideOrSelf(e, 500);
cell := LinksTo(ElementByPath(curMaster, 'Cell'));
AddMessage('--------------------------------');
AddMessage('!!! FOUND PRECOMBINE BREAKER !!!');
AddMessage('CELL: '+Name(cell));
AddMessage('REFR: '+Name(curMaster));
AddMessage('Culprit: '+GetFileName(GetFile(winner)));
AddMessage('--------------------------------');
end;
function FilesEqual(file1, file2: IwbFile): boolean;
begin
// Should be faster than comparing the filenames
Result := (GetLoadOrder(file1) = GetLoadOrder(file2));
end;
function getExistingElementOverride(sourceElem: IInterface; targetFile: IwbFile): IInterface;
var
masterElem, curOverride: IINterface;
numOverrides, i: integer;
targetFileName: string;
begin
Result := nil;
masterElem := MasterOrSelf(sourceElem);
targetFileName := GetFileName(targetFile);
// important failsafe
if(FilesEqual(targetFile, GetFile(masterElem))) then begin
Result := sourceElem;
exit;
end;
numOverrides := OverrideCount(masterElem);
for i:=0 to numOverrides-1 do begin
curOverride := OverrideByIndex(masterElem, i);
// AddMessage('checking='+GetFileName(GetFile(curOverride)));
if (FilesEqual(GetFile(curOverride), targetFile)) then begin
// AddMessage('should work');
Result := curOverride;
exit;
end;
end;
end;
function winnerHasPrecombines(e: IInterface): boolean;
var
winner, origCell, winCell: IInterface;
origPrevis, origPrecomb, winPrevis, winPrecomb: string;
begin
winner := HighestOverrideOrSelf(e, 500);
origCell := LinksTo(ElementByPath(e, 'Cell'));
//winCell := HighestOverrideOrSelf(origCell, 500);//LinksTo(ElementByPath(winner, 'Cell'));
//winCell := LinksTo(ElementByPath(winner, 'Cell'));
winCell := getExistingElementOverride(origCell, GetFile(winner));
//AddMessage('A'+Name(winCell));
origPrevis := GetElementEditValues(origCell, 'VISI');
origPrecomb:= GetElementEditValues(origCell, 'PCMB');
winPrevis := GetElementEditValues(winCell, 'VISI');
winPrecomb:= GetElementEditValues(winCell, 'PCMB');
//AddMessage(origPrevis+' '+origPrecomb+' = '+winPrevis+' '+winPrecomb);
Result := (origPrevis<winPrevis) and (origPrecomb<winPrecomb);
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
var
baseElem: IInterface;
curSig: string;
begin
Result := 0;
// comment this out if you don't want those messages
if(Signature(e) <> 'REFR') then begin
exit;
end;
baseElem := MasterOrSelf(e);
if(HasPrecombinedMesh(baseElem)) then begin
if(not IsWinningOverride(baseElem)) then begin
if(not winnerHasPrecombines(baseElem)) then begin
outputError(baseElem);
end;
end;
end;
//targetForm := LinksTo(ElementByPath(e, 'NAME'));
//curSig := Signature(targetForm);
//AddMessage(curSig);
end;
// Called after processing
// You can remove it if script doesn't require finalization code
function Finalize: integer;
begin
Result := 0;
end;
end.